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