1<?php 2/** 3 * Template Functions 4 * 5 * This file provides template specific custom functions that are 6 * not provided by the DokuWiki core. 7 * It is common practice to start each function with an underscore 8 * to make sure it won't interfere with future core functions. 9 */ 10 11// must be run from within DokuWiki 12if (!defined('DOKU_INC')) die(); 13 14/** 15 * Generate the HTML for the Site-Branding Area 16 * 17 * @return string 18 */ 19if (!function_exists('tpl_getSiteBranding')) { 20 function tpl_getSiteBranding() 21 { 22 // Retrieve the global variables 23 global $ID,$conf; 24 25 // Initialize the return value 26 $return = ''; 27 28 // Initialize the logo size and images 29 $logoSize = array(); 30 $logoImages = array(); 31 if(tpl_getConf('doLogoChangesByNamespace')){ 32 $namespace = ""; 33 $namespaces = array(); 34 foreach(explode(':',getNS($ID)) as $ns){ 35 $namespace .= "$ns:"; 36 $namespaces[] = $namespace; 37 } 38 foreach(array_reverse($namespaces) as $namespace){ 39 $logoImages[] = ":".trim($namespace,":").":logo.png"; 40 } 41 } 42 $logoImages[] = ':logo.png'; 43 $logoImages[] = ':wiki:logo.png'; 44 $logoImages[] = 'images/logo.png'; 45 $logo = tpl_getMediaFile($logoImages, false, $logoSize); 46 $link = wl(); 47 if(tpl_getConf('doLogoLinkChangesByNamespace')){ 48 $link = str_replace(['/_media','logo.png'],['',$conf['start']],$logo); 49 } 50 51 $return .= '<a class="site-logo" href="'.$link.'" title="'.$conf['title'].'" rel="home" accesskey="h" title="[H]">'; 52 $return .= '<img src="'.$logo.'" '.$logoSize[3].' alt="" class="no-grav header-image" />'; 53 $return .= '</a>'; 54 55 // Initialize the site branding 56 $title = $conf['title']; 57 if(tpl_getConf('doTitleChangesByNamespace')){ 58 $nstitle = tpl_include_page('nstitle', 0, 1); 59 if ($nstitle) { 60 $title = $nstitle; 61 } 62 } 63 $tagline = $conf['tagline']; 64 if(tpl_getConf('doTaglineChangesByNamespace')){ 65 $nstagline = tpl_include_page('nstagline', 0, 1); 66 if ($nstagline) { 67 $tagline = $nstagline; 68 } 69 } 70 $return .= '<div class="site-branding">'; 71 $return .= '<h1 class="site-title"><a href="'.$link.'" rel="home" accesskey="h" title="[H]">'.$title.'</a></h1>'; 72 if($tagline){ 73 $return .= '<h2 class="site-description">'.$tagline.'</h2>'; 74 } 75 $return .= '</div>'; 76 77 return $return; 78 } 79} 80 81/** 82 * Generate the gravatar URL for a given email 83 * 84 * @return string 85 */ 86if (!function_exists('tpl_getGravatarURL')) { 87 function tpl_getGravatarURL($email, $size = 96) 88 { 89 return 'https://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$size; 90 } 91} 92 93 94/** 95 * Generate the HTML for a menu 96 * 97 * @return string 98 */ 99if (!function_exists('tpl_getMenu')) { 100 function tpl_getMenu($menu) 101 { 102 switch($menu){ 103 case 'usermenu': 104 return tpl_getUserMenu(); 105 break; 106 case 'sidebarmenu': 107 return tpl_getSidebarMenu(); 108 break; 109 } 110 } 111} 112 113/** 114 * Generate the HTML for the user menu 115 * 116 * @return string 117 */ 118if (!function_exists('tpl_getUserMenu')) { 119 function tpl_getUserMenu() 120 { 121 global $lang,$ID,$conf,$INFO; 122 123 $return = ''; 124 125 $items = (new \dokuwiki\Menu\UserMenu())->getItems(); 126 127 if(isset($INFO['userinfo'])){ 128 $return .= '<div class="dropdown user-tools">'; 129 $return .= '<a href="'.wl($ID).'" class="dropdown-toggle" title="'.$lang['user_tools'].'" data-target="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">'; 130 $return .= '<i class="bi bi-person"></i>'.$INFO['userinfo']['name']; 131 $return .= '</a>'; 132 $return .= '<ul class="dropdown-menu" role="menu">'; 133 $return .= '<li>'; 134 $return .= '<p class="avatar">'; 135 $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail']).'" />'; 136 $return .= '</p>'; 137 $return .= '</li>'; 138 foreach($items as $item) { 139 $return .= '<li>' 140 .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 141 .'<i></i> ' 142 .$item->getLabel() 143 .'</a></li>'; 144 } 145 $return .= '</ul>'; 146 $return .= '</div>'; 147 } else { 148 $return .= '<div class="inline user-tools">'; 149 foreach($items as $item) { 150 $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 151 .'<i></i> ' 152 .$item->getLabel() 153 .'</a>'; 154 } 155 $return .= '</div>'; 156 } 157 158 return $return; 159 } 160} 161 162/** 163 * Generate the HTML for the sidebar menus 164 * 165 * @return string 166 */ 167if (!function_exists('tpl_getSidebarMenu')) { 168 function tpl_getSidebarMenu() 169 { 170 global $lang,$ID,$conf,$INFO; 171 172 $userItems = (new \dokuwiki\Menu\UserMenu())->getItems(); 173 $siteItems = (new \dokuwiki\Menu\SiteMenu())->getItems(); 174 175 $return = ''; 176 177 $return .= '<div id="writr__sidebar__tools">'; 178 179 if(isset($INFO['userinfo'])){ 180 $return .= '<div class="user-tools">'; 181 $return .= '<a href="'.wl($ID).'" class="" title="'.$lang['user_tools'].'" data-target="#user-tools-menu" data-toggle="collapse" role="button" aria-haspopup="true" aria-expanded="false">'; 182 $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail'], 32).'" />'; 183 $return .= '<span>'.$INFO['userinfo']['name'].'</span>'; 184 $return .= '</a>'; 185 $return .= '<div id="user-tools-menu" class="collapsed">'; 186 $return .= '<ul class="menu" role="menu">'; 187 foreach($userItems as $item) { 188 $return .= '<li>' 189 .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 190 .'<i></i> ' 191 .$item->getLabel() 192 .'</a></li>'; 193 } 194 $return .= '</ul>'; 195 $return .= '</div>'; 196 $return .= '</div>'; 197 } else { 198 $return .= '<div class="user-tools">'; 199 foreach($userItems as $item) { 200 $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 201 .'<i></i> ' 202 .$item->getLabel() 203 .'</a>'; 204 } 205 $return .= '</div>'; 206 } 207 208 $return .= '</div>'; 209 210 return $return; 211 } 212} 213