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

View file

@ -7,6 +7,13 @@ if (!is_dir(__DIR__ . "/cache")) mkdir(__DIR__ . "/cache", 0775, true);
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, "UTF-8"); } function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, "UTF-8"); }
function nice_title($s){ return trim(ucwords(str_replace(['_','-'], ' ', (string)$s))); } function nice_title($s){ return trim(ucwords(str_replace(['_','-'], ' ', (string)$s))); }
function lower_text($s){ return function_exists('mb_strtolower') ? mb_strtolower((string)$s, 'UTF-8') : strtolower((string)$s); } 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 keep_non_empty(array $params): array { return array_filter($params, fn($v)=>$v !== '' && $v !== null); } function keep_non_empty(array $params): array { return array_filter($params, fn($v)=>$v !== '' && $v !== null); }
function query_url(array $params): string { function query_url(array $params): string {
$params = keep_non_empty($params); $params = keep_non_empty($params);
@ -164,13 +171,13 @@ $videos = array_values(array_filter($videos, function($v) use ($videoCache, $key
$location = (string)($m['location'] ?? ''); $location = (string)($m['location'] ?? '');
if ($keywordType === 'date') { if ($keywordType === 'date') {
return stripos($date, $keywordValue) !== false || stripos($sortDate, $keywordValue) !== false; return ci_contains($date, $keywordValue) || ci_contains($sortDate, $keywordValue);
} }
if ($keywordType === 'location') { if ($keywordType === 'location') {
return stripos($location, $keywordValue) !== false; return ci_contains($location, $keywordValue);
} }
return stripos($title, $keywordValue) !== false || stripos($description, $keywordValue) !== false; return ci_contains($title, $keywordValue) || ci_contains($description, $keywordValue);
})); }));
$page = max(1, (int)($_GET['page'] ?? 1)); $page = max(1, (int)($_GET['page'] ?? 1));

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'; const ARTICLE_ID_FILE = '.mvlog-id';
function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, "UTF-8"); } 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 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){ function ascii_safe($s){
$s = strtr((string)$s, [ $s = strtr((string)$s, [
'æ'=>'ae','Æ'=>'Ae','ø'=>'o','Ø'=>'O','å'=>'aa','Å'=>'Aa', 'æ'=>'ae','Æ'=>'Ae','ø'=>'o','Ø'=>'O','å'=>'aa','Å'=>'Aa',
@ -845,9 +853,9 @@ if ($keywordValue !== '' || $statusFilterActive) {
$date = (string)($meta['date'] ?? ($data['date'] ?? '')); $date = (string)($meta['date'] ?? ($data['date'] ?? ''));
$location = (string)($meta['location'] ?? ($data['place'] ?? '')); $location = (string)($meta['location'] ?? ($data['place'] ?? ''));
if ($keywordType === 'date') return stripos($date, $keywordValue) !== false; if ($keywordType === 'date') return ci_contains($date, $keywordValue);
if ($keywordType === 'location') return stripos($location, $keywordValue) !== false; if ($keywordType === 'location') return ci_contains($location, $keywordValue);
return stripos($title, $keywordValue) !== false || stripos($description, $keywordValue) !== false; return ci_contains($title, $keywordValue) || ci_contains($description, $keywordValue);
})); }));
} }