<?php
// PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: plugin.php,v 1.12 2005/04/29 11:24:20 henoheno Exp $
+// $Id: plugin.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
// Copyright (C)
// 2002-2005 PukiWiki Developers Team
-// 2001 Originally written by yu-ji
+// 2001-2002 Originally written by yu-ji
// License: GPL v2 or (at your option) any later version
//
// Plugin related functions
$name = strtolower($name);
if(isset($exist[$name])) {
if (++$count[$name] > PKWK_PLUGIN_CALL_TIME_LIMIT)
- die('Alert: plugin "' . htmlspecialchars($name) .
+ 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='.
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;
}