PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins-dist/breves/breves_pipelines.php

https://bitbucket.org/re_al_/real.test.spip
PHP | 350 lines | 190 code | 44 blank | 116 comment | 34 complexity | c234aefc93b1c623f82c83ce371fd010 MD5 | raw file
Possible License(s): LGPL-2.1, MIT
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2016 *
  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. * Utilisations de pipelines
  13. *
  14. * @package SPIP\Breves\Pipelines
  15. **/
  16. if (!defined('_ECRIRE_INC_VERSION')) {
  17. return;
  18. }
  19. /**
  20. * Définir les meta de configuration liées aux brèves
  21. *
  22. * @pipeline configurer_liste_metas
  23. * @param array $metas
  24. * Couples nom de la méta => valeur par défaut
  25. * @return array
  26. * Couples nom de la méta => valeur par défaut
  27. */
  28. function breves_configurer_liste_metas($metas) {
  29. $metas['activer_breves'] = 'non';
  30. return $metas;
  31. }
  32. /**
  33. * Ajouter les brèves à valider sur les rubriques
  34. *
  35. * @pipeline rubrique_encours
  36. *
  37. * @param array $flux Données du pipeline
  38. * @return array Données du pipeline
  39. **/
  40. function breves_rubrique_encours($flux) {
  41. if ($flux['args']['type'] == 'rubrique') {
  42. $lister_objets = charger_fonction('lister_objets', 'inc');
  43. $id_rubrique = $flux['args']['id_objet'];
  44. //
  45. // Les breves a valider
  46. //
  47. $flux['data'] .= $lister_objets('breves', array(
  48. 'titre' => _T('breves:info_breves_valider'),
  49. 'statut' => array('prepa', 'prop'),
  50. 'id_rubrique' => $id_rubrique,
  51. 'par' => 'date_heure'
  52. ));
  53. }
  54. return $flux;
  55. }
  56. /**
  57. * Ajouter les brèves référencées sur les vues de rubriques
  58. *
  59. * @pipeline affiche_enfants
  60. *
  61. * @param array $flux Données du pipeline
  62. * @return array Données du pipeline
  63. **/
  64. function breves_affiche_enfants($flux) {
  65. if (isset($flux['args']['exec'])
  66. and $e = trouver_objet_exec($flux['args']['exec'])
  67. and $e['type'] == 'rubrique'
  68. and $e['edition'] == false
  69. ) {
  70. $id_rubrique = $flux['args']['id_rubrique'];
  71. if ($GLOBALS['meta']['activer_breves'] == 'oui') {
  72. $lister_objets = charger_fonction('lister_objets', 'inc');
  73. $bouton_breves = '';
  74. $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . $id_rubrique);
  75. if (autoriser('creerbrevedans', 'rubrique', $id_rubrique, null, array('id_parent' => $id_parent))) {
  76. $bouton_breves .= icone_verticale(
  77. _T('breves:icone_nouvelle_breve'),
  78. generer_url_ecrire('breve_edit', "id_rubrique=$id_rubrique&new=oui"),
  79. 'breve-24.png',
  80. 'new',
  81. 'right'
  82. )
  83. . "<br class='nettoyeur' />";
  84. }
  85. $flux['data'] .= $lister_objets('breves', array(
  86. 'titre' => _T('breves:icone_ecrire_nouvel_article'),
  87. 'where' => "statut != 'prop' AND statut != 'prepa'",
  88. 'id_rubrique' => $id_rubrique,
  89. 'par' => 'date_heure'
  90. ));
  91. $flux['data'] .= $bouton_breves;
  92. }
  93. }
  94. return $flux;
  95. }
  96. /**
  97. * Ajoute le nombre de brèves sur l'accueil privé
  98. *
  99. * @pipeline accueil_informations
  100. *
  101. * @param string $texte
  102. * HTML des informations générales concernant chaque type d'objet
  103. * sur la page d'accueil privée
  104. * @return string
  105. * HTML des informations générales concernant chaque type d'objet
  106. * sur la page d'accueil privée
  107. */
  108. function breves_accueil_informations($texte) {
  109. include_spip('base/abstract_sql');
  110. $q = sql_select('COUNT(*) AS cnt, statut', 'spip_breves', '', 'statut', '', '', 'COUNT(*)<>0');
  111. $cpt = array();
  112. $cpt2 = array();
  113. $where = false;
  114. if ($GLOBALS['visiteur_session']['statut'] == '0minirezo') {
  115. $where = sql_allfetsel(
  116. 'id_objet',
  117. 'spip_auteurs_liens',
  118. "objet='rubrique' AND id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur'])
  119. );
  120. if ($where) {
  121. $where = sql_in('id_rubrique', array_map('reset', $where));
  122. }
  123. }
  124. $defaut = $where ? '0/' : '';
  125. while ($row = sql_fetch($q)) {
  126. $cpt[$row['statut']] = $row['cnt'];
  127. $cpt2[$row['statut']] = $defaut;
  128. }
  129. if ($cpt) {
  130. if ($where) {
  131. $q = sql_select('COUNT(*) AS cnt, statut', 'spip_breves', $where, 'statut');
  132. while ($row = sql_fetch($q)) {
  133. $r = $row['statut'];
  134. $cpt2[$r] = intval($row['cnt']) . '/';
  135. }
  136. }
  137. $texte .= "<div class='accueil_informations breves liste'>";
  138. $texte .= '<h4>' . afficher_plus_info(generer_url_ecrire('breves'), '', _T('breves:info_breves_02')) . '</h4>';
  139. $texte .= "<ul class='liste-items'>";
  140. if (isset($cpt['prop'])) {
  141. $texte .= "<li class='item'>" . _T('texte_statut_attente_validation') . ': ' . $cpt2['prop'] . $cpt['prop'] . '</li>';
  142. }
  143. if (isset($cpt['publie'])) {
  144. $texte .= "<li class='item on'>" . _T('texte_statut_publies') . ': ' . $cpt2['publie'] . $cpt['publie'] . '</li>';
  145. }
  146. $texte .= '</ul>';
  147. $texte .= '</div>';
  148. }
  149. return $texte;
  150. }
  151. /**
  152. * Compter les brèves dans une rubrique
  153. *
  154. * @pipeline objet_compte_enfants
  155. *
  156. * @param array $flux Données du pipeline
  157. * @return array Données du pipeline
  158. */
  159. function breves_objet_compte_enfants($flux) {
  160. if ($flux['args']['objet'] == 'rubrique'
  161. and $id_rubrique = intval($flux['args']['id_objet'])
  162. ) {
  163. // juste les publies ?
  164. if (array_key_exists('statut', $flux['args']) and ($flux['args']['statut'] == 'publie')) {
  165. $flux['data']['breve'] = sql_countsel(
  166. 'spip_breves',
  167. 'id_rubrique=' . intval($id_rubrique) . " AND (statut='publie')"
  168. );
  169. } else {
  170. $flux['data']['breve'] = sql_countsel(
  171. 'spip_breves',
  172. 'id_rubrique=' . intval($id_rubrique) . " AND (statut='publie' OR statut='prop')"
  173. );
  174. }
  175. }
  176. return $flux;
  177. }
  178. /**
  179. * Changer la langue des brèves si la rubrique change
  180. *
  181. * @pipeline trig_calculer_langues_rubriques
  182. *
  183. * @param array $flux Données du pipeline
  184. * @return array Données du pipeline
  185. */
  186. function breves_trig_calculer_langues_rubriques($flux) {
  187. $s = sql_select(
  188. 'A.id_breve AS id_breve, R.lang AS lang',
  189. 'spip_breves AS A, spip_rubriques AS R',
  190. "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (A.lang='' OR R.lang<>'') AND R.lang<>A.lang"
  191. );
  192. while ($row = sql_fetch($s)) {
  193. $id_breve = $row['id_breve'];
  194. sql_updateq(
  195. 'spip_breves',
  196. array('lang' => $row['lang'], 'langue_choisie' => 'non'),
  197. 'id_breve='.intval($id_breve)
  198. );
  199. }
  200. return $flux;
  201. }
  202. /**
  203. * Publier et dater les rubriques qui ont une brève publiée
  204. *
  205. * @pipeline calculer_rubriques
  206. *
  207. * @param array $flux Données du pipeline
  208. * @return array Données du pipeline
  209. */
  210. function breves_calculer_rubriques($flux) {
  211. $r = sql_select(
  212. 'R.id_rubrique AS id, max(A.date_heure) AS date_h',
  213. 'spip_rubriques AS R JOIN spip_breves AS A ON R.id_rubrique = A.id_rubrique',
  214. "A.date_heure>R.date_tmp AND A.statut='publie' ",
  215. 'R.id_rubrique'
  216. );
  217. while ($row = sql_fetch($r)) {
  218. sql_updateq(
  219. 'spip_rubriques',
  220. array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
  221. 'id_rubrique=' . intval($row['id'])
  222. );
  223. }
  224. return $flux;
  225. }
  226. /**
  227. * Ajouter les brèves à valider sur la page d'accueil
  228. *
  229. * @pipeline accueil_encours
  230. *
  231. * @param string $flux HTML du bloc encours sur la page d'accueil privée
  232. * @return string HTML du bloc encours sur la page d'accueil privée
  233. **/
  234. function breves_accueil_encours($flux) {
  235. $lister_objets = charger_fonction('lister_objets', 'inc');
  236. $flux .= $lister_objets('breves', array(
  237. 'titre' => afficher_plus_info(generer_url_ecrire('breves')) . _T('breves:info_breves_valider'),
  238. 'statut' => array('prepa', 'prop'),
  239. 'par' => 'date_heure'
  240. ));
  241. return $flux;
  242. }
  243. /**
  244. * Optimiser la base de données en supprimant les liens de brèves orphelins
  245. *
  246. * @pipeline optimiser_base_disparus
  247. *
  248. * @param array $flux Données du pipeline
  249. * @return array Données du pipeline
  250. */
  251. function breves_optimiser_base_disparus($flux) {
  252. $n = &$flux['data'];
  253. $mydate = $flux['args']['date'];
  254. # les breves qui sont dans une id_rubrique inexistante
  255. $res = sql_select(
  256. 'B.id_breve AS id',
  257. 'spip_breves AS B
  258. LEFT JOIN spip_rubriques AS R
  259. ON B.id_rubrique=R.id_rubrique',
  260. 'R.id_rubrique IS NULL
  261. AND B.maj < ' . sql_quote($mydate)
  262. );
  263. $n += optimiser_sansref('spip_breves', 'id_breve', $res);
  264. //
  265. // Breves
  266. //
  267. sql_delete('spip_breves', "statut='refuse' AND maj < $mydate");
  268. return $flux;
  269. }
  270. /**
  271. * Afficher le nombre de brèves dans chaque rubrique
  272. *
  273. * @pipeline boite_infos
  274. *
  275. * @param array $flux Données du pipeline
  276. * @return array Données du pipeline
  277. */
  278. function breves_boite_infos($flux) {
  279. if (
  280. isset($flux['args']['type']) and $flux['args']['type'] == 'rubrique'
  281. and isset($flux['args']['id']) and $id_rubrique = $flux['args']['id']
  282. ) {
  283. if ($nb = sql_countsel('spip_breves', "statut='publie' AND id_rubrique=" . intval($id_rubrique))) {
  284. $nb = '<div>' . singulier_ou_pluriel($nb, 'breves:info_1_breve', 'breves:info_nb_breves') . '</div>';
  285. if ($p = strpos($flux['data'], '<!--nb_elements-->')) {
  286. $flux['data'] = substr_replace($flux['data'], $nb, $p, 0);
  287. }
  288. }
  289. }
  290. return $flux;
  291. }
  292. /**
  293. * Ajoute le formulaire de configuration des brèves sur la page de
  294. * configuration des contenus
  295. *
  296. * @pipeline affiche_milieu
  297. *
  298. * @param array $flux Données du pipeline
  299. * @return array Données du pipeline
  300. */
  301. function breves_affiche_milieu($flux) {
  302. if ($flux['args']['exec'] == 'configurer_contenu') {
  303. $flux['data'] .= recuperer_fond('prive/squelettes/inclure/configurer', array('configurer' => 'configurer_breves'));
  304. }
  305. return $flux;
  306. }