Skip to content

Commit

Permalink
The rule take care of nested plugins, the plugin processing is done b…
Browse files Browse the repository at this point in the history
…y parsing as

plugins produce wiki markup, this production is also recursively parsed case plugins produced


git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@191704 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
bertrand Gugger committed Jul 28, 2005
1 parent 5c33524 commit 0a27224
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions Text/Wiki/Parse/Tiki/Plugin.php
@@ -1,6 +1,26 @@
<?php
class Text_Wiki_Parse_Plugin extends Text_Wiki_Parse {

/**
* Configurations keys, the script's name of the plugin will be prefixed and an extension added
* the path is a comma separated list of directories where to find it
*
* @access public
* @var string
*/
var $conf = array (
'file_prefix' => 'wikiplugin_',
'file_extension' => '.php',
'file_path' => 'lib/wiki-plugins/'
);

/**
* The regular expression used in second stage to find plugin's arguments
*
* @access public
* @var string
*/
var $regexArgs = '#(\w+?)=>?("[^"]+"|\'[^\']+\'|[^"\'][^,]+)#';

/**
*
Expand All @@ -14,7 +34,7 @@ class Text_Wiki_Parse_Plugin extends Text_Wiki_Parse {
*/

//var $regex = '/^({([A-Z]+?)\((.+)?\)})((.+)({\2}))?(\s|$)/Umsi';
var $regex = '/(^|\s)\{([A-Z]+?)\((.+?)?\)}(.*?)\{\2}(\s|$)/msi';
var $regex = '/\{([A-Z]+?)\((.*?)\)}((?:(?R)|.)*?)\{\1}/msi';


/**
Expand All @@ -34,35 +54,40 @@ class Text_Wiki_Parse_Plugin extends Text_Wiki_Parse {

function process(&$matches)
{
// are there additional attribute arguments?
$args = trim($matches[2]);

if ($args == '') {
$options = array(
'text' => $matches[3],
'plugin' => $matches[1],
'attr' => array()
);
} else {
// get the attributes...
//$attr = $this->getAttrs($args);
foreach (explode(',', $args) as $part) {
if (false !== ($eq = strpos($part, '=')) && $eq != strlen($part) - 1) {
$attr[substr($part, 0, $eq)] = substr($part, $eq + 1 + ($part[$eq + 1] == '>' ? 1 : 0));
} else {
$attr[$part] = '';
$func = $this->getConf('file_prefix') . strtolower($matches[1]);
if (!function_exists($func)) {
$file = $func . $this->getConf('file_extension');
$paths = explode(',', $this->getConf('file_path'));
$found = false;
foreach ($paths as $path) {
if (file_exists($pathfile = trim($path) . DIRECTORY_SEPARATOR . $file)) {
require_once $pathfile;
break;
}
}
if (!function_exists($func)) {
return $matches[0];
}
}

// retain the options
$options = array(
'text' => $matches[3],
'plugin' => $matches[1],
'attr' => $attr
);
// are there additional attribute arguments?
preg_match_all($this->regexArgs, $matches[2], $args, PREG_PATTERN_ORDER);
$attr = array();
foreach ($args[1] as $i=>$name) {
if ($args[2][$i]{0} == '"' || $args[2][$i]{0} == "'") {
$attr[$name] = substr($args[2][$i], 1, -1);
} else {
$attr[$name] = trim($args[2][$i]);
}
}

return $this->wiki->addToken($this->rule, $options) . $matches[4];
// executes the plugin with data and pameters then recursive re-parse for nested or produced plugins
$res = $func($matches[3], $attr);
return preg_replace_callback(
$this->regex,
array(&$this, 'process'),
$res
);
}
}
?>

0 comments on commit 0a27224

Please sign in to comment.