content[] = ''; } /** * {@inheritdoc} */ public function beginChildren() { if ($this->getInnerIterator()->getMatches()) { $this->content[] = ''; } } public function highlight($line, array $matches) { $highlighted = ''; $offset = 0; ksort($matches); foreach ($matches as $position => $match) { $highlighted .= $this->getView()->escape(substr($line, $offset, $position - $offset)) . '' . $this->getView()->escape($match) . ''; $offset = $position + strlen($match); } $highlighted .= $this->getView()->escape(substr($line, $offset)); return $highlighted; } /** * {@inheritdoc} */ public function render() { foreach ($this as $section) { if (($matches = $this->getInnerIterator()->getMatches()) === null) { continue; } $title = $this->getView()->escape($section->getTitle()); $contentMatches = array(); foreach ($matches as $match) { if ($match->getMatchType() === DocSearchMatch::MATCH_HEADER) { $title = $this->highlight($match->getLine(), $match->getMatches()); } else { $contentMatches[] = sprintf( '

%s

', $this->highlight($match->getLine(), $match->getMatches()) ); } } $path = $this->getView()->getHelper('Url')->url( array_merge( $this->urlParams, array( 'chapter' => $this->encodeUrlParam($section->getChapter()->getId()) ) ), $this->url, false, false ); $url = $this->getView()->url( $path, array('highlight' => $this->getInnerIterator()->getSearch()->getInput()) ); /** @type \Icinga\Web\Url $url */ $url->setAnchor($this->encodeAnchor($section->getId())); $this->content[] = sprintf( '
  • %s', $section->getNoFollow() ? 'rel="nofollow" ' : '', $url->getAbsoluteUrl(), $title ); if (! empty($contentMatches)) { $this->content = array_merge($this->content, $contentMatches); } if (! $section->hasChildren()) { $this->content[] = '
  • '; } } return implode("\n", $this->content); } }