|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/***************************************************************************\ |
|
4
|
|
|
* SPIP, Systeme de publication pour l'internet * |
|
5
|
|
|
* * |
|
6
|
|
|
* Copyright (c) 2001-2019 * |
|
7
|
|
|
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
|
8
|
|
|
* * |
|
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
|
|
|
\***************************************************************************/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Gestion de l'API de modification/suppression des logos |
|
15
|
|
|
* |
|
16
|
|
|
* @package SPIP\Core\Logo\Edition |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) { |
|
20
|
|
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Supprimer le logo d'un objet |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $objet |
|
28
|
|
|
* @param int $id_objet |
|
29
|
|
|
* @param string $etat |
|
30
|
|
|
* `on` ou `off` |
|
31
|
|
|
*/ |
|
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'); |
|
37
|
|
|
|
|
38
|
|
|
// existe-t-il deja un logo ? |
|
39
|
|
|
$logo = $chercher_logo($id_objet, $primary, $etat); |
|
40
|
|
|
if ($logo) { |
|
41
|
|
|
# TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
42
|
|
|
if (count($logo) < 6) { |
|
43
|
|
|
spip_unlink($logo[0]); |
|
44
|
|
|
} |
|
45
|
|
|
elseif ($doc = $logo[5] |
|
46
|
|
|
and isset($doc['id_document']) |
|
47
|
|
|
and $id_document = $doc['id_document']) { |
|
48
|
|
|
|
|
49
|
|
|
include_spip('action/editer_liens'); |
|
50
|
|
|
// supprimer le lien dans la base |
|
51
|
|
|
objet_dissocier(array('document' => $id_document), array($objet => $id_objet), array('role' => '*')); |
|
52
|
|
|
|
|
53
|
|
|
// verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
54
|
|
|
$liens = objet_trouver_liens(array('document' => $id_document), '*'); |
|
55
|
|
|
if (!count($liens)) { |
|
56
|
|
|
$supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
57
|
|
|
$supprimer_document($doc['id_document']); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Modifier le logo d'un objet |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $objet |
|
67
|
|
|
* @param int $id_objet |
|
68
|
|
|
* @param string $etat |
|
69
|
|
|
* `on` ou `off` |
|
70
|
|
|
* @param string|array $source |
|
71
|
|
|
* - array : sous tableau de `$_FILE` issu de l'upload |
|
72
|
|
|
* - string : fichier source (chemin complet ou chemin relatif a `tmp/upload`) |
|
73
|
|
|
* @return string |
|
|
|
|
|
|
74
|
|
|
* Erreur, sinon '' |
|
75
|
|
|
*/ |
|
76
|
|
|
function logo_modifier($objet, $id_objet, $etat, $source) { |
|
77
|
|
|
$chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
|
|
|
|
|
78
|
|
|
$objet = objet_type($objet); |
|
79
|
|
|
$primary = id_table_objet($objet); |
|
|
|
|
|
|
80
|
|
|
include_spip('inc/chercher_logo'); |
|
81
|
|
|
|
|
82
|
|
|
$mode = preg_replace(",\W,", '', $etat); |
|
83
|
|
|
if (!$mode){ |
|
84
|
|
|
spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
85
|
|
|
$erreur = 'etat invalide'; |
|
86
|
|
|
|
|
87
|
|
|
return $erreur; |
|
88
|
|
|
} |
|
89
|
|
|
// chercher dans la base |
|
90
|
|
|
$mode_document = 'logo' . $mode; |
|
91
|
|
|
|
|
92
|
|
|
// supprimer le logo eventueel existant |
|
93
|
|
|
// TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
94
|
|
|
// mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
95
|
|
|
logo_supprimer($objet, $id_objet, $etat); |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
include_spip('inc/documents'); |
|
99
|
|
|
$erreur = ''; |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
if (!$source) { |
|
102
|
|
|
spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
103
|
|
|
$erreur = 'source inconnue'; |
|
104
|
|
|
|
|
105
|
|
|
return $erreur; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
// fichier dans upload/ |
|
109
|
|
|
if (is_string($source)) { |
|
110
|
|
|
$tmp_name = false; |
|
111
|
|
|
if (file_exists($source)) { |
|
112
|
|
|
$tmp_name = $source; |
|
113
|
|
|
} elseif (file_exists($f = determine_upload() . $source)) { |
|
114
|
|
|
$tmp_name = $f; |
|
115
|
|
|
} |
|
116
|
|
|
if (!$tmp_name) { |
|
|
|
|
|
|
117
|
|
|
spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
118
|
|
|
$erreur = 'source inconnue'; |
|
119
|
|
|
|
|
120
|
|
|
return $erreur; |
|
121
|
|
|
} |
|
122
|
|
|
$source = array( |
|
123
|
|
|
'tmp_name' => $tmp_name, |
|
124
|
|
|
'name' => basename($tmp_name), |
|
125
|
|
|
); |
|
126
|
|
|
} elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
127
|
|
|
return $erreur; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$source['mode'] = $mode_document; |
|
131
|
|
|
$ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
132
|
|
|
$ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
133
|
|
|
|
|
134
|
|
|
$id_document = reset($ajoutes); |
|
135
|
|
|
|
|
136
|
|
|
if (!is_numeric($id_document)) { |
|
137
|
|
|
$erreur = ($id_document ? $id_document : 'Erreur inconnue'); |
|
138
|
|
|
spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source), 'logo'); |
|
139
|
|
|
return $erreur; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return ''; // tout est bon, pas d'erreur |
|
143
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Convertit le type numerique retourne par getimagesize() en extension fichier |
|
149
|
|
|
* doublon de la fonction presente dans metadata/image du plugin medias |
|
150
|
|
|
* a fusionner avec les logos en documents |
|
151
|
|
|
* |
|
152
|
|
|
* @param int $type |
|
153
|
|
|
* @param bool $strict |
|
154
|
|
|
* @return string |
|
155
|
|
|
*/ |
|
156
|
|
|
// https://code.spip.net/@decoder_type_image |
|
157
|
|
|
function logo_decoder_type_image($type, $strict = false) { |
|
158
|
|
|
switch ($type) { |
|
159
|
|
|
case IMAGETYPE_GIF: |
|
160
|
|
|
return 'gif'; |
|
161
|
|
|
case IMAGETYPE_JPEG: |
|
162
|
|
|
return 'jpg'; |
|
163
|
|
|
case IMAGETYPE_PNG: |
|
164
|
|
|
return 'png'; |
|
165
|
|
|
case IMAGETYPE_SWF: |
|
166
|
|
|
return $strict ? '' : 'swf'; |
|
167
|
|
|
case IMAGETYPE_PSD: |
|
168
|
|
|
return 'psd'; |
|
169
|
|
|
case IMAGETYPE_BMP: |
|
170
|
|
|
return 'bmp'; |
|
171
|
|
|
case IMAGETYPE_TIFF_II: |
|
172
|
|
|
case IMAGETYPE_TIFF_MM: |
|
173
|
|
|
return 'tif'; |
|
174
|
|
|
case IMAGETYPE_WEBP: |
|
175
|
|
|
return 'webp'; |
|
176
|
|
|
case IMAGETYPE_SVG: |
|
177
|
|
|
return $strict ? '' : 'svg'; |
|
178
|
|
|
default: |
|
179
|
|
|
return ''; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]orarray<String>.