3 * StatusNet, the distributed open-source microblogging tool
5 * Output a user directory
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2011 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET'))
35 require_once INSTALLDIR . '/lib/publicgroupnav.php';
42 * @author Zach Copley <zach@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
46 class UserdirectoryAction extends Action
56 * What to filter the search results by
70 * How to order search results, ascending or descending
86 * @return string Title of the page
90 // @fixme: This looks kinda gross
92 if ($this->filter == 'all') {
93 if ($this->page != 1) {
94 return(sprintf(_m('All users, page %d'), $this->page));
96 return _m('All users');
99 if ($this->page == 1) {
101 _m('Users with nicknames beginning with %s'),
106 _m('Users with nicknames starting with %s, page %d'),
114 * Instructions for use
116 * @return instructions for use
118 function getInstructions()
120 return _('User directory');
124 * Is this page read-only?
126 * @return boolean true
128 function isReadOnly($args)
134 * Take arguments for running
136 * @param array $args $_REQUEST args
138 * @return boolean success flag
140 function prepare($args)
142 parent::prepare($args);
144 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
145 $this->filter = $this->arg('filter', 'all');
146 $this->reverse = $this->boolean('reverse');
147 $this->q = $this->trimmed('q');
148 $this->sort = $this->arg('sort', 'nickname');
150 common_set_returnto($this->selfUrl());
160 * @param array $args $_REQUEST args; handled in prepare()
164 function handle($args)
166 parent::handle($args);
171 * Show the page notice
173 * Shows instructions for the page
177 function showPageNotice()
179 $instr = $this->getInstructions();
180 $output = common_markup_to_html($instr);
182 $this->elementStart('div', 'instructions');
184 $this->elementEnd('div');
190 * This page is part of the public group, so show that.
194 function showLocalNav()
196 $nav = new PublicGroupNav($this);
203 * Shows the list of popular notices
207 function showContent()
211 $this->elementStart('div', array('id' => 'user_directory'));
213 $alphaNav = new AlphaNav($this, true, array('All'));
217 $profile = $this->getUsers();
220 if (!empty($profile)) {
221 $profileList = new SortableSubscriptionList(
223 common_current_user(),
227 $cnt = $profileList->show();
231 $this->showEmptyListMessage();
236 if (isset($this->q)) {
237 $args['q'] = $this->q;
239 $args['filter'] = $this->filter;
244 $cnt > PROFILES_PER_PAGE,
250 $this->elementEnd('div');
254 function showForm($error=null)
260 'id' => 'form_search',
261 'class' => 'form_settings',
262 'action' => common_local_url('userdirectory')
266 $this->elementStart('fieldset');
268 $this->element('legend', null, _('Search site'));
269 $this->elementStart('ul', 'form_data');
270 $this->elementStart('li');
272 $this->input('q', _('Keyword(s)'), $this->q);
274 $this->submit('search', _m('BUTTON','Search'));
275 $this->elementEnd('li');
276 $this->elementEnd('ul');
277 $this->elementEnd('fieldset');
278 $this->elementEnd('form');
282 * Get users filtered by the current filter, sort key,
283 * sort order, and page
287 $profile = new Profile();
289 $offset = ($this->page - 1) * PROFILES_PER_PAGE;
290 $limit = PROFILES_PER_PAGE + 1;
292 if (isset($this->q)) {
293 // User is searching via query
294 $search_engine = $profile->getSearchEngine('profile');
296 $mode = 'reverse_chron';
298 if ($this->sort == 'nickname') {
299 if ($this->reverse) {
300 $mode = 'nickname_desc';
302 $mode = 'nickname_asc';
305 if ($this->reverse) {
310 $search_engine->set_sort_mode($mode);
311 $search_engine->limit($offset, $limit);
312 $search_engine->query($this->q);
316 // User is browsing via AlphaNav
317 $sort = $this->getSortKey();
318 $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
320 if ($this->filter != 'all') {
322 ' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
328 ' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
330 $this->reverse ? 'DESC' : 'ASC',
335 $profile->query($sql);
342 * Filter the sort parameter
344 * @return string a column name for sorting
346 function getSortKey()
348 switch ($this->sort) {
361 * Show a nice message when there's no search results
363 function showEmptyListMessage()
365 $message = sprintf(_m('No users starting with **%s**'), $this->filter);
367 $this->elementStart('div', 'guide');
368 $this->raw(common_markup_to_html($message));
369 $this->elementEnd('div');