Skip to content
Snippets Groups Projects
Commit 378325f9 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

made the tpl_getMediaFile() function more flexible

parent 27833958
No related branches found
No related tags found
No related merge requests found
...@@ -1459,22 +1459,44 @@ function tpl_flush(){ ...@@ -1459,22 +1459,44 @@ function tpl_flush(){
} }
/** /**
* Returns link to media file from data/media root directory if it exists, * Tries to find a ressource file in the given locations.
* otherwise the one in the template's image directory.
* *
* @param string $fileName - file name of icon * If a given location starts with a colon it is assumed to be a media
* @param bool $abs - if to use absolute URL * file, otherwise it is assumed to be relative to the current template
* @author Anika Henke <anika@selfthinker.org> *
* @param array $search locations to look at
* @param bool $abs if to use absolute URL
* @param arrayref $imginfo filled with getimagesize()
* @author Andreas Gohr <andi@splitbrain.org>
*/ */
function tpl_getMediaFile($fileName, $abs=false) { function tpl_getMediaFile($search, $abs=false, &$imginfo=null){
if (file_exists(mediaFN($fileName))) { // loop through candidates until a match was found:
return ml($fileName, '', true, '', $abs); foreach($search as $img){
if(substr($img,0,1) == ':'){
$file = mediaFN($img);
$ismedia = true;
}else{
$file = DOKU_TPLINC.$img;
$ismedia = false;
}
if(file_exists($file)) break;
} }
if($abs) { // fetch image data if requested
return DOKU_URL.substr(DOKU_TPL.'images/'.$fileName, strlen(DOKU_REL)); if(!is_null($imginfo)){
$imginfo = getimagesize($file);
} }
return DOKU_TPL.'images/'.$fileName;
// build URL
if($ismedia){
$url = ml($img, '', true, '', $abs);
}else{
$url = DOKU_TPL.$img;
if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
}
return $url;
} }
/** /**
...@@ -1485,7 +1507,8 @@ function tpl_getMediaFile($fileName, $abs=false) { ...@@ -1485,7 +1507,8 @@ function tpl_getMediaFile($fileName, $abs=false) {
* @author Anika Henke <anika@selfthinker.org> * @author Anika Henke <anika@selfthinker.org>
*/ */
function tpl_getFavicon($abs=false, $fileName='favicon.ico') { function tpl_getFavicon($abs=false, $fileName='favicon.ico') {
return tpl_getMediaFile($fileName, $abs); $look = array(":wiki:$fileName", ":$fileName", "images/$fileName");
return tpl_getMediaFile($look, $abs);
} }
/** /**
...@@ -1501,14 +1524,17 @@ function tpl_favicon($types=array('favicon')) { ...@@ -1501,14 +1524,17 @@ function tpl_favicon($types=array('favicon')) {
foreach ($types as $type) { foreach ($types as $type) {
switch($type) { switch($type) {
case 'favicon': case 'favicon':
$return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile('favicon.ico').'" />'.NL; $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico');
$return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL;
break; break;
case 'mobile': case 'mobile':
$return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile('apple-touch-icon.png').'" />'.NL; $look = array(':wiki:apple-touch-icon.png', ':apple-touch-icon.png', 'images/apple-touch-icon.ico');
$return .= '<link rel="apple-touch-icon" href="'.tpl_getMediaFile($look).'" />'.NL;
break; break;
case 'generic': case 'generic':
// ideal world solution, which doesn't work in any browser yet // ideal world solution, which doesn't work in any browser yet
$return .= '<link rel="icon" href="'.tpl_getMediaFile('icon.svg').'" type="image/svg+xml" />'.NL; $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg');
$return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL;
break; break;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment