Table of contents:
This is a simple wrapper operator to directly call any system and user-defined functions in template.
Useful for calling string formatting functions that are missing in ez from php and adding your own functions without need to code extra extensions.
Essentially, this is a simple wrapper operator to directly call any system and user-defined functions in template.
It does not concern me much if doing so is good idea or 'pfui' as someone said once on the #ezpublish irc channel.
Undoubtedly care has to be taken to avoid security and caching problems, etc.
But it makes life a lot easier for me because I don't have to re-implement / write existing text processing functions in template language and do not need to set up separate extension to every small operator I need.
It's a swiss army knife - you can cut your hand but no one is forcing you to :)
I am not sure exactly what datatypes can be passed to functions from template like this.
Should work ok for integers, strings and boolean I think. If you are more informed about ez internals, please comment.
Using wrap_user_func with return_output=true() should enable easy embedding of existing php applications in templates, called through the user function. I have tested just simple test case but maybe someone can think of something more useful and post specific instructions..
There are two operators:
The return value of function you call.
If return_output is set true(), the OUTPUT from the function is returned instead.
Function names callable through operator must be explicitly listed in wrap_operator.ini , anything else is not allowed.
Calling internal php functions. For example: you want to use ereg_replace php function.
1. Add line to [PHPFunctions] section in wrap_operator.ini
[PHPFunctions] PermittedFunctionList[]=ereg_replace
2. Call it in your template
{wrap_php_func('ereg_replace', array('sour', 'sweet', 'Grapes are sour.'))}
Calling internal php functions. wrap_user_func expects each user function to be defined in separate file,
It uses include_once to read it in, so be sure to use <?php ?> around code.
Suppose you want to use following silly function in template
<?php function silly_thing($who) { return($who . ' is silly!'); } ?>
To do this you must ...
1. Save the function in file, 'extension/wrap_operator/userfunctions/silly_thing.php'
2. Add line to [UserFunctions] section in the override setting file, 'wrap_operator.ini'
[UserFunctions] PermittedFunctionList[]=silly_thing
3. Call it in your template
{wrap_user_func('silly_thing', array('This function'))}
Having ability to call your php functions like this is a very nice feature I think, kind of simplified plugin system for operators.
No need to write whole extension for each simple function.
Functions you have written can be easily shared by pasting them to forum, wiki or svn. So share yours :)