Changeset 193
- Timestamp:
- 03/29/08 12:59:29 (8 months ago)
- Files:
-
- trunk/Phergie/Plugin/Abstract/AdminCommand.php (deleted)
- trunk/Phergie/Plugin/Abstract/Base.php (modified) (13 diffs)
- trunk/Phergie/Plugin/Abstract/Command.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Plugin/Abstract/Base.php
r179 r193 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 /** 9 9 * @see Phergie_Event_Request 10 10 */ 11 require_once 'Phergie/Event/Request.php';11 require_once PHERGIE_EVENT_DIR.'Request.php'; 12 12 13 13 /** 14 14 * @see Phergie_Event_Response 15 15 */ 16 require_once 'Phergie/Event/Response.php';16 require_once PHERGIE_EVENT_DIR.'Response.php'; 17 17 18 18 /** … … 60 60 61 61 /** 62 * List of administrator hostmasks 63 * 64 * @var array 65 */ 66 protected $adminList = array(); 67 68 /** 69 * List of channel ops 70 * 71 * @var array 72 */ 73 protected $opList = array(); 74 75 /** 62 76 * Flag indicating whether or not the plugin is enabled and receives events 63 77 * … … 74 88 75 89 /** 90 * Flag indicating whether or not the plugin is a passive plugin or not 91 * 92 * @var bool 93 */ 94 public $passive = false; 95 96 /** 76 97 * Sets a reference to the client used to initiate commands. 77 98 * … … 81 102 final public function __construct(Phergie_Driver_Abstract $client) 82 103 { 104 set_error_handler(array(__CLASS__, 'onBaseError')); 83 105 $this->client = $client; 84 106 … … 88 110 if ($this->needsDir) { 89 111 $class = new ReflectionClass($name); 90 $dir = 91 dirname($class->getFilename()) . 92 DIRECTORY_SEPARATOR . 93 $this->name . 94 DIRECTORY_SEPARATOR; 112 $dir = dirname($class->getFilename()) . DS . $this->name . DS; 95 113 if (!file_exists($dir)) { 96 114 mkdir($dir); … … 101 119 102 120 /** 121 * Base error handler for PHP errors. This functions called onPHPError for 122 * any clas extending it to give each plugin its own error handler. 123 * 124 * @return bool 125 */ 126 public final function onBaseError($errno, $errstr, $errfile, $errline) { 127 if (!isset($this)) { 128 return false; 129 } 130 return call_user_func_array(array($this, 'onPHPError'), array($errno, $errstr, $errfile, $errline)); 131 } 132 133 /** 103 134 * Returns the short name of the current plugin. 104 135 * … … 181 212 public function debug($message) 182 213 { 183 $this->client->debug( strtolower($this->name) . ' -> ' . $message);214 $this->client->debug('<' . strtolower($this->name) . '> ' . $message); 184 215 } 185 216 … … 224 255 public function decodeTranslit($text, $charSetFrom = 'UTF-8', $charSetTo = 'ISO-8859-1') { 225 256 $text = html_entity_decode($text, ENT_QUOTES, $charSetFrom); 226 $text = preg_replace('/�*([0-9]+);/me', '$this->codeToUtf(\\1)', $text); 227 $text = preg_replace('/�*([a-f0-9]+);/mei', '$this->codeToUtf(hexdec(\\1))', $text); 257 if (strpos($text, '&#') !== false) { 258 $text = preg_replace('/�*([0-9]+);/me', '$this->codeToUtf(\\1)', $text); 259 $text = preg_replace('/�*([a-f0-9]+);/mei', '$this->codeToUtf(hexdec(\\1))', $text); 260 } 228 261 229 262 // Use the translit extension if installed else fallback on to basic transliteration … … 234 267 $text = transliterate($text, array('han_transliterate', 'diacritical_remove'), $charSetFrom, $charSetTo); 235 268 } else { 236 $text = strtr($text, ' ��������������������������������������������������������������',269 $text = strtr($text, 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', 237 270 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYPYaaaaaaaceeeeiiiidnoooooouuuuypy'); 238 $text = preg_replace('{[^a-z0-9&|"#\'\{\}() �^!�\[\]$*���%�`~=+:/;.,?><\\ _-]}i', '', $text);271 $text = preg_replace('{[^a-z0-9&|"#\'\{\}()§^!°\[\]$*¨µ£%´`~=+:/;.,?><\\ _-]}i', '', $text); 239 272 $text = utf8_decode($text); 240 273 } … … 405 438 406 439 /** 440 * Checks if a specified plugin is loaded 441 * 442 * @param string $plugin Plugin to check 443 * @param Phergie_Driver_Abstract $client Client instance 444 * @param array $plugins List of short names for plugins that the 445 * bootstrap file intends to instantiate 446 * @return bool 447 */ 448 public function pluginLoaded($plugin, $plugins = null, $client = null) { 449 $plugin = trim($plugin); 450 if (!empty($plugin)) { 451 if (!$client) { 452 $client = $this->client; 453 } 454 if (!is_array($plugins) || count($plugins) <= 0) { 455 $plugins = $this->getPluginList(); 456 } 457 $plugins = array_map('strtolower', $plugins); 458 if (in_array(strtolower($plugin), $plugins) && class_exists('Phergie_Plugin_' . $plugin) && 459 call_user_func(array('Phergie_Plugin_' . $plugin, 'checkDependencies'), $client, $plugins)) { 460 return true; 461 } 462 } 463 return false; 464 } 465 466 /** 467 * Static call to check if a specified plugin is loaded 468 * 469 * @param string $plugin Plugin to check 470 * @param Phergie_Driver_Abstract $client Client instance 471 * @param array $plugins List of short names for plugins that the 472 * bootstrap file intends to instantiate 473 * @return bool 474 */ 475 public static function staticPluginLoaded($plugin, $plugins, $client) { 476 $plugin = trim($plugin); 477 if (!empty($plugin) && is_array($plugins)) { 478 $plugins = array_map('strtolower', $plugins); 479 if (in_array(strtolower($plugin), $plugins) && class_exists('Phergie_Plugin_' . $plugin) && 480 call_user_func(array('Phergie_Plugin_' . $plugin, 'checkDependencies'), $client, $plugins)) { 481 return true; 482 } 483 } 484 return false; 485 } 486 487 /** 488 * Returns whether or not a message originated from an authorized admin or 489 * op. 490 * 491 * @param bool $includeOps Include ops in the admin check 492 * @return bool TRUE if the message originated from an authorized 493 * individual, FALSE otherwise 494 */ 495 public function fromAdmin($includeOps = true) 496 { 497 $class = $this->getName(); 498 // Check to see if the current class has any admin or ops settings specified 499 if (!isset($this->adminList[$class]) || !isset($this->opList[$class])) { 500 // Handle the op settings 501 $ini = $this->getPluginIni('ops'); 502 if ($ini === null) { 503 $ini = $this->getIni('admincommand.ops'); 504 } 505 $this->opList[$class] = ((strtolower($ini) === 'true' || $ini === '1')); 506 507 // Handle the admin settings 508 $ini = trim($this->getPluginIni('admins') . ' ' . $this->getIni('admincommand.admins')); 509 $this->adminList[$class] = (!empty($ini) ? $this->hostmasksToRegex($ini) : null); 510 unset($ini); 511 } 512 513 // Try to match mask against admin masks 514 if (isset($this->adminList[$class]) 515 && preg_match($this->adminList[$class], $this->event->getHostmask())) { 516 return true; 517 } 518 519 // Check if is op and ops are admins 520 if ($includeOps && isset($this->opList[$class]) && $this->pluginLoaded('Users')) { 521 $nick = $this->event->getNick(); 522 $source = $this->event->getSource(); 523 if (Phergie_Plugin_Users::isOp($nick, $source)) { 524 return true; 525 } 526 } 527 return false; 528 } 529 530 /** 407 531 * Returns whether or not the current environment meets the requirements 408 532 * of the plugin in order for it to be run, including the PHP version, … … 586 710 587 711 /** 712 * Handler for when the server sends a kill request. 713 * 714 * @return void 715 */ 716 public function onKill() { } 717 718 /** 588 719 * Handler for when a server response is received to a client-issued 589 720 * command. … … 592 723 */ 593 724 public function onResponse() { } 725 726 /** 727 * Handler for when PHP throws an error 728 * 729 * @return void 730 */ 731 public function onPHPError($errno, $errstr, $errfile, $errline) { return false; } 594 732 595 733 /** … … 605 743 { 606 744 // Silence output calls if the plugin is muted for that source or globally 607 $source = trim($arguments[0]); 608 if ((($source && isset($this->muted[$source]) && $this->muted[$source]) || 745 $source = null; 746 if (isset($arguments[0])) { 747 $source = trim($arguments[0]); 748 } 749 if (((isset($source) && isset($this->muted[$source]) && $this->muted[$source]) || 609 750 (isset($this->muted['global']) && $this->muted['global'])) && 610 751 substr($method, 0, 2) === 'do') { trunk/Phergie/Plugin/Abstract/Command.php
r179 r193 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 /** … … 19 19 */ 20 20 private $methods; 21 22 /** 23 * Flag indicating whether or not the plugin is an admin plugin or not 24 * 25 * @var bool 26 */ 27 public $needsAdmin = false; 21 28 22 29 /** … … 36 43 * 37 44 * @param string $message Message to analyze 45 * @param bool $ignorePrefix Whether or not to ignore the command prefix 46 * @param bool $forceBotPrefix Whether or not to require the bot's name as a 47 * prefix 38 48 * @return void 39 49 */ … … 52 62 } 53 63 } 64 } 65 66 // Checks to see if the plugin is an admin plugin and run the checks 67 if ($this->needsAdmin) { 68 if (!$this->fromAdmin()) { 69 return; 70 } 71 $ignorePrefix = $forceBotPrefix = true; 54 72 } 55 73