diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2013-05-30 11:20:22 -0400 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2013-05-30 11:20:22 -0400 |
commit | bd0d189f6fb96c3b21bd71c10349a02e6cc2e5d7 (patch) | |
tree | 0646d1900abe3dc7dc5ab86d449be056bc5e15ba /lib | |
parent | 16925672e885071afab1fe158dc206ab8ed93baf (diff) | |
parent | 476747ee892c0a97ca37547046189e4da5ffd573 (diff) | |
download | nextcloud-server-bd0d189f6fb96c3b21bd71c10349a02e6cc2e5d7.tar.gz nextcloud-server-bd0d189f6fb96c3b21bd71c10349a02e6cc2e5d7.zip |
Merge branch 'master' into googledrive
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 48 | ||||
-rw-r--r-- | lib/files.php | 5 | ||||
-rw-r--r-- | lib/files/cache/permissions.php | 20 | ||||
-rw-r--r-- | lib/files/cache/scanner.php | 15 | ||||
-rw-r--r-- | lib/files/view.php | 22 | ||||
-rw-r--r-- | lib/helper.php | 42 | ||||
-rw-r--r-- | lib/hooks/publicemitter.php | 20 | ||||
-rw-r--r-- | lib/l10n/fr.php | 1 | ||||
-rw-r--r-- | lib/l10n/ja_JP.php | 1 | ||||
-rw-r--r-- | lib/l10n/pt_PT.php | 1 | ||||
-rw-r--r-- | lib/l10n/sk_SK.php | 1 | ||||
-rw-r--r-- | lib/l10n/zh_TW.php | 1 | ||||
-rw-r--r-- | lib/mail.php | 2 | ||||
-rw-r--r-- | lib/session/internal.php | 39 | ||||
-rw-r--r-- | lib/session/memory.php | 63 | ||||
-rw-r--r-- | lib/session/session.php | 79 | ||||
-rw-r--r-- | lib/template.php | 8 | ||||
-rw-r--r-- | lib/user.php | 16 | ||||
-rwxr-xr-x | lib/util.php | 14 |
19 files changed, 325 insertions, 73 deletions
diff --git a/lib/base.php b/lib/base.php index 724bd250a5c..9d1d4b5e058 100644 --- a/lib/base.php +++ b/lib/base.php @@ -75,6 +75,11 @@ class OC { protected static $router = null; /** + * @var \OC\Session\Session + */ + public static $session = null; + + /** * @var \OC\Autoloader $loader */ public static $loader = null; @@ -253,7 +258,8 @@ class OC { public static function initTemplateEngine() { // Add the stuff we need always - OC_Util::addScript("jquery-1.7.2.min"); + OC_Util::addScript("jquery-1.10.0.min"); + OC_Util::addScript("jquery-migrate-1.2.1.min"); OC_Util::addScript("jquery-ui-1.10.0.custom"); OC_Util::addScript("jquery-showpassword"); OC_Util::addScript("jquery.infieldlabel"); @@ -283,14 +289,17 @@ class OC { $cookie_path = OC::$WEBROOT ?: '/'; ini_set('session.cookie_path', $cookie_path); - // set the session name to the instance id - which is unique - session_name(OC_Util::getInstanceId()); + try{ + // set the session name to the instance id - which is unique + self::$session = new \OC\Session\Internal(OC_Util::getInstanceId()); + // if session cant be started break with http 500 error + }catch (Exception $e){ + //set the session object to a dummy session so code relying on the session existing still works + self::$session = new \OC\Session\Memory(''); - // if session cant be started break with http 500 error - if (session_start() === false){ - OC_Log::write('core', 'Session could not be initialized', + OC_Log::write('core', 'Session could not be initialized', OC_Log::ERROR); - + header('HTTP/1.1 500 Internal Server Error'); OC_Util::addStyle("styles"); $error = 'Session could not be initialized. Please contact your '; @@ -304,15 +313,15 @@ class OC { } // regenerate session id periodically to avoid session fixation - if (!isset($_SESSION['SID_CREATED'])) { - $_SESSION['SID_CREATED'] = time(); - } else if (time() - $_SESSION['SID_CREATED'] > 60*60*12) { + if (!self::$session->exists('SID_CREATED')) { + self::$session->set('SID_CREATED', time()); + } else if (time() - self::$session->get('SID_CREATED') > 60*60*12) { session_regenerate_id(true); - $_SESSION['SID_CREATED'] = time(); + self::$session->set('SID_CREATED', time()); } // session timeout - if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 60*60*24)) { + if (self::$session->exists('LAST_ACTIVITY') && (time() - self::$session->get('LAST_ACTIVITY') > 60*60*24)) { if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time() - 42000, $cookie_path); } @@ -320,7 +329,8 @@ class OC { session_destroy(); session_start(); } - $_SESSION['LAST_ACTIVITY'] = time(); + + self::$session->set('LAST_ACTIVITY', time()); } public static function getRouter() { @@ -436,6 +446,8 @@ class OC { self::checkSSL(); if ( !self::$CLI ) { self::initSession(); + } else { + self::$session = new \OC\Session\Memory(''); } $errors = OC_Util::checkServer(); @@ -446,14 +458,14 @@ class OC { // User and Groups if (!OC_Config::getValue("installed", false)) { - $_SESSION['user_id'] = ''; + self::$session->set('user_id',''); } OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SESSION['user_id']) - && $_SERVER['PHP_AUTH_USER'] != $_SESSION['user_id']) { + if (isset($_SERVER['PHP_AUTH_USER']) && self::$session->exists('user_id') + && $_SERVER['PHP_AUTH_USER'] != self::$session->get('user_id')) { OC_User::logout(); } @@ -598,7 +610,7 @@ class OC { // Handle redirect URL for logged in users if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) { $location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url'])); - + // Deny the redirect if the URL contains a @ // This prevents unvalidated redirects like ?redirect_url=:user@domain.com if (strpos($location, '@') === false) { @@ -748,7 +760,7 @@ class OC { if (OC_User::login($_POST["user"], $_POST["password"])) { // setting up the time zone if (isset($_POST['timezone-offset'])) { - $_SESSION['timezone'] = $_POST['timezone-offset']; + self::$session->set('timezone', $_POST['timezone-offset']); } self::cleanupLoginTokens($_POST['user']); diff --git a/lib/files.php b/lib/files.php index ab7fa1ed096..abb1617c25e 100644 --- a/lib/files.php +++ b/lib/files.php @@ -123,8 +123,11 @@ class OC_Files { header('Content-Length: ' . filesize($filename)); self::addSendfileHeader($filename); }else{ + $filesize = \OC\Files\Filesystem::filesize($filename); header('Content-Type: '.\OC\Files\Filesystem::getMimeType($filename)); - header("Content-Length: ".\OC\Files\Filesystem::filesize($filename)); + if ($filesize > -1) { + header("Content-Length: ".$filesize); + } list($storage) = \OC\Files\Filesystem::resolvePath($filename); if ($storage instanceof \OC\Files\Storage\Local) { self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename)); diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php index faa5ff5eacc..29c30b0f36c 100644 --- a/lib/files/cache/permissions.php +++ b/lib/files/cache/permissions.php @@ -86,6 +86,26 @@ class Permissions { } /** + * get the permissions for all files in a folder + * + * @param int $parentId + * @param string $user + * @return int[] + */ + public function getDirectoryPermissions($parentId, $user) { + $query = \OC_DB::prepare('SELECT `*PREFIX*permissions`.`fileid`, `permissions` + FROM `*PREFIX*permissions` INNER JOIN `*PREFIX*filecache` ON `*PREFIX*permissions`.`fileid` = `*PREFIX*filecache`.`fileid` + WHERE `*PREFIX*filecache`.`parent` = ? AND `*PREFIX*permissions`.`user` = ?'); + + $result = $query->execute(array($parentId, $user)); + $filePermissions = array(); + while ($row = $result->fetchRow()) { + $filePermissions[$row['fileid']] = $row['permissions']; + } + return $filePermissions; + } + + /** * remove the permissions for a file * * @param int $fileId diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index 46122221dc2..8f9a7921956 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -78,18 +78,21 @@ class Scanner { $this->scanFile($parent); } } - if($cacheData = $this->cache->get($file)) { + $newData = $data; + if ($cacheData = $this->cache->get($file)) { + if ($checkExisting && $data['size'] === -1) { + $data['size'] = $cacheData['size']; + } if ($data['mtime'] === $cacheData['mtime'] && $data['size'] === $cacheData['size']) { $data['etag'] = $cacheData['etag']; } + // Only update metadata that has changed + $newData = array_diff($data, $cacheData); } - if ($checkExisting and $cacheData) { - if ($data['size'] === -1) { - $data['size'] = $cacheData['size']; - } + if (!empty($newData)) { + $this->cache->put($file, $newData); } - $this->cache->put($file, $data); } return $data; } diff --git a/lib/files/view.php b/lib/files/view.php index 8e7727d335c..ecb0f30400a 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -267,7 +267,7 @@ class View { $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) and Filesystem::isValidPath($path) - and ! Filesystem::isFileBlacklisted($path) + and !Filesystem::isFileBlacklisted($path) ) { $path = $this->getRelativePath($absolutePath); $exists = $this->file_exists($path); @@ -344,7 +344,7 @@ class View { \OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2) and Filesystem::isValidPath($path1) - and ! Filesystem::isFileBlacklisted($path2) + and !Filesystem::isFileBlacklisted($path2) ) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); @@ -371,7 +371,7 @@ class View { list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2); if ($storage) { $result = $storage->rename($internalPath1, $internalPath2); - \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2); + \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2); } else { $result = false; } @@ -418,7 +418,7 @@ class View { \OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and Filesystem::isValidPath($path2) and Filesystem::isValidPath($path1) - and ! Filesystem::isFileBlacklisted($path2) + and !Filesystem::isFileBlacklisted($path2) ) { $path1 = $this->getRelativePath($absolutePath1); $path2 = $this->getRelativePath($absolutePath2); @@ -632,7 +632,7 @@ class View { $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path)); if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and Filesystem::isValidPath($path) - and ! Filesystem::isFileBlacklisted($path) + and !Filesystem::isFileBlacklisted($path) ) { $path = $this->getRelativePath($absolutePath); if ($path == null) { @@ -760,7 +760,7 @@ class View { } } - $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data); + $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data); return $data; } @@ -797,18 +797,18 @@ class View { } $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter + $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user); $ids = array(); foreach ($files as $i => $file) { $files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file'; $ids[] = $file['fileid']; - $permissions = $permissionsCache->get($file['fileid'], $user); - if ($permissions === -1) { - $permissions = $storage->getPermissions($file['path']); - $permissionsCache->set($file['fileid'], $user, $permissions); + if (!isset($permissions[$file['fileid']])) { + $permissions[$file['fileid']] = $storage->getPermissions($file['path']); + $permissionsCache->set($file['fileid'], $user, $permissions[$file['fileid']]); } - $files[$i]['permissions'] = $permissions; + $files[$i]['permissions'] = $permissions[$file['fileid']]; } //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders diff --git a/lib/helper.php b/lib/helper.php index c69445ed788..225e9fd2a9a 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -27,6 +27,7 @@ class OC_Helper { private static $mimetypes=array(); private static $tmpFiles=array(); + private static $mimetypeIcons = array(); /** * @brief Creates an url using a defined route @@ -187,31 +188,38 @@ class OC_Helper { * * Returns the path to the image of this file type. */ - public static function mimetypeIcon( $mimetype ) { - $alias=array('application/xml'=>'code/xml'); - if(isset($alias[$mimetype])) { - $mimetype=$alias[$mimetype]; + public static function mimetypeIcon($mimetype) { + $alias = array('application/xml' => 'code/xml'); + if (isset($alias[$mimetype])) { + $mimetype = $alias[$mimetype]; + } + if (isset(self::$mimetypeIcons[$mimetype])) { + return self::$mimetypeIcons[$mimetype]; } // Replace slash and backslash with a minus - $mimetype = str_replace( "/", "-", $mimetype ); - $mimetype = str_replace( "\\", "-", $mimetype ); + $icon = str_replace('/', '-', $mimetype); + $icon = str_replace( '\\', '-', $icon); // Is it a dir? - if( $mimetype == "dir" ) { - return OC::$WEBROOT."/core/img/filetypes/folder.png"; + if ($mimetype === 'dir') { + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/folder.png'; + return OC::$WEBROOT.'/core/img/filetypes/folder.png'; } // Icon exists? - if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) { - return OC::$WEBROOT."/core/img/filetypes/$mimetype.png"; - } - //try only the first part of the filetype - $mimetype=substr($mimetype, 0, strpos($mimetype, '-')); - if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) { - return OC::$WEBROOT."/core/img/filetypes/$mimetype.png"; + if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$icon.'.png')) { + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png'; + return OC::$WEBROOT.'/core/img/filetypes/'.$icon.'.png'; } - else{ - return OC::$WEBROOT."/core/img/filetypes/file.png"; + + // Try only the first part of the filetype + $mimePart = substr($icon, 0, strpos($icon, '-')); + if (file_exists(OC::$SERVERROOT.'/core/img/filetypes/'.$mimePart.'.png')) { + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png'; + return OC::$WEBROOT.'/core/img/filetypes/'.$mimePart.'.png'; + } else { + self::$mimetypeIcons[$mimetype] = OC::$WEBROOT.'/core/img/filetypes/file.png'; + return OC::$WEBROOT.'/core/img/filetypes/file.png'; } } diff --git a/lib/hooks/publicemitter.php b/lib/hooks/publicemitter.php new file mode 100644 index 00000000000..e2371713ac3 --- /dev/null +++ b/lib/hooks/publicemitter.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Hooks; + +class PublicEmitter extends BasicEmitter { + /** + * @param string $scope + * @param string $method + * @param array $arguments optional + */ + public function emit($scope, $method, $arguments = array()) { + parent::emit($scope, $method, $arguments); + } +} diff --git a/lib/l10n/fr.php b/lib/l10n/fr.php index af4efc2b63f..aed5d056f37 100644 --- a/lib/l10n/fr.php +++ b/lib/l10n/fr.php @@ -24,6 +24,7 @@ "%s set the database host." => "%s spécifiez l'hôte de la base de données.", "PostgreSQL username and/or password not valid" => "Nom d'utilisateur et/ou mot de passe de la base PostgreSQL invalide", "You need to enter either an existing account or the administrator." => "Vous devez spécifier soit le nom d'un compte existant, soit celui de l'administrateur.", +"Oracle connection could not be established" => "La connexion Oracle ne peut pas être établie", "MySQL username and/or password not valid" => "Nom d'utilisateur et/ou mot de passe de la base MySQL invalide", "DB Error: \"%s\"" => "Erreur de la base de données : \"%s\"", "Offending command was: \"%s\"" => "La requête en cause est : \"%s\"", diff --git a/lib/l10n/ja_JP.php b/lib/l10n/ja_JP.php index 0e856b0497d..a2eb4bee67b 100644 --- a/lib/l10n/ja_JP.php +++ b/lib/l10n/ja_JP.php @@ -24,6 +24,7 @@ "%s set the database host." => "%s にデータベースホストを設定します。", "PostgreSQL username and/or password not valid" => "PostgreSQLのユーザ名もしくはパスワードは有効ではありません", "You need to enter either an existing account or the administrator." => "既存のアカウントもしくは管理者のどちらかを入力する必要があります。", +"Oracle connection could not be established" => "Oracleへの接続が確立できませんでした。", "MySQL username and/or password not valid" => "MySQLのユーザ名もしくはパスワードは有効ではありません", "DB Error: \"%s\"" => "DBエラー: \"%s\"", "Offending command was: \"%s\"" => "違反コマンド: \"%s\"", diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php index 176f4286c9d..f49258157ed 100644 --- a/lib/l10n/pt_PT.php +++ b/lib/l10n/pt_PT.php @@ -24,6 +24,7 @@ "%s set the database host." => "%s defina o servidor da base de dados (geralmente localhost)", "PostgreSQL username and/or password not valid" => "Nome de utilizador/password do PostgreSQL inválido", "You need to enter either an existing account or the administrator." => "Precisa de introduzir uma conta existente ou de administrador", +"Oracle connection could not be established" => "Não foi possível estabelecer a ligação Oracle", "MySQL username and/or password not valid" => "Nome de utilizador/password do MySQL inválida", "DB Error: \"%s\"" => "Erro na BD: \"%s\"", "Offending command was: \"%s\"" => "O comando gerador de erro foi: \"%s\"", diff --git a/lib/l10n/sk_SK.php b/lib/l10n/sk_SK.php index 121b2405dcf..c1ec2470b46 100644 --- a/lib/l10n/sk_SK.php +++ b/lib/l10n/sk_SK.php @@ -24,6 +24,7 @@ "%s set the database host." => "Zadajte názov počítača s databázou %s.", "PostgreSQL username and/or password not valid" => "Používateľské meno a/alebo heslo pre PostgreSQL databázu je neplatné", "You need to enter either an existing account or the administrator." => "Musíte zadať jestvujúci účet alebo administrátora.", +"Oracle connection could not be established" => "Nie je možné pripojiť sa k Oracle", "MySQL username and/or password not valid" => "Používateľské meno a/alebo heslo pre MySQL databázu je neplatné", "DB Error: \"%s\"" => "Chyba DB: \"%s\"", "Offending command was: \"%s\"" => "Podozrivý príkaz bol: \"%s\"", diff --git a/lib/l10n/zh_TW.php b/lib/l10n/zh_TW.php index ec7310d4e4e..4e0d50e7fc9 100644 --- a/lib/l10n/zh_TW.php +++ b/lib/l10n/zh_TW.php @@ -24,6 +24,7 @@ "%s set the database host." => "%s 設定資料庫主機。", "PostgreSQL username and/or password not valid" => "PostgreSQL 用戶名和/或密碼無效", "You need to enter either an existing account or the administrator." => "您必須輸入一個現有的帳號或管理員帳號。", +"Oracle connection could not be established" => "無法建立 Oracle 資料庫連線", "MySQL username and/or password not valid" => "MySQL 用戶名和/或密碼無效", "DB Error: \"%s\"" => "資料庫錯誤:\"%s\"", "Offending command was: \"%s\"" => "有問題的指令是:\"%s\"", diff --git a/lib/mail.php b/lib/mail.php index 61634632efc..e15af277a64 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -113,7 +113,7 @@ class OC_Mail { */ public static function getfooter() { - $txt="\n--\n"; + $txt="\n-- \n"; $txt.="ownCloud\n"; $txt.="Your Cloud, Your Data, Your Way!\n"; return($txt); diff --git a/lib/session/internal.php b/lib/session/internal.php new file mode 100644 index 00000000000..60aecccc8aa --- /dev/null +++ b/lib/session/internal.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Session; + +/** + * Class Internal + * + * wrap php's internal session handling into the Session interface + * + * @package OC\Session + */ +class Internal extends Memory { + public function __construct($name) { + session_name($name); + session_start(); + if (!isset($_SESSION)) { + throw new \Exception('Failed to start session'); + } + $this->data = $_SESSION; + } + + public function __destruct() { + $_SESSION = $this->data; + session_write_close(); + } + + public function clear() { + session_unset(); + @session_regenerate_id(true); + @session_start(); + $this->data = $_SESSION = array(); + } +} diff --git a/lib/session/memory.php b/lib/session/memory.php new file mode 100644 index 00000000000..c148ff4b9b9 --- /dev/null +++ b/lib/session/memory.php @@ -0,0 +1,63 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Session; + +/** + * Class Internal + * + * store session data in an in-memory array, not persistance + * + * @package OC\Session + */ +class Memory extends Session { + protected $data; + + public function __construct($name) { + //no need to use $name since all data is already scoped to this instance + $this->data = array(); + } + + /** + * @param string $key + * @param mixed $value + */ + public function set($key, $value) { + $this->data[$key] = $value; + } + + /** + * @param string $key + * @return mixed + */ + public function get($key) { + if (!$this->exists($key)) { + return null; + } + return $this->data[$key]; + } + + /** + * @param string $key + * @return bool + */ + public function exists($key) { + return isset($this->data[$key]); + } + + /** + * @param string $key + */ + public function remove($key) { + unset($this->data[$key]); + } + + public function clear() { + $this->data = array(); + } +} diff --git a/lib/session/session.php b/lib/session/session.php new file mode 100644 index 00000000000..55515f57a87 --- /dev/null +++ b/lib/session/session.php @@ -0,0 +1,79 @@ +<?php +/** + * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Session; + +abstract class Session implements \ArrayAccess { + /** + * $name serves as a namespace for the session keys + * + * @param string $name + */ + abstract public function __construct($name); + + /** + * @param string $key + * @param mixed $value + */ + abstract public function set($key, $value); + + /** + * @param string $key + * @return mixed should return null if $key does not exist + */ + abstract public function get($key); + + /** + * @param string $key + * @return bool + */ + abstract public function exists($key); + + /** + * should not throw any errors if $key does not exist + * + * @param string $key + */ + abstract public function remove($key); + + /** + * removes all entries within the cache namespace + */ + abstract public function clear(); + + /** + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset) { + return $this->exists($offset); + } + + /** + * @param mixed $offset + * @return mixed + */ + public function offsetGet($offset) { + return $this->get($offset); + } + + /** + * @param mixed $offset + * @param mixed $value + */ + public function offsetSet($offset, $value) { + $this->set($offset, $value); + } + + /** + * @param mixed $offset + */ + public function offsetUnset($offset) { + $this->remove($offset); + } +} diff --git a/lib/template.php b/lib/template.php index 2f535335648..9467dedb62a 100644 --- a/lib/template.php +++ b/lib/template.php @@ -246,14 +246,14 @@ class OC_Template{ // if the formfactor is not yet autodetected do the // autodetection now. For possible formfactors check the // detectFormfactor documentation - if(!isset($_SESSION['formfactor'])) { - $_SESSION['formfactor'] = self::detectFormfactor(); + if (!\OC::$session->exists('formfactor')) { + \OC::$session->set('formfactor', self::detectFormfactor()); } // allow manual override via GET parameter if(isset($_GET['formfactor'])) { - $_SESSION['formfactor']=$_GET['formfactor']; + \OC::$session->set('formfactor', $_GET['formfactor']); } - $formfactor=$_SESSION['formfactor']; + $formfactor = \OC::$session->get('formfactor'); if($formfactor=='default') { $fext=''; }elseif($formfactor=='mobile') { diff --git a/lib/user.php b/lib/user.php index 26fe73f8bfe..1dde87a1339 100644 --- a/lib/user.php +++ b/lib/user.php @@ -264,7 +264,7 @@ class OC_User { * @brief Sets user id for session and triggers emit */ public static function setUserId($uid) { - $_SESSION['user_id'] = $uid; + \OC::$session->set('user_id', $uid); } /** @@ -285,7 +285,7 @@ class OC_User { $result = true; } if (OC_User::getUser() === $uid) { - $_SESSION['display_name'] = $displayName; + \OC::$session->set('display_name', $displayName); } return $result; } @@ -328,10 +328,10 @@ class OC_User { * Checks if the user is logged in */ public static function isLoggedIn() { - if( isset($_SESSION['user_id']) AND $_SESSION['user_id']) { + if( \OC::$session->get('user_id')) { OC_App::loadApps(array('authentication')); self::setupBackends(); - if (self::userExists($_SESSION['user_id']) ) { + if (self::userExists(\OC::$session->get('user_id')) ) { return true; } } @@ -356,8 +356,8 @@ class OC_User { * @return string uid or false */ public static function getUser() { - if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) { - return $_SESSION['user_id']; + if( \OC::$session->get('user_id') ) { + return \OC::$session->get('user_id'); } else{ return false; @@ -371,8 +371,8 @@ class OC_User { public static function getDisplayName($user=null) { if ( $user ) { return self::determineDisplayName($user); - } else if( isset($_SESSION['display_name']) AND $_SESSION['display_name'] ) { - return $_SESSION['display_name']; + } else if( \OC::$session->get('display_name') ) { + return \OC::$session->get('display_name'); } else{ return false; diff --git a/lib/util.php b/lib/util.php index ce68568183b..581f35bc0ac 100755 --- a/lib/util.php +++ b/lib/util.php @@ -151,10 +151,10 @@ class OC_Util { * @param bool dateOnly option to omit time from the result */ public static function formatDate( $timestamp, $dateOnly=false) { - if(isset($_SESSION['timezone'])) {//adjust to clients timezone if we know it + if(\OC::$session->exists('timezone')) {//adjust to clients timezone if we know it $systemTimeZone = intval(date('O')); $systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100); - $clientTimeZone=$_SESSION['timezone']*60; + $clientTimeZone=\OC::$session->get('timezone')*60; $offset=$clientTimeZone-$systemTimeZone; $timestamp=$timestamp+$offset*60; } @@ -458,13 +458,13 @@ class OC_Util { */ public static function callRegister() { // Check if a token exists - if(!isset($_SESSION['requesttoken'])) { + if(!\OC::$session->exists('requesttoken')) { // No valid token found, generate a new one. $requestToken = self::generate_random_bytes(20); - $_SESSION['requesttoken']=$requestToken; + \OC::$session->set('requesttoken', $requestToken); } else { // Valid token already exists, send it - $requestToken = $_SESSION['requesttoken']; + $requestToken = \OC::$session->get('requesttoken'); } return($requestToken); } @@ -476,7 +476,7 @@ class OC_Util { * @see OC_Util::callRegister() */ public static function isCallRegistered() { - if(!isset($_SESSION['requesttoken'])) { + if(!\OC::$session->exists('requesttoken')) { return false; } @@ -492,7 +492,7 @@ class OC_Util { } // Check if the token is valid - if($token !== $_SESSION['requesttoken']) { + if($token !== \OC::$session->get('requesttoken')) { // Not valid return false; } else { |