podcast/action/supprimer_podcast.php
2021-02-10 07:46:37 +01:00

119 lines
3.5 KiB
PHP

<?php
/**
* Utilisation de l'action supprimer pour l'objet podcast
*
* @plugin podcast
* @copyright 2021
* @author chankalan,vcalame
* @licence GNU/GPL
* @package SPIP\Podcast\Action
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Action pour supprimer un·e podcast
*
* Vérifier l'autorisation avant d'appeler l'action.
*
* @example
* ```
* [(#AUTORISER{supprimer, podcast, #ID_PODCAST}|oui)
* [(#BOUTON_ACTION{<:podcast:supprimer_podcast:/>,
* #URL_ACTION_AUTEUR{supprimer_podcast, #ID_PODCAST, #URL_ECRIRE{podcasts}},
* danger, <:podcast:confirmer_supprimer_podcast:/>})]
* ]
* ```
*
* @example
* ```
* [(#AUTORISER{supprimer, podcast, #ID_PODCAST}|oui)
* [(#BOUTON_ACTION{
* [(#CHEMIN_IMAGE{podcast-del-24.png}|balise_img{<:podcast:supprimer_podcast:/>}|concat{' ',#VAL{<:podcast:supprimer_podcast:/>}|wrap{<b>}}|trim)],
* #URL_ACTION_AUTEUR{supprimer_podcast, #ID_PODCAST, #URL_ECRIRE{podcasts}},
* icone s24 horizontale danger podcast-del-24, <:podcast:confirmer_supprimer_podcast:/>})]
* ]
* ```
*
* @example
* ```
* if (autoriser('supprimer', 'podcast', $id_podcast)) {
* $supprimer_podcast = charger_fonction('supprimer_podcast', 'action');
* $supprimer_podcast($id_podcast);
* }
* ```
*
* @param null|int $arg
* Identifiant à supprimer.
* En absence de id utilise l'argument de l'action sécurisée.
**/
function action_supprimer_podcast_dist($arg=null) {
$need_confirm = false;
if (is_null($arg)){
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
$need_confirm = true;
}
$arg = intval($arg);
if ($need_confirm){
$ok = confirmer_supprimer_podcast_avant_action(_T('podcast:confirmer_supprimer_podcast'), _T('item_oui') . '! ' . _T('podcast:supprimer_podcast'));
}
// cas suppression
if (autoriser('supprimer', 'podcast', $arg)) {
if ($arg) {
$objet = sql_fetsel('*', 'spip_podcasts', 'id_podcast=' . sql_quote($arg));
$qui = (!empty($GLOBALS['visiteur_session']['id_auteur']) ? 'auteur #' . $GLOBALS['visiteur_session']['id_auteur'] : 'IP ' . $GLOBALS['ip']);
spip_log("SUPPRESSION podcast#$arg par $qui : " . json_encode($objet), "suppressions" . _LOG_INFO_IMPORTANTE);
sql_delete('spip_podcasts', 'id_podcast=' . sql_quote($arg));
// invalider le cache
include_spip('inc/invalideur');
suivre_invalideur("id='podcast/$arg'");
}
else {
spip_log("action_supprimer_podcast_dist $arg pas compris");
}
}
}
/**
* Confirmer avant suppression si on arrive par un bouton action
* @param string $titre
* @param string $titre_bouton
* @param string|null $url_action
* @return bool
*/
function confirmer_supprimer_podcast_avant_action($titre, $titre_bouton, $url_action=null) {
if (!$url_action) {
$url_action = self();
$action = _request('action');
$url_action = parametre_url($url_action, 'action', $action, '&');
}
else {
$action = parametre_url($url_action, 'action');
}
$arg = parametre_url($url_action, 'arg');
$confirm = md5("$action:$arg:".realpath(__FILE__));
if (_request('confirm_action') === $confirm) {
return true;
}
$url_confirm = parametre_url($url_action, "confirm_action", $confirm, '&');
include_spip("inc/filtres");
$bouton_action = bouton_action($titre_bouton, $url_confirm);
$corps = "<div style='text-align:center;'>$bouton_action</div>";
include_spip("inc/minipres");
echo minipres($titre,$corps);
exit;
}