From cade166404ccfdc5545c0068ce56326b3c873459 Mon Sep 17 00:00:00 2001 From: "cedric@yterium.com" <> Date: Wed, 29 Oct 2014 10:34:23 +0000 Subject: [PATCH] =?UTF-8?q?Quand=20une=20largeur=20maxi=20ou=20hauteur=20m?= =?UTF-8?q?axi=20d'image=20'est=20definie,=20plutot=20que=20de=20generer?= =?UTF-8?q?=20une=20erreur,=20on=20reduit=20automatiquement=20le=20fichier?= =?UTF-8?q?=20uploade=20si=20l'option=20'G=C3=A9n=C3=A9rer=20automatiqueme?= =?UTF-8?q?nt=20les=20miniatures=20des=20images'=20a=20=C3=A9t=C3=A9=20act?= =?UTF-8?q?iv=C3=A9e.=20Du=20coup=20il=20faut=20verifier=20la=20taille=20(?= =?UTF-8?q?en=20ko)=20apres,=20car=20si=20on=20a=20reduit=20l'image=20elle?= =?UTF-8?q?=20a=20des=20chances=20d'etre=20moins=20lourde=20aussi.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/ajouter_documents.php | 77 ++++++++++++++++++++++++++---------- paquet.xml | 2 +- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/action/ajouter_documents.php b/action/ajouter_documents.php index a47eeba8..6b7142f6 100644 --- a/action/ajouter_documents.php +++ b/action/ajouter_documents.php @@ -416,37 +416,72 @@ function fixer_fichier_upload($file, $mode=''){ * @param array $infos * @return bool|mixed|string */ -function verifier_taille_document_acceptable($infos){ +function verifier_taille_document_acceptable(&$infos){ // si ce n'est pas une image if (!$infos['type_image']) { - if (_DOC_MAX_SIZE > 0 - AND $infos['taille'] > _DOC_MAX_SIZE*1024) - return _T('medias:info_doc_max_poids', array('maxi' => taille_en_octets(_DOC_MAX_SIZE*1024), 'actuel' => taille_en_octets($infos['taille']))); + if (defined('_DOC_MAX_SIZE') AND _DOC_MAX_SIZE > 0 AND $infos['taille'] > _DOC_MAX_SIZE*1024){ + return _T('medias:info_doc_max_poids', + array( + 'maxi' => taille_en_octets(_DOC_MAX_SIZE*1024), + 'actuel' => taille_en_octets($infos['taille']) + ) + ); + } } // si c'est une image else { - if (_IMG_MAX_SIZE > 0 - AND $infos['taille'] > _IMG_MAX_SIZE*1024) - return _T('medias:info_image_max_poids', array('maxi' => taille_en_octets(_IMG_MAX_SIZE*1024), 'actuel' => taille_en_octets($infos['taille']))); - - if (_IMG_MAX_WIDTH * _IMG_MAX_HEIGHT - AND ($infos['largeur'] > _IMG_MAX_WIDTH - OR $infos['hauteur'] > _IMG_MAX_HEIGHT)) + if ((defined('_IMG_MAX_WIDTH') AND _IMG_MAX_WIDTH AND $infos['largeur']>_IMG_MAX_WIDTH) + OR (defined('_IMG_MAX_HEIGHT') AND _IMG_MAX_HEIGHT AND $infos['hauteur']>_IMG_MAX_HEIGHT) ){ + $max_width = (defined('_IMG_MAX_WIDTH') AND _IMG_MAX_WIDTH) ? _IMG_MAX_WIDTH : '*'; + $max_height = (defined('_IMG_MAX_HEIGHT') AND _IMG_MAX_HEIGHT) ? _IMG_MAX_HEIGHT : '*'; + + // pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures + // on met directement a la taille maxi a la volee + if (isset($GLOBALS['meta']['creer_preview']) AND $GLOBALS['meta']['creer_preview']=='oui'){ + include_spip('inc/filtres'); + $img = filtrer('image_reduire', $infos['fichier'], $max_width, $max_height); + $img = extraire_attribut($img, 'src'); + $img = supprimer_timestamp($img); + if (@file_exists($img) AND $img!==$infos['fichier']){ + spip_unlink($infos['fichier']); + @rename($img, $infos['fichier']); + $size = @getimagesize($infos['fichier']); + $infos['largeur'] = $size[0]; + $infos['hauteur'] = $size[1]; + $infos['taille'] = @filesize($infos['fichier']); + } + } - return _T('medias:info_logo_max_taille', + if ((defined('_IMG_MAX_WIDTH') AND _IMG_MAX_WIDTH AND $infos['largeur']>_IMG_MAX_WIDTH) + OR (defined('_IMG_MAX_HEIGHT') AND _IMG_MAX_HEIGHT AND $infos['hauteur']>_IMG_MAX_HEIGHT) ){ + + return _T('medias:info_logo_max_taille', array( - 'maxi' => - _T('info_largeur_vignette', - array('largeur_vignette' => _IMG_MAX_WIDTH, - 'hauteur_vignette' => _IMG_MAX_HEIGHT)), - 'actuel' => - _T('info_largeur_vignette', - array('largeur_vignette' => $infos['largeur'], - 'hauteur_vignette' => $infos['hauteur'])) - )); + 'maxi' => + _T('info_largeur_vignette', + array('largeur_vignette' => $max_width, + 'hauteur_vignette' => $max_height)), + 'actuel' => + _T('info_largeur_vignette', + array('largeur_vignette' => $infos['largeur'], + 'hauteur_vignette' => $infos['hauteur'])) + )); + } + } + + if (defined('_IMG_MAX_SIZE') AND _IMG_MAX_SIZE > 0 AND $infos['taille'] > _IMG_MAX_SIZE*1024){ + return _T('medias:info_image_max_poids', + array( + 'maxi' => taille_en_octets(_IMG_MAX_SIZE*1024), + 'actuel' => taille_en_octets($infos['taille'] + ) + ) + ); + } + } // verifier en fonction du mode si une fonction est proposee diff --git a/paquet.xml b/paquet.xml index 10da8d41..81e61337 100644 --- a/paquet.xml +++ b/paquet.xml @@ -1,7 +1,7 @@ <paquet prefix="medias" categorie="multimedia" - version="2.9.15" + version="2.10.0" etat="stable" compatibilite="[3.0.0;3.1.*]" logo="prive/themes/spip/images/portfolio-32.png" -- GitLab