Make WordPress Core

Ticket #4230: 4230.diff

File 4230.diff, 3.6 KB (added by Otto42, 17 years ago)

Makes update links functionality into a wp-cron job.

  • wp-includes/default-filters.php

     
    190190add_action('save_post', '_save_post_hook', 5, 2);
    191191add_action('transition_post_status', '_transition_post_status', 5, 3);
    192192
     193// actions to schedule the update_links call
     194add_action('update_links','wp_update_links');
     195add_action('update_option_use_linksupdate', 'links_update_change',10,2);
    193196?>
     197 No newline at end of file
  • wp-includes/pluggable.php

     
    174174        if ( empty( $headers ) ) {
    175175                $headers = array();
    176176        } elseif ( !is_array( $headers ) ) {
    177                 // Explode the headers out, so this function can take both 
     177                // Explode the headers out, so this function can take both
    178178                // string headers and an array of headers.
    179179                $tempheaders = (array) explode( "\n", $headers );
    180180                $headers = array();
     
    396396        $location = apply_filters('wp_redirect', $location, $status);
    397397
    398398        if ( !$location ) // allows the wp_redirect filter to cancel a redirect
    399                 return false; 
     399                return false;
    400400
    401401        $location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%]|i', '', $location);
    402402        $location = wp_kses_no_null($location);
     
    548548        global $wpdb;
    549549
    550550        if( get_option( "moderation_notify" ) == 0 )
    551                 return true; 
     551                return true;
    552552
    553553        $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
    554554        $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");
     
    653653}
    654654endif;
    655655
    656 ?>
     656if ( !function_exists('wp_update_links') ) :
     657// the links update function
     658function wp_update_links() {
     659
     660        if ( !get_option('use_linksupdate') )
     661                return;
     662
     663        $link_uris = $wpdb->get_col("SELECT link_url FROM $wpdb->links");
     664
     665        if ( !$link_uris )
     666                return;
     667
     668        $link_uris = urlencode( join( $link_uris, "\n" ) );
     669
     670        $query_string = "uris=$link_uris";
     671
     672        $http_request  = "POST /updated-batch/ HTTP/1.0\r\n";
     673        $http_request .= "Host: api.pingomatic.com\r\n";
     674        $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_option('blog_charset')."\r\n";
     675        $http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n";
     676        $http_request .= 'User-Agent: WordPress/' . $wp_version . "\r\n";
     677        $http_request .= "\r\n";
     678        $http_request .= $query_string;
     679
     680        $response = '';
     681        if ( false !== ( $fs = @fsockopen('api.pingomatic.com', 80, $errno, $errstr, 5) ) ) {
     682                fwrite($fs, $http_request);
     683                while ( !feof($fs) )
     684                        $response .= fgets($fs, 1160); // One TCP-IP packet
     685                fclose($fs);
     686
     687                $response = explode("\r\n\r\n", $response, 2);
     688                $body = trim( $response[1] );
     689                $body = str_replace(array("\r\n", "\r"), "\n", $body);
     690
     691                $returns = explode("\n", $body);
     692
     693                foreach ($returns as $return) :
     694                        $time = $wpdb->escape( substr($return, 0, 19) );
     695                        $uri = $wpdb->escape( preg_replace('/(.*?) | (.*?)/', '$2', $return) );
     696                        $wpdb->query("UPDATE $wpdb->links SET link_updated = '$time' WHERE link_url = '$uri'");
     697                endforeach;
     698        }
     699}
     700endif;
     701
     702if ( !function_exists('wp_links_update_change') ) :
     703// the update_links scheduler function
     704function wp_links_update_change($oldvalue, $newvalue) {
     705
     706        if ($oldvalue == $newvalue) return;
     707
     708        if ($newvalue == 1) {
     709                wp_schedule_event(time(), apply_filters('update_links_schedule','daily'), 'update_links');
     710        }
     711        else {
     712                wp_clear_scheduled_hook('update_links');
     713        }
     714}
     715endif;
     716
     717?>
     718 No newline at end of file