diff --git a/phpBB/common.php b/phpBB/common.php index 188f175366..afdd60a553 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -99,6 +99,7 @@ define('ITEM_MOVED', 2); define('POST_NORMAL', 0); define('POST_STICKY', 1); define('POST_ANNOUNCE', 2); +define('POST_GLOBAL', 3); // Lastread types define('TRACK_NORMAL', 0); // not used at the moment diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2ee615295b..6435617890 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -19,8 +19,7 @@ * ***************************************************************************/ -// Fill smiley templates (or just the variables) with smileys -// Either in a window or inline +// Fill smiley templates (or just the variables) with smileys, either in a window or inline function generate_smilies($mode) { global $SID, $auth, $db, $user, $config, $template; @@ -84,68 +83,22 @@ function generate_smilies($mode) } } -// DECODE TEXT -> This will/should be handled by bbcode.php eventually -function decode_text(&$message, $bbcode_uid) -{ - global $config; - - $server_protocol = ($config['cookie_secure']) ? 'https://' : 'http://'; - $server_port = ($config['server_port'] <> 80) ? ':' . trim($config['server_port']) . '/' : '/'; - - $search = array( - '
', - "[/*:m:$bbcode_uid]", - ":u:$bbcode_uid", - ":o:$bbcode_uid", - ":$bbcode_uid" - ); - $replace = array( - "\n", - '', - '', - '', - '' - ); - $message = str_replace($search, $replace, $message); - - $match = array( - '#.*?#', - '#.*?#', - '#.*?#', - '#.*?#', - '#bbcode_second_pass($message, $uid); - // If we allow users to disable display of emoticons - // we'll need an appropriate check and preg_replace here + // If we allow users to disable display of emoticons we'll need an appropriate + // check and preg_replace here $message = (empty($smilies) || empty($config['allow_smilies'])) ? preg_replace('#data['user_allowsmile']) || empty($config['enable_smilies'])) ? preg_replace('##', '\1', $user_sig) : str_replace('(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$censors['match'], \$censors['replace'], '\\0')", '>' . $user_sig . '<'), 1, -1)); } - $user_sig = '
_________________
' . str_replace("\n", '
', $user_sig); + $user_sig = str_replace("\n", '
', $user_sig); } else { $user_sig = ''; } -// $message = (empty($smilies) || empty($config['allow_smilies'])) ? preg_replace('#sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $post_id_array[] = intval($row['id']); - } - $db->sql_freeresult($result); - - if (!count($post_id_array)) + if (!($row = $db->sql_fetchrow($result))) { return; } + + do + { + $post_id_array[] = $row['id']; + } + while ($row = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); } if (!is_array($post_id_array)) @@ -296,20 +236,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' return; } - if (strstr($post_id_array, ', ')) - { - $post_id_array = explode(', ', $post_id_array); - } - else if (strstr($post_id_array, ',')) - { - $post_id_array = explode(',', $post_id_array); - } - else - { - $post_id = intval($post_id_array); - $post_id_array = array(); - $post_id_array[] = $post_id; - } + $post_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $post_id_array); } if (!count($post_id_array)) @@ -329,34 +256,22 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' GROUP BY attach_id'; $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $attach_id_array[] = intval($row['attach_id']); - } - $db->sql_freeresult($result); - - if (!count($attach_id_array)) + if (!($row = $db->sql_fetchrow($result))) { return; } + + do + { + $attach_id_array[] = $row['attach_id']; + } + while ($row = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); } if (!is_array($attach_id_array)) { - if (strstr($attach_id_array, ', ')) - { - $attach_id_array = explode(', ', $attach_id_array); - } - else if (strstr($attach_id_array, ',')) - { - $attach_id_array = explode(',', $attach_id_array); - } - else - { - $attach_id = intval($attach_id_array); - $attach_id_array = array(); - $attach_id_array[] = $attach_id; - } + $attach_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array); } if (!count($attach_id_array)) @@ -364,6 +279,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' return; } + // None of this is relevant to 2.2 as it stands I think if ($page == 'privmsgs') { $sql_id = 'privmsgs_id'; @@ -378,7 +294,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' while ($row = $db->sql_fetchrow($result)) { - switch (intval($row['privmsgs_type'])) + switch ($row['privmsgs_type']) { case PRIVMSGS_READ_MAIL: case PRIVMSGS_NEW_MAIL: @@ -420,9 +336,9 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' $sql_id = 'post_id'; } - $sql = "DELETE FROM " . ATTACHMENTS_TABLE . " - WHERE attach_id IN (" . implode(', ', $attach_id_array) . ") - AND $sql_id IN (" . implode(', ', $post_id_array) . ")"; + $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' + WHERE attach_id IN (' . implode(', ', $attach_id_array) . ") + AND $sql_id IN (" . implode(', ', $post_id_array) . ')'; $db->sql_query($sql); foreach ($attach_id_array as $attach_id) @@ -443,7 +359,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' while ($row = $db->sql_fetchrow($result)) { phpbb_unlink($row['physical_filename'], 'file', $config['use_ftp_upload']); - if (intval($row['thumbnail'])) + if ($row['thumbnail']) { phpbb_unlink($row['physical_filename'], 'thumbnail', $config['use_ftp_upload']); } @@ -487,7 +403,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' while ($row = $db->sql_fetchrow($result)) { - $topic_id = intval($row['topic_id']); + $topic_id = $row['topic_id']; $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " @@ -499,7 +415,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' while ($post_row = $db->sql_fetchrow($result2)) { - $post_ids[] = intval($post_row['post_id']); + $post_ids[] = $post_row['post_id']; } $db->sql_freeresult($result2); @@ -542,7 +458,7 @@ function delete_attachment($post_id_array = -1, $attach_id_array = -1, $page = ' // Upload Attachment - filedata is generated here function upload_attachment($filename) { - global $_POST, $_FILES, $auth, $user, $config, $db; + global $auth, $user, $config, $db; $filedata = array(); $filedata['error'] = array(); @@ -577,7 +493,7 @@ function upload_attachment($filename) $cat_id = $extensions[$filedata['extension']]['display_cat']; // check Filename - if ( preg_match("/[\\/:*?\"<>|]/i", $filename) ) + if (preg_match("#[\\/:*?\"<>|]#i", $filename)) { $filedata['error'][] = sprintf($user->lang['INVALID_FILENAME'], $filename); $filedata['post_attach'] = FALSE; @@ -597,11 +513,11 @@ function upload_attachment($filename) { list($width, $height) = getimagesize($file); - if ($width != 0 && $height != 0 && intval($config['img_max_width']) != 0 && intval($config['img_max_height']) != 0) + if ($width != 0 && $height != 0 && $config['img_max_width'] && $config['img_max_height']) { - if ($width > intval($config['img_max_width']) || $height > intval($attach_config['img_max_height'])) + if ($width > $config['img_max_width'] || $height > $attach_config['img_max_height']) { - $filedata['error'][] = sprintf($user->lang['Error_imagesize'], intval($attach_config['img_max_width']), intval($attach_config['img_max_height'])); + $filedata['error'][] = sprintf($user->lang['Error_imagesize'], $attach_config['img_max_width'], $attach_config['img_max_height']); $filedata['post_attach'] = false; return $filedata; } @@ -877,589 +793,6 @@ function phpbb_unlink($filename, $mode = 'file', $use_ftp = false) return $deleted; } - - - - - -// -// posting.php specific -// - - -// Submit Post -function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_uid, $poll, $attachment_data, $filename_data, $post_data) -{ - global $db, $auth, $user, $config, $phpEx, $SID, $template; - - $search = new fulltext_search(); - $current_time = time(); - - $post_data['subject'] = $subject; - - $db->sql_transaction(); - - // Initial Topic table info - if ( ($mode == 'post') || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_data['post_id'])) - { - $topic_sql = array( - 'forum_id' => $post_data['forum_id'], - 'topic_title' => stripslashes($subject), - 'topic_time' => $current_time, - 'topic_type' => $topic_type, - 'topic_approved' => ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1, - 'icon_id' => $post_data['icon_id'], - 'topic_attachment' => (sizeof($filename_data['physical_filename'])) ? 1 : 0 - ); - - if (!empty($poll['poll_options'])) - { - $topic_sql = array_merge($topic_sql, array( - 'poll_title' => stripslashes($poll['poll_title']), - 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time, - 'poll_max_options' => $poll['poll_max_options'], - 'poll_length' => $poll['poll_length'] * 86400) - ); - } - - if ($mode == 'post') - { - $topic_sql = array_merge($topic_sql, array( - 'topic_poster' => intval($user->data['user_id']), - 'topic_first_poster_name' => ($username != '') ? stripslashes($username) : (($user->data['user_id'] == ANONYMOUS) ? '' : stripslashes($user->data['username']))) - ); - } - - $sql = ($mode == 'post') ? 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $topic_sql) : 'UPDATE ' . TOPICS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $topic_sql) . ' WHERE topic_id = ' . $post_data['topic_id']; - $db->sql_query($sql); - - $post_data['topic_id'] = ($mode == 'post') ? $db->sql_nextid() : $post_data['topic_id']; - } - - // Post table info - $post_sql = array( - 'topic_id' => $post_data['topic_id'], - 'forum_id' => $post_data['forum_id'], - 'poster_id' => ($mode == 'edit') ? $post_data['poster_id'] : intval($user->data['user_id']), - 'post_username' => ($username != '') ? stripslashes($username) : '', - 'post_subject' => stripslashes($subject), - 'icon_id' => $post_data['icon_id'], - 'poster_ip' => $user->ip, - 'post_approved' => ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 0 : 1, - 'post_edit_time' => ($mode == 'edit' && $post_data['poster_id'] == $user->data['user_id']) ? $current_time : 0, - 'enable_sig' => $post_data['enable_sig'], - 'enable_bbcode' => $post_data['enable_bbcode'], - 'enable_html' => $post_data['enable_html'], - 'enable_smilies' => $post_data['enable_smilies'], - 'enable_magic_url' => $post_data['enable_urls'], - 'bbcode_uid' => $bbcode_uid, - 'bbcode_bitfield' => $post_data['bbcode_bitfield'], - 'post_edit_locked' => $post_data['post_edit_locked'], - 'post_text' => $message - ); - - if ($mode != 'edit') - { - $post_sql['post_time'] = $current_time; - } - - if ($mode != 'edit' || $post_data['message_md5'] != $post_data['post_checksum']) - { - $post_sql = array_merge($post_sql, array( - 'post_checksum' => $post_data['message_md5'], - 'post_encoding' => $user->lang['ENCODING']) - ); - } - - if ($mode == 'edit') - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $post_sql) . - (($post_data['poster_id'] == $user->data['user_id']) ? ' , post_edit_count = post_edit_count + 1' : '') . ' - WHERE post_id = ' . $post_data['post_id']; - } - else - { - $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . - $db->sql_build_array('INSERT', $post_sql); - } - $db->sql_query($sql); - - $post_data['post_id'] = ($mode == 'edit') ? $post_data['post_id'] : $db->sql_nextid(); - - // Submit Poll - if (!empty($poll['poll_options'])) - { - $cur_poll_options = array(); - - if ($poll['poll_start'] && $mode == 'edit') - { - $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' - WHERE topic_id = ' . $post_data['topic_id'] . ' - ORDER BY poll_option_id'; - $result = $db->sql_query($sql); - - while ($cur_poll_options[] = $db->sql_fetchrow($result)); - $db->sql_freeresult($result); - } - - for ($i = 0; $i < sizeof($poll['poll_options']); $i++) - { - if (trim($poll['poll_options'][$i]) != '') - { - if (empty($cur_poll_options[$i])) - { - $sql = 'INSERT INTO ' . POLL_OPTIONS_TABLE . " (poll_option_id, topic_id, poll_option_text) - VALUES ($i, " . $post_data['topic_id'] . ", '" . $db->sql_escape($poll['poll_options'][$i]) . "')"; - $db->sql_query($sql); - } - else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) - { - $sql = "UPDATE " . POLL_OPTIONS_TABLE . " - SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' - WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . " - AND topic_id = " . $post_data['topic_id']; - $db->sql_query($sql); - } - } - } - - if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) - { - $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' - WHERE poll_option_id > ' . sizeof($poll['poll_options']) . ' - AND topic_id = ' . $post_data['topic_id']; - $db->sql_query($sql); - } - } - - // Submit Attachments - if (count($attachment_data) && !empty($post_data['post_id']) && ($mode == 'post' || $mode == 'reply' || $mode == 'edit')) - { - foreach ($attachment_data as $attach_row) - { - if ($attach_row['attach_id'] != '-1') - { - // update entry in db if attachment already stored in db and filespace - $attach_sql = array( - 'comment' => trim($attach_row['comment']) - ); - - $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' - WHERE attach_id = ' . intval($attach_row['attach_id']); - $db->sql_query($sql); - } - else - { - // insert attachment into db - $attach_sql = array( - 'physical_filename' => $attach_row['physical_filename'], - 'real_filename' => $attach_row['real_filename'], - 'comment' => trim($attach_row['comment']), - 'extension' => $attach_row['extension'], - 'mimetype' => $attach_row['mimetype'], - 'filesize' => $attach_row['filesize'], - 'filetime' => $attach_row['filetime'], - 'thumbnail' => $attach_row['thumbnail'] - ); - - $sql = 'INSERT INTO ' . ATTACHMENTS_DESC_TABLE . ' ' . - $db->sql_build_array('INSERT', $attach_sql); - $db->sql_query($sql); - - $attach_sql = array( - 'attach_id' => $db->sql_nextid(), - 'post_id' => $post_data['post_id'], - 'privmsgs_id' => 0, - 'user_id_from' => ($mode == 'edit') ? $post_data['poster_id'] : intval($user->data['user_id']), - 'user_id_to' => 0 - ); - - $sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . - $db->sql_build_array('INSERT', $attach_sql); - $db->sql_query($sql); - } - } - - if (count($attachment_data)) - { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_attachment = 1 - WHERE post_id = ' . $post_data['post_id']; - $db->sql_query($sql); - - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_attachment = 1 - WHERE topic_id = ' . $post_data['topic_id']; - $db->sql_query($sql); - } - } - - // Fulltext parse - if ($post_data['message_md5'] != $post_data['post_checksum']) - { - $result = $search->add($mode, $post_data['post_id'], $message, $subject); - } - - // Sync forums, topics and users ... - if ($mode != 'edit') - { - $forum_topics_sql = ($mode == 'post') ? ', forum_topics = forum_topics + 1, forum_topics_real = forum_topics_real + 1' : ''; - $forum_sql = array( - 'forum_last_post_id' => $post_data['post_id'], - 'forum_last_post_time' => $current_time, - 'forum_last_poster_id' => intval($user->data['user_id']), - 'forum_last_poster_name'=> ($user->data['user_id'] == ANONYMOUS) ? stripslashes($username) : $user->data['username'], - ); - - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $forum_sql) . ', forum_posts = forum_posts + 1' . $forum_topics_sql . ' - WHERE forum_id = ' . $post_data['forum_id']; - $db->sql_query($sql); - - // Update topic: first/last post info, replies - $topic_sql = array( - 'topic_last_post_id' => $post_data['post_id'], - 'topic_last_post_time' => $current_time, - 'topic_last_poster_id' => intval($user->data['user_id']), - 'topic_last_poster_name'=> ($username != '') ? stripslashes($username) : (($user->data['user_id'] == ANONYMOUS) ? '' : stripslashes($user->data['username'])), - ); - - if ($mode == 'post') - { - $topic_sql = array_merge($topic_sql, array( - 'topic_first_post_id' => $post_data['post_id'], - )); - } - - $topic_replies_sql = ($mode == 'reply' || $mode == 'quote') ? ', topic_replies = topic_replies + 1, topic_replies_real = topic_replies_real + 1' : ''; - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $topic_sql) . $topic_replies_sql . ' - WHERE topic_id = ' . $post_data['topic_id']; - $db->sql_query($sql); - - // Update user post count ... if appropriate - if ($user->data['user_id'] != ANONYMOUS && $auth->acl_get('f_postcount', $post_data['forum_id'])) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_posts = user_posts + 1 - WHERE user_id = ' . intval($user->data['user_id']); - $db->sql_query($sql); - } - - // post counts for index, etc. - if ($mode == 'post') - { - set_config('num_topics', $config['num_topics'] + 1, TRUE); - } - - set_config('num_posts', $config['num_posts'] + 1, TRUE); - } - - // Topic Notification - if (($post_data['notify_set'] == 0 || $post_data['notify_set'] == -1) && $post_data['notify']) - { - $sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id) - VALUES (" . $user->data['user_id'] . ", " . $post_data['topic_id'] . ")"; - $db->sql_query($sql); - } - else if ($post_data['notify_set'] == 1 && !$post_data['notify']) - { - $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " - WHERE user_id = " . $user->data['user_id'] . " - AND topic_id = " . $post_data['topic_id']; - $db->sql_query($sql); - } - - // Mark this topic as read and posted to. - $mark_mode = ($mode == 'post' || $mode == 'reply' || $mode == 'quote') ? 'post' : 'topic'; - markread($mark_mode, $post_data['forum_id'], $post_data['topic_id'], $post_data['post_time']); - - $db->sql_transaction('commit'); - - // Send Notifications - if ($mode != 'edit' && $mode != 'delete') - { - user_notification($mode, stripslashes($post_data['subject']), $post_data['forum_id'], $post_data['topic_id'], $post_data['post_id']); - } - - meta_refresh(3, "viewtopic.$phpEx$SID&f=" . $post_data['forum_id'] . '&t=' . $post_data['topic_id'] . '&p=' . $post_data['post_id'] . '#' . $post_data['post_id']); - - $message = ($auth->acl_get('f_moderate', $post_data['forum_id']) && !$auth->acl_get('f_ignorequeue', $post_data['forum_id'])) ? 'POST_STORED_MOD' : 'POST_STORED'; - $message = $user->lang[$message] . '

' . sprintf($user->lang['VIEW_MESSAGE'], '', '') . '

' . sprintf($user->lang['RETURN_FORUM'], '', ''); - trigger_error($message); -} - -// User Notification -function user_notification($mode, $subject, $forum_id, $topic_id, $post_id) -{ - global $db, $user, $config, $phpEx; - - $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; - $newtopic_notification = ($mode == 'post') ? true : false; - - if (empty($censors)) - { - $censors = array(); - obtain_word_list($censors); - } - - // Get banned User ID's - $sql = "SELECT ban_userid - FROM " . BANLIST_TABLE; - $result = $db->sql_query($sql); - - $sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id']; - while ($row = $db->sql_fetchrow($result)) - { - if (isset($row['ban_userid'])) - { - $sql_ignore_users .= ', ' . $row['ban_userid']; - } - } - - $allowed_users = array(); - - $sql = "SELECT u.user_id - FROM " . TOPICS_WATCH_TABLE . " tw, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u - WHERE tw.topic_id = $topic_id - AND tw.user_id NOT IN ($sql_ignore_users) - AND t.topic_id = tw.topic_id - AND u.user_id = tw.user_id"; - $result = $db->sql_query($sql); - $ids = ''; - - while ($row = $db->sql_fetchrow($result)) - { - $ids .= ($ids != '') ? ', ' . $row['user_id'] : $row['user_id']; - } - $db->sql_freeresult($result); - - if ($ids != '') - { - // TODO: Paul - correct call to check f_read for specific users ? - $sql = "SELECT a.user_id - FROM " . ACL_OPTIONS_TABLE . " ao, " . ACL_USERS_TABLE . " a - WHERE a.user_id IN (" . $ids . ") - AND ao.auth_option_id = a.auth_option_id - AND ao.auth_option = 'f_read' - AND a.forum_id = " . $forum_id; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $allowed_users[] = $row['user_id']; - } - $db->sql_freeresult($result); - - - - - // TODO : Paul - // Now grab group settings ... users can belong to multiple groups so we grab - // the minimum setting for all options. ACL_NO overrides ACL_YES so act appropriatley - $sql = "SELECT ug.user_id, MIN(a.auth_setting) as min_setting - FROM " . USER_GROUP_TABLE . " ug, " . ACL_OPTIONS_TABLE . " ao, " . ACL_GROUPS_TABLE . " a - WHERE ug.user_id IN (" . $ids . ") - AND a.group_id = ug.group_id - AND ao.auth_option_id = a.auth_option_id - AND ao.auth_option = 'f_read' - AND a.forum_id = " . $forum_id . " - GROUP BY ao.auth_option, a.forum_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if ($row['min_setting'] == 1) - { - $allowed_users[] = $row['user_id']; - } - } - $db->sql_freeresult($result); - - $allowed_users = array_unique($allowed_users); - } - - - - - - // - if ($topic_notification) - { - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name - FROM ' . TOPICS_WATCH_TABLE . ' tw, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_TABLE . ' f - WHERE tw.topic_id = ' . $topic_id . ' - AND tw.user_id NOT IN (' . $sql_ignore_users . ') - AND tw.notify_status = 0 - AND f.forum_id = ' . $forum_id . ' - AND t.topic_id = tw.topic_id - AND u.user_id = tw.user_id'; - } - else if ($newtopic_notification) - { - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name - FROM ' . USERS_TABLE . ' u, ' . FORUMS_WATCH_TABLE . ' fw, ' . FORUMS_TABLE . ' f - WHERE fw.forum_id = ' . $forum_id . ' - AND fw.user_id NOT IN (' . $sql_ignore_users . ') - AND fw.notify_status = 0 - AND f.forum_id = fw.forum_id - AND u.user_id = fw.user_id'; - } - else - { - trigger_error('WRONG_NOTIFICATION_MODE'); - } - $result = $db->sql_query($sql); - - $email_users = array(); - $update_watched_sql_topic = $update_watched_sql_forum = $delete_users_topic = ''; - // - if ($row = $db->sql_fetchrow($result)) - { - if ($topic_notification) - { - decode_text($row['topic_title']); - $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $row['topic_title']) : $row['topic_title']; - } - else - { - decode_text($subject); - $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $subject) : $subject; - } - - $which_sql = ($topic_notification) ? 'update_watched_sql_topic' : 'update_watched_sql_forum'; - do - { - if (trim($row['user_email']) != '' && in_array($row['user_id'], $allowed_users)) - { - $row['email_template'] = ($topic_notification) ? 'topic_notify' : 'newtopic_notify'; - $email_users[] = $row; - - $$which_sql .= ($$which_sql != '') ? ', ' . $row['user_id'] : $row['user_id']; - } - else if (!in_array($row['user_id'], $allowed_users)) - { - $delete_users_topic .= ($delete_users_topic != '') ? ', ' . $row['user_id'] : $row['user_id']; - } - } - while ($row = $db->sql_fetchrow($result)); - } - $db->sql_freeresult($result); - - // Handle remaining Notifications (Forum) - if ($topic_notification) - { - $already_notified = ($update_watched_sql_topic == '') ? '' : $update_watched_sql_topic . ', '; - $already_notified .= ($update_watched_sql_forum == '') ? '' : $update_watched_sql_forum . ', '; - - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name - FROM ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_WATCH_TABLE . ' fw, ' . FORUMS_TABLE . ' f - WHERE fw.forum_id = ' . $forum_id . ' - AND fw.user_id NOT IN (' . $already_notified . ' ' . $sql_ignore_users . ') - AND fw.notify_status = 0 - AND t.topic_id = ' . $topic_id . ' - AND f.forum_id = fw.forum_id - AND u.user_id = fw.user_id'; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $forum_name = $row['forum_name']; - - do - { - if (trim($row['user_email']) != '') - { - $row['email_template'] = 'forum_notify'; - $email_users[] = $row; - - $update_watched_sql_forum .= ($update_watched_sql_forum != '') ? ', ' . $row['user_id'] : $row['user_id']; - } - } - while ($row = $db->sql_fetchrow($result)); - } - } - - // We are using an email queue here, no emails are sent now, only queued. - // Returned to use the TO-Header, default package size is 100 (should be admin-definable) !? - if (sizeof($email_users) && $config['email_enable']) - { - global $phpbb_root_path, $phpEx; - - @set_time_limit(60); - - include($phpbb_root_path . 'includes/emailer.'.$phpEx); - $emailer = new emailer(true); // use queue - - $email_list_ary = array(); - foreach ($email_users as $row) - { - $pos = sizeof($email_list_ary[$row['email_template']]); - $email_list_ary[$row['email_template']][$pos]['email'] = $row['user_email']; - $email_list_ary[$row['email_template']][$pos]['name'] = $row['username']; - $email_list_ary[$row['email_template']][$pos]['lang'] = $row['user_lang']; - } - unset($email_users); - - foreach ($email_list_ary as $email_template => $email_list) - { - foreach ($email_list as $addr) - { - $emailer->template($email_template, $addr['lang']); - - $emailer->replyto($config['board_email']); - $emailer->to($addr['email'], $addr['name']); - - $emailer->assign_vars(array( - 'EMAIL_SIG' => str_replace('
', "\n", "-- \n" . $config['board_email_sig']), - 'SITENAME' => $config['sitename'], - 'TOPIC_TITLE' => trim($topic_title), - 'FORUM_NAME' => trim($forum_name), - - 'U_TOPIC' => generate_board_url() . 'viewtopic.'.$phpEx . '?t=' . $topic_id . '&p=' . $post_id . '#' . $post_id, - 'U_FORUM' => generate_board_url() . 'viewforum.'.$phpEx . '?f=' . $forum_id, - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . 'viewtopic.'.$phpEx . '?t=' . $topic_id . '&unwatch=topic', - 'U_STOP_WATCHING_FORUM' => generate_board_url() . 'viewforum.'.$phpEx . '?f=' . $forum_id . '&unwatch=forum') - ); - - $emailer->send(); - $emailer->reset(); - } - } - - $emailer->queue->save(); - } - unset($email_list_ary); - - if ($delete_users_topic != '') - { - $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " - WHERE topic_id = " . $topic_id . " - AND user_id IN (" . $delete_users_topic . ")"; - $db->sql_query($sql); - } - - if ($update_watched_sql_topic != '') - { - $sql = "UPDATE " . TOPICS_WATCH_TABLE . " - SET notify_status = 1 - WHERE topic_id = " . $topic_id . " - AND user_id IN (" . $update_watched_sql_topic . ")"; - $db->sql_query($sql); - } - - if ($update_watched_sql_forum != '') - { - $sql = "UPDATE " . FORUMS_WATCH_TABLE . " - SET notify_status = 1 - WHERE forum_id = " . $forum_id . " - AND user_id IN (" . $update_watched_sql_forum . ")"; - $db->sql_query($sql); - } -} - // Read DWord (4 Bytes) from File function read_dword($fp) { @@ -1498,8 +831,7 @@ function image_getdimension($file) } // Try to get the Dimension manually, depending on the mimetype - $fp = @fopen($file, 'rb'); - if (!$fp) + if (!($fp = @fopen($file, 'rb'))) { return $size; } @@ -1848,11 +1180,11 @@ function create_thumbnail($source, $new_file, $mimetype) $used_imagick = FALSE; - if ($config['img_imagick'] != '') + if ($config['img_imagick']) { if (is_array($size) && count($size) > 0) { - @exec($config['img_imagick'] . ' -quality 75 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' ' . $source . ' +profile "*" ' . $new_file); + @exec($config['img_imagick'] . 'convert -quality 75 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' ' . $source . ' +profile "*" ' . $new_file); if (file_exists($new_file)) { $used_imagick = TRUE; @@ -1915,4 +1247,53 @@ function create_thumbnail($source, $new_file, $mimetype) } +// +// TODO +// + +// DECODE TEXT -> This will/should be handled by bbcode.php eventually +function decode_text(&$message, $bbcode_uid) +{ + global $config; + + $server_protocol = ($config['cookie_secure']) ? 'https://' : 'http://'; + $server_port = ($config['server_port'] <> 80) ? ':' . trim($config['server_port']) . '/' : '/'; + + $search = array( + '
', + "[/*:m:$bbcode_uid]", + ":u:$bbcode_uid", + ":o:$bbcode_uid", + ":$bbcode_uid" + ); + $replace = array( + "\n", + '', + '', + '', + '' + ); + $message = str_replace($search, $replace, $message); + + $match = array( + '#.*?#', + '#.*?#', + '#.*?#', + '#.*?#', + '#sql_query_limit($sql, $config['topics_per_page']); + $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { @@ -82,16 +96,31 @@ class ucp_main extends ucp $folder_new = 'folder_locked_new'; } - $unread_topic = ($user->data['user_id'] != ANONYMOUS) ? true : false; - if ($user->data['user_id'] != ANONYMOUS) - { - $topic_check = (!$config['load_db_lastread']) ? $tracking_topics[$topic_id] : $row['mark_time']; - $forum_check = (!$config['load_db_lastread']) ? $tracking_forums[$forum_id] : $track_data['mark_time']; + $unread_topic = true; - if ($topic_check > $row['topic_last_post_time'] || $forum_check > $row['topic_last_post_time']) + $topic_check = (!$config['load_db_lastread']) ? base_convert($tracking_topics[0][base_convert($topic_id, 10, 36)], 36, 10) + $config['board_startdate'] : $row['mark_time']; + + if (!$config['load_db_lastread']) + { + $forum_check = ''; + foreach ($tracking_topics as $forum_id => $tracking_time) { - $unread_topic = false; + if ($tracking_time[0] > $forum_check) + { + $forum_check = $tracking_time[0]; + } } + $forum_check = base_convert($forum_check, 36, 10) + $config['board_startdate']; + } + else + { + $forum_check = $track_data['mark_time']; + } + + + if ($topic_check > $row['topic_last_post_time'] || $forum_check > $row['topic_last_post_time']) + { + $unread_topic = false; } $newest_post_img = ($unread_topic) ? "" . $user->img('icon_post_newest', 'VIEW_NEWEST_POST') . ' ' : ''; @@ -106,7 +135,7 @@ class ucp_main extends ucp $view_topic_url = "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id"; - $last_post_img = "' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . ''; + $last_post_img = "' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . ''; $last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "' . $row['topic_last_poster_name'] . ''; @@ -277,22 +306,21 @@ class ucp_main extends ucp break; default: - $sql_lastread = 'LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)'; + $sql_from = '(' . FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id))'; break; } $lastread_select = ', ft.mark_time '; } else { - $sql_lastread = $lastread_select = ''; + $sql_from = FORUMS_TABLE . ' f '; + $lastread_select = ''; - $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_t'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_t']) : array(); - $tracking_forums = (isset($_COOKIE[$config['cookie_name'] . '_f'])) ? unserialize($_COOKIE[$config['cookie_name'] . '_f']) : array(); + $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? unserialize(stripslashes($_COOKIE[$config['cookie_name'] . '_track'])) : array(); } $sql = "SELECT f.*$lastread_select - FROM (" . FORUMS_TABLE . " f - $sql_lastread), " . FORUMS_WATCH_TABLE . ' fw + FROM $sql_from, " . FORUMS_WATCH_TABLE . ' fw WHERE fw.user_id = ' . $user->data['user_id'] . ' AND f.forum_id = fw.forum_id ORDER BY left_id'; @@ -304,7 +332,7 @@ class ucp_main extends ucp $forum_id = $row['forum_id']; $unread_forum = false; - $forum_check = (!$config['load_db_lastread']) ? $tracking_forums[$forum_id] : $row['mark_time']; + $forum_check = (!$config['load_db_lastread']) ? $tracking_topics[$forum_id][0] : $row['mark_time']; if ($forum_check < $row['forum_last_post_time']) { @@ -419,8 +447,8 @@ class ucp_main extends ucp $unread_topic = ($user->data['user_id'] != ANONYMOUS) ? true : false; if ($user->data['user_id'] != ANONYMOUS) { - $topic_check = (!$config['load_db_lastread']) ? $tracking_topics[$topic_id] : $row['mark_time']; - $forum_check = (!$config['load_db_lastread']) ? $tracking_forums[$forum_id] : $row['forum_mark_time']; + $topic_check = (!$config['load_db_lastread']) ? ((isset($tracking_topics[$forum_id][base_convert($topic_id, 10, 36)])) ? base_convert($tracking_topics[$forum_id36][$topic_id36], 36, 10) + $config['board_startdate'] : 0) : $row['mark_time']; + $forum_check = (!$config['load_db_lastread']) ? ((isset($tracking_topics[$forum_id][0])) ? base_convert($tracking_topics[$forum_id][0], 36, 10) + $config['board_startdate'] : 0) : $row['forum_mark_time']; if ($topic_check > $row['topic_last_post_time'] || $forum_check > $row['topic_last_post_time']) { @@ -438,20 +466,20 @@ class ucp_main extends ucp $folder_img .= '_posted'; } - if (($replies + 1) > intval($config['posts_per_page'])) + if (($replies + 1) > $config['posts_per_page']) { - $total_pages = ceil(($replies + 1) / intval($config['posts_per_page'])); + $total_pages = ceil(($replies + 1) / $config['posts_per_page']); $goto_page = ' [ ' . $user->img('icon_post', 'GOTO_PAGE') . $user->lang['GOTO_PAGE'] . ': '; $times = 1; - for($j = 0; $j < $replies + 1; $j += intval($config['posts_per_page'])) + for($j = 0; $j < $replies + 1; $j += $config['posts_per_page']) { $goto_page .= "$times"; if ($times == 1 && $total_pages > 4) { $goto_page .= ' ... '; $times = $total_pages - 3; - $j += ($total_pages - 4) * intval($config['posts_per_page']); + $j += ($total_pages - 4) * $config['posts_per_page']; } else if ($times < $total_pages) { diff --git a/phpBB/install/schemas/mysql_schema.sql b/phpBB/install/schemas/mysql_schema.sql index 2b6cc777bd..2202db9a35 100644 --- a/phpBB/install/schemas/mysql_schema.sql +++ b/phpBB/install/schemas/mysql_schema.sql @@ -585,10 +585,8 @@ CREATE TABLE phpbb_topics ( poll_last_vote int(11), PRIMARY KEY (topic_id), KEY forum_id (forum_id), - KEY topic_moved_id (topic_moved_id), + KEY forum_id_type (forum_id, topic_type), KEY topic_last_post_time (topic_last_post_time), - KEY poll_last_vote (poll_last_vote), - KEY topic_type (topic_type) ); # Table: 'phpbb_topic_marking' diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index da9c0b3750..ceee25cb86 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -157,7 +157,6 @@ INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_delete', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_poll', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_vote', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_votechg', 1); -INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_global', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_announce', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_sticky', 1); INSERT INTO phpbb_auth_options (auth_option, is_local) VALUES ('f_attach', 1); diff --git a/phpBB/language/en/lang_main.php b/phpBB/language/en/lang_main.php index 8fde775810..a840603bc2 100644 --- a/phpBB/language/en/lang_main.php +++ b/phpBB/language/en/lang_main.php @@ -359,8 +359,8 @@ $lang = array( 'POST_STICKY' => 'Sticky', - 'POST_ANNOUNCEMENT' => 'Announcement', - 'POST_GLOBAL' => 'Global announcement', + 'POST_ANNOUNCEMENT' => 'Announce', + 'POST_GLOBAL' => 'Global', 'POST_FORUM_LOCKED' => 'Forum is locked', 'POST_TOPIC_LOCKED' => 'Topic is locked', @@ -517,52 +517,82 @@ $lang = array( 'VIEW_TOPIC_POSTS' => '%d Posts', + 'BBCODE_B_HELP' => 'Bold text: [b]text[/b] (alt+b)', + 'BBCODE_I_HELP' => 'Italic text: [i]text[/i] (alt+i)', + 'BBCODE_U_HELP' => 'Underline text: [u]text[/u] (alt+u)', + 'BBCODE_Q_HELP' => 'Quote text: [quote]text[/quote] (alt+q)', + 'BBCODE_C_HELP' => 'Code display: [code]code[/code] (alt+c)', + 'BBCODE_L_HELP' => 'List: [list]text[/list] (alt+l)', + 'BBCODE_E_HELP' => 'List: Add list element', + 'BBCODE_O_HELP' => 'Ordered list: [list=]text[/list] (alt+o)', + 'BBCODE_P_HELP' => 'Insert image: [img]http://image_url[/img] (alt+p)', + 'BBCODE_W_HELP' => 'Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url] (alt+w)', + 'BBCODE_A_HELP' => 'Close all open bbCode tags', + 'BBCODE_S_HELP' => 'Font color: [color=red]text[/color] Tip: you can also use color=#FF0000', + 'BBCODE_F_HELP' => 'Font size: [size=x-small]small text[/size]', + 'EMOTICONS' => 'Emoticons', + 'MORE_EMOTICONS' => 'View more Emoticons', + 'FONT_COLOR' => 'Font color', + 'FONT_SIZE' => 'Font size', + 'FONT_TINY' => 'Tiny', + 'FONT_SMALL' => 'Small', + 'FONT_NORMAL' => 'Normal', + 'FONT_LARGE' => 'Large', + 'FONT_HUGE' => 'Huge', + 'CLOSE_TAGS' => 'Close Tags', + 'STYLES_TIP' => 'Tip: Styles can be applied quickly to selected text', + 'CLOSE_WINDOW' => 'Close Window', + 'MESSAGE_BODY' => 'Message body', 'MESSAGE_BODY_EXPLAIN' => 'Enter your message here, it may contain no more than %d characters.', - 'TOPIC_REVIEW' => 'Topic review', - 'TOPIC_ICON' => 'Topic icon', - 'POST_ICON' => 'Post icon', - 'No_post_mode' => 'No post mode specified', - 'POST_TOPIC' => 'Post a new topic', - 'POST_REPLY' => 'Post a reply', - 'POST_TOPIC_AS' => 'Post topic as', - 'CHANGE_TOPIC_TO' => 'Change topic type to', - 'EDIT_POST' => 'Edit post', - 'OPTIONS' => 'Options', - 'MOD_OPTIONS' => 'Moderator Options', - 'POST_NORMAL' => 'Normal', - 'POST_REVIEW' => 'Post Review', - 'POST_REVIEW_EXPLAIN' => 'Since the beginning of your reply, new posts were added to this topic. You are able to review these posts now, to change yours accordingly.
This reminder will be displayed only once, if you press submit the next time your post will be stored.', + 'TOPIC_REVIEW' => 'Topic review', + 'TOPIC_ICON' => 'Topic icon', + 'POST_ICON' => 'Post icon', + 'No_post_mode' => 'No post mode specified', + 'POST_TOPIC' => 'Post a new topic', + 'POST_REPLY' => 'Post a reply', + 'POST_TOPIC_AS' => 'Post topic as', + 'CHANGE_TOPIC_TO' => 'Change topic type to', + 'EDIT_POST' => 'Edit post', + 'OPTIONS' => 'Options', + 'MOD_OPTIONS' => 'Moderator Options', + 'POST_NORMAL' => 'Normal', + 'POST_REVIEW' => 'Post Review', + 'POST_REVIEW_EXPLAIN' => 'At least one new post has been made to this topic. You may wish to review your post inlight of this.', 'LOCK_POST' => 'Lock Post', 'LOCK_POST_EXPLAIN' => 'Prevent editing', - 'CONFIRM_DELETE' => 'Are you sure you want to delete this post?', - 'Confirm_delete_poll' => 'Are you sure you want to delete this poll?', - 'CANNOT_EDIT_TIME' => 'You can no longer edit or delete that post', - 'CANNOT_EDIT_POST_LOCKED' => 'This post has been locked. You can no longer edit that post.', - 'FLOOD_ERROR' => 'You cannot make another post so soon after your last, please try again in a short while', - 'EMPTY_SUBJECT' => 'You must specify a subject when posting a new topic', - 'To_long_subject' => 'The subject is too long it must be 60 characters or less', - 'EMPTY_MESSAGE' => 'You must enter a message when posting', - 'TOO_FEW_CHARS' => 'Your message contains too few characters', - 'TOO_MANY_CHARS' => 'Your message contains too many characters', - 'TOO_MANY_SMILIES' => 'Your message contains too many emoticons', - 'UNAUTHORISED_BBCODE' => 'Your are not authorised to use this bbcode: ', - 'QUOTE_DEPTH_EXCEEDED' => 'Quote depth exceeded', - 'Forum_locked' => 'This forum is locked you cannot post, reply to or edit topics', - 'Topic_locked' => 'This topic is locked you cannot edit posts or make replies', + 'CONFIRM_DELETE' => 'Are you sure you want to delete this post?', + 'Confirm_delete_poll' => 'Are you sure you want to delete this poll?', + 'CANNOT_EDIT_TIME' => 'You can no longer edit or delete that post', + 'CANNOT_EDIT_POST_LOCKED' => 'This post has been locked. You can no longer edit that post.', + 'FLOOD_ERROR' => 'You cannot make another post so soon after your last.', + 'EMPTY_SUBJECT' => 'You must specify a subject when posting a new topic.', + 'To_long_subject' => 'The subject is too long it must be 60 characters or less.', + 'EMPTY_MESSAGE' => 'You must enter a message when posting.', + 'TOO_FEW_CHARS' => 'Your message contains too few characters.', + 'TOO_MANY_CHARS' => 'Your message contains too many characters.', + 'TOO_MANY_SMILIES' => 'Your message contains too many emoticons.', + 'UNAUTHORISED_BBCODE' => 'You cannot use certain bbcodes: ', + 'QUOTE_DEPTH_EXCEEDED' => 'You may embed only %1$d quotes within each other.', + 'Forum_locked' => 'This forum is locked you cannot post, reply to or edit topics', + 'Topic_locked' => 'This topic is locked you cannot edit posts or make replies', + + 'USER_CANNOT_POST' => 'You cannot post in this forum', + 'USER_CANNOT_REPLY' => 'You cannot reply in this forum', + 'USER_CANNOT_QUOTE' => 'You cannot quote posts in this forum', + 'USER_CANNOT_EDIT' => 'You cannot edit posts in this forum', + 'USER_CANNOT_DELETE' => 'You cannot delete posts in this forum', + 'CANNOT_POST_STICKY' => 'Sorry but you cannot post sticky topics.', + 'CANNOT_POST_ANNOUNCE' => 'Sorry but you cannot post announcements.', + 'CANNOT_POST_NEWS' => 'Sorry but you cannot post news topics.', + 'CANNOT_DELETE_REPLIED' => 'Sorry but you may only delete posts which have not been replied to.', + 'CANNOT_DELETE_POLL' => 'Sorry but you cannot delete an active poll.', + 'EDIT_OWN_POSTS' => 'Sorry but you can only edit your own posts.', + 'DELETE_OWN_POSTS' => 'Sorry but you can only delete your own posts.', + 'ALREADY_DELETED' => 'Sorry but this message is already deleted.', - 'USER_CANNOT_POST' => 'You cannot post in this forum', - 'USER_CANNOT_REPLY' => 'You cannot reply in this forum', - 'USER_CANNOT_QUOTE' => 'You cannot quote posts in this forum', - 'USER_CANNOT_EDIT' => 'You cannot edit posts in this forum', - 'USER_CANNOT_DELETE' => 'You cannot delete posts in this forum', - 'CANNOT_DELETE_REPLIED' => 'Sorry but you may not delete posts that have been replied to', - 'CANNOT_DELETE_POLL' => 'Sorry but you cannot delete an active poll', - 'EDIT_OWN_POSTS' => 'Sorry but you can only edit your own posts', - 'DELETE_OWN_POSTS' => 'Sorry but you can only delete your own posts', - 'ALREADY_DELETED' => 'Sorry but this message is already deleted', 'No_such_post' => 'There is no such post, please return and try again', 'ADD_POLL' => 'Add a Poll', @@ -570,66 +600,44 @@ $lang = array( 'POLL_QUESTION' => 'Poll question', 'POLL_OPTIONS' => 'Poll options', 'POLL_OPTIONS_EXPLAIN' => 'Place each option on a new line. You may enter up to %d options', - 'POLL_FOR_EXPLAIN' => '[ Enter 0 or leave blank for a never ending poll ]', + 'POLL_FOR_EXPLAIN' => 'Enter 0 or leave blank for a never ending poll', 'POLL_MAX_OPTIONS' => 'Options per user', 'POLL_MAX_OPTIONS_EXPLAIN' => 'This is the number of options each user may select when voting.', 'POLL_FOR' => 'Run poll for', - 'DAYS' => 'Days', - 'POLL_DELETE' => 'Delete Poll', - 'ADD_ATTACHMENT' => 'Add an Attachment', - 'ADD_ATTACHMENT_EXPLAIN' => 'If you wish to attach one or more files enter the details below', - 'ADD_FILE' => 'Add File', - 'FILENAME' => 'Filename', - 'FILE_COMMENT' => 'File comment', - 'POSTED_ATTACHMENTS' => 'Posted attachments', - 'UPDATE_COMMENT' => 'Update comment', - 'DELETE_FILE' => 'Delete File', - 'DISABLE_HTML' => 'Disable HTML', - 'DISABLE_BBCODE' => 'Disable BBCode', - 'DISABLE_SMILIES' => 'Disable Smilies', + 'DAYS' => 'Days', + 'POLL_DELETE' => 'Delete Poll', + + 'ADD_ATTACHMENT' => 'Add an Attachment', + 'ADD_ATTACHMENT_EXPLAIN'=> 'If you wish to attach one or more files enter the details below', + 'ADD_FILE' => 'Add File', + 'FILENAME' => 'Filename', + 'FILE_COMMENT' => 'File comment', + 'POSTED_ATTACHMENTS'=> 'Posted attachments', + 'UPDATE_COMMENT' => 'Update comment', + 'DELETE_FILE' => 'Delete File', + + 'DISABLE_HTML' => 'Disable HTML', + 'DISABLE_BBCODE' => 'Disable BBCode', + 'DISABLE_SMILIES' => 'Disable Smilies', 'DISABLE_MAGIC_URL' => 'Do not automatically parse URLs', - 'HTML_IS_ON' => 'HTML is ON', - 'HTML_IS_OFF' => 'HTML is OFF', - 'BBCODE_IS_ON' => '%sBBCode%s is ON', - 'BBCODE_IS_OFF' => '%sBBCode%s is OFF', - 'SMILIES_ARE_ON'=> 'Smilies are ON', - 'SMILIES_ARE_OFF'=> 'Smilies are OFF', - 'IMAGES_ARE_ON' => '[img] is ON', - 'IMAGES_ARE_OFF'=> '[img] is OFF', - 'FLASH_IS_ON' => '[flash] is ON', - 'FLASH_IS_OFF' => '[flash] is ON', - 'ATTACH_SIG' => 'Attach a signature (signatures can be altered via the UCP)', - 'NOTIFY_REPLY' => 'Send me an email when a reply is posted', - 'SAVE' => 'Save', - 'POST_STORED' => 'Your message has been posted successfully', + 'HTML_IS_ON' => 'HTML is ON', + 'HTML_IS_OFF' => 'HTML is OFF', + 'BBCODE_IS_ON' => '%sBBCode%s is ON', + 'BBCODE_IS_OFF' => '%sBBCode%s is OFF', + 'SMILIES_ARE_ON' => 'Smilies are ON', + 'SMILIES_ARE_OFF' => 'Smilies are OFF', + 'IMAGES_ARE_ON' => '[img] is ON', + 'IMAGES_ARE_OFF' => '[img] is OFF', + 'FLASH_IS_ON' => '[flash] is ON', + 'FLASH_IS_OFF' => '[flash] is ON', + 'ATTACH_SIG' => 'Attach a signature (signatures can be altered via the UCP)', + 'NOTIFY_REPLY' => 'Send me an email when a reply is posted', + 'SAVE' => 'Save', + + 'POST_STORED' => 'Your message has been posted successfully', 'POST_STORED_MOD' => 'Your message has been saved but requires approval', - 'DELETED' => 'Your message has been deleted successfully', - 'Poll_delete' => 'Your poll has been deleted successfully', - 'BBCODE_B_HELP' => 'Bold text: [b]text[/b] (alt+b)', - 'BBCODE_I_HELP' => 'Italic text: [i]text[/i] (alt+i)', - 'BBCODE_U_HELP' => 'Underline text: [u]text[/u] (alt+u)', - 'BBCODE_Q_HELP' => 'Quote text: [quote]text[/quote] (alt+q)', - 'BBCODE_C_HELP' => 'Code display: [code]code[/code] (alt+c)', - 'BBCODE_L_HELP' => 'List: [list]text[/list] (alt+l)', - 'BBCODE_E_HELP' => 'List: Add list element', - 'BBCODE_O_HELP' => 'Ordered list: [list=]text[/list] (alt+o)', - 'BBCODE_P_HELP' => 'Insert image: [img]http://image_url[/img] (alt+p)', - 'BBCODE_W_HELP' => 'Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url] (alt+w)', - 'BBCODE_A_HELP' => 'Close all open bbCode tags', - 'BBCODE_S_HELP' => 'Font color: [color=red]text[/color] Tip: you can also use color=#FF0000', - 'BBCODE_F_HELP' => 'Font size: [size=x-small]small text[/size]', - 'EMOTICONS' => 'Emoticons', - 'MORE_EMOTICONS'=> 'View more Emoticons', - 'FONT_COLOR' => 'Font color', - 'FONT_SIZE' => 'Font size', - 'FONT_TINY' => 'Tiny', - 'FONT_SMALL' => 'Small', - 'FONT_NORMAL' => 'Normal', - 'FONT_LARGE' => 'Large', - 'FONT_HUGE' => 'Huge', - 'CLOSE_TAGS' => 'Close Tags', - 'STYLES_TIP' => 'Tip: Styles can be applied quickly to selected text', - 'CLOSE_WINDOW' => 'Close Window', + 'DELETED' => 'Your message has been deleted successfully', + 'Poll_delete' => 'Your poll has been deleted successfully', 'Topic_reply_notification' => 'Topic Reply Notification', 'TOO_FEW_POLL_OPTIONS' => 'You must enter at least two poll options', @@ -666,7 +674,6 @@ $lang = array( 'UCP' => 'User Control Panel', 'UCP_OPTIONS' => 'Options', - 'UCP_MAIN' => 'Overview', 'UCP_FRONT' => 'Front page', diff --git a/phpBB/mcp.php b/phpBB/mcp.php index 8915456d56..a1b77c3414 100644 --- a/phpBB/mcp.php +++ b/phpBB/mcp.php @@ -812,20 +812,20 @@ switch ($mode) switch ($mode) { case 'make_global': - $set_sql = 'topic_type = ' . POST_ANNOUNCE; - break; + $set_sql = 'topic_type = ' . POST_GLOBAL; + break; case 'make_announce': $set_sql = 'topic_type = ' . POST_ANNOUNCE; - break; + break; case 'make_sticky': $set_sql = 'topic_type = ' . POST_STICKY; - break; + break; case 'make_normal': $set_sql = 'topic_type = ' . POST_NORMAL; - break; + break; } if ($topic_info['forum_id'] == 0 && $mode != 'make_global') { diff --git a/phpBB/posting.php b/phpBB/posting.php index 176d1b3868..3535337a1b 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -19,15 +19,6 @@ * ***************************************************************************/ -// TODO for 2.2: -// -// * hidden form element containing sid to prevent remote posting - Edwin van Vliet -// * bbcode parsing -> see functions_posting.php -// * multichoice polls -// * permission defined ability for user to add poll options -// * Spellcheck? aspell? or some such? -// * Posting approval - define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); @@ -35,11 +26,13 @@ include($phpbb_root_path . 'common.'.$phpEx); include($phpbb_root_path . 'includes/functions_posting.'.$phpEx); include($phpbb_root_path . 'includes/message_parser.'.$phpEx); + // Start session management $user->start(); $auth->acl($user->data); $user->setup(); + // Grab only parameters needed here $mode = (!empty($_REQUEST['mode'])) ? strval($_REQUEST['mode']) : ''; $post_id = (!empty($_REQUEST['p'])) ? intval($_REQUEST['p']) : false; @@ -73,9 +66,17 @@ if ($cancel || time() - $lastclick < 2) $forum_validate = $topic_validate = $post_validate = false; // Easier validation -$forum_fields = array('forum_name' => 's', 'parent_id' => 'i', 'forum_parents' => 's', 'forum_status' => 'i', 'forum_type' => 'i', 'enable_icons' => 'i'); -$topic_fields = array('topic_status' => 'i', 'topic_first_post_id' => 'i', 'topic_last_post_id' => 'i', 'topic_type' => 'i', 'topic_title' => 's', 'poll_last_vote' => 'i', 'poll_start' => 'i', 'poll_title' => 's', 'poll_max_options' => 'i', 'poll_length' => 'i'); -$post_fields = array('post_time' => 'i', 'poster_id' => 'i', 'post_username' => 's', 'post_text' => 's', 'post_subject' => 's', 'post_checksum' => 's', 'post_attachment' => 'i', 'bbcode_uid' => 's', 'enable_magic_url' => 'i', 'enable_sig' => 'i', 'enable_smilies' => 'i', 'enable_bbcode' => 'i', 'post_edit_locked' => 'i'); +$parameters = array( + 'forums' => array( + 'forum_name' => 's', 'parent_id' => 'i', 'forum_parents' => 's', 'forum_status' => 'i', 'forum_type' => 'i', 'enable_icons' => 'i' + ), + 'topics' => array( + 'topic_status' => 'i', 'topic_first_post_id' => 'i', 'topic_last_post_id' => 'i', 'topic_type' => 'i', 'topic_title' => 's', 'poll_last_vote' => 'i', 'poll_start' => 'i', 'poll_title' => 's', 'poll_max_options' => 'i', 'poll_length' => 'i' + ), + 'posts' => array( + 'post_time' => 'i', 'poster_id' => 'i', 'post_username' => 's', 'post_text' => 's', 'post_subject' => 's', 'post_checksum' => 's', 'post_attachment' => 'i', 'bbcode_uid' => 's', 'enable_magic_url' => 'i', 'enable_sig' => 'i', 'enable_smilies' => 'i', 'enable_bbcode' => 'i', 'post_edit_locked' => 'i' + ) +); $sql = ''; switch ($mode) @@ -102,7 +103,7 @@ switch ($mode) $sql = 'SELECT t.*, f.* FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id - AND f.forum_id = t.forum_id"; + AND f.forum_id IN (t.forum_id, $forum_id)"; $forum_validate = $topic_validate = true; break; @@ -120,7 +121,7 @@ switch ($mode) WHERE p.post_id = $post_id AND t.topic_id = p.topic_id AND u.user_id = p.poster_id - AND f.forum_id = t.forum_id"; + AND f.forum_id IN (t.forum_id, $forum_id)"; $forum_validate = $topic_validate = $post_validate = true; break; @@ -131,7 +132,7 @@ switch ($mode) trigger_error($user->lang['NO_TOPIC']); } - topic_review($topic_id, false); + topic_review($topic_id, $forum_id, false); break; case 'smilies': @@ -142,8 +143,6 @@ switch ($mode) trigger_error($user->lang['NO_MODE']); } -$message_parser = new parse_message(0); // <- TODO: add constant (MSG_POST/MSG_PM) - if ($sql != '') { $result = $db->sql_query($sql); @@ -155,9 +154,9 @@ if ($sql != '') $postrow = $row; $quote_username = (!empty($row['username'])) ? $row['username'] : $row['post_username']; - $forum_id = intval($row['forum_id']); - $topic_id = intval($row['topic_id']); - $post_id = intval($row['post_id']); + $forum_id = (int) $row['forum_id']; + $topic_id = (int) $row['topic_id']; + $post_id = (int) $row['post_id']; $user->setup(false, $row['forum_style']); @@ -165,54 +164,29 @@ if ($sql != '') { login_forum_box($row); } - - foreach ($forum_fields as $var => $type) + + // ??? + foreach ($parameters as $parameter => $param_ary) { - switch ($type) + foreach ($param_ary as $var => $type) { - case 'i': - $$var = ($forum_validate) ? intval($row[$var]) : false; - break; - case 's': - $$var = ($forum_validate) ? trim($row[$var]) : ''; - break; - default: - $$var = ''; - } - } - - foreach ($topic_fields as $var => $type) - { - switch ($type) - { - case 'i': - $$var = ($topic_validate) ? intval($row[$var]) : false; - break; - case 's': - $$var = ($topic_validate) ? trim($row[$var]) : ''; - break; - default: - $$var = ''; - } - } - - foreach ($post_fields as $var => $type) - { - switch ($type) - { - case 'i': - $$var = ($post_validate) ? intval($row[$var]) : false; - break; - case 's': - $$var = ($post_validate) ? trim($row[$var]) : ''; - break; - default: - $$var = ''; + switch ($type) + { + case 'i': + $$var = ($forum_validate) ? (int) $row[$var] : false; + break; + case 's': + $$var = ($forum_validate) ? trim($row[$var]) : ''; + break; + default: + $$var = false; + } } } $post_subject = ($post_validate) ? $post_subject : $topic_title; + $poll_length = ($poll_length) ? $poll_length/3600 : $poll_length; $poll_options = array(); @@ -232,6 +206,10 @@ if ($sql != '') $db->sql_freeresult($result); } + + $message_parser = new parse_message(0); // <- TODO: add constant (MSG_POST/MSG_PM) + + $message_parser->filename_data['filecomment'] = (isset($_POST['filecomment'])) ? trim(strip_tags($_POST['filecomment'])) : ''; $message_parser->filename_data['filename'] = ($_FILES['fileupload']['name'] != 'none') ? trim($_FILES['fileupload']['name']) : ''; @@ -252,6 +230,7 @@ if ($sql != '') $db->sql_freeresult($result); } + if ($poster_id == ANONYMOUS || !$poster_id) { $username = ($post_validate) ? trim($post_username) : ''; @@ -263,17 +242,19 @@ if ($sql != '') $enable_urls = $enable_magic_url; + if (!$post_validate) { - $enable_sig = (intval($config['allow_sig']) && $user->data['user_attachsig']) ? true : false; - $enable_smilies = (intval($config['allow_smilies']) && $user->data['user_allowsmile']) ? true : false; - $enable_bbcode = (intval($config['allow_bbcode']) && $user->data['user_allowbbcode']) ? true : false; + $enable_sig = ($config['allow_sig'] && $user->data['user_attachsig']) ? true : false; + $enable_smilies = ($config['allow_smilies'] && $user->data['user_allowsmile']) ? true : false; + $enable_bbcode = ($config['allow_bbcode'] && $user->data['user_allowbbcode']) ? true : false; $enable_urls = true; } $enable_magic_url = false; } + // Notify user checkbox if ($mode != 'post' && $user->data['user_id'] != ANONYMOUS) { @@ -291,11 +272,13 @@ else $notify_set = -1; } + if (!$auth->acl_get('f_' . $mode, $forum_id) && $forum_type == FORUM_POST) { trigger_error($user->lang['USER_CANNOT_' . strtoupper($mode)]); } + // Forum/Topic locked? if (($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id)) { @@ -303,29 +286,34 @@ if (($forum_status == ITEM_LOCKED || $topic_status == ITEM_LOCKED) && !$auth->ac trigger_error($user->lang[$message]); } + // Can we edit this post? if (($mode == 'edit' || $mode == 'delete') && !$auth->acl_get('m_edit', $forum_id) && $config['edit_time'] && $post_time < time() - $config['edit_time']) { trigger_error($user->lang['CANNOT_EDIT_TIME']); } + // Do we want to edit our post ? if ($mode == 'edit' && !$auth->acl_get('m_edit', $forum_id) && $user->data['user_id'] != $poster_id) { trigger_error($user->lang['USER_CANNOT_EDIT']); } + // Is edit posting locked ? if ($mode == 'edit' && $post_edit_locked && !$auth->acl_get('m_', $forum_id)) { trigger_error($user->lang['CANNOT_EDIT_POST_LOCKED']); } + if ($mode == 'edit') { $message_parser->bbcode_uid = $row['bbcode_uid']; } + // Delete triggered ? if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data['user_id'] != ANONYMOUS && $auth->acl_get('f_delete', $forum_id) && $post_id == $topic_last_post_id) || $auth->acl_get('m_delete', $forum_id))) { @@ -385,7 +373,7 @@ if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data[' if ($post_data['topic_first_post_id'] != $post_data['topic_last_post_id'] && $post_id == $post_data['topic_first_post_id']) { $topic_sql = array( - 'topic_first_post_id' => intval($row['post_id']), + 'topic_first_post_id' => (int) $row['post_id'], 'topic_first_poster_name' => ($row['poster_id'] == ANONYMOUS) ? trim($row['post_username']) : trim($row['username']) ); } @@ -426,6 +414,7 @@ if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data[' $db->sql_transaction('commit'); + if ($post_data['topic_first_post_id'] == $post_data['topic_last_post_id']) { $meta_info = "viewforum.$phpEx$SID&f=$forum_id"; @@ -455,7 +444,7 @@ if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data[' 'MESSAGE_TITLE' => $user->lang['DELETE_MESSAGE'], 'MESSAGE_TEXT' => $user->lang['CONFIRM_DELETE'], - 'S_CONFIRM_ACTION' => $phpbb_root_path . 'posting.' . $phpEx . $SID, + 'S_CONFIRM_ACTION' => "posting.$phpEx$SID", 'S_HIDDEN_FIELDS' => $s_hidden_fields) ); @@ -463,27 +452,31 @@ if ($mode == 'delete' && (($poster_id == $user->data['user_id'] && $user->data[' } } + if ($mode == 'delete' && $poster_id != $user->data['user_id'] && !$auth->acl_get('f_delete', $forum_id)) { trigger_error($user->lang['DELETE_OWN_POSTS']); } + if ($mode == 'delete' && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && $post_id != $topic_last_post_id) { trigger_error($user->lang['CANNOT_DELETE_REPLIED']); } + if ($mode == 'delete') { trigger_error('USER_CANNOT_DELETE'); } + // HTML, BBCode, Smilies, Images and Flash status -$html_status = (intval($config['allow_html']) && $auth->acl_get('f_html', $forum_id)) ? true : false; -$bbcode_status = (intval($config['allow_bbcode']) && $auth->acl_get('f_bbcode', $forum_id)) ? true : false; -$smilies_status = (intval($config['allow_smilies']) && $auth->acl_get('f_smilies', $forum_id)) ? true : false; -$img_status = (intval($config['allow_img']) && $auth->acl_get('f_img', $forum_id)) ? true : false; -$flash_status = (intval($config['allow_flash']) && $auth->acl_get('f_flash', $forum_id)) ? true : false; +$html_status = ($config['allow_html'] && $auth->acl_get('f_html', $forum_id)) ? true : false; +$bbcode_status = ($config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id)) ? true : false; +$smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false; +$img_status = ($config['allow_img'] && $auth->acl_get('f_img', $forum_id)) ? true : false; +$flash_status = ($config['allow_flash'] && $auth->acl_get('f_flash', $forum_id)) ? true : false; if ($submit || $preview || $refresh) { @@ -498,7 +491,7 @@ if ($submit || $preview || $refresh) $message_parser->message = (!empty($_POST['message'])) ? trim(stripslashes($_POST['message'])) : ''; $username = (!empty($_POST['username'])) ? trim($_POST['username']) : ''; - $topic_type = (!empty($_POST['topic_type'])) ? intval($_POST['topic_type']) : POST_NORMAL; + $topic_type = (!empty($_POST['topic_type'])) ? (int) $_POST['topic_type'] : (($mode != 'post') ? $topic_type : POST_NORMAL); $icon_id = (!empty($_POST['icon'])) ? intval($_POST['icon']) : 0; $enable_html = (!$html_status || !empty($_POST['disable_html'])) ? FALSE : TRUE; @@ -513,10 +506,12 @@ if ($submit || $preview || $refresh) $poll_delete = (isset($_POST['poll_delete'])) ? true : false; + // Faster than crc32 $check_value = (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); $status_switch = (isset($_POST['status_switch']) && intval($_POST['status_switch']) != $check_value) ? true : false; + if ($poll_delete && (($mode == 'edit' && !empty($poll_options) && empty($poll_last_vote) && $poster_id == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id)) || $auth->acl_get('m_delete', $forum_id))) { // Delete Poll @@ -551,7 +546,7 @@ if ($submit || $preview || $refresh) $poll_max_options = (!empty($_POST['poll_max_options'])) ? intval($_POST['poll_max_options']) : 1; } - $err_msg = ''; + $error = array(); $current_time = time(); // If replying/quoting and last post id has changed @@ -631,7 +626,7 @@ if ($submit || $preview || $refresh) // Parse message if ($result = $message_parser->parse($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, $img_status, $flash_status)) { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . $result; + $error[] = $result; } } @@ -639,7 +634,7 @@ if ($submit || $preview || $refresh) if (count($result)) { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . implode('
', $result); + $error[] = implode('
', $result); } if ($mode != 'edit' && !$preview && !$refresh && !$auth->acl_get('f_ignoreflood', $forum_id)) @@ -654,12 +649,13 @@ if ($submit || $preview || $refresh) { if (intval($row['last_post_time']) && ($current_time - intval($row['last_post_time'])) < intval($config['flood_interval'])) { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . $user->lang['FLOOD_ERROR']; + $error[] = $user->lang['FLOOD_ERROR']; } } } // Validate username + // TODO if (($username != '' && $user->data['user_id'] == ANONYMOUS) || ($mode == 'edit' && $post_username != '')) { include($phpbb_root_path . 'includes/functions_user.' . $phpEx); @@ -668,14 +664,14 @@ if ($submit || $preview || $refresh) if (($result = $ucp->validate_username($username)) != false) { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . $result; + $error[] = $result; } } // Parse subject if ($subject == '' && ($mode == 'post' || ($mode == 'edit' && $topic_first_post_id == $post_id))) { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . $user->lang['EMPTY_SUBJECT']; + $error[] = $user->lang['EMPTY_SUBJECT']; } $poll_data = array( @@ -695,7 +691,7 @@ if ($submit || $preview || $refresh) $poll = array(); if (($result = $message_parser->parse_poll($poll, $poll_data)) != '') { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . $result; + $error[] = $result; } $poll_options = $poll['poll_options']; @@ -704,28 +700,29 @@ if ($submit || $preview || $refresh) // Check topic type if ($topic_type != POST_NORMAL) { - $auth_option = ''; switch ($topic_type) { case POST_GLOBAL: - $auth_option = 'global'; - break; +// $auth_option = 'a_news'; +// break; case POST_ANNOUNCE: - $auth_option = 'announce'; + $auth_option = 'f_announce'; break; case POST_STICKY: - $auth_option = 'sticky'; + $auth_option = 'f_sticky'; break; + default: + $auth_option = ''; } - if (!$auth->acl_get('f_' . $auth_option, $forum_id)) + if (!$auth->acl_get($auth_option, $forum_id)) { - $err_msg .= ((!empty($err_msg)) ? '
' : '') . $user->lang['CANNOT_POST_' . strtoupper($auth_option)]; + $error[] = $user->lang['CANNOT_POST_' . strtoupper($auth_option)]; } } // Store message, sync counters - if ($err_msg == '' && $submit) + if (!sizeof($error) && $submit) { // Lock/Unlock Topic $change_topic_status = $topic_status; @@ -782,7 +779,6 @@ if ($submit || $preview || $refresh) 'post_edit_locked' => $post_edit_locked, 'bbcode_bitfield' => $message_parser->bbcode_bitfield ); - submit_post($mode, $message_parser->message, $subject, $username, $topic_type, $message_parser->bbcode_uid, $poll, $message_parser->attachment_data, $message_parser->filename_data, $post_data); } @@ -791,7 +787,7 @@ if ($submit || $preview || $refresh) } // Preview -if (!$err_msg && $preview) +if (!sizeof($error) && $preview) { if (empty($censors)) { @@ -801,14 +797,17 @@ if (!$err_msg && $preview) $post_time = $current_time; + include($phpbb_root_path . 'includes/bbcode.' . $phpEx); $bbcode = new bbcode($message_parser->bbcode_bitfield); + $preview_message = format_display($message_parser->message, $enable_html, $enable_bbcode, $message_parser->bbcode_uid, $enable_urls, $enable_smilies, $enable_sig); $preview_subject = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $subject) : $subject; + // Poll Preview - if ( ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && empty($poll_last_vote))) && ($auth->acl_get('f_poll', $forum_id) || $auth->acl_get('m_edit', $forum_id)) ) + if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && empty($poll_last_vote))) && ($auth->acl_get('f_poll', $forum_id) || $auth->acl_get('m_edit', $forum_id))) { decode_text($poll_title, $message_parser->bbcode_uid); $preview_poll_title = format_display(stripslashes($poll_title), $enable_html, $enable_bbcode, $message_parser->bbcode_uid, $enable_urls, $enable_smilies, false, false); @@ -826,6 +825,7 @@ if (!$err_msg && $preview) } } + // Attachment Preview if (sizeof($message_parser->attachment_data)) { @@ -840,15 +840,18 @@ if (!$err_msg && $preview) } } + // Decode text for message display $bbcode_uid = ($mode == 'quote' && !$preview) ? $row['bbcode_uid'] : $message_parser->bbcode_uid; + decode_text($post_text, $bbcode_uid); if ($subject) { decode_text($subject, $bbcode_uid); } + // Save us some processing time. ;) if (count($poll_options)) { @@ -857,24 +860,29 @@ if (count($poll_options)) $poll_options = explode("\n", $poll_options_tmp); } + if ($mode == 'quote' && !$preview && !$refresh) { $post_text = '[quote="' . $quote_username . '"]' . trim($post_text) . "[/quote]\n"; } + if (($mode == 'reply' || $mode == 'quote') && !$preview && !$refresh) { $post_subject = ((!preg_match('/^Re:/', $post_subject)) ? 'Re: ' : '') . $post_subject; } + // MAIN POSTING PAGE BEGINS HERE // Forum moderators? get_moderators($moderators, $forum_id); + // Generate smilies and topic icon listings generate_smilies('inline'); + // Generate Topic icons $s_topic_icons = false; if ($enable_icons) @@ -910,8 +918,8 @@ if ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id)) { $topic_types = array( 'sticky' => array('const' => POST_STICKY, 'lang' => 'POST_STICKY'), - 'announce' => array('const' => POST_ANNOUNCE, 'lang' => 'POST_ANNOUNCEMENT') -// 'global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL') + 'announce' => array('const' => POST_ANNOUNCE, 'lang' => 'POST_ANNOUNCEMENT'), + 'global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL') ); foreach ($topic_types as $auth_key => $topic_value) @@ -919,7 +927,7 @@ if ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id)) if ($auth->acl_get('f_' . $auth_key, $forum_id)) { $topic_type_toggle .= 'assign_vars(array( 'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '', 'USERNAME' => (((!$preview) && ($mode != 'quote')) || ($preview)) ? stripslashes($username) : '', 'SUBJECT' => $post_subject, - 'PREVIEW_SUBJECT' => ($preview && !$err_msg) ? $preview_subject : '', + 'PREVIEW_SUBJECT' => ($preview && !sizeof($error)) ? $preview_subject : '', 'MESSAGE' => trim($post_text), - 'PREVIEW_MESSAGE' => ($preview && !$err_msg) ? $preview_message : '', + 'PREVIEW_MESSAGE' => ($preview && !sizeof($error)) ? $preview_message : '', 'HTML_STATUS' => ($html_status) ? $user->lang['HTML_IS_ON'] : $user->lang['HTML_IS_OFF'], 'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '', '') : sprintf($user->lang['BBCODE_IS_OFF'], '', ''), 'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], @@ -1001,13 +1009,13 @@ $template->assign_vars(array( 'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'MINI_POST_IMG' => $user->img('icon_post', $user->lang['POST']), 'POST_DATE' => ($post_time) ? $user->format_date($post_time) : '', - 'ERROR_MESSAGE' => $err_msg, + 'ERROR_MESSAGE' => (sizeof($error)) ? implode('
', $error) : '', 'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=" . $forum_id, 'U_VIEWTOPIC' => ($mode != 'post') ? "viewtopic.$phpEx$SID&$forum_id&t=$topic_id" : '', 'U_REVIEW_TOPIC' => ($mode != 'post') ? "posting.$phpEx$SID&mode=topicreview&f=$forum_id&t=$topic_id" : '', - 'S_DISPLAY_PREVIEW' => ($preview && !$err_msg), + 'S_DISPLAY_PREVIEW' => ($preview && !sizeof($error)), 'S_DISPLAY_REVIEW' => ($mode == 'reply' || $mode == 'quote') ? true : false, 'S_DISPLAY_USERNAME' => ($user->data['user_id'] == ANONYMOUS || ($mode == 'edit' && $post_username)) ? true : false, 'S_SHOW_TOPIC_ICONS' => $s_topic_icons, @@ -1111,15 +1119,593 @@ make_jumpbox('viewforum.'.$phpEx); // Topic review if ($mode == 'reply' || $mode == 'quote') { - topic_review($topic_id, true); + topic_review($topic_id, $forum_id, true); } page_footer(); + +// --------- // FUNCTIONS +// + +// Submit Post +function submit_post($mode, $message, $subject, $username, $topic_type, $bbcode_uid, $poll, $attach_data, $filename_data, $data) +{ + global $db, $auth, $user, $config, $phpEx, $SID, $template; + + $current_time = time(); + + $db->sql_transaction(); + + // Initial Topic table info + if ($mode == 'post' || ($mode == 'edit' && $data['topic_first_post_id'] == $data['post_id'])) + { + $topic_sql = array( + 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], + 'topic_title' => stripslashes($subject), + 'topic_time' => $current_time, + 'topic_type' => $topic_type, + 'topic_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('f_ignorequeue', $data['forum_id'])) ? 0 : 1, + 'icon_id' => $data['icon_id'], + 'topic_attachment' => (sizeof($filename_data['physical_filename'])) ? 1 : 0 + ); + + if (!empty($poll['poll_options'])) + { + $topic_sql = array_merge($topic_sql, array( + 'poll_title' => stripslashes($poll['poll_title']), + 'poll_start' => ($poll['poll_start']) ? $poll['poll_start'] : $current_time, + 'poll_max_options' => $poll['poll_max_options'], + 'poll_length' => $poll['poll_length'] * 86400) + ); + } + + if ($mode == 'post') + { + $topic_sql = array_merge($topic_sql, array( + 'topic_poster' => (int) $user->data['user_id'], + 'topic_first_poster_name' => ($username) ? stripslashes($username) : (($user->data['user_id'] == ANONYMOUS) ? '' : stripslashes($user->data['username']))) + ); + } + + $sql = ($mode == 'post') ? 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $topic_sql) : 'UPDATE ' . TOPICS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $topic_sql) . ' WHERE topic_id = ' . $data['topic_id']; + $db->sql_query($sql); + + $data['topic_id'] = ($mode == 'post') ? $db->sql_nextid() : $data['topic_id']; + } + + // Post table info + $post_sql = array( + 'topic_id' => $data['topic_id'], + 'forum_id' => ($topic_type == POST_GLOBAL) ? 0 : $data['forum_id'], + 'poster_id' => ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id'], + 'post_username' => ($username != '') ? stripslashes($username) : '', + 'post_subject' => stripslashes($subject), + 'icon_id' => $data['icon_id'], + 'poster_ip' => $user->ip, + 'post_approved' => ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('f_ignorequeue', $data['forum_id'])) ? 0 : 1, + 'post_edit_time' => ($mode == 'edit' && $data['poster_id'] == $user->data['user_id']) ? $current_time : 0, + 'enable_sig' => $data['enable_sig'], + 'enable_bbcode' => $data['enable_bbcode'], + 'enable_html' => $data['enable_html'], + 'enable_smilies' => $data['enable_smilies'], + 'enable_magic_url' => $data['enable_urls'], + 'bbcode_uid' => $bbcode_uid, + 'bbcode_bitfield' => $data['bbcode_bitfield'], + 'post_edit_locked' => $data['post_edit_locked'], + 'post_text' => $message + ); + + if ($mode != 'edit') + { + $post_sql['post_time'] = $current_time; + } + + if ($mode != 'edit' || $data['message_md5'] != $data['post_checksum']) + { + $post_sql = array_merge($post_sql, array( + 'post_checksum' => $data['message_md5'], + 'post_encoding' => $user->lang['ENCODING']) + ); + } + + if ($mode == 'edit') + { + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $post_sql) . + (($data['poster_id'] == $user->data['user_id']) ? ' , post_edit_count = post_edit_count + 1' : '') . ' + WHERE post_id = ' . $data['post_id']; + } + else + { + $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . + $db->sql_build_array('INSERT', $post_sql); + } + $db->sql_query($sql); + + $data['post_id'] = ($mode == 'edit') ? $data['post_id'] : $db->sql_nextid(); + + // Submit Poll + if (!empty($poll['poll_options'])) + { + $cur_poll_options = array(); + + if ($poll['poll_start'] && $mode == 'edit') + { + $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . ' + WHERE topic_id = ' . $data['topic_id'] . ' + ORDER BY poll_option_id'; + $result = $db->sql_query($sql); + + while ($cur_poll_options[] = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); + } + + for ($i = 0; $i < sizeof($poll['poll_options']); $i++) + { + if (trim($poll['poll_options'][$i])) + { + if (empty($cur_poll_options[$i])) + { + $sql = 'INSERT INTO ' . POLL_OPTIONS_TABLE . " (poll_option_id, topic_id, poll_option_text) + VALUES ($i, " . $data['topic_id'] . ", '" . $db->sql_escape($poll['poll_options'][$i]) . "')"; + $db->sql_query($sql); + } + else if ($poll['poll_options'][$i] != $cur_poll_options[$i]) + { + $sql = "UPDATE " . POLL_OPTIONS_TABLE . " + SET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "' + WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . " + AND topic_id = " . $data['topic_id']; + $db->sql_query($sql); + } + } + } + + if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) + { + $sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . ' + WHERE poll_option_id > ' . sizeof($poll['poll_options']) . ' + AND topic_id = ' . $data['topic_id']; + $db->sql_query($sql); + } + } + + // Submit Attachments + if (count($attach_data) && !empty($data['post_id']) && ($mode == 'post' || $mode == 'reply' || $mode == 'edit')) + { + foreach ($attach_data as $attach_row) + { + if ($attach_row['attach_id'] != '-1') + { + // update entry in db if attachment already stored in db and filespace + $attach_sql = array( + 'comment' => trim($attach_row['comment']) + ); + + $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $attach_sql) . ' + WHERE attach_id = ' . (int) $attach_row['attach_id']; + $db->sql_query($sql); + } + else + { + // insert attachment into db + $attach_sql = array( + 'physical_filename' => $attach_row['physical_filename'], + 'real_filename' => $attach_row['real_filename'], + 'comment' => trim($attach_row['comment']), + 'extension' => $attach_row['extension'], + 'mimetype' => $attach_row['mimetype'], + 'filesize' => $attach_row['filesize'], + 'filetime' => $attach_row['filetime'], + 'thumbnail' => $attach_row['thumbnail'] + ); + + $sql = 'INSERT INTO ' . ATTACHMENTS_DESC_TABLE . ' ' . + $db->sql_build_array('INSERT', $attach_sql); + $db->sql_query($sql); + + $attach_sql = array( + 'attach_id' => $db->sql_nextid(), + 'post_id' => $data['post_id'], + 'privmsgs_id' => 0, + 'user_id_from' => ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id'], + 'user_id_to' => 0 + ); + + $sql = 'INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . + $db->sql_build_array('INSERT', $attach_sql); + $db->sql_query($sql); + } + } + + if (count($attach_data)) + { + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_attachment = 1 + WHERE post_id = ' . $data['post_id']; + $db->sql_query($sql); + + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_attachment = 1 + WHERE topic_id = ' . $data['topic_id']; + $db->sql_query($sql); + } + } + + // Fulltext parse + if ($data['message_md5'] != $data['post_checksum']) + { + $search = new fulltext_search(); + $result = $search->add($mode, $data['post_id'], $message, $subject); + } + + // Sync forums, topics and users ... + if ($mode != 'edit') + { + if ($topic_type != POST_GLOBAL) + { + $forum_topics_sql = ($mode == 'post') ? ', forum_topics = forum_topics + 1, forum_topics_real = forum_topics_real + 1' : ''; + + $forum_sql = array( + 'forum_last_post_id' => $data['post_id'], + 'forum_last_post_time' => $current_time, + 'forum_last_poster_id' => (int) $user->data['user_id'], + 'forum_last_poster_name'=> ($user->data['user_id'] == ANONYMOUS) ? stripslashes($username) : $user->data['username'], + ); + + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $forum_sql) . ', forum_posts = forum_posts + 1' . $forum_topics_sql . ' + WHERE forum_id = ' . $data['forum_id']; + $db->sql_query($sql); + } + + // Update topic: first/last post info, replies + $topic_sql = array( + 'topic_last_post_id' => $data['post_id'], + 'topic_last_post_time' => $current_time, + 'topic_last_poster_id' => (int) $user->data['user_id'], + 'topic_last_poster_name'=> ($username != '') ? stripslashes($username) : (($user->data['user_id'] == ANONYMOUS) ? '' : stripslashes($user->data['username'])), + ); + + if ($mode == 'post') + { + $topic_sql = array_merge($topic_sql, array( + 'topic_first_post_id' => $data['post_id']) + ); + } + + $topic_replies_sql = ($mode == 'reply' || $mode == 'quote') ? ', topic_replies = topic_replies + 1, topic_replies_real = topic_replies_real + 1' : ''; + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $topic_sql) . $topic_replies_sql . ' + WHERE topic_id = ' . $data['topic_id']; + $db->sql_query($sql); + + // Update user post count ... if appropriate + if ($user->data['user_id'] != ANONYMOUS && $auth->acl_get('f_postcount', $data['forum_id'])) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts + 1 + WHERE user_id = ' . intval($user->data['user_id']); + $db->sql_query($sql); + } + + // post counts for index, etc. + if ($mode == 'post') + { + set_config('num_topics', $config['num_topics'] + 1, TRUE); + } + + set_config('num_posts', $config['num_posts'] + 1, TRUE); + } + + // Topic Notification + if (($data['notify_set'] == 0 || $data['notify_set'] == -1) && $data['notify']) + { + $sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' (user_id, topic_id) + VALUES (' . $user->data['user_id'] . ', ' . $data['topic_id'] . ')'; + $db->sql_query($sql); + } + else if ($data['notify_set'] == 1 && !$data['notify']) + { + $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . ' + WHERE user_id = ' . $user->data['user_id'] . ' + AND topic_id = ' . $data['topic_id']; + $db->sql_query($sql); + } + + // Mark this topic as read and posted to. + $mark_mode = ($mode == 'post' || $mode == 'reply' || $mode == 'quote') ? 'post' : 'topic'; + markread($mark_mode, $data['forum_id'], $data['topic_id'], $data['post_time']); + + $db->sql_transaction('commit'); + + // Send Notifications + if ($mode != 'edit' && $mode != 'delete') + { + user_notification($mode, stripslashes($subject), $data['forum_id'], $data['topic_id'], $data['post_id']); + } + + meta_refresh(3, "viewtopic.$phpEx$SID&f=" . $data['forum_id'] . '&t=' . $data['topic_id'] . '&p=' . $data['post_id'] . '#' . $data['post_id']); + + $message = ($auth->acl_get('f_moderate', $data['forum_id']) && !$auth->acl_get('f_ignorequeue', $data['forum_id'])) ? 'POST_STORED_MOD' : 'POST_STORED'; + $message = $user->lang[$message] . '

' . sprintf($user->lang['VIEW_MESSAGE'], '', '') . '

' . sprintf($user->lang['RETURN_FORUM'], '', ''); + trigger_error($message); +} + +// User Notification +function user_notification($mode, $subject, $forum_id, $topic_id, $post_id) +{ + global $db, $user, $config, $phpEx; + + $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; + $newtopic_notification = ($mode == 'post') ? true : false; + + if (empty($censors)) + { + $censors = array(); + obtain_word_list($censors); + } + + // Get banned User ID's + $sql = 'SELECT ban_userid + FROM ' . BANLIST_TABLE; + $result = $db->sql_query($sql); + + $sql_ignore_users = ANONYMOUS . ', ' . $user->data['user_id']; + while ($row = $db->sql_fetchrow($result)) + { + if (isset($row['ban_userid'])) + { + $sql_ignore_users .= ', ' . $row['ban_userid']; + } + } + + $allowed_users = array(); + + $sql = "SELECT u.user_id + FROM " . TOPICS_WATCH_TABLE . " tw, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u + WHERE tw.topic_id = $topic_id + AND tw.user_id NOT IN ($sql_ignore_users) + AND t.topic_id = tw.topic_id + AND u.user_id = tw.user_id"; + $result = $db->sql_query($sql); + $ids = ''; + + while ($row = $db->sql_fetchrow($result)) + { + $ids .= ($ids != '') ? ', ' . $row['user_id'] : $row['user_id']; + } + $db->sql_freeresult($result); + + if ($ids != '') + { + // TODO: Paul - correct call to check f_read for specific users ? + $sql = "SELECT a.user_id + FROM " . ACL_OPTIONS_TABLE . " ao, " . ACL_USERS_TABLE . " a + WHERE a.user_id IN (" . $ids . ") + AND ao.auth_option_id = a.auth_option_id + AND ao.auth_option = 'f_read' + AND a.forum_id = " . $forum_id; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $allowed_users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + + + + // TODO : Paul + // Now grab group settings ... users can belong to multiple groups so we grab + // the minimum setting for all options. ACL_NO overrides ACL_YES so act appropriatley + $sql = "SELECT ug.user_id, MIN(a.auth_setting) as min_setting + FROM " . USER_GROUP_TABLE . " ug, " . ACL_OPTIONS_TABLE . " ao, " . ACL_GROUPS_TABLE . " a + WHERE ug.user_id IN (" . $ids . ") + AND a.group_id = ug.group_id + AND ao.auth_option_id = a.auth_option_id + AND ao.auth_option = 'f_read' + AND a.forum_id = " . $forum_id . " + GROUP BY ao.auth_option, a.forum_id"; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + if ($row['min_setting'] == 1) + { + $allowed_users[] = $row['user_id']; + } + } + $db->sql_freeresult($result); + + $allowed_users = array_unique($allowed_users); + } + + + + + + // + if ($topic_notification) + { + $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name + FROM ' . TOPICS_WATCH_TABLE . ' tw, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_TABLE . ' f + WHERE tw.topic_id = ' . $topic_id . ' + AND tw.user_id NOT IN (' . $sql_ignore_users . ') + AND tw.notify_status = 0 + AND f.forum_id = ' . $forum_id . ' + AND t.topic_id = tw.topic_id + AND u.user_id = tw.user_id'; + } + else if ($newtopic_notification) + { + $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name + FROM ' . USERS_TABLE . ' u, ' . FORUMS_WATCH_TABLE . ' fw, ' . FORUMS_TABLE . ' f + WHERE fw.forum_id = ' . $forum_id . ' + AND fw.user_id NOT IN (' . $sql_ignore_users . ') + AND fw.notify_status = 0 + AND f.forum_id = fw.forum_id + AND u.user_id = fw.user_id'; + } + else + { + trigger_error('WRONG_NOTIFICATION_MODE'); + } + $result = $db->sql_query($sql); + + $email_users = array(); + $update_watched_sql_topic = $update_watched_sql_forum = $delete_users_topic = ''; + // + if ($row = $db->sql_fetchrow($result)) + { + if ($topic_notification) + { + decode_text($row['topic_title']); + $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $row['topic_title']) : $row['topic_title']; + } + else + { + decode_text($subject); + $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $subject) : $subject; + } + + $which_sql = ($topic_notification) ? 'update_watched_sql_topic' : 'update_watched_sql_forum'; + do + { + if (trim($row['user_email']) != '' && in_array($row['user_id'], $allowed_users)) + { + $row['email_template'] = ($topic_notification) ? 'topic_notify' : 'newtopic_notify'; + $email_users[] = $row; + + $$which_sql .= ($$which_sql != '') ? ', ' . $row['user_id'] : $row['user_id']; + } + else if (!in_array($row['user_id'], $allowed_users)) + { + $delete_users_topic .= ($delete_users_topic != '') ? ', ' . $row['user_id'] : $row['user_id']; + } + } + while ($row = $db->sql_fetchrow($result)); + } + $db->sql_freeresult($result); + + // Handle remaining Notifications (Forum) + if ($topic_notification) + { + $already_notified = ($update_watched_sql_topic == '') ? '' : $update_watched_sql_topic . ', '; + $already_notified .= ($update_watched_sql_forum == '') ? '' : $update_watched_sql_forum . ', '; + + $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name + FROM ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_WATCH_TABLE . ' fw, ' . FORUMS_TABLE . ' f + WHERE fw.forum_id = ' . $forum_id . ' + AND fw.user_id NOT IN (' . $already_notified . ' ' . $sql_ignore_users . ') + AND fw.notify_status = 0 + AND t.topic_id = ' . $topic_id . ' + AND f.forum_id = fw.forum_id + AND u.user_id = fw.user_id'; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $forum_name = $row['forum_name']; + + do + { + if (trim($row['user_email']) != '') + { + $row['email_template'] = 'forum_notify'; + $email_users[] = $row; + + $update_watched_sql_forum .= ($update_watched_sql_forum != '') ? ', ' . $row['user_id'] : $row['user_id']; + } + } + while ($row = $db->sql_fetchrow($result)); + } + } + + // We are using an email queue here, no emails are sent now, only queued. + // Returned to use the TO-Header, default package size is 100 (should be admin-definable) !? + if (sizeof($email_users) && $config['email_enable']) + { + global $phpbb_root_path, $phpEx; + + @set_time_limit(60); + + include($phpbb_root_path . 'includes/emailer.'.$phpEx); + $emailer = new emailer(true); // use queue + + $email_list_ary = array(); + foreach ($email_users as $row) + { + $pos = sizeof($email_list_ary[$row['email_template']]); + $email_list_ary[$row['email_template']][$pos]['email'] = $row['user_email']; + $email_list_ary[$row['email_template']][$pos]['name'] = $row['username']; + $email_list_ary[$row['email_template']][$pos]['lang'] = $row['user_lang']; + } + unset($email_users); + + foreach ($email_list_ary as $email_template => $email_list) + { + foreach ($email_list as $addr) + { + $emailer->template($email_template, $addr['lang']); + + $emailer->replyto($config['board_email']); + $emailer->to($addr['email'], $addr['name']); + + $emailer->assign_vars(array( + 'EMAIL_SIG' => str_replace('
', "\n", "-- \n" . $config['board_email_sig']), + 'SITENAME' => $config['sitename'], + 'TOPIC_TITLE' => trim($topic_title), + 'FORUM_NAME' => trim($forum_name), + + 'U_TOPIC' => generate_board_url() . 'viewtopic.'.$phpEx . '?t=' . $topic_id . '&p=' . $post_id . '#' . $post_id, + 'U_FORUM' => generate_board_url() . 'viewforum.'.$phpEx . '?f=' . $forum_id, + 'U_STOP_WATCHING_TOPIC' => generate_board_url() . 'viewtopic.'.$phpEx . '?t=' . $topic_id . '&unwatch=topic', + 'U_STOP_WATCHING_FORUM' => generate_board_url() . 'viewforum.'.$phpEx . '?f=' . $forum_id . '&unwatch=forum') + ); + + $emailer->send(); + $emailer->reset(); + } + } + + $emailer->queue->save(); + } + unset($email_list_ary); + + if ($delete_users_topic != '') + { + $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " + WHERE topic_id = " . $topic_id . " + AND user_id IN (" . $delete_users_topic . ")"; + $db->sql_query($sql); + } + + if ($update_watched_sql_topic != '') + { + $sql = "UPDATE " . TOPICS_WATCH_TABLE . " + SET notify_status = 1 + WHERE topic_id = " . $topic_id . " + AND user_id IN (" . $update_watched_sql_topic . ")"; + $db->sql_query($sql); + } + + if ($update_watched_sql_forum != '') + { + $sql = "UPDATE " . FORUMS_WATCH_TABLE . " + SET notify_status = 1 + WHERE forum_id = " . $forum_id . " + AND user_id IN (" . $update_watched_sql_forum . ")"; + $db->sql_query($sql); + } +} // Topic Review -function topic_review($topic_id, $is_inline_review = false) +function topic_review($topic_id, $forum_id, $is_inline_review = false) { global $template; @@ -1146,7 +1732,7 @@ function topic_review($topic_id, $is_inline_review = false) $sql = 'SELECT t.topic_title, f.forum_id FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f WHERE t.topic_id = $topic_id - AND f.forum_id = t.forum_id"; + AND f.forum_id IN (t.forum_id, $forum_id)"; $result = $db->sql_query($sql); if (!($row = $db->sql_fetchrow($result))) @@ -1276,4 +1862,8 @@ function phpbb_strtolower($string) return $new_string; } +// +// FUNCTIONS +// --------- + ?> \ No newline at end of file diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 80285cbe74..1cec5b663d 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -217,7 +217,8 @@ if ($forum_data['forum_type'] == FORUM_POST) $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . " WHERE forum_id = $forum_id - AND (topic_last_post_time >= $min_post_time) + AND topic_type <> " . POST_ANNOUNCE . " + AND topic_last_post_time >= $min_post_time " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1'); $result = $db->sql_query($sql); @@ -304,7 +305,6 @@ if ($forum_data['forum_type'] == FORUM_POST) $total_topics = 0; $row_ary = array(); - switch (SQL_LAYER) { case 'oracle': @@ -320,9 +320,9 @@ if ($forum_data['forum_type'] == FORUM_POST) $sql = "SELECT t.* $sql_select FROM $sql_from WHERE t.forum_id IN ($forum_id, 0) - AND t.topic_type = " . POST_ANNOUNCE . " + AND t.topic_type IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ") ORDER BY $sql_sort_order"; - $result = $db->sql_query_limit($sql, $config['topics_per_page']); + $result = $db->sql_query($sql); while($row = $db->sql_fetchrow($result)) { @@ -366,7 +366,6 @@ if ($forum_data['forum_type'] == FORUM_POST) { $topic_id = $row['topic_id']; - if ($config['load_db_lastread']) { $mark_time_topic = $row['mark_time']; @@ -374,7 +373,8 @@ if ($forum_data['forum_type'] == FORUM_POST) else { $topic_id36 = base_convert($topic_id, 10, 36); - $mark_time_topic = (isset($tracking_topics[$forum_id][$topic_id36])) ? base_convert($tracking_topics[$forum_id][$topic_id36], 36, 10) + $config['board_startdate'] : 0; + $forum_id36 = ($row['topic_type'] == POST_GLOBAL) ? 0 : $row['forum_id']; + $mark_time_topic = (isset($tracking_topics[$forum_id36][$topic_id36])) ? base_convert($tracking_topics[$forum_id36][$topic_id36], 36, 10) + $config['board_startdate'] : 0; } @@ -465,20 +465,20 @@ if ($forum_data['forum_type'] == FORUM_POST) // Goto message generation - if (($replies + 1) > intval($config['posts_per_page'])) + if (($replies + 1) > $config['posts_per_page']) { - $total_pages = ceil(($replies + 1) / intval($config['posts_per_page'])); + $total_pages = ceil(($replies + 1) / $config['posts_per_page']); $goto_page = ' [ ' . $user->img('icon_post', 'GOTO_PAGE') . $user->lang['GOTO_PAGE'] . ': '; $times = 1; - for($j = 0; $j < $replies + 1; $j += intval($config['posts_per_page'])) + for($j = 0; $j < $replies + 1; $j += $config['posts_per_page']) { $goto_page .= "$times"; if ($times == 1 && $total_pages > 4) { $goto_page .= ' ... '; $times = $total_pages - 3; - $j += ($total_pages - 4) * intval($config['posts_per_page']); + $j += ($total_pages - 4) * $config['posts_per_page']; } else if ($times < $total_pages) { @@ -505,26 +505,21 @@ if ($forum_data['forum_type'] == FORUM_POST) $last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "' . $row['topic_last_poster_name'] . ''; - $first_post_time = $user->format_date($row['topic_time'], $config['board_timezone']); - - $last_post_time = $user->format_date($row['topic_last_post_time']); - - $last_view_time = $user->format_date($row['topic_last_view_time']); // This will allow the style designer to output a different header // or even seperate the list of announcements from sticky and normal // topics - $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE) ? 1 : 0; + $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0; // Send vars to template $template->assign_block_vars('topicrow', array( 'FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => $topic_author, - 'FIRST_POST_TIME' => $first_post_time, - 'LAST_POST_TIME' => $last_post_time, + 'FIRST_POST_TIME' => $user->format_date($row['topic_time'], $config['board_timezone']), + 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), + 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => $last_post_author, - 'LAST_VIEW_TIME' => $last_view_time, 'GOTO_PAGE' => $goto_page, 'REPLIES' => ($auth->acl_get('m_approve')) ? $row['topic_replies_real'] : $row['topic_replies'], 'VIEWS' => $row['topic_views'], @@ -542,13 +537,13 @@ if ($forum_data['forum_type'] == FORUM_POST) 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false, - 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_gets('m_', $forum_id)) ? TRUE : FALSE, + 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_gets('m_', $forum_id)) ? TRUE : FALSE, 'S_TOPIC_UNAPPROVED' => (!$row['topic_approved'] && $auth->acl_gets('m_approve', $forum_id)) ? TRUE : FALSE, 'U_VIEW_TOPIC' => $view_topic_url) ); - $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE) ? 1 : 0; + $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0; $i++; diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index ac871350a1..06d5410c59 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -128,10 +128,6 @@ if (isset($_GET['view']) && !$post_id) } -// Look at this query ... perhaps a re-think? Perhaps store topic ids rather -// than last/first post ids and have a redirect at the top of this page -// for latest post, newest post for a given topic_id? - // This rather complex gaggle of code handles querying for topics but // also allows for direct linking to a post (and the calculation of which // page the post is on and the correct display of viewtopic) @@ -173,19 +169,6 @@ if ($user->data['user_id'] != ANONYMOUS) // whereupon we join on the forum_id passed as a parameter ... this // is done so navigation, forum name, etc. remain consistent with where // user clicked to view a global topic - - - - -// Note2: after much inspection, having to find a valid forum_id when making return_to_topic links -// for global announcements in mcp is a pain. The easiest solution is to let admins choose under -// what forum topics should be seen when forum_id is not specified (preferably a public forum) -if (!$forum_id) -{ - $forum_id = 2; -} - - $sql = 'SELECT t.topic_id, t.forum_id AS real_forum_id, t.topic_title, t.topic_attachment, t.topic_status, ' . (($auth->acl_get('m_approve')) ? 't.topic_replies_real AS topic_replies' : 't.topic_replies') . ', t.topic_last_post_id, t.topic_time, t.topic_type, t.poll_max_options, t.poll_start, t.poll_length, t.poll_title, f.forum_name, f.forum_desc, f.forum_parents, f.parent_id, f.left_id, f.right_id, f.forum_status, f.forum_id, f.forum_style, f.forum_password' . $extra_fields . ' FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f' . $join_sql_table . " WHERE $join_sql @@ -196,9 +179,6 @@ $sql = 'SELECT t.topic_id, t.forum_id AS real_forum_id, t.topic_title, t.topic_a $order_sql"; $result = $db->sql_query($sql); - - - if (!$topic_data = $db->sql_fetchrow($result)) { trigger_error('NO_TOPIC'); @@ -220,6 +200,7 @@ if ($topic_data['forum_password']) // Extract the data extract($topic_data); + // Start auth check if (!$auth->acl_get('f_read', $forum_id)) { @@ -231,7 +212,125 @@ if (!$auth->acl_get('f_read', $forum_id)) login_box(preg_replace('#.*?([a-z]+?\.' . $phpEx . '.*?)$#i', '\1', htmlspecialchars($_SERVER['REQUEST_URI'])), '', $user->lang['LOGIN_VIEWFORUM']); } -// KARMA BITS GO HERE AT PRESENT - Removed for now + + + + +// Not final in the slightest! Far too simplistic +if (isset($_GET['rate'])) +{ + // Check for rating count for previous X time + + + // Grab existing rating for this post, if it exists + $sql = 'SELECT * + FROM ' . RATINGS_TABLE . ' + WHERE user_id = ' . $user->data['user_id'] . " + AND post_id = $post_id"; + $result = $db->sql_query($sql); + + switch ($_GET['rate']) + { + case 'good': + $rate = 1; + break; + case 'bad': + $rate = -1; + break; + } + + $updated = ($row = $db->sql_fetchrow($result)) ? true : false; + $db->sql_freeresult($result); + + // Insert rating if appropriate + $sql = (!$updated) ? 'INSERT INTO ' . RATINGS_TABLE . ' (user_id, post_id, rating, rating_time) VALUES (' . $user->data['user_id'] . ", $post_id, $rate, " . time() . ')' : 'UPDATE ' . RATINGS_TABLE . " SET rating = $rate, rating_time = " . time() . " WHERE post_id = $post_id AND user_id = " . $user->data['user_id']; + $db->sql_query($sql); + + // Rating sum and count since first post + $sql = 'SELECT p.poster_id, SUM(r.rating) AS rated, COUNT(r.rating) as total_ratings + FROM ' . RATINGS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . " p2 + WHERE p2.post_id = $post_id + AND p.poster_id = p2.poster_id + AND p.post_time < " . (time() - (30 * 86400)) . ' + AND r.post_id = p.post_id + AND r.user_id <> p2.poster_id + GROUP BY p.poster_id'; + $result = $db->sql_query($sql); + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $total_ratings = $row['total_ratings']; + $historic_rating = ($row['rated'] / $row['total_ratings']) * 0.30; + + // Rating sum and count past thirty days + $sql = 'SELECT p.poster_id, SUM(r.rating) AS rated, COUNT(r.rating) as total_ratings + FROM ' . RATINGS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . " p2 + WHERE p2.post_id = $post_id + AND p.poster_id = p2.poster_id + AND p.post_time > " . (time() - (30 * 86400)) . ' + AND r.post_id = p.post_id + AND r.user_id <> p2.poster_id + GROUP BY p.poster_id'; + $result = $db->sql_query($sql); + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $total_ratings += $row['total_ratings']; + $thirty_day_rating = ($row['rated'] / $row['total_ratings']) * 0.50; + + if ($total_ratings > $config['min_ratings']) + { + // Post count and reg date for this user + $sql = 'SELECT user_id, user_regdate, user_posts + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . $row['poster_id']; + $result = $db->sql_query($sql); + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $post_count_rating = ($row['user_posts'] / $config['num_posts']) * 0.1; + $day_rating = (($row['user_regdate'] > $config['board_startdate']) ? $config['board_startdate'] / $row['user_regdate'] : 1) * 0.1; + $poster_id = $row['user_id']; + + // Number of rated posts by this user +/* $sql = 'SELECT COUNT(DISTINCT(p.post_id)) AS rated_posts + FROM ' . RATINGS_TABLE . ' r , ' . POSTS_TABLE . " p + WHERE p.poster_id = $poster_id + AND r.post_id = p.post_id + AND r.user_id <> $poster_id"; + $result = $db->sql_query($sql); + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result);*/ + + $karma = ($historic_rating + $thirty_day_rating + $day_rating + $post_count_rating) * 5; + $karma = ($karma < 0) ? floor($karma) : (($karma > 0) ? ceil($karma) : 0); + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_karma = $karma + WHERE user_id = $poster_id"; + $db->sql_query($sql); + } + + meta_refresh(3, "viewtopic.$phpEx$SID&f=$forum_id&t=$topic_id&p=$post_id#$post_id"); + $message = ($updated) ? $user->lang['RATING_UPDATED'] : $user->lang['RATING_ADDED']; + $message = $message . '

' . sprintf($user->lang['RETURN_POST'], "", ''); + trigger_error($message); +} + + + + + + + + + + + // What is start equal to? if (!empty($post_id)) @@ -331,7 +430,7 @@ gen_forum_rules('topic', $forum_id); // Quick mod tools $topic_mod = ''; -$topic_mod .= ($auth->acl_get('m_lock', $forum_id)) ? ((intval($topic_status) == ITEM_UNLOCKED) ? '' : '') : ''; +$topic_mod .= ($auth->acl_get('m_lock', $forum_id)) ? (($topic_status == ITEM_UNLOCKED) ? '' : '') : ''; $topic_mod .= ($auth->acl_get('m_delete', $forum_id)) ? '' : ''; $topic_mod .= ($auth->acl_get('m_move', $forum_id)) ? '' : ''; $topic_mod .= ($auth->acl_get('m_split', $forum_id)) ? '' : ''; @@ -378,8 +477,8 @@ $template->assign_vars(array( 'FORUM_DESC' => strip_tags($forum_desc), 'TOPIC_ID' => $topic_id, 'TOPIC_TITLE' => $topic_title, - 'PAGINATION' => (isset($_GET['view']) && $_GET['view'] == 'print') ? '' : $pagination, - 'PAGE_NUMBER' => (isset($_GET['view']) && $_GET['view'] == 'print') ? '' : on_page($total_posts, $config['posts_per_page'], $start), + 'PAGINATION' => $pagination, + 'PAGE_NUMBER' => on_page($total_posts, $config['posts_per_page'], $start), 'TOTAL_POSTS' => ($total_posts == 1) ? $user->lang['VIEW_TOPIC_POST'] : sprintf($user->lang['VIEW_TOPIC_POSTS'], $total_posts), 'MCP' => ($auth->acl_get('m_', $forum_id)) ? sprintf($user->lang['MCP'], "session_id . "&f=$forum_id&t=$topic_id&start=$start&$u_sort_param&posts_per_page=" . $config['posts_per_page'] . '">', '') : '', 'MODERATORS' => (sizeof($forum_moderators[$forum_id])) ? implode(', ', $forum_moderators[$forum_id]) : '', @@ -588,7 +687,7 @@ $sql = "SELECT u.username, u.user_id, u.user_colour, u.user_posts, u.user_from, $limit_posts_time AND u.user_id = p.poster_id ORDER BY $sort_order"; -$result = (isset($_GET['view']) && $_GET['view'] == 'print') ? $db->sql_query($sql) : $db->sql_query_limit($sql, $config['posts_per_page'], $start); +$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start); if (!$row = $db->sql_fetchrow($result)) { @@ -634,26 +733,26 @@ do } $rowset[] = array( - 'post_id' => $row['post_id'], + 'post_id' => $row['post_id'], 'post_time' => $row['post_time'], - 'poster' => ($row['user_colour']) ? '' . $poster . '' : $poster, - 'user_id' => $row['user_id'], - 'topic_id' => $row['topic_id'], - 'forum_id' => $row['forum_id'], + 'poster' => ($row['user_colour']) ? '' . $poster . '' : $poster, + 'user_id' => $row['user_id'], + 'topic_id' => $row['topic_id'], + 'forum_id' => $row['forum_id'], 'post_subject' => $row['post_subject'], 'post_edit_count' => $row['post_edit_count'], 'post_edit_time' => $row['post_edit_time'], - 'icon_id' => $row['icon_id'], - 'post_approved' => $row['post_approved'], + 'icon_id' => $row['icon_id'], + 'post_approved' => $row['post_approved'], 'post_reported' => $row['post_reported'], 'post_text' => $row['post_text'], 'post_encoding' => $row['post_encoding'], - 'bbcode_uid' => $row['bbcode_uid'], - 'bbcode_bitfield' => $row['bbcode_bitfield'], - 'enable_html' => $row['enable_html'], - 'enable_smilies' => $row['enable_smilies'], - 'enable_sig' => $row['enable_sig'], - 'display_notice' => $display_notice + 'bbcode_uid' => $row['bbcode_uid'], + 'bbcode_bitfield' => $row['bbcode_bitfield'], + 'enable_html' => $row['enable_html'], + 'enable_smilies' => $row['enable_smilies'], + 'enable_sig' => $row['enable_sig'], + 'display_notice' => $display_notice ); @@ -668,23 +767,23 @@ do if ($poster_id == ANONYMOUS) { $user_cache[$poster_id] = array( - 'joined' => '', + 'joined' => '', 'posts' => '', 'from' => '', - 'avatar' => '', - 'rank_title' => '', + 'avatar' => '', + 'rank_title' => '', 'rank_image' => '', - 'sig' => '', + 'sig' => '', 'posts' => '', - 'profile' => '', - 'pm' => '', + 'profile' => '', + 'pm' => '', 'email' => '', 'www' => '', 'icq_status_img'=> '', - 'icq' => '', - 'aim' => '', + 'icq' => '', + 'aim' => '', 'msn' => '', - 'search' => '' + 'search' => '' ); } else @@ -845,13 +944,16 @@ if (count($attach_list)) } } + +// Instantiate BBCode if need be if ($bbcode_bitfield) { - // Instantiate BBCode class include($phpbb_root_path . 'includes/bbcode.'.$phpEx); $bbcode = new bbcode($bbcode_bitfield); } + +// Output the posts foreach ($rowset as $i => $row) { $poster_id = $row['user_id']; @@ -987,14 +1089,12 @@ foreach ($rowset as $i => $row) 'SIGNATURE' => ($row['enable_sig']) ? $user_cache[$poster_id]['sig'] : '', 'EDITED_MESSAGE'=> $l_edited_by, - 'RATING' => $rating, - 'MINI_POST_IMG' => ($row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read && $user->data['user_id'] != ANONYMOUS) ? $user->img('icon_post_new', $user->lang['NEW_POST']) : $user->img('icon_post', $user->lang['POST']), 'POST_ICON_IMG' => (!empty($row['icon_id'])) ? '' : '', 'ICQ_STATUS_IMG' => $user_cache[$poster_id]['icq_status_img'], 'KARMA_IMG' => $user_cache[$poster_id]['karma_img'], - 'U_EDIT' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? "posting.$phpEx$SID&mode=edit&f=" . $row['forum_id'] . "&p=" . $row['post_id'] : '', + 'U_EDIT' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? "posting.$phpEx$SID&mode=edit&f=$forum_id&p=" . $row['post_id'] : '', 'U_QUOTE' => ($auth->acl_get('f_quote', $forum_id)) ? "posting.$phpEx$SID&mode=quote&f=$forum_id&p=" . $row['post_id'] : '', 'U_IP' => ($auth->acl_get('m_ip', $forum_id)) ? "mcp.$phpEx?sid=" . $user->session_id . "&mode=post_details&p=" . $row['post_id'] . "&t=$topic_id#ip" : '', 'U_DELETE' => (($user->data['user_id'] == $poster_id && $auth->acl_get('f_delete', $forum_id) && $topic_data['topic_last_post_id'] == $row['post_id'] && ($row['post_time'] > time() - $config['edit_time'] || !$config['edit_time'])) || $auth->acl_get('m_delete', $forum_id)) ? "posting.$phpEx$SID&mode=delete&p=" . $row['post_id'] : '', @@ -1039,18 +1139,17 @@ unset($rowset); unset($user_cache); - // Update topic view and if necessary attachment view counters ... but only // if this is the first 'page view' if (!preg_match("#&t=$topic_id#", $user->data['session_page'])) { - $sql = 'UPDATE ' . TOPICS_TABLE . " - SET topic_views = topic_views + 1, topic_last_view_time = " . time() . " + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . " WHERE topic_id = $topic_id"; $db->sql_query($sql); // Update the attachment download counts - if (count($update_count)) + if (sizeof($update_count)) { $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . ' SET download_count = download_count + 1 @@ -1061,7 +1160,8 @@ if (!preg_match("#&t=$topic_id#", $user->data['session_page'])) // Mark topics read -markread('topic', $forum_id, $topic_id, $row['post_time']); +$mark_forum_id = ($topic_type == POST_GLOBAL) ? 0 : $forum_id; +markread('topic', $mark_forum_id, $topic_id, $row['post_time']); // Change encoding if appropriate