function getWeather($zip) { if (!$zip) { $zip = '02111'; } $file = file_get_contents('http://rss.weather.com/weather/rss/local/' . $zip . '?cm_ven=LWO&cm_cat=rss&par=LWO_rss'); $fs = new FileStorage($this->cache, FS_WRITE); $fs->write($file); $error = XMLParseFile($parser, $this->cache, 0); if ($error) { return $error; } else { $ret = array(); foreach ($parser->structure as $k => $v) { if (is_string($v) && strstr($v, 'For more') !== FALSE) { $v = str_replace('°', '°', $v); if (strstr($v, '---') !== FALSE) { $days = explode('---', $v); $junk = array_pop($days); $ret['forecast'] = $days; } else { $v = strip_tags($v); $ret['current'] = substr($v, 0, strpos($v, 'For more') - 1); } } if (count($ret) == 2) { break; } } } return $ret; }
function register() { $users = $this->getArgs(); if (count($users) == 1) { $users = array($this->getUser()); } else { array_shift($users); } foreach ($users as $u) { if (!$this->registered($u)) { $fs = new FileStorage(REG_USERS_FILE, FS_APPEND); $fs->write($u); $this->pm("I'll start to remember you now, {$u}."); } else { $this->pm("I know you already, {$u}."); } } }
/** remove a name from the known users list. @access public **/ function unreg() { $user = $this->getArg(1); if ($user) { $fs = new FileStorage(REG_USERS_FILE); $fs->read(); $new = array(); foreach ($fs->contents as $nick) { if ($nick != $user) { $new[] = $nick; } else { $found = true; $this->pm($nick . " removed."); } } if (!$found) { $this->pm($nick . " wasnt in the list."); } else { $fs = new FileStorage(REG_USERS_FILE, FS_WRITE); $fs->write($new); } } }
/** Writes bug items to file @access private @return void */ function write() { $fs = new FileStorage($this->bugfile, FS_WRITE); $fs->write($this->encode($this->bugs)); }
/*use Nette\Debug;*/ set_time_limit(0); function randomStr() { $s = str_repeat('LaTrine', rand(100, 20000)); return sha1($s, TRUE) . $s; } function checkStr($s) { return substr($s, 0, 20) === sha1(substr($s, 20), TRUE); } define('COUNT_FILES', 3); $storage = new FileStorage(dirname(__FILE__) . '/tmp'); // clear playground for ($i = 0; $i <= COUNT_FILES; $i++) { $storage->write($i, randomStr(), array()); } // test loop echo "Testing...\n"; Debug::timer(); $hits = array('ok' => 0, 'notfound' => 0, 'error' => 0, 'cantwrite' => 0, 'cantdelete' => 0); for ($counter = 0; $counter < 1000; $counter++) { // write $ok = $storage->write(rand(0, COUNT_FILES), randomStr(), array()); if ($ok === FALSE) { $hits['cantwrite']++; } // remove //$ok = $storage->remove(rand(0, COUNT_FILES)); //if (!$ok) $hits['cantdelete']++; // read
function conclude($user, $store = false) { if ($this->dialogs[$user]) { if ($store) { $fs = new FileStorage($this->dialogs[$user]->dataFile, FS_WRITE); $fs->write($this->dialogs[$user]->getResponses()); } unset($this->dialogs[$user]); return $this->concludeMsg; } else { return false; } }
/** Log a line @access private @param string line to log @param string /path/to/logfile @return void */ function log($line, $file) { if (!$this->logging) { return; } $fs = new FileStorage($file, FS_APPEND); $fs->write($line); }
function removeLink($handle) { $new = array(); $fs = new FileStorage($this->storage); $fs->read(); foreach ($fs->contents as $line) { $line = trim($line); $x = explode('::', $line, 2); if ($x[0] != $handle) { $new[] = $line; } } unset($this->handles[$handle]); $fs = new FileStorage($this->storage, FS_WRITE); $fs->write($new); $this->pm('toast.'); }