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