source: trunk/web/punbb/index.php @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 12.8 KB
Line 
1<?php
2/***********************************************************************
3
4  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
5
6  This file is part of PunBB.
7
8  PunBB is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published
10  by the Free Software Foundation; either version 2 of the License,
11  or (at your option) any later version.
12
13  PunBB is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  MA  02111-1307  USA
22
23************************************************************************/
24
25
26define('PUN_ROOT', './');
27require PUN_ROOT.'include/common.php';
28
29
30if ($pun_user['g_read_board'] == '0')
31        message($lang_common['No view']);
32
33
34// Load the index.php language file
35require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
36
37$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
38define('PUN_ALLOW_INDEX', 1);
39require PUN_ROOT.'header.php';
40
41// Print the categories and forums
42$result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Impossible de retrouver la liste des catégories et des forums.', __FILE__, __LINE__, $db->error());
43
44$cur_category = 0;
45$cat_count = 0;
46while ($cur_forum = $db->fetch_assoc($result))
47{
48        $moderators = '';
49
50        if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
51        {
52                if ($cur_category != 0)
53                        echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n";
54
55                ++$cat_count;
56
57?>
58<div id="idx<?php echo $cat_count ?>" class="blocktable">
59        <h2><span><?php echo pun_htmlspecialchars($cur_forum['cat_name']) ?></span></h2>
60        <div class="box">
61                <div class="inbox">
62                        <table cellspacing="0">
63                        <thead>
64                                <tr>
65                                        <th class="tcl" scope="col"><?php echo $lang_common['Forum'] ?></th>
66                                        <th class="tc2" scope="col"><?php echo $lang_index['Topics'] ?></th>
67                                        <th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
68                                        <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
69                                </tr>
70                        </thead>
71                        <tbody>
72<?php
73
74                $cur_category = $cur_forum['cid'];
75        }
76
77        $item_status = '';
78        $icon_text = $lang_common['Normal icon'];
79        $icon_type = 'icon';
80
81        // Are there new posts?
82        if (!$pun_user['is_guest'] && $cur_forum['last_post'] > $pun_user['last_visit'])
83        {
84                $item_status = 'inew';
85                $icon_text = $lang_common['New icon'];
86                $icon_type = 'icon inew';
87        }
88
89        // Is this a redirect forum?
90        if ($cur_forum['redirect_url'] != '')
91        {
92                $forum_field = '<h3><a href="'.pun_htmlspecialchars($cur_forum['redirect_url']).'" title="'.$lang_index['Link to'].' '.pun_htmlspecialchars($cur_forum['redirect_url']).'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a></h3>';
93                $num_topics = $num_posts = '&#160;';
94                $item_status = 'iredirect';
95                $icon_text = $lang_common['Redirect icon'];
96                $icon_type = 'icon';
97        }
98        else
99        {
100                $forum_field = '<h3><a href="viewforum.php?id='.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a></h3>';
101                $num_topics = $cur_forum['num_topics'];
102                $num_posts = $cur_forum['num_posts'];
103        }
104
105        if ($cur_forum['forum_desc'] != '')
106                $forum_field .= "\n\t\t\t\t\t\t\t\t".$cur_forum['forum_desc'];
107
108
109        // If there is a last_post/last_poster.
110        if ($cur_forum['last_post'] != '')
111                $last_post = '<a href="viewtopic.php?pid='.$cur_forum['last_post_id'].'#p'.$cur_forum['last_post_id'].'">'.format_time($cur_forum['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_forum['last_poster']).'</span>';
112        else
113                $last_post = '&#160;';
114
115        if ($cur_forum['moderators'] != '')
116        {
117                $mods_array = unserialize($cur_forum['moderators']);
118                $moderators = array();
119
120                while (list($mod_username, $mod_id) = @each($mods_array))
121                        $moderators[] = '<a href="profile.php?id='.$mod_id.'">'.pun_htmlspecialchars($mod_username).'</a>';
122
123                $moderators = "\t\t\t\t\t\t\t\t".'<p><em>('.$lang_common['Moderated by'].'</em> '.implode(', ', $moderators).')</p>'."\n";
124        }
125
126?>
127                                <tr<?php if ($item_status != '') echo ' class="'.$item_status.'"'; ?>>
128                                        <td class="tcl">
129                                                <div class="intd">
130                                                        <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo $icon_text ?></div></div>
131                                                        <div class="tclcon">
132                                                                <?php echo $forum_field."\n".$moderators ?>
133                                                        </div>
134                                                </div>
135                                        </td>
136                                        <td class="tc2"><?php echo $num_topics ?></td>
137                                        <td class="tc3"><?php echo $num_posts ?></td>
138                                        <td class="tcr"><?php echo $last_post ?></td>
139                                </tr>
140<?php
141
142}
143
144// Did we output any categories and forums?
145if ($cur_category > 0)
146        echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n";
147else
148        echo '<div id="idx0" class="block"><div class="box"><div class="inbox"><p>'.$lang_index['Empty board'].'</p></div></div></div>';
149
150
151// Collect some statistics from the database
152$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Impossible de retrouver le nombre total d\utilisateurs', __FILE__, __LINE__, $db->error());
153$stats['total_users'] = $db->result($result);
154
155$result = $db->query('SELECT id, username FROM '.$db->prefix.'users ORDER BY registered DESC LIMIT 1') or error('Impossible de retrouver le dernier membre inscrit', __FILE__, __LINE__, $db->error());
156$stats['last_user'] = $db->fetch_assoc($result);
157
158$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Impossible de retrouver le nombre de discussions et de messages', __FILE__, __LINE__, $db->error());
159list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
160
161?>
162<div id="brdstats" class="block">
163        <h2><span><?php echo $lang_index['Board info'] ?></span></h2>
164        <div class="box">
165                <div class="inbox">
166                        <dl class="conr">
167                                <dt><strong><?php echo $lang_index['Board stats'] ?></strong></dt>
168                                <dd><?php echo $lang_index['No of users'].': <strong>'. $stats['total_users'] ?></strong></dd>
169                                <dd><?php echo $lang_index['No of topics'].': <strong>'.$stats['total_topics'] ?></strong></dd>
170                                <dd><?php echo $lang_index['No of posts'].': <strong>'.$stats['total_posts'] ?></strong></dd>
171                        </dl>
172                        <dl class="conl">
173                                <dt><strong><?php echo $lang_index['User info'] ?></strong></dt>
174                                <dd><?php echo $lang_index['Newest user'] ?>: <a href="profile.php?id=<?php echo $stats['last_user']['id'] ?>"><?php echo pun_htmlspecialchars($stats['last_user']['username']) ?></a></dd>
175<?php
176
177if ($pun_config['o_users_online'] == '1')
178{
179        // Fetch users online info and generate strings for output
180        $num_guests = 0;
181        $users = array();
182        $result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Impossible de retrouver la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error());
183
184        while ($pun_user_online = $db->fetch_assoc($result))
185        {
186                if ($pun_user_online['user_id'] > 1)
187                        $users[] = "\n\t\t\t\t".'<dd><a href="profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a>';
188                else
189                        ++$num_guests;
190        }
191
192        $num_users = count($users);
193        echo "\t\t\t\t".'<dd>'. $lang_index['Users online'].': <strong>'.$num_users.'</strong></dd>'."\n\t\t\t\t".'<dd>'.$lang_index['Guests online'].': <strong>'.$num_guests.'</strong></dd>'."\n\t\t\t".'</dl>'."\n";
194
195
196        if ($num_users > 0)
197                echo "\t\t\t".'<dl id="onlinelist" class= "clearb">'."\n\t\t\t\t".'<dt><strong>'.$lang_index['Online'].':&#160;</strong></dt>'."\t\t\t\t".implode(',</dd> ', $users).'</dd>'."\n\t\t\t".'</dl>'."\n";
198        else
199                echo "\t\t\t".'<div class="clearer"></div>'."\n";
200
201}
202else
203        echo "\t\t".'</dl>'."\n\t\t\t".'<div class="clearer"></div>'."\n";
204
205
206?>
207                </div>
208        </div>
209</div>
210<?php
211$hide_smilies = 0;
212$nb_messages_max = 50;
213$nom_fichier = 'chatbox.txt';
214$hauteur_parloire = '200px';
215$largeur_parloire = '100%';
216$color_box = '#666666';
217$color_title = '#FFFFFF';
218
219$anti_flood_msg = '<strong>ATTENTION : Vous avez déjà posté exactement le même message dans la chatbox auparavant. Pour éviter d\'encombrer la chatbox, votre message n\'a pas été posté.</strong>';
220$anti_blanc_msg = '<strong>ATTENTION : Vous avez posté un message sans aucun texte ! Votre "message" n\'a pas été posté.</strong>';
221$no_membre_msg = '<strong>Vous devez être membre pour accéder à la chatbox</strong>';
222$actualiser_msg = 'Actualiser';
223$poster_msg = 'Poster';
224
225
226require PUN_ROOT.'include/parser.php';
227
228$tpl_parloir = file_get_contents(PUN_ROOT.$nom_fichier);
229
230$messages = explode("</MESSAGE>", $tpl_parloir);
231
232$nb_messages = count($messages);
233
234$parloir = '';
235$parloir_txt = '';
236$anti_flood = 0;
237
238if (isset($_GET['option']) && isset($_POST['message']) && !$pun_user['is_guest'])
239  $parloir_tmp_flood = '<MESSAGE><ID>'.$pun_user['id'].'</ID><TEXTE>'.$_POST['message'].'</TEXTE>';
240else
241  $parloir_tmp_flood = '<no_post>';
242
243 
244for($i=0;$i<$nb_messages - 1;$i++)
245{
246  $grab = ereg("<ID>(.*)</ID>", $messages[$i], $mess_id);
247  $grab = ereg("<PSEUDO>(.*)</PSEUDO>", $messages[$i], $mess_pseudo);
248  $grab = ereg("<DATE>(.*)</DATE>", $messages[$i], $mess_date);
249  $grab = ereg("<TEXTE>(.*)</TEXTE>", $messages[$i], $mess_texte);
250
251  $parloir .= '<a href="profile.php?id='.$mess_id[1].'"><strong>'.pun_htmlspecialchars($mess_pseudo[1]).'</strong></a> - '.format_time($mess_date[1])."\n".'<br />'."\n".parse_message($mess_texte[1], $hide_smilies)."\n"."\n"."\n";
252  if ($i+1 < $nb_messages_max)
253  {
254
255  $parloir_txt_flood = '<MESSAGE><ID>'.$mess_id[1].'</ID><TEXTE>'.$mess_texte[1].'</TEXTE>';
256
257   if ($parloir_tmp_flood == $parloir_txt_flood)
258    $anti_flood = 1;
259
260    $parloir_txt .= '<MESSAGE>'."\r".' <ID>'.$mess_id[1].'</ID>'."\r".' <PSEUDO>'.$mess_pseudo[1].'</PSEUDO>'."\r".' <DATE>'.$mess_date[1].'</DATE>'."\r".' <TEXTE>'.$mess_texte[1].'</TEXTE>'."\r".'</MESSAGE>'."\n\n";
261
262  }
263
264}
265
266if (isset($_GET['option']) && isset($_POST['message']) && !$pun_user['is_guest'])
267{
268    if ($anti_flood == 0 && $_POST['message'] != '')
269    {
270      $fp = fopen(PUN_ROOT.$nom_fichier, "w");
271      if ($fp)
272      {
273        $parloir_txt = '<MESSAGE>'."\r".' <ID>'.$pun_user['id'].'</ID>'."\r".' <PSEUDO>'.$pun_user['username'].'</PSEUDO>'."\r".' <DATE>'.time().'</DATE>'."\r".' <TEXTE>'.$_POST['message'].'</TEXTE>'."\r".'</MESSAGE>'."\n\n".$parloir_txt;
274        $r = fwrite($fp, $parloir_txt);
275      }
276      fclose($fp); 
277      $parloir = '<a href="profile.php?id='.$pun_user['id'].'"><strong>'.pun_htmlspecialchars($pun_user['username']).'</strong></a> - '.format_time(time())."\n".'<br />'."\n".parse_message($_POST['message'], $hide_smilies)."\n"."\n"."\n".$parloir;
278    }
279    elseif ($anti_flood == 1)
280    {
281      $parloir = $anti_flood_msg."\n".'<br />'."\n".'<br />'."\n".$parloir;
282    }
283    else
284    {
285      $parloir = $anti_blanc_msg."\n".'<br />'."\n".'<br />'."\n".$parloir;
286    }
287}
288
289
290
291?>
292  <div style="border:1px solid <?php echo $color_box; ?>;width:<?php echo $largeur_parloire; ?>;">
293    <table border="0" cellspacing="0" cellpadding="0">
294          <tr style="background: <?php echo $color_box; ?>;color: <?php echo $color_title; ?>;">
295            <td style="border:none;"><strong>Chatbox</strong></td>
296          </tr>
297    </table>
298  <div style="background-color:#1f1f1f;padding:5px;margin:0;overflow:auto;height:<?php echo $hauteur_parloire; ?>;">
299<?php echo $parloir; ?>
300
301  </div>
302<?php
303
304if ($pun_user['is_guest'])
305{
306?>
307    <table border="0" cellspacing="0" cellpadding="0">
308          <tr style="background: <?php echo $color_box; ?>;color: <?php echo $color_title; ?>;">
309            <td style="border:none;"><?php echo $no_membre_msg; ?></td>
310          </tr>
311    </table>
312<?php
313}
314else
315{
316?>
317    <table border="0" cellspacing="0" cellpadding="0">
318          <tr style="background: <?php echo $color_box; ?>;color: <?php echo $color_title; ?>;">
319            <td style="border:none;vertical-align:middle;">
320          <form method="post" name="form_parloir" action="?option=post">
321            <NOBR><strong>Message : </strong> <input type="text" name="message"  size="35" maxlength="255" /> <input type="submit" name="ajouter" value="<?php echo $poster_msg; ?>" /> <a href="?refresh=1"><input type="button" value="<?php echo $actualiser_msg; ?>" /></a></NOBR>
322                </form>
323        </td>
324          </tr>
325    </table>
326<?php
327}
328
329?>
330  </div>
331<?php
332
333$footer_style = 'index';
334require PUN_ROOT.'footer.php';
Note: See TracBrowser for help on using the repository browser.