Completed
Push — master ( 350a8b...37aa61 )
by cam
01:39
created
ecrire/inc/drapeau_edition.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  * @package SPIP\Core\Drapeaux\Edition
30 30
  **/
31 31
 if (!defined('_ECRIRE_INC_VERSION')) {
32
-	return;
32
+    return;
33 33
 }
34 34
 
35 35
 
@@ -44,46 +44,46 @@  discard block
 block discarded – undo
44 44
  *     `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()`
45 45
  **/
46 46
 function lire_tableau_edition() {
47
-	$edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
48
-	if (!$edition) {
49
-		return [];
50
-	}
51
-	$changed = false;
47
+    $edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
48
+    if (!$edition) {
49
+        return [];
50
+    }
51
+    $changed = false;
52 52
 
53
-	$bon_pour_le_service = time() - 3600;
54
-	// parcourir le tableau et virer les vieux
55
-	foreach ($edition as $objet => $data) {
56
-		if (!is_array($data)) {
57
-			unset($edition[$objet]);
58
-		} // vieille version
59
-		else {
60
-			foreach ($data as $id => $tab) {
61
-				if (!is_array($tab)) {
62
-					unset($edition[$objet][$tab]);
63
-				} // vieille version
64
-				else {
65
-					foreach ($tab as $n => $duo) {
66
-						if (current($duo) < $bon_pour_le_service) {
67
-							unset($edition[$objet][$id][$n]);
68
-							$changed = true;
69
-						}
70
-					}
71
-				}
72
-				if (!$edition[$objet][$id]) {
73
-					unset($edition[$objet][$id]);
74
-				}
75
-			}
76
-		}
77
-		if (!$edition[$objet]) {
78
-			unset($edition[$objet]);
79
-		}
80
-	}
53
+    $bon_pour_le_service = time() - 3600;
54
+    // parcourir le tableau et virer les vieux
55
+    foreach ($edition as $objet => $data) {
56
+        if (!is_array($data)) {
57
+            unset($edition[$objet]);
58
+        } // vieille version
59
+        else {
60
+            foreach ($data as $id => $tab) {
61
+                if (!is_array($tab)) {
62
+                    unset($edition[$objet][$tab]);
63
+                } // vieille version
64
+                else {
65
+                    foreach ($tab as $n => $duo) {
66
+                        if (current($duo) < $bon_pour_le_service) {
67
+                            unset($edition[$objet][$id][$n]);
68
+                            $changed = true;
69
+                        }
70
+                    }
71
+                }
72
+                if (!$edition[$objet][$id]) {
73
+                    unset($edition[$objet][$id]);
74
+                }
75
+            }
76
+        }
77
+        if (!$edition[$objet]) {
78
+            unset($edition[$objet]);
79
+        }
80
+    }
81 81
 
82
-	if ($changed) {
83
-		ecrire_tableau_edition($edition);
84
-	}
82
+    if ($changed) {
83
+        ecrire_tableau_edition($edition);
84
+    }
85 85
 
86
-	return $edition;
86
+    return $edition;
87 87
 }
88 88
 
89 89
 /**
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
  *     `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()`
97 97
  **/
98 98
 function ecrire_tableau_edition($edition) {
99
-	ecrire_meta('drapeau_edition', serialize($edition));
99
+    ecrire_meta('drapeau_edition', serialize($edition));
100 100
 }
101 101
 
102 102
 /**
@@ -116,22 +116,22 @@  discard block
 block discarded – undo
116 116
  *     Type d'objet édité
117 117
  */
118 118
 function signale_edition($id, $auteur, $type = 'article') {
119
-	include_spip('base/objets');
120
-	include_spip('inc/filtres');
121
-	if (objet_info($type, 'editable') !== 'oui') {
122
-		return;
123
-	}
119
+    include_spip('base/objets');
120
+    include_spip('inc/filtres');
121
+    if (objet_info($type, 'editable') !== 'oui') {
122
+        return;
123
+    }
124 124
 
125
-	$edition = lire_tableau_edition();
125
+    $edition = lire_tableau_edition();
126 126
 
127
-	$nom = $auteur['nom'] ?? $GLOBALS['ip'];
128
-	$id_a = $auteur['id_auteur'] ?? $GLOBALS['ip'];
127
+    $nom = $auteur['nom'] ?? $GLOBALS['ip'];
128
+    $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip'];
129 129
 
130
-	if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) {
131
-		$edition[$type][$id] = [];
132
-	}
133
-	$edition[$type][$id][$id_a][$nom] = time();
134
-	ecrire_tableau_edition($edition);
130
+    if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) {
131
+        $edition[$type][$id] = [];
132
+    }
133
+    $edition[$type][$id][$id_a][$nom] = time();
134
+    ecrire_tableau_edition($edition);
135 135
 }
136 136
 
137 137
 /**
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
  */
149 149
 function qui_edite($id, $type = 'article') {
150 150
 
151
-	$edition = lire_tableau_edition();
151
+    $edition = lire_tableau_edition();
152 152
 
153
-	return empty($edition[$type][$id]) ? [] : $edition[$type][$id];
153
+    return empty($edition[$type][$id]) ? [] : $edition[$type][$id];
154 154
 }
155 155
 
156 156
 /**
@@ -164,23 +164,23 @@  discard block
 block discarded – undo
164 164
  *     Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]`
165 165
  */
166 166
 function mention_qui_edite($id, $type = 'article'): array {
167
-	$modif = qui_edite($id, $type);
168
-	unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
167
+    $modif = qui_edite($id, $type);
168
+    unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
169 169
 
170
-	if ($modif) {
171
-		$quand = 0;
172
-		foreach ($modif as $duo) {
173
-			$auteurs[] = typo(key($duo));
174
-			$quand = max($quand, current($duo));
175
-		}
170
+    if ($modif) {
171
+        $quand = 0;
172
+        foreach ($modif as $duo) {
173
+            $auteurs[] = typo(key($duo));
174
+            $quand = max($quand, current($duo));
175
+        }
176 176
 
177
-		// format lie a la chaine de langue 'avis_article_modifie'
178
-		return [
179
-			'nom_auteur_modif' => implode(' | ', $auteurs),
180
-			'date_diff' => ceil((time() - $quand) / 60)
181
-		];
182
-	}
183
-	return [];
177
+        // format lie a la chaine de langue 'avis_article_modifie'
178
+        return [
179
+            'nom_auteur_modif' => implode(' | ', $auteurs),
180
+            'date_diff' => ceil((time() - $quand) / 60)
181
+        ];
182
+    }
183
+    return [];
184 184
 }
185 185
 
186 186
 /**
@@ -194,25 +194,25 @@  discard block
 block discarded – undo
194 194
  *     Liste de tableaux `['objet' => x, 'id_objet' => n]`
195 195
  */
196 196
 function liste_drapeau_edition($id_auteur) {
197
-	$edition = lire_tableau_edition();
198
-	$objets_ouverts = [];
197
+    $edition = lire_tableau_edition();
198
+    $objets_ouverts = [];
199 199
 
200
-	foreach ($edition as $objet => $data) {
201
-		foreach ($data as $id => $auteurs) {
202
-			if (
203
-				isset($auteurs[$id_auteur])
204
-				&& is_array($auteurs[$id_auteur])
205
-				&& array_pop($auteurs[$id_auteur]) > time() - 3600
206
-			) {
207
-				$objets_ouverts[] = [
208
-					'objet' => $objet,
209
-					'id_objet' => $id,
210
-				];
211
-			}
212
-		}
213
-	}
200
+    foreach ($edition as $objet => $data) {
201
+        foreach ($data as $id => $auteurs) {
202
+            if (
203
+                isset($auteurs[$id_auteur])
204
+                && is_array($auteurs[$id_auteur])
205
+                && array_pop($auteurs[$id_auteur]) > time() - 3600
206
+            ) {
207
+                $objets_ouverts[] = [
208
+                    'objet' => $objet,
209
+                    'id_objet' => $id,
210
+                ];
211
+            }
212
+        }
213
+    }
214 214
 
215
-	return $objets_ouverts;
215
+    return $objets_ouverts;
216 216
 }
217 217
 
218 218
 /**
@@ -225,15 +225,15 @@  discard block
 block discarded – undo
225 225
  * @return void
226 226
  */
227 227
 function debloquer_tous($id_auteur) {
228
-	$edition = lire_tableau_edition();
229
-	foreach ($edition as $objet => $data) {
230
-		foreach ($data as $id => $auteurs) {
231
-			if (isset($auteurs[$id_auteur])) {
232
-				unset($edition[$objet][$id][$id_auteur]);
233
-				ecrire_tableau_edition($edition);
234
-			}
235
-		}
236
-	}
228
+    $edition = lire_tableau_edition();
229
+    foreach ($edition as $objet => $data) {
230
+        foreach ($data as $id => $auteurs) {
231
+            if (isset($auteurs[$id_auteur])) {
232
+                unset($edition[$objet][$id][$id_auteur]);
233
+                ecrire_tableau_edition($edition);
234
+            }
235
+        }
236
+    }
237 237
 }
238 238
 
239 239
 /**
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
  * @return void
252 252
  */
253 253
 function debloquer_edition($id_auteur, $id_objet, $type = 'article') {
254
-	$edition = lire_tableau_edition();
254
+    $edition = lire_tableau_edition();
255 255
 
256
-	foreach ($edition as $objet => $data) {
257
-		if ($objet == $type) {
258
-			foreach ($data as $id => $auteurs) {
259
-				if (
260
-					$id == $id_objet
261
-					&& isset($auteurs[$id_auteur])
262
-				) {
263
-					unset($edition[$objet][$id][$id_auteur]);
264
-					ecrire_tableau_edition($edition);
265
-				}
266
-			}
267
-		}
268
-	}
256
+    foreach ($edition as $objet => $data) {
257
+        if ($objet == $type) {
258
+            foreach ($data as $id => $auteurs) {
259
+                if (
260
+                    $id == $id_objet
261
+                    && isset($auteurs[$id_auteur])
262
+                ) {
263
+                    unset($edition[$objet][$id][$id_auteur]);
264
+                    ecrire_tableau_edition($edition);
265
+                }
266
+            }
267
+        }
268
+    }
269 269
 }
Please login to merge, or discard this patch.
ecrire/inc/documents.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -29,12 +29,12 @@  discard block
 block discarded – undo
29 29
  * @return string
30 30
  */
31 31
 function set_spip_doc(?string $fichier): string {
32
-	if ($fichier && str_starts_with($fichier, (string) _DIR_IMG)) {
33
-		return substr($fichier, strlen((string) _DIR_IMG));
34
-	} else {
35
-		// ex: fichier distant
36
-		return $fichier ?? '';
37
-	}
32
+    if ($fichier && str_starts_with($fichier, (string) _DIR_IMG)) {
33
+        return substr($fichier, strlen((string) _DIR_IMG));
34
+    } else {
35
+        // ex: fichier distant
36
+        return $fichier ?? '';
37
+    }
38 38
 }
39 39
 
40 40
 /**
@@ -46,26 +46,26 @@  discard block
 block discarded – undo
46 46
  * @return bool|string
47 47
  */
48 48
 function get_spip_doc(?string $fichier) {
49
-	if ($fichier === null) {
50
-		return false;
51
-	}
52
-
53
-	// fichier distant
54
-	if (tester_url_absolue($fichier)) {
55
-		return $fichier;
56
-	}
57
-
58
-	// gestion d'erreurs, fichier=''
59
-	if (!strlen($fichier)) {
60
-		return false;
61
-	}
62
-
63
-	if (!str_starts_with($fichier, (string) _DIR_IMG)) {
64
-		$fichier = _DIR_IMG . $fichier;
65
-	}
66
-
67
-	// fichier normal
68
-	return $fichier;
49
+    if ($fichier === null) {
50
+        return false;
51
+    }
52
+
53
+    // fichier distant
54
+    if (tester_url_absolue($fichier)) {
55
+        return $fichier;
56
+    }
57
+
58
+    // gestion d'erreurs, fichier=''
59
+    if (!strlen($fichier)) {
60
+        return false;
61
+    }
62
+
63
+    if (!str_starts_with($fichier, (string) _DIR_IMG)) {
64
+        $fichier = _DIR_IMG . $fichier;
65
+    }
66
+
67
+    // fichier normal
68
+    return $fichier;
69 69
 }
70 70
 
71 71
 /**
@@ -79,26 +79,26 @@  discard block
 block discarded – undo
79 79
  * @return string
80 80
  */
81 81
 function creer_repertoire_documents($ext) {
82
-	$rep = sous_repertoire(_DIR_IMG, $ext);
83
-
84
-	if (!$ext || !$rep) {
85
-		spip_log("creer_repertoire_documents '$rep' interdit");
86
-		exit;
87
-	}
88
-
89
-	// Cette variable de configuration peut etre posee par un plugin
90
-	// par exemple acces_restreint
91
-	// sauf pour logo/ utilise pour stocker les logoon et logooff
92
-	if (
93
-		isset($GLOBALS['meta']['creer_htaccess'])
94
-		&& $GLOBALS['meta']['creer_htaccess'] == 'oui'
95
-		&& $ext !== 'logo'
96
-	) {
97
-		include_spip('inc/acces');
98
-		verifier_htaccess($rep);
99
-	}
100
-
101
-	return $rep;
82
+    $rep = sous_repertoire(_DIR_IMG, $ext);
83
+
84
+    if (!$ext || !$rep) {
85
+        spip_log("creer_repertoire_documents '$rep' interdit");
86
+        exit;
87
+    }
88
+
89
+    // Cette variable de configuration peut etre posee par un plugin
90
+    // par exemple acces_restreint
91
+    // sauf pour logo/ utilise pour stocker les logoon et logooff
92
+    if (
93
+        isset($GLOBALS['meta']['creer_htaccess'])
94
+        && $GLOBALS['meta']['creer_htaccess'] == 'oui'
95
+        && $ext !== 'logo'
96
+    ) {
97
+        include_spip('inc/acces');
98
+        verifier_htaccess($rep);
99
+    }
100
+
101
+    return $rep;
102 102
 }
103 103
 
104 104
 /**
@@ -107,19 +107,19 @@  discard block
 block discarded – undo
107 107
  * @param string $nom
108 108
  */
109 109
 function effacer_repertoire_temporaire($nom) {
110
-	if ($d = opendir($nom)) {
111
-		while (($f = readdir($d)) !== false) {
112
-			if (is_file("$nom/$f")) {
113
-				spip_unlink("$nom/$f");
114
-			} else {
115
-				if ($f != '.' && $f != '..' && is_dir("$nom/$f")) {
116
-					effacer_repertoire_temporaire("$nom/$f");
117
-				}
118
-			}
119
-		}
120
-	}
121
-	closedir($d);
122
-	@rmdir($nom);
110
+    if ($d = opendir($nom)) {
111
+        while (($f = readdir($d)) !== false) {
112
+            if (is_file("$nom/$f")) {
113
+                spip_unlink("$nom/$f");
114
+            } else {
115
+                if ($f != '.' && $f != '..' && is_dir("$nom/$f")) {
116
+                    effacer_repertoire_temporaire("$nom/$f");
117
+                }
118
+            }
119
+        }
120
+    }
121
+    closedir($d);
122
+    @rmdir($nom);
123 123
 }
124 124
 
125 125
 //
@@ -136,44 +136,44 @@  discard block
 block discarded – undo
136 136
  */
137 137
 function copier_document($ext, $orig, $source, $subdir = null) {
138 138
 
139
-	$orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
140
-	$dir = creer_repertoire_documents($subdir ?: $ext);
141
-
142
-	$dest = preg_replace('/<[^>]*>/', '', basename($orig));
143
-	$dest = preg_replace('/\.([^.]+)$/', '', $dest);
144
-	$dest = translitteration($dest);
145
-	$dest = preg_replace('/[^.=\w-]+/', '_', (string) $dest);
146
-
147
-	// ne pas accepter de noms de la forme -r90.jpg qui sont reserves
148
-	// pour les images transformees par rotation (action/documenter)
149
-	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
150
-
151
-	while (preg_match(',\.(\w+)$,', $dest, $m)) {
152
-		if (
153
-			!function_exists('verifier_upload_autorise')
154
-			|| !($r = verifier_upload_autorise($dest))
155
-			|| !empty($r['autozip'])
156
-		) {
157
-			$dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1];
158
-			break;
159
-		} else {
160
-			$dest = substr($dest, 0, -strlen($m[0]));
161
-			$ext = $m[1] . '.' . $ext;
162
-		}
163
-	}
164
-
165
-	// Si le document "source" est deja au bon endroit, ne rien faire
166
-	if ($source == ($dir . $dest . '.' . $ext)) {
167
-		return $source;
168
-	}
169
-
170
-	// sinon tourner jusqu'a trouver un numero correct
171
-	$n = 0;
172
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
173
-		;
174
-	}
175
-
176
-	return deplacer_fichier_upload($source, $newFile);
139
+    $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
140
+    $dir = creer_repertoire_documents($subdir ?: $ext);
141
+
142
+    $dest = preg_replace('/<[^>]*>/', '', basename($orig));
143
+    $dest = preg_replace('/\.([^.]+)$/', '', $dest);
144
+    $dest = translitteration($dest);
145
+    $dest = preg_replace('/[^.=\w-]+/', '_', (string) $dest);
146
+
147
+    // ne pas accepter de noms de la forme -r90.jpg qui sont reserves
148
+    // pour les images transformees par rotation (action/documenter)
149
+    $dest = preg_replace(',-r(90|180|270)$,', '', $dest);
150
+
151
+    while (preg_match(',\.(\w+)$,', $dest, $m)) {
152
+        if (
153
+            !function_exists('verifier_upload_autorise')
154
+            || !($r = verifier_upload_autorise($dest))
155
+            || !empty($r['autozip'])
156
+        ) {
157
+            $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1];
158
+            break;
159
+        } else {
160
+            $dest = substr($dest, 0, -strlen($m[0]));
161
+            $ext = $m[1] . '.' . $ext;
162
+        }
163
+    }
164
+
165
+    // Si le document "source" est deja au bon endroit, ne rien faire
166
+    if ($source == ($dir . $dest . '.' . $ext)) {
167
+        return $source;
168
+    }
169
+
170
+    // sinon tourner jusqu'a trouver un numero correct
171
+    $n = 0;
172
+    while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
173
+        ;
174
+    }
175
+
176
+    return deplacer_fichier_upload($source, $newFile);
177 177
 }
178 178
 
179 179
 /**
@@ -188,28 +188,28 @@  discard block
 block discarded – undo
188 188
  * @return bool|string
189 189
  */
190 190
 function determine_upload($type = '') {
191
-	if (!function_exists('autoriser')) {
192
-		include_spip('inc/autoriser');
193
-	}
194
-
195
-	if (
196
-		!autoriser('chargerftp')
197
-		|| $type == 'logos'
198
-	) { # on ne le permet pas pour les logos
199
-	return false;
200
-	}
201
-
202
-	$repertoire = _DIR_TRANSFERT;
203
-	if (!@is_dir($repertoire)) {
204
-		$repertoire = str_replace(_DIR_TMP, '', (string) $repertoire);
205
-		$repertoire = sous_repertoire(_DIR_TMP, $repertoire);
206
-	}
207
-
208
-	if (!$GLOBALS['visiteur_session']['restreint']) {
209
-		return $repertoire;
210
-	} else {
211
-		return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
212
-	}
191
+    if (!function_exists('autoriser')) {
192
+        include_spip('inc/autoriser');
193
+    }
194
+
195
+    if (
196
+        !autoriser('chargerftp')
197
+        || $type == 'logos'
198
+    ) { # on ne le permet pas pour les logos
199
+    return false;
200
+    }
201
+
202
+    $repertoire = _DIR_TRANSFERT;
203
+    if (!@is_dir($repertoire)) {
204
+        $repertoire = str_replace(_DIR_TMP, '', (string) $repertoire);
205
+        $repertoire = sous_repertoire(_DIR_TMP, $repertoire);
206
+    }
207
+
208
+    if (!$GLOBALS['visiteur_session']['restreint']) {
209
+        return $repertoire;
210
+    } else {
211
+        return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
212
+    }
213 213
 }
214 214
 
215 215
 /**
@@ -228,31 +228,31 @@  discard block
 block discarded – undo
228 228
  * @return bool|mixed|string
229 229
  */
230 230
 function deplacer_fichier_upload($source, $dest, $move = false) {
231
-	// Securite
232
-	if (str_starts_with($dest, (string) _DIR_RACINE)) {
233
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE)));
234
-	} else {
235
-		$dest = preg_replace(',\.\.+,', '.', $dest);
236
-	}
237
-
238
-	$ok = $move ? @rename($source, $dest) : @copy($source, $dest);
239
-	if (!$ok) {
240
-		$ok = @move_uploaded_file($source, $dest);
241
-	}
242
-	if ($ok) {
243
-		@chmod($dest, _SPIP_CHMOD & ~0111);
244
-	} else {
245
-		$f = @fopen($dest, 'w');
246
-		if ($f) {
247
-			fclose($f);
248
-		} else {
249
-			include_spip('inc/flock');
250
-			raler_fichier($dest);
251
-		}
252
-		spip_unlink($dest);
253
-	}
254
-
255
-	return $ok ? $dest : false;
231
+    // Securite
232
+    if (str_starts_with($dest, (string) _DIR_RACINE)) {
233
+        $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE)));
234
+    } else {
235
+        $dest = preg_replace(',\.\.+,', '.', $dest);
236
+    }
237
+
238
+    $ok = $move ? @rename($source, $dest) : @copy($source, $dest);
239
+    if (!$ok) {
240
+        $ok = @move_uploaded_file($source, $dest);
241
+    }
242
+    if ($ok) {
243
+        @chmod($dest, _SPIP_CHMOD & ~0111);
244
+    } else {
245
+        $f = @fopen($dest, 'w');
246
+        if ($f) {
247
+            fclose($f);
248
+        } else {
249
+            include_spip('inc/flock');
250
+            raler_fichier($dest);
251
+        }
252
+        spip_unlink($dest);
253
+    }
254
+
255
+    return $ok ? $dest : false;
256 256
 }
257 257
 
258 258
 
@@ -276,60 +276,60 @@  discard block
 block discarded – undo
276 276
  */
277 277
 function check_upload_error($error, $msg = '', $return = false) {
278 278
 
279
-	if (!$error) {
280
-		return false;
281
-	}
282
-
283
-	spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
284
-
285
-	switch ($error) {
286
-		case 4: /* UPLOAD_ERR_NO_FILE */
287
-			return true;
288
-
289
-		# on peut affiner les differents messages d'erreur
290
-		case 1: /* UPLOAD_ERR_INI_SIZE */
291
-			$msg = _T(
292
-				'upload_limit',
293
-				['max' => ini_get('upload_max_filesize')]
294
-			);
295
-			break;
296
-		case 2: /* UPLOAD_ERR_FORM_SIZE */
297
-			$msg = _T(
298
-				'upload_limit',
299
-				['max' => ini_get('upload_max_filesize')]
300
-			);
301
-			break;
302
-		case 3: /* UPLOAD_ERR_PARTIAL  */
303
-			$msg = _T(
304
-				'upload_limit',
305
-				['max' => ini_get('upload_max_filesize')]
306
-			);
307
-			break;
308
-
309
-		default: /* autre */
310
-			if (!$msg) {
311
-				$msg = _T('pass_erreur') . ' ' . $error
312
-					. '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
313
-			}
314
-			break;
315
-	}
316
-
317
-	spip_log("erreur upload $error");
318
-	if ($return) {
319
-		return $msg;
320
-	}
321
-
322
-	if (_request('iframe') == 'iframe') {
323
-		echo "<div class='upload_answer upload_error'>$msg</div>";
324
-		exit;
325
-	}
326
-
327
-	include_spip('inc/minipres');
328
-	echo minipres(
329
-		$msg,
330
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
331
-	);
332
-	exit;
279
+    if (!$error) {
280
+        return false;
281
+    }
282
+
283
+    spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
284
+
285
+    switch ($error) {
286
+        case 4: /* UPLOAD_ERR_NO_FILE */
287
+            return true;
288
+
289
+        # on peut affiner les differents messages d'erreur
290
+        case 1: /* UPLOAD_ERR_INI_SIZE */
291
+            $msg = _T(
292
+                'upload_limit',
293
+                ['max' => ini_get('upload_max_filesize')]
294
+            );
295
+            break;
296
+        case 2: /* UPLOAD_ERR_FORM_SIZE */
297
+            $msg = _T(
298
+                'upload_limit',
299
+                ['max' => ini_get('upload_max_filesize')]
300
+            );
301
+            break;
302
+        case 3: /* UPLOAD_ERR_PARTIAL  */
303
+            $msg = _T(
304
+                'upload_limit',
305
+                ['max' => ini_get('upload_max_filesize')]
306
+            );
307
+            break;
308
+
309
+        default: /* autre */
310
+            if (!$msg) {
311
+                $msg = _T('pass_erreur') . ' ' . $error
312
+                    . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
313
+            }
314
+            break;
315
+    }
316
+
317
+    spip_log("erreur upload $error");
318
+    if ($return) {
319
+        return $msg;
320
+    }
321
+
322
+    if (_request('iframe') == 'iframe') {
323
+        echo "<div class='upload_answer upload_error'>$msg</div>";
324
+        exit;
325
+    }
326
+
327
+    include_spip('inc/minipres');
328
+    echo minipres(
329
+        $msg,
330
+        "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
331
+    );
332
+    exit;
333 333
 }
334 334
 
335 335
 /**
@@ -346,14 +346,14 @@  discard block
 block discarded – undo
346 346
  * @return string
347 347
  */
348 348
 function corriger_extension($ext) {
349
-	$ext = preg_replace(',[^a-z0-9],i', '', $ext);
350
-
351
-	return match ($ext) {
352
-		'htm' => 'html',
353
-		'jpeg' => 'jpg',
354
-		'tiff' => 'tif',
355
-		'aif' => 'aiff',
356
-		'mpeg' => 'mpg',
357
-		default => $ext,
358
-	};
349
+    $ext = preg_replace(',[^a-z0-9],i', '', $ext);
350
+
351
+    return match ($ext) {
352
+        'htm' => 'html',
353
+        'jpeg' => 'jpg',
354
+        'tiff' => 'tif',
355
+        'aif' => 'aiff',
356
+        'mpeg' => 'mpg',
357
+        default => $ext,
358
+    };
359 359
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	}
62 62
 
63 63
 	if (!str_starts_with($fichier, (string) _DIR_IMG)) {
64
-		$fichier = _DIR_IMG . $fichier;
64
+		$fichier = _DIR_IMG.$fichier;
65 65
 	}
66 66
 
67 67
 	// fichier normal
@@ -154,22 +154,22 @@  discard block
 block discarded – undo
154 154
 			|| !($r = verifier_upload_autorise($dest))
155 155
 			|| !empty($r['autozip'])
156 156
 		) {
157
-			$dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1];
157
+			$dest = substr($dest, 0, -strlen($m[0])).'_'.$m[1];
158 158
 			break;
159 159
 		} else {
160 160
 			$dest = substr($dest, 0, -strlen($m[0]));
161
-			$ext = $m[1] . '.' . $ext;
161
+			$ext = $m[1].'.'.$ext;
162 162
 		}
163 163
 	}
164 164
 
165 165
 	// Si le document "source" est deja au bon endroit, ne rien faire
166
-	if ($source == ($dir . $dest . '.' . $ext)) {
166
+	if ($source == ($dir.$dest.'.'.$ext)) {
167 167
 		return $source;
168 168
 	}
169 169
 
170 170
 	// sinon tourner jusqu'a trouver un numero correct
171 171
 	$n = 0;
172
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
172
+	while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) {
173 173
 		;
174 174
 	}
175 175
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 function deplacer_fichier_upload($source, $dest, $move = false) {
231 231
 	// Securite
232 232
 	if (str_starts_with($dest, (string) _DIR_RACINE)) {
233
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE)));
233
+		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE)));
234 234
 	} else {
235 235
 		$dest = preg_replace(',\.\.+,', '.', $dest);
236 236
 	}
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 
309 309
 		default: /* autre */
310 310
 			if (!$msg) {
311
-				$msg = _T('pass_erreur') . ' ' . $error
312
-					. '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
311
+				$msg = _T('pass_erreur').' '.$error
312
+					. '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
313 313
 			}
314 314
 			break;
315 315
 	}
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 	include_spip('inc/minipres');
328 328
 	echo minipres(
329 329
 		$msg,
330
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
330
+		"<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode((string) $GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>'
331 331
 	);
332 332
 	exit;
333 333
 }
Please login to merge, or discard this patch.
ecrire/inc/meta.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 // Les parametres generaux du site sont dans une table SQL;
@@ -26,51 +26,51 @@  discard block
 block discarded – undo
26 26
 define('_META_CACHE_TIME', 1 << 24);
27 27
 
28 28
 function inc_meta_dist($table = 'meta') {
29
-	$new = null;
30
-	// Lire les meta, en cache si present, valide et lisible
31
-	// en cas d'install ne pas faire confiance au meta_cache eventuel
32
-	$cache = cache_meta($table);
29
+    $new = null;
30
+    // Lire les meta, en cache si present, valide et lisible
31
+    // en cas d'install ne pas faire confiance au meta_cache eventuel
32
+    $cache = cache_meta($table);
33 33
 
34
-	if (
35
-		(!($exec = _request('exec')) || !autoriser_sans_cookie($exec))
36
-		 && ($new = jeune_fichier($cache, _META_CACHE_TIME))
37
-		 && lire_fichier_securise($cache, $meta)
38
-		 && ($meta = @unserialize($meta))
39
-	) {
40
-		$GLOBALS[$table] = $meta;
41
-	}
34
+    if (
35
+        (!($exec = _request('exec')) || !autoriser_sans_cookie($exec))
36
+         && ($new = jeune_fichier($cache, _META_CACHE_TIME))
37
+         && lire_fichier_securise($cache, $meta)
38
+         && ($meta = @unserialize($meta))
39
+    ) {
40
+        $GLOBALS[$table] = $meta;
41
+    }
42 42
 
43
-	if (
44
-		isset($GLOBALS[$table]['touch'])
45
-		&& $GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME
46
-	) {
47
-		$GLOBALS[$table] = [];
48
-	}
49
-	// sinon lire en base
50
-	if (!$GLOBALS[$table]) {
51
-		$new = !lire_metas($table);
52
-	}
43
+    if (
44
+        isset($GLOBALS[$table]['touch'])
45
+        && $GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME
46
+    ) {
47
+        $GLOBALS[$table] = [];
48
+    }
49
+    // sinon lire en base
50
+    if (!$GLOBALS[$table]) {
51
+        $new = !lire_metas($table);
52
+    }
53 53
 
54
-	// renouveller l'alea general si trop vieux ou sur demande explicite
55
-	if (
56
-		(test_espace_prive() || isset($_GET['renouvelle_alea']))
57
-		&& $GLOBALS[$table]
58
-		&& time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0)
59
-	) {
60
-		// si on n'a pas l'acces en ecriture sur le cache,
61
-		// ne pas renouveller l'alea sinon le cache devient faux
62
-		if (supprimer_fichier($cache)) {
63
-			include_spip('inc/acces');
64
-			renouvelle_alea();
65
-			$new = false;
66
-		} else {
67
-			spip_log("impossible d'ecrire dans " . $cache);
68
-		}
69
-	}
70
-	// et refaire le cache si on a du lire en base
71
-	if (!$new) {
72
-		touch_meta(false, $table);
73
-	}
54
+    // renouveller l'alea general si trop vieux ou sur demande explicite
55
+    if (
56
+        (test_espace_prive() || isset($_GET['renouvelle_alea']))
57
+        && $GLOBALS[$table]
58
+        && time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0)
59
+    ) {
60
+        // si on n'a pas l'acces en ecriture sur le cache,
61
+        // ne pas renouveller l'alea sinon le cache devient faux
62
+        if (supprimer_fichier($cache)) {
63
+            include_spip('inc/acces');
64
+            renouvelle_alea();
65
+            $new = false;
66
+        } else {
67
+            spip_log("impossible d'ecrire dans " . $cache);
68
+        }
69
+    }
70
+    // et refaire le cache si on a du lire en base
71
+    if (!$new) {
72
+        touch_meta(false, $table);
73
+    }
74 74
 }
75 75
 
76 76
 // fonctions aussi appelees a l'install ==> spip_query en premiere requete
@@ -78,39 +78,39 @@  discard block
 block discarded – undo
78 78
 
79 79
 function lire_metas($table = 'meta') {
80 80
 
81
-	if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) {
82
-		include_spip('base/abstract_sql');
83
-		$GLOBALS[$table] = [];
84
-		while ($row = sql_fetch($result)) {
85
-			$GLOBALS[$table][$row['nom']] = $row['valeur'];
86
-		}
87
-		sql_free($result);
81
+    if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) {
82
+        include_spip('base/abstract_sql');
83
+        $GLOBALS[$table] = [];
84
+        while ($row = sql_fetch($result)) {
85
+            $GLOBALS[$table][$row['nom']] = $row['valeur'];
86
+        }
87
+        sql_free($result);
88 88
 
89
-		if (
90
-			!isset($GLOBALS[$table]['charset'])
91
-			|| !$GLOBALS[$table]['charset']
92
-			|| $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install
93
-		) {
94
-			ecrire_meta('charset', _DEFAULT_CHARSET, null, $table);
95
-		}
89
+        if (
90
+            !isset($GLOBALS[$table]['charset'])
91
+            || !$GLOBALS[$table]['charset']
92
+            || $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install
93
+        ) {
94
+            ecrire_meta('charset', _DEFAULT_CHARSET, null, $table);
95
+        }
96 96
 
97
-		// noter cette table de configuration dans les meta de SPIP
98
-		if ($table !== 'meta') {
99
-			$liste = [];
100
-			if (isset($GLOBALS['meta']['tables_config'])) {
101
-				$liste = unserialize($GLOBALS['meta']['tables_config']);
102
-			}
103
-			if (!$liste) {
104
-				$liste = [];
105
-			}
106
-			if (!in_array($table, $liste)) {
107
-				$liste[] = $table;
108
-				ecrire_meta('tables_config', serialize($liste));
109
-			}
110
-		}
111
-	}
97
+        // noter cette table de configuration dans les meta de SPIP
98
+        if ($table !== 'meta') {
99
+            $liste = [];
100
+            if (isset($GLOBALS['meta']['tables_config'])) {
101
+                $liste = unserialize($GLOBALS['meta']['tables_config']);
102
+            }
103
+            if (!$liste) {
104
+                $liste = [];
105
+            }
106
+            if (!in_array($table, $liste)) {
107
+                $liste[] = $table;
108
+                ecrire_meta('tables_config', serialize($liste));
109
+            }
110
+        }
111
+    }
112 112
 
113
-	return $GLOBALS[$table] ?? null;
113
+    return $GLOBALS[$table] ?? null;
114 114
 }
115 115
 
116 116
 
@@ -124,22 +124,22 @@  discard block
 block discarded – undo
124 124
  *      Table SQL d'enregistrement des meta.
125 125
  **/
126 126
 function touch_meta($antidate = false, $table = 'meta') {
127
-	$file = cache_meta($table);
128
-	if (!$antidate || !@touch($file, $antidate)) {
129
-		$r = $GLOBALS[$table] ?? [];
130
-		if ($table == 'meta') {
131
-			unset($r['alea_ephemere']);
132
-			unset($r['alea_ephemere_ancien']);
133
-			// le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables
134
-			// mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique
135
-			// meme si son squelette est en cache
136
-			//unset($r['secret_du_site']);
137
-			if ($antidate) {
138
-				$r['touch'] = $antidate;
139
-			}
140
-		}
141
-		ecrire_fichier_securise($file, serialize($r));
142
-	}
127
+    $file = cache_meta($table);
128
+    if (!$antidate || !@touch($file, $antidate)) {
129
+        $r = $GLOBALS[$table] ?? [];
130
+        if ($table == 'meta') {
131
+            unset($r['alea_ephemere']);
132
+            unset($r['alea_ephemere_ancien']);
133
+            // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables
134
+            // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique
135
+            // meme si son squelette est en cache
136
+            //unset($r['secret_du_site']);
137
+            if ($antidate) {
138
+                $r['touch'] = $antidate;
139
+            }
140
+        }
141
+        ecrire_fichier_securise($file, serialize($r));
142
+    }
143 143
 }
144 144
 
145 145
 /**
@@ -155,21 +155,21 @@  discard block
 block discarded – undo
155 155
  *     Table SQL d'enregistrement de la meta.
156 156
  **/
157 157
 function effacer_meta($nom, $table = 'meta') {
158
-	// section critique sur le cache:
159
-	// l'invalider avant et apres la MAJ de la BD
160
-	// c'est un peu moins bien qu'un vrai verrou mais ca suffira
161
-	// et utiliser une statique pour eviter des acces disques a repetition
162
-	static $touch = [];
163
-	$antidate = time() - (_META_CACHE_TIME << 4);
164
-	if (!isset($touch[$table])) {
165
-		touch_meta($antidate, $table);
166
-	}
167
-	sql_delete('spip_' . $table, "nom='$nom'", '', 'continue');
168
-	unset($GLOBALS[$table][$nom]);
169
-	if (!isset($touch[$table])) {
170
-		touch_meta($antidate, $table);
171
-		$touch[$table] = false;
172
-	}
158
+    // section critique sur le cache:
159
+    // l'invalider avant et apres la MAJ de la BD
160
+    // c'est un peu moins bien qu'un vrai verrou mais ca suffira
161
+    // et utiliser une statique pour eviter des acces disques a repetition
162
+    static $touch = [];
163
+    $antidate = time() - (_META_CACHE_TIME << 4);
164
+    if (!isset($touch[$table])) {
165
+        touch_meta($antidate, $table);
166
+    }
167
+    sql_delete('spip_' . $table, "nom='$nom'", '', 'continue');
168
+    unset($GLOBALS[$table][$nom]);
169
+    if (!isset($touch[$table])) {
170
+        touch_meta($antidate, $table);
171
+        $touch[$table] = false;
172
+    }
173 173
 }
174 174
 
175 175
 /**
@@ -191,54 +191,54 @@  discard block
 block discarded – undo
191 191
  **/
192 192
 function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') {
193 193
 
194
-	static $touch = [];
195
-	if (!$nom) {
196
-		return;
197
-	}
198
-	include_spip('base/abstract_sql');
199
-	$res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue');
200
-	// table pas encore installee, travailler en php seulement
201
-	if (!$res) {
202
-		$GLOBALS[$table][$nom] = $valeur;
194
+    static $touch = [];
195
+    if (!$nom) {
196
+        return;
197
+    }
198
+    include_spip('base/abstract_sql');
199
+    $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue');
200
+    // table pas encore installee, travailler en php seulement
201
+    if (!$res) {
202
+        $GLOBALS[$table][$nom] = $valeur;
203 203
 
204
-		return;
205
-	}
206
-	$row = sql_fetch($res);
207
-	sql_free($res);
204
+        return;
205
+    }
206
+    $row = sql_fetch($res);
207
+    sql_free($res);
208 208
 
209
-	// ne pas invalider le cache si affectation a l'identique
210
-	// (tant pis si impt aurait du changer)
211
-	if (
212
-		$row
213
-		&& $valeur == $row['valeur']
214
-		&& isset($GLOBALS[$table][$nom])
215
-		&& $GLOBALS[$table][$nom] == $valeur
216
-	) {
217
-		return;
218
-	}
209
+    // ne pas invalider le cache si affectation a l'identique
210
+    // (tant pis si impt aurait du changer)
211
+    if (
212
+        $row
213
+        && $valeur == $row['valeur']
214
+        && isset($GLOBALS[$table][$nom])
215
+        && $GLOBALS[$table][$nom] == $valeur
216
+    ) {
217
+        return;
218
+    }
219 219
 
220
-	$GLOBALS[$table][$nom] = $valeur;
221
-	// cf effacer pour comprendre le double touch
222
-	$antidate = time() - (_META_CACHE_TIME << 1);
223
-	if (!isset($touch[$table])) {
224
-		touch_meta($antidate, $table);
225
-	}
226
-	$r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')];
227
-	// Gaffe aux tables sans impt (vieilles versions de SPIP notamment)
228
-	// ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot
229
-	// de lecture des descriptions des tables
230
-	if ($importable && isset($row['impt'])) {
231
-		$r['impt'] = sql_quote($importable, '', 'text');
232
-	}
233
-	if ($row) {
234
-		sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom));
235
-	} else {
236
-		sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')');
237
-	}
238
-	if (!isset($touch[$table])) {
239
-		touch_meta($antidate, $table);
240
-		$touch[$table] = false;
241
-	}
220
+    $GLOBALS[$table][$nom] = $valeur;
221
+    // cf effacer pour comprendre le double touch
222
+    $antidate = time() - (_META_CACHE_TIME << 1);
223
+    if (!isset($touch[$table])) {
224
+        touch_meta($antidate, $table);
225
+    }
226
+    $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')];
227
+    // Gaffe aux tables sans impt (vieilles versions de SPIP notamment)
228
+    // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot
229
+    // de lecture des descriptions des tables
230
+    if ($importable && isset($row['impt'])) {
231
+        $r['impt'] = sql_quote($importable, '', 'text');
232
+    }
233
+    if ($row) {
234
+        sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom));
235
+    } else {
236
+        sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')');
237
+    }
238
+    if (!isset($touch[$table])) {
239
+        touch_meta($antidate, $table);
240
+        $touch[$table] = false;
241
+    }
242 242
 }
243 243
 
244 244
 /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
  *     Nom du fichier cache
251 251
  **/
252 252
 function cache_meta($table = 'meta') {
253
-	return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php');
253
+    return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php');
254 254
 }
255 255
 
256 256
 /**
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
  * @param string $table
260 260
  */
261 261
 function installer_table_meta($table) {
262
-	$trouver_table = charger_fonction('trouver_table', 'base');
263
-	if (!$trouver_table("spip_$table")) {
264
-		include_spip('base/auxiliaires');
265
-		include_spip('base/create');
266
-		creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false);
267
-		$trouver_table('');
268
-	}
269
-	lire_metas($table);
262
+    $trouver_table = charger_fonction('trouver_table', 'base');
263
+    if (!$trouver_table("spip_$table")) {
264
+        include_spip('base/auxiliaires');
265
+        include_spip('base/create');
266
+        creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false);
267
+        $trouver_table('');
268
+    }
269
+    lire_metas($table);
270 270
 }
271 271
 
272 272
 /**
@@ -278,44 +278,44 @@  discard block
 block discarded – undo
278 278
  * @param bool $force
279 279
  */
280 280
 function supprimer_table_meta($table, $force = false) {
281
-	if ($table !== 'meta') {
282
-		// Vérifier le contenu restant de la table
283
-		$nb_variables = sql_countsel("spip_$table");
281
+    if ($table !== 'meta') {
282
+        // Vérifier le contenu restant de la table
283
+        $nb_variables = sql_countsel("spip_$table");
284 284
 
285
-		// Supprimer si :
286
-		// - la table est vide
287
-		// - ou limitée à la variable charset
288
-		// - ou qu'on force la suppression
289
-		if (
290
-			$force
291
-			|| !$nb_variables
292
-			|| $nb_variables == 1 && isset($GLOBALS[$table]['charset'])
293
-		) {
294
-			// Supprimer la table des globaleset de la base
295
-			unset($GLOBALS[$table]);
296
-			sql_drop_table("spip_$table");
297
-			// Supprimer le fichier cache
298
-			include_spip('inc/flock');
299
-			$cache = cache_meta($table);
300
-			supprimer_fichier($cache);
285
+        // Supprimer si :
286
+        // - la table est vide
287
+        // - ou limitée à la variable charset
288
+        // - ou qu'on force la suppression
289
+        if (
290
+            $force
291
+            || !$nb_variables
292
+            || $nb_variables == 1 && isset($GLOBALS[$table]['charset'])
293
+        ) {
294
+            // Supprimer la table des globaleset de la base
295
+            unset($GLOBALS[$table]);
296
+            sql_drop_table("spip_$table");
297
+            // Supprimer le fichier cache
298
+            include_spip('inc/flock');
299
+            $cache = cache_meta($table);
300
+            supprimer_fichier($cache);
301 301
 
302
-			// vider le cache des tables
303
-			$trouver_table = charger_fonction('trouver_table', 'base');
304
-			$trouver_table('');
302
+            // vider le cache des tables
303
+            $trouver_table = charger_fonction('trouver_table', 'base');
304
+            $trouver_table('');
305 305
 
306
-			// Supprimer la table de la liste des tables de configuration autres que spip_meta
307
-			if (isset($GLOBALS['meta']['tables_config'])) {
308
-				$liste = unserialize($GLOBALS['meta']['tables_config']);
309
-				$cle = array_search($table, $liste);
310
-				if ($cle !== false) {
311
-					unset($liste[$cle]);
312
-					if ($liste) {
313
-						ecrire_meta('tables_config', serialize($liste));
314
-					} else {
315
-						effacer_meta('tables_config');
316
-					}
317
-				}
318
-			}
319
-		}
320
-	}
306
+            // Supprimer la table de la liste des tables de configuration autres que spip_meta
307
+            if (isset($GLOBALS['meta']['tables_config'])) {
308
+                $liste = unserialize($GLOBALS['meta']['tables_config']);
309
+                $cle = array_search($table, $liste);
310
+                if ($cle !== false) {
311
+                    unset($liste[$cle]);
312
+                    if ($liste) {
313
+                        ecrire_meta('tables_config', serialize($liste));
314
+                    } else {
315
+                        effacer_meta('tables_config');
316
+                    }
317
+                }
318
+            }
319
+        }
320
+    }
321 321
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 			renouvelle_alea();
65 65
 			$new = false;
66 66
 		} else {
67
-			spip_log("impossible d'ecrire dans " . $cache);
67
+			spip_log("impossible d'ecrire dans ".$cache);
68 68
 		}
69 69
 	}
70 70
 	// et refaire le cache si on a du lire en base
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	if (!isset($touch[$table])) {
165 165
 		touch_meta($antidate, $table);
166 166
 	}
167
-	sql_delete('spip_' . $table, "nom='$nom'", '', 'continue');
167
+	sql_delete('spip_'.$table, "nom='$nom'", '', 'continue');
168 168
 	unset($GLOBALS[$table][$nom]);
169 169
 	if (!isset($touch[$table])) {
170 170
 		touch_meta($antidate, $table);
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		return;
197 197
 	}
198 198
 	include_spip('base/abstract_sql');
199
-	$res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue');
199
+	$res = sql_select('*', 'spip_'.$table, 'nom='.sql_quote($nom), '', '', '', '', '', 'continue');
200 200
 	// table pas encore installee, travailler en php seulement
201 201
 	if (!$res) {
202 202
 		$GLOBALS[$table][$nom] = $valeur;
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 		$r['impt'] = sql_quote($importable, '', 'text');
232 232
 	}
233 233
 	if ($row) {
234
-		sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom));
234
+		sql_update('spip_'.$table, $r, 'nom='.sql_quote($nom));
235 235
 	} else {
236
-		sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')');
236
+		sql_insert('spip_'.$table, '('.implode(',', array_keys($r)).')', '('.implode(',', array_values($r)).')');
237 237
 	}
238 238
 	if (!isset($touch[$table])) {
239 239
 		touch_meta($antidate, $table);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
  *     Nom du fichier cache
251 251
  **/
252 252
 function cache_meta($table = 'meta') {
253
-	return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php');
253
+	return ($table == 'meta') ? _FILE_META : (_DIR_CACHE.$table.'.php');
254 254
 }
255 255
 
256 256
 /**
Please login to merge, or discard this patch.
ecrire/inc/definir_menus_favoris.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,19 +19,19 @@
 block discarded – undo
19 19
  * Retourne la liste des menus favoris par défaut ainsi que leur rang
20 20
  */
21 21
 function inc_definir_menus_favoris_dist() {
22
-	return [
22
+    return [
23 23
 
24
-		// Menu Édition,
25
-		'auteurs' => 1,
26
-		'rubriques' => 2,
27
-		'articles' => 3,
24
+        // Menu Édition,
25
+        'auteurs' => 1,
26
+        'rubriques' => 2,
27
+        'articles' => 3,
28 28
 
29
-		// Menu Maintenance
30
-		'admin_vider' => 1,
29
+        // Menu Maintenance
30
+        'admin_vider' => 1,
31 31
 
32
-		// Menu Configurations
33
-		'configurer_identite' => 1,
34
-		'admin_plugin' => 2,
32
+        // Menu Configurations
33
+        'configurer_identite' => 1,
34
+        'admin_plugin' => 2,
35 35
 
36
-	];
36
+    ];
37 37
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 2 patches
Indentation   +1287 added lines, -1287 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
 include_spip('inc/filtres'); // par precaution
23 23
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
  *     Le code de la couleur en hexadécimal.
38 38
  */
39 39
 function _couleur_dec_to_hex($red, $green, $blue) {
40
-	$red = dechex($red);
41
-	$green = dechex($green);
42
-	$blue = dechex($blue);
43
-
44
-	if (strlen($red) == 1) {
45
-		$red = '0' . $red;
46
-	}
47
-	if (strlen($green) == 1) {
48
-		$green = '0' . $green;
49
-	}
50
-	if (strlen($blue) == 1) {
51
-		$blue = '0' . $blue;
52
-	}
53
-
54
-	return "$red$green$blue";
40
+    $red = dechex($red);
41
+    $green = dechex($green);
42
+    $blue = dechex($blue);
43
+
44
+    if (strlen($red) == 1) {
45
+        $red = '0' . $red;
46
+    }
47
+    if (strlen($green) == 1) {
48
+        $green = '0' . $green;
49
+    }
50
+    if (strlen($blue) == 1) {
51
+        $blue = '0' . $blue;
52
+    }
53
+
54
+    return "$red$green$blue";
55 55
 }
56 56
 
57 57
 /**
@@ -63,18 +63,18 @@  discard block
 block discarded – undo
63 63
  *     Un tableau des 3 éléments : rouge, vert, bleu.
64 64
  */
65 65
 function _couleur_hex_to_dec($couleur) {
66
-	$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;
66
+    $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;
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,55 +120,55 @@  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
-		$S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min);
141
-
142
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
143
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
144
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
145
-
146
-		if ($var_R === $var_Max) {
147
-			$H = $del_B - $del_G;
148
-		} else {
149
-			if ($var_G === $var_Max) {
150
-				$H = (1 / 3) + $del_R - $del_B;
151
-			} else {
152
-				if ($var_B === $var_Max) {
153
-					$H = (2 / 3) + $del_G - $del_R;
154
-				}
155
-			}
156
-		}
157
-
158
-		if ($H < 0) {
159
-			$H += 1;
160
-		}
161
-		if ($H > 1) {
162
-			$H -= 1;
163
-		}
164
-	}
165
-
166
-	$ret = [];
167
-	$ret['h'] = $H;
168
-	$ret['s'] = $S;
169
-	$ret['l'] = $L;
170
-
171
-	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
+        $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min);
141
+
142
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
143
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
144
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
145
+
146
+        if ($var_R === $var_Max) {
147
+            $H = $del_B - $del_G;
148
+        } else {
149
+            if ($var_G === $var_Max) {
150
+                $H = (1 / 3) + $del_R - $del_B;
151
+            } else {
152
+                if ($var_B === $var_Max) {
153
+                    $H = (2 / 3) + $del_G - $del_R;
154
+                }
155
+            }
156
+        }
157
+
158
+        if ($H < 0) {
159
+            $H += 1;
160
+        }
161
+        if ($H > 1) {
162
+            $H -= 1;
163
+        }
164
+    }
165
+
166
+    $ret = [];
167
+    $ret['h'] = $H;
168
+    $ret['s'] = $S;
169
+    $ret['l'] = $L;
170
+
171
+    return $ret;
172 172
 }
173 173
 
174 174
 
@@ -184,48 +184,48 @@  discard block
 block discarded – undo
184 184
  * @return array
185 185
  */
186 186
 function _couleur_hsl_to_rgb($H, $S, $L) {
187
-	// helper
188
-	$hue_2_rgb = function ($v1, $v2, $vH) {
189
-		if ($vH < 0) {
190
-			$vH += 1;
191
-		}
192
-		if ($vH > 1) {
193
-			$vH -= 1;
194
-		}
195
-		if ((6 * $vH) < 1) {
196
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
197
-		}
198
-		if ((2 * $vH) < 1) {
199
-			return ($v2);
200
-		}
201
-		if ((3 * $vH) < 2) {
202
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
203
-		}
204
-
205
-		return ($v1);
206
-	};
207
-
208
-	if ($S == 0) {
209
-		// HSV values = 0 -> 1
210
-		$R = $L * 255;
211
-		$G = $L * 255;
212
-		$B = $L * 255;
213
-	} else {
214
-		$var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L);
215
-
216
-		$var_1 = 2 * $L - $var_2;
217
-
218
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
219
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
220
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
221
-	}
222
-
223
-	$ret = [];
224
-	$ret['r'] = floor($R);
225
-	$ret['g'] = floor($G);
226
-	$ret['b'] = floor($B);
227
-
228
-	return $ret;
187
+    // helper
188
+    $hue_2_rgb = function ($v1, $v2, $vH) {
189
+        if ($vH < 0) {
190
+            $vH += 1;
191
+        }
192
+        if ($vH > 1) {
193
+            $vH -= 1;
194
+        }
195
+        if ((6 * $vH) < 1) {
196
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
197
+        }
198
+        if ((2 * $vH) < 1) {
199
+            return ($v2);
200
+        }
201
+        if ((3 * $vH) < 2) {
202
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
203
+        }
204
+
205
+        return ($v1);
206
+    };
207
+
208
+    if ($S == 0) {
209
+        // HSV values = 0 -> 1
210
+        $R = $L * 255;
211
+        $G = $L * 255;
212
+        $B = $L * 255;
213
+    } else {
214
+        $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L);
215
+
216
+        $var_1 = 2 * $L - $var_2;
217
+
218
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
219
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
220
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
221
+    }
222
+
223
+    $ret = [];
224
+    $ret['r'] = floor($R);
225
+    $ret['g'] = floor($G);
226
+    $ret['b'] = floor($B);
227
+
228
+    return $ret;
229 229
 }
230 230
 
231 231
 /**
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
  *     true si il faut supprimer le fichier temporaire ; false sinon.
244 244
  */
245 245
 function statut_effacer_images_temporaires($stat) {
246
-	static $statut = false; // par defaut on grave toute les images
247
-	if ($stat === 'get') {
248
-		return $statut;
249
-	}
250
-	$statut = (bool) $stat;
246
+    static $statut = false; // par defaut on grave toute les images
247
+    if ($stat === 'get') {
248
+        return $statut;
249
+    }
250
+    $statut = (bool) $stat;
251 251
 }
252 252
 
253 253
 
@@ -300,251 +300,251 @@  discard block
 block discarded – undo
300 300
  *     - array : tableau décrivant de l'image
301 301
  */
302 302
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
303
-	$valeurs = [];
304
-	$ret = [];
305
-	$f = null;
306
-	static $images_recalcul = [];
307
-	if (strlen($img) == 0) {
308
-		return false;
309
-	}
310
-
311
-	$source = trim(extraire_attribut($img, 'src') ?? '');
312
-	if (strlen($source) < 1) {
313
-		if (!str_starts_with($img, '<img ')) {
314
-			$source = $img;
315
-			$img = "<img src='$source' />";
316
-		} else {
317
-			// pas d'attribut src sur cette balise <img../>
318
-			return false;
319
-		}
320
-	} elseif (
321
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
-		&& ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
323
-		&& in_array($extension, _image_extensions_acceptees_en_entree())
324
-	) {
325
-		# gerer img src="data:....base64"
326
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
-		if (!file_exists($local)) {
328
-			ecrire_fichier($local, base64_decode($regs[2]));
329
-		}
330
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
331
-			$sanitizer($local);
332
-		}
333
-		$source = $local;
334
-		$img = inserer_attribut($img, 'src', $source);
335
-		# eviter les mauvaises surprises lors de conversions de format
336
-		$img = inserer_attribut($img, 'width', '');
337
-		$img = inserer_attribut($img, 'height', '');
338
-	}
339
-
340
-	// les protocoles web prennent au moins 3 lettres
341
-	if (tester_url_absolue($source)) {
342
-		include_spip('inc/distant');
343
-		$fichier = _DIR_RACINE . copie_locale($source);
344
-		if (!$fichier) {
345
-			return '';
346
-		}
347
-		if (
348
-			($extension = _image_trouver_extension($fichier))
349
-			&& ($sanitizer = charger_fonction($extension, 'sanitizer', true))
350
-		) {
351
-			$sanitizer($fichier);
352
-		}
353
-	} else {
354
-		// enlever le timestamp eventuel
355
-		if (str_contains($source, '?')) {
356
-			$source = preg_replace(',[?]\d+$,', '', $source);
357
-		}
358
-		if (
359
-			str_contains($source, '?')
360
-			&& str_starts_with($source, (string) _DIR_IMG)
361
-			&& file_exists($f = preg_replace(',[?].*$,', '', $source))
362
-		) {
363
-			$source = $f;
364
-		}
365
-		$fichier = $source;
366
-	}
367
-
368
-	$terminaison_dest = '';
369
-	if ($terminaison = _image_trouver_extension($fichier)) {
370
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
371
-	}
372
-
373
-	if (
374
-		$forcer_format !== false
375
-		&& ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
376
-	) {
377
-		$terminaison_dest = $forcer_format;
378
-	}
379
-
380
-	if (!$terminaison_dest) {
381
-		return false;
382
-	}
383
-
384
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
385
-	$fichier_dest = $nom_fichier;
386
-	if (
387
-		$find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f)
388
-		|| @file_exists($f = $fichier)
389
-	) {
390
-		// on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance
391
-		// on lit directement les infos du fichier
392
-		[$ret['hauteur'], $ret['largeur']] = taille_image($f);
393
-		$date_src = @filemtime($f);
394
-	} elseif (
395
-		@file_exists($f = "$fichier.src")
396
-		&& lire_fichier($f, $valeurs)
397
-		&& ($valeurs = unserialize($valeurs))
398
-		&& isset($valeurs['hauteur_dest'])
399
-		&& isset($valeurs['largeur_dest'])
400
-	) {
401
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
402
-		$ret['largeur'] = $valeurs['largeur_dest'];
403
-		$date_src = $valeurs['date'];
404
-	} // pas de fichier source par la
405
-	else {
406
-		return false;
407
-	}
408
-
409
-	// pas de taille mesurable ?
410
-	if (
411
-		!$ret['hauteur']
412
-		|| !($ret['hauteur'] = (int) round($ret['hauteur']))
413
-		|| !$ret['largeur']
414
-		|| !($ret['largeur'] = (int) round($ret['largeur']))
415
-	) {
416
-		return false;
417
-	}
418
-
419
-	// les images calculees dependent du chemin du fichier source
420
-	// 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
421
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
422
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
423
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
424
-	// alors que ca concerne peu de site au final
425
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
426
-	$identifiant = $fichier;
427
-
428
-	// cas general :
429
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
430
-	// cas particulier de reduire :
431
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
432
-	$cache = 'cache-gd2';
433
-	if (str_starts_with($effet, 'reduire')) {
434
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
435
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
436
-		$ret['largeur_dest'] = $destWidth;
437
-		$ret['hauteur_dest'] = $destHeight;
438
-		$effet = "L{$destWidth}xH$destHeight";
439
-		$cache = 'cache-vignettes';
440
-		$fichier_dest = basename($fichier_dest);
441
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
442
-			// on garde la terminaison initiale car image simplement copiee
443
-			// et on postfixe son nom avec un md5 du path
444
-			$terminaison_dest = $terminaison;
445
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
446
-		} else {
447
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
448
-		}
449
-		$cache = sous_repertoire(_DIR_VAR, $cache);
450
-		$cache = sous_repertoire($cache, $effet);
451
-	} else {
452
-		$fichier_dest = md5("$identifiant-$effet");
453
-		$cache = sous_repertoire(_DIR_VAR, $cache);
454
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
455
-		$fichier_dest = substr($fichier_dest, 2);
456
-	}
457
-
458
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
459
-
460
-	$GLOBALS['images_calculees'][] = $fichier_dest;
461
-
462
-	$creer = true;
463
-	// si recalcul des images demande, recalculer chaque image une fois
464
-	if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) {
465
-		$images_recalcul[$fichier_dest] = true;
466
-	} else {
467
-		if (@file_exists($f = $fichier_dest)) {
468
-			if (filemtime($f) >= $date_src) {
469
-				$creer = false;
470
-			}
471
-		} else {
472
-			if (
473
-				@file_exists($f = "$fichier_dest.src")
474
-				&& lire_fichier($f, $valeurs)
475
-				&& ($valeurs = unserialize($valeurs))
476
-				&& $valeurs['date'] >= $date_src
477
-			) {
478
-				$creer = false;
479
-			}
480
-		}
481
-	}
482
-	if ($creer && !@file_exists($fichier)) {
483
-		if (!@file_exists("$fichier.src")) {
484
-			spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR);
485
-
486
-			return false;
487
-		}
488
-		# on reconstruit l'image source absente a partir de la chaine des .src
489
-		reconstruire_image_intermediaire($fichier);
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 && !$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;
303
+    $valeurs = [];
304
+    $ret = [];
305
+    $f = null;
306
+    static $images_recalcul = [];
307
+    if (strlen($img) == 0) {
308
+        return false;
309
+    }
310
+
311
+    $source = trim(extraire_attribut($img, 'src') ?? '');
312
+    if (strlen($source) < 1) {
313
+        if (!str_starts_with($img, '<img ')) {
314
+            $source = $img;
315
+            $img = "<img src='$source' />";
316
+        } else {
317
+            // pas d'attribut src sur cette balise <img../>
318
+            return false;
319
+        }
320
+    } elseif (
321
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
+        && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
323
+        && in_array($extension, _image_extensions_acceptees_en_entree())
324
+    ) {
325
+        # gerer img src="data:....base64"
326
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
+        if (!file_exists($local)) {
328
+            ecrire_fichier($local, base64_decode($regs[2]));
329
+        }
330
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
331
+            $sanitizer($local);
332
+        }
333
+        $source = $local;
334
+        $img = inserer_attribut($img, 'src', $source);
335
+        # eviter les mauvaises surprises lors de conversions de format
336
+        $img = inserer_attribut($img, 'width', '');
337
+        $img = inserer_attribut($img, 'height', '');
338
+    }
339
+
340
+    // les protocoles web prennent au moins 3 lettres
341
+    if (tester_url_absolue($source)) {
342
+        include_spip('inc/distant');
343
+        $fichier = _DIR_RACINE . copie_locale($source);
344
+        if (!$fichier) {
345
+            return '';
346
+        }
347
+        if (
348
+            ($extension = _image_trouver_extension($fichier))
349
+            && ($sanitizer = charger_fonction($extension, 'sanitizer', true))
350
+        ) {
351
+            $sanitizer($fichier);
352
+        }
353
+    } else {
354
+        // enlever le timestamp eventuel
355
+        if (str_contains($source, '?')) {
356
+            $source = preg_replace(',[?]\d+$,', '', $source);
357
+        }
358
+        if (
359
+            str_contains($source, '?')
360
+            && str_starts_with($source, (string) _DIR_IMG)
361
+            && file_exists($f = preg_replace(',[?].*$,', '', $source))
362
+        ) {
363
+            $source = $f;
364
+        }
365
+        $fichier = $source;
366
+    }
367
+
368
+    $terminaison_dest = '';
369
+    if ($terminaison = _image_trouver_extension($fichier)) {
370
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
371
+    }
372
+
373
+    if (
374
+        $forcer_format !== false
375
+        && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
376
+    ) {
377
+        $terminaison_dest = $forcer_format;
378
+    }
379
+
380
+    if (!$terminaison_dest) {
381
+        return false;
382
+    }
383
+
384
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
385
+    $fichier_dest = $nom_fichier;
386
+    if (
387
+        $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f)
388
+        || @file_exists($f = $fichier)
389
+    ) {
390
+        // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance
391
+        // on lit directement les infos du fichier
392
+        [$ret['hauteur'], $ret['largeur']] = taille_image($f);
393
+        $date_src = @filemtime($f);
394
+    } elseif (
395
+        @file_exists($f = "$fichier.src")
396
+        && lire_fichier($f, $valeurs)
397
+        && ($valeurs = unserialize($valeurs))
398
+        && isset($valeurs['hauteur_dest'])
399
+        && isset($valeurs['largeur_dest'])
400
+    ) {
401
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
402
+        $ret['largeur'] = $valeurs['largeur_dest'];
403
+        $date_src = $valeurs['date'];
404
+    } // pas de fichier source par la
405
+    else {
406
+        return false;
407
+    }
408
+
409
+    // pas de taille mesurable ?
410
+    if (
411
+        !$ret['hauteur']
412
+        || !($ret['hauteur'] = (int) round($ret['hauteur']))
413
+        || !$ret['largeur']
414
+        || !($ret['largeur'] = (int) round($ret['largeur']))
415
+    ) {
416
+        return false;
417
+    }
418
+
419
+    // les images calculees dependent du chemin du fichier source
420
+    // 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
421
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
422
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
423
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
424
+    // alors que ca concerne peu de site au final
425
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
426
+    $identifiant = $fichier;
427
+
428
+    // cas general :
429
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
430
+    // cas particulier de reduire :
431
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
432
+    $cache = 'cache-gd2';
433
+    if (str_starts_with($effet, 'reduire')) {
434
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
435
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
436
+        $ret['largeur_dest'] = $destWidth;
437
+        $ret['hauteur_dest'] = $destHeight;
438
+        $effet = "L{$destWidth}xH$destHeight";
439
+        $cache = 'cache-vignettes';
440
+        $fichier_dest = basename($fichier_dest);
441
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
442
+            // on garde la terminaison initiale car image simplement copiee
443
+            // et on postfixe son nom avec un md5 du path
444
+            $terminaison_dest = $terminaison;
445
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
446
+        } else {
447
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
448
+        }
449
+        $cache = sous_repertoire(_DIR_VAR, $cache);
450
+        $cache = sous_repertoire($cache, $effet);
451
+    } else {
452
+        $fichier_dest = md5("$identifiant-$effet");
453
+        $cache = sous_repertoire(_DIR_VAR, $cache);
454
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
455
+        $fichier_dest = substr($fichier_dest, 2);
456
+    }
457
+
458
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
459
+
460
+    $GLOBALS['images_calculees'][] = $fichier_dest;
461
+
462
+    $creer = true;
463
+    // si recalcul des images demande, recalculer chaque image une fois
464
+    if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) {
465
+        $images_recalcul[$fichier_dest] = true;
466
+    } else {
467
+        if (@file_exists($f = $fichier_dest)) {
468
+            if (filemtime($f) >= $date_src) {
469
+                $creer = false;
470
+            }
471
+        } else {
472
+            if (
473
+                @file_exists($f = "$fichier_dest.src")
474
+                && lire_fichier($f, $valeurs)
475
+                && ($valeurs = unserialize($valeurs))
476
+                && $valeurs['date'] >= $date_src
477
+            ) {
478
+                $creer = false;
479
+            }
480
+        }
481
+    }
482
+    if ($creer && !@file_exists($fichier)) {
483
+        if (!@file_exists("$fichier.src")) {
484
+            spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR);
485
+
486
+            return false;
487
+        }
488
+        # on reconstruit l'image source absente a partir de la chaine des .src
489
+        reconstruire_image_intermediaire($fichier);
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 && !$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
 
@@ -552,54 +552,54 @@  discard block
 block discarded – undo
552 552
  * Extensions d’images acceptées en entrée
553 553
  */
554 554
 function _image_extensions_acceptees_en_entree(): array {
555
-	static $extensions = null;
556
-	if (empty($extensions)) {
557
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
558
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
559
-			// action=tester renseigne gd_formats et detecte le support de webp
560
-			$extensions = array_merge(explode(',', (string) $GLOBALS['meta']['gd_formats']));
561
-			$extensions = array_map('trim', $extensions);
562
-			$extensions = array_filter($extensions);
563
-			if (in_array('jpg', $extensions)) {
564
-				$extensions[] = 'jpeg';
565
-			}
566
-			$extensions = array_unique($extensions);
567
-		}
568
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
569
-	}
570
-
571
-	return $extensions;
555
+    static $extensions = null;
556
+    if (empty($extensions)) {
557
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
558
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
559
+            // action=tester renseigne gd_formats et detecte le support de webp
560
+            $extensions = array_merge(explode(',', (string) $GLOBALS['meta']['gd_formats']));
561
+            $extensions = array_map('trim', $extensions);
562
+            $extensions = array_filter($extensions);
563
+            if (in_array('jpg', $extensions)) {
564
+                $extensions[] = 'jpeg';
565
+            }
566
+            $extensions = array_unique($extensions);
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
  * Extensions d’images acceptées en sortie
576 576
  */
577 577
 function _image_extensions_acceptees_en_sortie(): array {
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) && !function_exists('imagegif')) {
583
-			$extensions = array_diff($extensions, ['gif']);
584
-		}
585
-		if (in_array('webp', $extensions) && !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) && !function_exists('imagegif')) {
583
+            $extensions = array_diff($extensions, ['gif']);
584
+        }
585
+        if (in_array('webp', $extensions) && !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((string) $extension);
595
-	if ($extension === 'jpeg') {
596
-		$extension = 'jpg';
597
-	}
598
-	return $extension;
594
+    $extension = strtolower((string) $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,11 +609,11 @@  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
-		return strtolower($regs[1]);
615
-	}
616
-	return '';
612
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
613
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
614
+        return strtolower($regs[1]);
615
+    }
616
+    return '';
617 617
 }
618 618
 
619 619
 /**
@@ -624,28 +624,28 @@  discard block
 block discarded – undo
624 624
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
625 625
  */
626 626
 function _image_trouver_extension_pertinente($path) {
627
-	$path = supprimer_timestamp($path);
628
-	$terminaison = _image_trouver_extension($path);
629
-	if ($terminaison == 'jpg') {
630
-		$terminaison = 'jpeg';
631
-	}
632
-
633
-	if (!file_exists($path)) {
634
-		return $terminaison;
635
-	}
636
-
637
-	if (!$info = @spip_getimagesize($path)) {
638
-		return $terminaison;
639
-	}
640
-
641
-	$mime = $info['mime'] ?? image_type_to_mime_type($info[2]);
642
-
643
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
644
-	if ($_terminaison && $_terminaison !== $terminaison) {
645
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
646
-		$terminaison = $_terminaison;
647
-	}
648
-	return $terminaison;
627
+    $path = supprimer_timestamp($path);
628
+    $terminaison = _image_trouver_extension($path);
629
+    if ($terminaison == 'jpg') {
630
+        $terminaison = 'jpeg';
631
+    }
632
+
633
+    if (!file_exists($path)) {
634
+        return $terminaison;
635
+    }
636
+
637
+    if (!$info = @spip_getimagesize($path)) {
638
+        return $terminaison;
639
+    }
640
+
641
+    $mime = $info['mime'] ?? image_type_to_mime_type($info[2]);
642
+
643
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
644
+    if ($_terminaison && $_terminaison !== $terminaison) {
645
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
646
+        $terminaison = $_terminaison;
647
+    }
648
+    return $terminaison;
649 649
 }
650 650
 
651 651
 /**
@@ -653,14 +653,14 @@  discard block
 block discarded – undo
653 653
  * @return string
654 654
  */
655 655
 function _image_trouver_extension_depuis_mime($mime) {
656
-	return match (strtolower($mime)) {
657
-		'image/png', 'image/x-png' => 'png',
658
-		'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg',
659
-		'image/gif' => 'gif',
660
-		'image/webp', 'image/x-webp' => 'webp',
661
-		'image/svg+xml' => 'svg',
662
-		default => '',
663
-	};
656
+    return match (strtolower($mime)) {
657
+        'image/png', 'image/x-png' => 'png',
658
+        'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg',
659
+        'image/gif' => 'gif',
660
+        'image/webp', 'image/x-webp' => 'webp',
661
+        'image/svg+xml' => 'svg',
662
+        default => '',
663
+    };
664 664
 }
665 665
 
666 666
 
@@ -680,18 +680,18 @@  discard block
 block discarded – undo
680 680
  *     Une ressource de type Image GD.
681 681
  */
682 682
 function _imagecreatefrom_func(string $func, string $filename) {
683
-	if (!function_exists($func)) {
684
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
685
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
686
-		return null;
687
-	}
688
-	$img = @$func($filename);
689
-	if (!$img) {
690
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
691
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
692
-		$img = imagecreate(10, 10);
693
-	}
694
-	return $img;
683
+    if (!function_exists($func)) {
684
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
685
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
686
+        return null;
687
+    }
688
+    $img = @$func($filename);
689
+    if (!$img) {
690
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
691
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
692
+        $img = imagecreate(10, 10);
693
+    }
694
+    return $img;
695 695
 }
696 696
 
697 697
 /**
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
  *     Une ressource de type Image GD.
708 708
  */
709 709
 function _imagecreatefromjpeg($filename) {
710
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
710
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
711 711
 }
712 712
 
713 713
 /**
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
  *     Une ressource de type Image GD.
724 724
  */
725 725
 function _imagecreatefrompng($filename) {
726
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
726
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
727 727
 }
728 728
 
729 729
 /**
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
  *     Une ressource de type Image GD.
740 740
  */
741 741
 function _imagecreatefromgif($filename) {
742
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
742
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
743 743
 }
744 744
 
745 745
 
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
  *     Une ressource de type Image GD.
757 757
  */
758 758
 function _imagecreatefromwebp($filename) {
759
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
759
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
760 760
 }
761 761
 
762 762
 /**
@@ -774,24 +774,24 @@  discard block
 block discarded – undo
774 774
  *     - true si une image est bien retournée.
775 775
  */
776 776
 function _image_imagepng($img, $fichier) {
777
-	if (!function_exists('imagepng')) {
778
-		return false;
779
-	}
780
-	$tmp = $fichier . '.tmp';
781
-	$ret = imagepng($img, $tmp);
782
-	if (file_exists($tmp)) {
783
-		$taille_test = @getimagesize($tmp);
784
-		if (empty($taille_test[0])) {
785
-			return false;
786
-		}
787
-
788
-		spip_unlink($fichier); // le fichier peut deja exister
789
-		@rename($tmp, $fichier);
790
-
791
-		return $ret;
792
-	}
793
-
794
-	return false;
777
+    if (!function_exists('imagepng')) {
778
+        return false;
779
+    }
780
+    $tmp = $fichier . '.tmp';
781
+    $ret = imagepng($img, $tmp);
782
+    if (file_exists($tmp)) {
783
+        $taille_test = @getimagesize($tmp);
784
+        if (empty($taille_test[0])) {
785
+            return false;
786
+        }
787
+
788
+        spip_unlink($fichier); // le fichier peut deja exister
789
+        @rename($tmp, $fichier);
790
+
791
+        return $ret;
792
+    }
793
+
794
+    return false;
795 795
 }
796 796
 
797 797
 /**
@@ -809,24 +809,24 @@  discard block
 block discarded – undo
809 809
  *     - true si une image est bien retournée.
810 810
  */
811 811
 function _image_imagegif($img, $fichier) {
812
-	if (!function_exists('imagegif')) {
813
-		return false;
814
-	}
815
-	$tmp = $fichier . '.tmp';
816
-	$ret = imagegif($img, $tmp);
817
-	if (file_exists($tmp)) {
818
-		$taille_test = @getimagesize($tmp);
819
-		if (empty($taille_test[0])) {
820
-			return false;
821
-		}
822
-
823
-		spip_unlink($fichier); // le fichier peut deja exister
824
-		@rename($tmp, $fichier);
825
-
826
-		return $ret;
827
-	}
828
-
829
-	return false;
812
+    if (!function_exists('imagegif')) {
813
+        return false;
814
+    }
815
+    $tmp = $fichier . '.tmp';
816
+    $ret = imagegif($img, $tmp);
817
+    if (file_exists($tmp)) {
818
+        $taille_test = @getimagesize($tmp);
819
+        if (empty($taille_test[0])) {
820
+            return false;
821
+        }
822
+
823
+        spip_unlink($fichier); // le fichier peut deja exister
824
+        @rename($tmp, $fichier);
825
+
826
+        return $ret;
827
+    }
828
+
829
+    return false;
830 830
 }
831 831
 
832 832
 /**
@@ -849,29 +849,29 @@  discard block
 block discarded – undo
849 849
  *     - true si une image est bien retournée.
850 850
  */
851 851
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
852
-	if (!function_exists('imagejpeg')) {
853
-		return false;
854
-	}
855
-	$tmp = $fichier . '.tmp';
852
+    if (!function_exists('imagejpeg')) {
853
+        return false;
854
+    }
855
+    $tmp = $fichier . '.tmp';
856 856
 
857
-	// Enable interlancing
858
-	imageinterlace($img, true);
857
+    // Enable interlancing
858
+    imageinterlace($img, true);
859 859
 
860
-	$ret = imagejpeg($img, $tmp, $qualite);
860
+    $ret = imagejpeg($img, $tmp, $qualite);
861 861
 
862
-	if (file_exists($tmp)) {
863
-		$taille_test = @getimagesize($tmp);
864
-		if (empty($taille_test[0])) {
865
-			return false;
866
-		}
862
+    if (file_exists($tmp)) {
863
+        $taille_test = @getimagesize($tmp);
864
+        if (empty($taille_test[0])) {
865
+            return false;
866
+        }
867 867
 
868
-		spip_unlink($fichier); // le fichier peut deja exister
869
-		@rename($tmp, $fichier);
868
+        spip_unlink($fichier); // le fichier peut deja exister
869
+        @rename($tmp, $fichier);
870 870
 
871
-		return $ret;
872
-	}
871
+        return $ret;
872
+    }
873 873
 
874
-	return false;
874
+    return false;
875 875
 }
876 876
 
877 877
 /**
@@ -889,9 +889,9 @@  discard block
 block discarded – undo
889 889
  *     true si le fichier a bien été créé ; false sinon.
890 890
  */
891 891
 function _image_imageico($img, $fichier) {
892
-	$gd_image_array = [$img];
892
+    $gd_image_array = [$img];
893 893
 
894
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
894
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
895 895
 }
896 896
 
897 897
 
@@ -910,24 +910,24 @@  discard block
 block discarded – undo
910 910
  *     - true si une image est bien retournée.
911 911
  */
912 912
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
913
-	if (!function_exists('imagewebp')) {
914
-		return false;
915
-	}
916
-	$tmp = $fichier . '.tmp';
917
-	$ret = imagewebp($img, $tmp, $qualite);
918
-	if (file_exists($tmp)) {
919
-		$taille_test = @getimagesize($tmp);
920
-		if (empty($taille_test[0])) {
921
-			return false;
922
-		}
923
-
924
-		spip_unlink($fichier); // le fichier peut deja exister
925
-		@rename($tmp, $fichier);
926
-
927
-		return $ret;
928
-	}
929
-
930
-	return false;
913
+    if (!function_exists('imagewebp')) {
914
+        return false;
915
+    }
916
+    $tmp = $fichier . '.tmp';
917
+    $ret = imagewebp($img, $tmp, $qualite);
918
+    if (file_exists($tmp)) {
919
+        $taille_test = @getimagesize($tmp);
920
+        if (empty($taille_test[0])) {
921
+            return false;
922
+        }
923
+
924
+        spip_unlink($fichier); // le fichier peut deja exister
925
+        @rename($tmp, $fichier);
926
+
927
+        return $ret;
928
+    }
929
+
930
+    return false;
931 931
 }
932 932
 
933 933
 /**
@@ -947,35 +947,35 @@  discard block
 block discarded – undo
947 947
  */
948 948
 function _image_imagesvg($img, $fichier) {
949 949
 
950
-	$tmp = $fichier . '.tmp';
951
-	if (!str_contains($img, '<')) {
952
-		$img = supprimer_timestamp($img);
953
-		if (!file_exists($img)) {
954
-			return false;
955
-		}
956
-		@copy($img, $tmp);
957
-		if (filesize($tmp) === filesize($img)) {
958
-			spip_unlink($fichier); // le fichier peut deja exister
959
-			@rename($tmp, $fichier);
960
-			return true;
961
-		}
962
-		return false;
963
-	}
964
-
965
-	file_put_contents($tmp, $img);
966
-	if (file_exists($tmp)) {
967
-		$taille_test = spip_getimagesize($tmp);
968
-		if (empty($taille_test[0])) {
969
-			return false;
970
-		}
971
-
972
-		spip_unlink($fichier); // le fichier peut deja exister
973
-		@rename($tmp, $fichier);
974
-
975
-		return true;
976
-	}
977
-
978
-	return false;
950
+    $tmp = $fichier . '.tmp';
951
+    if (!str_contains($img, '<')) {
952
+        $img = supprimer_timestamp($img);
953
+        if (!file_exists($img)) {
954
+            return false;
955
+        }
956
+        @copy($img, $tmp);
957
+        if (filesize($tmp) === filesize($img)) {
958
+            spip_unlink($fichier); // le fichier peut deja exister
959
+            @rename($tmp, $fichier);
960
+            return true;
961
+        }
962
+        return false;
963
+    }
964
+
965
+    file_put_contents($tmp, $img);
966
+    if (file_exists($tmp)) {
967
+        $taille_test = spip_getimagesize($tmp);
968
+        if (empty($taille_test[0])) {
969
+            return false;
970
+        }
971
+
972
+        spip_unlink($fichier); // le fichier peut deja exister
973
+        @rename($tmp, $fichier);
974
+
975
+        return true;
976
+    }
977
+
978
+    return false;
979 979
 }
980 980
 
981 981
 
@@ -1003,30 +1003,30 @@  discard block
 block discarded – undo
1003 1003
  *     - false sinon.
1004 1004
  */
1005 1005
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1006
-	if (is_null($fonction)) {
1007
-		$fonction = '_image_image' . $valeurs['format_dest'];
1008
-	}
1009
-	$ret = false;
1010
-	#un flag pour reperer les images gravees
1011
-	$lock = (
1012
-		!statut_effacer_images_temporaires('get')
1013
-		|| @file_exists($valeurs['fichier_dest'])
1014
-		&& !@file_exists($valeurs['fichier_dest'] . '.src')
1015
-	);
1016
-	if (
1017
-		function_exists($fonction)
1018
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1019
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1020
-		&& !$lock && @file_exists($valeurs['fichier_dest'])
1021
-	) {
1022
-		// dans tous les cas mettre a jour la taille de l'image finale
1023
-		[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1024
-		$valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1025
-		// pour la retrouver apres disparition
1026
-		ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1027
-	}
1028
-
1029
-	return $ret;
1006
+    if (is_null($fonction)) {
1007
+        $fonction = '_image_image' . $valeurs['format_dest'];
1008
+    }
1009
+    $ret = false;
1010
+    #un flag pour reperer les images gravees
1011
+    $lock = (
1012
+        !statut_effacer_images_temporaires('get')
1013
+        || @file_exists($valeurs['fichier_dest'])
1014
+        && !@file_exists($valeurs['fichier_dest'] . '.src')
1015
+    );
1016
+    if (
1017
+        function_exists($fonction)
1018
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1019
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1020
+        && !$lock && @file_exists($valeurs['fichier_dest'])
1021
+    ) {
1022
+        // dans tous les cas mettre a jour la taille de l'image finale
1023
+        [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1024
+        $valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1025
+        // pour la retrouver apres disparition
1026
+        ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1027
+    }
1028
+
1029
+    return $ret;
1030 1030
 }
1031 1031
 
1032 1032
 /**
@@ -1039,28 +1039,28 @@  discard block
 block discarded – undo
1039 1039
  *     Chemin vers le fichier manquant
1040 1040
  **/
1041 1041
 function reconstruire_image_intermediaire($fichier_manquant) {
1042
-	$source = null;
1043
-	$reconstruire = [];
1044
-	$fichier = $fichier_manquant;
1045
-	while (
1046
-		!str_contains((string) $fichier, '://')
1047
-		&& !@file_exists($fichier)
1048
-		&& lire_fichier($src = "$fichier.src", $source)
1049
-		&& ($valeurs = unserialize($source))
1050
-		&& ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1051
-	) {
1052
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1053
-		$reconstruire[] = $valeurs['reconstruction'];
1054
-	}
1055
-	while (count($reconstruire)) {
1056
-		$r = array_pop($reconstruire);
1057
-		$fonction = $r[0];
1058
-		$args = $r[1];
1059
-		$fonction(...$args);
1060
-	}
1061
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1062
-	// mais l'on peut nettoyer les miettes de sa creation
1063
-	ramasse_miettes($fichier_manquant);
1042
+    $source = null;
1043
+    $reconstruire = [];
1044
+    $fichier = $fichier_manquant;
1045
+    while (
1046
+        !str_contains((string) $fichier, '://')
1047
+        && !@file_exists($fichier)
1048
+        && lire_fichier($src = "$fichier.src", $source)
1049
+        && ($valeurs = unserialize($source))
1050
+        && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1051
+    ) {
1052
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1053
+        $reconstruire[] = $valeurs['reconstruction'];
1054
+    }
1055
+    while (count($reconstruire)) {
1056
+        $r = array_pop($reconstruire);
1057
+        $fonction = $r[0];
1058
+        $args = $r[1];
1059
+        $fonction(...$args);
1060
+    }
1061
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1062
+    // mais l'on peut nettoyer les miettes de sa creation
1063
+    ramasse_miettes($fichier_manquant);
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1080,26 +1080,26 @@  discard block
 block discarded – undo
1080 1080
  *     Chemin du fichier d'image calculé
1081 1081
  **/
1082 1082
 function ramasse_miettes($fichier) {
1083
-	$source = null;
1084
-	if (
1085
-		str_contains($fichier, '://')
1086
-		|| !lire_fichier($src = "$fichier.src", $source)
1087
-		|| !$valeurs = unserialize($source)
1088
-	) {
1089
-		return;
1090
-	}
1091
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1092
-	while (
1093
-		($fichier = $valeurs['fichier'])
1094
-		&& str_starts_with((string) $fichier, (string) _DIR_VAR)
1095
-		&& lire_fichier($src = "$fichier.src", $source)
1096
-		&& ($valeurs = unserialize($source))  # et valide
1097
-	) {
1098
-		# on efface le fichier
1099
-		spip_unlink($fichier);
1100
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1101
-		#spip_unlink($src);
1102
-	}
1083
+    $source = null;
1084
+    if (
1085
+        str_contains($fichier, '://')
1086
+        || !lire_fichier($src = "$fichier.src", $source)
1087
+        || !$valeurs = unserialize($source)
1088
+    ) {
1089
+        return;
1090
+    }
1091
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1092
+    while (
1093
+        ($fichier = $valeurs['fichier'])
1094
+        && str_starts_with((string) $fichier, (string) _DIR_VAR)
1095
+        && lire_fichier($src = "$fichier.src", $source)
1096
+        && ($valeurs = unserialize($source))  # et valide
1097
+    ) {
1098
+        # on efface le fichier
1099
+        spip_unlink($fichier);
1100
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1101
+        #spip_unlink($src);
1102
+    }
1103 1103
 }
1104 1104
 
1105 1105
 
@@ -1124,33 +1124,33 @@  discard block
 block discarded – undo
1124 1124
  *     Code HTML de l'image
1125 1125
  **/
1126 1126
 function image_graver($img) {
1127
-	// appeler le filtre post_image_filtrer qui permet de faire
1128
-	// des traitements auto a la fin d'une serie de filtres
1129
-	$img = pipeline('post_image_filtrer', $img);
1130
-
1131
-	$fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? '');
1132
-	if (($p = strpos($fichier, '?')) !== false) {
1133
-		$fichier = substr($fichier, 0, $p);
1134
-	}
1135
-	if (strlen($fichier) < 1 && !str_starts_with((string) $img, '<img ')) {
1136
-		$fichier = $img;
1137
-	}
1138
-	if (strlen((string) $fichier)) {
1139
-		# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1140
-		# et qu'il ne s'agit pas d'une URL
1141
-		if (!str_contains((string) $fichier, '://') && !@file_exists($fichier)) {
1142
-			reconstruire_image_intermediaire($fichier);
1143
-		}
1144
-		ramasse_miettes($fichier);
1145
-
1146
-		// ajouter le timestamp si besoin
1147
-		if (!str_contains($fichier_ori, '?')) {
1148
-			// on utilise str_replace pour attraper le onmouseover des logo si besoin
1149
-			$img = str_replace($fichier_ori, timestamp($fichier_ori), (string) $img);
1150
-		}
1151
-	}
1152
-
1153
-	return $img;
1127
+    // appeler le filtre post_image_filtrer qui permet de faire
1128
+    // des traitements auto a la fin d'une serie de filtres
1129
+    $img = pipeline('post_image_filtrer', $img);
1130
+
1131
+    $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? '');
1132
+    if (($p = strpos($fichier, '?')) !== false) {
1133
+        $fichier = substr($fichier, 0, $p);
1134
+    }
1135
+    if (strlen($fichier) < 1 && !str_starts_with((string) $img, '<img ')) {
1136
+        $fichier = $img;
1137
+    }
1138
+    if (strlen((string) $fichier)) {
1139
+        # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1140
+        # et qu'il ne s'agit pas d'une URL
1141
+        if (!str_contains((string) $fichier, '://') && !@file_exists($fichier)) {
1142
+            reconstruire_image_intermediaire($fichier);
1143
+        }
1144
+        ramasse_miettes($fichier);
1145
+
1146
+        // ajouter le timestamp si besoin
1147
+        if (!str_contains($fichier_ori, '?')) {
1148
+            // on utilise str_replace pour attraper le onmouseover des logo si besoin
1149
+            $img = str_replace($fichier_ori, timestamp($fichier_ori), (string) $img);
1150
+        }
1151
+    }
1152
+
1153
+    return $img;
1154 1154
 }
1155 1155
 
1156 1156
 /**
@@ -1177,32 +1177,32 @@  discard block
 block discarded – undo
1177 1177
  *     Code html modifié de la balise.
1178 1178
  **/
1179 1179
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1180
-	if ($style === false) {
1181
-		$style = extraire_attribut($tag, 'style');
1182
-	}
1183
-
1184
-	// enlever le width et height du style
1185
-	if ($style) {
1186
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1187
-	}
1188
-	if ($style && $style[0] === ';') {
1189
-		$style = substr($style, 1);
1190
-	}
1191
-
1192
-	// mettre des attributs de width et height sur les images,
1193
-	// ca accelere le rendu du navigateur
1194
-	// ca permet aux navigateurs de reserver la bonne taille
1195
-	// quand on a desactive l'affichage des images.
1196
-	$tag = inserer_attribut($tag, 'width', round($width));
1197
-	$tag = inserer_attribut($tag, 'height', round($height));
1198
-
1199
-	// attributs deprecies. Transformer en CSS
1200
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1201
-		$style = "margin:{$espace}px;" . $style;
1202
-		$tag = inserer_attribut($tag, 'hspace', '');
1203
-	}
1204
-
1205
-	return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style);
1180
+    if ($style === false) {
1181
+        $style = extraire_attribut($tag, 'style');
1182
+    }
1183
+
1184
+    // enlever le width et height du style
1185
+    if ($style) {
1186
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1187
+    }
1188
+    if ($style && $style[0] === ';') {
1189
+        $style = substr($style, 1);
1190
+    }
1191
+
1192
+    // mettre des attributs de width et height sur les images,
1193
+    // ca accelere le rendu du navigateur
1194
+    // ca permet aux navigateurs de reserver la bonne taille
1195
+    // quand on a desactive l'affichage des images.
1196
+    $tag = inserer_attribut($tag, 'width', round($width));
1197
+    $tag = inserer_attribut($tag, 'height', round($height));
1198
+
1199
+    // attributs deprecies. Transformer en CSS
1200
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1201
+        $style = "margin:{$espace}px;" . $style;
1202
+        $tag = inserer_attribut($tag, 'hspace', '');
1203
+    }
1204
+
1205
+    return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style);
1206 1206
 }
1207 1207
 
1208 1208
 
@@ -1228,70 +1228,70 @@  discard block
 block discarded – undo
1228 1228
  *     Retourne le code HTML de l'image
1229 1229
  **/
1230 1230
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1231
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1232
-
1233
-	// fermer les tags img pas bien fermes;
1234
-	$tag = str_replace('>', '/>', str_replace('/>', '>', (string) $valeurs['tag']));
1235
-
1236
-	// le style
1237
-	$style = $valeurs['style'];
1238
-	if (isset($surcharge['style'])) {
1239
-		$style = $surcharge['style'];
1240
-		unset($surcharge['style']);
1241
-	}
1242
-
1243
-	// traiter specifiquement la largeur et la hauteur
1244
-	$width = $valeurs['largeur'];
1245
-	if (isset($surcharge['width'])) {
1246
-		$width = $surcharge['width'];
1247
-		unset($surcharge['width']);
1248
-	}
1249
-	$height = $valeurs['hauteur'];
1250
-	if (isset($surcharge['height'])) {
1251
-		$height = $surcharge['height'];
1252
-		unset($surcharge['height']);
1253
-	}
1254
-
1255
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1256
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1257
-	// on remplace toute les ref a src dans le tag
1258
-	$src = extraire_attribut($tag, 'src');
1259
-	if (isset($surcharge['src'])) {
1260
-		$tag = str_replace($src, $surcharge['src'], $tag);
1261
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1262
-		// pas garanti comme methode, mais mieux que rien
1263
-		if (str_contains($src, '&')) {
1264
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1265
-		}
1266
-		$src = $surcharge['src'];
1267
-		unset($surcharge['src']);
1268
-	}
1269
-
1270
-	$class = $valeurs['class'];
1271
-	if (isset($surcharge['class'])) {
1272
-		$class = $surcharge['class'];
1273
-		unset($surcharge['class']);
1274
-	}
1275
-	if (is_scalar($class) && strlen($class)) {
1276
-		$tag = inserer_attribut($tag, 'class', $class);
1277
-	}
1278
-
1279
-	if ($surcharge !== []) {
1280
-		foreach ($surcharge as $attribut => $valeur) {
1281
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1282
-		}
1283
-	}
1284
-
1285
-	return pipeline(
1286
-		'image_ecrire_tag_finir',
1287
-		[
1288
-			'args' => [
1289
-				'valeurs' => $valeurs,
1290
-				'surcharge' => $surcharge,
1291
-			],
1292
-			'data' => $tag
1293
-		]
1294
-	);
1231
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1232
+
1233
+    // fermer les tags img pas bien fermes;
1234
+    $tag = str_replace('>', '/>', str_replace('/>', '>', (string) $valeurs['tag']));
1235
+
1236
+    // le style
1237
+    $style = $valeurs['style'];
1238
+    if (isset($surcharge['style'])) {
1239
+        $style = $surcharge['style'];
1240
+        unset($surcharge['style']);
1241
+    }
1242
+
1243
+    // traiter specifiquement la largeur et la hauteur
1244
+    $width = $valeurs['largeur'];
1245
+    if (isset($surcharge['width'])) {
1246
+        $width = $surcharge['width'];
1247
+        unset($surcharge['width']);
1248
+    }
1249
+    $height = $valeurs['hauteur'];
1250
+    if (isset($surcharge['height'])) {
1251
+        $height = $surcharge['height'];
1252
+        unset($surcharge['height']);
1253
+    }
1254
+
1255
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1256
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1257
+    // on remplace toute les ref a src dans le tag
1258
+    $src = extraire_attribut($tag, 'src');
1259
+    if (isset($surcharge['src'])) {
1260
+        $tag = str_replace($src, $surcharge['src'], $tag);
1261
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1262
+        // pas garanti comme methode, mais mieux que rien
1263
+        if (str_contains($src, '&')) {
1264
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1265
+        }
1266
+        $src = $surcharge['src'];
1267
+        unset($surcharge['src']);
1268
+    }
1269
+
1270
+    $class = $valeurs['class'];
1271
+    if (isset($surcharge['class'])) {
1272
+        $class = $surcharge['class'];
1273
+        unset($surcharge['class']);
1274
+    }
1275
+    if (is_scalar($class) && strlen($class)) {
1276
+        $tag = inserer_attribut($tag, 'class', $class);
1277
+    }
1278
+
1279
+    if ($surcharge !== []) {
1280
+        foreach ($surcharge as $attribut => $valeur) {
1281
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1282
+        }
1283
+    }
1284
+
1285
+    return pipeline(
1286
+        'image_ecrire_tag_finir',
1287
+        [
1288
+            'args' => [
1289
+                'valeurs' => $valeurs,
1290
+                'surcharge' => $surcharge,
1291
+            ],
1292
+            'data' => $tag
1293
+        ]
1294
+    );
1295 1295
 }
1296 1296
 
1297 1297
 /**
@@ -1314,268 +1314,268 @@  discard block
 block discarded – undo
1314 1314
  *     Description de l'image, sinon null.
1315 1315
  **/
1316 1316
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1317
-	$srcHeight = null;
1318
-	$retour = [];
1319
-	// ordre de preference des formats graphiques pour creer les vignettes
1320
-	// le premier format disponible, selon la methode demandee, est utilise
1321
-	$image = $valeurs['fichier'];
1322
-	$format = $valeurs['format_source'];
1323
-	$destdir = dirname((string) $valeurs['fichier_dest']);
1324
-	$destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1325
-
1326
-	$format_sortie = $valeurs['format_dest'];
1327
-
1328
-	if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1329
-		$process = $GLOBALS['meta']['image_process'];
1330
-	}
1331
-
1332
-	// si le doc n'est pas une image dans un format accetpable, refuser
1333
-	if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) {
1334
-		return;
1335
-	}
1336
-	$destination = "$destdir/$destfile";
1337
-
1338
-	// calculer la taille
1339
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1340
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1341
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1342
-		}
1343
-	} elseif ($process == 'convert' || $process == 'imagick') {
1344
-		$destWidth = $maxWidth;
1345
-		$destHeight = $maxHeight;
1346
-	} else {
1347
-		spip_log("echec $process sur $image");
1348
-
1349
-		return;
1350
-	}
1351
-
1352
-	$vignette = '';
1353
-
1354
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1355
-	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1356
-		$vignette = $destination . '.' . $format;
1357
-		@copy($image, $vignette);
1358
-	}
1359
-
1360
-	elseif ($valeurs['format_source'] === 'svg') {
1361
-		include_spip('inc/svg');
1362
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1363
-			$format_sortie = 'svg';
1364
-			$vignette = $destination . '.' . $format_sortie;
1365
-			$valeurs['fichier_dest'] = $vignette;
1366
-			_image_gd_output($svg, $valeurs);
1367
-		}
1368
-	}
1369
-
1370
-	// imagemagick en ligne de commande
1371
-	elseif ($process == 'convert') {
1372
-		if (!defined('_CONVERT_COMMAND')) {
1373
-			define('_CONVERT_COMMAND', 'convert');
1374
-		} // Securite : mes_options.php peut preciser le chemin absolu
1375
-		if (!defined('_RESIZE_COMMAND')) {
1376
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1377
-		}
1378
-		$vignette = $destination . '.' . $format_sortie;
1379
-		$commande = str_replace(
1380
-			['%x', '%y', '%src', '%dest'],
1381
-			[
1382
-				$destWidth,
1383
-				$destHeight,
1384
-				escapeshellcmd($image),
1385
-				escapeshellcmd($vignette)
1386
-			],
1387
-			(string) _RESIZE_COMMAND
1388
-		);
1389
-		spip_log($commande);
1390
-		exec($commande);
1391
-		if (!@file_exists($vignette)) {
1392
-			spip_log("echec convert sur $vignette");
1393
-
1394
-			return;  // echec commande
1395
-		}
1396
-	}
1397
-
1398
-	// php5 imagemagick
1399
-	elseif ($process == 'imagick') {
1400
-		if (!class_exists(\Imagick::class)) {
1401
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1402
-
1403
-			return;
1404
-		}
1405
-
1406
-		// chemin compatible Windows
1407
-		$output = realpath(dirname($destination));
1408
-		if (!$output) {
1409
-			return;
1410
-		}
1411
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1412
-
1413
-		$imagick = new Imagick();
1414
-		$imagick->readImage(realpath($image));
1415
-		$imagick->resizeImage(
1416
-			$destWidth,
1417
-			$destHeight,
1418
-			Imagick::FILTER_LANCZOS,
1419
-			1
1420
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1421
-		$imagick->writeImage($vignette);
1422
-
1423
-		if (!@file_exists($vignette)) {
1424
-			spip_log("echec imagick sur $vignette");
1425
-
1426
-			return;
1427
-		}
1428
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1429
-		$vignette = $destination . '.' . $format_sortie;
1430
-	}
1431
-
1432
-	// netpbm
1433
-	elseif ($process == 'netpbm') {
1434
-		if (!defined('_PNMSCALE_COMMAND')) {
1435
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1436
-		} // Securite : mes_options.php peut preciser le chemin absolu
1437
-		if (_PNMSCALE_COMMAND == '') {
1438
-			return;
1439
-		}
1440
-		$vignette = $destination . '.' . $format_sortie;
1441
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND);
1442
-		if ($format == 'jpg') {
1443
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND);
1444
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1445
-			if (!($s = @filesize($vignette))) {
1446
-				spip_unlink($vignette);
1447
-			}
1448
-			if (!@file_exists($vignette)) {
1449
-				spip_log("echec netpbm-jpg sur $vignette");
1450
-
1451
-				return;
1452
-			}
1453
-		} else {
1454
-			if ($format == 'gif') {
1455
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND);
1456
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1457
-				if (!($s = @filesize($vignette))) {
1458
-					spip_unlink($vignette);
1459
-				}
1460
-				if (!@file_exists($vignette)) {
1461
-					spip_log("echec netpbm-gif sur $vignette");
1462
-
1463
-					return;
1464
-				}
1465
-			} else {
1466
-				if ($format == 'png') {
1467
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND);
1468
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1469
-					if (!($s = @filesize($vignette))) {
1470
-						spip_unlink($vignette);
1471
-					}
1472
-					if (!@file_exists($vignette)) {
1473
-						spip_log("echec netpbm-png sur $vignette");
1474
-
1475
-						return;
1476
-					}
1477
-				}
1478
-			}
1479
-		}
1480
-	}
1481
-
1482
-	// gd ou gd2
1483
-	elseif ($process === 'gd2') {
1484
-		if (!function_exists('gd_info')) {
1485
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1486
-
1487
-			return;
1488
-		}
1489
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1490
-			spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1491
-
1492
-			return;
1493
-		}
1494
-		$destFormat = $format_sortie;
1495
-		if (!$destFormat) {
1496
-			spip_log("pas de format pour $image");
1497
-
1498
-			return;
1499
-		}
1500
-
1501
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1502
-		if (!function_exists($fonction_imagecreatefrom)) {
1503
-			return;
1504
-		}
1505
-		$srcImage = @$fonction_imagecreatefrom($image);
1506
-		if (!$srcImage) {
1507
-			spip_log('echec gd2');
1508
-
1509
-			return;
1510
-		}
1511
-
1512
-		// Initialisation de l'image destination
1513
-		$destImage = null;
1514
-		if ($process == 'gd2' && $destFormat != 'gif') {
1515
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1516
-		}
1517
-		if (!$destImage) {
1518
-			$destImage = ImageCreate($destWidth, $destHeight);
1519
-		}
1520
-
1521
-		// Recopie de l'image d'origine avec adaptation de la taille
1522
-		$ok = false;
1523
-		if ($process == 'gd2' && function_exists('ImageCopyResampled')) {
1524
-			if ($format == 'gif') {
1525
-				// Si un GIF est transparent,
1526
-				// fabriquer un PNG transparent
1527
-				$transp = imagecolortransparent($srcImage);
1528
-				if ($transp > 0) {
1529
-					$destFormat = 'png';
1530
-				}
1531
-			}
1532
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1533
-				// Conserver la transparence
1534
-				if (function_exists('imageAntiAlias')) {
1535
-					imageAntiAlias($destImage, true);
1536
-				}
1537
-				@imagealphablending($destImage, false);
1538
-				@imagesavealpha($destImage, true);
1539
-			}
1540
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1541
-		}
1542
-		if (!$ok) {
1543
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1544
-		}
1545
-
1546
-		// Sauvegarde de l'image destination
1547
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1548
-		$valeurs['format_dest'] = $format = $destFormat;
1549
-		_image_gd_output($destImage, $valeurs);
1550
-
1551
-		if ($srcImage) {
1552
-			ImageDestroy($srcImage);
1553
-		}
1554
-		ImageDestroy($destImage);
1555
-	}
1556
-
1557
-	if (!$vignette || !$size = @spip_getimagesize($vignette)) {
1558
-		$size = [$destWidth, $destHeight];
1559
-	}
1560
-
1561
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1562
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1563
-	if ($size[0] < 1) {
1564
-		$size[0] = $destWidth;
1565
-	}
1566
-	if ($size[1] < 1) {
1567
-		$size[1] = $destHeight;
1568
-	}
1569
-
1570
-	$retour['width'] = $largeur = $size[0];
1571
-	$retour['height'] = $hauteur = $size[1];
1572
-
1573
-	$retour['fichier'] = $vignette;
1574
-	$retour['format'] = $format;
1575
-	$retour['date'] = @filemtime($vignette);
1576
-
1577
-	// renvoyer l'image
1578
-	return $retour;
1317
+    $srcHeight = null;
1318
+    $retour = [];
1319
+    // ordre de preference des formats graphiques pour creer les vignettes
1320
+    // le premier format disponible, selon la methode demandee, est utilise
1321
+    $image = $valeurs['fichier'];
1322
+    $format = $valeurs['format_source'];
1323
+    $destdir = dirname((string) $valeurs['fichier_dest']);
1324
+    $destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1325
+
1326
+    $format_sortie = $valeurs['format_dest'];
1327
+
1328
+    if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1329
+        $process = $GLOBALS['meta']['image_process'];
1330
+    }
1331
+
1332
+    // si le doc n'est pas une image dans un format accetpable, refuser
1333
+    if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) {
1334
+        return;
1335
+    }
1336
+    $destination = "$destdir/$destfile";
1337
+
1338
+    // calculer la taille
1339
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1340
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1341
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1342
+        }
1343
+    } elseif ($process == 'convert' || $process == 'imagick') {
1344
+        $destWidth = $maxWidth;
1345
+        $destHeight = $maxHeight;
1346
+    } else {
1347
+        spip_log("echec $process sur $image");
1348
+
1349
+        return;
1350
+    }
1351
+
1352
+    $vignette = '';
1353
+
1354
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1355
+    if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1356
+        $vignette = $destination . '.' . $format;
1357
+        @copy($image, $vignette);
1358
+    }
1359
+
1360
+    elseif ($valeurs['format_source'] === 'svg') {
1361
+        include_spip('inc/svg');
1362
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1363
+            $format_sortie = 'svg';
1364
+            $vignette = $destination . '.' . $format_sortie;
1365
+            $valeurs['fichier_dest'] = $vignette;
1366
+            _image_gd_output($svg, $valeurs);
1367
+        }
1368
+    }
1369
+
1370
+    // imagemagick en ligne de commande
1371
+    elseif ($process == 'convert') {
1372
+        if (!defined('_CONVERT_COMMAND')) {
1373
+            define('_CONVERT_COMMAND', 'convert');
1374
+        } // Securite : mes_options.php peut preciser le chemin absolu
1375
+        if (!defined('_RESIZE_COMMAND')) {
1376
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1377
+        }
1378
+        $vignette = $destination . '.' . $format_sortie;
1379
+        $commande = str_replace(
1380
+            ['%x', '%y', '%src', '%dest'],
1381
+            [
1382
+                $destWidth,
1383
+                $destHeight,
1384
+                escapeshellcmd($image),
1385
+                escapeshellcmd($vignette)
1386
+            ],
1387
+            (string) _RESIZE_COMMAND
1388
+        );
1389
+        spip_log($commande);
1390
+        exec($commande);
1391
+        if (!@file_exists($vignette)) {
1392
+            spip_log("echec convert sur $vignette");
1393
+
1394
+            return;  // echec commande
1395
+        }
1396
+    }
1397
+
1398
+    // php5 imagemagick
1399
+    elseif ($process == 'imagick') {
1400
+        if (!class_exists(\Imagick::class)) {
1401
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1402
+
1403
+            return;
1404
+        }
1405
+
1406
+        // chemin compatible Windows
1407
+        $output = realpath(dirname($destination));
1408
+        if (!$output) {
1409
+            return;
1410
+        }
1411
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1412
+
1413
+        $imagick = new Imagick();
1414
+        $imagick->readImage(realpath($image));
1415
+        $imagick->resizeImage(
1416
+            $destWidth,
1417
+            $destHeight,
1418
+            Imagick::FILTER_LANCZOS,
1419
+            1
1420
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1421
+        $imagick->writeImage($vignette);
1422
+
1423
+        if (!@file_exists($vignette)) {
1424
+            spip_log("echec imagick sur $vignette");
1425
+
1426
+            return;
1427
+        }
1428
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1429
+        $vignette = $destination . '.' . $format_sortie;
1430
+    }
1431
+
1432
+    // netpbm
1433
+    elseif ($process == 'netpbm') {
1434
+        if (!defined('_PNMSCALE_COMMAND')) {
1435
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1436
+        } // Securite : mes_options.php peut preciser le chemin absolu
1437
+        if (_PNMSCALE_COMMAND == '') {
1438
+            return;
1439
+        }
1440
+        $vignette = $destination . '.' . $format_sortie;
1441
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND);
1442
+        if ($format == 'jpg') {
1443
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND);
1444
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1445
+            if (!($s = @filesize($vignette))) {
1446
+                spip_unlink($vignette);
1447
+            }
1448
+            if (!@file_exists($vignette)) {
1449
+                spip_log("echec netpbm-jpg sur $vignette");
1450
+
1451
+                return;
1452
+            }
1453
+        } else {
1454
+            if ($format == 'gif') {
1455
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND);
1456
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1457
+                if (!($s = @filesize($vignette))) {
1458
+                    spip_unlink($vignette);
1459
+                }
1460
+                if (!@file_exists($vignette)) {
1461
+                    spip_log("echec netpbm-gif sur $vignette");
1462
+
1463
+                    return;
1464
+                }
1465
+            } else {
1466
+                if ($format == 'png') {
1467
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND);
1468
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1469
+                    if (!($s = @filesize($vignette))) {
1470
+                        spip_unlink($vignette);
1471
+                    }
1472
+                    if (!@file_exists($vignette)) {
1473
+                        spip_log("echec netpbm-png sur $vignette");
1474
+
1475
+                        return;
1476
+                    }
1477
+                }
1478
+            }
1479
+        }
1480
+    }
1481
+
1482
+    // gd ou gd2
1483
+    elseif ($process === 'gd2') {
1484
+        if (!function_exists('gd_info')) {
1485
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1486
+
1487
+            return;
1488
+        }
1489
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1490
+            spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1491
+
1492
+            return;
1493
+        }
1494
+        $destFormat = $format_sortie;
1495
+        if (!$destFormat) {
1496
+            spip_log("pas de format pour $image");
1497
+
1498
+            return;
1499
+        }
1500
+
1501
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1502
+        if (!function_exists($fonction_imagecreatefrom)) {
1503
+            return;
1504
+        }
1505
+        $srcImage = @$fonction_imagecreatefrom($image);
1506
+        if (!$srcImage) {
1507
+            spip_log('echec gd2');
1508
+
1509
+            return;
1510
+        }
1511
+
1512
+        // Initialisation de l'image destination
1513
+        $destImage = null;
1514
+        if ($process == 'gd2' && $destFormat != 'gif') {
1515
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1516
+        }
1517
+        if (!$destImage) {
1518
+            $destImage = ImageCreate($destWidth, $destHeight);
1519
+        }
1520
+
1521
+        // Recopie de l'image d'origine avec adaptation de la taille
1522
+        $ok = false;
1523
+        if ($process == 'gd2' && function_exists('ImageCopyResampled')) {
1524
+            if ($format == 'gif') {
1525
+                // Si un GIF est transparent,
1526
+                // fabriquer un PNG transparent
1527
+                $transp = imagecolortransparent($srcImage);
1528
+                if ($transp > 0) {
1529
+                    $destFormat = 'png';
1530
+                }
1531
+            }
1532
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1533
+                // Conserver la transparence
1534
+                if (function_exists('imageAntiAlias')) {
1535
+                    imageAntiAlias($destImage, true);
1536
+                }
1537
+                @imagealphablending($destImage, false);
1538
+                @imagesavealpha($destImage, true);
1539
+            }
1540
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1541
+        }
1542
+        if (!$ok) {
1543
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1544
+        }
1545
+
1546
+        // Sauvegarde de l'image destination
1547
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1548
+        $valeurs['format_dest'] = $format = $destFormat;
1549
+        _image_gd_output($destImage, $valeurs);
1550
+
1551
+        if ($srcImage) {
1552
+            ImageDestroy($srcImage);
1553
+        }
1554
+        ImageDestroy($destImage);
1555
+    }
1556
+
1557
+    if (!$vignette || !$size = @spip_getimagesize($vignette)) {
1558
+        $size = [$destWidth, $destHeight];
1559
+    }
1560
+
1561
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1562
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1563
+    if ($size[0] < 1) {
1564
+        $size[0] = $destWidth;
1565
+    }
1566
+    if ($size[1] < 1) {
1567
+        $size[1] = $destHeight;
1568
+    }
1569
+
1570
+    $retour['width'] = $largeur = $size[0];
1571
+    $retour['height'] = $hauteur = $size[1];
1572
+
1573
+    $retour['fichier'] = $vignette;
1574
+    $retour['format'] = $format;
1575
+    $retour['date'] = @filemtime($vignette);
1576
+
1577
+    // renvoyer l'image
1578
+    return $retour;
1579 1579
 }
1580 1580
 
1581 1581
 /**
@@ -1595,25 +1595,25 @@  discard block
 block discarded – undo
1595 1595
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1596 1596
  **/
1597 1597
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1598
-	$ratioWidth = $srcWidth / $maxWidth;
1599
-	$ratioHeight = $srcHeight / $maxHeight;
1600
-
1601
-	if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1602
-		$destWidth = $srcWidth;
1603
-		$destHeight = $srcHeight;
1604
-	} elseif ($ratioWidth < $ratioHeight) {
1605
-		$destWidth = $srcWidth / $ratioHeight;
1606
-		$destHeight = $maxHeight;
1607
-	} else {
1608
-		$destWidth = $maxWidth;
1609
-		$destHeight = $srcHeight / $ratioWidth;
1610
-	}
1611
-
1612
-	return [
1613
-		(int) round($destWidth),
1614
-		(int) round($destHeight),
1615
-		max($ratioWidth, $ratioHeight)
1616
-	];
1598
+    $ratioWidth = $srcWidth / $maxWidth;
1599
+    $ratioHeight = $srcHeight / $maxHeight;
1600
+
1601
+    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1602
+        $destWidth = $srcWidth;
1603
+        $destHeight = $srcHeight;
1604
+    } elseif ($ratioWidth < $ratioHeight) {
1605
+        $destWidth = $srcWidth / $ratioHeight;
1606
+        $destHeight = $maxHeight;
1607
+    } else {
1608
+        $destWidth = $maxWidth;
1609
+        $destHeight = $srcHeight / $ratioWidth;
1610
+    }
1611
+
1612
+    return [
1613
+        (int) round($destWidth),
1614
+        (int) round($destHeight),
1615
+        max($ratioWidth, $ratioHeight)
1616
+    ];
1617 1617
 }
1618 1618
 
1619 1619
 /**
@@ -1633,25 +1633,25 @@  discard block
 block discarded – undo
1633 1633
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1634 1634
  **/
1635 1635
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1636
-	$ratioWidth = $srcWidth / $maxWidth;
1637
-	$ratioHeight = $srcHeight / $maxHeight;
1638
-
1639
-	if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1640
-		$destWidth = $srcWidth;
1641
-		$destHeight = $srcHeight;
1642
-	} elseif ($ratioWidth > $ratioHeight) {
1643
-		$destWidth = $srcWidth / $ratioHeight;
1644
-		$destHeight = $maxHeight;
1645
-	} else {
1646
-		$destWidth = $maxWidth;
1647
-		$destHeight = $srcHeight / $ratioWidth;
1648
-	}
1649
-
1650
-	return [
1651
-		(int) round($destWidth),
1652
-		(int) round($destHeight),
1653
-		min($ratioWidth, $ratioHeight)
1654
-	];
1636
+    $ratioWidth = $srcWidth / $maxWidth;
1637
+    $ratioHeight = $srcHeight / $maxHeight;
1638
+
1639
+    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1640
+        $destWidth = $srcWidth;
1641
+        $destHeight = $srcHeight;
1642
+    } elseif ($ratioWidth > $ratioHeight) {
1643
+        $destWidth = $srcWidth / $ratioHeight;
1644
+        $destHeight = $maxHeight;
1645
+    } else {
1646
+        $destWidth = $maxWidth;
1647
+        $destHeight = $srcHeight / $ratioWidth;
1648
+    }
1649
+
1650
+    return [
1651
+        (int) round($destWidth),
1652
+        (int) round($destHeight),
1653
+        min($ratioWidth, $ratioHeight)
1654
+    ];
1655 1655
 }
1656 1656
 
1657 1657
 
@@ -1664,12 +1664,12 @@  discard block
 block discarded – undo
1664 1664
  * @return string
1665 1665
  */
1666 1666
 function process_image_svg_identite($image) {
1667
-	if ($image['creer']) {
1668
-		$source = $image['fichier'];
1669
-		_image_gd_output($source, $image);
1670
-	}
1667
+    if ($image['creer']) {
1668
+        $source = $image['fichier'];
1669
+        _image_gd_output($source, $image);
1670
+    }
1671 1671
 
1672
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1672
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1673 1673
 }
1674 1674
 
1675 1675
 
@@ -1702,102 +1702,102 @@  discard block
 block discarded – undo
1702 1702
  *     Code HTML de la balise img produite
1703 1703
  **/
1704 1704
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1705
-	$image = false;
1706
-	if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1707
-		$process = $GLOBALS['meta']['image_process'];
1708
-	}
1709
-	# determiner le format de sortie
1710
-	$format_sortie = false; // le choix par defaut sera bon
1711
-	if ($process === 'netpbm') {
1712
-		$format_sortie = 'jpg';
1713
-	} elseif ($process === 'gd2') {
1714
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1715
-		// on verifie que l'extension choisie est bonne (en principe oui)
1716
-		$gd_formats = formats_image_acceptables(true);
1717
-		if (
1718
-			is_array($image)
1719
-			&& (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1720
-		) {
1721
-			$formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif'];
1722
-			// Choisir le format destination
1723
-			// - on sauve de preference en JPEG (meilleure compression)
1724
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1725
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1726
-			# pas *ecrire*
1727
-			$format_sortie = '';
1728
-			foreach ($formats_sortie as $fmt) {
1729
-				if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1730
-					$format_sortie = $fmt;
1731
-					break;
1732
-				}
1733
-			}
1734
-			$image = false;
1735
-		}
1736
-	}
1737
-
1738
-	if (!is_array($image)) {
1739
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1740
-	}
1741
-
1742
-	if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) {
1743
-		spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1744
-		// on peut resizer en mode html si on dispose des elements
1745
-		[$srcw, $srch] = taille_image($img);
1746
-		if ($srcw && $srch) {
1747
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1748
-
1749
-			return _image_tag_changer_taille($img, $w, $h);
1750
-		}
1751
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1752
-		// sous la forme style='max-width: NNpx;'
1753
-		return inserer_attribut(
1754
-			$img,
1755
-			'style',
1756
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1757
-		);
1758
-	}
1759
-
1760
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1761
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1762
-		if ($image['creer']) {
1763
-			@copy($image['fichier'], $image['fichier_dest']);
1764
-		}
1765
-
1766
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1767
-	}
1768
-
1769
-	if ($image['creer'] == false && !$force) {
1770
-		return _image_ecrire_tag(
1771
-			$image,
1772
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1773
-		);
1774
-	}
1775
-
1776
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1777
-		$destWidth = $image['largeur_dest'];
1778
-		$destHeight = $image['hauteur_dest'];
1779
-		$logo = $image['fichier'];
1780
-		$date = $image['date_src'];
1781
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1782
-
1783
-		if ($preview && $preview['fichier']) {
1784
-			$logo = $preview['fichier'];
1785
-			$destWidth = $preview['width'];
1786
-			$destHeight = $preview['height'];
1787
-			$date = $preview['date'];
1788
-		}
1789
-		// dans l'espace prive mettre un timestamp sur l'adresse
1790
-		// de l'image, de facon a tromper le cache du navigateur
1791
-		// quand on fait supprimer/reuploader un logo
1792
-		// (pas de filemtime si SAFE MODE)
1793
-		$date = test_espace_prive() ? ('?' . $date) : '';
1794
-
1795
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796
-	}
1797
-	else {
1798
-		# BMP, tiff ... les redacteurs osent tout!
1799
-		return $img;
1800
-	}
1705
+    $image = false;
1706
+    if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1707
+        $process = $GLOBALS['meta']['image_process'];
1708
+    }
1709
+    # determiner le format de sortie
1710
+    $format_sortie = false; // le choix par defaut sera bon
1711
+    if ($process === 'netpbm') {
1712
+        $format_sortie = 'jpg';
1713
+    } elseif ($process === 'gd2') {
1714
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1715
+        // on verifie que l'extension choisie est bonne (en principe oui)
1716
+        $gd_formats = formats_image_acceptables(true);
1717
+        if (
1718
+            is_array($image)
1719
+            && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1720
+        ) {
1721
+            $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif'];
1722
+            // Choisir le format destination
1723
+            // - on sauve de preference en JPEG (meilleure compression)
1724
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1725
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1726
+            # pas *ecrire*
1727
+            $format_sortie = '';
1728
+            foreach ($formats_sortie as $fmt) {
1729
+                if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1730
+                    $format_sortie = $fmt;
1731
+                    break;
1732
+                }
1733
+            }
1734
+            $image = false;
1735
+        }
1736
+    }
1737
+
1738
+    if (!is_array($image)) {
1739
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1740
+    }
1741
+
1742
+    if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) {
1743
+        spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1744
+        // on peut resizer en mode html si on dispose des elements
1745
+        [$srcw, $srch] = taille_image($img);
1746
+        if ($srcw && $srch) {
1747
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1748
+
1749
+            return _image_tag_changer_taille($img, $w, $h);
1750
+        }
1751
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1752
+        // sous la forme style='max-width: NNpx;'
1753
+        return inserer_attribut(
1754
+            $img,
1755
+            'style',
1756
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1757
+        );
1758
+    }
1759
+
1760
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1761
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1762
+        if ($image['creer']) {
1763
+            @copy($image['fichier'], $image['fichier_dest']);
1764
+        }
1765
+
1766
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1767
+    }
1768
+
1769
+    if ($image['creer'] == false && !$force) {
1770
+        return _image_ecrire_tag(
1771
+            $image,
1772
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1773
+        );
1774
+    }
1775
+
1776
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1777
+        $destWidth = $image['largeur_dest'];
1778
+        $destHeight = $image['hauteur_dest'];
1779
+        $logo = $image['fichier'];
1780
+        $date = $image['date_src'];
1781
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1782
+
1783
+        if ($preview && $preview['fichier']) {
1784
+            $logo = $preview['fichier'];
1785
+            $destWidth = $preview['width'];
1786
+            $destHeight = $preview['height'];
1787
+            $date = $preview['date'];
1788
+        }
1789
+        // dans l'espace prive mettre un timestamp sur l'adresse
1790
+        // de l'image, de facon a tromper le cache du navigateur
1791
+        // quand on fait supprimer/reuploader un logo
1792
+        // (pas de filemtime si SAFE MODE)
1793
+        $date = test_espace_prive() ? ('?' . $date) : '';
1794
+
1795
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796
+    }
1797
+    else {
1798
+        # BMP, tiff ... les redacteurs osent tout!
1799
+        return $img;
1800
+    }
1801 1801
 }
1802 1802
 
1803 1803
 /**
@@ -1811,145 +1811,145 @@  discard block
 block discarded – undo
1811 1811
  * Class phpthumb_functions
1812 1812
  */
1813 1813
 class phpthumb_functions {
1814
-	/**
1815
-	 * Retourne la couleur d'un pixel dans une image
1816
-	 *
1817
-	 * @param GdImage $img
1818
-	 * @param int $x
1819
-	 * @param int $y
1820
-	 * @return array|bool
1821
-	 */
1822
-	public static function GetPixelColor(&$img, $x, $y) {
1823
-		if ($img instanceof \GdImage) {
1824
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1825
-		}
1826
-		return false;
1827
-	}
1828
-
1829
-	/**
1830
-	 * Retourne un nombre dans une représentation en Little Endian
1831
-	 *
1832
-	 * @param int $number
1833
-	 * @param int $minbytes
1834
-	 * @return string
1835
-	 */
1836
-	public static function LittleEndian2String($number, $minbytes = 1) {
1837
-		$intstring = '';
1838
-		while ($number > 0) {
1839
-			$intstring .= chr($number & 255);
1840
-			$number >>= 8;
1841
-		}
1842
-
1843
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1844
-	}
1845
-
1846
-	/**
1847
-	 * Transforme une ressource GD en image au format ICO
1848
-	 *
1849
-	 * @param array $gd_image_array
1850
-	 *     Tableau de ressources d'images GD
1851
-	 * @return string
1852
-	 *     Image au format ICO
1853
-	 */
1854
-	public static function GD2ICOstring(&$gd_image_array) {
1855
-		foreach ($gd_image_array as $key => $gd_image) {
1856
-			$ImageWidths[$key] = ImageSX($gd_image);
1857
-			$ImageHeights[$key] = ImageSY($gd_image);
1858
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1859
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1860
-
1861
-			$icXOR[$key] = '';
1862
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1863
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1864
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1865
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1866
-					$r = $argb['red'];
1867
-					$g = $argb['green'];
1868
-					$b = $argb['blue'];
1869
-
1870
-					if ($bpp[$key] == 32) {
1871
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1872
-					} elseif ($bpp[$key] === 24) {
1873
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1874
-					}
1875
-
1876
-					if ($a < 128) {
1877
-						@$icANDmask[$key][$y] .= '1';
1878
-					} else {
1879
-						@$icANDmask[$key][$y] .= '0';
1880
-					}
1881
-				}
1882
-				// mask bits are 32-bit aligned per scanline
1883
-				while (strlen($icANDmask[$key][$y]) % 32) {
1884
-					$icANDmask[$key][$y] .= '0';
1885
-				}
1886
-			}
1887
-			$icAND[$key] = '';
1888
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1889
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1890
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1891
-				}
1892
-			}
1893
-		}
1894
-
1895
-		foreach (array_keys($gd_image_array) as $key) {
1896
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1897
-
1898
-			// BITMAPINFOHEADER - 40 bytes
1899
-			$BitmapInfoHeader[$key] = '';
1900
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1901
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1902
-			// The biHeight member specifies the combined
1903
-			// height of the XOR and AND masks.
1904
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1905
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1906
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1907
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1908
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1909
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1910
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1911
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1912
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1913
-		}
1914
-
1915
-
1916
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1917
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1918
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1919
-
1920
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1921
-		foreach (array_keys($gd_image_array) as $key) {
1922
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1923
-
1924
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1925
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1926
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1928
-
1929
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1930
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1931
-
1932
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1933
-			$icondata .= phpthumb_functions::LittleEndian2String(
1934
-				$dwBytesInRes,
1935
-				4
1936
-			);     // dwBytesInRes;	// How many bytes in this resource?
1937
-
1938
-			$icondata .= phpthumb_functions::LittleEndian2String(
1939
-				$dwImageOffset,
1940
-				4
1941
-			);    // dwImageOffset;   // Where in the file is this image?
1942
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1943
-			$dwImageOffset += strlen($icXOR[$key]);
1944
-			$dwImageOffset += strlen($icAND[$key]);
1945
-		}
1946
-
1947
-		foreach (array_keys($gd_image_array) as $key) {
1948
-			$icondata .= $BitmapInfoHeader[$key];
1949
-			$icondata .= $icXOR[$key];
1950
-			$icondata .= $icAND[$key];
1951
-		}
1952
-
1953
-		return $icondata;
1954
-	}
1814
+    /**
1815
+     * Retourne la couleur d'un pixel dans une image
1816
+     *
1817
+     * @param GdImage $img
1818
+     * @param int $x
1819
+     * @param int $y
1820
+     * @return array|bool
1821
+     */
1822
+    public static function GetPixelColor(&$img, $x, $y) {
1823
+        if ($img instanceof \GdImage) {
1824
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1825
+        }
1826
+        return false;
1827
+    }
1828
+
1829
+    /**
1830
+     * Retourne un nombre dans une représentation en Little Endian
1831
+     *
1832
+     * @param int $number
1833
+     * @param int $minbytes
1834
+     * @return string
1835
+     */
1836
+    public static function LittleEndian2String($number, $minbytes = 1) {
1837
+        $intstring = '';
1838
+        while ($number > 0) {
1839
+            $intstring .= chr($number & 255);
1840
+            $number >>= 8;
1841
+        }
1842
+
1843
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1844
+    }
1845
+
1846
+    /**
1847
+     * Transforme une ressource GD en image au format ICO
1848
+     *
1849
+     * @param array $gd_image_array
1850
+     *     Tableau de ressources d'images GD
1851
+     * @return string
1852
+     *     Image au format ICO
1853
+     */
1854
+    public static function GD2ICOstring(&$gd_image_array) {
1855
+        foreach ($gd_image_array as $key => $gd_image) {
1856
+            $ImageWidths[$key] = ImageSX($gd_image);
1857
+            $ImageHeights[$key] = ImageSY($gd_image);
1858
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1859
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1860
+
1861
+            $icXOR[$key] = '';
1862
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1863
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1864
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1865
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1866
+                    $r = $argb['red'];
1867
+                    $g = $argb['green'];
1868
+                    $b = $argb['blue'];
1869
+
1870
+                    if ($bpp[$key] == 32) {
1871
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1872
+                    } elseif ($bpp[$key] === 24) {
1873
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1874
+                    }
1875
+
1876
+                    if ($a < 128) {
1877
+                        @$icANDmask[$key][$y] .= '1';
1878
+                    } else {
1879
+                        @$icANDmask[$key][$y] .= '0';
1880
+                    }
1881
+                }
1882
+                // mask bits are 32-bit aligned per scanline
1883
+                while (strlen($icANDmask[$key][$y]) % 32) {
1884
+                    $icANDmask[$key][$y] .= '0';
1885
+                }
1886
+            }
1887
+            $icAND[$key] = '';
1888
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1889
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1890
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1891
+                }
1892
+            }
1893
+        }
1894
+
1895
+        foreach (array_keys($gd_image_array) as $key) {
1896
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1897
+
1898
+            // BITMAPINFOHEADER - 40 bytes
1899
+            $BitmapInfoHeader[$key] = '';
1900
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1901
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1902
+            // The biHeight member specifies the combined
1903
+            // height of the XOR and AND masks.
1904
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1905
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1906
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1907
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1908
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1909
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1910
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1911
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1912
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1913
+        }
1914
+
1915
+
1916
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1917
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1918
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1919
+
1920
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1921
+        foreach (array_keys($gd_image_array) as $key) {
1922
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1923
+
1924
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1925
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1926
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1928
+
1929
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1930
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1931
+
1932
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1933
+            $icondata .= phpthumb_functions::LittleEndian2String(
1934
+                $dwBytesInRes,
1935
+                4
1936
+            );     // dwBytesInRes;	// How many bytes in this resource?
1937
+
1938
+            $icondata .= phpthumb_functions::LittleEndian2String(
1939
+                $dwImageOffset,
1940
+                4
1941
+            );    // dwImageOffset;   // Where in the file is this image?
1942
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1943
+            $dwImageOffset += strlen($icXOR[$key]);
1944
+            $dwImageOffset += strlen($icAND[$key]);
1945
+        }
1946
+
1947
+        foreach (array_keys($gd_image_array) as $key) {
1948
+            $icondata .= $BitmapInfoHeader[$key];
1949
+            $icondata .= $icXOR[$key];
1950
+            $icondata .= $icAND[$key];
1951
+        }
1952
+
1953
+        return $icondata;
1954
+    }
1955 1955
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 	$blue = dechex($blue);
43 43
 
44 44
 	if (strlen($red) == 1) {
45
-		$red = '0' . $red;
45
+		$red = '0'.$red;
46 46
 	}
47 47
 	if (strlen($green) == 1) {
48
-		$green = '0' . $green;
48
+		$green = '0'.$green;
49 49
 	}
50 50
 	if (strlen($blue) == 1) {
51
-		$blue = '0' . $blue;
51
+		$blue = '0'.$blue;
52 52
 	}
53 53
 
54 54
 	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
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function _couleur_hsl_to_rgb($H, $S, $L) {
187 187
 	// helper
188
-	$hue_2_rgb = function ($v1, $v2, $vH) {
188
+	$hue_2_rgb = function($v1, $v2, $vH) {
189 189
 		if ($vH < 0) {
190 190
 			$vH += 1;
191 191
 		}
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
 		}
320 320
 	} elseif (
321 321
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
-		&& ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
322
+		&& ($extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]))
323 323
 		&& in_array($extension, _image_extensions_acceptees_en_entree())
324 324
 	) {
325 325
 		# gerer img src="data:....base64"
326
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
326
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
327 327
 		if (!file_exists($local)) {
328 328
 			ecrire_fichier($local, base64_decode($regs[2]));
329 329
 		}
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	// les protocoles web prennent au moins 3 lettres
341 341
 	if (tester_url_absolue($source)) {
342 342
 		include_spip('inc/distant');
343
-		$fichier = _DIR_RACINE . copie_locale($source);
343
+		$fichier = _DIR_RACINE.copie_locale($source);
344 344
 		if (!$fichier) {
345 345
 			return '';
346 346
 		}
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 			// on garde la terminaison initiale car image simplement copiee
443 443
 			// et on postfixe son nom avec un md5 du path
444 444
 			$terminaison_dest = $terminaison;
445
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
446 446
 		} else {
447
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
448 448
 		}
449 449
 		$cache = sous_repertoire(_DIR_VAR, $cache);
450 450
 		$cache = sous_repertoire($cache, $effet);
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 		$fichier_dest = substr($fichier_dest, 2);
456 456
 	}
457 457
 
458
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
459 459
 
460 460
 	$GLOBALS['images_calculees'][] = $fichier_dest;
461 461
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	}
482 482
 	if ($creer && !@file_exists($fichier)) {
483 483
 		if (!@file_exists("$fichier.src")) {
484
-			spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR);
484
+			spip_log("Image absente : $fichier", 'images'._LOG_ERREUR);
485 485
 
486 486
 			return false;
487 487
 		}
@@ -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;
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 
643 643
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
644 644
 	if ($_terminaison && $_terminaison !== $terminaison) {
645
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
645
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
646 646
 		$terminaison = $_terminaison;
647 647
 	}
648 648
 	return $terminaison;
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	if (!function_exists('imagepng')) {
778 778
 		return false;
779 779
 	}
780
-	$tmp = $fichier . '.tmp';
780
+	$tmp = $fichier.'.tmp';
781 781
 	$ret = imagepng($img, $tmp);
782 782
 	if (file_exists($tmp)) {
783 783
 		$taille_test = @getimagesize($tmp);
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 	if (!function_exists('imagegif')) {
813 813
 		return false;
814 814
 	}
815
-	$tmp = $fichier . '.tmp';
815
+	$tmp = $fichier.'.tmp';
816 816
 	$ret = imagegif($img, $tmp);
817 817
 	if (file_exists($tmp)) {
818 818
 		$taille_test = @getimagesize($tmp);
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 	if (!function_exists('imagejpeg')) {
853 853
 		return false;
854 854
 	}
855
-	$tmp = $fichier . '.tmp';
855
+	$tmp = $fichier.'.tmp';
856 856
 
857 857
 	// Enable interlancing
858 858
 	imageinterlace($img, true);
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
 	if (!function_exists('imagewebp')) {
914 914
 		return false;
915 915
 	}
916
-	$tmp = $fichier . '.tmp';
916
+	$tmp = $fichier.'.tmp';
917 917
 	$ret = imagewebp($img, $tmp, $qualite);
918 918
 	if (file_exists($tmp)) {
919 919
 		$taille_test = @getimagesize($tmp);
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
  */
948 948
 function _image_imagesvg($img, $fichier) {
949 949
 
950
-	$tmp = $fichier . '.tmp';
950
+	$tmp = $fichier.'.tmp';
951 951
 	if (!str_contains($img, '<')) {
952 952
 		$img = supprimer_timestamp($img);
953 953
 		if (!file_exists($img)) {
@@ -1004,14 +1004,14 @@  discard block
 block discarded – undo
1004 1004
  */
1005 1005
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1006 1006
 	if (is_null($fonction)) {
1007
-		$fonction = '_image_image' . $valeurs['format_dest'];
1007
+		$fonction = '_image_image'.$valeurs['format_dest'];
1008 1008
 	}
1009 1009
 	$ret = false;
1010 1010
 	#un flag pour reperer les images gravees
1011 1011
 	$lock = (
1012 1012
 		!statut_effacer_images_temporaires('get')
1013 1013
 		|| @file_exists($valeurs['fichier_dest'])
1014
-		&& !@file_exists($valeurs['fichier_dest'] . '.src')
1014
+		&& !@file_exists($valeurs['fichier_dest'].'.src')
1015 1015
 	);
1016 1016
 	if (
1017 1017
 		function_exists($fonction)
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 		[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1024 1024
 		$valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1025 1025
 		// pour la retrouver apres disparition
1026
-		ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1026
+		ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1027 1027
 	}
1028 1028
 
1029 1029
 	return $ret;
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 
1199 1199
 	// attributs deprecies. Transformer en CSS
1200 1200
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1201
-		$style = "margin:{$espace}px;" . $style;
1201
+		$style = "margin:{$espace}px;".$style;
1202 1202
 		$tag = inserer_attribut($tag, 'hspace', '');
1203 1203
 	}
1204 1204
 
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
 	$image = $valeurs['fichier'];
1322 1322
 	$format = $valeurs['format_source'];
1323 1323
 	$destdir = dirname((string) $valeurs['fichier_dest']);
1324
-	$destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1324
+	$destfile = basename((string) $valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1325 1325
 
1326 1326
 	$format_sortie = $valeurs['format_dest'];
1327 1327
 
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 
1354 1354
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1355 1355
 	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1356
-		$vignette = $destination . '.' . $format;
1356
+		$vignette = $destination.'.'.$format;
1357 1357
 		@copy($image, $vignette);
1358 1358
 	}
1359 1359
 
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
 		include_spip('inc/svg');
1362 1362
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1363 1363
 			$format_sortie = 'svg';
1364
-			$vignette = $destination . '.' . $format_sortie;
1364
+			$vignette = $destination.'.'.$format_sortie;
1365 1365
 			$valeurs['fichier_dest'] = $vignette;
1366 1366
 			_image_gd_output($svg, $valeurs);
1367 1367
 		}
@@ -1373,9 +1373,9 @@  discard block
 block discarded – undo
1373 1373
 			define('_CONVERT_COMMAND', 'convert');
1374 1374
 		} // Securite : mes_options.php peut preciser le chemin absolu
1375 1375
 		if (!defined('_RESIZE_COMMAND')) {
1376
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1376
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -orient Undefined -resize %xx%y! %src %dest');
1377 1377
 		}
1378
-		$vignette = $destination . '.' . $format_sortie;
1378
+		$vignette = $destination.'.'.$format_sortie;
1379 1379
 		$commande = str_replace(
1380 1380
 			['%x', '%y', '%src', '%dest'],
1381 1381
 			[
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
 		if (!@file_exists($vignette)) {
1392 1392
 			spip_log("echec convert sur $vignette");
1393 1393
 
1394
-			return;  // echec commande
1394
+			return; // echec commande
1395 1395
 		}
1396 1396
 	}
1397 1397
 
@@ -1408,7 +1408,7 @@  discard block
 block discarded – undo
1408 1408
 		if (!$output) {
1409 1409
 			return;
1410 1410
 		}
1411
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1411
+		$vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie;
1412 1412
 
1413 1413
 		$imagick = new Imagick();
1414 1414
 		$imagick->readImage(realpath($image));
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 			$destHeight,
1418 1418
 			Imagick::FILTER_LANCZOS,
1419 1419
 			1
1420
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1420
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1421 1421
 		$imagick->writeImage($vignette);
1422 1422
 
1423 1423
 		if (!@file_exists($vignette)) {
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
 			return;
1427 1427
 		}
1428 1428
 		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1429
-		$vignette = $destination . '.' . $format_sortie;
1429
+		$vignette = $destination.'.'.$format_sortie;
1430 1430
 	}
1431 1431
 
1432 1432
 	// netpbm
@@ -1437,11 +1437,11 @@  discard block
 block discarded – undo
1437 1437
 		if (_PNMSCALE_COMMAND == '') {
1438 1438
 			return;
1439 1439
 		}
1440
-		$vignette = $destination . '.' . $format_sortie;
1440
+		$vignette = $destination.'.'.$format_sortie;
1441 1441
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND);
1442 1442
 		if ($format == 'jpg') {
1443 1443
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND);
1444
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1444
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1445 1445
 			if (!($s = @filesize($vignette))) {
1446 1446
 				spip_unlink($vignette);
1447 1447
 			}
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
 		} else {
1454 1454
 			if ($format == 'gif') {
1455 1455
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND);
1456
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1456
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1457 1457
 				if (!($s = @filesize($vignette))) {
1458 1458
 					spip_unlink($vignette);
1459 1459
 				}
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 			} else {
1466 1466
 				if ($format == 'png') {
1467 1467
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND);
1468
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1468
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1469 1469
 					if (!($s = @filesize($vignette))) {
1470 1470
 						spip_unlink($vignette);
1471 1471
 					}
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
 			return;
1488 1488
 		}
1489 1489
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1490
-			spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1490
+			spip_log('vignette gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1491 1491
 
1492 1492
 			return;
1493 1493
 		}
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
 		// de l'image, de facon a tromper le cache du navigateur
1791 1791
 		// quand on fait supprimer/reuploader un logo
1792 1792
 		// (pas de filemtime si SAFE MODE)
1793
-		$date = test_espace_prive() ? ('?' . $date) : '';
1793
+		$date = test_espace_prive() ? ('?'.$date) : '';
1794 1794
 
1795 1795
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796 1796
 	}
@@ -1868,9 +1868,9 @@  discard block
 block discarded – undo
1868 1868
 					$b = $argb['blue'];
1869 1869
 
1870 1870
 					if ($bpp[$key] == 32) {
1871
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1871
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1872 1872
 					} elseif ($bpp[$key] === 24) {
1873
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1873
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1874 1874
 					}
1875 1875
 
1876 1876
 					if ($a < 128) {
@@ -1897,48 +1897,48 @@  discard block
 block discarded – undo
1897 1897
 
1898 1898
 			// BITMAPINFOHEADER - 40 bytes
1899 1899
 			$BitmapInfoHeader[$key] = '';
1900
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1901
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1900
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1901
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1902 1902
 			// The biHeight member specifies the combined
1903 1903
 			// height of the XOR and AND masks.
1904 1904
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1905
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1906
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1907
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1908
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1909
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1910
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1911
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1912
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1905
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1906
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1907
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1908
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1909
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1910
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1911
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1912
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1913 1913
 		}
1914 1914
 
1915 1915
 
1916
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1917
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1918
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1916
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1917
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1918
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1919 1919
 
1920 1920
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1921 1921
 		foreach (array_keys($gd_image_array) as $key) {
1922 1922
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1923 1923
 
1924
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1925
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1926
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1924
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1925
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1926
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1928 1928
 
1929
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1930
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1929
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1930
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1931 1931
 
1932 1932
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1933 1933
 			$icondata .= phpthumb_functions::LittleEndian2String(
1934 1934
 				$dwBytesInRes,
1935 1935
 				4
1936
-			);     // dwBytesInRes;	// How many bytes in this resource?
1936
+			); // dwBytesInRes;	// How many bytes in this resource?
1937 1937
 
1938 1938
 			$icondata .= phpthumb_functions::LittleEndian2String(
1939 1939
 				$dwImageOffset,
1940 1940
 				4
1941
-			);    // dwImageOffset;   // Where in the file is this image?
1941
+			); // dwImageOffset;   // Where in the file is this image?
1942 1942
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1943 1943
 			$dwImageOffset += strlen($icXOR[$key]);
1944 1944
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/admin.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -44,29 +44,29 @@  discard block
 block discarded – undo
44 44
  *     sinon code HTML de la page après le traitement effectué.
45 45
  **/
46 46
 function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) {
47
-	$reprise = true;
48
-	if (
49
-		!isset($GLOBALS['meta'][$script])
50
-		|| !isset($GLOBALS['meta']['admin'])
51
-	) {
52
-		$reprise = false;
53
-		$res = debut_admin($script, $titre, $comment);
54
-		if ($res) {
55
-			return $res;
56
-		}
57
-		spip_log("meta: $script " . print_r($_POST, true));
58
-		ecrire_meta($script, serialize($_POST));
59
-	}
47
+    $reprise = true;
48
+    if (
49
+        !isset($GLOBALS['meta'][$script])
50
+        || !isset($GLOBALS['meta']['admin'])
51
+    ) {
52
+        $reprise = false;
53
+        $res = debut_admin($script, $titre, $comment);
54
+        if ($res) {
55
+            return $res;
56
+        }
57
+        spip_log("meta: $script " . print_r($_POST, true));
58
+        ecrire_meta($script, serialize($_POST));
59
+    }
60 60
 
61
-	$res = admin_verifie_session($script, $anonymous);
62
-	if ($res) {
63
-		return $res;
64
-	}
65
-	$base = charger_fonction($script, 'base');
66
-	$base($titre, $reprise);
67
-	fin_admin($script);
61
+    $res = admin_verifie_session($script, $anonymous);
62
+    if ($res) {
63
+        return $res;
64
+    }
65
+    $base = charger_fonction($script, 'base');
66
+    $base($titre, $reprise);
67
+    fin_admin($script);
68 68
 
69
-	return '';
69
+    return '';
70 70
 }
71 71
 
72 72
 /**
@@ -97,36 +97,36 @@  discard block
 block discarded – undo
97 97
  *     Code HTML si message d'erreur, '' sinon;
98 98
  */
99 99
 function admin_verifie_session($script, $anonymous = false) {
100
-	include_spip('base/abstract_sql');
101
-	$pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']);
102
-	$signal = fichier_admin($script, "$script$pref");
103
-	$valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
104
-	if ($valeur === null) {
105
-		ecrire_meta('admin', $signal, 'non');
106
-	} else {
107
-		if (
108
-			!$anonymous
109
-			&& $valeur != $signal
110
-			&& (
111
-				!preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l)
112
-				|| (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur']
113
-			)
114
-		) {
115
-			include_spip('inc/minipres');
116
-			spip_log("refus de lancer $script, priorite a $valeur");
117
-			return minipres(_T('info_travaux_texte'), '', ['status' => 503]);
118
-		}
119
-	}
120
-	$journal = 'spip';
121
-	if (autoriser('configurer')) {
122
-		// c'est une action webmestre, soit par ftp soit par statut webmestre
123
-		$journal = 'webmestre';
124
-	}
125
-	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
100
+    include_spip('base/abstract_sql');
101
+    $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']);
102
+    $signal = fichier_admin($script, "$script$pref");
103
+    $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
104
+    if ($valeur === null) {
105
+        ecrire_meta('admin', $signal, 'non');
106
+    } else {
107
+        if (
108
+            !$anonymous
109
+            && $valeur != $signal
110
+            && (
111
+                !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l)
112
+                || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur']
113
+            )
114
+        ) {
115
+            include_spip('inc/minipres');
116
+            spip_log("refus de lancer $script, priorite a $valeur");
117
+            return minipres(_T('info_travaux_texte'), '', ['status' => 503]);
118
+        }
119
+    }
120
+    $journal = 'spip';
121
+    if (autoriser('configurer')) {
122
+        // c'est une action webmestre, soit par ftp soit par statut webmestre
123
+        $journal = 'webmestre';
124
+    }
125
+    // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
126 126
 
127
-	spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal);
127
+    spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal);
128 128
 
129
-	return '';
129
+    return '';
130 130
 }
131 131
 
132 132
 /**
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
  *     Chemin du répertoire.
140 140
  **/
141 141
 function dir_admin() {
142
-	if (autoriser('configurer')) {
143
-		return _DIR_TMP;
144
-	} else {
145
-		return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
146
-	}
142
+    if (autoriser('configurer')) {
143
+        return _DIR_TMP;
144
+    } else {
145
+        return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
146
+    }
147 147
 }
148 148
 
149 149
 /**
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
  *     Nom du fichier
161 161
  **/
162 162
 function fichier_admin($action, $pref = 'admin_') {
163
-	return $pref .
164
-	substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10);
163
+    return $pref .
164
+    substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10);
165 165
 }
166 166
 
167 167
 /**
@@ -187,76 +187,76 @@  discard block
 block discarded – undo
187 187
  *     sinon chaîne vide si déjà fait.
188 188
  **/
189 189
 function debut_admin($script, $action = '', $corps = '') {
190
-	if (
191
-		!$action
192
-		|| !autoriser('webmestre') && !autoriser('chargerftp')
193
-	) {
194
-		include_spip('inc/minipres');
190
+    if (
191
+        !$action
192
+        || !autoriser('webmestre') && !autoriser('chargerftp')
193
+    ) {
194
+        include_spip('inc/minipres');
195 195
 
196
-		return minipres();
197
-	} else {
198
-		$dir = dir_admin();
199
-		$signal = fichier_admin($script);
200
-		if (@file_exists($dir . $signal)) {
201
-			spip_log("Action admin: $action");
196
+        return minipres();
197
+    } else {
198
+        $dir = dir_admin();
199
+        $signal = fichier_admin($script);
200
+        if (@file_exists($dir . $signal)) {
201
+            spip_log("Action admin: $action");
202 202
 
203
-			return '';
204
-		}
205
-		include_spip('inc/minipres');
203
+            return '';
204
+        }
205
+        include_spip('inc/minipres');
206 206
 
207
-		// Si on est un super-admin, un bouton de validation suffit
208
-		// sauf dans les cas destroy
209
-		if (
210
-			(autoriser('webmestre') || $script === 'repair')
211
-			&& $script != 'delete_all'
212
-		) {
213
-			if (_request('validation_admin') == $signal) {
214
-				spip_log("Action super-admin: $action");
207
+        // Si on est un super-admin, un bouton de validation suffit
208
+        // sauf dans les cas destroy
209
+        if (
210
+            (autoriser('webmestre') || $script === 'repair')
211
+            && $script != 'delete_all'
212
+        ) {
213
+            if (_request('validation_admin') == $signal) {
214
+                spip_log("Action super-admin: $action");
215 215
 
216
-				return '';
217
-			}
218
-			$corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />';
219
-			$suivant = _T('bouton_valider');
220
-			$js = '';
221
-		} else {
222
-			// cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
223
-			// l'insertion du script a cet endroit n'est pas xhtml licite
224
-			// mais evite de l'embarquer dans toutes les pages minipres
225
-			$corps .= http_script('', 'spip_barre.js');
216
+                return '';
217
+            }
218
+            $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />';
219
+            $suivant = _T('bouton_valider');
220
+            $js = '';
221
+        } else {
222
+            // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
223
+            // l'insertion du script a cet endroit n'est pas xhtml licite
224
+            // mais evite de l'embarquer dans toutes les pages minipres
225
+            $corps .= http_script('', 'spip_barre.js');
226 226
 
227
-			$corps .= '<fieldset><legend>'
228
-				. _T('info_authentification_ftp')
229
-				. aider('ftp_auth')
230
-				. "</legend>\n<label for='fichier'>"
231
-				. _T('info_creer_repertoire')
232
-				. "</label>\n"
233
-				. "<span id='signal' class='formo'>" . $signal . '</span>'
234
-				. "<input type='hidden' id='fichier' name='fichier' value='"
235
-				. $signal
236
-				. "' />"
237
-				. _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)])
238
-				. '</fieldset>';
227
+            $corps .= '<fieldset><legend>'
228
+                . _T('info_authentification_ftp')
229
+                . aider('ftp_auth')
230
+                . "</legend>\n<label for='fichier'>"
231
+                . _T('info_creer_repertoire')
232
+                . "</label>\n"
233
+                . "<span id='signal' class='formo'>" . $signal . '</span>'
234
+                . "<input type='hidden' id='fichier' name='fichier' value='"
235
+                . $signal
236
+                . "' />"
237
+                . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)])
238
+                . '</fieldset>';
239 239
 
240
-			$suivant = _T('bouton_recharger_page');
240
+            $suivant = _T('bouton_recharger_page');
241 241
 
242
-			// code volontairement tordu:
243
-			// provoquer la copie dans le presse papier du nom du repertoire
244
-			// en remettant a vide le champ pour que ca marche aussi en cas
245
-			// de JavaScript inactif.
246
-			$js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'";
247
-		}
242
+            // code volontairement tordu:
243
+            // provoquer la copie dans le presse papier du nom du repertoire
244
+            // en remettant a vide le champ pour que ca marche aussi en cas
245
+            // de JavaScript inactif.
246
+            $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'";
247
+        }
248 248
 
249
-		// admin/xxx correspond
250
-		// a exec/base_xxx de preference
251
-		// et exec/xxx sinon (compat)
252
-		if (tester_url_ecrire("base_$script")) {
253
-			$script = "base_$script";
254
-		}
255
-		$form = copy_request($script, $corps, $suivant);
256
-		$info_action = _T('info_action', ['action' => "$action"]);
249
+        // admin/xxx correspond
250
+        // a exec/base_xxx de preference
251
+        // et exec/xxx sinon (compat)
252
+        if (tester_url_ecrire("base_$script")) {
253
+            $script = "base_$script";
254
+        }
255
+        $form = copy_request($script, $corps, $suivant);
256
+        $info_action = _T('info_action', ['action' => "$action"]);
257 257
 
258
-		return minipres($info_action, $form, ['onload' => $js]);
259
-	}
258
+        return minipres($info_action, $form, ['onload' => $js]);
259
+    }
260 260
 }
261 261
 
262 262
 /**
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
  *     Nom de l'action (en base) qui a été exécutée
268 268
  **/
269 269
 function fin_admin($action) {
270
-	$signal = dir_admin() . fichier_admin($action);
271
-	spip_unlink($signal);
272
-	if ($action != 'delete_all') {
273
-		effacer_meta($action);
274
-		effacer_meta('admin');
275
-		spip_log("efface les meta admin et $action ");
276
-	}
270
+    $signal = dir_admin() . fichier_admin($action);
271
+    spip_unlink($signal);
272
+    if ($action != 'delete_all') {
273
+        effacer_meta($action);
274
+        effacer_meta('admin');
275
+        spip_log("efface les meta admin et $action ");
276
+    }
277 277
 }
278 278
 
279 279
 /**
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
  *     Code HTML du formulaire
293 293
  **/
294 294
 function copy_request($script, $suite, $submit = '') {
295
-	include_spip('inc/filtres');
296
-	foreach ([...$_POST, ...$_GET] as $n => $c) {
297
-		if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) {
298
-			$suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" .
299
-				entites_html($c) .
300
-				"'  />";
301
-		}
302
-	}
295
+    include_spip('inc/filtres');
296
+    foreach ([...$_POST, ...$_GET] as $n => $c) {
297
+        if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) {
298
+            $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" .
299
+                entites_html($c) .
300
+                "'  />";
301
+        }
302
+    }
303 303
 
304
-	return generer_form_ecrire($script, $suite, '', $submit);
304
+    return generer_form_ecrire($script, $suite, '', $submit);
305 305
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		if ($res) {
55 55
 			return $res;
56 56
 		}
57
-		spip_log("meta: $script " . print_r($_POST, true));
57
+		spip_log("meta: $script ".print_r($_POST, true));
58 58
 		ecrire_meta($script, serialize($_POST));
59 59
 	}
60 60
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	}
125 125
 	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
126 126
 
127
-	spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal);
127
+	spip_log("admin $pref".($valeur ? ' (reprise)' : ' (init)'), $journal);
128 128
 
129 129
 	return '';
130 130
 }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	if (autoriser('configurer')) {
143 143
 		return _DIR_TMP;
144 144
 	} else {
145
-		return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
145
+		return _DIR_TRANSFERT.$GLOBALS['visiteur_session']['login'].'/';
146 146
 	}
147 147
 }
148 148
 
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
  *     Nom du fichier
161 161
  **/
162 162
 function fichier_admin($action, $pref = 'admin_') {
163
-	return $pref .
164
-	substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10);
163
+	return $pref.
164
+	substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10);
165 165
 }
166 166
 
167 167
 /**
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	} else {
198 198
 		$dir = dir_admin();
199 199
 		$signal = fichier_admin($script);
200
-		if (@file_exists($dir . $signal)) {
200
+		if (@file_exists($dir.$signal)) {
201 201
 			spip_log("Action admin: $action");
202 202
 
203 203
 			return '';
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 
216 216
 				return '';
217 217
 			}
218
-			$corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />';
218
+			$corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />';
219 219
 			$suivant = _T('bouton_valider');
220 220
 			$js = '';
221 221
 		} else {
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 				. "</legend>\n<label for='fichier'>"
231 231
 				. _T('info_creer_repertoire')
232 232
 				. "</label>\n"
233
-				. "<span id='signal' class='formo'>" . $signal . '</span>'
233
+				. "<span id='signal' class='formo'>".$signal.'</span>'
234 234
 				. "<input type='hidden' id='fichier' name='fichier' value='"
235 235
 				. $signal
236 236
 				. "' />"
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
  *     Nom de l'action (en base) qui a été exécutée
268 268
  **/
269 269
 function fin_admin($action) {
270
-	$signal = dir_admin() . fichier_admin($action);
270
+	$signal = dir_admin().fichier_admin($action);
271 271
 	spip_unlink($signal);
272 272
 	if ($action != 'delete_all') {
273 273
 		effacer_meta($action);
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	include_spip('inc/filtres');
296 296
 	foreach ([...$_POST, ...$_GET] as $n => $c) {
297 297
 		if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) {
298
-			$suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" .
299
-				entites_html($c) .
298
+			$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='".
299
+				entites_html($c).
300 300
 				"'  />";
301 301
 		}
302 302
 	}
Please login to merge, or discard this patch.
ecrire/inc/editer.php 3 patches
Indentation   +434 added lines, -434 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 include_spip('base/abstract_sql');
22 22
 
@@ -58,56 +58,56 @@  discard block
 block discarded – undo
58 58
  *     Retour des traitements.
59 59
  **/
60 60
 function formulaires_editer_objet_traiter(
61
-	$type,
62
-	$id = 'new',
63
-	$id_parent = 0,
64
-	$lier_trad = 0,
65
-	$retour = '',
66
-	$config_fonc = 'articles_edit_config',
67
-	$row = [],
68
-	$hidden = ''
61
+    $type,
62
+    $id = 'new',
63
+    $id_parent = 0,
64
+    $lier_trad = 0,
65
+    $retour = '',
66
+    $config_fonc = 'articles_edit_config',
67
+    $row = [],
68
+    $hidden = ''
69 69
 ) {
70 70
 
71
-	$res = [];
72
-	// eviter la redirection forcee par l'action...
73
-	set_request('redirect');
74
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
75
-		[$id, $err] = $action_editer($id);
76
-	} else {
77
-		$action_editer = charger_fonction('editer_objet', 'action');
78
-		[$id, $err] = $action_editer($id, $type);
79
-	}
80
-	$id_table_objet = id_table_objet($type);
81
-	$res[$id_table_objet] = $id;
82
-	if ($err || !$id) {
83
-		$res['message_erreur'] = ($err ?: _T('erreur'));
84
-	} else {
85
-		// Un lien de trad a prendre en compte
86
-		if ($lier_trad) {
87
-			// referencer la traduction
88
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
89
-			$referencer_traduction($type, $id, $lier_trad);
90
-			// actions de recopie de champs / liens sur le nouvel objet créé
91
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
92
-			$err = $completer_traduction($type, $id, $lier_trad);
93
-			if ($err) {
94
-				$res['message_erreur'] = $err;
95
-				return $res;
96
-			}
97
-		}
98
-
99
-		$res['message_ok'] = _T('info_modification_enregistree');
100
-		if ($retour) {
101
-			if (str_starts_with($retour, 'javascript:')) {
102
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
-				$res['editable'] = true;
104
-			} else {
105
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
106
-			}
107
-		}
108
-	}
109
-
110
-	return $res;
71
+    $res = [];
72
+    // eviter la redirection forcee par l'action...
73
+    set_request('redirect');
74
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
75
+        [$id, $err] = $action_editer($id);
76
+    } else {
77
+        $action_editer = charger_fonction('editer_objet', 'action');
78
+        [$id, $err] = $action_editer($id, $type);
79
+    }
80
+    $id_table_objet = id_table_objet($type);
81
+    $res[$id_table_objet] = $id;
82
+    if ($err || !$id) {
83
+        $res['message_erreur'] = ($err ?: _T('erreur'));
84
+    } else {
85
+        // Un lien de trad a prendre en compte
86
+        if ($lier_trad) {
87
+            // referencer la traduction
88
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
89
+            $referencer_traduction($type, $id, $lier_trad);
90
+            // actions de recopie de champs / liens sur le nouvel objet créé
91
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
92
+            $err = $completer_traduction($type, $id, $lier_trad);
93
+            if ($err) {
94
+                $res['message_erreur'] = $err;
95
+                return $res;
96
+            }
97
+        }
98
+
99
+        $res['message_ok'] = _T('info_modification_enregistree');
100
+        if ($retour) {
101
+            if (str_starts_with($retour, 'javascript:')) {
102
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+                $res['editable'] = true;
104
+            } else {
105
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
106
+            }
107
+        }
108
+    }
109
+
110
+    return $res;
111 111
 }
112 112
 
113 113
 /**
@@ -131,29 +131,29 @@  discard block
 block discarded – undo
131 131
  *     Tableau des erreurs
132 132
  **/
133 133
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) {
134
-	$erreurs = [];
135
-	if ((int) $id) {
136
-		$conflits = controler_contenu($type, $id);
137
-		if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) {
138
-			foreach ($conflits as $champ => $conflit) {
139
-				if (!isset($erreurs[$champ])) {
140
-					$erreurs[$champ] = '';
141
-				}
142
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
-			}
144
-		}
145
-	}
146
-	foreach ($oblis as $obli) {
147
-		$value = _request($obli);
148
-		if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) {
149
-			if (!isset($erreurs[$obli])) {
150
-				$erreurs[$obli] = '';
151
-			}
152
-			$erreurs[$obli] .= _T('info_obligatoire');
153
-		}
154
-	}
155
-
156
-	return $erreurs;
134
+    $erreurs = [];
135
+    if ((int) $id) {
136
+        $conflits = controler_contenu($type, $id);
137
+        if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) {
138
+            foreach ($conflits as $champ => $conflit) {
139
+                if (!isset($erreurs[$champ])) {
140
+                    $erreurs[$champ] = '';
141
+                }
142
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
+            }
144
+        }
145
+    }
146
+    foreach ($oblis as $obli) {
147
+        $value = _request($obli);
148
+        if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) {
149
+            if (!isset($erreurs[$obli])) {
150
+                $erreurs[$obli] = '';
151
+            }
152
+            $erreurs[$obli] .= _T('info_obligatoire');
153
+        }
154
+    }
155
+
156
+    return $erreurs;
157 157
 }
158 158
 
159 159
 /**
@@ -198,152 +198,152 @@  discard block
 block discarded – undo
198 198
  *     Environnement du formulaire.
199 199
  **/
200 200
 function formulaires_editer_objet_charger(
201
-	$type,
202
-	$id = 'new',
203
-	$id_parent = 0,
204
-	$lier_trad = 0,
205
-	$retour = '',
206
-	$config_fonc = 'articles_edit_config',
207
-	$row = [],
208
-	$hidden = ''
201
+    $type,
202
+    $id = 'new',
203
+    $id_parent = 0,
204
+    $lier_trad = 0,
205
+    $retour = '',
206
+    $config_fonc = 'articles_edit_config',
207
+    $row = [],
208
+    $hidden = ''
209 209
 ) {
210 210
 
211
-	$table_objet = table_objet($type);
212
-	$table_objet_sql = table_objet_sql($type);
213
-	$id_table_objet = id_table_objet($type);
214
-	if (!is_array($row)) {
215
-		$row = [];
216
-	}
217
-
218
-	// on accepte pas une fonction de config inconnue si elle vient d'un modele
219
-	if (
220
-		$config_fonc
221
-		&& !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
222
-		&& $config_fonc !== $table_objet . '_edit_config'
223
-		&& ($args = test_formulaire_inclus_par_modele())
224
-		&& in_array($config_fonc, $args)
225
-	) {
226
-		$config_fonc = '';
227
-	}
228
-
229
-	$new = !is_numeric($id);
230
-	$lang_default = '';
231
-	// Appel direct dans un squelette
232
-	if (!$row) {
233
-		if (!$new || $lier_trad) {
234
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
235
-				$row = $select($id, $id_parent, $lier_trad);
236
-				// si on a une fonction precharger, elle pu faire un reglage de langue
237
-				$lang_default = (empty($row['lang']) ? null : $row['lang']);
238
-			} else {
239
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id);
240
-			}
241
-			if (!$new) {
242
-				$md5 = controles_md5($row ?: []);
243
-			}
244
-		}
245
-		if (!$row) {
246
-			$row = [];
247
-			$trouver_table = charger_fonction('trouver_table', 'base');
248
-			if ($desc = $trouver_table($table_objet)) {
249
-				foreach ($desc['field'] as $k => $v) {
250
-					$row[$k] = '';
251
-				}
252
-			}
253
-		}
254
-	}
255
-
256
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
257
-	// (et donc: pas de lien de traduction)
258
-	$id = ($new || $lier_trad)
259
-		? 'oui'
260
-		: $row[$id_table_objet];
261
-	$row[$id_table_objet] = $id;
262
-
263
-	$contexte = $row;
264
-	if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) {
265
-		if (!isset($contexte['id_parent'])) {
266
-			unset($contexte['id_rubrique']);
267
-		}
268
-		$contexte['id_parent'] = $id_parent;
269
-	} elseif (!isset($contexte['id_parent'])) {
270
-		// id_rubrique dans id_parent si possible
271
-		if (isset($contexte['id_rubrique'])) {
272
-			$contexte['id_parent'] = $contexte['id_rubrique'];
273
-			unset($contexte['id_rubrique']);
274
-		} else {
275
-			$contexte['id_parent'] = '';
276
-		}
277
-		if (
278
-			!$contexte['id_parent']
279
-			&& ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true))
280
-		) {
281
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
282
-		}
283
-	}
284
-
285
-	$config = [];
286
-	if ($config_fonc) {
287
-		$contexte['config'] = $config = $config_fonc($contexte);
288
-		if (!$lang_default) {
289
-			$lang_default = $config['langue'] ?? session_get('lang') ;
290
-		}
291
-	}
292
-	$config += [
293
-		'lignes' => 0,
294
-		'langue' => '',
295
-	];
296
-
297
-	$att_text = " class='textarea' "
298
-		. " rows='"
299
-		. ($config['lignes'] + 15)
300
-		. "' cols='40'";
301
-	if (isset($contexte['texte'])) {
302
-		[$contexte['texte'], $contexte['_texte_trop_long']] = editer_texte_recolle($contexte['texte'], $att_text);
303
-	}
304
-
305
-	// on veut conserver la langue de l'interface ;
306
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
307
-	// voudrait l'exploiter
308
-	if (isset($contexte['lang'])) {
309
-		$contexte['langue'] = $contexte['lang'];
310
-		unset($contexte['lang']);
311
-	}
312
-
313
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
314
-		($lier_trad
315
-			 ? "\n<input type='hidden' name='lier_trad' value='" .
316
-				$lier_trad .
317
-				"' />" .
318
-				"\n<input type='hidden' name='changer_lang' value='" .
319
-				$lang_default .
320
-				"' />"
321
-			: '')
322
-		. $hidden
323
-		. ($md5 ?? '');
324
-
325
-	// preciser que le formulaire doit passer dans un pipeline
326
-	$contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]];
327
-
328
-	// preciser que le formulaire doit etre securise auteur/action
329
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
330
-	// on le garde pour compat
331
-	$contexte['_action'] = ["editer_$type", $id];
332
-
333
-	// et in fine placer l'autorisation
334
-	include_spip('inc/autoriser');
335
-	if ((int) $id) {
336
-		if (!autoriser('modifier', $type, (int) $id)) {
337
-			$contexte['editable'] = '';
338
-		}
339
-	}
340
-	else {
341
-		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
342
-			$contexte['editable'] = '';
343
-		}
344
-	}
345
-
346
-	return $contexte;
211
+    $table_objet = table_objet($type);
212
+    $table_objet_sql = table_objet_sql($type);
213
+    $id_table_objet = id_table_objet($type);
214
+    if (!is_array($row)) {
215
+        $row = [];
216
+    }
217
+
218
+    // on accepte pas une fonction de config inconnue si elle vient d'un modele
219
+    if (
220
+        $config_fonc
221
+        && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
222
+        && $config_fonc !== $table_objet . '_edit_config'
223
+        && ($args = test_formulaire_inclus_par_modele())
224
+        && in_array($config_fonc, $args)
225
+    ) {
226
+        $config_fonc = '';
227
+    }
228
+
229
+    $new = !is_numeric($id);
230
+    $lang_default = '';
231
+    // Appel direct dans un squelette
232
+    if (!$row) {
233
+        if (!$new || $lier_trad) {
234
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
235
+                $row = $select($id, $id_parent, $lier_trad);
236
+                // si on a une fonction precharger, elle pu faire un reglage de langue
237
+                $lang_default = (empty($row['lang']) ? null : $row['lang']);
238
+            } else {
239
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id);
240
+            }
241
+            if (!$new) {
242
+                $md5 = controles_md5($row ?: []);
243
+            }
244
+        }
245
+        if (!$row) {
246
+            $row = [];
247
+            $trouver_table = charger_fonction('trouver_table', 'base');
248
+            if ($desc = $trouver_table($table_objet)) {
249
+                foreach ($desc['field'] as $k => $v) {
250
+                    $row[$k] = '';
251
+                }
252
+            }
253
+        }
254
+    }
255
+
256
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
257
+    // (et donc: pas de lien de traduction)
258
+    $id = ($new || $lier_trad)
259
+        ? 'oui'
260
+        : $row[$id_table_objet];
261
+    $row[$id_table_objet] = $id;
262
+
263
+    $contexte = $row;
264
+    if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) {
265
+        if (!isset($contexte['id_parent'])) {
266
+            unset($contexte['id_rubrique']);
267
+        }
268
+        $contexte['id_parent'] = $id_parent;
269
+    } elseif (!isset($contexte['id_parent'])) {
270
+        // id_rubrique dans id_parent si possible
271
+        if (isset($contexte['id_rubrique'])) {
272
+            $contexte['id_parent'] = $contexte['id_rubrique'];
273
+            unset($contexte['id_rubrique']);
274
+        } else {
275
+            $contexte['id_parent'] = '';
276
+        }
277
+        if (
278
+            !$contexte['id_parent']
279
+            && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true))
280
+        ) {
281
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
282
+        }
283
+    }
284
+
285
+    $config = [];
286
+    if ($config_fonc) {
287
+        $contexte['config'] = $config = $config_fonc($contexte);
288
+        if (!$lang_default) {
289
+            $lang_default = $config['langue'] ?? session_get('lang') ;
290
+        }
291
+    }
292
+    $config += [
293
+        'lignes' => 0,
294
+        'langue' => '',
295
+    ];
296
+
297
+    $att_text = " class='textarea' "
298
+        . " rows='"
299
+        . ($config['lignes'] + 15)
300
+        . "' cols='40'";
301
+    if (isset($contexte['texte'])) {
302
+        [$contexte['texte'], $contexte['_texte_trop_long']] = editer_texte_recolle($contexte['texte'], $att_text);
303
+    }
304
+
305
+    // on veut conserver la langue de l'interface ;
306
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
307
+    // voudrait l'exploiter
308
+    if (isset($contexte['lang'])) {
309
+        $contexte['langue'] = $contexte['lang'];
310
+        unset($contexte['lang']);
311
+    }
312
+
313
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
314
+        ($lier_trad
315
+             ? "\n<input type='hidden' name='lier_trad' value='" .
316
+                $lier_trad .
317
+                "' />" .
318
+                "\n<input type='hidden' name='changer_lang' value='" .
319
+                $lang_default .
320
+                "' />"
321
+            : '')
322
+        . $hidden
323
+        . ($md5 ?? '');
324
+
325
+    // preciser que le formulaire doit passer dans un pipeline
326
+    $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]];
327
+
328
+    // preciser que le formulaire doit etre securise auteur/action
329
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
330
+    // on le garde pour compat
331
+    $contexte['_action'] = ["editer_$type", $id];
332
+
333
+    // et in fine placer l'autorisation
334
+    include_spip('inc/autoriser');
335
+    if ((int) $id) {
336
+        if (!autoriser('modifier', $type, (int) $id)) {
337
+            $contexte['editable'] = '';
338
+        }
339
+    }
340
+    else {
341
+        if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
342
+            $contexte['editable'] = '';
343
+        }
344
+    }
345
+
346
+    return $contexte;
347 347
 }
348 348
 
349 349
 /**
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
  * @return array
355 355
  */
356 356
 function coupe_trop_long($texte) {
357
-	$aider = charger_fonction('aider', 'inc');
358
-	if (strlen($texte) > 28 * 1024) {
359
-		$texte = str_replace("\r\n", "\n", $texte);
360
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
361
-		if ($pos > 0 && $pos < 32 * 1024) {
362
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
363
-			$suite = substr($texte, $pos + 2);
364
-		} else {
365
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
366
-			if (!($pos > 0 && $pos < 32 * 1024)) {
367
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
368
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
369
-			} else {
370
-				$decalage = 1;
371
-			}
372
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
373
-			$suite = substr($texte, $pos + $decalage);
374
-		}
375
-
376
-		return ([$debut, $suite]);
377
-	} else {
378
-		return ([$texte, '']);
379
-	}
357
+    $aider = charger_fonction('aider', 'inc');
358
+    if (strlen($texte) > 28 * 1024) {
359
+        $texte = str_replace("\r\n", "\n", $texte);
360
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
361
+        if ($pos > 0 && $pos < 32 * 1024) {
362
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
363
+            $suite = substr($texte, $pos + 2);
364
+        } else {
365
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
366
+            if (!($pos > 0 && $pos < 32 * 1024)) {
367
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
368
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
369
+            } else {
370
+                $decalage = 1;
371
+            }
372
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
373
+            $suite = substr($texte, $pos + $decalage);
374
+        }
375
+
376
+        return ([$debut, $suite]);
377
+    } else {
378
+        return ([$texte, '']);
379
+    }
380 380
 }
381 381
 
382 382
 /**
@@ -387,25 +387,25 @@  discard block
 block discarded – undo
387 387
  * @return array
388 388
  */
389 389
 function editer_texte_recolle($texte, $att_text) {
390
-	if (
391
-		strlen($texte) < 29 * 1024
392
-		|| include_spip('inc/layer') && $GLOBALS['browser_name'] != 'MSIE'
393
-	) {
394
-		return [$texte, ''];
395
-	}
396
-
397
-	include_spip('inc/barre');
398
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
399
-	$nombre = 0;
400
-
401
-	while (strlen((string) $texte) > 29 * 1024) {
402
-		$nombre++;
403
-		[$texte1, $texte] = coupe_trop_long($texte);
404
-		$textes_supplement .= '<br />' .
405
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
406
-	}
407
-
408
-	return [$texte, $textes_supplement];
390
+    if (
391
+        strlen($texte) < 29 * 1024
392
+        || include_spip('inc/layer') && $GLOBALS['browser_name'] != 'MSIE'
393
+    ) {
394
+        return [$texte, ''];
395
+    }
396
+
397
+    include_spip('inc/barre');
398
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
399
+    $nombre = 0;
400
+
401
+    while (strlen((string) $texte) > 29 * 1024) {
402
+        $nombre++;
403
+        [$texte1, $texte] = coupe_trop_long($texte);
404
+        $textes_supplement .= '<br />' .
405
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
406
+    }
407
+
408
+    return [$texte, $textes_supplement];
409 409
 }
410 410
 
411 411
 /**
@@ -416,13 +416,13 @@  discard block
 block discarded – undo
416 416
  * @param int $longueur
417 417
  */
418 418
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
419
-	if (!_request($champ_titre)) {
420
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
421
-		$t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur);
422
-		if ($t) {
423
-			set_request($champ_titre, $t);
424
-		}
425
-	}
419
+    if (!_request($champ_titre)) {
420
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
421
+        $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur);
422
+        if ($t) {
423
+            set_request($champ_titre, $t);
424
+        }
425
+    }
426 426
 }
427 427
 
428 428
 /**
@@ -442,20 +442,20 @@  discard block
 block discarded – undo
442 442
  * @return string
443 443
  */
444 444
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
445
-	// trouver un champ texte non vide
446
-	$t = '';
447
-	foreach ($champs_contenu as $champ) {
448
-		if ($t = _request($champ, $c)) {
449
-			break;
450
-		}
451
-	}
452
-
453
-	if ($t) {
454
-		include_spip('inc/texte_mini');
455
-		$t = couper($t, $longueur, '...');
456
-	}
457
-
458
-	return $t;
445
+    // trouver un champ texte non vide
446
+    $t = '';
447
+    foreach ($champs_contenu as $champ) {
448
+        if ($t = _request($champ, $c)) {
449
+            break;
450
+        }
451
+    }
452
+
453
+    if ($t) {
454
+        include_spip('inc/texte_mini');
455
+        $t = couper($t, $longueur, '...');
456
+    }
457
+
458
+    return $t;
459 459
 }
460 460
 
461 461
 /**
@@ -477,22 +477,22 @@  discard block
 block discarded – undo
477 477
  *      - array sinon couples ('$prefixe$colonne => md5)
478 478
  **/
479 479
 function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') {
480
-	$ctr = [];
481
-	foreach ($data as $key => $val) {
482
-		$m = md5($val ?? '');
483
-		$k = $prefixe . $key;
484
-
485
-		$ctr[$k] = match ($format) {
486
-			'html' => "<input type='hidden' value='$m' name='$k' />",
487
-			default => $m,
488
-		};
489
-	}
490
-
491
-	if ($format === 'html') {
492
-		return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n";
493
-	} else {
494
-		return $ctr;
495
-	}
480
+    $ctr = [];
481
+    foreach ($data as $key => $val) {
482
+        $m = md5($val ?? '');
483
+        $k = $prefixe . $key;
484
+
485
+        $ctr[$k] = match ($format) {
486
+            'html' => "<input type='hidden' value='$m' name='$k' />",
487
+            default => $m,
488
+        };
489
+    }
490
+
491
+    if ($format === 'html') {
492
+        return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n";
493
+    } else {
494
+        return $ctr;
495
+    }
496 496
 }
497 497
 
498 498
 /**
@@ -531,80 +531,80 @@  discard block
 block discarded – undo
531 531
  *     - post : le contenu posté
532 532
  **/
533 533
 function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') {
534
-	include_spip('inc/filtres');
535
-
536
-	$table_objet = table_objet($type);
537
-	$spip_table_objet = table_objet_sql($type);
538
-	$trouver_table = charger_fonction('trouver_table', 'base');
539
-	$desc = $trouver_table($table_objet, $serveur);
540
-
541
-	// Appels incomplets (sans $c)
542
-	if (!is_array($c)) {
543
-		$c = [];
544
-		foreach ($desc['field'] as $champ => $ignore) {
545
-			if (_request($champ)) {
546
-				$c[$champ] = _request($champ);
547
-			}
548
-		}
549
-	}
550
-
551
-	// Securite : certaines variables ne sont jamais acceptees ici
552
-	// car elles ne relevent pas de autoriser(article, modifier) ;
553
-	// il faut passer par instituer_XX()
554
-	// TODO: faut-il passer ces variables interdites
555
-	// dans un fichier de description separe ?
556
-	unset($c['statut']);
557
-	unset($c['id_parent']);
558
-	unset($c['id_rubrique']);
559
-	unset($c['id_secteur']);
560
-
561
-	// Gerer les champs non vides
562
-	if (isset($options['nonvide']) && is_array($options['nonvide'])) {
563
-		foreach ($options['nonvide'] as $champ => $sinon) {
564
-			if ($c[$champ] === '') {
565
-				$c[$champ] = $sinon;
566
-			}
567
-		}
568
-	}
569
-
570
-	// N'accepter que les champs qui existent
571
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
572
-	$champs = [];
573
-	foreach ($desc['field'] as $champ => $ignore) {
574
-		if (isset($c[$champ])) {
575
-			$champs[$champ] = $c[$champ];
576
-		}
577
-	}
578
-
579
-	// Nettoyer les valeurs
580
-	$champs = array_map('corriger_caracteres', $champs);
581
-
582
-	// Envoyer aux plugins
583
-	$champs = pipeline(
584
-		'pre_edition',
585
-		[
586
-			'args' => [
587
-				'table' => $spip_table_objet, // compatibilite
588
-				'table_objet' => $table_objet,
589
-				'spip_table_objet' => $spip_table_objet,
590
-				'type' => $type,
591
-				'id_objet' => $id,
592
-				'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
593
-				'action' => 'controler',
594
-				'serveur' => $serveur,
595
-			],
596
-			'data' => $champs
597
-		]
598
-	);
599
-
600
-	if (!$champs) {
601
-		return false;
602
-	}
603
-
604
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
605
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_');
606
-
607
-	return $conflits;
534
+    include_spip('inc/filtres');
535
+
536
+    $table_objet = table_objet($type);
537
+    $spip_table_objet = table_objet_sql($type);
538
+    $trouver_table = charger_fonction('trouver_table', 'base');
539
+    $desc = $trouver_table($table_objet, $serveur);
540
+
541
+    // Appels incomplets (sans $c)
542
+    if (!is_array($c)) {
543
+        $c = [];
544
+        foreach ($desc['field'] as $champ => $ignore) {
545
+            if (_request($champ)) {
546
+                $c[$champ] = _request($champ);
547
+            }
548
+        }
549
+    }
550
+
551
+    // Securite : certaines variables ne sont jamais acceptees ici
552
+    // car elles ne relevent pas de autoriser(article, modifier) ;
553
+    // il faut passer par instituer_XX()
554
+    // TODO: faut-il passer ces variables interdites
555
+    // dans un fichier de description separe ?
556
+    unset($c['statut']);
557
+    unset($c['id_parent']);
558
+    unset($c['id_rubrique']);
559
+    unset($c['id_secteur']);
560
+
561
+    // Gerer les champs non vides
562
+    if (isset($options['nonvide']) && is_array($options['nonvide'])) {
563
+        foreach ($options['nonvide'] as $champ => $sinon) {
564
+            if ($c[$champ] === '') {
565
+                $c[$champ] = $sinon;
566
+            }
567
+        }
568
+    }
569
+
570
+    // N'accepter que les champs qui existent
571
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
572
+    $champs = [];
573
+    foreach ($desc['field'] as $champ => $ignore) {
574
+        if (isset($c[$champ])) {
575
+            $champs[$champ] = $c[$champ];
576
+        }
577
+    }
578
+
579
+    // Nettoyer les valeurs
580
+    $champs = array_map('corriger_caracteres', $champs);
581
+
582
+    // Envoyer aux plugins
583
+    $champs = pipeline(
584
+        'pre_edition',
585
+        [
586
+            'args' => [
587
+                'table' => $spip_table_objet, // compatibilite
588
+                'table_objet' => $table_objet,
589
+                'spip_table_objet' => $spip_table_objet,
590
+                'type' => $type,
591
+                'id_objet' => $id,
592
+                'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
593
+                'action' => 'controler',
594
+                'serveur' => $serveur,
595
+            ],
596
+            'data' => $champs
597
+        ]
598
+    );
599
+
600
+    if (!$champs) {
601
+        return false;
602
+    }
603
+
604
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
605
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_');
606
+
607
+    return $conflits;
608 608
 }
609 609
 
610 610
 
@@ -634,66 +634,66 @@  discard block
 block discarded – undo
634 634
  *     - post : le contenu posté
635 635
  **/
636 636
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
637
-	$spip_table_objet = table_objet_sql($type);
638
-	$id_table_objet = id_table_objet($type);
639
-
640
-	// Controle des MD5 envoyes
641
-	// On elimine les donnees non modifiees par le formulaire (mais
642
-	// potentiellement modifiees entre temps par un autre utilisateur)
643
-	foreach ($champs as $key => $val) {
644
-		if (
645
-			isset($ctr[$prefix . $key])
646
-			&& ($m = $ctr[$prefix . $key])
647
-			&& (is_scalar($val) && $m == md5($val))
648
-		) {
649
-			unset($champs[$key]);
650
-		}
651
-	}
652
-	if (!$champs) {
653
-		return;
654
-	}
655
-
656
-	// On veut savoir si notre modif va avoir un impact
657
-	// par rapport aux donnees contenues dans la base
658
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
659
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
660
-	$intact = true;
661
-	foreach ($champs as $ch => $val) {
662
-		$intact &= ($s[$ch] == $val);
663
-	}
664
-	if ($intact) {
665
-		return;
666
-	}
667
-
668
-	// Detection de conflits :
669
-	// On verifie si notre modif ne provient pas d'un formulaire
670
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
671
-	// on compare a ce qui est dans la base, et on bloque en cas
672
-	// de conflit.
673
-	$ctrh = $ctrq = $conflits = [];
674
-	foreach (array_keys($champs) as $key) {
675
-		if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) {
676
-			$ctrh[$key] = $m;
677
-			$ctrq[] = $key;
678
-		}
679
-	}
680
-	if ($ctrq) {
681
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
682
-		foreach ($ctrh as $key => $m) {
683
-			if (
684
-				$m != md5((string) $ctrq[$key])
685
-				&& $champs[$key] !== $ctrq[$key]
686
-			) {
687
-				$conflits[$key] = [
688
-					'base' => $ctrq[$key],
689
-					'post' => $champs[$key]
690
-				];
691
-				unset($champs[$key]); # stocker quand meme les modifs ?
692
-			}
693
-		}
694
-	}
695
-
696
-	return $conflits;
637
+    $spip_table_objet = table_objet_sql($type);
638
+    $id_table_objet = id_table_objet($type);
639
+
640
+    // Controle des MD5 envoyes
641
+    // On elimine les donnees non modifiees par le formulaire (mais
642
+    // potentiellement modifiees entre temps par un autre utilisateur)
643
+    foreach ($champs as $key => $val) {
644
+        if (
645
+            isset($ctr[$prefix . $key])
646
+            && ($m = $ctr[$prefix . $key])
647
+            && (is_scalar($val) && $m == md5($val))
648
+        ) {
649
+            unset($champs[$key]);
650
+        }
651
+    }
652
+    if (!$champs) {
653
+        return;
654
+    }
655
+
656
+    // On veut savoir si notre modif va avoir un impact
657
+    // par rapport aux donnees contenues dans la base
658
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
659
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
660
+    $intact = true;
661
+    foreach ($champs as $ch => $val) {
662
+        $intact &= ($s[$ch] == $val);
663
+    }
664
+    if ($intact) {
665
+        return;
666
+    }
667
+
668
+    // Detection de conflits :
669
+    // On verifie si notre modif ne provient pas d'un formulaire
670
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
671
+    // on compare a ce qui est dans la base, et on bloque en cas
672
+    // de conflit.
673
+    $ctrh = $ctrq = $conflits = [];
674
+    foreach (array_keys($champs) as $key) {
675
+        if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) {
676
+            $ctrh[$key] = $m;
677
+            $ctrq[] = $key;
678
+        }
679
+    }
680
+    if ($ctrq) {
681
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
682
+        foreach ($ctrh as $key => $m) {
683
+            if (
684
+                $m != md5((string) $ctrq[$key])
685
+                && $champs[$key] !== $ctrq[$key]
686
+            ) {
687
+                $conflits[$key] = [
688
+                    'base' => $ctrq[$key],
689
+                    'post' => $champs[$key]
690
+                ];
691
+                unset($champs[$key]); # stocker quand meme les modifs ?
692
+            }
693
+        }
694
+    }
695
+
696
+    return $conflits;
697 697
 }
698 698
 
699 699
 /**
@@ -705,9 +705,9 @@  discard block
 block discarded – undo
705 705
  * @return string
706 706
  */
707 707
 function display_conflit_champ($x) {
708
-	if (strstr($x, "\n") || strlen($x) > 80) {
709
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
710
-	} else {
711
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
712
-	}
708
+    if (strstr($x, "\n") || strlen($x) > 80) {
709
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
710
+    } else {
711
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
712
+    }
713 713
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		$res['message_ok'] = _T('info_modification_enregistree');
100 100
 		if ($retour) {
101 101
 			if (str_starts_with($retour, 'javascript:')) {
102
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
102
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
103 103
 				$res['editable'] = true;
104 104
 			} else {
105 105
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 				if (!isset($erreurs[$champ])) {
140 140
 					$erreurs[$champ] = '';
141 141
 				}
142
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
142
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>';
143 143
 			}
144 144
 		}
145 145
 	}
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	if (
220 220
 		$config_fonc
221 221
 		&& !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
222
-		&& $config_fonc !== $table_objet . '_edit_config'
222
+		&& $config_fonc !== $table_objet.'_edit_config'
223 223
 		&& ($args = test_formulaire_inclus_par_modele())
224 224
 		&& in_array($config_fonc, $args)
225 225
 	) {
@@ -231,12 +231,12 @@  discard block
 block discarded – undo
231 231
 	// Appel direct dans un squelette
232 232
 	if (!$row) {
233 233
 		if (!$new || $lier_trad) {
234
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
234
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
235 235
 				$row = $select($id, $id_parent, $lier_trad);
236 236
 				// si on a une fonction precharger, elle pu faire un reglage de langue
237 237
 				$lang_default = (empty($row['lang']) ? null : $row['lang']);
238 238
 			} else {
239
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id);
239
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.(int) $id);
240 240
 			}
241 241
 			if (!$new) {
242 242
 				$md5 = controles_md5($row ?: []);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	if ($config_fonc) {
287 287
 		$contexte['config'] = $config = $config_fonc($contexte);
288 288
 		if (!$lang_default) {
289
-			$lang_default = $config['langue'] ?? session_get('lang') ;
289
+			$lang_default = $config['langue'] ?? session_get('lang');
290 290
 		}
291 291
 	}
292 292
 	$config += [
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 		unset($contexte['lang']);
311 311
 	}
312 312
 
313
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
313
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
314 314
 		($lier_trad
315
-			 ? "\n<input type='hidden' name='lier_trad' value='" .
316
-				$lier_trad .
317
-				"' />" .
318
-				"\n<input type='hidden' name='changer_lang' value='" .
319
-				$lang_default .
315
+			 ? "\n<input type='hidden' name='lier_trad' value='".
316
+				$lier_trad.
317
+				"' />".
318
+				"\n<input type='hidden' name='changer_lang' value='".
319
+				$lang_default.
320 320
 				"' />"
321 321
 			: '')
322 322
 		. $hidden
@@ -357,14 +357,14 @@  discard block
 block discarded – undo
357 357
 	$aider = charger_fonction('aider', 'inc');
358 358
 	if (strlen($texte) > 28 * 1024) {
359 359
 		$texte = str_replace("\r\n", "\n", $texte);
360
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
360
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
361 361
 		if ($pos > 0 && $pos < 32 * 1024) {
362
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
362
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
363 363
 			$suite = substr($texte, $pos + 2);
364 364
 		} else {
365
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
365
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
366 366
 			if (!($pos > 0 && $pos < 32 * 1024)) {
367
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
367
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
368 368
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
369 369
 			} else {
370 370
 				$decalage = 1;
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
 	}
396 396
 
397 397
 	include_spip('inc/barre');
398
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
398
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
399 399
 	$nombre = 0;
400 400
 
401 401
 	while (strlen((string) $texte) > 29 * 1024) {
402 402
 		$nombre++;
403 403
 		[$texte1, $texte] = coupe_trop_long($texte);
404
-		$textes_supplement .= '<br />' .
404
+		$textes_supplement .= '<br />'.
405 405
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
406 406
 	}
407 407
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	$ctr = [];
481 481
 	foreach ($data as $key => $val) {
482 482
 		$m = md5($val ?? '');
483
-		$k = $prefixe . $key;
483
+		$k = $prefixe.$key;
484 484
 
485 485
 		$ctr[$k] = match ($format) {
486 486
 			'html' => "<input type='hidden' value='$m' name='$k' />",
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 	}
490 490
 
491 491
 	if ($format === 'html') {
492
-		return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n";
492
+		return "\n\n<!-- controles md5 -->\n".implode("\n", $ctr)."\n\n";
493 493
 	} else {
494 494
 		return $ctr;
495 495
 	}
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
 	// potentiellement modifiees entre temps par un autre utilisateur)
643 643
 	foreach ($champs as $key => $val) {
644 644
 		if (
645
-			isset($ctr[$prefix . $key])
646
-			&& ($m = $ctr[$prefix . $key])
645
+			isset($ctr[$prefix.$key])
646
+			&& ($m = $ctr[$prefix.$key])
647 647
 			&& (is_scalar($val) && $m == md5($val))
648 648
 		) {
649 649
 			unset($champs[$key]);
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 	// de conflit.
673 673
 	$ctrh = $ctrq = $conflits = [];
674 674
 	foreach (array_keys($champs) as $key) {
675
-		if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) {
675
+		if (isset($ctr[$prefix.$key]) && ($m = $ctr[$prefix.$key])) {
676 676
 			$ctrh[$key] = $m;
677 677
 			$ctrq[] = $key;
678 678
 		}
@@ -706,8 +706,8 @@  discard block
 block discarded – undo
706 706
  */
707 707
 function display_conflit_champ($x) {
708 708
 	if (strstr($x, "\n") || strlen($x) > 80) {
709
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
709
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
710 710
 	} else {
711
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
711
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
712 712
 	}
713 713
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -336,8 +336,7 @@
 block discarded – undo
336 336
 		if (!autoriser('modifier', $type, (int) $id)) {
337 337
 			$contexte['editable'] = '';
338 338
 		}
339
-	}
340
-	else {
339
+	} else {
341 340
 		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
342 341
 			$contexte['editable'] = '';
343 342
 		}
Please login to merge, or discard this patch.
ecrire/inc/filtres_mini.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -34,20 +34,20 @@  discard block
 block discarded – undo
34 34
  * @return string URL nettoyée
35 35
  **/
36 36
 function resolve_path($url) {
37
-	[$url, $query] = array_pad(explode('?', $url, 2), 2, null);
38
-	while (
39
-		preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./
40
-		|| preg_match(',/[^/]*/\.\./,S', (string) $url, $regs)  # supprime /toto/../
41
-		|| preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut
42
-	) {
43
-		$url = str_replace($regs[0], '/', (string) $url);
44
-	}
37
+    [$url, $query] = array_pad(explode('?', $url, 2), 2, null);
38
+    while (
39
+        preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./
40
+        || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs)  # supprime /toto/../
41
+        || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut
42
+    ) {
43
+        $url = str_replace($regs[0], '/', (string) $url);
44
+    }
45 45
 
46
-	if ($query) {
47
-		$url .= '?' . $query;
48
-	}
46
+    if ($query) {
47
+        $url .= '?' . $query;
48
+    }
49 49
 
50
-	return '/' . preg_replace(',^/,S', '', (string) $url);
50
+    return '/' . preg_replace(',^/,S', '', (string) $url);
51 51
 }
52 52
 
53 53
 
@@ -68,40 +68,40 @@  discard block
 block discarded – undo
68 68
  **/
69 69
 function suivre_lien($url, $lien) {
70 70
 
71
-	$mot = null;
72
-	$get = null;
73
-	$hash = null;
74
-	if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
75
-		return $lien;
76
-	}
77
-	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
78
-		$r = array_pad($r, 3, '');
71
+    $mot = null;
72
+    $get = null;
73
+    $hash = null;
74
+    if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
75
+        return $lien;
76
+    }
77
+    if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
78
+        $r = array_pad($r, 3, '');
79 79
 
80
-		return $r[1] . resolve_path($r[2]);
81
-	}
80
+        return $r[1] . resolve_path($r[2]);
81
+    }
82 82
 
83
-	# L'url site spip est un lien absolu aussi
84
-	if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) {
85
-		return $lien;
86
-	}
83
+    # L'url site spip est un lien absolu aussi
84
+    if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) {
85
+        return $lien;
86
+    }
87 87
 
88
-	# lien relatif, il faut verifier l'url de base
89
-	# commencer par virer la chaine de get de l'url de base
90
-	$dir = '/';
91
-	$debut = '';
92
-	if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
93
-		$debut = $regs[1];
94
-		$dir = strlen($regs[2]) ? $regs[2] : '/';
95
-		$mot = $regs[3];
96
-		$get = $regs[4] ?? '';
97
-		$hash = $regs[5] ?? '';
98
-	}
99
-	return match (substr($lien, 0, 1)) {
100
-		'/' => $debut . resolve_path($lien),
101
-		'#' => $debut . resolve_path($dir . $mot . $get . $lien),
102
-		'' => $debut . resolve_path($dir . $mot . $get . $hash),
103
-		default => $debut . resolve_path($dir . $lien),
104
-	};
88
+    # lien relatif, il faut verifier l'url de base
89
+    # commencer par virer la chaine de get de l'url de base
90
+    $dir = '/';
91
+    $debut = '';
92
+    if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
93
+        $debut = $regs[1];
94
+        $dir = strlen($regs[2]) ? $regs[2] : '/';
95
+        $mot = $regs[3];
96
+        $get = $regs[4] ?? '';
97
+        $hash = $regs[5] ?? '';
98
+    }
99
+    return match (substr($lien, 0, 1)) {
100
+        '/' => $debut . resolve_path($lien),
101
+        '#' => $debut . resolve_path($dir . $mot . $get . $lien),
102
+        '' => $debut . resolve_path($dir . $mot . $get . $hash),
103
+        default => $debut . resolve_path($dir . $lien),
104
+    };
105 105
 }
106 106
 
107 107
 
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
  * @return string texte ou URL (en absolus)
125 125
  **/
126 126
 function url_absolue($url, $base = '') {
127
-	$url = trim((string) $url);
128
-	if (strlen($url = trim($url)) == 0) {
129
-		return '';
130
-	}
131
-	if (!$base) {
132
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
133
-	}
127
+    $url = trim((string) $url);
128
+    if (strlen($url = trim($url)) == 0) {
129
+        return '';
130
+    }
131
+    if (!$base) {
132
+        $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
133
+    }
134 134
 
135
-	return suivre_lien($base, $url);
135
+    return suivre_lien($base, $url);
136 136
 }
137 137
 
138 138
 /**
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
  * @return string
144 144
  */
145 145
 function protocole_implicite($url_absolue) {
146
-	return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
146
+    return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
147 147
 }
148 148
 
149 149
 /**
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
  */
155 155
 function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
156 156
 
157
-	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
158
-		$protocole = $m[1];
159
-		if (
160
-			in_array($protocole, $protocoles_autorises)
161
-			|| in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
162
-		) {
163
-			return true;
164
-		}
165
-	}
166
-	return false;
157
+    if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
158
+        $protocole = $m[1];
159
+        if (
160
+            in_array($protocole, $protocoles_autorises)
161
+            || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
162
+        ) {
163
+            return true;
164
+        }
165
+    }
166
+    return false;
167 167
 }
168 168
 
169 169
 /**
@@ -180,28 +180,28 @@  discard block
 block discarded – undo
180 180
  * @return string texte avec des URLs absolues
181 181
  **/
182 182
 function liens_absolus($texte, $base = '') {
183
-	if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
184
-		if (!function_exists('extraire_attribut')) {
185
-			include_spip('inc/filtres');
186
-		}
187
-		foreach ($liens as $lien) {
188
-			foreach (['href', 'src'] as $attr) {
189
-				$href = extraire_attribut($lien[0], $attr) ?? '';
190
-				if (
191
-					strlen((string) $href) > 0
192
-					&& !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href)
193
-				) {
194
-					$abs = url_absolue($href, $base);
195
-					if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) {
196
-						$texte_lien = inserer_attribut($lien[0], $attr, $abs);
197
-						$texte = str_replace($lien[0], $texte_lien, $texte);
198
-					}
199
-				}
200
-			}
201
-		}
202
-	}
183
+    if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
184
+        if (!function_exists('extraire_attribut')) {
185
+            include_spip('inc/filtres');
186
+        }
187
+        foreach ($liens as $lien) {
188
+            foreach (['href', 'src'] as $attr) {
189
+                $href = extraire_attribut($lien[0], $attr) ?? '';
190
+                if (
191
+                    strlen((string) $href) > 0
192
+                    && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href)
193
+                ) {
194
+                    $abs = url_absolue($href, $base);
195
+                    if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) {
196
+                        $texte_lien = inserer_attribut($lien[0], $attr, $abs);
197
+                        $texte = str_replace($lien[0], $texte_lien, $texte);
198
+                    }
199
+                }
200
+            }
201
+        }
202
+    }
203 203
 
204
-	return $texte;
204
+    return $texte;
205 205
 }
206 206
 
207 207
 
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
  * @return string texte ou URL (en absolus)
218 218
  **/
219 219
 function abs_url($texte, $base = '') {
220
-	if ($GLOBALS['mode_abs_url'] == 'url') {
221
-		return url_absolue($texte, $base);
222
-	} else {
223
-		return liens_absolus($texte, $base);
224
-	}
220
+    if ($GLOBALS['mode_abs_url'] == 'url') {
221
+        return url_absolue($texte, $base);
222
+    } else {
223
+        return liens_absolus($texte, $base);
224
+    }
225 225
 }
226 226
 
227 227
 /**
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
  * @return string
235 235
  */
236 236
 function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
237
-	if (is_null($flags)) {
238
-		$flags = ENT_COMPAT | ENT_HTML401;
239
-	}
237
+    if (is_null($flags)) {
238
+        $flags = ENT_COMPAT | ENT_HTML401;
239
+    }
240 240
 
241
-	return htmlspecialchars($string, $flags, $encoding, $double_encode);
241
+    return htmlspecialchars($string, $flags, $encoding, $double_encode);
242 242
 }
243 243
 
244 244
 /**
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
  * @return string
252 252
  */
253 253
 function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
254
-	if (is_null($flags)) {
255
-		$flags = ENT_COMPAT | ENT_HTML401;
256
-	}
254
+    if (is_null($flags)) {
255
+        $flags = ENT_COMPAT | ENT_HTML401;
256
+    }
257 257
 
258
-	return htmlentities($string, $flags, $encoding, $double_encode);
258
+    return htmlentities($string, $flags, $encoding, $double_encode);
259 259
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	}
45 45
 
46 46
 	if ($query) {
47
-		$url .= '?' . $query;
47
+		$url .= '?'.$query;
48 48
 	}
49 49
 
50
-	return '/' . preg_replace(',^/,S', '', (string) $url);
50
+	return '/'.preg_replace(',^/,S', '', (string) $url);
51 51
 }
52 52
 
53 53
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
78 78
 		$r = array_pad($r, 3, '');
79 79
 
80
-		return $r[1] . resolve_path($r[2]);
80
+		return $r[1].resolve_path($r[2]);
81 81
 	}
82 82
 
83 83
 	# L'url site spip est un lien absolu aussi
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 		$hash = $regs[5] ?? '';
98 98
 	}
99 99
 	return match (substr($lien, 0, 1)) {
100
-		'/' => $debut . resolve_path($lien),
101
-		'#' => $debut . resolve_path($dir . $mot . $get . $lien),
102
-		'' => $debut . resolve_path($dir . $mot . $get . $hash),
103
-		default => $debut . resolve_path($dir . $lien),
100
+		'/' => $debut.resolve_path($lien),
101
+		'#' => $debut.resolve_path($dir.$mot.$get.$lien),
102
+		'' => $debut.resolve_path($dir.$mot.$get.$hash),
103
+		default => $debut.resolve_path($dir.$lien),
104 104
 	};
105 105
 }
106 106
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		return '';
130 130
 	}
131 131
 	if (!$base) {
132
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
132
+		$base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
133 133
 	}
134 134
 
135 135
 	return suivre_lien($base, $url);
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
  * @param array $protocoles_autorises
153 153
  * @return bool
154 154
  */
155
-function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
155
+function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) {
156 156
 
157 157
 	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
158 158
 		$protocole = $m[1];
Please login to merge, or discard this patch.
ecrire/inc/surligne.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Surligne
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -34,43 +34,43 @@  discard block
 block discarded – undo
34 34
  *     Page HTML
35 35
  **/
36 36
 function surligner_mots($page, $surcharge_surligne = '') {
37
-	$surlignejs_engines = [
38
-		[
39
-			',' . str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site']) . ',i',
40
-			',recherche=([^&]+),i'
41
-		], //SPIP
42
-		[',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google
43
-		[',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo
44
-		[',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN
45
-		[',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live
46
-		[',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL
47
-		[',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com
48
-		[',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista
49
-		[',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster
50
-		[',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos
51
-		[',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb
52
-		[',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati
53
-	];
37
+    $surlignejs_engines = [
38
+        [
39
+            ',' . str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site']) . ',i',
40
+            ',recherche=([^&]+),i'
41
+        ], //SPIP
42
+        [',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google
43
+        [',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo
44
+        [',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN
45
+        [',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live
46
+        [',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL
47
+        [',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com
48
+        [',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista
49
+        [',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster
50
+        [',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos
51
+        [',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb
52
+        [',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati
53
+    ];
54 54
 
55 55
 
56
-	$ref = $_SERVER['HTTP_REFERER'] ?? null;
57
-	//avoid a js injection
58
-	if ($surcharge_surligne) {
59
-		$surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne);
60
-		$surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne);
61
-		if ($GLOBALS['meta']['charset'] == 'utf-8') {
62
-			include_spip('inc/charsets');
63
-			if (!is_utf8($surcharge_surligne)) {
64
-				$surcharge_surligne = mb_convert_encoding($surcharge_surligne, 'UTF-8', 'ISO-8859-1');
65
-			}
66
-		}
67
-		$surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
68
-	}
69
-	foreach ($surlignejs_engines as $engine) {
70
-		if ($surcharge_surligne || (preg_match($engine[0], (string) $ref) && preg_match($engine[1], (string) $ref))) {
71
-			//good referrer found or var_recherche is not null
72
-			include_spip('inc/filtres');
73
-			$script = "
56
+    $ref = $_SERVER['HTTP_REFERER'] ?? null;
57
+    //avoid a js injection
58
+    if ($surcharge_surligne) {
59
+        $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne);
60
+        $surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne);
61
+        if ($GLOBALS['meta']['charset'] == 'utf-8') {
62
+            include_spip('inc/charsets');
63
+            if (!is_utf8($surcharge_surligne)) {
64
+                $surcharge_surligne = mb_convert_encoding($surcharge_surligne, 'UTF-8', 'ISO-8859-1');
65
+            }
66
+        }
67
+        $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
68
+    }
69
+    foreach ($surlignejs_engines as $engine) {
70
+        if ($surcharge_surligne || (preg_match($engine[0], (string) $ref) && preg_match($engine[1], (string) $ref))) {
71
+            //good referrer found or var_recherche is not null
72
+            include_spip('inc/filtres');
73
+            $script = "
74 74
       <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script>
75 75
       <script type='text/javascript'>
76 76
        var highlighter = function() {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i],
83 83
             highlight:'.surlignable',
84 84
             nohighlight:'.pas_surlignable'" .
85
-				($surcharge_surligne ? ",
85
+                ($surcharge_surligne ? ",
86 86
             keys:'$surcharge_surligne'" : '') . ',
87 87
             min_length: 3
88 88
           });
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
       };
94 94
       </script>
95 95
       ';
96
-			// on l'insere juste avant </head>, sinon tout en bas
97
-			if (is_null($l = strpos($page, '</head>'))) {
98
-				$l = strlen($page);
99
-			}
100
-			$page = substr_replace($page, $script, $l, 0);
101
-			break;
102
-		}
103
-	}
96
+            // on l'insere juste avant </head>, sinon tout en bas
97
+            if (is_null($l = strpos($page, '</head>'))) {
98
+                $l = strlen($page);
99
+            }
100
+            $page = substr_replace($page, $script, $l, 0);
101
+            break;
102
+        }
103
+    }
104 104
 
105
-	return $page;
105
+    return $page;
106 106
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 function surligner_mots($page, $surcharge_surligne = '') {
37 37
 	$surlignejs_engines = [
38 38
 		[
39
-			',' . str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site']) . ',i',
39
+			','.str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site']).',i',
40 40
 			',recherche=([^&]+),i'
41 41
 		], //SPIP
42 42
 		[',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
 			//good referrer found or var_recherche is not null
72 72
 			include_spip('inc/filtres');
73 73
 			$script = "
74
-      <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script>
74
+      <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js'))."'></script>
75 75
       <script type='text/javascript'>
76 76
        var highlighter = function() {
77 77
 		  jQuery(this).SearchHighlight({
78
-            tag_name:'" . (html5_permis() ? 'mark' : 'span') . "',
78
+            tag_name:'" . (html5_permis() ? 'mark' : 'span')."',
79 79
             style_name:'spip_surligne',
80 80
             exact:'whole',
81 81
             style_name_suffix:false,
82
-            engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i],
82
+            engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], (string) $GLOBALS['meta']['adresse_site'])."/i,/recherche=([^&]+)/i],
83 83
             highlight:'.surlignable',
84 84
             nohighlight:'.pas_surlignable'" .
85 85
 				($surcharge_surligne ? ",
86
-            keys:'$surcharge_surligne'" : '') . ',
86
+            keys:'$surcharge_surligne'" : '').',
87 87
             min_length: 3
88 88
           });
89 89
 	  }
Please login to merge, or discard this patch.