Newer
Older
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
<?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;
}