]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/comment.php
Wordpress 2.3.2-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / comment.php
1 <?php
2
3 function comment_exists($comment_author, $comment_date) {
4         global $wpdb;
5
6         return $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments
7                         WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'");
8 }
9
10 function edit_comment() {
11         global $user_ID;
12
13         $comment_ID = (int) $_POST['comment_ID'];
14         $comment_post_ID = (int) $_POST['comment_post_ID'];
15
16         if (!current_user_can( 'edit_post', $comment_post_ID ))
17                 wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
18
19         $_POST['comment_author'] = $_POST['newcomment_author'];
20         $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
21         $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
22         $_POST['comment_approved'] = $_POST['comment_status'];
23         $_POST['comment_content'] = $_POST['content'];
24         $_POST['comment_ID'] = (int) $_POST['comment_ID'];
25
26         if (!empty ( $_POST['edit_date'] ) ) {
27                 $aa = $_POST['aa'];
28                 $mm = $_POST['mm'];
29                 $jj = $_POST['jj'];
30                 $hh = $_POST['hh'];
31                 $mn = $_POST['mn'];
32                 $ss = $_POST['ss'];
33                 $jj = ($jj > 31 ) ? 31 : $jj;
34                 $hh = ($hh > 23 ) ? $hh -24 : $hh;
35                 $mn = ($mn > 59 ) ? $mn -60 : $mn;
36                 $ss = ($ss > 59 ) ? $ss -60 : $ss;
37                 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
38         }
39
40         wp_update_comment( $_POST);
41 }
42
43 function get_comment_to_edit( $id ) {
44         if ( !$comment = get_comment($id) )
45                 return false;
46
47         $comment->comment_ID = (int) $comment->comment_ID;
48         $comment->comment_post_ID = (int) $comment->comment_post_ID;
49
50         $comment->comment_content = format_to_edit( $comment->comment_content );
51         $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
52
53         $comment->comment_author = format_to_edit( $comment->comment_author );
54         $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
55         $comment->comment_author_url = clean_url($comment->comment_author_url);
56         $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
57
58         return $comment;
59 }
60
61 function get_pending_comments_num( $post_id ) {
62         global $wpdb;
63         $post_id = (int) $post_id;
64         $pending = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '0'" );
65         return $pending;
66 }
67
68 ?>