Changeset 192
- Timestamp:
- 03/29/08 12:43:25 (8 months ago)
- Files:
-
- trunk/Phergie/Driver/Abstract.php (modified) (5 diffs)
- trunk/Phergie/Driver/Streams.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Driver/Abstract.php
r178 r192 4 4 * @see Phergie_Plugin_Abstract_Base 5 5 */ 6 require_once 'Phergie/Plugin/Abstract/Base.php';6 require_once PHERGIE_PLUGIN_DIR.'Abstract'.DS.'Base.php'; 7 7 8 8 /** … … 30 30 31 31 /** 32 * List of plugin instances 33 * 34 * @var array 35 */ 36 protected $plugins; 37 38 /** 32 39 * Returns the value associated with a specified configuration setting. 33 40 * … … 120 127 { 121 128 if ($this->getIni('debug')) { 122 $message = date('H:i:s') . '' . $message . PHP_EOL;129 $message = '[' . date('H:i:s') . '] ' . $message . PHP_EOL; 123 130 echo $message; 124 if ($log = $this->getIni('log') ) {131 if ($log = $this->getIni('log') and !empty($log)) { 125 132 file_put_contents($log, $message, FILE_APPEND); 126 133 } … … 132 139 * 133 140 * @param Phergie_Plugin_Abstract_Base $plugin 134 * @return void 135 */ 136 public abstract function addPlugin(Phergie_Plugin_Abstract_Base $plugin); 141 */ 142 public function addPlugin(Phergie_Plugin_Abstract_Base $plugin) 143 { 144 $plugin->init(); 145 146 $this->plugins[strtolower($plugin->getName())] = $plugin; 147 } 137 148 138 149 /** … … 141 152 * @return Phergie_Plugin_Abstract_Base 142 153 */ 143 public abstract function getPlugins(); 154 public function getPlugins() 155 { 156 return $this->plugins; 157 } 144 158 145 159 /** 146 * Returns a list of all the plugins 147 * 160 * Returns a list of all the plugins either currently loaded or within the 161 * plugin directory. 162 * 163 * @param $plugin $dirList If true, scan the Plugin directory for the list 148 164 * @return array 149 165 */ 150 public abstract function getPluginList(); 166 public function getPluginList($dirList = false, $preserveExt = false) 167 { 168 if (!$dirList) { 169 return array_keys($this->plugins); 170 } else { 171 $iterator = new DirectoryIterator(PHERGIE_PLUGIN_DIR); 172 $plugins = array(); 173 174 foreach ($iterator as $filename) { 175 if ($iterator->isFile() && pathinfo($filename, PATHINFO_EXTENSION) == 'php') { 176 $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php')); 177 } 178 } 179 unset($iterator, $filename, $dirList); 180 181 return $plugins; 182 } 183 } 151 184 152 185 /** 153 * Returns a plugin instance 154 *186 * Returns a plugin instance. 187 * 155 188 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix) 156 189 * @return Phergie_Plugin_Abstract_Base 157 190 */ 158 public abstract function getPlugin($plugin); 191 public function getPlugin($plugin) 192 { 193 $plugin = strtolower($plugin); 194 if (isset($this->plugins[$plugin])) 195 return $this->plugins[$plugin]; 196 return false; 197 } 159 198 160 199 /** trunk/Phergie/Driver/Streams.php
r178 r192 4 4 * @see Phergie_Driver_Abstract 5 5 */ 6 require_once 'Phergie/Driver/Abstract.php';6 require_once PHERGIE_DRIVER_DIR.'Abstract.php'; 7 7 8 8 /** … … 37 37 'whowas', 38 38 'mode', 39 'nick', 39 40 'privmsg', 40 'nick',41 41 'topic', 42 42 'invite', … … 53 53 54 54 /** 55 * List of plugin instances56 *57 * @var array58 */59 protected $plugins;60 61 /**62 55 * Flag to indicate whether or not the callbacks are currently being 63 56 * queued for execution rather than executed outright … … 91 84 $this->queue = array(); 92 85 } 93 94 /**95 * Adds a set of callbacks for events received from the server.96 *97 * @param Phergie_Plugin_Abstract_Base $plugin98 */99 public function addPlugin(Phergie_Plugin_Abstract_Base $plugin)100 {101 $plugin->init();102 103 $this->plugins[strtolower($plugin->getName())] = $plugin;104 }105 106 /**107 * Returns all the plugins.108 *109 * @return Phergie_Plugin_Abstract_Base110 */111 public function getPlugins()112 {113 return $this->plugins;114 }115 116 /**117 * Returns a list of all the plugins either currently loaded or within the118 * plugin directory.119 *120 * @param $plugin $dirList If true, scan the Plugin directory for the list121 * @return array122 */123 public function getPluginList($dirList = false, $preserveExt = false)124 {125 if (!$dirList) {126 return array_keys($this->plugins);127 } else {128 $iterator = new DirectoryIterator(PHERGIE_DIR . '/Phergie/Plugin');129 $plugins = array();130 131 foreach ($iterator as $filename) {132 if ($iterator->isFile()) {133 $plugins[] = ($preserveExt ? (string) $filename : basename((string) $filename, '.php'));134 }135 }136 unset($iterator, $filename, $dirList);137 138 return $plugins;139 }140 }141 142 /**143 * Returns a plugin instance.144 *145 * @param $plugin The plugin class name (without the Phergie_Plugin_ prefix)146 * @return Phergie_Plugin_Abstract_Base147 */148 public function getPlugin($plugin)149 {150 if (isset($this->plugins[strtolower($plugin)]))151 return $this->plugins[strtolower($plugin)];152 return false;153 }154 86 155 87 /** … … 217 149 ); 218 150 219 unset($server);220 221 151 $this->send('USER', $params); 222 152 $this->doNick($this->getIni('nick')); 223 224 unset($params); 153 unset($server, $params); 225 154 226 155 $ignore = $this->hostmasksToRegex($this->getIni('ignore')); … … 251 180 } 252 181 $buffer = rtrim($buffer); 253 $this->debug(' server ->' . $buffer);182 $this->debug('<- ' . $buffer); 254 183 255 184 if ($buffer[0] == ':') { … … 261 190 262 191 $cmd = strtolower($cmd); 263 264 192 switch ($cmd) { 265 193 case 'names': … … 268 196 case 'ping': 269 197 case 'join': 198 case 'error': 270 199 $args = array(ltrim($args, ':')); 271 200 break; … … 300 229 break; 301 230 case 'part': 231 case 'kill': 302 232 $args = preg_split('/ :?/', $args, 2); 303 233 break; … … 360 290 } 361 291 $plugin->setEvent($event); 292 // onRaw Handlers 293 $plugin->onRaw(); 362 294 if ($event instanceof Phergie_Event_Response) { 363 295 $plugin->onResponse(); … … 366 298 call_user_func(array($plugin, 'on' . ucfirst($event->getType()))); 367 299 } 368 // onRaw Handler369 $plugin->onRaw();370 300 } 371 301 $this->queueing = false; … … 417 347 $this->queue[$command][] = $arguments; 418 348 } else { 419 if ($command == 'raw') {349 if ($command == Phergie_Event_Request::TYPE_RAW) { 420 350 $buffer = (count($arguments) > 0 ? implode(' ', $arguments) : ''); 421 351 } else { … … 429 359 if (!empty($buffer)) { 430 360 fwrite($this->socket, $buffer . "\r\n"); 431 $this->debug(' client-> ' . $buffer);361 $this->debug('-> ' . $buffer); 432 362 } 433 363 } … … 471 401 * @param string $channel Name of the channel to leave 472 402 */ 473 public function doPart($channel )474 { 475 $this->send(Phergie_Event_Request::TYPE_PART, array($channel ));403 public function doPart($channel, $reason = null) 404 { 405 $this->send(Phergie_Event_Request::TYPE_PART, array($channel, $reason)); 476 406 } 477 407 … … 663 593 * @param string $version The version to send 664 594 */ 665 public function doVersionReply($target, $version ='')595 public function doVersionReply($target, $version = '') 666 596 { 667 597 $version = trim($version); … … 678 608 * @param string $time The time to send 679 609 */ 680 public function doTimeReply($target, $time ='')610 public function doTimeReply($target, $time = '') 681 611 { 682 612 $time = trim($time); … … 694 624 * @param string $reply The CTCP reply to send 695 625 */ 696 public function doCtcpReply($target, $command, $reply ='')626 public function doCtcpReply($target, $command, $reply = '') 697 627 { 698 628 $command = trim($command);