diff --git a/inc/template.php b/inc/template.php index a476e78abedd4c6a62ada21ec989f9d2df465199..5184929b8e8338f418fb3b24c57c985f283deb37 100644 --- a/inc/template.php +++ b/inc/template.php @@ -1340,21 +1340,50 @@ function tpl_flush(){ /** - * Use favicon.ico from data/media root directory if it exists, otherwise use + * Returns icon from data/media root directory if it exists, otherwise * the one in the template's image directory. * + * @param bool $abs - if to use absolute URL + * @param string $fileName - file name of icon * @author Anika Henke <anika@selfthinker.org> */ -function tpl_getFavicon($abs=false) { - if (file_exists(mediaFN('favicon.ico'))) { - return ml('favicon.ico', '', true, '', $abs); +function tpl_getFavicon($abs=false, $fileName='favicon.ico') { + if (file_exists(mediaFN($fileName))) { + return ml($fileName, '', true, '', $abs); } if($abs) { - return DOKU_URL.substr(DOKU_TPL.'images/favicon.ico', strlen(DOKU_REL)); + return DOKU_URL.substr(DOKU_TPL.'images/'.$fileName, strlen(DOKU_REL)); + } + return DOKU_TPL.'images/'.$fileName; +} + +/** + * Returns <link> tag for various icon types (favicon|mobile|generic) + * + * @param array $types - list of icon types to display (favicon|mobile|generic) + * @author Anika Henke <anika@selfthinker.org> + */ +function tpl_favicon($types=array('favicon')) { + + $return = ''; + + foreach ($types as $type) { + switch($type) { + case 'favicon': + $return .= '<link rel="shortcut icon" href="'.tpl_getFavicon().'" />'.NL; + break; + case 'mobile': + $return .= '<link rel="apple-touch-icon" href="'.tpl_getFavicon(false, 'apple-touch-icon.png').'" />'.NL; + break; + case 'generic': + // ideal world solution, which doesn't work in any browser yet + $return .= '<link rel="icon" href="'.tpl_getFavicon(false, 'icon.svg').'" type="image/svg+xml" />'.NL; + break; + } } - return DOKU_TPL.'images/favicon.ico'; + return $return; } diff --git a/lib/tpl/default/images/apple-touch-icon.png b/lib/tpl/default/images/apple-touch-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..45fa4e7b081d35277b8d6f86a3e2a3f16aa3295e Binary files /dev/null and b/lib/tpl/default/images/apple-touch-icon.png differ diff --git a/lib/tpl/default/main.php b/lib/tpl/default/main.php index 94c2322aa730fd680d8301082e84cb215a2c4c1f..26e84fde61ddf2eebce75adbd80b19bc981e8243 100644 --- a/lib/tpl/default/main.php +++ b/lib/tpl/default/main.php @@ -28,8 +28,7 @@ if (!defined('DOKU_INC')) die(); </title> <?php tpl_metaheaders()?> - - <link rel="shortcut icon" href="<?php echo tpl_getFavicon() ?>" /> + <?php echo tpl_favicon(array('favicon', 'mobile')) ?> <?php /*old includehook*/ @include(dirname(__FILE__).'/meta.html')?> </head>