ajout d'un bouton "en savoir plus" sur les galeries

utilise la quatrième ligne du fichiers 'infos.txt', l'option dans l'admin n'apparait que pour les dossiers contenant des images.
This commit is contained in:
Esenjin 2025-01-03 14:33:31 +01:00
parent 35a9aaa4c2
commit e7b24b3c30
4 changed files with 113 additions and 9 deletions

View File

@ -19,8 +19,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($path && $newName) {
$newPath = $path . '/' . sanitizeFilename($newName);
if (!file_exists($newPath)) {
$moreInfoUrl = $_POST['more_info_url'] ?? '';
mkdir($newPath, 0755, true);
$infoContent = $newName . "\n" . $description . "\n" . $matureContent;
$infoContent = $newName . "\n" . $description . "\n" . $matureContent . "\n" . $moreInfoUrl;
file_put_contents($newPath . '/infos.txt', $infoContent);
$_SESSION['success_message'] = "Dossier créé avec succès.";
} else {
@ -28,10 +29,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
}
break;
case 'edit_folder':
if ($path && isSecurePath($path)) {
$infoContent = $newName . "\n" . $description . "\n" . $matureContent;
$moreInfoUrl = $_POST['more_info_url'] ?? '';
$infoContent = $newName . "\n" . $description . "\n" . $matureContent . "\n" . $moreInfoUrl;
$infoPath = $path . '/infos.txt';
if (file_put_contents($infoPath, $infoContent) !== false) {
$_SESSION['success_message'] = "Dossier modifié avec succès.";
@ -104,7 +106,7 @@ function generateTree($path, $currentPath) {
}
$output .= '</span>';
$output .= '<div class="tree-actions">';
$output .= '<button onclick="editFolder(\'' . htmlspecialchars($path) . '\', \'' . htmlspecialchars($info['title']) . '\', \'' . htmlspecialchars($info['description']) . '\', ' . ($info['mature_content'] ? 'true' : 'false') . ')" class="tree-button">✏️</button>';
$output .= '<button onclick="editFolder(\'' . htmlspecialchars($fullPath) . '\', \'' . rawurlencode($info['title']) . '\', \'' . rawurlencode($info['description']) . '\', ' . ($info['mature_content'] ? 'true' : 'false') . ', \'' . rawurlencode($info['more_info_url']) . '\', ' . (hasImages($fullPath) ? 'true' : 'false') . ')" class="tree-button">✏️</button>';
$output .= '<button onclick="createSubfolder(\'' . htmlspecialchars($path) . '\')" class="tree-button"></button>';
$output .= '</div></div>';
}
@ -130,7 +132,22 @@ function generateTree($path, $currentPath) {
if (!$hasSubfolders) {
$output .= '<a href="arbre-img.php?path=' . urlencode($fullPath) . '" class="tree-button" style="text-decoration: none">🖼️</a>';
}
$output .= '<button onclick="editFolder(\'' . htmlspecialchars($fullPath) . '\', \'' . htmlspecialchars($info['title']) . '\', \'' . htmlspecialchars($info['description']) . '\', ' . ($info['mature_content'] ? 'true' : 'false') . ')" class="tree-button">✏️</button>';
// Pour les dossiers avec des images
if (!$hasSubfolders) {
$output .= '<button onclick="editFolder(\'' . htmlspecialchars($fullPath) . '\', \''
. rawurlencode($info['title']) . '\', \''
. rawurlencode($info['description']) . '\', '
. ($info['mature_content'] ? 'true' : 'false') . ', \''
. rawurlencode($info['more_info_url']) . '\', '
. (hasImages($fullPath) ? 'true' : 'false')
. ')" class="tree-button">✏️</button>';
} else {
// Pour les dossiers sans images
$output .= '<button onclick="editFolder(\'' . htmlspecialchars($fullPath) . '\', \''
. rawurlencode($info['title']) . '\', \''
. rawurlencode($info['description']) . '\', '
. ($info['mature_content'] ? 'true' : 'false') . ', \'\', false)" class="tree-button">✏️</button>';
}
if (!hasImages($fullPath)) {
$output .= '<button onclick="createSubfolder(\'' . htmlspecialchars($fullPath) . '\')" class="tree-button"></button>';
}
@ -199,6 +216,10 @@ function generateTree($path, $currentPath) {
<label for="description">Description :</label>
<textarea id="description" name="description" rows="4" class="form-textarea"></textarea>
</div>
<div class="form-group">
<label for="more_info_url">Lien "En savoir plus" (optionnel) :</label>
<input type="url" id="more_info_url" name="more_info_url" placeholder="https://...">
</div>
<div class="form-group">
<label class="toggle-label">
<input type="checkbox" name="mature_content" id="mature_content">
@ -206,6 +227,10 @@ function generateTree($path, $currentPath) {
<span class="toggle-warning">⚠️</span>
</label>
</div>
<div class="form-group" id="create_more_info_url_field" style="display: none;">
<label for="more_info_url">Lien "En savoir plus" (optionnel) :</label>
<input type="url" id="more_info_url" name="more_info_url" placeholder="https://...">
</div>
<div class="form-actions">
<button type="button" onclick="closeModal()" class="action-button action-button-secondary">Annuler</button>
<button type="submit" class="action-button">Créer</button>
@ -236,6 +261,10 @@ function generateTree($path, $currentPath) {
<span class="toggle-warning">⚠️</span>
</label>
</div>
<div class="form-group" id="edit_more_info_url_field">
<label for="edit_more_info_url">Lien "En savoir plus" (optionnel) :</label>
<input type="url" id="edit_more_info_url" name="more_info_url" placeholder="https://...">
</div>
<div class="form-actions">
<button type="button" onclick="closeModal()" class="action-button action-button-secondary">Annuler</button>
<button type="submit" class="action-button">Enregistrer</button>
@ -263,15 +292,45 @@ function generateTree($path, $currentPath) {
<script>
function createSubfolder(path) {
document.getElementById('parentPath').value = path;
document.getElementById('create_more_info_url_field').style.display = 'none';
document.getElementById('createFolderModal').style.display = 'block';
}
function editFolder(path, title, description, matureContent = false) {
function editFolder(path, title, description, matureContent = false, moreInfoUrl = '', hasImages = false) {
document.getElementById('editPath').value = path;
document.getElementById('edit_name').value = title;
document.getElementById('edit_description').value = description;
document.getElementById('edit_name').value = decodeURIComponent(title);
document.getElementById('edit_description').value = decodeURIComponent(description);
document.getElementById('edit_mature_content').checked = matureContent;
document.getElementById('edit_more_info_url').value = decodeURIComponent(moreInfoUrl);
// Récupérer le champ URL
const moreInfoUrlField = document.getElementById('edit_more_info_url_field');
// Convertir hasImages en booléen explicitement
const showUrlField = hasImages === true || hasImages === 'true';
// Afficher ou masquer le champ URL
if (moreInfoUrlField) {
console.log('Found field, setting display to:', showUrlField ? 'block' : 'none');
moreInfoUrlField.style.display = showUrlField ? 'block' : 'none';
// Si le champ est masqué, on vide aussi sa valeur
if (!showUrlField) {
document.getElementById('edit_more_info_url').value = '';
}
} else {
console.log('Field not found');
}
document.getElementById('editFolderModal').style.display = 'block';
// Debug
console.log('Edit folder:', {
path,
hasImages,
showUrlField,
fieldFound: !!moreInfoUrlField
});
}
function deleteFolder(path) {

View File

@ -22,7 +22,8 @@ function getAlbumInfo($albumPath) {
$info = [
'title' => basename($albumPath),
'description' => '',
'mature_content' => false
'mature_content' => false,
'more_info_url' => ''
];
if (file_exists($infoFile)) {
@ -31,6 +32,7 @@ function getAlbumInfo($albumPath) {
if (isset($lines[0])) $info['title'] = trim($lines[0]);
if (isset($lines[1])) $info['description'] = trim($lines[1]);
if (isset($lines[2])) $info['mature_content'] = trim($lines[2]) === '18+';
if (isset($lines[3])) $info['more_info_url'] = trim($lines[3]);
}
return $info;

View File

@ -80,6 +80,21 @@ if (!isSecurePath($parentPath)) {
Contenu réservé aux plus de 18 ans
</div>
<?php endif; ?>
<?php if (!empty($albumInfo['more_info_url'])): ?>
<div class="more-info-button">
<a href="<?php echo htmlspecialchars($albumInfo['more_info_url']); ?>"
target="_blank"
rel="noopener noreferrer"
class="action-button">
<svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="16" x2="12" y2="12"/>
<line x1="12" y1="8" x2="12" y2="8"/>
</svg>
En savoir plus sur <?php echo htmlspecialchars($albumInfo['title']); ?>
</a>
</div>
<?php endif; ?>
</div>
<div class="gallery-grid" id="gallery-grid">

View File

@ -322,6 +322,34 @@ body {
font-size: 1.2rem;
}
.more-info-button {
margin-top: 2rem;
}
.more-info-button .action-button {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.8rem 1.5rem;
background-color: #2196f3;
color: white;
text-decoration: none;
border-radius: 2rem;
font-size: 1rem;
transition: all 0.3s ease;
}
.more-info-button .action-button:hover {
background-color: #1976d2;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}
.more-info-button .icon {
width: 1.2em;
height: 1.2em;
}
.gallery-header {
width: 100%;
height: 500px;