Merge pull request #16 from Programvareverkstedet/gallery
Gallery of user images on the home page
This commit is contained in:
commit
31e104a150
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,5 +5,3 @@
|
||||
/vendor/
|
||||
/www/simplesaml
|
||||
composer.phar
|
||||
/www/galleri/bilder/slideshow/*.*
|
||||
!/www/galleri/bilder/slideshow/.gitkeep
|
@ -10,6 +10,7 @@ function navbar($depth, $active = NULL) {
|
||||
'Kontakt' => 'kontakt',
|
||||
'Webmail' => 'mail',
|
||||
//'Webmail' => 'https://webmail.pvv.ntnu.no/',
|
||||
'Galleri' => 'galleri',
|
||||
'Wiki' => 'pvv',
|
||||
'Git' => 'https://git.pvv.ntnu.no/',
|
||||
];
|
||||
|
1
www/css/bulma.min.css
vendored
Normal file
1
www/css/bulma.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
124
www/css/gallery.css
Normal file
124
www/css/gallery.css
Normal file
@ -0,0 +1,124 @@
|
||||
body, main {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
main {
|
||||
background-color: #ddd;
|
||||
}
|
||||
.gallery-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-gap: 10px;
|
||||
width: 95%;
|
||||
margin: 15px auto;
|
||||
}
|
||||
figure {
|
||||
overflow: hidden;
|
||||
}
|
||||
.card-image {
|
||||
margin: auto 0;
|
||||
object-fit: scale-down;
|
||||
object-position: 0 50%;
|
||||
object-position: center;
|
||||
object-fit: cover;
|
||||
max-height: 45vh;
|
||||
}
|
||||
|
||||
/* #region modal */
|
||||
|
||||
.modal-target:hover {opacity: 0.7;}
|
||||
|
||||
/* The Modal (background) */
|
||||
.modal {
|
||||
display: none; /* Hidden by default */
|
||||
position: fixed; /* Stay in place */
|
||||
z-index: 1; /* Sit on top */
|
||||
padding-top: 5vh;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto; /* Enable scroll if needed */
|
||||
background-color: rgb(0,0,0); /* Fallback color */
|
||||
background-color: rgba(0,0,0,0.8); /* Black w/ opacity */
|
||||
}
|
||||
|
||||
/* Modal Content (image) */
|
||||
.modal-content {
|
||||
margin: auto;
|
||||
display: block;
|
||||
object-fit: scale-down;
|
||||
overflow: visible;
|
||||
|
||||
/* yolo, it all goes down from here */
|
||||
min-width: 60vw;
|
||||
max-width: 90vw !important;
|
||||
min-height: 60vh;
|
||||
max-height: 80vh !important;
|
||||
|
||||
width: auto;
|
||||
height: auto;
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
/* Caption of Modal Image */
|
||||
.modal-caption {
|
||||
margin: auto;
|
||||
display: block;
|
||||
width: 80%;
|
||||
max-width: 90vw;
|
||||
text-align: center;
|
||||
color: white;
|
||||
font-weight: 700;
|
||||
font-size: 1em;
|
||||
margin-top: 32px;
|
||||
}
|
||||
|
||||
.modal-content, .modal-caption {
|
||||
-webkit-animation-name: zoom;
|
||||
-webkit-animation-duration: 0.6s;
|
||||
animation-name: zoom;
|
||||
animation-duration: 0.6s;
|
||||
}
|
||||
|
||||
@-webkit-keyframes zoom {
|
||||
from {-webkit-atransform:scale(0)}
|
||||
to {-webkit-transform:scale(1)}
|
||||
}
|
||||
|
||||
@keyframes zoom {
|
||||
from {transform:scale(0)}
|
||||
to {transform:scale(1)}
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
right: 35px;
|
||||
color: #f1f1f1;
|
||||
font-size: 72px;
|
||||
font-weight: bold;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.modal-close:hover, .modal-close:focus {
|
||||
color: #bbb;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
/* #endregion modal */
|
||||
|
||||
/* #region screen-size media-rules */
|
||||
@media only screen and (min-width:320px) {
|
||||
.gallery-container {grid-template-columns: 1fr !important; }
|
||||
}
|
||||
@media only screen and (min-width: 641px) {
|
||||
.gallery-container { grid-template-columns: repeat(2, 1fr) !important;}
|
||||
}
|
||||
@media only screen and (min-width: 961px) {
|
||||
.gallery-container { grid-template-columns: repeat(3, 1fr) !important;}
|
||||
}
|
||||
@media only screen and (min-width: 1281px) {
|
||||
.gallery-container { grid-template-columns: repeat(4, 1fr) !important;}
|
||||
}
|
||||
/* #endregion */
|
3
www/galleri/.gitignore
vendored
Normal file
3
www/galleri/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
bilder/slideshow/*
|
||||
bilder/pvv-photos/
|
||||
usernames.txt
|
14
www/galleri/fetchPics.sh
Executable file
14
www/galleri/fetchPics.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
outfolder="bilder/pvv-photos"
|
||||
folders=$(ssh pvv@microbel.pvv.ntnu.no -i /home/pvv/c/pvv/.ssh/photofetcher 'find /home/pvv -maxdepth 3 -name "pvv-photos" 2>/dev/null')
|
||||
unamefile="usernames.txt"
|
||||
> $unamefile # Empty the file
|
||||
|
||||
for imgfolder in $folders; do
|
||||
user=$(echo $imgfolder | cut -d "/" -f5)
|
||||
realname="$(getent passwd $user | cut -d ':' -f 5)"
|
||||
echo "$user:$realname" >> $unamefile
|
||||
destination="$outfolder/$user"
|
||||
mkdir -p $destination
|
||||
rsync -rtvz --delete "$imgfolder/" "$destination" # Copy and keep timestamps
|
||||
done
|
131
www/galleri/index.php
Normal file
131
www/galleri/index.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
require_once dirname(dirname(__DIR__)) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
|
||||
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
$unamefile = __DIR__ . '/usernames.txt';
|
||||
$relativePath = "/bilder/pvv-photos/";
|
||||
$allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp'];
|
||||
|
||||
$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"]);
|
||||
if ($pos !== false) {
|
||||
$cleanPath = substr_replace($path, "", $pos, strlen($GLOBALS["fullPath"]));
|
||||
}
|
||||
|
||||
//Check if the file is an image
|
||||
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
||||
if (in_array($ext, $GLOBALS["allowedExtensions"])) {
|
||||
$results[] = $cleanPath;
|
||||
}
|
||||
} else if ($value != "." && $value != "..") {
|
||||
//recursively scan directories
|
||||
getDirContents($path, $results);
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
$images = getDirContents($fullPath);
|
||||
|
||||
$imageTemplate = '
|
||||
<div class="card is-flex is-flex-direction-column is-justify-content-space-between gallery-img-card" data-user="%user" data-date="%timestamp" data-fname="%name">
|
||||
<div class="card-image">
|
||||
<figure class="image">
|
||||
<img src="%path" alt="%name" class="card-image modal-target">
|
||||
</figure>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<div class="media">
|
||||
<div class="media-content">
|
||||
<p class="title is-4">%realname</p>
|
||||
<p class="subtitle is-6">%user</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
%name
|
||||
<br>
|
||||
<time datetime="%time">%time</time>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
?>
|
||||
<!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">
|
||||
<link rel="stylesheet" href="../css/bulma.min.css">
|
||||
<meta name="theme-color" content="#024" />
|
||||
<title>Fotoverkstedet</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav id="navbar" class="">
|
||||
<?php echo navbar(1, 'galleri'); ?>
|
||||
<?php echo loginbar(null, $pdo); ?>
|
||||
</nav>
|
||||
<main class="card gallery-container">
|
||||
<?php
|
||||
foreach ($images as $key => $value) {
|
||||
$modTime = date("d.m.Y H:i", filemtime($fullPath . $value));
|
||||
$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 = [
|
||||
"%user" => htmlspecialchars($imguser),
|
||||
"%time" => $modTime,
|
||||
"%timestamp" => filemtime($fullPath . $value),
|
||||
"%name" => htmlspecialchars($displaypath),
|
||||
"%path" => "/galleri/" . $relativePath .$value,
|
||||
"%realname" => $htmlspecialchars(realname)
|
||||
];
|
||||
echo strtr($imageTemplate, $vars);
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
<div id="modal" class="modal">
|
||||
<span id="modal-close" class="modal-close">×</span>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
@ -42,7 +42,7 @@ $doorTime = date("H:i", $doorEntry->time);
|
||||
<header class="landing">
|
||||
<div id="imageSlideshow">
|
||||
<?php include("galleri/slideshow.php"); ?>
|
||||
<script src="galleri/slideshow.js"></script>
|
||||
<script src="js/slideshow.js"></script>
|
||||
</div>
|
||||
|
||||
<div class="info">
|
||||
|
25
www/js/galleri.js
Normal file
25
www/js/galleri.js
Normal file
@ -0,0 +1,25 @@
|
||||
// #region Modal
|
||||
var modal = document.getElementById('modal');
|
||||
|
||||
var modalClose = document.getElementById('modal-close');
|
||||
modalClose.addEventListener('click', function() {
|
||||
modal.style.display = "none";
|
||||
});
|
||||
|
||||
// global handler
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.className.indexOf('modal-target') !== -1) {
|
||||
var img = e.target;
|
||||
var modalImg = document.getElementById("modal-content");
|
||||
var captionText = document.getElementById("modal-caption");
|
||||
modal.style.display = "block";
|
||||
modalImg.src = img.src;
|
||||
captionText.innerHTML = img.alt;
|
||||
}
|
||||
});
|
||||
// #endregion
|
||||
|
||||
// #region sorting
|
||||
|
||||
|
||||
// #endregion
|
Loading…
Reference in New Issue
Block a user