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('GNUSOCIAL')) { exit(1); }
37 * @author Zach Copley <zach@status.net>
38 * @author Mikael Nordfeldth <mmn@hethane.se>
39 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40 * @link http://status.net/
42 class GroupdirectoryAction extends ManagedAction
52 * What to filter the search results by
66 * How to order search results, ascending or descending
82 * @return string Title of the page
86 // @fixme: This looks kinda gross
88 if ($this->filter == 'all') {
89 if ($this->page != 1) {
90 // TRANS: Title for group directory page. %d is a page number.
91 return(sprintf(_m('Group Directory, page %d'), $this->page));
93 // TRANS: Title for group directory page.
94 return _m('Group directory');
95 } else if ($this->page == 1) {
97 // TRANS: Title for group directory page when it is filtered.
98 // TRANS: %s is the filter string.
99 _m('Group directory - %s'),
100 strtoupper($this->filter)
104 // TRANS: Title for group directory page when it is filtered.
105 // TRANS: %1$s is the filter string, %2$d is a page number.
106 _m('Group directory - %1$s, page %2$d'),
107 strtoupper($this->filter),
114 * Instructions for use
116 * @return instructions for use
118 function getInstructions()
120 // TRANS: Page instructions.
121 return _m("After you join a group you can send messages to all other members\n".
122 "using the syntax \"!groupname\".\n\n".
123 "Browse groups, or search for groups by their name, location or topic.\n".
124 "Separate the terms by spaces; they must be three characters or more.") . "\n";
128 * Is this page read-only?
130 * @return boolean true
132 function isReadOnly($args)
137 protected function doPreparation()
139 $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
140 $this->filter = $this->arg('filter', 'all');
141 $this->reverse = $this->boolean('reverse');
142 $this->q = $this->trimmed('q');
143 $this->sort = $this->arg('sort', 'nickname');
145 common_set_returnto($this->selfUrl());
149 * Show the page notice
151 * Shows instructions for the page
155 function showPageNotice()
157 $instr = $this->getInstructions();
158 $output = common_markup_to_html($instr);
160 $this->elementStart('div', 'instructions');
162 $this->elementEnd('div');
173 function showContent()
175 if (common_logged_in()) {
185 'href' => common_local_url('newgroup'),
187 // TRANS: Link to create a new group on the group list page.
188 _m('Create a new group')
190 $this->elementEnd('p');
195 $this->elementStart('div', array('id' => 'profile_directory'));
197 // @todo FIXME: Does "All" need i18n here?
198 $alphaNav = new AlphaNav($this, false, false, array('0-9', 'All'));
202 $group = $this->getGroups();
205 if (!empty($group)) {
206 $groupList = new SortableGroupList(
208 common_current_user(),
212 $cnt = $groupList->show();
216 $this->showEmptyListMessage();
221 if (isset($this->q)) {
222 $args['q'] = $this->q;
224 $args['filter'] = $this->filter;
229 $cnt > PROFILES_PER_PAGE,
235 $this->elementEnd('div');
238 function showForm($error=null)
244 'id' => 'form_search',
245 'class' => 'form_settings',
246 'action' => common_local_url('groupdirectory')
250 $this->elementStart('fieldset');
252 // TRANS: Fieldset legend.
253 $this->element('legend', null, _m('Search groups'));
254 $this->elementStart('ul', 'form_data');
255 $this->elementStart('li');
257 // TRANS: Field label for input of one or more keywords.
258 $this->input('q', _m('Keyword(s)'), $this->q);
260 // TRANS: Button text for searching group directory.
261 $this->submit('search', _m('BUTTON','Search'));
262 $this->elementEnd('li');
263 $this->elementEnd('ul');
264 $this->elementEnd('fieldset');
265 $this->elementEnd('form');
269 * Get groups filtered by the current filter, sort key,
270 * sort order, and page
274 $group = new User_group();
276 // Disable this to get global group searches
277 $group->joinAdd(array('id', 'local_group:group_id'));
281 if (!empty($this->q)) {
282 $wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
283 foreach ($wheres as $where) {
284 // Double % because of sprintf
285 $group->whereAdd(sprintf('LOWER(%1$s.%2$s) LIKE LOWER("%%%3$s%%")',
286 $group->escapedTableName(), $where,
287 $group->escape($this->q)),
291 $order = sprintf('%1$s.%2$s %3$s',
292 $group->escapedTableName(),
293 $this->getSortKey('created'),
294 $this->reverse ? 'DESC' : 'ASC');
296 // User is browsing via AlphaNav
298 switch($this->filter) {
303 $group->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s',
304 $group->escapedTableName(),
307 $group->_quote("9")));
310 $group->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s',
311 $group->escapedTableName(),
313 $group->_quote($this->filter)));
316 $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
317 $group->escapedTableName(),
318 $this->getSortKey('nickname'),
319 $this->reverse ? 'DESC' : 'ASC',
323 $offset = ($this->page-1) * PROFILES_PER_PAGE;
324 $limit = PROFILES_PER_PAGE + 1;
326 $group->orderBy($order);
327 $group->limit($offset, $limit);
335 * Filter the sort parameter
337 * @return string a column name for sorting
339 function getSortKey($def='created')
341 switch ($this->sort) {
351 * Show a nice message when there's no search results
353 function showEmptyListMessage()
355 if (!empty($this->filter) && ($this->filter != 'all')) {
360 // TRANS: Empty list message for searching group directory.
361 // TRANS: %s is the search string.
362 _m('No groups starting with %s.'),
367 // TRANS: Empty list message for searching group directory.
368 $this->element('p', 'error', _m('No results.'));
369 // TRANS: Help text for searching group directory.
370 $message = _m("* Make sure all words are spelled correctly.\n".
371 "* Try different keywords.\n".
372 "* Try more general keywords.\n".
373 "* Try fewer keywords.");
374 $this->elementStart('div', 'help instructions');
375 $this->raw(common_markup_to_html($message));
376 $this->elementEnd('div');
380 function showSections()
382 $gbp = new GroupsByPostsSection($this);
384 $gbm = new GroupsByMembersSection($this);