From 573d19681b43dbcba42fc43610faa70094732851 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Tue, 12 Mar 2024 19:31:44 +0100 Subject: [PATCH] WIP: move gallery/slideshow directories --- flake.nix | 1 - www/galleri/bilder/slideshow/.gitkeep | 0 www/galleri/index.php | 21 ++++++++++--------- www/galleri/slideshow.php | 30 +++++++++++++++------------ 4 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 www/galleri/bilder/slideshow/.gitkeep diff --git a/flake.nix b/flake.nix index d1a3f4f..82afb98 100644 --- a/flake.nix +++ b/flake.nix @@ -65,7 +65,6 @@ # - Make "trusted.url.domains" dynamic based on the current host:port # - Do not download composer.phar with curl(!) # - Relicense the project to GPL or something - # - Move gallery/slideshow images to an external directory (configurable) # - Write a module for the project }; diff --git a/www/galleri/bilder/slideshow/.gitkeep b/www/galleri/bilder/slideshow/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/www/galleri/index.php b/www/galleri/index.php index cba76e1..35d25f4 100644 --- a/www/galleri/index.php +++ b/www/galleri/index.php @@ -18,23 +18,24 @@ if(!$loginname) { exit(); } +# Sourced from config.php through include.php +$galleryDir = $GALLERY_DIRECTORY; +$serverPath = $GALLERY_SERVER_PATH; -$unamefile = __DIR__ . '/usernames.txt'; -$relativePath = "/bilder/pvv-photos/"; $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']; +$unamefile = $galleryDir . "/usernames.txt"; $unamepairs = file($unamefile); -$fullPath = getcwd() . $relativePath; function getDirContents($dir, &$results = array()) { $files = scandir($dir); foreach ($files as $key => $value) { $path = realpath($dir . DIRECTORY_SEPARATOR . $value); if (!is_dir($path)) { - //Remove the full path on disk, keep username and relative path to image. ( $results[] = str_replace($GLOBALS["fullPath"], "", $path); is insecure.) - $pos = strpos($path, $GLOBALS["fullPath"]); + //Remove the full path on disk, keep username and relative path to image. + $pos = strpos($path, $GLOBALS["galleryDir"]); if ($pos !== false) { - $cleanPath = substr_replace($path, "", $pos, strlen($GLOBALS["fullPath"])); + $cleanPath = substr_replace($path, "", $pos, strlen($GLOBALS["galleryDir"])); } //Check if the file is an image @@ -49,7 +50,7 @@ function getDirContents($dir, &$results = array()) { } return $results; } -$images = getDirContents($fullPath); +$images = getDirContents($galleryDir); $imageTemplate = '
@@ -89,7 +90,7 @@ $imageTemplate = '
$value) { - $modTime = date("d.m.Y H:i", filemtime($fullPath . $value)); + $modTime = date("d.m.Y H:i", filemtime($galleryDir . $value)); $imguser = explode("/", $value)[0]; $displaypath = substr($value, strpos($value, "/")+1); $realname = "Ukjent"; @@ -104,9 +105,9 @@ $imageTemplate = ' $vars = [ "%user" => htmlspecialchars($imguser), "%time" => $modTime, - "%timestamp" => filemtime($fullPath . $value), + "%timestamp" => filemtime($galleryDir . $value), "%name" => htmlspecialchars($displaypath), - "%path" => "/galleri/" . $relativePath .$value, + "%path" => $serverPath . $value, "%realname" => htmlspecialchars($realname) ]; echo strtr($imageTemplate, $vars); diff --git a/www/galleri/slideshow.php b/www/galleri/slideshow.php index f0b959a..4d73ef5 100644 --- a/www/galleri/slideshow.php +++ b/www/galleri/slideshow.php @@ -1,30 +1,34 @@ - -$relativePath = "/bilder/slideshow/"; -$absolutePath = "/galleri" . $relativePath; -//Path to first image in slideshow and fallback image if no others are present + $value) { - if(in_array($value, [".gitkeep", ".", ".."])) { + if(in_array($value, [".", ".."])) { unset($filenames[$k]); } } -function getFullPath($fname) { return ($GLOBALS["absolutePath"] . $fname ); } +function getFullPath($fname) { return ($GLOBALS["serverPath"] . $fname ); } -//Sort filenames alphabetically and prepend the path prefix to each item. +// Sort filenames alphabetically and prepend the path prefix to each item. asort($filenames); $slideshowimagefilenames = aRrAy_MaP("getFullPath", $filenames); -//Prepend the cover photo +// Prepend the cover photo ArRaY_uNsHiFt($slideshowimagefilenames, $splashImg); eChO(''); ecHo(''); -//Store list of file names in a globel JS variable -EchO(""); -?> \ No newline at end of file +// Store list of file names in a globel JS variable +EchO(""); + +?>