1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
|
<?php
/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
* Copyright (c) 2001-2019 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
/**
* Gestion des puces de statut sur les objets
* ainsi que des puces de changement rapide de statut.
*
* @package SPIP\Core\PuceStatut
**/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
if (!defined('_ACTIVER_PUCE_RAPIDE')) {
/**
* Activer le changement rapide de statut sur les listes d'objets ?
*
* Peut ralentir un site sur des listes très longues.
*
* @var bool
**/
define('_ACTIVER_PUCE_RAPIDE', true);
}
/**
* Afficher la puce statut d'un objet
*
* Utilise une fonction spécifique pour un type d'objet si elle existe, tel que
* puce_statut_$type_dist(), sinon tente avec puce_statut_changement_rapide().
*
* @see puce_statut_changement_rapide()
*
* @param int $id_objet
* Identifiant de l'objet
* @param string $statut
* Statut actuel de l'objet
* @param int $id_parent
* Identifiant du parent
* @param string $type
* Type d'objet
* @param bool $ajax
* Indique s'il ne faut renvoyer que le coeur du menu car on est
* dans une requete ajax suite à un post de changement rapide
* @param bool $menu_rapide
* Indique si l'on peut changer le statut, ou si on l'affiche simplement
* @return string
* Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
*/
function inc_puce_statut_dist(
$id_objet,
$statut,
$id_parent,
$type,
$ajax = false,
$menu_rapide = _ACTIVER_PUCE_RAPIDE
) {
static $f_puce_statut = array();
$type = objet_type($type);
// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) {
$f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
}
if ($f_puce_statut[$type]) {
return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
}
// si statut_image trouve quelque chose (et '' est quelque chose)
// composer une puce, avec si possible changement rapide
elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
return $puce;
} // sinon fausse puce avec le type de l'image
else {
return http_img_pack("$type-16.png", '');
}
}
/**
* Récuperer l'image correspondant au statut pour un objet éditorial indiqué
*
* Retrouve l'image correspondant au statut, telle que declarée dans
* `declarer_tables_objets_sql` sous la forme :
*
* ```
* array(
* 'imagepardefaut.png',
* 'statut1' => 'imagestatut1.png',
* 'statut2' => 'imagestatut2.png',
* ...
* )
* ```
*
* Mettre une chaine vide pour ne pas avoir d'image pour un statut particulier.
*
* Si rien n'est declaré et que le statut est dans un des cas connus habituels
* (prepa, prop, publie, refuse, poubelle), alors on renvoie l'image par défaut pour ce statut
*
* @param string $objet
* @param string $statut
* @return string|null
* null si pas capable de déterminer l'image
*/
function statut_image($objet, $statut) {
$src = null;
$table = table_objet_sql($objet);
$desc = lister_tables_objets_sql($table);
if (isset($desc['statut_images'])) {
// si une declaration statut_images
// mais rien pour le statut demande, ne rien afficher
$src = '';
if (isset($desc['statut_images'][$statut])) {
$src = $desc['statut_images'][$statut];
} // sinon image par defaut ?
elseif (isset($desc['statut_images'][0])) {
$src = $desc['statut_images'][0];
}
} else {
switch ($statut) {
case 'prepa':
$src = 'puce-preparer-8.png';
break;
case 'prop':
$src = 'puce-proposer-8.png';
break;
case 'publie':
$src = 'puce-publier-8.png';
break;
case 'refuse':
$src = 'puce-refuser-8.png';
break;
case 'poubelle':
case 'poub':
$src = 'puce-supprimer-8.png';
break;
}
}
return $src;
}
/**
* Récupérer le titre correspondant au statut pour un objet éditorial indiqué
*
* Retrouve le titre correspondant au statut, tel qu'il a été declaré dans
* `declarer_tables_objets_sql` sous la forme :
*
* ```
* array(
* 'titre par defaut',
* 'statut1' => 'titre statut 1',
* 'statut2' => 'titre statut 2',
* ...
* )
* ```
*
* Mettre une chaine vide pour ne pas avoir de titre pour un statut particulier.
*
* Si rien n'est declaré et que le statut est dans un des cas connus habituels
* (prepa, prop, publie, refuse, poubelle), alors on renvoie le texte par défaut pour ce statut
*
* @param string $objet
* @param string $statut
* @return string
*/
function statut_titre($objet, $statut) {
$titre = '';
$table = table_objet_sql($objet);
$desc = lister_tables_objets_sql($table);
if (isset($desc['statut_titres'])) {
// si une declaration statut_titres
// mais rien pour le statut demande, ne rien afficher
if (isset($desc['statut_titres'][$statut])) {
$titre = $desc['statut_titres'][$statut];
} // sinon image par defaut ?
elseif (isset($desc['statut_titres'][0])) {
$titre = $desc['statut_titres'][0];
}
} else {
switch ($statut) {
case 'prepa':
$titre = 'texte_statut_en_cours_redaction';
break;
case 'prop':
$titre = 'texte_statut_propose_evaluation';
break;
case 'publie':
$titre = 'texte_statut_publie';
break;
case 'refuse':
$titre = 'texte_statut_refuse';
break;
case 'poubelle':
case 'poub':
$titre = 'texte_statut_poubelle';
break;
}
}
return $titre ? _T($titre) : '';
}
/**
* Recuperer le texte correspondant au choix de statut, tel que declare dans
* declarer_tables_objets_sql
* sous la forme
* array('statut1'=>'texte statut 1','statut2'=>'texte statut 2' ...)
* mettre une chaine vide pour ne pas proposer un statut
* les statuts seront proposes dans le meme ordre que dans la declaration
*
* si rien de declare et que le statut est dans les cas connus (prepa, prop, publie, refuse, poubelle)
* renvoyer le texte par defaut
*
* @param string $objet
* @param string $statut
* @return string
*/
function statut_texte_instituer($objet, $statut) {
$texte = '';
$table = table_objet_sql($objet);
$desc = lister_tables_objets_sql($table);
if (isset($desc['statut_textes_instituer'])) {
// si une declaration statut_titres
// mais rien pour le statut demande, ne rien afficher
if (isset($desc['statut_textes_instituer'][$statut])) {
$texte = $desc['statut_textes_instituer'][$statut];
}
} else {
switch ($statut) {
case 'prepa':
$texte = 'texte_statut_en_cours_redaction';
break;
case 'prop':
$texte = 'texte_statut_propose_evaluation';
break;
case 'publie':
$texte = 'texte_statut_publie';
break;
case 'refuse':
$texte = 'texte_statut_refuse';
break;
case 'poubelle':
case 'poub':
$texte = 'texte_statut_poubelle';
break;
}
}
return $texte ? _T($texte) : '';
}
/**
* Afficher la puce statut d'un auteur
*
* Ne semble plus servir : desactive
* Hack de compatibilite: les appels directs ont un $type != 'auteur'
* si l'auteur ne peut pas se connecter
*
* @param int $id
* @param string $statut
* @param int $id_parent
* @param string $type
* @param string $ajax
* @param bool $menu_rapide
* @return string
*/
function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
$img = statut_image('auteur', $statut);
if (!$img) {
return '';
}
$alt = statut_titre('auteur', $statut);
$fond = '';
$titre = '';
/*
if ($type != 'auteur') {
$img2 = chemin_image('del-16.png');
$titre = _T('titre_image_redacteur');
$fond = http_style_background($img2, 'top left no-repeat;');
}
else {
}
*/
return http_img_pack($img, $alt, $fond, $alt);
}
function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
return http_img_pack('rubrique-16.png', '');
}
/**
* Retourne le contenu d'une puce avec changement de statut possible
* si on en a l'autorisation, sinon simplement l'image de la puce
*
* @param int $id
* Identifiant de l'objet
* @param string $statut
* Statut actuel de l'objet
* @param int $id_rubrique
* Identifiant du parent, une rubrique
* @param string $type
* Type d'objet
* @param bool $ajax
* Indique s'il ne faut renvoyer que le coeur du menu car on est
* dans une requete ajax suite à un post de changement rapide
* @param bool $menu_rapide
* Indique si l'on peut changer le statut, ou si on l'affiche simplement
* @return string
* Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
**/
function puce_statut_changement_rapide(
$id,
$statut,
$id_rubrique,
$type = 'article',
$ajax = false,
$menu_rapide = _ACTIVER_PUCE_RAPIDE
) {
$src = statut_image($type, $statut);
if (!$src) {
return $src;
}
if (!$id
or !_SPIP_AJAX
or !$menu_rapide
) {
$ajax_node = '';
} else {
$ajax_node = " class='imgstatut$type$id'";
}
$t = statut_titre($type, $statut);
$inser_puce = http_img_pack($src, $t, $ajax_node, $t);
if (!$ajax_node) {
return $inser_puce;
}
$table = table_objet_sql($type);
$desc = lister_tables_objets_sql($table);
if (!isset($desc['statut_textes_instituer'])) {
return $inser_puce;
}
if (!function_exists('autoriser')) {
include_spip('inc/autoriser');
}
// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
if ($id_rubrique) {
if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
return $inser_puce;
}
} // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
else {
if (!autoriser('instituer', $type, $id, null, array('statut' => 'publie'))) {
return $inser_puce;
}
}
$coord = array_flip(array_keys($desc['statut_textes_instituer']));
if (!isset($coord[$statut])) {
return $inser_puce;
}
$unit = 8/*widh de img*/ + 4/*padding*/
;
$margin = 4; /* marge a gauche + droite */
$zero = 1 /*border*/ + $margin / 2 + 2 /*padding*/
;
$clip = $zero + ($unit * $coord[$statut]);
if ($ajax) {
$width = $unit * count($desc['statut_textes_instituer']) + $margin;
$out = "<span class='puce_objet_fixe $type'>"
. $inser_puce
. "</span>"
. "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
$i = 0;
foreach ($desc['statut_textes_instituer'] as $s => $t) {
$out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
}
$out .= "</span>";
return $out;
} else {
$nom = "puce_statut_";
$action = generer_url_ecrire('puce_statut', "", true);
$action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
$over = " onmouseover=\"$action\"";
$lang_dir = lang_dir(lang_typo());
return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
. $inser_puce
. '</span>';
}
}
function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
$h = generer_action_auteur("instituer_objet", "$type-$id-$statut");
$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
$t = supprimer_tags($titre);
return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>";
}
// compat
// La couleur du statut
function puce_statut($statut, $atts = '') {
$src = statut_image('article', $statut);
if (!$src) {
return '';
}
return http_img_pack($src, statut_titre('article', $statut), $atts);
}
|