Back to BugTrack2/301


diff file ?

Index: lib/plugin.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/lib/plugin.php,v
retrieving revision 1.15
diff -u -r1.15 plugin.php
--- pukiwiki/lib/plugin.php	3 Jul 2005 14:16:23 -0000	1.15
+++ pukiwiki/lib/plugin.php	30 Mar 2008 08:49:07 -0000
@@ -1,13 +1,33 @@
 <?php
-// PukiWiki - Yet another WikiWikiWeb clone.
 // $Id: plugin.php,v 1.15 2005/07/03 14:16:23 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
 
+/*
+PukiWiki - Yet another WikiWikiWeb clone, apparently.
+Copyright (C) 2002-2005 PukiWiki Developers,
+		 2001-2002 yu-ji
+
+License: As listed below (GPL v2) or (at your option) any later version, dependant upon compatibility of licenses.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+Note from JordanC: If you're licensing under the GPL, you need to implicitly
+define the GPL in the header so that if code is browsed, you don't run the risk of
+it being pseudo-legal.
+*/
+
+// Plugin related functions
 define('PKWK_PLUGIN_CALL_TIME_LIMIT', 768);
 
 // Set global variables for plugins
@@ -49,130 +69,104 @@
 	}
 }
 
-// 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
+/**
+ * @brief Used to check the existence of a callback function
+ * Since there's only a few function types for callbacks, the array can be
+ * manipulated or expanded to allow/deny other callback functions.
+ * @param string $name
+ * @param string $affix
+ * @return boolean
+ */
+function plugin_callback_exists($name,$affix = "action") {
+	if(in_array($affix,array("action","convert","inline")) && exist_plugin($name)) {
+		$plugin_name = "plugin_" . $name . "_" . $affix;
+		return (function_exists($plugin_name)) ? TRUE : FALSE; // Function exists : Function doesn't exist.
 	}
+}
 
-	return $checked[$name];
+function plugin_do_callback($name,$affix = NULL,$params = NULL) {
+	$name .= (is_null($affix)) ? "" : "_" . $affix;
+	$func_name = "plugin_" . $name;
+	return (count($params) > 0 && isset($params[0])) ? call_user_func($func_name,$params) : (isset($params) && is_string($params)) ?  $func_name($params) : $func_name();
 }
 
-// Call API 'action' of the plugin
-function do_plugin_action($name)
+// Do init the plugin
+function plugin_do_init($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 != '')
+	static $checked = array();
+	if(isset($checked[$name])) {
+		$funcname = plugin_callback_exists($name,'init') ? "plugin" . $name . "_init";
+		 return $checked[$name] = ($funcname()) ? $funcname() : call_user_func($funcname); // No need for double ternary - returns false on error.
+	} else {
+		return FALSE; // Yeah, your plugin is poop.
+	}
+}
+/**
+ * @brief Used to perform the predefined "action"
+ * @param string $name
+ *
+ * @return array
+ * @return string
+ */
+function plugin_do_action($name)
+{
+	if(plugin_callback_exists($name) && plugin_do_init($name)) { // Cached callback
+		$retvar = plugin_do_callback($name,"action");
+	}
+	elseif(!plugin_do_init($name)) {
+		$retvar = array();
+	} elseif(PKWK_ENCODING_HINT != '') {
 		$retvar =  preg_replace('/(<form[^>]*>)/', '$1' . "\n" .
-			'<div><input type="hidden" name="encode_hint" value="' .
-			PKWK_ENCODING_HINT . '" /></div>', $retvar);
-
+		'<div><input type="hidden" name="encode_hint" value="' .
+		PKWK_ENCODING_HINT . '" /></div>', $retvar);
+	}
 	return $retvar;
 }
 
-// Call API 'convert' of the plugin
-function do_plugin_convert($name, $args = '')
+/**
+ * @brief Calls the conversion function of the specified plug-in
+ *
+ * @param string $name
+ * @param string (CSV) $args
+ */
+function plugin_do_convert($name, $args = '')
 {
 	global $digest;
+	$args = ($args == '') ? array() : (strpos(",",$args)) ? csv_explode(',',$args) : FALSE;
 
-	if(do_plugin_init($name) === FALSE)
-		return '[Plugin init failed: ' . $name . ']';
-
-	if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
-		// Multiline plugin?
+	if(!plugin_do_init($name))
+		return "Plugin init failed for" .  $name;
+	if (!PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
+		if (isset($body)) $aryargs[] = & $body;
 		$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 = csv_explode(',', $args); // #plugin(A,B,C,D)
-	}
-	if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
-		if (isset($body)) $aryargs[] = & $body;     // #plugin(){{body}}
-	}
-
-	$_digest = $digest;
-	$retvar  = call_user_func_array('plugin_' . $name . '_convert', $aryargs);
-	$digest  = $_digest; // Revert
-
-	if ($retvar === FALSE) {
-		return htmlspecialchars('#' . $name .
-			($args != '' ? '(' . $args . ')' : ''));
-	} else if (PKWK_ENCODING_HINT != '') {
-		// Insert a hidden field, supports idenrtifying text enconding
-		return preg_replace('/(<form[^>]*>)/', '$1 ' . "\n" .
+		$bc_cache = plugin_do_callback("plugin_" . $name . "_convert",$args);
+	} elseif(!$bc_cache) {
+		if (PKWK_ENCODING_HINT != '') {
+			return preg_replace('/(<form[^>]*>)/', '$1 ' . "\n" .
 			'<div><input type="hidden" name="encode_hint" value="' .
-			PKWK_ENCODING_HINT . '" /></div>', $retvar);
-	} else {
-		return $retvar;
-	}
+			PKWK_ENCODING_HINT . '" /></div>', $bc_cache);
+		}
+		return htmlspecialchars('#' . $name . ($args != '' ? '(' . $args . ')' : ''));
+	} else
+		return FALSE;
 }
 
 // Call API 'inline' of the plugin
 function do_plugin_inline($name, $args, & $body)
 {
 	global $digest;
-
-	if(do_plugin_init($name) === FALSE)
-		return '[Plugin init failed: ' . $name . ']';
-
-	if ($args !== '') {
-		$aryargs = csv_explode(',', $args);
-	} else {
-		$aryargs = array();
-	}
-
-	// NOTE: A reference of $body is always the last argument
-	$aryargs[] = & $body; // func_num_args() != 0
-
-	$_digest = $digest;
-	$retvar  = call_user_func_array('plugin_' . $name . '_inline', $aryargs);
-	$digest  = $_digest; // Revert
-
-	if($retvar === FALSE) {
-		// Do nothing
+	$args = ($args == '') ? csv_explode(',', $args) & $body : array();
+	if(plugin_do_init($name))
+		return "Plugin init failed for" .$name;
+	$bc_cache = plugin_do_callback($name,"inline",$args);
+	if(!$bc_cache) {
 		return htmlspecialchars('&' . $name . ($args ? '(' . $args . ')' : '') . ';');
 	} else {
-		return $retvar;
+		return $bc_cache;
 	}
 }
 ?>
Index: pukiwiki/lib/convert_html.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/lib/convert_html.php,v
retrieving revision 1.20
diff -u -r1.20 convert_html.php
--- pukiwiki/lib/convert_html.php	10 Sep 2007 14:18:50 -0000	1.20
+++ pukiwiki/lib/convert_html.php	30 Mar 2008 08:20:17 -0000
@@ -141,18 +141,18 @@
 	if (PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
 		// Usual code
 		if (preg_match('/^\#([^\(]+)(?:\((.*)\))?/', $text, $matches) &&
-		    exist_plugin_convert($matches[1])) {
+		    plugin_callback_exists($matches[1], 'convert')) {
 			return new Div($matches);
 		}
 	} else {
 		// Hack code
 		if(preg_match('/^#([^\(\{]+)(?:\(([^\r]*)\))?(\{*)/', $text, $matches) &&
-		   exist_plugin_convert($matches[1])) {
+		   plugin_callback_exists($matches[1], 'convert')) {
 			$len  = strlen($matches[3]);
 			$body = array();
 			if ($len == 0) {
 				return new Div($matches); // Seems legacy block plugin
-			} else if (preg_match('/\{{' . $len . '}\s*\r(.*)\r\}{' . $len . '}/', $text, $body)) { 
+			} else if (preg_match('/\{{' . $len . '}\s*\r(.*)\r\}{' . $len . '}/', $text, $body)) {
 				$matches[2] .= "\r" . $body[1] . "\r";
 				return new Div($matches); // Seems multiline-enabled block plugin
 			}
@@ -783,7 +783,7 @@
 	function toString()
 	{
 		// Call #plugin
-		return do_plugin_convert($this->name, $this->param);
+		return plugin_do_convert($this->name, $this->param);
 	}
 }
 
Index: pukiwiki/lib/html.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/lib/html.php,v
retrieving revision 1.65
diff -u -r1.65 html.php
--- pukiwiki/lib/html.php	19 Aug 2007 13:59:07 -0000	1.65
+++ pukiwiki/lib/html.php	30 Mar 2008 08:24:44 -0000
@@ -91,7 +91,7 @@
 		' ' . get_pg_passage($_page, FALSE) : '';
 
 	// List of attached files to the page
-	$attaches = ($attach_link && $is_read && exist_plugin_action('attach')) ?
+	$attaches = ($attach_link && $is_read && plugin_callback_exists('attach', 'action')) ?
 		attach_filelist() : '';
 
 	// List of related pages
@@ -164,7 +164,7 @@
 	if ($digest === FALSE) $digest = md5(get_source($page, TRUE, TRUE));
 
 	$refer = $template = '';
- 
+
  	// Add plugin
 	$addtag = $add_top = '';
 	if(isset($vars['add'])) {
Index: pukiwiki/lib/pukiwiki.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/lib/pukiwiki.php,v
retrieving revision 1.21
diff -u -r1.21 pukiwiki.php
--- pukiwiki/lib/pukiwiki.php	26 Aug 2007 15:17:28 -0000	1.21
+++ pukiwiki/lib/pukiwiki.php	30 Mar 2008 08:29:40 -0000
@@ -133,8 +133,8 @@
 
 // Plugin execution
 if ($plugin != '') {
-	if (exist_plugin_action($plugin)) {
-		$retvars = do_plugin_action($plugin);
+	if (plugin_callback_exists($plugin, 'action')) {
+		$retvars = plugin_do_action($plugin);
 		if ($retvars === FALSE) exit; // Done
 
 		// Rescan $vars (Some plugins rewrite it)
Index: pukiwiki/plugin/filelist.inc.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/plugin/filelist.inc.php,v
retrieving revision 1.3
diff -u -r1.3 filelist.inc.php
--- pukiwiki/plugin/filelist.inc.php	9 Jan 2005 08:16:28 -0000	1.3
+++ pukiwiki/plugin/filelist.inc.php	30 Mar 2008 08:31:04 -0000
@@ -7,6 +7,6 @@
 
 function plugin_filelist_action()
 {
-	return do_plugin_action('list');
+	return plugin_do_action('list');
 }
 ?>
Index: pukiwiki/plugin/read.inc.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/plugin/read.inc.php,v
retrieving revision 1.8
diff -u -r1.8 read.inc.php
--- pukiwiki/plugin/read.inc.php	15 Jan 2005 13:57:07 -0000	1.8
+++ pukiwiki/plugin/read.inc.php	30 Mar 2008 08:32:30 -0000
@@ -17,11 +17,11 @@
 		return array('msg'=>'', 'body'=>'');
 
 	} else if (! PKWK_SAFE_MODE && is_interwiki($page)) {
-		return do_plugin_action('interwiki'); // InterWikiNameを処理
+		return plugin_do_action('interwiki'); // InterWikiNameを処理
 
 	} else if (is_pagename($page)) {
 		$vars['cmd'] = 'edit';
-		return do_plugin_action('edit'); // 存在しないので、編集フォームを表示
+		return plugin_do_action('edit'); // 存在しないので、編集フォームを表示
 
 	} else {
 		// 無効なページ名
Index: pukiwiki/plugin/rename.inc.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/plugin/rename.inc.php,v
retrieving revision 1.37
diff -u -r1.37 rename.inc.php
--- pukiwiki/plugin/rename.inc.php	3 Nov 2007 15:26:19 -0000	1.37
+++ pukiwiki/plugin/rename.inc.php	30 Mar 2008 08:34:21 -0000
@@ -310,8 +310,8 @@
 {
 	$files = array();
 	$dirs  = array(BACKUP_DIR, DIFF_DIR, DATA_DIR);
-	if (exist_plugin_convert('attach'))  $dirs[] = UPLOAD_DIR;
-	if (exist_plugin_convert('counter')) $dirs[] = COUNTER_DIR;
+	if (plugin_callback_exists('attach', 'convert'))  $dirs[] = UPLOAD_DIR;
+	if (plugin_callback_exists('counter', 'convert')) $dirs[] = COUNTER_DIR;
 	// and more ...
 
 	$matches = array();
Index: pukiwiki/skin/pukiwiki.skin.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/skin/pukiwiki.skin.php,v
retrieving revision 1.56
diff -u -r1.56 pukiwiki.skin.php
--- pukiwiki/skin/pukiwiki.skin.php	26 Jul 2007 00:57:00 -0000	1.56
+++ pukiwiki/skin/pukiwiki.skin.php	30 Mar 2008 08:35:39 -0000
@@ -51,7 +51,7 @@
 }
 
 // MenuBar
-$menu = arg_check('read') && exist_plugin_convert('menu') ? do_plugin_convert('menu') : FALSE;
+$menu = arg_check('read') && plugin_callback_exists('menu', 'convert') ? plugin_do_convert('menu') : FALSE;
 
 // ------------------------------------------------------------
 // Output
Index: pukiwiki/skin/tdiary.skin.php
===================================================================
RCS file: /cvsroot/pukiwiki/pukiwiki/skin/tdiary.skin.php,v
retrieving revision 1.36
diff -u -r1.36 tdiary.skin.php
--- pukiwiki/skin/tdiary.skin.php	24 Jun 2007 14:01:21 -0000	1.36
+++ pukiwiki/skin/tdiary.skin.php	30 Mar 2008 08:37:19 -0000
@@ -213,7 +213,7 @@
 	case 'white_flower':
 	case 'whiteout':
 	case 'wood':
-		$title_design_date = 0; // Select text design	
+		$title_design_date = 0; // Select text design
 		break;
 
 	case 'aqua':
@@ -531,11 +531,11 @@
 	$menu = FALSE;
 } else {
 	$menu = (arg_check('read') && is_page($GLOBALS['menubar']) &&
-		exist_plugin_convert('menu'));
+		plugin_callback_exists('menu', 'convert'));
 	if ($menu) {
 		$menu_body = preg_replace('#<h2 ([^>]*)>(.*?)</h2>#',
 			'<h3 $1><span class="sanchor"></span> $2</h3>',
-			do_plugin_convert('menu'));
+			plugin_do_convert('menu'));
 	}
 }
 

Back to BugTrack2/301


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2008-04-17 (木) 02:01:49
Site admin: PukiWiki Development Team

PukiWiki 1.5.2+ © 2001-2019 PukiWiki Development Team. Powered by PHP 5.6.40-0+deb8u7. HTML convert time: 0.255 sec.

OSDN