只是大致分析下執行流程,主要就是取得mod參數的值,根據取值加載控制器,控制器位置在最後一行指定了。
1 )定義應用名稱,加載兩個必要文件
define('APPTYPEID', 2); define('CURSCRIPT', 'forum'); require './source/class/class_core.php';//核心類 require './source/function/function_forum.php';//論壇函數庫
2 )modarray數組限定了mod取值范圍
$modarray = array('ajax','announcement','attachment','forumdisplay', 'group','image','index','medal','misc','modcp','notice','post','redirect', 'relatekw','relatethread','rss','topicadmin','trade','viewthread','tag','collection','guide' ); //模塊緩存列表,各個子數組分別表示各個模塊要緩存的緩存項 $modcachelist = array( 'index' => array('announcements', 'onlinelist', 'forumlinks', 'heats', 'historyposts', 'onlinerecord', 'userstats', 'diytemplatenameforum'), 'forumdisplay' => array('smilies', 'announcements_forum', 'globalstick', 'forums', 'onlinelist', 'forumstick', 'threadtable_info', 'threadtableids', 'stamps', 'diytemplatenameforum'), 'viewthread' => array('smilies', 'smileytypes', 'forums', 'usergroups', 'stamps', 'bbcodes', 'smilies', 'custominfo', 'groupicon', 'stamps', 'threadtableids', 'threadtable_info', 'posttable_info', 'diytemplatenameforum'), 'redirect' => array('threadtableids', 'threadtable_info', 'posttable_info'), 'post' => array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'domainwhitelist', 'albumcategory'), 'space' => array('fields_required', 'fields_optional', 'custominfo'), 'group' => array('grouptype', 'diytemplatenamegroup'), );
3 )如果mod參數為空或者不合法都會讓表達式為真,導致值為index
$mod = !in_array(C::app()->var['mod'], $modarray) ? 'index' : C::app()->var['mod'];
4 )做初始化
define('CURMODULE', $mod); //var_dump(CURMODULE); $cachelist = array(); if(isset($modcachelist[CURMODULE])) {//如果當前緩存項存在的話, $cachelist = $modcachelist[CURMODULE];//獲取當前緩存組的緩存列表項 $cachelist[] = 'plugin'; $cachelist[] = 'pluginlanguage_system'; } if(C::app()->var['mod'] == 'group') { $_G['basescript'] = 'group'; } C::app()->cachelist = $cachelist; C::app()->init();//初始化 loadforum(); set_rssauth(); runhooks();
5 )加載控制器
$navtitle = str_replace('{bbname}', $_G['setting']['bbname'], $_G['setting']['seotitle']['forum']); $_G['setting']['threadhidethreshold'] = 1; //var_dump($mod); require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';