Make keyword search case-insensitive across index and admin pages

This commit is contained in:
hbrain 2026-05-31 17:01:35 +02:00
parent 5aed2e1a25
commit fb78c277cc
2 changed files with 21 additions and 6 deletions

14
new.php
View file

@ -7,6 +7,14 @@ if (!is_dir(__DIR__ . "/cache")) mkdir(__DIR__ . "/cache", 0775, true);
const ARTICLE_ID_FILE = '.mvlog-id';
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, "UTF-8"); }
function ajax_json($data){ header('Content-Type: application/json; charset=UTF-8'); echo json_encode($data, JSON_UNESCAPED_UNICODE); exit; }
function lower_text($s){ return function_exists('mb_strtolower') ? mb_strtolower((string)$s, 'UTF-8') : strtolower((string)$s); }
function ci_contains($haystack, $needle){
$haystack = (string)$haystack;
$needle = (string)$needle;
if ($needle === '') return true;
if (function_exists('mb_stripos')) return mb_stripos($haystack, $needle, 0, 'UTF-8') !== false;
return strpos(lower_text($haystack), lower_text($needle)) !== false;
}
function ascii_safe($s){
$s = strtr((string)$s, [
'æ'=>'ae','Æ'=>'Ae','ø'=>'o','Ø'=>'O','å'=>'aa','Å'=>'Aa',
@ -845,9 +853,9 @@ if ($keywordValue !== '' || $statusFilterActive) {
$date = (string)($meta['date'] ?? ($data['date'] ?? ''));
$location = (string)($meta['location'] ?? ($data['place'] ?? ''));
if ($keywordType === 'date') return stripos($date, $keywordValue) !== false;
if ($keywordType === 'location') return stripos($location, $keywordValue) !== false;
return stripos($title, $keywordValue) !== false || stripos($description, $keywordValue) !== false;
if ($keywordType === 'date') return ci_contains($date, $keywordValue);
if ($keywordType === 'location') return ci_contains($location, $keywordValue);
return ci_contains($title, $keywordValue) || ci_contains($description, $keywordValue);
}));
}