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
49 protected $page = null;
51 /* What to filter the search results by */
52 protected $filter = null;
57 * @return string Title of the page
61 // @fixme: This looks kinda gross
63 if ($this->filter == 'All') {
64 if ($this->page != 1) {
65 return(sprintf(_m('All users, page %d'), $this->page));
67 return _m('All users');
70 if ($this->page == 1) {
72 _m('Users with nicknames beginning with %s'),
77 _m('Users with nicknames starting with %s, page %d'),
85 * Instructions for use
87 * @return instructions for use
89 function getInstructions()
91 return _('User directory');
95 * Is this page read-only?
97 * @return boolean true
99 function isReadOnly($args)
105 * Take arguments for running
107 * @param array $args $_REQUEST args
109 * @return boolean success flag
111 * @todo move queries from showContent() to here
113 function prepare($args)
115 parent::prepare($args);
117 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
118 $this->filter = $this->arg('filter') ? $this->arg('filter') : 'All';
119 common_set_returnto($this->selfUrl());
129 * @param array $args $_REQUEST args; handled in prepare()
133 function handle($args)
135 parent::handle($args);
140 * Show the page notice
142 * Shows instructions for the page
146 function showPageNotice()
148 $instr = $this->getInstructions();
149 $output = common_markup_to_html($instr);
151 $this->elementStart('div', 'instructions');
153 $this->elementEnd('div');
159 * This page is part of the public group, so show that.
163 function showLocalNav()
165 $nav = new PublicGroupNav($this);
172 * Shows the list of popular notices
176 function showContent()
178 // XXX Need search bar
180 $alphaNav = new AlphaNav($this, true, array('All'));
183 // XXX Maybe use a more specialized version of ProfileList here
185 $profile = $this->getUsers();
188 if (!empty($profile)) {
189 $profileList = new SubscriptionList(
191 common_current_user(),
195 $cnt = $profileList->show();
198 $this->showEmptyListMessage();
202 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
203 $this->page, 'userdirectory',
204 array('filter' => $this->filter));
209 * Get users filtered by the current filter and page
213 $offset = ($this->page-1) * PROFILES_PER_PAGE;
214 $limit = PROFILES_PER_PAGE + 1;
216 $profile = new Profile();
218 if ($this->filter != 'All') {
220 sprintf('LEFT(UPPER(nickname), 1) = \'%s\'', $this->filter)
223 $profile->orderBy('created DESC, nickname');
230 * Show a nice message when there's no search results
232 function showEmptyListMessage()
234 $message = sprintf(_m('No users starting with %s'), $this->filter);
236 $this->elementStart('div', 'guide');
237 $this->raw(common_markup_to_html($message));
238 $this->elementEnd('div');