]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/peoplesearch.php
Notice class has methods to check content length
[quix0rs-gnu-social.git] / actions / peoplesearch.php
index c61e0e273957f5779a9730650bc7fec073d78c1b..60ddb6a82863d80b0b78005c6dc2d5a9474f28df 100644 (file)
@@ -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 <evan@controlyourself.ca>
+ * @author   Robin Millette <millette@controlyourself.ca>
+ * @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, '<strong>\\1</strong>', htmlspecialchars($text));
+    }
+}
+