diff --git a/index.php b/index.php index a234328..1ebebe9 100644 --- a/index.php +++ b/index.php @@ -84,6 +84,24 @@ function shown_video_paths($config){ return $videos; } +function permalink_video_paths($config, $articleId){ + $articleId = strtolower(trim((string)$articleId)); + if (!preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $articleId)) return []; + foreach (glob($config['uploads_dir'].'/*', GLOB_ONLYDIR) ?: [] as $dir) { + if (!is_file($dir . '/.mvlog-permalink')) continue; + if (read_article_id($dir) !== $articleId) continue; + $stateFile = $dir . '/.movmaker-state.json'; + if (!is_file($stateFile)) return []; + $state = json_decode((string)file_get_contents($stateFile), true); + if (!is_array($state)) return []; + $name = basename((string)($state['output'] ?? '')); + if ($name === '' || preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', $name)) return []; + $path = $config['videos_dir'] . '/' . $name; + return is_file($path) ? [$path] : []; + } + return []; +} + function public_url_path($path){ $path = str_replace('\\', '/', trim((string)$path)); if ($path === '') return ''; @@ -309,9 +327,8 @@ if ($articleId !== '') { if (!article_permalink_enabled($config, $articleId)) { render_404_page(); } - $videos = array_values(array_filter($allVideos, function($v) use ($articleId, $config) { - return video_article_id($config, basename($v)) === $articleId; - })); + // Permalink pages are allowed when Permalink is ON, even if Show is OFF. + $videos = permalink_video_paths($config, $articleId); $rawKeyword = ''; $keywordType = 'general'; $keywordValue = '';