X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fpeoplesearch.php;h=60ddb6a82863d80b0b78005c6dc2d5a9474f28df;hb=84fb84693994ba05a642d105a57227df7b412466;hp=65d970dd159a7fea183763d9fd8488fdde4cb2ab;hpb=85873b1f2b5b6a3e065cf5d227df31380b6f239e;p=quix0rs-gnu-social.git diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php index 65d970dd15..60ddb6a828 100644 --- a/actions/peoplesearch.php +++ b/actions/peoplesearch.php @@ -12,7 +12,7 @@ * @link http://laconi.ca/ * * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. + * Copyright (C) 2008, 2009, Control Yourself, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -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)); + } +} +