|
1
|
|
|
<?php namespace XoopsModules\Smallworld; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* You may not change or alter any portion of this comment or credits |
|
5
|
|
|
* of supporting developers from this source code or any supporting source code |
|
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
* |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* SmallWorld |
|
15
|
|
|
* |
|
16
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @copyright 2011 Culex |
|
18
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
|
19
|
|
|
* @package SmallWorld |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Admin |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Get oldest message in Db |
|
27
|
|
|
* @returns time |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
public function oldestMsg() |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
global $xoopsDB; |
|
32
|
|
|
$date = 0; |
|
33
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_messages') . ' ORDER BY created LIMIT 1'; |
|
34
|
|
|
$result = $xoopsDB->queryF($sql); |
|
35
|
|
|
$counter = $xoopsDB->getRowsNum($result); |
|
36
|
|
|
if ($counter >= 1) { |
|
37
|
|
|
while ($sqlfetch = $xoopsDB->fetchArray($result)) { |
|
38
|
|
|
$date = $sqlfetch['created']; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $date; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get average messages sent per day |
|
47
|
|
|
* @param int $totaldays |
|
48
|
|
|
* @return int|string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function AvgMsgDay($totaldays) |
|
51
|
|
|
{ |
|
52
|
|
|
global $xoopsDB; |
|
53
|
|
|
$sql = 'SELECT count( * ) / ' . $totaldays . ' AS averg FROM ' . $xoopsDB->prefix('smallworld_messages') . ''; |
|
54
|
|
|
$result = $xoopsDB->queryF($sql); |
|
55
|
|
|
while ($sqlfetch = $xoopsDB->fetchArray($result)) { |
|
56
|
|
|
$avg = number_format($sqlfetch['averg'], 2, '.', ','); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $avg; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* total users using smallworld |
|
64
|
|
|
* @return int |
|
65
|
|
|
*/ |
|
66
|
|
|
public function TotalUsers() |
|
67
|
|
|
{ |
|
68
|
|
|
global $xoopsDB; |
|
69
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . ''; |
|
70
|
|
|
$result = $xoopsDB->queryF($sql); |
|
71
|
|
|
$counter = $xoopsDB->getRowsNum($result); |
|
72
|
|
|
if ($counter < 1) { |
|
73
|
|
|
$sum = 0; |
|
74
|
|
|
} else { |
|
75
|
|
|
$i = 0; |
|
76
|
|
|
while ($myrow = $xoopsDB->fetchArray($result)) { |
|
77
|
|
|
$user[$i]['username'] = $myrow['username']; |
|
|
|
|
|
|
78
|
|
|
++$i; |
|
79
|
|
|
} |
|
80
|
|
|
$all = $this->flatten($user); |
|
|
|
|
|
|
81
|
|
|
$sum = count(array_unique($all)); |
|
82
|
|
|
$unique = array_unique($all); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $sum; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get version of module |
|
90
|
|
|
* @returns string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function ModuleInstallVersion() |
|
93
|
|
|
{ |
|
94
|
|
|
global $xoopsModule; |
|
95
|
|
|
$version = round($xoopsModule->getVar('version') / 100, 2); |
|
96
|
|
|
|
|
97
|
|
|
return $version; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get date when Module was installed |
|
102
|
|
|
* @return string|time |
|
103
|
|
|
*/ |
|
104
|
|
|
public function ModuleInstallDate() |
|
105
|
|
|
{ |
|
106
|
|
|
global $xoopsModule; |
|
107
|
|
|
$date = formatTimestamp($xoopsModule->getVar('last_update'), 'm'); |
|
108
|
|
|
|
|
109
|
|
|
return $date; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Count total days represented in db |
|
114
|
|
|
* @return float|int|time |
|
115
|
|
|
*/ |
|
116
|
|
|
public function CountDays() |
|
117
|
|
|
{ |
|
118
|
|
|
global $xoopsDB, $xoopsModule; |
|
119
|
|
|
$date = $this->oldestMsg(); |
|
120
|
|
|
$now = time(); |
|
121
|
|
|
$diff = ($now - $date) / (60 * 60 * 24); |
|
122
|
|
|
|
|
123
|
|
|
return $diff; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* find user with most posted messages |
|
128
|
|
|
* @returns array |
|
129
|
|
|
*/ |
|
130
|
|
|
public function mostactiveusers_allround() |
|
131
|
|
|
{ |
|
132
|
|
|
global $xoopsDB, $xoopsUser; |
|
133
|
|
|
$sql = 'SELECT uid_fk, COUNT( * ) as cnt '; |
|
134
|
|
|
$sql .= 'FROM ( '; |
|
135
|
|
|
$sql .= 'SELECT uid_fk '; |
|
136
|
|
|
$sql .= 'FROM ' . $xoopsDB->prefix('smallworld_messages') . ' '; |
|
137
|
|
|
$sql .= 'UNION ALL SELECT uid_fk '; |
|
138
|
|
|
$sql .= 'FROM ' . $xoopsDB->prefix('smallworld_comments') . ' '; |
|
139
|
|
|
$sql .= ') AS u '; |
|
140
|
|
|
$sql .= 'GROUP BY uid_fk '; |
|
141
|
|
|
$sql .= 'ORDER BY count( * ) DESC limit 20'; |
|
142
|
|
|
$result = $xoopsDB->queryF($sql); |
|
143
|
|
|
$counter = $xoopsDB->getRowsNum($result); |
|
144
|
|
|
|
|
145
|
|
View Code Duplication |
if ($counter < 1) { |
|
|
|
|
|
|
146
|
|
|
$msg = []; |
|
147
|
|
|
} else { |
|
148
|
|
|
$msg = []; |
|
149
|
|
|
$i = 1; |
|
150
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
151
|
|
|
$msg['counter'][$i] = $i; |
|
152
|
|
|
$msg['img'][$i] = "<img style='margin:0px 5px;' src = '../assets/images/" . $i . ".png'>"; |
|
153
|
|
|
if ($msg['counter'][$i] > 3) { |
|
154
|
|
|
$msg['img'][$i] = ''; |
|
155
|
|
|
} |
|
156
|
|
|
$msg['cnt'][$i] = $row['cnt']; |
|
157
|
|
|
$msg['from'][$i] = $xoopsUser->getUnameFromId($row['uid_fk']); |
|
158
|
|
|
++$i; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $msg; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* find user with most posted messages in last 24 hours |
|
167
|
|
|
* @returns array |
|
168
|
|
|
*/ |
|
169
|
|
|
public function mostactiveusers_today() |
|
170
|
|
|
{ |
|
171
|
|
|
global $xoopsDB, $xoopsUser; |
|
172
|
|
|
$sql = 'SELECT uid_fk, COUNT( * ) as cnt '; |
|
173
|
|
|
$sql .= 'FROM ( '; |
|
174
|
|
|
$sql .= 'SELECT uid_fk '; |
|
175
|
|
|
$sql .= 'FROM ' . $xoopsDB->prefix('smallworld_messages') . ' '; |
|
176
|
|
|
$sql .= 'WHERE `created` > UNIX_TIMESTAMP(DATE_SUB( NOW( ) , INTERVAL 1 DAY )) '; |
|
177
|
|
|
$sql .= 'UNION ALL SELECT uid_fk '; |
|
178
|
|
|
$sql .= 'FROM ' . $xoopsDB->prefix('smallworld_comments') . ' '; |
|
179
|
|
|
$sql .= 'WHERE `created` > UNIX_TIMESTAMP(DATE_SUB( NOW( ) , INTERVAL 1 DAY )) '; |
|
180
|
|
|
$sql .= ') AS u '; |
|
181
|
|
|
$sql .= 'GROUP BY uid_fk '; |
|
182
|
|
|
$sql .= 'ORDER BY count( * ) DESC limit 20'; |
|
183
|
|
|
|
|
184
|
|
|
$result = $xoopsDB->queryF($sql); |
|
185
|
|
|
$msgtoday = []; |
|
186
|
|
|
|
|
187
|
|
View Code Duplication |
if (0 != $xoopsDB->getRowsNum($result)) { |
|
|
|
|
|
|
188
|
|
|
$i = 1; |
|
189
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
190
|
|
|
$msgtoday['counter'][$i] = $i; |
|
191
|
|
|
$msgtoday['img'][$i] = "<img style='margin:0px 5px;' src = '../assets/images/" . $i . ".png'>"; |
|
192
|
|
|
if ($msgtoday['counter'][$i] > 3) { |
|
193
|
|
|
$msgtoday['img'][$i] = ''; |
|
194
|
|
|
} |
|
195
|
|
|
$msgtoday['cnt'][$i] = $row['cnt']; |
|
196
|
|
|
$msgtoday['from'][$i] = $xoopsUser->getUnameFromId($row['uid_fk']); |
|
197
|
|
|
++$i; |
|
198
|
|
|
} |
|
199
|
|
|
} else { |
|
200
|
|
|
$msgtoday = []; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
return $msgtoday; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Find best OR worst rated users |
|
208
|
|
|
* @param string $direction |
|
209
|
|
|
* @returns array |
|
210
|
|
|
* @return array |
|
211
|
|
|
* @return array |
|
212
|
|
|
*/ |
|
213
|
|
|
public function topratedusers($direction) |
|
214
|
|
|
{ |
|
215
|
|
|
global $xoopsUser, $xoopsDB, $xoopsTpl; |
|
216
|
|
|
$array = []; |
|
217
|
|
|
|
|
218
|
|
|
if ('up' === $direction) { |
|
219
|
|
|
$sql = 'SELECT owner, count(*) AS cnt FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE up='1' GROUP BY owner ORDER BY cnt DESC LIMIT 20"; |
|
220
|
|
|
$result = $xoopsDB->queryF($sql); |
|
221
|
|
|
$count = $xoopsDB->getRowsNum($result); |
|
222
|
|
|
$i = 1; |
|
223
|
|
|
if ($count >= $i) { |
|
224
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
225
|
|
|
$array['counter'][$i] = $i; |
|
226
|
|
|
$array['img'][$i] = "<img height='10px' width='10px' " . "style='margin:0px 5px;' src = '../assets/images/like.png'>"; |
|
227
|
|
|
if ($array['counter'][$i] > 3) { |
|
228
|
|
|
$array['img'][$i] = ''; |
|
229
|
|
|
} |
|
230
|
|
|
$array['cnt'][$i] = $row['cnt']; |
|
231
|
|
|
$array['user'][$i] = $xoopsUser->getUnameFromId($row['owner']); |
|
232
|
|
|
++$i; |
|
233
|
|
|
} |
|
234
|
|
|
} else { |
|
235
|
|
|
$array = []; |
|
236
|
|
|
} |
|
237
|
|
|
} else { |
|
238
|
|
|
$sql = 'SELECT owner, count(*) AS cnt FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE down='1' GROUP BY owner ORDER BY cnt DESC LIMIT 20"; |
|
239
|
|
|
$result = $xoopsDB->queryF($sql); |
|
240
|
|
|
$count = $xoopsDB->getRowsNum($result); |
|
241
|
|
|
$i = 1; |
|
242
|
|
|
if (0 != $count) { |
|
243
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
244
|
|
|
$array['counter'][$i] = $i; |
|
245
|
|
|
$array['img'][$i] = "<img height='10px' width='10px' " . "style='margin:0px 5px;' src = '../assets/images/dislike.png'>"; |
|
246
|
|
|
if ($array['counter'][$i] > 3) { |
|
247
|
|
|
$array['img'][$i] = ''; |
|
248
|
|
|
} |
|
249
|
|
|
$array['cnt'][$i] = $row['cnt']; |
|
250
|
|
|
$array['user'][$i] = $xoopsUser->getUnameFromId($row['owner']); |
|
251
|
|
|
++$i; |
|
252
|
|
|
} |
|
253
|
|
|
} else { |
|
254
|
|
|
$array = []; |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
return $array; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Get all users to loop in admin for administration |
|
263
|
|
|
* @param string $inspect |
|
264
|
|
|
* @returns array |
|
265
|
|
|
* @return array |
|
266
|
|
|
* @return array |
|
|
|
|
|
|
267
|
|
|
*/ |
|
268
|
|
|
public function getAllUsers($inspect) |
|
269
|
|
|
{ |
|
270
|
|
|
global $xoopsDB, $xoopsUser, $xoopsTpl; |
|
271
|
|
|
$data = []; |
|
272
|
|
|
if ('yes' === $inspect) { |
|
273
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_admin') . ' WHERE (inspect_start + inspect_stop) >= ' . time() . ' ORDER BY username'; |
|
274
|
|
|
} else { |
|
275
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_admin') . ' WHERE (inspect_start + inspect_stop) < ' . time() . ' ORDER BY username'; |
|
276
|
|
|
} |
|
277
|
|
|
$result = $xoopsDB->queryF($sql); |
|
278
|
|
|
$count = $xoopsDB->getRowsNum($result); |
|
279
|
|
|
if (0 != $count) { |
|
280
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
281
|
|
|
$data[] = $row; |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
if (!empty($data)) { |
|
285
|
|
|
return $data; |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* check server if update is available |
|
291
|
|
|
* Server currently at culex.dk |
|
292
|
|
|
* Variable $version = current smallworld version number |
|
293
|
|
|
* @return string |
|
294
|
|
|
*/ |
|
295
|
|
|
public function doCheckUpdate() |
|
296
|
|
|
{ |
|
297
|
|
|
global $pathIcon16; |
|
298
|
|
|
$version = $this->ModuleInstallVersion(); |
|
299
|
|
|
$critical = false; |
|
300
|
|
|
$update = false; |
|
301
|
|
|
$rt = ''; |
|
|
|
|
|
|
302
|
|
|
$url = 'http://www.culex.dk/updates/smallworld_version.csv'; |
|
303
|
|
|
$fileC = $this->fetchURL($url, ['fopen', 'curl', 'socket']); |
|
304
|
|
|
$read = explode(';', $fileC); |
|
305
|
|
|
|
|
306
|
|
|
$upd_img = $pathIcon16 . '/on.png'; |
|
307
|
|
|
|
|
308
|
|
|
if ($read[0] > $version && '1' == $read[2]) { |
|
309
|
|
|
$critical = true; |
|
310
|
|
|
$upd_img = $pathIcon16 . '/off.png'; |
|
311
|
|
|
} |
|
312
|
|
|
if ($read[0] > $version && '1' != $read[2]) { |
|
313
|
|
|
$update = true; |
|
314
|
|
|
$upd_img = '../assets/images/upd_normal.png'; |
|
315
|
|
|
} |
|
316
|
|
|
if ($critical) { |
|
317
|
|
|
$rt = "<div class='smallworld_update'><img src='" . $upd_img . "'>"; |
|
318
|
|
|
$rt .= _AM_SMALLWORLD_UPDATE_CRITICAL_UPD . '</div>'; |
|
319
|
|
|
$rt .= "<textarea class='xim_update_changelog'>" . $read[1] . '</textarea><br><br>'; |
|
320
|
|
|
$rt .= _AM_SMALLWORLD_UPDATE_SERVER_FILE . "<br><a href='" . $read[3] . "'>" . $read[3] . '</a>'; |
|
321
|
|
|
} elseif ($update) { |
|
322
|
|
|
$rt = "<div class='smallworld_update'><img src='" . $upd_img . "'>"; |
|
323
|
|
|
$rt .= _AM_SMALLWORLD_UPDATE_NORMAL_UPD . '</div>'; |
|
324
|
|
|
$rt .= "<textarea class='smallworld_update_changelog'>" . $read[1] . '</textarea><br><br>'; |
|
325
|
|
|
$rt .= _AM_SMALLWORLD_UPDATE_SERVER_FILE . "<br><a href='" . $read[3] . "'>" . $read[3] . '</a>'; |
|
326
|
|
|
} else { |
|
327
|
|
|
$rt = "<div class='smallworld_update'><br><img src='" . $upd_img . "'>" . _AM_SMALLWORLD_UPDATE_YOUHAVENEWESTVERSION . '</div>'; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
return $rt; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Fetch content of comma separated text file |
|
335
|
|
|
* will attempt to use the fopen method first, then curl, then socket |
|
336
|
|
|
* @param string $url |
|
337
|
|
|
* @param array $methods |
|
338
|
|
|
* @returns string |
|
339
|
|
|
* @return bool|false|string |
|
340
|
|
|
* @return bool|false|string |
|
341
|
|
|
*/ |
|
342
|
|
|
public function fetchURL($url, $methods = ['fopen', 'curl', 'socket']) |
|
343
|
|
|
{ |
|
344
|
|
|
/** |
|
345
|
|
|
* December 21st 2010, Mathew Tinsley ([email protected]) |
|
346
|
|
|
* http://tinsology.net |
|
347
|
|
|
* |
|
348
|
|
|
* To the extent possible under law, Mathew Tinsley has waived all copyright and related or |
|
349
|
|
|
* neighboring rights to this work. There's absolutely no warranty. |
|
350
|
|
|
*/ |
|
351
|
|
|
if ('string' === gettype($methods)) { |
|
352
|
|
|
$methods = [$methods]; |
|
353
|
|
|
} elseif (!is_array($methods)) { |
|
354
|
|
|
return false; |
|
355
|
|
|
} |
|
356
|
|
|
foreach ($methods as $method) { |
|
357
|
|
|
switch ($method) { |
|
358
|
|
|
case 'fopen': |
|
359
|
|
|
//uses file_get_contents in place of fopen |
|
360
|
|
|
//allow_url_fopen must still be enabled |
|
361
|
|
|
if (ini_get('allow_url_fopen')) { |
|
362
|
|
|
$contents = file_get_contents($url); |
|
363
|
|
|
if (false !== $contents) { |
|
364
|
|
|
return $contents; |
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
break; |
|
368
|
|
|
case 'curl': |
|
369
|
|
|
if (function_exists('curl_init')) { |
|
370
|
|
|
$ch = curl_init(); |
|
371
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
|
372
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0); |
|
373
|
|
|
// return the value instead of printing the response to browser |
|
374
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
375
|
|
|
$result = curl_exec($ch); |
|
376
|
|
|
curl_close($ch); |
|
377
|
|
|
//return curl_exec($ch); |
|
378
|
|
|
return $result; |
|
379
|
|
|
} |
|
380
|
|
|
break; |
|
381
|
|
|
case 'socket': |
|
382
|
|
|
//make sure the url contains a protocol, otherwise $parts['host'] won't be set |
|
383
|
|
|
if (0 !== strpos($url, 'http://') && 0 !== strpos($url, 'https://')) { |
|
384
|
|
|
$url = 'http://' . $url; |
|
385
|
|
|
} |
|
386
|
|
|
$parts = parse_url($url); |
|
387
|
|
|
if ('https' === $parts['scheme']) { |
|
388
|
|
|
$target = 'ssl://' . $parts['host']; |
|
389
|
|
|
$port = isset($parts['port']) ? $parts['port'] : 443; |
|
390
|
|
|
} else { |
|
391
|
|
|
$target = $parts['host']; |
|
392
|
|
|
$port = isset($parts['port']) ? $parts['port'] : 80; |
|
393
|
|
|
} |
|
394
|
|
|
$page = isset($parts['path']) ? $parts['path'] : ''; |
|
395
|
|
|
$page .= isset($parts['query']) ? '?' . $parts['query'] : ''; |
|
396
|
|
|
$page .= isset($parts['fragment']) ? '#' . $parts['fragment'] : ''; |
|
397
|
|
|
$page = ('' == $page) ? '/' : $page; |
|
398
|
|
|
$fp = fsockopen($target, $port, $errno, $errstr, 15); |
|
399
|
|
|
if ($fp) { |
|
400
|
|
|
$headers = "GET $page HTTP/1.1\r\n"; |
|
401
|
|
|
$headers .= "Host: {$parts['host']}\r\n"; |
|
402
|
|
|
$headers .= "Connection: Close\r\n\r\n"; |
|
403
|
|
|
if (fwrite($fp, $headers)) { |
|
404
|
|
|
$resp = ''; |
|
405
|
|
|
//while not eof and an error does not occur when calling fgets |
|
406
|
|
|
while (!feof($fp) && false !== ($curr = fgets($fp, 128))) { |
|
407
|
|
|
$resp .= $curr; |
|
408
|
|
|
} |
|
409
|
|
|
if (isset($curr) && false !== $curr) { |
|
410
|
|
|
return substr(strstr($resp, "\r\n\r\n"), 3); |
|
411
|
|
|
} |
|
412
|
|
|
} |
|
413
|
|
|
fclose($fp); |
|
414
|
|
|
} |
|
415
|
|
|
break; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
return false; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* Smallworld_sanitize(array(array) ) |
|
424
|
|
|
* flatten multidimentional arrays to one dimentional |
|
425
|
|
|
* @param array $array |
|
426
|
|
|
* @return array |
|
427
|
|
|
*/ |
|
428
|
|
|
public function flatten($array) |
|
429
|
|
|
{ |
|
430
|
|
|
$return = []; |
|
431
|
|
|
while (count($array)) { |
|
432
|
|
|
$value = array_shift($array); |
|
433
|
|
|
if (is_array($value)) { |
|
434
|
|
|
foreach ($value as $sub) { |
|
435
|
|
|
$array[] = $sub; |
|
436
|
|
|
} |
|
437
|
|
|
} else { |
|
438
|
|
|
$return[] = $value; |
|
439
|
|
|
} |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
return $return; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* Smallworld_sanitize($string) |
|
447
|
|
|
* @param string $text |
|
448
|
|
|
* @returns string |
|
449
|
|
|
* @return string|string[] |
|
450
|
|
|
* @return string|string[] |
|
451
|
|
|
*/ |
|
452
|
|
|
public function Smallworld_sanitize($text) |
|
453
|
|
|
{ |
|
454
|
|
|
$text = htmlspecialchars($text, ENT_QUOTES); |
|
455
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
456
|
|
|
$text = $myts->displayTarea($text, 1, 1, 1, 1); |
|
457
|
|
|
$text = str_replace("\n\r", "\n", $text); |
|
458
|
|
|
$text = str_replace("\r\n", "\n", $text); |
|
459
|
|
|
$text = str_replace("\n", '<br>', $text); |
|
460
|
|
|
$text = str_replace('"', "'", $text); |
|
461
|
|
|
|
|
462
|
|
|
return $text; |
|
463
|
|
|
} |
|
464
|
|
|
} |
|
465
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.