Joomla插件没有被调用

时间:2012-07-24 06:35:41

标签: plugins joomla joomla1.5

这是我第一次尝试创建一个Joomla插件,我需要一些帮助才能让它工作。该插件非常简单,我想捕获HTTP_REFERER,检查请求是否来自Google有机或付费结果,将数据传递给会话var,然后将其与联系表单中的值一起提交。 (我的表单中有一个隐藏字段,它获取会话var值)。我使用RSForms创建表单,仅供参考。

一开始,我将以下代码硬编码到站点根目录下的index.php中,并且运行正常。现在,我正在尝试制作一个合适的插件,但是在加载页面时我无法启动它。我已经尝试了所有的系统方法,仍然没能让它运行。

这是我的代码:

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

class plgSystemRsformsGoogleReferer extends JPlugin
{

    public function plgSystemRsformsGoogleReferer( &$subject, $config )
    {
        parent::__construct( $subject, $config );
    }


    function onAfterRender()
    {
        $session = & JFactory::getSession();
        if (!$session->get('referrer', $origref, 'extref')) //If does not exist
        {
          $origref = $_SERVER['HTTP_REFERER'];
          $session->set('referrer', $origref, 'extref');
          $q =  search_engine_query_string($session->get('referrer', $origref, 'extref'));

          if(stristr($origref, 'aclk')) { // if referer is a google adwords link as opposed to an organic link
              $type = ', paid link';
          } else {
              $type = ', organic result';
          }

        $ginfo = $q.$type;
        $session->set('referrer', $ginfo, 'extref');  

        }

        function search_engine_query_string($url = false) {
            if(!$url && !$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false) {
                return '';
            }

            $parts_url = parse_url($url);
            $query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
            if(!$query) {
                return '';
            }
            parse_str($query, $parts_query);
            return isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['p']) ? $parts_query['p'] : '');
        }
    }
}

这是我的插件安装的清单xml(安装工作正常):

<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="system" method="upgrade">
    <name>RSForm Google Referer v1.1</name>
    <author>Me</author>
    <creationDate>July 2012</creationDate>
    <copyright>(C) 2004-2012 www.mysite.com</copyright>
    <license>Commercial</license>
    <authorEmail>info@mysite.com</authorEmail>
    <authorUrl>www.mysite.com</authorUrl>
    <version>1.1</version>
    <description><![CDATA[Track visitor's search terms and and attaches the information to the RSForm! Pro Forms emails when sent.]]></description>
    <files>
        <filename plugin="rsform_google_referer">rsform_google_referer.php</filename>
    </files>
</install>

我觉得我很接近,但我无法让它运行,任何建议都将受到赞赏。谢谢!

1 个答案:

答案 0 :(得分:4)

班级名称错了。它需要匹配插件文件夹的名称和插件文件的名称。它应该是:

class plgSystemRsform_Google_Referer extends JPlugin

这是Rsform而不是Rsforms和下划线。

相关问题