function get_subscribed_topic_func() { global $config, $db, $user, $auth, $mobiquo_config; // Only registered users can go beyond this point if (!$user->data['is_registered']) { return get_error(9); } $topic_list = array(); if ($config['allow_topic_notify']) { $forbidden_forums = $auth->acl_getf('!f_read', true); $forbidden_forums = array_unique(array_keys($forbidden_forums)); if (isset($mobiquo_config['hide_forum_id'])) { $forbidden_forums = array_unique(array_merge($forbidden_forums, $mobiquo_config['hide_forum_id'])); } $sql_array = array('SELECT' => 't.*, f.forum_name, u.user_avatar, u.user_avatar_type', 'FROM' => array(TOPICS_WATCH_TABLE => 'tw', TOPICS_TABLE => 't', USERS_TABLE => 'u'), 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id AND u.user_id = t.topic_last_poster_id AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true), 'ORDER_BY' => 't.topic_last_post_time DESC'); $sql_array['LEFT_JOIN'] = array(); $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id'); if ($config['allow_bookmarks']) { $sql_array['SELECT'] .= ', bm.topic_id as bookmarked'; $sql_array['LEFT_JOIN'][] = array('FROM' => array(BOOKMARKS_TABLE => 'bm'), 'ON' => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id'); } $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query_limit($sql, 20); $topic_list = array(); while ($row = $db->sql_fetchrow($result)) { $forum_id = $row['forum_id']; $topic_id = isset($row['b_topic_id']) ? $row['b_topic_id'] : $row['topic_id']; // Replies $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) { $topic_id = $row['topic_moved_id']; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $short_content = get_short_content($row['topic_last_post_id']); if ($forum_id) { $topic_tracking = get_complete_topic_tracking($forum_id, $topic_id); $new_post = $topic_tracking[$topic_id] < $row['topic_last_post_time'] ? true : false; } else { $new_post = false; } $user_avatar_url = get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']); $allow_change_type = $auth->acl_get('m_', $forum_id) || $user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'] ? true : false; $xmlrpc_topic = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(html_entity_decode($row['forum_name']), 'base64'), 'topic_id' => new xmlrpcval($topic_id), 'topic_title' => new xmlrpcval(html_entity_decode(strip_tags(censor_text($row['topic_title']))), 'base64'), 'reply_number' => new xmlrpcval(intval($replies), 'int'), 'view_number' => new xmlrpcval(intval($row['topic_views']), 'int'), 'short_content' => new xmlrpcval($short_content, 'base64'), 'post_author_id' => new xmlrpcval($row['topic_last_poster_id']), 'post_author_name' => new xmlrpcval(html_entity_decode($row['topic_last_poster_name']), 'base64'), 'new_post' => new xmlrpcval($new_post, 'boolean'), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($row['topic_last_post_time']), 'dateTime.iso8601'), 'icon_url' => new xmlrpcval($user_avatar_url), 'can_delete' => new xmlrpcval($auth->acl_get('m_delete', $forum_id), 'boolean'), 'can_bookmark' => new xmlrpcval($user->data['is_registered'] && $config['allow_bookmarks'], 'boolean'), 'isbookmarked' => new xmlrpcval($row['bookmarked'] ? true : false, 'boolean'), 'can_close' => new xmlrpcval($auth->acl_get('m_lock', $forum_id) || $auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'], 'boolean'), 'is_closed' => new xmlrpcval($row['topic_status'] == ITEM_LOCKED, 'boolean'), 'can_stick' => new xmlrpcval($allow_change_type && $auth->acl_get('f_sticky', $forum_id) && $row['topic_type'] != POST_STICKY, 'boolean')), 'struct'); $topic_list[] = $xmlrpc_topic; } $db->sql_freeresult($result); } $topic_num = count($topic_list); $response = new xmlrpcval(array('total_topic_num' => new xmlrpcval($topic_num, 'int'), 'topics' => new xmlrpcval($topic_list, 'array')), 'struct'); return new xmlrpcresp($response); }
/** * * @param array $topic_row a db topic row */ public function __construct(array $topic_row, $user, $auth, $phpbb_content_visibility, $phpbb_root_path, $php_ext) { $this->user = $user; $this->auth = $auth; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->topic_row = $topic_row; if ($topic_row['topic_status'] == ITEM_MOVED) { $this->topic_id = $topic_row['topic_moved_id']; } else { $this->topic_id = $topic_row['topic_id']; } $this->forum_id = (int) $this->topic_row['forum_id']; $this->view_topic_url_params = 'f=' . $this->forum_id . '&t=' . $this->topic_id; $this->view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params); $this->newest_post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&view=unread') . '#unread'; $this->last_post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $this->view_topic_url_params . '&p=' . $topic_row['topic_last_post_id']) . '#p' . $topic_row['topic_last_post_id']; $this->replies = $phpbb_content_visibility->get_count('topic_posts', $topic_row, $this->forum_id) - 1; // Get folder img, topic status/type related information topic_status($topic_row, $this->replies, $this->unread_topic(), $this->folder_img, $this->folder_alt, $this->topic_type); $this->topic_unapproved = ($topic_row['topic_visibility'] == ITEM_UNAPPROVED || $topic_row['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $this->forum_id); $this->posts_unapproved = $topic_row['topic_visibility'] == ITEM_APPROVED && $topic_row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $this->forum_id); $this->topic_deleted = $topic_row['topic_visibility'] == ITEM_DELETED; }
/** * Get similar topics by matching topic titles * * NOTE: Currently requires MySQL due to the use of FULLTEXT indexes * and MATCH and AGAINST and UNIX_TIMESTAMP. MySQL FULLTEXT has built-in * English ignore words. We use phpBB's ignore words for non-English * languages. We also remove any admin-defined special ignore words. * * @param array $topic_data Array with topic data * @return null * @access public */ public function display_similar_topics($topic_data) { $topic_title = $this->clean_topic_title($topic_data['topic_title']); // If the cleaned up topic_title is empty, no need to continue if (empty($topic_title)) { return; } // Similar Topics query $sql_array = array('SELECT' => "f.forum_id, f.forum_name, t.*,\n\t\t\t\tMATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') AS score", 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => "MATCH (t.topic_title) AGAINST ('" . $this->db->sql_escape($topic_title) . "') >= 0.5\n\t\t\t\tAND t.topic_status <> " . ITEM_MOVED . ' AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_time > (UNIX_TIMESTAMP() - ' . $this->config['similar_topics_time'] . ') AND t.topic_id <> ' . (int) $topic_data['topic_id']); // Add topic tracking data to the query (only if query caching is off) if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']); $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = f.forum_id AND ft.user_id = ' . $this->user->data['user_id']); $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as f_mark_time'; } else { if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) { // Cookie based tracking copied from search.php $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE); $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array(); } } // We need to exclude passworded forums so we do not leak the topic title $passworded_forums = $this->user->get_passworded_forums(); // See if the admin set this forum to only search a specific group of other forums, and include them if (!empty($topic_data['similar_topic_forums'])) { // Remove any passworded forums from this group of forums we will be searching $included_forums = array_diff(explode(',', $topic_data['similar_topic_forums']), $passworded_forums); // if there's nothing left to display (user has no access to the forums we want to search) if (empty($included_forums)) { return; } $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $included_forums); } else { if (!empty($this->config['similar_topics_ignore'])) { // Add passworded forums to the exlude array $excluded_forums = array_unique(array_merge(explode(',', $this->config['similar_topics_ignore']), $passworded_forums)); $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $excluded_forums, true); } else { if (!empty($passworded_forums)) { $sql_array['WHERE'] .= ' AND ' . $this->db->sql_in_set('f.forum_id', $passworded_forums, true); } } } /** * Event to modify the sql_array for similar topics * * @event vse.similartopics.get_topic_data * @var array sql_array SQL array to get similar topics data * @since 1.3.0 */ $vars = array('sql_array'); extract($this->dispatcher->trigger_event('vse.similartopics.get_topic_data', compact($vars))); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $this->config['similar_topics_limit'], 0, $this->config['similar_topics_cache']); // Grab icons $icons = $this->cache->obtain_icons(); $rowset = array(); while ($row = $this->db->sql_fetchrow($result)) { $similar_forum_id = (int) $row['forum_id']; $similar_topic_id = (int) $row['topic_id']; $rowset[$similar_topic_id] = $row; if ($this->auth->acl_get('f_read', $similar_forum_id)) { // Get topic tracking info if ($this->user->data['is_registered'] && $this->config['load_db_lastread'] && !$this->config['similar_topics_cache']) { $topic_tracking_info = get_topic_tracking($similar_forum_id, $similar_topic_id, $rowset, array($similar_forum_id => $row['f_mark_time'])); } else { if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) { $topic_tracking_info = get_complete_topic_tracking($similar_forum_id, $similar_topic_id); if (!$this->user->data['is_registered']) { $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0; } } } // Replies $replies = $this->content_visibility->get_count('topic_posts', $row, $similar_forum_id) - 1; // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; $unread_topic = isset($topic_tracking_info[$similar_topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$similar_topic_id] ? true : false; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false; $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $similar_forum_id) ? true : false; //$topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&t={$similar_topic_id}", true, $this->user->session_id) : ''; //$u_mcp_queue = (!$u_mcp_queue && $topic_deleted) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", "i=queue&mode=deleted_topics&t=$similar_topic_id", true, $this->user->session_id) : $u_mcp_queue; $base_url = append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&t=' . $similar_topic_id); $topic_row = array('TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => $row['topic_title'], 'FORUM_TITLE' => $row['forum_name'], 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang($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' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $similar_forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang('TOTAL_ATTACHMENTS')) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $this->auth->acl_get('m_report', $similar_forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'U_NEWEST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&t=' . $similar_topic_id . '&view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&t=' . $similar_topic_id . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_VIEW_TOPIC' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $similar_forum_id . '&t=' . $similar_topic_id), 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->php_ext}", 'f=' . $similar_forum_id), 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=reports&mode=reports&f=' . $similar_forum_id . '&t=' . $similar_topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue); /** * Event to modify the similar topics template block * * @event vse.similartopics.modify_topicrow * @var array row Array with similar topic data * @var array topic_row Template block array * @since 1.3.0 */ $vars = array('row', 'topic_row'); extract($this->dispatcher->trigger_event('vse.similartopics.modify_topicrow', compact($vars))); $this->template->assign_block_vars('similar', $topic_row); $this->pagination->generate_template_pagination($base_url, 'similar.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true); } } $this->db->sql_freeresult($result); $this->user->add_lang_ext('vse/similartopics', 'similar_topics'); $this->template->assign_vars(array('L_SIMILAR_TOPICS' => $this->user->lang('SIMILAR_TOPICS'), 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'REPORTED_IMG' => $this->user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'))); }
public function display_recent_topics($tpl_loopname = 'recent_topics', $spec_forum_id = 0, $include_subforums = true) { $this->user->add_lang_ext('paybas/recenttopics', 'recenttopics'); /** * Set some internal needed variables */ $topics_per_page = $this->config['rt_number']; $num_pages = $this->config['rt_page_number']; $min_topic_level = $this->config['rt_min_topic_level']; $excluded_topics = $this->config['rt_anti_topics']; $display_parent_forums = $this->config['rt_parents']; $unread_only = $this->config['rt_unreadonly']; $sort_topics = $this->config['rt_sort_start_time'] ? 'topic_time' : 'topic_last_post_time'; $persistent_display = $this->config['rt_persistent_display']; if ($persistent_display) { $this->template->assign_vars(array(strtoupper($tpl_loopname) . '_DISPLAY' => true)); } $start = $this->request->variable($tpl_loopname . '_start', 0); $excluded_topic_ids = explode(', ', $excluded_topics); $total_limit = $topics_per_page * $num_pages; if (!function_exists('display_forums')) { include $this->root_path . 'includes/functions_display.' . $this->phpEx; } /** * Get the forums we take our topics from */ // Get the allowed forums $forum_ary = array(); $forum_read_ary = $this->auth->acl_getf('f_read'); foreach ($forum_read_ary as $forum_id => $allowed) { if ($allowed['f_read']) { $forum_ary[] = (int) $forum_id; } } $forum_ids = array_unique($forum_ary); if (!sizeof($forum_ids)) { // No forums with f_read return; } $spec_forum_ary = array(); if ($spec_forum_id) { // Only take a special-forum if (!$include_subforums) { if (!in_array($spec_forum_id, $forum_ids)) { return; } $forum_ids = array(); $sql = 'SELECT 1 as display_forum FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . intval($spec_forum_id) . ' AND forum_recent_topics = 1'; $result = $this->db->sql_query_limit($sql, 1); $display_forum = (bool) $this->db->sql_fetchfield('display_forum'); $this->db->sql_freeresult($result); if ($display_forum) { $forum_ids = array($spec_forum_id); } } else { // ... and it's subforums $sql = 'SELECT f2.forum_id FROM ' . FORUMS_TABLE . ' f1 LEFT JOIN ' . FORUMS_TABLE . " f2\n\t\t\t\t\t\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\t\tORDER BY f2.left_id DESC"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $spec_forum_ary[] = $row['forum_id']; } $this->db->sql_freeresult($result); $forum_ids = array_intersect($forum_ids, $spec_forum_ary); if (!sizeof($forum_ids)) { return; } } } else { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE ' . $this->db->sql_in_set('forum_id', $forum_ids) . ' AND forum_recent_topics = 1'; $result = $this->db->sql_query($sql); $forum_ids = array(); while ($row = $this->db->sql_fetchrow($result)) { $forum_ids[] = $row['forum_id']; } $this->db->sql_freeresult($result); } // No forums with f_read or recent topics enabled if (!sizeof($forum_ids)) { return; } // Remove duplicated ids $forum_ids = array_unique($forum_ids); $forums = $topic_list = array(); $topics_count = 0; $obtain_icons = false; // Either use the phpBB core function to get unread topics, or the custom function for default behavior if ($unread_only && $this->user->data['user_id'] != ANONYMOUS) { // Get unread topics $sql_extra = ' AND ' . $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true); $sql_extra .= ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.'); $unread_topics = get_unread_topics(false, $sql_extra, '', $total_limit); foreach ($unread_topics as $topic_id => $mark_time) { $topics_count++; if ($topics_count > $start && $topics_count <= $start + $topics_per_page) { $topic_list[] = $topic_id; } } } else { // Get the allowed topics $sql_array = array('SELECT' => 't.forum_id, t.topic_id, t.topic_type, t.icon_id, tt.mark_time, ft.mark_time as f_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . ' AND t.topic_status <> ' . ITEM_MOVED . ' AND ' . $this->content_visibility->get_forums_visibility_sql('topic', $forum_ids, $table_alias = 't.'), 'ORDER_BY' => 't.' . $sort_topics . ' DESC'); // Check if we want all topics, or only stickies/announcements/globals if ($min_topic_level > 0) { $sql_array['WHERE'] .= ' AND t.topic_type >= ' . $min_topic_level; } /** * Event to modify the SQL query before the allowed topics list data is retrieved * * @event paybas.recenttopics.sql_pull_topics_list * @var array sql_array The SQL array * @since 2.0.4 */ $vars = array('sql_array'); extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_list', compact($vars))); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $total_limit); while ($row = $this->db->sql_fetchrow($result)) { $topics_count++; if ($topics_count > $start && $topics_count <= $start + $topics_per_page) { $topic_list[] = $row['topic_id']; $rowset[$row['topic_id']] = $row; if (!isset($forums[$row['forum_id']]) && $this->user->data['is_registered'] && $this->config['load_db_lastread']) { $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time']; } $forums[$row['forum_id']]['topic_list'][] = $row['topic_id']; $forums[$row['forum_id']]['rowset'][$row['topic_id']] =& $rowset[$row['topic_id']]; if ($row['icon_id'] && $this->auth->acl_get('f_icons', $row['forum_id'])) { $obtain_icons = true; } } } $this->db->sql_freeresult($result); } // No topics to display if (!sizeof($topic_list)) { return; } // Grab icons if ($obtain_icons) { $icons = $this->cache->obtain_icons(); } else { $icons = array(); } // Borrowed from search.php foreach ($forums as $forum_id => $forum) { if ($this->user->data['is_registered'] && $this->config['load_db_lastread']) { $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), $forum_id ? false : $forum['topic_list']); } else { if ($this->config['load_anon_lastread'] || $this->user->data['is_registered']) { $tracking_topics = $this->request->variable($this->config['cookie_name'] . '_track', '', true, \phpbb\request\request_interface::COOKIE); $tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array(); $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']); if (!$this->user->data['is_registered']) { $this->user->data['user_lastmark'] = isset($tracking_topics['l']) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $this->config['board_startdate']) : 0; } } } } // Now only pull the data of the requested topics $sql_array = array('SELECT' => 't.*, tp.topic_posted, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $this->user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_list), 'ORDER_BY' => 't.' . $sort_topics . ' DESC'); if ($display_parent_forums) { $sql_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id'; } /** * Event to modify the SQL query before the topics data is retrieved * * @event paybas.recenttopics.sql_pull_topics_data * @var array sql_array The SQL array * @since 2.0.0 */ $vars = array('sql_array'); extract($this->dispatcher->trigger_event('paybas.recenttopics.sql_pull_topics_data', compact($vars))); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $topics_per_page); $rowset = $topic_icons = array(); while ($row = $this->db->sql_fetchrow($result)) { $rowset[] = $row; } $this->db->sql_freeresult($result); // No topics returned by the DB if (!sizeof($rowset)) { return; } /** * Event to modify the topics list data before we start the display loop * * @event paybas.recenttopics.modify_topics_list * @var array topic_list Array of all the topic IDs * @var array rowset The full topics list array * @since 2.0.1 */ $vars = array('topic_list', 'rowset'); extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_topics_list', compact($vars))); foreach ($rowset as $row) { $topic_id = $row['topic_id']; $forum_id = $row['forum_id']; $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0; //$replies = ($this->auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; $replies = $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1; if ($unread_only) { topic_status($row, $replies, true, $folder_img, $folder_alt, $topic_type); $unread_topic = true; } else { topic_status($row, $replies, isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false, $folder_img, $folder_alt, $topic_type); $unread_topic = isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false; } $view_topic_url = append_sid("{$this->root_path}viewtopic.{$this->phpEx}", 'f=' . $forum_id . '&t=' . $topic_id); $view_forum_url = append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $forum_id); $topic_unapproved = $row['topic_visibility'] == ITEM_UNAPPROVED && $this->auth->acl_get('m_approve', $forum_id); $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $this->auth->acl_get('m_approve', $forum_id); $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&t={$topic_id}", true, $this->user->session_id) : ''; $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0; if (!empty($icons[$row['icon_id']])) { $topic_icons[] = $topic_id; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $tpl_ary = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $this->user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $this->user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $this->user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$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' => $this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $this->user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? $this->user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $this->auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test, 'U_NEWEST_POST' => $view_topic_url . '&view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$this->root_path}mcp.{$this->phpEx}", 'i=reports&mode=reports&f=' . $forum_id . '&t=' . $topic_id, true, $this->user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue); /** * Modify the topic data before it is assigned to the template * * @event paybas.recenttopics.modify_tpl_ary * @var array row Array with topic data * @var array tpl_ary Template block array with topic data * @since 2.0.0 */ $vars = array('row', 'tpl_ary'); extract($this->dispatcher->trigger_event('paybas.recenttopics.modify_tpl_ary', compact($vars))); $this->template->assign_block_vars($tpl_loopname, $tpl_ary); $this->pagination->generate_template_pagination($view_topic_url, $tpl_loopname . '.pagination', 'start', $replies + 1, $this->config['posts_per_page'], 1, true, true); if ($display_parent_forums) { $forum_parents = get_forum_parents($row); foreach ($forum_parents as $parent_id => $data) { $this->template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $parent_id))); } } } // Get URL-parameters for pagination $url_params = explode('&', $this->user->page['query_string']); $append_params = false; foreach ($url_params as $param) { if (!$param) { continue; } if (strpos($param, '=') === false) { // Fix MSSTI Advanced BBCode MOD $append_params[$param] = '1'; continue; } list($name, $value) = explode('=', $param); if ($name != $tpl_loopname . '_start') { $append_params[$name] = $value; } } $pagination_url = append_sid($this->root_path . $this->user->page['page_name'], $append_params); $this->pagination->generate_template_pagination($pagination_url, 'rt_pagination', $tpl_loopname . '_start', $topics_count, $topics_per_page, $start); $this->template->assign_vars(array('RT_SORT_START_TIME' => $sort_topics === 'topic_time' ? true : false, 'S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'POLL_IMG' => $this->user->img('icon_topic_poll', 'TOPIC_POLL'), strtoupper($tpl_loopname) . '_DISPLAY' => true)); }
function global_announcements() { global $db, $auth, $user, $template; global $phpbb_root_path, $phpEx, $config; global $cache, $topic_id; //need to know what page we are on.... $page = str_replace('.' . $phpEx, '', $user->page['page_name']); if ($page == 'index' && $config['load_global_announcements_home'] || $page == 'viewtopic' && $config['load_global_announcements_topic']) { //this template varible is only used to see if we should include forumlist_body on viewtopic_body (.html) $template->assign_var('S_HAS_GLOBAL', true); //so we are on the index or viewtopic page and we are enabled lets get the global announcements $sql = 'SELECT * FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . FORUM_CAT . ' AND topic_type = ' . POST_GLOBAL; if ($user->page['page_name'] == 'viewtopic.' . $phpEx) { //exclude the current topic, say if we are viewing it... $sql .= ' AND topic_id != ' . $topic_id; } $sql .= ' ORDER BY topic_time DESC'; //order by original creation user topic_last_post_time for last commente $result = $db->sql_query($sql); $first_time_flag = 0; $topic_list = $global_announce_list = array(); //generate items for tracking while ($row = $db->sql_fetchrow($result)) { $topic_list[] = $row['topic_id']; $global_announce_list[$row['topic_id']] = '1'; } $db->sql_freeresult($result); //tracking setup //sql hack to bypass the no f=0 topics... if (sizeof($topic_list)) { $topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $global_announce_list); } //regen $result = $db->sql_query($sql); $s_category = TRUE; while ($row = $db->sql_fetchrow($result)) { //is this the first time thru? if so we need a category... //genny a catergory :-) //highway of live mod no work, always gennys cats (under prosilver anyway) if ($s_category) { $template->assign_block_vars('forumrow', array('S_IS_CAT' => $s_category, 'FORUM_ID' => '0', 'FORUM_NAME' => $user->lang['GLOBAL_ANNOUNCEMENT'], 'U_VIEWFORUM' => '')); } $s_category = FALSE; // Grab topic icons stolen form cache.php $icons = $cache->obtain_icons(); // Get folder img, topic status/type related information and tracking/read/unread $unread_topic = isset($topic_tracking_info[$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$row['topic_id']] ? true : false; $folder_img = $folder_alt = ''; //topic_posted hack...for showing _mine images if ($row['topic_first_poster_name'] == $user->data['username']) { $row['topic_posted'] = true; } topic_status($row, $row['topic_replies'], $unread_topic, $folder_img, $folder_alt, $row['topic_type']); //doing first time here... so near to last time... $first_post_time = $user->format_date($row['topic_time']); // Create last post link information, if appropriate if ($row['topic_last_post_id']) { $last_post_subject = $row['topic_last_post_subject']; $last_post_time = $user->format_date($row['topic_last_post_time']); $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id']; } else { $last_post_subject = $last_post_time = $last_post_url = ''; } //most of the block varibles used forum var names but topic equiv to save mods to forumlist_body.html $template->assign_block_vars('forumrow', array('S_IS_CAT' => false, 'S_NO_CAT' => false, 'S_IS_LINK' => false, 'S_UNREAD_FORUM' => true, 'S_LOCKED_FORUM' => false, 'S_SUBFORUMS' => false, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['topic_title'], 'FORUM_DESC' => $user->lang['POST_BY_AUTHOR'] . ' ' . get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']) . ' ' . $user->lang['POSTED_ON_DATE'] . ' ' . $first_post_time, 'TOPICS' => $row['topic_replies'], 'POSTS' => $row['topic_views'], 'FORUM_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'LAST_POST_SUBJECT' => censor_text($last_post_subject), 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POSTER_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']), 'U_LAST_POSTER' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST' => $last_post_url, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$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' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '')); } $db->sql_freeresult($result); } return; }
/** * MCP Forum View */ function mcp_forum_view($id, $mode, $action, $forum_info) { global $template, $db, $user, $auth, $cache, $module; global $phpEx, $phpbb_root_path, $config; $user->add_lang(array('viewtopic', 'viewforum')); include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx; // merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action $merge_select = $action == 'merge_select' || $action == 'merge_topic' || $action == 'merge_topics' ? true : false; if ($merge_select) { // Fixes a "bug" that makes forum_view use the same ordering as topic_view unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']); } $forum_id = $forum_info['forum_id']; $start = request_var('start', 0); $topic_id_list = request_var('topic_id_list', array(0)); $post_id_list = request_var('post_id_list', array(0)); $source_topic_ids = array(request_var('t', 0)); $to_topic_id = request_var('to_topic_id', 0); $url_extra = ''; $url_extra .= $forum_id ? "&f={$forum_id}" : ''; $url_extra .= $GLOBALS['topic_id'] ? '&t=' . $GLOBALS['topic_id'] : ''; $url_extra .= $GLOBALS['post_id'] ? '&p=' . $GLOBALS['post_id'] : ''; $url_extra .= $GLOBALS['user_id'] ? '&u=' . $GLOBALS['user_id'] : ''; $url = append_sid("{$phpbb_root_path}mcp.{$phpEx}?{$url_extra}"); // Resync Topics switch ($action) { case 'resync': $topic_ids = request_var('topic_id_list', array(0)); mcp_resync_topics($topic_ids); break; case 'merge_topics': $source_topic_ids = $topic_id_list; case 'merge_topic': if ($to_topic_id) { merge_topics($forum_id, $source_topic_ids, $to_topic_id); } break; } $selected_ids = ''; if (sizeof($post_id_list) && $action != 'merge_topics') { foreach ($post_id_list as $num => $post_id) { $selected_ids .= '&post_id_list[' . $num . ']=' . $post_id; } } else { if (sizeof($topic_id_list) && $action == 'merge_topics') { foreach ($topic_id_list as $num => $topic_id) { $selected_ids .= '&topic_id_list[' . $num . ']=' . $topic_id; } } } make_jumpbox($url . "&i={$id}&action={$action}&mode={$mode}" . ($merge_select ? $selected_ids : ''), $forum_id, false, 'm_', true); $topics_per_page = $forum_info['forum_topics_per_page'] ? $forum_info['forum_topics_per_page'] : $config['topics_per_page']; $sort_days = $total = 0; $sort_key = $sort_dir = ''; $sort_by_sql = $sort_order_sql = array(); mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id); $forum_topics = $total == -1 ? $forum_info['forum_topics'] : $total; $limit_time_sql = $sort_days ? 'AND t.topic_last_post_time >= ' . (time() - $sort_days * 86400) : ''; $template->assign_vars(array('ACTION' => $action, 'FORUM_NAME' => $forum_info['forum_name'], 'FORUM_DESCRIPTION' => generate_text_for_display($forum_info['forum_desc'], $forum_info['forum_desc_uid'], $forum_info['forum_desc_bitfield'], $forum_info['forum_desc_options']), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id), 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id), 'S_CAN_MERGE' => $auth->acl_get('m_merge', $forum_id), 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id), 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id), 'S_CAN_LOCK' => $auth->acl_get('m_lock', $forum_id), 'S_CAN_SYNC' => $auth->acl_get('m_', $forum_id), 'S_CAN_APPROVE' => $auth->acl_get('m_approve', $forum_id), 'S_MERGE_SELECT' => $merge_select ? true : false, 'S_CAN_MAKE_NORMAL' => $auth->acl_gets('f_sticky', 'f_announce', $forum_id), 'S_CAN_MAKE_STICKY' => $auth->acl_get('f_sticky', $forum_id), 'S_CAN_MAKE_ANNOUNCE' => $auth->acl_get('f_announce', $forum_id), 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id), 'U_VIEW_FORUM_LOGS' => $auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=logs&mode=forum_logs&f=' . $forum_id) : '', 'S_MCP_ACTION' => $url . "&i={$id}&forum_action={$action}&mode={$mode}&start={$start}" . ($merge_select ? $selected_ids : ''), 'PAGINATION' => generate_pagination($url . "&i={$id}&action={$action}&mode={$mode}&sd={$sort_dir}&sk={$sort_key}&st={$sort_days}" . ($merge_select ? $selected_ids : ''), $forum_topics, $topics_per_page, $start), 'PAGE_NUMBER' => on_page($forum_topics, $topics_per_page, $start), 'TOTAL_TOPICS' => $forum_topics == 1 ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $forum_topics))); // Grab icons $icons = $cache->obtain_icons(); $topic_rows = array(); if ($config['load_db_lastread']) { $read_tracking_join = ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')'; $read_tracking_select = ', tt.mark_time'; } else { $read_tracking_join = $read_tracking_select = ''; } $sql = "SELECT t.topic_id\n\t\tFROM " . TOPICS_TABLE . " t\n\t\tWHERE t.forum_id IN({$forum_id}, 0)\n\t\t\t" . ($auth->acl_get('m_approve', $forum_id) ? '' : 'AND t.topic_approved = 1') . "\n\t\t\t{$limit_time_sql}\n\t\tORDER BY t.topic_type DESC, {$sort_order_sql}"; $result = $db->sql_query_limit($sql, $topics_per_page, $start); $topic_list = $topic_tracking_info = array(); while ($row = $db->sql_fetchrow($result)) { $topic_list[] = $row['topic_id']; } $db->sql_freeresult($result); $sql = "SELECT t.*{$read_tracking_select}\n\t\tFROM " . TOPICS_TABLE . " t {$read_tracking_join}\n\t\tWHERE " . $db->sql_in_set('t.topic_id', $topic_list, false, true); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $topic_rows[$row['topic_id']] = $row; } $db->sql_freeresult($result); // If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync if (!sizeof($topic_list) && $forum_topics && $start > 0) { redirect($url . "&i={$id}&action={$action}&mode={$mode}"); } // Get topic tracking info if (sizeof($topic_list)) { if ($config['load_db_lastread']) { $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']), array()); } else { $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, array()); } } foreach ($topic_list as $topic_id) { $topic_title = ''; $row =& $topic_rows[$topic_id]; $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; if ($row['topic_status'] == ITEM_MOVED) { $unread_topic = false; } else { $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $topic_title = censor_text($row['topic_title']); $topic_unapproved = !$row['topic_approved'] && $auth->acl_get('m_approve', $row['forum_id']) ? true : false; $posts_unapproved = $row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $row['forum_id']) ? true : false; $u_mcp_queue = $topic_unapproved || $posts_unapproved ? $url . '&i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . '&t=' . $row['topic_id'] : ''; $topic_row = array('SOLVED_TOPIC' => $row['topic_solved'] && $row['topic_type'] != POST_GLOBAL ? $forum_info['forum_solve_text'] ? $forum_info['forum_solve_text'] : $user->img('icon_topic_solved_list', 'TOPIC_SOLVED') : '', 'U_SOLVED_TOPIC' => $row['topic_solved'] ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'p=' . $row['topic_solved'] . '#p' . $row['topic_solved']) : '', 'SOLVED_STYLE' => $forum_info['forum_solve_color'] ? ' style="color: #' . $forum_info['forum_solve_color'] . '"' : '', 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), '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'] : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'TOPIC_TYPE' => $topic_type, 'TOPIC_TITLE' => $topic_title, 'REPLIES' => $auth->acl_get('m_approve', $row['forum_id']) ? $row['topic_replies_real'] : $row['topic_replies'], 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && empty($row['topic_moved_id']) && $auth->acl_get('m_report', $row['forum_id']) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_UNREAD_TOPIC' => $unread_topic); if ($row['topic_status'] == ITEM_MOVED) { $topic_row = array_merge($topic_row, array('U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_moved_id']}"), 'U_DELETE_TOPIC' => $auth->acl_get('m_delete', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&f={$forum_id}&topic_id_list[]={$row['topic_id']}&mode=forum_view&action=delete_topic") : '', 'S_MOVED_TOPIC' => true, 'TOPIC_ID' => $row['topic_moved_id'])); } else { if ($action == 'merge_topic' || $action == 'merge_topics') { $u_select_topic = $url . "&i={$id}&mode=forum_view&action={$action}&to_topic_id=" . $row['topic_id'] . $selected_ids; } else { $u_select_topic = $url . "&i={$id}&mode=topic_view&action=merge&to_topic_id=" . $row['topic_id'] . $selected_ids; } $topic_row = array_merge($topic_row, array('U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&f={$forum_id}&t={$row['topic_id']}&mode=topic_view"), 'S_SELECT_TOPIC' => $merge_select && !in_array($row['topic_id'], $source_topic_ids) ? true : false, 'U_SELECT_TOPIC' => $u_select_topic, 'U_MCP_QUEUE' => $u_mcp_queue, 'U_MCP_REPORT' => $auth->acl_get('m_report', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&mode=topic_view&t=' . $row['topic_id'] . '&action=reports') : '', 'TOPIC_ID' => $row['topic_id'], 'S_TOPIC_CHECKED' => $topic_id_list && in_array($row['topic_id'], $topic_id_list) ? true : false)); } $template->assign_block_vars('topicrow', $topic_row); } unset($topic_rows); }
$sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_sig, u.user_sig_bbcode_uid FROM ' . FORUMS_TABLE . ' f, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p \n\t\t\t\tWHERE {$sql_where} \n\t\t\t\t\tAND f.forum_id = p.forum_id\n\t\t\t\t\tAND p.topic_id = t.topic_id\n\t\t\t\t\tAND p.poster_id = u.user_id"; } else { $sql = 'SELECT t.*, f.forum_id, f.forum_name FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f \n\t\t\t\tWHERE {$sql_where} \n\t\t\t\t\tAND f.forum_id = t.forum_id"; } $sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC') . " LIMIT {$start}, {$per_page}"; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $forum_id = $row['forum_id']; $topic_id = $row['topic_id']; $view_topic_url = "Forums&file=viewtopic&f={$forum_id}&t={$topic_id}&hilit={$u_hilit}"; if ($show_results == 'topics') { $replies = $_CLASS['auth']->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, time(), time(), $folder_img, $folder_alt, $topic_type); $tpl_ary = array('TOPIC_AUTHOR' => topic_topic_author($row), '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' => topic_generate_pagination($replies, $view_topic_url), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TYPE' => $topic_type, 'LAST_POST_IMG' => $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST'), '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' => $_CLASS['auth']->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $_CLASS['core_user']->img('icon_attach', $_CLASS['core_user']->lang['TOTAL_ATTACHMENTS']) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => !empty($row['mark_type']) ? true : false, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $_CLASS['auth']->acl_gets('m_', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => !$row['topic_approved'] && $_CLASS['auth']->acl_gets('m_approve', $forum_id) ? true : false, 'S_IGNORE_POST' => false, 'U_LAST_POST' => generate_link($view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'], false), 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id'] ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_MCP_REPORT' => generate_link('Forums&file=mcp&mode=reports&t=' . $topic_id), 'U_MCP_QUEUE' => generate_link('Forums&file=mcp&i=queue&mode=approve_details&t=' . $topic_id)); } else { if (isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe']) && (!$view || $view != 'show' || $post_id != $row['post_id'])) { $_CLASS['core_template']->assign_vars_array('searchresults', array('S_IGNORE_POST' => true, 'L_IGNORE_POST' => sprintf($_CLASS['core_user']->lang['POST_BY_FOE'], $row['username'], '<a href="' . generate_link("Forums&file=search&search_session_id={$search_session_id}&{$u_sort_param}&p=" . $row['post_id'] . '&view=show#' . $row['post_id']) . '">', '</a>'))); continue; } if ($row['enable_html']) { $row['post_text'] = preg_replace('#(<!\\-\\- h \\-\\-><)([\\/]?.*?)(><!\\-\\- h \\-\\->)#is', "<\\2>", $row['post_text']); } $row['post_text'] = censor_text($row['post_text']); decode_message($row['post_text'], $row['bbcode_uid']); if ($return_chars) { $row['post_text'] = strlen($row['post_text']) < $return_chars + 3 ? $row['post_text'] : substr($row['post_text'], 0, $return_chars) . '...'; } if ($hilit) {
$row =& $rowset[$topic_id]; $topic_forum_id = $row['forum_id'] ? (int) $row['forum_id'] : $forum_id; // This will allow the style designer to output a different header // or even separate the list of announcements from sticky and normal topics $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0; // Replies $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $topic_forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED) { $topic_id = $row['topic_moved_id']; $unread_topic = false; } else { $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); // Generate all the URIs ... $view_topic_url_params = 'f=' . $row['forum_id'] . '&t=' . $topic_id; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params); $topic_unapproved = ($row['topic_visibility'] == ITEM_UNAPPROVED || $row['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $row['forum_id']); $posts_unapproved = $row['topic_visibility'] == ITEM_APPROVED && $row['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row['forum_id']); $topic_deleted = $row['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&t={$topic_id}", true, $user->session_id) : ''; $u_mcp_queue = !$u_mcp_queue && $topic_deleted ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&mode=deleted_topics&t=' . $topic_id, true, $user->session_id) : $u_mcp_queue; // Send vars to template $topic_row = array('FORUM_ID' => $row['forum_id'], 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'FORUM_NAME' => isset($row['forum_name']) ? $row['forum_name'] : $forum_data['forum_name'], 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$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' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id']) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_TOPIC_DELETED' => $topic_deleted, 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params . '&view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']), 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&mode=reports&f=' . $row['forum_id'] . '&t=' . $topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test); /** * Modify the topic data before it is assigned to the template * * @event core.viewforum_modify_topicrow * @var array row Array with topic data
function main($id, $mode) { global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; switch ($mode) { case 'front': $user->add_lang('memberlist'); $sql_from = TOPICS_TABLE . ' t '; $sql_select = ''; if ($config['load_db_track']) { $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id'] . ')'; $sql_select .= ', tp.topic_posted'; } if ($config['load_db_lastread']) { $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')'; $sql_select .= ', tt.mark_time'; } $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT']; $folder = 'folder_announce'; $folder_new = $folder . '_new'; // Get cleaned up list... return only those forums not having the f_read permission $forum_ary = $auth->acl_getf('!f_read', true); $forum_ary = array_unique(array_keys($forum_ary)); // Determine first forum the user is able to read into - for global announcement link $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST; if (sizeof($forum_ary)) { $sql .= ' AND forum_id NOT IN ( ' . implode(', ', $forum_ary) . ')'; } $result = $db->sql_query_limit($sql, 1); $g_forum_id = (int) $db->sql_fetchfield('forum_id'); $db->sql_freeresult($result); $sql = "SELECT t.* {$sql_select} \n\t\t\t\t\tFROM {$sql_from}\n\t\t\t\t\tWHERE t.forum_id = 0\n\t\t\t\t\t\tAND t.topic_type = " . POST_GLOBAL . ' ORDER BY t.topic_last_post_time DESC'; $result = $db->sql_query($sql); $topic_list = $rowset = array(); while ($row = $db->sql_fetchrow($result)) { $topic_list[] = $row['topic_id']; $rowset[$row['topic_id']] = $row; } $db->sql_freeresult($result); $topic_tracking_info = array(); if ($config['load_db_lastread']) { $topic_tracking_info = get_topic_tracking(0, $topic_list, $rowset, false, $topic_list); } else { $topic_tracking_info = get_complete_topic_tracking(0, $topic_list, $topic_list); } foreach ($topic_list as $topic_id) { $row =& $rowset[$topic_id]; $forum_id = $row['forum_id']; $topic_id = $row['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; if ($row['topic_status'] == ITEM_LOCKED) { $topic_type = $user->lang['VIEW_TOPIC_LOCKED']; $folder = 'folder_locked'; $folder_new = 'folder_locked_new'; } $folder_img = $unread_topic ? $folder_new : $folder; $folder_alt = $unread_topic ? 'NEW_POSTS' : ($row['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Posted image? if (!empty($row['topic_posted']) && $row['topic_posted']) { $folder_img .= '_posted'; } $template->assign_block_vars('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_POST_AUTHOR' => $row['topic_last_poster_id'] == ANONYMOUS ? $row['topic_last_poster_name'] != '' ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ' : $row['topic_last_poster_name'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $user->img('icon_post_newest', 'VIEW_NEWEST_POST'), 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'ATTACH_ICON_IMG' => $auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_attach', '') : '', 'S_USER_POSTED' => !empty($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD' => $unread_topic, 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$g_forum_id}&t={$topic_id}&p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$g_forum_id}&t={$topic_id}&view=unread") . '#unread', 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$g_forum_id}&t={$topic_id}"))); } if ($config['load_user_activity']) { if (!function_exists('display_user_activity')) { include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx; } display_user_activity($user->data); } // Do the relevant calculations $memberdays = max(1, round((time() - $user->data['user_regdate']) / 86400)); $posts_per_day = $user->data['user_posts'] / $memberdays; $percentage = $config['num_posts'] ? min(100, $user->data['user_posts'] / $config['num_posts'] * 100) : 0; $template->assign_vars(array('USER_COLOR' => !empty($user->data['user_colour']) ? $user->data['user_colour'] : '', 'JOINED' => $user->format_date($user->data['user_regdate']), 'VISITED' => empty($last_visit) ? ' - ' : $user->format_date($last_visit), 'WARNINGS' => $user->data['user_warnings'] ? $user->data['user_warnings'] : 0, 'POSTS' => $user->data['user_posts'] ? $user->data['user_posts'] : 0, 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day), 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage), 'OCCUPATION' => !empty($row['user_occ']) ? $row['user_occ'] : '', 'INTERESTS' => !empty($row['user_interests']) ? $row['user_interests'] : '', 'S_SHOW_ACTIVITY' => $config['load_user_activity'] ? true : false, 'U_SEARCH_USER' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", 'author_id=' . $user->data['user_id'] . '&sr=posts') : '')); break; case 'subscribed': include $phpbb_root_path . 'includes/functions_display.' . $phpEx; $user->add_lang('viewforum'); $unwatch = isset($_POST['unwatch']) ? true : false; if ($unwatch) { $forums = isset($_POST['f']) ? implode(', ', array_map('intval', array_keys($_POST['f']))) : false; $topics = isset($_POST['t']) ? implode(', ', array_map('intval', array_keys($_POST['t']))) : false; if ($forums || $topics) { $l_unwatch = ''; if ($forums) { $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id IN ({$forums}) \n\t\t\t\t\t\t\t\t\tAND user_id = " . $user->data['user_id']; $db->sql_query($sql); $l_unwatch .= '_FORUMS'; } if ($topics) { $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . "\n\t\t\t\t\t\t\t\tWHERE topic_id IN ({$topics}) \n\t\t\t\t\t\t\t\t\tAND user_id = " . $user->data['user_id']; $db->sql_query($sql); $l_unwatch .= '_TOPICS'; } $message = $user->lang['UNWATCHED' . $l_unwatch] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&mode=subscribed") . '">', '</a>'); meta_refresh(3, append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&mode=subscribed")); trigger_error($message); } } $sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_WATCH_TABLE => 'fw', FORUMS_TABLE => 'f'), 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . ' AND f.forum_id = fw.forum_id', 'ORDER_BY' => 'left_id'); if ($config['load_db_lastread']) { $sql_array['LEFT_JOIN'] = array(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 { $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(); } $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $forum_id = $row['forum_id']; if ($config['load_db_lastread']) { $forum_check = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark']; } else { $forum_check = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark']; } $unread_forum = $row['forum_last_post_time'] > $forum_check ? true : false; // Which folder should we display? if ($row['forum_status'] == ITEM_LOCKED) { $folder_image = $unread_forum ? 'folder_locked_new' : 'folder_locked'; $folder_alt = 'FORUM_LOCKED'; } else { $folder_image = $unread_forum ? 'folder_new' : 'folder'; $folder_alt = $unread_forum ? '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&u=' . $row['forum_last_poster_id']); $last_post_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&p=" . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id']; } else { $last_post_time = $last_poster = $last_poster_url = $last_post_url = ''; } $template->assign_block_vars('forumrow', array('FORUM_ID' => $forum_id, 'FORUM_FOLDER_IMG' => $user->img($folder_image, $folder_alt), 'FORUM_FOLDER_IMG_SRC' => $user->img($folder_image, $folder_alt, false, '', 'src'), 'FORUM_NAME' => $row['forum_name'], 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), 'LAST_POST_TIME' => $last_post_time, 'LAST_POST_AUTHOR' => $last_poster, 'U_LAST_POST_AUTHOR' => $last_poster_url, 'U_LAST_POST' => $last_post_url, 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']))); } $db->sql_freeresult($result); // Subscribed Topics $start = request_var('start', 0); $sql = 'SELECT COUNT(topic_id) as topics_count FROM ' . TOPICS_WATCH_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $topics_count = (int) $db->sql_fetchfield('topics_count'); $db->sql_freeresult($result); if ($topics_count) { $template->assign_vars(array('PAGINATION' => generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => $topics_count == 1 ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))); } $sql_array = array('SELECT' => 't.*', 'FROM' => array(TOPICS_WATCH_TABLE => 'tw', TOPICS_TABLE => 't'), 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id', 'ORDER_BY' => 't.topic_last_post_time DESC'); if ($config['load_db_lastread']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']); $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']); $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time'; } if ($config['load_db_track']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']); $sql_array['SELECT'] .= ', tp.topic_posted'; } $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $topic_list = $topic_forum_list = $global_announce_list = $rowset = array(); while ($row = $db->sql_fetchrow($result)) { $topic_list[] = $row['topic_id']; $rowset[$row['topic_id']] = $row; $topic_forum_list[$row['forum_id']]['forum_mark_time'] = $config['load_db_lastread'] ? $row['forum_mark_time'] : 0; $topic_forum_list[$row['forum_id']]['topics'][] = $row['topic_id']; if ($row['topic_type'] == POST_GLOBAL) { $global_announce_list[] = $row['topic_id']; } } $db->sql_freeresult($result); $topic_tracking_info = array(); if ($config['load_db_lastread']) { foreach ($topic_forum_list as $f_id => $topic_row) { $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), $f_id == 0 ? $global_announce_list : false); } } else { foreach ($topic_forum_list as $f_id => $topic_row) { $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list); } } foreach ($topic_list as $topic_id) { $row =& $rowset[$topic_id]; $forum_id = $row['forum_id']; $topic_id = $row['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; // Replies $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; if ($row['topic_status'] == ITEM_MOVED) { $topic_id = $row['topic_moved_id']; } // Get folder img, topic status/type related informations $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&t={$topic_id}"); // Send vars to template $template->assign_block_vars('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR' => topic_topic_author($row), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => $row['topic_last_poster_name'] != '' ? $row['topic_last_poster_name'] : $user->lang['GUEST'], 'PAGINATION' => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . ($row['forum_id'] ? $row['forum_id'] : $forum_id) . "&t={$topic_id}")), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $user->img('icon_post_newest', 'VIEW_NEWEST_POST'), 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), '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' => $auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => !empty($row['topic_posted']) ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&t={$topic_id}&view=unread") . '#unread', 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id'] ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_VIEW_TOPIC' => $view_topic_url)); } break; case 'bookmarks': if (!$config['allow_bookmarks']) { $template->assign_vars(array('S_NO_DISPLAY_BOOKMARKS' => true)); break; } include $phpbb_root_path . 'includes/functions_display.' . $phpEx; $user->add_lang('viewforum'); $move_up = request_var('move_up', 0); $move_down = request_var('move_down', 0); $sql = 'SELECT MAX(order_id) as max_order_id FROM ' . BOOKMARKS_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $max_order_id = (int) $db->sql_fetchfield('max_order_id'); $db->sql_freeresult($result); if ($move_up || $move_down) { if ($move_up && $move_up != 1 || $move_down && $move_down != $max_order_id) { $order = $move_up ? $move_up : $move_down; $order_total = $order * 2 + ($move_up ? -1 : 1); $sql = 'UPDATE ' . BOOKMARKS_TABLE . "\n\t\t\t\t\t\t\tSET order_id = {$order_total} - order_id\n\t\t\t\t\t\t\tWHERE order_id IN ({$order}, " . ($move_up ? $order - 1 : $order + 1) . ') AND user_id = ' . $user->data['user_id']; $db->sql_query($sql); } } if (isset($_POST['unbookmark'])) { $s_hidden_fields = array('unbookmark' => 1); $topics = isset($_POST['t']) ? array_map('intval', array_keys($_POST['t'])) : array(); $url = $this->u_action; if (!sizeof($topics)) { trigger_error('NO_BOOKMARKS_SELECTED'); } foreach ($topics as $topic_id) { $s_hidden_fields['t'][$topic_id] = 1; } if (confirm_box(true)) { $sql = 'DELETE FROM ' . BOOKMARKS_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' AND topic_id IN (' . implode(', ', $topics) . ')'; $db->sql_query($sql); // Re-Order bookmarks (possible with one query? This query massaker is not really acceptable...) $sql = 'SELECT topic_id FROM ' . BOOKMARKS_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' ORDER BY order_id ASC'; $result = $db->sql_query($sql); $i = 1; while ($row = $db->sql_fetchrow($result)) { $sql = 'UPDATE ' . BOOKMARKS_TABLE . "\n\t\t\t\t\t\t\t\tSET order_id = {$i}\n\t\t\t\t\t\t\t\tWHERE topic_id = {$row['topic_id']}\n\t\t\t\t\t\t\t\t\tAND user_id = {$user->data['user_id']}"; $db->sql_query($sql); $i++; } $db->sql_freeresult($result); meta_refresh(3, $url); $message = $user->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>'); trigger_error($message); } else { confirm_box(false, 'REMOVE_SELECTED_BOOKMARKS', build_hidden_fields($s_hidden_fields)); } } // We grab deleted topics here too... // NOTE: At the moment bookmarks are not removed with topics, might be useful later (not really sure how though. :D) // But since bookmarks are sensible to the user, they should not be deleted without notice. $sql = 'SELECT b.order_id, b.topic_id as b_topic_id, t.*, f.forum_name FROM ' . BOOKMARKS_TABLE . ' b LEFT JOIN ' . TOPICS_TABLE . ' t ON (b.topic_id = t.topic_id) LEFT JOIN ' . FORUMS_TABLE . ' f ON (t.forum_id = f.forum_id) WHERE b.user_id = ' . $user->data['user_id'] . ' ORDER BY b.order_id ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $forum_id = $row['forum_id']; $topic_id = $row['b_topic_id']; $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; // Get folder img, topic status/type related informations $folder_img = $folder_alt = $topic_type = ''; $unread_topic = false; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&t={$topic_id}"); $template->assign_block_vars('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'FORUM_NAME' => $row['forum_name'], 'S_DELETED_TOPIC' => !$row['topic_id'] ? true : false, 'S_GLOBAL_TOPIC' => !$forum_id ? true : false, 'TOPIC_AUTHOR' => topic_topic_author($row), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => $row['topic_last_poster_name'] != '' ? $row['topic_last_poster_name'] : $user->lang['GUEST'], 'PAGINATION' => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . ($row['forum_id'] ? $row['forum_id'] : $forum_id) . "&t={$topic_id}")), 'POSTED_AT' => $user->format_date($row['topic_time']), 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'ATTACH_ICON_IMG' => $auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_attach', '') : '', 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id'] ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id), 'U_MOVE_UP' => $row['order_id'] != 1 ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=main&mode=bookmarks&move_up=' . $row['order_id']) : '', 'U_MOVE_DOWN' => $row['order_id'] != $max_order_id ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=main&mode=bookmarks&move_down=' . $row['order_id']) : '')); } break; case 'drafts': $pm_drafts = $this->p_master->p_name == 'pm' ? true : false; $template->assign_var('S_SHOW_DRAFTS', true); $user->add_lang('posting'); $edit = isset($_REQUEST['edit']) ? true : false; $submit = isset($_POST['submit']) ? true : false; $draft_id = $edit ? intval($_REQUEST['edit']) : 0; $delete = isset($_POST['delete']) ? true : false; $s_hidden_fields = $edit ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : ''; $draft_subject = $draft_message = ''; if ($delete) { $drafts = isset($_POST['d']) ? implode(', ', array_map('intval', array_keys($_POST['d']))) : ''; if ($drafts) { $sql = 'DELETE FROM ' . DRAFTS_TABLE . "\n\t\t\t\t\t\t\tWHERE draft_id IN ({$drafts}) \n\t\t\t\t\t\t\t\tAND user_id = " . $user->data['user_id']; $db->sql_query($sql); $message = $user->lang['DRAFTS_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); meta_refresh(3, $this->u_action); trigger_error($message); } } if ($submit && $edit) { $draft_subject = request_var('subject', '', true); $draft_message = request_var('message', '', true); if ($draft_message && $draft_subject) { $draft_row = array('draft_subject' => $draft_subject, 'draft_message' => $draft_message); $sql = 'UPDATE ' . DRAFTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $draft_row) . " \n\t\t\t\t\t\t\tWHERE draft_id = {$draft_id}\n\t\t\t\t\t\t\t\tAND user_id = " . $user->data['user_id']; $db->sql_query($sql); $message = $user->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); meta_refresh(3, $this->u_action); trigger_error($message); } else { $template->assign_var('ERROR', $draft_message == '' ? $user->lang['EMPTY_DRAFT'] : ($draft_subject == '' ? $user->lang['EMPTY_DRAFT_TITLE'] : '')); } } if (!$pm_drafts) { $sql = 'SELECT d.*, f.forum_name FROM ' . DRAFTS_TABLE . ' d, ' . FORUMS_TABLE . ' f WHERE d.user_id = ' . $user->data['user_id'] . ' ' . ($edit ? "AND d.draft_id = {$draft_id}" : '') . ' AND f.forum_id = d.forum_id ORDER BY d.save_time DESC'; } else { $sql = 'SELECT * FROM ' . DRAFTS_TABLE . ' WHERE user_id = ' . $user->data['user_id'] . ' ' . ($edit ? "AND draft_id = {$draft_id}" : '') . ' AND forum_id = 0 AND topic_id = 0 ORDER BY save_time DESC'; } $result = $db->sql_query($sql); $draftrows = $topic_ids = array(); while ($row = $db->sql_fetchrow($result)) { if ($row['topic_id']) { $topic_ids[] = (int) $row['topic_id']; } $draftrows[] = $row; } $db->sql_freeresult($result); if (sizeof($topic_ids)) { $sql = 'SELECT topic_id, forum_id, topic_title FROM ' . TOPICS_TABLE . ' WHERE topic_id IN (' . implode(',', array_unique($topic_ids)) . ')'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $topic_rows[$row['topic_id']] = $row; } $db->sql_freeresult($result); } unset($topic_ids); $template->assign_var('S_EDIT_DRAFT', $edit); $row_count = 0; foreach ($draftrows as $draft) { $link_topic = $link_forum = $link_pm = false; $insert_url = $view_url = $title = ''; if (isset($topic_rows[$draft['topic_id']]) && $auth->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id'])) { $link_topic = true; $view_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id']); $title = $topic_rows[$draft['topic_id']]['topic_title']; $insert_url = append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id'] . '&mode=reply&d=' . $draft['draft_id']); } else { if ($auth->acl_get('f_read', $draft['forum_id'])) { $link_forum = true; $view_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $draft['forum_id']); $title = $draft['forum_name']; $insert_url = append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']); } else { if ($pm_drafts) { $link_pm = true; $insert_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&mode=compose&d=" . $draft['draft_id']); } } } $template_row = array('DATE' => $user->format_date($draft['save_time']), 'DRAFT_MESSAGE' => $submit ? $draft_message : $draft['draft_message'], 'DRAFT_SUBJECT' => $submit ? $draft_subject : $draft['draft_subject'], 'TITLE' => $title, 'DRAFT_ID' => $draft['draft_id'], 'FORUM_ID' => $draft['forum_id'], 'TOPIC_ID' => $draft['topic_id'], 'U_VIEW' => $view_url, 'U_VIEW_EDIT' => $this->u_action . '&edit=' . $draft['draft_id'], 'U_INSERT' => $insert_url, 'S_LINK_TOPIC' => $link_topic, 'S_LINK_FORUM' => $link_forum, 'S_LINK_PM' => $link_pm, 'S_HIDDEN_FIELDS' => $s_hidden_fields); $row_count++; $edit ? $template->assign_vars($template_row) : $template->assign_block_vars('draftrow', $template_row); } if (!$edit) { $template->assign_var('S_DRAFT_ROWS', $row_count); } break; } $template->assign_vars(array('L_TITLE' => $user->lang['UCP_MAIN_' . strtoupper($mode)], 'S_DISPLAY_MARK_ALL' => $mode == 'watched' || $mode == 'drafts' && !isset($_GET['edit']) ? true : false, 'S_HIDDEN_FIELDS' => isset($s_hidden_fields) ? $s_hidden_fields : '', 'S_UCP_ACTION' => $this->u_action)); // Set desired template $this->tpl_name = 'ucp_main_' . $mode; $this->page_title = 'UCP_MAIN_' . strtoupper($mode); }
function ucp_main($id, $mode) { global $config, $_CLASS, $site_file_root, $_CORE_CONFIG; $_CLASS['core_template']->assign_array(array('ERROR' => false, 'topicrow' => false, 'WARNINGS' => false, 'draftrow' => false)); $_CLASS['core_user']->user_setup(); switch ($mode) { case 'front': $_CLASS['core_user']->add_lang(false, 'Members_List'); if ($config['load_db_lastread'] || $config['load_db_track']) { if ($config['load_db_lastread']) { $sql = 'SELECT mark_time FROM ' . FORUMS_TRACK_TABLE . ' WHERE forum_id = 0 AND user_id = ' . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query($sql); $track_data = $_CLASS['core_db']->fetch_row_assoc($result); $_CLASS['core_db']->free_result($result); } $sql_from = FORUMS_TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $_CLASS['core_user']->data['user_id'] . ')'; $sql_select = ', tt.mark_time'; } else { $sql_from = TOPICS_TABLE . ' t '; $sql_select = ''; } // Has to be in while loop if we not only check forum id 0 if ($config['load_db_lastread']) { $forum_check = $track_data['mark_time']; } else { $tracking_topics = isset($_COOKIE[$_CORE_CONFIG['server']['cookie_name'] . '_track']) ? unserialize(stripslashes($_COOKIE[$_CORE_CONFIG['server']['cookie_name'] . '_track'])) : array(); $forum_check = isset($tracking_topics[0][0]) ? base_convert($tracking_topics[0][0], 36, 10) + $config['board_startdate'] : 0; } $topic_type = $_CLASS['core_user']->lang['VIEW_TOPIC_ANNOUNCEMENT']; $folder = 'folder_announce'; $folder_new = $folder . '_new'; $sql = "SELECT t.* {$sql_select} \n\t\t\t\t\tFROM {$sql_from}\n\t\t\t\t\tWHERE t.forum_id = 0\n\t\t\t\t\t\tAND t.topic_type = " . POST_GLOBAL . ' ORDER BY t.topic_last_post_time DESC'; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $forum_id = $row['forum_id']; $topic_id = $row['topic_id']; if ($row['topic_status'] == ITEM_LOCKED) { $topic_type = $_CLASS['core_user']->lang['VIEW_TOPIC_LOCKED']; $folder = 'folder_locked'; $folder_new = 'folder_locked_new'; } $unread_topic = true; if ($config['load_db_lastread']) { $topic_check = $row['mark_time']; } else { $topic_id36 = base_convert($topic_id, 10, 36); $topic_check = isset($tracking_topics[0][$topic_id36]) ? base_convert($tracking_topics[0][$topic_id36], 36, 10) + $config['board_startdate'] : 0; } if ($topic_check >= $row['topic_last_post_time'] || $forum_check >= $row['topic_last_post_time']) { $unread_topic = false; } $newest_post_img = $unread_topic ? '<a href="' . generate_link("Forums&file=viewtopic&t={$topic_id}&view=unread#unread") . '">' . $_CLASS['core_user']->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : ''; $folder_img = $unread_topic ? $folder_new : $folder; $folder_alt = $unread_topic ? 'NEW_POSTS' : ($row['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Posted image? $view_topic_url = generate_link("Forums&file=viewtopic&&t={$topic_id}"); $last_post_img = '<a href="' . generate_link("Forums&file=viewtopic&t={$topic_id}&p=" . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id']) . '">' . $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST') . '</a>'; $_CLASS['core_template']->assign_vars_array('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'GOTO_PAGE' => '', 'LAST_POST_TIME' => $_CLASS['core_user']->format_date($row['topic_last_post_time']), 'LAST_POST_AUTHOR' => $row['topic_last_poster_name'] ? $row['topic_last_poster_name'] : $_CLASS['core_user']->lang['GUEST'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'LAST_POST_IMG' => $last_post_img, 'NEWEST_POST_IMG' => $newest_post_img, 'TOPIC_FOLDER_IMG' => $_CLASS['core_user']->img($folder_img, $folder_alt), 'ATTACH_ICON_IMG' => $_CLASS['auth']->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $_CLASS['core_user']->img('icon_attach', '') : '', 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : false, 'U_VIEW_TOPIC' => $view_topic_url)); } $_CLASS['core_db']->free_result($result); $num_real_posts = $_CLASS['core_user']->data['user_posts']; $active_f_row = $active_t_row = array(); // Do the relevant calculations $memberdays = max(1, round(($_CLASS['core_user']->time - $_CLASS['core_user']->data['user_reg_date']) / 86400)); $posts_per_day = $_CLASS['core_user']->data['user_posts'] / $memberdays; $percentage = $config['num_posts'] ? min(100, $num_real_posts / $config['num_posts'] * 100) : 0; $active_f_name = $active_f_id = $active_f_count = $active_f_pct = ''; if (!empty($active_f_row['num_posts'])) { $active_f_name = $active_f_row['forum_name']; $active_f_id = $active_f_row['forum_id']; $active_f_count = $active_f_row['num_posts']; $active_f_pct = $_CLASS['core_user']->data['user_posts'] ? $active_f_count / $_CLASS['core_user']->data['user_posts'] * 100 : 0; } unset($active_f_row); $active_t_name = $active_t_id = $active_t_count = $active_t_pct = ''; if (!empty($active_t_row['num_posts'])) { $active_t_name = $active_t_row['topic_title']; $active_t_id = $active_t_row['topic_id']; $active_t_count = $active_t_row['num_posts']; $active_t_pct = $_CLASS['core_user']->data['user_posts'] ? $active_t_count / $_CLASS['core_user']->data['user_posts'] * 100 : 0; } unset($active_t_row); $_CLASS['core_template']->assign_array(array('USER_COLOR' => !empty($_CLASS['core_user']->data['user_colour']) ? $_CLASS['core_user']->data['user_colour'] : '', 'JOINED' => $_CLASS['core_user']->format_date($_CLASS['core_user']->data['user_reg_date']), 'VISITED' => empty($_CLASS['core_user']->data['user_lastvisit']) ? ' - ' : $_CLASS['core_user']->format_date($_CLASS['core_user']->data['user_lastvisit']), 'POSTS' => $_CLASS['core_user']->data['user_posts'] ? $_CLASS['core_user']->data['user_posts'] : 0, 'POSTS_DAY' => sprintf($_CLASS['core_user']->lang['POST_DAY'], $posts_per_day), 'POSTS_PCT' => sprintf($_CLASS['core_user']->lang['POST_PCT'], $percentage), 'ACTIVE_FORUM' => $active_f_name, 'ACTIVE_FORUM_POSTS' => $active_f_count == 1 ? sprintf($_CLASS['core_user']->lang['USER_POST'], 1) : sprintf($_CLASS['core_user']->lang['USER_POSTS'], $active_f_count), 'ACTIVE_FORUM_PCT' => sprintf($_CLASS['core_user']->lang['POST_PCT'], $active_f_pct), 'ACTIVE_TOPIC' => $active_t_name, 'ACTIVE_TOPIC_POSTS' => $active_t_count == 1 ? sprintf($_CLASS['core_user']->lang['USER_POST'], 1) : sprintf($_CLASS['core_user']->lang['USER_POSTS'], $active_t_count), 'ACTIVE_TOPIC_PCT' => sprintf($_CLASS['core_user']->lang['POST_PCT'], $active_t_pct), 'OCCUPATION' => !empty($row['user_occ']) ? $row['user_occ'] : '', 'INTERESTS' => !empty($row['user_interests']) ? $row['user_interests'] : '', 'U_SEARCH_USER' => $_CLASS['auth']->acl_get('u_search') ? generate_link('Forums&file=search&search_author=' . urlencode($_CLASS['core_user']->data['username']) . "&show_results=posts") : '', 'U_ACTIVE_FORUM' => generate_link('Forums&file=viewforum&f=' . $active_f_id), 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : false, 'U_ACTIVE_TOPIC' => generate_link('Forums&file=viewtopic&t=' . $active_t_id))); break; case 'subscribed': require $site_file_root . 'includes/forums/functions_display.php'; $unwatch = isset($_POST['unwatch']); if ($unwatch) { $forums = array_unique(get_variable('f', 'POST', array(), 'array:int')); $topics = array_unique(get_variable('t', 'POST', array(), 'array:int')); if (!empty($forums) || !empty($topics)) { $l_unwatch = ''; if (!empty($forums)) { $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . ' WHERE forum_id IN (' . implode(', ', $forums) . ') AND topic_id = 0 AND user_id = ' . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $l_unwatch .= '_FORUMS'; } if (!empty($topics)) { $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . ' WHERE topic_id IN (' . implode(', ', $topics) . ') AND user_id = ' . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $l_unwatch .= '_TOPICS'; } $message = $_CLASS['core_user']->lang['UNWATCHED' . $l_unwatch] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . generate_link("Control_Panel&i={$id}&mode=subscribed") . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, generate_link("Control_Panel&i={$id}&mode=subscribed")); trigger_error($message); } } if ($config['load_db_lastread']) { $sql_from = FORUMS_FORUMS_TABLE . ' f 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 = FORUMS_FORUMS_TABLE . ' f '; $lastread_select = ''; $tracking = @unserialize(get_variable($_CORE_CONFIG['server']['cookie_name'] . '_track', 'COOKIE')); if (!is_array($tracking)) { $tracking = array(); } } $sql = "SELECT f.*{$lastread_select} \n\t\t\t\t\tFROM {$sql_from}, " . FORUMS_WATCH_TABLE . ' fw WHERE fw.user_id = ' . $_CLASS['core_user']->data['user_id'] . ' AND fw.topic_id = 0 AND f.forum_id = fw.forum_id ORDER BY left_id'; $result = $_CLASS['core_db']->query($sql); //$topics_count = $_CLASS['core_db']->num_rows($result); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $forum_id = (int) $row['forum_id']; $unread_forum = false; if ($config['load_db_lastread']) { $mark_time_forum = $row['mark_time']; } else { $forum_id36 = base_convert($forum_id, 10, 36); $mark_time_forum = isset($tracking[$forum_id36][0]) ? (int) base_convert($tracking[$forum_id36][0], 36, 10) : 0; } if ($mark_time_forum < $row['forum_last_post_time']) { $unread_forum = true; } // Which folder should we display? if ($row['forum_status'] == ITEM_LOCKED) { $folder_image = $unread_forum ? 'folder_locked_new' : 'folder_locked'; $folder_alt = 'FORUM_LOCKED'; } else { $folder_image = $unread_forum ? 'folder_new' : 'folder'; $folder_alt = $unread_forum ? 'NEW_POSTS' : 'NO_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&mode=viewprofile&u=' . $row['forum_last_poster_id']); $last_post_url = generate_link("Forums&file=viewtopic&f={$forum_id}&p=" . $row['forum_last_post_id'] . '#' . $row['forum_last_post_id']); } else { $last_post_time = $last_poster = $last_poster_url = $last_post_url = ''; } $_CLASS['core_template']->assign_vars_array('forumrow', array('FORUM_ID' => $forum_id, 'FORUM_FOLDER_IMG' => $_CLASS['core_user']->img($folder_image, $folder_alt), 'FORUM_NAME' => $row['forum_name'], 'LAST_POST_IMG' => $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST'), 'LAST_POST_TIME' => $last_post_time, 'LAST_POST_AUTHOR' => $last_poster, 'U_LAST_POST_AUTHOR' => $last_poster_url, 'U_LAST_POST' => $last_post_url, 'U_VIEWFORUM' => generate_link('Forums&file=viewforum&f=' . $row['forum_id']))); } $_CLASS['core_db']->free_result($result); // Subscribed Topics $start = get_variable('start', 'REQUEST', 0, 'int'); if ($config['load_db_lastread']) { $sql_from = FORUMS_TOPICS_TABLE . ' t LEFT JOIN ' . FORUMS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $_CLASS['core_user']->data['user_id'] . ')'; $sql_t_select = ', tt.mark_time'; } else { $sql_from = FORUMS_TOPICS_TABLE . ' t'; $sql_t_select = ''; } $sql = "SELECT t.* {$sql_t_select} \n\t\t\t\t\tFROM " . FORUMS_WATCH_TABLE . " tw, {$sql_from} \n\t\t\t\t\tWHERE tw.user_id = " . $_CLASS['core_user']->data['user_id'] . ' AND t.topic_id = tw.topic_id ORDER BY t.topic_last_post_time DESC'; $result = $_CLASS['core_db']->query_limit($sql, $config['topics_per_page'], $start); $topics_count = $_CLASS['core_db']->num_rows($result); if ($topics_count) { $pagination = generate_pagination("Control_Panel&i={$id}&mode={$mode}", $topics_count, $config['topics_per_page'], $start); $_CLASS['core_template']->assign_array(array('PAGINATION' => $pagination['formated'], 'PAGINATION_ARRAY' => $pagination['array'], 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => $topics_count === 1 ? $_CLASS['core_user']->lang['VIEW_FORUM_TOPIC'] : sprintf($_CLASS['core_user']->lang['VIEW_FORUM_TOPICS'], $topics_count))); } else { $_CLASS['core_template']->assign('TOTAL_TOPICS', false); } while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $topic_id = $row['topic_id']; $forum_id = $row['forum_id']; if (!$config['load_db_lastread']) { $topic_id36 = base_convert($topic_id, 10, 36); $forum_id36 = $row['topic_type'] == POST_GLOBAL ? 0 : base_convert($forum_id, 10, 36); $mark_time_topic = isset($tracking[$forum_id36][$topic_id36]) ? (int) base_convert($tracking[$forum_id36][$topic_id36], 36, 10) : 0; $mark_time_forum = isset($tracking[$forum_id36][0]) ? (int) base_convert($tracking[$forum_id36][0], 36, 10) : 0; $row['mark_time'] = max($mark_time_topic, $mark_time_forum); } // Replies $replies = $_CLASS['auth']->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; if ($row['topic_status'] == ITEM_MOVED) { $topic_id = $row['topic_moved_id']; } // Get folder img, topic status/type related informations $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $row['mark_time'], $unread_topic, $folder_img, $folder_alt, $topic_type); $newest_post_img = $unread_topic ? '<a href="' . generate_link("Forums&file=viewtopic&f={$forum_id}&t={$topic_id}&view=unread#unread") . '">' . $_CLASS['core_user']->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : ''; $view_topic_url = 'Forums&file=viewtopic&t=' . $topic_id; $pagination = generate_pagination($view_topic_url, $replies, $config['topics_per_page'], 0); $_CLASS['core_template']->assign_vars_array('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_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&mode=viewprofile&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, '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']]) ? '' : '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />', 'ATTACH_ICON_IMG' => $_CLASS['auth']->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $_CLASS['core_user']->img('icon_attach', sprintf($_CLASS['core_user']->lang['TOTAL_ATTACHMENTS'], $row['topic_attachment'])) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_UNREAD_TOPIC' => $unread_topic, 'U_LAST_POST' => generate_link($view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id']), 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] && $row['topic_last_poster_id'] != ANONYMOUS ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_VIEW_TOPIC' => generate_link($view_topic_url))); } $_CLASS['core_db']->free_result($result); break; case 'bookmarks': require $site_file_root . 'includes/forums/functions_display.php'; $move_up = request_var('move_up', 0); $move_down = request_var('move_down', 0); $sql = 'SELECT MAX(order_id) as max_order_id FROM ' . FORUMS_BOOKMARKS_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query($sql); list($max_order_id) = $_CLASS['core_db']->fetch_row_num($result); $_CLASS['core_db']->free_result($result); if ($move_up || $move_down) { if ($move_up && $move_up != 1 || $move_down && $move_down != $max_order_id) { $order = $move_up ? $move_up : $move_down; $order_total = $order * 2 + ($move_up ? -1 : 1); $sql = 'UPDATE ' . FORUMS_BOOKMARKS_TABLE . "\n\t\t\t\t\t\t\tSET order_id = {$order_total} - order_id\n\t\t\t\t\t\t\tWHERE order_id IN ({$order}, " . ($move_up ? $order - 1 : $order + 1) . ') AND user_id = ' . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); } } if (isset($_POST['unbookmark'])) { $topics = array_unique(get_variable('t', 'POST', array(), 'array:int')); if (empty($topics)) { trigger_error('NO_BOOKMARKS_SELECTED'); } $hidden_fields = array('unbookmark' => 1, 't' => $topics); if (display_confirmation($_CLASS['core_user']->get_lang('REMOVE_SELECTED_BOOKMARKS'), generate_hidden_fields($hidden_fields))) { $sql = 'DELETE FROM ' . FORUMS_BOOKMARKS_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . ' AND topic_id IN (' . implode(', ', $topics) . ')'; $_CLASS['core_db']->query($sql); $sql = 'SELECT topic_id FROM ' . FORUMS_BOOKMARKS_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . ' ORDER BY order_id ASC'; $result = $_CLASS['core_db']->query($sql); $i = 1; while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $_CLASS['core_db']->query('UPDATE ' . FORUMS_BOOKMARKS_TABLE . "\n\t\t\t\t\t\t\t\tSET order_id = '{$i}'\n\t\t\t\t\t\t\t\tWHERE topic_id = '{$row['topic_id']}'\n\t\t\t\t\t\t\t\t\tAND user_id = '{$_CLASS['core_user']->data['user_id']}'"); $i++; } $_CLASS['core_db']->free_result($result); $url = generate_link('Control_Panel&i=main&mode=bookmarks'); $_CLASS['core_display']->meta_refresh(3, $url); $message = $_CLASS['core_user']->lang['BOOKMARKS_REMOVED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $url . '">', '</a>'); trigger_error($message); } } // We grab deleted topics here too... // NOTE: At the moment bookmarks are not removed with topics, might be useful later (not really sure how though. :D) // But since bookmarks are sensible to the user, they should not be deleted without notice. $sql = 'SELECT b.order_id, b.topic_id as b_topic_id, t.*, f.forum_name FROM ' . FORUMS_BOOKMARKS_TABLE . ' b LEFT JOIN ' . FORUMS_TOPICS_TABLE . ' t ON b.topic_id = t.topic_id LEFT JOIN ' . FORUMS_FORUMS_TABLE . ' f ON t.forum_id = f.forum_id WHERE b.user_id = ' . $_CLASS['core_user']->data['user_id'] . ' ORDER BY b.order_id ASC'; $result = $_CLASS['core_db']->query($sql); if (!($row = $_CLASS['core_db']->fetch_row_assoc($result))) { $_CLASS['core_db']->free_result($result); $_CLASS['core_template']->assign_array(array('S_BOOKMARKS' => false, 'S_BOOKMARKS_DISABLED' => false)); break; } $bookmarks = true; do { $forum_id = $row['forum_id']; $topic_id = $row['b_topic_id']; $bookmarks = true; $replies = $_CLASS['auth']->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; // Get folder img, topic status/type related informations $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $_CLASS['core_user']->time, $unread_topic, $folder_img, $folder_alt, $topic_type); $view_topic_url = "Forums&file=viewtopic&t={$topic_id}"; // $last_post_img = '<a href="'.generate_link("Forums&file=viewtopic&f=$forum_id&p=" . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id']) . '">' . $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST') . '</a>'; $pagination = generate_pagination('Forums&file=viewtopic&t=' . $topic_id, $replies, $config['posts_per_page'], 0); $_CLASS['core_template']->assign_vars_array('forummarks', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'S_DELETED_TOPIC' => !$row['topic_id'] ? true : false, 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'FORUM_NAME' => $row['forum_name'], 'TOPIC_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&mode=viewprofile&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'], 'LAST_POST_IMG' => $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST'), 'PAGINATION' => $pagination['formated'], 'PAGINATION_ARRAY' => $pagination['array'], 'POSTED_AT' => $_CLASS['core_user']->format_date($row['topic_time']), 'TOPIC_FOLDER_IMG' => $_CLASS['core_user']->img($folder_img, $folder_alt), 'ATTACH_ICON_IMG' => $_CLASS['auth']->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $_CLASS['core_user']->img('icon_attach', '') : '', 'U_VIEW_TOPIC' => generate_link($view_topic_url), 'U_VIEW_FORUM' => generate_link('Forums&file=viewforum&f=' . $forum_id), 'U_LAST_POST' => generate_link($view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id']), 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_MOVE_UP' => $row['order_id'] != 1 ? generate_link("Control_Panel&i=main&mode=bookmarks&move_up={$row['order_id']}") : '', 'U_MOVE_DOWN' => $row['order_id'] != $max_order_id ? generate_link("Control_Panel&i=main&mode=bookmarks&move_down={$row['order_id']}") : '')); } while ($row = $_CLASS['core_db']->fetch_row_assoc($result)); $_CLASS['core_db']->free_result($result); $_CLASS['core_template']->assign_array(array('S_BOOKMARKS' => $bookmarks, 'S_BOOKMARKS_DISABLED' => false)); break; case 'drafts': global $ucp; $pm_drafts = $ucp->name == 'pm' ? true : false; $_CLASS['core_user']->add_lang('posting', 'Forums'); $edit = isset($_REQUEST['edit']) ? true : false; $submit = isset($_POST['submit']) ? true : false; $draft_id = $edit ? intval($_REQUEST['edit']) : 0; $delete = isset($_POST['delete']) ? true : false; $s_hidden_fields = $edit ? '<input type="hidden" name="edit" value="' . $draft_id . '" />' : ''; $draft_subject = $draft_message = ''; if ($delete) { $drafts = isset($_POST['d']) ? implode(', ', array_map('intval', array_keys($_POST['d']))) : ''; if ($drafts) { $sql = 'DELETE FROM ' . FORUMS_DRAFTS_TABLE . "\n\t\t\t\t\t\t\tWHERE draft_id IN ({$drafts}) \n\t\t\t\t\t\t\t\tAND user_id = " . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $message = $_CLASS['core_user']->lang['DRAFTS_DELETED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . generate_link("Control_Panel&i={$id}&mode={$mode}") . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, generate_link("Control_Panel&i={$id}&mode={$mode}")); trigger_error($message); } } if ($submit && $edit) { $draft_subject = preg_replace('#&(\\#[0-9]+;)#', '&\\1', request_var('subject', '')); $draft_message = isset($_POST['message']) ? htmlspecialchars(trim(str_replace(array('\\\'', '\\"', '\\0', '\\\\'), array('\'', '"', '\\0', '\\'), $_POST['message']))) : ''; $draft_message = preg_replace('#&(\\#[0-9]+;)#', '&\\1', $draft_message); if ($draft_message && $draft_subject) { $draft_row = array('draft_subject' => $draft_subject, 'draft_message' => $draft_message); $sql = 'UPDATE ' . FORUMS_DRAFTS_TABLE . ' SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $draft_row) . " \n\t\t\t\t\t\t\tWHERE draft_id = {$draft_id}\n\t\t\t\t\t\t\t\tAND user_id = " . $_CLASS['core_user']->data['user_id']; $_CLASS['core_db']->query($sql); $message = $_CLASS['core_user']->lang['DRAFT_UPDATED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . generate_link("Control_Panel&i={$id}&mode={$mode}") . '">', '</a>'); $_CLASS['core_display']->meta_refresh(3, generate_link("Control_Panel&i={$id}&mode={$mode}")); trigger_error($message); } else { $_CLASS['core_template']->assign('ERROR', $draft_message == '' ? $_CLASS['core_user']->lang['EMPTY_DRAFT'] : ($draft_subject == '' ? $_CLASS['core_user']->lang['EMPTY_DRAFT_TITLE'] : '')); } } if (!$pm_drafts) { $sql = 'SELECT d.*, f.forum_name FROM ' . FORUMS_DRAFTS_TABLE . ' d, ' . FORUMS_FORUMS_TABLE . ' f WHERE d.user_id = ' . $_CLASS['core_user']->data['user_id'] . ' ' . ($edit ? "AND d.draft_id = {$draft_id}" : '') . ' AND f.forum_id = d.forum_id ORDER BY d.save_time DESC'; } else { $sql = 'SELECT * FROM ' . FORUMS_DRAFTS_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id'] . ' ' . ($edit ? "AND draft_id = {$draft_id}" : '') . ' AND forum_id = 0 AND topic_id = 0 ORDER BY save_time DESC'; } $result = $_CLASS['core_db']->query($sql); $draftrows = $topic_ids = array(); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { if ($row['topic_id']) { $topic_ids[] = (int) $row['topic_id']; } $draftrows[] = $row; } $_CLASS['core_db']->free_result($result); if (sizeof($topic_ids)) { $sql = 'SELECT topic_id, forum_id, topic_title FROM ' . FORUMS_TOPICS_TABLE . ' WHERE topic_id IN (' . implode(',', array_unique($topic_ids)) . ')'; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $topic_rows[$row['topic_id']] = $row; } $_CLASS['core_db']->free_result($result); } unset($topic_ids); $_CLASS['core_template']->assign('S_EDIT_DRAFT', $edit); foreach ($draftrows as $draft) { $link_topic = $link_forum = $link_pm = false; $insert_url = $view_url = $title = ''; if ($pm_drafts) { $link_pm = true; $insert_url = generate_link("Control_Panel&i={$id}&mode=compose&d=" . $draft['draft_id']); } else { if (isset($topic_rows[$draft['topic_id']]) && $_CLASS['auth']->acl_get('f_read', $topic_rows[$draft['topic_id']]['forum_id'])) { $link_topic = true; $view_url = generate_link('Forums&file=viewtopic&f=' . $topic_rows[$draft['topic_id']]['forum_id'] . "&t=" . $draft['topic_id']); $title = $topic_rows[$draft['topic_id']]['topic_title']; $insert_url = generate_link('Forums&file=posting&f=' . $topic_rows[$draft['topic_id']]['forum_id'] . '&t=' . $draft['topic_id'] . '&mode=reply&d=' . $draft['draft_id']); } else { if ($_CLASS['auth']->acl_get('f_read', $draft['forum_id'])) { $link_forum = true; $view_url = generate_link('Forums&file=viewforum&f=' . $draft['forum_id']); $title = $draft['forum_name']; $insert_url = generate_link('Forums&file=posting&f=' . $draft['forum_id'] . '&mode=post&d=' . $draft['draft_id']); } } } $template_row = array('DATE' => $_CLASS['core_user']->format_date($draft['save_time']), 'DRAFT_MESSAGE' => $submit ? $draft_message : $draft['draft_message'], 'DRAFT_SUBJECT' => $submit ? $draft_subject : $draft['draft_subject'], 'TITLE' => $title, 'DRAFT_ID' => $draft['draft_id'], 'FORUM_ID' => $draft['forum_id'], 'TOPIC_ID' => $draft['topic_id'], 'U_VIEW' => $view_url, 'U_VIEW_EDIT' => generate_link("Control_Panel&i={$id}&mode={$mode}&edit=" . $draft['draft_id']), 'U_INSERT' => $insert_url, 'S_LINK_TOPIC' => $link_topic, 'S_LINK_FORUM' => $link_forum, 'S_LINK_PM' => $link_pm, 'S_HIDDEN_FIELDS' => $s_hidden_fields); $edit ? $_CLASS['core_template']->assign_array($template_row) : $_CLASS['core_template']->assign_vars_array('draftrow', $template_row); } break; } $_CLASS['core_template']->assign_array(array('L_TITLE' => $_CLASS['core_user']->lang['UCP_MAIN_' . strtoupper($mode)], 'S_DISPLAY_MARK_ALL' => $mode == 'watched' || $mode == 'drafts' && !isset($_GET['edit']) ? true : false, 'S_HIDDEN_FIELDS' => isset($s_hidden_fields) ? $s_hidden_fields : '', 'S_DISPLAY_FORM' => true, 'S_UCP_ACTION' => generate_link("Control_Panel&i={$id}&mode={$mode}"))); $this->display($_CLASS['core_user']->lang['UCP_MAIN'], 'ucp_main_' . $mode . '.html'); }
/** * get related topic list * @param array $topic_data shuld at least provide with topic_id and topic_title * @param mixed $forum_id The forum id to search in (false / 0 / null to search into all forums) * */ function get($topic_data, $forum_id = false) { global $db, $auth, $cache, $template, $user, $phpEx, $phpbb_root_path, $topic_tracking_info, $config, $phpbb_seo; if (empty($config['seo_related'])) { return; } $related_result = false; $enable_icons = 0; $this->allforums = !$forum_id ? true : $this->allforums; $sql = $this->build_query($topic_data, $forum_id); if ($sql && ($result = $db->sql_query_limit($sql, $this->limit))) { // Grab icons $icons = $cache->obtain_icons(); $attachement_icon = $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']); $s_attachement = $auth->acl_get('u_download'); while ($row = $db->sql_fetchrow($result)) { $related_forum_id = (int) $row['forum_id']; $related_topic_id = (int) $row['topic_id']; $enable_icons = max($enable_icons, $row['enable_icons']); if ($auth->acl_get('f_list', $related_forum_id)) { $row['topic_title'] = censor_text($row['topic_title']); // www.phpBB-SEO.com SEO TOOLKIT BEGIN if (!empty($phpbb_seo->seo_opt['url_rewrite'])) { $phpbb_seo->set_url($row['forum_name'], $related_forum_id, $phpbb_seo->seo_static['forum']); $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$related_forum_id]); } // www.phpBB-SEO.com SEO TOOLKIT END // Replies $replies = $auth->acl_get('m_approve', $related_forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; $unread_topic = isset($topic_tracking_info[$related_topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$related_topic_id] ? true : false; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$related_forum_id}&t={$related_topic_id}"); $topic_unapproved = !$row['topic_approved'] && $auth->acl_get('m_approve', $related_forum_id) ? true : false; $u_mcp_queue = $topic_unapproved ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=queue&mode=approve_details&t={$related_topic_id}", true, $user->session_id) : ''; // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) { if ($replies + 1 > $phpbb_seo->seo_opt['topic_per_page']) { $phpbb_seo->seo_opt['topic_last_page'][$related_topic_id] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page']; } } // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe $template->assign_block_vars('related', array('TOPIC_TITLE' => $row['topic_title'], 'U_TOPIC' => $view_topic_url, 'U_FORUM' => $this->allforums ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$related_forum_id}") : '', 'FORUM' => $row['forum_name'], 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST' => !empty($phpbb_seo->seo_opt['no_dupe']['on']) ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$related_forum_id}&t={$related_topic_id}&start=" . @intval($phpbb_seo->seo_opt['topic_last_page'][$related_topic_id])) . '#p' . $row['topic_last_post_id'] : append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$related_forum_id}&t={$related_topic_id}&p=" . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt, false), 'TOPIC_ICON_IMG' => !empty($icons[$row['icon_id']]) ? $icons[$row['icon_id']]['img'] : '', 'ATTACH_ICON_IMG' => $row['topic_attachment'] && $s_attachement ? $attachement_icon : '', 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $auth->acl_get('m_report', $related_forum_id) ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&mode=reports&f=' . $related_forum_id . '&t=' . $related_topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue)); $related_result = true; } } $db->sql_freeresult($result); } if ($related_result) { $template->assign_vars(array('S_RELATED_RESULTS' => $related_result, 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'), 'S_TOPIC_ICONS' => $enable_icons)); } }
$mark_time = $mark_time_topic; } else { $mark_time = $mark_time_forum; } // This will allow the style designer to output a different header // or even seperate the list of announcements from sticky and normal // topics $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $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) { $topic_id = $row['topic_moved_id']; } // Get folder img, topic status/type related informations $folder_img = $folder_alt = $topic_type = ''; $unread_topic = topic_status($row, $replies, $mark_time, $folder_img, $folder_alt, $topic_type); $newest_post_img = $unread_topic ? '<a href="' . generate_link("Forums&file=viewtopic&t={$topic_id}&view=unread#unread") . '">' . $_CLASS['core_user']->img('icon_post_newest', 'VIEW_NEWEST_POST') . '</a> ' : ''; // Generate all the URIs ... $view_topic_url = 'Forums&file=viewtopic&t=' . $topic_id; $pagination = generate_pagination('Forums&file=viewtopic&&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, 'TOPIC_AUTHOR' => topic_topic_author($row), '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' => (int) $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, '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' => $_CLASS['auth']->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment'] ? $_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' => !empty($row['topic_reported']) && $_CLASS['auth']->acl_gets('m_', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => !$row['topic_approved'] && $_CLASS['auth']->acl_gets('m_approve', $forum_id) ? true : false, 'U_LAST_POST' => generate_link($view_topic_url . $SID . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'], false, false, false), 'U_LAST_POST_AUTHOR' => $_CLASS['core_user']->is_user && $row['topic_last_poster_id'] ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_VIEW_TOPIC' => generate_link($view_topic_url), 'U_MCP_REPORT' => generate_link("Forums&file=mcp&mode=reports&t={$topic_id}"), 'U_MCP_QUEUE' => generate_link('Forums&file=mcp&i=queue&mode=approve_details&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; } } // 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); } } else { $_CLASS['core_template']->assign_array(array('S_IS_POSTABLE' => false, 'S_DISPLAY_ACTIVE' => false, 'S_DISPLAY_SEARCHBOX' => false, 'TOTAL_TOPICS' => false));
public function main() { include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext; $this->user->add_lang(array('memberlist', 'groups', 'search')); $this->user->add_lang_ext('gfksx/ThanksForPosts', 'thanks_mod'); // Grab data $mode = $this->request->variable('mode', ''); $end_row_rating = isset($this->config['thanks_number_row_reput']) ? $this->config['thanks_number_row_reput'] : false; $full_post_rating = $full_topic_rating = $full_forum_rating = false; $u_search_post = $u_search_topic = $u_search_forum = ''; $total_match_count = 0; //$page_title = $this->user->lang['REPUT_TOPLIST']; $topic_id = $this->request->variable('t', 0); $return_chars = $this->request->variable('ch', $topic_id ? -1 : 300); $words = array(); $ex_fid_ary = array_keys($this->auth->acl_getf('!f_read', true)); $ex_fid_ary = sizeof($ex_fid_ary) ? $ex_fid_ary : true; $pagination_url = append_sid("{$this->phpbb_root_path}toplist", 'mode=' . $mode); if (!$this->auth->acl_gets('u_viewtoplist')) { if ($this->user->data['user_id'] != ANONYMOUS) { trigger_error('RATING_NO_VIEW_TOPLIST'); } login_box('', isset($this->user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]) ? $this->user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $this->user->lang['RETING_LOGIN_EXPLAIN']); } $notoplist = true; $start = $this->request->variable('start', 0); $max_post_thanks = $this->config['thanks_post_reput_view'] ? $this->gfksx_helper->get_max_post_thanks() : 1; $max_topic_thanks = $this->config['thanks_topic_reput_view'] ? $this->gfksx_helper->get_max_topic_thanks() : 1; $max_forum_thanks = $this->config['thanks_forum_reput_view'] ? $this->gfksx_helper->get_max_forum_thanks() : 1; switch ($mode) { case 'post': $sql = 'SELECT COUNT(DISTINCT post_id) as total_post_count FROM ' . $this->thanks_table . ' WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true); $result = $this->db->sql_query($sql); $total_match_count = (int) $this->db->sql_fetchfield('total_post_count'); $this->db->sql_freeresult($result); $full_post_rating = true; $notoplist = false; break; case 'topic': $sql = 'SELECT COUNT(DISTINCT topic_id) as total_topic_count FROM ' . $this->thanks_table . ' WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true); $result = $this->db->sql_query($sql); $total_match_count = (int) $this->db->sql_fetchfield('total_topic_count'); $this->db->sql_freeresult($result); $full_topic_rating = true; $notoplist = false; break; case 'forum': $sql = 'SELECT COUNT(DISTINCT forum_id) as total_forum_count FROM ' . $this->thanks_table . ' WHERE ' . $this->db->sql_in_set('forum_id', $ex_fid_ary, true); $result = $this->db->sql_query($sql); $total_match_count = (int) $this->db->sql_fetchfield('total_forum_count'); $this->db->sql_freeresult($result); $full_forum_rating = true; $notoplist = false; break; default: $page_title = $this->user->lang['REPUT_TOPLIST']; $total_match_count = 0; } $page_title = sprintf($this->user->lang['REPUT_TOPLIST'], $total_match_count); //post rating if (!$full_forum_rating && !$full_topic_rating && $this->config['thanks_post_reput_view']) { $end = $full_post_rating ? $this->config['topics_per_page'] : $end_row_rating; $sql_p_array['FROM'] = array($this->thanks_table => 't'); $sql_p_array['SELECT'] = 'u.user_id, u.username, u.user_colour, p.post_subject, p.post_id, p.post_time, p.poster_id, p.post_username, p.topic_id, p.forum_id, p.post_text, p.bbcode_uid, p.bbcode_bitfield, p.post_attachment'; $sql_p_array['SELECT'] .= ', t.post_id, COUNT(*) AS post_thanks'; $sql_p_array['LEFT_JOIN'][] = array('FROM' => array($this->posts_table => 'p'), 'ON' => 't.post_id = p.post_id'); $sql_p_array['LEFT_JOIN'][] = array('FROM' => array($this->users_table => 'u'), 'ON' => 'p.poster_id = u.user_id'); $sql_p_array['GROUP_BY'] = 't.post_id'; $sql_p_array['ORDER_BY'] = 'post_thanks DESC'; $sql_p_array['WHERE'] = $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true); $sql = $this->db->sql_build_query('SELECT', $sql_p_array); $result = $this->db->sql_query_limit($sql, $end, $start); $u_search_post = append_sid("{$this->phpbb_root_path}toplist", "mode=post"); if (!($row = $this->db->sql_fetchrow($result))) { trigger_error('RATING_VIEW_TOPLIST_NO'); } else { $notoplist = false; $bbcode_bitfield = $text_only_message = ''; do { // We pre-process some variables here for later usage $row['post_text'] = censor_text($row['post_text']); $text_only_message = $row['post_text']; // make list items visible as such if ($row['bbcode_uid']) { $text_only_message = str_replace('[*:' . $row['bbcode_uid'] . ']', '⋅ ', $text_only_message); // no BBCode in text only message strip_bbcode($text_only_message, $row['bbcode_uid']); } if ($return_chars == -1 || utf8_strlen($text_only_message) < $return_chars + 3) { $row['display_text_only'] = false; $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); // Does this post have an attachment? If so, add it to the list if ($row['post_attachment'] && $this->config['allow_attachments']) { $attach_list[$row['forum_id']][] = $row['post_id']; } } else { $row['post_text'] = $text_only_message; $row['display_text_only'] = true; } $rowset[] = $row; unset($text_only_message); // Instantiate BBCode if needed if ($bbcode_bitfield !== '' and !class_exists('bbcode')) { include $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext; $bbcode = new \bbcode(base64_encode($bbcode_bitfield)); } // Replace naughty words such as farty pants $row['post_subject'] = censor_text($row['post_subject']); if ($row['display_text_only']) { $row['post_text'] = get_context($row['post_text'], $words, $return_chars); $row['post_text'] = bbcode_nl2br($row['post_text']); } else { // Second parse bbcode here if ($row['bbcode_bitfield']) { $bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']); } $row['post_text'] = bbcode_nl2br($row['post_text']); $row['post_text'] = smiley_text($row['post_text']); } $post_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $row['post_id'] . '#p' . $row['post_id']); $this->template->assign_block_vars('toppostrow', array('MESSAGE' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['post_text'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['post_text']), 'POST_DATE' => !empty($row['post_time']) ? $this->user->format_date($row['post_time']) : '', 'MINI_POST_IMG' => $this->user->img('icon_post_target', 'POST'), 'POST_ID' => $post_url, 'POST_SUBJECT' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['post_subject'] : (!empty($row['forum_id']) ? '' : $row['post_subject']), 'POST_AUTHOR' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_REPUT' => round($row['post_thanks'] / ($max_post_thanks / 100), $this->config['thanks_number_digits']) . '%', 'POST_THANKS' => $row['post_thanks'], 'S_THANKS_POST_REPUT_VIEW' => isset($this->config['thanks_post_reput_view']) ? $this->config['thanks_post_reput_view'] : false, 'S_THANKS_REPUT_GRAPHIC' => isset($this->config['thanks_reput_graphic']) ? $this->config['thanks_reput_graphic'] : false, 'THANKS_REPUT_HEIGHT' => sprintf('%dpx', $this->config['thanks_reput_height']), 'THANKS_REPUT_GRAPHIC_WIDTH' => sprintf('%dpx', $this->config['thanks_reput_level'] * $this->config['thanks_reput_height']), 'THANKS_REPUT_IMAGE' => isset($this->config['thanks_reput_image']) ? $this->phpbb_root_path . $this->config['thanks_reput_image'] : '', 'THANKS_REPUT_IMAGE_BACK' => isset($this->config['thanks_reput_image_back']) ? $this->phpbb_root_path . $this->config['thanks_reput_image_back'] : '')); } while ($row = $this->db->sql_fetchrow($result)); $this->db->sql_freeresult($result); } } //topic rating if (!$full_forum_rating && !$full_post_rating && $this->config['thanks_topic_reput_view']) { $end = $full_topic_rating ? $this->config['topics_per_page'] : $end_row_rating; $sql_t_array['FROM'] = array($this->thanks_table => 'f'); $sql_t_array['SELECT'] = 'u.user_id, u.username, u.user_colour, t.topic_title, t.topic_id, t.topic_time, t.topic_poster, t.topic_first_poster_name, t.topic_first_poster_colour, t.forum_id, t.topic_type, t.topic_status, t.poll_start'; $sql_t_array['SELECT'] .= ', f.topic_id, COUNT(*) AS topic_thanks'; $sql_t_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'f.topic_id = t.topic_id'); $sql_t_array['LEFT_JOIN'][] = array('FROM' => array($this->users_table => 'u'), 'ON' => 't.topic_poster = u.user_id'); $sql_t_array['GROUP_BY'] = 'f.topic_id'; $sql_t_array['ORDER_BY'] = 'topic_thanks DESC'; $sql_t_array['WHERE'] = $this->db->sql_in_set('f.forum_id', $ex_fid_ary, true); $sql = $this->db->sql_build_query('SELECT', $sql_t_array); $result = $this->db->sql_query_limit($sql, $end, $start); $u_search_topic = append_sid("{$this->phpbb_root_path}toplist", "mode=topic"); if (!($row = $this->db->sql_fetchrow($result))) { trigger_error('RATING_VIEW_TOPLIST_NO'); } else { $notoplist = false; do { // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, 0, false, $folder_img, $folder_alt, $topic_type); $view_topic_url_params = 'f=' . ($row['forum_id'] ? $row['forum_id'] : '') . '&t=' . $row['topic_id']; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", $view_topic_url_params); $this->template->assign_block_vars('toptopicrow', array('TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG_SRC' => $row['forum_id'] ? 'topic_read' : 'announce_read', 'TOPIC_TITLE' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['topic_title'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['topic_title']), 'U_VIEW_TOPIC' => $view_topic_url, 'TOPIC_AUTHOR' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_THANKS' => $row['topic_thanks'], 'TOPIC_REPUT' => round($row['topic_thanks'] / ($max_topic_thanks / 100), $this->config['thanks_number_digits']) . '%', 'S_THANKS_TOPIC_REPUT_VIEW' => isset($this->config['thanks_topic_reput_view']) ? $this->config['thanks_topic_reput_view'] : false, 'S_THANKS_REPUT_GRAPHIC' => isset($this->config['thanks_reput_graphic']) ? $this->config['thanks_reput_graphic'] : false, 'THANKS_REPUT_HEIGHT' => sprintf('%dpx', $this->config['thanks_reput_height']), 'THANKS_REPUT_GRAPHIC_WIDTH' => sprintf('%dpx', $this->config['thanks_reput_level'] * $this->config['thanks_reput_height']), 'THANKS_REPUT_IMAGE' => isset($this->config['thanks_reput_image']) ? $this->phpbb_root_path . $this->config['thanks_reput_image'] : '', 'THANKS_REPUT_IMAGE_BACK' => isset($this->config['thanks_reput_image_back']) ? $this->phpbb_root_path . $this->config['thanks_reput_image_back'] : '')); } while ($row = $this->db->sql_fetchrow($result)); $this->db->sql_freeresult($result); } } //forum rating if (!$full_topic_rating && !$full_post_rating && $this->config['thanks_forum_reput_view']) { $end = $full_forum_rating ? $this->config['topics_per_page'] : $end_row_rating; $sql_f_array['FROM'] = array($this->thanks_table => 't'); $sql_f_array['SELECT'] = 'f.forum_name, f.forum_id'; $sql_f_array['SELECT'] .= ', t.forum_id, COUNT(*) AS forum_thanks'; $sql_f_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id'); $sql_f_array['GROUP_BY'] = 't.forum_id'; $sql_f_array['ORDER_BY'] = 'forum_thanks DESC'; $sql_f_array['WHERE'] = $this->db->sql_in_set('t.forum_id', $ex_fid_ary, true); $sql = $this->db->sql_build_query('SELECT', $sql_f_array); $result = $this->db->sql_query_limit($sql, $end, $start); $u_search_forum = append_sid("{$this->phpbb_root_path}toplist", "mode=forum"); if (!($row = $this->db->sql_fetchrow($result))) { trigger_error('RATING_VIEW_TOPLIST_NO'); } else { $notoplist = false; do { if (!empty($row['forum_id'])) { $u_viewforum = append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']); $folder_image = 'forum_read'; $this->template->assign_block_vars('topforumrow', array('FORUM_FOLDER_IMG_SRC' => $this->user->img('forum_read', 'NO_NEW_POSTS', false, '', 'src'), 'FORUM_IMG_STYLE' => $folder_image, 'FORUM_NAME' => $this->auth->acl_get('f_read', $row['forum_id']) ? $row['forum_name'] : (!empty($row['forum_id']) ? $this->user->lang['SORRY_AUTH_READ'] : $row['forum_name']), 'U_VIEW_FORUM' => $u_viewforum, 'FORUM_THANKS' => $row['forum_thanks'], 'FORUM_REPUT' => round($row['forum_thanks'] / ($max_forum_thanks / 100), $this->config['thanks_number_digits']) . '%', 'S_THANKS_FORUM_REPUT_VIEW' => isset($this->config['thanks_forum_reput_view']) ? $this->config['thanks_forum_reput_view'] : false, 'S_THANKS_REPUT_GRAPHIC' => isset($this->config['thanks_reput_graphic']) ? $this->config['thanks_reput_graphic'] : false, 'THANKS_REPUT_HEIGHT' => sprintf('%dpx', $this->config['thanks_reput_height']), 'THANKS_REPUT_GRAPHIC_WIDTH' => sprintf('%dpx', $this->config['thanks_reput_level'] * $this->config['thanks_reput_height']), 'THANKS_REPUT_IMAGE' => isset($this->config['thanks_reput_image']) ? $this->phpbb_root_path . $this->config['thanks_reput_image'] : '', 'THANKS_REPUT_IMAGE_BACK' => isset($this->config['thanks_reput_image_back']) ? $this->phpbb_root_path . $this->config['thanks_reput_image_back'] : '')); } } while ($row = $this->db->sql_fetchrow($result)); $this->db->sql_freeresult($result); } } if ($notoplist) { trigger_error('RATING_VIEW_TOPLIST_NO'); } $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_match_count, $this->config['topics_per_page'], $start); // Output the page $this->template->assign_vars(array('PAGE_NUMBER' => $this->pagination->on_page($total_match_count, $this->config['posts_per_page'], $start), 'PAGE_TITLE' => $page_title, 'S_THANKS_FORUM_REPUT_VIEW' => isset($this->config['thanks_forum_reput_view']) ? $this->config['thanks_forum_reput_view'] : false, 'S_THANKS_TOPIC_REPUT_VIEW' => isset($this->config['thanks_topic_reput_view']) ? $this->config['thanks_topic_reput_view'] : false, 'S_THANKS_POST_REPUT_VIEW' => isset($this->config['thanks_post_reput_view']) ? $this->config['thanks_post_reput_view'] : false, 'S_FULL_POST_RATING' => $full_post_rating, 'S_FULL_TOPIC_RATING' => $full_topic_rating, 'S_FULL_FORUM_RATING' => $full_forum_rating, 'U_SEARCH_POST' => $u_search_post, 'U_SEARCH_TOPIC' => $u_search_topic, 'U_SEARCH_FORUM' => $u_search_forum)); page_header($page_title); $this->template->set_filenames(array('body' => 'toplist_body.html')); make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}")); page_footer(); return new Response($this->template->return_display('body'), 200); }
/** * MCP Forum View */ function mcp_forum_view($id, $mode, $action, $forum_info) { global $template, $db, $user, $auth, $cache, $module; global $phpEx, $phpbb_root_path, $config; global $request, $phpbb_dispatcher, $phpbb_container; $user->add_lang(array('viewtopic', 'viewforum')); include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx; // merge_topic is the quickmod action, merge_topics is the mcp_forum action, and merge_select is the mcp_topic action $merge_select = $action == 'merge_select' || $action == 'merge_topic' || $action == 'merge_topics' ? true : false; $forum_id = $forum_info['forum_id']; $start = $request->variable('start', 0); $topic_id_list = $request->variable('topic_id_list', array(0)); $post_id_list = $request->variable('post_id_list', array(0)); $source_topic_ids = array($request->variable('t', 0)); $to_topic_id = $request->variable('to_topic_id', 0); $url_extra = ''; $url_extra .= $forum_id ? "&f={$forum_id}" : ''; $url_extra .= $GLOBALS['topic_id'] ? '&t=' . $GLOBALS['topic_id'] : ''; $url_extra .= $GLOBALS['post_id'] ? '&p=' . $GLOBALS['post_id'] : ''; $url_extra .= $GLOBALS['user_id'] ? '&u=' . $GLOBALS['user_id'] : ''; $url = append_sid("{$phpbb_root_path}mcp.{$phpEx}?{$url_extra}"); // Resync Topics switch ($action) { case 'resync': $topic_ids = $request->variable('topic_id_list', array(0)); mcp_resync_topics($topic_ids); break; case 'merge_topics': $source_topic_ids = $topic_id_list; case 'merge_topic': if ($to_topic_id) { merge_topics($forum_id, $source_topic_ids, $to_topic_id); } break; } /** * Get some data in order to execute other actions. * * @event core.mcp_forum_view_before * @var string action The action * @var array forum_info Array with forum infos * @var int start Start value * @var array topic_id_list Array of topics ids * @var array post_id_list Array of posts ids * @var array source_topic_ids Array of source topics ids * @var int to_topic_id Array of destination topics ids * @since 3.1.6-RC1 */ $vars = array('action', 'forum_info', 'start', 'topic_id_list', 'post_id_list', 'source_topic_ids', 'to_topic_id'); extract($phpbb_dispatcher->trigger_event('core.mcp_forum_view_before', compact($vars))); /* @var $pagination \phpbb\pagination */ $pagination = $phpbb_container->get('pagination'); $selected_ids = ''; if (sizeof($post_id_list) && $action != 'merge_topics') { foreach ($post_id_list as $num => $post_id) { $selected_ids .= '&post_id_list[' . $num . ']=' . $post_id; } } else { if (sizeof($topic_id_list) && $action == 'merge_topics') { foreach ($topic_id_list as $num => $topic_id) { $selected_ids .= '&topic_id_list[' . $num . ']=' . $topic_id; } } } make_jumpbox($url . "&i={$id}&action={$action}&mode={$mode}" . ($merge_select ? $selected_ids : ''), $forum_id, false, 'm_', true); $topics_per_page = $forum_info['forum_topics_per_page'] ? $forum_info['forum_topics_per_page'] : $config['topics_per_page']; $sort_days = $total = 0; $sort_key = $sort_dir = ''; $sort_by_sql = $sort_order_sql = array(); phpbb_mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id); $forum_topics = $total == -1 ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = $sort_days ? 'AND t.topic_last_post_time >= ' . (time() - $sort_days * 86400) : ''; $base_url = $url . "&i={$id}&action={$action}&mode={$mode}&sd={$sort_dir}&sk={$sort_key}&st={$sort_days}" . ($merge_select ? $selected_ids : ''); $pagination->generate_template_pagination($base_url, 'pagination', 'start', $forum_topics, $topics_per_page, $start); $template->assign_vars(array('ACTION' => $action, 'FORUM_NAME' => $forum_info['forum_name'], 'FORUM_DESCRIPTION' => generate_text_for_display($forum_info['forum_desc'], $forum_info['forum_desc_uid'], $forum_info['forum_desc_bitfield'], $forum_info['forum_desc_options']), 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'S_CAN_REPORT' => $auth->acl_get('m_report', $forum_id), 'S_CAN_DELETE' => $auth->acl_get('m_delete', $forum_id), 'S_CAN_RESTORE' => $auth->acl_get('m_approve', $forum_id), 'S_CAN_MERGE' => $auth->acl_get('m_merge', $forum_id), 'S_CAN_MOVE' => $auth->acl_get('m_move', $forum_id), 'S_CAN_FORK' => $auth->acl_get('m_', $forum_id), 'S_CAN_LOCK' => $auth->acl_get('m_lock', $forum_id), 'S_CAN_SYNC' => $auth->acl_get('m_', $forum_id), 'S_CAN_APPROVE' => $auth->acl_get('m_approve', $forum_id), 'S_MERGE_SELECT' => $merge_select ? true : false, 'S_CAN_MAKE_NORMAL' => $auth->acl_gets('f_sticky', 'f_announce', 'f_announce_global', $forum_id), 'S_CAN_MAKE_STICKY' => $auth->acl_get('f_sticky', $forum_id), 'S_CAN_MAKE_ANNOUNCE' => $auth->acl_get('f_announce', $forum_id), 'S_CAN_MAKE_ANNOUNCE_GLOBAL' => $auth->acl_get('f_announce_global', $forum_id), 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id), 'U_VIEW_FORUM_LOGS' => $auth->acl_gets('a_', 'm_', $forum_id) && $module->loaded('logs') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=logs&mode=forum_logs&f=' . $forum_id) : '', 'S_MCP_ACTION' => $url . "&i={$id}&forum_action={$action}&mode={$mode}&start={$start}" . ($merge_select ? $selected_ids : ''), 'TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $forum_topics))); // Grab icons $icons = $cache->obtain_icons(); $topic_rows = array(); if ($config['load_db_lastread']) { $read_tracking_join = ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')'; $read_tracking_select = ', tt.mark_time'; } else { $read_tracking_join = $read_tracking_select = ''; } /* @var $phpbb_content_visibility \phpbb\content_visibility */ $phpbb_content_visibility = $phpbb_container->get('content.visibility'); $sql = 'SELECT t.topic_id FROM ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' AND ' . $phpbb_content_visibility->get_visibility_sql('topic', $forum_id, 't.') . "\n\t\t\t{$limit_time_sql}\n\t\tORDER BY t.topic_type DESC, {$sort_order_sql}"; /** * Modify SQL query before MCP forum view topic list is queried * * @event core.mcp_view_forum_modify_sql * @var string sql SQL query for forum view topic list * @var int forum_id ID of the forum * @var string limit_time_sql SQL query part for limit time * @var string sort_order_sql SQL query part for sort order * @var int topics_per_page Number of topics per page * @var int start Start value * @since 3.1.2-RC1 */ $vars = array('sql', 'forum_id', 'limit_time_sql', 'sort_order_sql', 'topics_per_page', 'start'); extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_sql', compact($vars))); $result = $db->sql_query_limit($sql, $topics_per_page, $start); $topic_list = $topic_tracking_info = array(); while ($row_ary = $db->sql_fetchrow($result)) { $topic_list[] = $row_ary['topic_id']; } $db->sql_freeresult($result); $sql = "SELECT t.*{$read_tracking_select}\n\t\tFROM " . TOPICS_TABLE . " t {$read_tracking_join}\n\t\tWHERE " . $db->sql_in_set('t.topic_id', $topic_list, false, true); $result = $db->sql_query($sql); while ($row_ary = $db->sql_fetchrow($result)) { $topic_rows[$row_ary['topic_id']] = $row_ary; } $db->sql_freeresult($result); // If there is more than one page, but we have no topic list, then the start parameter is... erm... out of sync if (!sizeof($topic_list) && $forum_topics && $start > 0) { redirect($url . "&i={$id}&action={$action}&mode={$mode}"); } // Get topic tracking info if (sizeof($topic_list)) { if ($config['load_db_lastread']) { $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time'])); } else { $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list); } } foreach ($topic_list as $topic_id) { $row_ary =& $topic_rows[$topic_id]; $replies = $phpbb_content_visibility->get_count('topic_posts', $row_ary, $forum_id) - 1; if ($row_ary['topic_status'] == ITEM_MOVED) { $unread_topic = false; } else { $unread_topic = isset($topic_tracking_info[$topic_id]) && $row_ary['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row_ary, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $topic_title = censor_text($row_ary['topic_title']); $topic_unapproved = ($row_ary['topic_visibility'] == ITEM_UNAPPROVED || $row_ary['topic_visibility'] == ITEM_REAPPROVE) && $auth->acl_get('m_approve', $row_ary['forum_id']) ? true : false; $posts_unapproved = $row_ary['topic_visibility'] == ITEM_APPROVED && $row_ary['topic_posts_unapproved'] && $auth->acl_get('m_approve', $row_ary['forum_id']) ? true : false; $topic_deleted = $row_ary['topic_visibility'] == ITEM_DELETED; $u_mcp_queue = $topic_unapproved || $posts_unapproved ? $url . '&i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . '&t=' . $row_ary['topic_id'] : ''; $u_mcp_queue = !$u_mcp_queue && $topic_deleted ? $url . '&i=queue&mode=deleted_topics&t=' . $topic_id : $u_mcp_queue; $topic_row = array('ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row_ary['forum_id']) && $row_ary['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_ICON_IMG' => !empty($icons[$row_ary['icon_id']]) ? $icons[$row_ary['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$row_ary['icon_id']]) ? $icons[$row_ary['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$row_ary['icon_id']]) ? $icons[$row_ary['icon_id']]['height'] : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'DELETED_IMG' => $topic_deleted ? $user->img('icon_topic_deleted', 'POSTS_DELETED') : '', 'TOPIC_AUTHOR' => get_username_string('username', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row_ary['topic_poster'], $row_ary['topic_first_poster_name'], $row_ary['topic_first_poster_colour']), 'LAST_POST_AUTHOR' => get_username_string('username', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']), 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row_ary['topic_last_poster_id'], $row_ary['topic_last_poster_name'], $row_ary['topic_last_poster_colour']), 'TOPIC_TYPE' => $topic_type, 'TOPIC_TITLE' => $topic_title, 'REPLIES' => $phpbb_content_visibility->get_count('topic_posts', $row_ary, $row_ary['forum_id']) - 1, 'LAST_POST_TIME' => $user->format_date($row_ary['topic_last_post_time']), 'FIRST_POST_TIME' => $user->format_date($row_ary['topic_time']), 'LAST_POST_SUBJECT' => $row_ary['topic_last_post_subject'], 'LAST_VIEW_TIME' => $user->format_date($row_ary['topic_last_view_time']), 'S_TOPIC_REPORTED' => !empty($row_ary['topic_reported']) && empty($row_ary['topic_moved_id']) && $auth->acl_get('m_report', $row_ary['forum_id']) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_TOPIC_DELETED' => $topic_deleted, 'S_UNREAD_TOPIC' => $unread_topic); if ($row_ary['topic_status'] == ITEM_MOVED) { $topic_row = array_merge($topic_row, array('U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row_ary['topic_moved_id']}"), 'U_DELETE_TOPIC' => $auth->acl_get('m_delete', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&f={$forum_id}&topic_id_list[]={$row_ary['topic_id']}&mode=forum_view&action=delete_topic") : '', 'S_MOVED_TOPIC' => true, 'TOPIC_ID' => $row_ary['topic_moved_id'])); } else { if ($action == 'merge_topic' || $action == 'merge_topics') { $u_select_topic = $url . "&i={$id}&mode=forum_view&action={$action}&to_topic_id=" . $row_ary['topic_id'] . $selected_ids; } else { $u_select_topic = $url . "&i={$id}&mode=topic_view&action=merge&to_topic_id=" . $row_ary['topic_id'] . $selected_ids; } $topic_row = array_merge($topic_row, array('U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&f={$forum_id}&t={$row_ary['topic_id']}&mode=topic_view"), 'S_SELECT_TOPIC' => $merge_select && !in_array($row_ary['topic_id'], $source_topic_ids) ? true : false, 'U_SELECT_TOPIC' => $u_select_topic, 'U_MCP_QUEUE' => $u_mcp_queue, 'U_MCP_REPORT' => $auth->acl_get('m_report', $forum_id) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&mode=topic_view&t=' . $row_ary['topic_id'] . '&action=reports') : '', 'TOPIC_ID' => $row_ary['topic_id'], 'S_TOPIC_CHECKED' => $topic_id_list && in_array($row_ary['topic_id'], $topic_id_list) ? true : false)); } $row = $row_ary; /** * Modify the topic data before it is assigned to the template in MCP * * @event core.mcp_view_forum_modify_topicrow * @var array row Array with topic data * @var array topic_row Template array with topic data * @since 3.1.0-a1 */ $vars = array('row', 'topic_row'); extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars))); $row_ary = $row; unset($row); $template->assign_block_vars('topicrow', $topic_row); } unset($topic_rows); }
function display_recent_topics($topics_per_page, $num_pages, $excluded_topics, $tpl_loopname = 'recenttopicrow', $spec_forum_id = 0, $include_subforums = true, $display_parent_forums = true) { global $auth, $cache, $config, $db, $template, $user; global $phpbb_root_path, $phpEx; $user->add_lang('mods/info_acp_recenttopics'); /** * Set some internal needed variables */ $start = request_var($tpl_loopname . '_start', 0); $excluded_topic_ids = explode(', ', $excluded_topics); $total_limit = $topics_per_page * $num_pages; $ga_forum_id = 0; // Forum id we use for global announcements /** * Get the forums we take our topics from */ // Get the allowed forums $forum_ary = array(); $forum_read_ary = $auth->acl_getf('f_read'); foreach ($forum_read_ary as $forum_id => $allowed) { if ($allowed['f_read']) { $forum_ary[] = (int) $forum_id; } } $forum_ids = array_unique($forum_ary); if (!sizeof($forum_ids)) { // No forums with f_read return; } $spec_forum_ary = array(); if ($spec_forum_id) { // Only take a special-forum if (!$include_subforums) { if (!in_array($spec_forum_id, $forum_ids)) { return; } $forum_ids = array(); $sql = 'SELECT 1 as display_forum FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $spec_forum_id . ' AND forum_recent_topics = 1'; $result = $db->sql_query_limit($sql, 1); $display_forum = (bool) $db->sql_fetchfield('display_forum'); $db->sql_freeresult($result); if ($display_forum) { $forum_ids = array($spec_forum_id); } } else { // ... and it's subforums $sql = 'SELECT f2.forum_id FROM ' . FORUMS_TABLE . ' f1 LEFT JOIN ' . FORUMS_TABLE . " f2\n\t\t\t\t\tON (f2.left_id BETWEEN f1.left_id AND f1.right_id\n\t\t\t\t\t\tAND f2.forum_recent_topics = 1)\n\t\t\t\tWHERE f1.forum_id = {$spec_forum_id}\n\t\t\t\t\tAND f1.forum_recent_topics = 1\n\t\t\t\tORDER BY f2.left_id DESC"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $spec_forum_ary[] = $row['forum_id']; } $db->sql_freeresult($result); $forum_ids = array_intersect($forum_ids, $spec_forum_ary); if (!sizeof($forum_ids)) { return; } } } else { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' AND forum_recent_topics = 1'; $result = $db->sql_query($sql); $forum_ids = array(); while ($row = $db->sql_fetchrow($result)) { $forum_ids[] = $row['forum_id']; } $db->sql_freeresult($result); } // No forums with f_read if (!sizeof($forum_ids)) { return; } // Moderator forums $m_approve_ids = array(); $m_approve_ary = $auth->acl_getf('m_approve'); foreach ($m_approve_ary as $forum_id => $allowed) { if ($allowed['m_approve'] && in_array($forum_id, $forum_ids)) { $m_approve_ids[] = (int) $forum_id; } } // Get the allowed topics $sql_query_array = array('SELECT' => 't.forum_id, t.topic_id, t.topic_type, t.icon_id, tt.mark_time, ft.mark_time as f_mark_time', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']), array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id'])), 'WHERE' => ' ( (' . $db->sql_in_set('t.topic_id', $excluded_topic_ids, true) . ' AND ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' ) OR t.topic_type = ' . POST_GLOBAL . ' ) AND t.topic_status <> ' . ITEM_MOVED . ' AND (' . $db->sql_in_set('t.forum_id', $m_approve_ids, false, true) . ' OR t.topic_approved = 1)', 'ORDER_BY' => 't.topic_last_post_time DESC'); // Is a soft delete MOD installed? if (file_exists("{$phpbb_root_path}includes/mods/soft_delete.{$phpEx}")) { $sql_query_array['WHERE'] .= ' AND topic_deleted = 0'; } $sql = $db->sql_build_query('SELECT', $sql_query_array); $result = $db->sql_query_limit($sql, $total_limit); $forums = $ga_topic_ids = $topic_ids = array(); $num_topics = 0; $obtain_icons = false; while ($row = $db->sql_fetchrow($result)) { $num_topics++; if ($num_topics > $start && $num_topics <= $start + $topics_per_page) { $topic_ids[] = $row['topic_id']; $rowset[$row['topic_id']] = $row; if (!isset($forums[$row['forum_id']]) && $user->data['is_registered'] && $config['load_db_lastread']) { $forums[$row['forum_id']]['mark_time'] = $row['f_mark_time']; } $forums[$row['forum_id']]['topic_list'][] = $row['topic_id']; $forums[$row['forum_id']]['rowset'][$row['topic_id']] =& $rowset[$row['topic_id']]; if ($row['icon_id'] && $auth->acl_get('f_icons', $row['forum_id'])) { $obtain_icons = true; } } } $db->sql_freeresult($result); // No topics to display if (!sizeof($topic_ids)) { return; } // Grab icons if ($obtain_icons) { $icons = $cache->obtain_icons(); } else { $icons = array(); } // Borrowed from search.php foreach ($forums as $forum_id => $forum) { if ($user->data['is_registered'] && $config['load_db_lastread']) { $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), $forum_id ? false : $forum['topic_list']); } 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(); $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], $forum_id ? false : $forum['topic_list']); 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; } } } } // Now only pull the data of the requested topics $sql_query_array = array('SELECT' => 't.*, tp.topic_posted, f.forum_name', 'FROM' => array(TOPICS_TABLE => 't'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 't.topic_id = tp.topic_id AND tp.user_id = ' . $user->data['user_id']), array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = t.forum_id')), 'WHERE' => $db->sql_in_set('t.topic_id', $topic_ids), 'ORDER_BY' => 't.topic_last_post_time DESC'); if ($display_parent_forums) { $sql_query_array['SELECT'] .= ', f.parent_id, f.forum_parents, f.left_id, f.right_id'; } $sql = $db->sql_build_query('SELECT', $sql_query_array); $result = $db->sql_query_limit($sql, $topics_per_page); $topic_icons = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = $row['topic_id']; $forum_id = $row['forum_id']; // Cheat for Global Announcements on the unread-link: copied from search.php if (!$forum_id && !$ga_forum_id) { $sql2 = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . ' AND ' . $db->sql_in_set('forum_id', $forum_ary, false, true); $result2 = $db->sql_query_limit($sql2, 1); $ga_forum_id = (int) $db->sql_fetchfield('forum_id'); $db->sql_freeresult($result2); $forum_id = $ga_forum_id; } else { if (!$forum_id && $ga_forum_id) { $forum_id = $ga_forum_id; } } $s_type_switch_test = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0; $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; topic_status($row, $replies, isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false, $folder_img, $folder_alt, $topic_type); $unread_topic = isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']] ? true : false; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $forum_id . '&t=' . $topic_id); $view_forum_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id); $topic_unapproved = !$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id) ? true : false; $posts_unapproved = $row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id) ? true : false; $u_mcp_queue = $topic_unapproved || $posts_unapproved ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&mode=' . ($topic_unapproved ? 'approve_details' : 'unapproved_posts') . "&t={$topic_id}", true, $user->session_id) : ''; $s_type_switch = $row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL ? 1 : 0; if (!empty($icons[$row['icon_id']])) { $topic_icons[] = $topic_id; } $template->assign_block_vars($tpl_loopname, array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']), 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TYPE' => $topic_type, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt], 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), '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' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'UNAPPROVED_IMG' => $topic_unapproved || $posts_unapproved ? $user->img('icon_topic_unapproved', $topic_unapproved ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '', 'REPORTED_IMG' => $row['topic_reported'] && $auth->acl_get('m_report', $forum_id) ? $user->img('icon_topic_reported', 'TOPIC_REPORTED') : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => isset($row['topic_posted']) && $row['topic_posted'] ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'S_TOPIC_REPORTED' => $row['topic_reported'] && $auth->acl_get('m_report', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => $topic_unapproved, 'S_POSTS_UNAPPROVED' => $posts_unapproved, 'S_HAS_POLL' => $row['poll_start'] ? true : false, 'S_POST_ANNOUNCE' => $row['topic_type'] == POST_ANNOUNCE ? true : false, 'S_POST_GLOBAL' => $row['topic_type'] == POST_GLOBAL ? true : false, 'S_POST_STICKY' => $row['topic_type'] == POST_STICKY ? true : false, 'S_TOPIC_LOCKED' => $row['topic_status'] == ITEM_LOCKED ? true : false, 'S_TOPIC_MOVED' => $row['topic_status'] == ITEM_MOVED ? true : false, 'S_TOPIC_TYPE_SWITCH' => $s_type_switch == $s_type_switch_test ? -1 : $s_type_switch_test, 'U_NEWEST_POST' => $view_topic_url . '&view=unread#unread', 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id'], 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => $view_forum_url, 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&mode=reports&f=' . $forum_id . '&t=' . $topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue)); if ($display_parent_forums) { $forum_parents = get_forum_parents($row); foreach ($forum_parents as $parent_id => $data) { $template->assign_block_vars($tpl_loopname . '.parent_forums', array('FORUM_ID' => $parent_id, 'FORUM_NAME' => $data[0], 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $parent_id))); } } } $db->sql_freeresult($result); // Get URL-parameters for pagination $url_params = explode('&', $user->page['query_string']); $append_params = false; foreach ($url_params as $param) { if (!$param) { continue; } if (strpos($param, '=') === false) { // Fix MSSTI Advanced BBCode MOD $append_params[$param] = '1'; continue; } list($name, $value) = explode('=', $param); if ($name != $tpl_loopname . '_start') { $append_params[$name] = $value; } } $template->assign_vars(array('S_TOPIC_ICONS' => sizeof($topic_icons) ? true : false, 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), strtoupper($tpl_loopname) . '_DISPLAY' => true, strtoupper($tpl_loopname) . '_PAGE_NUMBER' => on_page($num_topics, $topics_per_page, $start), strtoupper($tpl_loopname) . '_PAGINATION' => recent_topics_generate_pagination(append_sid($phpbb_root_path . $user->page['page_name'], $append_params), $num_topics, $topics_per_page, $start, false, strtoupper($tpl_loopname), $tpl_loopname . '_start', $tpl_loopname))); }
} $view_topic_url_params = "f=$u_forum_id&t=$result_topic_id" . (($u_hilit) ? "&hilit=$u_hilit" : ''); $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params); $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; if ($show_results == 'topics') { if ($config['load_db_track'] && $author_id === $user->data['user_id']) { $row['topic_posted'] = 1; } $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false, $folder_img, $folder_alt, $topic_type); $unread_topic = (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false; $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $forum_id)) ? true : false; $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&t=$result_topic_id", true, $user->session_id) : ''; $row['topic_title'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['topic_title']); $tpl_ary = array( 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'],
$sql = 'SELECT p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_sig, u.user_sig_bbcode_uid FROM ' . FORUMS_FORUMS_TABLE . ' f, ' . FORUMS_TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_POSTS_TABLE . " p \n\t\t\t\tWHERE {$sql_where} \n\t\t\t\t\tAND f.forum_id = p.forum_id\n\t\t\t\t\tAND p.topic_id = t.topic_id\n\t\t\t\t\tAND p.poster_id = u.user_id"; } else { $sql = 'SELECT t.*, f.forum_id, f.forum_name FROM ' . FORUMS_TOPICS_TABLE . ' t, ' . FORUMS_FORUMS_TABLE . " f \n\t\t\t\tWHERE {$sql_where} \n\t\t\t\t\tAND f.forum_id = t.forum_id"; } $sql .= ' ORDER BY ' . $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC'); $result = $_CLASS['core_db']->query_limit($sql, $per_page, $start); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $forum_id = $row['forum_id']; $topic_id = $row['topic_id']; $view_topic_url = "Forums&file=viewtopic&f={$forum_id}&t={$topic_id}&hilit={$u_hilit}"; if ($show_results === 'topics') { $replies = $_CLASS['auth']->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; $folder_img = $unread_topic = $folder_alt = $topic_type = ''; topic_status($row, $replies, $_CLASS['core_user']->time, $unread_topic, $folder_img, $folder_alt, $topic_type); $pagination = generate_pagination($view_topic_url, $replies, $config['posts_per_page'], 0); $tpl_ary = array('TOPIC_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'], '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_TYPE' => $topic_type, 'LAST_POST_IMG' => $_CLASS['core_user']->img('icon_post_latest', 'VIEW_LATEST_POST'), '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' => $_CLASS['auth']->acl_gets(array('f_download', 'u_download'), $forum_id) && $row['topic_attachment'] ? $_CLASS['core_user']->img('icon_attach', $_CLASS['core_user']->lang['TOTAL_ATTACHMENTS']) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => !empty($row['mark_type']) ? true : false, 'S_TOPIC_REPORTED' => !empty($row['topic_reported']) && $_CLASS['auth']->acl_get('m_', $forum_id) ? true : false, 'S_TOPIC_UNAPPROVED' => !$row['topic_approved'] && $_CLASS['auth']->acl_get('m_approve', $forum_id) ? true : false, 'S_IGNORE_POST' => false, 'U_LAST_POST' => generate_link($view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'], false), 'U_LAST_POST_AUTHOR' => $row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id'] ? generate_link('Members_List&mode=viewprofile&u=' . $row['topic_last_poster_id']) : '', 'U_MCP_REPORT' => generate_link('Forums&file=mcp&mode=reports&t=' . $topic_id), 'U_MCP_QUEUE' => generate_link('Forums&file=mcp&i=queue&mode=approve_details&t=' . $topic_id)); } else { if (isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe']) && (!$view || $view != 'show' || $post_id != $row['post_id'])) { $_CLASS['core_template']->assign_vars_array('searchresults', array('S_IGNORE_POST' => true, 'L_IGNORE_POST' => sprintf($_CLASS['core_user']->lang['POST_BY_FOE'], $row['username'], '<a href="' . generate_link("Forums&file=search&search_session_id={$search_session_id}&{$u_sort_param}&p=" . $row['post_id'] . '&view=show#' . $row['post_id']) . '">', '</a>'))); continue; } if ($row['enable_html']) { $row['post_text'] = preg_replace('#(<!\\-\\- h \\-\\-><)([\\/]?.*?)(><!\\-\\- h \\-\\->)#is', "<\\2>", $row['post_text']); } $row['post_text'] = censor_text($row['post_text']); decode_message($row['post_text'], $row['bbcode_uid']); if ($return_chars) { $row['post_text'] = strlen($row['post_text']) < $return_chars + 3 ? $row['post_text'] : substr($row['post_text'], 0, $return_chars) . '...'; }
/** * Build and assign topiclist for bookmarks/subscribed topics */ function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array()) { global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx; $table = $mode == 'subscribed' ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE; $start = request_var('start', 0); // Grab icons $icons = $cache->obtain_icons(); $sql_array = array('SELECT' => 'COUNT(t.topic_id) as topics_count', 'FROM' => array($table => 'i', TOPICS_TABLE => 't'), 'WHERE' => 'i.topic_id = t.topic_id AND i.user_id = ' . $user->data['user_id'] . ' AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true)); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $topics_count = (int) $db->sql_fetchfield('topics_count'); $db->sql_freeresult($result); if ($topics_count) { $template->assign_vars(array('PAGINATION' => generate_pagination($this->u_action, $topics_count, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start), 'TOTAL_TOPICS' => $topics_count == 1 ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $topics_count))); } if ($mode == 'subscribed') { $sql_array = array('SELECT' => 't.*, f.forum_name, f.forum_solve_text, f.forum_solve_color, f.forum_allow_solve', 'FROM' => array(TOPICS_WATCH_TABLE => 'tw', TOPICS_TABLE => 't'), 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true), 'ORDER_BY' => 't.topic_last_post_time DESC'); $sql_array['LEFT_JOIN'] = array(); } else { $sql_array = array('SELECT' => 't.*, f.forum_name, f.forum_solve_text, f.forum_solve_color, f.forum_allow_solve, b.topic_id as b_topic_id', 'FROM' => array(BOOKMARKS_TABLE => 'b'), 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . ' AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true), 'ORDER_BY' => 't.topic_last_post_time DESC'); $sql_array['LEFT_JOIN'] = array(); $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id'); } $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id'); if ($config['load_db_lastread']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']); $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']); $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time'; } if ($config['load_db_track']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']); $sql_array['SELECT'] .= ', tp.topic_posted'; } $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $topic_list = $topic_forum_list = $global_announce_list = $rowset = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = isset($row['b_topic_id']) ? $row['b_topic_id'] : $row['topic_id']; $topic_list[] = $topic_id; $rowset[$topic_id] = $row; $topic_forum_list[$row['forum_id']]['forum_mark_time'] = $config['load_db_lastread'] ? $row['forum_mark_time'] : 0; $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id; if ($row['topic_type'] == POST_GLOBAL) { $global_announce_list[] = $topic_id; } } $db->sql_freeresult($result); $topic_tracking_info = array(); if ($config['load_db_lastread']) { foreach ($topic_forum_list as $f_id => $topic_row) { $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), $f_id == 0 ? $global_announce_list : false); } } else { foreach ($topic_forum_list as $f_id => $topic_row) { $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list); } } foreach ($topic_list as $topic_id) { $row =& $rowset[$topic_id]; $forum_id = $row['forum_id']; $topic_id = isset($row['b_topic_id']) ? $row['b_topic_id'] : $row['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; // Replies $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies']; if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) { $topic_id = $row['topic_moved_id']; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $view_topic_url_params = "f={$forum_id}&t={$topic_id}"; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params); // Send vars to template $template->assign_block_vars('topicrow', array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'S_DELETED_TOPIC' => !$row['topic_id'] ? true : false, 'S_GLOBAL_TOPIC' => !$forum_id ? true : false, 'PAGINATION' => topic_generate_pagination($replies, append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . ($row['forum_id'] ? $row['forum_id'] : $forum_id) . "&t={$topic_id}")), 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'FORUM_NAME' => $row['forum_name'], 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$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' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => !empty($row['topic_posted']) ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params . '&view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id), 'SOLVED_TOPIC' => $row['topic_solved'] && $row['forum_allow_solve'] ? $row['forum_solve_text'] ? $row['forum_solve_text'] : $user->img('icon_topic_solved_list', 'TOPIC_SOLVED') : '', 'U_SOLVED_TOPIC' => $row['topic_solved'] && $row['forum_allow_solve'] ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'p=' . $row['topic_solved'] . '#p' . $row['topic_solved']) : '', 'SOLVED_STYLE' => $row['forum_solve_color'] ? ' style="color: #' . $row['forum_solve_color'] . '"' : '')); } }
/** * Build and assign topiclist for bookmarks/subscribed topics */ function assign_topiclist($mode = 'subscribed', $forbidden_forum_ary = array()) { global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_container, $request, $phpbb_dispatcher; /* @var $pagination \phpbb\pagination */ $pagination = $phpbb_container->get('pagination'); $table = $mode == 'subscribed' ? TOPICS_WATCH_TABLE : BOOKMARKS_TABLE; $start = $request->variable('start', 0); // Grab icons $icons = $cache->obtain_icons(); $sql_array = array('SELECT' => 'COUNT(t.topic_id) as topics_count', 'FROM' => array($table => 'i', TOPICS_TABLE => 't'), 'WHERE' => 'i.topic_id = t.topic_id AND i.user_id = ' . $user->data['user_id'] . ' AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true)); /** * Modify the query used to retrieve the count of subscribed/bookmarked topics * * @event core.ucp_main_topiclist_count_modify_query * @var array sql_array The subscribed/bookmarked topics query * @var array forbidden_forum_ary The list of forbidden forums * @var string mode The type of topic list ('subscribed' or 'bookmarks') * @since 3.1.10-RC1 */ $vars = array('sql_array', 'forbidden_forum_ary', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_count_modify_query', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql); $topics_count = (int) $db->sql_fetchfield('topics_count'); $db->sql_freeresult($result); if ($topics_count) { $start = $pagination->validate_start($start, $config['topics_per_page'], $topics_count); $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $topics_count, $config['topics_per_page'], $start); $template->assign_vars(array('TOTAL_TOPICS' => $user->lang('VIEW_FORUM_TOPICS', (int) $topics_count))); } if ($mode == 'subscribed') { $sql_array = array('SELECT' => 't.*, f.forum_name', 'FROM' => array(TOPICS_WATCH_TABLE => 'tw', TOPICS_TABLE => 't'), 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tw.topic_id AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true), 'ORDER_BY' => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'); $sql_array['LEFT_JOIN'] = array(); } else { $sql_array = array('SELECT' => 't.*, f.forum_name, b.topic_id as b_topic_id', 'FROM' => array(BOOKMARKS_TABLE => 'b'), 'WHERE' => 'b.user_id = ' . $user->data['user_id'] . ' AND ' . $db->sql_in_set('f.forum_id', $forbidden_forum_ary, true, true), 'ORDER_BY' => 't.topic_last_post_time DESC, t.topic_last_post_id DESC'); $sql_array['LEFT_JOIN'] = array(); $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TABLE => 't'), 'ON' => 'b.topic_id = t.topic_id'); } $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id'); if ($config['load_db_lastread']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']); $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']); $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time'; } if ($config['load_db_track']) { $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']); $sql_array['SELECT'] .= ', tp.topic_posted'; } /** * Modify the query used to retrieve the list of subscribed/bookmarked topics * * @event core.ucp_main_topiclist_modify_query * @var array sql_array The subscribed/bookmarked topics query * @var array forbidden_forum_ary The list of forbidden forums * @var string mode The type of topic list ('subscribed' or 'bookmarks') * @since 3.1.10-RC1 */ $vars = array('sql_array', 'forbidden_forum_ary', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_modify_query', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $topic_list = $topic_forum_list = $global_announce_list = $rowset = array(); while ($row = $db->sql_fetchrow($result)) { $topic_id = isset($row['b_topic_id']) ? $row['b_topic_id'] : $row['topic_id']; $topic_list[] = $topic_id; $rowset[$topic_id] = $row; $topic_forum_list[$row['forum_id']]['forum_mark_time'] = $config['load_db_lastread'] ? $row['forum_mark_time'] : 0; $topic_forum_list[$row['forum_id']]['topics'][] = $topic_id; if ($row['topic_type'] == POST_GLOBAL) { $global_announce_list[] = $topic_id; } } $db->sql_freeresult($result); $topic_tracking_info = array(); if ($config['load_db_lastread']) { foreach ($topic_forum_list as $f_id => $topic_row) { $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time'])); } } else { foreach ($topic_forum_list as $f_id => $topic_row) { $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics']); } } /* @var $phpbb_content_visibility \phpbb\content_visibility */ $phpbb_content_visibility = $phpbb_container->get('content.visibility'); foreach ($topic_list as $topic_id) { $row =& $rowset[$topic_id]; $forum_id = $row['forum_id']; $topic_id = isset($row['b_topic_id']) ? $row['b_topic_id'] : $row['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; // Replies $replies = $phpbb_content_visibility->get_count('topic_posts', $row, $forum_id) - 1; if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) { $topic_id = $row['topic_moved_id']; } // Get folder img, topic status/type related information $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type); $view_topic_url_params = "f={$forum_id}&t={$topic_id}"; $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params); // Send vars to template $template_vars = array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $topic_id, 'FIRST_POST_TIME' => $user->format_date($row['topic_time']), 'LAST_POST_SUBJECT' => $row['topic_last_post_subject'], 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']), 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'S_DELETED_TOPIC' => !$row['topic_id'] ? true : false, 'REPLIES' => $replies, 'VIEWS' => $row['topic_views'], 'TOPIC_TITLE' => censor_text($row['topic_title']), 'TOPIC_TYPE' => $topic_type, 'FORUM_NAME' => $row['forum_name'], 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$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' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'S_TOPIC_TYPE' => $row['topic_type'], 'S_USER_POSTED' => !empty($row['topic_posted']) ? true : false, 'S_UNREAD_TOPIC' => $unread_topic, 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params . '&view=unread') . '#unread', 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id)); /** * Add template variables to a subscribed/bookmarked topic row. * * @event core.ucp_main_topiclist_topic_modify_template_vars * @var array template_vars Array containing the template variables for the row * @var array row Array containing the subscribed/bookmarked topic row data * @var int forum_id ID of the forum containing the topic * @var int topic_id Topic ID * @var int replies Number of replies in the topic * @var string topic_type Topic type * @var string folder_img Folder image * @var string folder_alt Alt text for the folder image * @var array icons Array containing topic icons * @var bool unread_topic Whether the topic has unread content or not * @var string view_topic_url The URL of the topic * @since 3.1.10-RC1 */ $vars = array('template_vars', 'row', 'forum_id', 'topic_id', 'replies', 'topic_type', 'folder_img', 'folder_alt', 'icons', 'unread_topic', 'view_topic_url'); extract($phpbb_dispatcher->trigger_event('core.ucp_main_topiclist_topic_modify_template_vars', compact($vars))); $template->assign_block_vars('topicrow', $template_vars); $pagination->generate_template_pagination(append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . "&t={$topic_id}"), 'topicrow.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true); } }