site-accueil-insa/photos.php

101 lines
2.9 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
function getActiveFolder()
{
if ($_GET['folder'] != "") {
return $_GET['folder'];
} else {
return "photos/";
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-03-25 14:19:53 +02:00
function getDirectories($dir)
{
$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 = "?folder=" . getActiveFolder() . $value . DIRECTORY_SEPARATOR;
$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-03-25 14:19:53 +02:00
function getPhotos($dir)
{
$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") {
$imageSrc = getActiveFolder() . $value;
$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-03-25 14:19:53 +02:00
function generatePath($dir)
{
$folders = explode(DIRECTORY_SEPARATOR, $dir);
$currentPath = "";
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
?>
<div id="photo_back_button" style="display:none">
<div id="close_back" onclick="closeBig()"><span class="fas fa-times" id="close"></span></div>
<span id="right" class="fas fa-arrow-right" onclick="displayNext(1)"></span>
<span id="left" class="fas fa-arrow-left" onclick="displayNext(-1)"></span>
<a href="" id="img_big_link">
<img src="" id="img_big"></img>
</a>
</div>
<h1>Photos</h1>
<p>Cliquez sur le dossier de votre choix pour afficher les photos</p>
<ul class="photos_path">
<p>Chemin : </p>
<?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
?>