发新话题
打印

[FOR DEV ONLY] ACTIVEPLUGINS

[FOR DEV ONLY] ACTIVEPLUGINS

想像到未來的插件可以不修改程程碼嗎?
這個只是花了15分鐘所制的核心


include/common.inc.php

require_once DISCUZ_ROOT.'./include/db_'.$database.'.class.php';
下加
require_once DISCUZ_ROOT.'./include/event.class.php';
$Event = new Event;


?>
下加
$Event->eventRun('COMMON_START');


register.php

include_once DISCUZ_ROOT.'./forumdata/cache/cache_bbcodes.php';
下加
$Event->eventRun('REG_CHECK');


updatesettings();
下加
$Event->eventRun('REG_OK');






include/event.class.php
复制内容到剪贴板
代码:
<?php

/*
        ActivePlugins For  Discuz Lite !, by fukid@styhk
        http://siulok.com/

        $RCSfile: event.class.php,v $
        $Date: 6/2/2007 20:04:34 $
*/

class Event {
        var $_eventsdir = '../pplugins';
        var $_events = array(        'COMMON_START' => array(),        #At the end of the common.inc.php
                                                        'REG_CHECK' => array(),                #when submited the reg
                                                        'REG_OK' => array(),                #when register finished
                                                        );
        function PluginLoad($name) {
                if ($name == '') return;
                foreach ($name as $entry){
                        if (file_exists("$this->_eventsdir/$name.php")){
                                if (!class_exists("$name")){
                                        include("$this->_eventsdir/$name.php");
                                        if (class_exists("$name")){
                                                global $$name;
                                                $$name = new $name;
                                        }
                                }
                        }
                }
        }
        function eventAdd($type, $func) {
                $this->_events[$type][] = $func;
        }
        function eventRun($type, $args='') {
                foreach ($this->_events[$type] as $key => $event){
                        @call_user_func($event, $args);
                }
        }
        function eventRemove($type, $func){
                $index = array_search($func, $this->_events[$type]);
                unset($this->_events[$type][$index]);
        }
}

?>
如何使用?

比如你想在每次COMMON.PHP 最尾也跑 function名為’checkuser’
你只要在你的plugins php內加上  eventAdd(’COMMON_START’, ’checkuser’);
完全不用修改common.php



msn:fukid@siulok.com

[ 本帖最后由 fukid2 于 2007-2-6 08:11 PM 编辑 ]
本帖最近评分记录
  • CS1.3 威望 +3 看起来不错的样子` 2007-2-7 01:29
  • CS1.3 金币 +6 看起来不错的样子` 2007-2-7 01:29

TOP

只适用于添加式修改

TOP

引用:
原帖由 Ling. 于 2007-2-6 09:40 PM 发表。
只适用于添加式修改
可不是喔   

如果把discuz 的代碼改為由event控制,  就可以通過 eventremove 和 eventadd就達到無需修改

TOP

要修改的地方太多
而且这样做影响效率。

TOP

PHP5似乎是有委托,你用哪个去做吧。

TOP

委托? 請問英文是..?

TOP

delegate
要么是PHP5要么是6
你这么太累了

TOP

不过类似的实现都很影响效率的。

TOP

发新话题