Assembla home | Assembla project page
 

Changeset 267

Show
Ignore:
Timestamp:
07/21/08 01:41:26 (4 months ago)
Author:
tobias382
Message:

Fixes #53 Added suggested optimizations to Bot.php (thanks Shadowhand)

Files:

Legend:

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

    r229 r267  
    4040 * @const string 
    4141 */ 
    42 define('PHERGIE_BASE_DIR', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR); 
     42define('PHERGIE_BASE_DIR', realpath('..') . DIRECTORY_SEPARATOR); 
    4343 
    4444/** 
     
    4747 * @const string 
    4848 */ 
    49 define('PHERGIE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR); 
     49define('PHERGIE_DIR', realpath('.') . DIRECTORY_SEPARATOR); 
    5050 
    5151/** 
     
    6464 * Check to make sure the CLI SAPI is being used 
    6565 */ 
    66 if (strtolower(php_sapi_name()) != 'cli') { 
     66if (strtolower(PHP_SAPI) != 'cli') { 
    6767    trigger_error('Phergie requires the CLI SAPI in order to run', E_USER_ERROR); 
    6868} 
     
    7272 * default timezone to prevent strict errors. 
    7373 */ 
    74  $timezone = ini_get('date.timezone'); 
    75 if (empty($timezone)) { 
    76     trigger_error('The default timezone wasn\'t set, defaulting to "' . date_default_timezone_get() . '."', E_USER_NOTICE); 
     74if (!ini_get('date.timezone')) { 
    7775    date_default_timezone_set(date_default_timezone_get()); 
    7876} 
    79 unset($timezone); 
    8077 
    8178/** 
     
    9390    echo 'No configuration file specified, defaulting to ' . PHERGIE_DEFAULT_INI . PHP_EOL; 
    9491    $ini = PHERGIE_DEFAULT_INI; 
    95 } else if (!empty($argv[1]) && file_exists($argv[1]) && is_readable($argv[1])) { 
     92} else if (!empty($argv[1]) && is_file($argv[1]) && is_readable($argv[1])) { 
    9693    echo 'Using specified configuration file ' . $argv[1] . PHP_EOL; 
    9794    $ini = $argv[1]; 
     
    125122{ 
    126123    $file = $class; 
    127     if (strtolower(substr($file, 0, 8)) == 'phergie_') { 
     124    if (stripos($file, 'phergie_') === 0) { 
    128125        $file = substr($file, 8); 
    129126    } 
    130     $file = str_replace('_', DIRECTORY_SEPARATOR, $file) . '.php'; 
    131     require_once ($file); 
    132     if (class_exists($class)) { 
    133         return; 
    134     } 
    135     trigger_error('Could not load class "' . $class . '" from file "' . $file . '"', E_USER_ERROR); 
     127    if (is_file($file = str_replace('_', DIRECTORY_SEPARATOR, $file) . '.php')) { 
     128        require $file; 
     129    } 
    136130} 
    137131 
     
    150144    $config = parse_ini_file(PHERGIE_INI_PATH); 
    151145 
    152     if (count($config) == 0) { 
     146    if (empty($config)) { 
    153147        trigger_error('Configuration file inaccessible or empty: ' . $ini, E_USER_ERROR); 
    154148    } 
     
    160154        } 
    161155    } 
    162     if (count($missing) > 0) { 
     156    if (!empty($missing)) { 
    163157        trigger_error('Fatal error: Required configuration settings missing: ' . implode(', ', $missing), E_USER_ERROR); 
    164158    } 
     
    199193    if (!empty($config['plugins']) && 
    200194        preg_match('/(all|none)(?:\s*except\s*(.+))?/ADi', $config['plugins'], $match)) { 
    201         $all = trim(strtolower($match[1])) != 'none'; 
     195        $all = strtolower(trim($match[1])) != 'none'; 
    202196        if (!empty($match[2])) { 
    203197            $include = array_map('strtolower', preg_split('/[, ]+/', trim($match[2])));