Assembla home | Assembla project page
 

Changeset 204

Show
Ignore:
Timestamp:
04/04/08 10:08:19 (8 months ago)
Author:
Slynderdale
Message:

Added various bug fixes, enhancements as well as removed some stay require_once statements.

Notable Changes:

  • Streams: Fixed a Fatal Error due to a typo in doWhois as well as a missing constant. Added an onConnect handler that gets called when Phergie connects to the Irc server. Also added support for invisible mode.
  • Logging: Added support to log private messages sent to the bot, added a new constant for it called query
  • Math: Added more math support by adding more constants and functions to the allowed list
  • Quit: Added restart and reboot commands that creates a new bot process and closes the original one
  • Seen: Added various bug fixes and changed the seen/heard bahavior to search even channel. Also added an -all flag to search for admins to search in private messages as well
  • Toggle: Added supported to save mute/disable statuses through restarts
  • Url: Added better URL checking as well as support for link merging. Basicly multiple links in one emssage can be merged and sent back as one message instead of multiple messages
Files:

Legend:

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

    r203 r204  
    113113* @const string 
    114114*/ 
    115 define('PHERGIE_INI', $ini); 
     115define('PHERGIE_INI', basename($ini)); 
    116116 
    117117/** 
     
    120120* @const string 
    121121*/ 
    122 define('PHERGIE_INI_PATH', PHERGIE_DIR . PHERGIE_INI); 
     122define('PHERGIE_INI_PATH', realpath($ini)); 
    123123 
    124124/** 
     
    131131function phergieAutoLoader($class) { 
    132132    if (strpos(strtolower($class), 'phergie_') === 0) { 
    133         list (, $type, $name) = explode('_', $class, 3); 
     133        list (, $type, $name) = array_pad(explode('_', $class, 3), 3, null); 
    134134        $name = str_replace('_', DIRECTORY_SEPARATOR, $name); 
    135135 
     
    200200        $driver = 'Streams'; 
    201201    } 
    202     require_once PHERGIE_DRIVER_DIR . $driver . '.php'; 
    203202    $class = 'Phergie_Driver_' . $driver; 
    204203    $client = new $class();  
     
    216215    $include = array(); 
    217216    if (!empty($config['plugins']) 
    218         && preg_match('/(all|none)(?: except (.+))?/ADi', $config['plugins'], $match)) { 
    219         $all = $match[1] != 'none'; 
    220         if (isset($match[2])) { 
    221             $include = array_map('strtolower', preg_split('/[, ]+/', $match[2])); 
     217        && preg_match('/(all|none)(?:\s*except\s*(.+))?/ADi', $config['plugins'], $match)) { 
     218        $all = trim(strtolower($match[1])) != 'none'; 
     219        if (!empty($match[2])) { 
     220            $include = array_map('strtolower', preg_split('/[, ]+/', trim($match[2]))); 
    222221        } 
    223222    } 
     
    244243 
    245244    foreach ($plugins as $plugin) { 
    246         require_once PHERGIE_PLUGIN_DIR . $plugin . '.php'; 
    247245        $class = 'Phergie_Plugin_' . $plugin; 
    248246        /** 
  • trunk/Phergie/Driver/Abstract.php

    r203 r204  
    7171    { 
    7272        if (preg_match('/^([^!@]+)!([^@]+)@(.*)$/', $hostmask, $match) > 0) { 
    73             list (, $nick, $user, $host) = $match
     73            list (, $nick, $user, $host) = array_pad($match, 4, null)
    7474        } else { 
    7575            $host = $hostmask; 
     
    125125            echo $message; 
    126126            if ($log = $this->getIni('log') and !empty($log)) { 
    127                 file_put_contents($log, $message, FILE_APPEND); 
     127                file_put_contents(realpath($log), $message, FILE_APPEND); 
    128128            } 
    129129        } 
     
    167167                foreach ($iterator as $filename) { 
    168168                        if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') { 
    169                                 $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php')); 
     169                                $plugins[] = ($preserveExt ? (string) $filename : basename($filename, '.php')); 
    170170                        } 
    171171                } 
  • trunk/Phergie/Driver/Streams.php

    r203 r204  
    11<?php 
    2  
    3 /** 
    4 * @see Phergie_Driver_Abstract 
    5 */ 
    6 require_once PHERGIE_DRIVER_DIR.'Abstract.php'; 
    72 
    83/** 
     
    153148        unset($server, $params); 
    154149 
     150        if ($this->getIni('invisible')) { 
     151            $this->doMode($this->getIni('nick'), '+i'); 
     152        } 
     153 
    155154        $ignore = $this->hostmasksToRegex($this->getIni('ignore')); 
     155 
     156        // Run the onConnect handler since we successfully connected to the server 
     157        foreach ($this->plugins as $plugin) { 
     158            $plugin->onConnect(); 
     159        } 
    156160 
    157161        while(true) { 
     
    159163            $this->queueing = true; 
    160164 
    161             $buffer = ''
    162             while (empty ($buffer)) { 
     165            $buffer = null
     166            while (empty($buffer)) { 
    163167                $buffer = fgets($this->socket, 512); 
    164168 
     
    179183                        } 
    180184            } 
     185            if (!isset($buffer) || empty($buffer)) { 
     186                continue; 
     187            } 
    181188            $buffer = rtrim($buffer); 
    182189            $this->debug('<- ' . $buffer); 
    183190 
    184             if ($buffer[0] == ':') { 
    185                 list ($prefix, $cmd, $args) = explode(' ', substr($buffer, 1), 3); 
     191            if (substr($buffer, 0, 1) == ':') { 
     192                list ($prefix, $cmd, $args) = array_pad(explode(' ', substr($buffer, 1), 3), 3, null); 
    186193                $this->parseHostmask($prefix, $nick, $user, $host); 
    187194            } else { 
    188                 list ($cmd, $args) = explode(' ', $buffer, 2); 
     195                list ($cmd, $args) = array_pad(explode(' ', $buffer, 2), 2, null); 
    189196            } 
    190197 
     
    203210                    if(substr($temp[1], 0, 1) === chr(1) && substr($temp[1], -1) === chr(1)) { 
    204211                        $ctcp = trim(substr($temp[1], 1, -1)); 
    205                         list ($cmd, $args) = explode(' ', $ctcp.' ', 2); 
     212                        list ($cmd, $args) = array_pad(explode(' ', $ctcp, 2), 2, null); 
    206213                        $cmd = strtolower($cmd); 
    207214 
     
    240247                    if(substr($temp[1], 0, 1) === chr(1) && substr($temp[1], -1) === chr(1)) { 
    241248                        $ctcp = trim(substr($temp[1], 1, -1)); 
    242                         list ($cmd, $args) = explode(' ', $ctcp.' ', 2); 
     249                        list ($cmd, $args) = array_pad(explode(' ', $ctcp, 2), 2, null); 
    243250                        $cmd = strtolower($cmd); 
    244251 
     
    496503    public function doWhois($nick) 
    497504    { 
    498         $this->send(Phergie_Event_Requset::TYPE_WHOIS, array($nick)); 
     505        $this->send(Phergie_Event_Request::TYPE_WHOIS, array($nick)); 
    499506    } 
    500507 
  • trunk/Phergie/Event/Request.php

    r194 r204  
    1414    */ 
    1515    const TYPE_NICK = 'nick'; 
     16 
     17    /** 
     18    * Whois message 
     19    * 
     20    * @const string 
     21    */ 
     22    const TYPE_WHOIS = 'whois'; 
    1623 
    1724    /** 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r203 r204  
    431431 
    432432        if ($time > 0 || count($return) <= 0) { 
    433                 $return[] = $time . 's'; 
     433                $return[] = ($time > 0 ? $time : '0') . 's'; 
    434434        } 
    435435 
     
    725725 
    726726    /** 
     727    * Handler for when the bot connects to the server 
     728    * 
     729    * @return void 
     730    */ 
     731    public function onConnect() { } 
     732 
     733    /** 
     734    * Handler for each iteration of the while loop while connected to the 
     735    * server 
     736    * 
     737    * @return void 
     738    */ 
     739    public function onTick() { } 
     740 
     741    /** 
    727742    * Handler for when PHP throws an error 
    728743    * 
     
    745760        $source = null; 
    746761        if (isset($arguments[0])) { 
    747             $source = trim($arguments[0]); 
    748         } 
    749         if (((isset($source) && isset($this->muted[$source]) && $this->muted[$source]) || 
     762            $source = trim(strtolower($arguments[0])); 
     763        } 
     764        if (((!empty($source) && isset($this->muted[$source]) && $this->muted[$source]) || 
    750765            (isset($this->muted['global']) && $this->muted['global'])) && 
    751766            substr($method, 0, 2) === 'do') { 
  • trunk/Phergie/Plugin/Ctcp.php

    r200 r204  
    5959            $name = $this->getIni('nick'); 
    6060            $realname = $this->getIni('realname'); 
     61            $username = $this->getIni('username'); 
    6162 
    62             $finger = 'Realname: '.(!empty($realname) ? $realname: $name); 
     63            $finger = (!empty($realname) ? $realname: $name) . 
     64                      ' ('.(!empty($username) ? $username: $name) . ')'; 
    6365            $this->doCtcpReply($source, 'finger', $finger); 
    6466        } 
  • trunk/Phergie/Plugin/Dice.php

    r203 r204  
    6969            } elseif ($substr === ')') { 
    7070                $out .= $substr; 
     71                $next = substr($expr, 1, $ptr+1); 
     72                if (!empty($next) && !in_array($next, array('+', '-', '/', '*', ')'))) { 
     73                    $out .= '*'; 
     74                } 
    7175                $expr = substr($expr, $ptr); 
    7276                $ptr = 0; 
     
    170174        $source = $this->event->getSource(); 
    171175        $ctcp = strtoupper($this->event->getArgument(1)); 
    172         list($ctcp, $message) = explode(' ', $ctcp.' ', 2); 
     176        list($ctcp, $message) = array_pad(explode(' ', $ctcp, 2), 2, null); 
    173177 
    174178        if (($ctcp == 'DICE' || $ctcp == 'ROLL') and $result =  $this->processDice($message)) { 
  • trunk/Phergie/Plugin/Drink.php

    r203 r204  
    353353 
    354354    /** 
     355    * Alias to Beer 
     356    * 
     357    * @param string $target Target for the request 
     358    * @return void 
     359    */ 
     360    public function onDoBooze($target) 
     361    { 
     362        $this->throwDrink('beer', $target); 
     363    } 
     364 
     365    /** 
    355366    * Handles cocktail requests. 
    356367    * 
  • trunk/Phergie/Plugin/FeedTicker.php

    r200 r204  
    164164    { 
    165165        if (!empty ($this->queue) && time() > $this->nextOutput) { 
    166             list ($title, $url, $chans, $feedTitle) = array_shift($this->queue); 
     166            list ($title, $url, $chans, $feedTitle) = array_pad(array_shift($this->queue), 4, null); 
    167167            foreach ($chans as $chan) { 
    168168                $this->doPrivmsg( 
     
    208208        // Retrieve each feed 
    209209        foreach ($this->feeds as $id => $feed) { 
    210             list ($url, $chans) = $feed
     210            list ($url, $chans) = array_pad($feed, 2, null)
    211211 
    212212            $content = @file_get_contents($url, null, $context); 
     
    218218            try { 
    219219                // RSS/RDF Feed 
    220                 if (strpos($content, '<rss version=') !== false || strpos($content, '<rdf') !== false) { 
     220                if (stripos($content, '<rss version=') !== false || stripos($content, '<rdf') !== false) { 
    221221                    $xml = new SimpleXMLElement($content); 
    222222                    $feedTitle = (string) $xml->channel->title; 
     
    224224                        $retrieved[$id][] = array((string) $item->title, (string) $item->link, $chans, $feedTitle); 
    225225                    } 
    226                 } elseif(strpos($content, '/Atom') !== false) { // ATOM Feed 
     226                } elseif(stripos($content, '/Atom') !== false) { // ATOM Feed 
    227227                    $xml = new SimpleXMLElement($content); 
    228228                    $feedTitle = (string) $xml->title; 
  • trunk/Phergie/Plugin/Karma.php

    r203 r204  
    6161    protected $negativeAnswers; 
    6262 
    63     /**#@+ 
     63    /** 
    6464     * Prepared PDO statements 
    6565     * 
     
    7070    protected $fetchKarma; 
    7171    protected $insertComment; 
    72     /**#@-*/ 
    7372 
    7473    /** 
     
    9291 
    9392        $this->fixedKarma = array ( 
    94             'phergie' => '%s has karma of awesome', 
    95             'pi' => 'pi has karma of ' . M_PI, 
    96             'chucknorris' => '%s has karma of Warning: Integer out of range', 
     93            'phergie'      => '%s has karma of awesome', 
     94            'pi'           => '%s has karma of ' . M_PI, 
     95            'Π'            => '%s has karma of ' . M_PI, 
     96            'π'            => '%s has karma of ' . M_PI, 
     97            'chucknorris'  => '%s has karma of Warning: Integer out of range', 
    9798            'chuck norris' => '%s has karma of Warning: Integer out of range', 
    98             'c' => '%s has karma of 299 792 458 m/s', 
    99             'e' => '%s has karma of ' . M_E, 
    100             'euler' => '%s has karma of ' . M_EULER, 
    101             'mole' => '%s has karma of 6.02214e23 molecules', 
    102             'avogadro' => '%s has karma of 6.02214e23 molecules', 
    103             'spoon' => '%s has no karma. There is no spoon', 
    104             'mc^2' => '%s has karma of e', 
    105             'mc2' => '%s has karma of e', 
    106             'mc²' => '%s has karma of e', 
    107             'i' => 'I haz big karma', 
     99            'c'            => '%s has karma of 299 792 458 m/s', 
     100            'e'            => '%s has karma of ' . M_E, 
     101            'euler'        => '%s has karma of ' . M_EULER, 
     102            'mole'         => '%s has karma of 6.02214e23 molecules', 
     103            'avogadro'     => '%s has karma of 6.02214e23 molecules', 
     104            'spoon'        => '%s has no karma. There is no spoon', 
     105            'mc^2'         => '%s has karma of e', 
     106            'mc2'          => '%s has karma of e', 
     107            'mc²'          => '%s has karma of e', 
     108            'i'            => '%s haz big karma', 
    108109            'karma' => 'The karma law says that all living creatures are responsible for their karma - their actions and the effects of their actions. You should watch yours.' 
    109110        ); 
     
    282283            $m[3] = (isset($m[5]) ? $m[5] : null); # Comment 
    283284            unset($m[4], $m[5]); 
    284             list(,$sign, $word, $comment) = $m
     285            list(, $sign, $word, $comment) = array_pad($m, 4, null)
    285286 
    286287            // Clean the word 
  • trunk/Phergie/Plugin/Lart.php

    r203 r204  
    346346        } 
    347347 
    348         $adminOnly = $this->getPluginIni('admin_only'); 
    349         if (preg_match('/^(' . $nick . '\s*:?\s+)?lartinfo\s+(.*?)$/i', $message, $match)) { 
    350               if ($this->fromAdmin()) { 
    351                        list (, $address, $name) = $match
    352                       $name = trim(strtolower($name)); 
    353                       if (!empty($name)) { 
    354                               $this->select->execute(array(':name' => $name)); 
    355                               $info = $this->select->fetch(); 
    356                               if ($info && count($info) > 0) { 
    357                                       $name = $info['name']; 
    358                                       $desc = $info['definition']; 
    359                                       $host = (isset($info['hostmask']) ? substr($info['hostmask'], 0, strpos($info['hostmask'], '!')) : 'N/A'); 
    360                                       $time = (isset($info['tstamp']) ? $this->getCountdown(time() -$info['tstamp']) : 'N/A'); 
    361                                       $aliases = $this->getAliases($name, false); 
    362                                       $aliases = (count($aliases) > 0 ? implode(', ', $aliases) : 'N/A'); 
    363  
    364                                       $this->doPrivmsg($this->event->getSource(), 
    365                                       $target . ': Lart Info -> Term: '.$name.' | Definition: '.$desc.' | User: '.$host.' | Added: '.$time.' ago | Aliases: '.$aliases); 
    366                               } else { 
    367                                       $this->doNotice($target, 'Unknown Lart: ' . $name); 
    368                               } 
    369                               unset($info); 
    370                       } 
    371               } else { 
    372                       $this->doNotice($target, 'You do not have permission to view the lart info.'); 
    373             } 
    374         } else if (preg_match('/^(' . $nick . '\s*:?\s+)?(.*?)\s+is\s+(.*)$/i', $message, $match)) { 
    375             list (, $address, $name, $definition) = $match
    376               if (!empty($name) && !empty($definition) && (empty($address) xor $source[0] == '#')) { 
    377                   if (!$adminOnly || $this->fromAdmin()) { 
    378                               $name = trim($name); 
    379                               $definition = trim($definition); 
    380  
    381                               $this->debug('Replacing term: ' . $name . ' = ' . $definition); 
    382                               $this->replace->execute(array(':name' => $name, ':definition' => $definition, ':hostmask' => $hostmask, ':tstamp' => $timenow)); 
    383                               $this->doNotice($target, 'Added lart "'. $name . '".'); 
    384                               $this->cache[$name] = $definition; 
    385                   } else { 
    386                           $this->doNotice($target, 'You do not have permission to add larts.'); 
    387                 } 
    388             } 
    389         } else if (preg_match('/^(' . $nick . '\s*:?\s+)?forget\s+(.*)$/i', $message, $match)) { 
    390               if (!$adminOnly || $this->fromAdmin()) { 
    391                        list (, $address, $name) = $match
    392                       if (!empty($name) && (empty($address) xor $source[0] == '#')) { 
    393                               $name = trim(strtolower($name)); 
    394                               $this->deleteLart($name); 
    395                               $this->doNotice($target, 'Removed lart "'. $name . '" and all its alises.'); 
    396                       } 
    397               } else { 
    398                       $this->doNotice($target, 'You do not have permission to remove larts.'); 
    399             } 
    400         } else { 
    401               $this->checkLart($message); 
    402        
     348       $adminOnly = $this->getPluginIni('admin_only'); 
     349       if (preg_match('/^(' . $nick . '\s*:?\s+)?lartinfo\s+(.*?)$/i', $message, $match)) { 
     350              if ($this->fromAdmin()) { 
     351                       list (, $address, $name) = array_pad($match, 3, null)
     352                      $name = trim(strtolower($name)); 
     353                      if (!empty($name)) { 
     354                              $this->select->execute(array(':name' => $name)); 
     355                              $info = $this->select->fetch(); 
     356                              if ($info && count($info) > 0) { 
     357                                      $name = $info['name']; 
     358                                      $desc = $info['definition']; 
     359                                      $host = (isset($info['hostmask']) ? substr($info['hostmask'], 0, strpos($info['hostmask'], '!')) : 'N/A'); 
     360                                      $time = (isset($info['tstamp']) ? $this->getCountdown(time() -$info['tstamp']) : 'N/A'); 
     361                                      $aliases = $this->getAliases($name, false); 
     362                                      $aliases = (count($aliases) > 0 ? implode(', ', $aliases) : 'N/A'); 
     363 
     364                                      $this->doPrivmsg($this->event->getSource(), 
     365                                      $target . ': Lart Info -> Term: '.$name.' | Definition: '.$desc.' | User: '.$host.' | Added: '.$time.' ago | Aliases: '.$aliases); 
     366                              } else { 
     367                                      $this->doNotice($target, 'Unknown Lart: ' . $name); 
     368                              } 
     369                              unset($info); 
     370                      } 
     371              } else { 
     372                      $this->doNotice($target, 'You do not have permission to view the lart info.'); 
     373           } 
     374       } else if (preg_match('/^(' . $nick . '\s*:?\s+)?(.*?)\s+is\s+(.*)$/i', $message, $match)) { 
     375           list (, $address, $name, $definition) = array_pad($match, 4, null)
     376              if (!empty($name) && !empty($definition) && (empty($address) xor $source[0] == '#')) { 
     377                  if (!$adminOnly || $this->fromAdmin()) { 
     378                              $name = trim($name); 
     379                              $definition = trim($definition); 
     380 
     381                              $this->debug('Replacing term: ' . $name . ' = ' . $definition); 
     382                              $this->replace->execute(array(':name' => $name, ':definition' => $definition, ':hostmask' => $hostmask, ':tstamp' => $timenow)); 
     383                              $this->doNotice($target, 'Added lart "'. $name . '".'); 
     384                              $this->cache[$name] = $definition; 
     385                  } else { 
     386                          $this->doNotice($target, 'You do not have permission to add larts.'); 
     387               } 
     388           } 
     389       } else if (preg_match('/^(' . $nick . '\s*:?\s+)?forget\s+(.*)$/i', $message, $match)) { 
     390              if (!$adminOnly || $this->fromAdmin()) { 
     391                       list (, $address, $name) = array_pad($match, 3, null)
     392                      if (!empty($name) && (empty($address) xor $source[0] == '#')) { 
     393                              $name = trim(strtolower($name)); 
     394                              $this->deleteLart($name); 
     395                              $this->doNotice($target, 'Removed lart "'. $name . '" and all its alises.'); 
     396                      } 
     397              } else { 
     398                      $this->doNotice($target, 'You do not have permission to remove larts.'); 
     399           } 
     400       } else { 
     401              $this->checkLart($message); 
     402       
    403403    } 
    404404 
  • trunk/Phergie/Plugin/Logging.php

    r203 r204  
    8383    */ 
    8484    const TOPIC = 9; 
     85 
     86    /** 
     87    * Indicates a QUERY event in the type column of the logs table 
     88    * This indicates that the message type is a PM 
     89    * 
     90    * @const int 
     91    */ 
     92    const QUERY = 10; 
    8593 
    8694    /** 
     
    212220        parent::onPrivmsg(); 
    213221 
    214         if ($this->event->isInChannel()) { 
    215             $this->insertEvent( 
    216                 self::PRIVMSG, 
    217                 $this->event->getSource(), 
    218                 $this->event->getNick(), 
    219                 $this->event->getArgument(1) 
    220             ); 
    221         } 
     222        $this->insertEvent( 
     223            ($this->event->isInChannel() ? self::PRIVMSG : self::QUERY), 
     224            $this->event->getSource(), 
     225            $this->event->getNick(), 
     226            $this->event->getArgument(1) 
     227        ); 
    222228    } 
    223229 
     
    352358 
    353359    public static function databaseExists() { 
    354         return (self::$db ? true : false); 
     360        return (is_object(self::$db) ? true : false); 
    355361    } 
    356362 
  • trunk/Phergie/Plugin/Math.php

    r200 r204  
    99{ 
    1010    /** 
     11    * Backwards compatibility for constants not defined in PHP 5.1.x 
     12    */ 
     13    public function init() 
     14    { 
     15        if (version_compare('5.2', PHP_VERSION, '>')) { 
     16            define('M_EULER', '0.57721566490153286061'); 
     17            define('M_LNPI', '1.14472988584940017414'); 
     18            define('M_SQRT3', '1.73205080756887729352'); 
     19            define('M_SQRTPI', '1.77245385090551602729'); 
     20        } 
     21    } 
     22 
     23    /** 
    1124    * Holds the allowed function, characters, operators and constants 
    1225    * 
     
    1932        'abs(', 'ceil(', 'floor(', 'exp(', 
    2033        'log10(', 
    21         'cos(', 'sin(', 'sqrt(', 'tan(', 
    22         'M_PI', 'INF', 'M_E', 
     34        'cos(', 'sin(', 'sqrt(', 'tan(', 'rad2deg(', 
     35        'acosh(', 'asin(', 'atan(', 'atanh(', 'cosh(', 
     36        'sinh(', 'tanh(', 'hexdec(', 'decoct(', 'dechex(', 
     37        'decbin(', 'bindec(', 'ord(', 'chr(', 
     38        'M_PI', 'INF', 'M_E', 'M_LOG2E', 'M_LOG10E', 
     39        'M_LN2', 'M_LN10', 'M_PI_2', 'M_PI_4', 'M_1_PI', 
     40        'M_2_PI', 'M_SQRTPI', 'M_2_SQRTPI', 'M_SQRT2', 
     41        'M_SQRT2', 'M_SQRT1_2', 'M_LNPI', 'M_EULER' 
     42    ); 
     43 
     44    /** 
     45    * Holds the functions that are allowed that are contained in the class 
     46    * 
     47    * @return void 
     48    */ 
     49    protected $classFuncs = array 
     50    ( 
     51        'sind(', 'cosd(', 'tand(', 
     52        'atand(', 'asind(', 'acosd(' 
    2353    ); 
    2454 
     
    3262        'round(', 'log(', 'pow(', 
    3363        'max(', 'min(', 'rand(', 
     64        'atan2(', 'mt_rand(', 
     65        'base_convert(' 
    3466    ); 
    3567 
    3668    /** 
     69    * Custom functions as defined in $classFuncs to be used in math operations 
     70    * these automatically get prepended with $this-> before the calculations 
     71    * take place. 
     72    */ 
     73    //return sine of <an angle in degrees> 
     74    protected function sind($degrees) { 
     75        return sin(deg2rad($degrees)); 
     76    } 
     77    //return cosd of <an angle in degrees> 
     78    protected function cosd($degrees) { 
     79        return cos(deg2rad($degrees)); 
     80    } 
     81    //return tand of <an angle in degrees> 
     82    protected function tand($degrees) { 
     83        return tan(deg2rad($degrees)); 
     84    } 
     85    //return atand of <an angle in degrees> 
     86    protected function atand($x) { 
     87        return rad2deg(atan($x)); 
     88    } 
     89    //return asind of <an angle in degrees> 
     90    protected function asind($x) { 
     91        return rad2deg(asin($x)); 
     92    } 
     93    //return acosd of <an angle in degrees> 
     94    protected function acosd($x) { 
     95        return rad2deg(acos($x)); 
     96    } 
     97 
     98    /** 
    3799    * Processes a request to perform a calculations. 
    38100    * 
     
    40102    * @return void 
    41103    */ 
    42     protected function processRequest($expr
     104    protected function processRequest($expr, $quietMode = false
    43105    { 
    44106        $user = $this->event->getNick(); 
     
    51113        ); 
    52114        $equationSrc = $equation; 
     115        $this->allowed = array_merge($this->allowed, $this->classFuncs); 
    53116 
    54117        // Parse equation 
     
    94157 
    95158                $out .= $substr; 
     159                $next = substr($equation, 1, $ptr+1); 
     160                if (!empty($next) && !in_array($next, array('+', '-', '/', '*', ')'))) { 
     161                    $out .= '*'; 
     162                } 
    96163                $equation = substr($equation, $ptr); 
    97164                $ptr = 0; 
    98165            // Parse error if we've consumed the entire equation without finding anything valid 
    99166            } elseif ($ptr >= strlen($equation)) { 
    100                 $this->doNotice($user, 'Syntax error at "' . $substr . '" in equation "' . $equationSrc . '"'); 
     167                if (!$quietMode) { 
     168                    $this->doNotice($user, 'Syntax error at "' . $substr . '" in equation "' . $equationSrc . '"'); 
     169                } 
    101170                return; 
    102171            } else { 
     
    104173            } 
    105174        } 
     175 
     176        foreach ($this->classFuncs as $func) { 
     177            $out = str_replace($func, '$this->' . $func, $out); 
     178        } 
     179 
    106180        $res = @eval('return ' . $out . ';'); 
    107181        $source = $this->event->getSource(); 
    108182        if($res === false) { 
    109             $this->doNotice($user, 'Computation error, division by zero?'); 
     183            if (!$quietMode) { 
     184                $this->doNotice($user, 'Computation error, division by zero?'); 
     185            } 
    110186        } else { 
    111             $this->doPrivmsg($source, $res); 
     187            $this->doPrivmsg($source, $user .': Result -> ' . $res); 
    112188        } 
    113189    } 
     
    120196    public function onDoMath($expr) 
    121197    { 
     198        $this->processRequest($expr, true); 
     199    } 
     200 
     201    /** 
     202    * Forwards calc commands onto a central handler. 
     203    * 
     204    * @return void 
     205    */ 
     206    public function onDoCalc($expr) 
     207    { 
    122208        $this->processRequest($expr); 
    123209    } 
    124  
    125     /** 
    126     * Forwards calc commands onto a central handler. 
    127     * 
    128     * @return void 
    129     */ 
    130     public function onDoCalc($expr) 
    131     { 
    132         $this->processRequest($expr); 
    133     } 
    134210} 
  • trunk/Phergie/Plugin/ModuleList.php

    r203 r204  
    9696 
    9797                    // Checks to see if the plugin is a muted plugin or not 
    98                     if ((isset($data->muted[$target]) && $data->muted[$target]) || 
    99                         (isset($data->muted['global']) && $data->muted['global'])) { 
    100                         $pluginData['Muted'][] = $plugin . ($data->muted['global'] ? '*' : ''); 
    101                         if ($data->muted['global']) { 
    102                                 $pluginData['Global_Muted'][] = $plugin; 
    103                         } 
    104                         if ($data->muted[$target]) { 
    105                             $pluginData['Local_Muted'][] = $plugin; 
    106                         } 
     98                    if (!empty($data->muted[$target]) || !empty($data->muted['global'])) { 
     99                            $pluginData['Muted'][] = $plugin . (!empty($data->muted['global']) ? '*' : ''); 
     100                            if (!empty($data->muted['global'])) { 
     101                                $pluginData['Global_Muted'][] = $plugin; 
     102                            } 
     103                            if (!empty($data->muted[$target])) { 
     104                                    $pluginData['Local_Muted'][] = $plugin; 
     105                            } 
    107106                    } else { 
    108107                        $pluginData['Unmuted'][] = $plugin; 
     
    131130                // Extended/Verbose plugins list that shows every plugin and their state 
    132131                $state = null; 
    133                 if ($args['v'] && is_array($pluginData)) { 
     132                if (isset($args['v']) && is_array($pluginData)) { 
    134133                    foreach ($this->verboseList as $key => $value) { 
    135134                        if (isset($pluginData[$key]) and is_array($pluginData[$key]) && 
     
    147146        // Go through the list of any passed arugments and generate the plugin list for them 
    148147        $message = null; 
    149         if (!$args['v'] && is_array($args) && count($args) > 0) { 
     148        if (!isset($args['v']) && is_array($args) && count($args) > 0) { 
    150149            foreach($args as $arg => $value) { 
    151150                $plugin = $this->argList[$arg]; 
     
    163162        // If the message is empty, aka no args were passed, return the full plugin list 
    164163        if (empty($message)) { 
    165             $display = ($args['v'] ? 'Verbose' : 'Plugins'); 
     164            $display = (isset($args['v']) ? 'Verbose' : 'Plugins'); 
    166165            if (is_array($pluginData[$display])) { 
    167166                sort($pluginData[$display]); 
  • trunk/Phergie/Plugin/Quit.php

    r203 r204  
    88{ 
    99    /** 
    10     * Flag indicating whether or not the plugin is an admin plugin or not 
    11    
    12     * @var bool 
    13     */ 
     10    * Flag indicating whether or not the plugin is an admin plugin or not 
     11   
     12    * @var bool 
     13    */ 
    1414    public $needsAdmin = true; 
    1515 
    1616    /** 
    17     * Random reconnect messages used if a quit message isn't given 
    18    
    19     * @var array 
    20     */ 
     17    * Random reconnect messages used if a quit message isn't given 
     18   
     19    * @var array 
     20    */ 
    2121    protected $messages = array 
    2222    ( 
     
    2929 
    3030    /** 
     31    * Path to the PHP executable file 
     32    * 
     33    * @var string 
     34    */ 
     35    protected $phpPath; 
     36 
     37    /** 
     38    * Attempts to auto-detect the path to the PHP executable if the path isn't 
     39    * set in the setting file 
     40    * 
     41    * @return void 
     42    */ 
     43    public function init() 
     44    { 
     45        $phpPath = trim($this->getPluginIni('php_path')); 
     46        if (empty($phpPath) || !is_file($phpPath) || 
     47            strtolower($phpPath) == 'autodetect' || strtolower($phpPath) == 'auto-detect') { 
     48            /** 
     49            * Array of file names to check for when auto-detecting the path to PHP 
     50            */ 
     51            $files = array( 
     52                'php', 
     53                'php.exe', 
     54                'php-win.exe' 
     55            ); 
     56 
     57            /** 
     58            * Array of file paths to check for the PHP executable 
     59            */ 
     60            $paths = array(); 
     61            if (strtolower(substr(PHP_OS, 0, 3)) === 'win') { 
     62                $paths = array_merge($paths, explode(';', ini_get('include_path'))); 
     63                $paths = array_merge($paths, explode(';', ini_get('extension_dir'))); 
     64            } else { 
     65                $paths = array_merge($paths, explode(':', ini_get('include_path'))); 
     66                $paths = array_merge($paths, explode(':', ini_get('extension_dir'))); 
     67            } 
     68 
     69            if (!empty($phpPath) && 
     70                strtolower($phpPath) != 'autodetect' && strtolower($phpPath) != 'auto-detect') { 
     71                $files[] = $phpPath; 
     72                $paths[] = $phpPath; 
     73            } 
     74 
     75            /** 
     76            * Attempt to auto-detect the path to the PHP executable from the list of file names and paths