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 * Get the logo of the wiki 16 * 17 * @return string 18 */ 19if (!function_exists('tpl_getLogo')) { 20 function tpl_getLogo() 21 { 22 global $ID,$conf; 23 24 $return = ''; 25 $logoSize = array(); 26 $logoImages = array(); 27 if(tpl_getConf('doLogoChangesByNamespace')){ 28 $namespace = ""; 29 $namespaces = array(); 30 foreach(explode(':',getNS($ID)) as $ns){ 31 $namespace .= "$ns:"; 32 $namespaces[] = $namespace; 33 } 34 foreach(array_reverse($namespaces) as $namespace){ 35 $logoImages[] = ":".trim($namespace,":").":logo.png"; 36 } 37 } 38 $logoImages[] = ':logo.png'; 39 $logoImages[] = ':wiki:logo.png'; 40 $logoImages[] = 'images/logo.png'; 41 $logo = tpl_getMediaFile($logoImages, false, $logoSize); 42 $link = wl(); 43 if(tpl_getConf('doLogoLinkChangesByNamespace')){ 44 $link = str_replace(['/_media','logo.png'],['','index'],$logo); 45 } 46 47 $return .= '<a class="site-logo" href="'.$link.'" title="'.$conf['title'].'" rel="home" accesskey="h" title="[H]">'; 48 $return .= '<img src="'.$logo.'" '.$logoSize[3].' alt="" class="no-grav header-image" />'; 49 $return .= '</a>'; 50 51 return $return; 52 } 53} 54 55/** 56 * Generate the gravatar URL for a given email 57 * 58 * @return string 59 */ 60if (!function_exists('tpl_getGravatarURL')) { 61 function tpl_getGravatarURL($email, $size = 96) 62 { 63 return 'https://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$size; 64 } 65} 66 67 68/** 69 * Generate the HTML for a menu 70 * 71 * @return string 72 */ 73if (!function_exists('tpl_getMenu')) { 74 function tpl_getMenu($menu) 75 { 76 switch($menu){ 77 case 'usermenu': 78 return tpl_getUserMenu(); 79 break; 80 case 'sidebarmenu': 81 return tpl_getSidebarMenu(); 82 break; 83 } 84 } 85} 86 87/** 88 * Generate the HTML for the user menu 89 * 90 * @return string 91 */ 92if (!function_exists('tpl_getUserMenu')) { 93 function tpl_getUserMenu() 94 { 95 global $lang,$ID,$conf,$INFO; 96 97 $return = ''; 98 99 $items = (new \dokuwiki\Menu\UserMenu())->getItems(); 100 101 if(isset($INFO['userinfo'])){ 102 $return .= '<div class="dropdown user-tools">'; 103 $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">'; 104 $return .= '<i class="bi bi-person"></i>'.$INFO['userinfo']['name']; 105 $return .= '</a>'; 106 $return .= '<ul class="dropdown-menu" role="menu">'; 107 $return .= '<li>'; 108 $return .= '<p class="avatar">'; 109 $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail']).'" />'; 110 $return .= '</p>'; 111 $return .= '</li>'; 112 foreach($items as $item) { 113 $return .= '<li>' 114 .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 115 .'<i></i> ' 116 .$item->getLabel() 117 .'</a></li>'; 118 } 119 $return .= '</ul>'; 120 $return .= '</div>'; 121 } else { 122 $return .= '<div class="inline user-tools">'; 123 foreach($items as $item) { 124 $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 125 .'<i></i> ' 126 .$item->getLabel() 127 .'</a>'; 128 } 129 $return .= '</div>'; 130 } 131 132 return $return; 133 } 134} 135 136/** 137 * Generate the HTML for the sidebar menus 138 * 139 * @return string 140 */ 141if (!function_exists('tpl_getSidebarMenu')) { 142 function tpl_getSidebarMenu() 143 { 144 global $lang,$ID,$conf,$INFO; 145 146 $userItems = (new \dokuwiki\Menu\UserMenu())->getItems(); 147 $siteItems = (new \dokuwiki\Menu\SiteMenu())->getItems(); 148 149 $return = ''; 150 151 $return .= '<div id="writr__sidebar__tools">'; 152 153 if(isset($INFO['userinfo'])){ 154 $return .= '<div class="user-tools">'; 155 $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">'; 156 $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail'], 32).'" />'; 157 $return .= '<span>'.$INFO['userinfo']['name'].'</span>'; 158 $return .= '</a>'; 159 $return .= '<div id="user-tools-menu" class="collapsed">'; 160 $return .= '<ul class="menu" role="menu">'; 161 foreach($userItems as $item) { 162 $return .= '<li>' 163 .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 164 .'<i></i> ' 165 .$item->getLabel() 166 .'</a></li>'; 167 } 168 $return .= '</ul>'; 169 $return .= '</div>'; 170 $return .= '</div>'; 171 } else { 172 $return .= '<div class="user-tools">'; 173 foreach($userItems as $item) { 174 $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">' 175 .'<i></i> ' 176 .$item->getLabel() 177 .'</a>'; 178 } 179 $return .= '</div>'; 180 } 181 182 $return .= '</div>'; 183 184 return $return; 185 } 186} 187