public function testLoadVendorDatabaseFromFile() { // Clear database first to ensure that data actually gets loaded MacAddress::loadVendorDatabase(array()); // Pass default database. It should load without errors. MacAddress::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); $this->assertAttributeNotEmpty('_vendorList', 'Library\\MacAddress'); }
public function testLoad() { $loader = new \Library\I18n\Translator\Loader\Po(); $textDomain = $loader->load('de', \Library\Module::getPath('data/Test/I18n/Translator/Loader/PoTest.po')); $this->assertInstanceOf('Zend\\I18n\\Translator\\TextDomain', $textDomain); $translations = array('single2single' => 'single to single', 'single2multi' => 'single to multi', 'multi2single' => 'multi to single', 'multi2multi' => 'multi to multi', "\\\n\"" => "\"\n\\"); $this->assertEquals($translations, $textDomain->getArrayCopy()); }
public function testLoadVendorDatabaseFromFile() { // Clear database first to ensure that data actually gets loaded MacAddress::loadVendorDatabase(array()); // Pass default database. It should load without errors. MacAddress::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); $reflectionClass = new \ReflectionClass('Library\\MacAddress'); $this->assertNotEmpty($reflectionClass->getStaticProperties()['_vendorList']); }
public function loadSettings() { $this->setCommand(['trigger' => 'cmd', 'action' => 'trigger', 'arguments' => -1, 'permit' => true]); $this->setCommand(['trigger' => 'bye', 'action' => 'quit', 'permit' => true]); $this->setCommand(['trigger' => 'restart', 'action' => 'restart', 'permit' => true]); $this->setCommand(['arguments' => -1, 'trigger' => 'say', 'action' => 'say', 'permit' => true]); $this->setCommand(['arguments' => 1, 'trigger' => 'part', 'action' => 'part', 'help' => 'Type "!part #<channel>" for part a channel.', 'permit' => true]); $this->setCommand(['arguments' => 1, 'trigger' => 'join', 'action' => 'join', 'help' => 'Type "!join #<channel>" for join to channel.', 'permit' => true]); $this->setCommand(['arguments' => -1, 'trigger' => 'help', 'action' => 'help', 'help' => 'Type "!help" for help or "!help <command>" for help for command.', 'permit' => false]); parent::loadSettings($this); }
private function main() { while (1) { $data = trim(str_replace([chr(9), chr(10), chr(11), chr(13), chr(0)], '', $this->connection->getData())); $this->checkStatus($data); if (!empty($this->buffer)) { $this->flushBuffer(); } if (empty($data) || !$this->chat->setIncommingData((string) $data)) { if ($this->channelList) { Module::executeListener(); } sleep(1); continue; } foreach ($this->module as $module) { $module->execute(); if (strpos($this->getMessage(), Config::$commandPrefix) === 0) { $module->executeCommand(); } } } }
private function shortIt($url, $md5) { if (!self::API_SHORT) { return $url; } parent::RedBeanConnect('short'); if ($fetch = @R::findOne('short_url', '`title` = ?', [$md5])) { return self::API_SHORT . $fetch->keyword; } $timestamp = date('Y-m-d H:i:s'); do { $uniq = ''; $base = strtolower(hash('sha256', uniqid())); while (strlen($uniq) < 8) { $uniq .= substr($base, (int) -(strlen($base) / (1 + strlen($uniq))), 1); } } while (@R::findOne('short_url', '`keyword` = ?', [$uniq])); $sql = 'INSERT INTO `short`.`short_url` '; $sql .= "(`keyword`, `url`, `title`, `timestamp`, `ip`, `clicks`) "; $sql .= "VALUES ('{$uniq}', '{$url}', '{$md5}', '{$timestamp}', '"; $sql .= getHostByName(getHostName()) . "', '0')"; R::exec($sql); R::close(); return 'http://exsubs.anidb.pl/short/' . $uniq; }
/** * Return the vendor for this address. * * If the database is empty, the default database is loaded. * * @return string Vendor or NULL if the address is not found in the database. */ public function getVendor() { if (empty(self::$_vendorList)) { self::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); } $addr = str_replace(':', '', $this->_address); // @codeCoverageIgnoreStart if (PHP_INT_SIZE < 8) { $addr = gmp_init($addr, 16); } else { $addr = hexdec($addr); } // @codeCoverageIgnoreEnd $longest = 0; $vendor = null; foreach (self::$_vendorList as $entry) { $mask = $entry['mask']; // Compare addresses only if this entry is more specific than the // last matching one. if ($mask > $longest and ($addr & $mask) == $entry['address']) { $vendor = $entry['vendor']; $longest = $mask; } } return $vendor; }
/** * Return the vendor for this address. * * If the database is empty, the default database is loaded. * * @return string Vendor or NULL if the address is not found in the database. */ public function getVendor() { if (empty(self::$_vendorList)) { self::loadVendorDatabaseFromFile(\Library\Module::getPath('data/MacAddress/manuf')); } $addr = str_replace(':', '', $this->_address); $longest = 0; $vendor = null; foreach (self::$_vendorList as $entry) { $length = $entry['length']; // Compare strings only if this entry is more specific than the // last matching one. The === operator is necessary to prevent // implicit casts that would lead to false positives with // "00:00:00" and similar. if ($length > $longest and substr($addr, 0, $length) === $entry['address']) { $vendor = $entry['vendor']; $longest = $length; } } return $vendor; }
public function loadSettings() { $this->setCommand(['trigger' => 'thsp', 'help' => 'I know some spell cards from touhou. Type "!thsp <game number or ' . 'short name>[/ or :]<number of spell>" to get some information about it. ' . '"!thsp list" list all cards', 'arguments' => 1, 'channels' => ['#touhoupl', '#xandros'], 'action' => 'action']); parent::loadSettings(); }
private function createTable() { parent::RedBeanConnect(self::DB_NAME); $sql = 'CREATE TABLE IF NOT EXISTS `' . self::TB_NAME . '`('; $sql .= '`id` int(10) NOT NULL AUTO_INCREMENT,'; $sql .= '`name` varchar(25),'; $sql .= '`orginal` varchar(45) NOT NULL,'; $sql .= '`icon` varchar(100) NOT NULL,'; $sql .= '`link` varchar(100) NOT NULL,'; $sql .= '`linkgc` varchar(100) NOT NULL,'; $sql .= 'PRIMARY KEY (`id`)'; $sql .= ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;'; $sql = trim($sql); R::exec($sql); R::close(); }
/** * @requires extension zip */ public function testZipArchiveCreation() { // The Zip extension does not support stream wrappers. Use real // filesystem objects instead. Since the target file must not exist, // tmpfile() is not suitable. Instead, use tempnam() with a dedicated // directory to get a safe filename and delete the created file. This // is mostly safe because the only source for filename clashes would be // another test running on the same tree in parallel, and the randomized // filename part reduces the risk even further. $tmpDir = \Library\Module::getPath('data/Test/ArchiveManager'); $archiveFile = tempnam($tmpDir, 'zip'); try { if (dirname($archiveFile) != $tmpDir) { throw new \UnexpectedValueException('Could not generate temporary file in safe location'); } unlink($archiveFile); $manager = new ArchiveManager(); $archive = $manager->createArchive(ArchiveManager::ZIP, $archiveFile); $manager->addFile($archive, __FILE__, 'äöü.txt'); $manager->closeArchive($archive); $this->assertFileExists($archiveFile); $this->assertTrue($manager->isArchive(ArchiveManager::ZIP, $archiveFile)); $testArchive = new \ZipArchive(); $this->assertTrue($testArchive->open($archiveFile)); $this->assertEquals(1, $testArchive->numFiles); $content = $testArchive->getFromName('äöü.txt'); $testArchive->close(); $this->assertNotFalse($content); // Message is easier readable in case of error $this->assertEquals(file_get_contents(__FILE__), $content); unlink($archiveFile); } catch (\Exception $e) { if ($archiveFile) { @unlink($archiveFile); throw $e; } } }
public function __construct() { parent::__construct(); libxml_use_internal_errors(true); }