]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/peoplesearchresults.php
f8ab7cf3b65d2109d17b8adae2d017fc6a09f002
[quix0rs-gnu-social.git] / lib / peoplesearchresults.php
1 <?php
2 /**
3  * People search results class
4  *
5  * PHP version 5
6  *
7  * @category Widget
8  * @package  Laconica
9  * @author   Evan Prodromou <evan@controlyourself.ca>
10  * @author   Robin Millette <millette@controlyourself.ca>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://laconi.ca/
13  *
14  * Laconica - a distributed open-source microblogging tool
15  * Copyright (C) 2008, Controlez-Vous, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/profilelist.php';
36
37 /**
38  * People search results class
39  *
40  * Derivative of ProfileList with specialization for highlighting search terms.
41  *
42  * @category Widget
43  * @package  Laconica
44  * @author   Evan Prodromou <evan@controlyourself.ca>
45  * @author   Robin Millette <millette@controlyourself.ca>
46  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47  * @link     http://laconi.ca/
48  *
49  * @see PeoplesearchAction
50  */
51
52 class PeopleSearchResults extends ProfileList
53 {
54     var $terms = null;
55     var $pattern = null;
56
57     function __construct($profile, $terms, $action)
58     {
59         parent::__construct($profile, $terms, $action);
60         $this->terms = array_map('preg_quote',
61                                  array_map('htmlspecialchars', $terms));
62         $this->pattern = '/('.implode('|',$terms).')/i';
63     }
64
65     function highlight($text)
66     {
67         return preg_replace($this->pattern, '<strong>\\1</strong>', htmlspecialchars($text));
68     }
69
70     function isReadOnly()
71     {
72         return true;
73     }
74 }
75