ultimix
search_engines.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $Security = false;
39  var $Text = false;
40 
51  function __construct()
52  {
53  try
54  {
55  $this->Security = get_package( 'security' , 'last' , __FILE__ );
56  $this->Text = get_package( 'string::text' , 'last' , __FILE__ );
57  }
58  catch( Exception $e )
59  {
60  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
61  }
62  }
63 
82  function get_referer()
83  {
84  try
85  {
86  $URL = '';
87 
88  if( $this->Security->get_gp( 'referer' , 'raw' , '' ) != '' )
89  {
90  $URL = $this->Security->get_gp( 'referer' , 'raw' );
91  }
92  else
93  {
94  $URL = $this->Security->get_srv( 'HTTP_REFERER' , 'raw' , false );
95  }
96 
97  return( $URL );
98  }
99  catch( Exception $e )
100  {
101  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
102  }
103  }
104 
135  function test_crawler( $CrawlerUrl , $CrawlerName , $Crawler )
136  {
137  try
138  {
139  $URL = $this->get_referer();
140 
141  if( $Crawler === false && stristr( $URL , $CrawlerUrl ) )
142  {
143  $Crawler = $CrawlerName;
144  }
145 
146  return( $Crawler );
147  }
148  catch( Exception $e )
149  {
150  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
151  }
152  }
153 
178  function get_search_engine()
179  {
180  try
181  {
182  if( $this->get_referer() === false )
183  {
184  return( false );
185  }
186 
187  $Crawler = false;
188 
189  $Crawler = $this->test_crawler( 'google.' , 'Google' , $Crawler );
190  $Crawler = $this->test_crawler( 'yandex.' , 'Yandex' , $Crawler );
191  $Crawler = $this->test_crawler( 'qip.ru' , 'Qip' , $Crawler );
192  $Crawler = $this->test_crawler( 'mail.ru' , 'Mail' , $Crawler );
193  $Crawler = $this->test_crawler( 'rambler.ru' , 'Rambler' , $Crawler );
194  $Crawler = $this->test_crawler( 'bing.com' , 'Bing' , $Crawler );
195  $Crawler = $this->test_crawler( 'nigma.ru' , 'Nigma' , $Crawler );
196  $Crawler = $this->test_crawler( 'webalta.ru' , 'Webalta' , $Crawler );
197  $Crawler = $this->test_crawler( 'ukr.net' , 'Ukr.net' , $Crawler );
198  $Crawler = $this->test_crawler( 'conduit.com' , 'Conduit' , $Crawler );
199 
200  return( $Crawler );
201  }
202  catch( Exception $e )
203  {
204  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
205  }
206  }
207 
226  function get_search_prefix()
227  {
228  try
229  {
230  $SearchEngine = $this->get_search_engine();
231 
232  $Search = false;
233 
234  switch( $SearchEngine )
235  {
236  case( 'Google' ):
237  case( 'Webalta' ):
238  case( 'Mail' ):
239  case( 'Bing' ):
240  case( 'Conduit' ):
241  case( 'Ukr.net' ):$Search = 'q=';break;
242  case( 'Yandex' ):$Search = 'text=';break;
243  case( 'Qip' ):
244  case( 'Rambler' ):$Search = 'query=';break;
245  case( 'Nigma' ):$Search = 's=';break;
246  }
247 
248  return( $Search );
249  }
250  catch( Exception $e )
251  {
252  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
253  }
254  }
255 
278  function get_search_query()
279  {
280  try
281  {
282  $Search = $this->get_search_prefix();
283 
284  if( $Search !== false )
285  {
286  $URL = $this->get_referer();
287 
288  $Phrase = urldecode( urldecode( $URL ) );
289 
290  preg_match( "/[\?\&]{1}$Search([^\&\#]*)/" , "$Phrase&" , $Phrase2 );
291 
292  return( isset( $Phrase2[ 1 ] ) ? $this->Text->iconv( false , 'utf-8' , $Phrase2[ 1 ] ) : false );
293  }
294  else
295  {
296  return( false );
297  }
298  }
299  catch( Exception $e )
300  {
301  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
302  }
303  }
304 
324  {
325  try
326  {
327  $Redir = $this->get_search_engine();
328 
329  return( $Redir === false ? false : true );
330  }
331  catch( Exception $e )
332  {
333  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
334  }
335  }
336  }
337 ?>