Ticket #2933: ping-4.patch
| File ping-4.patch, 5.9 KB (added by c960657, 5 years ago) |
|---|
-
wp-includes/comment.php
668 668 669 669 670 670 function generic_ping($post_id = 0) { 671 $errors = get_option('ping_errors'); 672 if ( !is_array($errors) ) 673 $errors = array(); 671 674 $services = get_option('ping_sites'); 672 675 $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines 673 676 $services = trim($services); 674 677 if ( '' != $services ) { 678 $update_ping_sites = false; 675 679 $services = explode("\n", $services); 676 foreach ( (array) $services as $service ) 677 weblog_ping($service); 680 foreach ( (array) $services as $i => $service ) { 681 $error = weblog_ping($service); 682 if ( $error ) { 683 if ( !isset($errors[$service]) ) 684 $errors[$service] = array('count' => 0); 685 $errors[$service]['count']++; 686 $errors[$service]['last_message'] = $error; 687 $statusCode = preg_match('/HTTP status: (\d\d\d)/', $error, $reg) ? intval($reg[1]) : false; 688 // Remove servers that keep failing, and allow server owners 689 // to speed up the process by returning 403 Forbidden, 404 690 // Not Found or 410 Gone 691 if ( $errors[$service]['count'] > 20 || 692 $errors[$service]['count'] > 3 && in_array($statusCode, array(403, 404, 410))) { 693 694 unset($services[$i]); 695 unset($errors[$service]); 696 $update_ping_sites = true; 697 } 698 } else { 699 unset($errors[$service]); 700 } 701 } 702 if ($update_ping_sites) 703 update_option('ping_sites', implode("\n", $services)); 678 704 } 705 update_option('ping_errors', $errors); 679 706 680 707 return $post_id; 681 708 } … … 799 826 // when set to true, this outputs debug messages by itself 800 827 $client->debug = false; 801 828 $home = trailingslashit( get_option('home') ); 802 if ( !$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping 829 $client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, get_bloginfo('rss2_url') ); 830 // If there was an XML-RPC service ("200" is a required but not sufficient 831 // condition) but it did not know extendedPing, try a regular ping 832 if ( $client->isError() && substr($client->getHttpStatus(), 0, 3) == '200' ) 803 833 $client->query('weblogUpdates.ping', get_option('blogname'), $home); 834 835 $error = false; 836 if ( $client->isError() ) { 837 $httpStatus = $client->getHttpStatus(); 838 if ($httpStatus && substr($httpStatus, 0, 3) != '200') 839 $error = 'HTTP status: ' . $httpStatus; 840 else 841 $error = $client->getErrorMessage(); 842 } else { 843 $response = $client->getResponse(); 844 if ( !isset($response['flerror']) || $response['flerror'] ) { 845 $error = isset($response['message']) && $response['message'] 846 ? $response['message'] : 'Invalid response'; 847 } 848 } 849 return $error; 804 850 } 805 851 806 852 // -
wp-includes/class-IXR.php
460 460 var $timeout; 461 461 // Storage place for an error message 462 462 var $error = false; 463 var $httpStatus = false; 463 464 function IXR_Client($server, $path = false, $port = 80, $timeout = false) { 464 465 if (!$path) { 465 466 // Assume we have been given a URL instead … … 513 514 $line = fgets($fp, 4096); 514 515 if (!$gotFirstLine) { 515 516 // Check line for '200' 516 if (strstr($line, '200') === false) { 517 $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); 517 if (preg_match('|^HTTP/1\.. ((\d\d\d) .*)|', $line, $reg)) { 518 $this->httpStatus = $reg[1]; 519 if ($reg[2] != '200') { 520 $this->error = new IXR_Error(-32300, 'transport error - ' . $this->httpStatus); 521 return false; 522 } 523 } else { 524 $this->error = new IXR_Error(-32300, 'transport error - no headers received' . $line); 518 525 return false; 519 526 } 520 527 $gotFirstLine = true; … … 554 561 function getErrorCode() { 555 562 return $this->error->code; 556 563 } 564 function getHttpStatus() { 565 // e.g. "200 OK" or "404 Not found" 566 return $this->httpStatus; 567 } 557 568 function getErrorMessage() { 558 569 return $this->error->message; 559 570 } -
wp-admin/options-writing.php
102 102 103 103 <textarea name="ping_sites" id="ping_sites" style="width: 98%;" rows="3" cols="50"><?php form_option('ping_sites'); ?></textarea> 104 104 105 <p><?php _e('These update services failed your last update. You should consider removing these services from the list above.') ?></p> 106 <dl> 107 <?php 108 $has_errors = false; 109 $services = get_option('ping_sites'); 110 $errors = get_option('ping_errors'); 111 if (is_array($errors)) 112 foreach (get_option('ping_errors') as $service => $error) : 113 if (preg_match('/(^|\s)' . preg_quote($service, '/') . '($|\s)/', $services)) : 114 echo "<dt>" . htmlspecialchars($service) . "</dt>"; 115 echo "<dd>"; 116 if ($error['count'] > 1) : 117 printf(__('Failed %d times. Last error message was: '), $error['count']); 118 endif; 119 echo htmlspecialchars($error['last_message']); 120 echo "</dd>"; 121 $has_errors = true; 122 endif; 123 endforeach; 124 125 if (!$has_errors) : 126 echo "<dd><em>" . __('No errors') . "</em></dd>"; 127 endif; 128 ?> 129 </dl> 130 105 131 <?php else : ?> 106 132 107 133 <p><?php printf(__('WordPress is not notifying any <a href="http://codex.wordpress.org/Update_Services">Update Services</a> because of your blog\'s <a href="%s">privacy settings</a>.'), 'options-privacy.php'); ?> … … 118 144 </form> 119 145 </div> 120 146 121 <?php include('./admin-footer.php') ?> 122 No newline at end of file 147 <?php include('./admin-footer.php') ?>
