/** * @return Storage */ static function storage() { global $argv; try { if (!isset($argv[1])) { throw new StorageException("No json file in arguments", StorageException::DATA_FILE_NOT_FOUND); } $storage = new Storage($argv[1]); } catch (StorageException $e) { if ($e->getCode() == StorageException::DATA_FILE_NOT_FOUND) { log_msg('Loader::storage >> no json file'); // User input echo "Put your key:" . PHP_EOL; $handle = fopen("php://stdin", "r"); $line = fgets($handle); $_input_key = trim($line); fclose($handle); echo "Put your secret:" . PHP_EOL; $handle = fopen("php://stdin", "r"); $line = fgets($handle); $_input_secret = trim($line); fclose($handle); $storage = Storage::create($argv[1], $_input_key, $_input_secret); if (!$storage) { log_msg('Access denied to create file storage', true); } } else { log_msg($e->getMessage(), true); } } return $storage; }
/** * Method description * * More detailed method description * @param void * @return void */ function buildComplete() { if (!isset($this->tpl)) { $this->tpl = $this->createTemplate(); } if (Config::get("CACHE_STATIC_PAGES")) { $page = Controller::getInstance()->getPage(); $cn = Controller::getInstance()->getControllerName(); $storage = Storage::create("WHTML cache"); if (!$storage->is_set($cn . "_" . $page . "_" . $this->getId())) { $this->page_text = $this->getSrc() ? file_get_contents($this->getSrc()) : ($this->getText() ? $this->getText() : null); $storage->set($cn . "_" . $page . "_" . $this->getId(), array("text" => $this->page_text, "cache_time" => time())); } else { $p = $storage->get($cn . "_" . $page . "_" . $this->getId()); $mtime = 0; $changed = 0; if ($this->getSrc()) { if (fileChanged($this->getSrc(), $p['cache_time']) || Controller::getInstance()->XMLPageChanged($p['cache_time'])) { $this->page_text = $this->getSrc() ? file_get_contents($this->getSrc()) : ""; $storage->set($cn . "_" . $page . "_" . $this->getId(), array("text" => $this->page_text, "cache_time" => time())); } else { $this->page_text = $p['text']; } } else { $this->page_text = $this->getText(); } } } else { $this->page_text = $this->getSrc() ? file_get_contents($this->getSrc()) : ($this->getText() ? $this->getText() : null); } parent::buildComplete(); }
public function init() { if (Config::getInstance()->language->cache_langs) { self::$langs_cache = Storage::create('__Language::list__'); } if (Config::getInstance()->language->cache_consts) { self::$const_cache = Storage::create('__Language::consts__'); } if (!isset(self::$langs_cache['__default__']) || !isset(self::$langs_cache['__list__'])) { try { $r = DB::query('select * from ' . self::LANGUAGE_TABLE); } catch (DBException $e) { if ($e->getCode() == 1146) { throw new LanguageException('Table "' . self::LANGUAGE_TABLE . '" not exists.', 1); } throw $e; } $list = array(); for ($i = 0, $c = count($r); $i < $c; $i++) { $cl = $r[$i]; $list[$cl['short_name']] = $cl['id']; self::$langs_cache[$cl['short_name']] = $cl['id']; if ($cl['default']) { self::$langs_cache['__default__'] = $cl['id']; } } self::$langs_cache['__list__'] = $list; } if (count(self::$langs_cache['__list__']) == 0) { throw new LanguageException('There isn\'t langauges (rows) in table "' . self::LANGUAGE_TABLE . '"', 2); } if (!isset(self::$langs_cache['__default__'])) { throw new LanguageException('Default language is not defined in table "' . self::LANGUAGE_TABLE . '"', 3); } self::determine(); }
function create($seg, $off, $name) { return parent::create(array('seg' => $seg, 'off' => $off, 'name' => $name)); }
/** * @param array $param * @return void */ public function save($sid, array $params) { $this->storage = Storage::create($this->getStorageName($sid), $params['time']); unset($params['time']); $this->storage['params'] = $params; }
/** * Flushes cached groups for given user. * Used only if acl.use and acl.cache_groups config flags are set to true values * * @param int id of user to flush cache * @return null */ static function flushCache($user_id) { if (!isset($user_id) || !is_numeric($user_id)) { throw new ACLException("Parameter 'user_id' has incorrect format"); } if (Config::getInstance()->acl->use && Config::getInstance()->acl->cache_groups) { Storage::create('acl_groups')->un_set($user_id); } }
function getImgSizeCache($path = null) { $v = Storage::create("images_size"); if (($ret = $v->get($path)) !== false && ($stat = stat(Config::get("root_dir") . Config::get("IMAGES_DIR") . "/" . $path)) !== false && $stat['mtime'] <= $ret['mtime']) { return $ret; } if (($ret = getImgSizeNoCache($path)) !== false) { if (($stat = stat(Config::get("root_dir") . Config::get("IMAGES_DIR") . "/" . $path)) !== false) { $ret['mtime'] = $stat['mtime']; } $v->set($path, $ret); return $ret; } return false; }
/** * returns storage (instantiate it if not yet). * @param string config section to take storage config from. * @return Storage * @author kstep */ public function getStorage($section = "storage") { $section = (string) $section; if (!$this->_storages[$section] && $this->_config[$section]) { $this->_storages[$section] = Storage::create($this->_config[$section]); } return $this->_storages[$section]; }