Completed
Push — master ( a56a38...81a660 )
by cam
01:36
created
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/rechercher.php 2 patches
Indentation   +308 added lines, -308 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
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -34,195 +34,195 @@  discard block
 block discarded – undo
34 34
  * @return array Couples (type d'objet => Couples (champ => score))
35 35
  */
36 36
 function liste_des_champs() {
37
-	static $liste = null;
38
-	if (is_null($liste)) {
39
-		$liste = [];
40
-		// recuperer les tables_objets_sql declarees
41
-		include_spip('base/objets');
42
-		$tables_objets = lister_tables_objets_sql();
43
-		foreach ($tables_objets as $t => $infos) {
44
-			if ($infos['rechercher_champs']) {
45
-				$liste[$infos['type']] = $infos['rechercher_champs'];
46
-			}
47
-		}
48
-		// puis passer dans le pipeline
49
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
50
-	}
51
-
52
-	return $liste;
37
+    static $liste = null;
38
+    if (is_null($liste)) {
39
+        $liste = [];
40
+        // recuperer les tables_objets_sql declarees
41
+        include_spip('base/objets');
42
+        $tables_objets = lister_tables_objets_sql();
43
+        foreach ($tables_objets as $t => $infos) {
44
+            if ($infos['rechercher_champs']) {
45
+                $liste[$infos['type']] = $infos['rechercher_champs'];
46
+            }
47
+        }
48
+        // puis passer dans le pipeline
49
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
50
+    }
51
+
52
+    return $liste;
53 53
 }
54 54
 
55 55
 
56 56
 // Recherche des auteurs et mots-cles associes
57 57
 // en ne regardant que le titre ou le nom
58 58
 function liste_des_jointures() {
59
-	static $liste = null;
60
-	if (is_null($liste)) {
61
-		$liste = [];
62
-		// recuperer les tables_objets_sql declarees
63
-		include_spip('base/objets');
64
-		$tables_objets = lister_tables_objets_sql();
65
-		foreach ($tables_objets as $t => $infos) {
66
-			if ($infos['rechercher_jointures']) {
67
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
68
-			}
69
-		}
70
-		// puis passer dans le pipeline
71
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
72
-	}
73
-
74
-	return $liste;
59
+    static $liste = null;
60
+    if (is_null($liste)) {
61
+        $liste = [];
62
+        // recuperer les tables_objets_sql declarees
63
+        include_spip('base/objets');
64
+        $tables_objets = lister_tables_objets_sql();
65
+        foreach ($tables_objets as $t => $infos) {
66
+            if ($infos['rechercher_jointures']) {
67
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
68
+            }
69
+        }
70
+        // puis passer dans le pipeline
71
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
72
+    }
73
+
74
+    return $liste;
75 75
 }
76 76
 
77 77
 function expression_recherche($recherche, $options) {
78
-	// ne calculer qu'une seule fois l'expression par hit
79
-	// (meme si utilisee dans plusieurs boucles)
80
-	static $expression = [];
81
-	$key = serialize([$recherche, $options['preg_flags']]);
82
-	if (isset($expression[$key])) {
83
-		return $expression[$key];
84
-	}
85
-
86
-	$u = $GLOBALS['meta']['pcre_u'];
87
-	if ($u && !str_contains($options['preg_flags'], (string) $u)) {
88
-		$options['preg_flags'] .= $u;
89
-	}
90
-	include_spip('inc/charsets');
91
-	$recherche = trim($recherche);
92
-
93
-	// retirer les + de +truc et les * de truc*
94
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
95
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
96
-
97
-	$is_preg = false;
98
-	if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99
-		// c'est une preg
100
-		$recherche_trans = translitteration($recherche);
101
-		$preg = $recherche_trans . $options['preg_flags'];
102
-		$is_preg = true;
103
-	} else {
104
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
105
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
106
-		// 'une', 'des' ...)
107
-
108
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
109
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
110
-
111
-		// les expressions entre " " sont un mot a chercher tel quel
112
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
113
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
114
-			foreach ($matches as $match) {
115
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
116
-				$word = trim($word, '"');
117
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
118
-			}
119
-		}
120
-
121
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
122
-			$is_preg = true;
123
-
124
-			$recherche_inter = '|';
125
-			$recherche_mots = explode(' ', $recherche_mod);
126
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
127
-			$petits_mots = true;
128
-			foreach ($recherche_mots as $mot) {
129
-				if (strlen($mot) >= $min_long) {
130
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
-					$recherche_inter .= preg_quote($mot) . ' ';
132
-					$petits_mots = false;
133
-				}
134
-			}
135
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
136
-
137
-			// mais on cherche quand même l'expression complète, même si elle
138
-			// comporte des mots de moins de quatre lettres
139
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
140
-			if (!$recherche || $petits_mots) {
141
-				$recherche = preg_quote($recherche_org);
142
-			}
143
-			$recherche_trans = translitteration($recherche);
144
-		}
145
-
146
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
147
-	}
148
-
149
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
150
-	// ou si l'expression reguliere est invalide
151
-	if (!$is_preg || @preg_match($preg, '') === false) {
152
-		$methode = 'LIKE';
153
-		$u = $GLOBALS['meta']['pcre_u'];
154
-
155
-		// echapper les % et _
156
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
157
-
158
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
159
-		$recherche = preg_quote($recherche, '/');
160
-		$recherche_trans = translitteration($recherche);
161
-		$recherche_mod = $recherche_trans;
162
-
163
-		// les expressions entre " " sont un mot a chercher tel quel
164
-		// -> on remplace les espaces par un _ et on enleve les guillemets
165
-		// corriger le like dans le $q
166
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
167
-			foreach ($matches as $match) {
168
-				$word = preg_replace(',\s+,Uims', '_', $match);
169
-				$word = trim($word, '"');
170
-				$q = str_replace($match, $word, $q);
171
-			}
172
-		}
173
-		// corriger la regexp
174
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
175
-			foreach ($matches as $match) {
176
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
177
-				$word = trim($word, '"');
178
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
179
-			}
180
-		}
181
-		$q = sql_quote(
182
-			'%'
183
-			. preg_replace(',\s+,' . $u, '%', $q)
184
-			. '%'
185
-		);
186
-
187
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
188
-	} else {
189
-		$methode = 'REGEXP';
190
-		$q = sql_quote(trim($recherche, '/'));
191
-	}
192
-
193
-	// tous les caracteres transliterables de $q sont remplaces par un joker
194
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
195
-	$q_t = $q;
196
-	for ($i = 0; $i < spip_strlen($q); $i++) {
197
-		$char = spip_substr($q, $i, 1);
198
-		if (
199
-			!is_ascii($char)
200
-			&& ($char_t = translitteration($char))
201
-			&& $char_t !== $char
202
-		) {
203
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
204
-			// mais c'est un pis aller cf #4354
205
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
206
-		}
207
-	}
208
-
209
-	$q = $q_t;
210
-
211
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
212
-	// les plus frequents qui peuvent etre accentues
213
-	// (oui c'est tres dicustable...)
214
-	if (
215
-		isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
216
-		&& str_starts_with($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite')
217
-	) {
218
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
219
-		// si il reste au moins un char significatif...
220
-		if (preg_match(",[^'%_.],", $q_t)) {
221
-			$q = $q_t;
222
-		}
223
-	}
224
-
225
-	return $expression[$key] = [$methode, $q, $preg];
78
+    // ne calculer qu'une seule fois l'expression par hit
79
+    // (meme si utilisee dans plusieurs boucles)
80
+    static $expression = [];
81
+    $key = serialize([$recherche, $options['preg_flags']]);
82
+    if (isset($expression[$key])) {
83
+        return $expression[$key];
84
+    }
85
+
86
+    $u = $GLOBALS['meta']['pcre_u'];
87
+    if ($u && !str_contains($options['preg_flags'], (string) $u)) {
88
+        $options['preg_flags'] .= $u;
89
+    }
90
+    include_spip('inc/charsets');
91
+    $recherche = trim($recherche);
92
+
93
+    // retirer les + de +truc et les * de truc*
94
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
95
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
96
+
97
+    $is_preg = false;
98
+    if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99
+        // c'est une preg
100
+        $recherche_trans = translitteration($recherche);
101
+        $preg = $recherche_trans . $options['preg_flags'];
102
+        $is_preg = true;
103
+    } else {
104
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
105
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
106
+        // 'une', 'des' ...)
107
+
108
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
109
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
110
+
111
+        // les expressions entre " " sont un mot a chercher tel quel
112
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
113
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
114
+            foreach ($matches as $match) {
115
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
116
+                $word = trim($word, '"');
117
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
118
+            }
119
+        }
120
+
121
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
122
+            $is_preg = true;
123
+
124
+            $recherche_inter = '|';
125
+            $recherche_mots = explode(' ', $recherche_mod);
126
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
127
+            $petits_mots = true;
128
+            foreach ($recherche_mots as $mot) {
129
+                if (strlen($mot) >= $min_long) {
130
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
+                    $recherche_inter .= preg_quote($mot) . ' ';
132
+                    $petits_mots = false;
133
+                }
134
+            }
135
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
136
+
137
+            // mais on cherche quand même l'expression complète, même si elle
138
+            // comporte des mots de moins de quatre lettres
139
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
140
+            if (!$recherche || $petits_mots) {
141
+                $recherche = preg_quote($recherche_org);
142
+            }
143
+            $recherche_trans = translitteration($recherche);
144
+        }
145
+
146
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
147
+    }
148
+
149
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
150
+    // ou si l'expression reguliere est invalide
151
+    if (!$is_preg || @preg_match($preg, '') === false) {
152
+        $methode = 'LIKE';
153
+        $u = $GLOBALS['meta']['pcre_u'];
154
+
155
+        // echapper les % et _
156
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
157
+
158
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
159
+        $recherche = preg_quote($recherche, '/');
160
+        $recherche_trans = translitteration($recherche);
161
+        $recherche_mod = $recherche_trans;
162
+
163
+        // les expressions entre " " sont un mot a chercher tel quel
164
+        // -> on remplace les espaces par un _ et on enleve les guillemets
165
+        // corriger le like dans le $q
166
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
167
+            foreach ($matches as $match) {
168
+                $word = preg_replace(',\s+,Uims', '_', $match);
169
+                $word = trim($word, '"');
170
+                $q = str_replace($match, $word, $q);
171
+            }
172
+        }
173
+        // corriger la regexp
174
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
175
+            foreach ($matches as $match) {
176
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
177
+                $word = trim($word, '"');
178
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
179
+            }
180
+        }
181
+        $q = sql_quote(
182
+            '%'
183
+            . preg_replace(',\s+,' . $u, '%', $q)
184
+            . '%'
185
+        );
186
+
187
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
188
+    } else {
189
+        $methode = 'REGEXP';
190
+        $q = sql_quote(trim($recherche, '/'));
191
+    }
192
+
193
+    // tous les caracteres transliterables de $q sont remplaces par un joker
194
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
195
+    $q_t = $q;
196
+    for ($i = 0; $i < spip_strlen($q); $i++) {
197
+        $char = spip_substr($q, $i, 1);
198
+        if (
199
+            !is_ascii($char)
200
+            && ($char_t = translitteration($char))
201
+            && $char_t !== $char
202
+        ) {
203
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
204
+            // mais c'est un pis aller cf #4354
205
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
206
+        }
207
+    }
208
+
209
+    $q = $q_t;
210
+
211
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
212
+    // les plus frequents qui peuvent etre accentues
213
+    // (oui c'est tres dicustable...)
214
+    if (
215
+        isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
216
+        && str_starts_with($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite')
217
+    ) {
218
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
219
+        // si il reste au moins un char significatif...
220
+        if (preg_match(",[^'%_.],", $q_t)) {
221
+            $q = $q_t;
222
+        }
223
+    }
224
+
225
+    return $expression[$key] = [$methode, $q, $preg];
226 226
 }
227 227
 
228 228
 
@@ -249,136 +249,136 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
252
-	include_spip('base/abstract_sql');
253
-
254
-	if (!is_array($tables)) {
255
-		$liste = liste_des_champs();
256
-
257
-		if (is_string($tables) && $tables != '') {
258
-			$toutes = [];
259
-			foreach (explode(',', $tables) as $t) {
260
-				$t = trim($t);
261
-				if (isset($liste[$t])) {
262
-					$toutes[$t] = $liste[$t];
263
-				}
264
-			}
265
-			$tables = $toutes;
266
-			unset($toutes);
267
-		} else {
268
-			$tables = $liste;
269
-		}
270
-	}
271
-
272
-	if (!strlen($recherche) || $tables === []) {
273
-		return [];
274
-	}
275
-
276
-	include_spip('inc/autoriser');
277
-
278
-	// options par defaut
279
-	$options = array_merge(
280
-		[
281
-		'preg_flags' => 'UimsS',
282
-		'toutvoir' => false,
283
-		'champs' => false,
284
-		'score' => false,
285
-		'matches' => false,
286
-		'jointures' => false,
287
-		'serveur' => $serveur
288
-		],
289
-		$options
290
-	);
291
-
292
-	$results = [];
293
-
294
-	// Utiliser l'iterateur (DATA:recherche)
295
-	// pour recuperer les couples (id_objet, score)
296
-	// Le resultat est au format {
297
-	//      id1 = { 'score' => x, attrs => { } },
298
-	//      id2 = { 'score' => x, attrs => { } },
299
-	// }
300
-
301
-	include_spip('inc/recherche_to_array');
302
-
303
-	foreach ($tables as $table => $champs) {
304
-		# lock via memoization, si dispo
305
-		if (function_exists('cache_lock')) {
306
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
307
-		}
308
-
309
-		spip_timer('rech');
310
-
311
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
312
-		$to_array = charger_fonction('recherche_to_array', 'inc');
313
-		$results[$table] = $to_array(
314
-			$recherche,
315
-			array_merge($options, ['table' => $table, 'champs' => $champs])
316
-		);
317
-		##var_dump($results[$table]);
318
-
319
-
320
-		spip_log(
321
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
322
-			'recherche'
323
-		);
324
-
325
-		if (isset($lock)) {
326
-			cache_unlock($lock);
327
-		}
328
-	}
329
-
330
-	return $results;
252
+    include_spip('base/abstract_sql');
253
+
254
+    if (!is_array($tables)) {
255
+        $liste = liste_des_champs();
256
+
257
+        if (is_string($tables) && $tables != '') {
258
+            $toutes = [];
259
+            foreach (explode(',', $tables) as $t) {
260
+                $t = trim($t);
261
+                if (isset($liste[$t])) {
262
+                    $toutes[$t] = $liste[$t];
263
+                }
264
+            }
265
+            $tables = $toutes;
266
+            unset($toutes);
267
+        } else {
268
+            $tables = $liste;
269
+        }
270
+    }
271
+
272
+    if (!strlen($recherche) || $tables === []) {
273
+        return [];
274
+    }
275
+
276
+    include_spip('inc/autoriser');
277
+
278
+    // options par defaut
279
+    $options = array_merge(
280
+        [
281
+        'preg_flags' => 'UimsS',
282
+        'toutvoir' => false,
283
+        'champs' => false,
284
+        'score' => false,
285
+        'matches' => false,
286
+        'jointures' => false,
287
+        'serveur' => $serveur
288
+        ],
289
+        $options
290
+    );
291
+
292
+    $results = [];
293
+
294
+    // Utiliser l'iterateur (DATA:recherche)
295
+    // pour recuperer les couples (id_objet, score)
296
+    // Le resultat est au format {
297
+    //      id1 = { 'score' => x, attrs => { } },
298
+    //      id2 = { 'score' => x, attrs => { } },
299
+    // }
300
+
301
+    include_spip('inc/recherche_to_array');
302
+
303
+    foreach ($tables as $table => $champs) {
304
+        # lock via memoization, si dispo
305
+        if (function_exists('cache_lock')) {
306
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
307
+        }
308
+
309
+        spip_timer('rech');
310
+
311
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
312
+        $to_array = charger_fonction('recherche_to_array', 'inc');
313
+        $results[$table] = $to_array(
314
+            $recherche,
315
+            array_merge($options, ['table' => $table, 'champs' => $champs])
316
+        );
317
+        ##var_dump($results[$table]);
318
+
319
+
320
+        spip_log(
321
+            "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
322
+            'recherche'
323
+        );
324
+
325
+        if (isset($lock)) {
326
+            cache_unlock($lock);
327
+        }
328
+    }
329
+
330
+    return $results;
331 331
 }
332 332
 
333 333
 
334 334
 // Effectue une recherche sur toutes les tables de la base de donnees
335 335
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
336
-	include_spip('inc/modifier');
337
-
338
-	// options par defaut
339
-	$options = array_merge(
340
-		[
341
-		'preg_flags' => 'UimsS',
342
-		'toutmodifier' => false
343
-		],
344
-		$options
345
-	);
346
-	$options['champs'] = true;
347
-
348
-
349
-	if (!is_array($tables)) {
350
-		$tables = liste_des_champs();
351
-	}
352
-
353
-	$results = recherche_en_base($recherche, $tables, $options);
354
-
355
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
356
-
357
-	foreach ($results as $table => $r) {
358
-		$_id_table = id_table_objet($table);
359
-		foreach ($r as $id => $x) {
360
-			if ($options['toutmodifier'] || autoriser('modifier', $table, $id)) {
361
-				$modifs = [];
362
-				foreach ($x['champs'] as $key => $val) {
363
-					if ($key == $_id_table) {
364
-						continue;
365
-					}
366
-					$repl = preg_replace($preg, $remplace, $val);
367
-					if ($repl != $val) {
368
-						$modifs[$key] = $repl;
369
-					}
370
-				}
371
-				if ($modifs) {
372
-					objet_modifier_champs(
373
-						$table,
374
-						$id,
375
-						[
376
-							'champs' => array_keys($modifs),
377
-						],
378
-						$modifs
379
-					);
380
-				}
381
-			}
382
-		}
383
-	}
336
+    include_spip('inc/modifier');
337
+
338
+    // options par defaut
339
+    $options = array_merge(
340
+        [
341
+        'preg_flags' => 'UimsS',
342
+        'toutmodifier' => false
343
+        ],
344
+        $options
345
+    );
346
+    $options['champs'] = true;
347
+
348
+
349
+    if (!is_array($tables)) {
350
+        $tables = liste_des_champs();
351
+    }
352
+
353
+    $results = recherche_en_base($recherche, $tables, $options);
354
+
355
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
356
+
357
+    foreach ($results as $table => $r) {
358
+        $_id_table = id_table_objet($table);
359
+        foreach ($r as $id => $x) {
360
+            if ($options['toutmodifier'] || autoriser('modifier', $table, $id)) {
361
+                $modifs = [];
362
+                foreach ($x['champs'] as $key => $val) {
363
+                    if ($key == $_id_table) {
364
+                        continue;
365
+                    }
366
+                    $repl = preg_replace($preg, $remplace, $val);
367
+                    if ($repl != $val) {
368
+                        $modifs[$key] = $repl;
369
+                    }
370
+                }
371
+                if ($modifs) {
372
+                    objet_modifier_champs(
373
+                        $table,
374
+                        $id,
375
+                        [
376
+                            'champs' => array_keys($modifs),
377
+                        ],
378
+                        $modifs
379
+                    );
380
+                }
381
+            }
382
+        }
383
+    }
384 384
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99 99
 		// c'est une preg
100 100
 		$recherche_trans = translitteration($recherche);
101
-		$preg = $recherche_trans . $options['preg_flags'];
101
+		$preg = $recherche_trans.$options['preg_flags'];
102 102
 		$is_preg = true;
103 103
 	} else {
104 104
 		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 			}
119 119
 		}
120 120
 
121
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
121
+		if (preg_match(',\s+,'.$u, $recherche_mod)) {
122 122
 			$is_preg = true;
123 123
 
124 124
 			$recherche_inter = '|';
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			foreach ($recherche_mots as $mot) {
129 129
 				if (strlen($mot) >= $min_long) {
130 130
 					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
-					$recherche_inter .= preg_quote($mot) . ' ';
131
+					$recherche_inter .= preg_quote($mot).' ';
132 132
 					$petits_mots = false;
133 133
 				}
134 134
 			}
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 
137 137
 			// mais on cherche quand même l'expression complète, même si elle
138 138
 			// comporte des mots de moins de quatre lettres
139
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
139
+			$recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|');
140 140
 			if (!$recherche || $petits_mots) {
141 141
 				$recherche = preg_quote($recherche_org);
142 142
 			}
143 143
 			$recherche_trans = translitteration($recherche);
144 144
 		}
145 145
 
146
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
146
+		$preg = '/'.str_replace('/', '\\/', $recherche_trans).'/'.$options['preg_flags'];
147 147
 	}
148 148
 
149 149
 	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 		}
181 181
 		$q = sql_quote(
182 182
 			'%'
183
-			. preg_replace(',\s+,' . $u, '%', $q)
183
+			. preg_replace(',\s+,'.$u, '%', $q)
184 184
 			. '%'
185 185
 		);
186 186
 
187
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
187
+		$preg = '/'.preg_replace(',\s+,'.$u, '.+', trim($recherche_mod)).'/'.$options['preg_flags'];
188 188
 	} else {
189 189
 		$methode = 'REGEXP';
190 190
 		$q = sql_quote(trim($recherche, '/'));
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	foreach ($tables as $table => $champs) {
304 304
 		# lock via memoization, si dispo
305 305
 		if (function_exists('cache_lock')) {
306
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
306
+			cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche);
307 307
 		}
308 308
 
309 309
 		spip_timer('rech');
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 
319 319
 
320 320
 		spip_log(
321
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
321
+			"recherche $table ($recherche) : ".(is_countable($results[$table]) ? count($results[$table]) : 0).' resultats '.spip_timer('rech'),
322 322
 			'recherche'
323 323
 		);
324 324
 
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 
353 353
 	$results = recherche_en_base($recherche, $tables, $options);
354 354
 
355
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
355
+	$preg = '/'.str_replace('/', '\\/', $recherche).'/'.$options['preg_flags'];
356 356
 
357 357
 	foreach ($results as $table => $r) {
358 358
 		$_id_table = id_table_objet($table);
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   +1287 added lines, -1287 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('inc/filtres'); // par precaution
23 23
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
  *     Le code de la couleur en hexadécimal.
38 38
  */
39 39
 function _couleur_dec_to_hex($red, $green, $blue) {
40
-	$red = dechex($red);
41
-	$green = dechex($green);
42
-	$blue = dechex($blue);
43
-
44
-	if (strlen($red) == 1) {
45
-		$red = '0' . $red;
46
-	}
47
-	if (strlen($green) == 1) {
48
-		$green = '0' . $green;
49
-	}
50
-	if (strlen($blue) == 1) {
51
-		$blue = '0' . $blue;
52
-	}
53
-
54
-	return "$red$green$blue";
40
+    $red = dechex($red);
41
+    $green = dechex($green);
42
+    $blue = dechex($blue);
43
+
44
+    if (strlen($red) == 1) {
45
+        $red = '0' . $red;
46
+    }
47
+    if (strlen($green) == 1) {
48
+        $green = '0' . $green;
49
+    }
50
+    if (strlen($blue) == 1) {
51
+        $blue = '0' . $blue;
52
+    }
53
+
54
+    return "$red$green$blue";
55 55
 }
56 56
 
57 57
 /**
@@ -63,18 +63,18 @@  discard block
 block discarded – undo
63 63
  *     Un tableau des 3 éléments : rouge, vert, bleu.
64 64
  */
65 65
 function _couleur_hex_to_dec($couleur) {
66
-	$couleur ??= '';
67
-	$couleur = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
66
+    $couleur ??= '';
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,55 +120,55 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$H = null;
124
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
-	$var_G = ($G / 255);
126
-	$var_B = ($B / 255);
127
-
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
131
-
132
-	$L = ($var_Max + $var_Min) / 2;
133
-
134
-	if ($del_Max == 0) {
135
-		//This is a gray, no chroma...
136
-		$H = 0; //HSL results = 0 ÷ 1
137
-		$S = 0;
138
-	} else {
139
-		// Chromatic data...
140
-		$S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min);
141
-
142
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
143
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
144
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
145
-
146
-		if ($var_R === $var_Max) {
147
-			$H = $del_B - $del_G;
148
-		} else {
149
-			if ($var_G === $var_Max) {
150
-				$H = (1 / 3) + $del_R - $del_B;
151
-			} else {
152
-				if ($var_B === $var_Max) {
153
-					$H = (2 / 3) + $del_G - $del_R;
154
-				}
155
-			}
156
-		}
157
-
158
-		if ($H < 0) {
159
-			$H += 1;
160
-		}
161
-		if ($H > 1) {
162
-			$H -= 1;
163
-		}
164
-	}
165
-
166
-	$ret = [];
167
-	$ret['h'] = $H;
168
-	$ret['s'] = $S;
169
-	$ret['l'] = $L;
170
-
171
-	return $ret;
123
+    $H = null;
124
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
+    $var_G = ($G / 255);
126
+    $var_B = ($B / 255);
127
+
128
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
131
+
132
+    $L = ($var_Max + $var_Min) / 2;
133
+
134
+    if ($del_Max == 0) {
135
+        //This is a gray, no chroma...
136
+        $H = 0; //HSL results = 0 ÷ 1
137
+        $S = 0;
138
+    } else {
139
+        // Chromatic data...
140
+        $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min);
141
+
142
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
143
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
144
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
145
+
146
+        if ($var_R === $var_Max) {
147
+            $H = $del_B - $del_G;
148
+        } else {
149
+            if ($var_G === $var_Max) {
150
+                $H = (1 / 3) + $del_R - $del_B;
151
+            } else {
152
+                if ($var_B === $var_Max) {
153
+                    $H = (2 / 3) + $del_G - $del_R;
154
+                }
155
+            }
156
+        }
157
+
158
+        if ($H < 0) {
159
+            $H += 1;
160
+        }
161
+        if ($H > 1) {
162
+            $H -= 1;
163
+        }
164
+    }
165
+
166
+    $ret = [];
167
+    $ret['h'] = $H;
168
+    $ret['s'] = $S;
169
+    $ret['l'] = $L;
170
+
171
+    return $ret;
172 172
 }
173 173
 
174 174
 
@@ -184,48 +184,48 @@  discard block
 block discarded – undo
184 184
  * @return array
185 185
  */
186 186
 function _couleur_hsl_to_rgb($H, $S, $L) {
187
-	// helper
188
-	$hue_2_rgb = function ($v1, $v2, $vH) {
189
-		if ($vH < 0) {
190
-			$vH += 1;
191
-		}
192
-		if ($vH > 1) {
193
-			$vH -= 1;
194
-		}
195
-		if ((6 * $vH) < 1) {
196
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
197
-		}
198
-		if ((2 * $vH) < 1) {
199
-			return ($v2);
200
-		}
201
-		if ((3 * $vH) < 2) {
202
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
203
-		}
204
-
205
-		return ($v1);
206
-	};
207
-
208
-	if ($S == 0) {
209
-		// HSV values = 0 -> 1
210
-		$R = $L * 255;
211
-		$G = $L * 255;
212
-		$B = $L * 255;
213
-	} else {
214
-		$var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L);
215
-
216
-		$var_1 = 2 * $L - $var_2;
217
-
218
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
219
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
220
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
221
-	}
222
-
223
-	$ret = [];
224
-	$ret['r'] = floor($R);
225
-	$ret['g'] = floor($G);
226
-	$ret['b'] = floor($B);
227
-
228
-	return $ret;
187
+    // helper
188
+    $hue_2_rgb = function ($v1, $v2, $vH) {
189
+        if ($vH < 0) {
190
+            $vH += 1;
191
+        }
192
+        if ($vH > 1) {
193
+            $vH -= 1;
194
+        }
195
+        if ((6 * $vH) < 1) {
196
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
197
+        }
198
+        if ((2 * $vH) < 1) {
199
+            return ($v2);
200
+        }
201
+        if ((3 * $vH) < 2) {
202
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
203
+        }
204
+
205
+        return ($v1);
206
+    };
207
+
208
+    if ($S == 0) {
209
+        // HSV values = 0 -> 1
210
+        $R = $L * 255;
211
+        $G = $L * 255;
212
+        $B = $L * 255;
213
+    } else {
214
+        $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L);
215
+
216
+        $var_1 = 2 * $L - $var_2;
217
+
218
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
219
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
220
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
221
+    }
222
+
223
+    $ret = [];
224
+    $ret['r'] = floor($R);
225
+    $ret['g'] = floor($G);
226
+    $ret['b'] = floor($B);
227
+
228
+    return $ret;
229 229
 }
230 230
 
231 231
 /**
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
  *     true si il faut supprimer le fichier temporaire ; false sinon.
244 244
  */
245 245
 function statut_effacer_images_temporaires($stat) {
246
-	static $statut = false; // par defaut on grave toute les images
247
-	if ($stat === 'get') {
248
-		return $statut;
249
-	}
250
-	$statut = (bool) $stat;
246
+    static $statut = false; // par defaut on grave toute les images
247
+    if ($stat === 'get') {
248
+        return $statut;
249
+    }
250
+    $statut = (bool) $stat;
251 251
 }
252 252
 
253 253
 
@@ -300,251 +300,251 @@  discard block
 block discarded – undo
300 300
  *     - array : tableau décrivant de l'image
301 301
  */
302 302
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
303
-	$valeurs = [];
304
-	$ret = [];
305
-	$f = null;
306
-	static $images_recalcul = [];
307
-	if (strlen($img) == 0) {
308
-		return false;
309
-	}
310
-
311
-	$source = trim(extraire_attribut($img, 'src') ?? '');
312
-	if (strlen($source) < 1) {
313
-		if (!str_starts_with($img, '<img ')) {
314
-			$source = $img;
315
-			$img = "<img src='$source' />";
316
-		} else {
317
-			// pas d'attribut src sur cette balise <img../>
318
-			return false;
319
-		}
320
-	} elseif (
321
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
-		&& ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
323
-		&& in_array($extension, _image_extensions_acceptees_en_entree())
324
-	) {
325
-		# gerer img src="data:....base64"
326
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
-		if (!file_exists($local)) {
328
-			ecrire_fichier($local, base64_decode($regs[2]));
329
-		}
330
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
331
-			$sanitizer($local);
332
-		}
333
-		$source = $local;
334
-		$img = inserer_attribut($img, 'src', $source);
335
-		# eviter les mauvaises surprises lors de conversions de format
336
-		$img = inserer_attribut($img, 'width', '');
337
-		$img = inserer_attribut($img, 'height', '');
338
-	}
339
-
340
-	// les protocoles web prennent au moins 3 lettres
341
-	if (tester_url_absolue($source)) {
342
-		include_spip('inc/distant');
343
-		$fichier = _DIR_RACINE . copie_locale($source);
344
-		if (!$fichier) {
345
-			return '';
346
-		}
347
-		if (
348
-			($extension = _image_trouver_extension($fichier))
349
-			&& ($sanitizer = charger_fonction($extension, 'sanitizer', true))
350
-		) {
351
-			$sanitizer($fichier);
352
-		}
353
-	} else {
354
-		// enlever le timestamp eventuel
355
-		if (str_contains($source, '?')) {
356
-			$source = preg_replace(',[?]\d+$,', '', $source);
357
-		}
358
-		if (
359
-			str_contains($source, '?')
360
-			&& str_starts_with($source, _DIR_IMG)
361
-			&& file_exists($f = preg_replace(',[?].*$,', '', $source))
362
-		) {
363
-			$source = $f;
364
-		}
365
-		$fichier = $source;
366
-	}
367
-
368
-	$terminaison_dest = '';
369
-	if ($terminaison = _image_trouver_extension($fichier)) {
370
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
371
-	}
372
-
373
-	if (
374
-		$forcer_format !== false
375
-		&& ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
376
-	) {
377
-		$terminaison_dest = $forcer_format;
378
-	}
379
-
380
-	if (!$terminaison_dest) {
381
-		return false;
382
-	}
383
-
384
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
385
-	$fichier_dest = $nom_fichier;
386
-	if (
387
-		$find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f)
388
-		|| @file_exists($f = $fichier)
389
-	) {
390
-		// on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance
391
-		// on lit directement les infos du fichier
392
-		[$ret['hauteur'], $ret['largeur']] = taille_image($f);
393
-		$date_src = @filemtime($f);
394
-	} elseif (
395
-		@file_exists($f = "$fichier.src")
396
-		&& lire_fichier($f, $valeurs)
397
-		&& ($valeurs = unserialize($valeurs))
398
-		&& isset($valeurs['hauteur_dest'])
399
-		&& isset($valeurs['largeur_dest'])
400
-	) {
401
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
402
-		$ret['largeur'] = $valeurs['largeur_dest'];
403
-		$date_src = $valeurs['date'];
404
-	} // pas de fichier source par la
405
-	else {
406
-		return false;
407
-	}
408
-
409
-	// pas de taille mesurable ?
410
-	if (
411
-		!$ret['hauteur']
412
-		|| !($ret['hauteur'] = (int) round($ret['hauteur']))
413
-		|| !$ret['largeur']
414
-		|| !($ret['largeur'] = (int) round($ret['largeur']))
415
-	) {
416
-		return false;
417
-	}
418
-
419
-	// les images calculees dependent du chemin du fichier source
420
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
421
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
422
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
423
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
424
-	// alors que ca concerne peu de site au final
425
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
426
-	$identifiant = $fichier;
427
-
428
-	// cas general :
429
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
430
-	// cas particulier de reduire :
431
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
432
-	$cache = 'cache-gd2';
433
-	if (str_starts_with($effet, 'reduire')) {
434
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
435
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
436
-		$ret['largeur_dest'] = $destWidth;
437
-		$ret['hauteur_dest'] = $destHeight;
438
-		$effet = "L{$destWidth}xH$destHeight";
439
-		$cache = 'cache-vignettes';
440
-		$fichier_dest = basename($fichier_dest);
441
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
442
-			// on garde la terminaison initiale car image simplement copiee
443
-			// et on postfixe son nom avec un md5 du path
444
-			$terminaison_dest = $terminaison;
445
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
446
-		} else {
447
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
448
-		}
449
-		$cache = sous_repertoire(_DIR_VAR, $cache);
450
-		$cache = sous_repertoire($cache, $effet);
451
-	} else {
452
-		$fichier_dest = md5("$identifiant-$effet");
453
-		$cache = sous_repertoire(_DIR_VAR, $cache);
454
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
455
-		$fichier_dest = substr($fichier_dest, 2);
456
-	}
457
-
458
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
459
-
460
-	$GLOBALS['images_calculees'][] = $fichier_dest;
461
-
462
-	$creer = true;
463
-	// si recalcul des images demande, recalculer chaque image une fois
464
-	if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) {
465
-		$images_recalcul[$fichier_dest] = true;
466
-	} else {
467
-		if (@file_exists($f = $fichier_dest)) {
468
-			if (filemtime($f) >= $date_src) {
469
-				$creer = false;
470
-			}
471
-		} else {
472
-			if (
473
-				@file_exists($f = "$fichier_dest.src")
474
-				&& lire_fichier($f, $valeurs)
475
-				&& ($valeurs = unserialize($valeurs))
476
-				&& $valeurs['date'] >= $date_src
477
-			) {
478
-				$creer = false;
479
-			}
480
-		}
481
-	}
482
-	if ($creer && !@file_exists($fichier)) {
483
-		if (!@file_exists("$fichier.src")) {
484
-			spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR);
485
-
486
-			return false;
487
-		}
488
-		# on reconstruit l'image source absente a partir de la chaine des .src
489
-		reconstruire_image_intermediaire($fichier);
490
-	}
491
-
492
-	if ($creer) {
493
-		spip_log(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
-			'images' . _LOG_DEBUG
496
-		);
497
-	}
498
-
499
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
500
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
501
-	$ret['fichier'] = $fichier;
502
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
503
-	$ret['fichier_dest'] = $fichier_dest;
504
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
505
-	$ret['format_dest'] = $terminaison_dest;
506
-	$ret['date_src'] = $date_src;
507
-	$ret['creer'] = $creer;
508
-	$ret['class'] = extraire_attribut($img, 'class');
509
-	$ret['alt'] = extraire_attribut($img, 'alt');
510
-	$ret['style'] = extraire_attribut($img, 'style');
511
-	$ret['tag'] = $img;
512
-	if ($fonction_creation) {
513
-		$ret['reconstruction'] = $fonction_creation;
514
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
515
-		# cas de image_reduire qui finalement ne reduit pas l'image source
516
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
517
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
518
-	}
519
-
520
-	$ret = pipeline('image_preparer_filtre', [
521
-			'args' => [
522
-				'img' => $img,
523
-				'effet' => $effet,
524
-				'forcer_format' => $forcer_format,
525
-				'fonction_creation' => $fonction_creation,
526
-				'find_in_path' => $find_in_path,
527
-			],
528
-			'data' => $ret
529
-		]);
530
-
531
-	// une globale pour le debug en cas de crash memoire
532
-	$GLOBALS['derniere_image_calculee'] = $ret;
533
-
534
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
535
-	if ($term_fonction === 'svg') {
536
-		if ($creer && !$support_svg) {
537
-			process_image_svg_identite($ret);
538
-			$ret['creer'] = false;
539
-		}
540
-	}
541
-	else {
542
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
543
-			return false;
544
-		}
545
-	}
546
-
547
-	return $ret;
303
+    $valeurs = [];
304
+    $ret = [];
305
+    $f = null;
306
+    static $images_recalcul = [];
307
+    if (strlen($img) == 0) {
308
+        return false;
309
+    }
310
+
311
+    $source = trim(extraire_attribut($img, 'src') ?? '');
312
+    if (strlen($source) < 1) {
313
+        if (!str_starts_with($img, '<img ')) {
314
+            $source = $img;
315
+            $img = "<img src='$source' />";
316
+        } else {
317
+            // pas d'attribut src sur cette balise <img../>
318
+            return false;
319
+        }
320
+    } elseif (
321
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
+        && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
323
+        && in_array($extension, _image_extensions_acceptees_en_entree())
324
+    ) {
325
+        # gerer img src="data:....base64"
326
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
327
+        if (!file_exists($local)) {
328
+            ecrire_fichier($local, base64_decode($regs[2]));
329
+        }
330
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
331
+            $sanitizer($local);
332
+        }
333
+        $source = $local;
334
+        $img = inserer_attribut($img, 'src', $source);
335
+        # eviter les mauvaises surprises lors de conversions de format
336
+        $img = inserer_attribut($img, 'width', '');
337
+        $img = inserer_attribut($img, 'height', '');
338
+    }
339
+
340
+    // les protocoles web prennent au moins 3 lettres
341
+    if (tester_url_absolue($source)) {
342
+        include_spip('inc/distant');
343
+        $fichier = _DIR_RACINE . copie_locale($source);
344
+        if (!$fichier) {
345
+            return '';
346
+        }
347
+        if (
348
+            ($extension = _image_trouver_extension($fichier))
349
+            && ($sanitizer = charger_fonction($extension, 'sanitizer', true))
350
+        ) {
351
+            $sanitizer($fichier);
352
+        }
353
+    } else {
354
+        // enlever le timestamp eventuel
355
+        if (str_contains($source, '?')) {
356
+            $source = preg_replace(',[?]\d+$,', '', $source);
357
+        }
358
+        if (
359
+            str_contains($source, '?')
360
+            && str_starts_with($source, _DIR_IMG)
361
+            && file_exists($f = preg_replace(',[?].*$,', '', $source))
362
+        ) {
363
+            $source = $f;
364
+        }
365
+        $fichier = $source;
366
+    }
367
+
368
+    $terminaison_dest = '';
369
+    if ($terminaison = _image_trouver_extension($fichier)) {
370
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
371
+    }
372
+
373
+    if (
374
+        $forcer_format !== false
375
+        && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
376
+    ) {
377
+        $terminaison_dest = $forcer_format;
378
+    }
379
+
380
+    if (!$terminaison_dest) {
381
+        return false;
382
+    }
383
+
384
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
385
+    $fichier_dest = $nom_fichier;
386
+    if (
387
+        $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f)
388
+        || @file_exists($f = $fichier)
389
+    ) {
390
+        // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance
391
+        // on lit directement les infos du fichier
392
+        [$ret['hauteur'], $ret['largeur']] = taille_image($f);
393
+        $date_src = @filemtime($f);
394
+    } elseif (
395
+        @file_exists($f = "$fichier.src")
396
+        && lire_fichier($f, $valeurs)
397
+        && ($valeurs = unserialize($valeurs))
398
+        && isset($valeurs['hauteur_dest'])
399
+        && isset($valeurs['largeur_dest'])
400
+    ) {
401
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
402
+        $ret['largeur'] = $valeurs['largeur_dest'];
403
+        $date_src = $valeurs['date'];
404
+    } // pas de fichier source par la
405
+    else {
406
+        return false;
407
+    }
408
+
409
+    // pas de taille mesurable ?
410
+    if (
411
+        !$ret['hauteur']
412
+        || !($ret['hauteur'] = (int) round($ret['hauteur']))
413
+        || !$ret['largeur']
414
+        || !($ret['largeur'] = (int) round($ret['largeur']))
415
+    ) {
416
+        return false;
417
+    }
418
+
419
+    // les images calculees dependent du chemin du fichier source
420
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
421
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
422
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
423
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
424
+    // alors que ca concerne peu de site au final
425
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
426
+    $identifiant = $fichier;
427
+
428
+    // cas general :
429
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
430
+    // cas particulier de reduire :
431
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
432
+    $cache = 'cache-gd2';
433
+    if (str_starts_with($effet, 'reduire')) {
434
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
435
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
436
+        $ret['largeur_dest'] = $destWidth;
437
+        $ret['hauteur_dest'] = $destHeight;
438
+        $effet = "L{$destWidth}xH$destHeight";
439
+        $cache = 'cache-vignettes';
440
+        $fichier_dest = basename($fichier_dest);
441
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
442
+            // on garde la terminaison initiale car image simplement copiee
443
+            // et on postfixe son nom avec un md5 du path
444
+            $terminaison_dest = $terminaison;
445
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
446
+        } else {
447
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
448
+        }
449
+        $cache = sous_repertoire(_DIR_VAR, $cache);
450
+        $cache = sous_repertoire($cache, $effet);
451
+    } else {
452
+        $fichier_dest = md5("$identifiant-$effet");
453
+        $cache = sous_repertoire(_DIR_VAR, $cache);
454
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
455
+        $fichier_dest = substr($fichier_dest, 2);
456
+    }
457
+
458
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
459
+
460
+    $GLOBALS['images_calculees'][] = $fichier_dest;
461
+
462
+    $creer = true;
463
+    // si recalcul des images demande, recalculer chaque image une fois
464
+    if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) {
465
+        $images_recalcul[$fichier_dest] = true;
466
+    } else {
467
+        if (@file_exists($f = $fichier_dest)) {
468
+            if (filemtime($f) >= $date_src) {
469
+                $creer = false;
470
+            }
471
+        } else {
472
+            if (
473
+                @file_exists($f = "$fichier_dest.src")
474
+                && lire_fichier($f, $valeurs)
475
+                && ($valeurs = unserialize($valeurs))
476
+                && $valeurs['date'] >= $date_src
477
+            ) {
478
+                $creer = false;
479
+            }
480
+        }
481
+    }
482
+    if ($creer && !@file_exists($fichier)) {
483
+        if (!@file_exists("$fichier.src")) {
484
+            spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR);
485
+
486
+            return false;
487
+        }
488
+        # on reconstruit l'image source absente a partir de la chaine des .src
489
+        reconstruire_image_intermediaire($fichier);
490
+    }
491
+
492
+    if ($creer) {
493
+        spip_log(
494
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
+            'images' . _LOG_DEBUG
496
+        );
497
+    }
498
+
499
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
500
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
501
+    $ret['fichier'] = $fichier;
502
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
503
+    $ret['fichier_dest'] = $fichier_dest;
504
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
505
+    $ret['format_dest'] = $terminaison_dest;
506
+    $ret['date_src'] = $date_src;
507
+    $ret['creer'] = $creer;
508
+    $ret['class'] = extraire_attribut($img, 'class');
509
+    $ret['alt'] = extraire_attribut($img, 'alt');
510
+    $ret['style'] = extraire_attribut($img, 'style');
511
+    $ret['tag'] = $img;
512
+    if ($fonction_creation) {
513
+        $ret['reconstruction'] = $fonction_creation;
514
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
515
+        # cas de image_reduire qui finalement ne reduit pas l'image source
516
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
517
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
518
+    }
519
+
520
+    $ret = pipeline('image_preparer_filtre', [
521
+            'args' => [
522
+                'img' => $img,
523
+                'effet' => $effet,
524
+                'forcer_format' => $forcer_format,
525
+                'fonction_creation' => $fonction_creation,
526
+                'find_in_path' => $find_in_path,
527
+            ],
528
+            'data' => $ret
529
+        ]);
530
+
531
+    // une globale pour le debug en cas de crash memoire
532
+    $GLOBALS['derniere_image_calculee'] = $ret;
533
+
534
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
535
+    if ($term_fonction === 'svg') {
536
+        if ($creer && !$support_svg) {
537
+            process_image_svg_identite($ret);
538
+            $ret['creer'] = false;
539
+        }
540
+    }
541
+    else {
542
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
543
+            return false;
544
+        }
545
+    }
546
+
547
+    return $ret;
548 548
 }
549 549
 
550 550
 
@@ -552,54 +552,54 @@  discard block
 block discarded – undo
552 552
  * Extensions d’images acceptées en entrée
553 553
  */
554 554
 function _image_extensions_acceptees_en_entree(): array {
555
-	static $extensions = null;
556
-	if (empty($extensions)) {
557
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
558
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
559
-			// action=tester renseigne gd_formats et detecte le support de webp
560
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
561
-			$extensions = array_map('trim', $extensions);
562
-			$extensions = array_filter($extensions);
563
-			if (in_array('jpg', $extensions)) {
564
-				$extensions[] = 'jpeg';
565
-			}
566
-			$extensions = array_unique($extensions);
567
-		}
568
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
569
-	}
570
-
571
-	return $extensions;
555
+    static $extensions = null;
556
+    if (empty($extensions)) {
557
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
558
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
559
+            // action=tester renseigne gd_formats et detecte le support de webp
560
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
561
+            $extensions = array_map('trim', $extensions);
562
+            $extensions = array_filter($extensions);
563
+            if (in_array('jpg', $extensions)) {
564
+                $extensions[] = 'jpeg';
565
+            }
566
+            $extensions = array_unique($extensions);
567
+        }
568
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
569
+    }
570
+
571
+    return $extensions;
572 572
 }
573 573
 
574 574
 /**
575 575
  * Extensions d’images acceptées en sortie
576 576
  */
577 577
 function _image_extensions_acceptees_en_sortie(): array {
578
-	static $extensions = null;
579
-	if (empty($extensions)) {
580
-		$extensions = _image_extensions_acceptees_en_entree();
581
-		$extensions = array_diff($extensions, ['jpeg']);
582
-		if (in_array('gif', $extensions) && !function_exists('imagegif')) {
583
-			$extensions = array_diff($extensions, ['gif']);
584
-		}
585
-		if (in_array('webp', $extensions) && !function_exists('imagewebp')) {
586
-			$extensions = array_diff($extensions, ['webp']);
587
-		}
588
-	}
589
-
590
-	return $extensions;
578
+    static $extensions = null;
579
+    if (empty($extensions)) {
580
+        $extensions = _image_extensions_acceptees_en_entree();
581
+        $extensions = array_diff($extensions, ['jpeg']);
582
+        if (in_array('gif', $extensions) && !function_exists('imagegif')) {
583
+            $extensions = array_diff($extensions, ['gif']);
584
+        }
585
+        if (in_array('webp', $extensions) && !function_exists('imagewebp')) {
586
+            $extensions = array_diff($extensions, ['webp']);
587
+        }
588
+    }
589
+
590
+    return $extensions;
591 591
 }
592 592
 
593 593
 function _image_extension_normalisee($extension) {
594
-	$extension = strtolower($extension);
595
-	if ($extension === 'jpeg') {
596
-		$extension = 'jpg';
597
-	}
598
-	return $extension;
594
+    $extension = strtolower($extension);
595
+    if ($extension === 'jpeg') {
596
+        $extension = 'jpg';
597
+    }
598
+    return $extension;
599 599
 }
600 600
 
601 601
 function _image_extensions_conservent_transparence() {
602
-	return ['png', 'webp'];
602
+    return ['png', 'webp'];
603 603
 }
604 604
 
605 605
 
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
  * @return string
610 610
  */
611 611
 function _image_trouver_extension($path) {
612
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
613
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
614
-		return strtolower($regs[1]);
615
-	}
616
-	return '';
612
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
613
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
614
+        return strtolower($regs[1]);
615
+    }
616
+    return '';
617 617
 }
618 618
 
619 619
 /**
@@ -624,28 +624,28 @@  discard block
 block discarded – undo
624 624
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
625 625
  */
626 626
 function _image_trouver_extension_pertinente($path) {
627
-	$path = supprimer_timestamp($path);
628
-	$terminaison = _image_trouver_extension($path);
629
-	if ($terminaison == 'jpg') {
630
-		$terminaison = 'jpeg';
631
-	}
632
-
633
-	if (!file_exists($path)) {
634
-		return $terminaison;
635
-	}
636
-
637
-	if (!$info = @spip_getimagesize($path)) {
638
-		return $terminaison;
639
-	}
640
-
641
-	$mime = $info['mime'] ?? image_type_to_mime_type($info[2]);
642
-
643
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
644
-	if ($_terminaison && $_terminaison !== $terminaison) {
645
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
646
-		$terminaison = $_terminaison;
647
-	}
648
-	return $terminaison;
627
+    $path = supprimer_timestamp($path);
628
+    $terminaison = _image_trouver_extension($path);
629
+    if ($terminaison == 'jpg') {
630
+        $terminaison = 'jpeg';
631
+    }
632
+
633
+    if (!file_exists($path)) {
634
+        return $terminaison;
635
+    }
636
+
637
+    if (!$info = @spip_getimagesize($path)) {
638
+        return $terminaison;
639
+    }
640
+
641
+    $mime = $info['mime'] ?? image_type_to_mime_type($info[2]);
642
+
643
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
644
+    if ($_terminaison && $_terminaison !== $terminaison) {
645
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
646
+        $terminaison = $_terminaison;
647
+    }
648
+    return $terminaison;
649 649
 }
650 650
 
651 651
 /**
@@ -653,14 +653,14 @@  discard block
 block discarded – undo
653 653
  * @return string
654 654
  */
655 655
 function _image_trouver_extension_depuis_mime($mime) {
656
-	return match (strtolower($mime)) {
657
-		'image/png', 'image/x-png' => 'png',
658
-		'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg',
659
-		'image/gif' => 'gif',
660
-		'image/webp', 'image/x-webp' => 'webp',
661
-		'image/svg+xml' => 'svg',
662
-		default => '',
663
-	};
656
+    return match (strtolower($mime)) {
657
+        'image/png', 'image/x-png' => 'png',
658
+        'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg',
659
+        'image/gif' => 'gif',
660
+        'image/webp', 'image/x-webp' => 'webp',
661
+        'image/svg+xml' => 'svg',
662
+        default => '',
663
+    };
664 664
 }
665 665
 
666 666
 
@@ -680,18 +680,18 @@  discard block
 block discarded – undo
680 680
  *     Une ressource de type Image GD.
681 681
  */
682 682
 function _imagecreatefrom_func(string $func, string $filename) {
683
-	if (!function_exists($func)) {
684
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
685
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
686
-		return null;
687
-	}
688
-	$img = @$func($filename);
689
-	if (!$img) {
690
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
691
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
692
-		$img = imagecreate(10, 10);
693
-	}
694
-	return $img;
683
+    if (!function_exists($func)) {
684
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
685
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
686
+        return null;
687
+    }
688
+    $img = @$func($filename);
689
+    if (!$img) {
690
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
691
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
692
+        $img = imagecreate(10, 10);
693
+    }
694
+    return $img;
695 695
 }
696 696
 
697 697
 /**
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
  *     Une ressource de type Image GD.
708 708
  */
709 709
 function _imagecreatefromjpeg($filename) {
710
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
710
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
711 711
 }
712 712
 
713 713
 /**
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
  *     Une ressource de type Image GD.
724 724
  */
725 725
 function _imagecreatefrompng($filename) {
726
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
726
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
727 727
 }
728 728
 
729 729
 /**
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
  *     Une ressource de type Image GD.
740 740
  */
741 741
 function _imagecreatefromgif($filename) {
742
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
742
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
743 743
 }
744 744
 
745 745
 
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
  *     Une ressource de type Image GD.
757 757
  */
758 758
 function _imagecreatefromwebp($filename) {
759
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
759
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
760 760
 }
761 761
 
762 762
 /**
@@ -774,24 +774,24 @@  discard block
 block discarded – undo
774 774
  *     - true si une image est bien retournée.
775 775
  */
776 776
 function _image_imagepng($img, $fichier) {
777
-	if (!function_exists('imagepng')) {
778
-		return false;
779
-	}
780
-	$tmp = $fichier . '.tmp';
781
-	$ret = imagepng($img, $tmp);
782
-	if (file_exists($tmp)) {
783
-		$taille_test = @getimagesize($tmp);
784
-		if (empty($taille_test[0])) {
785
-			return false;
786
-		}
787
-
788
-		spip_unlink($fichier); // le fichier peut deja exister
789
-		@rename($tmp, $fichier);
790
-
791
-		return $ret;
792
-	}
793
-
794
-	return false;
777
+    if (!function_exists('imagepng')) {
778
+        return false;
779
+    }
780
+    $tmp = $fichier . '.tmp';
781
+    $ret = imagepng($img, $tmp);
782
+    if (file_exists($tmp)) {
783
+        $taille_test = @getimagesize($tmp);
784
+        if (empty($taille_test[0])) {
785
+            return false;
786
+        }
787
+
788
+        spip_unlink($fichier); // le fichier peut deja exister
789
+        @rename($tmp, $fichier);
790
+
791
+        return $ret;
792
+    }
793
+
794
+    return false;
795 795
 }
796 796
 
797 797
 /**
@@ -809,24 +809,24 @@  discard block
 block discarded – undo
809 809
  *     - true si une image est bien retournée.
810 810
  */
811 811
 function _image_imagegif($img, $fichier) {
812
-	if (!function_exists('imagegif')) {
813
-		return false;
814
-	}
815
-	$tmp = $fichier . '.tmp';
816
-	$ret = imagegif($img, $tmp);
817
-	if (file_exists($tmp)) {
818
-		$taille_test = @getimagesize($tmp);
819
-		if (empty($taille_test[0])) {
820
-			return false;
821
-		}
822
-
823
-		spip_unlink($fichier); // le fichier peut deja exister
824
-		@rename($tmp, $fichier);
825
-
826
-		return $ret;
827
-	}
828
-
829
-	return false;
812
+    if (!function_exists('imagegif')) {
813
+        return false;
814
+    }
815
+    $tmp = $fichier . '.tmp';
816
+    $ret = imagegif($img, $tmp);
817
+    if (file_exists($tmp)) {
818
+        $taille_test = @getimagesize($tmp);
819
+        if (empty($taille_test[0])) {
820
+            return false;
821
+        }
822
+
823
+        spip_unlink($fichier); // le fichier peut deja exister
824
+        @rename($tmp, $fichier);
825
+
826
+        return $ret;
827
+    }
828
+
829
+    return false;
830 830
 }
831 831
 
832 832
 /**
@@ -849,29 +849,29 @@  discard block
 block discarded – undo
849 849
  *     - true si une image est bien retournée.
850 850
  */
851 851
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
852
-	if (!function_exists('imagejpeg')) {
853
-		return false;
854
-	}
855
-	$tmp = $fichier . '.tmp';
852
+    if (!function_exists('imagejpeg')) {
853
+        return false;
854
+    }
855
+    $tmp = $fichier . '.tmp';
856 856
 
857
-	// Enable interlancing
858
-	imageinterlace($img, true);
857
+    // Enable interlancing
858
+    imageinterlace($img, true);
859 859
 
860
-	$ret = imagejpeg($img, $tmp, $qualite);
860
+    $ret = imagejpeg($img, $tmp, $qualite);
861 861
 
862
-	if (file_exists($tmp)) {
863
-		$taille_test = @getimagesize($tmp);
864
-		if (empty($taille_test[0])) {
865
-			return false;
866
-		}
862
+    if (file_exists($tmp)) {
863
+        $taille_test = @getimagesize($tmp);
864
+        if (empty($taille_test[0])) {
865
+            return false;
866
+        }
867 867
 
868
-		spip_unlink($fichier); // le fichier peut deja exister
869
-		@rename($tmp, $fichier);
868
+        spip_unlink($fichier); // le fichier peut deja exister
869
+        @rename($tmp, $fichier);
870 870
 
871
-		return $ret;
872
-	}
871
+        return $ret;
872
+    }
873 873
 
874
-	return false;
874
+    return false;
875 875
 }
876 876
 
877 877
 /**
@@ -889,9 +889,9 @@  discard block
 block discarded – undo
889 889
  *     true si le fichier a bien été créé ; false sinon.
890 890
  */
891 891
 function _image_imageico($img, $fichier) {
892
-	$gd_image_array = [$img];
892
+    $gd_image_array = [$img];
893 893
 
894
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
894
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
895 895
 }
896 896
 
897 897
 
@@ -910,24 +910,24 @@  discard block
 block discarded – undo
910 910
  *     - true si une image est bien retournée.
911 911
  */
912 912
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
913
-	if (!function_exists('imagewebp')) {
914
-		return false;
915
-	}
916
-	$tmp = $fichier . '.tmp';
917
-	$ret = imagewebp($img, $tmp, $qualite);
918
-	if (file_exists($tmp)) {
919
-		$taille_test = @getimagesize($tmp);
920
-		if (empty($taille_test[0])) {
921
-			return false;
922
-		}
923
-
924
-		spip_unlink($fichier); // le fichier peut deja exister
925
-		@rename($tmp, $fichier);
926
-
927
-		return $ret;
928
-	}
929
-
930
-	return false;
913
+    if (!function_exists('imagewebp')) {
914
+        return false;
915
+    }
916
+    $tmp = $fichier . '.tmp';
917
+    $ret = imagewebp($img, $tmp, $qualite);
918
+    if (file_exists($tmp)) {
919
+        $taille_test = @getimagesize($tmp);
920
+        if (empty($taille_test[0])) {
921
+            return false;
922
+        }
923
+
924
+        spip_unlink($fichier); // le fichier peut deja exister
925
+        @rename($tmp, $fichier);
926
+
927
+        return $ret;
928
+    }
929
+
930
+    return false;
931 931
 }
932 932
 
933 933
 /**
@@ -947,35 +947,35 @@  discard block
 block discarded – undo
947 947
  */
948 948
 function _image_imagesvg($img, $fichier) {
949 949
 
950
-	$tmp = $fichier . '.tmp';
951
-	if (!str_contains($img, '<')) {
952
-		$img = supprimer_timestamp($img);
953
-		if (!file_exists($img)) {
954
-			return false;
955
-		}
956
-		@copy($img, $tmp);
957
-		if (filesize($tmp) === filesize($img)) {
958
-			spip_unlink($fichier); // le fichier peut deja exister
959
-			@rename($tmp, $fichier);
960
-			return true;
961
-		}
962
-		return false;
963
-	}
964
-
965
-	file_put_contents($tmp, $img);
966
-	if (file_exists($tmp)) {
967
-		$taille_test = spip_getimagesize($tmp);
968
-		if (empty($taille_test[0])) {
969
-			return false;
970
-		}
971
-
972
-		spip_unlink($fichier); // le fichier peut deja exister
973
-		@rename($tmp, $fichier);
974
-
975
-		return true;
976
-	}
977
-
978
-	return false;
950
+    $tmp = $fichier . '.tmp';
951
+    if (!str_contains($img, '<')) {
952
+        $img = supprimer_timestamp($img);
953
+        if (!file_exists($img)) {
954
+            return false;
955
+        }
956
+        @copy($img, $tmp);
957
+        if (filesize($tmp) === filesize($img)) {
958
+            spip_unlink($fichier); // le fichier peut deja exister
959
+            @rename($tmp, $fichier);
960
+            return true;
961
+        }
962
+        return false;
963
+    }
964
+
965
+    file_put_contents($tmp, $img);
966
+    if (file_exists($tmp)) {
967
+        $taille_test = spip_getimagesize($tmp);
968
+        if (empty($taille_test[0])) {
969
+            return false;
970
+        }
971
+
972
+        spip_unlink($fichier); // le fichier peut deja exister
973
+        @rename($tmp, $fichier);
974
+
975
+        return true;
976
+    }
977
+
978
+    return false;
979 979
 }
980 980
 
981 981
 
@@ -1003,30 +1003,30 @@  discard block
 block discarded – undo
1003 1003
  *     - false sinon.
1004 1004
  */
1005 1005
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1006
-	if (is_null($fonction)) {
1007
-		$fonction = '_image_image' . $valeurs['format_dest'];
1008
-	}
1009
-	$ret = false;
1010
-	#un flag pour reperer les images gravees
1011
-	$lock = (
1012
-		!statut_effacer_images_temporaires('get')
1013
-		|| @file_exists($valeurs['fichier_dest'])
1014
-		&& !@file_exists($valeurs['fichier_dest'] . '.src')
1015
-	);
1016
-	if (
1017
-		function_exists($fonction)
1018
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1019
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1020
-		&& !$lock && @file_exists($valeurs['fichier_dest'])
1021
-	) {
1022
-		// dans tous les cas mettre a jour la taille de l'image finale
1023
-		[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1024
-		$valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1025
-		// pour la retrouver apres disparition
1026
-		ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1027
-	}
1028
-
1029
-	return $ret;
1006
+    if (is_null($fonction)) {
1007
+        $fonction = '_image_image' . $valeurs['format_dest'];
1008
+    }
1009
+    $ret = false;
1010
+    #un flag pour reperer les images gravees
1011
+    $lock = (
1012
+        !statut_effacer_images_temporaires('get')
1013
+        || @file_exists($valeurs['fichier_dest'])
1014
+        && !@file_exists($valeurs['fichier_dest'] . '.src')
1015
+    );
1016
+    if (
1017
+        function_exists($fonction)
1018
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1019
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1020
+        && !$lock && @file_exists($valeurs['fichier_dest'])
1021
+    ) {
1022
+        // dans tous les cas mettre a jour la taille de l'image finale
1023
+        [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1024
+        $valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1025
+        // pour la retrouver apres disparition
1026
+        ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1027
+    }
1028
+
1029
+    return $ret;
1030 1030
 }
1031 1031
 
1032 1032
 /**
@@ -1039,28 +1039,28 @@  discard block
 block discarded – undo
1039 1039
  *     Chemin vers le fichier manquant
1040 1040
  **/
1041 1041
 function reconstruire_image_intermediaire($fichier_manquant) {
1042
-	$source = null;
1043
-	$reconstruire = [];
1044
-	$fichier = $fichier_manquant;
1045
-	while (
1046
-		!str_contains($fichier, '://')
1047
-		&& !@file_exists($fichier)
1048
-		&& lire_fichier($src = "$fichier.src", $source)
1049
-		&& ($valeurs = unserialize($source))
1050
-		&& ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1051
-	) {
1052
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1053
-		$reconstruire[] = $valeurs['reconstruction'];
1054
-	}
1055
-	while (count($reconstruire)) {
1056
-		$r = array_pop($reconstruire);
1057
-		$fonction = $r[0];
1058
-		$args = $r[1];
1059
-		$fonction(...$args);
1060
-	}
1061
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1062
-	// mais l'on peut nettoyer les miettes de sa creation
1063
-	ramasse_miettes($fichier_manquant);
1042
+    $source = null;
1043
+    $reconstruire = [];
1044
+    $fichier = $fichier_manquant;
1045
+    while (
1046
+        !str_contains($fichier, '://')
1047
+        && !@file_exists($fichier)
1048
+        && lire_fichier($src = "$fichier.src", $source)
1049
+        && ($valeurs = unserialize($source))
1050
+        && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1051
+    ) {
1052
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1053
+        $reconstruire[] = $valeurs['reconstruction'];
1054
+    }
1055
+    while (count($reconstruire)) {
1056
+        $r = array_pop($reconstruire);
1057
+        $fonction = $r[0];
1058
+        $args = $r[1];
1059
+        $fonction(...$args);
1060
+    }
1061
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1062
+    // mais l'on peut nettoyer les miettes de sa creation
1063
+    ramasse_miettes($fichier_manquant);
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1080,26 +1080,26 @@  discard block
 block discarded – undo
1080 1080
  *     Chemin du fichier d'image calculé
1081 1081
  **/
1082 1082
 function ramasse_miettes($fichier) {
1083
-	$source = null;
1084
-	if (
1085
-		str_contains($fichier, '://')
1086
-		|| !lire_fichier($src = "$fichier.src", $source)
1087
-		|| !$valeurs = unserialize($source)
1088
-	) {
1089
-		return;
1090
-	}
1091
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1092
-	while (
1093
-		($fichier = $valeurs['fichier'])
1094
-		&& str_starts_with($fichier, _DIR_VAR)
1095
-		&& lire_fichier($src = "$fichier.src", $source)
1096
-		&& ($valeurs = unserialize($source))  # et valide
1097
-	) {
1098
-		# on efface le fichier
1099
-		spip_unlink($fichier);
1100
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1101
-		#spip_unlink($src);
1102
-	}
1083
+    $source = null;
1084
+    if (
1085
+        str_contains($fichier, '://')
1086
+        || !lire_fichier($src = "$fichier.src", $source)
1087
+        || !$valeurs = unserialize($source)
1088
+    ) {
1089
+        return;
1090
+    }
1091
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1092
+    while (
1093
+        ($fichier = $valeurs['fichier'])
1094
+        && str_starts_with($fichier, _DIR_VAR)
1095
+        && lire_fichier($src = "$fichier.src", $source)
1096
+        && ($valeurs = unserialize($source))  # et valide
1097
+    ) {
1098
+        # on efface le fichier
1099
+        spip_unlink($fichier);
1100
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1101
+        #spip_unlink($src);
1102
+    }
1103 1103
 }
1104 1104
 
1105 1105
 
@@ -1124,33 +1124,33 @@  discard block
 block discarded – undo
1124 1124
  *     Code HTML de l'image
1125 1125
  **/
1126 1126
 function image_graver($img) {
1127
-	// appeler le filtre post_image_filtrer qui permet de faire
1128
-	// des traitements auto a la fin d'une serie de filtres
1129
-	$img = pipeline('post_image_filtrer', $img);
1130
-
1131
-	$fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? '');
1132
-	if (($p = strpos($fichier, '?')) !== false) {
1133
-		$fichier = substr($fichier, 0, $p);
1134
-	}
1135
-	if (strlen($fichier) < 1 && !str_starts_with($img, '<img ')) {
1136
-		$fichier = $img;
1137
-	}
1138
-	if (strlen($fichier)) {
1139
-		# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1140
-		# et qu'il ne s'agit pas d'une URL
1141
-		if (!str_contains($fichier, '://') && !@file_exists($fichier)) {
1142
-			reconstruire_image_intermediaire($fichier);
1143
-		}
1144
-		ramasse_miettes($fichier);
1145
-
1146
-		// ajouter le timestamp si besoin
1147
-		if (!str_contains($fichier_ori, '?')) {
1148
-			// on utilise str_replace pour attraper le onmouseover des logo si besoin
1149
-			$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1150
-		}
1151
-	}
1152
-
1153
-	return $img;
1127
+    // appeler le filtre post_image_filtrer qui permet de faire
1128
+    // des traitements auto a la fin d'une serie de filtres
1129
+    $img = pipeline('post_image_filtrer', $img);
1130
+
1131
+    $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? '');
1132
+    if (($p = strpos($fichier, '?')) !== false) {
1133
+        $fichier = substr($fichier, 0, $p);
1134
+    }
1135
+    if (strlen($fichier) < 1 && !str_starts_with($img, '<img ')) {
1136
+        $fichier = $img;
1137
+    }
1138
+    if (strlen($fichier)) {
1139
+        # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1140
+        # et qu'il ne s'agit pas d'une URL
1141
+        if (!str_contains($fichier, '://') && !@file_exists($fichier)) {
1142
+            reconstruire_image_intermediaire($fichier);
1143
+        }
1144
+        ramasse_miettes($fichier);
1145
+
1146
+        // ajouter le timestamp si besoin
1147
+        if (!str_contains($fichier_ori, '?')) {
1148
+            // on utilise str_replace pour attraper le onmouseover des logo si besoin
1149
+            $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1150
+        }
1151
+    }
1152
+
1153
+    return $img;
1154 1154
 }
1155 1155
 
1156 1156
 /**
@@ -1177,32 +1177,32 @@  discard block
 block discarded – undo
1177 1177
  *     Code html modifié de la balise.
1178 1178
  **/
1179 1179
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1180
-	if ($style === false) {
1181
-		$style = extraire_attribut($tag, 'style');
1182
-	}
1183
-
1184
-	// enlever le width et height du style
1185
-	if ($style) {
1186
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1187
-	}
1188
-	if ($style && $style[0] === ';') {
1189
-		$style = substr($style, 1);
1190
-	}
1191
-
1192
-	// mettre des attributs de width et height sur les images,
1193
-	// ca accelere le rendu du navigateur
1194
-	// ca permet aux navigateurs de reserver la bonne taille
1195
-	// quand on a desactive l'affichage des images.
1196
-	$tag = inserer_attribut($tag, 'width', round($width));
1197
-	$tag = inserer_attribut($tag, 'height', round($height));
1198
-
1199
-	// attributs deprecies. Transformer en CSS
1200
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1201
-		$style = "margin:{$espace}px;" . $style;
1202
-		$tag = inserer_attribut($tag, 'hspace', '');
1203
-	}
1204
-
1205
-	return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style);
1180
+    if ($style === false) {
1181
+        $style = extraire_attribut($tag, 'style');
1182
+    }
1183
+
1184
+    // enlever le width et height du style
1185
+    if ($style) {
1186
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1187
+    }
1188
+    if ($style && $style[0] === ';') {
1189
+        $style = substr($style, 1);
1190
+    }
1191
+
1192
+    // mettre des attributs de width et height sur les images,
1193
+    // ca accelere le rendu du navigateur
1194
+    // ca permet aux navigateurs de reserver la bonne taille
1195
+    // quand on a desactive l'affichage des images.
1196
+    $tag = inserer_attribut($tag, 'width', round($width));
1197
+    $tag = inserer_attribut($tag, 'height', round($height));
1198
+
1199
+    // attributs deprecies. Transformer en CSS
1200
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1201
+        $style = "margin:{$espace}px;" . $style;
1202
+        $tag = inserer_attribut($tag, 'hspace', '');
1203
+    }
1204
+
1205
+    return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style);
1206 1206
 }
1207 1207
 
1208 1208
 
@@ -1228,70 +1228,70 @@  discard block
 block discarded – undo
1228 1228
  *     Retourne le code HTML de l'image
1229 1229
  **/
1230 1230
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1231
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1232
-
1233
-	// fermer les tags img pas bien fermes;
1234
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1235
-
1236
-	// le style
1237
-	$style = $valeurs['style'];
1238
-	if (isset($surcharge['style'])) {
1239
-		$style = $surcharge['style'];
1240
-		unset($surcharge['style']);
1241
-	}
1242
-
1243
-	// traiter specifiquement la largeur et la hauteur
1244
-	$width = $valeurs['largeur'];
1245
-	if (isset($surcharge['width'])) {
1246
-		$width = $surcharge['width'];
1247
-		unset($surcharge['width']);
1248
-	}
1249
-	$height = $valeurs['hauteur'];
1250
-	if (isset($surcharge['height'])) {
1251
-		$height = $surcharge['height'];
1252
-		unset($surcharge['height']);
1253
-	}
1254
-
1255
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1256
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1257
-	// on remplace toute les ref a src dans le tag
1258
-	$src = extraire_attribut($tag, 'src');
1259
-	if (isset($surcharge['src'])) {
1260
-		$tag = str_replace($src, $surcharge['src'], $tag);
1261
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1262
-		// pas garanti comme methode, mais mieux que rien
1263
-		if (str_contains($src, '&')) {
1264
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1265
-		}
1266
-		$src = $surcharge['src'];
1267
-		unset($surcharge['src']);
1268
-	}
1269
-
1270
-	$class = $valeurs['class'];
1271
-	if (isset($surcharge['class'])) {
1272
-		$class = $surcharge['class'];
1273
-		unset($surcharge['class']);
1274
-	}
1275
-	if (is_scalar($class) && strlen($class)) {
1276
-		$tag = inserer_attribut($tag, 'class', $class);
1277
-	}
1278
-
1279
-	if ($surcharge !== []) {
1280
-		foreach ($surcharge as $attribut => $valeur) {
1281
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1282
-		}
1283
-	}
1284
-
1285
-	return pipeline(
1286
-		'image_ecrire_tag_finir',
1287
-		[
1288
-			'args' => [
1289
-				'valeurs' => $valeurs,
1290
-				'surcharge' => $surcharge,
1291
-			],
1292
-			'data' => $tag
1293
-		]
1294
-	);
1231
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1232
+
1233
+    // fermer les tags img pas bien fermes;
1234
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1235
+
1236
+    // le style
1237
+    $style = $valeurs['style'];
1238
+    if (isset($surcharge['style'])) {
1239
+        $style = $surcharge['style'];
1240
+        unset($surcharge['style']);
1241
+    }
1242
+
1243
+    // traiter specifiquement la largeur et la hauteur
1244
+    $width = $valeurs['largeur'];
1245
+    if (isset($surcharge['width'])) {
1246
+        $width = $surcharge['width'];
1247
+        unset($surcharge['width']);
1248
+    }
1249
+    $height = $valeurs['hauteur'];
1250
+    if (isset($surcharge['height'])) {
1251
+        $height = $surcharge['height'];
1252
+        unset($surcharge['height']);
1253
+    }
1254
+
1255
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1256
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1257
+    // on remplace toute les ref a src dans le tag
1258
+    $src = extraire_attribut($tag, 'src');
1259
+    if (isset($surcharge['src'])) {
1260
+        $tag = str_replace($src, $surcharge['src'], $tag);
1261
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1262
+        // pas garanti comme methode, mais mieux que rien
1263
+        if (str_contains($src, '&')) {
1264
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1265
+        }
1266
+        $src = $surcharge['src'];
1267
+        unset($surcharge['src']);
1268
+    }
1269
+
1270
+    $class = $valeurs['class'];
1271
+    if (isset($surcharge['class'])) {
1272
+        $class = $surcharge['class'];
1273
+        unset($surcharge['class']);
1274
+    }
1275
+    if (is_scalar($class) && strlen($class)) {
1276
+        $tag = inserer_attribut($tag, 'class', $class);
1277
+    }
1278
+
1279
+    if ($surcharge !== []) {
1280
+        foreach ($surcharge as $attribut => $valeur) {
1281
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1282
+        }
1283
+    }
1284
+
1285
+    return pipeline(
1286
+        'image_ecrire_tag_finir',
1287
+        [
1288
+            'args' => [
1289
+                'valeurs' => $valeurs,
1290
+                'surcharge' => $surcharge,
1291
+            ],
1292
+            'data' => $tag
1293
+        ]
1294
+    );
1295 1295
 }
1296 1296
 
1297 1297
 /**
@@ -1314,268 +1314,268 @@  discard block
 block discarded – undo
1314 1314
  *     Description de l'image, sinon null.
1315 1315
  **/
1316 1316
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1317
-	$srcHeight = null;
1318
-	$retour = [];
1319
-	// ordre de preference des formats graphiques pour creer les vignettes
1320
-	// le premier format disponible, selon la methode demandee, est utilise
1321
-	$image = $valeurs['fichier'];
1322
-	$format = $valeurs['format_source'];
1323
-	$destdir = dirname($valeurs['fichier_dest']);
1324
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1325
-
1326
-	$format_sortie = $valeurs['format_dest'];
1327
-
1328
-	if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1329
-		$process = $GLOBALS['meta']['image_process'];
1330
-	}
1331
-
1332
-	// si le doc n'est pas une image dans un format accetpable, refuser
1333
-	if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) {
1334
-		return;
1335
-	}
1336
-	$destination = "$destdir/$destfile";
1337
-
1338
-	// calculer la taille
1339
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1340
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1341
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1342
-		}
1343
-	} elseif ($process == 'convert' || $process == 'imagick') {
1344
-		$destWidth = $maxWidth;
1345
-		$destHeight = $maxHeight;
1346
-	} else {
1347
-		spip_log("echec $process sur $image");
1348
-
1349
-		return;
1350
-	}
1351
-
1352
-	$vignette = '';
1353
-
1354
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1355
-	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1356
-		$vignette = $destination . '.' . $format;
1357
-		@copy($image, $vignette);
1358
-	}
1359
-
1360
-	elseif ($valeurs['format_source'] === 'svg') {
1361
-		include_spip('inc/svg');
1362
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1363
-			$format_sortie = 'svg';
1364
-			$vignette = $destination . '.' . $format_sortie;
1365
-			$valeurs['fichier_dest'] = $vignette;
1366
-			_image_gd_output($svg, $valeurs);
1367
-		}
1368
-	}
1369
-
1370
-	// imagemagick en ligne de commande
1371
-	elseif ($process == 'convert') {
1372
-		if (!defined('_CONVERT_COMMAND')) {
1373
-			define('_CONVERT_COMMAND', 'convert');
1374
-		} // Securite : mes_options.php peut preciser le chemin absolu
1375
-		if (!defined('_RESIZE_COMMAND')) {
1376
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1377
-		}
1378
-		$vignette = $destination . '.' . $format_sortie;
1379
-		$commande = str_replace(
1380
-			['%x', '%y', '%src', '%dest'],
1381
-			[
1382
-				$destWidth,
1383
-				$destHeight,
1384
-				escapeshellcmd($image),
1385
-				escapeshellcmd($vignette)
1386
-			],
1387
-			_RESIZE_COMMAND
1388
-		);
1389
-		spip_log($commande);
1390
-		exec($commande);
1391
-		if (!@file_exists($vignette)) {
1392
-			spip_log("echec convert sur $vignette");
1393
-
1394
-			return;  // echec commande
1395
-		}
1396
-	}
1397
-
1398
-	// php5 imagemagick
1399
-	elseif ($process == 'imagick') {
1400
-		if (!class_exists(\Imagick::class)) {
1401
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1402
-
1403
-			return;
1404
-		}
1405
-
1406
-		// chemin compatible Windows
1407
-		$output = realpath(dirname($destination));
1408
-		if (!$output) {
1409
-			return;
1410
-		}
1411
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1412
-
1413
-		$imagick = new Imagick();
1414
-		$imagick->readImage(realpath($image));
1415
-		$imagick->resizeImage(
1416
-			$destWidth,
1417
-			$destHeight,
1418
-			Imagick::FILTER_LANCZOS,
1419
-			1
1420
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1421
-		$imagick->writeImage($vignette);
1422
-
1423
-		if (!@file_exists($vignette)) {
1424
-			spip_log("echec imagick sur $vignette");
1425
-
1426
-			return;
1427
-		}
1428
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1429
-		$vignette = $destination . '.' . $format_sortie;
1430
-	}
1431
-
1432
-	// netpbm
1433
-	elseif ($process == 'netpbm') {
1434
-		if (!defined('_PNMSCALE_COMMAND')) {
1435
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1436
-		} // Securite : mes_options.php peut preciser le chemin absolu
1437
-		if (_PNMSCALE_COMMAND == '') {
1438
-			return;
1439
-		}
1440
-		$vignette = $destination . '.' . $format_sortie;
1441
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1442
-		if ($format == 'jpg') {
1443
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1444
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1445
-			if (!($s = @filesize($vignette))) {
1446
-				spip_unlink($vignette);
1447
-			}
1448
-			if (!@file_exists($vignette)) {
1449
-				spip_log("echec netpbm-jpg sur $vignette");
1450
-
1451
-				return;
1452
-			}
1453
-		} else {
1454
-			if ($format == 'gif') {
1455
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1456
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1457
-				if (!($s = @filesize($vignette))) {
1458
-					spip_unlink($vignette);
1459
-				}
1460
-				if (!@file_exists($vignette)) {
1461
-					spip_log("echec netpbm-gif sur $vignette");
1462
-
1463
-					return;
1464
-				}
1465
-			} else {
1466
-				if ($format == 'png') {
1467
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1468
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1469
-					if (!($s = @filesize($vignette))) {
1470
-						spip_unlink($vignette);
1471
-					}
1472
-					if (!@file_exists($vignette)) {
1473
-						spip_log("echec netpbm-png sur $vignette");
1474
-
1475
-						return;
1476
-					}
1477
-				}
1478
-			}
1479
-		}
1480
-	}
1481
-
1482
-	// gd ou gd2
1483
-	elseif ($process === 'gd2') {
1484
-		if (!function_exists('gd_info')) {
1485
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1486
-
1487
-			return;
1488
-		}
1489
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1490
-			spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1491
-
1492
-			return;
1493
-		}
1494
-		$destFormat = $format_sortie;
1495
-		if (!$destFormat) {
1496
-			spip_log("pas de format pour $image");
1497
-
1498
-			return;
1499
-		}
1500
-
1501
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1502
-		if (!function_exists($fonction_imagecreatefrom)) {
1503
-			return;
1504
-		}
1505
-		$srcImage = @$fonction_imagecreatefrom($image);
1506
-		if (!$srcImage) {
1507
-			spip_log('echec gd2');
1508
-
1509
-			return;
1510
-		}
1511
-
1512
-		// Initialisation de l'image destination
1513
-		$destImage = null;
1514
-		if ($process == 'gd2' && $destFormat != 'gif') {
1515
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1516
-		}
1517
-		if (!$destImage) {
1518
-			$destImage = ImageCreate($destWidth, $destHeight);
1519
-		}
1520
-
1521
-		// Recopie de l'image d'origine avec adaptation de la taille
1522
-		$ok = false;
1523
-		if ($process == 'gd2' && function_exists('ImageCopyResampled')) {
1524
-			if ($format == 'gif') {
1525
-				// Si un GIF est transparent,
1526
-				// fabriquer un PNG transparent
1527
-				$transp = imagecolortransparent($srcImage);
1528
-				if ($transp > 0) {
1529
-					$destFormat = 'png';
1530
-				}
1531
-			}
1532
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1533
-				// Conserver la transparence
1534
-				if (function_exists('imageAntiAlias')) {
1535
-					imageAntiAlias($destImage, true);
1536
-				}
1537
-				@imagealphablending($destImage, false);
1538
-				@imagesavealpha($destImage, true);
1539
-			}
1540
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1541
-		}
1542
-		if (!$ok) {
1543
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1544
-		}
1545
-
1546
-		// Sauvegarde de l'image destination
1547
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1548
-		$valeurs['format_dest'] = $format = $destFormat;
1549
-		_image_gd_output($destImage, $valeurs);
1550
-
1551
-		if ($srcImage) {
1552
-			ImageDestroy($srcImage);
1553
-		}
1554
-		ImageDestroy($destImage);
1555
-	}
1556
-
1557
-	if (!$vignette || !$size = @spip_getimagesize($vignette)) {
1558
-		$size = [$destWidth, $destHeight];
1559
-	}
1560
-
1561
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1562
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1563
-	if ($size[0] < 1) {
1564
-		$size[0] = $destWidth;
1565
-	}
1566
-	if ($size[1] < 1) {
1567
-		$size[1] = $destHeight;
1568
-	}
1569
-
1570
-	$retour['width'] = $largeur = $size[0];
1571
-	$retour['height'] = $hauteur = $size[1];
1572
-
1573
-	$retour['fichier'] = $vignette;
1574
-	$retour['format'] = $format;
1575
-	$retour['date'] = @filemtime($vignette);
1576
-
1577
-	// renvoyer l'image
1578
-	return $retour;
1317
+    $srcHeight = null;
1318
+    $retour = [];
1319
+    // ordre de preference des formats graphiques pour creer les vignettes
1320
+    // le premier format disponible, selon la methode demandee, est utilise
1321
+    $image = $valeurs['fichier'];
1322
+    $format = $valeurs['format_source'];
1323
+    $destdir = dirname($valeurs['fichier_dest']);
1324
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1325
+
1326
+    $format_sortie = $valeurs['format_dest'];
1327
+
1328
+    if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1329
+        $process = $GLOBALS['meta']['image_process'];
1330
+    }
1331
+
1332
+    // si le doc n'est pas une image dans un format accetpable, refuser
1333
+    if (!$force && !in_array($format, formats_image_acceptables($process === 'gd2'))) {
1334
+        return;
1335
+    }
1336
+    $destination = "$destdir/$destfile";
1337
+
1338
+    // calculer la taille
1339
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1340
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1341
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1342
+        }
1343
+    } elseif ($process == 'convert' || $process == 'imagick') {
1344
+        $destWidth = $maxWidth;
1345
+        $destHeight = $maxHeight;
1346
+    } else {
1347
+        spip_log("echec $process sur $image");
1348
+
1349
+        return;
1350
+    }
1351
+
1352
+    $vignette = '';
1353
+
1354
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1355
+    if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1356
+        $vignette = $destination . '.' . $format;
1357
+        @copy($image, $vignette);
1358
+    }
1359
+
1360
+    elseif ($valeurs['format_source'] === 'svg') {
1361
+        include_spip('inc/svg');
1362
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1363
+            $format_sortie = 'svg';
1364
+            $vignette = $destination . '.' . $format_sortie;
1365
+            $valeurs['fichier_dest'] = $vignette;
1366
+            _image_gd_output($svg, $valeurs);
1367
+        }
1368
+    }
1369
+
1370
+    // imagemagick en ligne de commande
1371
+    elseif ($process == 'convert') {
1372
+        if (!defined('_CONVERT_COMMAND')) {
1373
+            define('_CONVERT_COMMAND', 'convert');
1374
+        } // Securite : mes_options.php peut preciser le chemin absolu
1375
+        if (!defined('_RESIZE_COMMAND')) {
1376
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1377
+        }
1378
+        $vignette = $destination . '.' . $format_sortie;
1379
+        $commande = str_replace(
1380
+            ['%x', '%y', '%src', '%dest'],
1381
+            [
1382
+                $destWidth,
1383
+                $destHeight,
1384
+                escapeshellcmd($image),
1385
+                escapeshellcmd($vignette)
1386
+            ],
1387
+            _RESIZE_COMMAND
1388
+        );
1389
+        spip_log($commande);
1390
+        exec($commande);
1391
+        if (!@file_exists($vignette)) {
1392
+            spip_log("echec convert sur $vignette");
1393
+
1394
+            return;  // echec commande
1395
+        }
1396
+    }
1397
+
1398
+    // php5 imagemagick
1399
+    elseif ($process == 'imagick') {
1400
+        if (!class_exists(\Imagick::class)) {
1401
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1402
+
1403
+            return;
1404
+        }
1405
+
1406
+        // chemin compatible Windows
1407
+        $output = realpath(dirname($destination));
1408
+        if (!$output) {
1409
+            return;
1410
+        }
1411
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1412
+
1413
+        $imagick = new Imagick();
1414
+        $imagick->readImage(realpath($image));
1415
+        $imagick->resizeImage(
1416
+            $destWidth,
1417
+            $destHeight,
1418
+            Imagick::FILTER_LANCZOS,
1419
+            1
1420
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1421
+        $imagick->writeImage($vignette);
1422
+
1423
+        if (!@file_exists($vignette)) {
1424
+            spip_log("echec imagick sur $vignette");
1425
+
1426
+            return;
1427
+        }
1428
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1429
+        $vignette = $destination . '.' . $format_sortie;
1430
+    }
1431
+
1432
+    // netpbm
1433
+    elseif ($process == 'netpbm') {
1434
+        if (!defined('_PNMSCALE_COMMAND')) {
1435
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1436
+        } // Securite : mes_options.php peut preciser le chemin absolu
1437
+        if (_PNMSCALE_COMMAND == '') {
1438
+            return;
1439
+        }
1440
+        $vignette = $destination . '.' . $format_sortie;
1441
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1442
+        if ($format == 'jpg') {
1443
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1444
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1445
+            if (!($s = @filesize($vignette))) {
1446
+                spip_unlink($vignette);
1447
+            }
1448
+            if (!@file_exists($vignette)) {
1449
+                spip_log("echec netpbm-jpg sur $vignette");
1450
+
1451
+                return;
1452
+            }
1453
+        } else {
1454
+            if ($format == 'gif') {
1455
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1456
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1457
+                if (!($s = @filesize($vignette))) {
1458
+                    spip_unlink($vignette);
1459
+                }
1460
+                if (!@file_exists($vignette)) {
1461
+                    spip_log("echec netpbm-gif sur $vignette");
1462
+
1463
+                    return;
1464
+                }
1465
+            } else {
1466
+                if ($format == 'png') {
1467
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1468
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1469
+                    if (!($s = @filesize($vignette))) {
1470
+                        spip_unlink($vignette);
1471
+                    }
1472
+                    if (!@file_exists($vignette)) {
1473
+                        spip_log("echec netpbm-png sur $vignette");
1474
+
1475
+                        return;
1476
+                    }
1477
+                }
1478
+            }
1479
+        }
1480
+    }
1481
+
1482
+    // gd ou gd2
1483
+    elseif ($process === 'gd2') {
1484
+        if (!function_exists('gd_info')) {
1485
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1486
+
1487
+            return;
1488
+        }
1489
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1490
+            spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1491
+
1492
+            return;
1493
+        }
1494
+        $destFormat = $format_sortie;
1495
+        if (!$destFormat) {
1496
+            spip_log("pas de format pour $image");
1497
+
1498
+            return;
1499
+        }
1500
+
1501
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1502
+        if (!function_exists($fonction_imagecreatefrom)) {
1503
+            return;
1504
+        }
1505
+        $srcImage = @$fonction_imagecreatefrom($image);
1506
+        if (!$srcImage) {
1507
+            spip_log('echec gd2');
1508
+
1509
+            return;
1510
+        }
1511
+
1512
+        // Initialisation de l'image destination
1513
+        $destImage = null;
1514
+        if ($process == 'gd2' && $destFormat != 'gif') {
1515
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1516
+        }
1517
+        if (!$destImage) {
1518
+            $destImage = ImageCreate($destWidth, $destHeight);
1519
+        }
1520
+
1521
+        // Recopie de l'image d'origine avec adaptation de la taille
1522
+        $ok = false;
1523
+        if ($process == 'gd2' && function_exists('ImageCopyResampled')) {
1524
+            if ($format == 'gif') {
1525
+                // Si un GIF est transparent,
1526
+                // fabriquer un PNG transparent
1527
+                $transp = imagecolortransparent($srcImage);
1528
+                if ($transp > 0) {
1529
+                    $destFormat = 'png';
1530
+                }
1531
+            }
1532
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1533
+                // Conserver la transparence
1534
+                if (function_exists('imageAntiAlias')) {
1535
+                    imageAntiAlias($destImage, true);
1536
+                }
1537
+                @imagealphablending($destImage, false);
1538
+                @imagesavealpha($destImage, true);
1539
+            }
1540
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1541
+        }
1542
+        if (!$ok) {
1543
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1544
+        }
1545
+
1546
+        // Sauvegarde de l'image destination
1547
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1548
+        $valeurs['format_dest'] = $format = $destFormat;
1549
+        _image_gd_output($destImage, $valeurs);
1550
+
1551
+        if ($srcImage) {
1552
+            ImageDestroy($srcImage);
1553
+        }
1554
+        ImageDestroy($destImage);
1555
+    }
1556
+
1557
+    if (!$vignette || !$size = @spip_getimagesize($vignette)) {
1558
+        $size = [$destWidth, $destHeight];
1559
+    }
1560
+
1561
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1562
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1563
+    if ($size[0] < 1) {
1564
+        $size[0] = $destWidth;
1565
+    }
1566
+    if ($size[1] < 1) {
1567
+        $size[1] = $destHeight;
1568
+    }
1569
+
1570
+    $retour['width'] = $largeur = $size[0];
1571
+    $retour['height'] = $hauteur = $size[1];
1572
+
1573
+    $retour['fichier'] = $vignette;
1574
+    $retour['format'] = $format;
1575
+    $retour['date'] = @filemtime($vignette);
1576
+
1577
+    // renvoyer l'image
1578
+    return $retour;
1579 1579
 }
1580 1580
 
1581 1581
 /**
@@ -1595,25 +1595,25 @@  discard block
 block discarded – undo
1595 1595
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1596 1596
  **/
1597 1597
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1598
-	$ratioWidth = $srcWidth / $maxWidth;
1599
-	$ratioHeight = $srcHeight / $maxHeight;
1600
-
1601
-	if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1602
-		$destWidth = $srcWidth;
1603
-		$destHeight = $srcHeight;
1604
-	} elseif ($ratioWidth < $ratioHeight) {
1605
-		$destWidth = $srcWidth / $ratioHeight;
1606
-		$destHeight = $maxHeight;
1607
-	} else {
1608
-		$destWidth = $maxWidth;
1609
-		$destHeight = $srcHeight / $ratioWidth;
1610
-	}
1611
-
1612
-	return [
1613
-		(int) round($destWidth),
1614
-		(int) round($destHeight),
1615
-		max($ratioWidth, $ratioHeight)
1616
-	];
1598
+    $ratioWidth = $srcWidth / $maxWidth;
1599
+    $ratioHeight = $srcHeight / $maxHeight;
1600
+
1601
+    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1602
+        $destWidth = $srcWidth;
1603
+        $destHeight = $srcHeight;
1604
+    } elseif ($ratioWidth < $ratioHeight) {
1605
+        $destWidth = $srcWidth / $ratioHeight;
1606
+        $destHeight = $maxHeight;
1607
+    } else {
1608
+        $destWidth = $maxWidth;
1609
+        $destHeight = $srcHeight / $ratioWidth;
1610
+    }
1611
+
1612
+    return [
1613
+        (int) round($destWidth),
1614
+        (int) round($destHeight),
1615
+        max($ratioWidth, $ratioHeight)
1616
+    ];
1617 1617
 }
1618 1618
 
1619 1619
 /**
@@ -1633,25 +1633,25 @@  discard block
 block discarded – undo
1633 1633
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1634 1634
  **/
1635 1635
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1636
-	$ratioWidth = $srcWidth / $maxWidth;
1637
-	$ratioHeight = $srcHeight / $maxHeight;
1638
-
1639
-	if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1640
-		$destWidth = $srcWidth;
1641
-		$destHeight = $srcHeight;
1642
-	} elseif ($ratioWidth > $ratioHeight) {
1643
-		$destWidth = $srcWidth / $ratioHeight;
1644
-		$destHeight = $maxHeight;
1645
-	} else {
1646
-		$destWidth = $maxWidth;
1647
-		$destHeight = $srcHeight / $ratioWidth;
1648
-	}
1649
-
1650
-	return [
1651
-		(int) round($destWidth),
1652
-		(int) round($destHeight),
1653
-		min($ratioWidth, $ratioHeight)
1654
-	];
1636
+    $ratioWidth = $srcWidth / $maxWidth;
1637
+    $ratioHeight = $srcHeight / $maxHeight;
1638
+
1639
+    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1640
+        $destWidth = $srcWidth;
1641
+        $destHeight = $srcHeight;
1642
+    } elseif ($ratioWidth > $ratioHeight) {
1643
+        $destWidth = $srcWidth / $ratioHeight;
1644
+        $destHeight = $maxHeight;
1645
+    } else {
1646
+        $destWidth = $maxWidth;
1647
+        $destHeight = $srcHeight / $ratioWidth;
1648
+    }
1649
+
1650
+    return [
1651
+        (int) round($destWidth),
1652
+        (int) round($destHeight),
1653
+        min($ratioWidth, $ratioHeight)
1654
+    ];
1655 1655
 }
1656 1656
 
1657 1657
 
@@ -1664,12 +1664,12 @@  discard block
 block discarded – undo
1664 1664
  * @return string
1665 1665
  */
1666 1666
 function process_image_svg_identite($image) {
1667
-	if ($image['creer']) {
1668
-		$source = $image['fichier'];
1669
-		_image_gd_output($source, $image);
1670
-	}
1667
+    if ($image['creer']) {
1668
+        $source = $image['fichier'];
1669
+        _image_gd_output($source, $image);
1670
+    }
1671 1671
 
1672
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1672
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1673 1673
 }
1674 1674
 
1675 1675
 
@@ -1702,102 +1702,102 @@  discard block
 block discarded – undo
1702 1702
  *     Code HTML de la balise img produite
1703 1703
  **/
1704 1704
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1705
-	$image = false;
1706
-	if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1707
-		$process = $GLOBALS['meta']['image_process'];
1708
-	}
1709
-	# determiner le format de sortie
1710
-	$format_sortie = false; // le choix par defaut sera bon
1711
-	if ($process === 'netpbm') {
1712
-		$format_sortie = 'jpg';
1713
-	} elseif ($process === 'gd2') {
1714
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1715
-		// on verifie que l'extension choisie est bonne (en principe oui)
1716
-		$gd_formats = formats_image_acceptables(true);
1717
-		if (
1718
-			is_array($image)
1719
-			&& (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1720
-		) {
1721
-			$formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif'];
1722
-			// Choisir le format destination
1723
-			// - on sauve de preference en JPEG (meilleure compression)
1724
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1725
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1726
-			# pas *ecrire*
1727
-			$format_sortie = '';
1728
-			foreach ($formats_sortie as $fmt) {
1729
-				if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1730
-					$format_sortie = $fmt;
1731
-					break;
1732
-				}
1733
-			}
1734
-			$image = false;
1735
-		}
1736
-	}
1737
-
1738
-	if (!is_array($image)) {
1739
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1740
-	}
1741
-
1742
-	if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) {
1743
-		spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1744
-		// on peut resizer en mode html si on dispose des elements
1745
-		[$srcw, $srch] = taille_image($img);
1746
-		if ($srcw && $srch) {
1747
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1748
-
1749
-			return _image_tag_changer_taille($img, $w, $h);
1750
-		}
1751
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1752
-		// sous la forme style='max-width: NNpx;'
1753
-		return inserer_attribut(
1754
-			$img,
1755
-			'style',
1756
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1757
-		);
1758
-	}
1759
-
1760
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1761
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1762
-		if ($image['creer']) {
1763
-			@copy($image['fichier'], $image['fichier_dest']);
1764
-		}
1765
-
1766
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1767
-	}
1768
-
1769
-	if ($image['creer'] == false && !$force) {
1770
-		return _image_ecrire_tag(
1771
-			$image,
1772
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1773
-		);
1774
-	}
1775
-
1776
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1777
-		$destWidth = $image['largeur_dest'];
1778
-		$destHeight = $image['hauteur_dest'];
1779
-		$logo = $image['fichier'];
1780
-		$date = $image['date_src'];
1781
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1782
-
1783
-		if ($preview && $preview['fichier']) {
1784
-			$logo = $preview['fichier'];
1785
-			$destWidth = $preview['width'];
1786
-			$destHeight = $preview['height'];
1787
-			$date = $preview['date'];
1788
-		}
1789
-		// dans l'espace prive mettre un timestamp sur l'adresse
1790
-		// de l'image, de facon a tromper le cache du navigateur
1791
-		// quand on fait supprimer/reuploader un logo
1792
-		// (pas de filemtime si SAFE MODE)
1793
-		$date = test_espace_prive() ? ('?' . $date) : '';
1794
-
1795
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796
-	}
1797
-	else {
1798
-		# BMP, tiff ... les redacteurs osent tout!
1799
-		return $img;
1800
-	}
1705
+    $image = false;
1706
+    if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) {
1707
+        $process = $GLOBALS['meta']['image_process'];
1708
+    }
1709
+    # determiner le format de sortie
1710
+    $format_sortie = false; // le choix par defaut sera bon
1711
+    if ($process === 'netpbm') {
1712
+        $format_sortie = 'jpg';
1713
+    } elseif ($process === 'gd2') {
1714
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1715
+        // on verifie que l'extension choisie est bonne (en principe oui)
1716
+        $gd_formats = formats_image_acceptables(true);
1717
+        if (
1718
+            is_array($image)
1719
+            && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1720
+        ) {
1721
+            $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif'];
1722
+            // Choisir le format destination
1723
+            // - on sauve de preference en JPEG (meilleure compression)
1724
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1725
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1726
+            # pas *ecrire*
1727
+            $format_sortie = '';
1728
+            foreach ($formats_sortie as $fmt) {
1729
+                if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1730
+                    $format_sortie = $fmt;
1731
+                    break;
1732
+                }
1733
+            }
1734
+            $image = false;
1735
+        }
1736
+    }
1737
+
1738
+    if (!is_array($image)) {
1739
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1740
+    }
1741
+
1742
+    if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) {
1743
+        spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1744
+        // on peut resizer en mode html si on dispose des elements
1745
+        [$srcw, $srch] = taille_image($img);
1746
+        if ($srcw && $srch) {
1747
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1748
+
1749
+            return _image_tag_changer_taille($img, $w, $h);
1750
+        }
1751
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1752
+        // sous la forme style='max-width: NNpx;'
1753
+        return inserer_attribut(
1754
+            $img,
1755
+            'style',
1756
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1757
+        );
1758
+    }
1759
+
1760
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1761
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1762
+        if ($image['creer']) {
1763
+            @copy($image['fichier'], $image['fichier_dest']);
1764
+        }
1765
+
1766
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1767
+    }
1768
+
1769
+    if ($image['creer'] == false && !$force) {
1770
+        return _image_ecrire_tag(
1771
+            $image,
1772
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1773
+        );
1774
+    }
1775
+
1776
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1777
+        $destWidth = $image['largeur_dest'];
1778
+        $destHeight = $image['hauteur_dest'];
1779
+        $logo = $image['fichier'];
1780
+        $date = $image['date_src'];
1781
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1782
+
1783
+        if ($preview && $preview['fichier']) {
1784
+            $logo = $preview['fichier'];
1785
+            $destWidth = $preview['width'];
1786
+            $destHeight = $preview['height'];
1787
+            $date = $preview['date'];
1788
+        }
1789
+        // dans l'espace prive mettre un timestamp sur l'adresse
1790
+        // de l'image, de facon a tromper le cache du navigateur
1791
+        // quand on fait supprimer/reuploader un logo
1792
+        // (pas de filemtime si SAFE MODE)
1793
+        $date = test_espace_prive() ? ('?' . $date) : '';
1794
+
1795
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796
+    }
1797
+    else {
1798
+        # BMP, tiff ... les redacteurs osent tout!
1799
+        return $img;
1800
+    }
1801 1801
 }
1802 1802
 
1803 1803
 /**
@@ -1811,145 +1811,145 @@  discard block
 block discarded – undo
1811 1811
  * Class phpthumb_functions
1812 1812
  */
1813 1813
 class phpthumb_functions {
1814
-	/**
1815
-	 * Retourne la couleur d'un pixel dans une image
1816
-	 *
1817
-	 * @param GdImage $img
1818
-	 * @param int $x
1819
-	 * @param int $y
1820
-	 * @return array|bool
1821
-	 */
1822
-	public static function GetPixelColor(&$img, $x, $y) {
1823
-		if ($img instanceof \GdImage) {
1824
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1825
-		}
1826
-		return false;
1827
-	}
1828
-
1829
-	/**
1830
-	 * Retourne un nombre dans une représentation en Little Endian
1831
-	 *
1832
-	 * @param int $number
1833
-	 * @param int $minbytes
1834
-	 * @return string
1835
-	 */
1836
-	public static function LittleEndian2String($number, $minbytes = 1) {
1837
-		$intstring = '';
1838
-		while ($number > 0) {
1839
-			$intstring .= chr($number & 255);
1840
-			$number >>= 8;
1841
-		}
1842
-
1843
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1844
-	}
1845
-
1846
-	/**
1847
-	 * Transforme une ressource GD en image au format ICO
1848
-	 *
1849
-	 * @param array $gd_image_array
1850
-	 *     Tableau de ressources d'images GD
1851
-	 * @return string
1852
-	 *     Image au format ICO
1853
-	 */
1854
-	public static function GD2ICOstring(&$gd_image_array) {
1855
-		foreach ($gd_image_array as $key => $gd_image) {
1856
-			$ImageWidths[$key] = ImageSX($gd_image);
1857
-			$ImageHeights[$key] = ImageSY($gd_image);
1858
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1859
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1860
-
1861
-			$icXOR[$key] = '';
1862
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1863
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1864
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1865
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1866
-					$r = $argb['red'];
1867
-					$g = $argb['green'];
1868
-					$b = $argb['blue'];
1869
-
1870
-					if ($bpp[$key] == 32) {
1871
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1872
-					} elseif ($bpp[$key] === 24) {
1873
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1874
-					}
1875
-
1876
-					if ($a < 128) {
1877
-						@$icANDmask[$key][$y] .= '1';
1878
-					} else {
1879
-						@$icANDmask[$key][$y] .= '0';
1880
-					}
1881
-				}
1882
-				// mask bits are 32-bit aligned per scanline
1883
-				while (strlen($icANDmask[$key][$y]) % 32) {
1884
-					$icANDmask[$key][$y] .= '0';
1885
-				}
1886
-			}
1887
-			$icAND[$key] = '';
1888
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1889
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1890
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1891
-				}
1892
-			}
1893
-		}
1894
-
1895
-		foreach (array_keys($gd_image_array) as $key) {
1896
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1897
-
1898
-			// BITMAPINFOHEADER - 40 bytes
1899
-			$BitmapInfoHeader[$key] = '';
1900
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1901
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1902
-			// The biHeight member specifies the combined
1903
-			// height of the XOR and AND masks.
1904
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1905
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1906
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1907
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1908
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1909
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1910
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1911
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1912
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1913
-		}
1914
-
1915
-
1916
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1917
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1918
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1919
-
1920
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1921
-		foreach (array_keys($gd_image_array) as $key) {
1922
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1923
-
1924
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1925
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1926
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1928
-
1929
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1930
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1931
-
1932
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1933
-			$icondata .= phpthumb_functions::LittleEndian2String(
1934
-				$dwBytesInRes,
1935
-				4
1936
-			);     // dwBytesInRes;	// How many bytes in this resource?
1937
-
1938
-			$icondata .= phpthumb_functions::LittleEndian2String(
1939
-				$dwImageOffset,
1940
-				4
1941
-			);    // dwImageOffset;   // Where in the file is this image?
1942
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1943
-			$dwImageOffset += strlen($icXOR[$key]);
1944
-			$dwImageOffset += strlen($icAND[$key]);
1945
-		}
1946
-
1947
-		foreach (array_keys($gd_image_array) as $key) {
1948
-			$icondata .= $BitmapInfoHeader[$key];
1949
-			$icondata .= $icXOR[$key];
1950
-			$icondata .= $icAND[$key];
1951
-		}
1952
-
1953
-		return $icondata;
1954
-	}
1814
+    /**
1815
+     * Retourne la couleur d'un pixel dans une image
1816
+     *
1817
+     * @param GdImage $img
1818
+     * @param int $x
1819
+     * @param int $y
1820
+     * @return array|bool
1821
+     */
1822
+    public static function GetPixelColor(&$img, $x, $y) {
1823
+        if ($img instanceof \GdImage) {
1824
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1825
+        }
1826
+        return false;
1827
+    }
1828
+
1829
+    /**
1830
+     * Retourne un nombre dans une représentation en Little Endian
1831
+     *
1832
+     * @param int $number
1833
+     * @param int $minbytes
1834
+     * @return string
1835
+     */
1836
+    public static function LittleEndian2String($number, $minbytes = 1) {
1837
+        $intstring = '';
1838
+        while ($number > 0) {
1839
+            $intstring .= chr($number & 255);
1840
+            $number >>= 8;
1841
+        }
1842
+
1843
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1844
+    }
1845
+
1846
+    /**
1847
+     * Transforme une ressource GD en image au format ICO
1848
+     *
1849
+     * @param array $gd_image_array
1850
+     *     Tableau de ressources d'images GD
1851
+     * @return string
1852
+     *     Image au format ICO
1853
+     */
1854
+    public static function GD2ICOstring(&$gd_image_array) {
1855
+        foreach ($gd_image_array as $key => $gd_image) {
1856
+            $ImageWidths[$key] = ImageSX($gd_image);
1857
+            $ImageHeights[$key] = ImageSY($gd_image);
1858
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1859
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1860
+
1861
+            $icXOR[$key] = '';
1862
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1863
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1864
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1865
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1866
+                    $r = $argb['red'];
1867
+                    $g = $argb['green'];
1868
+                    $b = $argb['blue'];
1869
+
1870
+                    if ($bpp[$key] == 32) {
1871
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1872
+                    } elseif ($bpp[$key] === 24) {
1873
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1874
+                    }
1875
+
1876
+                    if ($a < 128) {
1877
+                        @$icANDmask[$key][$y] .= '1';
1878
+                    } else {
1879
+                        @$icANDmask[$key][$y] .= '0';
1880
+                    }
1881
+                }
1882
+                // mask bits are 32-bit aligned per scanline
1883
+                while (strlen($icANDmask[$key][$y]) % 32) {
1884
+                    $icANDmask[$key][$y] .= '0';
1885
+                }
1886
+            }
1887
+            $icAND[$key] = '';
1888
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1889
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1890
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1891
+                }
1892
+            }
1893
+        }
1894
+
1895
+        foreach (array_keys($gd_image_array) as $key) {
1896
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1897
+
1898
+            // BITMAPINFOHEADER - 40 bytes
1899
+            $BitmapInfoHeader[$key] = '';
1900
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1901
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1902
+            // The biHeight member specifies the combined
1903
+            // height of the XOR and AND masks.
1904
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1905
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1906
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1907
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1908
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1909
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1910
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1911
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1912
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1913
+        }
1914
+
1915
+
1916
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1917
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1918
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1919
+
1920
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1921
+        foreach (array_keys($gd_image_array) as $key) {
1922
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1923
+
1924
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1925
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1926
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1928
+
1929
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1930
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1931
+
1932
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1933
+            $icondata .= phpthumb_functions::LittleEndian2String(
1934
+                $dwBytesInRes,
1935
+                4
1936
+            );     // dwBytesInRes;	// How many bytes in this resource?
1937
+
1938
+            $icondata .= phpthumb_functions::LittleEndian2String(
1939
+                $dwImageOffset,
1940
+                4
1941
+            );    // dwImageOffset;   // Where in the file is this image?
1942
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1943
+            $dwImageOffset += strlen($icXOR[$key]);
1944
+            $dwImageOffset += strlen($icAND[$key]);
1945
+        }
1946
+
1947
+        foreach (array_keys($gd_image_array) as $key) {
1948
+            $icondata .= $BitmapInfoHeader[$key];
1949
+            $icondata .= $icXOR[$key];
1950
+            $icondata .= $icAND[$key];
1951
+        }
1952
+
1953
+        return $icondata;
1954
+    }
1955 1955
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 	$blue = dechex($blue);
43 43
 
44 44
 	if (strlen($red) == 1) {
45
-		$red = '0' . $red;
45
+		$red = '0'.$red;
46 46
 	}
47 47
 	if (strlen($green) == 1) {
48
-		$green = '0' . $green;
48
+		$green = '0'.$green;
49 49
 	}
50 50
 	if (strlen($blue) == 1) {
51
-		$blue = '0' . $blue;
51
+		$blue = '0'.$blue;
52 52
 	}
53 53
 
54 54
 	return "$red$green$blue";
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	$couleur = couleur_html_to_hex($couleur);
68 68
 	$couleur = ltrim($couleur, '#');
69 69
 	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
70
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
71 71
 	}
72 72
 	$retour = [];
73 73
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 	$var_G = ($G / 255);
126 126
 	$var_B = ($B / 255);
127 127
 
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
128
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
129
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
130
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
131 131
 
132 132
 	$L = ($var_Max + $var_Min) / 2;
133 133
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function _couleur_hsl_to_rgb($H, $S, $L) {
187 187
 	// helper
188
-	$hue_2_rgb = function ($v1, $v2, $vH) {
188
+	$hue_2_rgb = function($v1, $v2, $vH) {
189 189
 		if ($vH < 0) {
190 190
 			$vH += 1;
191 191
 		}
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
 		}
320 320
 	} elseif (
321 321
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
322
-		&& ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]))
322
+		&& ($extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]))
323 323
 		&& in_array($extension, _image_extensions_acceptees_en_entree())
324 324
 	) {
325 325
 		# gerer img src="data:....base64"
326
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
326
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
327 327
 		if (!file_exists($local)) {
328 328
 			ecrire_fichier($local, base64_decode($regs[2]));
329 329
 		}
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	// les protocoles web prennent au moins 3 lettres
341 341
 	if (tester_url_absolue($source)) {
342 342
 		include_spip('inc/distant');
343
-		$fichier = _DIR_RACINE . copie_locale($source);
343
+		$fichier = _DIR_RACINE.copie_locale($source);
344 344
 		if (!$fichier) {
345 345
 			return '';
346 346
 		}
@@ -442,9 +442,9 @@  discard block
 block discarded – undo
442 442
 			// on garde la terminaison initiale car image simplement copiee
443 443
 			// et on postfixe son nom avec un md5 du path
444 444
 			$terminaison_dest = $terminaison;
445
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
446 446
 		} else {
447
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
448 448
 		}
449 449
 		$cache = sous_repertoire(_DIR_VAR, $cache);
450 450
 		$cache = sous_repertoire($cache, $effet);
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 		$fichier_dest = substr($fichier_dest, 2);
456 456
 	}
457 457
 
458
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
459 459
 
460 460
 	$GLOBALS['images_calculees'][] = $fichier_dest;
461 461
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 	}
482 482
 	if ($creer && !@file_exists($fichier)) {
483 483
 		if (!@file_exists("$fichier.src")) {
484
-			spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR);
484
+			spip_log("Image absente : $fichier", 'images'._LOG_ERREUR);
485 485
 
486 486
 			return false;
487 487
 		}
@@ -491,15 +491,15 @@  discard block
 block discarded – undo
491 491
 
492 492
 	if ($creer) {
493 493
 		spip_log(
494
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
495
-			'images' . _LOG_DEBUG
494
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
495
+			'images'._LOG_DEBUG
496 496
 		);
497 497
 	}
498 498
 
499 499
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
500
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
501 501
 	$ret['fichier'] = $fichier;
502
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
503 503
 	$ret['fichier_dest'] = $fichier_dest;
504 504
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
505 505
 	$ret['format_dest'] = $terminaison_dest;
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 
643 643
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
644 644
 	if ($_terminaison && $_terminaison !== $terminaison) {
645
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
645
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
646 646
 		$terminaison = $_terminaison;
647 647
 	}
648 648
 	return $terminaison;
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	if (!function_exists('imagepng')) {
778 778
 		return false;
779 779
 	}
780
-	$tmp = $fichier . '.tmp';
780
+	$tmp = $fichier.'.tmp';
781 781
 	$ret = imagepng($img, $tmp);
782 782
 	if (file_exists($tmp)) {
783 783
 		$taille_test = @getimagesize($tmp);
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 	if (!function_exists('imagegif')) {
813 813
 		return false;
814 814
 	}
815
-	$tmp = $fichier . '.tmp';
815
+	$tmp = $fichier.'.tmp';
816 816
 	$ret = imagegif($img, $tmp);
817 817
 	if (file_exists($tmp)) {
818 818
 		$taille_test = @getimagesize($tmp);
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 	if (!function_exists('imagejpeg')) {
853 853
 		return false;
854 854
 	}
855
-	$tmp = $fichier . '.tmp';
855
+	$tmp = $fichier.'.tmp';
856 856
 
857 857
 	// Enable interlancing
858 858
 	imageinterlace($img, true);
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
 	if (!function_exists('imagewebp')) {
914 914
 		return false;
915 915
 	}
916
-	$tmp = $fichier . '.tmp';
916
+	$tmp = $fichier.'.tmp';
917 917
 	$ret = imagewebp($img, $tmp, $qualite);
918 918
 	if (file_exists($tmp)) {
919 919
 		$taille_test = @getimagesize($tmp);
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
  */
948 948
 function _image_imagesvg($img, $fichier) {
949 949
 
950
-	$tmp = $fichier . '.tmp';
950
+	$tmp = $fichier.'.tmp';
951 951
 	if (!str_contains($img, '<')) {
952 952
 		$img = supprimer_timestamp($img);
953 953
 		if (!file_exists($img)) {
@@ -1004,14 +1004,14 @@  discard block
 block discarded – undo
1004 1004
  */
1005 1005
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1006 1006
 	if (is_null($fonction)) {
1007
-		$fonction = '_image_image' . $valeurs['format_dest'];
1007
+		$fonction = '_image_image'.$valeurs['format_dest'];
1008 1008
 	}
1009 1009
 	$ret = false;
1010 1010
 	#un flag pour reperer les images gravees
1011 1011
 	$lock = (
1012 1012
 		!statut_effacer_images_temporaires('get')
1013 1013
 		|| @file_exists($valeurs['fichier_dest'])
1014
-		&& !@file_exists($valeurs['fichier_dest'] . '.src')
1014
+		&& !@file_exists($valeurs['fichier_dest'].'.src')
1015 1015
 	);
1016 1016
 	if (
1017 1017
 		function_exists($fonction)
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 		[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1024 1024
 		$valeurs['date'] = @filemtime($valeurs['fichier_dest']);
1025 1025
 		// pour la retrouver apres disparition
1026
-		ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1026
+		ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1027 1027
 	}
1028 1028
 
1029 1029
 	return $ret;
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 
1199 1199
 	// attributs deprecies. Transformer en CSS
1200 1200
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1201
-		$style = "margin:{$espace}px;" . $style;
1201
+		$style = "margin:{$espace}px;".$style;
1202 1202
 		$tag = inserer_attribut($tag, 'hspace', '');
1203 1203
 	}
1204 1204
 
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
 	$image = $valeurs['fichier'];
1322 1322
 	$format = $valeurs['format_source'];
1323 1323
 	$destdir = dirname($valeurs['fichier_dest']);
1324
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1324
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1325 1325
 
1326 1326
 	$format_sortie = $valeurs['format_dest'];
1327 1327
 
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 
1354 1354
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1355 1355
 	if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
1356
-		$vignette = $destination . '.' . $format;
1356
+		$vignette = $destination.'.'.$format;
1357 1357
 		@copy($image, $vignette);
1358 1358
 	}
1359 1359
 
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
 		include_spip('inc/svg');
1362 1362
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1363 1363
 			$format_sortie = 'svg';
1364
-			$vignette = $destination . '.' . $format_sortie;
1364
+			$vignette = $destination.'.'.$format_sortie;
1365 1365
 			$valeurs['fichier_dest'] = $vignette;
1366 1366
 			_image_gd_output($svg, $valeurs);
1367 1367
 		}
@@ -1373,9 +1373,9 @@  discard block
 block discarded – undo
1373 1373
 			define('_CONVERT_COMMAND', 'convert');
1374 1374
 		} // Securite : mes_options.php peut preciser le chemin absolu
1375 1375
 		if (!defined('_RESIZE_COMMAND')) {
1376
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest');
1376
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -orient Undefined -resize %xx%y! %src %dest');
1377 1377
 		}
1378
-		$vignette = $destination . '.' . $format_sortie;
1378
+		$vignette = $destination.'.'.$format_sortie;
1379 1379
 		$commande = str_replace(
1380 1380
 			['%x', '%y', '%src', '%dest'],
1381 1381
 			[
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
 		if (!@file_exists($vignette)) {
1392 1392
 			spip_log("echec convert sur $vignette");
1393 1393
 
1394
-			return;  // echec commande
1394
+			return; // echec commande
1395 1395
 		}
1396 1396
 	}
1397 1397
 
@@ -1408,7 +1408,7 @@  discard block
 block discarded – undo
1408 1408
 		if (!$output) {
1409 1409
 			return;
1410 1410
 		}
1411
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1411
+		$vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie;
1412 1412
 
1413 1413
 		$imagick = new Imagick();
1414 1414
 		$imagick->readImage(realpath($image));
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 			$destHeight,
1418 1418
 			Imagick::FILTER_LANCZOS,
1419 1419
 			1
1420
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1420
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1421 1421
 		$imagick->writeImage($vignette);
1422 1422
 
1423 1423
 		if (!@file_exists($vignette)) {
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
 			return;
1427 1427
 		}
1428 1428
 		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1429
-		$vignette = $destination . '.' . $format_sortie;
1429
+		$vignette = $destination.'.'.$format_sortie;
1430 1430
 	}
1431 1431
 
1432 1432
 	// netpbm
@@ -1437,11 +1437,11 @@  discard block
 block discarded – undo
1437 1437
 		if (_PNMSCALE_COMMAND == '') {
1438 1438
 			return;
1439 1439
 		}
1440
-		$vignette = $destination . '.' . $format_sortie;
1440
+		$vignette = $destination.'.'.$format_sortie;
1441 1441
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1442 1442
 		if ($format == 'jpg') {
1443 1443
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1444
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1444
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1445 1445
 			if (!($s = @filesize($vignette))) {
1446 1446
 				spip_unlink($vignette);
1447 1447
 			}
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
 		} else {
1454 1454
 			if ($format == 'gif') {
1455 1455
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1456
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1456
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1457 1457
 				if (!($s = @filesize($vignette))) {
1458 1458
 					spip_unlink($vignette);
1459 1459
 				}
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 			} else {
1466 1466
 				if ($format == 'png') {
1467 1467
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1468
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1468
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1469 1469
 					if (!($s = @filesize($vignette))) {
1470 1470
 						spip_unlink($vignette);
1471 1471
 					}
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
 			return;
1488 1488
 		}
1489 1489
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1490
-			spip_log('vignette gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1490
+			spip_log('vignette gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1491 1491
 
1492 1492
 			return;
1493 1493
 		}
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
 		// de l'image, de facon a tromper le cache du navigateur
1791 1791
 		// quand on fait supprimer/reuploader un logo
1792 1792
 		// (pas de filemtime si SAFE MODE)
1793
-		$date = test_espace_prive() ? ('?' . $date) : '';
1793
+		$date = test_espace_prive() ? ('?'.$date) : '';
1794 1794
 
1795 1795
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1796 1796
 	}
@@ -1868,9 +1868,9 @@  discard block
 block discarded – undo
1868 1868
 					$b = $argb['blue'];
1869 1869
 
1870 1870
 					if ($bpp[$key] == 32) {
1871
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1871
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1872 1872
 					} elseif ($bpp[$key] === 24) {
1873
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1873
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1874 1874
 					}
1875 1875
 
1876 1876
 					if ($a < 128) {
@@ -1897,48 +1897,48 @@  discard block
 block discarded – undo
1897 1897
 
1898 1898
 			// BITMAPINFOHEADER - 40 bytes
1899 1899
 			$BitmapInfoHeader[$key] = '';
1900
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1901
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1900
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1901
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1902 1902
 			// The biHeight member specifies the combined
1903 1903
 			// height of the XOR and AND masks.
1904 1904
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1905
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1906
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1907
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1908
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1909
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1910
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1911
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1912
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1905
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1906
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1907
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1908
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1909
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1910
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1911
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1912
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1913 1913
 		}
1914 1914
 
1915 1915
 
1916
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1917
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1918
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1916
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1917
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1918
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1919 1919
 
1920 1920
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1921 1921
 		foreach (array_keys($gd_image_array) as $key) {
1922 1922
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1923 1923
 
1924
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1925
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1926
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1924
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1925
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1926
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1927
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1928 1928
 
1929
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1930
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1929
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1930
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1931 1931
 
1932 1932
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1933 1933
 			$icondata .= phpthumb_functions::LittleEndian2String(
1934 1934
 				$dwBytesInRes,
1935 1935
 				4
1936
-			);     // dwBytesInRes;	// How many bytes in this resource?
1936
+			); // dwBytesInRes;	// How many bytes in this resource?
1937 1937
 
1938 1938
 			$icondata .= phpthumb_functions::LittleEndian2String(
1939 1939
 				$dwImageOffset,
1940 1940
 				4
1941
-			);    // dwImageOffset;   // Where in the file is this image?
1941
+			); // dwImageOffset;   // Where in the file is this image?
1942 1942
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1943 1943
 			$dwImageOffset += strlen($icXOR[$key]);
1944 1944
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/traduire.php 2 patches
Indentation   +192 added lines, -192 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
 /**
@@ -39,18 +39,18 @@  discard block
 block discarded – undo
39 39
  *     Liste des fichiers de langue trouvés, dans l'ordre des chemins
40 40
  */
41 41
 function find_langs_in_path($file, $dirname = 'lang') {
42
-	static $dirs = [];
43
-	$liste = [];
44
-	foreach (creer_chemin() as $dir) {
45
-		if (!isset($dirs[$a = $dir . $dirname])) {
46
-			$dirs[$a] = (is_dir($a) || !$a);
47
-		}
48
-		if ($dirs[$a] && is_readable($a .= $file)) {
49
-			$liste[] = $a;
50
-		}
51
-	}
42
+    static $dirs = [];
43
+    $liste = [];
44
+    foreach (creer_chemin() as $dir) {
45
+        if (!isset($dirs[$a = $dir . $dirname])) {
46
+            $dirs[$a] = (is_dir($a) || !$a);
47
+        }
48
+        if ($dirs[$a] && is_readable($a .= $file)) {
49
+            $liste[] = $a;
50
+        }
51
+    }
52 52
 
53
-	return array_reverse($liste);
53
+    return array_reverse($liste);
54 54
 }
55 55
 
56 56
 /**
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
  *     Liste des fichiers touvés pour ce module et cette langue.
66 66
  **/
67 67
 function chercher_module_lang($module, $lang = '') {
68
-	if ($lang) {
69
-		$lang = '_' . $lang;
70
-	}
68
+    if ($lang) {
69
+        $lang = '_' . $lang;
70
+    }
71 71
 
72
-	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
73
-	if (
74
-		$f = ($module == 'local'
75
-		? find_in_path($module . $lang . '.php', 'lang/')
76
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
77
-	) {
78
-		return is_array($f) ? $f : [$f];
79
-	}
72
+    // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
73
+    if (
74
+        $f = ($module == 'local'
75
+        ? find_in_path($module . $lang . '.php', 'lang/')
76
+        : find_langs_in_path($module . $lang . '.php', 'lang/'))
77
+    ) {
78
+        return is_array($f) ? $f : [$f];
79
+    }
80 80
 
81
-	// 2) directement dans le chemin (old style, uniquement pour local)
82
-	return ($module == 'local' || strpos($module, '/'))
83
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
84
-		: false;
81
+    // 2) directement dans le chemin (old style, uniquement pour local)
82
+    return ($module == 'local' || strpos($module, '/'))
83
+        ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
84
+        : false;
85 85
 }
86 86
 
87 87
 /**
@@ -103,33 +103,33 @@  discard block
 block discarded – undo
103 103
  * @return void
104 104
  **/
105 105
 function charger_langue($lang, $module = 'spip') {
106
-	static $langs = [];
107
-	$var = 'i18n_' . $module . '_' . $lang;
108
-	if (!isset($langs[$lang])) {
109
-		$langs[$lang] = [];
110
-		if ($lang) {
111
-			$langs[$lang][] = $lang;
112
-			if (str_contains($lang, '_')) {
113
-				$l = explode('_', $lang);
114
-				$langs[$lang][] = reset($l);
115
-			}
116
-		}
117
-		$langs[$lang][] = $GLOBALS['meta']['langue_site'];
118
-		$langs[$lang][] = _LANGUE_PAR_DEFAUT;
119
-	}
120
-	foreach ($langs[$lang] as $l) {
121
-		if ($fichiers_lang = chercher_module_lang($module, $l)) {
122
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
123
-			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
124
-			surcharger_langue($fichiers_lang);
125
-			if ($l !== $lang) {
126
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
127
-			}
128
-			$GLOBALS['lang_' . $var] = $l;
129
-			#spip_log("module de langue : {$module}_$l.php", 'traduire');
130
-			break;
131
-		}
132
-	}
106
+    static $langs = [];
107
+    $var = 'i18n_' . $module . '_' . $lang;
108
+    if (!isset($langs[$lang])) {
109
+        $langs[$lang] = [];
110
+        if ($lang) {
111
+            $langs[$lang][] = $lang;
112
+            if (str_contains($lang, '_')) {
113
+                $l = explode('_', $lang);
114
+                $langs[$lang][] = reset($l);
115
+            }
116
+        }
117
+        $langs[$lang][] = $GLOBALS['meta']['langue_site'];
118
+        $langs[$lang][] = _LANGUE_PAR_DEFAUT;
119
+    }
120
+    foreach ($langs[$lang] as $l) {
121
+        if ($fichiers_lang = chercher_module_lang($module, $l)) {
122
+            $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
123
+            $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
124
+            surcharger_langue($fichiers_lang);
125
+            if ($l !== $lang) {
126
+                $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
127
+            }
128
+            $GLOBALS['lang_' . $var] = $l;
129
+            #spip_log("module de langue : {$module}_$l.php", 'traduire');
130
+            break;
131
+        }
132
+    }
133 133
 }
134 134
 
135 135
 /**
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
  * @return array<string, string>
143 143
  */
144 144
 function lire_fichier_langue(string $fichier): array {
145
-	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
146
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
147
-	$GLOBALS['idx_lang'] = $idx_lang_tmp;
148
-	$idx_lang = include $fichier;
149
-	$GLOBALS['idx_lang'] = $idx_lang_before;
150
-	if (!is_array($idx_lang)) {
151
-		if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) {
152
-			$idx_lang = $GLOBALS[$idx_lang_tmp];
153
-		} else {
154
-			$idx_lang = [];
155
-			spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
156
-		}
157
-		unset($GLOBALS[$idx_lang_tmp]);
158
-	}
159
-	return $idx_lang;
145
+    $idx_lang_before = $GLOBALS['idx_lang'] ?? null;
146
+    $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
147
+    $GLOBALS['idx_lang'] = $idx_lang_tmp;
148
+    $idx_lang = include $fichier;
149
+    $GLOBALS['idx_lang'] = $idx_lang_before;
150
+    if (!is_array($idx_lang)) {
151
+        if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) {
152
+            $idx_lang = $GLOBALS[$idx_lang_tmp];
153
+        } else {
154
+            $idx_lang = [];
155
+            spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
156
+        }
157
+        unset($GLOBALS[$idx_lang_tmp]);
158
+    }
159
+    return $idx_lang;
160 160
 }
161 161
 
162 162
 /**
@@ -176,29 +176,29 @@  discard block
 block discarded – undo
176 176
  *    Liste des chemins de fichiers de langue à surcharger.
177 177
  **/
178 178
 function surcharger_langue($fichiers) {
179
-	static $surcharges = [];
180
-	if (!isset($GLOBALS['idx_lang'])) {
181
-		return;
182
-	}
179
+    static $surcharges = [];
180
+    if (!isset($GLOBALS['idx_lang'])) {
181
+        return;
182
+    }
183 183
 
184
-	if (!is_array($fichiers)) {
185
-		$fichiers = [$fichiers];
186
-	}
187
-	if ($fichiers === []) {
188
-		return;
189
-	}
190
-	foreach ($fichiers as $fichier) {
191
-		if (!isset($surcharges[$fichier])) {
192
-			$surcharges[$fichier] = lire_fichier_langue($fichier);
193
-		}
194
-		if (is_array($surcharges[$fichier])) {
195
-			$GLOBALS[$GLOBALS['idx_lang']] ??= [];
196
-			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
197
-				$GLOBALS[$GLOBALS['idx_lang']],
198
-				$surcharges[$fichier]
199
-			);
200
-		}
201
-	}
184
+    if (!is_array($fichiers)) {
185
+        $fichiers = [$fichiers];
186
+    }
187
+    if ($fichiers === []) {
188
+        return;
189
+    }
190
+    foreach ($fichiers as $fichier) {
191
+        if (!isset($surcharges[$fichier])) {
192
+            $surcharges[$fichier] = lire_fichier_langue($fichier);
193
+        }
194
+        if (is_array($surcharges[$fichier])) {
195
+            $GLOBALS[$GLOBALS['idx_lang']] ??= [];
196
+            $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
197
+                $GLOBALS[$GLOBALS['idx_lang']],
198
+                $surcharges[$fichier]
199
+            );
200
+        }
201
+    }
202 202
 }
203 203
 
204 204
 /**
@@ -239,99 +239,99 @@  discard block
 block discarded – undo
239 239
  *     - Description : traduction et description (texte, module, langue)
240 240
  **/
241 241
 function inc_traduire_dist($ori, $lang, $raw = false) {
242
-	static $deja_vu = [];
243
-	static $local = [];
242
+    static $deja_vu = [];
243
+    static $local = [];
244 244
 
245
-	if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') {
246
-		return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
247
-	}
245
+    if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') {
246
+        return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
247
+    }
248 248
 
249
-	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
250
-	if (strpos($ori, ':')) {
251
-		[$modules, $code] = explode(':', $ori, 2);
252
-		$modules = explode('|', $modules);
253
-		$ori_complet = $ori;
254
-	} else {
255
-		$modules = ['spip', 'ecrire'];
256
-		$code = $ori;
257
-		$ori_complet = implode('|', $modules) . ':' . $ori;
258
-	}
249
+    // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
250
+    if (strpos($ori, ':')) {
251
+        [$modules, $code] = explode(':', $ori, 2);
252
+        $modules = explode('|', $modules);
253
+        $ori_complet = $ori;
254
+    } else {
255
+        $modules = ['spip', 'ecrire'];
256
+        $code = $ori;
257
+        $ori_complet = implode('|', $modules) . ':' . $ori;
258
+    }
259 259
 
260
-	$desc = new Description();
260
+    $desc = new Description();
261 261
 
262
-	// parcourir tous les modules jusqu'a ce qu'on trouve
263
-	foreach ($modules as $module) {
264
-		$var = 'i18n_' . $module . '_' . $lang;
262
+    // parcourir tous les modules jusqu'a ce qu'on trouve
263
+    foreach ($modules as $module) {
264
+        $var = 'i18n_' . $module . '_' . $lang;
265 265
 
266
-		if (empty($GLOBALS[$var])) {
267
-			charger_langue($lang, $module);
268
-			// surcharges persos -- on cherche
269
-			// (lang/)local_xx.php et/ou (lang/)local.php ...
270
-			if (!isset($local['local_' . $lang])) {
271
-				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
272
-				$GLOBALS['idx_lang'] = $var;
273
-				// ... (lang/)local_xx.php
274
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
275
-			}
276
-			if ($local['local_' . $lang]) {
277
-				surcharger_langue($local['local_' . $lang]);
278
-			}
279
-			// ... puis (lang/)local.php
280
-			if (!isset($local['local'])) {
281
-				$local['local'] = chercher_module_lang('local');
282
-			}
283
-			if ($local['local']) {
284
-				surcharger_langue($local['local']);
285
-			}
286
-		}
266
+        if (empty($GLOBALS[$var])) {
267
+            charger_langue($lang, $module);
268
+            // surcharges persos -- on cherche
269
+            // (lang/)local_xx.php et/ou (lang/)local.php ...
270
+            if (!isset($local['local_' . $lang])) {
271
+                // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
272
+                $GLOBALS['idx_lang'] = $var;
273
+                // ... (lang/)local_xx.php
274
+                $local['local_' . $lang] = chercher_module_lang('local', $lang);
275
+            }
276
+            if ($local['local_' . $lang]) {
277
+                surcharger_langue($local['local_' . $lang]);
278
+            }
279
+            // ... puis (lang/)local.php
280
+            if (!isset($local['local'])) {
281
+                $local['local'] = chercher_module_lang('local');
282
+            }
283
+            if ($local['local']) {
284
+                surcharger_langue($local['local']);
285
+            }
286
+        }
287 287
 
288
-		if (isset($GLOBALS[$var][$code])) {
289
-			$desc->code = $code;
290
-			$desc->module = $module;
291
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
292
-			$desc->texte = $GLOBALS[$var][$code];
293
-			break;
294
-		}
295
-	}
288
+        if (isset($GLOBALS[$var][$code])) {
289
+            $desc->code = $code;
290
+            $desc->module = $module;
291
+            $desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
292
+            $desc->texte = $GLOBALS[$var][$code];
293
+            break;
294
+        }
295
+    }
296 296
 
297
-	if (!$desc->corrections) {
298
-		$desc->corrections = true;
299
-		// Retour aux sources si la chaine est absente dans la langue cible ;
300
-		// on essaie d'abord la langue du site, puis a defaut la langue fr
301
-		if (
302
-			($desc->texte === null || !strlen($desc->texte))
303
-			&& $lang !== _LANGUE_PAR_DEFAUT
304
-		) {
305
-			if ($lang !== $GLOBALS['meta']['langue_site']) {
306
-				$desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
307
-			} else {
308
-				$desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
309
-			}
310
-		}
297
+    if (!$desc->corrections) {
298
+        $desc->corrections = true;
299
+        // Retour aux sources si la chaine est absente dans la langue cible ;
300
+        // on essaie d'abord la langue du site, puis a defaut la langue fr
301
+        if (
302
+            ($desc->texte === null || !strlen($desc->texte))
303
+            && $lang !== _LANGUE_PAR_DEFAUT
304
+        ) {
305
+            if ($lang !== $GLOBALS['meta']['langue_site']) {
306
+                $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
307
+            } else {
308
+                $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
309
+            }
310
+        }
311 311
 
312
-		// Supprimer la mention <NEW> ou <MODIF>
313
-		if ($desc->texte && str_starts_with($desc->texte, '<')) {
314
-			$desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
315
-		}
312
+        // Supprimer la mention <NEW> ou <MODIF>
313
+        if ($desc->texte && str_starts_with($desc->texte, '<')) {
314
+            $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
315
+        }
316 316
 
317
-		// Si on n'est pas en utf-8, la chaine peut l'etre...
318
-		// le cas echeant on la convertit en entites html &#xxx;
319
-		if (
320
-			(!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8')
321
-			&& preg_match(',[\x7f-\xff],S', $desc->texte)
322
-		) {
323
-			include_spip('inc/charsets');
324
-			$desc->texte = charset2unicode($desc->texte, 'utf-8');
325
-		}
326
-	}
317
+        // Si on n'est pas en utf-8, la chaine peut l'etre...
318
+        // le cas echeant on la convertit en entites html &#xxx;
319
+        if (
320
+            (!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8')
321
+            && preg_match(',[\x7f-\xff],S', $desc->texte)
322
+        ) {
323
+            include_spip('inc/charsets');
324
+            $desc->texte = charset2unicode($desc->texte, 'utf-8');
325
+        }
326
+    }
327 327
 
328
-	if (_request('var_mode') == 'traduction') {
329
-		$desc = definir_details_traduction($desc, $ori_complet);
330
-	} else {
331
-		$deja_vu[$lang][$ori] = $desc;
332
-	}
328
+    if (_request('var_mode') == 'traduction') {
329
+        $desc = definir_details_traduction($desc, $ori_complet);
330
+    } else {
331
+        $deja_vu[$lang][$ori] = $desc;
332
+    }
333 333
 
334
-	return $raw ? $desc : $desc->texte;
334
+    return $raw ? $desc : $desc->texte;
335 335
 }
336 336
 
337 337
 /**
@@ -343,23 +343,23 @@  discard block
 block discarded – undo
343 343
  * @return Description
344 344
  */
345 345
 function definir_details_traduction($desc, $modules) {
346
-	if (!$desc->mode && $desc->texte) {
347
-		// ne pas modifier 2 fois l'affichage
348
-		$desc->mode = 'traduction';
349
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
350
-		$desc->texte = '<span '
351
-			. 'lang=' . $desc->langue
352
-			. ' class=' . $classe
353
-			. ' data-module=' . $desc->module
354
-			. ' data-code=' . $desc->code
355
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
356
-			. $desc->texte
357
-			. '</span>';
358
-		$desc->texte = str_replace(
359
-			["$desc->module:", "$desc->module|"],
360
-			["*$desc->module*:", "*$desc->module*|"],
361
-			$desc->texte
362
-		);
363
-	}
364
-	return $desc;
346
+    if (!$desc->mode && $desc->texte) {
347
+        // ne pas modifier 2 fois l'affichage
348
+        $desc->mode = 'traduction';
349
+        $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
350
+        $desc->texte = '<span '
351
+            . 'lang=' . $desc->langue
352
+            . ' class=' . $classe
353
+            . ' data-module=' . $desc->module
354
+            . ' data-code=' . $desc->code
355
+            . ' title=' . $modules . '(' . $desc->langue . ')>'
356
+            . $desc->texte
357
+            . '</span>';
358
+        $desc->texte = str_replace(
359
+            ["$desc->module:", "$desc->module|"],
360
+            ["*$desc->module*:", "*$desc->module*|"],
361
+            $desc->texte
362
+        );
363
+    }
364
+    return $desc;
365 365
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	static $dirs = [];
43 43
 	$liste = [];
44 44
 	foreach (creer_chemin() as $dir) {
45
-		if (!isset($dirs[$a = $dir . $dirname])) {
45
+		if (!isset($dirs[$a = $dir.$dirname])) {
46 46
 			$dirs[$a] = (is_dir($a) || !$a);
47 47
 		}
48 48
 		if ($dirs[$a] && is_readable($a .= $file)) {
@@ -66,21 +66,21 @@  discard block
 block discarded – undo
66 66
  **/
67 67
 function chercher_module_lang($module, $lang = '') {
68 68
 	if ($lang) {
69
-		$lang = '_' . $lang;
69
+		$lang = '_'.$lang;
70 70
 	}
71 71
 
72 72
 	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
73 73
 	if (
74 74
 		$f = ($module == 'local'
75
-		? find_in_path($module . $lang . '.php', 'lang/')
76
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
75
+		? find_in_path($module.$lang.'.php', 'lang/')
76
+		: find_langs_in_path($module.$lang.'.php', 'lang/'))
77 77
 	) {
78 78
 		return is_array($f) ? $f : [$f];
79 79
 	}
80 80
 
81 81
 	// 2) directement dans le chemin (old style, uniquement pour local)
82 82
 	return ($module == 'local' || strpos($module, '/'))
83
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
83
+		? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false)
84 84
 		: false;
85 85
 }
86 86
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  **/
105 105
 function charger_langue($lang, $module = 'spip') {
106 106
 	static $langs = [];
107
-	$var = 'i18n_' . $module . '_' . $lang;
107
+	$var = 'i18n_'.$module.'_'.$lang;
108 108
 	if (!isset($langs[$lang])) {
109 109
 		$langs[$lang] = [];
110 110
 		if ($lang) {
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	}
120 120
 	foreach ($langs[$lang] as $l) {
121 121
 		if ($fichiers_lang = chercher_module_lang($module, $l)) {
122
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
122
+			$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l;
123 123
 			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
124 124
 			surcharger_langue($fichiers_lang);
125 125
 			if ($l !== $lang) {
126
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
126
+				$GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l];
127 127
 			}
128
-			$GLOBALS['lang_' . $var] = $l;
128
+			$GLOBALS['lang_'.$var] = $l;
129 129
 			#spip_log("module de langue : {$module}_$l.php", 'traduire');
130 130
 			break;
131 131
 		}
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
  */
144 144
 function lire_fichier_langue(string $fichier): array {
145 145
 	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
146
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
146
+	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire';
147 147
 	$GLOBALS['idx_lang'] = $idx_lang_tmp;
148 148
 	$idx_lang = include $fichier;
149 149
 	$GLOBALS['idx_lang'] = $idx_lang_before;
@@ -254,27 +254,27 @@  discard block
 block discarded – undo
254 254
 	} else {
255 255
 		$modules = ['spip', 'ecrire'];
256 256
 		$code = $ori;
257
-		$ori_complet = implode('|', $modules) . ':' . $ori;
257
+		$ori_complet = implode('|', $modules).':'.$ori;
258 258
 	}
259 259
 
260 260
 	$desc = new Description();
261 261
 
262 262
 	// parcourir tous les modules jusqu'a ce qu'on trouve
263 263
 	foreach ($modules as $module) {
264
-		$var = 'i18n_' . $module . '_' . $lang;
264
+		$var = 'i18n_'.$module.'_'.$lang;
265 265
 
266 266
 		if (empty($GLOBALS[$var])) {
267 267
 			charger_langue($lang, $module);
268 268
 			// surcharges persos -- on cherche
269 269
 			// (lang/)local_xx.php et/ou (lang/)local.php ...
270
-			if (!isset($local['local_' . $lang])) {
270
+			if (!isset($local['local_'.$lang])) {
271 271
 				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
272 272
 				$GLOBALS['idx_lang'] = $var;
273 273
 				// ... (lang/)local_xx.php
274
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
274
+				$local['local_'.$lang] = chercher_module_lang('local', $lang);
275 275
 			}
276
-			if ($local['local_' . $lang]) {
277
-				surcharger_langue($local['local_' . $lang]);
276
+			if ($local['local_'.$lang]) {
277
+				surcharger_langue($local['local_'.$lang]);
278 278
 			}
279 279
 			// ... puis (lang/)local.php
280 280
 			if (!isset($local['local'])) {
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 		if (isset($GLOBALS[$var][$code])) {
289 289
 			$desc->code = $code;
290 290
 			$desc->module = $module;
291
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
291
+			$desc->langue = $GLOBALS['lang_'.$var] ?? $lang;
292 292
 			$desc->texte = $GLOBALS[$var][$code];
293 293
 			break;
294 294
 		}
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
 	if (!$desc->mode && $desc->texte) {
347 347
 		// ne pas modifier 2 fois l'affichage
348 348
 		$desc->mode = 'traduction';
349
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
349
+		$classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : '');
350 350
 		$desc->texte = '<span '
351
-			. 'lang=' . $desc->langue
352
-			. ' class=' . $classe
353
-			. ' data-module=' . $desc->module
354
-			. ' data-code=' . $desc->code
355
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
351
+			. 'lang='.$desc->langue
352
+			. ' class='.$classe
353
+			. ' data-module='.$desc->module
354
+			. ' data-code='.$desc->code
355
+			. ' title='.$modules.'('.$desc->langue.')>'
356 356
 			. $desc->texte
357 357
 			. '</span>';
358 358
 		$desc->texte = str_replace(
Please login to merge, or discard this patch.
ecrire/inc/math.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 //
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 //
@@ -20,52 +20,52 @@  discard block
 block discarded – undo
20 20
 
21 21
 function produire_image_math($tex) {
22 22
 
23
-	switch ($GLOBALS['traiter_math']) {
24
-		// Attention: mathml desactiv'e pour l'instant
25
-		case 'mathml':
26
-			$ext = '.xhtml';
27
-			$server = $GLOBALS['mathml_server'];
28
-			break;
29
-		case 'tex':
30
-			$ext = '.png';
31
-			$server = $GLOBALS['tex_server'];
32
-			break;
33
-		default:
34
-			return $tex;
35
-	}
36
-
37
-	// Regarder dans le repertoire local des images TeX et blocs MathML
38
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
39
-		@mkdir($dir_tex, _SPIP_CHMOD);
40
-	}
41
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
42
-
43
-
44
-	// Aller chercher l'image sur le serveur
45
-	if (!@file_exists($fichier) && $server) {
46
-		spip_log($url = $server . '?' . rawurlencode($tex));
47
-		include_spip('inc/distant');
48
-		recuperer_url($url, ['file' => $fichier]);
49
-	}
50
-
51
-
52
-	// Composer la reponse selon presence ou non de l'image
53
-	$tex = entites_html($tex);
54
-	if (@file_exists($fichier)) {
55
-		// MathML
56
-		if ($GLOBALS['traiter_math'] == 'mathml') {
57
-			return implode('', file($fichier));
58
-		} // TeX
59
-		else {
60
-			[, , , $size] = @spip_getimagesize($fichier);
61
-			$alt = "alt=\"$tex\" title=\"$tex\"";
62
-
63
-			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
64
-		}
65
-	} else // pas de fichier
66
-	{
67
-		return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
68
-	}
23
+    switch ($GLOBALS['traiter_math']) {
24
+        // Attention: mathml desactiv'e pour l'instant
25
+        case 'mathml':
26
+            $ext = '.xhtml';
27
+            $server = $GLOBALS['mathml_server'];
28
+            break;
29
+        case 'tex':
30
+            $ext = '.png';
31
+            $server = $GLOBALS['tex_server'];
32
+            break;
33
+        default:
34
+            return $tex;
35
+    }
36
+
37
+    // Regarder dans le repertoire local des images TeX et blocs MathML
38
+    if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
39
+        @mkdir($dir_tex, _SPIP_CHMOD);
40
+    }
41
+    $fichier = $dir_tex . md5(trim($tex)) . $ext;
42
+
43
+
44
+    // Aller chercher l'image sur le serveur
45
+    if (!@file_exists($fichier) && $server) {
46
+        spip_log($url = $server . '?' . rawurlencode($tex));
47
+        include_spip('inc/distant');
48
+        recuperer_url($url, ['file' => $fichier]);
49
+    }
50
+
51
+
52
+    // Composer la reponse selon presence ou non de l'image
53
+    $tex = entites_html($tex);
54
+    if (@file_exists($fichier)) {
55
+        // MathML
56
+        if ($GLOBALS['traiter_math'] == 'mathml') {
57
+            return implode('', file($fichier));
58
+        } // TeX
59
+        else {
60
+            [, , , $size] = @spip_getimagesize($fichier);
61
+            $alt = "alt=\"$tex\" title=\"$tex\"";
62
+
63
+            return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
64
+        }
65
+    } else // pas de fichier
66
+    {
67
+        return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
68
+    }
69 69
 }
70 70
 
71 71
 
@@ -100,52 +100,52 @@  discard block
 block discarded – undo
100 100
  */
101 101
 function traiter_math($letexte, $source = '', $defaire_amp = false) {
102 102
 
103
-	$texte_a_voir = $letexte;
104
-	while (($debut = strpos($texte_a_voir, '<math>')) !== false) {
105
-		if (!$fin = strpos($texte_a_voir, '</math>')) {
106
-			$fin = strlen($texte_a_voir);
107
-		}
108
-
109
-		$texte_debut = substr($texte_a_voir, 0, $debut);
110
-		$texte_milieu = substr(
111
-			$texte_a_voir,
112
-			$debut + strlen('<math>'),
113
-			$fin - $debut - strlen('<math>')
114
-		);
115
-		$texte_fin = substr(
116
-			$texte_a_voir,
117
-			$fin + strlen('</math>'),
118
-			strlen($texte_a_voir)
119
-		);
120
-
121
-		// Les doubles $$x^2$$ en mode 'div'
122
-		while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) {
123
-			$expression = $regs[1];
124
-			if ($defaire_amp) {
125
-				$expression = str_replace('&amp;', '&', $expression);
126
-			}
127
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
128
-			$pos = strpos($texte_milieu, (string) $regs[0]);
129
-			$texte_milieu = substr($texte_milieu, 0, $pos)
130
-				. code_echappement($echap, $source)
131
-				. substr($texte_milieu, $pos + strlen($regs[0]));
132
-		}
133
-
134
-		// Les simples $x^2$ en mode 'span'
135
-		while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) {
136
-			$expression = $regs[1];
137
-			if ($defaire_amp) {
138
-				$expression = str_replace('&amp;', '&', $expression);
139
-			}
140
-			$echap = produire_image_math($expression);
141
-			$pos = strpos($texte_milieu, (string) $regs[0]);
142
-			$texte_milieu = substr($texte_milieu, 0, $pos)
143
-				. code_echappement($echap, $source)
144
-				. substr($texte_milieu, $pos + strlen($regs[0]));
145
-		}
146
-
147
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
148
-	}
149
-
150
-	return $texte_a_voir;
103
+    $texte_a_voir = $letexte;
104
+    while (($debut = strpos($texte_a_voir, '<math>')) !== false) {
105
+        if (!$fin = strpos($texte_a_voir, '</math>')) {
106
+            $fin = strlen($texte_a_voir);
107
+        }
108
+
109
+        $texte_debut = substr($texte_a_voir, 0, $debut);
110
+        $texte_milieu = substr(
111
+            $texte_a_voir,
112
+            $debut + strlen('<math>'),
113
+            $fin - $debut - strlen('<math>')
114
+        );
115
+        $texte_fin = substr(
116
+            $texte_a_voir,
117
+            $fin + strlen('</math>'),
118
+            strlen($texte_a_voir)
119
+        );
120
+
121
+        // Les doubles $$x^2$$ en mode 'div'
122
+        while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) {
123
+            $expression = $regs[1];
124
+            if ($defaire_amp) {
125
+                $expression = str_replace('&amp;', '&', $expression);
126
+            }
127
+            $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
128
+            $pos = strpos($texte_milieu, (string) $regs[0]);
129
+            $texte_milieu = substr($texte_milieu, 0, $pos)
130
+                . code_echappement($echap, $source)
131
+                . substr($texte_milieu, $pos + strlen($regs[0]));
132
+        }
133
+
134
+        // Les simples $x^2$ en mode 'span'
135
+        while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) {
136
+            $expression = $regs[1];
137
+            if ($defaire_amp) {
138
+                $expression = str_replace('&amp;', '&', $expression);
139
+            }
140
+            $echap = produire_image_math($expression);
141
+            $pos = strpos($texte_milieu, (string) $regs[0]);
142
+            $texte_milieu = substr($texte_milieu, 0, $pos)
143
+                . code_echappement($echap, $source)
144
+                . substr($texte_milieu, $pos + strlen($regs[0]));
145
+        }
146
+
147
+        $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
148
+    }
149
+
150
+    return $texte_a_voir;
151 151
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,15 +35,15 @@  discard block
 block discarded – undo
35 35
 	}
36 36
 
37 37
 	// Regarder dans le repertoire local des images TeX et blocs MathML
38
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
38
+	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) {
39 39
 		@mkdir($dir_tex, _SPIP_CHMOD);
40 40
 	}
41
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
41
+	$fichier = $dir_tex.md5(trim($tex)).$ext;
42 42
 
43 43
 
44 44
 	// Aller chercher l'image sur le serveur
45 45
 	if (!@file_exists($fichier) && $server) {
46
-		spip_log($url = $server . '?' . rawurlencode($tex));
46
+		spip_log($url = $server.'?'.rawurlencode($tex));
47 47
 		include_spip('inc/distant');
48 48
 		recuperer_url($url, ['file' => $fichier]);
49 49
 	}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 			return implode('', file($fichier));
58 58
 		} // TeX
59 59
 		else {
60
-			[, , , $size] = @spip_getimagesize($fichier);
60
+			[,,, $size] = @spip_getimagesize($fichier);
61 61
 			$alt = "alt=\"$tex\" title=\"$tex\"";
62 62
 
63 63
 			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 			if ($defaire_amp) {
125 125
 				$expression = str_replace('&amp;', '&', $expression);
126 126
 			}
127
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
127
+			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n";
128 128
 			$pos = strpos($texte_milieu, (string) $regs[0]);
129 129
 			$texte_milieu = substr($texte_milieu, 0, $pos)
130 130
 				. code_echappement($echap, $source)
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 				. substr($texte_milieu, $pos + strlen($regs[0]));
145 145
 		}
146 146
 
147
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
147
+		$texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
148 148
 	}
149 149
 
150 150
 	return $texte_a_voir;
Please login to merge, or discard this patch.
ecrire/inc/cvt_configurer.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 include_spip('inc/config');
@@ -31,31 +31,31 @@  discard block
 block discarded – undo
31 31
  * @return array|false
32 32
  */
33 33
 function cvtconf_formulaire_charger($flux) {
34
-	if (
35
-		($form = $flux['args']['form'])
36
-		&& str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
37
-	) {
38
-		// Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
39
-		include_spip('inc/autoriser');
40
-		if (!autoriser('configurer', '_' . substr($form, 11))) {
41
-			return false;
42
-		}
34
+    if (
35
+        ($form = $flux['args']['form'])
36
+        && str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
37
+    ) {
38
+        // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
39
+        include_spip('inc/autoriser');
40
+        if (!autoriser('configurer', '_' . substr($form, 11))) {
41
+            return false;
42
+        }
43 43
 
44
-		// S'il n'y a pas de fonction charger(), on génère un contexte automatiquement
45
-		if (!charger_fonction('charger', "formulaires/$form/", true)) {
46
-			$flux['data'] = cvtconf_formulaires_configurer_recense($form);
47
-			$flux['data']['editable'] = true;
48
-			if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
49
-				if (!_AJAX) {
50
-					var_dump($flux['data']);
51
-				}
52
-				// reinjecter pour la trace au traitement
53
-				$flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />";
54
-			}
55
-		}
56
-	}
44
+        // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement
45
+        if (!charger_fonction('charger', "formulaires/$form/", true)) {
46
+            $flux['data'] = cvtconf_formulaires_configurer_recense($form);
47
+            $flux['data']['editable'] = true;
48
+            if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
49
+                if (!_AJAX) {
50
+                    var_dump($flux['data']);
51
+                }
52
+                // reinjecter pour la trace au traitement
53
+                $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />";
54
+            }
55
+        }
56
+    }
57 57
 
58
-	return $flux;
58
+    return $flux;
59 59
 }
60 60
 
61 61
 /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
  * @return array
66 66
  */
67 67
 function cvtconf_formulaire_traiter($flux) {
68
-	if (
69
-		($form = $flux['args']['form'])
70
-		&& str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
71
-		&& !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
72
-	) {
73
-		$trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
74
-		$flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
75
-	}
68
+    if (
69
+        ($form = $flux['args']['form'])
70
+        && str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
71
+        && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
72
+    ) {
73
+        $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
74
+        $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
75
+    }
76 76
 
77
-	return $flux;
77
+    return $flux;
78 78
 }
79 79
 
80 80
 /**
@@ -90,32 +90,32 @@  discard block
 block discarded – undo
90 90
  * @return string
91 91
  */
92 92
 function cvtconf_formulaires_configurer_enregistre($form, $args) {
93
-	$valeurs = [];
94
-	// charger les valeurs
95
-	// ce qui permet de prendre en charge une fonction charger() existante
96
-	// qui prend alors la main sur l'auto detection
97
-	if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) {
98
-		$valeurs = $charger_valeurs(...$args);
99
-	}
100
-	$valeurs = pipeline(
101
-		'formulaire_charger',
102
-		[
103
-			'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false],
104
-			'data' => $valeurs
105
-		]
106
-	);
107
-	// ne pas stocker editable !
108
-	unset($valeurs['editable']);
93
+    $valeurs = [];
94
+    // charger les valeurs
95
+    // ce qui permet de prendre en charge une fonction charger() existante
96
+    // qui prend alors la main sur l'auto detection
97
+    if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) {
98
+        $valeurs = $charger_valeurs(...$args);
99
+    }
100
+    $valeurs = pipeline(
101
+        'formulaire_charger',
102
+        [
103
+            'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false],
104
+            'data' => $valeurs
105
+        ]
106
+    );
107
+    // ne pas stocker editable !
108
+    unset($valeurs['editable']);
109 109
 
110
-	// recuperer les valeurs postees
111
-	$store = [];
112
-	foreach ($valeurs as $k => $v) {
113
-		if (!str_starts_with($k, '_')) {
114
-			$store[$k] = _request($k);
115
-		}
116
-	}
110
+    // recuperer les valeurs postees
111
+    $store = [];
112
+    foreach ($valeurs as $k => $v) {
113
+        if (!str_starts_with($k, '_')) {
114
+            $store[$k] = _request($k);
115
+        }
116
+    }
117 117
 
118
-	return cvtconf_configurer_stocker($form, $valeurs, $store);
118
+    return cvtconf_configurer_stocker($form, $valeurs, $store);
119 119
 }
120 120
 
121 121
 /**
@@ -131,31 +131,31 @@  discard block
 block discarded – undo
131 131
  * @return array
132 132
  */
133 133
 function cvtconf_definir_configurer_conteneur($form, $valeurs) {
134
-	// stocker en base
135
-	// par defaut, dans un casier serialize dans spip_meta (idem CFG)
136
-	$casier = substr($form, 11);
137
-	$table = 'meta';
138
-	$prefixe = '';
139
-	$stockage = '';
134
+    // stocker en base
135
+    // par defaut, dans un casier serialize dans spip_meta (idem CFG)
136
+    $casier = substr($form, 11);
137
+    $table = 'meta';
138
+    $prefixe = '';
139
+    $stockage = '';
140 140
 
141
-	if (isset($valeurs['_meta_casier'])) {
142
-		$casier = $valeurs['_meta_casier'];
143
-	}
144
-	if (isset($valeurs['_meta_prefixe'])) {
145
-		$prefixe = $valeurs['_meta_prefixe'];
146
-	}
147
-	if (isset($valeurs['_meta_stockage'])) {
148
-		$stockage = $valeurs['_meta_stockage'] . '::';
149
-	}
141
+    if (isset($valeurs['_meta_casier'])) {
142
+        $casier = $valeurs['_meta_casier'];
143
+    }
144
+    if (isset($valeurs['_meta_prefixe'])) {
145
+        $prefixe = $valeurs['_meta_prefixe'];
146
+    }
147
+    if (isset($valeurs['_meta_stockage'])) {
148
+        $stockage = $valeurs['_meta_stockage'] . '::';
149
+    }
150 150
 
151
-	// si on indique juste une table, il faut vider les autres proprietes
152
-	// car par defaut on utilise ni casier ni prefixe dans ce cas
153
-	if (isset($valeurs['_meta_table'])) {
154
-		$table = $valeurs['_meta_table'];
155
-		$casier = ($valeurs['_meta_casier'] ?? '');
156
-	}
151
+    // si on indique juste une table, il faut vider les autres proprietes
152
+    // car par defaut on utilise ni casier ni prefixe dans ce cas
153
+    if (isset($valeurs['_meta_table'])) {
154
+        $table = $valeurs['_meta_table'];
155
+        $casier = ($valeurs['_meta_casier'] ?? '');
156
+    }
157 157
 
158
-	return [$table, $casier, $prefixe, $stockage];
158
+    return [$table, $casier, $prefixe, $stockage];
159 159
 }
160 160
 
161 161
 /**
@@ -166,49 +166,49 @@  discard block
 block discarded – undo
166 166
  * @return array
167 167
  */
168 168
 function cvtconf_formulaires_configurer_recense($form) {
169
-	$contenu = null;
170
-	$valeurs = ['editable' => ' '];
169
+    $contenu = null;
170
+    $valeurs = ['editable' => ' '];
171 171
 
172
-	// sinon cas analyse du squelette
173
-	if (
174
-		($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/'))
175
-		&& lire_fichier($f, $contenu)
176
-	) {
177
-		for ($i = 0; $i < 2; $i++) {
178
-			// a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
179
-			// permet de trouver aussi les name="#GET{truc}"
180
-			if ($i == 1) {
181
-				$contenu = recuperer_fond("formulaires/$form", $valeurs);
182
-			}
172
+    // sinon cas analyse du squelette
173
+    if (
174
+        ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/'))
175
+        && lire_fichier($f, $contenu)
176
+    ) {
177
+        for ($i = 0; $i < 2; $i++) {
178
+            // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
179
+            // permet de trouver aussi les name="#GET{truc}"
180
+            if ($i == 1) {
181
+                $contenu = recuperer_fond("formulaires/$form", $valeurs);
182
+            }
183 183
 
184
-			$balises = array_merge(
185
-				extraire_balises($contenu, 'input'),
186
-				extraire_balises($contenu, 'textarea'),
187
-				extraire_balises($contenu, 'select')
188
-			);
184
+            $balises = array_merge(
185
+                extraire_balises($contenu, 'input'),
186
+                extraire_balises($contenu, 'textarea'),
187
+                extraire_balises($contenu, 'select')
188
+            );
189 189
 
190
-			foreach ($balises as $b) {
191
-				if (
192
-					($n = extraire_attribut($b, 'name'))
193
-					&& preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r)
194
-					&& !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign'])
195
-					&& extraire_attribut($b, 'type') !== 'submit'
196
-				) {
197
-					$valeurs[$r[1]] = '';
198
-					// recuperer les valeurs _meta_xx qui peuvent etre fournies
199
-					// en input hidden dans le squelette
200
-					if (str_starts_with($r[1], '_meta_')) {
201
-						$valeurs[$r[1]] = extraire_attribut($b, 'value');
202
-					}
203
-				}
204
-			}
205
-		}
206
-	}
190
+            foreach ($balises as $b) {
191
+                if (
192
+                    ($n = extraire_attribut($b, 'name'))
193
+                    && preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r)
194
+                    && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign'])
195
+                    && extraire_attribut($b, 'type') !== 'submit'
196
+                ) {
197
+                    $valeurs[$r[1]] = '';
198
+                    // recuperer les valeurs _meta_xx qui peuvent etre fournies
199
+                    // en input hidden dans le squelette
200
+                    if (str_starts_with($r[1], '_meta_')) {
201
+                        $valeurs[$r[1]] = extraire_attribut($b, 'value');
202
+                    }
203
+                }
204
+            }
205
+        }
206
+    }
207 207
 
208 208
 
209
-	cvtconf_configurer_lire_meta($form, $valeurs);
209
+    cvtconf_configurer_lire_meta($form, $valeurs);
210 210
 
211
-	return $valeurs;
211
+    return $valeurs;
212 212
 }
213 213
 
214 214
 /**
@@ -220,26 +220,26 @@  discard block
 block discarded – undo
220 220
  * @return string
221 221
  */
222 222
 function cvtconf_configurer_stocker($form, $valeurs, $store) {
223
-	$trace = '';
224
-	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
225
-	// stocker en base
226
-	// par defaut, dans un casier serialize dans spip_meta (idem CFG)
227
-	if (!isset($GLOBALS[$table])) {
228
-		lire_metas($table);
229
-	}
223
+    $trace = '';
224
+    [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
225
+    // stocker en base
226
+    // par defaut, dans un casier serialize dans spip_meta (idem CFG)
227
+    if (!isset($GLOBALS[$table])) {
228
+        lire_metas($table);
229
+    }
230 230
 
231
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
232
-	$table = ($table) ? "/$table/" : '';
233
-	$casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien
231
+    $prefixe = ($prefixe ? $prefixe . '_' : '');
232
+    $table = ($table) ? "/$table/" : '';
233
+    $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien
234 234
 
235
-	foreach ($store as $k => $v) {
236
-		ecrire_config("$stockage$table$prefixe$casier$k", $v);
237
-		if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
238
-			$trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
239
-		}
240
-	}
235
+    foreach ($store as $k => $v) {
236
+        ecrire_config("$stockage$table$prefixe$casier$k", $v);
237
+        if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
238
+            $trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
239
+        }
240
+    }
241 241
 
242
-	return $trace;
242
+    return $trace;
243 243
 }
244 244
 
245 245
 /**
@@ -249,21 +249,21 @@  discard block
 block discarded – undo
249 249
  * @param array $valeurs
250 250
  */
251 251
 function cvtconf_configurer_lire_meta($form, &$valeurs) {
252
-	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
252
+    [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
253 253
 
254
-	$table = ($table) ? "/$table/" : '';
255
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
256
-	if ($casier) {
257
-		$meta = lire_config("$stockage$table$prefixe$casier");
258
-		$prefixe = '';
259
-	} else {
260
-		$table = rtrim($table, '/');
261
-		$meta = lire_config("$stockage$table");
262
-	}
254
+    $table = ($table) ? "/$table/" : '';
255
+    $prefixe = ($prefixe ? $prefixe . '_' : '');
256
+    if ($casier) {
257
+        $meta = lire_config("$stockage$table$prefixe$casier");
258
+        $prefixe = '';
259
+    } else {
260
+        $table = rtrim($table, '/');
261
+        $meta = lire_config("$stockage$table");
262
+    }
263 263
 
264
-	foreach (array_keys($valeurs) as $k) {
265
-		if (!str_starts_with($k, '_')) {
266
-			$valeurs[$k] = ($meta[$prefixe . $k] ?? null);
267
-		}
268
-	}
264
+    foreach (array_keys($valeurs) as $k) {
265
+        if (!str_starts_with($k, '_')) {
266
+            $valeurs[$k] = ($meta[$prefixe . $k] ?? null);
267
+        }
268
+    }
269 269
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	) {
38 38
 		// Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
39 39
 		include_spip('inc/autoriser');
40
-		if (!autoriser('configurer', '_' . substr($form, 11))) {
40
+		if (!autoriser('configurer', '_'.substr($form, 11))) {
41 41
 			return false;
42 42
 		}
43 43
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		&& !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
72 72
 	) {
73 73
 		$trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
74
-		$flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
74
+		$flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true];
75 75
 	}
76 76
 
77 77
 	return $flux;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$prefixe = $valeurs['_meta_prefixe'];
146 146
 	}
147 147
 	if (isset($valeurs['_meta_stockage'])) {
148
-		$stockage = $valeurs['_meta_stockage'] . '::';
148
+		$stockage = $valeurs['_meta_stockage'].'::';
149 149
 	}
150 150
 
151 151
 	// si on indique juste une table, il faut vider les autres proprietes
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
 	// sinon cas analyse du squelette
173 173
 	if (
174
-		($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/'))
174
+		($f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/'))
175 175
 		&& lire_fichier($f, $contenu)
176 176
 	) {
177 177
 		for ($i = 0; $i < 2; $i++) {
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
 		lire_metas($table);
229 229
 	}
230 230
 
231
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
231
+	$prefixe = ($prefixe ? $prefixe.'_' : '');
232 232
 	$table = ($table) ? "/$table/" : '';
233
-	$casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien
233
+	$casier = ($casier) ? rtrim($casier, '/').'/' : ''; // slash final, sinon rien
234 234
 
235 235
 	foreach ($store as $k => $v) {
236 236
 		ecrire_config("$stockage$table$prefixe$casier$k", $v);
237 237
 		if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
238
-			$trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
238
+			$trace .= "<br />table $table : ".$prefixe.$k." = $v;";
239 239
 		}
240 240
 	}
241 241
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
253 253
 
254 254
 	$table = ($table) ? "/$table/" : '';
255
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
255
+	$prefixe = ($prefixe ? $prefixe.'_' : '');
256 256
 	if ($casier) {
257 257
 		$meta = lire_config("$stockage$table$prefixe$casier");
258 258
 		$prefixe = '';
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 
264 264
 	foreach (array_keys($valeurs) as $k) {
265 265
 		if (!str_starts_with($k, '_')) {
266
-			$valeurs[$k] = ($meta[$prefixe . $k] ?? null);
266
+			$valeurs[$k] = ($meta[$prefixe.$k] ?? null);
267 267
 		}
268 268
 	}
269 269
 }
Please login to merge, or discard this patch.