libreavous/libreavous_pipelines.php

100 lines
2.7 KiB
PHP

<?php
/**
* Utilisations de pipelines par chapitre
*
* @plugin chapitre
* @copyright 2021
* @author chankalan,vcalame
* @licence GNU/GPL
* @package SPIP\Chapitre\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 libreavous_affiche_enfants($flux) {
if (
$e = trouver_objet_exec($flux['args']['exec'])
and $e['edition'] === false
) {
$id_objet = $flux['args']['id_objet'];
$id_rubrique = sql_getfetsel("id_rubrique", "spip_articles", "id_article=" . intval($id_objet));
$composition_rubrique = sql_getfetsel("composition", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
if ($e['type'] === 'article' and $composition_rubrique === 'emissions') {
$flux['data'] .= recuperer_fond(
'prive/objets/liste/chapitres',
array(
'titre' => _T('chapitre:titre_chapitres'),
'id_article' => $id_objet
)
);
if (autoriser('creerchapitredans', 'articles', $id_objet)) {
include_spip('inc/presentation');
$flux['data'] .= icone_verticale(
_T('chapitre:icone_creer_chapitre'),
generer_url_ecrire('chapitre_edit', "id_article=$id_objet"),
'chapitre-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 libreavous_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_chapitres', array('id_article=' . $id))) {
$texte .= '<div>' . singulier_ou_pluriel($nb, 'chapitre:info_1_chapitre', 'chapitre:info_nb_chapitres') . "</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 libreavous_objet_compte_enfants($flux) {
if ($flux['args']['objet'] == 'article' and $id_article = intval($flux['args']['id_objet'])) {
$flux['data']['chapitres'] = sql_countsel('spip_chapitres', 'id_article= ' . intval($id_article));
}
return $flux;
}