Esempio n. 1
0
    /**
     * Highlight specified words
     *
     * @param string|array $words  Words to highlight. They could be organized using the array or string.
     */
    public function highlight($words)
    {
        $color = $this->_highlightColors[$this->_currentColorIndex];
        $this->_currentColorIndex = ($this->_currentColorIndex + 1) % count($this->_highlightColors);

        $this->_doc->highlight($words, $color);
    }
Esempio n. 2
0
 public function testHtmlNoFollowLinks()
 {
     $html = '<HTML>' . '<HEAD><TITLE>Page title</TITLE></HEAD>' . '<BODY>' . 'Document body.' . '<a href="link1.html">Link 1</a>.' . '<a href="link2.html" rel="nofollow">Link 1</a>.' . '</BODY>' . '</HTML>';
     $oldNoFollowValue = Document\HTML::getExcludeNoFollowLinks();
     Document\HTML::setExcludeNoFollowLinks(false);
     $doc1 = Document\HTML::loadHTML($html);
     $this->assertTrue($doc1 instanceof Document\HTML);
     $this->assertTrue(array_values($doc1->getLinks()) == array('link1.html', 'link2.html'));
     Document\HTML::setExcludeNoFollowLinks(true);
     $doc2 = Document\HTML::loadHTML($html);
     $this->assertTrue($doc2 instanceof Document\HTML);
     $this->assertTrue(array_values($doc2->getLinks()) == array('link1.html'));
 }
Esempio n. 3
0
 /**
  * Highlight matches in $inputHTMLFragment and return it (without HTML header and body tag)
  *
  * @param string $inputHTMLFragment
  * @param string  $encoding   Input HTML string encoding
  * @param \Zend\Search\Lucene\Search\Highlighter|null $highlighter
  * @return string
  */
 public function htmlFragmentHighlightMatches($inputHTMLFragment, $encoding = 'UTF-8', $highlighter = null)
 {
     if ($highlighter === null) {
         $highlighter = new Highlighter\DefaultHighlighter();
     }
     $inputHTML = '<html><head><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"/></head><body>' . iconv($encoding, 'UTF-8//IGNORE', $inputHTMLFragment) . '</body></html>';
     $doc = Document\HTML::loadHTML($inputHTML);
     $highlighter->setDocument($doc);
     $this->_highlightMatches($highlighter);
     return $doc->getHTMLBody();
 }