]> source.dussan.org Git - nextcloud-server.git/commitdiff
Simplify loading app php script files
authorBart Visscher <bartv@thisnet.nl>
Fri, 10 Aug 2012 10:27:37 +0000 (12:27 +0200)
committerBart Visscher <bartv@thisnet.nl>
Fri, 10 Aug 2012 10:27:37 +0000 (12:27 +0200)
lib/base.php

index b200da77ba569189de738c1b573303fccbd4f3f1..c4127c73f26b57d3e4e69615bd21fc4c52929a9f 100644 (file)
@@ -409,10 +409,15 @@ class OC{
                                OC_User::logout();
                                header("Location: ".OC::$WEBROOT.'/');
                        }else{
-                               if(is_null(OC::$REQUESTEDFILE)) {
-                                       self::loadapp();
-                               }else{
-                                       self::loadfile();
+                               $app = OC::$REQUESTEDAPP;
+                               $file = OC::$REQUESTEDFILE;
+                               if(is_null($file)) {
+                                       $file = 'index.php';
+                               }
+                               $file_ext = substr($file, -3);
+                               if ($file_ext != 'php'
+                                       || !self::loadAppScriptFile($app, $file)) {
+                                       header('HTTP/1.0 404 Not Found');
                                }
                        }
                        return;
@@ -421,32 +426,15 @@ class OC{
                self::handleLogin();
        }
 
-       protected static function loadapp() {
-               if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/index.php')) {
-                       require_once(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/index.php');
-               }
-               else {
-                       trigger_error('The requested App was not found.', E_USER_ERROR);//load default app instead?
-               }
-       }
-
-       protected static function loadfile() {
-               $app = OC::$REQUESTEDAPP;
-               $file = OC::$REQUESTEDFILE;
+       protected static function loadAppScriptFile($app, $file) {
                $app_path = OC_App::getAppPath($app);
-               if (file_exists($app_path . '/' . $file)) {
-                       $file_ext = substr($file, -3);
-                       if ($file_ext == 'php') {
-                               $file = $app_path . '/' . $file;
-                               unset($app, $app_path, $app_web_path, $file_ext);
-                               require_once($file);
-                       }
-               }
-               else {
-                       die();
-                       header('HTTP/1.0 404 Not Found');
-                       exit;
+               $file = $app_path . '/' . $file;
+               unset($app, $app_path);
+               if (file_exists($file)) {
+                       require_once($file);
+                       return true;
                }
+               return false;
        }
 
        protected static function loadCSSFile() {