punbb/index.php
changeset 7 98bbc533541c
equal deleted inserted replaced
6:5e1f1e916419 7:98bbc533541c
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  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 
       
    26 // if (!defined('PUN_ROOT'))
       
    27 // 	define('PUN_ROOT', './');
       
    28 // require PUN_ROOT.'include/common.php';
       
    29 
       
    30 // import globals (I really hope this isn't dangerous)
       
    31 foreach ( $GLOBALS as $key => $_ )
       
    32 {
       
    33   $$key =& $GLOBALS[$key];
       
    34 }
       
    35 
       
    36 ($hook = get_hook('in_start')) ? eval($hook) : null;
       
    37 
       
    38 if ($pun_user['g_read_board'] == '0')
       
    39 	message($lang_common['No view']);
       
    40 
       
    41 // Load the index.php language file
       
    42 require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
       
    43 
       
    44 // Get list of forums and topics with new posts since last visit
       
    45 if (!$pun_user['is_guest'])
       
    46 {
       
    47 	$query = array(
       
    48 		'SELECT'	=> 't.forum_id, t.id, t.last_post',
       
    49 		'FROM'		=> 'topics AS t',
       
    50 		'JOINS'		=> array(
       
    51 			array(
       
    52 				'INNER JOIN'	=> 'forums AS f',
       
    53 				'ON'			=> 'f.id=t.forum_id'
       
    54 			),
       
    55 			array(
       
    56 				'LEFT JOIN'		=> 'forum_perms AS fp',
       
    57 				'ON'			=> '(fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].')'
       
    58 			)
       
    59 		),
       
    60 		'WHERE'		=> '(fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.$pun_user['last_visit'].' AND t.moved_to IS NULL'
       
    61 	);
       
    62 
       
    63 	($hook = get_hook('in_qr_get_new_topics')) ? eval($hook) : null;
       
    64 	$result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__);
       
    65 
       
    66 	$new_topics = array();
       
    67 	while ($cur_topic = $pun_db->fetch_assoc($result))
       
    68 		$new_topics[$cur_topic['forum_id']][$cur_topic['id']] = $cur_topic['last_post'];
       
    69 
       
    70 	$tracked_topics = get_tracked_topics();
       
    71 }
       
    72 
       
    73 ($hook = get_hook('in_pre_header_load')) ? eval($hook) : null;
       
    74 
       
    75 define('PUN_ALLOW_INDEX', 1);
       
    76 define('PUN_PAGE', 'index');
       
    77 
       
    78 require PUN_ROOT.'header.php';
       
    79 
       
    80 // Print the categories and forums
       
    81 $query = array(
       
    82 	'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',
       
    83 	'FROM'		=> 'categories AS c',
       
    84 	'JOINS'		=> array(
       
    85 		array(
       
    86 			'INNER JOIN'	=> 'forums AS f',
       
    87 			'ON'			=> 'c.id=f.cat_id'
       
    88 		),
       
    89 		array(
       
    90 			'LEFT JOIN'		=> 'forum_perms AS fp',
       
    91 			'ON'			=> '(fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].')'
       
    92 		)
       
    93 	),
       
    94 	'WHERE'		=> 'fp.read_forum IS NULL OR fp.read_forum=1',
       
    95 	'ORDER BY'	=> 'c.disp_position, c.id, f.disp_position'
       
    96 );
       
    97 
       
    98 ($hook = get_hook('in_qr_get_cats_and_forums')) ? eval($hook) : null;
       
    99 $result = $pun_db->query_build($query, true) or error(__FILE__, __LINE__);
       
   100 
       
   101 ?>
       
   102 <div id="pun-main" class="main">
       
   103 
       
   104 	<h1><span><?php echo htmlspecialchars($pun_config['o_board_title']) ?></span></h1>
       
   105 <?php
       
   106 
       
   107 $pun_page['cur_category'] = $pun_page['cat_count'] = $pun_page['item_count'] = 0;
       
   108 
       
   109 while ($cur_forum = $pun_db->fetch_assoc($result))
       
   110 {
       
   111 	($hook = get_hook('in_forum_loop_start')) ? eval($hook) : null;
       
   112 
       
   113 	$pun_page['item_mods'] = '';
       
   114 	++$pun_page['item_count'];
       
   115 
       
   116 	if ($cur_forum['cid'] != $pun_page['cur_category'])	// A new category since last iteration?
       
   117 	{
       
   118 		if ($pun_page['cur_category'] != 0)
       
   119 		{
       
   120 
       
   121 ?>
       
   122 			</tbody>
       
   123 		</table>
       
   124 	</div>
       
   125 <?php
       
   126 
       
   127 		}
       
   128 
       
   129 		++$pun_page['cat_count'];
       
   130 		$pun_page['item_count'] = 1;
       
   131 
       
   132 ?>
       
   133 	<div class="main-head">
       
   134 		<h2><span><?php echo htmlspecialchars($cur_forum['cat_name']) ?></span></h2>
       
   135 	</div>
       
   136 
       
   137 	<div id="category<?php echo $pun_page['cat_count'] ?>" class="main-content category">
       
   138 		<table cellspacing="0" summary="<?php printf($lang_index['Table summary'], htmlspecialchars($cur_forum['cat_name'])) ?>">
       
   139 			<thead>
       
   140 				<tr>
       
   141 					<th class="tcl" scope="col"><?php echo $lang_common['Forum'] ?></th>
       
   142 					<th class="tc2" scope="col"><?php echo $lang_common['Topics'] ?></th>
       
   143 					<th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
       
   144 <?php ($hook = get_hook('in_table_header_after_num_posts')) ? eval($hook) : null; ?>
       
   145 					<th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
       
   146 <?php ($hook = get_hook('in_table_header_after_last_post')) ? eval($hook) : null; ?>
       
   147 				</tr>
       
   148 			</thead>
       
   149 			<tbody class="statused">
       
   150 <?php
       
   151 
       
   152 		$pun_page['cur_category'] = $cur_forum['cid'];
       
   153 	}
       
   154 
       
   155 	$pun_page['item_status'] = $pun_page['item_subject'] = $pun_page['item_last_post'] = array();
       
   156 	$pun_page['item_alt_message'] = $lang_common['Forum'];
       
   157 	$pun_page['item_indicator'] = '';
       
   158 
       
   159 	// Is this a redirect forum?
       
   160 	if ($cur_forum['redirect_url'] != '')
       
   161 	{
       
   162 		$pun_page['item_title'] = '<h3><a class="external" href="'.htmlspecialchars($cur_forum['redirect_url']).'" title="'.sprintf($lang_index['Link to'], htmlspecialchars($cur_forum['redirect_url'])).'"><span>'.htmlspecialchars($cur_forum['forum_name']).'</span></a></h3>';
       
   163 		$cur_forum['num_topics'] = $cur_forum['num_posts'] = ' - ';
       
   164 		$pun_page['item_status'][] = 'redirect';
       
   165 		$pun_page['item_alt_message'] = $lang_index['External forum'];
       
   166 		$pun_page['item_last_post'][] = $lang_common['Unknown'];
       
   167 
       
   168 		if ($cur_forum['forum_desc'] != '')
       
   169 			$pun_page['item_subject'][] = $cur_forum['forum_desc'];
       
   170 	}
       
   171 	else
       
   172 	{
       
   173 		$pun_page['item_title'] = '<h3><a href="'.pun_link($pun_url['forum'], array($cur_forum['fid'], sef_friendly($cur_forum['forum_name']))).'"><span>'.htmlspecialchars($cur_forum['forum_name']).'</span></a></h3>';
       
   174 
       
   175 		// Are there new posts since our last visit?
       
   176 		if (!$pun_user['is_guest'] && $cur_forum['last_post'] > $pun_user['last_visit'] && (empty($tracked_topics['forums'][$cur_forum['fid']]) || $cur_forum['last_post'] > $tracked_topics['forums'][$cur_forum['fid']]))
       
   177 		{
       
   178 			// There are new posts in this forum, but have we read all of them already?
       
   179 			while (list($check_topic_id, $check_last_post) = @each($new_topics[$cur_forum['fid']]))
       
   180 			{
       
   181 				if (empty($tracked_topics['topics'][$check_topic_id]) || $tracked_topics['topics'][$check_topic_id] < $check_last_post)
       
   182 				{
       
   183 					$pun_page['item_status'][] = 'new';
       
   184 					$pun_page['item_alt_message'] = $lang_index['Forum has new'];
       
   185 					break;
       
   186 				}
       
   187 			}
       
   188 		}
       
   189 
       
   190 		if ($cur_forum['forum_desc'] != '')
       
   191 			$pun_page['item_subject'][] = $cur_forum['forum_desc'];
       
   192 
       
   193 		if ($cur_forum['moderators'] != '')
       
   194 		{
       
   195 			$pun_page['mods_array'] = unserialize($cur_forum['moderators']);
       
   196 			$pun_page['item_mods'] = array();
       
   197 
       
   198 			while (list($mod_username, $mod_id) = @each($pun_page['mods_array']))
       
   199 				$pun_page['item_mods'][] = '<a href="'.pun_link($pun_url['user'], $mod_id).'">'.htmlspecialchars($mod_username).'</a>';
       
   200 
       
   201 			$pun_page['item_subject'][] = '<span class="modlist">('.sprintf($lang_index['Moderated by'], implode(', ', $pun_page['item_mods'])).')</span>';
       
   202 		}
       
   203 
       
   204 		// If there is a last_post/last_poster.
       
   205 		if ($cur_forum['last_post'] != '')
       
   206 		{
       
   207 			$pun_page['item_last_post'][] = '<a href="'.pun_link($pun_url['post'], $cur_forum['last_post_id']).'"><span>'.format_time($cur_forum['last_post']).'</span></a>';
       
   208 			$pun_page['item_last_post'][] =	'<span class="byuser">'.sprintf($lang_common['By user'], htmlspecialchars($cur_forum['last_poster'])).'</span>';
       
   209 		}
       
   210 		else
       
   211 			$pun_page['item_last_post'][] = $lang_common['Never'];
       
   212 
       
   213 		if (empty($pun_page['item_status']))
       
   214 			$pun_page['item_status'][] = 'normal';
       
   215 	}
       
   216 
       
   217 	$pun_page['item_style'] = (($pun_page['item_count'] % 2 != 0) ? 'odd' : 'even').' '.implode(' ', $pun_page['item_status']);
       
   218 	$pun_page['item_indicator'] = '<span class="status '.implode(' ', $pun_page['item_status']).'" title="'.$pun_page['item_alt_message'].'"><img src="'.$base_url.'/style/'.$pun_user['style'].'/status.png" alt="'.$pun_page['item_alt_message'].'" /></span>';
       
   219 
       
   220 	($hook = get_hook('in_row_pre_display')) ? eval($hook) : null;
       
   221 
       
   222 ?>
       
   223 				<tr id="forum<?php echo $cur_forum['fid'] ?>" class="<?php echo $pun_page['item_style'] ?>">
       
   224 					<td class="tcl"><?php echo $pun_page['item_indicator'].' '.$pun_page['item_title'].implode('<br />', $pun_page['item_subject']) ?></td>
       
   225 					<td class="tc2"><?php echo $cur_forum['num_topics'] ?></td>
       
   226 					<td class="tc3"><?php echo $cur_forum['num_posts'] ?></td>
       
   227 <?php ($hook = get_hook('in_table_contents_after_num_posts')) ? eval($hook) : null; ?>
       
   228 					<td class="tcr"><?php if (!empty($pun_page['item_last_post'])) echo implode(' ', $pun_page['item_last_post']) ?></td>
       
   229 <?php ($hook = get_hook('in_table_contents_after_last_post')) ? eval($hook) : null; ?>
       
   230 				</tr>
       
   231 <?php
       
   232 
       
   233 }
       
   234 
       
   235 // Did we output any categories and forums?
       
   236 if ($pun_page['cur_category'] > 0)
       
   237 {
       
   238 
       
   239 ?>
       
   240 			</tbody>
       
   241 		</table>
       
   242 	</div>
       
   243 
       
   244 </div>
       
   245 <?php
       
   246 
       
   247 }
       
   248 else
       
   249 {
       
   250 
       
   251 ?>
       
   252 <div id="pun-main" class="main">
       
   253 
       
   254 	<h1><span><?php echo htmlspecialchars($pun_config['o_board_title']) ?></span></h1>
       
   255 
       
   256 	<div class="main-head">
       
   257 		<h2><span><?php echo $lang_common['Forum message'] ?></span></h2>
       
   258 	</div>
       
   259 	<div class="main-content message">
       
   260 		<p><?php echo $lang_index['Empty board'] ?></p>
       
   261 	</div>
       
   262 
       
   263 </div>
       
   264 <?php
       
   265 
       
   266 }
       
   267 
       
   268 ($hook = get_hook('in_end')) ? eval($hook) : null;
       
   269 
       
   270 require PUN_ROOT.'footer.php';