Completed
Push — master ( 25861b...65c7d7 )
by cam
01:16
created
ecrire/inc/definir_menus_favoris.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,21 +20,21 @@
 block discarded – undo
20 20
  * Retourne la liste des menus favoris par défaut ainsi que leur rang
21 21
  */
22 22
 function inc_definir_menus_favoris_dist() {
23
-	$liste = [
23
+    $liste = [
24 24
 
25
-		// Menu Édition,
26
-		'auteurs' => 1,
27
-		'rubriques' => 2,
28
-		'articles' => 3,
25
+        // Menu Édition,
26
+        'auteurs' => 1,
27
+        'rubriques' => 2,
28
+        'articles' => 3,
29 29
 
30
-		// Menu Maintenance
31
-		'admin_vider' => 1,
30
+        // Menu Maintenance
31
+        'admin_vider' => 1,
32 32
 
33
-		// Menu Configurations
34
-		'configurer_identite' => 1,
35
-		'admin_plugin' => 2,
33
+        // Menu Configurations
34
+        'configurer_identite' => 1,
35
+        'admin_plugin' => 2,
36 36
 
37
-	];
37
+    ];
38 38
 
39
-	return $liste;
39
+    return $liste;
40 40
 }
Please login to merge, or discard this patch.
ecrire/inc/urls.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
  */
212 212
 function nettoyer_url_page($url, $contexte = []) {
213 213
 	$url_objets = urls_liste_objets();
214
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
215
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
216
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
214
+	$raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,';
215
+	$raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
216
+	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,';
217 217
 
218 218
 	if (
219 219
 		preg_match($raccourci_url_page_html, $url, $regs)
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	static $furls = [];
252 252
 	if (!isset($furls[$objet])) {
253 253
 		if (
254
-			function_exists($f = 'generer_url_ecrire_' . $objet)
254
+			function_exists($f = 'generer_url_ecrire_'.$objet)
255 255
 			// ou definie par un plugin
256 256
 			or $f = charger_fonction($f, 'urls', true)
257 257
 		) {
@@ -271,10 +271,10 @@  discard block
 block discarded – undo
271 271
 	if ($public or $connect) {
272 272
 		return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
273 273
 	}
274
-	$a = id_table_objet($objet) . '=' . intval($id);
274
+	$a = id_table_objet($objet).'='.intval($id);
275 275
 	if (!function_exists('objet_info')) {
276 276
 		include_spip('inc/filtres');
277 277
 	}
278 278
 
279
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
279
+	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : '');
280 280
 }
Please login to merge, or discard this patch.
Indentation   +165 added lines, -165 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('base/objets');
23 23
 
@@ -57,116 +57,116 @@  discard block
 block discarded – undo
57 57
  *
58 58
  */
59 59
 function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) {
60
-	static $current_base = null;
60
+    static $current_base = null;
61 61
 
62
-	// les anciennes fonctions modifient directement les globales
63
-	// on les sauve avant l'appel, et on les retablit apres !
64
-	$save = [
65
-		$GLOBALS['fond'] ?? null,
66
-		$GLOBALS['contexte'] ?? null,
67
-		$_SERVER['REDIRECT_url_propre'] ?? null,
68
-		$_ENV['url_propre'] ?? null,
69
-		$GLOBALS['profondeur_url']
70
-	];
62
+    // les anciennes fonctions modifient directement les globales
63
+    // on les sauve avant l'appel, et on les retablit apres !
64
+    $save = [
65
+        $GLOBALS['fond'] ?? null,
66
+        $GLOBALS['contexte'] ?? null,
67
+        $_SERVER['REDIRECT_url_propre'] ?? null,
68
+        $_ENV['url_propre'] ?? null,
69
+        $GLOBALS['profondeur_url']
70
+    ];
71 71
 
72
-	if (is_null($current_base)) {
73
-		include_spip('inc/filtres_mini');
74
-		// le decodage des urls se fait toujours par rapport au site public
75
-		$current_base = url_absolue(_DIR_RACINE ?: './');
76
-	}
77
-	if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
-		$url = substr($url, strlen($current_base));
79
-	}
72
+    if (is_null($current_base)) {
73
+        include_spip('inc/filtres_mini');
74
+        // le decodage des urls se fait toujours par rapport au site public
75
+        $current_base = url_absolue(_DIR_RACINE ?: './');
76
+    }
77
+    if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
+        $url = substr($url, strlen($current_base));
79
+    }
80 80
 
81
-	// si on est en train d'assembler la page principale,
82
-	// recuperer l'url depuis les globales url propres si fournies
83
-	// sinon extraire la bonne portion d'url
84
-	if ($assembler) {
85
-		if (isset($_SERVER['REDIRECT_url_propre'])) {
86
-			$url = $_SERVER['REDIRECT_url_propre'];
87
-		} elseif (isset($_ENV['url_propre'])) {
88
-			$url = $_ENV['url_propre'];
89
-		} else {
90
-			$qs = explode('?', $url);
91
-			// ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
-			$url = ltrim($qs[0], '/');
93
-			$url = explode('/', $url);
94
-			while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
-				array_shift($url);
96
-			}
97
-			$qs[0] = implode('/', $url);
98
-			$url = implode('?', $qs);
99
-		}
100
-	}
81
+    // si on est en train d'assembler la page principale,
82
+    // recuperer l'url depuis les globales url propres si fournies
83
+    // sinon extraire la bonne portion d'url
84
+    if ($assembler) {
85
+        if (isset($_SERVER['REDIRECT_url_propre'])) {
86
+            $url = $_SERVER['REDIRECT_url_propre'];
87
+        } elseif (isset($_ENV['url_propre'])) {
88
+            $url = $_ENV['url_propre'];
89
+        } else {
90
+            $qs = explode('?', $url);
91
+            // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
+            $url = ltrim($qs[0], '/');
93
+            $url = explode('/', $url);
94
+            while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
+                array_shift($url);
96
+            }
97
+            $qs[0] = implode('/', $url);
98
+            $url = implode('?', $qs);
99
+        }
100
+    }
101 101
 
102
-	unset($_SERVER['REDIRECT_url_propre']);
103
-	unset($_ENV['url_propre']);
104
-	include_spip('inc/filtres_mini');
105
-	if (strpos($url, '://') === false) {
106
-		$GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
-	} else {
108
-		$GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
-	}
102
+    unset($_SERVER['REDIRECT_url_propre']);
103
+    unset($_ENV['url_propre']);
104
+    include_spip('inc/filtres_mini');
105
+    if (strpos($url, '://') === false) {
106
+        $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
+    } else {
108
+        $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
+    }
110 110
 
111
-	$url_redirect = '';
112
-	$renommer = generer_url_entite('', '', '', '', true);
113
-	if (!$renommer and !function_exists('recuperer_parametres_url')) {
114
-		$renommer = charger_fonction('page', 'urls');
115
-	} // fallback pour decoder l'url
116
-	if ($renommer) {
117
-		$a = $renommer($url, $fond, $contexte);
118
-		if (is_array($a)) {
119
-			[$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
120
-			$url_redirect ??= '';
121
-			if ($url_redirect === $url) {
122
-				$url_redirect = '';
123
-			} // securite pour eviter une redirection infinie
124
-			if ($assembler and strlen($url_redirect)) {
125
-				spip_log("Redirige $url vers $url_redirect");
126
-				include_spip('inc/headers');
127
-				redirige_par_entete($url_redirect, '', 301);
128
-			}
129
-			if (isset($nfond)) {
130
-				$fond = $nfond;
131
-			} else {
132
-				if (
133
-					$fond == ''
134
-					or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
135
-				) {
136
-					$fond = $type;
137
-				}
138
-			}
139
-			if (isset($ncontexte)) {
140
-				$contexte = $ncontexte;
141
-			}
142
-			if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
143
-				$contexte['type'] = $type;
144
-			}
145
-			if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
146
-				$contexte['type-page'] = $type;
147
-			}
148
-		}
149
-	} // compatibilite <= 1.9.2
150
-	elseif (function_exists('recuperer_parametres_url')) {
151
-		$GLOBALS['fond'] = $fond;
152
-		$GLOBALS['contexte'] = $contexte;
153
-		recuperer_parametres_url($fond, nettoyer_uri());
154
-		// fond est en principe modifiee directement
155
-		$contexte = $GLOBALS['contexte'];
156
-	}
111
+    $url_redirect = '';
112
+    $renommer = generer_url_entite('', '', '', '', true);
113
+    if (!$renommer and !function_exists('recuperer_parametres_url')) {
114
+        $renommer = charger_fonction('page', 'urls');
115
+    } // fallback pour decoder l'url
116
+    if ($renommer) {
117
+        $a = $renommer($url, $fond, $contexte);
118
+        if (is_array($a)) {
119
+            [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
120
+            $url_redirect ??= '';
121
+            if ($url_redirect === $url) {
122
+                $url_redirect = '';
123
+            } // securite pour eviter une redirection infinie
124
+            if ($assembler and strlen($url_redirect)) {
125
+                spip_log("Redirige $url vers $url_redirect");
126
+                include_spip('inc/headers');
127
+                redirige_par_entete($url_redirect, '', 301);
128
+            }
129
+            if (isset($nfond)) {
130
+                $fond = $nfond;
131
+            } else {
132
+                if (
133
+                    $fond == ''
134
+                    or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
135
+                ) {
136
+                    $fond = $type;
137
+                }
138
+            }
139
+            if (isset($ncontexte)) {
140
+                $contexte = $ncontexte;
141
+            }
142
+            if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
143
+                $contexte['type'] = $type;
144
+            }
145
+            if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
146
+                $contexte['type-page'] = $type;
147
+            }
148
+        }
149
+    } // compatibilite <= 1.9.2
150
+    elseif (function_exists('recuperer_parametres_url')) {
151
+        $GLOBALS['fond'] = $fond;
152
+        $GLOBALS['contexte'] = $contexte;
153
+        recuperer_parametres_url($fond, nettoyer_uri());
154
+        // fond est en principe modifiee directement
155
+        $contexte = $GLOBALS['contexte'];
156
+    }
157 157
 
158
-	// retablir les globales
159
-	[$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
158
+    // retablir les globales
159
+    [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
160 160
 
161
-	// vider les globales url propres qui ne doivent plus etre utilisees en cas
162
-	// d'inversion url => objet
163
-	// maintenir pour compat ?
164
-	#if ($assembler) {
165
-	#	unset($_SERVER['REDIRECT_url_propre']);
166
-	#	unset($_ENV['url_propre']);
167
-	#}
161
+    // vider les globales url propres qui ne doivent plus etre utilisees en cas
162
+    // d'inversion url => objet
163
+    // maintenir pour compat ?
164
+    #if ($assembler) {
165
+    #	unset($_SERVER['REDIRECT_url_propre']);
166
+    #	unset($_ENV['url_propre']);
167
+    #}
168 168
 
169
-	return [$fond, $contexte, $url_redirect];
169
+    return [$fond, $contexte, $url_redirect];
170 170
 }
171 171
 
172 172
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
  * @return string|array
181 181
  */
182 182
 function urls_liste_objets($preg = true) {
183
-	static $url_objets = null;
184
-	if (is_null($url_objets)) {
185
-		$url_objets = [];
186
-		// recuperer les tables_objets_sql declarees
187
-		$tables_objets = lister_tables_objets_sql();
188
-		foreach ($tables_objets as $t => $infos) {
189
-			if ($infos['page']) {
190
-				$url_objets[] = $infos['type'];
191
-				$url_objets = array_merge($url_objets, $infos['type_surnoms']);
192
-			}
193
-		}
194
-		$url_objets = pipeline('declarer_url_objets', $url_objets);
195
-	}
196
-	if (!$preg) {
197
-		return $url_objets;
198
-	}
183
+    static $url_objets = null;
184
+    if (is_null($url_objets)) {
185
+        $url_objets = [];
186
+        // recuperer les tables_objets_sql declarees
187
+        $tables_objets = lister_tables_objets_sql();
188
+        foreach ($tables_objets as $t => $infos) {
189
+            if ($infos['page']) {
190
+                $url_objets[] = $infos['type'];
191
+                $url_objets = array_merge($url_objets, $infos['type_surnoms']);
192
+            }
193
+        }
194
+        $url_objets = pipeline('declarer_url_objets', $url_objets);
195
+    }
196
+    if (!$preg) {
197
+        return $url_objets;
198
+    }
199 199
 
200
-	return implode('|', array_map('preg_quote', $url_objets));
200
+    return implode('|', array_map('preg_quote', $url_objets));
201 201
 }
202 202
 
203 203
 /**
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
  * @return array
212 212
  */
213 213
 function nettoyer_url_page($url, $contexte = []) {
214
-	$url_objets = urls_liste_objets();
215
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
216
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
217
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
214
+    $url_objets = urls_liste_objets();
215
+    $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
216
+    $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
217
+    $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
218 218
 
219
-	if (
220
-		preg_match($raccourci_url_page_html, $url, $regs)
221
-		or preg_match($raccourci_url_page_id, $url, $regs)
222
-		or preg_match($raccourci_url_page_spip, $url, $regs)
223
-	) {
224
-		$regs = array_pad($regs, 4, null);
225
-		$type = objet_type($regs[1]);
226
-		$_id = id_table_objet($type);
227
-		$contexte[$_id] = $regs[2];
228
-		$suite = $regs[3];
219
+    if (
220
+        preg_match($raccourci_url_page_html, $url, $regs)
221
+        or preg_match($raccourci_url_page_id, $url, $regs)
222
+        or preg_match($raccourci_url_page_spip, $url, $regs)
223
+    ) {
224
+        $regs = array_pad($regs, 4, null);
225
+        $type = objet_type($regs[1]);
226
+        $_id = id_table_objet($type);
227
+        $contexte[$_id] = $regs[2];
228
+        $suite = $regs[3];
229 229
 
230
-		return [$contexte, $type, null, $type, $suite];
231
-	}
230
+        return [$contexte, $type, null, $type, $suite];
231
+    }
232 232
 
233
-	return [];
233
+    return [];
234 234
 }
235 235
 
236 236
 /**
@@ -249,33 +249,33 @@  discard block
 block discarded – undo
249 249
  *
250 250
  */
251 251
 function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, string $connect = '') {
252
-	static $furls = [];
253
-	if (!isset($furls[$objet])) {
254
-		if (
255
-			function_exists($f = 'generer_url_ecrire_' . $objet)
256
-			// ou definie par un plugin
257
-			or $f = charger_fonction($f, 'urls', true)
258
-		) {
259
-			$furls[$objet] = $f;
260
-		} else {
261
-			$furls[$objet] = '';
262
-		}
263
-	}
264
-	if ($furls[$objet]) {
265
-		return $furls[$objet]($id, $args, $ancre, $public, $connect);
266
-	}
267
-	// si pas de flag public fourni
268
-	// le calculer en fonction de la declaration de statut
269
-	if (is_null($public) and !$connect) {
270
-		$public = objet_test_si_publie($objet, $id, $connect);
271
-	}
272
-	if ($public or $connect) {
273
-		return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
274
-	}
275
-	$a = id_table_objet($objet) . '=' . intval($id);
276
-	if (!function_exists('objet_info')) {
277
-		include_spip('inc/filtres');
278
-	}
252
+    static $furls = [];
253
+    if (!isset($furls[$objet])) {
254
+        if (
255
+            function_exists($f = 'generer_url_ecrire_' . $objet)
256
+            // ou definie par un plugin
257
+            or $f = charger_fonction($f, 'urls', true)
258
+        ) {
259
+            $furls[$objet] = $f;
260
+        } else {
261
+            $furls[$objet] = '';
262
+        }
263
+    }
264
+    if ($furls[$objet]) {
265
+        return $furls[$objet]($id, $args, $ancre, $public, $connect);
266
+    }
267
+    // si pas de flag public fourni
268
+    // le calculer en fonction de la declaration de statut
269
+    if (is_null($public) and !$connect) {
270
+        $public = objet_test_si_publie($objet, $id, $connect);
271
+    }
272
+    if ($public or $connect) {
273
+        return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
274
+    }
275
+    $a = id_table_objet($objet) . '=' . intval($id);
276
+    if (!function_exists('objet_info')) {
277
+        include_spip('inc/filtres');
278
+    }
279 279
 
280
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
280
+    return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
281 281
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_dates.php 3 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 function extraire_date($texte) {
39 39
 	// format = 2001-08
40 40
 	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
41
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
41
+		return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01';
42 42
 	}
43 43
 }
44 44
 
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
70 70
 			$regs = array_pad($regs, 4, null); // eviter notice php
71
-			$date = $regs[1] . '-00-00' . $regs[3];
71
+			$date = $regs[1].'-00-00'.$regs[3];
72 72
 		} else {
73 73
 			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
74 74
 				$regs = array_pad($regs, 4, null); // eviter notice php
75
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
75
+				$date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3];
76 76
 			} else {
77 77
 				$date = date('Y-m-d H:i:s', strtotime($date));
78 78
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 function vider_date($letexte, $verif_format_date = false) {
99 99
 	if (
100 100
 		!$verif_format_date
101
-		or (in_array(strlen($letexte), [10,19]) and
101
+		or (in_array(strlen($letexte), [10, 19]) and
102 102
 			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
103 103
 	) {
104 104
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
@@ -381,17 +381,17 @@  discard block
 block discarded – undo
381 381
 	if ($decal > 3600 * 24 * 30) {
382 382
 		$mois = floor($decal / (3600 * 24 * 30));
383 383
 		if ($mois < 2) {
384
-			$delai = "$mois " . _T('date_un_mois');
384
+			$delai = "$mois "._T('date_un_mois');
385 385
 		} else {
386
-			$delai = "$mois " . _T('date_mois');
386
+			$delai = "$mois "._T('date_mois');
387 387
 		}
388 388
 	} else {
389 389
 		if ($decal > 3600 * 24 * 7) {
390 390
 			$semaines = floor($decal / (3600 * 24 * 7));
391 391
 			if ($semaines < 2) {
392
-				$delai = "$semaines " . _T('date_une_semaine');
392
+				$delai = "$semaines "._T('date_une_semaine');
393 393
 			} else {
394
-				$delai = "$semaines " . _T('date_semaines');
394
+				$delai = "$semaines "._T('date_semaines');
395 395
 			}
396 396
 		} else {
397 397
 			if ($decal > 3600 * 24) {
@@ -399,30 +399,30 @@  discard block
 block discarded – undo
399 399
 				if ($jours < 2) {
400 400
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
401 401
 				} else {
402
-					$delai = "$jours " . _T('date_jours');
402
+					$delai = "$jours "._T('date_jours');
403 403
 				}
404 404
 			} else {
405 405
 				if ($decal >= 3600) {
406 406
 					$heures = floor($decal / 3600);
407 407
 					if ($heures < 2) {
408
-						$delai = "$heures " . _T('date_une_heure');
408
+						$delai = "$heures "._T('date_une_heure');
409 409
 					} else {
410
-						$delai = "$heures " . _T('date_heures');
410
+						$delai = "$heures "._T('date_heures');
411 411
 					}
412 412
 				} else {
413 413
 					if ($decal >= 60) {
414 414
 						$minutes = floor($decal / 60);
415 415
 						if ($minutes < 2) {
416
-							$delai = "$minutes " . _T('date_une_minute');
416
+							$delai = "$minutes "._T('date_une_minute');
417 417
 						} else {
418
-							$delai = "$minutes " . _T('date_minutes');
418
+							$delai = "$minutes "._T('date_minutes');
419 419
 						}
420 420
 					} else {
421 421
 						$secondes = ceil($decal);
422 422
 						if ($secondes < 2) {
423
-							$delai = "$secondes " . _T('date_une_seconde');
423
+							$delai = "$secondes "._T('date_une_seconde');
424 424
 						} else {
425
-							$delai = "$secondes " . _T('date_secondes');
425
+							$delai = "$secondes "._T('date_secondes');
426 426
 						}
427 427
 					}
428 428
 				}
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 		$njour = 0;
518 518
 	} else {
519 519
 		$njour = intval($jour);
520
-		if ($jourth = _T('date_jnum' . $jour)) {
520
+		if ($jourth = _T('date_jnum'.$jour)) {
521 521
 			$jour = $jourth;
522 522
 		}
523 523
 	}
@@ -525,10 +525,10 @@  discard block
 block discarded – undo
525 525
 	$mois = intval($mois);
526 526
 	if ($mois > 0 and $mois < 13) {
527 527
 		/* Traiter le cas "abbr" pour les noms de mois */
528
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
529
-		$nommois = _T('date_mois_' . $mois . $param);
528
+		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : '');
529
+		$nommois = _T('date_mois_'.$mois.$param);
530 530
 		if ($jour) {
531
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
531
+			$jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]);
532 532
 		} else {
533 533
 			$jourmois = $nommois;
534 534
 		}
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 	}
539 539
 
540 540
 	if ($annee < 0) {
541
-		$annee = -$annee . ' ' . _T('date_avant_jc');
541
+		$annee = -$annee.' '._T('date_avant_jc');
542 542
 		$avjc = true;
543 543
 	} else {
544 544
 		$avjc = false;
@@ -564,11 +564,11 @@  discard block
 block discarded – undo
564 564
 				}
565 565
 			}
566 566
 			if ($vue == 'saison') {
567
-				return $saison ? _T('date_saison_' . $saison) : '';
567
+				return $saison ? _T('date_saison_'.$saison) : '';
568 568
 			} else {
569 569
 				return $saison ? trim(_T(
570 570
 					'date_fmt_saison_annee',
571
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
571
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
572 572
 				)) : '';
573 573
 			}
574 574
 
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
647 647
 			$nom = 1 + date('w', $nom);
648
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
648
+			$param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : '');
649 649
 
650
-			return _T('date_jour_' . $nom . $param);
650
+			return _T('date_jour_'.$nom.$param);
651 651
 
652 652
 		case 'mois_annee':
653 653
 			if ($avjc) {
@@ -1042,8 +1042,8 @@  discard block
 block discarded – undo
1042 1042
 
1043 1043
 	$dtstart = $dtend = $dtabbr = '';
1044 1044
 	if (strpos($forme, 'hcal') !== false) {
1045
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1046
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1045
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1046
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1047 1047
 		$dtabbr = '</abbr>';
1048 1048
 	}
1049 1049
 
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
 			}
1092 1092
 		} else {
1093 1093
 			if ($dtabbr && $dtstart) {
1094
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1094
+				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1095 1095
 			} else {
1096 1096
 				$s = spip_ucfirst($s);
1097 1097
 			}
@@ -1114,8 +1114,8 @@  discard block
 block discarded – undo
1114 1114
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1115 1115
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1116 1116
 			}
1117
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1118
-			$date_fin = $dtend . $date_fin . $dtabbr;
1117
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1118
+			$date_fin = $dtend.$date_fin.$dtabbr;
1119 1119
 
1120 1120
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1121 1121
 		} else {
@@ -1132,8 +1132,8 @@  discard block
 block discarded – undo
1132 1132
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1133 1133
 			}
1134 1134
 
1135
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1136
-			$date_fin = $dtend . $date_fin . $dtabbr;
1135
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1136
+			$date_fin = $dtend.$date_fin.$dtabbr;
1137 1137
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1138 1138
 		}
1139 1139
 	}
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
 		$d = date('Y-m-d');
1238 1238
 	}
1239 1239
 
1240
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1240
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1241 1241
 }
1242 1242
 
1243 1243
 /**
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
 		$d = date('Y-m-d');
1258 1258
 	}
1259 1259
 
1260
-	return substr($d, 0, 4) . substr($d, 5, 2);
1260
+	return substr($d, 0, 4).substr($d, 5, 2);
1261 1261
 }
1262 1262
 
1263 1263
 /**
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -212,8 +212,7 @@
 block discarded – undo
212 212
 function heures_minutes($numdate, $forme = '') {
213 213
 	if ($forme != 'abbr') {
214 214
 		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
215
-	}
216
-	else {
215
+	} else {
217 216
 		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
218 217
 	}
219 218
 }
Please login to merge, or discard this patch.
Indentation   +577 added lines, -577 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
  *    Date au format SQL tel que `2008-04-01`
37 37
  **/
38 38
 function extraire_date($texte) {
39
-	// format = 2001-08
40
-	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
41
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
42
-	}
39
+    // format = 2001-08
40
+    if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
41
+        return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
42
+    }
43 43
 }
44 44
 
45 45
 
@@ -61,29 +61,29 @@  discard block
 block discarded – undo
61 61
  *     - une chaîne vide si la date est considérée nulle
62 62
  **/
63 63
 function normaliser_date($date, $forcer_jour = false) {
64
-	$date = vider_date($date);
65
-	if ($date) {
66
-		if (preg_match('/^[0-9]{8,10}$/', $date)) {
67
-			$date = date('Y-m-d H:i:s', $date);
68
-		}
69
-		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
70
-			$regs = array_pad($regs, 4, null); // eviter notice php
71
-			$date = $regs[1] . '-00-00' . $regs[3];
72
-		} else {
73
-			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
74
-				$regs = array_pad($regs, 4, null); // eviter notice php
75
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
76
-			} else {
77
-				$date = date('Y-m-d H:i:s', strtotime($date));
78
-			}
79
-		}
80
-
81
-		if ($forcer_jour) {
82
-			$date = str_replace('-00', '-01', $date);
83
-		}
84
-	}
85
-
86
-	return $date;
64
+    $date = vider_date($date);
65
+    if ($date) {
66
+        if (preg_match('/^[0-9]{8,10}$/', $date)) {
67
+            $date = date('Y-m-d H:i:s', $date);
68
+        }
69
+        if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
70
+            $regs = array_pad($regs, 4, null); // eviter notice php
71
+            $date = $regs[1] . '-00-00' . $regs[3];
72
+        } else {
73
+            if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
74
+                $regs = array_pad($regs, 4, null); // eviter notice php
75
+                $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
76
+            } else {
77
+                $date = date('Y-m-d H:i:s', strtotime($date));
78
+            }
79
+        }
80
+
81
+        if ($forcer_jour) {
82
+            $date = str_replace('-00', '-01', $date);
83
+        }
84
+    }
85
+
86
+    return $date;
87 87
 }
88 88
 
89 89
 /**
@@ -96,22 +96,22 @@  discard block
 block discarded – undo
96 96
  *     - Une chaine vide
97 97
  **/
98 98
 function vider_date($letexte, $verif_format_date = false) {
99
-	if (
100
-		!$verif_format_date
101
-		or (in_array(strlen($letexte), [10,19]) and
102
-			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
103
-	) {
104
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
105
-			return '';
106
-		}
107
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
108
-			return '';
109
-		}
110
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
111
-			return '';
112
-		}  // eviter le bug GMT-1
113
-	}
114
-	return $letexte;
99
+    if (
100
+        !$verif_format_date
101
+        or (in_array(strlen($letexte), [10,19]) and
102
+              preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
103
+    ) {
104
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
105
+            return '';
106
+        }
107
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
108
+            return '';
109
+        }
110
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
111
+            return '';
112
+        }  // eviter le bug GMT-1
113
+    }
114
+    return $letexte;
115 115
 }
116 116
 
117 117
 /**
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
  **/
128 128
 function recup_heure($date) {
129 129
 
130
-	static $d = [0, 0, 0];
131
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
132
-		return $d;
133
-	}
130
+    static $d = [0, 0, 0];
131
+    if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
132
+        return $d;
133
+    }
134 134
 
135
-	array_shift($r);
135
+    array_shift($r);
136 136
 
137
-	return $r;
137
+    return $r;
138 138
 }
139 139
 
140 140
 /**
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
  * @return int heures, sinon 0
149 149
  **/
150 150
 function heures($numdate) {
151
-	$heures = null;
152
-	$date_array = recup_heure($numdate);
153
-	if ($date_array) {
154
-		[$heures, $minutes, $secondes] = $date_array;
155
-	}
151
+    $heures = null;
152
+    $date_array = recup_heure($numdate);
153
+    if ($date_array) {
154
+        [$heures, $minutes, $secondes] = $date_array;
155
+    }
156 156
 
157
-	return $heures;
157
+    return $heures;
158 158
 }
159 159
 
160 160
 /**
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
  * @return int minutes, sinon 0
169 169
  **/
170 170
 function minutes($numdate) {
171
-	$minutes = null;
172
-	$date_array = recup_heure($numdate);
173
-	if ($date_array) {
174
-		[$heures, $minutes, $secondes] = $date_array;
175
-	}
171
+    $minutes = null;
172
+    $date_array = recup_heure($numdate);
173
+    if ($date_array) {
174
+        [$heures, $minutes, $secondes] = $date_array;
175
+    }
176 176
 
177
-	return $minutes;
177
+    return $minutes;
178 178
 }
179 179
 
180 180
 /**
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
  * @return int secondes, sinon 0
189 189
  **/
190 190
 function secondes($numdate) {
191
-	$secondes = null;
192
-	$date_array = recup_heure($numdate);
193
-	if ($date_array) {
194
-		[$heures, $minutes, $secondes] = $date_array;
195
-	}
191
+    $secondes = null;
192
+    $date_array = recup_heure($numdate);
193
+    if ($date_array) {
194
+        [$heures, $minutes, $secondes] = $date_array;
195
+    }
196 196
 
197
-	return $secondes;
197
+    return $secondes;
198 198
 }
199 199
 
200 200
 /**
@@ -213,12 +213,12 @@  discard block
 block discarded – undo
213 213
  * @return string L'heure formatée dans la langue en cours.
214 214
  **/
215 215
 function heures_minutes($numdate, $forme = '') {
216
-	if ($forme != 'abbr') {
217
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
218
-	}
219
-	else {
220
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
-	}
216
+    if ($forme != 'abbr') {
217
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
218
+    }
219
+    else {
220
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
+    }
222 222
 }
223 223
 
224 224
 /**
@@ -243,56 +243,56 @@  discard block
 block discarded – undo
243 243
  * @return array [année, mois, jour, heures, minutes, secondes]
244 244
  **/
245 245
 function recup_date($numdate, $forcer_jour = true) {
246
-	if (!$numdate) {
247
-		return '';
248
-	}
249
-	$heures = $minutes = $secondes = 0;
250
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
251
-		$jour = $regs[1];
252
-		$mois = $regs[2];
253
-		$annee = $regs[3];
254
-		if ($annee < 90) {
255
-			$annee = 2000 + $annee;
256
-		} elseif ($annee < 100) {
257
-			$annee = 1900 + $annee;
258
-		}
259
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
260
-	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
261
-		$annee = $regs[1];
262
-		$mois = $regs[2];
263
-		$jour = $regs[3];
264
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
265
-	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
266
-		$annee = $regs[1];
267
-		$mois = $regs[2];
268
-		$jour = '';
269
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
270
-	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
271
-		$annee = $regs[1];
272
-		$mois = $regs[2];
273
-		$jour = $regs[3];
274
-		$heures = $regs[4];
275
-		$minutes = $regs[5];
276
-		$secondes = $regs[6];
277
-	} else {
278
-		$annee = $mois = $jour = '';
279
-	}
280
-	if ($annee > 4000) {
281
-		$annee -= 9000;
282
-	}
283
-	if (strlen($jour) and substr($jour, 0, 1) == '0') {
284
-		$jour = substr($jour, 1);
285
-	}
286
-
287
-	if ($forcer_jour and $jour == '0') {
288
-		$jour = '1';
289
-	}
290
-	if ($forcer_jour and $mois == '0') {
291
-		$mois = '1';
292
-	}
293
-	if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
294
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
295
-	}
246
+    if (!$numdate) {
247
+        return '';
248
+    }
249
+    $heures = $minutes = $secondes = 0;
250
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
251
+        $jour = $regs[1];
252
+        $mois = $regs[2];
253
+        $annee = $regs[3];
254
+        if ($annee < 90) {
255
+            $annee = 2000 + $annee;
256
+        } elseif ($annee < 100) {
257
+            $annee = 1900 + $annee;
258
+        }
259
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
260
+    } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
261
+        $annee = $regs[1];
262
+        $mois = $regs[2];
263
+        $jour = $regs[3];
264
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
265
+    } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
266
+        $annee = $regs[1];
267
+        $mois = $regs[2];
268
+        $jour = '';
269
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
270
+    } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
271
+        $annee = $regs[1];
272
+        $mois = $regs[2];
273
+        $jour = $regs[3];
274
+        $heures = $regs[4];
275
+        $minutes = $regs[5];
276
+        $secondes = $regs[6];
277
+    } else {
278
+        $annee = $mois = $jour = '';
279
+    }
280
+    if ($annee > 4000) {
281
+        $annee -= 9000;
282
+    }
283
+    if (strlen($jour) and substr($jour, 0, 1) == '0') {
284
+        $jour = substr($jour, 1);
285
+    }
286
+
287
+    if ($forcer_jour and $jour == '0') {
288
+        $jour = '1';
289
+    }
290
+    if ($forcer_jour and $mois == '0') {
291
+        $mois = '1';
292
+    }
293
+    if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
294
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
295
+    }
296 296
 }
297 297
 
298 298
 /**
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
  *     La date relative ou complète
320 320
  **/
321 321
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */) {
322
-	return sinon(
323
-		date_relative($date, $decalage_maxi),
324
-		affdate_heure($date)
325
-	);
322
+    return sinon(
323
+        date_relative($date, $decalage_maxi),
324
+        affdate_heure($date)
325
+    );
326 326
 }
327 327
 
328 328
 /**
@@ -355,85 +355,85 @@  discard block
 block discarded – undo
355 355
  **/
356 356
 function date_relative($date, $decalage_maxi = 0, $ref_date = null) {
357 357
 
358
-	if (is_null($ref_date)) {
359
-		$ref_time = time();
360
-	} else {
361
-		$ref_time = strtotime($ref_date);
362
-	}
363
-
364
-	if (!$date) {
365
-		return;
366
-	}
367
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
368
-
369
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
370
-		return '';
371
-	}
372
-
373
-	if ($decal < 0) {
374
-		$il_y_a = 'date_dans';
375
-		$decal = -1 * $decal;
376
-	} else {
377
-		$il_y_a = 'date_il_y_a';
378
-	}
379
-
380
-	if ($decal > 3600 * 24 * 30 * 6) {
381
-		return affdate_court($date);
382
-	}
383
-
384
-	if ($decal > 3600 * 24 * 30) {
385
-		$mois = floor($decal / (3600 * 24 * 30));
386
-		if ($mois < 2) {
387
-			$delai = "$mois " . _T('date_un_mois');
388
-		} else {
389
-			$delai = "$mois " . _T('date_mois');
390
-		}
391
-	} else {
392
-		if ($decal > 3600 * 24 * 7) {
393
-			$semaines = floor($decal / (3600 * 24 * 7));
394
-			if ($semaines < 2) {
395
-				$delai = "$semaines " . _T('date_une_semaine');
396
-			} else {
397
-				$delai = "$semaines " . _T('date_semaines');
398
-			}
399
-		} else {
400
-			if ($decal > 3600 * 24) {
401
-				$jours = floor($decal / (3600 * 24));
402
-				if ($jours < 2) {
403
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
404
-				} else {
405
-					$delai = "$jours " . _T('date_jours');
406
-				}
407
-			} else {
408
-				if ($decal >= 3600) {
409
-					$heures = floor($decal / 3600);
410
-					if ($heures < 2) {
411
-						$delai = "$heures " . _T('date_une_heure');
412
-					} else {
413
-						$delai = "$heures " . _T('date_heures');
414
-					}
415
-				} else {
416
-					if ($decal >= 60) {
417
-						$minutes = floor($decal / 60);
418
-						if ($minutes < 2) {
419
-							$delai = "$minutes " . _T('date_une_minute');
420
-						} else {
421
-							$delai = "$minutes " . _T('date_minutes');
422
-						}
423
-					} else {
424
-						$secondes = ceil($decal);
425
-						if ($secondes < 2) {
426
-							$delai = "$secondes " . _T('date_une_seconde');
427
-						} else {
428
-							$delai = "$secondes " . _T('date_secondes');
429
-						}
430
-					}
431
-				}
432
-			}
433
-		}
434
-	}
435
-
436
-	return _T($il_y_a, ['delai' => $delai]);
358
+    if (is_null($ref_date)) {
359
+        $ref_time = time();
360
+    } else {
361
+        $ref_time = strtotime($ref_date);
362
+    }
363
+
364
+    if (!$date) {
365
+        return;
366
+    }
367
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
368
+
369
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
370
+        return '';
371
+    }
372
+
373
+    if ($decal < 0) {
374
+        $il_y_a = 'date_dans';
375
+        $decal = -1 * $decal;
376
+    } else {
377
+        $il_y_a = 'date_il_y_a';
378
+    }
379
+
380
+    if ($decal > 3600 * 24 * 30 * 6) {
381
+        return affdate_court($date);
382
+    }
383
+
384
+    if ($decal > 3600 * 24 * 30) {
385
+        $mois = floor($decal / (3600 * 24 * 30));
386
+        if ($mois < 2) {
387
+            $delai = "$mois " . _T('date_un_mois');
388
+        } else {
389
+            $delai = "$mois " . _T('date_mois');
390
+        }
391
+    } else {
392
+        if ($decal > 3600 * 24 * 7) {
393
+            $semaines = floor($decal / (3600 * 24 * 7));
394
+            if ($semaines < 2) {
395
+                $delai = "$semaines " . _T('date_une_semaine');
396
+            } else {
397
+                $delai = "$semaines " . _T('date_semaines');
398
+            }
399
+        } else {
400
+            if ($decal > 3600 * 24) {
401
+                $jours = floor($decal / (3600 * 24));
402
+                if ($jours < 2) {
403
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
404
+                } else {
405
+                    $delai = "$jours " . _T('date_jours');
406
+                }
407
+            } else {
408
+                if ($decal >= 3600) {
409
+                    $heures = floor($decal / 3600);
410
+                    if ($heures < 2) {
411
+                        $delai = "$heures " . _T('date_une_heure');
412
+                    } else {
413
+                        $delai = "$heures " . _T('date_heures');
414
+                    }
415
+                } else {
416
+                    if ($decal >= 60) {
417
+                        $minutes = floor($decal / 60);
418
+                        if ($minutes < 2) {
419
+                            $delai = "$minutes " . _T('date_une_minute');
420
+                        } else {
421
+                            $delai = "$minutes " . _T('date_minutes');
422
+                        }
423
+                    } else {
424
+                        $secondes = ceil($decal);
425
+                        if ($secondes < 2) {
426
+                            $delai = "$secondes " . _T('date_une_seconde');
427
+                        } else {
428
+                            $delai = "$secondes " . _T('date_secondes');
429
+                        }
430
+                    }
431
+                }
432
+            }
433
+        }
434
+    }
435
+
436
+    return _T($il_y_a, ['delai' => $delai]);
437 437
 }
438 438
 
439 439
 
@@ -459,32 +459,32 @@  discard block
 block discarded – undo
459 459
  **/
460 460
 function date_relativecourt($date, $decalage_maxi = 0) {
461 461
 
462
-	if (!$date) {
463
-		return;
464
-	}
465
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
466
-
467
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
468
-		return '';
469
-	}
470
-
471
-	if ($decal < -24 * 3600) {
472
-		$retour = date_relative($date, $decalage_maxi);
473
-	} elseif ($decal < 0) {
474
-		$retour = _T('date_demain');
475
-	} else {
476
-		if ($decal < (3600 * 24)) {
477
-			$retour = _T('date_aujourdhui');
478
-		} else {
479
-			if ($decal < (3600 * 24 * 2)) {
480
-				$retour = _T('date_hier');
481
-			} else {
482
-				$retour = date_relative($date, $decalage_maxi);
483
-			}
484
-		}
485
-	}
486
-
487
-	return $retour;
462
+    if (!$date) {
463
+        return;
464
+    }
465
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
466
+
467
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
468
+        return '';
469
+    }
470
+
471
+    if ($decal < -24 * 3600) {
472
+        $retour = date_relative($date, $decalage_maxi);
473
+    } elseif ($decal < 0) {
474
+        $retour = _T('date_demain');
475
+    } else {
476
+        if ($decal < (3600 * 24)) {
477
+            $retour = _T('date_aujourdhui');
478
+        } else {
479
+            if ($decal < (3600 * 24 * 2)) {
480
+                $retour = _T('date_hier');
481
+            } else {
482
+                $retour = date_relative($date, $decalage_maxi);
483
+            }
484
+        }
485
+    }
486
+
487
+    return $retour;
488 488
 }
489 489
 
490 490
 /**
@@ -503,174 +503,174 @@  discard block
 block discarded – undo
503 503
  * @return mixed|string
504 504
  */
505 505
 function affdate_base($numdate, $vue, $options = []) {
506
-	if (is_string($options)) {
507
-		$options = ['param' => $options];
508
-	}
509
-	$date_array = recup_date($numdate, false);
510
-	if (!$date_array) {
511
-		return;
512
-	}
513
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
514
-
515
-	// 1er, 21st, etc.
516
-	$journum = $jour;
517
-
518
-	if ($jour == 0) {
519
-		$jour = '';
520
-		$njour = 0;
521
-	} else {
522
-		$njour = intval($jour);
523
-		if ($jourth = _T('date_jnum' . $jour)) {
524
-			$jour = $jourth;
525
-		}
526
-	}
527
-
528
-	$mois = intval($mois);
529
-	if ($mois > 0 and $mois < 13) {
530
-		/* Traiter le cas "abbr" pour les noms de mois */
531
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
532
-		$nommois = _T('date_mois_' . $mois . $param);
533
-		if ($jour) {
534
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
535
-		} else {
536
-			$jourmois = $nommois;
537
-		}
538
-	} else {
539
-		$nommois = '';
540
-		$jourmois = '';
541
-	}
542
-
543
-	if ($annee < 0) {
544
-		$annee = -$annee . ' ' . _T('date_avant_jc');
545
-		$avjc = true;
546
-	} else {
547
-		$avjc = false;
548
-	}
549
-
550
-	switch ($vue) {
551
-		case 'saison':
552
-		case 'saison_annee':
553
-			$saison = '';
554
-			if ($mois > 0) {
555
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
556
-				if (($mois == 3 and $jour >= 21) or $mois > 3) {
557
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
558
-				}
559
-				if (($mois == 6 and $jour >= 21) or $mois > 6) {
560
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
561
-				}
562
-				if (($mois == 9 and $jour >= 21) or $mois > 9) {
563
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
564
-				}
565
-				if (($mois == 12 and $jour >= 21) or $mois > 12) {
566
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
567
-				}
568
-			}
569
-			if ($vue == 'saison') {
570
-				return $saison ? _T('date_saison_' . $saison) : '';
571
-			} else {
572
-				return $saison ? trim(_T(
573
-					'date_fmt_saison_annee',
574
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
575
-				)) : '';
576
-			}
577
-
578
-		case 'court':
579
-			if ($avjc) {
580
-				return $annee;
581
-			}
582
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
583
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
584
-				return $annee;
585
-			}
586
-			if ($annee != $a) {
587
-				return _T(
588
-					'date_fmt_mois_annee',
589
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
590
-				);
591
-			}
592
-
593
-			return _T(
594
-				'date_fmt_jour_mois',
595
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
596
-			);
597
-
598
-		case 'jourcourt':
599
-			if ($avjc) {
600
-				return $annee;
601
-			}
602
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
603
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
604
-				return $annee;
605
-			}
606
-			if ($annee != $a) {
607
-				return _T(
608
-					'date_fmt_jour_mois_annee',
609
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
610
-				);
611
-			}
612
-
613
-			return _T(
614
-				'date_fmt_jour_mois',
615
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
616
-			);
617
-
618
-		case 'entier':
619
-			if ($avjc) {
620
-				return $annee;
621
-			}
622
-			if ($jour) {
623
-				return _T(
624
-					'date_fmt_jour_mois_annee',
625
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
626
-				);
627
-			} elseif ($mois) {
628
-				return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
629
-			} else {
630
-				return $annee;
631
-			}
632
-
633
-		case 'nom_mois':
634
-			return $nommois;
635
-
636
-		case 'mois':
637
-			return sprintf('%02s', $mois);
638
-
639
-		case 'jour':
640
-			return $jour;
641
-
642
-		case 'journum':
643
-			return $journum;
644
-
645
-		case 'nom_jour':
646
-			if (!$mois or !$njour) {
647
-				return '';
648
-			}
649
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
650
-			$nom = 1 + date('w', $nom);
651
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
652
-
653
-			return _T('date_jour_' . $nom . $param);
654
-
655
-		case 'mois_annee':
656
-			if ($avjc) {
657
-				return $annee;
658
-			}
659
-
660
-			return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
661
-
662
-		case 'annee':
663
-			return $annee;
664
-
665
-		// Cas d'une vue non definie : retomber sur le format
666
-		// de date propose par http://www.php.net/date
667
-		default:
668
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
669
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
670
-				$time = strtotime($numdate);
671
-			}
672
-			return date($vue, $time);
673
-	}
506
+    if (is_string($options)) {
507
+        $options = ['param' => $options];
508
+    }
509
+    $date_array = recup_date($numdate, false);
510
+    if (!$date_array) {
511
+        return;
512
+    }
513
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
514
+
515
+    // 1er, 21st, etc.
516
+    $journum = $jour;
517
+
518
+    if ($jour == 0) {
519
+        $jour = '';
520
+        $njour = 0;
521
+    } else {
522
+        $njour = intval($jour);
523
+        if ($jourth = _T('date_jnum' . $jour)) {
524
+            $jour = $jourth;
525
+        }
526
+    }
527
+
528
+    $mois = intval($mois);
529
+    if ($mois > 0 and $mois < 13) {
530
+        /* Traiter le cas "abbr" pour les noms de mois */
531
+        $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
532
+        $nommois = _T('date_mois_' . $mois . $param);
533
+        if ($jour) {
534
+            $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
535
+        } else {
536
+            $jourmois = $nommois;
537
+        }
538
+    } else {
539
+        $nommois = '';
540
+        $jourmois = '';
541
+    }
542
+
543
+    if ($annee < 0) {
544
+        $annee = -$annee . ' ' . _T('date_avant_jc');
545
+        $avjc = true;
546
+    } else {
547
+        $avjc = false;
548
+    }
549
+
550
+    switch ($vue) {
551
+        case 'saison':
552
+        case 'saison_annee':
553
+            $saison = '';
554
+            if ($mois > 0) {
555
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
556
+                if (($mois == 3 and $jour >= 21) or $mois > 3) {
557
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
558
+                }
559
+                if (($mois == 6 and $jour >= 21) or $mois > 6) {
560
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
561
+                }
562
+                if (($mois == 9 and $jour >= 21) or $mois > 9) {
563
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
564
+                }
565
+                if (($mois == 12 and $jour >= 21) or $mois > 12) {
566
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
567
+                }
568
+            }
569
+            if ($vue == 'saison') {
570
+                return $saison ? _T('date_saison_' . $saison) : '';
571
+            } else {
572
+                return $saison ? trim(_T(
573
+                    'date_fmt_saison_annee',
574
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
575
+                )) : '';
576
+            }
577
+
578
+        case 'court':
579
+            if ($avjc) {
580
+                return $annee;
581
+            }
582
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
583
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
584
+                return $annee;
585
+            }
586
+            if ($annee != $a) {
587
+                return _T(
588
+                    'date_fmt_mois_annee',
589
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
590
+                );
591
+            }
592
+
593
+            return _T(
594
+                'date_fmt_jour_mois',
595
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
596
+            );
597
+
598
+        case 'jourcourt':
599
+            if ($avjc) {
600
+                return $annee;
601
+            }
602
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
603
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
604
+                return $annee;
605
+            }
606
+            if ($annee != $a) {
607
+                return _T(
608
+                    'date_fmt_jour_mois_annee',
609
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
610
+                );
611
+            }
612
+
613
+            return _T(
614
+                'date_fmt_jour_mois',
615
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
616
+            );
617
+
618
+        case 'entier':
619
+            if ($avjc) {
620
+                return $annee;
621
+            }
622
+            if ($jour) {
623
+                return _T(
624
+                    'date_fmt_jour_mois_annee',
625
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
626
+                );
627
+            } elseif ($mois) {
628
+                return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
629
+            } else {
630
+                return $annee;
631
+            }
632
+
633
+        case 'nom_mois':
634
+            return $nommois;
635
+
636
+        case 'mois':
637
+            return sprintf('%02s', $mois);
638
+
639
+        case 'jour':
640
+            return $jour;
641
+
642
+        case 'journum':
643
+            return $journum;
644
+
645
+        case 'nom_jour':
646
+            if (!$mois or !$njour) {
647
+                return '';
648
+            }
649
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
650
+            $nom = 1 + date('w', $nom);
651
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
652
+
653
+            return _T('date_jour_' . $nom . $param);
654
+
655
+        case 'mois_annee':
656
+            if ($avjc) {
657
+                return $annee;
658
+            }
659
+
660
+            return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
661
+
662
+        case 'annee':
663
+            return $annee;
664
+
665
+        // Cas d'une vue non definie : retomber sur le format
666
+        // de date propose par http://www.php.net/date
667
+        default:
668
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
669
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
670
+                $time = strtotime($numdate);
671
+            }
672
+            return date($vue, $time);
673
+    }
674 674
 }
675 675
 
676 676
 
@@ -697,11 +697,11 @@  discard block
 block discarded – undo
697 697
  *     Nom du jour
698 698
  **/
699 699
 function nom_jour($numdate, $forme = '') {
700
-	if (!($forme == 'abbr' or $forme == 'initiale')) {
701
-		$forme = '';
702
-	}
700
+    if (!($forme == 'abbr' or $forme == 'initiale')) {
701
+        $forme = '';
702
+    }
703 703
 
704
-	return affdate_base($numdate, 'nom_jour', $forme);
704
+    return affdate_base($numdate, 'nom_jour', $forme);
705 705
 }
706 706
 
707 707
 /**
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
  *     Numéro du jour
724 724
  **/
725 725
 function jour($numdate) {
726
-	return affdate_base($numdate, 'jour');
726
+    return affdate_base($numdate, 'jour');
727 727
 }
728 728
 
729 729
 /**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
  *     Numéro du jour
742 742
  **/
743 743
 function journum($numdate) {
744
-	return affdate_base($numdate, 'journum');
744
+    return affdate_base($numdate, 'journum');
745 745
 }
746 746
 
747 747
 /**
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
  *     Numéro du mois (sur 2 chiffres)
760 760
  **/
761 761
 function mois($numdate) {
762
-	return affdate_base($numdate, 'mois');
762
+    return affdate_base($numdate, 'mois');
763 763
 }
764 764
 
765 765
 /**
@@ -783,11 +783,11 @@  discard block
 block discarded – undo
783 783
  *     Nom du mois
784 784
  **/
785 785
 function nom_mois($numdate, $forme = '') {
786
-	if (!($forme == 'abbr')) {
787
-		$forme = '';
788
-	}
786
+    if (!($forme == 'abbr')) {
787
+        $forme = '';
788
+    }
789 789
 
790
-	return affdate_base($numdate, 'nom_mois', $forme);
790
+    return affdate_base($numdate, 'nom_mois', $forme);
791 791
 }
792 792
 
793 793
 /**
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
  *     Année (sur 4 chiffres)
806 806
  **/
807 807
 function annee($numdate) {
808
-	return affdate_base($numdate, 'annee');
808
+    return affdate_base($numdate, 'annee');
809 809
 }
810 810
 
811 811
 
@@ -835,11 +835,11 @@  discard block
 block discarded – undo
835 835
  *     La date formatée
836 836
  **/
837 837
 function saison($numdate, $hemisphere = 'nord') {
838
-	if ($hemisphere != 'sud') {
839
-		$hemisphere = 'nord';
840
-	}
838
+    if ($hemisphere != 'sud') {
839
+        $hemisphere = 'nord';
840
+    }
841 841
 
842
-	return affdate_base($numdate, 'saison', $hemisphere);
842
+    return affdate_base($numdate, 'saison', $hemisphere);
843 843
 }
844 844
 
845 845
 
@@ -868,11 +868,11 @@  discard block
 block discarded – undo
868 868
  *     La date formatée
869 869
  **/
870 870
 function saison_annee($numdate, $hemisphere = 'nord') {
871
-	if ($hemisphere != 'sud') {
872
-		$hemisphere = 'nord';
873
-	}
871
+    if ($hemisphere != 'sud') {
872
+        $hemisphere = 'nord';
873
+    }
874 874
 
875
-	return affdate_base($numdate, 'saison_annee', $hemisphere);
875
+    return affdate_base($numdate, 'saison_annee', $hemisphere);
876 876
 }
877 877
 
878 878
 /**
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
  *     La date formatée
901 901
  **/
902 902
 function affdate($numdate, $format = 'entier') {
903
-	return affdate_base($numdate, $format);
903
+    return affdate_base($numdate, $format);
904 904
 }
905 905
 
906 906
 
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
  *     La date formatée
928 928
  **/
929 929
 function affdate_court($numdate, $annee_courante = null) {
930
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
930
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
931 931
 }
932 932
 
933 933
 
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
  *     La date formatée
955 955
  **/
956 956
 function affdate_jourcourt($numdate, $annee_courante = null) {
957
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
957
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
958 958
 }
959 959
 
960 960
 /**
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
  *     La date formatée
973 973
  **/
974 974
 function affdate_mois_annee($numdate) {
975
-	return affdate_base($numdate, 'mois_annee');
975
+    return affdate_base($numdate, 'mois_annee');
976 976
 }
977 977
 
978 978
 /**
@@ -990,16 +990,16 @@  discard block
 block discarded – undo
990 990
  *     La date formatée
991 991
  **/
992 992
 function affdate_heure($numdate) {
993
-	$date_array = recup_date($numdate);
994
-	if (!$date_array) {
995
-		return;
996
-	}
997
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
998
-
999
-	return _T('date_fmt_jour_heure', [
1000
-		'jour' => affdate($numdate),
1001
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1002
-	]);
993
+    $date_array = recup_date($numdate);
994
+    if (!$date_array) {
995
+        return;
996
+    }
997
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
998
+
999
+    return _T('date_fmt_jour_heure', [
1000
+        'jour' => affdate($numdate),
1001
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1002
+    ]);
1003 1003
 }
1004 1004
 
1005 1005
 /**
@@ -1031,117 +1031,117 @@  discard block
 block discarded – undo
1031 1031
  *     Texte de la date
1032 1032
  */
1033 1033
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = '') {
1034
-	$abbr = $jour = '';
1035
-	$affdate = 'affdate_jourcourt';
1036
-	if (strpos($forme, 'abbr') !== false) {
1037
-		$abbr = 'abbr';
1038
-	}
1039
-	if (strpos($forme, 'annee') !== false) {
1040
-		$affdate = 'affdate';
1041
-	}
1042
-	if (strpos($forme, 'jour') !== false) {
1043
-		$jour = 'jour';
1044
-	}
1045
-
1046
-	$dtstart = $dtend = $dtabbr = '';
1047
-	if (strpos($forme, 'hcal') !== false) {
1048
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1049
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1050
-		$dtabbr = '</abbr>';
1051
-	}
1052
-
1053
-	$date_debut = strtotime($date_debut);
1054
-	$date_fin = strtotime($date_fin);
1055
-	$d = date('Y-m-d', $date_debut);
1056
-	$f = date('Y-m-d', $date_fin);
1057
-	$h = ($horaire === 'oui' or $horaire === true);
1058
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1059
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1060
-
1061
-	if ($d == $f) { // meme jour
1062
-		$nomjour = nom_jour($d, $abbr);
1063
-		$s = $affdate($d);
1064
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1065
-		if ($h) {
1066
-			if ($hd == $hf) {
1067
-				// Lundi 20 fevrier a 18h25
1068
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1069
-				$s = "$dtstart$s$dtabbr";
1070
-			} else {
1071
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1072
-				if ($dtabbr && $dtstart && $dtend) {
1073
-					$s = _T(
1074
-						'date_fmt_jour_heure_debut_fin_abbr',
1075
-						[
1076
-						'jour' => spip_ucfirst($s),
1077
-						'heure_debut' => $hd,
1078
-						'heure_fin' => $hf,
1079
-						'dtstart' => $dtstart,
1080
-						'dtend' => $dtend,
1081
-						'dtabbr' => $dtabbr
1082
-						],
1083
-						[
1084
-							'sanitize' => false
1085
-						]
1086
-					);
1087
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1088
-				else {
1089
-					$s = spip_ucfirst(_T(
1090
-						'date_fmt_jour_heure_debut_fin',
1091
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1092
-					));
1093
-				}
1094
-			}
1095
-		} else {
1096
-			if ($dtabbr && $dtstart) {
1097
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1098
-			} else {
1099
-				$s = spip_ucfirst($s);
1100
-			}
1101
-		}
1102
-	} else {
1103
-		if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1104
-			if (!$h) {
1105
-				$date_debut = jour($d);
1106
-			} else {
1107
-				$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1108
-			}
1109
-			$date_fin = $affdate($f);
1110
-			if ($jour) {
1111
-				$nomjour_debut = nom_jour($d, $abbr);
1112
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1113
-				$nomjour_fin = nom_jour($f, $abbr);
1114
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1115
-			}
1116
-			if ($h) {
1117
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1118
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1119
-			}
1120
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1121
-			$date_fin = $dtend . $date_fin . $dtabbr;
1122
-
1123
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1124
-		} else {
1125
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1126
-			$date_fin = $affdate($f);
1127
-			if ($jour) {
1128
-				$nomjour_debut = nom_jour($d, $abbr);
1129
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1130
-				$nomjour_fin = nom_jour($f, $abbr);
1131
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1132
-			}
1133
-			if ($h) {
1134
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1135
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1136
-			}
1137
-
1138
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1139
-			$date_fin = $dtend . $date_fin . $dtabbr;
1140
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1141
-		}
1142
-	}
1143
-
1144
-	return $s;
1034
+    $abbr = $jour = '';
1035
+    $affdate = 'affdate_jourcourt';
1036
+    if (strpos($forme, 'abbr') !== false) {
1037
+        $abbr = 'abbr';
1038
+    }
1039
+    if (strpos($forme, 'annee') !== false) {
1040
+        $affdate = 'affdate';
1041
+    }
1042
+    if (strpos($forme, 'jour') !== false) {
1043
+        $jour = 'jour';
1044
+    }
1045
+
1046
+    $dtstart = $dtend = $dtabbr = '';
1047
+    if (strpos($forme, 'hcal') !== false) {
1048
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1049
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1050
+        $dtabbr = '</abbr>';
1051
+    }
1052
+
1053
+    $date_debut = strtotime($date_debut);
1054
+    $date_fin = strtotime($date_fin);
1055
+    $d = date('Y-m-d', $date_debut);
1056
+    $f = date('Y-m-d', $date_fin);
1057
+    $h = ($horaire === 'oui' or $horaire === true);
1058
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1059
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1060
+
1061
+    if ($d == $f) { // meme jour
1062
+        $nomjour = nom_jour($d, $abbr);
1063
+        $s = $affdate($d);
1064
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1065
+        if ($h) {
1066
+            if ($hd == $hf) {
1067
+                // Lundi 20 fevrier a 18h25
1068
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1069
+                $s = "$dtstart$s$dtabbr";
1070
+            } else {
1071
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1072
+                if ($dtabbr && $dtstart && $dtend) {
1073
+                    $s = _T(
1074
+                        'date_fmt_jour_heure_debut_fin_abbr',
1075
+                        [
1076
+                        'jour' => spip_ucfirst($s),
1077
+                        'heure_debut' => $hd,
1078
+                        'heure_fin' => $hf,
1079
+                        'dtstart' => $dtstart,
1080
+                        'dtend' => $dtend,
1081
+                        'dtabbr' => $dtabbr
1082
+                        ],
1083
+                        [
1084
+                            'sanitize' => false
1085
+                        ]
1086
+                    );
1087
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1088
+                else {
1089
+                    $s = spip_ucfirst(_T(
1090
+                        'date_fmt_jour_heure_debut_fin',
1091
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1092
+                    ));
1093
+                }
1094
+            }
1095
+        } else {
1096
+            if ($dtabbr && $dtstart) {
1097
+                $s = $dtstart . spip_ucfirst($s) . $dtabbr;
1098
+            } else {
1099
+                $s = spip_ucfirst($s);
1100
+            }
1101
+        }
1102
+    } else {
1103
+        if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1104
+            if (!$h) {
1105
+                $date_debut = jour($d);
1106
+            } else {
1107
+                $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1108
+            }
1109
+            $date_fin = $affdate($f);
1110
+            if ($jour) {
1111
+                $nomjour_debut = nom_jour($d, $abbr);
1112
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1113
+                $nomjour_fin = nom_jour($f, $abbr);
1114
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1115
+            }
1116
+            if ($h) {
1117
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1118
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1119
+            }
1120
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1121
+            $date_fin = $dtend . $date_fin . $dtabbr;
1122
+
1123
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1124
+        } else {
1125
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1126
+            $date_fin = $affdate($f);
1127
+            if ($jour) {
1128
+                $nomjour_debut = nom_jour($d, $abbr);
1129
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1130
+                $nomjour_fin = nom_jour($f, $abbr);
1131
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1132
+            }
1133
+            if ($h) {
1134
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1135
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1136
+            }
1137
+
1138
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1139
+            $date_fin = $dtend . $date_fin . $dtabbr;
1140
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1141
+        }
1142
+    }
1143
+
1144
+    return $s;
1145 1145
 }
1146 1146
 
1147 1147
 /**
@@ -1162,10 +1162,10 @@  discard block
 block discarded – undo
1162 1162
  *     Date au format ical
1163 1163
  **/
1164 1164
 function date_ical($date, $addminutes = 0) {
1165
-	[$heures, $minutes, $secondes] = recup_heure($date);
1166
-	[$annee, $mois, $jour] = recup_date($date);
1165
+    [$heures, $minutes, $secondes] = recup_heure($date);
1166
+    [$annee, $mois, $jour] = recup_date($date);
1167 1167
 
1168
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1168
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1169 1169
 }
1170 1170
 
1171 1171
 
@@ -1189,11 +1189,11 @@  discard block
 block discarded – undo
1189 1189
  *     La date formatée
1190 1190
  **/
1191 1191
 function date_iso($date_heure) {
1192
-	[$annee, $mois, $jour] = recup_date($date_heure);
1193
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1194
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1192
+    [$annee, $mois, $jour] = recup_date($date_heure);
1193
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1194
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1195 1195
 
1196
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1196
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1197 1197
 }
1198 1198
 
1199 1199
 /**
@@ -1216,11 +1216,11 @@  discard block
 block discarded – undo
1216 1216
  *     La date formatée
1217 1217
  **/
1218 1218
 function date_822($date_heure) {
1219
-	[$annee, $mois, $jour] = recup_date($date_heure);
1220
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1221
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1219
+    [$annee, $mois, $jour] = recup_date($date_heure);
1220
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1221
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1222 1222
 
1223
-	return date('r', $time);
1223
+    return date('r', $time);
1224 1224
 }
1225 1225
 
1226 1226
 /**
@@ -1236,11 +1236,11 @@  discard block
 block discarded – undo
1236 1236
  *     Date au format `Ymd`
1237 1237
  **/
1238 1238
 function date_anneemoisjour($d) {
1239
-	if (!$d) {
1240
-		$d = date('Y-m-d');
1241
-	}
1239
+    if (!$d) {
1240
+        $d = date('Y-m-d');
1241
+    }
1242 1242
 
1243
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1243
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1244 1244
 }
1245 1245
 
1246 1246
 /**
@@ -1256,11 +1256,11 @@  discard block
 block discarded – undo
1256 1256
  *     Date au format `Ym`
1257 1257
  **/
1258 1258
 function date_anneemois($d) {
1259
-	if (!$d) {
1260
-		$d = date('Y-m-d');
1261
-	}
1259
+    if (!$d) {
1260
+        $d = date('Y-m-d');
1261
+    }
1262 1262
 
1263
-	return substr($d, 0, 4) . substr($d, 5, 2);
1263
+    return substr($d, 0, 4) . substr($d, 5, 2);
1264 1264
 }
1265 1265
 
1266 1266
 /**
@@ -1276,13 +1276,13 @@  discard block
 block discarded – undo
1276 1276
  *     Date au lundi de la même semaine au format `Ymd`
1277 1277
  **/
1278 1278
 function date_debut_semaine($annee, $mois, $jour) {
1279
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1280
-	if ($w_day == 0) {
1281
-		$w_day = 7;
1282
-	} // Gaffe: le dimanche est zero
1283
-	$debut = $jour - $w_day + 1;
1279
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1280
+    if ($w_day == 0) {
1281
+        $w_day = 7;
1282
+    } // Gaffe: le dimanche est zero
1283
+    $debut = $jour - $w_day + 1;
1284 1284
 
1285
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1285
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1286 1286
 }
1287 1287
 
1288 1288
 /**
@@ -1298,11 +1298,11 @@  discard block
 block discarded – undo
1298 1298
  *     Date au dimanche de la même semaine au format `Ymd`
1299 1299
  **/
1300 1300
 function date_fin_semaine($annee, $mois, $jour) {
1301
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1302
-	if ($w_day == 0) {
1303
-		$w_day = 7;
1304
-	} // Gaffe: le dimanche est zero
1305
-	$debut = $jour - $w_day + 1;
1301
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1302
+    if ($w_day == 0) {
1303
+        $w_day = 7;
1304
+    } // Gaffe: le dimanche est zero
1305
+    $debut = $jour - $w_day + 1;
1306 1306
 
1307
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1307
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1308 1308
 }
Please login to merge, or discard this patch.
ecrire/inc/puce_statut.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -416,7 +416,7 @@
 block discarded – undo
416 416
 	$h = generer_action_auteur('instituer_objet', "$type-$id-$statut");
417 417
 	$t = supprimer_tags($titre);
418 418
 
419
-	return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>';
419
+	return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t).'</a>';
420 420
 }
421 421
 
422 422
 // compat
Please login to merge, or discard this patch.
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 if (!defined('_ACTIVER_PUCE_RAPIDE')) {
25
-	/**
26
-	 * Activer le changement rapide de statut sur les listes d'objets ?
27
-	 *
28
-	 * Peut ralentir un site sur des listes très longues.
29
-	 *
30
-	 * @var bool
31
-	 **/
32
-	define('_ACTIVER_PUCE_RAPIDE', true);
25
+    /**
26
+     * Activer le changement rapide de statut sur les listes d'objets ?
27
+     *
28
+     * Peut ralentir un site sur des listes très longues.
29
+     *
30
+     * @var bool
31
+     **/
32
+    define('_ACTIVER_PUCE_RAPIDE', true);
33 33
 }
34 34
 
35 35
 /**
@@ -57,31 +57,31 @@  discard block
 block discarded – undo
57 57
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
58 58
  */
59 59
 function inc_puce_statut_dist(
60
-	$id_objet,
61
-	$statut,
62
-	$id_parent,
63
-	$type,
64
-	$ajax = false,
65
-	$menu_rapide = _ACTIVER_PUCE_RAPIDE
60
+    $id_objet,
61
+    $statut,
62
+    $id_parent,
63
+    $type,
64
+    $ajax = false,
65
+    $menu_rapide = _ACTIVER_PUCE_RAPIDE
66 66
 ) {
67
-	static $f_puce_statut = [];
68
-	$type = objet_type($type);
69
-	// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
70
-	if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) {
71
-		$f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
72
-	}
73
-	if ($f_puce_statut[$type]) {
74
-		return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
75
-	}
76
-
77
-	// si statut_image trouve quelque chose (et '' est quelque chose)
78
-	// composer une puce, avec si possible changement rapide
79
-	elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
80
-		return $puce;
81
-	} // sinon fausse puce avec le type de l'image
82
-	else {
83
-		return http_img_pack("$type-16.png", '');
84
-	}
67
+    static $f_puce_statut = [];
68
+    $type = objet_type($type);
69
+    // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
70
+    if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) {
71
+        $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
72
+    }
73
+    if ($f_puce_statut[$type]) {
74
+        return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
75
+    }
76
+
77
+    // si statut_image trouve quelque chose (et '' est quelque chose)
78
+    // composer une puce, avec si possible changement rapide
79
+    elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
80
+        return $puce;
81
+    } // sinon fausse puce avec le type de l'image
82
+    else {
83
+        return http_img_pack("$type-16.png", '');
84
+    }
85 85
 }
86 86
 
87 87
 /**
@@ -110,41 +110,41 @@  discard block
 block discarded – undo
110 110
  *   null si pas capable de déterminer l'image
111 111
  */
112 112
 function statut_image($objet, $statut) {
113
-	$src = null;
114
-	$table = table_objet_sql($objet);
115
-	$desc = lister_tables_objets_sql($table);
116
-	if (isset($desc['statut_images'])) {
117
-		// si une declaration statut_images
118
-		// mais rien pour le statut demande, ne rien afficher
119
-		$src = '';
120
-		if (isset($desc['statut_images'][$statut])) {
121
-			$src = $desc['statut_images'][$statut];
122
-		} // sinon image par defaut ?
123
-		elseif (isset($desc['statut_images'][0])) {
124
-			$src = $desc['statut_images'][0];
125
-		}
126
-	} else {
127
-		switch ($statut) {
128
-			case 'prepa':
129
-				$src = 'puce-preparer-xx.svg?12px';
130
-				break;
131
-			case 'prop':
132
-				$src = 'puce-proposer-xx.svg?12px';
133
-				break;
134
-			case 'publie':
135
-				$src = 'puce-publier-xx.svg?12px';
136
-				break;
137
-			case 'refuse':
138
-				$src = 'puce-refuser-xx.svg?12px';
139
-				break;
140
-			case 'poubelle':
141
-			case 'poub':
142
-				$src = 'puce-supprimer-xx.svg?12px';
143
-				break;
144
-		}
145
-	}
146
-
147
-	return $src;
113
+    $src = null;
114
+    $table = table_objet_sql($objet);
115
+    $desc = lister_tables_objets_sql($table);
116
+    if (isset($desc['statut_images'])) {
117
+        // si une declaration statut_images
118
+        // mais rien pour le statut demande, ne rien afficher
119
+        $src = '';
120
+        if (isset($desc['statut_images'][$statut])) {
121
+            $src = $desc['statut_images'][$statut];
122
+        } // sinon image par defaut ?
123
+        elseif (isset($desc['statut_images'][0])) {
124
+            $src = $desc['statut_images'][0];
125
+        }
126
+    } else {
127
+        switch ($statut) {
128
+            case 'prepa':
129
+                $src = 'puce-preparer-xx.svg?12px';
130
+                break;
131
+            case 'prop':
132
+                $src = 'puce-proposer-xx.svg?12px';
133
+                break;
134
+            case 'publie':
135
+                $src = 'puce-publier-xx.svg?12px';
136
+                break;
137
+            case 'refuse':
138
+                $src = 'puce-refuser-xx.svg?12px';
139
+                break;
140
+            case 'poubelle':
141
+            case 'poub':
142
+                $src = 'puce-supprimer-xx.svg?12px';
143
+                break;
144
+        }
145
+    }
146
+
147
+    return $src;
148 148
 }
149 149
 
150 150
 /**
@@ -172,40 +172,40 @@  discard block
 block discarded – undo
172 172
  * @return string
173 173
  */
174 174
 function statut_titre($objet, $statut) {
175
-	$titre = '';
176
-	$table = table_objet_sql($objet);
177
-	$desc = lister_tables_objets_sql($table);
178
-	if (isset($desc['statut_titres'])) {
179
-		// si une declaration statut_titres
180
-		// mais rien pour le statut demande, ne rien afficher
181
-		if (isset($desc['statut_titres'][$statut])) {
182
-			$titre = $desc['statut_titres'][$statut];
183
-		} // sinon image par defaut ?
184
-		elseif (isset($desc['statut_titres'][0])) {
185
-			$titre = $desc['statut_titres'][0];
186
-		}
187
-	} else {
188
-		switch ($statut) {
189
-			case 'prepa':
190
-				$titre = 'texte_statut_en_cours_redaction';
191
-				break;
192
-			case 'prop':
193
-				$titre = 'texte_statut_propose_evaluation';
194
-				break;
195
-			case 'publie':
196
-				$titre = 'texte_statut_publie';
197
-				break;
198
-			case 'refuse':
199
-				$titre = 'texte_statut_refuse';
200
-				break;
201
-			case 'poubelle':
202
-			case 'poub':
203
-				$titre = 'texte_statut_poubelle';
204
-				break;
205
-		}
206
-	}
207
-
208
-	return $titre ? _T($titre) : '';
175
+    $titre = '';
176
+    $table = table_objet_sql($objet);
177
+    $desc = lister_tables_objets_sql($table);
178
+    if (isset($desc['statut_titres'])) {
179
+        // si une declaration statut_titres
180
+        // mais rien pour le statut demande, ne rien afficher
181
+        if (isset($desc['statut_titres'][$statut])) {
182
+            $titre = $desc['statut_titres'][$statut];
183
+        } // sinon image par defaut ?
184
+        elseif (isset($desc['statut_titres'][0])) {
185
+            $titre = $desc['statut_titres'][0];
186
+        }
187
+    } else {
188
+        switch ($statut) {
189
+            case 'prepa':
190
+                $titre = 'texte_statut_en_cours_redaction';
191
+                break;
192
+            case 'prop':
193
+                $titre = 'texte_statut_propose_evaluation';
194
+                break;
195
+            case 'publie':
196
+                $titre = 'texte_statut_publie';
197
+                break;
198
+            case 'refuse':
199
+                $titre = 'texte_statut_refuse';
200
+                break;
201
+            case 'poubelle':
202
+            case 'poub':
203
+                $titre = 'texte_statut_poubelle';
204
+                break;
205
+        }
206
+    }
207
+
208
+    return $titre ? _T($titre) : '';
209 209
 }
210 210
 
211 211
 
@@ -225,37 +225,37 @@  discard block
 block discarded – undo
225 225
  * @return string
226 226
  */
227 227
 function statut_texte_instituer($objet, $statut) {
228
-	$texte = '';
229
-	$table = table_objet_sql($objet);
230
-	$desc = lister_tables_objets_sql($table);
231
-	if (isset($desc['statut_textes_instituer'])) {
232
-		// si une declaration statut_titres
233
-		// mais rien pour le statut demande, ne rien afficher
234
-		if (isset($desc['statut_textes_instituer'][$statut])) {
235
-			$texte = $desc['statut_textes_instituer'][$statut];
236
-		}
237
-	} else {
238
-		switch ($statut) {
239
-			case 'prepa':
240
-				$texte = 'texte_statut_en_cours_redaction';
241
-				break;
242
-			case 'prop':
243
-				$texte = 'texte_statut_propose_evaluation';
244
-				break;
245
-			case 'publie':
246
-				$texte = 'texte_statut_publie';
247
-				break;
248
-			case 'refuse':
249
-				$texte = 'texte_statut_refuse';
250
-				break;
251
-			case 'poubelle':
252
-			case 'poub':
253
-				$texte = 'texte_statut_poubelle';
254
-				break;
255
-		}
256
-	}
257
-
258
-	return $texte ? _T($texte) : '';
228
+    $texte = '';
229
+    $table = table_objet_sql($objet);
230
+    $desc = lister_tables_objets_sql($table);
231
+    if (isset($desc['statut_textes_instituer'])) {
232
+        // si une declaration statut_titres
233
+        // mais rien pour le statut demande, ne rien afficher
234
+        if (isset($desc['statut_textes_instituer'][$statut])) {
235
+            $texte = $desc['statut_textes_instituer'][$statut];
236
+        }
237
+    } else {
238
+        switch ($statut) {
239
+            case 'prepa':
240
+                $texte = 'texte_statut_en_cours_redaction';
241
+                break;
242
+            case 'prop':
243
+                $texte = 'texte_statut_propose_evaluation';
244
+                break;
245
+            case 'publie':
246
+                $texte = 'texte_statut_publie';
247
+                break;
248
+            case 'refuse':
249
+                $texte = 'texte_statut_refuse';
250
+                break;
251
+            case 'poubelle':
252
+            case 'poub':
253
+                $texte = 'texte_statut_poubelle';
254
+                break;
255
+        }
256
+    }
257
+
258
+    return $texte ? _T($texte) : '';
259 259
 }
260 260
 
261 261
 
@@ -275,16 +275,16 @@  discard block
 block discarded – undo
275 275
  * @return string
276 276
  */
277 277
 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
278
-	$img = statut_image('auteur', $statut);
279
-	if (!$img) {
280
-		return '';
281
-	}
282
-	$alt = statut_titre('auteur', $statut);
278
+    $img = statut_image('auteur', $statut);
279
+    if (!$img) {
280
+        return '';
281
+    }
282
+    $alt = statut_titre('auteur', $statut);
283 283
 
284
-	$fond = '';
285
-	$titre = '';
284
+    $fond = '';
285
+    $titre = '';
286 286
 
287
-	/*
287
+    /*
288 288
 	if ($type != 'auteur') {
289 289
 	  $img2 = chemin_image('del-16.png');
290 290
 	  $titre = _T('titre_image_redacteur');
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
 	}
295 295
 	*/
296 296
 
297
-	return http_img_pack($img, $alt, $fond, $alt);
297
+    return http_img_pack($img, $alt, $fond, $alt);
298 298
 }
299 299
 
300 300
 
301 301
 function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
302
-	return http_img_pack('rubrique-16.png', '');
302
+    return http_img_pack('rubrique-16.png', '');
303 303
 }
304 304
 
305 305
 /**
@@ -323,110 +323,110 @@  discard block
 block discarded – undo
323 323
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
324 324
  **/
325 325
 function puce_statut_changement_rapide(
326
-	$id,
327
-	$statut,
328
-	$id_rubrique,
329
-	$type = 'article',
330
-	$ajax = false,
331
-	$menu_rapide = _ACTIVER_PUCE_RAPIDE
326
+    $id,
327
+    $statut,
328
+    $id_rubrique,
329
+    $type = 'article',
330
+    $ajax = false,
331
+    $menu_rapide = _ACTIVER_PUCE_RAPIDE
332 332
 ) {
333
-	$src = statut_image($type, $statut);
334
-	if (!$src) {
335
-		return $src;
336
-	}
337
-
338
-	if (
339
-		!$id
340
-		or !_SPIP_AJAX
341
-		or !$menu_rapide
342
-	) {
343
-		$ajax_node = '';
344
-	} else {
345
-		$ajax_node = " class='imgstatut$type$id'";
346
-	}
347
-
348
-
349
-	$t = statut_titre($type, $statut);
350
-	$inser_puce = http_img_pack($src, $t, $ajax_node, $t);
351
-
352
-	if (!$ajax_node) {
353
-		return $inser_puce;
354
-	}
355
-
356
-	$table = table_objet_sql($type);
357
-	$desc = lister_tables_objets_sql($table);
358
-	if (!isset($desc['statut_textes_instituer'])) {
359
-		return $inser_puce;
360
-	}
361
-
362
-	if (!function_exists('autoriser')) {
363
-		include_spip('inc/autoriser');
364
-	}
365
-
366
-	// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
367
-	if ($id_rubrique) {
368
-		if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
369
-			return $inser_puce;
370
-		}
371
-	} // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
372
-	else {
373
-		if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) {
374
-			return $inser_puce;
375
-		}
376
-	}
377
-
378
-	$coord = array_flip(array_keys($desc['statut_textes_instituer']));
379
-	if (!isset($coord[$statut])) {
380
-		return $inser_puce;
381
-	}
382
-
383
-	$unit = 18/*widh de img*/ + 0/*padding*/
384
-	;
385
-	$margin = 0; /* marge a gauche + droite */
386
-	$zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/
387
-	;
388
-	$clip = $zero + ($unit * $coord[$statut]);
389
-
390
-	if ($ajax) {
391
-		$width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin;
392
-		$out = "<span class='puce_objet_fixe $type'>"
393
-			. $inser_puce
394
-			. '</span>'
395
-			. "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
396
-		$i = 0;
397
-		foreach ($desc['statut_textes_instituer'] as $s => $t) {
398
-			$out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
399
-		}
400
-		$out .= '</span>';
401
-
402
-		return $out;
403
-	} else {
404
-		$nom = 'puce_statut_';
405
-		$action = generer_url_ecrire('puce_statut', '', true);
406
-		$lang_dir = lang_dir(lang_typo());
407
-
408
-		return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>"
409
-		. $inser_puce
410
-		. '</span>';
411
-	}
333
+    $src = statut_image($type, $statut);
334
+    if (!$src) {
335
+        return $src;
336
+    }
337
+
338
+    if (
339
+        !$id
340
+        or !_SPIP_AJAX
341
+        or !$menu_rapide
342
+    ) {
343
+        $ajax_node = '';
344
+    } else {
345
+        $ajax_node = " class='imgstatut$type$id'";
346
+    }
347
+
348
+
349
+    $t = statut_titre($type, $statut);
350
+    $inser_puce = http_img_pack($src, $t, $ajax_node, $t);
351
+
352
+    if (!$ajax_node) {
353
+        return $inser_puce;
354
+    }
355
+
356
+    $table = table_objet_sql($type);
357
+    $desc = lister_tables_objets_sql($table);
358
+    if (!isset($desc['statut_textes_instituer'])) {
359
+        return $inser_puce;
360
+    }
361
+
362
+    if (!function_exists('autoriser')) {
363
+        include_spip('inc/autoriser');
364
+    }
365
+
366
+    // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
367
+    if ($id_rubrique) {
368
+        if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
369
+            return $inser_puce;
370
+        }
371
+    } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
372
+    else {
373
+        if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) {
374
+            return $inser_puce;
375
+        }
376
+    }
377
+
378
+    $coord = array_flip(array_keys($desc['statut_textes_instituer']));
379
+    if (!isset($coord[$statut])) {
380
+        return $inser_puce;
381
+    }
382
+
383
+    $unit = 18/*widh de img*/ + 0/*padding*/
384
+    ;
385
+    $margin = 0; /* marge a gauche + droite */
386
+    $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/
387
+    ;
388
+    $clip = $zero + ($unit * $coord[$statut]);
389
+
390
+    if ($ajax) {
391
+        $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin;
392
+        $out = "<span class='puce_objet_fixe $type'>"
393
+            . $inser_puce
394
+            . '</span>'
395
+            . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
396
+        $i = 0;
397
+        foreach ($desc['statut_textes_instituer'] as $s => $t) {
398
+            $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
399
+        }
400
+        $out .= '</span>';
401
+
402
+        return $out;
403
+    } else {
404
+        $nom = 'puce_statut_';
405
+        $action = generer_url_ecrire('puce_statut', '', true);
406
+        $lang_dir = lang_dir(lang_typo());
407
+
408
+        return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>"
409
+        . $inser_puce
410
+        . '</span>';
411
+    }
412 412
 }
413 413
 
414 414
 
415 415
 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
416
-	$h = generer_action_auteur('instituer_objet', "$type-$id-$statut");
417
-	$t = supprimer_tags($titre);
416
+    $h = generer_action_auteur('instituer_objet', "$type-$id-$statut");
417
+    $t = supprimer_tags($titre);
418 418
 
419
-	return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>';
419
+    return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>';
420 420
 }
421 421
 
422 422
 // compat
423 423
 // La couleur du statut
424 424
 
425 425
 function puce_statut($statut, $atts = '') {
426
-	$src = statut_image('article', $statut);
427
-	if (!$src) {
428
-		return '';
429
-	}
426
+    $src = statut_image('article', $statut);
427
+    if (!$src) {
428
+        return '';
429
+    }
430 430
 
431
-	return http_img_pack($src, statut_titre('article', $statut), $atts);
431
+    return http_img_pack($src, statut_titre('article', $statut), $atts);
432 432
 }
Please login to merge, or discard this patch.
ecrire/inc/rubriques.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,8 +77,7 @@
 block discarded – undo
77 77
 				break; // stop on a trouvé le bon champ
78 78
 			}
79 79
 		}
80
-	}
81
-	else {
80
+	} else {
82 81
 		$statuts_publies = ['publie'];
83 82
 	}
84 83
 
Please login to merge, or discard this patch.
Indentation   +621 added lines, -621 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -54,65 +54,65 @@  discard block
 block discarded – undo
54 54
  *     true si le statut change effectivement
55 55
  **/
56 56
 function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) {
57
-	$statuts_publies = null;
58
-	$neuf = false;
59
-
60
-	// Compat avec l'ancienne signature
61
-	if (is_string($infos)) {
62
-		$infos = ['statut_ancien' => $infos];
63
-	}
64
-	if (!isset($infos['statut_ancien'])) {
65
-		$infos['statut_ancien'] = '';
66
-	}
67
-
68
-	// On recherche quels statuts tester
69
-	if (
70
-		isset($infos['objet'])
71
-		and include_spip('inc/filtres')
72
-		and $declaration_statut = objet_info($infos['objet'], 'statut')
73
-		and is_array($declaration_statut)
74
-	) {
75
-		foreach ($declaration_statut as $champ_statut) {
76
-			if ($champ_statut['champ'] == 'statut') {
77
-				$statuts_publies = array_map('trim', explode(',', $champ_statut['publie']));
78
-				break; // stop on a trouvé le bon champ
79
-			}
80
-		}
81
-	}
82
-	else {
83
-		$statuts_publies = ['publie'];
84
-	}
85
-
86
-	if (in_array($infos['statut_ancien'], $statuts_publies)) {
87
-		if (
88
-			isset($modifs['statut'])
89
-			or isset($modifs['id_rubrique'])
90
-			or ($postdate and strtotime($postdate) > time())
91
-		) {
92
-			$neuf |= depublier_branche_rubrique_if($id_rubrique);
93
-		}
94
-		// ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
95
-		if ($postdate) {
96
-			calculer_prochain_postdate(true);
97
-			$neuf |= (strtotime($postdate) <= time()); // par securite
98
-		} elseif (isset($modifs['id_rubrique'])) {
99
-			$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
100
-		}
101
-	} elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) {
102
-		if ($postdate) {
103
-			calculer_prochain_postdate(true);
104
-			$neuf |= (strtotime($postdate) <= time()); // par securite
105
-		} else {
106
-			$neuf |= publier_branche_rubrique($id_rubrique);
107
-		}
108
-	}
109
-
110
-	if ($neuf) { // Sauver la date de la derniere mise a jour (pour menu_rubriques)
111
-	ecrire_meta('date_calcul_rubriques', date('U'));
112
-	}
113
-
114
-	$langues = calculer_langues_utilisees();
115
-	ecrire_meta('langues_utilisees', $langues);
57
+    $statuts_publies = null;
58
+    $neuf = false;
59
+
60
+    // Compat avec l'ancienne signature
61
+    if (is_string($infos)) {
62
+        $infos = ['statut_ancien' => $infos];
63
+    }
64
+    if (!isset($infos['statut_ancien'])) {
65
+        $infos['statut_ancien'] = '';
66
+    }
67
+
68
+    // On recherche quels statuts tester
69
+    if (
70
+        isset($infos['objet'])
71
+        and include_spip('inc/filtres')
72
+        and $declaration_statut = objet_info($infos['objet'], 'statut')
73
+        and is_array($declaration_statut)
74
+    ) {
75
+        foreach ($declaration_statut as $champ_statut) {
76
+            if ($champ_statut['champ'] == 'statut') {
77
+                $statuts_publies = array_map('trim', explode(',', $champ_statut['publie']));
78
+                break; // stop on a trouvé le bon champ
79
+            }
80
+        }
81
+    }
82
+    else {
83
+        $statuts_publies = ['publie'];
84
+    }
85
+
86
+    if (in_array($infos['statut_ancien'], $statuts_publies)) {
87
+        if (
88
+            isset($modifs['statut'])
89
+            or isset($modifs['id_rubrique'])
90
+            or ($postdate and strtotime($postdate) > time())
91
+        ) {
92
+            $neuf |= depublier_branche_rubrique_if($id_rubrique);
93
+        }
94
+        // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
95
+        if ($postdate) {
96
+            calculer_prochain_postdate(true);
97
+            $neuf |= (strtotime($postdate) <= time()); // par securite
98
+        } elseif (isset($modifs['id_rubrique'])) {
99
+            $neuf |= publier_branche_rubrique($modifs['id_rubrique']);
100
+        }
101
+    } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) {
102
+        if ($postdate) {
103
+            calculer_prochain_postdate(true);
104
+            $neuf |= (strtotime($postdate) <= time()); // par securite
105
+        } else {
106
+            $neuf |= publier_branche_rubrique($id_rubrique);
107
+        }
108
+    }
109
+
110
+    if ($neuf) { // Sauver la date de la derniere mise a jour (pour menu_rubriques)
111
+    ecrire_meta('date_calcul_rubriques', date('U'));
112
+    }
113
+
114
+    $langues = calculer_langues_utilisees();
115
+    ecrire_meta('langues_utilisees', $langues);
116 116
 }
117 117
 
118 118
 
@@ -130,22 +130,22 @@  discard block
 block discarded – undo
130 130
  *     true si le statut change effectivement
131 131
  */
132 132
 function publier_branche_rubrique($id_rubrique) {
133
-	$id_pred = $id_rubrique;
134
-	while (true) {
135
-		sql_updateq(
136
-			'spip_rubriques',
137
-			['statut' => 'publie', 'date' => date('Y-m-d H:i:s')],
138
-			'id_rubrique=' . intval($id_rubrique)
139
-		);
140
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique));
141
-		if (!$id_parent) {
142
-			break;
143
-		}
144
-		$id_rubrique = $id_parent;
145
-	}
133
+    $id_pred = $id_rubrique;
134
+    while (true) {
135
+        sql_updateq(
136
+            'spip_rubriques',
137
+            ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')],
138
+            'id_rubrique=' . intval($id_rubrique)
139
+        );
140
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique));
141
+        if (!$id_parent) {
142
+            break;
143
+        }
144
+        $id_rubrique = $id_parent;
145
+    }
146 146
 
147 147
 #	spip_log(" publier_branche_rubrique($id_rubrique $id_pred");
148
-	return $id_pred != $id_rubrique;
148
+    return $id_pred != $id_rubrique;
149 149
 }
150 150
 
151 151
 /**
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
  *     true si le statut change effectivement
164 164
  */
165 165
 function depublier_branche_rubrique_if($id_rubrique) {
166
-	$date = date('Y-m-d H:i:s'); // figer la date
167
-
168
-	#	spip_log("depublier_branche_rubrique($id_rubrique ?");
169
-	$id_pred = $id_rubrique;
170
-	while ($id_pred) {
171
-		if (!depublier_rubrique_if($id_pred, $date)) {
172
-			return $id_pred != $id_rubrique;
173
-		}
174
-		// passer au parent si on a depublie
175
-		$r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred));
176
-		$id_pred = $r['id_parent'];
177
-	}
178
-
179
-	return $id_pred != $id_rubrique;
166
+    $date = date('Y-m-d H:i:s'); // figer la date
167
+
168
+    #	spip_log("depublier_branche_rubrique($id_rubrique ?");
169
+    $id_pred = $id_rubrique;
170
+    while ($id_pred) {
171
+        if (!depublier_rubrique_if($id_pred, $date)) {
172
+            return $id_pred != $id_rubrique;
173
+        }
174
+        // passer au parent si on a depublie
175
+        $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred));
176
+        $id_pred = $r['id_parent'];
177
+    }
178
+
179
+    return $id_pred != $id_rubrique;
180 180
 }
181 181
 
182 182
 /**
@@ -193,61 +193,61 @@  discard block
 block discarded – undo
193 193
  *    true si la rubrique a été dépubliée
194 194
  */
195 195
 function depublier_rubrique_if($id_rubrique, $date = null) {
196
-	if (is_null($date)) {
197
-		$date = date('Y-m-d H:i:s');
198
-	}
199
-	$postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
200
-		' AND date <= ' . sql_quote($date) : '';
201
-
202
-	if (!$id_rubrique = intval($id_rubrique)) {
203
-		return false;
204
-	}
205
-
206
-	// verifier qu'elle existe et est bien publiee
207
-	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
208
-	if (!$r or $r['statut'] !== 'publie') {
209
-		return false;
210
-	}
211
-
212
-	// On met le nombre de chaque type d'enfants dans un tableau
213
-	// Le type de l'objet est au pluriel
214
-	$compte = [
215
-		'articles' => sql_countsel(
216
-			'spip_articles',
217
-			'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates"
218
-		),
219
-		'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"),
220
-		'documents' => sql_countsel(
221
-			'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document',
222
-			'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') "
223
-		)
224
-	];
225
-
226
-	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
227
-	$compte = pipeline(
228
-		'objet_compte_enfants',
229
-		[
230
-			'args' => [
231
-				'objet' => 'rubrique',
232
-				'id_objet' => $id_rubrique,
233
-				'statut' => 'publie',
234
-				'date' => $date
235
-			],
236
-			'data' => $compte
237
-		]
238
-	);
239
-
240
-	// S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
241
-	foreach ($compte as $objet => $n) {
242
-		if ($n) {
243
-			return false;
244
-		}
245
-	}
246
-
247
-	sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique));
196
+    if (is_null($date)) {
197
+        $date = date('Y-m-d H:i:s');
198
+    }
199
+    $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
200
+        ' AND date <= ' . sql_quote($date) : '';
201
+
202
+    if (!$id_rubrique = intval($id_rubrique)) {
203
+        return false;
204
+    }
205
+
206
+    // verifier qu'elle existe et est bien publiee
207
+    $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
208
+    if (!$r or $r['statut'] !== 'publie') {
209
+        return false;
210
+    }
211
+
212
+    // On met le nombre de chaque type d'enfants dans un tableau
213
+    // Le type de l'objet est au pluriel
214
+    $compte = [
215
+        'articles' => sql_countsel(
216
+            'spip_articles',
217
+            'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates"
218
+        ),
219
+        'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"),
220
+        'documents' => sql_countsel(
221
+            'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document',
222
+            'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') "
223
+        )
224
+    ];
225
+
226
+    // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
227
+    $compte = pipeline(
228
+        'objet_compte_enfants',
229
+        [
230
+            'args' => [
231
+                'objet' => 'rubrique',
232
+                'id_objet' => $id_rubrique,
233
+                'statut' => 'publie',
234
+                'date' => $date
235
+            ],
236
+            'data' => $compte
237
+        ]
238
+    );
239
+
240
+    // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
241
+    foreach ($compte as $objet => $n) {
242
+        if ($n) {
243
+            return false;
244
+        }
245
+    }
246
+
247
+    sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique));
248 248
 
249 249
 #		spip_log("depublier_rubrique $id_pred");
250
-	return true;
250
+    return true;
251 251
 }
252 252
 
253 253
 
@@ -270,18 +270,18 @@  discard block
 block discarded – undo
270 270
  **/
271 271
 function calculer_rubriques() {
272 272
 
273
-	calculer_rubriques_publiees();
273
+    calculer_rubriques_publiees();
274 274
 
275
-	// Apres chaque (de)publication
276
-	// recalculer les langues utilisees sur le site
277
-	$langues = calculer_langues_utilisees();
278
-	ecrire_meta('langues_utilisees', $langues);
275
+    // Apres chaque (de)publication
276
+    // recalculer les langues utilisees sur le site
277
+    $langues = calculer_langues_utilisees();
278
+    ecrire_meta('langues_utilisees', $langues);
279 279
 
280
-	// Sauver la date de la derniere mise a jour (pour menu_rubriques)
281
-	ecrire_meta('date_calcul_rubriques', date('U'));
280
+    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
281
+    ecrire_meta('date_calcul_rubriques', date('U'));
282 282
 
283
-	// on calcule la date du prochain article post-date
284
-	calculer_prochain_postdate();
283
+    // on calcule la date du prochain article post-date
284
+    calculer_prochain_postdate();
285 285
 }
286 286
 
287 287
 
@@ -298,61 +298,61 @@  discard block
 block discarded – undo
298 298
  **/
299 299
 function calculer_rubriques_publiees() {
300 300
 
301
-	// Mettre les compteurs a zero
302
-	sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']);
303
-
304
-	//
305
-	// Publier et dater les rubriques qui ont un article publie
306
-	//
307
-
308
-	// Afficher les articles post-dates ?
309
-	$postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
310
-		'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : '';
311
-
312
-	$r = sql_select(
313
-		'R.id_rubrique AS id, max(A.date) AS date_h',
314
-		'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique',
315
-		"A.date>R.date_tmp AND A.statut='publie' $postdates ",
316
-		'R.id_rubrique'
317
-	);
318
-	while ($row = sql_fetch($r)) {
319
-		sql_updateq(
320
-			'spip_rubriques',
321
-			['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']],
322
-			'id_rubrique=' . intval($row['id'])
323
-		);
324
-	}
325
-
326
-	// point d'entree pour permettre a des plugins de gerer le statut
327
-	// autrement (par ex: toute rubrique est publiee des sa creation)
328
-	// Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
329
-	// c'est statut_tmp/date_tmp qu'il doit modifier
330
-	// [C'est un trigger... a renommer en trig_calculer_rubriques ?]
331
-	pipeline('calculer_rubriques', null);
332
-
333
-
334
-	// Les rubriques qui ont une rubrique fille plus recente
335
-	// on tourne tant que les donnees remontent vers la racine.
336
-	do {
337
-		$continuer = false;
338
-		$r = sql_select(
339
-			'R.id_rubrique AS id, max(SR.date_tmp) AS date_h',
340
-			'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent',
341
-			"(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ",
342
-			'R.id_rubrique'
343
-		);
344
-		while ($row = sql_fetch($r)) {
345
-			sql_updateq(
346
-				'spip_rubriques',
347
-				['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']],
348
-				'id_rubrique=' . intval($row['id'])
349
-			);
350
-			$continuer = true;
351
-		}
352
-	} while ($continuer);
353
-
354
-	// Enregistrement des modifs
355
-	sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']);
301
+    // Mettre les compteurs a zero
302
+    sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']);
303
+
304
+    //
305
+    // Publier et dater les rubriques qui ont un article publie
306
+    //
307
+
308
+    // Afficher les articles post-dates ?
309
+    $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
310
+        'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : '';
311
+
312
+    $r = sql_select(
313
+        'R.id_rubrique AS id, max(A.date) AS date_h',
314
+        'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique',
315
+        "A.date>R.date_tmp AND A.statut='publie' $postdates ",
316
+        'R.id_rubrique'
317
+    );
318
+    while ($row = sql_fetch($r)) {
319
+        sql_updateq(
320
+            'spip_rubriques',
321
+            ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']],
322
+            'id_rubrique=' . intval($row['id'])
323
+        );
324
+    }
325
+
326
+    // point d'entree pour permettre a des plugins de gerer le statut
327
+    // autrement (par ex: toute rubrique est publiee des sa creation)
328
+    // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
329
+    // c'est statut_tmp/date_tmp qu'il doit modifier
330
+    // [C'est un trigger... a renommer en trig_calculer_rubriques ?]
331
+    pipeline('calculer_rubriques', null);
332
+
333
+
334
+    // Les rubriques qui ont une rubrique fille plus recente
335
+    // on tourne tant que les donnees remontent vers la racine.
336
+    do {
337
+        $continuer = false;
338
+        $r = sql_select(
339
+            'R.id_rubrique AS id, max(SR.date_tmp) AS date_h',
340
+            'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent',
341
+            "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ",
342
+            'R.id_rubrique'
343
+        );
344
+        while ($row = sql_fetch($r)) {
345
+            sql_updateq(
346
+                'spip_rubriques',
347
+                ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']],
348
+                'id_rubrique=' . intval($row['id'])
349
+            );
350
+            $continuer = true;
351
+        }
352
+    } while ($continuer);
353
+
354
+    // Enregistrement des modifs
355
+    sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']);
356 356
 }
357 357
 
358 358
 /**
@@ -367,123 +367,123 @@  discard block
 block discarded – undo
367 367
  * @return void
368 368
  **/
369 369
 function propager_les_secteurs() {
370
-	// Profondeur 0
371
-	// Toutes les rubriques racines sont de profondeur 0
372
-	// et fixer les id_secteur des rubriques racines
373
-	sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0');
374
-	// Toute rubrique non racine est de profondeur >0
375
-	sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0');
376
-
377
-	// securite : pas plus d'iteration que de rubriques dans la base
378
-	$maxiter = sql_countsel('spip_rubriques');
379
-
380
-	// reparer les rubriques qui n'ont pas l'id_secteur de leur parent
381
-	// on fait profondeur par profondeur
382
-
383
-	$prof = 0;
384
-	do {
385
-		$continuer = false;
386
-
387
-		// Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
388
-		// on fixe le profondeur $prof+1
389
-
390
-		// Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
391
-		// on teste A.profondeur > $prof+1 car :
392
-		// - toutes les rubriques de profondeur 0 à $prof sont bonnes
393
-		// - si A.profondeur = $prof+1 c'est bon
394
-		// - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
395
-		$maxiter2 = $maxiter;
396
-		while (
397
-			$maxiter2--
398
-			and $rows = sql_allfetsel(
399
-				'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur',
400
-				'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique',
401
-				'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)',
402
-				'',
403
-				'R.id_secteur',
404
-				'0,100'
405
-			)
406
-		) {
407
-			$id_secteur = null;
408
-			$ids = [];
409
-			while ($row = array_shift($rows)) {
410
-				if ($row['id_secteur'] !== $id_secteur) {
411
-					if (count($ids)) {
412
-						sql_updateq(
413
-							'spip_rubriques',
414
-							['id_secteur' => $id_secteur, 'profondeur' => $prof + 1],
415
-							sql_in('id_rubrique', $ids)
416
-						);
417
-					}
418
-					$id_secteur = $row['id_secteur'];
419
-					$ids = [];
420
-				}
421
-				$ids[] = $row['id'];
422
-			}
423
-			if (count($ids)) {
424
-				sql_updateq(
425
-					'spip_rubriques',
426
-					['id_secteur' => $id_secteur, 'profondeur' => $prof + 1],
427
-					sql_in('id_rubrique', $ids)
428
-				);
429
-			}
430
-		}
431
-
432
-
433
-		// Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
434
-		$maxiter2 = $maxiter;
435
-		while (
436
-			$maxiter2--
437
-			and $rows = sql_allfetsel(
438
-				'id_rubrique as id',
439
-				'spip_rubriques',
440
-				'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select(
441
-					'zzz.id_rubrique',
442
-					'spip_rubriques AS zzz',
443
-					'zzz.profondeur=' . intval($prof)
444
-				) . ')',
445
-				'',
446
-				'',
447
-				'0,100'
448
-			)
449
-		) {
450
-			$rows = array_column($rows, 'id');
451
-			sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows));
452
-		}
453
-
454
-		// ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
455
-		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
456
-		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
457
-		// on arrete les frais
458
-		if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) {
459
-			$prof++;
460
-			$continuer = true;
461
-		}
462
-	} while ($continuer and $maxiter--);
463
-
464
-	// loger si la table des rubriques semble foireuse
465
-	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
466
-	if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) {
467
-		spip_log(
468
-			'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)',
469
-			_LOG_CRITIQUE
470
-		);
471
-		sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1));
472
-	}
473
-
474
-	// reparer les articles
475
-	$r = sql_select(
476
-		'A.id_article AS id, R.id_secteur AS secteur',
477
-		'spip_articles AS A, spip_rubriques AS R',
478
-		'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur'
479
-	);
480
-
481
-	while ($row = sql_fetch($r)) {
482
-		sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id']));
483
-	}
484
-
485
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
486
-	pipeline('trig_propager_les_secteurs', '');
370
+    // Profondeur 0
371
+    // Toutes les rubriques racines sont de profondeur 0
372
+    // et fixer les id_secteur des rubriques racines
373
+    sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0');
374
+    // Toute rubrique non racine est de profondeur >0
375
+    sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0');
376
+
377
+    // securite : pas plus d'iteration que de rubriques dans la base
378
+    $maxiter = sql_countsel('spip_rubriques');
379
+
380
+    // reparer les rubriques qui n'ont pas l'id_secteur de leur parent
381
+    // on fait profondeur par profondeur
382
+
383
+    $prof = 0;
384
+    do {
385
+        $continuer = false;
386
+
387
+        // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
388
+        // on fixe le profondeur $prof+1
389
+
390
+        // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
391
+        // on teste A.profondeur > $prof+1 car :
392
+        // - toutes les rubriques de profondeur 0 à $prof sont bonnes
393
+        // - si A.profondeur = $prof+1 c'est bon
394
+        // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
395
+        $maxiter2 = $maxiter;
396
+        while (
397
+            $maxiter2--
398
+            and $rows = sql_allfetsel(
399
+                'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur',
400
+                'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique',
401
+                'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)',
402
+                '',
403
+                'R.id_secteur',
404
+                '0,100'
405
+            )
406
+        ) {
407
+            $id_secteur = null;
408
+            $ids = [];
409
+            while ($row = array_shift($rows)) {
410
+                if ($row['id_secteur'] !== $id_secteur) {
411
+                    if (count($ids)) {
412
+                        sql_updateq(
413
+                            'spip_rubriques',
414
+                            ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1],
415
+                            sql_in('id_rubrique', $ids)
416
+                        );
417
+                    }
418
+                    $id_secteur = $row['id_secteur'];
419
+                    $ids = [];
420
+                }
421
+                $ids[] = $row['id'];
422
+            }
423
+            if (count($ids)) {
424
+                sql_updateq(
425
+                    'spip_rubriques',
426
+                    ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1],
427
+                    sql_in('id_rubrique', $ids)
428
+                );
429
+            }
430
+        }
431
+
432
+
433
+        // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
434
+        $maxiter2 = $maxiter;
435
+        while (
436
+            $maxiter2--
437
+            and $rows = sql_allfetsel(
438
+                'id_rubrique as id',
439
+                'spip_rubriques',
440
+                'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select(
441
+                    'zzz.id_rubrique',
442
+                    'spip_rubriques AS zzz',
443
+                    'zzz.profondeur=' . intval($prof)
444
+                ) . ')',
445
+                '',
446
+                '',
447
+                '0,100'
448
+            )
449
+        ) {
450
+            $rows = array_column($rows, 'id');
451
+            sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows));
452
+        }
453
+
454
+        // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
455
+        // si pas de rubrique a profondeur $prof+1 pas la peine de continuer
456
+        // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
457
+        // on arrete les frais
458
+        if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) {
459
+            $prof++;
460
+            $continuer = true;
461
+        }
462
+    } while ($continuer and $maxiter--);
463
+
464
+    // loger si la table des rubriques semble foireuse
465
+    // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
466
+    if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) {
467
+        spip_log(
468
+            'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)',
469
+            _LOG_CRITIQUE
470
+        );
471
+        sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1));
472
+    }
473
+
474
+    // reparer les articles
475
+    $r = sql_select(
476
+        'A.id_article AS id, R.id_secteur AS secteur',
477
+        'spip_articles AS A, spip_rubriques AS R',
478
+        'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur'
479
+    );
480
+
481
+    while ($row = sql_fetch($r)) {
482
+        sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id']));
483
+    }
484
+
485
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
486
+    pipeline('trig_propager_les_secteurs', '');
487 487
 }
488 488
 
489 489
 
@@ -498,23 +498,23 @@  discard block
 block discarded – undo
498 498
  *     true si un changement a eu lieu
499 499
  **/
500 500
 function calculer_langues_rubriques_etape() {
501
-	$s = sql_select(
502
-		'A.id_rubrique AS id_rubrique, R.lang AS lang',
503
-		'spip_rubriques AS A, spip_rubriques AS R',
504
-		"A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"
505
-	);
506
-
507
-	$t = false;
508
-	while ($row = sql_fetch($s)) {
509
-		$id_rubrique = $row['id_rubrique'];
510
-		$t = sql_updateq(
511
-			'spip_rubriques',
512
-			['lang' => $row['lang'], 'langue_choisie' => 'non'],
513
-			'id_rubrique=' . intval($id_rubrique)
514
-		);
515
-	}
516
-
517
-	return $t;
501
+    $s = sql_select(
502
+        'A.id_rubrique AS id_rubrique, R.lang AS lang',
503
+        'spip_rubriques AS A, spip_rubriques AS R',
504
+        "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang"
505
+    );
506
+
507
+    $t = false;
508
+    while ($row = sql_fetch($s)) {
509
+        $id_rubrique = $row['id_rubrique'];
510
+        $t = sql_updateq(
511
+            'spip_rubriques',
512
+            ['lang' => $row['lang'], 'langue_choisie' => 'non'],
513
+            'id_rubrique=' . intval($id_rubrique)
514
+        );
515
+    }
516
+
517
+    return $t;
518 518
 }
519 519
 
520 520
 /**
@@ -534,38 +534,38 @@  discard block
 block discarded – undo
534 534
  **/
535 535
 function calculer_langues_rubriques() {
536 536
 
537
-	// rubriques (recursivite)
538
-	sql_updateq(
539
-		'spip_rubriques',
540
-		['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'],
541
-		"id_parent=0 AND langue_choisie != 'oui'"
542
-	);
543
-	while (calculer_langues_rubriques_etape()) {
544
-		;
545
-	}
546
-
547
-	// articles
548
-	$s = sql_select(
549
-		'A.id_article AS id_article, R.lang AS lang',
550
-		'spip_articles AS A, spip_rubriques AS R',
551
-		"A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"
552
-	);
553
-	while ($row = sql_fetch($s)) {
554
-		$id_article = $row['id_article'];
555
-		sql_updateq(
556
-			'spip_articles',
557
-			['lang' => $row['lang'], 'langue_choisie' => 'non'],
558
-			'id_article=' . intval($id_article)
559
-		);
560
-	}
561
-
562
-	if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
563
-		$langues = calculer_langues_utilisees();
564
-		ecrire_meta('langues_utilisees', $langues);
565
-	}
566
-
567
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
568
-	pipeline('trig_calculer_langues_rubriques', '');
537
+    // rubriques (recursivite)
538
+    sql_updateq(
539
+        'spip_rubriques',
540
+        ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'],
541
+        "id_parent=0 AND langue_choisie != 'oui'"
542
+    );
543
+    while (calculer_langues_rubriques_etape()) {
544
+        ;
545
+    }
546
+
547
+    // articles
548
+    $s = sql_select(
549
+        'A.id_article AS id_article, R.lang AS lang',
550
+        'spip_articles AS A, spip_rubriques AS R',
551
+        "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang"
552
+    );
553
+    while ($row = sql_fetch($s)) {
554
+        $id_article = $row['id_article'];
555
+        sql_updateq(
556
+            'spip_articles',
557
+            ['lang' => $row['lang'], 'langue_choisie' => 'non'],
558
+            'id_article=' . intval($id_article)
559
+        );
560
+    }
561
+
562
+    if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
563
+        $langues = calculer_langues_utilisees();
564
+        ecrire_meta('langues_utilisees', $langues);
565
+    }
566
+
567
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
568
+    pipeline('trig_calculer_langues_rubriques', '');
569 569
 }
570 570
 
571 571
 
@@ -582,80 +582,80 @@  discard block
 block discarded – undo
582 582
  *    Liste des langues utilisées séparées par des virgules
583 583
  **/
584 584
 function calculer_langues_utilisees($serveur = '') {
585
-	include_spip('public/interfaces');
586
-	include_spip('public/compiler');
587
-	include_spip('public/composer');
588
-	include_spip('public/phraser_html');
589
-	$langues = [];
590
-
591
-	$langues[$GLOBALS['meta']['langue_site']] = 1;
592
-
593
-	include_spip('base/objets');
594
-	$tables = lister_tables_objets_sql();
595
-	$trouver_table = charger_fonction('trouver_table', 'base');
596
-
597
-	foreach (array_keys($tables) as $t) {
598
-		$desc = $trouver_table($t, $serveur);
599
-		// c'est une table avec des langues
600
-		if (
601
-			$desc['exist']
602
-			and isset($desc['field']['lang'])
603
-			and isset($desc['field']['langue_choisie'])
604
-		) {
605
-			$boucle = new Boucle();
606
-			$boucle->show = $desc;
607
-			$boucle->nom = 'calculer_langues_utilisees';
608
-			$boucle->id_boucle = $desc['table_objet'];
609
-			$boucle->id_table = $desc['table_objet'];
610
-			$boucle->primary = $desc['key']['PRIMARY KEY'] ?? '';
611
-			$boucle->sql_serveur = $serveur;
612
-			$boucle->select[] = 'DISTINCT lang';
613
-			$boucle->from[$desc['table_objet']] = $t;
614
-			$boucle->separateur[] = ',';
615
-			$boucle->return = '$Pile[$SP][\'lang\']';
616
-			$boucle->iterateur = 'sql';
617
-
618
-			$boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php
619
-			$boucle->descr['sourcefile'] = 'internal';
620
-			$boucle->descr['gram'] = 'html';
621
-
622
-			$boucle = pipeline('pre_boucle', $boucle);
623
-
624
-			if (
625
-				isset($desc['statut'])
626
-				and $desc['statut']
627
-			) {
628
-				$boucles = [
629
-					'calculer_langues_utilisees' => $boucle,
630
-				];
631
-				// generer un nom de fonction "anonyme" unique
632
-				do {
633
-					$functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax());
634
-				} while (function_exists($functionname));
635
-				$code = calculer_boucle('calculer_langues_utilisees', $boucles);
636
-				$code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
637
-				$code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
638
-				$res = '';
639
-				eval($code);
640
-				$res = explode(',', $res);
641
-				foreach ($res as $lang) {
642
-					$langues[$lang] = 1;
643
-				}
644
-			} else {
645
-				$res = sql_select(implode(',', $boucle->select), $boucle->from);
646
-				while ($row = sql_fetch($res)) {
647
-					$langues[$row['lang']] = 1;
648
-				}
649
-			}
650
-		}
651
-	}
652
-
653
-	$langues = array_filter(array_keys($langues));
654
-	sort($langues);
655
-	$langues = join(',', $langues);
656
-	spip_log("langues utilisees: $langues");
657
-
658
-	return $langues;
585
+    include_spip('public/interfaces');
586
+    include_spip('public/compiler');
587
+    include_spip('public/composer');
588
+    include_spip('public/phraser_html');
589
+    $langues = [];
590
+
591
+    $langues[$GLOBALS['meta']['langue_site']] = 1;
592
+
593
+    include_spip('base/objets');
594
+    $tables = lister_tables_objets_sql();
595
+    $trouver_table = charger_fonction('trouver_table', 'base');
596
+
597
+    foreach (array_keys($tables) as $t) {
598
+        $desc = $trouver_table($t, $serveur);
599
+        // c'est une table avec des langues
600
+        if (
601
+            $desc['exist']
602
+            and isset($desc['field']['lang'])
603
+            and isset($desc['field']['langue_choisie'])
604
+        ) {
605
+            $boucle = new Boucle();
606
+            $boucle->show = $desc;
607
+            $boucle->nom = 'calculer_langues_utilisees';
608
+            $boucle->id_boucle = $desc['table_objet'];
609
+            $boucle->id_table = $desc['table_objet'];
610
+            $boucle->primary = $desc['key']['PRIMARY KEY'] ?? '';
611
+            $boucle->sql_serveur = $serveur;
612
+            $boucle->select[] = 'DISTINCT lang';
613
+            $boucle->from[$desc['table_objet']] = $t;
614
+            $boucle->separateur[] = ',';
615
+            $boucle->return = '$Pile[$SP][\'lang\']';
616
+            $boucle->iterateur = 'sql';
617
+
618
+            $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php
619
+            $boucle->descr['sourcefile'] = 'internal';
620
+            $boucle->descr['gram'] = 'html';
621
+
622
+            $boucle = pipeline('pre_boucle', $boucle);
623
+
624
+            if (
625
+                isset($desc['statut'])
626
+                and $desc['statut']
627
+            ) {
628
+                $boucles = [
629
+                    'calculer_langues_utilisees' => $boucle,
630
+                ];
631
+                // generer un nom de fonction "anonyme" unique
632
+                do {
633
+                    $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax());
634
+                } while (function_exists($functionname));
635
+                $code = calculer_boucle('calculer_langues_utilisees', $boucles);
636
+                $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
637
+                $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
638
+                $res = '';
639
+                eval($code);
640
+                $res = explode(',', $res);
641
+                foreach ($res as $lang) {
642
+                    $langues[$lang] = 1;
643
+                }
644
+            } else {
645
+                $res = sql_select(implode(',', $boucle->select), $boucle->from);
646
+                while ($row = sql_fetch($res)) {
647
+                    $langues[$row['lang']] = 1;
648
+                }
649
+            }
650
+        }
651
+    }
652
+
653
+    $langues = array_filter(array_keys($langues));
654
+    sort($langues);
655
+    $langues = join(',', $langues);
656
+    spip_log("langues utilisees: $langues");
657
+
658
+    return $langues;
659 659
 }
660 660
 
661 661
 /**
@@ -672,9 +672,9 @@  discard block
 block discarded – undo
672 672
  *     incluant les rubriques noeuds et toutes leurs descendances
673 673
  */
674 674
 function calcul_branche_in($id) {
675
-	$calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
675
+    $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
676 676
 
677
-	return $calcul_branche_in($id);
677
+    return $calcul_branche_in($id);
678 678
 }
679 679
 
680 680
 /**
@@ -692,9 +692,9 @@  discard block
 block discarded – undo
692 692
  *     incluant les rubriques transmises et toutes leurs parentées
693 693
  */
694 694
 function calcul_hierarchie_in($id, $tout = true) {
695
-	$calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
695
+    $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
696 696
 
697
-	return $calcul_hierarchie_in($id, $tout);
697
+    return $calcul_hierarchie_in($id, $tout);
698 698
 }
699 699
 
700 700
 
@@ -715,40 +715,40 @@  discard block
 block discarded – undo
715 715
  *     incluant les rubriques noeuds et toutes leurs descendances
716 716
  */
717 717
 function inc_calcul_branche_in_dist($id) {
718
-	static $b = [];
719
-
720
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
721
-	if (!is_array($id)) {
722
-		$id = explode(',', $id);
723
-	}
724
-	$id = join(',', array_map('intval', $id));
725
-	if (isset($b[$id])) {
726
-		return $b[$id];
727
-	}
728
-
729
-	// Notre branche commence par la rubrique de depart
730
-	$branche = $r = $id;
731
-
732
-	// On ajoute une generation (les filles de la generation precedente)
733
-	// jusqu'a epuisement, en se protegeant des references circulaires
734
-	$maxiter = 10000;
735
-	while (
736
-		$maxiter-- and $filles = sql_allfetsel(
737
-			'id_rubrique',
738
-			'spip_rubriques',
739
-			sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT')
740
-		)
741
-	) {
742
-		$r = join(',', array_column($filles, 'id_rubrique'));
743
-		$branche .= ',' . $r;
744
-	}
745
-
746
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
747
-	if (strlen($branche) < 10000) {
748
-		$b[$id] = $branche;
749
-	}
750
-
751
-	return $branche;
718
+    static $b = [];
719
+
720
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
721
+    if (!is_array($id)) {
722
+        $id = explode(',', $id);
723
+    }
724
+    $id = join(',', array_map('intval', $id));
725
+    if (isset($b[$id])) {
726
+        return $b[$id];
727
+    }
728
+
729
+    // Notre branche commence par la rubrique de depart
730
+    $branche = $r = $id;
731
+
732
+    // On ajoute une generation (les filles de la generation precedente)
733
+    // jusqu'a epuisement, en se protegeant des references circulaires
734
+    $maxiter = 10000;
735
+    while (
736
+        $maxiter-- and $filles = sql_allfetsel(
737
+            'id_rubrique',
738
+            'spip_rubriques',
739
+            sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT')
740
+        )
741
+    ) {
742
+        $r = join(',', array_column($filles, 'id_rubrique'));
743
+        $branche .= ',' . $r;
744
+    }
745
+
746
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
747
+    if (strlen($branche) < 10000) {
748
+        $b[$id] = $branche;
749
+    }
750
+
751
+    return $branche;
752 752
 }
753 753
 
754 754
 
@@ -770,45 +770,45 @@  discard block
 block discarded – undo
770 770
  *     incluant les rubriques transmises et toutes leurs parentées
771 771
  */
772 772
 function inc_calcul_hierarchie_in_dist($id, $tout = true) {
773
-	static $b = [];
774
-
775
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
776
-	if (!is_array($id)) {
777
-		$id = explode(',', $id);
778
-	}
779
-	$id = join(',', array_map('intval', $id));
780
-
781
-	if (isset($b[$id])) {
782
-		// Notre branche commence par la rubrique de depart si $tout=true
783
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
784
-	}
785
-
786
-	$hier = '';
787
-
788
-	// On ajoute une generation (les filles de la generation precedente)
789
-	// jusqu'a epuisement, en se protegeant des references circulaires
790
-	$ids_nouveaux_parents = $id;
791
-	$maxiter = 10000;
792
-	while (
793
-		$maxiter-- and $parents = sql_allfetsel(
794
-			'id_parent',
795
-			'spip_rubriques',
796
-			sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT')
797
-		)
798
-	) {
799
-		$ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
800
-		$hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
801
-	}
802
-
803
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
804
-	if (strlen($hier) < 10000) {
805
-		$b[$id] = $hier;
806
-	}
807
-
808
-	// Notre branche commence par la rubrique de depart si $tout=true
809
-	$hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
810
-
811
-	return $hier;
773
+    static $b = [];
774
+
775
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
776
+    if (!is_array($id)) {
777
+        $id = explode(',', $id);
778
+    }
779
+    $id = join(',', array_map('intval', $id));
780
+
781
+    if (isset($b[$id])) {
782
+        // Notre branche commence par la rubrique de depart si $tout=true
783
+        return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
784
+    }
785
+
786
+    $hier = '';
787
+
788
+    // On ajoute une generation (les filles de la generation precedente)
789
+    // jusqu'a epuisement, en se protegeant des references circulaires
790
+    $ids_nouveaux_parents = $id;
791
+    $maxiter = 10000;
792
+    while (
793
+        $maxiter-- and $parents = sql_allfetsel(
794
+            'id_parent',
795
+            'spip_rubriques',
796
+            sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT')
797
+        )
798
+    ) {
799
+        $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
800
+        $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
801
+    }
802
+
803
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
804
+    if (strlen($hier) < 10000) {
805
+        $b[$id] = $hier;
806
+    }
807
+
808
+    // Notre branche commence par la rubrique de depart si $tout=true
809
+    $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
810
+
811
+    return $hier;
812 812
 }
813 813
 
814 814
 
@@ -826,47 +826,47 @@  discard block
 block discarded – undo
826 826
  * @return void
827 827
  **/
828 828
 function calculer_prochain_postdate($check = false) {
829
-	include_spip('base/abstract_sql');
830
-	if ($check) {
831
-		$postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
832
-			'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : '';
833
-
834
-		$r = sql_select(
835
-			'DISTINCT A.id_rubrique AS id',
836
-			'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique',
837
-			"R.statut != 'publie' AND A.statut='publie'$postdates"
838
-		);
839
-		while ($row = sql_fetch($r)) {
840
-			publier_branche_rubrique($row['id']);
841
-		}
842
-
843
-		pipeline('trig_calculer_prochain_postdate', '');
844
-	}
845
-
846
-	$t = sql_fetsel(
847
-		'date',
848
-		'spip_articles',
849
-		"statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')),
850
-		'',
851
-		'date',
852
-		'1'
853
-	);
854
-
855
-	if ($t) {
856
-		$t = $t['date'];
857
-		if (
858
-			!isset($GLOBALS['meta']['date_prochain_postdate'])
859
-			or $t <> $GLOBALS['meta']['date_prochain_postdate']
860
-		) {
861
-			ecrire_meta('date_prochain_postdate', strtotime($t));
862
-			ecrire_meta('derniere_modif', time());
863
-		}
864
-	} else {
865
-		effacer_meta('date_prochain_postdate');
866
-		ecrire_meta('derniere_modif', time());
867
-	}
868
-
869
-	spip_log("prochain postdate: $t");
829
+    include_spip('base/abstract_sql');
830
+    if ($check) {
831
+        $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
832
+            'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : '';
833
+
834
+        $r = sql_select(
835
+            'DISTINCT A.id_rubrique AS id',
836
+            'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique',
837
+            "R.statut != 'publie' AND A.statut='publie'$postdates"
838
+        );
839
+        while ($row = sql_fetch($r)) {
840
+            publier_branche_rubrique($row['id']);
841
+        }
842
+
843
+        pipeline('trig_calculer_prochain_postdate', '');
844
+    }
845
+
846
+    $t = sql_fetsel(
847
+        'date',
848
+        'spip_articles',
849
+        "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')),
850
+        '',
851
+        'date',
852
+        '1'
853
+    );
854
+
855
+    if ($t) {
856
+        $t = $t['date'];
857
+        if (
858
+            !isset($GLOBALS['meta']['date_prochain_postdate'])
859
+            or $t <> $GLOBALS['meta']['date_prochain_postdate']
860
+        ) {
861
+            ecrire_meta('date_prochain_postdate', strtotime($t));
862
+            ecrire_meta('derniere_modif', time());
863
+        }
864
+    } else {
865
+        effacer_meta('date_prochain_postdate');
866
+        ecrire_meta('derniere_modif', time());
867
+    }
868
+
869
+    spip_log("prochain postdate: $t");
870 870
 }
871 871
 
872 872
 /**
@@ -891,62 +891,62 @@  discard block
 block discarded – undo
891 891
  */
892 892
 function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') {
893 893
 
894
-	// eclater l'arborescence demandee
895
-	// echapper les </multi> et autres balises fermantes html
896
-	$titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre);
897
-	$arbo = explode('/', preg_replace(',^/,', '', $titre));
898
-	include_spip('base/abstract_sql');
899
-	foreach ($arbo as $titre) {
900
-		// retablir les </multi> et autres balises fermantes html
901
-		$titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre);
902
-		$r = sql_getfetsel(
903
-			'id_rubrique',
904
-			'spip_rubriques',
905
-			'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent),
906
-			$groupby = [],
907
-			$orderby = [],
908
-			$limit = '',
909
-			$having = [],
910
-			$serveur
911
-		);
912
-		if ($r !== null) {
913
-			$id_parent = $r;
914
-		} else {
915
-			$id_rubrique = sql_insertq('spip_rubriques', [
916
-					'titre' => $titre,
917
-					'id_parent' => $id_parent,
918
-					'statut' => 'prepa'
919
-				], $desc = [], $serveur);
920
-			if ($id_parent > 0) {
921
-				$data = sql_fetsel(
922
-					'id_secteur,lang',
923
-					'spip_rubriques',
924
-					"id_rubrique=$id_parent",
925
-					$groupby = [],
926
-					$orderby = [],
927
-					$limit = '',
928
-					$having = [],
929
-					$serveur
930
-				);
931
-				$id_secteur = $data['id_secteur'];
932
-				$lang = $data['lang'];
933
-			} else {
934
-				$id_secteur = $id_rubrique;
935
-				$lang = $GLOBALS['meta']['langue_site'];
936
-			}
937
-
938
-			sql_updateq(
939
-				'spip_rubriques',
940
-				['id_secteur' => $id_secteur, 'lang' => $lang],
941
-				'id_rubrique=' . intval($id_rubrique),
942
-				$desc = '',
943
-				$serveur
944
-			);
945
-
946
-			// pour la recursion
947
-			$id_parent = $id_rubrique;
948
-		}
949
-	}
950
-
951
-	return intval($id_parent);
894
+    // eclater l'arborescence demandee
895
+    // echapper les </multi> et autres balises fermantes html
896
+    $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre);
897
+    $arbo = explode('/', preg_replace(',^/,', '', $titre));
898
+    include_spip('base/abstract_sql');
899
+    foreach ($arbo as $titre) {
900
+        // retablir les </multi> et autres balises fermantes html
901
+        $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre);
902
+        $r = sql_getfetsel(
903
+            'id_rubrique',
904
+            'spip_rubriques',
905
+            'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent),
906
+            $groupby = [],
907
+            $orderby = [],
908
+            $limit = '',
909
+            $having = [],
910
+            $serveur
911
+        );
912
+        if ($r !== null) {
913
+            $id_parent = $r;
914
+        } else {
915
+            $id_rubrique = sql_insertq('spip_rubriques', [
916
+                    'titre' => $titre,
917
+                    'id_parent' => $id_parent,
918
+                    'statut' => 'prepa'
919
+                ], $desc = [], $serveur);
920
+            if ($id_parent > 0) {
921
+                $data = sql_fetsel(
922
+                    'id_secteur,lang',
923
+                    'spip_rubriques',
924
+                    "id_rubrique=$id_parent",
925
+                    $groupby = [],
926
+                    $orderby = [],
927
+                    $limit = '',
928
+                    $having = [],
929
+                    $serveur
930
+                );
931
+                $id_secteur = $data['id_secteur'];
932
+                $lang = $data['lang'];
933
+            } else {
934
+                $id_secteur = $id_rubrique;
935
+                $lang = $GLOBALS['meta']['langue_site'];
936
+            }
937
+
938
+            sql_updateq(
939
+                'spip_rubriques',
940
+                ['id_secteur' => $id_secteur, 'lang' => $lang],
941
+                'id_rubrique=' . intval($id_rubrique),
942
+                $desc = '',
943
+                $serveur
944
+            );
945
+
946
+            // pour la recursion
947
+            $id_parent = $id_rubrique;
948
+        }
949
+    }
950
+
951
+    return intval($id_parent);
952 952
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 		sql_updateq(
136 136
 			'spip_rubriques',
137 137
 			['statut' => 'publie', 'date' => date('Y-m-d H:i:s')],
138
-			'id_rubrique=' . intval($id_rubrique)
138
+			'id_rubrique='.intval($id_rubrique)
139 139
 		);
140
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique));
140
+		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique='.intval($id_rubrique));
141 141
 		if (!$id_parent) {
142 142
 			break;
143 143
 		}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			return $id_pred != $id_rubrique;
173 173
 		}
174 174
 		// passer au parent si on a depublie
175
-		$r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred));
175
+		$r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id_pred));
176 176
 		$id_pred = $r['id_parent'];
177 177
 	}
178 178
 
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 		$date = date('Y-m-d H:i:s');
198 198
 	}
199 199
 	$postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
200
-		' AND date <= ' . sql_quote($date) : '';
200
+		' AND date <= '.sql_quote($date) : '';
201 201
 
202 202
 	if (!$id_rubrique = intval($id_rubrique)) {
203 203
 		return false;
204 204
 	}
205 205
 
206 206
 	// verifier qu'elle existe et est bien publiee
207
-	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
207
+	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique));
208 208
 	if (!$r or $r['statut'] !== 'publie') {
209 209
 		return false;
210 210
 	}
@@ -214,12 +214,12 @@  discard block
 block discarded – undo
214 214
 	$compte = [
215 215
 		'articles' => sql_countsel(
216 216
 			'spip_articles',
217
-			'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates"
217
+			'id_rubrique='.intval($id_rubrique)." AND statut='publie'$postdates"
218 218
 		),
219
-		'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"),
219
+		'rubriques' => sql_countsel('spip_rubriques', 'id_parent='.intval($id_rubrique)." AND statut='publie'"),
220 220
 		'documents' => sql_countsel(
221 221
 			'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document',
222
-			'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') "
222
+			'L.id_objet='.intval($id_rubrique)." AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') "
223 223
 		)
224 224
 	];
225 225
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 		}
245 245
 	}
246 246
 
247
-	sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique));
247
+	sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique='.intval($id_rubrique));
248 248
 
249 249
 #		spip_log("depublier_rubrique $id_pred");
250 250
 	return true;
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 
308 308
 	// Afficher les articles post-dates ?
309 309
 	$postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
310
-		'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : '';
310
+		'AND A.date <= '.sql_quote(date('Y-m-d H:i:s')) : '';
311 311
 
312 312
 	$r = sql_select(
313 313
 		'R.id_rubrique AS id, max(A.date) AS date_h',
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 		sql_updateq(
320 320
 			'spip_rubriques',
321 321
 			['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']],
322
-			'id_rubrique=' . intval($row['id'])
322
+			'id_rubrique='.intval($row['id'])
323 323
 		);
324 324
 	}
325 325
 
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 			sql_updateq(
346 346
 				'spip_rubriques',
347 347
 				['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']],
348
-				'id_rubrique=' . intval($row['id'])
348
+				'id_rubrique='.intval($row['id'])
349 349
 			);
350 350
 			$continuer = true;
351 351
 		}
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 			and $rows = sql_allfetsel(
399 399
 				'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur',
400 400
 				'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique',
401
-				'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)',
401
+				'R.profondeur='.intval($prof).' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)',
402 402
 				'',
403 403
 				'R.id_secteur',
404 404
 				'0,100'
@@ -437,11 +437,11 @@  discard block
 block discarded – undo
437 437
 			and $rows = sql_allfetsel(
438 438
 				'id_rubrique as id',
439 439
 				'spip_rubriques',
440
-				'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select(
440
+				'profondeur='.intval($prof + 1).' AND id_parent NOT IN ('.sql_get_select(
441 441
 					'zzz.id_rubrique',
442 442
 					'spip_rubriques AS zzz',
443
-					'zzz.profondeur=' . intval($prof)
444
-				) . ')',
443
+					'zzz.profondeur='.intval($prof)
444
+				).')',
445 445
 				'',
446 446
 				'',
447 447
 				'0,100'
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
456 456
 		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
457 457
 		// on arrete les frais
458
-		if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) {
458
+		if (sql_countsel('spip_rubriques', 'profondeur='.intval($prof + 1))) {
459 459
 			$prof++;
460 460
 			$continuer = true;
461 461
 		}
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
 
464 464
 	// loger si la table des rubriques semble foireuse
465 465
 	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
466
-	if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) {
466
+	if (sql_countsel('spip_rubriques', 'profondeur>'.intval($prof + 1))) {
467 467
 		spip_log(
468
-			'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)',
468
+			'Les rubriques de profondeur>'.($prof + 1).' semblent suspectes (branches morte ou reference circulaire dans les parents)',
469 469
 			_LOG_CRITIQUE
470 470
 		);
471
-		sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1));
471
+		sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>'.intval($prof + 1));
472 472
 	}
473 473
 
474 474
 	// reparer les articles
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	);
480 480
 
481 481
 	while ($row = sql_fetch($r)) {
482
-		sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id']));
482
+		sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article='.intval($row['id']));
483 483
 	}
484 484
 
485 485
 	// avertir les plugins qui peuvent faire leur mises a jour egalement
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 		$t = sql_updateq(
511 511
 			'spip_rubriques',
512 512
 			['lang' => $row['lang'], 'langue_choisie' => 'non'],
513
-			'id_rubrique=' . intval($id_rubrique)
513
+			'id_rubrique='.intval($id_rubrique)
514 514
 		);
515 515
 	}
516 516
 
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 		sql_updateq(
556 556
 			'spip_articles',
557 557
 			['lang' => $row['lang'], 'langue_choisie' => 'non'],
558
-			'id_article=' . intval($id_article)
558
+			'id_article='.intval($id_article)
559 559
 		);
560 560
 	}
561 561
 
@@ -630,11 +630,11 @@  discard block
 block discarded – undo
630 630
 				];
631 631
 				// generer un nom de fonction "anonyme" unique
632 632
 				do {
633
-					$functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax());
633
+					$functionname = 'f_calculer_langues_utilisees_'.$boucle->id_table.'_'.time().'_'.random_int(0, mt_getrandmax());
634 634
 				} while (function_exists($functionname));
635 635
 				$code = calculer_boucle('calculer_langues_utilisees', $boucles);
636
-				$code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
637
-				$code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
636
+				$code = '$SP=0; $command=array();$command["connect"] = $connect = "'.$serveur.'"; $Pile=array(0=>array());'."\n".$code;
637
+				$code = 'function '.$functionname.'(){'.$code.'};$res = '.$functionname.'();';
638 638
 				$res = '';
639 639
 				eval($code);
640 640
 				$res = explode(',', $res);
@@ -736,11 +736,11 @@  discard block
 block discarded – undo
736 736
 		$maxiter-- and $filles = sql_allfetsel(
737 737
 			'id_rubrique',
738 738
 			'spip_rubriques',
739
-			sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT')
739
+			sql_in('id_parent', $r).' AND '.sql_in('id_rubrique', $r, 'NOT')
740 740
 		)
741 741
 	) {
742 742
 		$r = join(',', array_column($filles, 'id_rubrique'));
743
-		$branche .= ',' . $r;
743
+		$branche .= ','.$r;
744 744
 	}
745 745
 
746 746
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 
781 781
 	if (isset($b[$id])) {
782 782
 		// Notre branche commence par la rubrique de depart si $tout=true
783
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
783
+		return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id];
784 784
 	}
785 785
 
786 786
 	$hier = '';
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
 		$maxiter-- and $parents = sql_allfetsel(
794 794
 			'id_parent',
795 795
 			'spip_rubriques',
796
-			sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT')
796
+			sql_in('id_rubrique', $ids_nouveaux_parents).' AND '.sql_in('id_parent', $hier, 'NOT')
797 797
 		)
798 798
 	) {
799 799
 		$ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
800
-		$hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
800
+		$hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : '');
801 801
 	}
802 802
 
803 803
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 	include_spip('base/abstract_sql');
830 830
 	if ($check) {
831 831
 		$postdates = ($GLOBALS['meta']['post_dates'] == 'non') ?
832
-			'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : '';
832
+			'AND A.date <= '.sql_quote(date('Y-m-d H:i:s')) : '';
833 833
 
834 834
 		$r = sql_select(
835 835
 			'DISTINCT A.id_rubrique AS id',
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	$t = sql_fetsel(
847 847
 		'date',
848 848
 		'spip_articles',
849
-		"statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')),
849
+		"statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')),
850 850
 		'',
851 851
 		'date',
852 852
 		'1'
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 		$r = sql_getfetsel(
903 903
 			'id_rubrique',
904 904
 			'spip_rubriques',
905
-			'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent),
905
+			'titre = '.sql_quote($titre).' AND id_parent='.intval($id_parent),
906 906
 			$groupby = [],
907 907
 			$orderby = [],
908 908
 			$limit = '',
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
 			sql_updateq(
939 939
 				'spip_rubriques',
940 940
 				['id_secteur' => $id_secteur, 'lang' => $lang],
941
-				'id_rubrique=' . intval($id_rubrique),
941
+				'id_rubrique='.intval($id_rubrique),
942 942
 				$desc = '',
943 943
 				$serveur
944 944
 			);
Please login to merge, or discard this patch.
ecrire/inc/filtres_mini.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 
47 47
 	if ($query) {
48
-		$url .= '?' . $query;
48
+		$url .= '?'.$query;
49 49
 	}
50 50
 
51
-	return '/' . preg_replace(',^/,S', '', $url);
51
+	return '/'.preg_replace(',^/,S', '', $url);
52 52
 }
53 53
 
54 54
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
76 76
 		$r = array_pad($r, 3, null);
77 77
 
78
-		return $r[1] . resolve_path($r[2]);
78
+		return $r[1].resolve_path($r[2]);
79 79
 	}
80 80
 
81 81
 	# L'url site spip est un lien absolu aussi
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 	switch (substr($lien, 0, 1)) {
98 98
 		case '/':
99
-			return $debut . resolve_path($lien);
99
+			return $debut.resolve_path($lien);
100 100
 		case '#':
101
-			return $debut . resolve_path($dir . $mot . $get . $lien);
101
+			return $debut.resolve_path($dir.$mot.$get.$lien);
102 102
 		case '':
103
-			return $debut . resolve_path($dir . $mot . $get . $hash);
103
+			return $debut.resolve_path($dir.$mot.$get.$hash);
104 104
 		default:
105
-			return $debut . resolve_path($dir . $lien);
105
+			return $debut.resolve_path($dir.$lien);
106 106
 	}
107 107
 }
108 108
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 		return '';
131 131
 	}
132 132
 	if (!$base) {
133
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
133
+		$base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
134 134
 	}
135 135
 
136 136
 	return suivre_lien($base, $url);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
  * @param array $protocoles_autorises
154 154
  * @return bool
155 155
  */
156
-function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
156
+function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) {
157 157
 
158 158
 	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
159 159
 		$protocole = $m[1];
Please login to merge, or discard this patch.
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
  * @return string URL nettoyée
36 36
  **/
37 37
 function resolve_path($url) {
38
-	[$url, $query] = array_pad(explode('?', $url, 2), 2, null);
39
-	while (
40
-		preg_match(',/\.?/,', $url, $regs)    # supprime // et /./
41
-		or preg_match(',/[^/]*/\.\./,S', $url, $regs)  # supprime /toto/../
42
-		or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut
43
-	) {
44
-		$url = str_replace($regs[0], '/', $url);
45
-	}
38
+    [$url, $query] = array_pad(explode('?', $url, 2), 2, null);
39
+    while (
40
+        preg_match(',/\.?/,', $url, $regs)    # supprime // et /./
41
+        or preg_match(',/[^/]*/\.\./,S', $url, $regs)  # supprime /toto/../
42
+        or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut
43
+    ) {
44
+        $url = str_replace($regs[0], '/', $url);
45
+    }
46 46
 
47
-	if ($query) {
48
-		$url .= '?' . $query;
49
-	}
47
+    if ($query) {
48
+        $url .= '?' . $query;
49
+    }
50 50
 
51
-	return '/' . preg_replace(',^/,S', '', $url);
51
+    return '/' . preg_replace(',^/,S', '', $url);
52 52
 }
53 53
 
54 54
 
@@ -69,44 +69,44 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function suivre_lien($url, $lien) {
71 71
 
72
-	$mot = null;
73
-	$get = null;
74
-	$hash = null;
75
-	if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
76
-		return $lien;
77
-	}
78
-	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79
-		$r = array_pad($r, 3, null);
72
+    $mot = null;
73
+    $get = null;
74
+    $hash = null;
75
+    if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
76
+        return $lien;
77
+    }
78
+    if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79
+        $r = array_pad($r, 3, null);
80 80
 
81
-		return $r[1] . resolve_path($r[2]);
82
-	}
81
+        return $r[1] . resolve_path($r[2]);
82
+    }
83 83
 
84
-	# L'url site spip est un lien absolu aussi
85
-	if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) {
86
-		return $lien;
87
-	}
84
+    # L'url site spip est un lien absolu aussi
85
+    if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) {
86
+        return $lien;
87
+    }
88 88
 
89
-	# lien relatif, il faut verifier l'url de base
90
-	# commencer par virer la chaine de get de l'url de base
91
-	$dir = '/';
92
-	$debut = '';
93
-	if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
94
-		$debut = $regs[1];
95
-		$dir = !strlen($regs[2]) ? '/' : $regs[2];
96
-		$mot = $regs[3];
97
-		$get = $regs[4] ?? '';
98
-		$hash = $regs[5] ?? '';
99
-	}
100
-	switch (substr($lien, 0, 1)) {
101
-		case '/':
102
-			return $debut . resolve_path($lien);
103
-		case '#':
104
-			return $debut . resolve_path($dir . $mot . $get . $lien);
105
-		case '':
106
-			return $debut . resolve_path($dir . $mot . $get . $hash);
107
-		default:
108
-			return $debut . resolve_path($dir . $lien);
109
-	}
89
+    # lien relatif, il faut verifier l'url de base
90
+    # commencer par virer la chaine de get de l'url de base
91
+    $dir = '/';
92
+    $debut = '';
93
+    if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
94
+        $debut = $regs[1];
95
+        $dir = !strlen($regs[2]) ? '/' : $regs[2];
96
+        $mot = $regs[3];
97
+        $get = $regs[4] ?? '';
98
+        $hash = $regs[5] ?? '';
99
+    }
100
+    switch (substr($lien, 0, 1)) {
101
+        case '/':
102
+            return $debut . resolve_path($lien);
103
+        case '#':
104
+            return $debut . resolve_path($dir . $mot . $get . $lien);
105
+        case '':
106
+            return $debut . resolve_path($dir . $mot . $get . $hash);
107
+        default:
108
+            return $debut . resolve_path($dir . $lien);
109
+    }
110 110
 }
111 111
 
112 112
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
  * @return string Texte ou URL (en absolus)
130 130
  **/
131 131
 function url_absolue($url, $base = '') {
132
-	if (strlen($url = trim($url)) == 0) {
133
-		return '';
134
-	}
135
-	if (!$base) {
136
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
137
-	}
132
+    if (strlen($url = trim($url)) == 0) {
133
+        return '';
134
+    }
135
+    if (!$base) {
136
+        $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
137
+    }
138 138
 
139
-	return suivre_lien($base, $url);
139
+    return suivre_lien($base, $url);
140 140
 }
141 141
 
142 142
 /**
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
  * @return string
148 148
  */
149 149
 function protocole_implicite($url_absolue) {
150
-	return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
150
+    return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
151 151
 }
152 152
 
153 153
 /**
@@ -158,16 +158,16 @@  discard block
 block discarded – undo
158 158
  */
159 159
 function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
160 160
 
161
-	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
162
-		$protocole = $m[1];
163
-		if (
164
-			in_array($protocole, $protocoles_autorises)
165
-			or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
166
-		) {
167
-			return true;
168
-		}
169
-	}
170
-	return false;
161
+    if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
162
+        $protocole = $m[1];
163
+        if (
164
+            in_array($protocole, $protocoles_autorises)
165
+            or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
166
+        ) {
167
+            return true;
168
+        }
169
+    }
170
+    return false;
171 171
 }
172 172
 
173 173
 /**
@@ -184,27 +184,27 @@  discard block
 block discarded – undo
184 184
  * @return string Texte avec des URLs absolues
185 185
  **/
186 186
 function liens_absolus($texte, $base = '') {
187
-	if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
188
-		if (!function_exists('extraire_attribut')) {
189
-			include_spip('inc/filtres');
190
-		}
191
-		foreach ($liens as $lien) {
192
-			foreach (['href', 'src'] as $attr) {
193
-				$href = extraire_attribut($lien[0], $attr);
194
-				if (strlen($href) > 0) {
195
-					if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) {
196
-						$abs = url_absolue($href, $base);
197
-						if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) {
198
-							$texte_lien = inserer_attribut($lien[0], $attr, $abs);
199
-							$texte = str_replace($lien[0], $texte_lien, $texte);
200
-						}
201
-					}
202
-				}
203
-			}
204
-		}
205
-	}
187
+    if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
188
+        if (!function_exists('extraire_attribut')) {
189
+            include_spip('inc/filtres');
190
+        }
191
+        foreach ($liens as $lien) {
192
+            foreach (['href', 'src'] as $attr) {
193
+                $href = extraire_attribut($lien[0], $attr);
194
+                if (strlen($href) > 0) {
195
+                    if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) {
196
+                        $abs = url_absolue($href, $base);
197
+                        if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) {
198
+                            $texte_lien = inserer_attribut($lien[0], $attr, $abs);
199
+                            $texte = str_replace($lien[0], $texte_lien, $texte);
200
+                        }
201
+                    }
202
+                }
203
+            }
204
+        }
205
+    }
206 206
 
207
-	return $texte;
207
+    return $texte;
208 208
 }
209 209
 
210 210
 
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
  * @return string Texte ou URL (en absolus)
221 221
  **/
222 222
 function abs_url($texte, $base = '') {
223
-	if ($GLOBALS['mode_abs_url'] == 'url') {
224
-		return url_absolue($texte, $base);
225
-	} else {
226
-		return liens_absolus($texte, $base);
227
-	}
223
+    if ($GLOBALS['mode_abs_url'] == 'url') {
224
+        return url_absolue($texte, $base);
225
+    } else {
226
+        return liens_absolus($texte, $base);
227
+    }
228 228
 }
229 229
 
230 230
 /**
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
  * @return string
238 238
  */
239 239
 function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
240
-	if (is_null($flags)) {
241
-		$flags = ENT_COMPAT | ENT_HTML401;
242
-	}
240
+    if (is_null($flags)) {
241
+        $flags = ENT_COMPAT | ENT_HTML401;
242
+    }
243 243
 
244
-	return htmlspecialchars($string, $flags, $encoding, $double_encode);
244
+    return htmlspecialchars($string, $flags, $encoding, $double_encode);
245 245
 }
246 246
 
247 247
 /**
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
  * @return string
255 255
  */
256 256
 function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
257
-	if (is_null($flags)) {
258
-		$flags = ENT_COMPAT | ENT_HTML401;
259
-	}
257
+    if (is_null($flags)) {
258
+        $flags = ENT_COMPAT | ENT_HTML401;
259
+    }
260 260
 
261
-	return htmlentities($string, $flags, $encoding, $double_encode);
261
+    return htmlentities($string, $flags, $encoding, $double_encode);
262 262
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 3 patches
Braces   +4 added lines, -9 removed lines patch added patch discarded remove patch
@@ -524,8 +524,7 @@  discard block
 block discarded – undo
524 524
 			process_image_svg_identite($ret);
525 525
 			$ret['creer'] = false;
526 526
 		}
527
-	}
528
-	else {
527
+	} else {
529 528
 		if (!function_exists($ret['fonction_imagecreatefrom'])) {
530 529
 			return false;
531 530
 		}
@@ -628,8 +627,7 @@  discard block
 block discarded – undo
628 627
 
629 628
 	if (isset($info['mime'])) {
630 629
 		$mime = $info['mime'];
631
-	}
632
-	else {
630
+	} else {
633 631
 		$mime = image_type_to_mime_type($info[2]);
634 632
 	}
635 633
 
@@ -1408,9 +1406,7 @@  discard block
 block discarded – undo
1408 1406
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1409 1407
 		$vignette = $destination . '.' . $format;
1410 1408
 		@copy($image, $vignette);
1411
-	}
1412
-
1413
-	elseif ($valeurs['format_source'] === 'svg') {
1409
+	} elseif ($valeurs['format_source'] === 'svg') {
1414 1410
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1415 1411
 			$format_sortie = 'svg';
1416 1412
 			$vignette = $destination . '.' . $format_sortie;
@@ -1846,8 +1842,7 @@  discard block
 block discarded – undo
1846 1842
 		$date = test_espace_prive() ? ('?' . $date) : '';
1847 1843
 
1848 1844
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1849
-	}
1850
-	else {
1845
+	} else {
1851 1846
 		# BMP, tiff ... les redacteurs osent tout!
1852 1847
 		return $img;
1853 1848
 	}
Please login to merge, or discard this patch.
Indentation   +1351 added lines, -1351 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$couleur = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,59 +120,59 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$H = null;
124
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
-	$var_G = ($G / 255);
126
-	$var_B = ($B / 255);
127
-
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
131
-
132
-	$L = ($var_Max + $var_Min) / 2;
133
-
134
-	if ($del_Max == 0) {
135
-		//This is a gray, no chroma...
136
-		$H = 0; //HSL results = 0 ÷ 1
137
-		$S = 0;
138
-	} else {
139
-		// Chromatic data...
140
-		if ($L < 0.5) {
141
-			$S = $del_Max / ($var_Max + $var_Min);
142
-		} else {
143
-			$S = $del_Max / (2 - $var_Max - $var_Min);
144
-		}
145
-
146
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
147
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
148
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
149
-
150
-		if ($var_R == $var_Max) {
151
-			$H = $del_B - $del_G;
152
-		} else {
153
-			if ($var_G == $var_Max) {
154
-				$H = (1 / 3) + $del_R - $del_B;
155
-			} else {
156
-				if ($var_B == $var_Max) {
157
-					$H = (2 / 3) + $del_G - $del_R;
158
-				}
159
-			}
160
-		}
161
-
162
-		if ($H < 0) {
163
-			$H += 1;
164
-		}
165
-		if ($H > 1) {
166
-			$H -= 1;
167
-		}
168
-	}
169
-
170
-	$ret = [];
171
-	$ret['h'] = $H;
172
-	$ret['s'] = $S;
173
-	$ret['l'] = $L;
174
-
175
-	return $ret;
123
+    $H = null;
124
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
+    $var_G = ($G / 255);
126
+    $var_B = ($B / 255);
127
+
128
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
131
+
132
+    $L = ($var_Max + $var_Min) / 2;
133
+
134
+    if ($del_Max == 0) {
135
+        //This is a gray, no chroma...
136
+        $H = 0; //HSL results = 0 ÷ 1
137
+        $S = 0;
138
+    } else {
139
+        // Chromatic data...
140
+        if ($L < 0.5) {
141
+            $S = $del_Max / ($var_Max + $var_Min);
142
+        } else {
143
+            $S = $del_Max / (2 - $var_Max - $var_Min);
144
+        }
145
+
146
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
147
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
148
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
149
+
150
+        if ($var_R == $var_Max) {
151
+            $H = $del_B - $del_G;
152
+        } else {
153
+            if ($var_G == $var_Max) {
154
+                $H = (1 / 3) + $del_R - $del_B;
155
+            } else {
156
+                if ($var_B == $var_Max) {
157
+                    $H = (2 / 3) + $del_G - $del_R;
158
+                }
159
+            }
160
+        }
161
+
162
+        if ($H < 0) {
163
+            $H += 1;
164
+        }
165
+        if ($H > 1) {
166
+            $H -= 1;
167
+        }
168
+    }
169
+
170
+    $ret = [];
171
+    $ret['h'] = $H;
172
+    $ret['s'] = $S;
173
+    $ret['l'] = $L;
174
+
175
+    return $ret;
176 176
 }
177 177
 
178 178
 
@@ -188,52 +188,52 @@  discard block
 block discarded – undo
188 188
  * @return array
189 189
  */
190 190
 function _couleur_hsl_to_rgb($H, $S, $L) {
191
-	// helper
192
-	$hue_2_rgb = function ($v1, $v2, $vH) {
193
-		if ($vH < 0) {
194
-			$vH += 1;
195
-		}
196
-		if ($vH > 1) {
197
-			$vH -= 1;
198
-		}
199
-		if ((6 * $vH) < 1) {
200
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
201
-		}
202
-		if ((2 * $vH) < 1) {
203
-			return ($v2);
204
-		}
205
-		if ((3 * $vH) < 2) {
206
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
207
-		}
208
-
209
-		return ($v1);
210
-	};
211
-
212
-	if ($S == 0) {
213
-		// HSV values = 0 -> 1
214
-		$R = $L * 255;
215
-		$G = $L * 255;
216
-		$B = $L * 255;
217
-	} else {
218
-		if ($L < 0.5) {
219
-			$var_2 = $L * (1 + $S);
220
-		} else {
221
-			$var_2 = ($L + $S) - ($S * $L);
222
-		}
223
-
224
-		$var_1 = 2 * $L - $var_2;
225
-
226
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
227
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
228
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
229
-	}
230
-
231
-	$ret = [];
232
-	$ret['r'] = floor($R);
233
-	$ret['g'] = floor($G);
234
-	$ret['b'] = floor($B);
235
-
236
-	return $ret;
191
+    // helper
192
+    $hue_2_rgb = function ($v1, $v2, $vH) {
193
+        if ($vH < 0) {
194
+            $vH += 1;
195
+        }
196
+        if ($vH > 1) {
197
+            $vH -= 1;
198
+        }
199
+        if ((6 * $vH) < 1) {
200
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
201
+        }
202
+        if ((2 * $vH) < 1) {
203
+            return ($v2);
204
+        }
205
+        if ((3 * $vH) < 2) {
206
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
207
+        }
208
+
209
+        return ($v1);
210
+    };
211
+
212
+    if ($S == 0) {
213
+        // HSV values = 0 -> 1
214
+        $R = $L * 255;
215
+        $G = $L * 255;
216
+        $B = $L * 255;
217
+    } else {
218
+        if ($L < 0.5) {
219
+            $var_2 = $L * (1 + $S);
220
+        } else {
221
+            $var_2 = ($L + $S) - ($S * $L);
222
+        }
223
+
224
+        $var_1 = 2 * $L - $var_2;
225
+
226
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
227
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
228
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
229
+    }
230
+
231
+    $ret = [];
232
+    $ret['r'] = floor($R);
233
+    $ret['g'] = floor($G);
234
+    $ret['b'] = floor($B);
235
+
236
+    return $ret;
237 237
 }
238 238
 
239 239
 /**
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
  *     true si il faut supprimer le fichier temporaire ; false sinon.
251 251
  */
252 252
 function statut_effacer_images_temporaires($stat) {
253
-	static $statut = false; // par defaut on grave toute les images
254
-	if ($stat === 'get') {
255
-		return $statut;
256
-	}
257
-	$statut = $stat ? true : false;
253
+    static $statut = false; // par defaut on grave toute les images
254
+    if ($stat === 'get') {
255
+        return $statut;
256
+    }
257
+    $statut = $stat ? true : false;
258 258
 }
259 259
 
260 260
 
@@ -307,243 +307,243 @@  discard block
 block discarded – undo
307 307
  *     - array : tableau décrivant de l'image
308 308
  */
309 309
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
310
-	$ret = [];
311
-	$f = null;
312
-	static $images_recalcul = [];
313
-	if (strlen($img) == 0) {
314
-		return false;
315
-	}
316
-
317
-	$source = trim(extraire_attribut($img, 'src') ?? '');
318
-	if (strlen($source) < 1) {
319
-		$source = $img;
320
-		$img = "<img src='$source' />";
321
-	} elseif (
322
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
323
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
324
-		and in_array($extension, _image_extensions_acceptees_en_entree())
325
-	) {
326
-		# gerer img src="data:....base64"
327
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
328
-		if (!file_exists($local)) {
329
-			ecrire_fichier($local, base64_decode($regs[2]));
330
-		}
331
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
332
-			$sanitizer($local);
333
-		}
334
-		$source = $local;
335
-		$img = inserer_attribut($img, 'src', $source);
336
-		# eviter les mauvaises surprises lors de conversions de format
337
-		$img = inserer_attribut($img, 'width', '');
338
-		$img = inserer_attribut($img, 'height', '');
339
-	}
340
-
341
-	// les protocoles web prennent au moins 3 lettres
342
-	if (tester_url_absolue($source)) {
343
-		include_spip('inc/distant');
344
-		$fichier = _DIR_RACINE . copie_locale($source);
345
-		if (!$fichier) {
346
-			return '';
347
-		}
348
-		if (
349
-			$extension = _image_trouver_extension($fichier)
350
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
351
-		) {
352
-			$sanitizer($fichier);
353
-		}
354
-	} else {
355
-		// enlever le timestamp eventuel
356
-		if (strpos($source, '?') !== false) {
357
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
358
-		}
359
-		if (
360
-			strpos($source, '?') !== false
361
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
362
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
363
-		) {
364
-			$source = $f;
365
-		}
366
-		$fichier = $source;
367
-	}
368
-
369
-	$terminaison_dest = '';
370
-	if ($terminaison = _image_trouver_extension($fichier)) {
371
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
372
-	}
373
-
374
-	if (
375
-		$forcer_format !== false
376
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
377
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
378
-	) {
379
-		$terminaison_dest = $forcer_format;
380
-	}
381
-
382
-	if (!$terminaison_dest) {
383
-		return false;
384
-	}
385
-
386
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
387
-	$fichier_dest = $nom_fichier;
388
-	if (
389
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
390
-		or @file_exists($f = $fichier)
391
-	) {
392
-		// on passe la balise img a taille image qui exraira les attributs si possible
393
-		// au lieu de faire un acces disque sur le fichier
394
-		[$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
395
-		$date_src = @filemtime($f);
396
-	} elseif (
397
-		@file_exists($f = "$fichier.src")
398
-		and lire_fichier($f, $valeurs)
399
-		and $valeurs = unserialize($valeurs)
400
-		and isset($valeurs['hauteur_dest'])
401
-		and isset($valeurs['largeur_dest'])
402
-	) {
403
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
404
-		$ret['largeur'] = $valeurs['largeur_dest'];
405
-		$date_src = $valeurs['date'];
406
-	} // pas de fichier source par la
407
-	else {
408
-		return false;
409
-	}
410
-
411
-	// pas de taille mesurable
412
-	if (!($ret['hauteur'] or $ret['largeur'])) {
413
-		return false;
414
-	}
415
-
416
-	// les images calculees dependent du chemin du fichier source
417
-	// 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
418
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
419
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
420
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
421
-	// alors que ca concerne peu de site au final
422
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
423
-	$identifiant = $fichier;
424
-
425
-	// cas general :
426
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
427
-	// cas particulier de reduire :
428
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
429
-	$cache = 'cache-gd2';
430
-	if (substr($effet, 0, 7) == 'reduire') {
431
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
432
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
433
-		$ret['largeur_dest'] = $destWidth;
434
-		$ret['hauteur_dest'] = $destHeight;
435
-		$effet = "L{$destWidth}xH$destHeight";
436
-		$cache = 'cache-vignettes';
437
-		$fichier_dest = basename($fichier_dest);
438
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
439
-			// on garde la terminaison initiale car image simplement copiee
440
-			// et on postfixe son nom avec un md5 du path
441
-			$terminaison_dest = $terminaison;
442
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
443
-		} else {
444
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
445
-		}
446
-		$cache = sous_repertoire(_DIR_VAR, $cache);
447
-		$cache = sous_repertoire($cache, $effet);
448
-	} else {
449
-		$fichier_dest = md5("$identifiant-$effet");
450
-		$cache = sous_repertoire(_DIR_VAR, $cache);
451
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
452
-		$fichier_dest = substr($fichier_dest, 2);
453
-	}
454
-
455
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
456
-
457
-	$GLOBALS['images_calculees'][] = $fichier_dest;
458
-
459
-	$creer = true;
460
-	// si recalcul des images demande, recalculer chaque image une fois
461
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
462
-		$images_recalcul[$fichier_dest] = true;
463
-	} else {
464
-		if (@file_exists($f = $fichier_dest)) {
465
-			if (filemtime($f) >= $date_src) {
466
-				$creer = false;
467
-			}
468
-		} else {
469
-			if (
470
-				@file_exists($f = "$fichier_dest.src")
471
-				and lire_fichier($f, $valeurs)
472
-				and $valeurs = unserialize($valeurs)
473
-				and $valeurs['date'] >= $date_src
474
-			) {
475
-				$creer = false;
476
-			}
477
-		}
478
-	}
479
-	if ($creer) {
480
-		if (!@file_exists($fichier)) {
481
-			if (!@file_exists("$fichier.src")) {
482
-				spip_log("Image absente : $fichier");
483
-
484
-				return false;
485
-			}
486
-			# on reconstruit l'image source absente a partir de la chaine des .src
487
-			reconstruire_image_intermediaire($fichier);
488
-		}
489
-	}
490
-
491
-	if ($creer) {
492
-		spip_log(
493
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
494
-			'images' . _LOG_DEBUG
495
-		);
496
-	}
497
-
498
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
499
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
-	$ret['fichier'] = $fichier;
501
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
-	$ret['fichier_dest'] = $fichier_dest;
503
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
504
-	$ret['format_dest'] = $terminaison_dest;
505
-	$ret['date_src'] = $date_src;
506
-	$ret['creer'] = $creer;
507
-	$ret['class'] = extraire_attribut($img, 'class');
508
-	$ret['alt'] = extraire_attribut($img, 'alt');
509
-	$ret['style'] = extraire_attribut($img, 'style');
510
-	$ret['tag'] = $img;
511
-	if ($fonction_creation) {
512
-		$ret['reconstruction'] = $fonction_creation;
513
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
514
-		# cas de image_reduire qui finalement ne reduit pas l'image source
515
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
516
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
517
-	}
518
-
519
-	$ret = pipeline('image_preparer_filtre', [
520
-			'args' => [
521
-				'img' => $img,
522
-				'effet' => $effet,
523
-				'forcer_format' => $forcer_format,
524
-				'fonction_creation' => $fonction_creation,
525
-				'find_in_path' => $find_in_path,
526
-			],
527
-			'data' => $ret
528
-		]);
529
-
530
-	// une globale pour le debug en cas de crash memoire
531
-	$GLOBALS['derniere_image_calculee'] = $ret;
532
-
533
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
534
-	if ($term_fonction === 'svg') {
535
-		if ($creer and !$support_svg) {
536
-			process_image_svg_identite($ret);
537
-			$ret['creer'] = false;
538
-		}
539
-	}
540
-	else {
541
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
542
-			return false;
543
-		}
544
-	}
545
-
546
-	return $ret;
310
+    $ret = [];
311
+    $f = null;
312
+    static $images_recalcul = [];
313
+    if (strlen($img) == 0) {
314
+        return false;
315
+    }
316
+
317
+    $source = trim(extraire_attribut($img, 'src') ?? '');
318
+    if (strlen($source) < 1) {
319
+        $source = $img;
320
+        $img = "<img src='$source' />";
321
+    } elseif (
322
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
323
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
324
+        and in_array($extension, _image_extensions_acceptees_en_entree())
325
+    ) {
326
+        # gerer img src="data:....base64"
327
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
328
+        if (!file_exists($local)) {
329
+            ecrire_fichier($local, base64_decode($regs[2]));
330
+        }
331
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
332
+            $sanitizer($local);
333
+        }
334
+        $source = $local;
335
+        $img = inserer_attribut($img, 'src', $source);
336
+        # eviter les mauvaises surprises lors de conversions de format
337
+        $img = inserer_attribut($img, 'width', '');
338
+        $img = inserer_attribut($img, 'height', '');
339
+    }
340
+
341
+    // les protocoles web prennent au moins 3 lettres
342
+    if (tester_url_absolue($source)) {
343
+        include_spip('inc/distant');
344
+        $fichier = _DIR_RACINE . copie_locale($source);
345
+        if (!$fichier) {
346
+            return '';
347
+        }
348
+        if (
349
+            $extension = _image_trouver_extension($fichier)
350
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
351
+        ) {
352
+            $sanitizer($fichier);
353
+        }
354
+    } else {
355
+        // enlever le timestamp eventuel
356
+        if (strpos($source, '?') !== false) {
357
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
358
+        }
359
+        if (
360
+            strpos($source, '?') !== false
361
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
362
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
363
+        ) {
364
+            $source = $f;
365
+        }
366
+        $fichier = $source;
367
+    }
368
+
369
+    $terminaison_dest = '';
370
+    if ($terminaison = _image_trouver_extension($fichier)) {
371
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
372
+    }
373
+
374
+    if (
375
+        $forcer_format !== false
376
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
377
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
378
+    ) {
379
+        $terminaison_dest = $forcer_format;
380
+    }
381
+
382
+    if (!$terminaison_dest) {
383
+        return false;
384
+    }
385
+
386
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
387
+    $fichier_dest = $nom_fichier;
388
+    if (
389
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
390
+        or @file_exists($f = $fichier)
391
+    ) {
392
+        // on passe la balise img a taille image qui exraira les attributs si possible
393
+        // au lieu de faire un acces disque sur le fichier
394
+        [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
395
+        $date_src = @filemtime($f);
396
+    } elseif (
397
+        @file_exists($f = "$fichier.src")
398
+        and lire_fichier($f, $valeurs)
399
+        and $valeurs = unserialize($valeurs)
400
+        and isset($valeurs['hauteur_dest'])
401
+        and isset($valeurs['largeur_dest'])
402
+    ) {
403
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
404
+        $ret['largeur'] = $valeurs['largeur_dest'];
405
+        $date_src = $valeurs['date'];
406
+    } // pas de fichier source par la
407
+    else {
408
+        return false;
409
+    }
410
+
411
+    // pas de taille mesurable
412
+    if (!($ret['hauteur'] or $ret['largeur'])) {
413
+        return false;
414
+    }
415
+
416
+    // les images calculees dependent du chemin du fichier source
417
+    // 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
418
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
419
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
420
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
421
+    // alors que ca concerne peu de site au final
422
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
423
+    $identifiant = $fichier;
424
+
425
+    // cas general :
426
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
427
+    // cas particulier de reduire :
428
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
429
+    $cache = 'cache-gd2';
430
+    if (substr($effet, 0, 7) == 'reduire') {
431
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
432
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
433
+        $ret['largeur_dest'] = $destWidth;
434
+        $ret['hauteur_dest'] = $destHeight;
435
+        $effet = "L{$destWidth}xH$destHeight";
436
+        $cache = 'cache-vignettes';
437
+        $fichier_dest = basename($fichier_dest);
438
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
439
+            // on garde la terminaison initiale car image simplement copiee
440
+            // et on postfixe son nom avec un md5 du path
441
+            $terminaison_dest = $terminaison;
442
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
443
+        } else {
444
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
445
+        }
446
+        $cache = sous_repertoire(_DIR_VAR, $cache);
447
+        $cache = sous_repertoire($cache, $effet);
448
+    } else {
449
+        $fichier_dest = md5("$identifiant-$effet");
450
+        $cache = sous_repertoire(_DIR_VAR, $cache);
451
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
452
+        $fichier_dest = substr($fichier_dest, 2);
453
+    }
454
+
455
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
456
+
457
+    $GLOBALS['images_calculees'][] = $fichier_dest;
458
+
459
+    $creer = true;
460
+    // si recalcul des images demande, recalculer chaque image une fois
461
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
462
+        $images_recalcul[$fichier_dest] = true;
463
+    } else {
464
+        if (@file_exists($f = $fichier_dest)) {
465
+            if (filemtime($f) >= $date_src) {
466
+                $creer = false;
467
+            }
468
+        } else {
469
+            if (
470
+                @file_exists($f = "$fichier_dest.src")
471
+                and lire_fichier($f, $valeurs)
472
+                and $valeurs = unserialize($valeurs)
473
+                and $valeurs['date'] >= $date_src
474
+            ) {
475
+                $creer = false;
476
+            }
477
+        }
478
+    }
479
+    if ($creer) {
480
+        if (!@file_exists($fichier)) {
481
+            if (!@file_exists("$fichier.src")) {
482
+                spip_log("Image absente : $fichier");
483
+
484
+                return false;
485
+            }
486
+            # on reconstruit l'image source absente a partir de la chaine des .src
487
+            reconstruire_image_intermediaire($fichier);
488
+        }
489
+    }
490
+
491
+    if ($creer) {
492
+        spip_log(
493
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
494
+            'images' . _LOG_DEBUG
495
+        );
496
+    }
497
+
498
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
499
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
+    $ret['fichier'] = $fichier;
501
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
+    $ret['fichier_dest'] = $fichier_dest;
503
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
504
+    $ret['format_dest'] = $terminaison_dest;
505
+    $ret['date_src'] = $date_src;
506
+    $ret['creer'] = $creer;
507
+    $ret['class'] = extraire_attribut($img, 'class');
508
+    $ret['alt'] = extraire_attribut($img, 'alt');
509
+    $ret['style'] = extraire_attribut($img, 'style');
510
+    $ret['tag'] = $img;
511
+    if ($fonction_creation) {
512
+        $ret['reconstruction'] = $fonction_creation;
513
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
514
+        # cas de image_reduire qui finalement ne reduit pas l'image source
515
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
516
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
517
+    }
518
+
519
+    $ret = pipeline('image_preparer_filtre', [
520
+            'args' => [
521
+                'img' => $img,
522
+                'effet' => $effet,
523
+                'forcer_format' => $forcer_format,
524
+                'fonction_creation' => $fonction_creation,
525
+                'find_in_path' => $find_in_path,
526
+            ],
527
+            'data' => $ret
528
+        ]);
529
+
530
+    // une globale pour le debug en cas de crash memoire
531
+    $GLOBALS['derniere_image_calculee'] = $ret;
532
+
533
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
534
+    if ($term_fonction === 'svg') {
535
+        if ($creer and !$support_svg) {
536
+            process_image_svg_identite($ret);
537
+            $ret['creer'] = false;
538
+        }
539
+    }
540
+    else {
541
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
542
+            return false;
543
+        }
544
+    }
545
+
546
+    return $ret;
547 547
 }
548 548
 
549 549
 
@@ -552,53 +552,53 @@  discard block
 block discarded – undo
552 552
  * @return array
553 553
  */
554 554
 function _image_extensions_acceptees_en_entree() {
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(',', $GLOBALS['meta']['gd_formats']));
561
-			$extensions = array_map('trim', $extensions);
562
-			$extensions = array_filter($extensions);
563
-			$extensions = array_unique($extensions);
564
-			if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
565
-			}
566
-		}
567
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
568
-	}
569
-
570
-	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(',', $GLOBALS['meta']['gd_formats']));
561
+            $extensions = array_map('trim', $extensions);
562
+            $extensions = array_filter($extensions);
563
+            $extensions = array_unique($extensions);
564
+            if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
565
+            }
566
+        }
567
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
568
+    }
569
+
570
+    return $extensions;
571 571
 }
572 572
 
573 573
 /**
574 574
  * @return array|string[]|null
575 575
  */
576 576
 function _image_extensions_acceptees_en_sortie() {
577
-	static $extensions = null;
578
-	if (empty($extensions)) {
579
-		$extensions = _image_extensions_acceptees_en_entree();
580
-		$extensions = array_diff($extensions, ['jpeg']);
581
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
582
-			$extensions = array_diff($extensions, ['gif']);
583
-		}
584
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
585
-			$extensions = array_diff($extensions, ['webp']);
586
-		}
587
-	}
588
-
589
-	return $extensions;
577
+    static $extensions = null;
578
+    if (empty($extensions)) {
579
+        $extensions = _image_extensions_acceptees_en_entree();
580
+        $extensions = array_diff($extensions, ['jpeg']);
581
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
582
+            $extensions = array_diff($extensions, ['gif']);
583
+        }
584
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
585
+            $extensions = array_diff($extensions, ['webp']);
586
+        }
587
+    }
588
+
589
+    return $extensions;
590 590
 }
591 591
 
592 592
 function _image_extension_normalisee($extension) {
593
-	$extension = strtolower($extension);
594
-	if ($extension === 'jpeg') {
595
-		$extension = 'jpg';
596
-	}
597
-	return $extension;
593
+    $extension = strtolower($extension);
594
+    if ($extension === 'jpeg') {
595
+        $extension = 'jpg';
596
+    }
597
+    return $extension;
598 598
 }
599 599
 
600 600
 function _image_extensions_conservent_transparence() {
601
-	return ['png', 'webp'];
601
+    return ['png', 'webp'];
602 602
 }
603 603
 
604 604
 
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
  * @return string
609 609
  */
610 610
 function _image_trouver_extension($path) {
611
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
612
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
613
-		$terminaison = strtolower($regs[1]);
614
-		return $terminaison;
615
-	}
616
-	return '';
611
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
612
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
613
+        $terminaison = strtolower($regs[1]);
614
+        return $terminaison;
615
+    }
616
+    return '';
617 617
 }
618 618
 
619 619
 /**
@@ -624,33 +624,33 @@  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
-	if (isset($info['mime'])) {
642
-		$mime = $info['mime'];
643
-	}
644
-	else {
645
-		$mime = image_type_to_mime_type($info[2]);
646
-	}
647
-
648
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
649
-	if ($_terminaison and $_terminaison !== $terminaison) {
650
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
651
-		$terminaison = $_terminaison;
652
-	}
653
-	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
+    if (isset($info['mime'])) {
642
+        $mime = $info['mime'];
643
+    }
644
+    else {
645
+        $mime = image_type_to_mime_type($info[2]);
646
+    }
647
+
648
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
649
+    if ($_terminaison and $_terminaison !== $terminaison) {
650
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
651
+        $terminaison = $_terminaison;
652
+    }
653
+    return $terminaison;
654 654
 }
655 655
 
656 656
 /**
@@ -658,36 +658,36 @@  discard block
 block discarded – undo
658 658
  * @return string
659 659
  */
660 660
 function _image_trouver_extension_depuis_mime($mime) {
661
-	switch (strtolower($mime)) {
662
-		case 'image/png':
663
-		case 'image/x-png':
664
-			$terminaison = 'png';
665
-			break;
666
-
667
-		case 'image/jpg':
668
-		case 'image/jpeg':
669
-		case 'image/pjpeg':
670
-			$terminaison = 'jpeg';
671
-			break;
672
-
673
-		case 'image/gif':
674
-			$terminaison = 'gif';
675
-			break;
676
-
677
-		case 'image/webp':
678
-		case 'image/x-webp':
679
-			$terminaison = 'webp';
680
-			break;
681
-
682
-		case 'image/svg+xml':
683
-			$terminaison = 'svg';
684
-			break;
685
-
686
-		default:
687
-			$terminaison = '';
688
-	}
689
-
690
-	return $terminaison;
661
+    switch (strtolower($mime)) {
662
+        case 'image/png':
663
+        case 'image/x-png':
664
+            $terminaison = 'png';
665
+            break;
666
+
667
+        case 'image/jpg':
668
+        case 'image/jpeg':
669
+        case 'image/pjpeg':
670
+            $terminaison = 'jpeg';
671
+            break;
672
+
673
+        case 'image/gif':
674
+            $terminaison = 'gif';
675
+            break;
676
+
677
+        case 'image/webp':
678
+        case 'image/x-webp':
679
+            $terminaison = 'webp';
680
+            break;
681
+
682
+        case 'image/svg+xml':
683
+            $terminaison = 'svg';
684
+            break;
685
+
686
+        default:
687
+            $terminaison = '';
688
+    }
689
+
690
+    return $terminaison;
691 691
 }
692 692
 
693 693
 
@@ -707,18 +707,18 @@  discard block
 block discarded – undo
707 707
  *     Une ressource de type Image GD.
708 708
  */
709 709
 function _imagecreatefrom_func(string $func, string $filename) {
710
-	if (!function_exists($func)) {
711
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
712
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
713
-		return null;
714
-	}
715
-	$img = @$func($filename);
716
-	if (!$img) {
717
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
718
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
719
-		$img = imagecreate(10, 10);
720
-	}
721
-	return $img;
710
+    if (!function_exists($func)) {
711
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
712
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
713
+        return null;
714
+    }
715
+    $img = @$func($filename);
716
+    if (!$img) {
717
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
718
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
719
+        $img = imagecreate(10, 10);
720
+    }
721
+    return $img;
722 722
 }
723 723
 
724 724
 /**
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
  *     Une ressource de type Image GD.
735 735
  */
736 736
 function _imagecreatefromjpeg($filename) {
737
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
737
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
738 738
 }
739 739
 
740 740
 /**
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
  *     Une ressource de type Image GD.
751 751
  */
752 752
 function _imagecreatefrompng($filename) {
753
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
753
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
754 754
 }
755 755
 
756 756
 /**
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
  *     Une ressource de type Image GD.
767 767
  */
768 768
 function _imagecreatefromgif($filename) {
769
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
769
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
770 770
 }
771 771
 
772 772
 
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
  *     Une ressource de type Image GD.
784 784
  */
785 785
 function _imagecreatefromwebp($filename) {
786
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
786
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
787 787
 }
788 788
 
789 789
 /**
@@ -801,24 +801,24 @@  discard block
 block discarded – undo
801 801
  *     - true si une image est bien retournée.
802 802
  */
803 803
 function _image_imagepng($img, $fichier) {
804
-	if (!function_exists('imagepng')) {
805
-		return false;
806
-	}
807
-	$tmp = $fichier . '.tmp';
808
-	$ret = imagepng($img, $tmp);
809
-	if (file_exists($tmp)) {
810
-		$taille_test = getimagesize($tmp);
811
-		if ($taille_test[0] < 1) {
812
-			return false;
813
-		}
814
-
815
-		spip_unlink($fichier); // le fichier peut deja exister
816
-		@rename($tmp, $fichier);
817
-
818
-		return $ret;
819
-	}
820
-
821
-	return false;
804
+    if (!function_exists('imagepng')) {
805
+        return false;
806
+    }
807
+    $tmp = $fichier . '.tmp';
808
+    $ret = imagepng($img, $tmp);
809
+    if (file_exists($tmp)) {
810
+        $taille_test = getimagesize($tmp);
811
+        if ($taille_test[0] < 1) {
812
+            return false;
813
+        }
814
+
815
+        spip_unlink($fichier); // le fichier peut deja exister
816
+        @rename($tmp, $fichier);
817
+
818
+        return $ret;
819
+    }
820
+
821
+    return false;
822 822
 }
823 823
 
824 824
 /**
@@ -836,24 +836,24 @@  discard block
 block discarded – undo
836 836
  *     - true si une image est bien retournée.
837 837
  */
838 838
 function _image_imagegif($img, $fichier) {
839
-	if (!function_exists('imagegif')) {
840
-		return false;
841
-	}
842
-	$tmp = $fichier . '.tmp';
843
-	$ret = imagegif($img, $tmp);
844
-	if (file_exists($tmp)) {
845
-		$taille_test = getimagesize($tmp);
846
-		if ($taille_test[0] < 1) {
847
-			return false;
848
-		}
849
-
850
-		spip_unlink($fichier); // le fichier peut deja exister
851
-		@rename($tmp, $fichier);
852
-
853
-		return $ret;
854
-	}
855
-
856
-	return false;
839
+    if (!function_exists('imagegif')) {
840
+        return false;
841
+    }
842
+    $tmp = $fichier . '.tmp';
843
+    $ret = imagegif($img, $tmp);
844
+    if (file_exists($tmp)) {
845
+        $taille_test = getimagesize($tmp);
846
+        if ($taille_test[0] < 1) {
847
+            return false;
848
+        }
849
+
850
+        spip_unlink($fichier); // le fichier peut deja exister
851
+        @rename($tmp, $fichier);
852
+
853
+        return $ret;
854
+    }
855
+
856
+    return false;
857 857
 }
858 858
 
859 859
 /**
@@ -876,29 +876,29 @@  discard block
 block discarded – undo
876 876
  *     - true si une image est bien retournée.
877 877
  */
878 878
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
879
-	if (!function_exists('imagejpeg')) {
880
-		return false;
881
-	}
882
-	$tmp = $fichier . '.tmp';
879
+    if (!function_exists('imagejpeg')) {
880
+        return false;
881
+    }
882
+    $tmp = $fichier . '.tmp';
883 883
 
884
-	// Enable interlancing
885
-	imageinterlace($img, true);
884
+    // Enable interlancing
885
+    imageinterlace($img, true);
886 886
 
887
-	$ret = imagejpeg($img, $tmp, $qualite);
887
+    $ret = imagejpeg($img, $tmp, $qualite);
888 888
 
889
-	if (file_exists($tmp)) {
890
-		$taille_test = getimagesize($tmp);
891
-		if ($taille_test[0] < 1) {
892
-			return false;
893
-		}
889
+    if (file_exists($tmp)) {
890
+        $taille_test = getimagesize($tmp);
891
+        if ($taille_test[0] < 1) {
892
+            return false;
893
+        }
894 894
 
895
-		spip_unlink($fichier); // le fichier peut deja exister
896
-		@rename($tmp, $fichier);
895
+        spip_unlink($fichier); // le fichier peut deja exister
896
+        @rename($tmp, $fichier);
897 897
 
898
-		return $ret;
899
-	}
898
+        return $ret;
899
+    }
900 900
 
901
-	return false;
901
+    return false;
902 902
 }
903 903
 
904 904
 /**
@@ -916,9 +916,9 @@  discard block
 block discarded – undo
916 916
  *     true si le fichier a bien été créé ; false sinon.
917 917
  */
918 918
 function _image_imageico($img, $fichier) {
919
-	$gd_image_array = [$img];
919
+    $gd_image_array = [$img];
920 920
 
921
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
921
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
922 922
 }
923 923
 
924 924
 
@@ -937,24 +937,24 @@  discard block
 block discarded – undo
937 937
  *     - true si une image est bien retournée.
938 938
  */
939 939
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
940
-	if (!function_exists('imagewebp')) {
941
-		return false;
942
-	}
943
-	$tmp = $fichier . '.tmp';
944
-	$ret = imagewebp($img, $tmp, $qualite);
945
-	if (file_exists($tmp)) {
946
-		$taille_test = getimagesize($tmp);
947
-		if ($taille_test[0] < 1) {
948
-			return false;
949
-		}
950
-
951
-		spip_unlink($fichier); // le fichier peut deja exister
952
-		@rename($tmp, $fichier);
953
-
954
-		return $ret;
955
-	}
956
-
957
-	return false;
940
+    if (!function_exists('imagewebp')) {
941
+        return false;
942
+    }
943
+    $tmp = $fichier . '.tmp';
944
+    $ret = imagewebp($img, $tmp, $qualite);
945
+    if (file_exists($tmp)) {
946
+        $taille_test = getimagesize($tmp);
947
+        if ($taille_test[0] < 1) {
948
+            return false;
949
+        }
950
+
951
+        spip_unlink($fichier); // le fichier peut deja exister
952
+        @rename($tmp, $fichier);
953
+
954
+        return $ret;
955
+    }
956
+
957
+    return false;
958 958
 }
959 959
 
960 960
 /**
@@ -974,35 +974,35 @@  discard block
 block discarded – undo
974 974
  */
975 975
 function _image_imagesvg($img, $fichier) {
976 976
 
977
-	$tmp = $fichier . '.tmp';
978
-	if (strpos($img, '<') === false) {
979
-		$img = supprimer_timestamp($img);
980
-		if (!file_exists($img)) {
981
-			return false;
982
-		}
983
-		@copy($img, $tmp);
984
-		if (filesize($tmp) == filesize($img)) {
985
-			spip_unlink($fichier); // le fichier peut deja exister
986
-			@rename($tmp, $fichier);
987
-			return true;
988
-		}
989
-		return false;
990
-	}
991
-
992
-	file_put_contents($tmp, $img);
993
-	if (file_exists($tmp)) {
994
-		$taille_test = spip_getimagesize($tmp);
995
-		if ($taille_test[0] < 1) {
996
-			return false;
997
-		}
998
-
999
-		spip_unlink($fichier); // le fichier peut deja exister
1000
-		@rename($tmp, $fichier);
1001
-
1002
-		return true;
1003
-	}
1004
-
1005
-	return false;
977
+    $tmp = $fichier . '.tmp';
978
+    if (strpos($img, '<') === false) {
979
+        $img = supprimer_timestamp($img);
980
+        if (!file_exists($img)) {
981
+            return false;
982
+        }
983
+        @copy($img, $tmp);
984
+        if (filesize($tmp) == filesize($img)) {
985
+            spip_unlink($fichier); // le fichier peut deja exister
986
+            @rename($tmp, $fichier);
987
+            return true;
988
+        }
989
+        return false;
990
+    }
991
+
992
+    file_put_contents($tmp, $img);
993
+    if (file_exists($tmp)) {
994
+        $taille_test = spip_getimagesize($tmp);
995
+        if ($taille_test[0] < 1) {
996
+            return false;
997
+        }
998
+
999
+        spip_unlink($fichier); // le fichier peut deja exister
1000
+        @rename($tmp, $fichier);
1001
+
1002
+        return true;
1003
+    }
1004
+
1005
+    return false;
1006 1006
 }
1007 1007
 
1008 1008
 
@@ -1030,29 +1030,29 @@  discard block
 block discarded – undo
1030 1030
  *     - false sinon.
1031 1031
  */
1032 1032
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1033
-	if (is_null($fonction)) {
1034
-		$fonction = '_image_image' . $valeurs['format_dest'];
1035
-	}
1036
-	$ret = false;
1037
-	#un flag pour reperer les images gravees
1038
-	$lock =
1039
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1040
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1041
-	if (
1042
-		function_exists($fonction)
1043
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1044
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1045
-		&& !$lock
1046
-	) {
1047
-		if (@file_exists($valeurs['fichier_dest'])) {
1048
-			// dans tous les cas mettre a jour la taille de l'image finale
1049
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1050
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1051
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1052
-		}
1053
-	}
1054
-
1055
-	return $ret;
1033
+    if (is_null($fonction)) {
1034
+        $fonction = '_image_image' . $valeurs['format_dest'];
1035
+    }
1036
+    $ret = false;
1037
+    #un flag pour reperer les images gravees
1038
+    $lock =
1039
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1040
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1041
+    if (
1042
+        function_exists($fonction)
1043
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1044
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1045
+        && !$lock
1046
+    ) {
1047
+        if (@file_exists($valeurs['fichier_dest'])) {
1048
+            // dans tous les cas mettre a jour la taille de l'image finale
1049
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1050
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1051
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1052
+        }
1053
+    }
1054
+
1055
+    return $ret;
1056 1056
 }
1057 1057
 
1058 1058
 /**
@@ -1065,27 +1065,27 @@  discard block
 block discarded – undo
1065 1065
  *     Chemin vers le fichier manquant
1066 1066
  **/
1067 1067
 function reconstruire_image_intermediaire($fichier_manquant) {
1068
-	$reconstruire = [];
1069
-	$fichier = $fichier_manquant;
1070
-	while (
1071
-		strpos($fichier, '://') === false
1072
-		and !@file_exists($fichier)
1073
-		and lire_fichier($src = "$fichier.src", $source)
1074
-		and $valeurs = unserialize($source)
1075
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1076
-	) {
1077
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1078
-		$reconstruire[] = $valeurs['reconstruction'];
1079
-	}
1080
-	while (count($reconstruire)) {
1081
-		$r = array_pop($reconstruire);
1082
-		$fonction = $r[0];
1083
-		$args = $r[1];
1084
-		call_user_func_array($fonction, $args);
1085
-	}
1086
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1087
-	// mais l'on peut nettoyer les miettes de sa creation
1088
-	ramasse_miettes($fichier_manquant);
1068
+    $reconstruire = [];
1069
+    $fichier = $fichier_manquant;
1070
+    while (
1071
+        strpos($fichier, '://') === false
1072
+        and !@file_exists($fichier)
1073
+        and lire_fichier($src = "$fichier.src", $source)
1074
+        and $valeurs = unserialize($source)
1075
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1076
+    ) {
1077
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1078
+        $reconstruire[] = $valeurs['reconstruction'];
1079
+    }
1080
+    while (count($reconstruire)) {
1081
+        $r = array_pop($reconstruire);
1082
+        $fonction = $r[0];
1083
+        $args = $r[1];
1084
+        call_user_func_array($fonction, $args);
1085
+    }
1086
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1087
+    // mais l'on peut nettoyer les miettes de sa creation
1088
+    ramasse_miettes($fichier_manquant);
1089 1089
 }
1090 1090
 
1091 1091
 /**
@@ -1105,28 +1105,28 @@  discard block
 block discarded – undo
1105 1105
  *     Chemin du fichier d'image calculé
1106 1106
  **/
1107 1107
 function ramasse_miettes($fichier) {
1108
-	if (
1109
-		strpos($fichier, '://') !== false
1110
-		or !lire_fichier($src = "$fichier.src", $source)
1111
-		or !$valeurs = unserialize($source)
1112
-	) {
1113
-		return;
1114
-	}
1115
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1116
-	while (
1117
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1118
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1119
-		and (lire_fichier(
1120
-			$src = "$fichier.src",
1121
-			$source
1122
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1123
-		and ($valeurs = unserialize($source))  # et valide
1124
-	) {
1125
-		# on efface le fichier
1126
-		spip_unlink($fichier);
1127
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1128
-		#spip_unlink($src);
1129
-	}
1108
+    if (
1109
+        strpos($fichier, '://') !== false
1110
+        or !lire_fichier($src = "$fichier.src", $source)
1111
+        or !$valeurs = unserialize($source)
1112
+    ) {
1113
+        return;
1114
+    }
1115
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1116
+    while (
1117
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1118
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1119
+        and (lire_fichier(
1120
+            $src = "$fichier.src",
1121
+            $source
1122
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1123
+        and ($valeurs = unserialize($source))  # et valide
1124
+    ) {
1125
+        # on efface le fichier
1126
+        spip_unlink($fichier);
1127
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1128
+        #spip_unlink($src);
1129
+    }
1130 1130
 }
1131 1131
 
1132 1132
 
@@ -1151,71 +1151,71 @@  discard block
 block discarded – undo
1151 1151
  *     Code HTML de l'image
1152 1152
  **/
1153 1153
 function image_graver($img) {
1154
-	// appeler le filtre post_image_filtrer qui permet de faire
1155
-	// des traitements auto a la fin d'une serie de filtres
1156
-	$img = pipeline('post_image_filtrer', $img);
1157
-
1158
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1159
-	if (($p = strpos($fichier, '?')) !== false) {
1160
-		$fichier = substr($fichier, 0, $p);
1161
-	}
1162
-	if (strlen($fichier) < 1) {
1163
-		$fichier = $img;
1164
-	}
1165
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1166
-	# et qu'il ne s'agit pas d'une URL
1167
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1168
-		reconstruire_image_intermediaire($fichier);
1169
-	}
1170
-	ramasse_miettes($fichier);
1171
-
1172
-	// ajouter le timestamp si besoin
1173
-	if (strpos($fichier_ori, '?') === false) {
1174
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1175
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1176
-	}
1177
-
1178
-	return $img;
1154
+    // appeler le filtre post_image_filtrer qui permet de faire
1155
+    // des traitements auto a la fin d'une serie de filtres
1156
+    $img = pipeline('post_image_filtrer', $img);
1157
+
1158
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1159
+    if (($p = strpos($fichier, '?')) !== false) {
1160
+        $fichier = substr($fichier, 0, $p);
1161
+    }
1162
+    if (strlen($fichier) < 1) {
1163
+        $fichier = $img;
1164
+    }
1165
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1166
+    # et qu'il ne s'agit pas d'une URL
1167
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1168
+        reconstruire_image_intermediaire($fichier);
1169
+    }
1170
+    ramasse_miettes($fichier);
1171
+
1172
+    // ajouter le timestamp si besoin
1173
+    if (strpos($fichier_ori, '?') === false) {
1174
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1175
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1176
+    }
1177
+
1178
+    return $img;
1179 1179
 }
1180 1180
 
1181 1181
 
1182 1182
 if (!function_exists('imagepalettetotruecolor')) {
1183
-	/**
1184
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1185
-	 *
1186
-	 * @note Pour compatibilité avec PHP < 5.5
1187
-	 *
1188
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1189
-	 *
1190
-	 * @param ressource $img
1191
-	 * @return bool
1192
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
1193
-	 *     - false si la transformation ne peut être faite.
1194
-	 **/
1195
-	function imagepalettetotruecolor(&$img) {
1196
-		if (!$img or !function_exists('imagecreatetruecolor')) {
1197
-			return false;
1198
-		} elseif (!imageistruecolor($img)) {
1199
-			$w = imagesx($img);
1200
-			$h = imagesy($img);
1201
-			$img1 = imagecreatetruecolor($w, $h);
1202
-			//Conserver la transparence si possible
1203
-			if (function_exists('ImageCopyResampled')) {
1204
-				if (function_exists('imageAntiAlias')) {
1205
-					imageAntiAlias($img1, true);
1206
-				}
1207
-				@imagealphablending($img1, false);
1208
-				@imagesavealpha($img1, true);
1209
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1210
-			} else {
1211
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1212
-			}
1213
-
1214
-			$img = $img1;
1215
-		}
1216
-
1217
-		return true;
1218
-	}
1183
+    /**
1184
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1185
+     *
1186
+     * @note Pour compatibilité avec PHP < 5.5
1187
+     *
1188
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1189
+     *
1190
+     * @param ressource $img
1191
+     * @return bool
1192
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
1193
+     *     - false si la transformation ne peut être faite.
1194
+     **/
1195
+    function imagepalettetotruecolor(&$img) {
1196
+        if (!$img or !function_exists('imagecreatetruecolor')) {
1197
+            return false;
1198
+        } elseif (!imageistruecolor($img)) {
1199
+            $w = imagesx($img);
1200
+            $h = imagesy($img);
1201
+            $img1 = imagecreatetruecolor($w, $h);
1202
+            //Conserver la transparence si possible
1203
+            if (function_exists('ImageCopyResampled')) {
1204
+                if (function_exists('imageAntiAlias')) {
1205
+                    imageAntiAlias($img1, true);
1206
+                }
1207
+                @imagealphablending($img1, false);
1208
+                @imagesavealpha($img1, true);
1209
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1210
+            } else {
1211
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1212
+            }
1213
+
1214
+            $img = $img1;
1215
+        }
1216
+
1217
+        return true;
1218
+    }
1219 1219
 }
1220 1220
 
1221 1221
 /**
@@ -1242,34 +1242,34 @@  discard block
 block discarded – undo
1242 1242
  *     Code html modifié de la balise.
1243 1243
  **/
1244 1244
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1245
-	if ($style === false) {
1246
-		$style = extraire_attribut($tag, 'style');
1247
-	}
1248
-
1249
-	// enlever le width et height du style
1250
-	if ($style) {
1251
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1252
-	}
1253
-	if ($style and $style[0] === ';') {
1254
-		$style = substr($style, 1);
1255
-	}
1256
-
1257
-	// mettre des attributs de width et height sur les images,
1258
-	// ca accelere le rendu du navigateur
1259
-	// ca permet aux navigateurs de reserver la bonne taille
1260
-	// quand on a desactive l'affichage des images.
1261
-	$tag = inserer_attribut($tag, 'width', round($width));
1262
-	$tag = inserer_attribut($tag, 'height', round($height));
1263
-
1264
-	// attributs deprecies. Transformer en CSS
1265
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1266
-		$style = "margin:${espace}px;" . $style;
1267
-		$tag = inserer_attribut($tag, 'hspace', '');
1268
-	}
1269
-
1270
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1271
-
1272
-	return $tag;
1245
+    if ($style === false) {
1246
+        $style = extraire_attribut($tag, 'style');
1247
+    }
1248
+
1249
+    // enlever le width et height du style
1250
+    if ($style) {
1251
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1252
+    }
1253
+    if ($style and $style[0] === ';') {
1254
+        $style = substr($style, 1);
1255
+    }
1256
+
1257
+    // mettre des attributs de width et height sur les images,
1258
+    // ca accelere le rendu du navigateur
1259
+    // ca permet aux navigateurs de reserver la bonne taille
1260
+    // quand on a desactive l'affichage des images.
1261
+    $tag = inserer_attribut($tag, 'width', round($width));
1262
+    $tag = inserer_attribut($tag, 'height', round($height));
1263
+
1264
+    // attributs deprecies. Transformer en CSS
1265
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1266
+        $style = "margin:${espace}px;" . $style;
1267
+        $tag = inserer_attribut($tag, 'hspace', '');
1268
+    }
1269
+
1270
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1271
+
1272
+    return $tag;
1273 1273
 }
1274 1274
 
1275 1275
 
@@ -1295,72 +1295,72 @@  discard block
 block discarded – undo
1295 1295
  *     Retourne le code HTML de l'image
1296 1296
  **/
1297 1297
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1298
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1299
-
1300
-	// fermer les tags img pas bien fermes;
1301
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1302
-
1303
-	// le style
1304
-	$style = $valeurs['style'];
1305
-	if (isset($surcharge['style'])) {
1306
-		$style = $surcharge['style'];
1307
-		unset($surcharge['style']);
1308
-	}
1309
-
1310
-	// traiter specifiquement la largeur et la hauteur
1311
-	$width = $valeurs['largeur'];
1312
-	if (isset($surcharge['width'])) {
1313
-		$width = $surcharge['width'];
1314
-		unset($surcharge['width']);
1315
-	}
1316
-	$height = $valeurs['hauteur'];
1317
-	if (isset($surcharge['height'])) {
1318
-		$height = $surcharge['height'];
1319
-		unset($surcharge['height']);
1320
-	}
1321
-
1322
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1323
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1324
-	// on remplace toute les ref a src dans le tag
1325
-	$src = extraire_attribut($tag, 'src');
1326
-	if (isset($surcharge['src'])) {
1327
-		$tag = str_replace($src, $surcharge['src'], $tag);
1328
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1329
-		// pas garanti comme methode, mais mieux que rien
1330
-		if (strpos($src, '&') !== false) {
1331
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1332
-		}
1333
-		$src = $surcharge['src'];
1334
-		unset($surcharge['src']);
1335
-	}
1336
-
1337
-	$class = $valeurs['class'];
1338
-	if (isset($surcharge['class'])) {
1339
-		$class = $surcharge['class'];
1340
-		unset($surcharge['class']);
1341
-	}
1342
-	if (is_scalar($class) && strlen($class)) {
1343
-		$tag = inserer_attribut($tag, 'class', $class);
1344
-	}
1345
-
1346
-	if (count($surcharge)) {
1347
-		foreach ($surcharge as $attribut => $valeur) {
1348
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1349
-		}
1350
-	}
1351
-
1352
-	$tag = pipeline(
1353
-		'image_ecrire_tag_finir',
1354
-		[
1355
-			'args' => [
1356
-				'valeurs' => $valeurs,
1357
-				'surcharge' => $surcharge,
1358
-			],
1359
-			'data' => $tag
1360
-		]
1361
-	);
1362
-
1363
-	return $tag;
1298
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1299
+
1300
+    // fermer les tags img pas bien fermes;
1301
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1302
+
1303
+    // le style
1304
+    $style = $valeurs['style'];
1305
+    if (isset($surcharge['style'])) {
1306
+        $style = $surcharge['style'];
1307
+        unset($surcharge['style']);
1308
+    }
1309
+
1310
+    // traiter specifiquement la largeur et la hauteur
1311
+    $width = $valeurs['largeur'];
1312
+    if (isset($surcharge['width'])) {
1313
+        $width = $surcharge['width'];
1314
+        unset($surcharge['width']);
1315
+    }
1316
+    $height = $valeurs['hauteur'];
1317
+    if (isset($surcharge['height'])) {
1318
+        $height = $surcharge['height'];
1319
+        unset($surcharge['height']);
1320
+    }
1321
+
1322
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1323
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1324
+    // on remplace toute les ref a src dans le tag
1325
+    $src = extraire_attribut($tag, 'src');
1326
+    if (isset($surcharge['src'])) {
1327
+        $tag = str_replace($src, $surcharge['src'], $tag);
1328
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1329
+        // pas garanti comme methode, mais mieux que rien
1330
+        if (strpos($src, '&') !== false) {
1331
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1332
+        }
1333
+        $src = $surcharge['src'];
1334
+        unset($surcharge['src']);
1335
+    }
1336
+
1337
+    $class = $valeurs['class'];
1338
+    if (isset($surcharge['class'])) {
1339
+        $class = $surcharge['class'];
1340
+        unset($surcharge['class']);
1341
+    }
1342
+    if (is_scalar($class) && strlen($class)) {
1343
+        $tag = inserer_attribut($tag, 'class', $class);
1344
+    }
1345
+
1346
+    if (count($surcharge)) {
1347
+        foreach ($surcharge as $attribut => $valeur) {
1348
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1349
+        }
1350
+    }
1351
+
1352
+    $tag = pipeline(
1353
+        'image_ecrire_tag_finir',
1354
+        [
1355
+            'args' => [
1356
+                'valeurs' => $valeurs,
1357
+                'surcharge' => $surcharge,
1358
+            ],
1359
+            'data' => $tag
1360
+        ]
1361
+    );
1362
+
1363
+    return $tag;
1364 1364
 }
1365 1365
 
1366 1366
 /**
@@ -1383,259 +1383,259 @@  discard block
 block discarded – undo
1383 1383
  *     Description de l'image, sinon null.
1384 1384
  **/
1385 1385
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1386
-	$srcHeight = null;
1387
-	$retour = [];
1388
-	// ordre de preference des formats graphiques pour creer les vignettes
1389
-	// le premier format disponible, selon la methode demandee, est utilise
1390
-	$image = $valeurs['fichier'];
1391
-	$format = $valeurs['format_source'];
1392
-	$destdir = dirname($valeurs['fichier_dest']);
1393
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1394
-
1395
-	$format_sortie = $valeurs['format_dest'];
1396
-
1397
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1398
-		$process = $GLOBALS['meta']['image_process'];
1399
-	}
1400
-
1401
-	// si le doc n'est pas une image dans un format accetpable, refuser
1402
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1403
-		return;
1404
-	}
1405
-	$destination = "$destdir/$destfile";
1406
-
1407
-	// calculer la taille
1408
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1409
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1410
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1411
-		}
1412
-	} elseif ($process == 'convert' or $process == 'imagick') {
1413
-		$destWidth = $maxWidth;
1414
-		$destHeight = $maxHeight;
1415
-	} else {
1416
-		spip_log("echec $process sur $image");
1417
-
1418
-		return;
1419
-	}
1420
-
1421
-	$vignette = '';
1422
-
1423
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1424
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1425
-		$vignette = $destination . '.' . $format;
1426
-		@copy($image, $vignette);
1427
-	}
1428
-
1429
-	elseif ($valeurs['format_source'] === 'svg') {
1430
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1431
-			$format_sortie = 'svg';
1432
-			$vignette = $destination . '.' . $format_sortie;
1433
-			$valeurs['fichier_dest'] = $vignette;
1434
-			_image_gd_output($svg, $valeurs);
1435
-		}
1436
-	}
1437
-
1438
-	// imagemagick en ligne de commande
1439
-	elseif ($process == 'convert') {
1440
-		if (!defined('_CONVERT_COMMAND')) {
1441
-			define('_CONVERT_COMMAND', 'convert');
1442
-		} // Securite : mes_options.php peut preciser le chemin absolu
1443
-		if (!defined('_RESIZE_COMMAND')) {
1444
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1445
-		}
1446
-		$vignette = $destination . '.' . $format_sortie;
1447
-		$commande = str_replace(
1448
-			['%x', '%y', '%src', '%dest'],
1449
-			[
1450
-				$destWidth,
1451
-				$destHeight,
1452
-				escapeshellcmd($image),
1453
-				escapeshellcmd($vignette)
1454
-			],
1455
-			_RESIZE_COMMAND
1456
-		);
1457
-		spip_log($commande);
1458
-		exec($commande);
1459
-		if (!@file_exists($vignette)) {
1460
-			spip_log("echec convert sur $vignette");
1461
-
1462
-			return;  // echec commande
1463
-		}
1464
-	}
1465
-
1466
-	// php5 imagemagick
1467
-	elseif ($process == 'imagick') {
1468
-		$vignette = "$destination." . $format_sortie;
1469
-
1470
-		if (!class_exists(\Imagick::class)) {
1471
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1472
-
1473
-			return;
1474
-		}
1475
-		$imagick = new Imagick();
1476
-		$imagick->readImage($image);
1477
-		$imagick->resizeImage(
1478
-			$destWidth,
1479
-			$destHeight,
1480
-			Imagick::FILTER_LANCZOS,
1481
-			1
1482
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1483
-		$imagick->writeImage($vignette);
1484
-
1485
-		if (!@file_exists($vignette)) {
1486
-			spip_log("echec imagick sur $vignette");
1487
-
1488
-			return;
1489
-		}
1490
-	}
1491
-
1492
-	// netpbm
1493
-	elseif ($process == 'netpbm') {
1494
-		if (!defined('_PNMSCALE_COMMAND')) {
1495
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1496
-		} // Securite : mes_options.php peut preciser le chemin absolu
1497
-		if (_PNMSCALE_COMMAND == '') {
1498
-			return;
1499
-		}
1500
-		$vignette = $destination . '.' . $format_sortie;
1501
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1502
-		if ($format == 'jpg') {
1503
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1504
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
-			if (!($s = @filesize($vignette))) {
1506
-				spip_unlink($vignette);
1507
-			}
1508
-			if (!@file_exists($vignette)) {
1509
-				spip_log("echec netpbm-jpg sur $vignette");
1510
-
1511
-				return;
1512
-			}
1513
-		} else {
1514
-			if ($format == 'gif') {
1515
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1516
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1517
-				if (!($s = @filesize($vignette))) {
1518
-					spip_unlink($vignette);
1519
-				}
1520
-				if (!@file_exists($vignette)) {
1521
-					spip_log("echec netpbm-gif sur $vignette");
1522
-
1523
-					return;
1524
-				}
1525
-			} else {
1526
-				if ($format == 'png') {
1527
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1528
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1529
-					if (!($s = @filesize($vignette))) {
1530
-						spip_unlink($vignette);
1531
-					}
1532
-					if (!@file_exists($vignette)) {
1533
-						spip_log("echec netpbm-png sur $vignette");
1534
-
1535
-						return;
1536
-					}
1537
-				}
1538
-			}
1539
-		}
1540
-	}
1541
-
1542
-	// gd ou gd2
1543
-	elseif ($process == 'gd1' or $process == 'gd2') {
1544
-		if (!function_exists('gd_info')) {
1545
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1546
-
1547
-			return;
1548
-		}
1549
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1550
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1551
-
1552
-			return;
1553
-		}
1554
-		$destFormat = $format_sortie;
1555
-		if (!$destFormat) {
1556
-			spip_log("pas de format pour $image");
1557
-
1558
-			return;
1559
-		}
1560
-
1561
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1562
-		if (!function_exists($fonction_imagecreatefrom)) {
1563
-			return '';
1564
-		}
1565
-		$srcImage = @$fonction_imagecreatefrom($image);
1566
-		if (!$srcImage) {
1567
-			spip_log('echec gd1/gd2');
1568
-
1569
-			return;
1570
-		}
1571
-
1572
-		// Initialisation de l'image destination
1573
-		$destImage = null;
1574
-		if ($process == 'gd2' and $destFormat != 'gif') {
1575
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1576
-		}
1577
-		if (!$destImage) {
1578
-			$destImage = ImageCreate($destWidth, $destHeight);
1579
-		}
1580
-
1581
-		// Recopie de l'image d'origine avec adaptation de la taille
1582
-		$ok = false;
1583
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1584
-			if ($format == 'gif') {
1585
-				// Si un GIF est transparent,
1586
-				// fabriquer un PNG transparent
1587
-				$transp = imagecolortransparent($srcImage);
1588
-				if ($transp > 0) {
1589
-					$destFormat = 'png';
1590
-				}
1591
-			}
1592
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1593
-				// Conserver la transparence
1594
-				if (function_exists('imageAntiAlias')) {
1595
-					imageAntiAlias($destImage, true);
1596
-				}
1597
-				@imagealphablending($destImage, false);
1598
-				@imagesavealpha($destImage, true);
1599
-			}
1600
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1601
-		}
1602
-		if (!$ok) {
1603
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1604
-		}
1605
-
1606
-		// Sauvegarde de l'image destination
1607
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1608
-		$valeurs['format_dest'] = $format = $destFormat;
1609
-		_image_gd_output($destImage, $valeurs);
1610
-
1611
-		if ($srcImage) {
1612
-			ImageDestroy($srcImage);
1613
-		}
1614
-		ImageDestroy($destImage);
1615
-	}
1616
-
1617
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1618
-		$size = [$destWidth, $destHeight];
1619
-	}
1620
-
1621
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1622
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1623
-	if ($size[0] < 1) {
1624
-		$size[0] = $destWidth;
1625
-	}
1626
-	if ($size[1] < 1) {
1627
-		$size[1] = $destHeight;
1628
-	}
1629
-
1630
-	$retour['width'] = $largeur = $size[0];
1631
-	$retour['height'] = $hauteur = $size[1];
1632
-
1633
-	$retour['fichier'] = $vignette;
1634
-	$retour['format'] = $format;
1635
-	$retour['date'] = @filemtime($vignette);
1636
-
1637
-	// renvoyer l'image
1638
-	return $retour;
1386
+    $srcHeight = null;
1387
+    $retour = [];
1388
+    // ordre de preference des formats graphiques pour creer les vignettes
1389
+    // le premier format disponible, selon la methode demandee, est utilise
1390
+    $image = $valeurs['fichier'];
1391
+    $format = $valeurs['format_source'];
1392
+    $destdir = dirname($valeurs['fichier_dest']);
1393
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1394
+
1395
+    $format_sortie = $valeurs['format_dest'];
1396
+
1397
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1398
+        $process = $GLOBALS['meta']['image_process'];
1399
+    }
1400
+
1401
+    // si le doc n'est pas une image dans un format accetpable, refuser
1402
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1403
+        return;
1404
+    }
1405
+    $destination = "$destdir/$destfile";
1406
+
1407
+    // calculer la taille
1408
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1409
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1410
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1411
+        }
1412
+    } elseif ($process == 'convert' or $process == 'imagick') {
1413
+        $destWidth = $maxWidth;
1414
+        $destHeight = $maxHeight;
1415
+    } else {
1416
+        spip_log("echec $process sur $image");
1417
+
1418
+        return;
1419
+    }
1420
+
1421
+    $vignette = '';
1422
+
1423
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1424
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1425
+        $vignette = $destination . '.' . $format;
1426
+        @copy($image, $vignette);
1427
+    }
1428
+
1429
+    elseif ($valeurs['format_source'] === 'svg') {
1430
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1431
+            $format_sortie = 'svg';
1432
+            $vignette = $destination . '.' . $format_sortie;
1433
+            $valeurs['fichier_dest'] = $vignette;
1434
+            _image_gd_output($svg, $valeurs);
1435
+        }
1436
+    }
1437
+
1438
+    // imagemagick en ligne de commande
1439
+    elseif ($process == 'convert') {
1440
+        if (!defined('_CONVERT_COMMAND')) {
1441
+            define('_CONVERT_COMMAND', 'convert');
1442
+        } // Securite : mes_options.php peut preciser le chemin absolu
1443
+        if (!defined('_RESIZE_COMMAND')) {
1444
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1445
+        }
1446
+        $vignette = $destination . '.' . $format_sortie;
1447
+        $commande = str_replace(
1448
+            ['%x', '%y', '%src', '%dest'],
1449
+            [
1450
+                $destWidth,
1451
+                $destHeight,
1452
+                escapeshellcmd($image),
1453
+                escapeshellcmd($vignette)
1454
+            ],
1455
+            _RESIZE_COMMAND
1456
+        );
1457
+        spip_log($commande);
1458
+        exec($commande);
1459
+        if (!@file_exists($vignette)) {
1460
+            spip_log("echec convert sur $vignette");
1461
+
1462
+            return;  // echec commande
1463
+        }
1464
+    }
1465
+
1466
+    // php5 imagemagick
1467
+    elseif ($process == 'imagick') {
1468
+        $vignette = "$destination." . $format_sortie;
1469
+
1470
+        if (!class_exists(\Imagick::class)) {
1471
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1472
+
1473
+            return;
1474
+        }
1475
+        $imagick = new Imagick();
1476
+        $imagick->readImage($image);
1477
+        $imagick->resizeImage(
1478
+            $destWidth,
1479
+            $destHeight,
1480
+            Imagick::FILTER_LANCZOS,
1481
+            1
1482
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1483
+        $imagick->writeImage($vignette);
1484
+
1485
+        if (!@file_exists($vignette)) {
1486
+            spip_log("echec imagick sur $vignette");
1487
+
1488
+            return;
1489
+        }
1490
+    }
1491
+
1492
+    // netpbm
1493
+    elseif ($process == 'netpbm') {
1494
+        if (!defined('_PNMSCALE_COMMAND')) {
1495
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1496
+        } // Securite : mes_options.php peut preciser le chemin absolu
1497
+        if (_PNMSCALE_COMMAND == '') {
1498
+            return;
1499
+        }
1500
+        $vignette = $destination . '.' . $format_sortie;
1501
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1502
+        if ($format == 'jpg') {
1503
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1504
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
+            if (!($s = @filesize($vignette))) {
1506
+                spip_unlink($vignette);
1507
+            }
1508
+            if (!@file_exists($vignette)) {
1509
+                spip_log("echec netpbm-jpg sur $vignette");
1510
+
1511
+                return;
1512
+            }
1513
+        } else {
1514
+            if ($format == 'gif') {
1515
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1516
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1517
+                if (!($s = @filesize($vignette))) {
1518
+                    spip_unlink($vignette);
1519
+                }
1520
+                if (!@file_exists($vignette)) {
1521
+                    spip_log("echec netpbm-gif sur $vignette");
1522
+
1523
+                    return;
1524
+                }
1525
+            } else {
1526
+                if ($format == 'png') {
1527
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1528
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1529
+                    if (!($s = @filesize($vignette))) {
1530
+                        spip_unlink($vignette);
1531
+                    }
1532
+                    if (!@file_exists($vignette)) {
1533
+                        spip_log("echec netpbm-png sur $vignette");
1534
+
1535
+                        return;
1536
+                    }
1537
+                }
1538
+            }
1539
+        }
1540
+    }
1541
+
1542
+    // gd ou gd2
1543
+    elseif ($process == 'gd1' or $process == 'gd2') {
1544
+        if (!function_exists('gd_info')) {
1545
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1546
+
1547
+            return;
1548
+        }
1549
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1550
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1551
+
1552
+            return;
1553
+        }
1554
+        $destFormat = $format_sortie;
1555
+        if (!$destFormat) {
1556
+            spip_log("pas de format pour $image");
1557
+
1558
+            return;
1559
+        }
1560
+
1561
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1562
+        if (!function_exists($fonction_imagecreatefrom)) {
1563
+            return '';
1564
+        }
1565
+        $srcImage = @$fonction_imagecreatefrom($image);
1566
+        if (!$srcImage) {
1567
+            spip_log('echec gd1/gd2');
1568
+
1569
+            return;
1570
+        }
1571
+
1572
+        // Initialisation de l'image destination
1573
+        $destImage = null;
1574
+        if ($process == 'gd2' and $destFormat != 'gif') {
1575
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1576
+        }
1577
+        if (!$destImage) {
1578
+            $destImage = ImageCreate($destWidth, $destHeight);
1579
+        }
1580
+
1581
+        // Recopie de l'image d'origine avec adaptation de la taille
1582
+        $ok = false;
1583
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1584
+            if ($format == 'gif') {
1585
+                // Si un GIF est transparent,
1586
+                // fabriquer un PNG transparent
1587
+                $transp = imagecolortransparent($srcImage);
1588
+                if ($transp > 0) {
1589
+                    $destFormat = 'png';
1590
+                }
1591
+            }
1592
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1593
+                // Conserver la transparence
1594
+                if (function_exists('imageAntiAlias')) {
1595
+                    imageAntiAlias($destImage, true);
1596
+                }
1597
+                @imagealphablending($destImage, false);
1598
+                @imagesavealpha($destImage, true);
1599
+            }
1600
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1601
+        }
1602
+        if (!$ok) {
1603
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1604
+        }
1605
+
1606
+        // Sauvegarde de l'image destination
1607
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1608
+        $valeurs['format_dest'] = $format = $destFormat;
1609
+        _image_gd_output($destImage, $valeurs);
1610
+
1611
+        if ($srcImage) {
1612
+            ImageDestroy($srcImage);
1613
+        }
1614
+        ImageDestroy($destImage);
1615
+    }
1616
+
1617
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1618
+        $size = [$destWidth, $destHeight];
1619
+    }
1620
+
1621
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1622
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1623
+    if ($size[0] < 1) {
1624
+        $size[0] = $destWidth;
1625
+    }
1626
+    if ($size[1] < 1) {
1627
+        $size[1] = $destHeight;
1628
+    }
1629
+
1630
+    $retour['width'] = $largeur = $size[0];
1631
+    $retour['height'] = $hauteur = $size[1];
1632
+
1633
+    $retour['fichier'] = $vignette;
1634
+    $retour['format'] = $format;
1635
+    $retour['date'] = @filemtime($vignette);
1636
+
1637
+    // renvoyer l'image
1638
+    return $retour;
1639 1639
 }
1640 1640
 
1641 1641
 /**
@@ -1655,25 +1655,25 @@  discard block
 block discarded – undo
1655 1655
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1656 1656
  **/
1657 1657
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1658
-	$ratioWidth = $srcWidth / $maxWidth;
1659
-	$ratioHeight = $srcHeight / $maxHeight;
1660
-
1661
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1662
-		$destWidth = $srcWidth;
1663
-		$destHeight = $srcHeight;
1664
-	} elseif ($ratioWidth < $ratioHeight) {
1665
-		$destWidth = $srcWidth / $ratioHeight;
1666
-		$destHeight = $maxHeight;
1667
-	} else {
1668
-		$destWidth = $maxWidth;
1669
-		$destHeight = $srcHeight / $ratioWidth;
1670
-	}
1671
-
1672
-	return [
1673
-		intval(round($destWidth)),
1674
-		intval(round($destHeight)),
1675
-		max($ratioWidth, $ratioHeight)
1676
-	];
1658
+    $ratioWidth = $srcWidth / $maxWidth;
1659
+    $ratioHeight = $srcHeight / $maxHeight;
1660
+
1661
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1662
+        $destWidth = $srcWidth;
1663
+        $destHeight = $srcHeight;
1664
+    } elseif ($ratioWidth < $ratioHeight) {
1665
+        $destWidth = $srcWidth / $ratioHeight;
1666
+        $destHeight = $maxHeight;
1667
+    } else {
1668
+        $destWidth = $maxWidth;
1669
+        $destHeight = $srcHeight / $ratioWidth;
1670
+    }
1671
+
1672
+    return [
1673
+        intval(round($destWidth)),
1674
+        intval(round($destHeight)),
1675
+        max($ratioWidth, $ratioHeight)
1676
+    ];
1677 1677
 }
1678 1678
 
1679 1679
 /**
@@ -1693,25 +1693,25 @@  discard block
 block discarded – undo
1693 1693
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1694 1694
  **/
1695 1695
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1696
-	$ratioWidth = $srcWidth / $maxWidth;
1697
-	$ratioHeight = $srcHeight / $maxHeight;
1698
-
1699
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1700
-		$destWidth = $srcWidth;
1701
-		$destHeight = $srcHeight;
1702
-	} elseif ($ratioWidth > $ratioHeight) {
1703
-		$destWidth = $srcWidth / $ratioHeight;
1704
-		$destHeight = $maxHeight;
1705
-	} else {
1706
-		$destWidth = $maxWidth;
1707
-		$destHeight = $srcHeight / $ratioWidth;
1708
-	}
1709
-
1710
-	return [
1711
-		intval(round($destWidth)),
1712
-		intval(round($destHeight)),
1713
-		min($ratioWidth, $ratioHeight)
1714
-	];
1696
+    $ratioWidth = $srcWidth / $maxWidth;
1697
+    $ratioHeight = $srcHeight / $maxHeight;
1698
+
1699
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1700
+        $destWidth = $srcWidth;
1701
+        $destHeight = $srcHeight;
1702
+    } elseif ($ratioWidth > $ratioHeight) {
1703
+        $destWidth = $srcWidth / $ratioHeight;
1704
+        $destHeight = $maxHeight;
1705
+    } else {
1706
+        $destWidth = $maxWidth;
1707
+        $destHeight = $srcHeight / $ratioWidth;
1708
+    }
1709
+
1710
+    return [
1711
+        intval(round($destWidth)),
1712
+        intval(round($destHeight)),
1713
+        min($ratioWidth, $ratioHeight)
1714
+    ];
1715 1715
 }
1716 1716
 
1717 1717
 
@@ -1724,12 +1724,12 @@  discard block
 block discarded – undo
1724 1724
  * @return string
1725 1725
  */
1726 1726
 function process_image_svg_identite($image) {
1727
-	if ($image['creer']) {
1728
-		$source = $image['fichier'];
1729
-		_image_gd_output($source, $image);
1730
-	}
1727
+    if ($image['creer']) {
1728
+        $source = $image['fichier'];
1729
+        _image_gd_output($source, $image);
1730
+    }
1731 1731
 
1732
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1732
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1733 1733
 }
1734 1734
 
1735 1735
 
@@ -1762,111 +1762,111 @@  discard block
 block discarded – undo
1762 1762
  *     Code HTML de la balise img produite
1763 1763
  **/
1764 1764
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1765
-	$image = false;
1766
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1767
-		$process = $GLOBALS['meta']['image_process'];
1768
-	}
1769
-	# determiner le format de sortie
1770
-	$format_sortie = false; // le choix par defaut sera bon
1771
-	if ($process == 'netpbm') {
1772
-		$format_sortie = 'jpg';
1773
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1774
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1775
-		// on verifie que l'extension choisie est bonne (en principe oui)
1776
-		$gd_formats = formats_image_acceptables(true);
1777
-		if (
1778
-			is_array($image)
1779
-			and (!in_array($image['format_dest'], $gd_formats)
1780
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1781
-			)
1782
-		) {
1783
-			if ($image['format_source'] == 'jpg') {
1784
-				$formats_sortie = ['jpg', 'png', 'gif'];
1785
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1786
-			{
1787
-				$formats_sortie = ['png', 'jpg', 'gif'];
1788
-			}
1789
-			// Choisir le format destination
1790
-			// - on sauve de preference en JPEG (meilleure compression)
1791
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1792
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1793
-			# pas *ecrire*
1794
-			$format_sortie = '';
1795
-			foreach ($formats_sortie as $fmt) {
1796
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1797
-					$format_sortie = $fmt;
1798
-					break;
1799
-				}
1800
-			}
1801
-			$image = false;
1802
-		}
1803
-	}
1804
-
1805
-	if (!is_array($image)) {
1806
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1807
-	}
1808
-
1809
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1810
-		spip_log("image_reduire_src:pas de version locale de $img");
1811
-		// on peut resizer en mode html si on dispose des elements
1812
-		if (
1813
-			$srcw = extraire_attribut($img, 'width')
1814
-			and $srch = extraire_attribut($img, 'height')
1815
-		) {
1816
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1817
-
1818
-			return _image_tag_changer_taille($img, $w, $h);
1819
-		}
1820
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1821
-		// sous la forme style='max-width: NNpx;'
1822
-		return inserer_attribut(
1823
-			$img,
1824
-			'style',
1825
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1826
-		);
1827
-	}
1828
-
1829
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1830
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1831
-		if ($image['creer']) {
1832
-			@copy($image['fichier'], $image['fichier_dest']);
1833
-		}
1834
-
1835
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1836
-	}
1837
-
1838
-	if ($image['creer'] == false && !$force) {
1839
-		return _image_ecrire_tag(
1840
-			$image,
1841
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1842
-		);
1843
-	}
1844
-
1845
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1846
-		$destWidth = $image['largeur_dest'];
1847
-		$destHeight = $image['hauteur_dest'];
1848
-		$logo = $image['fichier'];
1849
-		$date = $image['date_src'];
1850
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1851
-
1852
-		if ($preview && $preview['fichier']) {
1853
-			$logo = $preview['fichier'];
1854
-			$destWidth = $preview['width'];
1855
-			$destHeight = $preview['height'];
1856
-			$date = $preview['date'];
1857
-		}
1858
-		// dans l'espace prive mettre un timestamp sur l'adresse
1859
-		// de l'image, de facon a tromper le cache du navigateur
1860
-		// quand on fait supprimer/reuploader un logo
1861
-		// (pas de filemtime si SAFE MODE)
1862
-		$date = test_espace_prive() ? ('?' . $date) : '';
1863
-
1864
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1865
-	}
1866
-	else {
1867
-		# BMP, tiff ... les redacteurs osent tout!
1868
-		return $img;
1869
-	}
1765
+    $image = false;
1766
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1767
+        $process = $GLOBALS['meta']['image_process'];
1768
+    }
1769
+    # determiner le format de sortie
1770
+    $format_sortie = false; // le choix par defaut sera bon
1771
+    if ($process == 'netpbm') {
1772
+        $format_sortie = 'jpg';
1773
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1774
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1775
+        // on verifie que l'extension choisie est bonne (en principe oui)
1776
+        $gd_formats = formats_image_acceptables(true);
1777
+        if (
1778
+            is_array($image)
1779
+            and (!in_array($image['format_dest'], $gd_formats)
1780
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1781
+            )
1782
+        ) {
1783
+            if ($image['format_source'] == 'jpg') {
1784
+                $formats_sortie = ['jpg', 'png', 'gif'];
1785
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1786
+            {
1787
+                $formats_sortie = ['png', 'jpg', 'gif'];
1788
+            }
1789
+            // Choisir le format destination
1790
+            // - on sauve de preference en JPEG (meilleure compression)
1791
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1792
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1793
+            # pas *ecrire*
1794
+            $format_sortie = '';
1795
+            foreach ($formats_sortie as $fmt) {
1796
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1797
+                    $format_sortie = $fmt;
1798
+                    break;
1799
+                }
1800
+            }
1801
+            $image = false;
1802
+        }
1803
+    }
1804
+
1805
+    if (!is_array($image)) {
1806
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1807
+    }
1808
+
1809
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1810
+        spip_log("image_reduire_src:pas de version locale de $img");
1811
+        // on peut resizer en mode html si on dispose des elements
1812
+        if (
1813
+            $srcw = extraire_attribut($img, 'width')
1814
+            and $srch = extraire_attribut($img, 'height')
1815
+        ) {
1816
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1817
+
1818
+            return _image_tag_changer_taille($img, $w, $h);
1819
+        }
1820
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1821
+        // sous la forme style='max-width: NNpx;'
1822
+        return inserer_attribut(
1823
+            $img,
1824
+            'style',
1825
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1826
+        );
1827
+    }
1828
+
1829
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1830
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1831
+        if ($image['creer']) {
1832
+            @copy($image['fichier'], $image['fichier_dest']);
1833
+        }
1834
+
1835
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1836
+    }
1837
+
1838
+    if ($image['creer'] == false && !$force) {
1839
+        return _image_ecrire_tag(
1840
+            $image,
1841
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1842
+        );
1843
+    }
1844
+
1845
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1846
+        $destWidth = $image['largeur_dest'];
1847
+        $destHeight = $image['hauteur_dest'];
1848
+        $logo = $image['fichier'];
1849
+        $date = $image['date_src'];
1850
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1851
+
1852
+        if ($preview && $preview['fichier']) {
1853
+            $logo = $preview['fichier'];
1854
+            $destWidth = $preview['width'];
1855
+            $destHeight = $preview['height'];
1856
+            $date = $preview['date'];
1857
+        }
1858
+        // dans l'espace prive mettre un timestamp sur l'adresse
1859
+        // de l'image, de facon a tromper le cache du navigateur
1860
+        // quand on fait supprimer/reuploader un logo
1861
+        // (pas de filemtime si SAFE MODE)
1862
+        $date = test_espace_prive() ? ('?' . $date) : '';
1863
+
1864
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1865
+    }
1866
+    else {
1867
+        # BMP, tiff ... les redacteurs osent tout!
1868
+        return $img;
1869
+    }
1870 1870
 }
1871 1871
 
1872 1872
 /**
@@ -1881,145 +1881,145 @@  discard block
 block discarded – undo
1881 1881
  */
1882 1882
 class phpthumb_functions {
1883 1883
 
1884
-	/**
1885
-	 * Retourne la couleur d'un pixel dans une image
1886
-	 *
1887
-	 * @param ressource $img
1888
-	 * @param int $x
1889
-	 * @param int $y
1890
-	 * @return array|bool
1891
-	 */
1892
-	public static function GetPixelColor(&$img, $x, $y) {
1893
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1894
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1895
-		}
1896
-		return false;
1897
-	}
1898
-
1899
-	/**
1900
-	 * Retourne un nombre dans une représentation en Little Endian
1901
-	 *
1902
-	 * @param int $number
1903
-	 * @param int $minbytes
1904
-	 * @return string
1905
-	 */
1906
-	public static function LittleEndian2String($number, $minbytes = 1) {
1907
-		$intstring = '';
1908
-		while ($number > 0) {
1909
-			$intstring = $intstring . chr($number & 255);
1910
-			$number >>= 8;
1911
-		}
1912
-
1913
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1914
-	}
1915
-
1916
-	/**
1917
-	 * Transforme une ressource GD en image au format ICO
1918
-	 *
1919
-	 * @param array $gd_image_array
1920
-	 *     Tableau de ressources d'images GD
1921
-	 * @return string
1922
-	 *     Image au format ICO
1923
-	 */
1924
-	public static function GD2ICOstring(&$gd_image_array) {
1925
-		foreach ($gd_image_array as $key => $gd_image) {
1926
-			$ImageWidths[$key] = ImageSX($gd_image);
1927
-			$ImageHeights[$key] = ImageSY($gd_image);
1928
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1929
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1930
-
1931
-			$icXOR[$key] = '';
1932
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1933
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1934
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1935
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1936
-					$r = $argb['red'];
1937
-					$g = $argb['green'];
1938
-					$b = $argb['blue'];
1939
-
1940
-					if ($bpp[$key] == 32) {
1941
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1942
-					} elseif ($bpp[$key] == 24) {
1943
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1944
-					}
1945
-
1946
-					if ($a < 128) {
1947
-						@$icANDmask[$key][$y] .= '1';
1948
-					} else {
1949
-						@$icANDmask[$key][$y] .= '0';
1950
-					}
1951
-				}
1952
-				// mask bits are 32-bit aligned per scanline
1953
-				while (strlen($icANDmask[$key][$y]) % 32) {
1954
-					$icANDmask[$key][$y] .= '0';
1955
-				}
1956
-			}
1957
-			$icAND[$key] = '';
1958
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1959
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1960
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1961
-				}
1962
-			}
1963
-		}
1964
-
1965
-		foreach ($gd_image_array as $key => $gd_image) {
1966
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1967
-
1968
-			// BITMAPINFOHEADER - 40 bytes
1969
-			$BitmapInfoHeader[$key] = '';
1970
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1971
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1972
-			// The biHeight member specifies the combined
1973
-			// height of the XOR and AND masks.
1974
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1975
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1976
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1977
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1978
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1979
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1980
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1981
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1982
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1983
-		}
1984
-
1985
-
1986
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1987
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1988
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1989
-
1990
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1991
-		foreach ($gd_image_array as $key => $gd_image) {
1992
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1993
-
1994
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1995
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1996
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1997
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1998
-
1999
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
2000
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
2001
-
2002
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
2003
-			$icondata .= phpthumb_functions::LittleEndian2String(
2004
-				$dwBytesInRes,
2005
-				4
2006
-			);     // dwBytesInRes;	// How many bytes in this resource?
2007
-
2008
-			$icondata .= phpthumb_functions::LittleEndian2String(
2009
-				$dwImageOffset,
2010
-				4
2011
-			);    // dwImageOffset;   // Where in the file is this image?
2012
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2013
-			$dwImageOffset += strlen($icXOR[$key]);
2014
-			$dwImageOffset += strlen($icAND[$key]);
2015
-		}
2016
-
2017
-		foreach ($gd_image_array as $key => $gd_image) {
2018
-			$icondata .= $BitmapInfoHeader[$key];
2019
-			$icondata .= $icXOR[$key];
2020
-			$icondata .= $icAND[$key];
2021
-		}
2022
-
2023
-		return $icondata;
2024
-	}
1884
+    /**
1885
+     * Retourne la couleur d'un pixel dans une image
1886
+     *
1887
+     * @param ressource $img
1888
+     * @param int $x
1889
+     * @param int $y
1890
+     * @return array|bool
1891
+     */
1892
+    public static function GetPixelColor(&$img, $x, $y) {
1893
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1894
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1895
+        }
1896
+        return false;
1897
+    }
1898
+
1899
+    /**
1900
+     * Retourne un nombre dans une représentation en Little Endian
1901
+     *
1902
+     * @param int $number
1903
+     * @param int $minbytes
1904
+     * @return string
1905
+     */
1906
+    public static function LittleEndian2String($number, $minbytes = 1) {
1907
+        $intstring = '';
1908
+        while ($number > 0) {
1909
+            $intstring = $intstring . chr($number & 255);
1910
+            $number >>= 8;
1911
+        }
1912
+
1913
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1914
+    }
1915
+
1916
+    /**
1917
+     * Transforme une ressource GD en image au format ICO
1918
+     *
1919
+     * @param array $gd_image_array
1920
+     *     Tableau de ressources d'images GD
1921
+     * @return string
1922
+     *     Image au format ICO
1923
+     */
1924
+    public static function GD2ICOstring(&$gd_image_array) {
1925
+        foreach ($gd_image_array as $key => $gd_image) {
1926
+            $ImageWidths[$key] = ImageSX($gd_image);
1927
+            $ImageHeights[$key] = ImageSY($gd_image);
1928
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1929
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1930
+
1931
+            $icXOR[$key] = '';
1932
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1933
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1934
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1935
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1936
+                    $r = $argb['red'];
1937
+                    $g = $argb['green'];
1938
+                    $b = $argb['blue'];
1939
+
1940
+                    if ($bpp[$key] == 32) {
1941
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1942
+                    } elseif ($bpp[$key] == 24) {
1943
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1944
+                    }
1945
+
1946
+                    if ($a < 128) {
1947
+                        @$icANDmask[$key][$y] .= '1';
1948
+                    } else {
1949
+                        @$icANDmask[$key][$y] .= '0';
1950
+                    }
1951
+                }
1952
+                // mask bits are 32-bit aligned per scanline
1953
+                while (strlen($icANDmask[$key][$y]) % 32) {
1954
+                    $icANDmask[$key][$y] .= '0';
1955
+                }
1956
+            }
1957
+            $icAND[$key] = '';
1958
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1959
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1960
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1961
+                }
1962
+            }
1963
+        }
1964
+
1965
+        foreach ($gd_image_array as $key => $gd_image) {
1966
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1967
+
1968
+            // BITMAPINFOHEADER - 40 bytes
1969
+            $BitmapInfoHeader[$key] = '';
1970
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1971
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1972
+            // The biHeight member specifies the combined
1973
+            // height of the XOR and AND masks.
1974
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1975
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1976
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1977
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1978
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1979
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1980
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1981
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1982
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1983
+        }
1984
+
1985
+
1986
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1987
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1988
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1989
+
1990
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1991
+        foreach ($gd_image_array as $key => $gd_image) {
1992
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1993
+
1994
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1995
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1996
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1997
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1998
+
1999
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
2000
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
2001
+
2002
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
2003
+            $icondata .= phpthumb_functions::LittleEndian2String(
2004
+                $dwBytesInRes,
2005
+                4
2006
+            );     // dwBytesInRes;	// How many bytes in this resource?
2007
+
2008
+            $icondata .= phpthumb_functions::LittleEndian2String(
2009
+                $dwImageOffset,
2010
+                4
2011
+            );    // dwImageOffset;   // Where in the file is this image?
2012
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
2013
+            $dwImageOffset += strlen($icXOR[$key]);
2014
+            $dwImageOffset += strlen($icAND[$key]);
2015
+        }
2016
+
2017
+        foreach ($gd_image_array as $key => $gd_image) {
2018
+            $icondata .= $BitmapInfoHeader[$key];
2019
+            $icondata .= $icXOR[$key];
2020
+            $icondata .= $icAND[$key];
2021
+        }
2022
+
2023
+        return $icondata;
2024
+    }
2025 2025
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 	$blue = dechex($blue);
44 44
 
45 45
 	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
46
+		$red = '0'.$red;
47 47
 	}
48 48
 	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
49
+		$green = '0'.$green;
50 50
 	}
51 51
 	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
52
+		$blue = '0'.$blue;
53 53
 	}
54 54
 
55 55
 	return "$red$green$blue";
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	$couleur = couleur_html_to_hex($couleur);
68 68
 	$couleur = ltrim($couleur, '#');
69 69
 	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
70
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
71 71
 	}
72 72
 	$retour = [];
73 73
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	$var_G = ($G / 255);
126 126
 	$var_B = ($B / 255);
127 127
 
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
128
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
129
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
130
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
131 131
 
132 132
 	$L = ($var_Max + $var_Min) / 2;
133 133
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
  */
190 190
 function _couleur_hsl_to_rgb($H, $S, $L) {
191 191
 	// helper
192
-	$hue_2_rgb = function ($v1, $v2, $vH) {
192
+	$hue_2_rgb = function($v1, $v2, $vH) {
193 193
 		if ($vH < 0) {
194 194
 			$vH += 1;
195 195
 		}
@@ -320,11 +320,11 @@  discard block
 block discarded – undo
320 320
 		$img = "<img src='$source' />";
321 321
 	} elseif (
322 322
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
323
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
323
+		and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])
324 324
 		and in_array($extension, _image_extensions_acceptees_en_entree())
325 325
 	) {
326 326
 		# gerer img src="data:....base64"
327
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
328 328
 		if (!file_exists($local)) {
329 329
 			ecrire_fichier($local, base64_decode($regs[2]));
330 330
 		}
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	// les protocoles web prennent au moins 3 lettres
342 342
 	if (tester_url_absolue($source)) {
343 343
 		include_spip('inc/distant');
344
-		$fichier = _DIR_RACINE . copie_locale($source);
344
+		$fichier = _DIR_RACINE.copie_locale($source);
345 345
 		if (!$fichier) {
346 346
 			return '';
347 347
 		}
@@ -439,9 +439,9 @@  discard block
 block discarded – undo
439 439
 			// on garde la terminaison initiale car image simplement copiee
440 440
 			// et on postfixe son nom avec un md5 du path
441 441
 			$terminaison_dest = $terminaison;
442
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
442
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
443 443
 		} else {
444
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
444
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
445 445
 		}
446 446
 		$cache = sous_repertoire(_DIR_VAR, $cache);
447 447
 		$cache = sous_repertoire($cache, $effet);
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		$fichier_dest = substr($fichier_dest, 2);
453 453
 	}
454 454
 
455
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
455
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
456 456
 
457 457
 	$GLOBALS['images_calculees'][] = $fichier_dest;
458 458
 
@@ -490,15 +490,15 @@  discard block
 block discarded – undo
490 490
 
491 491
 	if ($creer) {
492 492
 		spip_log(
493
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
494
-			'images' . _LOG_DEBUG
493
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
494
+			'images'._LOG_DEBUG
495 495
 		);
496 496
 	}
497 497
 
498 498
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
499
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
499
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
500 500
 	$ret['fichier'] = $fichier;
501
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
501
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
502 502
 	$ret['fichier_dest'] = $fichier_dest;
503 503
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
504 504
 	$ret['format_dest'] = $terminaison_dest;
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 
648 648
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
649 649
 	if ($_terminaison and $_terminaison !== $terminaison) {
650
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
650
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
651 651
 		$terminaison = $_terminaison;
652 652
 	}
653 653
 	return $terminaison;
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
 	if (!function_exists('imagepng')) {
805 805
 		return false;
806 806
 	}
807
-	$tmp = $fichier . '.tmp';
807
+	$tmp = $fichier.'.tmp';
808 808
 	$ret = imagepng($img, $tmp);
809 809
 	if (file_exists($tmp)) {
810 810
 		$taille_test = getimagesize($tmp);
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 	if (!function_exists('imagegif')) {
840 840
 		return false;
841 841
 	}
842
-	$tmp = $fichier . '.tmp';
842
+	$tmp = $fichier.'.tmp';
843 843
 	$ret = imagegif($img, $tmp);
844 844
 	if (file_exists($tmp)) {
845 845
 		$taille_test = getimagesize($tmp);
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 	if (!function_exists('imagejpeg')) {
880 880
 		return false;
881 881
 	}
882
-	$tmp = $fichier . '.tmp';
882
+	$tmp = $fichier.'.tmp';
883 883
 
884 884
 	// Enable interlancing
885 885
 	imageinterlace($img, true);
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
 	if (!function_exists('imagewebp')) {
941 941
 		return false;
942 942
 	}
943
-	$tmp = $fichier . '.tmp';
943
+	$tmp = $fichier.'.tmp';
944 944
 	$ret = imagewebp($img, $tmp, $qualite);
945 945
 	if (file_exists($tmp)) {
946 946
 		$taille_test = getimagesize($tmp);
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
  */
975 975
 function _image_imagesvg($img, $fichier) {
976 976
 
977
-	$tmp = $fichier . '.tmp';
977
+	$tmp = $fichier.'.tmp';
978 978
 	if (strpos($img, '<') === false) {
979 979
 		$img = supprimer_timestamp($img);
980 980
 		if (!file_exists($img)) {
@@ -1031,13 +1031,13 @@  discard block
 block discarded – undo
1031 1031
  */
1032 1032
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1033 1033
 	if (is_null($fonction)) {
1034
-		$fonction = '_image_image' . $valeurs['format_dest'];
1034
+		$fonction = '_image_image'.$valeurs['format_dest'];
1035 1035
 	}
1036 1036
 	$ret = false;
1037 1037
 	#un flag pour reperer les images gravees
1038 1038
 	$lock =
1039 1039
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1040
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1040
+	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'));
1041 1041
 	if (
1042 1042
 		function_exists($fonction)
1043 1043
 		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
 			// dans tous les cas mettre a jour la taille de l'image finale
1049 1049
 			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1050 1050
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1051
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1051
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1052 1052
 		}
1053 1053
 	}
1054 1054
 
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
 
1264 1264
 	// attributs deprecies. Transformer en CSS
1265 1265
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1266
-		$style = "margin:${espace}px;" . $style;
1266
+		$style = "margin:${espace}px;".$style;
1267 1267
 		$tag = inserer_attribut($tag, 'hspace', '');
1268 1268
 	}
1269 1269
 
@@ -1390,7 +1390,7 @@  discard block
 block discarded – undo
1390 1390
 	$image = $valeurs['fichier'];
1391 1391
 	$format = $valeurs['format_source'];
1392 1392
 	$destdir = dirname($valeurs['fichier_dest']);
1393
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1393
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1394 1394
 
1395 1395
 	$format_sortie = $valeurs['format_dest'];
1396 1396
 
@@ -1422,14 +1422,14 @@  discard block
 block discarded – undo
1422 1422
 
1423 1423
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1424 1424
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1425
-		$vignette = $destination . '.' . $format;
1425
+		$vignette = $destination.'.'.$format;
1426 1426
 		@copy($image, $vignette);
1427 1427
 	}
1428 1428
 
1429 1429
 	elseif ($valeurs['format_source'] === 'svg') {
1430 1430
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1431 1431
 			$format_sortie = 'svg';
1432
-			$vignette = $destination . '.' . $format_sortie;
1432
+			$vignette = $destination.'.'.$format_sortie;
1433 1433
 			$valeurs['fichier_dest'] = $vignette;
1434 1434
 			_image_gd_output($svg, $valeurs);
1435 1435
 		}
@@ -1441,9 +1441,9 @@  discard block
 block discarded – undo
1441 1441
 			define('_CONVERT_COMMAND', 'convert');
1442 1442
 		} // Securite : mes_options.php peut preciser le chemin absolu
1443 1443
 		if (!defined('_RESIZE_COMMAND')) {
1444
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1444
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1445 1445
 		}
1446
-		$vignette = $destination . '.' . $format_sortie;
1446
+		$vignette = $destination.'.'.$format_sortie;
1447 1447
 		$commande = str_replace(
1448 1448
 			['%x', '%y', '%src', '%dest'],
1449 1449
 			[
@@ -1459,13 +1459,13 @@  discard block
 block discarded – undo
1459 1459
 		if (!@file_exists($vignette)) {
1460 1460
 			spip_log("echec convert sur $vignette");
1461 1461
 
1462
-			return;  // echec commande
1462
+			return; // echec commande
1463 1463
 		}
1464 1464
 	}
1465 1465
 
1466 1466
 	// php5 imagemagick
1467 1467
 	elseif ($process == 'imagick') {
1468
-		$vignette = "$destination." . $format_sortie;
1468
+		$vignette = "$destination.".$format_sortie;
1469 1469
 
1470 1470
 		if (!class_exists(\Imagick::class)) {
1471 1471
 			spip_log('Classe Imagick absente !', _LOG_ERREUR);
@@ -1479,7 +1479,7 @@  discard block
 block discarded – undo
1479 1479
 			$destHeight,
1480 1480
 			Imagick::FILTER_LANCZOS,
1481 1481
 			1
1482
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1482
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1483 1483
 		$imagick->writeImage($vignette);
1484 1484
 
1485 1485
 		if (!@file_exists($vignette)) {
@@ -1497,11 +1497,11 @@  discard block
 block discarded – undo
1497 1497
 		if (_PNMSCALE_COMMAND == '') {
1498 1498
 			return;
1499 1499
 		}
1500
-		$vignette = $destination . '.' . $format_sortie;
1500
+		$vignette = $destination.'.'.$format_sortie;
1501 1501
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1502 1502
 		if ($format == 'jpg') {
1503 1503
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1504
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1504
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1505 1505
 			if (!($s = @filesize($vignette))) {
1506 1506
 				spip_unlink($vignette);
1507 1507
 			}
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
 		} else {
1514 1514
 			if ($format == 'gif') {
1515 1515
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1516
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1516
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1517 1517
 				if (!($s = @filesize($vignette))) {
1518 1518
 					spip_unlink($vignette);
1519 1519
 				}
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
 			} else {
1526 1526
 				if ($format == 'png') {
1527 1527
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1528
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1528
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1529 1529
 					if (!($s = @filesize($vignette))) {
1530 1530
 						spip_unlink($vignette);
1531 1531
 					}
@@ -1547,7 +1547,7 @@  discard block
 block discarded – undo
1547 1547
 			return;
1548 1548
 		}
1549 1549
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1550
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1550
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1551 1551
 
1552 1552
 			return;
1553 1553
 		}
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
 		// de l'image, de facon a tromper le cache du navigateur
1860 1860
 		// quand on fait supprimer/reuploader un logo
1861 1861
 		// (pas de filemtime si SAFE MODE)
1862
-		$date = test_espace_prive() ? ('?' . $date) : '';
1862
+		$date = test_espace_prive() ? ('?'.$date) : '';
1863 1863
 
1864 1864
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1865 1865
 	}
@@ -1906,7 +1906,7 @@  discard block
 block discarded – undo
1906 1906
 	public static function LittleEndian2String($number, $minbytes = 1) {
1907 1907
 		$intstring = '';
1908 1908
 		while ($number > 0) {
1909
-			$intstring = $intstring . chr($number & 255);
1909
+			$intstring = $intstring.chr($number & 255);
1910 1910
 			$number >>= 8;
1911 1911
 		}
1912 1912
 
@@ -1938,9 +1938,9 @@  discard block
 block discarded – undo
1938 1938
 					$b = $argb['blue'];
1939 1939
 
1940 1940
 					if ($bpp[$key] == 32) {
1941
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1941
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1942 1942
 					} elseif ($bpp[$key] == 24) {
1943
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1943
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1944 1944
 					}
1945 1945
 
1946 1946
 					if ($a < 128) {
@@ -1967,48 +1967,48 @@  discard block
 block discarded – undo
1967 1967
 
1968 1968
 			// BITMAPINFOHEADER - 40 bytes
1969 1969
 			$BitmapInfoHeader[$key] = '';
1970
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1971
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1970
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1971
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1972 1972
 			// The biHeight member specifies the combined
1973 1973
 			// height of the XOR and AND masks.
1974 1974
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1975
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1976
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1977
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1978
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1979
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1980
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1981
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1982
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1975
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1976
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1977
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1978
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1979
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1980
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1981
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1982
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1983 1983
 		}
1984 1984
 
1985 1985
 
1986
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1987
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1988
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1986
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1987
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1988
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1989 1989
 
1990 1990
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1991 1991
 		foreach ($gd_image_array as $key => $gd_image) {
1992 1992
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1993 1993
 
1994
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1995
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1996
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1997
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1994
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1995
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1996
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1997
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1998 1998
 
1999
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
2000
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1999
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
2000
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
2001 2001
 
2002 2002
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
2003 2003
 			$icondata .= phpthumb_functions::LittleEndian2String(
2004 2004
 				$dwBytesInRes,
2005 2005
 				4
2006
-			);     // dwBytesInRes;	// How many bytes in this resource?
2006
+			); // dwBytesInRes;	// How many bytes in this resource?
2007 2007
 
2008 2008
 			$icondata .= phpthumb_functions::LittleEndian2String(
2009 2009
 				$dwImageOffset,
2010 2010
 				4
2011
-			);    // dwImageOffset;   // Where in the file is this image?
2011
+			); // dwImageOffset;   // Where in the file is this image?
2012 2012
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2013 2013
 			$dwImageOffset += strlen($icXOR[$key]);
2014 2014
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/presentation_mini.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		$rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
189 189
 	}
190 190
 
191
-	return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
191
+	return $rejouer.(defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
192 192
 }
193 193
 
194 194
 /**
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 	//
235 235
 	if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
236 236
 		if ($vcs['vcs'] === 'GIT') {
237
-			$url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
237
+			$url = 'https://git.spip.net/spip/spip/commit/'.$vcs['commit'];
238 238
 		} elseif ($vcs['vcs'] === 'SVN') {
239
-			$url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
239
+			$url = 'https://core.spip.net/projects/spip/repository/revisions/'.$vcs['commit'];
240 240
 		} else {
241 241
 			$url = '';
242 242
 		}
@@ -246,14 +246,14 @@  discard block
 block discarded – undo
246 246
 			$commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
247 247
 		}
248 248
 		if ($vcs['branch']) {
249
-			$commit = $vcs['branch'] . ': ' . $commit;
249
+			$commit = $vcs['branch'].': '.$commit;
250 250
 		}
251 251
 		$version .= " {$vcs['vcs']} [$commit]";
252 252
 	}
253 253
 
254 254
 	// et la version de l'ecran de securite
255 255
 	$secu = defined('_ECRAN_SECURITE')
256
-		? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
256
+		? '<br />'._T('ecran_securite', ['version' => _ECRAN_SECURITE])
257 257
 		: '';
258 258
 
259 259
 	return _T(
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
 		[
262 262
 			'spip' => "<b>SPIP $version</b> ",
263 263
 			'lien_gpl' =>
264
-				"<a href='" . generer_url_ecrire(
264
+				"<a href='".generer_url_ecrire(
265 265
 					'aide',
266
-					'aide=licence&var_lang=' . $GLOBALS['spip_lang']
267
-				) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
266
+					'aide=licence&var_lang='.$GLOBALS['spip_lang']
267
+				)."' class=\"aide popin\">"._T('info_copyright_gpl').'</a>'
268 268
 		]
269 269
 	)
270 270
 	. $secu;
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 		$onfocus = '';
292 292
 	}
293 293
 
294
-	$form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
295
-	$form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
294
+	$form = '<input type="text" size="10" value="'.$recherche_aff.'" name="recherche" class="recherche" accesskey="r"'.$onfocus.' />';
295
+	$form .= "<input type='image' src='".chemin_image('rechercher-20.png')."' name='submit' class='submit' alt='"._T('info_rechercher')."' />";
296 296
 
297
-	return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
297
+	return "<div class='spip_recherche'>".generer_form_ecrire($page, $form.$complement, " method='get'").'</div>';
298 298
 }
Please login to merge, or discard this patch.
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Affichage
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @return string Code HTML
26 26
  */
27 27
 function debut_grand_cadre() {
28
- return "\n<div class = 'table_page'>\n";
28
+    return "\n<div class = 'table_page'>\n";
29 29
 }
30 30
 
31 31
 /**
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return string Code HTML
35 35
  */
36 36
 function fin_grand_cadre() {
37
- return "\n</div>";
37
+    return "\n</div>";
38 38
 }
39 39
 
40 40
 // Debut de la colonne de gauche
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
  * @return string Code HTML
50 50
  */
51 51
 function debut_gauche() {
52
-	return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n";
52
+    return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n";
53 53
 }
54 54
 
55 55
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
  * @return string Code HTML
59 59
  */
60 60
 function fin_gauche() {
61
- return "</div></div><br class = 'nettoyeur' />";
61
+    return "</div></div><br class = 'nettoyeur' />";
62 62
 }
63 63
 
64 64
 /**
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
  * @return string Code HTML
68 68
  */
69 69
 function creer_colonne_droite() {
70
-	static $deja_colonne_droite;
71
-	if ($deja_colonne_droite) {
72
-		return '';
73
-	}
74
-	$deja_colonne_droite = true;
70
+    static $deja_colonne_droite;
71
+    if ($deja_colonne_droite) {
72
+        return '';
73
+    }
74
+    $deja_colonne_droite = true;
75 75
 
76
-	return "\n</div><div id='extra' class='lat' role='complementary'>";
76
+    return "\n</div><div id='extra' class='lat' role='complementary'>";
77 77
 }
78 78
 
79 79
 /**
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
  * @return string Code HTML
83 83
  */
84 84
 function debut_droite() {
85
-	return liste_objets_bloques(_request('exec'))
86
-	. creer_colonne_droite()
87
-	. '</div>'
88
-	. "\n<div id='contenu'>";
85
+    return liste_objets_bloques(_request('exec'))
86
+    . creer_colonne_droite()
87
+    . '</div>'
88
+    . "\n<div id='contenu'>";
89 89
 }
90 90
 
91 91
 /**
@@ -107,31 +107,31 @@  discard block
 block discarded – undo
107 107
  *     Code HTML
108 108
  **/
109 109
 function liste_objets_bloques($exec, $contexte = [], $auteur = null) {
110
-	$res = '';
111
-	if ($GLOBALS['meta']['articles_modif'] != 'non') {
112
-		include_spip('inc/drapeau_edition');
113
-		if (is_null($auteur)) {
114
-			$auteur = $GLOBALS['visiteur_session'];
115
-		}
116
-		if (
117
-			$en_cours = trouver_objet_exec($exec)
118
-			and $en_cours['edition']
119
-			and $type = $en_cours['type']
120
-			and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']])
121
-				or $id = _request($en_cours['id_table_objet']))
122
-		) {
123
-			// marquer le fait que l'objet est ouvert en edition par toto
124
-			// a telle date ; une alerte sera donnee aux autres redacteurs
125
-			signale_edition($id, $auteur, $type);
126
-		}
127
-
128
-		$objets_ouverts = liste_drapeau_edition($auteur['id_auteur']);
129
-		if (count($objets_ouverts)) {
130
-			$res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]);
131
-		}
132
-	}
133
-
134
-	return $res;
110
+    $res = '';
111
+    if ($GLOBALS['meta']['articles_modif'] != 'non') {
112
+        include_spip('inc/drapeau_edition');
113
+        if (is_null($auteur)) {
114
+            $auteur = $GLOBALS['visiteur_session'];
115
+        }
116
+        if (
117
+            $en_cours = trouver_objet_exec($exec)
118
+            and $en_cours['edition']
119
+            and $type = $en_cours['type']
120
+            and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']])
121
+                or $id = _request($en_cours['id_table_objet']))
122
+        ) {
123
+            // marquer le fait que l'objet est ouvert en edition par toto
124
+            // a telle date ; une alerte sera donnee aux autres redacteurs
125
+            signale_edition($id, $auteur, $type);
126
+        }
127
+
128
+        $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']);
129
+        if (count($objets_ouverts)) {
130
+            $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]);
131
+        }
132
+    }
133
+
134
+    return $res;
135 135
 }
136 136
 
137 137
 
@@ -145,20 +145,20 @@  discard block
 block discarded – undo
145 145
  * @return string Code HTML
146 146
  **/
147 147
 function fin_page() {
148
-	include_spip('inc/pipelines');
149
-	// avec &var_profile=1 on a le tableau de mesures SQL
150
-	$debug = ((_request('exec') !== 'valider_xml')
151
-		and ((_request('var_mode') == 'debug')
152
-			or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps'])
153
-			and isset($_COOKIE['spip_admin'])));
154
-	$t = '</div><div id="pied"><div class="largeur">'
155
-		. recuperer_fond('prive/squelettes/inclure/pied')
156
-		. '</div>'
157
-		. '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page()
158
-		. ($debug ? erreur_squelette() : '')
159
-		. "</body></html>\n";
160
-
161
-	return f_queue($t);
148
+    include_spip('inc/pipelines');
149
+    // avec &var_profile=1 on a le tableau de mesures SQL
150
+    $debug = ((_request('exec') !== 'valider_xml')
151
+        and ((_request('var_mode') == 'debug')
152
+            or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps'])
153
+            and isset($_COOKIE['spip_admin'])));
154
+    $t = '</div><div id="pied"><div class="largeur">'
155
+        . recuperer_fond('prive/squelettes/inclure/pied')
156
+        . '</div>'
157
+        . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page()
158
+        . ($debug ? erreur_squelette() : '')
159
+        . "</body></html>\n";
160
+
161
+    return f_queue($t);
162 162
 }
163 163
 
164 164
 /**
@@ -173,22 +173,22 @@  discard block
 block discarded – undo
173 173
  * @return string Code HTML
174 174
  **/
175 175
 function html_tests_js() {
176
-	if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) {
177
-		// pour le pied de page (deja defini si on est validation XML)
178
-		define(
179
-			'_TESTER_NOSCRIPT',
180
-			"<noscript>\n<div style='display:none;'><img src='"
181
-			. generer_url_ecrire('test_ajax', 'js=-1')
182
-			. "' width='1' height='1' alt='' /></div></noscript>\n"
183
-		);
184
-	}
185
-
186
-	$rejouer = '';
187
-	if (defined('_SESSION_REJOUER')) {
188
-		$rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
189
-	}
190
-
191
-	return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
176
+    if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) {
177
+        // pour le pied de page (deja defini si on est validation XML)
178
+        define(
179
+            '_TESTER_NOSCRIPT',
180
+            "<noscript>\n<div style='display:none;'><img src='"
181
+            . generer_url_ecrire('test_ajax', 'js=-1')
182
+            . "' width='1' height='1' alt='' /></div></noscript>\n"
183
+        );
184
+    }
185
+
186
+    $rejouer = '';
187
+    if (defined('_SESSION_REJOUER')) {
188
+        $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
189
+    }
190
+
191
+    return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
192 192
 }
193 193
 
194 194
 /**
@@ -198,25 +198,25 @@  discard block
 block discarded – undo
198 198
  **/
199 199
 function info_maj_spip() {
200 200
 
201
-	$maj = $GLOBALS['meta']['info_maj_spip'] ?? null;
202
-	if (!$maj) {
203
-		return '';
204
-	}
201
+    $maj = $GLOBALS['meta']['info_maj_spip'] ?? null;
202
+    if (!$maj) {
203
+        return '';
204
+    }
205 205
 
206
-	$maj = explode('|', $maj);
207
-	// c'est une ancienne notif, on a fait la maj depuis !
208
-	if ($GLOBALS['spip_version_branche'] !== reset($maj)) {
209
-		return '';
210
-	}
206
+    $maj = explode('|', $maj);
207
+    // c'est une ancienne notif, on a fait la maj depuis !
208
+    if ($GLOBALS['spip_version_branche'] !== reset($maj)) {
209
+        return '';
210
+    }
211 211
 
212
-	if (!autoriser('webmestre')) {
213
-		return '';
214
-	}
212
+    if (!autoriser('webmestre')) {
213
+        return '';
214
+    }
215 215
 
216
-	array_shift($maj);
217
-	$maj = implode('|', $maj);
216
+    array_shift($maj);
217
+    $maj = implode('|', $maj);
218 218
 
219
-	return "$maj<br />";
219
+    return "$maj<br />";
220 220
 }
221 221
 
222 222
 /**
@@ -227,47 +227,47 @@  discard block
 block discarded – undo
227 227
  **/
228 228
 function info_copyright() {
229 229
 
230
-	$version = $GLOBALS['spip_version_affichee'];
231
-
232
-	//
233
-	// Mention, le cas echeant, de la revision SVN courante
234
-	//
235
-	if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
236
-		if ($vcs['vcs'] === 'GIT') {
237
-			$url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
238
-		} elseif ($vcs['vcs'] === 'SVN') {
239
-			$url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
240
-		} else {
241
-			$url = '';
242
-		}
243
-		// affichage "GIT [master: abcdef]"
244
-		$commit = $vcs['commit_short'] ?? $vcs['commit'];
245
-		if ($url) {
246
-			$commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
247
-		}
248
-		if ($vcs['branch']) {
249
-			$commit = $vcs['branch'] . ': ' . $commit;
250
-		}
251
-		$version .= " {$vcs['vcs']} [$commit]";
252
-	}
253
-
254
-	// et la version de l'ecran de securite
255
-	$secu = defined('_ECRAN_SECURITE')
256
-		? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
257
-		: '';
258
-
259
-	return _T(
260
-		'info_copyright',
261
-		[
262
-			'spip' => "<b>SPIP $version</b> ",
263
-			'lien_gpl' =>
264
-				"<a href='" . generer_url_ecrire(
265
-					'aide',
266
-					'aide=licence&var_lang=' . $GLOBALS['spip_lang']
267
-				) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
268
-		]
269
-	)
270
-	. $secu;
230
+    $version = $GLOBALS['spip_version_affichee'];
231
+
232
+    //
233
+    // Mention, le cas echeant, de la revision SVN courante
234
+    //
235
+    if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
236
+        if ($vcs['vcs'] === 'GIT') {
237
+            $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
238
+        } elseif ($vcs['vcs'] === 'SVN') {
239
+            $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
240
+        } else {
241
+            $url = '';
242
+        }
243
+        // affichage "GIT [master: abcdef]"
244
+        $commit = $vcs['commit_short'] ?? $vcs['commit'];
245
+        if ($url) {
246
+            $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
247
+        }
248
+        if ($vcs['branch']) {
249
+            $commit = $vcs['branch'] . ': ' . $commit;
250
+        }
251
+        $version .= " {$vcs['vcs']} [$commit]";
252
+    }
253
+
254
+    // et la version de l'ecran de securite
255
+    $secu = defined('_ECRAN_SECURITE')
256
+        ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
257
+        : '';
258
+
259
+    return _T(
260
+        'info_copyright',
261
+        [
262
+            'spip' => "<b>SPIP $version</b> ",
263
+            'lien_gpl' =>
264
+                "<a href='" . generer_url_ecrire(
265
+                    'aide',
266
+                    'aide=licence&var_lang=' . $GLOBALS['spip_lang']
267
+                ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
268
+        ]
269
+    )
270
+    . $secu;
271 271
 }
272 272
 
273 273
 /**
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
  * @return string             Code HTML
283 283
  **/
284 284
 function formulaire_recherche($page, $complement = '') {
285
-	$recherche = _request('recherche');
286
-	$recherche_aff = entites_html($recherche);
287
-	if (!strlen($recherche)) {
288
-		$recherche_aff = _T('info_rechercher');
289
-		$onfocus = " onfocus=\"this.value='';\"";
290
-	} else {
291
-		$onfocus = '';
292
-	}
293
-
294
-	$form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
295
-	$form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
296
-
297
-	return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
285
+    $recherche = _request('recherche');
286
+    $recherche_aff = entites_html($recherche);
287
+    if (!strlen($recherche)) {
288
+        $recherche_aff = _T('info_rechercher');
289
+        $onfocus = " onfocus=\"this.value='';\"";
290
+    } else {
291
+        $onfocus = '';
292
+    }
293
+
294
+    $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
295
+    $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
296
+
297
+    return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
298 298
 }
Please login to merge, or discard this patch.
ecrire/inc/minipres.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -193,11 +193,9 @@
 block discarded – undo
193 193
 
194 194
 		if ($statut and test_espace_prive()) {
195 195
 			$corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil'));
196
-		}
197
-		elseif (!empty($_COOKIE['spip_admin'])) {
196
+		} elseif (!empty($_COOKIE['spip_admin'])) {
198 197
 			$corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login'));
199
-		}
200
-		else {
198
+		} else {
201 199
 			$corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202 200
 		}
203 201
 		$corps = "<div class='boutons'>$corps</div>";
Please login to merge, or discard this patch.
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Minipres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/headers');
@@ -46,61 +46,61 @@  discard block
 block discarded – undo
46 46
  */
47 47
 function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) {
48 48
 
49
-	utiliser_langue_visiteur();
50
-
51
-	http_no_cache();
52
-
53
-	if ($titre == 'AUTO') {
54
-		$titre = _T('info_installation_systeme_publication');
55
-	}
56
-
57
-	# le charset est en utf-8, pour recuperer le nom comme il faut
58
-	# lors de l'installation
59
-	if (!headers_sent()) {
60
-		header('Content-Type: text/html; charset=utf-8');
61
-	}
62
-
63
-	$css = '';
64
-	$files = ['reset.css', 'clear.css', 'minipres.css'];
65
-	if ($all_inline) {
66
-		// inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande)
67
-		foreach ($files as $name) {
68
-			$file = direction_css(find_in_theme($name));
69
-			if (function_exists('compacte')) {
70
-				$file = compacte($file);
71
-			} else {
72
-				$file = url_absolue_css($file); // precaution
73
-			}
74
-			lire_fichier($file, $c);
75
-			$css .= $c;
76
-		}
77
-		$css = "<style type='text/css'>" . $css . '</style>';
78
-	} else {
79
-		foreach ($files as $name) {
80
-			$file = direction_css(find_in_theme($name));
81
-			$css .= "<link rel='stylesheet' href='$file' type='text/css' />\n";
82
-		}
83
-	}
84
-
85
-	// au cas ou minipres() est appele avant spip_initialisation_suite()
86
-	if (!defined('_DOCTYPE_ECRIRE')) {
87
-		define('_DOCTYPE_ECRIRE', '');
88
-	}
89
-
90
-	return _DOCTYPE_ECRIRE .
91
-	html_lang_attributes() .
92
-	"<head>\n" .
93
-	'<title>' .
94
-	textebrut($titre) .
95
-	"</title>\n" .
96
-	"<meta name='viewport' content='width=device-width' />\n" .
97
-	$css .
98
-	'</head>
49
+    utiliser_langue_visiteur();
50
+
51
+    http_no_cache();
52
+
53
+    if ($titre == 'AUTO') {
54
+        $titre = _T('info_installation_systeme_publication');
55
+    }
56
+
57
+    # le charset est en utf-8, pour recuperer le nom comme il faut
58
+    # lors de l'installation
59
+    if (!headers_sent()) {
60
+        header('Content-Type: text/html; charset=utf-8');
61
+    }
62
+
63
+    $css = '';
64
+    $files = ['reset.css', 'clear.css', 'minipres.css'];
65
+    if ($all_inline) {
66
+        // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande)
67
+        foreach ($files as $name) {
68
+            $file = direction_css(find_in_theme($name));
69
+            if (function_exists('compacte')) {
70
+                $file = compacte($file);
71
+            } else {
72
+                $file = url_absolue_css($file); // precaution
73
+            }
74
+            lire_fichier($file, $c);
75
+            $css .= $c;
76
+        }
77
+        $css = "<style type='text/css'>" . $css . '</style>';
78
+    } else {
79
+        foreach ($files as $name) {
80
+            $file = direction_css(find_in_theme($name));
81
+            $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n";
82
+        }
83
+    }
84
+
85
+    // au cas ou minipres() est appele avant spip_initialisation_suite()
86
+    if (!defined('_DOCTYPE_ECRIRE')) {
87
+        define('_DOCTYPE_ECRIRE', '');
88
+    }
89
+
90
+    return _DOCTYPE_ECRIRE .
91
+    html_lang_attributes() .
92
+    "<head>\n" .
93
+    '<title>' .
94
+    textebrut($titre) .
95
+    "</title>\n" .
96
+    "<meta name='viewport' content='width=device-width' />\n" .
97
+    $css .
98
+    '</head>
99 99
 <body' . $onLoad . " class='minipres'>
100 100
 	<div id='minipres'>
101 101
 	<h1>" .
102
-	$titre .
103
-	"</h1>
102
+    $titre .
103
+    "</h1>
104 104
 	<div>\n";
105 105
 }
106 106
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
  * @return string Code HTML
111 111
  */
112 112
 function install_fin_html() {
113
-	return "\n\t</div>\n\t</div>\n</body>\n</html>";
113
+    return "\n\t</div>\n\t</div>\n</body>\n</html>";
114 114
 }
115 115
 
116 116
 
@@ -148,77 +148,77 @@  discard block
 block discarded – undo
148 148
  */
149 149
 function minipres($titre = '', $corps = '', $options = []) {
150 150
 
151
-	// compat signature old
152
-	// minipres($titre='', $corps="", $onload='', $all_inline = false)
153
-	$args = func_get_args();
154
-	if (isset($args[2]) and is_string($args[2])) {
155
-		$options = ['onload' => $args[2]];
156
-	}
157
-	if (isset($args[3])) {
158
-		$options['all_inline'] = $args[3];
159
-	}
160
-
161
-	$options = array_merge([
162
-		'onload' => '',
163
-		'all_inline' => false,
164
-	], $options);
165
-
166
-	if (!defined('_AJAX')) {
167
-		define('_AJAX', false);
168
-	} // par securite
169
-	if (!$titre) {
170
-		if (!isset($options['status'])) {
171
-			$options['status'] = 403;
172
-		}
173
-		if (
174
-			!$titre = _request('action')
175
-			and !$titre = _request('exec')
176
-			and !$titre = _request('page')
177
-		) {
178
-			$titre = '?';
179
-		}
180
-
181
-		$titre = spip_htmlspecialchars($titre);
182
-
183
-		$titre = ($titre == 'install')
184
-			? _T('avis_espace_interdit')
185
-			: $titre . '&nbsp;: ' . _T('info_acces_interdit');
186
-
187
-		$statut = $GLOBALS['visiteur_session']['statut'] ?? '';
188
-		$nom = $GLOBALS['visiteur_session']['nom'] ?? '';
189
-
190
-		if ($statut != '0minirezo') {
191
-			$titre = _T('info_acces_interdit');
192
-		}
193
-
194
-		if ($statut and test_espace_prive()) {
195
-			$corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil'));
196
-		}
197
-		elseif (!empty($_COOKIE['spip_admin'])) {
198
-			$corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login'));
199
-		}
200
-		else {
201
-			$corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202
-		}
203
-		$corps = "<div class='boutons'>$corps</div>";
204
-		spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']);
205
-	}
206
-
207
-	if (!_AJAX) {
208
-		if (isset($options['status'])) {
209
-			http_response_code($options['status']);
210
-		}
211
-
212
-		return install_debut_html($titre, $options['onload'], $options['all_inline'])
213
-		. $corps
214
-		. install_fin_html();
215
-	} else {
216
-		include_spip('inc/headers');
217
-		include_spip('inc/actions');
218
-		$url = self('&', true);
219
-		foreach ($_POST as $v => $c) {
220
-			$url = parametre_url($url, $v, $c, '&');
221
-		}
222
-		ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
223
-	}
151
+    // compat signature old
152
+    // minipres($titre='', $corps="", $onload='', $all_inline = false)
153
+    $args = func_get_args();
154
+    if (isset($args[2]) and is_string($args[2])) {
155
+        $options = ['onload' => $args[2]];
156
+    }
157
+    if (isset($args[3])) {
158
+        $options['all_inline'] = $args[3];
159
+    }
160
+
161
+    $options = array_merge([
162
+        'onload' => '',
163
+        'all_inline' => false,
164
+    ], $options);
165
+
166
+    if (!defined('_AJAX')) {
167
+        define('_AJAX', false);
168
+    } // par securite
169
+    if (!$titre) {
170
+        if (!isset($options['status'])) {
171
+            $options['status'] = 403;
172
+        }
173
+        if (
174
+            !$titre = _request('action')
175
+            and !$titre = _request('exec')
176
+            and !$titre = _request('page')
177
+        ) {
178
+            $titre = '?';
179
+        }
180
+
181
+        $titre = spip_htmlspecialchars($titre);
182
+
183
+        $titre = ($titre == 'install')
184
+            ? _T('avis_espace_interdit')
185
+            : $titre . '&nbsp;: ' . _T('info_acces_interdit');
186
+
187
+        $statut = $GLOBALS['visiteur_session']['statut'] ?? '';
188
+        $nom = $GLOBALS['visiteur_session']['nom'] ?? '';
189
+
190
+        if ($statut != '0minirezo') {
191
+            $titre = _T('info_acces_interdit');
192
+        }
193
+
194
+        if ($statut and test_espace_prive()) {
195
+            $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil'));
196
+        }
197
+        elseif (!empty($_COOKIE['spip_admin'])) {
198
+            $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login'));
199
+        }
200
+        else {
201
+            $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202
+        }
203
+        $corps = "<div class='boutons'>$corps</div>";
204
+        spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']);
205
+    }
206
+
207
+    if (!_AJAX) {
208
+        if (isset($options['status'])) {
209
+            http_response_code($options['status']);
210
+        }
211
+
212
+        return install_debut_html($titre, $options['onload'], $options['all_inline'])
213
+        . $corps
214
+        . install_fin_html();
215
+    } else {
216
+        include_spip('inc/headers');
217
+        include_spip('inc/actions');
218
+        $url = self('&', true);
219
+        foreach ($_POST as $v => $c) {
220
+            $url = parametre_url($url, $v, $c, '&');
221
+        }
222
+        ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
223
+    }
224 224
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			lire_fichier($file, $c);
75 75
 			$css .= $c;
76 76
 		}
77
-		$css = "<style type='text/css'>" . $css . '</style>';
77
+		$css = "<style type='text/css'>".$css.'</style>';
78 78
 	} else {
79 79
 		foreach ($files as $name) {
80 80
 			$file = direction_css(find_in_theme($name));
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
 		define('_DOCTYPE_ECRIRE', '');
88 88
 	}
89 89
 
90
-	return _DOCTYPE_ECRIRE .
91
-	html_lang_attributes() .
92
-	"<head>\n" .
93
-	'<title>' .
94
-	textebrut($titre) .
95
-	"</title>\n" .
96
-	"<meta name='viewport' content='width=device-width' />\n" .
97
-	$css .
90
+	return _DOCTYPE_ECRIRE.
91
+	html_lang_attributes().
92
+	"<head>\n".
93
+	'<title>'.
94
+	textebrut($titre).
95
+	"</title>\n".
96
+	"<meta name='viewport' content='width=device-width' />\n".
97
+	$css.
98 98
 	'</head>
99
-<body' . $onLoad . " class='minipres'>
99
+<body' . $onLoad." class='minipres'>
100 100
 	<div id='minipres'>
101 101
 	<h1>" .
102
-	$titre .
102
+	$titre.
103 103
 	"</h1>
104 104
 	<div>\n";
105 105
 }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
 		$titre = ($titre == 'install')
184 184
 			? _T('avis_espace_interdit')
185
-			: $titre . '&nbsp;: ' . _T('info_acces_interdit');
185
+			: $titre.'&nbsp;: '._T('info_acces_interdit');
186 186
 
187 187
 		$statut = $GLOBALS['visiteur_session']['statut'] ?? '';
188 188
 		$nom = $GLOBALS['visiteur_session']['nom'] ?? '';
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 			$corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']);
202 202
 		}
203 203
 		$corps = "<div class='boutons'>$corps</div>";
204
-		spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']);
204
+		spip_log($nom." $titre ".$_SERVER['REQUEST_URI']);
205 205
 	}
206 206
 
207 207
 	if (!_AJAX) {
@@ -219,6 +219,6 @@  discard block
 block discarded – undo
219 219
 		foreach ($_POST as $v => $c) {
220 220
 			$url = parametre_url($url, $v, $c, '&');
221 221
 		}
222
-		ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false);
222
+		ajax_retour('<div>'.$titre.redirige_formulaire($url).'</div>', false);
223 223
 	}
224 224
 }
Please login to merge, or discard this patch.