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

/ecrire/inc/pipelines_ecrire.php

https://bitbucket.org/re_al_/real.test.spip
PHP | 273 lines | 178 code | 20 blank | 75 comment | 33 complexity | ff441fc2df0ff28a4b00445f413650cc 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-2017 *
  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. * Fonctions déclarées dans des pipelines (espace privé)
  13. *
  14. * @package SPIP\Core\Pipelines
  15. **/
  16. if (!defined('_ECRIRE_INC_VERSION')) {
  17. return;
  18. }
  19. /**
  20. * Inserer jQuery et ses plugins pour l'espace privé
  21. *
  22. * La fonction ajoute les balises scripts dans le texte qui appelent
  23. * les scripts jQuery ainsi que certains de ses plugins. La liste
  24. * des js chargée peut être complété par le pipeline 'jquery_plugins'
  25. *
  26. * Cette fonction est appelée par le pipeline header_prive
  27. *
  28. * @see f_jQuery()
  29. * @link http://code.spip.net/@f_jQuery
  30. *
  31. * @param string $texte Contenu qui sera inséré dans le head HTML
  32. * @return string Contenu complété des scripts javascripts, dont jQuery
  33. **/
  34. function f_jQuery_prive($texte) {
  35. $x = '';
  36. $jquery_plugins = pipeline('jquery_plugins',
  37. array(
  38. 'prive/javascript/jquery.js',
  39. 'prive/javascript/jquery-migrate-3.0.1.js',
  40. 'prive/javascript/jquery.form.js',
  41. 'prive/javascript/jquery.autosave.js',
  42. 'prive/javascript/jquery.placeholder-label.js',
  43. 'prive/javascript/ajaxCallback.js',
  44. 'prive/javascript/js.cookie.js',
  45. 'prive/javascript/jquery.cookie.js',
  46. 'prive/javascript/spip_barre.js',
  47. ));
  48. foreach (array_unique($jquery_plugins) as $script) {
  49. if ($script = find_in_path(supprimer_timestamp($script))) {
  50. $script = timestamp($script);
  51. $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
  52. }
  53. }
  54. // inserer avant le premier script externe ou a la fin
  55. if (preg_match(",<script[^><]*src=,", $texte, $match)
  56. and $p = strpos($texte, $match[0])
  57. ) {
  58. $texte = substr_replace($texte, $x, $p, 0);
  59. } else {
  60. $texte .= $x;
  61. }
  62. return $texte;
  63. }
  64. /**
  65. * Ajout automatique du title dans les pages du privé en squelette
  66. *
  67. * Appellé dans le pipeline affichage_final_prive
  68. *
  69. * @param string $texte
  70. * @return string
  71. */
  72. function affichage_final_prive_title_auto($texte) {
  73. if (strpos($texte, '<title>') === false
  74. and
  75. (preg_match(",<h1[^>]*>(.+)</h1>,Uims", $texte, $match)
  76. or preg_match(",<h[23][^>]*>(.+)</h[23]>,Uims", $texte, $match))
  77. and $match = textebrut(trim($match[1]))
  78. and ($p = strpos($texte, '<head>')) !== false
  79. ) {
  80. if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']["nom_site"]))) {
  81. $nom_site_spip = _T('info_mon_site_spip');
  82. }
  83. $titre = "<title>["
  84. . $nom_site_spip
  85. . "] " . $match
  86. . "</title>";
  87. $texte = substr_replace($texte, $titre, $p + 6, 0);
  88. }
  89. return $texte;
  90. }
  91. // Fonction standard pour le pipeline 'boite_infos'
  92. // http://code.spip.net/@f_boite_infos
  93. function f_boite_infos($flux) {
  94. $args = $flux['args'];
  95. $type = $args['type'];
  96. unset($args['row']);
  97. if (!trouver_fond($type, "prive/objets/infos/")) {
  98. $type = 'objet';
  99. }
  100. $args['espace_prive'] = 1;
  101. $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
  102. return $flux;
  103. }
  104. /**
  105. * Utilisation du pipeline recuperer_fond dans le prive
  106. *
  107. * Branchement automatise de affiche_gauche, affiche_droite, affiche_milieu
  108. * pour assurer la compat avec les versions precedentes des exec en php
  109. * Branche de affiche_objet
  110. *
  111. * Les pipelines ne recevront plus exactement le meme contenu en entree,
  112. * mais la compat multi vertions pourra etre assuree
  113. * par une insertion au bon endroit quand le contenu de depart n'est pas vide
  114. *
  115. * @param array $flux Données du pipeline
  116. * @return array Données du pipeline
  117. */
  118. function f_afficher_blocs_ecrire($flux) {
  119. static $o = array();
  120. if (is_string($fond = $flux['args']['fond'])) {
  121. $exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec');
  122. if (!isset($o[$exec])) {
  123. $o[$exec] = trouver_objet_exec($exec);
  124. }
  125. // cas particulier
  126. if ($exec == "infos_perso") {
  127. $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
  128. }
  129. $typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec);
  130. if ($fond == "prive/squelettes/navigation/$typepage") {
  131. $flux['data']['texte'] = pipeline('affiche_gauche',
  132. array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']));
  133. } elseif ($fond == "prive/squelettes/extra/$typepage") {
  134. include_spip('inc/presentation_mini');
  135. $flux['data']['texte'] = pipeline('affiche_droite',
  136. array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte'])) . liste_objets_bloques($exec,
  137. $flux['args']['contexte']);
  138. } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
  139. // id non defini sur les formulaire de nouveaux objets
  140. $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
  141. $flux['data']['texte'] = pipeline('affiche_hierarchie',
  142. array('args' => array('objet' => $o[$exec]['type'], 'id_objet' => $id), 'data' => $flux['data']['texte']));
  143. } elseif ($fond == "prive/squelettes/contenu/$typepage") {
  144. if (!strpos($flux['data']['texte'], "<!--affiche_milieu-->")) {
  145. $flux['data']['texte'] = preg_replace(',<div id=["\']wysiwyg,', "<!--affiche_milieu-->\\0",
  146. $flux['data']['texte']);
  147. }
  148. if ($o[$exec]
  149. and $objet = $o[$exec]['type']
  150. and $o[$exec]['edition'] == false
  151. and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
  152. and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
  153. ) {
  154. // inserer le formulaire de traduction
  155. $flux['data']['texte'] = str_replace("<!--affiche_milieu-->", recuperer_fond('prive/objets/editer/traductions',
  156. array('objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1)) . "<!--affiche_milieu-->", $flux['data']['texte']);
  157. $flux['data']['texte'] = pipeline('afficher_fiche_objet', array(
  158. 'args' => array(
  159. 'contexte' => $flux['args']['contexte'],
  160. 'type' => $objet,
  161. 'id' => $id
  162. ),
  163. 'data' => $flux['data']['texte']
  164. ));
  165. }
  166. $flux['data']['texte'] = pipeline('affiche_milieu',
  167. array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']));
  168. } elseif ($fond == "prive/squelettes/inclure/pied") {
  169. $flux['data']['texte'] = pipeline('affiche_pied',
  170. array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']));
  171. } elseif (strncmp($fond, "prive/objets/contenu/", 21) == 0
  172. and $objet = basename($fond)
  173. and $objet == substr($fond, 21)
  174. and isset($o[$objet])
  175. and $o[$objet]
  176. ) {
  177. $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
  178. $flux['data']['texte'] = pipeline('afficher_contenu_objet', array(
  179. 'args' => array('type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']),
  180. 'data' => $flux['data']['texte']
  181. ));
  182. }
  183. }
  184. return $flux;
  185. }
  186. /**
  187. * Afficher les taches en attente liees a un objet
  188. *
  189. * @pipeline affiche_milieu
  190. * @param string $flux
  191. * @return string
  192. */
  193. function f_queue_affiche_milieu($flux) {
  194. $args = $flux['args'];
  195. $res = "";
  196. foreach ($args as $key => $arg) {
  197. if (preg_match(",^id_,", $key) and is_numeric($arg) and $arg = intval($arg)) {
  198. $objet = preg_replace(',^id_,', '', $key);
  199. $res .= recuperer_fond('modeles/object_jobs_list', array('id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1),
  200. array('ajax' => true));
  201. }
  202. }
  203. if ($res) {
  204. $flux['data'] = $res . $flux['data'];
  205. }
  206. return $flux;
  207. }
  208. /**
  209. * Trouver l'objet qui correspond à l'exec de l'espace privé passé en argument
  210. *
  211. * renvoie false si pas d'objet en cours, ou un tableau associatif
  212. * contenant les informations table_objet_sql,table,type,id_table_objet,edition
  213. *
  214. * @param string $exec
  215. * nom de la page testee
  216. * @return array|bool
  217. */
  218. function trouver_objet_exec($exec) {
  219. static $objet_exec = array();
  220. if (!$exec) {
  221. return false;
  222. }
  223. // cas particulier
  224. if ($exec == "infos_perso") {
  225. $exec = "auteur";
  226. set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
  227. }
  228. if (!isset($objet_exec[$exec])) {
  229. $objet_exec[$exec] = false;
  230. $infos = lister_tables_objets_sql();
  231. foreach ($infos as $t => $info) {
  232. if ($exec == $info['url_edit'] and $info['editable']) {
  233. return $objet_exec[$exec] = array(
  234. 'edition' => $exec == $info['url_voir'] ? '' : true,
  235. 'table_objet_sql' => $t,
  236. 'table' => $info['table_objet'],
  237. 'type' => $info['type'],
  238. 'id_table_objet' => id_table_objet($info['type'])
  239. );
  240. }
  241. if ($exec == $info['url_voir']) {
  242. return $objet_exec[$exec] = array(
  243. 'edition' => false,
  244. 'table_objet_sql' => $t,
  245. 'table' => $info['table_objet'],
  246. 'type' => $info['type'],
  247. 'id_table_objet' => id_table_objet($info['type'])
  248. );
  249. }
  250. }
  251. }
  252. return $objet_exec[$exec];
  253. }