| 1 |
2 |
thefinn |
<?php
|
| 2 |
8146 |
acydburn |
/**
|
| 3 |
5114 |
acydburn |
*
|
| 4 |
5114 |
acydburn |
* @package phpBB3
|
| 5 |
5114 |
acydburn |
* @version $Id$
|
| 6 |
8146 |
acydburn |
* @copyright (c) 2005 phpBB Group
|
| 7 |
8146 |
acydburn |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
| 8 |
5114 |
acydburn |
*
|
| 9 |
5114 |
acydburn |
*/
|
| 10 |
2 |
thefinn |
|
| 11 |
5114 |
acydburn |
/**
|
| 12 |
5883 |
acydburn |
* @ignore
|
| 13 |
5114 |
acydburn |
*/
|
| 14 |
2305 |
psotfx |
define('IN_PHPBB', true);
|
| 15 |
8572 |
acydburn |
if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './');
|
| 16 |
8572 |
acydburn |
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
|
| 17 |
8572 |
acydburn |
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
|
| 18 |
8572 |
acydburn |
include(PHPBB_ROOT_PATH . 'includes/functions_display.' . PHP_EXT);
|
| 19 |
8572 |
acydburn |
include(PHPBB_ROOT_PATH . 'includes/bbcode.' . PHP_EXT);
|
| 20 |
2 |
thefinn |
|
| 21 |
3953 |
psotfx |
// Start session management
|
| 22 |
5247 |
acydburn |
$user->session_begin();
|
| 23 |
3953 |
psotfx |
$auth->acl($user->data);
|
| 24 |
3953 |
psotfx |
|
| 25 |
3538 |
psotfx |
// Initial var setup
|
| 26 |
4578 |
psotfx |
$forum_id = request_var('f', 0);
|
| 27 |
4578 |
psotfx |
$topic_id = request_var('t', 0);
|
| 28 |
4578 |
psotfx |
$post_id = request_var('p', 0);
|
| 29 |
5412 |
davidmj |
$voted_id = request_var('vote_id', array('' => 0));
|
| 30 |
1215 |
dougk_ff7 |
|
| 31 |
4578 |
psotfx |
$start = request_var('start', 0);
|
| 32 |
4578 |
psotfx |
$view = request_var('view', '');
|
| 33 |
5068 |
acydburn |
|
| 34 |
8753 |
Kellanved |
$default_sort_days = (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0;
|
| 35 |
8753 |
Kellanved |
$default_sort_key = (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't';
|
| 36 |
8753 |
Kellanved |
$default_sort_dir = (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a';
|
| 37 |
5068 |
acydburn |
|
| 38 |
8753 |
Kellanved |
$sort_days = request_var('st', $default_sort_days);
|
| 39 |
8753 |
Kellanved |
$sort_key = request_var('sk', $default_sort_key);
|
| 40 |
8753 |
Kellanved |
$sort_dir = request_var('sd', $default_sort_dir);
|
| 41 |
8753 |
Kellanved |
|
| 42 |
4578 |
psotfx |
$update = request_var('update', false);
|
| 43 |
4441 |
psotfx |
|
| 44 |
7920 |
acydburn |
/**
|
| 45 |
7920 |
acydburn |
* @todo normalize?
|
| 46 |
7920 |
acydburn |
*/
|
| 47 |
6002 |
acydburn |
$hilit_words = request_var('hilit', '', true);
|
| 48 |
3538 |
psotfx |
|
| 49 |
3538 |
psotfx |
// Do we have a topic or post id?
|
| 50 |
4004 |
psotfx |
if (!$topic_id && !$post_id)
|
| 51 |
81 |
thefinn |
{
|
| 52 |
3538 |
psotfx |
trigger_error('NO_TOPIC');
|
| 53 |
81 |
thefinn |
}
|
| 54 |
2 |
thefinn |
|
| 55 |
2995 |
psotfx |
// Find topic id if user requested a newer or older topic
|
| 56 |
4441 |
psotfx |
if ($view && !$post_id)
|
| 57 |
301 |
thefinn |
{
|
| 58 |
5137 |
acydburn |
if (!$forum_id)
|
| 59 |
5137 |
acydburn |
{
|
| 60 |
6002 |
acydburn |
$sql = 'SELECT forum_id
|
| 61 |
6002 |
acydburn |
FROM ' . TOPICS_TABLE . "
|
| 62 |
5137 |
acydburn |
WHERE topic_id = $topic_id";
|
| 63 |
5137 |
acydburn |
$result = $db->sql_query($sql);
|
| 64 |
5824 |
acydburn |
$forum_id = (int) $db->sql_fetchfield('forum_id');
|
| 65 |
5824 |
acydburn |
$db->sql_freeresult($result);
|
| 66 |
5824 |
acydburn |
|
| 67 |
5824 |
acydburn |
if (!$forum_id)
|
| 68 |
5137 |
acydburn |
{
|
| 69 |
5137 |
acydburn |
trigger_error('NO_TOPIC');
|
| 70 |
5137 |
acydburn |
}
|
| 71 |
5137 |
acydburn |
}
|
| 72 |
5137 |
acydburn |
|
| 73 |
4441 |
psotfx |
if ($view == 'unread')
|
| 74 |
301 |
thefinn |
{
|
| 75 |
5272 |
acydburn |
// Get topic tracking info
|
| 76 |
5272 |
acydburn |
$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
|
| 77 |
3953 |
psotfx |
|
| 78 |
5272 |
acydburn |
$topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0;
|
| 79 |
5272 |
acydburn |
|
| 80 |
6513 |
acydburn |
$sql = 'SELECT post_id, topic_id, forum_id
|
| 81 |
6513 |
acydburn |
FROM ' . POSTS_TABLE . "
|
| 82 |
6513 |
acydburn |
WHERE topic_id = $topic_id
|
| 83 |
6513 |
acydburn |
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1') . "
|
| 84 |
6513 |
acydburn |
AND post_time > $topic_last_read
|
| 85 |
6513 |
acydburn |
ORDER BY post_time ASC";
|
| 86 |
5137 |
acydburn |
$result = $db->sql_query_limit($sql, 1);
|
| 87 |
5824 |
acydburn |
$row = $db->sql_fetchrow($result);
|
| 88 |
5824 |
acydburn |
$db->sql_freeresult($result);
|
| 89 |
3953 |
psotfx |
|
| 90 |
5824 |
acydburn |
if (!$row)
|
| 91 |
5137 |
acydburn |
{
|
| 92 |
6513 |
acydburn |
$sql = 'SELECT topic_last_post_id as post_id, topic_id, forum_id
|
| 93 |
6513 |
acydburn |
FROM ' . TOPICS_TABLE . '
|
| 94 |
6513 |
acydburn |
WHERE topic_id = ' . $topic_id;
|
| 95 |
6513 |
acydburn |
$result = $db->sql_query($sql);
|
| 96 |
6513 |
acydburn |
$row = $db->sql_fetchrow($result);
|
| 97 |
6513 |
acydburn |
$db->sql_freeresult($result);
|
| 98 |
6513 |
acydburn |
}
|
| 99 |
6513 |
acydburn |
|
| 100 |
6513 |
acydburn |
if (!$row)
|
| 101 |
6513 |
acydburn |
{
|
| 102 |
5137 |
acydburn |
// Setup user environment so we can process lang string
|
| 103 |
5137 |
acydburn |
$user->setup('viewtopic');
|
| 104 |
1093 |
psotfx |
|
| 105 |
6513 |
acydburn |
trigger_error('NO_TOPIC');
|
| 106 |
5137 |
acydburn |
}
|
| 107 |
3953 |
psotfx |
|
| 108 |
5272 |
acydburn |
$post_id = $row['post_id'];
|
| 109 |
5137 |
acydburn |
$topic_id = $row['topic_id'];
|
| 110 |
1093 |
psotfx |
}
|
| 111 |
4441 |
psotfx |
else if ($view == 'next' || $view == 'previous')
|
| 112 |
1093 |
psotfx |
{
|
| 113 |
4441 |
psotfx |
$sql_condition = ($view == 'next') ? '>' : '<';
|
| 114 |
4441 |
psotfx |
$sql_ordering = ($view == 'next') ? 'ASC' : 'DESC';
|
| 115 |
302 |
thefinn |
|
| 116 |
8023 |
davidmj |
$sql = 'SELECT forum_id, topic_last_post_time
|
| 117 |
8023 |
davidmj |
FROM ' . TOPICS_TABLE . '
|
| 118 |
8023 |
davidmj |
WHERE topic_id = ' . $topic_id;
|
| 119 |
8023 |
davidmj |
$result = $db->sql_query($sql);
|
| 120 |
8023 |
davidmj |
$row = $db->sql_fetchrow($result);
|
| 121 |
8023 |
davidmj |
$db->sql_freeresult($result);
|
| 122 |
8023 |
davidmj |
|
| 123 |
5824 |
acydburn |
if (!$row)
|
| 124 |
566 |
psotfx |
{
|
| 125 |
5858 |
acydburn |
$user->setup('viewtopic');
|
| 126 |
8228 |
kellanved |
// OK, the topic doesn't exist. This error message is not helpful, but technically correct.
|
| 127 |
6002 |
acydburn |
trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
|
| 128 |
566 |
psotfx |
}
|
| 129 |
566 |
psotfx |
else
|
| 130 |
566 |
psotfx |
{
|
| 131 |
8228 |
kellanved |
$sql = 'SELECT topic_id, forum_id
|
| 132 |
8228 |
kellanved |
FROM ' . TOPICS_TABLE . '
|
| 133 |
8228 |
kellanved |
WHERE forum_id = ' . $row['forum_id'] . "
|
| 134 |
8228 |
kellanved |
AND topic_moved_id = 0
|
| 135 |
8228 |
kellanved |
AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
|
| 136 |
8228 |
kellanved |
" . (($auth->acl_get('m_approve', $row['forum_id'])) ? '' : 'AND topic_approved = 1') . "
|
| 137 |
8228 |
kellanved |
ORDER BY topic_last_post_time $sql_ordering";
|
| 138 |
8228 |
kellanved |
$result = $db->sql_query_limit($sql, 1);
|
| 139 |
8228 |
kellanved |
$row = $db->sql_fetchrow($result);
|
| 140 |
8228 |
kellanved |
$db->sql_freeresult($result);
|
| 141 |
6151 |
naderman |
|
| 142 |
8228 |
kellanved |
if (!$row)
|
| 143 |
5137 |
acydburn |
{
|
| 144 |
8228 |
kellanved |
$user->setup('viewtopic');
|
| 145 |
8228 |
kellanved |
trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS');
|
| 146 |
5137 |
acydburn |
}
|
| 147 |
8228 |
kellanved |
else
|
| 148 |
5137 |
acydburn |
{
|
| 149 |
8228 |
kellanved |
$topic_id = $row['topic_id'];
|
| 150 |
8228 |
kellanved |
|
| 151 |
8228 |
kellanved |
// Check for global announcement correctness?
|
| 152 |
8228 |
kellanved |
if (!$row['forum_id'] && !$forum_id)
|
| 153 |
8228 |
kellanved |
{
|
| 154 |
8228 |
kellanved |
trigger_error('NO_TOPIC');
|
| 155 |
8228 |
kellanved |
}
|
| 156 |
8228 |
kellanved |
else if ($row['forum_id'])
|
| 157 |
8228 |
kellanved |
{
|
| 158 |
8228 |
kellanved |
$forum_id = $row['forum_id'];
|
| 159 |
8228 |
kellanved |
}
|
| 160 |
5137 |
acydburn |
}
|
| 161 |
566 |
psotfx |
}
|
| 162 |
566 |
psotfx |
}
|
| 163 |
5137 |
acydburn |
|
| 164 |
5137 |
acydburn |
// Check for global announcement correctness?
|
| 165 |
5390 |
subblue |
if ((!isset($row) || !$row['forum_id']) && !$forum_id)
|
| 166 |
5137 |
acydburn |
{
|
| 167 |
5137 |
acydburn |
trigger_error('NO_TOPIC');
|
| 168 |
5137 |
acydburn |
}
|
| 169 |
5390 |
subblue |
else if (isset($row) && $row['forum_id'])
|
| 170 |
5137 |
acydburn |
{
|
| 171 |
5137 |
acydburn |
$forum_id = $row['forum_id'];
|
| 172 |
5137 |
acydburn |
}
|
| 173 |
301 |
thefinn |
}
|
| 174 |
566 |
psotfx |
|
| 175 |
566 |
psotfx |
// This rather complex gaggle of code handles querying for topics but
|
| 176 |
566 |
psotfx |
// also allows for direct linking to a post (and the calculation of which
|
| 177 |
566 |
psotfx |
// page the post is on and the correct display of viewtopic)
|
| 178 |
5885 |
davidmj |
$sql_array = array(
|
| 179 |
5957 |
acydburn |
'SELECT' => 't.*, f.*',
|
| 180 |
5471 |
acydburn |
|
| 181 |
8852 |
acydburn |
'FROM' => array(FORUMS_TABLE => 'f'),
|
| 182 |
5885 |
davidmj |
);
|
| 183 |
5885 |
davidmj |
|
| 184 |
8972 |
acydburn |
// The FROM-Order is quite important here, else t.* columns can not be correctly bound.
|
| 185 |
8852 |
acydburn |
if ($post_id)
|
| 186 |
8852 |
acydburn |
{
|
| 187 |
8852 |
acydburn |
$sql_array['FROM'][POSTS_TABLE] = 'p';
|
| 188 |
8852 |
acydburn |
}
|
| 189 |
8852 |
acydburn |
|
| 190 |
8852 |
acydburn |
// Topics table need to be the last in the chain
|
| 191 |
8852 |
acydburn |
$sql_array['FROM'][TOPICS_TABLE] = 't';
|
| 192 |
8852 |
acydburn |
|
| 193 |
5117 |
acydburn |
if ($user->data['is_registered'])
|
| 194 |
3007 |
ludovic_arnaud |
{
|
| 195 |
5885 |
davidmj |
$sql_array['SELECT'] .= ', tw.notify_status';
|
| 196 |
6002 |
acydburn |
$sql_array['LEFT_JOIN'] = array();
|
| 197 |
6002 |
acydburn |
|
| 198 |
6002 |
acydburn |
$sql_array['LEFT_JOIN'][] = array(
|
| 199 |
5885 |
davidmj |
'FROM' => array(TOPICS_WATCH_TABLE => 'tw'),
|
| 200 |
5885 |
davidmj |
'ON' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id'
|
| 201 |
5885 |
davidmj |
);
|
| 202 |
5272 |
acydburn |
|
| 203 |
5272 |
acydburn |
if ($config['allow_bookmarks'])
|
| 204 |
5272 |
acydburn |
{
|
| 205 |
7497 |
acydburn |
$sql_array['SELECT'] .= ', bm.topic_id as bookmarked';
|
| 206 |
6002 |
acydburn |
$sql_array['LEFT_JOIN'][] = array(
|
| 207 |
5885 |
davidmj |
'FROM' => array(BOOKMARKS_TABLE => 'bm'),
|
| 208 |
5885 |
davidmj |
'ON' => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id'
|
| 209 |
5885 |
davidmj |
);
|
| 210 |
5272 |
acydburn |
}
|
| 211 |
5272 |
acydburn |
|
| 212 |
5272 |
acydburn |
if ($config['load_db_lastread'])
|
| 213 |
5272 |
acydburn |
{
|
| 214 |
5885 |
davidmj |
$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
|
| 215 |
6151 |
naderman |
|
| 216 |
6002 |
acydburn |
$sql_array['LEFT_JOIN'][] = array(
|
| 217 |
5885 |
davidmj |
'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
|
| 218 |
5885 |
davidmj |
'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
|
| 219 |
5885 |
davidmj |
);
|
| 220 |
6002 |
acydburn |
|
| 221 |
6002 |
acydburn |
$sql_array['LEFT_JOIN'][] = array(
|
| 222 |
5885 |
davidmj |
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
|
| 223 |
5885 |
davidmj |
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
|
| 224 |
5885 |
davidmj |
);
|
| 225 |
5272 |
acydburn |
}
|
| 226 |
3007 |
ludovic_arnaud |
}
|
| 227 |
3007 |
ludovic_arnaud |
|
| 228 |
5885 |
davidmj |
if (!$post_id)
|
| 229 |
5885 |
davidmj |
{
|
| 230 |
5885 |
davidmj |
$sql_array['WHERE'] = "t.topic_id = $topic_id";
|
| 231 |
5885 |
davidmj |
}
|
| 232 |
5885 |
davidmj |
else
|
| 233 |
5885 |
davidmj |
{
|
| 234 |
5885 |
davidmj |
$sql_array['WHERE'] = "p.post_id = $post_id AND t.topic_id = p.topic_id" . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '');
|
| 235 |
5885 |
davidmj |
}
|
| 236 |
5854 |
davidmj |
|
| 237 |
6135 |
acydburn |
$sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';
|
| 238 |
6135 |
acydburn |
|
| 239 |
6135 |
acydburn |
if (!$forum_id)
|
| 240 |
6135 |
acydburn |
{
|
| 241 |
6135 |
acydburn |
// If it is a global announcement make sure to set the forum id to a postable forum
|
| 242 |
6151 |
naderman |
$sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . '
|
| 243 |
6135 |
acydburn |
AND f.forum_type = ' . FORUM_POST . ')';
|
| 244 |
6135 |
acydburn |
}
|
| 245 |
6135 |
acydburn |
else
|
| 246 |
6135 |
acydburn |
{
|
| 247 |
6135 |
acydburn |
$sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . "
|
| 248 |
6135 |
acydburn |
AND f.forum_id = $forum_id)";
|
| 249 |
6135 |
acydburn |
}
|
| 250 |
6135 |
acydburn |
|
| 251 |
6135 |
acydburn |
$sql_array['WHERE'] .= ')';
|
| 252 |
5885 |
davidmj |
|
| 253 |
3567 |
psotfx |
// Join to forum table on topic forum_id unless topic forum_id is zero
|
| 254 |
3567 |
psotfx |
// whereupon we join on the forum_id passed as a parameter ... this
|
| 255 |
3567 |
psotfx |
// is done so navigation, forum name, etc. remain consistent with where
|
| 256 |
3567 |
psotfx |
// user clicked to view a global topic
|
| 257 |
5885 |
davidmj |
$sql = $db->sql_build_query('SELECT', $sql_array);
|
| 258 |
2673 |
psotfx |
$result = $db->sql_query($sql);
|
| 259 |
6002 |
acydburn |
$topic_data = $db->sql_fetchrow($result);
|
| 260 |
6002 |
acydburn |
$db->sql_freeresult($result);
|
| 261 |
355 |
psotfx |
|
| 262 |
6002 |
acydburn |
if (!$topic_data)
|
| 263 |
81 |
thefinn |
{
|
| 264 |
4679 |
acydburn |
// If post_id was submitted, we try at least to display the topic as a last resort...
|
| 265 |
4679 |
acydburn |
if ($post_id && $forum_id && $topic_id)
|
| 266 |
4679 |
acydburn |
{
|
| 267 |
8572 |
acydburn |
redirect(append_sid('viewtopic', "f=$forum_id&t=$topic_id"));
|
| 268 |
4679 |
acydburn |
}
|
| 269 |
5858 |
acydburn |
|
| 270 |
3538 |
psotfx |
trigger_error('NO_TOPIC');
|
| 271 |
81 |
thefinn |
}
|
| 272 |
566 |
psotfx |
|
| 273 |
5906 |
davidmj |
// This is for determining where we are (page)
|
| 274 |
5906 |
davidmj |
if ($post_id)
|
| 275 |
5906 |
davidmj |
{
|
| 276 |
6411 |
acydburn |
if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
|
| 277 |
6411 |
acydburn |
{
|
| 278 |
6411 |
acydburn |
$check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
|
| 279 |
6002 |
acydburn |
|
| 280 |
6411 |
acydburn |
if ($sort_dir == $check_sort)
|
| 281 |
6411 |
acydburn |
{
|
| 282 |
7447 |
acydburn |
$topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
|
| 283 |
6411 |
acydburn |
}
|
| 284 |
6411 |
acydburn |
else
|
| 285 |
6411 |
acydburn |
{
|
| 286 |
7447 |
acydburn |
$topic_data['prev_posts'] = 0;
|
| 287 |
6411 |
acydburn |
}
|
| 288 |
6411 |
acydburn |
}
|
| 289 |
6411 |
acydburn |
else
|
| 290 |
6411 |
acydburn |
{
|
| 291 |
6411 |
acydburn |
$sql = 'SELECT COUNT(p1.post_id) AS prev_posts
|
| 292 |
6411 |
acydburn |
FROM ' . POSTS_TABLE . ' p1, ' . POSTS_TABLE . " p2
|
| 293 |
6411 |
acydburn |
WHERE p1.topic_id = {$topic_data['topic_id']}
|
| 294 |
6411 |
acydburn |
AND p2.post_id = {$post_id}
|
| 295 |
6411 |
acydburn |
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p1.post_approved = 1' : '') . '
|
| 296 |
6411 |
acydburn |
AND ' . (($sort_dir == 'd') ? 'p1.post_time >= p2.post_time' : 'p1.post_time <= p2.post_time');
|
| 297 |
6411 |
acydburn |
|
| 298 |
6411 |
acydburn |
$result = $db->sql_query($sql);
|
| 299 |
6411 |
acydburn |
$row = $db->sql_fetchrow($result);
|
| 300 |
6411 |
acydburn |
$db->sql_freeresult($result);
|
| 301 |
6411 |
acydburn |
|
| 302 |
7447 |
acydburn |
$topic_data['prev_posts'] = $row['prev_posts'] - 1;
|
| 303 |
6411 |
acydburn |
}
|
| 304 |
5906 |
davidmj |
}
|
| 305 |
5906 |
davidmj |
|
| 306 |
5272 |
acydburn |
$forum_id = (int) $topic_data['forum_id'];
|
| 307 |
5272 |
acydburn |
$topic_id = (int) $topic_data['topic_id'];
|
| 308 |
3566 |
psotfx |
|
| 309 |
5027 |
acydburn |
//
|
| 310 |
5272 |
acydburn |
$topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] : $topic_data['topic_replies'];
|
| 311 |
4925 |
acydburn |
|
| 312 |
4577 |
acydburn |
// Check sticky/announcement time limit
|
| 313 |
5272 |
acydburn |
if (($topic_data['topic_type'] == POST_STICKY || $topic_data['topic_type'] == POST_ANNOUNCE) && $topic_data['topic_time_limit'] && ($topic_data['topic_time'] + $topic_data['topic_time_limit']) < time())
|
| 314 |
4577 |
acydburn |
{
|
| 315 |
4947 |
psotfx |
$sql = 'UPDATE ' . TOPICS_TABLE . '
|
| 316 |
4577 |
acydburn |
SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0
|
| 317 |
4577 |
acydburn |
WHERE topic_id = ' . $topic_id;
|
| 318 |
4577 |
acydburn |
$db->sql_query($sql);
|
| 319 |
5027 |
acydburn |
|
| 320 |
5272 |
acydburn |
$topic_data['topic_type'] = POST_NORMAL;
|
| 321 |
5272 |
acydburn |
$topic_data['topic_time_limit'] = 0;
|
| 322 |
4577 |
acydburn |
}
|
| 323 |
4577 |
acydburn |
|
| 324 |
3953 |
psotfx |
// Setup look and feel
|
| 325 |
5272 |
acydburn |
$user->setup('viewtopic', $topic_data['forum_style']);
|
| 326 |
3869 |
psotfx |
|
| 327 |
5272 |
acydburn |
if (!$topic_data['topic_approved'] && !$auth->acl_get('m_approve', $forum_id))
|
| 328 |
3969 |
psotfx |
{
|
| 329 |
4204 |
psotfx |
trigger_error('NO_TOPIC');
|
| 330 |
3969 |
psotfx |
}
|
| 331 |
3969 |
psotfx |
|
| 332 |
377 |
psotfx |
// Start auth check
|
| 333 |
3712 |
psotfx |
if (!$auth->acl_get('f_read', $forum_id))
|
| 334 |
377 |
psotfx |
{
|
| 335 |
3650 |
psotfx |
if ($user->data['user_id'] != ANONYMOUS)
|
| 336 |
2079 |
psotfx |
{
|
| 337 |
6002 |
acydburn |
trigger_error('SORRY_AUTH_READ');
|
| 338 |
2079 |
psotfx |
}
|
| 339 |
421 |
thefinn |
|
| 340 |
4970 |
psotfx |
login_box('', $user->lang['LOGIN_VIEWFORUM']);
|
| 341 |
377 |
psotfx |
}
|
| 342 |
377 |
psotfx |
|
| 343 |
4204 |
psotfx |
// Forum is passworded ... check whether access has been granted to this
|
| 344 |
4204 |
psotfx |
// user this session, if not show login box
|
| 345 |
5272 |
acydburn |
if ($topic_data['forum_password'])
|
| 346 |
4167 |
psotfx |
{
|
| 347 |
4204 |
psotfx |
login_forum_box($topic_data);
|
| 348 |
4167 |
psotfx |
}
|
| 349 |
4167 |
psotfx |
|
| 350 |
4912 |
acydburn |
// Redirect to login or to the correct post upon emailed notification links
|
| 351 |
4912 |
acydburn |
if (isset($_GET['e']))
|
| 352 |
4577 |
acydburn |
{
|
| 353 |
5078 |
psotfx |
$jump_to = request_var('e', 0);
|
| 354 |
5078 |
psotfx |
|
| 355 |
8572 |
acydburn |
$redirect_url = append_sid('viewtopic', "f=$forum_id&t=$topic_id");
|
| 356 |
4915 |
acydburn |
|
| 357 |
4912 |
acydburn |
if ($user->data['user_id'] == ANONYMOUS)
|
| 358 |
4912 |
acydburn |
{
|
| 359 |
6002 |
acydburn |
login_box($redirect_url . "&p=$post_id&e=$jump_to", $user->lang['LOGIN_NOTIFY_TOPIC']);
|
| 360 |
4912 |
acydburn |
}
|
| 361 |
5078 |
psotfx |
|
| 362 |
5078 |
psotfx |
if ($jump_to > 0)
|
| 363 |
4912 |
acydburn |
{
|
| 364 |
4912 |
acydburn |
// We direct the already logged in user to the correct post...
|
| 365 |
6015 |
acydburn |
redirect($redirect_url . ((!$post_id) ? "&p=$jump_to" : "&p=$post_id") . "#p$jump_to");
|
| 366 |
4912 |
acydburn |
}
|
| 367 |
4577 |
acydburn |
}
|
| 368 |
4577 |
acydburn |
|
| 369 |
3538 |
psotfx |
// What is start equal to?
|
| 370 |
5272 |
acydburn |
if ($post_id)
|
| 371 |
2079 |
psotfx |
{
|
| 372 |
7447 |
acydburn |
$start = floor(($topic_data['prev_posts']) / $config['posts_per_page']) * $config['posts_per_page'];
|
| 373 |
2079 |
psotfx |
}
|
| 374 |
2079 |
psotfx |
|
| 375 |
5272 |
acydburn |
// Get topic tracking info
|
| 376 |
5272 |
acydburn |
if (!isset($topic_tracking_info))
|
| 377 |
5272 |
acydburn |
{
|
| 378 |
6256 |
acydburn |
$topic_tracking_info = array();
|
| 379 |
6256 |
acydburn |
|
| 380 |
5272 |
acydburn |
// Get topic tracking info
|
| 381 |
5272 |
acydburn |
if ($config['load_db_lastread'] && $user->data['is_registered'])
|
| 382 |
5272 |
acydburn |
{
|
| 383 |
5272 |
acydburn |
$tmp_topic_data = array($topic_id => $topic_data);
|
| 384 |
5272 |
acydburn |
$topic_tracking_info = get_topic_tracking($forum_id, $topic_id, $tmp_topic_data, array($forum_id => $topic_data['forum_mark_time']));
|
| 385 |
5272 |
acydburn |
unset($tmp_topic_data);
|
| 386 |
5272 |
acydburn |
}
|
| 387 |
6256 |
acydburn |
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
|
| 388 |
5272 |
acydburn |
{
|
| 389 |
5272 |
acydburn |
$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
|
| 390 |
5272 |
acydburn |
}
|
| 391 |
5272 |
acydburn |
}
|
| 392 |
5272 |
acydburn |
|
| 393 |
2673 |
psotfx |
// Post ordering options
|
| 394 |
5705 |
naderman |
$limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
|
| 395 |
3538 |
psotfx |
|
| 396 |
3286 |
psotfx |
$sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
|
| 397 |
6650 |
acydburn |
$sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
|
| 398 |
862 |
psotfx |
|
| 399 |
3961 |
psotfx |
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
| 400 |
3538 |
psotfx |
|
| 401 |
8753 |
Kellanved |
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
|
| 402 |
8753 |
Kellanved |
|
| 403 |
3566 |
psotfx |
// Obtain correct post count and ordering SQL if user has
|
| 404 |
3566 |
psotfx |
// requested anything different
|
| 405 |
3561 |
ludovic_arnaud |
if ($sort_days)
|
| 406 |
2673 |
psotfx |
{
|
| 407 |
3561 |
ludovic_arnaud |
$min_post_time = time() - ($sort_days * 86400);
|
| 408 |
2110 |
psotfx |
|
| 409 |
3561 |
ludovic_arnaud |
$sql = 'SELECT COUNT(post_id) AS num_posts
|
| 410 |
3561 |
ludovic_arnaud |
FROM ' . POSTS_TABLE . "
|
| 411 |
3561 |
ludovic_arnaud |
WHERE topic_id = $topic_id
|
| 412 |
3561 |
ludovic_arnaud |
AND post_time >= $min_post_time
|
| 413 |
5025 |
acydburn |
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1');
|
| 414 |
3561 |
ludovic_arnaud |
$result = $db->sql_query($sql);
|
| 415 |
6002 |
acydburn |
$total_posts = (int) $db->sql_fetchfield('num_posts');
|
| 416 |
6002 |
acydburn |
$db->sql_freeresult($result);
|
| 417 |
862 |
psotfx |
|
| 418 |
6002 |
acydburn |
$limit_posts_time = "AND p.post_time >= $min_post_time ";
|
| 419 |
6002 |
acydburn |
|
| 420 |
4031 |
psotfx |
if (isset($_POST['sort']))
|
| 421 |
4031 |
psotfx |
{
|
| 422 |
4031 |
psotfx |
$start = 0;
|
| 423 |
4031 |
psotfx |
}
|
| 424 |
862 |
psotfx |
}
|
| 425 |
3567 |
psotfx |
else
|
| 426 |
3567 |
psotfx |
{
|
| 427 |
3567 |
psotfx |
$total_posts = $topic_replies + 1;
|
| 428 |
3567 |
psotfx |
$limit_posts_time = '';
|
| 429 |
3567 |
psotfx |
}
|
| 430 |
3561 |
ludovic_arnaud |
|
| 431 |
4912 |
acydburn |
// Was a highlight request part of the URI?
|
| 432 |
4912 |
acydburn |
$highlight_match = $highlight = '';
|
| 433 |
4912 |
acydburn |
if ($hilit_words)
|
| 434 |
4522 |
psotfx |
{
|
| 435 |
4912 |
acydburn |
foreach (explode(' ', trim($hilit_words)) as $word)
|
| 436 |
4912 |
acydburn |
{
|
| 437 |
4912 |
acydburn |
if (trim($word))
|
| 438 |
4912 |
acydburn |
{
|
| 439 |
|