diff options
Diffstat (limited to 'inc/template.php')
-rw-r--r-- | inc/template.php | 188 |
1 files changed, 149 insertions, 39 deletions
diff --git a/inc/template.php b/inc/template.php index c70e407d6..ab6aa925f 100644 --- a/inc/template.php +++ b/inc/template.php @@ -23,6 +23,31 @@ function template($tpl){ return DOKU_INC.'lib/tpl/default/'.$tpl; } + +/** + * Convenience function to access template dir from local FS + * + * This replaces the deprecated DOKU_TPLINC constant + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_incdir(){ + global $conf; + return DOKU_INC.'lib/tpl/'.$conf['template'].'/'; +} + +/** + * Convenience function to access template dir from web + * + * This replaces the deprecated DOKU_TPL constant + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_basedir(){ + global $conf; + return DOKU_BASE.'lib/tpl/'.$conf['template'].'/'; +} + /** * Print the content * @@ -969,10 +994,11 @@ function tpl_img($maxwidth=0,$maxheight=0,$link=true,$params=null){ /** * Default action for TPL_IMG_DISPLAY */ -function _tpl_img_action($data, $param=NULL) { +function _tpl_img_action($data, $param=null) { + global $lang; $p = buildAttributes($data['params']); - if($data['url']) print '<a href="'.hsc($data['url']).'">'; + if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">'; print '<img '.$p.'/>'; if($data['url']) print '</a>'; return true; @@ -986,8 +1012,6 @@ function _tpl_img_action($data, $param=NULL) { */ function tpl_indexerWebBug(){ global $ID; - global $INFO; - if(!$INFO['exists']) return false; $p = array(); $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). @@ -1033,7 +1057,7 @@ function tpl_getConf($id){ */ function tpl_loadConfig(){ - $file = DOKU_TPLINC.'/conf/default.php'; + $file = tpl_incdir().'/conf/default.php'; $conf = array(); if (!@file_exists($file)) return false; @@ -1054,7 +1078,7 @@ function tpl_getLang($id){ static $lang = array(); if (count($lang) === 0){ - $path = DOKU_TPLINC.'lang/'; + $path = tpl_incdir().'lang/'; $lang = array(); @@ -1206,12 +1230,13 @@ function tpl_mediaFileDetails($image, $rev){ list($ext,$mime,$dl) = mimetype($image,false); $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $class = 'select mediafile mf_'.$class; - $tabTitle = '<strong class="'.$class.'">'.$image.'</strong>'; + $tabTitle = '<strong class="'.$class.'"><a href="'.ml($image).'" title="'.$lang['mediaview'].'">'.$image.'</a>'.'</strong>'; if ($opened_tab === 'view' && $rev) { printf($lang['media_viewold'], $tabTitle, dformat($rev)); } else { printf($lang['media_' . $opened_tab], $tabTitle); } + echo '</h3></div>'.NL; echo '<div class="panelContent">'.NL; @@ -1261,6 +1286,7 @@ function tpl_actiondropdown($empty='',$button='>'){ global $auth; echo '<form action="' . DOKU_SCRIPT . '" method="post" accept-charset="utf-8">'; + echo '<div class="no">'; echo '<input type="hidden" name="id" value="'.$ID.'" />'; if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; @@ -1268,36 +1294,42 @@ function tpl_actiondropdown($empty='',$button='>'){ echo '<select name="do" class="edit quickselect">'; echo '<option value="">'.$empty.'</option>'; - echo '<optgroup label=" — ">'; + echo '<optgroup label="'.$lang['page_tools'].'">'; $act = tpl_get_action('edit'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; - $act = tpl_get_action('revisions'); + $act = tpl_get_action('revert'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; - $act = tpl_get_action('revert'); + $act = tpl_get_action('revisions'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; $act = tpl_get_action('backlink'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; - echo '</optgroup>'; - echo '<optgroup label=" — ">'; + $act = tpl_get_action('subscribe'); + if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; + echo '</optgroup>'; + + echo '<optgroup label="'.$lang['site_tools'].'">'; $act = tpl_get_action('recent'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; + $act = tpl_get_action('media'); + if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; + $act = tpl_get_action('index'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; echo '</optgroup>'; - echo '<optgroup label=" — ">'; + echo '<optgroup label="'.$lang['user_tools'].'">'; $act = tpl_get_action('login'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; - $act = tpl_get_action('profile'); + $act = tpl_get_action('register'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; - $act = tpl_get_action('subscribe'); + $act = tpl_get_action('profile'); if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>'; $act = tpl_get_action('admin'); @@ -1306,6 +1338,7 @@ function tpl_actiondropdown($empty='',$button='>'){ echo '</select>'; echo '<input type="submit" value="'.$button.'" />'; + echo '</div>'; echo '</form>'; } @@ -1315,31 +1348,33 @@ function tpl_actiondropdown($empty='',$button='>'){ * @author Andreas Gohr <andi@splitbrain.org> * @param string $img - print image? (|button|badge) * @param bool $return - when true don't print, but return HTML + * @param bool $wrap - wrap in div with class="license"? */ -function tpl_license($img='badge',$imgonly=false,$return=false){ +function tpl_license($img='badge',$imgonly=false,$return=false,$wrap=true){ global $license; global $conf; global $lang; if(!$conf['license']) return ''; if(!is_array($license[$conf['license']])) return ''; $lic = $license[$conf['license']]; + $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : ''; - $out = '<div class="license">'; + $out = ''; + if($wrap) $out .= '<div class="license">'; if($img){ $src = license_img($img); if($src){ - $out .= '<a href="'.$lic['url'].'" rel="license"'; - if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; - $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> '; + $out .= '<a href="'.$lic['url'].'" rel="license"'.$target; + $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>'; + if(!$imgonly) $out .= ' '; } } if(!$imgonly) { - $out .= $lang['license']; - $out .= ' <a href="'.$lic['url'].'" rel="license" class="urlextern"'; - if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; + $out .= $lang['license'].' '; + $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target; $out .= '>'.$lic['name'].'</a>'; } - $out .= '</div>'; + if($wrap) $out .= '</div>'; if($return) return $out; echo $out; @@ -1354,9 +1389,12 @@ function tpl_license($img='badge',$imgonly=false,$return=false){ */ function tpl_include_page($pageid,$print=true){ global $ID; - $oldid = $ID; + global $TOC; + $oldid = $ID; + $oldtoc = $TOC; $html = p_wiki_xhtml($pageid,'',false); - $ID = $oldid; + $ID = $oldid; + $TOC = $oldtoc; if(!$print) return $html; echo $html; @@ -1445,24 +1483,93 @@ function tpl_flush(){ flush(); } +/** + * Tries to find a ressource file in the given locations. + * + * If a given location starts with a colon it is assumed to be a media + * file, otherwise it is assumed to be relative to the current template + * + * @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($search, $abs=false, &$imginfo=null){ + // loop through candidates until a match was found: + foreach($search as $img){ + if(substr($img,0,1) == ':'){ + $file = mediaFN($img); + $ismedia = true; + }else{ + $file = tpl_incdir().$img; + $ismedia = false; + } + + if(file_exists($file)) break; + } + + // fetch image data if requested + if(!is_null($imginfo)){ + $imginfo = getimagesize($file); + } + + // build URL + if($ismedia){ + $url = ml($img, '', true, '', $abs); + }else{ + $url = tpl_basedir().$img; + if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); + } + + return $url; +} /** - * Returns icon from data/media root directory if it exists, otherwise - * the one in the template's image directory. + * PHP include a file + * + * either from the conf directory if it exists, otherwise use + * file in the template's root directory. + * + * The function honours config cascade settings and looks for the given + * file next to the ´main´ config files, in the order protected, local, + * default. + * + * Note: no escaping or sanity checking is done here. Never pass user input + * to this function! * - * @param bool $abs - if to use absolute URL - * @param string $fileName - file name of icon * @author Anika Henke <anika@selfthinker.org> + * @author Andreas Gohr <andi@splitbrain.org> */ -function tpl_getFavicon($abs=false, $fileName='favicon.ico') { - if (file_exists(mediaFN($fileName))) { - return ml($fileName, '', true, '', $abs); +function tpl_includeFile($file){ + global $config_cascade; + foreach (array('protected','local','default') as $config_group) { + if (empty($config_cascade['main'][$config_group])) continue; + foreach ($config_cascade['main'][$config_group] as $conf_file) { + $dir = dirname($conf_file); + if(file_exists("$dir/$file")){ + include("$dir/$file"); + return; + } + } } - if($abs) { - return DOKU_URL.substr(DOKU_TPL.'images/'.$fileName, strlen(DOKU_REL)); + // still here? try the template dir + $file = tpl_incdir().$file; + if(file_exists($file)){ + include($file); } - return DOKU_TPL.'images/'.$fileName; +} + +/** + * Returns icon from data/media root directory if it exists, otherwise + * the one in the template's image directory. + * + * @deprecated Use tpl_getMediaFile() instead + * @author Anika Henke <anika@selfthinker.org> + */ +function tpl_getFavicon($abs=false, $fileName='favicon.ico') { + $look = array(":wiki:$fileName", ":$fileName", "images/$fileName"); + return tpl_getMediaFile($look, $abs); } /** @@ -1478,14 +1585,17 @@ function tpl_favicon($types=array('favicon')) { foreach ($types as $type) { switch($type) { case 'favicon': - $return .= '<link rel="shortcut icon" href="'.tpl_getFavicon().'" />'.NL; + $look = array(':wiki:favicon.ico', ':favicon.ico', 'images/favicon.ico'); + $return .= '<link rel="shortcut icon" href="'.tpl_getMediaFile($look).'" />'.NL; break; case 'mobile': - $return .= '<link rel="apple-touch-icon" href="'.tpl_getFavicon(false, '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; 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; + $look = array(':wiki:favicon.svg', ':favicon.svg', 'images/favicon.svg'); + $return .= '<link rel="icon" href="'.tpl_getMediaFile($look).'" type="image/svg+xml" />'.NL; break; } } |