From c24a2e1e525f015b644fce07c8c5eba21a6c1621 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 13 Feb 2017 14:02:16 +0100 Subject: [PATCH] SVG Dispatch: allow for referencing material design icons A SVG not found in the template or in the local media storage will now be looked up in the Material Design Icon library (via a cached HTTP request to the rawgit CDN). --- svg.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/svg.php b/svg.php index f1bc30f..a40f39c 100644 --- a/svg.php +++ b/svg.php @@ -56,7 +56,7 @@ class SvgNode extends \SimpleXMLElement { $dom = dom_import_simplexml($this); $g = $dom->ownerDocument->createElement('g'); - while ($dom->childNodes->length > 0) { + while($dom->childNodes->length > 0) { $child = $dom->childNodes->item(0); $dom->removeChild($child); $g->appendChild($child); @@ -86,6 +86,7 @@ class SVG { const IMGDIR = __DIR__ . '/img/'; const BACKGROUNDCLASS = 'sprintdoc-background'; + const CDNBASE = 'https://cdn.rawgit.com/Templarian/MaterialDesign/master/icons/svg/'; protected $file; @@ -101,9 +102,17 @@ class SVG { // try local file first $file = self::IMGDIR . $svg; if(!file_exists($file)) { - // media files are ACL protected - if(auth_quickaclcheck($svg) < AUTH_READ) $this->abort(403); + // try media file $file = mediaFN($svg); + if(file_exists($file)) { + // media files are ACL protected + if(auth_quickaclcheck($svg) < AUTH_READ) $this->abort(403); + } else { + // get it from material design icons + $file = getCacheName($svg, '.svg'); + io_download(self::CDNBASE . $svg, $file); + } + } // check if media exists if(!file_exists($file)) $this->abort(404);