Changeset 2566:9bf417837888 for plugins/antispam/inc/lib.dc.antispam.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/antispam/inc/lib.dc.antispam.php
r1478 r2566 15 15 { 16 16 public static $filters; 17 17 18 18 public static function initFilters() 19 19 { 20 20 global $core; 21 21 22 22 if (!isset($core->spamfilters)) { 23 23 return; 24 24 } 25 25 26 26 self::$filters = new dcSpamFilters($core); 27 27 self::$filters->init($core->spamfilters); 28 28 } 29 29 30 30 public static function isSpam($cur) 31 31 { … … 33 33 self::$filters->isSpam($cur); 34 34 } 35 35 36 36 public static function trainFilters($blog,$cur,$rs) 37 37 { … … 41 41 $status = 'spam'; 42 42 } 43 43 44 44 # From spam to ham 45 45 if ($rs->comment_status == -2 && $cur->comment_status == 1) { 46 46 $status = 'ham'; 47 47 } 48 48 49 49 # the status of this comment has changed 50 50 if ($status) 51 51 { 52 52 $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 53 53 54 54 self::initFilters(); 55 55 self::$filters->trainFilters($rs,$status,$filter_name); 56 56 } 57 57 } 58 58 59 59 public static function statusMessage($rs) 60 60 { … … 62 62 { 63 63 $filter_name = $rs->exists('comment_spam_filter') ? $rs->comment_spam_filter : null; 64 64 65 65 self::initFilters(); 66 66 67 67 return 68 68 '<p><strong>'.__('This comment is a spam:').'</strong> '. … … 70 70 } 71 71 } 72 72 73 73 public static function dashboardIcon($core, $icons) 74 74 { … … 78 78 } 79 79 } 80 80 81 81 public static function dashboardIconTitle($core) 82 82 { … … 88 88 } 89 89 } 90 90 91 91 public static function countSpam($core) 92 92 { 93 93 return $core->blog->getComments(array('comment_status'=>-2),true)->f(0); 94 94 } 95 95 96 96 public static function countPublishedComments($core) 97 97 { 98 98 return $core->blog->getComments(array('comment_status'=>1),true)->f(0); 99 99 } 100 100 101 101 public static function delAllSpam($core, $beforeDate = null) 102 102 { … … 110 110 $strReq .= 'AND comment_dt < \''.$beforeDate.'\' '; 111 111 } 112 112 113 113 $rs = $core->con->select($strReq); 114 114 $r = array(); … … 116 116 $r[] = (integer) $rs->comment_id; 117 117 } 118 118 119 119 if (empty($r)) { 120 120 return; 121 121 } 122 122 123 123 $strReq = 124 124 'DELETE FROM '.$core->prefix.'comment '. 125 125 'WHERE comment_id '.$core->con->in($r).' '; 126 126 127 127 $core->con->execute($strReq); 128 128 } 129 129 130 130 public static function getUserCode($core) 131 131 { … … 135 135 return bin2hex($code); 136 136 } 137 137 138 138 public static function checkUserCode($core,$code) 139 139 { 140 140 $code = pack('H*',$code); 141 141 142 142 $user_id = trim(@pack('a32',substr($code,0,32))); 143 143 $pwd = @unpack('H40hex',substr($code,32,40)); 144 144 145 145 if ($user_id === false || $pwd === false) { 146 146 return false; 147 147 } 148 148 149 149 $pwd = $pwd['hex']; 150 150 151 151 $strReq = 'SELECT user_id, user_pwd '. 152 152 'FROM '.$core->prefix.'user '. 153 153 "WHERE user_id = '".$core->con->escape($user_id)."' "; 154 154 155 155 $rs = $core->con->select($strReq); 156 156 157 157 if ($rs->isEmpty()) { 158 158 return false; 159 159 } 160 160 161 161 if (crypt::hmac(DC_MASTER_KEY,$rs->user_pwd) != $pwd) { 162 162 return false; 163 163 } 164 164 165 165 $permissions = $core->getBlogPermissions($core->blog->id); 166 166 167 167 if ( empty($permissions[$rs->user_id]) ) { 168 168 return false; 169 169 } 170 170 171 171 return $rs->user_id; 172 172 } 173 173 174 174 public static function purgeOldSpam($core) 175 175 { … … 177 177 $defaultModerationTTL = '7'; 178 178 $init = false; 179 179 180 180 // settings 181 181 $core->blog->settings->addNamespace('antispam'); 182 182 183 183 $dateLastPurge = $core->blog->settings->antispam->antispam_date_last_purge; 184 184 if ($dateLastPurge === null) { … … 192 192 $moderationTTL = $defaultModerationTTL; 193 193 } 194 194 195 195 if ($moderationTTL < 0) { 196 196 // disabled 197 197 return; 198 198 } 199 199 200 200 // we call the purge every day 201 201 if ((time()-$dateLastPurge) > (86400)) { … … 203 203 if (!$init) { 204 204 $core->blog->settings->antispam->put('antispam_date_last_purge',time(),null,null,true,false); 205 } 205 } 206 206 $date = date('Y-m-d H:i:s', time() - $moderationTTL*86400); 207 207 dcAntispam::delAllSpam($core, $date); … … 209 209 } 210 210 } 211 ?>
Note: See TracChangeset
for help on using the changeset viewer.