Completed
Push — master ( b2f238...42b790 )
by cam
01:39
created
ecrire/public/quete.php 1 patch
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  * @return array|bool|null
34 34
  */
35 35
 function quete_virtuel($id_article, $connect) {
36
-	return sql_getfetsel(
37
-		'virtuel',
38
-		'spip_articles',
39
-		['id_article=' . intval($id_article), "statut='publie'"],
40
-		'',
41
-		'',
42
-		'',
43
-		'',
44
-		$connect
45
-	);
36
+    return sql_getfetsel(
37
+        'virtuel',
38
+        'spip_articles',
39
+        ['id_article=' . intval($id_article), "statut='publie'"],
40
+        '',
41
+        '',
42
+        '',
43
+        '',
44
+        $connect
45
+    );
46 46
 }
47 47
 
48 48
 /**
@@ -57,41 +57,41 @@  discard block
 block discarded – undo
57 57
  * @return array
58 58
  */
59 59
 function quete_parent_lang($table, $id, string $connect = '') {
60
-	static $cache_quete = [];
61
-
62
-	if (!isset($cache_quete[$connect][$table][$id])) {
63
-		if (!isset($cache_quete[$connect][$table]['_select'])) {
64
-			$trouver_table = charger_fonction('trouver_table', 'base');
65
-			if (
66
-				!$desc = $trouver_table(
67
-					$table,
68
-					$connect
69
-				) or !isset($desc['field']['id_rubrique'])
70
-			) {
71
-				// pas de parent rubrique, on passe
72
-				$cache_quete[$connect][$table]['_select'] = false;
73
-			} else {
74
-				$select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
75
-				$select .= isset($desc['field']['lang']) ? ', lang' : '';
76
-				$cache_quete[$connect][$table]['_select'] = $select;
77
-				$cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
78
-			}
79
-		}
80
-		if ($cache_quete[$connect][$table]['_select']) {
81
-			$cache_quete[$connect][$table][$id] = sql_fetsel(
82
-				$cache_quete[$connect][$table]['_select'],
83
-				$table,
84
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
85
-				'',
86
-				'',
87
-				'',
88
-				'',
89
-				$connect
90
-			);
91
-		}
92
-	}
93
-
94
-	return $cache_quete[$connect][$table][$id] ?? null;
60
+    static $cache_quete = [];
61
+
62
+    if (!isset($cache_quete[$connect][$table][$id])) {
63
+        if (!isset($cache_quete[$connect][$table]['_select'])) {
64
+            $trouver_table = charger_fonction('trouver_table', 'base');
65
+            if (
66
+                !$desc = $trouver_table(
67
+                    $table,
68
+                    $connect
69
+                ) or !isset($desc['field']['id_rubrique'])
70
+            ) {
71
+                // pas de parent rubrique, on passe
72
+                $cache_quete[$connect][$table]['_select'] = false;
73
+            } else {
74
+                $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
75
+                $select .= isset($desc['field']['lang']) ? ', lang' : '';
76
+                $cache_quete[$connect][$table]['_select'] = $select;
77
+                $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
78
+            }
79
+        }
80
+        if ($cache_quete[$connect][$table]['_select']) {
81
+            $cache_quete[$connect][$table][$id] = sql_fetsel(
82
+                $cache_quete[$connect][$table]['_select'],
83
+                $table,
84
+                $cache_quete[$connect][$table]['_id'] . '=' . intval($id),
85
+                '',
86
+                '',
87
+                '',
88
+                '',
89
+                $connect
90
+            );
91
+        }
92
+    }
93
+
94
+    return $cache_quete[$connect][$table][$id] ?? null;
95 95
 }
96 96
 
97 97
 
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
  * @return int
109 109
  */
110 110
 function quete_parent($id_rubrique, string $connect = '') {
111
-	if (!$id_rubrique = intval($id_rubrique)) {
112
-		return 0;
113
-	}
114
-	$id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
115
-	return $id_parent ? $id_parent['id_parent'] : 0;
111
+    if (!$id_rubrique = intval($id_rubrique)) {
112
+        return 0;
113
+    }
114
+    $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
115
+    return $id_parent ? $id_parent['id_parent'] : 0;
116 116
 }
117 117
 
118 118
 /**
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
  * @return int
129 129
  */
130 130
 function quete_rubrique($id_article, $serveur) {
131
-	$id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
131
+    $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
132 132
 
133
-	return $id_parent['id_rubrique'];
133
+    return $id_parent['id_rubrique'];
134 134
 }
135 135
 
136 136
 
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
  * @return int
145 145
  */
146 146
 function quete_profondeur($id, string $connect = '') {
147
-	$n = 0;
148
-	while ($id) {
149
-		$n++;
150
-		$id = quete_parent($id, $connect);
151
-	}
147
+    $n = 0;
148
+    while ($id) {
149
+        $n++;
150
+        $id = quete_parent($id, $connect);
151
+    }
152 152
 
153
-	return $n;
153
+    return $n;
154 154
 }
155 155
 
156 156
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  *     Morceau de la requête SQL testant la date
167 167
  */
168 168
 function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) {
169
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
170
-		return '1=1';
171
-	}
172
-
173
-	return
174
-		(isset($GLOBALS['meta']['date_prochain_postdate'])
175
-			and $GLOBALS['meta']['date_prochain_postdate'] > time())
176
-			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177
-			: '1=1';
169
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
170
+        return '1=1';
171
+    }
172
+
173
+    return
174
+        (isset($GLOBALS['meta']['date_prochain_postdate'])
175
+            and $GLOBALS['meta']['date_prochain_postdate'] > time())
176
+            ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177
+            : '1=1';
178 178
 }
179 179
 
180 180
 
@@ -194,101 +194,101 @@  discard block
 block discarded – undo
194 194
  * @return array|string
195 195
  */
196 196
 function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) {
197
-	static $cond = [];
198
-	$key = func_get_args();
199
-	$key = implode('-', $key);
200
-	if (isset($cond[$key])) {
201
-		return $cond[$key];
202
-	}
203
-
204
-	$liste_statuts = $publie;
205
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
206
-		$liste_statuts = $previsu;
207
-	}
208
-	$not = false;
209
-	if (strncmp($liste_statuts, '!', 1) == 0) {
210
-		$not = true;
211
-		$liste_statuts = substr($liste_statuts, 1);
212
-	}
213
-	// '' => ne rien afficher, '!'=> ne rien filtrer
214
-	if (!strlen($liste_statuts)) {
215
-		return $cond[$key] = ($not ? '1=1' : '0=1');
216
-	}
217
-
218
-	$liste_statuts = explode(',', $liste_statuts);
219
-	$where = [];
220
-	foreach ($liste_statuts as $k => $v) {
221
-		// filtrage /auteur pour limiter les objets d'un statut (prepa en general)
222
-		// a ceux de l'auteur identifie
223
-		if (strpos($v, '/') !== false) {
224
-			$v = explode('/', $v);
225
-			$filtre = end($v);
226
-			$v = reset($v);
227
-			$v = preg_replace(',\W,', '', $v);
228
-			if (
229
-				$filtre == 'auteur'
230
-				and (strpos($mstatut, '.') !== false)
231
-				and $objet = explode('.', $mstatut)
232
-				and $id_table = reset($objet)
233
-				and $objet = objet_type($id_table)
234
-			) {
235
-				$w = "$mstatut<>" . sql_quote($v);
236
-
237
-				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238
-				// sinon l’auteur en session
239
-				include_spip('inc/securiser_action');
240
-				if ($desc = decrire_token_previsu()) {
241
-					$id_auteur = $desc['id_auteur'];
242
-				} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
243
-					$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
244
-				} else {
245
-					$id_auteur = null;
246
-				}
247
-
248
-				// dans ce cas (admin en general), pas de filtrage sur ce statut
249
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
250
-					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251
-					if (!$id_auteur) {
252
-						$where[] = $w;
253
-					} else {
254
-						$primary = id_table_objet($objet);
255
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
256
-							'ssss.id_objet',
257
-							'spip_auteurs_liens AS ssss',
258
-							'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
259
-							'',
260
-							'',
261
-							'',
262
-							'',
263
-							$serveur
264
-						) . '))';
265
-					}
266
-				}
267
-			} // ignorer ce statut si on ne sait pas comment le filtrer
268
-			else {
269
-				$v = '';
270
-			}
271
-		}
272
-		// securite
273
-		$liste_statuts[$k] = preg_replace(',\W,', '', $v);
274
-	}
275
-	$liste_statuts = array_filter($liste_statuts);
276
-	if (count($liste_statuts) == 1) {
277
-		$where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)];
278
-	} else {
279
-		$where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
280
-	}
281
-
282
-	while (count($where) > 1) {
283
-		$and = ['AND', array_pop($where), array_pop($where)];
284
-		$where[] = $and;
285
-	}
286
-	$cond[$key] = reset($where);
287
-	if ($not) {
288
-		$cond[$key] = ['NOT', $cond[$key]];
289
-	}
290
-
291
-	return $cond[$key];
197
+    static $cond = [];
198
+    $key = func_get_args();
199
+    $key = implode('-', $key);
200
+    if (isset($cond[$key])) {
201
+        return $cond[$key];
202
+    }
203
+
204
+    $liste_statuts = $publie;
205
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
206
+        $liste_statuts = $previsu;
207
+    }
208
+    $not = false;
209
+    if (strncmp($liste_statuts, '!', 1) == 0) {
210
+        $not = true;
211
+        $liste_statuts = substr($liste_statuts, 1);
212
+    }
213
+    // '' => ne rien afficher, '!'=> ne rien filtrer
214
+    if (!strlen($liste_statuts)) {
215
+        return $cond[$key] = ($not ? '1=1' : '0=1');
216
+    }
217
+
218
+    $liste_statuts = explode(',', $liste_statuts);
219
+    $where = [];
220
+    foreach ($liste_statuts as $k => $v) {
221
+        // filtrage /auteur pour limiter les objets d'un statut (prepa en general)
222
+        // a ceux de l'auteur identifie
223
+        if (strpos($v, '/') !== false) {
224
+            $v = explode('/', $v);
225
+            $filtre = end($v);
226
+            $v = reset($v);
227
+            $v = preg_replace(',\W,', '', $v);
228
+            if (
229
+                $filtre == 'auteur'
230
+                and (strpos($mstatut, '.') !== false)
231
+                and $objet = explode('.', $mstatut)
232
+                and $id_table = reset($objet)
233
+                and $objet = objet_type($id_table)
234
+            ) {
235
+                $w = "$mstatut<>" . sql_quote($v);
236
+
237
+                // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238
+                // sinon l’auteur en session
239
+                include_spip('inc/securiser_action');
240
+                if ($desc = decrire_token_previsu()) {
241
+                    $id_auteur = $desc['id_auteur'];
242
+                } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
243
+                    $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
244
+                } else {
245
+                    $id_auteur = null;
246
+                }
247
+
248
+                // dans ce cas (admin en general), pas de filtrage sur ce statut
249
+                if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
250
+                    // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251
+                    if (!$id_auteur) {
252
+                        $where[] = $w;
253
+                    } else {
254
+                        $primary = id_table_objet($objet);
255
+                        $where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
256
+                            'ssss.id_objet',
257
+                            'spip_auteurs_liens AS ssss',
258
+                            'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
259
+                            '',
260
+                            '',
261
+                            '',
262
+                            '',
263
+                            $serveur
264
+                        ) . '))';
265
+                    }
266
+                }
267
+            } // ignorer ce statut si on ne sait pas comment le filtrer
268
+            else {
269
+                $v = '';
270
+            }
271
+        }
272
+        // securite
273
+        $liste_statuts[$k] = preg_replace(',\W,', '', $v);
274
+    }
275
+    $liste_statuts = array_filter($liste_statuts);
276
+    if (count($liste_statuts) == 1) {
277
+        $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)];
278
+    } else {
279
+        $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
280
+    }
281
+
282
+    while (count($where) > 1) {
283
+        $and = ['AND', array_pop($where), array_pop($where)];
284
+        $where[] = $and;
285
+    }
286
+    $cond[$key] = reset($where);
287
+    if ($not) {
288
+        $cond[$key] = ['NOT', $cond[$key]];
289
+    }
290
+
291
+    return $cond[$key];
292 292
 }
293 293
 
294 294
 /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
  * @return array|bool|null
300 300
  */
301 301
 function quete_fichier($id_document, $serveur = '') {
302
-	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
302
+    return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
303 303
 }
304 304
 
305 305
 /**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
  * @return array|bool
311 311
  */
312 312
 function quete_document($id_document, $serveur = '') {
313
-	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
313
+    return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
314 314
 }
315 315
 
316 316
 /**
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
  * @return array|bool|null
322 322
  */
323 323
 function quete_meta($nom, $serveur) {
324
-	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
324
+    return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
325 325
 }
326 326
 
327 327
 /**
@@ -347,66 +347,66 @@  discard block
 block discarded – undo
347 347
  *     Retourne soit un tableau, soit le chemin du fichier.
348 348
  */
349 349
 function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) {
350
-	include_spip('base/objets');
351
-	$nom = strtolower($onoff);
352
-
353
-	$cle_objet = id_table_objet($cle_objet);
354
-
355
-	while (1) {
356
-		$objet = objet_type($cle_objet);
357
-
358
-		$on = quete_logo_objet($id, $objet, $nom);
359
-
360
-		if ($on) {
361
-			if ($flag) {
362
-				return basename($on['chemin']);
363
-			} else {
364
-				$taille = @spip_getimagesize($on['chemin']);
365
-
366
-				// Si on a déjà demandé un survol directement ($onoff = off)
367
-				// ou qu'on a demandé uniquement le normal ($onoff = on)
368
-				// alors on ne cherche pas du tout le survol ici
369
-				if ($onoff != 'ON') {
370
-					$off = '';
371
-				} else {
372
-					// Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
373
-					$off = quete_logo_objet($id, $objet, 'off');
374
-				}
375
-
376
-				// on retourne une url du type IMG/artonXX?timestamp
377
-				// qui permet de distinguer le changement de logo
378
-				// et placer un expire sur le dossier IMG/
379
-				$res = [
380
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
-					(!$taille ? '' : (' ' . $taille[3]))
383
-				];
384
-				$res['src'] = $res[0];
385
-				$res['logo_on'] = $res[0];
386
-				$res['logo_off'] = $res[1];
387
-				$res['width'] = ($taille ? $taille[0] : '');
388
-				$res['height'] = ($taille ? $taille[1] : '');
389
-
390
-				return $res;
391
-			}
392
-		} else {
393
-			if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
394
-				return '';
395
-			} else {
396
-				if ($id_rubrique) {
397
-					$cle_objet = 'id_rubrique';
398
-					$id = $id_rubrique;
399
-					$id_rubrique = 0;
400
-				} else {
401
-					if ($id and $cle_objet == 'id_rubrique') {
402
-						$id = quete_parent($id);
403
-					} else {
404
-						return '';
405
-					}
406
-				}
407
-			}
408
-		}
409
-	}
350
+    include_spip('base/objets');
351
+    $nom = strtolower($onoff);
352
+
353
+    $cle_objet = id_table_objet($cle_objet);
354
+
355
+    while (1) {
356
+        $objet = objet_type($cle_objet);
357
+
358
+        $on = quete_logo_objet($id, $objet, $nom);
359
+
360
+        if ($on) {
361
+            if ($flag) {
362
+                return basename($on['chemin']);
363
+            } else {
364
+                $taille = @spip_getimagesize($on['chemin']);
365
+
366
+                // Si on a déjà demandé un survol directement ($onoff = off)
367
+                // ou qu'on a demandé uniquement le normal ($onoff = on)
368
+                // alors on ne cherche pas du tout le survol ici
369
+                if ($onoff != 'ON') {
370
+                    $off = '';
371
+                } else {
372
+                    // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
373
+                    $off = quete_logo_objet($id, $objet, 'off');
374
+                }
375
+
376
+                // on retourne une url du type IMG/artonXX?timestamp
377
+                // qui permet de distinguer le changement de logo
378
+                // et placer un expire sur le dossier IMG/
379
+                $res = [
380
+                    $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
+                    ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
+                    (!$taille ? '' : (' ' . $taille[3]))
383
+                ];
384
+                $res['src'] = $res[0];
385
+                $res['logo_on'] = $res[0];
386
+                $res['logo_off'] = $res[1];
387
+                $res['width'] = ($taille ? $taille[0] : '');
388
+                $res['height'] = ($taille ? $taille[1] : '');
389
+
390
+                return $res;
391
+            }
392
+        } else {
393
+            if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
394
+                return '';
395
+            } else {
396
+                if ($id_rubrique) {
397
+                    $cle_objet = 'id_rubrique';
398
+                    $id = $id_rubrique;
399
+                    $id_rubrique = 0;
400
+                } else {
401
+                    if ($id and $cle_objet == 'id_rubrique') {
402
+                        $id = quete_parent($id);
403
+                    } else {
404
+                        return '';
405
+                    }
406
+                }
407
+            }
408
+        }
409
+    }
410 410
 }
411 411
 
412 412
 /**
@@ -420,37 +420,37 @@  discard block
 block discarded – undo
420 420
  * 		"on" ou "off" suivant le logo normal ou survol
421 421
  **/
422 422
 function quete_logo_objet($id_objet, $objet, $mode) {
423
-	static $chercher_logo;
424
-	if (is_null($chercher_logo)) {
425
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
426
-	}
427
-	$cle_objet = id_table_objet($objet);
428
-
429
-	// On cherche pas la méthode classique
430
-	$infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
431
-	// Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
432
-	if (!empty($infos_logo)) {
433
-		$infos_logo = [
434
-			'chemin' => $infos_logo[0],
435
-			'timestamp' => $infos_logo[4],
436
-		];
437
-	}
438
-
439
-	// On passe cette recherche de logo dans un pipeline
440
-	$infos_logo = pipeline(
441
-		'quete_logo_objet',
442
-		[
443
-			'args' => [
444
-				'id_objet' => $id_objet,
445
-				'objet' => $objet,
446
-				'cle_objet' => $cle_objet,
447
-				'mode' => $mode,
448
-			],
449
-			'data' => $infos_logo,
450
-		]
451
-	);
452
-
453
-	return $infos_logo;
423
+    static $chercher_logo;
424
+    if (is_null($chercher_logo)) {
425
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
426
+    }
427
+    $cle_objet = id_table_objet($objet);
428
+
429
+    // On cherche pas la méthode classique
430
+    $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
431
+    // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
432
+    if (!empty($infos_logo)) {
433
+        $infos_logo = [
434
+            'chemin' => $infos_logo[0],
435
+            'timestamp' => $infos_logo[4],
436
+        ];
437
+    }
438
+
439
+    // On passe cette recherche de logo dans un pipeline
440
+    $infos_logo = pipeline(
441
+        'quete_logo_objet',
442
+        [
443
+            'args' => [
444
+                'id_objet' => $id_objet,
445
+                'objet' => $objet,
446
+                'cle_objet' => $cle_objet,
447
+                'mode' => $mode,
448
+            ],
449
+            'data' => $infos_logo,
450
+        ]
451
+    );
452
+
453
+    return $infos_logo;
454 454
 }
455 455
 
456 456
 /**
@@ -463,25 +463,25 @@  discard block
 block discarded – undo
463 463
  * @return bool|string
464 464
  */
465 465
 function quete_logo_file($row, $connect = null) {
466
-	include_spip('inc/documents');
467
-	$logo = vignette_logo_document($row, $connect);
468
-	if (!$logo) {
469
-		$logo = image_du_document($row, $connect);
470
-	}
471
-	if (!$logo) {
472
-		$f = charger_fonction('vignette', 'inc');
473
-		$logo = $f($row['extension'], false);
474
-	}
475
-	// si c'est une vignette type doc, la renvoyer direct
476
-	if (
477
-		strcmp($logo, _DIR_PLUGINS) == 0
478
-		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
480
-	) {
481
-		return $logo;
482
-	}
483
-
484
-	return get_spip_doc($logo);
466
+    include_spip('inc/documents');
467
+    $logo = vignette_logo_document($row, $connect);
468
+    if (!$logo) {
469
+        $logo = image_du_document($row, $connect);
470
+    }
471
+    if (!$logo) {
472
+        $f = charger_fonction('vignette', 'inc');
473
+        $logo = $f($row['extension'], false);
474
+    }
475
+    // si c'est une vignette type doc, la renvoyer direct
476
+    if (
477
+        strcmp($logo, _DIR_PLUGINS) == 0
478
+        or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
+        or strcmp($logo, _DIR_RACINE . 'prive/') == 0
480
+    ) {
481
+        return $logo;
482
+    }
483
+
484
+    return get_spip_doc($logo);
485 485
 }
486 486
 
487 487
 /**
@@ -509,20 +509,20 @@  discard block
 block discarded – undo
509 509
  */
510 510
 function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') {
511 511
 
512
-	include_spip('inc/documents');
513
-	$logo = '';
514
-	if (!in_array($mode_logo, ['icone', 'apercu'])) {
515
-		$logo = vignette_logo_document($row, $connect);
516
-	}
517
-	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
518
-	if ($mode_logo == 'vignette' and !$logo) {
519
-		return '';
520
-	}
521
-	if ($mode_logo == 'icone') {
522
-		$row['fichier'] = '';
523
-	}
524
-
525
-	return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
512
+    include_spip('inc/documents');
513
+    $logo = '';
514
+    if (!in_array($mode_logo, ['icone', 'apercu'])) {
515
+        $logo = vignette_logo_document($row, $connect);
516
+    }
517
+    // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
518
+    if ($mode_logo == 'vignette' and !$logo) {
519
+        return '';
520
+    }
521
+    if ($mode_logo == 'icone') {
522
+        $row['fichier'] = '';
523
+    }
524
+
525
+    return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
526 526
 }
527 527
 
528 528
 /**
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
  */
535 535
 function quete_html_logo($logo, $align, $lien) {
536 536
 
537
-	if (!is_array($logo)) {
538
-		return '';
539
-	}
540
-
541
-	$contexte = [];
542
-	foreach ($logo as $k => $v) {
543
-		if (!is_numeric($k)) {
544
-			$contexte[$k] = $v;
545
-		}
546
-	}
547
-	$contexte['align'] = $align;
548
-	$contexte['lien'] = $lien;
549
-	return recuperer_fond('modeles/logo', $contexte);
537
+    if (!is_array($logo)) {
538
+        return '';
539
+    }
540
+
541
+    $contexte = [];
542
+    foreach ($logo as $k => $v) {
543
+        if (!is_numeric($k)) {
544
+            $contexte[$k] = $v;
545
+        }
546
+    }
547
+    $contexte['align'] = $align;
548
+    $contexte['lien'] = $lien;
549
+    return recuperer_fond('modeles/logo', $contexte);
550 550
 }
551 551
 
552 552
 /**
@@ -560,14 +560,14 @@  discard block
 block discarded – undo
560 560
  * @return string|false
561 561
  */
562 562
 function document_spip_externe($fichier, $connect) {
563
-	if ($connect) {
564
-		$site = quete_meta('adresse_site', $connect);
565
-		if ($site) {
566
-			$dir = quete_meta('dir_img', $connect);
567
-			return "$site/$dir$fichier";
568
-		}
569
-	}
570
-	return false;
563
+    if ($connect) {
564
+        $site = quete_meta('adresse_site', $connect);
565
+        if ($site) {
566
+            $dir = quete_meta('dir_img', $connect);
567
+            return "$site/$dir$fichier";
568
+        }
569
+    }
570
+    return false;
571 571
 }
572 572
 
573 573
 /**
@@ -581,23 +581,23 @@  discard block
 block discarded – undo
581 581
  */
582 582
 function vignette_logo_document($row, string $connect = '') {
583 583
 
584
-	if (!$row or empty($row['id_vignette'])) {
585
-		return '';
586
-	}
587
-	$fichier = quete_fichier($row['id_vignette'], $connect);
588
-	if ($url = document_spip_externe($fichier, $connect)) {
589
-		return $url;
590
-	}
591
-
592
-	$f = get_spip_doc($fichier);
593
-	if ($f and @file_exists($f)) {
594
-		return $f;
595
-	}
596
-	if ($row['mode'] !== 'vignette') {
597
-		return '';
598
-	}
599
-
600
-	return generer_url_entite($row['id_document'], 'document', '', '', $connect);
584
+    if (!$row or empty($row['id_vignette'])) {
585
+        return '';
586
+    }
587
+    $fichier = quete_fichier($row['id_vignette'], $connect);
588
+    if ($url = document_spip_externe($fichier, $connect)) {
589
+        return $url;
590
+    }
591
+
592
+    $f = get_spip_doc($fichier);
593
+    if ($f and @file_exists($f)) {
594
+        return $f;
595
+    }
596
+    if ($row['mode'] !== 'vignette') {
597
+        return '';
598
+    }
599
+
600
+    return generer_url_entite($row['id_document'], 'document', '', '', $connect);
601 601
 }
602 602
 
603 603
 /**
@@ -613,66 +613,66 @@  discard block
 block discarded – undo
613 613
  * @return bool|string
614 614
  */
615 615
 function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') {
616
-	static $exposer = [];
617
-
618
-	// Que faut-il exposer ? Tous les elements de $reference
619
-	// ainsi que leur hierarchie ; on ne fait donc ce calcul
620
-	// qu'une fois (par squelette) et on conserve le resultat
621
-	// en static.
622
-	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
623
-		$principal = $reference[$type] ?? $reference["@$type"] ?? '';
624
-		// le parent fournit en argument est le parent de $id, pas celui de $principal
625
-		// il n'est donc pas utile
626
-		$parent = 0;
627
-		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
628
-			$enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
629
-			if (isset($enfants[$type])) {
630
-				foreach ($enfants[$type] as $t) {
631
-					if (
632
-						isset($reference[$t])
633
-						// cas de la reference donnee dynamiquement par la pagination
634
-						or isset($reference["@$t"])
635
-					) {
636
-						$type = $t;
637
-						$principal = $reference[$type] ?? $reference["@$type"];
638
-						continue;
639
-					}
640
-				}
641
-			}
642
-		}
643
-		$exposer[$m][$type] = [];
644
-		if ($principal) {
645
-			$principaux = is_array($principal) ? $principal : [$principal];
646
-			foreach ($principaux as $principal) {
647
-				$exposer[$m][$type][$principal] = true;
648
-				if ($type == 'id_mot') {
649
-					if (!$parent) {
650
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
651
-					}
652
-					if ($parent) {
653
-						$exposer[$m]['id_groupe'][$parent] = true;
654
-					}
655
-				} else {
656
-					if ($type != 'id_groupe') {
657
-						if (!$parent) {
658
-							if ($type == 'id_rubrique') {
659
-								$parent = $principal;
660
-							}
661
-							if ($type == 'id_article') {
662
-								$parent = quete_rubrique($principal, $connect);
663
-							}
664
-						}
665
-						do {
666
-							$exposer[$m]['id_rubrique'][$parent] = true;
667
-						} while ($parent = quete_parent($parent, $connect));
668
-					}
669
-				}
670
-			}
671
-		}
672
-	}
673
-
674
-	// And the winner is...
675
-	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
616
+    static $exposer = [];
617
+
618
+    // Que faut-il exposer ? Tous les elements de $reference
619
+    // ainsi que leur hierarchie ; on ne fait donc ce calcul
620
+    // qu'une fois (par squelette) et on conserve le resultat
621
+    // en static.
622
+    if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
623
+        $principal = $reference[$type] ?? $reference["@$type"] ?? '';
624
+        // le parent fournit en argument est le parent de $id, pas celui de $principal
625
+        // il n'est donc pas utile
626
+        $parent = 0;
627
+        if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
628
+            $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
629
+            if (isset($enfants[$type])) {
630
+                foreach ($enfants[$type] as $t) {
631
+                    if (
632
+                        isset($reference[$t])
633
+                        // cas de la reference donnee dynamiquement par la pagination
634
+                        or isset($reference["@$t"])
635
+                    ) {
636
+                        $type = $t;
637
+                        $principal = $reference[$type] ?? $reference["@$type"];
638
+                        continue;
639
+                    }
640
+                }
641
+            }
642
+        }
643
+        $exposer[$m][$type] = [];
644
+        if ($principal) {
645
+            $principaux = is_array($principal) ? $principal : [$principal];
646
+            foreach ($principaux as $principal) {
647
+                $exposer[$m][$type][$principal] = true;
648
+                if ($type == 'id_mot') {
649
+                    if (!$parent) {
650
+                        $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
651
+                    }
652
+                    if ($parent) {
653
+                        $exposer[$m]['id_groupe'][$parent] = true;
654
+                    }
655
+                } else {
656
+                    if ($type != 'id_groupe') {
657
+                        if (!$parent) {
658
+                            if ($type == 'id_rubrique') {
659
+                                $parent = $principal;
660
+                            }
661
+                            if ($type == 'id_article') {
662
+                                $parent = quete_rubrique($principal, $connect);
663
+                            }
664
+                        }
665
+                        do {
666
+                            $exposer[$m]['id_rubrique'][$parent] = true;
667
+                        } while ($parent = quete_parent($parent, $connect));
668
+                    }
669
+                }
670
+            }
671
+        }
672
+    }
673
+
674
+    // And the winner is...
675
+    return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
676 676
 }
677 677
 
678 678
 /**
@@ -687,23 +687,23 @@  discard block
 block discarded – undo
687 687
  * @return int
688 688
  */
689 689
 function quete_debut_pagination($primary, $valeur, $pas, $iter) {
690
-	// on ne devrait pas arriver ici si la cle primaire est inexistante
691
-	// ou composee, mais verifions
692
-	if (!$primary or preg_match('/[,\s]/', $primary)) {
693
-		return 0;
694
-	}
695
-
696
-	$pos = 0;
697
-	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
698
-		$pos++;
699
-	}
700
-	// si on a pas trouve
701
-	if (!$row or $row[$primary] != $valeur) {
702
-		return 0;
703
-	}
704
-
705
-	// sinon, calculer le bon numero de page
706
-	return floor($pos / $pas) * $pas;
690
+    // on ne devrait pas arriver ici si la cle primaire est inexistante
691
+    // ou composee, mais verifions
692
+    if (!$primary or preg_match('/[,\s]/', $primary)) {
693
+        return 0;
694
+    }
695
+
696
+    $pos = 0;
697
+    while ($row = $iter->fetch() and $row[$primary] != $valeur) {
698
+        $pos++;
699
+    }
700
+    // si on a pas trouve
701
+    if (!$row or $row[$primary] != $valeur) {
702
+        return 0;
703
+    }
704
+
705
+    // sinon, calculer le bon numero de page
706
+    return floor($pos / $pas) * $pas;
707 707
 }
708 708
 
709 709
 /**
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
  * @return boolean
715 715
  */
716 716
 function is_whereable($value): bool {
717
-	if (is_array($value) && count($value)) {
718
-		return true;
719
-	}
720
-	if (is_scalar($value) && strlen($value)) {
721
-		return true;
722
-	}
723
-	return false;
717
+    if (is_array($value) && count($value)) {
718
+        return true;
719
+    }
720
+    if (is_scalar($value) && strlen($value)) {
721
+        return true;
722
+    }
723
+    return false;
724 724
 }
Please login to merge, or discard this patch.