From 72d0ee4e2546a789728ee6d2750a2eed560d265f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 3 Jul 2009 10:10:12 -0400 Subject: move peoplesearchresults class to action/peoplesearch --- actions/peoplesearch.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'actions/peoplesearch.php') diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php index c61e0e273..60ddb6a82 100644 --- a/actions/peoplesearch.php +++ b/actions/peoplesearch.php @@ -87,3 +87,47 @@ class PeoplesearchAction extends SearchAction } } +/** + * People search results class + * + * Derivative of ProfileList with specialization for highlighting search terms. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou + * @author Robin Millette + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + * @see PeoplesearchAction + */ + +class PeopleSearchResults extends ProfileList +{ + var $terms = null; + var $pattern = null; + + function __construct($profile, $terms, $action) + { + parent::__construct($profile, $action); + + $this->terms = array_map('preg_quote', + array_map('htmlspecialchars', $terms)); + + $this->pattern = '/('.implode('|',$terms).')/i'; + } + + function newProfileItem($profile) + { + return new PeopleSearchResultItem($profile, $this->action); + } +} + +class PeopleSearchResultItem extends ProfileListItem +{ + function highlight($text) + { + return preg_replace($this->pattern, '\\1', htmlspecialchars($text)); + } +} + -- cgit v1.2.3-54-g00ecf