[pmwiki-users] Sanity check of first recipe

Petko Yotov 5ko at 5ko.fr
Sun Apr 27 07:40:16 CDT 2008


On Sunday 27 April 2008, Jan Erik Moström wrote:
> What I want to do is to be able to insert markup like this
>
>      (:jpl src="path|45|10" pop="path|12|15" capt="bla bla bla":)
>
> and it should generate some code for displaying photos 
 ...
> The 'pop' and 'capt' arguments are optional.
>
> Here is my recipe
>
> <?php
>
> Markup("jPhoto",
>      'inline',
>      "/\\(:jp(l|r|c) src=\"(.+?)\|(\d+)\|(\d+)\"(.+?):\\)/se",
>      "Keep(jpFixMarkup('$1','$2','$3','$4',PSS('$5')))"
> );
>
> function jpFixMarkup( $type, $image, $iwidth, $iheight,
> $tagstring )


Hi.

You may find usefull to look at how some other recipes are written. There is 
the ParseArgs() pmwiki function that will help you a lot, like this:


Markup("jPhoto", 'inline'
     "/\\(:jp(l|r|c) (.+?):\\)/se",
     "Keep(jpFixMarkup('$1',PSS('$2')))"
);

function jpFixMarkup( $type, $args)
{

	$opt = ParseArgs($args);
	
	# $opt['src'] is now your src= value
	# $opt['pop'] is now your pop= value,
		# to get the parts, use:
	list($path, $w1, $w2) = explode('|', $opt['pop']);
	# $opt['capt'] is now your capt= value
	
	return Keep("<pre>".print_r($opt, 1)."</pre>");

}


You may see for example how the Thumblist recipe is written. It accepts many 
arguments in the markup; it is quite complex but may be of some help, for you 
to write your own recipe. (Coincidently, it also does thumbnails linking to 
the originals.)

  http://pmwiki.org/wiki/Cookbook/ThumbList

If you have any questions about this code, I'll be happy to help.


See also:

  http://www.pmwiki.org/wiki/PmWiki/Functions
  http://www.pmwiki.org/wiki/PmWiki/FunctionList
  http://www.pmwiki.org/wiki/Cookbook/Functions

Thanks,
Petko

P.S. Remove the last ?> from your code, it is not needed, but any eventual 
newline/whitespace after it may break your layout with a PHP warning.




More information about the pmwiki-users mailing list