📄 plugin.class.php
字号:
<?
/*
+--------------------------------------------------------------------------
| Mega File Hosting Script v1.2
| ========================================
| by Stephen Yabziz
| (c) 2005-2006 YABSoft Services
| http://www.yabsoft.com
| ========================================
| Web: http://www.yabsoft.com
| Email: ywyhnchina@163.com
+--------------------------------------------------------------------------
|
| > Script written by Stephen Yabziz
| > Date started: 1th March 2006
+--------------------------------------------------------------------------
*/
/**
* Works the vBulletin Plugin Hook System
*
* @package vBulletin
* @version $Revision: 1.23 $
* @author Kier & Mike
* @checkedout $Name: $
* @date $Date: 2006/05/29 15:52:02 $
* @copyright http://www.vbulletin.com/license.html
*
*/
class YABPlugin
{
/**
* This holds the plugin data
*
* @var array
*/
var $hooks = array();
/**
* Constructor - unserializes the plugin data from the datastore when class is initiated
*
* @return none
*/
function YABPlugin()
{
}
/**
* Singleton emulation - use this function to instantiate the class
*
* @return vBulletinHook
*/
function &init()
{
static $instance;
if (!$instance)
{
$instance = new YABPlugin();
}
return $instance;
}
/**
* Sets the plugin list array
*/
function loadfromdb(&$db, $plugin_id=0)
{
$this->plugin_mode = 'db';
$this->db = $db;
if($plugin_id) $loadplugin = "p.plugin_id = '$plugin_id' and";
$this->db->setQuery("select h.location as hookname,p.name as pluginname,p.dependent,h.code,h.plugin_id,h.hook_id
from hooks as h
left join plugins as p on p.plugin_id=h.plugin_id
where $loadplugin p.enabled=1 and h.enabled=1
order by p.plugin_priority desc,h.hook_priority desc
");
$this->db->query();
$hookslist = $this->db->loadRowList();
foreach($hookslist as $hook)
{
# has dependent plugin ?
if(!defined('plugin_'.$hook[pluginname]))
{
$depends = split(',',$hook[dependent]);
if($depends)
foreach($depends as $depend)
{
if(!$depend) break;
if(!defined('plugin_'.$depend)||constant('plugin_'.$depend)==-1) {define('plugin_'.$hook[pluginname],-1);break;}
}
}
# no dependent plugin or loaded correct, load the current plugin
if(!defined('plugin_'.$hook[pluginname]))define('plugin_'.$hook[pluginname],1);
# if the plugin is loaded correctly,
if(constant('plugin_'.$hook[pluginname])==1)
{
$this->hooks[$hook[hookname]] .= "\n".$hook[code]."\n";
$this->hook_object[$hook[pluginname]][$hook[hookname]][] = $hook[code];
}
}
}
/**
* Sets the plugin list array
*/
function loadfromfile()
{
$this->plugin_mode = 'file';
require_once ROOT.'/plugins/load.php';
foreach($pluginlist as $plugin)
{
# has dependent plugin ?
if(!defined('plugin_'.$plugin[pluginname]))
{
$depends = split(',',$plugin[dependent]);
if($depends)
foreach($depends as $depend)
{
if(!$depend) break;
if(!defined('plugin_'.$depend)||constant('plugin_'.$depend)==-1) {define('plugin_'.$plugin[pluginname],-1);break;}
}
}
# no dependent plugin or loaded correct, load the current plugin
if(!defined('plugin_'.$plugin[pluginname]))define('plugin_'.$plugin[pluginname],1);
# if the plugin is loaded correctly,
if(constant('plugin_'.$plugin[pluginname])==1)
{
require_once 'plugins/'.$plugin[pluginname].'/run.php';
//echo 'plugins/'.$plugin[pluginname].'/run.php';
}
}
$this->pluginlist = $pluginlist;
}
function complie(&$db)
{
$this->db = $db;
## load plugin list
$this->db->setQuery("select p.name as pluginname,p.dependent,p.run_type,p.enabled,p.plugin_priority
from plugins as p
order by p.plugin_priority desc");
$this->db->query();
$pluginlist = $this->db->loadRowList();
## write to global plugin file
$fp = fopen('plugins/load.php','wb');
$buf=sprintf("<"."?"."php\n\$pluginlist=%s;\n"."?".">",var_export($pluginlist,1));
if($fp&&flock($fp,LOCK_EX)){ftruncate($fp,0);fseek($fp,0);fwrite($fp,$buf);fflush($fp);fclose($fp);}
## load hook list
$this->db->setQuery("select h.location as hookname,p.name as pluginname,h.code,p.run_type,h.enabled,h.hook_priority
from hooks as h
left join plugins as p on p.plugin_id=h.plugin_id
where 1
order by p.plugin_priority desc,h.hook_priority desc
");
$this->db->query();
$hookslist = $this->db->loadRowList();
foreach($hookslist as $hook)
{
$plugin_type[$hook[pluginname]] = $hook[run_type];
if($hook[enabled]) $plugin_code[$hook[pluginname]][$hook[hookname]] .= $hook[code];
}
## write to plugin file
foreach($plugin_code as $pluginname => $codeobj)
{
$phpcode = '';
foreach($codeobj as $hookname => $hookcode)
{
if($plugin_type[$hook[pluginname]]=='eval')
$phpcode .= sprintf("function %s_%s()\n{\n return <<<EOF\n%s\nEOF;\n}\n",$pluginname,$hookname,$hookcode);
else
$phpcode .= sprintf("function %s_%s()\n{\n %s \n}\n",$pluginname,$hookname,$hookcode);
}
$fp = fopen('plugins/'.$pluginname.'/run.php','wb');
if($fp&&flock($fp,LOCK_EX)){ftruncate($fp,0);fseek($fp,0);fwrite($fp,'<'."?\n".$phpcode.'?'.'>');fflush($fp);fclose($fp);}
}
}
/**
* Sets the plugin list array
*/
function set_hooks(&$hooks)
{
$this->hooks =& $hooks;
}
/**
* Returns any code attached to a hook with a specific name
*
* @param string hookname The name of the hook (location) to be executed
*
* @return string
*/
function &fetch_hook_object($hookname)
{
if($this->plugin_mode == 'db') return $this->hooks["$hookname"];
$code = '';
if($this->plugin_mode == 'file')
foreach($this->pluginlist as $plugin)
{
# if plugin loaded
if(constant('plugin_'.$plugin[pluginname])==1)
{
$hookfunc = $plugin[pluginname].'_'.$hookname;
if($plugin[enabled]&&function_exists($hookfunc))
{
#$code = $hookfunc($enabled,$priority);
if($plugin[run_type]=='function') $hookfunc();
else $code .= $hookfunc();
}
}
}
if($this->plugin_mode == 'file') return $code;
}
/**
* Returns any code attached to a hook with a specific name
*
* @param string hookname The name of the hook (location) to be executed
*
* @return string
*/
function &execute($hookname,$file=null,$line=null)
{
$this->hooks["$hookname"]?eval($this->hooks["$hookname"]):'';
}
/**
* Returns any code attached to a hook with a specific name. Used when the object is not in scope already.
*
* @param string hookname The name of the hook (location) to be executed
*
* @return string
*/
function &fetch_hook($hookname,$file=null,$line=null)
{
$obj =& YABPlugin::init();
//print_r($obj);
return $obj->fetch_hook_object($hookname);
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -