1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12: if (!defined('XOOPS_TRUST_PATH')){
13: echo 'XOOPS_TRUST_PATH is required after XOOPS Cube Legacy 2.2 in mainfile.php';exit();
14: }
15:
16: define('LEGACY_MODULE_VERSION', '2.2');
17:
18: define('LEGACY_CONTROLLER_STATE_PUBLIC', 1);
19: define('LEGACY_CONTROLLER_STATE_ADMIN', 2);
20:
21: define('LEGACY_XOOPS_MODULE_MANIFESTO_FILENAME', 'xoops_version.php');
22:
23: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_BlockProcedure.class.php';
24: require_once XOOPS_ROOT_PATH . '/modules/legacy/class/Legacy_Utils.class.php';
25: require_once XOOPS_ROOT_PATH . '/modules/legacy/class/Enum.class.php';
26: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_Identity.class.php';
27: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_RoleManager.class.php';
28:
29: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_CacheInformation.class.php';
30: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_PublicControllerStrategy.class.php';
31: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_TextFilter.class.php';
32: require_once XOOPS_ROOT_PATH . '/modules/legacy/class/Legacy_Debugger.class.php';
33:
34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46: class Legacy_Controller extends XCube_Controller
47: {
48: var $_mAdminModeFlag = false;
49: var $_mStrategy = null;
50:
51: var $mDialogMode = false;
52:
53: 54: 55:
56: var $mCheckLogin = null;
57:
58: 59: 60:
61: var $mLogout = null;
62:
63: 64: 65:
66: var $mCreateLanguageManager = null;
67:
68: 69: 70:
71: var $mSetBlockCachePolicy = null;
72:
73: 74: 75:
76: var $mActiveModules = null;
77:
78: 79: 80:
81: var $mSetModuleCachePolicy = null;
82:
83: 84: 85:
86: var $mGetLanguageName = null;
87:
88: 89: 90:
91: var $mSetupDebugger = null;
92:
93: 94: 95: 96: 97: 98:
99: var $_mNotifyRedirectToUser = null;
100:
101: 102: 103:
104: var $mLogger = null;
105:
106: function Legacy_Controller()
107: {
108: parent::XCube_Controller();
109:
110:
111:
112:
113: $this->mSetupUser->register('Legacy_Controller.SetupUser');
114:
115: $this->mCheckLogin =new XCube_Delegate();
116: $this->mCheckLogin->register('Site.CheckLogin');
117:
118: $this->mLogout =new XCube_Delegate();
119: $this->mLogout->register('Site.Logout');
120:
121: $this->mCreateLanguageManager = new XCube_Delegate();
122: $this->mCreateLanguageManager->register('Legacy_Controller.CreateLanguageManager');
123:
124: $this->mGetLanguageName = new XCube_Delegate();
125: $this->mGetLanguageName->register('Legacy_Controller.GetLanguageName');
126:
127: $this->mSetBlockCachePolicy = new XCube_Delegate();
128: $this->mSetModuleCachePolicy = new XCube_Delegate();
129:
130: $this->mSetupDebugger = new XCube_Delegate();
131: $this->mSetupDebugger->add('Legacy_DebuggerManager::createInstance');
132:
133: $this->mSetupTextFilter->add('Legacy_TextFilter::getInstance',XCUBE_DELEGATE_PRIORITY_FINAL-1);
134:
135: $this->_mNotifyRedirectToUser = new XCube_Delegate();
136: if(get_magic_quotes_runtime()) {
137: set_magic_quotes_runtime(0);
138: }
139: }
140:
141: function prepare(&$root)
142: {
143: parent::prepare($root);
144:
145:
146:
147:
148: $this->_processHostAbstractLayer();
149:
150: $urlInfo = $this->_parseUrl();
151:
152: $adminStateFlag = false;
153: if (count($urlInfo) >= 3) {
154: if (strtolower($urlInfo[0]) == 'modules') {
155: if (strtolower($urlInfo[2]) == 'admin') $adminStateFlag = true;
156: elseif ($urlInfo[1] == 'legacy' && $urlInfo[2] == 'include') $adminStateFlag = true;
157: elseif ($urlInfo[1] == 'system' && substr($urlInfo[2], 0, 9) == 'admin.php') $adminStateFlag = true;
158: }
159: } elseif (substr($urlInfo[0], 0, 9) == 'admin.php') $adminStateFlag = true;
160:
161: if ($adminStateFlag) {
162: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_AdminControllerStrategy.class.php';
163: $this->_mStrategy = new Legacy_AdminControllerStrategy($this);
164: }
165: else {
166: $this->_mStrategy = new Legacy_PublicControllerStrategy($this);
167: }
168: }
169:
170: 171: 172:
173: function executeCommon()
174: {
175:
176:
177:
178: $this->_setupFilterChain();
179: $this->_processFilter();
180:
181: if (!defined('OH_MY_GOD_HELP_ME')) {
182: error_reporting(0);
183: }
184:
185:
186: $this->_setupErrorHandler();
187:
188:
189: if(function_exists('date_default_timezone_set')){
190: date_default_timezone_set($this->_getLocalTimezone());
191: }
192:
193: $this->_setupEnvironment();
194:
195: $this->_setupLogger();
196:
197: $this->_setupDB();
198:
199: $this->_setupLanguage();
200:
201: $this->_setupTextFilter();
202:
203: $this->_setupConfig();
204:
205: $this->_setupScript();
206:
207: $this->_setupDebugger();
208:
209: $this->_loadInterfaceFiles();
210:
211: $this->_processPreBlockFilter();
212:
213: $this->_setupSession();
214:
215: $this->_setupUser();
216:
217: $this->setupModuleContext();
218:
219: $this->_processModule();
220:
221: $this->_processPostFilter();
222:
223: }
224:
225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235:
236: function executeCommonSubset($connectdb = true) {
237: $this->_setupErrorHandler();
238: $this->_setupEnvironment();
239: if ($connectdb) {
240: $this->_setupLogger();
241: $this->_setupDB();
242: }
243: }
244:
245: function _setupLogger()
246: {
247: require_once XOOPS_ROOT_PATH . '/class/logger.php';
248: $this->mLogger =& XoopsLogger::instance();
249: $this->mLogger->startTime();
250:
251: $GLOBALS['xoopsLogger'] =& $this->mLogger;
252: }
253:
254: function &getLogger()
255: {
256: return $this->mLogger;
257: }
258:
259: function _getLocalTimezone()
260: {
261: $iTime = time();
262: $arr = localtime($iTime);
263: $arr[5] += 1900;
264: $arr[4]++;
265: $iTztime = gmmktime($arr[2], $arr[1], $arr[0], $arr[4], $arr[3], $arr[5]);
266: $offset = doubleval(($iTztime-$iTime)/(60*60));
267: $zonelist =
268: array
269: (
270: 'Kwajalein' => -12.00,
271: 'Pacific/Midway' => -11.00,
272: 'Pacific/Honolulu' => -10.00,
273: 'America/Anchorage' => -9.00,
274: 'America/Los_Angeles' => -8.00,
275: 'America/Denver' => -7.00,
276: 'America/Tegucigalpa' => -6.00,
277: 'America/New_York' => -5.00,
278: 'America/Caracas' => -4.30,
279: 'America/Halifax' => -4.00,
280: 'America/St_Johns' => -3.30,
281: 'America/Argentina/Buenos_Aires' => -3.00,
282: 'America/Sao_Paulo' => -3.00,
283: 'Atlantic/South_Georgia' => -2.00,
284: 'Atlantic/Azores' => -1.00,
285: 'Europe/Dublin' => 0,
286: 'Europe/Belgrade' => 1.00,
287: 'Europe/Minsk' => 2.00,
288: 'Asia/Kuwait' => 3.00,
289: 'Asia/Tehran' => 3.30,
290: 'Asia/Muscat' => 4.00,
291: 'Asia/Yekaterinburg' => 5.00,
292: 'Asia/Kolkata' => 5.30,
293: 'Asia/Katmandu' => 5.45,
294: 'Asia/Dhaka' => 6.00,
295: 'Asia/Rangoon' => 6.30,
296: 'Asia/Krasnoyarsk' => 7.00,
297: 'Asia/Brunei' => 8.00,
298: 'Asia/Seoul' => 9.00,
299: 'Australia/Darwin' => 9.30,
300: 'Australia/Canberra' => 10.00,
301: 'Asia/Magadan' => 11.00,
302: 'Pacific/Fiji' => 12.00,
303: 'Pacific/Tongatapu' => 13.00
304: );
305: $index = array_keys($zonelist, $offset);
306: if(sizeof($index)!=1)
307: return false;
308: return $index[0];
309: }
310:
311: function _setupEnvironment()
312: {
313: parent::_setupEnvironment();
314: require_once XOOPS_ROOT_PATH.'/include/version.php';
315:
316: require_once XOOPS_TRUST_PATH.'/settings/definition.inc.php';
317: define('XOOPS_LEGACY_PATH',XOOPS_MODULE_PATH.'/'.XOOPS_LEGACY_PROC_NAME);
318:
319: require_once XOOPS_ROOT_PATH.'/include/functions.php';
320:
321: require_once XOOPS_ROOT_PATH.'/kernel/object.php';
322: require_once XOOPS_ROOT_PATH.'/class/criteria.php';
323: require_once XOOPS_ROOT_PATH.'/class/token.php';
324: require_once XOOPS_ROOT_PATH.'/class/module.textsanitizer.php';
325:
326: require_once XOOPS_LEGACY_PATH.'/kernel/object.php';
327: require_once XOOPS_LEGACY_PATH.'/kernel/handler.php';
328: require_once XOOPS_ROOT_PATH.'/core/XCube_Utils.class.php';
329:
330: require_once XOOPS_ROOT_PATH.'/class/xoopssecurity.php';
331: $GLOBALS['xoopsSecurity'] = new XoopsSecurity();
332: }
333:
334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347:
348: function _setupFilterChain()
349: {
350: $this->_mStrategy->_setupFilterChain();
351: }
352:
353: function _setupBlock()
354: {
355: $this->_mStrategy->setupBlock();
356: }
357:
358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368:
369: function _processBlock()
370: {
371: $i=0;
372:
373:
374:
375:
376:
377: $context =& $this->mRoot->mContext;
378:
379: foreach ($this->_mBlockChain as $blockProcedure) {
380:
381:
382:
383:
384: $usedCacheFlag = false;
385:
386: $cacheInfo = null;
387:
388: if ($this->isEnableCacheFeature() && $blockProcedure->isEnableCache()) {
389:
390:
391:
392: $cacheInfo =& $blockProcedure->createCacheInfo();
393:
394: $this->mSetBlockCachePolicy->call(new XCube_Ref($cacheInfo));
395: $filepath = $cacheInfo->getCacheFilePath();
396:
397:
398:
399:
400: if ($cacheInfo->isEnableCache() && $this->existActiveCacheFile($filepath, $blockProcedure->getCacheTime())) {
401: $content = $this->loadCache($filepath);
402: if ($blockProcedure->isDisplay() && !empty($content)) {
403: $context->mAttributes['legacy_BlockShowFlags'][$blockProcedure->getEntryIndex()] = true;
404: $context->mAttributes['legacy_BlockContents'][$blockProcedure->getEntryIndex()][] = array(
405: 'id' => $blockProcedure->getId(),
406: 'name' => $blockProcedure->getName(),
407: 'title' => $blockProcedure->getTitle(),
408: 'content' => $content,
409: 'weight' => $blockProcedure->getWeight()
410: );
411: }
412:
413: $usedCacheFlag = true;
414: }
415: }
416:
417: if (!$usedCacheFlag) {
418: $blockProcedure->execute();
419:
420: $renderBuffer = null;
421: if ($blockProcedure->isDisplay()) {
422: $renderBuffer =& $blockProcedure->getRenderTarget();
423:
424: $context->mAttributes['legacy_BlockShowFlags'][$blockProcedure->getEntryIndex()] = true;
425: $context->mAttributes['legacy_BlockContents'][$blockProcedure->getEntryIndex()][] = array(
426: 'name' => $blockProcedure->getName(),
427: 'title'=>$blockProcedure->getTitle(),
428: 'content'=>$renderBuffer->getResult(),
429: 'weight'=>$blockProcedure->getWeight(),
430: 'id' => $blockProcedure->getId(),
431: );
432: }
433: else {
434:
435:
436:
437: $renderBuffer = new XCube_RenderTarget();
438: }
439:
440: if ($this->isEnableCacheFeature() && $blockProcedure->isEnableCache() && is_object($cacheInfo) && $cacheInfo->isEnableCache()) {
441: $this->cacheRenderTarget($cacheInfo->getCacheFilePath(), $renderBuffer);
442: }
443: }
444:
445: unset($blockProcedure);
446: }
447: }
448:
449: function _parseUrl()
450: {
451: $ret = array();
452: $rootPathInfo = @parse_url(XOOPS_URL);
453: $rootPath = (isset($rootPathInfo['path']) ? $rootPathInfo['path'] : '') . '/';
454: $php_info = xoops_getenv('PATH_INFO');
455: $requestPathInfo = @parse_url(!empty($php_info) ? substr(xoops_getenv('PHP_SELF'),0,- strlen(xoops_getenv('PATH_INFO'))) : xoops_getenv('PHP_SELF'));
456:
457: if ($requestPathInfo === false) {
458: die();
459: }
460:
461: $requestPath = isset($requestPathInfo['path']) ? urldecode($requestPathInfo['path']) : '';
462: $subPath=substr($requestPath,strlen($rootPath));
463: $subPath = trim($subPath, '/');
464: $subPath = preg_replace('@/{2,}@', '/', $subPath);
465: $ret = explode('/', $subPath);
466: return $ret;
467: }
468:
469: function setupModuleContext($dirname = null)
470: {
471: if ($dirname == null) {
472:
473:
474:
475: $urlInfo = $this->_parseUrl();
476:
477: if (count($urlInfo) >= 2) {
478: if (strtolower($urlInfo[0]) == 'modules') {
479: $dirname = $urlInfo[1];
480: }
481: }
482: if (substr($urlInfo[0], 0, 9) == 'admin.php') {
483: $dirname = 'legacy';
484: }
485: }
486:
487: if ($dirname == null) {
488: return;
489: }
490:
491: if (!file_exists(XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . LEGACY_XOOPS_MODULE_MANIFESTO_FILENAME)) {
492: return;
493: }
494:
495: $this->_mStrategy->setupModuleContext($this->mRoot->mContext, $dirname);
496:
497: if ($this->mRoot->mContext->mModule != null) {
498: $this->mRoot->mContext->setAttribute('legacy_pagetitle', $this->mRoot->mContext->mModule->mXoopsModule->get('name'));
499: }
500: }
501:
502: function _processModule()
503: {
504: if ($this->mRoot->mContext->mModule != null) {
505: $module =& $this->mRoot->mContext->mModule;
506: if (!$module->isActive()) {
507: 508: 509: 510:
511: XCube_DelegateUtils::call('Legacy.Event.Exception.ModuleNotActive', $module);
512: $this->executeForward(XOOPS_URL . '/');
513: die();
514: }
515:
516: if (!$this->_mStrategy->enableAccess()) {
517: XCube_DelegateUtils::call('Legacy.Event.Exception.ModuleSecurity', $module);
518: $this->executeRedirect(XOOPS_URL . '/user.php', 1, _NOPERM);
519: die();
520: }
521:
522: $this->_mStrategy->setupModuleLanguage();
523: $module->startup();
524:
525: $GLOBALS['xoopsModule'] =& $module->mXoopsModule;
526: $GLOBALS['xoopsModuleConfig'] =& $module->mModuleConfig;
527: }
528:
529: Legacy_Utils::raiseUserControlEvent();
530: }
531:
532:
533: function _processHostAbstractLayer()
534: {
535: require_once XOOPS_ROOT_PATH.'/include/functions.php';
536:
537: $path_translated = xoops_getenv('PATH_TRANSLATED');
538: $script_filename = xoops_getenv('SCRIPT_FILENAME');
539: $request_uri = xoops_getenv('REQUEST_URI');
540: if ( !isset($path_translated) && isset($script_filename) ) {
541:
542: $_SERVER['PATH_TRANSLATED'] =& $_SERVER['SCRIPT_FILENAME'];
543: } elseif ( isset($path_translated) && !isset($script_filename) ) {
544:
545: $_SERVER['SCRIPT_FILENAME'] =& $_SERVER['PATH_TRANSLATED'];
546: }
547:
548:
549: if (empty($request_uri)) {
550: $query_string = xoops_getenv('QUERY_STRING');
551: if ( !( $_SERVER['REQUEST_URI'] = xoops_getenv('PHP_SELF'))) {
552: $_SERVER['REQUEST_URI'] = xoops_getenv('SCRIPT_NAME');
553: }
554: if (isset($query_string)) {
555: $_SERVER['REQUEST_URI'] .= '?' . $query_string;
556: }
557:
558:
559:
560: if(preg_match('/[\<\>\"\'\(\)]/',xoops_getenv('REQUEST_URI')))
561: die();
562: }
563:
564:
565: $GLOBALS['xoopsRequestUri'] = xoops_getenv('REQUEST_URI');
566: }
567:
568: function _setupUser()
569: {
570: parent::_setupUser();
571:
572:
573: $GLOBALS['xoopsUser'] =& $this->mRoot->mContext->mXoopsUser;
574: $GLOBALS['xoopsUserIsAdmin'] = is_object($this->mRoot->mContext->mXoopsUser) ? $this->mRoot->mContext->mXoopsUser->isAdmin(1) : false;
575:
576:
577:
578:
579: $GLOBALS['xoopsMemberHandler'] = xoops_gethandler('member');
580: $GLOBALS['member_handler'] =& $GLOBALS['xoopsMemberHandler'];
581: }
582:
583: function _setupErrorHandler()
584: {
585: }
586:
587: 588: 589: 590:
591: function _setupDB()
592: {
593: if(!defined('XOOPS_XMLRPC'))
594: define('XOOPS_DB_CHKREF', 1);
595: else
596: define('XOOPS_DB_CHKREF', 0);
597:
598: require_once XOOPS_ROOT_PATH.'/class/database/databasefactory.php';
599:
600: if ($this->mRoot->getSiteConfig('Legacy', 'AllowDBProxy') == true) {
601: if (xoops_getenv('REQUEST_METHOD') != 'POST' || !xoops_refcheck(XOOPS_DB_CHKREF)) {
602: define('XOOPS_DB_PROXY', 1);
603: }
604: }
605: elseif (xoops_getenv('REQUEST_METHOD') != 'POST') {
606: define('XOOPS_DB_PROXY', 1);
607: }
608:
609: $this->mDB =& XoopsDatabaseFactory::getDatabaseConnection();
610:
611: $GLOBALS['xoopsDB']=&$this->mDB;
612: }
613:
614: 615: 616: 617: 618: 619: 620: 621:
622: function _setupLanguage()
623: {
624: require_once XOOPS_LEGACY_PATH.'/kernel/Legacy_LanguageManager.class.php';
625:
626: $language = null;
627:
628: $this->mGetLanguageName->call(new XCube_Ref($language));
629:
630: if ($language == null) {
631: $handler = xoops_gethandler('config');
632: $criteria = new CriteriaCompo(new Criteria('conf_modid', 0));
633: $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
634: $criteria->add(new Criteria('conf_name', 'language'));
635: $configs =& $handler->getConfigs($criteria);
636:
637: if (count($configs) > 0) {
638: $language = $configs[0]->get('conf_value', 'none');
639: }
640: }
641:
642: $this->mRoot->mLanguageManager =& $this->_createLanguageManager($language);
643: $this->mRoot->mLanguageManager->setLanguage($language);
644: $this->mRoot->mLanguageManager->prepare();
645:
646:
647: if (isset($GLOBALS['xoopsOption']['pagetype'])) {
648: $this->mRoot->mLanguageManager->loadPageTypeMessageCatalog($GLOBALS['xoopsOption']['pagetype']);
649: }
650: }
651:
652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668:
669: function &_createLanguageManager($language)
670: {
671: require_once XOOPS_LEGACY_PATH . '/kernel/Legacy_LanguageManager.class.php';
672:
673: $languageManager = null;
674:
675: $this->mCreateLanguageManager->call(new XCube_Ref($languageManager), $language);
676:
677: if (!is_object($languageManager)) {
678: $className = 'Legacy_LanguageManager_' . ucfirst(strtolower($language));
679:
680:
681:
682:
683:
684: if (XC_CLASS_EXISTS($className)) {
685: $languageManager = new $className();
686: }
687: else {
688: $filePath = XOOPS_ROOT_PATH . '/language/' . $language . '/LanguageManager.class.php';
689: if (file_exists($filePath)) {
690: require_once $filePath;
691: }
692:
693: if (XC_CLASS_EXISTS($className)) {
694: $languageManager = new $className();
695: }
696: else {
697:
698:
699:
700: $languageManager = new Legacy_LanguageManager();
701: }
702: }
703: }
704:
705: return $languageManager;
706: }
707:
708: function _setupConfig()
709: {
710: $configHandler = xoops_gethandler('config');
711:
712: $this->mRoot->mContext->mXoopsConfig =& $configHandler->getConfigsByCat(XOOPS_CONF);
713:
714: $this->mRoot->mContext->mXoopsConfig['language'] = $this->mRoot->mLanguageManager->getLanguage();
715: $GLOBALS['xoopsConfig'] =& $this->mRoot->mContext->mXoopsConfig;
716: $GLOBALS['config_handler'] =& $configHandler;
717: $GLOBALS['module_handler'] = xoops_gethandler('module');
718:
719: if(count($this->mRoot->mContext->mXoopsConfig) == 0) {
720: return;
721: }
722:
723: $this->mRoot->mContext->setThemeName($this->mRoot->mContext->mXoopsConfig['theme_set']);
724:
725: $this->mRoot->mContext->setAttribute('legacy_sitename', $this->mRoot->mContext->mXoopsConfig['sitename']);
726: $this->mRoot->mContext->setAttribute('legacy_pagetitle', $this->mRoot->mContext->mXoopsConfig['slogan']);
727: $this->mRoot->mContext->setAttribute('legacy_slogan', $this->mRoot->mContext->mXoopsConfig['slogan']);
728: }
729:
730: function _setupScript()
731: {
732: require_once XOOPS_MODULE_PATH.'/legacy/class/Legacy_HeaderScript.class.php';
733: $headerScript = new Legacy_HeaderScript();
734: $this->mRoot->mContext->setAttribute('headerScript', $headerScript);
735: }
736:
737: 738: 739: 740:
741: function _setupDebugger()
742: {
743: error_reporting(0);
744:
745: $debug_mode = $this->mRoot->mContext->mXoopsConfig['debug_mode'];
746: if (defined('OH_MY_GOD_HELP_ME')) {
747: $debug_mode = XOOPS_DEBUG_PHP;
748: }
749:
750: $this->mSetupDebugger->call(new XCube_Ref($this->mDebugger), $debug_mode);
751: $this->mDebugger->prepare();
752:
753: $GLOBALS['xoopsDebugger']=&$this->mDebugger;
754: }
755:
756: function _processPreBlockFilter()
757: {
758: $this->_mStrategy->_processPreBlockFilter();
759: parent::_processPreBlockFilter();
760: }
761:
762: function _processModulePreload($dirname)
763: {
764:
765:
766:
767: if ($this->mRoot->getSiteConfig('Legacy', 'AutoPreload') == 1) {
768: if ($this->mActiveModules) $moduleObjects = $this->mActiveModules;
769: else {
770: $moduleHandler = xoops_gethandler('module');
771: $criteria = new Criteria('isactive', 1);
772: $this->mActiveModules =
773: $moduleObjects =& $moduleHandler->getObjects($criteria);
774: }
775: foreach ($moduleObjects as $moduleObject) {
776: $mod_dir = $moduleObject->getVar('dirname');
777: $dir = XOOPS_ROOT_PATH . '/modules/' . $mod_dir . $dirname . '/';
778: if(is_dir($dir)) {
779: $files = glob($dir.'*.class.php');
780: if ($files) {
781: foreach($files as $file) {
782: require_once $file;
783: $className = ucfirst($mod_dir) . '_' . basename($file, '.class.php');
784:
785: if (XC_CLASS_EXISTS($className) && !isset($this->_mLoadedFilterNames[$className])) {
786: $this->_mLoadedFilterNames[$className] = true;
787: $this->addActionFilter(new $className($this));
788: }
789: }
790: }
791: }
792: }
793: }
794: }
795:
796: function _setupSession()
797: {
798: parent::_setupSession();
799:
800: $root =& XCube_Root::getSingleton();
801: $xoopsConfig = $root->mContext->mXoopsConfig;
802: if ($xoopsConfig['use_mysession']) {
803: $this->mRoot->mSession->setParam($xoopsConfig['session_name'], $xoopsConfig['session_expire']);
804: }
805: $this->mRoot->mSession->start();
806: }
807:
808: protected function _loadInterfaceFiles()
809: {
810: $dir = XOOPS_MODULE_PATH.'/legacy/class/interface/';
811: $interfaces = glob($dir.'*.php');
812: foreach($interfaces as $file){
813: require_once($file);
814: }
815: }
816:
817: function executeHeader()
818: {
819:
820:
821:
822: parent::executeHeader();
823:
824:
825:
826:
827:
828:
829:
830:
831:
832:
833:
834: require_once XOOPS_ROOT_PATH.'/include/old_theme_functions.php';
835: $GLOBALS['xoopsTheme']['thename'] = $GLOBALS['xoopsConfig']['theme_set'];
836:
837:
838:
839:
840: if ($this->mRoot->mContext->mModule != null && $this->isEnableCacheFeature()) {
841: $cacheInfo =& $this->mRoot->mContext->mModule->createCacheInfo();
842:
843: $this->mSetModuleCachePolicy->call($cacheInfo);
844:
845: if ($this->mRoot->mContext->mModule->isEnableCache()) {
846:
847:
848:
849: $xoopsModule =& $this->mRoot->mContext->mXoopsModule;
850:
851: $cachetime = $this->mRoot->mContext->mXoopsConfig['module_cache'][$xoopsModule->get('mid')];
852: $filepath = $cacheInfo->getCacheFilePath();
853:
854:
855:
856:
857:
858: if ($cacheInfo->isEnableCache() && $this->existActiveCacheFile($filepath, $cachetime)) {
859: $renderSystem =& $this->mRoot->getRenderSystem($this->mRoot->mContext->mModule->getRenderSystemName());
860: $renderTarget =& $renderSystem->createRenderTarget(XCUBE_RENDER_TARGET_TYPE_MAIN);
861: $renderTarget->setResult($this->loadCache($filepath));
862:
863: $this->_executeViewTheme($renderTarget);
864:
865: exit();
866: }
867: }
868: }
869:
870: ob_start();
871: }
872:
873: function executeView()
874: {
875: if ($this->mRoot->mContext->mModule != null) {
876: $renderSystem =& $this->mRoot->getRenderSystem($this->mRoot->mContext->mModule->getRenderSystemName());
877: $renderTarget =& $this->mRoot->mContext->mModule->getRenderTarget();
878:
879:
880:
881:
882:
883:
884:
885:
886:
887: if (is_object($renderTarget)) {
888: if ($renderTarget->getTemplateName() == null) {
889: if (isset($GLOBALS['xoopsOption']['template_main'])) {
890: $renderTarget->setTemplateName($GLOBALS['xoopsOption']['template_main']);
891: }
892: }
893:
894: $renderTarget->setAttribute('stdout_buffer', ob_get_contents());
895: }
896:
897: ob_end_clean();
898:
899: if (is_object($renderTarget)) {
900: $renderSystem->render($renderTarget);
901:
902:
903:
904:
905: $module = $this->mRoot->mContext->mModule;
906: if ($this->isEnableCacheFeature() && $module->isEnableCache() && $module->mCacheInfo->isEnableCache()) {
907: $this->cacheRenderTarget($module->mCacheInfo->getCacheFilePath(), $renderTarget);
908: }
909: }
910: }
911:
912: $this->_executeViewTheme($renderTarget);
913: }
914:
915: 916: 917:
918: function _executeViewTheme(&$resultRenderTarget)
919: {
920:
921:
922:
923: $theme =& $this->_mStrategy->getMainThemeObject();
924: if (!is_object($theme)) {
925: die('Could not found any themes.');
926: }
927:
928: $renderSystem =& $this->mRoot->getRenderSystem($theme->get('render_system'));
929: $screenTarget = $renderSystem->getThemeRenderTarget($this->mDialogMode);
930:
931: if (is_object($resultRenderTarget)) {
932: $screenTarget->setAttribute('xoops_contents', $resultRenderTarget->getResult());
933: }
934:
935: $screenTarget->setTemplateName($theme->get('dirname'));
936:
937:
938:
939:
940: $renderSystem->render($screenTarget);
941:
942:
943:
944:
945: $isAdmin=false;
946: if(is_object($this->mRoot->mContext->mXoopsUser)) {
947: if($this->mRoot->mContext->mModule != null && $this->mRoot->mContext->mModule->isActive()) {
948:
949: $mid = $this->mRoot->mContext->mXoopsModule->getVar('mid');
950: }
951: else {
952: $mid = 1;
953: }
954:
955: $isAdmin = $this->mRoot->mContext->mXoopsUser->isAdmin($mid);
956: }
957:
958: if ($isAdmin) {
959: $this->mDebugger->displayLog();
960: }
961: }
962:
963: function &_createDelegateManager()
964: {
965: $delegateManager =& parent::_createDelegateManager();
966:
967: $file = XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_EventFunctions.class.php';
968:
969: $delegateManager->add('Legacypage.Notifications.Access', 'Legacy_EventFunction::notifications', $file);
970: $delegateManager->add('Legacyfunction.Notifications.Select', 'Legacy_EventFunction::notifications_select', $file);
971: $delegateManager->add('Legacypage.Search.Access', 'Legacy_EventFunction::search', $file);
972: $delegateManager->add('Legacypage.Imagemanager.Access', 'Legacy_EventFunction::imageManager', $file);
973: $delegateManager->add('Legacypage.Backend.Access', 'Legacy_EventFunction::backend', $file);
974: $delegateManager->add('Legacypage.Misc.Access', 'Legacy_EventFunction::misc', $file);
975: $delegateManager->add('User_UserViewAction.GetUserPosts', 'Legacy_EventFunction::recountPost', $file);
976:
977: return $delegateManager;
978: }
979:
980: function &_createServiceManager()
981: {
982: $serviceManager =& parent::_createServiceManager();
983:
984: require_once XOOPS_ROOT_PATH . '/modules/legacy/service/LegacySearchService.class.php';
985: $searchService = new Legacy_SearchService();
986: $searchService->prepare();
987:
988: $serviceManager->addService('LegacySearch', $searchService);
989:
990: return $serviceManager;
991: }
992:
993: 994: 995: 996: 997: 998:
999: function checkLogin()
1000: {
1001: if (!is_object($this->mRoot->mContext->mXoopsUser)) {
1002: $this->mCheckLogin->call(new XCube_Ref($this->mRoot->mContext->mXoopsUser));
1003:
1004: $this->mRoot->mLanguageManager->loadModuleMessageCatalog('legacy');
1005:
1006: if (is_object($this->mRoot->mContext->mXoopsUser)) {
1007:
1008: $t_groups =& $this->mRoot->mContext->mXoopsUser->getGroups();
1009: if (!is_array($t_groups)) {
1010:
1011: $this->logout();
1012: return;
1013: }
1014: else if (count($t_groups) == 0) {
1015:
1016: $this->logout();
1017: return;
1018: }
1019:
1020:
1021:
1022: $notification_handler = xoops_gethandler('notification');
1023: $notification_handler->doLoginMaintenance($this->mRoot->mContext->mXoopsUser->get('uid'));
1024:
1025: XCube_DelegateUtils::call('Site.CheckLogin.Success', new XCube_Ref($this->mRoot->mContext->mXoopsUser));
1026:
1027:
1028:
1029:
1030: $url = XOOPS_URL;
1031: if (!empty($_POST['xoops_redirect']) && !strpos(xoops_getrequest('xoops_redirect'), 'register')) {
1032: $parsed = parse_url(XOOPS_URL);
1033: $url = isset($parsed['scheme']) ? $parsed['scheme'].'://' : 'http://';
1034:
1035: if (isset($parsed['host'])) {
1036: $url .= isset($parsed['port']) ? $parsed['host'] . ':' . $parsed['port'] . trim(xoops_getrequest('xoops_redirect')): $parsed['host'] . trim(xoops_getrequest('xoops_redirect'));
1037: } else {
1038: $url .= xoops_getenv('HTTP_HOST') . trim(xoops_getrequest('xoops_redirect'));
1039: }
1040: }
1041:
1042: $this->executeRedirect($url, 1, XCube_Utils::formatMessage(_MD_LEGACY_MESSAGE_LOGIN_SUCCESS, $this->mRoot->mContext->mXoopsUser->get('uname')));
1043: }
1044: else {
1045: XCube_DelegateUtils::call('Site.CheckLogin.Fail', new XCube_Ref($this->mRoot->mContext->mXoopsUser));
1046:
1047:
1048:
1049:
1050: $this->executeRedirect(XOOPS_URL . '/user.php', 1, _MD_LEGACY_ERROR_INCORRECTLOGIN);
1051: }
1052: }
1053: else {
1054: $this->executeForward(XOOPS_URL . '/');
1055: }
1056: }
1057:
1058: 1059: 1060: 1061: 1062:
1063: function logout()
1064: {
1065: $successFlag = false;
1066: $xoopsUser =& $this->mRoot->mContext->mXoopsUser;
1067:
1068:
1069: if (is_object($xoopsUser)) {
1070: $this->mRoot->mLanguageManager->loadModuleMessageCatalog('legacy');
1071:
1072: $this->mLogout->call(new XCube_Ref($successFlag), $xoopsUser);
1073: if ($successFlag) {
1074: XCube_DelegateUtils::call('Site.Logout.Success', $xoopsUser);
1075: $this->executeRedirect(XOOPS_URL . '/', 1, array(_MD_LEGACY_MESSAGE_LOGGEDOUT, _MD_LEGACY_MESSAGE_THANKYOUFORVISIT));
1076: }
1077: else {
1078: XCube_DelegateUtils::call('Site.Logout.Fail', $xoopsUser);
1079: }
1080: }
1081: else {
1082: $this->executeForward(XOOPS_URL . '/');
1083: }
1084: }
1085:
1086: 1087: 1088: 1089:
1090: function switchStateCompulsory(&$strategy)
1091: {
1092: $this->setStrategy($strategy);
1093: }
1094:
1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102:
1103: function setStrategy(&$strategy)
1104: {
1105: if ($strategy->mStatusFlag != $this->_mStrategy->mStatusFlag) {
1106: $this->_mStrategy =& $strategy;
1107:
1108:
1109:
1110:
1111:
1112: $this->setupModuleContext();
1113: $this->_processModule();
1114: }
1115: }
1116:
1117: 1118: 1119: 1120: 1121: 1122:
1123: function setDialogMode($flag)
1124: {
1125: $this->mDialogMode = $flag;
1126: }
1127:
1128: 1129: 1130: 1131:
1132: function getDialogMode()
1133: {
1134: return $this->mDialogMode;
1135: }
1136:
1137: 1138: 1139: 1140: 1141: 1142: 1143:
1144: function &getVirtualCurrentModule()
1145: {
1146: $ret =& $this->_mStrategy->getVirtualCurrentModule();
1147: return $ret;
1148: }
1149:
1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164:
1165: function executeRedirect($url, $time = 1, $message = null, $addRedirect = true)
1166: {
1167: global $xoopsConfig, $xoopsRequestUri;
1168:
1169:
1170:
1171:
1172: if (preg_match('/(javascript|vbscript):/si', $url)) {
1173: $url = XOOPS_URL;
1174: }
1175:
1176: $displayMessage = '';
1177: if (is_array($message)) {
1178: foreach (array_keys($message) as $key) {
1179: $message[$key] = htmlspecialchars($message[$key], ENT_QUOTES);
1180: }
1181: $displayMessage = implode('<br/>', $message);
1182: }
1183: else {
1184: $displayMessage = $message;
1185: }
1186:
1187: $url = htmlspecialchars($url, ENT_QUOTES);
1188:
1189:
1190: if ($addRedirect && strstr($url, 'user.php')) {
1191: $this->_mNotifyRedirectToUser->call(new XCube_Ref($url));
1192: }
1193:
1194: if (defined('SID') && (! isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']])))) {
1195: if ( strpos($url, XOOPS_URL) === 0 ) {
1196: if (!strstr($url, '?')) {
1197: $connector = '?';
1198: }
1199: else {
1200: $connector = '&';
1201: }
1202: if (strstr($url, '#')) {
1203: $urlArray = explode( '#', $url );
1204: $url = $urlArray[0] . $connector . SID;
1205: if ( ! empty($urlArray[1]) ) {
1206: $url .= '#' . $urlArray[1];
1207: }
1208: }
1209: else {
1210: $url .= $connector . SID;
1211: }
1212: }
1213: }
1214:
1215: if (!defined('XOOPS_CPFUNC_LOADED')) {
1216: require_once XOOPS_ROOT_PATH.'/class/template.php';
1217: $xoopsTpl = new XoopsTpl();
1218: $xoopsTpl->assign(array('xoops_sitename'=>htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
1219: 'sitename'=>htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
1220: 'langcode'=>_LANGCODE, 'charset'=>_CHARSET,
1221: 'time'=>$time, 'url'=>$url,
1222: 'message'=>$displayMessage,
1223: 'lang_ifnotreload'=>sprintf(_IFNOTRELOAD, $url)));
1224: $GLOBALS['xoopsModuleUpdate'] = 1;
1225: $xoopsTpl->display('db:system_redirect.html');
1226: } else {
1227: header('Content-Type:text/html; charset='._CHARSET);
1228: echo '
1229: <html>
1230: <head>
1231: <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title>
1232: <meta http-equiv="Content-Type" content="text/html; charset='._CHARSET.'" />
1233: <meta http-equiv="Refresh" content="'.$time.'; url='.$url.'" />
1234: <style type="text/css">
1235: body {background-color : #fcfcfc; font-size: 12px; font-family: Trebuchet MS,Verdana, Arial, Helvetica, sans-serif; margin: 0px;}
1236: .redirect {width: 70%; margin: 110px; text-align: center; padding: 15px; border: #e0e0e0 1px solid; color: #666666; background-color: #f6f6f6;}
1237: .redirect a:link {color: #666666; text-decoration: none; font-weight: bold;}
1238: .redirect a:visited {color: #666666; text-decoration: none; font-weight: bold;}
1239: .redirect a:hover {color: #999999; text-decoration: underline; font-weight: bold;}
1240: </style>
1241: </head>
1242: <body>
1243: <div align="center">
1244: <div class="redirect">
1245: <span style="font-size: 16px; font-weight: bold;">'.$displayMessage.'</span>
1246: <hr style="height: 3px; border: 3px #E18A00 solid; width: 95%;" />
1247: <p>'.sprintf(_IFNOTRELOAD, $url).'</p>
1248: </div>
1249: </div>
1250: </body>
1251: </html>';
1252: }
1253:
1254: exit();
1255: }
1256:
1257: 1258: 1259: 1260:
1261: function isEnableCacheFeature()
1262: {
1263: return $this->_mStrategy->isEnableCacheFeature();
1264: }
1265:
1266: 1267: 1268: 1269: 1270: 1271: 1272: 1273:
1274: function existActiveCacheFile($filepath, $cachetime)
1275: {
1276: if ($cachetime == 0) {
1277: return false;
1278: }
1279:
1280: if (!file_exists($filepath)) {
1281: return false;
1282: }
1283:
1284: return ((time() - filemtime($filepath)) <= $cachetime);
1285: }
1286:
1287: 1288: 1289: 1290: 1291: 1292:
1293: function cacheRenderTarget($filepath, &$renderTarget)
1294: {
1295: $fp = fopen($filepath, 'wb');
1296: if ($fp) {
1297: fwrite($fp, $renderTarget->getResult());
1298: fclose($fp);
1299: return true;
1300: }
1301:
1302: return false;
1303: }
1304:
1305: 1306: 1307: 1308:
1309: function loadCache($filepath)
1310: {
1311: if (file_exists($filepath)) {
1312: return file_get_contents($filepath);
1313: }
1314:
1315: return null;
1316: }
1317:
1318: function &_createContext()
1319: {
1320: require_once XOOPS_ROOT_PATH . '/modules/legacy/kernel/Legacy_HttpContext.class.php';
1321:
1322: $context = new Legacy_HttpContext();
1323: $request = new XCube_HttpRequest();
1324: $context->setRequest($request);
1325:
1326: return $context;
1327: }
1328:
1329: 1330: 1331: 1332: 1333: 1334:
1335: function getPreferenceEditUrl(&$module)
1336: {
1337: if (is_object($module)) {
1338: return XOOPS_MODULE_URL . '/legacy/admin/index.php?action=PreferenceEdit&confmod_id=' . $module->get('mid');
1339: }
1340:
1341: return null;
1342: }
1343:
1344: 1345: 1346: 1347: 1348: 1349:
1350: function getHelpViewUrl(&$module)
1351: {
1352: if (is_object($module)) {
1353: return XOOPS_MODULE_URL . '/legacy/admin/index.php?action=Help&dirname=' . $module->get('dirname');
1354: }
1355:
1356: return null;
1357: }
1358: }
1359:
1360: 1361: 1362:
1363: class Legacy_AbstractControllerStrategy
1364: {
1365: 1366: 1367:
1368: var $mController = null;
1369:
1370: var $mStatusFlag;
1371:
1372: function Legacy_AbstractControllerStrategy(&$controller)
1373: {
1374: $this->mController =& $controller;
1375: }
1376:
1377: function _setupFilterChain()
1378: {
1379: $primaryPreloads = $this->mController->mRoot->getSiteConfig('Legacy.PrimaryPreloads');
1380: foreach ($primaryPreloads as $className => $classPath) {
1381: if (file_exists(XOOPS_ROOT_PATH . $classPath)) {
1382: require_once XOOPS_ROOT_PATH . $classPath;
1383: if (XC_CLASS_EXISTS($className) && !isset($this->_mLoadedFilterNames[$className])) {
1384: $this->_mLoadedFilterNames[$className] = true;
1385: $filter = new $className($this->mController);
1386: $this->mController->addActionFilter($filter);
1387: unset($filter);
1388: }
1389: }
1390: }
1391:
1392:
1393:
1394:
1395: if($this->mController->mRoot->getSiteConfig('Legacy', 'AutoPreload') == 1) {
1396: $this->mController->_processPreload(XOOPS_ROOT_PATH . '/preload');
1397: }
1398: }
1399:
1400: 1401: 1402: 1403: 1404: 1405: 1406: 1407: 1408:
1409: function setupModuleContext(&$context, $dirname)
1410: {
1411: $handler = xoops_gethandler('module');
1412: $module =& $handler->getByDirname($dirname);
1413:
1414: if (!is_object($module)) {
1415: XCube_DelegateUtils::call('Legacy.Event.Exception.XoopsModuleNotFound', $dirname);
1416: $this->mController->executeRedirect(XOOPS_URL . '/', 1, 'You can\'t access this URL.');
1417: die();
1418: }
1419:
1420: $context->mModule =& Legacy_Utils::createModule($module);
1421: $context->mXoopsModule =& $context->mModule->getXoopsModule();
1422: $context->mModuleConfig = $context->mModule->getModuleConfig();
1423:
1424:
1425:
1426:
1427: $this->mController->mRoot->mRoleManager->loadRolesByMid($context->mXoopsModule->get('mid'));
1428: }
1429:
1430: function setupBlock()
1431: {
1432: }
1433:
1434: function _processPreBlockFilter()
1435: {
1436: $this->mController->_processModulePreload('/preload');
1437: }
1438:
1439: 1440: 1441: 1442:
1443: function &getVirtualCurrentModule()
1444: {
1445: $ret = null;
1446: return $ret;
1447: }
1448:
1449: 1450: 1451:
1452: function isEnableCacheFeature()
1453: {
1454: }
1455:
1456: 1457: 1458: 1459:
1460: function enableAccess()
1461: {
1462: }
1463:
1464: function setupModuleLanguage()
1465: {
1466: }
1467: }
1468: ?>
1469: