Referer Class Reference
[Lib]
Referer extends URL and adds some search engine recognition routines. More...
Public Member Functions |
|
__construct ($referer_url= '') | |
Constructor. |
|
build ($mode=Url::ABSOLUTE, $encoding=Url::ENCODE_PARAMS) | |
Returns this query as a string. |
|
get_original_referer_url () | |
Returns original referer URL. |
|
is_external () | |
Returns true if referer is external.
|
|
is_internal () | |
Returns true if referer is internal.
|
|
search_engine_info () | |
Returns search engine information if referer
is a search engine, else false. |
|
Static Public Member Functions |
|
static | create ($s_url) |
Create new
Referer instancwe. |
|
static | current () |
Constructor. |
Detailed Description
Referer extends URL and adds some search engine recognition routines.
Definition at line 8 of file referer.cls.php.
Constructor & Destructor Documentation
Referer::__construct | ( | $ | referer_url = '' |
) |
Constructor.
Definition at line 35 of file referer.cls.php.
00035 { 00036 $this->original = $referer_url; 00037 parent::__construct($referer_url); 00038 }
Member Function Documentation
Referer::build | ( | $ | mode = Url::ABSOLUTE , |
|
$ | encoding = Url::ENCODE_PARAMS |
|||
) |
Returns this query as a string.
The URL is not ready for outputting it on an HTML page, it must be HTMLescaped before! It is however URL escaped.
- Returns:
- string This Url as a string.
- Exceptions:
-
Throws an exception if hostname is empty
Reimplemented from Url.
Definition at line 49 of file referer.cls.php.
00049 { 00050 if ($this->is_valid()) { 00051 return parent::build($mode, $encoding); 00052 } 00053 return ''; 00054 }
static Referer::create | ( | $ | s_url | ) | [static] |
static Referer::current | ( | ) | [static] |
Constructor.
- Returns:
- Referer
Reimplemented from Url.
Definition at line 17 of file referer.cls.php.
00017 { 00018 $referer = Arr::get_item($_SERVER, 'HTTP_REFERER', ''); 00019 return new Referer($referer); 00020 }
Referer::get_original_referer_url | ( | ) |
Referer::is_external | ( | ) |
Returns true if referer is external.
Definition at line 77 of file referer.cls.php.
00077 { 00078 return (!$this->is_empty() && !$this->is_internal()); 00079 }
Referer::is_internal | ( | ) |
Returns true if referer is internal.
Definition at line 69 of file referer.cls.php.
00069 { 00070 $url = Url::current(); 00071 return ($this->get_host() == $url->get_host()); 00072 }
Referer::search_engine_info | ( | ) |
Returns search engine information if referer is a search engine, else false.
Computation may be expensive, so handle with care.
Routine checks, if keywords are provided with referer, if not, referer is not recognized as a search engine!
- Returns:
- mixed False if referer is no searchengine, an associateive array with fields 'domain', 'host', and 'keywords' otherwise
Definition at line 90 of file referer.cls.php.
00090 { 00091 if (!$this->is_external()) { 00092 return false; 00093 } 00094 $query_params = $this->get_query_params(); 00095 if (count($query_params) == 0) { 00096 return false; // No params, no keywords... 00097 } 00098 00099 $arr_se = $this->get_search_engines(); 00100 $host = false; 00101 // We are interested in search engines that provide a query only 00102 foreach($query_params as $query_param => $query_value) { 00103 $possible_searchengine_sld = Arr::get_item($arr_se, $query_param, false); 00104 if ($possible_searchengine_sld !== false) { 00105 // We have a query param that *may* contain keywords 00106 // depending on referer domain ('q' are keywords for google, but not for a Drupal page) 00107 if (empty($host)) { 00108 // Only parse host (expensive!) if needed 00109 $host = $this->parse_host(); 00110 } 00111 if (in_array($host['sld'], $possible_searchengine_sld)) { 00112 // We have a query parameter and a domain that belong to a search engine. Return 00113 return array( 00114 'domain' => $host['domain'], 00115 'searchengine' => $host['sld'], 00116 'host' => $this->get_host(), 00117 'keywords' => $query_value 00118 ); 00119 } 00120 } 00121 } 00122 00123 return false; 00124 }
The documentation for this class was generated from the following file:
- gyro/core/lib/components/referer.cls.php