Changeset 46113

Show
Ignore:
Timestamp:
05/16/08 02:08:05 (2 months ago)
Author:
ronalfy
Message:

Moved edit links to just one line.
Fixed style bugs for IE7 and below.
Fixed numerous bugs for logged in users.
Fixed gravatar bug where changing the e-mail address didn't update the gravatar.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wp-ajax-edit-comments/trunk/2.0/wp-ajax-edit-comments/css/edit-comments.css

    r44479 r46113  
    88      padding: 2px 0px; 
    99      padding-left: 20px; 
     10      float: left; 
     11      margin-right: 10px; 
     12      /*todo - clear:after? */ 
     13} 
     14.clearfix:after { /* from http://blue-anvil.com/archives/experiments-with-floats-whats-the-best-method-of-clearance*/ 
     15    content: "."; 
     16    display: block; 
     17    height: 0; 
     18    clear: both; 
     19    visibility: hidden; 
    1020} 
    1121/* Begin Images */ 
     
    3747 
    3848} 
    39 .editableAuthor, .editableComment{ 
    40  color: #000; 
    41  background-color: #ffffd3; 
    42  } 
    43 .editAuthor { background-color: transparent; background-image: none; display: inline; margin: 0; padding: 0; border: 0; clear: none;} 
    44 /* Edit me for the textarea shown when editing a comment */ 
    45 .textComment textarea { width: 90%; height: 100px; } 
    46 /* Edit me for the div that contains the comment */ 
    47 .editComment, .editableComment, .textComment{ /*clear: both;*/ } 
    48 /* various CSS classes you can edit if you really want to 
    49 .ajaxSaveButtons { } 
    50 .textAuthor { } 
    51 .ajaxApproveLinks{} 
    52 span.ajax-admin-edit-links {} 
    53 */ 
    54  
    55 /*Edit me for the message that shows up to a user(non admin) when leaving a comment */ 
    56 .ajax-edit { font-size: 1em; font-style: italic; background-color: #333; color: #fff; padding: 5px; font-weight: bold;} 
    57 .ajax-edit .ajax-timer { font-size: 0.8em; color: #FFCC66; } 
    58 input.ajax-error { border: 3px solid #966; } 
    59 textarea.ajax-error, li.ajax-error { background: #966; } 
  • wp-ajax-edit-comments/trunk/2.0/wp-ajax-edit-comments/js/comment-editor.js.php

    r45538 r46113  
    156156                url = this.data; 
    157157                break; 
     158              case "gravatar": 
     159                  $j("#gravatar").html(this.data).show(); 
     160                  break; 
    158161            } 
    159162          } 
  • wp-ajax-edit-comments/trunk/2.0/wp-ajax-edit-comments/js/wp-ajax-edit-comments.js.php

    r45725 r46113  
    5151      $j(".edit-comment-admin-links").attr("style", "display: inherit"); 
    5252    $j(".edit-comment-user-link").attr("style", "display: inherit"); 
     53    /* For Crappy IE */ 
     54    $j(".edit-comment-admin-links").show(); 
     55    $j(".edit-comment-user-link").show(); 
    5356    $j(".ajax-admin-edit-links").each(function() {  
    5457      var element = $j(this); 
     
    8285      data.action = 'gettimeleft'; 
    8386      data.success = function(r) { 
     87            if (r == "-1") { 
     88            minutes = 0; 
     89          seconds = 0; 
     90        } else if (r == "1") { 
     91            return; 
     92        } 
    8493            var res = wpAjax.parseAjaxResponse(r, data.response,data.element); 
    8594        jQuery.each( res.responses, function() { 
     95            //todo - check for errors 
    8696            if (this.what == "minutes") { 
    8797            minutes = parseInt(this.data); 
     
    110120    element = timer.element; 
    111121    //Check to see if the time has run out 
    112             if (minutes <=0 && seconds <= 0) {  
     122            if (minutes ==0 && seconds == 0) {  
    113123                  $j("#edit" + timer.cid).unbind(); 
    114124      element.remove(); 
     
    117127      clearTimeout(timers[timer.cid]); 
    118128                  return; 
    119             } 
     129            }  
    120130            if (seconds < 0) { minutes -= 1; seconds = 59; } 
    121131    //Create timer text 
  • wp-ajax-edit-comments/trunk/2.0/wp-ajax-edit-comments/php/AjaxEditComments.php

    r45725 r46113  
    2727            if ($WPrapAjaxEditComments->can_edit_url($commentID, $postID)) { 
    2828                  $comment['comment_author_url'] = trim(strip_tags(urldecode($_POST['comment_author_url']))); 
     29            //Quick JS Test 
     30            if ($comment['comment_author_url'] == "undefined") {$comment['comment_author_url']='http://';} 
    2931            } 
    3032            $WPrapAjaxEditComments->save_comment($commentID, $postID, $comment); 
  • wp-ajax-edit-comments/trunk/2.0/wp-ajax-edit-comments/wp-ajax-edit-comments.php

    r45728 r46113  
    9898                  if (!$this->is_comment_owner($comment->comment_post_ID)) { 
    9999                        //For anonymous users 
    100                         $content .= "<div class='edit-comment-user-link' id='edit-comment-user-link-$comment->comment_ID'>"; 
     100                        $content .= "<div class='edit-comment-user-link clearfix' id='edit-comment-user-link-$comment->comment_ID'>"; 
    101101                        $content .= "<div class='edit-comment'><a title='Ajax Edit Comments' class='ajax-admin-edit-links thickbox' href='$edit_url' id='edit-$comment->comment_ID'>"; 
    102102                        $content .= $this->adminOptions['edit_text']; 
     
    104104                        //Check to see if timer is on 
    105105                        if ($this->adminOptions['show_timer'] == 'true') { 
    106                               $content .= " <span class='ajax-edit-time-left' id='ajax-edit-time-left-$comment->comment_ID'></span>"; 
     106                              //Check to see if user is logged in and admin can indefinitely edit 
     107                              if (!$this->can_indefinitely_edit($comment->user_id)) { 
     108                                    $content .= " <span class='ajax-edit-time-left' id='ajax-edit-time-left-$comment->comment_ID'></span>"; 
     109                              } 
    107110                        } 
    108111                        $content .= "</div></div>"; 
    109112                  } else { 
    110                         $content .= '<div class="' . $this->commentClassName . '-admin-links" id="' . $this->commentClassName . '-admin-links' . $comment->comment_ID . '">'; 
     113                        $content .= '<div class="' . $this->commentClassName . '-admin-links clearfix" id="' . $this->commentClassName . '-admin-links' . $comment->comment_ID . '">'; 
    111114                        //Spans are used here instead of LIs because of style conflicts in the admin panel 
    112115                        $content .= "<span class='edit-comment'><a title='Ajax Edit Comments' class='ajax-admin-edit-links thickbox' href='$edit_url' id='edit-$comment->comment_ID'>"; 
     
    171174                  } 
    172175                  //Get the current comment 
    173                   $query = "SELECT UNIX_TIMESTAMP(comment_date) time, comment_author_email, comment_author_IP, comment_date_gmt, comment_post_ID, comment_ID  FROM $wpdb->comments where comment_ID = $commentID"; 
     176                  $query = "SELECT UNIX_TIMESTAMP(comment_date) time, comment_author_email, comment_author_IP, comment_date_gmt, comment_post_ID, comment_ID, user_id  FROM $wpdb->comments where comment_ID = $commentID"; 
    174177                  $comment = $wpdb->get_row($query, ARRAY_A);  
    175178                  if (!$comment) { return 'get_comment_failed'; } 
     
    178181                        return 'comment_spam'; 
    179182                  } 
    180                   //Check to see if the user is logged in 
    181                   if ($this->is_logged_in($comment['comment_author_email'])) { 
    182                         //User is logged in and this is the user's comment - Does admin allow indefinite editing? 
    183                         if ($this->adminOptions['registered_users_edit'] == "true") { 
    184                               return 1; //Logged in user can indefinitely edit 
    185                         } 
     183                   
     184                  //Check to see if the user is logged in and can indefinitely edit 
     185                  if ($this->can_indefinitely_edit($comment['user_id'])) { 
     186                  return 1; 
    186187                  } 
    187188                  //Now check if options allow editing after an additional comment has been made 
     
    232233                  if ($this->is_comment_owner($postID)) { return true; } 
    233234                  $comment = get_comment($commentID, ARRAY_A); 
    234                   if ($this->is_logged_in($comment['comment_author_email'])) { //logged in 
     235                  if ($this->is_logged_in($comment['user_id'])) { //logged in 
    235236                        if ($this->adminOptions['registered_users_name_edit'] == "true") { return true;} 
    236237                  } else { //not logged in  
     
    245246                  if ($this->is_comment_owner($postID)) { return true; } 
    246247                  $comment = get_comment($commentID, ARRAY_A); 
    247                   if ($this->is_logged_in($comment['comment_author_email'])) { //logged in 
     248                  if ($this->is_logged_in($comment['user_id'])) { //logged in 
    248249                        if ($this->adminOptions['registered_users_email_edit'] == "true") { return true;} 
    249250                  } else { //not logged in  
     
    258259                  if ($this->is_comment_owner($postID)) { return true; } 
    259260                  $comment = get_comment($commentID, ARRAY_A); 
    260                   if ($this->is_logged_in($comment['comment_author_email'])) { //logged in 
     261                  if ($this->is_logged_in($comment['user_id'])) { //logged in 
    261262                        if ($this->adminOptions['registered_users_url_edit'] == "true") { return true;} 
    262263                  } else { //not logged in  
     
    271272                  if ($this->is_comment_owner($postID)) { return true; } 
    272273                  $comment = get_comment($commentID, ARRAY_A); 
    273                   if ($this->is_logged_in($comment['comment_author_email'])) { //logged in 
     274                  if ($this->is_logged_in($comment['user_id'])) { //logged in 
    274275                        if ($this->adminOptions['registered_users_url_edit'] == "true" || $this->adminOptions['registered_users_email_edit'] == "true" || $this->adminOptions['registered_users_name_edit'] == "true" ) { return true;} 
    275276                  } else { //not logged in  
    276277                        if ($this->adminOptions['allow_url_editing'] == "true" || $this->adminOptions['allow_email_editing'] == "true" || $this->adminOptions['allow_name_editing'] == "true") { return true;} 
     278                  } 
     279                  return false; 
     280            } 
     281            /* can_indefinitely_edit 
     282            Parameters - $userID 
     283            Returns - true if can, false if not */ 
     284            function can_indefinitely_edit($userID = 0) { 
     285                  if ($this->is_logged_in($userID)) { 
     286                        //User is logged in and this is the user's comment - Does admin allow indefinite editing? 
     287                        if ($this->adminOptions['registered_users_edit'] == "true") { 
     288                              return true; //Logged in user can indefinitely edit 
     289                        } 
    277290                  } 
    278291                  return false; 
     
    340353                        return $commentID; 
    341354                  } 
    342                   //Check to see if admin allows comment editing 
     355                  //Don't save data if user can indefinitely edit 
     356                  if ($this->can_indefinitely_edit($comment['user_id'])) { return $commentID; } 
     357                  //Check to see if admin allows comment editing  
    343358                  if ($this->adminOptions['allow_editing'] == "false") { return $commentID;} 
    344359                   
     
    521536            } 
    522537            /* get_time_left - Returns time remaining in seconds 
    523             parameters - $commentID */ 
     538            parameters - $commentID  
     539            Returns 1 if no time is necessary.  -1 if time is unavailable.  Time if available. 
     540            */ 
    524541            function get_time_left($commentID = 0) { 
    525542                  global $wpdb; 
    526543                  $adminMinutes = (int)$this->adminOptions['minutes']; 
    527                   $query = "SELECT ($adminMinutes * 60 - (UNIX_TIMESTAMP('" . current_time('mysql') . "') - UNIX_TIMESTAMP(comment_date))) time FROM $wpdb->comments where comment_ID = $commentID"; 
     544                  $query = "SELECT ($adminMinutes * 60 - (UNIX_TIMESTAMP('" . current_time('mysql') . "') - UNIX_TIMESTAMP(comment_date))) time, comment_author_email, user_id FROM $wpdb->comments where comment_ID = $commentID"; 
     545                   
    528546                  //Get the Timestamp 
    529547                  $comment = $wpdb->get_row($query, ARRAY_A); 
    530                   if (!$comment) { return "0"; } 
     548                  if (!$comment) { return "-1"; } 
     549                  if ($this->can_indefinitely_edit($comment['user_id'])) {     
     550                  return "1"; 
     551                  } 
    531552                  //Get the time elapsed since making the comment 
    532                   if ($comment['time'] <= 0) { return "0"; } 
     553                  if ((int)$comment['time'] <= 0) { return "-1"; } 
    533554                  $timeleft = (int)$comment['time']; 
    534555                  $minutes = floor($timeleft/60); 
     
    607628            Parameters - $email 
    608629            Returns true if logged in, false if not */ 
    609             function is_logged_in($email = '') { 
    610                   if ($this->get_user_email() == $email) { 
     630            function is_logged_in($userID = 0) { 
     631                  if ($this->get_user_id() == $userID) { 
    611632                        return true; 
    612633                  } else {  
     
    693714                  //Condition the data for returning 
    694715                  do_action('wp_ajax_comments_remove_content_filter'); 
     716                  //todo some char issues with quotes 
    695717                  $response->add( array( 
    696718                              'what' => 'comment_content', 
    697719                              'id' => $commentID, 
    698                               'data' => apply_filters('comment_text',apply_filters('get_comment_text',$this->encode($commentarr['comment_content']))) 
     720                              'data' => stripslashes(apply_filters('comment_text',apply_filters('get_comment_text',$this->encode($commentarr['comment_content'])))) 
    699721                  )); 
    700722                  $response->add( array( 
    701723                              'what' => 'comment_author', 
    702724                              'id' => $commentID, 
    703                               'data' => apply_filters('comment_author', apply_filters('get_comment_author', $this->encode($commentarr['comment_author']))) 
     725                              'data' => stripslashes(apply_filters('comment_author', apply_filters('get_comment_author', $this->encode($commentarr['comment_author'])))) 
    704726                  )); 
    705                   //Quick JavaScript test 
    706727                  $response->add( array( 
    707728                              'what' => 'comment_author_url', 
    708729                              'id' => $commentID, 
    709                               'data' => apply_filters('comment_url', apply_filters('get_comment_author_url', $commentarr['comment_author_url'])) 
     730                              'data' => stripslashes(apply_filters('comment_url', apply_filters('get_comment_author_url', $commentarr['comment_author_url']))) 
     731                  )); 
     732                  $response->add( array( 
     733                              'what' => 'gravatar', 
     734                              'id' => $commentID, 
     735                              'data' => get_avatar($commentarr['comment_author_email'], '40') 
    710736                  )); 
    711737                  $response->send(); 
     
    810836                  return $user_email; 
    811837            } 
     838            // Returns a logged-in user's ID 
     839            function get_user_id() { 
     840                  global $user_ID; 
     841                  if (!function_exists("get_currentuserinfo")) { return "-1"; } 
     842                  if (empty($user_ID)) {get_currentuserinfo();} //try to get user info 
     843                  if (empty($user_ID)) { return '-1'; } //Can't get user info, so return empty string 
     844                  return $user_ID; 
     845            } 
    812846             
    813847            //Returns an array of an individual's options 
     
    857891                        echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/wp-ajax-edit-comments/css/edit-comments.css" type="text/css" media="screen"  />';  
    858892                        echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'//wp-includes/js/thickbox/thickbox.css" type="text/css" media="all"  />';  
     893                        /* From http://blue-anvil.com/archives/experiments-with-floats-whats-the-best-method-of-clearance */ 
     894?> 
     895<!-- Ajax Edit Comments --> 
     896<!--[if IE]> 
     897<style> 
     898  .clearfix {display: inline-block;} 
     899  /* Hides from IE-mac \*/ 
     900  * html .clearfix {height: 1%;} 
     901  .clearfix {display: block;} 
     902  /* End hide from IE-mac */ 
     903</style> 
     904<![endif]--> 
     905<?php 
    859906                  } 
    860907            }