XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Legacy_Controller.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15if (!defined('XOOPS_TRUST_PATH')) {
16 echo 'Since XOOPSCube Legacy version 2.2 a TRUST_PATH is required in mainfile.php';
17 exit();
18}
19
20define('LEGACY_MODULE_VERSION', '2.5.0');
21
22define('LEGACY_CONTROLLER_STATE_PUBLIC', 1);
23define('LEGACY_CONTROLLER_STATE_ADMIN', 2);
24
25define('LEGACY_XOOPS_MODULE_MANIFESTO_FILENAME', 'xoops_version.php');
26
27require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_BlockProcedure.class.php';
28require_once XOOPS_ROOT_PATH . '/modules/legacy/class/Legacy_Utils.class.php';
29require_once XOOPS_ROOT_PATH . '/modules/legacy/class/Enum.class.php';
30require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_Identity.class.php';
31require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_RoleManager.class.php';
32
33require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_CacheInformation.class.php';
34require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_PublicControllerStrategy.class.php';
35require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_TextFilter.class.php';
36require_once XOOPS_ROOT_PATH . '/modules/legacy/class/Legacy_Debugger.class.php';
37
51{
52 public $_mAdminModeFlag = false;
53
54 public $_mStrategy = null;
55
56 public $mDialogMode = false;
57
61 public $mCheckLogin = null;
62
66 public $mLogout = null;
67
71 public $mCreateLanguageManager = null;
72
76 public $mSetBlockCachePolicy = null;
77
81 public $mActiveModules = null;
82
86 public $mSetModuleCachePolicy = null;
87
91 public $mGetLanguageName = null;
92
96 public $mSetupDebugger = null;
97
101 public $mDebugger;
102
109 public $_mNotifyRedirectToUser = null;
110
114 public $mLogger = null;
115
116 public function __construct()
117 {
118 parent::__construct();
119
120 //
121 // Setup member properties as member delegates.
122 //
123 $this->mSetupUser->register('Legacy_Controller.SetupUser');
124
125 $this->mCheckLogin =new XCube_Delegate();
126 $this->mCheckLogin->register('Site.CheckLogin');
127
128 $this->mLogout =new XCube_Delegate();
129 $this->mLogout->register('Site.Logout');
130
131 $this->mCreateLanguageManager = new XCube_Delegate();
132 $this->mCreateLanguageManager->register('Legacy_Controller.CreateLanguageManager');
133
134 $this->mGetLanguageName = new XCube_Delegate();
135 $this->mGetLanguageName->register('Legacy_Controller.GetLanguageName');
136
137 $this->mSetBlockCachePolicy = new XCube_Delegate();
138 $this->mSetModuleCachePolicy = new XCube_Delegate();
139
140 $this->mSetupDebugger = new XCube_Delegate();
141 $this->mSetupDebugger->add('Legacy_DebuggerManager::createInstance');
142
143 $this->mSetupTextFilter->add('Legacy_TextFilter::getInstance', XCUBE_DELEGATE_PRIORITY_FINAL-1);
144
145 $this->_mNotifyRedirectToUser = new XCube_Delegate();
146
147 }
148
149 public function prepare(&$root)
150 {
151 parent::prepare($root);
152
153 //
154 // Decide status. [TEST]
155 //
157
158 $urlInfo = $this->_parseUrl();
159
160 $adminStateFlag = false;
161 if ((is_countable($urlInfo) ? count($urlInfo) : 0) >= 3) {
162 if ('modules' === strtolower($urlInfo[0])) {
163 if ('admin' === strtolower($urlInfo[2])) {
164 $adminStateFlag = true;
165 } elseif ('legacy' === $urlInfo[1] && 'include' === $urlInfo[2]) {
166 $adminStateFlag = true;
167 } elseif ('system' === $urlInfo[1] && strpos($urlInfo[2], 'admin.php') === 0) {
168 $adminStateFlag = true;
169 }
170 }
171 } elseif (strpos($urlInfo[0], 'admin.php') === 0) {
172 $adminStateFlag = true;
173 }
174
175 if ($adminStateFlag) {
176 require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_AdminControllerStrategy.class.php';
177 $this->_mStrategy = new Legacy_AdminControllerStrategy($this);
178 } else {
179 $this->_mStrategy = new Legacy_PublicControllerStrategy($this);
180 }
181 }
182
186 public function executeCommon()
187 {
188 //
189 // Setup Filter chain and execute the process of these filters.
190 //
191 $this->_setupFilterChain();
192 $this->_processFilter();
193
194 if (!defined('XC_FORCE_DEBUG_PHP')) {
195 error_reporting(0);
196 }
197
198 // This ^^;
199 $this->_setupErrorHandler();
200
201 //function date_default_timezone_set() is added on PHP5.1.0
202 if (function_exists('date_default_timezone_set')) {
203 date_default_timezone_set($this->_getLocalTimezone());
204 }
205
206 $this->_setupEnvironment();
207
208 $this->_setupLogger();
209
210 $this->_setupDB();
211
212 $this->_setupLanguage();
213
214 $this->_setupTextFilter();
215
216 $this->_setupConfig();
217
218 $this->_setupScript();
219
220 $this->_setupDebugger();
221
222 $this->_loadInterfaceFiles();
223
224 $this->_processPreBlockFilter(); // What's !?
225
226 $this->_setupSession();
227
228 $this->_setupUser();
229
230 $this->setupModuleContext();
231
232 $this->_processModule();
233
234 $this->_processPostFilter();
235 }
236
248 public function executeCommonSubset(bool $connectdb = true)
249 {
250 $this->_setupErrorHandler();
251 $this->_setupEnvironment();
252 if ($connectdb) {
253 $this->_setupLogger();
254 $this->_setupDB();
255 }
256 }
257
258 public function _setupLogger()
259 {
260 require_once XOOPS_ROOT_PATH . '/class/logger.php';
261 $this->mLogger =& XoopsLogger::instance();
262 $this->mLogger->startTime();
263
264 $GLOBALS['xoopsLogger'] =& $this->mLogger;
265 }
266
267 public function &getLogger()
268 {
269 return $this->mLogger;
270 }
271
272 public function _getLocalTimezone()
273 {
274 $iTime = time();
275 $arr = localtime($iTime);
276 $arr[5] += 1900;
277 $arr[4]++;
278 $iTztime = gmmktime($arr[2], $arr[1], $arr[0], $arr[4], $arr[3], $arr[5]);
279 $offset = (float)(($iTztime - $iTime) / (60 * 60));
280 $zonelist =
281 [
282 'Kwajalein' => -12.00,
283 'Pacific/Midway' => -11.00,
284 'Pacific/Honolulu' => -10.00,
285 'America/Anchorage' => -9.00,
286 'America/Los_Angeles' => -8.00,
287 'America/Denver' => -7.00,
288 'America/Tegucigalpa' => -6.00,
289 'America/New_York' => -5.00,
290 'America/Caracas' => -4.30,
291 'America/Halifax' => -4.00,
292 'America/St_Johns' => -3.30,
293 'America/Argentina/Buenos_Aires' => -3.00,
294 'America/Sao_Paulo' => -3.00,
295 'Atlantic/South_Georgia' => -2.00,
296 'Atlantic/Azores' => -1.00,
297 'Europe/Dublin' => 0,
298 'Europe/Belgrade' => 1.00,
299 'Europe/Minsk' => 2.00,
300 'Asia/Kuwait' => 3.00,
301 'Asia/Tehran' => 3.30,
302 'Asia/Muscat' => 4.00,
303 'Asia/Yekaterinburg' => 5.00,
304 'Asia/Kolkata' => 5.30,
305 'Asia/Katmandu' => 5.45,
306 'Asia/Dhaka' => 6.00,
307 'Asia/Rangoon' => 6.30,
308 'Asia/Krasnoyarsk' => 7.00,
309 'Asia/Brunei' => 8.00,
310 'Asia/Seoul' => 9.00,
311 'Australia/Darwin' => 9.30,
312 'Australia/Canberra' => 10.00,
313 'Asia/Magadan' => 11.00,
314 'Pacific/Fiji' => 12.00,
315 'Pacific/Tongatapu' => 13.00
316 ];
317 $index = array_keys($zonelist, $offset);
318 if (1 !== count($index)) {
319 return false;
320 }
321 return $index[0];
322 }
323
324 public function _setupEnvironment()
325 {
326 parent::_setupEnvironment();
327
328 require_once XOOPS_ROOT_PATH.'/include/version.php';
329
330 require_once XOOPS_TRUST_PATH.'/settings/definition.inc.php';
331 define('XOOPS_LEGACY_PATH', XOOPS_MODULE_PATH.'/'.XOOPS_LEGACY_PROC_NAME);
332
333 require_once XOOPS_ROOT_PATH.'/include/functions.php';
334
335 require_once XOOPS_ROOT_PATH.'/kernel/object.php';
336 require_once XOOPS_ROOT_PATH.'/class/criteria.php';
337 require_once XOOPS_ROOT_PATH.'/class/token.php';
338 require_once XOOPS_ROOT_PATH.'/class/module.textsanitizer.php';
339
340 require_once XOOPS_LEGACY_PATH.'/kernel/object.php'; // ToDo (here?)
341 require_once XOOPS_LEGACY_PATH.'/kernel/handler.php'; // ToDo
342 require_once XOOPS_ROOT_PATH.'/core/XCube_Utils.class.php'; // ToDo
343
344 require_once XOOPS_ROOT_PATH.'/class/xoopssecurity.php';
345 $GLOBALS['xoopsSecurity'] = new XoopsSecurity();
346 }
347
361 public function _setupFilterChain()
362 {
363 $this->_mStrategy->_setupFilterChain();
364 }
365
366 public function _setupBlock()
367 {
368 $this->_mStrategy->setupBlock();
369 }
370
383 public function _processBlock()
384 {
385 $i=0;
386
391 $context =& $this->mRoot->mContext;
392
393 foreach ($this->_mBlockChain as $blockProcedure) {
394 //
395 // This is a flag indicating whether the controller needs to call
396 // the logic of the block.
397 //
398 $usedCacheFlag = false;
399
400 $cacheInfo = null;
401
402 if ($this->isEnableCacheFeature() && $blockProcedure->isEnableCache()) {
403 //
404 // Reset the block cache information structure, and initialize.
405 //
406 $cacheInfo =& $blockProcedure->createCacheInfo();
407
408 $this->mSetBlockCachePolicy->call(new XCube_Ref($cacheInfo));
409 $filepath = $cacheInfo->getCacheFilePath();
410
411 //
412 // If caching is enabled and the cache file exists, load and use it.
413 // Note : version 2.3.0
414 // @gigamaster added 'getTemplate' to link block in front theme
415 if ($cacheInfo->isEnableCache() && $this->existActiveCacheFile($filepath, $blockProcedure->getCacheTime())) {
416 $content = $this->loadCache($filepath);
417 if ($blockProcedure->isDisplay() && !empty($content)) {
418 $context->mAttributes['legacy_BlockShowFlags'][$blockProcedure->getEntryIndex()] = true;
419 $context->mAttributes['legacy_BlockContents'][$blockProcedure->getEntryIndex()][] = [
420 'id' => $blockProcedure->getId(),
421 'name' => $blockProcedure->getName(),
422 'title' => $blockProcedure->getTitle(),
423 'content' => $content,
424 'weight' => $blockProcedure->getWeight(),
425 'template' => $blockProcedure->getTemplate(),
426 ];
427 }
428
429 $usedCacheFlag = true;
430 }
431 }
432
433 if (!$usedCacheFlag) {
434 $blockProcedure->execute();
435
436 $renderBuffer = null;
437 if ($blockProcedure->isDisplay()) {
438 $renderBuffer =& $blockProcedure->getRenderTarget();
439 // Note : version 2.3.0
440 // @gigamaster added 'getTemplate' to link block in front theme
441 $context->mAttributes['legacy_BlockShowFlags'][$blockProcedure->getEntryIndex()] = true;
442 $context->mAttributes['legacy_BlockContents'][$blockProcedure->getEntryIndex()][] = [
443 'id' => $blockProcedure->getId(),
444 'name' => $blockProcedure->getName(),
445 'title' => $blockProcedure->getTitle(),
446 'content' => $renderBuffer->getResult(),
447 'weight' => $blockProcedure->getWeight(),
448 'template' => $blockProcedure->getTemplate(),
449 ];
450 } else {
451 //
452 // Dummy save
453 //
454 $renderBuffer = new XCube_RenderTarget();
455 }
456
457 if ($this->isEnableCacheFeature() && $blockProcedure->isEnableCache() && is_object($cacheInfo) && $cacheInfo->isEnableCache()) {
458 $this->cacheRenderTarget($cacheInfo->getCacheFilePath(), $renderBuffer);
459 }
460 }
461
462 unset($blockProcedure);
463 }
464 XCube_DelegateUtils::call('Legacy.SetupModuleContextSuccess', is_object($this->mRoot->mContext->mModule)? $this->mRoot->mContext->mModule->mXoopsModule : null);
465 }
466
467
468 public function _parseUrl()
469 {
470 $ret = [];
471 $rootPathInfo = @parse_url(XOOPS_URL);
472 $rootPath = ($rootPathInfo['path'] ?? '') . '/';
473 $php_info = xoops_getenv('PATH_INFO');
474 $requestPathInfo = @parse_url(!empty($php_info) ? substr(xoops_getenv('PHP_SELF'), 0, - strlen(xoops_getenv('PATH_INFO'))) : xoops_getenv('PHP_SELF'));
475
476 if (false === $requestPathInfo) {
477 die();
478 }
479
480 $requestPath = isset($requestPathInfo['path']) ? urldecode($requestPathInfo['path']) : '';
481 $subPath=substr($requestPath, strlen($rootPath));
482 $subPath = trim($subPath, '/');
483 $subPath = preg_replace('@/{2,}@', '/', $subPath);
484 // $ret = explode('/', $subPath);
485 // return $ret;
486 return explode('/', $subPath);
487 }
488
489
490 public function setupModuleContext($dirname = null)
491 {
492 if (null == $dirname) {
493 //
494 // Sets a module object.
495 //
496 $urlInfo = $this->_parseUrl();
497
498 if ((is_countable($urlInfo) ? count($urlInfo) : 0) >= 2) {
499 if ('modules' === strtolower($urlInfo[0])) {
500 $dirname = $urlInfo[1];
501 }
502 }
503 if ('admin.php' === substr($urlInfo[0], 0, 9)) {
504 $dirname = 'legacy';
505 }
506 }
507
508 if (null == $dirname) {
509 return;
510 }
511
512 if (!file_exists(XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . LEGACY_XOOPS_MODULE_MANIFESTO_FILENAME)) {
513 return;
514 }
515
516 $this->_mStrategy->setupModuleContext($this->mRoot->mContext, $dirname);
517
518 if (null !== $this->mRoot->mContext->mModule) {
519 $this->mRoot->mContext->setAttribute('legacy_pagetitle', $this->mRoot->mContext->mModule->mXoopsModule->get('name'));
520 }
521 }
522
523
524 public function _processModule()
525 {
526 if (null !== $this->mRoot->mContext->mModule) {
527 $module =& $this->mRoot->mContext->mModule;
528 if (!$module->isActive()) {
533 XCube_DelegateUtils::call('Legacy.Event.Exception.ModuleNotActive', $module);
534 $this->executeForward(XOOPS_URL . '/');
535 die();
536 }
537
538 if (!$this->_mStrategy->enableAccess()) {
539 XCube_DelegateUtils::call('Legacy.Event.Exception.ModuleSecurity', $module);
540 $this->executeRedirect(XOOPS_URL . '/user.php', 1, _NOPERM); // Depends on const message catalog.
541 die();
542 }
543
544 $this->_mStrategy->setupModuleLanguage();
545 $module->startup();
546
547 $GLOBALS['xoopsModule'] =& $module->mXoopsModule;
548 $GLOBALS['xoopsModuleConfig'] =& $module->mModuleConfig;
549 }
550
551 Legacy_Utils::raiseUserControlEvent();
552 }
553
554 // @todo change to refer settings ini file for HostAbstractLayer.
556 {
557 require_once XOOPS_ROOT_PATH.'/include/functions.php';
558
559 $path_translated = xoops_getenv('PATH_TRANSLATED');
560 $script_filename = xoops_getenv('SCRIPT_FILENAME');
561 $request_uri = xoops_getenv('REQUEST_URI');
562 if (!isset($path_translated) && isset($script_filename)) {
563 //
564 // @todo We have to confirm this.
565 // There is this setting for CGI mode.
566 //
567 $_SERVER['PATH_TRANSLATED'] =& $_SERVER['SCRIPT_FILENAME'];
568 } elseif (isset($path_translated) && !isset($script_filename)) {
569 // There is this setting for IIS Win2K. Really?
570 $_SERVER['SCRIPT_FILENAME'] =& $_SERVER['PATH_TRANSLATED'];
571 }
572
577 if (empty($request_uri)) {
578 $query_string = xoops_getenv('QUERY_STRING');
579 if (!($_SERVER['REQUEST_URI'] = xoops_getenv('PHP_SELF'))) {
580 $_SERVER['REQUEST_URI'] = xoops_getenv('SCRIPT_NAME');
581 }
582 if (isset($query_string)) {
583 $_SERVER['REQUEST_URI'] .= '?' . $query_string;
584 }
585
586 // Guard for XSS string of PHP_SELF
587 // @todo I must move this logic to preload plugin.
588 if (preg_match('/[<>\"\'\‍(\‍)]/', xoops_getenv('REQUEST_URI'))) {
589 die();
590 }
591 }
592
598 $GLOBALS['xoopsRequestUri'] = xoops_getenv('REQUEST_URI');
599 }
600
601 public function _setupUser()
602 {
603 parent::_setupUser();
604
605 // Set instance to global variable for compatibility with XOOPS2
606 $GLOBALS['xoopsUser'] =& $this->mRoot->mContext->mXoopsUser;
607 $GLOBALS['xoopsUserIsAdmin'] = is_object($this->mRoot->mContext->mXoopsUser) ? $this->mRoot->mContext->mXoopsUser->isAdmin(1) : false; // @todo Remove '1'?
608
609 //
610 // Set member handler to global variables for compatibility with XOOPS2
611 //
612 $GLOBALS['xoopsMemberHandler'] = xoops_gethandler('member');
613 $GLOBALS['member_handler'] =& $GLOBALS['xoopsMemberHandler'];
614 }
615
616 public function _setupErrorHandler()
617 {
618 }
619
624 public function _setupDB()
625 {
626 if (!defined('XOOPS_XMLRPC')) {
627 define('XOOPS_DB_CHKREF', 1);
628 } else {
629 define('XOOPS_DB_CHKREF', 0);
630 }
631
632 require_once XOOPS_ROOT_PATH.'/class/database/databasefactory.php';
633
634 if (true == $this->mRoot->getSiteConfig('Legacy', 'AllowDBProxy')) {
635 if ('POST' !== xoops_getenv('REQUEST_METHOD') || !xoops_refcheck(XOOPS_DB_CHKREF)) {
636 define('XOOPS_DB_PROXY', 1);
637 }
638 } elseif ('POST' !== xoops_getenv('REQUEST_METHOD')) {
639 define('XOOPS_DB_PROXY', 1);
640 }
641
643
644 $GLOBALS['xoopsDB']=&$this->mDB;
645 }
646
655 public function _setupLanguage()
656 {
657 require_once XOOPS_LEGACY_PATH.'/kernel/Legacy_LanguageManager.class.php';
658
659 $language = null;
660
661 $this->mGetLanguageName->call(new XCube_Ref($language));
662
663 if (null == $language) {
664 $handler = xoops_gethandler('config');
665 $criteria = new CriteriaCompo(new Criteria('conf_modid', 0));
666 $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
667 $criteria->add(new Criteria('conf_name', 'language'));
668 $configs =& $handler->getConfigs($criteria);
669
670 if ((is_countable($configs) ? count($configs) : 0) > 0) {
671 $language = $configs[0]->get('conf_value', 'none');
672 }
673 }
674
675 $this->mRoot->mLanguageManager =& $this->_createLanguageManager($language);
676 $this->mRoot->mLanguageManager->setLanguage($language);
677 $this->mRoot->mLanguageManager->prepare();
678
679 // If you use special page, load message catalog for it.
680 if (isset($GLOBALS['xoopsOption']['pagetype'])) {
681 $this->mRoot->mLanguageManager->loadPageTypeMessageCatalog($GLOBALS['xoopsOption']['pagetype']);
682 }
683 }
684
704 public function &_createLanguageManager($language)
705 {
706 require_once XOOPS_LEGACY_PATH . '/kernel/Legacy_LanguageManager.class.php';
707
708 $languageManager = null;
709
710 $this->mCreateLanguageManager->call(new XCube_Ref($languageManager), $language);
711
712 if (!is_object($languageManager)) {
713 $className = 'Legacy_LanguageManager_' . ucfirst(strtolower($language));
714
715 //
716 // If the class exists, create an instance. Else, load the file, and
717 // try creating an instance again.
718 //
719 if (XC_CLASS_EXISTS($className)) {
720 $languageManager = new $className();
721 } else {
722 $filePath = XOOPS_ROOT_PATH . '/language/' . $language . '/LanguageManager.class.php';
723 if (file_exists($filePath)) {
724 require_once $filePath;
725 }
726
727 if (XC_CLASS_EXISTS($className)) {
728 $languageManager = new $className();
729 } else {
730 //
731 // Default
732 //
733 $languageManager = new Legacy_LanguageManager();
734 }
735 }
736 }
737
738 return $languageManager;
739 }
740
741 public function _setupConfig()
742 {
743 $configHandler = xoops_gethandler('config');
744
745 $this->mRoot->mContext->mXoopsConfig =& $configHandler->getConfigsByCat(XOOPS_CONF);
746
747 $this->mRoot->mContext->mXoopsConfig['language'] = $this->mRoot->mLanguageManager->getLanguage();
748 $GLOBALS['xoopsConfig'] =& $this->mRoot->mContext->mXoopsConfig; // Compatibility for X2
749 $GLOBALS['config_handler'] =& $configHandler;
750 $GLOBALS['module_handler'] = xoops_gethandler('module');
751
752 if (0 == (is_countable($this->mRoot->mContext->mXoopsConfig) ? count($this->mRoot->mContext->mXoopsConfig) : 0)) {
753 return;
754 }
755
756 // @disable-parser-inspector
757 // Note: X-app themes must use Base System Render !
758 $this->mRoot->mContext->setThemeName($this->mRoot->mContext->mXoopsConfig['theme_set']);
759 $this->mRoot->mContext->setAttribute('legacy_sitename', $this->mRoot->mContext->mXoopsConfig['sitename']);
760 $this->mRoot->mContext->setAttribute('legacy_pagetitle', $this->mRoot->mContext->mXoopsConfig['slogan']);
761 $this->mRoot->mContext->setAttribute('legacy_slogan', $this->mRoot->mContext->mXoopsConfig['slogan']);
762 }
763
764 public function _setupScript()
765 {
766 require_once XOOPS_MODULE_PATH.'/legacy/class/Legacy_HeaderScript.class.php';
767 $headerScript = new Legacy_HeaderScript();
768 $this->mRoot->mContext->setAttribute('headerScript', $headerScript);
769 }
770
775 public function _setupDebugger()
776 {
777 // Commented out because suppressing errors here will not result in an error if the debugger setup fails.
778 // If the debugger setup succeeds, error_reporting is set to the value corresponding to the debug mode.
779 // error_reporting(0);
780
781 $debug_mode = $this->mRoot->mContext->mXoopsConfig['debug_mode'];
782 if (defined('XC_FORCE_DEBUG_PHP')) {
783 $debug_mode = XOOPS_DEBUG_PHP;
784 }
785
786 $this->mSetupDebugger->call(new XCube_Ref($this->mDebugger), $debug_mode);
787 $this->mDebugger && $this->mDebugger->prepare();
788
789 $GLOBALS['xoopsDebugger']=&$this->mDebugger;
790 }
791
792 public function _processPreBlockFilter()
793 {
794 $this->_mStrategy->_processPreBlockFilter();
795 parent::_processPreBlockFilter();
796 }
797
798 public function _processModulePreload($dirname)
799 {
800 //
801 // Auto pre-loading for Module.
802 //
803 if ($this->mRoot->getSiteConfig('Legacy', 'AutoPreload') == 1) {
804 if ($this->mActiveModules) {
805 $moduleObjects = $this->mActiveModules;
806 } else {
807 $moduleHandler = xoops_gethandler('module');
808 $criteria = new Criteria('isactive', 1);
809 $this->mActiveModules =
810 $moduleObjects =& $moduleHandler->getObjects($criteria);
811 }
812 foreach ($moduleObjects as $moduleObject) {
813 $mod_dir = $moduleObject->getVar('dirname');
814 $dir = XOOPS_ROOT_PATH . '/modules/' . $mod_dir . $dirname . '/';
815 if (is_dir($dir)) {
816 $files = glob($dir.'*.class.php');
817 if ($files) {
818 foreach ($files as $file) {
819 require_once $file;
820 $className = ucfirst($mod_dir) . '_' . basename($file, '.class.php');
821
822 if (XC_CLASS_EXISTS($className) && !isset($this->_mLoadedFilterNames[$className])) {
823 $instance = new $className($this);
824 $this->addActionFilter($instance);
825 unset($instance);
826 }
827 }
828 }
829 }
830 }
831 }
832 }
833
834 public function _setupSession()
835 {
836 parent::_setupSession();
837
838 $root =& XCube_Root::getSingleton();
839 $xoopsConfig = $root->mContext->mXoopsConfig;
840 if ($xoopsConfig['use_mysession']) {
841 $this->mRoot->mSession->setParam($xoopsConfig['session_name'], $xoopsConfig['session_expire']);
842 }
843 $this->mRoot->mSession->start();
844 }
845
846 protected function _loadInterfaceFiles()
847 {
848 $dir = XOOPS_MODULE_PATH.'/legacy/class/interface/';
849 $interfaces = glob($dir.'*.php');
850 foreach ($interfaces as $file) {
851 require_once($file);
852 }
853 }
854
855 public function executeHeader()
856 {
858 parent::executeHeader();
859
865
867 if (null !== $this->mRoot->mContext->mModule && $this->isEnableCacheFeature()) {
868 $cacheInfo =& $this->mRoot->mContext->mModule->createCacheInfo();
869
870 $this->mSetModuleCachePolicy->call($cacheInfo);
871
872 if ($this->mRoot->mContext->mModule->isEnableCache()) {
873
875 $xoopsModule =& $this->mRoot->mContext->mXoopsModule;
876
877 $cachetime = $this->mRoot->mContext->mXoopsConfig['module_cache'][$xoopsModule->get('mid')];
878 $filepath = $cacheInfo->getCacheFilePath();
879
884 if ($cacheInfo->isEnableCache() && $this->existActiveCacheFile($filepath, $cachetime)) {
885 $renderSystem =& $this->mRoot->getRenderSystem($this->mRoot->mContext->mModule->getRenderSystemName());
886 $renderTarget =& $renderSystem->createRenderTarget(XCUBE_RENDER_TARGET_TYPE_MAIN);
891 $renderCache = $this->loadCache($filepath);
892 $renderTarget->setResult($renderCache);
893
894 $this->_executeViewTheme($renderTarget);
895
896 exit();
897 }
898 }
899 }
900
901 ob_start();
902 }
903
904 public function executeView()
905 {
906 if (null !== $this->mRoot->mContext->mModule) {
907 $renderSystem =& $this->mRoot->getRenderSystem($this->mRoot->mContext->mModule->getRenderSystemName());
908 $renderTarget =& $this->mRoot->mContext->mModule->getRenderTarget();
909
910 /*
911 * Managing standard output buffering for the main render target is the responsibility of a controller.
912 * Of course, not all controllers are required to implement this.
913 * The following lines ensure the compatibility and functionality of this controller.
914 */
915
916 // Wmm...
917 if (is_object($renderTarget)) {
918 if (null == $renderTarget->getTemplateName()) {
919 if (isset($GLOBALS['xoopsOption']['template_main'])) {
920 $renderTarget->setTemplateName($GLOBALS['xoopsOption']['template_main']);
921 }
922 }
923
924 $renderTarget->setAttribute('stdout_buffer', ob_get_contents());
925 }
926
927 ob_end_clean();
928
929 if (is_object($renderTarget)) {
930 $renderSystem->render($renderTarget);
931
933 $module = $this->mRoot->mContext->mModule;
934 if ($this->isEnableCacheFeature() && $module->isEnableCache() && $module->mCacheInfo->isEnableCache()) {
935 $this->cacheRenderTarget($module->mCacheInfo->getCacheFilePath(), $renderTarget);
936 }
937 }
938 }
939
940 $this->_executeViewTheme($renderTarget);
941 }
942
947 public function _executeViewTheme(&$resultRenderTarget)
948 {
949
951 $theme =& $this->_mStrategy->getMainThemeObject();
952 if (!is_object($theme)) {
953 die('Could not found any compatible theme.');
954 }
955
956 $renderSystem =& $this->mRoot->getRenderSystem($theme->get('render_system'));
957 $screenTarget = $renderSystem->getThemeRenderTarget($this->mDialogMode);
958
959 if (is_object($resultRenderTarget)) {
960 $screenTarget->setAttribute('xoops_contents', $resultRenderTarget->getResult());
961 } else {
962 $screenTarget->setAttribute('xoops_contents', ob_get_contents());
963 ob_end_clean();
964 }
965
966 $screenTarget->setTemplateName($theme->get('dirname'));
967
968 //
969 // Rendering.
970 //
971 $renderSystem->render($screenTarget);
972
973 //
974 // Debug Process
975 //
976 $isAdmin=false;
977 if (is_object($this->mRoot->mContext->mXoopsUser)) {
978 if (null !== $this->mRoot->mContext->mModule && $this->mRoot->mContext->mModule->isActive()) {
979 // @todo depend on Legacy Module Controller.
980 $mid = $this->mRoot->mContext->mXoopsModule->getVar('mid');
981 } else {
982 $mid = 1;
983 }
984
985 $isAdmin = $this->mRoot->mContext->mXoopsUser->isAdmin($mid);
986 }
987
988 if ($isAdmin) {
989 $this->mDebugger->displayLog();
990 }
991 }
992
996 public function &_createDelegateManager()
997 {
998 $delegateManager =& parent::_createDelegateManager();
999
1000 $file = XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_EventFunctions.class.php';
1001
1002 $delegateManager->add('Legacypage.Notifications.Access', 'Legacy_EventFunction::notifications', $file);
1003 $delegateManager->add('Legacyfunction.Notifications.Select', 'Legacy_EventFunction::notifications_select', $file);
1004 $delegateManager->add('Legacypage.Search.Access', 'Legacy_EventFunction::search', $file);
1005 $delegateManager->add('Legacypage.Imagemanager.Access', 'Legacy_EventFunction::imageManager', $file);
1006 $delegateManager->add('Legacypage.Backend.Access', 'Legacy_EventFunction::backend', $file);
1007 $delegateManager->add('Legacypage.Misc.Access', 'Legacy_EventFunction::misc', $file);
1008 $delegateManager->add('User_UserViewAction.GetUserPosts', 'Legacy_EventFunction::recountPost', $file);
1009
1010 return $delegateManager;
1011 }
1012
1016 public function &_createServiceManager()
1017 {
1018 $serviceManager =& parent::_createServiceManager();
1019
1020 require_once XOOPS_ROOT_PATH . '/modules/legacy/service/LegacySearchService.class.php';
1021 $searchService = new Legacy_SearchService();
1022 $searchService->prepare();
1023
1024 $serviceManager->addService('LegacySearch', $searchService);
1025
1026 return $serviceManager;
1027 }
1028
1035 public function checkLogin()
1036 {
1037 if (!is_object($this->mRoot->mContext->mXoopsUser)) {
1038 $this->mCheckLogin->call(new XCube_Ref($this->mRoot->mContext->mXoopsUser));
1039
1040 $this->mRoot->mLanguageManager->loadModuleMessageCatalog('legacy');
1041
1042 if (is_object($this->mRoot->mContext->mXoopsUser)) {
1043 // If the current user doesn't belong to any groups, logout for XCL's security.
1044 $t_groups = $this->mRoot->mContext->mXoopsUser->getGroups();
1045 if (!is_array($t_groups)) {
1046 // exception
1047 $this->logout();
1048 return;
1049 } elseif (0 == count($t_groups)) {
1050 // exception, too
1051 $this->logout();
1052 return;
1053 }
1054
1055 // RMV-NOTIFY
1056 // Perform some maintenance of notification records
1057 $notification_handler = xoops_gethandler('notification');
1058 $notification_handler->doLoginMaintenance($this->mRoot->mContext->mXoopsUser->get('uid'));
1059
1060 XCube_DelegateUtils::call('Site.CheckLogin.Success', new XCube_Ref($this->mRoot->mContext->mXoopsUser));
1061
1062 //
1063 // Fall back process for login success.
1064 //
1065 $url = XOOPS_URL;
1066 if (!empty($_POST['xoops_redirect']) && !strpos(xoops_getrequest('xoops_redirect'), 'register')) {
1067 $parsed = parse_url(XOOPS_URL);
1068 $url = isset($parsed['scheme']) ? $parsed['scheme'].'://' : 'https://';
1069
1070 if (isset($parsed['host'])) {
1071 $url .= isset($parsed['port']) ? $parsed['host'] . ':' . $parsed['port'] . '/'.ltrim(trim(xoops_getrequest('xoops_redirect')), '/') : $parsed['host'] . '/'. ltrim(trim(xoops_getrequest('xoops_redirect')), '/');
1072 } else {
1073 $url .= xoops_getenv('HTTP_HOST') . '/'. ltrim(trim(xoops_getrequest('xoops_redirect')), '/');
1074 }
1075 }
1076
1077 $this->executeRedirect($url, 1, XCube_Utils::formatString(_MD_LEGACY_MESSAGE_LOGIN_SUCCESS, $this->mRoot->mContext->mXoopsUser->get('uname')));
1078 } else {
1079 XCube_DelegateUtils::call('Site.CheckLogin.Fail', new XCube_Ref($this->mRoot->mContext->mXoopsUser));
1080
1081 //
1082 // Fall back process for login fail.
1083 //
1084 $this->executeRedirect(XOOPS_URL . '/user.php', 1, _MD_LEGACY_ERROR_INCORRECTLOGIN);
1085 }
1086 } else {
1087 $this->executeForward(XOOPS_URL . '/');
1088 }
1089 }
1090
1096 public function logout()
1097 {
1098 $successFlag = false;
1099 $xoopsUser =& $this->mRoot->mContext->mXoopsUser;
1100
1101
1102 if (is_object($xoopsUser)) {
1103 $this->mRoot->mLanguageManager->loadModuleMessageCatalog('legacy');
1104
1105 $this->mLogout->call(new XCube_Ref($successFlag), $xoopsUser);
1106 if ($successFlag) {
1107 XCube_DelegateUtils::call('Site.Logout.Success', $xoopsUser);
1108 // @gigamaster join lang array, 'message' must be of the type string
1109 // $msg_array = [_MD_LEGACY_MESSAGE_LOGGEDOUT, _MD_LEGACY_MESSAGE_THANKYOUFORVISIT];
1110 // $msg_show = join('<br>', $msg_array);
1111 // $this->executeRedirect(XOOPS_URL . '/', 1, $msg_show);
1112 $this->executeRedirect(XOOPS_URL . '/', 1, [_MD_LEGACY_MESSAGE_LOGGEDOUT, _MD_LEGACY_MESSAGE_THANKYOUFORVISIT]);
1113 } else {
1114 XCube_DelegateUtils::call('Site.Logout.Fail', $xoopsUser);
1115 }
1116 } else {
1117 $this->executeForward(XOOPS_URL . '/');
1118 }
1119 }
1120
1126 public function switchStateCompulsory(&$strategy)
1127 {
1128 $this->setStrategy($strategy);
1129 }
1130
1139 public function setStrategy(&$strategy)
1140 {
1141 if ($strategy->mStatusFlag !== $this->_mStrategy->mStatusFlag) {
1142 $this->_mStrategy =& $strategy;
1143
1144 //
1145 // The following line depends on XCube_Controller process of executeCommon.
1146 // Note that there is only one method implemented in the default distribution.
1147 //
1148 $this->setupModuleContext();
1149 $this->_processModule();
1150 }
1151 }
1152
1159 public function setDialogMode($flag)
1160 {
1161 $this->mDialogMode = $flag;
1162 }
1163
1168 public function getDialogMode()
1169 {
1170 return $this->mDialogMode;
1171 }
1172
1181 public function &getVirtualCurrentModule()
1182 {
1183 $ret =& $this->_mStrategy->getVirtualCurrentModule();
1184 return $ret;
1185 }
1186
1201 public function executeRedirect($url, $time = 1, $message = null, $addRedirect = true)
1202 {
1203 global $xoopsConfig, $xoopsRequestUri;
1204
1205 //
1206 // Check the following by way of caution.
1207 //
1208 if (preg_match('/(javascript|vbscript):/si', $url)) {
1209 $url = XOOPS_URL;
1210 }
1211
1212 $displayMessage = '';
1213 if (is_array($message)) {
1214 foreach (array_keys($message) as $key) {
1215 $message[$key] = htmlspecialchars($message[$key], ENT_QUOTES);
1216 }
1217 $displayMessage = implode('<br>', $message);
1218 } else {
1219 $displayMessage = $message;
1220 }
1221
1222 $url = htmlspecialchars($url, ENT_QUOTES);
1223
1224 // @TODO test XOOPS2 Compatibility $addredirect = true
1225
1226 // TODO uncomment to test
1227 // $addRedirect = $addredirect = true;
1228
1229 if ($addRedirect && strpos($url, 'user.php') !== false) {
1230 $this->_mNotifyRedirectToUser->call(new XCube_Ref($url));
1231 }
1232
1233 if (defined('SID') && (! isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && '' !== $xoopsConfig['session_name'] && !isset($_COOKIE[$xoopsConfig['session_name']])))) {
1234 if (strpos($url, (string) XOOPS_URL) === 0) {
1235 if (strpos($url, '?') === false) {
1236 $connector = '?';
1237 } else {
1238 $connector = '&amp;';
1239 }
1240 if (strpos($url, '#') !== false) {
1241 $urlArray = explode('#', $url);
1242 $url = $urlArray[0] . $connector . SID;
1243 if (! empty($urlArray[1])) {
1244 $url .= '#' . $urlArray[1];
1245 }
1246 } else {
1247 $url .= $connector . SID;
1248 }
1249 }
1250 }
1251
1252 /* XCL 2.3.x
1253 * @gigamaster added theme_set, theme_url and theme_css (custom templates from theme)
1254 * also Render configs for X2 and D3 compatibility, refer to /class/template.php
1255 */
1256 $moduleHandler = xoops_gethandler('module');
1257 $legacyRender =& $moduleHandler->getByDirname('legacyRender');
1258 $configHandler = xoops_gethandler('config');
1259 $configs =& $configHandler->getConfigsByCat(0, $legacyRender->get('mid'));
1260
1261 if (!defined('XOOPS_CPFUNC_LOADED')) {
1262 require_once XOOPS_ROOT_PATH.'/class/template.php';
1263 $xoopsTpl = new XoopsTpl();
1264 $xoopsTpl->assign(
1265 [
1266 'xoops_sitename' =>htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
1267 'sitename' =>htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
1268 'theme_set' =>htmlspecialchars($xoopsConfig['theme_set'], ENT_QUOTES),
1269 'theme_url' =>XOOPS_THEME_URL . '/' . $xoopsConfig['theme_set'],
1270 'theme_css' =>getcss(),
1271 'langcode' =>_LANGCODE,
1272 'charset' =>_CHARSET,
1273 'time' =>$time,
1274 'url' =>$url,
1275 'message' =>$displayMessage,
1276 'logotype' =>$configs['logotype'],
1277 'favicon' =>$configs['favicon'],
1278 'lang_ifnotreload' =>sprintf(_IFNOTRELOAD, $url)
1279 ]
1280 );
1281 $GLOBALS['xoopsModuleUpdate'] = 1;
1282
1283 $xoopsTpl->display('db:system_redirect.html'); // Legacy compatibility
1284
1285 } else {
1286
1287 header('Content-Type:text/html; charset='._CHARSET);
1288 echo '
1289 <!DOCTYPE html>
1290 <head>
1291 <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title>
1292 <meta http-equiv="Content-Type" content="text/html; charset='._CHARSET.'">
1293 <{if !class_exists("AdelieDebug_Preload")}>
1294 <meta http-equiv="Refresh" content="'.$time.'; url='.$url.'">
1295 <{/if}>
1296 <link rel="stylesheet" href="<{$xoops_url}>/modules/legacy/admin/theme/style.css">
1297 <style>
1298 body {margin:2em;transition:background 500ms ease-in-out, color 200ms ease;}
1299
1300 .wrapper-require {
1301 align-content : center;
1302 display : flex;
1303 flex-direction : column;
1304 justify-content : center;
1305 min-height : 100vh;
1306 }
1307
1308 .wrapper-require > * {
1309 margin : 1em auto;
1310 }
1311 table {
1312 width: 100%;
1313 border-spacing: 1px;
1314 border-collapse: separate;
1315 }
1316 td {
1317 padding: 1em 2em;
1318 }
1319 .icon-package {
1320 margin-right : 1em; /* Space icon -> text */
1321 vertical-align : middle; /* Align icon and text */
1322 width : 1.5em; /* Size icon to text */
1323 }
1324
1325 </style>
1326
1327 </head>
1328 <body>
1329
1330 <div class="wrapper-redirect">
1331 <h2>Redirect</h2>
1332 <hr>
1333 <h4>'.$displayMessage.'</h4>
1334 <hr>
1335 <p>'.sprintf(_IFNOTRELOAD, $url).'</p>
1336 <hr>
1337 <{if class_exists("AdelieDebug_Preload")}>
1338 <p style="color:red;text-align: center">No automatic redirect during AdelieDebug execution.</p>
1339 <{/if}>
1340
1341 </div>
1342
1343 </body>
1344 </html>';
1345 }
1346
1347 exit();
1348 }
1349
1354 public function isEnableCacheFeature()
1355 {
1356 return $this->_mStrategy->isEnableCacheFeature();
1357 }
1358
1367 public function existActiveCacheFile($filepath, $cachetime)
1368 {
1369 if (0 == $cachetime) {
1370 return false;
1371 }
1372
1373 if (!file_exists($filepath)) {
1374 return false;
1375 }
1376
1377 return ((time() - filemtime($filepath)) <= $cachetime);
1378 }
1379
1386 public function cacheRenderTarget($filepath, &$renderTarget)
1387 {
1388 $fp = fopen($filepath, 'wb');
1389 if ($fp) {
1390 fwrite($fp, $renderTarget->getResult());
1391 fclose($fp);
1392 return true;
1393 }
1394
1395 return false;
1396 }
1397
1403 public function loadCache($filepath)
1404 {
1405 if (file_exists($filepath)) {
1406 return file_get_contents($filepath);
1407 }
1408
1409 return null;
1410 }
1411
1412 public function &_createContext()
1413 {
1414 require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_HttpContext.class.php';
1415
1416 $context = new Legacy_HttpContext();
1417 $request = new XCube_HttpRequest();
1418 $context->setRequest($request);
1419
1420 return $context;
1421 }
1422
1429 public function getPreferenceEditUrl(&$module)
1430 {
1431 if (is_object($module)) {
1432 return XOOPS_MODULE_URL . '/legacy/admin/index.php?action=PreferenceEdit&confmod_id=' . $module->get('mid');
1433 }
1434
1435 return null;
1436 }
1437
1444 public function getHelpViewUrl(&$module)
1445 {
1446 if (is_object($module)) {
1447 return XOOPS_MODULE_URL . '/legacy/admin/index.php?action=Help&dirname=' . $module->get('dirname');
1448 }
1449
1450 return null;
1451 }
1452}
1453
1458{
1462 public $mController = null;
1463
1464 public $mStatusFlag;
1465
1466 public array $_mLoadedFilterNames = [];
1467
1468 public function __construct(&$controller)
1469 {
1470 $this->mController =& $controller;
1471 }
1472
1473 public function _setupFilterChain()
1474 {
1475 $primaryPreloads = $this->mController->mRoot->getSiteConfig('Legacy.PrimaryPreloads');
1476 foreach ($primaryPreloads as $className => $classPath) {
1477 if (file_exists(XOOPS_ROOT_PATH . $classPath)) {
1478 require_once XOOPS_ROOT_PATH . $classPath;
1479 if (XC_CLASS_EXISTS($className) && !isset($this->_mLoadedFilterNames[$className])) {
1480 $this->_mLoadedFilterNames[$className] = true;
1481 $filter = new $className($this->mController);
1482 $this->mController->addActionFilter($filter);
1483 unset($filter);
1484 }
1485 }
1486 }
1487
1488 //
1489 // Auto pre-loading.
1490 //
1491 if (1 == $this->mController->mRoot->getSiteConfig('Legacy', 'AutoPreload')) {
1492 $this->mController->_processPreload(XOOPS_ROOT_PATH . '/preload');
1493 }
1494 }
1495
1505 public function setupModuleContext(&$context, $dirname)
1506 {
1507 $handler = xoops_gethandler('module');
1508 $module =& $handler->getByDirname($dirname);
1509
1510 if (!is_object($module)) {
1511 XCube_DelegateUtils::call('Legacy.Event.Exception.XoopsModuleNotFound', $dirname);
1512 $this->mController->executeRedirect(XOOPS_URL . '/', 1, 'You can\'t access this URL.'); // TODO need message catalog.
1513 die();
1514 }
1515
1516 $context->mModule =& Legacy_Utils::createModule($module);
1517 $context->mXoopsModule =& $context->mModule->getXoopsModule();
1518 $context->mModuleConfig = $context->mModule->getModuleConfig();
1519
1520 //
1521 // Load Roles
1522 //
1523 $this->mController->mRoot->mRoleManager->loadRolesByMid($context->mXoopsModule->get('mid'));
1524 }
1525
1526 public function setupBlock()
1527 {
1528 }
1529
1530 public function _processPreBlockFilter()
1531 {
1532 $this->mController->_processModulePreload('/preload');
1533 }
1534
1539 public function &getVirtualCurrentModule()
1540 {
1541 $ret = null;
1542 return $ret;
1543 }
1544
1548 public function isEnableCacheFeature()
1549 {
1550 }
1551
1556 public function enableAccess()
1557 {
1558 }
1559
1560 public function setupModuleLanguage()
1561 {
1562 }
1563}
_executeViewTheme(&$resultRenderTarget)
existActiveCacheFile($filepath, $cachetime)
executeCommonSubset(bool $connectdb=true)
cacheRenderTarget($filepath, &$renderTarget)
executeRedirect($url, $time=1, $message=null, $addRedirect=true)
[Secret Agreement] The context class for Legacy which extends to keep Legacy-module-specific informat...
executeForward(string $url, int $time=0, string $message=null)
[Final] Used for the simple mechanism for common delegation in XCube.
static formatString()
[Static] Formats string with special care for international.
static & getDatabaseConnection()
static & instance()
Definition logger.php:45