Changeset 3900
- Timestamp:
- 06/22/2006 07:44:36 PM (19 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/comment.php
r3887 r3900 437 437 } 438 438 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 // 518 442 519 443 function discover_pingback_server_uri($url, $timeout_bytes = 2048) { … … 607 531 } 608 532 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); 620 753 } 621 754 -
trunk/wp-includes/functions.php
r3897 r3900 320 320 } 321 321 322 function weblog_ping($server = '', $path = '') {323 global $wp_version;324 include_once (ABSPATH . WPINC . '/class-IXR.php');325 326 // using a timeout of 3 seconds should be enough to cover slow servers327 $client = new IXR_Client($server, ((!strlen(trim($path)) || ('/' == $path)) ? false : $path));328 $client->timeout = 3;329 $client->useragent .= ' -- WordPress/'.$wp_version;330 331 // when set to true, this outputs debug messages by itself332 $client->debug = false;333 $home = trailingslashit( get_option('home') );334 if ( !$client->query('weblogUpdates.extendedPing', get_settings('blogname'), $home, get_bloginfo('rss2_url') ) ) // then try a normal ping335 $client->query('weblogUpdates.ping', get_settings('blogname'), $home);336 }337 338 function generic_ping($post_id = 0) {339 $services = get_settings('ping_sites');340 $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines341 $services = trim($services);342 if ( '' != $services ) {343 $services = explode("\n", $services);344 foreach ($services as $service) {345 weblog_ping($service);346 }347 }348 349 return $post_id;350 }351 352 // Send a Trackback353 function trackback($trackback_url, $title, $excerpt, $ID) {354 global $wpdb, $wp_version;355 356 if ( empty($trackback_url) )357 return;358 359 $title = urlencode($title);360 $excerpt = urlencode($excerpt);361 $blog_name = urlencode(get_settings('blogname'));362 $tb_url = $trackback_url;363 $url = urlencode(get_permalink($ID));364 $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt";365 $trackback_url = parse_url($trackback_url);366 $http_request = 'POST ' . $trackback_url['path'] . ($trackback_url['query'] ? '?'.$trackback_url['query'] : '') . " HTTP/1.0\r\n";367 $http_request .= 'Host: '.$trackback_url['host']."\r\n";368 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_settings('blog_charset')."\r\n";369 $http_request .= 'Content-Length: '.strlen($query_string)."\r\n";370 $http_request .= "User-Agent: WordPress/" . $wp_version;371 $http_request .= "\r\n\r\n";372 $http_request .= $query_string;373 if ( '' == $trackback_url['port'] )374 $trackback_url['port'] = 80;375 $fs = @fsockopen($trackback_url['host'], $trackback_url['port'], $errno, $errstr, 4);376 @fputs($fs, $http_request);377 /*378 $debug_file = 'trackback.log';379 $fp = fopen($debug_file, 'a');380 fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n");381 while(!@feof($fs)) {382 fwrite($fp, @fgets($fs, 4096));383 }384 fwrite($fp, "\n\n");385 fclose($fp);386 */387 @fclose($fs);388 389 $tb_url = addslashes( $tb_url );390 $wpdb->query("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'");391 return $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = '$ID'");392 }393 394 322 function make_url_footnote($content) { 395 323 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches); … … 819 747 global $wpdb; 820 748 return $wpdb->num_queries; 821 }822 823 function privacy_ping_filter( $sites ) {824 if ( '0' != get_option('blog_public') )825 return $sites;826 else827 return '';828 749 } 829 750 … … 1069 990 } 1070 991 1071 function do_trackbacks($post_id) {1072 global $wpdb;1073 1074 $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $post_id");1075 $to_ping = get_to_ping($post_id);1076 $pinged = get_pung($post_id);1077 if ( empty($to_ping) ) {1078 $wpdb->query("UPDATE $wpdb->posts SET to_ping = '' WHERE ID = '$post_id'");1079 return;1080 }1081 1082 if (empty($post->post_excerpt))1083 $excerpt = apply_filters('the_content', $post->post_content);1084 else1085 $excerpt = apply_filters('the_excerpt', $post->post_excerpt);1086 $excerpt = str_replace(']]>', ']]>', $excerpt);1087 $excerpt = strip_tags($excerpt);1088 if ( function_exists('mb_strcut') ) // For international trackbacks1089 $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...';1090 else1091 $excerpt = substr($excerpt, 0, 252) . '...';1092 1093 $post_title = apply_filters('the_title', $post->post_title);1094 $post_title = strip_tags($post_title);1095 1096 if ($to_ping) : foreach ($to_ping as $tb_ping) :1097 $tb_ping = trim($tb_ping);1098 if ( !in_array($tb_ping, $pinged) ) {1099 trackback($tb_ping, $post_title, $excerpt, $post_id);1100 $pinged[] = $tb_ping;1101 } else {1102 $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'");1103 }1104 endforeach; endif;1105 }1106 1107 function do_all_pings() {1108 global $wpdb;1109 1110 // Do pingbacks1111 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")) {1112 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");1113 pingback($ping->post_content, $ping->ID);1114 }1115 1116 // Do Enclosures1117 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")) {1118 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");1119 do_enclose($enclosure->post_content, $enclosure->ID);1120 }1121 1122 // Do Trackbacks1123 $trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'");1124 if ( is_array($trackbacks) ) {1125 foreach ( $trackbacks as $trackback ) {1126 do_trackbacks($trackback->ID);1127 }1128 }1129 1130 //Do Update Services/Generic Pings1131 generic_ping();1132 }1133 1134 992 function wp_proxy_check($ipnum) { 1135 993 if ( get_option('open_proxy_check') && isset($ipnum) ) { -
trunk/wp-includes/post-template.php
r3852 r3900 35 35 if ( !empty($post->post_password) ) 36 36 $title = sprintf(__('Protected: %s'), $title); 37 else if ( 'private' == $post->post_status ) 38 $title = sprintf(__('Private: %s'), $title); 37 39 38 40 return $title; -
trunk/wp-includes/post.php
r3854 r3900 1118 1118 // Attachment functions 1119 1119 // 1120 1121 function is_local_attachment($url) { 1122 if ( !strstr($url, get_bloginfo('home') ) ) 1123 return false; 1124 if ( strstr($url, get_bloginfo('home') . '/?attachment_id=') ) 1125 return true; 1126 if ( $id = url_to_postid($url) ) { 1127 $post = & get_post($id); 1128 if ( 'attachment' == $post->post_type ) 1129 return true; 1130 } 1131 return false; 1132 } 1120 1133 1121 1134 function wp_insert_attachment($object, $file = false, $post_parent = 0) { -
trunk/wp-includes/query.php
r3896 r3900 851 851 $where .= " AND (post_type = '$post_type' AND (post_status = 'publish'"; 852 852 853 if ( is_admin() ) {853 if ( is_admin() ) 854 854 $where .= " OR post_status = 'future' OR post_status = 'draft'"; 855 855 856 if ( is_user_logged_in() ) { 857 if ( 'post' == $post_type ) 858 $cap = 'edit_private_posts'; 859 else 860 $cap = 'edit_private_pages'; 861 862 if ( current_user_can($cap) ) 863 $where .= "OR post_status = 'private'"; 864 else 865 $where .= " OR post_author = $user_ID AND post_status = 'private'"; 866 } 856 if ( is_user_logged_in() ) { 857 if ( 'post' == $post_type ) 858 $cap = 'edit_private_posts'; 859 else 860 $cap = 'edit_private_pages'; 861 862 if ( current_user_can($cap) ) 863 $where .= " OR post_status = 'private'"; 864 else 865 $where .= " OR post_author = $user_ID AND post_status = 'private'"; 867 866 } 868 867
Note: See TracChangeset
for help on using the changeset viewer.