$val)
if (! isset($GLOBALS[$name]))
$GLOBALS[$name] = $val;
}
// Same as getopt for plugins
function get_plugin_option($args, &$params, $tolower=TRUE, $separator=':')
{
if (empty($args)) {
$params['_done'] = TRUE;
return TRUE;
}
$keys = array_keys($params);
foreach($args as $val) {
list($_key, $_val) = array_pad(split($separator, $val, 2), 2, TRUE);
if ($tolower === TRUE) $_key = strtolower($_key);
$_key = trim($_key);
$_val = trim($_val);
if (in_array($_key, $keys)) {
$params[$_key] = $_val; // Exist keys
} else {
$params['_args'][] = $val; // Not exist keys, in '_args'
}
}
$params['_done'] = TRUE;
return TRUE;
}
// Check arguments for plugins
function check_plugin_option($val, &$params, $tolower=TRUE)
{
if ($val != '') {
if ($tolower === TRUE) $_val = strtolower($val);
foreach (array_keys($params) as $key) {
if (strpos($key, $_val) === 0) {
$params[$key] = TRUE;
return;
}
}
}
$params['_args'][] = $val;
}
// Check plugin '$name' is here
function exist_plugin($name)
{
global $vars;
global $exclude_plugin;
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];
}
//miko - Added exclude plugin spec.
if (in_array($name, $exclude_plugin)) {
$exist[$name] = FALSE;
$count[$name] = 1;
return FALSE;
}
//miko
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;
}
}
// Check if plugin API 'action' exists
function exist_plugin_action($name) {
return function_exists('plugin_' . $name . '_action') ? TRUE : exist_plugin($name) ?
function_exists('plugin_' . $name . '_action') : FALSE;
}
// Check if plugin API 'convert' exists
function exist_plugin_convert($name) {
return function_exists('plugin_' . $name . '_convert') ? TRUE : exist_plugin($name) ?
function_exists('plugin_' . $name . '_convert') : FALSE;
}
// Check if plugin API 'inline' exists
function exist_plugin_inline($name) {
return function_exists('plugin_' . $name . '_inline') ? TRUE : exist_plugin($name) ?
function_exists('plugin_' . $name . '_inline') : FALSE;
}
// Do init the plugin
function do_plugin_init($name)
{
static $checked = array();
if (isset($checked[$name])) return $checked[$name];
$func = 'plugin_' . $name . '_init';
if (function_exists($func)) {
// TRUE or FALSE or NULL (return nothing)
$checked[$name] = call_user_func($func);
} else {
$checked[$name] = NULL; // Not exist
}
return $checked[$name];
}
// Call API 'action' of the plugin
function do_plugin_action($name)
{
if (! exist_plugin_action($name)) return array();
if(do_plugin_init($name) === FALSE)
die_message('Plugin init failed: ' . $name);
$retvar = call_user_func('plugin_' . $name . '_action');
// Insert a hidden field, supports idenrtifying text enconding
if (PKWK_ENCODING_HINT != '')
$retvar = preg_replace('/(