Changeset 1671:7c0168380f80
- Timestamp:
- 08/31/13 14:37:33 (11 years ago)
- Branch:
- pingbacks
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.trackback.php
r1179 r1671 80 80 } 81 81 82 $data = array( 83 'title' => $post_title, 84 'excerpt' => $post_excerpt, 85 'url' => $post_url, 86 'blog_name' => trim(html::escapeHTML(html::clean($this->core->blog->name))) 87 //,'__debug' => false 88 ); 89 90 # Ping 91 try 92 { 93 $http = self::initHttp($url,$path); 94 $http->post($path,$data,'UTF-8'); 95 $res = $http->getContent(); 96 } 97 catch (Exception $e) 98 { 99 throw new Exception(__('Unable to ping URL')); 100 } 101 102 $pattern = 103 '|<response>.*<error>(.*)</error>(.*)'. 104 '(<message>(.*)</message>(.*))?'. 105 '</response>|msU'; 106 107 if (!preg_match($pattern,$res,$match)) 108 { 109 throw new Exception(sprintf(__('%s is not a ping URL'),$url)); 110 } 111 112 $ping_error = trim($match[1]); 113 $ping_msg = (!empty($match[4])) ? $match[4] : ''; 82 $ping_parts = explode('|',$url); 83 84 # Let's walk by the trackback way 85 if (count($ping_parts) < 2) { 86 $data = array( 87 'title' => $post_title, 88 'excerpt' => $post_excerpt, 89 'url' => $post_url, 90 'blog_name' => trim(html::escapeHTML(html::clean($this->core->blog->name))) 91 //,'__debug' => false 92 ); 93 94 # Ping 95 try 96 { 97 $http = self::initHttp($url,$path); 98 $http->post($path,$data,'UTF-8'); 99 $res = $http->getContent(); 100 } 101 catch (Exception $e) 102 { 103 throw new Exception(__('Unable to ping URL')); 104 } 105 106 $pattern = 107 '|<response>.*<error>(.*)</error>(.*)'. 108 '(<message>(.*)</message>(.*))?'. 109 '</response>|msU'; 110 111 if (!preg_match($pattern,$res,$match)) 112 { 113 throw new Exception(sprintf(__('%s is not a ping URL'),$url)); 114 } 115 116 $ping_error = trim($match[1]); 117 $ping_msg = (!empty($match[4])) ? $match[4] : ''; 118 } 119 # Damnit ! Let's play pingback 120 else { 121 try { 122 $xmlrpc = new xmlrpcClient($ping_parts[0]); 123 $res = $xmlrpc->query('pingback.ping', $post_url, $ping_parts[1]); 124 $ping_error = '0'; 125 } 126 catch (xmlrpcException $e) { 127 $ping_error = $e->getCode(); 128 $ping_msg = $e->getMessage(); 129 } 130 catch (Exception $e) { 131 throw new Exception(__('Unable to ping URL')); 132 } 133 } 114 134 115 135 if ($ping_error != '0') { … … 346 366 for ($i = 0; $i<count($match); $i++) 347 367 { 348 if (preg_match('/href="(http :\/\/[^"]+)"/ms', $match[$i][1], $matches)) {368 if (preg_match('/href="(https?:\/\/[^"]+)"/ms', $match[$i][1], $matches)) { 349 369 $res[$matches[1]] = 1; 350 370 } … … 358 378 for ($i = 0; $i<count($match); $i++) 359 379 { 360 if (preg_match('/cite="(http :\/\/[^"]+)"/ms', $match[$i][2], $matches)) {380 if (preg_match('/cite="(https?:\/\/[^"]+)"/ms', $match[$i][2], $matches)) { 361 381 $res[$matches[1]] = 1; 362 382 } … … 374 394 $http->get($path); 375 395 $page_content = $http->getContent(); 396 $pb_url = $http->getHeader('x-pingback'); 376 397 } 377 398 catch (Exception $e) … … 380 401 } 381 402 403 # If we've got a X-Pingback header and it's a valid URL, it will be enough 404 if ($pb_url && filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 405 return $pb_url.'|'.$url; 406 } 407 408 # No X-Pingback header ? OK, let's check for a trackback data chunk... 382 409 $pattern_rdf = 383 410 '/<rdf:RDF.*?>.*?'. … … 388 415 preg_match_all($pattern_rdf,$page_content,$rdf_all,PREG_SET_ORDER); 389 416 417 $url_path = parse_url($url, PHP_URL_PATH); 418 $sanitized_url = str_replace($url_path, html::sanitizeURL($url_path), $url); 419 390 420 for ($i=0; $i<count($rdf_all); $i++) 391 421 { 392 422 $rdf = $rdf_all[$i][1]; 393 394 if (preg_match('/dc:identifier="'.preg_quote($url,'/').'"/msi',$rdf)) {423 if (preg_match('/dc:identifier="'.preg_quote($url,'/').'"/msi',$rdf) || 424 preg_match('/dc:identifier="'.preg_quote($sanitized_url,'/').'"/msi',$rdf)) { 395 425 if (preg_match('/trackback:ping="(.*?)"/msi',$rdf,$tb_link)) { 396 426 return $tb_link[1]; … … 399 429 } 400 430 431 # Last call before the point of no return : a link rel=pingback, maybe ? 432 $pattern_pingback = '!<link rel="pingback" href="(.*?)"( /)?>!msi'; 433 434 if (preg_match($pattern_pingback,$page_content,$m)) { 435 $pb_url = $m[1]; 436 if (filter_var($pb_url,FILTER_VALIDATE_URL) && preg_match('!^https?:!',$pb_url)) { 437 return $pb_url.'|'.$url; 438 } 439 } 440 401 441 return null; 402 442 }
Note: See TracChangeset
for help on using the changeset viewer.