From d0cae6a99a332af79b2506205aa25aad4313d912 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 21 Jul 2012 19:43:50 +0200 Subject: Very basic conversion of ocs to Symfony Routing Component --- lib/base.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 631ed4fcce6..fcca1e77d26 100644 --- a/lib/base.php +++ b/lib/base.php @@ -86,6 +86,9 @@ class OC{ elseif(strpos($className,'Sabre_')===0) { require_once str_replace('_','/',$className) . '.php'; } + elseif(strpos($className,'Symfony\\')===0){ + require_once str_replace('\\','/',$className) . '.php'; + } elseif(strpos($className,'Test_')===0){ require_once 'tests/lib/'.strtolower(str_replace('_','/',substr($className,5)) . '.php'); } -- cgit v1.2.3 From 3e8b6e816a3f89ac20f22fdde630946058e5d184 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 30 Jul 2012 20:50:32 +0200 Subject: Create OC_Router in OC::init --- lib/base.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 5041f43648e..29a3502e352 100644 --- a/lib/base.php +++ b/lib/base.php @@ -62,6 +62,10 @@ class OC{ * requested file of app */ public static $REQUESTEDFILE = ''; + /* + * OC router + */ + public static $router = null; /** * check if owncloud runs in cli mode */ @@ -354,6 +358,8 @@ class OC{ OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); + OC::$router = new OC_Router(); + // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; -- cgit v1.2.3 From 3722928c46d0e4ec1935e4da4087b76aee24dd5d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 2 Aug 2012 17:47:38 +0200 Subject: Change access to router object to getter function --- lib/base.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 29a3502e352..43588944d04 100644 --- a/lib/base.php +++ b/lib/base.php @@ -62,14 +62,14 @@ class OC{ * requested file of app */ public static $REQUESTEDFILE = ''; - /* - * OC router - */ - public static $router = null; /** * check if owncloud runs in cli mode */ public static $CLI = false; + /* + * OC router + */ + protected static $router = null; /** * SPL autoload */ @@ -275,6 +275,14 @@ class OC{ } } + public static function getRouter() { + if (!isset(OC::$router)) { + OC::$router = new OC_Router(); + } + + return OC::$router; + } + public static function init(){ // register autoloader spl_autoload_register(array('OC','autoload')); @@ -358,8 +366,6 @@ class OC{ OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); - OC::$router = new OC_Router(); - // Load Apps // This includes plugins for users and filesystems as well global $RUNTIME_NOAPPS; -- cgit v1.2.3 From 72b2324b68c51baf140c6fab7957b59c31de4832 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 2 Aug 2012 17:59:18 +0200 Subject: Move loading of routes to OC::getRouter function --- lib/base.php | 1 + lib/router.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index 43588944d04..0d9ececc0c9 100644 --- a/lib/base.php +++ b/lib/base.php @@ -278,6 +278,7 @@ class OC{ public static function getRouter() { if (!isset(OC::$router)) { OC::$router = new OC_Router(); + OC::$router->loadRoutes(); } return OC::$router; diff --git a/lib/router.php b/lib/router.php index 5dd51e79156..a721255f297 100644 --- a/lib/router.php +++ b/lib/router.php @@ -16,10 +16,15 @@ class OC_Router { protected $collections = array(); protected $collection = null; + public function __construct() { + // TODO cache + $this->loadRoutes(); + } + /** * loads the api routes */ - public function loadRoutes(){ + public function loadRoutes() { // TODO cache foreach(OC_APP::getEnabledApps() as $app){ $file = OC_App::getAppPath($app).'/appinfo/routes.php'; -- cgit v1.2.3 From 1025e451a7610a9e5b50e7e99e808cb2d1915236 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 11 Aug 2012 01:00:26 +0200 Subject: Add router match to OC::handleRequest --- lib/base.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index b276cf5924d..a05d84fbae4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -421,6 +421,15 @@ class OC{ header('location: '.OC_Helper::linkToRemote('webdav')); return; } + try { + OC::getRouter()->match(OC_Request::getPathInfo()); + return; + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { + //header('HTTP/1.0 404 Not Found'); + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { + OC_Response::setStatus(405); + return; + } // Handle app css files if(substr(OC::$REQUESTEDFILE,-3) == 'css') { self::loadCSSFile(); -- cgit v1.2.3 From 8c024947440e2f15a9effe5fe6d91e60e8571a07 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Aug 2012 16:16:22 +0200 Subject: Routing: Prepare load funtions to be called from OC_Router --- lib/base.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index a05d84fbae4..0d7e224d354 100644 --- a/lib/base.php +++ b/lib/base.php @@ -430,9 +430,12 @@ class OC{ OC_Response::setStatus(405); return; } + $app = OC::$REQUESTEDAPP; + $file = OC::$REQUESTEDFILE; + $param = array('app' => $app, 'file' => $file); // Handle app css files - if(substr(OC::$REQUESTEDFILE,-3) == 'css') { - self::loadCSSFile(); + if(substr($file,-3) == 'css') { + self::loadCSSFile($param); return; } // Someone is logged in : @@ -442,14 +445,12 @@ class OC{ OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); }else{ - $app = OC::$REQUESTEDAPP; - $file = OC::$REQUESTEDFILE; if(is_null($file)) { - $file = 'index.php'; + $param['file'] = 'index.php'; } - $file_ext = substr($file, -3); + $file_ext = substr($param['file'], -3); if ($file_ext != 'php' - || !self::loadAppScriptFile($app, $file)) { + || !self::loadAppScriptFile($param)) { header('HTTP/1.0 404 Not Found'); } } @@ -459,7 +460,9 @@ class OC{ self::handleLogin(); } - protected static function loadAppScriptFile($app, $file) { + public static function loadAppScriptFile($param) { + $app = $param['app']; + $file = $param['file']; $app_path = OC_App::getAppPath($app); $file = $app_path . '/' . $file; unset($app, $app_path); @@ -470,9 +473,9 @@ class OC{ return false; } - protected static function loadCSSFile() { - $app = OC::$REQUESTEDAPP; - $file = OC::$REQUESTEDFILE; + public static function loadCSSFile($param) { + $app = $param['app']; + $file = $param['file']; $app_path = OC_App::getAppPath($app); if (file_exists($app_path . '/' . $file)) { $app_web_path = OC_App::getAppWebPath($app); -- cgit v1.2.3 From db4111f6d50d5bf2195d4a082ffc9dcea1d911ce Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Aug 2012 16:52:36 +0200 Subject: Routing: Add some core routes --- core/routes.php | 19 +++++++++++++++++++ lib/base.php | 3 ++- lib/router.php | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 core/routes.php (limited to 'lib/base.php') diff --git a/core/routes.php b/core/routes.php new file mode 100644 index 00000000000..04b42d20598 --- /dev/null +++ b/core/routes.php @@ -0,0 +1,19 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$this->create('app_css', '/apps/{app}/{file}') + ->requirements(array('file' => '.*.css')) + ->action('OC', 'loadCSSFile'); +$this->create('app_index_script', '/apps/{app}/') + ->defaults(array('file' => 'index.php')) + //->requirements(array('file' => '.*.php')) + ->action('OC', 'loadAppScriptFile'); +$this->create('app_script', '/apps/{app}/{file}') + ->defaults(array('file' => 'index.php')) + ->requirements(array('file' => '.*.php')) + ->action('OC', 'loadAppScriptFile'); diff --git a/lib/base.php b/lib/base.php index 0d7e224d354..3abfdb35668 100644 --- a/lib/base.php +++ b/lib/base.php @@ -440,8 +440,8 @@ class OC{ } // Someone is logged in : if(OC_User::isLoggedIn()) { - OC_App::loadApps(); if(isset($_GET["logout"]) and ($_GET["logout"])) { + OC_App::loadApps(); OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); }else{ @@ -461,6 +461,7 @@ class OC{ } public static function loadAppScriptFile($param) { + OC_App::loadApps(); $app = $param['app']; $file = $param['file']; $app_path = OC_App::getAppPath($app); diff --git a/lib/router.php b/lib/router.php index eca59d6dc3b..65fc51aff2c 100644 --- a/lib/router.php +++ b/lib/router.php @@ -34,6 +34,8 @@ class OC_Router { $this->root->addCollection($collection, '/apps/'.$app); } } + $this->useCollection('root'); + require_once('core/routes.php'); } protected function getCollection($name) { -- cgit v1.2.3 From ceec5e593c677ed9e9339739d0a66a28e4f25d12 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 7 Sep 2012 16:19:08 +0200 Subject: Remove redundant loadApps --- lib/base.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/base.php') diff --git a/lib/base.php b/lib/base.php index fc682fecfca..6af558ae9da 100644 --- a/lib/base.php +++ b/lib/base.php @@ -465,7 +465,6 @@ class OC{ OC_App::loadApps(); OC_User::setupBackends(); if(isset($_GET["logout"]) and ($_GET["logout"])) { - OC_App::loadApps(); OC_User::logout(); header("Location: ".OC::$WEBROOT.'/'); }else{ -- cgit v1.2.3 From f3a211c03c3dd017e263ac5226a52eb62562d198 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 5 Oct 2012 09:42:36 +0200 Subject: Implement routing on javascript side --- core/js/router.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ core/routes.php | 3 +++ lib/base.php | 1 + lib/router.php | 18 +++++++++++++ settings/js/users.js | 2 +- 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 core/js/router.js (limited to 'lib/base.php') diff --git a/core/js/router.js b/core/js/router.js new file mode 100644 index 00000000000..8b66f5a05c5 --- /dev/null +++ b/core/js/router.js @@ -0,0 +1,73 @@ +OC.router_base_url = OC.webroot + '/index.php/', +OC.Router = { + routes_request: $.ajax(OC.router_base_url + 'core/routes.json', { + dataType: 'json', + success: function(jsondata) { + if (jsondata.status == 'success') { + OC.Router.routes = jsondata.data; + } + } + }), + generate:function(name, opt_params) { + if (!('routes' in this)) { + if(this.routes_request.state() != 'resolved') { + alert('wait');// wait + } + } + if (!(name in this.routes)) { + throw new Error('The route "' + name + '" does not exist.'); + } + var route = this.routes[name]; + var params = opt_params || {}; + var unusedParams = $.extend(true, {}, params); + var url = ''; + var optional = true; + $(route.tokens).each(function(i, token) { + if ('text' === token[0]) { + url = token[1] + url; + optional = false; + + return; + } + + if ('variable' === token[0]) { + if (false === optional || !(token[3] in route.defaults) + || ((token[3] in params) && params[token[3]] != route.defaults[token[3]])) { + var value; + if (token[3] in params) { + value = params[token[3]]; + delete unusedParams[token[3]]; + } else if (token[3] in route.defaults) { + value = route.defaults[token[3]]; + } else if (optional) { + return; + } else { + throw new Error('The route "' + name + '" requires the parameter "' + token[3] + '".'); + } + + var empty = true === value || false === value || '' === value; + + if (!empty || !optional) { + url = token[1] + encodeURIComponent(value).replace(/%2F/g, '/') + url; + } + + optional = false; + } + + return; + } + + throw new Error('The token type "' + token[0] + '" is not supported.'); + }); + if (url === '') { + url = '/'; + } + + unusedParams = $.param(unusedParams); + if (unusedParams.length > 0) { + url += '?'+unusedParams; + } + + return OC.router_base_url + url; + } +}; diff --git a/core/routes.php b/core/routes.php index d396ddd6473..8d836816265 100644 --- a/core/routes.php +++ b/core/routes.php @@ -28,6 +28,9 @@ $this->create('core_ajax_vcategories_delete', '/core/ajax/vcategories/delete.php ->actionInclude('core/ajax/vcategories/delete.php'); $this->create('core_ajax_vcategories_edit', '/core/ajax/vcategories/edit.php') ->actionInclude('core/ajax/vcategories/edit.php'); +// Routing +$this->create('core_ajax_routes', '/core/routes.json') + ->action('OC_Router', 'JSRoutes'); // Not specifically routed $this->create('app_css', '/apps/{app}/{file}') diff --git a/lib/base.php b/lib/base.php index 2d82d5a40fc..f7967329c29 100644 --- a/lib/base.php +++ b/lib/base.php @@ -253,6 +253,7 @@ class OC{ OC_Util::addScript( "config" ); //OC_Util::addScript( "multiselect" ); OC_Util::addScript('search', 'result'); + OC_Util::addScript('router'); if( OC_Config::getValue( 'installed', false )) { if( OC_Appconfig::getValue( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax' ) { diff --git a/lib/router.php b/lib/router.php index da491e217fc..04a3d410060 100644 --- a/lib/router.php +++ b/lib/router.php @@ -94,4 +94,22 @@ class OC_Router { { return $this->getGenerator()->generate($name, $parameters, $absolute); } + + public static function JSRoutes() + { + // TODO: http caching + $routes = array(); + $router = OC::getRouter(); + $root = $router->getCollection('root'); + foreach($root->all() as $name => $route) { + $compiled_route = $route->compile(); + $defaults = $route->getDefaults(); + unset($defaults['action']); + $routes[$name] = array( + 'tokens' => $compiled_route->getTokens(), + 'defaults' => $defaults, + ); + } + OCP\JSON::success ( array( 'data' => $routes ) ); + } } diff --git a/settings/js/users.js b/settings/js/users.js index 81a3181ba59..1474ebcdd81 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -130,7 +130,7 @@ var UserList={ if (typeof UserList.offset === 'undefined') { UserList.offset = $('tbody tr').length; } - $.get(OC.filePath('settings', 'ajax', 'userlist'), { offset: UserList.offset }, function(result) { + $.get(OC.Router.generate('settings_ajax_userlist', { offset: UserList.offset }), function(result) { if (result.status === 'success') { $.each(result.data, function(index, user) { var tr = UserList.add(user.name, user.groups, user.subadmin, user.quota, false); -- cgit v1.2.3 From 43e8293d9ce92b42f2dd944847c7e4d8d1b17b9f Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 27 Oct 2012 11:32:16 +0200 Subject: Change Symfony/Component/Routing from submodule to composer fetching --- .gitignore | 4 ++++ .gitmodules | 3 --- 3rdparty/Symfony/Component/Routing | 1 - composer.json | 8 ++++++++ lib/base.php | 4 ++-- 5 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 .gitmodules delete mode 160000 3rdparty/Symfony/Component/Routing create mode 100644 composer.json (limited to 'lib/base.php') diff --git a/.gitignore b/.gitignore index 4749dea19dc..4ae39ed7fac 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,7 @@ nbproject # WebFinger .well-known /.buildpath +3rdparty/autoload.php +3rdparty/composer/ +3rdparty/symfony/ +composer.lock diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 0f4ad588071..00000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "3rdparty/Symfony/Component/Routing"] - path = 3rdparty/Symfony/Component/Routing - url = git://github.com/symfony/Routing.git diff --git a/3rdparty/Symfony/Component/Routing b/3rdparty/Symfony/Component/Routing deleted file mode 160000 index d7248389088..00000000000 --- a/3rdparty/Symfony/Component/Routing +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d72483890880a987afa679503af096d2aaf7d2ee diff --git a/composer.json b/composer.json new file mode 100644 index 00000000000..628ee601103 --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "require": { + "symfony/routing": "2.0.*" + }, + "config": { + "vendor-dir": "3rdparty" + } +} diff --git a/lib/base.php b/lib/base.php index c8a54d1c659..c688d785339 100644 --- a/lib/base.php +++ b/lib/base.php @@ -97,8 +97,8 @@ class OC{ elseif(strpos($className, 'Sabre_')===0) { $path = str_replace('_', '/', $className) . '.php'; } - elseif(strpos($className, 'Symfony\\')===0) { - $path = str_replace('\\', '/', $className) . '.php'; + elseif(strpos($className, 'Symfony\\Component\\Routing\\')===0) { + $path = 'symfony/routing/'.str_replace('\\', '/', $className) . '.php'; } elseif(strpos($className, 'Test_')===0) { $path = 'tests/lib/'.strtolower(str_replace('_', '/', substr($className, 5)) . '.php'); -- cgit v1.2.3