<?php
// PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: plugin.php,v 1.12 2005/04/29 11:24:20 henoheno Exp $
-// Copyright (C)
-// 2002-2005 PukiWiki Developers Team
-// 2001 Originally written by yu-ji
+// plugin.php
+// Copyright
+// 2002-2021 PukiWiki Development Team
+// 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='.
+ '<a href="' . get_base_uri() . '?cmd=edit&page='.
rawurlencode($vars['page']) . '">Try to edit this page</a><br />' . "\n" .
- '<a href="' . get_script_uri() . '">Return to frontpage</a>');
+ '<a href="' . get_base_uri() . '">Return to frontpage</a>');
return $exist[$name];
}
// 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;
+ if (function_exists('plugin_' . $name . '_action')) {
+ return TRUE;
+ }
+ if (exist_plugin($name)) {
+ return function_exists('plugin_' . $name . '_action');
+ }
+ return 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;
+ if (function_exists('plugin_' . $name . '_convert')) {
+ return TRUE;
+ }
+ if (exist_plugin($name)) {
+ return function_exists('plugin_' . $name . '_convert');
+ }
+ return 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;
+ if (function_exists('plugin_' . $name . '_inline')) {
+ return TRUE;
+ }
+ if (exist_plugin($name)) {
+ return function_exists('plugin_' . $name . '_inline');
+ }
+ return 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: ' . htmlsc($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: ' . htmlsc($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: ' . htmlsc($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;
}
}
-?>