【发布时间】:2014-11-30 09:44:26
【问题描述】:
我是 joomla 的新手。我正在尝试学习一些扩展开发。我已经有 WordPress 主题和插件方面的经验。我想过滤文章中的电话号码并以适当的方式显示。为此,我编写了测试插件代码,但它没有过滤。我什至尝试在 onContentPrepare() 挂钩中添加退出语句,但它不起作用。
/**
* @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;
}
}
我怎样才能让这个钩子起作用?
【问题讨论】:
-
它现在可以工作了我没有在插件之前添加前缀 plgContent。
-
你试过删除
exit();吗? -
是的,我把 exit() 用来检查它是否正常工作,实际上它没有被挂钩,因为我没有把 plgContent 放在我的插件类名中。我正在做一些项目:),我必须按原样工作,之后我将在 joomla 上进行研发什么、为什么、何时、如何、在哪里