Changeset 125
- Timestamp:
- 03/05/08 19:07:13 (9 months ago)
- Files:
-
- trunk/Phergie/Bot.php (modified) (3 diffs)
- trunk/Phergie/Plugin/Toggle.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Bot.php
r106 r125 140 140 $name = substr($entry, 0, -4); 141 141 if ($all xor in_array(strtolower($name), $include)) { 142 $plugins[$name] = true; 143 } else { 144 $plugins[$name] = false; 142 $plugins[] = $name; 145 143 } 146 144 } … … 151 149 unset ($iterator, $entry, $name, $all, $include); 152 150 153 foreach ($plugins as $plugin =>$enabled) {151 foreach ($plugins as $plugin) { 154 152 require_once 'Phergie/Plugin/' . $plugin . '.php'; 155 153 $class = 'Phergie_Plugin_' . $plugin; 156 154 if (call_user_func(array($class, 'checkDependencies'), $client, $plugins)) { 157 155 $instance = new $class($client); 158 $instance->enabled = $enabled;159 156 $client->addPlugin($instance); 160 $client->debug('Loaded ' . $plugin . ($enabled ? '':' [Disabled]'));157 $client->debug('Loaded ' . $plugin); 161 158 } else { 162 159 $client->debug('Unable to load ' . $plugin); … … 170 167 */ 171 168 $state = $client->run(); 169 unset($client); 172 170 173 171 switch($state) trunk/Phergie/Plugin/Toggle.php
r124 r125 13 13 public function onDoDisable($plugin) 14 14 { 15 if ( $instance = $this->getPlugin($plugin) && $instance != $this) {15 if (($instance = $this->getPlugin($plugin)) && $instance != $this) { 16 16 $instance->enabled = false; 17 17 $this->doPrivmsg($this->event->getSource(), 'Disabled '.$plugin.'.'); 18 18 } else { 19 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not disable.');19 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' is not loaded.'); 20 20 } 21 21 } … … 23 23 public function onDoEnable($plugin) 24 24 { 25 // Plugin is loaded already 25 26 if ($instance = $this->getPlugin($plugin)) { 26 $instance->enabled = true; 27 $this->doPrivmsg($this->event->getSource(), 'Enabled '.$plugin.'.'); 27 // Already enabled 28 if ($instance->enabled) { 29 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' was already enabled.'); 30 // Not yet enabled, enable 31 } else { 32 $instance->enabled = true; 33 $this->doPrivmsg($this->event->getSource(), 'Enabled '.$plugin.'.'); 34 } 35 // Plugin was not loaded, try to see if we can load it 28 36 } else { 29 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not enable.'); 37 // Build loaded plugin list to pass to the checkDependencies method 38 $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin'); 39 $plugins = array(); 40 41 foreach ($iterator as $entry) { 42 if ($iterator->isFile()) { 43 $plugins[] = basename((string) $entry, '.php'); 44 } 45 46 if ($iterator->isFile() && strtolower((string) $entry) == strtolower($plugin).'.php') { 47 $target = (string) $entry; 48 } 49 } 50 51 foreach ($plugins as $k=>$p) { 52 if(!($this->getPlugin($p) instanceof Phergie_Plugin_Abstract_Base)) { 53 unset($plugins[$k]); 54 } 55 } 56 57 // Plugin file was found, check if it can be loaded 58 if (isset($target)) { 59 require_once PHERGIE_DIR.'/Phergie/Plugin/'.$target; 60 $class = 'Phergie_Plugin_'.substr($target, 0, -4); 61 if (call_user_func(array($class, 'checkDependencies'), $this->client, $plugins)) { 62 $instance = new $class($this->client); 63 $this->client->addPlugin($instance); 64 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' loaded.'); 65 } else { 66 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' can not be loaded, missing dependencies.'); 67 } 68 // Plugin file not found 69 } else { 70 $this->doPrivmsg($this->event->getSource(), 'Plugin '.$plugin.' not found, could not enable.'); 71 } 30 72 } 31 73 }