2022-01-24 00:22:14 +01:00
|
|
|
<?php
|
2022-01-25 15:04:00 +01:00
|
|
|
error_reporting(0);
|
2022-01-24 00:22:14 +01:00
|
|
|
require_once dirname(dirname(__DIR__)) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
|
|
|
|
|
2024-03-12 19:33:09 +01:00
|
|
|
$pdo = new \PDO($DB_DSN, $DB_USER, $DB_PASS);
|
2022-01-24 00:22:14 +01:00
|
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
2022-01-25 16:23:14 +01:00
|
|
|
$userManager = new \pvv\admin\UserManager($pdo);
|
|
|
|
|
|
|
|
$as = new SimpleSAML_Auth_Simple('default-sp');
|
|
|
|
$as->requireAuth();
|
|
|
|
$attrs = $as->getAttributes();
|
|
|
|
$loginname = $attrs['uid'][0];
|
|
|
|
|
|
|
|
if(!$loginname) {
|
|
|
|
header('Content-Type: text/plain', true, 403);
|
|
|
|
echo "Du må være logget inn for å se bildegalleriet.\r\n";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2024-03-12 19:31:44 +01:00
|
|
|
# Sourced from config.php through include.php
|
|
|
|
$galleryDir = $GALLERY_DIRECTORY;
|
|
|
|
$serverPath = $GALLERY_SERVER_PATH;
|
2022-01-25 16:23:14 +01:00
|
|
|
|
2022-01-24 16:12:31 +01:00
|
|
|
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp'];
|
2024-03-12 19:31:44 +01:00
|
|
|
$unamefile = $galleryDir . "/usernames.txt";
|
2022-01-24 16:12:31 +01:00
|
|
|
|
|
|
|
$unamepairs = file($unamefile);
|
2022-01-24 00:22:14 +01:00
|
|
|
|
|
|
|
function getDirContents($dir, &$results = array()) {
|
|
|
|
$files = scandir($dir);
|
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
|
|
|
if (!is_dir($path)) {
|
2024-03-12 19:31:44 +01:00
|
|
|
//Remove the full path on disk, keep username and relative path to image.
|
|
|
|
$pos = strpos($path, $GLOBALS["galleryDir"]);
|
2022-01-24 00:22:14 +01:00
|
|
|
if ($pos !== false) {
|
2024-03-12 19:31:44 +01:00
|
|
|
$cleanPath = substr_replace($path, "", $pos, strlen($GLOBALS["galleryDir"]));
|
2022-01-24 00:22:14 +01:00
|
|
|
}
|
2022-01-24 16:12:31 +01:00
|
|
|
|
|
|
|
//Check if the file is an image
|
2022-01-31 12:32:33 +01:00
|
|
|
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
2022-01-24 16:12:31 +01:00
|
|
|
if (in_array($ext, $GLOBALS["allowedExtensions"])) {
|
|
|
|
$results[] = $cleanPath;
|
|
|
|
}
|
2022-01-24 00:22:14 +01:00
|
|
|
} else if ($value != "." && $value != "..") {
|
|
|
|
//recursively scan directories
|
|
|
|
getDirContents($path, $results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
2024-03-12 19:31:44 +01:00
|
|
|
$images = getDirContents($galleryDir);
|
2022-01-24 00:22:14 +01:00
|
|
|
|
|
|
|
$imageTemplate = '
|
2022-01-25 15:04:00 +01:00
|
|
|
<div class="card">
|
|
|
|
<div class="card-image-div">
|
|
|
|
<img src="%path" alt="%name" class="card-image modal-target">
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<p class="card-title">%realname</p>
|
|
|
|
<p class="card-subtitle">%user</p>
|
2022-01-24 00:22:14 +01:00
|
|
|
</div>
|
2022-01-25 15:04:00 +01:00
|
|
|
<div class="card-footer">
|
|
|
|
<p class="card-footer-item">%name</p>
|
|
|
|
<p class="card-footer-item">%time</p>
|
2022-01-24 00:22:14 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-01-25 15:04:00 +01:00
|
|
|
'
|
2022-01-24 00:22:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="no">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
|
|
|
<link rel="shortcut icon" href="favicon.ico">
|
|
|
|
<link rel="stylesheet" href="../css/normalize.css">
|
|
|
|
<link rel="stylesheet" href="../css/style.css">
|
|
|
|
<link rel="stylesheet" href="../css/gallery.css">
|
|
|
|
<meta name="theme-color" content="#024" />
|
|
|
|
<title>Fotoverkstedet</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<nav id="navbar" class="">
|
2022-01-24 16:12:31 +01:00
|
|
|
<?php echo navbar(1, 'galleri'); ?>
|
2022-01-24 00:22:14 +01:00
|
|
|
<?php echo loginbar(null, $pdo); ?>
|
|
|
|
</nav>
|
2022-01-25 15:04:00 +01:00
|
|
|
<main class="gallery-container">
|
2022-01-24 00:22:14 +01:00
|
|
|
<?php
|
|
|
|
foreach ($images as $key => $value) {
|
2024-03-12 19:31:44 +01:00
|
|
|
$modTime = date("d.m.Y H:i", filemtime($galleryDir . $value));
|
2022-01-24 00:22:14 +01:00
|
|
|
$imguser = explode("/", $value)[0];
|
|
|
|
$displaypath = substr($value, strpos($value, "/")+1);
|
|
|
|
$realname = "Ukjent";
|
|
|
|
foreach ($unamepairs as $unamepair) {
|
|
|
|
$unamepair = explode(":", $unamepair);
|
|
|
|
if ($unamepair[0] == $imguser) {
|
|
|
|
$realname = $unamepair[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = [
|
2022-01-25 09:05:34 +01:00
|
|
|
"%user" => htmlspecialchars($imguser),
|
2022-01-24 16:12:31 +01:00
|
|
|
"%time" => $modTime,
|
2024-03-12 19:31:44 +01:00
|
|
|
"%timestamp" => filemtime($galleryDir . $value),
|
2022-01-25 09:05:34 +01:00
|
|
|
"%name" => htmlspecialchars($displaypath),
|
2024-03-12 19:31:44 +01:00
|
|
|
"%path" => $serverPath . $value,
|
2022-01-25 09:19:43 +01:00
|
|
|
"%realname" => htmlspecialchars($realname)
|
2022-01-24 00:22:14 +01:00
|
|
|
];
|
|
|
|
echo strtr($imageTemplate, $vars);
|
|
|
|
}
|
2023-01-19 13:46:39 +01:00
|
|
|
|
|
|
|
if (count($images) == 0) {
|
|
|
|
echo "<h3 class='no-images'>Det er dessverre ingen bilder å vise.</h3>";
|
|
|
|
}
|
|
|
|
|
2022-01-24 00:22:14 +01:00
|
|
|
?>
|
|
|
|
</main>
|
2022-01-24 16:12:31 +01:00
|
|
|
<div id="modal" class="modal">
|
2022-01-25 15:04:00 +01:00
|
|
|
<span id="modal-close" class="modal-close">✖</span>
|
2022-01-24 16:12:31 +01:00
|
|
|
<img id="modal-content" class="modal-content">
|
|
|
|
<div id="modal-caption" class="modal-caption"></div>
|
|
|
|
</div>
|
|
|
|
<script type="text/javascript" src="../js/galleri.js"></script>
|
2022-01-24 00:22:14 +01:00
|
|
|
</body>
|
|
|
|
</html>
|