WordPress.org

Plugin Directory

Changeset 585416


Ignore:
Timestamp:
08/14/12 16:00:58 (21 months ago)
Author:
tommcfarlin
Message:
  • Changing the way comment images are associated with comments to improve performance for users who aren't logged in
  • Resolving a reported issue with Firefox and IE
Location:
comment-images/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • comment-images/trunk/README.txt

    r585322 r585416  
    55Requires at least: 3.4.1 
    66Tested up to: 3.4.1 
    7 Stable tag: 1.1 
     7Stable tag: 1.2 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    5959== Changelog == 
    6060 
     61= 1.2 = 
     62* Changing the way comment images are associated with comments to improve performance for users who aren't logged in 
     63* Resolving a reported issue with Firefox and IE 
     64 
    6165= 1.1 = 
    6266* Updating README to show the screenshots. 
  • comment-images/trunk/plugin.php

    r585322 r585416  
    44Plugin URI: http://tommcfarlin.com/comment-images 
    55Description: Allow your readers easily to attach an image to their comment. 
    6 Version: 1.1 
     6Version: 1.2 
    77Author: Tom McFarlin 
    88Author URI: http://tommcfarlin.com 
     
    2828// TODO  
    2929// - Next update show image preview in the admin of the image 
    30 // -  
     30// - JetPack compatibility 
    3131 
    3232class Comment_Image { 
     
    4545        // Determine if the hosting environment can save files. 
    4646        if( $this->can_save_files() ) { 
     47     
     48            // We need to update all of the comments thus far 
     49            if( false == get_option( 'update_comment_images' ) || null == get_option( 'update_comment_images' ) ) { 
     50                $this->update_old_comments(); 
     51            } // end if 
    4752     
    4853            // Add comment related stylesheets, scripts, form manipulation, and image serialization 
     
    5156            add_action( 'comment_form' , array( &$this, 'add_image_upload_form' ) ); 
    5257            add_filter( 'wp_insert_comment', array( &$this, 'save_comment_image' ) ); 
    53             add_filter( 'comment_text', array( &$this, 'display_comment_image' ) ); 
    54          
     58            add_filter( 'comments_array', array( &$this, 'display_comment_image' ) ); 
     59             
    5560        // If not, display a notice.     
    5661        } else { 
     
    6570     * Core Functions 
    6671     *---------------------------------------------*/ 
     72      
     73     /** 
     74      * In previous versions of the plugin, the image were written out after the comments. Now, 
     75      * they are actually part of the comment content so we need to update all old options. 
     76      * 
     77      * Note that this option is not removed on deactivation because it will run *again* if the 
     78      * user ever re-activates it this duplicating the image. 
     79      */ 
     80     private function update_old_comments() { 
     81          
     82        // Update the option that this has not run 
     83        update_option( 'update_comment_images', false ); 
     84         
     85        // Iterate through each of the comments... 
     86        foreach( get_comments() as $comment ) { 
     87         
     88            // If the comment image meta value exists... 
     89            if( true == get_comment_meta( $comment->comment_ID, 'comment_image' ) ) { 
     90             
     91                // Get the associated comment image 
     92                $comment_image = get_comment_meta( $comment->comment_ID, 'comment_image', true ); 
     93                 
     94                // Append the image to the comment content 
     95                $comment->comment_content .= '<p class="comment-image">'; 
     96                    $comment->comment_content .= '<img src="' . $comment_image['url'] . '" alt="" />'; 
     97                $comment->comment_content .= '</p><!-- /.comment-image -->'; 
     98                 
     99                // Now we need to actually update the comment 
     100                wp_update_comment( (array)$comment ); 
     101                 
     102            } // end if 
     103         
     104        } // end if 
     105         
     106        // Update the fact that this has run so we don't run it again 
     107        update_option( 'update_comment_images', true ); 
     108          
     109     } // end update_old_comments 
    67110      
    68111     /** 
     
    175218     * @params  $comment    The content of the comment. 
    176219     */ 
    177     function display_comment_image( $comment ) { 
    178          
     220    function display_comment_image( $comments ) { 
     221         
     222        // Get the most recent comment 
     223        $comment = $comments[ count( $comments ) - 1 ]; 
     224 
    179225        // If the comment image meta value exists, then render the comment image 
    180         if( false != get_comment_meta( get_comment_ID(), 'comment_image' ) ) { 
     226        if( false != get_comment_meta( $comment->comment_ID, 'comment_image' ) ) { 
    181227         
    182228            // Get the comment image meta 
    183             $comment_image = get_comment_meta( get_comment_ID(), 'comment_image', true ); 
     229            $comment_image = get_comment_meta( $comment->comment_ID, 'comment_image', true ); 
    184230             
    185231            // Render it in a paragraph element appended to the comment 
    186             $comment .= '<p class="comment-image">'; 
    187                 $comment .= '<img src="' . $comment_image['url'] . '" alt="" />'; 
    188             $comment .= '</p><!-- /.comment-image -->';  
    189              
    190         } // end if 
    191          
    192         return $comment; 
     232            $comment->comment_content .= '<p class="comment-image">'; 
     233                $comment->comment_content .= '<img src="' . $comment_image['url'] . '" alt="" />'; 
     234            $comment->comment_content .= '</p><!-- /.comment-image -->';     
     235             
     236        } // end if 
     237         
     238        return $comments; 
    193239         
    194240    } // end display_comment_image 
Note: See TracChangeset for help on using the changeset viewer.