From 76ffd9260c35e79498b365f5b5b8f545292f772f Mon Sep 17 00:00:00 2001 From: hbrain Date: Sun, 31 May 2026 16:12:39 +0200 Subject: [PATCH] Transliterate non-ASCII title chars when slugging input dirs --- new.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/new.php b/new.php index 04a75d0..5d9c1dc 100644 --- a/new.php +++ b/new.php @@ -6,7 +6,19 @@ foreach (["videos_dir", "thumbs_dir", "uploads_dir"] as $d) if (!is_dir($config[ if (!is_dir(__DIR__ . "/cache")) mkdir(__DIR__ . "/cache", 0775, true); 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 slugify($s){ $s = strtolower(trim($s)); $s = preg_replace('/[^a-z0-9]+/', '-', $s); return trim($s, '-') ?: 'movie'; } +function ascii_safe($s){ + $s = strtr((string)$s, [ + 'æ'=>'ae','Æ'=>'Ae','ø'=>'o','Ø'=>'O','å'=>'aa','Å'=>'Aa', + 'ä'=>'ae','Ä'=>'Ae','ö'=>'oe','Ö'=>'Oe','ü'=>'ue','Ü'=>'Ue','ß'=>'ss','ẞ'=>'SS', + 'č'=>'c','Č'=>'C','ć'=>'c','Ć'=>'C','ž'=>'z','Ž'=>'Z','š'=>'s','Š'=>'S','đ'=>'d','Đ'=>'D', + ]); + if (function_exists('iconv')) { + $x = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s); + if ($x !== false) $s = $x; + } + return preg_replace('/[^\x20-\x7E]/', '', $s) ?? ''; +} +function slugify($s){ $s = ascii_safe($s); $s = strtolower(trim($s)); $s = preg_replace('/[^a-z0-9]+/', '-', $s); return trim($s, '-') ?: 'movie'; } function rrmdir($dir){ if(!is_dir($dir)) return; foreach(scandir($dir) as $f){ if($f==='.'||$f==='..') continue; $p="$dir/$f"; is_dir($p)?rrmdir($p):unlink($p);} rmdir($dir); } function input_dirs($base){ return glob($base.'/*', GLOB_ONLYDIR) ?: []; } function safe_input_dir($base, $name){ $name = basename((string)$name); $path = realpath($base . '/' . $name); $root = realpath($base); if (!$path || !$root || !str_starts_with($path, $root . DIRECTORY_SEPARATOR) || !is_dir($path)) throw new RuntimeException('Invalid input directory.'); return $path; }