Changeset 136
- Timestamp:
- 03/07/08 03:43:21 (5 years ago)
- Files:
-
- 1 modified
-
trunk/Phergie/Plugin/Karma.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Phergie/Plugin/Karma.php
r135 r136 231 231 $res = $this->fetchKarma->fetch(PDO::FETCH_ASSOC); 232 232 233 // Sanity check if someone if someone prefixed their conversation with karma 234 if (!$res && substr_count($term, ' ') > 1 && !(substr($m[1], 0, 1) === '(' && substr($m[1], -1) === ')')) 235 return; 236 233 237 // Clean the raw term if it was contained within brackets 234 238 if(substr($m[1], 0, 1) === '(' && substr($m[1], -1) === ')') … … 241 245 } 242 246 // Incrementation/decrementation request 243 } elseif (preg_match(' #^('.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$#i', $message, $m)) {244 $word = strtolower($m[ 2]);247 } elseif (preg_match('{^(?:'.$prefix.')?(\S+?|\(.+?\)+)(\+{2,}|-{2,})(?:\s+(.*))?$}i', $message, $m)) { 248 $word = strtolower($m[1]); 245 249 // Strip parenthesis grouping multiple words 246 250 if(substr($word, 0, 1) === '(' && substr($word, -1) === ')') { 247 251 $word = substr($word, 1, -1); 248 252 } else { // Add trailing + or -'s 249 if(strlen($m[ 3]) > 2) {250 $word .= substr($m[ 3], 2);251 $m[ 3] = substr($m[3], -2);253 if(strlen($m[2]) > 2) { 254 $word .= substr($m[2], 2); 255 $m[2] = substr($m[2], -2); 252 256 } 253 257 } … … 260 264 // Force a decrementation if someone tries to update his own karma 261 265 if ($word == strtolower($this->event->getNick())) { 262 $m[ 3] = '--';266 $m[2] = '--'; 263 267 } 264 268 // Antithrottling check … … 279 283 if ($res) { 280 284 $args = array( 281 ':karma' => ($res['karma'] + ($m[ 3]=='++' ? 1 : -1)),285 ':karma' => ($res['karma'] + ($m[2]=='++' ? 1 : -1)), 282 286 ':word' => $word 283 287 ); … … 286 290 $args = array( 287 291 ':word' => $word, 288 ':karma' => ($m[ 3]=='++' ? '1' : '-1')292 ':karma' => ($m[2]=='++' ? '1' : '-1') 289 293 ); 290 294 $this->insertKarma->execute($args); … … 295 299 296 300 // Add comment 297 $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[ 4]);301 $comment = preg_replace('{(?:^//(.*)|^#(.*)|^/\*(.*?)\*/$)}', '$1$2$3', $m[3]); 298 302 if (!empty($comment)) { 299 303 $this->insertComment->execute(array(':wordid' => $id, ':comment' => $comment));