From daa0e0e0db86b05c05395d1516c4b018c48d2bd1 Mon Sep 17 00:00:00 2001 From: ringmaster Date: Tue, 21 Jan 2014 15:26:14 -0500 Subject: [PATCH 1/3] Let a valid route suffice for a file_exists() on a javascript URL. --- lib/private/router.php | 11 +++++++++++ lib/private/template/jsresourcelocator.php | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lib/private/router.php b/lib/private/router.php index 19c1e4473eca..9a9ccba944b5 100644 --- a/lib/private/router.php +++ b/lib/private/router.php @@ -134,6 +134,17 @@ public function match($url) { } } + /** + * Determine if the match can be made to a specific URL + * + * @param string $url The url to find + * @returns boolean True if the URL matches a route + */ + public function canMatch($url) { + $matcher = new UrlMatcher($this->root, $this->context); + return ($matcher->match($url)) ? true : false; + } + /** * Get the url generator * diff --git a/lib/private/template/jsresourcelocator.php b/lib/private/template/jsresourcelocator.php index f8fe3817ce60..5f1646912810 100644 --- a/lib/private/template/jsresourcelocator.php +++ b/lib/private/template/jsresourcelocator.php @@ -35,6 +35,9 @@ public function doFind( $script ) { ) { return; } + if (\OC::getRouter()->canMatch($app_url . '/' . $script . '.js')) { + return; + } throw new \Exception('js file not found: script:'.$script); } From 7ad046b0cb66212deb691c372d4cfeedc962c0a2 Mon Sep 17 00:00:00 2001 From: ringmaster Date: Tue, 21 Jan 2014 15:43:39 -0500 Subject: [PATCH 2/3] Append the script, and respect form-factor --- lib/private/template/jsresourcelocator.php | 5 +++++ lib/private/template/resourcelocator.php | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/private/template/jsresourcelocator.php b/lib/private/template/jsresourcelocator.php index 5f1646912810..f562a88f0d37 100644 --- a/lib/private/template/jsresourcelocator.php +++ b/lib/private/template/jsresourcelocator.php @@ -35,7 +35,12 @@ public function doFind( $script ) { ) { return; } + if (\OC::getRouter()->canMatch($app_url . '/' . $script . $this->form_factor . '.js')) { + $this->append($app_path, $script . $this->form_factor . '.js', $_SERVER['REQUEST_URI'] . $app_url); + return; + } if (\OC::getRouter()->canMatch($app_url . '/' . $script . '.js')) { + $this->append($app_path, $script . '.js', $_SERVER['REQUEST_URI'] . $app_url); return; } throw new \Exception('js file not found: script:'.$script); diff --git a/lib/private/template/resourcelocator.php b/lib/private/template/resourcelocator.php index 9f83673664df..3014e0f7a43f 100644 --- a/lib/private/template/resourcelocator.php +++ b/lib/private/template/resourcelocator.php @@ -55,15 +55,26 @@ public function find( $resources ) { */ protected function appendIfExist($root, $file, $webroot = null) { if (is_file($root.'/'.$file)) { - if (!$webroot) { - $webroot = $this->mapping[$root]; - } - $this->resources[] = array($root, $webroot, $file); - return true; + return $this->append($root, $file, $webroot); } return false; } + /* + * Append the $file resource at $root + * @param $root path to check + * @param $file the filename + * @param $web base for path, default map $root to $webroot + * @return boolean Always true + */ + protected function append($root, $file, $webroot = null) { + if (!$webroot) { + $webroot = $this->mapping[$root]; + } + $this->resources[] = array($root, $webroot, $file); + return true; + } + public function getResources() { return $this->resources; } From f8fbdffbe7d63185c6de52c8a4fd3a9bb6de677f Mon Sep 17 00:00:00 2001 From: ringmaster Date: Wed, 19 Feb 2014 14:01:34 -0500 Subject: [PATCH 3/3] The script is relative to the OC root, not the current URL. --- lib/private/template/jsresourcelocator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/template/jsresourcelocator.php b/lib/private/template/jsresourcelocator.php index f562a88f0d37..d94f797120d1 100644 --- a/lib/private/template/jsresourcelocator.php +++ b/lib/private/template/jsresourcelocator.php @@ -36,11 +36,11 @@ public function doFind( $script ) { return; } if (\OC::getRouter()->canMatch($app_url . '/' . $script . $this->form_factor . '.js')) { - $this->append($app_path, $script . $this->form_factor . '.js', $_SERVER['REQUEST_URI'] . $app_url); + $this->append($app_path, $script . $this->form_factor . '.js', $_SERVER['SCRIPT_NAME'] . $app_url); return; } if (\OC::getRouter()->canMatch($app_url . '/' . $script . '.js')) { - $this->append($app_path, $script . '.js', $_SERVER['REQUEST_URI'] . $app_url); + $this->append($app_path, $script . '.js', $_SERVER['SCRIPT_NAME'] . $app_url); return; } throw new \Exception('js file not found: script:'.$script);