1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xmf\Module\Session;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class PublisherUtils
24: {
25: 26: 27: 28: 29:
30: public static function cpHeader()
31: {
32: $xoops = Xoops::getInstance();
33: $publisher = Publisher::getInstance();
34: $xoops->header();
35:
36: $css = array();
37: $css[] = $publisher->path('css/publisher.css');
38: $xoops->theme()->addBaseStylesheetAssets($css);
39:
40: $js = array();
41: $js[] = $publisher->path('js/funcs.js');
42: $js[] = $publisher->path('js/cookies.js');
43: $js[] = $publisher->path('js/ajaxupload.3.9.js');
44: $js[] = $publisher->path('js/publisher.js');
45: $xoops->theme()->addBaseScriptAssets($js);
46: }
47:
48: 49: 50: 51: 52: 53: 54:
55: public static function getOrderBy($sort)
56: {
57: if (in_array($sort, array("datesub", "counter"))) {
58: return 'DESC';
59: }
60:
61: return 'ASC';
62: }
63:
64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
74: public static function substr($str, $start, $length, $trimmarker = '...')
75: {
76:
77: if ($str == '') {
78: return $str;
79: }
80:
81:
82: $reversed_string = strrev(XoopsLocale::substr($str, $start, $length, ''));
83:
84:
85: $position_of_space = strpos($reversed_string, " ", 0);
86:
87:
88:
89:
90: $truncated_string = XoopsLocale::substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker);
91:
92: return $truncated_string;
93: }
94:
95: 96: 97: 98: 99:
100: public static function html2text($document)
101: {
102:
103:
104:
105:
106:
107:
108: $search = array(
109: "'<script[^>]*?>.*?</script>'si",
110: "'<img.*?/>'si",
111: "'<[\/\!]*?[^<>]*?>'si",
112: "'([\r\n])[\s]+'",
113: "'&(quot|#34);'i",
114: "'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i",
115: "'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'&#(\d+);'e"
116: );
117:
118: $replace = array(
119: "", "", "", "\\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\\1)"
120: );
121:
122: $text = preg_replace($search, $replace, $document);
123:
124: return $text;
125: }
126:
127: 128: 129:
130: public static function getAllowedImagesTypes()
131: {
132: return array(
133: 'jpg/jpeg', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/x-png', 'image/png', 'image/pjpeg'
134: );
135: }
136:
137: 138: 139: 140: 141:
142: public static function moduleHome($withLink = true)
143: {
144: $xoops = Xoops::getInstance();
145: $publisher = Publisher::getInstance();
146:
147: if (!$publisher->getConfig('format_breadcrumb_modname')) {
148: return '';
149: }
150:
151: if (!$withLink) {
152: return $publisher->getModule()->getVar('name');
153: } else {
154: return '<a href="' . $xoops->url(PUBLISHER_URL) . '/">' . $publisher->getModule()->getVar('name') . '</a>';
155: }
156: }
157:
158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168:
169: public static function copyr($source, $dest)
170: {
171:
172: if (is_file($source)) {
173: return copy($source, $dest);
174: }
175:
176:
177: if (!is_dir($dest)) {
178: mkdir($dest);
179: }
180:
181:
182: $dir = dir($source);
183: while (false !== $entry = $dir->read()) {
184:
185: if ($entry === '.' || $entry === '..') {
186: continue;
187: }
188:
189:
190: if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) {
191: self::copyr("$source/$entry", "$dest/$entry");
192: } else {
193: copy("$source/$entry", "$dest/$entry");
194: }
195: }
196:
197:
198: $dir->close();
199:
200: return true;
201: }
202:
203: 204: 205: 206: 207: 208: 209: 210:
211: public static function getPathStatus($item, $getStatus = false)
212: {
213: $publisher = Publisher::getInstance();
214: if ($item === 'root') {
215: $path = '';
216: } else {
217: $path = $item;
218: }
219:
220: $thePath = self::getUploadDir(true, $path);
221:
222: if (empty($thePath)) {
223: return false;
224: }
225: if (@is_writable($thePath)) {
226: $pathCheckResult = 1;
227: $path_status = _AM_PUBLISHER_AVAILABLE;
228: } elseif (!@is_dir($thePath)) {
229: $pathCheckResult = -1;
230: $path_status = _AM_PUBLISHER_NOTAVAILABLE . " <a href='" . $publisher->url("admin/index.php?op=createdir&path={$item}") . "'>" . _AM_PUBLISHER_CREATETHEDIR . "</a>";
231: } else {
232: $pathCheckResult = -2;
233: $path_status = _AM_PUBLISHER_NOTWRITABLE . " <a href='" . $publisher->url("admin/index.php?op=setperm&path={$item}") . "'>" . _AM_SCS_SETMPERM . "</a>";
234: }
235: if (!$getStatus) {
236: return $path_status;
237: } else {
238: return $pathCheckResult;
239: }
240: }
241:
242: 243: 244: 245: 246: 247: 248:
249: public static function mkdir($target)
250: {
251:
252:
253:
254: if (is_dir($target) || empty($target)) {
255: return true;
256: }
257:
258: if (XoopsLoad::fileExists($target) && !is_dir($target)) {
259: return false;
260: }
261:
262: if (self::mkdir(substr($target, 0, strrpos($target, '/')))) {
263: if (!XoopsLoad::fileExists($target)) {
264: $res = mkdir($target, 0777);
265: self::chmod($target);
266:
267: return $res;
268: }
269: }
270: $res = is_dir($target);
271:
272: return $res;
273: }
274:
275: 276: 277: 278: 279: 280: 281: 282:
283: public static function chmod($target, $mode = 0777)
284: {
285: return @chmod($target, $mode);
286: }
287:
288: 289: 290: 291: 292: 293:
294: public static function getUploadDir($hasPath = true, $item = false)
295: {
296: $xoops = Xoops::getInstance();
297: if ($item) {
298: if ($item === 'root') {
299: $item = '';
300: } else {
301: $item = $item . '/';
302: }
303: } else {
304: $item = '';
305: }
306:
307: if ($hasPath) {
308: return $xoops->path(PUBLISHER_UPLOADS_PATH . '/' . $item);
309: } else {
310: return $xoops->url(PUBLISHER_UPLOADS_URL . '/' . $item);
311: }
312: }
313:
314: 315: 316: 317: 318: 319:
320: public static function getImageDir($item = '', $hasPath = true)
321: {
322: if ($item) {
323: $item = "images/{$item}";
324: } else {
325: $item = "images";
326: }
327:
328: return self::getUploadDir($hasPath, $item);
329: }
330:
331: 332: 333: 334: 335:
336: public static function formatErrors($errors = array())
337: {
338: $ret = '';
339: foreach ($errors as $value) {
340: $ret .= '<br /> - ' . $value;
341: }
342:
343: return $ret;
344: }
345:
346: 347: 348: 349: 350: 351: 352:
353: public static function IsUserAuthor($itemObj)
354: {
355: $xoops = Xoops::getInstance();
356:
357: return ($xoops->isUser() && is_object($itemObj) && ($xoops->user->getVar('uid') == $itemObj->getVar('uid')));
358: }
359:
360: 361: 362: 363: 364: 365: 366:
367: public static function IsUserModerator($itemObj)
368: {
369: $publisher = Publisher::getInstance();
370: $categoriesGranted = $publisher->getPermissionHandler()->getGrantedItems('category_moderation');
371:
372: return (is_object($itemObj) && in_array($itemObj->getVar('categoryid'), $categoriesGranted));
373: }
374:
375: public static function IsUserAdmin()
376: {
377: return Publisher::getInstance()->isUserAdmin();
378: }
379:
380: 381: 382: 383: 384: 385: 386: 387: 388: 389:
390: public static function saveCategoryPermissions($groups, $categoryid, $perm_name)
391: {
392: $xoops = Xoops::getInstance();
393: $publisher = Publisher::getInstance();
394:
395: $result = true;
396:
397: $module_id = $publisher->getModule()->getVar('mid');
398: $gperm_handler = $xoops->getHandlerGroupPermission();
399:
400: $gperm_handler->deleteByModule($module_id, $perm_name, $categoryid);
401:
402:
403: if (count($groups) > 0) {
404: foreach ($groups as $group_id) {
405: $gperm_handler->addRight($perm_name, $categoryid, $group_id, $module_id);
406: }
407: }
408:
409: return $result;
410: }
411:
412: 413: 414: 415: 416: 417: 418: 419: 420:
421: public static function openCollapsableBar($tablename = '', $iconname = '', $tabletitle = '', $tabledsc = '', $open = true)
422: {
423: $publisher = Publisher::getInstance();
424: $image = 'open12.gif';
425: $display = 'none';
426: if ($open) {
427: $image = 'close12.gif';
428: $display = 'block';
429: }
430:
431: echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "')\";>";
432: echo "<img id='" . $iconname . "' src='" . $publisher->url("images/links/" . $image) . "' alt='' /></a> " . $tabletitle . "</h3>";
433: echo "<div id='" . $tablename . "' style='display: " . $display . ";'>";
434: if ($tabledsc != '') {
435: echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $tabledsc . "</span>";
436: }
437: }
438:
439: 440: 441: 442: 443: 444:
445: public static function closeCollapsableBar($name, $icon)
446: {
447: echo "</div>";
448:
449: $urls = self::getCurrentUrls();
450: $path = $urls['phpself'];
451:
452: $cookie_name = $path . '_publisher_collaps_' . $name;
453: $cookie_name = str_replace('.', '_', $cookie_name);
454: $cookie = self::getCookieVar($cookie_name, '');
455:
456: if ($cookie === 'none') {
457: echo '
458: <script type="text/javascript"><!--
459: toggle("' . $name . '"); toggleIcon("' . $icon . '");
460: //-->
461: </script>
462: ';
463: }
464: }
465:
466: 467: 468: 469: 470: 471: 472:
473: public static function setCookieVar($name, $value, $time = 0)
474: {
475: if ($time == 0) {
476: $time = time() + 3600 * 24 * 365;
477: }
478: setcookie($name, $value, $time, '/');
479: }
480:
481: 482: 483: 484: 485: 486:
487: public static function getCookieVar($name, $default = '')
488: {
489: if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) {
490: return $_COOKIE[$name];
491: } else {
492: return $default;
493: }
494: }
495:
496: 497: 498:
499: public static function getCurrentUrls()
500: {
501: $http = strpos(\XoopsBaseConfig::get('url'), "https://") === false ? "http://" : "https://";
502: $phpself = $_SERVER['PHP_SELF'];
503: $httphost = $_SERVER['HTTP_HOST'];
504: $querystring = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
505:
506: if ($querystring != '') {
507: $querystring = '?' . $querystring;
508: }
509:
510: $currenturl = $http . $httphost . $phpself . $querystring;
511:
512: $urls = array();
513: $urls['http'] = $http;
514: $urls['httphost'] = $httphost;
515: $urls['phpself'] = $phpself;
516: $urls['querystring'] = $querystring;
517: $urls['full'] = $currenturl;
518:
519: return $urls;
520: }
521:
522: 523: 524:
525: public static function getCurrentPage()
526: {
527: $urls = self::getCurrentUrls();
528:
529: return $urls['full'];
530: }
531:
532: 533: 534: 535: 536: 537: 538: 539: 540:
541: public static function addCategoryOption($categoryObj, $selectedid = 0, $level = 0, $ret = '')
542: {
543: $publisher = Publisher::getInstance();
544:
545: $spaces = '';
546: for ($j = 0; $j < $level; ++$j) {
547: $spaces .= '--';
548: }
549:
550: $ret .= "<option value='" . $categoryObj->getVar('categoryid') . "'";
551: if (is_array($selectedid) && in_array($categoryObj->getVar('categoryid'), $selectedid)) {
552: $ret .= " selected='selected'";
553: } elseif ($categoryObj->getVar('categoryid') == $selectedid) {
554: $ret .= " selected='selected'";
555: }
556: $ret .= ">" . $spaces . $categoryObj->getVar('name') . "</option>\n";
557:
558: $subCategoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $categoryObj->getVar('categoryid'));
559: if (count($subCategoriesObj) > 0) {
560: ++$level;
561: foreach ($subCategoriesObj as $subCategoryObj) {
562: $ret .= self::addCategoryOption($subCategoryObj, $selectedid, $level);
563: }
564: }
565:
566: return $ret;
567: }
568:
569: 570: 571: 572: 573: 574: 575: 576: 577:
578: public static function createCategorySelect($selectedid = 0, $parentcategory = 0, $allCatOption = true, $selectname = 'options[0]')
579: {
580: $publisher = Publisher::getInstance();
581:
582: $selectedid = explode(',', $selectedid);
583:
584: $ret = "<select name='" . $selectname . "[]' multiple='multiple' size='10'>";
585: if ($allCatOption) {
586: $ret .= "<option value='0'";
587: if (in_array(0, $selectedid)) {
588: $ret .= " selected='selected'";
589: }
590: $ret .= ">" . _MB_PUBLISHER_ALLCAT . "</option>";
591: }
592:
593:
594: $categoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $parentcategory);
595:
596: if (count($categoriesObj) > 0) {
597: foreach ($categoriesObj as $catID => $categoryObj) {
598: $ret .= self::addCategoryOption($categoryObj, $selectedid);
599: }
600: }
601: $ret .= "</select>";
602:
603: return $ret;
604: }
605:
606: 607: 608: 609: 610: 611: 612: 613:
614: public static function createCategoryOptions($selectedid = 0, $parentcategory = 0, $allCatOption = true)
615: {
616: $publisher = Publisher::getInstance();
617:
618: $ret = "";
619: if ($allCatOption) {
620: $ret .= "<option value='0'";
621: $ret .= ">" . _MB_PUBLISHER_ALLCAT . "</option>\n";
622: }
623:
624:
625: $categoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $parentcategory);
626: if (count($categoriesObj) > 0) {
627: foreach ($categoriesObj as $categoryObj) {
628: $ret .= self::addCategoryOption($categoryObj, $selectedid);
629: }
630: }
631:
632: return $ret;
633: }
634:
635: 636: 637: 638: 639: 640: 641:
642: public static function renderErrors(&$err_arr, $reseturl = '')
643: {
644: if (is_array($err_arr) && count($err_arr) > 0) {
645: echo '<div id="readOnly" class="errorMsg" style="border:1px solid #D24D00; background:#FEFECC url(' . PUBLISHER_URL . '/images/important-32.png) no-repeat 7px 50%;color:#333;padding-left:45px;">';
646:
647: echo '<h4 style="text-align:left;margin:0; padding-top:0">' . _AM_PUBLISHER_MSG_SUBMISSION_ERR;
648:
649: if ($reseturl) {
650: echo ' <a href="' . $reseturl . '">[' . _AM_PUBLISHER_TEXT_SESSION_RESET . ']</a>';
651: }
652:
653: echo '</h4><ul>';
654:
655: foreach ($err_arr as $key => $error) {
656: if (is_array($error)) {
657: foreach ($error as $err) {
658: echo '<li><a href="#' . $key . '" onclick="var e = xoopsGetElementById(\'' . $key . '\'); e.focus();">' . htmlspecialchars($err) . '</a></li>';
659: }
660: } else {
661: echo '<li><a href="#' . $key . '" onclick="var e = xoopsGetElementById(\'' . $key . '\'); e.focus();">' . htmlspecialchars($error) . '</a></li>';
662: }
663: }
664: echo "</ul></div><br />";
665: }
666: }
667:
668: 669: 670: 671: 672: 673: 674: 675: 676: 677:
678: public static function makeURI($page, $vars = array(), $encodeAmp = true)
679: {
680: $joinStr = '';
681:
682: $amp = ($encodeAmp ? '&' : '&');
683:
684: if (!count($vars)) {
685: return $page;
686: }
687:
688: $qs = '';
689: foreach ($vars as $key => $value) {
690: $qs .= $joinStr . $key . '=' . $value;
691: $joinStr = $amp;
692: }
693:
694: return $page . '?' . $qs;
695: }
696:
697: 698: 699: 700: 701:
702: public static function tellafriend($subject = '')
703: {
704: $xoops = Xoops::getInstance();
705: if (stristr($subject, '%')) {
706: $subject = rawurldecode($subject);
707: }
708: $target_uri = $xoops->url($_SERVER['REQUEST_URI']);
709:
710: return $xoops->url('modules/tellafriend/index.php?target_uri=' . rawurlencode($target_uri) . '&subject=' . rawurlencode($subject));
711: }
712:
713: 714: 715: 716: 717: 718: 719:
720: public static function uploadFile($another = false, $withRedirect = true, &$itemObj)
721: {
722: $xoops = Xoops::getInstance();
723:
724: $publisher = Publisher::getInstance();
725:
726: $itemid = isset($_POST['itemid']) ? (int)($_POST['itemid']) : 0;
727: $uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
728: $session = new Session();
729: $session->set('publisher_file_filename', isset($_POST['item_file_name']) ? $_POST['item_file_name'] : '');
730: $session->set('publisher_file_description', isset($_POST['item_file_description']) ? $_POST['item_file_description'] : '');
731: $session->set('publisher_file_status', isset($_POST['item_file_status']) ? (int)($_POST['item_file_status']) : 1);
732: $session->set('publisher_file_uid', $uid);
733: $session->set('publisher_file_itemid', $itemid);
734:
735: if (!is_object($itemObj)) {
736: $itemObj = $publisher->getItemHandler()->get($itemid);
737: }
738:
739: $fileObj = $publisher->getFileHandler()->create();
740: $fileObj->setVar('name', isset($_POST['item_file_name']) ? $_POST['item_file_name'] : '');
741: $fileObj->setVar('description', isset($_POST['item_file_description']) ? $_POST['item_file_description'] : '');
742: $fileObj->setVar('status', isset($_POST['item_file_status']) ? (int)($_POST['item_file_status']) : 1);
743: $fileObj->setVar('uid', $uid);
744: $fileObj->setVar('itemid', $itemObj->getVar('itemid'));
745: $fileObj->setVar('datesub', time());
746:
747:
748: $allowed_mimetypes = $publisher->getMimetypeHandler()->getArrayByType();
749:
750: $errors = array();
751:
752: if ($publisher->getConfig('perm_upload') && is_uploaded_file($_FILES['item_upload_file']['tmp_name'])) {
753: if (!$ret = $fileObj->checkUpload('item_upload_file', $allowed_mimetypes, $errors)) {
754: $errorstxt = implode('<br />', $errors);
755:
756: $message = sprintf(_CO_PUBLISHER_MESSAGE_FILE_ERROR, $errorstxt);
757: if ($withRedirect) {
758: $xoops->redirect("file.php?op=mod&itemid=" . $itemid, 5, $message);
759: } else {
760: return $message;
761: }
762: }
763: }
764:
765:
766: if (!$fileObj->store($allowed_mimetypes)) {
767: if ($withRedirect) {
768: $xoops->redirect("file.php?op=mod&itemid=" . $fileObj->getVar('itemid'), 3, _CO_PUBLISHER_FILEUPLOAD_ERROR . self::formatErrors($fileObj->getErrors()));
769: } else {
770: return _CO_PUBLISHER_FILEUPLOAD_ERROR . self::formatErrors($fileObj->getErrors());
771: }
772: }
773:
774: if ($withRedirect) {
775: $redirect_page = $another ? 'file.php' : 'item.php';
776: $xoops->redirect($redirect_page . "?op=mod&itemid=" . $fileObj->getVar('itemid'), 2, _CO_PUBLISHER_FILEUPLOAD_SUCCESS);
777: }
778:
779: return true;
780: }
781:
782: 783: 784:
785: public static function newFeatureTag()
786: {
787: $ret = '<span style="padding-right: 4px; font-weight: bold; color: red;">' . _CO_PUBLISHER_NEW_FEATURE . '</span>';
788:
789: return $ret;
790: }
791:
792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812:
813: public static function truncateTagSafe($string, $length = 80, $etc = '...', $break_words = false)
814: {
815: if ($length == 0) {
816: return '';
817: }
818:
819: if (strlen($string) > $length) {
820: $length -= strlen($etc);
821: if (!$break_words) {
822: $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
823: $string = preg_replace('/<[^>]*$/', '', $string);
824: $string = self::closeTags($string);
825: }
826:
827: return $string . $etc;
828: } else {
829: return $string;
830: }
831: }
832:
833: 834: 835: 836: 837: 838: 839: 840:
841: public static function closeTags($string)
842: {
843:
844: if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) {
845: $start_tags = $start_tags[1];
846:
847: if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) {
848: $complete_tags = array();
849: $end_tags = $end_tags[1];
850:
851: foreach ($start_tags as $val) {
852: $posb = array_search($val, $end_tags);
853: if (is_integer($posb)) {
854: unset($end_tags[$posb]);
855: } else {
856: $complete_tags[] = $val;
857: }
858: }
859: } else {
860: $complete_tags = $start_tags;
861: }
862:
863: $complete_tags = array_reverse($complete_tags);
864: for ($i = 0; $i < count($complete_tags); ++$i) {
865: $string .= '</' . $complete_tags[$i] . '>';
866: }
867: }
868:
869: return $string;
870: }
871:
872: 873: 874: 875: 876:
877: public static function ratingBar($itemid)
878: {
879: $xoops = Xoops::getInstance();
880: $publisher = Publisher::getInstance();
881: $rating_unitwidth = 30;
882: $units = 5;
883:
884: $criteria = new Criteria('itemid', $itemid);
885: $ratingObjs = $publisher->getRatingHandler()->getObjects($criteria);
886: unset($criteria);
887:
888: $uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0;
889: $count = count($ratingObjs);
890: $current_rating = 0;
891: $voted = false;
892: $ip = getenv('REMOTE_ADDR');
893:
894:
895: foreach ($ratingObjs as $ratingObj) {
896: $current_rating += $ratingObj->getVar('rate');
897: if ($ratingObj->getVar('ip') == $ip || ($uid > 0 && $uid == $ratingObj->getVar('uid'))) {
898: $voted = true;
899: }
900: }
901:
902: $tense = $count == 1 ? _MD_PUBLISHER_VOTE_lVOTE : _MD_PUBLISHER_VOTE_lVOTES;
903:
904:
905: $rating_width = @number_format($current_rating / $count, 2) * $rating_unitwidth;
906: $rating1 = @number_format($current_rating / $count, 1);
907: $rating2 = @number_format($current_rating / $count, 2);
908:
909: $groups = $xoops->getUserGroups();
910: $gperm_handler = $publisher->getGrouppermHandler();
911:
912: if (!$gperm_handler->checkRight('global', _PUBLISHER_RATE, $groups, $publisher->getModule()->getVar('mid'))) {
913: $static_rater = array();
914: $static_rater[] .= "\n" . '<div class="publisher_ratingblock">';
915: $static_rater[] .= '<div id="unit_long' . $itemid . '">';
916: $static_rater[] .= '<div id="unit_ul' . $itemid . '" class="publisher_unit-rating" style="width:' . $rating_unitwidth * $units . 'px;">';
917: $static_rater[] .= '<div class="publisher_current-rating" style="width:' . $rating_width . 'px;">' . _MD_PUBLISHER_VOTE_RATING . ' ' . $rating2 . '/' . $units . '</div>';
918: $static_rater[] .= '</div>';
919: $static_rater[] .= '<div class="publisher_static">' . _MD_PUBLISHER_VOTE_RATING . ': <strong> ' . $rating1 . '</strong>/' . $units . ' (' . $count . ' ' . $tense . ') <br /><em>' . _MD_PUBLISHER_VOTE_DISABLE . '</em></div>';
920: $static_rater[] .= '</div>';
921: $static_rater[] .= '</div>' . "\n\n";
922:
923: return join("\n", $static_rater);
924: } else {
925: $rater = '';
926: $rater .= '<div class="publisher_ratingblock">';
927: $rater .= '<div id="unit_long' . $itemid . '">';
928: $rater .= '<div id="unit_ul' . $itemid . '" class="publisher_unit-rating" style="width:' . $rating_unitwidth * $units . 'px;">';
929: $rater .= '<div class="publisher_current-rating" style="width:' . $rating_width . 'px;">' . _MD_PUBLISHER_VOTE_RATING . ' ' . $rating2 . '/' . $units . '</div>';
930:
931: for ($ncount = 1; $ncount <= $units; ++$ncount) {
932: if (!$voted) {
933: $rater .= '<div><a href="' . PUBLISHER_URL . '/rate.php?itemid=' . $itemid . '&rating=' . $ncount . '" title="' . $ncount . ' ' . _MD_PUBLISHER_VOTE_OUTOF . ' ' . $units . '" class="publisher_r' . $ncount . '-unit rater" rel="nofollow">' . $ncount . '</a></div>';
934: }
935: }
936:
937: $rater .= ' </div>';
938: $rater .= ' <div';
939:
940: if ($voted) {
941: $rater .= ' class="publisher_voted"';
942: }
943:
944: $rater .= '>' . _MD_PUBLISHER_VOTE_RATING . ': <strong> ' . $rating1 . '</strong>/' . $units . ' (' . $count . ' ' . $tense . ')';
945: $rater .= ' </div>';
946: $rater .= '</div>';
947: $rater .= '</div>';
948:
949: return $rater;
950: }
951: }
952:
953: 954: 955: 956: 957:
958: public static function getEditors($allowed_editors = null)
959: {
960: $ret = array();
961: $nohtml = false;
962: $editor_handler = XoopsEditorHandler::getInstance();
963: $editors = $editor_handler->getList($nohtml);
964: foreach ($editors as $name => $title) {
965: $key = self::stringToInt($name);
966: if (is_array($allowed_editors)) {
967:
968: if (in_array($key, $allowed_editors)) {
969: $ret[] = $name;
970: }
971: } else {
972:
973: $ret[$key]['name'] = $name;
974: $ret[$key]['title'] = $title;
975: }
976: }
977:
978: return $ret;
979: }
980:
981: 982: 983: 984: 985: 986:
987: public static function stringToInt($string = '', $length = 5)
988: {
989: for ($i = 0, $final = "", $string = substr(md5($string), $length); $i < $length; $final .= (int)($string[$i]), ++$i) {
990: }
991:
992: return (int)($final);
993: }
994:
995: 996: 997: 998: 999:
1000: public static function convertCharset($item)
1001: {
1002: if (XoopsLocale::getCharset() === 'UTF-8') {
1003: return $item;
1004: }
1005:
1006: if (XoopsLocale::getCharset() !== 'windows-1256') {
1007: return utf8_encode($item);
1008: }
1009:
1010: if ($unserialize = unserialize($item)) {
1011: foreach ($unserialize as $key => $value) {
1012: $unserialize[$key] = @iconv('windows-1256', 'UTF-8', $value);
1013: }
1014: $serialize = serialize($unserialize);
1015:
1016: return $serialize;
1017: } else {
1018: return @iconv('windows-1256', 'UTF-8', $item);
1019: }
1020: }
1021:
1022: public static function seoTitle($title = '', $withExt = true)
1023: {
1024:
1025: 1026: 1027:
1028: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
1029: if (method_exists($myts, 'formatForML')) {
1030: $title = $myts->formatForML($title);
1031: }
1032:
1033:
1034:
1035: $title = rawurlencode(strtolower($title));
1036:
1037:
1038:
1039: $pattern = array(
1040: "/%09/", "/%20/", "/%21/", "/%22/", "/%23/", "/%25/", "/%26/", "/%27/", "/%28/", "/%29/", "/%2C/", "/%2F/",
1041: "/%3A/", "/%3B/", "/%3C/", "/%3D/", "/%3E/", "/%3F/", "/%40/", "/%5B/", "/%5C/", "/%5D/", "/%5E/", "/%7B/",
1042: "/%7C/", "/%7D/", "/%7E/", "/\./"
1043: );
1044: $rep_pat = array(
1045: "-", "-", "", "", "", "-100", "", "-", "", "", "", "-", "", "", "", "-", "", "", "-at-", "", "-", "", "-",
1046: "", "-", "", "-", ""
1047: );
1048: $title = preg_replace($pattern, $rep_pat, $title);
1049:
1050:
1051:
1052: $pattern = array(
1053: "/%B0/", "/%E8/", "/%E9/", "/%EA/", "/%EB/", "/%E7/", "/%E0/", "/%E2/", "/%E4/", "/%EE/", "/%EF/", "/%F9/",
1054: "/%FC/", "/%FB/", "/%F4/", "/%F6/"
1055: );
1056: $rep_pat = array("-", "e", "e", "e", "e", "c", "a", "a", "a", "i", "i", "u", "u", "u", "o", "o");
1057: $title = preg_replace($pattern, $rep_pat, $title);
1058:
1059: if (sizeof($title) > 0) {
1060: if ($withExt) {
1061: $title .= '.html';
1062: }
1063:
1064: return $title;
1065: }
1066:
1067: return '';
1068: }
1069:
1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078:
1079: public static function seoGenUrl($op, $id, $short_url = "")
1080: {
1081: $publisher = Publisher::getInstance();
1082: if ($publisher->getConfig('seo_url_rewrite') !== 'none') {
1083: if (!empty($short_url)) {
1084: $short_url = $short_url . '.html';
1085: }
1086:
1087: if ($publisher->getConfig('seo_url_rewrite') === 'htaccess') {
1088:
1089: return \XoopsBaseConfig::get('url') . '/' . $publisher->getConfig('seo_module_name') . ".${op}.${id}/${short_url}";
1090: } else {
1091: if ($publisher->getConfig('seo_url_rewrite') === 'path-info') {
1092:
1093: return $publisher->url("index.php/${op}.${id}/${short_url}");
1094: } else {
1095: die('Unknown SEO method.');
1096: }
1097: }
1098: } else {
1099:
1100: switch ($op) {
1101: case 'category':
1102: return $publisher->url("${op}.php?categoryid=${id}");
1103: case 'item':
1104: case 'print':
1105: return $publisher->url("${op}.php?itemid=${id}");
1106: default:
1107: die('Unknown SEO operation.');
1108: }
1109: }
1110: }
1111:
1112: 1113: 1114: 1115: 1116: 1117: 1118:
1119: public static function displayFlash($url, $width = 0, $height = 0)
1120: {
1121: if (!$width || !$height) {
1122: if (!$dimension = @getimagesize($url)) {
1123: return "<a href='{$url}' target='_blank'>{$url}</a>";
1124: }
1125: if (!$width) {
1126: $height = $dimension[1] * $width / $dimension[0];
1127: } elseif (!empty($height)) {
1128: $width = $dimension[0] * $height / $dimension[1];
1129: } else {
1130: list($width, $height) = array($dimension[0], $dimension[1]);
1131: }
1132: }
1133:
1134: $rp = "<object width='{$width}' height='{$height}' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
1135: $rp .= "<param name='movie' value='{$url}'>";
1136: $rp .= "<param name='QUALITY' value='high'>";
1137: $rp .= "<PARAM NAME='bgcolor' VALUE='#FFFFFF'>";
1138: $rp .= "<param name='wmode' value='transparent'>";
1139: $rp .= "<embed src='{$url}' width='{$width}' height='{$height}' quality='high' bgcolor='#FFFFFF' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed>";
1140: $rp .= "</object>";
1141:
1142: return $rp;
1143: }
1144: }
1145: