[SPIP] ~2.1.12 -->2.1.25
[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-2014 *
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 $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())"));
86 }
87 // pas d'auteurs poubellises
88 array_unshift($boucle->where,array("'!='", "'$mstatut'", "'\\'5poubelle\\''"));
89 }
90
91 return calculer_boucle($id_boucle, $boucles);
92 }
93
94 //
95 // <BOUCLE(BREVES)>
96 //
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';
102
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\\''"));
107 else
108 array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
109 }
110
111 return calculer_boucle($id_boucle, $boucles);
112 }
113
114
115 //
116 // <BOUCLE(FORUMS)>
117 //
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));
127 }
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\\')'"));
132 else
133 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
134 }
135
136 return calculer_boucle($id_boucle, $boucles);
137 }
138
139
140 //
141 // <BOUCLE(SIGNATURES)>
142 //
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';
148
149 // Restreindre aux elements publies
150 if (!isset($boucle->modificateur['criteres']['statut'])
151 AND !isset($boucle->modificateur['tout'])) {
152
153 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
154 }
155 return calculer_boucle($id_boucle, $boucles);
156 }
157
158
159 //
160 // <BOUCLE(DOCUMENTS)>
161 //
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;
166
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\\')'"));
170
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\\''"));
175 }
176
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'])
185 ) {
186 # Espace avant LEFT JOIN indispensable pour insertion de AS
187 # a refaire plus proprement
188
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\')
200 ";
201 $boucle->group[] = "$id_table.id_document";
202
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\'))'");
205 } else {
206 $postdates = ($GLOBALS['meta']['post_dates'] == 'non')
207 ? ' AND aa.date<=\'.sql_quote(quete_date_postdates()).\''
208 : '';
209 array_unshift($boucle->where,"'((aa.statut = \'publie\'$postdates) OR bb.statut = \'publie\' OR rr.statut = \'publie\' OR ff.statut=\'publie\')'");
210 }
211 }
212
213
214 return calculer_boucle($id_boucle, $boucles);
215 }
216
217 //
218 // <BOUCLE(RUBRIQUES)>
219 //
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';
225
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\\''"));
231 }
232
233 return calculer_boucle($id_boucle, $boucles);
234 }
235
236
237 //
238 // <BOUCLE(HIERARCHIE)>
239 //
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";
244
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)
247
248 $boucle->hierarchie = 'if (!($id_rubrique = intval('
249 . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles)
250 . ")))\n\t\treturn '';\n\t"
251 . '$hierarchie = '
252 . (isset($boucle->modificateur['tout']) ? '",$id_rubrique"' : "''")
253 . ";\n\t"
254 . 'while ($id_rubrique = sql_getfetsel("id_parent","spip_rubriques","id_rubrique=" . $id_rubrique,"","","", "", $connect)) {
255 $hierarchie = ",$id_rubrique$hierarchie";
256 }
257 if (!$hierarchie) return "";
258 $hierarchie = substr($hierarchie,1);';
259
260 $boucle->where[]= array("'IN'", "'$id_table'", '"($hierarchie)"');
261
262 $order = "FIELD($id_table, \$hierarchie)";
263 if (!isset($boucle->default_order[0]) OR $boucle->default_order[0] != " DESC")
264 $boucle->default_order[] = "\"$order\"";
265 else
266 $boucle->default_order[0] = "\"$order DESC\"";
267 return calculer_boucle($id_boucle, $boucles);
268 }
269
270
271 //
272 // <BOUCLE(SYNDICATION)>
273 //
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';
279
280 // Restreindre aux elements publies
281
282 if (!isset($boucle->modificateur['criteres']['statut'])) {
283 if (!$GLOBALS['var_preview']) {
284 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
285 } else
286 array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
287 }
288 return calculer_boucle($id_boucle, $boucles);
289 }
290
291 //
292 // <BOUCLE(SYNDIC_ARTICLES)>
293 //
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';
299
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\\')'"));
304 else {
305 $jointure = array_search("spip_syndic", $boucle->from);
306 if (!$jointure) {
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);
313 }
314 array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
315 $boucle->where[]= array("'='", "'$jointure" . ".statut'", "'\\'publie\\''");
316
317 }
318 return calculer_boucle($id_boucle, $boucles);
319 }
320
321 ?>