[ Index ] |
|
Code source de Cr@wltr@ck 2.2.1 |
1 <?php 2 //---------------------------------------------------------------------- 3 // CrawlTrack 2.2.1 4 //---------------------------------------------------------------------- 5 // Crawler Tracker for website 6 //---------------------------------------------------------------------- 7 // Author: Jean-Denis Brun 8 //---------------------------------------------------------------------- 9 // Website: www.crawltrack.fr 10 //---------------------------------------------------------------------- 11 // That script is distributed under GNU GPL license 12 //---------------------------------------------------------------------- 13 // file: searchenginespositionrefresh.php 14 //---------------------------------------------------------------------- 15 error_reporting(0); 16 //nusoap 17 /* 18 19 NuSOAP - Web Services Toolkit for PHP 20 21 Copyright (c) 2002 NuSphere Corporation 22 23 This library is free software; you can redistribute it and/or 24 modify it under the terms of the GNU Lesser General Public 25 License as published by the Free Software Foundation; either 26 version 2.1 of the License, or (at your option) any later version. 27 28 If you have any questions or comments, please email: 29 30 Dietrich Ayala 31 dietrich@ganx4.com 32 http://dietrich.ganx4.com/nusoap 33 34 NuSphere Corporation 35 http://www.nusphere.com 36 37 */ 38 39 class nusoap_base { 40 41 var $title = 'NuSOAP'; 42 var $version = '0.6.3'; 43 var $error_str = false; 44 var $debug_str = ''; 45 // toggles automatic encoding of special characters 46 var $charencoding = true; 47 48 /** 49 * set schema version 50 * 51 * @var XMLSchemaVersion 52 * @access public 53 */ 54 var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema'; 55 56 /** 57 * set default encoding 58 * 59 * @var soap_defencoding 60 * @access public 61 */ 62 //var $soap_defencoding = 'UTF-8'; 63 var $soap_defencoding = 'ISO-8859-1'; 64 65 /** 66 * load namespace uris into an array of uri => prefix 67 * 68 * @var namespaces 69 * @access public 70 */ 71 var $namespaces = array( 72 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/', 73 'xsd' => 'http://www.w3.org/2001/XMLSchema', 74 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 75 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/', 76 'si' => 'http://soapinterop.org/xsd'); 77 /** 78 * load types into typemap array 79 * is this legacy yet? 80 * no, this is used by the xmlschema class to verify type => namespace mappings. 81 * @var typemap 82 * @access public 83 */ 84 var $typemap = array( 85 'http://www.w3.org/2001/XMLSchema' => array( 86 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', 87 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'', 88 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string', 89 // derived datatypes 90 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'', 91 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer', 92 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer', 93 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''), 94 'http://www.w3.org/1999/XMLSchema' => array( 95 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', 96 'float'=>'double','dateTime'=>'string', 97 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), 98 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), 99 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), 100 'http://xml.apache.org/xml-soap' => array('Map') 101 ); 102 103 /** 104 * entities to convert 105 * 106 * @var xmlEntities 107 * @access public 108 */ 109 var $xmlEntities = array('quot' => '"','amp' => '&', 110 'lt' => '<','gt' => '>','apos' => "'"); 111 112 /** 113 * adds debug data to the class level debug string 114 * 115 * @param string $string debug data 116 * @access private 117 */ 118 function debug($string){ 119 $this->debug_str .= get_class($this).": $string\n"; 120 } 121 122 /** 123 * returns error string if present 124 * 125 * @return boolean $string error string 126 * @access public 127 */ 128 function getError(){ 129 if($this->error_str != ''){ 130 return $this->error_str; 131 } 132 return false; 133 } 134 135 /** 136 * sets error string 137 * 138 * @return boolean $string error string 139 * @access private 140 */ 141 function setError($str){ 142 $this->error_str = $str; 143 } 144 145 /** 146 * serializes PHP values in accordance w/ section 5 147 * @return string 148 * @access public 149 */ 150 function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false){ 151 if(is_object($val) && get_class($val) == 'soapval'){ 152 return $val->serialize(); 153 } 154 $this->debug( "in serialize_val: $val, $name, $type, $name_ns, $type_ns"); 155 // if no name, use item 156 $name = (!$name|| is_numeric($name)) ? 'soapVal' : $name; 157 // if name has ns, add ns prefix to name 158 $xmlns = ''; 159 if($name_ns){ 160 $prefix = 'nu'.rand(1000,9999); 161 $name = $prefix.':'.$name; 162 $xmlns .= " xmlns:$prefix=\"$name_ns\""; 163 } 164 // if type is prefixed, create type prefix 165 if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ 166 // need to fix this. shouldn't default to xsd if no ns specified 167 // w/o checking against typemap 168 $type_prefix = 'xsd'; 169 } elseif($type_ns){ 170 $type_prefix = 'ns'.rand(1000,9999); 171 $xmlns .= " xmlns:$type_prefix=\"$type_ns\""; 172 } 173 // serialize attributes if present 174 if($attributes){ 175 foreach($attributes as $k => $v){ 176 $atts .= " $k=\"$v\""; 177 } 178 } 179 // serialize if an xsd built-in primitive type 180 if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){ 181 return "<$name$xmlns xsi:type=\"xsd:$type\">$val</$name>"; 182 } 183 // detect type and serialize 184 $xml = ''; 185 $atts = ''; 186 switch(true) { 187 case ($type == '' && is_null($val)): 188 $xml .= "<$name$xmlns xsi:type=\"xsd:nil\"/>"; 189 break; 190 case (is_bool($val) || $type == 'boolean'): 191 if(!$val){ 192 $val = 0; 193 } 194 $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>"; 195 break; 196 case (is_int($val) || is_long($val) || $type == 'int'): 197 $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>"; 198 break; 199 case (is_float($val)|| is_double($val) || $type == 'float'): 200 $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>"; 201 break; 202 case (is_string($val) || $type == 'string'): 203 if($this->charencoding){ 204 $val = htmlspecialchars($val, ENT_QUOTES); 205 } 206 $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>"; 207 break; 208 case is_object($val): 209 break; 210 break; 211 case (is_array($val) || $type): 212 // detect if struct or array 213 $keyList = array_keys($val); 214 $valueType = 'arraySimple'; 215 foreach($keyList as $keyListValue){ 216 if(!is_int($keyListValue)){ 217 $valueType = 'arrayStruct'; 218 } 219 } 220 if($valueType=='arraySimple' || ereg('^ArrayOf',$type)){ 221 foreach($val as $v){ 222 if(is_object($v) && get_class($v) == 'soapval'){ 223 $tt = $v->type; 224 } else { 225 $tt = gettype($v); 226 } 227 $array_types[$tt] = 1; 228 $xml .= $this->serialize_val($v,'item'); 229 $i = 0; 230 if(is_array($v) && is_numeric(key($v))){ 231 $i += sizeof($v); 232 } else { 233 $i += 1; 234 } 235 } 236 if(count($array_types) > 1){ 237 $array_typename = 'xsd:ur-type'; 238 } elseif(isset($this->typemap[$this->XMLSchemaVersion][$tt])) { 239 $array_typename = 'xsd:'.$tt; 240 } elseif($tt == 'array' || $tt == 'Array'){ 241 $array_typename = 'SOAP-ENC:Array'; 242 } else { 243 $array_typename = $tt; 244 } 245 if(isset($array_types['array'])){ 246 $array_type = $i.",".$i; 247 } else { 248 $array_type = $i; 249 } 250 $xml = "<$name xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"$atts>".$xml."</$name>"; 251 } else { 252 // got a struct 253 if(isset($type) && isset($type_prefix)){ 254 $type_str = " xsi:type=\"$type_prefix:$type\""; 255 } else { 256 $type_str = ''; 257 } 258 $xml .= "<$name$xmlns$type_str$atts>"; 259 foreach($val as $k => $v){ 260 $xml .= $this->serialize_val($v,$k); 261 } 262 $xml .= "</$name>"; 263 } 264 break; 265 default: 266 $xml .= 'not detected, got '.gettype($val).' for '.$val; 267 break; 268 } 269 return $xml; 270 } 271 272 /** 273 * serialize message 274 * 275 * @param string body 276 * @param string headers 277 * @param array namespaces 278 * @return string message 279 * @access public 280 */ 281 function serializeEnvelope($body,$headers=false,$namespaces=array()){ 282 // serialize namespaces 283 $ns_string = ''; 284 foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ 285 $ns_string .= " xmlns:$k=\"$v\""; 286 } 287 // serialize headers 288 if($headers){ 289 $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>"; 290 } 291 // serialize envelope 292 return 293 '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">". 294 '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">". 295 $headers. 296 "<SOAP-ENV:Body>". 297 $body. 298 "</SOAP-ENV:Body>". 299 "</SOAP-ENV:Envelope>"; 300 } 301 302 function formatDump($str){ 303 $str = htmlspecialchars($str); 304 return nl2br($str); 305 } 306 307 /** 308 * returns the local part of a prefixed string 309 * returns the original string, if not prefixed 310 * 311 * @param string 312 * @return string 313 * @access public 314 */ 315 function getLocalPart($str){ 316 if($sstr = strrchr($str,':')){ 317 // get unqualified name 318 return substr( $sstr, 1 ); 319 } else { 320 return $str; 321 } 322 } 323 324 /** 325 * returns the prefix part of a prefixed string 326 * returns false, if not prefixed 327 * 328 * @param string 329 * @return mixed 330 * @access public 331 */ 332 function getPrefix($str){ 333 if($pos = strrpos($str,':')){ 334 // get prefix 335 return substr($str,0,$pos); 336 } 337 return false; 338 } 339 340 function varDump($data) { 341 ob_start(); 342 var_dump($data); 343 $ret_val = ob_get_contents(); 344 ob_end_clean(); 345 return $ret_val; 346 } 347 } 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 /** 366 * transport class for sending/receiving data via HTTP and HTTPS 367 * NOTE: PHP must be compiled with the CURL extension for HTTPS support 368 * 369 * @author Dietrich Ayala <dietrich@ganx4.com> 370 * @version v 0.6.3 371 * @access public 372 */ 373 class soap_transport_http extends nusoap_base { 374 375 var $username = ''; 376 var $password = ''; 377 var $url = ''; 378 var $proxyhost = ''; 379 var $proxyport = ''; 380 var $scheme = ''; 381 var $protocol_version = '1.0'; 382 var $encoding = ''; 383 var $outgoing_payload = ''; 384 var $incoming_payload = ''; 385 386 /** 387 * constructor 388 */ 389 function soap_transport_http($url){ 390 $this->url = $url; 391 $u = parse_url($url); 392 foreach($u as $k => $v){ 393 $this->debug("$k = $v"); 394 $this->$k = $v; 395 } 396 if(isset($u['query']) && $u['query'] != ''){ 397 $this->path .= '?' . $u['query']; 398 } 399 if(!isset($u['port']) && $u['scheme'] == 'http'){ 400 $this->port = 80; 401 } 402 } 403 404 /** 405 * if authenticating, set user credentials here 406 * 407 * @param string $user 408 * @param string $pass 409 * @access public 410 */ 411 function setCredentials($username, $password) { 412 $this->username = $username; 413 $this->password = $password; 414 } 415 416 /** 417 * set the soapaction value 418 * 419 * @param string $soapaction 420 * @access public 421 */ 422 function setSOAPAction($soapaction) { 423 $this->soapaction = $soapaction; 424 } 425 426 /** 427 * set proxy info here 428 * 429 * @param string $proxyhost 430 * @param string $proxyport 431 * @access public 432 */ 433 function setProxy($proxyhost, $proxyport) { 434 $this->proxyhost = $proxyhost; 435 $this->proxyport = $proxyport; 436 } 437 438 /** 439 * send the SOAP message via HTTP 440 * 441 * @param string $data message data 442 * @param integer $timeout set timeout in seconds 443 * @return string data 444 * @access public 445 */ 446 function send($data, $timeout=0) { 447 448 $this->debug('entered send() with data of length: '.strlen($data)); 449 // proxy 450 if($this->proxyhost != '' && $this->proxyport != ''){ 451 $host = $this->proxyhost; 452 $port = $this->proxyport; 453 $this->debug("using http proxy: $host, $port"); 454 } else { 455 $host = $this->host; 456 $port = $this->port; 457 } 458 // ssl 459 if($this->scheme == 'https'){ 460 $host = 'ssl://'.$host; 461 $port = 443; 462 } 463 464 $this->debug("connection params: $host, $port"); 465 // timeout 466 if($timeout > 0){ 467 $fp = fsockopen($host, $port, $this->errno, $this->error_str, $timeout); 468 } else { 469 $fp = fsockopen($host, $port, $this->errno, $this->error_str); 470 } 471 472 // test pointer 473 if(!$fp) { 474 $this->debug('Couldn\'t open socket connection to server '.$this->url.', Error: '.$this->error_str); 475 $this->setError('Couldn\'t open socket connection to server: '.$this->url.', Error: '.$this->error_str); 476 return false; 477 } 478 $this->debug('socket connected'); 479 // http auth 480 $credentials = ''; 481 if($this->username != '') { 482 $this->debug('setting http auth credentials'); 483 $credentials = 'Authorization: Basic '.base64_encode("$this->username:$this->password").'\r\n'; 484 } 485 // swap url for path if going through a proxy 486 if($this->proxyhost != '' && $this->proxyport != ''){ 487 $this->outgoing_payload = "POST $this->url ".strtoupper($this->scheme)."/$this->protocol_version\r\n"; 488 } else { 489 $this->outgoing_payload = "POST $this->path ".strtoupper($this->scheme)."/$this->protocol_version\r\n"; 490 } 491 // set encoding headers 492 if($this->encoding != '' && function_exists('gzdeflate')){ 493 $encoding_headers = "Accept-Encoding: $this->encoding\r\n". 494 "Connection: close\r\n"; 495 set_magic_quotes_runtime(0); 496 } else { 497 $encoding_headers = ''; 498 } 499 // make payload 500 $this->outgoing_payload .= 501 "User-Agent: $this->title/$this->version\r\n". 502 //"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n". 503 "Host: ".$this->host."\r\n". 504 $credentials. 505 "Content-Type: text/xml\r\nContent-Length: ".strlen($data)."\r\n". 506 $encoding_headers. 507 "SOAPAction: \"$this->soapaction\""."\r\n\r\n". 508 $data; 509 510 // send payload 511 if(!fputs($fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { 512 $this->setError('couldn\'t write message data to socket'); 513 $this->debug('Write error'); 514 } 515 $this->debug('wrote data to socket'); 516 517 // get response 518 $this->incoming_payload = ''; 519 //$strlen = 0; 520 while( $data = fread($fp, 32768) ){ 521 $this->incoming_payload .= $data; 522 //$strlen += strlen($data); 523 } 524 $this->debug('received '.strlen($this->incoming_payload).' bytes of data from server'); 525 526 // close filepointer 527 fclose($fp); 528 $this->debug('closed socket'); 529 530 // connection was closed unexpectedly 531 if($this->incoming_payload == ''){ 532 $this->setError('no response from server'); 533 return false; 534 } 535 536 $this->debug('received incoming payload: '.strlen($this->incoming_payload)); 537 $data = $this->incoming_payload."\r\n\r\n\r\n\r\n"; 538 539 // remove 100 header 540 if(ereg('^HTTP/1.1 100',$data)){ 541 if($pos = strpos($data,"\r\n\r\n") ){ 542 $data = ltrim(substr($data,$pos)); 543 } elseif($pos = strpos($data,"\n\n") ){ 544 $data = ltrim(substr($data,$pos)); 545 } 546 }// 547 548 // separate content from HTTP headers 549 if( $pos = strpos($data,"\r\n\r\n") ){ 550 $lb = "\r\n"; 551 } elseif( $pos = strpos($data,"\n\n") ){ 552 $lb = "\n"; 553 } else { 554 $this->setError('no proper separation of headers and document'); 555 return false; 556 } 557 $header_data = trim(substr($data,0,$pos)); 558 $header_array = explode($lb,$header_data); 559 $data = ltrim(substr($data,$pos)); 560 $this->debug('found proper separation of headers and document'); 561 $this->debug('cleaned data, stringlen: '.strlen($data)); 562 // clean headers 563 foreach($header_array as $header_line){ 564 $arr = explode(':',$header_line); 565 if(count($arr) >= 2){ 566 $headers[trim($arr[0])] = trim($arr[1]); 567 } 568 } 569 //print "headers: <pre>$header_data</pre><br>"; 570 //print "data: <pre>$data</pre><br>"; 571 572 // decode transfer-encoding 573 if(isset($headers['Transfer-Encoding']) && $headers['Transfer-Encoding'] == 'chunked'){ 574 //$timer->setMarker('starting to decode chunked content'); 575 if(!$data = $this->decodeChunked($data)){ 576 $this->setError('Decoding of chunked data failed'); 577 return false; 578 } 579 //$timer->setMarker('finished decoding of chunked content'); 580 //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>"; 581 } 582 583 // decode content-encoding 584 if(isset($headers['Content-Encoding']) && $headers['Content-Encoding'] != ''){ 585 if($headers['Content-Encoding'] == 'deflate' || $headers['Content-Encoding'] == 'gzip'){ 586 // if decoding works, use it. else assume data wasn't gzencoded 587 if(function_exists('gzinflate')){ 588 //$timer->setMarker('starting decoding of gzip/deflated content'); 589 if($headers['Content-Encoding'] == 'deflate' && $degzdata = @gzinflate($data)){ 590 $data = $degzdata; 591 } elseif($headers['Content-Encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))){ 592 $data = $degzdata; 593 } else { 594 $this->setError('Errors occurred when trying to decode the data'); 595 } 596 //$timer->setMarker('finished decoding of gzip/deflated content'); 597 //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; 598 } else { 599 $this->setError('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.'); 600 } 601 } 602 } 603 604 if(strlen($data) == 0){ 605 $this->debug('no data after headers!'); 606 $this->setError('no data present after HTTP headers'); 607 return false; 608 } 609 $this->debug('end of send()'); 610 return $data; 611 } 612 613 614 /** 615 * send the SOAP message via HTTPS 1.0 using CURL 616 * 617 * @param string $msg message data 618 * @param integer $timeout set timeout in seconds 619 * @return string data 620 * @access public 621 */ 622 function sendHTTPS($data, $timeout=0) { 623 global $t; 624 $t->setMarker('inside sendHTTPS()'); 625 $this->debug('entered sendHTTPS() with data of length: '.strlen($data)); 626 // init CURL 627 $ch = curl_init(); 628 $t->setMarker('got curl handle'); 629 // set proxy 630 if($this->proxyhost && $this->proxyport){ 631 $host = $this->proxyhost; 632 $port = $this->proxyport; 633 } else { 634 $host = $this->host; 635 $port = $this->port; 636 } 637 // set url 638 $hostURL = ($port != '') ? "https://$host:$port" : "https://$host"; 639 // add path 640 $hostURL .= $this->path; 641 curl_setopt($ch, CURLOPT_URL, $hostURL); 642 // set other options 643 curl_setopt($ch, CURLOPT_HEADER, 1); 644 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 645 // encode 646 if(function_exists('gzinflate')){ 647 curl_setopt($ch, CURLOPT_ENCODING, 'deflate'); 648 } 649 // set timeout 650 if($timeout != 0){ 651 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 652 } 653 654 $credentials = ''; 655 if($this->username != '') { 656 $credentials = 'Authorization: Basic '.base64_encode("$this->username:$this->password").'\r\n'; 657 } 658 659 if($this->encoding != ''){ 660 if(function_exists('gzdeflate')){ 661 $encoding_headers = "Accept-Encoding: $this->encoding\r\n". 662 "Connection: close\r\n"; 663 set_magic_quotes_runtime(0); 664 } 665 } 666 667 if($this->proxyhost && $this->proxyport){ 668 $this->outgoing_payload = "POST $this->url HTTP/$this->protocol_version\r\n"; 669 } else { 670 $this->outgoing_payload = "POST $this->path HTTP/$this->protocol_version\r\n"; 671 } 672 673 $this->outgoing_payload .= 674 "User-Agent: $this->title v$this->version\r\n". 675 "Host: ".$this->host."\r\n". 676 $encoding_headers. 677 $credentials. 678 "Content-Type: text/xml\r\nContent-Length: ".strlen($data)."\r\n". 679 "SOAPAction: \"$this->soapaction\""."\r\n\r\n". 680 $data; 681 682 // set payload 683 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->outgoing_payload); 684 $t->setMarker('set curl options, executing...'); 685 // send and receive 686 $this->incoming_payload = curl_exec($ch); 687 $t->setMarker('executed transfer'); 688 $data = $this->incoming_payload; 689 690 $cErr = curl_error($ch); 691 692 if($cErr != ''){ 693 $err = 'cURL ERROR: '.curl_errno($ch).': '.$cErr.'<br>'; 694 foreach(curl_getinfo($ch) as $k => $v){ 695 $err .= "$k: $v<br>"; 696 } 697 $this->setError($err); 698 curl_close($ch); 699 return false; 700 } else { 701 echo '<pre>'; 702 var_dump(curl_getinfo($ch)); 703 echo '</pre>'; 704 } 705 // close curl 706 curl_close($ch); 707 $t->setMarker('closed curl'); 708 709 // remove 100 header 710 if(ereg('^HTTP/1.1 100',$data)){ 711 if($pos = strpos($data,"\r\n\r\n") ){ 712 $data = ltrim(substr($data,$pos)); 713 } elseif($pos = strpos($data,"\n\n") ){ 714 $data = ltrim(substr($data,$pos)); 715 } 716 }// 717 718 // separate content from HTTP headers 719 if( $pos = strpos($data,"\r\n\r\n") ){ 720 $lb = "\r\n"; 721 } elseif( $pos = strpos($data,"\n\n") ){ 722 $lb = "\n"; 723 } else { 724 $this->setError('no proper separation of headers and document'); 725 return false; 726 } 727 $header_data = trim(substr($data,0,$pos)); 728 $header_array = explode($lb,$header_data); 729 $data = ltrim(substr($data,$pos)); 730 $this->debug('found proper separation of headers and document'); 731 $this->debug('cleaned data, stringlen: '.strlen($data)); 732 // clean headers 733 foreach($header_array as $header_line){ 734 $arr = explode(':',$header_line); 735 $headers[trim($arr[0])] = trim($arr[1]); 736 } 737 if(strlen($data) == 0){ 738 $this->debug('no data after headers!'); 739 $this->setError('no data present after HTTP headers.'); 740 return false; 741 } 742 743 // decode transfer-encoding 744 if($headers['Transfer-Encoding'] == 'chunked'){ 745 //$timer->setMarker('starting to decode chunked content'); 746 if(!$data = $this->decodeChunked($data)){ 747 $this->setError('Decoding of chunked data failed'); 748 return false; 749 } 750 //$timer->setMarker('finished decoding of chunked content'); 751 //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>"; 752 } 753 // decode content-encoding 754 if($headers['Content-Encoding'] != ''){ 755 if($headers['Content-Encoding'] == 'deflate' || $headers['Content-Encoding'] == 'gzip'){ 756 // if decoding works, use it. else assume data wasn't gzencoded 757 if(function_exists('gzinflate')){ 758 //$timer->setMarker('starting decoding of gzip/deflated content'); 759 if($headers['Content-Encoding'] == 'deflate' && $degzdata = @gzinflate($data)){ 760 $data = $degzdata; 761 } elseif($headers['Content-Encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))){ 762 $data = $degzdata; 763 } else { 764 $this->setError('Errors occurred when trying to decode the data'); 765 } 766 //$timer->setMarker('finished decoding of gzip/deflated content'); 767 //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; 768 } else { 769 $this->setError('The server sent deflated data. Your php install must have the Zlib extension compiled in to support this.'); 770 } 771 } 772 } 773 // set decoded payload 774 $this->incoming_payload = $header_data."\r\n\r\n".$data; 775 return $data; 776 } 777 778 function setEncoding($enc='gzip, deflate'){ 779 $this->encoding = $enc; 780 $this->protocol_version = '1.1'; 781 } 782 783 // This function will decode "chunked' transfer encoding 784 // as defined in RFC2068 19.4.6 785 function decodeChunked($buffer){ 786 // length := 0 787 $length = 0; 788 $new = ''; 789 790 // read chunk-size, chunk-extension (if any) and CRLF 791 // get the position of the linebreak 792 $chunkend = strpos($buffer,"\r\n") + 2; 793 $temp = substr($buffer,0,$chunkend); 794 $chunk_size = hexdec( trim($temp) ); 795 $chunkstart = $chunkend; 796 // while (chunk-size > 0) { 797 while ($chunk_size > 0) { 798 799 $chunkend = strpos( $buffer, "\r\n", $chunkstart + $chunk_size); 800 801 // Just in case we got a broken connection 802 if ($chunkend == FALSE) { 803 $chunk = substr($buffer,$chunkstart); 804 // append chunk-data to entity-body 805 $new .= $chunk; 806 $length += strlen($chunk); 807 break; 808 } 809 810 // read chunk-data and CRLF 811 $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart); 812 // append chunk-data to entity-body 813 $new .= $chunk; 814 // length := length + chunk-size 815 $length += strlen($chunk); 816 // read chunk-size and CRLF 817 $chunkstart = $chunkend + 2; 818 819 $chunkend = strpos($buffer,"\r\n",$chunkstart)+2; 820 if ($chunkend == FALSE) { 821 break; //Just in case we got a broken connection 822 } 823 $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart); 824 $chunk_size = hexdec( trim($temp) ); 825 $chunkstart = $chunkend; 826 } 827 // Update headers 828 //$this->Header['content-length'] = $length; 829 //unset($this->Header['transfer-encoding']); 830 return $new; 831 } 832 833 } 834 835 836 837 /** 838 * 839 * soap_parser class parses SOAP XML messages into native PHP values 840 * 841 * @author Dietrich Ayala <dietrich@ganx4.com> 842 * @version v 0.6.3 843 * @access public 844 */ 845 class soap_parser extends nusoap_base { 846 847 var $xml = ''; 848 var $xml_encoding = ''; 849 var $method = ''; 850 var $root_struct = ''; 851 var $root_struct_name = ''; 852 var $root_header = ''; 853 var $document = ''; 854 // determines where in the message we are (envelope,header,body,method) 855 var $status = ''; 856 var $position = 0; 857 var $depth = 0; 858 var $default_namespace = ''; 859 var $namespaces = array(); 860 var $message = array(); 861 var $parent = ''; 862 var $fault = false; 863 var $fault_code = ''; 864 var $fault_str = ''; 865 var $fault_detail = ''; 866 var $depth_array = array(); 867 var $debug_flag = true; 868 var $soapresponse = NULL; 869 var $responseHeaders = ''; 870 // for multiref parsing: 871 // array of id => pos 872 var $ids = array(); 873 // array of id => hrefs => pos 874 var $multirefs = array(); 875 876 /** 877 * constructor 878 * 879 * @param string $xml SOAP message 880 * @param string $encoding character encoding scheme of message 881 * @access public 882 */ 883 function soap_parser($xml,$encoding='UTF-8',$method=''){ 884 $this->xml = $xml; 885 $this->xml_encoding = $encoding; 886 $this->method = $method; 887 888 // Check whether content has been read. 889 if(!empty($xml)){ 890 $this->debug('Entering soap_parser()'); 891 // Create an XML parser. 892 $this->parser = xml_parser_create($this->xml_encoding); 893 // Set the options for parsing the XML data. 894 //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); 895 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); 896 // Set the object for the parser. 897 xml_set_object($this->parser, $this); 898 // Set the element handlers for the parser. 899 xml_set_element_handler($this->parser, 'start_element','end_element'); 900 xml_set_character_data_handler($this->parser,'character_data'); 901 902 // Parse the XML file. 903 if(!xml_parse($this->parser,$xml,true)){ 904 // Display an error message. 905 $err = sprintf('XML error on line %d: %s', 906 xml_get_current_line_number($this->parser), 907 xml_error_string(xml_get_error_code($this->parser))); 908 $this->debug('parse error: '.$err); 909 $this->errstr = $err; 910 } else { 911 $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name); 912 // get final value 913 $this->soapresponse = $this->message[$this->root_struct]['result']; 914 // get header value 915 if($this->root_header != ""){ 916 $this->responseHeaders = $this->message[$this->root_header]['result']; 917 } 918 } 919 xml_parser_free($this->parser); 920 } else { 921 $this->debug('xml was empty, didn\'t parse!'); 922 $this->errstr = 'xml was empty, didn\'t parse!'; 923 } 924 } 925 926 /** 927 * start-element handler 928 * 929 * @param string $parser XML parser object 930 * @param string $name element name 931 * @param string $attrs associative array of attributes 932 * @access private 933 */ 934 function start_element($parser, $name, $attrs) { 935 // position in a total number of elements, starting from 0 936 // update class level pos 937 $pos = $this->position++; 938 // and set mine 939 $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>''); 940 // depth = how many levels removed from root? 941 // set mine as current global depth and increment global depth value 942 $this->message[$pos]['depth'] = $this->depth++; 943 944 // else add self as child to whoever the current parent is 945 if($pos != 0){ 946 $this->message[$this->parent]['children'] .= '|'.$pos; 947 } 948 // set my parent 949 $this->message[$pos]['parent'] = $this->parent; 950 // set self as current parent 951 $this->parent = $pos; 952 // set self as current value for this depth 953 $this->depth_array[$this->depth] = $pos; 954 // get element prefix 955 if(strpos($name,':')){ 956 // get ns prefix 957 $prefix = substr($name,0,strpos($name,':')); 958 // get unqualified name 959 $name = substr(strstr($name,':'),1); 960 } 961 // set status 962 if($name == 'Envelope'){ 963 $this->status = 'envelope'; 964 } elseif($name == 'Header'){ 965 $this->root_header = $pos; 966 $this->status = 'header'; 967 } elseif($name == 'Body'){ 968 $this->status = 'body'; 969 $this->body_position = $pos; 970 // set method 971 } elseif($this->status == 'body' && $pos == ($this->body_position+1)){ 972 $this->status = 'method'; 973 $this->root_struct_name = $name; 974 $this->root_struct = $pos; 975 $this->message[$pos]['type'] = 'struct'; 976 $this->debug("found root struct $this->root_struct_name, pos $this->root_struct"); 977 } 978 // set my status 979 $this->message[$pos]['status'] = $this->status; 980 // set name 981 $this->message[$pos]['name'] = htmlspecialchars($name); 982 // set attrs 983 $this->message[$pos]['attrs'] = $attrs; 984 985 // loop through atts, logging ns and type declarations 986 $attstr = ''; 987 foreach($attrs as $key => $value){ 988 $key_prefix = $this->getPrefix($key); 989 $key_localpart = $this->getLocalPart($key); 990 // if ns declarations, add to class level array of valid namespaces 991 if($key_prefix == 'xmlns'){ 992 if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){ 993 $this->XMLSchemaVersion = $value; 994 $this->namespaces['xsd'] = $this->XMLSchemaVersion; 995 $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance'; 996 } 997 $this->namespaces[$key_localpart] = $value; 998 // set method namespace 999 if($name == $this->root_struct_name){ 1000 $this->methodNamespace = $value; 1001 } 1002 // if it's a type declaration, set type 1003 } elseif($key_localpart == 'type'){ 1004 $value_prefix = $this->getPrefix($value); 1005 $value_localpart = $this->getLocalPart($value); 1006 $this->message[$pos]['type'] = $value_localpart; 1007 $this->message[$pos]['typePrefix'] = $value_prefix; 1008 if(isset($this->namespaces[$value_prefix])){ 1009 $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix]; 1010 } 1011 // should do something here with the namespace of specified type? 1012 } elseif($key_localpart == 'arrayType'){ 1013 $this->message[$pos]['type'] = 'array'; 1014 /* do arrayType ereg here 1015 [1] arrayTypeValue ::= atype asize 1016 [2] atype ::= QName rank* 1017 [3] rank ::= '[' (',')* ']' 1018 [4] asize ::= '[' length~ ']' 1019 [5] length ::= nextDimension* Digit+ 1020 [6] nextDimension ::= Digit+ ',' 1021 */ 1022 $expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]'; 1023 if(ereg($expr,$value,$regs)){ 1024 $this->message[$pos]['typePrefix'] = $regs[1]; 1025 $this->message[$pos]['arraySize'] = $regs[3]; 1026 $this->message[$pos]['arrayCols'] = $regs[4]; 1027 } 1028 } 1029 // log id 1030 if($key == 'id'){ 1031 $this->ids[$value] = $pos; 1032 } 1033 // root 1034 if($key_localpart == 'root' && $value == 1){ 1035 $this->status = 'method'; 1036 $this->root_struct_name = $name; 1037 $this->root_struct = $pos; 1038 $this->debug("found root struct $this->root_struct_name, pos $pos"); 1039 } 1040 // for doclit 1041 $attstr .= " $key=\"$value\""; 1042 } 1043 // get namespace - must be done after namespace atts are processed 1044 if(isset($prefix)){ 1045 $this->message[$pos]['namespace'] = $this->namespaces[$prefix]; 1046 $this->default_namespace = $this->namespaces[$prefix]; 1047 } else { 1048 $this->message[$pos]['namespace'] = $this->default_namespace; 1049 } 1050 if($this->status == 'header'){ 1051 $this->responseHeaders .= "<$name$attstr>"; 1052 } elseif($this->root_struct_name != ''){ 1053 $this->document .= "<$name$attstr>"; 1054 } 1055 } 1056 1057 /** 1058 * end-element handler 1059 * 1060 * @param string $parser XML parser object 1061 * @param string $name element name 1062 * @access private 1063 */ 1064 function end_element($parser, $name) { 1065 // position of current element is equal to the last value left in depth_array for my depth 1066 $pos = $this->depth_array[$this->depth--]; 1067 1068 // get element prefix 1069 if(strpos($name,':')){ 1070 // get ns prefix 1071 $prefix = substr($name,0,strpos($name,':')); 1072 // get unqualified name 1073 $name = substr(strstr($name,':'),1); 1074 } 1075 1076 // build to native type 1077 if(isset($this->body_position) && $pos > $this->body_position){ 1078 // deal w/ multirefs 1079 if(isset($this->message[$pos]['attrs']['href'])){ 1080 // get id 1081 $id = substr($this->message[$pos]['attrs']['href'],1); 1082 // add placeholder to href array 1083 $this->multirefs[$id][$pos] = "placeholder"; 1084 // add set a reference to it as the result value 1085 $this->message[$pos]['result'] =& $this->multirefs[$id][$pos]; 1086 // build complex values 1087 } elseif($this->message[$pos]['children'] != ""){ 1088 $this->message[$pos]['result'] = $this->buildVal($pos); 1089 } else { 1090 $this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']); 1091 if(is_numeric($this->message[$pos]['cdata']) ){ 1092 if( strpos($this->message[$pos]['cdata'],'.') ){ 1093 $this->message[$pos]['result'] = doubleval($this->message[$pos]['cdata']); 1094 } else { 1095 $this->message[$pos]['result'] = intval($this->message[$pos]['cdata']); 1096 } 1097 } else { 1098 $this->message[$pos]['result'] = $this->message[$pos]['cdata']; 1099 } 1100 } 1101 } 1102 1103 // switch status 1104 if($pos == $this->root_struct){ 1105 $this->status = 'body'; 1106 } elseif($name == 'Body'){ 1107 $this->status = 'header'; 1108 } elseif($name == 'Header'){ 1109 $this->status = 'envelope'; 1110 } elseif($name == 'Envelope'){ 1111 // resolve hrefs/ids 1112 if(sizeof($this->multirefs) > 0){ 1113 foreach($this->multirefs as $id => $hrefs){ 1114 $this->debug('resolving multirefs for id: '.$id); 1115 foreach($hrefs as $refPos => $ref){ 1116 $this->debug('resolving href at pos '.$refPos); 1117 $this->multirefs[$id][$refPos] = $this->buildval($this->ids[$id]); 1118 } 1119 } 1120 } 1121 } 1122 // set parent back to my parent 1123 $this->parent = $this->message[$pos]['parent']; 1124 // for doclit 1125 if($this->status == 'header'){ 1126 $this->responseHeaders .= "</$name>"; 1127 } elseif($pos >= $this->root_struct){ 1128 $this->document .= "</$name>"; 1129 } 1130 } 1131 1132 /** 1133 * element content handler 1134 * 1135 * @param string $parser XML parser object 1136 * @param string $data element content 1137 * @access private 1138 */ 1139 function character_data($parser, $data){ 1140 $pos = $this->depth_array[$this->depth]; 1141 $this->message[$pos]['cdata'] .= $data; 1142 // for doclit 1143 if($this->status == 'header'){ 1144 $this->responseHeaders .= $data; 1145 } else { 1146 $this->document .= $data; 1147 } 1148 } 1149 1150 /** 1151 * get the parsed message 1152 * 1153 * @return mixed 1154 * @access public 1155 */ 1156 function get_response(){ 1157 return $this->soapresponse; 1158 } 1159 1160 /** 1161 * get the parsed headers 1162 * 1163 * @return string XML or empty if no headers 1164 * @access public 1165 */ 1166 function getHeaders(){ 1167 return $this->responseHeaders; 1168 } 1169 1170 /** 1171 * decodes entities 1172 * 1173 * @param string $text string to translate 1174 * @access private 1175 */ 1176 function decode_entities($text){ 1177 foreach($this->entities as $entity => $encoded){ 1178 $text = str_replace($encoded,$entity,$text); 1179 } 1180 return $text; 1181 } 1182 1183 /** 1184 * builds response structures for compound values (arrays/structs) 1185 * 1186 * @param string $pos position in node tree 1187 * @access private 1188 */ 1189 function buildVal($pos){ 1190 if(!isset($this->message[$pos]['type'])){ 1191 $this->message[$pos]['type'] = ''; 1192 } 1193 $this->debug('inside buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']); 1194 // if there are children... 1195 if($this->message[$pos]['children'] != ''){ 1196 $children = explode('|',$this->message[$pos]['children']); 1197 array_shift($children); // knock off empty 1198 // md array 1199 if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){ 1200 $r=0; // rowcount 1201 $c=0; // colcount 1202 foreach($children as $child_pos){ 1203 $this->debug("got an MD array element: $r, $c"); 1204 $params[$r][] = $this->message[$child_pos]['result']; 1205 $c++; 1206 if($c == $this->message[$pos]['arrayCols']){ 1207 $c = 0; 1208 $r++; 1209 } 1210 } 1211 // array 1212 } elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){ 1213 $this->debug('adding array '.$this->message[$pos]['name']); 1214 foreach($children as $child_pos){ 1215 $params[] = $this->message[$child_pos]['result']; 1216 } 1217 // apache Map type: java hashtable 1218 } elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){ 1219 foreach($children as $child_pos){ 1220 $kv = explode("|",$this->message[$child_pos]['children']); 1221 $params[$this->message[$kv[1]]['result']] = $this->message[$kv[2]]['result']; 1222 } 1223 // generic compound type 1224 //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') { 1225 } else { 1226 foreach($children as $child_pos){ 1227 $params[$this->message[$child_pos]['name']] =& $this->message[$child_pos]['result']; 1228 } 1229 } 1230 return is_array($params) ? $params : array(); 1231 } else { 1232 $this->debug('no children'); 1233 if(strpos($this->message[$pos]['cdata'],'&')){ 1234 return strtr($this->message[$pos]['cdata'],array_flip($this->entities)); 1235 } else { 1236 return $this->message[$pos]['cdata']; 1237 } 1238 } 1239 } 1240 } 1241 1242 1243 1244 /** 1245 * 1246 * soapclientct higher level class for easy usage. 1247 * 1248 * usage: 1249 * 1250 * // instantiate client with server info 1251 * $soapclientct = new soapclientct( string path [ ,boolean wsdl] ); 1252 * 1253 * // call method, get results 1254 * echo $soapclientct->call( string methodname [ ,array parameters] ); 1255 * 1256 * // bye bye client 1257 * unset($soapclientct); 1258 * 1259 * @author Dietrich Ayala <dietrich@ganx4.com> 1260 * @version v 0.6.3 1261 * @access public 1262 */ 1263 class soapclientct extends nusoap_base { 1264 1265 var $username = ''; 1266 var $password = ''; 1267 var $requestHeaders = false; 1268 var $responseHeaders; 1269 var $endpoint; 1270 var $error_str = false; 1271 var $proxyhost = ''; 1272 var $proxyport = ''; 1273 var $xml_encoding = ''; 1274 var $http_encoding = false; 1275 var $timeout = 0; 1276 var $endpointType = ''; 1277 /** 1278 * fault related variables 1279 * 1280 * @var fault 1281 * @var faultcode 1282 * @var faultstring 1283 * @var faultdetail 1284 * @access public 1285 */ 1286 var $fault, $faultcode, $faultstring, $faultdetail; 1287 1288 /** 1289 * constructor 1290 * 1291 * @param string $endpoint SOAP server or WSDL URL 1292 * @param bool $wsdl optional, set to true if using WSDL 1293 * @param int $portName optional portName in WSDL document 1294 * @access public 1295 */ 1296 function soapclientct($endpoint,$wsdl = false){ 1297 $this->endpoint = $endpoint; 1298 1299 // make values 1300 if($wsdl){ 1301 $this->endpointType = 'wsdl'; 1302 $this->wsdlFile = $this->endpoint; 1303 1304 // instantiate wsdl object and parse wsdl file 1305 $this->debug('instantiating wsdl class with doc: '.$endpoint); 1306 $this->wsdl =& new wsdl($this->wsdlFile); 1307 $this->debug("wsdl debug: \n".$this->wsdl->debug_str); 1308 // catch errors 1309 if($errstr = $this->wsdl->getError()){ 1310 $this->debug('got wsdl error: '.$errstr); 1311 $this->setError('wsdl error: '.$errstr); 1312 } elseif($this->operations = $this->wsdl->getOperations()){ 1313 $this->debug( 'got '.count($this->operations).' operations from wsdl '.$this->wsdlFile); 1314 } else { 1315 $this->debug( 'getOperations returned false'); 1316 $this->setError('no operations defined in the WSDL document!'); 1317 } 1318 } 1319 } 1320 1321 /** 1322 * calls method, returns PHP native type 1323 * 1324 * @param string $method SOAP server URL or path 1325 * @param array $params array of parameters, can be associative or not 1326 * @param string $namespace optional method namespace 1327 * @param string $soapAction optional SOAPAction value 1328 * @param boolean $headers optional array of soapval objects for headers 1329 * @return mixed 1330 * @access public 1331 */ 1332 function call($operation,$params=array(),$namespace='',$soapAction='',$headers=false){ 1333 $this->operation = $operation; 1334 $this->fault = false; 1335 $this->error_str = ''; 1336 $this->request = ''; 1337 $this->response = ''; 1338 $this->faultstring = ''; 1339 $this->faultcode = ''; 1340 $this->opData = array(); 1341 // if wsdl, get operation data and process parameters 1342 if($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)){ 1343 1344 $this->opData = $opData; 1345 foreach($opData as $key => $value){ 1346 $this->debug("$key -> $value"); 1347 } 1348 $soapAction = $opData['soapAction']; 1349 $this->endpoint = $opData['endpoint']; 1350 $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : 'http://testuri.org'; 1351 $style = $opData['style']; 1352 // add ns to ns array 1353 if($namespace != '' && !isset($this->wsdl->namespaces[$namespace])){ 1354 $this->wsdl->namespaces['nu'] = $namespace; 1355 } else { 1356 $namespace = 'http://testuri.org'; 1357 $this->wsdl->namespaces['nu'] = $namespace; 1358 } 1359 // serialize payload 1360 1361 if($opData['input']['use'] == 'literal') { 1362 $payload = is_array($params) ? array_shift($params) : $params; 1363 } else { 1364 $this->debug("serializing RPC params for operation $operation"); 1365 $payload = "<".$this->wsdl->getPrefixFromNamespace($namespace).":$operation>". 1366 $this->wsdl->serializeRPCParameters($operation,'input',$params). 1367 '</'.$this->wsdl->getPrefixFromNamespace($namespace).":$operation>"; 1368 } 1369 $this->debug('payload size: '.strlen($payload)); 1370 // serialize envelope 1371 $soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$this->wsdl->usedNamespaces); 1372 $this->debug("wsdl debug: \n".$this->wsdl->debug_str); 1373 } elseif($this->endpointType == 'wsdl') { 1374 $this->setError( 'operation '.$operation.' not present.'); 1375 $this->debug("operation '$operation' not present."); 1376 $this->debug("wsdl debug: \n".$this->wsdl->debug_str); 1377 return false; 1378 // no wsdl 1379 } else { 1380 // make message 1381 if(!isset($style)){ 1382 $style = 'rpc'; 1383 } 1384 if($namespace == ''){ 1385 $namespace = 'http://testuri.org'; 1386 $this->wsdl->namespaces['ns1'] = $namespace; 1387 } 1388 // serialize envelope 1389 $payload = ''; 1390 foreach($params as $k => $v){ 1391 $payload .= $this->serialize_val($v,$k); 1392 } 1393 $payload = "<ns1:$operation xmlns:ns1=\"$namespace\">\n".$payload."</ns1:$operation>\n"; 1394 $soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders); 1395 } 1396 $this->debug("endpoint: $this->endpoint, soapAction: $soapAction, namespace: $namespace"); 1397 // send 1398 $this->debug('sending msg (len: '.strlen($soapmsg).") w/ soapaction '$soapAction'..."); 1399 $return = $this->send($soapmsg,$soapAction,$this->timeout); 1400 if($errstr = $this->getError()){ 1401 $this->debug('Error: '.$errstr); 1402 return false; 1403 } else { 1404 $this->return = $return; 1405 $this->debug('sent message successfully and got a(n) '.gettype($return).' back'); 1406 1407 // fault? 1408 if(is_array($return) && isset($return['faultcode'])){ 1409 $this->debug('got fault'); 1410 $this->setError($return['faultcode'].': '.$return['faultstring']); 1411 $this->fault = true; 1412 foreach($return as $k => $v){ 1413 $this->$k = $v; 1414 $this->debug("$k = $v<br>"); 1415 } 1416 return $return; 1417 } else { 1418 // array of return values 1419 if(is_array($return)){ 1420 // multiple 'out' parameters 1421 if(sizeof($return) > 1){ 1422 return $return; 1423 } 1424 // single 'out' parameter 1425 return array_shift($return); 1426 // nothing returned (ie, echoVoid) 1427 } else { 1428 return ""; 1429 } 1430 } 1431 } 1432 } 1433 1434 /** 1435 * get available data pertaining to an operation 1436 * 1437 * @param string $operation operation name 1438 * @return array array of data pertaining to the operation 1439 * @access public 1440 */ 1441 function getOperationData($operation){ 1442 if(isset($this->operations[$operation])){ 1443 return $this->operations[$operation]; 1444 } 1445 } 1446 1447 /** 1448 * send the SOAP message 1449 * 1450 * Note: if the operation has multiple return values 1451 * the return value of this method will be an array 1452 * of those values. 1453 * 1454 * @param string $msg a SOAPx4 soapmsg object 1455 * @param string $soapaction SOAPAction value 1456 * @param integer $timeout set timeout in seconds 1457 * @return mixed native PHP types. 1458 * @access private 1459 */ 1460 function send($msg, $soapaction = '', $timeout=0) { 1461 // detect transport 1462 switch(true){ 1463 // http(s) 1464 case ereg('^http',$this->endpoint): 1465 $this->debug('transporting via HTTP'); 1466 $http = new soap_transport_http($this->endpoint); 1467 $http->setSOAPAction($soapaction); 1468 if($this->proxyhost && $this->proxyport){ 1469 $http->setProxy($this->proxyhost,$this->proxyport); 1470 } 1471 if($this->username != '' && $this->password != '') { 1472 $http->setCredentials($this->username,$this->password); 1473 } 1474 if($this->http_encoding != ''){ 1475 $http->setEncoding($this->http_encoding); 1476 } 1477 $this->debug('sending message, length: '.strlen($msg)); 1478 if(ereg('^http:',$this->endpoint)){ 1479 //if(strpos($this->endpoint,'http:')){ 1480 $response = $http->send($msg,$timeout); 1481 } elseif(ereg('^https',$this->endpoint)){ 1482 //} elseif(strpos($this->endpoint,'https:')){ 1483 //if(phpversion() == '4.3.0-dev'){ 1484 //$response = $http->send($msg,$timeout); 1485 //$this->request = $http->outgoing_payload; 1486 //$this->response = $http->incoming_payload; 1487 //} else 1488 if (extension_loaded('curl')) { 1489 $response = $http->sendHTTPS($msg,$timeout); 1490 } else { 1491 $this->setError('CURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS'); 1492 } 1493 } else { 1494 $this->setError('no http/s in endpoint url'); 1495 } 1496 $this->request = $http->outgoing_payload; 1497 $this->response = $http->incoming_payload; 1498 $this->debug("transport debug data...\n".$http->debug_str); 1499 if($err = $http->getError()){ 1500 $this->setError('HTTP Error: '.$err); 1501 return false; 1502 } elseif($this->getError()){ 1503 return false; 1504 } else { 1505 $this->debug('got response, length: '.strlen($response)); 1506 return $this->parseResponse($response); 1507 } 1508 break; 1509 default: 1510 $this->setError('no transport found, or selected transport is not yet supported!'); 1511 return false; 1512 break; 1513 } 1514 } 1515 1516 /** 1517 * processes SOAP message returned from server 1518 * 1519 * @param string unprocessed response data from server 1520 * @return mixed value of the message, decoded into a PHP type 1521 * @access private 1522 */ 1523 function parseResponse($data) { 1524 $this->debug('Entering parseResponse(), about to create soap_parser instance'); 1525 $parser = new soap_parser($data,$this->xml_encoding,$this->operation); 1526 // if parse errors 1527 if($errstr = $parser->getError()){ 1528 $this->setError( $errstr); 1529 // destroy the parser object 1530 unset($parser); 1531 return false; 1532 } else { 1533 // get SOAP headers 1534 $this->responseHeaders = $parser->getHeaders(); 1535 // get decoded message 1536 $return = $parser->get_response(); 1537 // add parser debug data to our debug 1538 $this->debug($parser->debug_str); 1539 // add document for doclit support 1540 $this->document = $parser->document; 1541 // destroy the parser object 1542 unset($parser); 1543 // return decode message 1544 return $return; 1545 } 1546 } 1547 1548 /** 1549 * set the SOAP headers 1550 * 1551 * @param $headers string XML 1552 * @access public 1553 */ 1554 function setHeaders($headers){ 1555 $this->requestHeaders = $headers; 1556 } 1557 1558 /** 1559 * get the response headers 1560 * 1561 * @return mixed object SOAPx4 soapval object or empty if no headers 1562 * @access public 1563 */ 1564 function getHeaders(){ 1565 if($this->responseHeaders != '') { 1566 return $this->responseHeaders; 1567 } 1568 } 1569 1570 /** 1571 * set proxy info here 1572 * 1573 * @param string $proxyhost 1574 * @param string $proxyport 1575 * @access public 1576 */ 1577 function setHTTPProxy($proxyhost, $proxyport) { 1578 $this->proxyhost = $proxyhost; 1579 $this->proxyport = $proxyport; 1580 } 1581 1582 /** 1583 * if authenticating, set user credentials here 1584 * 1585 * @param string $username 1586 * @param string $password 1587 * @access public 1588 */ 1589 function setCredentials($username, $password) { 1590 $this->username = $username; 1591 $this->password = $password; 1592 } 1593 1594 /** 1595 * use HTTP encoding 1596 * 1597 * @param string $enc 1598 * @access public 1599 */ 1600 function setHTTPEncoding($enc='gzip, deflate'){ 1601 $this->http_encoding = $enc; 1602 } 1603 1604 /** 1605 * dynamically creates proxy class, allowing user to directly call methods from wsdl 1606 * 1607 * @return object soap_proxy object 1608 * @access public 1609 */ 1610 function getProxy(){ 1611 foreach($this->operations as $operation => $opData){ 1612 if($operation != ''){ 1613 // create param string 1614 if(sizeof($opData['input']['parts']) > 0){ 1615 foreach($opData['input']['parts'] as $name => $type){ 1616 $paramStr .= "\$$name,"; 1617 } 1618 $paramStr = substr($paramStr,0,strlen($paramStr)-1); 1619 } 1620 $evalStr .= "function $operation ($paramStr){ 1621 // load params into array 1622 \$params = array($paramStr); 1623 return \$this->call('$operation',\$params,'".$opData['namespace']."','".$opData['soapAction']."'); 1624 }"; 1625 unset($paramStr); 1626 } 1627 } 1628 $r = rand(); 1629 $evalStr = 'class soap_proxy_'.$r.' extends soapclientct { 1630 '.$evalStr.' 1631 }'; 1632 //print "proxy class:<pre>$evalStr</pre>"; 1633 // eval the class 1634 eval($evalStr); 1635 // instantiate proxy object 1636 eval("\$proxy = new soap_proxy_$r('');"); 1637 // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice 1638 $proxy->endpointType = 'wsdl'; 1639 $proxy->wsdlFile = $this->wsdlFile; 1640 $proxy->wsdl = $this->wsdl; 1641 $proxy->operations = $this->operations; 1642 return $proxy; 1643 } 1644 } 1645 1646 //makeXMLTree 1647 1648 function makeXMLTree($data) 1649 { 1650 1651 // create parser 1652 $parser = xml_parser_create(); 1653 xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); 1654 xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); 1655 xml_parse_into_struct($parser,$data,$values,$tags); 1656 xml_parser_free($parser); 1657 1658 // we store our path here 1659 $hash_stack = array(); 1660 1661 // this is our target 1662 $ret = array(); 1663 foreach ($values as $key => $val) { 1664 1665 switch ($val['type']) { 1666 case 'open': 1667 array_push($hash_stack, $val['tag']); 1668 if (isset($val['attributes'])) 1669 $ret = composeArray($ret, $hash_stack, $val['attributes']); 1670 else 1671 $ret = composeArray($ret, $hash_stack); 1672 break; 1673 1674 case 'close': 1675 array_pop($hash_stack); 1676 break; 1677 1678 case 'complete': 1679 array_push($hash_stack, $val['tag']); 1680 $ret = composeArray($ret, $hash_stack, $val['value']); 1681 array_pop($hash_stack); 1682 1683 // handle attributes 1684 if (isset($val['attributes'])) 1685 { 1686 while(list($a_k,$a_v) = each($val['attributes'])) 1687 { 1688 $hash_stack[] = $val['tag']."_attribute_".$a_k; 1689 $ret = composeArray($ret, $hash_stack, $a_v); 1690 array_pop($hash_stack); 1691 } 1692 } 1693 1694 1695 break; 1696 } 1697 } 1698 1699 return $ret; 1700 } 1701 1702 function &composeArray($array, $elements, $value=array()) 1703 { 1704 1705 1706 // get current element 1707 $element = array_shift($elements); 1708 1709 // does the current element refer to a list 1710 if ($element=="Result") 1711 { 1712 // more elements? 1713 if(sizeof($elements) > 0) 1714 { 1715 $array[$element][sizeof($array[$element])-1] = &composeArray($array[$element][sizeof($array[$element])-1], $elements, $value); 1716 } 1717 else // if (is_array($value)) 1718 { 1719 $array[$element][sizeof($array[$element])] = $value; 1720 } 1721 } 1722 else 1723 { 1724 // more elements? 1725 if(sizeof($elements) > 0) 1726 { 1727 $array[$element] = &composeArray($array[$element], $elements, $value); 1728 } 1729 else 1730 { 1731 $array[$element] = $value; 1732 } 1733 } 1734 1735 return $array; 1736 } 1737 1738 //------------------------------------------------------------------------------------------------- 1739 //------------------------------------------------------------------------------------------------- 1740 //------------------------------------------------------------------------------------------------- 1741 //------------------------------------------------------------------------------------------------- 1742 //------------------------------------------------------------------------------------------------- 1743 //------------------------------------------------------------------------------------------------- 1744 //------------------------------------------------------------------------------------------------- 1745 //get url data 1746 1747 if(isset($_GET['navig'])) 1748 { 1749 $navig = (int)$_GET['navig']; 1750 } 1751 else 1752 { 1753 echo"<h1>Hacking attempt !!!!</h1>"; 1754 exit(); 1755 } 1756 if(isset($_GET['period'])) 1757 { 1758 $period = (int)$_GET['period']; 1759 } 1760 else 1761 { 1762 echo"<h1>Hacking attempt !!!!</h1>"; 1763 exit(); 1764 } 1765 if(isset($_GET['site'])) 1766 { 1767 $site= (int)$_GET['site']; 1768 } 1769 else 1770 { 1771 echo"<h1>Hacking attempt !!!!</h1>"; 1772 exit(); 1773 } 1774 if(isset($_GET['crawler'])) 1775 { 1776 $crawler= $_GET['crawler']; 1777 } 1778 else 1779 { 1780 echo"<h1>Hacking attempt !!!!</h1>"; 1781 exit(); 1782 } 1783 if(isset($_GET['graphpos'])) 1784 { 1785 $graphpos= $_GET['graphpos']; 1786 } 1787 else 1788 { 1789 echo"<h1>Hacking attempt !!!!</h1>"; 1790 exit(); 1791 } 1792 if(isset($_GET['retry'])) 1793 { 1794 $retry=$_GET['retry']; 1795 } 1796 else 1797 { 1798 echo"<h1>Hacking attempt !!!!</h1>"; 1799 exit(); 1800 } 1801 1802 1803 include "../include/functions.php"; 1804 1805 1806 1807 1808 //database connection 1809 include "../include/configconnect.php"; 1810 $connexion = mysql_connect($crawlthost,$crawltuser,$crawltpassword) or die("MySQL connection to database problem"); 1811 $selection = mysql_select_db($crawltdb) or die("MySQL database selection problem"); 1812 1813 //mysql requete for timeshift 1814 $sqlcrawltconfig = "SELECT timeshift FROM crawlt_config"; 1815 $requetecrawltconfig = mysql_query($sqlcrawltconfig, $connexion); 1816 $nbrresultcrawlt=mysql_num_rows($requetecrawltconfig); 1817 if($nbrresultcrawlt>=1) 1818 { 1819 $lignecrawlt = mysql_fetch_row($requetecrawltconfig); 1820 $crawlttime=$lignecrawlt[0]; 1821 } 1822 //take in account timeshift 1823 $crawltts = strtotime("today")-($crawlttime*3600); 1824 $crawltdatetoday2 = date("Y-m-d",$crawltts); 1825 1826 1827 1828 //mysql requete for site id and url 1829 1830 $crawltsql = "SELECT id_site, url FROM crawlt_site"; 1831 $crawltrequete = mysql_query($crawltsql, $connexion) or die("MySQL query error"); 1832 1833 $crawltnbrresult=mysql_num_rows($crawltrequete); 1834 $crawltnbrresult2 = ($crawltnbrresult*2); 1835 $crawltnbrresult3 = ($crawltnbrresult*3); 1836 //initialize array 1837 $listsitecrawlt=array(); 1838 $crawltsiteurl=array(); 1839 1840 if($crawltnbrresult >= 1) 1841 { 1842 while($crawltligne = mysql_fetch_row($crawltrequete)) 1843 { 1844 $listsitecrawlt[] = $crawltligne[0]; 1845 $crawltsiteurl[$crawltligne[0]] = $crawltligne[1]; 1846 } 1847 } 1848 1849 1850 1851 1852 //looking for position in search engines database using api 1853 1854 //test which one to retry 1855 1856 if($retry== 'yahoo') 1857 { 1858 //yahoo 1859 1860 foreach( $listsitecrawlt as $crawltidsite) 1861 { 1862 $crawlturlsite=$crawltsiteurl[$crawltidsite]; 1863 1864 1865 //to avoid problem if the url is enter in the database with http:// 1866 if (eregi("^http://", $crawlturlsite)) 1867 { 1868 $crawlturlsite= ltrim($crawlturlsite,"http://"); 1869 } 1870 1871 // yahoo links 1872 $crawltrequete1 = "linkdomain:$crawlturlsite"; 1873 $crawltquery1 = "http://api.search.yahoo.com/WebSearchService/V1/webSearch?query=".rawurlencode($crawltrequete1)."&appid=crawltrack"; 1874 $crawltxml1 = file_get_contents($crawltquery1); 1875 $crawltxml1 = makeXMLTree($crawltxml1); 1876 $crawltxml1 = $crawltxml1['ResultSet']; 1877 $crawltnbryahoo1 = $crawltxml1['totalResultsAvailable']; 1878 if($crawltnbryahoo1=='') 1879 { 1880 $crawltnbryahoo1=0; 1881 } 1882 1883 //check if the date exit already in the table 1884 $crawltsqlcheck = "SELECT date,id_site FROM crawlt_seo_position 1885 WHERE date= '".sql_quote($crawltdatetoday2)."' 1886 AND id_site='".sql_quote($crawltidsite)."'"; 1887 1888 $crawltrequetecheck = mysql_query($crawltsqlcheck, $connexion) or die("MySQL query error"); 1889 $crawltnbrresultcheck=mysql_num_rows($crawltrequetecheck); 1890 if($crawltnbrresultcheck >=1) 1891 { 1892 $crawltsqlseo ="UPDATE crawlt_seo_position SET linkyahoo='".sql_quote($crawltnbryahoo1)."' 1893 WHERE date= '".sql_quote($crawltdatetoday2)."' 1894 AND id_site='".sql_quote($crawltidsite)."'"; 1895 } 1896 else 1897 { 1898 $crawltsqlseo ="INSERT INTO crawlt_seo_position (date,id_site, linkyahoo, pageyahoo, linkmsn, pagemsn,nbrdelicious, tagdelicious) VALUES ( '".sql_quote($crawltdatetoday2)."','".sql_quote($crawltidsite)."','".sql_quote($crawltnbryahoo1)."','0','0','0','0',' ')"; 1899 } 1900 $crawltrequeteseo = mysql_query($crawltsqlseo, $connexion) or die("MySQL query error"); 1901 1902 1903 //yahoo pages 1904 $crawltrequete2 = "http://$crawlturlsite"; 1905 $crawltquery2 = "http://api.search.yahoo.com/WebSearchService/V1/webSearch?query=".rawurlencode($crawltrequete2)."&appid=crawltrack"; 1906 $crawltxml2 = file_get_contents($crawltquery2); 1907 $crawltxml2 = makeXMLTree($crawltxml2); 1908 $crawltxml2 = $crawltxml2['ResultSet']; 1909 $crawltnbryahoo2 = $crawltxml2['totalResultsAvailable']; 1910 if($crawltnbryahoo2=='') 1911 { 1912 $crawltnbryahoo2=0; 1913 } 1914 //check if the date exit already in the table 1915 $crawltsqlcheck = "SELECT date,id_site FROM crawlt_seo_position 1916 WHERE date= '".sql_quote($crawltdatetoday2)."' 1917 AND id_site='".sql_quote($crawltidsite)."'"; 1918 1919 $crawltrequetecheck = mysql_query($crawltsqlcheck, $connexion) or die("MySQL query error"); 1920 $crawltnbrresultcheck=mysql_num_rows($crawltrequetecheck); 1921 if($crawltnbrresultcheck >=1) 1922 { 1923 $crawltsqlseo ="UPDATE crawlt_seo_position SET pageyahoo='".sql_quote($crawltnbryahoo2)."' 1924 WHERE date= '".sql_quote($crawltdatetoday2)."' 1925 AND id_site='".sql_quote($crawltidsite)."'"; 1926 } 1927 else 1928 { 1929 $crawltsqlseo ="INSERT INTO crawlt_seo_position (date,id_site, linkyahoo, pageyahoo, linkmsn, pagemsn,nbrdelicious, tagdelicious) VALUES ( '".sql_quote($crawltdatetoday2)."','".sql_quote($crawltidsite)."','0','".sql_quote($crawltnbryahoo2)."','0','0','0',' ')"; 1930 } 1931 $crawltrequeteseo = mysql_query($crawltsqlseo, $connexion) or die("MySQL query error"); 1932 1933 1934 1935 } 1936 1937 1938 } 1939 elseif($retry == 'msn') 1940 { 1941 1942 //msn 1943 foreach( $listsitecrawlt as $crawltidsite) 1944 { 1945 $crawlturlsite=$crawltsiteurl[$crawltidsite]; 1946 1947 1948 1949 //to avoid problem if the url is enter in the database with http:// 1950 if (eregi("^http://", $crawlturlsite)) 1951 { 1952 $crawlturlsite= ltrim($crawlturlsite,"http://"); 1953 } 1954 1955 //msn links 1956 $crawltrequete1 = "linkdomain:$crawlturlsite"; 1957 $soapclientct = new soapclientct("http://soap.search.msn.com/webservices.asmx"); 1958 $crawltparam1 = array( 1959 'AppID' => '5E4A1FC1F7B268DD7BCE62F39BFF8A0D81CB900B', 1960 'Query' => $crawltrequete1, 1961 'CultureInfo' => 'en-US', 1962 'SafeSearch' => 'Off', 1963 'Requests' => array ( 1964 'SourceRequest' => array ( 1965 'Source' => 'Web', 1966 'Offset' => 0, 1967 'Count' => 50, 1968 'ResultFields' => 'All' 1969 ), 1970 ), 1971 ); 1972 $crawltsearchresults1 = $soapclientct->call("Search", array("Request"=>$crawltparam1)); 1973 if (!empty($crawltsearchresults1)) 1974 { 1975 $crawltnbrmsn1 = $crawltsearchresults1['Responses']['SourceResponse']['Total']; 1976 } 1977 else 1978 { 1979 $crawltnbrmsn1=0; 1980 } 1981 if($crawltnbrmsn1=='') 1982 { 1983 $crawltnbrmsn1=0; 1984 } 1985 1986 //insert values in the crawlt_seo_position table 1987 1988 //check if the date exit already in the table 1989 $crawltsqlcheck = "SELECT date,id_site FROM crawlt_seo_position 1990 WHERE date= '".sql_quote($crawltdatetoday2)."' 1991 AND id_site='".sql_quote($crawltidsite)."'"; 1992 1993 $crawltrequetecheck = mysql_query($crawltsqlcheck, $connexion) or die("MySQL query error"); 1994 $crawltnbrresultcheck=mysql_num_rows($crawltrequetecheck); 1995 if($crawltnbrresultcheck >=1) 1996 { 1997 $crawltsqlseo ="UPDATE crawlt_seo_position SET linkmsn='".sql_quote($crawltnbrmsn1)."' 1998 WHERE date= '".sql_quote($crawltdatetoday2)."' 1999 AND id_site='".sql_quote($crawltidsite)."'"; 2000 $crawltrequeteseo = mysql_query($crawltsqlseo, $connexion) or die("MySQL query error"); 2001 } 2002 else 2003 { 2004 $crawltsqlseo ="INSERT INTO crawlt_seo_position (date,id_site, linkyahoo, pageyahoo, linkmsn, pagemsn,nbrdelicious, tagdelicious) VALUES ( '".sql_quote($crawltdatetoday2)."','".sql_quote($crawltidsite)."','0','0','".sql_quote($crawltnbrmsn1)."','0','0',' ')"; 2005 $crawltrequeteseo = mysql_query($crawltsqlseo, $connexion) or die("MySQL query error"); 2006 } 2007 2008 2009 //msn pages 2010 $crawltrequete2 = "site:$crawlturlsite"; 2011 $soapclientct = new soapclientct("http://soap.search.msn.com/webservices.asmx"); 2012 $crawltparam2 = array( 2013 'AppID' => '5E4A1FC1F7B268DD7BCE62F39BFF8A0D81CB900B', 2014 'Query' => $crawltrequete2, 2015 'CultureInfo' => 'en-US', 2016 'SafeSearch' => 'Off', 2017 'Requests' => array ( 2018 'SourceRequest' => array ( 2019 'Source' => 'Web', 2020 'Offset' => 0, 2021 'Count' => 50, 2022 'ResultFields' => 'All' 2023 ), 2024 ), 2025 ); 2026 $crawltsearchresults2 = $soapclientct->call("Search", array("Request"=>$crawltparam2)); 2027 if (!empty($crawltsearchresults2)) 2028 { 2029 $crawltnbrmsn2 = $crawltsearchresults2['Responses']['SourceResponse']['Total']; 2030 } 2031 else 2032 { 2033 $crawltnbrmsn2=0; 2034 } 2035 if($crawltnbrmsn2=='') 2036 { 2037 $crawltnbrmsn2=0; 2038 } 2039 2040 //insert values in the crawlt_seo_position table 2041 2042 //check if the date exit already in the table 2043 $crawltsqlcheck = "SELECT date,id_site FROM crawlt_seo_position 2044 WHERE date= '".sql_quote($crawltdatetoday2)."' 2045 AND id_site='".sql_quote($crawltidsite)."'"; 2046 2047 $crawltrequetecheck = mysql_query($crawltsqlcheck, $connexion) or die("MySQL query error"); 2048 $crawltnbrresultcheck=mysql_num_rows($crawltrequetecheck); 2049 if($crawltnbrresultcheck >=1) 2050 { 2051 $crawltsqlseo ="UPDATE crawlt_seo_position SET pagemsn='".sql_quote($crawltnbrmsn2)."' 2052 WHERE date= '".sql_quote($crawltdatetoday2)."' 2053 AND id_site='".sql_quote($crawltidsite)."'"; 2054 } 2055 else 2056 { 2057 $crawltsqlseo ="INSERT INTO crawlt_seo_position (date,id_site, linkyahoo, pageyahoo, linkmsn, pagemsn,nbrdelicious, tagdelicious) VALUES ( '".sql_quote($crawltdatetoday2)."','".sql_quote($crawltidsite)."','0','0','0','".sql_quote($crawltnbrmsn2)."','0',' ')"; 2058 } 2059 $crawltrequeteseo = mysql_query($crawltsqlseo, $connexion) or die("MySQL query error"); 2060 2061 2062 2063 2064 } 2065 } 2066 elseif($retry == 'delicious') 2067 { 2068 2069 //del.icio.us 2070 foreach( $listsitecrawlt as $crawltidsite) 2071 { 2072 $crawlturlsite=$crawltsiteurl[$crawltidsite]; 2073 2074 //to avoid problem if the url is enter in the database with http:// 2075 if (eregi("^http://", $crawlturlsite)) 2076 { 2077 $crawlturlsite= ltrim($crawlturlsite,"http://"); 2078 } 2079 2080 $crawlturlsite2="http://".$crawlturlsite."/"; 2081 $crawltquery1 = "http://badges.del.icio.us/feeds/json/url/blogbadge?hash=".md5($crawlturlsite2); 2082 $crawltresultdelicious = file_get_contents($crawltquery1); 2083 2084 $crawltnbrtag=explode("\"total_posts\":",$crawltresultdelicious); 2085 2086 if(count($crawltnbrtag)==1) 2087 { 2088 $crawltnbrtagdelicious=0; 2089 $crawlttagtab=" "; 2090 } 2091 else 2092 { 2093 2094 //delicious tags 2095 $crawltnbrtag2 =explode("}",$crawltnbrtag[1]); 2096 $crawltnbrtagdelicious=$crawltnbrtag2[0]; 2097 2098 $crawlttag=explode("\"top_tags\":{\"",$crawltresultdelicious); 2099 $crawlttag2 =explode("}",$crawlttag[1]); 2100 $crawlttag3 =str_replace(":","",$crawlttag2[0]); 2101 $crawlttag3 =str_replace(",","",$crawlttag3); 2102 $crawlttag4 =explode("\"",$crawlttag3); 2103 2104 $n=count($crawlttag4); 2105 for($i=0;$i<$n;$i++) 2106 { 2107 if ($i%2 ==0) 2108 { 2109 $crawltnbrpertag[$crawlttag4[$i]]=$crawlttag4[$i+1]; 2110 } 2111 } 2112 $crawlttagtab= serialize($crawltnbrpertag); 2113 } 2114 //insert values in the crawlt_seo_position table 2115 2116 //check if the date exit already in the table 2117 $crawltsqlcheck = "SELECT date,id_site FROM crawlt_seo_position 2118 WHERE date= '".sql_quote($crawltdatetoday2)."' 2119 AND id_site='".sql_quote($crawltidsite)."'"; 2120 2121 $crawltrequetecheck = mysql_query($crawltsqlcheck, $connexion) or die("MySQL query error"); 2122 $nbrresultcheck=mysql_num_rows($crawltrequetecheck); 2123 if($nbrresultcheck >=1) 2124 { 2125 $crawltsqlseo ="UPDATE crawlt_seo_position SET nbrdelicious='".sql_quote($crawltnbrtagdelicious)."',tagdelicious='".sql_quote($crawlttagtab)."' 2126 WHERE date= '".sql_quote($crawltdatetoday2)."' 2127 AND id_site='".sql_quote($crawltidsite)."'"; 2128 } 2129 else 2130 { 2131 $crawltsqlseo ="INSERT INTO crawlt_seo_position (date,id_site, linkyahoo, pageyahoo, linkmsn, pagemsn,nbrdelicious, tagdelicious) VALUES ( '".sql_quote($crawltdatetoday2)."','".sql_quote($crawltidsite)."','0','0','0','0','".sql_quote($crawltnbrtagdelicious)."','".sql_quote($crawlttagtab)."')"; 2132 } 2133 $crawltrequeteseo = mysql_query($crawltsqlseo, $connexion) or die("MySQL query error"); 2134 2135 2136 } 2137 } 2138 //clear the cache and call back the indexation page 2139 2140 //clear cache table 2141 $sqlcache = "TRUNCATE TABLE crawlt_cache"; 2142 $requetecache = mysql_query($sqlcache, $connexion) or die("MySQL query error"); 2143 2144 //clear graph table 2145 $sqlgraph = "TRUNCATE TABLE crawlt_graph"; 2146 $requetegraph = mysql_query($sqlgraph, $connexion) or die("MySQL query error"); 2147 2148 2149 //mysql connexion close 2150 mysql_close($connexion); 2151 2152 //clear the cache folder 2153 $dir = dir('../cache/'); 2154 while (false !== $entry = $dir->read()) 2155 { 2156 // Skip pointers 2157 if ($entry == '.' || $entry == '..') 2158 { 2159 continue; 2160 } 2161 unlink("../cache/$entry"); 2162 } 2163 2164 // Clean up 2165 $dir->close(); 2166 2167 //call back the page 2168 2169 $urlrefresh ="../index.php?navig=$navig&period=$period&site=$site&crawler=$crawlencode&graphpos=$graphpos"; 2170 header("Location:$urlrefresh"); 2171 2172 2173 2174 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Sep 6 14:14:11 2007 | par Balluche grâce à PHPXref 0.7 |