3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/searchaction.php');
23 require_once(INSTALLDIR.'/lib/profilelist.php');
25 class PeoplesearchAction extends SearchAction
28 function get_instructions()
30 return _('Search for people on %%site.name%% by their name, location, or interests. ' .
31 'Separate the terms by spaces; they must be 3 characters or more.');
36 return _('People search');
39 function show_results($q, $page)
42 $profile = new Profile();
44 # lcase it for comparison
47 $search_engine = $profile->getSearchEngine('identica_people');
49 $search_engine->set_sort_mode('chron');
50 # Ask for an extra to see if there's more.
51 $search_engine->limit((($page-1)*PROFILES_PER_PAGE), PROFILES_PER_PAGE + 1);
52 if (false === $search_engine->query($q)) {
56 $cnt = $profile->find();
59 $terms = preg_split('/[\s,]+/', $q);
60 $results = new PeopleSearchResults($profile, $terms);
61 $results->show_list();
63 $this->element('p', 'error', _('No results'));
68 common_pagination($page > 1, $cnt > PROFILES_PER_PAGE,
69 $page, 'peoplesearch', array('q' => $q));
73 class PeopleSearchResults extends ProfileList
79 function __construct($profile, $terms)
81 parent::__construct($profile);
82 $this->terms = array_map('preg_quote',
83 array_map('htmlspecialchars', $terms));
84 $this->pattern = '/('.implode('|',$terms).')/i';
87 function highlight($text)
89 return preg_replace($this->pattern, '<strong>\\1</strong>', htmlspecialchars($text));