Support multiline descriptions in admin
This commit is contained in:
parent
61459d35a0
commit
79c7678458
2 changed files with 23 additions and 7 deletions
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){
|
||||
$data = ['title'=>'','date'=>'','place'=>'','description'=>'','captions'=>[]]; $file = $dir . '/data.txt';
|
||||
if (!is_file($file)) return $data;
|
||||
foreach (file($file, FILE_IGNORE_NEW_LINES) as $line) {
|
||||
$line = trim($line);
|
||||
$lines = file($file, FILE_IGNORE_NEW_LINES);
|
||||
for ($i = 0; $i < count($lines); $i++) {
|
||||
$line = trim($lines[$i]);
|
||||
if ($line === '' || str_starts_with($line, '#') || !str_contains($line, ':')) continue;
|
||||
[$key, $value] = array_map('trim', explode(':', $line, 2));
|
||||
$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, ['place','location','where'], true)) $data['place'] = $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 ($place !== '') $lines[] = 'Location: ' . $place;
|
||||
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'] ?? [];
|
||||
$captions = $post['captions'] ?? [];
|
||||
if (is_array($captionFiles) && is_array($captions)) {
|
||||
|
|
@ -113,8 +129,8 @@ try {
|
|||
write_data($dir, $_POST);
|
||||
save_uploads('media', $dir, $allowedMedia);
|
||||
save_uploads('audio', $dir, $allowedAudio);
|
||||
$msg = 'Updated input directory: in-dir/' . basename($dir);
|
||||
$_GET['edit'] = basename($dir);
|
||||
header('Location: new.php?tab=edit&msg=' . rawurlencode('Updated input directory: in-dir/' . basename($dir)));
|
||||
exit;
|
||||
} elseif ($action === 'delete_file') {
|
||||
$dir = safe_input_dir($config['uploads_dir'], $_POST['dir'] ?? '');
|
||||
$file = basename((string)($_POST['file'] ?? ''));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue