Pagine → 1 2
15/03/2023 15:52:08
Ok la smetto :P
gli ho dato un'ulteriore sistemata, aggiunti i due sorting mancanti, sistemato un bug per gli apostrofi nel titolo, rimossi eventuali file non immagine dall'elenco.
Codice finito, lo mando al portale :P
<?php /*HELP: */
if($_SESSION['permessi'] >= MODERATOR) { /* se almeno admin */
?>
<div>
<!-- Titolo della pagina -->
<div class="page_title">
<h3>Elenco immagini nella cartella dedicata</h3>
</div>
<!-- Operazioni -->
<div class="page_body">
<?php /**/
$path = '**inserire percorso assoluto**/themes/advanced/imgs/items';
// get the directory contents as an array
$dir_contents = scandir($path);
// remove . and .. from the array
$dir_contents = array_diff($dir_contents, array('.', '..'));
// check if the sort option is set in the query string
if (isset($_REQUEST['sort_by'])) {
$sort_by = $_REQUEST['sort_by'];
} else {
$sort_by = 'date_desc'; // default sorting is by date
}
// sort the array based on the selected option
switch ($sort_by) {
case 'name_desc':
arsort($dir_contents, SORT_NATURAL | SORT_FLAG_CASE); // sort by name, descending
break;
case 'name_asc':
asort($dir_contents, SORT_NATURAL | SORT_FLAG_CASE); // sort by name, ascending
break;
case 'date_asc':
$dir_contents = array_map(function($file) use($path) {
return [$file, filemtime("$path/$file")];
}, $dir_contents); // add file modification time to each file name
usort($dir_contents, function($a, $b) {
return $a[1] - $b[1]; // sort by modification time, ascending
});
$dir_contents = array_map(function($file) {
return $file[0]; // remove the modification time from the array
}, $dir_contents);
break;
case 'date_desc':
$dir_contents = array_map(function($file) use($path) {
return [$file, filemtime("$path/$file")];
}, $dir_contents); // add file modification time to each file name
usort($dir_contents, function($a, $b) {
return $b[1] - $a[1]; // sort by modification time, descending
});
$dir_contents = array_map(function($file) {
return $file[0]; // remove the modification time from the array
}, $dir_contents);
break;
default:
sort($dir_contents, SORT_NATURAL | SORT_FLAG_CASE); // default sorting is by name, ascending
}
// set the number of images per page
$per_page = 200;
// get the current page number from the query string
if (isset($_REQUEST['pagination'])) {
$pagination = $_REQUEST['pagination'];
} else {
$pagination = 1;
}
// calculate the offset
$offset = ($pagination - 1) * $per_page;
// remove non-image files from the array
$dir_contents = array_filter($dir_contents, function($file) use($path) {
return exif_imagetype("$path/$file");
});
// calculate the total number of pages
$total_pages = ceil(count($dir_contents) / $per_page);
// slice the array to get the current page's images
$images = array_slice($dir_contents, $offset, $per_page);
// print the images
echo 'IMMAGINI:';
echo '<div style="display: flex; flex-wrap: wrap;">';
foreach ($images as $image) {
// escape special characters in the image filename
$escaped_image = htmlspecialchars($image, ENT_QUOTES);
// print the image
echo '<div style="width: 200px; height: 200px; margin: 10px;">';
echo "<a href='../../themes/advanced/imgs/items/$escaped_image' target='_blank'><img src='../../themes/advanced/imgs/items/$escaped_image' width='200' height='200'></a>";
echo "<div style='text-align: center; height:100%;'>$escaped_image</div>";
echo '</div>';
}
echo '</div>';
// calculate the total number of pages
$total_pages = ceil(count($dir_contents) / $per_page);
// print the pagination links
echo '<div style="text-align: center;">';
echo '<form action="main.php?page=servizi_listaoggettifolder" method="post">';
echo '<select name="sort_by">';
echo "<option value='date_desc'".($sort_by == 'date_desc' ? ' selected' : '').">Data ultima modifica (Prima i piů recenti)</option>";
echo "<option value='date_asc'".($sort_by == 'date_asc' ? ' selected' : '').">Data ultima modifica (Prima i piů vecchi)</option>";
echo "<option value='name_asc'".($sort_by == 'name_asc' ? ' selected' : '').">Nome (da A a Z)</option>";
echo "<option value='name_desc'".($sort_by == 'name_desc' ? ' selected' : '').">Nome (da Z ad A)</option>";
echo '</select>';
echo '<input type="submit" value="Sort">';
echo '</form>';
// loop through the total number of pages and print the pagination links
for ($i = 1; $i <= $total_pages; $i++) {
if ($i == $pagination) {
echo "<span style='font-weight: bold;'>$i</span> ";
} else {
echo "<a href='main.php?page=servizi_listaoggettifolder&pagination=$i&sort_by=$sort_by'>$i</a> ";
}
}
echo '</div>';
} else { echo '<div class="warning">Non sei abilitato a vedere questa pagina</div>'; }//fine if se non si č admin ?>
</div><!-- operazioni-->
</div><!-- box -->
Leggendra.eu - Fantasy steampunk itinerante
https://www.leggendra.eu
Discussione seguita da
Pagine → 1 2
Aggiungi ai Preferiti Inoltra Discussione Forum Programmazione, GDRCD e Open Source Elenco Forum
neverhaveiever ha risposto alla discussione: Never Have I Ever: Mysteries of Laconia Bay
✋😟
Abbiamo rilevato che stai usando un software per bloccare la pubblicità!
L'utilizzo di GDR-online.com è gratuito da oltre 18 anni ma è necessario coprire i costi per mantenerlo online... ti chiediamo di aiutarci disabilitando il blocco dei banner pubblicitari.
Togliere il blocco significa fare in modo che GDR-online.com possa continuare a far conoscere piccoli giochi amatoriali gratuitamente e offrire un servizio sempre migliore e adatto alle esigenze dei suoi giocatori!
Se questo avviso continua ad apparire nonostante tu abbia autorizzato il portale:
- Verifica nelle opzioni che venga disattivato AdBlock in tutto il dominio gdr-online.com e non solo in una pagina
- Controlla di non avere fra le estensioni installate altre analoghe ad AdBlock, come AdBlock Plusbr, ublock origin, ecc.
- Probabilmente sul tuo PC è installato un Antivirus che ha anche funzioni di blocco pubblicità
- Se usi Firefox impostare il "Blocco Contenuti" su "Normale" e non su "Restrittivo". Per farlo clicca sull'icona dello scudo vicino all'URL e clicca su "Disattiva Blocco per questo sito"
- Prova a premere CTRL + F5, riloggarti e vedi se il problema persiste