The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Jul 24, 2012 6:48 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Oct 29, 2008 4:38 pm
Posts: 6
This is the 1st time I'm attempting to create a Joomla plugin and I need some help on getting this to work. The plugin is quite simple, I want to capture the HTTP_REFERER, check if the request was made from Google organic or paid results, pass the data to a session var and then submit it along with the values in a contact form. (there's a hidden field in my form and it gets the session var value). I use RSForms for creating my forms, just for the reference.

In the beginning, I hardcoded the following code into index.php at site root and it worked fine. Now, I'm trying to make a proper plugin but I can't get it to fire off when pages are loaded. I've tried all the system methods, still failing to get it to run.

This is my code:

Code:
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'] : '');
        }
    }
}


And this is my manifest xml for the plugin installation (installation works fine):

Code:
<?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>

I feel I'm close but I can't get it to run, any suggestions will be appreciated. Thanks!


Top
 Profile  
 
PostPosted: Tue Jul 24, 2012 7:49 am 
User avatar
Joomla! Master
Joomla! Master

Joined: Fri Aug 12, 2005 3:47 pm
Posts: 16641
Location: **Translation Matters**
NOTE: The license should be GPL. It does not prevent the plugin to be commercial.

_________________
Jean-Marie Simonet / infograf · http://www.info-graf.fr
Multilanguage in 2.5: http://help.joomla.org/files/EN-GB_multilang_tutorial.pdf
---------------------------------
Joomla Translation Coordination Team • Joomla! Production Working Group


Top
 Profile  
 
PostPosted: Tue Jul 24, 2012 12:48 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Oct 29, 2008 4:38 pm
Posts: 6
Thanks for pointing that out, i'll change it.


Top
 Profile  
 
PostPosted: Tue Jul 24, 2012 3:46 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Wed Oct 29, 2008 4:38 pm
Posts: 6
Finally figured it out myself. The <filename plugin="rsform_google_referer"> was different to the name of my function, changed it and it worked as expected.

One thing I am curious about though is that I got an error about undefined function search_engine_query_string() so I moved the function's code inline and everything was ok. Is there some problem with user defined functions when called inside a plugin or is there a mistake in the way I was making the call?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 



Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group