From 2b260dea58483a0225105d77efd5be53c6ac41db Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 18 Mar 2016 10:42:52 -0400
Subject: [PATCH] Added more flexibility to highlight helper.

---
 .../VuFind/src/VuFind/View/Helper/Root/Highlight.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Highlight.php b/module/VuFind/src/VuFind/View/Helper/Root/Highlight.php
index 53ad255aae6..1b32105b599 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/Highlight.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/Highlight.php
@@ -59,11 +59,15 @@ class Highlight extends AbstractHelper
      *
      * @param string $haystack String to highlight
      * @param mixed  $needle   Array of words to highlight (null for none)
+     * @param bool   $clear    Should we dehighlight (true) rather than highlight
+     * (false)?
+     * @param bool   $escape   Should we HTML encode the results?
      *
      * @return string          Highlighted, HTML encoded string
      */
-    public function __invoke($haystack, $needle = null)
-    {
+    public function __invoke($haystack, $needle = null, $clear = false,
+        $escape = true
+    ) {
         // Normalize value to an array so we can loop through it; this saves us from
         // writing the highlighting code twice, once for arrays, once for non-arrays.
         // Also make sure our generated array is empty if needle itself is empty --
@@ -90,8 +94,8 @@ class Highlight extends AbstractHelper
         // URL encode the string, then put in the highlight spans:
         $haystack = str_replace(
             ['{{{{START_HILITE}}}}', '{{{{END_HILITE}}}}'],
-            [$this->startTag, $this->endTag],
-            htmlspecialchars($haystack)
+            $clear ? '' : [$this->startTag, $this->endTag],
+            $escape ? htmlspecialchars($haystack) : $haystack
         );
 
         return $haystack;
-- 
GitLab