Changeset 242
- Timestamp:
- 04/14/08 23:59:18 (7 months ago)
- Files:
-
- trunk/Phergie/Plugin/Dice.php (modified) (2 diffs)
- trunk/Phergie/Plugin/Php.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Plugin/Dice.php
r234 r242 60 60 $expr = substr($expr, $ptr); 61 61 $ptr = 0; 62 // Opening parenthesis63 } elseif ($substr === '(') {64 $last = substr($out, -1);65 if (!empty($last) && !in_array($last, array('+', '-', '/', '*', '('))) {66 $out .= '*';67 }68 $out .= $substr;69 $expr = substr($expr, $ptr);70 $ptr = 0;71 // Closing parenthesis72 } elseif ($substr === ')') {73 $out .= $substr;74 $next = substr($equation, 1, 1);75 if (!empty($next) && !in_array($next, array('+', '-', '/', '*', ')'))) {76 $out .= '*';77 }78 $expr = substr($expr, $ptr);79 $ptr = 0;80 62 // Parse error if we've consumed the entire equation without finding anything valid 81 63 } elseif ($ptr >= strlen($expr)) { … … 117 99 $bonus = 0; 118 100 if (!empty($expression) && $this->allowExpressions) { 119 $expression = preg_replace('/((?:[0-9]+)?d[0-9]+(?:[+\*-][^\s] *)?)/e', '$this->processDice("\\1", true)', $expression);101 $expression = preg_replace('/((?:[0-9]+)?d[0-9]+(?:[+\*-][^\s]+)?)/e', '$this->processDice("\\1", true)', $expression); 120 102 $bonus = $this->processExpression($expression); 121 103 if (is_null($bonus)) { 122 return ($recursive ? 0: 'Error while processing the dice expression.');104 return ($recursive ? null : 'Error while processing the dice expression.'); 123 105 } 124 106 } trunk/Phergie/Plugin/Php.php
r240 r242 44 44 private function decode($str) 45 45 { 46 $str = str_replace( '—', '-', $str);46 $str = str_replace('—', '-', $str); 47 47 $str = trim(preg_replace(array('/<[^>]+>/ms', '/\s+/ms'), array( '', ' ' ), $str)); 48 48 return $this->decodeTranslit($str); … … 58 58 public function onDoPhp($function) 59 59 { 60 if (!isset($this->cache[$function])) { 61 $name = str_replace(array('_', ' '), '-', $function); 62 $tmp = file_get_contents('http://php.net/manual/en/function.' . rtrim($name, '();') . '.php'); 63 if(!$this->errorStatus && strpos($tmp, '<p class="refpurpose dc-title">') !== false) { 64 $contents = '[ '.$this->tinyUrl('http://php.net/'.$name).' ] '; 65 if (preg_match( '/<div class="methodsynopsis dc-description">(.*?)<\/div>/mis', $tmp, $m)) { 60 $name = preg_replace(array( '/[\s\(\);]*$/', '/\s+/', '/_/', '/\s/'), array('', ' ', '-', '-'), $function); 61 $name = trim(strtolower($name)); 62 if (!isset($this->cache[$name])) { 63 $tmp = file_get_contents('http://php.net/manual/en/function.' . $name . '.php'); 64 if (!$this->errorStatus && strpos($tmp, '<p class="refpurpose dc-title">') !== false) { 65 $contents = '[ ' . $this->tinyUrl('http://php.net/' . $name) . ' ] '; 66 if (preg_match('/<div class="methodsynopsis dc-description">(.*?)<\/div>/mis', $tmp, $m)) { 66 67 $contents .= $this->decode($m[1]); 67 68 } 68 if (preg_match( '/<p class="refpurpose dc-title">(.*?)<\/p>/mis', $tmp, $m)) {69 $m = explode( '-', $this->decode($m[1]), 2);70 $contents .= ' - ' .$m[1];69 if (preg_match('/<p class="refpurpose dc-title">(.*?)<\/p>/mis', $tmp, $m)) { 70 $m = explode('-', $this->decode($m[1]), 2); 71 $contents .= ' - ' . $m[1]; 71 72 } 72 73 $contents = trim(str_replace(' ,', ',', $contents)); 74 unset($tmp, $m); 73 75 } else { 74 76 $this->errorStatus = false; 75 $contents = 'Nothing found';77 $contents = null; 76 78 } 77 $this->cache[$ function] = $contents;79 $this->cache[$name] = $contents; 78 80 } 79 $this->doPrivmsg($this->event->getSource(), $this->cache[$function]); 81 if (!empty($this->cache[$name])) { 82 $this->doPrivmsg($this->event->getSource(), $this->cache[$name]); 83 } 80 84 } 81 85