From a00876a2f1180b531d6fade6aa1c85f4500b5f12 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 26 May 2014 13:30:35 -0500
Subject: [PATCH] thread: Add searchable view to ThreadBody

This will be useful for plugins which might need to scan the message body
regardless of its encoding. This will also be required for full-text indexes
which will not need to index HTML tags, for instance.
---
 include/class.thread.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/class.thread.php b/include/class.thread.php
index c69eb2854..741fb449a 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1352,6 +1352,11 @@ class ThreadBody /* extends SplString */ {
         throw new Exception('display: Abstract dispplay() method not implemented');
     }
 
+    function getSearchable() {
+        return $this->body;
+        // TODO: Normalize Unicode string
+    }
+
     static function fromFormattedText($text, $format=false) {
         switch ($format) {
         case 'text':
@@ -1419,6 +1424,13 @@ class HtmlThreadBody extends ThreadBody {
         return trim($this->body, " <>br/\t\n\r") ? Format::sanitize($this->body) : '';
     }
 
+    function getSearchable() {
+        // <br> -> \n
+        $body = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $this->body);
+        return Format::striptags($body);
+        // TODO: Normalize Unicode string
+    }
+
     function display($output=false) {
         if ($this->isEmpty())
             return '(empty)';
-- 
GitLab