Make WordPress Core


Ignore:
Timestamp:
06/26/2005 07:55:12 PM (21 years ago)
Author:
ryan
Message:

Comment updating cleanup. Add get_comment(), edit_comment(), get_comment_to_edit(), and wp_update_comment().

File:
1 edited

Legend:

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

    r2654 r2662  
    141141        get_currentuserinfo();
    142142
    143         $comment = $_GET['comment'];
    144         $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
    145 
    146         if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
     143        $comment = (int) $_GET['comment'];
     144
     145        if ( ! $comment = get_comment($comment) )
     146                die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
     147
     148        if ( !user_can_edit_post_comments($user_ID, $comment->comment_post_ID) )
    147149                die( __('You are not allowed to edit comments on this post.') );
    148         }
    149 
    150         $content = $commentdata['comment_content'];
    151         $content = format_to_edit($content);
    152         $content = apply_filters('comment_edit_pre', $content);
    153        
    154         $comment_status = $commentdata['comment_approved'];
     150
     151        $comment = get_comment_to_edit($comment);
    155152
    156153        include('edit-form-comment.php');
    … …  
    162159        require_once('./admin-header.php');
    163160
    164         $comment = $_GET['comment'];
     161        $comment = (int) $_GET['comment'];
    165162        $p = (int) $_GET['p'];
    166         $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
    167 
    168         if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
     163
     164        if ( ! $comment = get_comment($comment) )
     165                die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
     166
     167        if ( !user_can_delete_post_comments($user_ID, $comment->comment_post_ID) )
    169168                die( __('You are not allowed to delete comments on this post.') );
    170         }
    171169
    172170        echo "<div class=\"wrap\">\n";
    173171        echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
    174172        echo "<table border=\"0\">\n";
    175         echo "<tr><td>" . __('Author:') . "</td><td>" . $commentdata["comment_author"] . "</td></tr>\n";
    176         echo "<tr><td>" . __('E-mail:') . "</td><td>" . $commentdata["comment_author_email"] . "</td></tr>\n";
    177         echo "<tr><td>". __('URL:') . "</td><td>" . $commentdata["comment_author_url"] . "</td></tr>\n";
    178         echo "<tr><td>". __('Comment:') . "</td><td>" . stripslashes($commentdata["comment_content"]) . "</td></tr>\n";
     173        echo "<tr><td>" . __('Author:') . "</td><td>" . $comment->comment_author . "</td></tr>\n";
     174        echo "<tr><td>" . __('E-mail:') . "</td><td>" . $comment->comment_author_email . "</td></tr>\n";
     175        echo "<tr><td>". __('URL:') . "</td><td>" . $comment->comment_author_url . "</td></tr>\n";
     176        echo "<tr><td>". __('Comment:') . "</td><td>" . $comment->comment_content . "</td></tr>\n";
    179177        echo "</table>\n";
    180178        echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
    … …  
    197195        check_admin_referer();
    198196
    199         $comment = $_GET['comment'];
    200         $p = $_GET['p'];
     197        $comment = (int) $_GET['comment'];
     198        $p = (int) $_GET['p'];
    201199        if (isset($_GET['noredir'])) {
    202200                $noredir = true;
    … …  
    206204
    207205        $postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
    208         $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
    209 
    210         if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
     206
     207        if ( ! $comment = get_comment($comment) )
     208                         die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
     209
     210        if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID']))
    211211                die( __('You are not allowed to edit comments on this post.') );
    212         }
    213 
    214         wp_set_comment_status($comment, "delete");
    215         do_action('delete_comment', $comment);
     212
     213        wp_set_comment_status($comment->comment_ID, "delete");
     214        do_action('delete_comment', $comment->comment_ID);
    216215
    217216        if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
    … …  
    229228        check_admin_referer();
    230229
    231         $comment = $_GET['comment'];
    232         $p = $_GET['p'];
     230        $comment = (int) $_GET['comment'];
     231        $p = (int) $_GET['p'];
    233232        if (isset($_GET['noredir'])) {
    234233                $noredir = true;
    … …  
    237236        }
    238237
    239         $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
    240 
    241         if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
     238        if ( ! $comment = get_comment($comment) )
     239                die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
     240
     241        if ( !user_can_edit_post_comments($user_ID, $comment->comment_post_ID) )
    242242                die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
    243         }
    244 
    245         wp_set_comment_status($comment, "hold");
     243
     244        wp_set_comment_status($comment->comment_ID, "hold");
    246245
    247246        if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
    … …  
    257256        $comment = (int) $_GET['comment'];
    258257
    259         $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
    260 
    261         if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
     258        if ( ! $comment = get_comment($comment) )
     259                         die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
     260
     261        if ( !user_can_edit_post_comments($user_ID, $comment->comment_post_ID) )
    262262                die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
    263         }
    264 
    265         if ('1' != $commentdata['comment_approved']) {
    266                 wp_set_comment_status($comment, 'approve');
     263
     264        if ('1' != $comment->comment_approved) {
     265                wp_set_comment_status($comment->comment_ID, 'approve');
    267266                if (true == get_option('comments_notify'))
    268                         wp_notify_postauthor($comment);
     267                        wp_notify_postauthor($comment->comment_ID);
    269268        }
    270269
    … …  
    275274case 'approvecomment':
    276275
    277         $comment = $_GET['comment'];
    278         $p = $_GET['p'];
     276        $comment = (int) $_GET['comment'];
     277        $p = (int) $_GET['p'];
    279278        if (isset($_GET['noredir'])) {
    280279                $noredir = true;
    … …  
    282281                $noredir = false;
    283282        }
    284         $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
    285 
    286         if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
     283
     284        if ( ! $comment = get_comment($comment) )
     285                die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
     286
     287        if ( !user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID']))
    287288                die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
    288         }
    289 
    290         wp_set_comment_status($comment, "approve");
     289
     290        wp_set_comment_status($comment->comment_ID, "approve");
    291291        if (get_settings("comments_notify") == true) {
    292                 wp_notify_postauthor($comment);
     292                wp_notify_postauthor($comment->comment_ID);
    293293        }
    294294
    … …  
    304304case 'editedcomment':
    305305
    306         $comment_ID = $_POST['comment_ID'];
    307         $comment_post_ID = $_POST['comment_post_ID'];
    308         $newcomment_author = $_POST['newcomment_author'];
    309         $newcomment_author_email = $_POST['newcomment_author_email'];
    310         $newcomment_author_url = $_POST['newcomment_author_url'];
    311         $comment_status = $_POST['comment_status'];
    312 
    313         if (!user_can_edit_post_comments($user_ID, $comment_post_ID)) {
    314                 die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
    315         }
    316 
    317         if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
    318                 $aa = $_POST['aa'];
    319                 $mm = $_POST['mm'];
    320                 $jj = $_POST['jj'];
    321                 $hh = $_POST['hh'];
    322                 $mn = $_POST['mn'];
    323                 $ss = $_POST['ss'];
    324                 $jj = ($jj > 31) ? 31 : $jj;
    325                 $hh = ($hh > 23) ? $hh - 24 : $hh;
    326                 $mn = ($mn > 59) ? $mn - 60 : $mn;
    327                 $ss = ($ss > 59) ? $ss - 60 : $ss;
    328                 $datemodif = ", comment_date = '$aa-$mm-$jj $hh:$mn:$ss'";
    329         } else {
    330                 $datemodif = '';
    331         }
    332         $content = apply_filters('comment_save_pre', $_POST['content']);
    333 
    334         $result = $wpdb->query("
    335                 UPDATE $wpdb->comments SET
    336                         comment_content = '$content',
    337                         comment_author = '$newcomment_author',
    338                         comment_author_email = '$newcomment_author_email',
    339                         comment_approved = '$comment_status',
    340                         comment_author_url = '$newcomment_author_url'".$datemodif."
    341                 WHERE comment_ID = $comment_ID"
    342                 );
     306        edit_comment();
    343307
    344308        $referredby = $_POST['referredby'];
    … …  
    348312                header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
    349313        }
    350         do_action('edit_comment', $comment_ID);
     314
    351315        break;
    352316
Note: See TracChangeset for help on using the changeset viewer.