diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/private/Template/IconsCacher.php | 263 | ||||
-rw-r--r-- | lib/private/Template/SCSSCacher.php | 32 | ||||
-rw-r--r-- | lib/private/legacy/OC_Template.php | 1 |
5 files changed, 1 insertions, 299 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 32a4c749a08..233c374edbf 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -962,7 +962,6 @@ return array( 'OC\\Core\\Controller\\RecommendedAppsController' => $baseDir . '/core/Controller/RecommendedAppsController.php', 'OC\\Core\\Controller\\SearchController' => $baseDir . '/core/Controller/SearchController.php', 'OC\\Core\\Controller\\SetupController' => $baseDir . '/core/Controller/SetupController.php', - 'OC\\Core\\Controller\\SvgController' => $baseDir . '/core/Controller/SvgController.php', 'OC\\Core\\Controller\\TwoFactorChallengeController' => $baseDir . '/core/Controller/TwoFactorChallengeController.php', 'OC\\Core\\Controller\\UnifiedSearchController' => $baseDir . '/core/Controller/UnifiedSearchController.php', 'OC\\Core\\Controller\\UserController' => $baseDir . '/core/Controller/UserController.php', @@ -1523,7 +1522,6 @@ return array( 'OC\\TemplateLayout' => $baseDir . '/lib/private/TemplateLayout.php', 'OC\\Template\\Base' => $baseDir . '/lib/private/Template/Base.php', 'OC\\Template\\CSSResourceLocator' => $baseDir . '/lib/private/Template/CSSResourceLocator.php', - 'OC\\Template\\IconsCacher' => $baseDir . '/lib/private/Template/IconsCacher.php', 'OC\\Template\\JSCombiner' => $baseDir . '/lib/private/Template/JSCombiner.php', 'OC\\Template\\JSConfigHelper' => $baseDir . '/lib/private/Template/JSConfigHelper.php', 'OC\\Template\\JSResourceLocator' => $baseDir . '/lib/private/Template/JSResourceLocator.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 8f2b1cb648a..0b59d14657d 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -991,7 +991,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Controller\\RecommendedAppsController' => __DIR__ . '/../../..' . '/core/Controller/RecommendedAppsController.php', 'OC\\Core\\Controller\\SearchController' => __DIR__ . '/../../..' . '/core/Controller/SearchController.php', 'OC\\Core\\Controller\\SetupController' => __DIR__ . '/../../..' . '/core/Controller/SetupController.php', - 'OC\\Core\\Controller\\SvgController' => __DIR__ . '/../../..' . '/core/Controller/SvgController.php', 'OC\\Core\\Controller\\TwoFactorChallengeController' => __DIR__ . '/../../..' . '/core/Controller/TwoFactorChallengeController.php', 'OC\\Core\\Controller\\UnifiedSearchController' => __DIR__ . '/../../..' . '/core/Controller/UnifiedSearchController.php', 'OC\\Core\\Controller\\UserController' => __DIR__ . '/../../..' . '/core/Controller/UserController.php', @@ -1552,7 +1551,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\TemplateLayout' => __DIR__ . '/../../..' . '/lib/private/TemplateLayout.php', 'OC\\Template\\Base' => __DIR__ . '/../../..' . '/lib/private/Template/Base.php', 'OC\\Template\\CSSResourceLocator' => __DIR__ . '/../../..' . '/lib/private/Template/CSSResourceLocator.php', - 'OC\\Template\\IconsCacher' => __DIR__ . '/../../..' . '/lib/private/Template/IconsCacher.php', 'OC\\Template\\JSCombiner' => __DIR__ . '/../../..' . '/lib/private/Template/JSCombiner.php', 'OC\\Template\\JSConfigHelper' => __DIR__ . '/../../..' . '/lib/private/Template/JSConfigHelper.php', 'OC\\Template\\JSResourceLocator' => __DIR__ . '/../../..' . '/lib/private/Template/JSResourceLocator.php', diff --git a/lib/private/Template/IconsCacher.php b/lib/private/Template/IconsCacher.php deleted file mode 100644 index c2956d5712a..00000000000 --- a/lib/private/Template/IconsCacher.php +++ /dev/null @@ -1,263 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv@protonmail.com) - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Julius Härtl <jus@bitgrid.net> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -namespace OC\Template; - -use OC\Files\AppData\Factory; -use OCP\AppFramework\Utility\ITimeFactory; -use OCP\Files\IAppData; -use OCP\Files\NotFoundException; -use OCP\Files\SimpleFS\ISimpleFile; -use OCP\Files\SimpleFS\ISimpleFolder; -use OCP\IURLGenerator; -use Psr\Log\LoggerInterface; - -class IconsCacher { - protected LoggerInterface $logger; - - /** @var IAppData */ - protected $appData; - - /** @var ISimpleFolder */ - private $folder; - - /** @var IURLGenerator */ - protected $urlGenerator; - - /** @var ITimeFactory */ - protected $timeFactory; - - /** @var string */ - private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']?([a-zA-Z0-9-_\~\/\.\?\&\=\:\;\+\,]+)[^;]+;/m'; - - /** @var string */ - private $fileName = 'icons-vars.css'; - - private $iconList = 'icons-list.template'; - - private $cachedCss; - private $cachedList; - - /** - * @throws \OCP\Files\NotPermittedException - */ - public function __construct(LoggerInterface $logger, - Factory $appDataFactory, - IURLGenerator $urlGenerator, - ITimeFactory $timeFactory) { - $this->logger = $logger; - $this->appData = $appDataFactory->get('css'); - $this->urlGenerator = $urlGenerator; - $this->timeFactory = $timeFactory; - - try { - $this->folder = $this->appData->getFolder('icons'); - } catch (NotFoundException $e) { - $this->folder = $this->appData->newFolder('icons'); - } - } - - private function getIconsFromCss(string $css): array { - preg_match_all($this->iconVarRE, $css, $matches, PREG_SET_ORDER); - $icons = []; - foreach ($matches as $icon) { - $icons[$icon[1]] = $icon[2]; - } - - return $icons; - } - - /** - * @param string $css - * @return string - * @throws NotFoundException - * @throws \OCP\Files\NotPermittedException - */ - public function setIconsCss(string $css): string { - $cachedFile = $this->getCachedList(); - if (!$cachedFile) { - $currentData = ''; - $cachedFile = $this->folder->newFile($this->iconList); - } else { - $currentData = $cachedFile->getContent(); - } - - $cachedVarsCssFile = $this->getCachedCSS(); - if (!$cachedVarsCssFile) { - $cachedVarsCssFile = $this->folder->newFile($this->fileName); - } - - $icons = $this->getIconsFromCss($currentData . $css); - - $data = ''; - $list = ''; - foreach ($icons as $icon => $url) { - $list .= "--$icon: url('$url');"; - [$location,$color] = $this->parseUrl($url); - $svg = false; - if ($location !== '' && \file_exists($location)) { - $svg = \file_get_contents($location); - } - if ($svg === false) { - $this->logger->debug('Failed to get icon file ' . $location); - $data .= "--$icon: url('$url');"; - continue; - } - $encode = base64_encode($this->colorizeSvg($svg, $color)); - $data .= '--' . $icon . ': url(data:image/svg+xml;base64,' . $encode . ');'; - } - - if (\strlen($data) > 0 && \strlen($list) > 0) { - $data = ":root {\n$data\n}"; - $cachedVarsCssFile->putContent($data); - $list = ":root {\n$list\n}"; - $cachedFile->putContent($list); - $this->cachedList = null; - $this->cachedCss = null; - } - - return preg_replace($this->iconVarRE, '', $css); - } - - /** - * @param $url - * @return array - */ - private function parseUrl($url): array { - $location = ''; - $color = ''; - $base = $this->getRoutePrefix() . '/svg/'; - $cleanUrl = \substr($url, \strlen($base)); - if (\strpos($url, $base . 'core') === 0) { - $cleanUrl = \substr($cleanUrl, \strlen('core')); - if (\preg_match('/\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) { - [,$cleanUrl,$color] = $matches; - $location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg'; - } - } elseif (\strpos($url, $base) === 0) { - if (\preg_match('/([A-z0-9\_\-]+)\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) { - [,$app,$cleanUrl, $color] = $matches; - $appPath = \OC_App::getAppPath($app); - if ($appPath !== false) { - $location = $appPath . '/img/' . $cleanUrl . '.svg'; - } - if ($app === 'settings') { - $location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg'; - } - } - } - return [ - $location, - $color - ]; - } - - /** - * @param $svg - * @param $color - * @return string - */ - public function colorizeSvg($svg, $color): string { - if (!preg_match('/^[0-9a-f]{3,6}$/i', $color)) { - // Prevent not-sane colors from being written into the SVG - $color = '000'; - } - - // 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); - return $svg; - } - - 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 - */ - public function getCachedCSS() { - try { - if (!$this->cachedCss) { - $this->cachedCss = $this->folder->getFile($this->fileName); - } - return $this->cachedCss; - } catch (NotFoundException $e) { - return false; - } - } - - /** - * Get icon-vars list template - * @return ISimpleFile|boolean - */ - public function getCachedList() { - try { - if (!$this->cachedList) { - $this->cachedList = $this->folder->getFile($this->iconList); - } - return $this->cachedList; - } catch (NotFoundException $e) { - return false; - } - } - - /** - * Add the icons cache css into the header - */ - public function injectCss() { - $mtime = $this->timeFactory->getTime(); - $file = $this->getCachedList(); - if ($file) { - $mtime = $file->getMTime(); - } - // Only inject once - foreach (\OC_Util::$headers as $header) { - if ( - array_key_exists('attributes', $header) && - array_key_exists('href', $header['attributes']) && - strpos($header['attributes']['href'], $this->fileName) !== false) { - return; - } - } - $linkToCSS = $this->urlGenerator->linkToRoute('core.Css.getCss', ['appName' => 'icons', 'fileName' => $this->fileName, 'v' => $mtime]); - \OC_Util::addHeader('link', ['rel' => 'stylesheet', 'href' => $linkToCSS], null, true); - } -} diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index a552122b358..9ea0ad22de8 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -74,9 +74,6 @@ class SCSSCacher { /** @var ICacheFactory */ private $cacheFactory; - /** @var IconsCacher */ - private $iconsCacher; - /** @var ICache */ private $isCachedCache; @@ -98,7 +95,6 @@ class SCSSCacher { \OC_Defaults $defaults, $serverRoot, ICacheFactory $cacheFactory, - IconsCacher $iconsCacher, ITimeFactory $timeFactory, AppConfig $appConfig) { $this->logger = $logger; @@ -115,7 +111,6 @@ class SCSSCacher { $lockingCache = new NullCache(); } $this->lockingCache = $lockingCache; - $this->iconsCacher = $iconsCacher; $this->timeFactory = $timeFactory; $this->appConfig = $appConfig; } @@ -139,10 +134,6 @@ class SCSSCacher { $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); $this->logger->debug('SCSSCacher::process ordinary check follows', ['app' => 'scss_cacher']); - if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) { - // Inject icons vars css if any - return $this->injectCssVariablesIfAny(); - } try { $folder = $this->appData->getFolder($app); @@ -163,7 +154,7 @@ class SCSSCacher { if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $app)) { // Inject icons vars css if any $this->logger->debug("SCSSCacher::process cached file for app '$app' and file '$fileNameCSS' is now available after $retry s. Moving on...", ['app' => 'scss_cacher']); - return $this->injectCssVariablesIfAny(); + return true; } sleep(1); $retry++; @@ -184,11 +175,6 @@ class SCSSCacher { $this->lockingCache->remove($lockKey); $this->logger->debug('SCSSCacher::process Lock removed for ' . $lockKey, ['app' => 'scss_cacher']); - // Inject icons vars css if any - if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) { - $this->iconsCacher->injectCss(); - } - return $cached; } @@ -335,9 +321,6 @@ class SCSSCacher { return false; } - // Parse Icons and create related css variables - $compiledScss = $this->iconsCacher->setIconsCss($compiledScss); - // Gzip file try { $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz @@ -512,17 +495,4 @@ class SCSSCacher { return $webRoot . substr($path, strlen($serverRoot)); } - - /** - * Add the icons css cache in the header if needed - * - * @return boolean true - */ - private function injectCssVariablesIfAny() { - // Inject icons vars css if any - if ($this->iconsCacher->getCachedCSS() && $this->iconsCacher->getCachedCSS()->getSize() > 0) { - $this->iconsCacher->injectCss(); - } - return true; - } } diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index b7a400d3269..813cedd0740 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -105,7 +105,6 @@ class OC_Template extends \OC\Template\Base { // apps that started before the template initialization can load their own scripts/styles // so to make sure this scripts/styles here are loaded first we put all core scripts first // check lib/public/Util.php - // OC_Util::addStyle('css-variables', null, true); OC_Util::addStyle('server', null, true); // include common nextcloud webpack bundle |