3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
15 // Ce fichier definit les boucles standard de SPIP
18 if (!defined('_ECRIRE_INC_VERSION')) return;
21 // Boucle standard, sans condition rajoutee
23 // http://doc.spip.org/@boucle_DEFAUT_dist
24 function boucle_DEFAUT_dist($id_boucle, &$boucles) {
25 return calculer_boucle($id_boucle, $boucles);
30 // <BOUCLE(BOUCLE)> boucle dite recursive
32 // http://doc.spip.org/@boucle_BOUCLE_dist
33 function boucle_BOUCLE_dist($id_boucle, &$boucles) {
35 return calculer_boucle($id_boucle, $boucles);
41 // http://doc.spip.org/@boucle_ARTICLES_dist
42 function boucle_ARTICLES_dist($id_boucle, &$boucles) {
43 $boucle = &$boucles[$id_boucle];
44 $id_table = $boucle->id_table
;
45 $mstatut = $id_table .'.statut';
47 // Restreindre aux elements publies
48 if (!isset($boucle->modificateur
['criteres']['statut'])) {
49 if (!$GLOBALS['var_preview']) {
50 if ($GLOBALS['meta']["post_dates"] == 'non')
51 array_unshift($boucle->where
,array("'<'", "'$id_table" . ".date'", "sql_quote(quete_date_postdates())"));
52 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
54 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
56 return calculer_boucle($id_boucle, $boucles);
62 // http://doc.spip.org/@boucle_AUTEURS_dist
63 function boucle_AUTEURS_dist($id_boucle, &$boucles) {
64 $boucle = &$boucles[$id_boucle];
65 $id_table = $boucle->id_table
;
66 $mstatut = $id_table .'.statut';
68 // Restreindre aux elements publies
69 if (!isset($boucle->modificateur
['criteres']['statut'])) {
70 // Si pas de lien avec un article, selectionner
71 // uniquement les auteurs d'un article publie
72 if (!$GLOBALS['var_preview'])
73 if (!isset($boucle->modificateur
['lien']) AND !isset($boucle->modificateur
['tout'])) {
74 $trouver_table = charger_fonction('trouver_table', 'base');
75 $def = $trouver_table('spip_auteurs_articles');
76 $def = array('spip_auteurs_articles', $def);
77 $def = array($id_table, $def, 'id_auteur');
78 $def2 = array('', array('spip_articles'), 'id_article');
79 fabrique_jointures($boucle, array($def, $def2), true, $boucle->show
, $id_table);
80 $t = array_search('spip_articles', $boucle->from
);
81 array_unshift($boucle->where
,
82 array("'='", "'$t.statut'", "'\\'publie\\''"));
83 if ($GLOBALS['meta']['post_dates'] == 'non')
84 array_unshift($boucle->where
,
85 array("'<='", "'$t.date'", "sql_quote(quete_date_postdates())"));
87 // pas d'auteurs poubellises
88 array_unshift($boucle->where
,array("'!='", "'$mstatut'", "'\\'5poubelle\\''"));
91 return calculer_boucle($id_boucle, $boucles);
97 // http://doc.spip.org/@boucle_BREVES_dist
98 function boucle_BREVES_dist($id_boucle, &$boucles) {
99 $boucle = &$boucles[$id_boucle];
100 $id_table = $boucle->id_table
;
101 $mstatut = $id_table .'.statut';
103 // Restreindre aux elements publies
104 if (!isset($boucle->modificateur
['criteres']['statut'])) {
105 if (!$GLOBALS['var_preview'])
106 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
108 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
111 return calculer_boucle($id_boucle, $boucles);
118 // http://doc.spip.org/@boucle_FORUMS_dist
119 function boucle_FORUMS_dist($id_boucle, &$boucles) {
120 $boucle = &$boucles[$id_boucle];
121 $id_table = $boucle->id_table
;
122 $mstatut = $id_table .'.statut';
123 // Par defaut, selectionner uniquement les forums sans mere
124 // Les criteres {tout} et {plat} inversent ce choix
125 if (!isset($boucle->modificateur
['tout']) AND !isset($boucle->modificateur
['plat'])) {
126 array_unshift($boucle->where
,array("'='", "'$id_table." ."id_parent'", 0));
128 // Restreindre aux elements publies
129 if (!$boucle->modificateur
['criteres']['statut']) {
130 if ($GLOBALS['var_preview'])
131 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prive\\')'"));
133 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
136 return calculer_boucle($id_boucle, $boucles);
141 // <BOUCLE(SIGNATURES)>
143 // http://doc.spip.org/@boucle_SIGNATURES_dist
144 function boucle_SIGNATURES_dist($id_boucle, &$boucles) {
145 $boucle = &$boucles[$id_boucle];
146 $id_table = $boucle->id_table
;
147 $mstatut = $id_table .'.statut';
149 // Restreindre aux elements publies
150 if (!isset($boucle->modificateur
['criteres']['statut'])
151 AND !isset($boucle->modificateur
['tout'])) {
153 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
155 return calculer_boucle($id_boucle, $boucles);
160 // <BOUCLE(DOCUMENTS)>
162 // http://doc.spip.org/@boucle_DOCUMENTS_dist
163 function boucle_DOCUMENTS_dist($id_boucle, &$boucles) {
164 $boucle = &$boucles[$id_boucle];
165 $id_table = $boucle->id_table
;
167 // on ne veut pas des fichiers de taille nulle,
168 // sauf s'ils sont distants (taille inconnue)
169 array_unshift($boucle->where
,array("'($id_table.taille > 0 OR $id_table.distant=\\'oui\\')'"));
171 // Supprimer les vignettes
172 if (!isset($boucle->modificateur
['criteres']['mode'])
173 AND !isset($boucle->modificateur
['criteres']['tout'])) {
174 array_unshift($boucle->where
,array("'!='", "'$id_table.mode'", "'\\'vignette\\''"));
177 // Pour une boucle generique (DOCUMENTS) sans critere de lien, verifier
178 // qu notre document est lie a un element publie
179 // (le critere {tout} permet de les afficher tous quand meme)
180 // S'il y a un critere de lien {id_article} par exemple, on zappe
181 // ces complications (et tant pis si la boucle n'a pas prevu de
182 // verification du statut de l'article)
183 if ((!isset($boucle->modificateur
['tout']) OR !$boucle->modificateur
['tout'])
184 AND (!isset($boucle->modificateur
['criteres']['id_objet']) OR !$boucle->modificateur
['criteres']['id_objet'])
186 # Espace avant LEFT JOIN indispensable pour insertion de AS
187 # a refaire plus proprement
189 ## la boucle par defaut ignore les documents de forum
190 $boucle->from
[$id_table] = "spip_documents LEFT JOIN spip_documents_liens AS l
191 ON $id_table.id_document=l.id_document
192 LEFT JOIN spip_articles AS aa
193 ON (l.id_objet=aa.id_article AND l.objet=\'article\')
194 LEFT JOIN spip_breves AS bb
195 ON (l.id_objet=bb.id_breve AND l.objet=\'breve\')
196 LEFT JOIN spip_rubriques AS rr
197 ON (l.id_objet=rr.id_rubrique AND l.objet=\'rubrique\')
198 LEFT JOIN spip_forum AS ff
199 ON (l.id_objet=ff.id_forum AND l.objet=\'forum\')
201 $boucle->group
[] = "$id_table.id_document";
203 if ($GLOBALS['var_preview']) {
204 array_unshift($boucle->where
,"'(aa.statut IN (\'publie\',\'prop\') OR bb.statut IN (\'publie\',\'prop\') OR rr.statut IN (\'publie\',\'prive\') OR ff.statut IN (\'publie\',\'prop\'))'");
206 $postdates = ($GLOBALS['meta']['post_dates'] == 'non')
207 ?
' AND aa.date<=\'.sql_quote(quete_date_postdates()).\''
209 array_unshift($boucle->where
,"'((aa.statut = \'publie\'$postdates) OR bb.statut = \'publie\' OR rr.statut = \'publie\' OR ff.statut=\'publie\')'");
214 return calculer_boucle($id_boucle, $boucles);
218 // <BOUCLE(RUBRIQUES)>
220 // http://doc.spip.org/@boucle_RUBRIQUES_dist
221 function boucle_RUBRIQUES_dist($id_boucle, &$boucles) {
222 $boucle = &$boucles[$id_boucle];
223 $id_table = $boucle->id_table
;
224 $mstatut = $id_table .'.statut';
226 // Restreindre aux elements publies
227 if (!isset($boucle->modificateur
['criteres']['statut'])) {
228 if (!$GLOBALS['var_preview'])
229 if (!isset($boucle->modificateur
['tout']))
230 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
233 return calculer_boucle($id_boucle, $boucles);
238 // <BOUCLE(HIERARCHIE)>
240 // http://doc.spip.org/@boucle_HIERARCHIE_dist
241 function boucle_HIERARCHIE_dist($id_boucle, &$boucles) {
242 $boucle = &$boucles[$id_boucle];
243 $id_table = $boucle->id_table
. ".id_rubrique";
245 // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille
246 // sauf en presence du critere {tout} (vu par phraser_html)
248 $boucle->hierarchie
= 'if (!($id_rubrique = intval('
249 . calculer_argument_precedent($boucle->id_boucle
, 'id_rubrique', $boucles)
250 . ")))\n\t\treturn '';\n\t"
252 . (isset($boucle->modificateur
['tout']) ?
'",$id_rubrique"' : "''")
254 . 'while ($id_rubrique = sql_getfetsel("id_parent","spip_rubriques","id_rubrique=" . $id_rubrique,"","","", "", $connect)) {
255 $hierarchie = ",$id_rubrique$hierarchie";
257 if (!$hierarchie) return "";
258 $hierarchie = substr($hierarchie,1);';
260 $boucle->where
[]= array("'IN'", "'$id_table'", '"($hierarchie)"');
262 $order = "FIELD($id_table, \$hierarchie)";
263 if (!isset($boucle->default_order
[0]) OR $boucle->default_order
[0] != " DESC")
264 $boucle->default_order
[] = "\"$order\"";
266 $boucle->default_order
[0] = "\"$order DESC\"";
267 return calculer_boucle($id_boucle, $boucles);
272 // <BOUCLE(SYNDICATION)>
274 // http://doc.spip.org/@boucle_SYNDICATION_dist
275 function boucle_SYNDICATION_dist($id_boucle, &$boucles) {
276 $boucle = &$boucles[$id_boucle];
277 $id_table = $boucle->id_table
;
278 $mstatut = $id_table .'.statut';
280 // Restreindre aux elements publies
282 if (!isset($boucle->modificateur
['criteres']['statut'])) {
283 if (!$GLOBALS['var_preview']) {
284 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
286 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
288 return calculer_boucle($id_boucle, $boucles);
292 // <BOUCLE(SYNDIC_ARTICLES)>
294 // http://doc.spip.org/@boucle_SYNDIC_ARTICLES_dist
295 function boucle_SYNDIC_ARTICLES_dist($id_boucle, &$boucles) {
296 $boucle = &$boucles[$id_boucle];
297 $id_table = $boucle->id_table
;
298 $mstatut = $id_table .'.statut';
300 // Restreindre aux elements publies, sauf critere contraire
301 if (isset($boucle->modificateur
['criteres']['statut']) AND $boucle->modificateur
['criteres']['statut']) {}
302 else if ($GLOBALS['var_preview'])
303 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
305 $jointure = array_search("spip_syndic", $boucle->from
);
307 $trouver_table = charger_fonction('trouver_table', 'base');
308 $def = $trouver_table('spip_syndic');
309 $def = array('spip_syndic', $def);
310 $def = array($id_table, $def, 'id_syndic');
311 fabrique_jointures($boucle, array($def), true, $boucle->show
, $id_table);
312 $jointure = array_search('spip_syndic', $boucle->from
);
314 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
315 $boucle->where
[]= array("'='", "'$jointure" . ".statut'", "'\\'publie\\''");
318 return calculer_boucle($id_boucle, $boucles);