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).
This commit is contained in:
parent
09aeb71c54
commit
c24a2e1e52
1 changed files with 12 additions and 3 deletions
13
svg.php
13
svg.php
|
@ -56,7 +56,7 @@ class SvgNode extends \SimpleXMLElement {
|
||||||
$dom = dom_import_simplexml($this);
|
$dom = dom_import_simplexml($this);
|
||||||
|
|
||||||
$g = $dom->ownerDocument->createElement('g');
|
$g = $dom->ownerDocument->createElement('g');
|
||||||
while ($dom->childNodes->length > 0) {
|
while($dom->childNodes->length > 0) {
|
||||||
$child = $dom->childNodes->item(0);
|
$child = $dom->childNodes->item(0);
|
||||||
$dom->removeChild($child);
|
$dom->removeChild($child);
|
||||||
$g->appendChild($child);
|
$g->appendChild($child);
|
||||||
|
@ -86,6 +86,7 @@ class SVG {
|
||||||
|
|
||||||
const IMGDIR = __DIR__ . '/img/';
|
const IMGDIR = __DIR__ . '/img/';
|
||||||
const BACKGROUNDCLASS = 'sprintdoc-background';
|
const BACKGROUNDCLASS = 'sprintdoc-background';
|
||||||
|
const CDNBASE = 'https://cdn.rawgit.com/Templarian/MaterialDesign/master/icons/svg/';
|
||||||
|
|
||||||
protected $file;
|
protected $file;
|
||||||
|
|
||||||
|
@ -101,9 +102,17 @@ class SVG {
|
||||||
// try local file first
|
// try local file first
|
||||||
$file = self::IMGDIR . $svg;
|
$file = self::IMGDIR . $svg;
|
||||||
if(!file_exists($file)) {
|
if(!file_exists($file)) {
|
||||||
|
// try media file
|
||||||
|
$file = mediaFN($svg);
|
||||||
|
if(file_exists($file)) {
|
||||||
// media files are ACL protected
|
// media files are ACL protected
|
||||||
if(auth_quickaclcheck($svg) < AUTH_READ) $this->abort(403);
|
if(auth_quickaclcheck($svg) < AUTH_READ) $this->abort(403);
|
||||||
$file = mediaFN($svg);
|
} else {
|
||||||
|
// get it from material design icons
|
||||||
|
$file = getCacheName($svg, '.svg');
|
||||||
|
io_download(self::CDNBASE . $svg, $file);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// check if media exists
|
// check if media exists
|
||||||
if(!file_exists($file)) $this->abort(404);
|
if(!file_exists($file)) $this->abort(404);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue