aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-07-04 10:04:38 +0200
committerJulius Härtl <jus@bitgrid.net>2018-07-19 08:16:58 +0200
commit9e5885963c5dc09c20183732f0f94ca01598530e (patch)
tree92a3d5d2e9707644ec9c6b68ce0d3fe6d1f7165e
parent8977c71f8842f19077fdd0bfe27a4f48f2bc4726 (diff)
downloadnextcloud-server-9e5885963c5dc09c20183732f0f94ca01598530e.tar.gz
nextcloud-server-9e5885963c5dc09c20183732f0f94ca01598530e.zip
Fixed icons detection and caching
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r--apps/accessibility/lib/Controller/AccessibilityController.php26
-rw-r--r--core/Controller/SvgController.php14
-rw-r--r--lib/private/Group/Group.php2
-rw-r--r--lib/private/Template/IconsCacher.php18
4 files changed, 41 insertions, 19 deletions
diff --git a/apps/accessibility/lib/Controller/AccessibilityController.php b/apps/accessibility/lib/Controller/AccessibilityController.php
index f5ec1b8fab1..3ef305511e0 100644
--- a/apps/accessibility/lib/Controller/AccessibilityController.php
+++ b/apps/accessibility/lib/Controller/AccessibilityController.php
@@ -36,7 +36,7 @@ use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
-use OC\Template\SCSSCacher;
+use OC\Template\IconsCacher;
class AccessibilityController extends Controller {
@@ -67,6 +67,9 @@ class AccessibilityController extends Controller {
/** @var IAppManager */
private $appManager;
+ /** @var IconsCacher */
+ protected $iconsCacher;
+
/**
* Account constructor.
*
@@ -88,7 +91,8 @@ class AccessibilityController extends Controller {
IURLGenerator $urlGenerator,
ITimeFactory $timeFactory,
IUserSession $userSession,
- IAppManager $appManager) {
+ IAppManager $appManager,
+ IconsCacher $iconsCacher) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->config = $config;
@@ -98,6 +102,7 @@ class AccessibilityController extends Controller {
$this->timeFactory = $timeFactory;
$this->userSession = $userSession;
$this->appManager = $appManager;
+ $this->iconsCacher = $iconsCacher;
$this->serverRoot = \OC::$SERVERROOT;
$this->appRoot = $this->appManager->getAppPath($this->appName);
@@ -148,7 +153,12 @@ class AccessibilityController extends Controller {
// Rebase all urls
$appWebRoot = substr($this->appRoot, strlen($this->serverRoot) - strlen(\OC::$WEBROOT));
- $css = $this->rebaseUrls($css, $appWebRoot . '/css');
+ $css = $this->rebaseUrls($css, $appWebRoot . '/css');
+
+ if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) {
+ $iconsCss = $this->invertSvgIconsColor($this->iconsCacher->getCachedCSS()->getContent());
+ $css = $css . $iconsCss;
+ }
$response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']);
@@ -200,4 +210,14 @@ class AccessibilityController extends Controller {
return preg_replace($re, $subst, $css);
}
+
+ /**
+ * Remove all matches from the $rule regex
+ *
+ * @param string $css string to parse
+ * @return string
+ */
+ private function invertSvgIconsColor(string $css) {
+ return str_replace(['/000', '/fff'], ['/fff', '/000'], $css);
+ }
}
diff --git a/core/Controller/SvgController.php b/core/Controller/SvgController.php
index 4d71152f547..b1a78752c41 100644
--- a/core/Controller/SvgController.php
+++ b/core/Controller/SvgController.php
@@ -31,7 +31,6 @@ use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\NotFoundException;
use OCP\IRequest;
-use OC\Template\IconsCacher;
class SvgController extends Controller {
@@ -41,18 +40,13 @@ class SvgController extends Controller {
/** @var ITimeFactory */
protected $timeFactory;
- /** @var IconsCacher */
- protected $iconsCacher;
-
public function __construct(string $appName,
IRequest $request,
- ITimeFactory $timeFactory,
- IconsCacher $iconsCacher) {
+ ITimeFactory $timeFactory) {
parent::__construct($appName, $request);
$this->serverRoot = \OC::$SERVERROOT;
$this->timeFactory = $timeFactory;
- $this->iconsCacher = $iconsCacher;
}
/**
@@ -68,7 +62,7 @@ class SvgController extends Controller {
*/
public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') {
$path = $this->serverRoot . "/core/img/$folder/$fileName.svg";
- return $this->getSvg($path, $color);
+ return $this->getSvg($path, $color, $fileName);
}
/**
@@ -94,7 +88,7 @@ class SvgController extends Controller {
return new NotFoundResponse();
}
$path = $this->serverRoot . $appPath ."/img/$fileName.svg";
- return $this->getSvg($path, $color);
+ return $this->getSvg($path, $color, $fileName);
}
@@ -105,7 +99,7 @@ class SvgController extends Controller {
* @param string $color
* @return DataDisplayResponse|NotFoundException
*/
- private function getSvg(string $path, string $color) {
+ private function getSvg(string $path, string $color, string $fileName) {
if (!file_exists($path)) {
return new NotFoundResponse();
}
diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php
index 7f114873995..0d54cf8e35a 100644
--- a/lib/private/Group/Group.php
+++ b/lib/private/Group/Group.php
@@ -90,7 +90,7 @@ class Group implements IGroup {
public function getDisplayName() {
if (is_null($this->displayName)) {
- return $this->gid.'-name';
+ return $this->gid;
}
return $this->displayName;
}
diff --git a/lib/private/Template/IconsCacher.php b/lib/private/Template/IconsCacher.php
index 3f405cbf3c1..79c4b9d8ec0 100644
--- a/lib/private/Template/IconsCacher.php
+++ b/lib/private/Template/IconsCacher.php
@@ -45,7 +45,7 @@ class IconsCacher {
protected $urlGenerator;
/** @var string */
- private $iconVarRE = '/--([a-z-]+): url\("([a-z0-9-\/]+)[^;]+;/m';
+ private $iconVarRE = '/--([a-z0-9-]+): url\(["\']([a-z0-9-\/]+)[^;]+;/m';
/** @var string */
private $fileName = 'icons-vars.css';
@@ -84,12 +84,17 @@ class IconsCacher {
* @param string $css
*/
public function setIconsCss(string $css) {
+
try {
- $data = $this->folder->getFile($this->fileName)->getContent();
+ $currentData = $this->folder->getFile($this->fileName)->getContent();
} catch (NotFoundException $e) {
- $data = '';
+ $currentData = '';
}
- $icons = $this->getIconsFromCss($data . $css);
+
+ // remove :root
+ $currentData = str_replace([':root {', '}'], '', $currentData);
+
+ $icons = $this->getIconsFromCss($currentData . $css);
$data = '';
foreach ($icons as $icon => $url) {
@@ -127,7 +132,10 @@ class IconsCacher {
public function injectCss() {
// Only inject once
foreach (\OC_Util::$headers as $header) {
- if (strpos($header['attributes']['href'], $this->fileName) !== false) {
+ if (
+ array_key_exists('attributes', $header) &&
+ array_key_exists('href', $header['attributes']) &&
+ strpos($header['attributes']['href'], $this->fileName) !== false) {
return;
}
}