site-accueil-insa/photos.php

159 lines
4.7 KiB
PHP
Raw Normal View History

2018-03-25 13:22:28 +02:00
<?php
2018-03-25 14:19:53 +02:00
ob_start(); // Start reading html
define("urlParam", "path");
// Get active path from url and prevent from seeing folders before photos/
function getActivePath()
2018-03-25 14:19:53 +02:00
{
$dir = $_GET[urlParam];
2018-04-19 08:47:19 +02:00
$folders = explode(DIRECTORY_SEPARATOR, $dir);
$currentPath = "";
foreach ($folders as $value) {
if ($value != ".." && $value != "." && $value != "") {
$currentPath .= DIRECTORY_SEPARATOR.$value;
2018-04-19 08:47:19 +02:00
}
2018-03-25 13:22:28 +02:00
}
2018-04-19 08:47:19 +02:00
return $currentPath;
2018-03-25 14:19:53 +02:00
}
2018-03-25 13:22:28 +02:00
// Get active folder from the active path
function GetActiveFolder($path) {
$dir = explode(DIRECTORY_SEPARATOR, $path);
return $dir[sizeof($dir) - 1]; // Last item after /
}
function isAlbumAvailable($path) {
$dir = "photos".$path;
$files = scandir($dir);
$valid = false;
foreach ($files as $key => $value) {
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if (!is_dir($path)) {
$valid = pathinfo($path, PATHINFO_EXTENSION) == "zip";
if ($valid)
break;
}
}
return $valid;
}
2018-04-19 08:47:19 +02:00
// Get all directories in the specified path
2018-03-25 14:19:53 +02:00
function getDirectories($dir)
{
$dir = "photos".$dir;
2018-03-25 14:19:53 +02:00
$files = scandir($dir);
$displayedItems = 0;
foreach ($files as $key => $value) {
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (is_dir($path) && $value != "." && $value != "..") {
$folderTitle = $value;
$folderLink = "?".urlParam."=".getActivePath().DIRECTORY_SEPARATOR.$value;
2018-03-25 14:19:53 +02:00
include("includes/photos/folder_template.php");
$displayedItems++;
2018-03-25 13:22:28 +02:00
}
}
2018-03-25 14:19:53 +02:00
if ($displayedItems == 0) {
$placeHolder = "Pas d'autres albums !";
include("includes/photos/place_holder.php");
}
}
2018-03-25 13:22:28 +02:00
2018-04-19 08:47:19 +02:00
// Get all photos in the specified path
2018-03-25 14:19:53 +02:00
function getPhotos($dir)
{
$dir = "photos_thumb".$dir;
2018-03-25 14:19:53 +02:00
$files = scandir($dir);
$displayedItems = 0;
foreach ($files as $key => $value) {
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
2018-03-25 14:19:53 +02:00
if (!is_dir($path)) {
$ext = pathinfo($path, PATHINFO_EXTENSION);
if ($ext == "jpg" || $ext == "jpeg" || $ext == "png") {
$imageSrc = $dir.DIRECTORY_SEPARATOR.$value;
$imageId = "photo-".$displayedItems;
2018-03-25 14:19:53 +02:00
include("includes/photos/photo_template.php");
$displayedItems++;
2018-03-25 13:22:28 +02:00
}
}
}
2018-03-25 14:19:53 +02:00
if ($displayedItems == 0) {
$placeHolder = "Pas de photos ici !";
include("includes/photos/place_holder.php");
}
}
2018-03-25 13:22:28 +02:00
2018-04-19 08:47:19 +02:00
// Creates buttons representing the actual path for easier navigation
2018-03-25 14:19:53 +02:00
function generatePath($dir)
{
$folders = explode(DIRECTORY_SEPARATOR, $dir);
$currentPath = "";
2018-04-19 08:47:19 +02:00
$pathTitle = "Menu";
$pathLink = "?".urlParam."=";
2018-04-19 08:47:19 +02:00
include("includes/photos/path_template.php");
2018-03-25 14:19:53 +02:00
foreach ($folders as $value) {
if ($value != "") {
$pathTitle = $value;
$currentPath .= DIRECTORY_SEPARATOR.$value;
$pathLink = "?".urlParam."=".$currentPath;
2018-03-25 14:19:53 +02:00
include("includes/photos/path_template.php");
2018-03-25 13:22:28 +02:00
}
}
2018-03-25 14:19:53 +02:00
}
2018-03-25 13:22:28 +02:00
?>
2018-04-21 15:20:18 +02:00
<div id="photo_overlay" style="display:none">
<img src="" id="img_big" onclick="toggleFullscreen()">
<div id="close_back" onclick="closeBig()"></div>
2018-04-23 12:04:40 +02:00
<div id="loading" onclick="closeBig()">
<i class="fas fa-spinner fa-spin"></i>
</div>
2018-04-21 15:20:18 +02:00
<div id="photo_buttons">
<i id="right" class="fas fa-arrow-right" onclick="displayNext(1)"></i>
<i id="left" class="fas fa-arrow-left" onclick="displayNext(-1)"></i>
<div id="photo_control">
<i id="close" class="fas fa-times" onclick="closeBig()"></i>
<a id="img_big_download" download="" href="">
<i id="download" class="fas fa-download"></i>
</a>
2018-04-21 15:20:18 +02:00
<a href="" id="img_big_link">
<i id="fullscreen" class="fas fa-expand-arrows-alt" ></i>
</a>
</div>
</div>
2018-03-25 13:22:28 +02:00
</div>
<h1 id="photos_title">Photos</h1>
2018-03-25 13:22:28 +02:00
<p>Cliquez sur le dossier de votre choix pour afficher les photos</p>
<ul class="photos_path">
2018-04-21 15:20:18 +02:00
<li><p>Chemin : </p></li>
2018-03-25 13:22:28 +02:00
<?php
generatePath(getActivePath());
2018-03-25 13:22:28 +02:00
?>
</ul>
<div class="photos_folder">
<?php
getDirectories(getActivePath());
2018-03-25 13:22:28 +02:00
?>
</div>
<?php if(isAlbumAvailable(getActivePath())): ?>
<a download="" href="photos<?php echo getActivePath().DIRECTORY_SEPARATOR.GetActiveFolder(getActivePath())?>.zip" id="download_album">
<i class="fas fa-download"></i>
<p>Télécharger l'album</p>
</a>
<?php endif; ?>
2018-03-25 13:22:28 +02:00
<div class="photos">
<?php
getPhotos(getActivePath());
2018-03-25 13:22:28 +02:00
?>
</div>
<script src="assets/scripts/photosScript.js"></script>
<?php
2018-03-25 14:19:53 +02:00
$pageContent = ob_get_clean(); // Store html content in variable
include("template.php"); // Display template with variable content
2018-03-25 13:22:28 +02:00
?>