From d21ded67a70672cfa56a48051fa752b431118604 Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Thu, 25 Oct 2018 11:57:27 +0200 Subject: Keep list of icons in a separate file for use in the accessibility app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- core/Controller/SvgController.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'core/Controller') diff --git a/core/Controller/SvgController.php b/core/Controller/SvgController.php index f7159dd9fe1..bbf4e61c60c 100644 --- a/core/Controller/SvgController.php +++ b/core/Controller/SvgController.php @@ -31,6 +31,7 @@ use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\App\IAppManager; use OCP\IRequest; +use OC\Template\IconsCacher; class SvgController extends Controller { @@ -43,15 +44,20 @@ class SvgController extends Controller { /** @var IAppManager */ protected $appManager; + /** @var IconsCacher */ + private $iconsCacher; + public function __construct(string $appName, IRequest $request, ITimeFactory $timeFactory, - IAppManager $appManager) { + IAppManager $appManager, + IconsCacher $iconsCacher) { parent::__construct($appName, $request); $this->serverRoot = \OC::$SERVERROOT; $this->timeFactory = $timeFactory; $this->appManager = $appManager; + $this->iconsCacher = $iconsCacher; } /** @@ -114,17 +120,11 @@ class SvgController extends Controller { $svg = file_get_contents($path); - if (is_null($svg)) { + if ($svg === null) { return new NotFoundResponse(); } - // 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); + $svg = $this->iconsCacher->colorizeSvg($svg, $color); $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']); -- cgit v1.2.3