Newer
Older
<?php
/**
* SPIP, Système de publication pour l'internet
*
* Copyright © avec tendresse depuis 2001
* Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James
*
* Ce programme est un logiciel libre distribué sous licence GNU/GPL.
*/
/**
* Gestion des vignettes de types de fichier
*
* @package SPIP\Medias\Vignette
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Verifier si le fichier respecte les contraintes de tailles
*
* @param array $infos
* @param bool $is_logo
* @return bool|mixed|string
*/
function inc_verifier_taille_document_acceptable_dist(&$infos, $is_logo = false) {
// si ce n'est pas une image
if (!$infos['type_image']) {
$max_size = (defined('_DOC_MAX_SIZE') && _DOC_MAX_SIZE) ? _DOC_MAX_SIZE : null;
if ($res !== true) {
return $res;
}
} // si c'est une image
else {
// Ne pas contraindre les dimensions des images vectorielles, ça n'a pas de sens
if ($infos['type_image'] !== 'svg') {
if ($is_logo) {
$max_width = (defined('_LOGO_MAX_WIDTH') && _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : null;
$max_height = (defined('_LOGO_MAX_HEIGHT') && _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : null;
$min_width = (defined('_LOGO_MIN_WIDTH') && _LOGO_MIN_WIDTH) ? _LOGO_MIN_WIDTH : null;
$min_height = (defined('_LOGO_MIN_HEIGHT') && _LOGO_MIN_HEIGHT) ? _LOGO_MIN_HEIGHT : null;
$max_width = (defined('_IMG_MAX_WIDTH') && _IMG_MAX_WIDTH) ? _IMG_MAX_WIDTH : null;
$max_height = (defined('_IMG_MAX_HEIGHT') && _IMG_MAX_HEIGHT) ? _IMG_MAX_HEIGHT : null;
$min_width = (defined('_IMG_MIN_WIDTH') && _IMG_MIN_WIDTH) ? _IMG_MIN_WIDTH : null;
$min_height = (defined('_IMG_MIN_HEIGHT') && _IMG_MIN_HEIGHT) ? _IMG_MIN_HEIGHT : null;
$res = medias_verifier_largeur_hauteur_image($infos, $max_width, $max_height, $min_width, $min_height);
if ($res !== true) {
return $res;
}
}
$max_size = (defined('_LOGO_MAX_SIZE') && _LOGO_MAX_SIZE) ? _LOGO_MAX_SIZE : null;
$max_size = (defined('_IMG_MAX_SIZE') && _IMG_MAX_SIZE) ? _IMG_MAX_SIZE : null;
if ($res !== true) {
return $res;
}
}
return true;
}
/**
* Verifier largeur maxi et hauteur maxi d'une image
* + largeur mini et hauteur mini
* @param array $infos
* @param null|int $max_width
* @param null|int $max_height
* @param null|int $min_width
* @param null|int $min_height
* @return bool|string
*/
function medias_verifier_largeur_hauteur_image(
&$infos,
$max_width = null,
$max_height = null,
$min_width = null,
$min_height = null
) {
$max_width && $infos['largeur'] > $max_width || $max_height && $infos['hauteur'] > $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']) && $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) && $img !== $infos['fichier']) {
spip_unlink($infos['fichier']);
@rename($img, $infos['fichier']);
[$h, $w] = taille_image($infos['fichier'], true);
$infos['largeur'] = $w;
$infos['hauteur'] = $h;
$infos['taille'] = @filesize($infos['fichier']);
}
}
$max_width && $infos['largeur'] > $max_width || $max_height && $infos['hauteur'] > $max_height
) {
return _T(
'medias:info_image_max_taille',
'maxi' =>
_T(
'info_largeur_vignette',
RealET
a validé
'largeur_vignette' => $max_width ?? '∞',
),
'actuel' =>
_T(
'info_largeur_vignette',
'largeur_vignette' => $infos['largeur'],
);
}
}
$min_width && $infos['largeur'] < $min_width || $min_height && $infos['hauteur'] < $min_height
) {
if ($min_width && $max_width && $min_width > $max_width) {
spip_log(
'Constantes invalides détectées, modifiez votre fichier de configuration (_IMG_MIN_WIDTH > _IMG_MAX_WIDTH)',
'medias' . _LOG_INFO_IMPORTANTE
);
if ($min_height && $max_height && $min_height > $max_height) {
spip_log(
'Constantes invalides détectées, modifiez votre fichier de configuration (_IMG_MIN_HEIGHT > _IMG_MAX_HEIGHT)',
'medias' . _LOG_INFO_IMPORTANTE
);
return _T(
'medias:info_image_min_taille',
'mini' =>
_T(
'info_largeur_vignette',
RealET
a validé
'largeur_vignette' => $min_width ?? '0',
),
'actuel' =>
_T(
'info_largeur_vignette',
'largeur_vignette' => $infos['largeur'],
);
}
return true;
}
/**
* verifier le poids maxi d'une image
* @param array $infos
* @param null|int $max_size
* @return bool|string
*/
function medias_verifier_poids_fichier($infos, $max_size = null, $is_image = false) {
if ($max_size && $infos['taille'] > $max_size * 1024) {
$is_image ? 'medias:info_image_max_poids' : 'medias:info_doc_max_poids',
'maxi' => taille_en_octets($max_size * 1024),