Completed
Push — master ( 62aed1...8add54 )
by cam
01:34
created
ecrire/inc/importer_csv.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 include_spip('inc/charsets');
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
  * @return array
42 42
  */
43 43
 function importer_csv_importcharset($texte, $definir_charset_source = false) {
44
-	// le plus frequent, en particulier avec les trucs de ms@@@
45
-	static $charset_source = 'iso-8859-1';
46
-	if ($definir_charset_source) {
47
-		$charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source;
48
-	}
49
-	// mais open-office sait faire mieux, donc mefiance !
50
-	$charset = is_utf8($texte) ? 'utf-8' : $charset_source;
51
-	return importer_charset($texte, $charset);
44
+    // le plus frequent, en particulier avec les trucs de ms@@@
45
+    static $charset_source = 'iso-8859-1';
46
+    if ($definir_charset_source) {
47
+        $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source;
48
+    }
49
+    // mais open-office sait faire mieux, donc mefiance !
50
+    $charset = is_utf8($texte) ? 'utf-8' : $charset_source;
51
+    return importer_charset($texte, $charset);
52 52
 }
53 53
 
54 54
 /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
  * @return string
60 60
  */
61 61
 function importer_csv_nettoie_key($key) {
62
-	return translitteration($key);
62
+    return translitteration($key);
63 63
 }
64 64
 
65 65
 /**
@@ -78,70 +78,70 @@  discard block
 block discarded – undo
78 78
  */
79 79
 function inc_importer_csv_dist($file, $options = []) {
80 80
 
81
-	// support ancienne syntaxe
82
-	// inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '')
83
-	if (!is_array($options)) {
84
-		$args = func_get_args();
85
-		$options = [];
86
-		foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) {
87
-			if (!empty($args[$k])) {
88
-				$options[$option] = $args[$k];
89
-			}
90
-		}
91
-	}
81
+    // support ancienne syntaxe
82
+    // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '')
83
+    if (!is_array($options)) {
84
+        $args = func_get_args();
85
+        $options = [];
86
+        foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) {
87
+            if (!empty($args[$k])) {
88
+                $options[$option] = $args[$k];
89
+            }
90
+        }
91
+    }
92 92
 
93
-	$default_options = [
94
-		'head' => false,
95
-		'delim' => ',',
96
-		'enclos' => '"',
97
-		'len' => 10000,
98
-		'charset_source' => '',
99
-	];
100
-	$options = array_merge($default_options, $options);
93
+    $default_options = [
94
+        'head' => false,
95
+        'delim' => ',',
96
+        'enclos' => '"',
97
+        'len' => 10000,
98
+        'charset_source' => '',
99
+    ];
100
+    $options = array_merge($default_options, $options);
101 101
 
102 102
 
103
-	$return = [];
104
-	if (@file_exists($file) && ($handle = fopen($file, 'r'))) {
105
-		if ($options['charset_source']) {
106
-			importer_csv_importcharset('', $options['charset_source']);
107
-		}
108
-		if ($options['head']) {
109
-			$header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']);
110
-			if ($header) {
111
-				$header = array_map('importer_csv_importcharset', $header);
112
-				$header = array_map('importer_csv_nettoie_key', $header);
113
-				$header_type = [];
114
-				foreach ($header as $heading) {
115
-					$header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar';
116
-				}
117
-			}
118
-		}
103
+    $return = [];
104
+    if (@file_exists($file) && ($handle = fopen($file, 'r'))) {
105
+        if ($options['charset_source']) {
106
+            importer_csv_importcharset('', $options['charset_source']);
107
+        }
108
+        if ($options['head']) {
109
+            $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']);
110
+            if ($header) {
111
+                $header = array_map('importer_csv_importcharset', $header);
112
+                $header = array_map('importer_csv_nettoie_key', $header);
113
+                $header_type = [];
114
+                foreach ($header as $heading) {
115
+                    $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar';
116
+                }
117
+            }
118
+        }
119 119
 
120
-		while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) {
121
-			$data = array_map('importer_csv_importcharset', $data);
122
-			if ($options['head'] && isset($header)) {
123
-				$row = [];
124
-				foreach ($header as $key => $heading) {
125
-					if ($header_type[$heading] == 'array') {
126
-						if (!isset($row[$heading])) {
127
-							$row[$heading] = [];
128
-						}
129
-						if (isset($data[$key]) && strlen($data[$key])) {
130
-							$row[$heading][] = $data[$key];
131
-						}
132
-					} else {
133
-						$row[$heading] = $data[$key] ?? '';
134
-					}
135
-				}
136
-				$return[] = $row;
137
-			} else {
138
-				$return[] = $data;
139
-			}
140
-		}
141
-		if ($options['charset_source']) {
142
-			importer_csv_importcharset('', true);
143
-		}
144
-	}
120
+        while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) {
121
+            $data = array_map('importer_csv_importcharset', $data);
122
+            if ($options['head'] && isset($header)) {
123
+                $row = [];
124
+                foreach ($header as $key => $heading) {
125
+                    if ($header_type[$heading] == 'array') {
126
+                        if (!isset($row[$heading])) {
127
+                            $row[$heading] = [];
128
+                        }
129
+                        if (isset($data[$key]) && strlen($data[$key])) {
130
+                            $row[$heading][] = $data[$key];
131
+                        }
132
+                    } else {
133
+                        $row[$heading] = $data[$key] ?? '';
134
+                    }
135
+                }
136
+                $return[] = $row;
137
+            } else {
138
+                $return[] = $data;
139
+            }
140
+        }
141
+        if ($options['charset_source']) {
142
+            importer_csv_importcharset('', true);
143
+        }
144
+    }
145 145
 
146
-	return $return ?: false;
146
+    return $return ?: false;
147 147
 }
Please login to merge, or discard this patch.
ecrire/inc/recherche_to_array.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		$_id_table = reset($_id_table);
67 67
 	}
68 68
 
69
-	$requete['SELECT'][] = 't.' . $_id_table;
69
+	$requete['SELECT'][] = 't.'.$_id_table;
70 70
 	$a = [];
71 71
 	// Recherche fulltext
72 72
 	foreach ($champs as $champ => $poids) {
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
 				$champ = "t.$champ";
78 78
 			}
79 79
 			$requete['SELECT'][] = $champ;
80
-			$a[] = $champ . ' ' . $methode . ' ' . $q;
80
+			$a[] = $champ.' '.$methode.' '.$q;
81 81
 		}
82 82
 	}
83 83
 	if ($a) {
84 84
 		$requete['WHERE'][] = implode(' OR ', $a);
85 85
 	}
86
-	$requete['FROM'][] = table_objet_sql($table) . ' AS t';
86
+	$requete['FROM'][] = table_objet_sql($table).' AS t';
87 87
 
88 88
 	$results = [];
89 89
 
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 					);
245 245
 				} // cas table de liaison generique spip_xxx_yyy
246 246
 				elseif (
247
-					($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur))
248
-					|| ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur))
247
+					($t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur))
248
+					|| ($t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur))
249 249
 				) {
250 250
 					$s = sql_select(
251 251
 						"$cle_depart,$cle_arrivee",
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 				}
285 285
 				if (isset($joint['champs']) && $joint['champs']) {
286 286
 					foreach ($joint['champs'] as $c => $val) {
287
-						$results[$id]['champs'][$table_liee . '.' . $c] = $val;
287
+						$results[$id]['champs'][$table_liee.'.'.$c] = $val;
288 288
 					}
289 289
 				}
290 290
 				if (isset($joint['matches']) && $joint['matches']) {
291 291
 					foreach ($joint['matches'] as $c => $val) {
292
-						$results[$id]['matches'][$table_liee . '.' . $c] = $val;
292
+						$results[$id]['matches'][$table_liee.'.'.$c] = $val;
293 293
 					}
294 294
 				}
295 295
 			}
Please login to merge, or discard this patch.
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -10,291 +10,291 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 
17 17
 // methodes sql
18 18
 function inc_recherche_to_array_dist($recherche, $options = []) {
19 19
 
20
-	// options par defaut
21
-	$options = array_merge(
22
-		[
23
-			'score' => true,
24
-			'champs' => false,
25
-			'toutvoir' => false,
26
-			'matches' => false,
27
-			'jointures' => false
28
-		],
29
-		$options
30
-	);
20
+    // options par defaut
21
+    $options = array_merge(
22
+        [
23
+            'score' => true,
24
+            'champs' => false,
25
+            'toutvoir' => false,
26
+            'matches' => false,
27
+            'jointures' => false
28
+        ],
29
+        $options
30
+    );
31 31
 
32
-	include_spip('inc/rechercher');
33
-	include_spip('inc/autoriser');
32
+    include_spip('inc/rechercher');
33
+    include_spip('inc/autoriser');
34 34
 
35
-	$requete = [
36
-		'SELECT' => [],
37
-		'FROM' => [],
38
-		'WHERE' => [],
39
-		'GROUPBY' => [],
40
-		'ORDERBY' => [],
41
-		'LIMIT' => '',
42
-		'HAVING' => []
43
-	];
35
+    $requete = [
36
+        'SELECT' => [],
37
+        'FROM' => [],
38
+        'WHERE' => [],
39
+        'GROUPBY' => [],
40
+        'ORDERBY' => [],
41
+        'LIMIT' => '',
42
+        'HAVING' => []
43
+    ];
44 44
 
45
-	$table = sinon($options['table'], 'article');
46
-	if ($options['champs']) {
47
-		$champs = $options['champs'];
48
-	} else {
49
-		$l = liste_des_champs();
50
-		$champs = $l['article'];
51
-	}
52
-	$serveur = $options['serveur'];
45
+    $table = sinon($options['table'], 'article');
46
+    if ($options['champs']) {
47
+        $champs = $options['champs'];
48
+    } else {
49
+        $l = liste_des_champs();
50
+        $champs = $l['article'];
51
+    }
52
+    $serveur = $options['serveur'];
53 53
 
54
-	[$methode, $q, $preg] = expression_recherche($recherche, $options);
54
+    [$methode, $q, $preg] = expression_recherche($recherche, $options);
55 55
 
56
-	$jointures = $options['jointures']
57
-		? liste_des_jointures()
58
-		: [];
56
+    $jointures = $options['jointures']
57
+        ? liste_des_jointures()
58
+        : [];
59 59
 
60
-	$_id_table = id_table_objet($table);
60
+    $_id_table = id_table_objet($table);
61 61
 
62
-	// c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
63
-	// (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
64
-	if (str_contains((string) $_id_table, ',')) {
65
-		$_id_table = explode(',', (string) $_id_table);
66
-		$_id_table = reset($_id_table);
67
-	}
62
+    // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ','
63
+    // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs)
64
+    if (str_contains((string) $_id_table, ',')) {
65
+        $_id_table = explode(',', (string) $_id_table);
66
+        $_id_table = reset($_id_table);
67
+    }
68 68
 
69
-	$requete['SELECT'][] = 't.' . $_id_table;
70
-	$a = [];
71
-	// Recherche fulltext
72
-	foreach ($champs as $champ => $poids) {
73
-		if (is_array($champ)) {
74
-			spip_logger()->info('requetes imbriquees interdites');
75
-		} else {
76
-			if (!str_contains((string) $champ, '.')) {
77
-				$champ = "t.$champ";
78
-			}
79
-			$requete['SELECT'][] = $champ;
80
-			$a[] = $champ . ' ' . $methode . ' ' . $q;
81
-		}
82
-	}
83
-	if ($a) {
84
-		$requete['WHERE'][] = implode(' OR ', $a);
85
-	}
86
-	$requete['FROM'][] = table_objet_sql($table) . ' AS t';
69
+    $requete['SELECT'][] = 't.' . $_id_table;
70
+    $a = [];
71
+    // Recherche fulltext
72
+    foreach ($champs as $champ => $poids) {
73
+        if (is_array($champ)) {
74
+            spip_logger()->info('requetes imbriquees interdites');
75
+        } else {
76
+            if (!str_contains((string) $champ, '.')) {
77
+                $champ = "t.$champ";
78
+            }
79
+            $requete['SELECT'][] = $champ;
80
+            $a[] = $champ . ' ' . $methode . ' ' . $q;
81
+        }
82
+    }
83
+    if ($a) {
84
+        $requete['WHERE'][] = implode(' OR ', $a);
85
+    }
86
+    $requete['FROM'][] = table_objet_sql($table) . ' AS t';
87 87
 
88
-	$results = [];
88
+    $results = [];
89 89
 
90
-	$s = sql_select(
91
-		$requete['SELECT'],
92
-		$requete['FROM'],
93
-		$requete['WHERE'],
94
-		implode(' ', $requete['GROUPBY']),
95
-		$requete['ORDERBY'],
96
-		$requete['LIMIT'],
97
-		$requete['HAVING'],
98
-		$serveur
99
-	);
90
+    $s = sql_select(
91
+        $requete['SELECT'],
92
+        $requete['FROM'],
93
+        $requete['WHERE'],
94
+        implode(' ', $requete['GROUPBY']),
95
+        $requete['ORDERBY'],
96
+        $requete['LIMIT'],
97
+        $requete['HAVING'],
98
+        $serveur
99
+    );
100 100
 
101
-	while (
102
-		($t = sql_fetch($s, $serveur))
103
-		&& (!isset($t['score']) || $t['score'] > 0)
104
-	) {
105
-		$id = (int) $t[$_id_table];
101
+    while (
102
+        ($t = sql_fetch($s, $serveur))
103
+        && (!isset($t['score']) || $t['score'] > 0)
104
+    ) {
105
+        $id = (int) $t[$_id_table];
106 106
 
107
-		if ($options['toutvoir'] || autoriser('voir', $table, $id)) {
108
-			// indiquer les champs concernes
109
-			$champs_vus = [];
110
-			$score = 0;
111
-			$matches = [];
107
+        if ($options['toutvoir'] || autoriser('voir', $table, $id)) {
108
+            // indiquer les champs concernes
109
+            $champs_vus = [];
110
+            $score = 0;
111
+            $matches = [];
112 112
 
113
-			$vu = false;
114
-			foreach ($champs as $champ => $poids) {
115
-				$champ = explode('.', (string) $champ);
116
-				$champ = end($champ);
117
-				// translitteration_rapide uniquement si on est deja en utf-8
118
-				$value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
119
-				if (
120
-					$n =
121
-					($options['score'] || $options['matches'])
122
-						? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER)
123
-						: preg_match($preg, (string) $value)
124
-				) {
125
-					$vu = true;
113
+            $vu = false;
114
+            foreach ($champs as $champ => $poids) {
115
+                $champ = explode('.', (string) $champ);
116
+                $champ = end($champ);
117
+                // translitteration_rapide uniquement si on est deja en utf-8
118
+                $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ]));
119
+                if (
120
+                    $n =
121
+                    ($options['score'] || $options['matches'])
122
+                        ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER)
123
+                        : preg_match($preg, (string) $value)
124
+                ) {
125
+                    $vu = true;
126 126
 
127
-					if ($options['champs']) {
128
-						$champs_vus[$champ] = $t[$champ];
129
-					}
130
-					if ($options['score']) {
131
-						// compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
132
-						$score += $poids * strlen(implode('', array_column($regs, 0)));
133
-					}
127
+                    if ($options['champs']) {
128
+                        $champs_vus[$champ] = $t[$champ];
129
+                    }
130
+                    if ($options['score']) {
131
+                        // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars
132
+                        $score += $poids * strlen(implode('', array_column($regs, 0)));
133
+                    }
134 134
 
135
-					if ($options['matches']) {
136
-						$matches[$champ] = $regs;
137
-					}
135
+                    if ($options['matches']) {
136
+                        $matches[$champ] = $regs;
137
+                    }
138 138
 
139
-					if (!$options['champs'] && !$options['score'] && !$options['matches']) {
140
-						break;
141
-					}
142
-				}
143
-			}
139
+                    if (!$options['champs'] && !$options['score'] && !$options['matches']) {
140
+                        break;
141
+                    }
142
+                }
143
+            }
144 144
 
145
-			if ($vu) {
146
-				if (!isset($results)) {
147
-					$results = [];
148
-				}
149
-				$results[$id] = [];
150
-				if ($champs_vus) {
151
-					$results[$id]['champs'] = $champs_vus;
152
-				}
153
-				if ($score) {
154
-					$results[$id]['score'] = $score;
155
-				}
156
-				if ($matches) {
157
-					$results[$id]['matches'] = $matches;
158
-				}
159
-			}
160
-		}
161
-	}
145
+            if ($vu) {
146
+                if (!isset($results)) {
147
+                    $results = [];
148
+                }
149
+                $results[$id] = [];
150
+                if ($champs_vus) {
151
+                    $results[$id]['champs'] = $champs_vus;
152
+                }
153
+                if ($score) {
154
+                    $results[$id]['score'] = $score;
155
+                }
156
+                if ($matches) {
157
+                    $results[$id]['matches'] = $matches;
158
+                }
159
+            }
160
+        }
161
+    }
162 162
 
163 163
 
164
-	// Gerer les donnees associees
165
-	// ici on est un peu naze : pas capables de reconstruire une jointure complexe
166
-	// on ne sait passer que par table de laison en 1 coup
167
-	if (
168
-		isset($jointures[$table])
169
-		&& ($joints = recherche_en_base(
170
-			$recherche,
171
-			$jointures[$table],
172
-			array_merge($options, ['jointures' => false])
173
-		))
174
-	) {
175
-		include_spip('action/editer_liens');
176
-		$trouver_table = charger_fonction('trouver_table', 'base');
177
-		$cle_depart = id_table_objet($table);
178
-		$table_depart = table_objet($table, $serveur);
179
-		$desc_depart = $trouver_table($table_depart, $serveur);
180
-		$depart_associable = objet_associable($table);
181
-		foreach ($joints as $table_liee => $ids_trouves) {
182
-			// on peut definir une fonction de recherche jointe pour regler les cas particuliers
183
-			if (
184
-				!(
185
-				($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true))
186
-				|| ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true))
187
-				|| ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true))
188
-				)
189
-			) {
190
-				$cle_arrivee = id_table_objet($table_liee);
191
-				$table_arrivee = table_objet($table_liee, $serveur);
192
-				$desc_arrivee = $trouver_table($table_arrivee, $serveur);
193
-				// cas simple : $cle_depart dans la table_liee
194
-				if (isset($desc_arrivee['field'][$cle_depart])) {
195
-					$s = sql_select(
196
-						"$cle_depart, $cle_arrivee",
197
-						$desc_arrivee['table_sql'],
198
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
199
-						'',
200
-						'',
201
-						'',
202
-						'',
203
-						$serveur
204
-					);
205
-				} // cas simple : $cle_arrivee dans la table
206
-				elseif (isset($desc_depart['field'][$cle_arrivee])) {
207
-					$s = sql_select(
208
-						"$cle_depart, $cle_arrivee",
209
-						$desc_depart['table_sql'],
210
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
211
-						'',
212
-						'',
213
-						'',
214
-						'',
215
-						$serveur
216
-					);
217
-				}
218
-				// sinon cherchons une table de liaison
219
-				// cas recherche principale article, objet lie document : passer par spip_documents_liens
220
-				elseif ($l = objet_associable($table_liee)) {
221
-					[$primary, $table_liens] = $l;
222
-					$s = sql_select(
223
-						"id_objet as $cle_depart, $primary as $cle_arrivee",
224
-						$table_liens,
225
-						["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
226
-						'',
227
-						'',
228
-						'',
229
-						'',
230
-						$serveur
231
-					);
232
-				} // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
233
-				elseif ($l = $depart_associable) {
234
-					[$primary, $table_liens] = $l;
235
-					$s = sql_select(
236
-						"$primary as $cle_depart, id_objet as $cle_arrivee",
237
-						$table_liens,
238
-						["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
239
-						'',
240
-						'',
241
-						'',
242
-						'',
243
-						$serveur
244
-					);
245
-				} // cas table de liaison generique spip_xxx_yyy
246
-				elseif (
247
-					($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur))
248
-					|| ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur))
249
-				) {
250
-					$s = sql_select(
251
-						"$cle_depart,$cle_arrivee",
252
-						$t['table_sql'],
253
-						sql_in($cle_arrivee, array_keys($ids_trouves)),
254
-						'',
255
-						'',
256
-						'',
257
-						'',
258
-						$serveur
259
-					);
260
-				}
261
-			} else {
262
-				[$cle_depart, $cle_arrivee, $s] = $rechercher_joints(
263
-					$table,
264
-					$table_liee,
265
-					array_keys($ids_trouves),
266
-					$serveur
267
-				);
268
-			}
164
+    // Gerer les donnees associees
165
+    // ici on est un peu naze : pas capables de reconstruire une jointure complexe
166
+    // on ne sait passer que par table de laison en 1 coup
167
+    if (
168
+        isset($jointures[$table])
169
+        && ($joints = recherche_en_base(
170
+            $recherche,
171
+            $jointures[$table],
172
+            array_merge($options, ['jointures' => false])
173
+        ))
174
+    ) {
175
+        include_spip('action/editer_liens');
176
+        $trouver_table = charger_fonction('trouver_table', 'base');
177
+        $cle_depart = id_table_objet($table);
178
+        $table_depart = table_objet($table, $serveur);
179
+        $desc_depart = $trouver_table($table_depart, $serveur);
180
+        $depart_associable = objet_associable($table);
181
+        foreach ($joints as $table_liee => $ids_trouves) {
182
+            // on peut definir une fonction de recherche jointe pour regler les cas particuliers
183
+            if (
184
+                !(
185
+                ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true))
186
+                || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true))
187
+                || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true))
188
+                )
189
+            ) {
190
+                $cle_arrivee = id_table_objet($table_liee);
191
+                $table_arrivee = table_objet($table_liee, $serveur);
192
+                $desc_arrivee = $trouver_table($table_arrivee, $serveur);
193
+                // cas simple : $cle_depart dans la table_liee
194
+                if (isset($desc_arrivee['field'][$cle_depart])) {
195
+                    $s = sql_select(
196
+                        "$cle_depart, $cle_arrivee",
197
+                        $desc_arrivee['table_sql'],
198
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
199
+                        '',
200
+                        '',
201
+                        '',
202
+                        '',
203
+                        $serveur
204
+                    );
205
+                } // cas simple : $cle_arrivee dans la table
206
+                elseif (isset($desc_depart['field'][$cle_arrivee])) {
207
+                    $s = sql_select(
208
+                        "$cle_depart, $cle_arrivee",
209
+                        $desc_depart['table_sql'],
210
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
211
+                        '',
212
+                        '',
213
+                        '',
214
+                        '',
215
+                        $serveur
216
+                    );
217
+                }
218
+                // sinon cherchons une table de liaison
219
+                // cas recherche principale article, objet lie document : passer par spip_documents_liens
220
+                elseif ($l = objet_associable($table_liee)) {
221
+                    [$primary, $table_liens] = $l;
222
+                    $s = sql_select(
223
+                        "id_objet as $cle_depart, $primary as $cle_arrivee",
224
+                        $table_liens,
225
+                        ["objet='$table'", sql_in($primary, array_keys($ids_trouves))],
226
+                        '',
227
+                        '',
228
+                        '',
229
+                        '',
230
+                        $serveur
231
+                    );
232
+                } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens
233
+                elseif ($l = $depart_associable) {
234
+                    [$primary, $table_liens] = $l;
235
+                    $s = sql_select(
236
+                        "$primary as $cle_depart, id_objet as $cle_arrivee",
237
+                        $table_liens,
238
+                        ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))],
239
+                        '',
240
+                        '',
241
+                        '',
242
+                        '',
243
+                        $serveur
244
+                    );
245
+                } // cas table de liaison generique spip_xxx_yyy
246
+                elseif (
247
+                    ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur))
248
+                    || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur))
249
+                ) {
250
+                    $s = sql_select(
251
+                        "$cle_depart,$cle_arrivee",
252
+                        $t['table_sql'],
253
+                        sql_in($cle_arrivee, array_keys($ids_trouves)),
254
+                        '',
255
+                        '',
256
+                        '',
257
+                        '',
258
+                        $serveur
259
+                    );
260
+                }
261
+            } else {
262
+                [$cle_depart, $cle_arrivee, $s] = $rechercher_joints(
263
+                    $table,
264
+                    $table_liee,
265
+                    array_keys($ids_trouves),
266
+                    $serveur
267
+                );
268
+            }
269 269
 
270
-			while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
271
-				$id = $t[$cle_depart];
272
-				$joint = $ids_trouves[$t[$cle_arrivee]];
273
-				if (!isset($results)) {
274
-					$results = [];
275
-				}
276
-				if (!isset($results[$id])) {
277
-					$results[$id] = [];
278
-				}
279
-				if (isset($joint['score']) && $joint['score']) {
280
-					if (!isset($results[$id]['score'])) {
281
-						$results[$id]['score'] = 0;
282
-					}
283
-					$results[$id]['score'] += $joint['score'];
284
-				}
285
-				if (isset($joint['champs']) && $joint['champs']) {
286
-					foreach ($joint['champs'] as $c => $val) {
287
-						$results[$id]['champs'][$table_liee . '.' . $c] = $val;
288
-					}
289
-				}
290
-				if (isset($joint['matches']) && $joint['matches']) {
291
-					foreach ($joint['matches'] as $c => $val) {
292
-						$results[$id]['matches'][$table_liee . '.' . $c] = $val;
293
-					}
294
-				}
295
-			}
296
-		}
297
-	}
270
+            while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) {
271
+                $id = $t[$cle_depart];
272
+                $joint = $ids_trouves[$t[$cle_arrivee]];
273
+                if (!isset($results)) {
274
+                    $results = [];
275
+                }
276
+                if (!isset($results[$id])) {
277
+                    $results[$id] = [];
278
+                }
279
+                if (isset($joint['score']) && $joint['score']) {
280
+                    if (!isset($results[$id]['score'])) {
281
+                        $results[$id]['score'] = 0;
282
+                    }
283
+                    $results[$id]['score'] += $joint['score'];
284
+                }
285
+                if (isset($joint['champs']) && $joint['champs']) {
286
+                    foreach ($joint['champs'] as $c => $val) {
287
+                        $results[$id]['champs'][$table_liee . '.' . $c] = $val;
288
+                    }
289
+                }
290
+                if (isset($joint['matches']) && $joint['matches']) {
291
+                    foreach ($joint['matches'] as $c => $val) {
292
+                        $results[$id]['matches'][$table_liee . '.' . $c] = $val;
293
+                    }
294
+                }
295
+            }
296
+        }
297
+    }
298 298
 
299
-	return $results;
299
+    return $results;
300 300
 }
Please login to merge, or discard this patch.
ecrire/inc/presenter_enfants.php 2 patches
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 include_spip('inc/autoriser');
@@ -29,74 +29,74 @@  discard block
 block discarded – undo
29 29
  *  Un tableau des sous rubriques
30 30
  */
31 31
 function enfant_rub($collection, $debut = 0, $limite = 500) {
32
-	$voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non');
33
-	$logo = '';
34
-
35
-	if ($voir_logo) {
36
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
37
-		include_spip('inc/filtres_images_mini');
38
-	}
39
-
40
-	$res = [];
41
-
42
-	$result = sql_select(
43
-		'id_rubrique, id_parent, titre, descriptif, lang',
44
-		'spip_rubriques',
45
-		'id_parent=' . (int) $collection,
46
-		'',
47
-		'0+titre,titre',
48
-		$debut == -1 ? '' : "$debut,$limite"
49
-	);
50
-	while ($row = sql_fetch($result)) {
51
-		$id_rubrique = $row['id_rubrique'];
52
-		$id_parent = $row['id_parent'];
53
-		// pour etre sur de passer par tous les traitements
54
-		$titre = generer_objet_info($id_rubrique, 'rubrique', 'titre');
55
-		if ('' !== ($rang = recuperer_numero($row['titre']))) {
56
-			$rang = "<span class='rang'>$rang.</span> ";
57
-		}
58
-
59
-		if (autoriser('voir', 'rubrique', $id_rubrique)) {
60
-			$les_sous_enfants = sous_enfant_rub($id_rubrique);
61
-
62
-			changer_typo($row['lang']);
63
-			$lang_dir = lang_dir($row['lang']);
64
-			$descriptif = propre($row['descriptif']);
65
-
66
-			if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) {
67
-				[$fid, $dir, $nom, $format] = $logo;
68
-				$logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70);
69
-				if ($logo) {
70
-					$logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">');
71
-				}
72
-			}
73
-
74
-			$lib_bouton = (acces_restreint_rubrique($id_rubrique)
75
-				? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique'))
76
-				: '') .
77
-				" <a class='titremlien' dir='$lang_dir'" .
78
-				($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
79
-				" href='" .
80
-				generer_objet_url($id_rubrique, 'rubrique') .
81
-				"'><span class='titre'>" .
82
-				$rang . $titre
83
-				. '</span>'
84
-				. (is_string($logo) ? $logo : '')
85
-				. '</a>';
86
-
87
-			$titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique")
88
-				. ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '')
89
-				;
90
-
91
-			$res[] =
92
-				debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
93
-				$les_sous_enfants .
94
-				fin_cadre_sous_rub();
95
-		}
96
-	}
97
-
98
-	changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite
99
-	return $res;
32
+    $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non');
33
+    $logo = '';
34
+
35
+    if ($voir_logo) {
36
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
37
+        include_spip('inc/filtres_images_mini');
38
+    }
39
+
40
+    $res = [];
41
+
42
+    $result = sql_select(
43
+        'id_rubrique, id_parent, titre, descriptif, lang',
44
+        'spip_rubriques',
45
+        'id_parent=' . (int) $collection,
46
+        '',
47
+        '0+titre,titre',
48
+        $debut == -1 ? '' : "$debut,$limite"
49
+    );
50
+    while ($row = sql_fetch($result)) {
51
+        $id_rubrique = $row['id_rubrique'];
52
+        $id_parent = $row['id_parent'];
53
+        // pour etre sur de passer par tous les traitements
54
+        $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre');
55
+        if ('' !== ($rang = recuperer_numero($row['titre']))) {
56
+            $rang = "<span class='rang'>$rang.</span> ";
57
+        }
58
+
59
+        if (autoriser('voir', 'rubrique', $id_rubrique)) {
60
+            $les_sous_enfants = sous_enfant_rub($id_rubrique);
61
+
62
+            changer_typo($row['lang']);
63
+            $lang_dir = lang_dir($row['lang']);
64
+            $descriptif = propre($row['descriptif']);
65
+
66
+            if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) {
67
+                [$fid, $dir, $nom, $format] = $logo;
68
+                $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70);
69
+                if ($logo) {
70
+                    $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">');
71
+                }
72
+            }
73
+
74
+            $lib_bouton = (acces_restreint_rubrique($id_rubrique)
75
+                ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique'))
76
+                : '') .
77
+                " <a class='titremlien' dir='$lang_dir'" .
78
+                ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
79
+                " href='" .
80
+                generer_objet_url($id_rubrique, 'rubrique') .
81
+                "'><span class='titre'>" .
82
+                $rang . $titre
83
+                . '</span>'
84
+                . (is_string($logo) ? $logo : '')
85
+                . '</a>';
86
+
87
+            $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique")
88
+                . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '')
89
+                ;
90
+
91
+            $res[] =
92
+                debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
93
+                $les_sous_enfants .
94
+                fin_cadre_sous_rub();
95
+        }
96
+    }
97
+
98
+    changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite
99
+    return $res;
100 100
 }
101 101
 
102 102
 /**
@@ -109,71 +109,71 @@  discard block
 block discarded – undo
109 109
  *  Le contenu du bloc dépliable
110 110
  */
111 111
 function sous_enfant_rub($collection2) {
112
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2);
113
-
114
-	$retour = '';
115
-	$pagination = '';
116
-	$debut = 0;
117
-	$limite = 500;
118
-
119
-	/**
120
-	 * On ne va afficher que 500 résultats max
121
-	 * Si > 500 on affiche une pagination
122
-	 */
123
-	if ($nb > $limite) {
124
-		$debut = _request('debut_rubrique' . $collection2) ?: $debut;
125
-		$pagination = chercher_filtre('pagination');
126
-		$pagination = '<nav class="pagination">' . $pagination(
127
-			$nb,
128
-			'_rubrique' . $collection2,
129
-			$debut,
130
-			$limite,
131
-			true,
132
-			'prive'
133
-		) . '</nav>';
134
-		$limite = $debut + $limite;
135
-	}
136
-
137
-	$result = sql_select(
138
-		'id_rubrique, id_parent, titre, lang',
139
-		'spip_rubriques',
140
-		'id_parent=' . (int) $collection2,
141
-		'',
142
-		'0+titre,titre',
143
-		$debut == -1 ? '' : "$debut,$limite"
144
-	);
145
-
146
-	while ($row = sql_fetch($result)) {
147
-		$id_rubrique2 = $row['id_rubrique'];
148
-		$titre2 = generer_objet_info(
149
-			$id_rubrique2,
150
-			'rubrique',
151
-			'titre'
152
-		); // pour etre sur de passer par tous les traitements
153
-		if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
154
-			$rang2 = "<span class='rang'>$rang2.</span> ";
155
-		}
156
-
157
-		changer_typo($row['lang']);
158
-		$lang_dir = lang_dir($row['lang']);
159
-		if (autoriser('voir', 'rubrique', $id_rubrique2)) {
160
-			$retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url(
161
-				$id_rubrique2,
162
-				'rubrique'
163
-			) . "'>" . $rang2 . $titre2 . "</a></li>\n";
164
-		}
165
-	}
166
-
167
-	$retour = $pagination . $retour . $pagination;
168
-
169
-	if (!$retour) {
170
-		return '';
171
-	}
172
-
173
-	return debut_block_depliable($debut > 0, "enfants$collection2")
174
-	. "\n<ul class='liste-items sous-sous-rub'>\n"
175
-	. $retour
176
-	. "</ul>\n" . fin_block() . "\n\n";
112
+    $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2);
113
+
114
+    $retour = '';
115
+    $pagination = '';
116
+    $debut = 0;
117
+    $limite = 500;
118
+
119
+    /**
120
+     * On ne va afficher que 500 résultats max
121
+     * Si > 500 on affiche une pagination
122
+     */
123
+    if ($nb > $limite) {
124
+        $debut = _request('debut_rubrique' . $collection2) ?: $debut;
125
+        $pagination = chercher_filtre('pagination');
126
+        $pagination = '<nav class="pagination">' . $pagination(
127
+            $nb,
128
+            '_rubrique' . $collection2,
129
+            $debut,
130
+            $limite,
131
+            true,
132
+            'prive'
133
+        ) . '</nav>';
134
+        $limite = $debut + $limite;
135
+    }
136
+
137
+    $result = sql_select(
138
+        'id_rubrique, id_parent, titre, lang',
139
+        'spip_rubriques',
140
+        'id_parent=' . (int) $collection2,
141
+        '',
142
+        '0+titre,titre',
143
+        $debut == -1 ? '' : "$debut,$limite"
144
+    );
145
+
146
+    while ($row = sql_fetch($result)) {
147
+        $id_rubrique2 = $row['id_rubrique'];
148
+        $titre2 = generer_objet_info(
149
+            $id_rubrique2,
150
+            'rubrique',
151
+            'titre'
152
+        ); // pour etre sur de passer par tous les traitements
153
+        if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
154
+            $rang2 = "<span class='rang'>$rang2.</span> ";
155
+        }
156
+
157
+        changer_typo($row['lang']);
158
+        $lang_dir = lang_dir($row['lang']);
159
+        if (autoriser('voir', 'rubrique', $id_rubrique2)) {
160
+            $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url(
161
+                $id_rubrique2,
162
+                'rubrique'
163
+            ) . "'>" . $rang2 . $titre2 . "</a></li>\n";
164
+        }
165
+    }
166
+
167
+    $retour = $pagination . $retour . $pagination;
168
+
169
+    if (!$retour) {
170
+        return '';
171
+    }
172
+
173
+    return debut_block_depliable($debut > 0, "enfants$collection2")
174
+    . "\n<ul class='liste-items sous-sous-rub'>\n"
175
+    . $retour
176
+    . "</ul>\n" . fin_block() . "\n\n";
177 177
 }
178 178
 
179 179
 /**
@@ -188,41 +188,41 @@  discard block
 block discarded – undo
188 188
  *  Le contenu textuel affiché, la liste des sous rubriques
189 189
  */
190 190
 function afficher_enfant_rub($id_rubrique = 0) {
191
-	$pagination = '';
192
-	$debut = 0;
193
-	$limite = 500;
194
-
195
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique);
196
-
197
-	if ($nb > $limite) {
198
-		$debut = _request('debut_rubrique' . $id_rubrique) ?: $debut;
199
-		$pagination = chercher_filtre('pagination');
200
-		$pagination = '<br class="nettoyeur"><nav class="pagination">' .
201
-			$pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
202
-		'</nav>';
203
-	}
204
-
205
-	$les_enfants = enfant_rub($id_rubrique, $debut, $limite);
206
-
207
-	if (!$n = count($les_enfants)) {
208
-		return '';
209
-	}
210
-
211
-	if ($n == 1) {
212
-		$les_enfants = reset($les_enfants);
213
-		$les_enfants2 = '';
214
-	} else {
215
-		$n = ceil($n / 2);
216
-		$les_enfants2 = implode('', array_slice($les_enfants, $n));
217
-		$les_enfants = implode('', array_slice($les_enfants, 0, $n));
218
-	}
219
-
220
-	return $pagination
221
-		. "<div class='gauche'>"
222
-		. $les_enfants
223
-		. '</div>'
224
-		. "<div class='droite'>"
225
-		. $les_enfants2
226
-		. '</div>'
227
-		. $pagination;
191
+    $pagination = '';
192
+    $debut = 0;
193
+    $limite = 500;
194
+
195
+    $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique);
196
+
197
+    if ($nb > $limite) {
198
+        $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut;
199
+        $pagination = chercher_filtre('pagination');
200
+        $pagination = '<br class="nettoyeur"><nav class="pagination">' .
201
+            $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
202
+        '</nav>';
203
+    }
204
+
205
+    $les_enfants = enfant_rub($id_rubrique, $debut, $limite);
206
+
207
+    if (!$n = count($les_enfants)) {
208
+        return '';
209
+    }
210
+
211
+    if ($n == 1) {
212
+        $les_enfants = reset($les_enfants);
213
+        $les_enfants2 = '';
214
+    } else {
215
+        $n = ceil($n / 2);
216
+        $les_enfants2 = implode('', array_slice($les_enfants, $n));
217
+        $les_enfants = implode('', array_slice($les_enfants, 0, $n));
218
+    }
219
+
220
+    return $pagination
221
+        . "<div class='gauche'>"
222
+        . $les_enfants
223
+        . '</div>'
224
+        . "<div class='droite'>"
225
+        . $les_enfants2
226
+        . '</div>'
227
+        . $pagination;
228 228
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	$result = sql_select(
43 43
 		'id_rubrique, id_parent, titre, descriptif, lang',
44 44
 		'spip_rubriques',
45
-		'id_parent=' . (int) $collection,
45
+		'id_parent='.(int) $collection,
46 46
 		'',
47 47
 		'0+titre,titre',
48 48
 		$debut == -1 ? '' : "$debut,$limite"
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 
74 74
 			$lib_bouton = (acces_restreint_rubrique($id_rubrique)
75 75
 				? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique'))
76
-				: '') .
77
-				" <a class='titremlien' dir='$lang_dir'" .
78
-				($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
79
-				" href='" .
80
-				generer_objet_url($id_rubrique, 'rubrique') .
81
-				"'><span class='titre'>" .
82
-				$rang . $titre
76
+				: '').
77
+				" <a class='titremlien' dir='$lang_dir'".
78
+				($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='".$row['lang']."'" : '').
79
+				" href='".
80
+				generer_objet_url($id_rubrique, 'rubrique').
81
+				"'><span class='titre'>".
82
+				$rang.$titre
83 83
 				. '</span>'
84 84
 				. (is_string($logo) ? $logo : '')
85 85
 				. '</a>';
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 				;
90 90
 
91 91
 			$res[] =
92
-				debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
93
-				$les_sous_enfants .
92
+				debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre).
93
+				$les_sous_enfants.
94 94
 				fin_cadre_sous_rub();
95 95
 		}
96 96
 	}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
  *  Le contenu du bloc dépliable
110 110
  */
111 111
 function sous_enfant_rub($collection2) {
112
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2);
112
+	$nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $collection2);
113 113
 
114 114
 	$retour = '';
115 115
 	$pagination = '';
@@ -121,23 +121,23 @@  discard block
 block discarded – undo
121 121
 	 * Si > 500 on affiche une pagination
122 122
 	 */
123 123
 	if ($nb > $limite) {
124
-		$debut = _request('debut_rubrique' . $collection2) ?: $debut;
124
+		$debut = _request('debut_rubrique'.$collection2) ?: $debut;
125 125
 		$pagination = chercher_filtre('pagination');
126
-		$pagination = '<nav class="pagination">' . $pagination(
126
+		$pagination = '<nav class="pagination">'.$pagination(
127 127
 			$nb,
128
-			'_rubrique' . $collection2,
128
+			'_rubrique'.$collection2,
129 129
 			$debut,
130 130
 			$limite,
131 131
 			true,
132 132
 			'prive'
133
-		) . '</nav>';
133
+		).'</nav>';
134 134
 		$limite = $debut + $limite;
135 135
 	}
136 136
 
137 137
 	$result = sql_select(
138 138
 		'id_rubrique, id_parent, titre, lang',
139 139
 		'spip_rubriques',
140
-		'id_parent=' . (int) $collection2,
140
+		'id_parent='.(int) $collection2,
141 141
 		'',
142 142
 		'0+titre,titre',
143 143
 		$debut == -1 ? '' : "$debut,$limite"
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 		changer_typo($row['lang']);
158 158
 		$lang_dir = lang_dir($row['lang']);
159 159
 		if (autoriser('voir', 'rubrique', $id_rubrique2)) {
160
-			$retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url(
160
+			$retour .= "\n<li class='item' dir='$lang_dir'><a href='".generer_objet_url(
161 161
 				$id_rubrique2,
162 162
 				'rubrique'
163
-			) . "'>" . $rang2 . $titre2 . "</a></li>\n";
163
+			)."'>".$rang2.$titre2."</a></li>\n";
164 164
 		}
165 165
 	}
166 166
 
167
-	$retour = $pagination . $retour . $pagination;
167
+	$retour = $pagination.$retour.$pagination;
168 168
 
169 169
 	if (!$retour) {
170 170
 		return '';
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	return debut_block_depliable($debut > 0, "enfants$collection2")
174 174
 	. "\n<ul class='liste-items sous-sous-rub'>\n"
175 175
 	. $retour
176
-	. "</ul>\n" . fin_block() . "\n\n";
176
+	. "</ul>\n".fin_block()."\n\n";
177 177
 }
178 178
 
179 179
 /**
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 	$debut = 0;
193 193
 	$limite = 500;
194 194
 
195
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique);
195
+	$nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $id_rubrique);
196 196
 
197 197
 	if ($nb > $limite) {
198
-		$debut = _request('debut_rubrique' . $id_rubrique) ?: $debut;
198
+		$debut = _request('debut_rubrique'.$id_rubrique) ?: $debut;
199 199
 		$pagination = chercher_filtre('pagination');
200
-		$pagination = '<br class="nettoyeur"><nav class="pagination">' .
201
-			$pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
200
+		$pagination = '<br class="nettoyeur"><nav class="pagination">'.
201
+			$pagination($nb, '_rubrique'.$id_rubrique, $debut, $limite, true, 'prive').
202 202
 		'</nav>';
203 203
 	}
204 204
 
Please login to merge, or discard this patch.
ecrire/inc/preselectionner_parent_nouvel_objet.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 if (!defined('_AUTO_SELECTION_RUBRIQUE')) {
16
-	define('_AUTO_SELECTION_RUBRIQUE', false);
16
+    define('_AUTO_SELECTION_RUBRIQUE', false);
17 17
 }
18 18
 
19 19
 
@@ -27,39 +27,39 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function inc_preselectionner_parent_nouvel_objet_dist($objet, $row) {
30
-	if (!_AUTO_SELECTION_RUBRIQUE) {
31
-		return '';
32
-	}
30
+    if (!_AUTO_SELECTION_RUBRIQUE) {
31
+        return '';
32
+    }
33 33
 
34
-	if (!isset($row['id_rubrique'])) {
35
-		return '';
36
-	}
34
+    if (!isset($row['id_rubrique'])) {
35
+        return '';
36
+    }
37 37
 
38
-	$id_rubrique = '';
39
-	if ($GLOBALS['connect_id_rubrique']) {
40
-		// si admin restreint : sa rubrique
41
-		$id_rubrique = $GLOBALS['connect_id_rubrique'][0];
42
-	} elseif (
43
-		is_int(_AUTO_SELECTION_RUBRIQUE)
44
-		&& sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE)
45
-	) {
46
-		$id_rubrique = _AUTO_SELECTION_RUBRIQUE;
47
-	} else {
48
-		// sinon la derniere rubrique cree
49
-		$row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1');
50
-		$id_rubrique = $row_rub['id_rubrique'];
51
-	}
52
-	// si le choix ne convient pas, on cherche dans un secteur
53
-	if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) {
54
-		$id_rubrique = '';
55
-		// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
56
-		$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
57
-		while (!$id_rubrique && ($row_rub = sql_fetch($res))) {
58
-			if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) {
59
-				$id_rubrique = $row_rub['id_rubrique'];
60
-			}
61
-		}
62
-	}
38
+    $id_rubrique = '';
39
+    if ($GLOBALS['connect_id_rubrique']) {
40
+        // si admin restreint : sa rubrique
41
+        $id_rubrique = $GLOBALS['connect_id_rubrique'][0];
42
+    } elseif (
43
+        is_int(_AUTO_SELECTION_RUBRIQUE)
44
+        && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE)
45
+    ) {
46
+        $id_rubrique = _AUTO_SELECTION_RUBRIQUE;
47
+    } else {
48
+        // sinon la derniere rubrique cree
49
+        $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1');
50
+        $id_rubrique = $row_rub['id_rubrique'];
51
+    }
52
+    // si le choix ne convient pas, on cherche dans un secteur
53
+    if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) {
54
+        $id_rubrique = '';
55
+        // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
56
+        $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
57
+        while (!$id_rubrique && ($row_rub = sql_fetch($res))) {
58
+            if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) {
59
+                $id_rubrique = $row_rub['id_rubrique'];
60
+            }
61
+        }
62
+    }
63 63
 
64
-	return $id_rubrique;
64
+    return $id_rubrique;
65 65
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		$id_rubrique = $GLOBALS['connect_id_rubrique'][0];
42 42
 	} elseif (
43 43
 		is_int(_AUTO_SELECTION_RUBRIQUE)
44
-		&& sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE)
44
+		&& sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique='.(int) _AUTO_SELECTION_RUBRIQUE)
45 45
 	) {
46 46
 		$id_rubrique = _AUTO_SELECTION_RUBRIQUE;
47 47
 	} else {
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 		$id_rubrique = $row_rub['id_rubrique'];
51 51
 	}
52 52
 	// si le choix ne convient pas, on cherche dans un secteur
53
-	if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) {
53
+	if (!autoriser('creer'.$objet.'dans', 'rubrique', $id_rubrique)) {
54 54
 		$id_rubrique = '';
55 55
 		// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
56 56
 		$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
57 57
 		while (!$id_rubrique && ($row_rub = sql_fetch($res))) {
58
-			if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) {
58
+			if (autoriser('creer'.$objet.'dans', 'rubrique', $row_rub['id_rubrique'])) {
59 59
 				$id_rubrique = $row_rub['id_rubrique'];
60 60
 			}
61 61
 		}
Please login to merge, or discard this patch.
ecrire/inc/nfslock.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  **/
8 8
 
9 9
 if (!defined('_ECRIRE_INC_VERSION')) {
10
-	return;
10
+    return;
11 11
 }
12 12
 
13 13
 include_spip('inc/acces');
@@ -101,93 +101,93 @@  discard block
 block discarded – undo
101 101
  * @return int|bool Timestamp du verrou, false si erreur
102 102
  */
103 103
 function spip_nfslock($fichier, $max_age = 0) {
104
-	$tries = 0;
104
+    $tries = 0;
105 105
 
106
-	if (!$max_age) {
107
-		$max_age = _DEFAULT_LOCKTIME;
108
-	}
109
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
106
+    if (!$max_age) {
107
+        $max_age = _DEFAULT_LOCKTIME;
108
+    }
109
+    $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
110 110
 
111 111
 
112
-	/*
112
+    /*
113 113
 	 * 1. create a tmp file with a psuedo random file name. we also make
114 114
 	 *    tpath which is a buffer to store the full pathname of the tmp file.
115 115
 	 */
116 116
 
117
-	$id = creer_uniqid();
118
-	$tpath = _DIR_TMP . "slock.$id";
119
-	$tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ...
120
-	if (!$tmpfd) {  /* open failed */
121
-		@fclose($tmpfd);
122
-		spip_unlink($tpath);
117
+    $id = creer_uniqid();
118
+    $tpath = _DIR_TMP . "slock.$id";
119
+    $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ...
120
+    if (!$tmpfd) {  /* open failed */
121
+        @fclose($tmpfd);
122
+        spip_unlink($tpath);
123 123
 
124
-		return false; //NFSL_SYSF
125
-	}
124
+        return false; //NFSL_SYSF
125
+    }
126 126
 
127
-	/*
127
+    /*
128 128
 	 * 2. make fullpath, a buffer for the full pathname of the lock file.
129 129
 	 *    then start looping trying to lock it
130 130
 	 */
131 131
 
132
-	while ($tries < 10) {
133
-		/*
132
+    while ($tries < 10) {
133
+        /*
134 134
 		 * 3. link tmp file to lock file.  if it goes, we win and we clean
135 135
 		 *    up and return the st_ctime of the lock file.
136 136
 		 */
137 137
 
138
-		if (link($tpath, $lock_file) == 1) {
139
-			spip_unlink($tpath); /* got it! */
140
-			@fclose($tmpfd);
141
-			if (($our_tmp = lstat($lock_file)) == false) {  /* stat failed... shouldn't happen */
142
-				spip_unlink($lock_file);
138
+        if (link($tpath, $lock_file) == 1) {
139
+            spip_unlink($tpath); /* got it! */
140
+            @fclose($tmpfd);
141
+            if (($our_tmp = lstat($lock_file)) == false) {  /* stat failed... shouldn't happen */
142
+                spip_unlink($lock_file);
143 143
 
144
-				return false; // (NFSL_SYSF);
145
-			}
144
+                return false; // (NFSL_SYSF);
145
+            }
146 146
 
147
-			return ($our_tmp['ctime']);
148
-		}
147
+            return ($our_tmp['ctime']);
148
+        }
149 149
 
150
-		/*
150
+        /*
151 151
 		 * 4. the lock failed.  check for a stale lock file, being mindful
152 152
 		 *    of NFS and the fact the time is set from the NFS server.  we
153 153
 		 *    do a write on the tmp file to update its time to the server's
154 154
 		 *    idea of "now."
155 155
 		 */
156 156
 
157
-		$old_stat = lstat($lock_file);
158
-		if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) {
159
-			break;
160
-		} /* something bogus is going on */
157
+        $old_stat = lstat($lock_file);
158
+        if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) {
159
+            break;
160
+        } /* something bogus is going on */
161 161
 
162 162
 
163
-		if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) {
164
-			spip_unlink($lock_file); /* break the stale lock */
165
-			$tries++;
166
-			/* It is CRITICAL that we sleep after breaking
163
+        if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) {
164
+            spip_unlink($lock_file); /* break the stale lock */
165
+            $tries++;
166
+            /* It is CRITICAL that we sleep after breaking
167 167
 			 * the lock. Otherwise, we could race with
168 168
 			 * another process and unlink it's newly-
169 169
 			 * created file.
170 170
 			 */
171
-			sleep(1 + random_int(0, 4));
172
-			continue;
173
-		}
171
+            sleep(1 + random_int(0, 4));
172
+            continue;
173
+        }
174 174
 
175
-		/*
175
+        /*
176 176
 		 * 5. try again
177 177
 		 */
178 178
 
179
-		$tries++;
180
-		sleep(1 + random_int(0, 4));
181
-	}
179
+        $tries++;
180
+        sleep(1 + random_int(0, 4));
181
+    }
182 182
 
183
-	/*
183
+    /*
184 184
 	 * 6. give up, failure.
185 185
 	 */
186 186
 
187
-	spip_unlink($tpath);
188
-	@fclose($tmpfd);
187
+    spip_unlink($tpath);
188
+    @fclose($tmpfd);
189 189
 
190
-	return false; //(NFSL_LOCKED);
190
+    return false; //(NFSL_LOCKED);
191 191
 }
192 192
 
193 193
 /**
@@ -231,71 +231,71 @@  discard block
 block discarded – undo
231 231
  * return bool true si déverrouillé, false sinon
232 232
  */
233 233
 function spip_nfsunlock($fichier, $birth, $max_age = 0, $test = false) {
234
-	$id = creer_uniqid();
235
-	if (!$max_age) {
236
-		$max_age = _DEFAULT_LOCKTIME;
237
-	}
234
+    $id = creer_uniqid();
235
+    if (!$max_age) {
236
+        $max_age = _DEFAULT_LOCKTIME;
237
+    }
238 238
 
239
-	/*
239
+    /*
240 240
 	 * 1. Build a temp file and stat that to get an idea of what the server
241 241
 	 *    thinks the current time is (our_tmp.st_ctime)..
242 242
 	 */
243 243
 
244
-	$tpath = _DIR_TMP . "stime.$id";
245
-	$tmpfd = @fopen($tpath, 'w');
246
-	if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) {
247
-		/* The open failed, or we can't write the file, or we can't stat it */
248
-		@fclose($tmpfd);
249
-		spip_unlink($tpath);
244
+    $tpath = _DIR_TMP . "stime.$id";
245
+    $tmpfd = @fopen($tpath, 'w');
246
+    if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) {
247
+        /* The open failed, or we can't write the file, or we can't stat it */
248
+        @fclose($tmpfd);
249
+        spip_unlink($tpath);
250 250
 
251
-		return false; //(NFSL_SYSF);
252
-	}
251
+        return false; //(NFSL_SYSF);
252
+    }
253 253
 
254
-	@fclose($tmpfd);    /* We don't need this once we have our_tmp.st_ctime. */
255
-	spip_unlink($tpath);
254
+    @fclose($tmpfd);    /* We don't need this once we have our_tmp.st_ctime. */
255
+    spip_unlink($tpath);
256 256
 
257
-	/*
257
+    /*
258 258
 	 * 2. make fullpath, a buffer for the full pathname of the lock file
259 259
 	 */
260 260
 
261
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
261
+    $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
262 262
 
263
-	/*
263
+    /*
264 264
 	 * 3. If the ctime hasn't been modified, unlink the file and return. If the
265 265
 	 *    lock has expired, sleep the usual random interval before returning.
266 266
 	 *    If we didn't sleep, there could be a race if the caller immediately
267 267
 	 *    tries to relock the file.
268 268
 	 */
269 269
 
270
-	if (
271
-		($old_stat = @lstat($lock_file))  /* stat succeeds so file is there */
272
-		&& ($old_stat['ctime'] == $birth)
273
-	) {  /* hasn't been modified since birth */
274
-		if (!$test) {
275
-			spip_unlink($lock_file);
276
-		}      /* so the lock is ours to remove */
277
-		if ($our_tmp['ctime'] >= $birth + $max_age) {  /* the lock has expired */
278
-			if (!$test) {
279
-				return false;
280
-			} //(NFSL_LOST);
281
-			sleep(1 + (random_int(0, 4)));    /* so sleep a bit */
282
-		}
283
-
284
-		return true;//(NFSL_OK);			/* success */
285
-	}
286
-
287
-	/*
270
+    if (
271
+        ($old_stat = @lstat($lock_file))  /* stat succeeds so file is there */
272
+        && ($old_stat['ctime'] == $birth)
273
+    ) {  /* hasn't been modified since birth */
274
+        if (!$test) {
275
+            spip_unlink($lock_file);
276
+        }      /* so the lock is ours to remove */
277
+        if ($our_tmp['ctime'] >= $birth + $max_age) {  /* the lock has expired */
278
+            if (!$test) {
279
+                return false;
280
+            } //(NFSL_LOST);
281
+            sleep(1 + (random_int(0, 4)));    /* so sleep a bit */
282
+        }
283
+
284
+        return true;//(NFSL_OK);			/* success */
285
+    }
286
+
287
+    /*
288 288
 	 * 4. Either ctime has been modified, or the entire lock file is missing.
289 289
 	 *    If the lock should still be ours, based on the ctime of the temp
290 290
 	 *    file, return with NFSL_STOLEN. If not, then our lock is expired and
291 291
 	 *    someone else has grabbed the file, so return NFSL_LOST.
292 292
 	 */
293 293
 
294
-	if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */
295
-		return false;
296
-	} //(NFSL_STOLEN);
294
+    if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */
295
+        return false;
296
+    } //(NFSL_STOLEN);
297 297
 
298
-	return false; //(NFSL_LOST);	/* The lock must have expired first. */
298
+    return false; //(NFSL_LOST);	/* The lock must have expired first. */
299 299
 }
300 300
 
301 301
 
@@ -319,5 +319,5 @@  discard block
 block discarded – undo
319 319
  * return bool true si déverrouillé, false sinon
320 320
  */
321 321
 function spip_nfslock_test($fichier, $birth, $max_age = 0) {
322
-	return spip_nfsunlock($fichier, $birth, $max_age, true);
322
+    return spip_nfsunlock($fichier, $birth, $max_age, true);
323 323
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	if (!$max_age) {
107 107
 		$max_age = _DEFAULT_LOCKTIME;
108 108
 	}
109
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
109
+	$lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8);
110 110
 
111 111
 
112 112
 	/*
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 
117 117
 	$id = creer_uniqid();
118
-	$tpath = _DIR_TMP . "slock.$id";
118
+	$tpath = _DIR_TMP."slock.$id";
119 119
 	$tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ...
120 120
 	if (!$tmpfd) {  /* open failed */
121 121
 		@fclose($tmpfd);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 *    thinks the current time is (our_tmp.st_ctime)..
242 242
 	 */
243 243
 
244
-	$tpath = _DIR_TMP . "stime.$id";
244
+	$tpath = _DIR_TMP."stime.$id";
245 245
 	$tmpfd = @fopen($tpath, 'w');
246 246
 	if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) {
247 247
 		/* The open failed, or we can't write the file, or we can't stat it */
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
 		return false; //(NFSL_SYSF);
252 252
 	}
253 253
 
254
-	@fclose($tmpfd);    /* We don't need this once we have our_tmp.st_ctime. */
254
+	@fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */
255 255
 	spip_unlink($tpath);
256 256
 
257 257
 	/*
258 258
 	 * 2. make fullpath, a buffer for the full pathname of the lock file
259 259
 	 */
260 260
 
261
-	$lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8);
261
+	$lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8);
262 262
 
263 263
 	/*
264 264
 	 * 3. If the ctime hasn't been modified, unlink the file and return. If the
@@ -278,10 +278,10 @@  discard block
 block discarded – undo
278 278
 			if (!$test) {
279 279
 				return false;
280 280
 			} //(NFSL_LOST);
281
-			sleep(1 + (random_int(0, 4)));    /* so sleep a bit */
281
+			sleep(1 + (random_int(0, 4))); /* so sleep a bit */
282 282
 		}
283 283
 
284
-		return true;//(NFSL_OK);			/* success */
284
+		return true; //(NFSL_OK);			/* success */
285 285
 	}
286 286
 
287 287
 	/*
Please login to merge, or discard this patch.
ecrire/inc/puce_statut.php 2 patches
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@  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
 if (!defined('_ACTIVER_PUCE_RAPIDE')) {
24
-	/**
25
-	 * Activer le changement rapide de statut sur les listes d'objets ?
26
-	 *
27
-	 * Peut ralentir un site sur des listes très longues.
28
-	 *
29
-	 * @var bool
30
-	 **/
31
-	define('_ACTIVER_PUCE_RAPIDE', true);
24
+    /**
25
+     * Activer le changement rapide de statut sur les listes d'objets ?
26
+     *
27
+     * Peut ralentir un site sur des listes très longues.
28
+     *
29
+     * @var bool
30
+     **/
31
+    define('_ACTIVER_PUCE_RAPIDE', true);
32 32
 }
33 33
 
34 34
 /**
@@ -56,31 +56,31 @@  discard block
 block discarded – undo
56 56
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
57 57
  */
58 58
 function inc_puce_statut_dist(
59
-	$id_objet,
60
-	$statut,
61
-	$id_parent,
62
-	$type,
63
-	$ajax = false,
64
-	$menu_rapide = _ACTIVER_PUCE_RAPIDE
59
+    $id_objet,
60
+    $statut,
61
+    $id_parent,
62
+    $type,
63
+    $ajax = false,
64
+    $menu_rapide = _ACTIVER_PUCE_RAPIDE
65 65
 ) {
66
-	static $f_puce_statut = [];
67
-	$type = objet_type($type);
68
-	// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
69
-	if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) {
70
-		$f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
71
-	}
72
-	if ($f_puce_statut[$type]) {
73
-		return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
74
-	}
75
-
76
-	// si statut_image trouve quelque chose (et '' est quelque chose)
77
-	// composer une puce, avec si possible changement rapide
78
-	elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
79
-		return $puce;
80
-	} // sinon fausse puce avec le type de l'image
81
-	else {
82
-		return http_img_pack("$type-16.png", '');
83
-	}
66
+    static $f_puce_statut = [];
67
+    $type = objet_type($type);
68
+    // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
69
+    if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) {
70
+        $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
71
+    }
72
+    if ($f_puce_statut[$type]) {
73
+        return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
74
+    }
75
+
76
+    // si statut_image trouve quelque chose (et '' est quelque chose)
77
+    // composer une puce, avec si possible changement rapide
78
+    elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
79
+        return $puce;
80
+    } // sinon fausse puce avec le type de l'image
81
+    else {
82
+        return http_img_pack("$type-16.png", '');
83
+    }
84 84
 }
85 85
 
86 86
 /**
@@ -109,41 +109,41 @@  discard block
 block discarded – undo
109 109
  *   null si pas capable de déterminer l'image
110 110
  */
111 111
 function statut_image($objet, $statut) {
112
-	$src = null;
113
-	$table = table_objet_sql($objet);
114
-	$desc = lister_tables_objets_sql($table);
115
-	if (isset($desc['statut_images'])) {
116
-		// si une declaration statut_images
117
-		// mais rien pour le statut demande, ne rien afficher
118
-		$src = '';
119
-		if (isset($desc['statut_images'][$statut])) {
120
-			$src = $desc['statut_images'][$statut];
121
-		} // sinon image par defaut ?
122
-		elseif (isset($desc['statut_images'][0])) {
123
-			$src = $desc['statut_images'][0];
124
-		}
125
-	} else {
126
-		switch ($statut) {
127
-			case 'prepa':
128
-				$src = 'puce-preparer-xx.svg?12px';
129
-				break;
130
-			case 'prop':
131
-				$src = 'puce-proposer-xx.svg?12px';
132
-				break;
133
-			case 'publie':
134
-				$src = 'puce-publier-xx.svg?12px';
135
-				break;
136
-			case 'refuse':
137
-				$src = 'puce-refuser-xx.svg?12px';
138
-				break;
139
-			case 'poubelle':
140
-			case 'poub':
141
-				$src = 'puce-supprimer-xx.svg?12px';
142
-				break;
143
-		}
144
-	}
145
-
146
-	return $src;
112
+    $src = null;
113
+    $table = table_objet_sql($objet);
114
+    $desc = lister_tables_objets_sql($table);
115
+    if (isset($desc['statut_images'])) {
116
+        // si une declaration statut_images
117
+        // mais rien pour le statut demande, ne rien afficher
118
+        $src = '';
119
+        if (isset($desc['statut_images'][$statut])) {
120
+            $src = $desc['statut_images'][$statut];
121
+        } // sinon image par defaut ?
122
+        elseif (isset($desc['statut_images'][0])) {
123
+            $src = $desc['statut_images'][0];
124
+        }
125
+    } else {
126
+        switch ($statut) {
127
+            case 'prepa':
128
+                $src = 'puce-preparer-xx.svg?12px';
129
+                break;
130
+            case 'prop':
131
+                $src = 'puce-proposer-xx.svg?12px';
132
+                break;
133
+            case 'publie':
134
+                $src = 'puce-publier-xx.svg?12px';
135
+                break;
136
+            case 'refuse':
137
+                $src = 'puce-refuser-xx.svg?12px';
138
+                break;
139
+            case 'poubelle':
140
+            case 'poub':
141
+                $src = 'puce-supprimer-xx.svg?12px';
142
+                break;
143
+        }
144
+    }
145
+
146
+    return $src;
147 147
 }
148 148
 
149 149
 /**
@@ -171,40 +171,40 @@  discard block
 block discarded – undo
171 171
  * @return string
172 172
  */
173 173
 function statut_titre($objet, $statut) {
174
-	$titre = '';
175
-	$table = table_objet_sql($objet);
176
-	$desc = lister_tables_objets_sql($table);
177
-	if (isset($desc['statut_titres'])) {
178
-		// si une declaration statut_titres
179
-		// mais rien pour le statut demande, ne rien afficher
180
-		if (isset($desc['statut_titres'][$statut])) {
181
-			$titre = $desc['statut_titres'][$statut];
182
-		} // sinon image par defaut ?
183
-		elseif (isset($desc['statut_titres'][0])) {
184
-			$titre = $desc['statut_titres'][0];
185
-		}
186
-	} else {
187
-		switch ($statut) {
188
-			case 'prepa':
189
-				$titre = 'texte_statut_en_cours_redaction';
190
-				break;
191
-			case 'prop':
192
-				$titre = 'texte_statut_propose_evaluation';
193
-				break;
194
-			case 'publie':
195
-				$titre = 'texte_statut_publie';
196
-				break;
197
-			case 'refuse':
198
-				$titre = 'texte_statut_refuse';
199
-				break;
200
-			case 'poubelle':
201
-			case 'poub':
202
-				$titre = 'texte_statut_poubelle';
203
-				break;
204
-		}
205
-	}
206
-
207
-	return $titre ? _T($titre) : '';
174
+    $titre = '';
175
+    $table = table_objet_sql($objet);
176
+    $desc = lister_tables_objets_sql($table);
177
+    if (isset($desc['statut_titres'])) {
178
+        // si une declaration statut_titres
179
+        // mais rien pour le statut demande, ne rien afficher
180
+        if (isset($desc['statut_titres'][$statut])) {
181
+            $titre = $desc['statut_titres'][$statut];
182
+        } // sinon image par defaut ?
183
+        elseif (isset($desc['statut_titres'][0])) {
184
+            $titre = $desc['statut_titres'][0];
185
+        }
186
+    } else {
187
+        switch ($statut) {
188
+            case 'prepa':
189
+                $titre = 'texte_statut_en_cours_redaction';
190
+                break;
191
+            case 'prop':
192
+                $titre = 'texte_statut_propose_evaluation';
193
+                break;
194
+            case 'publie':
195
+                $titre = 'texte_statut_publie';
196
+                break;
197
+            case 'refuse':
198
+                $titre = 'texte_statut_refuse';
199
+                break;
200
+            case 'poubelle':
201
+            case 'poub':
202
+                $titre = 'texte_statut_poubelle';
203
+                break;
204
+        }
205
+    }
206
+
207
+    return $titre ? _T($titre) : '';
208 208
 }
209 209
 
210 210
 
@@ -224,37 +224,37 @@  discard block
 block discarded – undo
224 224
  * @return string
225 225
  */
226 226
 function statut_texte_instituer($objet, $statut) {
227
-	$texte = '';
228
-	$table = table_objet_sql($objet);
229
-	$desc = lister_tables_objets_sql($table);
230
-	if (isset($desc['statut_textes_instituer'])) {
231
-		// si une declaration statut_titres
232
-		// mais rien pour le statut demande, ne rien afficher
233
-		if (isset($desc['statut_textes_instituer'][$statut])) {
234
-			$texte = $desc['statut_textes_instituer'][$statut];
235
-		}
236
-	} else {
237
-		switch ($statut) {
238
-			case 'prepa':
239
-				$texte = 'texte_statut_en_cours_redaction';
240
-				break;
241
-			case 'prop':
242
-				$texte = 'texte_statut_propose_evaluation';
243
-				break;
244
-			case 'publie':
245
-				$texte = 'texte_statut_publie';
246
-				break;
247
-			case 'refuse':
248
-				$texte = 'texte_statut_refuse';
249
-				break;
250
-			case 'poubelle':
251
-			case 'poub':
252
-				$texte = 'texte_statut_poubelle';
253
-				break;
254
-		}
255
-	}
256
-
257
-	return $texte ? _T($texte) : '';
227
+    $texte = '';
228
+    $table = table_objet_sql($objet);
229
+    $desc = lister_tables_objets_sql($table);
230
+    if (isset($desc['statut_textes_instituer'])) {
231
+        // si une declaration statut_titres
232
+        // mais rien pour le statut demande, ne rien afficher
233
+        if (isset($desc['statut_textes_instituer'][$statut])) {
234
+            $texte = $desc['statut_textes_instituer'][$statut];
235
+        }
236
+    } else {
237
+        switch ($statut) {
238
+            case 'prepa':
239
+                $texte = 'texte_statut_en_cours_redaction';
240
+                break;
241
+            case 'prop':
242
+                $texte = 'texte_statut_propose_evaluation';
243
+                break;
244
+            case 'publie':
245
+                $texte = 'texte_statut_publie';
246
+                break;
247
+            case 'refuse':
248
+                $texte = 'texte_statut_refuse';
249
+                break;
250
+            case 'poubelle':
251
+            case 'poub':
252
+                $texte = 'texte_statut_poubelle';
253
+                break;
254
+        }
255
+    }
256
+
257
+    return $texte ? _T($texte) : '';
258 258
 }
259 259
 
260 260
 
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
  * @return string
275 275
  */
276 276
 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
277
-	$img = statut_image('auteur', $statut);
278
-	if (!$img) {
279
-		return '';
280
-	}
281
-	$alt = statut_titre('auteur', $statut);
277
+    $img = statut_image('auteur', $statut);
278
+    if (!$img) {
279
+        return '';
280
+    }
281
+    $alt = statut_titre('auteur', $statut);
282 282
 
283
-	$fond = '';
284
-	$titre = '';
283
+    $fond = '';
284
+    $titre = '';
285 285
 
286
-	/*
286
+    /*
287 287
 	if ($type != 'auteur') {
288 288
 	  $img2 = chemin_image('del-16.png');
289 289
 	  $titre = _T('titre_image_redacteur');
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
 	}
294 294
 	*/
295 295
 
296
-	return http_img_pack($img, $alt, $fond, $alt);
296
+    return http_img_pack($img, $alt, $fond, $alt);
297 297
 }
298 298
 
299 299
 
300 300
 function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
301
-	return http_img_pack('rubrique-16.png', '');
301
+    return http_img_pack('rubrique-16.png', '');
302 302
 }
303 303
 
304 304
 /**
@@ -322,101 +322,101 @@  discard block
 block discarded – undo
322 322
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
323 323
  **/
324 324
 function puce_statut_changement_rapide(
325
-	$id,
326
-	$statut,
327
-	$id_rubrique,
328
-	$type = 'article',
329
-	$ajax = false,
330
-	$menu_rapide = _ACTIVER_PUCE_RAPIDE
325
+    $id,
326
+    $statut,
327
+    $id_rubrique,
328
+    $type = 'article',
329
+    $ajax = false,
330
+    $menu_rapide = _ACTIVER_PUCE_RAPIDE
331 331
 ) {
332
-	$src = statut_image($type, $statut);
333
-	if (!$src) {
334
-		return $src;
335
-	}
336
-
337
-	$ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'";
338
-
339
-
340
-	$t = statut_titre($type, $statut);
341
-	$inser_puce = http_img_pack($src, $t, $ajax_node, $t);
342
-
343
-	if (!$ajax_node) {
344
-		return $inser_puce;
345
-	}
346
-
347
-	$table = table_objet_sql($type);
348
-	$desc = lister_tables_objets_sql($table);
349
-	if (!isset($desc['statut_textes_instituer'])) {
350
-		return $inser_puce;
351
-	}
352
-
353
-	if (!function_exists('autoriser')) {
354
-		include_spip('inc/autoriser');
355
-	}
356
-
357
-	// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
358
-	if ($id_rubrique) {
359
-		if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
360
-			return $inser_puce;
361
-		}
362
-	} // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
363
-	else {
364
-		if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) {
365
-			return $inser_puce;
366
-		}
367
-	}
368
-
369
-	$coord = array_flip(array_keys($desc['statut_textes_instituer']));
370
-	if (!isset($coord[$statut])) {
371
-		return $inser_puce;
372
-	}
373
-
374
-	$unit = 18/*widh de img*/ + 0/*padding*/
375
-	;
376
-	$margin = 0; /* marge a gauche + droite */
377
-	$zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/
378
-	;
379
-	$clip = $zero + ($unit * $coord[$statut]);
380
-
381
-	if ($ajax) {
382
-		$width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin;
383
-		$out = "<span class='puce_objet_fixe $type'>"
384
-			. $inser_puce
385
-			. '</span>'
386
-			. "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
387
-		$i = 0;
388
-		foreach ($desc['statut_textes_instituer'] as $s => $t) {
389
-			$out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
390
-		}
391
-
392
-		return $out . '</span>';
393
-	} else {
394
-		$nom = 'puce_statut_';
395
-		$action = generer_url_ecrire('puce_statut', '', true);
396
-		$lang_dir = lang_dir(lang_typo());
397
-
398
-		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'>"
399
-		. $inser_puce
400
-		. '</span>';
401
-	}
332
+    $src = statut_image($type, $statut);
333
+    if (!$src) {
334
+        return $src;
335
+    }
336
+
337
+    $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'";
338
+
339
+
340
+    $t = statut_titre($type, $statut);
341
+    $inser_puce = http_img_pack($src, $t, $ajax_node, $t);
342
+
343
+    if (!$ajax_node) {
344
+        return $inser_puce;
345
+    }
346
+
347
+    $table = table_objet_sql($type);
348
+    $desc = lister_tables_objets_sql($table);
349
+    if (!isset($desc['statut_textes_instituer'])) {
350
+        return $inser_puce;
351
+    }
352
+
353
+    if (!function_exists('autoriser')) {
354
+        include_spip('inc/autoriser');
355
+    }
356
+
357
+    // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
358
+    if ($id_rubrique) {
359
+        if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
360
+            return $inser_puce;
361
+        }
362
+    } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
363
+    else {
364
+        if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) {
365
+            return $inser_puce;
366
+        }
367
+    }
368
+
369
+    $coord = array_flip(array_keys($desc['statut_textes_instituer']));
370
+    if (!isset($coord[$statut])) {
371
+        return $inser_puce;
372
+    }
373
+
374
+    $unit = 18/*widh de img*/ + 0/*padding*/
375
+    ;
376
+    $margin = 0; /* marge a gauche + droite */
377
+    $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/
378
+    ;
379
+    $clip = $zero + ($unit * $coord[$statut]);
380
+
381
+    if ($ajax) {
382
+        $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin;
383
+        $out = "<span class='puce_objet_fixe $type'>"
384
+            . $inser_puce
385
+            . '</span>'
386
+            . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
387
+        $i = 0;
388
+        foreach ($desc['statut_textes_instituer'] as $s => $t) {
389
+            $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
390
+        }
391
+
392
+        return $out . '</span>';
393
+    } else {
394
+        $nom = 'puce_statut_';
395
+        $action = generer_url_ecrire('puce_statut', '', true);
396
+        $lang_dir = lang_dir(lang_typo());
397
+
398
+        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'>"
399
+        . $inser_puce
400
+        . '</span>';
401
+    }
402 402
 }
403 403
 
404 404
 
405 405
 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
406
-	$h = generer_action_auteur('instituer_objet', "$type-$id-$statut");
407
-	$t = supprimer_tags($titre);
406
+    $h = generer_action_auteur('instituer_objet', "$type-$id-$statut");
407
+    $t = supprimer_tags($titre);
408 408
 
409
-	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>';
409
+    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>';
410 410
 }
411 411
 
412 412
 // compat
413 413
 // La couleur du statut
414 414
 
415 415
 function puce_statut($statut, $atts = '') {
416
-	$src = statut_image('article', $statut);
417
-	if (!$src) {
418
-		return '';
419
-	}
416
+    $src = statut_image('article', $statut);
417
+    if (!$src) {
418
+        return '';
419
+    }
420 420
 
421
-	return http_img_pack($src, statut_titre('article', $statut), $atts);
421
+    return http_img_pack($src, statut_titre('article', $statut), $atts);
422 422
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 			$out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
390 390
 		}
391 391
 
392
-		return $out . '</span>';
392
+		return $out.'</span>';
393 393
 	} else {
394 394
 		$nom = 'puce_statut_';
395 395
 		$action = generer_url_ecrire('puce_statut', '', true);
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 	$h = generer_action_auteur('instituer_objet', "$type-$id-$statut");
407 407
 	$t = supprimer_tags($titre);
408 408
 
409
-	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>';
409
+	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>';
410 410
 }
411 411
 
412 412
 // compat
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 3 patches
Braces   +3 added lines, -7 removed lines patch added patch discarded remove patch
@@ -537,8 +537,7 @@  discard block
 block discarded – undo
537 537
 			process_image_svg_identite($ret);
538 538
 			$ret['creer'] = false;
539 539
 		}
540
-	}
541
-	else {
540
+	} else {
542 541
 		if (!function_exists($ret['fonction_imagecreatefrom'])) {
543 542
 			return false;
544 543
 		}
@@ -1356,9 +1355,7 @@  discard block
 block discarded – undo
1356 1355
 	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1357 1356
 		$vignette = $destination . '.' . $format;
1358 1357
 		@copy($image, $vignette);
1359
-	}
1360
-
1361
-	elseif ($valeurs['format_source'] === 'svg') {
1358
+	} elseif ($valeurs['format_source'] === 'svg') {
1362 1359
 		include_spip('inc/svg');
1363 1360
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1364 1361
 			$format_sortie = 'svg';
@@ -1793,8 +1790,7 @@  discard block
 block discarded – undo
1793 1790
 		$date = test_espace_prive() ? ('?' . $date) : '';
1794 1791
 
1795 1792
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796
-	}
1797
-	else {
1793
+	} else {
1798 1794
 		# BMP, tiff ... les redacteurs osent tout!
1799 1795
 		return $img;
1800 1796
 	}
Please login to merge, or discard this patch.
Indentation   +1286 added lines, -1286 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('inc/filtres'); // par precaution
23 23
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
  *     Le code de la couleur en hexadécimal.
38 38
  */
39 39
 function _couleur_dec_to_hex($red, $green, $blue) {
40
-	$red = dechex($red);
41
-	$green = dechex($green);
42
-	$blue = dechex($blue);
43
-
44
-	if (strlen($red) == 1) {
45
-		$red = '0' . $red;
46
-	}
47
-	if (strlen($green) == 1) {
48
-		$green = '0' . $green;
49
-	}
50
-	if (strlen($blue) == 1) {
51
-		$blue = '0' . $blue;
52
-	}
53
-
54
-	return "$red$green$blue";
40
+    $red = dechex($red);
41
+    $green = dechex($green);
42
+    $blue = dechex($blue);
43
+
44
+    if (strlen($red) == 1) {
45
+        $red = '0' . $red;
46
+    }
47
+    if (strlen($green) == 1) {
48
+        $green = '0' . $green;
49
+    }
50
+    if (strlen($blue) == 1) {
51
+        $blue = '0' . $blue;
52
+    }
53
+
54
+    return "$red$green$blue";
55 55
 }
56 56
 
57 57
 /**
@@ -63,18 +63,18 @@  discard block
 block discarded – undo
63 63
  *     Un tableau des 3 éléments : rouge, vert, bleu.
64 64
  */
65 65
 function _couleur_hex_to_dec($couleur) {
66
-	$couleur ??= '';
67
-	$couleur = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
66
+    $couleur ??= '';
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,55 +120,55 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$H = null;
124
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
-	$var_G = ($G / 255);
126
-	$var_B = ($B / 255);
127
-
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
131
-
132
-	$L = ($var_Max + $var_Min) / 2;
133
-
134
-	if ($del_Max == 0) {
135
-		//This is a gray, no chroma...
136
-		$H = 0; //HSL results = 0 ÷ 1
137
-		$S = 0;
138
-	} else {
139
-		// Chromatic data...
140
-		$S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min);
141
-
142
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
143
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
144
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
145
-
146
-		if ($var_R === $var_Max) {
147
-			$H = $del_B - $del_G;
148
-		} else {
149
-			if ($var_G === $var_Max) {
150
-				$H = (1 / 3) + $del_R - $del_B;
151
-			} else {
152
-				if ($var_B === $var_Max) {
153
-					$H = (2 / 3) + $del_G - $del_R;
154
-				}
155
-			}
156
-		}
157
-
158
-		if ($H < 0) {
159
-			$H += 1;
160
-		}
161
-		if ($H > 1) {
162
-			$H -= 1;
163
-		}
164
-	}
165
-
166
-	$ret = [];
167
-	$ret['h'] = $H;
168
-	$ret['s'] = $S;
169
-	$ret['l'] = $L;
170
-
171
-	return $ret;
123
+    $H = null;
124
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
+    $var_G = ($G / 255);
126
+    $var_B = ($B / 255);
127
+
128
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
131
+
132
+    $L = ($var_Max + $var_Min) / 2;
133
+
134
+    if ($del_Max == 0) {
135
+        //This is a gray, no chroma...
136
+        $H = 0; //HSL results = 0 ÷ 1
137
+        $S = 0;
138
+    } else {
139
+        // Chromatic data...
140
+        $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min);
141
+
142
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
143
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
144
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
145
+
146
+        if ($var_R === $var_Max) {
147
+            $H = $del_B - $del_G;
148
+        } else {
149
+            if ($var_G === $var_Max) {
150
+                $H = (1 / 3) + $del_R - $del_B;
151
+            } else {
152
+                if ($var_B === $var_Max) {
153
+                    $H = (2 / 3) + $del_G - $del_R;
154
+                }
155
+            }
156
+        }
157
+
158
+        if ($H < 0) {
159
+            $H += 1;
160
+        }
161
+        if ($H > 1) {
162
+            $H -= 1;
163
+        }
164
+    }
165
+
166
+    $ret = [];
167
+    $ret['h'] = $H;
168
+    $ret['s'] = $S;
169
+    $ret['l'] = $L;
170
+
171
+    return $ret;
172 172
 }
173 173
 
174 174
 
@@ -184,48 +184,48 @@  discard block
 block discarded – undo
184 184
  * @return array
185 185
  */
186 186
 function _couleur_hsl_to_rgb($H, $S, $L) {
187
-	// helper
188
-	$hue_2_rgb = function ($v1, $v2, $vH) {
189
-		if ($vH < 0) {
190
-			$vH += 1;
191
-		}
192
-		if ($vH > 1) {
193
-			$vH -= 1;
194
-		}
195
-		if ((6 * $vH) < 1) {
196
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
197
-		}
198
-		if ((2 * $vH) < 1) {
199
-			return ($v2);
200
-		}
201
-		if ((3 * $vH) < 2) {
202
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
203
-		}
204
-
205
-		return ($v1);
206
-	};
207
-
208
-	if ($S == 0) {
209
-		// HSV values = 0 -> 1
210
-		$R = $L * 255;
211
-		$G = $L * 255;
212
-		$B = $L * 255;
213
-	} else {
214
-		$var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L);
215
-
216
-		$var_1 = 2 * $L - $var_2;
217
-
218
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
219
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
220
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
221
-	}
222
-
223
-	$ret = [];
224
-	$ret['r'] = floor($R);
225
-	$ret['g'] = floor($G);
226
-	$ret['b'] = floor($B);
227
-
228
-	return $ret;
187
+    // helper
188
+    $hue_2_rgb = function ($v1, $v2, $vH) {
189
+        if ($vH < 0) {
190
+            $vH += 1;
191
+        }
192
+        if ($vH > 1) {
193
+            $vH -= 1;
194
+        }
195
+        if ((6 * $vH) < 1) {
196
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
197
+        }
198
+        if ((2 * $vH) < 1) {
199
+            return ($v2);
200
+        }
201
+        if ((3 * $vH) < 2) {
202
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
203
+        }
204
+
205
+        return ($v1);
206
+    };
207
+
208
+    if ($S == 0) {
209
+        // HSV values = 0 -> 1
210
+        $R = $L * 255;
211
+        $G = $L * 255;
212
+        $B = $L * 255;
213
+    } else {
214
+        $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L);
215
+
216
+        $var_1 = 2 * $L - $var_2;
217
+
218
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
219
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
220
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
221
+    }
222
+
223
+    $ret = [];
224
+    $ret['r'] = floor($R);
225
+    $ret['g'] = floor($G);
226
+    $ret['b'] = floor($B);
227
+
228
+    return $ret;
229 229
 }
230 230
 
231 231
 /**
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
  *     true si il faut supprimer le fichier temporaire ; false sinon.
244 244
  */
245 245
 function statut_effacer_images_temporaires($stat) {
246
-	static $statut = false; // par defaut on grave toute les images
247
-	if ($stat === 'get') {
248
-		return $statut;
249
-	}
250
-	$statut = (bool) $stat;
246
+    static $statut = false; // par defaut on grave toute les images
247
+    if ($stat === 'get') {
248
+        return $statut;
249
+    }
250
+    $statut = (bool) $stat;
251 251
 }
252 252
 
253 253
 
@@ -300,250 +300,250 @@  discard block
 block discarded – undo
300 300
  *     - array : tableau décrivant de l'image
301 301
  */
302 302
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
303
-	$valeurs = [];
304
-	$ret = [];
305
-	$f = null;
306
-	static $images_recalcul = [];
307
-	if (strlen($img) == 0) {
308
-		return false;
309
-	}
310
-
311
-	$source = trim(extraire_attribut($img, 'src') ?? '');
312
-	if (strlen($source) < 1) {
313
-		if (!str_starts_with($img, '<img ')) {
314
-			$source = $img;
315
-			$img = "<img src='$source' />";
316
-		} else {
317
-			// pas d'attribut src sur cette balise <img../>
318
-			return false;
319
-		}
320
-	} elseif (
321
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
-		&& ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
323
-		&& in_array($extension, _image_extensions_acceptees_en_entree())
324
-	) {
325
-		# gerer img src="data:....base64"
326
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
-		if (!file_exists($local)) {
328
-			ecrire_fichier($local, base64_decode($regs[2]));
329
-		}
330
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
331
-			$sanitizer($local);
332
-		}
333
-		$source = $local;
334
-		$img = inserer_attribut($img, 'src', $source);
335
-		# eviter les mauvaises surprises lors de conversions de format
336
-		$img = inserer_attribut($img, 'width', '');
337
-		$img = inserer_attribut($img, 'height', '');
338
-	}
339
-
340
-	// les protocoles web prennent au moins 3 lettres
341
-	if (tester_url_absolue($source)) {
342
-		include_spip('inc/distant');
343
-		$fichier = _DIR_RACINE . copie_locale($source);
344
-		if (!$fichier) {
345
-			return '';
346
-		}
347
-		if (
348
-			($extension = _image_trouver_extension($fichier))
349
-			&& ($sanitizer = charger_fonction($extension, 'sanitizer', true))
350
-		) {
351
-			$sanitizer($fichier);
352
-		}
353
-	} else {
354
-		// enlever le timestamp eventuel
355
-		if (str_contains($source, '?')) {
356
-			$source = preg_replace(',[?]\d+$,', '', $source);
357
-		}
358
-		if (
359
-			str_contains($source, '?')
360
-			&& str_starts_with($source, (string) _DIR_IMG)
361
-			&& file_exists($f = preg_replace(',[?].*$,', '', $source))
362
-		) {
363
-			$source = $f;
364
-		}
365
-		$fichier = $source;
366
-	}
367
-
368
-	$terminaison_dest = '';
369
-	if ($terminaison = _image_trouver_extension($fichier)) {
370
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
371
-	}
372
-
373
-	if (
374
-		$forcer_format !== false
375
-		&& ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
376
-	) {
377
-		$terminaison_dest = $forcer_format;
378
-	}
379
-
380
-	if (!$terminaison_dest) {
381
-		return false;
382
-	}
383
-
384
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
385
-	$fichier_dest = $nom_fichier;
386
-	if (
387
-		$find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f)
388
-		|| @file_exists($f = $fichier)
389
-	) {
390
-		// on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance
391
-		// on lit directement les infos du fichier
392
-		[$ret['hauteur'], $ret['largeur']] = taille_image($f);
393
-		$date_src = @filemtime($f);
394
-	} elseif (
395
-		@file_exists($f = "$fichier.src")
396
-		&& lire_fichier($f, $valeurs)
397
-		&& ($valeurs = unserialize($valeurs))
398
-		&& isset($valeurs['hauteur_dest'])
399
-		&& isset($valeurs['largeur_dest'])
400
-	) {
401
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
402
-		$ret['largeur'] = $valeurs['largeur_dest'];
403
-		$date_src = $valeurs['date'];
404
-	} // pas de fichier source par la
405
-	else {
406
-		return false;
407
-	}
408
-
409
-	// pas de taille mesurable ?
410
-	if (
411
-		!$ret['hauteur']
412
-		|| !($ret['hauteur'] = (int) round($ret['hauteur']))
413
-		|| !$ret['largeur']
414
-		|| !($ret['largeur'] = (int) round($ret['largeur']))
415
-	) {
416
-		return false;
417
-	}
418
-
419
-	// les images calculees dependent du chemin du fichier source
420
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
421
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
422
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
423
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
424
-	// alors que ca concerne peu de site au final
425
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
426
-	$identifiant = $fichier;
427
-
428
-	// cas general :
429
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
430
-	// cas particulier de reduire :
431
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
432
-	$cache = 'cache-gd2';
433
-	if (str_starts_with($effet, 'reduire')) {
434
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
435
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
436
-		$ret['largeur_dest'] = $destWidth;
437
-		$ret['hauteur_dest'] = $destHeight;
438
-		$effet = "L{$destWidth}xH$destHeight";
439
-		$cache = 'cache-vignettes';
440
-		$fichier_dest = basename($fichier_dest);
441
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
442
-			// on garde la terminaison initiale car image simplement copiee
443
-			// et on postfixe son nom avec un md5 du path
444
-			$terminaison_dest = $terminaison;
445
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
446
-		} else {
447
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
448
-		}
449
-		$cache = sous_repertoire(_DIR_VAR, $cache);
450
-		$cache = sous_repertoire($cache, $effet);
451
-	} else {
452
-		$fichier_dest = md5("$identifiant-$effet");
453
-		$cache = sous_repertoire(_DIR_VAR, $cache);
454
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
455
-		$fichier_dest = substr($fichier_dest, 2);
456
-	}
457
-
458
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
459
-
460
-	$GLOBALS['images_calculees'][] = $fichier_dest;
461
-
462
-	$creer = true;
463
-	// si recalcul des images demande, recalculer chaque image une fois
464
-	if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) {
465
-		$images_recalcul[$fichier_dest] = true;
466
-	} else {
467
-		if (@file_exists($f = $fichier_dest)) {
468
-			if (filemtime($f) >= $date_src) {
469
-				$creer = false;
470
-			}
471
-		} else {
472
-			if (
473
-				@file_exists($f = "$fichier_dest.src")
474
-				&& lire_fichier($f, $valeurs)
475
-				&& ($valeurs = unserialize($valeurs))
476
-				&& $valeurs['date'] >= $date_src
477
-			) {
478
-				$creer = false;
479
-			}
480
-		}
481
-	}
482
-	if ($creer && !@file_exists($fichier)) {
483
-		if (!@file_exists("$fichier.src")) {
484
-			spip_logger('images')->error("Image absente : $fichier");
485
-
486
-			return false;
487
-		}
488
-		# on reconstruit l'image source absente a partir de la chaine des .src
489
-		reconstruire_image_intermediaire($fichier);
490
-	}
491
-
492
-	if ($creer) {
493
-		spip_logger('images')->error(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
-		);
496
-	}
497
-
498
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
499
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
-	$ret['fichier'] = $fichier;
501
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
-	$ret['fichier_dest'] = $fichier_dest;
503
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
504
-	$ret['format_dest'] = $terminaison_dest;
505
-	$ret['date_src'] = $date_src;
506
-	$ret['creer'] = $creer;
507
-	$ret['class'] = extraire_attribut($img, 'class');
508
-	$ret['alt'] = extraire_attribut($img, 'alt');
509
-	$ret['style'] = extraire_attribut($img, 'style');
510
-	$ret['tag'] = $img;
511
-	if ($fonction_creation) {
512
-		$ret['reconstruction'] = $fonction_creation;
513
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
514
-		# cas de image_reduire qui finalement ne reduit pas l'image source
515
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
516
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
517
-	}
518
-
519
-	$ret = pipeline('image_preparer_filtre', [
520
-			'args' => [
521
-				'img' => $img,
522
-				'effet' => $effet,
523
-				'forcer_format' => $forcer_format,
524
-				'fonction_creation' => $fonction_creation,
525
-				'find_in_path' => $find_in_path,
526
-			],
527
-			'data' => $ret
528
-		]);
529
-
530
-	// une globale pour le debug en cas de crash memoire
531
-	$GLOBALS['derniere_image_calculee'] = $ret;
532
-
533
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
534
-	if ($term_fonction === 'svg') {
535
-		if ($creer && !$support_svg) {
536
-			process_image_svg_identite($ret);
537
-			$ret['creer'] = false;
538
-		}
539
-	}
540
-	else {
541
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
542
-			return false;
543
-		}
544
-	}
545
-
546
-	return $ret;
303
+    $valeurs = [];
304
+    $ret = [];
305
+    $f = null;
306
+    static $images_recalcul = [];
307
+    if (strlen($img) == 0) {
308
+        return false;
309
+    }
310
+
311
+    $source = trim(extraire_attribut($img, 'src') ?? '');
312
+    if (strlen($source) < 1) {
313
+        if (!str_starts_with($img, '<img ')) {
314
+            $source = $img;
315
+            $img = "<img src='$source' />";
316
+        } else {
317
+            // pas d'attribut src sur cette balise <img../>
318
+            return false;
319
+        }
320
+    } elseif (
321
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
+        && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
323
+        && in_array($extension, _image_extensions_acceptees_en_entree())
324
+    ) {
325
+        # gerer img src="data:....base64"
326
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
+        if (!file_exists($local)) {
328
+            ecrire_fichier($local, base64_decode($regs[2]));
329
+        }
330
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
331
+            $sanitizer($local);
332
+        }
333
+        $source = $local;
334
+        $img = inserer_attribut($img, 'src', $source);
335
+        # eviter les mauvaises surprises lors de conversions de format
336
+        $img = inserer_attribut($img, 'width', '');
337
+        $img = inserer_attribut($img, 'height', '');
338
+    }
339
+
340
+    // les protocoles web prennent au moins 3 lettres
341
+    if (tester_url_absolue($source)) {
342
+        include_spip('inc/distant');
343
+        $fichier = _DIR_RACINE . copie_locale($source);
344
+        if (!$fichier) {
345
+            return '';
346
+        }
347
+        if (
348
+            ($extension = _image_trouver_extension($fichier))
349
+            && ($sanitizer = charger_fonction($extension, 'sanitizer', true))
350
+        ) {
351
+            $sanitizer($fichier);
352
+        }
353
+    } else {
354
+        // enlever le timestamp eventuel
355
+        if (str_contains($source, '?')) {
356
+            $source = preg_replace(',[?]\d+$,', '', $source);
357
+        }
358
+        if (
359
+            str_contains($source, '?')
360
+            && str_starts_with($source, (string) _DIR_IMG)
361
+            && file_exists($f = preg_replace(',[?].*$,', '', $source))
362
+        ) {
363
+            $source = $f;
364
+        }
365
+        $fichier = $source;
366
+    }
367
+
368
+    $terminaison_dest = '';
369
+    if ($terminaison = _image_trouver_extension($fichier)) {
370
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
371
+    }
372
+
373
+    if (
374
+        $forcer_format !== false
375
+        && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
376
+    ) {
377
+        $terminaison_dest = $forcer_format;
378
+    }
379
+
380
+    if (!$terminaison_dest) {
381
+        return false;
382
+    }
383
+
384
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
385
+    $fichier_dest = $nom_fichier;
386
+    if (
387
+        $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f)
388
+        || @file_exists($f = $fichier)
389
+    ) {
390
+        // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance
391
+        // on lit directement les infos du fichier
392
+        [$ret['hauteur'], $ret['largeur']] = taille_image($f);
393
+        $date_src = @filemtime($f);
394
+    } elseif (
395
+        @file_exists($f = "$fichier.src")
396
+        && lire_fichier($f, $valeurs)
397
+        && ($valeurs = unserialize($valeurs))
398
+        && isset($valeurs['hauteur_dest'])
399
+        && isset($valeurs['largeur_dest'])
400
+    ) {
401
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
402
+        $ret['largeur'] = $valeurs['largeur_dest'];
403
+        $date_src = $valeurs['date'];
404
+    } // pas de fichier source par la
405
+    else {
406
+        return false;
407
+    }
408
+
409
+    // pas de taille mesurable ?
410
+    if (
411
+        !$ret['hauteur']
412
+        || !($ret['hauteur'] = (int) round($ret['hauteur']))
413
+        || !$ret['largeur']
414
+        || !($ret['largeur'] = (int) round($ret['largeur']))
415
+    ) {
416
+        return false;
417
+    }
418
+
419
+    // les images calculees dependent du chemin du fichier source
420
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
421
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
422
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
423
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
424
+    // alors que ca concerne peu de site au final
425
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
426
+    $identifiant = $fichier;
427
+
428
+    // cas general :
429
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
430
+    // cas particulier de reduire :
431
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
432
+    $cache = 'cache-gd2';
433
+    if (str_starts_with($effet, 'reduire')) {
434
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
435
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
436
+        $ret['largeur_dest'] = $destWidth;
437
+        $ret['hauteur_dest'] = $destHeight;
438
+        $effet = "L{$destWidth}xH$destHeight";
439
+        $cache = 'cache-vignettes';
440
+        $fichier_dest = basename($fichier_dest);
441
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
442
+            // on garde la terminaison initiale car image simplement copiee
443
+            // et on postfixe son nom avec un md5 du path
444
+            $terminaison_dest = $terminaison;
445
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
446
+        } else {
447
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
448
+        }
449
+        $cache = sous_repertoire(_DIR_VAR, $cache);
450
+        $cache = sous_repertoire($cache, $effet);
451
+    } else {
452
+        $fichier_dest = md5("$identifiant-$effet");
453
+        $cache = sous_repertoire(_DIR_VAR, $cache);
454
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
455
+        $fichier_dest = substr($fichier_dest, 2);
456
+    }
457
+
458
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
459
+
460
+    $GLOBALS['images_calculees'][] = $fichier_dest;
461
+
462
+    $creer = true;
463
+    // si recalcul des images demande, recalculer chaque image une fois
464
+    if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) {
465
+        $images_recalcul[$fichier_dest] = true;
466
+    } else {
467
+        if (@file_exists($f = $fichier_dest)) {
468
+            if (filemtime($f) >= $date_src) {
469
+                $creer = false;
470
+            }
471
+        } else {
472
+            if (
473
+                @file_exists($f = "$fichier_dest.src")
474
+                && lire_fichier($f, $valeurs)
475
+                && ($valeurs = unserialize($valeurs))
476
+                && $valeurs['date'] >= $date_src
477
+            ) {
478
+                $creer = false;
479
+            }
480
+        }
481
+    }
482
+    if ($creer && !@file_exists($fichier)) {
483
+        if (!@file_exists("$fichier.src")) {
484
+            spip_logger('images')->error("Image absente : $fichier");
485
+
486
+            return false;
487
+        }
488
+        # on reconstruit l'image source absente a partir de la chaine des .src
489
+        reconstruire_image_intermediaire($fichier);
490
+    }
491
+
492
+    if ($creer) {
493
+        spip_logger('images')->error(
494
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
+        );
496
+    }
497
+
498
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
499
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
+    $ret['fichier'] = $fichier;
501
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
+    $ret['fichier_dest'] = $fichier_dest;
503
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
504
+    $ret['format_dest'] = $terminaison_dest;
505
+    $ret['date_src'] = $date_src;
506
+    $ret['creer'] = $creer;
507
+    $ret['class'] = extraire_attribut($img, 'class');
508
+    $ret['alt'] = extraire_attribut($img, 'alt');
509
+    $ret['style'] = extraire_attribut($img, 'style');
510
+    $ret['tag'] = $img;
511
+    if ($fonction_creation) {
512
+        $ret['reconstruction'] = $fonction_creation;
513
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
514
+        # cas de image_reduire qui finalement ne reduit pas l'image source
515
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
516
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
517
+    }
518
+
519
+    $ret = pipeline('image_preparer_filtre', [
520
+            'args' => [
521
+                'img' => $img,
522
+                'effet' => $effet,
523
+                'forcer_format' => $forcer_format,
524
+                'fonction_creation' => $fonction_creation,
525
+                'find_in_path' => $find_in_path,
526
+            ],
527
+            'data' => $ret
528
+        ]);
529
+
530
+    // une globale pour le debug en cas de crash memoire
531
+    $GLOBALS['derniere_image_calculee'] = $ret;
532
+
533
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
534
+    if ($term_fonction === 'svg') {
535
+        if ($creer && !$support_svg) {
536
+            process_image_svg_identite($ret);
537
+            $ret['creer'] = false;
538
+        }
539
+    }
540
+    else {
541
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
542
+            return false;
543
+        }
544
+    }
545
+
546
+    return $ret;
547 547
 }
548 548
 
549 549
 
@@ -551,54 +551,54 @@  discard block
 block discarded – undo
551 551
  * Extensions d’images acceptées en entrée
552 552
  */
553 553
 function _image_extensions_acceptees_en_entree(): array {
554
-	static $extensions = null;
555
-	if (empty($extensions)) {
556
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
557
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
558
-			// action=tester renseigne gd_formats et detecte le support de webp
559
-			$extensions = array_merge(explode(',', (string) $GLOBALS['meta']['gd_formats']));
560
-			$extensions = array_map('trim', $extensions);
561
-			$extensions = array_filter($extensions);
562
-			if (in_array('jpg', $extensions)) {
563
-				$extensions[] = 'jpeg';
564
-			}
565
-			$extensions = array_unique($extensions);
566
-		}
567
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
568
-	}
569
-
570
-	return $extensions;
554
+    static $extensions = null;
555
+    if (empty($extensions)) {
556
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
557
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
558
+            // action=tester renseigne gd_formats et detecte le support de webp
559
+            $extensions = array_merge(explode(',', (string) $GLOBALS['meta']['gd_formats']));
560
+            $extensions = array_map('trim', $extensions);
561
+            $extensions = array_filter($extensions);
562
+            if (in_array('jpg', $extensions)) {
563
+                $extensions[] = 'jpeg';
564
+            }
565
+            $extensions = array_unique($extensions);
566
+        }
567
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
568
+    }
569
+
570
+    return $extensions;
571 571
 }
572 572
 
573 573
 /**
574 574
  * Extensions d’images acceptées en sortie
575 575
  */
576 576
 function _image_extensions_acceptees_en_sortie(): array {
577
-	static $extensions = null;
578
-	if (empty($extensions)) {
579
-		$extensions = _image_extensions_acceptees_en_entree();
580
-		$extensions = array_diff($extensions, ['jpeg']);
581
-		if (in_array('gif', $extensions) && !function_exists('imagegif')) {
582
-			$extensions = array_diff($extensions, ['gif']);
583
-		}
584
-		if (in_array('webp', $extensions) && !function_exists('imagewebp')) {
585
-			$extensions = array_diff($extensions, ['webp']);
586
-		}
587
-	}
588
-
589
-	return $extensions;
577
+    static $extensions = null;
578
+    if (empty($extensions)) {
579
+        $extensions = _image_extensions_acceptees_en_entree();
580
+        $extensions = array_diff($extensions, ['jpeg']);
581
+        if (in_array('gif', $extensions) && !function_exists('imagegif')) {
582
+            $extensions = array_diff($extensions, ['gif']);
583
+        }
584
+        if (in_array('webp', $extensions) && !function_exists('imagewebp')) {
585
+            $extensions = array_diff($extensions, ['webp']);
586
+        }
587
+    }
588
+
589
+    return $extensions;
590 590
 }
591 591
 
592 592
 function _image_extension_normalisee($extension) {
593
-	$extension = strtolower((string) $extension);
594
-	if ($extension === 'jpeg') {
595
-		$extension = 'jpg';
596
-	}
597
-	return $extension;
593
+    $extension = strtolower((string) $extension);
594
+    if ($extension === 'jpeg') {
595
+        $extension = 'jpg';
596
+    }
597
+    return $extension;
598 598
 }
599 599
 
600 600
 function _image_extensions_conservent_transparence() {
601
-	return ['png', 'webp'];
601
+    return ['png', 'webp'];
602 602
 }
603 603
 
604 604
 
@@ -608,11 +608,11 @@  discard block
 block discarded – undo
608 608
  * @return string
609 609
  */
610 610
 function _image_trouver_extension($path) {
611
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
612
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
613
-		return strtolower($regs[1]);
614
-	}
615
-	return '';
611
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
612
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
613
+        return strtolower($regs[1]);
614
+    }
615
+    return '';
616 616
 }
617 617
 
618 618
 /**
@@ -623,42 +623,42 @@  discard block
 block discarded – undo
623 623
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
624 624
  */
625 625
 function _image_trouver_extension_pertinente($path) {
626
-	$path = supprimer_timestamp($path);
627
-	$terminaison = _image_trouver_extension($path);
628
-	if ($terminaison == 'jpg') {
629
-		$terminaison = 'jpeg';
630
-	}
631
-
632
-	if (!file_exists($path)) {
633
-		return $terminaison;
634
-	}
635
-
636
-	if (!$info = @spip_getimagesize($path)) {
637
-		return $terminaison;
638
-	}
639
-
640
-	$mime = $info['mime'] ?? image_type_to_mime_type($info[2]);
641
-
642
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
643
-	if ($_terminaison && $_terminaison !== $terminaison) {
644
-		spip_logger('images')->notice("Mauvaise extension du fichier : $path . Son type mime est : $mime");
645
-		$terminaison = $_terminaison;
646
-	}
647
-	return $terminaison;
626
+    $path = supprimer_timestamp($path);
627
+    $terminaison = _image_trouver_extension($path);
628
+    if ($terminaison == 'jpg') {
629
+        $terminaison = 'jpeg';
630
+    }
631
+
632
+    if (!file_exists($path)) {
633
+        return $terminaison;
634
+    }
635
+
636
+    if (!$info = @spip_getimagesize($path)) {
637
+        return $terminaison;
638
+    }
639
+
640
+    $mime = $info['mime'] ?? image_type_to_mime_type($info[2]);
641
+
642
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
643
+    if ($_terminaison && $_terminaison !== $terminaison) {
644
+        spip_logger('images')->notice("Mauvaise extension du fichier : $path . Son type mime est : $mime");
645
+        $terminaison = $_terminaison;
646
+    }
647
+    return $terminaison;
648 648
 }
649 649
 
650 650
 /**
651 651
  * Retourne une extension d’image depuis un mime-type
652 652
  */
653 653
 function _image_trouver_extension_depuis_mime(string $mime): string {
654
-	return match (strtolower($mime)) {
655
-		'image/png', 'image/x-png' => 'png',
656
-		'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg',
657
-		'image/gif' => 'gif',
658
-		'image/webp', 'image/x-webp' => 'webp',
659
-		'image/svg+xml' => 'svg',
660
-		default => '',
661
-	};
654
+    return match (strtolower($mime)) {
655
+        'image/png', 'image/x-png' => 'png',
656
+        'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg',
657
+        'image/gif' => 'gif',
658
+        'image/webp', 'image/x-webp' => 'webp',
659
+        'image/svg+xml' => 'svg',
660
+        default => '',
661
+    };
662 662
 }
663 663
 
664 664
 
@@ -678,18 +678,18 @@  discard block
 block discarded – undo
678 678
  *     Une ressource de type Image GD.
679 679
  */
680 680
 function _imagecreatefrom_func(string $func, string $filename) {
681
-	if (!function_exists($func)) {
682
-		spip_logger('images')->critical("GD indisponible : $func inexistante. Traitement $filename impossible.");
683
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
684
-		return null;
685
-	}
686
-	$img = @$func($filename);
687
-	if (!$img) {
688
-		spip_logger('images')->critical("Erreur lecture $func $filename");
689
-		erreur_squelette("Erreur lecture $func $filename");
690
-		$img = imagecreate(10, 10);
691
-	}
692
-	return $img;
681
+    if (!function_exists($func)) {
682
+        spip_logger('images')->critical("GD indisponible : $func inexistante. Traitement $filename impossible.");
683
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
684
+        return null;
685
+    }
686
+    $img = @$func($filename);
687
+    if (!$img) {
688
+        spip_logger('images')->critical("Erreur lecture $func $filename");
689
+        erreur_squelette("Erreur lecture $func $filename");
690
+        $img = imagecreate(10, 10);
691
+    }
692
+    return $img;
693 693
 }
694 694
 
695 695
 /**
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
  *     Une ressource de type Image GD.
706 706
  */
707 707
 function _imagecreatefromjpeg($filename) {
708
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
708
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
709 709
 }
710 710
 
711 711
 /**
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
  *     Une ressource de type Image GD.
722 722
  */
723 723
 function _imagecreatefrompng($filename) {
724
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
724
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
725 725
 }
726 726
 
727 727
 /**
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
  *     Une ressource de type Image GD.
738 738
  */
739 739
 function _imagecreatefromgif($filename) {
740
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
740
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
741 741
 }
742 742
 
743 743
 
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
  *     Une ressource de type Image GD.
755 755
  */
756 756
 function _imagecreatefromwebp($filename) {
757
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
757
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
758 758
 }
759 759
 
760 760
 /**
@@ -772,24 +772,24 @@  discard block
 block discarded – undo
772 772
  *     - true si une image est bien retournée.
773 773
  */
774 774
 function _image_imagepng($img, $fichier) {
775
-	if (!function_exists('imagepng')) {
776
-		return false;
777
-	}
778
-	$tmp = $fichier . '.tmp';
779
-	$ret = imagepng($img, $tmp);
780
-	if (file_exists($tmp)) {
781
-		$taille_test = @getimagesize($tmp);
782
-		if (empty($taille_test[0])) {
783
-			return false;
784
-		}
785
-
786
-		spip_unlink($fichier); // le fichier peut deja exister
787
-		@rename($tmp, $fichier);
788
-
789
-		return $ret;
790
-	}
791
-
792
-	return false;
775
+    if (!function_exists('imagepng')) {
776
+        return false;
777
+    }
778
+    $tmp = $fichier . '.tmp';
779
+    $ret = imagepng($img, $tmp);
780
+    if (file_exists($tmp)) {
781
+        $taille_test = @getimagesize($tmp);
782
+        if (empty($taille_test[0])) {
783
+            return false;
784
+        }
785
+
786
+        spip_unlink($fichier); // le fichier peut deja exister
787
+        @rename($tmp, $fichier);
788
+
789
+        return $ret;
790
+    }
791
+
792
+    return false;
793 793
 }
794 794
 
795 795
 /**
@@ -807,24 +807,24 @@  discard block
 block discarded – undo
807 807
  *     - true si une image est bien retournée.
808 808
  */
809 809
 function _image_imagegif($img, $fichier) {
810
-	if (!function_exists('imagegif')) {
811
-		return false;
812
-	}
813
-	$tmp = $fichier . '.tmp';
814
-	$ret = imagegif($img, $tmp);
815
-	if (file_exists($tmp)) {
816
-		$taille_test = @getimagesize($tmp);
817
-		if (empty($taille_test[0])) {
818
-			return false;
819
-		}
820
-
821
-		spip_unlink($fichier); // le fichier peut deja exister
822
-		@rename($tmp, $fichier);
823
-
824
-		return $ret;
825
-	}
826
-
827
-	return false;
810
+    if (!function_exists('imagegif')) {
811
+        return false;
812
+    }
813
+    $tmp = $fichier . '.tmp';
814
+    $ret = imagegif($img, $tmp);
815
+    if (file_exists($tmp)) {
816
+        $taille_test = @getimagesize($tmp);
817
+        if (empty($taille_test[0])) {
818
+            return false;
819
+        }
820
+
821
+        spip_unlink($fichier); // le fichier peut deja exister
822
+        @rename($tmp, $fichier);
823
+
824
+        return $ret;
825
+    }
826
+
827
+    return false;
828 828
 }
829 829
 
830 830
 /**
@@ -847,29 +847,29 @@  discard block
 block discarded – undo
847 847
  *     - true si une image est bien retournée.
848 848
  */
849 849
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
850
-	if (!function_exists('imagejpeg')) {
851
-		return false;
852
-	}
853
-	$tmp = $fichier . '.tmp';
850
+    if (!function_exists('imagejpeg')) {
851
+        return false;
852
+    }
853
+    $tmp = $fichier . '.tmp';
854 854
 
855
-	// Enable interlancing
856
-	imageinterlace($img, true);
855
+    // Enable interlancing
856
+    imageinterlace($img, true);
857 857
 
858
-	$ret = imagejpeg($img, $tmp, $qualite);
858
+    $ret = imagejpeg($img, $tmp, $qualite);
859 859
 
860
-	if (file_exists($tmp)) {
861
-		$taille_test = @getimagesize($tmp);
862
-		if (empty($taille_test[0])) {
863
-			return false;
864
-		}
860
+    if (file_exists($tmp)) {
861
+        $taille_test = @getimagesize($tmp);
862
+        if (empty($taille_test[0])) {
863
+            return false;
864
+        }
865 865
 
866
-		spip_unlink($fichier); // le fichier peut deja exister
867
-		@rename($tmp, $fichier);
866
+        spip_unlink($fichier); // le fichier peut deja exister
867
+        @rename($tmp, $fichier);
868 868
 
869
-		return $ret;
870
-	}
869
+        return $ret;
870
+    }
871 871
 
872
-	return false;
872
+    return false;
873 873
 }
874 874
 
875 875
 /**
@@ -887,9 +887,9 @@  discard block
 block discarded – undo
887 887
  *     true si le fichier a bien été créé ; false sinon.
888 888
  */
889 889
 function _image_imageico($img, $fichier) {
890
-	$gd_image_array = [$img];
890
+    $gd_image_array = [$img];
891 891
 
892
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
892
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
893 893
 }
894 894
 
895 895
 
@@ -908,24 +908,24 @@  discard block
 block discarded – undo
908 908
  *     - true si une image est bien retournée.
909 909
  */
910 910
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
911
-	if (!function_exists('imagewebp')) {
912
-		return false;
913
-	}
914
-	$tmp = $fichier . '.tmp';
915
-	$ret = imagewebp($img, $tmp, $qualite);
916
-	if (file_exists($tmp)) {
917
-		$taille_test = @getimagesize($tmp);
918
-		if (empty($taille_test[0])) {
919
-			return false;
920
-		}
921
-
922
-		spip_unlink($fichier); // le fichier peut deja exister
923
-		@rename($tmp, $fichier);
924
-
925
-		return $ret;
926
-	}
927
-
928
-	return false;
911
+    if (!function_exists('imagewebp')) {
912
+        return false;
913
+    }
914
+    $tmp = $fichier . '.tmp';
915
+    $ret = imagewebp($img, $tmp, $qualite);
916
+    if (file_exists($tmp)) {
917
+        $taille_test = @getimagesize($tmp);
918
+        if (empty($taille_test[0])) {
919
+            return false;
920
+        }
921
+
922
+        spip_unlink($fichier); // le fichier peut deja exister
923
+        @rename($tmp, $fichier);
924
+
925
+        return $ret;
926
+    }
927
+
928
+    return false;
929 929
 }
930 930
 
931 931
 /**
@@ -945,35 +945,35 @@  discard block
 block discarded – undo
945 945
  */
946 946
 function _image_imagesvg($img, $fichier) {
947 947
 
948
-	$tmp = $fichier . '.tmp';
949
-	if (!str_contains($img, '<')) {
950
-		$img = supprimer_timestamp($img);
951
-		if (!file_exists($img)) {
952
-			return false;
953
-		}
954
-		@copy($img, $tmp);
955
-		if (filesize($tmp) === filesize($img)) {
956
-			spip_unlink($fichier); // le fichier peut deja exister
957
-			@rename($tmp, $fichier);
958
-			return true;
959
-		}
960
-		return false;
961
-	}
962
-
963
-	file_put_contents($tmp, $img);
964
-	if (file_exists($tmp)) {
965
-		$taille_test = spip_getimagesize($tmp);
966
-		if (empty($taille_test[0])) {
967
-			return false;
968
-		}
969
-
970
-		spip_unlink($fichier); // le fichier peut deja exister
971
-		@rename($tmp, $fichier);
972
-
973
-		return true;
974
-	}
975
-
976
-	return false;
948
+    $tmp = $fichier . '.tmp';
949
+    if (!str_contains($img, '<')) {
950
+        $img = supprimer_timestamp($img);
951
+        if (!file_exists($img)) {
952
+            return false;
953
+        }
954
+        @copy($img, $tmp);
955
+        if (filesize($tmp) === filesize($img)) {
956
+            spip_unlink($fichier); // le fichier peut deja exister
957
+            @rename($tmp, $fichier);
958
+            return true;
959
+        }
960
+        return false;
961
+    }
962
+
963
+    file_put_contents($tmp, $img);
964
+    if (file_exists($tmp)) {
965
+        $taille_test = spip_getimagesize($tmp);
966
+        if (empty($taille_test[0])) {
967
+            return false;
968
+        }
969
+
970
+        spip_unlink($fichier); // le fichier peut deja exister
971
+        @rename($tmp, $fichier);
972
+
973
+        return true;
974
+    }
975
+
976
+    return false;
977 977
 }
978 978
 
979 979
 
@@ -1001,30 +1001,30 @@  discard block
 block discarded – undo
1001 1001
  *     - false sinon.
1002 1002
  */
1003 1003
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1004
-	if (is_null($fonction)) {
1005
-		$fonction = '_image_image' . $valeurs['format_dest'];
1006
-	}
1007
-	$ret = false;
1008
-	#un flag pour reperer les images gravees
1009
-	$lock = (
1010
-		!statut_effacer_images_temporaires('get')
1011
-		|| @file_exists($valeurs['fichier_dest'])
1012
-		&& !@file_exists($valeurs['fichier_dest'] . '.src')
1013
-	);
1014
-	if (
1015
-		function_exists($fonction)
1016
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1017
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1018
-		&& !$lock && @file_exists($valeurs['fichier_dest'])
1019
-	) {
1020
-		// dans tous les cas mettre a jour la taille de l'image finale
1021
-		[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1022
-		$valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1023
-		// pour la retrouver apres disparition
1024
-		ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1025
-	}
1026
-
1027
-	return $ret;
1004
+    if (is_null($fonction)) {
1005
+        $fonction = '_image_image' . $valeurs['format_dest'];
1006
+    }
1007
+    $ret = false;
1008
+    #un flag pour reperer les images gravees
1009
+    $lock = (
1010
+        !statut_effacer_images_temporaires('get')
1011
+        || @file_exists($valeurs['fichier_dest'])
1012
+        && !@file_exists($valeurs['fichier_dest'] . '.src')
1013
+    );
1014
+    if (
1015
+        function_exists($fonction)
1016
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1017
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1018
+        && !$lock && @file_exists($valeurs['fichier_dest'])
1019
+    ) {
1020
+        // dans tous les cas mettre a jour la taille de l'image finale
1021
+        [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1022
+        $valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1023
+        // pour la retrouver apres disparition
1024
+        ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1025
+    }
1026
+
1027
+    return $ret;
1028 1028
 }
1029 1029
 
1030 1030
 /**
@@ -1037,28 +1037,28 @@  discard block
 block discarded – undo
1037 1037
  *     Chemin vers le fichier manquant
1038 1038
  **/
1039 1039
 function reconstruire_image_intermediaire($fichier_manquant) {
1040
-	$source = null;
1041
-	$reconstruire = [];
1042
-	$fichier = $fichier_manquant;
1043
-	while (
1044
-		!str_contains((string) $fichier, '://')
1045
-		&& !@file_exists($fichier)
1046
-		&& lire_fichier($src = "$fichier.src", $source)
1047
-		&& ($valeurs = unserialize($source))
1048
-		&& ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1049
-	) {
1050
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1051
-		$reconstruire[] = $valeurs['reconstruction'];
1052
-	}
1053
-	while (count($reconstruire)) {
1054
-		$r = array_pop($reconstruire);
1055
-		$fonction = $r[0];
1056
-		$args = $r[1];
1057
-		$fonction(...$args);
1058
-	}
1059
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1060
-	// mais l'on peut nettoyer les miettes de sa creation
1061
-	ramasse_miettes($fichier_manquant);
1040
+    $source = null;
1041
+    $reconstruire = [];
1042
+    $fichier = $fichier_manquant;
1043
+    while (
1044
+        !str_contains((string) $fichier, '://')
1045
+        && !@file_exists($fichier)
1046
+        && lire_fichier($src = "$fichier.src", $source)
1047
+        && ($valeurs = unserialize($source))
1048
+        && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1049
+    ) {
1050
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1051
+        $reconstruire[] = $valeurs['reconstruction'];
1052
+    }
1053
+    while (count($reconstruire)) {
1054
+        $r = array_pop($reconstruire);
1055
+        $fonction = $r[0];
1056
+        $args = $r[1];
1057
+        $fonction(...$args);
1058
+    }
1059
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1060
+    // mais l'on peut nettoyer les miettes de sa creation
1061
+    ramasse_miettes($fichier_manquant);
1062 1062
 }
1063 1063
 
1064 1064
 /**
@@ -1078,26 +1078,26 @@  discard block
 block discarded – undo
1078 1078
  *     Chemin du fichier d'image calculé
1079 1079
  **/
1080 1080
 function ramasse_miettes($fichier) {
1081
-	$source = null;
1082
-	if (
1083
-		str_contains($fichier, '://')
1084
-		|| !lire_fichier($src = "$fichier.src", $source)
1085
-		|| !$valeurs = unserialize($source)
1086
-	) {
1087
-		return;
1088
-	}
1089
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1090
-	while (
1091
-		($fichier = $valeurs['fichier'])
1092
-		&& str_starts_with((string) $fichier, (string) _DIR_VAR)
1093
-		&& lire_fichier($src = "$fichier.src", $source)
1094
-		&& ($valeurs = unserialize($source))  # et valide
1095
-	) {
1096
-		# on efface le fichier
1097
-		spip_unlink($fichier);
1098
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1099
-		#spip_unlink($src);
1100
-	}
1081
+    $source = null;
1082
+    if (
1083
+        str_contains($fichier, '://')
1084
+        || !lire_fichier($src = "$fichier.src", $source)
1085
+        || !$valeurs = unserialize($source)
1086
+    ) {
1087
+        return;
1088
+    }
1089
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1090
+    while (
1091
+        ($fichier = $valeurs['fichier'])
1092
+        && str_starts_with((string) $fichier, (string) _DIR_VAR)
1093
+        && lire_fichier($src = "$fichier.src", $source)
1094
+        && ($valeurs = unserialize($source))  # et valide
1095
+    ) {
1096
+        # on efface le fichier
1097
+        spip_unlink($fichier);
1098
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1099
+        #spip_unlink($src);
1100
+    }
1101 1101
 }
1102 1102
 
1103 1103
 
@@ -1122,33 +1122,33 @@  discard block
 block discarded – undo
1122 1122
  *     Code HTML de l'image
1123 1123
  **/
1124 1124
 function image_graver($img) {
1125
-	// appeler le filtre post_image_filtrer qui permet de faire
1126
-	// des traitements auto a la fin d'une serie de filtres
1127
-	$img = pipeline('post_image_filtrer', $img);
1128
-
1129
-	$fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? '');
1130
-	if (($p = strpos($fichier, '?')) !== false) {
1131
-		$fichier = substr($fichier, 0, $p);
1132
-	}
1133
-	if (strlen($fichier) < 1 && !str_starts_with((string) $img, '<img ')) {
1134
-		$fichier = $img;
1135
-	}
1136
-	if (strlen((string) $fichier)) {
1137
-		# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1138
-		# et qu'il ne s'agit pas d'une URL
1139
-		if (!str_contains((string) $fichier, '://') && !@file_exists($fichier)) {
1140
-			reconstruire_image_intermediaire($fichier);
1141
-		}
1142
-		ramasse_miettes($fichier);
1143
-
1144
-		// ajouter le timestamp si besoin
1145
-		if (!str_contains($fichier_ori, '?')) {
1146
-			// on utilise str_replace pour attraper le onmouseover des logo si besoin
1147
-			$img = str_replace($fichier_ori, timestamp($fichier_ori), (string) $img);
1148
-		}
1149
-	}
1150
-
1151
-	return $img;
1125
+    // appeler le filtre post_image_filtrer qui permet de faire
1126
+    // des traitements auto a la fin d'une serie de filtres
1127
+    $img = pipeline('post_image_filtrer', $img);
1128
+
1129
+    $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? '');
1130
+    if (($p = strpos($fichier, '?')) !== false) {
1131
+        $fichier = substr($fichier, 0, $p);
1132
+    }
1133
+    if (strlen($fichier) < 1 && !str_starts_with((string) $img, '<img ')) {
1134
+        $fichier = $img;
1135
+    }
1136
+    if (strlen((string) $fichier)) {
1137
+        # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1138
+        # et qu'il ne s'agit pas d'une URL
1139
+        if (!str_contains((string) $fichier, '://') && !@file_exists($fichier)) {
1140
+            reconstruire_image_intermediaire($fichier);
1141
+        }
1142
+        ramasse_miettes($fichier);
1143
+
1144
+        // ajouter le timestamp si besoin
1145
+        if (!str_contains($fichier_ori, '?')) {
1146
+            // on utilise str_replace pour attraper le onmouseover des logo si besoin
1147
+            $img = str_replace($fichier_ori, timestamp($fichier_ori), (string) $img);
1148
+        }
1149
+    }
1150
+
1151
+    return $img;
1152 1152
 }
1153 1153
 
1154 1154
 /**
@@ -1175,32 +1175,32 @@  discard block
 block discarded – undo
1175 1175
  *     Code html modifié de la balise.
1176 1176
  **/
1177 1177
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1178
-	if ($style === false) {
1179
-		$style = extraire_attribut($tag, 'style');
1180
-	}
1181
-
1182
-	// enlever le width et height du style
1183
-	if ($style) {
1184
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1185
-	}
1186
-	if ($style && $style[0] === ';') {
1187
-		$style = substr($style, 1);
1188
-	}
1189
-
1190
-	// mettre des attributs de width et height sur les images,
1191
-	// ca accelere le rendu du navigateur
1192
-	// ca permet aux navigateurs de reserver la bonne taille
1193
-	// quand on a desactive l'affichage des images.
1194
-	$tag = inserer_attribut($tag, 'width', round($width));
1195
-	$tag = inserer_attribut($tag, 'height', round($height));
1196
-
1197
-	// attributs deprecies. Transformer en CSS
1198
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1199
-		$style = "margin:{$espace}px;" . $style;
1200
-		$tag = inserer_attribut($tag, 'hspace', '');
1201
-	}
1202
-
1203
-	return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style);
1178
+    if ($style === false) {
1179
+        $style = extraire_attribut($tag, 'style');
1180
+    }
1181
+
1182
+    // enlever le width et height du style
1183
+    if ($style) {
1184
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1185
+    }
1186
+    if ($style && $style[0] === ';') {
1187
+        $style = substr($style, 1);
1188
+    }
1189
+
1190
+    // mettre des attributs de width et height sur les images,
1191
+    // ca accelere le rendu du navigateur
1192
+    // ca permet aux navigateurs de reserver la bonne taille
1193
+    // quand on a desactive l'affichage des images.
1194
+    $tag = inserer_attribut($tag, 'width', round($width));
1195
+    $tag = inserer_attribut($tag, 'height', round($height));
1196
+
1197
+    // attributs deprecies. Transformer en CSS
1198
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1199
+        $style = "margin:{$espace}px;" . $style;
1200
+        $tag = inserer_attribut($tag, 'hspace', '');
1201
+    }
1202
+
1203
+    return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style);
1204 1204
 }
1205 1205
 
1206 1206
 
@@ -1226,70 +1226,70 @@  discard block
 block discarded – undo
1226 1226
  *     Retourne le code HTML de l'image
1227 1227
  **/
1228 1228
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1229
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1230
-
1231
-	// fermer les tags img pas bien fermes;
1232
-	$tag = str_replace('>', '/>', str_replace('/>', '>', (string) $valeurs['tag']));
1233
-
1234
-	// le style
1235
-	$style = $valeurs['style'];
1236
-	if (isset($surcharge['style'])) {
1237
-		$style = $surcharge['style'];
1238
-		unset($surcharge['style']);
1239
-	}
1240
-
1241
-	// traiter specifiquement la largeur et la hauteur
1242
-	$width = $valeurs['largeur'];
1243
-	if (isset($surcharge['width'])) {
1244
-		$width = $surcharge['width'];
1245
-		unset($surcharge['width']);
1246
-	}
1247
-	$height = $valeurs['hauteur'];
1248
-	if (isset($surcharge['height'])) {
1249
-		$height = $surcharge['height'];
1250
-		unset($surcharge['height']);
1251
-	}
1252
-
1253
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1254
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1255
-	// on remplace toute les ref a src dans le tag
1256
-	$src = extraire_attribut($tag, 'src');
1257
-	if (isset($surcharge['src'])) {
1258
-		$tag = str_replace($src, $surcharge['src'], $tag);
1259
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1260
-		// pas garanti comme methode, mais mieux que rien
1261
-		if (str_contains($src, '&')) {
1262
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1263
-		}
1264
-		$src = $surcharge['src'];
1265
-		unset($surcharge['src']);
1266
-	}
1267
-
1268
-	$class = $valeurs['class'];
1269
-	if (isset($surcharge['class'])) {
1270
-		$class = $surcharge['class'];
1271
-		unset($surcharge['class']);
1272
-	}
1273
-	if (is_scalar($class) && strlen($class)) {
1274
-		$tag = inserer_attribut($tag, 'class', $class);
1275
-	}
1276
-
1277
-	if ($surcharge !== []) {
1278
-		foreach ($surcharge as $attribut => $valeur) {
1279
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1280
-		}
1281
-	}
1282
-
1283
-	return pipeline(
1284
-		'image_ecrire_tag_finir',
1285
-		[
1286
-			'args' => [
1287
-				'valeurs' => $valeurs,
1288
-				'surcharge' => $surcharge,
1289
-			],
1290
-			'data' => $tag
1291
-		]
1292
-	);
1229
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1230
+
1231
+    // fermer les tags img pas bien fermes;
1232
+    $tag = str_replace('>', '/>', str_replace('/>', '>', (string) $valeurs['tag']));
1233
+
1234
+    // le style
1235
+    $style = $valeurs['style'];
1236
+    if (isset($surcharge['style'])) {
1237
+        $style = $surcharge['style'];
1238
+        unset($surcharge['style']);
1239
+    }
1240
+
1241
+    // traiter specifiquement la largeur et la hauteur
1242
+    $width = $valeurs['largeur'];
1243
+    if (isset($surcharge['width'])) {
1244
+        $width = $surcharge['width'];
1245
+        unset($surcharge['width']);
1246
+    }
1247
+    $height = $valeurs['hauteur'];
1248
+    if (isset($surcharge['height'])) {
1249
+        $height = $surcharge['height'];
1250
+        unset($surcharge['height']);
1251
+    }
1252
+
1253
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1254
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1255
+    // on remplace toute les ref a src dans le tag
1256
+    $src = extraire_attribut($tag, 'src');
1257
+    if (isset($surcharge['src'])) {
1258
+        $tag = str_replace($src, $surcharge['src'], $tag);
1259
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1260
+        // pas garanti comme methode, mais mieux que rien
1261
+        if (str_contains($src, '&')) {
1262
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1263
+        }
1264
+        $src = $surcharge['src'];
1265
+        unset($surcharge['src']);
1266
+    }
1267
+
1268
+    $class = $valeurs['class'];
1269
+    if (isset($surcharge['class'])) {
1270
+        $class = $surcharge['class'];
1271
+        unset($surcharge['class']);
1272
+    }
1273
+    if (is_scalar($class) && strlen($class)) {
1274
+        $tag = inserer_attribut($tag, 'class', $class);
1275
+    }
1276
+
1277
+    if ($surcharge !== []) {
1278
+        foreach ($surcharge as $attribut => $valeur) {
1279
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1280
+        }
1281
+    }
1282
+
1283
+    return pipeline(
1284
+        'image_ecrire_tag_finir',
1285
+        [
1286
+            'args' => [
1287
+                'valeurs' => $valeurs,
1288
+                'surcharge' => $surcharge,
1289
+            ],
1290
+            'data' => $tag
1291
+        ]
1292
+    );
1293 1293
 }
1294 1294
 
1295 1295
 /**
@@ -1312,268 +1312,268 @@  discard block
 block discarded – undo
1312 1312
  *     Description de l'image, sinon null.
1313 1313
  **/
1314 1314
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1315
-	$srcHeight = null;
1316
-	$retour = [];
1317
-	// ordre de preference des formats graphiques pour creer les vignettes
1318
-	// le premier format disponible, selon la methode demandee, est utilise
1319
-	$image = $valeurs['fichier'];
1320
-	$format = $valeurs['format_source'];
1321
-	$destdir = dirname((string) $valeurs['fichier_dest']);
1322
-	$destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1323
-
1324
-	$format_sortie = $valeurs['format_dest'];
1325
-
1326
-	if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1327
-		$process = $GLOBALS['meta']['image_process'];
1328
-	}
1329
-
1330
-	// si le doc n'est pas une image dans un format accetpable, refuser
1331
-	if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) {
1332
-		return;
1333
-	}
1334
-	$destination = "$destdir/$destfile";
1335
-
1336
-	// calculer la taille
1337
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1338
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1339
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1340
-		}
1341
-	} elseif ($process == 'convert' || $process == 'imagick') {
1342
-		$destWidth = $maxWidth;
1343
-		$destHeight = $maxHeight;
1344
-	} else {
1345
-		spip_logger('images')->info("echec $process sur $image");
1346
-
1347
-		return;
1348
-	}
1349
-
1350
-	$vignette = '';
1351
-
1352
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1353
-	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1354
-		$vignette = $destination . '.' . $format;
1355
-		@copy($image, $vignette);
1356
-	}
1357
-
1358
-	elseif ($valeurs['format_source'] === 'svg') {
1359
-		include_spip('inc/svg');
1360
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1361
-			$format_sortie = 'svg';
1362
-			$vignette = $destination . '.' . $format_sortie;
1363
-			$valeurs['fichier_dest'] = $vignette;
1364
-			_image_gd_output($svg, $valeurs);
1365
-		}
1366
-	}
1367
-
1368
-	// imagemagick en ligne de commande
1369
-	elseif ($process == 'convert') {
1370
-		if (!defined('_CONVERT_COMMAND')) {
1371
-			define('_CONVERT_COMMAND', 'convert');
1372
-		} // Securite : mes_options.php peut preciser le chemin absolu
1373
-		if (!defined('_RESIZE_COMMAND')) {
1374
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1375
-		}
1376
-		$vignette = $destination . '.' . $format_sortie;
1377
-		$commande = str_replace(
1378
-			['%x', '%y', '%src', '%dest'],
1379
-			[
1380
-				$destWidth,
1381
-				$destHeight,
1382
-				escapeshellcmd($image),
1383
-				escapeshellcmd($vignette)
1384
-			],
1385
-			(string) _RESIZE_COMMAND
1386
-		);
1387
-		spip_logger('images')->info($commande);
1388
-		exec($commande);
1389
-		if (!@file_exists($vignette)) {
1390
-			spip_logger('images')->info("echec convert sur $vignette");
1391
-
1392
-			return;  // echec commande
1393
-		}
1394
-	}
1395
-
1396
-	// php5 imagemagick
1397
-	elseif ($process == 'imagick') {
1398
-		if (!class_exists(\Imagick::class)) {
1399
-			spip_logger('images')->error('Classe Imagick absente !');
1400
-
1401
-			return;
1402
-		}
1403
-
1404
-		// chemin compatible Windows
1405
-		$output = realpath(dirname($destination));
1406
-		if (!$output) {
1407
-			return;
1408
-		}
1409
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1410
-
1411
-		$imagick = new Imagick();
1412
-		$imagick->readImage(realpath($image));
1413
-		$imagick->resizeImage(
1414
-			$destWidth,
1415
-			$destHeight,
1416
-			Imagick::FILTER_LANCZOS,
1417
-			1
1418
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1419
-		$imagick->writeImage($vignette);
1420
-
1421
-		if (!@file_exists($vignette)) {
1422
-			spip_logger('images')->info("echec imagick sur $vignette");
1423
-
1424
-			return;
1425
-		}
1426
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1427
-		$vignette = $destination . '.' . $format_sortie;
1428
-	}
1429
-
1430
-	// netpbm
1431
-	elseif ($process == 'netpbm') {
1432
-		if (!defined('_PNMSCALE_COMMAND')) {
1433
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1434
-		} // Securite : mes_options.php peut preciser le chemin absolu
1435
-		if (_PNMSCALE_COMMAND == '') {
1436
-			return;
1437
-		}
1438
-		$vignette = $destination . '.' . $format_sortie;
1439
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND);
1440
-		if ($format == 'jpg') {
1441
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND);
1442
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1443
-			if (!($s = @filesize($vignette))) {
1444
-				spip_unlink($vignette);
1445
-			}
1446
-			if (!@file_exists($vignette)) {
1447
-				spip_logger('images')->info("echec netpbm-jpg sur $vignette");
1448
-
1449
-				return;
1450
-			}
1451
-		} else {
1452
-			if ($format == 'gif') {
1453
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND);
1454
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1455
-				if (!($s = @filesize($vignette))) {
1456
-					spip_unlink($vignette);
1457
-				}
1458
-				if (!@file_exists($vignette)) {
1459
-					spip_logger('images')->info("echec netpbm-gif sur $vignette");
1460
-
1461
-					return;
1462
-				}
1463
-			} else {
1464
-				if ($format == 'png') {
1465
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND);
1466
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1467
-					if (!($s = @filesize($vignette))) {
1468
-						spip_unlink($vignette);
1469
-					}
1470
-					if (!@file_exists($vignette)) {
1471
-						spip_logger('images')->info("echec netpbm-png sur $vignette");
1472
-
1473
-						return;
1474
-					}
1475
-				}
1476
-			}
1477
-		}
1478
-	}
1479
-
1480
-	// gd ou gd2
1481
-	elseif ($process === 'gd2') {
1482
-		if (!function_exists('gd_info')) {
1483
-			spip_logger('images')->error('Librairie GD absente !');
1484
-
1485
-			return;
1486
-		}
1487
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1488
-			spip_logger('images')->info('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1489
-
1490
-			return;
1491
-		}
1492
-		$destFormat = $format_sortie;
1493
-		if (!$destFormat) {
1494
-			spip_logger('images')->info("pas de format pour $image");
1495
-
1496
-			return;
1497
-		}
1498
-
1499
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1500
-		if (!function_exists($fonction_imagecreatefrom)) {
1501
-			return;
1502
-		}
1503
-		$srcImage = @$fonction_imagecreatefrom($image);
1504
-		if (!$srcImage) {
1505
-			spip_logger('images')->info('echec gd2');
1506
-
1507
-			return;
1508
-		}
1509
-
1510
-		// Initialisation de l'image destination
1511
-		$destImage = null;
1512
-		if ($process == 'gd2' && $destFormat != 'gif') {
1513
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1514
-		}
1515
-		if (!$destImage) {
1516
-			$destImage = ImageCreate($destWidth, $destHeight);
1517
-		}
1518
-
1519
-		// Recopie de l'image d'origine avec adaptation de la taille
1520
-		$ok = false;
1521
-		if ($process == 'gd2' && function_exists('ImageCopyResampled')) {
1522
-			if ($format == 'gif') {
1523
-				// Si un GIF est transparent,
1524
-				// fabriquer un PNG transparent
1525
-				$transp = imagecolortransparent($srcImage);
1526
-				if ($transp > 0) {
1527
-					$destFormat = 'png';
1528
-				}
1529
-			}
1530
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1531
-				// Conserver la transparence
1532
-				if (function_exists('imageAntiAlias')) {
1533
-					imageAntiAlias($destImage, true);
1534
-				}
1535
-				@imagealphablending($destImage, false);
1536
-				@imagesavealpha($destImage, true);
1537
-			}
1538
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1539
-		}
1540
-		if (!$ok) {
1541
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1542
-		}
1543
-
1544
-		// Sauvegarde de l'image destination
1545
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1546
-		$valeurs['format_dest'] = $format = $destFormat;
1547
-		_image_gd_output($destImage, $valeurs);
1548
-
1549
-		if ($srcImage) {
1550
-			ImageDestroy($srcImage);
1551
-		}
1552
-		ImageDestroy($destImage);
1553
-	}
1554
-
1555
-	if (!$vignette || !$size = @spip_getimagesize($vignette)) {
1556
-		$size = [$destWidth, $destHeight];
1557
-	}
1558
-
1559
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1560
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1561
-	if ($size[0] < 1) {
1562
-		$size[0] = $destWidth;
1563
-	}
1564
-	if ($size[1] < 1) {
1565
-		$size[1] = $destHeight;
1566
-	}
1567
-
1568
-	$retour['width'] = $largeur = $size[0];
1569
-	$retour['height'] = $hauteur = $size[1];
1570
-
1571
-	$retour['fichier'] = $vignette;
1572
-	$retour['format'] = $format;
1573
-	$retour['date'] = @filemtime($vignette);
1574
-
1575
-	// renvoyer l'image
1576
-	return $retour;
1315
+    $srcHeight = null;
1316
+    $retour = [];
1317
+    // ordre de preference des formats graphiques pour creer les vignettes
1318
+    // le premier format disponible, selon la methode demandee, est utilise
1319
+    $image = $valeurs['fichier'];
1320
+    $format = $valeurs['format_source'];
1321
+    $destdir = dirname((string) $valeurs['fichier_dest']);
1322
+    $destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1323
+
1324
+    $format_sortie = $valeurs['format_dest'];
1325
+
1326
+    if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1327
+        $process = $GLOBALS['meta']['image_process'];
1328
+    }
1329
+
1330
+    // si le doc n'est pas une image dans un format accetpable, refuser
1331
+    if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) {
1332
+        return;
1333
+    }
1334
+    $destination = "$destdir/$destfile";
1335
+
1336
+    // calculer la taille
1337
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1338
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1339
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1340
+        }
1341
+    } elseif ($process == 'convert' || $process == 'imagick') {
1342
+        $destWidth = $maxWidth;
1343
+        $destHeight = $maxHeight;
1344
+    } else {
1345
+        spip_logger('images')->info("echec $process sur $image");
1346
+
1347
+        return;
1348
+    }
1349
+
1350
+    $vignette = '';
1351
+
1352
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1353
+    if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1354
+        $vignette = $destination . '.' . $format;
1355
+        @copy($image, $vignette);
1356
+    }
1357
+
1358
+    elseif ($valeurs['format_source'] === 'svg') {
1359
+        include_spip('inc/svg');
1360
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1361
+            $format_sortie = 'svg';
1362
+            $vignette = $destination . '.' . $format_sortie;
1363
+            $valeurs['fichier_dest'] = $vignette;
1364
+            _image_gd_output($svg, $valeurs);
1365
+        }
1366
+    }
1367
+
1368
+    // imagemagick en ligne de commande
1369
+    elseif ($process == 'convert') {
1370
+        if (!defined('_CONVERT_COMMAND')) {
1371
+            define('_CONVERT_COMMAND', 'convert');
1372
+        } // Securite : mes_options.php peut preciser le chemin absolu
1373
+        if (!defined('_RESIZE_COMMAND')) {
1374
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1375
+        }
1376
+        $vignette = $destination . '.' . $format_sortie;
1377
+        $commande = str_replace(
1378
+            ['%x', '%y', '%src', '%dest'],
1379
+            [
1380
+                $destWidth,
1381
+                $destHeight,
1382
+                escapeshellcmd($image),
1383
+                escapeshellcmd($vignette)
1384
+            ],
1385
+            (string) _RESIZE_COMMAND
1386
+        );
1387
+        spip_logger('images')->info($commande);
1388
+        exec($commande);
1389
+        if (!@file_exists($vignette)) {
1390
+            spip_logger('images')->info("echec convert sur $vignette");
1391
+
1392
+            return;  // echec commande
1393
+        }
1394
+    }
1395
+
1396
+    // php5 imagemagick
1397
+    elseif ($process == 'imagick') {
1398
+        if (!class_exists(\Imagick::class)) {
1399
+            spip_logger('images')->error('Classe Imagick absente !');
1400
+
1401
+            return;
1402
+        }
1403
+
1404
+        // chemin compatible Windows
1405
+        $output = realpath(dirname($destination));
1406
+        if (!$output) {
1407
+            return;
1408
+        }
1409
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1410
+
1411
+        $imagick = new Imagick();
1412
+        $imagick->readImage(realpath($image));
1413
+        $imagick->resizeImage(
1414
+            $destWidth,
1415
+            $destHeight,
1416
+            Imagick::FILTER_LANCZOS,
1417
+            1
1418
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1419
+        $imagick->writeImage($vignette);
1420
+
1421
+        if (!@file_exists($vignette)) {
1422
+            spip_logger('images')->info("echec imagick sur $vignette");
1423
+
1424
+            return;
1425
+        }
1426
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1427
+        $vignette = $destination . '.' . $format_sortie;
1428
+    }
1429
+
1430
+    // netpbm
1431
+    elseif ($process == 'netpbm') {
1432
+        if (!defined('_PNMSCALE_COMMAND')) {
1433
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1434
+        } // Securite : mes_options.php peut preciser le chemin absolu
1435
+        if (_PNMSCALE_COMMAND == '') {
1436
+            return;
1437
+        }
1438
+        $vignette = $destination . '.' . $format_sortie;
1439
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND);
1440
+        if ($format == 'jpg') {
1441
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND);
1442
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1443
+            if (!($s = @filesize($vignette))) {
1444
+                spip_unlink($vignette);
1445
+            }
1446
+            if (!@file_exists($vignette)) {
1447
+                spip_logger('images')->info("echec netpbm-jpg sur $vignette");
1448
+
1449
+                return;
1450
+            }
1451
+        } else {
1452
+            if ($format == 'gif') {
1453
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND);
1454
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1455
+                if (!($s = @filesize($vignette))) {
1456
+                    spip_unlink($vignette);
1457
+                }
1458
+                if (!@file_exists($vignette)) {
1459
+                    spip_logger('images')->info("echec netpbm-gif sur $vignette");
1460
+
1461
+                    return;
1462
+                }
1463
+            } else {
1464
+                if ($format == 'png') {
1465
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND);
1466
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1467
+                    if (!($s = @filesize($vignette))) {
1468
+                        spip_unlink($vignette);
1469
+                    }
1470
+                    if (!@file_exists($vignette)) {
1471
+                        spip_logger('images')->info("echec netpbm-png sur $vignette");
1472
+
1473
+                        return;
1474
+                    }
1475
+                }
1476
+            }
1477
+        }
1478
+    }
1479
+
1480
+    // gd ou gd2
1481
+    elseif ($process === 'gd2') {
1482
+        if (!function_exists('gd_info')) {
1483
+            spip_logger('images')->error('Librairie GD absente !');
1484
+
1485
+            return;
1486
+        }
1487
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1488
+            spip_logger('images')->info('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1489
+
1490
+            return;
1491
+        }
1492
+        $destFormat = $format_sortie;
1493
+        if (!$destFormat) {
1494
+            spip_logger('images')->info("pas de format pour $image");
1495
+
1496
+            return;
1497
+        }
1498
+
1499
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1500
+        if (!function_exists($fonction_imagecreatefrom)) {
1501
+            return;
1502
+        }
1503
+        $srcImage = @$fonction_imagecreatefrom($image);
1504
+        if (!$srcImage) {
1505
+            spip_logger('images')->info('echec gd2');
1506
+
1507
+            return;
1508
+        }
1509
+
1510
+        // Initialisation de l'image destination
1511
+        $destImage = null;
1512
+        if ($process == 'gd2' && $destFormat != 'gif') {
1513
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1514
+        }
1515
+        if (!$destImage) {
1516
+            $destImage = ImageCreate($destWidth, $destHeight);
1517
+        }
1518
+
1519
+        // Recopie de l'image d'origine avec adaptation de la taille
1520
+        $ok = false;
1521
+        if ($process == 'gd2' && function_exists('ImageCopyResampled')) {
1522
+            if ($format == 'gif') {
1523
+                // Si un GIF est transparent,
1524
+                // fabriquer un PNG transparent
1525
+                $transp = imagecolortransparent($srcImage);
1526
+                if ($transp > 0) {
1527
+                    $destFormat = 'png';
1528
+                }
1529
+            }
1530
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1531
+                // Conserver la transparence
1532
+                if (function_exists('imageAntiAlias')) {
1533
+                    imageAntiAlias($destImage, true);
1534
+                }
1535
+                @imagealphablending($destImage, false);
1536
+                @imagesavealpha($destImage, true);
1537
+            }
1538
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1539
+        }
1540
+        if (!$ok) {
1541
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1542
+        }
1543
+
1544
+        // Sauvegarde de l'image destination
1545
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1546
+        $valeurs['format_dest'] = $format = $destFormat;
1547
+        _image_gd_output($destImage, $valeurs);
1548
+
1549
+        if ($srcImage) {
1550
+            ImageDestroy($srcImage);
1551
+        }
1552
+        ImageDestroy($destImage);
1553
+    }
1554
+
1555
+    if (!$vignette || !$size = @spip_getimagesize($vignette)) {
1556
+        $size = [$destWidth, $destHeight];
1557
+    }
1558
+
1559
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1560
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1561
+    if ($size[0] < 1) {
1562
+        $size[0] = $destWidth;
1563
+    }
1564
+    if ($size[1] < 1) {
1565
+        $size[1] = $destHeight;
1566
+    }
1567
+
1568
+    $retour['width'] = $largeur = $size[0];
1569
+    $retour['height'] = $hauteur = $size[1];
1570
+
1571
+    $retour['fichier'] = $vignette;
1572
+    $retour['format'] = $format;
1573
+    $retour['date'] = @filemtime($vignette);
1574
+
1575
+    // renvoyer l'image
1576
+    return $retour;
1577 1577
 }
1578 1578
 
1579 1579
 /**
@@ -1593,25 +1593,25 @@  discard block
 block discarded – undo
1593 1593
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1594 1594
  **/
1595 1595
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1596
-	$ratioWidth = $srcWidth / $maxWidth;
1597
-	$ratioHeight = $srcHeight / $maxHeight;
1598
-
1599
-	if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1600
-		$destWidth = $srcWidth;
1601
-		$destHeight = $srcHeight;
1602
-	} elseif ($ratioWidth < $ratioHeight) {
1603
-		$destWidth = $srcWidth / $ratioHeight;
1604
-		$destHeight = $maxHeight;
1605
-	} else {
1606
-		$destWidth = $maxWidth;
1607
-		$destHeight = $srcHeight / $ratioWidth;
1608
-	}
1609
-
1610
-	return [
1611
-		(int) round($destWidth),
1612
-		(int) round($destHeight),
1613
-		max($ratioWidth, $ratioHeight)
1614
-	];
1596
+    $ratioWidth = $srcWidth / $maxWidth;
1597
+    $ratioHeight = $srcHeight / $maxHeight;
1598
+
1599
+    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1600
+        $destWidth = $srcWidth;
1601
+        $destHeight = $srcHeight;
1602
+    } elseif ($ratioWidth < $ratioHeight) {
1603
+        $destWidth = $srcWidth / $ratioHeight;
1604
+        $destHeight = $maxHeight;
1605
+    } else {
1606
+        $destWidth = $maxWidth;
1607
+        $destHeight = $srcHeight / $ratioWidth;
1608
+    }
1609
+
1610
+    return [
1611
+        (int) round($destWidth),
1612
+        (int) round($destHeight),
1613
+        max($ratioWidth, $ratioHeight)
1614
+    ];
1615 1615
 }
1616 1616
 
1617 1617
 /**
@@ -1631,25 +1631,25 @@  discard block
 block discarded – undo
1631 1631
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1632 1632
  **/
1633 1633
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1634
-	$ratioWidth = $srcWidth / $maxWidth;
1635
-	$ratioHeight = $srcHeight / $maxHeight;
1636
-
1637
-	if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1638
-		$destWidth = $srcWidth;
1639
-		$destHeight = $srcHeight;
1640
-	} elseif ($ratioWidth > $ratioHeight) {
1641
-		$destWidth = $srcWidth / $ratioHeight;
1642
-		$destHeight = $maxHeight;
1643
-	} else {
1644
-		$destWidth = $maxWidth;
1645
-		$destHeight = $srcHeight / $ratioWidth;
1646
-	}
1647
-
1648
-	return [
1649
-		(int) round($destWidth),
1650
-		(int) round($destHeight),
1651
-		min($ratioWidth, $ratioHeight)
1652
-	];
1634
+    $ratioWidth = $srcWidth / $maxWidth;
1635
+    $ratioHeight = $srcHeight / $maxHeight;
1636
+
1637
+    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1638
+        $destWidth = $srcWidth;
1639
+        $destHeight = $srcHeight;
1640
+    } elseif ($ratioWidth > $ratioHeight) {
1641
+        $destWidth = $srcWidth / $ratioHeight;
1642
+        $destHeight = $maxHeight;
1643
+    } else {
1644
+        $destWidth = $maxWidth;
1645
+        $destHeight = $srcHeight / $ratioWidth;
1646
+    }
1647
+
1648
+    return [
1649
+        (int) round($destWidth),
1650
+        (int) round($destHeight),
1651
+        min($ratioWidth, $ratioHeight)
1652
+    ];
1653 1653
 }
1654 1654
 
1655 1655
 
@@ -1662,12 +1662,12 @@  discard block
 block discarded – undo
1662 1662
  * @return string
1663 1663
  */
1664 1664
 function process_image_svg_identite($image) {
1665
-	if ($image['creer']) {
1666
-		$source = $image['fichier'];
1667
-		_image_gd_output($source, $image);
1668
-	}
1665
+    if ($image['creer']) {
1666
+        $source = $image['fichier'];
1667
+        _image_gd_output($source, $image);
1668
+    }
1669 1669
 
1670
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1670
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1671 1671
 }
1672 1672
 
1673 1673
 
@@ -1700,102 +1700,102 @@  discard block
 block discarded – undo
1700 1700
  *     Code HTML de la balise img produite
1701 1701
  **/
1702 1702
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1703
-	$image = false;
1704
-	if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1705
-		$process = $GLOBALS['meta']['image_process'];
1706
-	}
1707
-	# determiner le format de sortie
1708
-	$format_sortie = false; // le choix par defaut sera bon
1709
-	if ($process === 'netpbm') {
1710
-		$format_sortie = 'jpg';
1711
-	} elseif ($process === 'gd2') {
1712
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1713
-		// on verifie que l'extension choisie est bonne (en principe oui)
1714
-		$gd_formats = formats_image_acceptables(true);
1715
-		if (
1716
-			is_array($image)
1717
-			&& (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1718
-		) {
1719
-			$formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif'];
1720
-			// Choisir le format destination
1721
-			// - on sauve de preference en JPEG (meilleure compression)
1722
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1723
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1724
-			# pas *ecrire*
1725
-			$format_sortie = '';
1726
-			foreach ($formats_sortie as $fmt) {
1727
-				if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1728
-					$format_sortie = $fmt;
1729
-					break;
1730
-				}
1731
-			}
1732
-			$image = false;
1733
-		}
1734
-	}
1735
-
1736
-	if (!is_array($image)) {
1737
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1738
-	}
1739
-
1740
-	if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) {
1741
-		spip_logger('images')->info("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1742
-		// on peut resizer en mode html si on dispose des elements
1743
-		[$srcw, $srch] = taille_image($img);
1744
-		if ($srcw && $srch) {
1745
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1746
-
1747
-			return _image_tag_changer_taille($img, $w, $h);
1748
-		}
1749
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1750
-		// sous la forme style='max-width: NNpx;'
1751
-		return inserer_attribut(
1752
-			$img,
1753
-			'style',
1754
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1755
-		);
1756
-	}
1757
-
1758
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1759
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1760
-		if ($image['creer']) {
1761
-			@copy($image['fichier'], $image['fichier_dest']);
1762
-		}
1763
-
1764
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1765
-	}
1766
-
1767
-	if ($image['creer'] == false && !$force) {
1768
-		return _image_ecrire_tag(
1769
-			$image,
1770
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1771
-		);
1772
-	}
1773
-
1774
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1775
-		$destWidth = $image['largeur_dest'];
1776
-		$destHeight = $image['hauteur_dest'];
1777
-		$logo = $image['fichier'];
1778
-		$date = $image['date_src'];
1779
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1780
-
1781
-		if ($preview && $preview['fichier']) {
1782
-			$logo = $preview['fichier'];
1783
-			$destWidth = $preview['width'];
1784
-			$destHeight = $preview['height'];
1785
-			$date = $preview['date'];
1786
-		}
1787
-		// dans l'espace prive mettre un timestamp sur l'adresse
1788
-		// de l'image, de facon a tromper le cache du navigateur
1789
-		// quand on fait supprimer/reuploader un logo
1790
-		// (pas de filemtime si SAFE MODE)
1791
-		$date = test_espace_prive() ? ('?' . $date) : '';
1792
-
1793
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1794
-	}
1795
-	else {
1796
-		# BMP, tiff ... les redacteurs osent tout!
1797
-		return $img;
1798
-	}
1703
+    $image = false;
1704
+    if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1705
+        $process = $GLOBALS['meta']['image_process'];
1706
+    }
1707
+    # determiner le format de sortie
1708
+    $format_sortie = false; // le choix par defaut sera bon
1709
+    if ($process === 'netpbm') {
1710
+        $format_sortie = 'jpg';
1711
+    } elseif ($process === 'gd2') {
1712
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1713
+        // on verifie que l'extension choisie est bonne (en principe oui)
1714
+        $gd_formats = formats_image_acceptables(true);
1715
+        if (
1716
+            is_array($image)
1717
+            && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1718
+        ) {
1719
+            $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif'];
1720
+            // Choisir le format destination
1721
+            // - on sauve de preference en JPEG (meilleure compression)
1722
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1723
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1724
+            # pas *ecrire*
1725
+            $format_sortie = '';
1726
+            foreach ($formats_sortie as $fmt) {
1727
+                if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1728
+                    $format_sortie = $fmt;
1729
+                    break;
1730
+                }
1731
+            }
1732
+            $image = false;
1733
+        }
1734
+    }
1735
+
1736
+    if (!is_array($image)) {
1737
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1738
+    }
1739
+
1740
+    if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) {
1741
+        spip_logger('images')->info("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1742
+        // on peut resizer en mode html si on dispose des elements
1743
+        [$srcw, $srch] = taille_image($img);
1744
+        if ($srcw && $srch) {
1745
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1746
+
1747
+            return _image_tag_changer_taille($img, $w, $h);
1748
+        }
1749
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1750
+        // sous la forme style='max-width: NNpx;'
1751
+        return inserer_attribut(
1752
+            $img,
1753
+            'style',
1754
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1755
+        );
1756
+    }
1757
+
1758
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1759
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1760
+        if ($image['creer']) {
1761
+            @copy($image['fichier'], $image['fichier_dest']);
1762
+        }
1763
+
1764
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1765
+    }
1766
+
1767
+    if ($image['creer'] == false && !$force) {
1768
+        return _image_ecrire_tag(
1769
+            $image,
1770
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1771
+        );
1772
+    }
1773
+
1774
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1775
+        $destWidth = $image['largeur_dest'];
1776
+        $destHeight = $image['hauteur_dest'];
1777
+        $logo = $image['fichier'];
1778
+        $date = $image['date_src'];
1779
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1780
+
1781
+        if ($preview && $preview['fichier']) {
1782
+            $logo = $preview['fichier'];
1783
+            $destWidth = $preview['width'];
1784
+            $destHeight = $preview['height'];
1785
+            $date = $preview['date'];
1786
+        }
1787
+        // dans l'espace prive mettre un timestamp sur l'adresse
1788
+        // de l'image, de facon a tromper le cache du navigateur
1789
+        // quand on fait supprimer/reuploader un logo
1790
+        // (pas de filemtime si SAFE MODE)
1791
+        $date = test_espace_prive() ? ('?' . $date) : '';
1792
+
1793
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1794
+    }
1795
+    else {
1796
+        # BMP, tiff ... les redacteurs osent tout!
1797
+        return $img;
1798
+    }
1799 1799
 }
1800 1800
 
1801 1801
 /**
@@ -1809,145 +1809,145 @@  discard block
 block discarded – undo
1809 1809
  * Class phpthumb_functions
1810 1810
  */
1811 1811
 class phpthumb_functions {
1812
-	/**
1813
-	 * Retourne la couleur d'un pixel dans une image
1814
-	 *
1815
-	 * @param GdImage $img
1816
-	 * @param int $x
1817
-	 * @param int $y
1818
-	 * @return array|bool
1819
-	 */
1820
-	public static function GetPixelColor(&$img, $x, $y) {
1821
-		if ($img instanceof \GdImage) {
1822
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1823
-		}
1824
-		return false;
1825
-	}
1826
-
1827
-	/**
1828
-	 * Retourne un nombre dans une représentation en Little Endian
1829
-	 *
1830
-	 * @param int $number
1831
-	 * @param int $minbytes
1832
-	 * @return string
1833
-	 */
1834
-	public static function LittleEndian2String($number, $minbytes = 1) {
1835
-		$intstring = '';
1836
-		while ($number > 0) {
1837
-			$intstring .= chr($number & 255);
1838
-			$number >>= 8;
1839
-		}
1840
-
1841
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1842
-	}
1843
-
1844
-	/**
1845
-	 * Transforme une ressource GD en image au format ICO
1846
-	 *
1847
-	 * @param array $gd_image_array
1848
-	 *     Tableau de ressources d'images GD
1849
-	 * @return string
1850
-	 *     Image au format ICO
1851
-	 */
1852
-	public static function GD2ICOstring(&$gd_image_array) {
1853
-		foreach ($gd_image_array as $key => $gd_image) {
1854
-			$ImageWidths[$key] = ImageSX($gd_image);
1855
-			$ImageHeights[$key] = ImageSY($gd_image);
1856
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1857
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1858
-
1859
-			$icXOR[$key] = '';
1860
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1861
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1862
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1863
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1864
-					$r = $argb['red'];
1865
-					$g = $argb['green'];
1866
-					$b = $argb['blue'];
1867
-
1868
-					if ($bpp[$key] == 32) {
1869
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1870
-					} elseif ($bpp[$key] === 24) {
1871
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1872
-					}
1873
-
1874
-					if ($a < 128) {
1875
-						@$icANDmask[$key][$y] .= '1';
1876
-					} else {
1877
-						@$icANDmask[$key][$y] .= '0';
1878
-					}
1879
-				}
1880
-				// mask bits are 32-bit aligned per scanline
1881
-				while (strlen($icANDmask[$key][$y]) % 32) {
1882
-					$icANDmask[$key][$y] .= '0';
1883
-				}
1884
-			}
1885
-			$icAND[$key] = '';
1886
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1887
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1888
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1889
-				}
1890
-			}
1891
-		}
1892
-
1893
-		foreach (array_keys($gd_image_array) as $key) {
1894
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1895
-
1896
-			// BITMAPINFOHEADER - 40 bytes
1897
-			$BitmapInfoHeader[$key] = '';
1898
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1899
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1900
-			// The biHeight member specifies the combined
1901
-			// height of the XOR and AND masks.
1902
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1903
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1904
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1905
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1906
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1907
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1908
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1909
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1910
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1911
-		}
1912
-
1913
-
1914
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1915
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1916
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1917
-
1918
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1919
-		foreach (array_keys($gd_image_array) as $key) {
1920
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1921
-
1922
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1923
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1924
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1925
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1926
-
1927
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1928
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1929
-
1930
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1931
-			$icondata .= phpthumb_functions::LittleEndian2String(
1932
-				$dwBytesInRes,
1933
-				4
1934
-			);     // dwBytesInRes;	// How many bytes in this resource?
1935
-
1936
-			$icondata .= phpthumb_functions::LittleEndian2String(
1937
-				$dwImageOffset,
1938
-				4
1939
-			);    // dwImageOffset;   // Where in the file is this image?
1940
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1941
-			$dwImageOffset += strlen($icXOR[$key]);
1942
-			$dwImageOffset += strlen($icAND[$key]);
1943
-		}
1944
-
1945
-		foreach (array_keys($gd_image_array) as $key) {
1946
-			$icondata .= $BitmapInfoHeader[$key];
1947
-			$icondata .= $icXOR[$key];
1948
-			$icondata .= $icAND[$key];
1949
-		}
1950
-
1951
-		return $icondata;
1952
-	}
1812
+    /**
1813
+     * Retourne la couleur d'un pixel dans une image
1814
+     *
1815
+     * @param GdImage $img
1816
+     * @param int $x
1817
+     * @param int $y
1818
+     * @return array|bool
1819
+     */
1820
+    public static function GetPixelColor(&$img, $x, $y) {
1821
+        if ($img instanceof \GdImage) {
1822
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1823
+        }
1824
+        return false;
1825
+    }
1826
+
1827
+    /**
1828
+     * Retourne un nombre dans une représentation en Little Endian
1829
+     *
1830
+     * @param int $number
1831
+     * @param int $minbytes
1832
+     * @return string
1833
+     */
1834
+    public static function LittleEndian2String($number, $minbytes = 1) {
1835
+        $intstring = '';
1836
+        while ($number > 0) {
1837
+            $intstring .= chr($number & 255);
1838
+            $number >>= 8;
1839
+        }
1840
+
1841
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1842
+    }
1843
+
1844
+    /**
1845
+     * Transforme une ressource GD en image au format ICO
1846
+     *
1847
+     * @param array $gd_image_array
1848
+     *     Tableau de ressources d'images GD
1849
+     * @return string
1850
+     *     Image au format ICO
1851
+     */
1852
+    public static function GD2ICOstring(&$gd_image_array) {
1853
+        foreach ($gd_image_array as $key => $gd_image) {
1854
+            $ImageWidths[$key] = ImageSX($gd_image);
1855
+            $ImageHeights[$key] = ImageSY($gd_image);
1856
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1857
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1858
+
1859
+            $icXOR[$key] = '';
1860
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1861
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1862
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1863
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1864
+                    $r = $argb['red'];
1865
+                    $g = $argb['green'];
1866
+                    $b = $argb['blue'];
1867
+
1868
+                    if ($bpp[$key] == 32) {
1869
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1870
+                    } elseif ($bpp[$key] === 24) {
1871
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1872
+                    }
1873
+
1874
+                    if ($a < 128) {
1875
+                        @$icANDmask[$key][$y] .= '1';
1876
+                    } else {
1877
+                        @$icANDmask[$key][$y] .= '0';
1878
+                    }
1879
+                }
1880
+                // mask bits are 32-bit aligned per scanline
1881
+                while (strlen($icANDmask[$key][$y]) % 32) {
1882
+                    $icANDmask[$key][$y] .= '0';
1883
+                }
1884
+            }
1885
+            $icAND[$key] = '';
1886
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1887
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1888
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1889
+                }
1890
+            }
1891
+        }
1892
+
1893
+        foreach (array_keys($gd_image_array) as $key) {
1894
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1895
+
1896
+            // BITMAPINFOHEADER - 40 bytes
1897
+            $BitmapInfoHeader[$key] = '';
1898
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1899
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1900
+            // The biHeight member specifies the combined
1901
+            // height of the XOR and AND masks.
1902
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1903
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1904
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1905
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1906
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1907
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1908
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1909
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1910
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1911
+        }
1912
+
1913
+
1914
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1915
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1916
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1917
+
1918
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1919
+        foreach (array_keys($gd_image_array) as $key) {
1920
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1921
+
1922
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1923
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1924
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1925
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1926
+
1927
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1928
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1929
+
1930
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1931
+            $icondata .= phpthumb_functions::LittleEndian2String(
1932
+                $dwBytesInRes,
1933
+                4
1934
+            );     // dwBytesInRes;	// How many bytes in this resource?
1935
+
1936
+            $icondata .= phpthumb_functions::LittleEndian2String(
1937
+                $dwImageOffset,
1938
+                4
1939
+            );    // dwImageOffset;   // Where in the file is this image?
1940
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1941
+            $dwImageOffset += strlen($icXOR[$key]);
1942
+            $dwImageOffset += strlen($icAND[$key]);
1943
+        }
1944
+
1945
+        foreach (array_keys($gd_image_array) as $key) {
1946
+            $icondata .= $BitmapInfoHeader[$key];
1947
+            $icondata .= $icXOR[$key];
1948
+            $icondata .= $icAND[$key];
1949
+        }
1950
+
1951
+        return $icondata;
1952
+    }
1953 1953
 }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 	$blue = dechex($blue);
43 43
 
44 44
 	if (strlen($red) == 1) {
45
-		$red = '0' . $red;
45
+		$red = '0'.$red;
46 46
 	}
47 47
 	if (strlen($green) == 1) {
48
-		$green = '0' . $green;
48
+		$green = '0'.$green;
49 49
 	}
50 50
 	if (strlen($blue) == 1) {
51
-		$blue = '0' . $blue;
51
+		$blue = '0'.$blue;
52 52
 	}
53 53
 
54 54
 	return "$red$green$blue";
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	$couleur = couleur_html_to_hex($couleur);
68 68
 	$couleur = ltrim($couleur, '#');
69 69
 	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
70
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
71 71
 	}
72 72
 	$retour = [];
73 73
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	$var_G = ($G / 255);
126 126
 	$var_B = ($B / 255);
127 127
 
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
128
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
129
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
130
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
131 131
 
132 132
 	$L = ($var_Max + $var_Min) / 2;
133 133
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function _couleur_hsl_to_rgb($H, $S, $L) {
187 187
 	// helper
188
-	$hue_2_rgb = function ($v1, $v2, $vH) {
188
+	$hue_2_rgb = function($v1, $v2, $vH) {
189 189
 		if ($vH < 0) {
190 190
 			$vH += 1;
191 191
 		}
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
 		}
320 320
 	} elseif (
321 321
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
-		&& ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
322
+		&& ($extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]))
323 323
 		&& in_array($extension, _image_extensions_acceptees_en_entree())
324 324
 	) {
325 325
 		# gerer img src="data:....base64"
326
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
326
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
327 327
 		if (!file_exists($local)) {
328 328
 			ecrire_fichier($local, base64_decode($regs[2]));
329 329
 		}
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	// les protocoles web prennent au moins 3 lettres
341 341
 	if (tester_url_absolue($source)) {
342 342
 		include_spip('inc/distant');
343
-		$fichier = _DIR_RACINE . copie_locale($source);
343
+		$fichier = _DIR_RACINE.copie_locale($source);
344 344
 		if (!$fichier) {
345 345
 			return '';
346 346
 		}
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 			// on garde la terminaison initiale car image simplement copiee
443 443
 			// et on postfixe son nom avec un md5 du path
444 444
 			$terminaison_dest = $terminaison;
445
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
446 446
 		} else {
447
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
448 448
 		}
449 449
 		$cache = sous_repertoire(_DIR_VAR, $cache);
450 450
 		$cache = sous_repertoire($cache, $effet);
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 		$fichier_dest = substr($fichier_dest, 2);
456 456
 	}
457 457
 
458
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
459 459
 
460 460
 	$GLOBALS['images_calculees'][] = $fichier_dest;
461 461
 
@@ -491,14 +491,14 @@  discard block
 block discarded – undo
491 491
 
492 492
 	if ($creer) {
493 493
 		spip_logger('images')->error(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
494
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
495 495
 		);
496 496
 	}
497 497
 
498 498
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
499
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
499
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
500 500
 	$ret['fichier'] = $fichier;
501
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
501
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
502 502
 	$ret['fichier_dest'] = $fichier_dest;
503 503
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
504 504
 	$ret['format_dest'] = $terminaison_dest;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 	if (!function_exists('imagepng')) {
776 776
 		return false;
777 777
 	}
778
-	$tmp = $fichier . '.tmp';
778
+	$tmp = $fichier.'.tmp';
779 779
 	$ret = imagepng($img, $tmp);
780 780
 	if (file_exists($tmp)) {
781 781
 		$taille_test = @getimagesize($tmp);
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	if (!function_exists('imagegif')) {
811 811
 		return false;
812 812
 	}
813
-	$tmp = $fichier . '.tmp';
813
+	$tmp = $fichier.'.tmp';
814 814
 	$ret = imagegif($img, $tmp);
815 815
 	if (file_exists($tmp)) {
816 816
 		$taille_test = @getimagesize($tmp);
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 	if (!function_exists('imagejpeg')) {
851 851
 		return false;
852 852
 	}
853
-	$tmp = $fichier . '.tmp';
853
+	$tmp = $fichier.'.tmp';
854 854
 
855 855
 	// Enable interlancing
856 856
 	imageinterlace($img, true);
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
 	if (!function_exists('imagewebp')) {
912 912
 		return false;
913 913
 	}
914
-	$tmp = $fichier . '.tmp';
914
+	$tmp = $fichier.'.tmp';
915 915
 	$ret = imagewebp($img, $tmp, $qualite);
916 916
 	if (file_exists($tmp)) {
917 917
 		$taille_test = @getimagesize($tmp);
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
  */
946 946
 function _image_imagesvg($img, $fichier) {
947 947
 
948
-	$tmp = $fichier . '.tmp';
948
+	$tmp = $fichier.'.tmp';
949 949
 	if (!str_contains($img, '<')) {
950 950
 		$img = supprimer_timestamp($img);
951 951
 		if (!file_exists($img)) {
@@ -1002,14 +1002,14 @@  discard block
 block discarded – undo
1002 1002
  */
1003 1003
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1004 1004
 	if (is_null($fonction)) {
1005
-		$fonction = '_image_image' . $valeurs['format_dest'];
1005
+		$fonction = '_image_image'.$valeurs['format_dest'];
1006 1006
 	}
1007 1007
 	$ret = false;
1008 1008
 	#un flag pour reperer les images gravees
1009 1009
 	$lock = (
1010 1010
 		!statut_effacer_images_temporaires('get')
1011 1011
 		|| @file_exists($valeurs['fichier_dest'])
1012
-		&& !@file_exists($valeurs['fichier_dest'] . '.src')
1012
+		&& !@file_exists($valeurs['fichier_dest'].'.src')
1013 1013
 	);
1014 1014
 	if (
1015 1015
 		function_exists($fonction)
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 		[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1022 1022
 		$valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1023 1023
 		// pour la retrouver apres disparition
1024
-		ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1024
+		ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1025 1025
 	}
1026 1026
 
1027 1027
 	return $ret;
@@ -1196,7 +1196,7 @@  discard block
 block discarded – undo
1196 1196
 
1197 1197
 	// attributs deprecies. Transformer en CSS
1198 1198
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1199
-		$style = "margin:{$espace}px;" . $style;
1199
+		$style = "margin:{$espace}px;".$style;
1200 1200
 		$tag = inserer_attribut($tag, 'hspace', '');
1201 1201
 	}
1202 1202
 
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
 	$image = $valeurs['fichier'];
1320 1320
 	$format = $valeurs['format_source'];
1321 1321
 	$destdir = dirname((string) $valeurs['fichier_dest']);
1322
-	$destfile = basename((string) $valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1322
+	$destfile = basename((string) $valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1323 1323
 
1324 1324
 	$format_sortie = $valeurs['format_dest'];
1325 1325
 
@@ -1351,7 +1351,7 @@  discard block
 block discarded – undo
1351 1351
 
1352 1352
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1353 1353
 	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1354
-		$vignette = $destination . '.' . $format;
1354
+		$vignette = $destination.'.'.$format;
1355 1355
 		@copy($image, $vignette);
1356 1356
 	}
1357 1357
 
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
 		include_spip('inc/svg');
1360 1360
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1361 1361
 			$format_sortie = 'svg';
1362
-			$vignette = $destination . '.' . $format_sortie;
1362
+			$vignette = $destination.'.'.$format_sortie;
1363 1363
 			$valeurs['fichier_dest'] = $vignette;
1364 1364
 			_image_gd_output($svg, $valeurs);
1365 1365
 		}
@@ -1371,9 +1371,9 @@  discard block
 block discarded – undo
1371 1371
 			define('_CONVERT_COMMAND', 'convert');
1372 1372
 		} // Securite : mes_options.php peut preciser le chemin absolu
1373 1373
 		if (!defined('_RESIZE_COMMAND')) {
1374
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1374
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -orient Undefined -resize %xx%y! %src %dest');
1375 1375
 		}
1376
-		$vignette = $destination . '.' . $format_sortie;
1376
+		$vignette = $destination.'.'.$format_sortie;
1377 1377
 		$commande = str_replace(
1378 1378
 			['%x', '%y', '%src', '%dest'],
1379 1379
 			[
@@ -1389,7 +1389,7 @@  discard block
 block discarded – undo
1389 1389
 		if (!@file_exists($vignette)) {
1390 1390
 			spip_logger('images')->info("echec convert sur $vignette");
1391 1391
 
1392
-			return;  // echec commande
1392
+			return; // echec commande
1393 1393
 		}
1394 1394
 	}
1395 1395
 
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
 		if (!$output) {
1407 1407
 			return;
1408 1408
 		}
1409
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1409
+		$vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie;
1410 1410
 
1411 1411
 		$imagick = new Imagick();
1412 1412
 		$imagick->readImage(realpath($image));
@@ -1415,7 +1415,7 @@  discard block
 block discarded – undo
1415 1415
 			$destHeight,
1416 1416
 			Imagick::FILTER_LANCZOS,
1417 1417
 			1
1418
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1418
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1419 1419
 		$imagick->writeImage($vignette);
1420 1420
 
1421 1421
 		if (!@file_exists($vignette)) {
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
 			return;
1425 1425
 		}
1426 1426
 		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1427
-		$vignette = $destination . '.' . $format_sortie;
1427
+		$vignette = $destination.'.'.$format_sortie;
1428 1428
 	}
1429 1429
 
1430 1430
 	// netpbm
@@ -1435,11 +1435,11 @@  discard block
 block discarded – undo
1435 1435
 		if (_PNMSCALE_COMMAND == '') {
1436 1436
 			return;
1437 1437
 		}
1438
-		$vignette = $destination . '.' . $format_sortie;
1438
+		$vignette = $destination.'.'.$format_sortie;
1439 1439
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', (string) _PNMSCALE_COMMAND);
1440 1440
 		if ($format == 'jpg') {
1441 1441
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', (string) _PNMSCALE_COMMAND);
1442
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1442
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1443 1443
 			if (!($s = @filesize($vignette))) {
1444 1444
 				spip_unlink($vignette);
1445 1445
 			}
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
 		} else {
1452 1452
 			if ($format == 'gif') {
1453 1453
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', (string) _PNMSCALE_COMMAND);
1454
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1454
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1455 1455
 				if (!($s = @filesize($vignette))) {
1456 1456
 					spip_unlink($vignette);
1457 1457
 				}
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 			} else {
1464 1464
 				if ($format == 'png') {
1465 1465
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', (string) _PNMSCALE_COMMAND);
1466
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1466
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1467 1467
 					if (!($s = @filesize($vignette))) {
1468 1468
 						spip_unlink($vignette);
1469 1469
 					}
@@ -1485,7 +1485,7 @@  discard block
 block discarded – undo
1485 1485
 			return;
1486 1486
 		}
1487 1487
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1488
-			spip_logger('images')->info('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1488
+			spip_logger('images')->info('vignette gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1489 1489
 
1490 1490
 			return;
1491 1491
 		}
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
 		// de l'image, de facon a tromper le cache du navigateur
1789 1789
 		// quand on fait supprimer/reuploader un logo
1790 1790
 		// (pas de filemtime si SAFE MODE)
1791
-		$date = test_espace_prive() ? ('?' . $date) : '';
1791
+		$date = test_espace_prive() ? ('?'.$date) : '';
1792 1792
 
1793 1793
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1794 1794
 	}
@@ -1866,9 +1866,9 @@  discard block
 block discarded – undo
1866 1866
 					$b = $argb['blue'];
1867 1867
 
1868 1868
 					if ($bpp[$key] == 32) {
1869
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1869
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1870 1870
 					} elseif ($bpp[$key] === 24) {
1871
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1871
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1872 1872
 					}
1873 1873
 
1874 1874
 					if ($a < 128) {
@@ -1895,48 +1895,48 @@  discard block
 block discarded – undo
1895 1895
 
1896 1896
 			// BITMAPINFOHEADER - 40 bytes
1897 1897
 			$BitmapInfoHeader[$key] = '';
1898
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1899
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1898
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1899
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1900 1900
 			// The biHeight member specifies the combined
1901 1901
 			// height of the XOR and AND masks.
1902 1902
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1903
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1904
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1905
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1906
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1907
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1908
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1909
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1910
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1903
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1904
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1905
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1906
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1907
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1908
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1909
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1910
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1911 1911
 		}
1912 1912
 
1913 1913
 
1914
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1915
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1916
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1914
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1915
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1916
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1917 1917
 
1918 1918
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1919 1919
 		foreach (array_keys($gd_image_array) as $key) {
1920 1920
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1921 1921
 
1922
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1923
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1924
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1925
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1922
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1923
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1924
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1925
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1926 1926
 
1927
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1928
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1927
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1928
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1929 1929
 
1930 1930
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1931 1931
 			$icondata .= phpthumb_functions::LittleEndian2String(
1932 1932
 				$dwBytesInRes,
1933 1933
 				4
1934
-			);     // dwBytesInRes;	// How many bytes in this resource?
1934
+			); // dwBytesInRes;	// How many bytes in this resource?
1935 1935
 
1936 1936
 			$icondata .= phpthumb_functions::LittleEndian2String(
1937 1937
 				$dwImageOffset,
1938 1938
 				4
1939
-			);    // dwImageOffset;   // Where in the file is this image?
1939
+			); // dwImageOffset;   // Where in the file is this image?
1940 1940
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1941 1941
 			$dwImageOffset += strlen($icXOR[$key]);
1942 1942
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/bandeau.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 			$_id = $e['id_table_objet'];
52 52
 			if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) {
53 53
 				$table = $e['table_objet_sql'];
54
-				$row = sql_fetsel('*', $table, "$_id=" . (int) $id);
54
+				$row = sql_fetsel('*', $table, "$_id=".(int) $id);
55 55
 				if (isset($row['id_rubrique'])) {
56 56
 					$contexte['id_rubrique'] = $row['id_rubrique'];
57 57
 					if (isset($row['id_secteur'])) {
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
 				$boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
116 116
 					+ [
117 117
 						$id => new Bouton(
118
-							($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
119
-							$infos['titre'],  // titre
118
+							($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone
119
+							$infos['titre'], // titre
120 120
 							(isset($infos['action']) && $infos['action']) ? $infos['action'] : null,
121 121
 							(isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null
122 122
 						)
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 				$boutons_admin = array_slice($boutons_admin, 0, $position)
134 134
 					+ [
135 135
 						$id => new Bouton(
136
-							($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
137
-							$infos['titre'],  // titre
136
+							($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone
137
+							$infos['titre'], // titre
138 138
 							(isset($infos['action']) && $infos['action']) ? $infos['action'] : null,
139 139
 							(isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null
140 140
 						)
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		$url = str_replace('&amp;', '&', $url);
222 222
 		while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
223 223
 			if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) {
224
-				$contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']);
224
+				$contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $contexte['id_rubrique']);
225 225
 			}
226 226
 			$val = _request($matches[2], $contexte);
227 227
 			$url = parametre_url($url, $matches[1], $val ?: '', '&');
Please login to merge, or discard this patch.
Indentation   +149 added lines, -149 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
 
24 24
 include_spip('inc/boutons');
@@ -38,33 +38,33 @@  discard block
 block discarded – undo
38 38
  *     contexte
39 39
  **/
40 40
 function definir_barre_contexte($contexte = null) {
41
-	if (is_null($contexte)) {
42
-		$contexte = $_GET;
43
-	} elseif (is_string($contexte)) {
44
-		$contexte = unserialize($contexte);
45
-	}
46
-	if (!isset($contexte['id_rubrique']) && isset($contexte['exec'])) {
47
-		if (!function_exists('trouver_objet_exec')) {
48
-			include_spip('inc/pipelines_ecrire');
49
-		}
50
-		if ($e = trouver_objet_exec($contexte['exec'])) {
51
-			$_id = $e['id_table_objet'];
52
-			if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) {
53
-				$table = $e['table_objet_sql'];
54
-				$row = sql_fetsel('*', $table, "$_id=" . (int) $id);
55
-				if (isset($row['id_rubrique'])) {
56
-					$contexte['id_rubrique'] = $row['id_rubrique'];
57
-					if (isset($row['id_secteur'])) {
58
-						$contexte['id_secteur'] = $row['id_secteur'];
59
-					}
60
-				} elseif (isset($row['id_groupe'])) {
61
-					// TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
62
-					$contexte['id_groupe'] = $row['id_groupe'];
63
-				}
64
-			}
65
-		}
66
-	}
67
-	return $contexte;
41
+    if (is_null($contexte)) {
42
+        $contexte = $_GET;
43
+    } elseif (is_string($contexte)) {
44
+        $contexte = unserialize($contexte);
45
+    }
46
+    if (!isset($contexte['id_rubrique']) && isset($contexte['exec'])) {
47
+        if (!function_exists('trouver_objet_exec')) {
48
+            include_spip('inc/pipelines_ecrire');
49
+        }
50
+        if ($e = trouver_objet_exec($contexte['exec'])) {
51
+            $_id = $e['id_table_objet'];
52
+            if (isset($contexte[$_id]) && ($id = (int) $contexte[$_id])) {
53
+                $table = $e['table_objet_sql'];
54
+                $row = sql_fetsel('*', $table, "$_id=" . (int) $id);
55
+                if (isset($row['id_rubrique'])) {
56
+                    $contexte['id_rubrique'] = $row['id_rubrique'];
57
+                    if (isset($row['id_secteur'])) {
58
+                        $contexte['id_secteur'] = $row['id_secteur'];
59
+                    }
60
+                } elseif (isset($row['id_groupe'])) {
61
+                    // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
62
+                    $contexte['id_groupe'] = $row['id_groupe'];
63
+                }
64
+            }
65
+        }
66
+    }
67
+    return $contexte;
68 68
 }
69 69
 
70 70
 /**
@@ -80,89 +80,89 @@  discard block
 block discarded – undo
80 80
  * @return array
81 81
  */
82 82
 function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) {
83
-	include_spip('inc/autoriser');
84
-	$boutons_admin = [];
83
+    include_spip('inc/autoriser');
84
+    $boutons_admin = [];
85 85
 
86
-	// les boutons du core, issus de ecrire/paquet.xml
87
-	$liste_boutons = [];
86
+    // les boutons du core, issus de ecrire/paquet.xml
87
+    $liste_boutons = [];
88 88
 
89
-	// ajouter les boutons issus des plugin via paquet.xml
90
-	if (
91
-		function_exists('boutons_plugins')
92
-		&& is_array($liste_boutons_plugins = boutons_plugins())
93
-	) {
94
-		$liste_boutons = &$liste_boutons_plugins;
95
-	}
89
+    // ajouter les boutons issus des plugin via paquet.xml
90
+    if (
91
+        function_exists('boutons_plugins')
92
+        && is_array($liste_boutons_plugins = boutons_plugins())
93
+    ) {
94
+        $liste_boutons = &$liste_boutons_plugins;
95
+    }
96 96
 
97
-	foreach ($liste_boutons as $id => $infos) {
98
-		$parent = '';
99
-		// les boutons principaux ne sont pas soumis a autorisation
100
-		if (
101
-			!isset($infos['parent'])
102
-			|| !($parent = $infos['parent'])
103
-			|| !$autorise
104
-			|| autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
105
-		) {
106
-			if (
107
-				$parent
108
-				&& ($parent = preg_replace(',^bando_,', 'menu_', (string) $parent))
109
-				&& isset($boutons_admin[$parent])
110
-			) {
111
-				$position = (isset($infos['position']) && strlen((string) $infos['position'])) ? (int) $infos['position'] : count($boutons_admin[$parent]->sousmenu);
112
-				if ($position < 0) {
113
-					$position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
114
-				}
115
-				$boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
116
-					+ [
117
-						$id => new Bouton(
118
-							($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
119
-							$infos['titre'],  // titre
120
-							(isset($infos['action']) && $infos['action']) ? $infos['action'] : null,
121
-							(isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null
122
-						)
123
-					]
124
-					+ array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
125
-			}
126
-			if (
127
-				!$parent
128
-				// provisoire, eviter les vieux boutons
129
-				&& !in_array($id, ['forum', 'statistiques_visites'])
130
-				&& (!$autorise || autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
131
-			) {
132
-				$position = (isset($infos['position']) && $infos['position']) ? $infos['position'] : count($boutons_admin);
133
-				$boutons_admin = array_slice($boutons_admin, 0, $position)
134
-					+ [
135
-						$id => new Bouton(
136
-							($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
137
-							$infos['titre'],  // titre
138
-							(isset($infos['action']) && $infos['action']) ? $infos['action'] : null,
139
-							(isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null
140
-						)
141
-					]
142
-					+ array_slice($boutons_admin, $position, 100);
143
-			}
144
-		}
145
-	}
146
-	$boutons_admin = pipeline('ajouter_menus', $boutons_admin);
97
+    foreach ($liste_boutons as $id => $infos) {
98
+        $parent = '';
99
+        // les boutons principaux ne sont pas soumis a autorisation
100
+        if (
101
+            !isset($infos['parent'])
102
+            || !($parent = $infos['parent'])
103
+            || !$autorise
104
+            || autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
105
+        ) {
106
+            if (
107
+                $parent
108
+                && ($parent = preg_replace(',^bando_,', 'menu_', (string) $parent))
109
+                && isset($boutons_admin[$parent])
110
+            ) {
111
+                $position = (isset($infos['position']) && strlen((string) $infos['position'])) ? (int) $infos['position'] : count($boutons_admin[$parent]->sousmenu);
112
+                if ($position < 0) {
113
+                    $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
114
+                }
115
+                $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
116
+                    + [
117
+                        $id => new Bouton(
118
+                            ($icones && !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
119
+                            $infos['titre'],  // titre
120
+                            (isset($infos['action']) && $infos['action']) ? $infos['action'] : null,
121
+                            (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null
122
+                        )
123
+                    ]
124
+                    + array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
125
+            }
126
+            if (
127
+                !$parent
128
+                // provisoire, eviter les vieux boutons
129
+                && !in_array($id, ['forum', 'statistiques_visites'])
130
+                && (!$autorise || autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
131
+            ) {
132
+                $position = (isset($infos['position']) && $infos['position']) ? $infos['position'] : count($boutons_admin);
133
+                $boutons_admin = array_slice($boutons_admin, 0, $position)
134
+                    + [
135
+                        $id => new Bouton(
136
+                            ($icones && isset($infos['icone']) && $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
137
+                            $infos['titre'],  // titre
138
+                            (isset($infos['action']) && $infos['action']) ? $infos['action'] : null,
139
+                            (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : null
140
+                        )
141
+                    ]
142
+                    + array_slice($boutons_admin, $position, 100);
143
+            }
144
+        }
145
+    }
146
+    $boutons_admin = pipeline('ajouter_menus', $boutons_admin);
147 147
 
148
-	// définir les favoris et positions d’origine
149
-	if ($boutons_admin) {
150
-		$menus_favoris = obtenir_menus_favoris();
151
-		$i = 1;
152
-		foreach ($boutons_admin as $key => $menu) {
153
-			$menu->favori = (int) table_valeur($menus_favoris, $key, false);
154
-			$menu->position = $i++;
155
-			if ($menu->sousmenu) {
156
-				$j = 1;
157
-				foreach ($menu->sousmenu as $key => $bouton) {
158
-					$bouton->favori = (int) table_valeur($menus_favoris, $key, false);
159
-					$bouton->position = $j++;
160
-				}
161
-			}
162
-		}
163
-	}
148
+    // définir les favoris et positions d’origine
149
+    if ($boutons_admin) {
150
+        $menus_favoris = obtenir_menus_favoris();
151
+        $i = 1;
152
+        foreach ($boutons_admin as $key => $menu) {
153
+            $menu->favori = (int) table_valeur($menus_favoris, $key, false);
154
+            $menu->position = $i++;
155
+            if ($menu->sousmenu) {
156
+                $j = 1;
157
+                foreach ($menu->sousmenu as $key => $bouton) {
158
+                    $bouton->favori = (int) table_valeur($menus_favoris, $key, false);
159
+                    $bouton->position = $j++;
160
+                }
161
+            }
162
+        }
163
+    }
164 164
 
165
-	return $boutons_admin;
165
+    return $boutons_admin;
166 166
 }
167 167
 
168 168
 /**
@@ -174,22 +174,22 @@  discard block
 block discarded – undo
174 174
  * @return Bouton[]
175 175
  */
176 176
 function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) {
177
-	foreach ($menus as $menu) {
178
-		if ($menu->sousmenu) {
179
-			$libelles = $isfavoris = $favoris = [];
180
-			foreach ($menu->sousmenu as $key => $item) {
181
-				$libelles[$key] = strtolower(translitteration(_T($item->libelle)));
182
-				$isfavoris[$key] = (bool) $item->favori;
183
-				$favoris[$key] = $item->favori;
184
-			}
185
-			if ($avec_favoris) {
186
-				array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
187
-			} else {
188
-				array_multisort($libelles, SORT_ASC, $menu->sousmenu);
189
-			}
190
-		}
191
-	}
192
-	return $menus;
177
+    foreach ($menus as $menu) {
178
+        if ($menu->sousmenu) {
179
+            $libelles = $isfavoris = $favoris = [];
180
+            foreach ($menu->sousmenu as $key => $item) {
181
+                $libelles[$key] = strtolower(translitteration(_T($item->libelle)));
182
+                $isfavoris[$key] = (bool) $item->favori;
183
+                $favoris[$key] = $item->favori;
184
+            }
185
+            if ($avec_favoris) {
186
+                array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
187
+            } else {
188
+                array_multisort($libelles, SORT_ASC, $menu->sousmenu);
189
+            }
190
+        }
191
+    }
192
+    return $menus;
193 193
 }
194 194
 
195 195
 /**
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
  * @return Bouton[]
201 201
  */
202 202
 function trier_boutons_enfants_par_favoris_alpha($menus) {
203
-	return trier_boutons_enfants_par_alpha($menus, true);
203
+    return trier_boutons_enfants_par_alpha($menus, true);
204 204
 }
205 205
 
206 206
 
@@ -213,23 +213,23 @@  discard block
 block discarded – undo
213 213
  * @return string
214 214
  */
215 215
 function bandeau_creer_url($url, $args = '', $contexte = null) {
216
-	if (!preg_match(',[\/\?],', $url)) {
217
-		$url = generer_url_ecrire($url, $args, true);
218
-		// recuperer les parametres du contexte demande par l'url sous la forme
219
-		// &truc=@machin@
220
-		// @machin@ etant remplace par _request('machin')
221
-		$url = str_replace('&amp;', '&', $url);
222
-		while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
223
-			if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) {
224
-				$contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']);
225
-			}
226
-			$val = _request($matches[2], $contexte);
227
-			$url = parametre_url($url, $matches[1], $val ?: '', '&');
228
-		}
229
-		$url = str_replace('&', '&amp;', $url);
230
-	}
216
+    if (!preg_match(',[\/\?],', $url)) {
217
+        $url = generer_url_ecrire($url, $args, true);
218
+        // recuperer les parametres du contexte demande par l'url sous la forme
219
+        // &truc=@machin@
220
+        // @machin@ etant remplace par _request('machin')
221
+        $url = str_replace('&amp;', '&', $url);
222
+        while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
223
+            if ($matches[2] == 'id_secteur' && !isset($contexte['id_secteur']) && isset($contexte['id_rubrique'])) {
224
+                $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $contexte['id_rubrique']);
225
+            }
226
+            $val = _request($matches[2], $contexte);
227
+            $url = parametre_url($url, $matches[1], $val ?: '', '&');
228
+        }
229
+        $url = str_replace('&', '&amp;', $url);
230
+    }
231 231
 
232
-	return $url;
232
+    return $url;
233 233
 }
234 234
 
235 235
 /**
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
  *     Code HTML du bandeau
240 240
  */
241 241
 function inc_bandeau_dist() {
242
-	return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
242
+    return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
243 243
 }
244 244
 
245 245
 
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
  * @return array
249 249
  */
250 250
 function obtenir_menus_favoris() {
251
-	if (
252
-		isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
253
-		&& is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
254
-		&& $GLOBALS['visiteur_session']['prefs']['menus_favoris']
255
-	) {
256
-		return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
257
-	}
258
-	$definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
259
-	return $definir_menus_favoris();
251
+    if (
252
+        isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
253
+        && is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
254
+        && $GLOBALS['visiteur_session']['prefs']['menus_favoris']
255
+    ) {
256
+        return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
257
+    }
258
+    $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
259
+    return $definir_menus_favoris();
260 260
 }
Please login to merge, or discard this patch.
ecrire/inc/selectionner.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 
54 54
 	if ($aff_racine) {
55 55
 		$info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
56
-		$idom3 = $idom . '_selection';
56
+		$idom3 = $idom.'_selection';
57 57
 
58 58
 		$onClick = "jQuery(this).parent().addClass('on');jQuery('#choix_parent_principal .on').removeClass('on'); aff_selection(0, '$idom3', '$info', event);return false;";
59 59
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 			'  '
72 72
 		);
73 73
 
74
-		$js_func = $do . '_selection_titre';
74
+		$js_func = $do.'_selection_titre';
75 75
 		$ondbClick = "$js_func('$ondbClick',0,'selection_rubrique','id_parent');";
76 76
 
77 77
 		$aff_racine = "<div class='petit-item petite-racine item'>"
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
  **/
113 113
 function construire_selectionner_hierarchie($idom, $liste, $racine, $url, $name, $url_init = '') {
114 114
 
115
-	$idom1 = $idom . '_champ_recherche';
116
-	$idom2 = $idom . '_principal';
117
-	$idom3 = $idom . '_selection';
118
-	$idom4 = $idom . '_col_1';
119
-	$idom5 = 'img_' . $idom4;
120
-	$idom6 = $idom . '_fonc';
115
+	$idom1 = $idom.'_champ_recherche';
116
+	$idom2 = $idom.'_principal';
117
+	$idom3 = $idom.'_selection';
118
+	$idom4 = $idom.'_col_1';
119
+	$idom5 = 'img_'.$idom4;
120
+	$idom6 = $idom.'_fonc';
121 121
 
122 122
 	return "<div id='$idom'>"
123 123
 	. "<a id='$idom6' style='visibility: hidden;'"
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 	. http_img_pack(
128 128
 		'loader.svg',
129 129
 		'',
130
-		"class='loader' style='visibility: hidden;float:" . $GLOBALS['spip_lang_right'] . "' id='$idom5'"
130
+		"class='loader' style='visibility: hidden;float:".$GLOBALS['spip_lang_right']."' id='$idom5'"
131 131
 	)
132 132
 	. ''
133
-	. "<input style='width: 10em;float:" . $GLOBALS['spip_lang_right'] . ";' type='text' class='text search' id='$idom1' placeholder='" . _T('info_rechercher') . "'"
133
+	. "<input style='width: 10em;float:".$GLOBALS['spip_lang_right'].";' type='text' class='text search' id='$idom1' placeholder='"._T('info_rechercher')."'"
134 134
 	// eliminer Return car il provoque la soumission (balise unique)
135 135
 	// et eliminer Tab pour la navigation au clavier
136 136
 	// ce serait encore mieux de ne le faire que s'il y a encore plusieurs
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 
178 178
 	$liste = $id_rubrique;
179 179
 	$id_rubrique = (int) $id_rubrique;
180
-	while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = ' . $id_rubrique)) {
181
-		$liste = $id_rubrique . ",$liste";
180
+	while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = '.$id_rubrique)) {
181
+		$liste = $id_rubrique.",$liste";
182 182
 	}
183 183
 
184 184
 	return explode(',', "0,$liste");
Please login to merge, or discard this patch.
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/filtres');
@@ -45,56 +45,56 @@  discard block
 block discarded – undo
45 45
  **/
46 46
 function inc_selectionner_dist($sel, $idom = '', $exclus = 0, $aff_racine = false, $recur = true, $do = 'aff') {
47 47
 
48
-	if ($recur) {
49
-		$recur = mini_hier($sel);
50
-	} else {
51
-		$sel = 0;
52
-	}
53
-
54
-	if ($aff_racine) {
55
-		$info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
56
-		$idom3 = $idom . '_selection';
57
-
58
-		$onClick = "jQuery(this).parent().addClass('on');jQuery('#choix_parent_principal .on').removeClass('on'); aff_selection(0, '$idom3', '$info', event);return false;";
59
-
60
-		$ondbClick = strtr(
61
-			str_replace(
62
-				"'",
63
-				'&#8217;',
64
-				str_replace(
65
-					'"',
66
-					'&#34;',
67
-					(string) textebrut(_T('info_racine_site'))
68
-				)
69
-			),
70
-			"\n\r",
71
-			'  '
72
-		);
73
-
74
-		$js_func = $do . '_selection_titre';
75
-		$ondbClick = "$js_func('$ondbClick',0,'selection_rubrique','id_parent');";
76
-
77
-		$aff_racine = "<div class='petit-item petite-racine item'>"
78
-			. "<a href='#'"
79
-			. 'onclick="'
80
-			. $onClick
81
-			. "\"\nondbclick=\""
82
-			. $ondbClick
83
-			. $onClick
84
-			. '">'
85
-			. _T('info_racine_site')
86
-			. '</a></div>';
87
-	}
88
-
89
-	$url_init = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclus&id=0&col=1&do=$do");
90
-
91
-	$plonger = charger_fonction('plonger', 'inc');
92
-	$plonger_r = $plonger($sel, $idom, $recur, 1, $exclus, $do);
93
-
94
-	// url completee par la fonction JS onkeypress_rechercher
95
-	$url = generer_url_ecrire('rechercher', "exclus=$exclus&rac=$idom&do=$do&type=");
96
-
97
-	return construire_selectionner_hierarchie($idom, $plonger_r, $aff_racine, $url, 'id_parent', $url_init);
48
+    if ($recur) {
49
+        $recur = mini_hier($sel);
50
+    } else {
51
+        $sel = 0;
52
+    }
53
+
54
+    if ($aff_racine) {
55
+        $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
56
+        $idom3 = $idom . '_selection';
57
+
58
+        $onClick = "jQuery(this).parent().addClass('on');jQuery('#choix_parent_principal .on').removeClass('on'); aff_selection(0, '$idom3', '$info', event);return false;";
59
+
60
+        $ondbClick = strtr(
61
+            str_replace(
62
+                "'",
63
+                '&#8217;',
64
+                str_replace(
65
+                    '"',
66
+                    '&#34;',
67
+                    (string) textebrut(_T('info_racine_site'))
68
+                )
69
+            ),
70
+            "\n\r",
71
+            '  '
72
+        );
73
+
74
+        $js_func = $do . '_selection_titre';
75
+        $ondbClick = "$js_func('$ondbClick',0,'selection_rubrique','id_parent');";
76
+
77
+        $aff_racine = "<div class='petit-item petite-racine item'>"
78
+            . "<a href='#'"
79
+            . 'onclick="'
80
+            . $onClick
81
+            . "\"\nondbclick=\""
82
+            . $ondbClick
83
+            . $onClick
84
+            . '">'
85
+            . _T('info_racine_site')
86
+            . '</a></div>';
87
+    }
88
+
89
+    $url_init = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclus&id=0&col=1&do=$do");
90
+
91
+    $plonger = charger_fonction('plonger', 'inc');
92
+    $plonger_r = $plonger($sel, $idom, $recur, 1, $exclus, $do);
93
+
94
+    // url completee par la fonction JS onkeypress_rechercher
95
+    $url = generer_url_ecrire('rechercher', "exclus=$exclus&rac=$idom&do=$do&type=");
96
+
97
+    return construire_selectionner_hierarchie($idom, $plonger_r, $aff_racine, $url, 'id_parent', $url_init);
98 98
 }
99 99
 
100 100
 /**
@@ -112,58 +112,58 @@  discard block
 block discarded – undo
112 112
  **/
113 113
 function construire_selectionner_hierarchie($idom, $liste, $racine, $url, $name, $url_init = '') {
114 114
 
115
-	$idom1 = $idom . '_champ_recherche';
116
-	$idom2 = $idom . '_principal';
117
-	$idom3 = $idom . '_selection';
118
-	$idom4 = $idom . '_col_1';
119
-	$idom5 = 'img_' . $idom4;
120
-	$idom6 = $idom . '_fonc';
121
-
122
-	return "<div id='$idom'>"
123
-	. "<a id='$idom6' style='visibility: hidden;'"
124
-	. ($url_init ? "\nhref='$url_init'" : '')
125
-	. '></a>'
126
-	. "<div class='recherche_rapide_parent formulaire_recherche'>"
127
-	. http_img_pack(
128
-		'loader.svg',
129
-		'',
130
-		"class='loader' style='visibility: hidden;float:" . $GLOBALS['spip_lang_right'] . "' id='$idom5'"
131
-	)
132
-	. ''
133
-	. "<input style='width: 10em;float:" . $GLOBALS['spip_lang_right'] . ";' type='text' class='text search' id='$idom1' placeholder='" . _T('info_rechercher') . "'"
134
-	// eliminer Return car il provoque la soumission (balise unique)
135
-	// et eliminer Tab pour la navigation au clavier
136
-	// ce serait encore mieux de ne le faire que s'il y a encore plusieurs
137
-	// resultats retournes par la recherche
138
-	. "\nonkeypress=\"k=event.keyCode;if (k==13 || k==3 || k==9){return false;}\""
139
-	// lancer la recherche apres le filtrage ci-dessus sauf sur le tab (navigation au clavier)
140
-	. "\nonkeyup=\"if(event.keyCode==9){return false;};return onkey_rechercher(this.value,"
141
-	// la destination de la recherche
142
-	. "'$idom4'"
115
+    $idom1 = $idom . '_champ_recherche';
116
+    $idom2 = $idom . '_principal';
117
+    $idom3 = $idom . '_selection';
118
+    $idom4 = $idom . '_col_1';
119
+    $idom5 = 'img_' . $idom4;
120
+    $idom6 = $idom . '_fonc';
121
+
122
+    return "<div id='$idom'>"
123
+    . "<a id='$idom6' style='visibility: hidden;'"
124
+    . ($url_init ? "\nhref='$url_init'" : '')
125
+    . '></a>'
126
+    . "<div class='recherche_rapide_parent formulaire_recherche'>"
127
+    . http_img_pack(
128
+        'loader.svg',
129
+        '',
130
+        "class='loader' style='visibility: hidden;float:" . $GLOBALS['spip_lang_right'] . "' id='$idom5'"
131
+    )
132
+    . ''
133
+    . "<input style='width: 10em;float:" . $GLOBALS['spip_lang_right'] . ";' type='text' class='text search' id='$idom1' placeholder='" . _T('info_rechercher') . "'"
134
+    // eliminer Return car il provoque la soumission (balise unique)
135
+    // et eliminer Tab pour la navigation au clavier
136
+    // ce serait encore mieux de ne le faire que s'il y a encore plusieurs
137
+    // resultats retournes par la recherche
138
+    . "\nonkeypress=\"k=event.keyCode;if (k==13 || k==3 || k==9){return false;}\""
139
+    // lancer la recherche apres le filtrage ci-dessus sauf sur le tab (navigation au clavier)
140
+    . "\nonkeyup=\"if(event.keyCode==9){return false;};return onkey_rechercher(this.value,"
141
+    // la destination de la recherche
142
+    . "'$idom4'"
143 143
 #	. "this.parentNode.parentNode.parentNode.parentNode.nextSibling.firstChild.id"
144
-	. ",'"
145
-	// l'url effectuant la recherche
146
-	. $url
147
-	. "',"
148
-	// le noeud contenant un gif anime
149
-	// . "'idom5'"
150
-	. 'this.parentNode.previousSibling.firstChild'
151
-	. ",'"
152
-	// la valeur de l'attribut Name a remplir
153
-	. $name
154
-	. "','"
155
-	// noeud invisible memorisant l'URL initiale (pour re-initialisation)
156
-	. $idom6
157
-	. "')\""
158
-	. ' />'
159
-	. "\n</div>"
160
-	. ($racine ? "<div>$racine</div>" : '')
161
-	. "<div id='"
162
-	. $idom2
163
-	. "'><div id='$idom4'"
164
-	. " class=''>"
165
-	. $liste
166
-	. "</div></div>\n<div id='$idom3'></div></div>\n";
144
+    . ",'"
145
+    // l'url effectuant la recherche
146
+    . $url
147
+    . "',"
148
+    // le noeud contenant un gif anime
149
+    // . "'idom5'"
150
+    . 'this.parentNode.previousSibling.firstChild'
151
+    . ",'"
152
+    // la valeur de l'attribut Name a remplir
153
+    . $name
154
+    . "','"
155
+    // noeud invisible memorisant l'URL initiale (pour re-initialisation)
156
+    . $idom6
157
+    . "')\""
158
+    . ' />'
159
+    . "\n</div>"
160
+    . ($racine ? "<div>$racine</div>" : '')
161
+    . "<div id='"
162
+    . $idom2
163
+    . "'><div id='$idom4'"
164
+    . " class=''>"
165
+    . $liste
166
+    . "</div></div>\n<div id='$idom3'></div></div>\n";
167 167
 }
168 168
 
169 169
 /**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
  **/
176 176
 function mini_hier($id_rubrique) {
177 177
 
178
-	$liste = $id_rubrique;
179
-	$id_rubrique = (int) $id_rubrique;
180
-	while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = ' . $id_rubrique)) {
181
-		$liste = $id_rubrique . ",$liste";
182
-	}
178
+    $liste = $id_rubrique;
179
+    $id_rubrique = (int) $id_rubrique;
180
+    while ($id_rubrique = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique = ' . $id_rubrique)) {
181
+        $liste = $id_rubrique . ",$liste";
182
+    }
183 183
 
184
-	return explode(',', "0,$liste");
184
+    return explode(',', "0,$liste");
185 185
 }
Please login to merge, or discard this patch.