summaryrefslogtreecommitdiffstats
path: root/apps/accessibility
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-06-22 08:25:23 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-06-25 17:12:28 +0200
commitfc0e62185c12714eb0f98f993ff3795632f71deb (patch)
treefe0b1afd40b9c6ab6a5584013c56c51e9b776b31 /apps/accessibility
parent1aa7fd891794f93933417ecde52e9123ed3befdc (diff)
downloadnextcloud-server-fc0e62185c12714eb0f98f993ff3795632f71deb.tar.gz
nextcloud-server-fc0e62185c12714eb0f98f993ff3795632f71deb.zip
Fixed webroot detection
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/accessibility')
-rw-r--r--apps/accessibility/css/themedark.scss3
-rw-r--r--apps/accessibility/lib/Controller/AccessibilityController.php62
2 files changed, 61 insertions, 4 deletions
diff --git a/apps/accessibility/css/themedark.scss b/apps/accessibility/css/themedark.scss
index 6a220d1f063..73cb03d11d6 100644
--- a/apps/accessibility/css/themedark.scss
+++ b/apps/accessibility/css/themedark.scss
@@ -18,6 +18,7 @@ $color-border: lighten($color-main-background, 7%);
$color-border-dark: lighten($color-main-background, 14%);
#app-navigation > ul > li > a:first-child img,
-#app-navigation > ul > li > ul > li > a:first-child img {
+#app-navigation > ul > li > ul > li > a:first-child img,
+#expanddiv a img {
filter: invert(100%);
} \ No newline at end of file
diff --git a/apps/accessibility/lib/Controller/AccessibilityController.php b/apps/accessibility/lib/Controller/AccessibilityController.php
index c6c6aa2468f..7e0c3ab48b6 100644
--- a/apps/accessibility/lib/Controller/AccessibilityController.php
+++ b/apps/accessibility/lib/Controller/AccessibilityController.php
@@ -111,8 +111,9 @@ class AccessibilityController extends Controller {
public function getCss(): DataDisplayResponse {
$css = '';
$imports = '';
+ $userValues = $this->getUserValues();
- foreach ($this->getUserValues() as $key => $scssFile) {
+ foreach ($userValues as $key => $scssFile) {
if ($scssFile !== false) {
$imports .= '@import "' . $scssFile . '";';
}
@@ -144,6 +145,16 @@ class AccessibilityController extends Controller {
// We don't want to override vars with url since path is different
$css = $this->filterOutRule('/--[a-z-:]+url\([^;]+\)/mi', $css);
+ // Calculate exact absolute path to file
+ $path = $this->urlGenerator->linkToRoute($this->appName . '.accessibility.getCss', ['md5' => md5(implode('-', $userValues))]);
+ $path = explode('/', $this->serverRoot . $path);
+ array_pop($path);
+ $path = implode('/', $path);
+ $webDir = $this->getWebDir($path, $this->appName, $this->serverRoot, \OC::$WEBROOT);
+
+ // Rebase all urls
+ $css = $this->rebaseUrls($css, $webDir);
+
$response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']);
// Set cache control
@@ -158,15 +169,60 @@ class AccessibilityController extends Controller {
return $response;
}
- private function getUserValues() {
+ /**
+ * Return an array with the user theme & font settings
+ *
+ * @return array
+ */
+ private function getUserValues(): array{
$userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false);
$userFont = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false);
return [$userTheme, $userFont];
}
- private function filterOutRule(string $rule, string $css) {
+ /**
+ * Remove all matches from the $rule regex
+ *
+ * @param string $rule regex to match
+ * @param string $css string to parse
+ * @return string
+ */
+ private function filterOutRule(string $rule, string $css): string {
return preg_replace($rule, '', $css);
}
+ /**
+ * Add the correct uri prefix to make uri valid again
+ *
+ * @param string $css
+ * @param string $webDir
+ * @return string
+ */
+ private function rebaseUrls(string $css, string $webDir): string {
+ $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x';
+ $subst = 'url(\'' . $webDir . '/$1\')';
+
+ return preg_replace($re, $subst, $css);
+ }
+
+ /**
+ * Get WebDir root
+ * @param string $path the css file path
+ * @param string $appName the app name
+ * @param string $serverRoot the server root path
+ * @param string $webRoot the nextcloud installation root path
+ * @return string the webDir
+ */
+ private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string {
+ // Detect if path is within server root AND if path is within an app path
+ if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) {
+ // Get the file path within the app directory
+ $appDirectoryPath = explode($appName, $path)[1];
+ // Remove the webroot
+ return str_replace($webRoot, '', $appWebPath.$appDirectoryPath);
+ }
+ return $webRoot.substr($path, strlen($serverRoot));
+ }
+
}