[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / inc / actions.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
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 if (!defined('_ECRIRE_INC_VERSION')) return;
14
15 /**
16 * retourne une URL ou un formulaire securises
17 *
18 * http://doc.spip.org/@generer_action_auteur
19 *
20 * @param string $action
21 * @param string $arg
22 * @param string $redirect
23 * @param bool|int|string $mode
24 * -1 : renvoyer action, arg et hash sous forme de array()
25 * true ou false : renvoyer une url, avec &amp; (false) ou & (true)
26 * string : renvoyer un formulaire
27 * @param string|int $att
28 * id_auteur pour lequel generer l'action en mode url ou array()
29 * atributs du formulaire en mode formulaire
30 * @param bool $public
31 * @return array|string
32 */
33 function generer_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false){
34 $securiser_action = charger_fonction('securiser_action', 'inc');
35 return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
36 }
37
38 // http://doc.spip.org/@redirige_action_auteur
39 function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) {
40
41 $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) .generer_url_ecrire($ret, $gra, true, true);
42
43 return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
44 }
45
46 // http://doc.spip.org/@redirige_action_post
47 function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = ''){
48 $r = _DIR_RESTREINT.generer_url_ecrire($ret, $gra, false, true);
49 return generer_action_auteur($action, $arg, $r, $corps, $att." method='post'");
50 }
51
52
53 /**
54 * Fonction de formatage du contenu renvoye en ajax
55 *
56 * http://doc.spip.org/@ajax_retour
57 *
58 * @param string $corps
59 * @param string $content_type
60 * permet de definir le type de contenu renvoye.
61 * Si rien de précisé, ou si true c'est "text/html" avec un entete xml en plus.
62 * La valeur speciale false fournit text/html sans entete xml. Elle equivaut a
63 * passer "text/html" comme $content_type
64 */
65 function ajax_retour($corps, $content_type = null){
66 $xml = false;
67 if (is_null($content_type) OR $content_type===true){
68 $xml = true;
69 $content_type = 'text/html';
70 }
71 elseif (!$content_type OR !is_string($content_type) OR strpos($content_type,'/')===false) {
72 $content_type = 'text/html';
73 }
74
75 $e = "";
76 if (isset($_COOKIE['spip_admin'])
77 AND ((_request('var_mode')=='debug') OR !empty($GLOBALS['tableau_des_temps'])))
78 $e = erreur_squelette();
79 if (isset($GLOBALS['transformer_xml']) OR (isset($GLOBALS['exec']) AND $GLOBALS['exec']=='valider_xml')){
80 $debut = _DOCTYPE_ECRIRE
81 ."<html><head><title>Debug Spip Ajax</title></head>"
82 ."<body><div>\n\n"
83 ."<!-- %%%%%%%%%%%%%%%%%%% Ajax %%%%%%%%%%%%%%%%%%% -->\n";
84
85 $fin = '</div></body></html>';
86
87 } else {
88 $c = $GLOBALS['meta']["charset"];
89 header('Content-Type: '.$content_type.'; charset='.$c);
90 $debut = (($xml AND strlen(trim($corps))) ? '<'."?xml version='1.0' encoding='".$c."'?".">\n" : '');
91 $fin = "";
92 }
93 echo $debut, $corps, $fin, $e;
94 }
95
96 ?>