mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
parent
1053e62e20
commit
ab78757483
@ -4,12 +4,21 @@
|
|||||||
namespace Icinga\Module\Doc\Search;
|
namespace Icinga\Module\Doc\Search;
|
||||||
|
|
||||||
use UnexpectedValueException;
|
use UnexpectedValueException;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Web\View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A doc search match
|
* A doc search match
|
||||||
*/
|
*/
|
||||||
class DocSearchMatch
|
class DocSearchMatch
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* CSS class for highlighting matches
|
||||||
|
*
|
||||||
|
* @type string
|
||||||
|
*/
|
||||||
|
const HIGHLIGHT_CSS_CLASS = 'search-highlight';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Header match
|
* Header match
|
||||||
*
|
*
|
||||||
@ -52,6 +61,13 @@ class DocSearchMatch
|
|||||||
*/
|
*/
|
||||||
protected $matches = array();
|
protected $matches = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View
|
||||||
|
*
|
||||||
|
* @type View|null
|
||||||
|
*/
|
||||||
|
protected $view;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the line
|
* Set the line
|
||||||
*
|
*
|
||||||
@ -139,6 +155,54 @@ class DocSearchMatch
|
|||||||
return $this->matches;
|
return $this->matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the view
|
||||||
|
*
|
||||||
|
* @param View $view
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setView(View $view)
|
||||||
|
{
|
||||||
|
$this->view = $view;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the view
|
||||||
|
*
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
|
public function getView()
|
||||||
|
{
|
||||||
|
if ($this->view === null) {
|
||||||
|
$this->view = Icinga::app()->getViewRenderer()->view;
|
||||||
|
}
|
||||||
|
return $this->view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the line having matches highlighted
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function highlight()
|
||||||
|
{
|
||||||
|
$highlighted = '';
|
||||||
|
$offset = 0;
|
||||||
|
$matches = $this->getMatches();
|
||||||
|
ksort($matches);
|
||||||
|
foreach ($matches as $position => $match) {
|
||||||
|
$highlighted .= $this->getView()->escape(substr($this->line, $offset, $position - $offset))
|
||||||
|
. '<span class="' . static::HIGHLIGHT_CSS_CLASS .'">'
|
||||||
|
. $this->getView()->escape($match)
|
||||||
|
. '</span>';
|
||||||
|
$offset = $position + strlen($match);
|
||||||
|
}
|
||||||
|
$highlighted .= $this->getView()->escape(substr($this->line, $offset));
|
||||||
|
return $highlighted;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the match is empty
|
* Whether the match is empty
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user