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 site branding configurations 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 $title = $conf['title']; 51 if(tpl_getConf('doTitleChangesByNamespace')){ 52 $nstitle = tpl_include_page('nstitle', 0, 1); 53 if ($nstitle) { 54 $title = str_replace(['<p>','</p>',"\n"],'',$nstitle); 55 } 56 } 57 $tagline = $conf['tagline']; 58 if(tpl_getConf('doTaglineChangesByNamespace')){ 59 $nstagline = tpl_include_page('nstagline', 0, 1); 60 if ($nstagline) { 61 $tagline = str_replace(['<p>','</p>',"\n"],'',$nstagline); 62 } 63 } 64 65 // Initialize the logo 66 $return .= '<a class="site-logo" href="'.$link.'" title="'.$title.'" rel="home" accesskey="h">'; 67 $return .= '<img src="'.$logo.'" '.$logoSize[3].' class="no-grav header-image" />'; 68 $return .= '</a>'; 69 70 // Initialize the site branding 71 $return .= '<div class="site-branding">'; 72 $return .= '<h1 class="site-title"><a href="'.$link.'" rel="home" accesskey="h" title="'.$title.'">'.$title.'</a></h1>'; 73 if($tagline){ 74 $return .= '<h2 class="site-description">'.$tagline.'</h2>'; 75 } 76 $return .= '</div>'; 77 78 return $return; 79 } 80} 81 82/** 83 * Generate the gravatar URL for a given email 84 * 85 * @return string 86 */ 87if (!function_exists('tpl_getGravatarURL')) { 88 function tpl_getGravatarURL($email, $size = 96) 89 { 90 return 'https://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$size; 91 } 92} 93 94 95/** 96 * Generate the HTML for a menu 97 * 98 * @return string 99 */ 100if (!function_exists('tpl_getMenu')) { 101 function tpl_getMenu($menu) 102 { 103 switch($menu){ 104 case 'usermenu': 105 return tpl_getUserMenu(); 106 break; 107 case 'sidebarmenu': 108 return tpl_getSidebarMenu(); 109 break; 110 } 111 } 112} 113 114/** 115 * Generate the HTML for the user menu 116 * 117 * @return string 118 */ 119if (!function_exists('tpl_getUserMenu')) { 120 function tpl_getUserMenu() 121 { 122 global $lang,$ID,$conf,$INFO; 123 124 $return = ''; 125 126 $items = (new \dokuwiki\Menu\UserMenu())->getItems(); 127 128 if(isset($INFO['userinfo'])){ 129 $return .= '<div class="dropdown user-tools">'; 130 $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">'; 131 $return .= '<i class="bi bi-person"></i>'.$INFO['userinfo']['name']; 132 $return .= '</a>'; 133 $return .= '<ul class="dropdown-menu" role="menu">'; 134 $return .= '<li>'; 135 $return .= '<p class="avatar">'; 136 $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail']).'" />'; 137 $return .= '</p>'; 138 $return .= '</li>'; 139 foreach($items as $item) { 140 $return .= '<li>' 141 .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 142 .'<i></i> ' 143 .$item->getLabel() 144 .'</a></li>'; 145 } 146 $return .= '</ul>'; 147 $return .= '</div>'; 148 } else { 149 $return .= '<div class="inline user-tools">'; 150 foreach($items as $item) { 151 $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 152 .'<i></i> ' 153 .$item->getLabel() 154 .'</a>'; 155 } 156 $return .= '</div>'; 157 } 158 159 return $return; 160 } 161} 162 163/** 164 * Generate the HTML for the sidebar menus 165 * 166 * @return string 167 */ 168if (!function_exists('tpl_getSidebarMenu')) { 169 function tpl_getSidebarMenu() 170 { 171 global $lang,$ID,$conf,$INFO; 172 173 $userItems = (new \dokuwiki\Menu\UserMenu())->getItems(); 174 $siteItems = (new \dokuwiki\Menu\SiteMenu())->getItems(); 175 176 $return = ''; 177 178 $return .= '<div id="writr__sidebar__tools">'; 179 180 if(isset($INFO['userinfo'])){ 181 $return .= '<div class="user-tools">'; 182 $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">'; 183 $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail'], 32).'" />'; 184 $return .= '<span>'.$INFO['userinfo']['name'].'</span>'; 185 $return .= '</a>'; 186 $return .= '<div id="user-tools-menu" class="collapsed">'; 187 $return .= '<ul class="menu" role="menu">'; 188 foreach($userItems as $item) { 189 $return .= '<li>' 190 .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 191 .'<i></i> ' 192 .$item->getLabel() 193 .'</a></li>'; 194 } 195 $return .= '</ul>'; 196 $return .= '</div>'; 197 $return .= '</div>'; 198 } else { 199 $return .= '<div class="user-tools">'; 200 foreach($userItems as $item) { 201 $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 202 .'<i></i> ' 203 .$item->getLabel() 204 .'</a>'; 205 } 206 $return .= '</div>'; 207 } 208 209 $return .= '</div>'; 210 211 return $return; 212 } 213} 214