Skip to content

Instantly share code, notes, and snippets.

@kesselb
Created November 23, 2019 21:32
Show Gist options
  • Save kesselb/d035c4a7334b155143686466370bc1eb to your computer and use it in GitHub Desktop.
Save kesselb/d035c4a7334b155143686466370bc1eb to your computer and use it in GitHub Desktop.
Add \OC::$APPSROOTS to mappings for findWebRoot
Index: lib/private/TemplateLayout.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/private/TemplateLayout.php (revision 4f2837017c95f063d99a05b6cd6a5e73ac388d75)
+++ lib/private/TemplateLayout.php (date 1574544614260)
@@ -48,6 +48,8 @@
class TemplateLayout extends \OC_Template {
private static $versionHash = '';
+ /** @var null|array A list of additional mappings for findWebRoot. null means not initialized. */
+ private static $partyMap;
/**
* @var \OCP\IConfig
@@ -298,7 +300,7 @@
$locator = new \OC\Template\CSSResourceLocator(
\OC::$server->getLogger(),
$theme,
- array( \OC::$SERVERROOT => \OC::$WEBROOT ),
+ [\OC::$SERVERROOT => \OC::$WEBROOT] + self::partyMap(),
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
$SCSSCacher
);
@@ -334,7 +336,7 @@
$locator = new \OC\Template\JSResourceLocator(
\OC::$server->getLogger(),
$theme,
- array( \OC::$SERVERROOT => \OC::$WEBROOT ),
+ [\OC::$SERVERROOT => \OC::$WEBROOT] + self::partyMap(),
array( \OC::$SERVERROOT => \OC::$WEBROOT ),
\OC::$server->query(JSCombiner::class)
);
@@ -342,6 +344,27 @@
return $locator->getResources();
}
+ /**
+ * Create a list of additional mappings for findWebRoot
+ *
+ * @return array
+ */
+ private static function partyMap(): array {
+ if (is_array(self::$partyMap)) {
+ return self::$partyMap;
+ }
+
+ self::$partyMap = [];
+ foreach (\OC::$APPSROOTS as $appsRoot) {
+ $realPath = realpath($appsRoot['path']);
+ if (strpos($realPath, \OC::$SERVERROOT) === 0) {
+ continue;
+ }
+ self::$partyMap[$realPath] = $appsRoot['url'];
+ }
+ return self::$partyMap;
+ }
+
/**
* Converts the absolute file path to a relative path from \OC::$SERVERROOT
* @param string $filePath Absolute path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment