I am developing a shortcodes plugin that searches trough Joomla content and creates html outputs from the matched string.
Currently I am using this
public function onContentPrepare($context, &$row, &$params, $page = 0){
if ($this->run_plg != 1)return;
require_once 'shortcodes.php';
$row->text = shortcodes($row->text);
return true;
}
And it works very well. As you can see this runs trough every Joomla content basically , including modules ( Not sure about Virtuemart or some other 3rd party extensions ) . But if you were to use the shortcode in your template files it would not find it.
So I am thinking on placing the function in onAfterRender like this:
function onAfterRender() {
require_once 'shortcodes.php';
$body = JResponse::getBody();
$body = shortcodes($body);
JResponse::setBody($body);
}
This would match the string anywhere on the site. My concern is the performance. Here is simple example of shortcodes function.
the original one is refined with PREG_SET_ORDER and runs only if the string from $shortcode['type'] is found.
So the question is , what would you recommend and why if you have time to explain.
Thank you and CONGRATS :)
JResponse::setBody
is deprecated as of Joomla 3.2 and replaced withJFactory::getApplication()->setBody()