3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2016 *
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;
14 if (!defined('_ACTIVER_PUCE_RAPIDE'))
15 define('_ACTIVER_PUCE_RAPIDE', true);
18 * Afficher la puce statut d'un objet
21 * http://doc.spip.org/@inc_puce_statut_dist
23 * @param int $id_objet
24 * @param string $statut
25 * @param int $id_parent
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
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);
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))){
47 // sinon fausse puce avec le type de l'image
49 return http_img_pack("$type-16.png",'');
53 * Recuperer l'image correspondant au statut, telle que declaree dans
54 * declarer_tables_objets_sql
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
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
62 * @param string $objet
63 * @param string $statut
65 * null si pas capable de determiner l'image
67 function statut_image($objet,$statut){
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
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];
84 $src = 'puce-preparer-8.png';
87 $src = 'puce-proposer-8.png';
90 $src = 'puce-publier-8.png';
93 $src = 'puce-refuser-8.png';
97 $src = 'puce-supprimer-8.png';
105 * Recuperer le titre correspondant au statut, tel que declaree dans
106 * declarer_tables_objets_sql
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
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
114 * @param string $objet
115 * @param string $statut
118 function statut_titre($objet,$statut){
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];
134 $titre = 'texte_statut_en_cours_redaction';
137 $titre = 'texte_statut_propose_evaluation';
140 $titre = 'texte_statut_publie';
143 $titre = 'texte_statut_refuse';
147 $titre = 'texte_statut_poubelle';
151 return $titre?
_T($titre):'';
156 * Recuperer le texte correspondant au choix de statut, tel que declare dans
157 * declarer_tables_objets_sql
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
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
166 * @param string $objet
167 * @param string $statut
170 function statut_texte_instituer($objet,$statut){
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];
183 $texte = 'texte_statut_en_cours_redaction';
186 $texte = 'texte_statut_propose_evaluation';
189 $texte = 'texte_statut_publie';
192 $texte = 'texte_statut_refuse';
196 $texte = 'texte_statut_poubelle';
200 return $texte?
_T($texte):'';
205 * Afficher la puce statut d'un auteur
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
211 * http://doc.spip.org/@puce_statut_auteur_dist
214 * @param string $statut
215 * @param int $id_parent
216 * @param string $type
217 * @param string $ajax
218 * @param bool $menu_rapide
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);
226 $fond = ''; $titre = '';
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;');
236 return http_img_pack($img, $alt, $fond, $alt);
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', '');
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);
257 $ajax_node = " class='imgstatut$type$id'";
260 $t = statut_titre($type, $statut);
261 $inser_puce = http_img_pack($src,$t,$ajax_node,$t);
266 $table = table_objet_sql($type);
267 $desc = lister_tables_objets_sql($table);
268 if (!isset($desc['statut_textes_instituer']))
271 include_spip('inc/autoriser');
272 // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
274 if (!autoriser('publierdans', 'rubrique', $id_rubrique))
277 // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
279 if (!autoriser('instituer', $type, $id, null, array('statut'=>'publie')))
283 $coord = array_flip(array_keys($desc['statut_textes_instituer']));
284 if (!isset($coord[$statut]))
287 $unit = 8/*widh de img*/+
4/*padding*/;
288 $margin = 4; /* marge a gauche + droite */
289 $zero = 1 /*border*/ +
$margin/2 +
2 /*padding*/;
290 $clip = $zero+
($unit*$coord[$statut]);
293 $width = $unit*count($desc['statut_textes_instituer'])+
$margin;
294 $out = "<span class='puce_objet_fixe $type'>"
297 . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
299 foreach($desc['statut_textes_instituer'] as $s=>$t){
300 $out .= afficher_script_statut($id, $type, -$zero-$i++
*$unit, statut_image($type,$s), $s, _T($t));
307 $nom = "puce_statut_";
308 $action = generer_url_ecrire('puce_statut',"",true);
309 $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
310 $over = " onmouseover=\"$action\"";
312 $lang_dir = lang_dir(lang_typo());
313 return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
319 // http://doc.spip.org/@afficher_script_statut
320 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act='') {
321 $h = generer_action_auteur("instituer_objet","$type-$id-$statut");
322 $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
323 $t = supprimer_tags($titre);
324 return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img,$t)."</a>";
328 // La couleur du statut
329 // http://doc.spip.org/@puce_statut
331 function puce_statut($statut, $atts='') {
332 $src = statut_image('article',$statut);
333 if (!$src) return '';
334 return http_img_pack($src, statut_titre('article',$statut), $atts);