[pmwiki-users] Conditional Markup enhancement
Knut Alboldt
pmwiki at alboldt.de
Wed Mar 2 14:56:39 CST 2005
Patrick R. Michaud schrieb:
> On Tue, Mar 01, 2005 at 11:39:53PM +0100, Knut Alboldt wrote:
>
>>The usage of "string with blanks" will be really an improvement, but I
>>can't see the improvement of using an array of arrays for different
>>types of args when processing that (keep in mind that I'm not a php
>>guru, so please, maybe I only need a little help to understand)
>
>
> Okay, I'll see if I can make it clearer then. Let me start with
> an example of something that GettingMarkupArguments can't handle.
> Suppose I want to display all pages in the PmWiki group that
> contain the word "group". The markup for this would normally be:
>
> (:searchresults group=PmWiki "group" :)
didn't think of these "unnamed" arguments, now it's clear.
>
> With GettingMarkupArguments, $arg['group'] would end up being
> 1, which isn't what I want. In general, GettingMarkupArguments
> doesn't allow someone to specify an argument with the same
> name as a name=value option. I can come up with tons of
> other real-world examples where this will be needed.
>
>
>>In the argument parsing originated in PITS (and modified in the Cookbook
>>recipe GettingMarkupArguments) I can check if a arg is passed simply by
>>name:
>> if (isset($arg['name'])) ...
>
>
> In the new version you can still do this:
>
> $arg = ParseArgs($x);
> if ($arg['xyz']) ... // xyz=something was specified
>
>
>>or even better, if I provide defaults
>> $argdefaults['this'] = 0;
>> $args = GetDirectiveArgs($args,$argdefaults)
>
>
> $argdefaults['this'] = 0;
> $arg = array_merge($argdefaults, ParseArgs($x));
>
> And if you're wanting to have +"value" and -"value" come
> back as a one or a zero (indicating "on" and "off"):
>
> $arg = ParseArgs($x);
> foreach((array)$arg[''] as $a) $arg[$a]=1;
> foreach((array)$arg['+'] as $a) $arg[$a]=1;
> foreach((array)$arg['-'] as $a) $arg[$a]=0;
>
> if ($arg['xyz']==0) ... // either -xyz or xyz=0
> if ($arg['xyz']==1) ... // either +xyz or xyz=1
> if (isset($arg['xyz'])) ... // xyz was specified somewhere
>
>
thanks a lot, now it's clear.
So at least, if I want to have the "old" behavior of
GettingMarkupArguments I could use the code above instead of and can use
a standard (and even better because of ""-processing) argument parsing
machine.
Thanks !
so when beta24 is out I will replace Cookbook.GettingMarkupArguments
with your explanations above.
Knut
More information about the pmwiki-users
mailing list