e4750c83a797ca6a2ff10e6f1002df25efa4f266
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2017 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
14 * Gestion de l'API de modification/suppression des logos
16 * @package SPIP\Core\Logo\Edition
19 if (!defined('_ECRIRE_INC_VERSION')) {
25 * Supprimer le logo d'un objet
27 * @param string $objet
28 * @param int $id_objet
32 function logo_supprimer($objet, $id_objet, $etat) {
33 $chercher_logo = charger_fonction('chercher_logo', 'inc');
34 $objet = objet_type($objet);
35 $primary = id_table_objet($objet);
36 include_spip('inc/chercher_logo');
38 // existe-t-il deja un logo ?
39 $logo = $chercher_logo($id_objet, $primary, $etat);
41 spip_unlink($logo[0]);
46 * Modifier le logo d'un objet
48 * @param string $objet
49 * @param int $id_objet
52 * @param string|array $source
53 * - array : sous tableau de `$_FILE` issu de l'upload
54 * - string : fichier source (chemin complet ou chemin relatif a `tmp/upload`)
58 function logo_modifier($objet, $id_objet, $etat, $source) {
59 $chercher_logo = charger_fonction('chercher_logo', 'inc');
60 $objet = objet_type($objet);
61 $primary = id_table_objet($objet);
62 include_spip('inc/chercher_logo');
63 $type = type_du_logo($primary);
66 $nom = $type . $etat . $id_objet;
68 // supprimer le logo eventueel existant
69 logo_supprimer($objet, $id_objet, $etat);
71 include_spip('inc/documents');
75 spip_log('spip_image_ajouter : source inconnue');
76 $erreur = 'source inconnue';
81 $file_tmp = _DIR_LOGOS
. $nom . '.tmp';
84 // fichier dans upload/
85 if (is_string($source)) {
86 if (file_exists($source)) {
87 $ok = @copy
($source, $file_tmp);
88 } elseif (file_exists($f = determine_upload() . $source)) {
89 $ok = @copy
($f, $file_tmp);
91 } elseif (!$erreur = check_upload_error($source['error'], '', true)) {
92 // Intercepter une erreur a l'envoi
93 // analyse le type de l'image (on ne fait pas confiance au nom de
94 // fichier envoye par le browser : pour les Macs c'est plus sur)
95 $ok = deplacer_fichier_upload($source['tmp_name'], $file_tmp);
101 if (!$ok or !file_exists($file_tmp)) {
102 spip_log($erreur = "probleme de copie pour $file_tmp ");
107 $size = @getimagesize
($file_tmp);
108 $extension = !$size ?
'' : ($size[2] > 3 ?
'' : $GLOBALS['formats_logos'][$size[2] - 1]);
110 @rename
($file_tmp, $file_tmp . ".$extension");
111 $file_tmp = $file_tmp . ".$extension";
112 $poids = filesize($file_tmp);
114 if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
115 if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH
and $size[0] > _LOGO_MAX_WIDTH
)
116 or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT
and $size[1] > _LOGO_MAX_HEIGHT
)
118 $max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH
) ? _LOGO_MAX_WIDTH
: '*';
119 $max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT
) ? _LOGO_MAX_HEIGHT
: '*';
121 // pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
122 // on met directement a la taille maxi a la volee
123 if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
124 include_spip('inc/filtres');
125 $img = filtrer('image_reduire', $file_tmp, $max_width, $max_height);
126 $img = extraire_attribut($img, 'src');
127 $img = supprimer_timestamp($img);
128 if (@file_exists
($img) and $img !== $file_tmp) {
129 spip_unlink($file_tmp);
130 @rename
($img, $file_tmp);
131 $size = @getimagesize
($file_tmp);
134 // verifier au cas ou image_reduire a echoue
135 if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH
and $size[0] > _LOGO_MAX_WIDTH
)
136 or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT
and $size[1] > _LOGO_MAX_HEIGHT
)
138 spip_unlink($file_tmp);
140 'info_logo_max_poids',
144 'info_largeur_vignette',
146 'largeur_vignette' => $max_width,
147 'hauteur_vignette' => $max_height
152 'info_largeur_vignette',
154 'largeur_vignette' => $size[0],
155 'hauteur_vignette' => $size[1]
164 if (!$erreur and defined('_LOGO_MAX_SIZE') and _LOGO_MAX_SIZE
and $poids > _LOGO_MAX_SIZE
* 1024) {
165 spip_unlink($file_tmp);
167 'info_logo_max_poids',
169 'maxi' => taille_en_octets(_LOGO_MAX_SIZE
* 1024),
170 'actuel' => taille_en_octets($poids)
176 @rename
($file_tmp, _DIR_LOGOS
. $nom . ".$extension");
179 spip_unlink($file_tmp);
181 'info_logo_format_interdit',
182 array('formats' => join(', ', $GLOBALS['formats_logos']))