[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / plugins-dist / breves / breves_pipelines.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined("_ECRIRE_INC_VERSION")) return;
14
15
16 /**
17 * Definir les meta de configuration liee aux breves
18 *
19 * @param array $metas
20 * @return array
21 */
22 function breves_configurer_liste_metas($metas){
23 $metas['activer_breves'] = 'non';
24 return $metas;
25 }
26
27 /**
28 * Ajouter les breves a valider sur les rubriques
29 *
30 * @param array $flux
31 * @return array
32 **/
33 function breves_rubrique_encours($flux){
34 if ($flux['args']['type'] == 'rubrique') {
35 $lister_objets = charger_fonction('lister_objets','inc');
36
37 $id_rubrique = $flux['args']['id_objet'];
38
39 //
40 // Les breves a valider
41 //
42 $flux['data'] .= $lister_objets('breves', array(
43 'titre'=>_T('breves:info_breves_valider'),
44 'statut'=>array('prepa','prop'),
45 'id_rubrique'=>$id_rubrique,
46 'par'=>'date_heure'));
47 }
48 return $flux;
49 }
50
51
52
53
54 /**
55 * Ajouter les breves references sur les vues de rubriques
56 *
57 * @param array $flux
58 * @return array
59 **/
60 function breves_affiche_enfants($flux) {
61 if ($e = trouver_objet_exec($flux['args']['exec'])
62 AND $e['type'] == 'rubrique'
63 AND $e['edition'] == false) {
64 $id_rubrique = $flux['args']['id_rubrique'];
65
66 if ($GLOBALS['meta']["activer_breves"] == 'oui') {
67 $lister_objets = charger_fonction('lister_objets','inc');
68 $bouton_breves = '';
69 $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.$id_rubrique);
70 if (autoriser('creerbrevedans','rubrique',$id_rubrique,NULL,array('id_parent'=>$id_parent))) {
71 $bouton_breves .= icone_verticale(_T('breves:icone_nouvelle_breve'), generer_url_ecrire("breve_edit","id_rubrique=$id_rubrique&new=oui"), "breve-24.png","new", 'right')
72 . "<br class='nettoyeur' />";
73 }
74
75 $flux['data'] .= $lister_objets('breves', array('titre'=>_T('breves:icone_ecrire_nouvel_article'), 'where'=>"statut != 'prop' AND statut != 'prepa'", 'id_rubrique'=>$id_rubrique, 'par'=>'date_heure'));
76 $flux['data'] .= $bouton_breves;
77 }
78 }
79 return $flux;
80 }
81
82
83
84
85 /**
86 * Bloc sur les informations generales concernant chaque type d'objet
87 *
88 * @param string $texte
89 * @return string
90 */
91 function breves_accueil_informations($texte){
92 include_spip('base/abstract_sql');
93
94 $q = sql_select("COUNT(*) AS cnt, statut", 'spip_breves', '', 'statut', '','', "COUNT(*)<>0");
95
96 $cpt = array();
97 $cpt2 = array();
98 $where = false;
99 if ($GLOBALS['visiteur_session']['statut']=='0minirezo'){
100 $where = sql_allfetsel('id_objet','spip_auteurs_liens',"objet='rubrique' AND id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']));
101 if ($where){
102 $where = sql_in('id_rubrique',array_map('reset',$where));
103 }
104 }
105 $defaut = $where ? '0/' : '';
106 while($row = sql_fetch($q)) {
107 $cpt[$row['statut']] = $row['cnt'];
108 $cpt2[$row['statut']] = $defaut;
109 }
110
111 if ($cpt) {
112 if ($where) {
113 $q = sql_select("COUNT(*) AS cnt, statut", 'spip_breves', $where, "statut");
114 while($row = sql_fetch($q)) {
115 $r = $row['statut'];
116 $cpt2[$r] = intval($row['cnt']) . '/';
117 }
118 }
119 $texte .= "<div class='accueil_informations breves liste'>";
120 $texte .= "<h4>" . afficher_plus_info(generer_url_ecrire("breves"), "", _T('breves:info_breves_02')) . "</h4>";
121 $texte .= "<ul class='liste-items'>";
122 if (isset($cpt['prop'])) $texte .= "<li class='item'>"._T("texte_statut_attente_validation").": ".$cpt2['prop'].$cpt['prop'] . '</li>';
123 if (isset($cpt['publie'])) $texte .= "<li class='item on'>"._T("texte_statut_publies").": ".$cpt2['publie'] .$cpt['publie'] . '</li>';
124 $texte .= "</ul>";
125 $texte .= "</div>";
126 }
127 return $texte;
128 }
129
130
131 /**
132 * Compter les breves dans une rubrique
133 *
134 * @param array $flux
135 * @return array
136 */
137 function breves_objet_compte_enfants($flux){
138 if ($flux['args']['objet']=='rubrique'
139 AND $id_rubrique=intval($flux['args']['id_objet'])) {
140 // juste les publies ?
141 if (array_key_exists('statut', $flux['args']) and ($flux['args']['statut'] == 'publie')) {
142 $flux['data']['breve'] = sql_countsel('spip_breves', "id_rubrique=".intval($id_rubrique)." AND (statut='publie')");
143 } else {
144 $flux['data']['breve'] = sql_countsel('spip_breves', "id_rubrique=".intval($id_rubrique)." AND (statut='publie' OR statut='prop')");
145 }
146 }
147 return $flux;
148 }
149
150
151 /**
152 * Changer la langue des breves si la rubrique change
153 *
154 * @param array $flux
155 * @return array
156 */
157 function breves_trig_calculer_langues_rubriques($flux){
158
159 $s = sql_select("A.id_breve AS id_breve, R.lang AS lang", "spip_breves AS A, spip_rubriques AS R", "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (A.lang='' OR R.lang<>'') AND R.lang<>A.lang");
160 while ($row = sql_fetch($s)) {
161 $id_breve = $row['id_breve'];
162 sql_updateq('spip_breves', array("lang"=>$row['lang'], 'langue_choisie'=>'non'), "id_breve=$id_breve");
163 }
164
165 return $flux;
166 }
167
168
169 /**
170 * Publier et dater les rubriques qui ont une breve publie
171 *
172 * @param array $flux
173 * @return array
174 */
175 function breves_calculer_rubriques($flux){
176
177 $r = sql_select("R.id_rubrique AS id, max(A.date_heure) AS date_h", "spip_rubriques AS R, spip_breves AS A", "R.id_rubrique = A.id_rubrique AND R.date_tmp <= A.date_heure AND A.statut='publie' ", "R.id_rubrique");
178 while ($row = sql_fetch($r))
179 sql_updateq('spip_rubriques', array('statut_tmp'=>'publie', 'date_tmp'=>$row['date_h']), "id_rubrique=".$row['id']);
180
181 return $flux;
182 }
183
184
185
186
187 /**
188 * Ajouter les breves a valider sur la page d'accueil
189 *
190 * @param array $flux
191 * @return array
192 **/
193 function breves_accueil_encours($flux){
194 $lister_objets = charger_fonction('lister_objets','inc');
195
196
197 $flux .= $lister_objets('breves', array(
198 'titre'=>afficher_plus_info(generer_url_ecrire('breves'))._T('breves:info_breves_valider'),
199 'statut'=>array('prepa','prop'),
200 'par'=>'date_heure'));
201
202 return $flux;
203 }
204
205
206
207 /**
208 * Optimiser la base de donnee en supprimant les liens orphelins
209 *
210 * @param array $flux
211 * @return array
212 */
213 function breves_optimiser_base_disparus($flux){
214 $n = &$flux['data'];
215 $mydate = $flux['args']['date'];
216
217
218 # les breves qui sont dans une id_rubrique inexistante
219 $res = sql_select("B.id_breve AS id",
220 "spip_breves AS B
221 LEFT JOIN spip_rubriques AS R
222 ON B.id_rubrique=R.id_rubrique",
223 "R.id_rubrique IS NULL
224 AND B.maj < $mydate");
225
226 $n+= optimiser_sansref('spip_breves', 'id_breve', $res);
227
228
229 //
230 // Breves
231 //
232
233 sql_delete("spip_breves", "statut='refuse' AND maj < $mydate");
234
235 return $flux;
236
237 }
238
239 /**
240 * Afficher le nombre de breves dans chaque rubrique
241 *
242 * @param array $flux
243 * @return array
244 */
245 function breves_boite_infos($flux){
246 if (
247 isset($flux['args']['type']) and $flux['args']['type'] == 'rubrique'
248 and isset($flux['args']['id']) and $id_rubrique = $flux['args']['id']
249 ){
250 if ($nb = sql_countsel('spip_breves',"statut='publie' AND id_rubrique=".intval($id_rubrique))){
251 $nb = "<div>". singulier_ou_pluriel($nb, "breves:info_1_breve", "breves:info_nb_breves") . "</div>";
252 if ($p = strpos($flux['data'],"<!--nb_elements-->"))
253 $flux['data'] = substr_replace($flux['data'],$nb,$p,0);
254 }
255 }
256 return $flux;
257 }
258
259 /**
260 * Configuration des contenus
261 * @param array $flux
262 * @return array
263 */
264 function breves_affiche_milieu($flux){
265 if ($flux["args"]["exec"] == "configurer_contenu") {
266 $flux["data"] .= recuperer_fond('prive/squelettes/inclure/configurer',array('configurer'=>'configurer_breves'));
267 }
268 return $flux;
269 }
270
271
272 ?>