2020-09-19 16:08:07 +02:00
|
|
|
<?php
|
|
|
|
ob_start(); // Start reading html
|
2022-06-20 14:05:27 +02:00
|
|
|
|
2022-10-10 16:02:07 +02:00
|
|
|
//header('Location: construction.php');
|
2022-06-20 14:05:27 +02:00
|
|
|
|
|
|
|
define("urlParam", "path");
|
2023-06-27 15:09:34 +02:00
|
|
|
define("photoRoot", "assets/img/com_photo/thumbs");
|
|
|
|
define("photoRootHQ", "assets/img/com_photo/full_q");
|
2022-06-20 14:05:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get active path from url and prevent from seeing folders before 'photos/'
|
|
|
|
* @return string current path
|
|
|
|
*/
|
|
|
|
function getActivePath()
|
|
|
|
{
|
|
|
|
$dir = '';
|
|
|
|
if (isset($_GET[urlParam]))
|
|
|
|
$dir = $_GET[urlParam];
|
|
|
|
$folders = explode(DIRECTORY_SEPARATOR, $dir);
|
|
|
|
$currentPath = "";
|
|
|
|
foreach ($folders as $value) {
|
|
|
|
if ($value != ".." && $value != "." && $value != "") {
|
|
|
|
$currentPath .= DIRECTORY_SEPARATOR . $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $currentPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get active folder from the active path
|
|
|
|
* @param string $path path representing the active folder
|
|
|
|
* @return string active folder name
|
|
|
|
*/
|
|
|
|
function GetActiveFolder($path)
|
|
|
|
{
|
|
|
|
$dir = explode(DIRECTORY_SEPARATOR, $path);
|
2022-10-25 21:05:09 +02:00
|
|
|
return ".".DIRECTORY_SEPARATOR.$dir[sizeof($dir) - 1]; // Last item after /
|
2022-06-20 14:05:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the current album is available for download as a .zip file
|
|
|
|
* @param string $path path to search the album in
|
|
|
|
* @return bool True if an album is available, false otherwise
|
|
|
|
*/
|
|
|
|
function isAlbumAvailable($path)
|
|
|
|
{
|
|
|
|
$dir = photoRoot . $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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all directories in the specified path and creates them on the page
|
|
|
|
* @param string $path path to search directories in
|
|
|
|
*/
|
|
|
|
function createDirectories($path)
|
|
|
|
{
|
|
|
|
$path = photoRoot . $path;
|
|
|
|
$displayedItems = 0;
|
|
|
|
$folders = getDirectories($path);
|
|
|
|
foreach ($folders as $key => $value) {
|
|
|
|
$folderTitle = $value;
|
|
|
|
$photos = getTotalPhotoCount($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
$albums = getTotalAlbumCount($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
$folderLink = "?" . urlParam . "=" . getActivePath() . DIRECTORY_SEPARATOR . $value;
|
|
|
|
?>
|
|
|
|
<a href="<?= $folderLink ?>">
|
2022-06-20 15:45:48 +02:00
|
|
|
<li class="directory-li">
|
2022-10-10 12:47:29 +02:00
|
|
|
<span id="folderTitle"><?= str_replace("_", " ", $folderTitle) ?></span>
|
2022-06-21 13:34:51 +02:00
|
|
|
<span id="folderPhotos">
|
|
|
|
<?php if ($photos > 1) {
|
2022-06-21 13:53:13 +02:00
|
|
|
echo " - ".$photos." photos";
|
2022-06-21 13:34:51 +02:00
|
|
|
} elseif ($photos == 1) {
|
2022-06-21 13:53:13 +02:00
|
|
|
echo " - ".$photos ." photo";
|
2022-06-21 13:34:51 +02:00
|
|
|
} else {
|
2022-06-21 13:53:13 +02:00
|
|
|
echo " - "."vide";
|
2022-06-21 13:34:51 +02:00
|
|
|
} ?>
|
|
|
|
</span>
|
|
|
|
<span id="folderAlbums">
|
|
|
|
<?php if ($albums > 1) {
|
2022-06-21 13:53:13 +02:00
|
|
|
echo " - ".$albums." albums";
|
2022-06-21 13:34:51 +02:00
|
|
|
} elseif ($albums == 1) {
|
2022-06-21 13:53:13 +02:00
|
|
|
echo " - ".$albums." album";
|
2022-06-21 13:34:51 +02:00
|
|
|
} ?>
|
|
|
|
</span>
|
2022-06-20 15:45:48 +02:00
|
|
|
</li>
|
2022-06-20 14:05:27 +02:00
|
|
|
</a>
|
|
|
|
<?php
|
|
|
|
$displayedItems++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all photos in the specified path and creates them on the page
|
|
|
|
* @param string $path path to search photos in
|
|
|
|
*/
|
2022-06-20 15:45:48 +02:00
|
|
|
function createPhotos($path_in)
|
2022-06-20 14:05:27 +02:00
|
|
|
{
|
2023-06-27 15:09:34 +02:00
|
|
|
$path = photoRoot . $path_in;
|
|
|
|
$path_no_thumb = photoRootHQ . $path_in;
|
2022-06-20 14:05:27 +02:00
|
|
|
$files = scandir($path);
|
|
|
|
$displayedItems = 0;
|
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
|
2022-06-20 15:45:48 +02:00
|
|
|
$realPath_no_thumb = realpath($path_no_thumb . DIRECTORY_SEPARATOR . $value);
|
|
|
|
if (isValidImage($realPath) AND isValidImage($realPath_no_thumb)) {
|
2022-06-20 14:05:27 +02:00
|
|
|
$imageSrc = $path . DIRECTORY_SEPARATOR . $value;
|
2022-06-20 15:45:48 +02:00
|
|
|
$img_no_thumb = $path_no_thumb . DIRECTORY_SEPARATOR . $value;
|
|
|
|
$imageId = "photo-" . $displayedItems;
|
|
|
|
?><a download="" href="<?= $img_no_thumb ?>"><img src="<?= $imageSrc ?>" class="photo" id="<?= $imageId ?>" alt=""/></a><?php
|
2022-06-20 14:05:27 +02:00
|
|
|
$displayedItems++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get folders in the given path
|
|
|
|
* @param string $path path to search folders in
|
|
|
|
* @return array array of folders
|
|
|
|
*/
|
|
|
|
function getDirectories($path)
|
|
|
|
{
|
|
|
|
$files = scandir($path);
|
|
|
|
$folders = [];
|
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
if (isValidDirectory($realPath, $value)) {
|
|
|
|
array_push($folders, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $folders;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts directories in the specified folder
|
|
|
|
* @param string $path path to search directories in
|
|
|
|
* @return int directories count
|
|
|
|
*/
|
|
|
|
function getDirectoriesCount($path)
|
|
|
|
{
|
|
|
|
$files = scandir($path);
|
|
|
|
$dirCount = 0;
|
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
if (isValidDirectory($realPath, $value)) {
|
|
|
|
$dirCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $dirCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts images in the specified folder
|
|
|
|
* @param string $path path to search photos in
|
|
|
|
* @return int photo count
|
|
|
|
*/
|
|
|
|
function getPhotoCount($path)
|
|
|
|
{
|
|
|
|
$files = scandir($path);
|
|
|
|
$fileCount = 0;
|
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
$realPath = realpath($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
if (isValidImage($realPath)) {
|
|
|
|
$fileCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $fileCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the count of all directories, recursively from the path specified
|
|
|
|
* @param string $path root for search
|
|
|
|
* @return int total number of directories
|
|
|
|
*/
|
|
|
|
function getTotalAlbumCount($path)
|
|
|
|
{
|
|
|
|
$folders = getDirectories($path);
|
|
|
|
$total = sizeof($folders);
|
|
|
|
foreach ($folders as $key => $value) {
|
|
|
|
$total += getTotalAlbumCount($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
}
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTotalPhotoCount($path)
|
|
|
|
{
|
|
|
|
$folders = getDirectories($path);
|
|
|
|
$total = getPhotoCount($path);
|
|
|
|
foreach ($folders as $key => $value) {
|
|
|
|
$total += getTotalPhotoCount($path . DIRECTORY_SEPARATOR . $value);
|
|
|
|
}
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the given image is valid
|
|
|
|
* @param string $imagePath absolute path of the image
|
|
|
|
* @return bool True if the file is a jpg, jpeg or png, false otherwise
|
|
|
|
*/
|
|
|
|
function isValidImage($imagePath)
|
|
|
|
{
|
|
|
|
$ext = pathinfo($imagePath, PATHINFO_EXTENSION);
|
|
|
|
return !is_dir($imagePath) && ($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG" || $ext == "png" || $ext == "PNG");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the given folder is valid (is not '.' or '..')
|
|
|
|
* @param string $directoryPath directory path
|
|
|
|
* @param string $directory directory name
|
|
|
|
* @return bool True if the directory is valid, false otherwise
|
|
|
|
*/
|
|
|
|
function isValidDirectory($directoryPath, $directory)
|
|
|
|
{
|
|
|
|
return is_dir($directoryPath) && $directory != "." && $directory != ".." && substr($directory, 0, 1) !== ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates buttons representing the actual path for easier navigation
|
|
|
|
* @param string $path Actual Path
|
|
|
|
*/
|
|
|
|
function generatePath($path)
|
|
|
|
{
|
|
|
|
$folders = explode(DIRECTORY_SEPARATOR, $path);
|
|
|
|
$currentPath = "";
|
|
|
|
$pathTitle = "Menu";
|
|
|
|
$pathLink = "?" . urlParam . "=";
|
2022-10-10 12:47:29 +02:00
|
|
|
echo '<li><a href="'.$pathLink.'" class="link">'.str_replace("_", " ", $pathTitle).'</a></li>';
|
2022-06-20 14:05:27 +02:00
|
|
|
foreach ($folders as $value) {
|
|
|
|
if ($value != "") {
|
|
|
|
$pathTitle = $value;
|
|
|
|
$currentPath .= DIRECTORY_SEPARATOR . $value;
|
|
|
|
$pathLink = "?" . urlParam . "=" . $currentPath;
|
2022-10-10 12:47:29 +02:00
|
|
|
echo ' > <li><a href="'.$pathLink.'" class="link">'.str_replace("_", " ", $pathTitle).'</a></li>';
|
2022-06-20 14:05:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:02:58 +02:00
|
|
|
|
|
|
|
//CAS
|
|
|
|
require_once("phpCAS-1.3.6/CAS.php");
|
|
|
|
|
2022-10-27 19:52:08 +02:00
|
|
|
|
2022-06-20 17:02:58 +02:00
|
|
|
phpCAS::client(CAS_VERSION_2_0, "cas.insa-toulouse.fr", 443, 'cas', true);
|
2022-10-27 19:52:08 +02:00
|
|
|
|
|
|
|
phpCAS::setNoCasServerValidation();
|
|
|
|
// phpCAS::setCasServerCACert($cas_server_ca_cert_path);
|
|
|
|
|
2022-06-20 17:02:58 +02:00
|
|
|
phpCAS::forceAuthentication();
|
|
|
|
if (isset($_REQUEST['logout'])) {
|
|
|
|
phpCAS::logout();
|
|
|
|
}
|
2020-09-19 16:08:07 +02:00
|
|
|
?>
|
2023-06-27 15:09:34 +02:00
|
|
|
|
|
|
|
|
2022-06-20 14:05:27 +02:00
|
|
|
<div class="inner">
|
|
|
|
|
2023-04-22 18:47:14 +02:00
|
|
|
<div class="zone_txt">
|
2022-06-20 17:02:58 +02:00
|
|
|
<font color="red">
|
|
|
|
<h1>Vous êtes connecté !</h1>
|
|
|
|
<p>Connecté en tant que : <b><?php echo phpCAS::getUser(); ?></b>.</p>
|
|
|
|
<p>Vous pouvez vous déconnecter en cliquant ici :<a href="?logout=" class="link">Se déconnecter</a></p>
|
|
|
|
</font><br><br>
|
2022-06-20 14:05:27 +02:00
|
|
|
<p>Clique sur le dossier de ton choix pour afficher les photos. Il faut que tu sois inscrit à l'INSA pour pouvoir
|
2022-06-20 15:45:48 +02:00
|
|
|
les regarder (et oui, pas de spoiler).</p>
|
|
|
|
<p>Il te suffit ensuite de cliquer sur la photo que tu veux télécharger.</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>
|
2023-04-22 18:47:14 +02:00
|
|
|
</div>
|
|
|
|
<div class="zone_txt" align="left">
|
2022-06-20 15:45:48 +02:00
|
|
|
<ul class="photos-path">
|
|
|
|
<li>Chemin : </li>
|
2022-06-20 14:05:27 +02:00
|
|
|
<?php
|
|
|
|
generatePath(getActivePath());
|
|
|
|
?>
|
2022-06-20 15:45:48 +02:00
|
|
|
</ul>
|
2022-10-26 09:08:38 +02:00
|
|
|
<?php if (isAlbumAvailable(getActivePath())): ?>
|
2023-06-27 15:09:34 +02:00
|
|
|
<a download="" href="assets/com_photo/"<?php echo getActivePath().DIRECTORY_SEPARATOR.GetActiveFolder(getActivePath()); ?>.zip" id="downloadAlbum">
|
2022-10-26 09:08:38 +02:00
|
|
|
<span id="downloadText">Télécharger</span>
|
|
|
|
<span id="albumPhotoCount"><?php echo getTotalPhotoCount(photoRoot . getActivePath()) ?> photos</span>
|
|
|
|
</a>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2022-06-20 15:45:48 +02:00
|
|
|
<ul class="directory-ul">
|
|
|
|
<?php if (getDirectoriesCount(photoRoot . getActivePath()) > 0): ?>
|
|
|
|
<div class="photos-folder-container">
|
|
|
|
<?php
|
|
|
|
createDirectories(getActivePath());
|
|
|
|
?>
|
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
</ul>
|
2022-10-26 09:08:38 +02:00
|
|
|
|
2022-06-20 15:45:48 +02:00
|
|
|
<?php if (getPhotoCount(photoRoot . getActivePath()) > 0): ?>
|
|
|
|
<div class="photos">
|
|
|
|
<?php
|
|
|
|
createPhotos(getActivePath());
|
|
|
|
?>
|
2022-10-26 09:08:38 +02:00
|
|
|
</div>
|
|
|
|
<?php endif; ?>
|
2023-04-22 18:47:14 +02:00
|
|
|
</div class="zone_txt">
|
2022-06-20 14:05:27 +02:00
|
|
|
</div>
|
|
|
|
<br>
|
|
|
|
|
2020-09-19 16:08:07 +02:00
|
|
|
<?php
|
2023-01-22 12:46:06 +01:00
|
|
|
$infopage = ["", "Photos", ob_get_clean(), "", "photos","Les photos"]; //relativepath, pagetitle, pagecontent, pagescript, pagename | cf structure/template.php ligne 2 à 6
|
2022-01-19 22:26:58 +01:00
|
|
|
include("structure/template.php");
|
2022-10-26 08:59:36 +02:00
|
|
|
?>
|