Total Complexity | 240 |
Total Lines | 1881 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Utility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Utility, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class Utility extends Common\SysUtility |
||
38 | { |
||
39 | //--------------- Custom module methods ----------------------------- |
||
40 | |||
41 | /** |
||
42 | * getHandler() |
||
43 | * |
||
44 | * @param $name |
||
45 | * @param bool $optional |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public static function getHandler($name, $optional = false) |
||
50 | { |
||
51 | global $handlers, $xoopsModule; |
||
52 | |||
53 | $name = mb_strtolower(\trim($name)); |
||
54 | if (!isset($handlers[$name])) { |
||
55 | if (\is_file($hnd_file = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/class_' . $name . '.php')) { |
||
56 | require_once $hnd_file; |
||
57 | } |
||
58 | $class = 'wfl' . \ucfirst($name) . 'Handler'; |
||
59 | if (\class_exists($class)) { |
||
60 | $handlers[$name] = new $class($GLOBALS['xoopsDB']); |
||
61 | } |
||
62 | } |
||
63 | if (!$optional && !isset($handlers[$name])) { |
||
64 | \trigger_error( |
||
65 | '<div>Class <b>' . $class . '</b> does not exist.</div> |
||
|
|||
66 | <div>Handler Name: ' . $name, |
||
67 | \E_USER_ERROR |
||
68 | ) . '</div>'; |
||
69 | } |
||
70 | |||
71 | return $handlers[$name] ?? false; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param int $cid |
||
76 | * @param string $permType |
||
77 | * @param bool $redirect |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public static function checkGroups($cid = 0, $permType = 'WFLinkCatPerm', $redirect = false) |
||
82 | { |
||
83 | global $xoopsUser, $xoopsModule; |
||
84 | |||
85 | $groups = \is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
86 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
87 | if (!$grouppermHandler->checkRight($permType, $cid, $groups, $xoopsModule->getVar('mid'))) { |
||
88 | if (false === $redirect) { |
||
89 | return false; |
||
90 | } |
||
91 | |||
92 | \redirect_header('index.php', 3, _NOPERM); |
||
93 | } |
||
94 | |||
95 | return true; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param int $lid |
||
100 | * @return array|bool|false |
||
101 | */ |
||
102 | public static function getVoteDetails($lid = 0) |
||
103 | { |
||
104 | global $xoopsDB; |
||
105 | |||
106 | $sql = 'SELECT |
||
107 | COUNT(rating) AS rate, |
||
108 | MIN(rating) AS min_rate, |
||
109 | MAX(rating) AS max_rate, |
||
110 | AVG(rating) AS avg_rate, |
||
111 | COUNT(ratinguser) AS rating_user, |
||
112 | MAX(ratinguser) AS max_user, |
||
113 | MAX(title) AS max_title, |
||
114 | MIN(title) AS min_title, |
||
115 | sum(ratinguser = 0) AS null_ratinguser |
||
116 | FROM ' . $xoopsDB->prefix('wflinks_votedata'); |
||
117 | if ($lid > 0) { |
||
118 | $sql .= " WHERE lid = $lid"; |
||
119 | } |
||
120 | if (!$result = $xoopsDB->query($sql)) { |
||
121 | return false; |
||
122 | } |
||
123 | $ret = $xoopsDB->fetchArray($result); |
||
124 | |||
125 | return $ret; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @param int $sel_id |
||
130 | * |
||
131 | * @return array|bool |
||
132 | */ |
||
133 | public static function calculateVoteData($sel_id = 0) |
||
134 | { |
||
135 | $ret = []; |
||
136 | $ret['useravgrating'] = 0; |
||
137 | |||
138 | $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('wflinks_votedata'); |
||
139 | if (0 != $sel_id) { |
||
140 | ' WHERE lid = ' . $sel_id; |
||
141 | } |
||
142 | if (!$result = $xoopsDB->query($sql)) { |
||
143 | return false; |
||
144 | } |
||
145 | $ret['uservotes'] = $xoopsDB->getRowsNum($result); |
||
146 | while (list($rating) = $xoopsDB->fetchRow($result)) { |
||
147 | $ret['useravgrating'] += (int)$rating; |
||
148 | } |
||
149 | if ($ret['useravgrating'] > 0) { |
||
150 | $ret['useravgrating'] = \number_format($ret['useravgrating'] / $ret['uservotes'], 2); |
||
151 | } |
||
152 | |||
153 | return $ret; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param $array |
||
158 | * @param null $name |
||
159 | * @param null $def |
||
160 | * @param bool $strict |
||
161 | * @param int $lengthcheck |
||
162 | * |
||
163 | * @return array|int|mixed|null|string |
||
164 | */ |
||
165 | public static function cleanRequestVars($array, $name = null, $def = null, $strict = false, $lengthcheck = 15) |
||
166 | { |
||
167 | // Sanitise $_request for further use. This method gives more control and security. |
||
168 | // Method is more for functionality rather than beauty at the moment, will correct later. |
||
169 | unset($array['usercookie'], $array['PHPSESSID']); |
||
170 | |||
171 | if (\is_array($array) && null === $name) { |
||
172 | $globals = []; |
||
173 | foreach (\array_keys($array) as $k) { |
||
174 | $value = \strip_tags(\trim($array[$k])); |
||
175 | if ('' !== $value >= $lengthcheck) { |
||
176 | return null; |
||
177 | } |
||
178 | if (ctype_digit($value)) { |
||
179 | $value = (int)$value; |
||
180 | } else { |
||
181 | if (true === $strict) { |
||
182 | $value = \preg_replace('/\W/', '', \trim($value)); |
||
183 | } |
||
184 | $value = mb_strtolower((string)$value); |
||
185 | } |
||
186 | $globals[$k] = $value; |
||
187 | } |
||
188 | |||
189 | return $globals; |
||
190 | } |
||
191 | if (!\array_key_exists($name, $array) || !isset($array[$name])) { |
||
192 | return $def; |
||
193 | } |
||
194 | |||
195 | $value = \strip_tags(\trim($array[$name])); |
||
196 | if (ctype_digit($value)) { |
||
197 | $value = (int)$value; |
||
198 | } else { |
||
199 | if (true === $strict) { |
||
200 | $value = \preg_replace('/\W/', '', \trim($value)); |
||
201 | } |
||
202 | $value = mb_strtolower((string)$value); |
||
203 | } |
||
204 | |||
205 | return $value; |
||
206 | } |
||
207 | |||
208 | // toolbar() |
||
209 | // @return |
||
210 | |||
211 | /** |
||
212 | * @param int $cid |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | public static function getToolbar($cid = 0) |
||
217 | { |
||
218 | $toolbar = '[ '; |
||
219 | if (true === static::checkGroups($cid, 'WFLinkSubPerm')) { |
||
220 | $toolbar .= "<a href='submit.php?cid=" . $cid . "'>" . _MD_WFL_SUBMITLINK . '</a> | '; |
||
221 | } |
||
222 | $toolbar .= "<a href='newlist.php?newlinkshowdays=7'>" . _MD_WFL_LATESTLIST . "</a> | <a href='topten.php?list=hit'>" . _MD_WFL_POPULARITY . '</a> ]'; |
||
223 | |||
224 | return $toolbar; |
||
225 | } |
||
226 | |||
227 | // displayicons() |
||
228 | // @param $time |
||
229 | // @param integer $status |
||
230 | // @param integer $counter |
||
231 | // @return |
||
232 | |||
233 | /** |
||
234 | * @param $time |
||
235 | * @param int $status |
||
236 | * @param int $counter |
||
237 | * |
||
238 | * @return string |
||
239 | */ |
||
240 | public static function displayIcons($time, $status = 0, $counter = 0) |
||
241 | { |
||
242 | global $xoopsModule; |
||
243 | /** @var Wflinks\Helper $helper */ |
||
244 | $helper = Wflinks\Helper::getInstance(); |
||
245 | |||
246 | $new = ''; |
||
247 | $pop = ''; |
||
248 | |||
249 | $newdate = (\time() - (86400 * (int)$helper->getConfig('daysnew'))); |
||
250 | $popdate = (\time() - (86400 * (int)$helper->getConfig('daysupdated'))); |
||
251 | |||
252 | if (3 != $helper->getConfig('displayicons')) { |
||
253 | if ($newdate < $time) { |
||
254 | if ((int)$status > 1) { |
||
255 | if (1 == $helper->getConfig('displayicons')) { |
||
256 | $new = ' <img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/update.png" alt="" align="top">'; |
||
257 | } |
||
258 | if (2 == $helper->getConfig('displayicons')) { |
||
259 | $new = '<i>Updated!</i>'; |
||
260 | } |
||
261 | } else { |
||
262 | if (1 == $helper->getConfig('displayicons')) { |
||
263 | $new = ' <img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/new.png" alt="" align="top">'; |
||
264 | } |
||
265 | if (2 == $helper->getConfig('displayicons')) { |
||
266 | $new = '<i>New!</i>'; |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | if ($popdate > $time) { |
||
271 | if ($counter >= $helper->getConfig('popular')) { |
||
272 | if (1 == $helper->getConfig('displayicons')) { |
||
273 | $pop = ' <img src ="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/popular.png" alt="" align="top">'; |
||
274 | } |
||
275 | if (2 == $helper->getConfig('displayicons')) { |
||
276 | $pop = '<i>Popular!</i>'; |
||
277 | } |
||
278 | } |
||
279 | } |
||
280 | } |
||
281 | $icons = $new . ' ' . $pop; |
||
282 | |||
283 | return $icons; |
||
284 | } |
||
285 | |||
286 | // updaterating() |
||
287 | // @param $sel_id |
||
288 | // @return updates rating data in itemtable for a given item |
||
289 | |||
290 | /** |
||
291 | * @param $sel_id |
||
292 | */ |
||
293 | public static function updateRating($sel_id) |
||
294 | { |
||
295 | global $xoopsDB; |
||
296 | $query = 'SELECT rating FROM ' . $xoopsDB->prefix('wflinks_votedata') . ' WHERE lid=' . $sel_id; |
||
297 | $voteresult = $xoopsDB->query($query); |
||
298 | $votesDB = $xoopsDB->getRowsNum($voteresult); |
||
299 | $totalrating = 0; |
||
300 | while (list($rating) = $xoopsDB->fetchRow($voteresult)) { |
||
301 | $totalrating += $rating; |
||
302 | } |
||
303 | $finalrating = $totalrating / $votesDB; |
||
304 | $finalrating = \number_format($finalrating, 4); |
||
305 | $sql = \sprintf('UPDATE `%s` SET rating = %u, votes = %u WHERE lid = %u', $xoopsDB->prefix('wflinks_links'), $finalrating, $votesDB, $sel_id); |
||
306 | $xoopsDB->query($sql); |
||
307 | } |
||
308 | |||
309 | // totalcategory() |
||
310 | // @param integer $pid |
||
311 | // @return |
||
312 | |||
313 | /** |
||
314 | * @param int $pid |
||
315 | * |
||
316 | * @return int |
||
317 | */ |
||
318 | public static function getTotalCategory($pid = 0) |
||
319 | { |
||
320 | global $xoopsDB; |
||
321 | |||
322 | $sql = 'SELECT cid FROM ' . $xoopsDB->prefix('wflinks_cat'); |
||
323 | if ($pid > 0) { |
||
324 | $sql .= ' WHERE pid=0'; |
||
325 | } |
||
326 | $result = $xoopsDB->query($sql); |
||
327 | $catlisting = 0; |
||
328 | while (list($cid) = $xoopsDB->fetchRow($result)) { |
||
329 | if (static::checkGroups($cid)) { |
||
330 | ++$catlisting; |
||
331 | } |
||
332 | } |
||
333 | |||
334 | return $catlisting; |
||
335 | } |
||
336 | |||
337 | // static::getTotalItems() |
||
338 | // @param integer $sel_id |
||
339 | // @param integer $get_child |
||
340 | // @param integer $return_sql |
||
341 | // @return |
||
342 | |||
343 | /** |
||
344 | * @param int $sel_id |
||
345 | * @param int $get_child |
||
346 | * @param int $return_sql |
||
347 | * |
||
348 | * @return mixed |
||
349 | */ |
||
350 | public static function getTotalItems($sel_id = 0, $get_child = 0, $return_sql = 0) |
||
351 | { |
||
352 | global $xoopsDB, $mytree, $_check_array; |
||
353 | |||
354 | if ($sel_id > 0) { |
||
355 | $sql = 'SELECT DISTINCT a.lid, a.cid, published FROM ' |
||
356 | . $xoopsDB->prefix('wflinks_links') |
||
357 | . ' a LEFT JOIN ' |
||
358 | . $xoopsDB->prefix('wflinks_altcat') |
||
359 | . ' b ' |
||
360 | . 'ON b.lid=a.lid ' |
||
361 | . 'WHERE published > 0 AND published <= ' |
||
362 | . \time() |
||
363 | . ' AND (expired = 0 OR expired > ' |
||
364 | . \time() |
||
365 | . ') AND offline = 0 ' |
||
366 | . ' AND (b.cid=a.cid OR (a.cid=' |
||
367 | . $sel_id |
||
368 | . ' OR b.cid=' |
||
369 | . $sel_id |
||
370 | . ')) '; |
||
371 | } else { |
||
372 | $sql = 'SELECT lid, cid, published FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE offline = 0 AND published > 0 AND published <= ' . \time() . ' AND (expired = 0 OR expired > ' . \time() . ')'; |
||
373 | } |
||
374 | if (1 == $return_sql) { |
||
375 | return $sql; |
||
376 | } |
||
377 | |||
378 | $count = 0; |
||
379 | $published_date = 0; |
||
380 | |||
381 | $items = []; |
||
382 | $result = $xoopsDB->query($sql); |
||
383 | while (list($lid, $cid, $published) = $xoopsDB->fetchRow($result)) { |
||
384 | if (true === static::checkGroups()) { |
||
385 | ++$count; |
||
386 | $published_date = ($published > $published_date) ? $published : $published_date; |
||
387 | } |
||
388 | } |
||
389 | |||
390 | $child_count = 0; |
||
391 | if (1 == $get_child) { |
||
392 | $items = $mytree->getAllChildId($sel_id); |
||
393 | foreach ($items as $item) { |
||
394 | $query2 = 'SELECT DISTINCT a.lid, a.cid, published FROM ' |
||
395 | . $xoopsDB->prefix('wflinks_links') |
||
396 | . ' a LEFT JOIN ' |
||
397 | . $xoopsDB->prefix('wflinks_altcat') |
||
398 | . ' b ' |
||
399 | . 'ON b.lid=a.lid ' |
||
400 | . 'WHERE published > 0 AND published <= ' |
||
401 | . \time() |
||
402 | . ' AND (expired = 0 OR expired > ' |
||
403 | . \time() |
||
404 | . ') AND offline = 0 ' |
||
405 | . ' AND (b.cid=a.cid OR (a.cid=' |
||
406 | . $item |
||
407 | . ' OR b.cid=' |
||
408 | . $item |
||
409 | . ')) '; |
||
410 | |||
411 | $result2 = $xoopsDB->query($query2); |
||
412 | while (list($lid, $published) = $xoopsDB->fetchRow($result2)) { |
||
413 | if (0 == $published) { |
||
414 | continue; |
||
415 | } |
||
416 | $published_date = ($published > $published_date) ? $published : $published_date; |
||
417 | ++$child_count; |
||
418 | } |
||
419 | } |
||
420 | } |
||
421 | $info['count'] = $count + $child_count; |
||
422 | $info['published'] = $published_date; |
||
423 | |||
424 | return $info; |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * @param string $indeximage |
||
429 | * @param string $indexheading |
||
430 | * |
||
431 | * @return string |
||
432 | */ |
||
433 | public static function getImageHeader($indeximage = '', $indexheading = '') |
||
434 | { |
||
435 | global $xoopsDB; |
||
436 | /** @var Wflinks\Helper $helper */ |
||
437 | $helper = Wflinks\Helper::getInstance(); |
||
438 | |||
439 | if ('' == $indeximage) { |
||
440 | $result = $xoopsDB->query('SELECT indeximage, indexheading FROM ' . $xoopsDB->prefix('wflinks_indexpage')); |
||
441 | list($indeximage, $indexheading) = $xoopsDB->fetchRow($result); |
||
442 | } |
||
443 | |||
444 | $image = ''; |
||
445 | if (!empty($indeximage)) { |
||
446 | $image = static::displayImage($indeximage, "'index.php'", $helper->getConfig('mainimagedir'), $indexheading); |
||
447 | } |
||
448 | |||
449 | return $image; |
||
450 | } |
||
451 | |||
452 | /** |
||
453 | * @param string $image |
||
454 | * @param string $path |
||
455 | * @param string $imgsource |
||
456 | * @param string $alttext |
||
457 | * |
||
458 | * @return string |
||
459 | */ |
||
460 | public static function displayImage($image = '', $path = '', $imgsource = '', $alttext = '') |
||
461 | { |
||
462 | global $xoopsConfig, $xoopsUser, $xoopsModule; |
||
463 | |||
464 | $showimage = ''; |
||
465 | // Check to see if link is given |
||
466 | if ($path) { |
||
467 | $showimage = '<a href=' . $path . '>'; |
||
468 | } |
||
469 | |||
470 | // checks to see if the file is valid else displays default blank image |
||
471 | if (!\is_dir(XOOPS_ROOT_PATH . "/{$imgsource}/{$image}") |
||
472 | && \is_dir(XOOPS_ROOT_PATH . "/{$imgsource}/{$image}")) { |
||
473 | $showimage .= "<img src='" . XOOPS_URL . "/{$imgsource}/{$image}' border='0' alt='" . $alttext . "'></a>"; |
||
474 | } elseif ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
||
475 | $showimage .= "<img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/brokenimg.gif' alt='" . _MD_WFL_ISADMINNOTICE . "'></a>"; |
||
476 | } else { |
||
477 | $showimage .= "<img src='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/assets/images/blank.gif' alt='" . $alttext . "'></a>"; |
||
478 | } |
||
479 | |||
480 | \clearstatcache(); |
||
481 | |||
482 | return $showimage; |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * @return string |
||
487 | */ |
||
488 | public static function getLetters() |
||
489 | { |
||
490 | global $xoopsModule; |
||
491 | |||
492 | $letterchoice = '<div>' . _MD_WFL_BROWSETOTOPIC . '</div>'; |
||
493 | $letterchoice .= '[ '; |
||
494 | $alphabet = [ |
||
495 | '0', |
||
496 | '1', |
||
497 | '2', |
||
498 | '3', |
||
499 | '4', |
||
500 | '5', |
||
501 | '6', |
||
502 | '7', |
||
503 | '8', |
||
504 | '9', |
||
505 | 'A', |
||
506 | 'B', |
||
507 | 'C', |
||
508 | 'D', |
||
509 | 'E', |
||
510 | 'F', |
||
511 | 'G', |
||
512 | 'H', |
||
513 | 'I', |
||
514 | 'J', |
||
515 | 'K', |
||
516 | 'L', |
||
517 | 'M', |
||
518 | 'N', |
||
519 | 'O', |
||
520 | 'P', |
||
521 | 'Q', |
||
522 | 'R', |
||
523 | 'S', |
||
524 | 'T', |
||
525 | 'U', |
||
526 | 'V', |
||
527 | 'W', |
||
528 | 'X', |
||
529 | 'Y', |
||
530 | 'Z', |
||
531 | ]; |
||
532 | $num = \count($alphabet) - 1; |
||
533 | $counter = 0; |
||
534 | // while (list(, $ltr) = each($alphabet)) { |
||
535 | foreach ($alphabet as $key => $ltr) { |
||
536 | $letterchoice .= "<a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/viewcat.php?list=$ltr'>$ltr</a>"; |
||
537 | if ($counter == \round($num / 2)) { |
||
538 | $letterchoice .= ' ]<br>[ '; |
||
539 | } elseif ($counter != $num) { |
||
540 | $letterchoice .= ' | '; |
||
541 | } |
||
542 | ++$counter; |
||
543 | } |
||
544 | $letterchoice .= ' ]'; |
||
545 | |||
546 | return $letterchoice; |
||
547 | } |
||
548 | |||
549 | /** |
||
550 | * @param $published |
||
551 | * |
||
552 | * @return mixed |
||
553 | */ |
||
554 | public static function isNewImage($published) |
||
555 | { |
||
556 | global $xoopsModule, $xoopsDB; |
||
557 | |||
558 | $oneday = (\time() - (86400 * 1)); |
||
559 | $threedays = (\time() - (86400 * 3)); |
||
560 | $week = (\time() - (86400 * 7)); |
||
561 | |||
562 | $path = 'modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon'; |
||
563 | |||
564 | if ($published > 0 && $published < $week) { |
||
565 | $indicator['image'] = "$path/linkload4.gif"; |
||
566 | $indicator['alttext'] = _MD_WFL_NEWLAST; |
||
567 | } elseif ($published >= $week && $published < $threedays) { |
||
568 | $indicator['image'] = "$path/linkload3.gif"; |
||
569 | $indicator['alttext'] = _MD_WFL_NEWTHIS; |
||
570 | } elseif ($published >= $threedays && $published < $oneday) { |
||
571 | $indicator['image'] = "$path/linkload2.gif"; |
||
572 | $indicator['alttext'] = _MD_WFL_THREE; |
||
573 | } elseif ($published >= $oneday) { |
||
574 | $indicator['image'] = "$path/linkload1.gif"; |
||
575 | $indicator['alttext'] = _MD_WFL_TODAY; |
||
576 | } else { |
||
577 | $indicator['image'] = "$path/linkload.gif"; |
||
578 | $indicator['alttext'] = _MD_WFL_NO_FILES; |
||
579 | } |
||
580 | |||
581 | return $indicator; |
||
582 | } |
||
583 | |||
584 | /** |
||
585 | * @param $haystack |
||
586 | * @param $needle |
||
587 | * |
||
588 | * @return string |
||
589 | */ |
||
590 | public static function searchString($haystack, $needle) |
||
591 | { |
||
592 | return mb_substr($haystack, 0, mb_strpos($haystack, $needle) + 1); |
||
593 | } |
||
594 | |||
595 | /** |
||
596 | * @param $selected |
||
597 | * @param $dirarray |
||
598 | * @param $namearray |
||
599 | */ |
||
600 | public static function getDirSelectOption($selected, $dirarray, $namearray) |
||
601 | { |
||
602 | echo "<select size='1' name='workd' onchange='location.href=\"upload.php?rootpath=\"+this.options[this.selectedIndex].value'>"; |
||
603 | echo "<option value=''>--------------------------------------</option>"; |
||
604 | foreach ($namearray as $namearray => $workd) { |
||
605 | if ($workd === $selected) { |
||
606 | $opt_selected = 'selected'; |
||
607 | } else { |
||
608 | $opt_selected = ''; |
||
609 | } |
||
610 | echo "<option value='" . \htmlspecialchars($namearray, \ENT_QUOTES) . "' $opt_selected>" . $workd . '</option>'; |
||
611 | } |
||
612 | echo '</select>'; |
||
613 | } |
||
614 | |||
615 | /** |
||
616 | * @param $FILES |
||
617 | * @param string $uploaddir |
||
618 | * @param string $allowed_mimetypes |
||
619 | * @param string $redirecturl |
||
620 | * @param int $num |
||
621 | * @param int $redirect |
||
622 | * @param int $usertype |
||
623 | * |
||
624 | * @return array|null |
||
625 | */ |
||
626 | public static function uploadFiles( |
||
627 | $FILES, |
||
628 | $uploaddir = 'uploads', |
||
629 | $allowed_mimetypes = '', |
||
630 | $redirecturl = 'index.php', |
||
631 | $num = 0, |
||
632 | $redirect = 0, |
||
633 | $usertype = 1 |
||
634 | ) { |
||
635 | global $FILES, $xoopsConfig, $xoopsModule; |
||
636 | /** @var Wflinks\Helper $helper */ |
||
637 | $helper = Wflinks\Helper::getInstance(); |
||
638 | |||
639 | $down = []; |
||
640 | // require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/uploader.php'; |
||
641 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
642 | if (empty($allowed_mimetypes)) { |
||
643 | $allowed_mimetypes = wfl_getmime($FILES['userfile']['name'], $usertype); |
||
644 | } |
||
645 | $upload_dir = XOOPS_ROOT_PATH . '/' . $uploaddir . '/'; |
||
646 | |||
647 | $maxfilesize = $helper->getConfig('maxfilesize'); |
||
648 | $maxfilewidth = $helper->getConfig('maximgwidth'); |
||
649 | $maxfileheight = $helper->getConfig('maximgheight'); |
||
650 | |||
651 | $uploader = new \XoopsMediaUploader($upload_dir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight); |
||
652 | // $uploader->noAdminSizeCheck(1); |
||
653 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||
654 | if (!$uploader->upload()) { |
||
655 | $errors = $uploader->getErrors(); |
||
656 | \redirect_header($redirecturl, 2, $errors); |
||
657 | } elseif ($redirect) { |
||
658 | \redirect_header($redirecturl, 1, _AM_WFL_UPLOADFILE); |
||
659 | } else { |
||
660 | if (\is_file($uploader->savedDestination)) { |
||
661 | $down['url'] = XOOPS_URL . '/' . $uploaddir . '/' . mb_strtolower($uploader->savedFileName); |
||
662 | $down['size'] = \filesize(XOOPS_ROOT_PATH . '/' . $uploaddir . '/' . mb_strtolower($uploader->savedFileName)); |
||
663 | } |
||
664 | |||
665 | return $down; |
||
666 | } |
||
667 | |||
668 | } else { |
||
669 | $errors = $uploader->getErrors(); |
||
670 | \redirect_header($redirecturl, 1, $errors); |
||
671 | } |
||
672 | |||
673 | return null; |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * @param $forumid |
||
678 | * |
||
679 | * @return mixed |
||
680 | */ |
||
681 | public static function getForum($forumid) |
||
682 | { |
||
683 | global $xoopsDB, $xoopsConfig; |
||
684 | |||
685 | echo "<select name='forumid'>"; |
||
686 | echo "<option value='0'>----------------------</option>"; |
||
687 | if ($forumid < 4) { |
||
688 | $result = $xoopsDB->query('SELECT forum_name, forum_id FROM ' . $xoopsDB->prefix('bb_forums') . ' ORDER BY forum_id'); |
||
689 | } else { |
||
690 | $result = $xoopsDB->query('SELECT forum_name, forum_id FROM ' . $xoopsDB->prefix('bbex_forums') . ' ORDER BY forum_id'); |
||
691 | } |
||
692 | while (list($forum_name, $forum_id) = $xoopsDB->fetchRow($result)) { |
||
693 | if ($forum_id == $forumid) { |
||
694 | $opt_selected = 'selected'; |
||
695 | } else { |
||
696 | $opt_selected = ''; |
||
697 | } |
||
698 | echo "<option value='" . $forum_id . "' $opt_selected>" . $forum_name . '</option>'; |
||
699 | } |
||
700 | echo '</select></div>'; |
||
701 | |||
702 | return $forumid; |
||
703 | } |
||
704 | |||
705 | /** |
||
706 | * @param $heading |
||
707 | */ |
||
708 | public static function getLinkListHeader($heading) |
||
709 | { |
||
710 | echo " |
||
711 | <!-- <h4 style='font-weight: bold; color: #0A3760;'>" . $heading . "</h4>\n --> |
||
712 | <table width='100%' cellspacing='1' class='outer' style='font-size: smaller;' summary>\n |
||
713 | <tr>\n |
||
714 | <th class='txtcenter;'>" . _AM_WFL_MINDEX_ID . "</th>\n |
||
715 | <th style='text-align: left;'><b>" . _AM_WFL_MINDEX_TITLE . "</th>\n |
||
716 | <th style='text-align: left;'><b>" . _AM_WFL_CATTITLE . "</th>\n |
||
717 | <th class='txtcenter;'>" . _AM_WFL_MINDEX_POSTER . "</th>\n |
||
718 | <th class='txtcenter;'>" . _AM_WFL_MINDEX_PUBLISH . "</th>\n |
||
719 | <th class='txtcenter;'>" . _AM_WFL_MINDEX_EXPIRE . "</th>\n |
||
720 | <th class='txtcenter;'>" . _AM_WFL_MINDEX_ONLINE . "</th>\n |
||
721 | <th class='txtcenter;'>" . _AM_WFL_MINDEX_ACTION . "</th>\n |
||
722 | </tr>\n |
||
723 | "; |
||
724 | } |
||
725 | |||
726 | /** |
||
727 | * @param $published |
||
728 | */ |
||
729 | public static function getLinkListBody($published) |
||
730 | { |
||
731 | global $myts, $imageArray, $xoopsModule; |
||
732 | /** @var Wflinks\Helper $helper */ |
||
733 | $helper = Wflinks\Helper::getInstance(); |
||
734 | \xoops_load('XoopsUserUtility'); |
||
735 | $lid = $published['lid']; |
||
736 | $cid = $published['cid']; |
||
737 | |||
738 | $title = "<a href='../singlelink.php?cid=" . $published['cid'] . '&lid=' . $published['lid'] . "'>" . htmlspecialchars(\trim($published['title'])) . '</a>'; |
||
739 | $maintitle = \urlencode(htmlspecialchars(\trim($published['title']))); |
||
740 | $cattitle = static::getCategoryTitle($published['cid']); |
||
741 | $submitter = \XoopsUserUtility::getUnameFromId($published['submitter']); |
||
742 | $hwhoisurl = \str_replace('http://', '', $published['url']); |
||
743 | $submitted = \formatTimestamp($published['date'], $helper->getConfig('dateformat')); |
||
744 | $publish = ($published['published'] > 0) ? \formatTimestamp($published['published'], $helper->getConfig('dateformatadmin')) : 'Not Published'; |
||
745 | $expires = $published['expired'] ? \formatTimestamp($published['expired'], $helper->getConfig('dateformatadmin')) : _AM_WFL_MINDEX_NOTSET; |
||
746 | // if ( ( $published['published'] && $published['published'] < time() ) && $published['offline'] == 0 ) { |
||
747 | // $published_status = $imageArray['online']; |
||
748 | // } else { |
||
749 | // $published_status = ( $published['published'] == 0 ) ? "<a href='newlinks.php'>" . $imageArray['offline'] . "</a>" : $imageArray['offline']; |
||
750 | // } |
||
751 | if (0 == $published['offline'] |
||
752 | && ($published['published'] && $published['published'] < \time()) |
||
753 | && (($published['expired'] && $published['expired'] > \time()) || 0 == $published['expired'])) { |
||
754 | $published_status = $imageArray['online']; |
||
755 | } elseif (0 == $published['offline'] && ($published['expired'] && $published['expired'] < \time())) { |
||
756 | $published_status = $imageArray['expired']; |
||
757 | } else { |
||
758 | $published_status = (0 == $published['published']) ? "<a href='newlinks.php'>" . $imageArray['offline'] . '</a>' : $imageArray['offline']; |
||
759 | } |
||
760 | $icon = "<a href='main.php?op=edit&lid=" . $lid . "' title='" . _AM_WFL_ICO_EDIT . "'>" . $imageArray['editimg'] . '</a> '; |
||
761 | $icon .= "<a href='main.php?op=delete&lid=" . $lid . "' title='" . _AM_WFL_ICO_DELETE . "'>" . $imageArray['deleteimg'] . '</a> '; |
||
762 | $icon .= "<a href='altcat.php?op=main&cid=" . $cid . '&lid=' . $lid . '&title=' . htmlspecialchars(\trim($published['title'])) . "' title='" . _AM_WFL_ALTCAT_CREATEF . "'>" . $imageArray['altcat'] . '</a> '; |
||
763 | $icon .= '<a href="http://whois.domaintools.com/' . $hwhoisurl . '" target="_blank"><img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/domaintools.png" alt="WHOIS" title="WHOIS" align="absmiddle"></a>'; |
||
764 | |||
765 | echo " |
||
766 | <tr class='txtcenter;'>\n |
||
767 | <td class='head'><small>" . $lid . "</small></td>\n |
||
768 | <td class='even' style='text-align: left;'><small>" . $title . "</small></td>\n |
||
769 | <td class='even' style='text-align: left;'><small>" . $cattitle . "</small></td>\n |
||
770 | <td class='even'><small>" . $submitter . "</small></td>\n |
||
771 | <td class='even'><small>" . $publish . "</small></td>\n |
||
772 | <td class='even'><small>" . $expires . "</small></td>\n |
||
773 | <td class='even' width='4%'>" . $published_status . "</td>\n |
||
774 | <td class='even' style='text-align: center; width: 6%; white-space: nowrap;'>$icon</td>\n |
||
775 | </tr>\n |
||
776 | "; |
||
777 | unset($published); |
||
778 | } |
||
779 | |||
780 | /** |
||
781 | * @param $catt |
||
782 | * |
||
783 | * @return mixed |
||
784 | */ |
||
785 | public static function getCategoryTitle($catt) |
||
786 | { |
||
787 | global $xoopsDB; |
||
788 | $sql = 'SELECT title FROM ' . $xoopsDB->prefix('wflinks_cat') . ' WHERE cid=' . $catt; |
||
789 | $result = $xoopsDB->query($sql); |
||
790 | $result = $xoopsDB->fetchArray($result); |
||
791 | |||
792 | return $result['title']; |
||
793 | } |
||
794 | |||
795 | public static function getLinkListFooter() |
||
796 | { |
||
797 | echo "<tr class='txtcenter;'>\n<td class='head' colspan='7'>" . _AM_WFL_MINDEX_NOLINKSFOUND . "</td>\n</tr>\n"; |
||
798 | } |
||
799 | |||
800 | /** |
||
801 | * @param $pubrowamount |
||
802 | * @param $start |
||
803 | * @param string $art |
||
804 | * @param string $_this |
||
805 | * |
||
806 | * @return bool|null |
||
807 | */ |
||
808 | public static function getLinkListPageNav($pubrowamount, $start, $art = 'art', $_this = '') |
||
809 | { |
||
810 | /** @var Wflinks\Helper $helper */ |
||
811 | $helper = Wflinks\Helper::getInstance(); |
||
812 | |||
813 | echo "</table>\n"; |
||
814 | if ($pubrowamount < $helper->getConfig('admin_perpage')) { |
||
815 | return false; |
||
816 | } |
||
817 | // Display Page Nav if published is > total display pages amount. |
||
818 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
819 | // $page = ( $pubrowamount > $helper->getConfig('admin_perpage') ) ? _AM_WFL_MINDEX_PAGE : ''; |
||
820 | $pagenav = new \XoopsPageNav($pubrowamount, $helper->getConfig('admin_perpage'), $start, 'st' . $art, $_this); |
||
821 | echo '<div align="right" style="padding: 8px;">' . $pagenav->renderNav() . '</div>'; |
||
822 | |||
823 | return null; |
||
824 | } |
||
825 | |||
826 | /** |
||
827 | * @param $pubrowamount |
||
828 | * @param $start |
||
829 | * @param string $art |
||
830 | * @param string $_this |
||
831 | * |
||
832 | * @return bool|null |
||
833 | */ |
||
834 | public static function getLinkListPageNavLeft($pubrowamount, $start, $art = 'art', $_this = '') |
||
835 | { |
||
836 | /** @var Wflinks\Helper $helper */ |
||
837 | $helper = Wflinks\Helper::getInstance(); |
||
838 | |||
839 | // echo "</table>\n"; |
||
840 | if ($pubrowamount < $helper->getConfig('admin_perpage')) { |
||
841 | return false; |
||
842 | } |
||
843 | // Display Page Nav if published is > total display pages amount. |
||
844 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
845 | // $page = ( $pubrowamount > $helper->getConfig('admin_perpage') ) ? _AM_WFL_MINDEX_PAGE : ''; |
||
846 | $pagenav = new \XoopsPageNav($pubrowamount, $helper->getConfig('admin_perpage'), $start, 'st' . $art, $_this); |
||
847 | echo '<div align="left" style="padding: 8px;">' . $pagenav->renderNav() . '</div>'; |
||
848 | |||
849 | return null; |
||
850 | } |
||
851 | |||
852 | // Retreive an editor according to the module's option "form_options" |
||
853 | |||
854 | /** |
||
855 | * @param $caption |
||
856 | * @param $name |
||
857 | * @param $value |
||
858 | * |
||
859 | * @return bool|\XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormHtmlarea|\XoopsFormTextArea |
||
860 | */ |
||
861 | public static function getWysiwygForm($caption, $name, $value) |
||
862 | { |
||
863 | global $xoopsUser, $xoopsModule; |
||
864 | /** @var Wflinks\Helper $helper */ |
||
865 | $helper = Wflinks\Helper::getInstance(); |
||
866 | |||
867 | $editor = false; |
||
868 | $x22 = false; |
||
869 | $xv = \str_replace('XOOPS ', '', \XOOPS_VERSION); |
||
870 | if ('2' == mb_substr($xv, 2, 1)) { |
||
871 | $x22 = true; |
||
872 | } |
||
873 | $editor_configs = []; |
||
874 | $editor_configs['name'] = $name; |
||
875 | $editor_configs['value'] = $value; |
||
876 | $editor_configs['rows'] = 35; |
||
877 | $editor_configs['cols'] = 60; |
||
878 | $editor_configs['width'] = '100%'; |
||
879 | $editor_configs['height'] = '400px'; |
||
880 | |||
881 | $isadmin = ((\is_object($xoopsUser) && null !== $xoopsUser) |
||
882 | && $xoopsUser->isAdmin($xoopsModule->mid())); |
||
883 | if (true === $isadmin) { |
||
884 | $formuser = $helper->getConfig('form_options'); |
||
885 | } else { |
||
886 | $formuser = $helper->getConfig('form_optionsuser'); |
||
887 | } |
||
888 | |||
889 | switch ($formuser) { |
||
890 | case 'htmlarea': |
||
891 | if ($x22) { |
||
892 | if (\is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
||
893 | require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
||
894 | $editor = new \XoopsFormHtmlarea($caption, $name, $value); |
||
895 | } |
||
896 | } else { |
||
897 | $editor = new \XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
||
898 | } |
||
899 | break; |
||
900 | case 'dhtml': |
||
901 | if ($x22) { |
||
902 | $editor = new \XoopsFormEditor($caption, 'dhtmltextarea', $editor_configs); |
||
903 | } else { |
||
904 | $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
||
905 | } |
||
906 | break; |
||
907 | case 'textarea': |
||
908 | $editor = new \XoopsFormTextArea($caption, $name, $value); |
||
909 | break; |
||
910 | case 'tinyeditor': |
||
911 | if ($x22) { |
||
912 | $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
||
913 | } else { |
||
914 | if (\is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
||
915 | require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
||
916 | $editor = new \XoopsFormTinyeditorTextArea( |
||
917 | [ |
||
918 | 'caption' => $caption, |
||
919 | 'name' => $name, |
||
920 | 'value' => $value, |
||
921 | 'width' => '100%', |
||
922 | 'height' => '400px', |
||
923 | ] |
||
924 | ); |
||
925 | } elseif ($dhtml) { |
||
926 | $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 50, 60); |
||
927 | } else { |
||
928 | $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
||
929 | } |
||
930 | } |
||
931 | break; |
||
932 | case 'dhtmlext': |
||
933 | if ($x22) { |
||
934 | $editor = new \XoopsFormEditor($caption, 'dhtmlext', $editor_configs); |
||
935 | } else { |
||
936 | if (\is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/dhtmlext/dhtmlext.php')) { |
||
937 | require_once XOOPS_ROOT_PATH . '/class/xoopseditor/dhtmlext/dhtmlext.php'; |
||
938 | $editor = new \XoopsFormDhtmlTextAreaExtended($caption, $name, $value, 10, 50); |
||
939 | } elseif ($dhtml) { |
||
940 | $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 50, 60); |
||
941 | } else { |
||
942 | $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
||
943 | } |
||
944 | } |
||
945 | break; |
||
946 | case 'tinymce': |
||
947 | if ($x22) { |
||
948 | $editor = new \XoopsFormEditor($caption, 'tinymce', $editor_configs); |
||
949 | } else { |
||
950 | if (\is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinymce/formtinymce.php')) { |
||
951 | require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinymce/formtinymce.php'; |
||
952 | $editor = new \XoopsFormTinymce( |
||
953 | [ |
||
954 | 'caption' => $caption, |
||
955 | 'name' => $name, |
||
956 | 'value' => $value, |
||
957 | 'width' => '100%', |
||
958 | 'height' => '400px', |
||
959 | ] |
||
960 | ); |
||
961 | } elseif (\is_readable(XOOPS_ROOT_PATH . '/editors/tinymce/formtinymce.php')) { |
||
962 | require_once XOOPS_ROOT_PATH . '/editors/tinymce/formtinymce.php'; |
||
963 | $editor = new \XoopsFormTinymce( |
||
964 | [ |
||
965 | 'caption' => $caption, |
||
966 | 'name' => $name, |
||
967 | 'value' => $value, |
||
968 | 'width' => '100%', |
||
969 | 'height' => '400px', |
||
970 | ] |
||
971 | ); |
||
972 | } elseif ($dhtml) { |
||
973 | $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
||
974 | } else { |
||
975 | $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
||
976 | } |
||
977 | } |
||
978 | break; |
||
979 | } |
||
980 | |||
981 | return $editor; |
||
982 | } |
||
983 | |||
984 | /** |
||
985 | * @param $countryn |
||
986 | * |
||
987 | * @return mixed |
||
988 | */ |
||
989 | public static function getCountryName($countryn) |
||
990 | { |
||
991 | $country_array = [ |
||
992 | '' => 'Unknown', |
||
993 | '-' => 'Unknown', |
||
994 | 'AD' => 'Andorra', |
||
995 | 'AE' => 'United Arab Emirates', |
||
996 | 'AF' => 'Afghanistan', |
||
997 | 'AG' => 'Antigua and Barbuda', |
||
998 | 'AI' => 'Anguilla', |
||
999 | 'AL' => 'Albania', |
||
1000 | 'AM' => 'Armenia', |
||
1001 | 'AN' => 'Netherlands Antilles', |
||
1002 | 'AO' => 'Angola', |
||
1003 | 'AQ' => 'Antarctica', |
||
1004 | 'AR' => 'Argentina', |
||
1005 | 'AS' => 'American Samoa', |
||
1006 | 'AT' => 'Austria', |
||
1007 | 'AU' => 'Australia', |
||
1008 | 'AW' => 'Aruba', |
||
1009 | 'AX' => 'Åland Islands', // Added |
||
1010 | 'AZ' => 'Azerbaijan', |
||
1011 | 'BA' => 'Bosnia and Herzegovina', |
||
1012 | 'BB' => 'Barbados', |
||
1013 | 'BD' => 'Bangladesh', |
||
1014 | 'BE' => 'Belgium', |
||
1015 | 'BF' => 'Burkina Faso', |
||
1016 | 'BG' => 'Bulgaria', |
||
1017 | 'BH' => 'Bahrain', |
||
1018 | 'BI' => 'Burundi', |
||
1019 | 'BJ' => 'Benin', |
||
1020 | 'BL' => 'Saint Barthélemy', // Added |
||
1021 | 'BM' => 'Bermuda', |
||
1022 | 'BN' => 'Brunei Darussalam', |
||
1023 | 'BO' => 'Bolivia', |
||
1024 | 'BR' => 'Brazil', |
||
1025 | 'BS' => 'Bahamas', |
||
1026 | 'BT' => 'Bhutan', |
||
1027 | 'BV' => 'Bouvet Island', |
||
1028 | 'BW' => 'Botswana', |
||
1029 | 'BY' => 'Belarus', |
||
1030 | 'BZ' => 'Belize', |
||
1031 | 'CA' => 'Canada', |
||
1032 | 'CC' => 'Cocos (Keeling) Islands', |
||
1033 | 'CD' => 'Congo (Dem. Rep.)', // Added |
||
1034 | 'CF' => 'Central African Republic', |
||
1035 | 'CG' => 'Congo', |
||
1036 | 'CH' => 'Switzerland', |
||
1037 | 'CI' => "Cote D'Ivoire", // Removed: (Ivory Coast) |
||
1038 | 'CK' => 'Cook Islands', |
||
1039 | 'CL' => 'Chile', |
||
1040 | 'CM' => 'Cameroon', |
||
1041 | 'CN' => 'China', |
||
1042 | 'CO' => 'Colombia', |
||
1043 | 'CR' => 'Costa Rica', |
||
1044 | 'CS' => 'Czechoslovakia (former)', // Not listed anymore |
||
1045 | 'CU' => 'Cuba', |
||
1046 | 'CV' => 'Cape Verde', |
||
1047 | 'CX' => 'Christmas Island', |
||
1048 | 'CY' => 'Cyprus', |
||
1049 | 'CZ' => 'Czech Republic', |
||
1050 | 'DE' => 'Germany', |
||
1051 | 'DJ' => 'Djibouti', |
||
1052 | 'DK' => 'Denmark', |
||
1053 | 'DM' => 'Dominica', |
||
1054 | 'DO' => 'Dominican Republic', |
||
1055 | 'DZ' => 'Algeria', |
||
1056 | 'EC' => 'Ecuador', |
||
1057 | 'EE' => 'Estonia', |
||
1058 | 'EG' => 'Egypt', |
||
1059 | 'EH' => 'Western Sahara', |
||
1060 | 'ER' => 'Eritrea', |
||
1061 | 'ES' => 'Spain', |
||
1062 | 'EU' => 'Europe', |
||
1063 | 'ET' => 'Ethiopia', |
||
1064 | 'FI' => 'Finland', |
||
1065 | 'FJ' => 'Fiji', |
||
1066 | 'FK' => 'Falkland Islands (Malvinas)', |
||
1067 | 'FM' => 'Micronesia', |
||
1068 | 'FO' => 'Faroe Islands', |
||
1069 | 'FR' => 'France', |
||
1070 | 'FX' => 'France, Metropolitan', // Not listed anymore |
||
1071 | 'GA' => 'Gabon', |
||
1072 | 'GB' => 'Great Britain', // Name was: Great Britain (UK) |
||
1073 | 'GD' => 'Grenada', |
||
1074 | 'GE' => 'Georgia', |
||
1075 | 'GF' => 'French Guiana', |
||
1076 | 'GG' => 'Guernsey', // Added |
||
1077 | 'GH' => 'Ghana', |
||
1078 | 'GI' => 'Gibraltar', |
||
1079 | 'GL' => 'Greenland', |
||
1080 | 'GM' => 'Gambia', |
||
1081 | 'GN' => 'Guinea', |
||
1082 | 'GP' => 'Guadeloupe', |
||
1083 | 'GQ' => 'Equatorial Guinea', |
||
1084 | 'GR' => 'Greece', |
||
1085 | 'GS' => 'S. Georgia and S. Sandwich Isls.', |
||
1086 | 'GT' => 'Guatemala', |
||
1087 | 'GU' => 'Guam', |
||
1088 | 'GW' => 'Guinea-Bissau', |
||
1089 | 'GY' => 'Guyana', |
||
1090 | 'HK' => 'Hong Kong', |
||
1091 | 'HM' => 'Heard and McDonald Islands', |
||
1092 | 'HN' => 'Honduras', |
||
1093 | 'HR' => 'Croatia', |
||
1094 | 'HT' => 'Haiti', |
||
1095 | 'HU' => 'Hungary', |
||
1096 | 'ID' => 'Indonesia', |
||
1097 | 'IE' => 'Ireland', |
||
1098 | 'IL' => 'Israel', |
||
1099 | 'IM' => 'Isle of Man', // Added |
||
1100 | 'IN' => 'India', |
||
1101 | 'IO' => 'British Indian Ocean Territory', |
||
1102 | 'IQ' => 'Iraq', |
||
1103 | 'IR' => 'Iran', // Changed name |
||
1104 | 'IS' => 'Iceland', |
||
1105 | 'IT' => 'Italy', |
||
1106 | 'JE' => 'Jersey', |
||
1107 | 'JM' => 'Jamaica', |
||
1108 | 'JO' => 'Jordan', |
||
1109 | 'JP' => 'Japan', |
||
1110 | 'KE' => 'Kenya', |
||
1111 | 'KG' => 'Kyrgyzstan', |
||
1112 | 'KH' => 'Cambodia', |
||
1113 | 'KI' => 'Kiribati', |
||
1114 | 'KM' => 'Comoros', |
||
1115 | 'KN' => 'Saint Kitts and Nevis', |
||
1116 | 'KP' => 'Korea (North)', // Official name: Korea, Democratic People's Republic of |
||
1117 | 'KR' => 'Korea (South)', // Official name: Korea, Republic of |
||
1118 | 'KW' => 'Kuwait', |
||
1119 | 'KY' => 'Cayman Islands', |
||
1120 | 'KZ' => 'Kazakhstan', |
||
1121 | 'LA' => 'Laos', // Official name: Lao People's Democratic Republic |
||
1122 | 'LB' => 'Lebanon', |
||
1123 | 'LC' => 'Saint Lucia', |
||
1124 | 'LI' => 'Liechtenstein', |
||
1125 | 'LK' => 'Sri Lanka', |
||
1126 | 'LR' => 'Liberia', |
||
1127 | 'LS' => 'Lesotho', |
||
1128 | 'LT' => 'Lithuania', |
||
1129 | 'LU' => 'Luxembourg', |
||
1130 | 'LV' => 'Latvia', |
||
1131 | 'LY' => 'Libya', // Official name: Libyan Arab Jamahiriya |
||
1132 | 'MA' => 'Morocco', |
||
1133 | 'MC' => 'Monaco', |
||
1134 | 'MD' => 'Moldova', // Official name: Moldova, Republic of |
||
1135 | 'ME' => 'Montenegro', // Added |
||
1136 | 'MF' => 'Saint Martin', // Added |
||
1137 | 'MG' => 'Madagascar', |
||
1138 | 'MH' => 'Marshall Islands', |
||
1139 | 'MK' => 'Macedonia', // Official name: Macedonia, The Former Yugoslav Republic of |
||
1140 | 'ML' => 'Mali', |
||
1141 | 'MM' => 'Myanmar', |
||
1142 | 'MN' => 'Mongolia', |
||
1143 | 'MO' => 'Macao', // Corrected name |
||
1144 | 'MP' => 'Northern Mariana Islands', |
||
1145 | 'MQ' => 'Martinique', |
||
1146 | 'MR' => 'Mauritania', |
||
1147 | 'MS' => 'Montserrat', |
||
1148 | 'MT' => 'Malta', |
||
1149 | 'MU' => 'Mauritius', |
||
1150 | 'MV' => 'Maldives', |
||
1151 | 'MW' => 'Malawi', |
||
1152 | 'MX' => 'Mexico', |
||
1153 | 'MY' => 'Malaysia', |
||
1154 | 'MZ' => 'Mozambique', |
||
1155 | 'NA' => 'Namibia', |
||
1156 | 'NC' => 'New Caledonia', |
||
1157 | 'NE' => 'Niger', |
||
1158 | 'NF' => 'Norfolk Island', |
||
1159 | 'NG' => 'Nigeria', |
||
1160 | 'NI' => 'Nicaragua', |
||
1161 | 'NL' => 'Netherlands', |
||
1162 | 'NO' => 'Norway', |
||
1163 | 'NP' => 'Nepal', |
||
1164 | 'NR' => 'Nauru', |
||
1165 | 'NT' => 'Neutral Zone', |
||
1166 | 'NU' => 'Niue', |
||
1167 | 'NZ' => 'New Zealand', |
||
1168 | 'OM' => 'Oman', |
||
1169 | 'PA' => 'Panama', |
||
1170 | 'PE' => 'Peru', |
||
1171 | 'PF' => 'French Polynesia', |
||
1172 | 'PG' => 'Papua New Guinea', |
||
1173 | 'PH' => 'Philippines', |
||
1174 | 'PK' => 'Pakistan', |
||
1175 | 'PL' => 'Poland', |
||
1176 | 'PM' => 'St. Pierre and Miquelon', |
||
1177 | 'PN' => 'Pitcairn', |
||
1178 | 'PR' => 'Puerto Rico', |
||
1179 | 'PS' => 'Palestinian Territory, Occupied', // Added |
||
1180 | 'PT' => 'Portugal', |
||
1181 | 'PW' => 'Palau', |
||
1182 | 'PY' => 'Paraguay', |
||
1183 | 'QA' => 'Qatar', |
||
1184 | 'RE' => 'Reunion', |
||
1185 | 'RO' => 'Romania', |
||
1186 | 'RS' => 'Serbia', // Added |
||
1187 | 'RU' => 'Russian Federation', |
||
1188 | 'RW' => 'Rwanda', |
||
1189 | 'SA' => 'Saudi Arabia', |
||
1190 | 'SB' => 'Solomon Islands', |
||
1191 | 'SC' => 'Seychelles', |
||
1192 | 'SD' => 'Sudan', |
||
1193 | 'SE' => 'Sweden', |
||
1194 | 'SG' => 'Singapore', |
||
1195 | 'SH' => 'St. Helena', |
||
1196 | 'SI' => 'Slovenia', |
||
1197 | 'SJ' => 'Svalbard and Jan Mayen Islands', |
||
1198 | 'SK' => 'Slovakia', // Changed name, was: Slovak Republic |
||
1199 | 'SL' => 'Sierra Leone', |
||
1200 | 'SM' => 'San Marino', |
||
1201 | 'SN' => 'Senegal', |
||
1202 | 'SO' => 'Somalia', |
||
1203 | 'SR' => 'Suriname', |
||
1204 | 'ST' => 'Sao Tome and Principe', |
||
1205 | 'SU' => 'USSR (former)', // Removed from ISO list, doesn' exsist anymore |
||
1206 | 'SV' => 'El Salvador', |
||
1207 | 'SY' => 'Syrian Arab Republic', // Changed name, was: Syria |
||
1208 | 'SZ' => 'Swaziland', |
||
1209 | 'TC' => 'Turks and Caicos Islands', |
||
1210 | 'TD' => 'Chad', |
||
1211 | 'TF' => 'French Southern Territories', |
||
1212 | 'TG' => 'Togo', |
||
1213 | 'TH' => 'Thailand', |
||
1214 | 'TJ' => 'Tajikistan', |
||
1215 | 'TK' => 'Tokelau', |
||
1216 | 'TL' => 'Timor-Leste', // Added |
||
1217 | 'TM' => 'Turkmenistan', |
||
1218 | 'TN' => 'Tunisia', |
||
1219 | 'TO' => 'Tonga', |
||
1220 | 'TP' => 'East Timor', // Removed from ISO list, doesn' exsist anymore |
||
1221 | 'TR' => 'Turkey', |
||
1222 | 'TT' => 'Trinidad and Tobago', |
||
1223 | 'TV' => 'Tuvalu', |
||
1224 | 'TW' => 'Taiwan', // Official name acc. to iso-list: Taiwan, Province of China |
||
1225 | 'TZ' => 'Tanzania', |
||
1226 | 'UA' => 'Ukraine', |
||
1227 | 'UG' => 'Uganda', |
||
1228 | 'UK' => 'United Kingdom', // Doesn't exsist in iso-list ? |
||
1229 | 'UM' => 'US Minor Outlying Islands', |
||
1230 | 'US' => 'United States', |
||
1231 | 'UY' => 'Uruguay', |
||
1232 | 'UZ' => 'Uzbekistan', |
||
1233 | 'VA' => 'Vatican City State', |
||
1234 | 'VC' => 'Saint Vincent and the Grenadines', |
||
1235 | 'VE' => 'Venezuela', |
||
1236 | 'VG' => 'Virgin Islands, British', |
||
1237 | 'VI' => 'Virgin Islands, U.S.', |
||
1238 | 'VN' => 'Viet Nam', |
||
1239 | 'VU' => 'Vanuatu', |
||
1240 | 'WF' => 'Wallis and Futuna Islands', |
||
1241 | 'WS' => 'Samoa', |
||
1242 | 'YE' => 'Yemen', |
||
1243 | 'YT' => 'Mayotte', |
||
1244 | 'YU' => 'Yugoslavia', // Removed from iso list |
||
1245 | 'ZA' => 'South Africa', |
||
1246 | 'ZM' => 'Zambia', |
||
1247 | 'ZR' => 'Zaire', // Removed from iso list |
||
1248 | 'ZW' => 'Zimbabwe', |
||
1249 | ]; |
||
1250 | |||
1251 | return $country_array[$countryn]; |
||
1252 | } |
||
1253 | |||
1254 | /** |
||
1255 | * @param $document |
||
1256 | * |
||
1257 | * @return mixed |
||
1258 | */ |
||
1259 | public static function convertHtml2text($document) |
||
1260 | { |
||
1261 | $search = [ |
||
1262 | "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
||
1263 | "'<img.*?>'si", // Strip out img tags |
||
1264 | "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
||
1265 | "'([\r\n])[\s]+'", // Strip out white space |
||
1266 | "'&(quot|#34);'i", // Replace HTML entities |
||
1267 | "'&(amp|#38);'i", |
||
1268 | "'&(lt|#60);'i", |
||
1269 | "'&(gt|#62);'i", |
||
1270 | "'&(nbsp|#160);'i", |
||
1271 | "'&(iexcl|#161);'i", |
||
1272 | "'&(cent|#162);'i", |
||
1273 | "'&(pound|#163);'i", |
||
1274 | "'&(copy|#169);'i", |
||
1275 | ]; // evaluate as php |
||
1276 | |||
1277 | $replace = [ |
||
1278 | '', |
||
1279 | '', |
||
1280 | '', |
||
1281 | '\\1', |
||
1282 | '"', |
||
1283 | '&', |
||
1284 | '<', |
||
1285 | '>', |
||
1286 | ' ', |
||
1287 | \chr(161), |
||
1288 | \chr(162), |
||
1289 | \chr(163), |
||
1290 | \chr(169), |
||
1291 | ]; |
||
1292 | |||
1293 | $text = \preg_replace($search, $replace, $document); |
||
1294 | |||
1295 | \preg_replace_callback( |
||
1296 | '/&#(\d+);/', |
||
1297 | static function ($matches) { |
||
1298 | return \chr($matches[1]); |
||
1299 | }, |
||
1300 | $document |
||
1301 | ); |
||
1302 | |||
1303 | return $text; |
||
1304 | } |
||
1305 | |||
1306 | // Start functions for Google PageRank |
||
1307 | // Source: http://www.sws-tech.com/scripts/googlepagerank.php |
||
1308 | // This code is released under the public domain |
||
1309 | |||
1310 | /** |
||
1311 | * @param $a |
||
1312 | * @param $b |
||
1313 | * |
||
1314 | * @return float|int |
||
1315 | */ |
||
1316 | public static function fillZeroes($a, $b) |
||
1317 | { |
||
1318 | $z = \hexdec(80000000); |
||
1319 | //echo $z; |
||
1320 | if ($z & $a) { |
||
1321 | $a >>= 1; |
||
1322 | $a &= (~$z); |
||
1323 | $a |= 0x40000000; |
||
1324 | $a >>= ($b - 1); |
||
1325 | } else { |
||
1326 | $a >>= $b; |
||
1327 | } |
||
1328 | |||
1329 | return $a; |
||
1330 | } |
||
1331 | |||
1332 | /** |
||
1333 | * @param $a |
||
1334 | * @param $b |
||
1335 | * @param $c |
||
1336 | * |
||
1337 | * @return array |
||
1338 | */ |
||
1339 | public static function mix($a, $b, $c) |
||
1340 | { |
||
1341 | $a -= $b; |
||
1342 | $a -= $c; |
||
1343 | $a ^= static::fillZeroes($c, 13); |
||
1344 | $b -= $c; |
||
1345 | $b -= $a; |
||
1346 | $b ^= ($a << 8); |
||
1347 | $c -= $a; |
||
1348 | $c -= $b; |
||
1349 | $c ^= static::fillZeroes($b, 13); |
||
1350 | $a -= $b; |
||
1351 | $a -= $c; |
||
1352 | $a ^= static::fillZeroes($c, 12); |
||
1353 | $b -= $c; |
||
1354 | $b -= $a; |
||
1355 | $b ^= ($a << 16); |
||
1356 | $c -= $a; |
||
1357 | $c -= $b; |
||
1358 | $c ^= static::fillZeroes($b, 5); |
||
1359 | $a -= $b; |
||
1360 | $a -= $c; |
||
1361 | $a ^= static::fillZeroes($c, 3); |
||
1362 | $b -= $c; |
||
1363 | $b -= $a; |
||
1364 | $b ^= ($a << 10); |
||
1365 | $c -= $a; |
||
1366 | $c -= $b; |
||
1367 | $c ^= static::fillZeroes($b, 15); |
||
1368 | |||
1369 | return [$a, $b, $c]; |
||
1370 | } |
||
1371 | |||
1372 | /** |
||
1373 | * @param array|null $url |
||
1374 | * @param null $length |
||
1375 | * @param int $init |
||
1376 | * |
||
1377 | * @return mixed |
||
1378 | */ |
||
1379 | public static function googleCh($url, $length = null, $init = 0xE6359A60) |
||
1439 | } |
||
1440 | |||
1441 | //converts a string into an array of integers containing the numeric value of the char |
||
1442 | |||
1443 | /** |
||
1444 | * @param $string |
||
1445 | * |
||
1446 | * @return mixed |
||
1447 | */ |
||
1448 | public static function strord($string) |
||
1449 | { |
||
1450 | $iMax = mb_strlen($string); |
||
1451 | for ($i = 0; $i < $iMax; ++$i) { |
||
1452 | $result[$i] = \ord($string[$i]); |
||
1453 | } |
||
1454 | |||
1455 | return $result; |
||
1456 | } |
||
1457 | |||
1458 | /** |
||
1459 | * @param $url |
||
1460 | * |
||
1461 | * @return bool|string |
||
1462 | */ |
||
1463 | public static function pagerank($url) |
||
1464 | { |
||
1465 | $pagerank = ''; |
||
1466 | $ch = '6' . static::googleCh(static::strord('info:' . $url)); |
||
1467 | $fp = \fsockopen('www.google.com', 80, $errno, $errstr, 30); |
||
1468 | if ($fp) { |
||
1469 | $out = 'GET /search?client=navclient-auto&ch=' . $ch . '&features=Rank&q=info:' . $url . " HTTP/1.1\r\n"; |
||
1470 | $out .= "Host: www.google.com\r\n"; |
||
1471 | $out .= "Connection: Close\r\n\r\n"; |
||
1472 | |||
1473 | \fwrite($fp, $out); |
||
1474 | |||
1475 | while (!\feof($fp)) { |
||
1476 | $data = \fgets($fp, 128); |
||
1477 | $pos = mb_strpos($data, 'Rank_'); |
||
1478 | if (false !== $pos) { |
||
1479 | $pagerank = mb_substr($data, $pos + 9); |
||
1480 | } else { |
||
1481 | } |
||
1482 | } |
||
1483 | \fclose($fp); |
||
1484 | } else { |
||
1485 | echo "$errstr ($errno)<br>\n"; |
||
1486 | } |
||
1487 | |||
1488 | return $pagerank; |
||
1489 | } |
||
1490 | |||
1491 | // End functions for Google PageRank |
||
1492 | |||
1493 | // Check if Tag module is installed |
||
1494 | |||
1495 | /** |
||
1496 | * @return bool |
||
1497 | */ |
||
1498 | public static function isTagModuleIncluded() |
||
1499 | { |
||
1500 | static $wfl_tag_module_included; |
||
1501 | if (!isset($wfl_tag_module_included)) { |
||
1502 | $modulesHandler = \xoops_getHandler('module'); |
||
1503 | $tag_mod = $modulesHandler->getByDirname('tag'); |
||
1504 | if ($tag_mod) { |
||
1505 | $wfl_tag_module_included = 1 == $tag_mod->getVar('isactive'); |
||
1506 | } else { |
||
1507 | $tag_mod = false; |
||
1508 | } |
||
1509 | } |
||
1510 | |||
1511 | return $wfl_tag_module_included; |
||
1512 | } |
||
1513 | |||
1514 | // Add item_tag to Tag-module |
||
1515 | |||
1516 | /** |
||
1517 | * @param $lid |
||
1518 | * @param $item_tag |
||
1519 | */ |
||
1520 | public static function updateTag($lid, $item_tag) |
||
1521 | { |
||
1522 | global $xoopsModule; |
||
1523 | if (static::isTagModuleIncluded()) { |
||
1524 | require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php'; |
||
1525 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag'); |
||
1526 | $tagHandler->updateByItem($item_tag, $lid, $xoopsModule->getVar('dirname'), 0); |
||
1527 | } |
||
1528 | } |
||
1529 | |||
1530 | // Check if News module is installed |
||
1531 | |||
1532 | /** |
||
1533 | * @return bool |
||
1534 | */ |
||
1535 | public static function isNewsModuleIncluded() |
||
1536 | { |
||
1537 | static $wfl_news_module_included; |
||
1538 | if (!isset($wfl_news_module_included)) { |
||
1539 | $modulesHandler = \xoops_getHandler('module'); |
||
1540 | $news_mod = $modulesHandler->getByDirname('news'); |
||
1541 | if ($news_mod) { |
||
1542 | $wfl_news_module_included = 1 == $news_mod->getVar('isactive'); |
||
1543 | } else { |
||
1544 | $news_mod = false; |
||
1545 | } |
||
1546 | } |
||
1547 | |||
1548 | return $wfl_news_module_included; |
||
1549 | } |
||
1550 | |||
1551 | /** |
||
1552 | * @param $banner_id |
||
1553 | * |
||
1554 | * @return null|string |
||
1555 | */ |
||
1556 | public static function getBannerFromIdBanner($banner_id) |
||
1557 | { |
||
1558 | ###### Hack by www.stefanosilvestrini.com ###### |
||
1559 | global $xoopsConfig; |
||
1560 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
1561 | $bresult = $db->query('SELECT COUNT(*) FROM ' . $db->prefix('banner') . ' WHERE bid=' . $banner_id); |
||
1562 | list($numrows) = $db->fetchRow($bresult); |
||
1563 | if ($numrows > 1) { |
||
1564 | --$numrows; |
||
1565 | $bannum = \mt_rand(0, $numrows); |
||
1566 | } else { |
||
1567 | $bannum = 0; |
||
1568 | } |
||
1569 | if ($numrows > 0) { |
||
1570 | $bresult = $db->query('SELECT * FROM ' . $db->prefix('banner') . ' WHERE bid=' . $banner_id, 1, $bannum); |
||
1571 | list($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult); |
||
1572 | if ($xoopsConfig['my_ip'] == \xoops_getenv('REMOTE_ADDR')) { |
||
1573 | // EMPTY |
||
1574 | } else { |
||
1575 | $db->queryF(\sprintf('UPDATE `%s` SET impmade = impmade+1 WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
1576 | } |
||
1577 | /* Check if this impression is the last one and print the banner */ |
||
1578 | if ($imptotal == $impmade) { |
||
1579 | $newid = $db->genId($db->prefix('bannerfinish') . '_bid_seq'); |
||
1580 | $sql = \sprintf('INSERT INTO `%s` (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)', $db->prefix('bannerfinish'), $newid, $cid, $impmade, $clicks, $date, \time()); |
||
1581 | $db->queryF($sql); |
||
1582 | $db->queryF(\sprintf('DELETE FROM `%s` WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
1583 | } |
||
1584 | if ($htmlbanner) { |
||
1585 | $bannerobject = $htmlcode; |
||
1586 | } else { |
||
1587 | $bannerobject = '<div align="center"><a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" target="_blank">'; |
||
1588 | if (false !== mb_stripos($imageurl, '.swf')) { |
||
1589 | $bannerobject = $bannerobject |
||
1590 | . '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">' |
||
1591 | . '<param name="movie" value="' |
||
1592 | . $imageurl |
||
1593 | . '"></param>' |
||
1594 | . '<param name="quality" value="high"></param>' |
||
1595 | . '<embed src="' |
||
1596 | . $imageurl |
||
1597 | . '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' |
||
1598 | . '</embed>' |
||
1599 | . '</object>'; |
||
1600 | } else { |
||
1601 | $bannerobject = $bannerobject . '<img src="' . $imageurl . '" alt="">'; |
||
1602 | } |
||
1603 | $bannerobject .= '</a></div>'; |
||
1604 | } |
||
1605 | |||
1606 | return $bannerobject; |
||
1607 | } |
||
1608 | |||
1609 | return null; |
||
1610 | } |
||
1611 | |||
1612 | /** |
||
1613 | * @param $client_id |
||
1614 | * |
||
1615 | * @return string |
||
1616 | */ |
||
1617 | public static function getBannerFromIdClient($client_id) |
||
1618 | { |
||
1619 | ###### Hack by www.stefanosilvestrini.com ###### |
||
1620 | global $xoopsConfig; |
||
1621 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
1622 | $bresult = $db->query('SELECT COUNT(*) FROM ' . $db->prefix('banner') . ' WHERE cid=' . $client_id); |
||
1623 | list($numrows) = $db->fetchRow($bresult); |
||
1624 | if ($numrows > 1) { |
||
1625 | --$numrows; |
||
1626 | $bannum = \mt_rand(0, $numrows); |
||
1627 | } else { |
||
1628 | $bannum = 0; |
||
1629 | } |
||
1630 | if ($numrows > 0) { |
||
1631 | $bresult = $db->query('SELECT * FROM ' . $db->prefix('banner') . ' WHERE cid=' . $client_id . ' ORDER BY rand()', 1, $bannum); |
||
1632 | list($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult); |
||
1633 | if ($xoopsConfig['my_ip'] == \xoops_getenv('REMOTE_ADDR')) { |
||
1634 | // EMPTY |
||
1635 | } else { |
||
1636 | $db->queryF(\sprintf('UPDATE `%s` SET impmade = impmade+1 WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
1637 | } |
||
1638 | /* Check if this impression is the last one and print the banner */ |
||
1639 | if ($imptotal == $impmade) { |
||
1640 | $newid = $db->genId($db->prefix('bannerfinish') . '_bid_seq'); |
||
1641 | $sql = \sprintf('INSERT INTO `%s` (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)', $db->prefix('bannerfinish'), $newid, $cid, $impmade, $clicks, $date, \time()); |
||
1642 | $db->queryF($sql); |
||
1643 | $db->queryF(\sprintf('DELETE FROM `%s` WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
1644 | } |
||
1645 | if ($htmlbanner) { |
||
1646 | $bannerobject = $htmlcode; |
||
1647 | } else { |
||
1648 | $bannerobject = '<div align="center"><a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" target="_blank">'; |
||
1649 | if (false !== mb_stripos($imageurl, '.swf')) { |
||
1650 | $bannerobject = $bannerobject |
||
1651 | . '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">' |
||
1652 | . '<param name="movie" value="' |
||
1653 | . $imageurl |
||
1654 | . '"></param>' |
||
1655 | . '<param name="quality" value="high"></param>' |
||
1656 | . '<embed src="' |
||
1657 | . $imageurl |
||
1658 | . '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' |
||
1659 | . '</embed>' |
||
1660 | . '</object>'; |
||
1661 | } else { |
||
1662 | $bannerobject = $bannerobject . '<img src="' . $imageurl . '" alt="">'; |
||
1663 | } |
||
1664 | $bannerobject .= '</a></div>'; |
||
1665 | } |
||
1666 | |||
1667 | return $bannerobject; |
||
1668 | } |
||
1669 | |||
1670 | return null; |
||
1671 | } |
||
1672 | |||
1673 | /** |
||
1674 | * @param $email |
||
1675 | * |
||
1676 | * @return mixed |
||
1677 | */ |
||
1678 | public static function convertEmail($email) |
||
1679 | { |
||
1680 | $search = [ |
||
1681 | "/\@/", |
||
1682 | "/\./", |
||
1683 | "/\mailto:/", |
||
1684 | ]; |
||
1685 | |||
1686 | $replace = [ |
||
1687 | ' AT ', |
||
1688 | ' DOT ', |
||
1689 | '', |
||
1690 | ]; |
||
1691 | |||
1692 | $text = \preg_replace($search, $replace, $email); |
||
1693 | |||
1694 | return $text; |
||
1695 | } |
||
1696 | |||
1697 | /** |
||
1698 | * @param $email |
||
1699 | * |
||
1700 | * @return mixed |
||
1701 | */ |
||
1702 | public static function printemailcnvrt($email) |
||
1703 | { |
||
1704 | $search = [ |
||
1705 | "/\ AT /", |
||
1706 | "/\ DOT /", |
||
1707 | ]; |
||
1708 | |||
1709 | $replace = [ |
||
1710 | '@', |
||
1711 | '.', |
||
1712 | ]; |
||
1713 | |||
1714 | $text = \preg_replace($search, $replace, $email); |
||
1715 | |||
1716 | return $text; |
||
1717 | } |
||
1718 | |||
1719 | /** |
||
1720 | * @param $str |
||
1721 | * @param $start |
||
1722 | * @param $length |
||
1723 | * @param string $trimmarker |
||
1724 | * |
||
1725 | * @return string |
||
1726 | */ |
||
1727 | public static function getSubstring($str, $start, $length, $trimmarker = '...') |
||
1728 | { |
||
1729 | $configHandler = \xoops_getHandler('config'); |
||
1730 | $im_multilanguageConfig = $configHandler->getConfigsByCat(IM_CONF_MULILANGUAGE); |
||
1731 | |||
1732 | if ($im_multilanguageConfig['ml_enable']) { |
||
1733 | $tags = \explode(',', $im_multilanguageConfig['ml_tags']); |
||
1734 | $strs = []; |
||
1735 | $hasML = false; |
||
1736 | foreach ($tags as $tag) { |
||
1737 | if (\preg_match("/\[" . $tag . "](.*)\[\/" . $tag . "\]/sU", $str, $matches)) { |
||
1738 | if (\count($matches) > 0) { |
||
1739 | $hasML = true; |
||
1740 | $strs[] = $matches[1]; |
||
1741 | } |
||
1742 | } |
||
1743 | } |
||
1744 | } else { |
||
1745 | $hasML = false; |
||
1746 | } |
||
1747 | |||
1748 | if (!$hasML) { |
||
1749 | $strs = [$str]; |
||
1750 | } |
||
1751 | |||
1752 | for ($i = 0; $i <= \count($strs) - 1; ++$i) { |
||
1753 | if (!XOOPS_USE_MULTIBYTES) { |
||
1754 | $strs[$i] = (mb_strlen($strs[$i]) - $start <= $length) ? mb_substr($strs[$i], $start, $length) : mb_substr($strs[$i], $start, $length - mb_strlen($trimmarker)) . $trimmarker; |
||
1755 | } |
||
1756 | |||
1757 | if (\function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) { |
||
1758 | $str2 = mb_strcut($strs[$i], $start, $length - mb_strlen($trimmarker)); |
||
1759 | $strs[$i] = $str2 . (mb_strlen($strs[$i]) != mb_strlen($str2) ? $trimmarker : ''); |
||
1760 | } |
||
1761 | |||
1762 | // phppp patch |
||
1763 | $DEP_CHAR = 127; |
||
1764 | $pos_st = 0; |
||
1765 | $action = false; |
||
1766 | for ($pos_i = 0, $pos_iMax = mb_strlen($strs[$i]); $pos_i < $pos_iMax; ++$pos_i) { |
||
1767 | if (\ord(mb_substr($strs[$i], $pos_i, 1)) > 127) { |
||
1768 | ++$pos_i; |
||
1769 | } |
||
1770 | if ($pos_i <= $start) { |
||
1771 | $pos_st = $pos_i; |
||
1772 | } |
||
1773 | if ($pos_i >= $pos_st + $length) { |
||
1774 | $action = true; |
||
1775 | break; |
||
1776 | } |
||
1777 | } |
||
1778 | $strs[$i] = $action ? mb_substr($strs[$i], $pos_st, $pos_i - $pos_st - mb_strlen($trimmarker)) . $trimmarker : $strs[$i]; |
||
1779 | |||
1780 | $strs[$i] = $hasML ? '[' . $tags[$i] . ']' . $strs[$i] . '[/' . $tags[$i] . ']' : $strs[$i]; |
||
1781 | } |
||
1782 | $str = \implode('', $strs); |
||
1783 | |||
1784 | return $str; |
||
1785 | } |
||
1786 | |||
1787 | // Reusable Link Sorting Functions |
||
1788 | // convertOrderByIn() |
||
1789 | // @param $orderby |
||
1790 | // @return |
||
1791 | |||
1792 | /** |
||
1793 | * @param $orderby |
||
1794 | * |
||
1795 | * @return string |
||
1796 | */ |
||
1797 | public static function convertOrderByIn($orderby) |
||
1798 | { |
||
1799 | switch (\trim($orderby)) { |
||
1800 | case 'titleA': |
||
1801 | $orderby = 'title ASC'; |
||
1802 | break; |
||
1803 | case 'dateA': |
||
1804 | $orderby = 'published ASC'; |
||
1805 | break; |
||
1806 | case 'hitsA': |
||
1807 | $orderby = 'hits ASC'; |
||
1808 | break; |
||
1809 | case 'ratingA': |
||
1810 | $orderby = 'rating ASC'; |
||
1811 | break; |
||
1812 | case 'countryA': |
||
1813 | $orderby = 'country ASC'; |
||
1814 | break; |
||
1815 | case 'titleD': |
||
1816 | $orderby = 'title DESC'; |
||
1817 | break; |
||
1818 | case 'hitsD': |
||
1819 | $orderby = 'hits DESC'; |
||
1820 | break; |
||
1821 | case 'ratingD': |
||
1822 | $orderby = 'rating DESC'; |
||
1823 | break; |
||
1824 | case'dateD': |
||
1825 | $orderby = 'published DESC'; |
||
1826 | break; |
||
1827 | case 'countryD': |
||
1828 | $orderby = 'country DESC'; |
||
1829 | break; |
||
1830 | } |
||
1831 | |||
1832 | return $orderby; |
||
1833 | } |
||
1834 | |||
1835 | /** |
||
1836 | * @param $orderby |
||
1837 | * |
||
1838 | * @return string |
||
1839 | */ |
||
1840 | public static function convertOrderByTrans($orderby) |
||
1874 | } |
||
1875 | |||
1876 | /** |
||
1877 | * @param $orderby |
||
1878 | * |
||
1879 | * @return string |
||
1880 | */ |
||
1881 | public static function convertOrderByOut($orderby) |
||
1918 | } |
||
1919 | } |
||
1920 |