Assembla home | Assembla project page
 

Changeset 242

Show
Ignore:
Timestamp:
04/14/08 23:59:18 (7 months ago)
Author:
Slynderdale
Message:

Fixed a couple tiny bugs in Dice and PHP

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/Dice.php

    r234 r242  
    6060                $expr = substr($expr, $ptr); 
    6161                $ptr = 0; 
    62             // Opening parenthesis 
    63             } 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 parenthesis 
    72             } 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; 
    8062            // Parse error if we've consumed the entire equation without finding anything valid 
    8163            } elseif ($ptr >= strlen($expr)) { 
     
    11799                $bonus = 0; 
    118100                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); 
    120102                    $bonus = $this->processExpression($expression); 
    121103                    if (is_null($bonus)) { 
    122                         return ($recursive ? 0 : 'Error while processing the dice expression.'); 
     104                        return ($recursive ? null : 'Error while processing the dice expression.'); 
    123105                    } 
    124106                } 
  • trunk/Phergie/Plugin/Php.php

    r240 r242  
    4444    private function decode($str) 
    4545    { 
    46         $str = str_replace( '—', '-', $str); 
     46        $str = str_replace('—', '-', $str); 
    4747        $str = trim(preg_replace(array('/<[^>]+>/ms', '/\s+/ms'), array( '', ' ' ), $str)); 
    4848        return $this->decodeTranslit($str); 
     
    5858    public function onDoPhp($function) 
    5959    { 
    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)) { 
    6667                  $contents .= $this->decode($m[1]); 
    6768               } 
    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]; 
    7172               } 
    7273               $contents = trim(str_replace(' ,', ',', $contents)); 
     74               unset($tmp, $m); 
    7375            } else { 
    7476                $this->errorStatus = false; 
    75                 $contents = 'Nothing found'
     77                $contents = null
    7678            } 
    77             $this->cache[$function] = $contents; 
     79            $this->cache[$name] = $contents; 
    7880        } 
    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        } 
    8084    } 
    8185