Support multiline descriptions in admin
This commit is contained in:
parent
61459d35a0
commit
79c7678458
2 changed files with 23 additions and 7 deletions
|
|
@ -90,6 +90,6 @@ $page=max(1,(int)($_GET['page']??1)); $per=$config['items_per_page']; $total=cou
|
||||||
<header class="site-header"><div class="brand-wrap"><a class="header-logo" href="index.php" aria-label="MVLog home"><img src="assets/img/moto_travel.png" alt=""></a><a class="brand" href="index.php"><h1>MVLog</h1><p>Bubulescu.Org</p></a></div><a class="rss-link" href="feed.php" aria-label="RSS feed" title="RSS feed"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6.2 17.8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM2.2 8.7v3.1a10 10 0 0 1 10 10h3.1A13.1 13.1 0 0 0 2.2 8.7Zm0-5.5v3.1a15.5 15.5 0 0 1 15.5 15.5h3.1A18.6 18.6 0 0 0 2.2 3.2Z"/></svg></a></header><main>
|
<header class="site-header"><div class="brand-wrap"><a class="header-logo" href="index.php" aria-label="MVLog home"><img src="assets/img/moto_travel.png" alt=""></a><a class="brand" href="index.php"><h1>MVLog</h1><p>Bubulescu.Org</p></a></div><a class="rss-link" href="feed.php" aria-label="RSS feed" title="RSS feed"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6.2 17.8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM2.2 8.7v3.1a10 10 0 0 1 10 10h3.1A13.1 13.1 0 0 0 2.2 8.7Zm0-5.5v3.1a15.5 15.5 0 0 1 15.5 15.5h3.1A18.6 18.6 0 0 0 2.2 3.2Z"/></svg></a></header><main>
|
||||||
<section id="videos"><?php if(!$slice): ?><p>No videos yet.</p><?php endif; ?><div class="video-list">
|
<section id="videos"><?php if(!$slice): ?><p>No videos yet.</p><?php endif; ?><div class="video-list">
|
||||||
<?php foreach($slice as $v): $name=basename($v); $url=$config['public_videos'].'/'.rawurlencode($name); $m=$videoCache[$name]['metadata'] ?? video_metadata($v); ?>
|
<?php foreach($slice as $v): $name=basename($v); $url=$config['public_videos'].'/'.rawurlencode($name); $m=$videoCache[$name]['metadata'] ?? video_metadata($v); ?>
|
||||||
<article class="video-row"><time class="created-at" datetime="<?=h(date('c', filemtime($v)))?>"><?=h(date('d.m.Y H:i', filemtime($v)))?></time><video controls controlsList="nodownload" oncontextmenu="return false" preload="metadata" src="<?=h($url)?>"></video><div class="video-info"><h2><?=h($m['title'])?></h2><p class="meta"><span><?=h($m['date'])?></span><?php if($m['location']): ?><span><?=h($m['location'])?></span><?php endif; ?></p><?php if($m['description']): ?><p class="description"><?=h($m['description'])?></p><?php endif; ?></div></article>
|
<article class="video-row"><time class="created-at" datetime="<?=h(date('c', filemtime($v)))?>"><?=h(date('d.m.Y H:i', filemtime($v)))?></time><video controls controlsList="nodownload" oncontextmenu="return false" preload="metadata" src="<?=h($url)?>"></video><div class="video-info"><h2><?=h($m['title'])?></h2><p class="meta"><span><?=h($m['date'])?></span><?php if($m['location']): ?><span><?=h($m['location'])?></span><?php endif; ?></p><?php if($m['description']): ?><p class="description"><?=nl2br(h($m['description']), false)?></p><?php endif; ?></div></article>
|
||||||
<?php endforeach; ?></div><div class="pages"><?php for($i=1;$i<=$pages;$i++): ?><a class="<?=$i===$page?'active':''?>" href="?page=<?=$i?>"><?=$i?></a><?php endfor; ?></div></section>
|
<?php endforeach; ?></div><div class="pages"><?php for($i=1;$i<=$pages;$i++): ?><a class="<?=$i===$page?'active':''?>" href="?page=<?=$i?>"><?=$i?></a><?php endfor; ?></div></section>
|
||||||
</main><footer>Bubulescu.Org</footer></body></html>
|
</main><footer>Bubulescu.Org</footer></body></html>
|
||||||
|
|
|
||||||
28
new.php
28
new.php
|
|
@ -11,12 +11,24 @@ function safe_input_dir($base, $name){ $name = basename((string)$name); $path =
|
||||||
function read_data($dir){
|
function read_data($dir){
|
||||||
$data = ['title'=>'','date'=>'','place'=>'','description'=>'','captions'=>[]]; $file = $dir . '/data.txt';
|
$data = ['title'=>'','date'=>'','place'=>'','description'=>'','captions'=>[]]; $file = $dir . '/data.txt';
|
||||||
if (!is_file($file)) return $data;
|
if (!is_file($file)) return $data;
|
||||||
foreach (file($file, FILE_IGNORE_NEW_LINES) as $line) {
|
$lines = file($file, FILE_IGNORE_NEW_LINES);
|
||||||
$line = trim($line);
|
for ($i = 0; $i < count($lines); $i++) {
|
||||||
|
$line = trim($lines[$i]);
|
||||||
if ($line === '' || str_starts_with($line, '#') || !str_contains($line, ':')) continue;
|
if ($line === '' || str_starts_with($line, '#') || !str_contains($line, ':')) continue;
|
||||||
[$key, $value] = array_map('trim', explode(':', $line, 2));
|
[$key, $value] = array_map('trim', explode(':', $line, 2));
|
||||||
$low = strtolower($key);
|
$low = strtolower($key);
|
||||||
if (in_array($low, ['title','name'], true)) $data['title'] = $value;
|
if ($value === '|' && in_array($low, ['description','desc','synopsis'], true)) {
|
||||||
|
$block = [];
|
||||||
|
while ($i + 1 < count($lines)) {
|
||||||
|
$next = $lines[$i + 1];
|
||||||
|
if (trim($next) !== '' && $next[0] !== ' ' && $next[0] !== "\t") break;
|
||||||
|
$i++;
|
||||||
|
if (str_starts_with($next, ' ')) $next = substr($next, 2);
|
||||||
|
elseif (str_starts_with($next, ' ') || str_starts_with($next, "\t")) $next = substr($next, 1);
|
||||||
|
$block[] = rtrim($next);
|
||||||
|
}
|
||||||
|
$data['description'] = trim(implode("\n", $block));
|
||||||
|
} elseif (in_array($low, ['title','name'], true)) $data['title'] = $value;
|
||||||
elseif (in_array($low, ['date','dates','when'], true)) $data['date'] = $value;
|
elseif (in_array($low, ['date','dates','when'], true)) $data['date'] = $value;
|
||||||
elseif (in_array($low, ['place','location','where'], true)) $data['place'] = $value;
|
elseif (in_array($low, ['place','location','where'], true)) $data['place'] = $value;
|
||||||
elseif (in_array($low, ['description','desc','synopsis'], true)) $data['description'] = $value;
|
elseif (in_array($low, ['description','desc','synopsis'], true)) $data['description'] = $value;
|
||||||
|
|
@ -34,7 +46,11 @@ function write_data($dir, $post){
|
||||||
if ($title !== '') $lines[] = 'Title: ' . $title;
|
if ($title !== '') $lines[] = 'Title: ' . $title;
|
||||||
if ($place !== '') $lines[] = 'Location: ' . $place;
|
if ($place !== '') $lines[] = 'Location: ' . $place;
|
||||||
if ($date !== '') $lines[] = 'Date: ' . $date;
|
if ($date !== '') $lines[] = 'Date: ' . $date;
|
||||||
if ($description !== '') $lines[] = 'Description: ' . str_replace(["\r", "\n"], ' ', $description);
|
if ($description !== '') {
|
||||||
|
$lines[] = 'Description: |';
|
||||||
|
$description = str_replace(["\r\n", "\r"], "\n", $description);
|
||||||
|
foreach (explode("\n", $description) as $descLine) $lines[] = ' ' . rtrim($descLine);
|
||||||
|
}
|
||||||
$captionFiles = $post['caption_files'] ?? [];
|
$captionFiles = $post['caption_files'] ?? [];
|
||||||
$captions = $post['captions'] ?? [];
|
$captions = $post['captions'] ?? [];
|
||||||
if (is_array($captionFiles) && is_array($captions)) {
|
if (is_array($captionFiles) && is_array($captions)) {
|
||||||
|
|
@ -113,8 +129,8 @@ try {
|
||||||
write_data($dir, $_POST);
|
write_data($dir, $_POST);
|
||||||
save_uploads('media', $dir, $allowedMedia);
|
save_uploads('media', $dir, $allowedMedia);
|
||||||
save_uploads('audio', $dir, $allowedAudio);
|
save_uploads('audio', $dir, $allowedAudio);
|
||||||
$msg = 'Updated input directory: in-dir/' . basename($dir);
|
header('Location: new.php?tab=edit&msg=' . rawurlencode('Updated input directory: in-dir/' . basename($dir)));
|
||||||
$_GET['edit'] = basename($dir);
|
exit;
|
||||||
} elseif ($action === 'delete_file') {
|
} elseif ($action === 'delete_file') {
|
||||||
$dir = safe_input_dir($config['uploads_dir'], $_POST['dir'] ?? '');
|
$dir = safe_input_dir($config['uploads_dir'], $_POST['dir'] ?? '');
|
||||||
$file = basename((string)($_POST['file'] ?? ''));
|
$file = basename((string)($_POST['file'] ?? ''));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue