Joomla插件内容挂钩无法正常工作

时间:2014-10-06 06:38:46

标签: joomla joomla-extensions

我是joomla的新手。我正在尝试学习一些扩展开发。我已经有WordPress主题和插件的经验。我想过滤文章中的电话号码并以适当的方式显示。为此,我编写了测试插件代码,但它没有过滤。我甚至试图在onContentPrepare()钩子中放置一个exit语句,但它不起作用。

/**
 * @package Joomla.Plugin
 * @subpackage Content.ClicktoCall
 * @since 3.0
 * @version 1.0.0
 */
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');

class eqlContentClicktoCall extends JPlugin {

    public function onContentPrepare($context, &$row, &$params, $page = 0) {
// Don't run this plugin when the content is being indexed
        exit();
        if ($context == 'com_finder.indexer') {
            return true;
        }
        if (is_object($row)) {
            return $this->clicktocall($row->text, $params);
        }
        return $this->clicktocall($row);
    }

    protected function clicktocall(&$text) {
        $pattern = '/(\d{4})(\d{3})(\d{4})/';
        $replace = "+92-$1-$2-$3";
        $text=preg_replace($pattern, $replace, $text);
        return true;
    }

}

如何让这个钩子工作?

1 个答案:

答案 0 :(得分:0)

你需要更改你的类名,有一种语法,如果不遵循,将导致插件不被触发。像这样重命名:

class plgContentClicktoCall extends JPlugin

此外,还有关于如何构建用于安装插件的清单的规则。

http://docs.joomla.org/Manifest_files http://svn.joomla.org/project/cms/development/trunk/tests/_data/installer_packages/plg_system_alpha/alpha.xml