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.
+++ /dev/null
-<?php
-/**
- * Phergie
- *
- * PHP version 5
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.
- * It is also available through the world-wide-web at this URL:
- * http://phergie.org/license
- *
- * @category Phergie
- * @package Phergie
- * @author Phergie Development Team <team@phergie.org>
- * @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 <team@phergie.org>
- * @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;
-}
+++ /dev/null
-<?php
-/**
- * Phergie
- *
- * PHP version 5
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.
- * It is also available through the world-wide-web at this URL:
- * http://phergie.org/license
- *
- * @category Phergie
- * @package Phergie
- * @author Phergie Development Team <team@phergie.org>
- * @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 <team@phergie.org>
- * @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);
-}
+++ /dev/null
-<?php
-
-/**
- * Phergie
- *
- * PHP version 5
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.
- * It is also available through the world-wide-web at this URL:
- * http://phergie.org/license
- *
- * @category Phergie
- * @package Phergie
- * @author Phergie Development Team <team@phergie.org>
- * @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 <team@phergie.org>
- * @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();
- }
-}
+++ /dev/null
-<?php\r
-/**\r
- * StatusNet - the distributed open-source microblogging tool\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Affero General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU Affero General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Affero General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- * Extends the configuration class (Phergie_Config) to allow passing config\r
- * array instead of loading from file\r
- *\r
- * @category Phergie\r
- * @package Phergie_Extended_Config\r
- * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>\r
- * @copyright 2010 StatusNet, Inc.\r
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0\r
- * @link http://status.net/\r
- */\r
-class Phergie_Extended_Config extends Phergie_Config {\r
- /**\r
- * Incorporates an associative array of settings into the current\r
- * configuration settings.\r
- *\r
- * @param array $array Array of settings\r
- *\r
- * @return Phergie_Config Provides a fluent interface\r
- * @throws Phergie_Config_Exception\r
- */\r
- public function readArray($array) {\r
- $settings = $array;\r
- if (!is_array($settings)) {\r
- throw new Phergie_Config_Exception(\r
- 'Parameter is not an array',\r
- Phergie_Config_Exception::ERR_ARRAY_NOT_RETURNED\r
- );\r
- }\r
-\r
- $this->settings += $settings;\r
-\r
- return $this;\r
- }\r
-}\r
<?php\r
+/**\r
+ * Phergie\r
+ *\r
+ * PHP version 5\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://phergie.org/license\r
+ *\r
+ * @category Phergie\r
+ * @package Phergie_Plugin_NickServ\r
+ * @author Phergie Development Team <team@phergie.org>\r
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)\r
+ * @license http://phergie.org/license New BSD License\r
+ * @link http://pear.phergie.org/package/Phergie_Plugin_NickServ\r
+ */\r
\r
/**\r
* Intercepts and responds to messages from the NickServ agent requesting that\r
*\r
* The password configuration setting should contain the password registered\r
* with NickServ for the nick used by the bot.\r
+ *\r
+ * @category Phergie\r
+ * @package Phergie_Plugin_NickServ\r
+ * @author Phergie Development Team <team@phergie.org>\r
+ * @license http://phergie.org/license New BSD License\r
+ * @link http://pear.phergie.org/package/Phergie_Plugin_NickServ\r
+ * @uses Phergie_Plugin_Command pear.phergie.org\r
*/\r
-class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract {\r
+class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract\r
+{\r
/**\r
- * The name of the nickserv bot\r
+ * Nick of the NickServ bot\r
*\r
* @var string\r
*/\r
protected $identifyMessage;\r
\r
/**\r
- * Initializes instance variables.\r
+ * Checks for dependencies and required configuration settings.\r
*\r
* @return void\r
*/\r
- public function onLoad() {\r
+ public function onLoad()\r
+ {\r
$this->getPluginHandler()->getPlugin('Command');\r
\r
// Get the name of the NickServ bot, defaults to NickServ\r
$this->botNick = $this->config['nickserv.botnick'];\r
- if (!$this->botNick) $this->botNick = 'NickServ';\r
+ if (!$this->botNick) {\r
+ $this->botNick = 'NickServ';\r
+ }\r
\r
// Get the identify message\r
$this->identifyMessage = $this->config['nickserv.identify_message'];\r
- if (!$this->identifyMessage) $this->identifyMessage = 'This nickname is registered.';\r
+ if (!$this->identifyMessage) {\r
+ $this->identifyMessage = 'This nickname is registered.';\r
+ }\r
}\r
\r
/**\r
*\r
* @return void\r
*/\r
- public function onNotice() {\r
+ public function onNotice()\r
+ {\r
$event = $this->event;\r
if (strtolower($event->getNick()) == strtolower($this->botNick)) {\r
$message = $event->getArgument(1);\r
}\r
\r
/**\r
- * Checks to see if the original Nick has quit, if so, take the name back\r
+ * Checks to see if the original nick has quit; if so, take the name back.\r
*\r
* @return void\r
*/\r
- public function onQuit() {\r
- $eventnick = $this->event->getNick();\r
+ public function onQuit()\r
+ {\r
+ $eventNick = $this->event->getNick();\r
$nick = $this->connection->getNick();\r
- if ($eventnick == $nick) {\r
+ if ($eventNick == $nick) {\r
$this->doNick($nick);\r
}\r
}\r
*\r
* @return void\r
*/\r
- public function onNick() {\r
+ public function onNick()\r
+ {\r
$event = $this->event;\r
$connection = $this->connection;\r
if ($event->getNick() == $connection->getNick()) {\r
*\r
* @return void\r
*/\r
- public function onDoGhostbust() {\r
+ public function onCommandGhostbust()\r
+ {\r
$event = $this->event;\r
$user = $event->getNick();\r
$conn = $this->connection;\r
if ($nick != $this->config['connections'][$conn->getHost()]['nick']) {\r
$password = $this->config['nickserv.password'];\r
if (!empty($password)) {\r
- $this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $nick .'.');\r
+ $this->doPrivmsg(\r
+ $this->event->getSource(),\r
+ $user . ': Attempting to ghost ' . $nick .'.'\r
+ );\r
$this->doPrivmsg(\r
$this->botNick,\r
'GHOST ' . $nick . ' ' . $password,\r
true\r
);\r
}\r
- unset($password);\r
}\r
}\r
\r
/**\r
- * Automatically send the GHOST command if the Nickname is in use\r
+ * Automatically send the GHOST command if the bot's nick is in use.\r
*\r
* @return void\r
*/\r
- public function onResponse() {\r
+ public function onResponse()\r
+ {\r
if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) {\r
$password = $this->config['nickserv.password'];\r
if (!empty($password)) {\r
$this->doPrivmsg(\r
$this->botNick,\r
- 'GHOST ' . $this->connection->getNick() . ' ' . $password,\r
- true\r
+ 'GHOST ' . $this->connection->getNick() . ' ' . $password\r
);\r
}\r
- unset($password);\r
}\r
}\r
\r
/**\r
- * The server sent a KILL request, so quit the server\r
+ * Handle the server sending a KILL request.\r
*\r
* @return void\r
*/\r
- public function onKill() {\r
+ public function onKill()\r
+ {\r
$this->doQuit($this->event->getArgument(1));\r
}\r
}\r
* @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.
*/
);
}
+ $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 = '{<tr class="iana-group[^>]*><td><a[^>]*>\s*\.?([^<]+)\s*'
- . '(?:<br/><span[^>]*>[^<]*</span>)?</a></td><td>\s*'
- . '([^<]+)\s*</td><td>\s*([^<]+)\s*}i';
- preg_match_all($regex, $contents, $matches, PREG_SET_ORDER);
-
- foreach ($matches as $match) {
- list(, $tld, $type, $description) = array_pad($match, 4, null);
- $type = trim(strtolower($type));
- if ($type != 'test') {
- $tld = trim(strtolower($tld));
- $description = trim($description);
-
- switch ($tld) {
-
- case 'com':
- $description = 'Commercial';
- break;
-
- case 'info':
- $description = 'Information';
- break;
-
- case 'net':
- $description = 'Network';
- break;
-
- case 'org':
- $description = 'Organization';
- break;
-
- case 'edu':
- $description = 'Educational';
- break;
-
- case 'name':
- $description = 'Individuals, by name';
- break;
- }
-
- if (empty($tld) || empty($description)) {
- continue;
- }
-
- $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);
- }
- }
-
- unset(
- $insert,
- $matches,
- $match,
- $contents,
- $tld,
- $type,
- $description,
- $data,
- $regex
- );
- }
-
- // Create a prepared statements for retrieving TLDs
- $this->select = $this->db->prepare(
- 'SELECT type, description '
- . 'FROM tld WHERE LOWER(tld) = LOWER(:tld)'
- );
-
- $this->selectAll = $this->db->prepare(
- 'SELECT tld, type, description FROM tld'
- );
+ $this->db = new PDO('sqlite:' . $dbFile);
+
+ $this->select = $this->db->prepare('
+ SELECT type, description
+ FROM tld
+ WHERE LOWER(tld) = LOWER(:tld)
+ ');
+
+ $this->selectAll = $this->db->prepare('
+ SELECT tld, type, description
+ FROM btld
+ ');
} catch (PDOException $e) {
+ $this->getPluginHandler()->removePlugin($this);
}
}
return false;
}
}
-
--- /dev/null
+<?php
+
+$dbFile = 'tld.db';
+
+if (file_exists($dbFile)) {
+ exit;
+}
+
+$db = new PDO('sqlite:' . dirname(__FILE__) . '/' . $dbFile);
+
+$query = '
+ CREATE TABLE tld (
+ tld VARCHAR(20),
+ type VARCHAR(20),
+ description VARCHAR(255)
+ )
+';
+$db->exec($query);
+
+$insert = $db->prepare('
+ INSERT INTO tld (tld, type, description)
+ VALUES (:tld, :type, :description)
+');
+
+$contents = file_get_contents(
+ 'http://www.iana.org/domains/root/db/'
+);
+
+libxml_use_internal_errors(true);
+$doc = new DOMDocument;
+$doc->loadHTML($contents);
+libxml_clear_errors();
+
+$descriptions = array(
+ 'com' => 'Commercial',
+ 'info' => 'Information',
+ 'net' => 'Network',
+ 'org' => 'Organization',
+ 'edu' => 'Educational',
+ 'name' => 'Individuals, by name'
+);
+
+$xpath = new DOMXPath($doc);
+$rows = $xpath->query('//tr[contains(@class, "iana-group")]');
+foreach (range(0, $rows->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);
+}
<?php
/**
- * Phergie
+ * Phergie
*
* PHP version 5
*
* It is also available through the world-wide-web at this URL:
* http://phergie.org/license
*
- * @category Phergie
+ * @category Phergie
* @package Phergie_Plugin_Twitter
* @author Phergie Development Team <team@phergie.org>
* @copyright 2008-2010 Phergie Development Team (http://phergie.org)
*/
/**
- * 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
*/
protected $twitterpassword = null;
- /**
- * Allow only admins to tweet
- */
- protected $requireAdmin = true;
-
/**
* Register with the URL plugin, if possible
*
*/
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']
) {
*/
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(
* 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
// if we get this far, we haven't satisfied the URL, so bail:
return false;
-
}
}
}
}
+ /**
+ * 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.
*
$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('(', ')', ',', ' '),