3 * Pixmicat! Module System
\r
5 * 增加掛載點供函式掛上並在需要時依序呼叫以動態改變內容或達成各種效果
\r
7 * @package PMCLibrary
\r
8 * @version $Id: pms.php 608 2008-03-04 12:44:27Z scribe $
\r
9 * @date $Date: 2008-03-04 20:44:27 +0800 (星期二, 04 三月 2008) $
\r
14 var $moduleInstance, $moduleLists;
\r
20 $this->loaded = false; // 是否載入完成 (模組及函式)
\r
21 $this->ENV = $ENV; // 環境變數
\r
22 $this->hooks = array_flip(array('Head', 'Toplink', 'LinksAboveBar', 'PostInfo', 'PostForm',
\r
23 'ThreadFront', 'ThreadRear', 'ThreadPost', 'ThreadReply',
\r
24 'Foot', 'ModulePage', 'RegistBegin', 'RegistBeforeCommit', 'RegistAfterCommit', 'PostOnDeletion',
\r
25 'AdminList', 'AdminFunction', 'Authenticate', 'ThreadOrder'
\r
27 $this->hookPoints = array(); // 掛載點
\r
28 $this->moduleInstance = array(); // 存放各模組實體
\r
29 $this->moduleLists = array(); // 存放各模組類別名稱
\r
35 $this->loaded = true;
\r
36 $this->loadModules();
\r
41 function onlyLoad($specificModule){
\r
42 // 搜尋載入模組列表有沒有,沒有就直接取消程式
\r
43 if(array_search($specificModule, $this->ENV['MODULE.LOADLIST'])===false) return false;
\r
44 $this->loadModules($specificModule);
\r
45 return isset($this->hookPoints['ModulePage']);
\r
49 function loadModules($specificModule=false){
\r
50 $loadlist = $specificModule ? array($specificModule) : $this->ENV['MODULE.LOADLIST'];
\r
51 foreach($loadlist as $f){
\r
52 $mpath = $this->ENV['MODULE.PATH'].$f.'.php';
\r
53 if(is_file($mpath) && array_search($f, $this->moduleLists)===false){
\r
54 include_once($mpath);
\r
55 $this->moduleLists[] = $f;
\r
56 $this->moduleInstance[$f] = new $f();
\r
62 function getLoadedModules(){
\r
63 if(!$this->loaded) $this->init();
\r
64 return $this->moduleLists;
\r
68 function getModuleInstance($module){
\r
69 return isset($this->moduleInstance[$module])?$this->moduleInstance[$module]:null;
\r
73 function getModuleMethods($module){
\r
74 if(!$this->loaded) $this->init();
\r
75 return array_search($module, $this->moduleLists)!==false ? get_class_methods($module) : array();
\r
80 function getModulePageURL($name){
\r
81 return $this->ENV['MODULE.PAGE'].$name;
\r
85 /* 自動掛載相關模組方法於掛載點並回傳掛載點 (Return by Reference) */
\r
86 function &__autoHookMethods($hookPoint){
\r
87 if(isset($this->hooks[$hookPoint]) && !isset($this->hookPoints[$hookPoint])){ // 尚未掛載
\r
88 $this->hookPoints[$hookPoint] = array();
\r
89 foreach($this->moduleLists as $m){
\r
90 if(method_exists($this->moduleInstance[$m], 'autoHook'.$hookPoint)){
\r
91 $this->hookModuleMethod($hookPoint, array(&$this->moduleInstance[$m], 'autoHook'.$hookPoint));
\r
95 return $this->hookPoints[$hookPoint];
\r
99 function hookModuleMethod($hookPoint, $methodObject){
\r
100 if(!isset($this->hooks[$hookPoint])) return false;
\r
101 if(!isset($this->hookPoints[$hookPoint]) && $hookPoint != 'ModulePage'){
\r
102 if(!$this->loaded) $this->init();
\r
103 $this->__autoHookMethods($hookPoint);
\r
105 $this->hookPoints[$hookPoint][] = $methodObject;
\r
109 function useModuleMethods($hookPoint, $parameter){
\r
110 if(!$this->loaded) $this->init();
\r
111 $arrMethod =& $this->__autoHookMethods($hookPoint); // 取得掛載點模組方法
\r
112 $imax = count($arrMethod);
\r
113 for($i = 0; $i < $imax; $i++) call_user_func_array($arrMethod[$i], $parameter);
\r