xpwiki = & $xpwiki;
$this->root = & $xpwiki->root;
$this->cont = & $xpwiki->cont;
$this->pid = $xpwiki->pid;
}
function load_ini() {
$root = & $this->root;
$const = & $this->cont;
/////////////////////////////////////////////////
// Require INI_FILE
$const['INI_FILE'] = $const['DATA_HOME'] . 'private/ini/pukiwiki.ini.php';
$die = '';
if (! file_exists($const['INI_FILE']) || ! is_readable($const['INI_FILE'])) {
$die .= 'File is not found. (INI_FILE)' . "\n";
} else {
require($const['INI_FILE']);
if (file_exists($const['CACHE_DIR'] . 'pukiwiki.ini.php')) {
include ($const['CACHE_DIR'] . 'pukiwiki.ini.php');
}
}
if ($die) $this->die_message(nl2br("\n\n" . $die));
}
function init() {
include(dirname(dirname(__FILE__))."/include/init.php");
}
function & get_plugin_instance ($name) {
static $instance = array();
if (is_null($name) && ! empty($instance[$this->xpwiki->pid])) {
$keys = array_keys($instance[$this->xpwiki->pid]);
foreach($keys as $key) {
unset($instance[$this->xpwiki->pid][$key]);
}
$ret = NULL;
return $ret;
}
if (!isset($instance[$this->xpwiki->pid][$name])) {
if ($class = $this->exist_plugin($name)) {
$instance[$this->xpwiki->pid][$name] =& new $class($this);
$instance[$this->xpwiki->pid][$name]->name = $name;
if ($this->plugin_init($name, $instance[$this->xpwiki->pid][$name]) === FALSE) {
$this->die_message('Plugin init failed: ' . $name);
}
} else {
$instance[$this->xpwiki->pid][$name] = false;
}
}
return $instance[$this->xpwiki->pid][$name];
}
function get_plugin_filename ($name) {
$files = array();
if (file_exists($this->root->mydirpath . '/private/plugin/' . $name . '.inc.php')) {
$files['user'] = $this->root->mydirpath . '/private/plugin/' . $name . '.inc.php';
}
if (file_exists($this->root->mytrustdirpath . '/plugin/' . $name . '.inc.php')) {
$files['system'] = $this->root->mytrustdirpath . '/plugin/' . $name . '.inc.php';
}
return $files;
}
// Set global variables for plugins
function set_plugin_messages($messages) {
foreach ($messages as $name=>$val)
if (! isset($this->root->$name))
$this->root->$name = $val;
}
// Check plugin '$name' is here
function exist_plugin($name) {
// global $vars;
static $exist = array(), $count = array();
$name = strtolower($name);
if(isset($exist[$this->xpwiki->pid][$name])) {
if (++$count[$this->xpwiki->pid][$name] > $this->cont['PKWK_PLUGIN_CALL_TIME_LIMIT'])
die('Alert: plugin "' . htmlspecialchars($name) .
'" was called over ' . $this->cont['PKWK_PLUGIN_CALL_TIME_LIMIT'] .
' times. SPAM or someting?
' . "\n" .
'Try to edit this page
' . "\n" .
'Return to frontpage');
return $exist[$this->xpwiki->pid][$name];
}
$plugin_files = $this->get_plugin_filename ($name);
$exist[$this->xpwiki->pid][$name] = FALSE;
$count[$this->xpwiki->pid][$name] = 1;
$ret = FALSE;
if (preg_match('/^\w{1,64}$/', $name) && $plugin_files ) {
$ret = FALSE;
if (isset($plugin_files['system'])) {
require_once($plugin_files['system']);
$class_name = "xpwiki_plugin_{$name}";
if (XC_CLASS_EXISTS($class_name)) {
$count[$this->xpwiki->pid][$name] = 1;
$ret = $class_name;
if (isset($plugin_files['user'])) {
require_once($plugin_files['user']);
$class_name = "xpwiki_".$this->root->mydirname."_plugin_{$name}";
if (XC_CLASS_EXISTS($class_name)) {
$ret = $class_name;
}
}
$ret = $class_name;
$exist[$this->xpwiki->pid][$name] = $ret;
$count[$this->xpwiki->pid][$name] = 1;
}
}
}
return $ret;
}
// Check if plugin API 'action' exists
function exist_plugin_action($name) {
$plugin = & $this->get_plugin_instance($name);
return is_object($plugin) ? method_exists($plugin, 'plugin_' . $name . '_action') : FALSE;
}
// Check if plugin API 'convert' exists
function exist_plugin_convert($name) {
$plugin = & $this->get_plugin_instance($name);
return is_object($plugin) ? method_exists($plugin, 'plugin_' . $name . '_convert') : FALSE;
}
// Check if plugin API 'inline' exists
function exist_plugin_inline($name) {
$plugin = & $this->get_plugin_instance($name);
return is_object($plugin) ? method_exists($plugin, 'plugin_' . $name . '_inline') : FALSE;
}
// Do init the plugin
function plugin_init($name, & $plugin) {
static $checked = array();
if (isset($checked[$this->xpwiki->pid][$name])) return $checked[$this->xpwiki->pid][$name];
$func = 'plugin_' . $name . '_init';
if (method_exists($plugin, $func)) {
// TRUE or FALSE or NULL (return nothing)
$checked[$this->xpwiki->pid][$name] = call_user_func(array(& $plugin, $func));
} else {
$checked[$this->xpwiki->pid][$name] = NULL; // Not exist
}
return $checked[$this->xpwiki->pid][$name];
}
// Compatibility
function do_plugin_init($name) {
$plugin = & $this->get_plugin_instance($name);
return $this->plugin_init($name, $plugin);
}
// Call API 'action' of the plugin
function do_plugin_action($name) {
if (! $this->exist_plugin_action($name)) return array();
$plugin = & $this->get_plugin_instance($name);
// ブラウザとのコネクションが切れても実行し続ける
$_iua = ignore_user_abort(TRUE);
$this->root->rtf['page_touch'] = array();
$retvar = call_user_func(array(& $plugin, 'plugin_' . $name . '_action'));
$this->plugin_page_touch($name);
// ignore_user_abort の設定値戻し
ignore_user_abort($_iua);
// exit 指定
if (is_array($retvar) && isset($retvar['exit'])) {
$this->clear_output_buffer();
exit($retvar['exit']);
}
// Insert a hidden field, supports idenrtifying text enconding
if ($this->cont['PKWK_ENCODING_HINT'] && is_array($retvar) && isset($retvar['body']))
$retvar['body'] = preg_replace('/(