Skip to content

Commit

Permalink
refactor(events): split images in "evenements" dir by year
Browse files Browse the repository at this point in the history
to ease the load of the huge amount of files
  • Loading branch information
agilare committed Dec 7, 2024
1 parent 9bbe3c6 commit 9929c94
Show file tree
Hide file tree
Showing 18 changed files with 816 additions and 903 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [3.5.4] - 2024-12-08

### Fixed
- events : increase "horaire_complement", "ref", "prelocations" fields lengths which were a little too tight

### Added
- events : split images in "evenements" dir by year to ease the load of the huge amount of files
- events : in edit form, title field, warn if user pastes text too large; it happens often and results in odd titles

### Changed
- events : remove the "new" icon in the 2 infos about Noctambus which were put 1 year ago
- upgrades : PHPMailer, PHP dotenv, Whoops 2.16, PHPStan 1.12, PHP_Codesniffer 3.10, Magnific-Popup 1.1 to 1.2, Zebra Datepicker 2.2


## [3.5.3] - 2024-11-10

### Fixed
Expand Down
15 changes: 5 additions & 10 deletions _evenement.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,19 @@
<?php
if (!empty($evenement['flyer']))
{
$imgInfo = getimagesize($rep_images_even.$evenement['flyer']);
?>
<a href="<?php echo $url_uploads_events.$evenement['flyer']."?".filemtime($rep_images_even.$evenement['flyer']) ?>" class="magnific-popup" target="_blank">
<a href="<?php echo Evenement::getFileHref(Evenement::getFilePath($evenement['flyer']), true) ?>" class="magnific-popup" target="_blank">

<img src="<?php echo $url_uploads_events.$evenement['flyer']."?".filemtime($rep_images_even.$evenement['flyer']) ?>" alt="Flyer de cet événement" width="100" />
<img src="<?php echo Evenement::getFileHref(Evenement::getFilePath($evenement['flyer'], 's_'), true) ?>" alt="Flyer de cet événement" width="100" />
</a>
<?php
//echo lien_popup($IMGeven.$evenement['flyer'].'?'.filemtime($rep_images_even.$evenement['flyer']), "flyer", $imgInfo[0]+20, $imgInfo[1]+20, "<img src=\"".$IMGeven."s_".$evenement['flyer']."?".filemtime($rep_images_even."s_".$evenement['flyer'])."\" alt=\"Flyer\" />");

}
else if (!empty($evenement['image']))
{
$imgInfo = @getimagesize($rep_images_even.$evenement['image']);
//echo lien_popup($IMGeven.$evenement['image']."?".filemtime($rep_images_even.$evenement['image']), "Image", $imgInfo[0]+20, $imgInfo[1]+20,"<img src=\"".$IMGeven."s_".$evenement['image']."?".filemtime($rep_images_even.$evenement['image'])."\" alt=\"Image\" />");
?>
<a href="<?php echo $url_uploads_events.$evenement['image']."?".filemtime($rep_images_even.$evenement['image']) ?>" class="magnific-popup" target="_blank">
<a href="<?php echo Evenement::getFileHref(Evenement::getFilePath($evenement['image']), true) ?>" class="magnific-popup" target="_blank">

<img src="<?php echo $url_uploads_events.$evenement['image']."?".filemtime($rep_images_even.$evenement['image']) ?>" alt="Photo pour cet événement" width="100" />
<img src="<?php echo Evenement::getFileHref(Evenement::getFilePath($evenement['image'], 's_'), true) ?>" alt="Photo pour cet événement" width="100" />
</a>
<?php
}
Expand Down Expand Up @@ -111,4 +106,4 @@
<!-- fin pratique -->

</div>
</div>
</div>
106 changes: 24 additions & 82 deletions admin/gererEvenements.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once("../app/bootstrap.php");

use Ladecadanse\Evenement;
use Ladecadanse\Utils\Validateur;
use Ladecadanse\Utils\ImageDriver2;
use Ladecadanse\EvenementCollection;
Expand Down Expand Up @@ -446,13 +447,13 @@

if (!empty($fichiers['flyer']['name']))
{
$champs['flyer'] = $idEven_courant.$tab_even['dateEvenement'].strrchr($fichiers['flyer']['name'], '.');
}
$champs['flyer'] = $idEven_courant . "_" . $tab_even['dateEvenement'] . strrchr($fichiers['flyer']['name'], '.');
}

if (!empty($fichiers['image']['name']))
{
$champs['image'] = $idEven_courant.$tab_even['dateEvenement']."_img".strrchr($fichiers['image']['name'], '.');
}
$champs['image'] = $idEven_courant . "_" . $tab_even['dateEvenement'] . "_img" . strrchr($fichiers['image']['name'], '.');
}


$sql_flyer = ""; // champ SQL pour le flyer
Expand All @@ -471,18 +472,12 @@
//si un ancien flyer a été effectivement trouvé suppression des fichiers
if (!empty($affFly['flyer']))
{
unlink($rep_images_even.$affFly['flyer']);
unlink($rep_images_even . "s_" . $affFly['flyer']);
Evenement::rmImageAndItsMiniature($affFly['flyer']);
echo "<div class=\"msg\">Ancien flyer ".$affFly['flyer']." supprimé</div>";
}


}
else
{
HtmlShrink::msgErreur("La requête SELECT flyer a échoué");
}


//si le champ "supprimer le flyer" est coché sans qu'un nouveau flyer soit remplacant
}

Expand All @@ -499,15 +494,9 @@

if (!empty($affFly['flyer']))
{
unlink($rep_images_even.$affFly['flyer']);
unlink($rep_images_even . "s_" . $affFly['flyer']);
//echo "<div class=\"msg\">Ancien flyer ".$affFly['flyer']." supprimé</div>";
Evenement::rmImageAndItsMiniature($affFly['flyer']);
}
}
else
{
HtmlShrink::msgErreur("La requête SELECT flyer a échoué");
}

} //elseif supprimer flyer

Expand All @@ -527,15 +516,9 @@
//si un ancien flyer a 굩 effectivement trouv顳uppression des fichiers
if (!empty($affImg['image']))
{
unlink($rep_images_even.$affImg['image']);
unlink($rep_images_even."s_".$affImg['image']);
//echo "<div class=\"msg\">Ancienne image ".$affImg['image']." supprimée</div>";
Evenement::rmImageAndItsMiniature($affImg['image']);
}
}
else
{
HtmlShrink::msgErreur("La requête SELECT image a échoué");
}

//si le champ "supprimer le flyer" est coch顳ans qu'un nouveau flyer soit remplacant
}
Expand All @@ -553,15 +536,9 @@

if (!empty($affimage['image']))
{
unlink($rep_images_even.$affimage['image']);
unlink($rep_images_even."s_".$affimage['image']);
//echo "<div class=\"msg\">Ancien image ".$affimage['image']." supprimée</div>";
Evenement::rmImageAndItsMiniature($affImg['image']);
}
}
else
{
HtmlShrink::msgErreur("La requête SELECT image a échoué");
}

} //if supprimer image

Expand Down Expand Up @@ -618,34 +595,18 @@
$erreur_image[] = $imD2->processImage($_FILES['flyer'], $champs['flyer'], 400, 400);
$erreur_image[] = $imD2->processImage($_FILES['flyer'], "s_".$champs['flyer'], 120, 190, 0, 1);

if (!empty($erreur_image))
{
//printr($erreur_image);
}

if (!empty($msg2))
$champs['flyer'] = '';

$srcFlyer = $champs['flyer'];
}
elseif (!empty($fichiers['flyer']['name']))
{

$src = $rep_images_even.$srcFlyer;
$des = $rep_images_even.$champs['flyer'];

if (!copy($src, $des))
HtmlShrink::msgErreur("La copie du fichier taille normale ".$champs['flyer']." n'a pas réussi...");


$src = $rep_images_even."s_".$srcFlyer;
$des = $rep_images_even."s_".$champs['flyer'];

if (!copy($src, $des))
HtmlShrink::msgErreur("La copie du fichier taille small " . $champs['flyer'] . " n'a pas réussi...");
copy(Evenement::getFilePath($srcFlyer), Evenement::getFilePath($champs['flyer']));
copy(Evenement::getFilePath($srcFlyer, "s_"), Evenement::getFilePath($champs['flyer'], "s_"));
}

if (!empty($fichiers['image']['name']) && $compteur_evenements == 0)
if (!empty($fichiers['image']['name']) && $compteur_evenements == 0)
{

$imD2 = new ImageDriver2("evenement");
Expand All @@ -664,36 +625,19 @@
}
elseif (!empty($fichiers['image']['name']))
{

$src = $rep_images_even.$src_image;
$des = $rep_images_even.$champs['image'];

if (!copy($src, $des))
HtmlShrink::msgErreur("La copie du fichier taille normale ".$champs['image']." n'a pas réussi...");

$src = $rep_images_even."s_".$src_image;
$des = $rep_images_even."s_".$champs['image'];

if (!copy($src, $des))
HtmlShrink::msgErreur("La copie du fichier taille small ".$champs['image']." n'a pas réussi...");

}
copy(Evenement::getFilePath($src_image), Evenement::getFilePath($champs['image']));
copy(Evenement::getFilePath($src_image, "s_"), Evenement::getFilePath($champs['image'], "s_"));
}

foreach ($champs['organisateurs'] as $no => $idOrg)
{
if ($idOrg != 0)
{
$sql = "INSERT INTO evenement_organisateur (idEvenement, idOrganisateur) VALUES (".$idEven_courant.", ".$idOrg.")";
//echo $sql;

if ($connector->query($sql))
{

}
}
$sql = "INSERT INTO evenement_organisateur (idEvenement, idOrganisateur) VALUES (" . $idEven_courant . ", " . $idOrg . ")";
$connector->query($sql);
}
}


$compteur_evenements++;
}

Expand Down Expand Up @@ -1340,8 +1284,7 @@
if (isset($get_idE) && !empty($champs['flyer']) && !$verif->getErreur($champs['flyer']))
{
echo '<div class="supImg">';
$imgInfo = getimagesize($rep_images_even.$champs['flyer']);
$iconeImage = '<img src="' . $url_uploads_events . "s_" . $champs['flyer'] . '" alt="image pour ' . sanitizeForHtml($champs['titre']) . '" />';
$iconeImage = '<img src="' . Evenement::getFileHref(Evenement::getFilePath($champs['flyer'], "s_")) . ' " alt="Flyer" />';
?>

<div><label for="sup_flyer" class="continu">Supprimer</label>
Expand All @@ -1358,7 +1301,7 @@

<p>
<label for="image">Image :</label>
<input type="file" name="image" id="flyer" class="js-file-upload-size-max" size="25" accept="image/jpeg,image/pjpeg,image/png,image/x-png,image/gif" title="Choisissez une image pour illustrer l'ê·©nement" tabindex="12" class="fichier" />
<input type="file" name="image" id="flyer" class="js-file-upload-size-max" size="25" accept="image/jpeg,image/pjpeg,image/png,image/x-png,image/gif" class="fichier" />
</p>
<div class="guideChamp">Seul les formats JPEG, PNG et GIF sont acceptés.</div>
<div class="spacer"></div>
Expand All @@ -1369,10 +1312,9 @@
//affichage du flyer, et du bouton pour supprimer
if (isset($get_idE) && !empty($champs['image']) && !$verif->getErreur('image'))
{
$imgInfo = getimagesize($rep_images_even.$champs['image']);
$iconeImage = "<img src=\"".$url_uploads_events."s_".$champs['image']."\" alt=\"image pour ".sanitizeForHtml($champs['titre'])."\" />";
$iconeImage = "<img src=\"" . Evenement::getFileHref(Evenement::getFilePath($champs['image'], "s_")) . "\" alt=\"Photo\" />";

echo "<div><label for=\"sup_image\" class=\"continu\">Supprimer</label><input type=\"checkbox\" name=\"sup_image\" id=\"sup_image\" value=\"image\" class=\"checkbox\" ";
echo "<div><label for=\"sup_image\" class=\"continu\">Supprimer</label><input type=\"checkbox\" name=\"sup_image\" id=\"sup_image\" value=\"image\" class=\"checkbox\" ";

if (!empty($supprimer['image']) && $verif->nbErreurs() == 0)
{
Expand Down Expand Up @@ -1405,4 +1347,4 @@
<div class="spacer"><!-- --></div>
<?php
include("../_footer.inc.php");
?>
?>
Loading

0 comments on commit 9929c94

Please sign in to comment.