<?php /** * Utilisations de pipelines par Blocks * * @plugin Blocks * @copyright 2023 * @author nicod_ * @licence GNU/GPL * @package SPIP\Blocks\Pipelines */ if (!defined('_ECRIRE_INC_VERSION')) { return; } /** * 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 blocks_affiche_enfants($flux) { if ( $e = trouver_objet_exec($flux['args']['exec']) and $e['edition'] === false ) { $id_objet = $flux['args']['id_objet']; if ($e['type'] === 'blocs_type') { $flux['data'] .= recuperer_fond( 'prive/objets/liste/blocs', [ 'titre' => _T('bloc:titre_blocs'), 'id_blocs_type' => $id_objet, ] ); } } 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 blocks_boite_infos($flux) { if (isset($flux['args']['type']) and isset($flux['args']['id']) and $id = intval($flux['args']['id'])) { $texte = ''; if ($flux['args']['type'] == 'blocs_type' and $nb = sql_countsel('spip_blocs', ["statut='publie'", 'id_blocs_type=' . $id])) { $texte .= '<div>' . singulier_ou_pluriel($nb, 'bloc:info_1_bloc', 'bloc:info_nb_blocs') . "</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 blocks_objet_compte_enfants($flux) { if ($flux['args']['objet'] == 'blocs_type' and $id_blocs_type = intval($flux['args']['id_objet'])) { // juste les publiés ? if (array_key_exists('statut', $flux['args']) and ($flux['args']['statut'] == 'publie')) { $flux['data']['blocs'] = sql_countsel('spip_blocs', 'id_blocs_type= ' . intval($id_blocs_type) . " AND (statut = 'publie')"); } else { $flux['data']['blocs'] = sql_countsel('spip_blocs', 'id_blocs_type= ' . intval($id_blocs_type) . " AND (statut <> 'poubelle')"); } } return $flux; } /** * Optimiser la base de données * * Supprime les liens orphelins de l'objet vers quelqu'un et de quelqu'un vers l'objet. * Supprime les objets à la poubelle. * * @pipeline optimiser_base_disparus * @param array $flux Données du pipeline * @return array Données du pipeline */ function blocks_optimiser_base_disparus($flux) { include_spip('action/editer_liens'); $flux['data'] += objet_optimiser_liens(['bloc' => '*'], '*'); sql_delete('spip_blocs', "statut='poubelle' AND maj < " . $flux['args']['date']); return $flux; }