Sort admin media by media date
This commit is contained in:
parent
f4521d4cce
commit
2e44a65287
1 changed files with 11 additions and 2 deletions
13
new.php
13
new.php
|
|
@ -63,7 +63,16 @@ function write_data($dir, $post){
|
||||||
file_put_contents($dir . '/data.txt', implode("\n", $lines) . "\n");
|
file_put_contents($dir . '/data.txt', implode("\n", $lines) . "\n");
|
||||||
}
|
}
|
||||||
function editable_file($f){ $ext = strtolower(pathinfo((string)$f, PATHINFO_EXTENSION)); return $f !== '' && $f[0] !== '.' && $f !== 'data.txt' && in_array($ext, ['jpg','jpeg','png','webp','gif','mp4','mov','m4v','avi','mkv','webm','mp3','wav','m4a','aac','ogg','flac'], true); }
|
function editable_file($f){ $ext = strtolower(pathinfo((string)$f, PATHINFO_EXTENSION)); return $f !== '' && $f[0] !== '.' && $f !== 'data.txt' && in_array($ext, ['jpg','jpeg','png','webp','gif','mp4','mov','m4v','avi','mkv','webm','mp3','wav','m4a','aac','ogg','flac'], true); }
|
||||||
function list_files($dir){ $files = array_values(array_filter(scandir($dir), fn($f)=>editable_file($f) && is_file($dir.'/'.$f))); natcasesort($files); return $files; }
|
function natural_file_compare($a, $b){ return strnatcasecmp((string)$a, (string)$b); }
|
||||||
|
function list_files($dir){ $files = array_values(array_filter(scandir($dir), fn($f)=>editable_file($f) && is_file($dir.'/'.$f))); usort($files, 'natural_file_compare'); return $files; }
|
||||||
|
function media_sort_files($dir, $files){
|
||||||
|
usort($files, function($a, $b) use ($dir) {
|
||||||
|
$da = media_file_date($dir . '/' . $a) ?? date('Ymd', filemtime($dir . '/' . $a));
|
||||||
|
$db = media_file_date($dir . '/' . $b) ?? date('Ymd', filemtime($dir . '/' . $b));
|
||||||
|
return $da === $db ? natural_file_compare($a, $b) : strcmp($da, $db);
|
||||||
|
});
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
function media_file_date($path){
|
function media_file_date($path){
|
||||||
$ext = strtolower(pathinfo((string)$path, PATHINFO_EXTENSION));
|
$ext = strtolower(pathinfo((string)$path, PATHINFO_EXTENSION));
|
||||||
if (in_array($ext, ['jpg','jpeg','tif','tiff'], true) && function_exists('exif_read_data')) {
|
if (in_array($ext, ['jpg','jpeg','tif','tiff'], true) && function_exists('exif_read_data')) {
|
||||||
|
|
@ -246,7 +255,7 @@ $page = max(1, (int)($_GET['page'] ?? 1));
|
||||||
[$videoPage, $videoPages, $orphanVideosPage, $orphanVideosTotal] = paginate($orphanVideos, $tab === 'videos' ? $page : 1);
|
[$videoPage, $videoPages, $orphanVideosPage, $orphanVideosTotal] = paginate($orphanVideos, $tab === 'videos' ? $page : 1);
|
||||||
$editName = $_GET['edit'] ?? '';
|
$editName = $_GET['edit'] ?? '';
|
||||||
$editDir = null; $editStatus = ''; $editRunning = false; $editData = ['title'=>'','date'=>'','place'=>'','description'=>'','captions'=>[]]; $editFiles = [];
|
$editDir = null; $editStatus = ''; $editRunning = false; $editData = ['title'=>'','date'=>'','place'=>'','description'=>'','captions'=>[]]; $editFiles = [];
|
||||||
if ($editName !== '') { try { $editDir = safe_input_dir($config['uploads_dir'], $editName); $editStatus = input_dir_status($editDir); $editRunning = $editStatus !== ''; if (!$editRunning) { $editData = read_data($editDir); $editFiles = list_files($editDir); } } catch (Throwable $e) { $err = $e->getMessage(); } }
|
if ($editName !== '') { try { $editDir = safe_input_dir($config['uploads_dir'], $editName); $editStatus = input_dir_status($editDir); $editRunning = $editStatus !== ''; if (!$editRunning) { $editData = read_data($editDir); $editFiles = media_sort_files($editDir, list_files($editDir)); } } catch (Throwable $e) { $err = $e->getMessage(); } }
|
||||||
?>
|
?>
|
||||||
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Admin - <?=h($config['site_name'])?></title><link rel="icon" type="image/png" href="assets/img/moto_travel.png"><link rel="stylesheet" href="style.css"></head><body>
|
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Admin - <?=h($config['site_name'])?></title><link rel="icon" type="image/png" href="assets/img/moto_travel.png"><link rel="stylesheet" href="style.css"></head><body>
|
||||||
<header class="site-header admin-header"><div class="admin-left"><nav class="tabs"><a class="<?= $tab==='new'?'active':'' ?>" href="new.php?tab=new">New</a><a class="<?= $tab==='edit'?'active':'' ?>" href="new.php?tab=edit">Edit</a><a class="<?= $tab==='videos'?'active':'' ?>" href="new.php?tab=videos">Videos</a></nav></div><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 Admin</h1><p>Bubulescu.Org</p></a></div><div class="admin-right"><div id="job-status" class="job-status" hidden></div><a class="logout-link" href="logout.php">Log off</a></div></header><main>
|
<header class="site-header admin-header"><div class="admin-left"><nav class="tabs"><a class="<?= $tab==='new'?'active':'' ?>" href="new.php?tab=new">New</a><a class="<?= $tab==='edit'?'active':'' ?>" href="new.php?tab=edit">Edit</a><a class="<?= $tab==='videos'?'active':'' ?>" href="new.php?tab=videos">Videos</a></nav></div><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 Admin</h1><p>Bubulescu.Org</p></a></div><div class="admin-right"><div id="job-status" class="job-status" hidden></div><a class="logout-link" href="logout.php">Log off</a></div></header><main>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue