I want to write a Joomla add-in for articles that I can add a count down timer. I would like to be able to run it using, for example, shortcode [countdowntimer date = "23-9-2017" time = "13:42"]
. I do not know just how can I add parameters to the shortcode and move them to my module. Replacing [countdowntimer]
on my counter I've already done.
<?php
defined( '_JEXEC' ) or die();
class plgContentShortcode extends JPlugin
{
protected $autoloadLanguage = true;
function onContentPrepare ($context, $article, $params, $limitstart)
{
// preg_match("/([[]countdowntimer(.*)[]])/", $article->text, $tmp, PREG_OFFSET_CAPTURE);
// I'm trying to extract parameters in this way
// preg_match("/date=\"([0-9-]+)\"/", $tmp[2][0], $return_tmp['date'], PREG_OFFSET_CAPTURE); //date
// preg_match("/time=\"([0-9:]+)\"/", $tmp[2][0], $return_tmp['time'], PREG_OFFSET_CAPTURE); // time
$article->text = preg_replace('/([[]countdowntimer(.*)[]])/', '{loadmodule mod_countdowntimer}', $article->text);
return true;
}
}
?>
In the title you mentioned that you have a "error". But you don't say what the exact problem is with your code (beside that it doesn't work). Instead of coding you're own plugin, you can use a existing extension for this: https://extensions.joomla.org/extension/modules-anywhere/. This extension can do exactly what you want.
But if you like to create you're own plugin, take a look at the JModuleHelper
class to load the module with parameters (see: https://api.joomla.org/cms-3/classes/JModuleHelper.html). The result of JModuleHelper::renderModule
is a string that can be append to $article->text