Completed
Push — master ( 0df2ac...a4a09d )
by cam
01:04
created
ecrire/inc/install.php 1 patch
Indentation   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
  * @return void
44 44
  **/
45 45
 function install_fichier_connexion($nom, $texte) {
46
-	$texte = '<' . "?php\n"
47
-		. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
-		. $texte
49
-		. '?' . '>';
46
+    $texte = '<' . "?php\n"
47
+        . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
48
+        . $texte
49
+        . '?' . '>';
50 50
 
51
-	ecrire_fichier($nom, $texte);
51
+    ecrire_fichier($nom, $texte);
52 52
 }
53 53
 
54 54
 
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
  *
78 78
  **/
79 79
 function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') {
80
-	$adr = addcslashes($adr, "'\\");
81
-	$port = addcslashes($port, "'\\");
82
-	$login = addcslashes($login, "'\\");
83
-	$pass = addcslashes($pass, "'\\");
84
-	$base = addcslashes($base, "'\\");
85
-	$type = addcslashes($type, "'\\");
86
-	$pref = addcslashes($pref, "'\\");
87
-	$ldap = addcslashes($ldap, "'\\");
88
-	$charset = addcslashes($charset, "'\\");
89
-
90
-	return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
91
-	. 'spip_connect_db('
92
-	. "'$adr','$port','$login','$pass','$base'"
93
-	. ",'$type', '$pref','$ldap','$charset');\n";
80
+    $adr = addcslashes($adr, "'\\");
81
+    $port = addcslashes($port, "'\\");
82
+    $login = addcslashes($login, "'\\");
83
+    $pass = addcslashes($pass, "'\\");
84
+    $base = addcslashes($base, "'\\");
85
+    $type = addcslashes($type, "'\\");
86
+    $pref = addcslashes($pref, "'\\");
87
+    $ldap = addcslashes($ldap, "'\\");
88
+    $charset = addcslashes($charset, "'\\");
89
+
90
+    return "\$GLOBALS['spip_connect_version'] = 0.8;\n"
91
+    . 'spip_connect_db('
92
+    . "'$adr','$port','$login','$pass','$base'"
93
+    . ",'$type', '$pref','$ldap','$charset');\n";
94 94
 }
95 95
 
96 96
 
@@ -106,26 +106,26 @@  discard block
 block discarded – undo
106 106
  *     Tableau des informations sur la connexion
107 107
  **/
108 108
 function analyse_fichier_connection($file) {
109
-	$s = @join('', file($file));
110
-	if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
111
-		array_shift($regs);
112
-
113
-		return $regs;
114
-	} else {
115
-		$ar = '\s*\'([^\']*)\'';
116
-		$r = '\s*,' . $ar;
117
-		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118
-		if (preg_match($r, $s, $regs)) {
119
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
120
-			array_shift($regs);
121
-			array_shift($regs);
122
-
123
-			return $regs;
124
-		}
125
-	}
126
-	spip_log("$file n'est pas un fichier de connexion");
127
-
128
-	return [];
109
+    $s = @join('', file($file));
110
+    if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
111
+        array_shift($regs);
112
+
113
+        return $regs;
114
+    } else {
115
+        $ar = '\s*\'([^\']*)\'';
116
+        $r = '\s*,' . $ar;
117
+        $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#";
118
+        if (preg_match($r, $s, $regs)) {
119
+            $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';');
120
+            array_shift($regs);
121
+            array_shift($regs);
122
+
123
+            return $regs;
124
+        }
125
+    }
126
+    spip_log("$file n'est pas un fichier de connexion");
127
+
128
+    return [];
129 129
 }
130 130
 
131 131
 /**
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
  *     Liste des noms de connecteurs
143 143
  **/
144 144
 function bases_referencees($exclu = '') {
145
-	$tables = [];
146
-	foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
147
-		if ($f != $exclu and analyse_fichier_connection($f)) {
148
-			$tables[] = basename($f, '.php');
149
-		}
150
-	}
151
-
152
-	return $tables;
145
+    $tables = [];
146
+    foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
147
+        if ($f != $exclu and analyse_fichier_connection($f)) {
148
+            $tables[] = basename($f, '.php');
149
+        }
150
+    }
151
+
152
+    return $tables;
153 153
 }
154 154
 
155 155
 
156 156
 function install_mode_appel($server_db, $tout = true) {
157
-	return ($server_db != 'mysql') ? ''
158
-		: (($tout ? test_rappel_nom_base_mysql($server_db) : '')
159
-			. test_sql_mode_mysql($server_db));
157
+    return ($server_db != 'mysql') ? ''
158
+        : (($tout ? test_rappel_nom_base_mysql($server_db) : '')
159
+            . test_sql_mode_mysql($server_db));
160 160
 }
161 161
 
162 162
 //
@@ -164,52 +164,52 @@  discard block
 block discarded – undo
164 164
 // (sert a l'etape 1 de l'installation)
165 165
 // https://code.spip.net/@tester_compatibilite_hebergement
166 166
 function tester_compatibilite_hebergement() {
167
-	$err = [];
168
-
169
-	$p = phpversion();
170
-	if (version_compare($p, _PHP_MIN, '<')) {
171
-		$err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
-	}
173
-
174
-	// Si on n'a pas la bonne version de PHP, c'est la fin
175
-	if ($err) {
176
-		die("<div class='error'>"
177
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
178
-			. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179
-	}
180
-
181
-	// Il faut une base de donnees tout de meme ...
182
-	$serveurs = install_select_serveur();
183
-	if (!$serveurs) {
184
-		$err[] = _T('install_extension_php_obligatoire')
185
-			. " <a href='http://www.php.net/mysql'>MYSQL</a>"
186
-			. "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
187
-			. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
188
-	}
189
-
190
-	// et il faut preg
191
-	if (!function_exists('preg_match_all')) {
192
-		$err[] = _T('install_extension_php_obligatoire')
193
-			. " <a href='http://se.php.net/pcre'>PCRE</a>";
194
-	}
195
-
196
-	// et surtout pas ce mbstring.overload
197
-	if ($a = @ini_get('mbstring.func_overload')) {
198
-		$err[] = _T('install_extension_mbstring')
199
-			. "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
200
-	}
201
-
202
-	if ($err) {
203
-		echo "<div class='error'>"
204
-			. '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
205
-		foreach ($err as $e) {
206
-			echo "<li><strong>$e</strong></li>\n";
207
-		}
208
-
209
-		# a priori ici on pourrait die(), mais il faut laisser la possibilite
210
-		# de forcer malgre tout (pour tester, ou si bug de detection)
211
-		echo "</ul></div>\n";
212
-	}
167
+    $err = [];
168
+
169
+    $p = phpversion();
170
+    if (version_compare($p, _PHP_MIN, '<')) {
171
+        $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]);
172
+    }
173
+
174
+    // Si on n'a pas la bonne version de PHP, c'est la fin
175
+    if ($err) {
176
+        die("<div class='error'>"
177
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"
178
+            . "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
179
+    }
180
+
181
+    // Il faut une base de donnees tout de meme ...
182
+    $serveurs = install_select_serveur();
183
+    if (!$serveurs) {
184
+        $err[] = _T('install_extension_php_obligatoire')
185
+            . " <a href='http://www.php.net/mysql'>MYSQL</a>"
186
+            . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
187
+            . "| <a href='http://www.php.net/sqlite'>SQLite</a>";
188
+    }
189
+
190
+    // et il faut preg
191
+    if (!function_exists('preg_match_all')) {
192
+        $err[] = _T('install_extension_php_obligatoire')
193
+            . " <a href='http://se.php.net/pcre'>PCRE</a>";
194
+    }
195
+
196
+    // et surtout pas ce mbstring.overload
197
+    if ($a = @ini_get('mbstring.func_overload')) {
198
+        $err[] = _T('install_extension_mbstring')
199
+            . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
200
+    }
201
+
202
+    if ($err) {
203
+        echo "<div class='error'>"
204
+            . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>";
205
+        foreach ($err as $e) {
206
+            echo "<li><strong>$e</strong></li>\n";
207
+        }
208
+
209
+        # a priori ici on pourrait die(), mais il faut laisser la possibilite
210
+        # de forcer malgre tout (pour tester, ou si bug de detection)
211
+        echo "</ul></div>\n";
212
+    }
213 213
 }
214 214
 
215 215
 
@@ -219,24 +219,24 @@  discard block
 block discarded – undo
219 219
  * @note superflu ??
220 220
  */
221 221
 function login_hebergeur() {
222
-	$base_hebergeur = 'localhost'; # par defaut
222
+    $base_hebergeur = 'localhost'; # par defaut
223 223
 
224
-	// Free
225
-	if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
226
-		$base_hebergeur = 'sql.free.fr';
227
-		$login_hebergeur = $regs[1];
228
-	} else {
229
-		$login_hebergeur = '';
230
-	}
224
+    // Free
225
+    if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) {
226
+        $base_hebergeur = 'sql.free.fr';
227
+        $login_hebergeur = $regs[1];
228
+    } else {
229
+        $login_hebergeur = '';
230
+    }
231 231
 
232
-	return [$base_hebergeur, $login_hebergeur];
232
+    return [$base_hebergeur, $login_hebergeur];
233 233
 }
234 234
 
235 235
 
236 236
 // https://code.spip.net/@info_etape
237 237
 function info_etape($titre, $complement = '') {
238
-	return '<h2>' . $titre . "</h2>\n" .
239
-	($complement ? '' . $complement . "\n" : '');
238
+    return '<h2>' . $titre . "</h2>\n" .
239
+    ($complement ? '' . $complement . "\n" : '');
240 240
 }
241 241
 
242 242
 /**
@@ -246,156 +246,156 @@  discard block
 block discarded – undo
246 246
  * @return string Code HTML du bouton
247 247
  **/
248 248
 function bouton_suivant($code = '') {
249
-	if ($code == '') {
250
-		$code = _T('bouton_suivant');
251
-	}
252
-	static $suivant = 0;
253
-	$id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
254
-	$suivant += 1;
255
-
256
-	return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
-	$code .
258
-	" >>\" /></p>\n";
249
+    if ($code == '') {
250
+        $code = _T('bouton_suivant');
251
+    }
252
+    static $suivant = 0;
253
+    $id = 'suivant' . (($suivant > 0) ? strval($suivant) : '');
254
+    $suivant += 1;
255
+
256
+    return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" .
257
+    $code .
258
+    " >>\" /></p>\n";
259 259
 }
260 260
 
261 261
 // https://code.spip.net/@info_progression_etape
262 262
 function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
263
-	//$en_cours = _request('etape')?_request('etape'):"";
264
-	$liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
265
-	$debut = 1;
266
-	$etat = 'ok';
267
-	$last = count($liste);
263
+    //$en_cours = _request('etape')?_request('etape'):"";
264
+    $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$');
265
+    $debut = 1;
266
+    $etat = 'ok';
267
+    $last = count($liste);
268 268
 //	$texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo'));
269 269
 
270
-	$intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
271
-	$intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
272
-	$intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
273
-	$intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
270
+    $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee'));
271
+    $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base'));
272
+    $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles'));
273
+    $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape'));
274 274
 
275
-	$intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
276
-	$intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
277
-	$intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
278
-	$intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
279
-	$intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
275
+    $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap'));
276
+    $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap'));
277
+    $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1'));
278
+    $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap'));
279
+    $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok'));
280 280
 
281 281
 //	$aff_etapes = "<span id='etapes'>";
282 282
 
283
-	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
284
-
285
-	foreach ($liste as $etape => $fichier) {
286
-		if ($debut < $last) {
287
-			if ($debut == $en_cours && $erreur) {
288
-				$class = 'on erreur';
289
-			} else {
290
-				if ($debut == $en_cours) {
291
-					$class = 'on';
292
-				} else {
293
-					if ($debut > $en_cours) {
294
-						$class = 'prochains';
295
-					} else {
296
-						$class = 'valides';
297
-					}
298
-				}
299
-			}
300
-
301
-			$aff_etapes .= "<li class='$class'><div class='fond'>";
302
-			$aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
-			$aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304
-			$aff_etapes .= $intitule_etat["$phase"][$debut];
305
-			$aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306
-			$aff_etapes .= '</div></li>';
307
-		}
308
-		$debut++;
309
-	}
310
-	$aff_etapes .= '</ul>';
311
-	$aff_etapes .= "<br class='nettoyeur' />\n";
312
-
313
-	return $aff_etapes;
283
+    $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
284
+
285
+    foreach ($liste as $etape => $fichier) {
286
+        if ($debut < $last) {
287
+            if ($debut == $en_cours && $erreur) {
288
+                $class = 'on erreur';
289
+            } else {
290
+                if ($debut == $en_cours) {
291
+                    $class = 'on';
292
+                } else {
293
+                    if ($debut > $en_cours) {
294
+                        $class = 'prochains';
295
+                    } else {
296
+                        $class = 'valides';
297
+                    }
298
+                }
299
+            }
300
+
301
+            $aff_etapes .= "<li class='$class'><div class='fond'>";
302
+            $aff_etapes .= ($debut == $en_cours) ? '<strong>' : '';
303
+            $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
304
+            $aff_etapes .= $intitule_etat["$phase"][$debut];
305
+            $aff_etapes .= ($debut == $en_cours) ? '</strong>' : '';
306
+            $aff_etapes .= '</div></li>';
307
+        }
308
+        $debut++;
309
+    }
310
+    $aff_etapes .= '</ul>';
311
+    $aff_etapes .= "<br class='nettoyeur' />\n";
312
+
313
+    return $aff_etapes;
314 314
 }
315 315
 
316 316
 
317 317
 // https://code.spip.net/@fieldset
318 318
 function fieldset($legend, $champs = [], $apres = '', $avant = '') {
319
-	return "<fieldset>\n" .
320
-	$avant .
321
-	($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
-	fieldset_champs($champs) .
323
-	$apres .
324
-	"</fieldset>\n";
319
+    return "<fieldset>\n" .
320
+    $avant .
321
+    ($legend ? '<legend>' . $legend . "</legend>\n" : '') .
322
+    fieldset_champs($champs) .
323
+    $apres .
324
+    "</fieldset>\n";
325 325
 }
326 326
 
327 327
 function fieldset_champs($champs = []) {
328
-	$fieldset = '';
329
-	foreach ($champs as $nom => $contenu) {
330
-		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331
-		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332
-		if (isset($contenu['alternatives'])) {
333
-			$fieldset .= $contenu['label'] . "\n";
334
-			foreach ($contenu['alternatives'] as $valeur => $label) {
335
-				$fieldset .= "<input type='radio' name='" . $nom .
336
-					"' id='$nom-$valeur' value='$valeur'"
337
-					. (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338
-					. "/>\n";
339
-				$fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
340
-			}
341
-			$fieldset .= "<br />\n";
342
-		} else {
343
-			$fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
-			$fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
345
-				. (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346
-				. ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347
-				. " />\n";
348
-		}
349
-	}
350
-
351
-	return $fieldset;
328
+    $fieldset = '';
329
+    foreach ($champs as $nom => $contenu) {
330
+        $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
331
+        $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
332
+        if (isset($contenu['alternatives'])) {
333
+            $fieldset .= $contenu['label'] . "\n";
334
+            foreach ($contenu['alternatives'] as $valeur => $label) {
335
+                $fieldset .= "<input type='radio' name='" . $nom .
336
+                    "' id='$nom-$valeur' value='$valeur'"
337
+                    . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
338
+                    . "/>\n";
339
+                $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n";
340
+            }
341
+            $fieldset .= "<br />\n";
342
+        } else {
343
+            $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n";
344
+            $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'"
345
+                . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
346
+                . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '')
347
+                . " />\n";
348
+        }
349
+    }
350
+
351
+    return $fieldset;
352 352
 }
353 353
 
354 354
 function install_select_serveur() {
355
-	$options = [];
356
-	$dir = _DIR_RESTREINT . 'req/';
357
-	$d = opendir($dir);
358
-	if (!$d) {
359
-		return [];
360
-	}
361
-	while (($f = readdir($d)) !== false) {
362
-		if (
363
-			(preg_match('/^(.*)[.]php$/', $f, $s))
364
-			and is_readable($f = $dir . $f)
365
-		) {
366
-			require_once($f);
367
-			$s = $s[1];
368
-			$v = 'spip_versions_' . $s;
369
-			if (function_exists($v) and $v()) {
370
-				$titre = _T("install_select_type_$s");
371
-				// proposer mysql par defaut si dispo
372
-				$checked = ($s == 'mysql' ? " checked='checked'" : '');
373
-				$options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
-					. "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
375
-			} else {
376
-				spip_log("$s: portage indisponible");
377
-			}
378
-		}
379
-	}
380
-	sort($options);
381
-
382
-	return $options;
355
+    $options = [];
356
+    $dir = _DIR_RESTREINT . 'req/';
357
+    $d = opendir($dir);
358
+    if (!$d) {
359
+        return [];
360
+    }
361
+    while (($f = readdir($d)) !== false) {
362
+        if (
363
+            (preg_match('/^(.*)[.]php$/', $f, $s))
364
+            and is_readable($f = $dir . $f)
365
+        ) {
366
+            require_once($f);
367
+            $s = $s[1];
368
+            $v = 'spip_versions_' . $s;
369
+            if (function_exists($v) and $v()) {
370
+                $titre = _T("install_select_type_$s");
371
+                // proposer mysql par defaut si dispo
372
+                $checked = ($s == 'mysql' ? " checked='checked'" : '');
373
+                $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>"
374
+                    . "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>';
375
+            } else {
376
+                spip_log("$s: portage indisponible");
377
+            }
378
+        }
379
+    }
380
+    sort($options);
381
+
382
+    return $options;
383 383
 }
384 384
 
385 385
 // https://code.spip.net/@install_connexion_form
386 386
 function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) {
387
-	$server_db = (is_string($predef[0])) ? $predef[0] : '';
388
-
389
-	return generer_form_ecrire('install', (
390
-		"\n<input type='hidden' name='etape' value='$etape' />"
391
-		. $hidden
392
-		. (_request('echec') ?
393
-			('<p><b>' . _T('avis_connexion_echec_1') .
394
-				'</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
-			: '')
396
-
397
-		. ($jquery ? http_script('', 'jquery.js') : '')
398
-		. http_script('
387
+    $server_db = (is_string($predef[0])) ? $predef[0] : '';
388
+
389
+    return generer_form_ecrire('install', (
390
+        "\n<input type='hidden' name='etape' value='$etape' />"
391
+        . $hidden
392
+        . (_request('echec') ?
393
+            ('<p><b>' . _T('avis_connexion_echec_1') .
394
+                '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>')
395
+            : '')
396
+
397
+        . ($jquery ? http_script('', 'jquery.js') : '')
398
+        . http_script('
399 399
 		jQuery(function($) {
400 400
 			$details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur");
401 401
 			$("input[type=hidden][name=server_db]").each(function(){
@@ -428,70 +428,70 @@  discard block
 block discarded – undo
428 428
 			});
429 429
 		});')
430 430
 
431
-		. ($server_db
432
-			? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
-			. (($predef[0])
434
-				? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
-				: '')
436
-			: ('<fieldset><legend>'
437
-				. _T('install_select_type_db')
438
-				. '</legend>'
439
-				. '<p class="explication">'
440
-				. _T('install_types_db_connus')
441
-				// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
-				// . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
-				. '</p>'
444
-				. "\n<div class='p'>\n<ul>\n"
445
-				. join("\n", install_select_serveur())
446
-				. "\n</ul>\n</div></fieldset>")
447
-		)
448
-		. '<div id="install_adresse_base_hebergeur">'
449
-		. '<p>' . _T('texte_connexion_mysql') . '</p>'
450
-		. ($predef[1]
451
-			? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
-			: fieldset(
453
-				_T('entree_base_donnee_1'),
454
-				[
455
-					'adresse_db' => [
456
-						'label' => $db[1],
457
-						'valeur' => $db[0]
458
-					],
459
-				]
460
-			)
461
-		)
462
-		. '</div>'
463
-
464
-		. '<div id="install_login_base_hebergeur">'
465
-		. ($predef[2]
466
-			? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
-			: fieldset(
468
-				_T('entree_login_connexion_1'),
469
-				[
470
-					'login_db' => [
471
-						'label' => $login[1],
472
-						'valeur' => $login[0]
473
-					],
474
-				]
475
-			)
476
-		)
477
-		. '</div>'
478
-
479
-		. '<div id="install_pass_base_hebergeur">'
480
-		. ($predef[3]
481
-			? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
-			: fieldset(
483
-				_T('entree_mot_passe_1'),
484
-				[
485
-					'pass_db' => [
486
-						'label' => $pass[1],
487
-						'valeur' => $pass[0]
488
-					],
489
-				]
490
-			)
491
-		)
492
-		. '</div>'
493
-
494
-		. bouton_suivant()));
431
+        . ($server_db
432
+            ? '<input type="hidden" name="server_db" value="' . $server_db . '" />'
433
+            . (($predef[0])
434
+                ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>')
435
+                : '')
436
+            : ('<fieldset><legend>'
437
+                . _T('install_select_type_db')
438
+                . '</legend>'
439
+                . '<p class="explication">'
440
+                . _T('install_types_db_connus')
441
+                // Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
442
+                // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
443
+                . '</p>'
444
+                . "\n<div class='p'>\n<ul>\n"
445
+                . join("\n", install_select_serveur())
446
+                . "\n</ul>\n</div></fieldset>")
447
+        )
448
+        . '<div id="install_adresse_base_hebergeur">'
449
+        . '<p>' . _T('texte_connexion_mysql') . '</p>'
450
+        . ($predef[1]
451
+            ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>'
452
+            : fieldset(
453
+                _T('entree_base_donnee_1'),
454
+                [
455
+                    'adresse_db' => [
456
+                        'label' => $db[1],
457
+                        'valeur' => $db[0]
458
+                    ],
459
+                ]
460
+            )
461
+        )
462
+        . '</div>'
463
+
464
+        . '<div id="install_login_base_hebergeur">'
465
+        . ($predef[2]
466
+            ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>'
467
+            : fieldset(
468
+                _T('entree_login_connexion_1'),
469
+                [
470
+                    'login_db' => [
471
+                        'label' => $login[1],
472
+                        'valeur' => $login[0]
473
+                    ],
474
+                ]
475
+            )
476
+        )
477
+        . '</div>'
478
+
479
+        . '<div id="install_pass_base_hebergeur">'
480
+        . ($predef[3]
481
+            ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>'
482
+            : fieldset(
483
+                _T('entree_mot_passe_1'),
484
+                [
485
+                    'pass_db' => [
486
+                        'label' => $pass[1],
487
+                        'valeur' => $pass[0]
488
+                    ],
489
+                ]
490
+            )
491
+        )
492
+        . '</div>'
493
+
494
+        . bouton_suivant()));
495 495
 }
496 496
 
497 497
 // 4 valeurs qu'on reconduit d'un script a l'autre
@@ -499,76 +499,76 @@  discard block
 block discarded – undo
499 499
 
500 500
 // https://code.spip.net/@predef_ou_cache
501 501
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) {
502
-	return ((defined('_INSTALL_HOST_DB'))
503
-		? ''
504
-		: "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
505
-	)
506
-	. ((defined('_INSTALL_USER_DB'))
507
-		? ''
508
-		: "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
509
-	)
510
-	. ((defined('_INSTALL_PASS_DB'))
511
-		? ''
512
-		: "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
513
-	)
514
-
515
-	. ((defined('_INSTALL_SERVER_DB'))
516
-		? ''
517
-		: "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
518
-	);
502
+    return ((defined('_INSTALL_HOST_DB'))
503
+        ? ''
504
+        : "\n<input type='hidden' name='adresse_db'  value=\"" . spip_htmlspecialchars($adresse_db) . '" />'
505
+    )
506
+    . ((defined('_INSTALL_USER_DB'))
507
+        ? ''
508
+        : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />'
509
+    )
510
+    . ((defined('_INSTALL_PASS_DB'))
511
+        ? ''
512
+        : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />'
513
+    )
514
+
515
+    . ((defined('_INSTALL_SERVER_DB'))
516
+        ? ''
517
+        : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />'
518
+    );
519 519
 }
520 520
 
521 521
 // presentation des bases existantes
522 522
 
523 523
 // https://code.spip.net/@install_etape_liste_bases
524 524
 function install_etape_liste_bases($server_db, $login_db, $disabled = []) {
525
-	$bases = $checked = [];
526
-	$noms = sql_listdbs($server_db);
527
-	if (!$noms) {
528
-		return '';
529
-	}
530
-
531
-	foreach ($noms as $nom) {
532
-		$id = spip_htmlspecialchars($nom);
533
-		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
534
-		$base = ' name="choix_db" value="'
535
-			. $nom
536
-			. '"'
537
-			. $dis
538
-			. " type='radio' id='$id'";
539
-		$label = "<label for='$id'>"
540
-			. ($dis ? "<i>$nom</i>" : $nom)
541
-			. '</label>';
542
-
543
-		if (
544
-			!$checked and !$dis and
545
-			(($nom == $login_db) or
546
-				($GLOBALS['table_prefix'] == $nom))
547
-		) {
548
-			$checked = "<input$base checked='checked' />\n$label";
549
-		} else {
550
-			$bases[] = "<input$base />\n$label";
551
-		}
552
-	}
553
-
554
-	if (!$bases && !$checked) {
555
-		return false;
556
-	}
557
-
558
-	if ($checked) {
559
-		array_unshift($bases, $checked);
560
-		$checked = true;
561
-	}
562
-
563
-	return [$checked, $bases];
525
+    $bases = $checked = [];
526
+    $noms = sql_listdbs($server_db);
527
+    if (!$noms) {
528
+        return '';
529
+    }
530
+
531
+    foreach ($noms as $nom) {
532
+        $id = spip_htmlspecialchars($nom);
533
+        $dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
534
+        $base = ' name="choix_db" value="'
535
+            . $nom
536
+            . '"'
537
+            . $dis
538
+            . " type='radio' id='$id'";
539
+        $label = "<label for='$id'>"
540
+            . ($dis ? "<i>$nom</i>" : $nom)
541
+            . '</label>';
542
+
543
+        if (
544
+            !$checked and !$dis and
545
+            (($nom == $login_db) or
546
+                ($GLOBALS['table_prefix'] == $nom))
547
+        ) {
548
+            $checked = "<input$base checked='checked' />\n$label";
549
+        } else {
550
+            $bases[] = "<input$base />\n$label";
551
+        }
552
+    }
553
+
554
+    if (!$bases && !$checked) {
555
+        return false;
556
+    }
557
+
558
+    if ($checked) {
559
+        array_unshift($bases, $checked);
560
+        $checked = true;
561
+    }
562
+
563
+    return [$checked, $bases];
564 564
 }
565 565
 
566 566
 function install_propager($hidden) {
567
-	$res = '';
568
-	foreach ($hidden as $k) {
569
-		$v = spip_htmlentities(_request($k));
570
-		$res .= "<input type='hidden' name='$k' value='$v' />";
571
-	}
567
+    $res = '';
568
+    foreach ($hidden as $k) {
569
+        $v = spip_htmlentities(_request($k));
570
+        $res .= "<input type='hidden' name='$k' value='$v' />";
571
+    }
572 572
 
573
-	return $res;
573
+    return $res;
574 574
 }
Please login to merge, or discard this patch.
ecrire/inc/icone_renommer.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -11,71 +11,71 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/boutons');
18 18
 include_spip('base/objets');
19 19
 
20 20
 function inc_icone_renommer_dist($fond, $fonction) {
21
-	$size = 24;
22
-	if (
23
-		preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match)
24
-		and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1]))
25
-	) {
26
-		if (isset($match[1]) and $match[1]) {
27
-			$size = $match[1];
28
-		}
29
-		$type = substr($fond, 0, -strlen($match[0]));
30
-		if (!isset($match[2]) or !$match[2]) {
31
-			$fond .= '.png';
32
-		}
33
-	} else {
34
-		$type = $fond;
35
-		$fond .= '.png';
36
-	}
21
+    $size = 24;
22
+    if (
23
+        preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match)
24
+        and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1]))
25
+    ) {
26
+        if (isset($match[1]) and $match[1]) {
27
+            $size = $match[1];
28
+        }
29
+        $type = substr($fond, 0, -strlen($match[0]));
30
+        if (!isset($match[2]) or !$match[2]) {
31
+            $fond .= '.png';
32
+        }
33
+    } else {
34
+        $type = $fond;
35
+        $fond .= '.png';
36
+    }
37 37
 
38
-	$rtl = false;
39
-	if (preg_match(',[-_]rtl$,i', $type, $match)) {
40
-		$rtl = true;
41
-		$type = substr($type, 0, -strlen($match[0]));
42
-	}
38
+    $rtl = false;
39
+    if (preg_match(',[-_]rtl$,i', $type, $match)) {
40
+        $rtl = true;
41
+        $type = substr($type, 0, -strlen($match[0]));
42
+    }
43 43
 
44
-	// objet_type garde invariant tout ce qui ne commence par par id_, spip_
45
-	// et ne finit pas par un s, sauf si c'est une exception declaree
46
-	$type = objet_type($type, false);
44
+    // objet_type garde invariant tout ce qui ne commence par par id_, spip_
45
+    // et ne finit pas par un s, sauf si c'est une exception declaree
46
+    $type = objet_type($type, false);
47 47
 
48
-	$dir = 'images/';
49
-	$f = "$type-$size.png";
50
-	if ($icone = find_in_theme($dir . $f)) {
51
-		$dir = dirname($icone);
52
-		$fond = $icone;
48
+    $dir = 'images/';
49
+    $f = "$type-$size.png";
50
+    if ($icone = find_in_theme($dir . $f)) {
51
+        $dir = dirname($icone);
52
+        $fond = $icone;
53 53
 
54
-		if (
55
-			$rtl
56
-			and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
57
-			and file_exists($fr)
58
-		) {
59
-			$fond = $fr;
60
-		}
54
+        if (
55
+            $rtl
56
+            and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone))
57
+            and file_exists($fr)
58
+        ) {
59
+            $fond = $fr;
60
+        }
61 61
 
62
-		$action = $fonction;
63
-		if ($action == 'supprimer.gif') {
64
-			$action = 'del';
65
-		} elseif ($action == 'creer.gif') {
66
-			$action = 'new';
67
-		} elseif ($action == 'edit.gif') {
68
-			$action = 'edit';
69
-		}
62
+        $action = $fonction;
63
+        if ($action == 'supprimer.gif') {
64
+            $action = 'del';
65
+        } elseif ($action == 'creer.gif') {
66
+            $action = 'new';
67
+        } elseif ($action == 'edit.gif') {
68
+            $action = 'edit';
69
+        }
70 70
 
71
-		$fonction = '';
72
-		if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
73
-			$fonction = $action;
74
-		}
71
+        $fonction = '';
72
+        if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
73
+            $fonction = $action;
74
+        }
75 75
 
76
-		// c'est bon !
77
-		return [$fond, $fonction];
78
-	}
76
+        // c'est bon !
77
+        return [$fond, $fonction];
78
+    }
79 79
 
80
-	return [$fond, $fonction];
80
+    return [$fond, $fonction];
81 81
 }
Please login to merge, or discard this patch.
ecrire/inc/presenter_enfants.php 1 patch
Indentation   +180 added lines, -180 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
 include_spip('inc/autoriser');
@@ -30,80 +30,80 @@  discard block
 block discarded – undo
30 30
  *  Un tableau des sous rubriques
31 31
  */
32 32
 function enfant_rub($collection, $debut = 0, $limite = 500) {
33
-	$voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non');
34
-	$logo = '';
35
-
36
-	if ($voir_logo) {
37
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
38
-		include_spip('inc/filtres_images_mini');
39
-	}
40
-
41
-	$res = [];
42
-
43
-	$result = sql_select(
44
-		'id_rubrique, id_parent, titre, descriptif, lang',
45
-		'spip_rubriques',
46
-		'id_parent=' . intval($collection),
47
-		'',
48
-		'0+titre,titre',
49
-		"$debut,$limite"
50
-	);
51
-	while ($row = sql_fetch($result)) {
52
-		$id_rubrique = $row['id_rubrique'];
53
-		$id_parent = $row['id_parent'];
54
-		// pour etre sur de passer par tous les traitements
55
-		$titre = generer_info_entite($id_rubrique, 'rubrique', 'titre');
56
-		if ('' !== ($rang = recuperer_numero($row['titre']))) {
57
-			$rang = "<span class='rang'>$rang.</span> ";
58
-		}
59
-
60
-		if (autoriser('voir', 'rubrique', $id_rubrique)) {
61
-			$les_sous_enfants = sous_enfant_rub($id_rubrique);
62
-
63
-			changer_typo($row['lang']);
64
-			$lang_dir = lang_dir($row['lang']);
65
-			$descriptif = propre($row['descriptif']);
66
-
67
-			if ($voir_logo) {
68
-				if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) {
69
-					list($fid, $dir, $nom, $format) = $logo;
70
-					$logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70);
71
-					if ($logo) {
72
-						$logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">');
73
-					}
74
-				}
75
-			}
76
-
77
-			$lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' :
78
-					http_img_pack(
79
-						'auteur-0minirezo-16.png',
80
-						'',
81
-						" width='16' height='16'",
82
-						_T('image_administrer_rubrique')
83
-					)) .
84
-				" <a class='titremlien' dir='$lang_dir'" .
85
-				($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
86
-				" href='" .
87
-				generer_url_entite($id_rubrique, 'rubrique') .
88
-				"'><span class='titre'>" .
89
-				$rang . $titre
90
-				. '</span>'
91
-				. (is_string($logo) ? $logo : '')
92
-				. '</a>';
93
-
94
-			$titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique")
95
-				. (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>")
96
-				;
97
-
98
-			$res[] =
99
-				debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
100
-				$les_sous_enfants .
101
-				fin_cadre_sous_rub(true);
102
-		}
103
-	}
104
-
105
-	changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite
106
-	return $res;
33
+    $voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non');
34
+    $logo = '';
35
+
36
+    if ($voir_logo) {
37
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
38
+        include_spip('inc/filtres_images_mini');
39
+    }
40
+
41
+    $res = [];
42
+
43
+    $result = sql_select(
44
+        'id_rubrique, id_parent, titre, descriptif, lang',
45
+        'spip_rubriques',
46
+        'id_parent=' . intval($collection),
47
+        '',
48
+        '0+titre,titre',
49
+        "$debut,$limite"
50
+    );
51
+    while ($row = sql_fetch($result)) {
52
+        $id_rubrique = $row['id_rubrique'];
53
+        $id_parent = $row['id_parent'];
54
+        // pour etre sur de passer par tous les traitements
55
+        $titre = generer_info_entite($id_rubrique, 'rubrique', 'titre');
56
+        if ('' !== ($rang = recuperer_numero($row['titre']))) {
57
+            $rang = "<span class='rang'>$rang.</span> ";
58
+        }
59
+
60
+        if (autoriser('voir', 'rubrique', $id_rubrique)) {
61
+            $les_sous_enfants = sous_enfant_rub($id_rubrique);
62
+
63
+            changer_typo($row['lang']);
64
+            $lang_dir = lang_dir($row['lang']);
65
+            $descriptif = propre($row['descriptif']);
66
+
67
+            if ($voir_logo) {
68
+                if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) {
69
+                    list($fid, $dir, $nom, $format) = $logo;
70
+                    $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70);
71
+                    if ($logo) {
72
+                        $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">');
73
+                    }
74
+                }
75
+            }
76
+
77
+            $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' :
78
+                    http_img_pack(
79
+                        'auteur-0minirezo-16.png',
80
+                        '',
81
+                        " width='16' height='16'",
82
+                        _T('image_administrer_rubrique')
83
+                    )) .
84
+                " <a class='titremlien' dir='$lang_dir'" .
85
+                ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') .
86
+                " href='" .
87
+                generer_url_entite($id_rubrique, 'rubrique') .
88
+                "'><span class='titre'>" .
89
+                $rang . $titre
90
+                . '</span>'
91
+                . (is_string($logo) ? $logo : '')
92
+                . '</a>';
93
+
94
+            $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique")
95
+                . (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>")
96
+                ;
97
+
98
+            $res[] =
99
+                debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) .
100
+                $les_sous_enfants .
101
+                fin_cadre_sous_rub(true);
102
+        }
103
+    }
104
+
105
+    changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite
106
+    return $res;
107 107
 }
108 108
 
109 109
 /**
@@ -116,71 +116,71 @@  discard block
 block discarded – undo
116 116
  *  Le contenu du bloc dépliable
117 117
  */
118 118
 function sous_enfant_rub($collection2) {
119
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2));
120
-
121
-	$retour = '';
122
-	$pagination = '';
123
-	$debut = 0;
124
-	$limite = 500;
125
-
126
-	/**
127
-	 * On ne va afficher que 500 résultats max
128
-	 * Si > 500 on affiche une pagination
129
-	 */
130
-	if ($nb > $limite) {
131
-		$debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut;
132
-		$pagination = chercher_filtre('pagination');
133
-		$pagination = '<p class="pagination">' . $pagination(
134
-			$nb,
135
-			'_rubrique' . $collection2,
136
-			$debut,
137
-			$limite,
138
-			true,
139
-			'prive'
140
-		) . '</p>';
141
-		$limite = $debut + $limite;
142
-	}
143
-
144
-	$result = sql_select(
145
-		'id_rubrique, id_parent, titre, lang',
146
-		'spip_rubriques',
147
-		'id_parent=' . intval($collection2),
148
-		'',
149
-		'0+titre,titre',
150
-		"$debut,$limite"
151
-	);
152
-
153
-	while ($row = sql_fetch($result)) {
154
-		$id_rubrique2 = $row['id_rubrique'];
155
-		$titre2 = generer_info_entite(
156
-			$id_rubrique2,
157
-			'rubrique',
158
-			'titre'
159
-		); // pour etre sur de passer par tous les traitements
160
-		if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
161
-			$rang2 = "<span class='rang'>$rang2.</span> ";
162
-		}
163
-
164
-		changer_typo($row['lang']);
165
-		$lang_dir = lang_dir($row['lang']);
166
-		if (autoriser('voir', 'rubrique', $id_rubrique2)) {
167
-			$retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite(
168
-				$id_rubrique2,
169
-				'rubrique'
170
-			) . "'>" . $rang2 . $titre2 . "</a></li>\n";
171
-		}
172
-	}
173
-
174
-	$retour = $pagination . $retour . $pagination;
175
-
176
-	if (!$retour) {
177
-		return '';
178
-	}
179
-
180
-	return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2")
181
-	. "\n<ul class='liste-items sous-sous-rub'>\n"
182
-	. $retour
183
-	. "</ul>\n" . fin_block() . "\n\n";
119
+    $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2));
120
+
121
+    $retour = '';
122
+    $pagination = '';
123
+    $debut = 0;
124
+    $limite = 500;
125
+
126
+    /**
127
+     * On ne va afficher que 500 résultats max
128
+     * Si > 500 on affiche une pagination
129
+     */
130
+    if ($nb > $limite) {
131
+        $debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut;
132
+        $pagination = chercher_filtre('pagination');
133
+        $pagination = '<p class="pagination">' . $pagination(
134
+            $nb,
135
+            '_rubrique' . $collection2,
136
+            $debut,
137
+            $limite,
138
+            true,
139
+            'prive'
140
+        ) . '</p>';
141
+        $limite = $debut + $limite;
142
+    }
143
+
144
+    $result = sql_select(
145
+        'id_rubrique, id_parent, titre, lang',
146
+        'spip_rubriques',
147
+        'id_parent=' . intval($collection2),
148
+        '',
149
+        '0+titre,titre',
150
+        "$debut,$limite"
151
+    );
152
+
153
+    while ($row = sql_fetch($result)) {
154
+        $id_rubrique2 = $row['id_rubrique'];
155
+        $titre2 = generer_info_entite(
156
+            $id_rubrique2,
157
+            'rubrique',
158
+            'titre'
159
+        ); // pour etre sur de passer par tous les traitements
160
+        if ('' !== ($rang2 = recuperer_numero($row['titre']))) {
161
+            $rang2 = "<span class='rang'>$rang2.</span> ";
162
+        }
163
+
164
+        changer_typo($row['lang']);
165
+        $lang_dir = lang_dir($row['lang']);
166
+        if (autoriser('voir', 'rubrique', $id_rubrique2)) {
167
+            $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite(
168
+                $id_rubrique2,
169
+                'rubrique'
170
+            ) . "'>" . $rang2 . $titre2 . "</a></li>\n";
171
+        }
172
+    }
173
+
174
+    $retour = $pagination . $retour . $pagination;
175
+
176
+    if (!$retour) {
177
+        return '';
178
+    }
179
+
180
+    return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2")
181
+    . "\n<ul class='liste-items sous-sous-rub'>\n"
182
+    . $retour
183
+    . "</ul>\n" . fin_block() . "\n\n";
184 184
 }
185 185
 
186 186
 /**
@@ -195,44 +195,44 @@  discard block
 block discarded – undo
195 195
  *  Le contenu textuel affiché, la liste des sous rubriques
196 196
  */
197 197
 function afficher_enfant_rub($id_rubrique = 0) {
198
-	$pagination = '';
199
-	$debut = 0;
200
-	$limite = 500;
201
-
202
-	$nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique));
203
-
204
-	if ($nb > $limite) {
205
-		$debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut;
206
-		$pagination = chercher_filtre('pagination');
207
-		$pagination = '<br class="nettoyeur"><p class="pagination">' .
208
-			$pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
209
-		'</p>';
210
-	}
211
-
212
-	$les_enfants = enfant_rub($id_rubrique, $debut, $limite);
213
-
214
-	if (!$n = count($les_enfants)) {
215
-		return '';
216
-	}
217
-
218
-	if ($n == 1) {
219
-		$les_enfants = reset($les_enfants);
220
-		$les_enfants2 = '';
221
-	} else {
222
-		$n = ceil($n / 2);
223
-		$les_enfants2 = implode('', array_slice($les_enfants, $n));
224
-		$les_enfants = implode('', array_slice($les_enfants, 0, $n));
225
-	}
226
-
227
-	$res =
228
-		$pagination
229
-		. "<div class='gauche'>"
230
-		. $les_enfants
231
-		. '</div>'
232
-		. "<div class='droite'>"
233
-		. $les_enfants2
234
-		. '</div>'
235
-		. $pagination;
236
-
237
-	return $res;
198
+    $pagination = '';
199
+    $debut = 0;
200
+    $limite = 500;
201
+
202
+    $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique));
203
+
204
+    if ($nb > $limite) {
205
+        $debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut;
206
+        $pagination = chercher_filtre('pagination');
207
+        $pagination = '<br class="nettoyeur"><p class="pagination">' .
208
+            $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') .
209
+        '</p>';
210
+    }
211
+
212
+    $les_enfants = enfant_rub($id_rubrique, $debut, $limite);
213
+
214
+    if (!$n = count($les_enfants)) {
215
+        return '';
216
+    }
217
+
218
+    if ($n == 1) {
219
+        $les_enfants = reset($les_enfants);
220
+        $les_enfants2 = '';
221
+    } else {
222
+        $n = ceil($n / 2);
223
+        $les_enfants2 = implode('', array_slice($les_enfants, $n));
224
+        $les_enfants = implode('', array_slice($les_enfants, 0, $n));
225
+    }
226
+
227
+    $res =
228
+        $pagination
229
+        . "<div class='gauche'>"
230
+        . $les_enfants
231
+        . '</div>'
232
+        . "<div class='droite'>"
233
+        . $les_enfants2
234
+        . '</div>'
235
+        . $pagination;
236
+
237
+    return $res;
238 238
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 1 patch
Indentation   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = [];
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = [];
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = [];
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = [];
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,31 +91,31 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (
100
-			function_exists('mb_internal_encoding')
101
-			and function_exists('mb_detect_order')
102
-			and function_exists('mb_substr')
103
-			and function_exists('mb_strlen')
104
-			and function_exists('mb_strtolower')
105
-			and function_exists('mb_strtoupper')
106
-			and function_exists('mb_encode_mimeheader')
107
-			and function_exists('mb_encode_numericentity')
108
-			and function_exists('mb_decode_numericentity')
109
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
110
-		) {
111
-			mb_internal_encoding('utf-8');
112
-			$mb = 1;
113
-		} else {
114
-			$mb = -1;
115
-		}
116
-	}
117
-
118
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (
100
+            function_exists('mb_internal_encoding')
101
+            and function_exists('mb_detect_order')
102
+            and function_exists('mb_substr')
103
+            and function_exists('mb_strlen')
104
+            and function_exists('mb_strtolower')
105
+            and function_exists('mb_strtoupper')
106
+            and function_exists('mb_encode_mimeheader')
107
+            and function_exists('mb_encode_numericentity')
108
+            and function_exists('mb_decode_numericentity')
109
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
110
+        ) {
111
+            mb_internal_encoding('utf-8');
112
+            $mb = 1;
113
+        } else {
114
+            $mb = -1;
115
+        }
116
+    }
117
+
118
+    return ($mb == 1);
119 119
 }
120 120
 
121 121
 /**
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
  *     true si iconv fonctionne correctement
131 131
  **/
132 132
 function test_iconv() {
133
-	static $iconv_ok;
134
-
135
-	if (!$iconv_ok) {
136
-		if (!function_exists('iconv')) {
137
-			$iconv_ok = -1;
138
-		} else {
139
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
140
-				$iconv_ok = 1;
141
-			} else {
142
-				$iconv_ok = -1;
143
-			}
144
-		}
145
-	}
146
-
147
-	return ($iconv_ok == 1);
133
+    static $iconv_ok;
134
+
135
+    if (!$iconv_ok) {
136
+        if (!function_exists('iconv')) {
137
+            $iconv_ok = -1;
138
+        } else {
139
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
140
+                $iconv_ok = 1;
141
+            } else {
142
+                $iconv_ok = -1;
143
+            }
144
+        }
145
+    }
146
+
147
+    return ($iconv_ok == 1);
148 148
 }
149 149
 
150 150
 
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
  *     true si PCRE supporte l'UTF-8 correctement
158 158
  **/
159 159
 function test_pcre_unicode() {
160
-	static $pcre_ok = 0;
161
-
162
-	if (!$pcre_ok) {
163
-		$s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
164
-		if (preg_match(',\W...\W,u', $s)) {
165
-			$pcre_ok = 1;
166
-		} else {
167
-			$pcre_ok = -1;
168
-		}
169
-	}
170
-
171
-	return $pcre_ok == 1;
160
+    static $pcre_ok = 0;
161
+
162
+    if (!$pcre_ok) {
163
+        $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
164
+        if (preg_match(',\W...\W,u', $s)) {
165
+            $pcre_ok = 1;
166
+        } else {
167
+            $pcre_ok = -1;
168
+        }
169
+    }
170
+
171
+    return $pcre_ok == 1;
172 172
 }
173 173
 
174 174
 /**
@@ -184,22 +184,22 @@  discard block
 block discarded – undo
184 184
  *    Plage de caractères
185 185
  **/
186 186
 function pcre_lettres_unicode() {
187
-	static $plage_unicode;
188
-
189
-	if (!$plage_unicode) {
190
-		if (test_pcre_unicode()) {
191
-			// cf. http://www.unicode.org/charts/
192
-			$plage_unicode = '\w' // iso-latin
193
-				. '\x{100}-\x{24f}' // europeen etendu
194
-				. '\x{300}-\x{1cff}' // des tas de trucs
195
-			;
196
-		} else {
197
-			// fallback a trois sous
198
-			$plage_unicode = '\w';
199
-		}
200
-	}
201
-
202
-	return $plage_unicode;
187
+    static $plage_unicode;
188
+
189
+    if (!$plage_unicode) {
190
+        if (test_pcre_unicode()) {
191
+            // cf. http://www.unicode.org/charts/
192
+            $plage_unicode = '\w' // iso-latin
193
+                . '\x{100}-\x{24f}' // europeen etendu
194
+                . '\x{300}-\x{1cff}' // des tas de trucs
195
+            ;
196
+        } else {
197
+            // fallback a trois sous
198
+            $plage_unicode = '\w';
199
+        }
200
+    }
201
+
202
+    return $plage_unicode;
203 203
 }
204 204
 
205 205
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
  *    Plage de caractères
218 218
  **/
219 219
 function plage_punct_unicode() {
220
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
221 221
 }
222 222
 
223 223
 /**
@@ -237,75 +237,75 @@  discard block
 block discarded – undo
237 237
  *     Texte corrigé
238 238
  **/
239 239
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
240
-	static $trans;
241
-
242
-	if (is_array($texte)) {
243
-		return array_map('corriger_caracteres_windows', $texte);
244
-	}
245
-
246
-	if ($charset == 'AUTO') {
247
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
248
-	}
249
-	if ($charset == 'utf-8') {
250
-		$p = chr(194);
251
-		if (strpos($texte, $p) == false) {
252
-			return $texte;
253
-		}
254
-	} else {
255
-		if ($charset == 'iso-8859-1') {
256
-			$p = '';
257
-		} else {
258
-			return $texte;
259
-		}
260
-	}
261
-
262
-	if (!isset($trans[$charset][$charset_cible])) {
263
-		$trans[$charset][$charset_cible] = [
264
-			$p . chr(128) => '&#8364;',
265
-			$p . chr(129) => ' ', # pas affecte
266
-			$p . chr(130) => '&#8218;',
267
-			$p . chr(131) => '&#402;',
268
-			$p . chr(132) => '&#8222;',
269
-			$p . chr(133) => '&#8230;',
270
-			$p . chr(134) => '&#8224;',
271
-			$p . chr(135) => '&#8225;',
272
-			$p . chr(136) => '&#710;',
273
-			$p . chr(137) => '&#8240;',
274
-			$p . chr(138) => '&#352;',
275
-			$p . chr(139) => '&#8249;',
276
-			$p . chr(140) => '&#338;',
277
-			$p . chr(141) => ' ', # pas affecte
278
-			$p . chr(142) => '&#381;',
279
-			$p . chr(143) => ' ', # pas affecte
280
-			$p . chr(144) => ' ', # pas affecte
281
-			$p . chr(145) => '&#8216;',
282
-			$p . chr(146) => '&#8217;',
283
-			$p . chr(147) => '&#8220;',
284
-			$p . chr(148) => '&#8221;',
285
-			$p . chr(149) => '&#8226;',
286
-			$p . chr(150) => '&#8211;',
287
-			$p . chr(151) => '&#8212;',
288
-			$p . chr(152) => '&#732;',
289
-			$p . chr(153) => '&#8482;',
290
-			$p . chr(154) => '&#353;',
291
-			$p . chr(155) => '&#8250;',
292
-			$p . chr(156) => '&#339;',
293
-			$p . chr(157) => ' ', # pas affecte
294
-			$p . chr(158) => '&#382;',
295
-			$p . chr(159) => '&#376;',
296
-		];
297
-		if ($charset_cible != 'unicode') {
298
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
299
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
300
-			}
301
-		}
302
-	}
303
-
304
-	return @str_replace(
305
-		array_keys($trans[$charset][$charset_cible]),
306
-		array_values($trans[$charset][$charset_cible]),
307
-		$texte
308
-	);
240
+    static $trans;
241
+
242
+    if (is_array($texte)) {
243
+        return array_map('corriger_caracteres_windows', $texte);
244
+    }
245
+
246
+    if ($charset == 'AUTO') {
247
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
248
+    }
249
+    if ($charset == 'utf-8') {
250
+        $p = chr(194);
251
+        if (strpos($texte, $p) == false) {
252
+            return $texte;
253
+        }
254
+    } else {
255
+        if ($charset == 'iso-8859-1') {
256
+            $p = '';
257
+        } else {
258
+            return $texte;
259
+        }
260
+    }
261
+
262
+    if (!isset($trans[$charset][$charset_cible])) {
263
+        $trans[$charset][$charset_cible] = [
264
+            $p . chr(128) => '&#8364;',
265
+            $p . chr(129) => ' ', # pas affecte
266
+            $p . chr(130) => '&#8218;',
267
+            $p . chr(131) => '&#402;',
268
+            $p . chr(132) => '&#8222;',
269
+            $p . chr(133) => '&#8230;',
270
+            $p . chr(134) => '&#8224;',
271
+            $p . chr(135) => '&#8225;',
272
+            $p . chr(136) => '&#710;',
273
+            $p . chr(137) => '&#8240;',
274
+            $p . chr(138) => '&#352;',
275
+            $p . chr(139) => '&#8249;',
276
+            $p . chr(140) => '&#338;',
277
+            $p . chr(141) => ' ', # pas affecte
278
+            $p . chr(142) => '&#381;',
279
+            $p . chr(143) => ' ', # pas affecte
280
+            $p . chr(144) => ' ', # pas affecte
281
+            $p . chr(145) => '&#8216;',
282
+            $p . chr(146) => '&#8217;',
283
+            $p . chr(147) => '&#8220;',
284
+            $p . chr(148) => '&#8221;',
285
+            $p . chr(149) => '&#8226;',
286
+            $p . chr(150) => '&#8211;',
287
+            $p . chr(151) => '&#8212;',
288
+            $p . chr(152) => '&#732;',
289
+            $p . chr(153) => '&#8482;',
290
+            $p . chr(154) => '&#353;',
291
+            $p . chr(155) => '&#8250;',
292
+            $p . chr(156) => '&#339;',
293
+            $p . chr(157) => ' ', # pas affecte
294
+            $p . chr(158) => '&#382;',
295
+            $p . chr(159) => '&#376;',
296
+        ];
297
+        if ($charset_cible != 'unicode') {
298
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
299
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
300
+            }
301
+        }
302
+    }
303
+
304
+    return @str_replace(
305
+        array_keys($trans[$charset][$charset_cible]),
306
+        array_values($trans[$charset][$charset_cible]),
307
+        $texte
308
+    );
309 309
 }
310 310
 
311 311
 
@@ -322,26 +322,26 @@  discard block
 block discarded – undo
322 322
  *     Texte converti
323 323
  **/
324 324
 function html2unicode($texte, $secure = false) {
325
-	if (strpos($texte, '&') === false) {
326
-		return $texte;
327
-	}
328
-	static $trans = [];
329
-	if (!$trans) {
330
-		load_charset('html');
331
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
332
-			$trans["&$key;"] = $val;
333
-		}
334
-	}
335
-
336
-	if ($secure) {
337
-		return str_replace(array_keys($trans), array_values($trans), $texte);
338
-	} else {
339
-		return str_replace(
340
-			['&amp;', '&quot;', '&lt;', '&gt;'],
341
-			['&', '"', '<', '>'],
342
-			str_replace(array_keys($trans), array_values($trans), $texte)
343
-		);
344
-	}
325
+    if (strpos($texte, '&') === false) {
326
+        return $texte;
327
+    }
328
+    static $trans = [];
329
+    if (!$trans) {
330
+        load_charset('html');
331
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
332
+            $trans["&$key;"] = $val;
333
+        }
334
+    }
335
+
336
+    if ($secure) {
337
+        return str_replace(array_keys($trans), array_values($trans), $texte);
338
+    } else {
339
+        return str_replace(
340
+            ['&amp;', '&quot;', '&lt;', '&gt;'],
341
+            ['&', '"', '<', '>'],
342
+            str_replace(array_keys($trans), array_values($trans), $texte)
343
+        );
344
+    }
345 345
 }
346 346
 
347 347
 
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
  *     Texte converti
357 357
  **/
358 358
 function mathml2unicode($texte) {
359
-	static $trans;
360
-	if (!$trans) {
361
-		load_charset('mathml');
359
+    static $trans;
360
+    if (!$trans) {
361
+        load_charset('mathml');
362 362
 
363
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
364
-			$trans["&$key;"] = $val;
365
-		}
366
-	}
363
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
364
+            $trans["&$key;"] = $val;
365
+        }
366
+    }
367 367
 
368
-	return str_replace(array_keys($trans), array_values($trans), $texte);
368
+    return str_replace(array_keys($trans), array_values($trans), $texte);
369 369
 }
370 370
 
371 371
 
@@ -387,75 +387,75 @@  discard block
 block discarded – undo
387 387
  *     Texte converti en unicode
388 388
  **/
389 389
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
390
-	static $trans;
391
-
392
-	if ($charset == 'AUTO') {
393
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
394
-	}
395
-
396
-	if ($charset == '') {
397
-		$charset = 'iso-8859-1';
398
-	}
399
-	$charset = strtolower($charset);
400
-
401
-	switch ($charset) {
402
-		case 'utf-8':
403
-		case 'utf8':
404
-			return utf_8_to_unicode($texte);
405
-
406
-		case 'iso-8859-1':
407
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
408
-		// pas de break; ici, on suit sur default:
409
-
410
-		default:
411
-			// mbstring presente ?
412
-			if (init_mb_string()) {
413
-				$order = mb_detect_order();
414
-				try {
415
-					# mb_string connait-il $charset?
416
-					if ($order and mb_detect_order($charset)) {
417
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
418
-						if ($s && $s != $texte) {
419
-							return utf_8_to_unicode($s);
420
-						}
421
-					}
422
-				} catch (\Error $e) {
423
-					// Le charset n'existe probablement pas
424
-				} finally {
425
-					mb_detect_order($order); # remettre comme precedemment
426
-				}
427
-			}
428
-
429
-			// Sinon, peut-etre connaissons-nous ce charset ?
430
-			if (!isset($trans[$charset])) {
431
-				if (
432
-					$cset = load_charset($charset)
433
-					and is_array($GLOBALS['CHARSET'][$cset])
434
-				) {
435
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
437
-					}
438
-				}
439
-			}
440
-			if (isset($trans[$charset]) and count($trans[$charset])) {
441
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
442
-			}
443
-
444
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
445
-			// caractere n'appartient pas au charset, mais c'est un probleme
446
-			// surtout en utf-8, gere ci-dessus)
447
-			if (test_iconv()) {
448
-				$s = iconv($charset, 'utf-32le', $texte);
449
-				if ($s) {
450
-					return utf_32_to_unicode($s);
451
-				}
452
-			}
453
-
454
-			// Au pire ne rien faire
455
-			spip_log("erreur charset '$charset' non supporte");
456
-
457
-			return $texte;
458
-	}
390
+    static $trans;
391
+
392
+    if ($charset == 'AUTO') {
393
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
394
+    }
395
+
396
+    if ($charset == '') {
397
+        $charset = 'iso-8859-1';
398
+    }
399
+    $charset = strtolower($charset);
400
+
401
+    switch ($charset) {
402
+        case 'utf-8':
403
+        case 'utf8':
404
+            return utf_8_to_unicode($texte);
405
+
406
+        case 'iso-8859-1':
407
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
408
+        // pas de break; ici, on suit sur default:
409
+
410
+        default:
411
+            // mbstring presente ?
412
+            if (init_mb_string()) {
413
+                $order = mb_detect_order();
414
+                try {
415
+                    # mb_string connait-il $charset?
416
+                    if ($order and mb_detect_order($charset)) {
417
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
418
+                        if ($s && $s != $texte) {
419
+                            return utf_8_to_unicode($s);
420
+                        }
421
+                    }
422
+                } catch (\Error $e) {
423
+                    // Le charset n'existe probablement pas
424
+                } finally {
425
+                    mb_detect_order($order); # remettre comme precedemment
426
+                }
427
+            }
428
+
429
+            // Sinon, peut-etre connaissons-nous ce charset ?
430
+            if (!isset($trans[$charset])) {
431
+                if (
432
+                    $cset = load_charset($charset)
433
+                    and is_array($GLOBALS['CHARSET'][$cset])
434
+                ) {
435
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
437
+                    }
438
+                }
439
+            }
440
+            if (isset($trans[$charset]) and count($trans[$charset])) {
441
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
442
+            }
443
+
444
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
445
+            // caractere n'appartient pas au charset, mais c'est un probleme
446
+            // surtout en utf-8, gere ci-dessus)
447
+            if (test_iconv()) {
448
+                $s = iconv($charset, 'utf-32le', $texte);
449
+                if ($s) {
450
+                    return utf_32_to_unicode($s);
451
+                }
452
+            }
453
+
454
+            // Au pire ne rien faire
455
+            spip_log("erreur charset '$charset' non supporte");
456
+
457
+            return $texte;
458
+    }
459 459
 }
460 460
 
461 461
 
@@ -474,44 +474,44 @@  discard block
 block discarded – undo
474 474
  *     Texte transformé dans le charset souhaité
475 475
  **/
476 476
 function unicode2charset($texte, $charset = 'AUTO') {
477
-	static $CHARSET_REVERSE = [];
478
-	static $trans = [];
479
-
480
-	if ($charset == 'AUTO') {
481
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
482
-	}
483
-
484
-	switch ($charset) {
485
-		case 'utf-8':
486
-			return unicode_to_utf_8($texte);
487
-			break;
488
-
489
-		default:
490
-			$charset = load_charset($charset);
491
-
492
-			if (empty($CHARSET_REVERSE[$charset])) {
493
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
494
-			}
495
-
496
-			if (!isset($trans[$charset])) {
497
-				$trans[$charset] = [];
498
-				$t = &$trans[$charset];
499
-				for ($e = 128; $e < 255; $e++) {
500
-					$h = dechex($e);
501
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502
-						$s = $CHARSET_REVERSE[$charset][$e];
503
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
505
-					} else {
506
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
508
-					}
509
-				}
510
-			}
511
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
512
-
513
-			return $texte;
514
-	}
477
+    static $CHARSET_REVERSE = [];
478
+    static $trans = [];
479
+
480
+    if ($charset == 'AUTO') {
481
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
482
+    }
483
+
484
+    switch ($charset) {
485
+        case 'utf-8':
486
+            return unicode_to_utf_8($texte);
487
+            break;
488
+
489
+        default:
490
+            $charset = load_charset($charset);
491
+
492
+            if (empty($CHARSET_REVERSE[$charset])) {
493
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
494
+            }
495
+
496
+            if (!isset($trans[$charset])) {
497
+                $trans[$charset] = [];
498
+                $t = &$trans[$charset];
499
+                for ($e = 128; $e < 255; $e++) {
500
+                    $h = dechex($e);
501
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502
+                        $s = $CHARSET_REVERSE[$charset][$e];
503
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
505
+                    } else {
506
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
508
+                    }
509
+                }
510
+            }
511
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
512
+
513
+            return $texte;
514
+    }
515 515
 }
516 516
 
517 517
 
@@ -529,39 +529,39 @@  discard block
 block discarded – undo
529 529
  *     Texte transformé dans le charset site
530 530
  **/
531 531
 function importer_charset($texte, $charset = 'AUTO') {
532
-	static $trans = [];
533
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
534
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
535
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
536
-		if (init_mb_string()) {
537
-			if (
538
-				$order = mb_detect_order() # mb_string connait-il $charset?
539
-				and mb_detect_order($charset)
540
-			) {
541
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
542
-			}
543
-			mb_detect_order($order); # remettre comme precedemment
544
-			return $s;
545
-		}
546
-		// Sinon, peut-etre connaissons-nous ce charset ?
547
-		if (!isset($trans[$charset])) {
548
-			if (
549
-				$cset = load_charset($charset)
550
-				and is_array($GLOBALS['CHARSET'][$cset])
551
-			) {
552
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
554
-				}
555
-			}
556
-		}
557
-		if (count($trans[$charset])) {
558
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
559
-		}
560
-
561
-		return $texte;
562
-	}
563
-
564
-	return unicode2charset(charset2unicode($texte, $charset));
532
+    static $trans = [];
533
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
534
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
535
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
536
+        if (init_mb_string()) {
537
+            if (
538
+                $order = mb_detect_order() # mb_string connait-il $charset?
539
+                and mb_detect_order($charset)
540
+            ) {
541
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
542
+            }
543
+            mb_detect_order($order); # remettre comme precedemment
544
+            return $s;
545
+        }
546
+        // Sinon, peut-etre connaissons-nous ce charset ?
547
+        if (!isset($trans[$charset])) {
548
+            if (
549
+                $cset = load_charset($charset)
550
+                and is_array($GLOBALS['CHARSET'][$cset])
551
+            ) {
552
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
554
+                }
555
+            }
556
+        }
557
+        if (count($trans[$charset])) {
558
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
559
+        }
560
+
561
+        return $texte;
562
+    }
563
+
564
+    return unicode2charset(charset2unicode($texte, $charset));
565 565
 }
566 566
 
567 567
 
@@ -577,92 +577,92 @@  discard block
 block discarded – undo
577 577
  **/
578 578
 function utf_8_to_unicode($source) {
579 579
 
580
-	// mb_string : methode rapide
581
-	if (init_mb_string()) {
582
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
583
-
584
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
585
-	}
586
-
587
-	// Sinon methode pas a pas
588
-	static $decrement;
589
-	static $shift;
590
-
591
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
592
-	if (!is_array($decrement)) {
593
-		// array used to figure what number to decrement from character order value
594
-		// according to number of characters used to map unicode to ascii by utf-8
595
-		$decrement[4] = 240;
596
-		$decrement[3] = 224;
597
-		$decrement[2] = 192;
598
-		$decrement[1] = 0;
599
-		// the number of bits to shift each charNum by
600
-		$shift[1][0] = 0;
601
-		$shift[2][0] = 6;
602
-		$shift[2][1] = 0;
603
-		$shift[3][0] = 12;
604
-		$shift[3][1] = 6;
605
-		$shift[3][2] = 0;
606
-		$shift[4][0] = 18;
607
-		$shift[4][1] = 12;
608
-		$shift[4][2] = 6;
609
-		$shift[4][3] = 0;
610
-	}
611
-
612
-	$pos = 0;
613
-	$len = strlen($source);
614
-	$encodedString = '';
615
-	while ($pos < $len) {
616
-		$char = '';
617
-		$ischar = false;
618
-		$asciiPos = ord(substr($source, $pos, 1));
619
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
620
-			// 4 chars representing one unicode character
621
-			$thisLetter = substr($source, $pos, 4);
622
-			$pos += 4;
623
-		} else {
624
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
625
-				// 3 chars representing one unicode character
626
-				$thisLetter = substr($source, $pos, 3);
627
-				$pos += 3;
628
-			} else {
629
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
630
-					// 2 chars representing one unicode character
631
-					$thisLetter = substr($source, $pos, 2);
632
-					$pos += 2;
633
-				} else {
634
-					// 1 char (lower ascii)
635
-					$thisLetter = substr($source, $pos, 1);
636
-					$pos += 1;
637
-					$char = $thisLetter;
638
-					$ischar = true;
639
-				}
640
-			}
641
-		}
642
-
643
-		if ($ischar) {
644
-			$encodedString .= $char;
645
-		} else {  // process the string representing the letter to a unicode entity
646
-			$thisLen = strlen($thisLetter);
647
-			$thisPos = 0;
648
-			$decimalCode = 0;
649
-			while ($thisPos < $thisLen) {
650
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
651
-				if ($thisPos == 0) {
652
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
653
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
654
-				} else {
655
-					$charNum = intval($thisCharOrd - 128);
656
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
657
-				}
658
-				$thisPos++;
659
-			}
660
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
661
-			$encodedString .= $encodedLetter;
662
-		}
663
-	}
664
-
665
-	return $encodedString;
580
+    // mb_string : methode rapide
581
+    if (init_mb_string()) {
582
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
583
+
584
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
585
+    }
586
+
587
+    // Sinon methode pas a pas
588
+    static $decrement;
589
+    static $shift;
590
+
591
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
592
+    if (!is_array($decrement)) {
593
+        // array used to figure what number to decrement from character order value
594
+        // according to number of characters used to map unicode to ascii by utf-8
595
+        $decrement[4] = 240;
596
+        $decrement[3] = 224;
597
+        $decrement[2] = 192;
598
+        $decrement[1] = 0;
599
+        // the number of bits to shift each charNum by
600
+        $shift[1][0] = 0;
601
+        $shift[2][0] = 6;
602
+        $shift[2][1] = 0;
603
+        $shift[3][0] = 12;
604
+        $shift[3][1] = 6;
605
+        $shift[3][2] = 0;
606
+        $shift[4][0] = 18;
607
+        $shift[4][1] = 12;
608
+        $shift[4][2] = 6;
609
+        $shift[4][3] = 0;
610
+    }
611
+
612
+    $pos = 0;
613
+    $len = strlen($source);
614
+    $encodedString = '';
615
+    while ($pos < $len) {
616
+        $char = '';
617
+        $ischar = false;
618
+        $asciiPos = ord(substr($source, $pos, 1));
619
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
620
+            // 4 chars representing one unicode character
621
+            $thisLetter = substr($source, $pos, 4);
622
+            $pos += 4;
623
+        } else {
624
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
625
+                // 3 chars representing one unicode character
626
+                $thisLetter = substr($source, $pos, 3);
627
+                $pos += 3;
628
+            } else {
629
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
630
+                    // 2 chars representing one unicode character
631
+                    $thisLetter = substr($source, $pos, 2);
632
+                    $pos += 2;
633
+                } else {
634
+                    // 1 char (lower ascii)
635
+                    $thisLetter = substr($source, $pos, 1);
636
+                    $pos += 1;
637
+                    $char = $thisLetter;
638
+                    $ischar = true;
639
+                }
640
+            }
641
+        }
642
+
643
+        if ($ischar) {
644
+            $encodedString .= $char;
645
+        } else {  // process the string representing the letter to a unicode entity
646
+            $thisLen = strlen($thisLetter);
647
+            $thisPos = 0;
648
+            $decimalCode = 0;
649
+            while ($thisPos < $thisLen) {
650
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
651
+                if ($thisPos == 0) {
652
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
653
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
654
+                } else {
655
+                    $charNum = intval($thisCharOrd - 128);
656
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
657
+                }
658
+                $thisPos++;
659
+            }
660
+            $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
661
+            $encodedString .= $encodedLetter;
662
+        }
663
+    }
664
+
665
+    return $encodedString;
666 666
 }
667 667
 
668 668
 /**
@@ -681,32 +681,32 @@  discard block
 block discarded – undo
681 681
  **/
682 682
 function utf_32_to_unicode($source) {
683 683
 
684
-	// mb_string : methode rapide
685
-	if (init_mb_string()) {
686
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
687
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
688
-
689
-		return str_replace(chr(0), '', $source);
690
-	}
691
-
692
-	// Sinon methode lente
693
-	$texte = '';
694
-	while ($source) {
695
-		$words = unpack('V*', substr($source, 0, 1024));
696
-		$source = substr($source, 1024);
697
-		foreach ($words as $word) {
698
-			if ($word < 128) {
699
-				$texte .= chr($word);
700
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701
-			else {
702
-				if ($word != 65279) {
703
-					$texte .= '&#' . $word . ';';
704
-				}
705
-			}
706
-		}
707
-	}
708
-
709
-	return $texte;
684
+    // mb_string : methode rapide
685
+    if (init_mb_string()) {
686
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
687
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
688
+
689
+        return str_replace(chr(0), '', $source);
690
+    }
691
+
692
+    // Sinon methode lente
693
+    $texte = '';
694
+    while ($source) {
695
+        $words = unpack('V*', substr($source, 0, 1024));
696
+        $source = substr($source, 1024);
697
+        foreach ($words as $word) {
698
+            if ($word < 128) {
699
+                $texte .= chr($word);
700
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701
+            else {
702
+                if ($word != 65279) {
703
+                    $texte .= '&#' . $word . ';';
704
+                }
705
+            }
706
+        }
707
+    }
708
+
709
+    return $texte;
710 710
 }
711 711
 
712 712
 
@@ -723,21 +723,21 @@  discard block
 block discarded – undo
723 723
  *    Caractère utf8 si trouvé, '' sinon
724 724
  **/
725 725
 function caractere_utf_8($num) {
726
-	$num = intval($num);
727
-	if ($num < 128) {
728
-		return chr($num);
729
-	}
730
-	if ($num < 2048) {
731
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
732
-	}
733
-	if ($num < 65536) {
734
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
735
-	}
736
-	if ($num < 1114112) {
737
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
738
-	}
739
-
740
-	return '';
726
+    $num = intval($num);
727
+    if ($num < 128) {
728
+        return chr($num);
729
+    }
730
+    if ($num < 2048) {
731
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
732
+    }
733
+    if ($num < 65536) {
734
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
735
+    }
736
+    if ($num < 1114112) {
737
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
738
+    }
739
+
740
+    return '';
741 741
 }
742 742
 
743 743
 /**
@@ -750,42 +750,42 @@  discard block
 block discarded – undo
750 750
  **/
751 751
 function unicode_to_utf_8($texte) {
752 752
 
753
-	// 1. Entites &#128; et suivantes
754
-	$vu = [];
755
-	if (
756
-		preg_match_all(
757
-			',&#0*([1-9][0-9][0-9]+);,S',
758
-			$texte,
759
-			$regs,
760
-			PREG_SET_ORDER
761
-		)
762
-	) {
763
-		foreach ($regs as $reg) {
764
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
765
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
766
-			}
767
-		}
768
-	}
769
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
770
-
771
-	// 2. Entites > &#xFF;
772
-	//$vu = array();
773
-	if (
774
-		preg_match_all(
775
-			',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
776
-			$texte,
777
-			$regs,
778
-			PREG_SET_ORDER
779
-		)
780
-	) {
781
-		foreach ($regs as $reg) {
782
-			if (!isset($vu[$reg[0]])) {
783
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
784
-			}
785
-		}
786
-	}
787
-
788
-	return str_replace(array_keys($vu), array_values($vu), $texte);
753
+    // 1. Entites &#128; et suivantes
754
+    $vu = [];
755
+    if (
756
+        preg_match_all(
757
+            ',&#0*([1-9][0-9][0-9]+);,S',
758
+            $texte,
759
+            $regs,
760
+            PREG_SET_ORDER
761
+        )
762
+    ) {
763
+        foreach ($regs as $reg) {
764
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
765
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
766
+            }
767
+        }
768
+    }
769
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
770
+
771
+    // 2. Entites > &#xFF;
772
+    //$vu = array();
773
+    if (
774
+        preg_match_all(
775
+            ',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
776
+            $texte,
777
+            $regs,
778
+            PREG_SET_ORDER
779
+        )
780
+    ) {
781
+        foreach ($regs as $reg) {
782
+            if (!isset($vu[$reg[0]])) {
783
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
784
+            }
785
+        }
786
+    }
787
+
788
+    return str_replace(array_keys($vu), array_values($vu), $texte);
789 789
 }
790 790
 
791 791
 /**
@@ -797,15 +797,15 @@  discard block
 block discarded – undo
797 797
  *     Texte converti
798 798
  **/
799 799
 function unicode_to_javascript($texte) {
800
-	$vu = [];
801
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802
-		$num = $regs[1];
803
-		$vu[$num] = true;
804
-		$s = '\u' . sprintf('%04x', $num);
805
-		$texte = str_replace($regs[0], $s, $texte);
806
-	}
807
-
808
-	return $texte;
800
+    $vu = [];
801
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802
+        $num = $regs[1];
803
+        $vu[$num] = true;
804
+        $s = '\u' . sprintf('%04x', $num);
805
+        $texte = str_replace($regs[0], $s, $texte);
806
+    }
807
+
808
+    return $texte;
809 809
 }
810 810
 
811 811
 /**
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
  *     Texte converti
818 818
  **/
819 819
 function javascript_to_unicode($texte) {
820
-	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
822
-	}
820
+    while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
+        $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
822
+    }
823 823
 
824
-	return $texte;
824
+    return $texte;
825 825
 }
826 826
 
827 827
 /**
@@ -833,11 +833,11 @@  discard block
 block discarded – undo
833 833
  *     Texte converti
834 834
  **/
835 835
 function javascript_to_binary($texte) {
836
-	while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
837
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
838
-	}
836
+    while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
837
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
838
+    }
839 839
 
840
-	return $texte;
840
+    return $texte;
841 841
 }
842 842
 
843 843
 
@@ -855,26 +855,26 @@  discard block
 block discarded – undo
855 855
  * @return string
856 856
  */
857 857
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
858
-	static $trans = [];
859
-	if ($charset == 'AUTO') {
860
-		$charset = $GLOBALS['meta']['charset'];
861
-	}
862
-	if (!strlen($texte)) {
863
-		return $texte;
864
-	}
865
-
866
-	$table_translit = 'translit' . $complexe;
867
-
868
-	// 2. Translitterer grace a la table predefinie
869
-	if (!isset($trans[$complexe])) {
870
-		$trans[$complexe] = [];
871
-		load_charset($table_translit);
872
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
873
-			$trans[$complexe][caractere_utf_8($key)] = $val;
874
-		}
875
-	}
876
-
877
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
858
+    static $trans = [];
859
+    if ($charset == 'AUTO') {
860
+        $charset = $GLOBALS['meta']['charset'];
861
+    }
862
+    if (!strlen($texte)) {
863
+        return $texte;
864
+    }
865
+
866
+    $table_translit = 'translit' . $complexe;
867
+
868
+    // 2. Translitterer grace a la table predefinie
869
+    if (!isset($trans[$complexe])) {
870
+        $trans[$complexe] = [];
871
+        load_charset($table_translit);
872
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
873
+            $trans[$complexe][caractere_utf_8($key)] = $val;
874
+        }
875
+    }
876
+
877
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
878 878
 }
879 879
 
880 880
 /**
@@ -897,14 +897,14 @@  discard block
 block discarded – undo
897 897
  * @return string
898 898
  */
899 899
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
900
-	// 0. Supprimer les caracteres illegaux
901
-	include_spip('inc/filtres');
902
-	$texte = corriger_caracteres($texte);
900
+    // 0. Supprimer les caracteres illegaux
901
+    include_spip('inc/filtres');
902
+    $texte = corriger_caracteres($texte);
903 903
 
904
-	// 1. Passer le charset et les &eacute en utf-8
905
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
904
+    // 1. Passer le charset et les &eacute en utf-8
905
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
906 906
 
907
-	return translitteration_rapide($texte, $charset, $complexe);
907
+    return translitteration_rapide($texte, $charset, $complexe);
908 908
 }
909 909
 
910 910
 /**
@@ -919,19 +919,19 @@  discard block
 block discarded – undo
919 919
  * @return string
920 920
  */
921 921
 function translitteration_complexe($texte, $chiffres = false) {
922
-	$texte = translitteration($texte, 'AUTO', 'complexe');
923
-
924
-	if ($chiffres) {
925
-		$texte = preg_replace_callback(
926
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
-			function ($m) {
928
-			return translitteration_chiffree($m[0]);
929
-			},
930
-			$texte
931
-		);
932
-	}
933
-
934
-	return $texte;
922
+    $texte = translitteration($texte, 'AUTO', 'complexe');
923
+
924
+    if ($chiffres) {
925
+        $texte = preg_replace_callback(
926
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
+            function ($m) {
928
+            return translitteration_chiffree($m[0]);
929
+            },
930
+            $texte
931
+        );
932
+    }
933
+
934
+    return $texte;
935 935
 }
936 936
 
937 937
 /**
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
  * @return string
944 944
  */
945 945
 function translitteration_chiffree($car) {
946
-	return strtr($car, "'`?~.^+(-", '123456789');
946
+    return strtr($car, "'`?~.^+(-", '123456789');
947 947
 }
948 948
 
949 949
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *    true s'il a un BOM
957 957
  **/
958 958
 function bom_utf8($texte) {
959
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
959
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
960 960
 }
961 961
 
962 962
 /**
@@ -973,21 +973,21 @@  discard block
 block discarded – undo
973 973
  *     true si c'est le cas
974 974
  **/
975 975
 function is_utf8($string) {
976
-	return !strlen(
977
-		preg_replace(
978
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
979
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
980
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
981
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
982
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
983
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
984
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
985
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
986
-			. ',sS',
987
-			'',
988
-			$string
989
-		)
990
-	);
976
+    return !strlen(
977
+        preg_replace(
978
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
979
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
980
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
981
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
982
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
983
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
984
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
985
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
986
+            . ',sS',
987
+            '',
988
+            $string
989
+        )
990
+    );
991 991
 }
992 992
 
993 993
 /**
@@ -999,13 +999,13 @@  discard block
 block discarded – undo
999 999
  *     true si c'est le cas
1000 1000
  **/
1001 1001
 function is_ascii($string) {
1002
-	return !strlen(
1003
-		preg_replace(
1004
-			',[\x09\x0A\x0D\x20-\x7E],sS',
1005
-			'',
1006
-			$string
1007
-		)
1008
-	);
1002
+    return !strlen(
1003
+        preg_replace(
1004
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
1005
+            '',
1006
+            $string
1007
+        )
1008
+    );
1009 1009
 }
1010 1010
 
1011 1011
 /**
@@ -1024,53 +1024,53 @@  discard block
 block discarded – undo
1024 1024
  **/
1025 1025
 function transcoder_page($texte, $headers = '') {
1026 1026
 
1027
-	// Si tout est < 128 pas la peine d'aller plus loin
1028
-	if (is_ascii($texte)) {
1029
-		#spip_log('charset: ascii');
1030
-		return $texte;
1031
-	}
1032
-
1033
-	if (bom_utf8($texte)) {
1034
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
1035
-		$charset = 'utf-8';
1036
-		$texte = substr($texte, 3);
1037
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1038
-		// charset precise par le contenu (xml)
1039
-		$charset = trim(strtolower($regs[1]));
1040
-	} elseif (
1041
-		// charset precise par le contenu (html)
1042
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1043
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1044
-		and false === strpos($regs[2], '#')
1045
-		and $tmp = trim(strtolower($regs[2]))
1046
-	) {
1047
-		$charset = $tmp;
1048
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1049
-		// charset de la reponse http
1050
-		$charset = trim(strtolower($regs[1]));
1051
-	} else {
1052
-		$charset = '';
1053
-	}
1054
-
1055
-
1056
-	// normaliser les noms du shif-jis japonais
1057
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1058
-		$charset = 'shift-jis';
1059
-	}
1060
-
1061
-	if ($charset) {
1062
-		spip_log("charset: $charset");
1063
-	} else {
1064
-		// valeur par defaut
1065
-		if (is_utf8($texte)) {
1066
-			$charset = 'utf-8';
1067
-		} else {
1068
-			$charset = 'iso-8859-1';
1069
-		}
1070
-		spip_log("charset probable: $charset");
1071
-	}
1072
-
1073
-	return importer_charset($texte, $charset);
1027
+    // Si tout est < 128 pas la peine d'aller plus loin
1028
+    if (is_ascii($texte)) {
1029
+        #spip_log('charset: ascii');
1030
+        return $texte;
1031
+    }
1032
+
1033
+    if (bom_utf8($texte)) {
1034
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
1035
+        $charset = 'utf-8';
1036
+        $texte = substr($texte, 3);
1037
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1038
+        // charset precise par le contenu (xml)
1039
+        $charset = trim(strtolower($regs[1]));
1040
+    } elseif (
1041
+        // charset precise par le contenu (html)
1042
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1043
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1044
+        and false === strpos($regs[2], '#')
1045
+        and $tmp = trim(strtolower($regs[2]))
1046
+    ) {
1047
+        $charset = $tmp;
1048
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1049
+        // charset de la reponse http
1050
+        $charset = trim(strtolower($regs[1]));
1051
+    } else {
1052
+        $charset = '';
1053
+    }
1054
+
1055
+
1056
+    // normaliser les noms du shif-jis japonais
1057
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1058
+        $charset = 'shift-jis';
1059
+    }
1060
+
1061
+    if ($charset) {
1062
+        spip_log("charset: $charset");
1063
+    } else {
1064
+        // valeur par defaut
1065
+        if (is_utf8($texte)) {
1066
+            $charset = 'utf-8';
1067
+        } else {
1068
+            $charset = 'iso-8859-1';
1069
+        }
1070
+        spip_log("charset probable: $charset");
1071
+    }
1072
+
1073
+    return importer_charset($texte, $charset);
1074 1074
 }
1075 1075
 
1076 1076
 
@@ -1094,26 +1094,26 @@  discard block
 block discarded – undo
1094 1094
  *     Le texte coupé
1095 1095
  **/
1096 1096
 function spip_substr($c, $start = 0, $length = null) {
1097
-	// Si ce n'est pas utf-8, utiliser substr
1098
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1099
-		if ($length) {
1100
-			return substr($c, $start, $length);
1101
-		} else {
1102
-			substr($c, $start);
1103
-		}
1104
-	}
1105
-
1106
-	// Si utf-8, voir si on dispose de mb_string
1107
-	if (init_mb_string()) {
1108
-		if ($length) {
1109
-			return mb_substr($c, $start, $length);
1110
-		} else {
1111
-			return mb_substr($c, $start);
1112
-		}
1113
-	}
1114
-
1115
-	// Version manuelle (cf. ci-dessous)
1116
-	return spip_substr_manuelle($c, $start, $length);
1097
+    // Si ce n'est pas utf-8, utiliser substr
1098
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1099
+        if ($length) {
1100
+            return substr($c, $start, $length);
1101
+        } else {
1102
+            substr($c, $start);
1103
+        }
1104
+    }
1105
+
1106
+    // Si utf-8, voir si on dispose de mb_string
1107
+    if (init_mb_string()) {
1108
+        if ($length) {
1109
+            return mb_substr($c, $start, $length);
1110
+        } else {
1111
+            return mb_substr($c, $start);
1112
+        }
1113
+    }
1114
+
1115
+    // Version manuelle (cf. ci-dessous)
1116
+    return spip_substr_manuelle($c, $start, $length);
1117 1117
 }
1118 1118
 
1119 1119
 
@@ -1132,40 +1132,40 @@  discard block
 block discarded – undo
1132 1132
  **/
1133 1133
 function spip_substr_manuelle($c, $start, $length = null) {
1134 1134
 
1135
-	// Cas pathologique
1136
-	if ($length === 0) {
1137
-		return '';
1138
-	}
1139
-
1140
-	// S'il y a un demarrage, on se positionne
1141
-	if ($start > 0) {
1142
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1143
-	} elseif ($start < 0) {
1144
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1145
-	}
1146
-
1147
-	if (!$length) {
1148
-		return $c;
1149
-	}
1150
-
1151
-	if ($length > 0) {
1152
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153
-		// (un caractere utf-8 prenant au maximum n bytes)
1154
-		$n = 0;
1155
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1156
-			;
1157
-		}
1158
-		$c = substr($c, 0, $n * $length);
1159
-		// puis, tant qu'on est trop long, on coupe...
1160
-		while (($l = spip_strlen($c)) > $length) {
1161
-			$c = substr($c, 0, $length - $l);
1162
-		}
1163
-
1164
-		return $c;
1165
-	}
1166
-
1167
-	// $length < 0
1168
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1135
+    // Cas pathologique
1136
+    if ($length === 0) {
1137
+        return '';
1138
+    }
1139
+
1140
+    // S'il y a un demarrage, on se positionne
1141
+    if ($start > 0) {
1142
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1143
+    } elseif ($start < 0) {
1144
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1145
+    }
1146
+
1147
+    if (!$length) {
1148
+        return $c;
1149
+    }
1150
+
1151
+    if ($length > 0) {
1152
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153
+        // (un caractere utf-8 prenant au maximum n bytes)
1154
+        $n = 0;
1155
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1156
+            ;
1157
+        }
1158
+        $c = substr($c, 0, $n * $length);
1159
+        // puis, tant qu'on est trop long, on coupe...
1160
+        while (($l = spip_strlen($c)) > $length) {
1161
+            $c = substr($c, 0, $length - $l);
1162
+        }
1163
+
1164
+        return $c;
1165
+    }
1166
+
1167
+    // $length < 0
1168
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1169 1169
 }
1170 1170
 
1171 1171
 /**
@@ -1179,14 +1179,14 @@  discard block
 block discarded – undo
1179 1179
  *     La chaîne avec une majuscule sur le premier mot
1180 1180
  */
1181 1181
 function spip_ucfirst($c) {
1182
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1183
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1184
-		return ucfirst($c);
1185
-	}
1182
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1183
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1184
+        return ucfirst($c);
1185
+    }
1186 1186
 
1187
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1187
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1188 1188
 
1189
-	return $lettre1 . spip_substr($c, 1);
1189
+    return $lettre1 . spip_substr($c, 1);
1190 1190
 }
1191 1191
 
1192 1192
 /**
@@ -1200,12 +1200,12 @@  discard block
 block discarded – undo
1200 1200
  *     La chaîne en minuscules
1201 1201
  */
1202 1202
 function spip_strtolower($c) {
1203
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1204
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1205
-		return strtolower($c);
1206
-	}
1203
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1204
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1205
+        return strtolower($c);
1206
+    }
1207 1207
 
1208
-	return mb_strtolower($c);
1208
+    return mb_strtolower($c);
1209 1209
 }
1210 1210
 
1211 1211
 /**
@@ -1219,23 +1219,23 @@  discard block
 block discarded – undo
1219 1219
  *     Longueur de la chaîne
1220 1220
  */
1221 1221
 function spip_strlen($c) {
1222
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1223
-	$c = str_replace("\r\n", "\n", $c);
1224
-
1225
-	// Si ce n'est pas utf-8, utiliser strlen
1226
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1227
-		return strlen($c);
1228
-	}
1229
-
1230
-	// Sinon, utiliser mb_strlen() si disponible
1231
-	if (init_mb_string()) {
1232
-		return mb_strlen($c);
1233
-	}
1234
-
1235
-	// Methode manuelle : on supprime les bytes 10......,
1236
-	// on compte donc les ascii (0.......) et les demarrages
1237
-	// de caracteres utf-8 (11......)
1238
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1222
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1223
+    $c = str_replace("\r\n", "\n", $c);
1224
+
1225
+    // Si ce n'est pas utf-8, utiliser strlen
1226
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1227
+        return strlen($c);
1228
+    }
1229
+
1230
+    // Sinon, utiliser mb_strlen() si disponible
1231
+    if (init_mb_string()) {
1232
+        return mb_strlen($c);
1233
+    }
1234
+
1235
+    // Methode manuelle : on supprime les bytes 10......,
1236
+    // on compte donc les ascii (0.......) et les demarrages
1237
+    // de caracteres utf-8 (11......)
1238
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1239 1239
 }
1240 1240
 
1241 1241
 // Initialisation
@@ -1245,16 +1245,16 @@  discard block
 block discarded – undo
1245 1245
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1246 1246
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1247 1247
 if (
1248
-	!isset($GLOBALS['meta']['pcre_u'])
1249
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1248
+    !isset($GLOBALS['meta']['pcre_u'])
1249
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1250 1250
 ) {
1251
-	include_spip('inc/meta');
1252
-	ecrire_meta(
1253
-		'pcre_u',
1254
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1255
-			and test_pcre_unicode())
1256
-			? 'u' : ''
1257
-	);
1251
+    include_spip('inc/meta');
1252
+    ecrire_meta(
1253
+        'pcre_u',
1254
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1255
+            and test_pcre_unicode())
1256
+            ? 'u' : ''
1257
+    );
1258 1258
 }
1259 1259
 
1260 1260
 
@@ -1270,17 +1270,17 @@  discard block
 block discarded – undo
1270 1270
  *     en unicode : &#128169;
1271 1271
  */
1272 1272
 function utf8_noplanes($x) {
1273
-	$regexp_utf8_4bytes = '/(
1273
+    $regexp_utf8_4bytes = '/(
1274 1274
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1275 1275
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1276 1276
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1277 1277
 )/xS';
1278
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1279
-		foreach ($z[0] as $k) {
1280
-			$ku = utf_8_to_unicode($k);
1281
-			$x = str_replace($k, $ku, $x);
1282
-		}
1283
-	}
1284
-
1285
-	return $x;
1278
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1279
+        foreach ($z[0] as $k) {
1280
+            $ku = utf_8_to_unicode($k);
1281
+            $x = str_replace($k, $ku, $x);
1282
+        }
1283
+    }
1284
+
1285
+    return $x;
1286 1286
 }
Please login to merge, or discard this patch.
ecrire/inc/presentation.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Presentation
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/presentation_mini');
@@ -32,141 +32,141 @@  discard block
 block discarded – undo
32 32
 
33 33
 // https://code.spip.net/@debut_cadre
34 34
 function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '', $class = '', $padding = true) {
35
-	$style_mapping = [
36
-		'r' => 'simple',
37
-		'e' => 'raccourcis',
38
-		'couleur' => 'basic highlight',
39
-		'couleur-foncee' => 'basic highlight',
40
-		'trait-couleur' => 'important',
41
-		'alerte' => 'notice',
42
-		'info' => 'info',
43
-		'sous_rub' => 'simple sous-rub'
44
-	];
45
-	$style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46
-	$c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
-	$class = $c . ($class ? " $class" : '');
48
-	if (!$padding) {
49
-		$class .= ($class ? ' ' : '') . 'no-padding';
50
-	}
51
-
52
-	//($id?"id='$id' ":"")
53
-	if (strlen($icone) > 1) {
54
-		if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
55
-			list($fond, $fonction) = $icone_renommer($icone, $fonction);
56
-		}
57
-		$size = 24;
58
-		if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) {
59
-			$size = $match[1];
60
-		}
61
-		if ($fonction) {
62
-			// 2 images pour composer l'icone : le fond (article) en background,
63
-			// la fonction (new) en image
64
-			$icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
65
-				http_style_background($fond, 'no-repeat center center', $size));
66
-		} else {
67
-			$icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68
-		}
69
-		$titre = $icone . $titre;
70
-	}
71
-
72
-	return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
35
+    $style_mapping = [
36
+        'r' => 'simple',
37
+        'e' => 'raccourcis',
38
+        'couleur' => 'basic highlight',
39
+        'couleur-foncee' => 'basic highlight',
40
+        'trait-couleur' => 'important',
41
+        'alerte' => 'notice',
42
+        'info' => 'info',
43
+        'sous_rub' => 'simple sous-rub'
44
+    ];
45
+    $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46
+    $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
+    $class = $c . ($class ? " $class" : '');
48
+    if (!$padding) {
49
+        $class .= ($class ? ' ' : '') . 'no-padding';
50
+    }
51
+
52
+    //($id?"id='$id' ":"")
53
+    if (strlen($icone) > 1) {
54
+        if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
55
+            list($fond, $fonction) = $icone_renommer($icone, $fonction);
56
+        }
57
+        $size = 24;
58
+        if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) {
59
+            $size = $match[1];
60
+        }
61
+        if ($fonction) {
62
+            // 2 images pour composer l'icone : le fond (article) en background,
63
+            // la fonction (new) en image
64
+            $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
65
+                http_style_background($fond, 'no-repeat center center', $size));
66
+        } else {
67
+            $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68
+        }
69
+        $titre = $icone . $titre;
70
+    }
71
+
72
+    return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
73 73
 }
74 74
 
75 75
 // https://code.spip.net/@fin_cadre
76 76
 function fin_cadre() {
77
- return boite_fermer();
77
+    return boite_fermer();
78 78
 }
79 79
 
80 80
 
81 81
 function debut_cadre_relief(
82
-	$icone = '',
83
-	$dummy = '',
84
-	$fonction = '',
85
-	$titre = '',
86
-	$id = '',
87
-	$class = ''
82
+    $icone = '',
83
+    $dummy = '',
84
+    $fonction = '',
85
+    $titre = '',
86
+    $id = '',
87
+    $class = ''
88 88
 ) {
89
-	return debut_cadre('r', $icone, $fonction, $titre, $id, $class);
89
+    return debut_cadre('r', $icone, $fonction, $titre, $id, $class);
90 90
 }
91 91
 
92 92
 function fin_cadre_relief() {
93
- return fin_cadre('r');
93
+    return fin_cadre('r');
94 94
 }
95 95
 
96 96
 function debut_cadre_enfonce(
97
-	$icone = '',
98
-	$dummy = '',
99
-	$fonction = '',
100
-	$titre = '',
101
-	$id = '',
102
-	$class = ''
97
+    $icone = '',
98
+    $dummy = '',
99
+    $fonction = '',
100
+    $titre = '',
101
+    $id = '',
102
+    $class = ''
103 103
 ) {
104
-	return debut_cadre('e', $icone, $fonction, $titre, $id, $class);
104
+    return debut_cadre('e', $icone, $fonction, $titre, $id, $class);
105 105
 }
106 106
 
107 107
 function fin_cadre_enfonce() {
108
- return fin_cadre('e');
108
+    return fin_cadre('e');
109 109
 }
110 110
 
111 111
 function debut_cadre_sous_rub(
112
-	$icone = '',
113
-	$dummy = '',
114
-	$fonction = '',
115
-	$titre = '',
116
-	$id = '',
117
-	$class = ''
112
+    $icone = '',
113
+    $dummy = '',
114
+    $fonction = '',
115
+    $titre = '',
116
+    $id = '',
117
+    $class = ''
118 118
 ) {
119
-	return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);
119
+    return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);
120 120
 }
121 121
 
122 122
 function fin_cadre_sous_rub() {
123
- return fin_cadre('sous_rub');
123
+    return fin_cadre('sous_rub');
124 124
 }
125 125
 
126 126
 function debut_cadre_couleur(
127
-	$icone = '',
128
-	$dummy = '',
129
-	$fonction = '',
130
-	$titre = '',
131
-	$id = '',
132
-	$class = ''
127
+    $icone = '',
128
+    $dummy = '',
129
+    $fonction = '',
130
+    $titre = '',
131
+    $id = '',
132
+    $class = ''
133 133
 ) {
134
-	return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);
134
+    return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);
135 135
 }
136 136
 
137 137
 function fin_cadre_couleur() {
138
- return fin_cadre('couleur');
138
+    return fin_cadre('couleur');
139 139
 }
140 140
 
141 141
 function debut_cadre_trait_couleur(
142
-	$icone = '',
143
-	$dummy = '',
144
-	$fonction = '',
145
-	$titre = '',
146
-	$id = '',
147
-	$class = ''
142
+    $icone = '',
143
+    $dummy = '',
144
+    $fonction = '',
145
+    $titre = '',
146
+    $id = '',
147
+    $class = ''
148 148
 ) {
149
-	return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);
149
+    return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);
150 150
 }
151 151
 
152 152
 function fin_cadre_trait_couleur() {
153
- return fin_cadre('trait-couleur');
153
+    return fin_cadre('trait-couleur');
154 154
 }
155 155
 
156 156
 function debut_boite_alerte() {
157
- return debut_cadre('alerte', '', '', '', '', '');
157
+    return debut_cadre('alerte', '', '', '', '', '');
158 158
 }
159 159
 
160 160
 function fin_boite_alerte() {
161
- return fin_cadre('alerte');
161
+    return fin_cadre('alerte');
162 162
 }
163 163
 
164 164
 function debut_boite_info() {
165
- return debut_cadre('info', '', '', '', '', '');
165
+    return debut_cadre('info', '', '', '', '', '');
166 166
 }
167 167
 
168 168
 function fin_boite_info() {
169
- return fin_cadre('info');
169
+    return fin_cadre('info');
170 170
 }
171 171
 
172 172
 /**
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
  * @return string Code PHP.
178 178
  **/
179 179
 function gros_titre(
180
-	$titre,
181
-	$ze_logo = ''
180
+    $titre,
181
+    $ze_logo = ''
182 182
 ) {
183
-	return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
183
+    return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
184 184
 }
185 185
 
186 186
 // La boite des raccourcis
187 187
 // Se place a droite si l'ecran est en mode panoramique.
188 188
 // https://code.spip.net/@bloc_des_raccourcis
189 189
 function bloc_des_raccourcis($bloc) {
190
-	return creer_colonne_droite()
191
-	. boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
190
+    return creer_colonne_droite()
191
+    . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
192 192
 }
193 193
 
194 194
 //
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
 // https://code.spip.net/@debut_onglet
200 200
 // @param string $sous_classe	prend la valeur second pour definir les onglet de deuxieme niveau
201 201
 function debut_onglet($classe = 'barre_onglet') {
202
- return "<div class = '$classe clearfix'><ul>\n";
202
+    return "<div class = '$classe clearfix'><ul>\n";
203 203
 }
204 204
 
205 205
 // https://code.spip.net/@fin_onglet
206 206
 function fin_onglet() {
207
- return "</ul></div>\n";
207
+    return "</ul></div>\n";
208 208
 }
209 209
 
210 210
 // https://code.spip.net/@onglet
211 211
 function onglet($texte, $lien, $onglet_ref, $onglet, $icone = '') {
212
-	return '<li>'
213
-	. ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '')
214
-	. lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
215
-	. '</li>';
212
+    return '<li>'
213
+    . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '')
214
+    . lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
215
+    . '</li>';
216 216
 }
217 217
 
218 218
 /**
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
  *     Code HTML du lien
245 245
  **/
246 246
 function icone_verticale($texte, $lien, $fond, $fonction = '', $align = '', $javascript = '') {
247
-	// cas d'ajax_action_auteur: faut defaire le boulot
248
-	// (il faudrait fusionner avec le cas $javascript)
249
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
250
-		list($x, $lien, $atts, $texte) = $r;
251
-		$javascript .= $atts;
252
-	}
253
-
254
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
247
+    // cas d'ajax_action_auteur: faut defaire le boulot
248
+    // (il faudrait fusionner avec le cas $javascript)
249
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
250
+        list($x, $lien, $atts, $texte) = $r;
251
+        $javascript .= $atts;
252
+    }
253
+
254
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
255 255
 }
256 256
 
257 257
 /**
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
  *     Code HTML du lien
277 277
  **/
278 278
 function icone_horizontale($texte, $lien, $fond, $fonction = '', $dummy = '', $javascript = '') {
279
-	$retour = '';
280
-	// cas d'ajax_action_auteur: faut defaire le boulot
281
-	// (il faudrait fusionner avec le cas $javascript)
282
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
283
-		list($x, $lien, $atts, $texte) = $r;
284
-		$javascript .= $atts;
285
-	}
279
+    $retour = '';
280
+    // cas d'ajax_action_auteur: faut defaire le boulot
281
+    // (il faudrait fusionner avec le cas $javascript)
282
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
283
+        list($x, $lien, $atts, $texte) = $r;
284
+        $javascript .= $atts;
285
+    }
286 286
 
287
-	$retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript);
287
+    $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript);
288 288
 
289
-	return $retour;
289
+    return $retour;
290 290
 }
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  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
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,127 +49,127 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = [],
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = [],
57
+    $primary = ''
58 58
 ) {
59
-	static $cache = [];
60
-	$delai_fraicheur = min(
61
-		_DELAI_CACHE_resultats,
62
-		time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)
63
-	);
64
-
65
-	// si recherche n'est pas dans le contexte, on va prendre en globals
66
-	// ca permet de faire des inclure simple.
67
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
68
-		$recherche = $GLOBALS['recherche'];
69
-	}
70
-
71
-	// traiter le cas {recherche?}
72
-	if ($cond and !strlen($recherche)) {
73
-		return [
74
-			'0 as points' /* as points */, /* where */
75
-			''
76
-		];
77
-	}
78
-
79
-
80
-	$rechercher = false;
81
-
82
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83
-	if (!isset($cache[$serveur][$table][$recherche])) {
84
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
-		$hash = substr(md5($recherche . $table), 0, 16);
86
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
87
-		$row = sql_fetsel(
88
-			'recherche',
89
-			'spip_resultats AS resultats',
90
-			$where . " AND $where_resultat_recent",
91
-			'',
92
-			'',
93
-			'0,1'
94
-		);
95
-		if (
96
-			!$row
97
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
98
-		) {
99
-			$rechercher = true;
100
-		}
101
-	}
102
-
103
-	// si on n'a pas encore traite les donnees dans une boucle precedente
104
-	if ($rechercher) {
105
-		//$tables = liste_des_champs();
106
-		$x = objet_type($table);
107
-		$points = recherche_en_base(
108
-			$recherche,
109
-			$x,
110
-			[
111
-				'score' => true,
112
-				'toutvoir' => true,
113
-				'jointures' => true
114
-			],
115
-			$serveur
116
-		);
117
-		// pas de résultat, pas de point
118
-		$points = isset($points[$x]) ? $points[$x] : [];
119
-
120
-		// permettre aux plugins de modifier le resultat
121
-		$points = pipeline('prepare_recherche', [
122
-			'args' => [
123
-				'type' => $x,
124
-				'recherche' => $recherche,
125
-				'serveur' => $serveur,
126
-				'modificateurs' => $modificateurs
127
-			],
128
-			'data' => $points
129
-		]);
130
-
131
-		// supprimer les anciens resultats de cette recherche
132
-		// et les resultats trop vieux avec une marge
133
-		// pas de AS resultats dans un delete (mysql)
134
-		$whered = str_replace(
135
-			['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
136
-			['recherche', 'table_objet', 'serveur'],
137
-			$where
138
-		);
139
-
140
-		sql_delete(
141
-			'spip_resultats',
142
-			"NOT($where_resultat_recent) OR ($whered)"
143
-		);
144
-
145
-		// inserer les resultats dans la table de cache des resultats
146
-		if (count($points)) {
147
-			$tab_couples = [];
148
-			foreach ($points as $id => $p) {
149
-				$tab_couples[] = [
150
-					'recherche' => $hash,
151
-					'id' => $id,
152
-					'points' => $p['score'],
153
-					'table_objet' => $table,
154
-					'serveur' => $hash_serv,
155
-				];
156
-			}
157
-			sql_insertq_multi('spip_resultats', $tab_couples, []);
158
-		}
159
-	}
160
-
161
-	if (!isset($cache[$serveur][$table][$recherche])) {
162
-		if (!$serveur) {
163
-			$cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
164
-		} else {
165
-			if (sql_countsel('spip_resultats as resultats', $where)) {
166
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
167
-			}
168
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
169
-		}
170
-	}
171
-
172
-	return $cache[$serveur][$table][$recherche];
59
+    static $cache = [];
60
+    $delai_fraicheur = min(
61
+        _DELAI_CACHE_resultats,
62
+        time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)
63
+    );
64
+
65
+    // si recherche n'est pas dans le contexte, on va prendre en globals
66
+    // ca permet de faire des inclure simple.
67
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
68
+        $recherche = $GLOBALS['recherche'];
69
+    }
70
+
71
+    // traiter le cas {recherche?}
72
+    if ($cond and !strlen($recherche)) {
73
+        return [
74
+            '0 as points' /* as points */, /* where */
75
+            ''
76
+        ];
77
+    }
78
+
79
+
80
+    $rechercher = false;
81
+
82
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83
+    if (!isset($cache[$serveur][$table][$recherche])) {
84
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
+        $hash = substr(md5($recherche . $table), 0, 16);
86
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
87
+        $row = sql_fetsel(
88
+            'recherche',
89
+            'spip_resultats AS resultats',
90
+            $where . " AND $where_resultat_recent",
91
+            '',
92
+            '',
93
+            '0,1'
94
+        );
95
+        if (
96
+            !$row
97
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
98
+        ) {
99
+            $rechercher = true;
100
+        }
101
+    }
102
+
103
+    // si on n'a pas encore traite les donnees dans une boucle precedente
104
+    if ($rechercher) {
105
+        //$tables = liste_des_champs();
106
+        $x = objet_type($table);
107
+        $points = recherche_en_base(
108
+            $recherche,
109
+            $x,
110
+            [
111
+                'score' => true,
112
+                'toutvoir' => true,
113
+                'jointures' => true
114
+            ],
115
+            $serveur
116
+        );
117
+        // pas de résultat, pas de point
118
+        $points = isset($points[$x]) ? $points[$x] : [];
119
+
120
+        // permettre aux plugins de modifier le resultat
121
+        $points = pipeline('prepare_recherche', [
122
+            'args' => [
123
+                'type' => $x,
124
+                'recherche' => $recherche,
125
+                'serveur' => $serveur,
126
+                'modificateurs' => $modificateurs
127
+            ],
128
+            'data' => $points
129
+        ]);
130
+
131
+        // supprimer les anciens resultats de cette recherche
132
+        // et les resultats trop vieux avec une marge
133
+        // pas de AS resultats dans un delete (mysql)
134
+        $whered = str_replace(
135
+            ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
136
+            ['recherche', 'table_objet', 'serveur'],
137
+            $where
138
+        );
139
+
140
+        sql_delete(
141
+            'spip_resultats',
142
+            "NOT($where_resultat_recent) OR ($whered)"
143
+        );
144
+
145
+        // inserer les resultats dans la table de cache des resultats
146
+        if (count($points)) {
147
+            $tab_couples = [];
148
+            foreach ($points as $id => $p) {
149
+                $tab_couples[] = [
150
+                    'recherche' => $hash,
151
+                    'id' => $id,
152
+                    'points' => $p['score'],
153
+                    'table_objet' => $table,
154
+                    'serveur' => $hash_serv,
155
+                ];
156
+            }
157
+            sql_insertq_multi('spip_resultats', $tab_couples, []);
158
+        }
159
+    }
160
+
161
+    if (!isset($cache[$serveur][$table][$recherche])) {
162
+        if (!$serveur) {
163
+            $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
164
+        } else {
165
+            if (sql_countsel('spip_resultats as resultats', $where)) {
166
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
167
+            }
168
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
169
+        }
170
+    }
171
+
172
+    return $cache[$serveur][$table][$recherche];
173 173
 }
174 174
 
175 175
 
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
  * @return array
186 186
  */
187 187
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
188
-	# calculer le {id_article IN()} et le {... as points}
189
-	if (!count($rows)) {
190
-		return ["''", '0=1'];
191
-	} else {
192
-		$listes_ids = [];
193
-		$select = '0';
194
-		foreach ($rows as $r) {
195
-			$listes_ids[$r['points']][] = $r['id'];
196
-		}
197
-
198
-		foreach ($listes_ids as $p => $ids) {
199
-			$select .= "+$p*(" .
200
-				sql_in("$table.$primary", $ids, '', $serveur)
201
-				. ') ';
202
-		}
203
-
204
-		return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
205
-	}
188
+    # calculer le {id_article IN()} et le {... as points}
189
+    if (!count($rows)) {
190
+        return ["''", '0=1'];
191
+    } else {
192
+        $listes_ids = [];
193
+        $select = '0';
194
+        foreach ($rows as $r) {
195
+            $listes_ids[$r['points']][] = $r['id'];
196
+        }
197
+
198
+        foreach ($listes_ids as $p => $ids) {
199
+            $select .= "+$p*(" .
200
+                sql_in("$table.$primary", $ids, '', $serveur)
201
+                . ') ';
202
+        }
203
+
204
+        return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
205
+    }
206 206
 }
Please login to merge, or discard this patch.
ecrire/inc/exporter_csv.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/charsets');
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function exporter_csv_champ($champ) {
35
-	#$champ = str_replace("\r", "\n", $champ);
36
-	#$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
-	#$champ = str_replace("\n", ", ", $champ);
38
-	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
-	$champ = str_replace('"', '""', $champ);
35
+    #$champ = str_replace("\r", "\n", $champ);
36
+    #$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
+    #$champ = str_replace("\n", ", ", $champ);
38
+    $champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
+    $champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+    return '"' . $champ . '"';
42 42
 }
43 43
 
44 44
 /**
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
  * @return string
56 56
  */
57 57
 function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, $callback = null) {
58
-	if ($callback) {
59
-		$ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60
-	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
-	if ($importer_charset) {
63
-		$output = str_replace('’', '\'', $output);
64
-		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
-	}
66
-	return $output;
58
+    if ($callback) {
59
+        $ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60
+    }
61
+    $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
+    if ($importer_charset) {
63
+        $output = str_replace('’', '\'', $output);
64
+        $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
+    }
66
+    return $output;
67 67
 }
68 68
 
69 69
 /**
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
  * @return string
76 76
  */
77 77
 function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) {
78
-	return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
78
+    return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
79 79
 }
80 80
 
81 81
 /**
@@ -101,101 +101,101 @@  discard block
 block discarded – undo
101 101
  */
102 102
 function inc_exporter_csv_dist($titre, $resource, $options = []) {
103 103
 
104
-	// support ancienne syntaxe
105
-	// inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
-	if (is_string($options)) {
107
-		$args = func_get_args();
108
-		$options = [];
109
-		foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
-			if (!empty($args[$k])) {
111
-				$options[$option] = $args[$k];
112
-			}
113
-		}
114
-	}
115
-
116
-	$default_options = [
117
-		'delim' => ', ',
118
-		'entetes' => null,
119
-		'envoyer' => true,
120
-		'charset' => null,
121
-		'callback' => null,
122
-	];
123
-	$options = array_merge($default_options, $options);
124
-
125
-	$filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
-
127
-	if ($options['delim'] == 'TAB') {
128
-		$options['delim'] = "\t";
129
-	}
130
-	if (!in_array($options['delim'], [',', ';', "\t"])) {
131
-		$options['delim'] = ',';
132
-	}
133
-
134
-	$charset = $GLOBALS['meta']['charset'];
135
-	$importer_charset = null;
136
-	if ($options['delim'] == ',') {
137
-		$extension = 'csv';
138
-	} else {
139
-		$extension = 'xls';
140
-		# Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
-		$charset = 'iso-8859-1';
142
-	}
143
-	// mais si une option charset est explicite, elle a la priorite
144
-	if (!empty($options['charset'])) {
145
-		$charset = $options['charset'];
146
-	}
147
-
148
-	$importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
-
150
-	$filename = "$filename.$extension";
151
-
152
-	$output = '';
153
-	$nb = 0;
154
-	if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
-		$output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
-	}
157
-	// les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
-	$nb++;
159
-
160
-	if ($options['envoyer']) {
161
-		$disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
-		header("Content-Type: text/comma-separated-values; charset=$charset");
163
-		header("Content-Disposition: $disposition; filename=$filename");
164
-
165
-		// Vider tous les tampons
166
-		$level = @ob_get_level();
167
-		while ($level--) {
168
-			@ob_end_flush();
169
-		}
170
-	}
171
-
172
-	// si envoyer=='attachment' on passe par un fichier temporaire
173
-	// sinon on ecrit directement sur stdout
174
-	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
-		$fichier = 'php://output';
176
-	}
177
-	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
-	}
180
-
181
-	$fp = fopen($fichier, 'w');
182
-	$length = fwrite($fp, $output);
183
-
184
-	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
-		$output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
-		$length += fwrite($fp, $output);
187
-		$nb++;
188
-	}
189
-	fclose($fp);
190
-
191
-	if ($options['envoyer']) {
192
-		if ($options['envoyer'] === 'attachment') {
193
-			header("Content-Length: $length");
194
-			readfile($fichier);
195
-		}
196
-		// si on a envoye inline, c'est deja tout bon
197
-		exit;
198
-	}
199
-
200
-	return $fichier;
104
+    // support ancienne syntaxe
105
+    // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
+    if (is_string($options)) {
107
+        $args = func_get_args();
108
+        $options = [];
109
+        foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
+            if (!empty($args[$k])) {
111
+                $options[$option] = $args[$k];
112
+            }
113
+        }
114
+    }
115
+
116
+    $default_options = [
117
+        'delim' => ', ',
118
+        'entetes' => null,
119
+        'envoyer' => true,
120
+        'charset' => null,
121
+        'callback' => null,
122
+    ];
123
+    $options = array_merge($default_options, $options);
124
+
125
+    $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
+
127
+    if ($options['delim'] == 'TAB') {
128
+        $options['delim'] = "\t";
129
+    }
130
+    if (!in_array($options['delim'], [',', ';', "\t"])) {
131
+        $options['delim'] = ',';
132
+    }
133
+
134
+    $charset = $GLOBALS['meta']['charset'];
135
+    $importer_charset = null;
136
+    if ($options['delim'] == ',') {
137
+        $extension = 'csv';
138
+    } else {
139
+        $extension = 'xls';
140
+        # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
+        $charset = 'iso-8859-1';
142
+    }
143
+    // mais si une option charset est explicite, elle a la priorite
144
+    if (!empty($options['charset'])) {
145
+        $charset = $options['charset'];
146
+    }
147
+
148
+    $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
+
150
+    $filename = "$filename.$extension";
151
+
152
+    $output = '';
153
+    $nb = 0;
154
+    if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
+        $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
+    }
157
+    // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
+    $nb++;
159
+
160
+    if ($options['envoyer']) {
161
+        $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
+        header("Content-Type: text/comma-separated-values; charset=$charset");
163
+        header("Content-Disposition: $disposition; filename=$filename");
164
+
165
+        // Vider tous les tampons
166
+        $level = @ob_get_level();
167
+        while ($level--) {
168
+            @ob_end_flush();
169
+        }
170
+    }
171
+
172
+    // si envoyer=='attachment' on passe par un fichier temporaire
173
+    // sinon on ecrit directement sur stdout
174
+    if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
+        $fichier = 'php://output';
176
+    }
177
+    else {
178
+    $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
+    }
180
+
181
+    $fp = fopen($fichier, 'w');
182
+    $length = fwrite($fp, $output);
183
+
184
+    while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
+        $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
+        $length += fwrite($fp, $output);
187
+        $nb++;
188
+    }
189
+    fclose($fp);
190
+
191
+    if ($options['envoyer']) {
192
+        if ($options['envoyer'] === 'attachment') {
193
+            header("Content-Length: $length");
194
+            readfile($fichier);
195
+        }
196
+        // si on a envoye inline, c'est deja tout bon
197
+        exit;
198
+    }
199
+
200
+    return $fichier;
201 201
 }
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -35,22 +35,22 @@  discard block
 block discarded – undo
35 35
  * @return array Couples (type d'objet => Couples (champ => score))
36 36
  */
37 37
 function liste_des_champs() {
38
-	static $liste = null;
39
-	if (is_null($liste)) {
40
-		$liste = [];
41
-		// recuperer les tables_objets_sql declarees
42
-		include_spip('base/objets');
43
-		$tables_objets = lister_tables_objets_sql();
44
-		foreach ($tables_objets as $t => $infos) {
45
-			if ($infos['rechercher_champs']) {
46
-				$liste[$infos['type']] = $infos['rechercher_champs'];
47
-			}
48
-		}
49
-		// puis passer dans le pipeline
50
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
51
-	}
52
-
53
-	return $liste;
38
+    static $liste = null;
39
+    if (is_null($liste)) {
40
+        $liste = [];
41
+        // recuperer les tables_objets_sql declarees
42
+        include_spip('base/objets');
43
+        $tables_objets = lister_tables_objets_sql();
44
+        foreach ($tables_objets as $t => $infos) {
45
+            if ($infos['rechercher_champs']) {
46
+                $liste[$infos['type']] = $infos['rechercher_champs'];
47
+            }
48
+        }
49
+        // puis passer dans le pipeline
50
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
51
+    }
52
+
53
+    return $liste;
54 54
 }
55 55
 
56 56
 
@@ -58,176 +58,176 @@  discard block
 block discarded – undo
58 58
 // en ne regardant que le titre ou le nom
59 59
 // https://code.spip.net/@liste_des_jointures
60 60
 function liste_des_jointures() {
61
-	static $liste = null;
62
-	if (is_null($liste)) {
63
-		$liste = [];
64
-		// recuperer les tables_objets_sql declarees
65
-		include_spip('base/objets');
66
-		$tables_objets = lister_tables_objets_sql();
67
-		foreach ($tables_objets as $t => $infos) {
68
-			if ($infos['rechercher_jointures']) {
69
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
70
-			}
71
-		}
72
-		// puis passer dans le pipeline
73
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
74
-	}
75
-
76
-	return $liste;
61
+    static $liste = null;
62
+    if (is_null($liste)) {
63
+        $liste = [];
64
+        // recuperer les tables_objets_sql declarees
65
+        include_spip('base/objets');
66
+        $tables_objets = lister_tables_objets_sql();
67
+        foreach ($tables_objets as $t => $infos) {
68
+            if ($infos['rechercher_jointures']) {
69
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
70
+            }
71
+        }
72
+        // puis passer dans le pipeline
73
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
74
+    }
75
+
76
+    return $liste;
77 77
 }
78 78
 
79 79
 function expression_recherche($recherche, $options) {
80
-	// ne calculer qu'une seule fois l'expression par hit
81
-	// (meme si utilisee dans plusieurs boucles)
82
-	static $expression = [];
83
-	$key = serialize([$recherche, $options['preg_flags']]);
84
-	if (isset($expression[$key])) {
85
-		return $expression[$key];
86
-	}
87
-
88
-	$u = $GLOBALS['meta']['pcre_u'];
89
-	if ($u and strpos($options['preg_flags'], $u) === false) {
90
-		$options['preg_flags'] .= $u;
91
-	}
92
-	include_spip('inc/charsets');
93
-	$recherche = trim($recherche);
94
-
95
-	// retirer les + de +truc et les * de truc*
96
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
97
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
98
-
99
-	$is_preg = false;
100
-	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101
-		// c'est une preg
102
-		$recherche_trans = translitteration($recherche);
103
-		$preg = $recherche_trans . $options['preg_flags'];
104
-		$is_preg = true;
105
-	} else {
106
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
107
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
108
-		// 'une', 'des' ...)
109
-
110
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
111
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
112
-
113
-		// les expressions entre " " sont un mot a chercher tel quel
114
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
115
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
116
-			foreach ($matches as $match) {
117
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
118
-				$word = trim($word, '"');
119
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
120
-			}
121
-		}
122
-
123
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
124
-			$is_preg = true;
125
-
126
-			$recherche_inter = '|';
127
-			$recherche_mots = explode(' ', $recherche_mod);
128
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
129
-			$petits_mots = true;
130
-			foreach ($recherche_mots as $mot) {
131
-				if (strlen($mot) >= $min_long) {
132
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
-					$recherche_inter .= preg_quote($mot) . ' ';
134
-					$petits_mots = false;
135
-				}
136
-			}
137
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
138
-
139
-			// mais on cherche quand même l'expression complète, même si elle
140
-			// comporte des mots de moins de quatre lettres
141
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
142
-			if (!$recherche or $petits_mots) {
143
-				$recherche = preg_quote($recherche_org);
144
-			}
145
-			$recherche_trans = translitteration($recherche);
146
-		}
147
-
148
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
149
-	}
150
-
151
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
152
-	// ou si l'expression reguliere est invalide
153
-	if (
154
-		!$is_preg
155
-		or (@preg_match($preg, '') === false)
156
-	) {
157
-		$methode = 'LIKE';
158
-		$u = $GLOBALS['meta']['pcre_u'];
159
-
160
-		// echapper les % et _
161
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
162
-
163
-		// 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
164
-		$recherche = preg_quote($recherche, '/');
165
-		$recherche_trans = translitteration($recherche);
166
-		$recherche_mod = $recherche_trans;
167
-
168
-		// les expressions entre " " sont un mot a chercher tel quel
169
-		// -> on remplace les espaces par un _ et on enleve les guillemets
170
-		// corriger le like dans le $q
171
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
172
-			foreach ($matches as $match) {
173
-				$word = preg_replace(',\s+,Uims', '_', $match);
174
-				$word = trim($word, '"');
175
-				$q = str_replace($match, $word, $q);
176
-			}
177
-		}
178
-		// corriger la regexp
179
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
180
-			foreach ($matches as $match) {
181
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
182
-				$word = trim($word, '"');
183
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
184
-			}
185
-		}
186
-		$q = sql_quote(
187
-			'%'
188
-			. preg_replace(',\s+,' . $u, '%', $q)
189
-			. '%'
190
-		);
191
-
192
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
193
-	} else {
194
-		$methode = 'REGEXP';
195
-		$q = sql_quote(trim($recherche, '/'));
196
-	}
197
-
198
-	// tous les caracteres transliterables de $q sont remplaces par un joker
199
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
200
-	$q_t = $q;
201
-	for ($i = 0; $i < spip_strlen($q); $i++) {
202
-		$char = spip_substr($q, $i, 1);
203
-		if (
204
-			!is_ascii($char)
205
-			and $char_t = translitteration($char)
206
-			and $char_t !== $char
207
-		) {
208
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
209
-			// mais c'est un pis aller cf #4354
210
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
211
-		}
212
-	}
213
-
214
-	$q = $q_t;
215
-
216
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
217
-	// les plus frequents qui peuvent etre accentues
218
-	// (oui c'est tres dicustable...)
219
-	if (
220
-		isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'])
221
-		and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0
222
-	) {
223
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
224
-		// si il reste au moins un char significatif...
225
-		if (preg_match(",[^'%_.],", $q_t)) {
226
-			$q = $q_t;
227
-		}
228
-	}
229
-
230
-	return $expression[$key] = [$methode, $q, $preg];
80
+    // ne calculer qu'une seule fois l'expression par hit
81
+    // (meme si utilisee dans plusieurs boucles)
82
+    static $expression = [];
83
+    $key = serialize([$recherche, $options['preg_flags']]);
84
+    if (isset($expression[$key])) {
85
+        return $expression[$key];
86
+    }
87
+
88
+    $u = $GLOBALS['meta']['pcre_u'];
89
+    if ($u and strpos($options['preg_flags'], $u) === false) {
90
+        $options['preg_flags'] .= $u;
91
+    }
92
+    include_spip('inc/charsets');
93
+    $recherche = trim($recherche);
94
+
95
+    // retirer les + de +truc et les * de truc*
96
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
97
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
98
+
99
+    $is_preg = false;
100
+    if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101
+        // c'est une preg
102
+        $recherche_trans = translitteration($recherche);
103
+        $preg = $recherche_trans . $options['preg_flags'];
104
+        $is_preg = true;
105
+    } else {
106
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
107
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
108
+        // 'une', 'des' ...)
109
+
110
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
111
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
112
+
113
+        // les expressions entre " " sont un mot a chercher tel quel
114
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
115
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
116
+            foreach ($matches as $match) {
117
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
118
+                $word = trim($word, '"');
119
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
120
+            }
121
+        }
122
+
123
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
124
+            $is_preg = true;
125
+
126
+            $recherche_inter = '|';
127
+            $recherche_mots = explode(' ', $recherche_mod);
128
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
129
+            $petits_mots = true;
130
+            foreach ($recherche_mots as $mot) {
131
+                if (strlen($mot) >= $min_long) {
132
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
+                    $recherche_inter .= preg_quote($mot) . ' ';
134
+                    $petits_mots = false;
135
+                }
136
+            }
137
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
138
+
139
+            // mais on cherche quand même l'expression complète, même si elle
140
+            // comporte des mots de moins de quatre lettres
141
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
142
+            if (!$recherche or $petits_mots) {
143
+                $recherche = preg_quote($recherche_org);
144
+            }
145
+            $recherche_trans = translitteration($recherche);
146
+        }
147
+
148
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
149
+    }
150
+
151
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
152
+    // ou si l'expression reguliere est invalide
153
+    if (
154
+        !$is_preg
155
+        or (@preg_match($preg, '') === false)
156
+    ) {
157
+        $methode = 'LIKE';
158
+        $u = $GLOBALS['meta']['pcre_u'];
159
+
160
+        // echapper les % et _
161
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
162
+
163
+        // 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
164
+        $recherche = preg_quote($recherche, '/');
165
+        $recherche_trans = translitteration($recherche);
166
+        $recherche_mod = $recherche_trans;
167
+
168
+        // les expressions entre " " sont un mot a chercher tel quel
169
+        // -> on remplace les espaces par un _ et on enleve les guillemets
170
+        // corriger le like dans le $q
171
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
172
+            foreach ($matches as $match) {
173
+                $word = preg_replace(',\s+,Uims', '_', $match);
174
+                $word = trim($word, '"');
175
+                $q = str_replace($match, $word, $q);
176
+            }
177
+        }
178
+        // corriger la regexp
179
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
180
+            foreach ($matches as $match) {
181
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
182
+                $word = trim($word, '"');
183
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
184
+            }
185
+        }
186
+        $q = sql_quote(
187
+            '%'
188
+            . preg_replace(',\s+,' . $u, '%', $q)
189
+            . '%'
190
+        );
191
+
192
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
193
+    } else {
194
+        $methode = 'REGEXP';
195
+        $q = sql_quote(trim($recherche, '/'));
196
+    }
197
+
198
+    // tous les caracteres transliterables de $q sont remplaces par un joker
199
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
200
+    $q_t = $q;
201
+    for ($i = 0; $i < spip_strlen($q); $i++) {
202
+        $char = spip_substr($q, $i, 1);
203
+        if (
204
+            !is_ascii($char)
205
+            and $char_t = translitteration($char)
206
+            and $char_t !== $char
207
+        ) {
208
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
209
+            // mais c'est un pis aller cf #4354
210
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
211
+        }
212
+    }
213
+
214
+    $q = $q_t;
215
+
216
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
217
+    // les plus frequents qui peuvent etre accentues
218
+    // (oui c'est tres dicustable...)
219
+    if (
220
+        isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'])
221
+        and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0
222
+    ) {
223
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
224
+        // si il reste au moins un char significatif...
225
+        if (preg_match(",[^'%_.],", $q_t)) {
226
+            $q = $q_t;
227
+        }
228
+    }
229
+
230
+    return $expression[$key] = [$methode, $q, $preg];
231 231
 }
232 232
 
233 233
 
@@ -254,143 +254,143 @@  discard block
 block discarded – undo
254 254
  * @return array
255 255
  */
256 256
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
257
-	include_spip('base/abstract_sql');
258
-
259
-	if (!is_array($tables)) {
260
-		$liste = liste_des_champs();
261
-
262
-		if (
263
-			is_string($tables)
264
-			and $tables != ''
265
-		) {
266
-			$toutes = [];
267
-			foreach (explode(',', $tables) as $t) {
268
-				$t = trim($t);
269
-				if (isset($liste[$t])) {
270
-					$toutes[$t] = $liste[$t];
271
-				}
272
-			}
273
-			$tables = $toutes;
274
-			unset($toutes);
275
-		} else {
276
-			$tables = $liste;
277
-		}
278
-	}
279
-
280
-	if (!strlen($recherche) or !count($tables)) {
281
-		return [];
282
-	}
283
-
284
-	include_spip('inc/autoriser');
285
-
286
-	// options par defaut
287
-	$options = array_merge(
288
-		[
289
-		'preg_flags' => 'UimsS',
290
-		'toutvoir' => false,
291
-		'champs' => false,
292
-		'score' => false,
293
-		'matches' => false,
294
-		'jointures' => false,
295
-		'serveur' => $serveur
296
-		],
297
-		$options
298
-	);
299
-
300
-	$results = [];
301
-
302
-	// Utiliser l'iterateur (DATA:recherche)
303
-	// pour recuperer les couples (id_objet, score)
304
-	// Le resultat est au format {
305
-	//      id1 = { 'score' => x, attrs => { } },
306
-	//      id2 = { 'score' => x, attrs => { } },
307
-	// }
308
-
309
-	include_spip('inc/recherche_to_array');
310
-
311
-	foreach ($tables as $table => $champs) {
312
-		# lock via memoization, si dispo
313
-		if (function_exists('cache_lock')) {
314
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
315
-		}
316
-
317
-		spip_timer('rech');
318
-
319
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
320
-		$to_array = charger_fonction('recherche_to_array', 'inc');
321
-		$results[$table] = $to_array(
322
-			$recherche,
323
-			array_merge($options, ['table' => $table, 'champs' => $champs])
324
-		);
325
-		##var_dump($results[$table]);
326
-
327
-
328
-		spip_log(
329
-			"recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
330
-			'recherche'
331
-		);
332
-
333
-		if (isset($lock)) {
334
-			cache_unlock($lock);
335
-		}
336
-	}
337
-
338
-	return $results;
257
+    include_spip('base/abstract_sql');
258
+
259
+    if (!is_array($tables)) {
260
+        $liste = liste_des_champs();
261
+
262
+        if (
263
+            is_string($tables)
264
+            and $tables != ''
265
+        ) {
266
+            $toutes = [];
267
+            foreach (explode(',', $tables) as $t) {
268
+                $t = trim($t);
269
+                if (isset($liste[$t])) {
270
+                    $toutes[$t] = $liste[$t];
271
+                }
272
+            }
273
+            $tables = $toutes;
274
+            unset($toutes);
275
+        } else {
276
+            $tables = $liste;
277
+        }
278
+    }
279
+
280
+    if (!strlen($recherche) or !count($tables)) {
281
+        return [];
282
+    }
283
+
284
+    include_spip('inc/autoriser');
285
+
286
+    // options par defaut
287
+    $options = array_merge(
288
+        [
289
+        'preg_flags' => 'UimsS',
290
+        'toutvoir' => false,
291
+        'champs' => false,
292
+        'score' => false,
293
+        'matches' => false,
294
+        'jointures' => false,
295
+        'serveur' => $serveur
296
+        ],
297
+        $options
298
+    );
299
+
300
+    $results = [];
301
+
302
+    // Utiliser l'iterateur (DATA:recherche)
303
+    // pour recuperer les couples (id_objet, score)
304
+    // Le resultat est au format {
305
+    //      id1 = { 'score' => x, attrs => { } },
306
+    //      id2 = { 'score' => x, attrs => { } },
307
+    // }
308
+
309
+    include_spip('inc/recherche_to_array');
310
+
311
+    foreach ($tables as $table => $champs) {
312
+        # lock via memoization, si dispo
313
+        if (function_exists('cache_lock')) {
314
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
315
+        }
316
+
317
+        spip_timer('rech');
318
+
319
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
320
+        $to_array = charger_fonction('recherche_to_array', 'inc');
321
+        $results[$table] = $to_array(
322
+            $recherche,
323
+            array_merge($options, ['table' => $table, 'champs' => $champs])
324
+        );
325
+        ##var_dump($results[$table]);
326
+
327
+
328
+        spip_log(
329
+            "recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
330
+            'recherche'
331
+        );
332
+
333
+        if (isset($lock)) {
334
+            cache_unlock($lock);
335
+        }
336
+    }
337
+
338
+    return $results;
339 339
 }
340 340
 
341 341
 
342 342
 // Effectue une recherche sur toutes les tables de la base de donnees
343 343
 // https://code.spip.net/@remplace_en_base
344 344
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
345
-	include_spip('inc/modifier');
346
-
347
-	// options par defaut
348
-	$options = array_merge(
349
-		[
350
-		'preg_flags' => 'UimsS',
351
-		'toutmodifier' => false
352
-		],
353
-		$options
354
-	);
355
-	$options['champs'] = true;
356
-
357
-
358
-	if (!is_array($tables)) {
359
-		$tables = liste_des_champs();
360
-	}
361
-
362
-	$results = recherche_en_base($recherche, $tables, $options);
363
-
364
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
365
-
366
-	foreach ($results as $table => $r) {
367
-		$_id_table = id_table_objet($table);
368
-		foreach ($r as $id => $x) {
369
-			if (
370
-				$options['toutmodifier']
371
-				or autoriser('modifier', $table, $id)
372
-			) {
373
-				$modifs = [];
374
-				foreach ($x['champs'] as $key => $val) {
375
-					if ($key == $_id_table) {
376
-						continue;
377
-					}
378
-					$repl = preg_replace($preg, $remplace, $val);
379
-					if ($repl <> $val) {
380
-						$modifs[$key] = $repl;
381
-					}
382
-				}
383
-				if ($modifs) {
384
-					objet_modifier_champs(
385
-						$table,
386
-						$id,
387
-						[
388
-							'champs' => array_keys($modifs),
389
-						],
390
-						$modifs
391
-					);
392
-				}
393
-			}
394
-		}
395
-	}
345
+    include_spip('inc/modifier');
346
+
347
+    // options par defaut
348
+    $options = array_merge(
349
+        [
350
+        'preg_flags' => 'UimsS',
351
+        'toutmodifier' => false
352
+        ],
353
+        $options
354
+    );
355
+    $options['champs'] = true;
356
+
357
+
358
+    if (!is_array($tables)) {
359
+        $tables = liste_des_champs();
360
+    }
361
+
362
+    $results = recherche_en_base($recherche, $tables, $options);
363
+
364
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
365
+
366
+    foreach ($results as $table => $r) {
367
+        $_id_table = id_table_objet($table);
368
+        foreach ($r as $id => $x) {
369
+            if (
370
+                $options['toutmodifier']
371
+                or autoriser('modifier', $table, $id)
372
+            ) {
373
+                $modifs = [];
374
+                foreach ($x['champs'] as $key => $val) {
375
+                    if ($key == $_id_table) {
376
+                        continue;
377
+                    }
378
+                    $repl = preg_replace($preg, $remplace, $val);
379
+                    if ($repl <> $val) {
380
+                        $modifs[$key] = $repl;
381
+                    }
382
+                }
383
+                if ($modifs) {
384
+                    objet_modifier_champs(
385
+                        $table,
386
+                        $id,
387
+                        [
388
+                            'champs' => array_keys($modifs),
389
+                        ],
390
+                        $modifs
391
+                    );
392
+                }
393
+            }
394
+        }
395
+    }
396 396
 }
Please login to merge, or discard this patch.
ecrire/inc/svg.php 1 patch
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  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('IMG_SVG')) {
24
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
-	define('IMG_SVG', 128);
26
-	define('IMAGETYPE_SVG', 19);
24
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
+    define('IMG_SVG', 128);
26
+    define('IMAGETYPE_SVG', 19);
27 27
 }
28 28
 
29 29
 /**
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
  *   false si on a pas pu charger l'image
40 40
  */
41 41
 function svg_charger($fichier, $maxlen = null) {
42
-	if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
-		$image = explode(';', $fichier, 2);
44
-		$image = end($image);
45
-		if (strpos($image, 'base64,') === 0) {
46
-			$image = base64_decode(substr($image, 7));
47
-		}
48
-		if (strpos($image, '<svg') !== false) {
49
-			return $image;
50
-		}
51
-		// encodage inconnu ou autre format d'image ?
52
-		return false;
53
-	}
54
-	// c'est peut etre deja une image svg ?
55
-	if (strpos($fichier, '<svg') !== false) {
56
-		return $fichier;
57
-	}
58
-	if (!file_exists($fichier)) {
59
-		$fichier  = supprimer_timestamp($fichier);
60
-		if (!file_exists($fichier)) {
61
-			return false;
62
-		}
63
-	}
64
-	if (is_null($maxlen)) {
65
-		$image = file_get_contents($fichier);
66
-	}
67
-	else {
68
-		$image = file_get_contents($fichier, false, null, 0, $maxlen);
69
-	}
70
-	// est-ce bien une image svg ?
71
-	if (strpos($image, '<svg') !== false) {
72
-		return $image;
73
-	}
74
-	return false;
42
+    if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
+        $image = explode(';', $fichier, 2);
44
+        $image = end($image);
45
+        if (strpos($image, 'base64,') === 0) {
46
+            $image = base64_decode(substr($image, 7));
47
+        }
48
+        if (strpos($image, '<svg') !== false) {
49
+            return $image;
50
+        }
51
+        // encodage inconnu ou autre format d'image ?
52
+        return false;
53
+    }
54
+    // c'est peut etre deja une image svg ?
55
+    if (strpos($fichier, '<svg') !== false) {
56
+        return $fichier;
57
+    }
58
+    if (!file_exists($fichier)) {
59
+        $fichier  = supprimer_timestamp($fichier);
60
+        if (!file_exists($fichier)) {
61
+            return false;
62
+        }
63
+    }
64
+    if (is_null($maxlen)) {
65
+        $image = file_get_contents($fichier);
66
+    }
67
+    else {
68
+        $image = file_get_contents($fichier, false, null, 0, $maxlen);
69
+    }
70
+    // est-ce bien une image svg ?
71
+    if (strpos($image, '<svg') !== false) {
72
+        return $image;
73
+    }
74
+    return false;
75 75
 }
76 76
 
77 77
 /**
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
  * @return array|bool
81 81
  */
82 82
 function svg_lire_balise_svg($fichier) {
83
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
-		return false;
85
-	}
86
-
87
-	if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
-		$pe = stripos($debut_fichier, '>', $ps);
89
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
-
91
-		if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
-			if (!function_exists('extraire_attribut')) {
93
-				include_spip('inc/filtres');
94
-			}
95
-			$attributs = [];
96
-			foreach ($matches[1] as $att) {
97
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
98
-			}
99
-
100
-			return [$balise_svg, $attributs];
101
-		}
102
-	}
103
-
104
-	return false;
83
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
+        return false;
85
+    }
86
+
87
+    if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
+        $pe = stripos($debut_fichier, '>', $ps);
89
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
+
91
+        if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
+            if (!function_exists('extraire_attribut')) {
93
+                include_spip('inc/filtres');
94
+            }
95
+            $attributs = [];
96
+            foreach ($matches[1] as $att) {
97
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
98
+            }
99
+
100
+            return [$balise_svg, $attributs];
101
+        }
102
+    }
103
+
104
+    return false;
105 105
 }
106 106
 
107 107
 /**
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function svg_lire_attributs($img) {
113 113
 
114
-	if ($svg_infos = svg_lire_balise_svg($img)) {
115
-		list($balise_svg, $attributs) = $svg_infos;
116
-		return $attributs;
117
-	}
114
+    if ($svg_infos = svg_lire_balise_svg($img)) {
115
+        list($balise_svg, $attributs) = $svg_infos;
116
+        return $attributs;
117
+    }
118 118
 
119
-	return false;
119
+    return false;
120 120
 }
121 121
 
122 122
 /**
@@ -126,38 +126,38 @@  discard block
 block discarded – undo
126 126
  * @return bool|float|int
127 127
  */
128 128
 function svg_dimension_to_pixels($dimension, $precision = 2) {
129
-	if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
-		switch (strtolower($m[2])) {
131
-			case '%':
132
-				// on ne sait pas faire :(
133
-				return false;
134
-				break;
135
-			case 'em':
136
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
137
-				break;
138
-			case 'ex':
139
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
140
-				break;
141
-			case 'pc':
142
-				return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
-				break;
144
-			case 'cm':
145
-				return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
-				break;
147
-			case 'mm':
148
-				return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
-				break;
150
-			case 'in':
151
-				return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
-				break;
153
-			case 'px':
154
-			case 'pt':
155
-			default:
156
-				return $m[1];
157
-				break;
158
-		}
159
-	}
160
-	return false;
129
+    if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
+        switch (strtolower($m[2])) {
131
+            case '%':
132
+                // on ne sait pas faire :(
133
+                return false;
134
+                break;
135
+            case 'em':
136
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
137
+                break;
138
+            case 'ex':
139
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
140
+                break;
141
+            case 'pc':
142
+                return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
+                break;
144
+            case 'cm':
145
+                return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
+                break;
147
+            case 'mm':
148
+                return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
+                break;
150
+            case 'in':
151
+                return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
+                break;
153
+            case 'px':
154
+            case 'pt':
155
+            default:
156
+                return $m[1];
157
+                break;
158
+        }
159
+    }
160
+    return false;
161 161
 }
162 162
 
163 163
 /**
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
  * @return string
169 169
  */
170 170
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
171
-	$new_balise_svg = '<svg';
172
-	foreach ($attributs as $k => $v) {
173
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
-	}
175
-	$new_balise_svg .= '>';
176
-
177
-	$p = strpos($svg, $old_balise_svg);
178
-	$svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
-	return $svg;
171
+    $new_balise_svg = '<svg';
172
+    foreach ($attributs as $k => $v) {
173
+        $new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
+    }
175
+    $new_balise_svg .= '>';
176
+
177
+    $p = strpos($svg, $old_balise_svg);
178
+    $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
+    return $svg;
180 180
 }
181 181
 
182 182
 /**
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function svg_insert_shapes($svg, $shapes, $start = true) {
190 190
 
191
-	if ($start === false or $start === 'end') {
192
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
-	}
194
-	else {
195
-		$p = stripos($svg, '<svg');
196
-		$p = strpos($svg, '>', $p);
197
-		$svg = substr_replace($svg, $shapes, $p + 1, 0);
198
-	}
199
-	return $svg;
191
+    if ($start === false or $start === 'end') {
192
+        $svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
+    }
194
+    else {
195
+        $p = stripos($svg, '<svg');
196
+        $p = strpos($svg, '>', $p);
197
+        $svg = substr_replace($svg, $shapes, $p + 1, 0);
198
+    }
199
+    return $svg;
200 200
 }
201 201
 
202 202
 /**
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
  * @return string
210 210
  */
211 211
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
212
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
-	$g = "<g clip-path=\"url(#$id)\">";
216
-	$svg = svg_insert_shapes($svg, $clippath . $g);
217
-	$svg = svg_insert_shapes($svg, '</g>', false);
218
-	return $svg;
212
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
+    $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
+    $g = "<g clip-path=\"url(#$id)\">";
216
+    $svg = svg_insert_shapes($svg, $clippath . $g);
217
+    $svg = svg_insert_shapes($svg, '</g>', false);
218
+    return $svg;
219 219
 }
220 220
 
221 221
 /**
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
  * @return bool|string
227 227
  */
228 228
 function svg_redimensionner($img, $new_width, $new_height) {
229
-	if (
230
-		$svg = svg_charger($img)
231
-		and $svg_infos = svg_lire_balise_svg($svg)
232
-	) {
233
-		list($balise_svg, $attributs) = $svg_infos;
234
-		if (!isset($attributs['viewBox'])) {
235
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
-		}
237
-		$attributs['width'] = strval($new_width);
238
-		$attributs['height'] = strval($new_height);
239
-
240
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
-		return $svg;
242
-	}
243
-
244
-	return $img;
229
+    if (
230
+        $svg = svg_charger($img)
231
+        and $svg_infos = svg_lire_balise_svg($svg)
232
+    ) {
233
+        list($balise_svg, $attributs) = $svg_infos;
234
+        if (!isset($attributs['viewBox'])) {
235
+            $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
+        }
237
+        $attributs['width'] = strval($new_width);
238
+        $attributs['height'] = strval($new_height);
239
+
240
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
+        return $svg;
242
+    }
243
+
244
+    return $img;
245 245
 }
246 246
 
247 247
 /**
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
  * @return string
251 251
  */
252 252
 function svg_couleur_to_hexa($couleur) {
253
-	if (strpos($couleur, 'rgb(') === 0) {
254
-		$c = explode(',', substr($couleur, 4));
255
-		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
-	}
257
-	else {
258
-		$couleur = couleur_html_to_hex($couleur);
259
-	}
260
-	$couleur = '#' . ltrim($couleur, '#');
261
-	return $couleur;
253
+    if (strpos($couleur, 'rgb(') === 0) {
254
+        $c = explode(',', substr($couleur, 4));
255
+        $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
+    }
257
+    else {
258
+        $couleur = couleur_html_to_hex($couleur);
259
+    }
260
+    $couleur = '#' . ltrim($couleur, '#');
261
+    return $couleur;
262 262
 }
263 263
 
264 264
 /**
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
  * @return array
268 268
  */
269 269
 function svg_couleur_to_rgb($couleur) {
270
-	if (strpos($couleur, 'rgb(') === 0) {
271
-		$c = explode(',', substr($couleur, 4));
272
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
-	}
274
-	return _couleur_hex_to_dec($couleur);
270
+    if (strpos($couleur, 'rgb(') === 0) {
271
+        $c = explode(',', substr($couleur, 4));
272
+        return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
+    }
274
+    return _couleur_hex_to_dec($couleur);
275 275
 }
276 276
 
277 277
 
@@ -281,70 +281,70 @@  discard block
 block discarded – undo
281 281
  * @return array
282 282
  */
283 283
 function svg_getimagesize_from_attr($attributs) {
284
-	$width = 350; // default width
285
-	$height = 150; // default height
286
-
287
-	$viewBox = "0 0 $width $height";
288
-	if (isset($attributs['viewBox'])) {
289
-		$viewBox = $attributs['viewBox'];
290
-		$viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
-	}
292
-	// et on la convertit en px
293
-	$viewBox = explode(' ', $viewBox);
294
-	$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
-	if (!$viewBox[2]) {
296
-		$viewBox[2] = $width;
297
-	}
298
-	if (!$viewBox[3]) {
299
-		$viewBox[3] = $height;
300
-	}
301
-
302
-	$coeff = 1;
303
-	if (
304
-		isset($attributs['width'])
305
-		and $w = svg_dimension_to_pixels($attributs['width'])
306
-	) {
307
-		$width = $w;
308
-	}
309
-	else {
310
-		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311
-		$width = $viewBox[2];
312
-		if ($width < 1) {
313
-			$coeff = max($coeff, 1000);
314
-		}
315
-		elseif ($width < 10) {
316
-			$coeff = max($coeff, 100);
317
-		}
318
-		elseif ($width < 100) {
319
-			$coeff = max($coeff, 10);
320
-		}
321
-	}
322
-	if (
323
-		isset($attributs['height'])
324
-		and $h = svg_dimension_to_pixels($attributs['height'])
325
-	) {
326
-		$height = $h;
327
-	}
328
-	else {
329
-		$height = $viewBox[3];
330
-		if ($height < 1) {
331
-			$coeff = max($coeff, 1000);
332
-		}
333
-		elseif ($height < 10) {
334
-			$coeff = max($coeff, 100);
335
-		}
336
-		elseif ($height < 100) {
337
-			$coeff = max($coeff, 10);
338
-		}
339
-	}
340
-
341
-	// arrondir le width et height en pixel in fine
342
-	$width = round($coeff * $width);
343
-	$height = round($coeff * $height);
344
-
345
-	$viewBox = implode(' ', $viewBox);
346
-
347
-	return [$width, $height, $viewBox];
284
+    $width = 350; // default width
285
+    $height = 150; // default height
286
+
287
+    $viewBox = "0 0 $width $height";
288
+    if (isset($attributs['viewBox'])) {
289
+        $viewBox = $attributs['viewBox'];
290
+        $viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
+    }
292
+    // et on la convertit en px
293
+    $viewBox = explode(' ', $viewBox);
294
+    $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
+    if (!$viewBox[2]) {
296
+        $viewBox[2] = $width;
297
+    }
298
+    if (!$viewBox[3]) {
299
+        $viewBox[3] = $height;
300
+    }
301
+
302
+    $coeff = 1;
303
+    if (
304
+        isset($attributs['width'])
305
+        and $w = svg_dimension_to_pixels($attributs['width'])
306
+    ) {
307
+        $width = $w;
308
+    }
309
+    else {
310
+        // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311
+        $width = $viewBox[2];
312
+        if ($width < 1) {
313
+            $coeff = max($coeff, 1000);
314
+        }
315
+        elseif ($width < 10) {
316
+            $coeff = max($coeff, 100);
317
+        }
318
+        elseif ($width < 100) {
319
+            $coeff = max($coeff, 10);
320
+        }
321
+    }
322
+    if (
323
+        isset($attributs['height'])
324
+        and $h = svg_dimension_to_pixels($attributs['height'])
325
+    ) {
326
+        $height = $h;
327
+    }
328
+    else {
329
+        $height = $viewBox[3];
330
+        if ($height < 1) {
331
+            $coeff = max($coeff, 1000);
332
+        }
333
+        elseif ($height < 10) {
334
+            $coeff = max($coeff, 100);
335
+        }
336
+        elseif ($height < 100) {
337
+            $coeff = max($coeff, 10);
338
+        }
339
+    }
340
+
341
+    // arrondir le width et height en pixel in fine
342
+    $width = round($coeff * $width);
343
+    $height = round($coeff * $height);
344
+
345
+    $viewBox = implode(' ', $viewBox);
346
+
347
+    return [$width, $height, $viewBox];
348 348
 }
349 349
 
350 350
 /**
@@ -360,25 +360,25 @@  discard block
 block discarded – undo
360 360
  * @return string
361 361
  */
362 362
 function svg_force_viewBox_px($img, $force_width_and_height = false) {
363
-	if (
364
-		$svg = svg_charger($img)
365
-		and $svg_infos = svg_lire_balise_svg($svg)
366
-	) {
367
-		list($balise_svg, $attributs) = $svg_infos;
363
+    if (
364
+        $svg = svg_charger($img)
365
+        and $svg_infos = svg_lire_balise_svg($svg)
366
+    ) {
367
+        list($balise_svg, $attributs) = $svg_infos;
368 368
 
369
-		list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs);
369
+        list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs);
370 370
 
371
-		if ($force_width_and_height) {
372
-			$attributs['width'] = $width;
373
-			$attributs['height'] = $height;
374
-		}
371
+        if ($force_width_and_height) {
372
+            $attributs['width'] = $width;
373
+            $attributs['height'] = $height;
374
+        }
375 375
 
376
-		$attributs['viewBox'] = $viewBox;
376
+        $attributs['viewBox'] = $viewBox;
377 377
 
378
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
379
-		return $svg;
380
-	}
381
-	return $img;
378
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
379
+        return $svg;
380
+    }
381
+    return $img;
382 382
 }
383 383
 
384 384
 /**
@@ -387,12 +387,12 @@  discard block
 block discarded – undo
387 387
  * @return array|mixed
388 388
  */
389 389
 function svg_extract_couleurs($img) {
390
-	if ($svg = svg_charger($img)) {
391
-		if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) {
392
-			return $matches[0];
393
-		}
394
-	}
395
-	return [];
390
+    if ($svg = svg_charger($img)) {
391
+        if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) {
392
+            return $matches[0];
393
+        }
394
+    }
395
+    return [];
396 396
 }
397 397
 
398 398
 /**
@@ -403,58 +403,58 @@  discard block
 block discarded – undo
403 403
  * @return bool|string
404 404
  */
405 405
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
406
-	if (
407
-		$svg = svg_force_viewBox_px($img)
408
-		and $svg_infos = svg_lire_balise_svg($svg)
409
-	) {
410
-		list($balise_svg, $attributs) = $svg_infos;
411
-		$viewBox = explode(' ', $attributs['viewBox']);
412
-
413
-		$viewport_w = $new_width;
414
-		$viewport_h = $new_height;
415
-		$viewport_ox = $offset_width;
416
-		$viewport_oy = $offset_height;
417
-
418
-		// si on a un width/height qui rescale, il faut rescaler
419
-		if (
420
-			isset($attributs['width'])
421
-			and $w = svg_dimension_to_pixels($attributs['width'])
422
-			and isset($attributs['height'])
423
-			and $h = svg_dimension_to_pixels($attributs['height'])
424
-		) {
425
-			$xscale = $viewBox[2] / $w;
426
-			$viewport_w = round($viewport_w * $xscale, 2);
427
-			$viewport_ox = round($viewport_ox * $xscale, 2);
428
-			$yscale = $viewBox[3] / $h;
429
-			$viewport_h = round($viewport_h * $yscale, 2);
430
-			$viewport_oy = round($viewport_oy * $yscale, 2);
431
-		}
432
-
433
-		if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
434
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
435
-		}
436
-
437
-		// maintenant on redefinit la viewBox
438
-		$viewBox[0] += $viewport_ox;
439
-		$viewBox[1] += $viewport_oy;
440
-		$viewBox[2] = $viewport_w;
441
-		$viewBox[3] = $viewport_h;
442
-
443
-		$attributs['viewBox'] = implode(' ', $viewBox);
444
-		$attributs['width'] = strval($new_width);
445
-		$attributs['height'] = strval($new_height);
446
-
447
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
448
-
449
-		// ajouter un background
450
-		if ($background_color and $background_color !== 'transparent') {
451
-			$svg = svg_ajouter_background($svg, $background_color);
452
-		}
453
-
454
-		return $svg;
455
-	}
456
-
457
-	return $img;
406
+    if (
407
+        $svg = svg_force_viewBox_px($img)
408
+        and $svg_infos = svg_lire_balise_svg($svg)
409
+    ) {
410
+        list($balise_svg, $attributs) = $svg_infos;
411
+        $viewBox = explode(' ', $attributs['viewBox']);
412
+
413
+        $viewport_w = $new_width;
414
+        $viewport_h = $new_height;
415
+        $viewport_ox = $offset_width;
416
+        $viewport_oy = $offset_height;
417
+
418
+        // si on a un width/height qui rescale, il faut rescaler
419
+        if (
420
+            isset($attributs['width'])
421
+            and $w = svg_dimension_to_pixels($attributs['width'])
422
+            and isset($attributs['height'])
423
+            and $h = svg_dimension_to_pixels($attributs['height'])
424
+        ) {
425
+            $xscale = $viewBox[2] / $w;
426
+            $viewport_w = round($viewport_w * $xscale, 2);
427
+            $viewport_ox = round($viewport_ox * $xscale, 2);
428
+            $yscale = $viewBox[3] / $h;
429
+            $viewport_h = round($viewport_h * $yscale, 2);
430
+            $viewport_oy = round($viewport_oy * $yscale, 2);
431
+        }
432
+
433
+        if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
434
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
435
+        }
436
+
437
+        // maintenant on redefinit la viewBox
438
+        $viewBox[0] += $viewport_ox;
439
+        $viewBox[1] += $viewport_oy;
440
+        $viewBox[2] = $viewport_w;
441
+        $viewBox[3] = $viewport_h;
442
+
443
+        $attributs['viewBox'] = implode(' ', $viewBox);
444
+        $attributs['width'] = strval($new_width);
445
+        $attributs['height'] = strval($new_height);
446
+
447
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
448
+
449
+        // ajouter un background
450
+        if ($background_color and $background_color !== 'transparent') {
451
+            $svg = svg_ajouter_background($svg, $background_color);
452
+        }
453
+
454
+        return $svg;
455
+    }
456
+
457
+    return $img;
458 458
 }
459 459
 
460 460
 /**
@@ -464,26 +464,26 @@  discard block
 block discarded – undo
464 464
  * @return bool|string
465 465
  */
466 466
 function svg_ajouter_background($img, $background_color) {
467
-	if (
468
-		$svg = svg_charger($img)
469
-		and $svg_infos = svg_lire_balise_svg($svg)
470
-	) {
471
-		if ($background_color and $background_color !== 'transparent') {
472
-			list($balise_svg, $attributs) = $svg_infos;
473
-
474
-			$background_color = svg_couleur_to_hexa($background_color);
475
-			if (isset($attributs['viewBox'])) {
476
-				$viewBox = explode(' ', $attributs['viewBox']);
477
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
-			}
479
-			else {
480
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481
-			}
482
-			$svg = svg_insert_shapes($svg, $rect);
483
-		}
484
-		return $svg;
485
-	}
486
-	return $img;
467
+    if (
468
+        $svg = svg_charger($img)
469
+        and $svg_infos = svg_lire_balise_svg($svg)
470
+    ) {
471
+        if ($background_color and $background_color !== 'transparent') {
472
+            list($balise_svg, $attributs) = $svg_infos;
473
+
474
+            $background_color = svg_couleur_to_hexa($background_color);
475
+            if (isset($attributs['viewBox'])) {
476
+                $viewBox = explode(' ', $attributs['viewBox']);
477
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
+            }
479
+            else {
480
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481
+            }
482
+            $svg = svg_insert_shapes($svg, $rect);
483
+        }
484
+        return $svg;
485
+    }
486
+    return $img;
487 487
 }
488 488
 
489 489
 
@@ -494,26 +494,26 @@  discard block
 block discarded – undo
494 494
  * @return bool|string
495 495
  */
496 496
 function svg_ajouter_voile($img, $background_color, $opacity) {
497
-	if (
498
-		$svg = svg_charger($img)
499
-		and $svg_infos = svg_lire_balise_svg($svg)
500
-	) {
501
-		if ($background_color and $background_color !== 'transparent') {
502
-			list($balise_svg, $attributs) = $svg_infos;
503
-
504
-			$background_color = svg_couleur_to_hexa($background_color);
505
-			if (isset($attributs['viewBox'])) {
506
-				$viewBox = explode(' ', $attributs['viewBox']);
507
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
-			}
509
-			else {
510
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511
-			}
512
-			$svg = svg_insert_shapes($svg, $rect, false);
513
-		}
514
-		return $svg;
515
-	}
516
-	return $img;
497
+    if (
498
+        $svg = svg_charger($img)
499
+        and $svg_infos = svg_lire_balise_svg($svg)
500
+    ) {
501
+        if ($background_color and $background_color !== 'transparent') {
502
+            list($balise_svg, $attributs) = $svg_infos;
503
+
504
+            $background_color = svg_couleur_to_hexa($background_color);
505
+            if (isset($attributs['viewBox'])) {
506
+                $viewBox = explode(' ', $attributs['viewBox']);
507
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
+            }
509
+            else {
510
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511
+            }
512
+            $svg = svg_insert_shapes($svg, $rect, false);
513
+        }
514
+        return $svg;
515
+    }
516
+    return $img;
517 517
 }
518 518
 
519 519
 
@@ -524,27 +524,27 @@  discard block
 block discarded – undo
524 524
  * @return bool|string
525 525
  */
526 526
 function svg_transformer($img, $attributs) {
527
-	if (
528
-		$svg = svg_charger($img)
529
-		and $svg_infos = svg_lire_balise_svg($svg)
530
-	) {
531
-		if ($attributs) {
532
-			list($balise_svg, ) = $svg_infos;
533
-			$g = '<g';
534
-			foreach ($attributs as $k => $v) {
535
-				if (strlen($v)) {
536
-					$g .= " $k=\"" . attribut_html($v) . '"';
537
-				}
538
-			}
539
-			if (strlen($g) > 2) {
540
-				$g .= '>';
541
-				$svg = svg_insert_shapes($svg, $g);
542
-				$svg = svg_insert_shapes($svg, '</g>', false);
543
-			}
544
-		}
545
-		return $svg;
546
-	}
547
-	return $img;
527
+    if (
528
+        $svg = svg_charger($img)
529
+        and $svg_infos = svg_lire_balise_svg($svg)
530
+    ) {
531
+        if ($attributs) {
532
+            list($balise_svg, ) = $svg_infos;
533
+            $g = '<g';
534
+            foreach ($attributs as $k => $v) {
535
+                if (strlen($v)) {
536
+                    $g .= " $k=\"" . attribut_html($v) . '"';
537
+                }
538
+            }
539
+            if (strlen($g) > 2) {
540
+                $g .= '>';
541
+                $svg = svg_insert_shapes($svg, $g);
542
+                $svg = svg_insert_shapes($svg, '</g>', false);
543
+            }
544
+        }
545
+        return $svg;
546
+    }
547
+    return $img;
548 548
 }
549 549
 
550 550
 /**
@@ -555,21 +555,21 @@  discard block
 block discarded – undo
555 555
  * @return bool|string
556 556
  */
557 557
 function svg_apply_filter($img, $filter_def) {
558
-	if (
559
-		$svg = svg_charger($img)
560
-		and $svg_infos = svg_lire_balise_svg($svg)
561
-	) {
562
-		if ($filter_def) {
563
-			list($balise_svg, ) = $svg_infos;
564
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
565
-			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566
-			$g = "<g filter=\"url(#$filter_id)\">";
567
-			$svg = svg_insert_shapes($svg, $filter . $g);
568
-			$svg = svg_insert_shapes($svg, '</g>', false);
569
-		}
570
-		return $svg;
571
-	}
572
-	return $img;
558
+    if (
559
+        $svg = svg_charger($img)
560
+        and $svg_infos = svg_lire_balise_svg($svg)
561
+    ) {
562
+        if ($filter_def) {
563
+            list($balise_svg, ) = $svg_infos;
564
+            $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
565
+            $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566
+            $g = "<g filter=\"url(#$filter_id)\">";
567
+            $svg = svg_insert_shapes($svg, $filter . $g);
568
+            $svg = svg_insert_shapes($svg, '</g>', false);
569
+        }
570
+        return $svg;
571
+    }
572
+    return $img;
573 573
 }
574 574
 
575 575
 /**
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
  * @return string
580 580
  */
581 581
 function svg_filter_blur($img, $blur_width) {
582
-	$blur_width = intval($blur_width);
583
-	return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
582
+    $blur_width = intval($blur_width);
583
+    return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
584 584
 }
585 585
 
586 586
 /**
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
  * @return bool|string
591 591
  */
592 592
 function svg_filter_grayscale($img, $intensity) {
593
-	$value = round(1.0 - $intensity, 2);
594
-	//$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
595
-	$filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
596
-	return svg_apply_filter($img, $filter);
593
+    $value = round(1.0 - $intensity, 2);
594
+    //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
595
+    $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
596
+    return svg_apply_filter($img, $filter);
597 597
 }
598 598
 
599 599
 /**
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
  * @return bool|string
604 604
  */
605 605
 function svg_filter_sepia($img, $intensity) {
606
-	$filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
607
-	return svg_apply_filter($img, $filter);
606
+    $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
607
+    return svg_apply_filter($img, $filter);
608 608
 }
609 609
 
610 610
 /**
@@ -614,31 +614,31 @@  discard block
 block discarded – undo
614 614
  * @return bool|string
615 615
  */
616 616
 function svg_flip($img, $HorV) {
617
-	if (
618
-		$svg = svg_force_viewBox_px($img)
619
-		and $svg_infos = svg_lire_balise_svg($svg)
620
-	) {
621
-		list($balise_svg, $atts) = $svg_infos;
622
-		$viewBox = explode(' ', $atts['viewBox']);
623
-
624
-		if (!in_array($HorV, ['h', 'H'])) {
625
-			$transform = 'scale(-1,1)';
626
-
627
-			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628
-			$mx = -$x;
629
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
630
-		}
631
-		else {
632
-			$transform = 'scale(1,-1)';
633
-
634
-			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
635
-			$my = -$y;
636
-			$transform = "translate(0, $y) $transform translate(0, $my)";
637
-		}
638
-		$svg = svg_transformer($svg, ['transform' => $transform]);
639
-		return $svg;
640
-	}
641
-	return $img;
617
+    if (
618
+        $svg = svg_force_viewBox_px($img)
619
+        and $svg_infos = svg_lire_balise_svg($svg)
620
+    ) {
621
+        list($balise_svg, $atts) = $svg_infos;
622
+        $viewBox = explode(' ', $atts['viewBox']);
623
+
624
+        if (!in_array($HorV, ['h', 'H'])) {
625
+            $transform = 'scale(-1,1)';
626
+
627
+            $x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628
+            $mx = -$x;
629
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
630
+        }
631
+        else {
632
+            $transform = 'scale(1,-1)';
633
+
634
+            $y = intval($viewBox[1]) + intval($viewBox[3] / 2);
635
+            $my = -$y;
636
+            $transform = "translate(0, $y) $transform translate(0, $my)";
637
+        }
638
+        $svg = svg_transformer($svg, ['transform' => $transform]);
639
+        return $svg;
640
+    }
641
+    return $img;
642 642
 }
643 643
 
644 644
 /**
@@ -652,20 +652,20 @@  discard block
 block discarded – undo
652 652
  * @return bool|string
653 653
  */
654 654
 function svg_rotate($img, $angle, $center_x, $center_y) {
655
-	if (
656
-		$svg = svg_force_viewBox_px($img)
657
-		and $svg_infos = svg_lire_balise_svg($svg)
658
-	) {
659
-		list($balise_svg, $atts) = $svg_infos;
660
-		$viewBox = explode(' ', $atts['viewBox']);
661
-
662
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
663
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
664
-		$svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
665
-
666
-		return $svg;
667
-	}
668
-	return $img;
655
+    if (
656
+        $svg = svg_force_viewBox_px($img)
657
+        and $svg_infos = svg_lire_balise_svg($svg)
658
+    ) {
659
+        list($balise_svg, $atts) = $svg_infos;
660
+        $viewBox = explode(' ', $atts['viewBox']);
661
+
662
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
663
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
664
+        $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
665
+
666
+        return $svg;
667
+    }
668
+    return $img;
669 669
 }
670 670
 
671 671
 /**
@@ -677,41 +677,41 @@  discard block
 block discarded – undo
677 677
  * @return bool|mixed|string
678 678
  */
679 679
 function svg_filtrer_couleurs($img, $callback_filter) {
680
-	if (
681
-		$svg = svg_force_viewBox_px($img)
682
-		and $colors = svg_extract_couleurs($svg)
683
-	) {
684
-		$colors = array_unique($colors);
685
-
686
-		$short = [];
687
-		$long = [];
688
-		while (count($colors)) {
689
-			$c = array_shift($colors);
690
-			if (strlen($c) == 4) {
691
-				$short[] = $c;
692
-			}
693
-			else {
694
-				$long[] = $c;
695
-			}
696
-		}
697
-
698
-		$colors = array_merge($long, $short);
699
-		$new_colors = [];
700
-		$colors = array_flip($colors);
701
-		foreach ($colors as $c => $k) {
702
-			$colors[$c] = "@@@COLOR$$k$@@@";
703
-		}
704
-
705
-
706
-		foreach ($colors as $original => $replace) {
707
-			$new = svg_couleur_to_hexa($original);
708
-			$new_colors[$replace] = $callback_filter($new);
709
-		}
710
-
711
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
712
-		$svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
713
-
714
-		return $svg;
715
-	}
716
-	return $img;
680
+    if (
681
+        $svg = svg_force_viewBox_px($img)
682
+        and $colors = svg_extract_couleurs($svg)
683
+    ) {
684
+        $colors = array_unique($colors);
685
+
686
+        $short = [];
687
+        $long = [];
688
+        while (count($colors)) {
689
+            $c = array_shift($colors);
690
+            if (strlen($c) == 4) {
691
+                $short[] = $c;
692
+            }
693
+            else {
694
+                $long[] = $c;
695
+            }
696
+        }
697
+
698
+        $colors = array_merge($long, $short);
699
+        $new_colors = [];
700
+        $colors = array_flip($colors);
701
+        foreach ($colors as $c => $k) {
702
+            $colors[$c] = "@@@COLOR$$k$@@@";
703
+        }
704
+
705
+
706
+        foreach ($colors as $original => $replace) {
707
+            $new = svg_couleur_to_hexa($original);
708
+            $new_colors[$replace] = $callback_filter($new);
709
+        }
710
+
711
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
712
+        $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
713
+
714
+        return $svg;
715
+    }
716
+    return $img;
717 717
 }
Please login to merge, or discard this patch.