Back to [[BugTrack2/301]]

#contents

-----
** lib/plugin.php [#mdc641cf]
- From [[this file>http://sourceforge.jp/tracker/download.php?group_id=166&atid=713&file_id=2259&aid=12174]]
-- Fix, PHP errors
-- Fix, Not same work some functions ((PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK, PKWK_ENCODING_HINT, and etc.))

 <?php
 // $Id: plugin.php,v 1.15 2005/07/03 14:16:23 henoheno Exp $
 
 /*
 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
 function set_plugin_messages($messages)
 {
 	foreach ($messages as $name=>$val)
 		if (! isset($GLOBALS[$name]))
 			$GLOBALS[$name] = $val;
 }
 
 // Check plugin '$name' is here
 function exist_plugin($name)
 {
 	global $vars;
 	static $exist = array(), $count = array();
 
 	$name = strtolower($name);
 	if(isset($exist[$name])) {
 		if (++$count[$name] > PKWK_PLUGIN_CALL_TIME_LIMIT)
 			die('Alert: plugin "' . htmlspecialchars($name) .
 			'" was called over ' . PKWK_PLUGIN_CALL_TIME_LIMIT .
 			' times. SPAM or someting?<br />' . "\n" .
 			'<a href="' . get_script_uri() . '?cmd=edit&amp;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')) {
 	    	$exist[$name] = TRUE;
 	    	$count[$name] = 1;
 		require_once(PLUGIN_DIR . $name . '.inc.php');
 		return TRUE;
 	} else {
 	    	$exist[$name] = FALSE;
 	    	$count[$name] = 1;
 		return FALSE;
 	}
 }
 
 /**
  * @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.
 
 	} else {
 		return FALSE;
 	}
 }
 
 function plugin_do_callback($name, $affix = '', $params = array()) { 
 	if(in_array($affix, array('action', 'convert', 'inline')) && is_array($params)) {
 		$func_name = 'plugin_' . $name . '_' . $affix;
 		return call_user_func_array($func_name, $params);
 
 	} else {
 		return FALSE;
 	}
 }
 
 // Do init the plugin
 function plugin_do_init($name)
 {
 	static $checked = array();
 
 	// No need for double ternary - returns false on error.
 	if(isset($checked[$name])) { 
 		 return $checked[$name];
 	}
 
 	if (plugin_callback_exists($name,'init')) {
 		if (call_user_func('plugin_' . $name . '_init') !== FALSE) {
 			return $checked[$name] = TRUE;
 		} else {
 			return $checked[$name] = FALSE; // Yeah, your plugin is poop.
 		}
 
 	} else {
 		return $checked[$name] = TRUE;
 	}
 }
 
 /**
  * @brief Used to perform the predefined "action"
  * @param string $name
  * 
  * @return array
  * @return string
  */
 function plugin_do_action($name)
 {
 	if(plugin_callback_exists($name)) { // Cached callback 
 		if (! plugin_do_init($name))
 			return die('Plugin init failed for ' . $name);
 
 		$retvar = plugin_do_callback($name, 'action');
 		if(PKWK_ENCODING_HINT != '') {
 			$retvar =  preg_replace('/(<form[^>]*>)/', '$1' . "\n" .
 			'<div><input type="hidden" name="encode_hint" value="' .
 			PKWK_ENCODING_HINT . '" /></div>', $retvar);
 		}
 
 	} else {
 		$retvar = array();
 	}
 
 	return $retvar;
 }
 
 /**
  * @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;
 
 	if(! plugin_do_init($name)) 
 		return 'Plugin init failed for ' . $name;
 
 	if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
 		$pos  = strpos($args, "\r"); // "\r" is just a delimiter
 		if ($pos !== FALSE) { // divide multiline strings
 			$body = substr($args, $pos + 1);
 			$args = substr($args, 0, $pos);
 		}
 		$params = ($args == '') ? array() : csv_explode(',',$args);
 		if (isset($body)) $params[] = & $body;     // #plugin(){{body}}
 
 	} else {
 		$params = ($args == '') ? array() : csv_explode(',',$args);
 	}
 
 	$bc_cache = plugin_do_callback($name, 'convert', $params);
 	if($bc_cache === FALSE) {
 		return htmlspecialchars('#' . $name . ($args != '' ? '(' . $args . ')' : ''));
 	} else {
 		if (PKWK_ENCODING_HINT != '') {
 			return preg_replace('/(<form[^>]*>)/', '$1 ' . "\n" .
 			'<div><input type="hidden" name="encode_hint" value="' .
 			PKWK_ENCODING_HINT . '" /></div>', $bc_cache);
 		}
 		return $bc_cache;
 	}
 }
 
 // Call API 'inline' of the plugin
 function plugin_do_inline($name, $args, & $body)
 {
 	global $digest;
 
 	$params = ($args == '') ? array() : csv_explode(',', $args);
 	$params[] = & $body;
 
 	if(! plugin_do_init($name))
 		return 'Plugin init failed for ' .$name;
 
 	$bc_cache = plugin_do_callback($name, 'inline', $params);
 	if($bc_cache === FALSE) {
 		return htmlspecialchars('&' . $name . ($args ? '(' . $args . ')' : '') . ';');
 	} else { 
 		return $bc_cache;
 	}
 }
 ?>

** diff file ? [#oaf70da5]

 Index: convert_html.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/lib/convert_html.php,v
 diff -u convert_html.php
 @@ -141,13 +141,13 @@
         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) {
 @@ -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: html.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/lib/html.php,v
 diff -u html.php
 @@ -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
 Index: make_link.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/lib/make_link.php,v
 diff -u make_link.php
 @@ -264,8 +264,8 @@
                 $str = FALSE;
 
                 // Try to call the plugin
 -               if (exist_plugin_inline($this->name))
 -                       $str = do_plugin_inline($this->name, $this->param, $body);
 +               if (plugin_callback_exists($this->name, 'inline'))
 +                       $str = plugin_do_inline($this->name, $this->param, $body);
 
                 if ($str !== FALSE) {
                         return $str; // Succeed
 Index: pukiwiki.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/lib/pukiwiki.php,v
 diff -u pukiwiki.php
 @@ -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: filelist.inc.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/plugin/filelist.inc.php,v
 diff -u filelist.inc.php
 @@ -7,6 +7,6 @@
 
  function plugin_filelist_action()
  {
 -       return do_plugin_action('list');
 +       return plugin_do_action('list');
  }
  ?>
 Index: read.inc.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/plugin/read.inc.php,v
 diff -u read.inc.php
 @@ -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: rename.inc.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/plugin/rename.inc.php,v
 diff -u rename.inc.php
 @@ -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.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/skin/pukiwiki.skin.php,v
 diff -u pukiwiki.skin.php
 @@ -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: tdiary.skin.php
 ===================================================================
 RCS file: /cvsroot/pukiwiki/pukiwiki/skin/tdiary.skin.php,v
 diff -u tdiary.skin.php
 @@ -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
Site admin: PukiWiki Development Team

PukiWiki 1.5.4+ © 2001-2022 PukiWiki Development Team. Powered by PHP 5.6.40-0+deb8u12. HTML convert time: 0.055 sec.

OSDN