Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Template/CSSResourceLocator.php53
-rwxr-xr-xlib/private/Template/ResourceLocator.php90
2 files changed, 74 insertions, 69 deletions
diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php
index 29f3efaa8da..d5e9ce732cc 100644
--- a/lib/private/Template/CSSResourceLocator.php
+++ b/lib/private/Template/CSSResourceLocator.php
@@ -6,6 +6,7 @@
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Kyle Fazzari <kyrofa@ubuntu.com>
*
* @license AGPL-3.0
*
@@ -122,45 +123,25 @@ class CSSResourceLocator extends ResourceLocator {
parent::append($root, $file, $webRoot, $throw);
} else {
if (!$webRoot) {
- $tmpRoot = realpath($root);
- /*
- * traverse the potential web roots upwards in the path
- *
- * example:
- * - root: /srv/www/apps/myapp
- * - available mappings: ['/srv/www']
- *
- * First we check if a mapping for /srv/www/apps/myapp is available,
- * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
- * valid web root
- */
- do {
- if (isset($this->mapping[$tmpRoot])) {
- $webRoot = $this->mapping[$tmpRoot];
- break;
+ $webRoot = $this->findWebRoot($root);
+
+ if ($webRoot === null) {
+ $webRoot = '';
+ $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
+ 'app' => 'lib',
+ 'root' => $root,
+ 'file' => $file,
+ 'webRoot' => $webRoot,
+ 'throw' => $throw ? 'true' : 'false'
+ ]);
+
+ if ($throw && $root === '/') {
+ throw new ResourceNotFoundException($file, $webRoot);
}
-
- if ($tmpRoot === '/') {
- $webRoot = '';
- $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
- 'app' => 'lib',
- 'root' => $root,
- 'file' => $file,
- 'webRoot' => $webRoot,
- 'throw' => $throw ? 'true' : 'false'
- ]);
- break;
- }
- $tmpRoot = dirname($tmpRoot);
- } while(true);
-
- }
-
- if ($throw && $tmpRoot === '/') {
- throw new ResourceNotFoundException($file, $webRoot);
+ }
}
- $this->resources[] = array($tmpRoot, $webRoot, $file);
+ $this->resources[] = array($webRoot? : '/', $webRoot, $file);
}
}
}
diff --git a/lib/private/Template/ResourceLocator.php b/lib/private/Template/ResourceLocator.php
index f721906e12b..0d7767fdd0b 100755
--- a/lib/private/Template/ResourceLocator.php
+++ b/lib/private/Template/ResourceLocator.php
@@ -7,6 +7,7 @@
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <robin@mccorkell.me.uk>
+ * @author Kyle Fazzari <kyrofa@ubuntu.com>
*
* @license AGPL-3.0
*
@@ -107,6 +108,50 @@ abstract class ResourceLocator {
}
/**
+ * Attempt to find the webRoot
+ *
+ * traverse the potential web roots upwards in the path
+ *
+ * example:
+ * - root: /srv/www/apps/myapp
+ * - available mappings: ['/srv/www']
+ *
+ * First we check if a mapping for /srv/www/apps/myapp is available,
+ * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
+ * valid web root
+ *
+ * @param string $root
+ * @return string|null The web root or null on failure
+ */
+ protected function findWebRoot($root) {
+ $webRoot = null;
+ $tmpRoot = $root;
+
+ while ($webRoot === null) {
+ if (isset($this->mapping[$tmpRoot])) {
+ $webRoot = $this->mapping[$tmpRoot];
+ break;
+ }
+
+ if ($tmpRoot === '/') {
+ break;
+ }
+
+ $tmpRoot = dirname($tmpRoot);
+ }
+
+ if ($webRoot === null) {
+ $realpath = realpath($root);
+
+ if ($realpath && ($realpath !== $root)) {
+ return $this->findWebRoot($realpath);
+ }
+ }
+
+ return $webRoot;
+ }
+
+ /**
* append the $file resource at $root
*
* @param string $root path to check
@@ -116,7 +161,6 @@ abstract class ResourceLocator {
* @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing
*/
protected function append($root, $file, $webRoot = null, $throw = true) {
-
if (!is_string($root)) {
if ($throw) {
throw new ResourceNotFoundException($file, $webRoot);
@@ -125,38 +169,18 @@ abstract class ResourceLocator {
}
if (!$webRoot) {
- $tmpRoot = realpath($root);
- /*
- * traverse the potential web roots upwards in the path
- *
- * example:
- * - root: /srv/www/apps/myapp
- * - available mappings: ['/srv/www']
- *
- * First we check if a mapping for /srv/www/apps/myapp is available,
- * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a
- * valid web root
- */
- do {
- if (isset($this->mapping[$tmpRoot])) {
- $webRoot = $this->mapping[$tmpRoot];
- break;
- }
-
- if ($tmpRoot === '/') {
- $webRoot = '';
- $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
- 'app' => 'lib',
- 'root' => $root,
- 'file' => $file,
- 'webRoot' => $webRoot,
- 'throw' => $throw ? 'true' : 'false'
- ]);
- break;
- }
- $tmpRoot = dirname($tmpRoot);
- } while(true);
-
+ $webRoot = $this->findWebRoot($root);
+
+ if ($webRoot === null) {
+ $webRoot = '';
+ $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [
+ 'app' => 'lib',
+ 'root' => $root,
+ 'file' => $file,
+ 'webRoot' => $webRoot,
+ 'throw' => $throw ? 'true' : 'false'
+ ]);
+ }
}
$this->resources[] = array($root, $webRoot, $file);