Plugin Directory

Changeset 1491269


Ignore:
Timestamp:
09/06/2016 04:19:38 PM (10 years ago)
Author:
pgogy
Message:

Better code

Location:
anonymous-comments
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • anonymous-comments/trunk/anonymous_comments.php

    r1449875 r1491269  
    44    Plugin Name: Anonymous Comment
    55    Description: Allows a page to have anonymous comments
    6     Version: 0.1
     6    Version: 0.2
    77    Author: pgogy
    88    Author URI: http://www.pgogywebstuff.com
  • anonymous-comments/trunk/code/display/class-anonymous_comments_display.php

    r1449875 r1491269  
    44   
    55    public function __construct() {         
    6         add_filter('get_comment_author', array($this, 'author'));
    7         add_filter('get_avatar', array($this, 'avatar'), 1 , 5);
    8         add_filter('comment_url', array($this, 'url'));
    9         add_filter('comment_email', array($this, 'email'));
     6        add_filter('get_comment_author', array($this, 'author'), 10, 3);
     7        add_filter('get_avatar', array($this, 'avatar'), 10 , 5);
     8        add_filter('get_comment_author_url', array($this, 'url'),10,3);
     9        add_filter('comment_email', array($this, 'email'), 10, 3);
    1010        add_action('comment_form', array($this, 'additional'));
    1111    }
    1212   
    1313    function additional(){
    14         echo "<p>" . __("All comments to this site are anonymous") . "</p>";
     14        global $post;
     15        if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
     16            echo "<p>" . __("All comments to this post are anonymous") . "</p>";
     17        }
    1518    }
    1619   
    17     function email( $email ) {
    18         if(is_single()){
    19             global $post,$comment;
    20            
    21             if(get_post_meta($post->ID, "anonymous_comments")!==""){
    22            
    23                 if(get_current_user_id()!=0){
    24                     if(get_post_meta($post->ID, "anonymous_comments")!==""){
    25                         if(get_post_meta($post->ID, "admin_bypass_anonymous_comments")!==""){
    26                             return $email;
    27                         }
    28                     }
     20    function email( $email, $comment_ID, $comment ) {
     21       
     22        if(is_admin()){
     23            if (defined('DOING_AJAX')){
     24                if(!DOING_AJAX) {
     25                    return $author;
    2926                }
    30                
    31                 if($comment->user_id==$post->post_author){
    32                     if(get_post_meta($post->ID, "show_author_anonymous_comments")!==""){
     27            }
     28        }
     29
     30        global $post,$comment;
     31       
     32        if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
     33       
     34            if(get_current_user_id()!=0){
     35                if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
     36                    if(get_post_meta($post->ID, "admin_bypass_anonymous_comments",true)!==""){
    3337                        return $email;
    3438                    }
    3539                }
    36                
    37                 return "";
    38                
    3940            }
    4041           
     42            if($comment->user_id==$post->post_author){
     43                if(get_post_meta($post->ID, "show_author_anonymous_comments",true)!==""){
     44                    return $email;
     45                }
     46            }
     47           
     48            return "";
     49           
    4150        }
     51
    4252    }
    4353   
    44     function url( $url ) {
    45         if(is_single()){
    46             global $post,$comment;
     54    function url( $url, $comment_ID, $comment) {
     55   
     56        if(is_admin()){
     57            if (defined('DOING_AJAX')){
     58                if(!DOING_AJAX) {
     59                    return $author;
     60                }
     61            }
     62        }
     63       
     64        global $post,$comment;
    4765           
    48             if(get_post_meta($post->ID, "anonymous_comments")!==""){
    49            
    50                 if(get_current_user_id()!=0){
    51                     if(get_post_meta($post->ID, "anonymous_comments")!==""){
    52                         if(get_post_meta($post->ID, "admin_bypass_anonymous_comments")!==""){
    53                             return $url;
    54                         }
    55                     }
    56                 }
    57                
    58                 if($comment->user_id==$post->post_author){
    59                     if(get_post_meta($post->ID, "show_author_anonymous_comments")!==""){
     66        if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
     67       
     68            if(get_current_user_id()!=0){
     69                if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
     70                    if(get_post_meta($post->ID, "admin_bypass_anonymous_comments",true)!==""){
    6071                        return $url;
    6172                    }
    6273                }
    63                
    64                 return "";
    65                
    6674            }
    6775           
     76            if($comment->user_id==$post->post_author){
     77                if(get_post_meta($post->ID, "show_author_anonymous_comments",true)!==""){
     78                    return $url;
     79                }
     80            }
     81           
     82            return "";
     83           
    6884        }
     85
    6986    }
    7087   
    7188    function avatar( $avatar, $id_or_email, $size, $default, $alt ) {
    7289   
    73         if(is_single()){
    74             global $post,$comment;
     90        if(is_admin()){
     91            if (defined('DOING_AJAX')){
     92                if(!DOING_AJAX) {
     93                    return $author;
     94                }
     95            }
     96        }
     97       
     98        global $post,$comment;
    7599           
    76             if(get_post_meta($post->ID, "anonymous_comments")!==""){
     100        if(isset($post->ID)){   
     101           
     102            if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
    77103           
    78104                if(get_current_user_id()!=0){
    79                     if(get_post_meta($post->ID, "anonymous_comments")!==""){
    80                         if(get_post_meta($post->ID, "admin_bypass_anonymous_comments")!==""){
     105                    if(get_post_meta($post->ID, "anonymous_comments",true)!==""){
     106                        if(get_post_meta($post->ID, "admin_bypass_anonymous_comments",true)!==""){
    81107                            return $avatar;
    82108                        }
     
    84110                }
    85111               
    86                 if($comment->user_id==$post->post_author){
    87                     if(get_post_meta($post->ID, "show_author_anonymous_comments")!==""){
    88                         return $avatar;
     112                if(isset($comment->user_id)){
     113                    if($comment->user_id==$post->post_author){
     114                        if(get_post_meta($post->ID, "show_author_anonymous_comments",true)!==""){
     115                            return $avatar;
     116                        }
    89117                    }
    90118                }
     
    95123           
    96124        }
     125
    97126    }
    98127   
    99     function author($author){
    100 
    101         if(is_single()){
     128    function author($author, $comment_ID, $comment){
    102129   
    103             global $post, $comment;
     130        if(is_admin()){
     131            if (defined('DOING_AJAX')){
     132                if(!DOING_AJAX) {
     133                    return $author;
     134                }
     135            }
     136        }
    104137       
    105             if(get_post_meta($post->ID, "anonymous_comments")!==""){
    106            
    107                 if(get_current_user_id()!=0){
    108                     if(get_post_meta($post->ID, "anonymous_comments")!==""){
    109                         if(get_post_meta($post->ID, "admin_bypass_anonymous_comments")!==""){
    110                             return $author;
    111                         }
    112                     }
    113                 }
    114                
    115                 if($comment->user_id==$post->post_author){
    116                     if(get_post_meta($post->ID, "show_author_anonymous_comments")!==""){
     138        if(get_post_meta($comment->comment_post_ID, "anonymous_comments",true)!==""){
     139       
     140            if(get_current_user_id()!=0){
     141                if(get_post_meta($comment->comment_post_ID, "anonymous_comments",true)!==""){
     142                    if(get_post_meta($comment->comment_post_ID, "admin_bypass_anonymous_comments",true)!==""){
    117143                        return $author;
    118144                    }
    119145                }
    120                
    121                 $authors = get_post_meta($post->ID, "comment_authors", true);
    122                 if(!is_array($authors)){
    123                     $authors = array();
     146            }
     147           
     148            $post = get_post($comment->comment_post_ID);
     149           
     150            if($comment->user_id==$post->post_author){
     151                if(get_post_meta($post->ID, "show_author_anonymous_comments", true)!==""){
     152                    return $author;
    124153                }
    125                    
    126                 if(!in_array($author, $authors)){
    127                     $authors[] = $author;
    128                     update_post_meta($post->ID, "comment_authors", $authors);
    129                     return __("Anonymous Commenter") . " " . count($authors);
    130                 }else{
    131                     return __("Anonymous Commenter") . " " . (array_search ($author, $authors) + 1);   
    132                 }
    133                
     154            }
     155           
     156            $authors = get_post_meta($comment->comment_post_ID, "comment_authors", true);
     157            if(!is_array($authors)){
     158                $authors = array();
     159            }
     160           
     161            if(!in_array($author, $authors)){
     162                $authors[] = $author;
     163                update_post_meta($comment->comment_post_ID, "comment_authors", $authors);
     164                return __("Anonymous Commenter") . " " . count($authors);
     165            }else{
     166                return __("Anonymous Commenter") . " " . (array_search ($author, $authors) + 1);   
    134167            }
    135168           
    136169        }
    137170       
     171        return $author;
     172           
    138173    }
    139174   
Note: See TracChangeset for help on using the changeset viewer.