Dotclear


Ignore:
Timestamp:
08/10/09 23:33:28 (14 years ago)
Author:
JcDenis
Message:

topWriter 0.2:

  • Fixed php 5.3 compatibility
  • Fixed PostGreSQL compatibility
  • Added option to exclude post authors from comment list
File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/topWriter/_widgets.php

    r1304 r1379  
    1111# -- END LICENSE BLOCK ------------------------------------ 
    1212 
    13 if (!defined('DC_RC_PATH')) return; 
     13if (!defined('DC_RC_PATH')){return;} 
    1414 
    1515$core->addBehavior('initWidgets',array('topWriterWidget','init')); 
     
    1717class topWriterWidget 
    1818{ 
    19      public static function init(&$w) 
     19     public static function init($w) 
    2020     { 
    2121          $w->create('topcom',__('Top comments'), 
     
    3131               __('Ascending') => 'asc',__('Descending') => 'desc')); 
    3232          $w->topcom->setting('limit',__('Limit:'),'10','text'); 
     33          $w->topcom->setting('exclude',__('Exclude post writer from list'),0,'check'); 
    3334          $w->topcom->setting('homeonly',__('Home page only'),1,'check'); 
    3435 
     
    4849     } 
    4950 
    50      public static function topCom(&$w) 
     51     public static function topCom($w) 
    5152     { 
    5253          global $core; 
     
    5455          if ($w->homeonly && $core->url->type != 'default') return; 
    5556 
    56           $rs = $core->con->select(  
    57                'SELECT COUNT(comment_id) AS comment_count, '. 
    58                'comment_author, comment_email, comment_site '. 
    59                "FROM ".$core->prefix."post P,  ".$core->prefix."comment C ". 
    60                'WHERE P.post_id=C.post_id '. 
    61                "AND blog_id='".$core->con->escape($core->blog->id)."' ". 
    62                'AND post_status=1 AND comment_status=1 '. 
    63                self::period('comment_dt',$w->period). 
    64                'GROUP BY C.comment_email '. 
    65                'ORDER BY  comment_count '.($w->sort == 'asc' ? 'ASC' : 'DESC'). 
    66                ', comment_dt DESC '. 
    67                $core->con->limit(abs((integer) $w->limit)) 
    68           ); 
     57          $req = 
     58          'SELECT COUNT(*) AS count, comment_email '. 
     59          "FROM ".$core->prefix."post P,  ".$core->prefix."comment C ". 
     60          'WHERE P.post_id=C.post_id '. 
     61          "AND blog_id='".$core->con->escape($core->blog->id)."' ". 
     62          'AND post_status=1 AND comment_status=1 '. 
     63          self::period('comment_dt',$w->period); 
     64 
     65          if ($w->exclude) { 
     66               $req .=  
     67               'AND comment_email NOT IN ('. 
     68               ' SELECT U.user_email '. 
     69               ' FROM '.$core->prefix.'user U'. 
     70               ' INNER JOIN '.$core->prefix.'post P ON P.user_id = U.user_id '. 
     71               " WHERE blog_id='".$core->con->escape($core->blog->id)."' ". 
     72               ' GROUP BY U.user_email) '; 
     73          } 
     74 
     75          $req .= 
     76          'GROUP BY comment_email '. 
     77          'ORDER BY count '.($w->sort == 'asc' ? 'ASC' : 'DESC').' '. 
     78          $core->con->limit(abs((integer) $w->limit)); 
     79           
     80          $rs = $core->con->select($req); 
    6981 
    7082          if ($rs->isEmpty()) return; 
    7183 
    7284          $content = ''; 
    73           $res = array(); 
    7485          $i = 0; 
    7586          while($rs->fetch()){ 
     87               $user = $core->con->select( 
     88                    "SELECT * FROM ".$core->prefix."comment WHERE comment_email='".$rs->comment_email."' " 
     89               ); 
     90 
     91               if (!$user->comment_author) continue; 
     92 
    7693               $i++; 
    7794               $rank = '<span class="topcomments-rank">'.$i.'</span>'; 
    7895 
    79                if ($rs->comment_site) { 
    80                     $author = '<a href="'.$rs->comment_site.'" title="'. 
    81                          __('Author link').'">'.$rs->comment_author.'</a>'; 
    82                } else 
    83                     $author = $rs->comment_author; 
    84  
    85                if ($rs->comment_count == 0) 
     96               if ($user->comment_site) { 
     97                    $author = '<a href="'.$user->comment_site.'" title="'. 
     98                         __('Author link').'">'.$user->comment_author.'</a>'; 
     99               } 
     100               else 
     101                    $author = $user->comment_author; 
     102 
     103               if ($rs->count == 0) 
    86104                    $count = __('no comment'); 
    87                elseif($rs->comment_count == 1) 
     105 
     106               elseif ($rs->count == 1) 
    88107                    $count = __('one comment'); 
     108 
    89109               else 
    90                     $count = sprintf(__('%s comments'),$rs->comment_count); 
     110                    $count = sprintf(__('%s comments'),$rs->count); 
    91111 
    92112               $content .= '<li>'.str_replace( 
     
    97117          } 
    98118 
     119          if ($i < 1) return; 
     120 
    99121          return  
    100122          '<div class="topcomments">'. 
     
    104126     } 
    105127 
    106      public static function topPost(&$w) 
     128     public static function topPost($w) 
    107129     { 
    108130          global $core; 
     
    111133 
    112134          $rs = $core->con->select( 
    113           'SELECT COUNT(P.post_id) AS post_count, '. 
    114           'U.user_id, U.user_name, U.user_firstname, U.user_displayname, U.user_email '. 
     135          'SELECT COUNT(*) AS count, U.user_id '. 
    115136          "FROM ".$core->prefix."post P ". 
    116137          'INNER JOIN '.$core->prefix.'user U ON U.user_id = P.user_id '. 
     
    119140          self::period('post_dt',$w->period). 
    120141          'GROUP BY U.user_id '. 
    121           'ORDER BY post_count '.($w->sort == 'asc' ? 'ASC' : 'DESC'). 
    122           ', post_dt DESC '. 
     142          'ORDER BY count '.($w->sort == 'asc' ? 'ASC' : 'DESC').', U.user_id ASC '. 
    123143          $core->con->limit(abs((integer) $w->limit))); 
    124144 
     
    128148          $i = 0; 
    129149          while($rs->fetch()){ 
     150               $user = $core->con->select( 
     151                    "SELECT * FROM ".$core->prefix."user WHERE user_id='".$rs->user_id."' " 
     152               ); 
     153 
     154               $author = dcUtils::getUserCN($user->user_id,$user->user_name, 
     155                    $user->user_firstname,$user->user_displayname); 
     156 
     157               if (empty($author)) continue; 
     158 
    130159               $i++; 
    131160               $rank = '<span class="topentries-rank">'.$i.'</span>'; 
    132161 
    133                $author = dcUtils::getUserCN($rs->user_id,$rs->user_name, 
    134                     $rs->user_firstname,$rs->user_displayname); 
    135  
    136162               if ($core->blog->settings->authormode_active) { 
    137163                    $author = '<a href="'. 
    138                          $core->blog->url.$core->url->getBase("author").'/'.$rs->user_id.'" '. 
     164                         $core->blog->url.$core->url->getBase("author").'/'.$user->user_id.'" '. 
    139165                         'title="'.__('Author posts').'">'.$author.'</a>'; 
    140                } elseif ($rs->user_url) { 
    141                     $author = '<a href="'.$rs->user_url.'" title="'. 
     166               } 
     167               elseif ($user->user_url) { 
     168                    $author = '<a href="'.$user->user_url.'" title="'. 
    142169                         __('Author link').'">'.$author.'</a>'; 
    143170               } 
    144171 
    145                if ($rs->post_count == 0) 
     172               if ($rs->count == 0) 
    146173                    $count = __('no post'); 
    147                elseif($rs->post_count == 1) 
     174 
     175               elseif ($rs->count == 1) 
    148176                    $count = __('one post'); 
     177 
    149178               else 
    150                     $count = sprintf(__('%s posts'),$rs->post_count); 
     179                    $count = sprintf(__('%s posts'),$rs->count); 
    151180 
    152181               $content .= '<li>'.str_replace( 
     
    156185               ).'</li>'; 
    157186          } 
     187 
     188          if ($i < 1) return; 
    158189 
    159190          return  
Note: See TracChangeset for help on using the changeset viewer.

Sites map