Make WordPress Core


Ignore:
Timestamp:
09/27/2008 09:39:22 PM (16 years ago)
Author:
westi
Message:

Move the link timestamp updater to the new HTTP api. See #7793 props jacobsantos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/update-links.php

    r8645 r9011  
    1616require_once('../wp-load.php');
    1717
    18 /** Load Snoopy HTTP Client class */
    19 require_once( ABSPATH . 'wp-includes/class-snoopy.php');
    20 
    2118if ( !get_option('use_linksupdate') )
    2219    wp_die(__('Feature disabled.'));
     
    3128$query_string = "uris=$link_uris";
    3229
    33 $http_request  = "POST /updated-batch/ HTTP/1.0\r\n";
    34 $http_request .= "Host: api.pingomatic.com\r\n";
    35 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_option('blog_charset')."\r\n";
    36 $http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n";
    37 $http_request .= 'User-Agent: WordPress/' . $wp_version . "\r\n";
    38 $http_request .= "\r\n";
    39 $http_request .= $query_string;
     30$options = array();
     31$options['timeout'] = 30;
     32$options['body'] = $query_string;
    4033
    41 $response = '';
    42 if ( false !== ( $fs = @fsockopen('api.pingomatic.com', 80, $errno, $errstr, 5) ) ) {
    43     fwrite($fs, $http_request);
    44     while ( !feof($fs) )
    45         $response .= fgets($fs, 1160); // One TCP-IP packet
    46     fclose($fs);
     34$options['headers'] = array(
     35    'content-type' => 'application/x-www-form-urlencoded; charset='.get_option('blog_charset'),
     36    'content-length' => strlen( $query_string ),
     37);
    4738
    48     $response = explode("\r\n\r\n", $response, 2);
    49     $body = trim( $response[1] );
    50     $body = str_replace(array("\r\n", "\r"), "\n", $body);
     39$response = wp_remote_get('http://api.pingomatic.com/updated-batch/', $options);
    5140
    52     $returns = explode("\n", $body);
     41if ( $response['response']['code'] != 200 )
     42    wp_die(__('Request Failed.'));
    5343
    54     foreach ($returns as $return) :
    55         $time = substr($return, 0, 19);
    56         $uri = preg_replace('/(.*?) | (.*?)/', '$2', $return);
    57         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_updated = %s WHERE link_url = %s", $time, $uri) );
    58     endforeach;
    59 }
     44$body = str_replace(array("\r\n", "\r"), "\n", $response['body']);
     45$returns = explode("\n", $body);
     46
     47foreach ($returns as $return) :
     48    $time = substr($return, 0, 19);
     49    $uri = preg_replace('/(.*?) | (.*?)/', '$2', $return);
     50    $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_updated = %s WHERE link_url = %s", $time, $uri) );
     51endforeach;
     52
    6053?>
Note: See TracChangeset for help on using the changeset viewer.