Dotclear

Changeset 358


Ignore:
Timestamp:
03/19/08 17:49:43 (16 years ago)
Author:
sacha
Message:

Carnaval - Small bugfix and performance level improvements

Location:
plugins/carnaval
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • plugins/carnaval/_define.php

    r329 r358  
    1919     /* Description*/    'Identify your comments', 
    2020     /* Author */        'Osku', 
    21      /* Version */       '1.0.0', 
     21     /* Version */       '1.0.1', 
    2222     /* Permissions */   'contentadmin' 
    2323); 
  • plugins/carnaval/_prepend.php

    r318 r358  
    1616 
    1717$__autoload['dcCarnaval'] = dirname(__FILE__).'/class.dc.carnaval.php'; 
     18 
     19dcCarnaval::init($GLOBALS['core']->blog); 
    1820?> 
  • plugins/carnaval/_public.php

    r331 r358  
    4545     public static function getCommentClass() 
    4646     { 
    47           global $core,$_ctx; 
     47          global $_ctx; 
    4848           
    49           $carnaval = new dcCarnaval($core->blog); 
    50           $classe_perso = $carnaval->getCommentClass($_ctx->comments->getEmail(false));  
    51           $classe_perso = html::escapeHTML($classe_perso); 
     49          $classe_perso = dcCarnaval::getCommentClass($_ctx->comments->getEmail(false)); 
    5250          return html::escapeHTML($classe_perso); 
    5351     } 
     
    5553     public static function getPingClass() 
    5654     { 
    57           global $core,$_ctx; 
     55          global $_ctx; 
    5856           
    59           $carnaval = new dcCarnaval($core->blog); 
    60           $classe_perso = $carnaval->getPingClass($_ctx->pings->getAuthorURL());  
    61           $classe_perso = html::escapeHTML($classe_perso); 
     57          $classe_perso = dcCarnaval::getPingClass($_ctx->pings->getAuthorURL()); 
    6258          return html::escapeHTML($classe_perso); 
    6359     } 
  • plugins/carnaval/class.dc.carnaval.php

    r329 r358  
    1717class dcCarnaval 
    1818{ 
    19      private $blog; 
    20      private $con; 
    21      private $table; 
     19     private static $blog; 
     20     private static $con; 
     21     private static $table; 
    2222      
    23      public function __construct(&$blog) 
     23     public static $found;    // Avoid multiple SQL requests 
     24 
     25     public static function init(&$blog) 
    2426     { 
    25           $this->blog =& $blog; 
    26           $this->con =& $blog->con; 
    27           $this->table = $this->blog->prefix.'carnaval'; 
     27          self::$blog =& $blog; 
     28          self::$con =& $blog->con; 
     29          self::$table = $blog->prefix.'carnaval'; 
     30           
     31          self::$found  = array( 
     32               'comments'=>array(), 
     33               'pings'=>array() 
     34          ); 
    2835     } 
    29       
    30      public function getClasses($params=array()) 
     36 
     37     public static function getClasses($params=array()) 
    3138     { 
    3239          $strReq = 
    3340               'SELECT class_id, comment_author, comment_author_mail, '. 
    3441               'comment_author_site, comment_class '. 
    35                'FROM '.$this->table.' '. 
    36                "WHERE blog_id = '".$this->con->escape($this->blog->id)."' "; 
    37            
     42               'FROM '.self::$table.' '. 
     43               "WHERE blog_id = '".self::$con->escape(self::$blog->id)."' "; 
     44 
    3845          if (isset($params['class_id'])) { 
    3946               $strReq .= 'AND class_id = '.(integer) $params['class_id'].' '; 
    4047          } 
    4148          if (isset($params['mail'])) { 
    42                $strReq .= 'AND comment_author_mail = \''. 
    43                     $this->con->escape($params['mail']).'\''; 
     49               $strReq .= 'AND comment_author_mail <> \'\' '. 
     50                    'AND comment_author_mail = \''. 
     51                    self::$con->escape($params['mail']).'\''; 
    4452          } 
    4553          if (isset($params['site'])) { 
    46                $strReq .= 'AND \''.$this->con->escape($params['site']).'\' '. 
     54               $strReq .= 'AND comment_author_site <> \'\' '. 
     55                    'AND \''.self::$con->escape($params['site']).'\' '. 
    4756                    'LIKE CONCAT(comment_author_site,\'%\')'; 
    4857          } 
    49           return $this->con->select($strReq); 
     58          return self::$con->select($strReq); 
    5059     } 
    51       
    52      public function getClass($id) 
     60 
     61     public static function getClass($id) 
    5362     { 
    54           return $this->getClasses(array('class_id'=>$id)); 
     63          return self::getClasses(array('class_id'=>$id)); 
    5564     } 
    56       
    57      public function addClass($author,$mail,$site='',$class) 
     65 
     66     public static function addClass($author,$mail,$site='',$class) 
    5867     { 
    59           $cur = $this->con->openCursor($this->table); 
    60            
    61           $cur->blog_id = (string) $this->blog->id; 
     68          $cur = self::$con->openCursor(self::$table); 
     69 
     70          $cur->blog_id = (string) self::$blog->id; 
    6271          $cur->comment_author = (string) $author; 
    6372          $cur->comment_author_mail = (string) $mail; 
    6473          $cur->comment_author_site  = (string) $site; 
    6574          $cur->comment_class = (string) $class; 
    66            
     75 
    6776          if ($cur->comment_author == '') { 
    6877               throw new Exception(__('You must provide a name')); 
     
    7483               throw new Exception(__('You must provide an e-mail or a web site adress')); 
    7584          } 
    76            
    77           $strReq = 'SELECT MAX(class_id) FROM '.$this->table; 
    78            
    79           $rs = $this->con->select($strReq); 
     85 
     86          $strReq = 'SELECT MAX(class_id) FROM '.self::$table; 
     87 
     88          $rs = self::$con->select($strReq); 
    8089          $cur->class_id = (integer) $rs->f(0) + 1; 
    8190          $cur->insert(); 
    82            
    83           $this->blog->triggerBlog(); 
     91 
     92          self::$blog->triggerBlog(); 
    8493     } 
    85       
    86      public function updateClass($id,$author,$mail='',$site='',$class='') 
     94 
     95     public static function updateClass($id,$author,$mail='',$site='',$class='') 
    8796     { 
    88           $cur = $this->con->openCursor($this->table); 
     97          $cur = self::$con->openCursor(self::$table); 
    8998          $cur->comment_author = $author; 
    9099          $cur->comment_author_mail = $mail; 
    91100          $cur->comment_author_site  = $site; 
    92101          $cur->comment_class = $class; 
    93            
     102 
    94103          if ($cur->comment_author == '') { 
    95104               throw new Exception(__('You must provide a name')); 
    96           }          
     105          } 
    97106          if ($cur->comment_class == '') { 
    98107               throw new Exception(__('You must provide a CSS Class')); 
     
    101110               throw new Exception(__('You must provide an e-mail or a web site adress')); 
    102111          } 
    103            
     112 
    104113          $cur->update('WHERE class_id = '.(integer) $id. 
    105                " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 
    106            
    107           $this->blog->triggerBlog(); 
     114               " AND blog_id = '".self::$con->escape(self::$blog->id)."'"); 
     115 
     116          self::$blog->triggerBlog(); 
    108117     } 
    109       
    110       
    111      public function delClass($id) 
     118 
     119 
     120     public static function delClass($id) 
    112121     { 
    113122          $id = (integer) $id; 
    114            
    115           $strReq = 'DELETE FROM '.$this->table.' '. 
    116                     "WHERE blog_id = '".$this->con->escape($this->blog->id)."' ". 
     123 
     124          $strReq = 'DELETE FROM '.self::$table.' '. 
     125                    "WHERE blog_id = '".self::$con->escape(self::$blog->id)."' ". 
    117126                    'AND class_id = '.$id.' '; 
    118            
    119           $this->con->execute($strReq); 
    120           $this->blog->triggerBlog(); 
     127 
     128          self::$con->execute($strReq); 
     129          self::$blog->triggerBlog(); 
    121130     } 
    122131 
    123      public function getCommentClass($mail) 
     132     public static function getCommentClass($mail) 
    124133     { 
    125           $rs = $this->getClasses(array('mail'=>$mail)); 
    126           return $rs->isEmpty() ? '' : ' '.$rs->comment_class; 
     134          if (isset(self::$found['comments'][$mail])) { 
     135               return self::$found['comments'][$mail]; 
     136          } 
     137           
     138          $rs = self::getClasses(array('mail'=>$mail)); 
     139          self::$found['comments'][$mail] = 
     140               $rs->isEmpty() ? '' : ' '.$rs->comment_class; 
     141           
     142          return self::$found['comments'][$mail]; 
    127143     } 
    128       
    129      public function getPingClass($site) 
     144 
     145     public static function getPingClass($site) 
    130146     { 
    131           $rs = $this->getClasses(array('site'=>$site)); 
    132           return $rs->isEmpty() ? '' : ' '.$rs->comment_class; 
     147          if (isset(self::$found['pings'][$site])) { 
     148               return self::$found['pings'][$site]; 
     149          } 
     150           
     151          $rs = self::getClasses(array('site'=>$site)); 
     152          self::$found['pings'][$site] = 
     153               $rs->isEmpty() ? '' : ' '.$rs->comment_class; 
     154                
     155          return self::$found['pings'][$site]; 
    133156     } 
    134157} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map