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 %%site.name%% groups let you find and talk with people of similar
124 interests. After you join a group you can send messages to all other
125 members using the syntax "!groupname".
127 Browse groups, or search for groups on by their name, location or topic.
128 Separate the terms by spaces; they must be three characters or more.
130 Don't see a group you like? [start your own](%%action.newgroup%%)!
133 return _m($instructions);
137 * Is this page read-only?
139 * @return boolean true
141 function isReadOnly($args)
147 * Take arguments for running
149 * @param array $args $_REQUEST args
151 * @return boolean success flag
153 function prepare($args)
155 parent::prepare($args);
157 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
158 $this->filter = $this->arg('filter', 'all');
159 $this->reverse = $this->boolean('reverse');
160 $this->q = $this->trimmed('q');
161 $this->sort = $this->arg('sort', 'nickname');
163 common_set_returnto($this->selfUrl());
173 * @param array $args $_REQUEST args; handled in prepare()
177 function handle($args)
179 parent::handle($args);
184 * Show the page notice
186 * Shows instructions for the page
190 function showPageNotice()
192 $instr = $this->getInstructions();
193 $output = common_markup_to_html($instr);
195 $this->elementStart('div', 'instructions');
197 $this->elementEnd('div');
204 * Shows the list of popular notices
208 function showContent()
212 $this->elementStart('div', array('id' => 'profile_directory'));
214 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
218 $group = $this->getGroups();
221 if (!empty($group)) {
222 $groupList = new SortableGroupList(
224 common_current_user(),
228 $cnt = $groupList->show();
232 $this->showEmptyListMessage();
237 if (isset($this->q)) {
238 $args['q'] = $this->q;
240 $args['filter'] = $this->filter;
245 $cnt > PROFILES_PER_PAGE,
251 $this->elementEnd('div');
254 function showForm($error=null)
260 'id' => 'form_search',
261 'class' => 'form_settings',
262 'action' => common_local_url('groupdirectory')
266 $this->elementStart('fieldset');
268 $this->element('legend', null, _m('Search groups'));
269 $this->elementStart('ul', 'form_data');
270 $this->elementStart('li');
272 $this->input('q', _m('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 groups filtered by the current filter, sort key,
283 * sort order, and page
287 $group = new User_group();
289 $offset = ($this->page-1) * PROFILES_PER_PAGE;
290 $limit = PROFILES_PER_PAGE + 1;
292 if (isset($this->q)) {
294 $order = 'user_group.created ASC';
296 if ($this->sort == 'nickname') {
297 if ($this->reverse) {
298 $order = 'user_group.nickname DESC';
300 $order = 'user_group.nickname ASC';
303 if ($this->reverse) {
304 $order = 'user_group.created DESC';
308 $sql = <<< GROUP_QUERY_END
311 JOIN local_group ON user_group.id = local_group.group_id
317 $group->query(sprintf($sql, $order, $limit, $offset));
321 // User is browsing via AlphaNav
322 $sort = $this->getSortKey();
324 $sql = <<< GROUP_QUERY_END
327 JOIN local_group ON user_group.id = local_group.group_id
330 switch($this->filter)
337 ' AND LEFT(user_group.nickname, 1) BETWEEN \'0\' AND \'9\'';
341 ' AND LEFT(LOWER(user_group.nickname), 1) = \'%s\'',
347 ' ORDER BY user_group.%s %s, user_group.nickname ASC LIMIT %d, %d',
349 $this->reverse ? 'DESC' : 'ASC',
361 * Filter the sort parameter
363 * @return string a column name for sorting
365 function getSortKey()
367 switch ($this->sort) {
380 * Show a nice message when there's no search results
382 function showEmptyListMessage()
384 if (!empty($this->filter) && ($this->filter != 'all')) {
389 _m('No groups starting with %s'),
394 $this->element('p', 'error', _m('No results.'));
395 $message = _m(<<<E_O_T
396 * Make sure all words are spelled correctly.
397 * Try different keywords.
398 * Try more general keywords.
399 * Try fewer keywords.
402 $this->elementStart('div', 'help instructions');
403 $this->raw(common_markup_to_html($message));
404 $this->elementEnd('div');
408 // XXX This needs some adjustment
411 function showSections()
413 $gbp = new GroupsByPostsSection($this);
415 $gbm = new GroupsByMembersSection($this);