| 439 | | function pingback($content, $post_ID) { |
|---|
| 440 | | global $wp_version, $wpdb; |
|---|
| 441 | | include_once (ABSPATH . WPINC . '/class-IXR.php'); |
|---|
| 442 | | |
|---|
| 443 | | // original code by Mort (http://mort.mine.nu:8080) |
|---|
| 444 | | $log = debug_fopen(ABSPATH . '/pingback.log', 'a'); |
|---|
| 445 | | $post_links = array(); |
|---|
| 446 | | debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n"); |
|---|
| 447 | | |
|---|
| 448 | | $pung = get_pung($post_ID); |
|---|
| 449 | | |
|---|
| 450 | | // Variables |
|---|
| 451 | | $ltrs = '\w'; |
|---|
| 452 | | $gunk = '/#~:.?+=&%@!\-'; |
|---|
| 453 | | $punc = '.:?\-'; |
|---|
| 454 | | $any = $ltrs . $gunk . $punc; |
|---|
| 455 | | |
|---|
| 456 | | // Step 1 |
|---|
| 457 | | // Parsing the post, external links (if any) are stored in the $post_links array |
|---|
| 458 | | // This regexp comes straight from phpfreaks.com |
|---|
| 459 | | // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php |
|---|
| 460 | | preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp); |
|---|
| 461 | | |
|---|
| 462 | | // Debug |
|---|
| 463 | | debug_fwrite($log, 'Post contents:'); |
|---|
| 464 | | debug_fwrite($log, $content."\n"); |
|---|
| 465 | | |
|---|
| 466 | | // Step 2. |
|---|
| 467 | | // Walking thru the links array |
|---|
| 468 | | // first we get rid of links pointing to sites, not to specific files |
|---|
| 469 | | // Example: |
|---|
| 470 | | // http://dummy-weblog.org |
|---|
| 471 | | // http://dummy-weblog.org/ |
|---|
| 472 | | // http://dummy-weblog.org/post.php |
|---|
| 473 | | // We don't wanna ping first and second types, even if they have a valid <link/> |
|---|
| 474 | | |
|---|
| 475 | | foreach($post_links_temp[0] as $link_test) : |
|---|
| 476 | | if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself |
|---|
| 477 | | && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. |
|---|
| 478 | | $test = parse_url($link_test); |
|---|
| 479 | | if (isset($test['query'])) |
|---|
| 480 | | $post_links[] = $link_test; |
|---|
| 481 | | elseif(($test['path'] != '/') && ($test['path'] != '')) |
|---|
| 482 | | $post_links[] = $link_test; |
|---|
| 483 | | endif; |
|---|
| 484 | | endforeach; |
|---|
| 485 | | |
|---|
| 486 | | do_action('pre_ping', array(&$post_links, &$pung)); |
|---|
| 487 | | |
|---|
| 488 | | foreach ($post_links as $pagelinkedto){ |
|---|
| 489 | | debug_fwrite($log, "Processing -- $pagelinkedto\n"); |
|---|
| 490 | | $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048); |
|---|
| 491 | | |
|---|
| 492 | | if ($pingback_server_url) { |
|---|
| 493 | | @ set_time_limit( 60 ); |
|---|
| 494 | | // Now, the RPC call |
|---|
| 495 | | debug_fwrite($log, "Page Linked To: $pagelinkedto \n"); |
|---|
| 496 | | debug_fwrite($log, 'Page Linked From: '); |
|---|
| 497 | | $pagelinkedfrom = get_permalink($post_ID); |
|---|
| 498 | | debug_fwrite($log, $pagelinkedfrom."\n"); |
|---|
| 499 | | |
|---|
| 500 | | // using a timeout of 3 seconds should be enough to cover slow servers |
|---|
| 501 | | $client = new IXR_Client($pingback_server_url); |
|---|
| 502 | | $client->timeout = 3; |
|---|
| 503 | | $client->useragent .= ' -- WordPress/' . $wp_version; |
|---|
| 504 | | |
|---|
| 505 | | // when set to true, this outputs debug messages by itself |
|---|
| 506 | | $client->debug = false; |
|---|
| 507 | | |
|---|
| 508 | | if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto ) ) |
|---|
| 509 | | add_ping( $post_ID, $pagelinkedto ); |
|---|
| 510 | | else |
|---|
| 511 | | debug_fwrite($log, "Error.\n Fault code: ".$client->getErrorCode()." : ".$client->getErrorMessage()."\n"); |
|---|
| 512 | | } |
|---|
| 513 | | } |
|---|
| 514 | | |
|---|
| 515 | | debug_fwrite($log, "\nEND: ".time()."\n****************************\n"); |
|---|
| 516 | | debug_fclose($log); |
|---|
| 517 | | } |
|---|
| | 439 | // |
|---|
| | 440 | // Ping and trackback functions. |
|---|
| | 441 | // |
|---|
| 609 | | function is_local_attachment($url) { |
|---|
| 610 | | if ( !strstr($url, get_bloginfo('home') ) ) |
|---|
| 611 | | return false; |
|---|
| 612 | | if ( strstr($url, get_bloginfo('home') . '/?attachment_id=') ) |
|---|
| 613 | | return true; |
|---|
| 614 | | if ( $id = url_to_postid($url) ) { |
|---|
| 615 | | $post = & get_post($id); |
|---|
| 616 | | if ( 'attachment' == $post->post_type ) |
|---|
| 617 | | return true; |
|---|
| 618 | | } |
|---|
| 619 | | return false; |
|---|
| | 533 | function do_all_pings() { |
|---|
| | 534 | global $wpdb; |
|---|
| | 535 | |
|---|
| | 536 | // Do pingbacks |
|---|
| | 537 | while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { |
|---|
| | 538 | $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';"); |
|---|
| | 539 | pingback($ping->post_content, $ping->ID); |
|---|
| | 540 | } |
|---|
| | 541 | |
|---|
| | 542 | // Do Enclosures |
|---|
| | 543 | while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { |
|---|
| | 544 | $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';"); |
|---|
| | 545 | do_enclose($enclosure->post_content, $enclosure->ID); |
|---|
| | 546 | } |
|---|
| | 547 | |
|---|
| | 548 | // Do Trackbacks |
|---|
| | 549 | $trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'"); |
|---|
| | 550 | if ( is_array($trackbacks) ) { |
|---|
| | 551 | foreach ( $trackbacks as $trackback ) { |
|---|
| | 552 | do_trackbacks($trackback->ID); |
|---|
| | 553 | } |
|---|
| | 554 | } |
|---|
| | 555 | |
|---|
| | 556 | //Do Update Services/Generic Pings |
|---|
| | 557 | generic_ping(); |
|---|
| | 558 | } |
|---|
| | 559 | |
|---|
| | 560 | function do_trackbacks($post_id) { |
|---|
| | 561 | global $wpdb; |
|---|
| | 562 | |
|---|
| | 563 | $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $post_id"); |
|---|
| | 564 | $to_ping = get_to_ping($post_id); |
|---|
| | 565 | $pinged = get_pung($post_id); |
|---|
| | 566 | if ( empty($to_ping) ) { |
|---|
| | 567 | $wpdb->query("UPDATE $wpdb->posts SET to_ping = '' WHERE ID = '$post_id'"); |
|---|
| | 568 | return; |
|---|
| | 569 | } |
|---|
| | 570 | |
|---|
| | 571 | if (empty($post->post_excerpt)) |
|---|
| | 572 | $excerpt = apply_filters('the_content', $post->post_content); |
|---|
| | 573 | else |
|---|
| | 574 | $excerpt = apply_filters('the_excerpt', $post->post_excerpt); |
|---|
| | 575 | $excerpt = str_replace(']]>', ']]>', $excerpt); |
|---|
| | 576 | $excerpt = strip_tags($excerpt); |
|---|
| | 577 | if ( function_exists('mb_strcut') ) // For international trackbacks |
|---|
| | 578 | $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...'; |
|---|
| | 579 | else |
|---|
| | 580 | $excerpt = substr($excerpt, 0, 252) . '...'; |
|---|
| | 581 | |
|---|
| | 582 | $post_title = apply_filters('the_title', $post->post_title); |
|---|
| | 583 | $post_title = strip_tags($post_title); |
|---|
| | 584 | |
|---|
| | 585 | if ($to_ping) : foreach ($to_ping as $tb_ping) : |
|---|
| | 586 | $tb_ping = trim($tb_ping); |
|---|
| | 587 | if ( !in_array($tb_ping, $pinged) ) { |
|---|
| | 588 | trackback($tb_ping, $post_title, $excerpt, $post_id); |
|---|
| | 589 | $pinged[] = $tb_ping; |
|---|
| | 590 | } else { |
|---|
| | 591 | $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'"); |
|---|
| | 592 | } |
|---|
| | 593 | endforeach; endif; |
|---|
| | 594 | } |
|---|
| | 595 | |
|---|
| | 596 | function generic_ping($post_id = 0) { |
|---|
| | 597 | $services = get_settings('ping_sites'); |
|---|
| | 598 | $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines |
|---|
| | 599 | $services = trim($services); |
|---|
| | 600 | if ( '' != $services ) { |
|---|
| | 601 | $services = explode("\n", $services); |
|---|
| | 602 | foreach ($services as $service) { |
|---|
| | 603 | weblog_ping($service); |
|---|
| | 604 | } |
|---|
| | 605 | } |
|---|
| | 606 | |
|---|
| | 607 | return $post_id; |
|---|
| | 608 | } |
|---|
| | 609 | |
|---|
| | 610 | function pingback($content, $post_ID) { |
|---|
| | 611 | global $wp_version, $wpdb; |
|---|
| | 612 | include_once (ABSPATH . WPINC . '/class-IXR.php'); |
|---|
| | 613 | |
|---|
| | 614 | // original code by Mort (http://mort.mine.nu:8080) |
|---|
| | 615 | $log = debug_fopen(ABSPATH . '/pingback.log', 'a'); |
|---|
| | 616 | $post_links = array(); |
|---|
| | 617 | debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n"); |
|---|
| | 618 | |
|---|
| | 619 | $pung = get_pung($post_ID); |
|---|
| | 620 | |
|---|
| | 621 | // Variables |
|---|
| | 622 | $ltrs = '\w'; |
|---|
| | 623 | $gunk = '/#~:.?+=&%@!\-'; |
|---|
| | 624 | $punc = '.:?\-'; |
|---|
| | 625 | $any = $ltrs . $gunk . $punc; |
|---|
| | 626 | |
|---|
| | 627 | // Step 1 |
|---|
| | 628 | // Parsing the post, external links (if any) are stored in the $post_links array |
|---|
| | 629 | // This regexp comes straight from phpfreaks.com |
|---|
| | 630 | // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php |
|---|
| | 631 | preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp); |
|---|
| | 632 | |
|---|
| | 633 | // Debug |
|---|
| | 634 | debug_fwrite($log, 'Post contents:'); |
|---|
| | 635 | debug_fwrite($log, $content."\n"); |
|---|
| | 636 | |
|---|
| | 637 | // Step 2. |
|---|
| | 638 | // Walking thru the links array |
|---|
| | 639 | // first we get rid of links pointing to sites, not to specific files |
|---|
| | 640 | // Example: |
|---|
| | 641 | // http://dummy-weblog.org |
|---|
| | 642 | // http://dummy-weblog.org/ |
|---|
| | 643 | // http://dummy-weblog.org/post.php |
|---|
| | 644 | // We don't wanna ping first and second types, even if they have a valid <link/> |
|---|
| | 645 | |
|---|
| | 646 | foreach($post_links_temp[0] as $link_test) : |
|---|
| | 647 | if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself |
|---|
| | 648 | && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments. |
|---|
| | 649 | $test = parse_url($link_test); |
|---|
| | 650 | if (isset($test['query'])) |
|---|
| | 651 | $post_links[] = $link_test; |
|---|
| | 652 | elseif(($test['path'] != '/') && ($test['path'] != '')) |
|---|
| | 653 | $post_links[] = $link_test; |
|---|
| | 654 | endif; |
|---|
| | 655 | endforeach; |
|---|
| | 656 | |
|---|
| | 657 | do_action('pre_ping', array(&$post_links, &$pung)); |
|---|
| | 658 | |
|---|
| | 659 | foreach ($post_links as $pagelinkedto){ |
|---|
| | 660 | debug_fwrite($log, "Processing -- $pagelinkedto\n"); |
|---|
| | 661 | $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048); |
|---|
| | 662 | |
|---|
| | 663 | if ($pingback_server_url) { |
|---|
| | 664 | @ set_time_limit( 60 ); |
|---|
| | 665 | // Now, the RPC call |
|---|
| | 666 | debug_fwrite($log, "Page Linked To: $pagelinkedto \n"); |
|---|
| | 667 | debug_fwrite($log, 'Page Linked From: '); |
|---|
| | 668 | $pagelinkedfrom = get_permalink($post_ID); |
|---|
| | 669 | debug_fwrite($log, $pagelinkedfrom."\n"); |
|---|
| | 670 | |
|---|
| | 671 | // using a timeout of 3 seconds should be enough to cover slow servers |
|---|
| | 672 | $client = new IXR_Client($pingback_server_url); |
|---|
| | 673 | $client->timeout = 3; |
|---|
| | 674 | $client->useragent .= ' -- WordPress/' . $wp_version; |
|---|
| | 675 | |
|---|
| | 676 | // when set to true, this outputs debug messages by itself |
|---|
| | 677 | $client->debug = false; |
|---|
| | 678 | |
|---|
| | 679 | if ( $client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto ) ) |
|---|
| | 680 | add_ping( $post_ID, $pagelinkedto ); |
|---|
| | 681 | else |
|---|
| | 682 | debug_fwrite($log, "Error.\n Fault code: ".$client->getErrorCode()." : ".$client->getErrorMessage()."\n"); |
|---|
| | 683 | } |
|---|
| | 684 | } |
|---|
| | 685 | |
|---|
| | 686 | debug_fwrite($log, "\nEND: ".time()."\n****************************\n"); |
|---|
| | 687 | debug_fclose($log); |
|---|
| | 688 | } |
|---|
| | 689 | |
|---|
| | 690 | function privacy_ping_filter( $sites ) { |
|---|
| | 691 | if ( '0' != get_option('blog_public') ) |
|---|
| | 692 | return $sites; |
|---|
| | 693 | else |
|---|
| | 694 | return ''; |
|---|
| | 695 | } |
|---|
| | 696 | |
|---|
| | 697 | // Send a Trackback |
|---|
| | 698 | function trackback($trackback_url, $title, $excerpt, $ID) { |
|---|
| | 699 | global $wpdb, $wp_version; |
|---|
| | 700 | |
|---|
| | 701 | if ( empty($trackback_url) ) |
|---|
| | 702 | return; |
|---|
| | 703 | |
|---|
| | 704 | $title = urlencode($title); |
|---|
| | 705 | $excerpt = urlencode($excerpt); |
|---|
| | 706 | $blog_name = urlencode(get_settings('blogname')); |
|---|
| | 707 | $tb_url = $trackback_url; |
|---|
| | 708 | $url = urlencode(get_permalink($ID)); |
|---|
| | 709 | $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt"; |
|---|
| | 710 | $trackback_url = parse_url($trackback_url); |
|---|
| | 711 | $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?'.$trackback_url['query'] : '') . " HTTP/1.0\r\n"; |
|---|
| | 712 | $http_request .= 'Host: '.$trackback_url['host']."\r\n"; |
|---|
| | 713 | $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_settings('blog_charset')."\r\n"; |
|---|
| | 714 | $http_request .= 'Content-Length: '.strlen($query_string)."\r\n"; |
|---|
| | 715 | $http_request .= "User-Agent: WordPress/" . $wp_version; |
|---|
| | 716 | $http_request .= "\r\n\r\n"; |
|---|
| | 717 | $http_request .= $query_string; |
|---|
| | 718 | if ( '' == $trackback_url['port'] ) |
|---|
| | 719 | $trackback_url['port'] = 80; |
|---|
| | 720 | $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4); |
|---|
| | 721 | @fputs($fs, $http_request); |
|---|
| | 722 | /* |
|---|
| | 723 | $debug_file = 'trackback.log'; |
|---|
| | 724 | $fp = fopen($debug_file, 'a'); |
|---|
| | 725 | fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"); |
|---|
| | 726 | while(!@feof($fs)) { |
|---|
| | 727 | fwrite($fp, @fgets($fs, 4096)); |
|---|
| | 728 | } |
|---|
| | 729 | fwrite($fp, "\n\n"); |
|---|
| | 730 | fclose($fp); |
|---|
| | 731 | */ |
|---|
| | 732 | @fclose($fs); |
|---|
| | 733 | |
|---|
| | 734 | $tb_url = addslashes( $tb_url ); |
|---|
| | 735 | $wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'"); |
|---|
| | 736 | return $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = '$ID'"); |
|---|
| | 737 | } |
|---|
| | 738 | |
|---|
| | 739 | function weblog_ping($server = '', $path = '') { |
|---|
| | 740 | global $wp_version; |
|---|
| | 741 | include_once (ABSPATH . WPINC . '/class-IXR.php'); |
|---|
| | 742 | |
|---|
| | 743 | // using a timeout of 3 seconds should be enough to cover slow servers |
|---|
| | 744 | $client = new IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path)); |
|---|
| | 745 | $client->timeout = 3; |
|---|
| | 746 | $client->useragent .= ' -- WordPress/'.$wp_version; |
|---|
| | 747 | |
|---|
| | 748 | // when set to true, this outputs debug messages by itself |
|---|
| | 749 | $client->debug = false; |
|---|
| | 750 | $home = trailingslashit( get_option('home') ); |
|---|
| | 751 | if ( !$client->query('weblogUpdates.extendedPing', get_settings('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping |
|---|
| | 752 | $client->query('weblogUpdates.ping', get_settings('blogname'), $home); |
|---|