4 // define('GROUPS_PER_PAGE', 20);
8 * Group search action class.
14 * @author Evan Prodromou <evan@controlyourself.ca>
15 * @author Robin Millette <millette@controlyourself.ca>
16 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
17 * @link http://laconi.ca/
19 * Laconica - a distributed open-source microblogging tool
20 * Copyright (C) 2008, Controlez-Vous, Inc.
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU Affero General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Affero General Public License for more details.
32 * You should have received a copy of the GNU Affero General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 if (!defined('LACONICA')) {
40 //require_once INSTALLDIR.'/lib/searchaction.php';
41 //require_once INSTALLDIR.'/lib/profilelist.php';
44 * Group search action class.
48 * @author Evan Prodromou <evan@controlyourself.ca>
49 * @author Robin Millette <millette@controlyourself.ca>
50 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
51 * @link http://laconi.ca/
53 class GroupsearchAction extends SearchAction
55 function getInstructions()
57 return _('Search for groups on %%site.name%% by their name, location, or description. ' .
58 'Separate the terms by spaces; they must be 3 characters or more.');
63 return _('Group search');
66 function showResults($q, $page)
68 $user_group = new User_group;
69 $user_group->limit((($page-1)*GROUPS_PER_PAGE), GROUPS_PER_PAGE + 1);
70 $wheres = array('nickname', 'fullname', 'homepage', 'description', 'location');
71 foreach ($wheres as $where) {
72 $where_q = "$where like '%" . trim($user_group->escape($q), '\'') . '%\'';
73 $user_group->whereAdd($where_q, 'OR');
75 $cnt = $user_group->find();
77 $terms = preg_split('/[\s,]+/', $q);
78 $results = new GroupSearchResults($user_group, $terms, $this);
81 $this->element('p', 'error', _('No results'));
84 $this->pagination($page > 1, $cnt > GROUPS_PER_PAGE,
85 $page, 'groupsearch', array('q' => $q));
89 class GroupSearchResults extends GroupList
94 function __construct($user_group, $terms, $action)
96 parent::__construct($user_group, $terms, $action);
97 $this->terms = array_map('preg_quote',
98 array_map('htmlspecialchars', $terms));
99 $this->pattern = '/('.implode('|',$terms).')/i';
102 function highlight($text)
104 return preg_replace($this->pattern, '<strong>\\1</strong>', htmlspecialchars($text));
107 function isReadOnly()