想像到未來的插件可以不修改程程碼嗎?
這個只是花了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 编辑 ]