Changeset 358
- Timestamp:
- 03/19/08 17:49:43 (16 years ago)
- Location:
- plugins/carnaval
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/carnaval/_define.php
r329 r358 19 19 /* Description*/ 'Identify your comments', 20 20 /* Author */ 'Osku', 21 /* Version */ '1.0. 0',21 /* Version */ '1.0.1', 22 22 /* Permissions */ 'contentadmin' 23 23 ); -
plugins/carnaval/_prepend.php
r318 r358 16 16 17 17 $__autoload['dcCarnaval'] = dirname(__FILE__).'/class.dc.carnaval.php'; 18 19 dcCarnaval::init($GLOBALS['core']->blog); 18 20 ?> -
plugins/carnaval/_public.php
r331 r358 45 45 public static function getCommentClass() 46 46 { 47 global $ core,$_ctx;47 global $_ctx; 48 48 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)); 52 50 return html::escapeHTML($classe_perso); 53 51 } … … 55 53 public static function getPingClass() 56 54 { 57 global $ core,$_ctx;55 global $_ctx; 58 56 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()); 62 58 return html::escapeHTML($classe_perso); 63 59 } -
plugins/carnaval/class.dc.carnaval.php
r329 r358 17 17 class dcCarnaval 18 18 { 19 private $blog;20 private $con;21 private $table;19 private static $blog; 20 private static $con; 21 private static $table; 22 22 23 public function __construct(&$blog) 23 public static $found; // Avoid multiple SQL requests 24 25 public static function init(&$blog) 24 26 { 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 ); 28 35 } 29 30 public function getClasses($params=array())36 37 public static function getClasses($params=array()) 31 38 { 32 39 $strReq = 33 40 'SELECT class_id, comment_author, comment_author_mail, '. 34 41 '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 38 45 if (isset($params['class_id'])) { 39 46 $strReq .= 'AND class_id = '.(integer) $params['class_id'].' '; 40 47 } 41 48 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']).'\''; 44 52 } 45 53 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']).'\' '. 47 56 'LIKE CONCAT(comment_author_site,\'%\')'; 48 57 } 49 return $this->con->select($strReq);58 return self::$con->select($strReq); 50 59 } 51 52 public function getClass($id)60 61 public static function getClass($id) 53 62 { 54 return $this->getClasses(array('class_id'=>$id));63 return self::getClasses(array('class_id'=>$id)); 55 64 } 56 57 public function addClass($author,$mail,$site='',$class)65 66 public static function addClass($author,$mail,$site='',$class) 58 67 { 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; 62 71 $cur->comment_author = (string) $author; 63 72 $cur->comment_author_mail = (string) $mail; 64 73 $cur->comment_author_site = (string) $site; 65 74 $cur->comment_class = (string) $class; 66 75 67 76 if ($cur->comment_author == '') { 68 77 throw new Exception(__('You must provide a name')); … … 74 83 throw new Exception(__('You must provide an e-mail or a web site adress')); 75 84 } 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); 80 89 $cur->class_id = (integer) $rs->f(0) + 1; 81 90 $cur->insert(); 82 83 $this->blog->triggerBlog();91 92 self::$blog->triggerBlog(); 84 93 } 85 86 public function updateClass($id,$author,$mail='',$site='',$class='')94 95 public static function updateClass($id,$author,$mail='',$site='',$class='') 87 96 { 88 $cur = $this->con->openCursor($this->table);97 $cur = self::$con->openCursor(self::$table); 89 98 $cur->comment_author = $author; 90 99 $cur->comment_author_mail = $mail; 91 100 $cur->comment_author_site = $site; 92 101 $cur->comment_class = $class; 93 102 94 103 if ($cur->comment_author == '') { 95 104 throw new Exception(__('You must provide a name')); 96 } 105 } 97 106 if ($cur->comment_class == '') { 98 107 throw new Exception(__('You must provide a CSS Class')); … … 101 110 throw new Exception(__('You must provide an e-mail or a web site adress')); 102 111 } 103 112 104 113 $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(); 108 117 } 109 110 111 public function delClass($id)118 119 120 public static function delClass($id) 112 121 { 113 122 $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)."' ". 117 126 'AND class_id = '.$id.' '; 118 119 $this->con->execute($strReq);120 $this->blog->triggerBlog();127 128 self::$con->execute($strReq); 129 self::$blog->triggerBlog(); 121 130 } 122 131 123 public function getCommentClass($mail)132 public static function getCommentClass($mail) 124 133 { 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]; 127 143 } 128 129 public function getPingClass($site)144 145 public static function getPingClass($site) 130 146 { 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]; 133 156 } 134 157 }
Note: See TracChangeset
for help on using the changeset viewer.