1<?php
2/**
3 * DokuWiki Plugin usercontact (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Adrian Lang <lang@cosmocode.de>
7 */
8
9class action_plugin_usercontact extends DokuWiki_Action_Plugin
10{
11
12    function register(Doku_Event_Handler $controller)
13    {
14        global $JSINFO;
15        $JSINFO['plugin']['usercontact']['users_namespace'] = $this->getConf('users_namespace');
16
17        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
18    }
19
20    public function handle_ajax_call_unknown(Doku_Event $event, $param)
21    {
22        if ($event->data !== 'plugin_usercontact') {
23            return;
24        }
25
26        $event->preventDefault();
27        $event->stopPropagation();
28
29        /** @var DokuWiki_Auth_Plugin $auth */
30        global $auth;
31        global $INPUT;
32
33        $userdata = $auth->getUserData($INPUT->str('name'));
34        if (empty($userdata)) {
35            http_status(404, 'User not found');
36            return;
37        }
38        $fields = explode(',', $this->getConf('fields'));
39        $fields = array_map('trim', $fields);
40        $fields = array_filter($fields);
41
42        if (count($userdata) > 0) {
43            echo '<ul>';
44            foreach ($fields as $name) {
45                if (!isset($userdata[$name])) {
46                    continue;
47                }
48
49                $val = $userdata[$name];
50                echo '<li class="userov_' . hsc($name) . '">';
51                echo '<div class="li">';
52                if ($name === 'mail') {
53                    echo '<a href="mailto:' . obfuscate($val) . '" class="mail">' . obfuscate($val) . '</a>';
54                } else {
55                    echo hsc($val);
56                }
57                echo '</div></li>';
58            }
59            echo '</ul>';
60        }
61    }
62}
63