Show on main landing page restore, separately from permalink

This commit is contained in:
hbrain 2026-06-04 23:57:00 +02:00
parent 5505f0dee2
commit edcb6ca928
4 changed files with 119 additions and 19 deletions

View file

@ -104,6 +104,27 @@ function video_article_id($config, $videoName){
}
return '';
}
function input_dirs($base){ return glob($base.'/*', GLOB_ONLYDIR) ?: []; }
function read_article_id($dir){
$idFile = rtrim((string)$dir, '/').'/.mvlog-id';
if (!is_file($idFile)) return '';
$id = trim((string)file_get_contents($idFile));
return preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $id) ? $id : '';
}
function input_dir_permalink($dir){ return is_file($dir . '/.mvlog-permalink'); }
function article_permalink_enabled($config, $articleId){
static $cache = null;
if ($cache === null) {
$cache = [];
foreach (input_dirs($config['uploads_dir']) as $dir) {
$id = read_article_id($dir);
if ($id !== '') $cache[$id] = input_dir_permalink($dir);
}
}
$articleId = strtolower(trim((string)$articleId));
if (!preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $articleId)) return false;
return !empty($cache[$articleId]);
}
function article_og_image_url($articleId){
$articleId = strtolower(trim((string)$articleId));
if (!preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $articleId)) return '';
@ -252,14 +273,14 @@ function load_video_cache($videos){
$hiddenOutputs = hidden_video_outputs($config);
$hiddenMapOutputs = map_hidden_outputs($config);
$videos = array_values(array_filter(
$allVideos = array_values(array_filter(
glob($config['videos_dir'].'/*.{mp4,webm,mov,m4v}', GLOB_BRACE) ?: [],
fn($v)=>empty($hiddenOutputs[basename($v)]) && !preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', basename($v))
fn($v)=>!preg_match('/_preview\.(mp4|webm|mov|m4v)$/i', basename($v))
));
$videoCache = load_video_cache($videos);
$videoCache = load_video_cache($allVideos);
usort($videos, function($a, $b) use ($videoCache) {
usort($allVideos, function($a, $b) use ($videoCache) {
$am = $videoCache[basename($a)] ?? [];
$bm = $videoCache[basename($b)] ?? [];
$ad = strtotime((string)($am['metadata']['sort_date'] ?? $am['metadata']['date'] ?? '')) ?: filemtime($a);
@ -271,18 +292,18 @@ $articleId = trim((string)($_GET['id'] ?? ''));
if ($articleId !== '' && (!preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $articleId) || count(array_diff_key($_GET, ['id' => true])) > 0)) {
render_404_page();
}
if ($articleId === '') {
render_blank_page();
}
if ($articleId !== '') {
$videos = array_values(array_filter($videos, function($v) use ($articleId, $config) {
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;
}));
$rawKeyword = '';
$keywordType = 'general';
$keywordValue = '';
} else {
$videos = array_values(array_filter($allVideos, fn($v) => empty($hiddenOutputs[basename($v)])));
$rawKeyword = trim((string)($_GET['q'] ?? ''));
// Backward compatibility with older filter/query formats.
@ -341,6 +362,9 @@ $pages = max(1, (int)ceil($total / $per));
$page = min($page, $pages);
$slice = array_slice($videos, ($page - 1) * $per, $per);
if (!$slice) {
if ($articleId === '') {
render_blank_page();
}
render_404_page();
}
@ -367,7 +391,6 @@ if ($articleId !== '') {
}
$headerTitles = require __DIR__ . '/header_titles.php';
$siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
$brandUrl = '?id=' . rawurlencode($articleId);
?>
<!doctype html>
<html>
@ -409,8 +432,9 @@ $brandUrl = '?id=' . rawurlencode($articleId);
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
.filter-summary{color:#A0A4AB;font-size:.9rem;margin:0 0 .8rem}
.video-row-title{font-size:1.35rem;line-height:1.2;color:#F3F4F6}
.video-row-title a{color:inherit;text-decoration:none}
.video-row-title a:hover{text-decoration:underline}
.video-row-title a{color:inherit;text-decoration:none;cursor:pointer}
.video-row-title a:visited{color:inherit}
.video-row-title a:hover,.video-row-title a:focus,.video-row-title a:active{text-decoration:none}
.video-row-head-mobile{display:none}
.video-row-head-mobile .video-row-title{margin:0 0 .15rem}
.video-row-head-mobile .meta{margin:0 0 .25rem}
@ -469,7 +493,8 @@ $brandUrl = '?id=' . rawurlencode($articleId);
$name = basename($v);
$base = pathinfo($name, PATHINFO_FILENAME);
$articleIdForVideo = video_article_id($config, $name);
$permalinkUrl = $articleIdForVideo !== '' ? query_url(['id' => $articleIdForVideo]) : '';
$permalinkEnabled = $articleIdForVideo !== '' && article_permalink_enabled($config, $articleIdForVideo);
$permalinkUrl = $permalinkEnabled ? query_url(['id' => $articleIdForVideo]) : '';
$url = $config['public_videos'].'/'.rawurlencode($name);
$m = $videoCache[$name]['metadata'] ?? video_metadata($v);
$posterUrl = video_thumb_public_url($config, $name);