PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/spip/ecrire/public/boucles.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 314 lines | 178 code | 49 blank | 87 comment | 33 complexity | 719bc7ee1b3ed780b672165b7657fad7 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. //
  12. // Ce fichier definit les boucles standard de SPIP
  13. //
  14. if (!defined('_ECRIRE_INC_VERSION')) return;
  15. //
  16. // Boucle standard, sans condition rajoutee
  17. //
  18. // http://doc.spip.org/@boucle_DEFAUT_dist
  19. function boucle_DEFAUT_dist($id_boucle, &$boucles) {
  20. return calculer_boucle($id_boucle, $boucles);
  21. }
  22. //
  23. // <BOUCLE(BOUCLE)> boucle dite recursive
  24. //
  25. // http://doc.spip.org/@boucle_BOUCLE_dist
  26. function boucle_BOUCLE_dist($id_boucle, &$boucles) {
  27. return calculer_boucle($id_boucle, $boucles);
  28. }
  29. //
  30. // <BOUCLE(ARTICLES)>
  31. //
  32. // http://doc.spip.org/@boucle_ARTICLES_dist
  33. function boucle_ARTICLES_dist($id_boucle, &$boucles) {
  34. $boucle = &$boucles[$id_boucle];
  35. $id_table = $boucle->id_table;
  36. $mstatut = $id_table .'.statut';
  37. // Restreindre aux elements publies
  38. if (!isset($boucle->modificateur['criteres']['statut'])) {
  39. if (!$GLOBALS['var_preview']) {
  40. if ($GLOBALS['meta']["post_dates"] == 'non')
  41. array_unshift($boucle->where,array("'<'", "'$id_table" . ".date'", "sql_quote(quete_date_postdates())"));
  42. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  43. } else
  44. array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
  45. }
  46. return calculer_boucle($id_boucle, $boucles);
  47. }
  48. //
  49. // <BOUCLE(AUTEURS)>
  50. //
  51. // http://doc.spip.org/@boucle_AUTEURS_dist
  52. function boucle_AUTEURS_dist($id_boucle, &$boucles) {
  53. $boucle = &$boucles[$id_boucle];
  54. $id_table = $boucle->id_table;
  55. $mstatut = $id_table .'.statut';
  56. // Restreindre aux elements publies
  57. if (!isset($boucle->modificateur['criteres']['statut'])) {
  58. // Si pas de lien avec un article, selectionner
  59. // uniquement les auteurs d'un article publie
  60. if (!$GLOBALS['var_preview'])
  61. if (!isset($boucle->modificateur['lien']) AND !isset($boucle->modificateur['tout'])) {
  62. fabrique_jointures($boucle, array(
  63. array($id_table, array('spip_auteurs_articles'), 'id_auteur'),
  64. array('', array('spip_articles'), 'id_article')), true, $boucle->show, $id_table);
  65. $t = array_search('spip_articles', $boucle->from);
  66. array_unshift($boucle->where,
  67. array("'='", "'$t.statut'", "'\\'publie\\''"));
  68. if ($GLOBALS['meta']['post_dates'] == 'non')
  69. array_unshift($boucle->where,
  70. array("'<='", "'$t.date'", "sql_quote(quete_date_postdates())"));
  71. }
  72. // pas d'auteurs poubellises
  73. array_unshift($boucle->where,array("'!='", "'$mstatut'", "'\\'5poubelle\\''"));
  74. }
  75. return calculer_boucle($id_boucle, $boucles);
  76. }
  77. //
  78. // <BOUCLE(BREVES)>
  79. //
  80. // http://doc.spip.org/@boucle_BREVES_dist
  81. function boucle_BREVES_dist($id_boucle, &$boucles) {
  82. $boucle = &$boucles[$id_boucle];
  83. $id_table = $boucle->id_table;
  84. $mstatut = $id_table .'.statut';
  85. // Restreindre aux elements publies
  86. if (!isset($boucle->modificateur['criteres']['statut'])) {
  87. if (!$GLOBALS['var_preview'])
  88. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  89. else
  90. array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
  91. }
  92. return calculer_boucle($id_boucle, $boucles);
  93. }
  94. //
  95. // <BOUCLE(FORUMS)>
  96. //
  97. // http://doc.spip.org/@boucle_FORUMS_dist
  98. function boucle_FORUMS_dist($id_boucle, &$boucles) {
  99. $boucle = &$boucles[$id_boucle];
  100. $id_table = $boucle->id_table;
  101. $mstatut = $id_table .'.statut';
  102. // Par defaut, selectionner uniquement les forums sans mere
  103. // Les criteres {tout} et {plat} inversent ce choix
  104. if (!isset($boucle->modificateur['tout']) AND !isset($boucle->modificateur['plat'])) {
  105. array_unshift($boucle->where,array("'='", "'$id_table." ."id_parent'", 0));
  106. }
  107. // Restreindre aux elements publies
  108. if (!$boucle->modificateur['criteres']['statut']) {
  109. if ($GLOBALS['var_preview'])
  110. array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prive\\')'"));
  111. else
  112. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  113. }
  114. return calculer_boucle($id_boucle, $boucles);
  115. }
  116. //
  117. // <BOUCLE(SIGNATURES)>
  118. //
  119. // http://doc.spip.org/@boucle_SIGNATURES_dist
  120. function boucle_SIGNATURES_dist($id_boucle, &$boucles) {
  121. $boucle = &$boucles[$id_boucle];
  122. $id_table = $boucle->id_table;
  123. $mstatut = $id_table .'.statut';
  124. // Restreindre aux elements publies
  125. if (!isset($boucle->modificateur['criteres']['statut'])
  126. AND !isset($boucle->modificateur['tout'])) {
  127. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  128. }
  129. return calculer_boucle($id_boucle, $boucles);
  130. }
  131. //
  132. // <BOUCLE(DOCUMENTS)>
  133. //
  134. // http://doc.spip.org/@boucle_DOCUMENTS_dist
  135. function boucle_DOCUMENTS_dist($id_boucle, &$boucles) {
  136. $boucle = &$boucles[$id_boucle];
  137. $id_table = $boucle->id_table;
  138. // on ne veut pas des fichiers de taille nulle,
  139. // sauf s'ils sont distants (taille inconnue)
  140. array_unshift($boucle->where,array("'($id_table.taille > 0 OR $id_table.distant=\\'oui\\')'"));
  141. // Supprimer les vignettes
  142. if (!isset($boucle->modificateur['criteres']['mode'])
  143. AND !isset($boucle->modificateur['criteres']['tout'])) {
  144. array_unshift($boucle->where,array("'!='", "'$id_table.mode'", "'\\'vignette\\''"));
  145. }
  146. // Pour une boucle generique (DOCUMENTS) sans critere de lien, verifier
  147. // qu notre document est lie a un element publie
  148. // (le critere {tout} permet de les afficher tous quand meme)
  149. // S'il y a un critere de lien {id_article} par exemple, on zappe
  150. // ces complications (et tant pis si la boucle n'a pas prevu de
  151. // verification du statut de l'article)
  152. if ((!isset($boucle->modificateur['tout']) OR !$boucle->modificateur['tout'])
  153. AND (!isset($boucle->modificateur['criteres']['id_objet']) OR !$boucle->modificateur['criteres']['id_objet'])
  154. ) {
  155. # Espace avant LEFT JOIN indispensable pour insertion de AS
  156. # a refaire plus proprement
  157. ## la boucle par defaut ignore les documents de forum
  158. $boucle->from[$id_table] = "spip_documents LEFT JOIN spip_documents_liens AS l
  159. ON $id_table.id_document=l.id_document
  160. LEFT JOIN spip_articles AS aa
  161. ON (l.id_objet=aa.id_article AND l.objet=\'article\')
  162. LEFT JOIN spip_breves AS bb
  163. ON (l.id_objet=bb.id_breve AND l.objet=\'breve\')
  164. LEFT JOIN spip_rubriques AS rr
  165. ON (l.id_objet=rr.id_rubrique AND l.objet=\'rubrique\')
  166. LEFT JOIN spip_forum AS ff
  167. ON (l.id_objet=ff.id_forum AND l.objet=\'forum\')
  168. ";
  169. $boucle->group[] = "$id_table.id_document";
  170. if ($GLOBALS['var_preview']) {
  171. 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\'))'");
  172. } else {
  173. $postdates = ($GLOBALS['meta']['post_dates'] == 'non')
  174. ? ' AND aa.date<=\'.sql_quote(quete_date_postdates()).\''
  175. : '';
  176. array_unshift($boucle->where,"'((aa.statut = \'publie\'$postdates) OR bb.statut = \'publie\' OR rr.statut = \'publie\' OR ff.statut=\'publie\')'");
  177. }
  178. }
  179. return calculer_boucle($id_boucle, $boucles);
  180. }
  181. //
  182. // <BOUCLE(RUBRIQUES)>
  183. //
  184. // http://doc.spip.org/@boucle_RUBRIQUES_dist
  185. function boucle_RUBRIQUES_dist($id_boucle, &$boucles) {
  186. $boucle = &$boucles[$id_boucle];
  187. $id_table = $boucle->id_table;
  188. $mstatut = $id_table .'.statut';
  189. // Restreindre aux elements publies
  190. if (!isset($boucle->modificateur['criteres']['statut'])) {
  191. if (!$GLOBALS['var_preview'])
  192. if (!isset($boucle->modificateur['tout']))
  193. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  194. }
  195. return calculer_boucle($id_boucle, $boucles);
  196. }
  197. //
  198. // <BOUCLE(HIERARCHIE)>
  199. //
  200. // http://doc.spip.org/@boucle_HIERARCHIE_dist
  201. function boucle_HIERARCHIE_dist($id_boucle, &$boucles) {
  202. $boucle = &$boucles[$id_boucle];
  203. $id_table = $boucle->id_table . ".id_rubrique";
  204. // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille
  205. // sauf en presence du critere {tout} (vu par phraser_html)
  206. $boucle->hierarchie = 'if (!($id_rubrique = intval('
  207. . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles)
  208. . ")))\n\t\treturn '';\n\t"
  209. . '$hierarchie = '
  210. . (isset($boucle->modificateur['tout']) ? '",$id_rubrique"' : "''")
  211. . ";\n\t"
  212. . 'while ($id_rubrique = sql_getfetsel("id_parent","spip_rubriques","id_rubrique=" . $id_rubrique,"","","", "", $connect)) {
  213. $hierarchie = ",$id_rubrique$hierarchie";
  214. }
  215. if (!$hierarchie) return "";
  216. $hierarchie = substr($hierarchie,1);';
  217. $boucle->where[]= array("'IN'", "'$id_table'", '"($hierarchie)"');
  218. $order = "FIELD($id_table, \$hierarchie)";
  219. if (!isset($boucle->default_order[0]) OR $boucle->default_order[0] != " DESC")
  220. $boucle->default_order[] = "\"$order\"";
  221. else
  222. $boucle->default_order[0] = "\"$order DESC\"";
  223. return calculer_boucle($id_boucle, $boucles);
  224. }
  225. //
  226. // <BOUCLE(SYNDICATION)>
  227. //
  228. // http://doc.spip.org/@boucle_SYNDICATION_dist
  229. function boucle_SYNDICATION_dist($id_boucle, &$boucles) {
  230. $boucle = &$boucles[$id_boucle];
  231. $id_table = $boucle->id_table;
  232. $mstatut = $id_table .'.statut';
  233. // Restreindre aux elements publies
  234. if (!isset($boucle->modificateur['criteres']['statut'])) {
  235. if (!$GLOBALS['var_preview']) {
  236. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  237. } else
  238. array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
  239. }
  240. return calculer_boucle($id_boucle, $boucles);
  241. }
  242. //
  243. // <BOUCLE(SYNDIC_ARTICLES)>
  244. //
  245. // http://doc.spip.org/@boucle_SYNDIC_ARTICLES_dist
  246. function boucle_SYNDIC_ARTICLES_dist($id_boucle, &$boucles) {
  247. $boucle = &$boucles[$id_boucle];
  248. $id_table = $boucle->id_table;
  249. $mstatut = $id_table .'.statut';
  250. // Restreindre aux elements publies, sauf critere contraire
  251. if (isset($boucle->modificateur['criteres']['statut']) AND $boucle->modificateur['criteres']['statut']) {}
  252. else if ($GLOBALS['var_preview'])
  253. array_unshift($boucle->where,array("'IN'", "'$mstatut'", "'(\\'publie\\',\\'prop\\')'"));
  254. else {
  255. $jointure = array_search("spip_syndic", $boucle->from);
  256. if (!$jointure) {
  257. fabrique_jointures($boucle, array(array($id_table, array('spip_syndic'), 'id_syndic')), true, $boucle->show, $id_table);
  258. $jointure = array_search('spip_syndic', $boucle->from);
  259. }
  260. array_unshift($boucle->where,array("'='", "'$mstatut'", "'\\'publie\\''"));
  261. $boucle->where[]= array("'='", "'$jointure" . ".statut'", "'\\'publie\\''");
  262. }
  263. return calculer_boucle($id_boucle, $boucles);
  264. }
  265. ?>