xref: /template/writr/tpl_functions.php (revision df5bf7f31039806933059535433560f8ed455a13)
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
43        $return .= '<a class="site-logo"  href="'.wl().'" title="'.$conf['title'].'" rel="home" accesskey="h" title="[H]">';
44        $return .= '<img src="'.$logo.'" '.$logoSize[3].' alt="" class="no-grav header-image" />';
45        $return .= '</a>';
46
47        return $return;
48    }
49}
50
51/**
52 * Generate the gravatar URL for a given email
53 *
54 * @return string
55 */
56if (!function_exists('tpl_getGravatarURL')) {
57    function tpl_getGravatarURL($email, $size = 96)
58    {
59        return 'https://www.gravatar.com/avatar/'.md5(strtolower(trim($email))).'?s='.$size;
60    }
61}
62
63
64/**
65 * Generate the HTML for a menu
66 *
67 * @return string
68 */
69if (!function_exists('tpl_getMenu')) {
70    function tpl_getMenu($menu)
71    {
72        switch($menu){
73            case 'usermenu':
74                return tpl_getUserMenu();
75                break;
76        }
77    }
78}
79
80/**
81 * Generate the HTML for the user menu
82 *
83 * @return string
84 */
85if (!function_exists('tpl_getUserMenu')) {
86    function tpl_getUserMenu()
87    {
88        global $lang,$ID,$conf,$INFO;
89
90        $return = '';
91
92        $items = (new \dokuwiki\Menu\UserMenu())->getItems();
93
94        if(isset($INFO['userinfo'])){
95            $return .= '<div class="dropdown user-tools">';
96                $return .= '<a href="'.wl($ID).'" class="dropdown-toggle" data-target="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">';
97                    $return .= '<i class="bi bi-person"></i>'.$INFO['userinfo']['name'];
98                $return .= '</a>';
99                $return .= '<ul class="dropdown-menu" role="menu">';
100                    $return .= '<li>';
101                        $return .= '<p class="avatar">';
102                            $return .= '<img alt="'.$INFO['userinfo']['name'].'" src="'.tpl_getGravatarURL($INFO['userinfo']['mail']).'" />';
103                        $return .= '</p>';
104                    $return .= '</li>';
105                    foreach($items as $item) {
106                        $return .= '<li>'
107                            .'<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">'
108                            .'<i></i> '
109                            .$item->getLabel()
110                            .'</a></li>';
111                    }
112                $return .= '</ul>';
113            $return .= '</div>';
114        } else {
115            $return .= '<div class="inline user-tools">';
116            foreach($items as $item) {
117                $return .= '<a href="'.$item->getLink().'" class="action '.strtolower($item->getType()).'" rel="nofollow" title="'.$item->getTitle().'">'
118                    .'<i></i> '
119                    .$item->getLabel()
120                    .'</a>';
121            }
122            $return .= '</div>';
123        }
124
125        return $return;
126    }
127}
128