-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathOutput.php
More file actions
143 lines (122 loc) · 3.98 KB
/
Copy pathOutput.php
File metadata and controls
143 lines (122 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace dokuwiki\plugin\qc;
/**
* Class Output
*
* Create the HTML formatted output of the scoring analysis
*
* @package dokuwiki\plugin\qc
*/
class Output
{
public const MAXERR = 10; //what score to use as total failure
/** @var array the scoring data */
protected $data;
/** @var \helper_plugin_qc */
protected $helper;
/**
* Output constructor.
* @param string $page the page to analyze
*/
public function __construct($page)
{
$this->helper = plugin_load('helper', 'qc');
$this->data = $this->helper->getQCData($page);
}
/**
* Get the score as icon
*
* @param $score
* @return string
*/
public static function scoreIcon($score)
{
$html = '';
// rate the score
if ($score > self::MAXERR) {
$rating = 'bad';
} elseif ($score) {
$rating = 'meh';
} else {
$rating = 'good';
}
// output icon and score
$html .= '<span class="qc_icon qc_' . $rating . '">';
$html .= inlineSVG(__DIR__ . '/svg/' . $rating . '.svg');
if ($score) $html .= '<span>' . $score . '</span>';
$html .= '</span>';
return $html;
}
/**
* Print the short summary
*
* @return string
*/
public function short()
{
return self::scoreIcon($this->data['score']);
}
/**
* Print full analysis
*
* @return string
*/
public function long()
{
$html = '';
$html .= '<h1>' . $this->helper->getLang('intro_h') . '</h1>';
$html .= '<div>';
$html .= '<dl>';
$html .= '<dt>' . $this->helper->getLang('g_created') . '</dt>';
$html .= '<dd>' . dformat($this->data['created']) . '</dd>';
$html .= '<dt>' . $this->helper->getLang('g_modified') . '</dt>';
$html .= '<dd>' . dformat($this->data['modified']) . '</dd>';
// print top 5 authors
if (!is_array($this->data['authors'])) $this->data['authors'] = [];
arsort($this->data['authors']);
$top5 = array_slice($this->data['authors'], 0, 5);
$cnt = count($top5);
$i = 1;
$html .= '<dt>' . $this->helper->getLang('g_authors') . '</dt>';
$html .= '<dd>';
foreach ($top5 as $a => $e) {
if ($a == '*') {
$html .= $this->helper->getLang('anonymous');
} else {
$html .= editorinfo($a);
}
$html .= ' (' . $e . ')';
if ($i++ < $cnt) $html .= ', ';
}
$html .= '</dd>';
$html .= '<dt>' . $this->helper->getLang('g_changes') . '</dt>';
$html .= '<dd>' . $this->data['changes'] . '</dd>';
$html .= '<dt>' . $this->helper->getLang('g_chars') . '</dt>';
$html .= '<dd>' . $this->data['chars'] . '</dd>';
$html .= '<dt>' . $this->helper->getLang('g_words') . '</dt>';
$html .= '<dd>' . $this->data['words'] . '</dd>';
$html .= '</dl>';
$html .= '</div>';
// output all the problems
if ($this->data['score']) {
$html .= '<h2>' . $this->helper->getLang('errorsfound_h') . '</h2>';
$html .= '<p>' . $this->helper->getLang('errorsfound') . '</p>';
$html .= '<div>';
arsort($this->data['err']); #sort by score
foreach ($this->data['err'] as $err => $val) {
if ($val) {
$html .= '<h3>';
$html .= sprintf($this->helper->getLang($err . '_h'), $val);
$html .= '<span class="qc_icon qc_bad">';
$html .= inlineSVG(__DIR__ . '/svg/bad.svg');
$html .= '<span>' . $val . '</span>';
$html .= '</span>';
$html .= '</h3>';
$html .= '<p>' . sprintf($this->helper->getLang($err), $val) . '</p>';
}
}
$html .= '</div>';
}
return $html;
}
}