public function submit_post_end($event)
    {
        if ($event['mode'] == 'edit') {
            // we need to ensure that what we are resetting is appropriate
            // do we care about when someone edits the first post of a topic?
            // $event['data']['topic_first_post_id'] == $event['data']['post_id'] $post_mode = 'edit_first_post'
            $ext_post_mode = '';
            if ($event['data']['topic_posts_approved'] + $event['data']['topic_posts_unapproved'] + $event['data']['topic_posts_softdeleted'] == 1) {
                $ext_post_mode = 'edit_topic';
            } else {
                if ($event['data']['topic_last_post_id'] == $event['data']['post_id']) {
                    $ext_post_mode = 'edit_last_post';
                }
            }
            if ($ext_post_mode == 'edit_last_post' || $ext_post_mode == 'edit_topic') {
                $sql = 'UPDATE ' . POSTS_TABLE . '
					SET post_time = ' . time() . '
					WHERE post_id = ' . $event['data']['post_id'] . '
						AND topic_id = ' . $event['data']['topic_id'];
                $this->db->sql_query($sql);
                $sql = 'UPDATE ' . TOPICS_TABLE . '
					SET topic_last_post_time = ' . time() . '
					WHERE topic_id = ' . $event['data']['topic_id'];
                $this->db->sql_query($sql);
                if (!function_exists('update_post_information')) {
                    include $this->root_path . 'includes/functions_posting.' . $this->php_ext;
                }
                update_post_information('forum', $event['data']['forum_id']);
                markread('post', $event['data']['forum_id'], $event['data']['topic_id'], $event['data']['post_time']);
            }
        }
    }
function mark_all_as_read_func($xmlrpc_params)
{
    $params = php_xmlrpc_decode($xmlrpc_params);
    if (!isset($params[0]) || $params[0] === 0) {
        markread('all');
    } else {
        $forum_id = intval($params[0]);
        markread('topics', $forum_id);
    }
    $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'result_text' => new xmlrpcval('', 'base64')), 'struct');
    return new xmlrpcresp($response);
}
/**
* Submit Post
*/
function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
{
    global $config, $_CORE_CONFIG, $_CLASS;
    // We do not handle erasing posts here
    if ($mode == 'delete') {
        return false;
    }
    $current_time = $_CLASS['core_user']->time;
    if ($mode == 'post') {
        $post_mode = 'post';
        $update_message = true;
    } else {
        if ($mode != 'edit') {
            $post_mode = 'reply';
            $update_message = true;
        } else {
            if ($mode == 'edit') {
                $post_mode = $data['topic_first_post_id'] == $data['topic_last_post_id'] ? 'edit_topic' : ($data['topic_first_post_id'] == $data['post_id'] ? 'edit_first_post' : ($data['topic_last_post_id'] == $data['post_id'] ? 'edit_last_post' : 'edit'));
            }
        }
    }
    // Collect some basic informations about which tables and which rows to update/insert
    $sql_data = array();
    $poster_id = $mode == 'edit' ? $data['poster_id'] : (int) $_CLASS['core_user']->data['user_id'];
    // Collect Informations
    switch ($post_mode) {
        case 'post':
        case 'reply':
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => (int) $_CLASS['core_user']->data['user_id'], 'icon_id' => $data['icon_id'], 'poster_ip' => $_CLASS['core_user']->ip, 'post_time' => $current_time, 'post_approved' => !$_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) && !$_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? 0 : 1, 'enable_html' => $data['enable_html'], 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => !$_CLASS['core_user']->is_user ? $username : '', 'post_subject' => $subject, 'post_text' => $data['message'], 'post_checksum' => $data['message_md5'], 'post_attachment' => empty($data['attachment_data']) ? 0 : 1, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_postcount' => $_CLASS['forums_auth']->acl_get('f_postcount', $data['forum_id']) ? 1 : 0, 'post_edit_locked' => $data['post_edit_locked']);
            break;
        case 'edit_first_post':
        case 'edit':
            if (!$_CLASS['forums_auth']->acl_get('m_edit', $data['forum_id']) || $data['post_edit_reason']) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time);
                $sql_data[FORUMS_POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            }
            // no break
        // no break
        case 'edit_last_post':
        case 'edit_topic':
            if (($post_mode == 'edit_last_post' || $post_mode == 'edit_topic') && $data['post_edit_reason']) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time);
                $sql_data[FORUMS_POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            }
            if (!isset($sql_data[FORUMS_POSTS_TABLE]['sql'])) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array();
            }
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], 'post_approved' => !$_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) && !$_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? 0 : 1, 'enable_html' => $data['enable_html'], 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => $username && $data['poster_id'] == ANONYMOUS ? $username : '', 'post_subject' => $subject, 'post_edit_reason' => $data['post_edit_reason'], 'post_edit_user' => (int) $data['post_edit_user'], 'post_checksum' => $data['message_md5'], 'post_attachment' => empty($data['attachment_data']) ? 0 : 1, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked']));
            if ($update_message) {
                $sql_data[FORUMS_POSTS_TABLE]['sql']['post_text'] = $data['message'];
            }
            break;
    }
    // And the topic ladies and gentlemen
    switch ($post_mode) {
        case 'post':
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('topic_poster' => (int) $_CLASS['core_user']->data['user_id'], 'topic_time' => $current_time, 'forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => !$_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) && !$_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? 0 : 1, 'topic_title' => $subject, 'topic_first_poster_name' => !$_CLASS['core_user']->is_user && $username ? $username : ($_CLASS['core_user']->data['user_id'] != ANONYMOUS ? $_CLASS['core_user']->data['username'] : ''), 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'topic_attachment' => empty($data['attachment_data']) ? 0 : 1, 'topic_status' => 0, 'topic_replies_real' => 0, 'topic_replies' => 0, 'topic_views' => 0, 'topic_moved_id' => 0);
            if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
                $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array_merge($sql_data[FORUMS_TOPICS_TABLE]['sql'], array('poll_title' => $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, 'poll_vote_change' => $poll['poll_vote_change']));
            }
            $sql_data[CORE_USERS_TABLE]['stat'][] = "user_last_post_time = {$current_time}" . ($_CLASS['forums_auth']->acl_get('f_postcount', $data['forum_id']) ? ', user_posts = user_posts + 1' : '');
            if ($topic_type != POST_GLOBAL) {
                if ($_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id'])) {
                    $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
                }
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ($_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? ', forum_topics = forum_topics + 1' : '');
            }
            break;
        case 'reply':
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . ($_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? ', topic_replies = topic_replies + 1' : '');
            $sql_data[CORE_USERS_TABLE]['stat'][] = "user_last_post_time = {$current_time}" . ($_CLASS['forums_auth']->acl_get('f_postcount', $data['forum_id']) ? ', user_posts = user_posts + 1' : '');
            if (($_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id'])) && $topic_type != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
            }
            break;
        case 'edit_topic':
        case 'edit_first_post':
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => !$_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) && !$_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? 0 : 1, 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'poll_title' => isset($poll['poll_options']) ? $poll['poll_title'] : '', 'poll_start' => isset($poll['poll_options']) ? $poll['poll_start'] ? $poll['poll_start'] : $current_time : 0, 'poll_max_options' => isset($poll['poll_options']) ? $poll['poll_max_options'] : 1, 'poll_length' => isset($poll['poll_options']) ? $poll['poll_length'] * 86400 : 0, 'poll_vote_change' => isset($poll['poll_vote_change']) ? $poll['poll_vote_change'] : 0, 'topic_attachment' => empty($data['attachment_data']) ? 0 : 1);
            break;
    }
    $_CLASS['core_db']->transaction();
    // Submit new topic
    if ($post_mode === 'post') {
        $sql = 'INSERT INTO ' . FORUMS_TOPICS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $sql_data[FORUMS_TOPICS_TABLE]['sql']);
        $_CLASS['core_db']->query($sql);
        $data['topic_id'] = $_CLASS['core_db']->insert_id(FORUMS_TOPICS_TABLE, 'topic_id');
        $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        unset($sql_data[FORUMS_TOPICS_TABLE]['sql']);
    }
    // Submit new post
    if ($post_mode === 'post' || $post_mode === 'reply') {
        if ($post_mode === 'reply') {
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        }
        $_CLASS['core_db']->sql_query_build('INSERT', $sql_data[FORUMS_POSTS_TABLE]['sql'], FORUMS_POSTS_TABLE);
        unset($sql_data[FORUMS_POSTS_TABLE]['sql']);
        $data['post_id'] = $_CLASS['core_db']->insert_id(FORUMS_POSTS_TABLE, 'post_id');
        if ($post_mode === 'post') {
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('topic_first_post_id' => $data['post_id'], 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => (int) $_CLASS['core_user']->data['user_id'], 'topic_last_poster_name' => !$_CLASS['core_user']->is_user && $username ? $username : ($_CLASS['core_user']->data['user_id'] != ANONYMOUS ? $_CLASS['core_user']->data['username'] : ''));
        }
    }
    $make_global = false;
    // Are we globalising or unglobalising?
    if ($post_mode === 'edit_first_post' || $post_mode === 'edit_topic') {
        $sql = 'SELECT topic_type, topic_replies_real, topic_approved
			FROM ' . FORUMS_TOPICS_TABLE . '
			WHERE topic_id = ' . $data['topic_id'];
        $result = $_CLASS['core_db']->query($sql);
        $row = $_CLASS['core_db']->fetch_row_assoc($result);
        $_CLASS['core_db']->free_result($result);
        // globalise
        if ($row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) {
            // Decrement topic/post count
            $make_global = true;
            $sql_data[FORUMS_FORUMS_TABLE]['stat'] = array();
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($row['topic_replies_real'] + 1);
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . ($row['topic_approved'] ? ', forum_topics = forum_topics - 1' : '');
            // Update forum_ids for all posts
            $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
				SET forum_id = 0
				WHERE topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        } else {
            if ($row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) {
                // Increment topic/post count
                $make_global = true;
                $sql_data[FORUMS_FORUMS_TABLE]['stat'] = array();
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($row['topic_replies_real'] + 1);
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ($row['topic_approved'] ? ', forum_topics = forum_topics + 1' : '');
                // Update forum_ids for all posts
                $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
				SET forum_id = ' . $data['forum_id'] . '
				WHERE topic_id = ' . $data['topic_id'];
                $_CLASS['core_db']->query($sql);
            }
        }
    }
    // Update the topics table
    if (isset($sql_data[FORUMS_TOPICS_TABLE]['sql'])) {
        $sql = 'UPDATE ' . FORUMS_TOPICS_TABLE . '
			SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_data[FORUMS_TOPICS_TABLE]['sql']) . '
			WHERE topic_id = ' . $data['topic_id'];
        $_CLASS['core_db']->query($sql);
    }
    // Update the posts table
    if (isset($sql_data[FORUMS_POSTS_TABLE]['sql'])) {
        $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
			SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_data[FORUMS_POSTS_TABLE]['sql']) . '
			WHERE post_id = ' . $data['post_id'];
        $_CLASS['core_db']->query($sql);
    }
    // Update Poll Tables
    if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
        $cur_poll_options = array();
        if ($poll['poll_start'] && $mode == 'edit') {
            $sql = 'SELECT * FROM ' . FORUMS_POLL_OPTIONS_TABLE . '
				WHERE topic_id = ' . $data['topic_id'] . '
				ORDER BY poll_option_id';
            $result = $_CLASS['core_db']->query($sql);
            $cur_poll_options = array();
            while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                $cur_poll_options[] = $row;
            }
            $_CLASS['core_db']->free_result($result);
        }
        $sql_insert_ary = array();
        for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++) {
            if (trim($poll['poll_options'][$i])) {
                if (empty($cur_poll_options[$i])) {
                    $sql_insert_ary[] = array('poll_option_id' => (int) $i, 'topic_id' => (int) $data['topic_id'], 'poll_option_text' => (string) $poll['poll_options'][$i], 'poll_option_total' => 0);
                } else {
                    if ($poll['poll_options'][$i] != $cur_poll_options[$i]) {
                        $sql = "UPDATE " . FORUMS_POLL_OPTIONS_TABLE . "\r\n\t\t\t\t\t\tSET poll_option_text = '" . $_CLASS['core_db']->escape($poll['poll_options'][$i]) . "'\r\n\t\t\t\t\t\tWHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "\r\n\t\t\t\t\t\t\tAND topic_id = " . $data['topic_id'];
                        $_CLASS['core_db']->query($sql);
                    }
                }
            }
        }
        if (!empty($sql_insert_ary)) {
            $_CLASS['core_db']->sql_query_build('MULTI_INSERT', $sql_insert_ary, FORUMS_POLL_OPTIONS_TABLE);
            unset($sql_insert_ary);
        }
        if (count($poll['poll_options']) < count($cur_poll_options)) {
            $sql = 'DELETE FROM ' . FORUMS_POLL_OPTIONS_TABLE . '
				WHERE poll_option_id >= ' . count($poll['poll_options']) . '
					AND topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
    }
    // Submit Attachments
    if (count($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) {
        $space_taken = $files_added = $files_updated = 0;
        $orphan_rows = array();
        foreach ($data['attachment_data'] as $pos => $attach_row) {
            $orphan_rows[(int) $attach_row['attach_id']] = array();
        }
        if (sizeof($orphan_rows)) {
            $sql = 'SELECT attach_id, filesize, physical_filename
				FROM ' . FORUMS_ATTACHMENTS_TABLE . '
				WHERE attach_id IN (' . implode(', ', array_keys($orphan_rows)) . ')
					AND is_orphan = 1
					AND poster_id = ' . $_CLASS['core_user']->data['user_id'];
            $result = $_CLASS['core_db']->query($sql);
            $orphan_rows = array();
            while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
                $orphan_rows[$row['attach_id']] = $row;
            }
            $_CLASS['core_db']->free_result($result);
        }
        foreach ($data['attachment_data'] as $pos => $attach_row) {
            if ($attach_row['is_orphan'] && !in_array($attach_row['attach_id'], array_keys($orphan_rows))) {
                continue;
            }
            if (!$attach_row['is_orphan']) {
                // update entry in db if attachment already stored in db and filespace
                $sql = 'UPDATE ' . FORUMS_ATTACHMENTS_TABLE . "\r\n\t\t\t\t\tSET attach_comment = '" . $_CLASS['core_db']->escape($attach_row['attach_comment']) . "'\r\n\t\t\t\t\tWHERE attach_id = " . (int) $attach_row['attach_id'] . '
						AND is_orphan = 0';
                $_CLASS['core_db']->query($sql);
            } else {
                // insert attachment into db
                if (!@file_exists(SITE_FILE_ROOT . $config['upload_path'] . '/' . basename($orphan_rows[$attach_row['attach_id']]['physical_filename']))) {
                    continue;
                }
                $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize'];
                $files_added++;
                $attach_sql = array('post_msg_id' => $data['post_id'], 'topic_id' => $data['topic_id'], 'is_orphan' => 0, 'poster_id' => $poster_id, 'attach_comment' => $attach_row['attach_comment']);
                $sql = 'UPDATE ' . FORUMS_ATTACHMENTS_TABLE . ' SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $attach_sql) . '
					WHERE attach_id = ' . $attach_row['attach_id'] . '
						AND is_orphan = 1
						AND poster_id = ' . $user->data['user_id'];
                $_CLASS['core_db']->query($sql);
            }
        }
        if ($files_updated || $files_added) {
            set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
            set_config('num_files', $config['num_files'] + $files_added, true);
        }
    }
    $_CLASS['core_db']->transaction('commit');
    if ($post_mode === 'post' || $post_mode === 'reply' || $post_mode === 'edit_last_post') {
        if ($topic_type != POST_GLOBAL) {
            $update_sql = update_post_information('forum', $data['forum_id'], true);
            if (sizeof($update_sql)) {
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = implode(', ', $update_sql[$data['forum_id']]);
            }
        }
        $update_sql = update_post_information('topic', $data['topic_id'], true);
        if (sizeof($update_sql)) {
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = implode(', ', $update_sql[$data['topic_id']]);
        }
    }
    if ($make_global) {
        $update_sql = update_post_information('forum', $data['forum_id'], true);
        if (sizeof($update_sql)) {
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = implode(', ', $update_sql[$data['forum_id']]);
        }
    }
    if ($post_mode === 'edit_topic') {
        $update_sql = update_post_information('topic', $data['topic_id'], true);
        if (sizeof($update_sql)) {
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = implode(', ', $update_sql[$data['topic_id']]);
        }
    }
    // Update total post count, do not consider moderated posts/topics
    if ($_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id'])) {
        if ($post_mode === 'post') {
            set_config('num_topics', $config['num_topics'] + 1, true);
            set_config('num_posts', $config['num_posts'] + 1, true);
        }
        if ($post_mode === 'reply') {
            set_config('num_posts', $config['num_posts'] + 1, true);
        }
    }
    // Update forum stats
    $_CLASS['core_db']->transaction();
    $where_sql = array(FORUMS_POSTS_TABLE => 'post_id = ' . $data['post_id'], FORUMS_TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], CORE_USERS_TABLE => 'user_id = ' . $_CLASS['core_user']->data['user_id']);
    foreach ($sql_data as $table => $update_ary) {
        if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) {
            $_CLASS['core_db']->query("UPDATE {$table} SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]);
        }
    }
    // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
    if ($make_global) {
        $sql = 'DELETE FROM ' . FORUMS_TOPICS_TABLE . '
			WHERE topic_moved_id = ' . $data['topic_id'];
        $_CLASS['core_db']->query($sql);
    }
    // Index message contents
    if (false && $update_message && $data['enable_indexing']) {
        // Select the search method and do some additional checks to ensure it can actually be utilised
        $search_type = basename($config['search_type']);
        if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) {
            trigger_error('NO_SUCH_SEARCH_MODULE');
        }
        require "{$phpbb_root_path}includes/search/{$search_type}.{$phpEx}";
        $error = false;
        $search = new $search_type($error);
        if ($error) {
            trigger_error($error);
        }
        $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $topic_type == POST_GLOBAL ? 0 : $data['forum_id']);
    }
    $_CLASS['core_db']->transaction('commit');
    // Delete draft if post was loaded...
    $draft_id = request_var('draft_loaded', 0);
    if ($draft_id) {
        $sql = 'DELETE FROM ' . FORUMS_DRAFTS_TABLE . "\r\n\t\t\tWHERE draft_id = {$draft_id}\r\n\t\t\t\tAND user_id = {$_CLASS['core_user']->data['user_id']}";
        $_CLASS['core_db']->query($sql);
    }
    // Topic Notification, do not change if moderator is changing other users posts...
    if ($_CLASS['core_user']->data['user_id'] == $poster_id) {
        if (!$data['notify_set'] && $data['notify']) {
            $notify_sql = array('user_id' => $_CLASS['core_user']->data['user_id'], 'forum_id' => $data['forum_id'], 'topic_id' => $data['topic_id'], 'notify_type' => $poster_id, 'notify_status' => 0);
            $_CLASS['core_db']->sql_query_build('INSERT', $notify_sql, FORUMS_WATCH_TABLE);
            unset($notify_sql);
        } else {
            if ($data['notify_set'] && !$data['notify']) {
                $sql = 'DELETE FROM ' . FORUMS_TOPICS_WATCH_TABLE . '
				WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . '
					AND topic_id = ' . $data['topic_id'];
                $_CLASS['core_db']->query($sql);
            }
        }
    }
    if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') {
        // Mark this topic as posted to
        markread('post', $data['forum_id'], $data['topic_id'], $data['post_time']);
    }
    // Mark this topic as read
    // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
    markread('topic', $data['forum_id'], $data['topic_id'], $_CLASS['core_user']->time);
    // Send Notifications
    if ($mode !== 'edit' && $mode !== 'delete' && ($_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']))) {
        user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']);
    }
    if ($mode === 'post') {
        $url = $_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? generate_link('forums&amp;file=viewtopic&amp;f=' . $data['forum_id'] . '&amp;t=' . $data['topic_id']) : generate_link('forums&amp;file=viewforum&amp;f=' . $data['forum_id']);
    } else {
        $url = $_CLASS['forums_auth']->acl_get('f_noapprove', $data['forum_id']) || $_CLASS['forums_auth']->acl_get('m_approve', $data['forum_id']) ? generate_link("forums&amp;file=viewtopic&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}&amp;p={$data['post_id']}") . "#p{$data['post_id']}" : generate_link("forums&amp;file=viewtopic&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}");
    }
    return $url;
}
Ejemplo n.º 4
0
$template->assign_vars(array('U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}" . ($start == 0 ? '' : "&amp;start={$start}"))));
// Not postable forum or showing active topics?
if (!($forum_data['forum_type'] == FORUM_POST || $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS && $forum_data['forum_type'] == FORUM_CAT)) {
    page_footer();
}
// Ok, if someone has only list-access, we only display the forum list.
// We also make this circumstance available to the template in case we want to display a notice. ;)
if (!$auth->acl_get('f_read', $forum_id)) {
    $template->assign_vars(array('S_NO_READ_ACCESS' => true));
    page_footer();
}
// Handle marking posts
if ($mark_read == 'topics') {
    $token = $request->variable('hash', '');
    if (check_link_hash($token, 'global')) {
        markread('topics', array($forum_id), false, $request->variable('mark_time', 0));
    }
    $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
    meta_refresh(3, $redirect_url);
    if ($request->is_ajax()) {
        // Tell the ajax script what language vars and URL need to be replaced
        $data = array('NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], 'U_MARK_TOPICS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'hash=' . generate_link_hash('global') . "&f={$forum_id}&mark=topics&mark_time=" . time()) : '', 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['TOPICS_MARKED']);
        $json_response = new \phpbb\json_response();
        $json_response->send($data);
    }
    trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
}
// Is a forum specific topic count required?
if ($forum_data['forum_topics_per_page']) {
    $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
}
Ejemplo n.º 5
0
    public function update_read_tracking($data)
    {
        // Mark the post and the topic read
        markread('post', (int) $data['forum_id'], (int) $data['topic_id'], $data['post_time']);
        markread('topic', (int) $data['forum_id'], (int) $data['topic_id'], time());
        // Handle read tracking
        if ($this->config['load_db_lastread'] && $this->user->data['is_registered']) {
            $sql = 'SELECT mark_time
				FROM ' . FORUMS_TRACK_TABLE . '
				WHERE user_id = ' . (int) $this->user->data['user_id'] . '
					AND forum_id = ' . (int) $data['forum_id'];
            $result = $this->db->sql_query($sql);
            $f_mark_time = (int) $this->db->sql_fetchfield('mark_time');
            $this->db->sql_freeresult($result);
        } else {
            if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
                $f_mark_time = false;
            }
        }
        if ($this->config['load_db_lastread'] && $this->user->data['is_registered'] || $this->config['load_anon_lastread'] || $this->user->data['is_registered']) {
            // Update forum info
            $sql = 'SELECT forum_last_post_time
				FROM ' . FORUMS_TABLE . '
				WHERE forum_id = ' . (int) $data['forum_id'];
            $result = $this->db->sql_query($sql);
            $forum_last_post_time = (int) $this->db->sql_fetchfield('forum_last_post_time');
            $this->db->sql_freeresult($result);
            update_forum_tracking_info((int) $data['forum_id'], $forum_last_post_time, $f_mark_time, false);
        }
    }
Ejemplo n.º 6
0
$template->assign_vars(array('U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}&amp;start={$start}")));
// Not postable forum or showing active topics?
if (!($forum_data['forum_type'] == FORUM_POST || $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS && $forum_data['forum_type'] == FORUM_CAT)) {
    page_footer();
}
// Ok, if someone has only list-access, we only display the forum list.
// We also make this circumstance available to the template in case we want to display a notice. ;)
if (!$auth->acl_get('f_read', $forum_id)) {
    $template->assign_vars(array('S_NO_READ_ACCESS' => true, 'S_AUTOLOGIN_ENABLED' => $config['allow_autologin'] ? true : false, 'S_LOGIN_ACTION' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=login') . '&amp;redirect=' . urlencode(str_replace('&amp;', '&', build_url()))));
    page_footer();
}
// Handle marking posts
if ($mark_read == 'topics') {
    $token = request_var('hash', '');
    if (check_link_hash($token, 'global')) {
        markread('topics', $forum_id);
    }
    $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
    meta_refresh(3, $redirect_url);
    trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
}
// Is a forum specific topic count required?
if ($forum_data['forum_topics_per_page']) {
    $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
}
// Do the forum Prune thang - cron type job ...
if ($forum_data['prune_next'] < time() && $forum_data['enable_prune']) {
    $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
}
// Forum rules and subscription info
$s_watching_forum = array('link' => '', 'title' => '', 'is_watching' => false);
Ejemplo n.º 7
0
/**
* Display Forums
*/
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
{
    global $db, $auth, $user, $template;
    global $phpbb_root_path, $phpEx, $config;
    $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
    $parent_id = $visible_forums = 0;
    $sql_from = '';
    // Mark forums read?
    $mark_read = request_var('mark', '');
    if ($mark_read == 'all') {
        $mark_read = '';
    }
    if (!$root_data) {
        if ($mark_read == 'forums') {
            $mark_read = 'all';
        }
        $root_data = array('forum_id' => 0);
        $sql_where = '';
    } else {
        $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
    }
    // Display list of active topics for this category?
    $show_active = isset($root_data['forum_flags']) && $root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS ? true : false;
    $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
        $sql_array['SELECT'] .= ', ft.mark_time';
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            $tracking_topics = isset($_COOKIE[$config['cookie_name'] . '_track']) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track'] : '';
            $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
            if (!$user->data['is_registered']) {
                $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
            }
        }
    }
    if ($show_active) {
        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_ACCESS_TABLE => 'fa'), 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'");
        $sql_array['SELECT'] .= ', fa.user_id';
    }
    $sql = $db->sql_build_query('SELECT', array('SELECT' => $sql_array['SELECT'], 'FROM' => $sql_array['FROM'], 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], 'WHERE' => $sql_where, 'ORDER_BY' => 'f.left_id'));
    $result = $db->sql_query($sql);
    $forum_tracking_info = array();
    $branch_root_id = $root_data['forum_id'];
    // Check for unread global announcements (index page only)
    $ga_unread = false;
    if ($root_data['forum_id'] == 0) {
        $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
        if (!empty($unread_ga_list)) {
            $ga_unread = true;
        }
    }
    while ($row = $db->sql_fetchrow($result)) {
        $forum_id = $row['forum_id'];
        // Mark forums read?
        if ($mark_read == 'forums' || $mark_read == 'all') {
            if ($auth->acl_get('f_list', $forum_id)) {
                $forum_ids[] = $forum_id;
                continue;
            }
        }
        // Category with no members
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            continue;
        }
        // Skip branch
        if (isset($right_id)) {
            if ($row['left_id'] < $right_id) {
                continue;
            }
            unset($right_id);
        }
        if (!$auth->acl_get('f_list', $forum_id)) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        $forum_ids[] = $forum_id;
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $forum_tracking_info[$forum_id] = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                if (!$user->data['is_registered']) {
                    $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
                }
                $forum_tracking_info[$forum_id] = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
        }
        // Count the difference of real to public topics, so we can display an information to moderators
        $row['forum_id_unapproved_topics'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_topics_real'] != $row['forum_topics'] ? $forum_id : 0;
        $row['forum_topics'] = $auth->acl_get('m_approve', $forum_id) ? $row['forum_topics_real'] : $row['forum_topics'];
        // Display active topics from this forum?
        if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && $row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) {
            if (!isset($active_forum_ary['forum_topics'])) {
                $active_forum_ary['forum_topics'] = 0;
            }
            if (!isset($active_forum_ary['forum_posts'])) {
                $active_forum_ary['forum_posts'] = 0;
            }
            $active_forum_ary['forum_id'][] = $forum_id;
            $active_forum_ary['enable_icons'][] = $row['enable_icons'];
            $active_forum_ary['forum_topics'] += $row['forum_topics'];
            $active_forum_ary['forum_posts'] += $row['forum_posts'];
            // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
            if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) {
                $active_forum_ary['exclude_forum_id'][] = $forum_id;
            }
        }
        //
        if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) {
            if ($row['forum_type'] != FORUM_CAT) {
                $forum_ids_moderator[] = (int) $forum_id;
            }
            // Direct child of current branch
            $parent_id = $forum_id;
            $forum_rows[$forum_id] = $row;
            if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) {
                $branch_root_id = $forum_id;
            }
            $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
            $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
        } else {
            if ($row['forum_type'] != FORUM_CAT) {
                $subforums[$parent_id][$forum_id]['display'] = $row['display_on_index'] ? true : false;
                $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
                $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
                $subforums[$parent_id][$forum_id]['children'] = array();
                if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index']) {
                    $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
                }
                if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics']) {
                    $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
                }
                $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
                // Do not list redirects in LINK Forums as Posts.
                if ($row['forum_type'] != FORUM_LINK) {
                    $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
                }
                if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) {
                    $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
                    $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
                    $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
                    $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
                    $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
                    $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
                    $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
                }
            }
        }
    }
    $db->sql_freeresult($result);
    // Handle marking posts
    if ($mark_read == 'forums' || $mark_read == 'all') {
        $redirect = build_url(array('mark', 'hash'));
        $token = request_var('hash', '');
        if (check_link_hash($token, 'global')) {
            if ($mark_read == 'all') {
                markread('all');
                $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
            } else {
                // Add 0 to forums array to mark global announcements correctly
                $forum_ids[] = 0;
                markread('topics', $forum_ids);
                $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
            }
            meta_refresh(3, $redirect);
            trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
        } else {
            $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
            meta_refresh(3, $redirect);
            trigger_error($message);
        }
    }
    // Grab moderators ... if necessary
    if ($display_moderators) {
        if ($return_moderators) {
            $forum_ids_moderator[] = $root_data['forum_id'];
        }
        get_moderators($forum_moderators, $forum_ids_moderator);
    }
    // Used to tell whatever we have to create a dummy category or not.
    $last_catless = true;
    foreach ($forum_rows as $row) {
        // Empty category
        if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT) {
            $template->assign_block_vars('forumrow', array('S_IS_CAT' => true, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'FORUM_FOLDER_IMG' => '', 'FORUM_FOLDER_IMG_SRC' => '', 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id'])));
            continue;
        }
        $visible_forums++;
        $forum_id = $row['forum_id'];
        $forum_unread = isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id] ? true : false;
        // Mark the first visible forum on index as unread if there's any unread global announcement
        if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0]) {
            $forum_unread = true;
        }
        $folder_image = $folder_alt = $l_subforums = '';
        $subforums_list = array();
        // Generate list of subforums if we need to
        if (isset($subforums[$forum_id])) {
            foreach ($subforums[$forum_id] as $subforum_id => $subforum_row) {
                $subforum_unread = isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id] ? true : false;
                if (!$subforum_unread && !empty($subforum_row['children'])) {
                    foreach ($subforum_row['children'] as $child_id) {
                        if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id]) {
                            // Once we found an unread child forum, we can drop out of this loop
                            $subforum_unread = true;
                            break;
                        }
                    }
                }
                if ($subforum_row['display'] && $subforum_row['name']) {
                    $subforums_list[] = array('link' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $subforum_id), 'name' => $subforum_row['name'], 'unread' => $subforum_unread);
                } else {
                    unset($subforums[$forum_id][$subforum_id]);
                }
                // If one subforum is unread the forum gets unread too...
                if ($subforum_unread) {
                    $forum_unread = true;
                }
            }
            $l_subforums = sizeof($subforums[$forum_id]) == 1 ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
            $folder_image = $forum_unread ? 'forum_unread_subforum' : 'forum_read_subforum';
        } else {
            switch ($row['forum_type']) {
                case FORUM_POST:
                    $folder_image = $forum_unread ? 'forum_unread' : 'forum_read';
                    break;
                case FORUM_LINK:
                    $folder_image = 'forum_link';
                    break;
            }
        }
        // Which folder should we display?
        if ($row['forum_status'] == ITEM_LOCKED) {
            $folder_image = $forum_unread ? 'forum_unread_locked' : 'forum_read_locked';
            $folder_alt = 'FORUM_LOCKED';
        } else {
            $folder_alt = $forum_unread ? 'NEW_POSTS' : 'NO_NEW_POSTS';
        }
        // Create last post link information, if appropriate
        if ($row['forum_last_post_id']) {
            $last_post_subject = $row['forum_last_post_subject'];
            $last_post_time = $user->format_date($row['forum_last_post_time']);
            $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
        } else {
            $last_post_subject = $last_post_time = $last_post_url = '';
        }
        // Output moderator listing ... if applicable
        $l_moderator = $moderators_list = '';
        if ($display_moderators && !empty($forum_moderators[$forum_id])) {
            $l_moderator = sizeof($forum_moderators[$forum_id]) == 1 ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
            $moderators_list = implode(', ', $forum_moderators[$forum_id]);
        }
        $l_post_click_count = $row['forum_type'] == FORUM_LINK ? 'CLICKS' : 'POSTS';
        $post_click_count = $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK ? $row['forum_posts'] : '';
        $s_subforums_list = array();
        foreach ($subforums_list as $subforum) {
            $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . ($subforum['unread'] ? 'unread' : 'read') . '" title="' . ($subforum['unread'] ? $user->lang['NEW_POSTS'] : $user->lang['NO_NEW_POSTS']) . '">' . $subforum['name'] . '</a>';
        }
        $s_subforums_list = (string) implode(', ', $s_subforums_list);
        $catless = $row['parent_id'] == $root_data['forum_id'] ? true : false;
        if ($row['forum_type'] != FORUM_LINK) {
            $u_viewforum = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']);
        } else {
            // If the forum is a link and we count redirects we need to visit it
            // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
            if ($row['forum_flags'] & FORUM_FLAG_LINK_TRACK || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id)) {
                $u_viewforum = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']);
            } else {
                $u_viewforum = $row['forum_link'];
            }
        }
        $template->assign_block_vars('forumrow', array('S_IS_CAT' => false, 'S_NO_CAT' => $catless && !$last_catless, 'S_IS_LINK' => $row['forum_type'] == FORUM_LINK ? true : false, 'S_UNREAD_FORUM' => $forum_unread, 'S_LOCKED_FORUM' => $row['forum_status'] == ITEM_LOCKED ? true : false, 'S_LIST_SUBFORUMS' => $row['display_subforum_list'] ? true : false, 'S_SUBFORUMS' => sizeof($subforums_list) ? true : false, 'S_FEED_ENABLED' => $config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) ? true : false, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'TOPICS' => $row['forum_topics'], $l_post_click_count => $post_click_count, 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'), 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '', 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'LAST_POST_SUBJECT' => censor_text($last_post_subject), 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'MODERATORS' => $moderators_list, 'SUBFORUMS' => $s_subforums_list, 'L_SUBFORUM_STR' => $l_subforums, 'L_FORUM_FOLDER_ALT' => $folder_alt, 'L_MODERATOR_STR' => $l_moderator, 'U_UNAPPROVED_TOPICS' => $row['forum_id_unapproved_topics'] ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '', 'U_VIEWFORUM' => $u_viewforum, 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST' => $last_post_url));
        // Assign subforums loop for style authors
        foreach ($subforums_list as $subforum) {
            $template->assign_block_vars('forumrow.subforum', array('U_SUBFORUM' => $subforum['link'], 'SUBFORUM_NAME' => $subforum['name'], 'S_UNREAD' => $subforum['unread']));
        }
        $last_catless = $catless;
    }
    $template->assign_vars(array('U_MARK_FORUMS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums') : '', 'S_HAS_SUBFORUM' => $visible_forums ? true : false, 'L_SUBFORUM' => $visible_forums == 1 ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED')));
    if ($return_moderators) {
        return array($active_forum_ary, $forum_moderators);
    }
    return array($active_forum_ary, array());
}
Ejemplo n.º 8
0
    }
    // List comments
    $sql = $db->sql_build_query('SELECT', array('SELECT' => 'p.*, u.*, r.rank_title', 'FROM' => array(POSTS_TABLE => 'p', USERS_TABLE => 'u'), 'WHERE' => "p.topic_id = {$topic_id}\n\t\t\tAND p.post_id != {$report['post_id']}\n\t\t\t" . (!$auth->acl_get('m_approve', $forum_id) ? 'AND p.post_approved = 1' : '') . '
			AND u.user_id = p.poster_id', 'LEFT_JOIN' => array(array('FROM' => array(RANKS_TABLE => 'r'), 'ON' => 'u.user_rank = r.rank_id AND r.rank_special = 1')), 'ORDER_BY' => 'p.post_time ' . ($user->data['user_post_sortby_dir'] == 'a' ? 'ASC' : 'DESC')));
    $result = $db->sql_query($sql);
    $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id);
    while ($row = $db->sql_fetchrow($result)) {
        $row['bbcode_options'] = ($row['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($row['enable_magic_url'] ? OPTION_FLAG_LINKS : 0);
        $post_unread = isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id] ? true : false;
        // @todo add edit option?
        $template->assign_block_vars('commentrow', array('COMMENT_ID' => $row['post_id'], 'U_MINI_POST' => append_sid("{$phpbb_root_path}bugs.{$phpEx}", "mode=report&amp;project={$report['project_name']}&amp;report_id={$report_id}#comment-{$row['post_id']}"), 'POST_SUBJECT' => $row['post_subject'], 'POSTED_INFO' => sprintf($user->lang['POSTED_INFO'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['post_username']), $row['rank_title'] == '' ? '' : '(' . $row['rank_title'] . ')', $user->format_date($row['post_time'])), 'COMMENT_ID' => $row['post_id'], 'POST_AUTHOR' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['post_username']), 'MINI_POST_IMG' => $post_unread ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'), 'MESSAGE' => generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'COMMENT_ID' => $row['post_id'], 'COMMENT_ID' => $row['post_id'], 'U_MCP_REPORT' => $auth->acl_get('m_report', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '', 'U_MCP_APPROVE' => $auth->acl_get('m_approve', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '', 'S_POST_REPORTED' => $row['post_reported'] == 1 && $auth->acl_get('m_report', $forum_id) ? true : false, 'S_POST_UNAPPROVED' => $row['post_approved'] == 0 ? true : false));
    }
    $db->sql_freeresult($result);
    // Mark comments read
    if (isset($topic_tracking_info[$topic_id]) && $report['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $report['topic_last_post_time'] > $topic_tracking_info[$topic_id]) {
        markread('topic', $forum_id, $topic_id, $report['topic_last_post_time']);
        // Update forum info
        update_forum_tracking_info($forum_id, $report['forum_last_post_time']);
    }
    // Finally display the page
    site_header($user->lang['BUG_TRACKER'] . ' - ' . $report['report_title'], 'bugs', array(array('bugs.' . $phpEx, 'BUG_TRACKER'), array("bugs.{$phpEx}?mode=project&amp;project={$report['project_name']}", $report['project_title']), array("bugs.{$phpEx}?mode=report&amp;project={$report['project_name']}&amp;report_id={$report_id}", sprintf($user->lang['BUG_NO'], $report_id))));
    $template->set_filenames(array('body' => 'bugs_report.html'));
    site_footer();
} elseif ($mode == 'add' || $mode == 'edit') {
    $project_name = request_var('project', '');
    $report_id = request_var('report_id', 0);
    // Load language file
    $user->add_lang('posting');
    // Include files
    include "{$phpbb_root_path}includes/functions_user.{$phpEx}";
    include "{$phpbb_root_path}includes/functions_posting.{$phpEx}";
/**
* Check for read forums and update topic tracking info accordingly
*
* @param int $forum_id the forum id to check
* @param int $forum_last_post_time the forums last post time
* @param int $f_mark_time the forums last mark time if user is registered and load_db_lastread enabled
* @param int $mark_time_forum false if the mark time needs to be obtained, else the last users forum mark time
*
* @return true if complete forum got marked read, else false.
*/
function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false)
{
    global $db, $tracking_topics, $user, $config, $auth, $request, $phpbb_container;
    // Determine the users last forum mark time if not given.
    if ($mark_time_forum === false) {
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $mark_time_forum = !empty($f_mark_time) ? $f_mark_time : $user->data['user_lastmark'];
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
                $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                if (!$user->data['is_registered']) {
                    $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
                }
                $mark_time_forum = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
        }
    }
    // Handle update of unapproved topics info.
    // Only update for moderators having m_approve permission for the forum.
    $phpbb_content_visibility = $phpbb_container->get('content.visibility');
    // Check the forum for any left unread topics.
    // If there are none, we mark the forum as read.
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        if ($mark_time_forum >= $forum_last_post_time) {
            // We do not need to mark read, this happened before. Therefore setting this to true
            $row = true;
        } else {
            $sql = 'SELECT t.forum_id
				FROM ' . TOPICS_TABLE . ' t
				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt
					ON (tt.topic_id = t.topic_id
						AND tt.user_id = ' . $user->data['user_id'] . ')
				WHERE t.forum_id = ' . $forum_id . '
					AND t.topic_last_post_time > ' . $mark_time_forum . '
					AND t.topic_moved_id = 0
					AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . '
					AND (tt.topic_id IS NULL
						OR tt.mark_time < t.topic_last_post_time)';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            // Get information from cookie
            $row = false;
            if (!isset($tracking_topics['tf'][$forum_id])) {
                // We do not need to mark read, this happened before. Therefore setting this to true
                $row = true;
            } else {
                $sql = 'SELECT t.topic_id
				FROM ' . TOPICS_TABLE . ' t
				WHERE t.forum_id = ' . $forum_id . '
					AND t.topic_last_post_time > ' . $mark_time_forum . '
					AND t.topic_moved_id = 0
					AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.');
                $result = $db->sql_query($sql);
                $check_forum = $tracking_topics['tf'][$forum_id];
                $unread = false;
                while ($row = $db->sql_fetchrow($result)) {
                    if (!isset($check_forum[base_convert($row['topic_id'], 10, 36)])) {
                        $unread = true;
                        break;
                    }
                }
                $db->sql_freeresult($result);
                $row = $unread;
            }
        } else {
            $row = true;
        }
    }
    if (!$row) {
        markread('topics', $forum_id);
        return true;
    }
    return false;
}
Ejemplo n.º 10
0
/**
* Fork Topic
*/
function mcp_fork_topic($topic_ids)
{
    global $auth, $user, $db, $template, $config;
    global $phpEx, $phpbb_root_path;
    if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_'))) {
        return;
    }
    $to_forum_id = request_var('to_forum_id', 0);
    $forum_id = request_var('f', 0);
    $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
    $additional_msg = $success_msg = '';
    $s_hidden_fields = build_hidden_fields(array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'fork', 'redirect' => $redirect));
    if ($to_forum_id) {
        $forum_data = get_forum_data($to_forum_id, 'f_post');
        if (!sizeof($topic_ids)) {
            $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
        } else {
            if (!sizeof($forum_data)) {
                $additional_msg = $user->lang['FORUM_NOT_EXIST'];
            } else {
                $forum_data = $forum_data[$to_forum_id];
                if ($forum_data['forum_type'] != FORUM_POST) {
                    $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
                } else {
                    if (!$auth->acl_get('f_post', $to_forum_id)) {
                        $additional_msg = $user->lang['USER_CANNOT_POST'];
                    }
                }
            }
        }
    } else {
        if (isset($_POST['confirm'])) {
            $additional_msg = $user->lang['FORUM_NOT_EXIST'];
        }
    }
    if ($additional_msg) {
        unset($_POST['confirm']);
        unset($_REQUEST['confirm_key']);
    }
    if (confirm_box(true)) {
        $topic_data = get_topic_data($topic_ids, 'f_post');
        $total_posts = 0;
        $new_topic_id_list = array();
        if ($topic_data['enable_indexing']) {
            // Select the search method and do some additional checks to ensure it can actually be utilised
            $search_type = basename($config['search_type']);
            if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) {
                trigger_error('NO_SUCH_SEARCH_MODULE');
            }
            if (!class_exists($search_type)) {
                include "{$phpbb_root_path}includes/search/{$search_type}.{$phpEx}";
            }
            $error = false;
            $search = new $search_type($error);
            $search_mode = 'post';
            if ($error) {
                trigger_error($error);
            }
        } else {
            $search_type = false;
        }
        foreach ($topic_data as $topic_id => $topic_row) {
            $sql_ary = array('forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], 'topic_approved' => 1, 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], 'topic_replies' => (int) $topic_row['topic_replies_real'], 'topic_replies_real' => (int) $topic_row['topic_replies_real'], 'topic_status' => (int) $topic_row['topic_status'], 'topic_type' => (int) $topic_row['topic_type'], 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'], 'topic_bumped' => (int) $topic_row['topic_bumped'], 'topic_bumper' => (int) $topic_row['topic_bumper'], 'poll_title' => (string) $topic_row['poll_title'], 'poll_start' => (int) $topic_row['poll_start'], 'poll_length' => (int) $topic_row['poll_length'], 'poll_max_options' => (int) $topic_row['poll_max_options'], 'poll_vote_change' => (int) $topic_row['poll_vote_change']);
            $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
            $new_topic_id = $db->sql_nextid();
            $new_topic_id_list[$topic_id] = $new_topic_id;
            if ($topic_row['poll_start']) {
                $poll_rows = array();
                $sql = 'SELECT *
					FROM ' . POLL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $sql_ary = array('poll_option_id' => (int) $row['poll_option_id'], 'topic_id' => (int) $new_topic_id, 'poll_option_text' => (string) $row['poll_option_text'], 'poll_option_total' => 0);
                    $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                }
            }
            $sql = 'SELECT *
				FROM ' . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tORDER BY post_time ASC";
            $result = $db->sql_query($sql);
            $post_rows = array();
            while ($row = $db->sql_fetchrow($result)) {
                $post_rows[] = $row;
            }
            $db->sql_freeresult($result);
            if (!sizeof($post_rows)) {
                continue;
            }
            $total_posts += sizeof($post_rows);
            foreach ($post_rows as $row) {
                $sql_ary = array('topic_id' => (int) $new_topic_id, 'forum_id' => (int) $to_forum_id, 'poster_id' => (int) $row['poster_id'], 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], 'post_approved' => 1, 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], 'enable_magic_url' => (int) $row['enable_magic_url'], 'enable_sig' => (int) $row['enable_sig'], 'post_username' => (string) $row['post_username'], 'post_subject' => (string) $row['post_subject'], 'post_text' => (string) $row['post_text'], 'post_edit_reason' => (string) $row['post_edit_reason'], 'post_edit_user' => (int) $row['post_edit_user'], 'post_checksum' => (string) $row['post_checksum'], 'post_attachment' => (int) $row['post_attachment'], 'bbcode_bitfield' => $row['bbcode_bitfield'], 'bbcode_uid' => (string) $row['bbcode_uid'], 'post_edit_time' => (int) $row['post_edit_time'], 'post_edit_count' => (int) $row['post_edit_count'], 'post_edit_locked' => (int) $row['post_edit_locked'], 'post_postcount' => 0);
                $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                $new_post_id = $db->sql_nextid();
                // Copy whether the topic is dotted
                markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
                if ($search_type) {
                    $search->index($search_mode, $sql_ary['post_id'], $sql_ary['post_text'], $sql_ary['post_subject'], $sql_ary['poster_id'], $topic_row['topic_type'] == POST_GLOBAL ? 0 : $to_forum_id);
                    $search_mode = 'reply';
                    // After one we index replies
                }
                // Copy Attachments
                if ($row['post_attachment']) {
                    $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\tWHERE post_msg_id = {$row['post_id']}\n\t\t\t\t\t\t\tAND topic_id = {$topic_id}\n\t\t\t\t\t\t\tAND in_message = 0";
                    $result = $db->sql_query($sql);
                    $sql_ary = array();
                    while ($attach_row = $db->sql_fetchrow($result)) {
                        $sql_ary[] = array('post_msg_id' => (int) $new_post_id, 'topic_id' => (int) $new_topic_id, 'in_message' => 0, 'is_orphan' => (int) $attach_row['is_orphan'], 'poster_id' => (int) $attach_row['poster_id'], 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']), 'real_filename' => (string) utf8_basename($attach_row['real_filename']), 'download_count' => (int) $attach_row['download_count'], 'attach_comment' => (string) $attach_row['attach_comment'], 'extension' => (string) $attach_row['extension'], 'mimetype' => (string) $attach_row['mimetype'], 'filesize' => (int) $attach_row['filesize'], 'filetime' => (int) $attach_row['filetime'], 'thumbnail' => (int) $attach_row['thumbnail']);
                    }
                    $db->sql_freeresult($result);
                    if (sizeof($sql_ary)) {
                        $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
                    }
                }
            }
            $sql = 'SELECT user_id, notify_status
				FROM ' . TOPICS_WATCH_TABLE . '
				WHERE topic_id = ' . $topic_id;
            $result = $db->sql_query($sql);
            $sql_ary = array();
            while ($row = $db->sql_fetchrow($result)) {
                $sql_ary[] = array('topic_id' => (int) $new_topic_id, 'user_id' => (int) $row['user_id'], 'notify_status' => (int) $row['notify_status']);
            }
            $db->sql_freeresult($result);
            if (sizeof($sql_ary)) {
                $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
            }
        }
        // Sync new topics, parent forums and board stats
        sync('topic', 'topic_id', $new_topic_id_list);
        $sync_sql = array();
        $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
        $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
        $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
        foreach ($sync_sql as $forum_id_key => $array) {
            $sql = 'UPDATE ' . FORUMS_TABLE . '
				SET ' . implode(', ', $array) . '
				WHERE forum_id = ' . $forum_id_key;
            $db->sql_query($sql);
        }
        sync('forum', 'forum_id', $to_forum_id);
        set_config_count('num_topics', sizeof($new_topic_id_list), true);
        set_config_count('num_posts', $total_posts, true);
        foreach ($new_topic_id_list as $topic_id => $new_topic_id) {
            add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
        }
        $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
    } else {
        $template->assign_vars(array('S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true), 'S_CAN_LEAVE_SHADOW' => false, 'ADDITIONAL_MSG' => $additional_msg));
        confirm_box(false, 'FORK_TOPIC' . (sizeof($topic_ids) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
        meta_refresh(3, $redirect_url);
        $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
        if ($forum_id != $to_forum_id) {
            $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $to_forum_id) . '">', '</a>');
        }
        trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
    }
}
Ejemplo n.º 11
0
/**
* Display Forums
*/
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
{
    global $db, $auth, $user, $template;
    global $phpbb_root_path, $phpEx, $config;
    global $request, $phpbb_dispatcher, $phpbb_container;
    $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
    $parent_id = $visible_forums = 0;
    $sql_from = '';
    // Mark forums read?
    $mark_read = $request->variable('mark', '');
    if ($mark_read == 'all') {
        $mark_read = '';
    }
    if (!$root_data) {
        if ($mark_read == 'forums') {
            $mark_read = 'all';
        }
        $root_data = array('forum_id' => 0);
        $sql_where = '';
    } else {
        $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
    }
    // Handle marking everything read
    if ($mark_read == 'all') {
        $redirect = build_url(array('mark', 'hash', 'mark_time'));
        meta_refresh(3, $redirect);
        if (check_link_hash($request->variable('hash', ''), 'global')) {
            markread('all', false, false, $request->variable('mark_time', 0));
            if ($request->is_ajax()) {
                // Tell the ajax script what language vars and URL need to be replaced
                $data = array('NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], 'U_MARK_FORUMS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}index.{$phpEx}", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time()) : '', 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']);
                $json_response = new \phpbb\json_response();
                $json_response->send($data);
            }
            trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>'));
        } else {
            trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
        }
    }
    // Display list of active topics for this category?
    $show_active = isset($root_data['forum_flags']) && $root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS ? true : false;
    $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_TABLE => 'f'), 'LEFT_JOIN' => array());
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
        $sql_array['SELECT'] .= ', ft.mark_time';
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            $tracking_topics = $request->variable($config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE);
            $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
            if (!$user->data['is_registered']) {
                $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
            }
        }
    }
    if ($show_active) {
        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_ACCESS_TABLE => 'fa'), 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'");
        $sql_array['SELECT'] .= ', fa.user_id';
    }
    $sql_ary = array('SELECT' => $sql_array['SELECT'], 'FROM' => $sql_array['FROM'], 'LEFT_JOIN' => $sql_array['LEFT_JOIN'], 'WHERE' => $sql_where, 'ORDER_BY' => 'f.left_id');
    /**
     * Event to modify the SQL query before the forum data is queried
     *
     * @event core.display_forums_modify_sql
     * @var	array	sql_ary		The SQL array to get the data of the forums
     * @since 3.1.0-a1
     */
    $vars = array('sql_ary');
    extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
    $sql = $db->sql_build_query('SELECT', $sql_ary);
    $result = $db->sql_query($sql);
    $forum_tracking_info = $valid_categories = array();
    $branch_root_id = $root_data['forum_id'];
    /* @var $phpbb_content_visibility \phpbb\content_visibility */
    $phpbb_content_visibility = $phpbb_container->get('content.visibility');
    while ($row = $db->sql_fetchrow($result)) {
        /**
         * Event to modify the data set of a forum
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_modify_row
         * @var	int		branch_root_id	Last top-level forum
         * @var	array	row				The data of the forum
         * @since 3.1.0-a1
         */
        $vars = array('branch_root_id', 'row');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars)));
        $forum_id = $row['forum_id'];
        // Mark forums read?
        if ($mark_read == 'forums') {
            if ($auth->acl_get('f_list', $forum_id)) {
                $forum_ids[] = $forum_id;
            }
            continue;
        }
        // Category with no members
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            continue;
        }
        // Skip branch
        if (isset($right_id)) {
            if ($row['left_id'] < $right_id) {
                continue;
            }
            unset($right_id);
        }
        if (!$auth->acl_get('f_list', $forum_id)) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $forum_tracking_info[$forum_id] = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                if (!$user->data['is_registered']) {
                    $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
                }
                $forum_tracking_info[$forum_id] = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
        }
        // Lets check whether there are unapproved topics/posts, so we can display an information to moderators
        $row['forum_id_unapproved_topics'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_topics_unapproved'] ? $forum_id : 0;
        $row['forum_id_unapproved_posts'] = $auth->acl_get('m_approve', $forum_id) && $row['forum_posts_unapproved'] ? $forum_id : 0;
        $row['forum_posts'] = $phpbb_content_visibility->get_count('forum_posts', $row, $forum_id);
        $row['forum_topics'] = $phpbb_content_visibility->get_count('forum_topics', $row, $forum_id);
        // Display active topics from this forum?
        if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && $row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) {
            if (!isset($active_forum_ary['forum_topics'])) {
                $active_forum_ary['forum_topics'] = 0;
            }
            if (!isset($active_forum_ary['forum_posts'])) {
                $active_forum_ary['forum_posts'] = 0;
            }
            $active_forum_ary['forum_id'][] = $forum_id;
            $active_forum_ary['enable_icons'][] = $row['enable_icons'];
            $active_forum_ary['forum_topics'] += $row['forum_topics'];
            $active_forum_ary['forum_posts'] += $row['forum_posts'];
            // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
            if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) {
                $active_forum_ary['exclude_forum_id'][] = $forum_id;
            }
        }
        // Fill list of categories with forums
        if (isset($forum_rows[$row['parent_id']])) {
            $valid_categories[$row['parent_id']] = true;
        }
        //
        if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) {
            if ($row['forum_type'] != FORUM_CAT) {
                $forum_ids_moderator[] = (int) $forum_id;
            }
            // Direct child of current branch
            $parent_id = $forum_id;
            $forum_rows[$forum_id] = $row;
            if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) {
                $branch_root_id = $forum_id;
            }
            $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
            $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
            $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
        } else {
            if ($row['forum_type'] != FORUM_CAT) {
                $subforums[$parent_id][$forum_id]['display'] = $row['display_on_index'] ? true : false;
                $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
                $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
                $subforums[$parent_id][$forum_id]['children'] = array();
                if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index']) {
                    $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
                }
                if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics']) {
                    $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
                }
                if (!$forum_rows[$parent_id]['forum_id_unapproved_posts'] && $row['forum_id_unapproved_posts']) {
                    $forum_rows[$parent_id]['forum_id_unapproved_posts'] = $forum_id;
                }
                $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
                // Do not list redirects in LINK Forums as Posts.
                if ($row['forum_type'] != FORUM_LINK) {
                    $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
                }
                if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) {
                    $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
                    $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
                    $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
                    $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
                    $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
                    $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
                    $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
                    $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password'];
                }
            }
        }
        /**
         * Event to modify the forum rows data set
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_modify_forum_rows
         * @var	array	forum_rows		Data array of all forums we display
         * @var	array	subforums		Data array of all subforums we display
         * @var	int		branch_root_id	Current top-level forum
         * @var	int		parent_id		Current parent forum
         * @var	array	row				The data of the forum
         * @since 3.1.0-a1
         */
        $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));
    }
    $db->sql_freeresult($result);
    // Handle marking posts
    if ($mark_read == 'forums') {
        $redirect = build_url(array('mark', 'hash', 'mark_time'));
        $token = $request->variable('hash', '');
        if (check_link_hash($token, 'global')) {
            markread('topics', $forum_ids, false, $request->variable('mark_time', 0));
            $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
            meta_refresh(3, $redirect);
            if ($request->is_ajax()) {
                // Tell the ajax script what language vars and URL need to be replaced
                $data = array('NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], 'U_MARK_FORUMS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time()) : '', 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']);
                $json_response = new \phpbb\json_response();
                $json_response->send($data);
            }
            trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
        } else {
            $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
            meta_refresh(3, $redirect);
            trigger_error($message);
        }
    }
    // Grab moderators ... if necessary
    if ($display_moderators) {
        if ($return_moderators) {
            $forum_ids_moderator[] = $root_data['forum_id'];
        }
        get_moderators($forum_moderators, $forum_ids_moderator);
    }
    /**
     * Event to perform additional actions before the forum list is being generated
     *
     * @event core.display_forums_before
     * @var	array	active_forum_ary	Array with forum data to display active topics
     * @var	bool	display_moderators	Flag indicating if we display forum moderators
     * @var	array	forum_moderators	Array with forum moderators list
     * @var	array	forum_rows			Data array of all forums we display
     * @var	bool	return_moderators	Flag indicating if moderators list should be returned
     * @var	array	root_data			Array with the root forum data
     * @since 3.1.4-RC1
     */
    $vars = array('active_forum_ary', 'display_moderators', 'forum_moderators', 'forum_rows', 'return_moderators', 'root_data');
    extract($phpbb_dispatcher->trigger_event('core.display_forums_before', compact($vars)));
    // Used to tell whatever we have to create a dummy category or not.
    $last_catless = true;
    foreach ($forum_rows as $row) {
        // Category
        if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT) {
            // Do not display categories without any forums to display
            if (!isset($valid_categories[$row['forum_id']])) {
                continue;
            }
            $cat_row = array('S_IS_CAT' => true, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'FORUM_FOLDER_IMG' => '', 'FORUM_FOLDER_IMG_SRC' => '', 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']));
            /**
             * Modify the template data block of the 'category'
             *
             * This event is triggered once per 'category'
             *
             * @event core.display_forums_modify_category_template_vars
             * @var	array	cat_row			Template data of the 'category'
             * @var	bool	catless			The flag indicating whether the 'category' has a parent category
             * @var	bool	last_catless	The flag indicating whether the last forum had a parent category
             * @var	array	root_data		Array with the root forum data
             * @var	array	row				The data of the 'category'
             * @since 3.1.0-RC4
             */
            $vars = array('cat_row', 'catless', 'last_catless', 'root_data', 'row');
            extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_category_template_vars', compact($vars)));
            $template->assign_block_vars('forumrow', $cat_row);
            continue;
        }
        $visible_forums++;
        $forum_id = $row['forum_id'];
        $forum_unread = isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id] ? true : false;
        $folder_image = $folder_alt = $l_subforums = '';
        $subforums_list = array();
        // Generate list of subforums if we need to
        if (isset($subforums[$forum_id])) {
            foreach ($subforums[$forum_id] as $subforum_id => $subforum_row) {
                $subforum_unread = isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id] ? true : false;
                if (!$subforum_unread && !empty($subforum_row['children'])) {
                    foreach ($subforum_row['children'] as $child_id) {
                        if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id]) {
                            // Once we found an unread child forum, we can drop out of this loop
                            $subforum_unread = true;
                            break;
                        }
                    }
                }
                if ($subforum_row['display'] && $subforum_row['name']) {
                    $subforums_list[] = array('link' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $subforum_id), 'name' => $subforum_row['name'], 'unread' => $subforum_unread);
                } else {
                    unset($subforums[$forum_id][$subforum_id]);
                }
                // If one subforum is unread the forum gets unread too...
                if ($subforum_unread) {
                    $forum_unread = true;
                }
            }
            $l_subforums = sizeof($subforums[$forum_id]) == 1 ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'];
            $folder_image = $forum_unread ? 'forum_unread_subforum' : 'forum_read_subforum';
        } else {
            switch ($row['forum_type']) {
                case FORUM_POST:
                    $folder_image = $forum_unread ? 'forum_unread' : 'forum_read';
                    break;
                case FORUM_LINK:
                    $folder_image = 'forum_link';
                    break;
            }
        }
        // Which folder should we display?
        if ($row['forum_status'] == ITEM_LOCKED) {
            $folder_image = $forum_unread ? 'forum_unread_locked' : 'forum_read_locked';
            $folder_alt = 'FORUM_LOCKED';
        } else {
            $folder_alt = $forum_unread ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
        }
        // Create last post link information, if appropriate
        if ($row['forum_last_post_id']) {
            if ($row['forum_password_last_post'] === '' && $auth->acl_get('f_read', $row['forum_id_last_post'])) {
                $last_post_subject = censor_text($row['forum_last_post_subject']);
                $last_post_subject_truncated = truncate_string($last_post_subject, 30, 255, false, $user->lang['ELLIPSIS']);
            } else {
                $last_post_subject = $last_post_subject_truncated = '';
            }
            $last_post_time = $user->format_date($row['forum_last_post_time']);
            $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
        } else {
            $last_post_subject = $last_post_time = $last_post_url = $last_post_subject_truncated = '';
        }
        // Output moderator listing ... if applicable
        $l_moderator = $moderators_list = '';
        if ($display_moderators && !empty($forum_moderators[$forum_id])) {
            $l_moderator = sizeof($forum_moderators[$forum_id]) == 1 ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
            $moderators_list = implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]);
        }
        $l_post_click_count = $row['forum_type'] == FORUM_LINK ? 'CLICKS' : 'POSTS';
        $post_click_count = $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK ? $row['forum_posts'] : '';
        $s_subforums_list = $subforums_row = array();
        foreach ($subforums_list as $subforum) {
            $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . ($subforum['unread'] ? 'unread' : 'read') . '" title="' . ($subforum['unread'] ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>';
            $subforums_row[] = array('U_SUBFORUM' => $subforum['link'], 'SUBFORUM_NAME' => $subforum['name'], 'S_UNREAD' => $subforum['unread']);
        }
        $s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $s_subforums_list);
        $catless = $row['parent_id'] == $root_data['forum_id'] ? true : false;
        if ($row['forum_type'] != FORUM_LINK) {
            $u_viewforum = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']);
        } else {
            // If the forum is a link and we count redirects we need to visit it
            // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
            if ($row['forum_flags'] & FORUM_FLAG_LINK_TRACK || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id)) {
                $u_viewforum = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']);
            } else {
                $u_viewforum = $row['forum_link'];
            }
        }
        $forum_row = array('S_IS_CAT' => false, 'S_NO_CAT' => $catless && !$last_catless, 'S_IS_LINK' => $row['forum_type'] == FORUM_LINK ? true : false, 'S_UNREAD_FORUM' => $forum_unread, 'S_AUTH_READ' => $auth->acl_get('f_read', $row['forum_id']), 'S_LOCKED_FORUM' => $row['forum_status'] == ITEM_LOCKED ? true : false, 'S_LIST_SUBFORUMS' => $row['display_subforum_list'] ? true : false, 'S_SUBFORUMS' => sizeof($subforums_list) ? true : false, 'S_DISPLAY_SUBJECT' => $last_post_subject !== '' && $config['display_last_subject'] ? true : false, 'S_FEED_ENABLED' => $config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST ? true : false, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'TOPICS' => $row['forum_topics'], $l_post_click_count => $post_click_count, 'FORUM_IMG_STYLE' => $folder_image, 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '', 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'LAST_POST_SUBJECT' => $last_post_subject, 'LAST_POST_SUBJECT_TRUNCATED' => $last_post_subject_truncated, 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_FULL' => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'MODERATORS' => $moderators_list, 'SUBFORUMS' => $s_subforums_list, 'L_SUBFORUM_STR' => $l_subforums, 'L_MODERATOR_STR' => $l_moderator, 'U_UNAPPROVED_TOPICS' => $row['forum_id_unapproved_topics'] ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '', 'U_UNAPPROVED_POSTS' => $row['forum_id_unapproved_posts'] ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=unapproved_posts&amp;f=' . $row['forum_id_unapproved_posts']) : '', 'U_VIEWFORUM' => $u_viewforum, 'U_LAST_POSTER' => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'U_LAST_POST' => $last_post_url);
        /**
         * Modify the template data block of the forum
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_modify_template_vars
         * @var	array	forum_row		Template data of the forum
         * @var	array	row				The data of the forum
         * @var	array	subforums_row	Template data of subforums
         * @since 3.1.0-a1
         * @change 3.1.0-b5 Added var subforums_row
         */
        $vars = array('forum_row', 'row', 'subforums_row');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars)));
        $template->assign_block_vars('forumrow', $forum_row);
        // Assign subforums loop for style authors
        $template->assign_block_vars_array('forumrow.subforum', $subforums_row);
        /**
         * Modify and/or assign additional template data for the forum
         * after forumrow loop has been assigned. This can be used
         * to create additional forumrow subloops in extensions.
         *
         * This event is triggered once per forum
         *
         * @event core.display_forums_add_template_data
         * @var	array	forum_row		Template data of the forum
         * @var	array	row				The data of the forum
         * @var	array	subforums_list	The data of subforums
         * @var	array	subforums_row	Template data of subforums
         * @var	bool	catless			The flag indicating whether a forum has a parent category
         * @since 3.1.0-b5
         */
        $vars = array('forum_row', 'row', 'subforums_list', 'subforums_row', 'catless');
        extract($phpbb_dispatcher->trigger_event('core.display_forums_add_template_data', compact($vars)));
        $last_catless = $catless;
    }
    $template->assign_vars(array('U_MARK_FORUMS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums&amp;mark_time=' . time()) : '', 'S_HAS_SUBFORUM' => $visible_forums ? true : false, 'L_SUBFORUM' => $visible_forums == 1 ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'), 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM')));
    /**
     * Event to perform additional actions after the forum list has been generated
     *
     * @event core.display_forums_after
     * @var	array	active_forum_ary	Array with forum data to display active topics
     * @var	bool	display_moderators	Flag indicating if we display forum moderators
     * @var	array	forum_moderators	Array with forum moderators list
     * @var	array	forum_rows			Data array of all forums we display
     * @var	bool	return_moderators	Flag indicating if moderators list should be returned
     * @var	array	root_data			Array with the root forum data
     * @since 3.1.0-RC5
     */
    $vars = array('active_forum_ary', 'display_moderators', 'forum_moderators', 'forum_rows', 'return_moderators', 'root_data');
    extract($phpbb_dispatcher->trigger_event('core.display_forums_after', compact($vars)));
    if ($return_moderators) {
        return array($active_forum_ary, $forum_moderators);
    }
    return array($active_forum_ary, array());
}
Ejemplo n.º 12
0
$template->assign_vars(array('U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}" . ($start == 0 ? '' : "&amp;start={$start}"))));
// Not postable forum or showing active topics?
if (!($forum_data['forum_type'] == FORUM_POST || $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS && $forum_data['forum_type'] == FORUM_CAT)) {
    page_footer();
}
// Ok, if someone has only list-access, we only display the forum list.
// We also make this circumstance available to the template in case we want to display a notice. ;)
if (!$auth->acl_get('f_read', $forum_id)) {
    $template->assign_vars(array('S_NO_READ_ACCESS' => true));
    page_footer();
}
// Handle marking posts
if ($mark_read == 'topics') {
    $token = request_var('hash', '');
    if (check_link_hash($token, 'global')) {
        markread('topics', array($forum_id), false, request_var('mark_time', 0));
    }
    $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
    meta_refresh(3, $redirect_url);
    if ($request->is_ajax()) {
        // Tell the ajax script what language vars and URL need to be replaced
        $data = array('NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'], 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'], 'U_MARK_TOPICS' => $user->data['is_registered'] || $config['load_anon_lastread'] ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'hash=' . generate_link_hash('global') . "&f={$forum_id}&mark=topics&mark_time=" . time()) : '', 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['TOPICS_MARKED']);
        $json_response = new \phpbb\json_response();
        $json_response->send($data);
    }
    trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
}
// Is a forum specific topic count required?
if ($forum_data['forum_topics_per_page']) {
    $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
}
Ejemplo n.º 13
0
        // topics
        $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
        // Replies
        $replies = $_CLASS['auth']->acl_get('m_approve', $forum_id) ? (int) $row['topic_replies_real'] : (int) $row['topic_replies'];
        if ($row['topic_status'] == ITEM_MOVED) {
            // currently no marking supported
            $topic_id = $row['topic_moved_id'];
        }
        // Get folder img, topic status/type related informations
        $folder_img = $folder_alt = $topic_type = '';
        //	$status = topic_status($row, $replies, $mark_time, $unread_topic, $folder_img, $folder_alt, $topic_type);
        topic_status($row, $replies, $mark_time, $unread_topic, $folder_img, $folder_alt, $topic_type);
        $newest_post_img = $unread_topic ? '<a href="' . generate_link("Forums&amp;file=viewtopic&amp;t={$topic_id}&amp;view=unread#unread") . '">' . $_CLASS['core_user']->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : '';
        // Generate all the URIs ...
        $view_topic_url = 'Forums&amp;file=viewtopic&amp;t=' . $topic_id;
        $pagination = generate_pagination('Forums&amp;file=viewtopic&amp;&amp;t=' . $topic_id, $replies, $config['posts_per_page']);
        // Send vars to template
        $_CLASS['core_template']->assign_vars_array('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'AUTHOR' => $row['topic_poster'] == ANONYMOUS ? $row['topic_first_poster_name'] ? $row['topic_first_poster_name'] : $_CLASS['core_user']->get_lang('GUEST') : $row['topic_first_poster_name'], 'LINK_AUTHOR' => $row['topic_poster'] == ANONYMOUS ? '' : generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $row['topic_poster']), 'FIRST_POST_TIME' => $_CLASS['core_user']->format_date($row['topic_time']), 'LAST_POST_TIME' => $_CLASS['core_user']->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $_CLASS['core_user']->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => $row['topic_last_poster_name'] != '' ? $row['topic_last_poster_name'] : $_CLASS['core_user']->lang['GUEST'], 'PAGINATION' => $pagination['formated'], 'PAGINATION_ARRAY' => $pagination['array'], 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? 1 : 0, 'LAST_POST_IMG' => $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $newest_post_img, 'TOPIC_FOLDER_IMG' => $_CLASS['core_user']->img($folder_img, $folder_alt), 'TOPIC_ICON_IMG' => empty($icons[$row['icon_id']]) ? '' : $icons[$row['icon_id']]['img'], 'TOPIC_ICON_IMG_WIDTH' => empty($icons[$row['icon_id']]) ? '' : $icons[$row['icon_id']]['width'], 'TOPIC_ICON_IMG_HEIGHT' => empty($icons[$row['icon_id']]) ? '' : $icons[$row['icon_id']]['height'], 'ATTACH_ICON_IMG' => $row['topic_attachment'] && $_CLASS['auth']->acl_gets(array('f_download', 'u_download'), $forum_id) ? $_CLASS['core_user']->img('icon_attach', $_CLASS['core_user']->lang['TOTAL_ATTACHMENTS']) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $_CLASS['auth']->acl_get('m_report', $forum_id), 'S_TOPIC_UNAPPROVED' => !$row['topic_approved'] && $_CLASS['auth']->acl_get('m_approve', $forum_id), 'U_LAST_POST' => generate_link($view_topic_url . '&amp;p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id']), 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] ? generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $row['topic_last_poster_id']) : '', 'U_VIEW_TOPIC' => generate_link($view_topic_url), 'U_MCP_REPORT' => generate_link('Forums&amp;file=mcp&amp;mode=reports&amp;t=' . $topic_id), 'U_MCP_QUEUE' => generate_link('Forums&amp;file=mcp&amp;i=queue&amp;mode=approve_details&amp;t=' . $topic_id), 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test));
        $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0;
        unset($row, $rowset[$topic_id]);
    }
    unset($topic_list);
}
// Update the marktime only if $mark_forum_read is set to a time
if ($forum_data['forum_type'] == FORUM_POST && is_int($mark_forum_read)) {
    markread('forum', $forum_id, false, $mark_forum_read);
}
page_header();
make_jumpbox(generate_link('Forums&amp;file=viewforum'), $forum_id);
$_CLASS['core_display']->footer .= $_CLASS['core_template']->display('modules/Forums/menus.html', true);
$_CLASS['core_display']->display(false, 'modules/Forums/viewforum_body.html');
Ejemplo n.º 14
0
/**
* Fork Topic
*/
function mcp_fork_topic($topic_ids)
{
    global $auth, $user, $db, $template, $config;
    global $phpEx, $phpbb_root_path;
    if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_'))) {
        return;
    }
    $to_forum_id = request_var('to_forum_id', 0);
    $redirect = request_var('redirect', $user->data['session_page']);
    $additional_msg = $success_msg = '';
    $s_hidden_fields = build_hidden_fields(array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'fork', 'redirect' => $redirect));
    if ($to_forum_id) {
        $forum_data = get_forum_data($to_forum_id);
        if (!sizeof($topic_ids)) {
            $additional_msg = $user->lang['NO_TOPICS_SELECTED'];
        } else {
            if (!sizeof($forum_data)) {
                $additional_msg = $user->lang['FORUM_NOT_EXIST'];
            } else {
                $forum_data = $forum_data[$to_forum_id];
                if ($forum_data['forum_type'] != FORUM_POST) {
                    $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
                } else {
                    if (!$auth->acl_get('f_post', $to_forum_id)) {
                        $additional_msg = $user->lang['USER_CANNOT_POST'];
                    }
                }
            }
        }
    }
    if (!$to_forum_id || $additional_msg) {
        unset($_POST['confirm']);
    }
    if (confirm_box(true)) {
        $topic_data = get_topic_data($topic_ids);
        $total_posts = 0;
        $new_topic_id_list = array();
        foreach ($topic_data as $topic_id => $topic_row) {
            $sql_ary = array('forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], 'topic_approved' => 1, 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], 'topic_replies' => (int) $topic_row['topic_replies_real'], 'topic_replies_real' => (int) $topic_row['topic_replies_real'], 'topic_status' => (int) $topic_row['topic_status'], 'topic_type' => (int) $topic_row['topic_type'], 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'], 'topic_bumped' => (int) $topic_row['topic_bumped'], 'topic_bumper' => (int) $topic_row['topic_bumper'], 'poll_title' => (string) $topic_row['poll_title'], 'poll_start' => (int) $topic_row['poll_start'], 'poll_length' => (int) $topic_row['poll_length']);
            $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
            $new_topic_id = $db->sql_nextid();
            $new_topic_id_list[$topic_id] = $new_topic_id;
            /**
             * @todo enable? (is this still needed?)
             * markread('topic', $to_forum_id, $new_topic_id);
             */
            if ($topic_row['poll_start']) {
                $poll_rows = array();
                $sql = 'SELECT *
					FROM ' . POLL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $sql_ary = array('poll_option_id' => (int) $row['poll_option_id'], 'topic_id' => (int) $new_topic_id, 'poll_option_text' => (string) $row['poll_option_text'], 'poll_option_total' => 0);
                    $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                }
            }
            $sql = 'SELECT *
				FROM ' . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tORDER BY post_id ASC";
            $result = $db->sql_query($sql);
            $post_rows = array();
            while ($row = $db->sql_fetchrow($result)) {
                $post_rows[] = $row;
            }
            $db->sql_freeresult($result);
            if (!sizeof($post_rows)) {
                continue;
            }
            $total_posts += sizeof($post_rows);
            foreach ($post_rows as $row) {
                $sql_ary = array('topic_id' => (int) $new_topic_id, 'forum_id' => (int) $to_forum_id, 'poster_id' => (int) $row['poster_id'], 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], 'post_approved' => 1, 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], 'enable_magic_url' => (int) $row['enable_magic_url'], 'enable_sig' => (int) $row['enable_sig'], 'post_username' => (string) $row['post_username'], 'post_subject' => (string) $row['post_subject'], 'post_text' => (string) $row['post_text'], 'post_edit_reason' => (string) $row['post_edit_reason'], 'post_edit_user' => (int) $row['post_edit_user'], 'post_checksum' => (string) $row['post_checksum'], 'post_encoding' => (string) $row['post_encoding'], 'post_attachment' => (int) $row['post_attachment'], 'bbcode_bitfield' => (int) $row['bbcode_bitfield'], 'bbcode_uid' => (string) $row['bbcode_uid'], 'post_edit_time' => (int) $row['post_edit_time'], 'post_edit_count' => (int) $row['post_edit_count'], 'post_edit_locked' => (int) $row['post_edit_locked']);
                $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                $new_post_id = $db->sql_nextid();
                // Copy whether the topic is dotted
                markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
                // Copy Attachments
                if ($row['post_attachment']) {
                    $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\tWHERE post_msg_id = {$row['post_id']}\n\t\t\t\t\t\t\tAND topic_id = {$topic_id}\n\t\t\t\t\t\t\tAND in_message = 0";
                    $result = $db->sql_query($sql);
                    while ($attach_row = $db->sql_fetchrow($result)) {
                        $sql_ary = array('post_msg_id' => (int) $new_post_id, 'topic_id' => (int) $new_topic_id, 'in_message' => 0, 'poster_id' => (int) $attach_row['poster_id'], 'physical_filename' => (string) basename($attach_row['physical_filename']), 'real_filename' => (string) basename($attach_row['real_filename']), 'download_count' => (int) $attach_row['download_count'], 'comment' => (string) $attach_row['comment'], 'extension' => (string) $attach_row['extension'], 'mimetype' => (string) $attach_row['mimetype'], 'filesize' => (int) $attach_row['filesize'], 'filetime' => (int) $attach_row['filetime'], 'thumbnail' => (int) $attach_row['thumbnail']);
                        $db->sql_query('INSERT INTO ' . ATTACHMENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                    }
                    $db->sql_freeresult($result);
                }
            }
        }
        // Sync new topics, parent forums and board stats
        sync('topic', 'topic_id', $new_topic_id_list, true);
        sync('forum', 'forum_id', $to_forum_id, true);
        set_config('num_topics', $config['num_topics'] + sizeof($new_topic_id_list));
        set_config('num_posts', $config['num_posts'] + $total_posts);
        foreach ($new_topic_id_list as $topic_id => $new_topic_id) {
            add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
        }
        $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
    } else {
        $template->assign_vars(array('S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true), 'S_CAN_LEAVE_SHADOW' => false, 'ADDITIONAL_MSG' => $additional_msg));
        confirm_box(false, 'FORK_TOPIC' . (sizeof($topic_ids) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
        meta_refresh(3, $redirect_url);
        $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
        if ($forum_id != $to_forum_id) {
            $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $to_forum_id) . '">', '</a>');
        }
        trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
    }
}
Ejemplo n.º 15
0
/**
* Change a post's poster
*/
function change_poster(&$post_info, $userdata)
{
    global $auth, $db, $config;
    if (empty($userdata) || $userdata['user_id'] == $post_info['user_id']) {
        return;
    }
    $post_id = $post_info['post_id'];
    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\tSET poster_id = {$userdata['user_id']}\n\t\tWHERE post_id = {$post_id}";
    $db->sql_query($sql);
    // Resync topic/forum if needed
    if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id) {
        sync('topic', 'topic_id', $post_info['topic_id'], false, false);
        sync('forum', 'forum_id', $post_info['forum_id'], false, false);
    }
    // Adjust post counts
    $auth_user_from = new auth();
    $auth_user_from->acl($post_info);
    $auth_user_to = new auth();
    $auth_user_to->acl($userdata);
    // Decrease post count by one for the old user
    if ($auth_user_from->acl_get('f_postcount', $post_info['forum_id'])) {
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_posts = user_posts - 1
			WHERE user_id = ' . $post_info['user_id'];
        $db->sql_query($sql);
    }
    // Increase post count by one for the new user
    if ($auth_user_to->acl_get('f_postcount', $post_info['forum_id'])) {
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_posts = user_posts + 1
			WHERE user_id = ' . $userdata['user_id'];
        $db->sql_query($sql);
    }
    // Add posted to information for this topic for the new user
    markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
    // Remove the dotted topic option if the old user has no more posts within this topic
    if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS) {
        $sql = 'SELECT topic_id
			FROM ' . POSTS_TABLE . '
			WHERE topic_id = ' . $post_info['topic_id'] . '
				AND poster_id = ' . $post_info['user_id'];
        $result = $db->sql_query_limit($sql, 1);
        $topic_id = (int) $db->sql_fetchfield('topic_id');
        $db->sql_freeresult($result);
        if (!$topic_id) {
            $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
				WHERE user_id = ' . $post_info['user_id'] . '
					AND topic_id = ' . $post_info['topic_id'];
            $db->sql_query($sql);
        }
    }
    // Do not change the poster_id within the attachments table, since they were still posted by the original user
    $from_username = $post_info['username'];
    $to_username = $userdata['username'];
    // Renew post info
    $post_info = get_post_data(array($post_id));
    if (!sizeof($post_info)) {
        trigger_error($user->lang['POST_NOT_EXIST']);
    }
    $post_info = $post_info[$post_id];
    // Now add log entry
    add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
}
Ejemplo n.º 16
0
/**
* Display Forums
*/
function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
{
    global $db, $auth, $user, $template;
    global $phpbb_root_path, $phpEx, $config;
    $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
    $parent_id = $visible_forums = 0;
    $sql_from = $lastread_select = '';
    // Mark forums read?
    $mark_read = request_var('mark', '');
    if ($mark_read == 'all') {
        $mark_read = '';
    }
    if (!$root_data) {
        if ($mark_read == 'forums') {
            $mark_read = 'all';
        }
        $root_data = array('forum_id' => 0);
        $sql_where = '';
    } else {
        $sql_where = ' WHERE left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
    }
    // Display list of active topics for this category?
    $show_active = isset($root_data['forum_flags']) && $root_data['forum_flags'] & 16 ? true : false;
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        $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)';
        $lastread_select = ', ft.mark_time ';
    } else {
        $sql_from = FORUMS_TABLE . ' f ';
        $lastread_select = $sql_lastread = '';
        $tracking_topics = isset($_COOKIE[$config['cookie_name'] . '_track']) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track'] : '';
        $tracking_topics = $tracking_topics ? unserialize($tracking_topics) : array();
        if (!$user->data['is_registered']) {
            $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
        }
    }
    $sql = "SELECT f.* {$lastread_select}\n\t\tFROM {$sql_from}\n\t\t{$sql_where}\n\t\tORDER BY f.left_id";
    $result = $db->sql_query($sql);
    $forum_tracking_info = array();
    $branch_root_id = $root_data['forum_id'];
    while ($row = $db->sql_fetchrow($result)) {
        $forum_id = $row['forum_id'];
        // Mark forums read?
        if ($mark_read == 'forums' || $mark_read == 'all') {
            if ($auth->acl_get('f_list', $forum_id)) {
                $forum_ids[] = $forum_id;
                continue;
            }
        }
        // Category with no members
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            continue;
        }
        // Skip branch
        if (isset($right_id)) {
            if ($row['left_id'] < $right_id) {
                continue;
            }
            unset($right_id);
        }
        if (!$auth->acl_get('f_list', $forum_id)) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        $forum_ids[] = $forum_id;
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $forum_tracking_info[$forum_id] = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
        } else {
            if (!$user->data['is_registered']) {
                $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
            }
            $forum_tracking_info[$forum_id] = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
        }
        // Display active topics from this forum?
        if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && $row['forum_flags'] & 16) {
            if (!isset($active_forum_ary['forum_topics'])) {
                $active_forum_ary['forum_topics'] = 0;
            }
            if (!isset($active_forum_ary['forum_posts'])) {
                $active_forum_ary['forum_posts'] = 0;
            }
            $active_forum_ary['forum_id'][] = $forum_id;
            $active_forum_ary['enable_icons'][] = $row['enable_icons'];
            $active_forum_ary['forum_topics'] += $auth->acl_get('m_approve', $forum_id) ? $row['forum_topics_real'] : $row['forum_topics'];
            $active_forum_ary['forum_posts'] += $row['forum_posts'];
        }
        //
        if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) {
            if ($row['forum_type'] != FORUM_CAT) {
                $forum_ids_moderator[] = $forum_id;
            }
            // Direct child of current branch
            $parent_id = $forum_id;
            $forum_rows[$forum_id] = $row;
            if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) {
                $branch_root_id = $forum_id;
            }
            $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
            $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
        } else {
            if ($row['forum_type'] != FORUM_CAT) {
                $subforums[$parent_id][$forum_id]['display'] = $row['display_on_index'] ? true : false;
                $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
                $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
                $forum_rows[$parent_id]['forum_topics'] += $auth->acl_get('m_approve', $forum_id) ? $row['forum_topics_real'] : $row['forum_topics'];
                // Do not list redirects in LINK Forums as Posts.
                if ($row['forum_type'] != FORUM_LINK) {
                    $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
                }
                if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) {
                    $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
                    $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
                    $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
                    $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
                    $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
                } else {
                    $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
                }
            }
        }
    }
    $db->sql_freeresult($result);
    // Handle marking posts
    if ($mark_read == 'forums' || $mark_read == 'all') {
        $redirect = build_url('mark');
        if ($mark_read == 'all') {
            markread('all');
            $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
        } else {
            markread('topics', $forum_ids);
            $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
        }
        meta_refresh(3, $redirect);
        trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
    }
    // Grab moderators ... if necessary
    if ($display_moderators) {
        if ($return_moderators) {
            $forum_ids_moderator[] = $root_data['forum_id'];
        }
        get_moderators($forum_moderators, $forum_ids_moderator);
    }
    foreach ($forum_rows as $row) {
        // Empty category
        if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT) {
            $template->assign_block_vars('forumrow', array('S_IS_CAT' => true, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield']), 'FORUM_FOLDER_IMG' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '', 'FORUM_FOLDER_IMG_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id'])));
            continue;
        }
        $visible_forums++;
        $forum_id = $row['forum_id'];
        $forum_unread = isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id] ? true : false;
        $folder_image = $folder_alt = $subforums_list = $l_subforums = '';
        // Generate list of subforums if we need to
        if (isset($subforums[$forum_id])) {
            foreach ($subforums[$forum_id] as $subforum_id => $subforum_row) {
                // Update unread information if needed
                if (!$forum_unread) {
                    $forum_unread = isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id] ? true : false;
                }
                if ($subforum_row['display'] && $subforum_row['name']) {
                    $subforums_list .= $subforums_list == '' ? '' : ', ';
                    $subforums_list .= '<a href="' . append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $subforum_id) . '">' . $subforum_row['name'] . '</a>';
                } else {
                    unset($subforums[$forum_id][$subforum_id]);
                }
            }
            $l_subforums = sizeof($subforums[$forum_id]) == 1 ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
            $folder_image = $forum_unread ? 'sub_forum_new' : 'sub_forum';
        } else {
            switch ($row['forum_type']) {
                case FORUM_POST:
                    $folder_image = $forum_unread ? 'forum_new' : 'forum';
                    break;
                case FORUM_LINK:
                    $folder_image = 'forum_link';
                    break;
            }
        }
        // Which folder should we display?
        if ($row['forum_status'] == ITEM_LOCKED) {
            $folder_image = 'forum_locked';
            $folder_alt = 'FORUM_LOCKED';
        } else {
            $folder_alt = $forum_unread ? 'NEW_POSTS' : 'NO_NEW_POSTS';
        }
        // Create last post link information, if appropriate
        if ($row['forum_last_post_id']) {
            $last_post_time = $user->format_date($row['forum_last_post_time']);
            $last_poster = $row['forum_last_poster_name'] != '' ? $row['forum_last_poster_name'] : $user->lang['GUEST'];
            $last_poster_url = $row['forum_last_poster_id'] == ANONYMOUS ? '' : append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $row['forum_last_poster_id']);
            $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
        } else {
            $last_post_time = $last_poster = $last_poster_url = $last_post_url = '';
        }
        // Output moderator listing ... if applicable
        $l_moderator = $moderators_list = '';
        if ($display_moderators && !empty($forum_moderators[$forum_id])) {
            $l_moderator = sizeof($forum_moderators[$forum_id]) == 1 ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
            $moderators_list = implode(', ', $forum_moderators[$forum_id]);
        }
        $l_post_click_count = $row['forum_type'] == FORUM_LINK ? 'CLICKS' : 'POSTS';
        $post_click_count = $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1 ? $row['forum_posts'] : '';
        $template->assign_block_vars('forumrow', array('S_IS_CAT' => false, 'S_IS_LINK' => $row['forum_type'] == FORUM_LINK ? true : false, 'S_UNREAD_FORUM' => $forum_unread, 'S_LOCKED_FORUM' => $row['forum_status'] == ITEM_LOCKED ? true : false, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield']), 'TOPICS' => $row['forum_topics'], $l_post_click_count => $post_click_count, 'FORUM_FOLDER_IMG' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : $user->img($folder_image, $folder_alt, false, '', 'src'), 'SUBFORUMS' => $subforums_list, 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => $last_poster, 'MODERATORS' => $moderators_list, 'L_SUBFORUM_STR' => $l_subforums, 'L_FORUM_FOLDER_ALT' => $folder_alt, 'L_MODERATOR_STR' => $l_moderator, 'U_VIEWFORUM' => $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1 ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']) : $row['forum_link'], 'U_LAST_POSTER' => $last_poster_url, 'U_LAST_POST' => $last_post_url));
    }
    $template->assign_vars(array('U_MARK_FORUMS' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $root_data['forum_id'] . '&amp;mark=forums'), 'S_HAS_SUBFORUM' => $visible_forums ? true : false, 'L_SUBFORUM' => $visible_forums == 1 ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST')));
    if ($return_moderators) {
        return array($active_forum_ary, $forum_moderators);
    }
    return array($active_forum_ary, array());
}
Ejemplo n.º 17
0
	$topic_data['forum_last_post_time'] = (int) $db->sql_fetchfield('forum_last_post_time');
	$db->sql_freeresult($result);

	$sql = 'SELECT mark_time as forum_mark_time
		FROM ' . FORUMS_TRACK_TABLE . '
		WHERE forum_id = 0
			AND user_id = ' . $user->data['user_id'];
	$result = $db->sql_query($sql);
	$topic_data['forum_mark_time'] = (int) $db->sql_fetchfield('forum_mark_time');
	$db->sql_freeresult($result);
}

// Only mark topic if it's currently unread. Also make sure we do not set topic tracking back if earlier pages are viewed.
if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $max_post_time > $topic_tracking_info[$topic_id])
{
	markread('topic', (($topic_data['topic_type'] == POST_GLOBAL) ? 0 : $forum_id), $topic_id, $max_post_time);

	// Update forum info
	$all_marked_read = update_forum_tracking_info((($topic_data['topic_type'] == POST_GLOBAL) ? 0 : $forum_id), $topic_data['forum_last_post_time'], (isset($topic_data['forum_mark_time'])) ? $topic_data['forum_mark_time'] : false, false);
}
else
{
	$all_marked_read = true;
}

// If there are absolutely no more unread posts in this forum and unread posts shown, we can savely show the #unread link
if ($all_marked_read)
{
	if ($post_unread)
	{
		$template->assign_vars(array(
Ejemplo n.º 18
0
			SET topic_last_post_time = $current_time,
				topic_bumped = 1,
				topic_bumper = " . $user->data['user_id'] . "
			WHERE topic_id = $topic_id";
		$db->sql_query($sql);

		update_post_information('forum', $forum_id);

		$sql = 'UPDATE ' . USERS_TABLE . "
			SET user_lastpost_time = $current_time
			WHERE user_id = " . $user->data['user_id'];
		$db->sql_query($sql);

		$db->sql_transaction('commit');

		markread('post', $forum_id, $topic_id, $current_time);

		add_log('mod', $forum_id, $topic_id, 'LOG_BUMP_TOPIC', $post_data['topic_title']);

		$meta_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id&amp;p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}";
		meta_refresh(3, $meta_url);

		$message = $user->lang['TOPIC_BUMPED'] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $meta_url . '">', '</a>');
		$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');

		trigger_error($message);
	}

	trigger_error('BUMP_ERROR');
}
/**
* Change a post's poster
*/
function change_poster(&$post_info, $userdata)
{
    global $auth, $db, $config, $phpbb_root_path, $phpEx, $user, $phpbb_dispatcher;
    if (empty($userdata) || $userdata['user_id'] == $post_info['user_id']) {
        return;
    }
    $post_id = $post_info['post_id'];
    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\tSET poster_id = {$userdata['user_id']}\n\t\tWHERE post_id = {$post_id}";
    $db->sql_query($sql);
    // Resync topic/forum if needed
    if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id || $post_info['topic_first_post_id'] == $post_id) {
        sync('topic', 'topic_id', $post_info['topic_id'], false, false);
        sync('forum', 'forum_id', $post_info['forum_id'], false, false);
    }
    // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
    if ($post_info['post_postcount'] && $post_info['post_visibility'] == ITEM_APPROVED) {
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_posts = user_posts - 1
			WHERE user_id = ' . $post_info['user_id'] . '
			AND user_posts > 0';
        $db->sql_query($sql);
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_posts = user_posts + 1
			WHERE user_id = ' . $userdata['user_id'];
        $db->sql_query($sql);
    }
    // Add posted to information for this topic for the new user
    markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
    // Remove the dotted topic option if the old user has no more posts within this topic
    if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS) {
        $sql = 'SELECT topic_id
			FROM ' . POSTS_TABLE . '
			WHERE topic_id = ' . $post_info['topic_id'] . '
				AND poster_id = ' . $post_info['user_id'];
        $result = $db->sql_query_limit($sql, 1);
        $topic_id = (int) $db->sql_fetchfield('topic_id');
        $db->sql_freeresult($result);
        if (!$topic_id) {
            $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
				WHERE user_id = ' . $post_info['user_id'] . '
					AND topic_id = ' . $post_info['topic_id'];
            $db->sql_query($sql);
        }
    }
    // change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
    if ($post_info['post_attachment']) {
        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
			SET poster_id = ' . $userdata['user_id'] . '
			WHERE poster_id = ' . $post_info['user_id'] . '
				AND post_msg_id = ' . $post_info['post_id'] . '
				AND topic_id = ' . $post_info['topic_id'];
        $db->sql_query($sql);
    }
    // refresh search cache of this post
    $search_type = $config['search_type'];
    if (class_exists($search_type)) {
        // We do some additional checks in the module to ensure it can actually be utilised
        $error = false;
        $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
        if (!$error && method_exists($search, 'destroy_cache')) {
            $search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
        }
    }
    $from_username = $post_info['username'];
    $to_username = $userdata['username'];
    /**
     * This event allows you to perform additional tasks after changing a post's poster
     *
     * @event core.mcp_change_poster_after
     * @var	array	userdata	Information on a post's new poster
     * @var	array	post_info	Information on the affected post
     * @since 3.1.6-RC1
     * @changed 3.1.7-RC1		Change location to prevent post_info from being set to the new post information
     */
    $vars = array('userdata', 'post_info');
    extract($phpbb_dispatcher->trigger_event('core.mcp_change_poster_after', compact($vars)));
    // Renew post info
    $post_info = phpbb_get_post_data(array($post_id), false, true);
    if (!sizeof($post_info)) {
        trigger_error('POST_NOT_EXIST');
    }
    $post_info = $post_info[$post_id];
    // Now add log entry
    add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
}
Ejemplo n.º 20
0
 function mark_read()
 {
     if ($this->post_id) {
         //only when post already stored
         markread('topic', $this->forum_id, $this->topic_id, time());
     }
 }
Ejemplo n.º 21
0
/**
* Change a post's poster
*/
function change_poster(&$post_info, $userdata)
{
    global $auth, $db, $config, $phpbb_root_path, $phpEx;
    if (empty($userdata) || $userdata['user_id'] == $post_info['user_id']) {
        return;
    }
    $post_id = $post_info['post_id'];
    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\tSET poster_id = {$userdata['user_id']}\n\t\tWHERE post_id = {$post_id}";
    $db->sql_query($sql);
    // Resync topic/forum if needed
    if ($post_info['topic_last_post_id'] == $post_id || $post_info['forum_last_post_id'] == $post_id || $post_info['topic_first_post_id'] == $post_id) {
        sync('topic', 'topic_id', $post_info['topic_id'], false, false);
        sync('forum', 'forum_id', $post_info['forum_id'], false, false);
    }
    // Adjust post counts... only if the post is approved (else, it was not added the users post count anyway)
    if ($post_info['post_postcount'] && $post_info['post_approved']) {
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_posts = user_posts - 1
			WHERE user_id = ' . $post_info['user_id'] . '
			AND user_posts > 0';
        $db->sql_query($sql);
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_posts = user_posts + 1
			WHERE user_id = ' . $userdata['user_id'];
        $db->sql_query($sql);
    }
    // Add posted to information for this topic for the new user
    markread('post', $post_info['forum_id'], $post_info['topic_id'], time(), $userdata['user_id']);
    // Remove the dotted topic option if the old user has no more posts within this topic
    if ($config['load_db_track'] && $post_info['user_id'] != ANONYMOUS) {
        $sql = 'SELECT topic_id
			FROM ' . POSTS_TABLE . '
			WHERE topic_id = ' . $post_info['topic_id'] . '
				AND poster_id = ' . $post_info['user_id'];
        $result = $db->sql_query_limit($sql, 1);
        $topic_id = (int) $db->sql_fetchfield('topic_id');
        $db->sql_freeresult($result);
        if (!$topic_id) {
            $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
				WHERE user_id = ' . $post_info['user_id'] . '
					AND topic_id = ' . $post_info['topic_id'];
            $db->sql_query($sql);
        }
    }
    // change the poster_id within the attachments table, else the data becomes out of sync and errors displayed because of wrong ownership
    if ($post_info['post_attachment']) {
        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
			SET poster_id = ' . $userdata['user_id'] . '
			WHERE poster_id = ' . $post_info['user_id'] . '
				AND post_msg_id = ' . $post_info['post_id'] . '
				AND topic_id = ' . $post_info['topic_id'];
        $db->sql_query($sql);
    }
    // refresh search cache of this post
    $search_type = basename($config['search_type']);
    if (file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) {
        require "{$phpbb_root_path}includes/search/{$search_type}.{$phpEx}";
        // We do some additional checks in the module to ensure it can actually be utilised
        $error = false;
        $search = new $search_type($error);
        if (!$error && method_exists($search, 'destroy_cache')) {
            $search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
        }
    }
    $from_username = $post_info['username'];
    $to_username = $userdata['username'];
    // Renew post info
    $post_info = get_post_data(array($post_id), false, true);
    if (!sizeof($post_info)) {
        trigger_error('POST_NOT_EXIST');
    }
    $post_info = $post_info[$post_id];
    // Now add log entry
    add_log('mod', $post_info['forum_id'], $post_info['topic_id'], 'LOG_MCP_CHANGE_POSTER', $post_info['topic_title'], $from_username, $to_username);
}
Ejemplo n.º 22
0
            $row['mark_time'] = isset($tracking[$forum_id36][$topic_id36]) ? (int) base_convert($tracking[$forum_id36][$topic_id36], 36, 10) : 0;
        }
        $last_mark_time = max($row['mark_time'], $mark_time_forum);
        if ($row['topic_last_post_time'] > $last_mark_time && $row['topic_id'] != $topic_id) {
            // We have a winner/loser
            // Set so the forum isn't marked
            $update_forum_mark = false;
            break;
        }
    }
    $_CLASS['core_db']->free_result($result);
    // Was this the last unread topic ?
    if ($update_forum_mark) {
        markread('forum', $forum_id, 0, $last_forum_post);
    } else {
        markread('topic', $forum_id, $topic_id, $update_mark);
    }
}
if ($view == 'print') {
    $_CLASS['core_display']->display(false, 'modules/Forums/viewtopic_print.html');
}
page_header();
make_jumpbox(generate_link('Forums&amp;file=viewforum'), $forum_id);
$_CLASS['core_display']->display(array($_CLASS['core_user']->get_lang('VIEWING_TOPIC'), $topic_data['topic_title']), 'modules/Forums/viewtopic_body.html');
//Move if we can
function topic_last_read($topic_id, $forum_id)
{
    global $config, $_CORE_CONFIG, $_CLASS;
    if ($_CLASS['core_user']->is_bot) {
        return gmtime();
    }
Ejemplo n.º 23
0
// Update topic view and if necessary attachment view counters ... but only for humans and if this is the first 'page view'
if (isset($user->data['session_page']) && !$user->data['is_bot'] && (strpos($user->data['session_page'], '&t=' . $topic_id) === false || isset($user->data['session_created']))) {
    $sql = 'UPDATE ' . TOPICS_TABLE . '
		SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "\n\t\tWHERE topic_id = {$topic_id}";
    $db->sql_query($sql);
    // Update the attachment download counts
    if (sizeof($update_count)) {
        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
			SET download_count = download_count + 1
			WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
        $db->sql_query($sql);
    }
}
// Only mark topic if it's currently unread. Also make sure we do not set topic tracking back if earlier pages are viewed.
if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id] && $max_post_time > $topic_tracking_info[$topic_id]) {
    markread('topic', $forum_id, $topic_id, $max_post_time);
    // Update forum info
    $all_marked_read = update_forum_tracking_info($forum_id, $topic_data['forum_last_post_time'], isset($topic_data['forum_mark_time']) ? $topic_data['forum_mark_time'] : false, false);
} else {
    $all_marked_read = true;
}
// If there are absolutely no more unread posts in this forum
// and unread posts shown, we can safely show the #unread link
if ($all_marked_read) {
    if ($post_unread) {
        $template->assign_vars(array('U_VIEW_UNREAD_POST' => '#unread'));
    } else {
        if (isset($topic_tracking_info[$topic_id]) && $topic_data['topic_last_post_time'] > $topic_tracking_info[$topic_id]) {
            $template->assign_vars(array('U_VIEW_UNREAD_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;view=unread") . '#unread'));
        }
    }
Ejemplo n.º 24
0
function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true)
{
    global $_CLASS, $config;
    // We do not handle erasing posts here
    if ($mode == 'delete') {
        return;
    }
    $current_time = gmtime();
    if ($mode == 'post') {
        $post_mode = 'post';
        $update_message = true;
    } else {
        if ($mode != 'edit') {
            $post_mode = 'reply';
            $update_message = true;
        } else {
            if ($mode == 'edit') {
                $post_mode = $data['topic_first_post_id'] == $data['topic_last_post_id'] ? 'edit_topic' : ($data['topic_first_post_id'] == $data['post_id'] ? 'edit_first_post' : ($data['topic_last_post_id'] == $data['post_id'] ? 'edit_last_post' : 'edit'));
            }
        }
    }
    // Collect some basic informations about which tables and which rows to update/insert
    $sql_data = array();
    $poster_id = $mode == 'edit' ? $data['poster_id'] : (int) $_CLASS['core_user']->data['user_id'];
    // Collect Informations
    switch ($post_mode) {
        case 'post':
        case 'reply':
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => (int) $_CLASS['core_user']->data['user_id'], 'icon_id' => $data['icon_id'], 'poster_ip' => $_CLASS['core_user']->ip, 'post_time' => $current_time, 'post_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'enable_bbcode' => $data['enable_bbcode'], 'enable_html' => $data['enable_html'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => !$_CLASS['core_user']->is_user ? stripslashes($username) : '', 'post_subject' => $subject, 'post_text' => $data['message'], 'post_checksum' => $data['message_md5'], 'post_attachment' => isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked']);
            break;
        case 'edit_first_post':
        case 'edit':
            if (!$_CLASS['auth']->acl_gets('m_', 'a_') || $data['post_edit_reason']) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time);
                $sql_data[FORUMS_POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            }
        case 'edit_last_post':
        case 'edit_topic':
            if (($post_mode == 'edit_last_post' || $post_mode == 'edit_topic') && $data['post_edit_reason']) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time);
                $sql_data[FORUMS_POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            }
            if (!isset($sql_data[FORUMS_POSTS_TABLE]['sql'])) {
                $sql_data[FORUMS_POSTS_TABLE]['sql'] = array();
            }
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], 'post_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'enable_bbcode' => $data['enable_bbcode'], 'enable_html' => $data['enable_html'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => $username && $data['poster_id'] == ANONYMOUS ? stripslashes($username) : '', 'post_subject' => $subject, 'post_edit_reason' => $data['post_edit_reason'], 'post_edit_user' => (int) $data['post_edit_user'], 'post_checksum' => $data['message_md5'], 'post_attachment' => isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked']));
            if ($update_message) {
                $sql_data[FORUMS_POSTS_TABLE]['sql']['post_text'] = $data['message'];
            }
            break;
    }
    // And the topic ladies and gentlemen
    switch ($post_mode) {
        case 'post':
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('topic_poster' => (int) $_CLASS['core_user']->data['user_id'], 'topic_time' => $current_time, 'forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'topic_title' => $subject, 'topic_first_poster_name' => !$_CLASS['core_user']->is_user && $username ? stripslashes($username) : $_CLASS['core_user']->data['username'], 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'topic_status' => $data['topic_status'], 'topic_attachment' => isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0, 'topic_replies_real' => 0, 'topic_replies' => 0, 'topic_views' => 0);
            if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
                $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array('poll_title' => $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, 'poll_vote_change' => $poll['poll_vote_change']));
            }
            $sql_data[USERS_TABLE]['stat'][] = "user_last_post_time = {$current_time}" . ($_CLASS['auth']->acl_get('f_postcount', $data['forum_id']) ? ', user_posts = user_posts + 1' : '');
            if ($topic_type != POST_GLOBAL) {
                if (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve')) {
                    $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
                }
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? ', forum_topics = forum_topics + 1' : '');
            }
            break;
        case 'reply':
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = 'topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? ', topic_replies = topic_replies + 1' : '');
            $sql_data[USERS_TABLE]['stat'][] = "user_last_post_time = {$current_time}" . ($_CLASS['auth']->acl_get('f_postcount', $data['forum_id']) ? ', user_posts = user_posts + 1' : '');
            if ((!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve')) && $topic_type != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
            }
            break;
        case 'edit_topic':
        case 'edit_first_post':
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? 0 : 1, 'topic_title' => $subject, 'topic_first_poster_name' => stripslashes($username), 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'poll_title' => $poll['poll_options'] ? $poll['poll_title'] : '', 'poll_start' => $poll['poll_options'] ? $poll['poll_start'] ? $poll['poll_start'] : $current_time : 0, 'poll_max_options' => $poll['poll_options'] ? $poll['poll_max_options'] : 1, 'poll_length' => $poll['poll_options'] ? $poll['poll_length'] * 86400 : 0, 'poll_vote_change' => $poll['poll_vote_change'], 'topic_attachment' => $post_mode == 'edit_topic' ? isset($data['filename_data']['physical_filename']) && sizeof($data['filename_data']) ? 1 : 0 : $data['topic_attachment']);
            break;
    }
    $_CLASS['core_db']->transaction();
    // Submit new topic
    if ($post_mode == 'post') {
        $sql = 'INSERT INTO ' . FORUMS_TOPICS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $sql_data[FORUMS_TOPICS_TABLE]['sql']);
        $_CLASS['core_db']->query($sql);
        $data['topic_id'] = $_CLASS['core_db']->insert_id(FORUMS_TOPICS_TABLE, 'topic_id');
        $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        unset($sql_data[FORUMS_TOPICS_TABLE]['sql']);
    }
    // Submit new post
    if ($post_mode == 'post' || $post_mode == 'reply') {
        if ($post_mode == 'reply') {
            $sql_data[FORUMS_POSTS_TABLE]['sql'] = array_merge($sql_data[FORUMS_POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        }
        $sql = 'INSERT INTO ' . FORUMS_POSTS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $sql_data[FORUMS_POSTS_TABLE]['sql']);
        $_CLASS['core_db']->query($sql);
        $data['post_id'] = $_CLASS['core_db']->insert_id(FORUMS_POSTS_TABLE, 'post_id');
        if ($post_mode == 'post') {
            $sql_data[FORUMS_TOPICS_TABLE]['sql'] = array('topic_first_post_id' => $data['post_id'], 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => (int) $_CLASS['core_user']->data['user_id'], 'topic_last_poster_name' => !$_CLASS['core_user']->is_user && $username ? $username : $_CLASS['core_user']->data['username']);
        }
        unset($sql_data[FORUMS_POSTS_TABLE]['sql']);
    }
    $make_global = false;
    // Are we globalising or unglobalising?
    if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic') {
        $sql = 'SELECT topic_type, topic_replies_real, topic_approved
			FROM ' . FORUMS_TOPICS_TABLE . '
			WHERE topic_id = ' . $data['topic_id'];
        $result = $_CLASS['core_db']->query($sql);
        $row = $_CLASS['core_db']->fetch_row_assoc($result);
        $_CLASS['core_db']->free_result($result);
        // globalise
        if ($row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) {
            // Decrement topic/post count
            $make_global = true;
            $sql_data[FORUMS_FORUMS_TABLE]['stat'] = array();
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($row['topic_replies_real'] + 1);
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . ($row['topic_approved'] ? ', forum_topics = forum_topics - 1' : '');
            // Update forum_ids for all posts
            $sql = 'UPDATE ' . POSTS_TABLE . '
				SET forum_id = 0
				WHERE topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        } else {
            if ($row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) {
                // Increment topic/post count
                $make_global = true;
                $sql_data[FORUMS_FORUMS_TABLE]['stat'] = array();
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($row['topic_replies_real'] + 1);
                $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ($row['topic_approved'] ? ', forum_topics = forum_topics + 1' : '');
                // Update forum_ids for all posts
                $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
				SET forum_id = ' . $data['forum_id'] . '
				WHERE topic_id = ' . $data['topic_id'];
                $_CLASS['core_db']->query($sql);
            }
        }
    }
    // Update the topics table
    if (isset($sql_data[FORUMS_TOPICS_TABLE]['sql'])) {
        $_CLASS['core_db']->query('UPDATE ' . FORUMS_TOPICS_TABLE . '
			SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_data[FORUMS_TOPICS_TABLE]['sql']) . '
			WHERE topic_id = ' . $data['topic_id']);
    }
    // Update the posts table
    if (isset($sql_data[FORUMS_POSTS_TABLE]['sql'])) {
        $_CLASS['core_db']->query('UPDATE ' . FORUMS_POSTS_TABLE . '
			SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_data[FORUMS_POSTS_TABLE]['sql']) . '
			WHERE post_id = ' . $data['post_id']);
    }
    // Update Poll Tables
    if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
        $cur_poll_options = array();
        if ($poll['poll_start'] && $mode == 'edit') {
            $sql = 'SELECT * FROM ' . FORUMS_POLL_OPTIONS_TABLE . '
				WHERE topic_id = ' . $data['topic_id'] . '
				ORDER BY poll_option_id';
            $result = $_CLASS['core_db']->query($sql);
            while ($cur_poll_options[] = $_CLASS['core_db']->fetch_row_assoc($result)) {
            }
            $_CLASS['core_db']->free_result($result);
        }
        $size = sizeof($poll['poll_options']);
        for ($i = 0, $size; $i < $size; $i++) {
            if (trim($poll['poll_options'][$i])) {
                if (!$cur_poll_options[$i]) {
                    $sql = 'INSERT INTO ' . FORUMS_POLL_OPTIONS_TABLE . "  (poll_option_id, topic_id, poll_option_text)\n\t\t\t\t\t\tVALUES ({$i}, " . $data['topic_id'] . ", '" . $_CLASS['core_db']->sql_escape($poll['poll_options'][$i]) . "')";
                    $_CLASS['core_db']->query($sql);
                } else {
                    if ($poll['poll_options'][$i] != $cur_poll_options[$i]) {
                        $sql = "UPDATE " . FORUMS_POLL_OPTIONS_TABLE . "\n\t\t\t\t\t\tSET poll_option_text = '" . $_CLASS['core_db']->sql_escape($poll['poll_options'][$i]) . "'\n\t\t\t\t\t\tWHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "\n\t\t\t\t\t\t\tAND topic_id = " . $data['topic_id'];
                        $_CLASS['core_db']->query($sql);
                    }
                }
            }
        }
        if (sizeof($poll['poll_options']) < sizeof($cur_poll_options)) {
            $sql = 'DELETE FROM ' . FORUMS_POLL_OPTIONS_TABLE . '
				WHERE poll_option_id >= ' . sizeof($poll['poll_options']) . '
					AND topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
    }
    // Submit Attachments
    if (sizeof($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) {
        $space_taken = $files_added = 0;
        foreach ($data['attachment_data'] as $pos => $attach_row) {
            if ($attach_row['attach_id']) {
                // update entry in db if attachment already stored in db and filespace
                $sql = 'UPDATE ' . FORUMS_ATTACHMENTS_TABLE . "\n\t\t\t\t\tSET comment = '" . $_CLASS['core_db']->sql_escape($attach_row['comment']) . "'\n\t\t\t\t\tWHERE attach_id = " . (int) $attach_row['attach_id'];
                $_CLASS['core_db']->query($sql);
            } else {
                // insert attachment into db
                if (!@file_exists($config['upload_path'] . '/' . basename($attach_row['physical_filename']))) {
                    continue;
                }
                $attach_sql = array('post_msg_id' => $data['post_id'], 'topic_id' => $data['topic_id'], 'in_message' => 0, 'poster_id' => $poster_id, 'physical_filename' => basename($attach_row['physical_filename']), 'real_filename' => basename($attach_row['real_filename']), 'comment' => $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 ' . FORUMS_ATTACHMENTS_TABLE . ' ' . $_CLASS['core_db']->sql_build_array('INSERT', $attach_sql);
                $_CLASS['core_db']->query($sql);
                $space_taken += $attach_row['filesize'];
                $files_added++;
            }
        }
        if (sizeof($data['attachment_data'])) {
            $sql = 'UPDATE ' . FORUMS_POSTS_TABLE . '
				SET post_attachment = 1
				WHERE post_id = ' . $data['post_id'];
            $_CLASS['core_db']->query($sql);
            $sql = 'UPDATE ' . FORUMS_TOPICS_TABLE . '
				SET topic_attachment = 1
				WHERE topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
        set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
        set_config('num_files', $config['num_files'] + $files_added, true);
    }
    $_CLASS['core_db']->transaction('commit');
    if ($post_mode == 'post' || $post_mode == 'reply' || $post_mode == 'edit_last_post') {
        if ($topic_type != POST_GLOBAL) {
            $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id']));
        }
        $update = update_last_post_information('topic', $data['topic_id']);
        if (sizeof($update)) {
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = implode(', ', $update);
        }
    }
    if ($make_global) {
        $sql_data[FORUMS_FORUMS_TABLE]['stat'][] = implode(', ', update_last_post_information('forum', $data['forum_id']));
    }
    if ($post_mode == 'edit_topic') {
        $update = update_last_post_information('topic', $data['topic_id']);
        if (sizeof($update)) {
            $sql_data[FORUMS_TOPICS_TABLE]['stat'][] = implode(', ', $update);
        }
    }
    // Update total post count, do not consider moderated posts/topics
    if (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve')) {
        if ($post_mode == 'post') {
            set_config('num_topics', $config['num_topics'] + 1, true);
            set_config('num_posts', $config['num_posts'] + 1, true);
        }
        if ($post_mode == 'reply') {
            set_config('num_posts', $config['num_posts'] + 1, true);
        }
    }
    // Update forum stats
    $_CLASS['core_db']->transaction();
    $where_sql = array(FORUMS_POSTS_TABLE => 'post_id = ' . $data['post_id'], FORUMS_TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $_CLASS['core_user']->data['user_id']);
    foreach ($sql_data as $table => $update_ary) {
        if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) {
            $_CLASS['core_db']->query("UPDATE {$table} SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table]);
        }
    }
    // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
    if ($make_global) {
        $_CLASS['core_db']->query('DELETE FROM ' . FORUMS_TOPICS_TABLE . '
			WHERE topic_moved_id = ' . $data['topic_id']);
    }
    // Fulltext parse
    if ($update_message && $data['enable_indexing']) {
        $search = new fulltext_search();
        $result = $search->add($mode, $data['post_id'], $data['message'], $subject);
    }
    $_CLASS['core_db']->transaction('commit');
    // Delete draft if post was loaded...
    $draft_id = request_var('draft_loaded', 0);
    if ($draft_id) {
        $_CLASS['core_db']->query('DELETE FROM ' . DRAFTS_TABLE . " WHERE draft_id = {$draft_id} AND user_id = " . $_CLASS['core_user']->data['user_id']);
    }
    // Topic Notification
    if (!$data['notify_set'] && $data['notify']) {
        $sql = 'INSERT INTO ' . FORUMS_TOPICS_WATCH_TABLE . ' (user_id, topic_id)
			VALUES (' . $_CLASS['core_user']->data['user_id'] . ', ' . $data['topic_id'] . ')';
        $_CLASS['core_db']->query($sql);
    } else {
        if ($data['notify_set'] && !$data['notify']) {
            $sql = 'DELETE FROM ' . FORUMS_TOPICS_WATCH_TABLE . '
			WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . '
				AND topic_id = ' . $data['topic_id'];
            $_CLASS['core_db']->query($sql);
        }
    }
    // Mark this topic as read and posted to.
    markread('topic', $data['forum_id'], $data['topic_id'], $data['post_time']);
    // Send Notifications
    if ($mode != 'edit' && $mode != 'delete' && (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve'))) {
        user_notification($mode, stripslashes($subject), stripslashes($data['topic_title']), stripslashes($data['forum_name']), $data['forum_id'], $data['topic_id'], $data['post_id']);
    }
    if ($mode == 'post') {
        $url = !$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? generate_link('Forums&amp;file=viewtopic&amp;f=' . $data['forum_id'] . '&amp;t=' . $data['topic_id']) : generate_link('Forums&amp;file=viewforum&amp;f=' . $data['forum_id']);
    } else {
        $url = !$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? generate_link("Forums&amp;file=viewtopic&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}&amp;p={$data['post_id']}#{$data['post_id']}") : generate_link("Forums&amp;file=viewtopic&amp;f={$data['forum_id']}&amp;t={$data['topic_id']}");
    }
    $_CLASS['core_display']->meta_refresh(3, $url);
    $message = $_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) && !$_CLASS['auth']->acl_get('m_approve') ? $mode == 'edit' ? 'POST_EDITED_MOD' : 'POST_STORED_MOD' : ($mode == 'edit' ? 'POST_EDITED' : 'POST_STORED');
    $message = $_CLASS['core_user']->lang[$message] . (!$_CLASS['auth']->acl_get('f_moderate', $data['forum_id']) || $_CLASS['auth']->acl_get('m_approve') ? '<br /><br />' . sprintf($_CLASS['core_user']->lang['VIEW_MESSAGE'], '<a href="' . $url . '">', '</a>') : '') . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . generate_link('Forums&amp;file=viewforum&amp;f=' . $data['forum_id']) . '">', '</a>');
    trigger_error($message);
}
Ejemplo n.º 25
0
/**
* Handle topic bumping
* @param int $forum_id The ID of the forum the topic is being bumped belongs to
* @param int $topic_id The ID of the topic is being bumping
* @param array $post_data Passes some topic parameters:
*				- 'topic_title'
*				- 'topic_last_post_id'
*				- 'topic_last_poster_id'
*				- 'topic_last_post_subject'
*				- 'topic_last_poster_name'
*				- 'topic_last_poster_colour'
* @param int $bump_time The time at which topic was bumped, usually it is a current time as obtained via time().
* @return string An URL to the bumped topic, example: ./viewtopic.php?forum_id=1&amptopic_id=2&ampp=3#p3
*/
function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false)
{
    global $config, $db, $user, $phpEx, $phpbb_root_path, $phpbb_log;
    if ($bump_time === false) {
        $bump_time = time();
    }
    // Begin bumping
    $db->sql_transaction('begin');
    // Update the topic's last post post_time
    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\tSET post_time = {$bump_time}\n\t\tWHERE post_id = {$post_data['topic_last_post_id']}\n\t\t\tAND topic_id = {$topic_id}";
    $db->sql_query($sql);
    // Sync the topic's last post time, the rest of the topic's last post data isn't changed
    $sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\tSET topic_last_post_time = {$bump_time},\n\t\t\ttopic_bumped = 1,\n\t\t\ttopic_bumper = " . $user->data['user_id'] . "\n\t\tWHERE topic_id = {$topic_id}";
    $db->sql_query($sql);
    // Update the forum's last post info
    $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\tSET forum_last_post_id = " . $post_data['topic_last_post_id'] . ",\n\t\t\tforum_last_poster_id = " . $post_data['topic_last_poster_id'] . ",\n\t\t\tforum_last_post_subject = '" . $db->sql_escape($post_data['topic_last_post_subject']) . "',\n\t\t\tforum_last_post_time = {$bump_time},\n\t\t\tforum_last_poster_name = '" . $db->sql_escape($post_data['topic_last_poster_name']) . "',\n\t\t\tforum_last_poster_colour = '" . $db->sql_escape($post_data['topic_last_poster_colour']) . "'\n\t\tWHERE forum_id = {$forum_id}";
    $db->sql_query($sql);
    // Update bumper's time of the last posting to prevent flood
    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\tSET user_lastpost_time = {$bump_time}\n\t\tWHERE user_id = " . $user->data['user_id'];
    $db->sql_query($sql);
    $db->sql_transaction('commit');
    // Mark this topic as posted to
    markread('post', $forum_id, $topic_id, $bump_time);
    // Mark this topic as read
    markread('topic', $forum_id, $topic_id, $bump_time);
    // Update forum tracking info
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        $sql = 'SELECT mark_time
			FROM ' . FORUMS_TRACK_TABLE . '
			WHERE user_id = ' . $user->data['user_id'] . '
				AND forum_id = ' . $forum_id;
        $result = $db->sql_query($sql);
        $f_mark_time = (int) $db->sql_fetchfield('mark_time');
        $db->sql_freeresult($result);
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            $f_mark_time = false;
        }
    }
    if ($config['load_db_lastread'] && $user->data['is_registered'] || $config['load_anon_lastread'] || $user->data['is_registered']) {
        // Update forum info
        $sql = 'SELECT forum_last_post_time
			FROM ' . FORUMS_TABLE . '
			WHERE forum_id = ' . $forum_id;
        $result = $db->sql_query($sql);
        $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
        $db->sql_freeresult($result);
        update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time, false);
    }
    $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_BUMP_TOPIC', false, array('forum_id' => $forum_id, 'topic_id' => $topic_id, $post_data['topic_title']));
    $url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}&amp;p={$post_data['topic_last_post_id']}") . "#p{$post_data['topic_last_post_id']}";
    return $url;
}
Ejemplo n.º 26
0
/**
* Submit Post
* @todo Split up and create lightweight, simple API for this.
*/
function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true)
{
    global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path;
    // www.phpBB-SEO.com SEO TOOLKIT BEGIN
    global $phpbb_seo;
    // www.phpBB-SEO.com SEO TOOLKIT END
    // We do not handle erasing posts here
    if ($mode == 'delete') {
        return false;
    }
    $current_time = time();
    if ($mode == 'post') {
        $post_mode = 'post';
        $update_message = true;
    } else {
        if ($mode != 'edit') {
            $post_mode = 'reply';
            $update_message = true;
        } else {
            if ($mode == 'edit') {
                $post_mode = $data['topic_replies_real'] == 0 ? 'edit_topic' : ($data['topic_first_post_id'] == $data['post_id'] ? 'edit_first_post' : ($data['topic_last_post_id'] == $data['post_id'] ? 'edit_last_post' : 'edit'));
            }
        }
    }
    // First of all make sure the subject and topic title are having the correct length.
    // To achieve this without cutting off between special chars we convert to an array and then count the elements.
    $subject = truncate_string($subject);
    $data['topic_title'] = truncate_string($data['topic_title']);
    // Collect some basic information about which tables and which rows to update/insert
    $sql_data = $topic_row = array();
    $poster_id = $mode == 'edit' ? $data['poster_id'] : (int) $user->data['user_id'];
    // Retrieve some additional information if not present
    if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false)) {
        $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved
			FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
			WHERE t.topic_id = p.topic_id
				AND p.post_id = ' . $data['post_id'];
        $result = $db->sql_query($sql);
        $topic_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        $data['topic_approved'] = $topic_row['topic_approved'];
        $data['post_approved'] = $topic_row['post_approved'];
    }
    // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval
    // The variable name should be $post_approved, because it indicates if the post is approved or not
    $post_approval = 1;
    // Check the permissions for post approval. Moderators are not affected.
    if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) {
        // Post not approved, but in queue
        $post_approval = 0;
    }
    // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved
    if (isset($data['force_approved_state'])) {
        $post_approval = $data['force_approved_state'] ? 1 : 0;
    }
    // Start the transaction here
    $db->sql_transaction('begin');
    // Collect Information
    switch ($post_mode) {
        case 'post':
        case 'reply':
            $sql_data[POSTS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => (int) $user->data['user_id'], 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, 'post_approved' => $post_approval, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => !$user->data['is_registered'] ? $username : '', 'post_subject' => $subject, 'post_text' => $data['message'], 'post_checksum' => $data['message_md5'], 'post_attachment' => !empty($data['attachment_data']) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_postcount' => $auth->acl_get('f_postcount', $data['forum_id']) ? 1 : 0, 'post_edit_locked' => $data['post_edit_locked']);
            break;
        case 'edit_first_post':
        case 'edit':
        case 'edit_last_post':
        case 'edit_topic':
            // If edit reason is given always display edit info
            // If editing last post then display no edit info
            // If m_edit permission then display no edit info
            // If normal edit display edit info
            // Display edit info if edit reason given or user is editing his post, which is not the last within the topic.
            if ($data['post_edit_reason'] || !$auth->acl_get('m_edit', $data['forum_id']) && ($post_mode == 'edit' || $post_mode == 'edit_first_post')) {
                $data['post_edit_reason'] = truncate_string($data['post_edit_reason'], 255, 255, false);
                $sql_data[POSTS_TABLE]['sql'] = array('post_edit_time' => $current_time, 'post_edit_reason' => $data['post_edit_reason'], 'post_edit_user' => (int) $data['post_edit_user']);
                $sql_data[POSTS_TABLE]['stat'][] = 'post_edit_count = post_edit_count + 1';
            } else {
                if (!$data['post_edit_reason'] && $mode == 'edit' && $auth->acl_get('m_edit', $data['forum_id'])) {
                    $sql_data[POSTS_TABLE]['sql'] = array('post_edit_reason' => '');
                }
            }
            // If the person editing this post is different to the one having posted then we will add a log entry stating the edit
            // Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods
            if ($user->data['user_id'] != $poster_id) {
                $log_subject = $subject ? $subject : $data['topic_title'];
                add_log('mod', $data['forum_id'], $data['topic_id'], 'LOG_POST_EDITED', $log_subject, !empty($username) ? $username : $user->lang['GUEST']);
            }
            if (!isset($sql_data[POSTS_TABLE]['sql'])) {
                $sql_data[POSTS_TABLE]['sql'] = array();
            }
            $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], 'post_approved' => !$post_approval ? 0 : $data['post_approved'], 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], 'enable_sig' => $data['enable_sig'], 'post_username' => $username && $data['poster_id'] == ANONYMOUS ? $username : '', 'post_subject' => $subject, 'post_checksum' => $data['message_md5'], 'post_attachment' => !empty($data['attachment_data']) ? 1 : 0, 'bbcode_bitfield' => $data['bbcode_bitfield'], 'bbcode_uid' => $data['bbcode_uid'], 'post_edit_locked' => $data['post_edit_locked']));
            if ($update_message) {
                $sql_data[POSTS_TABLE]['sql']['post_text'] = $data['message'];
            }
            break;
    }
    $post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved'];
    $topic_row = array();
    // And the topic ladies and gentlemen
    switch ($post_mode) {
        case 'post':
            $sql_data[TOPICS_TABLE]['sql'] = array('topic_poster' => (int) $user->data['user_id'], 'topic_time' => $current_time, 'topic_last_view_time' => $current_time, 'forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => $post_approval, 'topic_title' => $subject, 'topic_first_poster_name' => !$user->data['is_registered'] && $username ? $username : ($user->data['user_id'] != ANONYMOUS ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'topic_attachment' => !empty($data['attachment_data']) ? 1 : 0);
            // www.phpBB-SEO.com SEO TOOLKIT BEGIN
            if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) {
                $sql_data[TOPICS_TABLE]['sql'] += array('topic_url' => isset($data['topic_url']) ? $data['topic_url'] : '');
            }
            // www.phpBB-SEO.com SEO TOOLKIT END
            if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
                $poll_start = $poll['poll_start'] ? $poll['poll_start'] : $current_time;
                $poll_length = $poll['poll_length'] * 86400;
                if ($poll_length < 0) {
                    $poll_start = $poll_start + $poll_length;
                    if ($poll_start < 0) {
                        $poll_start = 0;
                    }
                    $poll_length = 1;
                }
                $sql_data[TOPICS_TABLE]['sql'] = array_merge($sql_data[TOPICS_TABLE]['sql'], array('poll_title' => $poll['poll_title'], 'poll_start' => $poll_start, 'poll_max_options' => $poll['poll_max_options'], 'poll_length' => $poll_length, 'poll_vote_change' => $poll['poll_vote_change']));
            }
            $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = {$current_time}" . ($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval ? ', user_posts = user_posts + 1' : '');
            if ($topic_type != POST_GLOBAL) {
                if ($post_approval) {
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
                }
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ($post_approval ? ', forum_topics = forum_topics + 1' : '');
            }
            break;
        case 'reply':
            $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ',
				topic_replies_real = topic_replies_real + 1,
				topic_bumped = 0,
				topic_bumper = 0' . ($post_approval ? ', topic_replies = topic_replies + 1' : '') . (!empty($data['attachment_data']) || isset($data['topic_attachment']) && $data['topic_attachment'] ? ', topic_attachment = 1' : '');
            $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = {$current_time}" . ($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval ? ', user_posts = user_posts + 1' : '');
            if ($post_approval && $topic_type != POST_GLOBAL) {
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1';
            }
            break;
        case 'edit_topic':
        case 'edit_first_post':
            if (isset($poll['poll_options']) && !empty($poll['poll_options'])) {
                $poll_start = $poll['poll_start'] ? $poll['poll_start'] : $current_time;
                $poll_length = $poll['poll_length'] * 86400;
                if ($poll_length < 0) {
                    $poll_start = $poll_start + $poll_length;
                    if ($poll_start < 0) {
                        $poll_start = 0;
                    }
                    $poll_length = 1;
                }
            }
            $sql_data[TOPICS_TABLE]['sql'] = array('forum_id' => $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_approved' => !$post_approval ? 0 : $data['topic_approved'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, 'topic_time_limit' => $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ? $data['topic_time_limit'] * 86400 : 0, 'poll_title' => isset($poll['poll_options']) ? $poll['poll_title'] : '', 'poll_start' => isset($poll['poll_options']) ? $poll_start : 0, 'poll_max_options' => isset($poll['poll_options']) ? $poll['poll_max_options'] : 1, 'poll_length' => isset($poll['poll_options']) ? $poll_length : 0, 'poll_vote_change' => isset($poll['poll_vote_change']) ? $poll['poll_vote_change'] : 0, 'topic_last_view_time' => $current_time, 'topic_attachment' => !empty($data['attachment_data']) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0));
            // www.phpBB-SEO.com SEO TOOLKIT BEGIN
            if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) {
                $sql_data[TOPICS_TABLE]['sql'] += array('topic_url' => isset($data['topic_url']) ? $data['topic_url'] : '');
            }
            // www.phpBB-SEO.com SEO TOOLKIT END
            // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved
            if (!$post_approval && $data['topic_approved']) {
                // Do we need to grab some topic informations?
                if (!sizeof($topic_row)) {
                    $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved
						FROM ' . TOPICS_TABLE . '
						WHERE topic_id = ' . $data['topic_id'];
                    $result = $db->sql_query($sql);
                    $topic_row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                }
                // If this is the only post remaining we do not need to decrement topic_replies.
                // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again.
                // If this is an edited topic or the first post the topic gets completely disapproved later on...
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1';
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1);
                set_config_count('num_topics', -1, true);
                set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * -1, true);
                // Only decrement this post, since this is the one non-approved now
                if ($auth->acl_get('f_postcount', $data['forum_id'])) {
                    $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
                }
            }
            break;
        case 'edit':
        case 'edit_last_post':
            // Correctly set back the topic replies and forum posts... but only if the post was approved before.
            if (!$post_approval && $data['post_approved']) {
                $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1';
                set_config_count('num_posts', -1, true);
                if ($auth->acl_get('f_postcount', $data['forum_id'])) {
                    $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1';
                }
            }
            break;
    }
    // Submit new topic
    if ($post_mode == 'post') {
        $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[TOPICS_TABLE]['sql']);
        $db->sql_query($sql);
        $data['topic_id'] = $db->sql_nextid();
        $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        unset($sql_data[TOPICS_TABLE]['sql']);
    }
    // Submit new post
    if ($post_mode == 'post' || $post_mode == 'reply') {
        if ($post_mode == 'reply') {
            $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array('topic_id' => $data['topic_id']));
        }
        $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']);
        $db->sql_query($sql);
        $data['post_id'] = $db->sql_nextid();
        if ($post_mode == 'post') {
            $sql_data[TOPICS_TABLE]['sql'] = array('topic_first_post_id' => $data['post_id'], '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' => !$user->data['is_registered'] && $username ? $username : ($user->data['user_id'] != ANONYMOUS ? $user->data['username'] : ''), 'topic_last_poster_colour' => $user->data['user_colour'], 'topic_last_post_subject' => (string) $subject);
        }
        unset($sql_data[POSTS_TABLE]['sql']);
    }
    $make_global = false;
    // Are we globalising or unglobalising?
    if ($post_mode == 'edit_first_post' || $post_mode == 'edit_topic') {
        if (!sizeof($topic_row)) {
            $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved, topic_last_post_id
				FROM ' . TOPICS_TABLE . '
				WHERE topic_id = ' . $data['topic_id'];
            $result = $db->sql_query($sql);
            $topic_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
        // globalise/unglobalise?
        if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL || $topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) {
            if (!empty($sql_data[FORUMS_TABLE]['stat']) && implode('', $sql_data[FORUMS_TABLE]['stat'])) {
                $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET ' . implode(', ', $sql_data[FORUMS_TABLE]['stat']) . ' WHERE forum_id = ' . $data['forum_id']);
            }
            $make_global = true;
            $sql_data[FORUMS_TABLE]['stat'] = array();
        }
        // globalise
        if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL) {
            // Decrement topic/post count
            $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies_real'] + 1);
            $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real - 1' . ($topic_row['topic_approved'] ? ', forum_topics = forum_topics - 1' : '');
            // Update forum_ids for all posts
            $sql = 'UPDATE ' . POSTS_TABLE . '
				SET forum_id = 0
				WHERE topic_id = ' . $data['topic_id'];
            $db->sql_query($sql);
        } else {
            if ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL) {
                // Increment topic/post count
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + ' . ($topic_row['topic_replies_real'] + 1);
                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . ($topic_row['topic_approved'] ? ', forum_topics = forum_topics + 1' : '');
                // Update forum_ids for all posts
                $sql = 'UPDATE ' . POSTS_TABLE . '
				SET forum_id = ' . $data['forum_id'] . '
				WHERE topic_id = ' . $data['topic_id'];
                $db->sql_query($sql);
            }
        }
    }
    // Update the topics table
    if (isset($sql_data[TOPICS_TABLE]['sql'])) {
        $sql = 'UPDATE ' . TOPICS_TABLE . '
			SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . '
			WHERE topic_id = ' . $data['topic_id'];
        $db->sql_query($sql);
    }
    // Update the posts table
    if (isset($sql_data[POSTS_TABLE]['sql'])) {
        $sql = 'UPDATE ' . POSTS_TABLE . '
			SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . '
			WHERE post_id = ' . $data['post_id'];
        $db->sql_query($sql);
    }
    // Update Poll Tables
    if (isset($poll['poll_options']) && !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);
            $cur_poll_options = array();
            while ($row = $db->sql_fetchrow($result)) {
                $cur_poll_options[] = $row;
            }
            $db->sql_freeresult($result);
        }
        $sql_insert_ary = array();
        for ($i = 0, $size = sizeof($poll['poll_options']); $i < $size; $i++) {
            if (strlen(trim($poll['poll_options'][$i]))) {
                if (empty($cur_poll_options[$i])) {
                    // If we add options we need to put them to the end to be able to preserve votes...
                    $sql_insert_ary[] = array('poll_option_id' => (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary), 'topic_id' => (int) $data['topic_id'], 'poll_option_text' => (string) $poll['poll_options'][$i]);
                } else {
                    if ($poll['poll_options'][$i] != $cur_poll_options[$i]) {
                        $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "\n\t\t\t\t\t\tSET poll_option_text = '" . $db->sql_escape($poll['poll_options'][$i]) . "'\n\t\t\t\t\t\tWHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . '
							AND topic_id = ' . $data['topic_id'];
                        $db->sql_query($sql);
                    }
                }
            }
        }
        $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);
        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);
        }
        // If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option
        if ($mode == 'edit' && sizeof($poll['poll_options']) != sizeof($cur_poll_options)) {
            $db->sql_query('DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data['topic_id']);
            $db->sql_query('UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data['topic_id']);
        }
    }
    // Submit Attachments
    if (!empty($data['attachment_data']) && $data['post_id'] && in_array($mode, array('post', 'reply', 'quote', 'edit'))) {
        $space_taken = $files_added = 0;
        $orphan_rows = array();
        foreach ($data['attachment_data'] as $pos => $attach_row) {
            $orphan_rows[(int) $attach_row['attach_id']] = array();
        }
        if (sizeof($orphan_rows)) {
            $sql = 'SELECT attach_id, filesize, physical_filename
				FROM ' . ATTACHMENTS_TABLE . '
				WHERE ' . $db->sql_in_set('attach_id', array_keys($orphan_rows)) . '
					AND is_orphan = 1
					AND poster_id = ' . $user->data['user_id'];
            $result = $db->sql_query($sql);
            $orphan_rows = array();
            while ($row = $db->sql_fetchrow($result)) {
                $orphan_rows[$row['attach_id']] = $row;
            }
            $db->sql_freeresult($result);
        }
        foreach ($data['attachment_data'] as $pos => $attach_row) {
            if ($attach_row['is_orphan'] && !isset($orphan_rows[$attach_row['attach_id']])) {
                continue;
            }
            if (!$attach_row['is_orphan']) {
                // update entry in db if attachment already stored in db and filespace
                $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tSET attach_comment = '" . $db->sql_escape($attach_row['attach_comment']) . "'\n\t\t\t\t\tWHERE attach_id = " . (int) $attach_row['attach_id'] . '
						AND is_orphan = 0';
                $db->sql_query($sql);
            } else {
                // insert attachment into db
                if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename']))) {
                    continue;
                }
                $space_taken += $orphan_rows[$attach_row['attach_id']]['filesize'];
                $files_added++;
                $attach_sql = array('post_msg_id' => $data['post_id'], 'topic_id' => $data['topic_id'], 'is_orphan' => 0, 'poster_id' => $poster_id, 'attach_comment' => $attach_row['attach_comment']);
                $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $attach_sql) . '
					WHERE attach_id = ' . $attach_row['attach_id'] . '
						AND is_orphan = 1
						AND poster_id = ' . $user->data['user_id'];
                $db->sql_query($sql);
            }
        }
        if ($space_taken && $files_added) {
            set_config_count('upload_dir_size', $space_taken, true);
            set_config_count('num_files', $files_added, true);
        }
    }
    // we need to update the last forum information
    // only applicable if the topic is not global and it is approved
    // we also check to make sure we are not dealing with globaling the latest topic (pretty rare but still needs to be checked)
    if ($topic_type != POST_GLOBAL && !$make_global && ($post_approved || !$data['post_approved'])) {
        // the last post makes us update the forum table. This can happen if...
        // We make a new topic
        // We reply to a topic
        // We edit the last post in a topic and this post is the latest in the forum (maybe)
        // We edit the only post in the topic
        // We edit the first post in the topic and all the other posts are not approved
        if (($post_mode == 'post' || $post_mode == 'reply') && $post_approved) {
            $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id'];
            $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'";
            $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time;
            $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id'];
            $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(!$user->data['is_registered'] && $username ? $username : ($user->data['user_id'] != ANONYMOUS ? $user->data['username'] : '')) . "'";
            $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'";
        } else {
            if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $post_mode == 'edit_first_post' && !$data['topic_replies']) {
                // this does not _necessarily_ mean that we must update the info again,
                // it just means that we might have to
                $sql = 'SELECT forum_last_post_id, forum_last_post_subject
				FROM ' . FORUMS_TABLE . '
				WHERE forum_id = ' . (int) $data['forum_id'];
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                // this post is the latest post in the forum, better update
                if ($row['forum_last_post_id'] == $data['post_id']) {
                    // If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows
                    if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) {
                        // the post's subject changed
                        if ($row['forum_last_post_subject'] !== $subject) {
                            $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\'';
                        }
                        // Update the user name if poster is anonymous... just in case an admin changed it
                        if ($data['poster_id'] == ANONYMOUS) {
                            $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'";
                        }
                    } else {
                        if ($data['post_approved'] !== $post_approved) {
                            // we need a fresh change of socks, everything has become invalidated
                            $sql = 'SELECT MAX(topic_last_post_id) as last_post_id
						FROM ' . TOPICS_TABLE . '
						WHERE forum_id = ' . (int) $data['forum_id'] . '
							AND topic_approved = 1';
                            $result = $db->sql_query($sql);
                            $row = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            // any posts left in this forum?
                            if (!empty($row['last_post_id'])) {
                                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
							FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
							WHERE p.poster_id = u.user_id
								AND p.post_id = ' . (int) $row['last_post_id'];
                                $result = $db->sql_query($sql);
                                $row = $db->sql_fetchrow($result);
                                $db->sql_freeresult($result);
                                // salvation, a post is found! jam it into the forums table
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id'];
                                $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time'];
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id'];
                                $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($row['poster_id'] == ANONYMOUS ? $row['post_username'] : $row['username']) . "'";
                                $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
                            } else {
                                // just our luck, the last topic in the forum has just been turned unapproved...
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0';
                                $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''";
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0';
                                $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0';
                                $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''";
                                $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''";
                            }
                        }
                    }
                }
            }
        }
    } else {
        if ($make_global) {
            // somebody decided to be a party pooper, we must recalculate the whole shebang (maybe)
            $sql = 'SELECT forum_last_post_id
			FROM ' . FORUMS_TABLE . '
			WHERE forum_id = ' . (int) $data['forum_id'];
            $result = $db->sql_query($sql);
            $forum_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            // we made a topic global, go get new data
            if ($topic_row['topic_type'] != POST_GLOBAL && $topic_type == POST_GLOBAL && $forum_row['forum_last_post_id'] == $topic_row['topic_last_post_id']) {
                // we need a fresh change of socks, everything has become invalidated
                $sql = 'SELECT MAX(topic_last_post_id) as last_post_id
				FROM ' . TOPICS_TABLE . '
				WHERE forum_id = ' . (int) $data['forum_id'] . '
					AND topic_approved = 1';
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                // any posts left in this forum?
                if (!empty($row['last_post_id'])) {
                    $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
					FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
					WHERE p.poster_id = u.user_id
						AND p.post_id = ' . (int) $row['last_post_id'];
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    // salvation, a post is found! jam it into the forums table
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id'];
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time'];
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id'];
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($row['poster_id'] == ANONYMOUS ? $row['post_username'] : $row['username']) . "'";
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
                } else {
                    // just our luck, the last topic in the forum has just been globalized...
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0';
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''";
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0';
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0';
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''";
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''";
                }
            } else {
                if ($topic_row['topic_type'] == POST_GLOBAL && $topic_type != POST_GLOBAL && $forum_row['forum_last_post_id'] < $topic_row['topic_last_post_id']) {
                    // this post has a higher id, it is newer
                    $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
				WHERE p.poster_id = u.user_id
					AND p.post_id = ' . (int) $topic_row['topic_last_post_id'];
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    // salvation, a post is found! jam it into the forums table
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id'];
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time'];
                    $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id'];
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($row['poster_id'] == ANONYMOUS ? $row['post_username'] : $row['username']) . "'";
                    $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
                }
            }
        }
    }
    // topic sync time!
    // simply, we update if it is a reply or the last post is edited
    if ($post_approved) {
        // reply requires the whole thing
        if ($post_mode == 'reply') {
            $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $data['post_id'];
            $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $user->data['user_id'];
            $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape(!$user->data['is_registered'] && $username ? $username : ($user->data['user_id'] != ANONYMOUS ? $user->data['username'] : '')) . "'";
            $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . ($user->data['user_id'] != ANONYMOUS ? $db->sql_escape($user->data['user_colour']) : '') . "'";
            $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'";
            $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $current_time;
        } else {
            if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $post_mode == 'edit_first_post' && !$data['topic_replies']) {
                // only the subject can be changed from edit
                $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'";
                // Maybe not only the subject, but also changing anonymous usernames. ;)
                if ($data['poster_id'] == ANONYMOUS) {
                    $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'";
                }
            }
        }
    } else {
        if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $post_mode == 'edit_first_post' && !$data['topic_replies'])) {
            // like having the rug pulled from under us
            $sql = 'SELECT MAX(post_id) as last_post_id
			FROM ' . POSTS_TABLE . '
			WHERE topic_id = ' . (int) $data['topic_id'] . '
				AND post_approved = 1';
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            // any posts left in this forum?
            if (!empty($row['last_post_id'])) {
                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour
				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
				WHERE p.poster_id = u.user_id
					AND p.post_id = ' . (int) $row['last_post_id'];
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                // salvation, a post is found! jam it into the topics table
                $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $row['post_id'];
                $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'";
                $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $row['post_time'];
                $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $row['poster_id'];
                $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($row['poster_id'] == ANONYMOUS ? $row['post_username'] : $row['username']) . "'";
                $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'";
            }
        }
    }
    // Update total post count, do not consider moderated posts/topics
    if ($post_approval) {
        if ($post_mode == 'post') {
            set_config_count('num_topics', 1, true);
            set_config_count('num_posts', 1, true);
        }
        if ($post_mode == 'reply') {
            set_config_count('num_posts', 1, true);
        }
    }
    // Update forum stats
    $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id);
    foreach ($sql_data as $table => $update_ary) {
        if (isset($update_ary['stat']) && implode('', $update_ary['stat'])) {
            $sql = "UPDATE {$table} SET " . implode(', ', $update_ary['stat']) . ' WHERE ' . $where_sql[$table];
            $db->sql_query($sql);
        }
    }
    // Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
    if ($make_global) {
        $sql = 'DELETE FROM ' . TOPICS_TABLE . '
			WHERE topic_moved_id = ' . $data['topic_id'];
        $db->sql_query($sql);
    }
    // Committing the transaction before updating search index
    $db->sql_transaction('commit');
    // Delete draft if post was loaded...
    $draft_id = request_var('draft_loaded', 0);
    if ($draft_id) {
        $sql = 'DELETE FROM ' . DRAFTS_TABLE . "\n\t\t\tWHERE draft_id = {$draft_id}\n\t\t\t\tAND user_id = {$user->data['user_id']}";
        $db->sql_query($sql);
    }
    // Index message contents
    if ($update_search_index && $data['enable_indexing']) {
        // Select the search method and do some additional checks to ensure it can actually be utilised
        $search_type = basename($config['search_type']);
        if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) {
            trigger_error('NO_SUCH_SEARCH_MODULE');
        }
        if (!class_exists($search_type)) {
            include "{$phpbb_root_path}includes/search/{$search_type}.{$phpEx}";
        }
        $error = false;
        $search = new $search_type($error);
        if ($error) {
            trigger_error($error);
        }
        $search->index($mode, $data['post_id'], $data['message'], $subject, $poster_id, $topic_type == POST_GLOBAL ? 0 : $data['forum_id']);
    }
    // Topic Notification, do not change if moderator is changing other users posts...
    if ($user->data['user_id'] == $poster_id) {
        if (!$data['notify_set'] && $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'] && !$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);
            }
        }
    }
    if ($mode == 'post' || $mode == 'reply' || $mode == 'quote') {
        // Mark this topic as posted to
        markread('post', $data['forum_id'], $data['topic_id'], $data['post_time']);
    }
    // Mark this topic as read
    // We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
    markread('topic', $topic_type == POST_GLOBAL ? 0 : $data['forum_id'], $data['topic_id'], time());
    //
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        $sql = 'SELECT mark_time
			FROM ' . FORUMS_TRACK_TABLE . '
			WHERE user_id = ' . $user->data['user_id'] . '
				AND forum_id = ' . ($topic_type == POST_GLOBAL ? 0 : $data['forum_id']);
        $result = $db->sql_query($sql);
        $f_mark_time = (int) $db->sql_fetchfield('mark_time');
        $db->sql_freeresult($result);
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            $f_mark_time = false;
        }
    }
    if ($config['load_db_lastread'] && $user->data['is_registered'] || $config['load_anon_lastread'] || $user->data['is_registered']) {
        // Update forum info
        if ($topic_type == POST_GLOBAL) {
            $sql = 'SELECT MAX(topic_last_post_time) as forum_last_post_time
				FROM ' . TOPICS_TABLE . '
				WHERE forum_id = 0';
        } else {
            $sql = 'SELECT forum_last_post_time
				FROM ' . FORUMS_TABLE . '
				WHERE forum_id = ' . $data['forum_id'];
        }
        $result = $db->sql_query($sql);
        $forum_last_post_time = (int) $db->sql_fetchfield('forum_last_post_time');
        $db->sql_freeresult($result);
        update_forum_tracking_info($topic_type == POST_GLOBAL ? 0 : $data['forum_id'], $forum_last_post_time, $f_mark_time, false);
    }
    // Send Notifications
    if ($mode != 'edit' && $mode != 'delete' && $post_approval) {
        user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']);
    }
    $params = $add_anchor = '';
    if ($post_approval) {
        $params .= '&amp;t=' . $data['topic_id'];
        if ($mode != 'post') {
            $params .= '&amp;p=' . $data['post_id'];
            $add_anchor = '#p' . $data['post_id'];
        }
    } else {
        if ($mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic') {
            $params .= '&amp;t=' . $data['topic_id'];
        }
    }
    // www.phpBB-SEO.com SEO TOOLKIT BEGIN
    $phpbb_seo->set_url($data['forum_name'], $data['forum_id'], $phpbb_seo->seo_static['forum']);
    if ($params) {
        $phpbb_seo->prepare_iurl($data, 'topic', $topic_type == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$data['forum_id']]);
    }
    // www.phpBB-SEO.com SEO TOOLKIT END
    $url = !$params ? "{$phpbb_root_path}viewforum.{$phpEx}" : "{$phpbb_root_path}viewtopic.{$phpEx}";
    $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;
    return $url;
}
Ejemplo n.º 27
0
/**
* Fork Topic
*/
function mcp_fork_topic($topic_ids)
{
    global $auth, $user, $db, $template, $config;
    global $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher;
    if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_'))) {
        return;
    }
    $to_forum_id = $request->variable('to_forum_id', 0);
    $forum_id = $request->variable('f', 0);
    $redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));
    $additional_msg = $success_msg = '';
    $counter = array();
    $s_hidden_fields = build_hidden_fields(array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'fork', 'redirect' => $redirect));
    if ($to_forum_id) {
        $forum_data = phpbb_get_forum_data($to_forum_id, 'f_post');
        if (!sizeof($topic_ids)) {
            $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
        } else {
            if (!sizeof($forum_data)) {
                $additional_msg = $user->lang['FORUM_NOT_EXIST'];
            } else {
                $forum_data = $forum_data[$to_forum_id];
                if ($forum_data['forum_type'] != FORUM_POST) {
                    $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
                } else {
                    if (!$auth->acl_get('f_post', $to_forum_id)) {
                        $additional_msg = $user->lang['USER_CANNOT_POST'];
                    }
                }
            }
        }
    } else {
        if (isset($_POST['confirm'])) {
            $additional_msg = $user->lang['FORUM_NOT_EXIST'];
        }
    }
    if ($additional_msg) {
        $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
        $request->overwrite('confirm_key', null);
    }
    if (confirm_box(true)) {
        $topic_data = phpbb_get_topic_data($topic_ids, 'f_post');
        $total_topics = $total_topics_unapproved = $total_topics_softdeleted = 0;
        $total_posts = $total_posts_unapproved = $total_posts_softdeleted = 0;
        $new_topic_id_list = array();
        foreach ($topic_data as $topic_id => $topic_row) {
            if (!isset($search_type) && $topic_row['enable_indexing']) {
                // Select the search method and do some additional checks to ensure it can actually be utilised
                $search_type = $config['search_type'];
                if (!class_exists($search_type)) {
                    trigger_error('NO_SUCH_SEARCH_MODULE');
                }
                $error = false;
                $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
                $search_mode = 'post';
                if ($error) {
                    trigger_error($error);
                }
            } else {
                if (!isset($search_type) && !$topic_row['enable_indexing']) {
                    $search_type = false;
                }
            }
            $sql_ary = array('forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], 'topic_visibility' => (int) $topic_row['topic_visibility'], 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], 'topic_posts_approved' => (int) $topic_row['topic_posts_approved'], 'topic_posts_unapproved' => (int) $topic_row['topic_posts_unapproved'], 'topic_posts_softdeleted' => (int) $topic_row['topic_posts_softdeleted'], 'topic_status' => (int) $topic_row['topic_status'], 'topic_type' => (int) $topic_row['topic_type'], 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'], 'topic_bumped' => (int) $topic_row['topic_bumped'], 'topic_bumper' => (int) $topic_row['topic_bumper'], 'poll_title' => (string) $topic_row['poll_title'], 'poll_start' => (int) $topic_row['poll_start'], 'poll_length' => (int) $topic_row['poll_length'], 'poll_max_options' => (int) $topic_row['poll_max_options'], 'poll_vote_change' => (int) $topic_row['poll_vote_change']);
            $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
            $new_topic_id = $db->sql_nextid();
            $new_topic_id_list[$topic_id] = $new_topic_id;
            switch ($topic_row['topic_visibility']) {
                case ITEM_APPROVED:
                    $total_topics++;
                    break;
                case ITEM_UNAPPROVED:
                case ITEM_REAPPROVE:
                    $total_topics_unapproved++;
                    break;
                case ITEM_DELETED:
                    $total_topics_softdeleted++;
                    break;
            }
            if ($topic_row['poll_start']) {
                $poll_rows = array();
                $sql = 'SELECT *
					FROM ' . POLL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $sql_ary = array('poll_option_id' => (int) $row['poll_option_id'], 'topic_id' => (int) $new_topic_id, 'poll_option_text' => (string) $row['poll_option_text'], 'poll_option_total' => 0);
                    $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                }
                $db->sql_freeresult($result);
            }
            $sql = 'SELECT *
				FROM ' . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tORDER BY post_time ASC, post_id ASC";
            $result = $db->sql_query($sql);
            $post_rows = array();
            while ($row = $db->sql_fetchrow($result)) {
                $post_rows[] = $row;
            }
            $db->sql_freeresult($result);
            if (!sizeof($post_rows)) {
                continue;
            }
            foreach ($post_rows as $row) {
                $sql_ary = array('topic_id' => (int) $new_topic_id, 'forum_id' => (int) $to_forum_id, 'poster_id' => (int) $row['poster_id'], 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], 'post_visibility' => (int) $row['post_visibility'], 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], 'enable_magic_url' => (int) $row['enable_magic_url'], 'enable_sig' => (int) $row['enable_sig'], 'post_username' => (string) $row['post_username'], 'post_subject' => (string) $row['post_subject'], 'post_text' => (string) $row['post_text'], 'post_edit_reason' => (string) $row['post_edit_reason'], 'post_edit_user' => (int) $row['post_edit_user'], 'post_checksum' => (string) $row['post_checksum'], 'post_attachment' => (int) $row['post_attachment'], 'bbcode_bitfield' => $row['bbcode_bitfield'], 'bbcode_uid' => (string) $row['bbcode_uid'], 'post_edit_time' => (int) $row['post_edit_time'], 'post_edit_count' => (int) $row['post_edit_count'], 'post_edit_locked' => (int) $row['post_edit_locked'], 'post_postcount' => $row['post_postcount']);
                // Adjust post count only if the post can be incremented to the user counter
                if ($row['post_postcount']) {
                    if (isset($counter[$row['poster_id']])) {
                        ++$counter[$row['poster_id']];
                    } else {
                        $counter[$row['poster_id']] = 1;
                    }
                }
                $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                $new_post_id = $db->sql_nextid();
                switch ($row['post_visibility']) {
                    case ITEM_APPROVED:
                        $total_posts++;
                        break;
                    case ITEM_UNAPPROVED:
                    case ITEM_REAPPROVE:
                        $total_posts_unapproved++;
                        break;
                    case ITEM_DELETED:
                        $total_posts_softdeleted++;
                        break;
                }
                // Copy whether the topic is dotted
                markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
                if (!empty($search_type)) {
                    $search->index($search_mode, $new_post_id, $sql_ary['post_text'], $sql_ary['post_subject'], $sql_ary['poster_id'], $topic_row['topic_type'] == POST_GLOBAL ? 0 : $to_forum_id);
                    $search_mode = 'reply';
                    // After one we index replies
                }
                // Copy Attachments
                if ($row['post_attachment']) {
                    $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\tWHERE post_msg_id = {$row['post_id']}\n\t\t\t\t\t\t\tAND topic_id = {$topic_id}\n\t\t\t\t\t\t\tAND in_message = 0";
                    $result = $db->sql_query($sql);
                    $sql_ary = array();
                    while ($attach_row = $db->sql_fetchrow($result)) {
                        $sql_ary[] = array('post_msg_id' => (int) $new_post_id, 'topic_id' => (int) $new_topic_id, 'in_message' => 0, 'is_orphan' => (int) $attach_row['is_orphan'], 'poster_id' => (int) $attach_row['poster_id'], 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']), 'real_filename' => (string) utf8_basename($attach_row['real_filename']), 'download_count' => (int) $attach_row['download_count'], 'attach_comment' => (string) $attach_row['attach_comment'], 'extension' => (string) $attach_row['extension'], 'mimetype' => (string) $attach_row['mimetype'], 'filesize' => (int) $attach_row['filesize'], 'filetime' => (int) $attach_row['filetime'], 'thumbnail' => (int) $attach_row['thumbnail']);
                    }
                    $db->sql_freeresult($result);
                    if (sizeof($sql_ary)) {
                        $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
                    }
                }
            }
            // Copy topic subscriptions to new topic
            $sql = 'SELECT user_id, notify_status
				FROM ' . TOPICS_WATCH_TABLE . '
				WHERE topic_id = ' . $topic_id;
            $result = $db->sql_query($sql);
            $sql_ary = array();
            while ($row = $db->sql_fetchrow($result)) {
                $sql_ary[] = array('topic_id' => (int) $new_topic_id, 'user_id' => (int) $row['user_id'], 'notify_status' => (int) $row['notify_status']);
            }
            $db->sql_freeresult($result);
            if (sizeof($sql_ary)) {
                $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
            }
            // Copy bookmarks to new topic
            $sql = 'SELECT user_id
				FROM ' . BOOKMARKS_TABLE . '
				WHERE topic_id = ' . $topic_id;
            $result = $db->sql_query($sql);
            $sql_ary = array();
            while ($row = $db->sql_fetchrow($result)) {
                $sql_ary[] = array('topic_id' => (int) $new_topic_id, 'user_id' => (int) $row['user_id']);
            }
            $db->sql_freeresult($result);
            if (sizeof($sql_ary)) {
                $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary);
            }
        }
        // Sync new topics, parent forums and board stats
        $sql = 'UPDATE ' . FORUMS_TABLE . '
			SET forum_posts_approved = forum_posts_approved + ' . $total_posts . ',
				forum_posts_unapproved = forum_posts_unapproved + ' . $total_posts_unapproved . ',
				forum_posts_softdeleted = forum_posts_softdeleted + ' . $total_posts_softdeleted . ',
				forum_topics_approved = forum_topics_approved + ' . $total_topics . ',
				forum_topics_unapproved = forum_topics_unapproved + ' . $total_topics_unapproved . ',
				forum_topics_softdeleted = forum_topics_softdeleted + ' . $total_topics_softdeleted . '
			WHERE forum_id = ' . $to_forum_id;
        $db->sql_query($sql);
        if (!empty($counter)) {
            // Do only one query per user and not a query per post.
            foreach ($counter as $user_id => $count) {
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET user_posts = user_posts + ' . (int) $count . '
					WHERE user_id = ' . (int) $user_id;
                $db->sql_query($sql);
            }
        }
        sync('topic', 'topic_id', $new_topic_id_list);
        sync('forum', 'forum_id', $to_forum_id);
        $config->increment('num_topics', sizeof($new_topic_id_list), false);
        $config->increment('num_posts', $total_posts, false);
        foreach ($new_topic_id_list as $topic_id => $new_topic_id) {
            $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_FORK', false, array('forum_id' => $to_forum_id, 'topic_id' => $new_topic_id, $topic_row['forum_name']));
        }
        $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
    } else {
        $template->assign_vars(array('S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true), 'S_CAN_LEAVE_SHADOW' => false, 'ADDITIONAL_MSG' => $additional_msg));
        confirm_box(false, 'FORK_TOPIC' . (sizeof($topic_ids) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
    }
    $redirect = $request->variable('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
        meta_refresh(3, $redirect_url);
        $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
        if ($forum_id != $to_forum_id) {
            $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $to_forum_id) . '">', '</a>');
        }
        trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
    }
}
Ejemplo n.º 28
0
// Not postable forum or showing active topics?
if (!($forum_data['forum_type'] == FORUM_POST || $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS && $forum_data['forum_type'] == FORUM_CAT)) {
    page_footer();
}
// Ok, if someone has only list-access, we only display the forum list.
// We also make this circumstance available to the template in case we want to display a notice. ;)
if (!$auth->acl_get('f_read', $forum_id)) {
    $template->assign_vars(array('S_NO_READ_ACCESS' => true));
    page_footer();
}
// Handle marking posts
if ($mark_read == 'topics') {
    $token = request_var('hash', '');
    if (check_link_hash($token, 'global')) {
        // Add 0 to forums array to mark global announcements correctly
        markread('topics', array($forum_id, 0));
    }
    $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
    meta_refresh(3, $redirect_url);
    trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
}
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> Zero dupe
// Moved this a little above for the zero dupe
// Is a forum specific topic count required?
//if ($forum_data['forum_topics_per_page'])
//{
//	$config['topics_per_page'] = $forum_data['forum_topics_per_page'];
//}
// www.phpBB-SEO.com SEO TOOLKIT END -> Zero dupe
// Do the forum Prune thang - cron type job ...
if ($forum_data['prune_next'] < time() && $forum_data['enable_prune']) {
Ejemplo n.º 29
0
/**
* Check for read forums and update topic tracking info accordingly
*
* @param int $forum_id the forum id to check
* @param int $forum_last_post_time the forums last post time
* @param int $f_mark_time the forums last mark time if user is registered and load_db_lastread enabled
* @param int $mark_time_forum false if the mark time needs to be obtained, else the last users forum mark time
*
* @return true if complete forum got marked read, else false.
*/
function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_time = false, $mark_time_forum = false)
{
    global $db, $tracking_topics, $user, $config;
    // Determine the users last forum mark time if not given.
    if ($mark_time_forum === false) {
        if ($config['load_db_lastread'] && $user->data['is_registered']) {
            $mark_time_forum = !empty($f_mark_time) ? $f_mark_time : $user->data['user_lastmark'];
        } else {
            if ($config['load_anon_lastread'] || $user->data['is_registered']) {
                $tracking_topics = isset($_COOKIE[$config['cookie_name'] . '_track']) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track'] : '';
                $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
                if (!$user->data['is_registered']) {
                    $user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
                }
                $mark_time_forum = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
            }
        }
    }
    // Check the forum for any left unread topics.
    // If there are none, we mark the forum as read.
    if ($config['load_db_lastread'] && $user->data['is_registered']) {
        if ($mark_time_forum >= $forum_last_post_time) {
            // We do not need to mark read, this happened before. Therefore setting this to true
            $row = true;
        } else {
            $sql = 'SELECT t.forum_id FROM ' . TOPICS_TABLE . ' t
				LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')
				WHERE t.forum_id = ' . $forum_id . '
					AND t.topic_last_post_time > ' . $mark_time_forum . '
					AND t.topic_moved_id = 0
					AND (tt.topic_id IS NULL OR tt.mark_time < t.topic_last_post_time)
				GROUP BY t.forum_id';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
    } else {
        if ($config['load_anon_lastread'] || $user->data['is_registered']) {
            // Get information from cookie
            $row = false;
            if (!isset($tracking_topics['tf'][$forum_id])) {
                // We do not need to mark read, this happened before. Therefore setting this to true
                $row = true;
            } else {
                $sql = 'SELECT topic_id
				FROM ' . TOPICS_TABLE . '
				WHERE forum_id = ' . $forum_id . '
					AND topic_last_post_time > ' . $mark_time_forum . '
					AND topic_moved_id = 0';
                $result = $db->sql_query($sql);
                $check_forum = $tracking_topics['tf'][$forum_id];
                $unread = false;
                while ($row = $db->sql_fetchrow($result)) {
                    if (!isset($check_forum[base_convert($row['topic_id'], 10, 36)])) {
                        $unread = true;
                        break;
                    }
                }
                $db->sql_freeresult($result);
                $row = $unread;
            }
        } else {
            $row = true;
        }
    }
    if (!$row) {
        markread('topics', $forum_id);
        return true;
    }
    return false;
}
function display_forums($root_data = '', $display_moderators = true)
{
    global $config, $_CLASS, $_CORE_CONFIG;
    // Get posted/get info
    $mark_read = request_var('mark', '');
    $forum_id_ary = $active_forum_ary = $forum_rows = $subforums = $forum_moderators = $mark_forums = array();
    $visible_forums = 0;
    if (!$root_data) {
        $root_data = array('forum_id' => 0);
        $sql_where = '';
    } else {
        $sql_where = 'AND left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
    }
    // Display list of active topics for this category?
    $show_active = isset($root_data['forum_flags']) && $root_data['forum_flags'] & 16 ? true : false;
    if ($_CLASS['core_user']->is_user && $config['load_db_lastread']) {
        $sql_from = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $_CLASS['core_user']->data['user_id'] . ' 
				AND ft.forum_id = f.forum_id AND ft.topic_id = 0)';
        $lastread_select = ', ft.mark_time ';
    } else {
        $sql_from = $lastread_select = $sql_lastread = '';
        $tracking_topics = @unserialize(get_variable($_CORE_CONFIG['server']['cookie_name'] . '_track', 'COOKIE'));
    }
    $sql = "SELECT f.* {$lastread_select} \n\t\tFROM " . FORUMS_FORUMS_TABLE . " f {$sql_from}\n\t\tWHERE forum_status <> " . ITEM_DELETING . "\n\t\t{$sql_where}\n\t\tORDER BY f.left_id";
    $result = $_CLASS['core_db']->query($sql);
    $branch_root_id = $root_data['forum_id'];
    $forum_ids = array($root_data['forum_id']);
    while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
        if ($mark_read == 'forums' && $_CLASS['core_user']->is_user) {
            if ($_CLASS['auth']->acl_get('f_list', $row['forum_id'])) {
                $forum_id_ary[] = $row['forum_id'];
            }
            continue;
        }
        if (isset($right_id)) {
            if ($row['left_id'] < $right_id) {
                continue;
            }
            unset($right_id);
        }
        if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
            // Non-postable forum with no subforums: don't display
            continue;
        }
        $forum_id = $row['forum_id'];
        if (!$_CLASS['auth']->acl_get('f_list', $forum_id)) {
            // if the user does not have permissions to list this forum, skip everything until next branch
            $right_id = $row['right_id'];
            continue;
        }
        // Display active topics from this forum?
        if ($show_active && $row['forum_type'] == FORUM_POST && $_CLASS['auth']->acl_get('f_read', $forum_id) && $row['forum_flags'] & 16) {
            $active_forum_ary['forum_id'][] = $forum_id;
            $active_forum_ary['enable_icons'][] = $row['enable_icons'];
            $active_forum_ary['forum_topics'] += $_CLASS['auth']->acl_get('m_approve', $forum_id) ? $row['forum_topics_real'] : $row['forum_topics'];
            $active_forum_ary['forum_posts'] += $row['forum_posts'];
        }
        if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) {
            // Direct child
            $parent_id = $forum_id;
            $forum_rows[$forum_id] = $row;
            $forum_ids[] = $forum_id;
            if (!$row['parent_id'] && $row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id']) {
                $branch_root_id = $forum_id;
            }
            $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
        } elseif ($row['forum_type'] != FORUM_CAT) {
            $subforums[$parent_id]['display'] = $row['display_on_index'] ? true : false;
            $subforums[$parent_id]['name'][$forum_id] = $row['forum_name'];
            $forum_rows[$parent_id]['forum_topics'] += $_CLASS['auth']->acl_get('m_approve', $forum_id) ? $row['forum_topics_real'] : $row['forum_topics'];
            // Do not list redirects in LINK Forums as Posts.
            if ($row['forum_type'] != FORUM_LINK) {
                $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
            }
            if (isset($forum_rows[$parent_id]) && $row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time']) {
                $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
                $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
                $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
                $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
                $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
            } else {
                $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
            }
        }
        if (!$_CLASS['core_user']->is_user || !$config['load_db_lastread']) {
            $forum_id36 = base_convert($forum_id, 10, 36);
            $row['mark_time'] = isset($tracking_topics[$forum_id36][0]) ? (int) base_convert($tracking_topics[$forum_id36][0], 36, 10) : 0;
        }
        if ($row['mark_time'] < $row['forum_last_post_time']) {
            $forum_unread[$parent_id] = true;
        }
    }
    $_CLASS['core_db']->free_result($result);
    // Handle marking posts
    if ($mark_read == 'forums') {
        markread('mark', $forum_id_ary);
        $redirect = generate_link('Forums');
        $_CLASS['core_display']->meta_refresh(3, $redirect);
        $message = strpos($redirect, 'viewforum') !== false ? 'RETURN_FORUM' : 'RETURN_INDEX';
        $message = $_CLASS['core_user']->lang['FORUMS_MARKED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang[$message], '<a href="' . $redirect . '">', '</a> ');
        trigger_error($message);
    }
    // Grab moderators ... if necessary
    if ($display_moderators) {
        $forum_moderators = get_moderators($forum_ids);
    }
    // Loop through the forums
    $root_id = $root_data['forum_id'];
    foreach ($forum_rows as $row) {
        if ($row['parent_id'] == $root_id && !$row['parent_id']) {
            if ($row['forum_type'] == FORUM_CAT) {
                $hold = $row;
                continue;
            } else {
                unset($hold);
            }
        } else {
            if (!empty($hold)) {
                $_CLASS['core_template']->assign_vars_array('forumrow', array('S_IS_CAT' => TRUE, 'FORUM_ID' => $hold['forum_id'], 'FORUM_NAME' => $hold['forum_name'], 'FORUM_DESC' => $hold['forum_desc'], 'U_VIEWFORUM' => generate_link('Forums&amp;file=viewforum&amp;f=' . $hold['forum_id'])));
                unset($hold);
            }
        }
        $visible_forums++;
        $forum_id = $row['forum_id'];
        $subforums_list = $l_subforums = '';
        // Generate list of subforums if we need to
        if (isset($subforums[$forum_id])) {
            if ($subforums[$forum_id]['display']) {
                $links = array();
                foreach ($subforums[$forum_id]['name'] as $subforum_id => $subforum_name) {
                    if (!empty($subforum_name)) {
                        $links[] = '<a href="' . generate_link('Forums&amp;file=viewforum&amp;f=' . $subforum_id) . '">' . $subforum_name . '</a>';
                    }
                }
                if (!empty($links)) {
                    $subforums_list = implode(', ', $links);
                    $l_subforums = count($subforums[$forum_id]) == 1 ? $_CLASS['core_user']->lang['SUBFORUM'] . ': ' : $_CLASS['core_user']->lang['SUBFORUMS'] . ': ';
                }
                unset($links);
            }
            $folder_image = !empty($forum_unread[$forum_id]) ? 'sub_forum_new' : 'sub_forum';
        } else {
            switch ($row['forum_type']) {
                case FORUM_POST:
                    $folder_image = !empty($forum_unread[$forum_id]) ? 'forum_new' : 'forum';
                    break;
                case FORUM_LINK:
                    $folder_image = 'forum_link';
                    break;
            }
        }
        // Which folder should we display?
        if ($row['forum_status'] == ITEM_LOCKED) {
            // forum_locked_new , need an image for this one
            $folder_image = empty($forum_unread[$forum_id]) ? 'forum_locked' : 'folder_locked_new';
            $folder_alt = 'FORUM_LOCKED';
        } else {
            $folder_alt = empty($forum_unread[$forum_id]) ? 'NO_NEW_POSTS' : 'NEW_POSTS';
        }
        // Create last post link information, if appropriate
        if ($row['forum_last_post_id']) {
            $last_post_time = $_CLASS['core_user']->format_date($row['forum_last_post_time']);
            $last_poster = $row['forum_last_poster_name'] != '' ? $row['forum_last_poster_name'] : $_CLASS['core_user']->lang['GUEST'];
            $last_poster_url = $row['forum_last_poster_id'] == ANONYMOUS ? '' : generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $row['forum_last_poster_id']);
            $last_post_url = generate_link('Forums&amp;file=viewtopic&amp;f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id'] . '#' . $row['forum_last_post_id'], false, false, false);
        } else {
            $last_post_time = $last_poster = $last_poster_url = $last_post_url = '';
        }
        // Output moderator listing ... if applicable
        $l_moderator = $moderators_list = '';
        if ($display_moderators && !empty($forum_moderators[$forum_id])) {
            $l_moderator = count($forum_moderators[$forum_id]) == 1 ? $_CLASS['core_user']->lang['MODERATOR'] : $_CLASS['core_user']->lang['MODERATORS'];
            $moderators_list = implode(', ', $forum_moderators[$forum_id]);
        }
        $l_post_click_count = $row['forum_type'] == FORUM_LINK ? 'CLICKS' : 'POSTS';
        $post_click_count = $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1 ? $row['forum_posts'] : '';
        $_CLASS['core_template']->assign_vars_array('forumrow', array('S_IS_CAT' => false, 'S_IS_LINK' => $row['forum_type'] == FORUM_LINK, 'LAST_POST_IMG' => $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST'), 'FORUM_ID' => $row['forum_id'], 'FORUM_FOLDER_IMG' => $row['forum_image'] ? '<img src="' . $row['forum_image'] . '" alt="' . $folder_alt . '" />' : $_CLASS['core_user']->img($folder_image, $folder_alt), 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESC' => $row['forum_desc'], 'FORUM_LOCKED' => $row['forum_status'] == ITEM_LOCKED ? 1 : 0, $l_post_click_count => $post_click_count, 'TOPICS' => $row['forum_topics'], 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => $last_poster, 'MODERATORS' => $moderators_list, 'SUBFORUMS' => $subforums_list, 'L_SUBFORUM_STR' => $l_subforums, 'L_MODERATOR_STR' => $l_moderator, 'L_FORUM_FOLDER_ALT' => $folder_alt, 'U_LAST_POSTER' => $last_poster_url, 'U_LAST_POST' => $last_post_url, 'U_VIEWFORUM' => $row['forum_type'] != FORUM_LINK || $row['forum_flags'] & 1 ? generate_link('Forums&amp;file=viewforum&amp;f=' . $row['forum_id']) : $row['forum_link']));
    }
    $_CLASS['core_template']->assign_array(array('MODIFY_FORUM' => $_CLASS['auth']->acl_get('a_forum'), 'U_MARK_FORUMS' => generate_link('Forums&amp;file=viewforum&amp;f=' . $root_data['forum_id'] . '&amp;mark=Forums'), 'S_HAS_SUBFORUM' => $visible_forums ? true : false, 'L_SUBFORUM' => $visible_forums == 1 ? $_CLASS['core_user']->lang['SUBFORUM'] : $_CLASS['core_user']->lang['SUBFORUMS']));
    return $active_forum_ary;
}