site-accueil-insa/photos.php

125 lines
3.6 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
2018-04-19 08:47:19 +02:00
// Get active folder from url and prevent from seeing folders before photos/
2018-03-25 14:19:53 +02:00
function getActiveFolder()
{
2018-04-19 08:47:19 +02:00
$dir = $_GET['folder'];
$folders = explode(DIRECTORY_SEPARATOR, $dir);
$currentPath = "";
foreach ($folders as $value) {
if ($value != "..") {
$currentPath .= $value . DIRECTORY_SEPARATOR;
}
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
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)
{
2018-04-19 08:47:19 +02:00
$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;
2018-04-21 15:20:18 +02:00
$folderLink = "?folder=" . getActiveFolder() . $value;
2018-03-25 14:19:53 +02:00
$folderClass = "";
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)
{
2018-04-19 08:47:19 +02:00
$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)) {
$ext = pathinfo($path, PATHINFO_EXTENSION);
if ($ext == "bmp" || $ext == "jpg" || $ext == "jpeg" || $ext == "png") {
2018-04-21 15:20:18 +02:00
$imageSrc = $dir . $value;
2018-03-25 14:19:53 +02:00
$imageId = "photo-" . $displayedItems;
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 = "?folder=";
include("includes/photos/path_template.php");
2018-03-25 14:19:53 +02:00
foreach ($folders as $value) {
if ($value != "") {
$pathTitle = $value;
$currentPath .= $value . DIRECTORY_SEPARATOR;
$pathLink = "?folder=" . $currentPath;
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>
<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 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>Photos</h1>
<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
2018-03-25 14:19:53 +02:00
generatePath(getActiveFolder());
2018-03-25 13:22:28 +02:00
?>
</ul>
<div class="photos_folder">
<?php
2018-03-25 14:19:53 +02:00
getDirectories(getActiveFolder());
2018-03-25 13:22:28 +02:00
?>
</div>
<div class="photos">
<?php
2018-03-25 14:19:53 +02:00
getPhotos(getActiveFolder());
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
?>