root / tags / milestone_3 / phpBB / viewtopic.php
History | View | Annotate | Download (51.8 kB)
| 1 | 2 | thefinn | <?php
|
|---|---|---|---|
| 2 | 5114 | acydburn | /**
|
| 3 | 5114 | acydburn | * |
| 4 | 5114 | acydburn | * @package phpBB3 |
| 5 | 5114 | acydburn | * @version $Id$ |
| 6 | 5114 | acydburn | * @copyright (c) 2005 phpBB Group |
| 7 | 5114 | 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 | 5114 | acydburn | */ |
| 13 | 2305 | psotfx | define('IN_PHPBB', true); |
| 14 | 2411 | psotfx | $phpbb_root_path = './'; |
| 15 | 4441 | psotfx | $phpEx = substr(strrchr(__FILE__, '.'), 1); |
| 16 | 646 | psotfx | include($phpbb_root_path . 'common.'.$phpEx); |
| 17 | 5247 | acydburn | include($phpbb_root_path . 'includes/functions_display.' . $phpEx); |
| 18 | 2 | thefinn | |
| 19 | 3953 | psotfx | // Start session management
|
| 20 | 5247 | acydburn | $user->session_begin();
|
| 21 | 3953 | psotfx | $auth->acl($user->data); |
| 22 | 3953 | psotfx | |
| 23 | 3538 | psotfx | // Initial var setup
|
| 24 | 4578 | psotfx | $forum_id = request_var('f', 0); |
| 25 | 4578 | psotfx | $topic_id = request_var('t', 0); |
| 26 | 4578 | psotfx | $post_id = request_var('p', 0); |
| 27 | 4578 | psotfx | $voted_id = request_var('vote_id', 0);; |
| 28 | 1215 | dougk_ff7 | |
| 29 | 4578 | psotfx | $start = request_var('start', 0); |
| 30 | 4578 | psotfx | $view = request_var('view', ''); |
| 31 | 4578 | psotfx | $rate = request_var('rate', 0); |
| 32 | 5068 | acydburn | |
| 33 | 5068 | acydburn | $sort_days = request_var('st', ((!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0)); |
| 34 | 5068 | acydburn | $sort_key = request_var('sk', ((!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't')); |
| 35 | 5068 | acydburn | $sort_dir = request_var('sd', ((!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a')); |
| 36 | 5068 | acydburn | |
| 37 | 4578 | psotfx | $update = request_var('update', false); |
| 38 | 4441 | psotfx | |
| 39 | 5034 | acydburn | $hilit_words = request_var('hilit', ''); |
| 40 | 3538 | psotfx | |
| 41 | 3538 | psotfx | // Do we have a topic or post id?
|
| 42 | 4004 | psotfx | if (!$topic_id && !$post_id) |
| 43 | 81 | thefinn | {
|
| 44 | 3538 | psotfx | trigger_error('NO_TOPIC'); |
| 45 | 81 | thefinn | } |
| 46 | 2 | thefinn | |
| 47 | 2995 | psotfx | // Find topic id if user requested a newer or older topic
|
| 48 | 5137 | acydburn | $unread_post_id = 0; |
| 49 | 4441 | psotfx | if ($view && !$post_id) |
| 50 | 301 | thefinn | {
|
| 51 | 5137 | acydburn | if (!$forum_id) |
| 52 | 5137 | acydburn | {
|
| 53 | 5137 | acydburn | $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . " |
| 54 | 5137 | acydburn | WHERE topic_id = $topic_id"; |
| 55 | 5137 | acydburn | $db->sql_query_limit($sql, 1); |
| 56 | 5137 | acydburn | $result = $db->sql_query($sql); |
| 57 | 5137 | acydburn | if ($row = $db->sql_fetchrow($result)) |
| 58 | 5137 | acydburn | {
|
| 59 | 5137 | acydburn | $forum_id = $row['forum_id']; |
| 60 | 5137 | acydburn | } |
| 61 | 5137 | acydburn | else
|
| 62 | 5137 | acydburn | {
|
| 63 | 5137 | acydburn | trigger_error('NO_TOPIC'); |
| 64 | 5137 | acydburn | } |
| 65 | 5137 | acydburn | $db->sql_freeresult($result); |
| 66 | 5137 | acydburn | } |
| 67 | 5137 | acydburn | |
| 68 | 4441 | psotfx | if ($view == 'unread') |
| 69 | 301 | thefinn | {
|
| 70 | 5117 | acydburn | if ($user->data['is_registered']) |
| 71 | 1093 | psotfx | {
|
| 72 | 5137 | acydburn | $topic_last_read = get_topic_last_read($topic_id, $forum_id); |
| 73 | 5137 | acydburn | } |
| 74 | 5137 | acydburn | else
|
| 75 | 5137 | acydburn | {
|
| 76 | 5137 | acydburn | $topic_last_read = 0; |
| 77 | 5137 | acydburn | } |
| 78 | 3953 | psotfx | |
| 79 | 5137 | acydburn | $sql = 'SELECT p.post_id, p.topic_id, p.forum_id |
| 80 | 5137 | acydburn | FROM (' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t) |
| 81 | 5137 | acydburn | WHERE t.topic_id = $topic_id |
| 82 | 5137 | acydburn | AND p.topic_id = t.topic_id |
| 83 | 5137 | acydburn | " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND p.post_approved = 1') . " |
| 84 | 5137 | acydburn | AND (p.post_time > $topic_last_read |
| 85 | 5137 | acydburn | OR p.post_id = t.topic_last_post_id) |
| 86 | 5137 | acydburn | ORDER BY p.post_time ASC";
|
| 87 | 5137 | acydburn | $result = $db->sql_query_limit($sql, 1); |
| 88 | 3953 | psotfx | |
| 89 | 5137 | acydburn | if (!($row = $db->sql_fetchrow($result))) |
| 90 | 5137 | acydburn | {
|
| 91 | 5137 | acydburn | // Setup user environment so we can process lang string
|
| 92 | 5137 | acydburn | $user->setup('viewtopic'); |
| 93 | 1093 | psotfx | |
| 94 | 5137 | acydburn | meta_refresh(3, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); |
| 95 | 5137 | acydburn | $message = $user->lang['NO_UNREAD_POSTS'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id\">", '</a>'); |
| 96 | 5137 | acydburn | trigger_error($message); |
| 97 | 5137 | acydburn | } |
| 98 | 5137 | acydburn | $db->sql_freeresult($result); |
| 99 | 3953 | psotfx | |
| 100 | 5137 | acydburn | $unread_post_id = $post_id = $row['post_id']; |
| 101 | 5137 | acydburn | $topic_id = $row['topic_id']; |
| 102 | 1093 | psotfx | } |
| 103 | 4441 | psotfx | else if ($view == 'next' || $view == 'previous') |
| 104 | 1093 | psotfx | {
|
| 105 | 4441 | psotfx | $sql_condition = ($view == 'next') ? '>' : '<'; |
| 106 | 4441 | psotfx | $sql_ordering = ($view == 'next') ? 'ASC' : 'DESC'; |
| 107 | 302 | thefinn | |
| 108 | 5137 | acydburn | $sql = 'SELECT t.topic_id, t.forum_id |
| 109 | 4051 | psotfx | FROM ' . TOPICS_TABLE . ' t, ' . TOPICS_TABLE . " t2 |
| 110 | 2376 | psotfx | WHERE t2.topic_id = $topic_id |
| 111 | 2376 | psotfx | AND t.forum_id = t2.forum_id |
| 112 | 4947 | psotfx | " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . " |
| 113 | 2866 | psotfx | AND t.topic_last_post_time $sql_condition t2.topic_last_post_time |
| 114 | 3357 | psotfx | ORDER BY t.topic_last_post_time $sql_ordering"; |
| 115 | 3357 | psotfx | $result = $db->sql_query_limit($sql, 1); |
| 116 | 792 | thefinn | |
| 117 | 2996 | psotfx | if (!($row = $db->sql_fetchrow($result))) |
| 118 | 566 | psotfx | {
|
| 119 | 4441 | psotfx | $message = ($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS'; |
| 120 | 2997 | psotfx | trigger_error($message); |
| 121 | 566 | psotfx | } |
| 122 | 566 | psotfx | else
|
| 123 | 566 | psotfx | {
|
| 124 | 2376 | psotfx | $topic_id = $row['topic_id']; |
| 125 | 5137 | acydburn | |
| 126 | 5137 | acydburn | // Check for global announcement correctness?
|
| 127 | 5137 | acydburn | if (!$row['forum_id'] && !$forum_id) |
| 128 | 5137 | acydburn | {
|
| 129 | 5137 | acydburn | trigger_error('NO_TOPIC'); |
| 130 | 5137 | acydburn | } |
| 131 | 5137 | acydburn | else if ($row['forum_id']) |
| 132 | 5137 | acydburn | {
|
| 133 | 5137 | acydburn | $forum_id = $row['forum_id']; |
| 134 | 5137 | acydburn | } |
| 135 | 566 | psotfx | } |
| 136 | 566 | psotfx | } |
| 137 | 5137 | acydburn | |
| 138 | 5137 | acydburn | // Check for global announcement correctness?
|
| 139 | 5137 | acydburn | if ((!$row || !$row['forum_id']) && !$forum_id) |
| 140 | 5137 | acydburn | {
|
| 141 | 5137 | acydburn | trigger_error('NO_TOPIC'); |
| 142 | 5137 | acydburn | } |
| 143 | 5137 | acydburn | else if ($row['forum_id']) |
| 144 | 5137 | acydburn | {
|
| 145 | 5137 | acydburn | $forum_id = $row['forum_id']; |
| 146 | 5137 | acydburn | } |
| 147 | 301 | thefinn | } |
| 148 | 566 | psotfx | |
| 149 | 566 | psotfx | // This rather complex gaggle of code handles querying for topics but
|
| 150 | 566 | psotfx | // also allows for direct linking to a post (and the calculation of which
|
| 151 | 566 | psotfx | // page the post is on and the correct display of viewtopic)
|
| 152 | 2997 | psotfx | $join_sql_table = (!$post_id) ? '' : ', ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . ' p2 '; |
| 153 | 3640 | ludovic_arnaud | if (!$post_id) |
| 154 | 3640 | ludovic_arnaud | {
|
| 155 | 3640 | ludovic_arnaud | $join_sql = "t.topic_id = $topic_id"; |
| 156 | 3640 | ludovic_arnaud | } |
| 157 | 3640 | ludovic_arnaud | else
|
| 158 | 3640 | ludovic_arnaud | {
|
| 159 | 3712 | psotfx | if ($auth->acl_get('m_approve', $forum_id)) |
| 160 | 3640 | ludovic_arnaud | {
|
| 161 | 3640 | ludovic_arnaud | $join_sql = (!$post_id) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id"; |
| 162 | 3640 | ludovic_arnaud | } |
| 163 | 3640 | ludovic_arnaud | else
|
| 164 | 3640 | ludovic_arnaud | {
|
| 165 | 3640 | ludovic_arnaud | $join_sql = (!$post_id) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND p.post_approved = 1 AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_approved = 1 AND p2.post_id <= $post_id"; |
| 166 | 3640 | ludovic_arnaud | } |
| 167 | 3640 | ludovic_arnaud | } |
| 168 | 4192 | ludovic_arnaud | $extra_fields = (!$post_id) ? '' : ', COUNT(p2.post_id) AS prev_posts'; |
| 169 | 4192 | ludovic_arnaud | $order_sql = (!$post_id) ? '' : 'GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style, f.forum_password ORDER BY p.post_id ASC'; |
| 170 | 87 | psotfx | |
| 171 | 5117 | acydburn | if ($user->data['is_registered']) |
| 172 | 3007 | ludovic_arnaud | {
|
| 173 | 5140 | acydburn | $extra_fields .= ', tw.notify_status' . (($config['allow_bookmarks']) ? ', bm.order_id as bookmarked' : ''); |
| 174 | 5140 | acydburn | $join_sql_table .= ' LEFT JOIN ' . TOPICS_WATCH_TABLE . ' tw ON (tw.user_id = ' . $user->data['user_id'] . ' |
| 175 | 5140 | acydburn | AND t.topic_id = tw.topic_id)';
|
| 176 | 5140 | acydburn | $join_sql_table .= ($config['allow_bookmarks']) ? ' LEFT JOIN ' . BOOKMARKS_TABLE . ' bm ON (bm.user_id = ' . $user->data['user_id'] . ' |
| 177 | 5140 | acydburn | AND t.topic_id = bm.topic_id)' : ''; |
| 178 | 3007 | ludovic_arnaud | } |
| 179 | 3007 | ludovic_arnaud | |
| 180 | 3567 | psotfx | // Join to forum table on topic forum_id unless topic forum_id is zero
|
| 181 | 3567 | psotfx | // whereupon we join on the forum_id passed as a parameter ... this
|
| 182 | 3567 | psotfx | // is done so navigation, forum name, etc. remain consistent with where
|
| 183 | 3567 | psotfx | // user clicked to view a global topic
|
| 184 | 4981 | acydburn | $sql = 'SELECT t.topic_id, t.forum_id, t.topic_title, t.topic_attachment, t.topic_status, t.topic_approved, t.topic_replies_real, t.topic_replies, t.topic_first_post_id, t.topic_last_post_id, t.topic_last_poster_id, t.topic_last_post_time, t.topic_poster, t.topic_time, t.topic_time_limit, t.topic_type, t.topic_bumped, t.topic_bumper, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, t.poll_vote_change, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_type, f.forum_id, f.forum_style, f.forum_password, f.forum_rules, f.forum_rules_link, f.forum_rules_flags, f.forum_rules_bbcode_uid, f.forum_rules_bbcode_bitfield' . $extra_fields . ' |
| 185 | 3969 | psotfx | FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f' . $join_sql_table . " |
| 186 | 1222 | dougk_ff7 | WHERE $join_sql |
| 187 | 3567 | psotfx | AND (f.forum_id = t.forum_id |
| 188 | 4192 | ludovic_arnaud | " . ((!$forum_id) ? '' : 'OR (t.topic_type = ' . POST_GLOBAL . " AND f.forum_id = $forum_id)") . " |
| 189 | 4192 | ludovic_arnaud | ) |
| 190 | 4192 | ludovic_arnaud | $order_sql"; |
| 191 | 2673 | psotfx | $result = $db->sql_query($sql); |
| 192 | 355 | psotfx | |
| 193 | 4204 | psotfx | if (!($topic_data = $db->sql_fetchrow($result))) |
| 194 | 81 | thefinn | {
|
| 195 | 4679 | acydburn | // If post_id was submitted, we try at least to display the topic as a last resort...
|
| 196 | 4679 | acydburn | if ($post_id && $forum_id && $topic_id) |
| 197 | 4679 | acydburn | {
|
| 198 | 4679 | acydburn | redirect("viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id");
|
| 199 | 4679 | acydburn | } |
| 200 | 3538 | psotfx | trigger_error('NO_TOPIC'); |
| 201 | 81 | thefinn | } |
| 202 | 566 | psotfx | |
| 203 | 4192 | ludovic_arnaud | // Extract the data
|
| 204 | 4192 | ludovic_arnaud | extract($topic_data); |
| 205 | 3566 | psotfx | |
| 206 | 5027 | acydburn | //
|
| 207 | 4936 | acydburn | $topic_replies = ($auth->acl_get('m_approve', $forum_id)) ? $topic_replies_real : $topic_replies; |
| 208 | 4925 | acydburn | unset($topic_replies_real); |
| 209 | 4925 | acydburn | |
| 210 | 5137 | acydburn | if ($user->data['is_registered'] && !isset($topic_last_read)) |
| 211 | 4892 | acydburn | {
|
| 212 | 5137 | acydburn | $topic_last_read = get_topic_last_read($topic_id, $forum_id); |
| 213 | 4892 | acydburn | } |
| 214 | 4892 | acydburn | else
|
| 215 | 4892 | acydburn | {
|
| 216 | 4892 | acydburn | $topic_last_read = 0; |
| 217 | 4892 | acydburn | } |
| 218 | 4892 | acydburn | |
| 219 | 4577 | acydburn | // Check sticky/announcement time limit
|
| 220 | 5027 | acydburn | if (($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) && $topic_time_limit && ($topic_time + $topic_time_limit) < time()) |
| 221 | 4577 | acydburn | {
|
| 222 | 4947 | psotfx | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 223 | 4577 | acydburn | SET topic_type = ' . POST_NORMAL . ', topic_time_limit = 0 |
| 224 | 4577 | acydburn | WHERE topic_id = ' . $topic_id; |
| 225 | 4577 | acydburn | $db->sql_query($sql); |
| 226 | 5027 | acydburn | |
| 227 | 4577 | acydburn | $topic_type = POST_NORMAL; |
| 228 | 4577 | acydburn | $topic_time_limit = 0; |
| 229 | 4577 | acydburn | } |
| 230 | 4577 | acydburn | |
| 231 | 3953 | psotfx | // Setup look and feel
|
| 232 | 4844 | acydburn | $user->setup('viewtopic', $forum_style); |
| 233 | 3869 | psotfx | |
| 234 | 4204 | psotfx | if (!$topic_approved && !$auth->acl_get('m_approve', $forum_id)) |
| 235 | 3969 | psotfx | {
|
| 236 | 4204 | psotfx | trigger_error('NO_TOPIC'); |
| 237 | 3969 | psotfx | } |
| 238 | 3969 | psotfx | |
| 239 | 377 | psotfx | // Start auth check
|
| 240 | 3712 | psotfx | if (!$auth->acl_get('f_read', $forum_id)) |
| 241 | 377 | psotfx | {
|
| 242 | 3650 | psotfx | if ($user->data['user_id'] != ANONYMOUS) |
| 243 | 2079 | psotfx | {
|
| 244 | 3650 | psotfx | trigger_error($user->lang['SORRY_AUTH_READ']); |
| 245 | 2079 | psotfx | } |
| 246 | 421 | thefinn | |
| 247 | 4970 | psotfx | login_box('', $user->lang['LOGIN_VIEWFORUM']); |
| 248 | 377 | psotfx | } |
| 249 | 377 | psotfx | |
| 250 | 4204 | psotfx | // Forum is passworded ... check whether access has been granted to this
|
| 251 | 4204 | psotfx | // user this session, if not show login box
|
| 252 | 4204 | psotfx | if ($forum_password) |
| 253 | 4167 | psotfx | {
|
| 254 | 4204 | psotfx | login_forum_box($topic_data);
|
| 255 | 4167 | psotfx | } |
| 256 | 4167 | psotfx | |
| 257 | 4912 | acydburn | // Redirect to login or to the correct post upon emailed notification links
|
| 258 | 4912 | acydburn | if (isset($_GET['e'])) |
| 259 | 4577 | acydburn | {
|
| 260 | 5078 | psotfx | $jump_to = request_var('e', 0); |
| 261 | 5078 | psotfx | |
| 262 | 4969 | acydburn | $redirect_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; |
| 263 | 4915 | acydburn | |
| 264 | 4912 | acydburn | if ($user->data['user_id'] == ANONYMOUS) |
| 265 | 4912 | acydburn | {
|
| 266 | 4972 | psotfx | login_box($redirect_url . "&p=$post_id&e=$jump_to", $user->lang['LOGIN_NOTIFY_TOPIC']); |
| 267 | 4912 | acydburn | } |
| 268 | 5078 | psotfx | |
| 269 | 5078 | psotfx | if ($jump_to > 0) |
| 270 | 4912 | acydburn | {
|
| 271 | 4912 | acydburn | // We direct the already logged in user to the correct post...
|
| 272 | 4969 | acydburn | redirect($redirect_url . ((!$post_id) ? "&p=$jump_to" : "&p=$post_id") . "#$jump_to"); |
| 273 | 4912 | acydburn | } |
| 274 | 4577 | acydburn | } |
| 275 | 4577 | acydburn | |
| 276 | 3538 | psotfx | // What is start equal to?
|
| 277 | 2995 | psotfx | if (!empty($post_id)) |
| 278 | 2079 | psotfx | {
|
| 279 | 2983 | psotfx | $start = floor(($prev_posts - 1) / $config['posts_per_page']) * $config['posts_per_page']; |
| 280 | 2079 | psotfx | } |
| 281 | 2079 | psotfx | |
| 282 | 2673 | psotfx | // Post ordering options
|
| 283 | 3538 | psotfx | $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'], 364 => $user->lang['1_YEAR']); |
| 284 | 3538 | psotfx | |
| 285 | 3286 | psotfx | $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); |
| 286 | 3561 | ludovic_arnaud | $sort_by_sql = array('a' => 'u.username', 't' => 'p.post_id', 's' => 'p.post_subject'); |
| 287 | 862 | psotfx | |
| 288 | 3961 | psotfx | $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; |
| 289 | 3961 | psotfx | 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); |
| 290 | 3538 | psotfx | |
| 291 | 3566 | psotfx | // Obtain correct post count and ordering SQL if user has
|
| 292 | 3566 | psotfx | // requested anything different
|
| 293 | 3561 | ludovic_arnaud | if ($sort_days) |
| 294 | 2673 | psotfx | {
|
| 295 | 3561 | ludovic_arnaud | $min_post_time = time() - ($sort_days * 86400); |
| 296 | 2110 | psotfx | |
| 297 | 3561 | ludovic_arnaud | $sql = 'SELECT COUNT(post_id) AS num_posts |
| 298 | 3561 | ludovic_arnaud | FROM ' . POSTS_TABLE . " |
| 299 | 3561 | ludovic_arnaud | WHERE topic_id = $topic_id |
| 300 | 3561 | ludovic_arnaud | AND post_time >= $min_post_time |
| 301 | 5025 | acydburn | " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND post_approved = 1'); |
| 302 | 3561 | ludovic_arnaud | $result = $db->sql_query($sql); |
| 303 | 862 | psotfx | |
| 304 | 4031 | psotfx | if (isset($_POST['sort'])) |
| 305 | 4031 | psotfx | {
|
| 306 | 4031 | psotfx | $start = 0; |
| 307 | 4031 | psotfx | } |
| 308 | 3561 | ludovic_arnaud | $total_posts = ($row = $db->sql_fetchrow($result)) ? $row['num_posts'] : 0; |
| 309 | 3561 | ludovic_arnaud | $limit_posts_time = "AND p.post_time >= $min_post_time "; |
| 310 | 862 | psotfx | } |
| 311 | 3567 | psotfx | else
|
| 312 | 3567 | psotfx | {
|
| 313 | 3567 | psotfx | $total_posts = $topic_replies + 1; |
| 314 | 3567 | psotfx | $limit_posts_time = ''; |
| 315 | 3567 | psotfx | } |
| 316 | 3561 | ludovic_arnaud | |
| 317 | 4912 | acydburn | // Was a highlight request part of the URI?
|
| 318 | 4912 | acydburn | $highlight_match = $highlight = ''; |
| 319 | 4912 | acydburn | if ($hilit_words) |
| 320 | 4522 | psotfx | {
|
| 321 | 4912 | acydburn | foreach (explode(' ', trim($hilit_words)) as $word) |
| 322 | 4912 | acydburn | {
|
| 323 | 4912 | acydburn | if (trim($word)) |
| 324 | 4912 | acydburn | {
|
| 325 | 5034 | acydburn | $highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('\*', '\w*?', preg_quote(urlencode($word), '#')); |
| 326 | 4912 | acydburn | } |
| 327 | 4912 | acydburn | } |
| 328 | 4912 | acydburn | |
| 329 | 5034 | acydburn | $highlight = urlencode($hilit_words); |
| 330 | 4522 | psotfx | } |
| 331 | 862 | psotfx | |
| 332 | 4912 | acydburn | // General Viewtopic URL for return links
|
| 333 | 4912 | acydburn | $viewtopic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start&$u_sort_param" . (($highlight_match) ? "&hilit=$highlight" : ''); |
| 334 | 4912 | acydburn | |
| 335 | 4522 | psotfx | // Are we watching this topic?
|
| 336 | 4892 | acydburn | $s_watching_topic = $s_watching_topic_img = array(); |
| 337 | 4892 | acydburn | $s_watching_topic['link'] = $s_watching_topic['title'] = ''; |
| 338 | 5117 | acydburn | if ($config['email_enable'] && $config['allow_topic_notify'] && $user->data['is_registered']) |
| 339 | 4522 | psotfx | {
|
| 340 | 4912 | acydburn | watch_topic_forum('topic', $s_watching_topic, $s_watching_topic_img, $user->data['user_id'], $topic_id, $notify_status, $start); |
| 341 | 4522 | psotfx | } |
| 342 | 4522 | psotfx | |
| 343 | 4912 | acydburn | // Bookmarks
|
| 344 | 5117 | acydburn | if ($config['allow_bookmarks'] && $user->data['is_registered'] && request_var('bookmark', 0)) |
| 345 | 4912 | acydburn | {
|
| 346 | 4912 | acydburn | if (!$bookmarked) |
| 347 | 4912 | acydburn | {
|
| 348 | 4912 | acydburn | $sql = 'INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
| 349 | 4912 | acydburn | 'user_id' => $user->data['user_id'], |
| 350 | 4912 | acydburn | 'topic_id' => $topic_id, |
| 351 | 4912 | acydburn | 'order_id' => 0) |
| 352 | 4912 | acydburn | ); |
| 353 | 4912 | acydburn | $db->sql_query($sql); |
| 354 | 4912 | acydburn | |
| 355 | 4912 | acydburn | $where_sql = ''; |
| 356 | 4912 | acydburn | $sign = '+'; |
| 357 | 4912 | acydburn | } |
| 358 | 4912 | acydburn | else
|
| 359 | 4912 | acydburn | {
|
| 360 | 4947 | psotfx | $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . " |
| 361 | 4912 | acydburn | WHERE user_id = {$user->data['user_id']} |
| 362 | 4912 | acydburn | AND topic_id = $topic_id"; |
| 363 | 4912 | acydburn | $db->sql_query($sql); |
| 364 | 4947 | psotfx | |
| 365 | 4912 | acydburn | // Works because of current order_id selected as bookmark value (please do not change because of simplicity)
|
| 366 | 4912 | acydburn | $where_sql = " AND order_id > $bookmarked"; |
| 367 | 4912 | acydburn | $sign = '-'; |
| 368 | 4912 | acydburn | } |
| 369 | 4912 | acydburn | |
| 370 | 4912 | acydburn | // Re-Sort Bookmarks
|
| 371 | 4912 | acydburn | $sql = 'UPDATE ' . BOOKMARKS_TABLE . " |
| 372 | 4912 | acydburn | SET order_id = order_id $sign 1 |
| 373 | 4912 | acydburn | WHERE user_id = {$user->data['user_id']} |
| 374 | 4912 | acydburn | $where_sql"; |
| 375 | 4912 | acydburn | $db->sql_query($sql); |
| 376 | 4912 | acydburn | |
| 377 | 4912 | acydburn | meta_refresh(3, $viewtopic_url); |
| 378 | 5078 | psotfx | |
| 379 | 4912 | acydburn | $message = (($bookmarked) ? $user->lang['BOOKMARK_REMOVED'] : $user->lang['BOOKMARK_ADDED']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>'); |
| 380 | 4912 | acydburn | trigger_error($message); |
| 381 | 4912 | acydburn | } |
| 382 | 4912 | acydburn | |
| 383 | 4150 | psotfx | // Grab ranks
|
| 384 | 4150 | psotfx | $ranks = array(); |
| 385 | 5247 | acydburn | $cache->obtain_ranks($ranks); |
| 386 | 81 | thefinn | |
| 387 | 3357 | psotfx | // Grab icons
|
| 388 | 3357 | psotfx | $icons = array(); |
| 389 | 5247 | acydburn | $cache->obtain_icons($icons); |
| 390 | 2673 | psotfx | |
| 391 | 4912 | acydburn | // Grab extensions
|
| 392 | 4912 | acydburn | $extensions = array(); |
| 393 | 4912 | acydburn | if ($topic_attachment) |
| 394 | 1830 | psotfx | {
|
| 395 | 5247 | acydburn | $cache->obtain_attach_extensions($extensions); |
| 396 | 1830 | psotfx | } |
| 397 | 1830 | psotfx | |
| 398 | 3538 | psotfx | // Forum rules listing
|
| 399 | 2673 | psotfx | $s_forum_rules = ''; |
| 400 | 4903 | acydburn | gen_forum_auth_level('topic', $forum_id); |
| 401 | 1452 | bartvb | |
| 402 | 3538 | psotfx | // Quick mod tools
|
| 403 | 2708 | psotfx | $topic_mod = ''; |
| 404 | 5117 | acydburn | $topic_mod .= ($auth->acl_get('m_lock', $forum_id) || ($auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $topic_poster)) ? (($topic_status == ITEM_UNLOCKED) ? '<option value="lock">' . $user->lang['LOCK_TOPIC'] . '</option>' : '<option value="unlock">' . $user->lang['UNLOCK_TOPIC'] . '</option>') : ''; |
| 405 | 3876 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '<option value="delete_topic">' . $user->lang['DELETE_TOPIC'] . '</option>' : ''; |
| 406 | 3712 | psotfx | $topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '<option value="move">' . $user->lang['MOVE_TOPIC'] . '</option>' : ''; |
| 407 | 3712 | psotfx | $topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '<option value="split">' . $user->lang['SPLIT_TOPIC'] . '</option>' : ''; |
| 408 | 3712 | psotfx | $topic_mod .= ($auth->acl_get('m_merge', $forum_id)) ? '<option value="merge">' . $user->lang['MERGE_TOPIC'] . '</option>' : ''; |
| 409 | 3797 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="fork">' . $user->lang['FORK_TOPIC'] . '</option>' : ''; |
| 410 | 3764 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('m_', $forum_id) && $topic_type != POST_NORMAL) ? '<option value="make_normal">' . $user->lang['MAKE_NORMAL'] . '</option>' : ''; |
| 411 | 3764 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('f_sticky', $forum_id) && $topic_type != POST_STICKY) ? '<option value="make_sticky">' . $user->lang['MAKE_STICKY'] . '</option>' : ''; |
| 412 | 4192 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_type != POST_ANNOUNCE) ? '<option value="make_announce">' . $user->lang['MAKE_ANNOUNCE'] . '</option>' : ''; |
| 413 | 4192 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('f_announce', $forum_id) && $topic_type != POST_GLOBAL) ? '<option value="make_global">' . $user->lang['MAKE_GLOBAL'] . '</option>' : ''; |
| 414 | 3782 | ludovic_arnaud | $topic_mod .= ($auth->acl_get('m_', $forum_id)) ? '<option value="viewlogs">' . $user->lang['VIEW_TOPIC_LOGS'] . '</option>' : ''; |
| 415 | 1452 | bartvb | |
| 416 | 2673 | psotfx | // If we've got a hightlight set pass it on to pagination.
|
| 417 | 4918 | acydburn | $pagination = generate_pagination("{$phpbb_root_path}viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&$u_sort_param" . (($highlight_match) ? "&hilit=$highlight" : ''), $total_posts, $config['posts_per_page'], $start); |
| 418 | 2673 | psotfx | |
| 419 | 3359 | ludovic_arnaud | // Navigation links
|
| 420 | 3359 | ludovic_arnaud | generate_forum_nav($topic_data);
|
| 421 | 3347 | psotfx | |
| 422 | 4903 | acydburn | // Forum Rules
|
| 423 | 4903 | acydburn | generate_forum_rules($topic_data);
|
| 424 | 4903 | acydburn | |
| 425 | 3063 | psotfx | // Moderators
|
| 426 | 3063 | psotfx | $forum_moderators = array(); |
| 427 | 3063 | psotfx | get_moderators($forum_moderators, $forum_id); |
| 428 | 3063 | psotfx | |
| 429 | 3347 | psotfx | // This is only used for print view so ...
|
| 430 | 4675 | ludovic_arnaud | $server_path = (!$view) ? '' : generate_board_url() . '/'; |
| 431 | 3071 | psotfx | |
| 432 | 3953 | psotfx | // Replace naughty words in title
|
| 433 | 4836 | acydburn | $topic_title = censor_text($topic_title); |
| 434 | 3953 | psotfx | |
| 435 | 1851 | psotfx | // Send vars to template
|
| 436 | 355 | psotfx | $template->assign_vars(array( |
| 437 | 2972 | psotfx | 'FORUM_ID' => $forum_id, |
| 438 | 4870 | acydburn | 'FORUM_NAME' => $forum_name, |
| 439 | 4455 | psotfx | 'FORUM_DESC' => $forum_desc, |
| 440 | 4870 | acydburn | 'TOPIC_ID' => $topic_id, |
| 441 | 4870 | acydburn | 'TOPIC_TITLE' => $topic_title, |
| 442 | 4167 | psotfx | 'PAGINATION' => $pagination, |
| 443 | 4167 | psotfx | 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start), |
| 444 | 4947 | psotfx | 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts), |
| 445 | 4675 | ludovic_arnaud | 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? "mcp.$phpEx?sid=" . $user->session_id . "&mode=topic_view&f=$forum_id&t=$topic_id&start=$start&$u_sort_param" : '', |
| 446 | 4892 | acydburn | 'MODERATORS' => (isset($forum_moderators[$forum_id]) && sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '', |
| 447 | 770 | psotfx | |
| 448 | 4749 | psotfx | 'POST_IMG' => ($forum_status == ITEM_LOCKED) ? $user->img('btn_locked', 'FORUM_LOCKED') : $user->img('btn_post', 'POST_NEW_TOPIC'), |
| 449 | 4892 | acydburn | 'QUOTE_IMG' => $user->img('btn_quote', 'REPLY_WITH_QUOTE'), |
| 450 | 4749 | psotfx | 'REPLY_IMG' => ($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) ? $user->img('btn_locked', 'TOPIC_LOCKED') : $user->img('btn_reply', 'REPLY_TO_TOPIC'), |
| 451 | 4749 | psotfx | 'EDIT_IMG' => $user->img('btn_edit', 'EDIT_POST'), |
| 452 | 4749 | psotfx | 'DELETE_IMG' => $user->img('btn_delete', 'DELETE_POST'), |
| 453 | 4947 | psotfx | 'INFO_IMG' => $user->img('btn_info', 'VIEW_INFO'), |
| 454 | 4947 | psotfx | 'PROFILE_IMG' => $user->img('btn_profile', 'READ_PROFILE'), |
| 455 | 4749 | psotfx | 'SEARCH_IMG' => $user->img('btn_search', 'SEARCH_USER_POSTS'), |
| 456 | 4749 | psotfx | 'PM_IMG' => $user->img('btn_pm', 'SEND_PRIVATE_MESSAGE'), |
| 457 | 4749 | psotfx | 'EMAIL_IMG' => $user->img('btn_email', 'SEND_EMAIL'), |
| 458 | 4749 | psotfx | 'WWW_IMG' => $user->img('btn_www', 'VISIT_WEBSITE'), |
| 459 | 4749 | psotfx | 'ICQ_IMG' => $user->img('btn_icq', 'ICQ'), |
| 460 | 4749 | psotfx | 'AIM_IMG' => $user->img('btn_aim', 'AIM'), |
| 461 | 4749 | psotfx | 'MSN_IMG' => $user->img('btn_msnm', 'MSNM'), |
| 462 | 4749 | psotfx | 'YIM_IMG' => $user->img('btn_yim', 'YIM'), |
| 463 | 4749 | psotfx | 'JABBER_IMG' => $user->img('btn_jabber', 'JABBER') , |
| 464 | 4749 | psotfx | 'REPORT_IMG' => $user->img('btn_report', 'REPORT_POST'), |
| 465 | 4749 | psotfx | 'REPORTED_IMG' => $user->img('icon_reported', 'POST_REPORTED'), |
| 466 | 4749 | psotfx | 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'POST_UNAPPROVED'), |
| 467 | 3640 | ludovic_arnaud | |
| 468 | 3538 | psotfx | 'S_SELECT_SORT_DIR' => $s_sort_dir, |
| 469 | 3538 | psotfx | 'S_SELECT_SORT_KEY' => $s_sort_key, |
| 470 | 3538 | psotfx | 'S_SELECT_SORT_DAYS' => $s_limit_days, |
| 471 | 3953 | psotfx | 'S_TOPIC_ACTION' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&start=$start", |
| 472 | 3538 | psotfx | 'S_TOPIC_MOD' => ($topic_mod != '') ? '<select name="mode">' . $topic_mod . '</select>' : '', |
| 473 | 4947 | psotfx | 'S_MOD_ACTION' => "mcp.$phpEx?sid=" . $user->session_id . "&t=$topic_id&f=$forum_id&quickmod=1", |
| 474 | 3600 | ludovic_arnaud | |
| 475 | 4947 | psotfx | 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, |
| 476 | 5003 | acydburn | 'S_SEARCHBOX_ACTION' => "search.$phpEx$SID&search_forum[]=$forum_id", |
| 477 | 659 | psotfx | |
| 478 | 4473 | psotfx | 'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id", |
| 479 | 3071 | psotfx | 'U_FORUM' => $server_path, |
| 480 | 4192 | ludovic_arnaud | 'U_VIEW_UNREAD_POST' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=unread#unread", |
| 481 | 4912 | acydburn | 'U_VIEW_TOPIC' => $viewtopic_url, |
| 482 | 4065 | psotfx | 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id", |
| 483 | 4065 | psotfx | 'U_VIEW_OLDER_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=previous", |
| 484 | 4192 | ludovic_arnaud | 'U_VIEW_NEWER_TOPIC' => "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&view=next", |
| 485 | 4912 | acydburn | 'U_PRINT_TOPIC' => ($auth->acl_get('f_print', $forum_id)) ? $viewtopic_url . '&view=print' : '', |
| 486 | 4947 | psotfx | 'U_EMAIL_TOPIC' => ($auth->acl_get('f_email', $forum_id) && $config['email_enable']) ? "memberlist.$phpEx$SID&mode=email&t=$topic_id" : '', |
| 487 | 3747 | psotfx | |
| 488 | 4947 | psotfx | 'U_WATCH_TOPIC' => $s_watching_topic['link'], |
| 489 | 4947 | psotfx | 'L_WATCH_TOPIC' => $s_watching_topic['title'], |
| 490 | 4892 | acydburn | |
| 491 | 5117 | acydburn | 'U_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks']) ? $viewtopic_url . '&bookmark=1' : '', |
| 492 | 5117 | acydburn | 'L_BOOKMARK_TOPIC' => ($user->data['is_registered'] && $config['allow_bookmarks'] && $bookmarked) ? $user->lang['BOOKMARK_TOPIC_REMOVE'] : $user->lang['BOOKMARK_TOPIC'], |
| 493 | 4947 | psotfx | |
| 494 | 4150 | psotfx | 'U_POST_NEW_TOPIC' => "posting.$phpEx$SID&mode=post&f=$forum_id", |
| 495 | 4614 | acydburn | 'U_POST_REPLY_TOPIC' => "posting.$phpEx$SID&mode=reply&f=$forum_id&t=$topic_id", |
| 496 | 4634 | acydburn | 'U_BUMP_TOPIC' => (bump_topic_allowed($forum_id, $topic_bumped, $topic_last_post_time, $topic_poster, $topic_last_poster_id)) ? "posting.$phpEx$SID&mode=bump&f=$forum_id&t=$topic_id" : '') |
| 497 | 579 | psotfx | ); |
| 498 | 237 | psotfx | |
| 499 | 2853 | psotfx | // Does this topic contain a poll?
|
| 500 | 2983 | psotfx | if (!empty($poll_start)) |
| 501 | 987 | psotfx | {
|
| 502 | 4981 | acydburn | $sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid |
| 503 | 4981 | acydburn | FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p |
| 504 | 5078 | psotfx | WHERE o.topic_id = $topic_id |
| 505 | 4981 | acydburn | AND p.post_id = $topic_first_post_id |
| 506 | 4981 | acydburn | AND p.topic_id = o.topic_id |
| 507 | 4981 | acydburn | ORDER BY o.poll_option_id";
|
| 508 | 2673 | psotfx | $result = $db->sql_query($sql); |
| 509 | 987 | psotfx | |
| 510 | 4184 | acydburn | $poll_info = array(); |
| 511 | 2997 | psotfx | while ($row = $db->sql_fetchrow($result)) |
| 512 | 987 | psotfx | {
|
| 513 | 2983 | psotfx | $poll_info[] = $row; |
| 514 | 2983 | psotfx | } |
| 515 | 2983 | psotfx | $db->sql_freeresult($result); |
| 516 | 5078 | psotfx | |
| 517 | 4455 | psotfx | $cur_voted_id = array(); |
| 518 | 5117 | acydburn | if ($user->data['is_registered']) |
| 519 | 3953 | psotfx | {
|
| 520 | 4051 | psotfx | $sql = 'SELECT poll_option_id |
| 521 | 4057 | acydburn | FROM ' . POLL_VOTES_TABLE . ' |
| 522 | 4057 | acydburn | WHERE topic_id = ' . $topic_id . ' |
| 523 | 4057 | acydburn | AND vote_user_id = ' . $user->data['user_id']; |
| 524 | 3953 | psotfx | $result = $db->sql_query($sql); |
| 525 | 987 | psotfx | |
| 526 | 4192 | ludovic_arnaud | while ($row = $db->sql_fetchrow($result)) |
| 527 | 3920 | psotfx | {
|
| 528 | 4455 | psotfx | $cur_voted_id[] = $row['poll_option_id']; |
| 529 | 3920 | psotfx | } |
| 530 | 3953 | psotfx | $db->sql_freeresult($result); |
| 531 | 3920 | psotfx | } |
| 532 | 3953 | psotfx | else
|
| 533 | 3920 | psotfx | {
|
| 534 | 3953 | psotfx | // Cookie based guest tracking ... I don't like this but hum ho
|
| 535 | 3953 | psotfx | // it's oft requested. This relies on "nice" users who don't feel
|
| 536 | 4749 | psotfx | // the need to delete cookies to mess with results.
|
| 537 | 3953 | psotfx | if (isset($_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id])) |
| 538 | 3920 | psotfx | {
|
| 539 | 4455 | psotfx | $cur_voted_id = explode(',', $_COOKIE[$config['cookie_name'] . '_poll_' . $topic_id]); |
| 540 | 3920 | psotfx | } |
| 541 | 3953 | psotfx | } |
| 542 | 987 | psotfx | |
| 543 | 4947 | psotfx | $s_can_vote = (((!sizeof($cur_voted_id) && $auth->acl_get('f_vote', $forum_id)) || |
| 544 | 4981 | acydburn | ($auth->acl_get('f_votechg', $forum_id) && $poll_vote_change)) && |
| 545 | 4455 | psotfx | (($poll_length != 0 && $poll_start + $poll_length > time()) || $poll_length == 0) && |
| 546 | 4947 | psotfx | $topic_status != ITEM_LOCKED && |
| 547 | 3953 | psotfx | $forum_status != ITEM_LOCKED) ? true : false; |
| 548 | 5078 | psotfx | $s_display_results = (!$s_can_vote || ($s_can_vote && sizeof($cur_voted_id)) || $view == 'viewpoll') ? true : false; |
| 549 | 3953 | psotfx | |
| 550 | 4455 | psotfx | if ($update && $s_can_vote) |
| 551 | 3953 | psotfx | {
|
| 552 | 3920 | psotfx | if (!sizeof($voted_id) || sizeof($voted_id) > $poll_max_options) |
| 553 | 3920 | psotfx | {
|
| 554 | 3953 | psotfx | meta_refresh(5, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); |
| 555 | 3953 | psotfx | |
| 556 | 3953 | psotfx | $message = (!sizeof($voted_id)) ? 'NO_VOTE_OPTION' : 'TOO_MANY_VOTE_OPTIONS'; |
| 557 | 3953 | psotfx | $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id\">", '</a>'); |
| 558 | 3953 | psotfx | trigger_error($message); |
| 559 | 3920 | psotfx | } |
| 560 | 3920 | psotfx | |
| 561 | 3920 | psotfx | foreach ($voted_id as $option) |
| 562 | 3920 | psotfx | {
|
| 563 | 4455 | psotfx | if (in_array($option, $cur_voted_id)) |
| 564 | 4455 | psotfx | {
|
| 565 | 4455 | psotfx | continue;
|
| 566 | 4455 | psotfx | } |
| 567 | 4455 | psotfx | |
| 568 | 4947 | psotfx | $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " |
| 569 | 4947 | psotfx | SET poll_option_total = poll_option_total + 1 |
| 570 | 4947 | psotfx | WHERE poll_option_id = $option |
| 571 | 3920 | psotfx | AND topic_id = $topic_id"; |
| 572 | 3920 | psotfx | $db->sql_query($sql); |
| 573 | 3953 | psotfx | |
| 574 | 5117 | acydburn | if ($user->data['is_registered']) |
| 575 | 3953 | psotfx | {
|
| 576 | 4947 | psotfx | $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . " (topic_id, poll_option_id, vote_user_id, vote_user_ip) |
| 577 | 3953 | psotfx | VALUES ($topic_id, $option, " . $user->data['user_id'] . ", '$user->ip')"; |
| 578 | 3953 | psotfx | $db->sql_query($sql); |
| 579 | 3953 | psotfx | } |
| 580 | 3920 | psotfx | } |
| 581 | 3920 | psotfx | |
| 582 | 4455 | psotfx | foreach ($cur_voted_id as $option) |
| 583 | 4455 | psotfx | {
|
| 584 | 4455 | psotfx | if (!in_array($option, $voted_id)) |
| 585 | 4455 | psotfx | {
|
| 586 | 4947 | psotfx | $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " |
| 587 | 4947 | psotfx | SET poll_option_total = poll_option_total - 1 |
| 588 | 4947 | psotfx | WHERE poll_option_id = $option |
| 589 | 4455 | psotfx | AND topic_id = $topic_id"; |
| 590 | 4455 | psotfx | $db->sql_query($sql); |
| 591 | 4455 | psotfx | |
| 592 | 5117 | acydburn | if ($user->data['is_registered']) |
| 593 | 4455 | psotfx | {
|
| 594 | 4947 | psotfx | $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . " |
| 595 | 4455 | psotfx | WHERE topic_id = $topic_id |
| 596 | 4947 | psotfx | AND poll_option_id = $option |
| 597 | 4455 | psotfx | AND vote_user_id = " . $user->data['user_id']; |
| 598 | 4455 | psotfx | $db->sql_query($sql); |
| 599 | 4455 | psotfx | } |
| 600 | 4455 | psotfx | } |
| 601 | 4455 | psotfx | } |
| 602 | 4455 | psotfx | |
| 603 | 5117 | acydburn | if ($user->data['user_id'] == ANONYMOUS && !$user->data['is_bot']) |
| 604 | 3953 | psotfx | {
|
| 605 | 4904 | acydburn | $user->set_cookie('poll_' . $topic_id, implode(',', $voted_id), time() + 31536000); |
| 606 | 3953 | psotfx | } |
| 607 | 3953 | psotfx | |
| 608 | 4947 | psotfx | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 609 | 4947 | psotfx | SET poll_last_vote = ' . time() . " |
| 610 | 3920 | psotfx | WHERE topic_id = $topic_id"; |
| 611 | 5078 | psotfx | //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now
|
| 612 | 3920 | psotfx | $db->sql_query($sql); |
| 613 | 3953 | psotfx | |
| 614 | 3953 | psotfx | meta_refresh(5, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"); |
| 615 | 3953 | psotfx | |
| 616 | 3953 | psotfx | $message = $user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id\">", '</a>'); |
| 617 | 3953 | psotfx | trigger_error($message); |
| 618 | 3920 | psotfx | } |
| 619 | 3920 | psotfx | |
| 620 | 2983 | psotfx | $poll_total = 0; |
| 621 | 2983 | psotfx | foreach ($poll_info as $poll_option) |
| 622 | 2983 | psotfx | {
|
| 623 | 2983 | psotfx | $poll_total += $poll_option['poll_option_total']; |
| 624 | 2983 | psotfx | } |
| 625 | 987 | psotfx | |
| 626 | 4981 | acydburn | if ($poll_info[0]['bbcode_bitfield']) |
| 627 | 4981 | acydburn | {
|
| 628 | 4981 | acydburn | include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); |
| 629 | 4981 | acydburn | $poll_bbcode = new bbcode(); |
| 630 | 4981 | acydburn | |
| 631 | 4984 | acydburn | for ($i = 0, $size = sizeof($poll_info); $i < $size; $i++) |
| 632 | 4981 | acydburn | {
|
| 633 | 4981 | acydburn | $poll_bbcode->bbcode_second_pass($poll_info[$i]['poll_option_text'], $poll_info[$i]['bbcode_uid'], $poll_option['bbcode_bitfield']); |
| 634 | 5108 | acydburn | $poll_info[$i]['poll_option_text'] = smiley_text($poll_info[$i]['poll_option_text']); |
| 635 | 4981 | acydburn | $poll_info[$i]['poll_option_text'] = str_replace("\n", '<br />', censor_text($poll_info[$i]['poll_option_text'])); |
| 636 | 4981 | acydburn | } |
| 637 | 4981 | acydburn | |
| 638 | 4981 | acydburn | $poll_bbcode->bbcode_second_pass($poll_title, $poll_info[0]['bbcode_uid'], $poll_info[0]['bbcode_bitfield']); |
| 639 | 5108 | acydburn | $poll_title = smiley_text($poll_title); |
| 640 | 4981 | acydburn | $poll_title = str_replace("\n", '<br />', censor_text($poll_title)); |
| 641 | 4981 | acydburn | |
| 642 | 4981 | acydburn | unset($poll_bbcode); |
| 643 | 4981 | acydburn | } |
| 644 | 5078 | psotfx | |
| 645 | 2983 | psotfx | foreach ($poll_info as $poll_option) |
| 646 | 2983 | psotfx | {
|
| 647 | 3061 | psotfx | $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0; |
| 648 | 2983 | psotfx | $option_pct_txt = sprintf("%.1d%%", ($option_pct * 100)); |
| 649 | 987 | psotfx | |
| 650 | 2983 | psotfx | $template->assign_block_vars('poll_option', array( |
| 651 | 2983 | psotfx | 'POLL_OPTION_ID' => $poll_option['poll_option_id'], |
| 652 | 2983 | psotfx | 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'], |
| 653 | 2983 | psotfx | 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'], |
| 654 | 3953 | psotfx | 'POLL_OPTION_PERCENT' => $option_pct_txt, |
| 655 | 5073 | acydburn | 'POLL_OPTION_PCT' => round($option_pct * 100), |
| 656 | 4947 | psotfx | 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)), |
| 657 | 4455 | psotfx | 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false) |
| 658 | 2983 | psotfx | ); |
| 659 | 2983 | psotfx | } |
| 660 | 987 | psotfx | |
| 661 | 2983 | psotfx | $template->assign_vars(array( |
| 662 | 4981 | acydburn | 'POLL_QUESTION' => $poll_title, |
| 663 | 2983 | psotfx | 'TOTAL_VOTES' => $poll_total, |
| 664 | 2983 | psotfx | 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'), |
| 665 | 2983 | psotfx | 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'), |
| 666 | 2117 | psotfx | |
| 667 | 4947 | psotfx | 'L_MAX_VOTES' => ($poll_max_options == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $poll_max_options), |
| 668 | 4947 | psotfx | 'L_POLL_LENGTH' => ($poll_length) ? sprintf($user->lang['POLL_RUN_TILL'], $user->format_date($poll_length + $poll_start)) : '', |
| 669 | 3920 | psotfx | |
| 670 | 4947 | psotfx | 'S_HAS_POLL' => true, |
| 671 | 4947 | psotfx | 'S_CAN_VOTE' => $s_can_vote, |
| 672 | 3953 | psotfx | 'S_DISPLAY_RESULTS' => $s_display_results, |
| 673 | 4947 | psotfx | 'S_IS_MULTI_CHOICE' => ($poll_max_options > 1) ? true : false, |
| 674 | 4912 | acydburn | 'S_POLL_ACTION' => $viewtopic_url, |
| 675 | 987 | psotfx | |
| 676 | 4912 | acydburn | 'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll') |
| 677 | 2983 | psotfx | ); |
| 678 | 3961 | psotfx | |
| 679 | 4981 | acydburn | unset($poll_info, $voted_id); |
| 680 | 987 | psotfx | } |
| 681 | 987 | psotfx | |
| 682 | 4471 | ludovic_arnaud | // If the user is trying to reach the second half of the topic, fetch it starting from the end
|
| 683 | 4471 | ludovic_arnaud | $store_reverse = FALSE; |
| 684 | 4675 | ludovic_arnaud | $sql_limit = $config['posts_per_page']; |
| 685 | 4675 | ludovic_arnaud | |
| 686 | 4471 | ludovic_arnaud | if ($start > $total_posts / 2) |
| 687 | 4471 | ludovic_arnaud | {
|
| 688 | 4471 | ludovic_arnaud | $store_reverse = TRUE; |
| 689 | 4471 | ludovic_arnaud | |
| 690 | 4471 | ludovic_arnaud | if ($start + $config['posts_per_page'] > $total_posts) |
| 691 | 4471 | ludovic_arnaud | {
|
| 692 | 4675 | ludovic_arnaud | $sql_limit = min($config['posts_per_page'], max(1, $total_posts - $start)); |
| 693 | 4471 | ludovic_arnaud | } |
| 694 | 4471 | ludovic_arnaud | |
| 695 | 4675 | ludovic_arnaud | // Select the sort order
|
| 696 | 4675 | ludovic_arnaud | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC'); |
| 697 | 4675 | ludovic_arnaud | $sql_start = max(0, $total_posts - $sql_limit - $start); |
| 698 | 4471 | ludovic_arnaud | } |
| 699 | 4522 | psotfx | else
|
| 700 | 4522 | psotfx | {
|
| 701 | 4522 | psotfx | // Select the sort order
|
| 702 | 4675 | ludovic_arnaud | $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); |
| 703 | 4675 | ludovic_arnaud | $sql_start = $start; |
| 704 | 4522 | psotfx | } |
| 705 | 4471 | ludovic_arnaud | |
| 706 | 4522 | psotfx | // Container for user details, only process once
|
| 707 | 4767 | acydburn | $post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = array(); |
| 708 | 4859 | acydburn | $has_attachments = $display_notice = false; |
| 709 | 4522 | psotfx | $force_encoding = ''; |
| 710 | 4522 | psotfx | $bbcode_bitfield = $i = $i_total = 0; |
| 711 | 4522 | psotfx | |
| 712 | 3856 | ludovic_arnaud | // Go ahead and pull all data for this topic
|
| 713 | 4675 | ludovic_arnaud | $sql = 'SELECT p.post_id |
| 714 | 4892 | acydburn | FROM ' . POSTS_TABLE . ' p' . (($sort_by_sql[$sort_key]{0} == 'u') ? ', ' . USERS_TABLE . ' u': '') . " |
| 715 | 3856 | ludovic_arnaud | WHERE p.topic_id = $topic_id |
| 716 | 4675 | ludovic_arnaud | " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . " |
| 717 | 4892 | acydburn | " . (($sort_by_sql[$sort_key]{0} == 'u') ? 'AND u.user_id = p.poster_id': '') . " |
| 718 | 3856 | ludovic_arnaud | $limit_posts_time |
| 719 | 4675 | ludovic_arnaud | ORDER BY $sql_sort_order"; |
| 720 | 4675 | ludovic_arnaud | $result = $db->sql_query_limit($sql, $sql_limit, $sql_start); |
| 721 | 3856 | ludovic_arnaud | |
| 722 | 4675 | ludovic_arnaud | $i = ($store_reverse) ? $sql_limit - 1 : 0; |
| 723 | 4675 | ludovic_arnaud | while ($row = $db->sql_fetchrow($result)) |
| 724 | 3856 | ludovic_arnaud | {
|
| 725 | 4675 | ludovic_arnaud | $post_list[$i] = $row['post_id']; |
| 726 | 4675 | ludovic_arnaud | ($store_reverse) ? --$i : ++$i; |
| 727 | 4675 | ludovic_arnaud | } |
| 728 | 5108 | acydburn | $db->sql_freeresult($result); |
| 729 | 4675 | ludovic_arnaud | |
| 730 | 4675 | ludovic_arnaud | if (empty($post_list)) |
| 731 | 4675 | ludovic_arnaud | {
|
| 732 | 3856 | ludovic_arnaud | trigger_error($user->lang['NO_TOPIC']); |
| 733 | 3856 | ludovic_arnaud | } |
| 734 | 3856 | ludovic_arnaud | |
| 735 | 4887 | psotfx | $sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_jabber, u.user_regdate, u.user_msnm, u.user_allow_viewemail, u.user_allow_viewonline, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, z.friend, z.foe, p.* |
| 736 | 5140 | acydburn | FROM (' . POSTS_TABLE . ' p |
| 737 | 5140 | acydburn | LEFT JOIN ' . ZEBRA_TABLE . ' z ON (z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id)), ' . USERS_TABLE . ' u |
| 738 | 4675 | ludovic_arnaud | WHERE p.post_id IN (' . implode(', ', $post_list) . ') |
| 739 | 4675 | ludovic_arnaud | AND u.user_id = p.poster_id';
|
| 740 | 4675 | ludovic_arnaud | $result = $db->sql_query($sql); |
| 741 | 4675 | ludovic_arnaud | |
| 742 | 3868 | ludovic_arnaud | // Posts are stored in the $rowset array while $attach_list, $user_cache
|
| 743 | 3868 | ludovic_arnaud | // and the global bbcode_bitfield are built
|
| 744 | 4675 | ludovic_arnaud | while ($row = $db->sql_fetchrow($result)) |
| 745 | 3856 | ludovic_arnaud | {
|
| 746 | 3869 | psotfx | $poster_id = $row['poster_id']; |
| 747 | 3868 | ludovic_arnaud | $poster = ($poster_id == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username']; |
| 748 | 3856 | ludovic_arnaud | |
| 749 | 4522 | psotfx | if (!$view || $view != 'show' || $post_id != $row['post_id']) |
| 750 | 3868 | ludovic_arnaud | {
|
| 751 | 4887 | psotfx | if ($row['foe']) |
| 752 | 4522 | psotfx | {
|
| 753 | 4762 | acydburn | $rowset[$row['post_id']] = array( |
| 754 | 4903 | acydburn | 'foe' => true, |
| 755 | 4947 | psotfx | 'post_id' => $row['post_id'], |
| 756 | 4522 | psotfx | 'poster' => $poster, |
| 757 | 4522 | psotfx | ); |
| 758 | 4522 | psotfx | |
| 759 | 4522 | psotfx | continue;
|
| 760 | 4522 | psotfx | } |
| 761 | 3868 | ludovic_arnaud | } |
| 762 | 3868 | ludovic_arnaud | |
| 763 | 4139 | acydburn | // Does post have an attachment? If so, add it to the list
|
| 764 | 4139 | acydburn | if ($row['post_attachment'] && $config['allow_attachments']) |
| 765 | 4139 | acydburn | {
|
| 766 | 4269 | psotfx | $attach_list[] = $row['post_id']; |
| 767 | 4947 | psotfx | |
| 768 | 4269 | psotfx | if ($row['post_approved']) |
| 769 | 4139 | acydburn | {
|
| 770 | 4269 | psotfx | $has_attachments = TRUE; |
| 771 | 4139 | acydburn | } |
| 772 | 4139 | acydburn | } |
| 773 | 4139 | acydburn | |
| 774 | 4675 | ludovic_arnaud | $rowset[$row['post_id']] = array( |
| 775 | 4675 | ludovic_arnaud | 'post_id' => $row['post_id'], |
| 776 | 4675 | ludovic_arnaud | 'post_time' => $row['post_time'], |
| 777 | 4675 | ludovic_arnaud | 'poster' => ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster, |
| 778 | 4675 | ludovic_arnaud | 'user_id' => $row['user_id'], |
| 779 | 4675 | ludovic_arnaud | 'topic_id' => $row['topic_id'], |
| 780 | 4675 | ludovic_arnaud | 'forum_id' => $row['forum_id'], |
| 781 | 4675 | ludovic_arnaud | 'post_subject' => $row['post_subject'], |
| 782 | 4675 | ludovic_arnaud | 'post_edit_count' => $row['post_edit_count'], |
| 783 | 4675 | ludovic_arnaud | 'post_edit_time' => $row['post_edit_time'], |
| 784 | 4767 | acydburn | 'post_edit_reason' => $row['post_edit_reason'], |
| 785 | 4767 | acydburn | 'post_edit_user' => $row['post_edit_user'], |
| 786 | 4675 | ludovic_arnaud | 'icon_id' => $row['icon_id'], |
| 787 | 4675 | ludovic_arnaud | 'post_attachment' => $row['post_attachment'], |
| 788 | 4675 | ludovic_arnaud | 'post_approved' => $row['post_approved'], |
| 789 | 4675 | ludovic_arnaud | 'post_reported' => $row['post_reported'], |
| 790 | 4675 | ludovic_arnaud | 'post_text' => $row['post_text'], |
| 791 | 4675 | ludovic_arnaud | 'post_encoding' => $row['post_encoding'], |
| 792 | 4675 | ludovic_arnaud | 'bbcode_uid' => $row['bbcode_uid'], |
| 793 | 4675 | ludovic_arnaud | 'bbcode_bitfield' => $row['bbcode_bitfield'], |
| 794 | 4675 | ludovic_arnaud | 'enable_html' => $row['enable_html'], |
| 795 | 4675 | ludovic_arnaud | 'enable_smilies' => $row['enable_smilies'], |
| 796 | 4947 | psotfx | 'enable_sig' => $row['enable_sig'], |
| 797 | 4947 | psotfx | 'friend' => $row['friend'], |
| 798 | 4675 | ludovic_arnaud | ); |
| 799 | 3868 | ludovic_arnaud | |
| 800 | 3953 | psotfx | // Define the global bbcode bitfield, will be used to load bbcodes
|
| 801 | 3953 | psotfx | $bbcode_bitfield |= $row['bbcode_bitfield']; |
| 802 | 3953 | psotfx | |
| 803 | 4499 | ludovic_arnaud | // Is a signature attached? Are we going to display it?
|
| 804 | 4577 | acydburn | if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) |
| 805 | 4499 | ludovic_arnaud | {
|
| 806 | 4499 | ludovic_arnaud | $bbcode_bitfield |= $row['user_sig_bbcode_bitfield']; |
| 807 | 4499 | ludovic_arnaud | } |
| 808 | 4499 | ludovic_arnaud | |
| 809 | 3856 | ludovic_arnaud | // Cache various user specific data ... so we don't have to recompute
|
| 810 | 3856 | ludovic_arnaud | // this each time the same user appears on this page
|
| 811 | 3856 | ludovic_arnaud | if (!isset($user_cache[$poster_id])) |
| 812 | 3856 | ludovic_arnaud | {
|
| 813 | 3856 | ludovic_arnaud | if ($poster_id == ANONYMOUS) |
| 814 | 3538 | psotfx | {
|
| 815 | 3856 | ludovic_arnaud | $user_cache[$poster_id] = array( |
| 816 | 4892 | acydburn | 'joined' => '', |
| 817 | 4892 | acydburn | 'posts' => '', |
| 818 | 4892 | acydburn | 'from' => '', |
| 819 | 4892 | acydburn | |
| 820 | 4892 | acydburn | 'sig' => '', |
| 821 | 4892 | acydburn | 'sig_bbcode_uid' => '', |
| 822 | 4892 | acydburn | 'sig_bbcode_bitfield' => '', |
| 823 | 4892 | acydburn | |
| 824 | 4920 | acydburn | 'online' => false, |
| 825 | 4892 | acydburn | 'avatar' => '', |
| 826 | 4892 | acydburn | 'rank_title' => '', |
| 827 | 4892 | acydburn | 'rank_image' => '', |
| 828 | 4892 | acydburn | 'sig' => '', |
| 829 | 4892 | acydburn | 'posts' => '', |
| 830 | 4892 | acydburn | 'profile' => '', |
| 831 | 4892 | acydburn | 'pm' => '', |
| 832 | 4892 | acydburn | 'email' => '', |
| 833 | 4892 | acydburn | 'www' => '', |
| 834 | 4892 | acydburn | 'icq_status_img'=> '', |
| 835 | 4892 | acydburn | 'icq' => '', |
| 836 | 4892 | acydburn | 'aim' => '', |
| 837 | 4892 | acydburn | 'msn' => '', |
| 838 | 4892 | acydburn | 'yim' => '', |
| 839 | 4892 | acydburn | 'jabber' => '', |
| 840 | 4892 | acydburn | 'search' => '', |
| 841 | 4892 | acydburn | 'username' => ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster |
| 842 | 3856 | ludovic_arnaud | ); |
| 843 | 3856 | ludovic_arnaud | } |
| 844 | 3856 | ludovic_arnaud | else
|
| 845 | 3856 | ludovic_arnaud | {
|
| 846 | 3953 | psotfx | $user_sig = ''; |
| 847 | 4578 | psotfx | |
| 848 | 4749 | psotfx | if ($row['enable_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) |
| 849 | 3538 | psotfx | {
|
| 850 | 3953 | psotfx | $user_sig = $row['user_sig']; |
| 851 | 3538 | psotfx | } |
| 852 | 4441 | psotfx | |
| 853 | 4269 | psotfx | $id_cache[] = $poster_id; |
| 854 | 4749 | psotfx | |
| 855 | 3856 | ludovic_arnaud | $user_cache[$poster_id] = array( |
| 856 | 4051 | psotfx | 'joined' => $user->format_date($row['user_regdate'], $user->lang['DATE_FORMAT']), |
| 857 | 5216 | bartvb | 'posts' => $row['user_posts'], |
| 858 | 4051 | psotfx | 'from' => (!empty($row['user_from'])) ? $row['user_from'] : '', |
| 859 | 3953 | psotfx | |
| 860 | 4051 | psotfx | 'sig' => $user_sig, |
| 861 | 4051 | psotfx | 'sig_bbcode_uid' => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '', |
| 862 | 4051 | psotfx | 'sig_bbcode_bitfield' => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '', |
| 863 | 3953 | psotfx | |
| 864 | 4947 | psotfx | 'viewonline' => $row['user_allow_viewonline'], |
| 865 | 4269 | psotfx | |
| 866 | 4051 | psotfx | 'avatar' => '', |
| 867 | 3868 | ludovic_arnaud | |
| 868 | 4920 | acydburn | 'online' => false, |
| 869 | 5137 | acydburn | 'profile' => "{$phpbb_root_path}memberlist.$phpEx$SID&mode=viewprofile&u=$poster_id", |
| 870 | 4051 | psotfx | 'www' => $row['user_website'], |
| 871 | 4051 | psotfx | 'aim' => ($row['user_aim']) ? "memberlist.$phpEx$SID&mode=contact&action=aim&u=$poster_id" : '', |
| 872 | 4051 | psotfx | 'msn' => ($row['user_msnm']) ? "memberlist.$phpEx$SID&mode=contact&action=msnm&u=$poster_id" : '', |
| 873 | 4051 | psotfx | 'yim' => ($row['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $row['user_yim'] . '&.src=pg' : '', |
| 874 | 4051 | psotfx | 'jabber' => ($row['user_jabber']) ? "memberlist.$phpEx$SID&mode=contact&action=jabber&u=$poster_id" : '', |
| 875 | 4634 | acydburn | 'search' => ($auth->acl_get('u_search')) ? "search.$phpEx$SID&search_author=" . urlencode($row['username']) .'&showresults=posts' : '', |
| 876 | 4634 | acydburn | 'username' => ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster |
| 877 | 3856 | ludovic_arnaud | ); |
| 878 | 3538 | psotfx | |
| 879 | 4577 | acydburn | if ($row['user_avatar'] && $user->optionget('viewavatars')) |
| 880 | 2708 | psotfx | {
|
| 881 | 4065 | psotfx | $avatar_img = ''; |
| 882 | 2997 | psotfx | switch ($row['user_avatar_type']) |
| 883 | 2714 | psotfx | {
|
| 884 | 4062 | psotfx | case AVATAR_UPLOAD: |
| 885 | 4062 | psotfx | $avatar_img = $config['avatar_path'] . '/'; |
| 886 | 2714 | psotfx | break;
|
| 887 | 4062 | psotfx | case AVATAR_GALLERY: |
| 888 | 4062 | psotfx | $avatar_img = $config['avatar_gallery_path'] . '/'; |
| 889 | 2714 | psotfx | break;
|
| 890 | 2714 | psotfx | } |
| 891 | 4062 | psotfx | $avatar_img .= $row['user_avatar']; |
| 892 | 4062 | psotfx | |
| 893 | 4964 | acydburn | $user_cache[$poster_id]['avatar'] = '<img src="' . $avatar_img . '" width="' . $row['user_avatar_width'] . '" height="' . $row['user_avatar_height'] . '" border="0" alt="" />'; |
| 894 | 2708 | psotfx | } |
| 895 | 3856 | ludovic_arnaud | |
| 896 | 3856 | ludovic_arnaud | if (!empty($row['user_rank'])) |
| 897 | 2714 | psotfx | {
|
| 898 | 4920 | acydburn | $user_cache[$poster_id]['rank_title'] = (isset($ranks['special'][$row['user_rank']])) ? $ranks['special'][$row['user_rank']]['rank_title'] : ''; |
| 899 | 4076 | psotfx | $user_cache[$poster_id]['rank_image'] = (!empty($ranks['special'][$row['user_rank']]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$row['user_rank']]['rank_image'] . '" border="0" alt="' . $ranks['special'][$row['user_rank']]['rank_title'] . '" title="' . $ranks['special'][$row['user_rank']]['rank_title'] . '" /><br />' : ''; |
| 900 | 2714 | psotfx | } |
| 901 | 3856 | ludovic_arnaud | else
|
| 902 | 136 | psotfx | {
|
| 903 | 4920 | acydburn | if (isset($ranks['normal']) && sizeof($ranks['normal'])) |
| 904 | 2673 | psotfx | {
|
| 905 | 4912 | acydburn | foreach ($ranks['normal'] as $rank) |
| 906 | 3856 | ludovic_arnaud | {
|
| 907 | 4912 | acydburn | if ($row['user_posts'] >= $rank['rank_min']) |
| 908 | 4912 | acydburn | {
|
| 909 | 4912 | acydburn | $user_cache[$poster_id]['rank_title'] = $rank['rank_title']; |
| 910 | 4912 | acydburn | $user_cache[$poster_id]['rank_image'] = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" border="0" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : ''; |
| 911 | 4912 | acydburn | break;
|
| 912 | 4912 | acydburn | } |
| 913 | 3856 | ludovic_arnaud | } |
| 914 | 2673 | psotfx | } |
| 915 | 4912 | acydburn | else
|
| 916 | 4912 | acydburn | {
|
| 917 | 4912 | acydburn | $user_cache[$poster_id]['rank_title'] = ''; |
| 918 | 4912 | acydburn | $user_cache[$poster_id]['rank_image'] = ''; |
| 919 | 4912 | acydburn | } |
| 920 | 281 | psotfx | } |
| 921 | 136 | psotfx | |
| 922 | 4150 | psotfx | if (!empty($row['user_allow_viewemail']) || $auth->acl_get('a_email')) |
| 923 | 2714 | psotfx | {
|
| 924 | 5071 | acydburn | $user_cache[$poster_id]['email'] = ($config['board_email_form'] && $config['email_enable']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&mode=email&u=$poster_id" : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']); |
| 925 | 2714 | psotfx | } |
| 926 | 2714 | psotfx | else
|
| 927 | 2714 | psotfx | {
|
| 928 | 3286 | psotfx | $user_cache[$poster_id]['email'] = ''; |
| 929 | 2714 | psotfx | } |
| 930 | 2714 | psotfx | |
| 931 | 2997 | psotfx | if (!empty($row['user_icq'])) |
| 932 | 2714 | psotfx | {
|
| 933 | 4051 | psotfx | $user_cache[$poster_id]['icq'] = "memberlist.$phpEx$SID&mode=contact&action=icq&u=$poster_id"; |
| 934 | 4150 | psotfx | $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&img=5" width="18" height="18" border="0" />'; |
| 935 | 2714 | psotfx | } |
| 936 | 2714 | psotfx | else
|
| 937 | 2714 | psotfx | {
|
| 938 | 3286 | psotfx | $user_cache[$poster_id]['icq_status_img'] = ''; |
| 939 | 3286 | psotfx | $user_cache[$poster_id]['icq'] = ''; |
| 940 | 2714 | psotfx | } |
| 941 | 1320 | psotfx | } |
| 942 | 3856 | ludovic_arnaud | } |
| 943 | 3868 | ludovic_arnaud | } |
| 944 | 3868 | ludovic_arnaud | $db->sql_freeresult($result); |
| 945 | 1320 | psotfx | |
| 946 | 4984 | acydburn | // Load custom profile fields
|
| 947 | 4984 | acydburn | if ($config['load_cpf_viewtopic']) |
| 948 | 4892 | acydburn | {
|
| 949 | 4892 | acydburn | include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); |
| 950 | 4892 | acydburn | $cp = new custom_profile(); |
| 951 | 4984 | acydburn | |
| 952 | 4984 | acydburn | // Grab all profile fields from users in id cache for later use - similar to the poster cache
|
| 953 | 4892 | acydburn | $profile_fields_cache = $cp->generate_profile_fields_template('grab', $id_cache); |
| 954 | 4892 | acydburn | } |
| 955 | 4892 | acydburn | |
| 956 | 4269 | psotfx | // Generate online information for user
|
| 957 | 4269 | psotfx | if ($config['load_onlinetrack'] && sizeof($id_cache)) |
| 958 | 3868 | ludovic_arnaud | {
|
| 959 | 4973 | psotfx | $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline |
| 960 | 4947 | psotfx | FROM ' . SESSIONS_TABLE . ' |
| 961 | 4269 | psotfx | WHERE session_user_id IN (' . implode(', ', $id_cache) . ') |
| 962 | 4269 | psotfx | GROUP BY session_user_id';
|
| 963 | 3868 | ludovic_arnaud | $result = $db->sql_query($sql); |
| 964 | 3868 | ludovic_arnaud | |
| 965 | 4269 | psotfx | $update_time = $config['load_online_time'] * 60; |
| 966 | 3868 | ludovic_arnaud | while ($row = $db->sql_fetchrow($result)) |
| 967 | 3868 | ludovic_arnaud | {
|
| 968 | 4269 | psotfx | $user_cache[$row['session_user_id']]['online'] = (time() - $update_time < $row['online_time'] && (($row['viewonline'] && $user_cache[$row['session_user_id']]['viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false; |
| 969 | 3868 | ludovic_arnaud | } |
| 970 | 4269 | psotfx | } |
| 971 | 4269 | psotfx | unset($id_cache); |
| 972 | 3868 | ludovic_arnaud | |
| 973 | 4269 | psotfx | // Pull attachment data
|
| 974 | 4920 | acydburn | if (sizeof($attach_list)) |
| 975 | 4269 | psotfx | {
|
| 976 | 4637 | acydburn | if ($auth->acl_gets('f_download', 'u_download', $forum_id)) |
| 977 | 3868 | ludovic_arnaud | {
|
| 978 | 4947 | psotfx | $sql = 'SELECT * |
| 979 | 4637 | acydburn | FROM ' . ATTACHMENTS_TABLE . ' |
| 980 | 4883 | acydburn | WHERE post_msg_id IN (' . implode(', ', $attach_list) . ') |
| 981 | 4883 | acydburn | AND in_message = 0 |
| 982 | 4883 | acydburn | ORDER BY filetime ' . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC'; |
| 983 | 4269 | psotfx | $result = $db->sql_query($sql); |
| 984 | 4269 | psotfx | |
| 985 | 4269 | psotfx | while ($row = $db->sql_fetchrow($result)) |
| 986 | 3868 | ludovic_arnaud | {
|
| 987 | 4883 | acydburn | $attachments[$row['post_msg_id']][] = $row; |
| 988 | 4269 | psotfx | } |
| 989 | 4269 | psotfx | $db->sql_freeresult($result); |
| 990 | 3868 | ludovic_arnaud | |
| 991 | 4473 | psotfx | // No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
|
| 992 | 4920 | acydburn | if (!sizeof($attachments)) |
| 993 | 4269 | psotfx | {
|
| 994 | 4947 | psotfx | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 995 | 4947 | psotfx | SET post_attachment = 0 |
| 996 | 4269 | psotfx | WHERE post_id IN (' . implode(', ', $attach_list) . ')'; |
| 997 | 4269 | psotfx | $db->sql_query($sql); |
| 998 | 4269 | psotfx | |
| 999 | 4269 | psotfx | // We need to update the topic indicator too if the complete topic is now without an attachment
|
| 1000 | 4920 | acydburn | if (sizeof($rowset) != $total_posts) |
| 1001 | 3868 | ludovic_arnaud | {
|
| 1002 | 4269 | psotfx | // Not all posts are displayed so we query the db to find if there's any attachment for this topic
|
| 1003 | 4883 | acydburn | $sql = 'SELECT a.post_msg_id as post_id |
| 1004 | 4269 | psotfx | FROM ' . ATTACHMENTS_TABLE . ' a, ' . POSTS_TABLE . " p |
| 1005 | 4269 | psotfx | WHERE p.topic_id = $topic_id |
| 1006 | 4269 | psotfx | AND p.post_approved = 1 |
| 1007 | 4883 | acydburn | AND p.topic_id = a.topic_id";
|
| 1008 | 4269 | psotfx | $result = $db->sql_query_limit($sql, 1); |
| 1009 | 4269 | psotfx | |
| 1010 | 4269 | psotfx | if (!$db->sql_fetchrow($result)) |
| 1011 | 4269 | psotfx | {
|
| 1012 | 4947 | psotfx | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 1013 | 4947 | psotfx | SET topic_attachment = 0 |
| 1014 | 4269 | psotfx | WHERE topic_id = $topic_id"; |
| 1015 | 4269 | psotfx | $db->sql_query($sql); |
| 1016 | 4269 | psotfx | } |
| 1017 | 4269 | psotfx | } |
| 1018 | 4269 | psotfx | else
|
| 1019 | 4269 | psotfx | {
|
| 1020 | 4947 | psotfx | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 1021 | 4947 | psotfx | SET topic_attachment = 0 |
| 1022 | 3920 | psotfx | WHERE topic_id = $topic_id"; |
| 1023 | 3920 | psotfx | $db->sql_query($sql); |
| 1024 | 3868 | ludovic_arnaud | } |
| 1025 | 3868 | ludovic_arnaud | } |
| 1026 | 4762 | acydburn | else if ($has_attachments && !$topic_data['topic_attachment']) |
| 1027 | 3868 | ludovic_arnaud | {
|
| 1028 | 4269 | psotfx | // Topic has approved attachments but its flag is wrong
|
| 1029 | 4947 | psotfx | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 1030 | 4947 | psotfx | SET topic_attachment = 1 |
| 1031 | 3920 | psotfx | WHERE topic_id = $topic_id"; |
| 1032 | 3920 | psotfx | $db->sql_query($sql); |
| 1033 | 4762 | acydburn | |
| 1034 | 4762 | acydburn | $topic_data['topic_attachment'] = 1; |
| 1035 | 3868 | ludovic_arnaud | } |
| 1036 | 3868 | ludovic_arnaud | } |
| 1037 | 4269 | psotfx | else
|
| 1038 | 3868 | ludovic_arnaud | {
|
| 1039 | 4859 | acydburn | $display_notice = true; |
| 1040 | 3868 | ludovic_arnaud | } |
| 1041 | 3868 | ludovic_arnaud | } |
| 1042 | 3868 | ludovic_arnaud | |
| 1043 | 4167 | psotfx | // Instantiate BBCode if need be
|
| 1044 | 3868 | ludovic_arnaud | if ($bbcode_bitfield) |
| 1045 | 3868 | ludovic_arnaud | {
|
| 1046 | 4904 | acydburn | include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); |
| 1047 | 3868 | ludovic_arnaud | $bbcode = new bbcode($bbcode_bitfield); |
| 1048 | 3868 | ludovic_arnaud | } |
| 1049 | 3868 | ludovic_arnaud | |
| 1050 | 4473 | psotfx | $i_total = sizeof($rowset) - 1; |
| 1051 | 4473 | psotfx | $prev_post_id = ''; |
| 1052 | 4167 | psotfx | |
| 1053 | 4870 | acydburn | $template->assign_vars(array( |
| 1054 | 4920 | acydburn | 'S_NUM_POSTS' => sizeof($post_list)) |
| 1055 | 4870 | acydburn | ); |
| 1056 | 4870 | acydburn | |
| 1057 | 4167 | psotfx | // Output the posts
|
| 1058 | 4675 | ludovic_arnaud | //foreach ($rowset as $i => $row)
|
| 1059 | 4920 | acydburn | for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) |
| 1060 | 3868 | ludovic_arnaud | {
|
| 1061 | 4675 | ludovic_arnaud | $row =& $rowset[$post_list[$i]]; |
| 1062 | 4062 | psotfx | $poster_id = $row['user_id']; |
| 1063 | 3868 | ludovic_arnaud | |
| 1064 | 3868 | ludovic_arnaud | // Three situations can prevent a post being display:
|
| 1065 | 4887 | psotfx | // i) The posters karma is below the minimum of the user ... not in 2.2.x
|
| 1066 | 3868 | ludovic_arnaud | // ii) The poster is on the users ignore list
|
| 1067 | 3868 | ludovic_arnaud | // iii) The post was made in a codepage different from the users
|
| 1068 | 4903 | acydburn | if (isset($row['foe']) && $row['foe']) |
| 1069 | 3868 | ludovic_arnaud | {
|
| 1070 | 3868 | ludovic_arnaud | $template->assign_block_vars('postrow', array( |
| 1071 | 4947 | psotfx | 'S_IGNORE_POST' => true, |
| 1072 | 4522 | psotfx | 'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['poster'], "<a href=\"viewtopic.$phpEx$SID&f=$forum_id&p=" . $row['post_id'] . '&view=show#' . $row['post_id'] . '">', '</a>')) |
| 1073 | 4522 | psotfx | ); |
| 1074 | 4522 | psotfx | |
| 1075 | 4522 | psotfx | continue;
|
| 1076 | 4522 | psotfx | } |
| 1077 | 3868 | ludovic_arnaud | else if ($row['post_encoding'] != $user->lang['ENCODING']) |
| 1078 | 3868 | ludovic_arnaud | {
|
| 1079 | 4473 | psotfx | if ($view == 'encoding' && $post_id == $row['post_id']) |
| 1080 | 3868 | ludovic_arnaud | {
|
| 1081 | 3868 | ludovic_arnaud | $force_encoding = $row['post_encoding']; |
| 1082 | 3868 | ludovic_arnaud | } |
| 1083 | 3868 | ludovic_arnaud | else
|
| 1084 | 3868 | ludovic_arnaud | {
|
| 1085 | 3868 | ludovic_arnaud | $template->assign_block_vars('postrow', array( |
| 1086 | 4947 | psotfx | 'S_IGNORE_POST' => true, |
| 1087 | 4080 | psotfx | 'L_IGNORE_POST' => sprintf($user->lang['POST_ENCODING'], $row['poster'], '<a href="viewtopic.' . $phpEx . $SID . '&p=' . $row['post_id'] . '&view=encoding#' . $row['post_id'] . '">', '</a>')) |
| 1088 | 3868 | ludovic_arnaud | ); |
| 1089 | 3868 | ludovic_arnaud | |
| 1090 | 3868 | ludovic_arnaud | continue;
|
| 1091 | 3868 | ludovic_arnaud | } |
| 1092 | 3868 | ludovic_arnaud | } |
| 1093 | 3868 | ludovic_arnaud | |
| 1094 | 3868 | ludovic_arnaud | // End signature parsing, only if needed
|
| 1095 | 4578 | psotfx | if ($user_cache[$poster_id]['sig'] && empty($user_cache[$poster_id]['sig_parsed'])) |
| 1096 | 3868 | ludovic_arnaud | {
|
| 1097 | 3868 | ludovic_arnaud | if ($user_cache[$poster_id]['sig_bbcode_bitfield']) |
| 1098 | 3868 | ludovic_arnaud | {
|
| 1099 | 4150 | psotfx | $bbcode->bbcode_second_pass($user_cache[$poster_id]['sig'], $user_cache[$poster_id]['sig_bbcode_uid'], $user_cache[$poster_id]['sig_bbcode_bitfield']); |
| 1100 | 3868 | ludovic_arnaud | } |
| 1101 | 3869 | psotfx | |
| 1102 | 5108 | acydburn | $user_cache[$poster_id]['sig'] = smiley_text($user_cache[$poster_id]['sig']); |
| 1103 | 4836 | acydburn | $user_cache[$poster_id]['sig'] = str_replace("\n", '<br />', censor_text($user_cache[$poster_id]['sig'])); |
| 1104 | 3868 | ludovic_arnaud | $user_cache[$poster_id]['sig_parsed'] = TRUE; |
| 1105 | 3868 | ludovic_arnaud | } |
| 1106 | 3868 | ludovic_arnaud | |
| 1107 | 3856 | ludovic_arnaud | // Parse the message and subject
|
| 1108 | 3856 | ludovic_arnaud | $message = $row['post_text']; |
| 1109 | 3347 | psotfx | |
| 1110 | 4473 | psotfx | // If the board has HTML off but the post has HTML on then we process it, else leave it alone
|
| 1111 | 4984 | acydburn | if (!$auth->acl_get('f_html', $forum_id) && $row['enable_html']) |
| 1112 | 3856 | ludovic_arnaud | {
|
| 1113 | 4984 | acydburn | $message = preg_replace('#(<!\-\- h \-\-><)([\/]?.*?)(><!\-\- h \-\->)#is', "<\\2>", $message); |
| 1114 | 3856 | ludovic_arnaud | } |
| 1115 | 3286 | psotfx | |
| 1116 | 3856 | ludovic_arnaud | // Second parse bbcode here
|
| 1117 | 3856 | ludovic_arnaud | if ($row['bbcode_bitfield']) |
| 1118 | 3856 | ludovic_arnaud | {
|
| 1119 | 4150 | psotfx | $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']); |
| 1120 | 3856 | ludovic_arnaud | } |
| 1121 | 303 | thefinn | |
| 1122 | 4836 | acydburn | // Always process smilies after parsing bbcodes
|
| 1123 | 5108 | acydburn | $message = smiley_text($message); |
| 1124 | 987 | psotfx | |
| 1125 | 4984 | acydburn | if (isset($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']])) |
| 1126 | 4984 | acydburn | {
|
| 1127 | 4984 | acydburn | $unset_attachments = parse_inline_attachments($message, $attachments[$row['post_id']], $update_count, $forum_id); |
| 1128 | 4984 | acydburn | |
| 1129 | 4984 | acydburn | // Needed to let not display the inlined attachments at the end of the post again
|
| 1130 | 4984 | acydburn | foreach ($unset_attachments as $index) |
| 1131 | 4984 | acydburn | {
|
| 1132 | 4984 | acydburn | unset($attachments[$row['post_id']][$index]); |
| 1133 | 4984 | acydburn | } |
| 1134 | 4984 | acydburn | } |
| 1135 | 4984 | acydburn | |
| 1136 | 3856 | ludovic_arnaud | // Highlight active words (primarily for search)
|
| 1137 | 3856 | ludovic_arnaud | if ($highlight_match) |
| 1138 | 3856 | ludovic_arnaud | {
|
| 1139 | 3856 | ludovic_arnaud | // This was shamelessly 'borrowed' from volker at multiartstudio dot de
|
| 1140 | 3856 | ludovic_arnaud | // via php.net's annotated manual
|
| 1141 | 5168 | acydburn | $message = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . str_replace('\\', '\\\\', addslashes($highlight_match)) . ")\b#i', '<span class=\"posthilit\">\\\\1</span>', '\\0')", '>' . $message . '<'), 1, -1)); |
| 1142 | 3856 | ludovic_arnaud | } |
| 1143 | 3347 | psotfx | |
| 1144 | 4984 | acydburn | if ($row['enable_html'] && $auth->acl_get('f_html', $forum_id)) |
| 1145 | 4984 | acydburn | {
|
| 1146 | 5137 | acydburn | // Remove Comments from post content
|
| 1147 | 4984 | acydburn | $message = preg_replace('#<!\-\-(.*?)\-\->#is', '', $message); |
| 1148 | 4984 | acydburn | } |
| 1149 | 5078 | psotfx | |
| 1150 | 3856 | ludovic_arnaud | // Replace naughty words such as farty pants
|
| 1151 | 4836 | acydburn | $row['post_subject'] = censor_text($row['post_subject']); |
| 1152 | 4836 | acydburn | $message = str_replace("\n", '<br />', censor_text($message)); |
| 1153 | 2997 | psotfx | |
| 1154 | 3856 | ludovic_arnaud | // Editing information
|
| 1155 | 4767 | acydburn | if (($row['post_edit_count'] && $config['display_last_edited']) || $row['post_edit_reason']) |
| 1156 | 3856 | ludovic_arnaud | {
|
| 1157 | 4767 | acydburn | // Get usernames for all following posts if not already stored
|
| 1158 | 4767 | acydburn | if (!sizeof($post_edit_list) && $row['post_edit_reason']) |
| 1159 | 4767 | acydburn | {
|
| 1160 | 4767 | acydburn | // Remove all post_ids already parsed (we do not have to check them)
|
| 1161 | 5068 | acydburn | $post_storage_list = (!$store_reverse) ? array_slice($post_list, $i) : array_slice(array_reverse($post_list), $i); |
| 1162 | 4767 | acydburn | |
| 1163 | 4947 | psotfx | $sql = 'SELECT DISTINCT u.user_id, u.username, u.user_colour |
| 1164 | 4767 | acydburn | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
| 1165 | 4767 | acydburn | WHERE p.post_id IN (' . implode(', ', $post_storage_list) . ") |
| 1166 | 4767 | acydburn | AND p.post_edit_count <> 0 |
| 1167 | 4767 | acydburn | AND p.post_edit_user <> 0 |
| 1168 | 4767 | acydburn | AND p.post_edit_reason <> '' |
| 1169 | 4767 | acydburn | AND p.post_edit_user = u.user_id";
|
| 1170 | 4767 | acydburn | $result2 = $db->sql_query($sql); |
| 1171 | 4767 | acydburn | while ($user_edit_row = $db->sql_fetchrow($result2)) |
| 1172 | 4767 | acydburn | {
|
| 1173 | 4767 | acydburn | $post_edit_list[$user_edit_row['user_id']] = $user_edit_row; |
| 1174 | 4767 | acydburn | } |
| 1175 | 4767 | acydburn | $db->sql_freeresult($result2); |
| 1176 | 4947 | psotfx | |
| 1177 | 4767 | acydburn | unset($post_storage_list); |
| 1178 | 4767 | acydburn | } |
| 1179 | 5078 | psotfx | |
| 1180 | 4005 | acydburn | $l_edit_time_total = ($row['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL']; |
| 1181 | 3357 | psotfx | |
| 1182 | 5027 | acydburn | if ($row['post_edit_reason']) |
| 1183 | 5027 | acydburn | {
|
| 1184 | 5027 | acydburn | $user_edit_row = $post_edit_list[$row['post_edit_user']]; |
| 1185 | 5027 | acydburn | $l_edited_by = sprintf($l_edit_time_total, (!$row['post_edit_user']) ? $row['poster'] : (($user_edit_row['user_colour']) ? '<span style="color:#' . $user_edit_row['user_colour'] . '">' . $user_edit_row['username'] . '</span>' : $user_edit_row['username']), $user->format_date($row['post_edit_time']), $row['post_edit_count']); |
| 1186 | 5027 | acydburn | } |
| 1187 | 5027 | acydburn | else
|
| 1188 | 5027 | acydburn | {
|
| 1189 | 5027 | acydburn | $l_edited_by = sprintf($l_edit_time_total, (!$row['post_edit_user']) ? $row['poster'] : $user_cache[$row['post_edit_user']]['username'], $user->format_date($row['post_edit_time']), $row['post_edit_count']); |
| 1190 | 5027 | acydburn | } |
| 1191 | 3856 | ludovic_arnaud | } |
| 1192 | 3856 | ludovic_arnaud | else
|
| 1193 | 3856 | ludovic_arnaud | {
|
| 1194 | 3856 | ludovic_arnaud | $l_edited_by = ''; |
| 1195 | 3856 | ludovic_arnaud | } |
| 1196 | 2448 | psotfx | |
| 1197 | 4634 | acydburn | // Bump information
|
| 1198 | 4634 | acydburn | if ($topic_bumped && $row['post_id'] == $topic_last_post_id) |
| 1199 | 4634 | acydburn | {
|
| 1200 | 4947 | psotfx | // It is safe to grab the username from the user cache array, we are at the last
|
| 1201 | 4634 | acydburn | // post and only the topic poster and last poster are allowed to bump
|
| 1202 | 4634 | acydburn | $l_bumped_by = '<br /><br />' . sprintf($user->lang['BUMPED_BY'], $user_cache[$topic_bumper]['username'], $user->format_date($topic_last_post_time)); |
| 1203 | 4634 | acydburn | } |
| 1204 | 4634 | acydburn | else
|
| 1205 | 4634 | acydburn | {
|
| 1206 | 4634 | acydburn | $l_bumped_by = ''; |
| 1207 | 4634 | acydburn | } |
| 1208 | 4634 | acydburn | |
| 1209 | 4984 | acydburn | $cp_row = array(); |
| 1210 | 4818 | acydburn | |
| 1211 | 4984 | acydburn | //
|
| 1212 | 4984 | acydburn | if ($config['load_cpf_viewtopic']) |
| 1213 | 4892 | acydburn | {
|
| 1214 | 4892 | acydburn | $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array(); |
| 1215 | 4892 | acydburn | } |
| 1216 | 4892 | acydburn | |
| 1217 | 4984 | acydburn | //
|
| 1218 | 4892 | acydburn | $postrow = array( |
| 1219 | 3868 | ludovic_arnaud | 'POSTER_NAME' => $row['poster'], |
| 1220 | 3856 | ludovic_arnaud | 'POSTER_RANK' => $user_cache[$poster_id]['rank_title'], |
| 1221 | 3856 | ludovic_arnaud | 'RANK_IMAGE' => $user_cache[$poster_id]['rank_image'], |
| 1222 | 3856 | ludovic_arnaud | 'POSTER_JOINED' => $user_cache[$poster_id]['joined'], |
| 1223 | 3856 | ludovic_arnaud | 'POSTER_POSTS' => $user_cache[$poster_id]['posts'], |
| 1224 | 3856 | ludovic_arnaud | 'POSTER_FROM' => $user_cache[$poster_id]['from'], |
| 1225 | 3856 | ludovic_arnaud | 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'], |
| 1226 | 3920 | psotfx | |
| 1227 | 3876 | ludovic_arnaud | 'POST_DATE' => $user->format_date($row['post_time']), |
| 1228 | 3869 | psotfx | 'POST_SUBJECT' => $row['post_subject'], |
| 1229 | 3856 | ludovic_arnaud | 'MESSAGE' => $message, |
| 1230 | 4161 | ludovic_arnaud | 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '', |
| 1231 | 3856 | ludovic_arnaud | 'EDITED_MESSAGE'=> $l_edited_by, |
| 1232 | 4767 | acydburn | 'EDIT_REASON' => $row['post_edit_reason'], |
| 1233 | 4634 | acydburn | 'BUMPED_MESSAGE'=> $l_bumped_by, |
| 1234 | 884 | psotfx | |
| 1235 | 5118 | acydburn | 'MINI_POST_IMG' => ($user->data['is_registered'] && $row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read) ? $user->img('icon_post_new', 'NEW_POST') : $user->img('icon_post', 'POST'), |
| 1236 | 5118 | acydburn | 'POST_ICON_IMG' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['img'] : '', |
| 1237 | 5118 | acydburn | 'POST_ICON_IMG_WIDTH' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '', |
| 1238 | 5118 | acydburn | 'POST_ICON_IMG_HEIGHT' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '', |
| 1239 | 4051 | psotfx | 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'], |
| 1240 | 4947 | psotfx | 'ONLINE_IMG' => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? '' : (($user_cache[$poster_id]['online']) ? $user->img('btn_online', 'ONLINE') : $user->img('btn_offline', 'OFFLINE')), |
| 1241 | 2708 | psotfx | |
| 1242 | 4167 | psotfx | 'U_EDIT' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? "posting.$phpEx$SID&mode=edit&f=$forum_id&p=" . $row['post_id'] : '', |
| 1243 | 4947 | psotfx | 'U_QUOTE' => ($auth->acl_get('f_quote', $forum_id)) ? "posting.$phpEx$SID&mode=quote&f=$forum_id&p=" . $row['post_id'] : '', |
| 1244 | 4981 | acydburn | 'U_INFO' => ($auth->acl_get('m_', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '', |
| 1245 | 4178 | acydburn | 'U_DELETE' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_delete', $forum_id) && $topic_data['topic_last_post_id'] == $row['post_id'] && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_delete', $forum_id)) ? "posting.$phpEx$SID&mode=delete&f=$forum_id&p=" . $row['post_id'] : '', |
| 1246 | 2708 | psotfx | |
| 1247 | 4051 | psotfx | 'U_PROFILE' => $user_cache[$poster_id]['profile'], |
| 1248 | 4051 | psotfx | 'U_SEARCH' => $user_cache[$poster_id]['search'], |
| 1249 | 5247 | acydburn | 'U_PM' => ($poster_id != ANONYMOUS) ? "{$phpbb_root_path}ucp.$phpEx$SID&i=pm&mode=compose&action=quotepost&p=" . $row['post_id'] : '', |
| 1250 | 4051 | psotfx | 'U_EMAIL' => $user_cache[$poster_id]['email'], |
| 1251 | 4051 | psotfx | 'U_WWW' => $user_cache[$poster_id]['www'], |
| 1252 | 4051 | psotfx | 'U_ICQ' => $user_cache[$poster_id]['icq'], |
| 1253 | 4051 | psotfx | 'U_AIM' => $user_cache[$poster_id]['aim'], |
| 1254 | 4051 | psotfx | 'U_MSN' => $user_cache[$poster_id]['msn'], |
| 1255 | 4051 | psotfx | 'U_YIM' => $user_cache[$poster_id]['yim'], |
| 1256 | 4947 | psotfx | 'U_JABBER' => $user_cache[$poster_id]['jabber'], |
| 1257 | 3357 | psotfx | |
| 1258 | 4051 | psotfx | 'U_REPORT' => "report.$phpEx$SID&p=" . $row['post_id'], |
| 1259 | 4912 | acydburn | 'U_MCP_REPORT' => ($auth->acl_gets('m_', 'a_', 'f_report', $forum_id)) ? "mcp.$phpEx$SID&mode=post_details&p=" . $row['post_id'] : '', |
| 1260 | 4937 | acydburn | 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? "mcp.$phpEx$SID&i=queue&mode=approve&post_id_list[]=" . $row['post_id'] : '', |
| 1261 | 4051 | psotfx | 'U_MINI_POST' => "viewtopic.$phpEx$SID&p=" . $row['post_id'] . '#' . $row['post_id'], |
| 1262 | 4947 | psotfx | 'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$i + 1])) ? $rowset[$i + 1]['post_id'] : '', |
| 1263 | 4947 | psotfx | 'U_PREV_POST_ID' => $prev_post_id, |
| 1264 | 2708 | psotfx | |
| 1265 | 4964 | acydburn | 'POST_ID' => $row['post_id'], |
| 1266 | 4964 | acydburn | |
| 1267 | 3868 | ludovic_arnaud | 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? TRUE : FALSE, |
| 1268 | 3856 | ludovic_arnaud | 'S_POST_UNAPPROVED' => ($row['post_approved']) ? FALSE : TRUE, |
| 1269 | 4139 | acydburn | 'S_POST_REPORTED' => ($row['post_reported'] && $auth->acl_get('m_', $forum_id)) ? TRUE : FALSE, |
| 1270 | 4947 | psotfx | 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'], |
| 1271 | 4964 | acydburn | 'S_FRIEND' => ($row['friend']) ? true : false, |
| 1272 | 5117 | acydburn | 'S_UNREAD_POST' => ($user->data['is_registered'] && $row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read) ? true : false, |
| 1273 | 4984 | acydburn | 'S_FIRST_UNREAD' => ($unread_post_id == $row['post_id']) ? true : false, |
| 1274 | 5137 | acydburn | 'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false |
| 1275 | 3869 | psotfx | ); |
| 1276 | 2708 | psotfx | |
| 1277 | 5137 | acydburn | if (isset($cp_row['row']) && sizeof($cp_row['row'])) |
| 1278 | 4892 | acydburn | {
|
| 1279 | 5137 | acydburn | $postrow = array_merge($postrow, $cp_row['row']); |
| 1280 | 4984 | acydburn | } |
| 1281 | 4892 | acydburn | |
| 1282 | 4984 | acydburn | // Dump vars into template
|
| 1283 | 4892 | acydburn | $template->assign_block_vars('postrow', $postrow); |
| 1284 | 4947 | psotfx | |
| 1285 | 5137 | acydburn | if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow'])) |
| 1286 | 5137 | acydburn | {
|
| 1287 | 5137 | acydburn | foreach ($cp_row['blockrow'] as $field_data) |
| 1288 | 5137 | acydburn | {
|
| 1289 | 5137 | acydburn | $template->assign_block_vars('postrow.custom_fields', $field_data); |
| 1290 | 5137 | acydburn | } |
| 1291 | 5137 | acydburn | } |
| 1292 | 5137 | acydburn | |
| 1293 | 4818 | acydburn | // Display not already displayed Attachments for this post, we already parsed them. ;)
|
| 1294 | 4892 | acydburn | if (isset($attachments[$row['post_id']]) && sizeof($attachments[$row['post_id']])) |
| 1295 | 3856 | ludovic_arnaud | {
|
| 1296 | 4818 | acydburn | foreach ($attachments[$row['post_id']] as $attachment) |
| 1297 | 4818 | acydburn | {
|
| 1298 | 4818 | acydburn | $template->assign_block_vars('postrow.attachment', array( |
| 1299 | 4920 | acydburn | 'DISPLAY_ATTACHMENT' => $attachment) |
| 1300 | 4818 | acydburn | ); |
| 1301 | 4818 | acydburn | } |
| 1302 | 2714 | psotfx | } |
| 1303 | 3868 | ludovic_arnaud | |
| 1304 | 4473 | psotfx | $prev_post_id = $row['post_id']; |
| 1305 | 4473 | psotfx | |
| 1306 | 4161 | ludovic_arnaud | unset($rowset[$i]); |
| 1307 | 3868 | ludovic_arnaud | unset($attachments[$row['post_id']]); |
| 1308 | 81 | thefinn | } |
| 1309 | 3856 | ludovic_arnaud | unset($rowset); |
| 1310 | 3856 | ludovic_arnaud | unset($user_cache); |
| 1311 | 82 | thefinn | |
| 1312 | 3961 | psotfx | // Update topic view and if necessary attachment view counters ... but only
|
| 1313 | 3961 | psotfx | // if this is the first 'page view'
|
| 1314 | 5024 | acydburn | if (isset($user->data['session_page']) && !preg_match("#&t=$topic_id#", $user->data['session_page'])) |
| 1315 | 3286 | psotfx | {
|
| 1316 | 4167 | psotfx | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 1317 | 4167 | psotfx | SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . " |
| 1318 | 3856 | ludovic_arnaud | WHERE topic_id = $topic_id"; |
| 1319 | 3807 | acydburn | $db->sql_query($sql); |
| 1320 | 3961 | psotfx | |
| 1321 | 3961 | psotfx | // Update the attachment download counts
|
| 1322 | 4167 | psotfx | if (sizeof($update_count)) |
| 1323 | 3961 | psotfx | {
|
| 1324 | 4947 | psotfx | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' |
| 1325 | 4947 | psotfx | SET download_count = download_count + 1 |
| 1326 | 4051 | psotfx | WHERE attach_id IN (' . implode(', ', array_unique($update_count)) . ')'; |
| 1327 | 3961 | psotfx | $db->sql_query($sql); |
| 1328 | 3961 | psotfx | } |
| 1329 | 3286 | psotfx | } |
| 1330 | 3286 | psotfx | |
| 1331 | 3953 | psotfx | // Mark topics read
|
| 1332 | 4167 | psotfx | $mark_forum_id = ($topic_type == POST_GLOBAL) ? 0 : $forum_id; |
| 1333 | 4167 | psotfx | markread('topic', $mark_forum_id, $topic_id, $row['post_time']); |
| 1334 | 3953 | psotfx | |
| 1335 | 3538 | psotfx | // Change encoding if appropriate
|
| 1336 | 3538 | psotfx | if ($force_encoding != '') |
| 1337 | 3538 | psotfx | {
|
| 1338 | 3538 | psotfx | $user->lang['ENCODING'] = $force_encoding; |
| 1339 | 3538 | psotfx | } |
| 1340 | 3538 | psotfx | |
| 1341 | 2995 | psotfx | // Output the page
|
| 1342 | 3969 | psotfx | page_header($user->lang['VIEW_TOPIC'] .' - ' . $topic_title); |
| 1343 | 2995 | psotfx | |
| 1344 | 2995 | psotfx | $template->set_filenames(array( |
| 1345 | 4473 | psotfx | 'body' => ($view == 'print') ? 'viewtopic_print.html' : 'viewtopic_body.html') |
| 1346 | 2995 | psotfx | ); |
| 1347 | 2995 | psotfx | make_jumpbox('viewforum.'.$phpEx, $forum_id); |
| 1348 | 2995 | psotfx | |
| 1349 | 3969 | psotfx | page_footer(); |
| 1350 | 81 | thefinn | |
| 1351 | 5137 | acydburn | |
| 1352 | 5137 | acydburn | // FUNCTIONS
|
| 1353 | 5137 | acydburn | |
| 1354 | 5137 | acydburn | function get_topic_last_read($topic_id, $forum_id) |
| 1355 | 5137 | acydburn | {
|
| 1356 | 5137 | acydburn | global $config, $user, $db; |
| 1357 | 5137 | acydburn | |
| 1358 | 5137 | acydburn | $topic_last_read = 0; |
| 1359 | 5137 | acydburn | |
| 1360 | 5137 | acydburn | if ($config['load_db_lastread']) |
| 1361 | 5137 | acydburn | {
|
| 1362 | 5137 | acydburn | $sql = 'SELECT mark_time |
| 1363 | 5137 | acydburn | FROM ' . TOPICS_TRACK_TABLE . ' |
| 1364 | 5137 | acydburn | WHERE user_id = ' . $user->data['user_id'] . " |
| 1365 | 5137 | acydburn | AND topic_id = $topic_id"; |
| 1366 | 5140 | acydburn | $result = $db->sql_query($sql); |
| 1367 | 5137 | acydburn | $row = $db->sql_fetchrow($result); |
| 1368 | 5137 | acydburn | $db->sql_freeresult($result); |
| 1369 | 5137 | acydburn | |
| 1370 | 5137 | acydburn | $topic_last_read = ($row) ? min($row['mark_time'], $user->data['session_last_visit']) : $user->data['session_last_visit']; |
| 1371 | 5137 | acydburn | |
| 1372 | 5137 | acydburn | if (!$row) |
| 1373 | 5137 | acydburn | {
|
| 1374 | 5137 | acydburn | $sql = 'SELECT mark_time |
| 1375 | 5137 | acydburn | FROM ' . FORUMS_TRACK_TABLE . ' |
| 1376 | 5137 | acydburn | WHERE user_id = ' . $user->data['user_id'] . " |
| 1377 | 5137 | acydburn | AND forum_id = $forum_id"; |
| 1378 | 5137 | acydburn | $result = $db->sql_query($sql); |
| 1379 | 5137 | acydburn | $forum_mark_time = (int) $db->sql_fetchfield('mark_time', 0, $result); |
| 1380 | 5137 | acydburn | $db->sql_freeresult($result); |
| 1381 | 5137 | acydburn | |
| 1382 | 5137 | acydburn | $topic_last_read = ($forum_mark_time) ? min($topic_last_read, $forum_mark_time) : $topic_last_read; |
| 1383 | 5137 | acydburn | } |
| 1384 | 5137 | acydburn | } |
| 1385 | 5137 | acydburn | else
|
| 1386 | 5137 | acydburn | {
|
| 1387 | 5137 | acydburn | $topic_last_read = 0; |
| 1388 | 5137 | acydburn | if (isset($_COOKIE[$config['cookie_name'] . '_track'])) |
| 1389 | 5137 | acydburn | {
|
| 1390 | 5137 | acydburn | $tracking_topics = unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])); |
| 1391 | 5137 | acydburn | if (isset($tracking_topics[$forum_id])) |
| 1392 | 5137 | acydburn | {
|
| 1393 | 5137 | acydburn | $topic_last_read = base_convert(max($tracking_topics[$forum_id]), 36, 10); |
| 1394 | 5137 | acydburn | $topic_last_read = max($topic_last_read, $user->data['session_last_visit']); |
| 1395 | 5137 | acydburn | } |
| 1396 | 5137 | acydburn | unset($tracking_topics); |
| 1397 | 5137 | acydburn | } |
| 1398 | 5137 | acydburn | } |
| 1399 | 5137 | acydburn | |
| 1400 | 5137 | acydburn | return $topic_last_read; |
| 1401 | 5137 | acydburn | } |
| 1402 | 5137 | acydburn | |
| 1403 | 3286 | psotfx | ?> |

