656 | | ?> |
| 656 | if ( !function_exists('wp_update_links') ) : |
| 657 | // the links update function |
| 658 | function 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 | } |
| 700 | endif; |
| 701 | |
| 702 | if ( !function_exists('wp_links_update_change') ) : |
| 703 | // the update_links scheduler function |
| 704 | function 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 | } |
| 715 | endif; |
| 716 | |
| 717 | ?> |
| 718 | No newline at end of file |