88aa2797791c4261ea1edba402a6e1ec9769114f
[lhc/web/www.git] / www / plugins-dist / sites / sites_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')) {
14 return;
15 }
16
17 /**
18 * Ajouter les sites et syndication a valider sur les rubriques
19 *
20 * @param array $flux
21 * @return array
22 */
23 function sites_rubrique_encours($flux) {
24 if ($flux['args']['type'] == 'rubrique') {
25 $lister_objets = charger_fonction('lister_objets', 'inc');
26
27 $id_rubrique = $flux['args']['id_objet'];
28
29 //
30 // Les sites references a valider
31 //
32 if ($GLOBALS['meta']['activer_sites'] != 'non') {
33 $flux['data'] .= $lister_objets('sites', array(
34 'titre' => _T('sites:info_site_valider'),
35 'statut' => 'prop',
36 'id_rubrique' => $id_rubrique,
37 'par' => 'nom_site'
38 ));
39 }
40
41 //
42 // Les sites a probleme
43 //
44 if ($GLOBALS['meta']['activer_sites'] != 'non'
45 and autoriser('publierdans', 'rubrique', $id_rubrique)
46 ) {
47 $flux['data'] .= $lister_objets('sites', array(
48 'titre' => _T('sites:avis_sites_syndiques_probleme'),
49 'statut' => 'publie',
50 'syndication' => array('off', 'sus'),
51 'id_rubrique' => $id_rubrique,
52 'par' => 'nom_site'
53 ));
54 }
55
56 // Les articles syndiques en attente de validation
57 if ($id_rubrique == 0
58 and autoriser('publierdans', 'rubrique', $id_rubrique)
59 ) {
60
61 $cpt = sql_countsel("spip_syndic_articles", "statut='dispo'");
62 if ($cpt) {
63 $flux['data'] .= "<br /><small><a href='" .
64 generer_url_ecrire("sites") .
65 "' style='color: black;'>" .
66 $cpt .
67 " " .
68 _T('sites:info_liens_syndiques_1') .
69 " " .
70 _T('sites:info_liens_syndiques_2') .
71 "</a></small>";
72 }
73 }
74 }
75
76 return $flux;
77 }
78
79 /**
80 * Configuration des contenus
81 *
82 * @param array $flux
83 * @return array
84 */
85 function sites_affiche_milieu($flux) {
86 if ($flux["args"]["exec"] == "configurer_contenu") {
87 $flux["data"] .= recuperer_fond('prive/squelettes/inclure/configurer', array('configurer' => 'configurer_sites'));
88 }
89
90 return $flux;
91 }
92
93 /**
94 * Ajouter les sites et syndication a valider sur la page d'accueil
95 *
96 * @param array $flux
97 * @return array
98 */
99 function sites_accueil_encours($flux) {
100 $lister_objets = charger_fonction('lister_objets', 'inc');
101
102 //
103 // Les sites references a valider
104 //
105 if ($GLOBALS['meta']['activer_sites'] != 'non') {
106 $flux .= $lister_objets('sites', array(
107 'titre' => afficher_plus_info(generer_url_ecrire('sites')) . _T('sites:info_site_valider'),
108 'statut' => 'prop',
109 'par' => 'nom_site'
110 ));
111 }
112
113 if ($GLOBALS['visiteur_session']['statut'] == '0minirezo') {
114 //
115 // Les sites a probleme
116 //
117 if ($GLOBALS['meta']['activer_sites'] != 'non') {
118 $flux .= $lister_objets('sites', array(
119 'titre' => afficher_plus_info(generer_url_ecrire('sites')) . _T('sites:avis_sites_syndiques_probleme'),
120 'statut' => 'publie',
121 'syndication' => array('off', 'sus'),
122 'par' => 'nom_site'
123 ));
124 }
125
126 // Les articles syndiques en attente de validation
127 $cpt = sql_countsel("spip_syndic_articles", "statut='dispo'");
128 if ($cpt) {
129 $flux .= "\n<br /><small><a href='"
130 . generer_url_ecrire("sites", "")
131 . "' style='color: black;'>"
132 . $cpt
133 . " "
134 . _T('sites:info_liens_syndiques_1')
135 . " "
136 . _T('sites:info_liens_syndiques_2')
137 . "</a></small>";
138 }
139
140 }
141
142 return $flux;
143 }
144
145
146 /**
147 * Ajouter les sites references sur les vues de rubriques
148 *
149 * @param array $flux
150 * @return array
151 */
152 function sites_affiche_enfants($flux) {
153 if (isset($flux['args']['exec'])
154 and $e = trouver_objet_exec($flux['args']['exec'])
155 and $e['type'] == 'rubrique'
156 and $e['edition'] == false
157 ) {
158 $id_rubrique = $flux['args']['id_rubrique'];
159
160 if ($GLOBALS['meta']["activer_sites"] == 'oui') {
161 $lister_objets = charger_fonction('lister_objets', 'inc');
162 $bouton_sites = '';
163 if (autoriser('creersitedans', 'rubrique', $id_rubrique)) {
164 $bouton_sites .= icone_verticale(_T('sites:info_sites_referencer'),
165 generer_url_ecrire('site_edit', "id_rubrique=$id_rubrique"), "site-24.png", "new", 'right')
166 . "<br class='nettoyeur' />";
167 }
168
169 $flux['data'] .= $lister_objets('sites', array(
170 'titre' => _T('sites:titre_sites_references_rubrique'),
171 'where' => "statut!='refuse' AND statut != 'prop' AND syndication NOT IN ('off','sus')",
172 'id_rubrique' => $id_rubrique,
173 'par' => 'nom_site'
174 ));
175 $flux['data'] .= $bouton_sites;
176 }
177 }
178
179 return $flux;
180 }
181
182
183 /**
184 * Definir les meta de configuration liee aux syndications et sites
185 *
186 * @param array $metas
187 * @return array
188 */
189 function sites_configurer_liste_metas($metas) {
190 $metas['activer_sites'] = 'non';
191 $metas['proposer_sites'] = 0;
192 $metas['activer_syndic'] = 'oui';
193 $metas['moderation_sites'] = 'non';
194
195 return $metas;
196 }
197
198 /**
199 * Taches periodiques de syndication
200 *
201 * @param array $taches_generales
202 * @return array
203 */
204 function sites_taches_generales_cron($taches_generales) {
205
206 if (isset($GLOBALS['meta']["activer_syndic"])
207 and $GLOBALS['meta']["activer_syndic"] == "oui"
208 and isset($GLOBALS['meta']["activer_sites"])
209 and $GLOBALS['meta']["activer_sites"] == "oui"
210 ) {
211 $taches_generales['syndic'] = 90;
212 }
213
214 return $taches_generales;
215 }
216
217
218 /**
219 * Optimiser la base de donnee en supprimant les liens orphelins
220 *
221 * @param array $flux
222 * @return array
223 */
224 function sites_optimiser_base_disparus($flux) {
225 $n = &$flux['data'];
226 $mydate = $flux['args']['date'];
227
228 sql_delete("spip_syndic", "maj<" . sql_quote($mydate) . " AND statut=" . sql_quote("refuse"));
229
230 # les articles syndiques appartenant a des sites effaces
231 $res = sql_select("S.id_syndic AS id",
232 "spip_syndic_articles AS S
233 LEFT JOIN spip_syndic AS syndic
234 ON S.id_syndic=syndic.id_syndic",
235 "syndic.id_syndic IS NULL");
236
237 $n += optimiser_sansref('spip_syndic_articles', 'id_syndic', $res);
238
239
240 return $flux;
241
242 }
243
244
245 /**
246 * Publier et dater les rubriques qui ont un site publie
247 *
248 * @param array $flux
249 * @return array
250 */
251 function sites_calculer_rubriques($flux) {
252
253 $r = sql_select(
254 "R.id_rubrique AS id, max(A.date) AS date_h",
255 "spip_rubriques AS R JOIN spip_syndic AS A ON R.id_rubrique = A.id_rubrique",
256 "A.date>R.date_tmp AND A.statut='publie' ", "R.id_rubrique");
257 while ($row = sql_fetch($r)) {
258 sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
259 "id_rubrique=" . $row['id']);
260 }
261
262 return $flux;
263 }
264
265 /**
266 * Compter les sites dans une rubrique
267 *
268 * @param array $flux
269 * @return array
270 */
271 function sites_objet_compte_enfants($flux) {
272 if ($flux['args']['objet'] == 'rubrique'
273 and $id_rubrique = intval($flux['args']['id_objet'])
274 ) {
275 // juste les publies ?
276 if (array_key_exists('statut', $flux['args']) and ($flux['args']['statut'] == 'publie')) {
277 $flux['data']['site'] = sql_countsel('spip_syndic',
278 "id_rubrique=" . intval($id_rubrique) . " AND (statut='publie')");
279 } else {
280 $flux['data']['site'] = sql_countsel('spip_syndic',
281 "id_rubrique=" . intval($id_rubrique) . " AND (statut='publie' OR statut='prop')");
282 }
283 }
284
285 return $flux;
286 }
287
288
289 function sites_trig_propager_les_secteurs($flux) {
290 // reparer les sites
291 $r = sql_select("A.id_syndic AS id, R.id_secteur AS secteur", "spip_syndic AS A, spip_rubriques AS R",
292 "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
293 while ($row = sql_fetch($r)) {
294 sql_update("spip_syndic", array("id_secteur" => $row['secteur']), "id_syndic=" . $row['id']);
295 }
296
297 return $flux;
298 }
299
300 /**
301 * Afficher le nombre de sites dans chaque rubrique
302 *
303 * @param array $flux
304 * @return array
305 */
306 function sites_boite_infos($flux) {
307 if ($flux['args']['type'] == 'rubrique'
308 and $id_rubrique = $flux['args']['id']
309 ) {
310 if ($nb = sql_countsel('spip_syndic', "statut='publie' AND id_rubrique=" . intval($id_rubrique))) {
311 $nb = "<div>" . singulier_ou_pluriel($nb, "sites:info_1_site", "sites:info_nb_sites") . "</div>";
312 if ($p = strpos($flux['data'], "<!--nb_elements-->")) {
313 $flux['data'] = substr_replace($flux['data'], $nb, $p, 0);
314 }
315 }
316 }
317
318 return $flux;
319 }