9c27e6f6d56cf3dee7a1cdea12dad5f62f8df9c1
[ptitvelo/web/www.git] / www / ecrire / inc / puce_statut.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
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 if (!defined('_ACTIVER_PUCE_RAPIDE'))
15 define('_ACTIVER_PUCE_RAPIDE', true);
16
17 /**
18 * Afficher la puce statut d'un objet
19 *
20 *
21 * http://doc.spip.org/@inc_puce_statut_dist
22 *
23 * @param int $id_objet
24 * @param string $statut
25 * @param int $id_parent
26 * @param string $type
27 * @param bool $ajax
28 * indique qu'il ne faut renvoyer que le coeur du menu car on est dans la requete ajax post changement rapide
29 * @param bool $menu_rapide
30 * @return string
31 */
32 function inc_puce_statut_dist($id_objet, $statut, $id_parent, $type, $ajax=false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
33 static $f_puce_statut = array();
34 $type = objet_type($type);
35 // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
36 if (!isset($f_puce_statut[$type]) OR is_null($f_puce_statut[$type]))
37 $f_puce_statut[$type] = charger_fonction($type,'puce_statut',true);
38 if ($f_puce_statut[$type])
39 return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
40
41 // si statut_image trouve quelque chose (et '' est quelque chose)
42 // composer une puce, avec si possible changement rapide
43 elseif(!is_null($puce=puce_statut_changement_rapide($id_objet,$statut,$id_parent,$type,$ajax,$menu_rapide))){
44 return $puce;
45 }
46
47 // sinon fausse puce avec le type de l'image
48 else
49 return http_img_pack("$type-16.png",'');
50 }
51
52 /**
53 * Recuperer l'image correspondant au statut, telle que declaree dans
54 * declarer_tables_objets_sql
55 * sous la forme
56 * array('imagepardefaut.png','statut1'=>'imagestatut1.png','statut2'=>imagestatut2.png' ...)
57 * mettre une chaine vide pour ne pas avoir d'image pour un statut particulier
58 *
59 * si rien de declare et que le statut est dans les cas connus (prepa, prop, publie, refuse, poubelle)
60 * renvoyer l'image par defaut
61 *
62 * @param string $objet
63 * @param string $statut
64 * @return string
65 * null si pas capable de determiner l'image
66 */
67 function statut_image($objet,$statut){
68 $src = null;
69 $table = table_objet_sql($objet);
70 $desc = lister_tables_objets_sql($table);
71 if (isset($desc['statut_images'])){
72 // si une declaration statut_images
73 // mais rien pour le statut demande, ne rien afficher
74 $src = '';
75 if (isset($desc['statut_images'][$statut]))
76 $src = $desc['statut_images'][$statut];
77 // sinon image par defaut ?
78 elseif (isset($desc['statut_images'][0]))
79 $src = $desc['statut_images'][0];
80 }
81 else {
82 switch ($statut) {
83 case 'prepa':
84 $src = 'puce-preparer-8.png';
85 break;
86 case 'prop':
87 $src = 'puce-proposer-8.png';
88 break;
89 case 'publie':
90 $src = 'puce-publier-8.png';
91 break;
92 case 'refuse':
93 $src = 'puce-refuser-8.png';
94 break;
95 case 'poubelle':
96 case 'poub':
97 $src = 'puce-supprimer-8.png';
98 break;
99 }
100 }
101 return $src;
102 }
103
104 /**
105 * Recuperer le titre correspondant au statut, tel que declaree dans
106 * declarer_tables_objets_sql
107 * sous la forme
108 * array('titre par defaut','statut1'=>'titre statut 1','statut2'=>'titre statut 2' ...)
109 * mettre une chaine vide pour ne pas avoir de titre pour un statut particulier
110 *
111 * si rien de declare et que le statut est dans les cas connus (prepa, prop, publie, refuse, poubelle)
112 * renvoyer le texte par defaut
113 *
114 * @param string $objet
115 * @param string $statut
116 * @return string
117 */
118 function statut_titre($objet,$statut){
119 $titre = '';
120 $table = table_objet_sql($objet);
121 $desc = lister_tables_objets_sql($table);
122 if (isset($desc['statut_titres'])){
123 // si une declaration statut_titres
124 // mais rien pour le statut demande, ne rien afficher
125 if (isset($desc['statut_titres'][$statut]))
126 $titre = $desc['statut_titres'][$statut];
127 // sinon image par defaut ?
128 elseif (isset($desc['statut_titres'][0]))
129 $titre = $desc['statut_titres'][0];
130 }
131 else {
132 switch ($statut) {
133 case 'prepa':
134 $titre = 'texte_statut_en_cours_redaction';
135 break;
136 case 'prop':
137 $titre = 'texte_statut_propose_evaluation';
138 break;
139 case 'publie':
140 $titre = 'texte_statut_publie';
141 break;
142 case 'refuse':
143 $titre = 'texte_statut_refuse';
144 break;
145 case 'poubelle':
146 case 'poub':
147 $titre = 'texte_statut_poubelle';
148 break;
149 }
150 }
151 return $titre?_T($titre):'';
152 }
153
154
155 /**
156 * Recuperer le texte correspondant au choix de statut, tel que declare dans
157 * declarer_tables_objets_sql
158 * sous la forme
159 * array('statut1'=>'texte statut 1','statut2'=>'texte statut 2' ...)
160 * mettre une chaine vide pour ne pas proposer un statut
161 * les statuts seront proposes dans le meme ordre que dans la declaration
162 *
163 * si rien de declare et que le statut est dans les cas connus (prepa, prop, publie, refuse, poubelle)
164 * renvoyer le texte par defaut
165 *
166 * @param string $objet
167 * @param string $statut
168 * @return string
169 */
170 function statut_texte_instituer($objet,$statut){
171 $texte = '';
172 $table = table_objet_sql($objet);
173 $desc = lister_tables_objets_sql($table);
174 if (isset($desc['statut_textes_instituer'])){
175 // si une declaration statut_titres
176 // mais rien pour le statut demande, ne rien afficher
177 if (isset($desc['statut_textes_instituer'][$statut]))
178 $texte = $desc['statut_textes_instituer'][$statut];
179 }
180 else {
181 switch ($statut) {
182 case 'prepa':
183 $texte = 'texte_statut_en_cours_redaction';
184 break;
185 case 'prop':
186 $texte = 'texte_statut_propose_evaluation';
187 break;
188 case 'publie':
189 $texte = 'texte_statut_publie';
190 break;
191 case 'refuse':
192 $texte = 'texte_statut_refuse';
193 break;
194 case 'poubelle':
195 case 'poub':
196 $texte = 'texte_statut_poubelle';
197 break;
198 }
199 }
200 return $texte?_T($texte):'';
201 }
202
203
204 /**
205 * Afficher la puce statut d'un auteur
206 *
207 * Ne semble plus servir : desactive
208 * Hack de compatibilite: les appels directs ont un $type != 'auteur'
209 * si l'auteur ne peut pas se connecter
210 *
211 * http://doc.spip.org/@puce_statut_auteur_dist
212 *
213 * @param int $id
214 * @param string $statut
215 * @param int $id_parent
216 * @param string $type
217 * @param string $ajax
218 * @param bool $menu_rapide
219 * @return string
220 */
221 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax='', $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
222 $img = statut_image('auteur',$statut);
223 if (!$img) return '';
224 $alt = statut_titre('auteur',$statut);
225
226 $fond = ''; $titre = '';
227 /*
228 if ($type != 'auteur') {
229 $img2 = chemin_image('del-16.png');
230 $titre = _T('titre_image_redacteur');
231 $fond = http_style_background($img2, 'top left no-repeat;');
232 }
233 else {
234 }
235 */
236 return http_img_pack($img, $alt, $fond, $alt);
237 }
238
239
240 // http://doc.spip.org/@puce_statut_rubrique_dist
241 function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax='',$menu_rapide=_ACTIVER_PUCE_RAPIDE) {
242 return http_img_pack('rubrique-16.png', '');
243 }
244
245 // http://doc.spip.org/@puce_statut_article_dist
246 function puce_statut_changement_rapide($id, $statut, $id_rubrique, $type='article', $ajax = false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
247 $src = statut_image($type, $statut);
248 if (!$src)
249 return $src;
250
251 if (!$id
252 OR !_SPIP_AJAX
253 OR !$menu_rapide) {
254 $ajax_node ='';
255 }
256 else
257 $ajax_node = " class='imgstatut$type$id'";
258
259
260 $t = statut_titre($type, $statut);
261 $inser_puce = http_img_pack($src,$t,$ajax_node,$t);
262
263 if (!$ajax_node)
264 return $inser_puce;
265
266 $table = table_objet_sql($type);
267 $desc = lister_tables_objets_sql($table);
268 if (!isset($desc['statut_textes_instituer']))
269 return $inser_puce;
270
271 // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
272 if ($id_rubrique){
273 if (!autoriser('publierdans', 'rubrique', $id_rubrique))
274 return $inser_puce;
275 }
276 // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
277 else {
278 if (!autoriser('instituer', $type, $id, null, array('statut'=>'publie')))
279 return $inser_puce;
280 }
281
282 $coord = array_flip(array_keys($desc['statut_textes_instituer']));
283 if (!isset($coord[$statut]))
284 return $inser_puce;
285
286 $unit = 8/*widh de img*/+4/*padding*/;
287 $margin = 4; /* marge a gauche + droite */
288 $zero = 1 /*border*/ + $margin/2 + 2 /*padding*/;
289 $clip = $zero+ ($unit*$coord[$statut]);
290
291 if ($ajax){
292 $width = $unit*count($desc['statut_textes_instituer'])+$margin;
293 $out = "<span class='puce_objet_fixe $type'>"
294 . $inser_puce
295 . "</span>"
296 . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
297 $i=0;
298 foreach($desc['statut_textes_instituer'] as $s=>$t){
299 $out .= afficher_script_statut($id, $type, -$zero-$i++*$unit, statut_image($type,$s), $s, _T($t));
300 }
301 $out .= "</span>";
302 return $out;
303 }
304 else {
305
306 $nom = "puce_statut_";
307 $action = generer_url_ecrire('puce_statut',"",true);
308 $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
309 $over = " onmouseover=\"$action\"";
310
311 $lang_dir = lang_dir(lang_typo());
312 return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
313 . $inser_puce
314 . '</span>';
315 }
316 }
317
318 // http://doc.spip.org/@afficher_script_statut
319 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act='') {
320 $h = generer_action_auteur("instituer_objet","$type-$id-$statut");
321 $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
322 $t = supprimer_tags($titre);
323 return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img,$t)."</a>";
324 }
325
326 // compat
327 // La couleur du statut
328 // http://doc.spip.org/@puce_statut
329
330 function puce_statut($statut, $atts='') {
331 $src = statut_image('article',$statut);
332 if (!$src) return '';
333 return http_img_pack($src, statut_titre('article',$statut), $atts);
334 }
335
336 ?>