Projects : mp-wp : mp-wp_svg-screenshots-and-errorreporting-r2

mp-wp/wp-admin/includes/comment.php

Dir - Raw

1<?php
2/**
3 * WordPress Comment Administration API.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/**
10 * {@internal Missing Short Description}}
11 *
12 * @since unknown
13 * @uses $wpdb
14 *
15 * @param string $comment_author
16 * @param string $comment_date
17 * @return mixed Comment ID on success.
18 */
19function comment_exists($comment_author, $comment_date) {
20 global $wpdb;
21
22 return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments
23 WHERE comment_author = %s AND comment_date = %s", $comment_author, $comment_date) );
24}
25
26/**
27 * {@internal Missing Short Description}}
28 *
29 * @since unknown
30 */
31function edit_comment() {
32
33 $comment_post_ID = (int) $_POST['comment_post_ID'];
34
35 if (!current_user_can( 'edit_post', $comment_post_ID ))
36 wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
37
38 $_POST['comment_author'] = $_POST['newcomment_author'];
39 $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
40 $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
41 $_POST['comment_approved'] = $_POST['comment_status'];
42 $_POST['comment_content'] = $_POST['content'];
43 $_POST['comment_ID'] = (int) $_POST['comment_ID'];
44
45 foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
46 if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
47 $_POST['edit_date'] = '1';
48 break;
49 }
50 }
51
52 if (!empty ( $_POST['edit_date'] ) ) {
53 $aa = $_POST['aa'];
54 $mm = $_POST['mm'];
55 $jj = $_POST['jj'];
56 $hh = $_POST['hh'];
57 $mn = $_POST['mn'];
58 $ss = $_POST['ss'];
59 $jj = ($jj > 31 ) ? 31 : $jj;
60 $hh = ($hh > 23 ) ? $hh -24 : $hh;
61 $mn = ($mn > 59 ) ? $mn -60 : $mn;
62 $ss = ($ss > 59 ) ? $ss -60 : $ss;
63 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
64 }
65
66 wp_update_comment( $_POST);
67}
68
69/**
70 * {@internal Missing Short Description}}
71 *
72 * @since unknown
73 *
74 * @param unknown_type $id
75 * @return unknown
76 */
77function get_comment_to_edit( $id ) {
78 if ( !$comment = get_comment($id) )
79 return false;
80
81 $comment->comment_ID = (int) $comment->comment_ID;
82 $comment->comment_post_ID = (int) $comment->comment_post_ID;
83
84 $comment->comment_content = format_to_edit( $comment->comment_content );
85 $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
86
87 $comment->comment_author = format_to_edit( $comment->comment_author );
88 $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
89 $comment->comment_author_url = clean_url($comment->comment_author_url);
90 $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
91
92 return $comment;
93}
94
95/**
96 * {@internal Missing Short Description}}
97 *
98 * @since unknown
99 * @uses $wpdb
100 *
101 * @param int $post_id Post ID
102 * @return unknown
103 */
104function get_pending_comments_num( $post_id ) {
105 global $wpdb;
106
107 $single = false;
108 if ( !is_array($post_id) ) {
109 $post_id = (array) $post_id;
110 $single = true;
111 }
112 $post_id = array_map('intval', $post_id);
113 $post_id = "'" . implode("', '", $post_id) . "'";
114
115 $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_N );
116
117 if ( empty($pending) )
118 return 0;
119
120 if ( $single )
121 return $pending[0][1];
122
123 $pending_keyed = array();
124 foreach ( $pending as $pend )
125 $pending_keyed[$pend[0]] = $pend[1];
126
127 return $pending_keyed;
128}
129
130/**
131 * Add avatars to relevant places in admin, or try to.
132 *
133 * @since unknown
134 * @uses $comment
135 *
136 * @param string $name User name.
137 * @return string Avatar with Admin name.
138 */
139function floated_admin_avatar( $name ) {
140 global $comment;
141
142 $id = $avatar = false;
143 if ( $comment->comment_author_email )
144 $id = $comment->comment_author_email;
145 if ( $comment->user_id )
146 $id = $comment->user_id;
147
148 if ( $id )
149 $avatar = get_avatar( $id, 32 );
150
151 return "$avatar $name";
152}
153
154function enqueue_comment_hotkeys_js() {
155 if ( 'true' == get_user_option( 'comment_shortcuts' ) )
156 wp_enqueue_script( 'jquery-table-hotkeys' );
157}
158
159if ( is_admin() && ('edit-comments.php' == $pagenow || 'edit.php' == $pagenow) ) {
160 if ( get_option('show_avatars') )
161 add_filter( 'comment_author', 'floated_admin_avatar' );
162}
163
164?>