3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2019 *
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 \***************************************************************************/
14 * Gestion des puces de statut sur les objets
15 * ainsi que des puces de changement rapide de statut.
17 * @package SPIP\Core\PuceStatut
20 if (!defined('_ECRIRE_INC_VERSION')) {
24 if (!defined('_ACTIVER_PUCE_RAPIDE')) {
26 * Activer le changement rapide de statut sur les listes d'objets ?
28 * Peut ralentir un site sur des listes très longues.
32 define('_ACTIVER_PUCE_RAPIDE', true);
36 * Afficher la puce statut d'un objet
38 * Utilise une fonction spécifique pour un type d'objet si elle existe, tel que
39 * puce_statut_$type_dist(), sinon tente avec puce_statut_changement_rapide().
41 * @see puce_statut_changement_rapide()
43 * @param int $id_objet
44 * Identifiant de l'objet
45 * @param string $statut
46 * Statut actuel de l'objet
47 * @param int $id_parent
48 * Identifiant du parent
52 * Indique s'il ne faut renvoyer que le coeur du menu car on est
53 * dans une requete ajax suite à un post de changement rapide
54 * @param bool $menu_rapide
55 * Indique si l'on peut changer le statut, ou si on l'affiche simplement
57 * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
59 function inc_puce_statut_dist(
65 $menu_rapide = _ACTIVER_PUCE_RAPIDE
67 static $f_puce_statut = array();
68 $type = objet_type($type);
69 // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
70 if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) {
71 $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
73 if ($f_puce_statut[$type]) {
74 return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
77 // si statut_image trouve quelque chose (et '' est quelque chose)
78 // composer une puce, avec si possible changement rapide
79 elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
81 } // sinon fausse puce avec le type de l'image
83 return http_img_pack("$type-16.png", '');
88 * Récuperer l'image correspondant au statut pour un objet éditorial indiqué
90 * Retrouve l'image correspondant au statut, telle que declarée dans
91 * `declarer_tables_objets_sql` sous la forme :
95 * 'imagepardefaut.png',
96 * 'statut1' => 'imagestatut1.png',
97 * 'statut2' => 'imagestatut2.png',
102 * Mettre une chaine vide pour ne pas avoir d'image pour un statut particulier.
104 * Si rien n'est declaré et que le statut est dans un des cas connus habituels
105 * (prepa, prop, publie, refuse, poubelle), alors on renvoie l'image par défaut pour ce statut
107 * @param string $objet
108 * @param string $statut
109 * @return string|null
110 * null si pas capable de déterminer l'image
112 function statut_image($objet, $statut) {
114 $table = table_objet_sql($objet);
115 $desc = lister_tables_objets_sql($table);
116 if (isset($desc['statut_images'])) {
117 // si une declaration statut_images
118 // mais rien pour le statut demande, ne rien afficher
120 if (isset($desc['statut_images'][$statut])) {
121 $src = $desc['statut_images'][$statut];
122 } // sinon image par defaut ?
123 elseif (isset($desc['statut_images'][0])) {
124 $src = $desc['statut_images'][0];
129 $src = 'puce-preparer-8.png';
132 $src = 'puce-proposer-8.png';
135 $src = 'puce-publier-8.png';
138 $src = 'puce-refuser-8.png';
142 $src = 'puce-supprimer-8.png';
151 * Récupérer le titre correspondant au statut pour un objet éditorial indiqué
153 * Retrouve le titre correspondant au statut, tel qu'il a été declaré dans
154 * `declarer_tables_objets_sql` sous la forme :
158 * 'titre par defaut',
159 * 'statut1' => 'titre statut 1',
160 * 'statut2' => 'titre statut 2',
165 * Mettre une chaine vide pour ne pas avoir de titre pour un statut particulier.
167 * Si rien n'est declaré et que le statut est dans un des cas connus habituels
168 * (prepa, prop, publie, refuse, poubelle), alors on renvoie le texte par défaut pour ce statut
170 * @param string $objet
171 * @param string $statut
174 function statut_titre($objet, $statut) {
176 $table = table_objet_sql($objet);
177 $desc = lister_tables_objets_sql($table);
178 if (isset($desc['statut_titres'])) {
179 // si une declaration statut_titres
180 // mais rien pour le statut demande, ne rien afficher
181 if (isset($desc['statut_titres'][$statut])) {
182 $titre = $desc['statut_titres'][$statut];
183 } // sinon image par defaut ?
184 elseif (isset($desc['statut_titres'][0])) {
185 $titre = $desc['statut_titres'][0];
190 $titre = 'texte_statut_en_cours_redaction';
193 $titre = 'texte_statut_propose_evaluation';
196 $titre = 'texte_statut_publie';
199 $titre = 'texte_statut_refuse';
203 $titre = 'texte_statut_poubelle';
208 return $titre ?
_T($titre) : '';
213 * Recuperer le texte correspondant au choix de statut, tel que declare dans
214 * declarer_tables_objets_sql
216 * array('statut1'=>'texte statut 1','statut2'=>'texte statut 2' ...)
217 * mettre une chaine vide pour ne pas proposer un statut
218 * les statuts seront proposes dans le meme ordre que dans la declaration
220 * si rien de declare et que le statut est dans les cas connus (prepa, prop, publie, refuse, poubelle)
221 * renvoyer le texte par defaut
223 * @param string $objet
224 * @param string $statut
227 function statut_texte_instituer($objet, $statut) {
229 $table = table_objet_sql($objet);
230 $desc = lister_tables_objets_sql($table);
231 if (isset($desc['statut_textes_instituer'])) {
232 // si une declaration statut_titres
233 // mais rien pour le statut demande, ne rien afficher
234 if (isset($desc['statut_textes_instituer'][$statut])) {
235 $texte = $desc['statut_textes_instituer'][$statut];
240 $texte = 'texte_statut_en_cours_redaction';
243 $texte = 'texte_statut_propose_evaluation';
246 $texte = 'texte_statut_publie';
249 $texte = 'texte_statut_refuse';
253 $texte = 'texte_statut_poubelle';
258 return $texte ?
_T($texte) : '';
263 * Afficher la puce statut d'un auteur
265 * Ne semble plus servir : desactive
266 * Hack de compatibilite: les appels directs ont un $type != 'auteur'
267 * si l'auteur ne peut pas se connecter
270 * @param string $statut
271 * @param int $id_parent
272 * @param string $type
273 * @param string $ajax
274 * @param bool $menu_rapide
277 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE
) {
278 $img = statut_image('auteur', $statut);
282 $alt = statut_titre('auteur', $statut);
288 if ($type != 'auteur') {
289 $img2 = chemin_image('del-16.png');
290 $titre = _T('titre_image_redacteur');
291 $fond = http_style_background($img2, 'top left no-repeat;');
297 return http_img_pack($img, $alt, $fond, $alt);
301 function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE
) {
302 return http_img_pack('rubrique-16.png', '');
306 * Retourne le contenu d'une puce avec changement de statut possible
307 * si on en a l'autorisation, sinon simplement l'image de la puce
310 * Identifiant de l'objet
311 * @param string $statut
312 * Statut actuel de l'objet
313 * @param int $id_rubrique
314 * Identifiant du parent, une rubrique
315 * @param string $type
318 * Indique s'il ne faut renvoyer que le coeur du menu car on est
319 * dans une requete ajax suite à un post de changement rapide
320 * @param bool $menu_rapide
321 * Indique si l'on peut changer le statut, ou si on l'affiche simplement
323 * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
325 function puce_statut_changement_rapide(
331 $menu_rapide = _ACTIVER_PUCE_RAPIDE
333 $src = statut_image($type, $statut);
344 $ajax_node = " class='imgstatut$type$id'";
348 $t = statut_titre($type, $statut);
349 $inser_puce = http_img_pack($src, $t, $ajax_node, $t);
355 $table = table_objet_sql($type);
356 $desc = lister_tables_objets_sql($table);
357 if (!isset($desc['statut_textes_instituer'])) {
361 if (!function_exists('autoriser')) {
362 include_spip('inc/autoriser');
365 // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
367 if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
370 } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
372 if (!autoriser('instituer', $type, $id, null, array('statut' => 'publie'))) {
377 $coord = array_flip(array_keys($desc['statut_textes_instituer']));
378 if (!isset($coord[$statut])) {
382 $unit = 8/*widh de img*/ +
4/*padding*/
384 $margin = 4; /* marge a gauche + droite */
385 $zero = 1 /*border*/ +
$margin / 2 +
2 /*padding*/
387 $clip = $zero +
($unit * $coord[$statut]);
390 $width = $unit * count($desc['statut_textes_instituer']) +
$margin;
391 $out = "<span class='puce_objet_fixe $type'>"
394 . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
396 foreach ($desc['statut_textes_instituer'] as $s => $t) {
397 $out .= afficher_script_statut($id, $type, -$zero - $i++
* $unit, statut_image($type, $s), $s, _T($t));
404 $nom = "puce_statut_";
405 $action = generer_url_ecrire('puce_statut', "", true);
406 $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
407 $over = " onmouseover=\"$action\"";
409 $lang_dir = lang_dir(lang_typo());
411 return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
418 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
419 $h = generer_action_auteur("instituer_objet", "$type-$id-$statut");
420 $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
421 $t = supprimer_tags($titre);
423 return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>";
427 // La couleur du statut
429 function puce_statut($statut, $atts = '') {
430 $src = statut_image('article', $statut);
435 return http_img_pack($src, statut_titre('article', $statut), $atts);