1<?php
2
3/**
4 * DokuWiki Bootstrap3 Template: User Menu
5 *
6 * @link     http://dokuwiki.org/template:bootstrap3
7 * @author   Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
8 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 */
10
11global $INFO, $lang, $TPL;
12
13$use_avatar = $TPL->getConf('useAvatar');
14
15$extensions_update = array();
16$avatar_size       = 96;
17$avatar_size_small = 32;
18
19if ($use_avatar) {
20    $avatar_img_small = $TPL->getAvatar($_SERVER['REMOTE_USER'], $INFO['userinfo']['mail'], $avatar_size_small);
21    $avatar_img       = $TPL->getAvatar($_SERVER['REMOTE_USER'], $INFO['userinfo']['mail'], $avatar_size);
22} else {
23    $avatar_img = tpl_getMediaFile(array('images/avatar.png'));
24}
25
26$label_type = 'info';
27$user_type  = 'User';
28
29if ($INFO['ismanager']) {
30    $label_type = 'warning';
31    $user_type  = 'Manager';
32}
33
34if ($INFO['isadmin']) {
35    $label_type = 'danger';
36    $user_type  = 'Admin';
37}
38
39if ($INFO['isadmin'] && $TPL->getConf('notifyExtensionsUpdate')) {
40
41    /** @var $plugin_controller PluginController */
42    global $plugin_controller;
43
44    $extension = plugin_load('helper','extension_extension');
45
46    foreach ($plugin_controller->getList('', true) as $plugin) {
47        $extension->setExtension($plugin);
48        if ($extension->updateAvailable() && $extension->isEnabled()) {
49            $extensions_update[] = $extension->getDisplayName();
50        }
51    }
52
53  sort($extensions_update);
54
55}
56
57?>
58<!-- user-menu -->
59<ul class="nav navbar-nav" id="dw__user_menu">
60    <li class="dropdown">
61
62        <a href="<?php wl($ID) ?>" class="dropdown-toggle" data-target="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
63            <?php if ($use_avatar): ?>
64            <img alt="<?php echo hsc($_SERVER['REMOTE_USER']) ?>" src="<?php echo $avatar_img_small ?>" class="img-circle profile-image" width="<?php echo $avatar_size_small ?>" height="<?php echo $avatar_size_small ?>" />
65            <?php else: ?>
66            <?php echo iconify('mdi:account'); ?>
67            <?php endif; ?> <span class="hidden-lg hidden-md hidden-sm"><?php echo hsc($_SERVER['REMOTE_USER']) ?></span> <span class="caret"></span>
68        </a>
69
70        <ul class="dropdown-menu" role="menu">
71
72            <li>
73
74                <div class="container-fluid">
75
76                    <p class="text-right">
77                        <span style="cursor:help" class="label label-<?php echo $label_type; ?>" title="<?php echo tpl_getLang('user_groups'); ?>: <?php echo join(', ', $INFO['userinfo']['grps']); ?>">
78                            <?php echo $user_type; ?>
79                        </span>
80                    </p>
81
82                    <p class="text-center">
83                        <img alt="<?php echo hsc($_SERVER['REMOTE_USER']) ?>" src="<?php echo $avatar_img ?>" class="img-circle" width="<?php echo $avatar_size ?>" height="<?php echo $avatar_size ?>" />
84                    </p>
85
86                    <div class="mb-2">
87                        <div class="mb-2">
88                            <strong><?php echo hsc($INFO['userinfo']['name']) ?></strong>
89                        </div>
90                        <div class="small">
91                            <bdi><?php echo hsc($_SERVER['REMOTE_USER']) ?></bdi>
92                        </div>
93                        <div class="small">
94                            <?php echo $INFO['userinfo']['mail'] ?>
95                        </div>
96                    </div>
97
98                </div>
99
100            </li>
101
102            <li class="divider"></li>
103
104            <?php if ($TPL->getConf('showUserHomeLink')): ?>
105            <li class="dropdown-header">Home-Page</li>
106            <?php
107                if ($userhomepage = $TPL->getPlugin('userhomepage')):
108                    echo '<li><a rel="nofollow" href="' . wl($userhomepage->getPublicID()) . '" title="'. $userhomepage->getLang('publicpage') .'">' .
109                         iconify('mdi:home') . ' ' . $userhomepage->getLang('publicpage') .'</a></li>';
110
111                    echo '<li><a rel="nofollow" href="' . wl($userhomepage->getPrivateID()) . '" title="'. $userhomepage->getLang('privatenamespace') .'">' .
112                         iconify('mdi:home-account') . ' ' . $userhomepage->getLang('privatenamespace') .'</a></li>';
113                else:
114            ?>
115
116            <li>
117                <a href="<?php echo $TPL->getUserHomePageLink() ?>" title="Home-Page" rel="nofollow">
118                    <?php echo iconify('mdi:home-account'); ?> Home-Page
119                </a>
120            </li>
121
122            <?php endif; ?>
123            <li class="divider"></li>
124            <?php endif; ?>
125
126            <li class="dropdown-header"><?php echo $lang['user_tools'] ?></li>
127
128            <?php
129
130                echo $TPL->getToolMenuItemLink('user', 'profile');
131
132                if ($INFO['isadmin']) {
133                    echo $TPL->getToolMenuItemLink('user', 'admin');
134                }
135
136            ?>
137
138            <?php if ($INFO['isadmin'] && count($extensions_update)): ?>
139            <li>
140                <a href="<?php echo wl($ID, array('do' => 'admin', 'page' => 'extension')); ?>" title=" - <?php echo implode('&#13; - ', $extensions_update) ?>">
141                    <?php echo iconify('mdi:puzzle', array('class' => 'text-success')) ?> <?php echo tpl_getLang('extensions_update'); ?> <span class="badge"><?php echo count($extensions_update) ?></span>
142                </a>
143            </li>
144            <?php endif; ?>
145
146            <li class="divider"></li>
147
148            <?php
149
150                // Add the user menu
151
152                $usermenu_pageid = null;
153                $user_homepage_id = $TPL->getUserHomePageID();
154
155                foreach (array("$user_homepage_id:usermenu", 'usermenu') as $id) {
156                    $usermenu_pageid = page_findnearest($id, $TPL->getConf('useACL'));
157                    if ($usermenu_pageid) break;
158                }
159
160                if ($usermenu_pageid) {
161
162                    $html = new simple_html_dom;
163                    $html->load($TPL->includePage($usermenu_pageid, true), true, false);
164
165                    foreach ($html->find('h1,h2,h3,h4,h5,h6') as $elm) {
166                        $elm->outertext = '<li class="dropdown-header">' . $elm->innertext . '</li>';
167                    }
168                    foreach ($html->find('hr') as $elm) {
169                        $elm->outertext = '<li class="divider"></li>';
170                    }
171                    foreach ($html->find('ul') as $elm) {
172                        $elm->outertext = '' . $elm->innertext;
173                    }
174                    foreach ($html->find('div') as $elm) {
175                        $elm->outertext = $elm->innertext;
176                    }
177
178                    $content = $html->save();
179
180                    $html->clear();
181                    unset($html);
182
183                    $content = str_replace('urlextern', '', $content);
184
185                    echo $content;
186                    echo '<li class="divider"></li>';
187
188                }
189            ?>
190
191            <?php
192                echo $TPL->getToolMenuItemLink('user', 'logout');
193            ?>
194
195        </ul>
196    </li>
197</ul>
198<!-- /user-menu -->
199