implement article permalinks and hide search bar conditionally on index.php
This commit is contained in:
parent
3abecc729e
commit
9217f874b4
1 changed files with 65 additions and 48 deletions
113
index.php
113
index.php
|
|
@ -178,56 +178,67 @@ usort($videos, function($a, $b) use ($videoCache) {
|
||||||
return $bd <=> $ad;
|
return $bd <=> $ad;
|
||||||
});
|
});
|
||||||
|
|
||||||
$rawKeyword = trim((string)($_GET['q'] ?? ''));
|
$articleId = trim((string)($_GET['id'] ?? ''));
|
||||||
|
|
||||||
// Backward compatibility with older filter/query formats.
|
if ($articleId !== '') {
|
||||||
if ($rawKeyword === '') {
|
$videos = array_values(array_filter($videos, function($v) use ($articleId) {
|
||||||
$legacyTitle = trim((string)($_GET['f_title'] ?? ''));
|
return pathinfo($v, PATHINFO_FILENAME) === $articleId;
|
||||||
$legacyDate = trim((string)($_GET['f_date'] ?? ''));
|
}));
|
||||||
$legacyLocation = trim((string)($_GET['f_location'] ?? ''));
|
$rawKeyword = '';
|
||||||
$legacyJob = trim((string)($_GET['job'] ?? ''));
|
$keywordType = 'general';
|
||||||
|
$keywordValue = '';
|
||||||
|
} else {
|
||||||
|
$rawKeyword = trim((string)($_GET['q'] ?? ''));
|
||||||
|
|
||||||
if ($legacyTitle !== '') $rawKeyword = $legacyTitle;
|
// Backward compatibility with older filter/query formats.
|
||||||
elseif ($legacyDate !== '') $rawKeyword = 'date=' . $legacyDate;
|
if ($rawKeyword === '') {
|
||||||
elseif ($legacyLocation !== '') $rawKeyword = 'location=' . $legacyLocation;
|
$legacyTitle = trim((string)($_GET['f_title'] ?? ''));
|
||||||
elseif ($legacyJob !== '') {
|
$legacyDate = trim((string)($_GET['f_date'] ?? ''));
|
||||||
$legacy = preg_replace('/^\d{8}[_-]/', '', $legacyJob);
|
$legacyLocation = trim((string)($_GET['f_location'] ?? ''));
|
||||||
$rawKeyword = nice_title($legacy ?: $legacyJob);
|
$legacyJob = trim((string)($_GET['job'] ?? ''));
|
||||||
|
|
||||||
|
if ($legacyTitle !== '') $rawKeyword = $legacyTitle;
|
||||||
|
elseif ($legacyDate !== '') $rawKeyword = 'date=' . $legacyDate;
|
||||||
|
elseif ($legacyLocation !== '') $rawKeyword = 'location=' . $legacyLocation;
|
||||||
|
elseif ($legacyJob !== '') {
|
||||||
|
$legacy = preg_replace('/^\d{8}[_-]/', '', $legacyJob);
|
||||||
|
$rawKeyword = nice_title($legacy ?: $legacyJob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$keywordType = 'general';
|
||||||
|
$keywordValue = $rawKeyword;
|
||||||
|
if ($rawKeyword !== '' && preg_match('/^\s*(date|location|place)\s*=\s*(.+)\s*$/i', $rawKeyword, $m)) {
|
||||||
|
$keywordType = lower_text((string)$m[1]);
|
||||||
|
if ($keywordType === 'place') $keywordType = 'location';
|
||||||
|
$keywordValue = trim((string)$m[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$videos = array_values(array_filter($videos, function($v) use ($videoCache, $keywordType, $keywordValue) {
|
||||||
|
if ($keywordValue === '') return true;
|
||||||
|
|
||||||
|
$name = basename($v);
|
||||||
|
$m = $videoCache[$name]['metadata'] ?? video_metadata($v);
|
||||||
|
|
||||||
|
$title = (string)($m['title'] ?? '');
|
||||||
|
$teaser = (string)($m['teaser'] ?? '');
|
||||||
|
$description = (string)($m['description'] ?? '');
|
||||||
|
$quoteDa = (string)($m['quote_da'] ?? '');
|
||||||
|
$date = (string)($m['date'] ?? '');
|
||||||
|
$sortDate = (string)($m['sort_date'] ?? '');
|
||||||
|
$location = (string)($m['location'] ?? '');
|
||||||
|
|
||||||
|
if ($keywordType === 'date') {
|
||||||
|
return ci_contains($date, $keywordValue) || ci_contains($sortDate, $keywordValue);
|
||||||
|
}
|
||||||
|
if ($keywordType === 'location') {
|
||||||
|
return ci_contains($location, $keywordValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ci_contains($title, $keywordValue) || ci_contains($teaser, $keywordValue) || ci_contains($quoteDa, $keywordValue) || ci_contains($description, $keywordValue);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
$keywordType = 'general';
|
|
||||||
$keywordValue = $rawKeyword;
|
|
||||||
if ($rawKeyword !== '' && preg_match('/^\s*(date|location|place)\s*=\s*(.+)\s*$/i', $rawKeyword, $m)) {
|
|
||||||
$keywordType = lower_text((string)$m[1]);
|
|
||||||
if ($keywordType === 'place') $keywordType = 'location';
|
|
||||||
$keywordValue = trim((string)$m[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$videos = array_values(array_filter($videos, function($v) use ($videoCache, $keywordType, $keywordValue) {
|
|
||||||
if ($keywordValue === '') return true;
|
|
||||||
|
|
||||||
$name = basename($v);
|
|
||||||
$m = $videoCache[$name]['metadata'] ?? video_metadata($v);
|
|
||||||
|
|
||||||
$title = (string)($m['title'] ?? '');
|
|
||||||
$teaser = (string)($m['teaser'] ?? '');
|
|
||||||
$description = (string)($m['description'] ?? '');
|
|
||||||
$quoteDa = (string)($m['quote_da'] ?? '');
|
|
||||||
$date = (string)($m['date'] ?? '');
|
|
||||||
$sortDate = (string)($m['sort_date'] ?? '');
|
|
||||||
$location = (string)($m['location'] ?? '');
|
|
||||||
|
|
||||||
if ($keywordType === 'date') {
|
|
||||||
return ci_contains($date, $keywordValue) || ci_contains($sortDate, $keywordValue);
|
|
||||||
}
|
|
||||||
if ($keywordType === 'location') {
|
|
||||||
return ci_contains($location, $keywordValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ci_contains($title, $keywordValue) || ci_contains($teaser, $keywordValue) || ci_contains($quoteDa, $keywordValue) || ci_contains($description, $keywordValue);
|
|
||||||
}));
|
|
||||||
|
|
||||||
$page = max(1, (int)($_GET['page'] ?? 1));
|
$page = max(1, (int)($_GET['page'] ?? 1));
|
||||||
$per = $config['items_per_page'];
|
$per = $config['items_per_page'];
|
||||||
$total = count($videos);
|
$total = count($videos);
|
||||||
|
|
@ -321,6 +332,8 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
.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}
|
.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}
|
.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{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-head-mobile{display:none}
|
.video-row-head-mobile{display:none}
|
||||||
.video-info .video-row-title{margin:0 0 .35rem}
|
.video-info .video-row-title{margin:0 0 .35rem}
|
||||||
.video-info .meta{margin:0 0 .45rem}
|
.video-info .meta{margin:0 0 .45rem}
|
||||||
|
|
@ -348,6 +361,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
<?php include __DIR__ . '/_header.php'; ?>
|
<?php include __DIR__ . '/_header.php'; ?>
|
||||||
<main>
|
<main>
|
||||||
<section id="videos">
|
<section id="videos">
|
||||||
|
<?php if ($articleId === ''): ?>
|
||||||
<form method="get" class="filter-form">
|
<form method="get" class="filter-form">
|
||||||
<div class="filter-input-wrap">
|
<div class="filter-input-wrap">
|
||||||
<input name="q" value="<?=h($rawKeyword)?>" placeholder="Search title/teaser/quote_da/description or use date=... / location=..." aria-label="Search articles">
|
<input name="q" value="<?=h($rawKeyword)?>" placeholder="Search title/teaser/quote_da/description or use date=... / location=..." aria-label="Search articles">
|
||||||
|
|
@ -358,6 +372,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
<span class="sr-only">Filter</span>
|
<span class="sr-only">Filter</span>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<p class="filter-summary">
|
<p class="filter-summary">
|
||||||
Showing <?=h((string)$total)?> article(s)
|
Showing <?=h((string)$total)?> article(s)
|
||||||
|
|
@ -369,6 +384,8 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
<div class="video-list">
|
<div class="video-list">
|
||||||
<?php foreach($slice as $v):
|
<?php foreach($slice as $v):
|
||||||
$name = basename($v);
|
$name = basename($v);
|
||||||
|
$base = pathinfo($name, PATHINFO_FILENAME);
|
||||||
|
$permalinkUrl = query_url(['id' => $base]);
|
||||||
$url = $config['public_videos'].'/'.rawurlencode($name);
|
$url = $config['public_videos'].'/'.rawurlencode($name);
|
||||||
$m = $videoCache[$name]['metadata'] ?? video_metadata($v);
|
$m = $videoCache[$name]['metadata'] ?? video_metadata($v);
|
||||||
$posterUrl = video_thumb_public_url($config, $name);
|
$posterUrl = video_thumb_public_url($config, $name);
|
||||||
|
|
@ -377,7 +394,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
?>
|
?>
|
||||||
<article class="video-row">
|
<article class="video-row">
|
||||||
<div class="video-row-head video-row-head-mobile">
|
<div class="video-row-head video-row-head-mobile">
|
||||||
<h2 class="video-row-title"><?=h($m['title'])?></h2>
|
<h2 class="video-row-title"><a href="<?=h($permalinkUrl)?>"><?=h($m['title'])?></a></h2>
|
||||||
<p class="meta">
|
<p class="meta">
|
||||||
<span><a href="<?=h($dateFilterUrl)?>"><?=h($m['date'])?></a></span>
|
<span><a href="<?=h($dateFilterUrl)?>"><?=h($m['date'])?></a></span>
|
||||||
<?php if(!empty($m['location'])): ?><span><a href="<?=h($locFilterUrl)?>"><?=h($m['location'])?></a></span><?php endif; ?>
|
<?php if(!empty($m['location'])): ?><span><a href="<?=h($locFilterUrl)?>"><?=h($m['location'])?></a></span><?php endif; ?>
|
||||||
|
|
@ -395,7 +412,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="video-info">
|
<div class="video-info">
|
||||||
<h2 class="video-row-title video-row-title-desktop"><?=h($m['title'])?></h2>
|
<h2 class="video-row-title video-row-title-desktop"><a href="<?=h($permalinkUrl)?>"><?=h($m['title'])?></a></h2>
|
||||||
<p class="meta meta-desktop">
|
<p class="meta meta-desktop">
|
||||||
<span><a href="<?=h($dateFilterUrl)?>"><?=h($m['date'])?></a></span>
|
<span><a href="<?=h($dateFilterUrl)?>"><?=h($m['date'])?></a></span>
|
||||||
<?php if(!empty($m['location'])): ?><span><a href="<?=h($locFilterUrl)?>"><?=h($m['location'])?></a></span><?php endif; ?>
|
<?php if(!empty($m['location'])): ?><span><a href="<?=h($locFilterUrl)?>"><?=h($m['location'])?></a></span><?php endif; ?>
|
||||||
|
|
@ -420,4 +437,4 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
|
||||||
</main>
|
</main>
|
||||||
<?php include __DIR__ . '/_footer.php'; ?>
|
<?php include __DIR__ . '/_footer.php'; ?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue