source: trunk/www.guidonia.net/wp/wp-admin/includes/comment.php@ 44

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