00001 <?php
00002
00003
00004
00005
00006
00007
00008 class Referer extends Url {
00009 private $keyword_query_key = false;
00010 private $original = '';
00011
00012
00013
00014
00015
00016
00017 public static function current() {
00018 $referer = Arr::get_item($_SERVER, 'HTTP_REFERER', '');
00019 return new Referer($referer);
00020 }
00021
00022
00023
00024
00025
00026
00027
00028 public static function create($s_url) {
00029 return new Referer($s_url);
00030 }
00031
00032
00033
00034
00035 public function __construct($referer_url = '') {
00036 $this->original = $referer_url;
00037 parent::__construct($referer_url);
00038 }
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 public function build($mode = Url::ABSOLUTE, $encoding = Url::ENCODE_PARAMS) {
00050 if ($this->is_valid()) {
00051 return parent::build($mode, $encoding);
00052 }
00053 return '';
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 public function get_original_referer_url() {
00063 return $this->original;
00064 }
00065
00066
00067
00068
00069 public function is_internal() {
00070 $url = Url::current();
00071 return ($this->get_host() == $url->get_host());
00072 }
00073
00074
00075
00076
00077 public function is_external() {
00078 return (!$this->is_empty() && !$this->is_internal());
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 public function search_engine_info() {
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;
00097 }
00098
00099 $arr_se = $this->get_search_engines();
00100 $host = false;
00101
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
00106
00107 if (empty($host)) {
00108
00109 $host = $this->parse_host();
00110 }
00111 if (in_array($host['sld'], $possible_searchengine_sld)) {
00112
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 }
00125
00126
00127
00128
00129 private function get_search_engines() {
00130 return array (
00131 'encquery' => array('aol'),
00132 'p' => array('yahoo'),
00133 'q' => array('google', 'msn', 'ask', 'altavista', 'alltheweb', 'gigablast', 'live', 'najdi', 'aol', 'club-internet', 'seznam', 'search', 'aolsvc', 't-online'),
00134 'qs' => array('virgilio', 'alice'),
00135 'qt' => array('looksmart'),
00136 'query' => array('aol', 'lycos', 'cnn', 'mamma', 'mama'),
00137 'rdata' => array('voila'),
00138 's' => array('netscape'),
00139 'terms' => array('about'),
00140 'text' => array('yandex'),
00141 'w' => array('seznam'),
00142 'wd' => array('baidu')
00143 );
00144 }
00145 }