Completed
Push — master ( 5b64d4...58871c )
by cam
01:05
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' . $senstri;
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' . $senstri;
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.