[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / public / boucles.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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 //
15 // Ce fichier definit les boucles standard de SPIP
16 //
17
18 if (!defined('_ECRIRE_INC_VERSION')) return;
19
20 //
21 // Boucle standard, sans condition rajoutee
22 //
23 // http://doc.spip.org/@boucle_DEFAUT_dist
24 function boucle_DEFAUT_dist($id_boucle, &$boucles) {
25 return calculer_boucle($id_boucle, $boucles);
26 }
27
28
29 //
30 // <BOUCLE(BOUCLE)> boucle dite recursive
31 //
32 // http://doc.spip.org/@boucle_BOUCLE_dist
33 function boucle_BOUCLE_dist($id_boucle, &$boucles) {
34
35 return calculer_boucle($id_boucle, $boucles);
36 }
37
38 //
39 // <BOUCLE(ARTICLES)>
40 //
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';
46
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\\''"));
53 } else
54 array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
55 }
56 return calculer_boucle($id_boucle, $boucles);
57 }
58
59 //
60 // <BOUCLE(AUTEURS)>
61 //
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';
67
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())"));
83 }
84 // pas d'auteurs poubellises
85 array_unshift($boucle->where,array("'!='", "'$mstatut'", "'\\'5poubelle\\''"));
86 }
87
88 return calculer_boucle($id_boucle, $boucles);
89 }
90
91 //
92 // <BOUCLE(BREVES)>
93 //
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';
99
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\\''"));
104 else
105 array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
106 }
107
108 return calculer_boucle($id_boucle, $boucles);
109 }
110
111
112 //
113 // <BOUCLE(FORUMS)>
114 //
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));
124 }
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\\')'"));
129 else
130 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
131 }
132
133 return calculer_boucle($id_boucle, $boucles);
134 }
135
136
137 //
138 // <BOUCLE(SIGNATURES)>
139 //
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';
145
146 // Restreindre aux elements publies
147 if (!isset($boucle->modificateur['criteres']['statut'])
148 AND !isset($boucle->modificateur['tout'])) {
149
150 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
151 }
152 return calculer_boucle($id_boucle, $boucles);
153 }
154
155
156 //
157 // <BOUCLE(DOCUMENTS)>
158 //
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;
163
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\\')'"));
167
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\\''"));
172 }
173
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'])
182 ) {
183 # Espace avant LEFT JOIN indispensable pour insertion de AS
184 # a refaire plus proprement
185
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\')
197 ";
198 $boucle->group[] = "$id_table.id_document";
199
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\'))'");
202 } else {
203 $postdates = ($GLOBALS['meta']['post_dates'] == 'non')
204 ? ' AND aa.date<=\'.sql_quote(quete_date_postdates()).\''
205 : '';
206 array_unshift($boucle->where,"'((aa.statut = \'publie\'$postdates) OR bb.statut = \'publie\' OR rr.statut = \'publie\' OR ff.statut=\'publie\')'");
207 }
208 }
209
210
211 return calculer_boucle($id_boucle, $boucles);
212 }
213
214 //
215 // <BOUCLE(RUBRIQUES)>
216 //
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';
222
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\\''"));
228 }
229
230 return calculer_boucle($id_boucle, $boucles);
231 }
232
233
234 //
235 // <BOUCLE(HIERARCHIE)>
236 //
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";
241
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)
244
245 $boucle->hierarchie = 'if (!($id_rubrique = intval('
246 . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles)
247 . ")))\n\t\treturn '';\n\t"
248 . '$hierarchie = '
249 . (isset($boucle->modificateur['tout']) ? '",$id_rubrique"' : "''")
250 . ";\n\t"
251 . 'while ($id_rubrique = sql_getfetsel("id_parent","spip_rubriques","id_rubrique=" . $id_rubrique,"","","", "", $connect)) {
252 $hierarchie = ",$id_rubrique$hierarchie";
253 }
254 if (!$hierarchie) return "";
255 $hierarchie = substr($hierarchie,1);';
256
257 $boucle->where[]= array("'IN'", "'$id_table'", '"($hierarchie)"');
258
259 $order = "FIELD($id_table, \$hierarchie)";
260 if (!isset($boucle->default_order[0]) OR $boucle->default_order[0] != " DESC")
261 $boucle->default_order[] = "\"$order\"";
262 else
263 $boucle->default_order[0] = "\"$order DESC\"";
264 return calculer_boucle($id_boucle, $boucles);
265 }
266
267
268 //
269 // <BOUCLE(SYNDICATION)>
270 //
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';
276
277 // Restreindre aux elements publies
278
279 if (!isset($boucle->modificateur['criteres']['statut'])) {
280 if (!$GLOBALS['var_preview']) {
281 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
282 } else
283 array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
284 }
285 return calculer_boucle($id_boucle, $boucles);
286 }
287
288 //
289 // <BOUCLE(SYNDIC_ARTICLES)>
290 //
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';
296
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\\')'"));
301 else {
302 $jointure = array_search("spip_syndic", $boucle->from);
303 if (!$jointure) {
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);
306 }
307 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
308 $boucle->where[]= array("'='", "'$jointure" . ".statut'", "'\\'publie\\''");
309
310 }
311 return calculer_boucle($id_boucle, $boucles);
312 }
313
314 ?>