diff --git a/index.php b/index.php index 79e48b0..86c82c3 100644 --- a/index.php +++ b/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)); diff --git a/new.php b/new.php index a23d10b..41f1f22 100644 --- a/new.php +++ b/new.php @@ -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); })); }