예제 #1
0
파일: base.php 프로젝트: gmurayama/core
 /**
  * @throws \RuntimeException when the 3rdparty directory is missing or
  * the app path list is empty or contains an invalid path
  */
 public static function initPaths()
 {
     if (defined('PHPUNIT_CONFIG_DIR')) {
         self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/';
     } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) {
         self::$configDir = OC::$SERVERROOT . '/tests/config/';
     } else {
         self::$configDir = OC::$SERVERROOT . '/config/';
     }
     self::$config = new \OC\Config(self::$configDir);
     OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
     /**
      * FIXME: The following lines are required because we can't yet instantiiate
      *        \OC::$server->getRequest() since \OC::$server does not yet exist.
      */
     $params = ['server' => ['SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME']]];
     $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config)));
     $scriptName = $fakeRequest->getScriptName();
     if (substr($scriptName, -1) == '/') {
         $scriptName .= 'index.php';
         //make sure suburi follows the same rules as scriptName
         if (substr(OC::$SUBURI, -9) != 'index.php') {
             if (substr(OC::$SUBURI, -1) != '/') {
                 OC::$SUBURI = OC::$SUBURI . '/';
             }
             OC::$SUBURI = OC::$SUBURI . 'index.php';
         }
     }
     if (OC::$CLI) {
         OC::$WEBROOT = self::$config->getValue('overwritewebroot', '');
     } else {
         if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) {
             OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI));
             if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') {
                 OC::$WEBROOT = '/' . OC::$WEBROOT;
             }
         } else {
             // The scriptName is not ending with OC::$SUBURI
             // This most likely means that we are calling from CLI.
             // However some cron jobs still need to generate
             // a web URL, so we use overwritewebroot as a fallback.
             OC::$WEBROOT = self::$config->getValue('overwritewebroot', '');
         }
         // Resolve /owncloud to /owncloud/ to ensure to always have a trailing
         // slash which is required by URL generation.
         if ($_SERVER['REQUEST_URI'] === \OC::$WEBROOT && substr($_SERVER['REQUEST_URI'], -1) !== '/') {
             header('Location: ' . \OC::$WEBROOT . '/');
             exit;
         }
     }
     // search the 3rdparty folder
     OC::$THIRDPARTYROOT = self::$config->getValue('3rdpartyroot', null);
     OC::$THIRDPARTYWEBROOT = self::$config->getValue('3rdpartyurl', null);
     if (empty(OC::$THIRDPARTYROOT) && empty(OC::$THIRDPARTYWEBROOT)) {
         if (file_exists(OC::$SERVERROOT . '/3rdparty')) {
             OC::$THIRDPARTYROOT = OC::$SERVERROOT;
             OC::$THIRDPARTYWEBROOT = OC::$WEBROOT;
         } elseif (file_exists(OC::$SERVERROOT . '/../3rdparty')) {
             OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/');
             OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/');
         }
     }
     if (empty(OC::$THIRDPARTYROOT) || !file_exists(OC::$THIRDPARTYROOT)) {
         throw new \RuntimeException('3rdparty directory not found! Please put the ownCloud 3rdparty' . ' folder in the ownCloud folder or the folder above.' . ' You can also configure the location in the config.php file.');
     }
     // search the apps folder
     $config_paths = self::$config->getValue('apps_paths', array());
     if (!empty($config_paths)) {
         foreach ($config_paths as $paths) {
             if (isset($paths['url']) && isset($paths['path'])) {
                 $paths['url'] = rtrim($paths['url'], '/');
                 $paths['path'] = rtrim($paths['path'], '/');
                 OC::$APPSROOTS[] = $paths;
             }
         }
     } elseif (file_exists(OC::$SERVERROOT . '/apps')) {
         OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true);
     } elseif (file_exists(OC::$SERVERROOT . '/../apps')) {
         OC::$APPSROOTS[] = array('path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', 'url' => '/apps', 'writable' => true);
     }
     if (empty(OC::$APPSROOTS)) {
         throw new \RuntimeException('apps directory not found! Please put the ownCloud apps folder in the ownCloud folder' . ' or the folder above. You can also configure the location in the config.php file.');
     }
     $paths = array();
     foreach (OC::$APPSROOTS as $path) {
         $paths[] = $path['path'];
         if (!is_dir($path['path'])) {
             throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the ownCloud apps folder in the' . ' ownCloud folder or the folder above. You can also configure the location in the' . ' config.php file.', $path['path']));
         }
     }
     // set the right include path
     set_include_path(OC::$SERVERROOT . '/lib/private' . PATH_SEPARATOR . OC::$SERVERROOT . '/config' . PATH_SEPARATOR . OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR . implode(PATH_SEPARATOR, $paths) . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR . OC::$SERVERROOT);
 }
예제 #2
0
 public static function initPaths()
 {
     // calculate the root directories
     OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4));
     // ensure we can find OC_Config
     set_include_path(OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . get_include_path());
     if (defined('PHPUNIT_CONFIG_DIR')) {
         self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/';
     } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) {
         self::$configDir = OC::$SERVERROOT . '/tests/config/';
     } else {
         self::$configDir = OC::$SERVERROOT . '/config/';
     }
     OC_Config::$object = new \OC\Config(self::$configDir);
     OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
     /**
      * FIXME: The following line is required because of a cyclic dependency
      *        on IRequest.
      */
     $params = ['server' => ['SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME']]];
     $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig()));
     $scriptName = $fakeRequest->getScriptName();
     if (substr($scriptName, -1) == '/') {
         $scriptName .= 'index.php';
         //make sure suburi follows the same rules as scriptName
         if (substr(OC::$SUBURI, -9) != 'index.php') {
             if (substr(OC::$SUBURI, -1) != '/') {
                 OC::$SUBURI = OC::$SUBURI . '/';
             }
             OC::$SUBURI = OC::$SUBURI . 'index.php';
         }
     }
     if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) {
         OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI));
         if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') {
             OC::$WEBROOT = '/' . OC::$WEBROOT;
         }
     } else {
         // The scriptName is not ending with OC::$SUBURI
         // This most likely means that we are calling from CLI.
         // However some cron jobs still need to generate
         // a web URL, so we use overwritewebroot as a fallback.
         OC::$WEBROOT = OC_Config::getValue('overwritewebroot', '');
     }
     // search the 3rdparty folder
     OC::$THIRDPARTYROOT = OC_Config::getValue('3rdpartyroot', null);
     OC::$THIRDPARTYWEBROOT = OC_Config::getValue('3rdpartyurl', null);
     if (empty(OC::$THIRDPARTYROOT) && empty(OC::$THIRDPARTYWEBROOT)) {
         if (file_exists(OC::$SERVERROOT . '/3rdparty')) {
             OC::$THIRDPARTYROOT = OC::$SERVERROOT;
             OC::$THIRDPARTYWEBROOT = OC::$WEBROOT;
         } elseif (file_exists(OC::$SERVERROOT . '/../3rdparty')) {
             OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/');
             OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/');
         }
     }
     if (empty(OC::$THIRDPARTYROOT) || !file_exists(OC::$THIRDPARTYROOT)) {
         echo '3rdparty directory not found! Please put the ownCloud 3rdparty' . ' folder in the ownCloud folder or the folder above.' . ' You can also configure the location in the config.php file.';
         return;
     }
     // search the apps folder
     $config_paths = OC_Config::getValue('apps_paths', array());
     if (!empty($config_paths)) {
         foreach ($config_paths as $paths) {
             if (isset($paths['url']) && isset($paths['path'])) {
                 $paths['url'] = rtrim($paths['url'], '/');
                 $paths['path'] = rtrim($paths['path'], '/');
                 OC::$APPSROOTS[] = $paths;
             }
         }
     } elseif (file_exists(OC::$SERVERROOT . '/apps')) {
         OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true);
     } elseif (file_exists(OC::$SERVERROOT . '/../apps')) {
         OC::$APPSROOTS[] = array('path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', 'url' => '/apps', 'writable' => true);
     }
     if (empty(OC::$APPSROOTS)) {
         throw new Exception('apps directory not found! Please put the ownCloud apps folder in the ownCloud folder' . ' or the folder above. You can also configure the location in the config.php file.');
     }
     $paths = array();
     foreach (OC::$APPSROOTS as $path) {
         $paths[] = $path['path'];
     }
     // set the right include path
     set_include_path(OC::$SERVERROOT . '/lib/private' . PATH_SEPARATOR . OC::$SERVERROOT . '/config' . PATH_SEPARATOR . OC::$THIRDPARTYROOT . '/3rdparty' . PATH_SEPARATOR . implode(PATH_SEPARATOR, $paths) . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR . OC::$SERVERROOT);
 }