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 // @todo fixme: This looks kinda gross
92 if ($this->filter == 'all') {
93 if ($this->page != 1) {
94 // TRANS: Page title for user directory. %d is a page number.
95 return(sprintf(_m('User Directory, page %d'), $this->page));
97 // TRANS: Page title for user directory.
98 return _m('User directory');
99 } else if ($this->page == 1) {
101 // TRANS: Page title for user directory. %s is the applied filter.
102 _m('User directory - %s'),
103 strtoupper($this->filter)
107 // TRANS: Page title for user directory.
108 // TRANS: %1$s is the applied filter, %2$d is a page number.
109 _m('User directory - %1$s, page %2$d'),
110 strtoupper($this->filter),
117 * Instructions for use
119 * @return instructions for use
121 function getInstructions()
123 // TRANS: %%site.name%% is the name of the StatusNet site.
124 return _m('Search for people on %%site.name%% by their name, '
125 . 'location, or interests. Separate the terms by spaces; '
126 . ' they must be 3 characters or more.'
131 * Is this page read-only?
133 * @return boolean true
135 function isReadOnly($args)
141 * Take arguments for running
143 * @param array $args $_REQUEST args
145 * @return boolean success flag
147 function prepare($args)
149 parent::prepare($args);
151 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
152 $this->filter = $this->arg('filter', 'all');
153 $this->reverse = $this->boolean('reverse');
154 $this->q = $this->trimmed('q');
155 $this->sort = $this->arg('sort', 'nickname');
157 common_set_returnto($this->selfUrl());
167 * @param array $args $_REQUEST args; handled in prepare()
171 function handle($args)
173 parent::handle($args);
178 * Show the page notice
180 * Shows instructions for the page
184 function showPageNotice()
186 $instr = $this->getInstructions();
187 $output = common_markup_to_html($instr);
189 $this->elementStart('div', 'instructions');
191 $this->elementEnd('div');
198 * Shows the list of popular notices
202 function showContent()
206 $this->elementStart('div', array('id' => 'profile_directory'));
208 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
212 $profile = $this->getUsers();
215 if (!empty($profile)) {
216 $profileList = new SortableSubscriptionList(
218 common_current_user(),
222 $cnt = $profileList->show();
226 $this->showEmptyListMessage();
231 if (isset($this->q)) {
232 $args['q'] = $this->q;
233 } elseif (isset($this->filter) && $this->filter != 'all') {
234 $args['filter'] = $this->filter;
237 if (isset($this->sort)) {
238 $args['sort'] = $this->sort;
240 if (!empty($this->reverse)) {
241 $args['reverse'] = $this->reverse;
246 $cnt > PROFILES_PER_PAGE,
252 $this->elementEnd('div');
256 function showForm($error=null)
262 'id' => 'form_search',
263 'class' => 'form_settings',
264 'action' => common_local_url('userdirectory')
268 $this->elementStart('fieldset');
270 // TRANS: Fieldset legend.
271 $this->element('legend', null, _m('Search site'));
272 $this->elementStart('ul', 'form_data');
273 $this->elementStart('li');
275 // TRANS: Field label for user directory filter.
276 $this->input('q', _m('Keyword(s)'), $this->q);
278 // TRANS: Button text.
279 $this->submit('search', _m('BUTTON','Search'));
280 $this->elementEnd('li');
281 $this->elementEnd('ul');
282 $this->elementEnd('fieldset');
283 $this->elementEnd('form');
287 * Get users filtered by the current filter, sort key,
288 * sort order, and page
292 $profile = new Profile();
294 $offset = ($this->page - 1) * PROFILES_PER_PAGE;
295 $limit = PROFILES_PER_PAGE + 1;
297 if (isset($this->q)) {
298 // User is searching via query
299 $search_engine = $profile->getSearchEngine('profile');
301 $mode = 'reverse_chron';
303 if ($this->sort == 'nickname') {
304 if ($this->reverse) {
305 $mode = 'nickname_desc';
307 $mode = 'nickname_asc';
310 if ($this->reverse) {
315 $search_engine->set_sort_mode($mode);
316 $search_engine->limit($offset, $limit);
317 $search_engine->query($this->q);
321 // User is browsing via AlphaNav
322 $sort = $this->getSortKey();
323 $sql = 'SELECT profile.* FROM profile, user WHERE profile.id = user.id';
325 switch($this->filter)
332 ' AND LEFT(profile.nickname, 1) BETWEEN \'0\' AND \'9\'';
336 ' AND LEFT(LOWER(profile.nickname), 1) = \'%s\'',
342 ' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
344 $this->reverse ? 'DESC' : 'ASC',
349 $profile->query($sql);
356 * Filter the sort parameter
358 * @return string a column name for sorting
360 function getSortKey()
362 switch ($this->sort) {
375 * Show a nice message when there's no search results
377 function showEmptyListMessage()
379 if (!empty($this->filter) && ($this->filter != 'all')) {
384 // TRANS: Empty list message for user directory.
385 _m('No users starting with %s'),
390 // TRANS: Empty list message for user directory.
391 $this->element('p', 'error', _m('No results.'));
392 // TRANS: Standard search suggestions shown when a search does not give any results.
393 $message = _m("* Make sure all words are spelled correctly.
394 * Try different keywords.
395 * Try more general keywords.
396 * Try fewer keywords.");
399 $this->elementStart('div', 'help instructions');
400 $this->raw(common_markup_to_html($message));
401 $this->elementEnd('div');