in a German thread the idea came up to simplify the plugin call, so that the trailing semicolon can be omitted, and also empty parentheses. For instance:
Code: Select all
{{{quoteoftheday}}}
Code: Select all
{{{audio 'song'}}}
Christoph
Code: Select all
{{{quoteoftheday}}}
Code: Select all
{{{audio 'song'}}}
what about numerical variables, could they go without ' ' ? E.g. {{calendar 2}} (=> display of two months in coming calendar 2.0)cmb wrote:parentheses generally optional
I've thought about that already, but I'm not sure, if there are existing installations which use double braces for something else. Maybe we should delay that to 1.7.svasti wrote:What about one more simplification: only 2 x {{
Yes, that already works due to PHP's dynamic typing, and I don't see, why that would be a problem after the simplifications.svasti wrote:what about numerical variables, could they go without ' ' ? E.g. {{calendar 2}} (=> display of two months in coming calendar 2.0)
I do not see a serious reason, too, but I consider it a slight convenience.Tata wrote:I basically don't see any serious reason for changing the calls.
Well, this notation does still work. While PLUGIN: was necessary in earlier versions, now it is optional. And actually, PLUGIN: is now simply treated as a comment, so one could write:Tata wrote:I even welcomed very much the {{{PLUGIN:...}}}. It was good visible in the code and it was prety safe to explain to any enuser that he must never touch these parts.
Code: Select all
{{{DON'T CHANGE THIS LINE:plugin('...');}}}
Code: Select all
{{{Zeigt das Zitat des Tages:quoteoftheday();}}}
Code: Select all
Index: cmsimple/functions.php
===================================================================
--- cmsimple/functions.php (revision 1402)
+++ cmsimple/functions.php (working copy)
@@ -225,21 +225,23 @@
$message = '<span class="xh_fail">' . $tx['error']['plugincall']
. '</span>';
- $re = '/{{{(?:[^:]+:)?(([a-z_0-9]+)\(.*?\);)}}}/iu';
+ $re = '/{{{(?:[^:]+:)?([a-z_0-9]+)\s*\(?(.*?)\)?;?}}}/iu';
preg_match_all($re, $text, $calls, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
$results = array();
foreach ($calls as $call) {
- $expression = preg_replace(
+ $arguments = preg_replace(
array(
'/&(quot|#34);/i', '/&(amp|#38);/i', '/&(apos|#39);/i',
'/&(lt|#60);/i', '/&(gt|#62);/i', '/&(nbsp|#160);/i'
),
array('"', '&', '\'', '<', '>', ' '),
- $call[1][0]
+ $call[2][0]
);
- $function = $call[2][0];
+ $function = $call[1][0];
if (function_exists($function)) {
- $results[] = XH_evaluateSinglePluginCall($expression);
+ $results[] = XH_evaluateSinglePluginCall(
+ $function . '(' . $arguments . ')'
+ );
} else {
$results[] = sprintf($message, $function);
}
@@ -273,7 +275,7 @@
foreach ($GLOBALS as $___var => $___value) {
$$___var = $GLOBALS[$___var];
}
- return eval('return ' . $___expression);
+ return eval('return ' . $___expression . ';');
}
/**
Index: tests/unit/FunctionsTest.php
===================================================================
--- tests/unit/FunctionsTest.php (revision 1402)
+++ tests/unit/FunctionsTest.php (working copy)
@@ -130,7 +130,16 @@
'foo {{{PLUGIN:doesnotexist();}}} bar',
'foo <span class="xh_fail">Function doesnotexist() is not defined!</span> bar'
),
- array('foo {{{PLUGIN:trim(\':\');}}} bar', 'foo : bar')
+ array('foo {{{PLUGIN:trim(\':\');}}} bar', 'foo : bar'),
+ array( // without trailing semicolon
+ 'foo {{{trim(\'baz\');}}} bar', 'foo baz bar'
+ ),
+ array( // with whitespace before the opening parenthesis
+ 'foo {{{trim(\'baz\');}}} bar', 'foo baz bar'
+ ),
+ array( // without parentheses
+ 'foo {{{trim \'baz\';}}} bar', 'foo baz bar'
+ )
);
}