c24698dad7dacd8cdf99b4e49a23fbbb3f5eaba6
[lhc/web/clavette_www.git] / www / ecrire / inc / pipelines_ecrire.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 * Fonctions déclarées dans des pipelines (espace privé)
15 *
16 * @package SPIP\Pipelines
17 **/
18 if (!defined('_ECRIRE_INC_VERSION')) return;
19
20
21 /**
22 * Inserer jQuery et ses plugins pour l'espace privé
23 *
24 * La fonction ajoute les balises scripts dans le texte qui appelent
25 * les scripts jQuery ainsi que certains de ses plugins. La liste
26 * des js chargée peut être complété par le pipeline 'jquery_plugins'
27 *
28 * Cette fonction est appelée par le pipeline header_prive
29 *
30 * @see f_jQuery()
31 * @link http://doc.spip.org/@f_jQuery
32 *
33 * @param string $texte Contenu qui sera inséré dans le head HTML
34 * @return string Contenu complété des scripts javascripts, dont jQuery
35 **/
36 function f_jQuery_prive ($texte) {
37 $x = '';
38 $jquery_plugins = pipeline('jquery_plugins',
39 array(
40 'prive/javascript/jquery.js',
41 'prive/javascript/jquery.form.js',
42 'prive/javascript/jquery.autosave.js',
43 'prive/javascript/jquery.placeholder-label.js',
44 'prive/javascript/ajaxCallback.js',
45 'prive/javascript/jquery.colors.js',
46 'prive/javascript/jquery.cookie.js',
47 'prive/javascript/spip_barre.js',
48 ));
49 foreach (array_unique($jquery_plugins) as $script)
50 if ($script = find_in_path($script))
51 $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
52 // inserer avant le premier script externe ou a la fin
53 if (preg_match(",<script[^><]*src=,",$texte,$match)
54 AND $p = strpos($texte,$match[0])){
55 $texte = substr_replace($texte,$x,$p,0);
56 }
57 else
58 $texte .= $x;
59 return $texte;
60 }
61
62
63 /**
64 * Ajout automatique du title dans les pages du privé en squelette
65 *
66 * Appellé dans le pipeline affichage_final_prive
67 *
68 * @param string $texte
69 * @return string
70 */
71 function affichage_final_prive_title_auto($texte){
72 if (strpos($texte,'<title>')===false
73 AND
74 (preg_match(",<h1[^>]*>(.+)</h1>,Uims", $texte, $match)
75 OR preg_match(",<h[23][^>]*>(.+)</h[23]>,Uims", $texte, $match))
76 AND $match = textebrut(trim($match[1]))
77 AND ($p = strpos($texte,'<head>'))!==FALSE) {
78 if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']["nom_site"])))
79 $nom_site_spip= _T('info_mon_site_spip');
80
81 $titre = "<title>["
82 . $nom_site_spip
83 . "] ". $match
84 ."</title>";
85
86 $texte = substr_replace($texte, $titre, $p+6,0);
87 }
88 return $texte;
89 }
90
91
92 // Fonction standard pour le pipeline 'boite_infos'
93 // http://doc.spip.org/@f_boite_infos
94 function f_boite_infos($flux) {
95 $args = $flux['args'];
96 $type = $args['type'];
97 unset($args['row']);
98 if (!trouver_fond($type,"prive/objets/infos/"))
99 $type = 'objet';
100 $flux['data'] .= recuperer_fond("prive/objets/infos/$type",$args);
101 return $flux;
102 }
103
104
105 /**
106 * pipeline recuperer_fond
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
116 * @return array
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 $typepage = (isset($flux['args']['contexte']['type-page'])?$flux['args']['contexte']['type-page']:$exec);
126 if ($fond == "prive/squelettes/navigation/$typepage"){
127 $flux['data']['texte'] = pipeline('affiche_gauche',array('args'=>$flux['args']['contexte'],'data'=>$flux['data']['texte']));
128 }
129 elseif ($fond=="prive/squelettes/extra/$typepage") {
130 include_spip('inc/presentation_mini');
131 $flux['data']['texte'] = pipeline('affiche_droite',array('args'=>$flux['args']['contexte'],'data'=>$flux['data']['texte'])).liste_objets_bloques($exec,$flux['args']['contexte']);
132 }
133 elseif ($fond=="prive/squelettes/hierarchie/$typepage" AND $o[$exec]) {
134 // id non defini sur les formulaire de nouveaux objets
135 $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
136 $flux['data']['texte'] = pipeline('affiche_hierarchie',array('args'=>array('objet'=>$o[$exec]['type'],'id_objet'=>$id),'data'=>$flux['data']['texte']));
137 }
138 elseif ($fond=="prive/squelettes/contenu/$typepage"){
139 if (!strpos($flux['data']['texte'],"<!--affiche_milieu-->"))
140 $flux['data']['texte'] = preg_replace(',<div id=["\']wysiwyg,',"<!--affiche_milieu-->\\0",$flux['data']['texte']);
141 if ($o[$exec]
142 AND $objet = $o[$exec]['type']
143 AND $o[$exec]['edition'] == false
144 AND $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])){
145 // inserer le formulaire de traduction
146 $flux['data']['texte'] = str_replace("<!--affiche_milieu-->",recuperer_fond('prive/objets/editer/traductions',array('objet'=>$objet,'id_objet'=>$id))."<!--affiche_milieu-->",$flux['data']['texte']);
147 $flux['data']['texte'] = pipeline('afficher_fiche_objet',array(
148 'args'=>array(
149 'contexte'=>$flux['args']['contexte'],
150 'type'=>$objet,
151 'id'=>$id),
152 'data'=>$flux['data']['texte']));
153 }
154 $flux['data']['texte'] = pipeline('affiche_milieu',array('args'=>$flux['args']['contexte'],'data'=>$flux['data']['texte']));
155 }
156 elseif ($fond=="prive/squelettes/inclure/pied"){
157 $flux['data']['texte'] = pipeline('affiche_pied',array('args'=>$flux['args']['contexte'],'data'=>$flux['data']['texte']));
158 }
159 elseif (strncmp($fond,"prive/objets/contenu/",21)==0
160 AND $objet=basename($fond)
161 AND $objet==substr($fond,21)
162 AND isset($o[$objet])
163 AND $o[$objet]) {
164 $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
165 $flux['data']['texte'] = pipeline('afficher_contenu_objet',array('args'=>array('type'=>$objet,'id_objet'=>$id,'contexte'=>$flux['args']['contexte']),'data'=>$flux['data']['texte']));
166 }
167 }
168
169 return $flux;
170 }
171
172 /**
173 * Afficher les taches en attente liees a un objet
174 * @param string $flux
175 * @return string
176 */
177 function f_queue_affiche_milieu($flux){
178 $args = $flux['args'];
179 $res = "";
180 foreach($args as $key=>$arg){
181 if (preg_match(",^id_,",$key) AND is_numeric($arg) AND $arg=intval($arg)){
182 $objet = preg_replace(',^id_,', '', $key);
183 $res .= recuperer_fond('modeles/object_jobs_list',array('id_objet'=>$arg,'objet'=>$objet),array('ajax'=>true));
184 }
185 }
186 if ($res)
187 $flux['data'] = $res . $flux['data'];
188
189 return $flux;
190 }
191
192 /**
193 * Trouver l'objet qui correspond
194 * a l'exec de l'espace prive passe en argument
195 * renvoie false si pas d'objet en cours, ou un tableau associatif
196 * contenant les informations table_objet_sql,table,type,id_table_objet,edition
197 *
198 * @param string $exec
199 * nom de la page testee
200 * @return array|bool
201 */
202 function trouver_objet_exec($exec){
203 static $objet_exec=array();
204 if (!$exec) return false;
205 if (!isset($objet_exec[$exec])){
206 $objet_exec[$exec]=false;
207 $infos = lister_tables_objets_sql();
208 foreach($infos as $t=>$info){
209 if ($exec==$info['url_edit'] AND $info['editable']){
210 return $objet_exec[$exec] = array('edition'=>$exec==$info['url_voir']?'':true,'table_objet_sql'=>$t,'table'=>$info['table_objet'],'type'=>$info['type'],'id_table_objet'=>id_table_objet($info['type']));
211 }
212 if ($exec==$info['url_voir']){
213 return $objet_exec[$exec] = array('edition'=>false,'table_objet_sql'=>$t,'table'=>$info['table_objet'],'type'=>$info['type'],'id_table_objet'=>id_table_objet($info['type']));
214 }
215 }
216 }
217 return $objet_exec[$exec];
218 }
219 ?>