-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.php
294 lines (275 loc) · 9.64 KB
/
library.php
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
/*
* Copyright (C) 2015 greg
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in the LICENSE file.
* If not, see <http://www.gnu.org/licenses/>.
*/
// composer libraries
require __DIR__ . '/vendor/autoload.php';
function mail_report($report, $MwApi, $email=null) {
global $quiet;
require __DIR__ . '/secret.php';
$byline = <<<HERE
<div>
<br />
<br />
This report was brought to you by
<img src="https://freephile.org/wikireport/favicon.ico" alt="="/> eQuality Technology<br />
a leader in free software and wikis.<br />
<a href="https://freephile.org/wikireport/">Get another Wiki Report</a>
</div>
HERE;
// echo "sending for $gmailUser\n<br />";
// return true;
// mail the report
$report .= $byline;
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPDebug = 0; // 0 no debugging - 4 is maximum
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//$mail->Host = 'smtp.gmail.com'; // Specify SMTP server(s)
$mail->Host = gethostbyname("smtp.gmail.com");
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $gmailUser; // SMTP username
$mail->Password = $gmailPassword; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption
$mail->Port = 587; // TCP port to connect to
// Google rewrites this to the default set in your account
$mail->setFrom('info@eQuality-Tech.com', 'Wiki Report');
if (! is_null($email)) {
$mail->addAddress($email); // Add a recipient
}
// I can suppress bcc by adding ?quiet=1 "true", "on", "yes"
//if (isset($quiet) && $quiet != true) {
if (!in_array($_SERVER['REMOTE_ADDR'], $ipWhitelist)) {
$mail->addBCC('info@eQuality-Tech.com');
}
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Wiki Report for $MwApi->sitename ($MwApi->base).";
$mail->Body = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>';
$mail->Body .= $report;
$mail->Body .= '</body></html>';
$mail->AltBody = strip_tags($report);
if(!$mail->send()) {
return $mail->ErrorInfo;
} else {
return true;
}
}
function populate_err_message($errors, $url) {
$msg = '';
if (! count($errors)) {
return '';
}
foreach ($errors as $k => $v) {
if ($k == 'Url') {
$msg .= <<<HERE
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error: </span>
We could not detect a wiki at <a href="$url" target="_blank">$url</a>
</div>
HERE;
}
if ($k == 'WikiPerm') {
$msg .= <<<HERE
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error: </span>
Wiki detected at <a href="$url" target="_blank">$url</a>, but we can't report on it.
</div>
HERE;
}
}
return $msg;
}
function show_statistics_data_table($tabledata, $section, $title) {
$return = '';
$format = new \eqt\wikireport\Format();
$headings = array_keys($tabledata);
$len = count($tabledata);
$values = array_values($tabledata);
$return .= <<<HERE
<div class="col-md-6 col-md-offset-3">
<h2>$title</h2>
<div class="table-responsive">
<table id="wiki-$section-table" class="table table-striped table-condensed table-bordered table-hover">
<thead>
<tr>
HERE;
for ($i = 0; $i < $len; $i++) {
$return .= "<th>$headings[$i]</th>";
}
$return .= "</tr></thead>
<tbody>";
$return .= "\n<tr>";
for ($i = 0; $i < $len; $i++) {
$return .= "<td class=\"number\">$values[$i]</td>";
}
$return .= "</tr>";
$return .= "</tbody>
</table>
</div>
</div>";
return $return;
}
function show_general_data_table($tabledata, $section, $title) {
$return = '';
$format = new \eqt\wikireport\Format();
$return .= <<<HERE
<div class="col-md-6 col-md-offset-3">
<h2>$title</h2>
<div class="table-responsive">
<table id="wiki-$section-table" class="table table-striped table-condensed table-bordered table-hover">
<thead>
<tr><th>Item</th><th>Value</th></tr>
</thead>
<tbody>
HERE;
foreach ($tabledata as $k => $v) {
$format->linkify($v);
$v = $format->implode($v); // avoid array to string conversion and no output
$return .= "<tr><th>$k</th><td>$v</td></tr>";
}
$return .= " </tbody>
</table>
</div>
</div>";
return $return;
}
function show_extensions_data_table($tabledata, $section, $title) {
$return = '';
$format = new \eqt\wikireport\Format();
$return .= <<<HERE
<div class="col-md-12">
<h2>$title</h2>
HERE;
foreach ($tabledata as $k => $v) {
$return .= <<<HERE
<div class="table-responsive">
<table id="wiki-$section-table-$k" class="table table-striped table-condensed table-bordered table-hover">
<thead>
<tr><th colspan="2" class="text-center">{$v["name"]}</th></tr>
</thead>
<tbody>
HERE;
foreach ($v as $key => $value) {
if ((strlen($value)) && ($key != 'name')) {
$format->linkify($value);
$value = $format->implode($value);
$return .= "<tr><th>$key</th><td>$value</td></tr>";
}
}
$return .= "</tbody>
</table>
</div>";
}
$return .= "
</div>";
return $return;
}
/**
* convert a HSL colorscheme to either Hexadecimal (default) or RGB.
*
* We want a method where we can programmatically generate a series of colors
* between two values (eg. red to green) which is easy to do with HSL because
* you just change the hue. (0 = red, 120 = green). You can use this function
* to convert those hsl color values to either the rgb or hexadecimal color scheme.
* e.g. You have
* hsl(50, 100%, 50%)
* To convert,
* $hex = convertHSL(50,100,50); // returns #ffd500
* or
* $rgb = convertHSL(50,100,50, false); // returns rgb(255, 213, 0)
*
* see https://coderwall.com/p/dvsxwg/smoothly-transition-from-green-to-red
* @param int $h the hue
* @param int $s the saturation
* @param int $l the luminance
* @param bool $toHex whether you want hexadecimal equivalent or rgb equivalent
* @return string usable in HTML or CSS
*/
function convertHSL($h, $s, $l, $toHex=true){
$h /= 360;
$s /=100;
$l /=100;
$r = $l;
$g = $l;
$b = $l;
$v = ($l <= 0.5) ? ($l * (1.0 + $s)) : ($l + $s - $l * $s);
if ($v > 0){
$m;
$sv;
$sextant;
$fract;
$vsf;
$mid1;
$mid2;
$m = $l + $l - $v;
$sv = ($v - $m ) / $v;
$h *= 6.0;
$sextant = floor($h);
$fract = $h - $sextant;
$vsf = $v * $sv * $fract;
$mid1 = $m + $vsf;
$mid2 = $v - $vsf;
switch ($sextant)
{
case 0:
$r = $v;
$g = $mid1;
$b = $m;
break;
case 1:
$r = $mid2;
$g = $v;
$b = $m;
break;
case 2:
$r = $m;
$g = $v;
$b = $mid1;
break;
case 3:
$r = $m;
$g = $mid2;
$b = $v;
break;
case 4:
$r = $mid1;
$g = $m;
$b = $v;
break;
case 5:
$r = $v;
$g = $m;
$b = $mid2;
break;
}
}
$r = round($r * 255, 0);
$g = round($g * 255, 0);
$b = round($b * 255, 0);
if ($toHex) {
$r = ($r < 15)? '0' . dechex($r) : dechex($r);
$g = ($g < 15)? '0' . dechex($g) : dechex($g);
$b = ($b < 15)? '0' . dechex($b) : dechex($b);
return "#$r$g$b";
} else {
return "rgb($r, $g, $b)";
}
}