From 06cdf1484d980754fc39934b12a7eda059d7f4dd Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 20 Feb 2017 16:21:45 +0100 Subject: [PATCH] SPR-787 use same logo resized --- Template.php | 40 +++++++++++++++++++- main.php | 1 - tpl/favicon_tiles.php | 86 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 107 insertions(+), 20 deletions(-) diff --git a/Template.php b/Template.php index e9106e8..f8ad262 100644 --- a/Template.php +++ b/Template.php @@ -30,7 +30,6 @@ class Template { return $instance; } - /** * Template constructor. */ @@ -80,4 +79,43 @@ class Template { return $tabs; } + + /** + * Creates an image tag and includes the first found image correctly resized + * + * @param string $tag + * @param array $attributes + * @param int $w + * @param int $h + * @return string + */ + public static function getResizedImgTag($tag, $attributes, $w, $h) { + $attr = ''; + $medias = array(); + + // the attribute having an array defines where the image goes + foreach($attributes as $attribute => $data) { + if(is_array($data)) { + $medias = $data; + $attr = $attribute; + } + } + // if the image attribute could not be found return + if(!$attr || !$medias) return ''; + + // try all medias until an existing one is found + $media = ''; + foreach($medias as $media) { + if(file_exists(mediaFN($media))) break; + $media = ''; + } + if($media === '') return ''; + + // replace the array + $media = ml($media, array('w' => $w, 'h' => $h, 'crop' => 1), true, '&'); + $attributes[$attr] = $media; + + // return the full tag + return '<' . $tag . ' ' . buildAttributes($attributes) . ' />'; + } } diff --git a/main.php b/main.php index 4527e46..11c2fcf 100755 --- a/main.php +++ b/main.php @@ -67,7 +67,6 @@ $showSidebar = true; /* */ /* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */ ?> +/** + * Embed the various bookmarking icon sizes + * + * Basically it will first check for an exact image in the right size in the wiki namespace, then for generally named + * logos in the wiki namespace and finally it falls back to the logo configured in the template. + * + * + * @author Andreas Gohr + */ +use dokuwiki\template\sprintdoc\Template; - - - - - - - - - +if(!defined('DOKU_INC')) die(); - - - +// standard favicon +echo Template::getResizedImgTag( + 'link', + array( + 'rel' => 'shortcut icon', + 'href' => array('wiki:favicon.ico', 'wiki:favicon.png', tpl_getConf('logo')) + ), + 0, 0 // no scaling +); - - - - +// square apple icons +foreach(array(57, 60, 72, 76, 114, 120, 144, 152, 180) as $size) { + echo Template::getResizedImgTag( + 'link', + array( + 'rel' => 'apple-touch-icon', + 'sizes' => $size . 'x' . $size, + 'href' => array('wiki:logo-' . $size . 'x' . $size . '.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')) + ), + $size, $size + ); +} +// square favicons +foreach(array(32, 96, 192) as $size) { + echo Template::getResizedImgTag( + 'link', + array( + 'rel' => 'icon', + 'sizes' => $size . 'x' . $size, + 'href' => array('wiki:logo-' . $size . 'x' . $size . '.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')) + ), + $size, $size + ); +} + +// square microsoft icons +foreach(array(70, 310) as $size) { + echo Template::getResizedImgTag( + 'meta', + array( + 'name' => 'msapplication-square' . $size . 'x' . $size . 'logo', + 'content' => array('wiki:logo-' . $size . 'x' . $size . '.png', 'wiki:logo-square.png', 'wiki:logo.png', tpl_getConf('logo')) + ), + $size, $size + ); +} + +// wide micorsoft icons +foreach(array(array(310, 150)) as $size) { + echo Template::getResizedImgTag( + 'meta', + array( + 'name' => 'msapplication-wide' . $size[0] . 'x' . $size[1] . 'logo', + 'content' => array('wiki:logo-' . $size[0] . 'x' . $size[1] . '.png', 'wiki:logo-wide.png', 'wiki:logo.png', tpl_getConf('logo')) + ), + $size[0], $size[1] + ); +}