Total Complexity | 445 |
Total Lines | 3306 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 |
||
276 | class Utility extends Common\SysUtility |
||
277 | { |
||
278 | //--------------- Custom module methods ----------------------------- |
||
279 | |||
280 | public const MODULE_NAME = 'xoopstube'; |
||
281 | |||
282 | /** |
||
283 | * Access the only instance of this class |
||
284 | * |
||
285 | * @return \XoopsModules\Xoopstube\Utility |
||
286 | * |
||
287 | * @static |
||
288 | * @staticvar object |
||
289 | */ |
||
290 | public static function getInstance() |
||
291 | { |
||
292 | static $instance; |
||
293 | if (null === $instance) { |
||
294 | $instance = new static(); |
||
295 | } |
||
296 | |||
297 | return $instance; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Returns a module's option (with cache) |
||
302 | * |
||
303 | * @param string $option module option's name |
||
304 | * @param bool $withCache Do we have to use some cache ? |
||
305 | * |
||
306 | * @return mixed option's value |
||
307 | */ |
||
308 | public static function getModuleOption($option, $withCache = true) |
||
309 | { |
||
310 | global $xoopsModuleConfig, $xoopsModule; |
||
311 | $repmodule = self::MODULE_NAME; |
||
312 | static $options = []; |
||
313 | if (is_array($options) && array_key_exists($option, $options) && $withCache) { |
||
314 | return $options[$option]; |
||
315 | } |
||
316 | |||
317 | $retval = false; |
||
318 | if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) { |
||
319 | if (isset($xoopsModuleConfig[$option])) { |
||
320 | $retval = $xoopsModuleConfig[$option]; |
||
321 | } |
||
322 | } else { |
||
323 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
324 | $moduleHandler = xoops_getHandler('module'); |
||
325 | $module = $moduleHandler->getByDirname($repmodule); |
||
326 | $configHandler = xoops_getHandler('config'); |
||
327 | if ($module) { |
||
328 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
|
|||
329 | if (isset($moduleConfig[$option])) { |
||
330 | $retval = $moduleConfig[$option]; |
||
331 | } |
||
332 | } |
||
333 | } |
||
334 | $options[$option] = $retval; |
||
335 | |||
336 | return $retval; |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * Is Xoops 2.3.x ? |
||
341 | * |
||
342 | * @return bool |
||
343 | */ |
||
344 | public static function isX23() |
||
345 | { |
||
346 | $x23 = false; |
||
347 | $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
||
348 | if ((int)mb_substr($xv, 2, 1) >= 3) { |
||
349 | $x23 = true; |
||
350 | } |
||
351 | |||
352 | return $x23; |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * Is Xoops 2.0.x ? |
||
357 | * |
||
358 | * @return bool |
||
359 | */ |
||
360 | public static function isX20() |
||
361 | { |
||
362 | $x20 = false; |
||
363 | $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
||
364 | if ('0' == mb_substr($xv, 2, 1)) { |
||
365 | $x20 = true; |
||
366 | } |
||
367 | |||
368 | return $x20; |
||
369 | } |
||
370 | |||
371 | /** |
||
372 | * Create (in a link) a javascript confirmation's box |
||
373 | * |
||
374 | * @param string $message Message to display |
||
375 | * @param bool $form Is this a confirmation for a form ? |
||
376 | * |
||
377 | * @return string the javascript code to insert in the link (or in the form) |
||
378 | */ |
||
379 | public static function javascriptLinkConfirm($message, $form = false) |
||
380 | { |
||
381 | if (!$form) { |
||
382 | return "onclick=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
||
383 | } |
||
384 | |||
385 | return "onSubmit=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * Get current user IP |
||
390 | * |
||
391 | * @return string IP address (format Ipv4) |
||
392 | */ |
||
393 | public static function IP() |
||
394 | { |
||
395 | $proxy_ip = ''; |
||
396 | if (Request::hasVar('HTTP_X_FORWARDED_FOR', 'SERVER')) { |
||
397 | $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
||
398 | } elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) { |
||
399 | $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; |
||
400 | } elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { |
||
401 | $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; |
||
402 | } elseif (!empty($_SERVER['HTTP_FORWARDED'])) { |
||
403 | $proxy_ip = $_SERVER['HTTP_FORWARDED']; |
||
404 | } elseif (!empty($_SERVER['HTTP_VIA'])) { |
||
405 | $proxy_ip = $_SERVER['HTTP_VIA']; |
||
406 | } elseif (!empty($_SERVER['HTTP_X_COMING_FROM'])) { |
||
407 | $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; |
||
408 | } elseif (!empty($_SERVER['HTTP_COMING_FROM'])) { |
||
409 | $proxy_ip = $_SERVER['HTTP_COMING_FROM']; |
||
410 | } |
||
411 | $regs = []; |
||
412 | //if (!empty($proxy_ip) && $is_ip = ereg('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $proxy_ip, $regs) && count($regs) > 0) { |
||
413 | if (!empty($proxy_ip) && filter_var($proxy_ip, FILTER_VALIDATE_IP) && count($regs) > 0) { |
||
414 | $the_IP = $regs[0]; |
||
415 | } else { |
||
416 | $the_IP = $_SERVER['REMOTE_ADDR']; |
||
417 | } |
||
418 | |||
419 | return $the_IP; |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * Set the page's title, meta description and meta keywords |
||
424 | * Datas are supposed to be sanitized |
||
425 | * |
||
426 | * @param string $pageTitle Page's Title |
||
427 | * @param string $metaDescription Page's meta description |
||
428 | * @param string $metaKeywords Page's meta keywords |
||
429 | */ |
||
430 | public static function setMetas($pageTitle = '', $metaDescription = '', $metaKeywords = '') |
||
431 | { |
||
432 | global $xoTheme, $xoTheme, $xoopsTpl; |
||
433 | $xoopsTpl->assign('xoops_pagetitle', $pageTitle); |
||
434 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
435 | if (!empty($metaKeywords)) { |
||
436 | $xoTheme->addMeta('meta', 'keywords', $metaKeywords); |
||
437 | } |
||
438 | if (!empty($metaDescription)) { |
||
439 | $xoTheme->addMeta('meta', 'description', $metaDescription); |
||
440 | } |
||
441 | } elseif (isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
||
442 | if (!empty($metaKeywords)) { |
||
443 | $xoopsTpl->assign('xoops_meta_keywords', $metaKeywords); |
||
444 | } |
||
445 | if (!empty($metaDescription)) { |
||
446 | $xoopsTpl->assign('xoops_meta_description', $metaDescription); |
||
447 | } |
||
448 | } |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Send an email from a template to a list of recipients |
||
453 | * |
||
454 | * @param $tplName |
||
455 | * @param array $recipients List of recipients |
||
456 | * @param string $subject Email's subject |
||
457 | * @param array $variables Varirables to give to the template |
||
458 | * |
||
459 | * @return bool Result of the send |
||
460 | * @internal param string $tpl_name Template's name |
||
461 | */ |
||
462 | public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
||
463 | { |
||
464 | global $xoopsConfig; |
||
465 | require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
||
466 | if (!is_array($recipients)) { |
||
467 | if ('' === trim($recipients)) { |
||
468 | return false; |
||
469 | } |
||
470 | } elseif (0 == count($recipients)) { |
||
471 | return false; |
||
472 | } |
||
473 | if (function_exists('xoops_getMailer')) { |
||
474 | $xoopsMailer = xoops_getMailer(); |
||
475 | } else { |
||
476 | $xoopsMailer = getMailer(); |
||
477 | } |
||
478 | |||
479 | $xoopsMailer->useMail(); |
||
480 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'; |
||
481 | if (!is_dir($templateDir)) { |
||
482 | $templateDir = XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/english/mail_template'; |
||
483 | } |
||
484 | $xoopsMailer->setTemplateDir($templateDir); |
||
485 | $xoopsMailer->setTemplate($tplName); |
||
486 | $xoopsMailer->setToEmails($recipients); |
||
487 | // TODO: Change ! |
||
488 | // $xoopsMailer->setFromEmail('[email protected]'); |
||
489 | //$xoopsMailer->setFromName('MonSite'); |
||
490 | $xoopsMailer->setSubject($subject); |
||
491 | foreach ($variables as $key => $value) { |
||
492 | $xoopsMailer->assign($key, $value); |
||
493 | } |
||
494 | $res = $xoopsMailer->send(); |
||
495 | unset($xoopsMailer); |
||
496 | $filename = XOOPS_UPLOAD_PATH . '/logmail_' . self::MODULE_NAME . '.php'; |
||
497 | if (!is_file($filename)) { |
||
498 | $fp = @fopen($filename, 'ab'); |
||
499 | if ($fp) { |
||
500 | fwrite($fp, "<?php exit(); ?>\n"); |
||
501 | fclose($fp); |
||
502 | } |
||
503 | } |
||
504 | $fp = @fopen($filename, 'ab'); |
||
505 | |||
506 | if ($fp) { |
||
507 | fwrite($fp, str_repeat('-', 120) . "\n"); |
||
508 | fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
||
509 | fwrite($fp, 'Template name : ' . $tplName . "\n"); |
||
510 | fwrite($fp, 'Email subject : ' . $subject . "\n"); |
||
511 | if (is_array($recipients)) { |
||
512 | fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
||
513 | } else { |
||
514 | fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
||
515 | } |
||
516 | fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
||
517 | fclose($fp); |
||
518 | } |
||
519 | |||
520 | return $res; |
||
521 | } |
||
522 | |||
523 | /** |
||
524 | * Remove module's cache |
||
525 | */ |
||
526 | public static function updateCache() |
||
527 | { |
||
528 | global $xoopsModule; |
||
529 | $folder = $xoopsModule->getVar('dirname'); |
||
530 | $tpllist = []; |
||
531 | require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
532 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
533 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
534 | $tpllist = $tplfileHandler->find(null, null, null, $folder); |
||
535 | xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
||
536 | |||
537 | foreach ($tpllist as $onetemplate) { // Remove cache for each page. |
||
538 | if ('module' === $onetemplate->getVar('tpl_type')) { |
||
539 | // Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
||
540 | $files_del = []; |
||
541 | $files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*', GLOB_NOSORT); |
||
542 | if (count($files_del) > 0 && is_array($files_del)) { |
||
543 | foreach ($files_del as $one_file) { |
||
544 | if (is_file($one_file)) { |
||
545 | unlink($one_file); |
||
546 | } |
||
547 | } |
||
548 | } |
||
549 | } |
||
550 | } |
||
551 | } |
||
552 | |||
553 | /** |
||
554 | * Redirect user with a message |
||
555 | * |
||
556 | * @param string $message message to display |
||
557 | * @param string $url The place where to go |
||
558 | * @param mixed $time |
||
559 | */ |
||
560 | public static function redirect($message = '', $url = 'index.php', $time = 2) |
||
561 | { |
||
562 | redirect_header($url, $time, $message); |
||
563 | } |
||
564 | |||
565 | /** |
||
566 | * Returns the module's name (as defined by the user in the module manager) with cache |
||
567 | * |
||
568 | * @return string Module's name |
||
569 | */ |
||
570 | public static function getModuleName() |
||
571 | { |
||
572 | static $moduleName; |
||
573 | if (!isset($moduleName)) { |
||
574 | $mymodule = self::_getModule(); |
||
575 | $moduleName = $mymodule->getVar('name'); |
||
576 | } |
||
577 | |||
578 | return $moduleName; |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * Create a title for the href tags inside html links |
||
583 | * |
||
584 | * @param string $title Text to use |
||
585 | * |
||
586 | * @return string Formated text |
||
587 | */ |
||
588 | public static function makeHrefTitle($title) |
||
589 | { |
||
590 | $s = "\"'"; |
||
591 | $r = ' '; |
||
592 | |||
593 | return strtr($title, $s, $r); |
||
594 | } |
||
595 | |||
596 | /** |
||
597 | * Retourne la liste des utilisateurs appartenants à un groupe |
||
598 | * |
||
599 | * @param int $groupId Searched group |
||
600 | * |
||
601 | * @return array Array of XoopsUsers |
||
602 | */ |
||
603 | public static function getUsersFromGroup($groupId) |
||
604 | { |
||
605 | $users = []; |
||
606 | $memberHandler = xoops_getHandler('member'); |
||
607 | $users = $memberHandler->getUsersByGroup($groupId, true); |
||
608 | |||
609 | return $users; |
||
610 | } |
||
611 | |||
612 | /** |
||
613 | * Retourne la liste des emails des utilisateurs membres d'un groupe |
||
614 | * |
||
615 | * @param $groupId |
||
616 | * |
||
617 | * @return array Emails list |
||
618 | * @internal param int $group_id Group's number |
||
619 | */ |
||
620 | public static function getEmailsFromGroup($groupId) |
||
621 | { |
||
622 | $ret = []; |
||
623 | $users = self::getUsersFromGroup($groupId); |
||
624 | foreach ($users as $user) { |
||
625 | $ret[] = $user->getVar('email'); |
||
626 | } |
||
627 | |||
628 | return $ret; |
||
629 | } |
||
630 | |||
631 | /** |
||
632 | * Vérifie que l'utilisateur courant fait partie du groupe des administrateurs |
||
633 | * |
||
634 | * @return bool Admin or not |
||
635 | */ |
||
636 | public static function isAdmin() |
||
637 | { |
||
638 | global $xoopsUser, $xoopsModule; |
||
639 | if (is_object($xoopsUser)) { |
||
640 | if (in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups())) { |
||
641 | return true; |
||
642 | } elseif (isset($xoopsModule) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
||
643 | return true; |
||
644 | } |
||
645 | } |
||
646 | |||
647 | return false; |
||
648 | } |
||
649 | |||
650 | /** |
||
651 | * Returns the current date in the Mysql format |
||
652 | * |
||
653 | * @return string Date in the Mysql format |
||
654 | */ |
||
655 | public static function getCurrentSQLDate() |
||
656 | { |
||
657 | return date('Y-m-d'); // 2007-05-02 |
||
658 | } |
||
659 | |||
660 | /** |
||
661 | * @return bool|string |
||
662 | */ |
||
663 | public static function getCurrentSQLDateTime() |
||
664 | { |
||
665 | return date('Y-m-d H:i:s'); // 2007-05-02 |
||
666 | } |
||
667 | |||
668 | /** |
||
669 | * Convert a Mysql date to the human's format |
||
670 | * |
||
671 | * @param string $date The date to convert |
||
672 | * @param string $format |
||
673 | * |
||
674 | * @return string The date in a human form |
||
675 | */ |
||
676 | public static function SQLDateToHuman($date, $format = 'l') |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * Convert a timestamp to a Mysql date |
||
687 | * |
||
688 | * @param int $timestamp The timestamp to use |
||
689 | * |
||
690 | * @return string The date in the Mysql format |
||
691 | */ |
||
692 | public static function timestampToMysqlDate($timestamp) |
||
693 | { |
||
694 | return date('Y-m-d', (int)$timestamp); |
||
695 | } |
||
696 | |||
697 | /** |
||
698 | * Conversion d'un dateTime Mysql en date lisible en français |
||
699 | * |
||
700 | * @param $dateTime |
||
701 | * |
||
702 | * @return bool|string |
||
703 | */ |
||
704 | public static function sqlDateTimeToFrench($dateTime) |
||
705 | { |
||
706 | return date('d/m/Y H:i:s', strtotime($dateTime)); |
||
707 | } |
||
708 | |||
709 | /** |
||
710 | * Convert a timestamp to a Mysql datetime form |
||
711 | * |
||
712 | * @param int $timestamp The timestamp to use |
||
713 | * |
||
714 | * @return string The date and time in the Mysql format |
||
715 | */ |
||
716 | public static function timestampToMysqlDateTime($timestamp) |
||
717 | { |
||
718 | return date('Y-m-d H:i:s', $timestamp); |
||
719 | } |
||
720 | |||
721 | /** |
||
722 | * This function indicates if the current Xoops version needs to add asterisks to required fields in forms |
||
723 | * |
||
724 | * @return bool Yes = we need to add them, false = no |
||
725 | */ |
||
726 | public static function needsAsterisk() |
||
727 | { |
||
728 | if (self::isX23()) { |
||
729 | return false; |
||
730 | } |
||
731 | if (false !== mb_stripos(XOOPS_VERSION, 'impresscms')) { |
||
732 | return false; |
||
733 | } |
||
734 | if (false === mb_stripos(XOOPS_VERSION, 'legacy')) { |
||
735 | $xv = xoops_trim(str_replace('XOOPS ', '', XOOPS_VERSION)); |
||
736 | if ((int)mb_substr($xv, 4, 2) >= 17) { |
||
737 | return false; |
||
738 | } |
||
739 | } |
||
740 | |||
741 | return true; |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * Mark the mandatory fields of a form with a star |
||
746 | * |
||
747 | * @param \XoopsObject $sform The form to modify |
||
748 | * |
||
749 | * @return \XoopsObject The modified form |
||
750 | * @internal param string $caracter The character to use to mark fields |
||
751 | */ |
||
752 | public static function &formMarkRequiredFields(XoopsObject $sform) |
||
753 | { |
||
754 | if (self::needsAsterisk()) { |
||
755 | $required = []; |
||
756 | foreach ($sform->getRequired() as $item) { |
||
757 | $required[] = $item->_name; |
||
758 | } |
||
759 | $elements = []; |
||
760 | $elements = $sform->getElements(); |
||
761 | foreach ($elements as $iValue) { |
||
762 | if (is_object($iValue) && in_array($iValue->_name, $required)) { |
||
763 | $iValue->_caption .= ' *'; |
||
764 | } |
||
765 | } |
||
766 | } |
||
767 | |||
768 | return $sform; |
||
769 | } |
||
770 | |||
771 | /** |
||
772 | * Create an html heading (from h1 to h6) |
||
773 | * |
||
774 | * @param string $title The text to use |
||
775 | * @param int $level Level to return |
||
776 | * |
||
777 | * @return string The heading |
||
778 | */ |
||
779 | public static function htitle($title = '', $level = 1) |
||
780 | { |
||
781 | printf('<h%01d>%s</h%01d>', $level, $title, $level); |
||
782 | } |
||
783 | |||
784 | /** |
||
785 | * Create a unique upload filename |
||
786 | * |
||
787 | * @param string $folder The folder where the file will be saved |
||
788 | * @param string $fileName Original filename (coming from the user) |
||
789 | * @param bool $trimName Do we need to create a "short" unique name ? |
||
790 | * |
||
791 | * @return string The unique filename to use (with its extension) |
||
792 | */ |
||
793 | public static function createUploadName($folder, $fileName, $trimName = false) |
||
794 | { |
||
795 | $workingfolder = $folder; |
||
796 | if ('/' !== xoops_substr($workingfolder, mb_strlen($workingfolder) - 1, 1)) { |
||
797 | $workingfolder .= '/'; |
||
798 | } |
||
799 | $ext = basename($fileName); |
||
800 | $ext = explode('.', $ext); |
||
801 | $ext = '.' . $ext[count($ext) - 1]; |
||
802 | $true = true; |
||
803 | while ($true) { |
||
804 | $ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
||
805 | [$usec, $sec] = explode(' ', microtime()); |
||
806 | $usec *= 65536; |
||
807 | $sec = ((int)$sec) & 0xFFFF; |
||
808 | |||
809 | if ($trimName) { |
||
810 | $uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
||
811 | } else { |
||
812 | $uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
||
813 | } |
||
814 | if (!file_exists($workingfolder . $uid . $ext)) { |
||
815 | $true = false; |
||
816 | } |
||
817 | } |
||
818 | |||
819 | return $uid . $ext; |
||
820 | } |
||
821 | |||
822 | /** |
||
823 | * Replace html entities with their ASCII equivalent |
||
824 | * |
||
825 | * @param string $chaine The string undecode |
||
826 | * |
||
827 | * @return string The undecoded string |
||
828 | */ |
||
829 | public static function unhtml($chaine) |
||
830 | { |
||
831 | $search = $replace = []; |
||
832 | $chaine = html_entity_decode($chaine); |
||
833 | |||
834 | for ($i = 0; $i <= 255; ++$i) { |
||
835 | $search[] = '&#' . $i . ';'; |
||
836 | $replace[] = chr($i); |
||
837 | } |
||
838 | $replace[] = '...'; |
||
839 | $search[] = ' '; |
||
840 | $replace[] = "'"; |
||
841 | $search[] = ''; |
||
842 | $replace[] = "'"; |
||
843 | $search[] = ''; |
||
844 | $replace[] = '-'; |
||
845 | $search[] = '•'; // $replace[] = ''; |
||
846 | $replace[] = ''; |
||
847 | $search[] = '—'; |
||
848 | $replace[] = '-'; |
||
849 | $search[] = '–'; |
||
850 | $replace[] = '-'; |
||
851 | $search[] = '­'; |
||
852 | $replace[] = '"'; |
||
853 | $search[] = '"'; |
||
854 | $replace[] = '&'; |
||
855 | $search[] = '&'; |
||
856 | $replace[] = ''; |
||
857 | $search[] = 'ˆ'; |
||
858 | $replace[] = '¡'; |
||
859 | $search[] = '¡'; |
||
860 | $replace[] = '¦'; |
||
861 | $search[] = '¦'; |
||
862 | $replace[] = '¨'; |
||
863 | $search[] = '¨'; |
||
864 | $replace[] = '¯'; |
||
865 | $search[] = '¯'; |
||
866 | $replace[] = '´'; |
||
867 | $search[] = '´'; |
||
868 | $replace[] = '¸'; |
||
869 | $search[] = '¸'; |
||
870 | $replace[] = '¿'; |
||
871 | $search[] = '¿'; |
||
872 | $replace[] = ''; |
||
873 | $search[] = '˜'; |
||
874 | $replace[] = "'"; |
||
875 | $search[] = '‘'; // $replace[]=''; |
||
876 | $replace[] = "'"; |
||
877 | $search[] = '’'; // $replace[]=''; |
||
878 | $replace[] = ''; |
||
879 | $search[] = '‚'; |
||
880 | $replace[] = "'"; |
||
881 | $search[] = '“'; // $replace[]=''; |
||
882 | $replace[] = "'"; |
||
883 | $search[] = '”'; // $replace[]=''; |
||
884 | $replace[] = ''; |
||
885 | $search[] = '„'; |
||
886 | $replace[] = ''; |
||
887 | $search[] = '‹'; |
||
888 | $replace[] = ''; |
||
889 | $search[] = '›'; |
||
890 | $replace[] = '<'; |
||
891 | $search[] = '<'; |
||
892 | $replace[] = '>'; |
||
893 | $search[] = '>'; |
||
894 | $replace[] = '±'; |
||
895 | $search[] = '±'; |
||
896 | $replace[] = '«'; |
||
897 | $search[] = '«'; |
||
898 | $replace[] = '»'; |
||
899 | $search[] = '»'; |
||
900 | $replace[] = '×'; |
||
901 | $search[] = '×'; |
||
902 | $replace[] = '÷'; |
||
903 | $search[] = '÷'; |
||
904 | $replace[] = '¢'; |
||
905 | $search[] = '¢'; |
||
906 | $replace[] = '£'; |
||
907 | $search[] = '£'; |
||
908 | $replace[] = '¤'; |
||
909 | $search[] = '¤'; |
||
910 | $replace[] = '¥'; |
||
911 | $search[] = '¥'; |
||
912 | $replace[] = '§'; |
||
913 | $search[] = '§'; |
||
914 | $replace[] = '©'; |
||
915 | $search[] = '©'; |
||
916 | $replace[] = '¬'; |
||
917 | $search[] = '¬'; |
||
918 | $replace[] = '®'; |
||
919 | $search[] = '®'; |
||
920 | $replace[] = '°'; |
||
921 | $search[] = '°'; |
||
922 | $replace[] = 'µ'; |
||
923 | $search[] = 'µ'; |
||
924 | $replace[] = '¶'; |
||
925 | $search[] = '¶'; |
||
926 | $replace[] = '·'; |
||
927 | $search[] = '·'; |
||
928 | $replace[] = ''; |
||
929 | $search[] = '†'; |
||
930 | $replace[] = ''; |
||
931 | $search[] = '‡'; |
||
932 | $replace[] = ''; |
||
933 | $search[] = '‰'; |
||
934 | $replace[] = 'Euro'; |
||
935 | $search[] = '€'; // $replace[]='' |
||
936 | $replace[] = '¼'; |
||
937 | $search[] = '¼'; |
||
938 | $replace[] = '½'; |
||
939 | $search[] = '½'; |
||
940 | $replace[] = '¾'; |
||
941 | $search[] = '¾'; |
||
942 | $replace[] = '¹'; |
||
943 | $search[] = '¹'; |
||
944 | $replace[] = '²'; |
||
945 | $search[] = '²'; |
||
946 | $replace[] = '³'; |
||
947 | $search[] = '³'; |
||
948 | $replace[] = 'á'; |
||
949 | $search[] = 'á'; |
||
950 | $replace[] = 'Á'; |
||
951 | $search[] = 'Á'; |
||
952 | $replace[] = 'â'; |
||
953 | $search[] = 'â'; |
||
954 | $replace[] = 'Â'; |
||
955 | $search[] = 'Â'; |
||
956 | $replace[] = 'à'; |
||
957 | $search[] = 'à'; |
||
958 | $replace[] = 'À'; |
||
959 | $search[] = 'À'; |
||
960 | $replace[] = 'å'; |
||
961 | $search[] = 'å'; |
||
962 | $replace[] = 'Å'; |
||
963 | $search[] = 'Å'; |
||
964 | $replace[] = 'ã'; |
||
965 | $search[] = 'ã'; |
||
966 | $replace[] = 'Ã'; |
||
967 | $search[] = 'Ã'; |
||
968 | $replace[] = 'ä'; |
||
969 | $search[] = 'ä'; |
||
970 | $replace[] = 'Ä'; |
||
971 | $search[] = 'Ä'; |
||
972 | $replace[] = 'ª'; |
||
973 | $search[] = 'ª'; |
||
974 | $replace[] = 'æ'; |
||
975 | $search[] = 'æ'; |
||
976 | $replace[] = 'Æ'; |
||
977 | $search[] = 'Æ'; |
||
978 | $replace[] = 'ç'; |
||
979 | $search[] = 'ç'; |
||
980 | $replace[] = 'Ç'; |
||
981 | $search[] = 'Ç'; |
||
982 | $replace[] = 'ð'; |
||
983 | $search[] = 'ð'; |
||
984 | $replace[] = 'Ð'; |
||
985 | $search[] = 'Ð'; |
||
986 | $replace[] = 'é'; |
||
987 | $search[] = 'é'; |
||
988 | $replace[] = 'É'; |
||
989 | $search[] = 'É'; |
||
990 | $replace[] = 'ê'; |
||
991 | $search[] = 'ê'; |
||
992 | $replace[] = 'Ê'; |
||
993 | $search[] = 'Ê'; |
||
994 | $replace[] = 'è'; |
||
995 | $search[] = 'è'; |
||
996 | $replace[] = 'È'; |
||
997 | $search[] = 'È'; |
||
998 | $replace[] = 'ë'; |
||
999 | $search[] = 'ë'; |
||
1000 | $replace[] = 'Ë'; |
||
1001 | $search[] = 'Ë'; |
||
1002 | $replace[] = ''; |
||
1003 | $search[] = 'ƒ'; |
||
1004 | $replace[] = 'í'; |
||
1005 | $search[] = 'í'; |
||
1006 | $replace[] = 'Í'; |
||
1007 | $search[] = 'Í'; |
||
1008 | $replace[] = 'î'; |
||
1009 | $search[] = 'î'; |
||
1010 | $replace[] = 'Î'; |
||
1011 | $search[] = 'Î'; |
||
1012 | $replace[] = 'ì'; |
||
1013 | $search[] = 'ì'; |
||
1014 | $replace[] = 'Ì'; |
||
1015 | $search[] = 'Ì'; |
||
1016 | $replace[] = 'ï'; |
||
1017 | $search[] = 'ï'; |
||
1018 | $replace[] = 'Ï'; |
||
1019 | $search[] = 'Ï'; |
||
1020 | $replace[] = 'ñ'; |
||
1021 | $search[] = 'ñ'; |
||
1022 | $replace[] = 'Ñ'; |
||
1023 | $search[] = 'Ñ'; |
||
1024 | $replace[] = 'ó'; |
||
1025 | $search[] = 'ó'; |
||
1026 | $replace[] = 'Ó'; |
||
1027 | $search[] = 'Ó'; |
||
1028 | $replace[] = 'ô'; |
||
1029 | $search[] = 'ô'; |
||
1030 | $replace[] = 'Ô'; |
||
1031 | $search[] = 'Ô'; |
||
1032 | $replace[] = 'ò'; |
||
1033 | $search[] = 'ò'; |
||
1034 | $replace[] = 'Ò'; |
||
1035 | $search[] = 'Ò'; |
||
1036 | $replace[] = 'º'; |
||
1037 | $search[] = 'º'; |
||
1038 | $replace[] = 'ø'; |
||
1039 | $search[] = 'ø'; |
||
1040 | $replace[] = 'Ø'; |
||
1041 | $search[] = 'Ø'; |
||
1042 | $replace[] = 'õ'; |
||
1043 | $search[] = 'õ'; |
||
1044 | $replace[] = 'Õ'; |
||
1045 | $search[] = 'Õ'; |
||
1046 | $replace[] = 'ö'; |
||
1047 | $search[] = 'ö'; |
||
1048 | $replace[] = 'Ö'; |
||
1049 | $search[] = 'Ö'; |
||
1050 | $replace[] = ''; |
||
1051 | $search[] = 'œ'; |
||
1052 | $replace[] = ''; |
||
1053 | $search[] = 'Œ'; |
||
1054 | $replace[] = ''; |
||
1055 | $search[] = 'š'; |
||
1056 | $replace[] = ''; |
||
1057 | $search[] = 'Š'; |
||
1058 | $replace[] = 'ß'; |
||
1059 | $search[] = 'ß'; |
||
1060 | $replace[] = 'þ'; |
||
1061 | $search[] = 'þ'; |
||
1062 | $replace[] = 'Þ'; |
||
1063 | $search[] = 'Þ'; |
||
1064 | $replace[] = 'ú'; |
||
1065 | $search[] = 'ú'; |
||
1066 | $replace[] = 'Ú'; |
||
1067 | $search[] = 'Ú'; |
||
1068 | $replace[] = 'û'; |
||
1069 | $search[] = 'û'; |
||
1070 | $replace[] = 'Û'; |
||
1071 | $search[] = 'Û'; |
||
1072 | $replace[] = 'ù'; |
||
1073 | $search[] = 'ù'; |
||
1074 | $replace[] = 'Ù'; |
||
1075 | $search[] = 'Ù'; |
||
1076 | $replace[] = 'ü'; |
||
1077 | $search[] = 'ü'; |
||
1078 | $replace[] = 'Ü'; |
||
1079 | $search[] = 'Ü'; |
||
1080 | $replace[] = 'ý'; |
||
1081 | $search[] = 'ý'; |
||
1082 | $replace[] = 'Ý'; |
||
1083 | $search[] = 'Ý'; |
||
1084 | $replace[] = 'ÿ'; |
||
1085 | $search[] = 'ÿ'; |
||
1086 | $replace[] = ''; |
||
1087 | $search[] = 'Ÿ'; |
||
1088 | $chaine = str_replace($search, $replace, $chaine); |
||
1089 | |||
1090 | return $chaine; |
||
1091 | } |
||
1092 | |||
1093 | /** |
||
1094 | * Create a title to be used by the url rewriting |
||
1095 | * |
||
1096 | * @param string $content The text to use to create the url |
||
1097 | * @param int $urw The lower limit to create words |
||
1098 | * |
||
1099 | * @return string The text to use for the url |
||
1100 | * Note, some parts are from Solo's code |
||
1101 | */ |
||
1102 | public static function makeSeoUrl($content, $urw = 1) |
||
1103 | { |
||
1104 | $s = "ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÇÌÍÎÏÙÚÛÜÑàáâãäåòóôõöøèéêëçìíîïùúûüÿñ '()"; |
||
1105 | $r = 'AAAAAAOOOOOOEEEECIIIIUUUUYNaaaaaaooooooeeeeciiiiuuuuyn----'; |
||
1106 | $content = self::unhtml($content); // First, remove html entities |
||
1107 | $content = strtr($content, $s, $r); |
||
1108 | $content = strip_tags($content); |
||
1109 | $content = mb_strtolower($content); |
||
1110 | $content = htmlentities($content, ENT_QUOTES | ENT_HTML5); // TODO: Vérifier |
||
1111 | $content = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $content); |
||
1112 | $content = html_entity_decode($content); |
||
1113 | $content = str_ireplace('quot', ' ', $content); |
||
1114 | $content = preg_replace("/'/i", ' ', $content); |
||
1115 | $content = str_ireplace('-', ' ', $content); |
||
1116 | $content = preg_replace('/[[:punct:]]/i', '', $content); |
||
1117 | |||
1118 | // Selon option mais attention au fichier .htaccess ! |
||
1119 | // $content = eregi_replace('[[:digit:]]','', $content); |
||
1120 | $content = preg_replace('/[^a-z|A-Z|0-9]/', '-', $content); |
||
1121 | |||
1122 | $words = explode(' ', $content); |
||
1123 | $keywords = ''; |
||
1124 | foreach ($words as $word) { |
||
1125 | if (mb_strlen($word) >= $urw) { |
||
1126 | $keywords .= '-' . trim($word); |
||
1127 | } |
||
1128 | } |
||
1129 | if (!$keywords) { |
||
1130 | $keywords = '-'; |
||
1131 | } |
||
1132 | // Supprime les tirets en double |
||
1133 | $keywords = str_replace('---', '-', $keywords); |
||
1134 | $keywords = str_replace('--', '-', $keywords); |
||
1135 | // Supprime un éventuel tiret à la fin de la chaine |
||
1136 | if ('-' === mb_substr($keywords, mb_strlen($keywords) - 1, 1)) { |
||
1137 | $keywords = mb_substr($keywords, 0, -1); |
||
1138 | } |
||
1139 | |||
1140 | return $keywords; |
||
1141 | } |
||
1142 | |||
1143 | /** |
||
1144 | * Create the meta keywords based on the content |
||
1145 | * |
||
1146 | * @param string $content Content from which we have to create metakeywords |
||
1147 | * |
||
1148 | * @return string The list of meta keywords |
||
1149 | */ |
||
1150 | public static function createMetaKeywords($content) |
||
1151 | { |
||
1152 | $keywordscount = self::getModuleOption('metagen_maxwords'); |
||
1153 | $keywordsorder = self::getModuleOption('metagen_order'); |
||
1154 | |||
1155 | $tmp = []; |
||
1156 | // Search for the "Minimum keyword length" |
||
1157 | if (Request::hasVar('xoopstube_keywords_limit', 'SESSION')) { |
||
1158 | $limit = $_SESSION['xoopstube_keywords_limit']; |
||
1159 | } else { |
||
1160 | $configHandler = xoops_getHandler('config'); |
||
1161 | $xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
||
1162 | $limit = $xoopsConfigSearch['keyword_min']; |
||
1163 | $_SESSION['xoopstube_keywords_limit'] = $limit; |
||
1164 | } |
||
1165 | $myts = MyTextSanitizer::getInstance(); |
||
1166 | $content = str_replace('<br>', ' ', $content); |
||
1167 | $content = $myts->undoHtmlSpecialChars($content); |
||
1168 | $content = strip_tags($content); |
||
1169 | $content = mb_strtolower($content); |
||
1170 | $search_pattern = [' ', "\t", "\r\n", "\r", "\n", ',', '.', "'", ';', ':', ')', '(', '"', '?', '!', '{', '}', '[', ']', '<', '>', '/', '+', '-', '_', '\\', '*']; |
||
1171 | $replace_pattern = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']; |
||
1172 | $content = str_replace($search_pattern, $replace_pattern, $content); |
||
1173 | $keywords = explode(' ', $content); |
||
1174 | switch ($keywordsorder) { |
||
1175 | case 0: // Ordre d'apparition dans le texte |
||
1176 | $keywords = array_unique($keywords); |
||
1177 | break; |
||
1178 | case 1: // Ordre de fréquence des mots |
||
1179 | $keywords = array_count_values($keywords); |
||
1180 | asort($keywords); |
||
1181 | $keywords = array_keys($keywords); |
||
1182 | break; |
||
1183 | case 2: // Ordre inverse de la fréquence des mots |
||
1184 | $keywords = array_count_values($keywords); |
||
1185 | arsort($keywords); |
||
1186 | $keywords = array_keys($keywords); |
||
1187 | break; |
||
1188 | } |
||
1189 | // Remove black listed words |
||
1190 | if ('' !== xoops_trim(self::getModuleOption('metagen_blacklist'))) { |
||
1191 | $metagen_blacklist = str_replace("\r", '', self::getModuleOption('metagen_blacklist')); |
||
1192 | $metablack = explode("\n", $metagen_blacklist); |
||
1193 | array_walk($metablack, '\trim'); |
||
1194 | $keywords = array_diff($keywords, $metablack); |
||
1195 | } |
||
1196 | |||
1197 | foreach ($keywords as $keyword) { |
||
1198 | if (mb_strlen($keyword) >= $limit && !is_numeric($keyword)) { |
||
1199 | $tmp[] = $keyword; |
||
1200 | } |
||
1201 | } |
||
1202 | $tmp = array_slice($tmp, 0, $keywordscount); |
||
1203 | if (count($tmp) > 0) { |
||
1204 | return implode(',', $tmp); |
||
1205 | } |
||
1206 | if (!isset($configHandler) || !is_object($configHandler)) { |
||
1207 | $configHandler = xoops_getHandler('config'); |
||
1208 | } |
||
1209 | $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
||
1210 | return $xoopsConfigMetaFooter['meta_keywords'] ?? ''; |
||
1211 | } |
||
1212 | |||
1213 | /** |
||
1214 | * Fonction chargée de gérer l'upload |
||
1215 | * |
||
1216 | * @param int $indice L'indice du fichier à télécharger |
||
1217 | * @param string $dstpath |
||
1218 | * @param null $mimeTypes |
||
1219 | * @param null $uploadMaxSize |
||
1220 | * @param null $maxWidth |
||
1221 | * @param null $maxHeight |
||
1222 | * |
||
1223 | * @return mixed True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
||
1224 | */ |
||
1225 | public static function uploadFile( |
||
1226 | $indice, |
||
1227 | $dstpath = XOOPS_UPLOAD_PATH, |
||
1228 | $mimeTypes = null, |
||
1229 | $uploadMaxSize = null, |
||
1230 | $maxWidth = null, |
||
1231 | $maxHeight = null |
||
1232 | ) { |
||
1233 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
1234 | global $destname; |
||
1235 | if (Request::hasVar('xoops_upload_file', 'POST')) { |
||
1236 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
1237 | $fldname = ''; |
||
1238 | $fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
||
1239 | $fldname = $fldname['name']; |
||
1240 | if (xoops_trim('' !== $fldname)) { |
||
1241 | $destname = self::createUploadName($dstpath, $fldname, true); |
||
1242 | if (null === $mimeTypes) { |
||
1243 | $permittedtypes = explode("\n", str_replace("\r", '', self::getModuleOption('mimetypes'))); |
||
1244 | array_walk($permittedtypes, '\trim'); |
||
1245 | } else { |
||
1246 | $permittedtypes = $mimeTypes; |
||
1247 | } |
||
1248 | $uploadSize = $uploadMaxSize ?? self::getModuleOption('maxuploadsize'); |
||
1249 | $uploader = new Xoopstube\MediaUploader($dstpath, $permittedtypes, $uploadSize, $maxWidth, $maxHeight); |
||
1250 | //$uploader->allowUnknownTypes = true; |
||
1251 | $uploader->setTargetFileName($destname); |
||
1252 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][$indice])) { |
||
1253 | if ($uploader->upload()) { |
||
1254 | return true; |
||
1255 | } |
||
1256 | |||
1257 | return _ERRORS . ' ' . htmlentities($uploader->getErrors(), ENT_QUOTES | ENT_HTML5); |
||
1258 | } |
||
1259 | |||
1260 | return htmlentities($uploader->getErrors(), ENT_QUOTES | ENT_HTML5); |
||
1261 | } |
||
1262 | |||
1263 | return false; |
||
1264 | } |
||
1265 | |||
1266 | return false; |
||
1267 | } |
||
1268 | |||
1269 | /** |
||
1270 | * Resize a Picture to some given dimensions (using the wideImage library) |
||
1271 | * |
||
1272 | * @param string $src_path Picture's source |
||
1273 | * @param string $dst_path Picture's destination |
||
1274 | * @param int $param_width Maximum picture's width |
||
1275 | * @param int $param_height Maximum picture's height |
||
1276 | * @param bool $keep_original Do we have to keep the original picture ? |
||
1277 | * @param string $fit Resize mode (see the wideImage library for more information) |
||
1278 | * |
||
1279 | * @return bool |
||
1280 | */ |
||
1281 | public static function resizePicture( |
||
1282 | $src_path, |
||
1283 | $dst_path, |
||
1284 | $param_width, |
||
1285 | $param_height, |
||
1286 | $keep_original = false, |
||
1287 | $fit = 'inside' |
||
1288 | ) { |
||
1289 | $resize = true; |
||
1290 | if (XOOPSTUBE_DONT_RESIZE_IF_SMALLER) { |
||
1291 | $pictureDimensions = getimagesize($src_path); |
||
1292 | if (is_array($pictureDimensions)) { |
||
1293 | $width = $pictureDimensions[0]; |
||
1294 | $height = $pictureDimensions[1]; |
||
1295 | if ($width < $param_width && $height < $param_height) { |
||
1296 | $resize = false; |
||
1297 | } |
||
1298 | } |
||
1299 | } |
||
1300 | |||
1301 | $img = WideImage::load($src_path); |
||
1302 | if ($resize) { |
||
1303 | $result = $img->resize($param_width, $param_height, $fit); |
||
1304 | $result->saveToFile($dst_path); |
||
1305 | } else { |
||
1306 | @copy($src_path, $dst_path); |
||
1307 | } |
||
1308 | |||
1309 | if (!$keep_original) { |
||
1310 | @unlink($src_path); |
||
1311 | } |
||
1312 | |||
1313 | return true; |
||
1314 | } |
||
1315 | |||
1316 | /** |
||
1317 | * Add days to a date and return the new date in Mysql Date format |
||
1318 | * |
||
1319 | * @param int $duration |
||
1320 | * @param int $startingDate Starting date (timestamp) |
||
1321 | * |
||
1322 | * @return bool|string |
||
1323 | * @internal param int $ Duration in days |
||
1324 | */ |
||
1325 | public static function addDaysToDate($duration = 1, $startingDate = 0) |
||
1326 | { |
||
1327 | if (0 == $startingDate) { |
||
1328 | $startingDate = time(); |
||
1329 | } |
||
1330 | $endingDate = $startingDate + ($duration * 86400); |
||
1331 | |||
1332 | return date('Y-m-d', $endingDate); |
||
1333 | } |
||
1334 | |||
1335 | /** |
||
1336 | * Returns a breadcrumb according to the parameters passed and starting (automatically) from the root of the module |
||
1337 | * |
||
1338 | * @param array $path The full path (except the root) of the breadcrumb in the form of key = url value = title |
||
1339 | * @param string $raquo The default separator to use |
||
1340 | * |
||
1341 | * @return string le breadcrumb |
||
1342 | */ |
||
1343 | public static function breadcrumb($path, $raquo = ' » ') |
||
1344 | { |
||
1345 | $breadcrumb = ''; |
||
1346 | $workingBreadcrumb = []; |
||
1347 | if (is_array($path)) { |
||
1348 | $moduleName = self::getModuleName(); |
||
1349 | $workingBreadcrumb[] = "<a href='" . XOOPSTUBE_URL . "' title='" . self::makeHrefTitle($moduleName) . "'>" . $moduleName . '</a>'; |
||
1350 | foreach ($path as $url => $title) { |
||
1351 | $workingBreadcrumb[] = "<a href='" . $url . "'>" . $title . '</a>'; |
||
1352 | } |
||
1353 | $cnt = count($workingBreadcrumb); |
||
1354 | foreach ($workingBreadcrumb as $i => $iValue) { |
||
1355 | if ($i == $cnt - 1) { |
||
1356 | $workingBreadcrumb[$i] = strip_tags($iValue); |
||
1357 | } |
||
1358 | } |
||
1359 | $breadcrumb = implode($raquo, $workingBreadcrumb); |
||
1360 | } |
||
1361 | |||
1362 | return $breadcrumb; |
||
1363 | } |
||
1364 | |||
1365 | /** |
||
1366 | * @param $string |
||
1367 | * |
||
1368 | * @return string |
||
1369 | */ |
||
1370 | public static function close_tags($string) |
||
1371 | { |
||
1372 | // match opened tags |
||
1373 | if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
||
1374 | $start_tags = $start_tags[1]; |
||
1375 | |||
1376 | // match closed tags |
||
1377 | if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
||
1378 | $complete_tags = []; |
||
1379 | $end_tags = $end_tags[1]; |
||
1380 | |||
1381 | foreach ($start_tags as $key => $val) { |
||
1382 | $posb = array_search($val, $end_tags, true); |
||
1383 | if (is_int($posb)) { |
||
1384 | unset($end_tags[$posb]); |
||
1385 | } else { |
||
1386 | $complete_tags[] = $val; |
||
1387 | } |
||
1388 | } |
||
1389 | } else { |
||
1390 | $complete_tags = $start_tags; |
||
1391 | } |
||
1392 | |||
1393 | $complete_tags = array_reverse($complete_tags); |
||
1394 | foreach ($complete_tags as $iValue) { |
||
1395 | $string .= '</' . $iValue . '>'; |
||
1396 | } |
||
1397 | } |
||
1398 | |||
1399 | return $string; |
||
1400 | } |
||
1401 | |||
1402 | /** |
||
1403 | * @param $string |
||
1404 | * @param int $length |
||
1405 | * @param string $etc |
||
1406 | * @param bool $break_words |
||
1407 | * |
||
1408 | * @return mixed|string |
||
1409 | */ |
||
1410 | public static function truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) |
||
1411 | { |
||
1412 | if (0 == $length) { |
||
1413 | return ''; |
||
1414 | } |
||
1415 | |||
1416 | if (mb_strlen($string) > $length) { |
||
1417 | $length -= mb_strlen($etc); |
||
1418 | if (!$break_words) { |
||
1419 | $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1)); |
||
1420 | $string = preg_replace('/<[^>]*$/', '', $string); |
||
1421 | $string = self::close_tags($string); |
||
1422 | } |
||
1423 | |||
1424 | return $string . $etc; |
||
1425 | } |
||
1426 | |||
1427 | return $string; |
||
1428 | } |
||
1429 | |||
1430 | /** |
||
1431 | * Create an infotip |
||
1432 | * @param $text |
||
1433 | * @return string |
||
1434 | */ |
||
1435 | public static function makeInfotips($text) |
||
1436 | { |
||
1437 | $ret = ''; |
||
1438 | $infotips = self::getModuleOption('infotips'); |
||
1439 | if ($infotips > 0) { |
||
1440 | $myts = MyTextSanitizer::getInstance(); |
||
1441 | $ret = htmlspecialchars(xoops_substr(strip_tags($text), 0, $infotips)); |
||
1442 | } |
||
1443 | |||
1444 | return $ret; |
||
1445 | } |
||
1446 | |||
1447 | /** |
||
1448 | * @param $datastream |
||
1449 | * @param $url |
||
1450 | * |
||
1451 | * @return string |
||
1452 | */ |
||
1453 | public static function postIt($datastream, $url) |
||
1454 | { |
||
1455 | $url = preg_replace('@^http://@i', '', $url); |
||
1456 | $host = mb_substr($url, 0, mb_strpos($url, '/')); |
||
1457 | $uri = mb_strstr($url, '/'); |
||
1458 | $reqbody = ''; |
||
1459 | foreach ($datastream as $key => $val) { |
||
1460 | if (!empty($reqbody)) { |
||
1461 | $reqbody .= '&'; |
||
1462 | } |
||
1463 | $reqbody .= $key . '=' . urlencode($val); |
||
1464 | } |
||
1465 | $contentlength = mb_strlen($reqbody); |
||
1466 | $reqheader = "POST $uri HTTP/1.1\r\n" . "Host: $host\n" . "Content-Type: application/x-www-form-urlencoded\r\n" . "Content-Length: $contentlength\r\n\r\n" . "$reqbody\r\n"; |
||
1467 | |||
1468 | return $reqheader; |
||
1469 | } |
||
1470 | |||
1471 | /** |
||
1472 | * Returns the mime type of a file using first finfo then mime_content |
||
1473 | * |
||
1474 | * @param $filename |
||
1475 | * @return string |
||
1476 | */ |
||
1477 | public static function getMimeType($filename) |
||
1478 | { |
||
1479 | if (function_exists('finfo_open')) { |
||
1480 | $finfo = finfo_open(); |
||
1481 | $mimetype = finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); |
||
1482 | finfo_close($finfo); |
||
1483 | |||
1484 | return $mimetype; |
||
1485 | } |
||
1486 | if (function_exists('mime_content_type')) { |
||
1487 | return mime_content_type($filename); |
||
1488 | } |
||
1489 | |||
1490 | return ''; |
||
1491 | } |
||
1492 | |||
1493 | /** |
||
1494 | * Retourne un criteria compo qui permet de filtrer les produits sur le mois courant |
||
1495 | * |
||
1496 | * @return \CriteriaCompo |
||
1497 | */ |
||
1498 | public static function getThisMonthCriteria() |
||
1499 | { |
||
1500 | $start = mktime(0, 1, 0, date('n'), date('j'), date('Y')); |
||
1501 | $end = mktime(0, 0, 0, date('n'), date('t'), date('Y')); |
||
1502 | $criteriaThisMonth = new CriteriaCompo(); |
||
1503 | $criteriaThisMonth->add(new Criteria('product_submitted', $start, '>=')); |
||
1504 | $criteriaThisMonth->add(new Criteria('product_submitted', $end, '<=')); |
||
1505 | |||
1506 | return $criteriaThisMonth; |
||
1507 | } |
||
1508 | |||
1509 | /** |
||
1510 | * Retourne une liste d'objets XoopsUsers à partir d'une liste d'identifiants |
||
1511 | * |
||
1512 | * @param array $xoopsUsersIDs La liste des ID |
||
1513 | * |
||
1514 | * @return array Les objets XoopsUsers |
||
1515 | */ |
||
1516 | public static function getUsersFromIds($xoopsUsersIDs) |
||
1517 | { |
||
1518 | $users = []; |
||
1519 | if ($xoopsUsersIDs && is_array($xoopsUsersIDs)) { |
||
1520 | $xoopsUsersIDs = array_unique($xoopsUsersIDs); |
||
1521 | sort($xoopsUsersIDs); |
||
1522 | if (count($xoopsUsersIDs) > 0) { |
||
1523 | /** @var \XoopsUserHandler $memberHandler */ |
||
1524 | $memberHandler = xoops_getHandler('user'); |
||
1525 | $criteria = new Criteria('uid', '(' . implode(',', $xoopsUsersIDs) . ')', 'IN'); |
||
1526 | $criteria->setSort('uid'); |
||
1527 | $users = $memberHandler->getObjects($criteria, true); |
||
1528 | } |
||
1529 | } |
||
1530 | |||
1531 | return $users; |
||
1532 | } |
||
1533 | |||
1534 | /** |
||
1535 | * Retourne l'ID de l'utilisateur courant (s'il est connecté) |
||
1536 | * |
||
1537 | * @return int L'uid ou 0 |
||
1538 | */ |
||
1539 | public static function getCurrentUserID() |
||
1540 | { |
||
1546 | |||
1547 | /** |
||
1548 | * Retourne la liste des groupes de l'utilisateur courant (avec cache) |
||
1549 | * |
||
1550 | * @param int $uid |
||
1551 | * |
||
1552 | * @return array Les ID des groupes auquel l'utilisateur courant appartient |
||
1553 | */ |
||
1554 | public static function getMemberGroups($uid = 0) |
||
1555 | { |
||
1556 | static $buffer = []; |
||
1557 | if (0 == $uid) { |
||
1558 | $uid = self::getCurrentUserID(); |
||
1559 | } |
||
1560 | |||
1561 | if (is_array($buffer) && count($buffer) > 0 && isset($buffer[$uid])) { |
||
1562 | return $buffer[$uid]; |
||
1563 | } |
||
1564 | if ($uid > 0) { |
||
1565 | $memberHandler = xoops_getHandler('member'); |
||
1566 | $buffer[$uid] = $memberHandler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
||
1567 | } else { |
||
1568 | $buffer[$uid] = [XOOPS_GROUP_ANONYMOUS]; |
||
1569 | } |
||
1570 | |||
1571 | return $buffer[$uid]; |
||
1572 | } |
||
1573 | |||
1574 | /** |
||
1575 | * Indique si l'utilisateur courant fait partie d'une groupe donné (avec gestion de cache) |
||
1576 | * |
||
1577 | * @param int $group Groupe recherché |
||
1578 | * @param int $uid |
||
1579 | * |
||
1580 | * @return bool vrai si l'utilisateur fait partie du groupe, faux sinon |
||
1581 | */ |
||
1582 | public static function isMemberOfGroup($group = 0, $uid = 0) |
||
1583 | { |
||
1584 | static $buffer = []; |
||
1585 | $retval = false; |
||
1586 | if (0 == $uid) { |
||
1587 | $uid = self::getCurrentUserID(); |
||
1588 | } |
||
1589 | if (is_array($buffer) && array_key_exists($group, $buffer)) { |
||
1590 | $retval = $buffer[$group]; |
||
1591 | } else { |
||
1592 | $memberHandler = xoops_getHandler('member'); |
||
1593 | $groups = $memberHandler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
||
1594 | $retval = in_array($group, $groups); |
||
1595 | $buffer[$group] = $retval; |
||
1596 | } |
||
1597 | |||
1598 | return $retval; |
||
1599 | } |
||
1600 | |||
1601 | /** |
||
1602 | * Function responsible for verifying that a directory exists, we can write in and create an index.html file |
||
1603 | * |
||
1604 | * @param $folder |
||
1605 | */ |
||
1606 | public static function prepareFolder($folder) |
||
1607 | { |
||
1608 | if (!is_dir($folder)) { |
||
1609 | if (!mkdir($folder) && !is_dir($folder)) { |
||
1610 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $folder)); |
||
1611 | } |
||
1612 | file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
||
1613 | } |
||
1614 | // chmod($folder, 0777); |
||
1615 | } |
||
1616 | |||
1617 | /** |
||
1618 | * Duplicate a file in local |
||
1619 | * |
||
1620 | * @param string $path The file's path |
||
1621 | * @param string $filename The filename |
||
1622 | * |
||
1623 | * @return mixed If the copy succeed, the new filename else false |
||
1624 | * @since 2.1 |
||
1625 | */ |
||
1626 | public static function duplicateFile($path, $filename) |
||
1627 | { |
||
1628 | $newName = self::createUploadName($path, $filename); |
||
1629 | if (copy($path . DIRECTORY_SEPARATOR . $filename, $path . DIRECTORY_SEPARATOR . $newName)) { |
||
1630 | return $newName; |
||
1631 | } |
||
1632 | |||
1633 | return false; |
||
1634 | } |
||
1635 | |||
1636 | //================================================================================================================================= |
||
1637 | |||
1638 | /** |
||
1639 | * @param $name |
||
1640 | * @param bool $optional |
||
1641 | * @return bool |
||
1642 | */ |
||
1643 | public static function getHandler($name, $optional = false) |
||
1644 | { |
||
1645 | global $handlers, $xoopsModule; |
||
1646 | |||
1647 | $name = mb_strtolower(trim($name)); |
||
1648 | if (!isset($handlers[$name])) { |
||
1649 | if (is_file($hnd_file = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/class_' . $name . '.php')) { |
||
1650 | require_once $hnd_file; |
||
1651 | } |
||
1652 | $class = 'xtube' . ucfirst($name) . 'Handler'; |
||
1653 | if (class_exists($class)) { |
||
1654 | $handlers[$name] = new $class($GLOBALS['xoopsDB']); |
||
1655 | } |
||
1656 | } |
||
1657 | if (!isset($handlers[$name]) && !$optional) { |
||
1658 | trigger_error('<div>Class <span style="font-weight: bold;">' . $class . '</span> does not exist.</div><div>Handler Name: ' . $name, E_USER_ERROR) . '</div>'; |
||
1659 | } |
||
1660 | |||
1661 | return $handlers[$name] ?? false; |
||
1662 | } |
||
1663 | |||
1664 | /** |
||
1665 | * @param int $cid |
||
1666 | * @param string $permType |
||
1667 | * @param bool $redirect |
||
1668 | * |
||
1669 | * @return bool |
||
1670 | */ |
||
1671 | public static function checkGroups($cid = 0, $permType = 'XTubeCatPerm', $redirect = false) |
||
1672 | { |
||
1673 | global $xoopsModule; |
||
1674 | |||
1675 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
1676 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
1677 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
1678 | if (!$grouppermHandler->checkRight($permType, $cid, $groups, $xoopsModule->getVar('mid'))) { |
||
1679 | if (false === $redirect) { |
||
1680 | return false; |
||
1681 | } |
||
1682 | redirect_header('index.php', 3, _NOPERM); |
||
1683 | } |
||
1684 | |||
1685 | return true; |
||
1686 | } |
||
1687 | |||
1688 | /** |
||
1689 | * @param int $lid |
||
1690 | * |
||
1691 | * @return bool |
||
1692 | */ |
||
1693 | public static function getVoteDetails($lid = 0) |
||
1694 | { |
||
1695 | $sql = 'SELECT |
||
1696 | COUNT(rating) AS rate, |
||
1697 | MIN(rating) AS min_rate, |
||
1698 | MAX(rating) AS max_rate, |
||
1699 | AVG(rating) AS avg_rate, |
||
1700 | COUNT(ratinguser) AS rating_user, |
||
1701 | MAX(ratinguser) AS max_user, |
||
1702 | MAX(title) AS max_title, |
||
1703 | MIN(title) AS min_title, |
||
1704 | sum(ratinguser = 0) AS null_ratinguser |
||
1705 | FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata'); |
||
1706 | if ($lid > 0) { |
||
1707 | $sql .= ' WHERE lid=' . $lid; |
||
1708 | } |
||
1709 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
1710 | return false; |
||
1711 | } |
||
1712 | $ret = $GLOBALS['xoopsDB']->fetchArray($result); |
||
1713 | |||
1714 | return $ret; |
||
1715 | } |
||
1716 | |||
1717 | /** |
||
1718 | * @param int $sel_id |
||
1719 | * |
||
1720 | * @return array|bool |
||
1721 | */ |
||
1722 | public static function calculateVoteData($sel_id = 0) |
||
1723 | { |
||
1724 | $ret = []; |
||
1725 | $ret['useravgrating'] = 0; |
||
1726 | |||
1727 | $sql = 'SELECT rating FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata'); |
||
1728 | if (0 !== $sel_id) { |
||
1729 | $sql .= ' WHERE lid=' . $sel_id; |
||
1730 | } |
||
1731 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
1732 | return false; |
||
1733 | } |
||
1734 | $ret['uservotes'] = $GLOBALS['xoopsDB']->getRowsNum($result); |
||
1735 | while (list($rating) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
1736 | $ret['useravgrating'] += (int)$rating; |
||
1737 | } |
||
1738 | if ($ret['useravgrating'] > 0) { |
||
1739 | $ret['useravgrating'] = number_format($ret['useravgrating'] / $ret['uservotes'], 2); |
||
1740 | } |
||
1741 | |||
1742 | return $ret; |
||
1743 | } |
||
1744 | |||
1745 | /** |
||
1746 | * @param $array |
||
1747 | * @param null $name |
||
1748 | * @param null $def |
||
1749 | * @param bool $strict |
||
1750 | * @param int $lengthcheck |
||
1751 | * |
||
1752 | * @return array|int|null|string |
||
1753 | */ |
||
1754 | public static function cleanRequestVars( |
||
1755 | &$array, |
||
1756 | $name = null, |
||
1757 | $def = null, |
||
1758 | $strict = false, |
||
1759 | $lengthcheck = 15 |
||
1760 | ) { |
||
1761 | // Sanitise $_request for further use. This method gives more control and security. |
||
1762 | // Method is more for functionality rather than beauty at the moment, will correct later. |
||
1763 | unset($array['usercookie'], $array['PHPSESSID']); |
||
1764 | |||
1765 | if (is_array($array) && null === $name) { |
||
1766 | $globals = []; |
||
1767 | foreach (array_keys($array) as $k) { |
||
1768 | $value = strip_tags(trim($array[$k])); |
||
1769 | if (mb_strlen($value >= $lengthcheck)) { |
||
1770 | return null; |
||
1771 | } |
||
1772 | if (ctype_digit($value)) { |
||
1773 | $value = (int)$value; |
||
1774 | } else { |
||
1775 | if (true === $strict) { |
||
1776 | $value = preg_replace('/\W/', '', trim($value)); |
||
1777 | } |
||
1778 | $value = mb_strtolower((string)$value); |
||
1779 | } |
||
1780 | $globals[$k] = $value; |
||
1781 | } |
||
1782 | |||
1783 | return $globals; |
||
1784 | } |
||
1785 | if (!isset($array[$name]) || !array_key_exists($name, $array)) { |
||
1786 | return $def; |
||
1787 | } |
||
1788 | $value = strip_tags(trim($array[$name])); |
||
1789 | |||
1790 | if (ctype_digit($value)) { |
||
1791 | $value = (int)$value; |
||
1792 | } else { |
||
1793 | if (true === $strict) { |
||
1794 | $value = preg_replace('/\W/', '', trim($value)); |
||
1795 | } |
||
1796 | $value = mb_strtolower((string)$value); |
||
1797 | } |
||
1798 | |||
1799 | return $value; |
||
1800 | } |
||
1801 | |||
1802 | /** |
||
1803 | * @param int $cid |
||
1804 | * |
||
1805 | * @return string |
||
1806 | */ |
||
1807 | public static function renderToolbar($cid = 0) |
||
1808 | { |
||
1809 | $toolbar = '[ '; |
||
1810 | if (true === self::checkGroups($cid, 'XTubeSubPerm')) { |
||
1811 | $toolbar .= '<a href="submit.php?cid=' . $cid . '">' . _MD_XOOPSTUBE_SUBMITVIDEO . '</a> | '; |
||
1812 | } |
||
1813 | $toolbar .= '<a href="newlist.php?newvideoshowdays=7">' . _MD_XOOPSTUBE_LATESTLIST . '</a> | <a href="topten.php?list=hit">' . _MD_XOOPSTUBE_POPULARITY . '</a> | <a href="topten.php?list=rate">' . _MD_XOOPSTUBE_TOPRATED . '</a> ]'; |
||
1814 | |||
1815 | return $toolbar; |
||
1816 | } |
||
1817 | |||
1818 | public static function getServerStatistics() |
||
1819 | { |
||
1820 | global $xoopsModule; |
||
1821 | echo '<fieldset style="border: #E8E8E8 1px solid;"> |
||
1822 | <legend style="display: inline; font-weight: bold; color: #0A3760;">' . _AM_XOOPSTUBE_VIDEO_IMAGEINFO . '</legend> |
||
1823 | <div style="padding: 8px;"> |
||
1824 | <img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/server.png" alt="" style="float: left; padding-right: 10px;"> |
||
1825 | <div>' . _AM_XOOPSTUBE_VIDEO_SPHPINI . '</div>'; |
||
1826 | |||
1827 | // $safemode = ini_get('safe_mode') ? _AM_XOOPSTUBE_VIDEO_ON . _AM_XOOPSTUBE_VIDEO_SAFEMODEPROBLEMS : _AM_XOOPSTUBE_VIDEO_OFF; |
||
1828 | // $registerglobals = (ini_get('register_globals') === '') ? _AM_XOOPSTUBE_VIDEO_OFF : _AM_XOOPSTUBE_VIDEO_ON; |
||
1829 | $videos = ini_get('file_uploads') ? _AM_XOOPSTUBE_VIDEO_ON : _AM_XOOPSTUBE_VIDEO_OFF; |
||
1830 | |||
1831 | $gdlib = function_exists('gd_info') ? _AM_XOOPSTUBE_VIDEO_GDON : _AM_XOOPSTUBE_VIDEO_GDOFF; |
||
1832 | echo '<li>' . _AM_XOOPSTUBE_VIDEO_GDLIBSTATUS . $gdlib; |
||
1833 | if (function_exists('gd_info')) { |
||
1834 | if (true === $gdlib = gd_info()) { |
||
1835 | echo '<li>' . _AM_XOOPSTUBE_VIDEO_GDLIBVERSION . '<b>' . $gdlib['GD Version'] . '</b>'; |
||
1836 | } |
||
1837 | } |
||
1838 | echo '<br><br>'; |
||
1839 | // echo '<li>' . _AM_XOOPSTUBE_VIDEO_SAFEMODESTATUS . $safemode; |
||
1840 | // echo '<li>' . _AM_XOOPSTUBE_VIDEO_REGISTERGLOBALS . $registerglobals; |
||
1841 | echo '<li>' . _AM_XOOPSTUBE_VIDEO_SERVERUPLOADSTATUS . $videos; |
||
1842 | echo '</div>'; |
||
1843 | echo '</fieldset>'; |
||
1844 | } |
||
1845 | |||
1846 | // displayIcons() |
||
1847 | // |
||
1848 | // @param $time |
||
1849 | // @param integer $status |
||
1850 | // @param integer $counter |
||
1851 | // @return |
||
1852 | |||
1853 | /** |
||
1854 | * @param $time |
||
1855 | * @param int $status |
||
1856 | * @param int $counter |
||
1857 | * |
||
1858 | * @return string |
||
1859 | */ |
||
1860 | public static function displayIcons($time, $status = 0, $counter = 0) |
||
1861 | { |
||
1862 | global $xoopsModule; |
||
1863 | |||
1864 | $new = ''; |
||
1865 | $pop = ''; |
||
1866 | |||
1867 | $newdate = (time() - (86400 * (int)$GLOBALS['xoopsModuleConfig']['daysnew'])); |
||
1868 | $popdate = (time() - (86400 * (int)$GLOBALS['xoopsModuleConfig']['daysupdated'])); |
||
1869 | |||
1870 | if (3 != $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1871 | if ($newdate < $time) { |
||
1872 | if ((int)$status > 1) { |
||
1873 | if (1 == $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1874 | $new = ' <img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/updated.gif" alt="" style="vertical-align: middle;">'; |
||
1875 | } |
||
1876 | if (2 == $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1877 | $new = '<em>' . _MD_XOOPSTUBE_UPDATED . '</em>'; |
||
1878 | } |
||
1879 | } else { |
||
1880 | if (1 == $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1881 | $new = ' <img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/new.gif" alt="" style="vertical-align: middle;">'; |
||
1882 | } |
||
1883 | if (2 == $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1884 | $new = '<em>' . _MD_XOOPSTUBE_NEW . '</em>'; |
||
1885 | } |
||
1886 | } |
||
1887 | } |
||
1888 | if ($popdate > $time) { |
||
1889 | if ($counter >= $GLOBALS['xoopsModuleConfig']['popular']) { |
||
1890 | if (1 == $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1891 | $pop = ' <img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon/popular.png" alt="" style="vertical-align: middle;">'; |
||
1892 | } |
||
1893 | if (2 == $GLOBALS['xoopsModuleConfig']['displayicons']) { |
||
1894 | $pop = '<em>' . _MD_XOOPSTUBE_POPULAR . '!</em>'; |
||
1895 | } |
||
1896 | } |
||
1897 | } |
||
1898 | } |
||
1899 | $icons = $new . ' ' . $pop; |
||
1900 | |||
1901 | return $icons; |
||
1902 | } |
||
1903 | |||
1904 | // Reusable Link Sorting Functions |
||
1905 | // convertOrderByIn() |
||
1906 | // @param $orderby |
||
1907 | // @return |
||
1908 | |||
1909 | /** |
||
1910 | * @param $orderby |
||
1911 | * |
||
1912 | * @return string |
||
1913 | */ |
||
1914 | public static function convertOrderByIn($orderby) |
||
1915 | { |
||
1916 | switch (trim($orderby)) { |
||
1917 | case 'titleA': |
||
1918 | $orderby = 'title ASC'; |
||
1919 | break; |
||
1920 | case 'dateA': |
||
1921 | $orderby = 'published ASC'; |
||
1922 | break; |
||
1923 | case 'hitsA': |
||
1924 | $orderby = 'hits ASC'; |
||
1925 | break; |
||
1926 | case 'ratingA': |
||
1927 | $orderby = 'rating ASC'; |
||
1928 | break; |
||
1929 | case 'countryA': |
||
1930 | $orderby = 'country ASC'; |
||
1931 | break; |
||
1932 | case 'titleD': |
||
1933 | $orderby = 'title DESC'; |
||
1934 | break; |
||
1935 | case 'hitsD': |
||
1936 | $orderby = 'hits DESC'; |
||
1937 | break; |
||
1938 | case 'ratingD': |
||
1939 | $orderby = 'rating DESC'; |
||
1940 | break; |
||
1941 | case'dateD': |
||
1942 | $orderby = 'published DESC'; |
||
1943 | break; |
||
1944 | case 'countryD': |
||
1945 | $orderby = 'country DESC'; |
||
1946 | break; |
||
1947 | } |
||
1948 | |||
1949 | return $orderby; |
||
1950 | } |
||
1951 | |||
1952 | /** |
||
1953 | * @param $orderby |
||
1954 | * |
||
1955 | * @return string |
||
1956 | */ |
||
1957 | public static function convertOrderByTrans($orderby) |
||
1958 | { |
||
1959 | switch ($orderby) { |
||
1960 | case 'hits ASC': |
||
1961 | $orderByTrans = _MD_XOOPSTUBE_POPULARITYLTOM; |
||
1962 | break; |
||
1963 | case 'hits DESC': |
||
1964 | $orderByTrans = _MD_XOOPSTUBE_POPULARITYMTOL; |
||
1965 | break; |
||
1966 | case 'title ASC': |
||
1967 | $orderByTrans = _MD_XOOPSTUBE_TITLEATOZ; |
||
1968 | break; |
||
1969 | case 'title DESC': |
||
1970 | $orderByTrans = _MD_XOOPSTUBE_TITLEZTOA; |
||
1971 | break; |
||
1972 | case 'published ASC': |
||
1973 | $orderByTrans = _MD_XOOPSTUBE_DATEOLD; |
||
1974 | break; |
||
1975 | case 'published DESC': |
||
1976 | $orderByTrans = _MD_XOOPSTUBE_DATENEW; |
||
1977 | break; |
||
1978 | case 'rating ASC': |
||
1979 | $orderByTrans = _MD_XOOPSTUBE_RATINGLTOH; |
||
1980 | break; |
||
1981 | case 'rating DESC': |
||
1982 | $orderByTrans = _MD_XOOPSTUBE_RATINGHTOL; |
||
1983 | break; |
||
1984 | case'country ASC': |
||
1985 | $orderByTrans = _MD_XOOPSTUBE_COUNTRYLTOH; |
||
1986 | break; |
||
1987 | case 'country DESC': |
||
1988 | $orderByTrans = _MD_XOOPSTUBE_COUNTRYHTOL; |
||
1989 | break; |
||
1990 | } |
||
1991 | |||
1992 | return $orderByTrans; |
||
1993 | } |
||
1994 | |||
1995 | /** |
||
1996 | * @param $orderby |
||
1997 | * |
||
1998 | * @return string |
||
1999 | */ |
||
2000 | public static function convertOrderByOut($orderby) |
||
2001 | { |
||
2037 | |||
2038 | // updaterating() |
||
2039 | // @param $sel_id |
||
2040 | // @return updates rating data in itemtable for a given item |
||
2041 | |||
2042 | /** |
||
2043 | * @param $sel_id |
||
2044 | */ |
||
2045 | public static function updateRating($sel_id) |
||
2046 | { |
||
2047 | $query = 'SELECT rating FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_votedata') . ' WHERE lid=' . $sel_id; |
||
2048 | $voteresult = $GLOBALS['xoopsDB']->query($query); |
||
2049 | $votesDB = $GLOBALS['xoopsDB']->getRowsNum($voteresult); |
||
2050 | $totalrating = 0; |
||
2051 | while (list($rating) = $GLOBALS['xoopsDB']->fetchRow($voteresult)) { |
||
2052 | $totalrating += $rating; |
||
2053 | } |
||
2054 | $finalrating = $totalrating / $votesDB; |
||
2055 | $finalrating = number_format($finalrating, 4); |
||
2056 | $sql = sprintf('UPDATE `%s` SET rating = %u, votes = %u WHERE lid = %u', $GLOBALS['xoopsDB']->prefix('xoopstube_videos'), $finalrating, $votesDB, $sel_id); |
||
2057 | $GLOBALS['xoopsDB']->query($sql); |
||
2058 | } |
||
2059 | |||
2060 | // totalcategory() |
||
2061 | // @param integer $pid |
||
2062 | // @return |
||
2063 | |||
2064 | /** |
||
2065 | * @param int $pid |
||
2066 | * |
||
2067 | * @return int |
||
2068 | */ |
||
2069 | public static function getTotalCategoryCount($pid = 0) |
||
2070 | { |
||
2071 | $sql = 'SELECT cid FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat'); |
||
2072 | if ($pid > 0) { |
||
2073 | $sql .= ' WHERE pid = 0'; |
||
2074 | } |
||
2075 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
2076 | $catlisting = 0; |
||
2077 | while (list($cid) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
2078 | if (self::checkGroups($cid)) { |
||
2079 | ++$catlisting; |
||
2080 | } |
||
2081 | } |
||
2082 | |||
2083 | return $catlisting; |
||
2084 | } |
||
2085 | |||
2086 | // getTotalItems() |
||
2087 | // @param integer $sel_id |
||
2088 | // @param integer $get_child |
||
2089 | // @param integer $return_sql |
||
2090 | // @return |
||
2091 | |||
2092 | /** |
||
2093 | * @param int $sel_id |
||
2094 | * @param int $get_child |
||
2095 | * @param int $return_sql |
||
2096 | * |
||
2097 | * @return string |
||
2098 | */ |
||
2099 | public static function getTotalItems($sel_id = 0, $get_child = 0, $return_sql = 0) |
||
2100 | { |
||
2101 | global $mytree, $_check_array; |
||
2102 | |||
2103 | if ($sel_id > 0) { |
||
2104 | $sql = 'SELECT a.lid, a.cid, a.published FROM ' |
||
2105 | . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') |
||
2106 | . ' a LEFT JOIN ' |
||
2107 | . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') |
||
2108 | . ' b' |
||
2109 | . ' ON b.lid=a.lid' |
||
2110 | . ' WHERE a.published > 0 AND a.published <= ' |
||
2111 | . time() |
||
2112 | . ' AND (a.expired = 0 OR a.expired > ' |
||
2113 | . time() |
||
2114 | . ') AND offline = 0 ' |
||
2115 | . ' AND (b.cid=a.cid OR (a.cid=' |
||
2116 | . $sel_id |
||
2117 | . ' OR b.cid=' |
||
2118 | . $sel_id |
||
2119 | . '))' |
||
2120 | . ' GROUP BY a.lid, a.cid, a.published'; |
||
2121 | } else { |
||
2122 | $sql = 'SELECT lid, cid, published FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE offline = 0 AND published > 0 AND published <= ' . time() . ' AND (expired = 0 OR expired > ' . time() . ')'; |
||
2123 | } |
||
2124 | if (1 == $return_sql) { |
||
2125 | return $sql; |
||
2126 | } |
||
2127 | |||
2128 | $count = 0; |
||
2129 | $published_date = 0; |
||
2130 | |||
2131 | $arr = []; |
||
2132 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
2133 | while (list($lid, $cid, $published) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
2134 | if (true === self::checkGroups()) { |
||
2135 | ++$count; |
||
2136 | $published_date = ($published > $published_date) ? $published : $published_date; |
||
2137 | } |
||
2138 | } |
||
2139 | |||
2140 | $child_count = 0; |
||
2141 | if (1 == $get_child) { |
||
2142 | $arr = $mytree->getAllChildId($sel_id); |
||
2143 | $size = count($arr); |
||
2144 | foreach ($arr as $iValue) { |
||
2145 | $query2 = 'SELECT a.lid, a.published, a.cid FROM ' |
||
2146 | . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') |
||
2147 | . ' a LEFT JOIN ' |
||
2148 | . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') |
||
2149 | . ' b' |
||
2150 | . ' ON b.lid = a.lid' |
||
2151 | . ' WHERE a.published > 0 AND a.published <= ' |
||
2152 | . time() |
||
2153 | . ' AND (a.expired = 0 OR a.expired > ' |
||
2154 | . time() |
||
2155 | . ') AND offline = 0' |
||
2156 | . ' AND (b.cid=a.cid OR (a.cid=' |
||
2157 | . $iValue |
||
2158 | . ' OR b.cid=' |
||
2159 | . $iValue |
||
2160 | . ')) GROUP BY a.lid, a.published, a.cid'; |
||
2161 | |||
2162 | $result2 = $GLOBALS['xoopsDB']->query($query2); |
||
2163 | while (list($lid, $published) = $GLOBALS['xoopsDB']->fetchRow($result2)) { |
||
2164 | if (0 == $published) { |
||
2165 | continue; |
||
2166 | } |
||
2167 | $published_date = ($published > $published_date) ? $published : $published_date; |
||
2168 | ++$child_count; |
||
2169 | } |
||
2170 | } |
||
2171 | } |
||
2172 | $info['count'] = $count + $child_count; |
||
2173 | $info['published'] = $published_date; |
||
2174 | |||
2175 | return $info; |
||
2176 | } |
||
2177 | |||
2178 | /** |
||
2179 | * @param string $indeximage |
||
2180 | * @param string $indexheading |
||
2181 | * |
||
2182 | * @return string |
||
2183 | */ |
||
2184 | public static function renderImageHeader($indeximage = '', $indexheading = '') |
||
2185 | { |
||
2186 | if ('' === $indeximage) { |
||
2187 | $result = $GLOBALS['xoopsDB']->query('SELECT indeximage, indexheading FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_indexpage')); |
||
2188 | [$indeximage, $indexheading] = $GLOBALS['xoopsDB']->fetchrow($result); |
||
2189 | } |
||
2190 | |||
2191 | $image = ''; |
||
2192 | if (!empty($indeximage)) { |
||
2193 | $image = self::displayImage($indeximage, 'index.php', $GLOBALS['xoopsModuleConfig']['mainimagedir'], $indexheading); |
||
2194 | } |
||
2195 | |||
2196 | return $image; |
||
2197 | } |
||
2198 | |||
2199 | /** |
||
2200 | * @param string $image |
||
2201 | * @param string $path |
||
2202 | * @param string $imgsource |
||
2203 | * @param string $alttext |
||
2204 | * |
||
2205 | * @return string |
||
2206 | */ |
||
2207 | public static function displayImage($image = '', $path = '', $imgsource = '', $alttext = '') |
||
2208 | { |
||
2209 | global $xoopsModule; |
||
2210 | |||
2211 | $showimage = ''; |
||
2212 | // Check to see if link is given |
||
2213 | if ($path) { |
||
2214 | $showimage = '<a href="' . $path . '">'; |
||
2215 | } |
||
2216 | // checks to see if the file is valid else displays default blank image |
||
2217 | if (is_file(XOOPS_ROOT_PATH . "/{$imgsource}/{$image}")// && is_dir(XOOPS_ROOT_PATH . "/{$imgsource}/{$image}") |
||
2218 | ) { |
||
2219 | $showimage .= "<img src='" . XOOPS_URL . "/{$imgsource}/{$image}' border='0' title='" . $alttext . "' alt='" . $alttext . "'></a>"; |
||
2220 | } elseif ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->isAdmin($xoopsModule->getVar('mid'))) { |
||
2221 | $showimage .= '<img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/brokenimg.png" alt="' . _MD_XOOPSTUBE_ISADMINNOTICE . '"></a>'; |
||
2222 | } else { |
||
2223 | $showimage .= '<img src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/assets/images/blank.png" alt="' . $alttext . '"></a>'; |
||
2224 | } |
||
2225 | clearstatcache(); |
||
2226 | |||
2227 | return $showimage; |
||
2228 | } |
||
2229 | |||
2230 | /** |
||
2231 | * @param $published |
||
2232 | * |
||
2233 | * @return mixed |
||
2234 | */ |
||
2235 | public static function isNewImage($published) |
||
2236 | { |
||
2237 | global $xoopsModule; |
||
2238 | |||
2239 | $oneday = (time() - (86400 * 1)); |
||
2240 | $threedays = (time() - (86400 * 3)); |
||
2241 | $week = (time() - (86400 * 7)); |
||
2242 | |||
2243 | $path = 'modules/' . $xoopsModule->getVar('dirname') . '/assets/images/icon'; |
||
2244 | |||
2245 | if ($published > 0 && $published < $week) { |
||
2246 | $indicator['image'] = "$path/linkload4.png"; |
||
2247 | $indicator['alttext'] = _MD_XOOPSTUBE_NEWLAST; |
||
2248 | } elseif ($published >= $week && $published < $threedays) { |
||
2249 | $indicator['image'] = "$path/linkload3.png"; |
||
2250 | $indicator['alttext'] = _MD_XOOPSTUBE_NEWTHIS; |
||
2251 | } elseif ($published >= $threedays && $published < $oneday) { |
||
2252 | $indicator['image'] = "$path/linkload2.png"; |
||
2253 | $indicator['alttext'] = _MD_XOOPSTUBE_THREE; |
||
2254 | } elseif ($published >= $oneday) { |
||
2255 | $indicator['image'] = "$path/linkload1.png"; |
||
2256 | $indicator['alttext'] = _MD_XOOPSTUBE_TODAY; |
||
2257 | } else { |
||
2258 | $indicator['image'] = "$path/linkload.png"; |
||
2259 | $indicator['alttext'] = _MD_XOOPSTUBE_NO_FILES; |
||
2260 | } |
||
2261 | |||
2262 | return $indicator; |
||
2263 | } |
||
2264 | |||
2265 | /** |
||
2266 | * @param $haystack |
||
2267 | * @param $needle |
||
2268 | * |
||
2269 | * @return string |
||
2270 | */ |
||
2271 | public static function findStringChar($haystack, $needle) |
||
2272 | { |
||
2273 | return mb_substr($haystack, 0, mb_strpos($haystack, $needle) + 1); |
||
2274 | } |
||
2275 | |||
2276 | /** |
||
2277 | * @param string $header |
||
2278 | * @param string $menu |
||
2279 | * @param string $extra |
||
2280 | * @param int $scount |
||
2281 | * |
||
2282 | * @return bool|null |
||
2283 | */ |
||
2284 | public static function renderAdminMenu($header = '', $menu = '', $extra = '', $scount = 4) |
||
2285 | { |
||
2498 | |||
2499 | /** |
||
2500 | * @param $selected |
||
2501 | * @param $dirarray |
||
2502 | * @param $namearray |
||
2503 | */ |
||
2504 | public static function getDirSelectOption($selected, $dirarray, $namearray) |
||
2505 | { |
||
2506 | echo "<select size='1' name='workd' onchange='location.href=\"upload.php?rootpath=\"+this.options[this.selectedIndex].value'>"; |
||
2507 | echo "<option value=''>--------------------------------------</option>"; |
||
2508 | foreach ($namearray as $namearray => $workd) { |
||
2509 | $opt_selected = ''; |
||
2510 | if ($workd == $selected) { |
||
2511 | $opt_selected = 'selected'; |
||
2512 | } |
||
2513 | echo '<option value="' . htmlspecialchars($namearray, ENT_QUOTES) . '" $opt_selected>' . $workd . '</option>'; |
||
2514 | } |
||
2515 | echo '</select>'; |
||
2516 | } |
||
2517 | |||
2518 | // /** |
||
2519 | // * @param $selected |
||
2520 | // * @param $dirarray |
||
2521 | // * @param $namearray |
||
2522 | // */ |
||
2523 | // public static function getDirSelectOption($selected, $dirarray, $namearray) |
||
2524 | // { |
||
2525 | // echo "<select size='1' name='workd' onchange='location.href=\"vupload.php?rootpath=\"+this.options[this.selectedIndex].value'>"; |
||
2526 | // echo "<option value=''>--------------------------------------</option>"; |
||
2527 | // foreach ($namearray as $namearray => $workd) { |
||
2528 | // $opt_selected = ''; |
||
2529 | // if ($workd == $selected) { |
||
2530 | // $opt_selected = 'selected'; |
||
2531 | // } |
||
2532 | // echo '<option value="' . htmlspecialchars($namearray, ENT_QUOTES) . '" $opt_selected>' . $workd . '</option>'; |
||
2533 | // } |
||
2534 | // echo '</select>'; |
||
2535 | // } |
||
2536 | |||
2537 | /** |
||
2538 | * @param $FILES |
||
2539 | * @param string $uploaddir |
||
2540 | * @param string $allowed_mimetypes |
||
2541 | * @param string $redirecturl |
||
2542 | * @param int $redirect |
||
2543 | * @param int $usertype |
||
2544 | * |
||
2545 | * @return array|null |
||
2546 | */ |
||
2547 | public static function uploadFiles( |
||
2548 | $FILES, |
||
2549 | $uploaddir = 'uploads', |
||
2550 | $allowed_mimetypes = '', |
||
2551 | $redirecturl = 'index.php', // $num = 0, |
||
2552 | $redirect = 0, |
||
2553 | $usertype = 1 |
||
2554 | ) { |
||
2555 | global $FILES, $xoopsModule; |
||
2556 | |||
2557 | $down = []; |
||
2558 | // require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/uploader.php'; |
||
2559 | // require_once __DIR__ . '/uploader.php'; |
||
2560 | // require XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
2561 | |||
2562 | if (empty($allowed_mimetypes)) { |
||
2563 | $allowed_mimetypes = xtube_getmime($FILES['userfile']['name'], $usertype); |
||
2564 | } |
||
2565 | $upload_dir = XOOPS_ROOT_PATH . '/' . $uploaddir . '/'; |
||
2566 | |||
2567 | $maxfilesize = $GLOBALS['xoopsModuleConfig']['maxfilesize']; |
||
2568 | |||
2569 | $maxfilewidth = $GLOBALS['xoopsModuleConfig']['maximgwidth']; |
||
2570 | $maxfileheight = $GLOBALS['xoopsModuleConfig']['maximgheight']; |
||
2571 | |||
2572 | $uploader = new Xoopstube\MediaUploader($upload_dir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight); |
||
2573 | $uploader->noAdminSizeCheck(1); |
||
2574 | //if ($uploader->fetchMedia(Request::getArray('xoops_upload_file[0]', array(), 'POST'))) { |
||
2575 | if ($uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0])) { |
||
2576 | if (!$uploader->upload()) { |
||
2577 | $errors = $uploader->getErrors(); |
||
2578 | redirect_header($redirecturl, 2, $errors); |
||
2579 | } elseif ($redirect) { |
||
2580 | redirect_header($redirecturl, 1, _AM_XOOPSTUBE_UPLOADFILE); |
||
2581 | } else { |
||
2582 | if (is_file($uploader->savedDestination)) { |
||
2583 | $down['url'] = XOOPS_URL . '/' . $uploaddir . '/' . mb_strtolower($uploader->savedFileName); |
||
2584 | $down['size'] = filesize(XOOPS_ROOT_PATH . '/' . $uploaddir . '/' . mb_strtolower($uploader->savedFileName)); |
||
2585 | } |
||
2586 | |||
2587 | return $down; |
||
2588 | } |
||
2589 | } else { |
||
2590 | $errors = $uploader->getErrors(); |
||
2591 | redirect_header($redirecturl, 1, $errors); |
||
2592 | } |
||
2593 | |||
2594 | return null; |
||
2595 | } |
||
2596 | |||
2597 | /** |
||
2598 | * @param $heading |
||
2599 | */ |
||
2600 | public static function renderCategoryListHeader($heading) |
||
2601 | { |
||
2602 | echo ' |
||
2603 | <h4 style="font-weight: bold; color: #0A3760;">' . $heading . '</h4> |
||
2604 | <table width="100%" cellspacing="1" class="outer" summary> |
||
2605 | <tr> |
||
2606 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_ID . '</th> |
||
2607 | <th style=" font-size: smaller;"><b>' . _AM_XOOPSTUBE_FCATEGORY_TITLE . '</th> |
||
2608 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_FCATEGORY_WEIGHT . '</th> |
||
2609 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_FCATEGORY_CIMAGE . '</th> |
||
2610 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_CATSPONSOR . '</th> |
||
2611 | <!-- <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_PUBLISH . '</th> |
||
2612 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_EXPIRE . '</th> |
||
2613 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_ONLINE . '</th> |
||
2614 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_ACTION . '</th> --> |
||
2615 | </tr> |
||
2616 | '; |
||
2617 | } |
||
2618 | |||
2619 | /** |
||
2620 | * @param $published |
||
2621 | */ |
||
2622 | public static function renderCategoryListBody($published) |
||
2623 | { |
||
2624 | global $xtubemyts, $xtubeImageArray; |
||
2625 | |||
2626 | $lid = $published['lid']; |
||
2627 | $cid = $published['cid']; |
||
2628 | |||
2629 | $title = '<a href="../singlevideo.php?cid=' . $published['cid'] . '&lid=' . $published['lid'] . '">' . htmlspecialcharsStrip(trim($published['title'])) . '</a>'; |
||
2630 | $maintitle = urlencode(htmlspecialchars(trim($published['title']))); |
||
2631 | $cattitle = '<a href="../viewcat.php?cid=' . $published['cid'] . '">' . self::getCategoryTitle($published['cid']) . '</a>'; |
||
2632 | $submitter = self::getLinkedUserNameFromId($published['submitter']); |
||
2633 | $returnsource = xtubeReturnSource($published['vidsource']); |
||
2634 | $submitted = self::getTimestamp(formatTimestamp($published['date'], $GLOBALS['xoopsModuleConfig']['dateformatadmin'])); |
||
2635 | $publish = ($published['published'] > 0) ? self::getTimestamp(formatTimestamp($published['published'], $GLOBALS['xoopsModuleConfig']['dateformatadmin'])) : 'Not Published'; |
||
2636 | $expires = $published['expired'] ? self::getTimestamp(formatTimestamp($published['expired'], $GLOBALS['xoopsModuleConfig']['dateformatadmin'])) : _AM_XOOPSTUBE_MINDEX_NOTSET; |
||
2637 | |||
2638 | if ((($published['expired'] && $published['expired'] > time()) || 0 == $published['expired']) |
||
2639 | && ($published['published'] && $published['published'] < time()) |
||
2640 | && 0 == $published['offline']) { |
||
2641 | $published_status = $xtubeImageArray['online']; |
||
2642 | } elseif (($published['expired'] && $published['expired'] < time()) && 0 == $published['offline']) { |
||
2643 | $published_status = $xtubeImageArray['expired']; |
||
2644 | } else { |
||
2645 | $published_status = (0 == $published['published']) ? '<a href="newvideos.php">' . $xtubeImageArray['offline'] . '</a>' : $xtubeImageArray['offline']; |
||
2646 | } |
||
2647 | |||
2648 | if (200 == $published['vidsource']) { |
||
2649 | $icon = '<a href="main.php?op=edit&lid=' . $lid . '" title="' . _AM_XOOPSTUBE_ICO_EDIT . '">' . $xtubeImageArray['editimg'] . '</a> '; |
||
2650 | } else { |
||
2651 | $icon = '<a href="main.php?op=edit&lid=' . $lid . '" title="' . _AM_XOOPSTUBE_ICO_EDIT . '">' . $xtubeImageArray['editimg'] . '</a> '; |
||
2652 | } |
||
2653 | $icon .= '<a href="main.php?op=delete&lid=' . $lid . '" title="' . _AM_XOOPSTUBE_ICO_DELETE . '">' . $xtubeImageArray['deleteimg'] . '</a> '; |
||
2654 | $icon .= '<a href="altcat.php?op=main&cid=' . $cid . '&lid=' . $lid . '&title=' . $published['title'] . '" title="' . _AM_XOOPSTUBE_ALTCAT_CREATEF . '">' . $xtubeImageArray['altcat'] . '</a>'; |
||
2655 | |||
2656 | echo ' |
||
2657 | <tr style="text-align: center; font-size: smaller;"> |
||
2658 | <td class="head">' . $lid . '</span></td> |
||
2659 | <td class="even" style="text-align: left;">' . $title . '</td> |
||
2660 | <td class="even">' . $returnsource . '</td> |
||
2661 | <td class="even">' . $cattitle . '</td> |
||
2662 | <td class="even">' . $submitter . '</td> |
||
2663 | <td class="even">' . $publish . '</td> |
||
2664 | <td class="even">' . $expires . '</td> |
||
2665 | <td class="even" style="width: 4%;">' . $published_status . '</td> |
||
2666 | <td class="even" style="text-align: center; width: 6%; white-space: nowrap;">' . $icon . '</td> |
||
2667 | </tr>'; |
||
2668 | // unset($published); |
||
2669 | } |
||
2670 | |||
2671 | /** |
||
2672 | * @param $pubrowamount |
||
2673 | * @param $start |
||
2674 | * @param string $art |
||
2675 | * @param string $_this |
||
2676 | * @param $align |
||
2677 | * |
||
2678 | * @return bool|null |
||
2679 | */ |
||
2680 | public static function setPageNavigationCategoryList( |
||
2681 | $pubrowamount, |
||
2682 | $start, |
||
2683 | $art, |
||
2684 | $_this, |
||
2685 | $align |
||
2686 | ) { |
||
2687 | if ($pubrowamount < $GLOBALS['xoopsModuleConfig']['admin_perpage']) { |
||
2688 | return false; |
||
2689 | } |
||
2690 | // Display Page Nav if published is > total display pages amount. |
||
2691 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
2692 | $pagenav = new XoopsPageNav($pubrowamount, $GLOBALS['xoopsModuleConfig']['admin_perpage'], $start, 'st' . $art, $_this); |
||
2693 | echo '<div style="text-align: ' . $align . '; padding: 8px;">' . $pagenav->renderNav() . '</div>'; |
||
2694 | |||
2695 | return null; |
||
2696 | } |
||
2697 | |||
2698 | public static function renderCategoryListFooter() |
||
2699 | { |
||
2700 | echo '<tr style="text-align: center;"> |
||
2701 | <td class="head" colspan="7">' . _AM_XOOPSTUBE_MINDEX_NOVIDEOSFOUND . '</td> |
||
2702 | </tr>'; |
||
2703 | } |
||
2704 | |||
2705 | /** |
||
2706 | * @param $heading |
||
2707 | */ |
||
2708 | public static function renderVideoListHeader($heading) |
||
2709 | { |
||
2710 | echo ' |
||
2711 | <h4 style="font-weight: bold; color: #0A3760;">' . $heading . '</h4> |
||
2712 | <table width="100%" cellspacing="1" class="outer" summary> |
||
2713 | <tr> |
||
2714 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_ID . '</th> |
||
2715 | <th style=" font-size: smaller;"><b>' . _AM_XOOPSTUBE_MINDEX_TITLE . '</th> |
||
2716 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_VIDSOURCE2 . '</th> |
||
2717 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_CATTITLE . '</th> |
||
2718 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_POSTER . '</th> |
||
2719 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_PUBLISH . '</th> |
||
2720 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_EXPIRE . '</th> |
||
2721 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_ONLINE . '</th> |
||
2722 | <th style="text-align: center; font-size: smaller;">' . _AM_XOOPSTUBE_MINDEX_ACTION . '</th> |
||
2723 | </tr> |
||
2724 | '; |
||
2725 | } |
||
2726 | |||
2727 | /** |
||
2728 | * @param $published |
||
2729 | */ |
||
2730 | public static function renderVideoListBody($published) |
||
2731 | { |
||
2732 | global $xtubemyts, $xtubeImageArray, $pathIcon16; |
||
2733 | |||
2734 | $lid = $published['lid']; |
||
2735 | $cid = $published['cid']; |
||
2736 | |||
2737 | $title = '<a href="../singlevideo.php?cid=' . $published['cid'] . '&lid=' . $published['lid'] . '">' . htmlspecialchars(trim($published['title'])) . '</a>'; |
||
2738 | $maintitle = urlencode(htmlspecialchars(trim($published['title']))); |
||
2739 | $cattitle = '<a href="../viewcat.php?cid=' . $published['cid'] . '">' . self::getCategoryTitle($published['cid']) . '</a>'; |
||
2740 | $submitter = self::getLinkedUserNameFromId($published['submitter']); |
||
2741 | $returnsource = xtubeReturnSource($published['vidsource']); |
||
2742 | $submitted = self::getTimestamp(formatTimestamp($published['date'], $GLOBALS['xoopsModuleConfig']['dateformatadmin'])); |
||
2743 | $publish = ($published['published'] > 0) ? self::getTimestamp(formatTimestamp($published['published'], $GLOBALS['xoopsModuleConfig']['dateformatadmin'])) : 'Not Published'; |
||
2744 | $expires = $published['expired'] ? self::getTimestamp(formatTimestamp($published['expired'], $GLOBALS['xoopsModuleConfig']['dateformatadmin'])) : _AM_XOOPSTUBE_MINDEX_NOTSET; |
||
2745 | |||
2746 | if ((($published['expired'] && $published['expired'] > time()) || 0 === $published['expired']) |
||
2747 | && ($published['published'] && $published['published'] < time()) |
||
2748 | && 0 === $published['offline']) { |
||
2749 | // $published_status = $xtubeImageArray['online']; |
||
2750 | $published_status = '<a href="main.php?op=toggle&lid=' . $lid . '&offline=' . $published['offline'] . '"><img src="' . $pathIcon16 . '/1.png' . '"></a>'; |
||
2751 | } elseif (($published['expired'] && $published['expired'] < time()) && 0 === $published['offline']) { |
||
2752 | $published_status = $xtubeImageArray['expired']; |
||
2753 | } else { |
||
2754 | $published_status = (0 === $published['published']) ? '<a href="newvideos.php">' . $xtubeImageArray['offline'] . '</a>' : '<a href="main.php?op=toggle&lid=' . $lid . '&offline=' . $published['offline'] . '"><img src="' . $pathIcon16 . '/0.png' . '"></a>'; |
||
2755 | } |
||
2756 | |||
2757 | if (200 == $published['vidsource']) { |
||
2758 | $icon = '<a href="main.php?op=edit&lid=' . $lid . '" title="' . _AM_XOOPSTUBE_ICO_EDIT . '">' . $xtubeImageArray['editimg'] . '</a> '; |
||
2759 | } else { |
||
2760 | $icon = '<a href="main.php?op=edit&lid=' . $lid . '" title="' . _AM_XOOPSTUBE_ICO_EDIT . '">' . $xtubeImageArray['editimg'] . '</a> '; |
||
2761 | } |
||
2762 | $icon .= '<a href="main.php?op=delete&lid=' . $lid . '" title="' . _AM_XOOPSTUBE_ICO_DELETE . '">' . $xtubeImageArray['deleteimg'] . '</a> '; |
||
2763 | $icon .= '<a href="altcat.php?op=main&cid=' . $cid . '&lid=' . $lid . '&title=' . $published['title'] . '" title="' . _AM_XOOPSTUBE_ALTCAT_CREATEF . '">' . $xtubeImageArray['altcat'] . '</a>'; |
||
2764 | |||
2765 | echo ' |
||
2766 | <tr style="text-align: center; font-size: smaller;"> |
||
2767 | <td class="head">' . $lid . '</span></td> |
||
2768 | <td class="even" style="text-align: left;">' . $title . '</td> |
||
2769 | <td class="even">' . $returnsource . '</td> |
||
2770 | <td class="even">' . $cattitle . '</td> |
||
2771 | <td class="even">' . $submitter . '</td> |
||
2772 | <td class="even">' . $publish . '</td> |
||
2773 | <td class="even">' . $expires . '</td> |
||
2774 | <td class="even" style="width: 4%;">' . $published_status . '</td> |
||
2775 | <td class="even" style="text-align: center; width: 6%; white-space: nowrap;">' . $icon . '</td> |
||
2776 | </tr>'; |
||
2777 | // unset($published); |
||
2778 | } |
||
2779 | |||
2780 | /** |
||
2781 | * @param $catt |
||
2782 | * |
||
2783 | * @return mixed |
||
2784 | */ |
||
2785 | public static function getCategoryTitle($catt) |
||
2786 | { |
||
2787 | $sql = 'SELECT title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat') . ' WHERE cid=' . $catt; |
||
2788 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
2789 | $result = $GLOBALS['xoopsDB']->fetchArray($result); |
||
2790 | |||
2791 | return $result['title']; |
||
2792 | } |
||
2793 | |||
2794 | public static function renderVideoListFooter() |
||
2795 | { |
||
2796 | echo '<tr style="text-align: center;"> |
||
2797 | <td class="head" colspan="7">' . _AM_XOOPSTUBE_MINDEX_NOVIDEOSFOUND . '</td> |
||
2798 | </tr>'; |
||
2799 | } |
||
2800 | |||
2801 | /** |
||
2802 | * @param $pubrowamount |
||
2803 | * @param $start |
||
2804 | * @param string $art |
||
2805 | * @param string $_this |
||
2806 | * @param $align |
||
2807 | * |
||
2808 | * @return bool|null |
||
2809 | */ |
||
2810 | public static function setPageNavigationVideoList($pubrowamount, $start, $art, $_this, $align) |
||
2811 | { |
||
2812 | if ($pubrowamount < $GLOBALS['xoopsModuleConfig']['admin_perpage']) { |
||
2813 | return false; |
||
2814 | } |
||
2815 | // Display Page Nav if published is > total display pages amount. |
||
2816 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
2817 | $pagenav = new XoopsPageNav($pubrowamount, $GLOBALS['xoopsModuleConfig']['admin_perpage'], $start, 'st' . $art, $_this); |
||
2818 | echo '<div style="text-align: ' . $align . '; padding: 8px;">' . $pagenav->renderNav() . '</div>'; |
||
2819 | |||
2820 | return null; |
||
2821 | } |
||
2822 | |||
2823 | /** |
||
2824 | * @param $document |
||
2825 | * |
||
2826 | * @return mixed |
||
2827 | */ |
||
2828 | public static function convertHtml2text($document) |
||
2829 | { |
||
2830 | // PHP Manual:: function preg_replace |
||
2831 | // $document should contain an HTML document. |
||
2832 | // This will remove HTML tags, javascript sections |
||
2833 | // and white space. It will also convert some |
||
2834 | // common HTML entities to their text equivalent. |
||
2835 | // Credits : newbb2 |
||
2836 | $search = [ |
||
2837 | "'<script[^>]*?>.*?</script>'si", // Strip out javascript |
||
2838 | "'<img.*?>'si", // Strip out img tags |
||
2839 | "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
||
2840 | "'([\r\n])[\s]+'", // Strip out white space |
||
2841 | "'&(quot|#34);'i", // Replace HTML entities |
||
2842 | "'&(amp|#38);'i", |
||
2843 | "'&(lt|#60);'i", |
||
2844 | "'&(gt|#62);'i", |
||
2845 | "'&(nbsp|#160);'i", |
||
2846 | "'&(iexcl|#161);'i", |
||
2847 | "'&(cent|#162);'i", |
||
2848 | "'&(pound|#163);'i", |
||
2849 | "'&(copy|#169);'i", |
||
2850 | ]; // evaluate as php |
||
2851 | |||
2852 | $replace = [ |
||
2853 | '', |
||
2854 | '', |
||
2855 | '', |
||
2856 | '\\1', |
||
2857 | '"', |
||
2858 | '&', |
||
2859 | '<', |
||
2860 | '>', |
||
2861 | ' ', |
||
2862 | chr(161), |
||
2863 | chr(162), |
||
2864 | chr(163), |
||
2865 | chr(169), |
||
2866 | ]; |
||
2867 | |||
2868 | $text = preg_replace($search, $replace, $document); |
||
2869 | |||
2870 | preg_replace_callback( |
||
2871 | '/&#(\d+);/', |
||
2872 | static function ($matches) { |
||
2873 | return chr($matches[1]); |
||
2874 | }, |
||
2875 | $document |
||
2876 | ); |
||
2877 | |||
2878 | return $text; |
||
2879 | } |
||
2880 | |||
2881 | // Check if Tag module is installed |
||
2882 | |||
2883 | /** |
||
2884 | * @return bool |
||
2885 | */ |
||
2886 | public static function isModuleTagInstalled() |
||
2887 | { |
||
2888 | static $isModuleTagInstalled; |
||
2889 | if (!isset($isModuleTagInstalled)) { |
||
2890 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
2891 | $moduleHandler = xoops_getHandler('module'); |
||
2892 | $tag_mod = $moduleHandler->getByDirname('tag'); |
||
2893 | if (!$tag_mod) { |
||
2894 | $tag_mod = false; |
||
2895 | } else { |
||
2896 | $isModuleTagInstalled = 1 == $tag_mod->getVar('isactive'); |
||
2897 | } |
||
2898 | } |
||
2899 | |||
2900 | return $isModuleTagInstalled; |
||
2901 | } |
||
2902 | |||
2903 | // Add item_tag to Tag-module |
||
2904 | |||
2905 | /** |
||
2906 | * @param $lid |
||
2907 | * @param $item_tag |
||
2908 | */ |
||
2909 | public static function updateTag($lid, $item_tag) |
||
2910 | { |
||
2911 | global $xoopsModule; |
||
2912 | if (self::isModuleTagInstalled()) { |
||
2913 | require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php'; |
||
2914 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag'); |
||
2915 | $tagHandler->updateByItem($item_tag, $lid, $xoopsModule->getVar('dirname'), 0); |
||
2916 | } |
||
2917 | } |
||
2918 | |||
2919 | /** |
||
2920 | * @param $lid |
||
2921 | */ |
||
2922 | public static function updateCounter($lid) |
||
2923 | { |
||
2924 | $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' SET hits=hits+1 WHERE lid=' . (int)$lid; |
||
2925 | $result = $GLOBALS['xoopsDB']->queryF($sql); |
||
2926 | } |
||
2927 | |||
2928 | /** |
||
2929 | * @param $banner_id |
||
2930 | * |
||
2931 | * @return null|string |
||
2932 | */ |
||
2933 | public static function getBannerFromBannerId($banner_id) |
||
2934 | { |
||
2935 | ###### Hack by www.stefanosilvestrini.com ###### |
||
2936 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
2937 | $bresult = $db->query('SELECT COUNT(*) FROM ' . $db->prefix('banner') . ' WHERE bid=' . $banner_id); |
||
2938 | [$numrows] = $db->fetchRow($bresult); |
||
2939 | if ($numrows > 1) { |
||
2940 | --$numrows; |
||
2941 | $bannum = mt_rand(0, $numrows); |
||
2942 | } else { |
||
2943 | $bannum = 0; |
||
2944 | } |
||
2945 | if ($numrows > 0) { |
||
2946 | $bresult = $db->query('SELECT * FROM ' . $db->prefix('banner') . ' WHERE bid=' . $banner_id, 1, $bannum); |
||
2947 | [$bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode] = $db->fetchRow($bresult); |
||
2948 | if ($GLOBALS['xoopsConfig']['my_ip'] == xoops_getenv('REMOTE_ADDR')) { |
||
2949 | // EMPTY |
||
2950 | } else { |
||
2951 | $db->queryF(sprintf('UPDATE `%s` SET impmade = impmade+1 WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
2952 | } |
||
2953 | /* Check if this impression is the last one and print the banner */ |
||
2954 | if ($imptotal == $impmade) { |
||
2955 | $newid = $db->genId($db->prefix('bannerfinish') . '_bid_seq'); |
||
2956 | $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()); |
||
2957 | $db->queryF($sql); |
||
2958 | $db->queryF(sprintf('DELETE FROM `%s` WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
2959 | } |
||
2960 | if ($htmlbanner) { |
||
2961 | $bannerobject = $htmlcode; |
||
2962 | } else { |
||
2963 | $bannerobject = '<div align="center"><a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" target="_blank">'; |
||
2964 | if (false !== mb_stripos($imageurl, '.swf')) { |
||
2965 | $bannerobject .= '<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">' |
||
2966 | . '<param name="movie" value="' |
||
2967 | . $imageurl |
||
2968 | . '"></param>' |
||
2969 | . '<param name="quality" value="high"></param>' |
||
2970 | . '<embed src="' |
||
2971 | . $imageurl |
||
2972 | . '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' |
||
2973 | . '</embed>' |
||
2974 | . '</object>'; |
||
2975 | } else { |
||
2976 | $bannerobject .= '<img src="' . $imageurl . '" alt="">'; |
||
2977 | } |
||
2978 | $bannerobject .= '</a></div>'; |
||
2979 | } |
||
2980 | |||
2981 | return $bannerobject; |
||
2982 | } |
||
2983 | |||
2984 | return null; |
||
2985 | } |
||
2986 | |||
2987 | /** |
||
2988 | * @param $client_id |
||
2989 | * |
||
2990 | * @return null|string |
||
2991 | */ |
||
2992 | public static function getBannerFromClientId($client_id) |
||
2993 | { |
||
2994 | ###### Hack by www.stefanosilvestrini.com ###### |
||
2995 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
2996 | $bresult = $db->query('SELECT COUNT(*) FROM ' . $db->prefix('banner') . ' WHERE cid=' . $client_id); |
||
2997 | [$numrows] = $db->fetchRow($bresult); |
||
2998 | if ($numrows > 1) { |
||
2999 | --$numrows; |
||
3000 | $bannum = mt_rand(0, $numrows); |
||
3001 | } else { |
||
3002 | $bannum = 0; |
||
3003 | } |
||
3004 | if ($numrows > 0) { |
||
3005 | $bresult = $db->query('SELECT * FROM ' . $db->prefix('banner') . ' WHERE cid=' . $client_id . ' ORDER BY rand()', 1, $bannum); |
||
3006 | [$bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode] = $db->fetchRow($bresult); |
||
3007 | if ($GLOBALS['xoopsConfig']['my_ip'] == xoops_getenv('REMOTE_ADDR')) { |
||
3008 | // EMPTY |
||
3009 | } else { |
||
3010 | $db->queryF(sprintf('UPDATE `%s` SET impmade = impmade+1 WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
3011 | } |
||
3012 | /* Check if this impression is the last one and print the banner */ |
||
3013 | if ($imptotal == $impmade) { |
||
3014 | $newid = $db->genId($db->prefix('bannerfinish') . '_bid_seq'); |
||
3015 | $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()); |
||
3016 | $db->queryF($sql); |
||
3017 | $db->queryF(sprintf('DELETE FROM `%s` WHERE bid = %u', $db->prefix('banner'), $bid)); |
||
3018 | } |
||
3019 | if ($htmlbanner) { |
||
3020 | $bannerobject = $htmlcode; |
||
3021 | } else { |
||
3022 | $bannerobject = '<div align="center"><a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" target="_blank">'; |
||
3023 | if (false !== mb_stripos($imageurl, '.swf')) { |
||
3024 | $bannerobject .= '<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">' |
||
3025 | . '<param name="movie" value="' |
||
3026 | . $imageurl |
||
3027 | . '"></param>' |
||
3028 | . '<param name="quality" value="high"></param>' |
||
3029 | . '<embed src="' |
||
3030 | . $imageurl |
||
3031 | . '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' |
||
3032 | . '</embed>' |
||
3033 | . '</object>'; |
||
3034 | } else { |
||
3035 | $bannerobject .= '<img src="' . $imageurl . '" alt="">'; |
||
3036 | } |
||
3037 | $bannerobject .= '</a></div>'; |
||
3038 | } |
||
3039 | |||
3040 | return $bannerobject; |
||
3041 | } |
||
3042 | |||
3043 | return null; |
||
3044 | } |
||
3045 | |||
3046 | public static function setNoIndexNoFollow() |
||
3047 | { |
||
3048 | global $xoopsTpl; |
||
3049 | if (is_object($GLOBALS['xoTheme'])) { |
||
3050 | $GLOBALS['xoTheme']->addMeta('meta', 'robots', 'noindex,nofollow'); |
||
3051 | } else { |
||
3052 | $xoopsTpl->assign('xoops_meta_robots', 'noindex,nofollow'); |
||
3053 | } |
||
3054 | } |
||
3055 | |||
3056 | /** |
||
3057 | * @param $userid |
||
3058 | * |
||
3059 | * @return string |
||
3060 | */ |
||
3061 | public static function getLinkedUserNameFromId($userid) |
||
3062 | { |
||
3063 | $userid = (int)$userid; |
||
3064 | if ($userid > 0) { |
||
3065 | /** @var \XoopsMemberHandler $memberHandler */ |
||
3066 | $memberHandler = xoops_getHandler('member'); |
||
3067 | $user = $memberHandler->getUser($userid); |
||
3068 | if (is_object($user)) { |
||
3069 | $linkeduser = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $userid . '">' . $user->getVar('uname') . '</a>'; |
||
3070 | |||
3071 | return $linkeduser; |
||
3072 | } |
||
3073 | } |
||
3074 | |||
3075 | return $GLOBALS['xoopsConfig']['anonymous']; |
||
3076 | } |
||
3077 | |||
3078 | /** |
||
3079 | * @param $time |
||
3080 | * |
||
3081 | * @return string |
||
3082 | */ |
||
3083 | public static function getTimestamp($time) |
||
3084 | { |
||
3085 | $moduleDirName = basename(dirname(__DIR__)); |
||
3086 | xoops_loadLanguage('local', $moduleDirName); |
||
3087 | |||
3088 | $trans = [ |
||
3089 | 'Monday' => _XOOPSTUBE_MONDAY, |
||
3090 | 'Tuesday' => _XOOPSTUBE_TUESDAY, |
||
3091 | 'Wednesday' => _XOOPSTUBE_WEDNESDAY, |
||
3092 | 'Thursday' => _XOOPSTUBE_THURSDAY, |
||
3093 | 'Friday' => _XOOPSTUBE_FRIDAY, |
||
3094 | 'Saturday' => _XOOPSTUBE_SATURDAY, |
||
3095 | 'Sunday' => _XOOPSTUBE_SUNDAY, |
||
3096 | 'Mon' => _XOOPSTUBE_MON, |
||
3097 | 'Tue' => _XOOPSTUBE_TUE, |
||
3098 | 'Wed' => _XOOPSTUBE_WED, |
||
3099 | 'Thu' => _XOOPSTUBE_THU, |
||
3100 | 'Fri' => _XOOPSTUBE_FRI, |
||
3101 | 'Sat' => _XOOPSTUBE_SAT, |
||
3102 | 'Sun' => _XOOPSTUBE_SUN, |
||
3103 | 'January' => _XOOPSTUBE_JANUARI, |
||
3104 | 'February' => _XOOPSTUBE_FEBRUARI, |
||
3105 | 'March' => _XOOPSTUBE_MARCH, |
||
3106 | 'April' => _XOOPSTUBE_APRIL, |
||
3107 | 'May' => _XOOPSTUBE_MAY, |
||
3108 | 'June' => _XOOPSTUBE_JUNE, |
||
3109 | 'July' => _XOOPSTUBE_JULY, |
||
3110 | 'August' => _XOOPSTUBE_AUGUST, |
||
3111 | 'September' => _XOOPSTUBE_SEPTEMBER, |
||
3112 | 'October' => _XOOPSTUBE_OCTOBER, |
||
3113 | 'November' => _XOOPSTUBE_NOVEMBER, |
||
3114 | 'December' => _XOOPSTUBE_DECEMBER, |
||
3115 | 'Jan' => _XOOPSTUBE_JAN, |
||
3116 | 'Feb' => _XOOPSTUBE_FEB, |
||
3117 | 'Mar' => _XOOPSTUBE_MAR, |
||
3118 | 'Apr' => _XOOPSTUBE_APR, |
||
3119 | // 'May' => _XOOPSTUBE_MAY2, |
||
3120 | 'Jun' => _XOOPSTUBE_JUN, |
||
3121 | 'Jul' => _XOOPSTUBE_JUL, |
||
3122 | 'Aug' => _XOOPSTUBE_AUG, |
||
3123 | 'Sep' => _XOOPSTUBE_SEP, |
||
3124 | 'Oct' => _XOOPSTUBE_OCT, |
||
3125 | 'Nov' => _XOOPSTUBE_NOV, |
||
3126 | 'Dec' => _XOOPSTUBE_DEC, |
||
3127 | ]; |
||
3128 | $timestamp = strtr($time, $trans); |
||
3129 | |||
3130 | return $timestamp; |
||
3131 | } |
||
3132 | |||
3133 | /** |
||
3134 | * Do some basic file checks and stuff. |
||
3135 | * Author: Andrew Mills Email: [email protected] |
||
3136 | * from amReviews module |
||
3137 | */ |
||
3138 | public static function fileChecks() |
||
3139 | { |
||
3140 | echo '<fieldset>'; |
||
3141 | echo '<legend style="color: #990000; font-weight: bold;">' . _AM_XOOPSTUBE_FILECHECKS . '</legend>'; |
||
3142 | |||
3143 | $dirPhotos = XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['catimage']; |
||
3144 | $dirVideos = XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['videodir']; |
||
3145 | $dirScreenshots = XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['videoimgdir']; |
||
3146 | |||
3147 | if (file_exists($dirPhotos)) { |
||
3148 | if (!is_writable($dirPhotos)) { |
||
3149 | echo '<span style=" color: red; font-weight: bold;">Warning:</span> ' . _AM_XOOPSTUBE_UNABLE_TO_WRITE . $dirPhotos . '<br>'; |
||
3150 | } else { |
||
3151 | echo '<span style=" color: green; font-weight: bold;">OK:</span> ' . $dirPhotos . '<br>'; |
||
3152 | } |
||
3153 | } else { |
||
3154 | echo '<span style=" color: red; font-weight: bold;">' . _AM_XOOPSTUBE_WARNING . '</span> ' . $dirPhotos . ' <span style=" color: red; ">' . _AM_XOOPSTUBE_NOT_EXISTS . '</span> <br>'; |
||
3155 | } |
||
3156 | // photothumbdir |
||
3157 | if (file_exists($dirVideos)) { |
||
3158 | if (!is_writable($dirVideos)) { |
||
3159 | echo '<span style=" color: red; font-weight: bold;">' . _AM_XOOPSTUBE_WARNING . '</span> ' . _AM_XOOPSTUBE_UNABLE_TO_WRITE . $dirVideos . '<br>'; |
||
3160 | } else { |
||
3161 | echo '<span style=" color: green; font-weight: bold;">OK:</span> ' . $dirVideos . '<br>'; |
||
3162 | } |
||
3163 | } else { |
||
3164 | echo '<span style=" color: red; font-weight: bold;">' . _AM_XOOPSTUBE_WARNING . '</span> ' . $dirVideos . ' <span style=" color: red; ">' . _AM_XOOPSTUBE_NOT_EXISTS . '</span> <br>'; |
||
3165 | } |
||
3166 | // photohighdir |
||
3167 | if (file_exists($dirScreenshots)) { |
||
3168 | if (!is_writable($dirScreenshots)) { |
||
3169 | echo '<span style=" color: red; font-weight: bold;">Warning:</span> ' . _AM_XOOPSTUBE_UNABLE_TO_WRITE . $dirScreenshots . '<br>'; |
||
3170 | } else { |
||
3171 | echo '<span style=" color: green; font-weight: bold;">OK:</span> ' . $dirScreenshots . '<br>'; |
||
3172 | } |
||
3173 | } else { |
||
3174 | echo '<span style=" color: red; font-weight: bold;">' . _AM_XOOPSTUBE_WARNING . '</span> ' . $dirScreenshots . ' <span style=" color: red; ">' . _AM_XOOPSTUBE_NOT_EXISTS . '</span> <br>'; |
||
3175 | } |
||
3176 | |||
3177 | /** |
||
3178 | * Some info. |
||
3179 | */ |
||
3180 | $uploads = ini_get('file_uploads') ? _AM_XOOPSTUBE_UPLOAD_ON : _AM_XOOPSTUBE_UPLOAD_OFF; |
||
3181 | echo '<br>'; |
||
3182 | echo '<ul>'; |
||
3183 | echo '<li>' . _AM_XOOPSTUBE_UPLOADMAX . '<b>' . ini_get('upload_max_filesize') . '</b></li>'; |
||
3184 | echo '<li>' . _AM_XOOPSTUBE_POSTMAX . '<b>' . ini_get('post_max_size') . '</b></li>'; |
||
3185 | echo '<li>' . _AM_XOOPSTUBE_UPLOADS . '<b>' . $uploads . '</b></li>'; |
||
3186 | |||
3187 | $gdinfo = gd_info(); |
||
3188 | if (function_exists('gd_info')) { |
||
3189 | echo '<li>' . _AM_XOOPSTUBE_GDIMGSPPRT . '<b>' . _AM_XOOPSTUBE_GDIMGON . '</b></li>'; |
||
3190 | echo '<li>' . _AM_XOOPSTUBE_GDIMGVRSN . '<b>' . $gdinfo['GD Version'] . '</b></li>'; |
||
3191 | } else { |
||
3192 | echo '<li>' . _AM_XOOPSTUBE_GDIMGSPPRT . '<b>' . _AM_XOOPSTUBE_GDIMGOFF . '</b></li>'; |
||
3193 | } |
||
3194 | echo '</ul>'; |
||
3195 | |||
3196 | //$inithingy = ini_get_all(); |
||
3197 | //print_r($inithingy); |
||
3198 | |||
3199 | echo '</fieldset>'; |
||
3200 | } |
||
3201 | |||
3202 | /** |
||
3203 | * @param $path |
||
3204 | * @param int $mode |
||
3205 | * @param $fileSource |
||
3206 | * @param null $fileTarget |
||
3207 | */ |
||
3208 | public static function createDirectory($path, $mode, $fileSource, $fileTarget = null) |
||
3209 | { |
||
3210 | if (!is_dir($path)) { |
||
3211 | if (!mkdir($path, $mode) && !is_dir($path)) { |
||
3212 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $path)); |
||
3213 | } |
||
3214 | file_put_contents($path . '/index.html', '<script>history.go(-1);</script>'); |
||
3215 | if (!empty($fileSource) && !empty($fileTarget)) { |
||
3216 | @copy($fileSource, $fileTarget); |
||
3217 | } |
||
3218 | } |
||
3219 | chmod($path, $mode); |
||
3220 | } |
||
3221 | |||
3222 | /** |
||
3223 | * @return string |
||
3224 | */ |
||
3225 | public static function getLetters() |
||
3226 | { |
||
3227 | global $xoopsModule; |
||
3228 | |||
3229 | $letterchoice = '<div>' . _MD_XOOPSTUBE_BROWSETOTOPIC . '</div>'; |
||
3230 | $alphabet = getXtubeAlphabet(); |
||
3231 | $num = count($alphabet) - 1; |
||
3232 | $counter = 0; |
||
3233 | $distinctDbLetters_arr = []; |
||
3234 | $sql = 'SELECT DISTINCT (UPPER(LEFT(title, 1))) AS letter FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos WHERE expired = 0 AND offline = 0'); |
||
3235 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
3236 | if ($result) { |
||
3237 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
3238 | $distinctDbLetters_arr[] = $row['letter']; |
||
3239 | } |
||
3240 | } |
||
3241 | unset($sql); |
||
3242 | |||
3243 | // while (list(, $ltr) = each($alphabet)) { |
||
3244 | foreach ($alphabet as $key => $ltr) { |
||
3245 | if (in_array($ltr, $distinctDbLetters_arr)) { |
||
3246 | $letterchoice .= '<a class="xoopstube_letters xoopstube_letters_green" href="'; |
||
3247 | } else { |
||
3248 | $letterchoice .= '<a class="xoopstube_letters" href="'; |
||
3249 | } |
||
3250 | $letterchoice .= XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?letter=' . $ltr . '">' . $ltr . '</a>'; |
||
3251 | if ($counter == round($num / 2)) { |
||
3252 | $letterchoice .= '<br>'; |
||
3253 | } elseif ($counter !== $num) { |
||
3254 | $letterchoice .= ' '; |
||
3255 | } |
||
3256 | ++$counter; |
||
3257 | } |
||
3258 | |||
3259 | return $letterchoice; |
||
3260 | } |
||
3261 | |||
3262 | /** |
||
3263 | * @return mixed|string |
||
3264 | */ |
||
3265 | public static function getLettersChoice() |
||
3266 | { |
||
3267 | global $xoopsModule; |
||
3268 | |||
3269 | $moduleDirName = $xoopsModule->getVar('dirname'); |
||
3270 | require_once XOOPS_ROOT_PATH . "/modules/$moduleDirName/class/$moduleDirName.php"; |
||
3271 | /** @var \Xoopstube\Helper $helper */ |
||
3272 | $helper = Xoopstube\Helper::getInstance(); |
||
3273 | |||
3274 | $a = $helper->getHandler('Xoopstube'); |
||
3275 | $b = $a->getActiveCriteria(); |
||
3276 | $moduleDirName = basename(dirname(__DIR__)); |
||
3277 | |||
3278 | $criteria = $helper->getHandler('Xoopstube')->getActiveCriteria(); |
||
3279 | $criteria->setGroupby('UPPER(LEFT(title,1))'); |
||
3280 | $countsByLetters = $helper->getHandler($moduleDirName)->getCounts($criteria); |
||
3281 | // Fill alphabet array |
||
3282 | $alphabet = getXtubeAlphabet(); |
||
3283 | $alphabet_array = []; |
||
3284 | foreach ($alphabet as $letter) { |
||
3285 | $letter_array = []; |
||
3286 | if (isset($countsByLetters[$letter])) { |
||
3287 | $letter_array['letter'] = $letter; |
||
3288 | $letter_array['count'] = $countsByLetters[$letter]; |
||
3289 | $letter_array['url'] = '' . XOOPS_URL . "/modules/$moduleDirName/viewcat.php?letter={$letter}"; |
||
3290 | } else { |
||
3291 | $letter_array['letter'] = $letter; |
||
3292 | $letter_array['count'] = 0; |
||
3293 | $letter_array['url'] = ''; |
||
3294 | } |
||
3295 | $alphabet_array[$letter] = $letter_array; |
||
3296 | unset($letter_array); |
||
3297 | } |
||
3298 | // Render output |
||
3299 | if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
||
3300 | require_once $GLOBALS['xoops']->path('class/theme.php'); |
||
3301 | $GLOBALS['xoTheme'] = new xos_opal_Theme(); |
||
3302 | } |
||
3303 | require_once $GLOBALS['xoops']->path('class/template.php'); |
||
3304 | $letterschoiceTpl = new XoopsTpl(); |
||
3305 | $letterschoiceTpl->caching = 0; // Disable cache |
||
3306 | $letterschoiceTpl->assign('alphabet', $alphabet_array); |
||
3307 | $html = $letterschoiceTpl->fetch('db:' . $helper->getModule()->dirname() . '_common_letterschoice.tpl'); |
||
3308 | unset($letterschoiceTpl); |
||
3309 | |||
3310 | return $html; |
||
3311 | } |
||
3312 | |||
3313 | /** |
||
3314 | * Recursively sort categories by level and weight |
||
3315 | * |
||
3316 | * @param int $pid |
||
3317 | * @param int $level |
||
3318 | * |
||
3319 | * @return array array of arrays: 'pid', 'cid', 'level', 'category' as array |
||
3320 | * |
||
3321 | * @access public |
||
3322 | * @author luciorota |
||
3323 | */ |
||
3324 | public static function sortCategories($pid = 0, $level = 0) |
||
3325 | { |
||
3326 | /** @var \Xoopstube\Helper $helper */ |
||
3327 | $helper = Xoopstube\Helper::getInstance(); |
||
3328 | |||
3329 | $sorted = []; |
||
3330 | $criteria = new CriteriaCompo(); |
||
3331 | $criteria->add(new Criteria('pid', $pid)); |
||
3332 | $criteria->setSort('weight'); |
||
3333 | $criteria->setOrder('ASC'); |
||
3334 | $subCategoryObjs = $helper->getHandler('Category')->getObjects($criteria); |
||
3335 | if (count($subCategoryObjs) > 0) { |
||
3336 | ++$level; |
||
3337 | foreach ($subCategoryObjs as $subCategoryObj) { |
||
3338 | $pid = $subCategoryObj->getVar('pid'); |
||
3339 | $cid = $subCategoryObj->getVar('cid'); |
||
3340 | $sorted[] = ['pid' => $pid, 'cid' => $cid, 'level' => $level, 'category' => $subCategoryObj->toArray()]; |
||
3341 | if (false !== ($subSorted = self::sortCategories($cid, $level))) { |
||
3342 | $sorted = array_merge($sorted, $subSorted); |
||
3343 | } |
||
3344 | } |
||
3345 | } |
||
3346 | |||
3347 | return $sorted; |
||
3348 | } |
||
3349 | |||
3350 | /** |
||
3351 | * Create download by letter choice bar/menu |
||
3352 | * updated starting from this idea https://xoops.org/modules/news/article.php?storyid=6497 |
||
3353 | * |
||
3354 | * @return string html |
||
3355 | * |
||
3356 | * @access public |
||
3357 | * @author luciorota |
||
3358 | */ |
||
3359 | // public static function lettersChoice() |
||
3360 | // { |
||
3361 | // /** @var \Xoopstube\Helper $helper */ |
||
3362 | // $helper = Xoopstube\Helper::getInstance(); |
||
3363 | // |
||
3364 | // $criteria = $helper->getHandler('Videos')->getActiveCriteria(); |
||
3365 | // $criteria->setGroupby('UPPER(LEFT(title,1))'); |
||
3366 | // $countsByLetters = $helper->getHandler('Videos')->getCounts($criteria); |
||
3367 | // // Fill alphabet array |
||
3368 | // $alphabet = getLocalAlphabet(); |
||
3369 | // $alphabetArray = []; |
||
3370 | // foreach ($alphabet as $letter) { |
||
3371 | // $letter_array = []; |
||
3372 | // if (isset($countsByLetters[$letter])) { |
||
3373 | // $letter_array['letter'] = $letter; |
||
3374 | // $letter_array['count'] = $countsByLetters[$letter]; |
||
3375 | // $letter_array['url'] = XOOPS_URL . "/modules/{$helper->getModule()->dirname()}/viewcat.php?list={$letter}"; |
||
3376 | // } else { |
||
3377 | // $letter_array['letter'] = $letter; |
||
3378 | // $letter_array['count'] = 0; |
||
3379 | // $letter_array['url'] = ''; |
||
3380 | // } |
||
3381 | // $alphabetArray[$letter] = $letter_array; |
||
3382 | // unset($letter_array); |
||
3383 | // } |
||
3384 | // // Render output |
||
3385 | // if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
||
3386 | // require_once $GLOBALS['xoops']->path('/class/theme.php'); |
||
3387 | // $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||
3388 | // } |
||
3389 | // require_once $GLOBALS['xoops']->path('class/template.php'); |
||
3390 | // $letterschoiceTpl = new \XoopsTpl(); |
||
3391 | // $letterschoiceTpl->caching = false; // Disable cache |
||
3392 | // $letterschoiceTpl->assign('alphabet', $alphabetArray); |
||
3393 | // $html = $letterschoiceTpl->fetch("db:{$helper->getModule()->dirname()}_common_letterschoice.tpl"); |
||
3394 | // unset($letterschoiceTpl); |
||
3395 | // |
||
3396 | // return $html; |
||
3397 | // } |
||
3398 | |||
3399 | //=============== from WF-Downloads ====================================== |
||
3400 | |||
3401 | /** |
||
3402 | * @return bool |
||
3403 | */ |
||
3404 | public static function isUserAdmin() |
||
3405 | { |
||
3406 | /** @var \Xoopstube\Helper $helper */ |
||
3407 | $helper = Xoopstube\Helper::getInstance(); |
||
3408 | |||
3409 | static $xtubeIsAdmin; |
||
3410 | |||
3411 | if (isset($xtubeIsAdmin)) { |
||
3412 | return $xtubeIsAdmin; |
||
3413 | } |
||
3414 | |||
3415 | if (!$GLOBALS['xoopsUser']) { |
||
3416 | $xtubeIsAdmin = false; |
||
3417 | } else { |
||
3418 | $xtubeIsAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid')); |
||
3419 | } |
||
3420 | |||
3421 | return $xtubeIsAdmin; |
||
3422 | } |
||
3423 | |||
3424 | //from Lexikon |
||
3425 | |||
3426 | /** |
||
3427 | * @return int |
||
3428 | */ |
||
3429 | public static function countCats() |
||
3430 | { |
||
3431 | global $xoopsUser, $xoopsModule; |
||
3432 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
3433 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
3434 | $totalcats = $grouppermHandler->getItemIds('lexikon_view', $groups, $xoopsModule->getVar('mid')); |
||
3435 | |||
3436 | return count($totalcats); |
||
3437 | } |
||
3438 | |||
3439 | /** |
||
3440 | * @return mixed |
||
3441 | */ |
||
3442 | public static function countWords() |
||
3443 | { |
||
3444 | global $xoopsUser, $xoopsDB; |
||
3445 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
3446 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
3447 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
3448 | $moduleHandler = xoops_getHandler('module'); |
||
3449 | $module = $moduleHandler->getByDirname('lexikon'); |
||
3450 | $module_id = $module->getVar('mid'); |
||
3451 | $allowed_cats = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id); |
||
3452 | $catids = implode(',', $allowed_cats); |
||
3453 | $catperms = " AND categoryID IN ($catids) "; |
||
3454 | |||
3455 | $pubwords = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit = '0' AND offline ='0' AND request = '0' " . $catperms . ' '); |
||
3456 | $publishedwords = $xoopsDB->getRowsNum($pubwords); |
||
3457 | |||
3458 | return $publishedwords; |
||
3459 | } |
||
3460 | |||
3461 | /** |
||
3462 | * @return array |
||
3463 | */ |
||
3464 | public static function getCategoryArray() |
||
3465 | { |
||
3466 | global $xoopsDB, $xoopsUser, $xoopsModule; |
||
3467 | /** @var \Xoopstube\Helper $helper */ |
||
3468 | $helper = Xoopstube\Helper::getInstance(); |
||
3469 | $myts = MyTextSanitizer::getInstance(); |
||
3470 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
3471 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
3472 | $block0 = []; |
||
3473 | $count = 1; |
||
3474 | $resultcat = $xoopsDB->query('SELECT categoryID, name, total, logourl FROM ' . $xoopsDB->prefix('lxcategories') . ' ORDER BY weight ASC'); |
||
3475 | while (list($catID, $name, $total, $logourl) = $xoopsDB->fetchRow($resultcat)) { |
||
3476 | if ($grouppermHandler->checkRight('lexikon_view', $catID, $groups, $xoopsModule->getVar('mid'))) { |
||
3477 | $catlinks = []; |
||
3478 | ++$count; |
||
3479 | if ($logourl && 'http://' !== $logourl) { |
||
3480 | $logourl = htmlspecialchars($logourl); |
||
3481 | } else { |
||
3482 | $logourl = ''; |
||
3483 | } |
||
3484 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
3485 | $catlinks['id'] = (int)$catID; |
||
3486 | $catlinks['total'] = (int)$total; |
||
3487 | $catlinks['linktext'] = htmlspecialchars($name); |
||
3488 | $catlinks['image'] = $logourl; |
||
3489 | $catlinks['count'] = $count; |
||
3490 | |||
3491 | $block0['categories'][] = $catlinks; |
||
3492 | } |
||
3493 | } |
||
3494 | |||
3495 | return $block0; |
||
3496 | } |
||
3497 | |||
3498 | /** |
||
3499 | * @return array |
||
3500 | */ |
||
3501 | public static function getAlphaArray() |
||
3502 | { |
||
3503 | global $xoopsUser, $xoopsDB, $xoopsModule; |
||
3504 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
3505 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
3506 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
3507 | $moduleHandler = xoops_getHandler('module'); |
||
3508 | $module = $moduleHandler->getByDirname('lexikon'); |
||
3509 | $module_id = $module->getVar('mid'); |
||
3510 | $allowed_cats = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id); |
||
3511 | $catids = implode(',', $allowed_cats); |
||
3512 | $catperms = " AND categoryID IN ($catids) "; |
||
3513 | $alpha = []; |
||
3514 | /** |
||
3515 | * @param $a |
||
3516 | * @return null|string|string[] |
||
3517 | */ |
||
3518 | function unichr($a) |
||
3519 | { |
||
3520 | return mb_convert_encoding(pack('N', $a), mb_internal_encoding(), 'UCS-4BE'); |
||
3521 | } |
||
3522 | |||
3523 | for ($a = 48; $a < (48 + 10); ++$a) { |
||
3524 | $letterlinks = []; |
||
3525 | $initial = unichr($a); |
||
3526 | $sql = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '$initial' AND submit = '0' AND offline ='0' AND request = '0' " . $catperms . ' '); |
||
3527 | $howmany = $xoopsDB->getRowsNum($sql); |
||
3528 | $letterlinks['total'] = $howmany; |
||
3529 | $letterlinks['id'] = unichr($a); |
||
3530 | $letterlinks['linktext'] = unichr($a); |
||
3531 | |||
3532 | $alpha['initial'][] = $letterlinks; |
||
3533 | } |
||
3534 | for ($a = 65; $a < (65 + 26); ++$a) { |
||
3535 | $letterlinks = []; |
||
3536 | $initial = unichr($a); |
||
3537 | $sql = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '$initial' AND submit = '0' AND offline ='0' AND request = '0' " . $catperms . ' '); |
||
3538 | $howmany = $xoopsDB->getRowsNum($sql); |
||
3539 | $letterlinks['total'] = $howmany; |
||
3540 | $letterlinks['id'] = unichr($a); |
||
3541 | $letterlinks['linktext'] = unichr($a); |
||
3542 | |||
3543 | $alpha['initial'][] = $letterlinks; |
||
3544 | } |
||
3545 | /*for ($a = 1040; $a < (1040 + 32); ++$a) { |
||
3546 | $letterlinks = []; |
||
3547 | $initial = unichr($a); |
||
3548 | $sql = $xoopsDB->query('SELECT entryID FROM ' |
||
3549 | . $xoopsDB->prefix('lxentries') |
||
3550 | . " WHERE init = '$initial' AND submit = '0' AND offline ='0' AND request = '0' " |
||
3551 | . $catperms |
||
3552 | . ''); |
||
3553 | $howmany = $xoopsDB->getRowsNum($sql); |
||
3554 | $letterlinks['total'] = $howmany; |
||
3555 | $letterlinks['id'] = unichr($a); |
||
3556 | $letterlinks['linktext'] = unichr($a); |
||
3557 | $alpha['initial'][] = $letterlinks; |
||
3558 | }*/ |
||
3559 | |||
3560 | return $alpha; |
||
3561 | } |
||
3562 | |||
3563 | /** |
||
3564 | * chr() with unicode support |
||
3565 | * I found this on this site http://en.php.net/chr |
||
3566 | * don't take credit for this. |
||
3567 | * @param $initials |
||
3568 | * @return string |
||
3569 | */ |
||
3570 | public static function getUchr($initials) |
||
3571 | { |
||
3582 | } |
||
3583 |