From 9383a15af699ede77142d040b65118e15754a2ca Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 25 Jan 2014 14:56:02 -0500 Subject: First commit --- models/config.php | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 models/config.php (limited to 'models/config.php') diff --git a/models/config.php b/models/config.php new file mode 100644 index 00000000..d854047d --- /dev/null +++ b/models/config.php @@ -0,0 +1,88 @@ + t('English'), + 'fr_FR' => t('French'), + ); + } + + public function get($name, $default_value = '') + { + if (! isset($_SESSION['config'][$name])) { + $_SESSION['config'] = $this->getAll(); + } + + if (isset($_SESSION['config'][$name])) { + return $_SESSION['config'][$name]; + } + + return $default_value; + } + + public function getAll() + { + return $this->db->table(self::TABLE)->findOne(); + } + + public function save(array $values) + { + $_SESSION['config'] = $values; + return $this->db->table(self::TABLE)->update($values); + } + + public function reload() + { + $_SESSION['config'] = $this->getAll(); + + $language = $this->get('language', 'en_US'); + if ($language !== 'en_US') \Translator\load($language); + } + + public function validateModification(array $values) + { + $v = new Validator($values, array( + new Validators\Required('language', t('The language is required')), + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + public static function generateToken() + { + if (ini_get('open_basedir') === '') { + return substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); + } + else { + return substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); + } + } + + public function optimizeDatabase() + { + $this->db->getconnection()->exec("VACUUM"); + } + + public function downloadDatabase() + { + return gzencode(file_get_contents(self::DB_FILENAME)); + } + + public function getDatabaseSize() + { + return filesize(self::DB_FILENAME); + } +} -- cgit v1.2.3