Completed
Push — master ( d8d4cc...6b056b )
by cam
07:55
created

quete.php ➔ quete_condition_statut()   F

Complexity

Conditions 22
Paths 393

Size

Total Lines 96
Code Lines 66

Duplication

Lines 7
Ratio 7.29 %

Importance

Changes 0
Metric Value
cc 22
eloc 66
nc 393
nop 5
dl 7
loc 96
rs 3.5977
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2017                                                *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
10
 *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11
\***************************************************************************/
12
13
/**
14
 * Fonctions d'appel aux serveurs SQL presentes dans le code compile
15
 *
16
 * NB : à l'exception des fonctions pour les balises dynamiques
17
 *
18
 * @package SPIP\Core\Compilateur\Quetes
19
 **/
20
21
if (!defined('_ECRIRE_INC_VERSION')) {
22
	return;
23
}
24
25
26
include_spip('base/abstract_sql');
27
28
/**
29
 * Retourne l'URL de redirection d'un article virtuel, seulement si il est publié
30
 *
31
 * @param $id_article
32
 * @param $connect
33
 * @return array|bool|null
34
 */
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
	);
46
}
47
48
/**
49
 * Retourne le couple `parent,lang` pour toute table
50
 *
51
 * En pratique `id_rubrique` si présent (ou `id_parent` pour table rubriques)
52
 * et champ `lang` si présent
53
 *
54
 * @param string $table
55
 * @param int $id
56
 * @param string $connect
57
 * @return array
58
 */
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;
92
}
93
94
95
/**
96
 * Retourne le parent d'une rubrique
97
 *
98
 * Repose sur la fonction quete_parent_lang pour la mutualisation
99
 * +mise en cache SQL des requêtes
100
 *
101
 * @uses quete_parent_lang()
102
 *
103
 * @param int $id_rubrique
104
 * @param string $connect
105
 * @return int
106
 */
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
113
	return $id_parent['id_parent'];
114
}
115
116
/**
117
 * Retourne la rubrique d'un article
118
 *
119
 * Repose sur la fonction quete_parent_lang pour la mutualisation
120
 * +mise en cache SQL des requêtes
121
 *
122
 * @uses quete_parent_lang()
123
 *
124
 * @param int $id_article
125
 * @param $serveur
126
 * @return int
127
 */
128
function quete_rubrique($id_article, $serveur) {
129
	$id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
130
131
	return $id_parent['id_rubrique'];
132
}
133
134
135
/**
136
 * Retourne la profondeur d'une rubrique
137
 *
138
 * @uses quete_parent()
139
 *
140
 * @param int $id
141
 * @param string $connect
142
 * @return int
143
 */
144
function quete_profondeur($id, $connect = '') {
145
	$n = 0;
146
	while ($id) {
147
		$n++;
148
		$id = quete_parent($id, $connect);
149
	}
150
151
	return $n;
152
}
153
154
155
/**
156
 * Retourne la condition sur la date lorsqu'il y a des post-dates
157
 *
158
 * @param string $champ_date
159
 *     Nom de la colonne de date dans la table SQL
160
 * @param string $serveur
161
 * @param bool $ignore_previsu
162
 *     true pour forcer le test même en prévisu
163
 * @return string
164
 *     Morceau de la requête SQL testant la date
165
 */
166
function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) {
167
	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
168
		return '1=1';
169
	}
170
171
	return
172
		(isset($GLOBALS['meta']['date_prochain_postdate'])
173
			and $GLOBALS['meta']['date_prochain_postdate'] > time())
174
			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
175
			: '1=1';
176
}
177
178
179
/**
180
 * Calculer la condition pour filtrer les status,
181
 *
182
 * @param string $mstatut
183
 *   Le champ de la table sur lequel porte la condition
184
 * @param string $previsu
185
 *   Mode previsu : statut ou liste des statuts séparés par une virgule
186
 * @param string $publie
187
 *   Mode publie : statut ou liste des statuts séparés par une virgule
188
 * @param string $serveur
189
 *   Serveur de BDD
190
 * @param bool $ignore_previsu
191
 *   true pour forcer le test même en prévisu
192
 * @return array
193
 */
194
function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) {
195
	static $cond = array();
196
	$key = func_get_args();
197
	$key = implode('-', $key);
198
	if (isset($cond[$key])) {
199
		return $cond[$key];
200
	}
201
202
	$liste_statuts = $publie;
203
	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
204
		$liste_statuts = $previsu;
205
	}
206
	$not = false;
207
	if (strncmp($liste_statuts, '!', 1) == 0) {
208
		$not = true;
209
		$liste_statuts = substr($liste_statuts, 1);
210
	}
211
	// '' => ne rien afficher, '!'=> ne rien filtrer
212
	if (!strlen($liste_statuts)) {
213
		return $cond[$key] = ($not ? '1=1' : "'0=1'");
214
	}
215
216
	$liste_statuts = explode(',', $liste_statuts);
217
	$where = array();
218
	foreach ($liste_statuts as $k => $v) {
219
		// filtrage /auteur pour limiter les objets d'un statut (prepa en general)
220
		// a ceux de l'auteur identifie
221
		if (strpos($v, '/') !== false) {
222
			$v = explode('/', $v);
223
			$filtre = end($v);
224
			$v = reset($v);
225
			$v = preg_replace(',\W,', '', $v);
226
			if ($filtre == 'auteur'
227
				and (strpos($mstatut, '.') !== false)
228
				and $objet = explode('.', $mstatut)
229
				and $id_table = reset($objet)
230
				and $objet = objet_type($id_table)
231
			) {
232
				$w = "$mstatut<>" . sql_quote($v);
233
234
				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
235
				// sinon l’auteur en session
236
				include_spip('inc/securiser_action');
237 View Code Duplication
				if ($desc = decrire_token_previsu()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
238
					$id_auteur = $desc['id_auteur'];
239
				} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
240
					$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
241
				} else {
242
					$id_auteur = null;
243
				}
244
245
				// dans ce cas (admin en general), pas de filtrage sur ce statut
246
				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
247
					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
248
					if (!$id_auteur) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id_auteur of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
249
						$where[] = $w;
250
					} else {
251
						$primary = id_table_objet($objet);
252
						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
253
								'ssss.id_objet',
254
								'spip_auteurs_liens AS ssss',
255
								'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
256
								'',
257
								'',
258
								'',
259
								'',
260
								$serveur
261
							) . '))';
262
					}
263
				}
264
			} // ignorer ce statut si on ne sait pas comment le filtrer
265
			else {
266
				$v = '';
267
			}
268
		}
269
		// securite
270
		$liste_statuts[$k] = preg_replace(',\W,', '', $v);
271
	}
272
	$liste_statuts = array_filter($liste_statuts);
273
	if (count($liste_statuts) == 1) {
274
		$where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur));
275
	} else {
276
		$where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
277
	}
278
279
	while (count($where) > 1) {
280
		$and = array('AND', array_pop($where), array_pop($where));
281
		$where[] = $and;
282
	}
283
	$cond[$key] = reset($where);
284
	if ($not) {
285
		$cond[$key] = array('NOT', $cond[$key]);
286
	}
287
288
	return $cond[$key];
289
}
290
291
/**
292
 * retourne le fichier d'un document
293
 *
294
 * http://code.spip.net/@quete_fichier
295
 *
296
 * @param int $id_document
297
 * @param string $serveur
298
 * @return array|bool|null
299
 */
300
function quete_fichier($id_document, $serveur = '') {
301
	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
302
}
303
304
/**
305
 * Toute les infos sur un document
306
 *
307
 * @param int $id_document
308
 * @param string $serveur
309
 * @return array|bool
310
 */
311
function quete_document($id_document, $serveur = '') {
312
	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
313
}
314
315
/**
316
 * recuperer une meta sur un site distant (en local il y a plus simple)
317
 *
318
 * http://code.spip.net/@quete_meta
319
 *
320
 * @param $nom
321
 * @param $serveur
322
 * @return array|bool|null
323
 */
324
function quete_meta($nom, $serveur) {
325
	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
326
}
327
328
/**
329
 * Retourne le logo d'un objet, éventuellement par héritage
330
 *
331
 * Si flag != false, retourne le chemin du fichier, sinon retourne un tableau
332
 * de 3 elements :
333
 * le chemin du fichier, celui du logo de survol, l'attribut style=w/h.
334
 *
335
 * @param string $cle_objet
336
 *     Nom de la clé de l'objet dont on veut chercher le logo.
337
 * @param string $onoff
338
 *     Sélectionne quel(s) logo(s) : "on" pour le logo normal, "off" pour le logo de survol, ou "ON" pour l'ensemble.
339
 * @param int $id
340
 *     Identifiant de l'objet dont on veut chercher le logo.
341
 * @param int $id_rubrique
342
 *     Identifiant de la rubrique parente si l'on veut aller chercher son logo
343
 *     dans le cas où l'objet demandé n'en a pas.
344
 * @param bool $flag
345
 *     Lorsque le drapeau est évalué comme "true", la fonction ne renvoie
346
 *     que le chemin du fichier, sinon elle renvoie le tableau plus complet.
347
 * @return array|string
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string|array.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
348
 *     Retourne soit un tableau, soit le chemin du fichier.
349
 */
350
function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) {
351
	include_spip('base/objets');
352
	$nom = strtolower($onoff);
353
354
	while (1) {
355
		$objet = objet_type($cle_objet);
356
357
		$on = quete_logo_objet($id, $objet, $nom);
358
359
		if ($on) {
360
			if ($flag) {
361
				return basename($on['chemin']);
362
			} else {
363
				$taille = @getimagesize($on['chemin']);
364
365
				// Si on a déjà demandé un survol directement ($onoff = off)
366
				// ou qu'on a demandé uniquement le normal ($onoff = on)
367
				// alors on ne cherche pas du tout le survol ici
368
				if ($onoff != 'ON') {
369
					$off = '';
370
				} else {
371
					// Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
372
					$off = quete_logo_objet($id, $objet, 'off');
373
				}
374
375
				// on retourne une url du type IMG/artonXX?timestamp
376
				// qui permet de distinguer le changement de logo
377
				// et placer un expire sur le dossier IMG/
378
				$res = array(
379
					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
380
					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
381
					(!$taille ? '' : (' ' . $taille[3]))
382
				);
383
				$res['src'] = $res[0];
384
				$res['logo_on'] = $res[0];
385
				$res['logo_off'] = $res[1];
386
				$res['width'] = ($taille ? $taille[0] : '');
387
				$res['height'] = ($taille ? $taille[1] : '');
388
389
				return $res;
390
			}
391
		} else {
392
			if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
393
				return '';
394
			} else {
395
				if ($id_rubrique) {
396
					$cle_objet = 'id_rubrique';
397
					$id = $id_rubrique;
398
					$id_rubrique = 0;
399
				} else {
400
					if ($id and $cle_objet == 'id_rubrique') {
401
						$id = quete_parent($id);
402
					} else {
403
						return '';
404
					}
405
				}
406
			}
407
		}
408
	}
409
}
410
411
/**
412
 * Chercher le logo d'un contenu précis
413
 *
414
 * @param int $id_objet
415
 * 		Idenfiant de l'objet dont on cherche le logo
416
 * @param string $objet
417
 * 		Type de l'objet dont on cherche le logo
418
 * @param string $mode
419
 * 		"on" ou "off" suivant le logo normal ou survol
420
 **/
421
function quete_logo_objet($id_objet, $objet, $mode) {
422
	static $chercher_logo;
423
	if (is_null($chercher_logo)) {
424
		$chercher_logo = charger_fonction('chercher_logo', 'inc');
425
	}
426
	$cle_objet = id_table_objet($objet);
427
428
	// On cherche pas la méthode classique
429
	$infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
430
	// Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
431
	if (!empty($infos_logo)) {
432
		$infos_logo = array(
433
			'chemin' => $infos_logo[0],
434
			'timestamp' => $infos_logo[4],
435
		);
436
	}
437
438
	// On passe cette recherche de logo dans un pipeline
439
	$infos_logo = pipeline(
440
		'quete_logo_objet',
441
		array(
442
			'args' => array(
443
				'id_objet' => $id_objet,
444
				'objet' => $objet,
445
				'cle_objet' => $cle_objet,
446
				'mode' => $mode,
447
			),
448
			'data' => $infos_logo,
449
		)
450
	);
451
452
	return $infos_logo;
453
}
454
455
/**
456
 * fonction appelee par la balise #LOGO_DOCUMENT
457
 *
458
 * http://code.spip.net/@calcule_logo_document
459
 *
460
 * @param array $row
461
 * @param string $connect
0 ignored issues
show
Documentation introduced by
Should the type for parameter $connect not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
462
 * @return bool|string
463
 */
464
function quete_logo_file($row, $connect = null) {
465
	include_spip('inc/documents');
466
	$logo = vignette_logo_document($row, $connect);
467
	if (!$logo) {
468
		$logo = image_du_document($row);
469
	}
470
	if (!$logo) {
471
		$f = charger_fonction('vignette', 'inc');
472
		$logo = $f($row['extension'], false);
473
	}
474
	// si c'est une vignette type doc, la renvoyer direct
475
	if (strcmp($logo, _DIR_PLUGINS) == 0
476
		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
477
		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
478
	) {
479
		return $logo;
480
	}
481
482
	return get_spip_doc($logo);
483
}
484
485
/**
486
 * Trouver l'image logo d'un document
487
 *
488
 * @param  $row
489
 *   description du document, issue de la base
490
 * @param  $lien
491
 *   url de lien
492
 * @param  $align
493
 *   alignement left/right
494
 * @param  $mode_logo
495
 *   mode du logo :
496
 *     '' => automatique (vignette sinon apercu sinon icone)
497
 *     icone => icone du type du fichier
498
 *     apercu => apercu de l'image exclusivement, meme si une vignette existe
499
 *     vignette => vignette exclusivement, ou rien si elle n'existe pas
500
 * @param  $x
501
 *   largeur maxi
502
 * @param  $y
503
 *   hauteur maxi
504
 * @param string $connect
0 ignored issues
show
Documentation introduced by
Should the type for parameter $connect not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
505
 *   serveur
506
 * @return string
507
 */
508
function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) {
509
	include_spip('inc/documents');
510
	$logo = '';
511
	if (!in_array($mode_logo, array('icone', 'apercu'))) {
512
		$logo = vignette_logo_document($row, $connect);
513
	}
514
	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
515
	if ($mode_logo == 'vignette' and !$logo) {
516
		return '';
517
	}
518
	if ($mode_logo == 'icone') {
519
		$row['fichier'] = '';
520
	}
521
522
	return vignette_automatique($logo, $row, $lien, $x, $y, $align);
523
}
524
525
/**
526
 * Retourne la vignette explicitement attachee a un document
527
 * le resutat est un fichier local existant, ou une URL
528
 * ou vide si pas de vignette
529
 *
530
 * @param array $row
531
 * @param string $connect
532
 * @return string
533
 */
534
function vignette_logo_document($row, $connect = '') {
535
	if (!$row['id_vignette']) {
536
		return '';
537
	}
538
	$fichier = quete_fichier($row['id_vignette'], $connect);
539
	if ($connect) {
540
		$site = quete_meta('adresse_site', $connect);
541
		$dir = quete_meta('dir_img', $connect);
542
543
		return "$site/$dir$fichier";
544
	}
545
	$f = get_spip_doc($fichier);
546
	if ($f and @file_exists($f)) {
547
		return $f;
548
	}
549
	if ($row['mode'] !== 'vignette') {
550
		return '';
551
	}
552
553
	return generer_url_entite($row['id_document'], 'document', '', '', $connect);
554
}
555
556
/**
557
 * Calcul pour savoir si un objet est expose dans le contexte
558
 * fournit par $reference
559
 *
560
 * @param int $id
561
 * @param string $prim
562
 * @param array $reference
563
 * @param int $parent
564
 * @param string $type
565
 * @param string $connect
566
 * @return bool|string
567
 */
568
function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $parent is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
569
	static $exposer = array();
570
571
	// Que faut-il exposer ? Tous les elements de $reference
572
	// ainsi que leur hierarchie ; on ne fait donc ce calcul
573
	// qu'une fois (par squelette) et on conserve le resultat
574
	// en static.
575
	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
576
		$principal = isset($reference[$type]) ? $reference[$type] :
577
			// cas de la pagination indecte @xx qui positionne la page avec l'id xx
578
			// et donne la reference dynamique @type=xx dans le contexte
579
			(isset($reference["@$type"]) ? $reference["@$type"] : '');
580
		// le parent fournit en argument est le parent de $id, pas celui de $principal
581
		// il n'est donc pas utile
582
		$parent = 0;
583
		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
584
			$enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot'));
585
			if (isset($enfants[$type])) {
586
				foreach ($enfants[$type] as $t) {
587
					if (isset($reference[$t])
588
						// cas de la reference donnee dynamiquement par la pagination
589
						or isset($reference["@$t"])
590
					) {
591
						$type = $t;
592
						$principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
593
						continue;
594
					}
595
				}
596
			}
597
		}
598
		$exposer[$m][$type] = array();
599
		if ($principal) {
600
			$principaux = is_array($principal) ? $principal : array($principal);
601
			foreach ($principaux as $principal) {
602
				$exposer[$m][$type][$principal] = true;
603
				if ($type == 'id_mot') {
604
					if (!$parent) {
605
						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
606
					}
607
					if ($parent) {
608
						$exposer[$m]['id_groupe'][$parent] = true;
609
					}
610
				} else {
611
					if ($type != 'id_groupe') {
612
						if (!$parent) {
613
							if ($type == 'id_rubrique') {
614
								$parent = $principal;
615
							}
616
							if ($type == 'id_article') {
617
								$parent = quete_rubrique($principal, $connect);
618
							}
619
						}
620
						do {
621
							$exposer[$m]['id_rubrique'][$parent] = true;
622
						} while ($parent = quete_parent($parent, $connect));
623
					}
624
				}
625
			}
626
		}
627
	}
628
629
	// And the winner is...
630
	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
631
}
632
633
/**
634
 * Trouver le numero de page d'une pagination indirecte
635
 * lorsque debut_xxx=@123
636
 * on cherche la page qui contient l'item dont la cle primaire vaut 123
637
 *
638
 * @param string $primary
639
 * @param int|string $valeur
640
 * @param int $pas
641
 * @param objetc $iter
642
 * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
643
 */
644
function quete_debut_pagination($primary, $valeur, $pas, $iter) {
645
	// on ne devrait pas arriver ici si la cle primaire est inexistante
646
	// ou composee, mais verifions
647
	if (!$primary or preg_match('/[,\s]/', $primary)) {
648
		return 0;
649
	}
650
651
	$pos = 0;
652
	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
653
		$pos++;
654
	}
655
	// si on a pas trouve
656
	if ($row[$primary] != $valeur) {
657
		return 0;
658
	}
659
660
	// sinon, calculer le bon numero de page
661
	return floor($pos / $pas) * $pas;
662
}
663