[eluser]Madmartigan1[/eluser]
I'm looking for a good solution for executing PHP code within database content. I'm using a WYSIWYG editor to manage page content, and need to be able to execute various CI and PHP functions.
I've used Dwoo, but I don't need a full template parsing engine.
I just want to be able to alias certain whitelisted functions and parse a (very large) string (the database content).
No IF blocks or even variables.
I've had some success and was able to do some simple single argument functions, and then switched things up and used call_user_func_array() to output some CI stuff, turning {class:method(arg)} into $this->class->method($arg), but it was very slow and rigid.
I would like to know if anyone has any advice on this, maybe some useful links or alternatives methods. I'm coming up totally dry on google.
Here is the code I'm using to parse simple tokens that represent PHP functions with one argument:
Code:
// token format {function:argument}
// This will turn {date:Y} into <?php echo date("Y"); ?>, for instance
// this is just an example of what i want to do
private function _parse($str)
{
$l_delim = '{';
$r_delim = '}';
$parsed = preg_replace_callback(
'/' . $l_delim . '(.*?):(.*?)' . $r_delim . '/',
create_function('$match', 'return $match[1]($match[2]);'),
$str
);
return $parsed;
}