[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / balise / formulaire_admin.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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 // http://doc.spip.org/@balise_FORMULAIRE_ADMIN
16 function balise_FORMULAIRE_ADMIN ($p) {
17 return calculer_balise_dynamique($p,'FORMULAIRE_ADMIN', array());
18 }
19
20 # on ne peut rien dire au moment de l'execution du squelette
21
22 // http://doc.spip.org/@balise_FORMULAIRE_ADMIN_stat
23 function balise_FORMULAIRE_ADMIN_stat($args, $context_compil) {
24 return $args;
25 }
26
27 # les boutons admin sont mis d'autorite si absents
28 # donc une variable statique controle si FORMULAIRE_ADMIN a ete vu.
29 # Toutefois, si c'est le debuger qui appelle,
30 # il peut avoir recopie le code dans ses donnees et il faut le lui refounir.
31 # Pas question de recompiler: ca fait boucler !
32 # Le debuger transmet donc ses donnees, et cette balise y retrouve son petit.
33
34 // http://doc.spip.org/@balise_FORMULAIRE_ADMIN_dyn
35 function balise_FORMULAIRE_ADMIN_dyn($float='', $debug='') {
36
37 global $var_preview, $use_cache;
38 static $dejafait = false;
39
40 if (!@$_COOKIE['spip_admin'])
41 return '';
42
43 if (!is_array($debug)) {
44 if ($dejafait)
45 return '';
46 } else {
47 if ($dejafait) {
48 if (empty($debug['sourcefile'])) return '';
49 foreach($debug['sourcefile'] as $k => $v) {
50 if (strpos($v,'administration.') !== false)
51 return $debug['resultat'][$k . 'tout'];
52 }
53 return '';
54 }
55 }
56
57 include_spip('inc/autoriser');
58 include_spip('base/abstract_sql');
59
60
61 $dejafait = true;
62
63 // Preparer le #ENV des boutons
64
65 $env = admin_objet();
66
67 // Pas de "modifier ce..." ? -> donner "acces a l'espace prive"
68 if (!$env)
69 $env['ecrire'] = _DIR_RESTREINT_ABS;
70
71 $env['divclass'] = $float;
72 $env['lang'] = admin_lang();
73 $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul');
74 $env['debug'] = $var_preview ? "" : admin_debug();
75 $env['analyser'] = (!$env['debug'] AND !$GLOBALS['xhtml']) ? '' : admin_valider();
76 $env['inclure'] = ($GLOBALS['var_inclure']?'inclure':'');
77
78 if (!$use_cache)
79 $env['use_cache'] = ' *';
80
81 if (isset($debug['validation'])) {
82 $env['xhtml_error'] = $debug['validation'];
83 }
84
85 $env['_pipeline'] = 'formulaire_admin';
86
87 return array('formulaires/administration', 0, $env);
88 }
89
90 // Afficher le bouton 'Modifier ce...'
91 // s'il y a un $id_XXX defini globalement par spip_register_globals
92 // Attention a l'ordre dans la boucle:
93 // on ne veut pas la rubrique si un autre bouton est possible
94
95 // http://doc.spip.org/@admin_objet
96 function admin_objet()
97 {
98 include_spip('inc/urls');
99 $env = array();
100
101 foreach (array('mot','auteur','rubrique','breve','article','syndic'=>'site')
102 as $id => $obj) {
103 if (is_int($id)) $id = $obj;
104 $_id_type = id_table_objet($id);
105 if (isset($GLOBALS['contexte'][$_id_type]) AND $id_type = $GLOBALS['contexte'][$_id_type]) {
106 $id_type = sql_getfetsel($_id_type, table_objet_sql($id), "$_id_type=".intval($id_type));
107 if ($id_type) {
108 $env[$_id_type] = $id_type;
109 $env['objet'] = $id;
110 $env['id_objet'] = $id_type;
111 $g = 'generer_url_ecrire_'.$obj;
112 $env['voir_'.$obj] =
113 str_replace('&amp;', '&', $g($id_type, '','', 'prop'));
114 if ($id == 'article' OR $id == 'breve') {
115 unset($env['id_rubrique']);
116 unset($env['voir_rubrique']);
117 if ($l = admin_stats($id, $id_type, $var_preview)) {
118 $env['visites'] = $l[0];
119 $env['popularite'] = $l[1];
120 $env['statistiques'] = $l[2];
121 }
122 if (admin_preview($id, $id_type))
123 $env['preview']=parametre_url(self(),'var_mode','preview','&');
124 }
125 }
126 }
127 }
128 return $env;
129 }
130
131
132 // http://doc.spip.org/@admin_preview
133 function admin_preview($id, $id_type)
134 {
135 if ($GLOBALS['var_preview']) return '';
136
137 if (!($id == 'article'
138 OR $id == 'breve'
139 OR $id == 'rubrique'
140 OR $id == 'syndic'))
141
142 return '';
143
144 include_spip('inc/autoriser');
145 if (!autoriser('previsualiser')) return '';
146
147 $notpub = sql_in("statut", array('prop', 'prive'));
148
149 if ($id == 'article' AND $GLOBALS['meta']['post_dates'] != 'oui')
150 $notpub .= " OR (statut='publie' AND date>".sql_quote(date('Y-m-d H:i:s')).")";
151
152 return sql_fetsel('1', table_objet_sql($id), id_table_objet($id)."=".$id_type." AND ($notpub)");
153 }
154
155 //
156 // Regler les boutons dans la langue de l'admin (sinon tant pis)
157 //
158
159 // http://doc.spip.org/@admin_lang
160 function admin_lang()
161 {
162 $alang = sql_getfetsel('lang', 'spip_auteurs', "login=" . sql_quote(preg_replace(',^@,','',@$_COOKIE['spip_admin'])));
163 if (!$alang) return '';
164
165 $l = lang_select($alang);
166 $alang = $GLOBALS['spip_lang'];
167 if ($l) lang_select();
168 return $alang;
169 }
170
171 // http://doc.spip.org/@admin_valider
172 function admin_valider()
173 {
174 global $xhtml;
175
176 return ((@$xhtml !== 'true') ?
177 (parametre_url(self(), 'var_mode', 'debug', '&')
178 .'&var_mode_affiche=validation') :
179 ('http://validator.w3.org/check?uri='
180 . rawurlencode("http://" . $_SERVER['HTTP_HOST'] . nettoyer_uri())));
181 }
182
183 // http://doc.spip.org/@admin_debug
184 function admin_debug()
185 {
186 return ((
187 (isset($GLOBALS['forcer_debug']) AND $GLOBALS['forcer_debug'])
188 OR (isset($GLOBALS['bouton_admin_debug']) AND $GLOBALS['bouton_admin_debug'])
189 OR (
190 isset($GLOBALS['var_mode'])
191 AND $GLOBALS['var_mode'] == 'debug'
192 AND $_COOKIE['spip_debug']
193 )
194 ) AND autoriser('debug')
195 )
196 ? parametre_url(self(),'var_mode', 'debug', '&'): '';
197 }
198
199
200 // Tant que les stats ne sont pas passees dans une extension, il faut les traiter ici
201 // http://doc.spip.org/@admin_stats
202 function admin_stats($id, $id_type, $var_preview)
203 {
204 if ($GLOBALS['meta']["activer_statistiques"] != "non"
205 AND $id = 'article'
206 AND !$var_preview
207 AND autoriser('voirstats')
208 ) {
209 $row = sql_fetsel("visites, popularite", "spip_articles", "id_article=$id_type AND statut='publie'");
210
211 if ($row) {
212 return array(intval($row['visites']),
213 ceil($row['popularite']),
214 str_replace('&amp;', '&', generer_url_ecrire_statistiques($id_type)));
215 }
216 }
217 return false;
218 }
219
220
221 ?>