From: Luke Fitzgerald Date: Sun, 18 Jul 2010 13:28:15 +0000 (-0700) Subject: Merged in changes to Phergie X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7caff948f6cc70d8b14ddf02051476d8feb0c696;p=quix0rs-gnu-social.git Merged in changes to Phergie --- diff --git a/plugins/Irc/extlib/phergie/Phergie/Config.php b/plugins/Irc/extlib/phergie/Phergie/Config.php index f011db2365..c182f2ac1e 100755 --- a/plugins/Irc/extlib/phergie/Phergie/Config.php +++ b/plugins/Irc/extlib/phergie/Phergie/Config.php @@ -82,6 +82,22 @@ class Phergie_Config implements ArrayAccess return $this; } + /** + * Merges an associative array of configuration setting values into the + * current configuration settings. + * + * @param array $settings Associative array of configuration setting + * values keyed by setting name + * + * @return Phergie_Config Provides a fluent interface + */ + public function readArray(array $settings) + { + $this->settings += $settings; + + return $this; + } + /** * Writes the values of the current configuration settings back to their * originating files. diff --git a/plugins/Irc/extlib/phergie/Phergie/Db/Exception.php b/plugins/Irc/extlib/phergie/Phergie/Db/Exception.php deleted file mode 100644 index 77421108ad..0000000000 --- a/plugins/Irc/extlib/phergie/Phergie/Db/Exception.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @copyright 2008-2010 Phergie Development Team (http://phergie.org) - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie - */ - -/** - * Exceptions related to handling databases for plugins. - * - * @category Phergie - * @package Phergie - * @author Phergie Development Team - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie - */ - -class Phergie_Db_Exception extends Phergie_Exception -{ - /** - * Error indicating that a directory needed to support database - * functionality was unable to be created. - */ - const ERR_UNABLE_TO_CREATE_DIRECTORY = 1; -} diff --git a/plugins/Irc/extlib/phergie/Phergie/Db/Manager.php b/plugins/Irc/extlib/phergie/Phergie/Db/Manager.php deleted file mode 100755 index 2a8215e96d..0000000000 --- a/plugins/Irc/extlib/phergie/Phergie/Db/Manager.php +++ /dev/null @@ -1,49 +0,0 @@ - - * @copyright 2008-2010 Phergie Development Team (http://phergie.org) - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie_Command - */ - -/** - * Database management class. Provides a base API for managing databases - * within - * - * @category Phergie - * @package Phergie - * @author Phergie Development Team - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie_Db_Manager - */ -abstract class Phergie_Db_Manager -{ - /** - * Returns a connection to the database. - * - * @return object - */ - public abstract function getDb(); - - /** - * Checks if a table/collection exists within the database. - * - * @param string $table Table/collection name to check for - * - * @return boolean - */ - public abstract function hasTable($table); -} diff --git a/plugins/Irc/extlib/phergie/Phergie/Db/Sqlite.php b/plugins/Irc/extlib/phergie/Phergie/Db/Sqlite.php deleted file mode 100644 index 14ee520fd1..0000000000 --- a/plugins/Irc/extlib/phergie/Phergie/Db/Sqlite.php +++ /dev/null @@ -1,117 +0,0 @@ - - * @copyright 2008-2010 Phergie Development Team (http://phergie.org) - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie - */ - -/** - * Provides basic management for SQLite databases - * - * @category Phergie - * @package Phergie - * @author Phergie Development Team - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie - */ -class Phergie_Db_Sqlite extends Phergie_Db_Manager -{ - /** - * Database connection - * - * @var PDO - */ - protected $db; - - /** - * Database file path - * - * @var string - */ - protected $dbFile; - - /** - * Allows setting of the database file path when creating the class. - * - * @param string $dbFile database file path (optional) - * - * @return void - */ - public function __construct($dbFile = null) - { - if ($dbFile != null) { - $this->setDbFile($dbFile); - } - } - - /** - * Sets the database file path. - * - * @param string $dbFile SQLite database file path - * - * @return null - */ - public function setDbFile($dbFile) - { - if (is_string($dbFile) && !empty($dbFile)) { - $this->dbFile = $dbFile; - } - } - - /** - * Returns a configured database connection. - * - * @return PDO - */ - public function getDb() - { - if (!empty($this->db)) { - return $this->db; - } - - $dir = dirname($this->dbFile); - if (!is_dir($dir) && !mkdir($dir, 0755, true)) { - throw new Phergie_Db_Exception( - 'Unable to create directory', - Phergie_Db_Exception::ERR_UNABLE_TO_CREATE_DIRECTORY - ); - } - - $this->db = new PDO('sqlite:' . $this->dbFile); - - return $this->db; - } - - - /** - * Returns whether a given table exists in the database. - * - * @param string $table Name of the table to check for - * - * @return boolean TRUE if the table exists, FALSE otherwise - */ - public function hasTable($table) - { - $db = $this->getDb(); - - return (bool) $db->query( - 'SELECT COUNT(*) FROM sqlite_master WHERE name = ' - . $db->quote($table) - )->fetchColumn(); - } -} diff --git a/plugins/Irc/extlib/phergie/Phergie/ExtendedConfig.php b/plugins/Irc/extlib/phergie/Phergie/ExtendedConfig.php deleted file mode 100644 index 4ae6b0293c..0000000000 --- a/plugins/Irc/extlib/phergie/Phergie/ExtendedConfig.php +++ /dev/null @@ -1,51 +0,0 @@ -. - * - * Extends the configuration class (Phergie_Config) to allow passing config - * array instead of loading from file - * - * @category Phergie - * @package Phergie_Extended_Config - * @author Luke Fitzgerald - * @copyright 2010 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 - * @link http://status.net/ - */ -class Phergie_Extended_Config extends Phergie_Config { - /** - * Incorporates an associative array of settings into the current - * configuration settings. - * - * @param array $array Array of settings - * - * @return Phergie_Config Provides a fluent interface - * @throws Phergie_Config_Exception - */ - public function readArray($array) { - $settings = $array; - if (!is_array($settings)) { - throw new Phergie_Config_Exception( - 'Parameter is not an array', - Phergie_Config_Exception::ERR_ARRAY_NOT_RETURNED - ); - } - - $this->settings += $settings; - - return $this; - } -} diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php index c3af4ed42d..ff181d94e2 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php @@ -1,4 +1,23 @@ + * @copyright 2008-2010 Phergie Development Team (http://phergie.org) + * @license http://phergie.org/license New BSD License + * @link http://pear.phergie.org/package/Phergie_Plugin_NickServ + */ /** * Intercepts and responds to messages from the NickServ agent requesting that @@ -6,10 +25,18 @@ * * The password configuration setting should contain the password registered * with NickServ for the nick used by the bot. + * + * @category Phergie + * @package Phergie_Plugin_NickServ + * @author Phergie Development Team + * @license http://phergie.org/license New BSD License + * @link http://pear.phergie.org/package/Phergie_Plugin_NickServ + * @uses Phergie_Plugin_Command pear.phergie.org */ -class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { +class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract +{ /** - * The name of the nickserv bot + * Nick of the NickServ bot * * @var string */ @@ -21,20 +48,25 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { protected $identifyMessage; /** - * Initializes instance variables. + * Checks for dependencies and required configuration settings. * * @return void */ - public function onLoad() { + public function onLoad() + { $this->getPluginHandler()->getPlugin('Command'); // Get the name of the NickServ bot, defaults to NickServ $this->botNick = $this->config['nickserv.botnick']; - if (!$this->botNick) $this->botNick = 'NickServ'; + if (!$this->botNick) { + $this->botNick = 'NickServ'; + } // Get the identify message $this->identifyMessage = $this->config['nickserv.identify_message']; - if (!$this->identifyMessage) $this->identifyMessage = 'This nickname is registered.'; + if (!$this->identifyMessage) { + $this->identifyMessage = 'This nickname is registered.'; + } } /** @@ -44,7 +76,8 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { * * @return void */ - public function onNotice() { + public function onNotice() + { $event = $this->event; if (strtolower($event->getNick()) == strtolower($this->botNick)) { $message = $event->getArgument(1); @@ -62,14 +95,15 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { } /** - * Checks to see if the original Nick has quit, if so, take the name back + * Checks to see if the original nick has quit; if so, take the name back. * * @return void */ - public function onQuit() { - $eventnick = $this->event->getNick(); + public function onQuit() + { + $eventNick = $this->event->getNick(); $nick = $this->connection->getNick(); - if ($eventnick == $nick) { + if ($eventNick == $nick) { $this->doNick($nick); } } @@ -80,7 +114,8 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { * * @return void */ - public function onNick() { + public function onNick() + { $event = $this->event; $connection = $this->connection; if ($event->getNick() == $connection->getNick()) { @@ -93,7 +128,8 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { * * @return void */ - public function onDoGhostbust() { + public function onCommandGhostbust() + { $event = $this->event; $user = $event->getNick(); $conn = $this->connection; @@ -102,42 +138,44 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract { if ($nick != $this->config['connections'][$conn->getHost()]['nick']) { $password = $this->config['nickserv.password']; if (!empty($password)) { - $this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $nick .'.'); + $this->doPrivmsg( + $this->event->getSource(), + $user . ': Attempting to ghost ' . $nick .'.' + ); $this->doPrivmsg( $this->botNick, 'GHOST ' . $nick . ' ' . $password, true ); } - unset($password); } } /** - * Automatically send the GHOST command if the Nickname is in use + * Automatically send the GHOST command if the bot's nick is in use. * * @return void */ - public function onResponse() { + public function onResponse() + { if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) { $password = $this->config['nickserv.password']; if (!empty($password)) { $this->doPrivmsg( $this->botNick, - 'GHOST ' . $this->connection->getNick() . ' ' . $password, - true + 'GHOST ' . $this->connection->getNick() . ' ' . $password ); } - unset($password); } } /** - * The server sent a KILL request, so quit the server + * Handle the server sending a KILL request. * * @return void */ - public function onKill() { + public function onKill() + { $this->doQuit($this->event->getArgument(1)); } } diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Tld.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Tld.php index 21ba1e6719..5efc265c64 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Tld.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Tld.php @@ -30,6 +30,8 @@ * @license http://phergie.org/license New BSD License * @link http://pear.phergie.org/package/Phergie_Plugin_Tld * @uses Phergie_Plugin_Http pear.phergie.org + * @uses extension PDO + * @uses extension pdo_sqlite * * @pluginDesc Provides information for a top level domain. */ @@ -78,116 +80,22 @@ class Phergie_Plugin_Tld extends Phergie_Plugin_Abstract ); } + $dbFile = dirname(__FILE__) . '/Tld/tld.db'; try { - $dbFile = dirname(__FILE__) . '/Tld/tld.db'; - $dbManager = new Phergie_Db_Sqlite($dbFile); - $this->db = $dbManager->getDb(); - if (!$dbManager->hasTable('tld')) { - $query = 'CREATE TABLE tld (' - . 'tld VARCHAR(20), ' - . 'type VARCHAR(20), ' - . 'description VARCHAR(255))'; - - $this->db->exec($query); - - // prepare a statement to populate the table with - // tld information - $insert = $this->db->prepare( - 'INSERT INTO tld - (tld, type, description) - VALUES (:tld, :type, :description)' - ); - - // grab tld data from iana.org... - $contents = file_get_contents( - 'http://www.iana.org/domains/root/db/' - ); - - // ...and then parse it out - $regex = '{length - 1) as $index) { + $row = $rows->item($index); + $tld = strtolower(ltrim($row->childNodes->item(0)->textContent, '.')); + $type = $row->childNodes->item(1)->nodeValue; + if (isset($descriptions[$tld])) { + $description = $descriptions[$tld]; + } else { + $description = $row->childNodes->item(2)->textContent; + $regex = '{(^(?:Reserved|Restricted)\s*(?:exclusively\s*)?' + . '(?:for|to)\s*(?:members of\s*)?(?:the|support)?' + . '\s*|\s*as advised.*$)}i'; + $description = preg_replace($regex, '', $description); + $description = ucfirst(trim($description)); + } + $data = array_map( + 'html_entity_decode', + array( + 'tld' => $tld, + 'type' => $type, + 'description' => $description + ) + ); + $insert->execute($data); +} diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Twitter.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Twitter.php index 91f177d2ae..4a77d1e418 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Twitter.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Twitter.php @@ -1,6 +1,6 @@ * @copyright 2008-2010 Phergie Development Team (http://phergie.org) @@ -20,7 +20,7 @@ */ /** - * These requires are for library code, so they don't fit Autoload's normal + * These requires are for library code, so they don't fit Autoload's normal * conventions. * * @link http://github.com/scoates/simpletweet @@ -67,11 +67,6 @@ class Phergie_Plugin_Twitter extends Phergie_Plugin_Abstract */ protected $twitterpassword = null; - /** - * Allow only admins to tweet - */ - protected $requireAdmin = true; - /** * Register with the URL plugin, if possible * @@ -91,13 +86,6 @@ class Phergie_Plugin_Twitter extends Phergie_Plugin_Abstract */ public function onLoad() { - // see if tweetrequireadmin defined in config - if (isset($this->config['twitter.tweetrequireadmin']) - && $req = $this->config['twitter.tweetrequireadmin'] - ) { - // if so, override default - $this->requireAdmin = $req; - } if (!isset($this->config['twitter.class']) || !$twitterClass = $this->config['twitter.class'] ) { @@ -150,14 +138,10 @@ class Phergie_Plugin_Twitter extends Phergie_Plugin_Abstract */ public function onCommandTweet($txt) { - echo "Tweet!\n"; $nick = $this->getEvent()->getNick(); if (!$this->twitteruser) { return; } - if ($this->requireAdmin && !$this->fromAdmin(true)) { - return; - } $source = $this->getEvent()->getSource(); if ($tweet = $this->twitter->sendTweet($txt)) { $this->doPrivmsg( @@ -173,7 +157,7 @@ class Phergie_Plugin_Twitter extends Phergie_Plugin_Abstract * Formats a Tweet into a message suitable for output * * @param object $tweet JSON-decoded tweet object from Twitter - * @param bool $includeUrl whether or not to include the URL in the + * @param bool $includeUrl whether or not to include the URL in the * formatted output * * @return string @@ -218,6 +202,5 @@ class Phergie_Plugin_Twitter extends Phergie_Plugin_Abstract // if we get this far, we haven't satisfied the URL, so bail: return false; - } } diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Weather.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Weather.php old mode 100755 new mode 100644 index 7d3cc1de03..499cd9d556 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Weather.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Weather.php @@ -55,6 +55,30 @@ class Phergie_Plugin_Weather extends Phergie_Plugin_Abstract } } + /** + * Converts a temperature in Celsius to Fahrenheit. + * + * @param int $temp Temperature in Celsius + * + * @return int Temperature converted to Fahrenheit + */ + public function convertCelsiusToFahrenheit($temp) + { + return round(((((int) $temp * 9) / 5) + 32)); + } + + /** + * Converts a temperature in Fahrenheit to Celsius. + * + * @param int $temp Temperature in Fahrenheit + * + * @return int Temperature converted to Celsius + */ + public function convertFahrenheitToCelsius($temp) + { + return round(((((int) $temp - 32) * 5) / 9)); + } + /** * Returns a weather report for a specified location. * @@ -107,18 +131,44 @@ class Phergie_Plugin_Weather extends Phergie_Plugin_Abstract $xml = $response->getContent(); $weather = 'Weather for ' . (string) $xml->loc->dnam . ' - '; - $weather .= 'Current temperature ' . - (string) $xml->cc->tmp . - (string) $xml->head->ut . ' / '; - if ((string) $xml->head->ut == 'F') { - $weather .= round(((((int) $xml->cc->tmp - 32) * 5) / 9)) . 'C'; - } else { - $weather .= round(((((int) $xml->cc->tmp * 9) / 5) + 32)) . 'F'; + switch ($xml->head->ut) { + case 'F': + $tempF = $xml->cc->tmp; + $tempC = $this->convertFahrenheitToCelsius($tempF); + break; + case 'C': + $tempC = $xml->cc->tmp; + $tempF = $this->convertCelsiusToFahrenheit($tempC); + break; + default: + $this->doNotice( + $this->event->getNick(), + 'ERROR: No scale information given.'); + break; + } + $r = $xml->cc->hmid; + $tempF2 = $tempF * $tempF; + $r2 = $r * $r; + $hiF = round( + -42.379 + + (2.04901523 * $tempF) + + (10.14333127 * $r) - + (.22475541 * $tempF * $r) - + (6.83783 * pow(10,-3) * $tempF2) - + (5.481717 * pow(10,-2) * $r2) + + (1.22874 * pow(10,-3) * $tempF2 * $r) + + (8.5282 * pow(10,-4) * $tempF * $r2) - + (1.99 * pow(10,-6) * $tempF2 * $r2) + ); + $hiC = $this->convertFahrenheitToCelsius($hiF); + $weather .= 'Temperature: ' . $tempF . 'F/' . $tempC . 'C'; + $weather .= ', Humidity: ' . (string) $xml->cc->hmid . '%'; + if ($hiF > $tempF || $hiC > $tempC) { + $weather .= ', Heat Index: ' . $hiF . 'F/' . $hiC . 'C'; } $weather .= - ', Relative humidity ' . (string) $xml->cc->hmid . '%' . - ', Current conditions ' . (string) $xml->cc->t . - ', Last update ' . (string) $xml->cc->lsup . + ', Conditions: ' . (string) $xml->cc->t . + ', Updated: ' . (string) $xml->cc->lsup . ' [ http://weather.com/weather/today/' . str_replace( array('(', ')', ',', ' '),