$val)
if (! isset($GLOBALS[$name]))
$GLOBALS[$name] = $val;
}
// Check plugin '$name' is here
function exist_plugin($name)
{
global $vars;
static $exist = array(), $count = array();
$name = strtolower($name);
if(isset($exist[$name])) {
if (++$count[$name] > PKWK_PLUGIN_CALL_TIME_LIMIT)
die('Alert: plugin "' . htmlspecialchars($name) .
'" was called over ' . PKWK_PLUGIN_CALL_TIME_LIMIT .
' times. SPAM or someting?
' . "\n" .
'Try to edit this page
' . "\n" .
'Return to frontpage');
return $exist[$name];
}
if (preg_match('/^\w{1,64}$/', $name) &&
file_exists(PLUGIN_DIR . $name . '.inc.php')) {
$exist[$name] = TRUE;
$count[$name] = 1;
require_once(PLUGIN_DIR . $name . '.inc.php');
return TRUE;
} else {
$exist[$name] = FALSE;
$count[$name] = 1;
return FALSE;
}
}
/**
* @brief Used to check the existence of a callback function
* Since there's only a few function types for callbacks, the array can be
* manipulated or expanded to allow/deny other callback functions.
* @param string $name
* @param string $affix
* @return boolean
*/
function plugin_callback_exists($name,$affix = "action") {
if(in_array($affix,array("action","convert","inline")) && exist_plugin($name)) {
$plugin_name = "plugin_" . $name . "_" . $affix;
return (function_exists($plugin_name)) ? TRUE : FALSE; // Function exists : Function doesn't exist.
}
}
function plugin_do_callback($name,$affix = NULL,$params = NULL) {
$name .= (is_null($affix)) ? "" : "_" . $affix;
$func_name = "plugin_" . $name;
return (count($params) > 0 && isset($params[0])) ? call_user_func($func_name,$params) : (isset($params) && is_string($params)) ? $func_name($params) : $func_name();
}
// Do init the plugin
function plugin_do_init($name)
{
static $checked = array();
if(isset($checked[$name])) {
$funcname = plugin_callback_exists($name,'init') ? "plugin" . $name . "_init" : FALSE;
return $checked[$name] = ($funcname && $funcname()) ? $funcname() : call_user_func($funcname); // No need for double ternary - returns false on error.
} else {
return FALSE; // Yeah, your plugin is poop.
}
}
/**
* @brief Used to perform the predefined "action"
* @param string $name
*
* @return array
* @return string
*/
function plugin_do_action($name)
{
if(plugin_callback_exists($name) && plugin_do_init($name)) { // Cached callback
$retvar = plugin_do_callback($name,"action");
}
elseif(!plugin_do_init($name)) {
$retvar = array();
} elseif(PKWK_ENCODING_HINT != '') {
$retvar = preg_replace('/(