1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\HttpRequest;
13: use Xoops\Core\Request;
14: use Xoops\Core\FixedGroups;
15: use Xoops\Core\Handler\Factory as HandlerFactory;
16: use Xoops\Core\Kernel\Handlers\XoopsModule;
17: use Xoops\Core\Kernel\Handlers\XoopsUser;
18: use Xoops\Core\Theme\XoopsTheme;
19: use Xoops\Core\XoopsTpl;
20: use Psr\Log\LogLevel;
21:
22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
34: class Xoops
35: {
36: const VERSION = 'XOOPS 2.6.0-Alpha 3';
37:
38: 39: 40:
41: public $sessionManager = null;
42:
43: 44: 45:
46: public $module = null;
47:
48: 49: 50:
51: public $config = array();
52:
53: 54: 55:
56: public $moduleConfig = array();
57:
58: 59: 60:
61: public $moduleDirname = '';
62:
63: 64: 65:
66: public $user = '';
67:
68: 69: 70:
71: public $userIsAdmin = false;
72:
73: 74: 75:
76: public $option = array();
77:
78: 79: 80:
81: private $tpl = null;
82:
83: 84: 85:
86: private $theme = null;
87:
88: 89: 90:
91: public $paths = array(
92: 'XOOPS' => array(), 'www' => array(), 'var' => array(), 'lib' => array(), 'modules' => array(),
93: 'themes' => array(), 'media' => array()
94: );
95:
96: 97: 98:
99: public $tpl_name = '';
100:
101: 102: 103:
104: private $handlerFactory;
105:
106: 107: 108:
109: private $kernelHandlers = array();
110:
111: 112: 113:
114: private $moduleHandlers = array();
115:
116: 117: 118:
119: private $activeModules = null;
120:
121: 122: 123:
124: private $moduleConfigs = array();
125:
126: 127: 128:
129: public $isAdminSide = false;
130:
131: 132: 133:
134: private function __construct()
135: {
136: $root = \XoopsBaseConfig::get('root-path');
137: $lib = \XoopsBaseConfig::get('lib-path');
138: $var = \XoopsBaseConfig::get('var-path');
139:
140: $url = \XoopsBaseConfig::get('url');
141:
142: $this->paths['www'] = array($root, $url);
143: $this->paths['var'] = array($var, null);
144: $this->paths['lib'] = array($lib, $url . '/browse.php');
145: $this->paths['XOOPS'] = array($lib, $url . '/browse.php');
146: $this->paths['assets'] = array(\XoopsBaseConfig::get('asset-path'), \XoopsBaseConfig::get('asset-url'));
147: $this->paths['images'] = array($root . '/images', $url . '/images');
148: $this->paths['language'] = array($root . '/language', $url . '/language');
149: $this->paths['locale'] = array($root . '/locale', $url . '/locale');
150: $this->paths['media'] = array(\XoopsBaseConfig::get('media-path'), \XoopsBaseConfig::get('media-url'));
151: $this->paths['modules'] = array($root . '/modules', $url . '/modules');
152: $this->paths['themes'] = array(\XoopsBaseConfig::get('themes-path'), \XoopsBaseConfig::get('themes-url'));
153: $this->paths['uploads'] = array(\XoopsBaseConfig::get('uploads-path'), \XoopsBaseConfig::get('uploads-url'));
154:
155: $this->pathTranslation();
156: }
157:
158: 159: 160: 161: 162:
163: public static function getInstance()
164: {
165: static $instance;
166: if (!isset($instance)) {
167: $class = __CLASS__;
168: $instance = new $class();
169: }
170: return $instance;
171: }
172:
173: 174: 175: 176: 177:
178: public function db()
179: {
180: return \Xoops\Core\Database\Factory::getConnection();
181: }
182:
183: 184: 185: 186: 187: 188: 189:
190: public function cache($cacheName = 'default')
191: {
192: static $cacheManager;
193:
194: if (!isset($cacheManager)) {
195: $cacheManager = new \Xoops\Core\Cache\CacheManager();
196: }
197:
198: return $cacheManager->getCache($cacheName);
199: }
200:
201: 202: 203: 204: 205:
206: public function logger()
207: {
208: return \Xoops\Core\Logger::getInstance();
209: }
210:
211:
212: 213: 214: 215: 216:
217: public function events()
218: {
219: return \Xoops\Core\Events::getInstance();
220: }
221:
222: 223: 224: 225: 226:
227: public function assets()
228: {
229: static $instance;
230: if (!isset($instance)) {
231: $instance = new \Xoops\Core\Assets;
232: }
233: return $instance;
234: }
235:
236: 237: 238: 239: 240: 241: 242:
243: public function service($service)
244: {
245: static $instance;
246: if (!isset($instance)) {
247: $instance = \Xoops\Core\Service\Manager::getInstance();
248: }
249: return $instance->locate($service);
250: }
251:
252: 253: 254: 255: 256:
257: public function registry()
258: {
259: static $instance;
260: if (!isset($instance)) {
261: $instance = new \Xoops\Core\Registry();
262: }
263: return $instance;
264: }
265:
266: 267: 268: 269: 270:
271: public function security()
272: {
273: static $instance;
274: if (!isset($instance)) {
275: $instance = new \Xoops\Core\Security();
276: }
277: return $instance;
278: }
279:
280: 281: 282: 283: 284:
285: public function tpl()
286: {
287: return $this->tpl;
288: }
289:
290: 291: 292: 293: 294: 295: 296:
297: public function setTpl(XoopsTpl $tpl)
298: {
299: return $this->tpl = $tpl;
300: }
301:
302: 303: 304: 305: 306: 307: 308:
309: public function theme($tpl_name = null)
310: {
311: if (!isset($this->theme)) {
312: if ($tpl_name) {
313: $tpl_info = $this->getTplInfo($tpl_name);
314: $this->tpl_name = $tpl_info['tpl_name'];
315: } else {
316: $tpl_name = 'module:system/system_dummy.tpl';
317: $tpl_info = $this->getTplInfo($tpl_name);
318: $this->tpl_name = $tpl_info['tpl_name'];
319: }
320: if (!$this->isAdminSide) {
321: $xoopsThemeFactory = null;
322: $xoopsThemeFactory = new \Xoops\Core\Theme\Factory();
323: $xoopsThemeFactory->allowedThemes = $this->getConfig('theme_set_allowed');
324: $xoopsThemeFactory->defaultTheme = $this->getConfig('theme_set');
325: $this->setTheme($xoopsThemeFactory->createInstance(array('contentTemplate' => $this->tpl_name)));
326: } else {
327: $adminThemeFactory = new \Xoops\Core\Theme\AdminFactory();
328: $this->setTheme($adminThemeFactory->createInstance(array(
329: 'folderName' => 'default', 'themesPath' => 'modules/system/themes',
330: 'contentTemplate' => $this->tpl_name
331: )));
332:
333: list($cssAssets, $jsAssets) = $this->theme()->getLocalizationAssets('admin');
334: if (!empty($cssAssets)) {
335: $this->theme()->addBaseStylesheetAssets($cssAssets);
336: }
337: if (!empty($jsAssets)) {
338: $this->theme()->addBaseScriptAssets($jsAssets);
339: }
340: }
341: } else {
342: if ($tpl_name) {
343: $tpl_info = $this->getTplInfo($tpl_name);
344: $this->tpl_name = $tpl_info['tpl_name'];
345: $this->theme->contentTemplate = $this->tpl_name;
346: }
347: }
348: $GLOBALS['xoTheme'] = $this->theme;
349: return $this->theme;
350: }
351:
352: 353: 354: 355: 356: 357: 358:
359: public function setTheme(XoopsTheme $theme)
360: {
361: return $this->theme = $theme;
362: }
363:
364: 365: 366: 367: 368: 369: 370: 371:
372: public function path($url, $virtual = false)
373: {
374: $url = $this->normalizePath($url);
375: $rootPath = $this->normalizePath(\XoopsBaseConfig::get('root-path') . '/');
376: if (0 === strpos($url, $rootPath)) {
377: $url = substr($url, strlen($rootPath));
378: }
379:
380: $parts = explode('/', $url, 2);
381: $root = isset($parts[0]) ? $parts[0] : '';
382: $path = isset($parts[1]) ? $parts[1] : '';
383: if (!isset($this->paths[$root])) {
384: list($root, $path) = array('www', $url);
385: }
386: if (!$virtual) {
387: $path = $this->paths[$root][0] . '/' . $path;
388:
389: return $path;
390: }
391: return !isset($this->paths[$root][1]) ? '' : ($this->paths[$root][1] . '/' . $path);
392: }
393:
394: 395: 396: 397: 398: 399: 400:
401: public function normalizePath($path)
402: {
403: return str_replace('\\', '/', $path);
404: }
405:
406: 407: 408: 409: 410: 411: 412:
413: public function url($url)
414: {
415: return (false !== strpos($url, '://') ? $url : $this->path($url, true));
416: }
417:
418: 419: 420: 421: 422: 423: 424: 425:
426: public function buildUrl($url, $params = array())
427: {
428: if ($url === '.') {
429: $url = $_SERVER['REQUEST_URI'];
430: }
431: $split = explode('?', $url);
432: if (count($split) > 1) {
433: list($url, $query) = $split;
434: parse_str($query, $query);
435: $params = array_merge($query, $params);
436: }
437: if (!empty($params)) {
438: foreach ($params as $k => $v) {
439: $params[$k] = $k . '=' . rawurlencode($v);
440: }
441: $url .= '?' . implode('&', $params);
442: }
443: return $url;
444: }
445:
446: 447: 448: 449: 450: 451: 452: 453:
454: public function pathExists($path, $error_type)
455: {
456: if (XoopsLoad::fileExists($path)) {
457: return $path;
458: } else {
459: $this->logger()->log(
460: LogLevel::WARNING,
461: \XoopsLocale::E_FILE_NOT_FOUND,
462: array($path, $error_type)
463: );
464:
465:
466: return false;
467: }
468: }
469:
470: 471: 472: 473: 474:
475: public function gzipCompression()
476: {
477: 478: 479:
480: if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) === 'cli') {
481: $this->setConfig('gzip_compression', 0);
482: }
483:
484: if ($this->getConfig('gzip_compression') == 1
485: && extension_loaded('zlib')
486: && !ini_get('zlib.output_compression')
487: ) {
488: if (@ini_get('zlib.output_compression_level') < 0) {
489: ini_set('zlib.output_compression_level', 6);
490: }
491: ob_start('ob_gzhandler');
492: }
493: }
494:
495: 496: 497: 498: 499:
500: public function pathTranslation()
501: {
502: 503: 504: 505:
506: if (!isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['SCRIPT_FILENAME'])) {
507: $_SERVER['PATH_TRANSLATED'] = $_SERVER['SCRIPT_FILENAME'];
508: } else {
509: if (isset($_SERVER['PATH_TRANSLATED']) && !isset($_SERVER['SCRIPT_FILENAME'])) {
510: $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
511: }
512: }
513: 514: 515:
516: if (empty($_SERVER['REQUEST_URI'])) {
517:
518: if (!($_SERVER['REQUEST_URI'] = @$_SERVER['PHP_SELF'])) {
519: $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
520: }
521: if (isset($_SERVER['QUERY_STRING'])) {
522: $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
523: }
524: }
525: }
526:
527: 528: 529: 530: 531:
532: public function themeSelect()
533: {
534: $xoopsThemeSelect = Request::getString('xoops_theme_select', '', 'POST');
535: if (!empty($xoopsThemeSelect) && in_array($xoopsThemeSelect, $this->getConfig('theme_set_allowed'))) {
536: $this->setConfig('theme_set', $xoopsThemeSelect);
537: $_SESSION['xoopsUserTheme'] = $xoopsThemeSelect;
538: } else {
539: if (!empty($_SESSION['xoopsUserTheme'])
540: && in_array($_SESSION['xoopsUserTheme'], $this->getConfig('theme_set_allowed'))
541: ) {
542: $this->setConfig('theme_set', $_SESSION['xoopsUserTheme']);
543: }
544: }
545: }
546:
547: 548: 549: 550: 551: 552: 553: 554:
555: public function getTplInfo($tpl_name)
556: {
557: $parts = array();
558: $matched = preg_match('#(\w+):(\w+)/(.*)$#', $tpl_name, $parts);
559: if ($matched) {
560: $names = array('tpl_name', 'type', 'module', 'file');
561: $ret = array();
562: for ($i=0; $i<4; ++$i) {
563: $ret[$names[$i]] = $parts[$i];
564: }
565: } else {
566:
567: $this->events()->triggerEvent('debug.log', "Sloppy template: " . $tpl_name);
568: $ret = array();
569: $ret['type'] = $this->isAdminSide ? 'admin' : 'module';
570: $info = explode(':', $tpl_name);
571: if (count($info) == 2) {
572: $ret['type'] = $info[0];
573: $tpl_name = str_replace($ret['type'] . ':', '', $tpl_name);
574: }
575:
576: if ($ret['type'] === 'db') {
577:
578: $ret['type'] = $this->isAdminSide ? 'admin' : 'module';
579: }
580:
581: $info = explode('|', $tpl_name);
582: if (count($info) == 2) {
583: $ret['module'] = $info[0];
584: $ret['file'] = $info[1];
585: } else {
586: $ret['module'] = 'system';
587: $ret['file'] = $tpl_name;
588: if ($this->isModule()) {
589: $ret['module'] = $this->module->getVar('dirname', 'n');
590: }
591: }
592: $ret['tpl_name'] = $ret['type'] . ':' . $ret['module'] . '/' . $ret['file'];
593: }
594:
595: return $ret;
596: }
597:
598: 599: 600: 601: 602: 603: 604:
605: public function header($tpl_name = null)
606: {
607: static $included = false;
608: if ($included) {
609: return false;
610: }
611: $included = true;
612:
613: $this->events()->triggerEvent('core.header.start');
614:
615:
616: if (!$tpl_name && isset($this->option['template_main'])) {
617: $tpl_name = $this->option['template_main'];
618: $this->deprecated(
619: 'XoopsOption \'template_main\' is deprecated, please use $xoops->header(\'templatename.tpl\') instead'
620: );
621: }
622: $this->theme($tpl_name);
623: $this->tpl()->assign('xoops', $this);
624:
625: if ($this->isAdminSide) {
626: $this->events()->triggerEvent('system.class.gui.header');
627: include_once $this->path('modules/system/themes/default/default.php');
628: $gui = new XoopsGuiDefault();
629: $gui->header();
630: } else {
631: $this->events()->triggerEvent('core.header.addmeta');
632:
633: if (defined("XOOPS_STARTPAGE_REDIRECTED")) {
634: $smarty = $repeat = null;
635: $this->theme()->headContent(
636: null,
637: "<base href='" . \XoopsBaseConfig::get('url') . '/modules/'
638: . $this->getConfig('startpage') . "/' />",
639: $smarty,
640: $repeat
641: );
642: }
643:
644:
645: if ($this->isModule()) {
646: $cache_times = $this->getConfig('module_cache');
647: $this->theme()->contentCacheLifetime =
648: isset($cache_times[$this->module->getVar('mid')]) ? $cache_times[$this->module->getVar('mid')] : 0;
649:
650: } else {
651: if ($this->tpl_name === 'module:system/system_homepage.tpl') {
652:
653: }
654: }
655: $this->events()->triggerEvent('core.header.checkcache');
656: if ($this->theme()->checkCache()) {
657: exit();
658: }
659: }
660:
661: if (!isset($this->tpl_name) && $this->isModule()) {
662: ob_start();
663: }
664:
665: $this->events()->triggerEvent('core.header.end');
666: return true;
667: }
668:
669: 670: 671: 672: 673:
674: public function footer()
675: {
676: static $included = false;
677: if ($included) {
678: return false;
679: }
680: $included = true;
681:
682: $this->events()->triggerEvent('core.footer.start');
683:
684: if (!headers_sent()) {
685: header('Content-Type:text/html; charset=' . XoopsLocale::getCharset());
686: header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
687: header('Cache-Control: private, no-cache');
688: header('Pragma: no-cache');
689: }
690:
691: if (isset($this->option['template_main'])
692: && $this->option['template_main'] != $this->theme()->contentTemplate
693: ) {
694: trigger_error("xoopsOption[template_main] should be defined before including header.php", E_USER_WARNING);
695: $this->theme()->contentTemplate = $this->tpl_name;
696: }
697: $this->theme()->render();
698: $this->events()->triggerEvent('core.footer.end');
699: exit();
700: }
701:
702: 703: 704: 705: 706:
707: public function isModule()
708: {
709: return $this->module instanceof XoopsModule ? true : false;
710: }
711:
712: 713: 714: 715: 716:
717: public function isUser()
718: {
719: return $this->user instanceof XoopsUser ? true : false;
720: }
721:
722: 723: 724: 725: 726:
727: public function isAdmin()
728: {
729: return $this->userIsAdmin;
730: }
731:
732: 733: 734: 735: 736: 737: 738:
739: public function getHandlerBlock($optional = false)
740: {
741: return $this->getHandler('Block', $optional);
742: }
743:
744: 745: 746: 747: 748: 749: 750:
751: public function getHandlerBlockModuleLink($optional = false)
752: {
753: return $this->getHandler('BlockModuleLink', $optional);
754: }
755:
756: 757: 758: 759: 760: 761: 762:
763: public function getHandlerConfig($optional = false)
764: {
765: return $this->getHandler('Config', $optional);
766: }
767:
768: 769: 770: 771: 772: 773: 774:
775: public function getHandlerConfigItem($optional = false)
776: {
777: return $this->getHandler('ConfigItem', $optional);
778: }
779:
780: 781: 782: 783: 784: 785: 786:
787: public function getHandlerConfigOption($optional = false)
788: {
789: return $this->getHandler('ConfigOption', $optional);
790: }
791:
792: 793: 794: 795: 796: 797: 798:
799: public function getHandlerGroup($optional = false)
800: {
801: return $this->getHandler('Group', $optional);
802: }
803:
804: 805: 806: 807: 808: 809: 810:
811: public function getHandlerGroupPermission($optional = false)
812: {
813: return $this->getHandler('GroupPerm', $optional);
814: }
815:
816: 817: 818: 819: 820: 821: 822:
823: public function getHandlerMember($optional = false)
824: {
825: return $this->getHandler('Member', $optional);
826: }
827:
828: 829: 830: 831: 832: 833: 834:
835: public function getHandlerMembership($optional = false)
836: {
837: return $this->getHandler('Membership', $optional);
838: }
839:
840: 841: 842: 843: 844: 845: 846:
847: public function getHandlerModule($optional = false)
848: {
849: return $this->getHandler('Module', $optional);
850: }
851:
852: 853: 854: 855: 856: 857: 858:
859: public function getHandlerOnline($optional = false)
860: {
861: return $this->getHandler('Online', $optional);
862: }
863:
864: 865: 866: 867: 868: 869: 870:
871: public function getHandlerPrivateMessage($optional = false)
872: {
873: return $this->getHandler('Privmessage', $optional);
874: }
875:
876: 877: 878: 879: 880:
881: public function session()
882: {
883: if ($this->sessionManager === null) {
884: $this->sessionManager = new \Xoops\Core\Session\Manager();
885: }
886: return $this->sessionManager;
887: }
888:
889: 890: 891: 892: 893: 894: 895:
896: public function getHandlerTplFile($optional = false)
897: {
898: return $this->getHandler('tplfile', $optional);
899: }
900:
901: 902: 903: 904: 905: 906: 907:
908: public function getHandlerTplSet($optional = false)
909: {
910: return $this->getHandler('Tplset', $optional);
911: }
912:
913: 914: 915: 916: 917: 918: 919:
920: public function getHandlerUser($optional = false)
921: {
922: return $this->getHandler('user', $optional);
923: }
924:
925: 926: 927: 928: 929: 930: 931: 932:
933: protected function getHandler($name, $optional = false)
934: {
935: if (!isset($this->kernelHandlers[$name])) {
936: if (!isset($this->handlerFactory)) {
937: $this->handlerFactory = HandlerFactory::getInstance();
938: }
939: $handler = $this->handlerFactory->newSpec()->scheme('kernel')->name($name)->optional($optional)->build();
940: if ($handler === null) {
941: $this->logger()->log(
942: \Psr\Log\LogLevel::WARNING,
943: sprintf('A handler for %s is not available', $name)
944: );
945: }
946: $this->kernelHandlers[$name] = $handler;
947: }
948:
949: return $this->kernelHandlers[$name];
950: }
951:
952: 953: 954: 955: 956: 957: 958: 959: 960:
961: public function getModuleHandler($name = null, $module_dir = null, $optional = false)
962: {
963:
964: if (!isset($module_dir)) {
965:
966: if ($this->module instanceof XoopsModule) {
967: $module_dir = $this->module->getVar('dirname', 'n');
968: } else {
969: trigger_error('No Module is loaded', E_USER_ERROR);
970: }
971: } else {
972: $module_dir = trim($module_dir);
973: }
974: $name = (!isset($name)) ? $module_dir : trim($name);
975: if (!isset($this->moduleHandlers[$module_dir][$name])) {
976: if (!isset($this->handlerFactory)) {
977: $this->handlerFactory = HandlerFactory::getInstance();
978: }
979: $handler = $this->handlerFactory->create($name, $module_dir, $optional);
980: if ($handler === null) {
981: $this->logger()->log(
982: LogLevel::WARNING,
983: sprintf('No handler for %s exists in module %s', $name, $module_dir)
984: );
985: }
986: $this->moduleHandlers[$module_dir][$name] = $handler;
987: }
988: return $this->moduleHandlers[$module_dir][$name];
989: }
990:
991: 992: 993: 994: 995: 996: 997: 998: 999:
1000: public function getModuleForm($obj, $name, $module_dir = null)
1001: {
1002: if (empty($name)) {
1003: return false;
1004: }
1005: if (empty($module_dir)) {
1006: if ($this->isModule()) {
1007: $module_dir = $this->module->getVar('dirname', 'n');
1008: } else {
1009: return false;
1010: }
1011: }
1012: if (XoopsLoad::fileExists(
1013: $hnd_file = \XoopsBaseConfig::get('root-path') . "/modules/{$module_dir}/class/form/{$name}.php"
1014: )) {
1015: include_once $hnd_file;
1016: $class = ucfirst(strtolower($module_dir)) . ucfirst($name) . 'Form';
1017: if (class_exists($class)) {
1018: $instance = new $class($obj);
1019: if ($instance instanceof \Xoops\Form\Form) {
1020: return $instance;
1021: }
1022: }
1023: }
1024: return false;
1025: }
1026:
1027: 1028: 1029: 1030: 1031: 1032: 1033:
1034: public static function getModuleHelper($dirname)
1035: {
1036: return \Xoops\Module\Helper::getHelper($dirname);
1037: }
1038:
1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050:
1051: public function loadLanguage($name, $domain = '', $language = null)
1052: {
1053: if (empty($name)) {
1054: return false;
1055: }
1056:
1057: $language = empty($language) ? XoopsLocale::getLegacyLanguage() : $language;
1058:
1059: if ((empty($domain) || 'global' === $domain)) {
1060: $path = '';
1061: } else {
1062: $path = (is_array($domain)) ? array_shift($domain) . '/' : "modules/{$domain}/";
1063: }
1064: $path .= 'language';
1065:
1066: if (!XoopsLoad::fileExists($file = $this->path("{$path}/{$language}/{$name}.php"))) {
1067: if (!XoopsLoad::fileExists($file = $this->path("{$path}/english/{$name}.php"))) {
1068: return false;
1069: }
1070: }
1071: $ret = include_once $file;
1072: return $ret;
1073: }
1074:
1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082:
1083: public static function loadLocale($domain = null, $locale = null)
1084: {
1085: return \Xoops\Locale::loadLocale($domain, $locale);
1086: }
1087:
1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095:
1096: public function translate($key, $dirname = 'xoops')
1097: {
1098: return \Xoops\Locale::translate($key, $dirname);
1099: }
1100:
1101: 1102: 1103: 1104: 1105:
1106: public function getActiveModules()
1107: {
1108: if (is_array($this->activeModules)) {
1109: return $this->activeModules;
1110: }
1111:
1112: try {
1113: if (!$this->activeModules = $this->cache()->read('system/modules/active')) {
1114: $this->setActiveModules();
1115: }
1116: } catch (\Exception $e) {
1117: $this->activeModules = array();
1118: }
1119: return $this->activeModules;
1120: }
1121:
1122: 1123: 1124: 1125: 1126:
1127: public function setActiveModules()
1128: {
1129: $module_handler = $this->getHandlerModule();
1130: $modules_array = $module_handler->getAll(new Criteria('isactive', 1), array('dirname'), false, false);
1131: $modules_active = array();
1132: foreach ($modules_array as $module) {
1133: $modules_active[$module['mid']] = $module['dirname'];
1134: }
1135: $this->cache()->write('system/modules/active', $modules_active);
1136: $this->activeModules = $modules_active;
1137: return $modules_active;
1138: }
1139:
1140: 1141: 1142: 1143: 1144: 1145: 1146:
1147: public function isActiveModule($dirname)
1148: {
1149: if (isset($dirname) && in_array($dirname, $this->getActiveModules())) {
1150: return true;
1151: }
1152: return false;
1153: }
1154:
1155: 1156: 1157: 1158: 1159: 1160: 1161:
1162: public function getModuleByDirname($dirname)
1163: {
1164: $key = "system/module/dirname/{$dirname}";
1165: if (!$module = $this->cache()->read($key)) {
1166: $module = $this->getHandlerModule()->getByDirname($dirname);
1167: $this->cache()->write($key, $module);
1168: }
1169: return $module;
1170: }
1171:
1172: 1173: 1174: 1175: 1176: 1177: 1178:
1179: public function getModuleById($id)
1180: {
1181: $key = "system/module/id/{$id}";
1182: if (!$module = $this->cache()->read($key)) {
1183: $module = $this->getHandlerModule()->getById($id);
1184: $this->cache()->write($key, $module);
1185: }
1186: return $module;
1187: }
1188:
1189: 1190: 1191: 1192: 1193: 1194: 1195:
1196: public function simpleHeader($closehead = true)
1197: {
1198: $this->events()->triggerEvent('core.header.start');
1199: $this->theme();
1200: $xoopsConfigMetaFooter = $this->getConfigs();
1201:
1202: if (!headers_sent()) {
1203: header('Content-Type:text/html; charset=' . XoopsLocale::getCharset());
1204: header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
1205: header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
1206: header(
1207: 'Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0'
1208: );
1209: header("Pragma: no-cache");
1210: }
1211:
1212: echo "<!DOCTYPE html>\n";
1213: $xoops_url = \XoopsBaseConfig::get('url');
1214: echo '<html lang="' . XoopsLocale::getLangCode() . '">
1215: <head>
1216: <meta http-equiv="content-type" content="text/html; charset=' . XoopsLocale::getCharset() . '" />
1217: <meta name="robots" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_robots']) . '" />
1218: <meta name="keywords" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']) . '" />
1219: <meta name="description" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_description']) . '" />
1220: <meta name="rating" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_rating']) . '" />
1221: <meta name="author" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_author']) . '" />
1222: <meta name="generator" content="XOOPS" />
1223: <title>' . htmlspecialchars($this->getConfig('sitename')) . '</title>
1224: <script type="text/javascript" src="' . $xoops_url . '/include/xoops.js"></script>
1225: <script type="text/javascript" src="' . $xoops_url . '/media/jquery/jquery.js"></script>
1226: <script type="text/javascript" src="' . $xoops_url . '/media/bootstrap/js/bootstrap.min.js"></script>';
1227: $themecss = $this->getCss($this->getConfig('theme_set'));
1228: echo '<link rel="stylesheet" type="text/css" media="all" href="' . $xoops_url . '/xoops.css" />';
1229: $locale = $this->getConfig('locale');
1230: if (XoopsLoad::fileExists($this->path('locale/' . $locale . '/style.css'))) {
1231: echo '<link rel="stylesheet" type="text/css" media="all" href="' . $xoops_url
1232: . '/locale/' . $locale . '/style.css" />';
1233: }
1234: if ($themecss) {
1235: echo '<link rel="stylesheet" type="text/css" media="all" href="' . $themecss . '" />';
1236: echo '<link rel="stylesheet" type="text/css" media="screen" href="' .
1237: $this->url('themes/' . $this->getConfig('theme_set') . '/media/bootstrap/css/xoops.bootstrap.css')
1238: .'" />';
1239: }
1240: if ($closehead) {
1241: echo '</head><body>';
1242: }
1243: }
1244:
1245: 1246: 1247: 1248: 1249:
1250: public function simpleFooter()
1251: {
1252: $this->events()->triggerEvent('core.header.footer');
1253: echo '</body></html>';
1254: ob_end_flush();
1255: }
1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264:
1265: public function alert($type, $msg, $title = '/')
1266: {
1267: $tpl = new XoopsTpl();
1268: switch ($type) {
1269: case 'info':
1270: default:
1271: $tpl->assign('alert_type', 'alert-info');
1272: if ($title === '/') {
1273: $title = XoopsLocale::INFORMATION;
1274: }
1275: break;
1276:
1277: case 'error':
1278: $tpl->assign('alert_type', 'alert-error');
1279: if ($title === '/') {
1280: $title = XoopsLocale::ERROR;
1281: }
1282: break;
1283:
1284: case 'success':
1285: $tpl->assign('alert_type', 'alert-success');
1286: if ($title === '/') {
1287: $title = XoopsLocale::SUCCESS;
1288: }
1289: break;
1290:
1291: case 'warning':
1292: $tpl->assign('alert_type', '');
1293: if ($title === '/') {
1294: $title = XoopsLocale::WARNING;
1295: }
1296: break;
1297: }
1298:
1299: if ($title != '') {
1300: $tpl->assign('alert_title', $title);
1301: }
1302: if (!is_scalar($msg) && !is_array($msg)) {
1303: $msg = '';
1304: }
1305: if (is_array($msg)) {
1306:
1307: $alert_msg = @implode("<br />", $msg);
1308: } else {
1309: $alert_msg = $msg;
1310: }
1311: if ($alert_msg == '') {
1312: return '';
1313: } else {
1314: $tpl->assign('alert_msg', $alert_msg);
1315: $ret = $tpl->fetch('module:system/system_alert.tpl');
1316: return $ret;
1317: }
1318: }
1319:
1320: 1321: 1322: 1323: 1324: 1325: 1326: 1327: 1328: 1329: 1330:
1331: public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true)
1332: {
1333: $tpl = new XoopsTpl();
1334: $submit = ($submit != '') ? trim($submit) : XoopsLocale::A_SUBMIT;
1335: $tpl->assign('msg', $msg);
1336: $tpl->assign('action', $action);
1337: $tpl->assign('submit', $submit);
1338: $str_hiddens = '';
1339: foreach ($hiddens as $name => $value) {
1340: if (is_array($value)) {
1341: foreach ($value as $caption => $newvalue) {
1342: $str_hiddens .= '<input type="radio" name="' . $name . '" value="'
1343: . htmlspecialchars($newvalue) . '" > ' . $caption . NWLINE;
1344: }
1345: $str_hiddens .= '<br />' . NWLINE;
1346: } else {
1347: $str_hiddens .= '<input type="hidden" name="' . $name . '" value="'
1348: . htmlspecialchars($value) . '" />' . NWLINE;
1349: }
1350: }
1351: if ($addtoken != false) {
1352: $tpl->assign('token', $this->security()->getTokenHTML());
1353: }
1354: $tpl->assign('hiddens', $str_hiddens);
1355: return $tpl->fetch('module:system/system_confirm.tpl');
1356: }
1357:
1358: 1359: 1360: 1361: 1362: 1363: 1364:
1365: public function getUserTimestamp($time)
1366: {
1367: $dt = \Xoops\Core\Locale\Time::cleanTime($time);
1368: return $dt->getTimestamp();
1369: }
1370:
1371: 1372: 1373: 1374: 1375: 1376: 1377: 1378:
1379: public function userTimeToServerTime($timestamp, $userTZ = null)
1380: {
1381: if (!isset($userTZ)) {
1382: $userTZ = $this->getConfig('default_TZ');
1383: }
1384: $timestamp = $timestamp - (($userTZ - $this->getConfig('server_TZ')) * 3600);
1385: return (int)$timestamp;
1386: }
1387:
1388: 1389: 1390: 1391: 1392:
1393: public function getUserGroups()
1394: {
1395: $groups = $this->isUser() ? $this->user->getGroups() : array(FixedGroups::ANONYMOUS);
1396:
1397: return $groups;
1398: }
1399:
1400: 1401: 1402: 1403: 1404: 1405: 1406:
1407: public function makePass()
1408: {
1409: $makepass = '';
1410: $syllables = array(
1411: 'er', 'in', 'tia', 'wol', 'fe', 'pre', 'vet', 'jo', 'nes', 'al', 'len', 'son', 'cha', 'ir', 'ler', 'bo',
1412: 'ok', 'tio', 'nar', 'sim', 'ple', 'bla', 'ten', 'toe', 'cho', 'co', 'lat', 'spe', 'ak', 'er', 'po', 'co',
1413: 'lor', 'pen', 'cil', 'li', 'ght', 'wh', 'at', 'the', 'he', 'ck', 'is', 'mam', 'bo', 'no', 'fi', 've', 'any',
1414: 'way', 'pol', 'iti', 'cs', 'ra', 'dio', 'sou', 'rce', 'sea', 'rch', 'pa', 'per', 'com', 'bo', 'sp', 'eak',
1415: 'st', 'fi', 'rst', 'gr', 'oup', 'boy', 'ea', 'gle', 'tr', 'ail', 'bi', 'ble', 'brb', 'pri', 'dee', 'kay',
1416: 'en', 'be', 'se'
1417: );
1418: for ($count = 1; $count <= 4; ++$count) {
1419: if (1 == mt_rand() % 10) {
1420: $makepass .= sprintf('%0.0f', (rand() % 50) + 1);
1421: } else {
1422: $makepass .= sprintf('%s', $syllables[rand() % 62]);
1423: }
1424: }
1425: return $makepass;
1426: }
1427:
1428: 1429: 1430: 1431: 1432: 1433: 1434: 1435:
1436: public function checkEmail($email, $antispam = false)
1437: {
1438: if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
1439: return false;
1440: }
1441: if ($antispam) {
1442: $email = str_replace("@", " at ", $email);
1443: $email = str_replace(".", " dot ", $email);
1444: }
1445: return $email;
1446: }
1447:
1448: 1449: 1450: 1451: 1452: 1453: 1454:
1455: public function formatURL($url)
1456: {
1457: $url = trim($url);
1458: if ($url != '') {
1459: if (!preg_match('/^(https?|ftps?|ed2k)\:\/\//i', $url)) {
1460: $url = 'http://' . $url;
1461: }
1462: }
1463: return $url;
1464: }
1465:
1466: 1467: 1468: 1469: 1470:
1471: public function getBanner()
1472: {
1473: $options = '';
1474: $this->events()->triggerEvent('core.banner.display', array(&$options));
1475: return $options;
1476: }
1477:
1478: 1479: 1480: 1481: 1482: 1483: 1484: 1485: 1486: 1487: 1488: 1489:
1490: public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false)
1491: {
1492: $this->events()->triggerEvent('core.redirect.start', array(
1493: $url, $time, $message, $addredirect, $allowExternalLink
1494: ));
1495:
1496:
1497: $this->events()->triggerEvent('core.include.functions.redirectheader', array(
1498: $url, $time, $message, $addredirect, $allowExternalLink
1499: ));
1500:
1501: $xoops_url = \XoopsBaseConfig::get('url');
1502:
1503: if (preg_match("/[\\0-\\31]|about:|script:/i", $url)) {
1504: if (!preg_match('/^\b(java)?script:([\s]*)history\.go\(-[0-9]*\)([\s]*[;]*[\s]*)$/si', $url)) {
1505: $url = $xoops_url;
1506: }
1507: }
1508: if (!$allowExternalLink && $pos = strpos($url, '://')) {
1509: $xoopsLocation = substr($xoops_url, strpos($xoops_url, '://') + 3);
1510: if (strcasecmp(substr($url, $pos + 3, strlen($xoopsLocation)), $xoopsLocation)) {
1511: $url = $xoops_url;
1512: }
1513: }
1514: if (!defined('XOOPS_CPFUNC_LOADED')) {
1515: $theme = 'default';
1516: } else {
1517: $theme = $this->getConfig('theme_set');
1518: }
1519:
1520: $xoopsThemeFactory = null;
1521: $xoopsThemeFactory = new \Xoops\Core\Theme\Factory();
1522: $xoopsThemeFactory->allowedThemes = $this->getConfig('theme_set_allowed');
1523: $xoopsThemeFactory->defaultTheme = $theme;
1524: $this->setTheme($xoopsThemeFactory->createInstance(array(
1525: "plugins" => array(), "renderBanner" => false
1526: )));
1527: $this->setTpl($this->theme()->template);
1528: $this->tpl()->assign(array(
1529: 'xoops_theme' => $theme, 'xoops_imageurl' => \XoopsBaseConfig::get('themes-url') . '/' . $theme . '/',
1530: 'xoops_themecss' => $this->getCss($theme),
1531: 'xoops_requesturi' => htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES),
1532: 'xoops_sitename' => htmlspecialchars($this->getConfig('sitename'), ENT_QUOTES),
1533: 'xoops_slogan' => htmlspecialchars($this->getConfig('slogan'), ENT_QUOTES),
1534: 'xoops_dirname' => $this->isModule() ? $this->module->getVar('dirname') : 'system',
1535: 'xoops_pagetitle' => $this->isModule() ? $this->module->getVar('name')
1536: : htmlspecialchars($this->getConfig('slogan'), ENT_QUOTES)
1537: ));
1538:
1539: $this->tpl()->assign('time', (int)($time));
1540: if (!empty($_SERVER['REQUEST_URI']) && $addredirect && strstr($url, 'user.php')) {
1541: $joiner = (false===strpos($url, '?')) ? '?' : '&';
1542: $url .= $joiner . 'xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']);
1543: }
1544: $url = preg_replace("/&/i", '&', htmlspecialchars($url, ENT_QUOTES));
1545: $this->tpl()->assign('url', $url);
1546: $message = trim($message) != '' ? $message : XoopsLocale::E_TAKING_YOU_BACK;
1547: $this->tpl()->assign('message', $message);
1548: $this->tpl()->assign('lang_ifnotreload', sprintf(XoopsLocale::F_IF_PAGE_NOT_RELOAD_CLICK_HERE, $url));
1549:
1550: $this->events()->triggerEvent('core.include.functions.redirectheader.end');
1551: $this->tpl()->display('module:system/system_redirect.tpl');
1552: exit();
1553: }
1554:
1555: 1556: 1557: 1558: 1559: 1560: 1561: 1562: 1563:
1564: public static function simpleRedirect($url)
1565: {
1566: header("location: {$url}");
1567: $xoops = \Xoops::getInstance();
1568: $xoops->events()->triggerEvent('core.redirect.start', array($url));
1569: exit;
1570: }
1571:
1572: 1573: 1574: 1575: 1576: 1577: 1578:
1579: public function getEnv($key)
1580: {
1581: return HttpRequest::getInstance()->getEnv($key, '');
1582: }
1583:
1584: 1585: 1586: 1587: 1588: 1589: 1590:
1591: public function getCss($theme = '')
1592: {
1593: if ($theme == '') {
1594: $theme = $this->getConfig('theme_set');
1595: }
1596: $userAgent = $this->getEnv('HTTP_USER_AGENT');
1597: if (stristr($userAgent, 'mac')) {
1598: $str_css = 'styleMAC.css';
1599: } elseif (preg_match("/MSIE ([0-9]\.[0-9]{1,2})/i", $userAgent)) {
1600: $str_css = 'style.css';
1601: } else {
1602: $str_css = 'styleNN.css';
1603: }
1604: $xoops_theme_path = \XoopsBaseConfig::get('themes-path');
1605: $xoops_theme_url = \XoopsBaseConfig::get('themes-url');
1606: if (is_dir($xoops_theme_path . '/' . $theme)) {
1607: if (XoopsLoad::fileExists($xoops_theme_path . '/' . $theme . '/' . $str_css)) {
1608: return $xoops_theme_url . '/' . $theme . '/' . $str_css;
1609: } elseif (XoopsLoad::fileExists($xoops_theme_path . '/' . $theme . '/style.css')) {
1610: return $xoops_theme_url . '/' . $theme . '/style.css';
1611: }
1612: }
1613: if (is_dir($xoops_theme_path . '/' . $theme . '/css')) {
1614: if (XoopsLoad::fileExists($xoops_theme_path . '/' . $theme . '/css/' . $str_css)) {
1615: return $xoops_theme_url . '/' . $theme . '/css/' . $str_css;
1616: } elseif (XoopsLoad::fileExists($xoops_theme_path . '/' . $theme . '/css/style.css')) {
1617: return $xoops_theme_url . '/' . $theme . '/css/style.css';
1618: }
1619: }
1620: return '';
1621: }
1622:
1623: 1624: 1625: 1626: 1627:
1628: public function getMailer()
1629: {
1630: static $mailer;
1631: if (is_object($mailer)) {
1632: return $mailer;
1633: }
1634: \Xoops\Locale::loadMailerLocale();
1635: if (class_exists('XoopsMailerLocale')) {
1636: $mailer = new XoopsMailerLocale();
1637: } else {
1638: $mailer = new XoopsMailer();
1639: }
1640: return $mailer;
1641: }
1642:
1643: 1644: 1645: 1646: 1647: 1648: 1649:
1650: public function getOption($key)
1651: {
1652: $ret = '';
1653: if (isset($this->option[$key])) {
1654: $ret = $this->option[$key];
1655: }
1656: return $ret;
1657: }
1658:
1659: 1660: 1661: 1662: 1663: 1664: 1665: 1666:
1667: public function setOption($key, $value = null)
1668: {
1669: if (!is_null($value)) {
1670: $this->option[$key] = $value;
1671: }
1672: }
1673:
1674: 1675: 1676: 1677: 1678: 1679: 1680:
1681: public function getConfig($key)
1682: {
1683: return $this->getModuleConfig($key, 'system');
1684: }
1685:
1686: 1687: 1688: 1689: 1690:
1691: public function getConfigs()
1692: {
1693: return $this->getModuleConfigs('system');
1694: }
1695:
1696: 1697: 1698: 1699: 1700: 1701: 1702: 1703:
1704: public function addConfigs($configs, $dirname = 'system')
1705: {
1706: $dirname = trim(strtolower($dirname));
1707: if (empty($dirname)) {
1708: $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system';
1709: }
1710: if (!empty($dirname)) {
1711: $this->moduleConfigs[$dirname] = array_merge($this->moduleConfigs[$dirname], (array)$configs);
1712: }
1713: }
1714:
1715: 1716: 1717: 1718: 1719: 1720: 1721: 1722: 1723:
1724: public function setConfig($key, $value = null, $dirname = 'system')
1725: {
1726: if (!is_null($value)) {
1727: $dirname = trim(strtolower($dirname));
1728: if (empty($dirname)) {
1729: $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system';
1730: }
1731: $this->moduleConfigs[$dirname][$key] =& $value;
1732: }
1733: }
1734:
1735: 1736: 1737: 1738: 1739: 1740: 1741: 1742:
1743: public function unsetConfig($key, $dirname = 'system')
1744: {
1745: $dirname = trim(strtolower($dirname));
1746: if (empty($dirname)) {
1747: $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system';
1748: }
1749: unset($this->moduleConfigs[$dirname][$key]);
1750: if (empty($this->moduleConfigs[$dirname])) {
1751: unset($this->moduleConfigs[$dirname]);
1752: }
1753: }
1754:
1755: 1756: 1757: 1758: 1759:
1760: public function clearModuleConfigsCache()
1761: {
1762: $this->moduleConfigs = array();
1763: }
1764:
1765: 1766: 1767: 1768: 1769: 1770: 1771: 1772:
1773: public function getModuleConfig($key, $dirname = '')
1774: {
1775: $dirname = trim(strtolower($dirname));
1776: if (empty($dirname)) {
1777: $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system';
1778: }
1779:
1780: if (isset($this->moduleConfigs[$dirname][$key])) {
1781: return $this->moduleConfigs[$dirname][$key];
1782: }
1783:
1784: $this->getModuleConfigs($dirname);
1785:
1786: if (!isset($this->moduleConfigs[$dirname][$key])) {
1787: $this->moduleConfigs[$dirname][$key] = '';
1788: }
1789: return $this->moduleConfigs[$dirname][$key];
1790: }
1791:
1792: 1793: 1794: 1795: 1796: 1797: 1798:
1799: public function getModuleConfigs($dirname = '')
1800: {
1801: $dirname = trim($dirname);
1802: if (empty($dirname)) {
1803: $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system';
1804: }
1805: if (isset($this->moduleConfigs[$dirname])) {
1806: return $this->moduleConfigs[$dirname];
1807: }
1808: $this->moduleConfigs[$dirname] = array();
1809: $key = "system/module/configs/{$dirname}";
1810: if (!$configs = $this->cache()->read($key)) {
1811: $module = $this->getModuleByDirname($dirname);
1812: if (is_object($module)) {
1813: $configs = $this->getHandlerConfig()->getConfigsByModule($module->getVar('mid'));
1814: $this->cache()->write($key, $configs);
1815: $this->moduleConfigs[$dirname] =& $configs;
1816: }
1817: } else {
1818: $this->moduleConfigs[$dirname] =& $configs;
1819: }
1820:
1821: if ($this->isModule()) {
1822:
1823: $this->moduleConfig =& $this->moduleConfigs[$this->module->getVar('dirname')];
1824: }
1825: if ($dirname === 'system') {
1826: $this->config =& $this->moduleConfigs['system'];
1827: }
1828: return $this->moduleConfigs[$dirname];
1829: }
1830:
1831: 1832: 1833: 1834: 1835: 1836: 1837: 1838: 1839: 1840: 1841:
1842: public function appendConfig($key, array $values, $appendWithKey = false, $dirname = 'system')
1843: {
1844: $dirname = trim(strtolower($dirname));
1845: if (empty($dirname)) {
1846: $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system';
1847: }
1848: if (!isset($this->moduleConfigs[$dirname][$key]) || !is_array($this->moduleConfigs[$dirname][$key])) {
1849: $this->moduleConfigs[$dirname][$key] = array();
1850: }
1851: if ($appendWithKey) {
1852: foreach ($values as $key2 => $value) {
1853: $this->moduleConfigs[$dirname][$key][$key2] =& $value;
1854: }
1855: } else {
1856: $this->moduleConfigs[$dirname][$key][] =& $values;
1857: }
1858: }
1859:
1860: 1861: 1862: 1863: 1864:
1865: public function disableModuleCache()
1866: {
1867: if ($this->isModule()) {
1868: $this->appendConfig('module_cache', array($this->module->getVar('mid') => 0), true);
1869: }
1870: }
1871:
1872: 1873: 1874: 1875: 1876: 1877: 1878: 1879: 1880: 1881: 1882: 1883: 1884: 1885:
1886: public function getBaseDomain($url, $includeSubdomain = false, $returnObject = false)
1887: {
1888: $pslManager = new \Pdp\PublicSuffixListManager();
1889: $parser = new \Pdp\Parser($pslManager->getList());
1890:
1891: $url=mb_strtolower($url, 'UTF-8');
1892:
1893: try {
1894:
1895: $pdp = $parser->parseUrl($url);
1896: $host = $pdp->host->host;
1897: } catch (\Exception $e) {
1898: $this->events()->triggerEvent('core.exception', $e);
1899: return null;
1900: }
1901:
1902: if (!empty($host)) {
1903:
1904: if ($host==='localhost') {
1905: return $returnObject ? $pdp->host : $host;
1906: }
1907:
1908:
1909: if (substr($host, 0, 1)==='[' && substr($host, -1)===']') {
1910: $host = substr($host, 1, (strlen($host)-2));
1911: }
1912:
1913: if (filter_var($host, FILTER_VALIDATE_IP)) {
1914: return $returnObject ? new \Pdp\Uri\Url\Host(null, null, null, $host) : $host;
1915: }
1916: }
1917:
1918: $host = $pdp->host->registerableDomain;
1919: if (!empty($host) && $includeSubdomain) {
1920: $host = $pdp->host->host;
1921: }
1922: return $returnObject ? $pdp->host : $host;
1923: }
1924:
1925: 1926: 1927: 1928: 1929: 1930: 1931:
1932: public function templateTouch($tpl_id)
1933: {
1934: $tplfile = $this->getHandlerTplFile()->get($tpl_id);
1935:
1936: if (is_object($tplfile)) {
1937: $file = $tplfile->getVar('tpl_file', 'n');
1938: $module = $tplfile->getVar('tpl_module', 'n');
1939: $type = $tplfile->getVar('tpl_type', 'n');
1940: $tpl = new XoopsTpl();
1941: return $tpl->touch($type . ':' . $module . '/' . $file);
1942: }
1943: return false;
1944: }
1945:
1946: 1947: 1948: 1949: 1950: 1951: 1952:
1953: public function templateClearModuleCache($mid)
1954: {
1955: $module = $this->getModuleById($mid);
1956: $xoopsTpl = new XoopsTpl();
1957: $xoopsTpl->clearModuleCompileCache($module->getVar('dirname'));
1958: }
1959:
1960: 1961: 1962: 1963: 1964: 1965: 1966:
1967: public function deprecated($message)
1968: {
1969: $message = $this->logger()->sanitizePath($message);
1970: $this->events()->triggerEvent('core.deprecated', array($message));
1971: }
1972:
1973: 1974: 1975: 1976: 1977:
1978: public function disableErrorReporting()
1979: {
1980:
1981: $this->events()->triggerEvent('core.disableerrorreporting');
1982: }
1983: }
1984: