|
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
|
|
|
include_spip('inc/actions'); |
|
15
|
|
|
|
|
16
|
|
|
// http://doc.spip.org/@affiche_navigation_forum |
|
17
|
|
|
function affiche_navigation_forum(&$query, $script, $args, $debut, $pas=NULL, $enplus=NULL, $date=NULL) |
|
18
|
|
|
{ |
|
19
|
|
|
if (!$pas) $pas = 10; |
|
20
|
|
|
if (!$enplus) $enplus = 100; |
|
21
|
|
|
|
|
22
|
|
|
$total = sql_countsel($query['FROM'], $query['WHERE'], $query['GROUP BY']); |
|
23
|
|
|
// pas de navigation si tout tient |
|
24
|
|
|
if ($total > $pas) { |
|
25
|
|
|
if ($date) { |
|
26
|
|
|
preg_match('/^\w+/', $query['ORDER BY'], $m); |
|
27
|
|
|
$debut = navigation_trouve_date($date, $m[0], $pas, $query); |
|
28
|
|
|
} |
|
29
|
|
|
if ($total <= $debut) $debut = $total-$pas; |
|
30
|
|
|
$max = min($total, $debut+$enplus); |
|
31
|
|
|
$tranche = $debut; |
|
32
|
|
|
while (($tranche + $enplus) >= $max) |
|
33
|
|
|
$tranche -= $pas; |
|
34
|
|
|
if ($tranche <0) $tranche = 0; |
|
35
|
|
|
|
|
36
|
|
|
$h = generer_url_ecrire($script, $args); |
|
37
|
|
|
$nav = (!$tranche ? '' : "<a href='$h'>0</a>| ... |\n"); |
|
38
|
|
|
|
|
39
|
|
|
$e = (_SPIP_AJAX === 1 ); |
|
40
|
|
|
|
|
41
|
|
|
for (;$tranche<$max;$tranche+=$pas){ |
|
42
|
|
|
if ($tranche == $debut) |
|
43
|
|
|
$nav .= "<span class='spip_medium'><b>$tranche</b></span> |\n"; |
|
44
|
|
View Code Duplication |
else { |
|
|
|
|
|
|
45
|
|
|
$h = "$args&debut=$tranche"; |
|
46
|
|
|
$h = generer_url_ecrire($script, $h); |
|
47
|
|
|
if ($e) $e = "\nonclick=" . ajax_action_declencheur($h,$script); |
|
48
|
|
|
$nav .= "<a href='$h'$e>$tranche</a> |\n"; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
View Code Duplication |
if ($tranche < $total) { |
|
|
|
|
|
|
53
|
|
|
$h = generer_url_ecrire($script, $args . "&debut=" . $total); |
|
54
|
|
|
if ($e) { |
|
55
|
|
|
$e = "\nonclick=" . ajax_action_declencheur($h,$script); |
|
56
|
|
|
} |
|
57
|
|
|
$nav .= "... | <a href='$h'$e>$total</a>"; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$query['LIMIT'] = "$debut, $pas"; |
|
62
|
|
|
return $nav; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// http://doc.spip.org/@navigation_trouve_date |
|
66
|
|
|
function navigation_trouve_date($date, $nom_date, $pas, $query) |
|
67
|
|
|
{ |
|
68
|
|
|
$debut = 0; |
|
69
|
|
|
if (!is_numeric($date)) { |
|
70
|
|
|
include_spip('inc/filtres'); |
|
71
|
|
|
list($a,$m,$j,$h,$n,$s) = recup_date($date); |
|
72
|
|
|
$date = mktime($h,$n,$s,$m ? $m : 1,$j ? $j : 1,$a); |
|
73
|
|
|
} |
|
74
|
|
|
$q = sql_select($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY'], $query['ORDER BY']); |
|
75
|
|
|
while ($r = sql_fetch($q)) { |
|
76
|
|
|
if ($r[$nom_date] <= $date) break; |
|
77
|
|
|
$debut++; |
|
78
|
|
|
} |
|
79
|
|
|
$debut -= ($debut%$pas); |
|
80
|
|
|
return $debut; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// tous les boutons de controle d'un forum |
|
84
|
|
|
// nb : les forums prives (privrac ou prive), une fois effaces |
|
85
|
|
|
// (privoff), ne sont pas revalidables ; le forum d'admin (privadm) |
|
86
|
|
|
// n'est pas effacable |
|
87
|
|
|
|
|
88
|
|
|
// http://doc.spip.org/@boutons_controle_forum |
|
89
|
|
|
function boutons_controle_forum($id_forum, $forum_stat, $forum_id_auteur=0, $ref, $forum_ip, $script, $args) { |
|
90
|
|
|
$controle = $original = $spam = ''; |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
// selection du logo et des boutons correspondant a l'etat du forum |
|
94
|
|
|
switch ($forum_stat) { |
|
95
|
|
|
# forum sous un article dans l'espace prive |
|
96
|
|
View Code Duplication |
case "prive": |
|
|
|
|
|
|
97
|
|
|
$logo = "forum-interne-24.gif"; |
|
98
|
|
|
$valider = false; |
|
99
|
|
|
$valider_repondre = false; |
|
100
|
|
|
$suppression = 'privoff'; |
|
101
|
|
|
break; |
|
102
|
|
|
# forum des administrateurs |
|
103
|
|
|
case "privadmin": |
|
104
|
|
|
$logo = "forum-admin-24.gif"; |
|
105
|
|
|
$valider = false; |
|
106
|
|
|
$valider_repondre = false; |
|
107
|
|
|
$suppression = false; |
|
108
|
|
|
break; |
|
109
|
|
|
# forum de l'espace prive, supprime (non revalidable, |
|
110
|
|
|
# d'ailleurs on ne sait plus a quel type de forum il appartenait) |
|
111
|
|
View Code Duplication |
case "privoff": |
|
|
|
|
|
|
112
|
|
|
$logo = "forum-interne-24.gif"; |
|
113
|
|
|
$valider = false; |
|
114
|
|
|
$valider_repondre = false; |
|
115
|
|
|
$suppression = false; |
|
116
|
|
|
break; |
|
117
|
|
|
# forum general de l'espace prive |
|
118
|
|
View Code Duplication |
case "privrac": |
|
|
|
|
|
|
119
|
|
|
$logo = "forum-interne-24.gif"; |
|
120
|
|
|
$valider = false; |
|
121
|
|
|
$valider_repondre = false; |
|
122
|
|
|
$suppression = 'privoff'; |
|
123
|
|
|
break; |
|
124
|
|
|
|
|
125
|
|
|
# forum publie sur le site public |
|
126
|
|
View Code Duplication |
case "publie": |
|
|
|
|
|
|
127
|
|
|
$logo = "forum-public-24.gif"; |
|
128
|
|
|
$valider = false; |
|
129
|
|
|
$valider_repondre = false; |
|
130
|
|
|
$suppression = 'off'; |
|
131
|
|
|
break; |
|
132
|
|
|
# forum supprime sur le site public |
|
133
|
|
|
case "off": |
|
134
|
|
|
$logo = "forum-public-24.gif"; |
|
135
|
|
|
$valider = 'publie'; |
|
136
|
|
|
$valider_repondre = false; |
|
137
|
|
|
$suppression = false; |
|
138
|
|
|
$controle = "<br /><span style='color: red; font-weight: bold;'>"._T('info_message_supprime')." $forum_ip</span>"; |
|
139
|
|
|
if($forum_id_auteur) |
|
140
|
|
|
$controle .= " - <a href='" . generer_url_ecrire('auteur_infos', "id_auteur=$forum_id_auteur") . |
|
141
|
|
|
"'>" ._T('lien_voir_auteur'). "</a>"; |
|
142
|
|
|
break; |
|
143
|
|
|
# forum propose (a moderer) sur le site public |
|
144
|
|
View Code Duplication |
case "prop": |
|
|
|
|
|
|
145
|
|
|
$logo = "forum-public-24.gif"; |
|
146
|
|
|
$valider = 'publie'; |
|
147
|
|
|
$valider_repondre = true; |
|
148
|
|
|
$suppression = 'off'; |
|
149
|
|
|
break; |
|
150
|
|
|
# forum signale comme spam sur le site public |
|
151
|
|
View Code Duplication |
case "spam": |
|
|
|
|
|
|
152
|
|
|
$logo = "forum-public-24.gif"; |
|
153
|
|
|
$valider = 'publie'; |
|
154
|
|
|
$valider_repondre = false; |
|
155
|
|
|
$suppression = false; |
|
156
|
|
|
$spam = true; |
|
157
|
|
|
break; |
|
158
|
|
|
# forum original (reponse a un forum modifie) sur le site public |
|
159
|
|
|
case "original": |
|
160
|
|
|
$logo = "forum-public-24.gif"; |
|
161
|
|
|
$original = true; |
|
162
|
|
|
break; |
|
163
|
|
|
default: |
|
164
|
|
|
return; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$lien = generer_url_ecrire($script, $args, true, true) . "#forum$id_forum"; |
|
168
|
|
|
$boutons =''; |
|
169
|
|
|
if ($suppression) |
|
|
|
|
|
|
170
|
|
|
$boutons .= icone_inline(_T('icone_supprimer_message'), generer_action_auteur('instituer_forum',"$id_forum-$suppression", $lien), |
|
|
|
|
|
|
171
|
|
|
$logo, |
|
172
|
|
|
"supprimer.gif", 'right', 'non'); |
|
173
|
|
|
|
|
174
|
|
|
if ($valider) |
|
|
|
|
|
|
175
|
|
|
$boutons .= icone_inline(_T('icone_valider_message'), generer_action_auteur('instituer_forum',"$id_forum-$valider", $lien), |
|
|
|
|
|
|
176
|
|
|
$logo, |
|
177
|
|
|
"creer.gif", 'right', 'non'); |
|
178
|
|
|
|
|
179
|
|
|
if ($valider_repondre) { |
|
|
|
|
|
|
180
|
|
|
$dblret = rawurlencode(_DIR_RESTREINT_ABS . $lien); |
|
181
|
|
|
$boutons .= icone_inline(_T('icone_valider_message') . " & " . _T('lien_repondre_message'), generer_action_auteur('instituer_forum',"$id_forum-$valider", generer_url_public('forum', "$ref&id_forum=$id_forum&retour=$dblret", true, true)), |
|
182
|
|
|
$logo, |
|
183
|
|
|
"creer.gif", 'right', 'non'); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if ($boutons) $controle .= "<div style='float:".$GLOBALS['spip_lang_right'] ."; width: 80px; padding-bottom:20px;'>". $boutons . "</div>"; |
|
187
|
|
|
|
|
188
|
|
|
// TODO: un bouton retablir l'original ? |
|
189
|
|
View Code Duplication |
if ($original) { |
|
|
|
|
|
|
190
|
|
|
$controle .= "<div style='float:".$GLOBALS['spip_lang_right'].";color:green'>" |
|
191
|
|
|
."(" |
|
192
|
|
|
._T('forum_info_original') |
|
193
|
|
|
.")</div>"; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
View Code Duplication |
if ($spam) { |
|
|
|
|
|
|
197
|
|
|
$controle .= "<div style='float:".$GLOBALS['spip_lang_right'].";color:red'>" |
|
198
|
|
|
."(" |
|
199
|
|
|
._T('spam') // Marque' comme spam ? |
|
200
|
|
|
.")</div>"; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
return $controle; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
// recuperer le critere SQL qui selectionne nos forums |
|
208
|
|
|
// http://doc.spip.org/@critere_statut_controle_forum |
|
209
|
|
|
function critere_statut_controle_forum($type, $id_rubrique=0, $recherche='') { |
|
210
|
|
|
|
|
211
|
|
|
if (is_array($id_rubrique)) $id_rubrique = join(',',$id_rubrique); |
|
212
|
|
|
if (!$id_rubrique) { |
|
213
|
|
|
$from = 'spip_forum AS F'; |
|
214
|
|
|
$where = ""; |
|
215
|
|
|
$and = ""; |
|
216
|
|
|
} else { |
|
217
|
|
|
if (strpos($id_rubrique,',')) |
|
218
|
|
|
$eq = " IN ($id_rubrique)"; |
|
219
|
|
|
else $eq = "=$id_rubrique"; |
|
220
|
|
|
|
|
221
|
|
|
$from = 'spip_forum AS F, spip_articles AS A'; |
|
222
|
|
|
$where = "A.id_secteur$eq AND F.id_article=A.id_article"; |
|
223
|
|
|
$and = ' AND '; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
switch ($type) { |
|
227
|
|
|
case 'public': |
|
228
|
|
|
$and .= "F.statut IN ('publie', 'off', 'prop', 'spam') AND F.texte!=''"; |
|
229
|
|
|
break; |
|
230
|
|
|
case 'prop': |
|
231
|
|
|
$and .= "F.statut='prop'"; |
|
232
|
|
|
break; |
|
233
|
|
|
case 'spam': |
|
234
|
|
|
$and .= "F.statut='spam'"; |
|
235
|
|
|
break; |
|
236
|
|
|
case 'interne': |
|
237
|
|
|
$and .= "F.statut IN ('prive', 'privrac', 'privoff', 'privadm') AND F.texte!=''"; |
|
238
|
|
|
break; |
|
239
|
|
|
case 'vide': |
|
240
|
|
|
$and .= "F.statut IN ('publie', 'off', 'prive', 'privrac', 'privoff', 'privadm') AND F.texte=''"; |
|
241
|
|
|
break; |
|
242
|
|
|
default: |
|
243
|
|
|
$where = '0=1'; |
|
244
|
|
|
$and =''; |
|
245
|
|
|
break; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
if ($recherche) { |
|
249
|
|
|
# recherche par IP |
|
250
|
|
|
if (preg_match(',^\d+\.\d+\.(\*|\d+\.(\*|\d+))$,', $recherche)) { |
|
251
|
|
|
$and .= " AND ip LIKE ".sql_quote(str_replace('*', '%', $recherche)); |
|
252
|
|
|
} else { |
|
253
|
|
|
include_spip('inc/rechercher'); |
|
254
|
|
|
if ($a = recherche_en_base($recherche, 'forum')) |
|
255
|
|
|
$and .= " AND ".sql_in('id_forum', |
|
256
|
|
|
array_keys(array_pop($a))); |
|
257
|
|
|
else |
|
258
|
|
|
$and .= " AND 0=1"; |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
return array($from, "$where$and"); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
// Index d'invalidation des forums |
|
266
|
|
|
// http://doc.spip.org/@calcul_index_forum |
|
267
|
|
|
function calcul_index_forum($id_article, $id_breve, $id_rubrique, $id_syndic) { |
|
268
|
|
|
if ($id_article) return 'a'.$id_article; |
|
269
|
|
|
if ($id_breve) return 'b'.$id_breve; |
|
270
|
|
|
if ($id_rubrique) return 'r'.$id_rubrique; |
|
271
|
|
|
if ($id_syndic) return 's'.$id_syndic; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
// |
|
275
|
|
|
// Recalculer tous les threads |
|
276
|
|
|
// |
|
277
|
|
|
// http://doc.spip.org/@calculer_threads |
|
278
|
|
|
function calculer_threads() { |
|
279
|
|
|
// fixer les id_thread des debuts de discussion |
|
280
|
|
|
sql_update('spip_forum', array('id_thread'=>'id_forum'), "id_parent=0"); |
|
281
|
|
|
// reparer les messages qui n'ont pas l'id_secteur de leur parent |
|
282
|
|
|
do { |
|
283
|
|
|
$discussion = "0"; |
|
284
|
|
|
$precedent = 0; |
|
285
|
|
|
$r = sql_select("fille.id_forum AS id, maman.id_thread AS thread", 'spip_forum AS fille, spip_forum AS maman', "fille.id_parent = maman.id_forum AND fille.id_thread <> maman.id_thread",'', "thread"); |
|
286
|
|
|
while ($row = sql_fetch($r)) { |
|
287
|
|
|
if ($row['thread'] == $precedent) |
|
288
|
|
|
$discussion .= "," . $row['id']; |
|
289
|
|
|
else { |
|
290
|
|
|
if ($precedent) |
|
291
|
|
|
sql_updateq("spip_forum", array("id_thread" => $precedent), "id_forum IN ($discussion)"); |
|
292
|
|
|
$precedent = $row['thread']; |
|
293
|
|
|
$discussion = $row['id']; |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
sql_updateq("spip_forum", array("id_thread" => $precedent), "id_forum IN ($discussion)"); |
|
297
|
|
|
} while ($discussion != "0"); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
// Calculs des URLs des forums (pour l'espace public) |
|
301
|
|
|
// http://doc.spip.org/@racine_forum |
|
302
|
|
|
function racine_forum($id_forum){ |
|
303
|
|
|
if (!$id_forum = intval($id_forum)) return false; |
|
304
|
|
|
|
|
305
|
|
|
$row = sql_fetsel("id_parent, id_rubrique, id_article, id_breve, id_syndic, id_message, id_thread", "spip_forum", "id_forum=".$id_forum); |
|
306
|
|
|
|
|
307
|
|
|
if (!$row) return false; |
|
308
|
|
|
|
|
309
|
|
|
if ($row['id_parent'] |
|
310
|
|
|
AND $row['id_thread'] != $id_forum) // eviter boucle infinie |
|
311
|
|
|
return racine_forum($row['id_thread']); |
|
312
|
|
|
|
|
313
|
|
|
if ($row['id_message']) |
|
314
|
|
|
return array('message', $row['id_message'], $id_forum); |
|
315
|
|
|
if ($row['id_rubrique']) |
|
316
|
|
|
return array('rubrique', $row['id_rubrique'], $id_forum); |
|
317
|
|
|
if ($row['id_article']) |
|
318
|
|
|
return array('article', $row['id_article'], $id_forum); |
|
319
|
|
|
if ($row['id_breve']) |
|
320
|
|
|
return array('breve', $row['id_breve'], $id_forum); |
|
321
|
|
|
if ($row['id_syndic']) |
|
322
|
|
|
return array('site', $row['id_syndic'], $id_forum); |
|
323
|
|
|
|
|
324
|
|
|
// On ne devrait jamais arriver ici, mais prevoir des cas de forums |
|
325
|
|
|
// poses sur autre chose que les objets prevus... |
|
326
|
|
|
spip_log("erreur racine_forum $id_forum"); |
|
327
|
|
|
return array(); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
// http://doc.spip.org/@parent_forum |
|
332
|
|
|
function parent_forum($id_forum) { |
|
333
|
|
|
if (!$id_forum = intval($id_forum)) return; |
|
334
|
|
|
$row = sql_fetsel("id_parent, id_rubrique, id_article, id_breve, id_syndic", "spip_forum", "id_forum=".$id_forum); |
|
335
|
|
|
if(!$row) return array(); |
|
336
|
|
|
if($row['id_parent']) return array('forum', $row['id_parent']); |
|
337
|
|
|
if($row['id_article']) return array('article', $row['id_article']); |
|
338
|
|
|
if($row['id_breve']) return array('breve', $row['id_breve']); |
|
339
|
|
|
if($row['id_rubrique']) return array('rubrique', $row['id_rubrique']); |
|
340
|
|
|
if($row['id_syndic']) return array('site', $row['id_syndic']); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
|
|
344
|
|
|
// obsolete, maintenu poru compat |
|
345
|
|
|
// http://doc.spip.org/@generer_url_forum_dist |
|
346
|
|
|
function generer_url_forum_dist($id_forum, $args='', $ancre='') { |
|
347
|
|
|
$generer_url_externe = charger_fonction("generer_url_forum",'urls'); |
|
348
|
|
|
return $generer_url_externe($id_forum, $args, $ancre); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
|
|
352
|
|
|
// http://doc.spip.org/@generer_url_forum_parent |
|
353
|
|
|
function generer_url_forum_parent($id_forum) { |
|
354
|
|
|
if ($id_forum = intval($id_forum)) { |
|
355
|
|
|
list($type, $id) = parent_forum($id_forum); |
|
356
|
|
|
if ($type) |
|
357
|
|
|
return generer_url_entite($id, $type); |
|
358
|
|
|
} |
|
359
|
|
|
return ''; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
// Quand on edite un forum, on tient a conserver l'original |
|
364
|
|
|
// sous forme d'un forum en reponse, de statut 'original' |
|
365
|
|
|
// http://doc.spip.org/@conserver_original |
|
366
|
|
|
function conserver_original($id_forum) { |
|
367
|
|
|
$s = sql_fetsel("id_forum", "spip_forum", "id_parent=".sql_quote($id_forum)." AND statut='original'"); |
|
368
|
|
|
|
|
369
|
|
|
if ($s) return ''; // pas d'erreur |
|
370
|
|
|
|
|
371
|
|
|
// recopier le forum |
|
372
|
|
|
$t = sql_fetsel("*", "spip_forum", "id_forum=".sql_quote($id_forum)); |
|
373
|
|
|
|
|
374
|
|
|
if ($t) { |
|
375
|
|
|
unset($t['id_forum']); |
|
376
|
|
|
$id_copie = sql_insertq('spip_forum', $t); |
|
377
|
|
|
if ($id_copie) { |
|
378
|
|
|
sql_updateq('spip_forum', array('id_parent'=> $id_forum, 'statut'=>'original'), "id_forum=$id_copie"); |
|
379
|
|
|
return ''; // pas d'erreur |
|
380
|
|
|
} |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
return '&erreur'; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
// appelle conserver_original(), puis modifie le contenu via l'API inc/modifier |
|
387
|
|
|
// http://doc.spip.org/@enregistre_et_modifie_forum |
|
388
|
|
|
function enregistre_et_modifie_forum($id_forum, $c=false) { |
|
389
|
|
|
if ($err = conserver_original($id_forum)) { |
|
390
|
|
|
spip_log("erreur de sauvegarde de l'original, $err"); |
|
391
|
|
|
return; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
include_spip('inc/modifier'); |
|
395
|
|
|
return revision_forum($id_forum, $c); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
// |
|
399
|
|
|
// Afficher les forums |
|
400
|
|
|
// |
|
401
|
|
|
|
|
402
|
|
|
// http://doc.spip.org/@afficher_forum |
|
403
|
|
|
function afficher_forum($query, $retour, $arg, $controle_id_article = false, $script='', $argscript='') { |
|
404
|
|
|
global $spip_display; |
|
405
|
|
|
static $compteur_forum = 0; |
|
406
|
|
|
static $nb_forum = array(); |
|
407
|
|
|
static $thread = array(); |
|
408
|
|
|
|
|
409
|
|
|
$request = sql_allfetsel($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUP BY'], $query['ORDER BY'], $query['LIMIT']); |
|
410
|
|
|
$compteur_forum++; |
|
411
|
|
|
$nb_forum[$compteur_forum] = count($request); |
|
412
|
|
|
$thread[$compteur_forum] = 1; |
|
413
|
|
|
|
|
414
|
|
|
$res = ''; |
|
415
|
|
|
|
|
416
|
|
|
foreach($request as $row) { |
|
417
|
|
|
$statut=$row['statut']; |
|
418
|
|
|
$id_parent=$row['id_parent']; |
|
419
|
|
|
if (($controle_id_article) ? ($statut!="perso") : |
|
420
|
|
|
(($statut=="prive" OR $statut=="privrac" OR $statut=="privadm" OR $statut=="perso") |
|
421
|
|
|
OR ($statut=="publie" AND $id_parent > 0))) { |
|
422
|
|
|
|
|
423
|
|
|
$query = array('SELECT' => "*", |
|
424
|
|
|
'FROM' => "spip_forum", |
|
425
|
|
|
'WHERE' => "id_parent='" . $row['id_forum'] . "'" . ($controle_id_article ? '':" AND statut<>'off'"), |
|
426
|
|
|
'ORDER BY' => "date_heure"); |
|
427
|
|
|
|
|
428
|
|
|
$bloc = afficher_forum_thread($row, $controle_id_article, $compteur_forum, $nb_forum, $thread, $retour, $arg, $script, $argscript) |
|
429
|
|
|
. afficher_forum($query, $retour, $arg, $controle_id_article, $script, $argscript); |
|
430
|
|
|
|
|
431
|
|
|
$res .= ajax_action_greffe('poster_forum_prive', $row['id_forum'], $bloc); |
|
432
|
|
|
} |
|
433
|
|
|
$thread[$compteur_forum]++; |
|
434
|
|
|
} |
|
435
|
|
|
$compteur_forum--; |
|
436
|
|
|
if ($spip_display == 4 AND $res) $res = "<ul>$res</ul>"; |
|
437
|
|
|
return $res; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
// Construit une Div comportant un unique message, |
|
441
|
|
|
// plus les lignes verticales de conduite |
|
442
|
|
|
|
|
443
|
|
|
// http://doc.spip.org/@afficher_forum_thread |
|
444
|
|
|
function afficher_forum_thread($row, $controle_id_article, $compteur_forum, $nb_forum, $i, $retour, $arg, $script, $argscript) { |
|
445
|
|
|
global $spip_lang_right, $spip_display; |
|
446
|
|
|
static $voir_logo = array(); // pour ne calculer qu'une fois |
|
447
|
|
|
|
|
448
|
|
|
if (is_array($voir_logo)) { |
|
449
|
|
|
$voir_logo = (($spip_display != 1 AND $spip_display != 4 AND $GLOBALS['meta']['image_process'] != "non") ? |
|
450
|
|
|
"position: absolute; $spip_lang_right: 0px; margin: 0px; margin-top: -3px; margin-$spip_lang_right: 0px;" |
|
451
|
|
|
: ''); |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
$id_forum=$row['id_forum']; |
|
455
|
|
|
$id_parent=$row['id_parent']; |
|
|
|
|
|
|
456
|
|
|
$id_rubrique=$row['id_rubrique']; |
|
|
|
|
|
|
457
|
|
|
$id_article=$row['id_article']; |
|
458
|
|
|
$id_breve=$row['id_breve']; |
|
|
|
|
|
|
459
|
|
|
$id_message=$row['id_message']; |
|
|
|
|
|
|
460
|
|
|
$id_syndic=$row['id_syndic']; |
|
|
|
|
|
|
461
|
|
|
$id_auteur=$row["id_auteur"]; |
|
462
|
|
|
$titre=$row['titre']; |
|
463
|
|
|
$texte=$row['texte']; |
|
464
|
|
|
$nom_site=$row['nom_site']; |
|
465
|
|
|
$url_site=$row['url_site']; |
|
466
|
|
|
$statut=$row['statut']; |
|
467
|
|
|
$ip=$row["ip"]; |
|
468
|
|
|
|
|
469
|
|
|
$h = (!$id_article ? '' : generer_url_entite($id_article, 'article')) |
|
470
|
|
|
. "#forum$id_forum"; |
|
471
|
|
|
|
|
472
|
|
|
$titre_boite = "<a href='$h' id='forum$id_forum'>" |
|
473
|
|
|
. typo($titre) |
|
474
|
|
|
. '</a>'; |
|
475
|
|
|
|
|
476
|
|
|
if ($spip_display == 4) { |
|
477
|
|
|
$res = $titre_boite ."<br id='id$id_forum' />"; |
|
478
|
|
|
} else { |
|
479
|
|
|
if ($id_auteur AND $voir_logo) { |
|
480
|
|
|
$chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
481
|
|
View Code Duplication |
if ($logo = $chercher_logo($id_auteur, 'id_auteur', 'on')) { |
|
|
|
|
|
|
482
|
|
|
list($fid, $dir, $nom, $format) = $logo; |
|
|
|
|
|
|
483
|
|
|
include_spip('inc/filtres_images_mini'); |
|
484
|
|
|
$logo = image_reduire("<img src='$fid' alt='' />", 48, 48); |
|
485
|
|
|
if ($logo) |
|
486
|
|
|
$titre_boite = "\n<div style='$voir_logo'>$logo</div>$titre_boite" ; |
|
487
|
|
|
} |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
|
|
491
|
|
|
$res = "<tr id='id$id_forum'>" |
|
492
|
|
|
. afficher_forum_4($compteur_forum, $nb_forum, $i) |
|
493
|
|
|
. "\n<td style='width: 100%' valign='top'>" |
|
494
|
|
|
. (($compteur_forum == 1) |
|
495
|
|
|
? debut_cadre_forum(forum_logo($statut), true, "", $titre_boite) |
|
496
|
|
|
: debut_cadre_thread_forum("", true, "", $titre_boite)); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
// Si refuse, cadre rouge |
|
500
|
|
|
if ($statut=="off") { |
|
501
|
|
|
$style =" style='border: 2px dashed red; padding: 5px;'"; |
|
502
|
|
|
} |
|
503
|
|
|
// Si propose, cadre jaune |
|
504
|
|
|
else if ($statut=="prop") { |
|
505
|
|
|
$style = " style='border: 1px solid yellow; padding: 5px;'"; |
|
506
|
|
|
} |
|
507
|
|
|
// Si original, cadre vert |
|
508
|
|
|
else if ($statut=="original") { |
|
509
|
|
|
$style = " style='border: 1px solid green; padding: 5px;'"; |
|
510
|
|
|
} else $style = ''; |
|
511
|
|
|
|
|
512
|
|
|
$mots = afficher_forum_mots($id_forum); |
|
513
|
|
|
|
|
514
|
|
|
$res .= "<table$style width='100%' cellpadding='5' cellspacing='0'>\n<tr><td>" |
|
515
|
|
|
. afficher_forum_auteur($row) |
|
516
|
|
|
. (!$controle_id_article ? '' : |
|
517
|
|
|
boutons_controle_forum($id_forum, $statut, $id_auteur, "id_article=$id_article", $ip, $script, $argscript)) |
|
518
|
|
|
. "<div style='font-weight: normal;'>" |
|
519
|
|
|
. safehtml(justifier(propre($texte))) |
|
520
|
|
|
. join(', ', lister_forum_documents($id_forum)) |
|
521
|
|
|
. "</div>\n" |
|
522
|
|
|
. (!$nom_site ? '' : |
|
523
|
|
|
((strlen($url_site) > 10) ? "\n<div style='text-align: left' class='verdana2'><b><a href='$url_site'>$nom_site</a></b></div>" |
|
524
|
|
|
: "<b>$nom_site</b>")) |
|
525
|
|
|
. ($controle_id_article ? '' : |
|
526
|
|
|
repondre_forum($row, $titre, $statut, "$retour?$arg", _T('lien_repondre_message'))) |
|
527
|
|
|
. $mots |
|
528
|
|
|
. "</td></tr></table>"; |
|
529
|
|
|
|
|
530
|
|
|
if ($spip_display == 4) return "\n<li>$res</li>\n"; |
|
531
|
|
|
|
|
532
|
|
|
if ($compteur_forum == 1) $res .= fin_cadre_forum(true); |
|
533
|
|
|
else $res .= fin_cadre_thread_forum(true); |
|
534
|
|
|
$res .= "</td></tr>"; |
|
535
|
|
|
|
|
536
|
|
|
return "<table width='100%' cellpadding='0' cellspacing='0' border='0'>$res</table>\n"; |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
// http://doc.spip.org/@repondre_forum |
|
540
|
|
|
function repondre_forum($row, $titre, $statut, $retour, $clic) |
|
541
|
|
|
{ |
|
542
|
|
|
$id_forum = $row['id_forum']; |
|
543
|
|
|
$id_thread = $row['id_thread']; |
|
544
|
|
|
$ancre = "poster_forum_prive-$id_thread"; |
|
545
|
|
|
|
|
546
|
|
|
$lien = generer_url_ecrire("poster_forum_prive", "statut=$statut&id_parent=$id_forum&titre_message=" . rawurlencode($titre) . "&script=" . urlencode($retour)) . '#formulaire'; |
|
547
|
|
|
|
|
548
|
|
|
return "<div style='text-align: right' class='verdana1'><b><a onclick=" |
|
549
|
|
|
. ajax_action_declencheur($lien, $ancre) |
|
550
|
|
|
. "\nhref='" |
|
551
|
|
|
. $lien |
|
552
|
|
|
. "'>" |
|
553
|
|
|
. $clic |
|
554
|
|
|
. "</a></b></div>\n"; |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
// http://doc.spip.org/@afficher_forum_auteur |
|
558
|
|
|
function afficher_forum_auteur($row) |
|
559
|
|
|
{ |
|
560
|
|
|
$titre=$row['titre']; |
|
561
|
|
|
$id_auteur=$row["id_auteur"]; |
|
562
|
|
|
$date_heure=$row['date_heure']; |
|
563
|
|
|
$email_auteur=$row['email_auteur']; |
|
564
|
|
|
$auteur= extraire_multi($row['auteur']); |
|
565
|
|
|
|
|
566
|
|
|
if ($id_auteur) { |
|
567
|
|
|
$formater_auteur = charger_fonction('formater_auteur', 'inc'); |
|
568
|
|
|
$res = join(' ',$formater_auteur($id_auteur)); |
|
569
|
|
|
} else { |
|
570
|
|
|
if ($email_auteur) { |
|
571
|
|
View Code Duplication |
if (email_valide($email_auteur)) |
|
|
|
|
|
|
572
|
|
|
$email_auteur = "<a href='mailto:" |
|
573
|
|
|
.htmlspecialchars($email_auteur) |
|
574
|
|
|
."?subject=".rawurlencode($titre)."'>".$email_auteur |
|
575
|
|
|
."</a>"; |
|
576
|
|
|
$auteur .= " — $email_auteur"; |
|
577
|
|
|
} |
|
578
|
|
|
$res = safehtml("<span class='arial2'> / <b>$auteur</b></span>"); |
|
579
|
|
|
} |
|
580
|
|
|
return "<div style='font-weight: normal;'>" |
|
581
|
|
|
. date_interface($date_heure) |
|
582
|
|
|
. " $res</div>"; |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
// http://doc.spip.org/@afficher_forum_mots |
|
586
|
|
|
function afficher_forum_mots($id_forum) |
|
587
|
|
|
{ |
|
588
|
|
|
if ($GLOBALS['meta']["mots_cles_forums"] <> "oui") return ''; |
|
589
|
|
|
|
|
590
|
|
|
$mots = sql_allfetsel("titre, type", "spip_mots AS M LEFT JOIN spip_mots_forum AS L ON L.id_mot=M.id_mot", "L.id_forum=" . intval($id_forum)); |
|
591
|
|
|
|
|
592
|
|
View Code Duplication |
foreach ($mots as $k => $r) { |
|
|
|
|
|
|
593
|
|
|
$mots[$k] = propre('<b>' . $r['type'] . ' :</b>') . ' ' |
|
594
|
|
|
. propre($r['titre']); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
if (!$mots) return ''; |
|
598
|
|
|
return ("\n<ul><li>" . join("</li>\n<li>", $mots) . "</li></ul>\n"); |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
// affiche les traits de liaisons entre les reponses |
|
602
|
|
|
|
|
603
|
|
|
// http://doc.spip.org/@afficher_forum_4 |
|
604
|
|
|
function afficher_forum_4($compteur_forum, $nb_forum, $thread) |
|
605
|
|
|
{ |
|
606
|
|
|
global $spip_lang_rtl; |
|
607
|
|
|
$fleche2="forum-droite$spip_lang_rtl.gif"; |
|
608
|
|
|
$fleche='rien.gif'; |
|
609
|
|
|
$vertical = chemin_image('forum-vert.gif'); |
|
610
|
|
|
$rien = chemin_image('rien.gif'); |
|
611
|
|
|
$res = ''; |
|
612
|
|
|
for ($j=2;$j<=$compteur_forum AND $j<20;$j++){ |
|
613
|
|
|
$res .= "<td style='width: 10px; vertical-align: top; background-image: url(" |
|
614
|
|
|
. (($thread[$j]!=$nb_forum[$j]) ? $vertical : $rien) |
|
615
|
|
|
. ");'>" |
|
616
|
|
|
. http_img_pack(($j==$compteur_forum) ? $fleche2 : $fleche, "", "width='10' height='13'") |
|
617
|
|
|
. "</td>\n"; |
|
618
|
|
|
} |
|
619
|
|
|
return $res; |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
function lister_forum_documents($id_forum, $autoriser=true) |
|
623
|
|
|
{ |
|
624
|
|
|
if ($documents = sql_allfetsel('D.id_document, D.fichier AS fichier', 'spip_documents AS D LEFT JOIN spip_documents_liens AS L ON D.id_document=L.id_document', "objet='forum' AND L.id_objet=".intval($id_forum))) { |
|
625
|
|
|
include_spip('inc/documents'); |
|
626
|
|
|
foreach ($documents as $k => $t) { |
|
627
|
|
|
$texte = basename($t['fichier']); |
|
628
|
|
|
if ($autoriser) { |
|
629
|
|
|
$h = generer_url_entite($t['id_document'], 'document'); |
|
630
|
|
|
$texte = "<a href='$h'>$texte</a>"; |
|
631
|
|
|
} |
|
632
|
|
|
$documents[$k] = $texte; |
|
633
|
|
|
} |
|
634
|
|
|
} |
|
635
|
|
|
return $documents; |
|
636
|
|
|
} |
|
637
|
|
|
?> |
|
|
|
|
|
|
638
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.