root / trunk / phpBB / includes / functions_posting.php
History | View | Annotate | Download (79.8 kB)
| 1 | 2666 | psotfx | <?php
|
|---|---|---|---|
| 2 | 8146 | acydburn | /**
|
| 3 | 5114 | acydburn | * |
| 4 | 5114 | acydburn | * @package phpBB3 |
| 5 | 8146 | acydburn | * @copyright (c) 2005 phpBB Group |
| 6 | 11653 | git-gate | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
| 7 | 5114 | acydburn | * |
| 8 | 5114 | acydburn | */ |
| 9 | 2666 | psotfx | |
| 10 | 5114 | acydburn | /**
|
| 11 | 8146 | acydburn | * @ignore |
| 12 | 8146 | acydburn | */ |
| 13 | 8146 | acydburn | if (!defined('IN_PHPBB')) |
| 14 | 8146 | acydburn | {
|
| 15 | 8146 | acydburn | exit;
|
| 16 | 8146 | acydburn | } |
| 17 | 8146 | acydburn | |
| 18 | 8146 | acydburn | /**
|
| 19 | 6915 | acydburn | * Fill smiley templates (or just the variables) with smilies, either in a window or inline |
| 20 | 5114 | acydburn | */ |
| 21 | 4544 | acydburn | function generate_smilies($mode, $forum_id) |
| 22 | 2923 | psotfx | {
|
| 23 | 11131 | git-gate | global $db, $user, $config, $template; |
| 24 | 4544 | acydburn | global $phpEx, $phpbb_root_path; |
| 25 | 2923 | psotfx | |
| 26 | 9764 | acydburn | $start = request_var('start', 0); |
| 27 | 9764 | acydburn | |
| 28 | 3013 | psotfx | if ($mode == 'window') |
| 29 | 2923 | psotfx | {
|
| 30 | 4883 | acydburn | if ($forum_id) |
| 31 | 4544 | acydburn | {
|
| 32 | 4883 | acydburn | $sql = 'SELECT forum_style |
| 33 | 4883 | acydburn | FROM ' . FORUMS_TABLE . " |
| 34 | 4883 | acydburn | WHERE forum_id = $forum_id"; |
| 35 | 4883 | acydburn | $result = $db->sql_query_limit($sql, 1); |
| 36 | 4883 | acydburn | $row = $db->sql_fetchrow($result); |
| 37 | 4883 | acydburn | $db->sql_freeresult($result); |
| 38 | 8253 | kellanved | |
| 39 | 4883 | acydburn | $user->setup('posting', (int) $row['forum_style']); |
| 40 | 4544 | acydburn | } |
| 41 | 4883 | acydburn | else
|
| 42 | 4883 | acydburn | {
|
| 43 | 4883 | acydburn | $user->setup('posting'); |
| 44 | 4883 | acydburn | } |
| 45 | 4440 | psotfx | |
| 46 | 5109 | acydburn | page_header($user->lang['SMILIES']); |
| 47 | 9764 | acydburn | |
| 48 | 10558 | git-gate | $sql = 'SELECT COUNT(smiley_id) AS item_count |
| 49 | 9763 | aptx | FROM ' . SMILIES_TABLE . ' |
| 50 | 9763 | aptx | GROUP BY smiley_url';
|
| 51 | 9763 | aptx | $result = $db->sql_query($sql, 3600); |
| 52 | 9764 | acydburn | |
| 53 | 9763 | aptx | $smiley_count = 0; |
| 54 | 9763 | aptx | while ($row = $db->sql_fetchrow($result)) |
| 55 | 9763 | aptx | {
|
| 56 | 9763 | aptx | ++$smiley_count;
|
| 57 | 9763 | aptx | } |
| 58 | 9763 | aptx | $db->sql_freeresult($result); |
| 59 | 2923 | psotfx | |
| 60 | 2923 | psotfx | $template->set_filenames(array( |
| 61 | 2986 | psotfx | 'body' => 'posting_smilies.html') |
| 62 | 2923 | psotfx | ); |
| 63 | 9764 | acydburn | |
| 64 | 9763 | aptx | $template->assign_var('PAGINATION', |
| 65 | 9763 | aptx | generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), |
| 66 | 9764 | acydburn | $smiley_count, $config['smilies_per_page'], $start, true) |
| 67 | 9764 | acydburn | ); |
| 68 | 2923 | psotfx | } |
| 69 | 2923 | psotfx | |
| 70 | 4767 | acydburn | $display_link = false; |
| 71 | 4544 | acydburn | if ($mode == 'inline') |
| 72 | 4544 | acydburn | {
|
| 73 | 5109 | acydburn | $sql = 'SELECT smiley_id |
| 74 | 4549 | acydburn | FROM ' . SMILIES_TABLE . ' |
| 75 | 4550 | acydburn | WHERE display_on_posting = 0';
|
| 76 | 4544 | acydburn | $result = $db->sql_query_limit($sql, 1, 0, 3600); |
| 77 | 4578 | psotfx | |
| 78 | 4550 | acydburn | if ($row = $db->sql_fetchrow($result)) |
| 79 | 4550 | acydburn | {
|
| 80 | 4767 | acydburn | $display_link = true; |
| 81 | 4550 | acydburn | } |
| 82 | 4578 | psotfx | $db->sql_freeresult($result); |
| 83 | 4544 | acydburn | } |
| 84 | 4544 | acydburn | |
| 85 | 9763 | aptx | if ($mode == 'window') |
| 86 | 9763 | aptx | {
|
| 87 | 10558 | git-gate | $sql = 'SELECT smiley_url, MIN(emotion) as emotion, MIN(code) AS code, smiley_width, smiley_height, MIN(smiley_order) AS min_smiley_order |
| 88 | 9763 | aptx | FROM ' . SMILIES_TABLE . ' |
| 89 | 9764 | acydburn | GROUP BY smiley_url, smiley_width, smiley_height |
| 90 | 10558 | git-gate | ORDER BY min_smiley_order';
|
| 91 | 9764 | acydburn | $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $start, 3600); |
| 92 | 9763 | aptx | } |
| 93 | 9763 | aptx | else
|
| 94 | 9763 | aptx | {
|
| 95 | 9763 | aptx | $sql = 'SELECT * |
| 96 | 9763 | aptx | FROM ' . SMILIES_TABLE . ' |
| 97 | 9763 | aptx | WHERE display_on_posting = 1 |
| 98 | 9763 | aptx | ORDER BY smiley_order';
|
| 99 | 9763 | aptx | $result = $db->sql_query($sql, 3600); |
| 100 | 9763 | aptx | } |
| 101 | 2923 | psotfx | |
| 102 | 7614 | acydburn | $smilies = array(); |
| 103 | 4550 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 104 | 2923 | psotfx | {
|
| 105 | 7614 | acydburn | if (empty($smilies[$row['smiley_url']])) |
| 106 | 5832 | davidmj | {
|
| 107 | 7614 | acydburn | $smilies[$row['smiley_url']] = $row; |
| 108 | 7614 | acydburn | } |
| 109 | 7614 | acydburn | } |
| 110 | 7614 | acydburn | $db->sql_freeresult($result); |
| 111 | 7614 | acydburn | |
| 112 | 7614 | acydburn | if (sizeof($smilies)) |
| 113 | 7614 | acydburn | {
|
| 114 | 10008 | acydburn | $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; |
| 115 | 10008 | acydburn | |
| 116 | 7614 | acydburn | foreach ($smilies as $row) |
| 117 | 7614 | acydburn | {
|
| 118 | 5832 | davidmj | $template->assign_block_vars('smiley', array( |
| 119 | 5888 | naderman | 'SMILEY_CODE' => $row['code'], |
| 120 | 5888 | naderman | 'A_SMILEY_CODE' => addslashes($row['code']), |
| 121 | 10008 | acydburn | 'SMILEY_IMG' => $root_path . $config['smilies_path'] . '/' . $row['smiley_url'], |
| 122 | 5888 | naderman | 'SMILEY_WIDTH' => $row['smiley_width'], |
| 123 | 5888 | naderman | 'SMILEY_HEIGHT' => $row['smiley_height'], |
| 124 | 5888 | naderman | 'SMILEY_DESC' => $row['emotion']) |
| 125 | 5832 | davidmj | ); |
| 126 | 5832 | davidmj | } |
| 127 | 2923 | psotfx | } |
| 128 | 2923 | psotfx | |
| 129 | 4550 | acydburn | if ($mode == 'inline' && $display_link) |
| 130 | 4550 | acydburn | {
|
| 131 | 4550 | acydburn | $template->assign_vars(array( |
| 132 | 5109 | acydburn | 'S_SHOW_SMILEY_LINK' => true, |
| 133 | 6015 | acydburn | 'U_MORE_SMILIES' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id)) |
| 134 | 4550 | acydburn | ); |
| 135 | 4550 | acydburn | } |
| 136 | 4550 | acydburn | |
| 137 | 2986 | psotfx | if ($mode == 'window') |
| 138 | 2923 | psotfx | {
|
| 139 | 4057 | acydburn | page_footer(); |
| 140 | 2923 | psotfx | } |
| 141 | 2923 | psotfx | } |
| 142 | 2923 | psotfx | |
| 143 | 5114 | acydburn | /**
|
| 144 | 6787 | acydburn | * Update last post information |
| 145 | 6650 | acydburn | * Should be used instead of sync() if only the last post information are out of sync... faster |
| 146 | 5902 | acydburn | * |
| 147 | 7355 | naderman | * @param string $type Can be forum|topic |
| 148 | 7355 | naderman | * @param mixed $ids topic/forum ids |
| 149 | 7355 | naderman | * @param bool $return_update_sql true: SQL query shall be returned, false: execute SQL |
| 150 | 5114 | acydburn | */ |
| 151 | 7507 | davidmj | function update_post_information($type, $ids, $return_update_sql = false) |
| 152 | 3887 | acydburn | {
|
| 153 | 3887 | acydburn | global $db; |
| 154 | 3887 | acydburn | |
| 155 | 7800 | kellanved | if (empty($ids)) |
| 156 | 7800 | kellanved | {
|
| 157 | 7800 | kellanved | return;
|
| 158 | 7800 | kellanved | } |
| 159 | 5486 | acydburn | if (!is_array($ids)) |
| 160 | 5486 | acydburn | {
|
| 161 | 5486 | acydburn | $ids = array($ids); |
| 162 | 5486 | acydburn | } |
| 163 | 4573 | acydburn | |
| 164 | 7800 | kellanved | |
| 165 | 6511 | acydburn | $update_sql = $empty_forums = $not_empty_forums = array(); |
| 166 | 5088 | acydburn | |
| 167 | 7191 | naderman | if ($type != 'topic') |
| 168 | 7191 | naderman | {
|
| 169 | 7191 | naderman | $topic_join = ', ' . TOPICS_TABLE . ' t'; |
| 170 | 7191 | naderman | $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1'; |
| 171 | 7191 | naderman | } |
| 172 | 7191 | naderman | else
|
| 173 | 7191 | naderman | {
|
| 174 | 7191 | naderman | $topic_join = ''; |
| 175 | 7191 | naderman | $topic_condition = ''; |
| 176 | 7191 | naderman | } |
| 177 | 7191 | naderman | |
| 178 | 6364 | acydburn | if (sizeof($ids) == 1) |
| 179 | 6364 | acydburn | {
|
| 180 | 7191 | naderman | $sql = 'SELECT MAX(p.post_id) as last_post_id |
| 181 | 7191 | naderman | FROM ' . POSTS_TABLE . " p $topic_join |
| 182 | 7191 | naderman | WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " |
| 183 | 7191 | naderman | $topic_condition |
| 184 | 7518 | davidmj | AND p.post_approved = 1";
|
| 185 | 6364 | acydburn | } |
| 186 | 6364 | acydburn | else
|
| 187 | 6364 | acydburn | {
|
| 188 | 7191 | naderman | $sql = 'SELECT p.' . $type . '_id, MAX(p.post_id) as last_post_id |
| 189 | 7191 | naderman | FROM ' . POSTS_TABLE . " p $topic_join |
| 190 | 7191 | naderman | WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " |
| 191 | 7191 | naderman | $topic_condition |
| 192 | 7191 | naderman | AND p.post_approved = 1 |
| 193 | 7191 | naderman | GROUP BY p.{$type}_id"; |
| 194 | 6364 | acydburn | } |
| 195 | 4676 | acydburn | $result = $db->sql_query($sql); |
| 196 | 3887 | acydburn | |
| 197 | 5486 | acydburn | $last_post_ids = array(); |
| 198 | 5486 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 199 | 4477 | acydburn | {
|
| 200 | 6364 | acydburn | if (sizeof($ids) == 1) |
| 201 | 6364 | acydburn | {
|
| 202 | 6364 | acydburn | $row[$type . '_id'] = $ids[0]; |
| 203 | 6364 | acydburn | } |
| 204 | 6364 | acydburn | |
| 205 | 5486 | acydburn | if ($type == 'forum') |
| 206 | 5486 | acydburn | {
|
| 207 | 6511 | acydburn | $not_empty_forums[] = $row['forum_id']; |
| 208 | 6511 | acydburn | |
| 209 | 6511 | acydburn | if (empty($row['last_post_id'])) |
| 210 | 6511 | acydburn | {
|
| 211 | 6511 | acydburn | $empty_forums[] = $row['forum_id']; |
| 212 | 6511 | acydburn | } |
| 213 | 5486 | acydburn | } |
| 214 | 5486 | acydburn | |
| 215 | 5486 | acydburn | $last_post_ids[] = $row['last_post_id']; |
| 216 | 5486 | acydburn | } |
| 217 | 5486 | acydburn | $db->sql_freeresult($result); |
| 218 | 5486 | acydburn | |
| 219 | 5486 | acydburn | if ($type == 'forum') |
| 220 | 5486 | acydburn | {
|
| 221 | 6511 | acydburn | $empty_forums = array_merge($empty_forums, array_diff($ids, $not_empty_forums)); |
| 222 | 5486 | acydburn | |
| 223 | 5486 | acydburn | foreach ($empty_forums as $void => $forum_id) |
| 224 | 5486 | acydburn | {
|
| 225 | 5486 | acydburn | $update_sql[$forum_id][] = 'forum_last_post_id = 0'; |
| 226 | 6360 | grahamje | $update_sql[$forum_id][] = "forum_last_post_subject = ''"; |
| 227 | 6311 | grahamje | $update_sql[$forum_id][] = 'forum_last_post_time = 0'; |
| 228 | 5486 | acydburn | $update_sql[$forum_id][] = 'forum_last_poster_id = 0'; |
| 229 | 5486 | acydburn | $update_sql[$forum_id][] = "forum_last_poster_name = ''"; |
| 230 | 6311 | grahamje | $update_sql[$forum_id][] = "forum_last_poster_colour = ''"; |
| 231 | 5486 | acydburn | } |
| 232 | 5486 | acydburn | } |
| 233 | 5486 | acydburn | |
| 234 | 5486 | acydburn | if (sizeof($last_post_ids)) |
| 235 | 5486 | acydburn | {
|
| 236 | 6360 | grahamje | $sql = 'SELECT p.' . $type . '_id, p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour |
| 237 | 4676 | acydburn | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
| 238 | 4676 | acydburn | WHERE p.poster_id = u.user_id |
| 239 | 6271 | acydburn | AND ' . $db->sql_in_set('p.post_id', $last_post_ids); |
| 240 | 4676 | acydburn | $result = $db->sql_query($sql); |
| 241 | 5486 | acydburn | |
| 242 | 5486 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 243 | 5486 | acydburn | {
|
| 244 | 5486 | acydburn | $update_sql[$row["{$type}_id"]][] = $type . '_last_post_id = ' . (int) $row['post_id']; |
| 245 | 6360 | grahamje | $update_sql[$row["{$type}_id"]][] = "{$type}_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; |
| 246 | 5486 | acydburn | $update_sql[$row["{$type}_id"]][] = $type . '_last_post_time = ' . (int) $row['post_time']; |
| 247 | 5486 | acydburn | $update_sql[$row["{$type}_id"]][] = $type . '_last_poster_id = ' . (int) $row['poster_id']; |
| 248 | 6311 | grahamje | $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; |
| 249 | 5486 | acydburn | $update_sql[$row["{$type}_id"]][] = "{$type}_last_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; |
| 250 | 5486 | acydburn | } |
| 251 | 4676 | acydburn | $db->sql_freeresult($result); |
| 252 | 5486 | acydburn | } |
| 253 | 5486 | acydburn | unset($empty_forums, $ids, $last_post_ids); |
| 254 | 4676 | acydburn | |
| 255 | 5902 | acydburn | if ($return_update_sql || !sizeof($update_sql)) |
| 256 | 5486 | acydburn | {
|
| 257 | 5902 | acydburn | return $update_sql; |
| 258 | 4477 | acydburn | } |
| 259 | 5486 | acydburn | |
| 260 | 5486 | acydburn | $table = ($type == 'forum') ? FORUMS_TABLE : TOPICS_TABLE; |
| 261 | 5486 | acydburn | |
| 262 | 5486 | acydburn | foreach ($update_sql as $update_id => $update_sql_ary) |
| 263 | 4477 | acydburn | {
|
| 264 | 5486 | acydburn | $sql = "UPDATE $table |
| 265 | 5486 | acydburn | SET " . implode(', ', $update_sql_ary) . " |
| 266 | 5486 | acydburn | WHERE {$type}_id = $update_id"; |
| 267 | 5486 | acydburn | $db->sql_query($sql); |
| 268 | 4477 | acydburn | } |
| 269 | 5967 | acydburn | |
| 270 | 5967 | acydburn | return;
|
| 271 | 3887 | acydburn | } |
| 272 | 3887 | acydburn | |
| 273 | 5114 | acydburn | /**
|
| 274 | 5902 | acydburn | * Generate Topic Icons for display |
| 275 | 5902 | acydburn | */ |
| 276 | 5902 | acydburn | function posting_gen_topic_icons($mode, $icon_id) |
| 277 | 5902 | acydburn | {
|
| 278 | 5902 | acydburn | global $phpbb_root_path, $config, $template, $cache; |
| 279 | 5902 | acydburn | |
| 280 | 5902 | acydburn | // Grab icons
|
| 281 | 6572 | acydburn | $icons = $cache->obtain_icons(); |
| 282 | 5902 | acydburn | |
| 283 | 5902 | acydburn | if (!$icon_id) |
| 284 | 5902 | acydburn | {
|
| 285 | 5902 | acydburn | $template->assign_var('S_NO_ICON_CHECKED', ' checked="checked"'); |
| 286 | 5902 | acydburn | } |
| 287 | 6015 | acydburn | |
| 288 | 5902 | acydburn | if (sizeof($icons)) |
| 289 | 5902 | acydburn | {
|
| 290 | 5902 | acydburn | foreach ($icons as $id => $data) |
| 291 | 5902 | acydburn | {
|
| 292 | 5902 | acydburn | if ($data['display']) |
| 293 | 5902 | acydburn | {
|
| 294 | 5902 | acydburn | $template->assign_block_vars('topic_icon', array( |
| 295 | 5902 | acydburn | 'ICON_ID' => $id, |
| 296 | 5902 | acydburn | 'ICON_IMG' => $phpbb_root_path . $config['icons_path'] . '/' . $data['img'], |
| 297 | 5902 | acydburn | 'ICON_WIDTH' => $data['width'], |
| 298 | 6015 | acydburn | 'ICON_HEIGHT' => $data['height'], |
| 299 | 8350 | acydburn | |
| 300 | 5902 | acydburn | 'S_CHECKED' => ($id == $icon_id) ? true : false, |
| 301 | 5902 | acydburn | 'S_ICON_CHECKED' => ($id == $icon_id) ? ' checked="checked"' : '') |
| 302 | 5902 | acydburn | ); |
| 303 | 5902 | acydburn | } |
| 304 | 5902 | acydburn | } |
| 305 | 5902 | acydburn | |
| 306 | 5902 | acydburn | return true; |
| 307 | 5902 | acydburn | } |
| 308 | 5902 | acydburn | |
| 309 | 5902 | acydburn | return false; |
| 310 | 5902 | acydburn | } |
| 311 | 5902 | acydburn | |
| 312 | 5902 | acydburn | /**
|
| 313 | 5902 | acydburn | * Build topic types able to be selected |
| 314 | 5902 | acydburn | */ |
| 315 | 5902 | acydburn | function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL) |
| 316 | 5902 | acydburn | {
|
| 317 | 5902 | acydburn | global $auth, $user, $template, $topic_type; |
| 318 | 5902 | acydburn | |
| 319 | 5902 | acydburn | $toggle = false; |
| 320 | 5902 | acydburn | |
| 321 | 5902 | acydburn | $topic_types = array( |
| 322 | 5902 | acydburn | 'sticky' => array('const' => POST_STICKY, 'lang' => 'POST_STICKY'), |
| 323 | 5902 | acydburn | 'announce' => array('const' => POST_ANNOUNCE, 'lang' => 'POST_ANNOUNCEMENT'), |
| 324 | 5902 | acydburn | 'global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL') |
| 325 | 5902 | acydburn | ); |
| 326 | 6015 | acydburn | |
| 327 | 5902 | acydburn | $topic_type_array = array(); |
| 328 | 6015 | acydburn | |
| 329 | 5902 | acydburn | foreach ($topic_types as $auth_key => $topic_value) |
| 330 | 5902 | acydburn | {
|
| 331 | 5902 | acydburn | // We do not have a special post global announcement permission
|
| 332 | 5902 | acydburn | $auth_key = ($auth_key == 'global') ? 'announce' : $auth_key; |
| 333 | 5902 | acydburn | |
| 334 | 5902 | acydburn | if ($auth->acl_get('f_' . $auth_key, $forum_id)) |
| 335 | 5902 | acydburn | {
|
| 336 | 5902 | acydburn | $toggle = true; |
| 337 | 5902 | acydburn | |
| 338 | 5902 | acydburn | $topic_type_array[] = array( |
| 339 | 5902 | acydburn | 'VALUE' => $topic_value['const'], |
| 340 | 11100 | git-gate | 'S_CHECKED' => ($cur_topic_type == $topic_value['const']) ? ' checked="checked"' : '', |
| 341 | 5902 | acydburn | 'L_TOPIC_TYPE' => $user->lang[$topic_value['lang']] |
| 342 | 5902 | acydburn | ); |
| 343 | 5902 | acydburn | } |
| 344 | 5902 | acydburn | } |
| 345 | 5902 | acydburn | |
| 346 | 5902 | acydburn | if ($toggle) |
| 347 | 5902 | acydburn | {
|
| 348 | 5902 | acydburn | $topic_type_array = array_merge(array(0 => array( |
| 349 | 5902 | acydburn | 'VALUE' => POST_NORMAL, |
| 350 | 10640 | git-gate | 'S_CHECKED' => ($cur_topic_type == POST_NORMAL) ? ' checked="checked"' : '', |
| 351 | 8146 | acydburn | 'L_TOPIC_TYPE' => $user->lang['POST_NORMAL'])), |
| 352 | 6015 | acydburn | |
| 353 | 5902 | acydburn | $topic_type_array
|
| 354 | 5902 | acydburn | ); |
| 355 | 8350 | acydburn | |
| 356 | 5902 | acydburn | foreach ($topic_type_array as $array) |
| 357 | 5902 | acydburn | {
|
| 358 | 5902 | acydburn | $template->assign_block_vars('topic_type', $array); |
| 359 | 5902 | acydburn | } |
| 360 | 5902 | acydburn | |
| 361 | 5902 | acydburn | $template->assign_vars(array( |
| 362 | 5902 | acydburn | 'S_TOPIC_TYPE_STICKY' => ($auth->acl_get('f_sticky', $forum_id)), |
| 363 | 5902 | acydburn | 'S_TOPIC_TYPE_ANNOUNCE' => ($auth->acl_get('f_announce', $forum_id))) |
| 364 | 5902 | acydburn | ); |
| 365 | 5902 | acydburn | } |
| 366 | 5902 | acydburn | |
| 367 | 5902 | acydburn | return $toggle; |
| 368 | 5902 | acydburn | } |
| 369 | 5902 | acydburn | |
| 370 | 5902 | acydburn | //
|
| 371 | 5902 | acydburn | // Attachment related functions
|
| 372 | 5902 | acydburn | //
|
| 373 | 5902 | acydburn | |
| 374 | 5902 | acydburn | /**
|
| 375 | 5114 | acydburn | * Upload Attachment - filedata is generated here |
| 376 | 5114 | acydburn | * Uses upload class |
| 377 | 5114 | acydburn | */ |
| 378 | 6977 | acydburn | function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false) |
| 379 | 3697 | acydburn | {
|
| 380 | 5241 | acydburn | global $auth, $user, $config, $db, $cache; |
| 381 | 6015 | acydburn | global $phpbb_root_path, $phpEx; |
| 382 | 3697 | acydburn | |
| 383 | 5902 | acydburn | $filedata = array( |
| 384 | 5902 | acydburn | 'error' => array() |
| 385 | 5902 | acydburn | ); |
| 386 | 3697 | acydburn | |
| 387 | 6015 | acydburn | include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); |
| 388 | 5109 | acydburn | $upload = new fileupload(); |
| 389 | 6015 | acydburn | |
| 390 | 10922 | git-gate | if ($config['check_attachment_content'] && isset($config['mime_triggers'])) |
| 391 | 8555 | Kellanved | {
|
| 392 | 8555 | Kellanved | $upload->set_disallowed_content(explode('|', $config['mime_triggers'])); |
| 393 | 8555 | Kellanved | } |
| 394 | 8667 | acydburn | |
| 395 | 5140 | acydburn | if (!$local) |
| 396 | 5140 | acydburn | {
|
| 397 | 5140 | acydburn | $filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false; |
| 398 | 5140 | acydburn | } |
| 399 | 5140 | acydburn | else
|
| 400 | 5140 | acydburn | {
|
| 401 | 5140 | acydburn | $filedata['post_attach'] = true; |
| 402 | 5140 | acydburn | } |
| 403 | 5109 | acydburn | |
| 404 | 3697 | acydburn | if (!$filedata['post_attach']) |
| 405 | 3697 | acydburn | {
|
| 406 | 6364 | acydburn | $filedata['error'][] = $user->lang['NO_UPLOAD_FORM_FOUND']; |
| 407 | 3898 | acydburn | return $filedata; |
| 408 | 3697 | acydburn | } |
| 409 | 3697 | acydburn | |
| 410 | 6816 | acydburn | $extensions = $cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id)); |
| 411 | 5109 | acydburn | $upload->set_allowed_extensions(array_keys($extensions['_allowed_'])); |
| 412 | 3697 | acydburn | |
| 413 | 6977 | acydburn | $file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name); |
| 414 | 5032 | acydburn | |
| 415 | 5109 | acydburn | if ($file->init_error) |
| 416 | 5032 | acydburn | {
|
| 417 | 5032 | acydburn | $filedata['post_attach'] = false; |
| 418 | 5032 | acydburn | return $filedata; |
| 419 | 5032 | acydburn | } |
| 420 | 5032 | acydburn | |
| 421 | 5109 | acydburn | $cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE; |
| 422 | 5032 | acydburn | |
| 423 | 6364 | acydburn | // Make sure the image category only holds valid images...
|
| 424 | 6364 | acydburn | if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) |
| 425 | 6364 | acydburn | {
|
| 426 | 6364 | acydburn | $file->remove();
|
| 427 | 6364 | acydburn | |
| 428 | 6364 | acydburn | // If this error occurs a user tried to exploit an IE Bug by renaming extensions
|
| 429 | 6364 | acydburn | // Since the image category is displaying content inline we need to catch this.
|
| 430 | 6973 | acydburn | trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']); |
| 431 | 6364 | acydburn | } |
| 432 | 6364 | acydburn | |
| 433 | 5109 | acydburn | // Do we have to create a thumbnail?
|
| 434 | 5109 | acydburn | $filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0; |
| 435 | 5032 | acydburn | |
| 436 | 3697 | acydburn | // Check Image Size, if it is an image
|
| 437 | 6046 | naderman | if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id) && $cat_id == ATTACHMENT_CATEGORY_IMAGE) |
| 438 | 3697 | acydburn | {
|
| 439 | 6601 | acydburn | $file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']); |
| 440 | 3697 | acydburn | } |
| 441 | 4005 | acydburn | |
| 442 | 6165 | acydburn | // Admins and mods are allowed to exceed the allowed filesize
|
| 443 | 6046 | naderman | if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) |
| 444 | 3697 | acydburn | {
|
| 445 | 6165 | acydburn | if (!empty($extensions[$file->get('extension')]['max_filesize'])) |
| 446 | 6165 | acydburn | {
|
| 447 | 6165 | acydburn | $allowed_filesize = $extensions[$file->get('extension')]['max_filesize']; |
| 448 | 6165 | acydburn | } |
| 449 | 6165 | acydburn | else
|
| 450 | 6165 | acydburn | {
|
| 451 | 6165 | acydburn | $allowed_filesize = ($is_message) ? $config['max_filesize_pm'] : $config['max_filesize']; |
| 452 | 6165 | acydburn | } |
| 453 | 6165 | acydburn | |
| 454 | 5109 | acydburn | $file->upload->set_max_filesize($allowed_filesize); |
| 455 | 5109 | acydburn | } |
| 456 | 6015 | acydburn | |
| 457 | 5109 | acydburn | $file->clean_filename('unique', $user->data['user_id'] . '_'); |
| 458 | 6015 | acydburn | |
| 459 | 7616 | acydburn | // Are we uploading an image *and* this image being within the image category? Only then perform additional image checks.
|
| 460 | 7616 | acydburn | $no_image = ($cat_id == ATTACHMENT_CATEGORY_IMAGE) ? false : true; |
| 461 | 7616 | acydburn | |
| 462 | 7616 | acydburn | $file->move_file($config['upload_path'], false, $no_image); |
| 463 | 7616 | acydburn | |
| 464 | 5109 | acydburn | if (sizeof($file->error)) |
| 465 | 5109 | acydburn | {
|
| 466 | 5109 | acydburn | $file->remove();
|
| 467 | 5109 | acydburn | $filedata['error'] = array_merge($filedata['error'], $file->error); |
| 468 | 4767 | acydburn | $filedata['post_attach'] = false; |
| 469 | 5032 | acydburn | |
| 470 | 3898 | acydburn | return $filedata; |
| 471 | 3697 | acydburn | } |
| 472 | 3697 | acydburn | |
| 473 | 5109 | acydburn | $filedata['filesize'] = $file->get('filesize'); |
| 474 | 5109 | acydburn | $filedata['mimetype'] = $file->get('mimetype'); |
| 475 | 5109 | acydburn | $filedata['extension'] = $file->get('extension'); |
| 476 | 5109 | acydburn | $filedata['physical_filename'] = $file->get('realname'); |
| 477 | 5109 | acydburn | $filedata['real_filename'] = $file->get('uploadname'); |
| 478 | 5109 | acydburn | $filedata['filetime'] = time(); |
| 479 | 5109 | acydburn | |
| 480 | 3697 | acydburn | // Check our complete quota
|
| 481 | 4668 | acydburn | if ($config['attachment_quota']) |
| 482 | 3697 | acydburn | {
|
| 483 | 5109 | acydburn | if ($config['upload_dir_size'] + $file->get('filesize') > $config['attachment_quota']) |
| 484 | 3697 | acydburn | {
|
| 485 | 4005 | acydburn | $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED']; |
| 486 | 4767 | acydburn | $filedata['post_attach'] = false; |
| 487 | 5032 | acydburn | |
| 488 | 5109 | acydburn | $file->remove();
|
| 489 | 5032 | acydburn | |
| 490 | 3898 | acydburn | return $filedata; |
| 491 | 3697 | acydburn | } |
| 492 | 3697 | acydburn | } |
| 493 | 3697 | acydburn | |
| 494 | 5114 | acydburn | // Check free disk space
|
| 495 | 5114 | acydburn | if ($free_space = @disk_free_space($phpbb_root_path . $config['upload_path'])) |
| 496 | 4668 | acydburn | {
|
| 497 | 5109 | acydburn | if ($free_space <= $file->get('filesize')) |
| 498 | 4668 | acydburn | {
|
| 499 | 4668 | acydburn | $filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED']; |
| 500 | 4767 | acydburn | $filedata['post_attach'] = false; |
| 501 | 5032 | acydburn | |
| 502 | 5109 | acydburn | $file->remove();
|
| 503 | 6015 | acydburn | |
| 504 | 4668 | acydburn | return $filedata; |
| 505 | 4668 | acydburn | } |
| 506 | 4668 | acydburn | } |
| 507 | 4668 | acydburn | |
| 508 | 5109 | acydburn | // Create Thumbnail
|
| 509 | 4160 | acydburn | if ($filedata['thumbnail']) |
| 510 | 3697 | acydburn | {
|
| 511 | 5109 | acydburn | $source = $file->get('destination_file'); |
| 512 | 5109 | acydburn | $destination = $file->get('destination_path') . '/thumb_' . $file->get('realname'); |
| 513 | 3697 | acydburn | |
| 514 | 5109 | acydburn | if (!create_thumbnail($source, $destination, $file->get('mimetype'))) |
| 515 | 3697 | acydburn | {
|
| 516 | 5109 | acydburn | $filedata['thumbnail'] = 0; |
| 517 | 3697 | acydburn | } |
| 518 | 4160 | acydburn | } |
| 519 | 4440 | psotfx | |
| 520 | 5109 | acydburn | return $filedata; |
| 521 | 3697 | acydburn | } |
| 522 | 3697 | acydburn | |
| 523 | 5114 | acydburn | /**
|
| 524 | 5114 | acydburn | * Calculate the needed size for Thumbnail |
| 525 | 5114 | acydburn | */ |
| 526 | 4160 | acydburn | function get_img_size_format($width, $height) |
| 527 | 4160 | acydburn | {
|
| 528 | 6320 | acydburn | global $config; |
| 529 | 6320 | acydburn | |
| 530 | 4920 | acydburn | // Maximum Width the Image can take
|
| 531 | 6320 | acydburn | $max_width = ($config['img_max_thumb_width']) ? $config['img_max_thumb_width'] : 400; |
| 532 | 4160 | acydburn | |
| 533 | 4920 | acydburn | if ($width > $height) |
| 534 | 4160 | acydburn | {
|
| 535 | 4920 | acydburn | return array( |
| 536 | 4920 | acydburn | round($width * ($max_width / $width)), |
| 537 | 4920 | acydburn | round($height * ($max_width / $width)) |
| 538 | 4920 | acydburn | ); |
| 539 | 6015 | acydburn | } |
| 540 | 6015 | acydburn | else
|
| 541 | 4160 | acydburn | {
|
| 542 | 4920 | acydburn | return array( |
| 543 | 4920 | acydburn | round($width * ($max_width / $height)), |
| 544 | 4920 | acydburn | round($height * ($max_width / $height)) |
| 545 | 4920 | acydburn | ); |
| 546 | 4160 | acydburn | } |
| 547 | 4160 | acydburn | } |
| 548 | 4160 | acydburn | |
| 549 | 5114 | acydburn | /**
|
| 550 | 5114 | acydburn | * Return supported image types |
| 551 | 5114 | acydburn | */ |
| 552 | 5039 | acydburn | function get_supported_image_types($type = false) |
| 553 | 4160 | acydburn | {
|
| 554 | 4160 | acydburn | if (@extension_loaded('gd')) |
| 555 | 4160 | acydburn | {
|
| 556 | 4920 | acydburn | $format = imagetypes();
|
| 557 | 4920 | acydburn | $new_type = 0; |
| 558 | 4920 | acydburn | |
| 559 | 5039 | acydburn | if ($type !== false) |
| 560 | 4160 | acydburn | {
|
| 561 | 8517 | acydburn | // Type is one of the IMAGETYPE constants - it is fetched from getimagesize()
|
| 562 | 5039 | acydburn | switch ($type) |
| 563 | 5039 | acydburn | {
|
| 564 | 6016 | acydburn | // GIF
|
| 565 | 10778 | git-gate | case IMAGETYPE_GIF: |
| 566 | 6016 | acydburn | $new_type = ($format & IMG_GIF) ? IMG_GIF : false; |
| 567 | 5902 | acydburn | break;
|
| 568 | 5902 | acydburn | |
| 569 | 6016 | acydburn | // JPG, JPC, JP2
|
| 570 | 10778 | git-gate | case IMAGETYPE_JPEG: |
| 571 | 10778 | git-gate | case IMAGETYPE_JPC: |
| 572 | 10778 | git-gate | case IMAGETYPE_JPEG2000: |
| 573 | 10778 | git-gate | case IMAGETYPE_JP2: |
| 574 | 10778 | git-gate | case IMAGETYPE_JPX: |
| 575 | 10778 | git-gate | case IMAGETYPE_JB2: |
| 576 | 6016 | acydburn | $new_type = ($format & IMG_JPG) ? IMG_JPG : false; |
| 577 | 5902 | acydburn | break;
|
| 578 | 6015 | acydburn | |
| 579 | 6016 | acydburn | // PNG
|
| 580 | 10778 | git-gate | case IMAGETYPE_PNG: |
| 581 | 6016 | acydburn | $new_type = ($format & IMG_PNG) ? IMG_PNG : false; |
| 582 | 5902 | acydburn | break;
|
| 583 | 6015 | acydburn | |
| 584 | 8517 | acydburn | // WBMP
|
| 585 | 10778 | git-gate | case IMAGETYPE_WBMP: |
| 586 | 6016 | acydburn | $new_type = ($format & IMG_WBMP) ? IMG_WBMP : false; |
| 587 | 5902 | acydburn | break;
|
| 588 | 5039 | acydburn | } |
| 589 | 4160 | acydburn | } |
| 590 | 5039 | acydburn | else
|
| 591 | 5039 | acydburn | {
|
| 592 | 5039 | acydburn | $new_type = array(); |
| 593 | 5039 | acydburn | $go_through_types = array(IMG_GIF, IMG_JPG, IMG_PNG, IMG_WBMP); |
| 594 | 5039 | acydburn | |
| 595 | 5039 | acydburn | foreach ($go_through_types as $check_type) |
| 596 | 5039 | acydburn | {
|
| 597 | 5039 | acydburn | if ($format & $check_type) |
| 598 | 5039 | acydburn | {
|
| 599 | 5039 | acydburn | $new_type[] = $check_type; |
| 600 | 5039 | acydburn | } |
| 601 | 5039 | acydburn | } |
| 602 | 5039 | acydburn | } |
| 603 | 6015 | acydburn | |
| 604 | 4920 | acydburn | return array( |
| 605 | 4920 | acydburn | 'gd' => ($new_type) ? true : false, |
| 606 | 4920 | acydburn | 'format' => $new_type, |
| 607 | 4920 | acydburn | 'version' => (function_exists('imagecreatetruecolor')) ? 2 : 1 |
| 608 | 4920 | acydburn | ); |
| 609 | 4920 | acydburn | } |
| 610 | 4920 | acydburn | |
| 611 | 4920 | acydburn | return array('gd' => false); |
| 612 | 4160 | acydburn | } |
| 613 | 4160 | acydburn | |
| 614 | 5114 | acydburn | /**
|
| 615 | 5114 | acydburn | * Create Thumbnail |
| 616 | 5114 | acydburn | */ |
| 617 | 8146 | acydburn | function create_thumbnail($source, $destination, $mimetype) |
| 618 | 4160 | acydburn | {
|
| 619 | 4160 | acydburn | global $config; |
| 620 | 4160 | acydburn | |
| 621 | 4175 | acydburn | $min_filesize = (int) $config['img_min_thumb_filesize']; |
| 622 | 4767 | acydburn | $img_filesize = (file_exists($source)) ? @filesize($source) : false; |
| 623 | 4160 | acydburn | |
| 624 | 4175 | acydburn | if (!$img_filesize || $img_filesize <= $min_filesize) |
| 625 | 4160 | acydburn | {
|
| 626 | 4767 | acydburn | return false; |
| 627 | 4160 | acydburn | } |
| 628 | 5902 | acydburn | |
| 629 | 7646 | acydburn | $dimension = @getimagesize($source); |
| 630 | 4160 | acydburn | |
| 631 | 7150 | acydburn | if ($dimension === false) |
| 632 | 4160 | acydburn | {
|
| 633 | 4767 | acydburn | return false; |
| 634 | 4160 | acydburn | } |
| 635 | 4160 | acydburn | |
| 636 | 7150 | acydburn | list($width, $height, $type, ) = $dimension; |
| 637 | 7150 | acydburn | |
| 638 | 7503 | acydburn | if (empty($width) || empty($height)) |
| 639 | 7150 | acydburn | {
|
| 640 | 7150 | acydburn | return false; |
| 641 | 7150 | acydburn | } |
| 642 | 7150 | acydburn | |
| 643 | 4920 | acydburn | list($new_width, $new_height) = get_img_size_format($width, $height); |
| 644 | 4160 | acydburn | |
| 645 | 6601 | acydburn | // Do not create a thumbnail if the resulting width/height is bigger than the original one
|
| 646 | 9462 | acydburn | if ($new_width >= $width && $new_height >= $height) |
| 647 | 6601 | acydburn | {
|
| 648 | 6601 | acydburn | return false; |
| 649 | 6601 | acydburn | } |
| 650 | 6601 | acydburn | |
| 651 | 4767 | acydburn | $used_imagick = false; |
| 652 | 4160 | acydburn | |
| 653 | 6135 | acydburn | // Only use imagemagick if defined and the passthru function not disabled
|
| 654 | 6135 | acydburn | if ($config['img_imagick'] && function_exists('passthru')) |
| 655 | 4160 | acydburn | {
|
| 656 | 8314 | acydburn | if (substr($config['img_imagick'], -1) !== '/') |
| 657 | 8310 | acydburn | {
|
| 658 | 8314 | acydburn | $config['img_imagick'] .= '/'; |
| 659 | 8310 | acydburn | } |
| 660 | 8310 | acydburn | |
| 661 | 9372 | acydburn | @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"'); |
| 662 | 6317 | acydburn | |
| 663 | 5109 | acydburn | if (file_exists($destination)) |
| 664 | 4160 | acydburn | {
|
| 665 | 4920 | acydburn | $used_imagick = true; |
| 666 | 4160 | acydburn | } |
| 667 | 5902 | acydburn | } |
| 668 | 4160 | acydburn | |
| 669 | 8146 | acydburn | if (!$used_imagick) |
| 670 | 4160 | acydburn | {
|
| 671 | 4920 | acydburn | $type = get_supported_image_types($type); |
| 672 | 5902 | acydburn | |
| 673 | 4920 | acydburn | if ($type['gd']) |
| 674 | 4160 | acydburn | {
|
| 675 | 6016 | acydburn | // If the type is not supported, we are not able to create a thumbnail
|
| 676 | 6016 | acydburn | if ($type['format'] === false) |
| 677 | 6016 | acydburn | {
|
| 678 | 6016 | acydburn | return false; |
| 679 | 6016 | acydburn | } |
| 680 | 6016 | acydburn | |
| 681 | 8146 | acydburn | switch ($type['format']) |
| 682 | 4160 | acydburn | {
|
| 683 | 4920 | acydburn | case IMG_GIF: |
| 684 | 6016 | acydburn | $image = @imagecreatefromgif($source); |
| 685 | 5902 | acydburn | break;
|
| 686 | 5902 | acydburn | |
| 687 | 4920 | acydburn | case IMG_JPG: |
| 688 | 9904 | rxu | @ini_set('gd.jpeg_ignore_warning', 1); |
| 689 | 6016 | acydburn | $image = @imagecreatefromjpeg($source); |
| 690 | 5902 | acydburn | break;
|
| 691 | 6015 | acydburn | |
| 692 | 4920 | acydburn | case IMG_PNG: |
| 693 | 6016 | acydburn | $image = @imagecreatefrompng($source); |
| 694 | 5902 | acydburn | break;
|
| 695 | 6015 | acydburn | |
| 696 | 4920 | acydburn | case IMG_WBMP: |
| 697 | 6016 | acydburn | $image = @imagecreatefromwbmp($source); |
| 698 | 5902 | acydburn | break;
|
| 699 | 4920 | acydburn | } |
| 700 | 4920 | acydburn | |
| 701 | 9899 | bantu | if (empty($image)) |
| 702 | 9899 | bantu | {
|
| 703 | 9899 | bantu | return false; |
| 704 | 9899 | bantu | } |
| 705 | 9899 | bantu | |
| 706 | 4920 | acydburn | if ($type['version'] == 1) |
| 707 | 4920 | acydburn | {
|
| 708 | 4920 | acydburn | $new_image = imagecreate($new_width, $new_height); |
| 709 | 8011 | acydburn | |
| 710 | 8011 | acydburn | if ($new_image === false) |
| 711 | 8011 | acydburn | {
|
| 712 | 8011 | acydburn | return false; |
| 713 | 8011 | acydburn | } |
| 714 | 8011 | acydburn | |
| 715 | 4920 | acydburn | imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
| 716 | 4920 | acydburn | } |
| 717 | 4920 | acydburn | else
|
| 718 | 4920 | acydburn | {
|
| 719 | 4920 | acydburn | $new_image = imagecreatetruecolor($new_width, $new_height); |
| 720 | 8011 | acydburn | |
| 721 | 8011 | acydburn | if ($new_image === false) |
| 722 | 8011 | acydburn | {
|
| 723 | 8011 | acydburn | return false; |
| 724 | 8011 | acydburn | } |
| 725 | 8011 | acydburn | |
| 726 | 8864 | acydburn | // Preserve alpha transparency (png for example)
|
| 727 | 8864 | acydburn | @imagealphablending($new_image, false); |
| 728 | 8864 | acydburn | @imagesavealpha($new_image, true); |
| 729 | 8864 | acydburn | |
| 730 | 4920 | acydburn | imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
| 731 | 4920 | acydburn | } |
| 732 | 6015 | acydburn | |
| 733 | 6232 | acydburn | // If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
|
| 734 | 6232 | acydburn | if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on') |
| 735 | 6232 | acydburn | {
|
| 736 | 6232 | acydburn | @touch($destination); |
| 737 | 6232 | acydburn | } |
| 738 | 6232 | acydburn | |
| 739 | 4920 | acydburn | switch ($type['format']) |
| 740 | 4920 | acydburn | {
|
| 741 | 4920 | acydburn | case IMG_GIF: |
| 742 | 5109 | acydburn | imagegif($new_image, $destination); |
| 743 | 5902 | acydburn | break;
|
| 744 | 6015 | acydburn | |
| 745 | 4920 | acydburn | case IMG_JPG: |
| 746 | 5109 | acydburn | imagejpeg($new_image, $destination, 90); |
| 747 | 5902 | acydburn | break;
|
| 748 | 6015 | acydburn | |
| 749 | 4920 | acydburn | case IMG_PNG: |
| 750 | 5109 | acydburn | imagepng($new_image, $destination); |
| 751 | 5902 | acydburn | break;
|
| 752 | 6015 | acydburn | |
| 753 | 4920 | acydburn | case IMG_WBMP: |
| 754 | 5109 | acydburn | imagewbmp($new_image, $destination); |
| 755 | 5902 | acydburn | break;
|
| 756 | 4160 | acydburn | } |
| 757 | 4920 | acydburn | |
| 758 | 4920 | acydburn | imagedestroy($new_image);
|
| 759 | 4160 | acydburn | } |
| 760 | 6016 | acydburn | else
|
| 761 | 6016 | acydburn | {
|
| 762 | 6016 | acydburn | return false; |
| 763 | 6016 | acydburn | } |
| 764 | 4160 | acydburn | } |
| 765 | 4160 | acydburn | |
| 766 | 5109 | acydburn | if (!file_exists($destination)) |
| 767 | 4160 | acydburn | {
|
| 768 | 4767 | acydburn | return false; |
| 769 | 4160 | acydburn | } |
| 770 | 4160 | acydburn | |
| 771 | 8780 | acydburn | phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE); |
| 772 | 4668 | acydburn | |
| 773 | 4767 | acydburn | return true; |
| 774 | 4160 | acydburn | } |
| 775 | 4160 | acydburn | |
| 776 | 5114 | acydburn | /**
|
| 777 | 5114 | acydburn | * Assign Inline attachments (build option fields) |
| 778 | 5114 | acydburn | */ |
| 779 | 4984 | acydburn | function posting_gen_inline_attachments(&$attachment_data) |
| 780 | 4883 | acydburn | {
|
| 781 | 4883 | acydburn | global $template; |
| 782 | 4883 | acydburn | |
| 783 | 4978 | acydburn | if (sizeof($attachment_data)) |
| 784 | 4883 | acydburn | {
|
| 785 | 4883 | acydburn | $s_inline_attachment_options = ''; |
| 786 | 6015 | acydburn | |
| 787 | 4978 | acydburn | foreach ($attachment_data as $i => $attachment) |
| 788 | 4883 | acydburn | {
|
| 789 | 9905 | acydburn | $s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>'; |
| 790 | 4883 | acydburn | } |
| 791 | 4883 | acydburn | |
| 792 | 4883 | acydburn | $template->assign_var('S_INLINE_ATTACHMENT_OPTIONS', $s_inline_attachment_options); |
| 793 | 4883 | acydburn | |
| 794 | 4883 | acydburn | return true; |
| 795 | 4883 | acydburn | } |
| 796 | 4883 | acydburn | |
| 797 | 4883 | acydburn | return false; |
| 798 | 4883 | acydburn | } |
| 799 | 4883 | acydburn | |
| 800 | 5114 | acydburn | /**
|
| 801 | 5114 | acydburn | * Generate inline attachment entry |
| 802 | 5114 | acydburn | */ |
| 803 | 8976 | acydburn | function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true) |
| 804 | 4883 | acydburn | {
|
| 805 | 11131 | git-gate | global $template, $config, $phpbb_root_path, $phpEx, $user; |
| 806 | 6015 | acydburn | |
| 807 | 8976 | acydburn | // Some default template variables
|
| 808 | 4883 | acydburn | $template->assign_vars(array( |
| 809 | 8976 | acydburn | 'S_SHOW_ATTACH_BOX' => $show_attach_box, |
| 810 | 8976 | acydburn | 'S_HAS_ATTACHMENTS' => sizeof($attachment_data), |
| 811 | 8976 | acydburn | 'FILESIZE' => $config['max_filesize'], |
| 812 | 8976 | acydburn | 'FILE_COMMENT' => (isset($filename_data['filecomment'])) ? $filename_data['filecomment'] : '', |
| 813 | 8976 | acydburn | )); |
| 814 | 4883 | acydburn | |
| 815 | 4978 | acydburn | if (sizeof($attachment_data)) |
| 816 | 4883 | acydburn | {
|
| 817 | 6628 | acydburn | // We display the posted attachments within the desired order.
|
| 818 | 6628 | acydburn | ($config['display_order']) ? krsort($attachment_data) : ksort($attachment_data); |
| 819 | 6628 | acydburn | |
| 820 | 6628 | acydburn | foreach ($attachment_data as $count => $attach_row) |
| 821 | 4883 | acydburn | {
|
| 822 | 4883 | acydburn | $hidden = ''; |
| 823 | 9905 | acydburn | $attach_row['real_filename'] = utf8_basename($attach_row['real_filename']); |
| 824 | 4883 | acydburn | |
| 825 | 4883 | acydburn | foreach ($attach_row as $key => $value) |
| 826 | 4883 | acydburn | {
|
| 827 | 4883 | acydburn | $hidden .= '<input type="hidden" name="attachment_data[' . $count . '][' . $key . ']" value="' . $value . '" />'; |
| 828 | 4883 | acydburn | } |
| 829 | 6015 | acydburn | |
| 830 | 8119 | acydburn | $download_link = append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&id=' . (int) $attach_row['attach_id'], true, ($attach_row['is_orphan']) ? $user->session_id : false); |
| 831 | 6015 | acydburn | |
| 832 | 4883 | acydburn | $template->assign_block_vars('attach_row', array( |
| 833 | 9905 | acydburn | 'FILENAME' => utf8_basename($attach_row['real_filename']), |
| 834 | 9905 | acydburn | 'A_FILENAME' => addslashes(utf8_basename($attach_row['real_filename'])), |
| 835 | 6177 | acydburn | 'FILE_COMMENT' => $attach_row['attach_comment'], |
| 836 | 4883 | acydburn | 'ATTACH_ID' => $attach_row['attach_id'], |
| 837 | 6364 | acydburn | 'S_IS_ORPHAN' => $attach_row['is_orphan'], |
| 838 | 4883 | acydburn | 'ASSOC_INDEX' => $count, |
| 839 | 4883 | acydburn | |
| 840 | 5902 | acydburn | 'U_VIEW_ATTACHMENT' => $download_link, |
| 841 | 4883 | acydburn | 'S_HIDDEN' => $hidden) |
| 842 | 4883 | acydburn | ); |
| 843 | 4883 | acydburn | } |
| 844 | 4883 | acydburn | } |
| 845 | 4883 | acydburn | |
| 846 | 4978 | acydburn | return sizeof($attachment_data); |
| 847 | 4883 | acydburn | } |
| 848 | 4883 | acydburn | |
| 849 | 5902 | acydburn | //
|
| 850 | 5902 | acydburn | // General Post functions
|
| 851 | 5902 | acydburn | //
|
| 852 | 5902 | acydburn | |
| 853 | 5114 | acydburn | /**
|
| 854 | 5114 | acydburn | * Load Drafts |
| 855 | 5114 | acydburn | */ |
| 856 | 9685 | nickvergessen | function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $msg_id = 0) |
| 857 | 4883 | acydburn | {
|
| 858 | 5902 | acydburn | global $user, $db, $template, $auth; |
| 859 | 6015 | acydburn | global $phpbb_root_path, $phpEx; |
| 860 | 4883 | acydburn | |
| 861 | 5952 | acydburn | $topic_ids = $forum_ids = $draft_rows = array(); |
| 862 | 5902 | acydburn | |
| 863 | 5470 | acydburn | // Load those drafts not connected to forums/topics
|
| 864 | 5922 | acydburn | // If forum_id == 0 AND topic_id == 0 then this is a PM draft
|
| 865 | 5952 | acydburn | if (!$topic_id && !$forum_id) |
| 866 | 5952 | acydburn | {
|
| 867 | 5957 | acydburn | $sql_and = ' AND d.forum_id = 0 AND d.topic_id = 0'; |
| 868 | 5952 | acydburn | } |
| 869 | 5952 | acydburn | else
|
| 870 | 5952 | acydburn | {
|
| 871 | 5952 | acydburn | $sql_and = ''; |
| 872 | 6015 | acydburn | $sql_and .= ($forum_id) ? ' AND d.forum_id = ' . (int) $forum_id : ''; |
| 873 | 6015 | acydburn | $sql_and .= ($topic_id) ? ' AND d.topic_id = ' . (int) $topic_id : ''; |
| 874 | 5952 | acydburn | } |
| 875 | 5952 | acydburn | |
| 876 | 5952 | acydburn | $sql = 'SELECT d.*, f.forum_id, f.forum_name |
| 877 | 5952 | acydburn | FROM ' . DRAFTS_TABLE . ' d |
| 878 | 5952 | acydburn | LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = d.forum_id) |
| 879 | 5952 | acydburn | WHERE d.user_id = ' . $user->data['user_id'] . " |
| 880 | 5952 | acydburn | $sql_and |
| 881 | 5952 | acydburn | ORDER BY d.save_time DESC";
|
| 882 | 4883 | acydburn | $result = $db->sql_query($sql); |
| 883 | 4883 | acydburn | |
| 884 | 4883 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 885 | 4883 | acydburn | {
|
| 886 | 4883 | acydburn | if ($row['topic_id']) |
| 887 | 4883 | acydburn | {
|
| 888 | 4883 | acydburn | $topic_ids[] = (int) $row['topic_id']; |
| 889 | 4883 | acydburn | } |
| 890 | 5902 | acydburn | $draft_rows[] = $row; |
| 891 | 4883 | acydburn | } |
| 892 | 4883 | acydburn | $db->sql_freeresult($result); |
| 893 | 5470 | acydburn | |
| 894 | 5902 | acydburn | if (!sizeof($draft_rows)) |
| 895 | 5470 | acydburn | {
|
| 896 | 5470 | acydburn | return;
|
| 897 | 5470 | acydburn | } |
| 898 | 5470 | acydburn | |
| 899 | 5902 | acydburn | $topic_rows = array(); |
| 900 | 4883 | acydburn | if (sizeof($topic_ids)) |
| 901 | 4883 | acydburn | {
|
| 902 | 4883 | acydburn | $sql = 'SELECT topic_id, forum_id, topic_title |
| 903 | 4883 | acydburn | FROM ' . TOPICS_TABLE . ' |
| 904 | 6271 | acydburn | WHERE ' . $db->sql_in_set('topic_id', array_unique($topic_ids)); |
| 905 | 4883 | acydburn | $result = $db->sql_query($sql); |
| 906 | 4883 | acydburn | |
| 907 | 4883 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 908 | 4883 | acydburn | {
|
| 909 | 4883 | acydburn | $topic_rows[$row['topic_id']] = $row; |
| 910 | 4883 | acydburn | } |
| 911 | 4883 | acydburn | $db->sql_freeresult($result); |
| 912 | 4883 | acydburn | } |
| 913 | 4883 | acydburn | unset($topic_ids); |
| 914 | 5952 | acydburn | |
| 915 | 5470 | acydburn | $template->assign_var('S_SHOW_DRAFTS', true); |
| 916 | 5470 | acydburn | |
| 917 | 5902 | acydburn | foreach ($draft_rows as $draft) |
| 918 | 4883 | acydburn | {
|
| 919 | 5470 | acydburn | $link_topic = $link_forum = $link_pm = false; |
| 920 | 5470 | acydburn | $insert_url = $view_url = $title = ''; |
| 921 | 4883 | acydburn | |
| 922 | 7615 | acydburn | if (isset($topic_rows[$draft['topic_id']]) |
| 923 | 7615 | acydburn | && ( |
| 924 | 7615 | acydburn | ($topic_rows[$draft['topic_id']]['forum_id'] && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id'])) |
| 925 | 7615 | acydburn | || |
| 926 | 7615 | acydburn | (!$topic_rows[$draft['topic_id']]['forum_id'] && $auth->acl_getf_global('f_read')) |
| 927 | 7615 | acydburn | )) |
| 928 | 4883 | acydburn | {
|
| 929 | 7615 | acydburn | $topic_forum_id = ($topic_rows[$draft['topic_id']]['forum_id']) ? $topic_rows[$draft['topic_id']]['forum_id'] : $forum_id; |
| 930 | 7615 | acydburn | |
| 931 | 5470 | acydburn | $link_topic = true; |
| 932 | 7615 | acydburn | $view_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_forum_id . '&t=' . $draft['topic_id']); |
| 933 | 5470 | acydburn | $title = $topic_rows[$draft['topic_id']]['topic_title']; |
| 934 | 4883 | acydburn | |
| 935 | 7615 | acydburn | $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $topic_forum_id . '&t=' . $draft['topic_id'] . '&mode=reply&d=' . $draft['draft_id']); |
| 936 | 5470 | acydburn | } |
| 937 | 5922 | acydburn | else if ($draft['forum_id'] && $auth->acl_get('f_read', $draft['forum_id'])) |
| 938 | 5470 | acydburn | {
|
| 939 | 5470 | acydburn | $link_forum = true; |
| 940 | 6015 | acydburn | $view_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $draft['forum_id']); |
| 941 | 5470 | acydburn | $title = $draft['forum_name']; |
| 942 | 4883 | acydburn | |
| 943 | 6015 | acydburn | $insert_url = append_sid("{$phpbb_root_path}posting.$phpEx", 'f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']); |
| 944 | 5470 | acydburn | } |
| 945 | 5470 | acydburn | else
|
| 946 | 5470 | acydburn | {
|
| 947 | 5922 | acydburn | // Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
|
| 948 | 5470 | acydburn | $link_pm = true; |
| 949 | 9685 | nickvergessen | $insert_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&d={$draft['draft_id']}" . (($pm_action) ? "&action=$pm_action" : '') . (($msg_id) ? "&p=$msg_id" : '')); |
| 950 | 5470 | acydburn | } |
| 951 | 5902 | acydburn | |
| 952 | 5470 | acydburn | $template->assign_block_vars('draftrow', array( |
| 953 | 5470 | acydburn | 'DRAFT_ID' => $draft['draft_id'], |
| 954 | 5470 | acydburn | 'DATE' => $user->format_date($draft['save_time']), |
| 955 | 5470 | acydburn | 'DRAFT_SUBJECT' => $draft['draft_subject'], |
| 956 | 4883 | acydburn | |
| 957 | 5470 | acydburn | 'TITLE' => $title, |
| 958 | 5470 | acydburn | 'U_VIEW' => $view_url, |
| 959 | 5470 | acydburn | 'U_INSERT' => $insert_url, |
| 960 | 4883 | acydburn | |
| 961 | 5470 | acydburn | 'S_LINK_PM' => $link_pm, |
| 962 | 5470 | acydburn | 'S_LINK_TOPIC' => $link_topic, |
| 963 | 5470 | acydburn | 'S_LINK_FORUM' => $link_forum) |
| 964 | 5470 | acydburn | ); |
| 965 | 4883 | acydburn | } |
| 966 | 4883 | acydburn | } |
| 967 | 4883 | acydburn | |
| 968 | 5114 | acydburn | /**
|
| 969 | 5114 | acydburn | * Topic Review |
| 970 | 5114 | acydburn | */ |
| 971 | 4925 | acydburn | function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true) |
| 972 | 4925 | acydburn | {
|
| 973 | 7642 | acydburn | global $user, $auth, $db, $template, $bbcode, $cache; |
| 974 | 6015 | acydburn | global $config, $phpbb_root_path, $phpEx; |
| 975 | 4925 | acydburn | |
| 976 | 4925 | acydburn | // Go ahead and pull all data for this topic
|
| 977 | 6986 | davidmj | $sql = 'SELECT p.post_id |
| 978 | 6986 | davidmj | FROM ' . POSTS_TABLE . ' p' . " |
| 979 | 4925 | acydburn | WHERE p.topic_id = $topic_id |
| 980 | 4925 | acydburn | " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . ' |
| 981 | 4925 | acydburn | ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' |
| 982 | 9731 | bantu | ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' |
| 983 | 8354 | acydburn | ORDER BY p.post_time ';
|
| 984 | 8350 | acydburn | $sql .= ($mode == 'post_review') ? 'ASC' : 'DESC'; |
| 985 | 4925 | acydburn | $result = $db->sql_query_limit($sql, $config['posts_per_page']); |
| 986 | 4925 | acydburn | |
| 987 | 6986 | davidmj | $post_list = array(); |
| 988 | 6986 | davidmj | |
| 989 | 6986 | davidmj | while ($row = $db->sql_fetchrow($result)) |
| 990 | 4925 | acydburn | {
|
| 991 | 6986 | davidmj | $post_list[] = $row['post_id']; |
| 992 | 6986 | davidmj | } |
| 993 | 6986 | davidmj | |
| 994 | 6986 | davidmj | $db->sql_freeresult($result); |
| 995 | 6986 | davidmj | |
| 996 | 6986 | davidmj | if (!sizeof($post_list)) |
| 997 | 6986 | davidmj | {
|
| 998 | 4925 | acydburn | return false; |
| 999 | 4925 | acydburn | } |
| 1000 | 4925 | acydburn | |
| 1001 | 9731 | bantu | // Handle 'post_review_edit' like 'post_review' from now on
|
| 1002 | 9731 | bantu | if ($mode == 'post_review_edit') |
| 1003 | 9731 | bantu | {
|
| 1004 | 9731 | bantu | $mode = 'post_review'; |
| 1005 | 9731 | bantu | } |
| 1006 | 9731 | bantu | |
| 1007 | 11585 | git-gate | $sql_ary = array( |
| 1008 | 9305 | terrafrost | 'SELECT' => 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe', |
| 1009 | 6986 | davidmj | |
| 1010 | 6986 | davidmj | 'FROM' => array( |
| 1011 | 6986 | davidmj | USERS_TABLE => 'u', |
| 1012 | 6986 | davidmj | POSTS_TABLE => 'p', |
| 1013 | 6986 | davidmj | ), |
| 1014 | 6986 | davidmj | |
| 1015 | 9305 | terrafrost | 'LEFT_JOIN' => array( |
| 1016 | 9305 | terrafrost | array(
|
| 1017 | 9305 | terrafrost | 'FROM' => array(ZEBRA_TABLE => 'z'), |
| 1018 | 11585 | git-gate | 'ON' => 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id', |
| 1019 | 11585 | git-gate | ), |
| 1020 | 9305 | terrafrost | ), |
| 1021 | 9305 | terrafrost | |
| 1022 | 6986 | davidmj | 'WHERE' => $db->sql_in_set('p.post_id', $post_list) . ' |
| 1023 | 11585 | git-gate | AND u.user_id = p.poster_id',
|
| 1024 | 11585 | git-gate | ); |
| 1025 | 6986 | davidmj | |
| 1026 | 11585 | git-gate | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 1027 | 6986 | davidmj | $result = $db->sql_query($sql); |
| 1028 | 6986 | davidmj | |
| 1029 | 6209 | davidmj | $bbcode_bitfield = ''; |
| 1030 | 6987 | davidmj | $rowset = array(); |
| 1031 | 7642 | acydburn | $has_attachments = false; |
| 1032 | 6986 | davidmj | while ($row = $db->sql_fetchrow($result)) |
| 1033 | 4925 | acydburn | {
|
| 1034 | 7103 | davidmj | $rowset[$row['post_id']] = $row; |
| 1035 | 6263 | davidmj | $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); |
| 1036 | 7642 | acydburn | |
| 1037 | 7642 | acydburn | if ($row['post_attachment']) |
| 1038 | 7642 | acydburn | {
|
| 1039 | 7642 | acydburn | $has_attachments = true; |
| 1040 | 7642 | acydburn | } |
| 1041 | 4925 | acydburn | } |
| 1042 | 4925 | acydburn | $db->sql_freeresult($result); |
| 1043 | 4925 | acydburn | |
| 1044 | 4925 | acydburn | // Instantiate BBCode class
|
| 1045 | 6293 | davidmj | if (!isset($bbcode) && $bbcode_bitfield !== '') |
| 1046 | 4925 | acydburn | {
|
| 1047 | 6015 | acydburn | include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); |
| 1048 | 6293 | davidmj | $bbcode = new bbcode(base64_encode($bbcode_bitfield)); |
| 1049 | 4925 | acydburn | } |
| 1050 | 4925 | acydburn | |
| 1051 | 7642 | acydburn | // Grab extensions
|
| 1052 | 7642 | acydburn | $extensions = $attachments = array(); |
| 1053 | 7642 | acydburn | if ($has_attachments && $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id)) |
| 1054 | 7642 | acydburn | {
|
| 1055 | 7642 | acydburn | $extensions = $cache->obtain_attach_extensions($forum_id); |
| 1056 | 7642 | acydburn | |
| 1057 | 7642 | acydburn | // Get attachments...
|
| 1058 | 7642 | acydburn | $sql = 'SELECT * |
| 1059 | 7642 | acydburn | FROM ' . ATTACHMENTS_TABLE . ' |
| 1060 | 7642 | acydburn | WHERE ' . $db->sql_in_set('post_msg_id', $post_list) . ' |
| 1061 | 7642 | acydburn | AND in_message = 0 |
| 1062 | 7642 | acydburn | ORDER BY filetime DESC, post_msg_id ASC';
|
| 1063 | 7642 | acydburn | $result = $db->sql_query($sql); |
| 1064 | 7642 | acydburn | |
| 1065 | 7642 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1066 | 7642 | acydburn | {
|
| 1067 | 7642 | acydburn | $attachments[$row['post_msg_id']][] = $row; |
| 1068 | 7642 | acydburn | } |
| 1069 | 7642 | acydburn | $db->sql_freeresult($result); |
| 1070 | 7642 | acydburn | } |
| 1071 | 7642 | acydburn | |
| 1072 | 7103 | davidmj | for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) |
| 1073 | 4925 | acydburn | {
|
| 1074 | 7103 | davidmj | // A non-existing rowset only happens if there was no user present for the entered poster_id
|
| 1075 | 7103 | davidmj | // This could be a broken posts table.
|
| 1076 | 7103 | davidmj | if (!isset($rowset[$post_list[$i]])) |
| 1077 | 7103 | davidmj | {
|
| 1078 | 7103 | davidmj | continue;
|
| 1079 | 7103 | davidmj | } |
| 1080 | 7103 | davidmj | |
| 1081 | 11361 | git-gate | $row = $rowset[$post_list[$i]]; |
| 1082 | 7103 | davidmj | |
| 1083 | 6589 | acydburn | $poster_id = $row['user_id']; |
| 1084 | 6589 | acydburn | $post_subject = $row['post_subject']; |
| 1085 | 6589 | acydburn | $message = censor_text($row['post_text']); |
| 1086 | 4925 | acydburn | |
| 1087 | 6085 | acydburn | $decoded_message = false; |
| 1088 | 4925 | acydburn | |
| 1089 | 6085 | acydburn | if ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) |
| 1090 | 6085 | acydburn | {
|
| 1091 | 6085 | acydburn | $decoded_message = $message; |
| 1092 | 6085 | acydburn | decode_message($decoded_message, $row['bbcode_uid']); |
| 1093 | 6085 | acydburn | |
| 1094 | 8050 | naderman | $decoded_message = bbcode_nl2br($decoded_message); |
| 1095 | 6085 | acydburn | } |
| 1096 | 6085 | acydburn | |
| 1097 | 4925 | acydburn | if ($row['bbcode_bitfield']) |
| 1098 | 4925 | acydburn | {
|
| 1099 | 4925 | acydburn | $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']); |
| 1100 | 4925 | acydburn | } |
| 1101 | 4925 | acydburn | |
| 1102 | 8050 | naderman | $message = bbcode_nl2br($message); |
| 1103 | 5109 | acydburn | $message = smiley_text($message, !$row['enable_smilies']); |
| 1104 | 4925 | acydburn | |
| 1105 | 7642 | acydburn | if (!empty($attachments[$row['post_id']])) |
| 1106 | 7642 | acydburn | {
|
| 1107 | 7642 | acydburn | $update_count = array(); |
| 1108 | 7642 | acydburn | parse_attachments($forum_id, $message, $attachments[$row['post_id']], $update_count); |
| 1109 | 7642 | acydburn | } |
| 1110 | 7642 | acydburn | |
| 1111 | 4925 | acydburn | $post_subject = censor_text($post_subject); |
| 1112 | 4925 | acydburn | |
| 1113 | 9305 | terrafrost | $post_anchor = ($mode == 'post_review') ? 'ppr' . $row['post_id'] : 'pr' . $row['post_id']; |
| 1114 | 9305 | terrafrost | $u_show_post = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, "f=$forum_id&t=$topic_id&p={$row['post_id']}&view=show#p{$row['post_id']}"); |
| 1115 | 9305 | terrafrost | |
| 1116 | 4925 | acydburn | $template->assign_block_vars($mode . '_row', array( |
| 1117 | 6589 | acydburn | 'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), |
| 1118 | 6589 | acydburn | 'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), |
| 1119 | 6589 | acydburn | 'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), |
| 1120 | 6589 | acydburn | 'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), |
| 1121 | 6589 | acydburn | |
| 1122 | 7642 | acydburn | 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false, |
| 1123 | 9305 | terrafrost | 'S_FRIEND' => ($row['friend']) ? true : false, |
| 1124 | 9305 | terrafrost | 'S_IGNORE_POST' => ($row['foe']) ? true : false, |
| 1125 | 9305 | terrafrost | 'L_IGNORE_POST' => ($row['foe']) ? sprintf($user->lang['POST_BY_FOE'], get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), "<a href=\"{$u_show_post}\" onclick=\"dE('{$post_anchor}', 1); return false;\">", '</a>') : '', |
| 1126 | 7642 | acydburn | |
| 1127 | 6085 | acydburn | 'POST_SUBJECT' => $post_subject, |
| 1128 | 6237 | acydburn | 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']), |
| 1129 | 6085 | acydburn | 'POST_DATE' => $user->format_date($row['post_time']), |
| 1130 | 6321 | naderman | 'MESSAGE' => $message, |
| 1131 | 6085 | acydburn | 'DECODED_MESSAGE' => $decoded_message, |
| 1132 | 7642 | acydburn | 'POST_ID' => $row['post_id'], |
| 1133 | 6085 | acydburn | 'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'], |
| 1134 | 6085 | acydburn | 'U_MCP_DETAILS' => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=post_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '', |
| 1135 | 6596 | acydburn | 'POSTER_QUOTE' => ($show_quote_button && $auth->acl_get('f_reply', $forum_id)) ? addslashes(get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username'])) : '') |
| 1136 | 4925 | acydburn | ); |
| 1137 | 7642 | acydburn | |
| 1138 | 7642 | acydburn | // Display not already displayed Attachments for this post, we already parsed them. ;)
|
| 1139 | 7642 | acydburn | if (!empty($attachments[$row['post_id']])) |
| 1140 | 7642 | acydburn | {
|
| 1141 | 7642 | acydburn | foreach ($attachments[$row['post_id']] as $attachment) |
| 1142 | 7642 | acydburn | {
|
| 1143 | 7642 | acydburn | $template->assign_block_vars($mode . '_row.attachment', array( |
| 1144 | 7642 | acydburn | 'DISPLAY_ATTACHMENT' => $attachment) |
| 1145 | 7642 | acydburn | ); |
| 1146 | 7642 | acydburn | } |
| 1147 | 7642 | acydburn | } |
| 1148 | 7642 | acydburn | |
| 1149 | 10637 | git-gate | unset($rowset[$post_list[$i]]); |
| 1150 | 4925 | acydburn | } |
| 1151 | 4925 | acydburn | |
| 1152 | 4925 | acydburn | if ($mode == 'topic_review') |
| 1153 | 4925 | acydburn | {
|
| 1154 | 6237 | acydburn | $template->assign_var('QUOTE_IMG', $user->img('icon_post_quote', $user->lang['REPLY_WITH_QUOTE'])); |
| 1155 | 4925 | acydburn | } |
| 1156 | 4925 | acydburn | |
| 1157 | 4925 | acydburn | return true; |
| 1158 | 4925 | acydburn | } |
| 1159 | 4925 | acydburn | |
| 1160 | 5114 | acydburn | /**
|
| 1161 | 5114 | acydburn | * User Notification |
| 1162 | 5114 | acydburn | */ |
| 1163 | 4937 | acydburn | function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id) |
| 1164 | 4937 | acydburn | {
|
| 1165 | 4937 | acydburn | global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; |
| 1166 | 4937 | acydburn | |
| 1167 | 6364 | acydburn | $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; |
| 1168 | 6364 | acydburn | $forum_notification = ($mode == 'post') ? true : false; |
| 1169 | 4937 | acydburn | |
| 1170 | 4937 | acydburn | if (!$topic_notification && !$forum_notification) |
| 1171 | 4937 | acydburn | {
|
| 1172 | 9457 | acydburn | trigger_error('NO_MODE'); |
| 1173 | 4937 | acydburn | } |
| 1174 | 4937 | acydburn | |
| 1175 | 8353 | acydburn | if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify'])) |
| 1176 | 5949 | acydburn | {
|
| 1177 | 5949 | acydburn | return;
|
| 1178 | 5949 | acydburn | } |
| 1179 | 5949 | acydburn | |
| 1180 | 4937 | acydburn | $topic_title = ($topic_notification) ? $topic_title : $subject; |
| 1181 | 4937 | acydburn | $topic_title = censor_text($topic_title); |
| 1182 | 4937 | acydburn | |
| 1183 | 4937 | acydburn | // Get banned User ID's
|
| 1184 | 8146 | acydburn | $sql = 'SELECT ban_userid |
| 1185 | 8450 | acydburn | FROM ' . BANLIST_TABLE . ' |
| 1186 | 8450 | acydburn | WHERE ban_userid <> 0 |
| 1187 | 8450 | acydburn | AND ban_exclude <> 1';
|
| 1188 | 4937 | acydburn | $result = $db->sql_query($sql); |
| 1189 | 4937 | acydburn | |
| 1190 | 4937 | acydburn | $sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id']; |
| 1191 | 4937 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1192 | 4937 | acydburn | {
|
| 1193 | 8450 | acydburn | $sql_ignore_users .= ', ' . (int) $row['ban_userid']; |
| 1194 | 4937 | acydburn | } |
| 1195 | 4937 | acydburn | $db->sql_freeresult($result); |
| 1196 | 4937 | acydburn | |
| 1197 | 4937 | acydburn | $notify_rows = array(); |
| 1198 | 4937 | acydburn | |
| 1199 | 4937 | acydburn | // -- get forum_userids || topic_userids
|
| 1200 | 8146 | acydburn | $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber |
| 1201 | 4937 | acydburn | FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u |
| 1202 | 4937 | acydburn | WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . " |
| 1203 | 4937 | acydburn | AND w.user_id NOT IN ($sql_ignore_users) |
| 1204 | 10637 | git-gate | AND w.notify_status = " . NOTIFY_YES . ' |
| 1205 | 10637 | git-gate | AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') |
| 1206 | 5117 | acydburn | AND u.user_id = w.user_id';
|
| 1207 | 4937 | acydburn | $result = $db->sql_query($sql); |
| 1208 | 4937 | acydburn | |
| 1209 | 4937 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1210 | 4937 | acydburn | {
|
| 1211 | 4937 | acydburn | $notify_rows[$row['user_id']] = array( |
| 1212 | 4937 | acydburn | 'user_id' => $row['user_id'], |
| 1213 | 4937 | acydburn | 'username' => $row['username'], |
| 1214 | 4937 | acydburn | 'user_email' => $row['user_email'], |
| 1215 | 8146 | acydburn | 'user_jabber' => $row['user_jabber'], |
| 1216 | 8146 | acydburn | 'user_lang' => $row['user_lang'], |
| 1217 | 4937 | acydburn | 'notify_type' => ($topic_notification) ? 'topic' : 'forum', |
| 1218 | 4937 | acydburn | 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify', |
| 1219 | 8146 | acydburn | 'method' => $row['user_notify_type'], |
| 1220 | 4937 | acydburn | 'allowed' => false |
| 1221 | 4937 | acydburn | ); |
| 1222 | 4937 | acydburn | } |
| 1223 | 4937 | acydburn | $db->sql_freeresult($result); |
| 1224 | 6015 | acydburn | |
| 1225 | 5902 | acydburn | // forum notification is sent to those not already receiving topic notifications
|
| 1226 | 5902 | acydburn | if ($topic_notification) |
| 1227 | 4937 | acydburn | {
|
| 1228 | 4937 | acydburn | if (sizeof($notify_rows)) |
| 1229 | 4937 | acydburn | {
|
| 1230 | 4937 | acydburn | $sql_ignore_users .= ', ' . implode(', ', array_keys($notify_rows)); |
| 1231 | 4937 | acydburn | } |
| 1232 | 4937 | acydburn | |
| 1233 | 8146 | acydburn | $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber |
| 1234 | 4937 | acydburn | FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u |
| 1235 | 4937 | acydburn | WHERE fw.forum_id = $forum_id |
| 1236 | 4937 | acydburn | AND fw.user_id NOT IN ($sql_ignore_users) |
| 1237 | 10637 | git-gate | AND fw.notify_status = " . NOTIFY_YES . ' |
| 1238 | 10637 | git-gate | AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') |
| 1239 | 5117 | acydburn | AND u.user_id = fw.user_id';
|
| 1240 | 4937 | acydburn | $result = $db->sql_query($sql); |
| 1241 | 4937 | acydburn | |
| 1242 | 4937 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 1243 | 4937 | acydburn | {
|
| 1244 | 4937 | acydburn | $notify_rows[$row['user_id']] = array( |
| 1245 | 4937 | acydburn | 'user_id' => $row['user_id'], |
| 1246 | 4937 | acydburn | 'username' => $row['username'], |
| 1247 | 4937 | acydburn | 'user_email' => $row['user_email'], |
| 1248 | 8146 | acydburn | 'user_jabber' => $row['user_jabber'], |
| 1249 | 4937 | acydburn | 'user_lang' => $row['user_lang'], |
| 1250 | 4937 | acydburn | 'notify_type' => 'forum', |
| 1251 | 4937 | acydburn | 'template' => 'forum_notify', |
| 1252 | 8146 | acydburn | 'method' => $row['user_notify_type'], |
| 1253 | 4937 | acydburn | 'allowed' => false |
| 1254 | 4937 | acydburn | ); |
| 1255 | 4937 | acydburn | } |
| 1256 | 4937 | acydburn | $db->sql_freeresult($result); |
| 1257 | 4937 | acydburn | } |
| 1258 | 4937 | acydburn | |
| 1259 | 4937 | acydburn | if (!sizeof($notify_rows)) |
| 1260 | 4937 | acydburn | {
|
| 1261 | 4937 | acydburn | return;
|
| 1262 | 4937 | acydburn | } |
| 1263 | 4937 | acydburn | |
| 1264 | 5902 | acydburn | // Make sure users are allowed to read the forum
|
| 1265 | 4937 | acydburn | foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) |
| 1266 | 4937 | acydburn | {
|
| 1267 | 4937 | acydburn | foreach ($forum_ary as $auth_option => $user_ary) |
| 1268 | 4937 | acydburn | {
|
| 1269 | 4937 | acydburn | foreach ($user_ary as $user_id) |
| 1270 | 4937 | acydburn | {
|
| 1271 | 4937 | acydburn | $notify_rows[$user_id]['allowed'] = true; |
| 1272 | 4937 | acydburn | } |
| 1273 | 4937 | acydburn | } |
| 1274 | 4937 | acydburn | } |
| 1275 | 4937 | acydburn | |
| 1276 | 4937 | acydburn | |
| 1277 | 4937 | acydburn | // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;)
|
| 1278 | 4937 | acydburn | $msg_users = $delete_ids = $update_notification = array(); |
| 1279 | 4937 | acydburn | foreach ($notify_rows as $user_id => $row) |
| 1280 | 4937 | acydburn | {
|
| 1281 | 4937 | acydburn | if (!$row['allowed'] || !trim($row['user_email'])) |
| 1282 | 4937 | acydburn | {
|
| 1283 | 4937 | acydburn | $delete_ids[$row['notify_type']][] = $row['user_id']; |
| 1284 | 4937 | acydburn | } |
| 1285 | 4937 | acydburn | else
|
| 1286 | 4937 | acydburn | {
|
| 1287 | 4937 | acydburn | $msg_users[] = $row; |
| 1288 | 4937 | acydburn | $update_notification[$row['notify_type']][] = $row['user_id']; |
| 1289 | 4937 | acydburn | } |
| 1290 | 4937 | acydburn | } |
| 1291 | 4937 | acydburn | unset($notify_rows); |
| 1292 | 4937 | acydburn | |
| 1293 | 4937 | acydburn | // Now, we are able to really send out notifications
|
| 1294 | 4937 | acydburn | if (sizeof($msg_users)) |
| 1295 | 4937 | acydburn | {
|
| 1296 | 8241 | acydburn | include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); |
| 1297 | 4937 | acydburn | $messenger = new messenger(); |
| 1298 | 4937 | acydburn | |
| 1299 | 4937 | acydburn | $msg_list_ary = array(); |
| 1300 | 4937 | acydburn | foreach ($msg_users as $row) |
| 1301 | 8146 | acydburn | {
|
| 1302 | 5023 | acydburn | $pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]); |
| 1303 | 4937 | acydburn | |
| 1304 | 4937 | acydburn | $msg_list_ary[$row['template']][$pos]['method'] = $row['method']; |
| 1305 | 4937 | acydburn | $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email']; |
| 1306 | 4937 | acydburn | $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber']; |
| 1307 | 4937 | acydburn | $msg_list_ary[$row['template']][$pos]['name'] = $row['username']; |
| 1308 | 4937 | acydburn | $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang']; |
| 1309 | 8799 | acydburn | $msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id']; |
| 1310 | 4937 | acydburn | } |
| 1311 | 4937 | acydburn | unset($msg_users); |
| 1312 | 4937 | acydburn | |
| 1313 | 4937 | acydburn | foreach ($msg_list_ary as $email_template => $email_list) |
| 1314 | 4937 | acydburn | {
|
| 1315 | 4937 | acydburn | foreach ($email_list as $addr) |
| 1316 | 4937 | acydburn | {
|
| 1317 | 4937 | acydburn | $messenger->template($email_template, $addr['lang']); |
| 1318 | 4937 | acydburn | |
| 1319 | 4937 | acydburn | $messenger->to($addr['email'], $addr['name']); |
| 1320 | 4937 | acydburn | $messenger->im($addr['jabber'], $addr['name']); |
| 1321 | 4937 | acydburn | |
| 1322 | 4937 | acydburn | $messenger->assign_vars(array( |
| 1323 | 6548 | acydburn | 'USERNAME' => htmlspecialchars_decode($addr['name']), |
| 1324 | 6548 | acydburn | 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), |
| 1325 | 6548 | acydburn | 'FORUM_NAME' => htmlspecialchars_decode($forum_name), |
| 1326 | 4937 | acydburn | |
| 1327 | 8025 | acydburn | 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", |
| 1328 | 8025 | acydburn | 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", |
| 1329 | 4937 | acydburn | 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", |
| 1330 | 8775 | Kellanved | 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", |
| 1331 | 8775 | Kellanved | 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", |
| 1332 | 4937 | acydburn | )); |
| 1333 | 4937 | acydburn | |
| 1334 | 4937 | acydburn | $messenger->send($addr['method']); |
| 1335 | 4937 | acydburn | } |
| 1336 | 4937 | acydburn | } |
| 1337 | 4937 | acydburn | unset($msg_list_ary); |
| 1338 | 4937 | acydburn | |
| 1339 | 5114 | acydburn | $messenger->save_queue();
|
| 1340 | 4937 | acydburn | } |
| 1341 | 4937 | acydburn | |
| 1342 | 4937 | acydburn | // Handle the DB updates
|
| 1343 | 6015 | acydburn | $db->sql_transaction('begin'); |
| 1344 | 4937 | acydburn | |
| 1345 | 5902 | acydburn | if (!empty($update_notification['topic'])) |
| 1346 | 4937 | acydburn | {
|
| 1347 | 10637 | git-gate | $sql = 'UPDATE ' . TOPICS_WATCH_TABLE . ' |
| 1348 | 10637 | git-gate | SET notify_status = ' . NOTIFY_NO . " |
| 1349 | 4937 | acydburn | WHERE topic_id = $topic_id |
| 1350 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $update_notification['topic']); |
| 1351 | 6015 | acydburn | $db->sql_query($sql); |
| 1352 | 4937 | acydburn | } |
| 1353 | 4937 | acydburn | |
| 1354 | 5902 | acydburn | if (!empty($update_notification['forum'])) |
| 1355 | 4937 | acydburn | {
|
| 1356 | 10637 | git-gate | $sql = 'UPDATE ' . FORUMS_WATCH_TABLE . ' |
| 1357 | 10637 | git-gate | SET notify_status = ' . NOTIFY_NO . " |
| 1358 | 4937 | acydburn | WHERE forum_id = $forum_id |
| 1359 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $update_notification['forum']); |
| 1360 | 6015 | acydburn | $db->sql_query($sql); |
| 1361 | 4937 | acydburn | } |
| 1362 | 4937 | acydburn | |
| 1363 | 7242 | acydburn | // Now delete the user_ids not authorised to receive notifications on this topic/forum
|
| 1364 | 5902 | acydburn | if (!empty($delete_ids['topic'])) |
| 1365 | 4937 | acydburn | {
|
| 1366 | 6015 | acydburn | $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " |
| 1367 | 4937 | acydburn | WHERE topic_id = $topic_id |
| 1368 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $delete_ids['topic']); |
| 1369 | 6015 | acydburn | $db->sql_query($sql); |
| 1370 | 4937 | acydburn | } |
| 1371 | 4937 | acydburn | |
| 1372 | 5902 | acydburn | if (!empty($delete_ids['forum'])) |
| 1373 | 4937 | acydburn | {
|
| 1374 | 6015 | acydburn | $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . " |
| 1375 | 4937 | acydburn | WHERE forum_id = $forum_id |
| 1376 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $delete_ids['forum']); |
| 1377 | 6015 | acydburn | $db->sql_query($sql); |
| 1378 | 4937 | acydburn | } |
| 1379 | 4937 | acydburn | |
| 1380 | 4937 | acydburn | $db->sql_transaction('commit'); |
| 1381 | 4937 | acydburn | } |
| 1382 | 4937 | acydburn | |
| 1383 | 5902 | acydburn | //
|
| 1384 | 5902 | acydburn | // Post handling functions
|
| 1385 | 5902 | acydburn | //
|
| 1386 | 5902 | acydburn | |
| 1387 | 5902 | acydburn | /**
|
| 1388 | 5902 | acydburn | * Delete Post |
| 1389 | 5902 | acydburn | */ |
| 1390 | 5902 | acydburn | function delete_post($forum_id, $topic_id, $post_id, &$data) |
| 1391 | 5902 | acydburn | {
|
| 1392 | 5902 | acydburn | global $db, $user, $auth; |
| 1393 | 6015 | acydburn | global $config, $phpEx, $phpbb_root_path; |
| 1394 | 5902 | acydburn | |
| 1395 | 5902 | acydburn | // Specify our post mode
|
| 1396 | 8362 | Kellanved | $post_mode = 'delete'; |
| 1397 | 8362 | Kellanved | if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && $data['topic_replies_real'] == 0) |
| 1398 | 8362 | Kellanved | {
|
| 1399 | 8362 | Kellanved | $post_mode = 'delete_topic'; |
| 1400 | 8362 | Kellanved | } |
| 1401 | 8362 | Kellanved | else if ($data['topic_first_post_id'] == $post_id) |
| 1402 | 8362 | Kellanved | {
|
| 1403 | 8362 | Kellanved | $post_mode = 'delete_first_post'; |
| 1404 | 8667 | acydburn | } |
| 1405 | 8362 | Kellanved | else if ($data['topic_last_post_id'] == $post_id) |
| 1406 | 8362 | Kellanved | {
|
| 1407 | 8362 | Kellanved | $post_mode = 'delete_last_post'; |
| 1408 | 8362 | Kellanved | } |
| 1409 | 5902 | acydburn | $sql_data = array(); |
| 1410 | 8362 | Kellanved | $next_post_id = false; |
| 1411 | 5902 | acydburn | |
| 1412 | 5902 | acydburn | include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
| 1413 | 5902 | acydburn | |
| 1414 | 6015 | acydburn | $db->sql_transaction('begin'); |
| 1415 | 5902 | acydburn | |
| 1416 | 7832 | davidmj | // we must make sure to update forums that contain the shadow'd topic
|
| 1417 | 7832 | davidmj | if ($post_mode == 'delete_topic') |
| 1418 | 7832 | davidmj | {
|
| 1419 | 7832 | davidmj | $shadow_forum_ids = array(); |
| 1420 | 7832 | davidmj | |
| 1421 | 7832 | davidmj | $sql = 'SELECT forum_id |
| 1422 | 7832 | davidmj | FROM ' . TOPICS_TABLE . ' |
| 1423 | 7832 | davidmj | WHERE ' . $db->sql_in_set('topic_moved_id', $topic_id); |
| 1424 | 7832 | davidmj | $result = $db->sql_query($sql); |
| 1425 | 7832 | davidmj | while ($row = $db->sql_fetchrow($result)) |
| 1426 | 7832 | davidmj | {
|
| 1427 | 7832 | davidmj | if (!isset($shadow_forum_ids[(int) $row['forum_id']])) |
| 1428 | 7832 | davidmj | {
|
| 1429 | 7832 | davidmj | $shadow_forum_ids[(int) $row['forum_id']] = 1; |
| 1430 | 7832 | davidmj | } |
| 1431 | 7832 | davidmj | else
|
| 1432 | 7832 | davidmj | {
|
| 1433 | 7832 | davidmj | $shadow_forum_ids[(int) $row['forum_id']]++; |
| 1434 | 7832 | davidmj | } |
| 1435 | 7832 | davidmj | } |
| 1436 | 7832 | davidmj | $db->sql_freeresult($result); |
| 1437 | 7832 | davidmj | } |
| 1438 | 7832 | davidmj | |
| 1439 | 5973 | acydburn | if (!delete_posts('post_id', array($post_id), false, false)) |
| 1440 | 5902 | acydburn | {
|
| 1441 | 5902 | acydburn | // Try to delete topic, we may had an previous error causing inconsistency
|
| 1442 | 6063 | naderman | if ($post_mode == 'delete_topic') |
| 1443 | 5902 | acydburn | {
|
| 1444 | 5902 | acydburn | delete_topics('topic_id', array($topic_id), false); |
| 1445 | 5902 | acydburn | } |
| 1446 | 5902 | acydburn | trigger_error('ALREADY_DELETED'); |
| 1447 | 5902 | acydburn | } |
| 1448 | 5902 | acydburn | |
| 1449 | 5902 | acydburn | $db->sql_transaction('commit'); |
| 1450 | 5902 | acydburn | |
| 1451 | 6063 | naderman | // Collect the necessary information for updating the tables
|
| 1452 | 5902 | acydburn | $sql_data[FORUMS_TABLE] = ''; |
| 1453 | 5902 | acydburn | switch ($post_mode) |
| 1454 | 5902 | acydburn | {
|
| 1455 | 5902 | acydburn | case 'delete_topic': |
| 1456 | 7832 | davidmj | |
| 1457 | 7832 | davidmj | foreach ($shadow_forum_ids as $updated_forum => $topic_count) |
| 1458 | 7832 | davidmj | {
|
| 1459 | 7832 | davidmj | // counting is fun! we only have to do sizeof($forum_ids) number of queries,
|
| 1460 | 7832 | davidmj | // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum)
|
| 1461 | 7832 | davidmj | $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_topics_real = forum_topics_real - ' . $topic_count . ', forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum); |
| 1462 | 7832 | davidmj | update_post_information('forum', $updated_forum); |
| 1463 | 7832 | davidmj | } |
| 1464 | 7832 | davidmj | |
| 1465 | 5902 | acydburn | delete_topics('topic_id', array($topic_id), false); |
| 1466 | 5902 | acydburn | |
| 1467 | 11100 | git-gate | $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; |
| 1468 | 11100 | git-gate | $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; |
| 1469 | 5902 | acydburn | |
| 1470 | 5902 | acydburn | $update_sql = update_post_information('forum', $forum_id, true); |
| 1471 | 5902 | acydburn | if (sizeof($update_sql)) |
| 1472 | 5902 | acydburn | {
|
| 1473 | 5902 | acydburn | $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; |
| 1474 | 5902 | acydburn | $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); |
| 1475 | 5902 | acydburn | } |
| 1476 | 5902 | acydburn | break;
|
| 1477 | 5902 | acydburn | |
| 1478 | 5902 | acydburn | case 'delete_first_post': |
| 1479 | 10990 | git-gate | $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour |
| 1480 | 5902 | acydburn | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u |
| 1481 | 5902 | acydburn | WHERE p.topic_id = $topic_id |
| 1482 | 5902 | acydburn | AND p.poster_id = u.user_id |
| 1483 | 5902 | acydburn | ORDER BY p.post_time ASC";
|
| 1484 | 5902 | acydburn | $result = $db->sql_query_limit($sql, 1); |
| 1485 | 5902 | acydburn | $row = $db->sql_fetchrow($result); |
| 1486 | 5902 | acydburn | $db->sql_freeresult($result); |
| 1487 | 5902 | acydburn | |
| 1488 | 11100 | git-gate | $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; |
| 1489 | 5902 | acydburn | |
| 1490 | 10990 | git-gate | $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; |
| 1491 | 7491 | acydburn | |
| 1492 | 7491 | acydburn | // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
|
| 1493 | 5902 | acydburn | $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); |
| 1494 | 5902 | acydburn | |
| 1495 | 5902 | acydburn | $next_post_id = (int) $row['post_id']; |
| 1496 | 5902 | acydburn | break;
|
| 1497 | 5902 | acydburn | |
| 1498 | 5902 | acydburn | case 'delete_last_post': |
| 1499 | 11100 | git-gate | $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; |
| 1500 | 5902 | acydburn | |
| 1501 | 5902 | acydburn | $update_sql = update_post_information('forum', $forum_id, true); |
| 1502 | 5902 | acydburn | if (sizeof($update_sql)) |
| 1503 | 5902 | acydburn | {
|
| 1504 | 5902 | acydburn | $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; |
| 1505 | 5902 | acydburn | $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); |
| 1506 | 5902 | acydburn | } |
| 1507 | 6015 | acydburn | |
| 1508 | 5902 | acydburn | $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); |
| 1509 | 5902 | acydburn | |
| 1510 | 5902 | acydburn | $update_sql = update_post_information('topic', $topic_id, true); |
| 1511 | 5902 | acydburn | if (sizeof($update_sql)) |
| 1512 | 5902 | acydburn | {
|
| 1513 | 5902 | acydburn | $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); |
| 1514 | 5902 | acydburn | $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); |
| 1515 | 5902 | acydburn | } |
| 1516 | 5902 | acydburn | else
|
| 1517 | 5902 | acydburn | {
|
| 1518 | 5902 | acydburn | $sql = 'SELECT MAX(post_id) as last_post_id |
| 1519 | 5902 | acydburn | FROM ' . POSTS_TABLE . " |
| 1520 | 5902 | acydburn | WHERE topic_id = $topic_id " . |
| 1521 | 5902 | acydburn | ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : ''); |
| 1522 | 5902 | acydburn | $result = $db->sql_query($sql); |
| 1523 | 5902 | acydburn | $row = $db->sql_fetchrow($result); |
| 1524 | 5902 | acydburn | $db->sql_freeresult($result); |
| 1525 | 5902 | acydburn | |
| 1526 | 5902 | acydburn | $next_post_id = (int) $row['last_post_id']; |
| 1527 | 5902 | acydburn | } |
| 1528 | 5902 | acydburn | break;
|
| 1529 | 5902 | acydburn | |
| 1530 | 5902 | acydburn | case 'delete': |
| 1531 | 5902 | acydburn | $sql = 'SELECT post_id |
| 1532 | 5902 | acydburn | FROM ' . POSTS_TABLE . " |
| 1533 | 5902 | acydburn | WHERE topic_id = $topic_id " . |
| 1534 | 5902 | acydburn | ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . ' |
| 1535 | 5902 | acydburn | AND post_time > ' . $data['post_time'] . ' |
| 1536 | 5902 | acydburn | ORDER BY post_time ASC';
|
| 1537 | 5902 | acydburn | $result = $db->sql_query_limit($sql, 1); |
| 1538 | 5902 | acydburn | $row = $db->sql_fetchrow($result); |
| 1539 | 5902 | acydburn | $db->sql_freeresult($result); |
| 1540 | 5902 | acydburn | |
| 1541 | 11100 | git-gate | $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; |
| 1542 | 5902 | acydburn | |
| 1543 | 5902 | acydburn | $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); |
| 1544 | 5902 | acydburn | $next_post_id = (int) $row['post_id']; |
| 1545 | 5902 | acydburn | break;
|
| 1546 | 5902 | acydburn | } |
| 1547 | 5902 | acydburn | |
| 1548 | 9843 | nickvergessen | if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) |
| 1549 | 9843 | nickvergessen | {
|
| 1550 | 9843 | nickvergessen | $sql = 'SELECT 1 AS has_attachments |
| 1551 | 9843 | nickvergessen | FROM ' . ATTACHMENTS_TABLE . ' |
| 1552 | 9893 | nickvergessen | WHERE topic_id = ' . $topic_id; |
| 1553 | 9893 | nickvergessen | $result = $db->sql_query_limit($sql, 1); |
| 1554 | 9843 | nickvergessen | $has_attachments = (int) $db->sql_fetchfield('has_attachments'); |
| 1555 | 9843 | nickvergessen | $db->sql_freeresult($result); |
| 1556 | 9843 | nickvergessen | |
| 1557 | 9843 | nickvergessen | if (!$has_attachments) |
| 1558 | 9843 | nickvergessen | {
|
| 1559 | 9843 | nickvergessen | $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0'; |
| 1560 | 9843 | nickvergessen | } |
| 1561 | 9843 | nickvergessen | } |
| 1562 | 9843 | nickvergessen | |
| 1563 | 6224 | acydburn | // $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
|
| 1564 | 5902 | acydburn | |
| 1565 | 6015 | acydburn | $db->sql_transaction('begin'); |
| 1566 | 5902 | acydburn | |
| 1567 | 5902 | acydburn | $where_sql = array( |
| 1568 | 5902 | acydburn | FORUMS_TABLE => "forum_id = $forum_id", |
| 1569 | 5902 | acydburn | TOPICS_TABLE => "topic_id = $topic_id", |
| 1570 | 5902 | acydburn | USERS_TABLE => 'user_id = ' . $data['poster_id'] |
| 1571 | 5902 | acydburn | ); |
| 1572 | 5902 | acydburn | |
| 1573 | 5902 | acydburn | foreach ($sql_data as $table => $update_sql) |
| 1574 | 5902 | acydburn | {
|
| 1575 | 5902 | acydburn | if ($update_sql) |
| 1576 | 5902 | acydburn | {
|
| 1577 | 5902 | acydburn | $db->sql_query("UPDATE $table SET $update_sql WHERE " . $where_sql[$table]); |
| 1578 | 5902 | acydburn | } |
| 1579 | 5902 | acydburn | } |
| 1580 | 5902 | acydburn | |
| 1581 | 5973 | acydburn | // Adjust posted info for this user by looking for a post by him/her within this topic...
|
| 1582 | 6770 | acydburn | if ($post_mode != 'delete_topic' && $config['load_db_track'] && $data['poster_id'] != ANONYMOUS) |
| 1583 | 5973 | acydburn | {
|
| 1584 | 5973 | acydburn | $sql = 'SELECT poster_id |
| 1585 | 5973 | acydburn | FROM ' . POSTS_TABLE . ' |
| 1586 | 5973 | acydburn | WHERE topic_id = ' . $topic_id . ' |
| 1587 | 6770 | acydburn | AND poster_id = ' . $data['poster_id']; |
| 1588 | 5973 | acydburn | $result = $db->sql_query_limit($sql, 1); |
| 1589 | 5973 | acydburn | $poster_id = (int) $db->sql_fetchfield('poster_id'); |
| 1590 | 5973 | acydburn | $db->sql_freeresult($result); |
| 1591 | 5973 | acydburn | |
| 1592 | 5973 | acydburn | // The user is not having any more posts within this topic
|
| 1593 | 5973 | acydburn | if (!$poster_id) |
| 1594 | 5973 | acydburn | {
|
| 1595 | 5973 | acydburn | $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . ' |
| 1596 | 5973 | acydburn | WHERE topic_id = ' . $topic_id . ' |
| 1597 | 6770 | acydburn | AND user_id = ' . $data['poster_id']; |
| 1598 | 5973 | acydburn | $db->sql_query($sql); |
| 1599 | 5973 | acydburn | } |
| 1600 | 5973 | acydburn | } |
| 1601 | 5973 | acydburn | |
| 1602 | 7469 | acydburn | $db->sql_transaction('commit'); |
| 1603 | 7469 | acydburn | |
| 1604 | 6063 | naderman | if ($data['post_reported'] && ($post_mode != 'delete_topic')) |
| 1605 | 6063 | naderman | {
|
| 1606 | 6063 | naderman | sync('topic_reported', 'topic_id', array($topic_id)); |
| 1607 | 6063 | naderman | } |
| 1608 | 6063 | naderman | |
| 1609 | 5902 | acydburn | return $next_post_id; |
| 1610 | 5902 | acydburn | } |
| 1611 | 5902 | acydburn | |
| 1612 | 5902 | acydburn | /**
|
| 1613 | 5902 | acydburn | * Submit Post |
| 1614 | 9959 | acydburn | * @todo Split up and create lightweight, simple API for this. |
| 1615 | 5902 | acydburn | */ |
| 1616 | 9959 | acydburn | function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) |
| 1617 | 5902 | acydburn | {
|
| 1618 | 6015 | acydburn | global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; |
| 1619 | 5902 | acydburn | |
| 1620 | 5902 | acydburn | // We do not handle erasing posts here
|
| 1621 | 5902 | acydburn | if ($mode == 'delete') |
| 1622 | 5902 | acydburn | {
|
| 1623 | 5967 | acydburn | return false; |
| 1624 | 5902 | acydburn | } |
| 1625 | 5902 | acydburn | |
| 1626 | 5902 | acydburn | $current_time = time(); |
| 1627 | 5902 | acydburn | |
| 1628 | 5902 | acydburn | if ($mode == 'post') |
| 1629 | 5902 | acydburn | {
|
| 1630 | 5902 | acydburn | $post_mode = 'post'; |
| 1631 | 5902 | acydburn | $update_message = true; |
| 1632 | 5902 | acydburn | } |
| 1633 | 5902 | acydburn | else if ($mode != 'edit') |
| 1634 | 5902 | acydburn | {
|
| 1635 | 5902 | acydburn | $post_mode = 'reply'; |
| 1636 | 5902 | acydburn | $update_message = true; |
| 1637 | 5902 | acydburn | } |
| 1638 | 5902 | acydburn | else if ($mode == 'edit') |
| 1639 | 5902 | acydburn | {
|
| 1640 | 7537 | davidmj | $post_mode = ($data['topic_replies_real'] == 0) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); |
| 1641 | 5902 | acydburn | } |
| 1642 | 5902 | acydburn | |
| 1643 | 6224 | acydburn | // First of all make sure the subject and topic title are having the correct length.
|
| 1644 | 7547 | acydburn | // To achieve this without cutting off between special chars we convert to an array and then count the elements.
|
| 1645 | 6224 | acydburn | $subject = truncate_string($subject); |
| 1646 | 6224 | acydburn | $data['topic_title'] = truncate_string($data['topic_title']); |
| 1647 | 6224 | acydburn | |
| 1648 | 6650 | acydburn | // Collect some basic information about which tables and which rows to update/insert
|
| 1649 | 7519 | acydburn | $sql_data = $topic_row = array(); |
| 1650 | 5902 | acydburn | $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; |
| 1651 | 5902 | acydburn | |
| 1652 | 7519 | acydburn | // Retrieve some additional information if not present
|
| 1653 | 7519 | acydburn | if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false)) |
| 1654 | 7519 | acydburn | {
|
| 1655 | 7519 | acydburn | $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved |
| 1656 | 7519 | acydburn | FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p |
| 1657 | 7519 | acydburn | WHERE t.topic_id = p.topic_id |
| 1658 | 7519 | acydburn | AND p.post_id = ' . $data['post_id']; |
| 1659 | 7519 | acydburn | $result = $db->sql_query($sql); |
| 1660 | 7519 | acydburn | $topic_row = $db->sql_fetchrow($result); |
| 1661 | 7519 | acydburn | $db->sql_freeresult($result); |
| 1662 | 7519 | acydburn | |
| 1663 | 7519 | acydburn | $data['topic_approved'] = $topic_row['topic_approved']; |
| 1664 | 7519 | acydburn | $data['post_approved'] = $topic_row['post_approved']; |
| 1665 | 7519 | acydburn | } |
| 1666 | 7519 | acydburn | |
| 1667 | 8805 | acydburn | // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval
|
| 1668 | 9927 | acydburn | // The variable name should be $post_approved, because it indicates if the post is approved or not
|
| 1669 | 8805 | acydburn | $post_approval = 1; |
| 1670 | 8805 | acydburn | |
| 1671 | 9636 | acydburn | // Check the permissions for post approval. Moderators are not affected.
|
| 1672 | 9636 | acydburn | if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) |
| 1673 | 8805 | acydburn | {
|
| 1674 | 9927 | acydburn | // Post not approved, but in queue
|
| 1675 | 8805 | acydburn | $post_approval = 0; |
| 1676 | 8805 | acydburn | } |
| 1677 | 8805 | acydburn | |
| 1678 | 9927 | acydburn | // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved
|
| 1679 | 9929 | acydburn | if (isset($data['force_approved_state'])) |
| 1680 | 9927 | acydburn | {
|
| 1681 | 9927 | acydburn | $post_approval = ($data['force_approved_state']) ? 1 : 0; |
| 1682 | 9927 | acydburn | } |
| 1683 | 9927 | acydburn | |
| 1684 | 7521 | acydburn | // Start the transaction here
|
| 1685 | 7521 | acydburn | $db->sql_transaction('begin'); |
| 1686 | 7521 | acydburn | |
| 1687 | 6650 | acydburn | // Collect Information
|
| 1688 | 5902 | acydburn | switch ($post_mode) |
| 1689 | 5902 | acydburn | {
|
| 1690 | 5902 | acydburn | case 'post': |
| 1691 | 5902 | acydburn | case 'reply': |
| 1692 | 5902 | acydburn | $sql_data[POSTS_TABLE]['sql'] = array( |
| 1693 | 11100 | git-gate | 'forum_id' => $data['forum_id'], |
| 1694 | 6015 | acydburn | 'poster_id' => (int) $user->data['user_id'], |
| 1695 | 5902 | acydburn | 'icon_id' => $data['icon_id'], |
| 1696 | 6015 | acydburn | 'poster_ip' => $user->ip, |
| 1697 | 5902 | acydburn | 'post_time' => $current_time, |
| 1698 | 8805 | acydburn | 'post_approved' => $post_approval, |
| 1699 | 6015 | acydburn | 'enable_bbcode' => $data['enable_bbcode'], |
| 1700 | 6015 | acydburn | 'enable_smilies' => $data['enable_smilies'], |
| 1701 | 6015 | acydburn | 'enable_magic_url' => $data['enable_urls'], |
| 1702 | 6015 | acydburn | 'enable_sig' => $data['enable_sig'], |
| 1703 | 5902 | acydburn | 'post_username' => (!$user->data['is_registered']) ? $username : '', |
| 1704 | 5902 | acydburn | 'post_subject' => $subject, |
| 1705 | 6015 | acydburn | 'post_text' => $data['message'], |
| 1706 | 5902 | acydburn | 'post_checksum' => $data['message_md5'], |
| 1707 | 6414 | acydburn | 'post_attachment' => (!empty($data['attachment_data'])) ? 1 : 0, |
| 1708 | 5902 | acydburn | 'bbcode_bitfield' => $data['bbcode_bitfield'], |
| 1709 | 5902 | acydburn | 'bbcode_uid' => $data['bbcode_uid'], |
| 1710 | 6227 | naderman | 'post_postcount' => ($auth->acl_get('f_postcount', $data['forum_id'])) ? 1 : 0, |
| 1711 | 5902 | acydburn | 'post_edit_locked' => $data['post_edit_locked'] |
| 1712 | 5902 | acydburn | ); |
| 1713 | 5902 | acydburn | break;
|
| 1714 | 5902 | acydburn | |
| 1715 | 5902 | acydburn | case 'edit_first_post': |
| 1716 | 5902 | acydburn | case 'edit': |
| 1717 | 6015 | acydburn | |
| 1718 | 5902 | acydburn | case 'edit_last_post': |
| 1719 | 5902 | acydburn | case 'edit_topic': |
| 1720 | 5902 | acydburn | |
| 1721 | 7451 | acydburn | // If edit reason is given always display edit info
|
| 1722 | 7451 | acydburn | |
| 1723 | 7451 | acydburn | // If editing last post then display no edit info
|
| 1724 | 7451 | acydburn | // If m_edit permission then display no edit info
|
| 1725 | 7451 | acydburn | // If normal edit display edit info
|
| 1726 | 7451 | acydburn | |
| 1727 | 7451 | acydburn | // Display edit info if edit reason given or user is editing his post, which is not the last within the topic.
|
| 1728 | 7451 | acydburn | if ($data['post_edit_reason'] || (!$auth->acl_get('m_edit', $data['forum_id']) && ($post_mode == 'edit' || $post_mode == 'edit_first_post'))) |
| 1729 | 5902 | acydburn | {
|
| 1730 | 8667 | acydburn | $data['post_edit_reason'] = truncate_string($data['post_edit_reason'], 255, 255, false); |
| 1731 | 8253 | kellanved | |
| 1732 | 8251 | kellanved | $sql_data[POSTS_TABLE]['sql'] = array( |
| 1733 | 7451 | acydburn | 'post_edit_time' => $current_time, |
| 1734 | 7451 | acydburn | 'post_edit_reason' => $data['post_edit_reason'], |
| 1735 | 7451 | acydburn | 'post_edit_user' => (int) $data['post_edit_user'], |
| 1736 | 5902 | acydburn | ); |
| 1737 | 5902 | acydburn | |
| 1738 | 5902 | acydburn | $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1'; |
| 1739 | 5902 | acydburn | } |
| 1740 | 8075 | acydburn | else if (!$data['post_edit_reason'] && $mode == 'edit' && $auth->acl_get('m_edit', $data['forum_id'])) |
| 1741 | 8075 | acydburn | {
|
| 1742 | 8075 | acydburn | $sql_data[POSTS_TABLE]['sql'] = array( |
| 1743 | 8075 | acydburn | 'post_edit_reason' => '', |
| 1744 | 8075 | acydburn | ); |
| 1745 | 8075 | acydburn | } |
| 1746 | 5902 | acydburn | |
| 1747 | 7491 | acydburn | // If the person editing this post is different to the one having posted then we will add a log entry stating the edit
|
| 1748 | 7491 | acydburn | // Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods
|
| 1749 | 7491 | acydburn | if ($user->data['user_id'] != $poster_id) |
| 1750 | 7491 | acydburn | {
|
| 1751 | 7491 | acydburn | $log_subject = ($subject) ? $subject : $data['topic_title']; |
| 1752 | 7589 | acydburn | add_log('mod', $data['forum_id'], $data['topic_id'], 'LOG_POST_EDITED', $log_subject, (!empty($username)) ? $username : $user->lang['GUEST']); |
| 1753 | 7491 | acydburn | } |
| 1754 | 7491 | acydburn | |
| 1755 | 5902 | acydburn | if (!isset($sql_data[POSTS_TABLE]['sql'])) |
| 1756 | 5902 | acydburn | {
|
| 1757 | 5902 | acydburn | $sql_data[POSTS_TABLE]['sql'] = array(); |
| 1758 | 5902 | acydburn | } |
| 1759 | 5902 | acydburn | |
| 1760 | 5902 | acydburn | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( |
| 1761 | 11100 | git-gate | 'forum_id' => $data['forum_id'], |
| 1762 | 6015 | acydburn | 'poster_id' => $data['poster_id'], |
| 1763 | 5902 | acydburn | 'icon_id' => $data['icon_id'], |
| 1764 | 8805 | acydburn | 'post_approved' => (!$post_approval) ? 0 : $data['post_approved'], |
| 1765 | 6015 | acydburn | 'enable_bbcode' => $data['enable_bbcode'], |
| 1766 | 6015 | acydburn | 'enable_smilies' => $data['enable_smilies'], |
| 1767 | 6015 | acydburn | 'enable_magic_url' => $data['enable_urls'], |
| 1768 | 6015 | acydburn | 'enable_sig' => $data['enable_sig'], |
| 1769 | 5902 | acydburn | 'post_username' => ($username && $data['poster_id'] == ANONYMOUS) ? $username : '', |
| 1770 | 5902 | acydburn | 'post_subject' => $subject, |
| 1771 | 5902 | acydburn | 'post_checksum' => $data['message_md5'], |
| 1772 | 6414 | acydburn | 'post_attachment' => (!empty($data['attachment_data'])) ? 1 : 0, |
| 1773 | 5902 | acydburn | 'bbcode_bitfield' => $data['bbcode_bitfield'], |
| 1774 | 5902 | acydburn | 'bbcode_uid' => $data['bbcode_uid'], |
| 1775 | 5902 | acydburn | 'post_edit_locked' => $data['post_edit_locked']) |
| 1776 | 5902 | acydburn | ); |
| 1777 | 5902 | acydburn | |
| 1778 | 5902 | acydburn | if ($update_message) |
| 1779 | 5902 | acydburn | {
|
| 1780 | 5902 | acydburn | $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message']; |
| 1781 | 5902 | acydburn | } |
| 1782 | 5902 | acydburn | |
| 1783 | 5902 | acydburn | break;
|
| 1784 | 5902 | acydburn | } |
| 1785 | 5902 | acydburn | |
| 1786 | 7441 | davidmj | $post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved']; |
| 1787 | 7491 | acydburn | $topic_row = array(); |
| 1788 | 7441 | davidmj | |
| 1789 | 5902 | acydburn | // And the topic ladies and gentlemen
|
| 1790 | 5902 | acydburn | switch ($post_mode) |
| 1791 | 5902 | acydburn | {
|
| 1792 | 5902 | acydburn | case 'post': |
| 1793 | 5902 | acydburn | $sql_data[TOPICS_TABLE]['sql'] = array( |
| 1794 | 5902 | acydburn | 'topic_poster' => (int) $user->data['user_id'], |
| 1795 | 5902 | acydburn | 'topic_time' => $current_time, |
| 1796 | 9426 | acydburn | 'topic_last_view_time' => $current_time, |
| 1797 | 11100 | git-gate | 'forum_id' => $data['forum_id'], |
| 1798 | 5902 | acydburn | 'icon_id' => $data['icon_id'], |
| 1799 | 8805 | acydburn | 'topic_approved' => $post_approval, |
| 1800 | 6015 | acydburn | 'topic_title' => $subject, |
| 1801 | 5902 | acydburn | 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), |
| 1802 | 7744 | kellanved | 'topic_first_poster_colour' => $user->data['user_colour'], |
| 1803 | 5902 | acydburn | 'topic_type' => $topic_type, |
| 1804 | 5902 | acydburn | 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, |
| 1805 | 6414 | acydburn | 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : 0, |
| 1806 | 5902 | acydburn | ); |
| 1807 | 5902 | acydburn | |
| 1808 | 5902 | acydburn | if (isset($poll['poll_options']) && !empty($poll['poll_options'])) |
| 1809 | 5902 | acydburn | {
|
| 1810 | 9342 | terrafrost | $poll_start = ($poll['poll_start']) ? $poll['poll_start'] : $current_time; |
| 1811 | 9342 | terrafrost | $poll_length = $poll['poll_length'] * 86400; |
| 1812 | 9342 | terrafrost | if ($poll_length < 0) |
| 1813 | 9342 | terrafrost | {
|
| 1814 | 9342 | terrafrost | $poll_start = $poll_start + $poll_length; |
| 1815 | 9342 | terrafrost | if ($poll_start < 0) |
| 1816 | 9342 | terrafrost | {
|
| 1817 | 9342 | terrafrost | $poll_start = 0; |
| 1818 | 9342 | terrafrost | } |
| 1819 | 9342 | terrafrost | $poll_length = 1; |
| 1820 | 9342 | terrafrost | } |
| 1821 | 9342 | terrafrost | |
| 1822 | 5902 | acydburn | $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array( |
| 1823 | 5902 | acydburn | 'poll_title' => $poll['poll_title'], |
| 1824 | 9342 | terrafrost | 'poll_start' => $poll_start, |
| 1825 | 5902 | acydburn | 'poll_max_options' => $poll['poll_max_options'], |
| 1826 | 9342 | terrafrost | 'poll_length' => $poll_length, |
| 1827 | 5902 | acydburn | 'poll_vote_change' => $poll['poll_vote_change']) |
| 1828 | 5902 | acydburn | ); |
| 1829 | 5902 | acydburn | } |
| 1830 | 5902 | acydburn | |
| 1831 | 8805 | acydburn | $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); |
| 1832 | 8350 | acydburn | |
| 1833 | 11100 | git-gate | if ($post_approval) |
| 1834 | 5902 | acydburn | {
|
| 1835 | 11100 | git-gate | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; |
| 1836 | 5902 | acydburn | } |
| 1837 | 11100 | git-gate | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : ''); |
| 1838 | 5902 | acydburn | break;
|
| 1839 | 5902 | acydburn | |
| 1840 | 5902 | acydburn | case 'reply': |
| 1841 | 9426 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', |
| 1842 | 9426 | acydburn | topic_replies_real = topic_replies_real + 1, |
| 1843 | 9426 | acydburn | topic_bumped = 0, |
| 1844 | 9426 | acydburn | topic_bumper = 0' .
|
| 1845 | 9426 | acydburn | (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . |
| 1846 | 9426 | acydburn | ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); |
| 1847 | 9426 | acydburn | |
| 1848 | 8805 | acydburn | $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); |
| 1849 | 7114 | acydburn | |
| 1850 | 11100 | git-gate | if ($post_approval) |
| 1851 | 5902 | acydburn | {
|
| 1852 | 5902 | acydburn | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; |
| 1853 | 5902 | acydburn | } |
| 1854 | 5902 | acydburn | break;
|
| 1855 | 5902 | acydburn | |
| 1856 | 5902 | acydburn | case 'edit_topic': |
| 1857 | 5902 | acydburn | case 'edit_first_post': |
| 1858 | 11555 | git-gate | if (isset($poll['poll_options'])) |
| 1859 | 9342 | terrafrost | {
|
| 1860 | 11555 | git-gate | $poll_start = ($poll['poll_start'] || empty($poll['poll_options'])) ? $poll['poll_start'] : $current_time; |
| 1861 | 9342 | terrafrost | $poll_length = $poll['poll_length'] * 86400; |
| 1862 | 9342 | terrafrost | if ($poll_length < 0) |
| 1863 | 9342 | terrafrost | {
|
| 1864 | 9342 | terrafrost | $poll_start = $poll_start + $poll_length; |
| 1865 | 9342 | terrafrost | if ($poll_start < 0) |
| 1866 | 9342 | terrafrost | {
|
| 1867 | 9342 | terrafrost | $poll_start = 0; |
| 1868 | 9342 | terrafrost | } |
| 1869 | 9342 | terrafrost | $poll_length = 1; |
| 1870 | 9342 | terrafrost | } |
| 1871 | 9342 | terrafrost | } |
| 1872 | 5902 | acydburn | |
| 1873 | 5902 | acydburn | $sql_data[TOPICS_TABLE]['sql'] = array( |
| 1874 | 11100 | git-gate | 'forum_id' => $data['forum_id'], |
| 1875 | 5902 | acydburn | 'icon_id' => $data['icon_id'], |
| 1876 | 8805 | acydburn | 'topic_approved' => (!$post_approval) ? 0 : $data['topic_approved'], |
| 1877 | 6015 | acydburn | 'topic_title' => $subject, |
| 1878 | 5902 | acydburn | 'topic_first_poster_name' => $username, |
| 1879 | 5902 | acydburn | 'topic_type' => $topic_type, |
| 1880 | 5902 | acydburn | 'topic_time_limit' => ($topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE) ? ($data['topic_time_limit'] * 86400) : 0, |
| 1881 | 5902 | acydburn | 'poll_title' => (isset($poll['poll_options'])) ? $poll['poll_title'] : '', |
| 1882 | 9342 | terrafrost | 'poll_start' => (isset($poll['poll_options'])) ? $poll_start : 0, |
| 1883 | 5902 | acydburn | 'poll_max_options' => (isset($poll['poll_options'])) ? $poll['poll_max_options'] : 1, |
| 1884 | 9342 | terrafrost | 'poll_length' => (isset($poll['poll_options'])) ? $poll_length : 0, |
| 1885 | 5902 | acydburn | 'poll_vote_change' => (isset($poll['poll_vote_change'])) ? $poll['poll_vote_change'] : 0, |
| 1886 | 9426 | acydburn | 'topic_last_view_time' => $current_time, |
| 1887 | 5902 | acydburn | |
| 1888 | 6414 | acydburn | 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0), |
| 1889 | 5902 | acydburn | ); |
| 1890 | 7150 | acydburn | |
| 1891 | 7519 | acydburn | // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved
|
| 1892 | 8805 | acydburn | if (!$post_approval && $data['topic_approved']) |
| 1893 | 7491 | acydburn | {
|
| 1894 | 7519 | acydburn | // Do we need to grab some topic informations?
|
| 1895 | 7519 | acydburn | if (!sizeof($topic_row)) |
| 1896 | 7519 | acydburn | {
|
| 1897 | 7519 | acydburn | $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved |
| 1898 | 7519 | acydburn | FROM ' . TOPICS_TABLE . ' |
| 1899 | 7519 | acydburn | WHERE topic_id = ' . $data['topic_id']; |
| 1900 | 7519 | acydburn | $result = $db->sql_query($sql); |
| 1901 | 7519 | acydburn | $topic_row = $db->sql_fetchrow($result); |
| 1902 | 7519 | acydburn | $db->sql_freeresult($result); |
| 1903 | 7519 | acydburn | } |
| 1904 | 7150 | acydburn | |
| 1905 | 7491 | acydburn | // If this is the only post remaining we do not need to decrement topic_replies.
|
| 1906 | 7491 | acydburn | // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again.
|
| 1907 | 7491 | acydburn | |
| 1908 | 7491 | acydburn | // If this is an edited topic or the first post the topic gets completely disapproved later on...
|
| 1909 | 7491 | acydburn | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1'; |
| 1910 | 7491 | acydburn | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1); |
| 1911 | 7491 | acydburn | |
| 1912 | 9398 | acydburn | set_config_count('num_topics', -1, true); |
| 1913 | 9398 | acydburn | set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true); |
| 1914 | 8805 | acydburn | |
| 1915 | 8805 | acydburn | // Only decrement this post, since this is the one non-approved now
|
| 1916 | 8805 | acydburn | if ($auth->acl_get('f_postcount', $data['forum_id'])) |
| 1917 | 8805 | acydburn | {
|
| 1918 | 8805 | acydburn | $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; |
| 1919 | 8805 | acydburn | } |
| 1920 | 7491 | acydburn | } |
| 1921 | 7491 | acydburn | |
| 1922 | 7491 | acydburn | break;
|
| 1923 | 7491 | acydburn | |
| 1924 | 7150 | acydburn | case 'edit': |
| 1925 | 7150 | acydburn | case 'edit_last_post': |
| 1926 | 7150 | acydburn | |
| 1927 | 7519 | acydburn | // Correctly set back the topic replies and forum posts... but only if the post was approved before.
|
| 1928 | 8805 | acydburn | if (!$post_approval && $data['post_approved']) |
| 1929 | 7150 | acydburn | {
|
| 1930 | 9426 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; |
| 1931 | 7150 | acydburn | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; |
| 1932 | 7491 | acydburn | |
| 1933 | 9398 | acydburn | set_config_count('num_posts', -1, true); |
| 1934 | 8805 | acydburn | |
| 1935 | 8805 | acydburn | if ($auth->acl_get('f_postcount', $data['forum_id'])) |
| 1936 | 8805 | acydburn | {
|
| 1937 | 8805 | acydburn | $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; |
| 1938 | 8805 | acydburn | } |
| 1939 | 7150 | acydburn | } |
| 1940 | 7150 | acydburn | |
| 1941 | 5902 | acydburn | break;
|
| 1942 | 5902 | acydburn | } |
| 1943 | 5902 | acydburn | |
| 1944 | 5902 | acydburn | // Submit new topic
|
| 1945 | 5902 | acydburn | if ($post_mode == 'post') |
| 1946 | 5902 | acydburn | {
|
| 1947 | 5902 | acydburn | $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . |
| 1948 | 5902 | acydburn | $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']); |
| 1949 | 5902 | acydburn | $db->sql_query($sql); |
| 1950 | 5902 | acydburn | |
| 1951 | 5902 | acydburn | $data['topic_id'] = $db->sql_nextid(); |
| 1952 | 5902 | acydburn | |
| 1953 | 5902 | acydburn | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( |
| 1954 | 5902 | acydburn | 'topic_id' => $data['topic_id']) |
| 1955 | 5902 | acydburn | ); |
| 1956 | 5902 | acydburn | unset($sql_data[TOPICS_TABLE]['sql']); |
| 1957 | 5902 | acydburn | } |
| 1958 | 5902 | acydburn | |
| 1959 | 5902 | acydburn | // Submit new post
|
| 1960 | 5902 | acydburn | if ($post_mode == 'post' || $post_mode == 'reply') |
| 1961 | 5902 | acydburn | {
|
| 1962 | 5902 | acydburn | if ($post_mode == 'reply') |
| 1963 | 5902 | acydburn | {
|
| 1964 | 5902 | acydburn | $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( |
| 1965 | 5902 | acydburn | 'topic_id' => $data['topic_id']) |
| 1966 | 5902 | acydburn | ); |
| 1967 | 5902 | acydburn | } |
| 1968 | 5902 | acydburn | |
| 1969 | 6880 | davidmj | $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); |
| 1970 | 5902 | acydburn | $db->sql_query($sql); |
| 1971 | 5902 | acydburn | $data['post_id'] = $db->sql_nextid(); |
| 1972 | 5902 | acydburn | |
| 1973 | 5902 | acydburn | if ($post_mode == 'post') |
| 1974 | 5902 | acydburn | {
|
| 1975 | 5902 | acydburn | $sql_data[TOPICS_TABLE]['sql'] = array( |
| 1976 | 7491 | acydburn | 'topic_first_post_id' => $data['post_id'], |
| 1977 | 7491 | acydburn | 'topic_last_post_id' => $data['post_id'], |
| 1978 | 7491 | acydburn | 'topic_last_post_time' => $current_time, |
| 1979 | 7491 | acydburn | 'topic_last_poster_id' => (int) $user->data['user_id'], |
| 1980 | 7491 | acydburn | 'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), |
| 1981 | 7744 | kellanved | 'topic_last_poster_colour' => $user->data['user_colour'], |
| 1982 | 8630 | Kellanved | 'topic_last_post_subject' => (string) $subject, |
| 1983 | 5902 | acydburn | ); |
| 1984 | 5902 | acydburn | } |
| 1985 | 5902 | acydburn | |
| 1986 | 5902 | acydburn | unset($sql_data[POSTS_TABLE]['sql']); |
| 1987 | 5902 | acydburn | } |
| 1988 | 5902 | acydburn | |
| 1989 | 5902 | acydburn | // Update the topics table
|
| 1990 | 5902 | acydburn | if (isset($sql_data[TOPICS_TABLE]['sql'])) |
| 1991 | 5902 | acydburn | {
|
| 1992 | 6015 | acydburn | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 1993 | 5902 | acydburn | SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' |
| 1994 | 6015 | acydburn | WHERE topic_id = ' . $data['topic_id']; |
| 1995 | 6015 | acydburn | $db->sql_query($sql); |
| 1996 | 5902 | acydburn | } |
| 1997 | 5902 | acydburn | |
| 1998 | 5902 | acydburn | // Update the posts table
|
| 1999 | 5902 | acydburn | if (isset($sql_data[POSTS_TABLE]['sql'])) |
| 2000 | 5902 | acydburn | {
|
| 2001 | 6015 | acydburn | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 2002 | 6238 | davidmj | SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' |
| 2003 | 6015 | acydburn | WHERE post_id = ' . $data['post_id']; |
| 2004 | 6015 | acydburn | $db->sql_query($sql); |
| 2005 | 5902 | acydburn | } |
| 2006 | 5902 | acydburn | |
| 2007 | 5902 | acydburn | // Update Poll Tables
|
| 2008 | 11555 | git-gate | if (isset($poll['poll_options'])) |
| 2009 | 5902 | acydburn | {
|
| 2010 | 5902 | acydburn | $cur_poll_options = array(); |
| 2011 | 5902 | acydburn | |
| 2012 | 11555 | git-gate | if ($mode == 'edit') |
| 2013 | 5902 | acydburn | {
|
| 2014 | 7267 | acydburn | $sql = 'SELECT * |
| 2015 | 7267 | acydburn | FROM ' . POLL_OPTIONS_TABLE . ' |
| 2016 | 5902 | acydburn | WHERE topic_id = ' . $data['topic_id'] . ' |
| 2017 | 5902 | acydburn | ORDER BY poll_option_id';
|
| 2018 | 5902 | acydburn | $result = $db->sql_query($sql); |
| 2019 | 5902 | acydburn | |
| 2020 | 5902 | acydburn | $cur_poll_options = array(); |
| 2021 | 5902 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 2022 | 5902 | acydburn | {
|
| 2023 | 5902 | acydburn | $cur_poll_options[] = $row; |
| 2024 | 5902 | acydburn | } |
| 2025 | 5902 | acydburn | $db->sql_freeresult($result); |
| 2026 | 5902 | acydburn | } |
| 2027 | 5902 | acydburn | |
| 2028 | 5902 | acydburn | $sql_insert_ary = array(); |
| 2029 | 8350 | acydburn | |
| 2030 | 5902 | acydburn | for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++) |
| 2031 | 5902 | acydburn | {
|
| 2032 | 8115 | kellanved | if (strlen(trim($poll['poll_options'][$i]))) |
| 2033 | 5902 | acydburn | {
|
| 2034 | 5957 | acydburn | if (empty($cur_poll_options[$i])) |
| 2035 | 5902 | acydburn | {
|
| 2036 | 7267 | acydburn | // If we add options we need to put them to the end to be able to preserve votes...
|
| 2037 | 5902 | acydburn | $sql_insert_ary[] = array( |
| 2038 | 7267 | acydburn | 'poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary), |
| 2039 | 5902 | acydburn | 'topic_id' => (int) $data['topic_id'], |
| 2040 | 5902 | acydburn | 'poll_option_text' => (string) $poll['poll_options'][$i] |
| 2041 | 5902 | acydburn | ); |
| 2042 | 5902 | acydburn | } |
| 2043 | 5902 | acydburn | else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) |
| 2044 | 5902 | acydburn | {
|
| 2045 | 7267 | acydburn | $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . " |
| 2046 | 5902 | acydburn | SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' |
| 2047 | 7267 | acydburn | WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . ' |
| 2048 | 7267 | acydburn | AND topic_id = ' . $data['topic_id']; |
| 2049 | 5902 | acydburn | $db->sql_query($sql); |
| 2050 | 5902 | acydburn | } |
| 2051 | 5902 | acydburn | } |
| 2052 | 5902 | acydburn | } |
| 2053 | 5902 | acydburn | |
| 2054 | 6497 | acydburn | $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary); |
| 2055 | 5902 | acydburn | |
| 2056 | 5902 | acydburn | if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) |
| 2057 | 5902 | acydburn | {
|
| 2058 | 5902 | acydburn | $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' |
| 2059 | 8115 | kellanved | WHERE poll_option_id > ' . sizeof($poll['poll_options']) . ' |
| 2060 | 5902 | acydburn | AND topic_id = ' . $data['topic_id']; |
| 2061 | 5902 | acydburn | $db->sql_query($sql); |
| 2062 | 5902 | acydburn | } |
| 2063 | 7267 | acydburn | |
| 2064 | 7267 | acydburn | // If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option
|
| 2065 | 7267 | acydburn | if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options)) |
| 2066 | 7267 | acydburn | {
|
| 2067 | 7267 | acydburn | $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']); |
| 2068 | 7267 | acydburn | $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']); |
| 2069 | 7267 | acydburn | } |
| 2070 | 5902 | acydburn | } |
| 2071 | 5902 | acydburn | |
| 2072 | 5902 | acydburn | // Submit Attachments
|
| 2073 | 6414 | acydburn | if (!empty($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) |
| 2074 | 5902 | acydburn | {
|
| 2075 | 5902 | acydburn | $space_taken = $files_added = 0; |
| 2076 | 6364 | acydburn | $orphan_rows = array(); |
| 2077 | 5902 | acydburn | |
| 2078 | 5902 | acydburn | foreach ($data['attachment_data'] as $pos => $attach_row) |
| 2079 | 5902 | acydburn | {
|
| 2080 | 6364 | acydburn | $orphan_rows[(int) $attach_row['attach_id']] = array(); |
| 2081 | 6364 | acydburn | } |
| 2082 | 6364 | acydburn | |
| 2083 | 6364 | acydburn | if (sizeof($orphan_rows)) |
| 2084 | 6364 | acydburn | {
|
| 2085 | 6364 | acydburn | $sql = 'SELECT attach_id, filesize, physical_filename |
| 2086 | 6364 | acydburn | FROM ' . ATTACHMENTS_TABLE . ' |
| 2087 | 6364 | acydburn | WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . ' |
| 2088 | 6364 | acydburn | AND is_orphan = 1 |
| 2089 | 6364 | acydburn | AND poster_id = ' . $user->data['user_id']; |
| 2090 | 6364 | acydburn | $result = $db->sql_query($sql); |
| 2091 | 6364 | acydburn | |
| 2092 | 6364 | acydburn | $orphan_rows = array(); |
| 2093 | 6364 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 2094 | 5902 | acydburn | {
|
| 2095 | 6364 | acydburn | $orphan_rows[$row['attach_id']] = $row; |
| 2096 | 6364 | acydburn | } |
| 2097 | 6364 | acydburn | $db->sql_freeresult($result); |
| 2098 | 6364 | acydburn | } |
| 2099 | 6364 | acydburn | |
| 2100 | 6364 | acydburn | foreach ($data['attachment_data'] as $pos => $attach_row) |
| 2101 | 6364 | acydburn | {
|
| 2102 | 8350 | acydburn | if ($attach_row['is_orphan'] && !isset($orphan_rows[$attach_row['attach_id']])) |
| 2103 | 6364 | acydburn | {
|
| 2104 | 6364 | acydburn | continue;
|
| 2105 | 6364 | acydburn | } |
| 2106 | 6364 | acydburn | |
| 2107 | 6364 | acydburn | if (!$attach_row['is_orphan']) |
| 2108 | 6364 | acydburn | {
|
| 2109 | 5902 | acydburn | // update entry in db if attachment already stored in db and filespace
|
| 2110 | 5902 | acydburn | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . " |
| 2111 | 6177 | acydburn | SET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "' |
| 2112 | 6364 | acydburn | WHERE attach_id = " . (int) $attach_row['attach_id'] . ' |
| 2113 | 6364 | acydburn | AND is_orphan = 0';
|
| 2114 | 5902 | acydburn | $db->sql_query($sql); |
| 2115 | 5902 | acydburn | } |
| 2116 | 5902 | acydburn | else
|
| 2117 | 5902 | acydburn | {
|
| 2118 | 5902 | acydburn | // insert attachment into db
|
| 2119 | 9905 | acydburn | if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename']))) |
| 2120 | 5902 | acydburn | {
|
| 2121 | 5902 | acydburn | continue;
|
| 2122 | 5902 | acydburn | } |
| 2123 | 6015 | acydburn | |
| 2124 | 6364 | acydburn | $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize']; |
| 2125 | 6364 | acydburn | $files_added++;
|
| 2126 | 6364 | acydburn | |
| 2127 | 5902 | acydburn | $attach_sql = array( |
| 2128 | 5902 | acydburn | 'post_msg_id' => $data['post_id'], |
| 2129 | 5902 | acydburn | 'topic_id' => $data['topic_id'], |
| 2130 | 6364 | acydburn | 'is_orphan' => 0, |
| 2131 | 5902 | acydburn | 'poster_id' => $poster_id, |
| 2132 | 6177 | acydburn | 'attach_comment' => $attach_row['attach_comment'], |
| 2133 | 5902 | acydburn | ); |
| 2134 | 5902 | acydburn | |
| 2135 | 6364 | acydburn | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' |
| 2136 | 6364 | acydburn | WHERE attach_id = ' . $attach_row['attach_id'] . ' |
| 2137 | 6364 | acydburn | AND is_orphan = 1 |
| 2138 | 6364 | acydburn | AND poster_id = ' . $user->data['user_id']; |
| 2139 | 5902 | acydburn | $db->sql_query($sql); |
| 2140 | 5902 | acydburn | } |
| 2141 | 5902 | acydburn | } |
| 2142 | 5902 | acydburn | |
| 2143 | 6364 | acydburn | if ($space_taken && $files_added) |
| 2144 | 5902 | acydburn | {
|
| 2145 | 9398 | acydburn | set_config_count('upload_dir_size', $space_taken, true); |
| 2146 | 9398 | acydburn | set_config_count('num_files', $files_added, true); |
| 2147 | 5902 | acydburn | } |
| 2148 | 5902 | acydburn | } |
| 2149 | 5902 | acydburn | |
| 2150 | 7507 | davidmj | // we need to update the last forum information
|
| 2151 | 11100 | git-gate | // only applicable if the topic is approved
|
| 2152 | 11100 | git-gate | if ($post_approved || !$data['post_approved']) |
| 2153 | 5902 | acydburn | {
|
| 2154 | 7507 | davidmj | // the last post makes us update the forum table. This can happen if...
|
| 2155 | 7507 | davidmj | // We make a new topic
|
| 2156 | 7507 | davidmj | // We reply to a topic
|
| 2157 | 7507 | davidmj | // We edit the last post in a topic and this post is the latest in the forum (maybe)
|
| 2158 | 7831 | davidmj | // We edit the only post in the topic
|
| 2159 | 7831 | davidmj | // We edit the first post in the topic and all the other posts are not approved
|
| 2160 | 7522 | davidmj | if (($post_mode == 'post' || $post_mode == 'reply') && $post_approved) |
| 2161 | 5902 | acydburn | {
|
| 2162 | 7507 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; |
| 2163 | 7507 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; |
| 2164 | 7507 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; |
| 2165 | 7507 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; |
| 2166 | 7507 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; |
| 2167 | 7744 | kellanved | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; |
| 2168 | 7507 | davidmj | } |
| 2169 | 7831 | davidmj | else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) |
| 2170 | 7507 | davidmj | {
|
| 2171 | 7831 | davidmj | // this does not _necessarily_ mean that we must update the info again,
|
| 2172 | 7507 | davidmj | // it just means that we might have to
|
| 2173 | 7509 | kellanved | $sql = 'SELECT forum_last_post_id, forum_last_post_subject |
| 2174 | 7507 | davidmj | FROM ' . FORUMS_TABLE . ' |
| 2175 | 7507 | davidmj | WHERE forum_id = ' . (int) $data['forum_id']; |
| 2176 | 7507 | davidmj | $result = $db->sql_query($sql); |
| 2177 | 7507 | davidmj | $row = $db->sql_fetchrow($result); |
| 2178 | 7507 | davidmj | $db->sql_freeresult($result); |
| 2179 | 7507 | davidmj | |
| 2180 | 7831 | davidmj | // this post is the latest post in the forum, better update
|
| 2181 | 7522 | davidmj | if ($row['forum_last_post_id'] == $data['post_id']) |
| 2182 | 7441 | davidmj | {
|
| 2183 | 9166 | acydburn | // If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows
|
| 2184 | 9166 | acydburn | if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) |
| 2185 | 7522 | davidmj | {
|
| 2186 | 9166 | acydburn | // the post's subject changed
|
| 2187 | 9166 | acydburn | if ($row['forum_last_post_subject'] !== $subject) |
| 2188 | 9166 | acydburn | {
|
| 2189 | 9166 | acydburn | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\''; |
| 2190 | 9166 | acydburn | } |
| 2191 | 9166 | acydburn | |
| 2192 | 9166 | acydburn | // Update the user name if poster is anonymous... just in case an admin changed it
|
| 2193 | 9166 | acydburn | if ($data['poster_id'] == ANONYMOUS) |
| 2194 | 9166 | acydburn | {
|
| 2195 | 9166 | acydburn | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; |
| 2196 | 9166 | acydburn | } |
| 2197 | 7522 | davidmj | } |
| 2198 | 7522 | davidmj | else if ($data['post_approved'] !== $post_approved) |
| 2199 | 7522 | davidmj | {
|
| 2200 | 7522 | davidmj | // we need a fresh change of socks, everything has become invalidated
|
| 2201 | 7522 | davidmj | $sql = 'SELECT MAX(topic_last_post_id) as last_post_id |
| 2202 | 7522 | davidmj | FROM ' . TOPICS_TABLE . ' |
| 2203 | 7522 | davidmj | WHERE forum_id = ' . (int) $data['forum_id'] . ' |
| 2204 | 7522 | davidmj | AND topic_approved = 1';
|
| 2205 | 7522 | davidmj | $result = $db->sql_query($sql); |
| 2206 | 7522 | davidmj | $row = $db->sql_fetchrow($result); |
| 2207 | 7522 | davidmj | $db->sql_freeresult($result); |
| 2208 | 7522 | davidmj | |
| 2209 | 7522 | davidmj | // any posts left in this forum?
|
| 2210 | 7522 | davidmj | if (!empty($row['last_post_id'])) |
| 2211 | 7522 | davidmj | {
|
| 2212 | 7522 | davidmj | $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour |
| 2213 | 7522 | davidmj | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
| 2214 | 7522 | davidmj | WHERE p.poster_id = u.user_id |
| 2215 | 7522 | davidmj | AND p.post_id = ' . (int) $row['last_post_id']; |
| 2216 | 7522 | davidmj | $result = $db->sql_query($sql); |
| 2217 | 7522 | davidmj | $row = $db->sql_fetchrow($result); |
| 2218 | 7522 | davidmj | $db->sql_freeresult($result); |
| 2219 | 7522 | davidmj | |
| 2220 | 7522 | davidmj | // salvation, a post is found! jam it into the forums table
|
| 2221 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id']; |
| 2222 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; |
| 2223 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time']; |
| 2224 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id']; |
| 2225 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; |
| 2226 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; |
| 2227 | 7522 | davidmj | } |
| 2228 | 7522 | davidmj | else
|
| 2229 | 7522 | davidmj | {
|
| 2230 | 7831 | davidmj | // just our luck, the last topic in the forum has just been turned unapproved...
|
| 2231 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0'; |
| 2232 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''"; |
| 2233 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0'; |
| 2234 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0'; |
| 2235 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''"; |
| 2236 | 7522 | davidmj | $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''"; |
| 2237 | 7522 | davidmj | } |
| 2238 | 7522 | davidmj | } |
| 2239 | 5902 | acydburn | } |
| 2240 | 5902 | acydburn | } |
| 2241 | 7507 | davidmj | } |
| 2242 | 5902 | acydburn | |
| 2243 | 7507 | davidmj | // topic sync time!
|
| 2244 | 7507 | davidmj | // simply, we update if it is a reply or the last post is edited
|
| 2245 | 7507 | davidmj | if ($post_approved) |
| 2246 | 5902 | acydburn | {
|
| 2247 | 7507 | davidmj | // reply requires the whole thing
|
| 2248 | 7507 | davidmj | if ($post_mode == 'reply') |
| 2249 | 5902 | acydburn | {
|
| 2250 | 7507 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $data['post_id']; |
| 2251 | 7507 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $user->data['user_id']; |
| 2252 | 7507 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; |
| 2253 | 7507 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . (($user->data['user_id'] != ANONYMOUS) ? $db->sql_escape($user->data['user_colour']) : '') . "'"; |
| 2254 | 7507 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; |
| 2255 | 7511 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $current_time; |
| 2256 | 5902 | acydburn | } |
| 2257 | 7831 | davidmj | else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) |
| 2258 | 7507 | davidmj | {
|
| 2259 | 7507 | davidmj | // only the subject can be changed from edit
|
| 2260 | 7507 | davidmj | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; |
| 2261 | 9166 | acydburn | |
| 2262 | 9166 | acydburn | // Maybe not only the subject, but also changing anonymous usernames. ;)
|
| 2263 | 9166 | acydburn | if ($data['poster_id'] == ANONYMOUS) |
| 2264 | 9166 | acydburn | {
|
| 2265 | 9166 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'"; |
| 2266 | 9166 | acydburn | } |
| 2267 | 7507 | davidmj | } |
| 2268 | 5902 | acydburn | } |
| 2269 | 7831 | davidmj | else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) |
| 2270 | 7521 | acydburn | {
|
| 2271 | 7521 | acydburn | // like having the rug pulled from under us
|
| 2272 | 7521 | acydburn | $sql = 'SELECT MAX(post_id) as last_post_id |
| 2273 | 7521 | acydburn | FROM ' . POSTS_TABLE . ' |
| 2274 | 7521 | acydburn | WHERE topic_id = ' . (int) $data['topic_id'] . ' |
| 2275 | 7521 | acydburn | AND post_approved = 1';
|
| 2276 | 7521 | acydburn | $result = $db->sql_query($sql); |
| 2277 | 7521 | acydburn | $row = $db->sql_fetchrow($result); |
| 2278 | 7521 | acydburn | $db->sql_freeresult($result); |
| 2279 | 5902 | acydburn | |
| 2280 | 7521 | acydburn | // any posts left in this forum?
|
| 2281 | 7521 | acydburn | if (!empty($row['last_post_id'])) |
| 2282 | 7521 | acydburn | {
|
| 2283 | 7521 | acydburn | $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour |
| 2284 | 7521 | acydburn | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
| 2285 | 7521 | acydburn | WHERE p.poster_id = u.user_id |
| 2286 | 7521 | acydburn | AND p.post_id = ' . (int) $row['last_post_id']; |
| 2287 | 7521 | acydburn | $result = $db->sql_query($sql); |
| 2288 | 7521 | acydburn | $row = $db->sql_fetchrow($result); |
| 2289 | 7521 | acydburn | $db->sql_freeresult($result); |
| 2290 | 7521 | acydburn | |
| 2291 | 7856 | davidmj | // salvation, a post is found! jam it into the topics table
|
| 2292 | 7521 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $row['post_id']; |
| 2293 | 7521 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; |
| 2294 | 7521 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $row['post_time']; |
| 2295 | 7521 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $row['poster_id']; |
| 2296 | 7521 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; |
| 2297 | 7521 | acydburn | $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; |
| 2298 | 7521 | acydburn | } |
| 2299 | 7521 | acydburn | } |
| 2300 | 7521 | acydburn | |
| 2301 | 5902 | acydburn | // Update total post count, do not consider moderated posts/topics
|
| 2302 | 8805 | acydburn | if ($post_approval) |
| 2303 | 5902 | acydburn | {
|
| 2304 | 5902 | acydburn | if ($post_mode == 'post') |
| 2305 | 5902 | acydburn | {
|
| 2306 | 9398 | acydburn | set_config_count('num_topics', 1, true); |
| 2307 | 9398 | acydburn | set_config_count('num_posts', 1, true); |
| 2308 | 5902 | acydburn | } |
| 2309 | 5902 | acydburn | |
| 2310 | 5902 | acydburn | if ($post_mode == 'reply') |
| 2311 | 5902 | acydburn | {
|
| 2312 | 9398 | acydburn | set_config_count('num_posts', 1, true); |
| 2313 | 5902 | acydburn | } |
| 2314 | 5902 | acydburn | } |
| 2315 | 5902 | acydburn | |
| 2316 | 5902 | acydburn | // Update forum stats
|
| 2317 | 8805 | acydburn | $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id); |
| 2318 | 5902 | acydburn | |
| 2319 | 5902 | acydburn | foreach ($sql_data as $table => $update_ary) |
| 2320 | 5902 | acydburn | {
|
| 2321 | 5902 | acydburn | if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) |
| 2322 | 5902 | acydburn | {
|
| 2323 | 7491 | acydburn | $sql = "UPDATE $table SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]; |
| 2324 | 7491 | acydburn | $db->sql_query($sql); |
| 2325 | 5902 | acydburn | } |
| 2326 | 5902 | acydburn | } |
| 2327 | 5902 | acydburn | |
| 2328 | 5902 | acydburn | // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
|
| 2329 | 11100 | git-gate | if ($topic_type == POST_GLOBAL) |
| 2330 | 5902 | acydburn | {
|
| 2331 | 6015 | acydburn | $sql = 'DELETE FROM ' . TOPICS_TABLE . ' |
| 2332 | 6015 | acydburn | WHERE topic_moved_id = ' . $data['topic_id']; |
| 2333 | 6015 | acydburn | $db->sql_query($sql); |
| 2334 | 5902 | acydburn | } |
| 2335 | 5902 | acydburn | |
| 2336 | 7946 | acydburn | // Committing the transaction before updating search index
|
| 2337 | 7946 | acydburn | $db->sql_transaction('commit'); |
| 2338 | 7946 | acydburn | |
| 2339 | 7946 | acydburn | // Delete draft if post was loaded...
|
| 2340 | 7946 | acydburn | $draft_id = request_var('draft_loaded', 0); |
| 2341 | 7946 | acydburn | if ($draft_id) |
| 2342 | 7946 | acydburn | {
|
| 2343 | 7946 | acydburn | $sql = 'DELETE FROM ' . DRAFTS_TABLE . " |
| 2344 | 7946 | acydburn | WHERE draft_id = $draft_id |
| 2345 | 7946 | acydburn | AND user_id = {$user->data['user_id']}"; |
| 2346 | 7946 | acydburn | $db->sql_query($sql); |
| 2347 | 7946 | acydburn | } |
| 2348 | 7946 | acydburn | |
| 2349 | 5902 | acydburn | // Index message contents
|
| 2350 | 9959 | acydburn | if ($update_search_index && $data['enable_indexing']) |
| 2351 | 5902 | acydburn | {
|
| 2352 | 5902 | acydburn | // Select the search method and do some additional checks to ensure it can actually be utilised
|
| 2353 | 11557 | git-gate | $search_type = $config['search_type']; |
| 2354 | 6015 | acydburn | |
| 2355 | 11557 | git-gate | if (!class_exists($search_type)) |
| 2356 | 5902 | acydburn | {
|
| 2357 | 5902 | acydburn | trigger_error('NO_SUCH_SEARCH_MODULE'); |
| 2358 | 5902 | acydburn | } |
| 2359 | 6015 | acydburn | |
| 2360 | 5902 | acydburn | $error = false; |
| 2361 | 5902 | acydburn | $search = new $search_type($error); |
| 2362 | 6015 | acydburn | |
| 2363 | 5902 | acydburn | if ($error) |
| 2364 | 5902 | acydburn | {
|
| 2365 | 5902 | acydburn | trigger_error($error); |
| 2366 | 5902 | acydburn | } |
| 2367 | 5902 | acydburn | |
| 2368 | 11100 | git-gate | $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $data['forum_id']); |
| 2369 | 5902 | acydburn | } |
| 2370 | 5902 | acydburn | |
| 2371 | 5902 | acydburn | // Topic Notification, do not change if moderator is changing other users posts...
|
| 2372 | 5902 | acydburn | if ($user->data['user_id'] == $poster_id) |
| 2373 | 5902 | acydburn | {
|
| 2374 | 5902 | acydburn | if (!$data['notify_set'] && $data['notify']) |
| 2375 | 5902 | acydburn | {
|
| 2376 | 5902 | acydburn | $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id) |
| 2377 | 5902 | acydburn | VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')'; |
| 2378 | 5902 | acydburn | $db->sql_query($sql); |
| 2379 | 5902 | acydburn | } |
| 2380 | 10558 | git-gate | else if (($config['email_enable'] || $config['jab_enable']) && $data['notify_set'] && !$data['notify']) |
| 2381 | 5902 | acydburn | {
|
| 2382 | 5902 | acydburn | $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . ' |
| 2383 | 5902 | acydburn | WHERE user_id = ' . $user->data['user_id'] . ' |
| 2384 | 5902 | acydburn | AND topic_id = ' . $data['topic_id']; |
| 2385 | 5902 | acydburn | $db->sql_query($sql); |
| 2386 | 5902 | acydburn | } |
| 2387 | 5902 | acydburn | } |
| 2388 | 5902 | acydburn | |
| 2389 | 5902 | acydburn | if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') |
| 2390 | 5902 | acydburn | {
|
| 2391 | 5902 | acydburn | // Mark this topic as posted to
|
| 2392 | 10751 | git-gate | markread('post', $data['forum_id'], $data['topic_id']); |
| 2393 | 5902 | acydburn | } |
| 2394 | 5902 | acydburn | |
| 2395 | 5902 | acydburn | // Mark this topic as read
|
| 2396 | 5902 | acydburn | // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
|
| 2397 | 11100 | git-gate | markread('topic', $data['forum_id'], $data['topic_id'], time()); |
| 2398 | 5902 | acydburn | |
| 2399 | 6256 | acydburn | //
|
| 2400 | 6256 | acydburn | if ($config['load_db_lastread'] && $user->data['is_registered']) |
| 2401 | 6256 | acydburn | {
|
| 2402 | 6256 | acydburn | $sql = 'SELECT mark_time |
| 2403 | 6256 | acydburn | FROM ' . FORUMS_TRACK_TABLE . ' |
| 2404 | 6256 | acydburn | WHERE user_id = ' . $user->data['user_id'] . ' |
| 2405 | 11100 | git-gate | AND forum_id = ' . $data['forum_id']; |
| 2406 | 6256 | acydburn | $result = $db->sql_query($sql); |
| 2407 | 6256 | acydburn | $f_mark_time = (int) $db->sql_fetchfield('mark_time'); |
| 2408 | 6256 | acydburn | $db->sql_freeresult($result); |
| 2409 | 6256 | acydburn | } |
| 2410 | 6256 | acydburn | else if ($config['load_anon_lastread'] || $user->data['is_registered']) |
| 2411 | 6256 | acydburn | {
|
| 2412 | 6256 | acydburn | $f_mark_time = false; |
| 2413 | 6256 | acydburn | } |
| 2414 | 6256 | acydburn | |
| 2415 | 6299 | davidmj | if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered']) |
| 2416 | 6256 | acydburn | {
|
| 2417 | 6256 | acydburn | // Update forum info
|
| 2418 | 11100 | git-gate | $sql = 'SELECT forum_last_post_time |
| 2419 | 11100 | git-gate | FROM ' . FORUMS_TABLE . ' |
| 2420 | 11100 | git-gate | WHERE forum_id = ' . $data['forum_id']; |
| 2421 | 6256 | acydburn | $result = $db->sql_query($sql); |
| 2422 | 6256 | acydburn | $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time'); |
| 2423 | 6256 | acydburn | $db->sql_freeresult($result); |
| 2424 | 6256 | acydburn | |
| 2425 | 11100 | git-gate | update_forum_tracking_info($data['forum_id'], $forum_last_post_time, $f_mark_time, false); |
| 2426 | 6256 | acydburn | } |
| 2427 | 6256 | acydburn | |
| 2428 | 5902 | acydburn | // Send Notifications
|
| 2429 | 10787 | git-gate | if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) |
| 2430 | 5902 | acydburn | {
|
| 2431 | 5902 | acydburn | user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); |
| 2432 | 5902 | acydburn | } |
| 2433 | 5902 | acydburn | |
| 2434 | 7514 | acydburn | $params = $add_anchor = ''; |
| 2435 | 7491 | acydburn | |
| 2436 | 8805 | acydburn | if ($post_approval) |
| 2437 | 5902 | acydburn | {
|
| 2438 | 7491 | acydburn | $params .= '&t=' . $data['topic_id']; |
| 2439 | 7491 | acydburn | |
| 2440 | 7491 | acydburn | if ($mode != 'post') |
| 2441 | 7491 | acydburn | {
|
| 2442 | 7491 | acydburn | $params .= '&p=' . $data['post_id']; |
| 2443 | 7494 | shs | $add_anchor = '#p' . $data['post_id']; |
| 2444 | 7491 | acydburn | } |
| 2445 | 5902 | acydburn | } |
| 2446 | 7519 | acydburn | else if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic') |
| 2447 | 5902 | acydburn | {
|
| 2448 | 7491 | acydburn | $params .= '&t=' . $data['topic_id']; |
| 2449 | 5902 | acydburn | } |
| 2450 | 5902 | acydburn | |
| 2451 | 7514 | acydburn | $url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx"; |
| 2452 | 7514 | acydburn | $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor; |
| 2453 | 7491 | acydburn | |
| 2454 | 5902 | acydburn | return $url; |
| 2455 | 5902 | acydburn | } |
| 2456 | 11199 | git-gate | |
| 2457 | 11199 | git-gate | /**
|
| 2458 | 11199 | git-gate | * Handle topic bumping |
| 2459 | 11199 | git-gate | * @param int $forum_id The ID of the forum the topic is being bumped belongs to |
| 2460 | 11199 | git-gate | * @param int $topic_id The ID of the topic is being bumping |
| 2461 | 11199 | git-gate | * @param array $post_data Passes some topic parameters: |
| 2462 | 11199 | git-gate | * - 'topic_title' |
| 2463 | 11199 | git-gate | * - 'topic_last_post_id' |
| 2464 | 11199 | git-gate | * - 'topic_last_poster_id' |
| 2465 | 11199 | git-gate | * - 'topic_last_post_subject' |
| 2466 | 11199 | git-gate | * - 'topic_last_poster_name' |
| 2467 | 11199 | git-gate | * - 'topic_last_poster_colour' |
| 2468 | 11199 | git-gate | * @param int $bump_time The time at which topic was bumped, usually it is a current time as obtained via time(). |
| 2469 | 11199 | git-gate | * @return string An URL to the bumped topic, example: ./viewtopic.php?forum_id=1&topic_id=2&p=3#p3 |
| 2470 | 11199 | git-gate | */ |
| 2471 | 11199 | git-gate | function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false) |
| 2472 | 11199 | git-gate | {
|
| 2473 | 11199 | git-gate | global $config, $db, $user, $phpEx, $phpbb_root_path; |
| 2474 | 11199 | git-gate | |
| 2475 | 11199 | git-gate | if ($bump_time === false) |
| 2476 | 11199 | git-gate | {
|
| 2477 | 11199 | git-gate | $bump_time = time(); |
| 2478 | 11199 | git-gate | } |
| 2479 | 11199 | git-gate | |
| 2480 | 11199 | git-gate | // Begin bumping
|
| 2481 | 11199 | git-gate | $db->sql_transaction('begin'); |
| 2482 | 11199 | git-gate | |
| 2483 | 11199 | git-gate | // Update the topic's last post post_time
|
| 2484 | 11199 | git-gate | $sql = 'UPDATE ' . POSTS_TABLE . " |
| 2485 | 11199 | git-gate | SET post_time = $bump_time |
| 2486 | 11199 | git-gate | WHERE post_id = {$post_data['topic_last_post_id']} |
| 2487 | 11199 | git-gate | AND topic_id = $topic_id"; |
| 2488 | 11199 | git-gate | $db->sql_query($sql); |
| 2489 | 11199 | git-gate | |
| 2490 | 11199 | git-gate | // Sync the topic's last post time, the rest of the topic's last post data isn't changed
|
| 2491 | 11199 | git-gate | $sql = 'UPDATE ' . TOPICS_TABLE . " |
| 2492 | 11199 | git-gate | SET topic_last_post_time = $bump_time, |
| 2493 | 11199 | git-gate | topic_bumped = 1, |
| 2494 | 11199 | git-gate | topic_bumper = " . $user->data['user_id'] . " |
| 2495 | 11199 | git-gate | WHERE topic_id = $topic_id"; |
| 2496 | 11199 | git-gate | $db->sql_query($sql); |
| 2497 | 11199 | git-gate | |
| 2498 | 11199 | git-gate | // Update the forum's last post info
|
| 2499 | 11199 | git-gate | $sql = 'UPDATE ' . FORUMS_TABLE . " |
| 2500 | 11199 | git-gate | SET forum_last_post_id = " . $post_data['topic_last_post_id'] . ", |
| 2501 | 11199 | git-gate | forum_last_poster_id = " . $post_data['topic_last_poster_id'] . ", |
| 2502 | 11199 | git-gate | forum_last_post_subject = '" . $db->sql_escape($post_data['topic_last_post_subject']) . "', |
| 2503 | 11199 | git-gate | forum_last_post_time = $bump_time, |
| 2504 | 11199 | git-gate | forum_last_poster_name = '" . $db->sql_escape($post_data['topic_last_poster_name']) . "', |
| 2505 | 11199 | git-gate | forum_last_poster_colour = '" . $db->sql_escape($post_data['topic_last_poster_colour']) . "' |
| 2506 | 11199 | git-gate | WHERE forum_id = $forum_id"; |
| 2507 | 11199 | git-gate | $db->sql_query($sql); |
| 2508 | 11199 | git-gate | |
| 2509 | 11199 | git-gate | // Update bumper's time of the last posting to prevent flood
|
| 2510 | 11199 | git-gate | $sql = 'UPDATE ' . USERS_TABLE . " |
| 2511 | 11199 | git-gate | SET user_lastpost_time = $bump_time |
| 2512 | 11199 | git-gate | WHERE user_id = " . $user->data['user_id']; |
| 2513 | 11199 | git-gate | $db->sql_query($sql); |
| 2514 | 11199 | git-gate | |
| 2515 | 11199 | git-gate | $db->sql_transaction('commit'); |
| 2516 | 11199 | git-gate | |
| 2517 | 11199 | git-gate | // Mark this topic as posted to
|
| 2518 | 11199 | git-gate | markread('post', $forum_id, $topic_id, $bump_time); |
| 2519 | 11199 | git-gate | |
| 2520 | 11199 | git-gate | // Mark this topic as read
|
| 2521 | 11199 | git-gate | markread('topic', $forum_id, $topic_id, $bump_time); |
| 2522 | 11199 | git-gate | |
| 2523 | 11199 | git-gate | // Update forum tracking info
|
| 2524 | 11199 | git-gate | if ($config['load_db_lastread'] && $user->data['is_registered']) |
| 2525 | 11199 | git-gate | {
|
| 2526 | 11199 | git-gate | $sql = 'SELECT mark_time |
| 2527 | 11199 | git-gate | FROM ' . FORUMS_TRACK_TABLE . ' |
| 2528 | 11199 | git-gate | WHERE user_id = ' . $user->data['user_id'] . ' |
| 2529 | 11199 | git-gate | AND forum_id = ' . $forum_id; |
| 2530 | 11199 | git-gate | $result = $db->sql_query($sql); |
| 2531 | 11199 | git-gate | $f_mark_time = (int) $db->sql_fetchfield('mark_time'); |
| 2532 | 11199 | git-gate | $db->sql_freeresult($result); |
| 2533 | 11199 | git-gate | } |
| 2534 | 11199 | git-gate | else if ($config['load_anon_lastread'] || $user->data['is_registered']) |
| 2535 | 11199 | git-gate | {
|
| 2536 | 11199 | git-gate | $f_mark_time = false; |
| 2537 | 11199 | git-gate | } |
| 2538 | 11199 | git-gate | |
| 2539 | 11199 | git-gate | if (($config['load_db_lastread'] && $user->data['is_registered']) || $config['load_anon_lastread'] || $user->data['is_registered']) |
| 2540 | 11199 | git-gate | {
|
| 2541 | 11199 | git-gate | // Update forum info
|
| 2542 | 11199 | git-gate | $sql = 'SELECT forum_last_post_time |
| 2543 | 11199 | git-gate | FROM ' . FORUMS_TABLE . ' |
| 2544 | 11199 | git-gate | WHERE forum_id = ' . $forum_id; |
| 2545 | 11199 | git-gate | $result = $db->sql_query($sql); |
| 2546 | 11199 | git-gate | $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time'); |
| 2547 | 11199 | git-gate | $db->sql_freeresult($result); |
| 2548 | 11199 | git-gate | |
| 2549 | 11199 | git-gate | update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time, false); |
| 2550 | 11199 | git-gate | } |
| 2551 | 11199 | git-gate | |
| 2552 | 11199 | git-gate | add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']); |
| 2553 | 11199 | git-gate | |
| 2554 | 11199 | git-gate | $url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}"; |
| 2555 | 11199 | git-gate | |
| 2556 | 11199 | git-gate | return $url; |
| 2557 | 11199 | git-gate | } |

