X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Factions.php;fp=www%2Fecrire%2Finc%2Factions.php;h=e6689175dd2e0d18d197f263072e288707b3e392;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/ecrire/inc/actions.php b/www/ecrire/inc/actions.php new file mode 100644 index 0000000..e668917 --- /dev/null +++ b/www/ecrire/inc/actions.php @@ -0,0 +1,240 @@ +" + . (!$corps ? $cli : ("\n$cli")) + . ""; + } +} + +// Comme ci-dessus, mais reduit au cas POST et on fournit le bouton Submit. +// +// http://doc.spip.org/@ajax_action_post +function ajax_action_post($action, $arg, $retour, $gra, $corps, $clic='', $atts_i='', $atts_span = "", $args_ajax='', $fct_ajax='') +{ + global $spip_lang_right; + + if (strpos($gra,"#")===FALSE) { + // A etudier: prendre systematiquement arg en trancodant les \W + $n = intval($arg); + $ancre = "$action-" . ($n ? $n : $arg); + } else { + $ancre = explode("#",$gra); + $args = $ancre[0]; + $ancre = $ancre[1]; + } + + if (!$atts_i) + $atts_i = " style='float: $spip_lang_right'"; + + if (is_array($clic)) { + $submit = ""; + $atts_i .= "\nonclick='AjaxNamedSubmit(this)'"; + foreach($clic as $n => $c) + $submit .= "\n"; + } else { + if (!$clic) $clic = _T('bouton_valider'); + $submit = ""; + } + $corps = "
" + . $corps + . "" + . $submit + . "
"; + + if (_SPIP_AJAX !== 1) { + return redirige_action_post($action, $arg, $retour, + ($gra . '#' . $ancre), + $corps); + } else { + + if ($gra AND !$args_ajax) $args_ajax = "&$gra"; + if (isset($GLOBALS['var_profile'])) + $args_ajax .= '&var_profile=1'; + + $js = ajax_action_declencheur('this', $ancre, $fct_ajax); + return redirige_action_post($action, + $arg, + $action, + "script=$retour$args_ajax", + $corps, + " onsubmit=$js"); + } +} + +// +// Attention pour que Safari puisse manipuler cet evenement +// il faut onsubmit="return AjaxSqueeze(x,'truc',...)" +// et non pas onsubmit='return AjaxSqueeze(x,"truc",...)' +// +// http://doc.spip.org/@ajax_action_declencheur +function ajax_action_declencheur($request, $noeud, $fct_ajax='') { + if (strpos($request, 'this') !== 0) + $request = "'".$request."'"; + + return '"return AjaxSqueeze(' + . $request + . ",'" + . $noeud + . "'," + . ($fct_ajax ? $fct_ajax : "''") + . ',event)"'; +} + +// Place un element HTML dans une div nommee, +// sauf si c'est un appel Ajax car alors la div y est deja +// $fonction : denomination semantique du bloc, que l'on retouve en attribut class +// $id : id de l'objet concerne si il y a lieu ou "", sert a construire un identifiant unique au bloc ("fonction-id") +// http://doc.spip.org/@ajax_action_greffe +function ajax_action_greffe($fonction, $id, $corps) +{ + $idom = $fonction.(strlen($id)?"-$id":""); + return _AJAX + ? "$corps" + : "\n
$corps\n
\n"; +} + +// http://doc.spip.org/@ajax_retour +function ajax_retour($corps, $xml = true) +{ + if (isset($_COOKIE['spip_admin']) AND $GLOBALS['tableau_des_temps']) + erreur_squelette(); + else { + if ($GLOBALS['exec'] == 'valider_xml') { + $debut = _DOCTYPE_ECRIRE + . "Debug Spip Ajax" + . "
\n\n" + . "\n"; + + $fin = '
'; + + } else { + $c = $GLOBALS['meta']["charset"]; + header('Content-Type: text/html; charset='. $c); + $debut = (($xml AND strlen(trim($corps)))?'<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n":''); + $fin = ''; + } + echo $debut, $corps, $fin; + } +} + +// http://doc.spip.org/@determine_upload +function determine_upload($type='') { + include_spip('inc/autoriser'); + + if (!autoriser('chargerftp') + OR $type == 'logos') # on ne le permet pas pour les logos + return false; + + $repertoire = _DIR_TRANSFERT; + if (!@is_dir($repertoire)) { + $repertoire = str_replace(_DIR_TMP, '', $repertoire); + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); + } + + if (!$GLOBALS['visiteur_session']['restreint']) + return $repertoire; + else + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); +} +?>