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