58 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
108 function set( $FieldName , $FieldValue )
110 $this->$FieldName = $FieldValue;
139 private function send_request( $Data , $Region = 0 )
143 $Header =
"Content-type: application/xml\r\nContent-length: " . strlen( $Data );
144 $HttpDescription = array(
'method' =>
"POST" ,
'content' => $Data ,
'header' => $Header );
145 $ContextDescription = array(
'http' => $HttpDescription );
146 $Context = stream_context_create( $ContextDescription );
148 $URL =
"http://xmlsearch.yandex.ru/xmlsearch?user=".
149 "$this->User&key=$this->Key".( $Region ?
"&lr=$Region" :
'' );
150 $Result = file_get_contents( $URL ,
true , $Context );
154 catch( Exception $e )
186 private function search_query( $Query , $Region = 0 )
190 $Data =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
192 <query>$Query</query>
194 <groupby attr=\"d\" mode=\"deep\" groups-on-page=\"100\" docs-in-group=\"1\" />
198 return( $this->send_request( $Data , $Region ) );
200 catch( Exception $e )
228 private function parse_response( $Response )
232 $XMLDoc =
new SimpleXMLElement( $Response );
234 return( $XMLDoc->xpath(
"response/results/grouping/group/doc" ) );
236 catch( Exception $e )
276 $Domain = str_ireplace(
'http://' ,
'' , $Domain );
277 $Domain = rtrim( $Domain ,
'/\\' );
279 $Response = $this->search_query( $Query , $Region );
281 $Response = $this->parse_response( $Response );
284 foreach( $Response as $Item )
286 if( strtolower( $Item->domain ) == strtolower( $Domain ) )
295 catch( Exception $e )
335 $Domain = str_ireplace(
'http://' ,
'' , $Domain );
336 $Domain = rtrim( $Domain ,
'/\\' );
337 $Response = $this->search_query( $Query , $Region );
338 $Response = $this->parse_response( $Response );
340 if( empty( $Response ) )
342 return( array(
false ,
false ) );
346 foreach( $Response as $Item )
348 if( strtolower( $Item->domain ) == strtolower( $Domain ) )
350 return( array( $Counter ,
"$Item->url" ) );
355 return( array( $Counter < count( $Response ) ? $Counter : 0 ,
'undefined' ) );
357 catch( Exception $e )
393 function get_url( $Domain , $Query , $Region = 0 )
397 $Domain = str_ireplace(
'http://' ,
'' , $Domain );
398 $Domain = rtrim( $Domain ,
'/\\' );
400 $Response = $this->search_query(
"$Query site:$Domain" , $Region );
402 $Response = $this->parse_response( $Response );
404 foreach( $Response as $Item )
406 if( strtolower( $Item->domain ) == strtolower( $Domain ) )
408 return(
"$Item->url" );
414 catch( Exception $e )