hasIdentity()) { $data = $auth->getIdentity(); if (!class_exists($authAdapterClassName, true)) { return false; } /** @var $authAdapter Qs_Auth_Adapter_DbTable */ $authAdapter = new $authAdapterClassName(); $authAdapter->setIdentity($data); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { self::$_userData = $auth->getData(); return true; } else { $auth->clearIdentity(); } } return false; } /** * @static * @param string $type * @return bool */ protected static function _switchSession($type) { if (null === self::$_sessionNameBackup) { self::$_sessionNameBackup = session_name(); } $roles = self::_getSessionConfig('rolePostfix'); if (is_array($roles)) { foreach ($roles as $role) { if ($role['currentPagePrefix'] == $type) { $sessionName = __getSessionName($type); __switchSession($sessionName); } } } return true; } protected static function _restoreSession() { if (null !== self::$_sessionNameBackup && self::$_sessionNameBackup != session_name()) { __switchSession(self::$_sessionNameBackup); } return true; } /** * @static * @param string|null $var * @return mixed */ protected static function _getSessionConfig($var = null) { if (null === self::$_sessionConfig) { self::$_sessionConfig = Zend_Registry::get('config')->session->toArray(); } if (null !== $var) { return Qs_Array::get(self::$_sessionConfig, $var); } return self::$_sessionConfig; } public static function getBaseUrl() { return Qs_Constant::get('BASE_URL') . '/userfiles/' . self::_getPathPrefix() . '/'; } public static function getBaseDir() { return Qs_Constant::get('WWW_PATH') . '/userfiles/' . self::_getPathPrefix() . '/'; } protected static function _getPathPrefix() { $isAdmin = self::_checkAuth4Type(self::AUTH_TYPE_ADMIN); $adminFinderUserId = self::getFinderUserId(); self::_restoreSession(); if ($isAdmin) { if ($adminFinderUserId) { return self::getUserDir($adminFinderUserId) . '/ckfiles'; } return 'ckfiles'; } else { $isUser = self::_checkAuth4Type(self::AUTH_TYPE_USER); self::_restoreSession(); if ($isUser) { if (empty(self::$_userData) || empty(self::$_userData['id'])) { throw new Exception('FCFinder: unknown user.'); } return self::getUserDir(self::$_userData['id']) . '/ckfiles'; } } throw new Exception('FCFinder: authentication failed.'); } public static function getUserDir($userId) { if (empty($userId)) { throw new Exception('FCFinder: user id is required'); } return 'members/' . sha1('member' . $userId); } public static function setFinderUserId($userId) { $session = new Qs_Session_Namespace(self::class); $session->finderUserId = $userId; } public static function getFinderUserId() { $session = new Qs_Session_Namespace(self::class); return $session->finderUserId; } }