From 19143de4d7e0bf6e286d5b07cdc8224d3fabe217 Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Wed, 23 Dec 2020 04:11:26 -0700 Subject: [PATCH] Fix search.php to more properly handle multibyte strings --- Rocksolid_Light/rocksolid/search.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Rocksolid_Light/rocksolid/search.php b/Rocksolid_Light/rocksolid/search.php index 5108a04..50591fd 100644 --- a/Rocksolid_Light/rocksolid/search.php +++ b/Rocksolid_Light/rocksolid/search.php @@ -126,12 +126,25 @@ $results=0; $database = $spooldir.'/'.$config_name.'-overview.db3'; $table = 'overview'; $dbh = rslight_db_open($database, $table); + $overview = array(); if($dbh) { -// $stmt = $dbh->prepare("SELECT * FROM $table WHERE ".$_POST['searchpoint']." like '%".$_POST['terms']."%' ORDER BY date DESC"); - $stmt = $dbh->prepare("SELECT * FROM $table WHERE ".$_POST['searchpoint']." like :terms ORDER BY date DESC"); - $stmt->bindParam(':terms', $searchterms); - $stmt->execute(); - while($overviewline = $stmt->fetch()) { + if(is_multibyte($_POST['terms'])) { + $stmt = $dbh->query("SELECT * FROM $table"); + while($row = $stmt->fetch()) { + if(stripos(quoted_printable_decode(mb_decode_mimeheader($row[$_POST['searchpoint']])), $_POST['terms']) !== false) { + $overview[] = $row; + } + } + } else { + $stmt = $dbh->prepare("SELECT * FROM $table WHERE ".$_POST['searchpoint']." like :terms ORDER BY date DESC"); + $stmt->bindParam(':terms', $searchterms); + $stmt->execute(); + while($found = $stmt->fetch()) { + $overview[] = $found; + } + } + $dbh = null; + foreach($overview as $overviewline) { # Generate link $url = $thissite."/article-flat.php?id=".$overviewline['number']."&group="._rawurlencode($overviewline['newsgroup'])."#".$overviewline['number']; $groupurl = $thissite."/thread.php?group="._rawurlencode($overviewline['newsgroup']); @@ -164,12 +177,11 @@ $results=0; echo ''.$overviewline['newsgroup'].''; echo '

'; - echo '

Posted: '.$newdate.' by: '.mb_decode_mimeheader($lastname).'

'; + echo '

Posted: '.$newdate.' by: '.mb_decode_mimeheader($overviewline['name']).'

'; echo ''; if($results++ > ($maxdisplay - 2)) break; } - $dbh = null; } echo '';