home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / includes / comment.php < prev    next >
Encoding:
PHP Script  |  2008-04-23  |  3.3 KB  |  116 lines

  1. <?php
  2.  
  3. function comment_exists($comment_author, $comment_date) {
  4.     global $wpdb;
  5.  
  6.     return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments
  7.             WHERE comment_author = %s AND comment_date = %s", $comment_author, $comment_date) );
  8. }
  9.  
  10. function edit_comment() {
  11.  
  12.     $comment_post_ID = (int) $_POST['comment_post_ID'];
  13.  
  14.     if (!current_user_can( 'edit_post', $comment_post_ID ))
  15.         wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
  16.  
  17.     $_POST['comment_author'] = $_POST['newcomment_author'];
  18.     $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
  19.     $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
  20.     $_POST['comment_approved'] = $_POST['comment_status'];
  21.     $_POST['comment_content'] = $_POST['content'];
  22.     $_POST['comment_ID'] = (int) $_POST['comment_ID'];
  23.  
  24.     foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
  25.         if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
  26.             $_POST['edit_date'] = '1';
  27.             break;
  28.         }
  29.     }
  30.  
  31.  
  32.     if (!empty ( $_POST['edit_date'] ) ) {
  33.         $aa = $_POST['aa'];
  34.         $mm = $_POST['mm'];
  35.         $jj = $_POST['jj'];
  36.         $hh = $_POST['hh'];
  37.         $mn = $_POST['mn'];
  38.         $ss = $_POST['ss'];
  39.         $jj = ($jj > 31 ) ? 31 : $jj;
  40.         $hh = ($hh > 23 ) ? $hh -24 : $hh;
  41.         $mn = ($mn > 59 ) ? $mn -60 : $mn;
  42.         $ss = ($ss > 59 ) ? $ss -60 : $ss;
  43.         $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
  44.     }
  45.  
  46.     wp_update_comment( $_POST);
  47. }
  48.  
  49. function get_comment_to_edit( $id ) {
  50.     if ( !$comment = get_comment($id) )
  51.         return false;
  52.  
  53.     $comment->comment_ID = (int) $comment->comment_ID;
  54.     $comment->comment_post_ID = (int) $comment->comment_post_ID;
  55.  
  56.     $comment->comment_content = format_to_edit( $comment->comment_content );
  57.     $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
  58.  
  59.     $comment->comment_author = format_to_edit( $comment->comment_author );
  60.     $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
  61.     $comment->comment_author_url = clean_url($comment->comment_author_url);
  62.     $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
  63.  
  64.     return $comment;
  65. }
  66.  
  67. function get_pending_comments_num( $post_id ) {
  68.     global $wpdb;
  69.  
  70.     $single = false;
  71.     if ( !is_array($post_id) ) {
  72.         $post_id = (array) $post_id;
  73.         $single = true;
  74.     }
  75.     $post_id = array_map('intval', $post_id);
  76.     $post_id = "'" . implode("', '", $post_id) . "'";
  77.  
  78.     $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 );
  79.  
  80.     if ( empty($pending) )
  81.         return 0;
  82.  
  83.     if ( $single )
  84.         return $pending[0][1];
  85.  
  86.     $pending_keyed = array();
  87.     foreach ( $pending as $pend )
  88.         $pending_keyed[$pend[0]] = $pend[1];
  89.  
  90.     return $pending_keyed;
  91. }
  92.  
  93. // Add avatars to relevant places in admin, or try to
  94.  
  95. function floated_admin_avatar( $name ) {
  96.     global $comment;
  97.  
  98.     $id = $avatar = false;
  99.     if ( $comment->comment_author_email )
  100.         $id = $comment->comment_author_email;
  101.     if ( $comment->user_id )
  102.         $id = $comment->user_id;
  103.  
  104.     if ( $id )
  105.         $avatar = get_avatar( $id, 32 );
  106.  
  107.     return "$avatar $name";
  108. }
  109.  
  110. if ( is_admin() && ('edit-comments.php' == $pagenow || 'edit.php' == $pagenow) ) {
  111.     if ( get_option('show_avatars') )
  112.         add_filter( 'comment_author', 'floated_admin_avatar' );
  113. }
  114.  
  115. ?>
  116.