Assembla home | Assembla project page
 

Changeset 78

Show
Ignore:
Timestamp:
02/26/08 03:47:02 (9 months ago)
Author:
tobias382
Message:

Fixes #26
* Modified the bootstrap file to determine all plugins to be instantiated

prior to performing actual instantiation

* Modified the base plugin class to include a default implementation of

checkDependencies() that returns true

* Modified the Karma, Lart, Drink, Acronym, Nickserv, Logging, and

AdminCommand? plugins to use checkDependencies()

Files:

Legend:

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

    r71 r78  
    6767    $ini = PHERGIE_INI; 
    6868} else { 
     69    echo 'Loaded specified configuration file ' . $argv[1] . "\n"; 
    6970    $ini = $argv[1]; 
    7071} 
     
    8889} 
    8990 
     91unset ($required); 
     92 
    9093/** 
    9194* Configure the client 
     
    104107} 
    105108 
     109unset ($setting, $value, $driver, $class); 
     110 
    106111/** 
    107112* Determine which plugins should be loaded 
     
    117122} 
    118123 
    119 /** 
    120 * Remove temporary global configuration variables from memory 
    121 */ 
    122 unset($required, $config, $setting, $driver, $class); 
     124unset ($config); 
    123125 
    124126/** 
     
    126128*/ 
    127129$iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 
     130$plugins = array(); 
    128131foreach ($iterator as $entry) { 
    129     if ($iterator->isFile() 
    130         && substr($entry, -4) == '.php' 
    131         && ($all xor in_array(strtolower(substr($entry, 0, -4)), $include))) { 
    132         require_once 'Phergie/Plugin/' . $entry; 
    133         $class = 'Phergie_Plugin_' . str_replace('.php', '', $entry); 
     132    if ($iterator->isFile()) { 
     133        $name = substr($entry, 0, -4); 
     134        if ($all xor in_array(strtolower($name), $include)) { 
     135            $plugins[] = $name; 
     136        } 
     137    } 
     138
     139sort($plugins); 
     140 
     141unset ($iterator, $entry, $name, $all, $include); 
     142 
     143foreach ($plugins as $plugin) { 
     144    require_once 'Phergie/Plugin/' . $plugin . '.php'; 
     145    $class = 'Phergie_Plugin_' . $plugin;  
     146    if (call_user_func(array($class, 'checkDependencies'), $plugins)) { 
    134147        $instance = new $class($client); 
    135148        $client->addPlugin($instance); 
    136         $client->debug('Loaded ' . $instance->getName()); 
     149        $client->debug('Loaded ' . $plugin);  
     150    } else { 
     151        $client->debug('Unable to load ' . $plugin); 
    137152    } 
    138153} 
    139154 
    140 /** 
    141 * Remove temporary plugin configuration variables from memory 
    142 */ 
    143 unset($iterator, $class, $entry, $all, $exclude, $reflector); 
     155unset ($plugins, $plugin, $class, $instance); 
    144156 
    145157/** 
  • trunk/Phergie/Plugin/Abstract/AdminCommand.php

    r71 r78  
    108108 
    109109    /** 
     110    * Returns whether or not the plugin's dependencies are met. 
     111    * 
     112    * @param array $plugins List of short names for plugins that the  
     113    *                       bootstrap file intends to instantiate 
     114    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     115    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     116    * @return bool TRUE if dependencies are met, FALSE otherwise 
     117    */ 
     118    public static function checkDependencies(array $plugins) 
     119    { 
     120        if (! in_array('Users', $plugins) 
     121            || ! Phergie_Plugin_Users::checkDependencies($plugins)) { 
     122            return false; 
     123        } 
     124 
     125        return true; 
     126    } 
     127 
     128    /** 
    110129    * Returns whether or not a message originated from an authorized admin or 
    111130    * op. 
  • trunk/Phergie/Plugin/Abstract/Base.php

    r71 r78  
    3232 
    3333    /** 
    34     * Path to the directory for the plugin if needsDir is enabled 
     34    * Path to the directory for the plugin if $needsDir is enabled 
    3535    * 
    3636    * @see $needsDir 
     
    3939 
    4040    /** 
    41     * Reference back to the client used to initiate commands 
     41    * Reference back to the client, used to initiate commands 
    4242    * 
    4343    * @var Phergie_Driver_Abstract 
     
    4646 
    4747    /** 
     48    * Reference to the current instance of the plugin, used to make its  
     49    * non-static methods accessible to other plugins 
     50    * 
     51    * @var Phergie_Plugin_Abstract_Base 
     52    */ 
     53    protected static $instance; 
     54 
     55    /** 
    4856    * Short class name 
    4957    * 
     
    6775    final public function __construct(Phergie_Driver_Abstract $client) 
    6876    { 
     77        self::$instance = $this; 
     78 
    6979        $this->client = $client; 
    7080 
     
    191201 
    192202    /** 
     203    * Returns a reference to the instance of the current plugin. 
     204    * 
     205    * @return Phergie_Plugin_Abstract_Base 
     206    */ 
     207    public static function getInstance() 
     208    { 
     209        return self::$instance; 
     210    } 
     211 
     212    /** 
     213    * Returns whether or not the current environment meets the requirements  
     214    * of the plugin in order for it to be run, including the PHP version,  
     215    * loaded PHP extensions, and other plugins intended to be loaded.  
     216    * Plugins with such requirements should override this method. 
     217    * 
     218    * @param array $plugins List of short names for plugins that the  
     219    *                       bootstrap file intends to instantiate 
     220    * @return bool TRUE if dependencies are met, FALSE otherwise 
     221    */ 
     222    public static function checkDependencies(array $plugins) 
     223    { 
     224        return true; 
     225    } 
     226 
     227    /** 
    193228    * Initializes the plugin. Should it require initialization, just 
    194229    * override this method. 
  • trunk/Phergie/Plugin/Acronym.php

    r72 r78  
    55*/ 
    66require_once 'Phergie/Plugin/Abstract/Base.php'; 
     7 
     8/** 
     9* @see Phergie_Plugin_Users 
     10*/ 
     11require_once 'Phergie/Plugin/Users.php'; 
    712 
    813/** 
     
    6368 
    6469        $this->filter = array_filter(preg_split('/[ ,]/', $this->getPluginIni('filter')), 'strlen'); 
     70    } 
     71 
     72    /** 
     73    * Returns whether or not the plugin's dependencies are met. 
     74    * 
     75    * @param array $plugins List of short names for plugins that the  
     76    *                       bootstrap file intends to instantiate 
     77    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     78    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     79    * @return bool TRUE if dependencies are met, FALSE otherwise 
     80    */ 
     81    public static function checkDependencies(array $plugins) 
     82    { 
     83        if (! in_array('Users', $plugins) 
     84            || ! Phergie_Plugin_Users::checkDependencies($plugins)) { 
     85            return false; 
     86        } 
     87 
     88        return true; 
    6589    } 
    6690 
  • trunk/Phergie/Plugin/Drink.php

    r61 r78  
    8989    public function init() 
    9090    { 
    91         // Check for the necessary extensions 
    92         if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) { 
    93             return; 
    94         } 
    95  
    96         // Initialize the database connection 
    97         $this->db = new PDO('sqlite:' . $this->dir . 'drink.db'); 
    98  
    99         // Populate the database if necessary 
    100         if ($this->needTable('beer')) { 
    101             $contents = @file_get_contents('http://beerme.com/beerlist.php'); 
    102             if ($contents !== false) { 
    103                 preg_match_all('/brewery\.php\?[0-9]+#[0-9]+\'>([^<]+)/', $contents, $matches); 
     91        try { 
     92            // Initialize the database connection 
     93            $this->db = new PDO('sqlite:' . $this->dir . 'drink.db'); 
     94 
     95            // Populate the database if necessary 
     96            if ($this->needTable('beer')) { 
     97                $contents = @file_get_contents('http://beerme.com/beerlist.php'); 
     98                if ($contents !== false) { 
     99                    preg_match_all('/brewery\.php\?[0-9]+#[0-9]+\'>([^<]+)/', $contents, $matches); 
     100                    $names = array(); 
     101                    foreach ($matches[1] as $key => $name) { 
     102                        if ($this->hasBadChars($name) 
     103                            || strpos($name, '(discontinued)') !== false) { 
     104                            continue; 
     105                        } 
     106                        $name = explode('/', preg_replace('/\([^)]+\)/', '', $name)); 
     107                        $name = trim(array_shift($name)); 
     108                        if (!empty($name)) { 
     109                            $name = html_entity_decode($name); 
     110                            $names[] = $name; 
     111                        } 
     112                    } 
     113                    $this->populateTable('beer', $names); 
     114                    unset($names); 
     115                } 
     116            } 
     117 
     118            if ($this->needTable('cocktail')) { 
     119                $limit = 2; 
    104120                $names = array(); 
    105                 foreach ($matches[1] as $key => $name) { 
    106                     if ($this->hasBadChars($name) 
    107                         || strpos($name, '(discontinued)') !== false) { 
    108                         continue; 
    109                     } 
    110                     $name = explode('/', preg_replace('/\([^)]+\)/', '', $name)); 
    111                     $name = trim(array_shift($name)); 
    112                     if (!empty($name)) { 
    113                         $name = html_entity_decode($name); 
     121                for ($i = 1; $i <= $limit; $i += 150) { 
     122                    $contents = @file_get_contents('http://www.webtender.com/db/browse?level=2&dir=drinks&char=%2A&start=' . $i); 
     123                    if ($contents === false) { 
     124                        break; 
     125                    } 
     126                    if ($i == 1) { 
     127                        preg_match('/>([0-9]+) found\\.</', $contents, $match); 
     128                        $limit = $match[1] + (150 - ($match[1] % 150)); 
     129                    } 
     130                    preg_match_all('/db\\/drink\\/[0-9]+">([^<]+)/', $contents, $matches); 
     131                    foreach ($matches[1] as $name) { 
     132                        if ($this->hasBadChars($name)) { 
     133                            continue; 
     134                        } 
     135                        $name = html_entity_decode(preg_replace('/ The$|^The |\s*\([^)]+\)\s*| #[0-9]+$/', '', $name)); 
    114136                        $names[] = $name; 
    115137                    } 
    116138                } 
    117                 $this->populateTable('beer', $names); 
     139                if ($contents) { 
     140                    $this->populateTable('cocktail', $names); 
     141                } 
    118142                unset($names); 
    119143            } 
    120         } 
    121  
    122         if ($this->needTable('cocktail')) { 
    123             $limit = 2; 
    124             $names = array(); 
    125             for ($i = 1; $i <= $limit; $i += 150) { 
    126                 $contents = @file_get_contents('http://www.webtender.com/db/browse?level=2&dir=drinks&char=%2A&start=' . $i); 
    127                 if ($contents === false) { 
    128                     break; 
    129                 } 
    130                 if ($i == 1) { 
    131                     preg_match('/>([0-9]+) found\\.</', $contents, $match); 
    132                     $limit = $match[1] + (150 - ($match[1] % 150)); 
    133                 } 
    134                 preg_match_all('/db\\/drink\\/[0-9]+">([^<]+)/', $contents, $matches); 
    135                 foreach ($matches[1] as $name) { 
    136                     if ($this->hasBadChars($name)) { 
    137                         continue; 
    138                     } 
    139                     $name = html_entity_decode(preg_replace('/ The$|^The |\s*\([^)]+\)\s*| #[0-9]+$/', '', $name)); 
    140                     $names[] = $name; 
    141                 } 
    142             } 
    143             if ($contents) { 
    144                 $this->populateTable('cocktail', $names); 
    145             } 
    146             unset($names); 
    147         } 
    148  
    149         if ($this->needTable('coke')) { 
    150             $contents = @file_get_contents('http://www.energyfiend.com/huge-caffeine-database/'); 
    151             if ($contents) { 
    152                 // List of drinks to filter out 
    153                 $filter = array( 
    154                     'tea', 
    155                     'coffee', 
    156                     'starbucks' 
    157                 ); 
    158                 $start = stripos($contents, 'id="caffeinedb"'); 
    159                 $end = stripos($contents, '</table>', $start); 
    160                 $contents = substr($contents, $start, $end - $start); 
    161                 preg_match_all('/<tr[^>]*><td>(<[^>]+>)?([^<]+)/is', $contents, $matches); 
    162                 $names = array(); 
    163                 foreach ($matches[2] as $name) { 
    164                     $name = html_entity_decode(trim(preg_replace('/ \\([^)]+\\)| - .*$/', '', $name))); 
    165                     if (!preg_match('/(?:^|\s+)(?:' . implode('|', $filter) . ')(?:\s+|$)/i', $name)) { 
    166                         $names[] = $name; 
    167                     } 
    168                 } 
    169                 $this->populateTable('coke', $names); 
    170                 unset($names); 
    171             } 
    172         } 
    173  
    174         if ($this->needTable('tea')) { 
    175             $names = @file('http://www.midnight-labs.org/tea.txt'); 
    176             if ($names) { 
    177                 foreach ($names as $key => $value) { 
    178                     $names[$key] = ucwords(rtrim($value)); 
    179                 } 
    180                 $this->populateTable('tea', $names); 
    181                 unset($names); 
    182             } 
    183         } 
     144 
     145            if ($this->needTable('coke')) { 
     146                $contents = @file_get_contents('http://www.energyfiend.com/huge-caffeine-database/'); 
     147                if ($contents) { 
     148                    // List of drinks to filter out 
     149                    $filter = array( 
     150                        'tea', 
     151                        'coffee', 
     152                        'starbucks' 
     153                    ); 
     154                    $start = stripos($contents, 'id="caffeinedb"'); 
     155                    $end = stripos($contents, '</table>', $start); 
     156                    $contents = substr($contents, $start, $end - $start); 
     157                    preg_match_all('/<tr[^>]*><td>(<[^>]+>)?([^<]+)/is', $contents, $matches); 
     158                    $names = array(); 
     159                    foreach ($matches[2] as $name) { 
     160                        $name = html_entity_decode(trim(preg_replace('/ \\([^)]+\\)| - .*$/', '', $name))); 
     161                        if (!preg_match('/(?:^|\s+)(?:' . implode('|', $filter) . ')(?:\s+|$)/i', $name)) { 
     162                            $names[] = $name; 
     163                        } 
     164                    } 
     165                    $this->populateTable('coke', $names); 
     166                    unset($names); 
     167                } 
     168            } 
     169 
     170            if ($this->needTable('tea')) { 
     171                $names = @file('http://www.midnight-labs.org/tea.txt'); 
     172                if ($names) { 
     173                    foreach ($names as $key => $value) { 
     174                        $names[$key] = ucwords(rtrim($value)); 
     175                    } 
     176                    $this->populateTable('tea', $names); 
     177                    unset($names); 
     178                } 
     179            } 
     180        } catch (PDOException $e) { } 
    184181 
    185182        unset($this->filter); 
     183    } 
     184 
     185    /** 
     186    * Returns whether or not the plugin's dependencies are met. 
     187    * 
     188    * @param array $plugins List of short names for plugins that the  
     189    *                       bootstrap file intends to instantiate 
     190    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     191    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     192    * @return bool TRUE if dependencies are met, FALSE otherwise 
     193    */ 
     194    public static function checkDependencies(array $plugins) 
     195    { 
     196        if (!extension_loaded('PDO')  
     197            || !extension_loaded('pdo_sqlite')) { 
     198            return false; 
     199        } 
     200 
     201        return true; 
    186202    } 
    187203 
  • trunk/Phergie/Plugin/Karma.php

    r76 r78  
    8080        if ($static) { 
    8181            $this->fixedKarma[strtolower($this->getIni('nick'))] = $static; 
    82         } 
    83  
    84         // Check to ensure that the SQLite extension is loaded 
    85         if (!extension_loaded('sqlite')) { 
    86             return; 
    8782        } 
    8883 
     
    107102 
    108103    /** 
     104    * Returns whether or not the plugin's dependencies are met. 
     105    * 
     106    * @param array $plugins List of short names for plugins that the  
     107    *                       bootstrap file intends to instantiate 
     108    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     109    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     110    * @return bool TRUE if dependencies are met, FALSE otherwise 
     111    */ 
     112    public static function checkDependencies(array $plugins) 
     113    { 
     114        if (!extension_loaded('sqlite')) { 
     115            return false; 
     116        } 
     117 
     118        return true; 
     119    } 
     120 
     121    /** 
    109122    * Handles requests for incrementation, decrementation, or lookup of karma 
    110123    * ratings sent via messages from users. 
  • trunk/Phergie/Plugin/Lart.php

    r77 r78  
    7171    public function init() 
    7272    { 
    73         // Check for the necessary extensions 
    74         if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) { 
    75             return; 
    76         } 
    77  
    78         // Initialize the database connection 
    79         $db = $this->dir . 'lart.db'; 
    80         $create = !file_exists($db); 
    81         $this->db = new PDO('sqlite:' . $db); 
    82  
    83         // Create database tables if necessary 
    84         if ($create) { 
    85             $this->db->exec(' 
    86                 CREATE TABLE lart ( name VARCHAR(255), definition TEXT ); 
    87                 CREATE UNIQUE INDEX lart_name ON lart (name) 
     73        try { 
     74            // Initialize the database connection 
     75            $db = $this->dir . 'lart.db'; 
     76            $create = !file_exists($db); 
     77            $this->db = new PDO('sqlite:' . $db); 
     78 
     79            // Create database tables if necessary 
     80            if ($create) { 
     81                $this->db->exec(' 
     82                    CREATE TABLE lart ( name VARCHAR(255), definition TEXT ); 
     83                    CREATE UNIQUE INDEX lart_name ON lart (name) 
     84                '); 
     85            } 
     86 
     87            // Initialize prepared statements for common operations 
     88            $this->replace = $this->db->prepare(' 
     89                REPLACE INTO lart (name, definition) VALUES (:name, :definition) 
    8890            '); 
    89         } 
    90  
    91         // Initialize prepared statements for common operations 
    92         $this->replace = $this->db->prepare(' 
    93             REPLACE INTO lart (name, definition) VALUES (:name, :definition) 
    94         '); 
    95         $this->select = $this->db->prepare(' 
    96             SELECT definition FROM lart WHERE name = :name 
    97         '); 
    98         $this->delete = $this->db->prepare(' 
    99             DELETE FROM lart WHERE name = :name 
    100         '); 
     91            $this->select = $this->db->prepare(' 
     92                SELECT definition FROM lart WHERE name = :name 
     93            '); 
     94            $this->delete = $this->db->prepare(' 
     95                DELETE FROM lart WHERE name = :name 
     96            '); 
     97        } catch (PDOException $e) { } 
     98    } 
     99 
     100    /** 
     101    * Returns whether or not the plugin's dependencies are met. 
     102    * 
     103    * @param array $plugins List of short names for plugins that the  
     104    *                       bootstrap file intends to instantiate 
     105    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     106    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     107    * @return bool TRUE if dependencies are met, FALSE otherwise 
     108    */ 
     109    public static function checkDependencies(array $plugins) 
     110    { 
     111        if (!extension_loaded('PDO')  
     112            || !extension_loaded('pdo_sqlite')) { 
     113            return false; 
     114        } 
     115 
     116        return true; 
    101117    } 
    102118 
     
    172188    public function onAction() 
    173189    { 
     190        if (!$this->db) { 
     191            return; 
     192        } 
     193 
    174194        $this->checkLart($this->event->getArgument(1)); 
    175195    } 
     
    183203    public function onPrivmsg() 
    184204    { 
     205        if (!$this->db) { 
     206            return; 
     207        } 
     208 
    185209        $source = $this->event->getArgument(0); 
    186210        $message = $this->event->getArgument(1); 
  • trunk/Phergie/Plugin/Logging.php

    r72 r78  
    55*/ 
    66require_once 'Phergie/Plugin/Abstract/Command.php'; 
     7 
     8/** 
     9* @see Phergie_Plugin_Users 
     10*/ 
     11require_once 'Phergie/Plugin/Users.php'; 
    712 
    813/** 
     
    170175    public function init() 
    171176    { 
    172         // Check for the necessary extensions 
    173         if (!extension_loaded('PDO') || !extension_loaded('pdo_sqlite')) { 
    174             return; 
    175         } 
    176  
    177         // Initialize the database connection 
    178         $db = $this->dir . 'logging.db'; 
    179         $create = !file_exists($db); 
    180         $this->db = new PDO('sqlite:' . $db); 
    181  
    182         // Create database tables if necessary 
    183         if ($create) { 
    184             $result = $this->db->exec(' 
    185                 CREATE TABLE logs ( 
    186                     tstamp VARCHAR(14), 
    187                     type SHORTINT, 
    188                     chan VARCHAR(45), 
    189                     nick VARCHAR(25), 
    190                     message VARCHAR(255) 
    191                 ); 
    192                 CREATE INDEX channicktype ON logs (tstamp, type, chan, nick); 
    193                 CREATE INDEX channick ON logs (tstamp, chan, nick); 
     177        try { 
     178            // Initialize the database connection 
     179            $db = $this->dir . 'logging.db'; 
     180            $create = !file_exists($db); 
     181            $this->db = new PDO('sqlite:' . $db); 
     182 
     183            // Create database tables if necessary 
     184            if ($create) { 
     185                $result = $this->db->exec(' 
     186                    CREATE TABLE logs ( 
     187                        tstamp VARCHAR(14), 
     188                        type SHORTINT, 
     189                        chan VARCHAR(45), 
     190                        nick VARCHAR(25), 
     191                        message VARCHAR(255) 
     192                    ); 
     193                    CREATE INDEX channicktype ON logs (tstamp, type, chan, nick); 
     194                    CREATE INDEX channick ON logs (tstamp, chan, nick); 
     195                '); 
     196            } 
     197 
     198            // Initialize prepared statements for common operations 
     199            $this->search = $this->db->prepare(' 
     200                SELECT tstamp, type, chan, nick, message 
     201                FROM logs 
     202                WHERE nick LIKE :phrase 
     203                OR message LIKE :phrase 
     204                ORDER BY tstamp DESC 
     205                LIMIT :limit 
    194206            '); 
    195         } 
    196  
    197         // Initialize prepared statements for common operations 
    198         $this->search = $this->db->prepare(' 
    199             SELECT tstamp, type, chan, nick, message 
    200             FROM logs 
    201             WHERE nick LIKE :phrase 
    202             OR message LIKE :phrase 
    203             ORDER BY tstamp DESC 
    204             LIMIT :limit 
    205         '); 
    206  
    207         $this->seen = $this->db->prepare(' 
    208             SELECT tstamp, type, message 
    209             FROM logs 
    210             WHERE nick = :name 
    211             AND chan = :chan 
    212             ORDER BY tstamp DESC 
    213             LIMIT 1 
    214         '); 
    215  
    216         $this->heard = $this->db->prepare(' 
    217             SELECT tstamp, type, message 
    218             FROM logs 
    219             WHERE type IN (' . self::PRIVMSG . ', ' . self::ACTION . ') 
    220             AND nick = :nick 
    221             AND chan = :chan 
    222             ORDER BY tstamp DESC 
    223             LIMIT 1 
    224         '); 
    225  
    226         $this->insert = $this->db->prepare(' 
    227             INSERT INTO logs ( 
    228                 tstamp, 
    229                 type, 
    230                 chan, 
    231                 nick, 
    232                 message 
    233             ) 
    234             VALUES ( 
    235                 :tstamp, 
    236                 :type, 
    237                 :chan, 
    238                 :nick, 
    239                 :message 
    240             ) 
    241         '); 
     207 
     208            $this->seen = $this->db->prepare(' 
     209                SELECT tstamp, type, message 
     210                FROM logs 
     211                WHERE nick = :name 
     212                AND chan = :chan 
     213                ORDER BY tstamp DESC 
     214                LIMIT 1 
     215            '); 
     216 
     217            $this->heard = $this->db->prepare(' 
     218                SELECT tstamp, type, message 
     219                FROM logs 
     220                WHERE type IN (' . self::PRIVMSG . ', ' . self::ACTION . ') 
     221                AND nick = :nick 
     222                AND chan = :chan 
     223                ORDER BY tstamp DESC 
     224                LIMIT 1 
     225            '); 
     226 
     227            $this->insert = $this->db->prepare(' 
     228                INSERT INTO logs ( 
     229                    tstamp, 
     230                    type, 
     231                    chan, 
     232                    nick, 
     233                    message 
     234                ) 
     235                VALUES ( 
     236                    :tstamp, 
     237                    :type, 
     238                    :chan, 
     239                    :nick, 
     240                    :message 
     241                ) 
     242            '); 
     243        } catch (PDOException $e) { } 
     244    } 
     245 
     246    /** 
     247    * Returns whether or not the plugin's dependencies are met. 
     248    * 
     249    * @param array $plugins List of short names for plugins that the  
     250    *                       bootstrap file intends to instantiate 
     251    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     252    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     253    * @return bool TRUE if dependencies are met, FALSE otherwise 
     254    */ 
     255    public static function checkDependencies(array $plugins) 
     256    { 
     257        if (! in_array('Users', $plugins) 
     258            || ! Phergie_Plugin_Users::checkDependencies($plugins)) { 
     259            return false; 
     260        } 
     261 
     262        if (!extension_loaded('PDO')  
     263            || !extension_loaded('pdo_sqlite')) { 
     264            return false; 
     265        } 
     266 
     267        return true; 
    242268    } 
    243269 
     
    289315    protected function insertEvent($type, $chan, $nick, $message = null) 
    290316    { 
     317        if (!$this->db) { 
     318            return; 
     319        } 
     320 
    291321        $params = array( 
    292322            ':tstamp' => date('YmdHis'), 
     
    458488    public function onDoSearch($phrase) 
    459489    { 
     490        if (!$this->db) { 
     491            return; 
     492        } 
     493 
    460494        $source = $this->event->getSource(); 
    461495 
     
    491525    public function onDoSeen($user) 
    492526    { 
     527        if (!$this->db) { 
     528            return; 
     529        } 
     530 
    493531        // Don't match if user has a space (obviously it's not a nick) 
    494532        if (strpos($user, ' ') !== false) { 
     
    558596    public function onDoHeard($user) 
    559597    { 
     598        if (!$this->db) { 
     599            return; 
     600        } 
     601 
    560602        // Don't match if user has a space (obviously it's not a nick) 
    561603        if (strpos($user, ' ') !== false) { 
  • trunk/Phergie/Plugin/Nickserv.php

    r71 r78  
    55*/ 
    66require_once 'Phergie/Plugin/Abstract/AdminCommand.php'; 
     7 
     8/** 
     9* @see Phergie_Plugin_Users 
     10*/ 
     11require_once 'Phergie/Plugin/Users.php'; 
    712 
    813/** 
     
    3237 
    3338        $this->nick = $this->getIni('nick'); 
     39    } 
     40 
     41    /** 
     42    * Returns whether or not the plugin's dependencies are met. 
     43    * 
     44    * @param array $plugins List of short names for plugins that the  
     45    *                       bootstrap file intends to instantiate 
     46    * @return bool TRUE if the plugins dependencies are met, FALSE otherwise 
     47    * @see Phergie_Plugin_Abstract_Base::checkDependencies() 
     48    * @return bool TRUE if dependencies are met, FALSE otherwise 
     49    */ 
     50    public static function checkDependencies(array $plugins) 
     51    { 
     52        return true; 
    3453    } 
    3554 
     
    7695    public function onDoGhostbust() 
    7796    { 
    78         $password = $this->getPluginIni('password'); 
    79         $this->debug('password = ' . $password); 
     97        if (Phergie_Plugin_Users::getInstance() === null) { 
     98            $password = $this->getPluginIni('password'); 
     99            $this->debug('password = ' . $password); 
    80100 
    81         if (!empty ($password)) { 
    82             $this->doPrivmsg( 
    83                 'NickServ', 
    84                 'GHOST ' . $this->nick . ' ' . $password 
    85             ); 
    86         } 
     101            if (!empty ($password)) { 
     102                $this->doPrivmsg( 
     103                    'NickServ', 
     104                    'GHOST ' . $this->nick . ' ' . $password 
     105                ); 
     106            } 
     107       } 
    87108    } 
    88109}