Make WordPress Core

Changeset 1794


Ignore:
Timestamp:
10/14/2004 07:26:41 AM (22 years ago)
Author:
saxmatt
Message:

Trackback and pingback cleanups.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/post.php

    r1793 r1794  
    1414
    1515if (!get_magic_quotes_gpc()) {
    16 $_GET    = add_magic_quotes($_GET);
    17 $_POST   = add_magic_quotes($_POST);
    18 $_COOKIE = add_magic_quotes($_COOKIE);
     16        $_GET    = add_magic_quotes($_GET);
     17        $_POST   = add_magic_quotes($_POST);
     18        $_COOKIE = add_magic_quotes($_COOKIE);
    1919}
    2020
    … …  
    3838switch($action) {
    3939case 'post':
    40                 $standalone = 1;
    41                 require_once('admin-header.php');
    42 
    43         $post_ID = $wpdb->get_var("SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1") + 1;
    44 
    45                 $post_pingback = intval($_POST['post_pingback']);
    46                 $content = apply_filters('content_save_pre', $_POST['content']);
    47                 $content = format_to_post($content);
    48                 $excerpt = apply_filters('excerpt_save_pre',$_POST['excerpt']);
    49                 $excerpt = format_to_post($excerpt);
    50                 $post_title = $_POST['post_title'];
    51                 $post_categories = $_POST['post_category'];
    52                 $post_status = $_POST['post_status'];
    53                 $post_name = $_POST['post_name'];
    54                 $post_parent = 0;
    55                 if (isset($_POST['parent_id'])) {
    56                         $post_parent = $_POST['parent_id'];
    57                 }
    58 
    59                 if (empty($post_status)) $post_status = 'draft';
    60                 // Double-check
    61                 if ( 'publish' == $post_status && 1 == $user_level && 2 != get_option('new_users_can_blog') )
    62                         $post_status = 'draft';
    63                 $comment_status = $_POST['comment_status'];
    64                 if (empty($comment_status)) $comment_status = get_settings('default_comment_status');
    65                 $ping_status = $_POST['ping_status'];
    66                 if (empty($ping_status)) $ping_status = get_settings('default_ping_status');
    67                 $post_password = $_POST['post_password'];
    68                
    69                 if (empty($post_name)) {
    70                         if (! empty($post_title)) {
    71                                 $post_name = sanitize_title($post_title, $post_ID);
    72                         }
    73                 } else {
    74                         $post_name = sanitize_title($post_name, $post_ID);
    75                 }
    76 
    77                 $trackback = $_POST['trackback_url'];
    78         // Format trackbacks
    79         $trackback = preg_replace('|\s+|', '\n', $trackback);
     40        $standalone = 1;
     41        require_once('admin-header.php');
     42
     43        $post_ID = $wpdb->get_var("SELECT MAX(ID) FROM $wpdb->posts") + 1;
     44
     45        $post_pingback = intval($_POST['post_pingback']);
     46        $content = apply_filters('content_save_pre', $_POST['content']);
     47        $content = format_to_post($content);
     48        $excerpt = apply_filters('excerpt_save_pre',$_POST['excerpt']);
     49        $excerpt = format_to_post($excerpt);
     50        $post_title = $_POST['post_title'];
     51        $post_categories = $_POST['post_category'];
     52        $post_status = $_POST['post_status'];
     53        $post_name = $_POST['post_name'];
     54        $post_parent = 0;
     55
     56        if ( isset($_POST['parent_id']) )
     57                $post_parent = $_POST['parent_id'];
     58
     59        if ( empty($post_status) )
     60                $post_status = 'draft';
     61        // Double-check
     62        if ( 'publish' == $post_status && 1 == $user_level && 2 != get_option('new_users_can_blog') )
     63                $post_status = 'draft';
     64        $comment_status = $_POST['comment_status'];
     65        if ( empty($comment_status) )
     66                $comment_status = get_option('default_comment_status');
     67        $ping_status = $_POST['ping_status'];
     68        if ( empty($ping_status) )
     69                $ping_status = get_option('default_ping_status');
     70        $post_password = $_POST['post_password'];
     71       
     72        if ( empty($post_name) ) {
     73                if ( !empty($post_title) )
     74                        $post_name = sanitize_title($post_title, $post_ID);
     75        } else {
     76                $post_name = sanitize_title($post_name, $post_ID);
     77        }
     78
     79        $trackback = $_POST['trackback_url'];
     80        $trackback = preg_replace('|\s+|', "\n", $trackback);
    8081
    8182        if ($user_level == 0)
    … …  
    9394                $mn = ($mn > 59) ? $mn - 60 : $mn;
    9495                $ss = ($ss > 59) ? $ss - 60 : $ss;
    95         $now = "$aa-$mm-$jj $hh:$mn:$ss";
    96         $now_gmt = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
    97         } else {
    98         $now = current_time('mysql');
    99         $now_gmt = current_time('mysql', 1);
     96                $now = "$aa-$mm-$jj $hh:$mn:$ss";
     97                $now_gmt = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
     98        } else {
     99                $now = current_time('mysql');
     100                $now_gmt = current_time('mysql', 1);
    100101        }
    101102
    … …  
    110111                        (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent)
    111112                        VALUES
    112                         ('0', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt', '$post_parent')
     113                        ('$post_ID', '$user_ID', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt', '$post_parent')
    113114                        ";
    114115
    … …  
    128129                }
    129130        } else {
    130                 $location = 'post.php';
    131         }
     131                $location = 'post.php?posted=true';
     132        }
     133
    132134        if ( '' != $_POST['advanced'] || isset($_POST['save']) )
    133135                $location = "post.php?action=edit&post=$post_ID";
    … …  
    138140        header("Location: $location"); // Send user on their way while we keep working
    139141
    140 
    141142        // Insert categories
    142143        // Check to make sure there is a category, if not just set it to some default
    143         if (!$post_categories) $post_categories[] = 1;
     144        if (!$post_categories) $post_categories[] = get_option('default_category');
    144145        foreach ($post_categories as $post_category) {
    145146                // Double check it's not there already
    146147                $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_ID AND category_id = $post_category");
    147148
    148                  if (!$exists && $result) {
     149                 if (!$exists) {
    149150                        $wpdb->query("
    150151                        INSERT INTO $wpdb->post2cat
    … …  
    159160
    160161        $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
    161        
    162         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
    163                         sleep($sleep_after_edit);
    164         }
    165 
    166         if ($post_status == 'publish') {
    167 
    168                 if ($post_pingback) {
     162
     163        do_action('save_post', $post_ID);
     164
     165        if ('publish' == $post_status) {
     166                if ($post_pingback)
    169167                        pingback($content, $post_ID);
    170                 }
    171                
     168                do_trackbacks($post_ID);
    172169                do_action('publish_post', $post_ID);
    173 
    174                 // Time for trackbacks
    175                 $to_ping = $wpdb->get_var("SELECT to_ping FROM $wpdb->posts WHERE ID = $post_ID");
    176                 $pinged = $wpdb->get_var("SELECT pinged FROM $wpdb->posts WHERE ID = $post_ID");
    177                 $pinged = explode("\n", $pinged);
    178                 if ('' != $to_ping) {
    179                         if (strlen($excerpt) > 0) {
    180                                 $the_excerpt = (strlen(strip_tags($excerpt)) > 255) ? substr(strip_tags($excerpt), 0, 252) . '...' : strip_tags($excerpt)       ;
    181                         } else {
    182                                 $the_excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content);
    183                         }
    184                         $excerpt = stripslashes($the_excerpt);
    185                         $to_pings = explode("\n", $to_ping);
    186                         foreach ($to_pings as $tb_ping) {
    187                                 $tb_ping = trim($tb_ping);
    188                                 if (!in_array($tb_ping, $pinged)) {
    189                                  trackback($tb_ping, stripslashes($post_title), $excerpt, $post_ID);
    190                                 }
    191                         }
    192                 }
    193 
    194         } // end if publish
     170        }
    195171
    196172        if ($post_status == 'static') {
    197173                generate_page_rewrite_rules();
    198 
    199174                add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true);
    200175        }
    … …  
    350325                $location = 'post.php';
    351326        }
    352         header ('Location: ' . $location); // Send user on their way while we keep working
     327        //header ('Location: ' . $location); // Send user on their way while we keep working
    353328
    354329$now = current_time('mysql');
    … …  
    402377                if (!in_array($new_cat, $old_categories))
    403378                        $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
    404         }
    405        
    406         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
    407                 sleep($sleep_after_edit);
    408379        }
    409380
    … …  
    447418        }
    448419
    449         // are we going from draft/private to published?
    450         if ($prev_status != 'publish' && $post_status == 'publish') {
    451                 if ($post_pingback) {
    452                         pingback($content, $post_ID);
    453                 }
    454         } // end if moving from draft/private to published
     420        if ($prev_status != 'publish' && $post_status == 'publish')
     421                do_action('private_to_published', $post_ID);
     422
    455423        if ($post_status == 'publish') {
    456424                do_action('publish_post', $post_ID);
    457 
    458                 // Trackback time.
    459                 $to_ping = trim($wpdb->get_var("SELECT to_ping FROM $wpdb->posts WHERE ID = $post_ID"));
    460                 $pinged = trim($wpdb->get_var("SELECT pinged FROM $wpdb->posts WHERE ID = $post_ID"));
    461                 $pinged = explode("\n", $pinged);
    462                 if ('' != $to_ping) {
    463                         if (strlen($excerpt) > 0) {
    464                                 $the_excerpt = (strlen(strip_tags($excerpt)) > 255) ? substr(strip_tags($excerpt), 0, 252) . '...' : strip_tags($excerpt)       ;
    465                         } else {
    466                                 $the_excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252) . '...' : strip_tags($content);
    467                         }
    468                         $excerpt = stripslashes($the_excerpt);
    469                         $to_pings = explode("\n", $to_ping);
    470                         foreach ($to_pings as $tb_ping) {
    471                                 $tb_ping = trim($tb_ping);
    472                                 if (!in_array($tb_ping, $pinged)) {
    473                                  trackback($tb_ping, stripslashes($post_title), $excerpt, $post_ID);
    474                                 }
    475                         }
    476                 }
    477         } // end if publish
     425                do_trackbacks($post_ID);
     426                if ( get_option('default_pingback_flag') )
     427                        pingback($content, $post_ID);
     428        }
    478429
    479430        if ($post_status == 'static') {
    … …  
    500451
    501452        $post_id = intval($_GET['post']);
    502         $postdata = get_postdata($post_id) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'post.php'));
    503         $authordata = get_userdata($postdata['Author_ID']);
     453        $postdata = $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = '$post_id'") or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'post.php'));
     454        $authordata = get_userdata($postdata->post_author);
    504455
    505456        if ($user_level < $authordata->user_level)
    … …  
    515466
    516467    $meta = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $post_id");
    517 
    518         if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
    519                 sleep($sleep_after_edit);
    520         }
    521468
    522469        $sendback = $_SERVER['HTTP_REFERER'];
  • trunk/wp-includes/functions-post.php

    r1778 r1794  
    361361        $comment_author = strip_tags($comment_author);
    362362        $comment_author = htmlspecialchars($comment_author);
    363         $comment_author = $wpdb->escape($comment_author);
    364363
    365364        $comment_author_email = preg_replace('/[^a-z+_.@-]/i', '', $comment_author_email);
    … …  
    367366        $comment_author_url = strip_tags($comment_author_url);
    368367        $comment_author_url = htmlspecialchars($comment_author_url);
    369         $comment_author_url = $wpdb->escape($comment_author_url);
    370368
    371369        $comment_content = apply_filters('comment_content_presave', $comment_content);
    372         $comment_content = $wpdb->escape($comment_content);
    373370
    374371        $user_ip = addslashes($_SERVER['REMOTE_ADDR']);
    … …  
    407404}
    408405
     406function do_trackbacks($post_id) {
     407        global $wpdb;
     408
     409        $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $post_id");
     410        $to_ping = get_to_ping($post_id);
     411        $pinged  = get_pung($post_id);
     412        $content = strip_tags($post->post_content);
     413        $excerpt = strip_tags($post->post_excerpt);
     414        $post_title = strip_tags($post->post_title);
     415
     416        if ( $excerpt )
     417                $excerpt = substr($excerpt, 0, 252) . '...';
     418        else
     419                $excerpt = substr($content, 0, 252) . '...';
     420
     421        if ($to_ping) : foreach ($to_ping as $tb_ping) :
     422                $tb_ping = trim($tb_ping);
     423                if ( !in_array($tb_ping, $pinged) )
     424                 trackback($tb_ping, $post_title, $excerpt, $post_id);
     425        endforeach; endif;
     426}
     427
     428function get_pung($post_id) { // Get URIs already pung for a post
     429        global $wpdb;
     430        $pung = $wpdb->get_var("SELECT pinged FROM $wpdb->posts WHERE ID = $post_id");
     431        $pung = trim($pung);
     432        $pung = preg_split('/\s/', $pung);
     433        return $pung;
     434}
     435
     436function get_to_ping($post_id) { // Get any URIs in the todo list
     437        global $wpdb;
     438        $to_ping = $wpdb->get_var("SELECT to_ping FROM $wpdb->posts WHERE ID = $post_id");
     439        $to_ping = trim($to_ping);
     440        $to_ping = preg_split('/\s/', $to_ping);
     441        return $to_ping;
     442}
     443
     444function add_ping($post_id, $uri) { // Add a URI to those already pung
     445        global $wpdb;
     446        $pung = $wpdb->get_var("SELECT pinged FROM $wpdb->posts WHERE ID = $post_id");
     447        $pung = trim($pung);
     448        $pung = preg_split('/\s/', $pung);
     449        $pung[] = $uri;
     450        $new = implode("\n", $pung);
     451        return $wpdb->query("UPDATE $wpdb->posts SET pinged = '$new' WHERE ID = $post_id");
     452}
     453
    409454?>
  • trunk/wp-includes/functions.php

    r1792 r1794  
    735735
    736736function pingback($content, $post_ID) {
    737 
    738         global $wp_version;
     737        global $wp_version, $wpdb;
    739738        include_once (ABSPATH . WPINC . '/class-IXR.php');
    740739
    741740        // original code by Mort (http://mort.mine.nu:8080)
    742         $log = debug_fopen('./pingback.log', 'a');
     741        $log = debug_fopen(ABSPATH . '/pingback.log', 'a');
    743742        $post_links = array();
    744743        debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
     744
     745        $pung = get_pung($post_ID);
    745746
    746747        // Variables
    … …  
    748749        $gunk = '/#~:.?+=&%@!\-';
    749750        $punc = '.:?\-';
    750         $any = $ltrs.$gunk.$punc;
     751        $any = $ltrs . $gunk . $punc;
    751752
    752753        // Step 1
    … …  
    769770        // We don't wanna ping first and second types, even if they have a valid <link/>
    770771
    771         foreach($post_links_temp[0] as $link_test){
    772                 $test = parse_url($link_test);
    773                 if (isset($test['query'])) {
    774                         $post_links[] = $link_test;
    775                 } elseif(($test['path'] != '/') && ($test['path'] != '')) {
    776                         $post_links[] = $link_test;
    777                 }
    778         }
     772        foreach($post_links_temp[0] as $link_test) :
     773                if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
     774                        $test = parse_url($link_test);
     775                        if (isset($test['query']))
     776                                $post_links[] = $link_test;
     777                        elseif(($test['path'] != '/') && ($test['path'] != ''))
     778                                $post_links[] = $link_test;
     779                endif;
     780        endforeach;
    779781
    780782        foreach ($post_links as $pagelinkedto){
    781 
    782783                debug_fwrite($log, "Processing -- $pagelinkedto\n");
    783784                $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);
    784785
    785                 if($pingback_server_url) {
    786 
     786                if ($pingback_server_url) {
    787787                         // Now, the RPC call
    788                         $method = 'pingback.ping';
    789                         debug_fwrite($log, 'Page Linked To: '.$pagelinkedto."\n");
     788                        debug_fwrite($log, "Page Linked To: $pagelinkedto \n");
    790789                        debug_fwrite($log, 'Page Linked From: ');
    791790                        $pagelinkedfrom = get_permalink($post_ID);
    … …  
    795794                        $client = new IXR_Client($pingback_server_url);
    796795                        $client->timeout = 3;
    797                         $client->useragent .= ' -- WordPress/'.$wp_version;
     796                        $client->useragent .= ' -- WordPress/' . $wp_version;
    798797
    799798                        // when set to true, this outputs debug messages by itself
    800799                        $client->debug = false;
    801800                        $client->query('pingback.ping', array($pagelinkedfrom, $pagelinkedto));
    802 
    803                         if (!$client->query('pingback.ping', array($pagelinkedfrom, $pagelinkedto))) {
     801                       
     802                        if ( !$client->query('pingback.ping', array($pagelinkedfrom, $pagelinkedto) ) )
    804803                                debug_fwrite($log, "Error.\n Fault code: ".$client->getErrorCode()." : ".$client->getErrorMessage()."\n");
    805                         }
    806                 }
    807         }
    808 
    809         debug_fwrite($log, "\nEND: ".time()."\n****************************\n\r");
     804                        else
     805                                add_ping( $post_ID, $pagelinkedto );
     806                }
     807        }
     808
     809        debug_fwrite($log, "\nEND: ".time()."\n****************************\n");
    810810        debug_fclose($log);
    811811}
    … …  
    16081608
    16091609    // Get post-meta info
    1610     if ( $meta_list = $wpdb->get_results("
    1611                         SELECT post_id,meta_key,meta_value
    1612                         FROM $wpdb->postmeta
    1613                         WHERE post_id IN($post_id_list)
    1614                         ORDER BY post_id,meta_key
    1615                 ", ARRAY_A) ) {
     1610    if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta  WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) {
    16161611               
    16171612        // Change from flat structure to hierarchical:
  • trunk/wp-settings.php

    r1773 r1794  
    5050require (ABSPATH . WPINC . '/functions.php');
    5151require (ABSPATH . WPINC . '/functions-formatting.php');
     52require (ABSPATH . WPINC . '/functions-post.php');
    5253require (ABSPATH . WPINC . '/classes.php');
    5354require (ABSPATH . WPINC . '/template-functions.php');
  • trunk/wp-trackback.php

    r1734 r1794  
    11<?php
     2
     3function add_magic_quotes($array) {
     4        foreach ($array as $k => $v) {
     5                if (is_array($v)) {
     6                        $array[$k] = add_magic_quotes($v);
     7                } else {
     8                        $array[$k] = addslashes($v);
     9                }
     10        }
     11        return $array;
     12}
     13
     14if (!get_magic_quotes_gpc()) {
     15        $_GET    = add_magic_quotes($_GET);
     16        $_POST   = add_magic_quotes($_POST);
     17        $_COOKIE = add_magic_quotes($_COOKIE);
     18}
    219
    320if ( !$doing_trackback) {
    … …  
    522    require('wp-blog-header.php');
    623}
    7 
    8 include_once (ABSPATH . WPINC . '/functions-post.php');
    924
    1025function trackback_response($error = 0, $error_message = '') {
  • trunk/xmlrpc.php

    r1777 r1794  
    66include('./wp-config.php');
    77include_once(ABSPATH . WPINC . '/class-IXR.php');
    8 include_once(ABSPATH . WPINC . '/functions-post.php');
    98
    109// Turn off all warnings and errors.
Note: See TracChangeset for help on using the changeset viewer.