podcast/podcast_pipelines.php

97 lines
2.4 KiB
PHP

<?php
/**
* Utilisations de pipelines par podcast
*
* @plugin podcast
* @copyright 2021
* @author chankalan,vcalame
* @licence GNU/GPL
* @package SPIP\Podcast\Pipelines
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/*
* Un fichier de pipelines permet de regrouper
* les fonctions de branchement de votre plugin
* sur des pipelines existants.
*/
/**
* Ajouter les objets sur les vues des parents directs
*
* @pipeline affiche_enfants
* @param array $flux Données du pipeline
* @return array Données du pipeline
**/
function podcast_affiche_enfants($flux) {
if (
$e = trouver_objet_exec($flux['args']['exec'])
and $e['edition'] === false
) {
$id_objet = $flux['args']['id_objet'];
if ($e['type'] === 'article') {
$flux['data'] .= recuperer_fond(
'prive/objets/liste/podcasts',
array(
'titre' => _T('podcast:titre_podcasts'),
'id_article' => $id_objet
)
);
if (autoriser('creerpodcastdans', 'articles', $id_objet)) {
include_spip('inc/presentation');
$flux['data'] .= icone_verticale(
_T('podcast:icone_creer_podcast'),
generer_url_ecrire('podcast_edit', "id_article=$id_objet"),
'podcast-24.png',
'new',
'right'
) . "<br class='nettoyeur' />";
}
}
}
return $flux;
}
/**
* Afficher le nombre d'éléments dans les parents
*
* @pipeline boite_infos
* @param array $flux Données du pipeline
* @return array Données du pipeline
**/
function podcast_boite_infos($flux) {
if (isset($flux['args']['type']) and isset($flux['args']['id']) and $id = intval($flux['args']['id'])) {
$texte = '';
if ($flux['args']['type'] == 'article' and $nb = sql_countsel('spip_podcasts', array('id_article=' . $id))) {
$texte .= '<div>' . singulier_ou_pluriel($nb, 'podcast:info_1_podcast', 'podcast:info_nb_podcasts') . "</div>\n";
}
if ($texte and $p = strpos($flux['data'], '<!--nb_elements-->')) {
$flux['data'] = substr_replace($flux['data'], $texte, $p, 0);
}
}
return $flux;
}
/**
* Compter les enfants d'un objet
*
* @pipeline objets_compte_enfants
* @param array $flux Données du pipeline
* @return array Données du pipeline
**/
function podcast_objet_compte_enfants($flux) {
if ($flux['args']['objet'] == 'article' and $id_article = intval($flux['args']['id_objet'])) {
$flux['data']['podcasts'] = sql_countsel('spip_podcasts', 'id_article= ' . intval($id_article));
}
return $flux;
}