Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
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 | global $table_des_tables; | |
26 | $boucle = &$boucles[$id_boucle]; | |
27 | $type = $boucle->type_requete; | |
28 | $id_table = $table_des_tables[$type]; | |
29 | if (!$id_table) | |
30 | // table hors SPIP | |
31 | $boucle->from[$type] = $type; | |
32 | else { | |
33 | // les tables declarees par spip ont un prefixe et un surnom | |
34 | $boucle->from[$id_table] = 'spip_' . $type ; | |
35 | } | |
36 | ||
37 | return calculer_boucle($id_boucle, $boucles); | |
38 | } | |
39 | ||
40 | ||
41 | // | |
42 | // <BOUCLE(BOUCLE)> boucle dite recursive | |
43 | // | |
44 | // http://doc.spip.org/@boucle_BOUCLE_dist | |
45 | function boucle_BOUCLE_dist($id_boucle, &$boucles) { | |
46 | ||
47 | return calculer_boucle($id_boucle, $boucles); | |
48 | } | |
49 | ||
50 | // | |
51 | // <BOUCLE(ARTICLES)> | |
52 | // | |
53 | // http://doc.spip.org/@boucle_ARTICLES_dist | |
54 | function boucle_ARTICLES_dist($id_boucle, &$boucles) { | |
55 | $boucle = &$boucles[$id_boucle]; | |
56 | $id_table = $boucle->id_table; | |
57 | $boucle->from[$id_table] = "spip_articles"; | |
58 | $mstatut = $id_table .'.statut'; | |
59 | ||
60 | // Restreindre aux elements publies | |
61 | if (!$boucle->modificateur['criteres']['statut']) { | |
62 | if (!$GLOBALS['var_preview']) { | |
63 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
64 | if ($GLOBALS['meta']["post_dates"] == 'non') | |
65 | $boucle->where[]= array("'<'", "'$id_table" . ".date'", "'NOW()'"); | |
66 | } else | |
67 | $boucle->where[]= array("'IN'", "'$mstatut'", "'(\"publie\",\"prop\")'"); | |
68 | } | |
69 | return calculer_boucle($id_boucle, $boucles); | |
70 | } | |
71 | ||
72 | // | |
73 | // <BOUCLE(AUTEURS)> | |
74 | // | |
75 | // http://doc.spip.org/@boucle_AUTEURS_dist | |
76 | function boucle_AUTEURS_dist($id_boucle, &$boucles) { | |
77 | $boucle = &$boucles[$id_boucle]; | |
78 | $id_table = $boucle->id_table; | |
79 | $boucle->from[$id_table] = "spip_auteurs"; | |
80 | $mstatut = $id_table .'.statut'; | |
81 | ||
82 | // Restreindre aux elements publies | |
83 | if (!$boucle->modificateur['criteres']['statut']) { | |
84 | // Si pas de lien avec un article, selectionner | |
85 | // uniquement les auteurs d'un article publie | |
86 | if (!$GLOBALS['var_preview']) | |
87 | if (!isset($boucle->modificateur['lien']) AND !isset($boucle->modificateur['tout'])) { | |
88 | $boucle->from["lien"] = "spip_auteurs_articles"; | |
89 | $boucle->from["articles"] = "spip_articles"; | |
90 | $boucle->where[]= array("'='", "'lien.id_auteur'", "'$id_table.id_auteur'"); | |
91 | $boucle->where[]= array("'='", "'lien.id_article'", "'articles.id_article'"); | |
92 | $boucle->where[]= array("'='", "'articles.statut'", "'\"publie\"'"); | |
93 | $boucle->group[] = $boucle->id_table . '.' . $boucle->primary; | |
94 | } | |
95 | // pas d'auteurs poubellises | |
96 | $boucle->where[]= array("'!='", "'$mstatut'", "'\"5poubelle\"'"); | |
97 | } | |
98 | ||
99 | return calculer_boucle($id_boucle, $boucles); | |
100 | } | |
101 | ||
102 | // | |
103 | // <BOUCLE(BREVES)> | |
104 | // | |
105 | // http://doc.spip.org/@boucle_BREVES_dist | |
106 | function boucle_BREVES_dist($id_boucle, &$boucles) { | |
107 | $boucle = &$boucles[$id_boucle]; | |
108 | $id_table = $boucle->id_table; | |
109 | $boucle->from[$id_table] = "spip_breves"; | |
110 | $mstatut = $id_table .'.statut'; | |
111 | ||
112 | // Restreindre aux elements publies | |
113 | if (!$boucle->modificateur['criteres']['statut']) { | |
114 | if (!$GLOBALS['var_preview']) | |
115 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
116 | else | |
117 | $boucle->where[]= array("'IN'", "'$mstatut'", "'(\"publie\",\"prop\")'"); | |
118 | } | |
119 | ||
120 | return calculer_boucle($id_boucle, $boucles); | |
121 | } | |
122 | ||
123 | ||
124 | // | |
125 | // <BOUCLE(FORUMS)> | |
126 | // | |
127 | // http://doc.spip.org/@boucle_FORUMS_dist | |
128 | function boucle_FORUMS_dist($id_boucle, &$boucles) { | |
129 | $boucle = &$boucles[$id_boucle]; | |
130 | $id_table = $boucle->id_table; | |
131 | $boucle->from[$id_table] = "spip_forum"; | |
132 | $mstatut = $id_table .'.statut'; | |
133 | ||
134 | // Par defaut, selectionner uniquement les forums sans mere | |
135 | // Les criteres {tout} et {plat} inversent ce choix | |
136 | if (!isset($boucle->modificateur['tout']) AND !isset($boucle->modificateur['plat'])) { | |
137 | $boucle->where[]= array("'='", "'$id_table." ."id_parent'", 0); | |
138 | } | |
139 | // Restreindre aux elements publies | |
140 | if (!$boucle->modificateur['criteres']['statut']) { | |
141 | if ($GLOBALS['var_preview']) | |
142 | $boucle->where[]= array("'IN'", "'$mstatut'", "'(\"publie\",\"prive\")'"); | |
143 | else | |
144 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
145 | } | |
146 | ||
147 | return calculer_boucle($id_boucle, $boucles); | |
148 | } | |
149 | ||
150 | ||
151 | // | |
152 | // <BOUCLE(SIGNATURES)> | |
153 | // | |
154 | // http://doc.spip.org/@boucle_SIGNATURES_dist | |
155 | function boucle_SIGNATURES_dist($id_boucle, &$boucles) { | |
156 | $boucle = &$boucles[$id_boucle]; | |
157 | $id_table = $boucle->id_table; | |
158 | $mstatut = $id_table .'.statut'; | |
159 | ||
160 | $boucle->from[$id_table] = "spip_signatures"; | |
161 | ||
162 | // Restreindre aux elements publies | |
163 | if (!$boucle->modificateur['criteres']['statut']) { | |
164 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
165 | } | |
166 | return calculer_boucle($id_boucle, $boucles); | |
167 | } | |
168 | ||
169 | ||
170 | // | |
171 | // <BOUCLE(DOCUMENTS)> | |
172 | // | |
173 | // http://doc.spip.org/@boucle_DOCUMENTS_dist | |
174 | function boucle_DOCUMENTS_dist($id_boucle, &$boucles) { | |
175 | $boucle = &$boucles[$id_boucle]; | |
176 | $id_table = $boucle->id_table; | |
177 | $boucle->from[$id_table] = "spip_documents"; | |
178 | // on ne veut pas des fichiers de taille nulle, | |
179 | // sauf s'ils sont distants (taille inconnue) | |
180 | $boucle->where[]= array("'($id_table.taille > 0 OR $id_table.distant=\"oui\")'"); | |
181 | ||
182 | return calculer_boucle($id_boucle, $boucles); | |
183 | } | |
184 | ||
185 | // | |
186 | // <BOUCLE(RUBRIQUES)> | |
187 | // | |
188 | // http://doc.spip.org/@boucle_RUBRIQUES_dist | |
189 | function boucle_RUBRIQUES_dist($id_boucle, &$boucles) { | |
190 | $boucle = &$boucles[$id_boucle]; | |
191 | $id_table = $boucle->id_table; | |
192 | $boucle->from[$id_table] = "spip_rubriques"; | |
193 | $mstatut = $id_table .'.statut'; | |
194 | ||
195 | // Restreindre aux elements publies | |
196 | if (!$boucle->modificateur['criteres']['statut']) { | |
197 | if (!$GLOBALS['var_preview']) | |
198 | if (!isset($boucle->modificateur['tout'])) | |
199 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
200 | } | |
201 | ||
202 | return calculer_boucle($id_boucle, $boucles); | |
203 | } | |
204 | ||
205 | ||
206 | // | |
207 | // <BOUCLE(HIERARCHIE)> | |
208 | // | |
209 | // http://doc.spip.org/@boucle_HIERARCHIE_dist | |
210 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { | |
211 | $boucle = &$boucles[$id_boucle]; | |
212 | $id_table = $boucle->id_table; | |
213 | $boucle->from[$id_table] = "spip_rubriques"; | |
214 | ||
215 | // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille | |
216 | // sauf en presence du critere {tout} (vu par phraser_html) | |
217 | ||
218 | $boucle->hierarchie = '$hierarchie = calculer_hierarchie(' | |
219 | . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) | |
220 | . ', ' | |
221 | . (isset($boucle->modificateur['tout']) ? 'false' : 'true') | |
222 | . ');'; | |
223 | ||
224 | $boucle->having[]= array("'<>'", "'rang'", 0); | |
225 | $boucle->select[]= "FIELD($id_table" . '.id_rubrique, $hierarchie) AS rang'; | |
226 | ||
227 | if ($boucle->default_order[0] != " DESC") | |
228 | $boucle->default_order[] = "'rang'" ; | |
229 | else | |
230 | $boucle->default_order[0] = "'rang DESC'" ; | |
231 | return calculer_boucle($id_boucle, $boucles); | |
232 | } | |
233 | ||
234 | ||
235 | // | |
236 | // <BOUCLE(SYNDICATION)> | |
237 | // | |
238 | // http://doc.spip.org/@boucle_SYNDICATION_dist | |
239 | function boucle_SYNDICATION_dist($id_boucle, &$boucles) { | |
240 | $boucle = &$boucles[$id_boucle]; | |
241 | $id_table = $boucle->id_table; | |
242 | $boucle->from[$id_table] = "spip_syndic"; | |
243 | $mstatut = $id_table .'.statut'; | |
244 | ||
245 | // Restreindre aux elements publies | |
246 | ||
247 | if (!$boucle->modificateur['criteres']['statut']) { | |
248 | if (!$GLOBALS['var_preview']) { | |
249 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
250 | } else | |
251 | $boucle->where[]= array("'IN'", "'$mstatut'", "'(\"publie\",\"prop\")'"); | |
252 | } | |
253 | return calculer_boucle($id_boucle, $boucles); | |
254 | } | |
255 | ||
256 | // | |
257 | // <BOUCLE(SYNDIC_ARTICLES)> | |
258 | // | |
259 | // http://doc.spip.org/@boucle_SYNDIC_ARTICLES_dist | |
260 | function boucle_SYNDIC_ARTICLES_dist($id_boucle, &$boucles) { | |
261 | $boucle = &$boucles[$id_boucle]; | |
262 | $id_table = $boucle->id_table; | |
263 | $boucle->from[$id_table] = "spip_syndic_articles" ; | |
264 | $mstatut = $id_table .'.statut'; | |
265 | ||
266 | // Restreindre aux elements publies, sauf critere contraire | |
267 | if ($boucle->modificateur['criteres']['statut']) {} | |
268 | else if ($GLOBALS['var_preview']) | |
269 | $boucle->where[]= array("'IN'", "'$mstatut'", "'(\"publie\",\"prop\")'"); | |
270 | else { | |
271 | $jointure = array_search("spip_syndic", $boucle->from); | |
272 | if (!$jointure) { | |
273 | $jointure = 'J' . count($boucle->from); | |
274 | $boucle->from[$jointure] = 'spip_syndic'; | |
275 | $boucle->where[]= array("'='", "'$id_table" .".id_syndic'", | |
276 | "\"$jointure" . '.id_syndic"'); | |
277 | } | |
278 | $boucle->where[]= array("'='", "'$mstatut'", "'\"publie\"'"); | |
279 | $boucle->where[]= array("'='", "'$jointure" . ".statut'", "'\"publie\"'"); | |
280 | ||
281 | } | |
282 | return calculer_boucle($id_boucle, $boucles); | |
283 | } | |
284 | ||
285 | ?> |