Completed
Push — master ( 3aac8c...691b26 )
by cam
01:02
created
ecrire/public/fonctions.php 1 patch
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 
25 25
 if (!defined('_ECRIRE_INC_VERSION')) {
26
-	return;
26
+    return;
27 27
 }
28 28
 
29 29
 
@@ -52,75 +52,75 @@  discard block
 block discarded – undo
52 52
  *     Introduction calculée
53 53
  **/
54 54
 function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) {
55
-	// Si un descriptif est envoye, on l'utilise directement
56
-	if (strlen($descriptif)) {
57
-		return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect);
58
-	}
59
-
60
-	// De preference ce qui est marque <intro>...</intro>
61
-	$intro = '';
62
-	$texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules
63
-	while ($fin = strpos($texte, '</intro>')) {
64
-		$zone = substr($texte, 0, $fin);
65
-		$texte = substr($texte, $fin + strlen('</intro>'));
66
-		if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') {
67
-			$zone = substr($zone, $deb + 7);
68
-		}
69
-		$intro .= $zone;
70
-	}
71
-
72
-	// [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut,
73
-	// qui inclus raccourcis et modeles
74
-	// un simple <articlexx> peut etre ensuite transforme en 1000 lignes ...
75
-	// par ailleurs le nettoyage des raccourcis ne tient pas compte
76
-	// des surcharges et enrichissement de propre
77
-	// couper doit se faire apres propre
78
-	//$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect);
79
-
80
-	// Cependant pour des questions de perfs on coupe quand meme, en prenant
81
-	// large et en se mefiant des tableaux #1323
82
-
83
-	if (strlen($intro)) {
84
-		$texte = $intro;
85
-	} else {
86
-		if (
87
-			strpos("\n" . $texte, "\n|") === false
88
-			and strlen($texte) > 2.5 * $longueur
89
-		) {
90
-			if (strpos($texte, '<multi') !== false) {
91
-				$texte = extraire_multi($texte);
92
-			}
93
-			$texte = couper($texte, 2 * $longueur);
94
-		}
95
-	}
96
-
97
-	// ne pas tenir compte des notes
98
-	if ($notes = charger_fonction('notes', 'inc', true)) {
99
-		$notes('', 'empiler');
100
-	}
101
-	// Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable
102
-	// dans l'introduction.
103
-	$texte = supprime_img($texte, '');
104
-	$texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect);
105
-
106
-	if ($notes) {
107
-		$notes('', 'depiler');
108
-	}
109
-
110
-	if (is_null($suite) and defined('_INTRODUCTION_SUITE')) {
111
-		$suite = _INTRODUCTION_SUITE;
112
-	}
113
-	$texte = couper($texte, $longueur, $suite);
114
-	// comme on a coupe il faut repasser la typo (on a perdu les insecables)
115
-	$texte = typo($texte, true, $connect, []);
116
-
117
-	// et reparagrapher si necessaire (coherence avec le cas descriptif)
118
-	// une introduction a tojours un <p>
119
-	if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes
120
-	$texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
121
-	}
122
-
123
-	return $texte;
55
+    // Si un descriptif est envoye, on l'utilise directement
56
+    if (strlen($descriptif)) {
57
+        return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect);
58
+    }
59
+
60
+    // De preference ce qui est marque <intro>...</intro>
61
+    $intro = '';
62
+    $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules
63
+    while ($fin = strpos($texte, '</intro>')) {
64
+        $zone = substr($texte, 0, $fin);
65
+        $texte = substr($texte, $fin + strlen('</intro>'));
66
+        if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') {
67
+            $zone = substr($zone, $deb + 7);
68
+        }
69
+        $intro .= $zone;
70
+    }
71
+
72
+    // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut,
73
+    // qui inclus raccourcis et modeles
74
+    // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ...
75
+    // par ailleurs le nettoyage des raccourcis ne tient pas compte
76
+    // des surcharges et enrichissement de propre
77
+    // couper doit se faire apres propre
78
+    //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect);
79
+
80
+    // Cependant pour des questions de perfs on coupe quand meme, en prenant
81
+    // large et en se mefiant des tableaux #1323
82
+
83
+    if (strlen($intro)) {
84
+        $texte = $intro;
85
+    } else {
86
+        if (
87
+            strpos("\n" . $texte, "\n|") === false
88
+            and strlen($texte) > 2.5 * $longueur
89
+        ) {
90
+            if (strpos($texte, '<multi') !== false) {
91
+                $texte = extraire_multi($texte);
92
+            }
93
+            $texte = couper($texte, 2 * $longueur);
94
+        }
95
+    }
96
+
97
+    // ne pas tenir compte des notes
98
+    if ($notes = charger_fonction('notes', 'inc', true)) {
99
+        $notes('', 'empiler');
100
+    }
101
+    // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable
102
+    // dans l'introduction.
103
+    $texte = supprime_img($texte, '');
104
+    $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect);
105
+
106
+    if ($notes) {
107
+        $notes('', 'depiler');
108
+    }
109
+
110
+    if (is_null($suite) and defined('_INTRODUCTION_SUITE')) {
111
+        $suite = _INTRODUCTION_SUITE;
112
+    }
113
+    $texte = couper($texte, $longueur, $suite);
114
+    // comme on a coupe il faut repasser la typo (on a perdu les insecables)
115
+    $texte = typo($texte, true, $connect, []);
116
+
117
+    // et reparagrapher si necessaire (coherence avec le cas descriptif)
118
+    // une introduction a tojours un <p>
119
+    if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes
120
+    $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
121
+    }
122
+
123
+    return $texte;
124 124
 }
125 125
 
126 126
 
@@ -155,73 +155,73 @@  discard block
 block discarded – undo
155 155
  *     Code HTML de la pagination
156 156
  **/
157 157
 function filtre_pagination_dist(
158
-	$total,
159
-	$nom,
160
-	$position,
161
-	$pas,
162
-	$liste = true,
163
-	$modele = '',
164
-	string $connect = '',
165
-	$env = []
158
+    $total,
159
+    $nom,
160
+    $position,
161
+    $pas,
162
+    $liste = true,
163
+    $modele = '',
164
+    string $connect = '',
165
+    $env = []
166 166
 ) {
167
-	static $ancres = [];
168
-	if ($pas < 1) {
169
-		return '';
170
-	}
171
-	$ancre = 'pagination' . $nom; // #pagination_articles
172
-	$debut = 'debut' . $nom; // 'debut_articles'
173
-
174
-	// n'afficher l'ancre qu'une fois
175
-	if (!isset($ancres[$ancre])) {
176
-		$bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>";
177
-	} else {
178
-		$bloc_ancre = '';
179
-	}
180
-	// liste = false : on ne veut que l'ancre
181
-	if (!$liste) {
182
-		return $ancres[$ancre];
183
-	}
184
-
185
-	$self = (empty($env['self']) ? self() : $env['self']);
186
-	$pagination = [
187
-		'debut' => $debut,
188
-		'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
189
-		'total' => $total,
190
-		'position' => intval($position),
191
-		'pas' => $pas,
192
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
193
-		'page_courante' => floor(intval($position) / $pas) + 1,
194
-		'ancre' => $ancre,
195
-		'bloc_ancre' => $bloc_ancre
196
-	];
197
-	if (is_array($env)) {
198
-		$pagination = array_merge($env, $pagination);
199
-	}
200
-
201
-	// Pas de pagination
202
-	if ($pagination['nombre_pages'] <= 1) {
203
-		return '';
204
-	}
205
-
206
-	if ($modele) {
207
-		$pagination['type_pagination'] = $modele;
208
-		if (trouver_fond('pagination_' . $modele, 'modeles')) {
209
-			$modele = '_' . $modele;
210
-		}
211
-		else {
212
-			$modele = '';
213
-		}
214
-	}
215
-
216
-	if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) {
217
-		define('_PAGINATION_NOMBRE_LIENS_MAX', 10);
218
-	}
219
-	if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) {
220
-		define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5);
221
-	}
222
-
223
-
224
-	return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect);
167
+    static $ancres = [];
168
+    if ($pas < 1) {
169
+        return '';
170
+    }
171
+    $ancre = 'pagination' . $nom; // #pagination_articles
172
+    $debut = 'debut' . $nom; // 'debut_articles'
173
+
174
+    // n'afficher l'ancre qu'une fois
175
+    if (!isset($ancres[$ancre])) {
176
+        $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>";
177
+    } else {
178
+        $bloc_ancre = '';
179
+    }
180
+    // liste = false : on ne veut que l'ancre
181
+    if (!$liste) {
182
+        return $ancres[$ancre];
183
+    }
184
+
185
+    $self = (empty($env['self']) ? self() : $env['self']);
186
+    $pagination = [
187
+        'debut' => $debut,
188
+        'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
189
+        'total' => $total,
190
+        'position' => intval($position),
191
+        'pas' => $pas,
192
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
193
+        'page_courante' => floor(intval($position) / $pas) + 1,
194
+        'ancre' => $ancre,
195
+        'bloc_ancre' => $bloc_ancre
196
+    ];
197
+    if (is_array($env)) {
198
+        $pagination = array_merge($env, $pagination);
199
+    }
200
+
201
+    // Pas de pagination
202
+    if ($pagination['nombre_pages'] <= 1) {
203
+        return '';
204
+    }
205
+
206
+    if ($modele) {
207
+        $pagination['type_pagination'] = $modele;
208
+        if (trouver_fond('pagination_' . $modele, 'modeles')) {
209
+            $modele = '_' . $modele;
210
+        }
211
+        else {
212
+            $modele = '';
213
+        }
214
+    }
215
+
216
+    if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) {
217
+        define('_PAGINATION_NOMBRE_LIENS_MAX', 10);
218
+    }
219
+    if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) {
220
+        define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5);
221
+    }
222
+
223
+
224
+    return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect);
225 225
 }
226 226
 
227 227
 
@@ -240,44 +240,44 @@  discard block
 block discarded – undo
240 240
  *     Liste (première page, dernière page).
241 241
  **/
242 242
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
243
-	if ($max <= 0 or $max >= $nombre) {
244
-		return [1, $nombre];
245
-	}
246
-	if ($max <= 1) {
247
-		return [$courante, $courante];
248
-	}
249
-
250
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
251
-	$derniere = min($nombre, $premiere + $max - 2);
252
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
253
-
254
-	return [$premiere, $derniere];
243
+    if ($max <= 0 or $max >= $nombre) {
244
+        return [1, $nombre];
245
+    }
246
+    if ($max <= 1) {
247
+        return [$courante, $courante];
248
+    }
249
+
250
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
251
+    $derniere = min($nombre, $premiere + $max - 2);
252
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
253
+
254
+    return [$premiere, $derniere];
255 255
 }
256 256
 
257 257
 function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) {
258
-	if ($numero_page === 'tous') {
259
-		return '&#8734;';
260
-	}
261
-	if ($numero_page === 'prev') {
262
-		return '&lt;';
263
-	}
264
-	if ($numero_page === 'next') {
265
-		return '&gt;';
266
-	}
267
-
268
-	switch ($type_pagination) {
269
-		case 'resultats':
270
-			return $rang_item + 1; // 1 11 21 31...
271
-		case 'naturel':
272
-			return $rang_item ?: 1; // 1 10 20 30...
273
-		case 'rang':
274
-			return $rang_item; // 0 10 20 30...
275
-
276
-		case 'page':
277
-		case 'prive':
278
-		default:
279
-			return $numero_page; // 1 2 3 4 5...
280
-	}
258
+    if ($numero_page === 'tous') {
259
+        return '&#8734;';
260
+    }
261
+    if ($numero_page === 'prev') {
262
+        return '&lt;';
263
+    }
264
+    if ($numero_page === 'next') {
265
+        return '&gt;';
266
+    }
267
+
268
+    switch ($type_pagination) {
269
+        case 'resultats':
270
+            return $rang_item + 1; // 1 11 21 31...
271
+        case 'naturel':
272
+            return $rang_item ?: 1; // 1 10 20 30...
273
+        case 'rang':
274
+            return $rang_item; // 0 10 20 30...
275
+
276
+        case 'page':
277
+        case 'prive':
278
+        default:
279
+            return $numero_page; // 1 2 3 4 5...
280
+    }
281 281
 }
282 282
 
283 283
 /**
@@ -290,15 +290,15 @@  discard block
 block discarded – undo
290 290
  **/
291 291
 function lister_objets_avec_logos($type) {
292 292
 
293
-	$objet = objet_type($type);
294
-	$ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet));
295
-	if ($ids) {
296
-		$ids = array_column($ids, 'id_objet');
297
-		return implode(',', $ids);
298
-	}
299
-	else {
300
-		return '0';
301
-	}
293
+    $objet = objet_type($type);
294
+    $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet));
295
+    if ($ids) {
296
+        $ids = array_column($ids, 'id_objet');
297
+        return implode(',', $ids);
298
+    }
299
+    else {
300
+        return '0';
301
+    }
302 302
 }
303 303
 
304 304
 
@@ -314,14 +314,14 @@  discard block
 block discarded – undo
314 314
  *     Code HTML des notes
315 315
  **/
316 316
 function calculer_notes() {
317
-	$r = '';
318
-	if ($notes = charger_fonction('notes', 'inc', true)) {
319
-		$r = $notes([]);
320
-		$notes('', 'depiler');
321
-		$notes('', 'empiler');
322
-	}
323
-
324
-	return $r;
317
+    $r = '';
318
+    if ($notes = charger_fonction('notes', 'inc', true)) {
319
+        $r = $notes([]);
320
+        $notes('', 'depiler');
321
+        $notes('', 'empiler');
322
+    }
323
+
324
+    return $r;
325 325
 }
326 326
 
327 327
 
@@ -338,10 +338,10 @@  discard block
 block discarded – undo
338 338
  * @return string
339 339
  */
340 340
 function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) {
341
-	$res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien);
342
-	$res = array_column($res, 'rang_lien', $objet_source);
341
+    $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien);
342
+    $res = array_column($res, 'rang_lien', $objet_source);
343 343
 
344
-	return ($res[$ids] ?? '');
344
+    return ($res[$ids] ?? '');
345 345
 }
346 346
 
347 347
 
@@ -358,19 +358,19 @@  discard block
 block discarded – undo
358 358
  * @private
359 359
  */
360 360
 function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) {
361
-	static $liens = [];
362
-	if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) {
363
-		include_spip('action/editer_liens');
364
-		// quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source
365
-		if ($objet_lien == $objet and $objet_lien !== $objet_source) {
366
-			$res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']);
367
-		} else {
368
-			$res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]);
369
-		}
370
-
371
-		$liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res;
372
-	}
373
-	return $liens["$objet_source-$objet-$id_objet-$objet_lien"];
361
+    static $liens = [];
362
+    if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) {
363
+        include_spip('action/editer_liens');
364
+        // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source
365
+        if ($objet_lien == $objet and $objet_lien !== $objet_source) {
366
+            $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']);
367
+        } else {
368
+            $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]);
369
+        }
370
+
371
+        $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res;
372
+    }
373
+    return $liens["$objet_source-$objet-$id_objet-$objet_lien"];
374 374
 }
375 375
 
376 376
 /**
@@ -384,24 +384,24 @@  discard block
 block discarded – undo
384 384
  * @return int|string
385 385
  */
386 386
 function calculer_rang_smart($titre, $objet_source, $id, $env) {
387
-	// Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien
388
-	// permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens
389
-	if (
390
-		isset($env['form']) and $env['form']
391
-		and isset($env['_objet_lien']) and $env['_objet_lien']
392
-		and (function_exists('lien_triables') or include_spip('action/editer_liens'))
393
-		and $r = objet_associable($env['_objet_lien'])
394
-		and [$p, $table_lien] = $r
395
-		and lien_triables($table_lien)
396
-		and isset($env['objet']) and $env['objet']
397
-		and isset($env['id_objet']) and $env['id_objet']
398
-		and $objet_source
399
-		and $id = intval($id)
400
-	) {
401
-		$rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']);
402
-		return ($rang ?: '');
403
-	}
404
-	return recuperer_numero($titre);
387
+    // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien
388
+    // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens
389
+    if (
390
+        isset($env['form']) and $env['form']
391
+        and isset($env['_objet_lien']) and $env['_objet_lien']
392
+        and (function_exists('lien_triables') or include_spip('action/editer_liens'))
393
+        and $r = objet_associable($env['_objet_lien'])
394
+        and [$p, $table_lien] = $r
395
+        and lien_triables($table_lien)
396
+        and isset($env['objet']) and $env['objet']
397
+        and isset($env['id_objet']) and $env['id_objet']
398
+        and $objet_source
399
+        and $id = intval($id)
400
+    ) {
401
+        $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']);
402
+        return ($rang ?: '');
403
+    }
404
+    return recuperer_numero($titre);
405 405
 }
406 406
 
407 407
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
  * @return string
418 418
  */
419 419
 function tri_protege_champ($t) {
420
-	return preg_replace(',[^\s\w.+\[\]],', '', $t);
420
+    return preg_replace(',[^\s\w.+\[\]],', '', $t);
421 421
 }
422 422
 
423 423
 /**
@@ -430,43 +430,43 @@  discard block
 block discarded – undo
430 430
  * @return string
431 431
  */
432 432
 function tri_champ_order($t, $from = null, $senstri = '') {
433
-	if (strncmp($t, 'multi ', 6) == 0) {
434
-		return 'multi';
435
-	}
436
-
437
-	$champ = $t;
438
-
439
-	$prefixe = '';
440
-	foreach (['num ', 'sinum '] as $p) {
441
-		if (strpos($t, $p) === 0) {
442
-			$champ = substr($t, strlen($p));
443
-			$prefixe = $p;
444
-		}
445
-	}
446
-
447
-	// enlever les autres espaces non evacues par tri_protege_champ
448
-	$champ = preg_replace(',\s,', '', $champ);
449
-
450
-	if (is_array($from)) {
451
-		$trouver_table = charger_fonction('trouver_table', 'base');
452
-		foreach ($from as $idt => $table_sql) {
453
-			if (
454
-				$desc = $trouver_table($table_sql)
455
-				and isset($desc['field'][$champ])
456
-			) {
457
-				$champ = "$idt.$champ";
458
-				break;
459
-			}
460
-		}
461
-	}
462
-	switch ($prefixe) {
463
-		case 'num ':
464
-			return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}";
465
-		case 'sinum ':
466
-			return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}";
467
-		default:
468
-			return $champ . $senstri;
469
-	}
433
+    if (strncmp($t, 'multi ', 6) == 0) {
434
+        return 'multi';
435
+    }
436
+
437
+    $champ = $t;
438
+
439
+    $prefixe = '';
440
+    foreach (['num ', 'sinum '] as $p) {
441
+        if (strpos($t, $p) === 0) {
442
+            $champ = substr($t, strlen($p));
443
+            $prefixe = $p;
444
+        }
445
+    }
446
+
447
+    // enlever les autres espaces non evacues par tri_protege_champ
448
+    $champ = preg_replace(',\s,', '', $champ);
449
+
450
+    if (is_array($from)) {
451
+        $trouver_table = charger_fonction('trouver_table', 'base');
452
+        foreach ($from as $idt => $table_sql) {
453
+            if (
454
+                $desc = $trouver_table($table_sql)
455
+                and isset($desc['field'][$champ])
456
+            ) {
457
+                $champ = "$idt.$champ";
458
+                break;
459
+            }
460
+        }
461
+    }
462
+    switch ($prefixe) {
463
+        case 'num ':
464
+            return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}";
465
+        case 'sinum ':
466
+            return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}";
467
+        default:
468
+            return $champ . $senstri;
469
+    }
470 470
 }
471 471
 
472 472
 /**
@@ -480,18 +480,18 @@  discard block
 block discarded – undo
480 480
  * @return string
481 481
  */
482 482
 function tri_champ_select($t) {
483
-	if (strncmp($t, 'multi ', 6) == 0) {
484
-		$t = substr($t, 6);
485
-		$t = preg_replace(',\s,', '', $t);
486
-		$t = sql_multi($t, $GLOBALS['spip_lang']);
487
-
488
-		return $t;
489
-	}
490
-	if (trim($t) == 'hasard') {
491
-		return 'rand() AS hasard';
492
-	}
493
-
494
-	return "''";
483
+    if (strncmp($t, 'multi ', 6) == 0) {
484
+        $t = substr($t, 6);
485
+        $t = preg_replace(',\s,', '', $t);
486
+        $t = sql_multi($t, $GLOBALS['spip_lang']);
487
+
488
+        return $t;
489
+    }
490
+    if (trim($t) == 'hasard') {
491
+        return 'rand() AS hasard';
492
+    }
493
+
494
+    return "''";
495 495
 }
496 496
 
497 497
 /**
@@ -503,16 +503,16 @@  discard block
 block discarded – undo
503 503
  * @return string
504 504
  */
505 505
 function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') {
506
-	if (!is_array($valeurs)) {
507
-		return '';
508
-	}
509
-	$f = sql_serveur('quote', $serveur, true);
510
-	if (!is_string($f) or !$f) {
511
-		return '';
512
-	}
513
-	$valeurs = implode(',', array_map($f, array_unique($valeurs)));
514
-
515
-	return $valeurs;
506
+    if (!is_array($valeurs)) {
507
+        return '';
508
+    }
509
+    $f = sql_serveur('quote', $serveur, true);
510
+    if (!is_string($f) or !$f) {
511
+        return '';
512
+    }
513
+    $valeurs = implode(',', array_map($f, array_unique($valeurs)));
514
+
515
+    return $valeurs;
516 516
 }
517 517
 
518 518
 /**
@@ -535,20 +535,20 @@  discard block
 block discarded – undo
535 535
  *     Valeur $defaut sinon.
536 536
  **/
537 537
 function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') {
538
-	// Si c'est un filtre d'image, on utilise image_filtrer()
539
-	// Attention : les 2 premiers arguments sont inversés dans ce cas
540
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
541
-		include_spip('inc/filtres_images_lib_mini');
542
-		$args[1] = $args[0];
543
-		$args[0] = $filtre;
544
-		return image_graver(image_filtrer($args));
545
-	}
546
-
547
-	$f = chercher_filtre($filtre);
548
-	if (!$f) {
549
-		return $defaut;
550
-	}
551
-	array_shift($args); // enlever $arg
552
-	array_shift($args); // enlever $filtre
553
-	return $f($arg, ...$args);
538
+    // Si c'est un filtre d'image, on utilise image_filtrer()
539
+    // Attention : les 2 premiers arguments sont inversés dans ce cas
540
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
541
+        include_spip('inc/filtres_images_lib_mini');
542
+        $args[1] = $args[0];
543
+        $args[0] = $filtre;
544
+        return image_graver(image_filtrer($args));
545
+    }
546
+
547
+    $f = chercher_filtre($filtre);
548
+    if (!$f) {
549
+        return $defaut;
550
+    }
551
+    array_shift($args); // enlever $arg
552
+    array_shift($args); // enlever $filtre
553
+    return $f($arg, ...$args);
554 554
 }
Please login to merge, or discard this patch.
ecrire/exec/puce_statut.php 1 patch
Indentation   +24 added lines, -24 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/presentation');
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @uses exec_puce_statut_args()
32 32
  **/
33 33
 function exec_puce_statut_dist(): void {
34
-	exec_puce_statut_args(_request('id'), _request('type'));
34
+    exec_puce_statut_args(_request('id'), _request('type'));
35 35
 }
36 36
 
37 37
 /**
@@ -50,26 +50,26 @@  discard block
 block discarded – undo
50 50
  *     Type d'objet
51 51
  **/
52 52
 function exec_puce_statut_args($id, $type): void {
53
-	$id = intval($id);
54
-	if (
55
-		$table_objet_sql = table_objet_sql($type)
56
-		and $d = lister_tables_objets_sql($table_objet_sql)
57
-		and isset($d['statut_textes_instituer'])
58
-		and $d['statut_textes_instituer']
59
-	) {
60
-		$prim = id_table_objet($type);
61
-		if (isset($d['field']['id_rubrique'])) {
62
-			$select = 'id_rubrique,statut';
63
-		} else {
64
-			$select = '0 as id_rubrique,statut';
65
-		}
66
-		$r = sql_fetsel($select, $table_objet_sql, "$prim=$id");
67
-		$statut = $r['statut'];
68
-		$id_rubrique = $r['id_rubrique'];
69
-	} else {
70
-		$id_rubrique = $id;
71
-		$statut = 'prop'; // arbitraire
72
-	}
73
-	$puce_statut = charger_fonction('puce_statut', 'inc');
74
-	ajax_retour($puce_statut($id, $statut, $id_rubrique, $type, true));
53
+    $id = intval($id);
54
+    if (
55
+        $table_objet_sql = table_objet_sql($type)
56
+        and $d = lister_tables_objets_sql($table_objet_sql)
57
+        and isset($d['statut_textes_instituer'])
58
+        and $d['statut_textes_instituer']
59
+    ) {
60
+        $prim = id_table_objet($type);
61
+        if (isset($d['field']['id_rubrique'])) {
62
+            $select = 'id_rubrique,statut';
63
+        } else {
64
+            $select = '0 as id_rubrique,statut';
65
+        }
66
+        $r = sql_fetsel($select, $table_objet_sql, "$prim=$id");
67
+        $statut = $r['statut'];
68
+        $id_rubrique = $r['id_rubrique'];
69
+    } else {
70
+        $id_rubrique = $id;
71
+        $statut = 'prop'; // arbitraire
72
+    }
73
+    $puce_statut = charger_fonction('puce_statut', 'inc');
74
+    ajax_retour($puce_statut($id, $statut, $id_rubrique, $type, true));
75 75
 }
Please login to merge, or discard this patch.
ecrire/inc/boutons.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -25,51 +25,51 @@  discard block
 block discarded – undo
25 25
  * privée ou dans un de ses sous menus
26 26
  */
27 27
 class Bouton {
28
-	/** @var string L'icone à mettre dans le bouton */
29
-	public $icone;
30
-
31
-	/** @var string Le nom de l'entrée d'i18n associé */
32
-	public $libelle;
33
-
34
-	/** @var null|string L'URL de la page (null => ?exec=nom) */
35
-	public $url = null;
36
-
37
-	/** @var null|string|array Arguments supplementaires de l'URL */
38
-	public $urlArg = null;
39
-
40
-	/** @var null|string URL du javascript */
41
-	public $url2 = null;
42
-
43
-	/** @var null|string Pour ouvrir dans une fenetre a part */
44
-	public $target = null;
45
-
46
-	/** @var array Sous-barre de boutons / onglets */
47
-	public $sousmenu = [];
48
-
49
-	/**
50
-	 * Définit un bouton
51
-	 *
52
-	 * @param string $icone
53
-	 *    L'icone à mettre dans le bouton
54
-	 * @param string $libelle
55
-	 *    Le nom de l'entrée i18n associé
56
-	 * @param null|string $url
57
-	 *    L'URL de la page
58
-	 * @param null|string|array $urlArg
59
-	 *    Arguments supplémentaires de l'URL
60
-	 * @param null|string $url2
61
-	 *    URL du javascript
62
-	 * @param null|mixed $target
63
-	 *    Pour ouvrir une fenêtre à part
64
-	 */
65
-	public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) {
66
-		$this->icone = $icone;
67
-		$this->libelle = $libelle;
68
-		$this->url = $url;
69
-		$this->urlArg = $urlArg;
70
-		$this->url2 = $url2;
71
-		$this->target = $target;
72
-	}
28
+    /** @var string L'icone à mettre dans le bouton */
29
+    public $icone;
30
+
31
+    /** @var string Le nom de l'entrée d'i18n associé */
32
+    public $libelle;
33
+
34
+    /** @var null|string L'URL de la page (null => ?exec=nom) */
35
+    public $url = null;
36
+
37
+    /** @var null|string|array Arguments supplementaires de l'URL */
38
+    public $urlArg = null;
39
+
40
+    /** @var null|string URL du javascript */
41
+    public $url2 = null;
42
+
43
+    /** @var null|string Pour ouvrir dans une fenetre a part */
44
+    public $target = null;
45
+
46
+    /** @var array Sous-barre de boutons / onglets */
47
+    public $sousmenu = [];
48
+
49
+    /**
50
+     * Définit un bouton
51
+     *
52
+     * @param string $icone
53
+     *    L'icone à mettre dans le bouton
54
+     * @param string $libelle
55
+     *    Le nom de l'entrée i18n associé
56
+     * @param null|string $url
57
+     *    L'URL de la page
58
+     * @param null|string|array $urlArg
59
+     *    Arguments supplémentaires de l'URL
60
+     * @param null|string $url2
61
+     *    URL du javascript
62
+     * @param null|mixed $target
63
+     *    Pour ouvrir une fenêtre à part
64
+     */
65
+    public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) {
66
+        $this->icone = $icone;
67
+        $this->libelle = $libelle;
68
+        $this->url = $url;
69
+        $this->urlArg = $urlArg;
70
+        $this->url2 = $url2;
71
+        $this->target = $target;
72
+    }
73 73
 }
74 74
 
75 75
 
@@ -86,35 +86,35 @@  discard block
 block discarded – undo
86 86
  */
87 87
 function definir_barre_onglets($script) {
88 88
 
89
-	$onglets = [];
90
-	$liste_onglets = [];
91
-
92
-	// ajouter les onglets issus des plugin via paquet.xml
93
-	if (function_exists('onglets_plugins')) {
94
-		$liste_onglets = onglets_plugins();
95
-	}
96
-
97
-
98
-	foreach ($liste_onglets as $id => $infos) {
99
-		if (
100
-			($parent = $infos['parent'])
101
-			&& $parent == $script
102
-			&& autoriser('onglet', "_$id")
103
-		) {
104
-			$onglets[$id] = new Bouton(
105
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
-				$infos['titre'],  // titre
107
-				(isset($infos['action']) and $infos['action'])
108
-					? generer_url_ecrire(
109
-						$infos['action'],
110
-						(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
111
-					)
112
-					: null
113
-			);
114
-		}
115
-	}
116
-
117
-	return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
89
+    $onglets = [];
90
+    $liste_onglets = [];
91
+
92
+    // ajouter les onglets issus des plugin via paquet.xml
93
+    if (function_exists('onglets_plugins')) {
94
+        $liste_onglets = onglets_plugins();
95
+    }
96
+
97
+
98
+    foreach ($liste_onglets as $id => $infos) {
99
+        if (
100
+            ($parent = $infos['parent'])
101
+            && $parent == $script
102
+            && autoriser('onglet', "_$id")
103
+        ) {
104
+            $onglets[$id] = new Bouton(
105
+                isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
106
+                $infos['titre'],  // titre
107
+                (isset($infos['action']) and $infos['action'])
108
+                    ? generer_url_ecrire(
109
+                        $infos['action'],
110
+                        (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
111
+                    )
112
+                    : null
113
+            );
114
+        }
115
+    }
116
+
117
+    return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
118 118
 }
119 119
 
120 120
 
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') {
136
-	include_spip('inc/presentation');
136
+    include_spip('inc/presentation');
137 137
 
138
-	$res = '';
138
+    $res = '';
139 139
 
140
-	foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
141
-		$url = $onglet->url ?: generer_url_ecrire($exec);
142
-		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
143
-	}
140
+    foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
141
+        $url = $onglet->url ?: generer_url_ecrire($exec);
142
+        $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
143
+    }
144 144
 
145
-	return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
145
+    return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
146 146
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 1 patch
Indentation   +732 added lines, -732 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 is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
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 is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
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,43 +474,43 @@  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
-
488
-		default:
489
-			$charset = load_charset($charset);
490
-
491
-			if (empty($CHARSET_REVERSE[$charset])) {
492
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
493
-			}
494
-
495
-			if (!isset($trans[$charset])) {
496
-				$trans[$charset] = [];
497
-				$t = &$trans[$charset];
498
-				for ($e = 128; $e < 255; $e++) {
499
-					$h = dechex($e);
500
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
501
-						$s = $CHARSET_REVERSE[$charset][$e];
502
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
503
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
504
-					} else {
505
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
506
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
507
-					}
508
-				}
509
-			}
510
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
511
-
512
-			return $texte;
513
-	}
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
+
488
+        default:
489
+            $charset = load_charset($charset);
490
+
491
+            if (empty($CHARSET_REVERSE[$charset])) {
492
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
493
+            }
494
+
495
+            if (!isset($trans[$charset])) {
496
+                $trans[$charset] = [];
497
+                $t = &$trans[$charset];
498
+                for ($e = 128; $e < 255; $e++) {
499
+                    $h = dechex($e);
500
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
501
+                        $s = $CHARSET_REVERSE[$charset][$e];
502
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
503
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
504
+                    } else {
505
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
506
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
507
+                    }
508
+                }
509
+            }
510
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
511
+
512
+            return $texte;
513
+    }
514 514
 }
515 515
 
516 516
 
@@ -528,40 +528,40 @@  discard block
 block discarded – undo
528 528
  *     Texte transformé dans le charset site
529 529
  **/
530 530
 function importer_charset($texte, $charset = 'AUTO') {
531
-	$s = null;
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 (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
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));
531
+    $s = null;
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 (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
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 < 1_114_112) {
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 < 1_114_112) {
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)));
904
+    // 1. Passer le charset et les &eacute en utf-8
905
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
906 906
 
907
-	return translitteration_rapide($texte, $charset, $complexe);
907
+    return translitteration_rapide($texte, $charset, $complexe);
908 908
 }
909 909
 
910 910
 /**
@@ -919,17 +919,17 @@  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');
922
+    $texte = translitteration($texte, 'AUTO', 'complexe');
923 923
 
924
-	if ($chiffres) {
925
-		$texte = preg_replace_callback(
926
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
-			fn($m) => translitteration_chiffree($m[0]),
928
-			$texte
929
-		);
930
-	}
924
+    if ($chiffres) {
925
+        $texte = preg_replace_callback(
926
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
+            fn($m) => translitteration_chiffree($m[0]),
928
+            $texte
929
+        );
930
+    }
931 931
 
932
-	return $texte;
932
+    return $texte;
933 933
 }
934 934
 
935 935
 /**
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
  * @return string
942 942
  */
943 943
 function translitteration_chiffree($car) {
944
-	return strtr($car, "'`?~.^+(-", '123456789');
944
+    return strtr($car, "'`?~.^+(-", '123456789');
945 945
 }
946 946
 
947 947
 
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
  *    true s'il a un BOM
955 955
  **/
956 956
 function bom_utf8($texte) {
957
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
957
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
958 958
 }
959 959
 
960 960
 /**
@@ -971,21 +971,21 @@  discard block
 block discarded – undo
971 971
  *     true si c'est le cas
972 972
  **/
973 973
 function is_utf8($string) {
974
-	return !strlen(
975
-		preg_replace(
976
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
977
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
978
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
979
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
980
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
981
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
982
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
983
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
984
-			. ',sS',
985
-			'',
986
-			$string
987
-		)
988
-	);
974
+    return !strlen(
975
+        preg_replace(
976
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
977
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
978
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
979
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
980
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
981
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
982
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
983
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
984
+            . ',sS',
985
+            '',
986
+            $string
987
+        )
988
+    );
989 989
 }
990 990
 
991 991
 /**
@@ -997,13 +997,13 @@  discard block
 block discarded – undo
997 997
  *     true si c'est le cas
998 998
  **/
999 999
 function is_ascii($string) {
1000
-	return !strlen(
1001
-		preg_replace(
1002
-			',[\x09\x0A\x0D\x20-\x7E],sS',
1003
-			'',
1004
-			$string
1005
-		)
1006
-	);
1000
+    return !strlen(
1001
+        preg_replace(
1002
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
1003
+            '',
1004
+            $string
1005
+        )
1006
+    );
1007 1007
 }
1008 1008
 
1009 1009
 /**
@@ -1022,53 +1022,53 @@  discard block
 block discarded – undo
1022 1022
  **/
1023 1023
 function transcoder_page($texte, $headers = '') {
1024 1024
 
1025
-	// Si tout est < 128 pas la peine d'aller plus loin
1026
-	if (is_ascii($texte)) {
1027
-		#spip_log('charset: ascii');
1028
-		return $texte;
1029
-	}
1030
-
1031
-	if (bom_utf8($texte)) {
1032
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
1033
-		$charset = 'utf-8';
1034
-		$texte = substr($texte, 3);
1035
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1036
-		// charset precise par le contenu (xml)
1037
-		$charset = trim(strtolower($regs[1]));
1038
-	} elseif (
1039
-		// charset precise par le contenu (html)
1040
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1041
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1042
-		and false === strpos($regs[2], '#')
1043
-		and $tmp = trim(strtolower($regs[2]))
1044
-	) {
1045
-		$charset = $tmp;
1046
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1047
-		// charset de la reponse http
1048
-		$charset = trim(strtolower($regs[1]));
1049
-	} else {
1050
-		$charset = '';
1051
-	}
1052
-
1053
-
1054
-	// normaliser les noms du shif-jis japonais
1055
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1056
-		$charset = 'shift-jis';
1057
-	}
1058
-
1059
-	if ($charset) {
1060
-		spip_log("charset: $charset");
1061
-	} else {
1062
-		// valeur par defaut
1063
-		if (is_utf8($texte)) {
1064
-			$charset = 'utf-8';
1065
-		} else {
1066
-			$charset = 'iso-8859-1';
1067
-		}
1068
-		spip_log("charset probable: $charset");
1069
-	}
1070
-
1071
-	return importer_charset($texte, $charset);
1025
+    // Si tout est < 128 pas la peine d'aller plus loin
1026
+    if (is_ascii($texte)) {
1027
+        #spip_log('charset: ascii');
1028
+        return $texte;
1029
+    }
1030
+
1031
+    if (bom_utf8($texte)) {
1032
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
1033
+        $charset = 'utf-8';
1034
+        $texte = substr($texte, 3);
1035
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1036
+        // charset precise par le contenu (xml)
1037
+        $charset = trim(strtolower($regs[1]));
1038
+    } elseif (
1039
+        // charset precise par le contenu (html)
1040
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1041
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1042
+        and false === strpos($regs[2], '#')
1043
+        and $tmp = trim(strtolower($regs[2]))
1044
+    ) {
1045
+        $charset = $tmp;
1046
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1047
+        // charset de la reponse http
1048
+        $charset = trim(strtolower($regs[1]));
1049
+    } else {
1050
+        $charset = '';
1051
+    }
1052
+
1053
+
1054
+    // normaliser les noms du shif-jis japonais
1055
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1056
+        $charset = 'shift-jis';
1057
+    }
1058
+
1059
+    if ($charset) {
1060
+        spip_log("charset: $charset");
1061
+    } else {
1062
+        // valeur par defaut
1063
+        if (is_utf8($texte)) {
1064
+            $charset = 'utf-8';
1065
+        } else {
1066
+            $charset = 'iso-8859-1';
1067
+        }
1068
+        spip_log("charset probable: $charset");
1069
+    }
1070
+
1071
+    return importer_charset($texte, $charset);
1072 1072
 }
1073 1073
 
1074 1074
 
@@ -1092,26 +1092,26 @@  discard block
 block discarded – undo
1092 1092
  *     Le texte coupé
1093 1093
  **/
1094 1094
 function spip_substr($c, $start = 0, $length = null) {
1095
-	// Si ce n'est pas utf-8, utiliser substr
1096
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1097
-		if ($length) {
1098
-			return substr($c, $start, $length);
1099
-		} else {
1100
-			return substr($c, $start);
1101
-		}
1102
-	}
1103
-
1104
-	// Si utf-8, voir si on dispose de mb_string
1105
-	if (init_mb_string()) {
1106
-		if ($length) {
1107
-			return mb_substr($c, $start, $length);
1108
-		} else {
1109
-			return mb_substr($c, $start);
1110
-		}
1111
-	}
1112
-
1113
-	// Version manuelle (cf. ci-dessous)
1114
-	return spip_substr_manuelle($c, $start, $length);
1095
+    // Si ce n'est pas utf-8, utiliser substr
1096
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1097
+        if ($length) {
1098
+            return substr($c, $start, $length);
1099
+        } else {
1100
+            return substr($c, $start);
1101
+        }
1102
+    }
1103
+
1104
+    // Si utf-8, voir si on dispose de mb_string
1105
+    if (init_mb_string()) {
1106
+        if ($length) {
1107
+            return mb_substr($c, $start, $length);
1108
+        } else {
1109
+            return mb_substr($c, $start);
1110
+        }
1111
+    }
1112
+
1113
+    // Version manuelle (cf. ci-dessous)
1114
+    return spip_substr_manuelle($c, $start, $length);
1115 1115
 }
1116 1116
 
1117 1117
 
@@ -1130,40 +1130,40 @@  discard block
 block discarded – undo
1130 1130
  **/
1131 1131
 function spip_substr_manuelle($c, $start, $length = null) {
1132 1132
 
1133
-	// Cas pathologique
1134
-	if ($length === 0) {
1135
-		return '';
1136
-	}
1137
-
1138
-	// S'il y a un demarrage, on se positionne
1139
-	if ($start > 0) {
1140
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1141
-	} elseif ($start < 0) {
1142
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1143
-	}
1144
-
1145
-	if (!$length) {
1146
-		return $c;
1147
-	}
1148
-
1149
-	if ($length > 0) {
1150
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1151
-		// (un caractere utf-8 prenant au maximum n bytes)
1152
-		$n = 0;
1153
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1154
-			;
1155
-		}
1156
-		$c = substr($c, 0, $n * $length);
1157
-		// puis, tant qu'on est trop long, on coupe...
1158
-		while (($l = spip_strlen($c)) > $length) {
1159
-			$c = substr($c, 0, $length - $l);
1160
-		}
1161
-
1162
-		return $c;
1163
-	}
1164
-
1165
-	// $length < 0
1166
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1133
+    // Cas pathologique
1134
+    if ($length === 0) {
1135
+        return '';
1136
+    }
1137
+
1138
+    // S'il y a un demarrage, on se positionne
1139
+    if ($start > 0) {
1140
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1141
+    } elseif ($start < 0) {
1142
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1143
+    }
1144
+
1145
+    if (!$length) {
1146
+        return $c;
1147
+    }
1148
+
1149
+    if ($length > 0) {
1150
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1151
+        // (un caractere utf-8 prenant au maximum n bytes)
1152
+        $n = 0;
1153
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1154
+            ;
1155
+        }
1156
+        $c = substr($c, 0, $n * $length);
1157
+        // puis, tant qu'on est trop long, on coupe...
1158
+        while (($l = spip_strlen($c)) > $length) {
1159
+            $c = substr($c, 0, $length - $l);
1160
+        }
1161
+
1162
+        return $c;
1163
+    }
1164
+
1165
+    // $length < 0
1166
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1167 1167
 }
1168 1168
 
1169 1169
 /**
@@ -1177,14 +1177,14 @@  discard block
 block discarded – undo
1177 1177
  *     La chaîne avec une majuscule sur le premier mot
1178 1178
  */
1179 1179
 function spip_ucfirst($c) {
1180
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1181
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1182
-		return ucfirst($c);
1183
-	}
1180
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1181
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1182
+        return ucfirst($c);
1183
+    }
1184 1184
 
1185
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1185
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1186 1186
 
1187
-	return $lettre1 . spip_substr($c, 1);
1187
+    return $lettre1 . spip_substr($c, 1);
1188 1188
 }
1189 1189
 
1190 1190
 /**
@@ -1198,12 +1198,12 @@  discard block
 block discarded – undo
1198 1198
  *     La chaîne en minuscules
1199 1199
  */
1200 1200
 function spip_strtolower($c) {
1201
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1202
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1203
-		return strtolower($c);
1204
-	}
1201
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1202
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1203
+        return strtolower($c);
1204
+    }
1205 1205
 
1206
-	return mb_strtolower($c);
1206
+    return mb_strtolower($c);
1207 1207
 }
1208 1208
 
1209 1209
 /**
@@ -1217,23 +1217,23 @@  discard block
 block discarded – undo
1217 1217
  *     Longueur de la chaîne
1218 1218
  */
1219 1219
 function spip_strlen($c) {
1220
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1221
-	$c = str_replace("\r\n", "\n", $c);
1222
-
1223
-	// Si ce n'est pas utf-8, utiliser strlen
1224
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1225
-		return strlen($c);
1226
-	}
1227
-
1228
-	// Sinon, utiliser mb_strlen() si disponible
1229
-	if (init_mb_string()) {
1230
-		return mb_strlen($c);
1231
-	}
1232
-
1233
-	// Methode manuelle : on supprime les bytes 10......,
1234
-	// on compte donc les ascii (0.......) et les demarrages
1235
-	// de caracteres utf-8 (11......)
1236
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1220
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1221
+    $c = str_replace("\r\n", "\n", $c);
1222
+
1223
+    // Si ce n'est pas utf-8, utiliser strlen
1224
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1225
+        return strlen($c);
1226
+    }
1227
+
1228
+    // Sinon, utiliser mb_strlen() si disponible
1229
+    if (init_mb_string()) {
1230
+        return mb_strlen($c);
1231
+    }
1232
+
1233
+    // Methode manuelle : on supprime les bytes 10......,
1234
+    // on compte donc les ascii (0.......) et les demarrages
1235
+    // de caracteres utf-8 (11......)
1236
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1237 1237
 }
1238 1238
 
1239 1239
 // Initialisation
@@ -1243,16 +1243,16 @@  discard block
 block discarded – undo
1243 1243
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1244 1244
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1245 1245
 if (
1246
-	!isset($GLOBALS['meta']['pcre_u'])
1247
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1246
+    !isset($GLOBALS['meta']['pcre_u'])
1247
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1248 1248
 ) {
1249
-	include_spip('inc/meta');
1250
-	ecrire_meta(
1251
-		'pcre_u',
1252
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1253
-			and test_pcre_unicode())
1254
-			? 'u' : ''
1255
-	);
1249
+    include_spip('inc/meta');
1250
+    ecrire_meta(
1251
+        'pcre_u',
1252
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1253
+            and test_pcre_unicode())
1254
+            ? 'u' : ''
1255
+    );
1256 1256
 }
1257 1257
 
1258 1258
 
@@ -1268,17 +1268,17 @@  discard block
 block discarded – undo
1268 1268
  *     en unicode : &#128169;
1269 1269
  */
1270 1270
 function utf8_noplanes($x) {
1271
-	$regexp_utf8_4bytes = '/(
1271
+    $regexp_utf8_4bytes = '/(
1272 1272
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1273 1273
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1274 1274
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1275 1275
 )/xS';
1276
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1277
-		foreach ($z[0] as $k) {
1278
-			$ku = utf_8_to_unicode($k);
1279
-			$x = str_replace($k, $ku, $x);
1280
-		}
1281
-	}
1282
-
1283
-	return $x;
1276
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1277
+        foreach ($z[0] as $k) {
1278
+            $ku = utf_8_to_unicode($k);
1279
+            $x = str_replace($k, $ku, $x);
1280
+        }
1281
+    }
1282
+
1283
+    return $x;
1284 1284
 }
Please login to merge, or discard this patch.
ecrire/inc/cvt_multietapes.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
  */
67 67
 
68 68
 if (!defined('_ECRIRE_INC_VERSION')) {
69
-	return;
69
+    return;
70 70
 }
71 71
 
72 72
 /**
@@ -77,46 +77,46 @@  discard block
 block discarded – undo
77 77
  * @return array|false
78 78
  */
79 79
 function cvtmulti_recuperer_post_precedents($form) {
80
-	include_spip('inc/filtres');
81
-	if (
82
-		$form
83
-		and $c = _request('cvtm_prev_post')
84
-		and $c = decoder_contexte_ajax($c, $form)
85
-	) {
86
-		#var_dump($c);
80
+    include_spip('inc/filtres');
81
+    if (
82
+        $form
83
+        and $c = _request('cvtm_prev_post')
84
+        and $c = decoder_contexte_ajax($c, $form)
85
+    ) {
86
+        #var_dump($c);
87 87
 
88
-		# reinjecter dans la bonne variable pour permettre de retrouver
89
-		# toutes les saisies dans un seul tableau
90
-		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91
-			$store = &$_POST;
92
-		} else {
93
-			$store = &$_GET;
94
-		}
88
+        # reinjecter dans la bonne variable pour permettre de retrouver
89
+        # toutes les saisies dans un seul tableau
90
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91
+            $store = &$_POST;
92
+        } else {
93
+            $store = &$_GET;
94
+        }
95 95
 
96
-		foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau !
97
-		if (!isset($store[$k])) {
98
-				$_REQUEST[$k] = $store[$k] = $v;
99
-		} // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie
100
-			elseif (
101
-				is_array($store[$k])
102
-				and is_array($v)
103
-				and $z = array_keys($v)
104
-				and !is_numeric(reset($z))
105
-				and $z = array_keys($store[$k])
106
-				and !is_numeric(reset($z))
107
-			) {
108
-				$_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]);
109
-			}
110
-		}
96
+        foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau !
97
+        if (!isset($store[$k])) {
98
+                $_REQUEST[$k] = $store[$k] = $v;
99
+        } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie
100
+            elseif (
101
+                is_array($store[$k])
102
+                and is_array($v)
103
+                and $z = array_keys($v)
104
+                and !is_numeric(reset($z))
105
+                and $z = array_keys($store[$k])
106
+                and !is_numeric(reset($z))
107
+            ) {
108
+                $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]);
109
+            }
110
+        }
111 111
 
112
-		// vider pour eviter un second appel a verifier_n
113
-		// en cas de double implementation (unipotence)
114
-		set_request('cvtm_prev_post');
112
+        // vider pour eviter un second appel a verifier_n
113
+        // en cas de double implementation (unipotence)
114
+        set_request('cvtm_prev_post');
115 115
 
116
-		return [$c['_etape'], $c['_etapes']];
117
-	}
116
+        return [$c['_etape'], $c['_etapes']];
117
+    }
118 118
 
119
-	return false;
119
+    return false;
120 120
 }
121 121
 
122 122
 /**
@@ -129,28 +129,28 @@  discard block
 block discarded – undo
129 129
  * @return array
130 130
  */
131 131
 function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) {
132
-	if (!isset($valeurs['_cvtm_prev_post'])) {
133
-		$post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']];
134
-		foreach (array_keys($valeurs) as $champ) {
135
-			if (substr($champ, 0, 1) !== '_') {
136
-				if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) {
137
-					if (($v = _request($champ)) !== null) {
138
-						$post[$champ] = $v;
139
-					}
140
-				}
141
-			}
142
-		}
143
-		include_spip('inc/filtres');
144
-		$c = encoder_contexte_ajax($post, $form);
145
-		if (!isset($valeurs['_hidden'])) {
146
-			$valeurs['_hidden'] = '';
147
-		}
148
-		$valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />";
149
-		// marquer comme fait, pour eviter double encodage (unipotence)
150
-		$valeurs['_cvtm_prev_post'] = true;
151
-	}
132
+    if (!isset($valeurs['_cvtm_prev_post'])) {
133
+        $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']];
134
+        foreach (array_keys($valeurs) as $champ) {
135
+            if (substr($champ, 0, 1) !== '_') {
136
+                if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) {
137
+                    if (($v = _request($champ)) !== null) {
138
+                        $post[$champ] = $v;
139
+                    }
140
+                }
141
+            }
142
+        }
143
+        include_spip('inc/filtres');
144
+        $c = encoder_contexte_ajax($post, $form);
145
+        if (!isset($valeurs['_hidden'])) {
146
+            $valeurs['_hidden'] = '';
147
+        }
148
+        $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />";
149
+        // marquer comme fait, pour eviter double encodage (unipotence)
150
+        $valeurs['_cvtm_prev_post'] = true;
151
+    }
152 152
 
153
-	return $valeurs;
153
+    return $valeurs;
154 154
 }
155 155
 
156 156
 
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
  * @return array
165 165
  */
166 166
 function cvtmulti_formulaire_charger($flux) {
167
-	if (
168
-		is_array($flux['data'])
169
-		and isset($flux['data']['_etapes'])
170
-	) {
171
-		$flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']);
172
-	}
167
+    if (
168
+        is_array($flux['data'])
169
+        and isset($flux['data']['_etapes'])
170
+    ) {
171
+        $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']);
172
+    }
173 173
 
174
-	return $flux;
174
+    return $flux;
175 175
 }
176 176
 
177 177
 /**
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
181 181
  * @return array
182 182
  */
183 183
 function cvtmulti_formulaire_charger_etapes($args, $valeurs) {
184
-	if (!isset($valeurs['_etape'])) {
185
-		$form = $args['form'];
186
-		$je_suis_poste = $args['je_suis_poste'];
187
-		$nb_etapes = $valeurs['_etapes'];
188
-		$etape = _request('_etape');
189
-		$etape = min(max($etape, 1), $nb_etapes);
190
-		set_request('_etape', $etape);
191
-		$valeurs['_etape'] = $etape;
184
+    if (!isset($valeurs['_etape'])) {
185
+        $form = $args['form'];
186
+        $je_suis_poste = $args['je_suis_poste'];
187
+        $nb_etapes = $valeurs['_etapes'];
188
+        $etape = _request('_etape');
189
+        $etape = min(max($etape, 1), $nb_etapes);
190
+        set_request('_etape', $etape);
191
+        $valeurs['_etape'] = $etape;
192 192
 
193
-		// sauver les posts de cette etape pour les avoir a la prochaine etape
194
-		$valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs);
195
-	}
196
-	return $valeurs;
193
+        // sauver les posts de cette etape pour les avoir a la prochaine etape
194
+        $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs);
195
+    }
196
+    return $valeurs;
197 197
 }
198 198
 
199 199
 
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
  * @return array
207 207
  */
208 208
 function cvtmulti_formulaire_verifier($flux) {
209
-	$flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']);
210
-	return $flux;
209
+    $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']);
210
+    return $flux;
211 211
 }
212 212
 
213 213
 /**
@@ -218,87 +218,87 @@  discard block
 block discarded – undo
218 218
  * @return array
219 219
  */
220 220
 function cvtmulti_formulaire_verifier_etapes($args, $erreurs) {
221
-	#var_dump('Pipe verifier');
221
+    #var_dump('Pipe verifier');
222 222
 
223
-	if (
224
-		$form = $args['form']
225
-		and ($e = cvtmulti_recuperer_post_precedents($form)) !== false
226
-	) {
227
-		// recuperer l'etape saisie et le nombre d'etapes total
228
-		[$etape, $etapes] = $e;
229
-		$etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape
223
+    if (
224
+        $form = $args['form']
225
+        and ($e = cvtmulti_recuperer_post_precedents($form)) !== false
226
+    ) {
227
+        // recuperer l'etape saisie et le nombre d'etapes total
228
+        [$etape, $etapes] = $e;
229
+        $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape
230 230
 
231
-		$args['etape_saisie'] = $etape;
232
-		$args['etapes'] = $etapes;
233
-		// lancer les verifs pour chaque etape deja saisie de 1 a $etape
234
-		$erreurs_etapes = [];
235
-		$derniere_etape_ok = 0;
236
-		$e = 0;
237
-		while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) {
238
-			$e++;
239
-			$erreurs_etapes[$e] = [];
240
-			if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) {
241
-				$erreurs_etapes[$e] = $verifier(...$args['args']);
242
-			} elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) {
243
-				$a = $args['args'];
244
-				array_unshift($a, $e);
245
-				$erreurs_etapes[$e] = $verifier(...$a);
246
-			}
247
-			// et on appelle un pipeline dedie aux etapes, plus easy
248
-			$args['etape'] = $e;
249
-			$args['etape_demandee'] = $etape_demandee;
250
-			$erreurs_etapes[$e] = pipeline(
251
-				'formulaire_verifier_etape',
252
-				[
253
-					'args' => $args,
254
-					'data' => $erreurs_etapes[$e]
255
-				]
256
-			);
231
+        $args['etape_saisie'] = $etape;
232
+        $args['etapes'] = $etapes;
233
+        // lancer les verifs pour chaque etape deja saisie de 1 a $etape
234
+        $erreurs_etapes = [];
235
+        $derniere_etape_ok = 0;
236
+        $e = 0;
237
+        while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) {
238
+            $e++;
239
+            $erreurs_etapes[$e] = [];
240
+            if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) {
241
+                $erreurs_etapes[$e] = $verifier(...$args['args']);
242
+            } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) {
243
+                $a = $args['args'];
244
+                array_unshift($a, $e);
245
+                $erreurs_etapes[$e] = $verifier(...$a);
246
+            }
247
+            // et on appelle un pipeline dedie aux etapes, plus easy
248
+            $args['etape'] = $e;
249
+            $args['etape_demandee'] = $etape_demandee;
250
+            $erreurs_etapes[$e] = pipeline(
251
+                'formulaire_verifier_etape',
252
+                [
253
+                    'args' => $args,
254
+                    'data' => $erreurs_etapes[$e]
255
+                ]
256
+            );
257 257
 
258
-			if ($derniere_etape_ok == $e - 1 and !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) {
259
-				$derniere_etape_ok = $e;
260
-			}
261
-			// possibilite de poster dans _retour_etape_x ou aller_a_etape
262
-			if (!is_null(_request("_retour_etape_$e"))) {
263
-				$etape_demandee = $e;
264
-			}
265
-			// Il se peut que les verifications ait décidé de faire sauter des étapes
266
-			if ($aller_a_etape = intval(_request('aller_a_etape'))) {
267
-				$etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape
268
-			}
269
-		}
258
+            if ($derniere_etape_ok == $e - 1 and !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) {
259
+                $derniere_etape_ok = $e;
260
+            }
261
+            // possibilite de poster dans _retour_etape_x ou aller_a_etape
262
+            if (!is_null(_request("_retour_etape_$e"))) {
263
+                $etape_demandee = $e;
264
+            }
265
+            // Il se peut que les verifications ait décidé de faire sauter des étapes
266
+            if ($aller_a_etape = intval(_request('aller_a_etape'))) {
267
+                $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape
268
+            }
269
+        }
270 270
 
271 271
 
272
-		// si la derniere etape OK etait la derniere
273
-		// on renvoie le flux inchange et ca declenche traiter
274
-		if (
275
-			$derniere_etape_ok == $etapes
276
-			and (!$etape_demandee or $etape_demandee >= $etapes)
277
-		) {
278
-			return $erreurs;
279
-		} else {
280
-			$etape = $derniere_etape_ok + 1;
281
-			if ($etape_demandee > 0 and $etape_demandee < $etape) {
282
-				$etape = $etape_demandee;
283
-			}
284
-			$etape = min($etape, $etapes);
285
-			#var_dump("prochaine etape $etape");
286
-			// retourner les erreurs de l'etape ciblee
287
-			$erreurs = $erreurs_etapes[$etape] ?? [];
288
-			// Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur !
289
-			if ($erreurs) {
290
-				if (!isset($erreurs['message_erreur'])) {
291
-					$erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie');
292
-				}
293
-			} else {
294
-				$erreurs['message_erreur'] = '';
295
-			}
296
-			$erreurs['_etapes'] = "etape suivante $etape";
297
-			set_request('_etape', $etape);
298
-		}
299
-	}
272
+        // si la derniere etape OK etait la derniere
273
+        // on renvoie le flux inchange et ca declenche traiter
274
+        if (
275
+            $derniere_etape_ok == $etapes
276
+            and (!$etape_demandee or $etape_demandee >= $etapes)
277
+        ) {
278
+            return $erreurs;
279
+        } else {
280
+            $etape = $derniere_etape_ok + 1;
281
+            if ($etape_demandee > 0 and $etape_demandee < $etape) {
282
+                $etape = $etape_demandee;
283
+            }
284
+            $etape = min($etape, $etapes);
285
+            #var_dump("prochaine etape $etape");
286
+            // retourner les erreurs de l'etape ciblee
287
+            $erreurs = $erreurs_etapes[$etape] ?? [];
288
+            // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur !
289
+            if ($erreurs) {
290
+                if (!isset($erreurs['message_erreur'])) {
291
+                    $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie');
292
+                }
293
+            } else {
294
+                $erreurs['message_erreur'] = '';
295
+            }
296
+            $erreurs['_etapes'] = "etape suivante $etape";
297
+            set_request('_etape', $etape);
298
+        }
299
+    }
300 300
 
301
-	return $erreurs;
301
+    return $erreurs;
302 302
 }
303 303
 
304 304
 /**
@@ -310,17 +310,17 @@  discard block
 block discarded – undo
310 310
  * @return array
311 311
  */
312 312
 function cvtmulti_styliser($flux) {
313
-	if (
314
-		strncmp($flux['args']['fond'], 'formulaires/', 12) == 0
315
-		and isset($flux['args']['contexte']['_etapes'])
316
-		and isset($flux['args']['contexte']['_etape'])
317
-		and ($e = $flux['args']['contexte']['_etape']) > 1
318
-		and $ext = $flux['args']['ext']
319
-		and $f = $flux['data']
320
-		and file_exists($f . "_$e.$ext")
321
-	) {
322
-		$flux['data'] = $f . "_$e";
323
-	}
313
+    if (
314
+        strncmp($flux['args']['fond'], 'formulaires/', 12) == 0
315
+        and isset($flux['args']['contexte']['_etapes'])
316
+        and isset($flux['args']['contexte']['_etape'])
317
+        and ($e = $flux['args']['contexte']['_etape']) > 1
318
+        and $ext = $flux['args']['ext']
319
+        and $f = $flux['data']
320
+        and file_exists($f . "_$e.$ext")
321
+    ) {
322
+        $flux['data'] = $f . "_$e";
323
+    }
324 324
 
325
-	return $flux;
325
+    return $flux;
326 326
 }
Please login to merge, or discard this patch.
ecrire/inc/actions.php 1 patch
Indentation   +26 added lines, -26 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,9 +43,9 @@  discard block
 block discarded – undo
43 43
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
44 44
  */
45 45
 function generer_action_auteur($action, $arg = '', $redirect = '', $mode = false, $att = '', $public = false) {
46
-	$securiser_action = charger_fonction('securiser_action', 'inc');
46
+    $securiser_action = charger_fonction('securiser_action', 'inc');
47 47
 
48
-	return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
48
+    return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
49 49
 }
50 50
 
51 51
 /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
  *     Code HTML du formulaire
79 79
  */
80 80
 function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) {
81
-	$r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
81
+    $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
82 82
 
83
-	return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
83
+    return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
84 84
 }
85 85
 
86 86
 /**
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
106 106
  */
107 107
 function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') {
108
-	$r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
108
+    $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
109 109
 
110
-	return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
110
+    return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
111 111
 }
112 112
 
113 113
 
@@ -124,26 +124,26 @@  discard block
 block discarded – undo
124 124
  *   passer "text/html" comme $content_type
125 125
  */
126 126
 function ajax_retour($corps, $content_type = null): void {
127
-	$xml = false;
128
-	if (is_null($content_type) or $content_type === true) {
129
-		$xml = true;
130
-		$content_type = 'text/html';
131
-	} elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) {
132
-		$content_type = 'text/html';
133
-	}
127
+    $xml = false;
128
+    if (is_null($content_type) or $content_type === true) {
129
+        $xml = true;
130
+        $content_type = 'text/html';
131
+    } elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) {
132
+        $content_type = 'text/html';
133
+    }
134 134
 
135
-	$e = '';
136
-	if (
137
-		isset($_COOKIE['spip_admin'])
138
-		and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps']))
139
-	) {
140
-		$e = erreur_squelette();
141
-	}
135
+    $e = '';
136
+    if (
137
+        isset($_COOKIE['spip_admin'])
138
+        and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps']))
139
+    ) {
140
+        $e = erreur_squelette();
141
+    }
142 142
 
143
-	$c = $GLOBALS['meta']['charset'];
144
-	header('Content-Type: ' . $content_type . '; charset=' . $c);
145
-	$debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
146
-	$fin = '';
143
+    $c = $GLOBALS['meta']['charset'];
144
+    header('Content-Type: ' . $content_type . '; charset=' . $c);
145
+    $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
146
+    $fin = '';
147 147
 
148
-	echo $debut, $corps, $fin, $e;
148
+    echo $debut, $corps, $fin, $e;
149 149
 }
Please login to merge, or discard this patch.
ecrire/inc/drapeau_edition.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @package SPIP\Core\Drapeaux\Edition
31 31
  **/
32 32
 if (!defined('_ECRIRE_INC_VERSION')) {
33
-	return;
33
+    return;
34 34
 }
35 35
 
36 36
 
@@ -45,46 +45,46 @@  discard block
 block discarded – undo
45 45
  *     `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()`
46 46
  **/
47 47
 function lire_tableau_edition() {
48
-	$edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
49
-	if (!$edition) {
50
-		return [];
51
-	}
52
-	$changed = false;
48
+    $edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
49
+    if (!$edition) {
50
+        return [];
51
+    }
52
+    $changed = false;
53 53
 
54
-	$bon_pour_le_service = time() - 3600;
55
-	// parcourir le tableau et virer les vieux
56
-	foreach ($edition as $objet => $data) {
57
-		if (!is_array($data)) {
58
-			unset($edition[$objet]);
59
-		} // vieille version
60
-		else {
61
-			foreach ($data as $id => $tab) {
62
-				if (!is_array($tab)) {
63
-					unset($edition[$objet][$tab]);
64
-				} // vieille version
65
-				else {
66
-					foreach ($tab as $n => $duo) {
67
-						if (current($duo) < $bon_pour_le_service) {
68
-							unset($edition[$objet][$id][$n]);
69
-							$changed = true;
70
-						}
71
-					}
72
-				}
73
-				if (!$edition[$objet][$id]) {
74
-					unset($edition[$objet][$id]);
75
-				}
76
-			}
77
-		}
78
-		if (!$edition[$objet]) {
79
-			unset($edition[$objet]);
80
-		}
81
-	}
54
+    $bon_pour_le_service = time() - 3600;
55
+    // parcourir le tableau et virer les vieux
56
+    foreach ($edition as $objet => $data) {
57
+        if (!is_array($data)) {
58
+            unset($edition[$objet]);
59
+        } // vieille version
60
+        else {
61
+            foreach ($data as $id => $tab) {
62
+                if (!is_array($tab)) {
63
+                    unset($edition[$objet][$tab]);
64
+                } // vieille version
65
+                else {
66
+                    foreach ($tab as $n => $duo) {
67
+                        if (current($duo) < $bon_pour_le_service) {
68
+                            unset($edition[$objet][$id][$n]);
69
+                            $changed = true;
70
+                        }
71
+                    }
72
+                }
73
+                if (!$edition[$objet][$id]) {
74
+                    unset($edition[$objet][$id]);
75
+                }
76
+            }
77
+        }
78
+        if (!$edition[$objet]) {
79
+            unset($edition[$objet]);
80
+        }
81
+    }
82 82
 
83
-	if ($changed) {
84
-		ecrire_tableau_edition($edition);
85
-	}
83
+    if ($changed) {
84
+        ecrire_tableau_edition($edition);
85
+    }
86 86
 
87
-	return $edition;
87
+    return $edition;
88 88
 }
89 89
 
90 90
 /**
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
  *     `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()`
98 98
  **/
99 99
 function ecrire_tableau_edition($edition) {
100
-	ecrire_meta('drapeau_edition', serialize($edition));
100
+    ecrire_meta('drapeau_edition', serialize($edition));
101 101
 }
102 102
 
103 103
 /**
@@ -117,24 +117,24 @@  discard block
 block discarded – undo
117 117
  *     Type d'objet édité
118 118
  */
119 119
 function signale_edition($id, $auteur, $type = 'article') {
120
-	include_spip('base/objets');
121
-	include_spip('inc/filtres');
122
-	if (objet_info($type, 'editable') !== 'oui') {
123
-		return;
124
-	}
120
+    include_spip('base/objets');
121
+    include_spip('inc/filtres');
122
+    if (objet_info($type, 'editable') !== 'oui') {
123
+        return;
124
+    }
125 125
 
126
-	$edition = lire_tableau_edition();
127
-	if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur']) {
128
-		$nom = $auteur['nom'];
129
-	} else {
130
-		$nom = $id_a = $GLOBALS['ip'];
131
-	}
126
+    $edition = lire_tableau_edition();
127
+    if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur']) {
128
+        $nom = $auteur['nom'];
129
+    } else {
130
+        $nom = $id_a = $GLOBALS['ip'];
131
+    }
132 132
 
133
-	if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) {
134
-		$edition[$type][$id] = [];
135
-	}
136
-	$edition[$type][$id][$id_a][$nom] = time();
137
-	ecrire_tableau_edition($edition);
133
+    if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) {
134
+        $edition[$type][$id] = [];
135
+    }
136
+    $edition[$type][$id][$id_a][$nom] = time();
137
+    ecrire_tableau_edition($edition);
138 138
 }
139 139
 
140 140
 /**
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
  */
152 152
 function qui_edite($id, $type = 'article') {
153 153
 
154
-	$edition = lire_tableau_edition();
154
+    $edition = lire_tableau_edition();
155 155
 
156
-	return empty($edition[$type][$id]) ? [] : $edition[$type][$id];
156
+    return empty($edition[$type][$id]) ? [] : $edition[$type][$id];
157 157
 }
158 158
 
159 159
 /**
@@ -167,23 +167,23 @@  discard block
 block discarded – undo
167 167
  *     Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]`
168 168
  */
169 169
 function mention_qui_edite($id, $type = 'article'): array {
170
-	$modif = qui_edite($id, $type);
171
-	unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
170
+    $modif = qui_edite($id, $type);
171
+    unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
172 172
 
173
-	if ($modif) {
174
-		$quand = 0;
175
-		foreach ($modif as $duo) {
176
-			$auteurs[] = typo(key($duo));
177
-			$quand = max($quand, current($duo));
178
-		}
173
+    if ($modif) {
174
+        $quand = 0;
175
+        foreach ($modif as $duo) {
176
+            $auteurs[] = typo(key($duo));
177
+            $quand = max($quand, current($duo));
178
+        }
179 179
 
180
-		// format lie a la chaine de langue 'avis_article_modifie'
181
-		return [
182
-			'nom_auteur_modif' => join(' | ', $auteurs),
183
-			'date_diff' => ceil((time() - $quand) / 60)
184
-		];
185
-	}
186
-	return [];
180
+        // format lie a la chaine de langue 'avis_article_modifie'
181
+        return [
182
+            'nom_auteur_modif' => join(' | ', $auteurs),
183
+            'date_diff' => ceil((time() - $quand) / 60)
184
+        ];
185
+    }
186
+    return [];
187 187
 }
188 188
 
189 189
 /**
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
  *     Liste de tableaux `['objet' => x, 'id_objet' => n]`
198 198
  */
199 199
 function liste_drapeau_edition($id_auteur) {
200
-	$edition = lire_tableau_edition();
201
-	$objets_ouverts = [];
200
+    $edition = lire_tableau_edition();
201
+    $objets_ouverts = [];
202 202
 
203
-	foreach ($edition as $objet => $data) {
204
-		foreach ($data as $id => $auteurs) {
205
-			if (
206
-				isset($auteurs[$id_auteur])
207
-				and is_array($auteurs[$id_auteur]) // precaution
208
-				and (array_pop($auteurs[$id_auteur]) > time() - 3600)
209
-			) {
210
-				$objets_ouverts[] = [
211
-					'objet' => $objet,
212
-					'id_objet' => $id,
213
-				];
214
-			}
215
-		}
216
-	}
203
+    foreach ($edition as $objet => $data) {
204
+        foreach ($data as $id => $auteurs) {
205
+            if (
206
+                isset($auteurs[$id_auteur])
207
+                and is_array($auteurs[$id_auteur]) // precaution
208
+                and (array_pop($auteurs[$id_auteur]) > time() - 3600)
209
+            ) {
210
+                $objets_ouverts[] = [
211
+                    'objet' => $objet,
212
+                    'id_objet' => $id,
213
+                ];
214
+            }
215
+        }
216
+    }
217 217
 
218
-	return $objets_ouverts;
218
+    return $objets_ouverts;
219 219
 }
220 220
 
221 221
 /**
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
  * @return void
229 229
  */
230 230
 function debloquer_tous($id_auteur) {
231
-	$edition = lire_tableau_edition();
232
-	foreach ($edition as $objet => $data) {
233
-		foreach ($data as $id => $auteurs) {
234
-			if (isset($auteurs[$id_auteur])) {
235
-				unset($edition[$objet][$id][$id_auteur]);
236
-				ecrire_tableau_edition($edition);
237
-			}
238
-		}
239
-	}
231
+    $edition = lire_tableau_edition();
232
+    foreach ($edition as $objet => $data) {
233
+        foreach ($data as $id => $auteurs) {
234
+            if (isset($auteurs[$id_auteur])) {
235
+                unset($edition[$objet][$id][$id_auteur]);
236
+                ecrire_tableau_edition($edition);
237
+            }
238
+        }
239
+    }
240 240
 }
241 241
 
242 242
 /**
@@ -254,19 +254,19 @@  discard block
 block discarded – undo
254 254
  * @return void
255 255
  */
256 256
 function debloquer_edition($id_auteur, $id_objet, $type = 'article') {
257
-	$edition = lire_tableau_edition();
257
+    $edition = lire_tableau_edition();
258 258
 
259
-	foreach ($edition as $objet => $data) {
260
-		if ($objet == $type) {
261
-			foreach ($data as $id => $auteurs) {
262
-				if (
263
-					$id == $id_objet
264
-					and isset($auteurs[$id_auteur])
265
-				) {
266
-					unset($edition[$objet][$id][$id_auteur]);
267
-					ecrire_tableau_edition($edition);
268
-				}
269
-			}
270
-		}
271
-	}
259
+    foreach ($edition as $objet => $data) {
260
+        if ($objet == $type) {
261
+            foreach ($data as $id => $auteurs) {
262
+                if (
263
+                    $id == $id_objet
264
+                    and isset($auteurs[$id_auteur])
265
+                ) {
266
+                    unset($edition[$objet][$id][$id_auteur]);
267
+                    ecrire_tableau_edition($edition);
268
+                }
269
+            }
270
+        }
271
+    }
272 272
 }
Please login to merge, or discard this patch.
ecrire/inc/bandeau.php 1 patch
Indentation   +149 added lines, -149 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/boutons');
@@ -37,33 +37,33 @@  discard block
 block discarded – undo
37 37
  *     Contexte
38 38
  **/
39 39
 function definir_barre_contexte($contexte = null) {
40
-	if (is_null($contexte)) {
41
-		$contexte = $_GET;
42
-	} elseif (is_string($contexte)) {
43
-		$contexte = unserialize($contexte);
44
-	}
45
-	if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) {
46
-		if (!function_exists('trouver_objet_exec')) {
47
-			include_spip('inc/pipelines_ecrire');
48
-		}
49
-		if ($e = trouver_objet_exec($contexte['exec'])) {
50
-			$_id = $e['id_table_objet'];
51
-			if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) {
52
-				$table = $e['table_objet_sql'];
53
-				$row = sql_fetsel('*', $table, "$_id=" . intval($id));
54
-				if (isset($row['id_rubrique'])) {
55
-					$contexte['id_rubrique'] = $row['id_rubrique'];
56
-					if (isset($row['id_secteur'])) {
57
-						$contexte['id_secteur'] = $row['id_secteur'];
58
-					}
59
-				} elseif (isset($row['id_groupe'])) {
60
-					// TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
61
-					$contexte['id_groupe'] = $row['id_groupe'];
62
-				}
63
-			}
64
-		}
65
-	}
66
-	return $contexte;
40
+    if (is_null($contexte)) {
41
+        $contexte = $_GET;
42
+    } elseif (is_string($contexte)) {
43
+        $contexte = unserialize($contexte);
44
+    }
45
+    if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) {
46
+        if (!function_exists('trouver_objet_exec')) {
47
+            include_spip('inc/pipelines_ecrire');
48
+        }
49
+        if ($e = trouver_objet_exec($contexte['exec'])) {
50
+            $_id = $e['id_table_objet'];
51
+            if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) {
52
+                $table = $e['table_objet_sql'];
53
+                $row = sql_fetsel('*', $table, "$_id=" . intval($id));
54
+                if (isset($row['id_rubrique'])) {
55
+                    $contexte['id_rubrique'] = $row['id_rubrique'];
56
+                    if (isset($row['id_secteur'])) {
57
+                        $contexte['id_secteur'] = $row['id_secteur'];
58
+                    }
59
+                } elseif (isset($row['id_groupe'])) {
60
+                    // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
61
+                    $contexte['id_groupe'] = $row['id_groupe'];
62
+                }
63
+            }
64
+        }
65
+    }
66
+    return $contexte;
67 67
 }
68 68
 
69 69
 /**
@@ -79,89 +79,89 @@  discard block
 block discarded – undo
79 79
  * @return array
80 80
  */
81 81
 function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) {
82
-	include_spip('inc/autoriser');
83
-	$boutons_admin = [];
82
+    include_spip('inc/autoriser');
83
+    $boutons_admin = [];
84 84
 
85
-	// les boutons du core, issus de ecrire/paquet.xml
86
-	$liste_boutons = [];
85
+    // les boutons du core, issus de ecrire/paquet.xml
86
+    $liste_boutons = [];
87 87
 
88
-	// ajouter les boutons issus des plugin via paquet.xml
89
-	if (
90
-		function_exists('boutons_plugins')
91
-		and is_array($liste_boutons_plugins = boutons_plugins())
92
-	) {
93
-		$liste_boutons = &$liste_boutons_plugins;
94
-	}
88
+    // ajouter les boutons issus des plugin via paquet.xml
89
+    if (
90
+        function_exists('boutons_plugins')
91
+        and is_array($liste_boutons_plugins = boutons_plugins())
92
+    ) {
93
+        $liste_boutons = &$liste_boutons_plugins;
94
+    }
95 95
 
96
-	foreach ($liste_boutons as $id => $infos) {
97
-		$parent = '';
98
-		// les boutons principaux ne sont pas soumis a autorisation
99
-		if (
100
-			!isset($infos['parent'])
101
-			or !($parent = $infos['parent'])
102
-			or !$autorise
103
-			or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
104
-		) {
105
-			if (
106
-				$parent
107
-				and $parent = preg_replace(',^bando_,', 'menu_', $parent)
108
-				and isset($boutons_admin[$parent])
109
-			) {
110
-				$position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu);
111
-				if ($position < 0) {
112
-					$position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
113
-				}
114
-				$boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
115
-					+ [
116
-						$id => new Bouton(
117
-							($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
118
-							$infos['titre'],  // titre
119
-							(isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
120
-							(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
121
-						)
122
-					]
123
-					+ array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
124
-			}
125
-			if (
126
-				!$parent
127
-				// provisoire, eviter les vieux boutons
128
-				and (!in_array($id, ['forum', 'statistiques_visites']))
129
-				and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
130
-			) {
131
-				$position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin);
132
-				$boutons_admin = array_slice($boutons_admin, 0, $position)
133
-					+ [
134
-						$id => new Bouton(
135
-							($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
136
-							$infos['titre'],  // titre
137
-							(isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
138
-							(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
139
-						)
140
-					]
141
-					+ array_slice($boutons_admin, $position, 100);
142
-			}
143
-		}
144
-	}
145
-	$boutons_admin = pipeline('ajouter_menus', $boutons_admin);
96
+    foreach ($liste_boutons as $id => $infos) {
97
+        $parent = '';
98
+        // les boutons principaux ne sont pas soumis a autorisation
99
+        if (
100
+            !isset($infos['parent'])
101
+            or !($parent = $infos['parent'])
102
+            or !$autorise
103
+            or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
104
+        ) {
105
+            if (
106
+                $parent
107
+                and $parent = preg_replace(',^bando_,', 'menu_', $parent)
108
+                and isset($boutons_admin[$parent])
109
+            ) {
110
+                $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu);
111
+                if ($position < 0) {
112
+                    $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
113
+                }
114
+                $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
115
+                    + [
116
+                        $id => new Bouton(
117
+                            ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
118
+                            $infos['titre'],  // titre
119
+                            (isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
120
+                            (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
121
+                        )
122
+                    ]
123
+                    + array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
124
+            }
125
+            if (
126
+                !$parent
127
+                // provisoire, eviter les vieux boutons
128
+                and (!in_array($id, ['forum', 'statistiques_visites']))
129
+                and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
130
+            ) {
131
+                $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin);
132
+                $boutons_admin = array_slice($boutons_admin, 0, $position)
133
+                    + [
134
+                        $id => new Bouton(
135
+                            ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
136
+                            $infos['titre'],  // titre
137
+                            (isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
138
+                            (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
139
+                        )
140
+                    ]
141
+                    + array_slice($boutons_admin, $position, 100);
142
+            }
143
+        }
144
+    }
145
+    $boutons_admin = pipeline('ajouter_menus', $boutons_admin);
146 146
 
147
-	// définir les favoris et positions d’origine
148
-	if ($boutons_admin) {
149
-		$menus_favoris = obtenir_menus_favoris();
150
-		$i = 1;
151
-		foreach ($boutons_admin as $key => $menu) {
152
-			$menu->favori = table_valeur($menus_favoris, $key, false);
153
-			$menu->position = $i++;
154
-			if ($menu->sousmenu) {
155
-				$j = 1;
156
-				foreach ($menu->sousmenu as $key => $bouton) {
157
-					$bouton->favori = table_valeur($menus_favoris, $key, false);
158
-					$bouton->position = $j++;
159
-				}
160
-			}
161
-		}
162
-	}
147
+    // définir les favoris et positions d’origine
148
+    if ($boutons_admin) {
149
+        $menus_favoris = obtenir_menus_favoris();
150
+        $i = 1;
151
+        foreach ($boutons_admin as $key => $menu) {
152
+            $menu->favori = table_valeur($menus_favoris, $key, false);
153
+            $menu->position = $i++;
154
+            if ($menu->sousmenu) {
155
+                $j = 1;
156
+                foreach ($menu->sousmenu as $key => $bouton) {
157
+                    $bouton->favori = table_valeur($menus_favoris, $key, false);
158
+                    $bouton->position = $j++;
159
+                }
160
+            }
161
+        }
162
+    }
163 163
 
164
-	return $boutons_admin;
164
+    return $boutons_admin;
165 165
 }
166 166
 
167 167
 /**
@@ -173,22 +173,22 @@  discard block
 block discarded – undo
173 173
  * @return Bouton[]
174 174
  */
175 175
 function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) {
176
-	foreach ($menus as $menu) {
177
-		if ($menu->sousmenu) {
178
-			$libelles = $isfavoris = $favoris = [];
179
-			foreach ($menu->sousmenu as $key => $item) {
180
-				$libelles[$key] = strtolower(translitteration(_T($item->libelle)));
181
-				$isfavoris[$key] = (bool)$item->favori;
182
-				$favoris[$key] = $item->favori;
183
-			}
184
-			if ($avec_favoris) {
185
-				array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
186
-			} else {
187
-				array_multisort($libelles, SORT_ASC, $menu->sousmenu);
188
-			}
189
-		}
190
-	}
191
-	return $menus;
176
+    foreach ($menus as $menu) {
177
+        if ($menu->sousmenu) {
178
+            $libelles = $isfavoris = $favoris = [];
179
+            foreach ($menu->sousmenu as $key => $item) {
180
+                $libelles[$key] = strtolower(translitteration(_T($item->libelle)));
181
+                $isfavoris[$key] = (bool)$item->favori;
182
+                $favoris[$key] = $item->favori;
183
+            }
184
+            if ($avec_favoris) {
185
+                array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
186
+            } else {
187
+                array_multisort($libelles, SORT_ASC, $menu->sousmenu);
188
+            }
189
+        }
190
+    }
191
+    return $menus;
192 192
 }
193 193
 
194 194
 /**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
  * @return Bouton[]
200 200
  */
201 201
 function trier_boutons_enfants_par_favoris_alpha($menus) {
202
-	return trier_boutons_enfants_par_alpha($menus, true);
202
+    return trier_boutons_enfants_par_alpha($menus, true);
203 203
 }
204 204
 
205 205
 
@@ -212,23 +212,23 @@  discard block
 block discarded – undo
212 212
  * @return string
213 213
  */
214 214
 function bandeau_creer_url($url, $args = '', $contexte = null) {
215
-	if (!preg_match(',[\/\?],', $url)) {
216
-		$url = generer_url_ecrire($url, $args, true);
217
-		// recuperer les parametres du contexte demande par l'url sous la forme
218
-		// &truc=@machin@
219
-		// @machin@ etant remplace par _request('machin')
220
-		$url = str_replace('&amp;', '&', $url);
221
-		while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
222
-			if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) {
223
-				$contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique']));
224
-			}
225
-			$val = _request($matches[2], $contexte);
226
-			$url = parametre_url($url, $matches[1], $val ?: '', '&');
227
-		}
228
-		$url = str_replace('&', '&amp;', $url);
229
-	}
215
+    if (!preg_match(',[\/\?],', $url)) {
216
+        $url = generer_url_ecrire($url, $args, true);
217
+        // recuperer les parametres du contexte demande par l'url sous la forme
218
+        // &truc=@machin@
219
+        // @machin@ etant remplace par _request('machin')
220
+        $url = str_replace('&amp;', '&', $url);
221
+        while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
222
+            if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) {
223
+                $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique']));
224
+            }
225
+            $val = _request($matches[2], $contexte);
226
+            $url = parametre_url($url, $matches[1], $val ?: '', '&');
227
+        }
228
+        $url = str_replace('&', '&amp;', $url);
229
+    }
230 230
 
231
-	return $url;
231
+    return $url;
232 232
 }
233 233
 
234 234
 /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  *     Code HTML du bandeau
239 239
  */
240 240
 function inc_bandeau_dist() {
241
-	return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
241
+    return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
242 242
 }
243 243
 
244 244
 
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
  * @return array
248 248
  */
249 249
 function obtenir_menus_favoris() {
250
-	if (
251
-		isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
252
-		and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
253
-		and $GLOBALS['visiteur_session']['prefs']['menus_favoris']
254
-	) {
255
-		return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
256
-	}
257
-	$definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
258
-	return $definir_menus_favoris();
250
+    if (
251
+        isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
252
+        and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
253
+        and $GLOBALS['visiteur_session']['prefs']['menus_favoris']
254
+    ) {
255
+        return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
256
+    }
257
+    $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
258
+    return $definir_menus_favoris();
259 259
 }
Please login to merge, or discard this patch.
ecrire/base/connect_sql.php 1 patch
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\SQL
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 require_once _ROOT_RESTREINT . 'base/objets.php';
22 22
 
@@ -42,118 +42,118 @@  discard block
 block discarded – undo
42 42
  **/
43 43
 function spip_connect($serveur = '', $version = '') {
44 44
 
45
-	$serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
-	$index = $serveur ?: 0;
47
-	if (!$version) {
48
-		$version = $GLOBALS['spip_sql_version'];
49
-	}
50
-	if (isset($GLOBALS['connexions'][$index][$version])) {
51
-		return $GLOBALS['connexions'][$index];
52
-	}
53
-
54
-	include_spip('base/abstract_sql');
55
-	$install = (_request('exec') == 'install');
56
-
57
-	// Premiere connexion ?
58
-	if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
-		$f = (!preg_match('/^[\w\.]*$/', $serveur))
60
-			? '' // nom de serveur mal ecrit
61
-			: ($serveur ?
62
-				(_DIR_CONNECT . $serveur . '.php') // serveur externe
63
-				: (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal
64
-						: ''))); // installation pas faite
65
-
66
-		unset($GLOBALS['db_ok']);
67
-		unset($GLOBALS['spip_connect_version']);
68
-		if ($f) {
69
-			if (is_readable($f)) {
70
-				include($f);
71
-			} elseif ($serveur and !$install) {
72
-				// chercher une declaration de serveur dans le path
73
-				// qui pourra un jour servir a declarer des bases sqlite
74
-				// par des plugins. Et sert aussi aux boucles POUR.
75
-				find_in_path("$serveur.php", 'connect/', true);
76
-			}
77
-		}
78
-		if (!isset($GLOBALS['db_ok'])) {
79
-			// fera mieux la prochaine fois
80
-			if ($install) {
81
-				return false;
82
-			}
83
-			if ($f and is_readable($f)) {
84
-				spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
85
-			} else {
86
-				spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
87
-			}
88
-			spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
89
-
90
-			// ne plus reessayer si ce n'est pas l'install
91
-			return $GLOBALS['connexions'][$index] = false;
92
-		}
93
-		$GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
94
-	}
95
-	// si la connexion a deja ete tentee mais a echoue, le dire!
96
-	if (!$GLOBALS['connexions'][$index]) {
97
-		return false;
98
-	}
99
-
100
-	// la connexion a reussi ou etait deja faite.
101
-	// chargement de la version du jeu de fonctions
102
-	// si pas dans le fichier par defaut
103
-	$type = $GLOBALS['db_ok']['type'];
104
-	$jeu = 'spip_' . $type . '_functions_' . $version;
105
-	if (!isset($GLOBALS[$jeu])) {
106
-		if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
107
-			spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
108
-
109
-			// ne plus reessayer
110
-			return $GLOBALS['connexions'][$index][$version] = [];
111
-		}
112
-	}
113
-	$GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
114
-	if ($old) {
115
-		return $GLOBALS['connexions'][$index];
116
-	}
117
-
118
-	$GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0;
119
-
120
-	// initialisation de l'alphabet utilise dans les connexions SQL
121
-	// si l'installation l'a determine.
122
-	// Celui du serveur principal l'impose aux serveurs secondaires
123
-	// s'ils le connaissent
124
-
125
-	if (!$serveur) {
126
-		$charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
127
-		if (!$charset) {
128
-			unset($GLOBALS['connexions'][$index]);
129
-			spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT);
130
-
131
-			return false;
132
-		}
133
-	} else {
134
-		if ($GLOBALS['db_ok']['charset']) {
135
-			$charset = $GLOBALS['db_ok']['charset'];
136
-		}
137
-		// spip_meta n'existe pas toujours dans la base
138
-		// C'est le cas d'un dump sqlite par exemple
139
-		elseif (
140
-			$GLOBALS['connexions'][$index]['spip_connect_version']
141
-			and sql_showtable('spip_meta', true, $serveur)
142
-			and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
-		) {
144
-			$charset = $r;
145
-		} else {
146
-			$charset = -1;
147
-		}
148
-	}
149
-	if ($charset != -1) {
150
-		$f = $GLOBALS[$jeu]['set_charset'];
151
-		if (function_exists($f)) {
152
-			$f($charset, $serveur);
153
-		}
154
-	}
155
-
156
-	return $GLOBALS['connexions'][$index];
45
+    $serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
+    $index = $serveur ?: 0;
47
+    if (!$version) {
48
+        $version = $GLOBALS['spip_sql_version'];
49
+    }
50
+    if (isset($GLOBALS['connexions'][$index][$version])) {
51
+        return $GLOBALS['connexions'][$index];
52
+    }
53
+
54
+    include_spip('base/abstract_sql');
55
+    $install = (_request('exec') == 'install');
56
+
57
+    // Premiere connexion ?
58
+    if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
+        $f = (!preg_match('/^[\w\.]*$/', $serveur))
60
+            ? '' // nom de serveur mal ecrit
61
+            : ($serveur ?
62
+                (_DIR_CONNECT . $serveur . '.php') // serveur externe
63
+                : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal
64
+                        : ''))); // installation pas faite
65
+
66
+        unset($GLOBALS['db_ok']);
67
+        unset($GLOBALS['spip_connect_version']);
68
+        if ($f) {
69
+            if (is_readable($f)) {
70
+                include($f);
71
+            } elseif ($serveur and !$install) {
72
+                // chercher une declaration de serveur dans le path
73
+                // qui pourra un jour servir a declarer des bases sqlite
74
+                // par des plugins. Et sert aussi aux boucles POUR.
75
+                find_in_path("$serveur.php", 'connect/', true);
76
+            }
77
+        }
78
+        if (!isset($GLOBALS['db_ok'])) {
79
+            // fera mieux la prochaine fois
80
+            if ($install) {
81
+                return false;
82
+            }
83
+            if ($f and is_readable($f)) {
84
+                spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
85
+            } else {
86
+                spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
87
+            }
88
+            spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
89
+
90
+            // ne plus reessayer si ce n'est pas l'install
91
+            return $GLOBALS['connexions'][$index] = false;
92
+        }
93
+        $GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
94
+    }
95
+    // si la connexion a deja ete tentee mais a echoue, le dire!
96
+    if (!$GLOBALS['connexions'][$index]) {
97
+        return false;
98
+    }
99
+
100
+    // la connexion a reussi ou etait deja faite.
101
+    // chargement de la version du jeu de fonctions
102
+    // si pas dans le fichier par defaut
103
+    $type = $GLOBALS['db_ok']['type'];
104
+    $jeu = 'spip_' . $type . '_functions_' . $version;
105
+    if (!isset($GLOBALS[$jeu])) {
106
+        if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
107
+            spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
108
+
109
+            // ne plus reessayer
110
+            return $GLOBALS['connexions'][$index][$version] = [];
111
+        }
112
+    }
113
+    $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
114
+    if ($old) {
115
+        return $GLOBALS['connexions'][$index];
116
+    }
117
+
118
+    $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0;
119
+
120
+    // initialisation de l'alphabet utilise dans les connexions SQL
121
+    // si l'installation l'a determine.
122
+    // Celui du serveur principal l'impose aux serveurs secondaires
123
+    // s'ils le connaissent
124
+
125
+    if (!$serveur) {
126
+        $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
127
+        if (!$charset) {
128
+            unset($GLOBALS['connexions'][$index]);
129
+            spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT);
130
+
131
+            return false;
132
+        }
133
+    } else {
134
+        if ($GLOBALS['db_ok']['charset']) {
135
+            $charset = $GLOBALS['db_ok']['charset'];
136
+        }
137
+        // spip_meta n'existe pas toujours dans la base
138
+        // C'est le cas d'un dump sqlite par exemple
139
+        elseif (
140
+            $GLOBALS['connexions'][$index]['spip_connect_version']
141
+            and sql_showtable('spip_meta', true, $serveur)
142
+            and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
+        ) {
144
+            $charset = $r;
145
+        } else {
146
+            $charset = -1;
147
+        }
148
+    }
149
+    if ($charset != -1) {
150
+        $f = $GLOBALS[$jeu]['set_charset'];
151
+        if (function_exists($f)) {
152
+            $f($charset, $serveur);
153
+        }
154
+    }
155
+
156
+    return $GLOBALS['connexions'][$index];
157 157
 }
158 158
 
159 159
 /**
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
  * @param string $serveur Nom du connecteur de bdd utilisé
163 163
  **/
164 164
 function spip_sql_erreur($serveur = '') {
165
-	$connexion = spip_connect($serveur);
166
-	$e = sql_errno($serveur);
167
-	$t = ($connexion['type'] ?? 'sql');
168
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
-	$f = $t . $serveur;
170
-	spip_log($m, $f . '.' . _LOG_ERREUR);
165
+    $connexion = spip_connect($serveur);
166
+    $e = sql_errno($serveur);
167
+    $t = ($connexion['type'] ?? 'sql');
168
+    $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
+    $f = $t . $serveur;
170
+    spip_log($m, $f . '.' . _LOG_ERREUR);
171 171
 }
172 172
 
173 173
 /**
@@ -189,23 +189,23 @@  discard block
 block discarded – undo
189 189
  *     - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion
190 190
  **/
191 191
 function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) {
192
-	$desc = spip_connect($serveur, $version);
193
-	if (
194
-		$desc
195
-		and $f = ($desc[$version][$ins] ?? '')
196
-		and function_exists($f)
197
-	) {
198
-		return $f;
199
-	}
200
-	if ($continue) {
201
-		return $desc;
202
-	}
203
-	if ($ins) {
204
-		spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
205
-	}
206
-	include_spip('inc/minipres');
207
-	echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]);
208
-	exit;
192
+    $desc = spip_connect($serveur, $version);
193
+    if (
194
+        $desc
195
+        and $f = ($desc[$version][$ins] ?? '')
196
+        and function_exists($f)
197
+    ) {
198
+        return $f;
199
+    }
200
+    if ($continue) {
201
+        return $desc;
202
+    }
203
+    if ($ins) {
204
+        spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
205
+    }
206
+    include_spip('inc/minipres');
207
+    echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]);
208
+    exit;
209 209
 }
210 210
 
211 211
 /**
@@ -231,70 +231,70 @@  discard block
 block discarded – undo
231 231
  * @return array|null Description de la connexion
232 232
  */
233 233
 function spip_connect_db(
234
-	$host,
235
-	$port,
236
-	$login,
237
-	$pass,
238
-	$db = '',
239
-	$type = 'mysql',
240
-	$prefixe = '',
241
-	$auth = '',
242
-	$charset = ''
234
+    $host,
235
+    $port,
236
+    $login,
237
+    $pass,
238
+    $db = '',
239
+    $type = 'mysql',
240
+    $prefixe = '',
241
+    $auth = '',
242
+    $charset = ''
243 243
 ) {
244
-	// temps avant nouvelle tentative de connexion
245
-	// suite a une connection echouee
246
-	if (!defined('_CONNECT_RETRY_DELAY')) {
247
-		define('_CONNECT_RETRY_DELAY', 30);
248
-	}
249
-
250
-	$f = '';
251
-	// un fichier de identifiant par combinaison (type,host,port,db)
252
-	// pour ne pas declarer tout indisponible d'un coup
253
-	// si en cours d'installation ou si db=@test@ on ne pose rien
254
-	// car c'est un test de connexion
255
-	if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') {
256
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
257
-	} elseif ($db == '@test@') {
258
-		$db = '';
259
-	}
260
-
261
-	if (
262
-		$f
263
-		and @file_exists($f)
264
-		and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
265
-	) {
266
-		spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
267
-
268
-		return null;
269
-	}
270
-
271
-	if (!$prefixe) {
272
-		$prefixe = $GLOBALS['table_prefix'] ?? $db;
273
-	}
274
-	$h = charger_fonction($type, 'req', true);
275
-	if (!$h) {
276
-		spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
277
-
278
-		return null;
279
-	}
280
-	if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
281
-		if (!is_array($auth)) {
282
-			// compatibilite version 0.7 initiale
283
-			$g['ldap'] = $auth;
284
-			$auth = ['ldap' => $auth];
285
-		}
286
-		$g['authentification'] = $auth;
287
-		$g['type'] = $type;
288
-		$g['charset'] = $charset;
289
-
290
-		return $GLOBALS['db_ok'] = $g;
291
-	}
292
-	// En cas d'indisponibilite du serveur, eviter de le bombarder
293
-	if ($f) {
294
-		@touch($f);
295
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
296
-	}
297
-	return null;
244
+    // temps avant nouvelle tentative de connexion
245
+    // suite a une connection echouee
246
+    if (!defined('_CONNECT_RETRY_DELAY')) {
247
+        define('_CONNECT_RETRY_DELAY', 30);
248
+    }
249
+
250
+    $f = '';
251
+    // un fichier de identifiant par combinaison (type,host,port,db)
252
+    // pour ne pas declarer tout indisponible d'un coup
253
+    // si en cours d'installation ou si db=@test@ on ne pose rien
254
+    // car c'est un test de connexion
255
+    if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') {
256
+        $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
257
+    } elseif ($db == '@test@') {
258
+        $db = '';
259
+    }
260
+
261
+    if (
262
+        $f
263
+        and @file_exists($f)
264
+        and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
265
+    ) {
266
+        spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
267
+
268
+        return null;
269
+    }
270
+
271
+    if (!$prefixe) {
272
+        $prefixe = $GLOBALS['table_prefix'] ?? $db;
273
+    }
274
+    $h = charger_fonction($type, 'req', true);
275
+    if (!$h) {
276
+        spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
277
+
278
+        return null;
279
+    }
280
+    if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
281
+        if (!is_array($auth)) {
282
+            // compatibilite version 0.7 initiale
283
+            $g['ldap'] = $auth;
284
+            $auth = ['ldap' => $auth];
285
+        }
286
+        $g['authentification'] = $auth;
287
+        $g['type'] = $type;
288
+        $g['charset'] = $charset;
289
+
290
+        return $GLOBALS['db_ok'] = $g;
291
+    }
292
+    // En cas d'indisponibilite du serveur, eviter de le bombarder
293
+    if ($f) {
294
+        @touch($f);
295
+        spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
296
+    }
297
+    return null;
298 298
 }
299 299
 
300 300
 
@@ -326,32 +326,32 @@  discard block
 block discarded – undo
326 326
  *     - nom du charset sinon
327 327
  **/
328 328
 function spip_connect_main($connexion, $charset_sql_connexion = '') {
329
-	if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
330
-		include_spip('inc/headers');
331
-		redirige_url_ecrire('upgrade', 'reinstall=oui');
332
-	}
333
-
334
-	if (!($f = $connexion['select'])) {
335
-		return false;
336
-	}
337
-	// si le charset est fourni, l'utiliser
338
-	if ($charset_sql_connexion) {
339
-		return $charset_sql_connexion;
340
-	}
341
-	// sinon on regarde la table spip_meta
342
-	// en cas d'erreur select retourne la requette (is_string=true donc)
343
-	if (
344
-		!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
345
-		or is_string($r)
346
-	) {
347
-		return false;
348
-	}
349
-	if (!($f = $connexion['fetch'])) {
350
-		return false;
351
-	}
352
-	$r = $f($r);
353
-
354
-	return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
329
+    if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
330
+        include_spip('inc/headers');
331
+        redirige_url_ecrire('upgrade', 'reinstall=oui');
332
+    }
333
+
334
+    if (!($f = $connexion['select'])) {
335
+        return false;
336
+    }
337
+    // si le charset est fourni, l'utiliser
338
+    if ($charset_sql_connexion) {
339
+        return $charset_sql_connexion;
340
+    }
341
+    // sinon on regarde la table spip_meta
342
+    // en cas d'erreur select retourne la requette (is_string=true donc)
343
+    if (
344
+        !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
345
+        or is_string($r)
346
+    ) {
347
+        return false;
348
+    }
349
+    if (!($f = $connexion['fetch'])) {
350
+        return false;
351
+    }
352
+    $r = $f($r);
353
+
354
+    return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
355 355
 }
356 356
 
357 357
 /**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
  * @return array
368 368
  */
369 369
 function spip_connect_ldap($serveur = '') {
370
-	include_spip('auth/ldap');
371
-	return auth_ldap_connect($serveur);
370
+    include_spip('auth/ldap');
371
+    return auth_ldap_connect($serveur);
372 372
 }
373 373
 
374 374
 /**
@@ -384,16 +384,16 @@  discard block
 block discarded – undo
384 384
  * @return string Valeur échappée.
385 385
  **/
386 386
 function _q($a): string {
387
-	if (is_numeric($a)) {
388
-		return strval($a);
389
-	} elseif (is_array($a)) {
390
-		return join(',', array_map('_q', $a));
391
-	} elseif (is_scalar($a)) {
392
-		return ("'" . addslashes($a) . "'");
393
-	} elseif ($a === null) {
394
-		return "''";
395
-	}
396
-	throw new \RuntimeException('Can’t use _q with ' . gettype($a));
387
+    if (is_numeric($a)) {
388
+        return strval($a);
389
+    } elseif (is_array($a)) {
390
+        return join(',', array_map('_q', $a));
391
+    } elseif (is_scalar($a)) {
392
+        return ("'" . addslashes($a) . "'");
393
+    } elseif ($a === null) {
394
+        return "''";
395
+    }
396
+    throw new \RuntimeException('Can’t use _q with ' . gettype($a));
397 397
 }
398 398
 
399 399
 /**
@@ -409,75 +409,75 @@  discard block
 block discarded – undo
409 409
  * @return array
410 410
  */
411 411
 function query_echappe_textes($query, $uniqid = null) {
412
-	static $codeEchappements = null;
413
-	if (is_null($codeEchappements) or $uniqid) {
414
-		if (is_null($uniqid)) {
415
-			$uniqid = uniqid();
416
-		}
417
-		$uniqid = substr(md5($uniqid), 0, 4);
418
-		$codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"];
419
-	}
420
-	if ($query === null) {
421
-		return $codeEchappements;
422
-	}
423
-
424
-	// si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien
425
-	// ce n'est pas un cas legitime
426
-	foreach ($codeEchappements as $codeEchappement) {
427
-		if (strpos($query, (string) $codeEchappement) !== false) {
428
-			return [$query, []];
429
-		}
430
-	}
431
-
432
-	$query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
433
-	if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) {
434
-		$textes = reset($textes);
435
-
436
-		$parts = [];
437
-		$currentpos = 0;
438
-		$k = 0;
439
-		while (count($textes)) {
440
-			$part = array_shift($textes);
441
-			$nextpos = strpos($query_echappees, $part, $currentpos);
442
-			// si besoin recoller ensemble les doubles '' de sqlite (echappement des ')
443
-			while (count($textes) and substr($part, -1) === "'") {
444
-				$next = reset($textes);
445
-				if (
446
-					strpos($next, "'") === 0
447
-					and strpos($query_echappees, $part . $next, $currentpos) === $nextpos
448
-				) {
449
-					$part .= array_shift($textes);
450
-				}
451
-				else {
452
-					break;
453
-				}
454
-			}
455
-			$k++;
456
-			$parts[$k] = [
457
-				'texte' => $part,
458
-				'position' => $nextpos,
459
-				'placeholder' => '%' . $k . '$s',
460
-			];
461
-			$currentpos = $nextpos + strlen($part);
462
-		}
463
-
464
-		// et on replace les parts une par une en commencant par la fin
465
-		while ($k > 0) {
466
-			$query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen($parts[$k]['texte']));
467
-			$k--;
468
-		}
469
-		$textes = array_column($parts, 'texte');
470
-	} else {
471
-		$textes = [];
472
-	}
473
-
474
-	// si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux
475
-	// dans le doute on ne touche a rien
476
-	if (strpbrk($query_echappees, "'\"") !== false) {
477
-		return [$query, []];
478
-	}
479
-
480
-	return [$query_echappees, $textes];
412
+    static $codeEchappements = null;
413
+    if (is_null($codeEchappements) or $uniqid) {
414
+        if (is_null($uniqid)) {
415
+            $uniqid = uniqid();
416
+        }
417
+        $uniqid = substr(md5($uniqid), 0, 4);
418
+        $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"];
419
+    }
420
+    if ($query === null) {
421
+        return $codeEchappements;
422
+    }
423
+
424
+    // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien
425
+    // ce n'est pas un cas legitime
426
+    foreach ($codeEchappements as $codeEchappement) {
427
+        if (strpos($query, (string) $codeEchappement) !== false) {
428
+            return [$query, []];
429
+        }
430
+    }
431
+
432
+    $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
433
+    if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) {
434
+        $textes = reset($textes);
435
+
436
+        $parts = [];
437
+        $currentpos = 0;
438
+        $k = 0;
439
+        while (count($textes)) {
440
+            $part = array_shift($textes);
441
+            $nextpos = strpos($query_echappees, $part, $currentpos);
442
+            // si besoin recoller ensemble les doubles '' de sqlite (echappement des ')
443
+            while (count($textes) and substr($part, -1) === "'") {
444
+                $next = reset($textes);
445
+                if (
446
+                    strpos($next, "'") === 0
447
+                    and strpos($query_echappees, $part . $next, $currentpos) === $nextpos
448
+                ) {
449
+                    $part .= array_shift($textes);
450
+                }
451
+                else {
452
+                    break;
453
+                }
454
+            }
455
+            $k++;
456
+            $parts[$k] = [
457
+                'texte' => $part,
458
+                'position' => $nextpos,
459
+                'placeholder' => '%' . $k . '$s',
460
+            ];
461
+            $currentpos = $nextpos + strlen($part);
462
+        }
463
+
464
+        // et on replace les parts une par une en commencant par la fin
465
+        while ($k > 0) {
466
+            $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen($parts[$k]['texte']));
467
+            $k--;
468
+        }
469
+        $textes = array_column($parts, 'texte');
470
+    } else {
471
+        $textes = [];
472
+    }
473
+
474
+    // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux
475
+    // dans le doute on ne touche a rien
476
+    if (strpbrk($query_echappees, "'\"") !== false) {
477
+        return [$query, []];
478
+    }
479
+
480
+    return [$query_echappees, $textes];
481 481
 }
482 482
 
483 483
 /**
@@ -491,16 +491,16 @@  discard block
 block discarded – undo
491 491
  * @return string
492 492
  */
493 493
 function query_reinjecte_textes($query, $textes) {
494
-	// recuperer les codes echappements
495
-	$codeEchappements = query_echappe_textes(null);
494
+    // recuperer les codes echappements
495
+    $codeEchappements = query_echappe_textes(null);
496 496
 
497
-	if (!empty($textes)) {
498
-		$query = sprintf($query, ...$textes);
499
-	}
497
+    if (!empty($textes)) {
498
+        $query = sprintf($query, ...$textes);
499
+    }
500 500
 
501
-	$query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
501
+    $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
502 502
 
503
-	return $query;
503
+    return $query;
504 504
 }
505 505
 
506 506
 
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
  **/
520 520
 function spip_query($query, $serveur = '') {
521 521
 
522
-	$f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
522
+    $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
523 523
 
524
-	return function_exists($f) ? $f($query, $serveur) : false;
524
+    return function_exists($f) ? $f($query, $serveur) : false;
525 525
 }
Please login to merge, or discard this patch.