* No, we can not put this class in its own file because it is used by
* OC_autoload!
*/
-class OC
-{
+class OC {
/**
* Associative array for autoloading. classname => filename
*/
/**
* SPL autoload
*/
- public static function autoload($className)
- {
+ public static function autoload($className) {
if (array_key_exists($className, OC::$CLASSPATH)) {
$path = OC::$CLASSPATH[$className];
/** @TODO: Remove this when necessary
- Remove "apps/" from inclusion path for smooth migration to mutli app dir
- */
+ Remove "apps/" from inclusion path for smooth migration to mutli app dir
+ */
if (strpos($path, 'apps/') === 0) {
OC_Log::write('core', 'include path for class "' . $className . '" starts with "apps/"', OC_Log::DEBUG);
$path = str_replace('apps/', '', $path);
} elseif (strpos($className, 'OCP\\') === 0) {
$path = 'public/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
} elseif (strpos($className, 'OCA\\') === 0) {
- foreach(self::$APPSROOTS as $appDir) {
+ foreach (self::$APPSROOTS as $appDir) {
$path = $appDir['path'] . '/' . strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
$fullPath = stream_resolve_include_path($path);
if (file_exists($fullPath)) {
return false;
}
- public static function initPaths()
- {
+ public static function initPaths() {
// calculate the root directories
OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4));
OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
// ensure we can find OC_Config
set_include_path(
OC::$SERVERROOT . '/lib' . PATH_SEPARATOR .
- get_include_path()
+ get_include_path()
);
// search the 3rdparty folder
exit;
}
$paths = array();
- foreach (OC::$APPSROOTS as $path)
+ foreach (OC::$APPSROOTS as $path) {
$paths[] = $path['path'];
+ }
// set the right include path
set_include_path(
OC::$SERVERROOT . '/lib' . PATH_SEPARATOR .
- OC::$SERVERROOT . '/config' . PATH_SEPARATOR .
- OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR .
- implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR .
- get_include_path() . PATH_SEPARATOR .
- OC::$SERVERROOT
+ OC::$SERVERROOT . '/config' . PATH_SEPARATOR .
+ OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR .
+ implode($paths, PATH_SEPARATOR) . PATH_SEPARATOR .
+ get_include_path() . PATH_SEPARATOR .
+ OC::$SERVERROOT
);
}
}
}
- public static function checkInstalled()
- {
+ public static function checkInstalled() {
// Redirect to installer if not installed
if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
if (!OC::$CLI) {
}
}
- public static function checkSSL()
- {
+ public static function checkSSL() {
// redirect to https site if configured
if (OC_Config::getValue("forcessl", false)) {
header('Strict-Transport-Security: max-age=31536000');
}
}
- public static function initTemplateEngine()
- {
+ public static function initTemplateEngine() {
// Add the stuff we need always
OC_Util::addScript("jquery-1.7.2.min");
OC_Util::addScript("jquery-ui-1.10.0.custom");
OC_Util::addScript("oc-requesttoken");
}
- public static function initSession()
- {
+ public static function initSession() {
// prevents javascript from accessing php session cookies
ini_set('session.cookie_httponly', '1;');
$_SESSION['LAST_ACTIVITY'] = time();
}
- public static function getRouter()
- {
+ public static function getRouter() {
if (!isset(OC::$router)) {
OC::$router = new OC_Router();
OC::$router->loadRoutes();
}
- public static function loadAppClassPaths()
- {
- foreach(OC_APP::getEnabledApps() as $app) {
- $file = OC_App::getAppPath($app).'/appinfo/classpath.php';
- if(file_exists($file)) {
+ public static function loadAppClassPaths() {
+ foreach (OC_APP::getEnabledApps() as $app) {
+ $file = OC_App::getAppPath($app) . '/appinfo/classpath.php';
+ if (file_exists($file)) {
require_once $file;
}
}
}
- public static function init()
- {
+ public static function init() {
// register autoloader
spl_autoload_register(array('OC', 'autoload'));
setlocale(LC_ALL, 'en_US.UTF-8');
/**
* register hooks for the cache
*/
- public static function registerCacheHooks()
- {
+ public static function registerCacheHooks() {
// register cache cleanup jobs
OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
/**
* register hooks for the filesystem
*/
- public static function registerFilesystemHooks()
- {
+ public static function registerFilesystemHooks() {
// Check for blacklisted files
OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
/**
* register hooks for sharing
*/
- public static function registerShareHooks()
- {
+ public static function registerShareHooks() {
OC_Hook::connect('OC_User', 'post_deleteUser', 'OCP\Share', 'post_deleteUser');
OC_Hook::connect('OC_User', 'post_addToGroup', 'OCP\Share', 'post_addToGroup');
OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OCP\Share', 'post_removeFromGroup');
/**
* @brief Handle the request
*/
- public static function handleRequest()
- {
+ public static function handleRequest() {
// load all the classpaths from the enabled apps so they are available
// in the routing files of each app
OC::loadAppClassPaths();
+ // Check if ownCloud is installed or in maintenance (update) mode
+ if (!OC_Config::getValue('installed', false)) {
+ require_once 'core/setup.php';
+ exit();
+ }
+ self::checkMaintenanceMode();
+ self::checkUpgrade();
+
try {
OC::getRouter()->match(OC_Request::getPathInfo());
return;
return;
}
- // Check if ownCloud is installed or in maintenance (update) mode
- if (!OC_Config::getValue('installed', false)) {
- require_once 'core/setup.php';
- exit();
- }
- self::checkMaintenanceMode();
- self::checkUpgrade();
-
// Handle redirect URL for logged in users
if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) {
$location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url']));
$file_ext = substr($param['file'], -3);
if ($file_ext != 'php'
|| !self::loadAppScriptFile($param)
- ) {
+ ) {
header('HTTP/1.0 404 Not Found');
}
}
self::handleLogin();
}
- public static function loadAppScriptFile($param)
- {
+ public static function loadAppScriptFile($param) {
OC_App::loadApps();
$app = $param['app'];
$file = $param['file'];
return false;
}
- public static function loadCSSFile($param)
- {
+ public static function loadCSSFile($param) {
$app = $param['app'];
$file = $param['file'];
$app_path = OC_App::getAppPath($app);
}
}
- protected static function handleLogin()
- {
+ protected static function handleLogin() {
OC_App::loadApps(array('prelogin'));
$error = array();
// remember was checked after last login
if (OC::tryRememberLogin()) {
$error[] = 'invalidcookie';
- // Someone wants to log in :
+ // Someone wants to log in :
} elseif (OC::tryFormLogin()) {
$error[] = 'invalidpassword';
- // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
+ // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
} elseif (OC::tryBasicAuthLogin()) {
$error[] = 'invalidpassword';
}
OC_Util::displayLoginPage(array_unique($error));
}
- protected static function cleanupLoginTokens($user)
- {
+ protected static function cleanupLoginTokens($user) {
$cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
$tokens = OC_Preferences::getKeys($user, 'login_token');
foreach ($tokens as $token) {
}
}
- protected static function tryRememberLogin()
- {
+ protected static function tryRememberLogin() {
if (!isset($_COOKIE["oc_remember_login"])
|| !isset($_COOKIE["oc_token"])
|| !isset($_COOKIE["oc_username"])
|| !$_COOKIE["oc_remember_login"]
- ) {
+ ) {
return false;
}
OC_App::loadApps(array('authentication'));
return true;
}
- protected static function tryFormLogin()
- {
+ protected static function tryFormLogin() {
if (!isset($_POST["user"]) || !isset($_POST['password'])) {
return false;
}
return true;
}
- protected static function tryBasicAuthLogin()
- {
+ protected static function tryBasicAuthLogin() {
if (!isset($_SERVER["PHP_AUTH_USER"])
|| !isset($_SERVER["PHP_AUTH_PW"])
- ) {
+ ) {
return false;
}
OC_App::loadApps(array('authentication'));
}
if (!function_exists('get_temp_dir')) {
- function get_temp_dir()
- {
+ function get_temp_dir() {
if ($temp = ini_get('upload_tmp_dir')) return $temp;
if ($temp = getenv('TMP')) return $temp;
if ($temp = getenv('TEMP')) return $temp;