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(); } # Sourced from config.php through include.php $galleryDir = $GALLERY_DIRECTORY; $serverPath = $GALLERY_SERVER_PATH; $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']; $unamefile = $galleryDir . "/usernames.txt"; $unamepairs = file($unamefile); 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. $pos = strpos($path, $GLOBALS["galleryDir"]); if ($pos !== false) { $cleanPath = substr_replace($path, "", $pos, strlen($GLOBALS["galleryDir"])); } //Check if the file is an image $ext = strtolower(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($galleryDir); $imageTemplate = '
%name

%realname

%user

' ?> Fotoverkstedet
$value) { $modTime = date("d.m.Y H:i", filemtime($galleryDir . $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($galleryDir . $value), "%name" => htmlspecialchars($displaypath), "%path" => $serverPath . $value, "%realname" => htmlspecialchars($realname) ]; echo strtr($imageTemplate, $vars); } if (count($images) == 0) { echo "

Det er dessverre ingen bilder å vise.

"; } ?>