3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2017 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
14 * Fonctions déclarées dans des pipelines (espace privé)
16 * @package SPIP\Core\Pipelines
18 if (!defined('_ECRIRE_INC_VERSION')) {
24 * Inserer jQuery et ses plugins pour l'espace privé
26 * La fonction ajoute les balises scripts dans le texte qui appelent
27 * les scripts jQuery ainsi que certains de ses plugins. La liste
28 * des js chargée peut être complété par le pipeline 'jquery_plugins'
30 * Cette fonction est appelée par le pipeline header_prive
33 * @link http://code.spip.net/@f_jQuery
35 * @param string $texte Contenu qui sera inséré dans le head HTML
36 * @return string Contenu complété des scripts javascripts, dont jQuery
38 function f_jQuery_prive($texte) {
40 $jquery_plugins = pipeline('jquery_plugins',
42 'prive/javascript/jquery.js',
43 'prive/javascript/jquery-migrate-3.0.1.js',
44 'prive/javascript/jquery.form.js',
45 'prive/javascript/jquery.autosave.js',
46 'prive/javascript/jquery.placeholder-label.js',
47 'prive/javascript/ajaxCallback.js',
48 'prive/javascript/js.cookie.js',
49 'prive/javascript/jquery.cookie.js',
50 'prive/javascript/spip_barre.js',
52 foreach (array_unique($jquery_plugins) as $script) {
53 if ($script = find_in_path(supprimer_timestamp($script))) {
54 $script = timestamp($script);
55 $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
58 // inserer avant le premier script externe ou a la fin
59 if (preg_match(",<script[^><]*src=,", $texte, $match)
60 and $p = strpos($texte, $match[0])
62 $texte = substr_replace($texte, $x, $p, 0);
72 * Ajout automatique du title dans les pages du privé en squelette
74 * Appellé dans le pipeline affichage_final_prive
76 * @param string $texte
79 function affichage_final_prive_title_auto($texte) {
80 if (strpos($texte, '<title>') === false
82 (preg_match(",<h1[^>]*>(.+)</h1>,Uims", $texte, $match)
83 or preg_match(",<h[23][^>]*>(.+)</h[23]>,Uims", $texte, $match))
84 and $match = textebrut(trim($match[1]))
85 and ($p = strpos($texte, '<head>')) !== false
87 if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']["nom_site"]))) {
88 $nom_site_spip = _T('info_mon_site_spip');
96 $texte = substr_replace($texte, $titre, $p +
6, 0);
103 // Fonction standard pour le pipeline 'boite_infos'
104 // http://code.spip.net/@f_boite_infos
105 function f_boite_infos($flux) {
106 $args = $flux['args'];
107 $type = $args['type'];
109 if (!trouver_fond($type, "prive/objets/infos/")) {
112 $args['espace_prive'] = 1;
113 $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
120 * Utilisation du pipeline recuperer_fond dans le prive
122 * Branchement automatise de affiche_gauche, affiche_droite, affiche_milieu
123 * pour assurer la compat avec les versions precedentes des exec en php
124 * Branche de affiche_objet
126 * Les pipelines ne recevront plus exactement le meme contenu en entree,
127 * mais la compat multi vertions pourra etre assuree
128 * par une insertion au bon endroit quand le contenu de depart n'est pas vide
130 * @param array $flux Données du pipeline
131 * @return array Données du pipeline
133 function f_afficher_blocs_ecrire($flux) {
135 if (is_string($fond = $flux['args']['fond'])) {
136 $exec = isset($flux['args']['contexte']['exec']) ?
$flux['args']['contexte']['exec'] : _request('exec');
137 if (!isset($o[$exec])) {
138 $o[$exec] = trouver_objet_exec($exec);
141 if ($exec == "infos_perso") {
142 $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
144 $typepage = (isset($flux['args']['contexte']['type-page']) ?
$flux['args']['contexte']['type-page'] : $exec);
145 if ($fond == "prive/squelettes/navigation/$typepage") {
146 $flux['data']['texte'] = pipeline('affiche_gauche',
147 array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']));
148 } elseif ($fond == "prive/squelettes/extra/$typepage") {
149 include_spip('inc/presentation_mini');
150 $flux['data']['texte'] = pipeline('affiche_droite',
151 array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte'])) . liste_objets_bloques($exec,
152 $flux['args']['contexte']);
153 } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
154 // id non defini sur les formulaire de nouveaux objets
155 $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ?
intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
156 $flux['data']['texte'] = pipeline('affiche_hierarchie',
157 array('args' => array('objet' => $o[$exec]['type'], 'id_objet' => $id), 'data' => $flux['data']['texte']));
158 } elseif ($fond == "prive/squelettes/contenu/$typepage") {
159 if (!strpos($flux['data']['texte'], "<!--affiche_milieu-->")) {
160 $flux['data']['texte'] = preg_replace(',<div id=["\']wysiwyg,', "<!--affiche_milieu-->\\0",
161 $flux['data']['texte']);
164 and $objet = $o[$exec]['type']
165 and $o[$exec]['edition'] == false
166 and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
167 and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
169 // inserer le formulaire de traduction
170 $flux['data']['texte'] = str_replace("<!--affiche_milieu-->", recuperer_fond('prive/objets/editer/traductions',
171 array('objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1)) . "<!--affiche_milieu-->", $flux['data']['texte']);
172 $flux['data']['texte'] = pipeline('afficher_fiche_objet', array(
174 'contexte' => $flux['args']['contexte'],
178 'data' => $flux['data']['texte']
181 $flux['data']['texte'] = pipeline('affiche_milieu',
182 array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']));
183 } elseif ($fond == "prive/squelettes/inclure/pied") {
184 $flux['data']['texte'] = pipeline('affiche_pied',
185 array('args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']));
186 } elseif (strncmp($fond, "prive/objets/contenu/", 21) == 0
187 and $objet = basename($fond)
188 and $objet == substr($fond, 21)
189 and isset($o[$objet])
192 $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
193 $flux['data']['texte'] = pipeline('afficher_contenu_objet', array(
194 'args' => array('type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']),
195 'data' => $flux['data']['texte']
204 * Afficher les taches en attente liees a un objet
206 * @pipeline affiche_milieu
207 * @param string $flux
210 function f_queue_affiche_milieu($flux) {
211 $args = $flux['args'];
213 foreach ($args as $key => $arg) {
214 if (preg_match(",^id_,", $key) and is_numeric($arg) and $arg = intval($arg)) {
215 $objet = preg_replace(',^id_,', '', $key);
216 $res .= recuperer_fond('modeles/object_jobs_list', array('id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1),
217 array('ajax' => true));
221 $flux['data'] = $res . $flux['data'];
228 * Trouver l'objet qui correspond à l'exec de l'espace privé passé en argument
230 * renvoie false si pas d'objet en cours, ou un tableau associatif
231 * contenant les informations table_objet_sql,table,type,id_table_objet,edition
233 * @param string $exec
234 * nom de la page testee
237 function trouver_objet_exec($exec) {
238 static $objet_exec = array();
243 if ($exec == "infos_perso") {
245 set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
247 if (!isset($objet_exec[$exec])) {
248 $objet_exec[$exec] = false;
249 $infos = lister_tables_objets_sql();
250 foreach ($infos as $t => $info) {
251 if ($exec == $info['url_edit'] and $info['editable']) {
252 return $objet_exec[$exec] = array(
253 'edition' => $exec == $info['url_voir'] ?
'' : true,
254 'table_objet_sql' => $t,
255 'table' => $info['table_objet'],
256 'type' => $info['type'],
257 'id_table_objet' => id_table_objet($info['type'])
260 if ($exec == $info['url_voir']) {
261 return $objet_exec[$exec] = array(
263 'table_objet_sql' => $t,
264 'table' => $info['table_objet'],
265 'type' => $info['type'],
266 'id_table_objet' => id_table_objet($info['type'])
272 return $objet_exec[$exec];