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('GNUSOCIAL')) { exit(1); }
37 * @author Zach Copley <zach@status.net>
38 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39 * @link http://status.net/
41 class UserdirectoryAction extends ManagedAction
51 * What to filter the search results by
65 * How to order search results, ascending or descending
81 * @return string Title of the page
85 // @todo fixme: This looks kinda gross
87 if ($this->filter == 'all') {
88 if ($this->page != 1) {
89 // TRANS: Page title for user directory. %d is a page number.
90 return(sprintf(_m('User Directory, page %d'), $this->page));
92 // TRANS: Page title for user directory.
93 return _m('User directory');
94 } else if ($this->page == 1) {
96 // TRANS: Page title for user directory. %s is the applied filter.
97 _m('User directory - %s'),
98 strtoupper($this->filter)
102 // TRANS: Page title for user directory.
103 // TRANS: %1$s is the applied filter, %2$d is a page number.
104 _m('User directory - %1$s, page %2$d'),
105 strtoupper($this->filter),
112 * Instructions for use
114 * @return instructions for use
116 function getInstructions()
118 // TRANS: %%site.name%% is the name of the StatusNet site.
119 return _m('Search for people on %%site.name%% by their name, '
120 . 'location, or interests. Separate the terms by spaces; '
121 . ' they must be 3 characters or more.'
126 * Is this page read-only?
128 * @return boolean true
130 function isReadOnly($args)
135 protected function doPreparation()
137 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
138 $this->filter = $this->arg('filter', 'all');
139 $this->reverse = $this->boolean('reverse');
140 $this->q = $this->trimmed('q');
141 $this->sort = $this->arg('sort', 'nickname');
143 common_set_returnto($this->selfUrl());
147 * Show the page notice
149 * Shows instructions for the page
153 function showPageNotice()
155 $instr = $this->getInstructions();
156 $output = common_markup_to_html($instr);
158 $this->elementStart('div', 'instructions');
160 $this->elementEnd('div');
167 * Shows the list of popular notices
171 function showContent()
175 $this->elementStart('div', array('id' => 'profile_directory'));
177 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
181 $profile = $this->getUsers();
184 if (!empty($profile)) {
185 $profileList = new SortableSubscriptionList(
187 common_current_user(),
191 $cnt = $profileList->show();
195 $this->showEmptyListMessage();
200 if (isset($this->q)) {
201 $args['q'] = $this->q;
202 } elseif (isset($this->filter) && $this->filter != 'all') {
203 $args['filter'] = $this->filter;
206 if (isset($this->sort)) {
207 $args['sort'] = $this->sort;
209 if (!empty($this->reverse)) {
210 $args['reverse'] = $this->reverse;
215 $cnt > PROFILES_PER_PAGE,
221 $this->elementEnd('div');
225 function showForm($error=null)
231 'id' => 'form_search',
232 'class' => 'form_settings',
233 'action' => common_local_url('userdirectory')
237 $this->elementStart('fieldset');
239 // TRANS: Fieldset legend.
240 $this->element('legend', null, _m('Search site'));
241 $this->elementStart('ul', 'form_data');
242 $this->elementStart('li');
244 // TRANS: Field label for user directory filter.
245 $this->input('q', _m('Keyword(s)'), $this->q);
247 // TRANS: Button text.
248 $this->submit('search', _m('BUTTON','Search'));
249 $this->elementEnd('li');
250 $this->elementEnd('ul');
251 $this->elementEnd('fieldset');
252 $this->elementEnd('form');
256 * Get users filtered by the current filter, sort key,
257 * sort order, and page
261 $profile = new Profile();
263 // Comment this out or disable to get global profile searches
264 $profile->joinAdd(array('id', 'user:id'));
266 $offset = ($this->page - 1) * PROFILES_PER_PAGE;
267 $limit = PROFILES_PER_PAGE + 1;
269 if (!empty($this->q)) {
270 // User is searching via query
271 $search_engine = $profile->getSearchEngine('profile');
273 $mode = 'reverse_chron';
275 if ($this->sort == 'nickname') {
276 if ($this->reverse) {
277 $mode = 'nickname_desc';
279 $mode = 'nickname_asc';
282 if ($this->reverse) {
287 $search_engine->set_sort_mode($mode);
288 $search_engine->limit($offset, $limit);
289 $search_engine->query($this->q);
293 // User is browsing via AlphaNav
295 switch ($this->filter) {
300 $profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
301 $profile->escapedTableName(),
303 $profile->_quote("0"),
304 $profile->_quote("9")));
307 $profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
308 $profile->escapedTableName(),
310 $profile->_quote($this->filter)));
313 $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
314 $profile->escapedTableName(),
315 $this->getSortKey('nickname'),
316 $this->reverse ? 'DESC' : 'ASC',
318 $profile->orderBy($order);
319 $profile->limit($offset, $limit);
328 * Filter the sort parameter
330 * @return string a column name for sorting
332 function getSortKey($def='nickname')
334 switch ($this->sort) {
344 * Show a nice message when there's no search results
346 function showEmptyListMessage()
348 if (!empty($this->filter) && ($this->filter != 'all')) {
353 // TRANS: Empty list message for user directory.
354 _m('No users starting with %s'),
359 // TRANS: Empty list message for user directory.
360 $this->element('p', 'error', _m('No results.'));
361 // TRANS: Standard search suggestions shown when a search does not give any results.
362 $message = _m("* Make sure all words are spelled correctly.
363 * Try different keywords.
364 * Try more general keywords.
365 * Try fewer keywords.");
368 $this->elementStart('div', 'help instructions');
369 $this->raw(common_markup_to_html($message));
370 $this->elementEnd('div');