Completed
Push — master ( c994fa...ad8ec0 )
by cam
01:07
created
ecrire/inc/auth.php 1 patch
Indentation   +446 added lines, -446 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('base/abstract_sql');
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
  *  - une chaîne vide si autorisation à pénétrer dans l'espace privé.
36 36
  */
37 37
 function inc_auth_dist() {
38
-	$row = auth_mode();
38
+    $row = auth_mode();
39 39
 
40
-	if ($row) {
41
-		return auth_init_droits($row);
42
-	}
40
+    if ($row) {
41
+        return auth_init_droits($row);
42
+    }
43 43
 
44
-	if (!$GLOBALS['connect_login']) {
45
-		return auth_a_loger();
46
-	}
44
+    if (!$GLOBALS['connect_login']) {
45
+        return auth_a_loger();
46
+    }
47 47
 
48
-	// Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui
49
-	// C'est soit parce que la base est inutilisable,
50
-	// soit parce que la table des auteurs a changee (restauration etc)
51
-	// Pas la peine d'insister.
52
-	// Renvoyer le nom fautif et une URL de remise a zero
48
+    // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui
49
+    // C'est soit parce que la base est inutilisable,
50
+    // soit parce que la table des auteurs a changee (restauration etc)
51
+    // Pas la peine d'insister.
52
+    // Renvoyer le nom fautif et une URL de remise a zero
53 53
 
54
-	if (spip_connect()) {
55
-		return [
56
-			'login' => $GLOBALS['connect_login'],
57
-			'site' => generer_url_public('', 'action=logout&logout=prive')
58
-		];
59
-	}
54
+    if (spip_connect()) {
55
+        return [
56
+            'login' => $GLOBALS['connect_login'],
57
+            'site' => generer_url_public('', 'action=logout&logout=prive')
58
+        ];
59
+    }
60 60
 
61
-	$n = intval(sql_errno());
62
-	spip_log("Erreur base de donnees $n " . sql_error());
61
+    $n = intval(sql_errno());
62
+    spip_log("Erreur base de donnees $n " . sql_error());
63 63
 
64
-	return $n ?: 1;
64
+    return $n ?: 1;
65 65
 }
66 66
 
67 67
 /**
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function auth_controler_password_auteur_connecte(string $password): bool {
73 73
 
74
-	if (
75
-		empty($GLOBALS['visiteur_session']['id_auteur'])
76
-		or empty($GLOBALS['visiteur_session']['login'])
77
-	) {
78
-		return false;
79
-	}
80
-
81
-	$auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true);
82
-	if (
83
-		is_array($auth)
84
-		and $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur']
85
-	) {
86
-		return true;
87
-	}
88
-
89
-	return false;
74
+    if (
75
+        empty($GLOBALS['visiteur_session']['id_auteur'])
76
+        or empty($GLOBALS['visiteur_session']['login'])
77
+    ) {
78
+        return false;
79
+    }
80
+
81
+    $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true);
82
+    if (
83
+        is_array($auth)
84
+        and $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur']
85
+    ) {
86
+        return true;
87
+    }
88
+
89
+    return false;
90 90
 }
91 91
 
92 92
 /**
@@ -98,39 +98,39 @@  discard block
 block discarded – undo
98 98
  * @return array|string
99 99
  */
100 100
 function auth_echec($raison) {
101
-	include_spip('inc/minipres');
102
-	include_spip('inc/headers');
103
-	// pas authentifie. Pourquoi ?
104
-	if (is_string($raison)) {
105
-		// redirection vers une page d'authentification
106
-		// on ne revient pas de cette fonction
107
-		// sauf si pb de header
108
-		$raison = redirige_formulaire($raison);
109
-	} elseif (is_int($raison)) {
110
-		// erreur SQL a afficher
111
-		$raison = minipres(
112
-			_T('info_travaux_titre'),
113
-			_T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
114
-		);
115
-	} elseif (@$raison['statut']) {
116
-		// un simple visiteur n'a pas acces a l'espace prive
117
-		spip_log('connexion refusee a ' . @$raison['id_auteur']);
118
-		$raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur'));
119
-	} else {
120
-		// auteur en fin de droits ...
121
-		$h = $raison['site'];
122
-		$raison = minipres(
123
-			_T('avis_erreur_connexion'),
124
-			'<br /><br /><p>'
125
-			. _T('texte_inc_auth_1', ['auth_login' => $raison['login']])
126
-			. " <a href='$h'>"
127
-			. _T('texte_inc_auth_2')
128
-			. '</a>'
129
-			. _T('texte_inc_auth_3')
130
-		);
131
-	}
132
-
133
-	return $raison;
101
+    include_spip('inc/minipres');
102
+    include_spip('inc/headers');
103
+    // pas authentifie. Pourquoi ?
104
+    if (is_string($raison)) {
105
+        // redirection vers une page d'authentification
106
+        // on ne revient pas de cette fonction
107
+        // sauf si pb de header
108
+        $raison = redirige_formulaire($raison);
109
+    } elseif (is_int($raison)) {
110
+        // erreur SQL a afficher
111
+        $raison = minipres(
112
+            _T('info_travaux_titre'),
113
+            _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
114
+        );
115
+    } elseif (@$raison['statut']) {
116
+        // un simple visiteur n'a pas acces a l'espace prive
117
+        spip_log('connexion refusee a ' . @$raison['id_auteur']);
118
+        $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur'));
119
+    } else {
120
+        // auteur en fin de droits ...
121
+        $h = $raison['site'];
122
+        $raison = minipres(
123
+            _T('avis_erreur_connexion'),
124
+            '<br /><br /><p>'
125
+            . _T('texte_inc_auth_1', ['auth_login' => $raison['login']])
126
+            . " <a href='$h'>"
127
+            . _T('texte_inc_auth_2')
128
+            . '</a>'
129
+            . _T('texte_inc_auth_3')
130
+        );
131
+    }
132
+
133
+    return $raison;
134 134
 }
135 135
 
136 136
 /**
@@ -140,81 +140,81 @@  discard block
 block discarded – undo
140 140
  * @return array|bool|string
141 141
  */
142 142
 function auth_mode() {
143
-	//
144
-	// Initialiser variables (eviter hacks par URL)
145
-	//
146
-	$GLOBALS['connect_login'] = '';
147
-	$id_auteur = null;
148
-	$GLOBALS['auth_can_disconnect'] = false;
149
-
150
-	//
151
-	// Recuperer les donnees d'identification
152
-	//
153
-	include_spip('inc/session');
154
-	// Session valide en cours ?
155
-	if (isset($_COOKIE['spip_session'])) {
156
-		$session = charger_fonction('session', 'inc');
157
-		if (
158
-			$id_auteur = $session()
159
-			or $id_auteur === 0 // reprise sur restauration
160
-		) {
161
-			$GLOBALS['auth_can_disconnect'] = true;
162
-			$GLOBALS['connect_login'] = session_get('login');
163
-		} else {
164
-			unset($_COOKIE['spip_session']);
165
-		}
166
-	}
167
-
168
-	// Essayer auth http si significatif
169
-	// (ignorer les login d'intranet independants de spip)
170
-	if (!$GLOBALS['ignore_auth_http']) {
171
-		if (
172
-			(isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW'])
173
-				and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
174
-			or
175
-			// Si auth http differtente de basic, PHP_AUTH_PW
176
-			// est indisponible mais tentons quand meme pour
177
-			// autocreation via LDAP
178
-			(isset($_SERVER['REMOTE_USER'])
179
-				and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], ''))
180
-		) {
181
-			if (!$id_auteur) {
182
-				$_SERVER['PHP_AUTH_PW'] = '';
183
-				$GLOBALS['auth_can_disconnect'] = true;
184
-				$GLOBALS['visiteur_session'] = $r;
185
-				$GLOBALS['connect_login'] = session_get('login');
186
-				$id_auteur = $r['id_auteur'];
187
-			} else {
188
-				// cas de la session en plus de PHP_AUTH
189
-				/*				  if ($id_auteur != $r['id_auteur']){
143
+    //
144
+    // Initialiser variables (eviter hacks par URL)
145
+    //
146
+    $GLOBALS['connect_login'] = '';
147
+    $id_auteur = null;
148
+    $GLOBALS['auth_can_disconnect'] = false;
149
+
150
+    //
151
+    // Recuperer les donnees d'identification
152
+    //
153
+    include_spip('inc/session');
154
+    // Session valide en cours ?
155
+    if (isset($_COOKIE['spip_session'])) {
156
+        $session = charger_fonction('session', 'inc');
157
+        if (
158
+            $id_auteur = $session()
159
+            or $id_auteur === 0 // reprise sur restauration
160
+        ) {
161
+            $GLOBALS['auth_can_disconnect'] = true;
162
+            $GLOBALS['connect_login'] = session_get('login');
163
+        } else {
164
+            unset($_COOKIE['spip_session']);
165
+        }
166
+    }
167
+
168
+    // Essayer auth http si significatif
169
+    // (ignorer les login d'intranet independants de spip)
170
+    if (!$GLOBALS['ignore_auth_http']) {
171
+        if (
172
+            (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW'])
173
+                and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
174
+            or
175
+            // Si auth http differtente de basic, PHP_AUTH_PW
176
+            // est indisponible mais tentons quand meme pour
177
+            // autocreation via LDAP
178
+            (isset($_SERVER['REMOTE_USER'])
179
+                and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], ''))
180
+        ) {
181
+            if (!$id_auteur) {
182
+                $_SERVER['PHP_AUTH_PW'] = '';
183
+                $GLOBALS['auth_can_disconnect'] = true;
184
+                $GLOBALS['visiteur_session'] = $r;
185
+                $GLOBALS['connect_login'] = session_get('login');
186
+                $id_auteur = $r['id_auteur'];
187
+            } else {
188
+                // cas de la session en plus de PHP_AUTH
189
+                /*				  if ($id_auteur != $r['id_auteur']){
190 190
 					spip_log("vol de session $id_auteur" . join(', ', $r));
191 191
 				unset($_COOKIE['spip_session']);
192 192
 				$id_auteur = '';
193 193
 				} */
194
-			}
195
-		} else {
196
-			// Authentification .htaccess old style, car .htaccess semble
197
-			// souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW
198
-			if (isset($_SERVER['REMOTE_USER'])) {
199
-				$GLOBALS['connect_login'] = $_SERVER['REMOTE_USER'];
200
-			}
201
-		}
202
-	}
203
-
204
-	$where = (is_numeric($id_auteur)
205
-		/*AND $id_auteur>0*/ // reprise lors des restaurations
206
-	) ?
207
-		"id_auteur=$id_auteur" :
208
-		(!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text'));
209
-
210
-	if (!$where) {
211
-		return '';
212
-	}
213
-
214
-	// Trouver les autres infos dans la table auteurs.
215
-	// le champ 'quand' est utilise par l'agenda
216
-
217
-	return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'");
194
+            }
195
+        } else {
196
+            // Authentification .htaccess old style, car .htaccess semble
197
+            // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW
198
+            if (isset($_SERVER['REMOTE_USER'])) {
199
+                $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER'];
200
+            }
201
+        }
202
+    }
203
+
204
+    $where = (is_numeric($id_auteur)
205
+        /*AND $id_auteur>0*/ // reprise lors des restaurations
206
+    ) ?
207
+        "id_auteur=$id_auteur" :
208
+        (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text'));
209
+
210
+    if (!$where) {
211
+        return '';
212
+    }
213
+
214
+    // Trouver les autres infos dans la table auteurs.
215
+    // le champ 'quand' est utilise par l'agenda
216
+
217
+    return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'");
218 218
 }
219 219
 
220 220
 /**
@@ -232,86 +232,86 @@  discard block
 block discarded – undo
232 232
  */
233 233
 function auth_init_droits($row) {
234 234
 
235
-	include_spip('inc/autoriser');
236
-	if (!autoriser('loger', '', 0, $row)) {
237
-		return false;
238
-	}
239
-
240
-
241
-	if ($row['statut'] == 'nouveau') {
242
-		include_spip('action/inscrire_auteur');
243
-		$row = confirmer_statut_inscription($row);
244
-	}
245
-
246
-	$GLOBALS['connect_id_auteur'] = $row['id_auteur'];
247
-	$GLOBALS['connect_login'] = $row['login'];
248
-	$GLOBALS['connect_statut'] = $row['statut'];
249
-
250
-	$GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row);
251
-
252
-	// au cas ou : ne pas memoriser les champs sensibles
253
-	unset($GLOBALS['visiteur_session']['pass']);
254
-	unset($GLOBALS['visiteur_session']['htpass']);
255
-	unset($GLOBALS['visiteur_session']['alea_actuel']);
256
-	unset($GLOBALS['visiteur_session']['alea_futur']);
257
-	unset($GLOBALS['visiteur_session']['ldap_password']);
258
-
259
-	// creer la session au besoin
260
-	if (!isset($_COOKIE['spip_session'])) {
261
-		$session = charger_fonction('session', 'inc');
262
-		$spip_session = $session($row);
263
-	}
264
-
265
-	// reinjecter les preferences_auteur apres le reset de spip_session
266
-	// car utilisees au retour par auth_loger()
267
-	$r = @unserialize($row['prefs']);
268
-	$GLOBALS['visiteur_session']['prefs'] = ($r ?: []);
269
-	// si prefs pas definies, les definir par defaut
270
-	if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) {
271
-		$GLOBALS['visiteur_session']['prefs']['couleur'] = 2;
272
-		$GLOBALS['visiteur_session']['prefs']['display'] = 2;
273
-		$GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones';
274
-		$GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui';
275
-	}
276
-
277
-	$GLOBALS['visiteur_session'] = pipeline(
278
-		'preparer_visiteur_session',
279
-		['args' => ['row' => $row],
280
-		'data' => $GLOBALS['visiteur_session']]
281
-	);
282
-
283
-	// Etablir les droits selon le codage attendu
284
-	// dans ecrire/index.php ecrire/prive.php
285
-
286
-	// Pas autorise a acceder a ecrire ? renvoyer le tableau
287
-	// A noter : le premier appel a autoriser() a le bon gout
288
-	// d'initialiser $GLOBALS['visiteur_session']['restreint'],
289
-	// qui ne figure pas dans le fichier de session
290
-
291
-	if (!autoriser('ecrire')) {
292
-		return $row;
293
-	}
294
-
295
-	// autoriser('ecrire') ne laisse passer que les Admin et les Redac
296
-
297
-	auth_trace($row);
298
-
299
-	// Administrateurs
300
-	if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) {
301
-		if (
302
-			isset($GLOBALS['visiteur_session']['restreint'])
303
-			and is_array($GLOBALS['visiteur_session']['restreint'])
304
-		) {
305
-			$GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint'];
306
-		}
307
-		if ($GLOBALS['connect_statut'] == '0minirezo') {
308
-			$GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique'];
309
-		}
310
-	}
311
-
312
-	// Pour les redacteurs, inc_version a fait l'initialisation minimale
313
-
314
-	return ''; // i.e. pas de pb.
235
+    include_spip('inc/autoriser');
236
+    if (!autoriser('loger', '', 0, $row)) {
237
+        return false;
238
+    }
239
+
240
+
241
+    if ($row['statut'] == 'nouveau') {
242
+        include_spip('action/inscrire_auteur');
243
+        $row = confirmer_statut_inscription($row);
244
+    }
245
+
246
+    $GLOBALS['connect_id_auteur'] = $row['id_auteur'];
247
+    $GLOBALS['connect_login'] = $row['login'];
248
+    $GLOBALS['connect_statut'] = $row['statut'];
249
+
250
+    $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row);
251
+
252
+    // au cas ou : ne pas memoriser les champs sensibles
253
+    unset($GLOBALS['visiteur_session']['pass']);
254
+    unset($GLOBALS['visiteur_session']['htpass']);
255
+    unset($GLOBALS['visiteur_session']['alea_actuel']);
256
+    unset($GLOBALS['visiteur_session']['alea_futur']);
257
+    unset($GLOBALS['visiteur_session']['ldap_password']);
258
+
259
+    // creer la session au besoin
260
+    if (!isset($_COOKIE['spip_session'])) {
261
+        $session = charger_fonction('session', 'inc');
262
+        $spip_session = $session($row);
263
+    }
264
+
265
+    // reinjecter les preferences_auteur apres le reset de spip_session
266
+    // car utilisees au retour par auth_loger()
267
+    $r = @unserialize($row['prefs']);
268
+    $GLOBALS['visiteur_session']['prefs'] = ($r ?: []);
269
+    // si prefs pas definies, les definir par defaut
270
+    if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) {
271
+        $GLOBALS['visiteur_session']['prefs']['couleur'] = 2;
272
+        $GLOBALS['visiteur_session']['prefs']['display'] = 2;
273
+        $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones';
274
+        $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui';
275
+    }
276
+
277
+    $GLOBALS['visiteur_session'] = pipeline(
278
+        'preparer_visiteur_session',
279
+        ['args' => ['row' => $row],
280
+        'data' => $GLOBALS['visiteur_session']]
281
+    );
282
+
283
+    // Etablir les droits selon le codage attendu
284
+    // dans ecrire/index.php ecrire/prive.php
285
+
286
+    // Pas autorise a acceder a ecrire ? renvoyer le tableau
287
+    // A noter : le premier appel a autoriser() a le bon gout
288
+    // d'initialiser $GLOBALS['visiteur_session']['restreint'],
289
+    // qui ne figure pas dans le fichier de session
290
+
291
+    if (!autoriser('ecrire')) {
292
+        return $row;
293
+    }
294
+
295
+    // autoriser('ecrire') ne laisse passer que les Admin et les Redac
296
+
297
+    auth_trace($row);
298
+
299
+    // Administrateurs
300
+    if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) {
301
+        if (
302
+            isset($GLOBALS['visiteur_session']['restreint'])
303
+            and is_array($GLOBALS['visiteur_session']['restreint'])
304
+        ) {
305
+            $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint'];
306
+        }
307
+        if ($GLOBALS['connect_statut'] == '0minirezo') {
308
+            $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique'];
309
+        }
310
+    }
311
+
312
+    // Pour les redacteurs, inc_version a fait l'initialisation minimale
313
+
314
+    return ''; // i.e. pas de pb.
315 315
 }
316 316
 
317 317
 /**
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
  * @return string
321 321
  */
322 322
 function auth_a_loger() {
323
-	$redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), true);
324
-
325
-	// un echec au "bonjour" (login initial) quand le statut est
326
-	// inconnu signale sans doute un probleme de cookies
327
-	if (isset($_GET['bonjour'])) {
328
-		$redirect = parametre_url(
329
-			$redirect,
330
-			'var_erreur',
331
-			(!isset($GLOBALS['visiteur_session']['statut'])
332
-				? 'cookie'
333
-				: 'statut'
334
-			),
335
-			'&'
336
-		);
337
-	}
338
-
339
-	return $redirect;
323
+    $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), true);
324
+
325
+    // un echec au "bonjour" (login initial) quand le statut est
326
+    // inconnu signale sans doute un probleme de cookies
327
+    if (isset($_GET['bonjour'])) {
328
+        $redirect = parametre_url(
329
+            $redirect,
330
+            'var_erreur',
331
+            (!isset($GLOBALS['visiteur_session']['statut'])
332
+                ? 'cookie'
333
+                : 'statut'
334
+            ),
335
+            '&'
336
+        );
337
+    }
338
+
339
+    return $redirect;
340 340
 }
341 341
 
342 342
 /**
@@ -348,19 +348,19 @@  discard block
 block discarded – undo
348 348
  * @param null|string $date
349 349
  */
350 350
 function auth_trace($row, $date = null) {
351
-	// Indiquer la connexion. A la minute pres ca suffit.
352
-	if (!is_numeric($connect_quand = $row['quand'] ?? '')) {
353
-		$connect_quand = strtotime($connect_quand);
354
-	}
351
+    // Indiquer la connexion. A la minute pres ca suffit.
352
+    if (!is_numeric($connect_quand = $row['quand'] ?? '')) {
353
+        $connect_quand = strtotime($connect_quand);
354
+    }
355 355
 
356
-	$date ??= date('Y-m-d H:i:s');
356
+    $date ??= date('Y-m-d H:i:s');
357 357
 
358
-	if (abs(strtotime($date) - $connect_quand) >= 60) {
359
-		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur']));
360
-		$row['en_ligne'] = $date;
361
-	}
358
+    if (abs(strtotime($date) - $connect_quand) >= 60) {
359
+        sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur']));
360
+        $row['en_ligne'] = $date;
361
+    }
362 362
 
363
-	pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]);
363
+    pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]);
364 364
 }
365 365
 
366 366
 
@@ -386,28 +386,28 @@  discard block
 block discarded – undo
386 386
  * @return mixed
387 387
  */
388 388
 function auth_administrer($fonction, $args, $defaut = false) {
389
-	$auth_methode = array_shift($args);
390
-	$auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou
391
-	if (
392
-		$auth = charger_fonction($auth_methode, 'auth', true)
393
-		and function_exists($f = "auth_{$auth_methode}_$fonction")
394
-	) {
395
-		$res = $f(...$args);
396
-	} else {
397
-		$res = $defaut;
398
-	}
399
-	$res = pipeline(
400
-		'auth_administrer',
401
-		[
402
-			'args' => [
403
-				'fonction' => $fonction,
404
-				'methode' => $auth_methode,
405
-				'args' => $args
406
-			],
407
-			'data' => $res
408
-		]
409
-	);
410
-	return $res;
389
+    $auth_methode = array_shift($args);
390
+    $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou
391
+    if (
392
+        $auth = charger_fonction($auth_methode, 'auth', true)
393
+        and function_exists($f = "auth_{$auth_methode}_$fonction")
394
+    ) {
395
+        $res = $f(...$args);
396
+    } else {
397
+        $res = $defaut;
398
+    }
399
+    $res = pipeline(
400
+        'auth_administrer',
401
+        [
402
+            'args' => [
403
+                'fonction' => $fonction,
404
+                'methode' => $auth_methode,
405
+                'args' => $args
406
+            ],
407
+            'data' => $res
408
+        ]
409
+    );
410
+    return $res;
411 411
 }
412 412
 
413 413
 /**
@@ -417,11 +417,11 @@  discard block
 block discarded – undo
417 417
  * @return array
418 418
  */
419 419
 function auth_formulaire_login($flux) {
420
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
421
-		$flux = auth_administrer('formulaire_login', [$methode, $flux], $flux);
422
-	}
420
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
421
+        $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux);
422
+    }
423 423
 
424
-	return $flux;
424
+    return $flux;
425 425
 }
426 426
 
427 427
 
@@ -435,19 +435,19 @@  discard block
 block discarded – undo
435 435
  * @return string/bool
436 436
  */
437 437
 function auth_retrouver_login($login, $serveur = '') {
438
-	if (!spip_connect($serveur)) {
439
-		include_spip('inc/minipres');
440
-		echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
441
-		exit;
442
-	}
443
-
444
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
445
-		if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) {
446
-			return $auteur;
447
-		}
448
-	}
449
-
450
-	return false;
438
+    if (!spip_connect($serveur)) {
439
+        include_spip('inc/minipres');
440
+        echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
441
+        exit;
442
+    }
443
+
444
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
445
+        if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) {
446
+            return $auteur;
447
+        }
448
+    }
449
+
450
+    return false;
451 451
 }
452 452
 
453 453
 /**
@@ -462,34 +462,34 @@  discard block
 block discarded – undo
462 462
  * @return array
463 463
  */
464 464
 function auth_informer_login($login, $serveur = '') {
465
-	if (
466
-		!$login
467
-		or !$login_base = auth_retrouver_login($login, $serveur)
468
-		or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur)
469
-	) {
470
-		// generer de fausses infos, mais credibles, pour eviter une attaque
471
-		// https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
472
-
473
-		$row = [
474
-			'login' => $login,
475
-			'cnx' => '0',
476
-			'logo' => '',
477
-		];
478
-
479
-		return $row;
480
-	}
481
-
482
-	$prefs = @unserialize($row['prefs']);
483
-	$infos = [
484
-		'id_auteur' => $row['id_auteur'],
485
-		'login' => $row['login'],
486
-		'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0',
487
-		'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row),
488
-	];
489
-
490
-	verifier_visiteur();
491
-
492
-	return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos);
465
+    if (
466
+        !$login
467
+        or !$login_base = auth_retrouver_login($login, $serveur)
468
+        or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur)
469
+    ) {
470
+        // generer de fausses infos, mais credibles, pour eviter une attaque
471
+        // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
472
+
473
+        $row = [
474
+            'login' => $login,
475
+            'cnx' => '0',
476
+            'logo' => '',
477
+        ];
478
+
479
+        return $row;
480
+    }
481
+
482
+    $prefs = @unserialize($row['prefs']);
483
+    $infos = [
484
+        'id_auteur' => $row['id_auteur'],
485
+        'login' => $row['login'],
486
+        'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0',
487
+        'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row),
488
+    ];
489
+
490
+    verifier_visiteur();
491
+
492
+    return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos);
493 493
 }
494 494
 
495 495
 
@@ -503,21 +503,21 @@  discard block
 block discarded – undo
503 503
  * @return mixed
504 504
  */
505 505
 function auth_identifier_login($login, $password, $serveur = '', bool $phpauth = false) {
506
-	$erreur = '';
507
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
508
-		if ($auth = charger_fonction($methode, 'auth', true)) {
509
-			$auteur = $auth($login, $password, $serveur, $phpauth);
510
-			if (is_array($auteur) and count($auteur)) {
511
-				spip_log("connexion de $login par methode $methode");
512
-				$auteur['auth'] = $methode;
513
-				return $auteur;
514
-			} elseif (is_string($auteur)) {
515
-				$erreur .= "$auteur ";
516
-			}
517
-		}
518
-	}
519
-
520
-	return $erreur;
506
+    $erreur = '';
507
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
508
+        if ($auth = charger_fonction($methode, 'auth', true)) {
509
+            $auteur = $auth($login, $password, $serveur, $phpauth);
510
+            if (is_array($auteur) and count($auteur)) {
511
+                spip_log("connexion de $login par methode $methode");
512
+                $auteur['auth'] = $methode;
513
+                return $auteur;
514
+            } elseif (is_string($auteur)) {
515
+                $erreur .= "$auteur ";
516
+            }
517
+        }
518
+    }
519
+
520
+    return $erreur;
521 521
 }
522 522
 
523 523
 /**
@@ -531,8 +531,8 @@  discard block
 block discarded – undo
531 531
  * @return string
532 532
  */
533 533
 function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') {
534
-	$securiser_action = charger_fonction('securiser_action', 'inc');
535
-	return $securiser_action('auth', "$auth_methode/$login", $redirect, true);
534
+    $securiser_action = charger_fonction('securiser_action', 'inc');
535
+    return $securiser_action('auth', "$auth_methode/$login", $redirect, true);
536 536
 }
537 537
 
538 538
 /**
@@ -546,9 +546,9 @@  discard block
 block discarded – undo
546 546
  * @return mixed
547 547
  */
548 548
 function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') {
549
-	$args = func_get_args();
550
-	$auteur = auth_administrer('terminer_identifier_login', $args);
551
-	return $auteur;
549
+    $args = func_get_args();
550
+    $auteur = auth_administrer('terminer_identifier_login', $args);
551
+    return $auteur;
552 552
 }
553 553
 
554 554
 /**
@@ -558,29 +558,29 @@  discard block
 block discarded – undo
558 558
  * @return bool
559 559
  */
560 560
 function auth_loger($auteur) {
561
-	if (!is_array($auteur) or !count($auteur)) {
562
-		return false;
563
-	}
564
-
565
-	// initialiser et poser le cookie de session
566
-	unset($_COOKIE['spip_session']);
567
-	if (auth_init_droits($auteur) === false) {
568
-		return false;
569
-	}
570
-
571
-	// initialiser les prefs
572
-	$p = $GLOBALS['visiteur_session']['prefs'];
573
-	$p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : '';
574
-
575
-	sql_updateq(
576
-		'spip_auteurs',
577
-		['prefs' => serialize($p)],
578
-		'id_auteur=' . intval($auteur['id_auteur'])
579
-	);
580
-
581
-	//  bloquer ici le visiteur qui tente d'abuser de ses droits
582
-	verifier_visiteur();
583
-	return true;
561
+    if (!is_array($auteur) or !count($auteur)) {
562
+        return false;
563
+    }
564
+
565
+    // initialiser et poser le cookie de session
566
+    unset($_COOKIE['spip_session']);
567
+    if (auth_init_droits($auteur) === false) {
568
+        return false;
569
+    }
570
+
571
+    // initialiser les prefs
572
+    $p = $GLOBALS['visiteur_session']['prefs'];
573
+    $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : '';
574
+
575
+    sql_updateq(
576
+        'spip_auteurs',
577
+        ['prefs' => serialize($p)],
578
+        'id_auteur=' . intval($auteur['id_auteur'])
579
+    );
580
+
581
+    //  bloquer ici le visiteur qui tente d'abuser de ses droits
582
+    verifier_visiteur();
583
+    return true;
584 584
 }
585 585
 
586 586
 /**
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
  * return void
591 591
  **/
592 592
 function auth_deloger() {
593
-	$logout = charger_fonction('logout', 'action');
594
-	$logout();
593
+    $logout = charger_fonction('logout', 'action');
594
+    $logout();
595 595
 }
596 596
 
597 597
 /**
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
  * @return bool
606 606
  */
607 607
 function auth_autoriser_modifier_login($auth_methode, $serveur = '') {
608
-	$args = func_get_args();
609
-	return auth_administrer('autoriser_modifier_login', $args);
608
+    $args = func_get_args();
609
+    return auth_administrer('autoriser_modifier_login', $args);
610 610
 }
611 611
 
612 612
 /**
@@ -621,8 +621,8 @@  discard block
 block discarded – undo
621 621
  *  message d'erreur ou chaine vide si pas d'erreur
622 622
  */
623 623
 function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') {
624
-	$args = func_get_args();
625
-	return auth_administrer('verifier_login', $args, '');
624
+    $args = func_get_args();
625
+    return auth_administrer('verifier_login', $args, '');
626 626
 }
627 627
 
628 628
 /**
@@ -635,8 +635,8 @@  discard block
 block discarded – undo
635 635
  * @return bool
636 636
  */
637 637
 function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') {
638
-	$args = func_get_args();
639
-	return auth_administrer('modifier_login', $args);
638
+    $args = func_get_args();
639
+    return auth_administrer('modifier_login', $args);
640 640
 }
641 641
 
642 642
 /**
@@ -651,8 +651,8 @@  discard block
 block discarded – undo
651 651
  *  succès ou échec
652 652
  */
653 653
 function auth_autoriser_modifier_pass($auth_methode, $serveur = '') {
654
-	$args = func_get_args();
655
-	return auth_administrer('autoriser_modifier_pass', $args);
654
+    $args = func_get_args();
655
+    return auth_administrer('autoriser_modifier_pass', $args);
656 656
 }
657 657
 
658 658
 /**
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
  *  message d'erreur ou chaine vide si pas d'erreur
669 669
  */
670 670
 function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur = 0, $serveur = '') {
671
-	$args = func_get_args();
672
-	return auth_administrer('verifier_pass', $args, '');
671
+    $args = func_get_args();
672
+    return auth_administrer('verifier_pass', $args, '');
673 673
 }
674 674
 
675 675
 /**
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
  *  succes ou echec
686 686
  */
687 687
 function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur = '') {
688
-	$args = func_get_args();
689
-	return auth_administrer('modifier_pass', $args);
688
+    $args = func_get_args();
689
+    return auth_administrer('modifier_pass', $args);
690 690
 }
691 691
 
692 692
 /**
@@ -702,24 +702,24 @@  discard block
 block discarded – undo
702 702
  * @return void
703 703
  */
704 704
 function auth_synchroniser_distant(
705
-	$auth_methode = true,
706
-	$id_auteur = 0,
707
-	$champs = [],
708
-	$options = [],
709
-	$serveur = ''
705
+    $auth_methode = true,
706
+    $id_auteur = 0,
707
+    $champs = [],
708
+    $options = [],
709
+    $serveur = ''
710 710
 ) {
711
-	$args = func_get_args();
712
-	if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) {
713
-		$options['all'] = true; // ajouter une option all=>true pour chaque auth
714
-		$args = [true, $id_auteur, $champs, $options, $serveur];
715
-		foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
716
-			array_shift($args);
717
-			array_unshift($args, $methode);
718
-			auth_administrer('synchroniser_distant', $args);
719
-		}
720
-	} else {
721
-		auth_administrer('synchroniser_distant', $args);
722
-	}
711
+    $args = func_get_args();
712
+    if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) {
713
+        $options['all'] = true; // ajouter une option all=>true pour chaque auth
714
+        $args = [true, $id_auteur, $champs, $options, $serveur];
715
+        foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
716
+            array_shift($args);
717
+            array_unshift($args, $methode);
718
+            auth_administrer('synchroniser_distant', $args);
719
+        }
720
+    } else {
721
+        auth_administrer('synchroniser_distant', $args);
722
+    }
723 723
 }
724 724
 
725 725
 
@@ -732,45 +732,45 @@  discard block
 block discarded – undo
732 732
  * @return array|bool
733 733
  */
734 734
 function lire_php_auth($login, $pw, $serveur = '') {
735
-	if (
736
-		!$login
737
-		or !$login = auth_retrouver_login($login, $serveur)
738
-	) {
739
-		return false;
740
-	}
741
-
742
-	$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur);
743
-
744
-	if (!$row) {
745
-		if (
746
-			include_spip('inc/auth')
747
-			and auth_ldap_connect($serveur)
748
-			and $auth_ldap = charger_fonction('ldap', 'auth', true)
749
-		) {
750
-			return $auth_ldap($login, $pw, $serveur, true);
751
-		}
752
-
753
-		return false;
754
-	}
755
-	// su pas de source definie
756
-	// ou auth/xxx introuvable, utiliser 'spip'
757
-	if (
758
-		!$auth_methode = $row['source']
759
-		or !$auth = charger_fonction($auth_methode, 'auth', true)
760
-	) {
761
-		$auth = charger_fonction('spip', 'auth', true);
762
-	}
763
-
764
-	$auteur = '';
765
-	if ($auth) {
766
-		$auteur = $auth($login, $pw, $serveur, true);
767
-	}
768
-	// verifier que ce n'est pas un message d'erreur
769
-	if (is_array($auteur) and count($auteur)) {
770
-		return $auteur;
771
-	}
772
-
773
-	return false;
735
+    if (
736
+        !$login
737
+        or !$login = auth_retrouver_login($login, $serveur)
738
+    ) {
739
+        return false;
740
+    }
741
+
742
+    $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur);
743
+
744
+    if (!$row) {
745
+        if (
746
+            include_spip('inc/auth')
747
+            and auth_ldap_connect($serveur)
748
+            and $auth_ldap = charger_fonction('ldap', 'auth', true)
749
+        ) {
750
+            return $auth_ldap($login, $pw, $serveur, true);
751
+        }
752
+
753
+        return false;
754
+    }
755
+    // su pas de source definie
756
+    // ou auth/xxx introuvable, utiliser 'spip'
757
+    if (
758
+        !$auth_methode = $row['source']
759
+        or !$auth = charger_fonction($auth_methode, 'auth', true)
760
+    ) {
761
+        $auth = charger_fonction('spip', 'auth', true);
762
+    }
763
+
764
+    $auteur = '';
765
+    if ($auth) {
766
+        $auteur = $auth($login, $pw, $serveur, true);
767
+    }
768
+    // verifier que ce n'est pas un message d'erreur
769
+    if (is_array($auteur) and count($auteur)) {
770
+        return $auteur;
771
+    }
772
+
773
+    return false;
774 774
 }
775 775
 
776 776
 /**
@@ -786,21 +786,21 @@  discard block
 block discarded – undo
786 786
  * @param string $lien
787 787
  */
788 788
 function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') {
789
-	@Header('WWW-Authenticate: Basic realm="espace prive"');
790
-	@Header('HTTP/1.0 401 Unauthorized');
791
-	$corps = '';
792
-	$public = generer_url_public();
793
-	$ecrire = generer_url_ecrire();
794
-	$retour = $retour ?: _T('icone_retour');
795
-	$corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
796
-	if ($url) {
797
-		$corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
798
-	}
799
-
800
-	if ($lien) {
801
-		$corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
802
-	}
803
-	include_spip('inc/minipres');
804
-	echo minipres($pb, $corps);
805
-	exit;
789
+    @Header('WWW-Authenticate: Basic realm="espace prive"');
790
+    @Header('HTTP/1.0 401 Unauthorized');
791
+    $corps = '';
792
+    $public = generer_url_public();
793
+    $ecrire = generer_url_ecrire();
794
+    $retour = $retour ?: _T('icone_retour');
795
+    $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
796
+    if ($url) {
797
+        $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
798
+    }
799
+
800
+    if ($lien) {
801
+        $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
802
+    }
803
+    include_spip('inc/minipres');
804
+    echo minipres($pb, $corps);
805
+    exit;
806 806
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 2 patches
Indentation   +1326 added lines, -1326 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$couleur = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,59 +120,59 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$H = null;
124
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
-	$var_G = ($G / 255);
126
-	$var_B = ($B / 255);
127
-
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
131
-
132
-	$L = ($var_Max + $var_Min) / 2;
133
-
134
-	if ($del_Max == 0) {
135
-		//This is a gray, no chroma...
136
-		$H = 0; //HSL results = 0 ÷ 1
137
-		$S = 0;
138
-	} else {
139
-		// Chromatic data...
140
-		if ($L < 0.5) {
141
-			$S = $del_Max / ($var_Max + $var_Min);
142
-		} else {
143
-			$S = $del_Max / (2 - $var_Max - $var_Min);
144
-		}
145
-
146
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
147
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
148
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
149
-
150
-		if ($var_R == $var_Max) {
151
-			$H = $del_B - $del_G;
152
-		} else {
153
-			if ($var_G == $var_Max) {
154
-				$H = (1 / 3) + $del_R - $del_B;
155
-			} else {
156
-				if ($var_B == $var_Max) {
157
-					$H = (2 / 3) + $del_G - $del_R;
158
-				}
159
-			}
160
-		}
161
-
162
-		if ($H < 0) {
163
-			$H += 1;
164
-		}
165
-		if ($H > 1) {
166
-			$H -= 1;
167
-		}
168
-	}
169
-
170
-	$ret = [];
171
-	$ret['h'] = $H;
172
-	$ret['s'] = $S;
173
-	$ret['l'] = $L;
174
-
175
-	return $ret;
123
+    $H = null;
124
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
+    $var_G = ($G / 255);
126
+    $var_B = ($B / 255);
127
+
128
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
131
+
132
+    $L = ($var_Max + $var_Min) / 2;
133
+
134
+    if ($del_Max == 0) {
135
+        //This is a gray, no chroma...
136
+        $H = 0; //HSL results = 0 ÷ 1
137
+        $S = 0;
138
+    } else {
139
+        // Chromatic data...
140
+        if ($L < 0.5) {
141
+            $S = $del_Max / ($var_Max + $var_Min);
142
+        } else {
143
+            $S = $del_Max / (2 - $var_Max - $var_Min);
144
+        }
145
+
146
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
147
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
148
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
149
+
150
+        if ($var_R == $var_Max) {
151
+            $H = $del_B - $del_G;
152
+        } else {
153
+            if ($var_G == $var_Max) {
154
+                $H = (1 / 3) + $del_R - $del_B;
155
+            } else {
156
+                if ($var_B == $var_Max) {
157
+                    $H = (2 / 3) + $del_G - $del_R;
158
+                }
159
+            }
160
+        }
161
+
162
+        if ($H < 0) {
163
+            $H += 1;
164
+        }
165
+        if ($H > 1) {
166
+            $H -= 1;
167
+        }
168
+    }
169
+
170
+    $ret = [];
171
+    $ret['h'] = $H;
172
+    $ret['s'] = $S;
173
+    $ret['l'] = $L;
174
+
175
+    return $ret;
176 176
 }
177 177
 
178 178
 
@@ -188,52 +188,52 @@  discard block
 block discarded – undo
188 188
  * @return array
189 189
  */
190 190
 function _couleur_hsl_to_rgb($H, $S, $L) {
191
-	// helper
192
-	$hue_2_rgb = function ($v1, $v2, $vH) {
193
-		if ($vH < 0) {
194
-			$vH += 1;
195
-		}
196
-		if ($vH > 1) {
197
-			$vH -= 1;
198
-		}
199
-		if ((6 * $vH) < 1) {
200
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
201
-		}
202
-		if ((2 * $vH) < 1) {
203
-			return ($v2);
204
-		}
205
-		if ((3 * $vH) < 2) {
206
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
207
-		}
208
-
209
-		return ($v1);
210
-	};
211
-
212
-	if ($S == 0) {
213
-		// HSV values = 0 -> 1
214
-		$R = $L * 255;
215
-		$G = $L * 255;
216
-		$B = $L * 255;
217
-	} else {
218
-		if ($L < 0.5) {
219
-			$var_2 = $L * (1 + $S);
220
-		} else {
221
-			$var_2 = ($L + $S) - ($S * $L);
222
-		}
223
-
224
-		$var_1 = 2 * $L - $var_2;
225
-
226
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
227
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
228
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
229
-	}
230
-
231
-	$ret = [];
232
-	$ret['r'] = floor($R);
233
-	$ret['g'] = floor($G);
234
-	$ret['b'] = floor($B);
235
-
236
-	return $ret;
191
+    // helper
192
+    $hue_2_rgb = function ($v1, $v2, $vH) {
193
+        if ($vH < 0) {
194
+            $vH += 1;
195
+        }
196
+        if ($vH > 1) {
197
+            $vH -= 1;
198
+        }
199
+        if ((6 * $vH) < 1) {
200
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
201
+        }
202
+        if ((2 * $vH) < 1) {
203
+            return ($v2);
204
+        }
205
+        if ((3 * $vH) < 2) {
206
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
207
+        }
208
+
209
+        return ($v1);
210
+    };
211
+
212
+    if ($S == 0) {
213
+        // HSV values = 0 -> 1
214
+        $R = $L * 255;
215
+        $G = $L * 255;
216
+        $B = $L * 255;
217
+    } else {
218
+        if ($L < 0.5) {
219
+            $var_2 = $L * (1 + $S);
220
+        } else {
221
+            $var_2 = ($L + $S) - ($S * $L);
222
+        }
223
+
224
+        $var_1 = 2 * $L - $var_2;
225
+
226
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
227
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
228
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
229
+    }
230
+
231
+    $ret = [];
232
+    $ret['r'] = floor($R);
233
+    $ret['g'] = floor($G);
234
+    $ret['b'] = floor($B);
235
+
236
+    return $ret;
237 237
 }
238 238
 
239 239
 /**
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
  *     true si il faut supprimer le fichier temporaire ; false sinon.
252 252
  */
253 253
 function statut_effacer_images_temporaires($stat) {
254
-	static $statut = false; // par defaut on grave toute les images
255
-	if ($stat === 'get') {
256
-		return $statut;
257
-	}
258
-	$statut = $stat ? true : false;
254
+    static $statut = false; // par defaut on grave toute les images
255
+    if ($stat === 'get') {
256
+        return $statut;
257
+    }
258
+    $statut = $stat ? true : false;
259 259
 }
260 260
 
261 261
 
@@ -308,243 +308,243 @@  discard block
 block discarded – undo
308 308
  *     - array : tableau décrivant de l'image
309 309
  */
310 310
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
311
-	$ret = [];
312
-	$f = null;
313
-	static $images_recalcul = [];
314
-	if (strlen($img) == 0) {
315
-		return false;
316
-	}
317
-
318
-	$source = trim(extraire_attribut($img, 'src') ?? '');
319
-	if (strlen($source) < 1) {
320
-		$source = $img;
321
-		$img = "<img src='$source' />";
322
-	} elseif (
323
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
324
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
325
-		and in_array($extension, _image_extensions_acceptees_en_entree())
326
-	) {
327
-		# gerer img src="data:....base64"
328
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
329
-		if (!file_exists($local)) {
330
-			ecrire_fichier($local, base64_decode($regs[2]));
331
-		}
332
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
333
-			$sanitizer($local);
334
-		}
335
-		$source = $local;
336
-		$img = inserer_attribut($img, 'src', $source);
337
-		# eviter les mauvaises surprises lors de conversions de format
338
-		$img = inserer_attribut($img, 'width', '');
339
-		$img = inserer_attribut($img, 'height', '');
340
-	}
341
-
342
-	// les protocoles web prennent au moins 3 lettres
343
-	if (tester_url_absolue($source)) {
344
-		include_spip('inc/distant');
345
-		$fichier = _DIR_RACINE . copie_locale($source);
346
-		if (!$fichier) {
347
-			return '';
348
-		}
349
-		if (
350
-			$extension = _image_trouver_extension($fichier)
351
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
352
-		) {
353
-			$sanitizer($fichier);
354
-		}
355
-	} else {
356
-		// enlever le timestamp eventuel
357
-		if (strpos($source, '?') !== false) {
358
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
359
-		}
360
-		if (
361
-			strpos($source, '?') !== false
362
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
363
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
364
-		) {
365
-			$source = $f;
366
-		}
367
-		$fichier = $source;
368
-	}
369
-
370
-	$terminaison_dest = '';
371
-	if ($terminaison = _image_trouver_extension($fichier)) {
372
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
373
-	}
374
-
375
-	if (
376
-		$forcer_format !== false
377
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
378
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
379
-	) {
380
-		$terminaison_dest = $forcer_format;
381
-	}
382
-
383
-	if (!$terminaison_dest) {
384
-		return false;
385
-	}
386
-
387
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
388
-	$fichier_dest = $nom_fichier;
389
-	if (
390
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
391
-		or @file_exists($f = $fichier)
392
-	) {
393
-		// on passe la balise img a taille image qui exraira les attributs si possible
394
-		// au lieu de faire un acces disque sur le fichier
395
-		[$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
396
-		$date_src = @filemtime($f);
397
-	} elseif (
398
-		@file_exists($f = "$fichier.src")
399
-		and lire_fichier($f, $valeurs)
400
-		and $valeurs = unserialize($valeurs)
401
-		and isset($valeurs['hauteur_dest'])
402
-		and isset($valeurs['largeur_dest'])
403
-	) {
404
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
405
-		$ret['largeur'] = $valeurs['largeur_dest'];
406
-		$date_src = $valeurs['date'];
407
-	} // pas de fichier source par la
408
-	else {
409
-		return false;
410
-	}
411
-
412
-	// pas de taille mesurable
413
-	if (!($ret['hauteur'] or $ret['largeur'])) {
414
-		return false;
415
-	}
416
-
417
-	// les images calculees dependent du chemin du fichier source
418
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
419
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
420
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
421
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
422
-	// alors que ca concerne peu de site au final
423
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
424
-	$identifiant = $fichier;
425
-
426
-	// cas general :
427
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
428
-	// cas particulier de reduire :
429
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
430
-	$cache = 'cache-gd2';
431
-	if (substr($effet, 0, 7) == 'reduire') {
432
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
433
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
434
-		$ret['largeur_dest'] = $destWidth;
435
-		$ret['hauteur_dest'] = $destHeight;
436
-		$effet = "L{$destWidth}xH$destHeight";
437
-		$cache = 'cache-vignettes';
438
-		$fichier_dest = basename($fichier_dest);
439
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
440
-			// on garde la terminaison initiale car image simplement copiee
441
-			// et on postfixe son nom avec un md5 du path
442
-			$terminaison_dest = $terminaison;
443
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
444
-		} else {
445
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
446
-		}
447
-		$cache = sous_repertoire(_DIR_VAR, $cache);
448
-		$cache = sous_repertoire($cache, $effet);
449
-	} else {
450
-		$fichier_dest = md5("$identifiant-$effet");
451
-		$cache = sous_repertoire(_DIR_VAR, $cache);
452
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
453
-		$fichier_dest = substr($fichier_dest, 2);
454
-	}
455
-
456
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
457
-
458
-	$GLOBALS['images_calculees'][] = $fichier_dest;
459
-
460
-	$creer = true;
461
-	// si recalcul des images demande, recalculer chaque image une fois
462
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
463
-		$images_recalcul[$fichier_dest] = true;
464
-	} else {
465
-		if (@file_exists($f = $fichier_dest)) {
466
-			if (filemtime($f) >= $date_src) {
467
-				$creer = false;
468
-			}
469
-		} else {
470
-			if (
471
-				@file_exists($f = "$fichier_dest.src")
472
-				and lire_fichier($f, $valeurs)
473
-				and $valeurs = unserialize($valeurs)
474
-				and $valeurs['date'] >= $date_src
475
-			) {
476
-				$creer = false;
477
-			}
478
-		}
479
-	}
480
-	if ($creer) {
481
-		if (!@file_exists($fichier)) {
482
-			if (!@file_exists("$fichier.src")) {
483
-				spip_log("Image absente : $fichier");
484
-
485
-				return false;
486
-			}
487
-			# on reconstruit l'image source absente a partir de la chaine des .src
488
-			reconstruire_image_intermediaire($fichier);
489
-		}
490
-	}
491
-
492
-	if ($creer) {
493
-		spip_log(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
-			'images' . _LOG_DEBUG
496
-		);
497
-	}
498
-
499
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
500
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
501
-	$ret['fichier'] = $fichier;
502
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
503
-	$ret['fichier_dest'] = $fichier_dest;
504
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
505
-	$ret['format_dest'] = $terminaison_dest;
506
-	$ret['date_src'] = $date_src;
507
-	$ret['creer'] = $creer;
508
-	$ret['class'] = extraire_attribut($img, 'class');
509
-	$ret['alt'] = extraire_attribut($img, 'alt');
510
-	$ret['style'] = extraire_attribut($img, 'style');
511
-	$ret['tag'] = $img;
512
-	if ($fonction_creation) {
513
-		$ret['reconstruction'] = $fonction_creation;
514
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
515
-		# cas de image_reduire qui finalement ne reduit pas l'image source
516
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
517
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
518
-	}
519
-
520
-	$ret = pipeline('image_preparer_filtre', [
521
-			'args' => [
522
-				'img' => $img,
523
-				'effet' => $effet,
524
-				'forcer_format' => $forcer_format,
525
-				'fonction_creation' => $fonction_creation,
526
-				'find_in_path' => $find_in_path,
527
-			],
528
-			'data' => $ret
529
-		]);
530
-
531
-	// une globale pour le debug en cas de crash memoire
532
-	$GLOBALS['derniere_image_calculee'] = $ret;
533
-
534
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
535
-	if ($term_fonction === 'svg') {
536
-		if ($creer and !$support_svg) {
537
-			process_image_svg_identite($ret);
538
-			$ret['creer'] = false;
539
-		}
540
-	}
541
-	else {
542
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
543
-			return false;
544
-		}
545
-	}
546
-
547
-	return $ret;
311
+    $ret = [];
312
+    $f = null;
313
+    static $images_recalcul = [];
314
+    if (strlen($img) == 0) {
315
+        return false;
316
+    }
317
+
318
+    $source = trim(extraire_attribut($img, 'src') ?? '');
319
+    if (strlen($source) < 1) {
320
+        $source = $img;
321
+        $img = "<img src='$source' />";
322
+    } elseif (
323
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
324
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
325
+        and in_array($extension, _image_extensions_acceptees_en_entree())
326
+    ) {
327
+        # gerer img src="data:....base64"
328
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
329
+        if (!file_exists($local)) {
330
+            ecrire_fichier($local, base64_decode($regs[2]));
331
+        }
332
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
333
+            $sanitizer($local);
334
+        }
335
+        $source = $local;
336
+        $img = inserer_attribut($img, 'src', $source);
337
+        # eviter les mauvaises surprises lors de conversions de format
338
+        $img = inserer_attribut($img, 'width', '');
339
+        $img = inserer_attribut($img, 'height', '');
340
+    }
341
+
342
+    // les protocoles web prennent au moins 3 lettres
343
+    if (tester_url_absolue($source)) {
344
+        include_spip('inc/distant');
345
+        $fichier = _DIR_RACINE . copie_locale($source);
346
+        if (!$fichier) {
347
+            return '';
348
+        }
349
+        if (
350
+            $extension = _image_trouver_extension($fichier)
351
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
352
+        ) {
353
+            $sanitizer($fichier);
354
+        }
355
+    } else {
356
+        // enlever le timestamp eventuel
357
+        if (strpos($source, '?') !== false) {
358
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
359
+        }
360
+        if (
361
+            strpos($source, '?') !== false
362
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
363
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
364
+        ) {
365
+            $source = $f;
366
+        }
367
+        $fichier = $source;
368
+    }
369
+
370
+    $terminaison_dest = '';
371
+    if ($terminaison = _image_trouver_extension($fichier)) {
372
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
373
+    }
374
+
375
+    if (
376
+        $forcer_format !== false
377
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
378
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
379
+    ) {
380
+        $terminaison_dest = $forcer_format;
381
+    }
382
+
383
+    if (!$terminaison_dest) {
384
+        return false;
385
+    }
386
+
387
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
388
+    $fichier_dest = $nom_fichier;
389
+    if (
390
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
391
+        or @file_exists($f = $fichier)
392
+    ) {
393
+        // on passe la balise img a taille image qui exraira les attributs si possible
394
+        // au lieu de faire un acces disque sur le fichier
395
+        [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
396
+        $date_src = @filemtime($f);
397
+    } elseif (
398
+        @file_exists($f = "$fichier.src")
399
+        and lire_fichier($f, $valeurs)
400
+        and $valeurs = unserialize($valeurs)
401
+        and isset($valeurs['hauteur_dest'])
402
+        and isset($valeurs['largeur_dest'])
403
+    ) {
404
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
405
+        $ret['largeur'] = $valeurs['largeur_dest'];
406
+        $date_src = $valeurs['date'];
407
+    } // pas de fichier source par la
408
+    else {
409
+        return false;
410
+    }
411
+
412
+    // pas de taille mesurable
413
+    if (!($ret['hauteur'] or $ret['largeur'])) {
414
+        return false;
415
+    }
416
+
417
+    // les images calculees dependent du chemin du fichier source
418
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
419
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
420
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
421
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
422
+    // alors que ca concerne peu de site au final
423
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
424
+    $identifiant = $fichier;
425
+
426
+    // cas general :
427
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
428
+    // cas particulier de reduire :
429
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
430
+    $cache = 'cache-gd2';
431
+    if (substr($effet, 0, 7) == 'reduire') {
432
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
433
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
434
+        $ret['largeur_dest'] = $destWidth;
435
+        $ret['hauteur_dest'] = $destHeight;
436
+        $effet = "L{$destWidth}xH$destHeight";
437
+        $cache = 'cache-vignettes';
438
+        $fichier_dest = basename($fichier_dest);
439
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
440
+            // on garde la terminaison initiale car image simplement copiee
441
+            // et on postfixe son nom avec un md5 du path
442
+            $terminaison_dest = $terminaison;
443
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
444
+        } else {
445
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
446
+        }
447
+        $cache = sous_repertoire(_DIR_VAR, $cache);
448
+        $cache = sous_repertoire($cache, $effet);
449
+    } else {
450
+        $fichier_dest = md5("$identifiant-$effet");
451
+        $cache = sous_repertoire(_DIR_VAR, $cache);
452
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
453
+        $fichier_dest = substr($fichier_dest, 2);
454
+    }
455
+
456
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
457
+
458
+    $GLOBALS['images_calculees'][] = $fichier_dest;
459
+
460
+    $creer = true;
461
+    // si recalcul des images demande, recalculer chaque image une fois
462
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
463
+        $images_recalcul[$fichier_dest] = true;
464
+    } else {
465
+        if (@file_exists($f = $fichier_dest)) {
466
+            if (filemtime($f) >= $date_src) {
467
+                $creer = false;
468
+            }
469
+        } else {
470
+            if (
471
+                @file_exists($f = "$fichier_dest.src")
472
+                and lire_fichier($f, $valeurs)
473
+                and $valeurs = unserialize($valeurs)
474
+                and $valeurs['date'] >= $date_src
475
+            ) {
476
+                $creer = false;
477
+            }
478
+        }
479
+    }
480
+    if ($creer) {
481
+        if (!@file_exists($fichier)) {
482
+            if (!@file_exists("$fichier.src")) {
483
+                spip_log("Image absente : $fichier");
484
+
485
+                return false;
486
+            }
487
+            # on reconstruit l'image source absente a partir de la chaine des .src
488
+            reconstruire_image_intermediaire($fichier);
489
+        }
490
+    }
491
+
492
+    if ($creer) {
493
+        spip_log(
494
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
+            'images' . _LOG_DEBUG
496
+        );
497
+    }
498
+
499
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
500
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
501
+    $ret['fichier'] = $fichier;
502
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
503
+    $ret['fichier_dest'] = $fichier_dest;
504
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
505
+    $ret['format_dest'] = $terminaison_dest;
506
+    $ret['date_src'] = $date_src;
507
+    $ret['creer'] = $creer;
508
+    $ret['class'] = extraire_attribut($img, 'class');
509
+    $ret['alt'] = extraire_attribut($img, 'alt');
510
+    $ret['style'] = extraire_attribut($img, 'style');
511
+    $ret['tag'] = $img;
512
+    if ($fonction_creation) {
513
+        $ret['reconstruction'] = $fonction_creation;
514
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
515
+        # cas de image_reduire qui finalement ne reduit pas l'image source
516
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
517
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
518
+    }
519
+
520
+    $ret = pipeline('image_preparer_filtre', [
521
+            'args' => [
522
+                'img' => $img,
523
+                'effet' => $effet,
524
+                'forcer_format' => $forcer_format,
525
+                'fonction_creation' => $fonction_creation,
526
+                'find_in_path' => $find_in_path,
527
+            ],
528
+            'data' => $ret
529
+        ]);
530
+
531
+    // une globale pour le debug en cas de crash memoire
532
+    $GLOBALS['derniere_image_calculee'] = $ret;
533
+
534
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
535
+    if ($term_fonction === 'svg') {
536
+        if ($creer and !$support_svg) {
537
+            process_image_svg_identite($ret);
538
+            $ret['creer'] = false;
539
+        }
540
+    }
541
+    else {
542
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
543
+            return false;
544
+        }
545
+    }
546
+
547
+    return $ret;
548 548
 }
549 549
 
550 550
 
@@ -553,53 +553,53 @@  discard block
 block discarded – undo
553 553
  * @return array
554 554
  */
555 555
 function _image_extensions_acceptees_en_entree() {
556
-	static $extensions = null;
557
-	if (empty($extensions)) {
558
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
559
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
560
-			// action=tester renseigne gd_formats et detecte le support de webp
561
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
562
-			$extensions = array_map('trim', $extensions);
563
-			$extensions = array_filter($extensions);
564
-			$extensions = array_unique($extensions);
565
-			if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
566
-			}
567
-		}
568
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
569
-	}
570
-
571
-	return $extensions;
556
+    static $extensions = null;
557
+    if (empty($extensions)) {
558
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
559
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
560
+            // action=tester renseigne gd_formats et detecte le support de webp
561
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
562
+            $extensions = array_map('trim', $extensions);
563
+            $extensions = array_filter($extensions);
564
+            $extensions = array_unique($extensions);
565
+            if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
566
+            }
567
+        }
568
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
569
+    }
570
+
571
+    return $extensions;
572 572
 }
573 573
 
574 574
 /**
575 575
  * @return array|string[]|null
576 576
  */
577 577
 function _image_extensions_acceptees_en_sortie() {
578
-	static $extensions = null;
579
-	if (empty($extensions)) {
580
-		$extensions = _image_extensions_acceptees_en_entree();
581
-		$extensions = array_diff($extensions, ['jpeg']);
582
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
583
-			$extensions = array_diff($extensions, ['gif']);
584
-		}
585
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
586
-			$extensions = array_diff($extensions, ['webp']);
587
-		}
588
-	}
589
-
590
-	return $extensions;
578
+    static $extensions = null;
579
+    if (empty($extensions)) {
580
+        $extensions = _image_extensions_acceptees_en_entree();
581
+        $extensions = array_diff($extensions, ['jpeg']);
582
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
583
+            $extensions = array_diff($extensions, ['gif']);
584
+        }
585
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
586
+            $extensions = array_diff($extensions, ['webp']);
587
+        }
588
+    }
589
+
590
+    return $extensions;
591 591
 }
592 592
 
593 593
 function _image_extension_normalisee($extension) {
594
-	$extension = strtolower($extension);
595
-	if ($extension === 'jpeg') {
596
-		$extension = 'jpg';
597
-	}
598
-	return $extension;
594
+    $extension = strtolower($extension);
595
+    if ($extension === 'jpeg') {
596
+        $extension = 'jpg';
597
+    }
598
+    return $extension;
599 599
 }
600 600
 
601 601
 function _image_extensions_conservent_transparence() {
602
-	return ['png', 'webp'];
602
+    return ['png', 'webp'];
603 603
 }
604 604
 
605 605
 
@@ -609,12 +609,12 @@  discard block
 block discarded – undo
609 609
  * @return string
610 610
  */
611 611
 function _image_trouver_extension($path) {
612
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
613
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
614
-		$terminaison = strtolower($regs[1]);
615
-		return $terminaison;
616
-	}
617
-	return '';
612
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
613
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
614
+        $terminaison = strtolower($regs[1]);
615
+        return $terminaison;
616
+    }
617
+    return '';
618 618
 }
619 619
 
620 620
 /**
@@ -625,33 +625,33 @@  discard block
 block discarded – undo
625 625
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
626 626
  */
627 627
 function _image_trouver_extension_pertinente($path) {
628
-	$path = supprimer_timestamp($path);
629
-	$terminaison = _image_trouver_extension($path);
630
-	if ($terminaison == 'jpg') {
631
-		$terminaison = 'jpeg';
632
-	}
633
-
634
-	if (!file_exists($path)) {
635
-		return $terminaison;
636
-	}
637
-
638
-	if (!$info = @spip_getimagesize($path)) {
639
-		return $terminaison;
640
-	}
641
-
642
-	if (isset($info['mime'])) {
643
-		$mime = $info['mime'];
644
-	}
645
-	else {
646
-		$mime = image_type_to_mime_type($info[2]);
647
-	}
648
-
649
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
650
-	if ($_terminaison and $_terminaison !== $terminaison) {
651
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
652
-		$terminaison = $_terminaison;
653
-	}
654
-	return $terminaison;
628
+    $path = supprimer_timestamp($path);
629
+    $terminaison = _image_trouver_extension($path);
630
+    if ($terminaison == 'jpg') {
631
+        $terminaison = 'jpeg';
632
+    }
633
+
634
+    if (!file_exists($path)) {
635
+        return $terminaison;
636
+    }
637
+
638
+    if (!$info = @spip_getimagesize($path)) {
639
+        return $terminaison;
640
+    }
641
+
642
+    if (isset($info['mime'])) {
643
+        $mime = $info['mime'];
644
+    }
645
+    else {
646
+        $mime = image_type_to_mime_type($info[2]);
647
+    }
648
+
649
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
650
+    if ($_terminaison and $_terminaison !== $terminaison) {
651
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
652
+        $terminaison = $_terminaison;
653
+    }
654
+    return $terminaison;
655 655
 }
656 656
 
657 657
 /**
@@ -659,36 +659,36 @@  discard block
 block discarded – undo
659 659
  * @return string
660 660
  */
661 661
 function _image_trouver_extension_depuis_mime($mime) {
662
-	switch (strtolower($mime)) {
663
-		case 'image/png':
664
-		case 'image/x-png':
665
-			$terminaison = 'png';
666
-			break;
667
-
668
-		case 'image/jpg':
669
-		case 'image/jpeg':
670
-		case 'image/pjpeg':
671
-			$terminaison = 'jpeg';
672
-			break;
673
-
674
-		case 'image/gif':
675
-			$terminaison = 'gif';
676
-			break;
677
-
678
-		case 'image/webp':
679
-		case 'image/x-webp':
680
-			$terminaison = 'webp';
681
-			break;
682
-
683
-		case 'image/svg+xml':
684
-			$terminaison = 'svg';
685
-			break;
686
-
687
-		default:
688
-			$terminaison = '';
689
-	}
690
-
691
-	return $terminaison;
662
+    switch (strtolower($mime)) {
663
+        case 'image/png':
664
+        case 'image/x-png':
665
+            $terminaison = 'png';
666
+            break;
667
+
668
+        case 'image/jpg':
669
+        case 'image/jpeg':
670
+        case 'image/pjpeg':
671
+            $terminaison = 'jpeg';
672
+            break;
673
+
674
+        case 'image/gif':
675
+            $terminaison = 'gif';
676
+            break;
677
+
678
+        case 'image/webp':
679
+        case 'image/x-webp':
680
+            $terminaison = 'webp';
681
+            break;
682
+
683
+        case 'image/svg+xml':
684
+            $terminaison = 'svg';
685
+            break;
686
+
687
+        default:
688
+            $terminaison = '';
689
+    }
690
+
691
+    return $terminaison;
692 692
 }
693 693
 
694 694
 
@@ -708,18 +708,18 @@  discard block
 block discarded – undo
708 708
  *     Une ressource de type Image GD.
709 709
  */
710 710
 function _imagecreatefrom_func(string $func, string $filename) {
711
-	if (!function_exists($func)) {
712
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
713
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
714
-		return null;
715
-	}
716
-	$img = @$func($filename);
717
-	if (!$img) {
718
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
719
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
720
-		$img = imagecreate(10, 10);
721
-	}
722
-	return $img;
711
+    if (!function_exists($func)) {
712
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
713
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
714
+        return null;
715
+    }
716
+    $img = @$func($filename);
717
+    if (!$img) {
718
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
719
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
720
+        $img = imagecreate(10, 10);
721
+    }
722
+    return $img;
723 723
 }
724 724
 
725 725
 /**
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
  *     Une ressource de type Image GD.
736 736
  */
737 737
 function _imagecreatefromjpeg($filename) {
738
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
738
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
739 739
 }
740 740
 
741 741
 /**
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
  *     Une ressource de type Image GD.
752 752
  */
753 753
 function _imagecreatefrompng($filename) {
754
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
754
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
755 755
 }
756 756
 
757 757
 /**
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
  *     Une ressource de type Image GD.
768 768
  */
769 769
 function _imagecreatefromgif($filename) {
770
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
770
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
771 771
 }
772 772
 
773 773
 
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
  *     Une ressource de type Image GD.
785 785
  */
786 786
 function _imagecreatefromwebp($filename) {
787
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
787
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
788 788
 }
789 789
 
790 790
 /**
@@ -802,24 +802,24 @@  discard block
 block discarded – undo
802 802
  *     - true si une image est bien retournée.
803 803
  */
804 804
 function _image_imagepng($img, $fichier) {
805
-	if (!function_exists('imagepng')) {
806
-		return false;
807
-	}
808
-	$tmp = $fichier . '.tmp';
809
-	$ret = imagepng($img, $tmp);
810
-	if (file_exists($tmp)) {
811
-		$taille_test = getimagesize($tmp);
812
-		if ($taille_test[0] < 1) {
813
-			return false;
814
-		}
815
-
816
-		spip_unlink($fichier); // le fichier peut deja exister
817
-		@rename($tmp, $fichier);
818
-
819
-		return $ret;
820
-	}
821
-
822
-	return false;
805
+    if (!function_exists('imagepng')) {
806
+        return false;
807
+    }
808
+    $tmp = $fichier . '.tmp';
809
+    $ret = imagepng($img, $tmp);
810
+    if (file_exists($tmp)) {
811
+        $taille_test = getimagesize($tmp);
812
+        if ($taille_test[0] < 1) {
813
+            return false;
814
+        }
815
+
816
+        spip_unlink($fichier); // le fichier peut deja exister
817
+        @rename($tmp, $fichier);
818
+
819
+        return $ret;
820
+    }
821
+
822
+    return false;
823 823
 }
824 824
 
825 825
 /**
@@ -837,24 +837,24 @@  discard block
 block discarded – undo
837 837
  *     - true si une image est bien retournée.
838 838
  */
839 839
 function _image_imagegif($img, $fichier) {
840
-	if (!function_exists('imagegif')) {
841
-		return false;
842
-	}
843
-	$tmp = $fichier . '.tmp';
844
-	$ret = imagegif($img, $tmp);
845
-	if (file_exists($tmp)) {
846
-		$taille_test = getimagesize($tmp);
847
-		if ($taille_test[0] < 1) {
848
-			return false;
849
-		}
850
-
851
-		spip_unlink($fichier); // le fichier peut deja exister
852
-		@rename($tmp, $fichier);
853
-
854
-		return $ret;
855
-	}
856
-
857
-	return false;
840
+    if (!function_exists('imagegif')) {
841
+        return false;
842
+    }
843
+    $tmp = $fichier . '.tmp';
844
+    $ret = imagegif($img, $tmp);
845
+    if (file_exists($tmp)) {
846
+        $taille_test = getimagesize($tmp);
847
+        if ($taille_test[0] < 1) {
848
+            return false;
849
+        }
850
+
851
+        spip_unlink($fichier); // le fichier peut deja exister
852
+        @rename($tmp, $fichier);
853
+
854
+        return $ret;
855
+    }
856
+
857
+    return false;
858 858
 }
859 859
 
860 860
 /**
@@ -877,29 +877,29 @@  discard block
 block discarded – undo
877 877
  *     - true si une image est bien retournée.
878 878
  */
879 879
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
880
-	if (!function_exists('imagejpeg')) {
881
-		return false;
882
-	}
883
-	$tmp = $fichier . '.tmp';
880
+    if (!function_exists('imagejpeg')) {
881
+        return false;
882
+    }
883
+    $tmp = $fichier . '.tmp';
884 884
 
885
-	// Enable interlancing
886
-	imageinterlace($img, true);
885
+    // Enable interlancing
886
+    imageinterlace($img, true);
887 887
 
888
-	$ret = imagejpeg($img, $tmp, $qualite);
888
+    $ret = imagejpeg($img, $tmp, $qualite);
889 889
 
890
-	if (file_exists($tmp)) {
891
-		$taille_test = getimagesize($tmp);
892
-		if ($taille_test[0] < 1) {
893
-			return false;
894
-		}
890
+    if (file_exists($tmp)) {
891
+        $taille_test = getimagesize($tmp);
892
+        if ($taille_test[0] < 1) {
893
+            return false;
894
+        }
895 895
 
896
-		spip_unlink($fichier); // le fichier peut deja exister
897
-		@rename($tmp, $fichier);
896
+        spip_unlink($fichier); // le fichier peut deja exister
897
+        @rename($tmp, $fichier);
898 898
 
899
-		return $ret;
900
-	}
899
+        return $ret;
900
+    }
901 901
 
902
-	return false;
902
+    return false;
903 903
 }
904 904
 
905 905
 /**
@@ -917,9 +917,9 @@  discard block
 block discarded – undo
917 917
  *     true si le fichier a bien été créé ; false sinon.
918 918
  */
919 919
 function _image_imageico($img, $fichier) {
920
-	$gd_image_array = [$img];
920
+    $gd_image_array = [$img];
921 921
 
922
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
922
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
923 923
 }
924 924
 
925 925
 
@@ -938,24 +938,24 @@  discard block
 block discarded – undo
938 938
  *     - true si une image est bien retournée.
939 939
  */
940 940
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
941
-	if (!function_exists('imagewebp')) {
942
-		return false;
943
-	}
944
-	$tmp = $fichier . '.tmp';
945
-	$ret = imagewebp($img, $tmp, $qualite);
946
-	if (file_exists($tmp)) {
947
-		$taille_test = getimagesize($tmp);
948
-		if ($taille_test[0] < 1) {
949
-			return false;
950
-		}
951
-
952
-		spip_unlink($fichier); // le fichier peut deja exister
953
-		@rename($tmp, $fichier);
954
-
955
-		return $ret;
956
-	}
957
-
958
-	return false;
941
+    if (!function_exists('imagewebp')) {
942
+        return false;
943
+    }
944
+    $tmp = $fichier . '.tmp';
945
+    $ret = imagewebp($img, $tmp, $qualite);
946
+    if (file_exists($tmp)) {
947
+        $taille_test = getimagesize($tmp);
948
+        if ($taille_test[0] < 1) {
949
+            return false;
950
+        }
951
+
952
+        spip_unlink($fichier); // le fichier peut deja exister
953
+        @rename($tmp, $fichier);
954
+
955
+        return $ret;
956
+    }
957
+
958
+    return false;
959 959
 }
960 960
 
961 961
 /**
@@ -975,35 +975,35 @@  discard block
 block discarded – undo
975 975
  */
976 976
 function _image_imagesvg($img, $fichier) {
977 977
 
978
-	$tmp = $fichier . '.tmp';
979
-	if (strpos($img, '<') === false) {
980
-		$img = supprimer_timestamp($img);
981
-		if (!file_exists($img)) {
982
-			return false;
983
-		}
984
-		@copy($img, $tmp);
985
-		if (filesize($tmp) == filesize($img)) {
986
-			spip_unlink($fichier); // le fichier peut deja exister
987
-			@rename($tmp, $fichier);
988
-			return true;
989
-		}
990
-		return false;
991
-	}
992
-
993
-	file_put_contents($tmp, $img);
994
-	if (file_exists($tmp)) {
995
-		$taille_test = spip_getimagesize($tmp);
996
-		if ($taille_test[0] < 1) {
997
-			return false;
998
-		}
999
-
1000
-		spip_unlink($fichier); // le fichier peut deja exister
1001
-		@rename($tmp, $fichier);
1002
-
1003
-		return true;
1004
-	}
1005
-
1006
-	return false;
978
+    $tmp = $fichier . '.tmp';
979
+    if (strpos($img, '<') === false) {
980
+        $img = supprimer_timestamp($img);
981
+        if (!file_exists($img)) {
982
+            return false;
983
+        }
984
+        @copy($img, $tmp);
985
+        if (filesize($tmp) == filesize($img)) {
986
+            spip_unlink($fichier); // le fichier peut deja exister
987
+            @rename($tmp, $fichier);
988
+            return true;
989
+        }
990
+        return false;
991
+    }
992
+
993
+    file_put_contents($tmp, $img);
994
+    if (file_exists($tmp)) {
995
+        $taille_test = spip_getimagesize($tmp);
996
+        if ($taille_test[0] < 1) {
997
+            return false;
998
+        }
999
+
1000
+        spip_unlink($fichier); // le fichier peut deja exister
1001
+        @rename($tmp, $fichier);
1002
+
1003
+        return true;
1004
+    }
1005
+
1006
+    return false;
1007 1007
 }
1008 1008
 
1009 1009
 
@@ -1031,31 +1031,31 @@  discard block
 block discarded – undo
1031 1031
  *     - false sinon.
1032 1032
  */
1033 1033
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1034
-	if (is_null($fonction)) {
1035
-		$fonction = '_image_image' . $valeurs['format_dest'];
1036
-	}
1037
-	$ret = false;
1038
-	#un flag pour reperer les images gravees
1039
-	$lock = (
1040
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1041
-	    or
1042
-		(@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1043
-		);
1044
-	if (
1045
-		function_exists($fonction)
1046
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1047
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1048
-		&& !$lock
1049
-	) {
1050
-		if (@file_exists($valeurs['fichier_dest'])) {
1051
-			// dans tous les cas mettre a jour la taille de l'image finale
1052
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1053
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1054
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1055
-		}
1056
-	}
1057
-
1058
-	return $ret;
1034
+    if (is_null($fonction)) {
1035
+        $fonction = '_image_image' . $valeurs['format_dest'];
1036
+    }
1037
+    $ret = false;
1038
+    #un flag pour reperer les images gravees
1039
+    $lock = (
1040
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1041
+        or
1042
+        (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1043
+        );
1044
+    if (
1045
+        function_exists($fonction)
1046
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1047
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1048
+        && !$lock
1049
+    ) {
1050
+        if (@file_exists($valeurs['fichier_dest'])) {
1051
+            // dans tous les cas mettre a jour la taille de l'image finale
1052
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1053
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1054
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1055
+        }
1056
+    }
1057
+
1058
+    return $ret;
1059 1059
 }
1060 1060
 
1061 1061
 /**
@@ -1068,27 +1068,27 @@  discard block
 block discarded – undo
1068 1068
  *     Chemin vers le fichier manquant
1069 1069
  **/
1070 1070
 function reconstruire_image_intermediaire($fichier_manquant) {
1071
-	$reconstruire = [];
1072
-	$fichier = $fichier_manquant;
1073
-	while (
1074
-		strpos($fichier, '://') === false
1075
-		and !@file_exists($fichier)
1076
-		and lire_fichier($src = "$fichier.src", $source)
1077
-		and $valeurs = unserialize($source)
1078
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1079
-	) {
1080
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1081
-		$reconstruire[] = $valeurs['reconstruction'];
1082
-	}
1083
-	while (count($reconstruire)) {
1084
-		$r = array_pop($reconstruire);
1085
-		$fonction = $r[0];
1086
-		$args = $r[1];
1087
-		$fonction(...$args);
1088
-	}
1089
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1090
-	// mais l'on peut nettoyer les miettes de sa creation
1091
-	ramasse_miettes($fichier_manquant);
1071
+    $reconstruire = [];
1072
+    $fichier = $fichier_manquant;
1073
+    while (
1074
+        strpos($fichier, '://') === false
1075
+        and !@file_exists($fichier)
1076
+        and lire_fichier($src = "$fichier.src", $source)
1077
+        and $valeurs = unserialize($source)
1078
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1079
+    ) {
1080
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1081
+        $reconstruire[] = $valeurs['reconstruction'];
1082
+    }
1083
+    while (count($reconstruire)) {
1084
+        $r = array_pop($reconstruire);
1085
+        $fonction = $r[0];
1086
+        $args = $r[1];
1087
+        $fonction(...$args);
1088
+    }
1089
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1090
+    // mais l'on peut nettoyer les miettes de sa creation
1091
+    ramasse_miettes($fichier_manquant);
1092 1092
 }
1093 1093
 
1094 1094
 /**
@@ -1108,28 +1108,28 @@  discard block
 block discarded – undo
1108 1108
  *     Chemin du fichier d'image calculé
1109 1109
  **/
1110 1110
 function ramasse_miettes($fichier) {
1111
-	if (
1112
-		strpos($fichier, '://') !== false
1113
-		or !lire_fichier($src = "$fichier.src", $source)
1114
-		or !$valeurs = unserialize($source)
1115
-	) {
1116
-		return;
1117
-	}
1118
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1119
-	while (
1120
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1121
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1122
-		and (lire_fichier(
1123
-			$src = "$fichier.src",
1124
-			$source
1125
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1126
-		and ($valeurs = unserialize($source))  # et valide
1127
-	) {
1128
-		# on efface le fichier
1129
-		spip_unlink($fichier);
1130
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1131
-		#spip_unlink($src);
1132
-	}
1111
+    if (
1112
+        strpos($fichier, '://') !== false
1113
+        or !lire_fichier($src = "$fichier.src", $source)
1114
+        or !$valeurs = unserialize($source)
1115
+    ) {
1116
+        return;
1117
+    }
1118
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1119
+    while (
1120
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1121
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1122
+        and (lire_fichier(
1123
+            $src = "$fichier.src",
1124
+            $source
1125
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1126
+        and ($valeurs = unserialize($source))  # et valide
1127
+    ) {
1128
+        # on efface le fichier
1129
+        spip_unlink($fichier);
1130
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1131
+        #spip_unlink($src);
1132
+    }
1133 1133
 }
1134 1134
 
1135 1135
 
@@ -1154,31 +1154,31 @@  discard block
 block discarded – undo
1154 1154
  *     Code HTML de l'image
1155 1155
  **/
1156 1156
 function image_graver($img) {
1157
-	// appeler le filtre post_image_filtrer qui permet de faire
1158
-	// des traitements auto a la fin d'une serie de filtres
1159
-	$img = pipeline('post_image_filtrer', $img);
1160
-
1161
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1162
-	if (($p = strpos($fichier, '?')) !== false) {
1163
-		$fichier = substr($fichier, 0, $p);
1164
-	}
1165
-	if (strlen($fichier) < 1) {
1166
-		$fichier = $img;
1167
-	}
1168
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1169
-	# et qu'il ne s'agit pas d'une URL
1170
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1171
-		reconstruire_image_intermediaire($fichier);
1172
-	}
1173
-	ramasse_miettes($fichier);
1174
-
1175
-	// ajouter le timestamp si besoin
1176
-	if (strpos($fichier_ori, '?') === false) {
1177
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1178
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1179
-	}
1180
-
1181
-	return $img;
1157
+    // appeler le filtre post_image_filtrer qui permet de faire
1158
+    // des traitements auto a la fin d'une serie de filtres
1159
+    $img = pipeline('post_image_filtrer', $img);
1160
+
1161
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1162
+    if (($p = strpos($fichier, '?')) !== false) {
1163
+        $fichier = substr($fichier, 0, $p);
1164
+    }
1165
+    if (strlen($fichier) < 1) {
1166
+        $fichier = $img;
1167
+    }
1168
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1169
+    # et qu'il ne s'agit pas d'une URL
1170
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1171
+        reconstruire_image_intermediaire($fichier);
1172
+    }
1173
+    ramasse_miettes($fichier);
1174
+
1175
+    // ajouter le timestamp si besoin
1176
+    if (strpos($fichier_ori, '?') === false) {
1177
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1178
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1179
+    }
1180
+
1181
+    return $img;
1182 1182
 }
1183 1183
 
1184 1184
 /**
@@ -1205,34 +1205,34 @@  discard block
 block discarded – undo
1205 1205
  *     Code html modifié de la balise.
1206 1206
  **/
1207 1207
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1208
-	if ($style === false) {
1209
-		$style = extraire_attribut($tag, 'style');
1210
-	}
1211
-
1212
-	// enlever le width et height du style
1213
-	if ($style) {
1214
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1215
-	}
1216
-	if ($style and $style[0] === ';') {
1217
-		$style = substr($style, 1);
1218
-	}
1219
-
1220
-	// mettre des attributs de width et height sur les images,
1221
-	// ca accelere le rendu du navigateur
1222
-	// ca permet aux navigateurs de reserver la bonne taille
1223
-	// quand on a desactive l'affichage des images.
1224
-	$tag = inserer_attribut($tag, 'width', round($width));
1225
-	$tag = inserer_attribut($tag, 'height', round($height));
1226
-
1227
-	// attributs deprecies. Transformer en CSS
1228
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1229
-		$style = "margin:${espace}px;" . $style;
1230
-		$tag = inserer_attribut($tag, 'hspace', '');
1231
-	}
1232
-
1233
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1234
-
1235
-	return $tag;
1208
+    if ($style === false) {
1209
+        $style = extraire_attribut($tag, 'style');
1210
+    }
1211
+
1212
+    // enlever le width et height du style
1213
+    if ($style) {
1214
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1215
+    }
1216
+    if ($style and $style[0] === ';') {
1217
+        $style = substr($style, 1);
1218
+    }
1219
+
1220
+    // mettre des attributs de width et height sur les images,
1221
+    // ca accelere le rendu du navigateur
1222
+    // ca permet aux navigateurs de reserver la bonne taille
1223
+    // quand on a desactive l'affichage des images.
1224
+    $tag = inserer_attribut($tag, 'width', round($width));
1225
+    $tag = inserer_attribut($tag, 'height', round($height));
1226
+
1227
+    // attributs deprecies. Transformer en CSS
1228
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1229
+        $style = "margin:${espace}px;" . $style;
1230
+        $tag = inserer_attribut($tag, 'hspace', '');
1231
+    }
1232
+
1233
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1234
+
1235
+    return $tag;
1236 1236
 }
1237 1237
 
1238 1238
 
@@ -1258,72 +1258,72 @@  discard block
 block discarded – undo
1258 1258
  *     Retourne le code HTML de l'image
1259 1259
  **/
1260 1260
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1261
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1262
-
1263
-	// fermer les tags img pas bien fermes;
1264
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1265
-
1266
-	// le style
1267
-	$style = $valeurs['style'];
1268
-	if (isset($surcharge['style'])) {
1269
-		$style = $surcharge['style'];
1270
-		unset($surcharge['style']);
1271
-	}
1272
-
1273
-	// traiter specifiquement la largeur et la hauteur
1274
-	$width = $valeurs['largeur'];
1275
-	if (isset($surcharge['width'])) {
1276
-		$width = $surcharge['width'];
1277
-		unset($surcharge['width']);
1278
-	}
1279
-	$height = $valeurs['hauteur'];
1280
-	if (isset($surcharge['height'])) {
1281
-		$height = $surcharge['height'];
1282
-		unset($surcharge['height']);
1283
-	}
1284
-
1285
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1286
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1287
-	// on remplace toute les ref a src dans le tag
1288
-	$src = extraire_attribut($tag, 'src');
1289
-	if (isset($surcharge['src'])) {
1290
-		$tag = str_replace($src, $surcharge['src'], $tag);
1291
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1292
-		// pas garanti comme methode, mais mieux que rien
1293
-		if (strpos($src, '&') !== false) {
1294
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1295
-		}
1296
-		$src = $surcharge['src'];
1297
-		unset($surcharge['src']);
1298
-	}
1299
-
1300
-	$class = $valeurs['class'];
1301
-	if (isset($surcharge['class'])) {
1302
-		$class = $surcharge['class'];
1303
-		unset($surcharge['class']);
1304
-	}
1305
-	if (is_scalar($class) && strlen($class)) {
1306
-		$tag = inserer_attribut($tag, 'class', $class);
1307
-	}
1308
-
1309
-	if (count($surcharge)) {
1310
-		foreach ($surcharge as $attribut => $valeur) {
1311
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1312
-		}
1313
-	}
1314
-
1315
-	$tag = pipeline(
1316
-		'image_ecrire_tag_finir',
1317
-		[
1318
-			'args' => [
1319
-				'valeurs' => $valeurs,
1320
-				'surcharge' => $surcharge,
1321
-			],
1322
-			'data' => $tag
1323
-		]
1324
-	);
1325
-
1326
-	return $tag;
1261
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1262
+
1263
+    // fermer les tags img pas bien fermes;
1264
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1265
+
1266
+    // le style
1267
+    $style = $valeurs['style'];
1268
+    if (isset($surcharge['style'])) {
1269
+        $style = $surcharge['style'];
1270
+        unset($surcharge['style']);
1271
+    }
1272
+
1273
+    // traiter specifiquement la largeur et la hauteur
1274
+    $width = $valeurs['largeur'];
1275
+    if (isset($surcharge['width'])) {
1276
+        $width = $surcharge['width'];
1277
+        unset($surcharge['width']);
1278
+    }
1279
+    $height = $valeurs['hauteur'];
1280
+    if (isset($surcharge['height'])) {
1281
+        $height = $surcharge['height'];
1282
+        unset($surcharge['height']);
1283
+    }
1284
+
1285
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1286
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1287
+    // on remplace toute les ref a src dans le tag
1288
+    $src = extraire_attribut($tag, 'src');
1289
+    if (isset($surcharge['src'])) {
1290
+        $tag = str_replace($src, $surcharge['src'], $tag);
1291
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1292
+        // pas garanti comme methode, mais mieux que rien
1293
+        if (strpos($src, '&') !== false) {
1294
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1295
+        }
1296
+        $src = $surcharge['src'];
1297
+        unset($surcharge['src']);
1298
+    }
1299
+
1300
+    $class = $valeurs['class'];
1301
+    if (isset($surcharge['class'])) {
1302
+        $class = $surcharge['class'];
1303
+        unset($surcharge['class']);
1304
+    }
1305
+    if (is_scalar($class) && strlen($class)) {
1306
+        $tag = inserer_attribut($tag, 'class', $class);
1307
+    }
1308
+
1309
+    if (count($surcharge)) {
1310
+        foreach ($surcharge as $attribut => $valeur) {
1311
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1312
+        }
1313
+    }
1314
+
1315
+    $tag = pipeline(
1316
+        'image_ecrire_tag_finir',
1317
+        [
1318
+            'args' => [
1319
+                'valeurs' => $valeurs,
1320
+                'surcharge' => $surcharge,
1321
+            ],
1322
+            'data' => $tag
1323
+        ]
1324
+    );
1325
+
1326
+    return $tag;
1327 1327
 }
1328 1328
 
1329 1329
 /**
@@ -1346,268 +1346,268 @@  discard block
 block discarded – undo
1346 1346
  *     Description de l'image, sinon null.
1347 1347
  **/
1348 1348
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1349
-	$srcHeight = null;
1350
-	$retour = [];
1351
-	// ordre de preference des formats graphiques pour creer les vignettes
1352
-	// le premier format disponible, selon la methode demandee, est utilise
1353
-	$image = $valeurs['fichier'];
1354
-	$format = $valeurs['format_source'];
1355
-	$destdir = dirname($valeurs['fichier_dest']);
1356
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1357
-
1358
-	$format_sortie = $valeurs['format_dest'];
1359
-
1360
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1361
-		$process = $GLOBALS['meta']['image_process'];
1362
-	}
1363
-
1364
-	// si le doc n'est pas une image dans un format accetpable, refuser
1365
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1366
-		return;
1367
-	}
1368
-	$destination = "$destdir/$destfile";
1369
-
1370
-	// calculer la taille
1371
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1372
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1373
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1374
-		}
1375
-	} elseif ($process == 'convert' or $process == 'imagick') {
1376
-		$destWidth = $maxWidth;
1377
-		$destHeight = $maxHeight;
1378
-	} else {
1379
-		spip_log("echec $process sur $image");
1380
-
1381
-		return;
1382
-	}
1383
-
1384
-	$vignette = '';
1385
-
1386
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1387
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1388
-		$vignette = $destination . '.' . $format;
1389
-		@copy($image, $vignette);
1390
-	}
1391
-
1392
-	elseif ($valeurs['format_source'] === 'svg') {
1393
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1394
-			$format_sortie = 'svg';
1395
-			$vignette = $destination . '.' . $format_sortie;
1396
-			$valeurs['fichier_dest'] = $vignette;
1397
-			_image_gd_output($svg, $valeurs);
1398
-		}
1399
-	}
1400
-
1401
-	// imagemagick en ligne de commande
1402
-	elseif ($process == 'convert') {
1403
-		if (!defined('_CONVERT_COMMAND')) {
1404
-			define('_CONVERT_COMMAND', 'convert');
1405
-		} // Securite : mes_options.php peut preciser le chemin absolu
1406
-		if (!defined('_RESIZE_COMMAND')) {
1407
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1408
-		}
1409
-		$vignette = $destination . '.' . $format_sortie;
1410
-		$commande = str_replace(
1411
-			['%x', '%y', '%src', '%dest'],
1412
-			[
1413
-				$destWidth,
1414
-				$destHeight,
1415
-				escapeshellcmd($image),
1416
-				escapeshellcmd($vignette)
1417
-			],
1418
-			_RESIZE_COMMAND
1419
-		);
1420
-		spip_log($commande);
1421
-		exec($commande);
1422
-		if (!@file_exists($vignette)) {
1423
-			spip_log("echec convert sur $vignette");
1424
-
1425
-			return;  // echec commande
1426
-		}
1427
-	}
1428
-
1429
-	// php5 imagemagick
1430
-	elseif ($process == 'imagick') {
1431
-
1432
-		if (!class_exists(\Imagick::class)) {
1433
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1434
-
1435
-			return;
1436
-		}
1437
-
1438
-		// chemin compatible Windows
1439
-		$output = realpath(dirname($destination));
1440
-		if (!$output) {
1441
-			return;
1442
-		}
1443
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1444
-
1445
-		$imagick = new Imagick();
1446
-		$imagick->readImage(realpath($image));
1447
-		$imagick->resizeImage(
1448
-			$destWidth,
1449
-			$destHeight,
1450
-			Imagick::FILTER_LANCZOS,
1451
-			1
1452
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453
-		$imagick->writeImage($vignette);
1454
-
1455
-		if (!@file_exists($vignette)) {
1456
-			spip_log("echec imagick sur $vignette");
1457
-
1458
-			return;
1459
-		}
1460
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
-		$vignette = $destination . '.' . $format_sortie;
1462
-	}
1463
-
1464
-	// netpbm
1465
-	elseif ($process == 'netpbm') {
1466
-		if (!defined('_PNMSCALE_COMMAND')) {
1467
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1468
-		} // Securite : mes_options.php peut preciser le chemin absolu
1469
-		if (_PNMSCALE_COMMAND == '') {
1470
-			return;
1471
-		}
1472
-		$vignette = $destination . '.' . $format_sortie;
1473
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474
-		if ($format == 'jpg') {
1475
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
-			if (!($s = @filesize($vignette))) {
1478
-				spip_unlink($vignette);
1479
-			}
1480
-			if (!@file_exists($vignette)) {
1481
-				spip_log("echec netpbm-jpg sur $vignette");
1482
-
1483
-				return;
1484
-			}
1485
-		} else {
1486
-			if ($format == 'gif') {
1487
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
-				if (!($s = @filesize($vignette))) {
1490
-					spip_unlink($vignette);
1491
-				}
1492
-				if (!@file_exists($vignette)) {
1493
-					spip_log("echec netpbm-gif sur $vignette");
1494
-
1495
-					return;
1496
-				}
1497
-			} else {
1498
-				if ($format == 'png') {
1499
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1501
-					if (!($s = @filesize($vignette))) {
1502
-						spip_unlink($vignette);
1503
-					}
1504
-					if (!@file_exists($vignette)) {
1505
-						spip_log("echec netpbm-png sur $vignette");
1506
-
1507
-						return;
1508
-					}
1509
-				}
1510
-			}
1511
-		}
1512
-	}
1513
-
1514
-	// gd ou gd2
1515
-	elseif ($process == 'gd1' or $process == 'gd2') {
1516
-		if (!function_exists('gd_info')) {
1517
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1518
-
1519
-			return;
1520
-		}
1521
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1523
-
1524
-			return;
1525
-		}
1526
-		$destFormat = $format_sortie;
1527
-		if (!$destFormat) {
1528
-			spip_log("pas de format pour $image");
1529
-
1530
-			return;
1531
-		}
1532
-
1533
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1534
-		if (!function_exists($fonction_imagecreatefrom)) {
1535
-			return;
1536
-		}
1537
-		$srcImage = @$fonction_imagecreatefrom($image);
1538
-		if (!$srcImage) {
1539
-			spip_log('echec gd1/gd2');
1540
-
1541
-			return;
1542
-		}
1543
-
1544
-		// Initialisation de l'image destination
1545
-		$destImage = null;
1546
-		if ($process == 'gd2' and $destFormat != 'gif') {
1547
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1548
-		}
1549
-		if (!$destImage) {
1550
-			$destImage = ImageCreate($destWidth, $destHeight);
1551
-		}
1552
-
1553
-		// Recopie de l'image d'origine avec adaptation de la taille
1554
-		$ok = false;
1555
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1556
-			if ($format == 'gif') {
1557
-				// Si un GIF est transparent,
1558
-				// fabriquer un PNG transparent
1559
-				$transp = imagecolortransparent($srcImage);
1560
-				if ($transp > 0) {
1561
-					$destFormat = 'png';
1562
-				}
1563
-			}
1564
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1565
-				// Conserver la transparence
1566
-				if (function_exists('imageAntiAlias')) {
1567
-					imageAntiAlias($destImage, true);
1568
-				}
1569
-				@imagealphablending($destImage, false);
1570
-				@imagesavealpha($destImage, true);
1571
-			}
1572
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1573
-		}
1574
-		if (!$ok) {
1575
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1576
-		}
1577
-
1578
-		// Sauvegarde de l'image destination
1579
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1580
-		$valeurs['format_dest'] = $format = $destFormat;
1581
-		_image_gd_output($destImage, $valeurs);
1582
-
1583
-		if ($srcImage) {
1584
-			ImageDestroy($srcImage);
1585
-		}
1586
-		ImageDestroy($destImage);
1587
-	}
1588
-
1589
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1590
-		$size = [$destWidth, $destHeight];
1591
-	}
1592
-
1593
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1594
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1595
-	if ($size[0] < 1) {
1596
-		$size[0] = $destWidth;
1597
-	}
1598
-	if ($size[1] < 1) {
1599
-		$size[1] = $destHeight;
1600
-	}
1601
-
1602
-	$retour['width'] = $largeur = $size[0];
1603
-	$retour['height'] = $hauteur = $size[1];
1604
-
1605
-	$retour['fichier'] = $vignette;
1606
-	$retour['format'] = $format;
1607
-	$retour['date'] = @filemtime($vignette);
1608
-
1609
-	// renvoyer l'image
1610
-	return $retour;
1349
+    $srcHeight = null;
1350
+    $retour = [];
1351
+    // ordre de preference des formats graphiques pour creer les vignettes
1352
+    // le premier format disponible, selon la methode demandee, est utilise
1353
+    $image = $valeurs['fichier'];
1354
+    $format = $valeurs['format_source'];
1355
+    $destdir = dirname($valeurs['fichier_dest']);
1356
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1357
+
1358
+    $format_sortie = $valeurs['format_dest'];
1359
+
1360
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1361
+        $process = $GLOBALS['meta']['image_process'];
1362
+    }
1363
+
1364
+    // si le doc n'est pas une image dans un format accetpable, refuser
1365
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1366
+        return;
1367
+    }
1368
+    $destination = "$destdir/$destfile";
1369
+
1370
+    // calculer la taille
1371
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1372
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1373
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1374
+        }
1375
+    } elseif ($process == 'convert' or $process == 'imagick') {
1376
+        $destWidth = $maxWidth;
1377
+        $destHeight = $maxHeight;
1378
+    } else {
1379
+        spip_log("echec $process sur $image");
1380
+
1381
+        return;
1382
+    }
1383
+
1384
+    $vignette = '';
1385
+
1386
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1387
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1388
+        $vignette = $destination . '.' . $format;
1389
+        @copy($image, $vignette);
1390
+    }
1391
+
1392
+    elseif ($valeurs['format_source'] === 'svg') {
1393
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1394
+            $format_sortie = 'svg';
1395
+            $vignette = $destination . '.' . $format_sortie;
1396
+            $valeurs['fichier_dest'] = $vignette;
1397
+            _image_gd_output($svg, $valeurs);
1398
+        }
1399
+    }
1400
+
1401
+    // imagemagick en ligne de commande
1402
+    elseif ($process == 'convert') {
1403
+        if (!defined('_CONVERT_COMMAND')) {
1404
+            define('_CONVERT_COMMAND', 'convert');
1405
+        } // Securite : mes_options.php peut preciser le chemin absolu
1406
+        if (!defined('_RESIZE_COMMAND')) {
1407
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1408
+        }
1409
+        $vignette = $destination . '.' . $format_sortie;
1410
+        $commande = str_replace(
1411
+            ['%x', '%y', '%src', '%dest'],
1412
+            [
1413
+                $destWidth,
1414
+                $destHeight,
1415
+                escapeshellcmd($image),
1416
+                escapeshellcmd($vignette)
1417
+            ],
1418
+            _RESIZE_COMMAND
1419
+        );
1420
+        spip_log($commande);
1421
+        exec($commande);
1422
+        if (!@file_exists($vignette)) {
1423
+            spip_log("echec convert sur $vignette");
1424
+
1425
+            return;  // echec commande
1426
+        }
1427
+    }
1428
+
1429
+    // php5 imagemagick
1430
+    elseif ($process == 'imagick') {
1431
+
1432
+        if (!class_exists(\Imagick::class)) {
1433
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1434
+
1435
+            return;
1436
+        }
1437
+
1438
+        // chemin compatible Windows
1439
+        $output = realpath(dirname($destination));
1440
+        if (!$output) {
1441
+            return;
1442
+        }
1443
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1444
+
1445
+        $imagick = new Imagick();
1446
+        $imagick->readImage(realpath($image));
1447
+        $imagick->resizeImage(
1448
+            $destWidth,
1449
+            $destHeight,
1450
+            Imagick::FILTER_LANCZOS,
1451
+            1
1452
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453
+        $imagick->writeImage($vignette);
1454
+
1455
+        if (!@file_exists($vignette)) {
1456
+            spip_log("echec imagick sur $vignette");
1457
+
1458
+            return;
1459
+        }
1460
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
+        $vignette = $destination . '.' . $format_sortie;
1462
+    }
1463
+
1464
+    // netpbm
1465
+    elseif ($process == 'netpbm') {
1466
+        if (!defined('_PNMSCALE_COMMAND')) {
1467
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1468
+        } // Securite : mes_options.php peut preciser le chemin absolu
1469
+        if (_PNMSCALE_COMMAND == '') {
1470
+            return;
1471
+        }
1472
+        $vignette = $destination . '.' . $format_sortie;
1473
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474
+        if ($format == 'jpg') {
1475
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
+            if (!($s = @filesize($vignette))) {
1478
+                spip_unlink($vignette);
1479
+            }
1480
+            if (!@file_exists($vignette)) {
1481
+                spip_log("echec netpbm-jpg sur $vignette");
1482
+
1483
+                return;
1484
+            }
1485
+        } else {
1486
+            if ($format == 'gif') {
1487
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
+                if (!($s = @filesize($vignette))) {
1490
+                    spip_unlink($vignette);
1491
+                }
1492
+                if (!@file_exists($vignette)) {
1493
+                    spip_log("echec netpbm-gif sur $vignette");
1494
+
1495
+                    return;
1496
+                }
1497
+            } else {
1498
+                if ($format == 'png') {
1499
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1501
+                    if (!($s = @filesize($vignette))) {
1502
+                        spip_unlink($vignette);
1503
+                    }
1504
+                    if (!@file_exists($vignette)) {
1505
+                        spip_log("echec netpbm-png sur $vignette");
1506
+
1507
+                        return;
1508
+                    }
1509
+                }
1510
+            }
1511
+        }
1512
+    }
1513
+
1514
+    // gd ou gd2
1515
+    elseif ($process == 'gd1' or $process == 'gd2') {
1516
+        if (!function_exists('gd_info')) {
1517
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1518
+
1519
+            return;
1520
+        }
1521
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1523
+
1524
+            return;
1525
+        }
1526
+        $destFormat = $format_sortie;
1527
+        if (!$destFormat) {
1528
+            spip_log("pas de format pour $image");
1529
+
1530
+            return;
1531
+        }
1532
+
1533
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1534
+        if (!function_exists($fonction_imagecreatefrom)) {
1535
+            return;
1536
+        }
1537
+        $srcImage = @$fonction_imagecreatefrom($image);
1538
+        if (!$srcImage) {
1539
+            spip_log('echec gd1/gd2');
1540
+
1541
+            return;
1542
+        }
1543
+
1544
+        // Initialisation de l'image destination
1545
+        $destImage = null;
1546
+        if ($process == 'gd2' and $destFormat != 'gif') {
1547
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1548
+        }
1549
+        if (!$destImage) {
1550
+            $destImage = ImageCreate($destWidth, $destHeight);
1551
+        }
1552
+
1553
+        // Recopie de l'image d'origine avec adaptation de la taille
1554
+        $ok = false;
1555
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1556
+            if ($format == 'gif') {
1557
+                // Si un GIF est transparent,
1558
+                // fabriquer un PNG transparent
1559
+                $transp = imagecolortransparent($srcImage);
1560
+                if ($transp > 0) {
1561
+                    $destFormat = 'png';
1562
+                }
1563
+            }
1564
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1565
+                // Conserver la transparence
1566
+                if (function_exists('imageAntiAlias')) {
1567
+                    imageAntiAlias($destImage, true);
1568
+                }
1569
+                @imagealphablending($destImage, false);
1570
+                @imagesavealpha($destImage, true);
1571
+            }
1572
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1573
+        }
1574
+        if (!$ok) {
1575
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1576
+        }
1577
+
1578
+        // Sauvegarde de l'image destination
1579
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1580
+        $valeurs['format_dest'] = $format = $destFormat;
1581
+        _image_gd_output($destImage, $valeurs);
1582
+
1583
+        if ($srcImage) {
1584
+            ImageDestroy($srcImage);
1585
+        }
1586
+        ImageDestroy($destImage);
1587
+    }
1588
+
1589
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1590
+        $size = [$destWidth, $destHeight];
1591
+    }
1592
+
1593
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1594
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1595
+    if ($size[0] < 1) {
1596
+        $size[0] = $destWidth;
1597
+    }
1598
+    if ($size[1] < 1) {
1599
+        $size[1] = $destHeight;
1600
+    }
1601
+
1602
+    $retour['width'] = $largeur = $size[0];
1603
+    $retour['height'] = $hauteur = $size[1];
1604
+
1605
+    $retour['fichier'] = $vignette;
1606
+    $retour['format'] = $format;
1607
+    $retour['date'] = @filemtime($vignette);
1608
+
1609
+    // renvoyer l'image
1610
+    return $retour;
1611 1611
 }
1612 1612
 
1613 1613
 /**
@@ -1627,25 +1627,25 @@  discard block
 block discarded – undo
1627 1627
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1628 1628
  **/
1629 1629
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1630
-	$ratioWidth = $srcWidth / $maxWidth;
1631
-	$ratioHeight = $srcHeight / $maxHeight;
1632
-
1633
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1634
-		$destWidth = $srcWidth;
1635
-		$destHeight = $srcHeight;
1636
-	} elseif ($ratioWidth < $ratioHeight) {
1637
-		$destWidth = $srcWidth / $ratioHeight;
1638
-		$destHeight = $maxHeight;
1639
-	} else {
1640
-		$destWidth = $maxWidth;
1641
-		$destHeight = $srcHeight / $ratioWidth;
1642
-	}
1643
-
1644
-	return [
1645
-		intval(round($destWidth)),
1646
-		intval(round($destHeight)),
1647
-		max($ratioWidth, $ratioHeight)
1648
-	];
1630
+    $ratioWidth = $srcWidth / $maxWidth;
1631
+    $ratioHeight = $srcHeight / $maxHeight;
1632
+
1633
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1634
+        $destWidth = $srcWidth;
1635
+        $destHeight = $srcHeight;
1636
+    } elseif ($ratioWidth < $ratioHeight) {
1637
+        $destWidth = $srcWidth / $ratioHeight;
1638
+        $destHeight = $maxHeight;
1639
+    } else {
1640
+        $destWidth = $maxWidth;
1641
+        $destHeight = $srcHeight / $ratioWidth;
1642
+    }
1643
+
1644
+    return [
1645
+        intval(round($destWidth)),
1646
+        intval(round($destHeight)),
1647
+        max($ratioWidth, $ratioHeight)
1648
+    ];
1649 1649
 }
1650 1650
 
1651 1651
 /**
@@ -1665,25 +1665,25 @@  discard block
 block discarded – undo
1665 1665
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1666 1666
  **/
1667 1667
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1668
-	$ratioWidth = $srcWidth / $maxWidth;
1669
-	$ratioHeight = $srcHeight / $maxHeight;
1670
-
1671
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1672
-		$destWidth = $srcWidth;
1673
-		$destHeight = $srcHeight;
1674
-	} elseif ($ratioWidth > $ratioHeight) {
1675
-		$destWidth = $srcWidth / $ratioHeight;
1676
-		$destHeight = $maxHeight;
1677
-	} else {
1678
-		$destWidth = $maxWidth;
1679
-		$destHeight = $srcHeight / $ratioWidth;
1680
-	}
1681
-
1682
-	return [
1683
-		intval(round($destWidth)),
1684
-		intval(round($destHeight)),
1685
-		min($ratioWidth, $ratioHeight)
1686
-	];
1668
+    $ratioWidth = $srcWidth / $maxWidth;
1669
+    $ratioHeight = $srcHeight / $maxHeight;
1670
+
1671
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1672
+        $destWidth = $srcWidth;
1673
+        $destHeight = $srcHeight;
1674
+    } elseif ($ratioWidth > $ratioHeight) {
1675
+        $destWidth = $srcWidth / $ratioHeight;
1676
+        $destHeight = $maxHeight;
1677
+    } else {
1678
+        $destWidth = $maxWidth;
1679
+        $destHeight = $srcHeight / $ratioWidth;
1680
+    }
1681
+
1682
+    return [
1683
+        intval(round($destWidth)),
1684
+        intval(round($destHeight)),
1685
+        min($ratioWidth, $ratioHeight)
1686
+    ];
1687 1687
 }
1688 1688
 
1689 1689
 
@@ -1696,12 +1696,12 @@  discard block
 block discarded – undo
1696 1696
  * @return string
1697 1697
  */
1698 1698
 function process_image_svg_identite($image) {
1699
-	if ($image['creer']) {
1700
-		$source = $image['fichier'];
1701
-		_image_gd_output($source, $image);
1702
-	}
1699
+    if ($image['creer']) {
1700
+        $source = $image['fichier'];
1701
+        _image_gd_output($source, $image);
1702
+    }
1703 1703
 
1704
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1704
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1705 1705
 }
1706 1706
 
1707 1707
 
@@ -1734,111 +1734,111 @@  discard block
 block discarded – undo
1734 1734
  *     Code HTML de la balise img produite
1735 1735
  **/
1736 1736
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1737
-	$image = false;
1738
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1739
-		$process = $GLOBALS['meta']['image_process'];
1740
-	}
1741
-	# determiner le format de sortie
1742
-	$format_sortie = false; // le choix par defaut sera bon
1743
-	if ($process == 'netpbm') {
1744
-		$format_sortie = 'jpg';
1745
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1746
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1747
-		// on verifie que l'extension choisie est bonne (en principe oui)
1748
-		$gd_formats = formats_image_acceptables(true);
1749
-		if (
1750
-			is_array($image)
1751
-			and (!in_array($image['format_dest'], $gd_formats)
1752
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1753
-			)
1754
-		) {
1755
-			if ($image['format_source'] == 'jpg') {
1756
-				$formats_sortie = ['jpg', 'png', 'gif'];
1757
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1758
-			{
1759
-				$formats_sortie = ['png', 'jpg', 'gif'];
1760
-			}
1761
-			// Choisir le format destination
1762
-			// - on sauve de preference en JPEG (meilleure compression)
1763
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1764
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1765
-			# pas *ecrire*
1766
-			$format_sortie = '';
1767
-			foreach ($formats_sortie as $fmt) {
1768
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1769
-					$format_sortie = $fmt;
1770
-					break;
1771
-				}
1772
-			}
1773
-			$image = false;
1774
-		}
1775
-	}
1776
-
1777
-	if (!is_array($image)) {
1778
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1779
-	}
1780
-
1781
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1782
-		spip_log("image_reduire_src:pas de version locale de $img");
1783
-		// on peut resizer en mode html si on dispose des elements
1784
-		if (
1785
-			$srcw = extraire_attribut($img, 'width')
1786
-			and $srch = extraire_attribut($img, 'height')
1787
-		) {
1788
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1789
-
1790
-			return _image_tag_changer_taille($img, $w, $h);
1791
-		}
1792
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1793
-		// sous la forme style='max-width: NNpx;'
1794
-		return inserer_attribut(
1795
-			$img,
1796
-			'style',
1797
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1798
-		);
1799
-	}
1800
-
1801
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1802
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1803
-		if ($image['creer']) {
1804
-			@copy($image['fichier'], $image['fichier_dest']);
1805
-		}
1806
-
1807
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1808
-	}
1809
-
1810
-	if ($image['creer'] == false && !$force) {
1811
-		return _image_ecrire_tag(
1812
-			$image,
1813
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1814
-		);
1815
-	}
1816
-
1817
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1818
-		$destWidth = $image['largeur_dest'];
1819
-		$destHeight = $image['hauteur_dest'];
1820
-		$logo = $image['fichier'];
1821
-		$date = $image['date_src'];
1822
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1823
-
1824
-		if ($preview && $preview['fichier']) {
1825
-			$logo = $preview['fichier'];
1826
-			$destWidth = $preview['width'];
1827
-			$destHeight = $preview['height'];
1828
-			$date = $preview['date'];
1829
-		}
1830
-		// dans l'espace prive mettre un timestamp sur l'adresse
1831
-		// de l'image, de facon a tromper le cache du navigateur
1832
-		// quand on fait supprimer/reuploader un logo
1833
-		// (pas de filemtime si SAFE MODE)
1834
-		$date = test_espace_prive() ? ('?' . $date) : '';
1835
-
1836
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1837
-	}
1838
-	else {
1839
-		# BMP, tiff ... les redacteurs osent tout!
1840
-		return $img;
1841
-	}
1737
+    $image = false;
1738
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1739
+        $process = $GLOBALS['meta']['image_process'];
1740
+    }
1741
+    # determiner le format de sortie
1742
+    $format_sortie = false; // le choix par defaut sera bon
1743
+    if ($process == 'netpbm') {
1744
+        $format_sortie = 'jpg';
1745
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1746
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1747
+        // on verifie que l'extension choisie est bonne (en principe oui)
1748
+        $gd_formats = formats_image_acceptables(true);
1749
+        if (
1750
+            is_array($image)
1751
+            and (!in_array($image['format_dest'], $gd_formats)
1752
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1753
+            )
1754
+        ) {
1755
+            if ($image['format_source'] == 'jpg') {
1756
+                $formats_sortie = ['jpg', 'png', 'gif'];
1757
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1758
+            {
1759
+                $formats_sortie = ['png', 'jpg', 'gif'];
1760
+            }
1761
+            // Choisir le format destination
1762
+            // - on sauve de preference en JPEG (meilleure compression)
1763
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1764
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1765
+            # pas *ecrire*
1766
+            $format_sortie = '';
1767
+            foreach ($formats_sortie as $fmt) {
1768
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1769
+                    $format_sortie = $fmt;
1770
+                    break;
1771
+                }
1772
+            }
1773
+            $image = false;
1774
+        }
1775
+    }
1776
+
1777
+    if (!is_array($image)) {
1778
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1779
+    }
1780
+
1781
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1782
+        spip_log("image_reduire_src:pas de version locale de $img");
1783
+        // on peut resizer en mode html si on dispose des elements
1784
+        if (
1785
+            $srcw = extraire_attribut($img, 'width')
1786
+            and $srch = extraire_attribut($img, 'height')
1787
+        ) {
1788
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1789
+
1790
+            return _image_tag_changer_taille($img, $w, $h);
1791
+        }
1792
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1793
+        // sous la forme style='max-width: NNpx;'
1794
+        return inserer_attribut(
1795
+            $img,
1796
+            'style',
1797
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1798
+        );
1799
+    }
1800
+
1801
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1802
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1803
+        if ($image['creer']) {
1804
+            @copy($image['fichier'], $image['fichier_dest']);
1805
+        }
1806
+
1807
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1808
+    }
1809
+
1810
+    if ($image['creer'] == false && !$force) {
1811
+        return _image_ecrire_tag(
1812
+            $image,
1813
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1814
+        );
1815
+    }
1816
+
1817
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1818
+        $destWidth = $image['largeur_dest'];
1819
+        $destHeight = $image['hauteur_dest'];
1820
+        $logo = $image['fichier'];
1821
+        $date = $image['date_src'];
1822
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1823
+
1824
+        if ($preview && $preview['fichier']) {
1825
+            $logo = $preview['fichier'];
1826
+            $destWidth = $preview['width'];
1827
+            $destHeight = $preview['height'];
1828
+            $date = $preview['date'];
1829
+        }
1830
+        // dans l'espace prive mettre un timestamp sur l'adresse
1831
+        // de l'image, de facon a tromper le cache du navigateur
1832
+        // quand on fait supprimer/reuploader un logo
1833
+        // (pas de filemtime si SAFE MODE)
1834
+        $date = test_espace_prive() ? ('?' . $date) : '';
1835
+
1836
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1837
+    }
1838
+    else {
1839
+        # BMP, tiff ... les redacteurs osent tout!
1840
+        return $img;
1841
+    }
1842 1842
 }
1843 1843
 
1844 1844
 /**
@@ -1852,145 +1852,145 @@  discard block
 block discarded – undo
1852 1852
  * Class phpthumb_functions
1853 1853
  */
1854 1854
 class phpthumb_functions {
1855
-	/**
1856
-	 * Retourne la couleur d'un pixel dans une image
1857
-	 *
1858
-	 * @param resource|GdImage $img
1859
-	 * @param int $x
1860
-	 * @param int $y
1861
-	 * @return array|bool
1862
-	 */
1863
-	public static function GetPixelColor(&$img, $x, $y) {
1864
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1865
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1866
-		}
1867
-		return false;
1868
-	}
1869
-
1870
-	/**
1871
-	 * Retourne un nombre dans une représentation en Little Endian
1872
-	 *
1873
-	 * @param int $number
1874
-	 * @param int $minbytes
1875
-	 * @return string
1876
-	 */
1877
-	public static function LittleEndian2String($number, $minbytes = 1) {
1878
-		$intstring = '';
1879
-		while ($number > 0) {
1880
-			$intstring = $intstring . chr($number & 255);
1881
-			$number >>= 8;
1882
-		}
1883
-
1884
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1885
-	}
1886
-
1887
-	/**
1888
-	 * Transforme une ressource GD en image au format ICO
1889
-	 *
1890
-	 * @param array $gd_image_array
1891
-	 *     Tableau de ressources d'images GD
1892
-	 * @return string
1893
-	 *     Image au format ICO
1894
-	 */
1895
-	public static function GD2ICOstring(&$gd_image_array) {
1896
-		foreach ($gd_image_array as $key => $gd_image) {
1897
-			$ImageWidths[$key] = ImageSX($gd_image);
1898
-			$ImageHeights[$key] = ImageSY($gd_image);
1899
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1900
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1901
-
1902
-			$icXOR[$key] = '';
1903
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1904
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1905
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1906
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1907
-					$r = $argb['red'];
1908
-					$g = $argb['green'];
1909
-					$b = $argb['blue'];
1910
-
1911
-					if ($bpp[$key] == 32) {
1912
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1913
-					} elseif ($bpp[$key] == 24) {
1914
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1915
-					}
1916
-
1917
-					if ($a < 128) {
1918
-						@$icANDmask[$key][$y] .= '1';
1919
-					} else {
1920
-						@$icANDmask[$key][$y] .= '0';
1921
-					}
1922
-				}
1923
-				// mask bits are 32-bit aligned per scanline
1924
-				while (strlen($icANDmask[$key][$y]) % 32) {
1925
-					$icANDmask[$key][$y] .= '0';
1926
-				}
1927
-			}
1928
-			$icAND[$key] = '';
1929
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1930
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1931
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1932
-				}
1933
-			}
1934
-		}
1935
-
1936
-		foreach ($gd_image_array as $key => $gd_image) {
1937
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1938
-
1939
-			// BITMAPINFOHEADER - 40 bytes
1940
-			$BitmapInfoHeader[$key] = '';
1941
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1942
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1943
-			// The biHeight member specifies the combined
1944
-			// height of the XOR and AND masks.
1945
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1946
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1947
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1948
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1949
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1950
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1951
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1952
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1953
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1954
-		}
1955
-
1956
-
1957
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1958
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1959
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1960
-
1961
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1962
-		foreach ($gd_image_array as $key => $gd_image) {
1963
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1964
-
1965
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1966
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1967
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1968
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1969
-
1970
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1971
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1972
-
1973
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1974
-			$icondata .= phpthumb_functions::LittleEndian2String(
1975
-				$dwBytesInRes,
1976
-				4
1977
-			);     // dwBytesInRes;	// How many bytes in this resource?
1978
-
1979
-			$icondata .= phpthumb_functions::LittleEndian2String(
1980
-				$dwImageOffset,
1981
-				4
1982
-			);    // dwImageOffset;   // Where in the file is this image?
1983
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1984
-			$dwImageOffset += strlen($icXOR[$key]);
1985
-			$dwImageOffset += strlen($icAND[$key]);
1986
-		}
1987
-
1988
-		foreach ($gd_image_array as $key => $gd_image) {
1989
-			$icondata .= $BitmapInfoHeader[$key];
1990
-			$icondata .= $icXOR[$key];
1991
-			$icondata .= $icAND[$key];
1992
-		}
1993
-
1994
-		return $icondata;
1995
-	}
1855
+    /**
1856
+     * Retourne la couleur d'un pixel dans une image
1857
+     *
1858
+     * @param resource|GdImage $img
1859
+     * @param int $x
1860
+     * @param int $y
1861
+     * @return array|bool
1862
+     */
1863
+    public static function GetPixelColor(&$img, $x, $y) {
1864
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1865
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1866
+        }
1867
+        return false;
1868
+    }
1869
+
1870
+    /**
1871
+     * Retourne un nombre dans une représentation en Little Endian
1872
+     *
1873
+     * @param int $number
1874
+     * @param int $minbytes
1875
+     * @return string
1876
+     */
1877
+    public static function LittleEndian2String($number, $minbytes = 1) {
1878
+        $intstring = '';
1879
+        while ($number > 0) {
1880
+            $intstring = $intstring . chr($number & 255);
1881
+            $number >>= 8;
1882
+        }
1883
+
1884
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1885
+    }
1886
+
1887
+    /**
1888
+     * Transforme une ressource GD en image au format ICO
1889
+     *
1890
+     * @param array $gd_image_array
1891
+     *     Tableau de ressources d'images GD
1892
+     * @return string
1893
+     *     Image au format ICO
1894
+     */
1895
+    public static function GD2ICOstring(&$gd_image_array) {
1896
+        foreach ($gd_image_array as $key => $gd_image) {
1897
+            $ImageWidths[$key] = ImageSX($gd_image);
1898
+            $ImageHeights[$key] = ImageSY($gd_image);
1899
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1900
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1901
+
1902
+            $icXOR[$key] = '';
1903
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1904
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1905
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1906
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1907
+                    $r = $argb['red'];
1908
+                    $g = $argb['green'];
1909
+                    $b = $argb['blue'];
1910
+
1911
+                    if ($bpp[$key] == 32) {
1912
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1913
+                    } elseif ($bpp[$key] == 24) {
1914
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1915
+                    }
1916
+
1917
+                    if ($a < 128) {
1918
+                        @$icANDmask[$key][$y] .= '1';
1919
+                    } else {
1920
+                        @$icANDmask[$key][$y] .= '0';
1921
+                    }
1922
+                }
1923
+                // mask bits are 32-bit aligned per scanline
1924
+                while (strlen($icANDmask[$key][$y]) % 32) {
1925
+                    $icANDmask[$key][$y] .= '0';
1926
+                }
1927
+            }
1928
+            $icAND[$key] = '';
1929
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1930
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1931
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1932
+                }
1933
+            }
1934
+        }
1935
+
1936
+        foreach ($gd_image_array as $key => $gd_image) {
1937
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1938
+
1939
+            // BITMAPINFOHEADER - 40 bytes
1940
+            $BitmapInfoHeader[$key] = '';
1941
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1942
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1943
+            // The biHeight member specifies the combined
1944
+            // height of the XOR and AND masks.
1945
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1946
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1947
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1948
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1949
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1950
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1951
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1952
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1953
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1954
+        }
1955
+
1956
+
1957
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1958
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1959
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1960
+
1961
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1962
+        foreach ($gd_image_array as $key => $gd_image) {
1963
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1964
+
1965
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1966
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1967
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1968
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1969
+
1970
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1971
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1972
+
1973
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1974
+            $icondata .= phpthumb_functions::LittleEndian2String(
1975
+                $dwBytesInRes,
1976
+                4
1977
+            );     // dwBytesInRes;	// How many bytes in this resource?
1978
+
1979
+            $icondata .= phpthumb_functions::LittleEndian2String(
1980
+                $dwImageOffset,
1981
+                4
1982
+            );    // dwImageOffset;   // Where in the file is this image?
1983
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1984
+            $dwImageOffset += strlen($icXOR[$key]);
1985
+            $dwImageOffset += strlen($icAND[$key]);
1986
+        }
1987
+
1988
+        foreach ($gd_image_array as $key => $gd_image) {
1989
+            $icondata .= $BitmapInfoHeader[$key];
1990
+            $icondata .= $icXOR[$key];
1991
+            $icondata .= $icAND[$key];
1992
+        }
1993
+
1994
+        return $icondata;
1995
+    }
1996 1996
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 	$blue = dechex($blue);
44 44
 
45 45
 	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
46
+		$red = '0'.$red;
47 47
 	}
48 48
 	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
49
+		$green = '0'.$green;
50 50
 	}
51 51
 	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
52
+		$blue = '0'.$blue;
53 53
 	}
54 54
 
55 55
 	return "$red$green$blue";
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	$couleur = couleur_html_to_hex($couleur);
68 68
 	$couleur = ltrim($couleur, '#');
69 69
 	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
70
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
71 71
 	}
72 72
 	$retour = [];
73 73
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	$var_G = ($G / 255);
126 126
 	$var_B = ($B / 255);
127 127
 
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
128
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
129
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
130
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
131 131
 
132 132
 	$L = ($var_Max + $var_Min) / 2;
133 133
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
  */
190 190
 function _couleur_hsl_to_rgb($H, $S, $L) {
191 191
 	// helper
192
-	$hue_2_rgb = function ($v1, $v2, $vH) {
192
+	$hue_2_rgb = function($v1, $v2, $vH) {
193 193
 		if ($vH < 0) {
194 194
 			$vH += 1;
195 195
 		}
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
 		$img = "<img src='$source' />";
322 322
 	} elseif (
323 323
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
324
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
324
+		and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])
325 325
 		and in_array($extension, _image_extensions_acceptees_en_entree())
326 326
 	) {
327 327
 		# gerer img src="data:....base64"
328
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
328
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
329 329
 		if (!file_exists($local)) {
330 330
 			ecrire_fichier($local, base64_decode($regs[2]));
331 331
 		}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	// les protocoles web prennent au moins 3 lettres
343 343
 	if (tester_url_absolue($source)) {
344 344
 		include_spip('inc/distant');
345
-		$fichier = _DIR_RACINE . copie_locale($source);
345
+		$fichier = _DIR_RACINE.copie_locale($source);
346 346
 		if (!$fichier) {
347 347
 			return '';
348 348
 		}
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
 			// on garde la terminaison initiale car image simplement copiee
441 441
 			// et on postfixe son nom avec un md5 du path
442 442
 			$terminaison_dest = $terminaison;
443
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
443
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
444 444
 		} else {
445
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
445
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
446 446
 		}
447 447
 		$cache = sous_repertoire(_DIR_VAR, $cache);
448 448
 		$cache = sous_repertoire($cache, $effet);
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		$fichier_dest = substr($fichier_dest, 2);
454 454
 	}
455 455
 
456
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
456
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
457 457
 
458 458
 	$GLOBALS['images_calculees'][] = $fichier_dest;
459 459
 
@@ -491,15 +491,15 @@  discard block
 block discarded – undo
491 491
 
492 492
 	if ($creer) {
493 493
 		spip_log(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
-			'images' . _LOG_DEBUG
494
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
495
+			'images'._LOG_DEBUG
496 496
 		);
497 497
 	}
498 498
 
499 499
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
500
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
501 501
 	$ret['fichier'] = $fichier;
502
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
503 503
 	$ret['fichier_dest'] = $fichier_dest;
504 504
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
505 505
 	$ret['format_dest'] = $terminaison_dest;
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 
649 649
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
650 650
 	if ($_terminaison and $_terminaison !== $terminaison) {
651
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
651
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
652 652
 		$terminaison = $_terminaison;
653 653
 	}
654 654
 	return $terminaison;
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 	if (!function_exists('imagepng')) {
806 806
 		return false;
807 807
 	}
808
-	$tmp = $fichier . '.tmp';
808
+	$tmp = $fichier.'.tmp';
809 809
 	$ret = imagepng($img, $tmp);
810 810
 	if (file_exists($tmp)) {
811 811
 		$taille_test = getimagesize($tmp);
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
 	if (!function_exists('imagegif')) {
841 841
 		return false;
842 842
 	}
843
-	$tmp = $fichier . '.tmp';
843
+	$tmp = $fichier.'.tmp';
844 844
 	$ret = imagegif($img, $tmp);
845 845
 	if (file_exists($tmp)) {
846 846
 		$taille_test = getimagesize($tmp);
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 	if (!function_exists('imagejpeg')) {
881 881
 		return false;
882 882
 	}
883
-	$tmp = $fichier . '.tmp';
883
+	$tmp = $fichier.'.tmp';
884 884
 
885 885
 	// Enable interlancing
886 886
 	imageinterlace($img, true);
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
 	if (!function_exists('imagewebp')) {
942 942
 		return false;
943 943
 	}
944
-	$tmp = $fichier . '.tmp';
944
+	$tmp = $fichier.'.tmp';
945 945
 	$ret = imagewebp($img, $tmp, $qualite);
946 946
 	if (file_exists($tmp)) {
947 947
 		$taille_test = getimagesize($tmp);
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
  */
976 976
 function _image_imagesvg($img, $fichier) {
977 977
 
978
-	$tmp = $fichier . '.tmp';
978
+	$tmp = $fichier.'.tmp';
979 979
 	if (strpos($img, '<') === false) {
980 980
 		$img = supprimer_timestamp($img);
981 981
 		if (!file_exists($img)) {
@@ -1032,14 +1032,14 @@  discard block
 block discarded – undo
1032 1032
  */
1033 1033
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1034 1034
 	if (is_null($fonction)) {
1035
-		$fonction = '_image_image' . $valeurs['format_dest'];
1035
+		$fonction = '_image_image'.$valeurs['format_dest'];
1036 1036
 	}
1037 1037
 	$ret = false;
1038 1038
 	#un flag pour reperer les images gravees
1039 1039
 	$lock = (
1040 1040
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1041 1041
 	    or
1042
-		(@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1042
+		(@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'))
1043 1043
 		);
1044 1044
 	if (
1045 1045
 		function_exists($fonction)
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
 			// dans tous les cas mettre a jour la taille de l'image finale
1052 1052
 			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1053 1053
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1054
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1054
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1055 1055
 		}
1056 1056
 	}
1057 1057
 
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
 
1227 1227
 	// attributs deprecies. Transformer en CSS
1228 1228
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1229
-		$style = "margin:${espace}px;" . $style;
1229
+		$style = "margin:${espace}px;".$style;
1230 1230
 		$tag = inserer_attribut($tag, 'hspace', '');
1231 1231
 	}
1232 1232
 
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 	$image = $valeurs['fichier'];
1354 1354
 	$format = $valeurs['format_source'];
1355 1355
 	$destdir = dirname($valeurs['fichier_dest']);
1356
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1356
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1357 1357
 
1358 1358
 	$format_sortie = $valeurs['format_dest'];
1359 1359
 
@@ -1385,14 +1385,14 @@  discard block
 block discarded – undo
1385 1385
 
1386 1386
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1387 1387
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1388
-		$vignette = $destination . '.' . $format;
1388
+		$vignette = $destination.'.'.$format;
1389 1389
 		@copy($image, $vignette);
1390 1390
 	}
1391 1391
 
1392 1392
 	elseif ($valeurs['format_source'] === 'svg') {
1393 1393
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1394 1394
 			$format_sortie = 'svg';
1395
-			$vignette = $destination . '.' . $format_sortie;
1395
+			$vignette = $destination.'.'.$format_sortie;
1396 1396
 			$valeurs['fichier_dest'] = $vignette;
1397 1397
 			_image_gd_output($svg, $valeurs);
1398 1398
 		}
@@ -1404,9 +1404,9 @@  discard block
 block discarded – undo
1404 1404
 			define('_CONVERT_COMMAND', 'convert');
1405 1405
 		} // Securite : mes_options.php peut preciser le chemin absolu
1406 1406
 		if (!defined('_RESIZE_COMMAND')) {
1407
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1407
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1408 1408
 		}
1409
-		$vignette = $destination . '.' . $format_sortie;
1409
+		$vignette = $destination.'.'.$format_sortie;
1410 1410
 		$commande = str_replace(
1411 1411
 			['%x', '%y', '%src', '%dest'],
1412 1412
 			[
@@ -1422,7 +1422,7 @@  discard block
 block discarded – undo
1422 1422
 		if (!@file_exists($vignette)) {
1423 1423
 			spip_log("echec convert sur $vignette");
1424 1424
 
1425
-			return;  // echec commande
1425
+			return; // echec commande
1426 1426
 		}
1427 1427
 	}
1428 1428
 
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
 		if (!$output) {
1441 1441
 			return;
1442 1442
 		}
1443
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1443
+		$vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie;
1444 1444
 
1445 1445
 		$imagick = new Imagick();
1446 1446
 		$imagick->readImage(realpath($image));
@@ -1449,7 +1449,7 @@  discard block
 block discarded – undo
1449 1449
 			$destHeight,
1450 1450
 			Imagick::FILTER_LANCZOS,
1451 1451
 			1
1452
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1452
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453 1453
 		$imagick->writeImage($vignette);
1454 1454
 
1455 1455
 		if (!@file_exists($vignette)) {
@@ -1458,7 +1458,7 @@  discard block
 block discarded – undo
1458 1458
 			return;
1459 1459
 		}
1460 1460
 		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
-		$vignette = $destination . '.' . $format_sortie;
1461
+		$vignette = $destination.'.'.$format_sortie;
1462 1462
 	}
1463 1463
 
1464 1464
 	// netpbm
@@ -1469,11 +1469,11 @@  discard block
 block discarded – undo
1469 1469
 		if (_PNMSCALE_COMMAND == '') {
1470 1470
 			return;
1471 1471
 		}
1472
-		$vignette = $destination . '.' . $format_sortie;
1472
+		$vignette = $destination.'.'.$format_sortie;
1473 1473
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474 1474
 		if ($format == 'jpg') {
1475 1475
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1476
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1477 1477
 			if (!($s = @filesize($vignette))) {
1478 1478
 				spip_unlink($vignette);
1479 1479
 			}
@@ -1485,7 +1485,7 @@  discard block
 block discarded – undo
1485 1485
 		} else {
1486 1486
 			if ($format == 'gif') {
1487 1487
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1488
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1489 1489
 				if (!($s = @filesize($vignette))) {
1490 1490
 					spip_unlink($vignette);
1491 1491
 				}
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
 			} else {
1498 1498
 				if ($format == 'png') {
1499 1499
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1500
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1501 1501
 					if (!($s = @filesize($vignette))) {
1502 1502
 						spip_unlink($vignette);
1503 1503
 					}
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
 			return;
1520 1520
 		}
1521 1521
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1522
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1523 1523
 
1524 1524
 			return;
1525 1525
 		}
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
 		// de l'image, de facon a tromper le cache du navigateur
1832 1832
 		// quand on fait supprimer/reuploader un logo
1833 1833
 		// (pas de filemtime si SAFE MODE)
1834
-		$date = test_espace_prive() ? ('?' . $date) : '';
1834
+		$date = test_espace_prive() ? ('?'.$date) : '';
1835 1835
 
1836 1836
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1837 1837
 	}
@@ -1877,7 +1877,7 @@  discard block
 block discarded – undo
1877 1877
 	public static function LittleEndian2String($number, $minbytes = 1) {
1878 1878
 		$intstring = '';
1879 1879
 		while ($number > 0) {
1880
-			$intstring = $intstring . chr($number & 255);
1880
+			$intstring = $intstring.chr($number & 255);
1881 1881
 			$number >>= 8;
1882 1882
 		}
1883 1883
 
@@ -1909,9 +1909,9 @@  discard block
 block discarded – undo
1909 1909
 					$b = $argb['blue'];
1910 1910
 
1911 1911
 					if ($bpp[$key] == 32) {
1912
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1912
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1913 1913
 					} elseif ($bpp[$key] == 24) {
1914
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1914
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1915 1915
 					}
1916 1916
 
1917 1917
 					if ($a < 128) {
@@ -1938,48 +1938,48 @@  discard block
 block discarded – undo
1938 1938
 
1939 1939
 			// BITMAPINFOHEADER - 40 bytes
1940 1940
 			$BitmapInfoHeader[$key] = '';
1941
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1942
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1941
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1942
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1943 1943
 			// The biHeight member specifies the combined
1944 1944
 			// height of the XOR and AND masks.
1945 1945
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1946
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1947
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1948
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1949
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1950
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1951
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1952
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1953
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1946
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1947
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1948
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1949
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1950
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1951
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1952
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1953
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1954 1954
 		}
1955 1955
 
1956 1956
 
1957
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1958
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1959
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1957
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1958
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1959
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1960 1960
 
1961 1961
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1962 1962
 		foreach ($gd_image_array as $key => $gd_image) {
1963 1963
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1964 1964
 
1965
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1966
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1967
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1968
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1965
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1966
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1967
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1968
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1969 1969
 
1970
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1971
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1970
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1971
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1972 1972
 
1973 1973
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1974 1974
 			$icondata .= phpthumb_functions::LittleEndian2String(
1975 1975
 				$dwBytesInRes,
1976 1976
 				4
1977
-			);     // dwBytesInRes;	// How many bytes in this resource?
1977
+			); // dwBytesInRes;	// How many bytes in this resource?
1978 1978
 
1979 1979
 			$icondata .= phpthumb_functions::LittleEndian2String(
1980 1980
 				$dwImageOffset,
1981 1981
 				4
1982
-			);    // dwImageOffset;   // Where in the file is this image?
1982
+			); // dwImageOffset;   // Where in the file is this image?
1983 1983
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1984 1984
 			$dwImageOffset += strlen($icXOR[$key]);
1985 1985
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.