3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
16 // http://doc.spip.org/@generer_action_auteur
17 function generer_action_auteur($action, $arg, $redirect="", $mode=false, $att='', $public=false)
19 $securiser_action = charger_fonction('securiser_action', 'inc');
20 return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
23 // http://doc.spip.org/@redirige_action_auteur
24 function redirige_action_auteur($action, $arg, $ret, $gra='', $mode=false, $atts='') {
26 $r = _DIR_RESTREINT
. generer_url_ecrire($ret, $gra, true, true);
28 return generer_action_auteur($action, $arg, $r, $mode, $atts);
31 // http://doc.spip.org/@redirige_action_post
32 function redirige_action_post($action, $arg, $ret, $gra, $corps, $att='') {
33 $r = _DIR_RESTREINT
. generer_url_ecrire($ret, $gra, false, true);
34 return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
37 // Retourne un formulaire d'execution de $action sur $id,
38 // revenant a l'envoyeur $script d'arguments $args.
39 // Utilise Ajax si dispo, en ecrivant le resultat dans le innerHTML du noeud
40 // d'attribut id = $action-$id (cf. AjaxSqueeze dans layer.js)
42 // http://doc.spip.org/@ajax_action_auteur
43 function ajax_action_auteur($action, $id, $script, $args='', $corps=false, $args_ajax='', $fct_ajax='')
45 if (strpos($args,"#")===FALSE)
46 $ancre = "$action-" . intval($id);
48 $ancre = explode("#",$args);
54 // methodes traditionnelle et ajax a unifier...
55 if (is_string($corps)) {
57 // Methode traditionnelle
58 if (_SPIP_AJAX
!== 1) {
59 return redirige_action_post($action,
68 if ($args AND !$args_ajax) $args_ajax = "&$args";
69 if (isset($_GET['var_profile']))
70 $args_ajax .= '&var_profile=1';
71 return redirige_action_post($action,
74 "script=$script$args_ajax",
77 . ajax_action_declencheur('this', $ancre, $fct_ajax)));
84 $href = redirige_action_auteur($action,
90 if ($args AND !$args_ajax) $args_ajax = "&$args";
91 if (isset($_GET['var_profile']))
92 $args_ajax .= '&var_profile=1';
94 $ajax = redirige_action_auteur($action,
97 "script=$script$args_ajax");
99 $cli = array_shift($corps);
100 return "<a href='$href'\nonclick="
101 . ajax_action_declencheur($ajax, $ancre, $fct_ajax)
103 . (!$corps ?
$cli : ("\n<span" . $corps[0] . ">$cli</span>"))
108 // Comme ci-dessus, mais reduit au cas POST et on fournit le bouton Submit.
110 // http://doc.spip.org/@ajax_action_post
111 function ajax_action_post($action, $arg, $retour, $gra, $corps, $clic='', $atts_i='', $atts_span = "", $args_ajax='', $fct_ajax='')
113 global $spip_lang_right;
115 if (strpos($gra,"#")===FALSE) {
116 // A etudier: prendre systematiquement arg en trancodant les \W
118 $ancre = "$action-" . ($n ?
$n : $arg);
120 $ancre = explode("#",$gra);
126 $atts_i = " style='float: $spip_lang_right'";
128 if (is_array($clic)) {
130 $atts_i .= "\nonclick='AjaxNamedSubmit(this)'";
131 foreach($clic as $n => $c)
132 $submit .= "\n<input type='submit' name='$n' value='$c' $atts_i />";
134 if (!$clic) $clic = _T('bouton_valider');
135 $submit = "<input type='submit' value='$clic' $atts_i />";
145 if (_SPIP_AJAX
!== 1) {
146 return redirige_action_post($action, $arg, $retour,
147 ($gra . '#' . $ancre),
151 if ($gra AND !$args_ajax) $args_ajax = "&$gra";
152 if (isset($GLOBALS['var_profile']))
153 $args_ajax .= '&var_profile=1';
155 $js = ajax_action_declencheur('this', $ancre, $fct_ajax);
156 return redirige_action_post($action,
159 "script=$retour$args_ajax",
166 // Attention pour que Safari puisse manipuler cet evenement
167 // il faut onsubmit="return AjaxSqueeze(x,'truc',...)"
168 // et non pas onsubmit='return AjaxSqueeze(x,"truc",...)'
170 // http://doc.spip.org/@ajax_action_declencheur
171 function ajax_action_declencheur($request, $noeud, $fct_ajax='') {
172 if (strpos($request, 'this') !== 0)
173 $request = "'".$request."'";
175 return '"return AjaxSqueeze('
180 . ($fct_ajax ?
$fct_ajax : "''")
184 // Place un element HTML dans une div nommee,
185 // sauf si c'est un appel Ajax car alors la div y est deja
186 // $fonction : denomination semantique du bloc, que l'on retouve en attribut class
187 // $id : id de l'objet concerne si il y a lieu ou "", sert a construire un identifiant unique au bloc ("fonction-id")
188 // http://doc.spip.org/@ajax_action_greffe
189 function ajax_action_greffe($fonction, $id, $corps)
191 $idom = $fonction.(strlen($id)?
"-$id":"");
194 : "\n<div id='$idom' class='ajax-action $fonction'>$corps\n</div>\n";
197 // http://doc.spip.org/@ajax_retour
198 function ajax_retour($corps, $xml = true)
200 if (isset($_COOKIE['spip_admin']) AND $GLOBALS['tableau_des_temps'])
203 if ($GLOBALS['exec'] == 'valider_xml') {
204 $debut = _DOCTYPE_ECRIRE
205 . "<html><head><title>Debug Spip Ajax</title></head>"
207 . "<!-- %%%%%%%%%%%%%%%%%%% Ajax %%%%%%%%%%%%%%%%%%% -->\n";
209 $fin = '</div></body></html>';
212 $c = $GLOBALS['meta']["charset"];
213 header('Content-Type: text/html; charset='. $c);
214 $debut = (($xml AND strlen(trim($corps)))?
'<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n":'');
217 echo $debut, $corps, $fin;
221 // http://doc.spip.org/@determine_upload
222 function determine_upload($type='') {
223 include_spip('inc/autoriser');
225 if (!autoriser('chargerftp')
226 OR $type == 'logos') # on ne le permet pas pour les logos
229 $repertoire = _DIR_TRANSFERT
;
230 if (!@is_dir
($repertoire)) {
231 $repertoire = str_replace(_DIR_TMP
, '', $repertoire);
232 $repertoire = sous_repertoire(_DIR_TMP
, $repertoire);
235 if (!$GLOBALS['visiteur_session']['restreint'])
238 return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);