4 |
david |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************\
|
|
|
4 |
* SPIP, Systeme de publication pour l'internet *
|
|
|
5 |
* *
|
|
|
6 |
* Copyright (c) 2001-2005 *
|
|
|
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 |
|
|
|
14 |
//
|
|
|
15 |
// Ce fichier ne sera execute qu'une fois
|
|
|
16 |
if (defined("_ECRIRE_INC_FORUM")) return;
|
|
|
17 |
define("_ECRIRE_INC_FORUM", "1");
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
//
|
|
|
21 |
// Suppression de forums
|
|
|
22 |
//
|
|
|
23 |
function changer_statut_forum($id_forum, $statut) {
|
|
|
24 |
$result = spip_query("SELECT * FROM spip_forum WHERE id_forum=$id_forum");
|
|
|
25 |
|
|
|
26 |
if (!($row = spip_fetch_array($result)))
|
|
|
27 |
return;
|
|
|
28 |
|
|
|
29 |
$id_parent = $row['id_parent'];
|
|
|
30 |
|
|
|
31 |
// invalider les pages comportant ce forum
|
|
|
32 |
include_ecrire('inc_invalideur.php3');
|
|
|
33 |
$index_forum = calcul_index_forum($row['id_article'], $row['id_breve'], $row['id_rubrique'], $row['id_syndic']);
|
|
|
34 |
suivre_invalideur("id='id_forum/$index_forum'");
|
|
|
35 |
|
|
|
36 |
// Signaler au moteur de recherche qu'il faut reindexer le thread
|
|
|
37 |
if ($id_parent) {
|
|
|
38 |
include_ecrire('inc_index.php3');
|
|
|
39 |
marquer_indexer ('forum', $id_parent);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
// changer le statut de toute l'arborescence dependant de ce message
|
|
|
43 |
$id_messages = array($id_forum);
|
|
|
44 |
while ($id_messages) {
|
|
|
45 |
$id_messages = join(',', $id_messages);
|
|
|
46 |
$query_forum = "UPDATE spip_forum SET statut='$statut'
|
|
|
47 |
WHERE id_forum IN ($id_messages)";
|
|
|
48 |
$result_forum = spip_query($query_forum);
|
|
|
49 |
$query_forum = "SELECT id_forum FROM spip_forum
|
|
|
50 |
WHERE id_parent IN ($id_messages)";
|
|
|
51 |
$result_forum = spip_query($query_forum);
|
|
|
52 |
unset($id_messages);
|
|
|
53 |
while ($row = spip_fetch_array($result_forum))
|
|
|
54 |
$id_messages[] = $row['id_forum'];
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
function controler_statut_forum ($controle_forum, $id_controle_forum) {
|
|
|
59 |
// Verifier qu'on a le droit d'agir sur ce forum
|
|
|
60 |
global $connect_toutes_rubriques, $connect_statut;
|
|
|
61 |
$ok = ($connect_statut == "0minirezo" AND $connect_toutes_rubriques);
|
|
|
62 |
if (!$ok) return;
|
|
|
63 |
|
|
|
64 |
// Que faut-il faire ?
|
|
|
65 |
switch($controle_forum) {
|
|
|
66 |
case 'supp_forum':
|
|
|
67 |
$statut = 'off';
|
|
|
68 |
break;
|
|
|
69 |
case 'supp_forum_priv':
|
|
|
70 |
$statut = 'privoff';
|
|
|
71 |
break;
|
|
|
72 |
case 'valid_forum':
|
|
|
73 |
$statut = 'publie';
|
|
|
74 |
break;
|
|
|
75 |
// nb : les forums prives (privrac ou prive), une fois effaces
|
|
|
76 |
// (privoff), ne sont pas revalidables ; le forum d'admin (privadm)
|
|
|
77 |
// n'est pas effacable
|
|
|
78 |
}
|
|
|
79 |
changer_statut_forum($id_controle_forum, $statut);
|
|
|
80 |
return $statut;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
// Installer un bouton de moderation dans l'espace prive
|
|
|
84 |
function controle_cache_forum($action, $id, $texte, $fond, $fonction, $but='') {
|
|
|
85 |
$link = new Link();
|
|
|
86 |
|
|
|
87 |
$link->addvar('controle_forum', $action);
|
|
|
88 |
$link->addvar('id_controle_forum', $id);
|
|
|
89 |
$link = $link->geturl() . "#id$id";
|
|
|
90 |
|
|
|
91 |
if ($but)
|
|
|
92 |
$link = $but . "&retour=ecrire/" . urlencode($link);
|
|
|
93 |
|
|
|
94 |
return icone($texte,
|
|
|
95 |
$link,
|
|
|
96 |
$fond,
|
|
|
97 |
$fonction,
|
|
|
98 |
"right",
|
|
|
99 |
'non');
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
// tous les boutons de controle d'un forum
|
|
|
103 |
function boutons_controle_forum($id_forum, $forum_stat, $forum_id_auteur=0, $ref, $forum_ip) {
|
|
|
104 |
$controle = '';
|
|
|
105 |
|
|
|
106 |
// selection du logo et des boutons correspondant a l'etat du forum
|
|
|
107 |
switch ($forum_stat) {
|
|
|
108 |
# forum sous un article dans l'espace prive
|
|
|
109 |
case "prive":
|
|
|
110 |
$logo = "forum-interne-24.gif";
|
|
|
111 |
$valider = false;
|
|
|
112 |
$valider_repondre = false;
|
|
|
113 |
$supprimer = 'supp_forum_priv';
|
|
|
114 |
break;
|
|
|
115 |
# forum des administrateurs
|
|
|
116 |
case "privadmin":
|
|
|
117 |
$logo = "forum-admin-24.gif";
|
|
|
118 |
$valider = false;
|
|
|
119 |
$valider_repondre = false;
|
|
|
120 |
$supprimer = false;
|
|
|
121 |
break;
|
|
|
122 |
# forum de l'espace prive, supprime (non revalidable,
|
|
|
123 |
# d'ailleurs on ne sait plus a quel type de forum il appartenait)
|
|
|
124 |
case "privoff":
|
|
|
125 |
$logo = "forum-interne-24.gif";
|
|
|
126 |
$valider = false;
|
|
|
127 |
$valider_repondre = false;
|
|
|
128 |
$supprimer = false;
|
|
|
129 |
break;
|
|
|
130 |
# forum general de l'espace prive
|
|
|
131 |
case "privrac":
|
|
|
132 |
$logo = "forum-interne-24.gif";
|
|
|
133 |
$valider = false;
|
|
|
134 |
$valider_repondre = false;
|
|
|
135 |
$supprimer = 'supp_forum_priv';
|
|
|
136 |
break;
|
|
|
137 |
|
|
|
138 |
# forum publie sur le site public
|
|
|
139 |
case "publie":
|
|
|
140 |
$logo = "forum-public-24.gif";
|
|
|
141 |
$valider = false;
|
|
|
142 |
$valider_repondre = false;
|
|
|
143 |
$supprimer = 'supp_forum';
|
|
|
144 |
break;
|
|
|
145 |
# forum supprime sur le site public
|
|
|
146 |
case "off":
|
|
|
147 |
$logo = "forum-public-24.gif";
|
|
|
148 |
$valider = 'valid_forum';
|
|
|
149 |
$valider_repondre = false;
|
|
|
150 |
$supprimer = false;
|
|
|
151 |
$message = "<BR><FONT COLOR='red'><B>"._T('info_message_supprime')." $forum_ip</B></FONT>";
|
|
|
152 |
if($forum_id_auteur)
|
|
|
153 |
$message .= " - <A HREF='auteurs_edit.php3?id_auteur="
|
|
|
154 |
.$forum_id_auteur."'>" ._T('lien_voir_auteur'). "</A>";
|
|
|
155 |
break;
|
|
|
156 |
# forum propose (a moderer) sur le site public
|
|
|
157 |
case "prop":
|
|
|
158 |
$logo = "forum-public-24.gif";
|
|
|
159 |
$valider = 'valid_forum';
|
|
|
160 |
$valider_repondre = true;
|
|
|
161 |
$supprimer = 'supp_forum';
|
|
|
162 |
break;
|
|
|
163 |
default:
|
|
|
164 |
return;
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
if ($message)
|
|
|
168 |
$controle .= $message;
|
|
|
169 |
|
|
|
170 |
if ($supprimer)
|
|
|
171 |
$controle .= controle_cache_forum($supprimer,
|
|
|
172 |
$id_forum,
|
|
|
173 |
_T('icone_supprimer_message'),
|
|
|
174 |
$logo,
|
|
|
175 |
"supprimer.gif");
|
|
|
176 |
|
|
|
177 |
if ($valider)
|
|
|
178 |
$controle .= controle_cache_forum($valider,
|
|
|
179 |
$id_forum,
|
|
|
180 |
_T('icone_valider_message'),
|
|
|
181 |
$logo,
|
|
|
182 |
"creer.gif");
|
|
|
183 |
|
|
|
184 |
if ($valider_repondre) {
|
|
|
185 |
|
|
|
186 |
$controle .= controle_cache_forum($valider,
|
|
|
187 |
$id_forum,
|
|
|
188 |
_T('icone_valider_message') . " & " .
|
|
|
189 |
_T('lien_repondre_message'),
|
|
|
190 |
$logo,
|
|
|
191 |
"creer.gif",
|
|
|
192 |
"../forum.php3?$ref&id_forum=$id_forum"
|
|
|
193 |
);
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
return $controle;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
// Selon ce qu'on veut suivre depuis ecrire/controle_forum, retourner le SQL
|
|
|
200 |
function critere_statut_controle_forum($page) {
|
|
|
201 |
switch ($page) {
|
|
|
202 |
case 'public':
|
|
|
203 |
$query_forum = "statut IN ('publie', 'off', 'prop') AND texte!=''";
|
|
|
204 |
break;
|
|
|
205 |
case 'prop':
|
|
|
206 |
$query_forum = "statut='prop'";
|
|
|
207 |
break;
|
|
|
208 |
case 'interne':
|
|
|
209 |
$query_forum = "statut IN ('prive', 'privrac', 'privoff', 'privadm') AND texte!=''";
|
|
|
210 |
break;
|
|
|
211 |
case 'vide':
|
|
|
212 |
$query_forum = "statut IN ('publie', 'off', 'prive', 'privrac', 'privoff', 'privadm') AND texte=''";
|
|
|
213 |
break;
|
|
|
214 |
default:
|
|
|
215 |
$query_forum = "0=1";
|
|
|
216 |
break;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
return $query_forum;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
// Index d'invalidation des forums
|
|
|
223 |
function calcul_index_forum($id_article, $id_breve, $id_rubrique, $id_syndic) {
|
|
|
224 |
if ($id_article) return 'a'.$id_article;
|
|
|
225 |
if ($id_breve) return 'b'.$id_breve;
|
|
|
226 |
if ($id_rubrique) return 'r'.$id_rubrique;
|
|
|
227 |
if ($id_syndic) return 's'.$id_syndic;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
//
|
|
|
231 |
// Recalculer tous les threads
|
|
|
232 |
//
|
|
|
233 |
function calculer_threads() {
|
|
|
234 |
// fixer les id_thread des debuts de discussion
|
|
|
235 |
spip_query("UPDATE spip_forum SET id_thread=id_forum
|
|
|
236 |
WHERE id_parent=0");
|
|
|
237 |
|
|
|
238 |
// reparer les messages qui n'ont pas l'id_secteur de leur parent
|
|
|
239 |
do {
|
|
|
240 |
$discussion = "0";
|
|
|
241 |
$precedent = 0;
|
|
|
242 |
$r = spip_query("SELECT fille.id_forum AS id,
|
|
|
243 |
maman.id_thread AS thread
|
|
|
244 |
FROM spip_forum AS fille, spip_forum AS maman
|
|
|
245 |
WHERE fille.id_parent = maman.id_forum
|
|
|
246 |
AND fille.id_thread <> maman.id_thread
|
|
|
247 |
ORDER BY thread");
|
|
|
248 |
while (list($id, $thread) = spip_fetch_array($r)) {
|
|
|
249 |
if ($thread == $precedent)
|
|
|
250 |
$discussion .= ",$id";
|
|
|
251 |
else {
|
|
|
252 |
if ($precedent)
|
|
|
253 |
spip_query("UPDATE spip_forum SET id_thread=$precedent
|
|
|
254 |
WHERE id_forum IN ($discussion)");
|
|
|
255 |
$precedent = $thread;
|
|
|
256 |
$discussion = "$id";
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
spip_query("UPDATE spip_forum SET id_thread=$precedent
|
|
|
260 |
WHERE id_forum IN ($discussion)");
|
|
|
261 |
} while ($discussion != "0");
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
// Calculs des URLs des forums (pour l'espace public)
|
|
|
265 |
function racine_forum($id_forum){
|
|
|
266 |
if (!$id_forum = intval($id_forum)) return;
|
|
|
267 |
$query = "SELECT id_parent, id_rubrique, id_article, id_breve FROM spip_forum WHERE id_forum=".$id_forum;
|
|
|
268 |
$result = spip_query($query);
|
|
|
269 |
if($row = spip_fetch_array($result)){
|
|
|
270 |
if($row['id_parent']) {
|
|
|
271 |
return racine_forum($row['id_parent']);
|
|
|
272 |
}
|
|
|
273 |
else {
|
|
|
274 |
if($row['id_rubrique']) return array('rubrique',$row['id_rubrique'], $id_forum);
|
|
|
275 |
if($row['id_article']) return array('article',$row['id_article'], $id_forum);
|
|
|
276 |
if($row['id_breve']) return array('breve',$row['id_breve'], $id_forum);
|
|
|
277 |
}
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
function generer_url_forum_dist($id_forum, $show_thread=false) {
|
|
|
282 |
list($type, $id, $id_thread) = racine_forum($id_forum);
|
|
|
283 |
if ($id_thread>0 AND $show_thread)
|
|
|
284 |
$id_forum = $id_thread;
|
|
|
285 |
switch($type) {
|
|
|
286 |
case 'article':
|
|
|
287 |
return generer_url_article($id)."#forum$id_forum";
|
|
|
288 |
break;
|
|
|
289 |
case 'breve':
|
|
|
290 |
return generer_url_breve($id)."#forum$id_forum";
|
|
|
291 |
break;
|
|
|
292 |
case 'rubrique':
|
|
|
293 |
return generer_url_rubrique($id)."#forum$id_forum";
|
|
|
294 |
break;
|
|
|
295 |
case 'site':
|
|
|
296 |
return generer_url_site($id)."#forum$id_forum";
|
|
|
297 |
break;
|
|
|
298 |
default:
|
|
|
299 |
return "forum.php3?id_forum=".$id_forum;
|
|
|
300 |
}
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
// Recuperer le reglage des forums publics de l'article x
|
|
|
305 |
function get_forums_publics($id_article=0) {
|
|
|
306 |
$forums_publics = lire_meta("forums_publics");
|
|
|
307 |
if ($id_article) {
|
|
|
308 |
$query = "SELECT accepter_forum FROM spip_articles WHERE id_article=$id_article";
|
|
|
309 |
$res = spip_query($query);
|
|
|
310 |
if ($obj = spip_fetch_array($res))
|
|
|
311 |
$forums_publics = $obj['accepter_forum'];
|
|
|
312 |
} else { // dans ce contexte, inutile
|
|
|
313 |
$forums_publics = substr(lire_meta("forums_publics"),0,3);
|
|
|
314 |
}
|
|
|
315 |
return $forums_publics;
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
// Modifier le reglage des forums publics de l'article x
|
|
|
319 |
function modifier_forums_publics($id_article, $forums_publics) {
|
|
|
320 |
spip_query ("UPDATE spip_articles
|
|
|
321 |
SET accepter_forum='$forums_publics'
|
|
|
322 |
WHERE id_article=".intval($id_article));
|
|
|
323 |
if ($forums_publics == 'abo') {
|
|
|
324 |
ecrire_meta('accepter_visiteurs', 'oui');
|
|
|
325 |
ecrire_metas();
|
|
|
326 |
}
|
|
|
327 |
include_ecrire('inc_invalideur.php3');
|
|
|
328 |
suivre_invalideur("id='id_forum/a$id_article'");
|
|
|
329 |
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
// Cree le formulaire de modification du reglage des forums de l'article
|
|
|
333 |
function formulaire_modification_forums_publics($id_article, $forums_publics) {
|
|
|
334 |
global $spip_lang_right;
|
|
|
335 |
|
|
|
336 |
$r = "\n<form action='". $GLOBALS['clean_link']->getUrl()
|
|
|
337 |
."' method='POST'>";
|
|
|
338 |
|
|
|
339 |
$r .= "\n<input type='hidden' name='id_article' value='$id_article'>";
|
|
|
340 |
$r .= "<br>"._T('info_fonctionnement_forum')."\n";
|
|
|
341 |
$r .= "<select name='change_accepter_forum'
|
|
|
342 |
class='fondl' style='font-size:10px;'
|
|
|
343 |
onChange=\"setvisibility('valider_forum', 'visible');\"
|
|
|
344 |
>\n";
|
|
|
345 |
|
|
|
346 |
foreach (array(
|
|
|
347 |
'pos'=>_T('bouton_radio_modere_posteriori'),
|
|
|
348 |
'pri'=>_T('bouton_radio_modere_priori'),
|
|
|
349 |
'abo'=>_T('bouton_radio_modere_abonnement'),
|
|
|
350 |
'non'=>_T('info_pas_de_forum'))
|
|
|
351 |
as $val => $desc) {
|
|
|
352 |
$r .= "<option";
|
|
|
353 |
if ($forums_publics == $val)
|
|
|
354 |
$r .= " selected";
|
|
|
355 |
$r .= " value='$val'>".$desc."</option>\n";
|
|
|
356 |
}
|
|
|
357 |
$r .= "</select>\n";
|
|
|
358 |
|
|
|
359 |
$r .= "<div align='$spip_lang_right'
|
|
|
360 |
class='visible_au_chargement' id='valider_forum'>
|
|
|
361 |
<input type='submit' name='Changer' class='fondo'
|
|
|
362 |
value='"._T('bouton_changer')."' STYLE='font-size:10px'>
|
|
|
363 |
</div>\n";
|
|
|
364 |
|
|
|
365 |
$r .= "</form>";
|
|
|
366 |
|
|
|
367 |
return $r;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
?>
|