1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8namespace Search\ResultSet;
9
10class UrlHighlightTermsTransform
11{
12	private $termsParameter;
13
14	function __construct($terms)
15	{
16		if ($terms) {
17			$this->termsParameter = 'highlight=' . urlencode(implode(' ', $terms));
18		} else {
19			$this->termsParameter = '';
20		}
21	}
22
23	function __invoke($entry)
24	{
25		if (isset($entry['url']) && $this->termsParameter) {
26			$entry['url'] = $entry['url'] . (strpos($entry['url'], '?') === false ? '?' : '&') . $this->termsParameter;
27		}
28
29		return $entry;
30	}
31}
32