3 * StatusNet, the distributed open-source microblogging tool
5 * Output a group 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 GroupdirectoryAction 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('Group Directory, page %d'), $this->page));
96 return _m('Group directory');
97 } else if ($this->page == 1) {
99 _m('Group directory - %s'),
100 strtoupper($this->filter)
104 _m('Group directory - %s, page %d'),
105 strtoupper($this->filter),
112 * Instructions for use
114 * @return instructions for use
116 function getInstructions()
118 // TRANS: Page notice for groups directory.
119 // TRANS: %%site.name%% is the name of the StatusNet site.
120 // TRANS: %%action.newgroup%% is a URL. Do not change it.
121 // TRANS: This message contains Markdown links in the form [link text](link).
122 $instructions = <<< END_OF_INSTRUCTIONS
123 After you join a group you can send messages to all other members
124 using the syntax "!groupname".
126 Browse groups, or search for groups on by their name, location or topic.
127 Separate the terms by spaces; they must be three characters or more.
130 return _m($instructions);
134 * Is this page read-only?
136 * @return boolean true
138 function isReadOnly($args)
144 * Take arguments for running
146 * @param array $args $_REQUEST args
148 * @return boolean success flag
150 function prepare($args)
152 parent::prepare($args);
154 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
155 $this->filter = $this->arg('filter', 'all');
156 $this->reverse = $this->boolean('reverse');
157 $this->q = $this->trimmed('q');
158 $this->sort = $this->arg('sort', 'nickname');
160 common_set_returnto($this->selfUrl());
170 * @param array $args $_REQUEST args; handled in prepare()
174 function handle($args)
176 parent::handle($args);
181 * Show the page notice
183 * Shows instructions for the page
187 function showPageNotice()
189 $instr = $this->getInstructions();
190 $output = common_markup_to_html($instr);
192 $this->elementStart('div', 'instructions');
194 $this->elementEnd('div');
205 function showContent()
207 if (common_logged_in()) {
217 'href' => common_local_url('newgroup'),
219 // TRANS: Link to create a new group on the group list page.
220 _('Create a new group')
222 $this->elementEnd('p');
227 $this->elementStart('div', array('id' => 'profile_directory'));
229 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
233 $group = $this->getGroups();
236 if (!empty($group)) {
237 $groupList = new SortableGroupList(
239 common_current_user(),
243 $cnt = $groupList->show();
247 $this->showEmptyListMessage();
252 if (isset($this->q)) {
253 $args['q'] = $this->q;
255 $args['filter'] = $this->filter;
260 $cnt > PROFILES_PER_PAGE,
266 $this->elementEnd('div');
269 function showForm($error=null)
275 'id' => 'form_search',
276 'class' => 'form_settings',
277 'action' => common_local_url('groupdirectory')
281 $this->elementStart('fieldset');
283 $this->element('legend', null, _m('Search groups'));
284 $this->elementStart('ul', 'form_data');
285 $this->elementStart('li');
287 $this->input('q', _m('Keyword(s)'), $this->q);
289 $this->submit('search', _m('BUTTON','Search'));
290 $this->elementEnd('li');
291 $this->elementEnd('ul');
292 $this->elementEnd('fieldset');
293 $this->elementEnd('form');
297 * Get groups filtered by the current filter, sort key,
298 * sort order, and page
302 $group = new User_group();
304 $offset = ($this->page-1) * PROFILES_PER_PAGE;
305 $limit = PROFILES_PER_PAGE + 1;
307 if (isset($this->q)) {
309 $order = 'user_group.created ASC';
311 if ($this->sort == 'nickname') {
312 if ($this->reverse) {
313 $order = 'user_group.nickname DESC';
315 $order = 'user_group.nickname ASC';
318 if ($this->reverse) {
319 $order = 'user_group.created DESC';
323 $sql = <<< GROUP_QUERY_END
326 JOIN local_group ON user_group.id = local_group.group_id
332 $group->query(sprintf($sql, $order, $limit, $offset));
336 // User is browsing via AlphaNav
337 $sort = $this->getSortKey();
339 $sql = <<< GROUP_QUERY_END
342 JOIN local_group ON user_group.id = local_group.group_id
345 switch($this->filter)
352 ' AND LEFT(user_group.nickname, 1) BETWEEN \'0\' AND \'9\'';
356 ' AND LEFT(LOWER(user_group.nickname), 1) = \'%s\'',
362 ' ORDER BY user_group.%s %s, user_group.nickname ASC LIMIT %d, %d',
364 $this->reverse ? 'DESC' : 'ASC',
376 * Filter the sort parameter
378 * @return string a column name for sorting
380 function getSortKey()
382 switch ($this->sort) {
395 * Show a nice message when there's no search results
397 function showEmptyListMessage()
399 if (!empty($this->filter) && ($this->filter != 'all')) {
404 _m('No groups starting with %s'),
409 $this->element('p', 'error', _m('No results.'));
410 $message = _m(<<<E_O_T
411 * Make sure all words are spelled correctly.
412 * Try different keywords.
413 * Try more general keywords.
414 * Try fewer keywords.
417 $this->elementStart('div', 'help instructions');
418 $this->raw(common_markup_to_html($message));
419 $this->elementEnd('div');
423 function showSections()
425 $gbp = new GroupsByPostsSection($this);
427 $gbm = new GroupsByMembersSection($this);