3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
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 fabrique_jointures($boucle, array(
75 array($id_table, array('spip_auteurs_articles'), 'id_auteur'),
76 array('', array('spip_articles'), 'id_article')), true, $boucle->show
, $id_table);
77 $t = array_search('spip_articles', $boucle->from
);
78 array_unshift($boucle->where
,
79 array("'='", "'$t.statut'", "'\\'publie\\''"));
80 if ($GLOBALS['meta']['post_dates'] == 'non')
81 array_unshift($boucle->where
,
82 array("'<='", "'$t.date'", "sql_quote(quete_date_postdates())"));
84 // pas d'auteurs poubellises
85 array_unshift($boucle->where
,array("'!='", "'$mstatut'", "'\\'5poubelle\\''"));
88 return calculer_boucle($id_boucle, $boucles);
94 // http://doc.spip.org/@boucle_BREVES_dist
95 function boucle_BREVES_dist($id_boucle, &$boucles) {
96 $boucle = &$boucles[$id_boucle];
97 $id_table = $boucle->id_table
;
98 $mstatut = $id_table .'.statut';
100 // Restreindre aux elements publies
101 if (!isset($boucle->modificateur
['criteres']['statut'])) {
102 if (!$GLOBALS['var_preview'])
103 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
105 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
108 return calculer_boucle($id_boucle, $boucles);
115 // http://doc.spip.org/@boucle_FORUMS_dist
116 function boucle_FORUMS_dist($id_boucle, &$boucles) {
117 $boucle = &$boucles[$id_boucle];
118 $id_table = $boucle->id_table
;
119 $mstatut = $id_table .'.statut';
120 // Par defaut, selectionner uniquement les forums sans mere
121 // Les criteres {tout} et {plat} inversent ce choix
122 if (!isset($boucle->modificateur
['tout']) AND !isset($boucle->modificateur
['plat'])) {
123 array_unshift($boucle->where
,array("'='", "'$id_table." ."id_parent'", 0));
125 // Restreindre aux elements publies
126 if (!$boucle->modificateur
['criteres']['statut']) {
127 if ($GLOBALS['var_preview'])
128 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prive\\')'"));
130 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
133 return calculer_boucle($id_boucle, $boucles);
138 // <BOUCLE(SIGNATURES)>
140 // http://doc.spip.org/@boucle_SIGNATURES_dist
141 function boucle_SIGNATURES_dist($id_boucle, &$boucles) {
142 $boucle = &$boucles[$id_boucle];
143 $id_table = $boucle->id_table
;
144 $mstatut = $id_table .'.statut';
146 // Restreindre aux elements publies
147 if (!isset($boucle->modificateur
['criteres']['statut'])
148 AND !isset($boucle->modificateur
['tout'])) {
150 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
152 return calculer_boucle($id_boucle, $boucles);
157 // <BOUCLE(DOCUMENTS)>
159 // http://doc.spip.org/@boucle_DOCUMENTS_dist
160 function boucle_DOCUMENTS_dist($id_boucle, &$boucles) {
161 $boucle = &$boucles[$id_boucle];
162 $id_table = $boucle->id_table
;
164 // on ne veut pas des fichiers de taille nulle,
165 // sauf s'ils sont distants (taille inconnue)
166 array_unshift($boucle->where
,array("'($id_table.taille > 0 OR $id_table.distant=\\'oui\\')'"));
168 // Supprimer les vignettes
169 if (!isset($boucle->modificateur
['criteres']['mode'])
170 AND !isset($boucle->modificateur
['criteres']['tout'])) {
171 array_unshift($boucle->where
,array("'!='", "'$id_table.mode'", "'\\'vignette\\''"));
174 // Pour une boucle generique (DOCUMENTS) sans critere de lien, verifier
175 // qu notre document est lie a un element publie
176 // (le critere {tout} permet de les afficher tous quand meme)
177 // S'il y a un critere de lien {id_article} par exemple, on zappe
178 // ces complications (et tant pis si la boucle n'a pas prevu de
179 // verification du statut de l'article)
180 if ((!isset($boucle->modificateur
['tout']) OR !$boucle->modificateur
['tout'])
181 AND (!isset($boucle->modificateur
['criteres']['id_objet']) OR !$boucle->modificateur
['criteres']['id_objet'])
183 # Espace avant LEFT JOIN indispensable pour insertion de AS
184 # a refaire plus proprement
186 ## la boucle par defaut ignore les documents de forum
187 $boucle->from
[$id_table] = "spip_documents LEFT JOIN spip_documents_liens AS l
188 ON $id_table.id_document=l.id_document
189 LEFT JOIN spip_articles AS aa
190 ON (l.id_objet=aa.id_article AND l.objet=\'article\')
191 LEFT JOIN spip_breves AS bb
192 ON (l.id_objet=bb.id_breve AND l.objet=\'breve\')
193 LEFT JOIN spip_rubriques AS rr
194 ON (l.id_objet=rr.id_rubrique AND l.objet=\'rubrique\')
195 LEFT JOIN spip_forum AS ff
196 ON (l.id_objet=ff.id_forum AND l.objet=\'forum\')
198 $boucle->group
[] = "$id_table.id_document";
200 if ($GLOBALS['var_preview']) {
201 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\'))'");
203 $postdates = ($GLOBALS['meta']['post_dates'] == 'non')
204 ?
' AND aa.date<=\'.sql_quote(quete_date_postdates()).\''
206 array_unshift($boucle->where
,"'((aa.statut = \'publie\'$postdates) OR bb.statut = \'publie\' OR rr.statut = \'publie\' OR ff.statut=\'publie\')'");
211 return calculer_boucle($id_boucle, $boucles);
215 // <BOUCLE(RUBRIQUES)>
217 // http://doc.spip.org/@boucle_RUBRIQUES_dist
218 function boucle_RUBRIQUES_dist($id_boucle, &$boucles) {
219 $boucle = &$boucles[$id_boucle];
220 $id_table = $boucle->id_table
;
221 $mstatut = $id_table .'.statut';
223 // Restreindre aux elements publies
224 if (!isset($boucle->modificateur
['criteres']['statut'])) {
225 if (!$GLOBALS['var_preview'])
226 if (!isset($boucle->modificateur
['tout']))
227 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
230 return calculer_boucle($id_boucle, $boucles);
235 // <BOUCLE(HIERARCHIE)>
237 // http://doc.spip.org/@boucle_HIERARCHIE_dist
238 function boucle_HIERARCHIE_dist($id_boucle, &$boucles) {
239 $boucle = &$boucles[$id_boucle];
240 $id_table = $boucle->id_table
. ".id_rubrique";
242 // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille
243 // sauf en presence du critere {tout} (vu par phraser_html)
245 $boucle->hierarchie
= 'if (!($id_rubrique = intval('
246 . calculer_argument_precedent($boucle->id_boucle
, 'id_rubrique', $boucles)
247 . ")))\n\t\treturn '';\n\t"
249 . (isset($boucle->modificateur
['tout']) ?
'",$id_rubrique"' : "''")
251 . 'while ($id_rubrique = sql_getfetsel("id_parent","spip_rubriques","id_rubrique=" . $id_rubrique,"","","", "", $connect)) {
252 $hierarchie = ",$id_rubrique$hierarchie";
254 if (!$hierarchie) return "";
255 $hierarchie = substr($hierarchie,1);';
257 $boucle->where
[]= array("'IN'", "'$id_table'", '"($hierarchie)"');
259 $order = "FIELD($id_table, \$hierarchie)";
260 if (!isset($boucle->default_order
[0]) OR $boucle->default_order
[0] != " DESC")
261 $boucle->default_order
[] = "\"$order\"";
263 $boucle->default_order
[0] = "\"$order DESC\"";
264 return calculer_boucle($id_boucle, $boucles);
269 // <BOUCLE(SYNDICATION)>
271 // http://doc.spip.org/@boucle_SYNDICATION_dist
272 function boucle_SYNDICATION_dist($id_boucle, &$boucles) {
273 $boucle = &$boucles[$id_boucle];
274 $id_table = $boucle->id_table
;
275 $mstatut = $id_table .'.statut';
277 // Restreindre aux elements publies
279 if (!isset($boucle->modificateur
['criteres']['statut'])) {
280 if (!$GLOBALS['var_preview']) {
281 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
283 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
285 return calculer_boucle($id_boucle, $boucles);
289 // <BOUCLE(SYNDIC_ARTICLES)>
291 // http://doc.spip.org/@boucle_SYNDIC_ARTICLES_dist
292 function boucle_SYNDIC_ARTICLES_dist($id_boucle, &$boucles) {
293 $boucle = &$boucles[$id_boucle];
294 $id_table = $boucle->id_table
;
295 $mstatut = $id_table .'.statut';
297 // Restreindre aux elements publies, sauf critere contraire
298 if (isset($boucle->modificateur
['criteres']['statut']) AND $boucle->modificateur
['criteres']['statut']) {}
299 else if ($GLOBALS['var_preview'])
300 array_unshift($boucle->where
,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
302 $jointure = array_search("spip_syndic", $boucle->from
);
304 fabrique_jointures($boucle, array(array($id_table, array('spip_syndic'), 'id_syndic')), true, $boucle->show
, $id_table);
305 $jointure = array_search('spip_syndic', $boucle->from
);
307 array_unshift($boucle->where
,array("'='", "'$mstatut'", "'\\'publie\\''"));
308 $boucle->where
[]= array("'='", "'$jointure" . ".statut'", "'\\'publie\\''");
311 return calculer_boucle($id_boucle, $boucles);