Permalink
Browse files

First public release

  • Loading branch information...
1 parent 50f1c8e commit 4c01fd3b4d2433be60c9163d30a2def0822bea13 @tyssen committed May 21, 2012
View
16 readme.md
@@ -1,3 +1,17 @@
# Referrer Keywords
-To come.
+This plugin is to be used in conjunction with ExpressionEngine's first party Referrer module. You could just do this:
+
+{exp:referrer limit="1"}{ref_from}{/exp:referrer}
+
+but because the module automatically outputs {ref_from} with an anchor tag wrapped around it, if you try to use that in a hidden form input in a contact form, it'll break your page.
+
+So this plugin just strips out the unnecessary HTML and returns a string including the referrer and the keywords (if the referrer is a search engine).
+
+Place {exp:referrer limit="1"}{exp:referrer_keywords}{ref_from}{/exp:referrer_keywords}{/exp:referrer} somewhere in your template.
+
+## Changelog
+
+### 1.0.0
+--------------------
+Initial public release
View
143 system/expressionengine/third_party/referrer_keywords/ext.referrer_keywords.php
@@ -1,143 +0,0 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
-
-/**
- * ExpressionEngine - by EllisLab
- *
- * @package ExpressionEngine
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2003 - 2011, EllisLab, Inc.
- * @license http://expressionengine.com/user_guide/license.html
- * @link http://expressionengine.com
- * @since Version 2.0
- * @filesource
- */
-
-// ------------------------------------------------------------------------
-
-/**
- * Referrer Keywords Extension
- *
- * @package ExpressionEngine
- * @subpackage Addons
- * @category Extension
- * @author John Faulds
- * @link http://www.tyssendesign.com.au
- */
-
-class Referrer_keywords_ext {
-
- public $settings = array();
- public $description = 'Returns the keywords visitors from Google used to find your site';
- public $docs_url = '';
- public $name = 'Referrer Keywords';
- public $settings_exist = 'n';
- public $version = '1.0';
-
- private $EE;
-
- /**
- * Constructor
- *
- * @param mixed Settings array or empty string if none exist.
- */
- public function __construct($settings = '')
- {
- $this->EE =& get_instance();
- $this->settings = $settings;
- }// ----------------------------------------------------------------------
-
- /**
- * Activate Extension
- *
- * This function enters the extension into the exp_extensions table
- *
- * @see http://codeigniter.com/user_guide/database/index.html for
- * more information on the db class.
- *
- * @return void
- */
- public function activate_extension()
- {
- // Setup custom settings in this array.
- $this->settings = array();
-
- $data = array(
- 'class' => __CLASS__,
- 'method' => 'referrer_keywords',
- 'hook' => 'sessions_start',
- 'settings' => serialize($this->settings),
- 'version' => $this->version,
- 'enabled' => 'y'
- );
-
- $this->EE->db->insert('extensions', $data);
-
- }
-
- // ----------------------------------------------------------------------
-
- /**
- * referrer_keywords
- *
- * @param
- * @return
- */
- public function referrer_keywords()
- {
- $keywords="";
-
- // Get the full referring URL
- $referrer = ( ! isset($_SERVER['HTTP_REFERER'])) ? '' : $this->EE->security->xss_clean($_SERVER['HTTP_REFERER']);
-
- if (eregi("www.google",$referrer)) {
- preg_match("'q=(.*?)(&| )'si", " $referrer ", $keywords);
- }
-
- if (($keywords[1]!="") and ($keywords[1]!=" ")) {
- $keywords=eregi_replace("/+/"," ",$keywords[1]);
- $keywords=eregi_replace("%2B"," ",$keywords);
- $keywords=eregi_replace("%2E",".",$keywords);
- $keywords=trim(eregi_replace('%22','"',$keywords));
- }
-
- $this->EE->config->_global_vars['keywords'] = $keywords;
- }
-
- // ----------------------------------------------------------------------
-
- /**
- * Disable Extension
- *
- * This method removes information from the exp_extensions table
- *
- * @return void
- */
- function disable_extension()
- {
- $this->EE->db->where('class', __CLASS__);
- $this->EE->db->delete('extensions');
- }
-
- // ----------------------------------------------------------------------
-
- /**
- * Update Extension
- *
- * This function performs any necessary db updates when the extension
- * page is visited
- *
- * @return mixed void on update / false if none
- */
- function update_extension($current = '')
- {
- if ($current == '' OR $current == $this->version)
- {
- return FALSE;
- }
- }
-
- // ----------------------------------------------------------------------
-}
-
-/* End of file ext.referrer_keywords.php */
-/* Location: /system/expressionengine/third_party/referrer_keywords/ext.referrer_keywords.php */
View
102 system/expressionengine/third_party/referrer_keywords/pi.referrer_keywords.php
@@ -1,7 +1,7 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
- * Referrer Keywords Plugins - Saves the keywords from a referring search engine
+ * Referrer Keywords Plugin - Saves the keywords from a referring search engine
*
* @package ExpressionEngine
* @subpackage Addons
@@ -15,7 +15,7 @@
/**
* Changelog
*
-* Version 1.0.0 20120224
+* Version 1.0.0 20120521
* --------------------
* Initial public release
*
@@ -26,72 +26,48 @@
'pi_version' =>'1.0.0',
'pi_author' =>'John Faulds',
'pi_author_url' => 'http://www.tyssendesign.com.au',
- 'pi_description' => 'Referrer Keywords Plugins - Saves the keywords from a referring search engine',
- 'pi_usage' => Ress::usage()
+ 'pi_description' => 'Referrer Keywords Plugin - Extracts the keywords from a referring search engine querstring captured with EE’s first party Referrer module',
+ 'pi_usage' => Referrer_keywords::usage()
);
class Referrer_keywords {
+ var $return_data = '';
+
public function __construct()
{
$this->EE =& get_instance();
- }
- function set()
- {
- if(!isset $_SESSION['keywords'])
- {
- $keywords='';
-
- // Get the full referring URL
- $referrer = ( ! isset($_SERVER['HTTP_REFERER'])) ? '' : $this->EE->security->xss_clean($_SERVER['HTTP_REFERER']);
- $uri = parse_url($referrer);
-
-
- // Remove our own domain
- if($uri['host'] != 'www.tyssendesign.com.au')
- {
- // Get keywords from referrer
- $parsed = parse_url($referrer, PHP_URL_QUERY);
- parse_str($parsed, $query);
- $keywords = $query['q'];
-
- //if no active session we start a new one
- if (session_id() == "")
- {
- session_start();
- }
-
- $_SESSION['keywords'] = $keywords;
-
- }
- }
- }
- /* END */
+ $str = $this->EE->TMPL->tagdata;
- // --------------------------------------------------------------------
-
- /**
- * Get session variable
- */
- function get()
- {
- // if no active session we start a new one
- if (session_id() == "")
- {
- session_start();
- }
-
- if (isset($_SESSION['keywords']))
- {
- return $_SESSION['keywords'];
- }
-
- else
+ // Remove HTML from around the URL
+ preg_match('/\>(.*)<\/a>/', $str, $referrer);
+
+ // Parse the referrer URL
+ $parsed_url = parse_url($referrer[1]);
+ if (empty($parsed_url['host']))
+ return false;
+ $host = $parsed_url['host'];
+
+ // Parse the querystring
+ $query_str = (!empty($parsed_url['query'])) ? $parsed_url['query'] : '';
+ $query_str = (empty($query_str) && !empty($parsed_url['fragment'])) ? $parsed_url['fragment'] : $query_str;
+
+ // Start the output with the referrer
+ $output = 'Referrer: '. $host;
+
+ // If the referrer is a search engine output the value of the search query
+ if($query_str)
{
- return '';
+ parse_str($query_str);
+ $keywords = $q;
+ $output .= '; Keywords: '. $q;
}
+
+ $this->return_data = $output;
+
}
+
/* END */
// --------------------------------------------------------------------
@@ -109,11 +85,15 @@ public static function usage()
?>
Usage example:
- Place {exp:ress:cookie} somewhere in the head of your template to set a cookie based on your window's width.
+ This plugin is to be used in conjunction with ExpressionEngine's first party Referrer module. You could just do this:
+
+ {exp:referrer limit="1"}{ref_from}{/exp:referrer}
+
+ but because the module automatically outputs {ref_from} with an anchor tag wrapped around it, if you try to use that in a hidden form input in a contact form, it'll break your page.
- The screen width will then be available as an ExpressionEngine variable {ress} which you can use anywhere in your templates.
+ So this plugin just strips out the unnecessary HTML and returns a string including the referrer and the keywords (if the referrer is a search engine).
- Possible scenarios include hiding or showing certain content based on screen size, e.g.: {if {ress} > 480} show larger screen content {/if}
+ Place {exp:referrer limit="1"}{exp:referrer_keywords}{ref_from}{/exp:referrer_keywords}{/exp:referrer} somewhere in your template.
<?php
$buffer = ob_get_contents();
@@ -126,5 +106,5 @@ public static function usage()
}
-/* End of file pi.ress.php */
-/* Location: ./system/expressionengine/third_party/ress/pi.ress.php */
+/* End of file pi.referrer_keywords.php */
+/* Location: ./system/expressionengine/third_party/ress/pi.referrer_keywords.php */

0 comments on commit 4c01fd3

Please sign in to comment.