/** * Строим переводчик * @throws Exception */ public function __construct() { //Строим путь до базы $dir = APPLICATION_PATH . "/lang/"; //Получаем из куков язык if (class_exists("Boot_Cookie") && Boot_Cookie::get("lang")) { $lang = Boot_Cookie::get("lang"); } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); } else { $lang = "ru"; } //Проверяем директорию if (is_dir($dir) == false) { throw new Boot_Exception("База перевода не найдена", 500); } $this->_dir = $dir; //Если файл перевода не найден if (file_exists($dir . $lang . ".json") == false) { $lang = "ru"; if (class_exists("Boot_Cookie")) { Boot_Cookie::set('lang', $lang); } } //Парсим файл $this->parseJSON($lang); $this->_default = $lang; }
/** * Возвращаем авторизацию * @return Model_User */ public function getAuth() { if ($this->_me === null) { //Читаем токен $token = Boot_Cookie::get("auth_token"); //Разбиваем токен @(list($id, $skey, $sig) = explode("#", $token)); if (!$id || !$skey || !$sig) { $this->_me = false; Boot_Cookie::clear("auth_token"); return false; } //Получаем юзера try { $this->_me = Model_User::find($id); } catch (Exception $e) { $this->_me = false; } //Проверяем корректность if ($this->_me == false || $skey != Boot_Skey::get() || $sig != md5($id . $skey . $this->_me->skey)) { $this->_me = false; Boot_Cookie::clear("auth_token"); return false; } } return $this->_me; }