1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function wikiplugin_userlist_info() 9{ 10 return [ 11 'name' => tra('User List'), 12 'documentation' => 'PluginUserList', 13 'description' => tra('Display a list of registered users'), 14 'prefs' => [ 'wikiplugin_userlist' ], 15 'body' => tra('Login Filter'), 16 'iconname' => 'group', 17 'introduced' => 3, 18 'params' => [ 19 'sep' => [ 20 'required' => false, 21 'name' => tra('Separator'), 22 'description' => tra('Separator to use between users in the list. Default: comma'), 23 'since' => '3.0', 24 'default' => ', ', 25 'advanced' => true, 26 ], 27 'max' => [ 28 'required' => false, 29 'name' => tra('Maximum'), 30 'description' => tra('Result limit'), 31 'since' => '3.0', 32 'default' => '', 33 'filter' => 'digits', 34 'advanced' => true, 35 ], 36 'sort' => [ 37 'required' => false, 38 'name' => tra('Sort order'), 39 'description' => tra('Set to sort in ascending or descending order'), 40 'since' => '3.0', 41 'default' => '', 42 'filter' => 'alpha', 43 'options' => [ 44 ['text' => '', 'value' => ''], 45 ['text' => tra('Ascending'), 'value' => 'asc'], 46 ['text' => tra('Descending'), 'value' => 'desc'], 47 ], 48 ], 49 'layout' => [ 50 'required' => false, 51 'name' => tra('Layout'), 52 'description' => tra('Set to table to display results in a table'), 53 'since' => '3.0', 54 'default' => '', 55 'filter' => 'alpha', 56 'options' => [ 57 ['text' => '', 'value' => ''], 58 ['text' => tra('List'), 'value' => ''], 59 ['text' => tra('Table'), 'value' => 'table'], 60 ], 61 ], 62 'link' => [ 63 'required' => false, 64 'name' => tra('Link'), 65 'description' => tra('Make the user names listed links to different types of user information'), 66 'since' => '3.0', 67 'default' => '', 68 'filter' => 'alpha', 69 'options' => [ 70 ['text' => '', 'value' => ''], 71 ['text' => tra('User info'), 'value' => 'userinfo'], 72 ['text' => tra('User page'), 'value' => 'userpage'], 73 ['text' => tra('User pref'), 'value' => 'userpref'], 74 ], 75 ], 76 'realname' => [ 77 'required' => false, 78 'filter' => 'alpha', 79 'name' => tra('Real Name'), 80 'description' => tra('Display the user\'s real name (when available) instead of login name'), 81 'since' => '4.0', 82 'default' => '', 83 'options' => [ 84 ['text' => '', 'value' => ''], 85 ['text' => tra('Yes'), 'value' => 'y'], 86 ['text' => tra('No'), 'value' => ''], 87 ], 88 ], 89 'group' => [ 90 'required' => false, 91 'name' => tra('Group'), 92 'description' => tra('Filter on a group'), 93 'since' => '5.0', 94 'filter' => 'groupname', 95 'default' => '', 96 ], 97 ], 98 ]; 99} 100 101function wikiplugin_userlist($data, $params) 102{ 103 global $prefs, $tiki_p_admin, $tiki_p_admin_users, $user; 104 $userlib = TikiLib::lib('user'); 105 $tikilib = TikiLib::lib('tiki'); 106 107 extract($params, EXTR_SKIP); 108 109 if (! isset($sep)) { 110 $sep = ', '; 111 } 112 if (! isset($max)) { 113 $numRows = -1; 114 } else { 115 $numRows = (int) $max; 116 } 117 118 $from = ''; 119 if ($data) { 120 $mid = '`login` like ?'; 121 $findesc = '%' . $data . '%'; 122 $bindvars = [$findesc]; 123 } else { 124 $mid = '1'; 125 $bindvars = []; 126 } 127 $pre = ''; 128 $post = ''; 129 if (isset($layout)) { 130 if ($layout == 'table') { 131 $pre = '<table class=\'sortable\' id=\'' . $tikilib->now . '\'><tr><th>' . tra('users') . '</th></tr><tr><td>'; 132 $sep = '</td></tr><tr><td>'; 133 $post = '</td></tr></table>'; 134 } 135 } 136 if (isset($group)) { 137 $from .= ", users_usergroups uug"; 138 $mid .= ' and uug.`groupName` = ? and uu.`userId` = uug.`userId`'; 139 $bindvars[] = $group; 140 } 141 if (isset($sort)) { 142 $sort = strtolower($sort); 143 if (($sort == 'asc') || ($sort == 'desc')) { 144 $mid .= ' ORDER BY `login` ' . $sort; 145 } 146 } 147 148 $query = "select `login`, uu.`userId` from `users_users` uu $from where $mid"; 149 $result = $tikilib->query($query, $bindvars, $numRows); 150 $ret = []; 151 152 while ($row = $result->fetchRow()) { 153 $res = ''; 154 if (isset($link)) { 155 if ($link == 'userpage') { 156 if ($prefs['feature_wiki_userpage'] == 'y') { 157 $wikilib = TikiLib::lib('wiki'); 158 $page = $prefs['feature_wiki_userpage_prefix'] . $row['login']; 159 if ($tikilib->page_exists($page)) { 160 $res = '<a href="' . $wikilib->sefurl($page) . '" title="' . tra('Page') . '">'; 161 } 162 } 163 } elseif (isset($link) && $link == 'userpref') { 164 if ($prefs['feature_userPreferences'] == 'y' && ($tiki_p_admin_users == 'y' || $tiki_p_admin == 'y')) { 165 $res = '<a href="tiki-user_preferences.php?userId=' . $row['userId'] . '" title="' . tra('Preferences') . '">'; 166 } 167 } elseif (isset($link) && $link == 'userinfo') { 168 if ($tiki_p_admin_users == 'y' || $tiki_p_admin == 'y') { 169 $res = '<a href="tiki-user_information.php?userId=' . $row['userId'] . '" title="' . tra('User Information') . '">'; 170 } else { 171 $user_information = $tikilib->get_user_preference($row['login'], 'user_information', 'public'); 172 if ($user_information != 'private' && $row['login'] != $user) { 173 $res = '<a href="tiki-user_information.php?userId=' . $row['userId'] . '" title="' . tra('User Information') . '">'; 174 } 175 } 176 } 177 } 178 $displayName = $row['login']; 179 if ($params['realname']) { 180 $realName = $tikilib->get_user_preference($row['login'], 'realName'); 181 182 if ($realName) { 183 $displayName = $realName; 184 } 185 } 186 187 $ret[] = $res . $displayName . ($res ? '</a>' : ''); 188 } 189 return $pre . implode($sep, $ret) . $post; 190} 191