Make keyword search case-insensitive across index and admin pages
This commit is contained in:
parent
5aed2e1a25
commit
fb78c277cc
2 changed files with 21 additions and 6 deletions
13
index.php
13
index.php
|
|
@ -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 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 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 query_url(array $params): string {
|
||||
$params = keep_non_empty($params);
|
||||
|
|
@ -164,13 +171,13 @@ $videos = array_values(array_filter($videos, function($v) use ($videoCache, $key
|
|||
$location = (string)($m['location'] ?? '');
|
||||
|
||||
if ($keywordType === 'date') {
|
||||
return stripos($date, $keywordValue) !== false || stripos($sortDate, $keywordValue) !== false;
|
||||
return ci_contains($date, $keywordValue) || ci_contains($sortDate, $keywordValue);
|
||||
}
|
||||
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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue