Welcome to Geeklog, Anonymous Tuesday, November 26 2024 @ 08:24 pm EST

Geeklog Forums

Bug report about highlighting


kazuhiro

Anonymous
When I use search form of Geeklog with regular expression characters which are quoted by preg_quote function and visit hit pages from results, highlighted string is replaced with quoted one. For example, if I visit
http://www.geeklog.net/article.php?story=geeklog-1.4.0sr6&query=1.4.1
we can see that highlighted string is replaced with "1\.4\.1" from "1.4.1".
Second, when I search with Japanese characters which are URL encoded, matched strings are never highlighted in hit pages.

Changing COM_highlightQuery function as below works well for me.
Text Formatted Code

function COM_highlightQuery( $text, $query )
{
    $query = urldecode(str_replace( '+', ' ', $query ));

    // ugly workaround:
    // Using the /e modifier in preg_replace will cause all double quotes to
    // be returned as \" - so we replace all \" in the result with unescaped
    // double quotes. Any actual \" in the original text therefore have to be
    // turned into \\" first ...
    $text = str_replace( '\\"', '\\\\"', $text );

    $mywords = explode( ' ', $query );
    foreach( $mywords as $searchword )
    {
        if( !empty( $searchword ))
        {
            $reg_searchword = preg_quote( str_replace( "'", "\'", $searchword ));
            $text = preg_replace( '/(\>(((?>[^><]+)|(?R))*)\<)/ie', "preg_replace('/(?>$reg_searchword+)/i','<span class=\"highlight\">$searchword</span>','\\0')", '<!-- x -->' . $text . '<!-- x -->' );
        }
    }

    // ugly workaround, part 2
    $text = str_replace( '\\"', '"', $text );

    return $text;
}
 

 Quote

All times are EST. The time is now 08:24 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content