summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-10-24 14:30:30 +0200
committerJulius Härtl <jus@bitgrid.net>2018-10-25 11:58:00 +0200
commit845f1b67d5f31cad36becfb8b20c42e5eb191bc8 (patch)
treecf910851ee8e9b9ac166c6d5570b054e586f6eef
parent58fde16226351e085aff60bca0d778f30704c4a8 (diff)
downloadnextcloud-server-845f1b67d5f31cad36becfb8b20c42e5eb191bc8.tar.gz
nextcloud-server-845f1b67d5f31cad36becfb8b20c42e5eb191bc8.zip
Directly embed icons into the icon-vars css file
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--lib/private/Template/IconsCacher.php49
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/private/Template/IconsCacher.php b/lib/private/Template/IconsCacher.php
index f3660442dc5..52fae068835 100644
--- a/lib/private/Template/IconsCacher.php
+++ b/lib/private/Template/IconsCacher.php
@@ -101,7 +101,45 @@ class IconsCacher {
$data = '';
foreach ($icons as $icon => $url) {
- $data .= "--$icon: url('$url');";
+ $base = $this->getRoutePrefix() . '/svg/';
+ $svg = false;
+ if (strpos($url, $base . 'core') === 0) {
+ $cleanUrl = substr($url, strlen($base.'core'));
+ $cleanUrl = substr($cleanUrl, 0, strpos($cleanUrl, '?'));
+ $parts = explode('/', $cleanUrl);
+ $color = array_pop($parts);
+ $cleanUrl = implode('/', $parts);
+ $location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg';
+ $svg = file_get_contents($location);
+ } elseif (strpos($url, $base) === 0) {
+ $cleanUrl = substr($url, strlen($base));
+ $cleanUrl = substr($cleanUrl, 0, strpos($cleanUrl, '?'));
+ $parts = explode('/', $cleanUrl);
+ $app = array_shift($parts);
+ $color = array_pop($parts);
+ $cleanUrl = implode('/', $parts);
+ $location = \OC_App::getAppPath($app) . '/img/' . $cleanUrl . '.svg';
+ if ($app === 'settings') {
+ $location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg';
+ }
+ $svg = file_get_contents($location);
+ }
+ if ($svg === false) {
+ $this->logger->debug('Failed to get icon file ' . $location);
+ $data .= "--$icon: url('$url');";
+ continue;
+ }
+ // TODO: Copied from SvgController (we should put this into a separate method so the controller can use it as well)
+ // add fill (fill is not present on black elements)
+ $fillRe = '/<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;])+)\/>/mi';
+ $svg = preg_replace($fillRe, '<$1 fill="#' . $color . '"/>', $svg);
+
+ // replace any fill or stroke colors
+ $svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg);
+ $svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg);
+
+ $encode = base64_encode($svg);
+ $data .= "--$icon: url(data:image/svg+xml;base64,$encode) !default;";
}
if (strlen($data) > 0) {
@@ -118,6 +156,15 @@ class IconsCacher {
return preg_replace($this->iconVarRE, '', $css);
}
+ private function getRoutePrefix() {
+ $frontControllerActive = (\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
+ $prefix = \OC::$WEBROOT . '/index.php';
+ if ($frontControllerActive) {
+ $prefix = \OC::$WEBROOT;
+ }
+ return $prefix;
+ }
+
/**
* Get icons css file
* @return ISimpleFile|boolean