Photo test v10.3

This commit is contained in:
Arthur 2019-08-28 19:20:41 +02:00
parent 2485b3dc4b
commit ef4b948d27

View file

@ -17,8 +17,8 @@ function getActivePath()
$currentPath = ""; $currentPath = "";
foreach ($folders as $value) { foreach ($folders as $value) {
if ($value != ".." && $value != "." && $value != "") { if ($value != ".." && $value != "." && $value != "") {
$currentPath .= DIRECTORY_SEPARATOR . $value; $currentPath .= DIRECTORY_SEPARATOR . $value;
} }
} }
return $currentPath; return $currentPath;
} }
@ -30,8 +30,8 @@ function getActivePath()
*/ */
function GetActiveFolder($path) function GetActiveFolder($path)
{ {
$dir = explode(DIRECTORY_SEPARATOR, $path); $dir = explode(DIRECTORY_SEPARATOR, $path);
return $dir[sizeof($dir) - 1]; // Last item after / return $dir[sizeof($dir) - 1]; // Last item after /
} }
/** /**
@ -41,15 +41,15 @@ function GetActiveFolder($path)
*/ */
function isAlbumAvailable($path) function isAlbumAvailable($path)
{ {
$dir = photoRoot . $path; $dir = photoRoot . $path;
$files = scandir($dir); $files = scandir($dir);
$valid = false; $valid = false;
foreach ($files as $key => $value) { foreach ($files as $key => $value) {
$path = realpath($dir . DIRECTORY_SEPARATOR . $value); $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
if (!is_dir($path)) { if (!is_dir($path)) {
$valid = pathinfo($path, PATHINFO_EXTENSION) == "zip"; $valid = pathinfo($path, PATHINFO_EXTENSION) == "zip";
if ($valid) if ($valid)
break; break;
} }
} }
return $valid; return $valid;
@ -61,18 +61,18 @@ function isAlbumAvailable($path)
*/ */
function createDirectories($path) function createDirectories($path)
{ {
$path = photoRoot . $path; $path = photoRoot . $path;
$displayedItems = 0; $displayedItems = 0;
$folders = getDirectories($path); $folders = getDirectories($path);
foreach ($folders as $key => $value) { foreach ($folders as $key => $value) {
$folderTitle = $value; $folderTitle = $value;
$photos = getTotalPhotoCount($path . DIRECTORY_SEPARATOR . $value); $photos = getTotalPhotoCount($path . DIRECTORY_SEPARATOR . $value);
$albums = getTotalAlbumCount($path . DIRECTORY_SEPARATOR . $value); $albums = getTotalAlbumCount($path . DIRECTORY_SEPARATOR . $value);
$folderLink = "?" . urlParam . "=" . getActivePath() . DIRECTORY_SEPARATOR . $value; $folderLink = "?" . urlParam . "=" . getActivePath() . DIRECTORY_SEPARATOR . $value;
include("includes/photos/folder_template.php"); include("includes/photos/folder_template.php");
$displayedItems++; $displayedItems++;
} }
} }
@ -83,16 +83,16 @@ function createDirectories($path)
function createPhotos($path) function createPhotos($path)
{ {
$path = photoRoot . "_thumb" . $path; $path = photoRoot . "_thumb" . $path;
$files = scandir($path); $files = scandir($path);
$displayedItems = 0; $displayedItems = 0;
foreach ($files as $key => $value) { foreach ($files as $key => $value) {
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value); $realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
if (isValidImage($realPath)) { if (isValidImage($realPath)) {
$imageSrc = $path . DIRECTORY_SEPARATOR . $value; $imageSrc = $path . DIRECTORY_SEPARATOR . $value;
$imageId = "photo-" . $displayedItems; $imageId = "photo-" . $displayedItems;
include("includes/photos/photo_template.php"); include("includes/photos/photo_template.php");
$displayedItems++; $displayedItems++;
} }
} }
} }
@ -103,13 +103,13 @@ function createPhotos($path)
*/ */
function getDirectories($path) function getDirectories($path)
{ {
$files = scandir($path); $files = scandir($path);
$folders = []; $folders = [];
foreach ($files as $key => $value) { foreach ($files as $key => $value) {
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value); $realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
if (isValidDirectory($realPath, $value)) { if (isValidDirectory($realPath, $value)) {
array_push($folders, $value); array_push($folders, $value);
} }
} }
return $folders; return $folders;
} }
@ -121,13 +121,13 @@ function getDirectories($path)
*/ */
function getDirectoriesCount($path) function getDirectoriesCount($path)
{ {
$files = scandir($path); $files = scandir($path);
$dirCount = 0; $dirCount = 0;
foreach ($files as $key => $value) { foreach ($files as $key => $value) {
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value); $realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
if (isValidDirectory($realPath, $value)) { if (isValidDirectory($realPath, $value)) {
$dirCount++; $dirCount++;
} }
} }
return $dirCount; return $dirCount;
} }
@ -140,12 +140,12 @@ function getDirectoriesCount($path)
function getPhotoCount($path) function getPhotoCount($path)
{ {
$files = scandir($path); $files = scandir($path);
$fileCount = 0; $fileCount = 0;
foreach ($files as $key => $value) { foreach ($files as $key => $value) {
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value); $realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
if (isValidImage($realPath)) { if (isValidImage($realPath)) {
$fileCount++; $fileCount++;
} }
} }
return $fileCount; return $fileCount;
} }
@ -157,21 +157,21 @@ function getPhotoCount($path)
*/ */
function getTotalAlbumCount($path) function getTotalAlbumCount($path)
{ {
$folders = getDirectories($path); $folders = getDirectories($path);
$total = sizeof($folders); $total = sizeof($folders);
foreach ($folders as $key => $value) { foreach ($folders as $key => $value) {
$total += getTotalAlbumCount($path . DIRECTORY_SEPARATOR . $value); $total += getTotalAlbumCount($path . DIRECTORY_SEPARATOR . $value);
} }
return $total; return $total;
} }
function getTotalPhotoCount($path) function getTotalPhotoCount($path)
{ {
$folders = getDirectories($path); $folders = getDirectories($path);
$total = getPhotoCount($path); $total = getPhotoCount($path);
foreach ($folders as $key => $value) { foreach ($folders as $key => $value) {
$total += getTotalPhotoCount($path . DIRECTORY_SEPARATOR . $value); $total += getTotalPhotoCount($path . DIRECTORY_SEPARATOR . $value);
} }
return $total; return $total;
} }
@ -182,8 +182,8 @@ function getTotalPhotoCount($path)
*/ */
function isValidImage($imagePath) function isValidImage($imagePath)
{ {
$ext = pathinfo($imagePath, PATHINFO_EXTENSION); $ext = pathinfo($imagePath, PATHINFO_EXTENSION);
return !is_dir($imagePath) && ($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG" || $ext == "png" || $ext == "PNG"); return !is_dir($imagePath) && ($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG" || $ext == "png" || $ext == "PNG");
} }
/** /**
@ -194,7 +194,7 @@ function isValidImage($imagePath)
*/ */
function isValidDirectory($directoryPath, $directory) function isValidDirectory($directoryPath, $directory)
{ {
return is_dir($directoryPath) && $directory != "." && $directory != ".." && substr($directory, 0, 1) !== "."; return is_dir($directoryPath) && $directory != "." && $directory != ".." && substr($directory, 0, 1) !== ".";
} }
@ -204,89 +204,91 @@ function isValidDirectory($directoryPath, $directory)
*/ */
function generatePath($path) function generatePath($path)
{ {
$folders = explode(DIRECTORY_SEPARATOR, $path); $folders = explode(DIRECTORY_SEPARATOR, $path);
$currentPath = ""; $currentPath = "";
$pathTitle = "Menu"; $pathTitle = "Menu";
$pathLink = "?" . urlParam . "="; $pathLink = "?" . urlParam . "=";
include("includes/photos/path_template.php"); include("includes/photos/path_template.php");
foreach ($folders as $value) { foreach ($folders as $value) {
if ($value != "") { if ($value != "") {
$pathTitle = $value; $pathTitle = $value;
$currentPath .= DIRECTORY_SEPARATOR . $value; $currentPath .= DIRECTORY_SEPARATOR . $value;
$pathLink = "?" . urlParam . "=" . $currentPath; $pathLink = "?" . urlParam . "=" . $currentPath;
include("includes/photos/path_template.php"); include("includes/photos/path_template.php");
} }
} }
} }
?> ?>
<div class="inner"> <div class="inner">
<div id="photoOverlay" style="display:none"> <div id="photoOverlay" style="display:none">
<img src="" id="imgBig"> <img src="" id="imgBig">
<div id="closeBack" onclick="closeBig()"></div> <div id="closeBack" onclick="closeBig()"></div>
<div id="loadingIconContainer" onclick="closeBig()"> <div id="loadingIconContainer" onclick="closeBig()">
<i class="fas fa-spinner fa-spin"></i> <i class="fas fa-spinner fa-spin"></i>
</div> </div>
<div id="photoButtonsContainer"> <div id="photoButtonsContainer">
<div id="rightButton" onclick="displayNext(1)"> <div id="rightButton" onclick="displayNext(1)">
<i class="fas fa-arrow-right"></i> <i class="fas fa-arrow-right"></i>
</div> </div>
<div id="leftButton" onclick="displayNext(-1)"> <div id="leftButton" onclick="displayNext(-1)">
<i class="fas fa-arrow-left"></i> <i class="fas fa-arrow-left"></i>
</div>
<a id="downloadButton" download="" href="">
<i class="fas fa-download"></i>
</a>
<div id="closeButton">
<i class="fas fa-times" onclick="closeBig()"></i>
</div>
</div>
</div> </div>
<div id="closeButton"> <h1 id="photosTitle">Photos</h1>
<i class="fas fa-times" onclick="closeBig()"></i> <p>Clique sur le dossier de ton choix pour afficher les photos. Il faut que tu sois inscrit à l'INSA pour pouvoir
</div> les regarder (et oui, pas de spoiler).
</div> </p>
<p>
Si tu ne peux pas voir les photos (la fenêtre pour entrer le mot de passe ne s'affiche pas), ouvre cette page
avec
un autre navigateur.
</p>
<ul class="photos-path">
<li><p>Chemin : </p></li>
<?php
generatePath(getActivePath());
?>
</ul>
</div>
<div id="photoContainer">
<?php if (getDirectoriesCount(photoRoot . getActivePath()) > 0): ?>
<div class="photos-folder-container">
<?php
createDirectories(getActivePath());
?>
</div>
<?php endif; ?>
<?php if (isAlbumAvailable(getActivePath())): ?>
<a download=""
href="photos_folders/photos<?php echo getActivePath() . DIRECTORY_SEPARATOR . GetActiveFolder(getActivePath()) ?>.zip"
id="downloadAlbum">
<span id="downloadText"><i class="fas fa-download"></i>Télécharger</span>
<span id="albumPhotoCount"><?php echo getPhotoCount(photoRoot . getActivePath()) ?> photos</span>
</a>
<?php endif; ?>
<?php if (getPhotoCount(photoRoot . getActivePath()) > 0): ?>
<div class="photos">
<?php
createPhotos(getActivePath());
?>
</div>
<?php endif; ?>
</div> </div>
<h1 id="photosTitle">Photos</h1>
<p>Clique sur le dossier de ton choix pour afficher les photos. Il faut que tu sois inscrit à l'INSA pour pouvoir
les regarder (et oui, pas de spoiler).
</p>
<p>
Si tu ne peux pas voir les photos (la fenêtre pour entrer le mot de passe ne s'affiche pas), ouvre cette page
avec
un autre navigateur.
</p>
<ul class="photos-path">
<li><p>Chemin : </p></li>
<?php
generatePath(getActivePath());
?>
</ul>
</div>
<div id="photoContainer">
<?php if (getDirectoriesCount(photoRoot . getActivePath()) > 0): ?>
<div class="photos-folder-container">
<?php
createDirectories(getActivePath());
?>
</div>
<?php endif; ?>
<?php if (isAlbumAvailable(getActivePath())): ?>
<a download=""
href="photos_folders/photos<?php echo getActivePath() . DIRECTORY_SEPARATOR . GetActiveFolder(getActivePath()) ?>.zip"
id="downloadAlbum">
<span id="downloadText"><i class="fas fa-download"></i>Télécharger</span>
<span id="albumPhotoCount"><?php echo getPhotoCount(photoRoot . getActivePath()) ?> photos</span>
</a>
<?php endif; ?>
<?php if (getPhotoCount(photoRoot . getActivePath()) > 0): ?>
<div class="photos">
<?php
createPhotos(getActivePath());
?>
</div>
<?php endif; ?>
</div>
<link rel="stylesheet" type="text/css" media="screen" href="assets/css/photos.css">
<?php <?php
$pageContent = ob_get_clean(); // Store html content in variable $pageContent = ob_get_clean(); // Store html content in variable
@ -295,4 +297,3 @@ $pageScripts = "<script src=\"assets/js/photos.js\"></script><script type=\"text
include("includes/template.php"); // Display template with variable content include("includes/template.php"); // Display template with variable content
?> ?>