Assembla home | Assembla project page
 

Changeset 226

Show
Ignore:
Timestamp:
04/13/08 03:17:59 (6 months ago)
Author:
Slynderdale
Message:

Some bug fixes and tweaks. Fixed up the error handling in URL a bit and also its URL checking. Added a check to the restart command in quit to check the syntax of Phergie before restarting.

Files:

Legend:

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

    r223 r226  
    1717 */ 
    1818} elseif (version_compare('5.2', PHP_VERSION, '>')) { 
    19     trigger_error('Warning: PHP 5.2+ is recommended, current version: ' . PHP_VERSION, E_USER_WARNING); 
     19    trigger_error('PHP 5.2+ is recommended, current version: ' . PHP_VERSION, E_USER_WARNING); 
    2020} 
    2121 
  • trunk/Phergie/Driver/Abstract.php

    r218 r226  
    117117     * 
    118118     * @param string $message Debugging message 
    119      * @return void 
    120      */ 
    121     public function debug($message) 
     119     * @param bool $displayDebug Toggle whether to display the message in the 
     120     *                           console or not 
     121     * @return void 
     122     */ 
     123    public function debug($message, $displayDebug = true) 
    122124    { 
    123125        if ($this->getIni('debug')) { 
    124126            $message = '[' . date('H:i:s') . '] ' . $message . PHP_EOL; 
    125             echo $message; 
     127            if ($displayDebug) { 
     128                echo $message; 
     129            } 
    126130            if ($log = $this->getIni('log') and !empty($log)) { 
    127131                file_put_contents($log, $message, FILE_APPEND); 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r223 r226  
    204204     * 
    205205     * @param string $message Message to log 
    206      * @return void 
    207      */ 
    208     public function debug($message) 
    209     { 
    210         $this->client->debug('<' . strtolower($this->name) . '> ' . $message); 
     206     * @param bool $displayDebug Toggle whether to display the message in the 
     207     *                           console or not 
     208     * @return void 
     209     */ 
     210    public function debug($message, $displayDebug = true) 
     211    { 
     212        $this->client->debug('<' . strtolower($this->name) . '> ' . $message, $displayDebug); 
    211213    } 
    212214 
  • trunk/Phergie/Plugin/Quit.php

    r223 r226  
    146146        $user = $this->event->getNick(); 
    147147        if (empty($this->phpPath) or !is_file($this->phpPath)) { 
    148             trigger_error('Warning: Could not restart Phergie, make sure the setting "quit.php_path" is correct', E_USER_WARNING); 
     148            trigger_error('Could not restart Phergie, make sure the setting "quit.php_path" is correct', E_USER_WARNING); 
     149            $this->doNotice($user, 'Error: Couldn\'t restart Phergie.'); 
     150            return; 
     151        } 
     152 
     153        $exec = shell_exec(PHERGIE_PHP_PATH . ' -l ' . PHERGIE_DIR . 'Bot.php ' . PHERGIE_INI_PATH); 
     154        if (stripos($exec, 'No syntax errors') === false) { 
     155            trigger_error('Encountered an error while trying to restart.', E_USER_WARNING); 
     156            $this->debug('Restart Error: ' . trim($exec)); 
    149157            $this->doNotice($user, 'Error: Couldn\'t restart Phergie.'); 
    150158            return; 
     
    165173            $this->handleQuit($message); 
    166174        } else { 
    167             trigger_error('Warning: Could not create another instance of Phergie.', E_USER_WARNING); 
     175            trigger_error('Could not create another instance of Phergie.', E_USER_WARNING); 
    168176            $this->doNotice($user, 'Error: Couldn\'t restart Phergie.'); 
    169177        } 
  • trunk/Phergie/Plugin/Url.php

    r225 r226  
    6565     */ 
    6666    protected $errorStatus = false; 
     67    protected $errorMessage = null; 
    6768 
    6869    /** 
     
    188189 
    189190                // Check to see if the URL has a valid TLD 
    190                 if (is_array($this->tldList) && count($this->tldList) > 3 && 
    191                     !in_array(strtolower($parsed['tld']), $this->tldList)) { 
     191                if (is_array($this->tldList) && !in_array(strtolower($parsed['tld']), $this->tldList)) { 
    192192                    continue; 
    193193                } 
     
    267267                if (empty($title)) { 
    268268                    if ($this->errorStatus) { 
    269                         if (!$this->showErrors) { 
     269                        if (!$this->showErrors || $this->errorStatus == 1) { 
    270270                            continue; 
    271271                        } 
    272                         $title = 'Error: ' . $this->errorStatus
     272                        $title = $this->errorMessage
    273273                        $this->errorStatus = false; 
     274                        $this->errorMessage = null; 
    274275                    } else { 
    275276                        $title = 'No Title'; 
     
    419420            // Check to see if there was HTTP warning while connecting to the site 
    420421            if (preg_match('{HTTP/1\.[01] ([0-9]{3})}i', $errstr, $m)) { 
    421                 $this->errorStatus = (isset($this->httpErrors[$m[1]]) ? $this->httpErrors[$m[1]] : $m[1]); 
     422                $this->errorStatus = $m[1]; 
     423                $this->errorMessage = (isset($this->httpErrors[$m[1]]) ? $this->httpErrors[$m[1]] : $m[1]); 
     424                $this->debug('PHP Warning:  ' . $errstr . 'in ' . $errfile . ' on line ' . $errline); 
    422425                return true; 
    423                 // Safely ignore these SSL warnings so they don't appear in the log 
     426            // Safely ignore these SSL warnings so they don't appear in the log 
    424427            } else if (stripos($errstr, 'SSL: fatal protocol error in') !== false || 
    425428                       stripos($errstr, 'failed to open stream') !== false || 
     
    430433                       stripos($errstr, 'SSL operation failed with code') !== false || 
    431434                       stripos($errstr, 'unable to connect to') !== false) { 
     435                $this->errorStatus = 1; 
     436                $this->debug('PHP Warning:  ' . $errstr . 'in ' . $errfile . ' on line ' . $errline); 
    432437                return true; 
    433438            } 
     
    549554    { 
    550555        $temp = $this->getPluginIni($setting); 
    551         if (($integer && intval($temp) > 0) || (!$integer && !empty($temp))) { 
     556        if (($integer && intval($temp) > 0) || (!$integer && isset($temp))) { 
    552557             $this->{$var} = $temp; 
    553558        }