Assembla home | Assembla project page
 

Changeset 200

Show
Ignore:
Timestamp:
03/31/08 03:49:48 (8 months ago)
Author:
tobias382
Message:

* Change: Modified phergie.ini to default debug to true and log to null
* Change: Modified the bootstrap file to use E_STRICT error reporting
* Change: Removed explicit require statements from all files in favor of the autoloader in the bootstrap
* Cleanup: Moved constant declarations added for PHP 5.1.x compatibility from the bootstrap to the Karma plugin
* Cleanup: Optimized multiple areas of the bootstrap file
* Cleanup: Renamed onPHPError to onPhpError in the base plugin class
* Cleanup: Replaced tabs with spaces in multiple files
* Fix: Updated multiple files for E_STRICT compliance
* Fix: Patched the regular expression in the Sed plugin (thanks Slynderdale)

Files:

Legend:

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

    r191 r200  
    1010* Check to see if the version of PHP meets the minimun requirement 
    1111*/ 
    12 if (version_compare("5.1.2", PHP_VERSION, '>')) { 
    13     trigger_error('Fatal Error: Invalid version of PHP! You\'re using PHP ' . PHP_VERSION . ' while PHP version 5.1+ is required to run Phergie.', E_USER_ERROR); 
    14 
     12if (version_compare('5.1.2', PHP_VERSION, '>')) { 
     13    trigger_error('Fatal error: PHP 5.1.2+ is required, current version: ' . PHP_VERSION, E_USER_ERROR); 
    1514 
    1615/** 
    1716* Backwards compatibility check to see if the PHP version is lower than 5.2 
    1817*/ 
    19 if (version_compare("5.2", PHP_VERSION, '>')) { 
    20         $constants = array( 
    21             'M_EULER' => '0.57721566490153286061', 
    22         'M_LNPI' => '1.14472988584940017414', 
    23         'M_SQRT3' => '1.73205080756887729352', 
    24         'M_SQRTPI' => '1.77245385090551602729' 
    25         ); 
    26         foreach($constants as $constant => $value) { 
    27                 if (!defined($constant)) { 
    28                         define($constant, $value); 
    29                 } 
    30         } 
    31         unset($constants, $constant, $value); 
    32  
    33     trigger_error('Warning: PHP version is ' . PHP_VERSION . '. PHP version 5.2+ is recommended to run Phergie.', E_USER_WARNING); 
    34 
    35  
    36 /** 
    37 * If this file is being included rather than executed, just terminate 
    38 */ 
    39 if ($_SERVER['SCRIPT_NAME'] == __FILE__) { 
    40     return; 
     18} elseif (version_compare('5.2', PHP_VERSION, '>')) { 
     19    trigger_error('Warning: PHP 5.2+ is recommended, current version: ' . PHP_VERSION, E_USER_WARNING); 
    4120} 
    4221 
     
    5736 
    5837/** 
    59 * Short name for DIRECTORY_SEPARATOR 
    60 * 
    61 * @const string 
    62 */ 
    63 define('DS', DIRECTORY_SEPARATOR); 
    64  
    65 /** 
    6638* Path to the directory containing the Phergie directory 
    6739* 
    6840* @const string 
    6941*/ 
    70 define('PHERGIE_DIR', dirname(__FILE__) . DS); 
    71  
    72 /** 
    73 * Path to the directory containing the Plugin file
    74 * 
    75 * @const string 
    76 */ 
    77 define('PHERGIE_PLUGIN_DIR', PHERGIE_DIR . 'Plugin' . DS); 
    78  
    79 /** 
    80 * Path to the directory containing the Util files 
    81 * 
    82 * @const string 
    83 */ 
    84 define('PHERGIE_UTIL_DIR', PHERGIE_DIR . 'Util' . DS); 
    85  
    86 /** 
    87 * Path to the directory containing the Driver file
    88 * 
    89 * @const string 
    90 */ 
    91 define('PHERGIE_DRIVER_DIR', PHERGIE_DIR . 'Driver' . DS); 
    92  
    93 /** 
    94 * Path to the directory containing the Event files 
    95 * 
    96 * @const string 
    97 */ 
    98 define('PHERGIE_EVENT_DIR', PHERGIE_DIR . 'Event' . DS); 
     42define('PHERGIE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); 
     43 
     44/** 
     45* Path to the directory containing the plugin
     46* 
     47* @const string 
     48*/ 
     49define('PHERGIE_PLUGIN_DIR', PHERGIE_DIR . 'Plugin' . DIRECTORY_SEPARATOR); 
     50 
     51/** 
     52* Path to the directory containing the utilities 
     53* 
     54* @const string 
     55*/ 
     56define('PHERGIE_UTIL_DIR', PHERGIE_DIR . 'Util' . DIRECTORY_SEPARATOR); 
     57 
     58/** 
     59* Path to the directory containing the driver
     60* 
     61* @const string 
     62*/ 
     63define('PHERGIE_DRIVER_DIR', PHERGIE_DIR . 'Driver' . DIRECTORY_SEPARATOR); 
     64 
     65/** 
     66* Path to the directory containing the event data structures 
     67* 
     68* @const string 
     69*/ 
     70define('PHERGIE_EVENT_DIR', PHERGIE_DIR . 'Event' . DIRECTORY_SEPARATOR); 
    9971 
    10072/** 
     
    11183*/ 
    11284if (strtolower(php_sapi_name()) != 'cli') { 
    113     trigger_error('Phergie is intended to be run using the CLI SAPI for PHP', E_USER_ERROR); 
     85    trigger_error('Phergie requires the CLI SAPI in order to run', E_USER_ERROR); 
    11486} 
    11587 
     
    137109 
    138110/** 
    139 * Name of the configuration file 
     111* Name of the configuration file currently in use 
    140112* 
    141113* @const string 
     
    151123 
    152124/** 
    153 * A class auto loader handler that attempts to find the specified class and 
    154 * load it if it exists else produce a fetal error
    155 * 
    156 * @param string $class The class name to check and attempt to load 
    157 * @return bool Returns true if successful, else produce a fatal error 
     125* Loader to automate inclusion of classes based on directory structure and 
     126* class naming conventions
     127* 
     128* @param string $class Class name to check and attempt to load 
     129* @return void 
    158130*/ 
    159131function phergieAutoLoader($class) { 
    160         if (substr(strtolower($class), 0, 8) == 'phergie_') { 
    161                 list (, $type, $name) = explode('_', $class); 
    162  
    163                 switch (strtolower($type)) { 
    164                         case 'plugin': 
    165                             $file = PHERGIE_PLUGIN_DIR . $name . '.php'; 
    166                         break; 
    167                         case 'util': 
    168                             $file = PHERGIE_UTIL_DIR . $name . '.php'; 
    169                         break; 
    170                 } 
    171  
    172                 if (file_exists($file) && is_readable($file)) { 
    173                     require_once($file); 
    174                     if (class_exists($class)) { 
    175                             return true; 
    176                     } 
    177             } 
    178         } 
    179     trigger_error('Fatal Error: Could not load class "' . $class . '". Class is either invalid, doesn\'t exist or is not supported by Phergie.', E_USER_ERROR); 
    180 
    181 spl_autoload_register("phergieAutoLoader"); 
    182  
    183 /** 
    184  * Start a runtime loop, if the bot disconnects and reconnects it will reload 
    185  * all settings from the ini file, allowing you to modify it without really shutting 
    186  * it down 
    187  */ 
     132    if (strpos(strtolower($class), 'phergie_') === 0) { 
     133        list (, $type, $name) = explode('_', $class, 3); 
     134        $name = str_replace('_', DIRECTORY_SEPARATOR, $name); 
     135 
     136        switch (strtolower($type)) { 
     137            case 'driver': 
     138            case 'event': 
     139            case 'plugin': 
     140            case 'util': 
     141                $file = constant('PHERGIE_' . strtoupper($type) . '_DIR') . $name . '.php'; 
     142                break; 
     143        } 
     144 
     145        if (file_exists($file) && is_readable($file)) { 
     146            require_once($file); 
     147            if (class_exists($class)) { 
     148                return; 
     149            } 
     150        } 
     151    } 
     152    trigger_error('Fatal error: Could not load class "' . $class . '"', E_USER_ERROR); 
     153
     154 
     155spl_autoload_register('phergieAutoLoader'); 
     156 
     157/** 
     158* Start a runtime loop that will reload all settings from the configuration 
     159* file if the bot disconnects and reconnects, allowing for flushing of the 
     160* configuration without a full shutdown of the bot 
     161*/ 
    188162while (true) { 
    189        /** 
    190        * Obtain and validate the contents of the configuration file 
    191        */ 
    192        $required = array('server', 'username', 'nick'); 
    193        $config = parse_ini_file(PHERGIE_INI_PATH); 
    194  
    195        if (count($config) == 0) { 
    196         trigger_error('Fatal Error: Configuration file inaccessible or empty: ' . $ini, E_USER_ERROR); 
    197        
     163    /** 
     164    * Obtain and validate the contents of the configuration file 
     165    */ 
     166    $required = array('server', 'username', 'nick'); 
     167    $config = parse_ini_file(PHERGIE_INI_PATH); 
     168 
     169    if (count($config) == 0) { 
     170        trigger_error('Fatal error: Configuration file inaccessible or empty: ' . $ini, E_USER_ERROR); 
     171   
    198172 
    199173    $missing = array(); 
    200         foreach ($required as $value) { 
    201                 if (empty($config[$value])) { 
    202                 $missing[] = $value; 
    203             } 
    204         } 
    205         if (count($missing) > 0) { 
    206             trigger_error('Fatal Error: Required configuration settings missing: ' . implode(', ', $missing), E_USER_ERROR); 
    207         } 
    208         unset($required, $missing, $value); 
    209  
    210     if (empty($config['autojoin.channels'])) { 
    211         trigger_error('Warning: The setting "autojoin.channels" is empty. Without it, you will have to manually join a channel.', E_USER_WARNING); 
    212     } 
    213  
    214     /** 
    215     * Set the error reporting value to E_ALL (Minus E_STRICT) and display errors in 
    216     * the output if debug mode is enabled. 
     174    foreach ($required as $value) { 
     175        if (empty($config[$value])) { 
     176            $missing[] = $value; 
     177        } 
     178    } 
     179    if (count($missing) > 0) { 
     180        trigger_error('Fatal error: Required configuration settings missing: ' . implode(', ', $missing), E_USER_ERROR); 
     181    } 
     182    unset($required, $missing, $value); 
     183 
     184    /** 
     185    * Set error reporting to display errors if debug mode is enabled 
    217186    */ 
    218187    if ($config['debug']) { 
    219         error_reporting(E_ALL & ~E_STRICT); 
     188        error_reporting(E_ALL | E_STRICT); 
    220189        ini_set('display_errors', true); 
    221190        ini_set('ignore_repeated_errors', true); 
    222191    } 
    223192 
    224         /** 
    225         * Configure the client 
    226         */ 
    227         if (isset($config['driver'])) { 
    228             $driver = ucfirst(strtolower($config['driver'])); 
    229         } else { 
    230             $driver = 'Streams'; 
    231         } 
    232         require_once PHERGIE_DRIVER_DIR . $driver . '.php'; 
    233         $class = 'Phergie_Driver_' . $driver; 
    234         $client = new $class(); 
    235  
    236         foreach ($config as $setting => $value) { 
    237             $client->setIni($setting, $value); 
    238         } 
    239  
    240         unset ($setting, $value, $driver, $class); 
    241  
    242         /** 
    243         * Determine which plugins should be loaded 
    244         */ 
    245         $all = true; 
    246         $include = array(); 
    247         if (!empty($config['plugins']) 
    248             && preg_match('/(all|none)(?: except (.+))?/ADi', $config['plugins'], $match)) { 
    249             $all = $match[1] != 'none'; 
    250             if (isset($match[2])) { 
    251                 $include = array_map('strtolower', preg_split('/[, ]+/', $match[2])); 
    252             } 
    253         } 
    254  
    255         unset ($config); 
    256  
    257         /** 
    258         * Set up plugins 
    259         */ 
    260         $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 
    261         $plugins = array(); 
    262         foreach ($iterator as $entry) { 
    263             if ($iterator->isFile() && pathinfo($entry, PATHINFO_EXTENSION) == 'php') { 
    264                 $name = basename((string) $entry, '.php'); 
    265                 if ($all xor in_array(strtolower($name), $include)) { 
    266                     $plugins[] = $name; 
    267                 } 
    268             } 
    269         } 
    270  
    271         ksort($plugins); 
    272  
    273         unset ($iterator, $entry, $name, $all, $include); 
    274  
    275         foreach ($plugins as $plugin) { 
    276             require_once PHERGIE_PLUGIN_DIR . $plugin . '.php'; 
    277             $class = 'Phergie_Plugin_' . $plugin; 
    278             if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 
    279                 $instance = new $class($client); 
    280                 $client->addPlugin($instance); 
    281             $client->debug('Loaded ' . $plugin); 
    282             } else { 
    283                 $client->debug('Unable to load ' . $plugin); 
    284             } 
    285         } 
    286  
    287         unset ($plugins, $plugin, $class, $instance); 
    288  
    289         /** 
    290         * Execute the event handling loop for the client 
    291         */ 
    292         $state = $client->run(); 
    293         unset($client); 
    294  
    295         switch($state) 
    296         { 
    297                 case Phergie_Driver_Abstract::RETURN_RECONNECT: 
    298                         sleep(1); 
    299                         break; 
    300                 case Phergie_Driver_Abstract::RETURN_KEEPALIVE: 
    301                         sleep(15); 
    302                         break; 
    303                 case Phergie_Driver_Abstract::RETURN_END: 
    304                         break 2; 
    305         } 
    306 
     193    /** 
     194    * Configure the client 
     195    */ 
     196    if (isset($config['driver'])) { 
     197        $driver = ucfirst(strtolower($config['driver'])); 
     198    } 
     199    if (!isset($driver) || !file_exists(PHERGIE_DRIVER_DIR . $driver . '.php')) { 
     200        trigger_error('Driver not specified or not found, defaulting to Streams', E_USER_NOTICE); 
     201        $driver = 'Streams'; 
     202    } 
     203    require_once PHERGIE_DRIVER_DIR . $driver . '.php'; 
     204    $class = 'Phergie_Driver_' . $driver; 
     205    $client = new $class();  
     206 
     207    foreach ($config as $setting => $value) { 
     208        $client->setIni($setting, $value); 
     209    } 
     210 
     211    unset ($setting, $value, $driver, $class); 
     212 
     213    /** 
     214    * Determine which plugins should be loaded 
     215    */ 
     216    $all = true; 
     217    $include = array(); 
     218    if (!empty($config['plugins']) 
     219        && preg_match('/(all|none)(?: except (.+))?/ADi', $config['plugins'], $match)) { 
     220        $all = $match[1] != 'none'; 
     221        if (isset($match[2])) { 
     222            $include = array_map('strtolower', preg_split('/[, ]+/', $match[2])); 
     223        } 
     224    } 
     225 
     226    unset ($config, $match); 
     227 
     228    /** 
     229    * Set up plugins 
     230    */ 
     231    $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 
     232    $plugins = array(); 
     233    foreach ($iterator as $entry) { 
     234        if ($iterator->isFile() && pathinfo($entry, PATHINFO_EXTENSION) == 'php') { 
     235            $name = basename($entry, '.php'); 
     236            if ($all xor in_array(strtolower($name), $include)) { 
     237                $plugins[] = $name; 
     238            } 
     239        } 
     240    } 
     241 
     242    ksort($plugins); 
     243 
     244    unset ($iterator, $entry, $name, $all, $include); 
     245 
     246    foreach ($plugins as $plugin) { 
     247        require_once PHERGIE_PLUGIN_DIR . $plugin . '.php'; 
     248        $class = 'Phergie_Plugin_' . $plugin; 
     249        /** 
     250        * @todo When PHP 5.3 is a stable release, change this to 
     251        *       $class::checkDependencies($client, $plugins); 
     252        */ 
     253        if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 
     254            $instance = new $class($client); 
     255            $client->addPlugin($instance); 
     256            $client->debug('Loaded ' . $plugin); 
     257        } else { 
     258            $client->debug('Unable to load ' . $plugin); 
     259        } 
     260    } 
     261 
     262    unset ($plugins, $plugin, $class, $instance); 
     263 
     264    /** 
     265    * Execute the event handling loop for the client 
     266    */ 
     267    $state = $client->run(); 
     268    unset($client); 
     269 
     270    switch($state) 
     271    { 
     272        case Phergie_Driver_Abstract::RETURN_RECONNECT: 
     273            sleep(1); 
     274            break; 
     275        case Phergie_Driver_Abstract::RETURN_KEEPALIVE: 
     276            sleep(15); 
     277            break; 
     278        case Phergie_Driver_Abstract::RETURN_END: 
     279            break 2; 
     280    } 
     281
  • trunk/Phergie/Driver/Abstract.php

    r199 r200  
    11<?php 
    2  
    3 /** 
    4 * @see Phergie_Plugin_Abstract_Base 
    5 */ 
    6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 
    72 
    83/** 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r199 r200  
    11<?php 
    2  
    3 /** 
    4 * @see Phergie_Driver_Abstract 
    5 */ 
    6 require_once PHERGIE_DRIVER_DIR.'Abstract.php'; 
    7  
    8 /** 
    9 * @see Phergie_Event_Request 
    10 */ 
    11 require_once PHERGIE_EVENT_DIR.'Request.php'; 
    12  
    13 /** 
    14 * @see Phergie_Event_Response 
    15 */ 
    16 require_once PHERGIE_EVENT_DIR.'Response.php'; 
    172 
    183/** 
     
    10287    final public function __construct(Phergie_Driver_Abstract $client) 
    10388    { 
    104        set_error_handler(array(__CLASS__, 'onBaseError')); 
     89        set_error_handler(array($this, 'onBaseError')); 
    10590        $this->client = $client; 
    10691 
     
    120105 
    121106    /** 
    122     * Base error handler for PHP errors. This functions called onPHPError for 
     107    * Base error handler for PHP errors. This functions called onPhpError for 
    123108    * any clas extending it to give each plugin its own error handler. 
    124109    * 
     
    126111    */ 
    127112    public final function onBaseError($errno, $errstr, $errfile, $errline) { 
    128        if (!isset($this)) { 
    129               return false; 
    130        
    131        return call_user_func_array(array($this, 'onPHPError'), array($errno, $errstr, $errfile, $errline)); 
     113        if (!isset($this)) { 
     114              return false; 
     115       
     116        return call_user_func_array(array($this, 'onPhpError'), array($errno, $errstr, $errfile, $errline)); 
    132117    } 
    133118 
     
    225210    { 
    226211        if (strlen($url) > 30) { 
    227                $opts = array('http' => 
    228                    array( 
    229                        'timeout' => 4, 
    230                        'method' => 'POST', 
    231                        'header' => 'Content-type: application/x-www-form-urlencoded', 
    232                        'content' => http_build_query(array('url' => $url)) 
    233                    ) 
    234                ); 
    235                $context = stream_context_create($opts); 
    236                $tiny = @file_get_contents('http://tinyurl.com/api-create.php', false, $context); 
     212            $opts = array('http' => 
     213                array( 
     214                    'timeout' => 4, 
     215                    'method' => 'POST', 
     216                    'header' => 'Content-type: application/x-www-form-urlencoded', 
     217                    'content' => http_build_query(array('url' => $url)) 
     218                ) 
     219            ); 
     220            $context = stream_context_create($opts); 
     221            $tiny = @file_get_contents('http://tinyurl.com/api-create.php', false, $context); 
    237222            if (empty($tiny)) { 
    238223                $tiny = $url; 
     
    255240    */ 
    256241    public function decodeTranslit($text, $charSetFrom = 'UTF-8', $charSetTo = 'ISO-8859-1') { 
    257                $text = html_entity_decode($text, ENT_QUOTES, $charSetFrom); 
    258                if (strpos($text, '&#') !== false) { 
    259           $text = preg_replace('/&#0*([0-9]+);/me', '$this->codeToUtf(\\1)', $text); 
    260           $text = preg_replace('/&#x0*([a-f0-9]+);/mei', '$this->codeToUtf(hexdec(\\1))', $text); 
     242           $text = html_entity_decode($text, ENT_QUOTES, $charSetFrom); 
     243           if (strpos($text, '&#') !== false) { 
     244              $text = preg_replace('/&#0*([0-9]+);/me', '$this->codeToUtf(\\1)', $text); 
     245              $text = preg_replace('/&#x0*([a-f0-9]+);/mei', '$this->codeToUtf(hexdec(\\1))', $text); 
    261246        } 
    262247 
    263248        // Use the translit extension if installed else fallback on to basic transliteration 
    264249        if (extension_loaded('iconv')) { 
    265                $text = iconv($charSetFrom, $charSetTo.'//TRANSLIT', $text); 
     250                $text = iconv($charSetFrom, $charSetTo.'//TRANSLIT', $text); 
    266251        // Transliteration supprt via the translit extension is still experimental 
    267       } else if (false && extension_loaded('translit')) { 
    268           $text = transliterate($text, array('han_transliterate', 'diacritical_remove'), $charSetFrom, $charSetTo); 
    269       } else { 
     252          } else if (false && extension_loaded('translit')) { 
     253              $text = transliterate($text, array('han_transliterate', 'diacritical_remove'), $charSetFrom, $charSetTo); 
     254          } else { 
    270255            $text = strtr($text, 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', 
    271256                                 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYPYaaaaaaaceeeeiiiidnoooooouuuuypy'); 
    272257            $text = preg_replace('{[^a-z0-9&|"#\'\{\}()§^!°\[\]$*¨µ£%´`~=+:/;.,?><\\ _-]}i', '', $text); 
    273258            $text = utf8_decode($text); 
    274      
    275  
    276       return $text; 
     259         
     260 
     261          return $text; 
    277262    } 
    278263 
     
    284269    */ 
    285270    public function codeToUtf($code) { 
    286       $code = intval($code); 
     271          $code = intval($code); 
    287272        switch ($code) { 
    288273            // 1 byte, 7 bits 
    289274            case 0: 
    290275                return chr(0); 
    291                   case ($code & 0x7F): 
    292                       return chr($code); 
    293  
    294                   // 2 bytes, 11 bits 
    295                   case ($code & 0x7FF): 
    296                       return chr(0xC0 | (($code >> 6) & 0x1F)) . 
     276                  case ($code & 0x7F): 
     277                      return chr($code); 
     278 
     279                  // 2 bytes, 11 bits 
     280                  case ($code & 0x7FF): 
     281                      return chr(0xC0 | (($code >> 6) & 0x1F)) . 
    297282                       chr(0x80 | ($code & 0x3F)); 
    298283 
    299                   // 3 bytes, 16 bits 
    300                   case ($code & 0xFFFF): 
    301                       return chr(0xE0 | (($code >> 12) & 0x0F)) . 
     284                  // 3 bytes, 16 bits 
     285                  case ($code & 0xFFFF): 
     286                      return chr(0xE0 | (($code >> 12) & 0x0F)) . 
    302287                       chr(0x80 | (($code >> 6) & 0x3F)) . 
    303288                       chr(0x80 | ($code & 0x3F)); 
    304289 
    305                   // 4 bytes, 21 bits 
    306                   case ($code & 0x1FFFFF): 
    307                       return chr(0xF0 | ($code >> 18)) . 
     290                  // 4 bytes, 21 bits 
     291                  case ($code & 0x1FFFFF): 
     292                      return chr(0xF0 | ($code >> 18)) . 
    308293                       chr(0x80 | (($code >> 12) & 0x3F)) . 
    309294                       chr(0x80 | (($code >> 6) & 0x3F)) . 
    310295                       chr(0x80 | ($code & 0x3F)); 
    311          } 
    312     } 
    313  
    314        /** 
    315        * Parses a string of command line like arguments and returns them as an array 
    316        * Parses the following: 
    317        *    -Strings: "" | "foo" | "foo bar" | "foo \" bar" | foo 
    318        *    -Options: --opt | --opt foo | --opt= | --opt=foo | --opt="" | --opt="foo" | --opt="foo bar" 
    319        *      @Note: If no parameter is given, the value returned by the option defaults to 
    320        *            1 unless its an empty value such as --opt="" or --opt= 
    321        *    -Flags: -flag +flag 
    322        *      @Note: Flags are handled using bitwise. 1 = -flag, 2 = +flag, 3 = Both a +flag and -flag 
    323        
    324        * The results get stored in an array for the following structure: 
    325        *     Array -> strings []                   -Array containing all the string matches 
    326        *     Array -> commands [command] => value  -Array containing all the string matches 
    327        *     Array -> flags [flag] => bitwise      -Array containing all the string matches 
    328        *     Array -> all [strings|commands|flags] -Array containing a list of all the 
    329        *                                            strings, commands and flags 
    330        
    331        * @param string $args String of arguments that will be parsed 
    332        * @return array 
    333        */ 
    334        public function parseArguments($args) { 
    335               // Strip away multiple spaces 
    336               $args = ' '.preg_replace('#\s+#', ' ', trim($args)).' '; 
    337  
    338               // Check the args string for agurments 
    339               preg_match_all('{'. 
    340               // String Regex: Matches "" | "foo" | "foo bar" | "foo \" bar" | foo 
    341               '(".*?(?<!\\\)" | [^-+\s]+) | '. 
    342               // Option Regex: Matches --opt | --opt foo | --opt= | --opt=foo | --opt="" | --opt="foo" | --opt="foo bar" 
    343               '(--\w+ (?:=".*?(?<!\\\)" | [=\s][^-+"\s]*)?) | '. 
    344               // Flag Regex: Matches -flag +flag 
    345               '([-+]\w+)'. 
    346               '}xi', 
    347               $args, $matches); 
    348               // Shifts the first group matches element off of matches 
    349               $matches = array_shift($matches); 
    350  
    351               // Returned data structure 
    352               $data = array( 
    353                   'strings'    => array(), 
    354                   'commands' => array(), 
    355                   'flags'    => array(), 
    356                   'all'      => array( 
    357                       'strings'    => '', 
    358                       'commands' => array(), 
    359                       'flags'    => array() 
    360                   ) 
    361               ); 
    362  
    363               // Loop through the results 
    364               foreach ($matches as $match) { 
    365                       $match = trim($match); 
    366                       // Check to see if the current match an an --option 
    367                       if (substr($match, 0, 2 ) === '--') { 
    368                               $value = preg_split('/[=\s]/', $match, 2); 
    369                               $com   = substr(array_shift($value), 2); 
    370                               $value = trim(join($value)); 
    371                               // Strip quotes from the option's value 
    372                               $realValue = (substr($value, 0, 1) === '"' && substr($value, -1) === '"' || substr($match, -1) === '='); 
    373                               if(substr($value, 0, 1) === '"' && substr($value, -1) === '"') { 
    374                                       $value = trim(substr($value, 1, -1)); 
    375                               } 
    376                               if (!in_array($com, $data['all']['commands'])) 
    377                               $data['all']['commands'][] = $com; 
    378                               $data['commands'][$com] = (!empty($value) || $realValue? str_replace('\"', '"', $value) : true); 
    379                               continue; 
    380                       } 
    381  
    382                       // Check to see if the current match is a -flag 
    383                       if (substr($match, 0, 1) === '-' || substr($match, 0, 1) === '+') { 
    384                               $flag = substr($match, 1); 
    385                               if (!in_array($flag, $data['all']['flags'])) 
    386                               $data['all']['flags'][] = $flag; 
    387                               // Handle the flags using bitwise operations. 1=-flag, 2=+flag, 3=Both a plus and minus 
    388                               $data['flags'][$flag] |= (substr($match, 0, 1) === '-' ? 0x1 : 0x2); 
    389                               continue; 
    390                       } 
    391  
    392                       // Strip the quotes away from match 
    393                       if(substr($match, 0, 1) === '"' && substr($match, -1) === '"') { 
    394                               $match = trim(substr($match, 1, -1)); 
    395                       } 
    396                       // The match value isn't a flag or an option so consider it a string 
    397                       if (!empty($match)) 
    398                       $data['strings'][] = str_replace('\"', '"', $match); 
    399               } 
    400  
    401               $data['all']['strings'] = trim(implode(' ', $data['strings'])); 
    402               return $data; 
    403        
     296          } 
     297    } 
     298 
     299    /** 
     300    * Parses a string of command line like arguments and returns them as an array 
     301    * Parses the following: 
     302    *    -Strings: "" | "foo" | "foo bar" | "foo \" bar" | foo 
     303    *    -Options: --opt | --opt foo | --opt= | --opt=foo | --opt="" | --opt="foo" | --opt="foo bar" 
     304    *      @Note: If no parameter is given, the value returned by the option defaults to 
     305    *            1 unless its an empty value such as --opt="" or --opt= 
     306    *    -Flags: -flag +flag 
     307    *      @Note: Flags are handled using bitwise. 1 = -flag, 2 = +flag, 3 = Both a +flag and -flag 
     308   
     309    * The results get stored in an array for the following structure: 
     310    *     Array -> strings []                   -Array containing all the string matches 
     311    *     Array -> commands [command] => value  -Array containing all the string matches 
     312    *     Array -> flags [flag] => bitwise      -Array containing all the string matches 
     313    *     Array -> all [strings|commands|flags] -Array containing a list of all the 
     314    *                                            strings, commands and flags 
     315   
     316    * @param string $args String of arguments that will be parsed 
     317    * @return array 
     318    */ 
     319    public function parseArguments($args) { 
     320      // Strip away multiple spaces 
     321      $args = ' '.preg_replace('#\s+#', ' ', trim($args)).' '; 
     322 
     323      // Check the args string for agurments 
     324      preg_match_all('{'. 
     325      // String Regex: Matches "" | "foo" | "foo bar" | "foo \" bar" | foo 
     326      '(".*?(?<!\\\)" | [^-+\s]+) | '. 
     327      // Option Regex: Matches --opt | --opt foo | --opt= | --opt=foo | --opt="" | --opt="foo" | --opt="foo bar" 
     328      '(--\w+ (?:=".*?(?<!\\\)" | [=\s][^-+"\s]*)?) | '. 
     329      // Flag Regex: Matches -flag +flag 
     330      '([-+]\w+)'. 
     331      '}xi', 
     332      $args, $matches); 
     333      // Shifts the first group matches element off of matches 
     334      $matches = array_shift($matches); 
     335 
     336      // Returned data structure 
     337      $data = array( 
     338          'strings'    => array(), 
     339          'commands' => array(), 
     340          'flags'    => array(), 
     341          'all'      => array( 
     342              'strings'    => '', 
     343              'commands' => array(), 
     344              'flags'    => array() 
     345          ) 
     346      ); 
     347 
     348      // Loop through the results 
     349      foreach ($matches as $match) { 
     350              $match = trim($match); 
     351              // Check to see if the current match an an --option 
     352              if (substr($match, 0, 2 ) === '--') { 
     353                      $value = preg_split('/[=\s]/', $match, 2); 
     354                      $com   = substr(array_shift($value), 2); 
     355                      $value = trim(join($value)); 
     356                      // Strip quotes from the option's value 
     357                      $realValue = (substr($value, 0, 1) === '"' && substr($value, -1) === '"' || substr($match, -1) === '='); 
     358                      if(substr($value, 0, 1) === '"' && substr($value, -1) === '"') { 
     359                              $value = trim(substr($value, 1, -1)); 
     360                      } 
     361                      if (!in_array($com, $data['all']['commands'])) 
     362                      $data['all']['commands'][] = $com; 
     363                      $data['commands'][$com] = (!empty($value) || $realValue? str_replace('\"', '"', $value) : true); 
     364                      continue; 
     365              } 
     366 
     367              // Check to see if the current match is a -flag 
     368              if (substr($match, 0, 1) === '-' || substr($match, 0, 1) === '+') { 
     369                      $flag = substr($match, 1); 
     370                      if (!in_array($flag, $data['all']['flags'])) 
     371                      $data['all']['flags'][] = $flag; 
     372                      // Handle the flags using bitwise operations. 1=-flag, 2=+flag, 3=Both a plus and minus 
     373                      $data['flags'][$flag] |= (substr($match, 0, 1) === '-' ? 0x1 : 0x2); 
     374                      continue; 
     375              } 
     376 
     377              // Strip the quotes away from match 
     378              if(substr($match, 0, 1) === '"' && substr($match, -1) === '"') { 
     379                      $match = trim(substr($match, 1, -1)); 
     380              } 
     381              // The match value isn't a flag or an option so consider it a string 
     382              if (!empty($match)) 
     383              $data['strings'][] = str_replace('\"', '"', $match); 
     384      } 
     385 
     386      $data['all']['strings'] = trim(implode(' ', $data['strings'])); 
     387      return $data; 
     388   
    404389 
    405390    /** 
     
    431416        } 
    432417 
    433               if ($time > 0 || count($return) <= 0) { 
    434                       $return[] = $time . 's'; 
    435               } 
     418      if ($time > 0 || count($return) <= 0) { 
     419              $return[] = $time . 's'; 
     420      } 
    436421 
    437422        return implode(' ', $return); 
     
    448433    */ 
    449434    public function pluginLoaded($plugin, $plugins = null, $client = null) { 
    450        $plugin = trim($plugin); 
    451        if (!empty($plugin)) { 
    452            if (!$client) { 
    453               $client = $this->client; 
    454            } 
    455            if (!is_array($plugins) || count($plugins) <= 0) { 
    456                $plugins = $this->getPluginList(); 
    457            } 
    458            $plugins = array_map('strtolower', $plugins); 
    459            if (in_array(strtolower($plugin), $plugins) && class_exists('Phergie_Plugin_' . $plugin) && 
    460                call_user_func(array('Phergie_Plugin_' . $plugin, 'checkDependencies'), $client, $plugins)) { 
    461                return true; 
    462            } 
    463        
     435        $plugin = trim($plugin); 
     436        if (!empty($plugin)) { 
     437            if (!$client) { 
     438              $client = $this->client; 
     439            } 
     440            if (!is_array($plugins) || count($plugins) <= 0) { 
     441                $plugins = $this->getPluginList(); 
     442            } 
     443            $plugins = array_map('strtolower', $plugins); 
     444            if (in_array(strtolower($plugin), $plugins) && class_exists('Phergie_Plugin_' . $plugin) && 
     445                call_user_func(array('Phergie_Plugin_' . $plugin, 'checkDependencies'), $client, $plugins)) { 
     446                return true; 
     447            } 
     448       
    464449        return false; 
    465450    } 
     
    475460    */ 
    476461    public static function staticPluginLoaded($plugin, $plugins, $client) { 
    477        $plugin = trim($plugin); 
    478        if (!empty($plugin) && is_array($plugins)) { 
    479            $plugins = array_map('strtolower', $plugins); 
    480            if (in_array(strtolower($plugin), $plugins) && class_exists('Phergie_Plugin_' . $plugin) && 
    481                call_user_func(array('Phergie_Plugin_' . $plugin, 'checkDependencies'), $client, $plugins)) { 
    482                return true; 
    483            } 
    484        
     462        $plugin = trim($plugin); 
     463        if (!empty($plugin) && is_array($plugins)) { 
     464            $plugins = array_map('strtolower', $plugins); 
     465            if (in_array(strtolower($plugin), $plugins) && class_exists('Phergie_Plugin_' . $plugin) && 
     466                call_user_func(array('Phergie_Plugin_' . $plugin, 'checkDependencies'), $client, $plugins)) { 
     467                return true; 
     468            } 
     469       
    485470        return false; 
    486471    } 
     
    499484        // Check to see if the current class has any admin or ops settings specified 
    500485        if (!isset($this->adminList[$c