<?php
// PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: plugin.php,v 1.8 2005/04/05 14:42:02 henoheno Exp $
+// $Id: plugin.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
+// Copyright (C)
+// 2002-2005 PukiWiki Developers Team
+// 2001-2002 Originally written by yu-ji
+// License: GPL v2 or (at your option) any later version
//
// Plugin related functions
+define('PKWK_PLUGIN_CALL_TIME_LIMIT', 768);
+
// Set global variables for plugins
function set_plugin_messages($messages)
{
// Check plugin '$name' is here
function exist_plugin($name)
{
- static $exists = array();
+ global $vars;
+ static $exist = array(), $count = array();
$name = strtolower($name);
- if(isset($exists[$name])) return $exists[$name];
+ if(isset($exist[$name])) {
+ if (++$count[$name] > PKWK_PLUGIN_CALL_TIME_LIMIT)
+ die('Alert: plugin "' . htmlsc($name) .
+ '" was called over ' . PKWK_PLUGIN_CALL_TIME_LIMIT .
+ ' times. SPAM or someting?<br />' . "\n" .
+ '<a href="' . get_script_uri() . '?cmd=edit&page='.
+ rawurlencode($vars['page']) . '">Try to edit this page</a><br />' . "\n" .
+ '<a href="' . get_script_uri() . '">Return to frontpage</a>');
+ return $exist[$name];
+ }
if (preg_match('/^\w{1,64}$/', $name) &&
file_exists(PLUGIN_DIR . $name . '.inc.php')) {
- $exists[$name] = TRUE;
+ $exist[$name] = TRUE;
+ $count[$name] = 1;
require_once(PLUGIN_DIR . $name . '.inc.php');
return TRUE;
} else {
- $exists[$name] = FALSE;
+ $exist[$name] = FALSE;
+ $count[$name] = 1;
return FALSE;
}
}
function_exists('plugin_' . $name . '_inline') : FALSE;
}
-// Do init the plugin
+// Call 'init' function for the plugin
+// NOTE: Returning FALSE means "An erorr occurerd"
function do_plugin_init($name)
{
- static $checked = array();
+ static $done = 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
+ if (! isset($done[$name])) {
+ $func = 'plugin_' . $name . '_init';
+ $done[$name] = (! function_exists($func) || call_user_func($func) !== FALSE);
}
- return $checked[$name];
+ return $done[$name];
}
// Call API 'action' of the plugin
{
if (! exist_plugin_action($name)) return array();
- if(do_plugin_init($name) === FALSE)
- die_message('Plugin init failed: ' . $name);
+ if (do_plugin_init($name) === FALSE) {
+ die_message('Plugin init failed: ' . htmlspecialchars($name));
+ }
$retvar = call_user_func('plugin_' . $name . '_action');
{
global $digest;
- if(do_plugin_init($name) === FALSE)
- return '[Plugin init failed: ' . $name . ']';
+ if (do_plugin_init($name) === FALSE) {
+ return '[Plugin init failed: ' . htmlspecialchars($name) . ']';
+ }
- if ($args !== '') {
- $aryargs = csv_explode(',', $args);
+ if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
+ // Multiline plugin?
+ $pos = strpos($args, "\r"); // "\r" is just a delimiter
+ if ($pos !== FALSE) {
+ $body = substr($args, $pos + 1);
+ $args = substr($args, 0, $pos);
+ }
+ }
+
+ if ($args === '') {
+ $aryargs = array(); // #plugin()
} else {
- $aryargs = array();
+ $aryargs = csv_explode(',', $args); // #plugin(A,B,C,D)
+ }
+ if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
+ if (isset($body)) $aryargs[] = & $body; // #plugin(){{body}}
}
$_digest = $digest;
$digest = $_digest; // Revert
if ($retvar === FALSE) {
- return htmlspecialchars('#' . $name .
+ return htmlsc('#' . $name .
($args != '' ? '(' . $args . ')' : ''));
} else if (PKWK_ENCODING_HINT != '') {
// Insert a hidden field, supports idenrtifying text enconding
{
global $digest;
- if(do_plugin_init($name) === FALSE)
- return '[Plugin init failed: ' . $name . ']';
+ if (do_plugin_init($name) === FALSE) {
+ return '[Plugin init failed: ' . htmlspecialchars($name) . ']';
+ }
- if ($args !== '') {
- $aryargs = csv_explode(',', $args);
- } else {
+ if ($args === '') {
$aryargs = array();
+ } else {
+ $aryargs = csv_explode(',', $args);
}
// NOTE: A reference of $body is always the last argument
if($retvar === FALSE) {
// Do nothing
- return htmlspecialchars('&' . $name . ($args ? '(' . $args . ')' : '') . ';');
+ return htmlsc('&' . $name . ($args ? '(' . $args . ')' : '') . ';');
} else {
return $retvar;
}