public function __construct() { global $template, $db, $board_config, $phpbb_seo, $lang; global $rcs, $get, $qte; $template->assign_vars(array('MARQUEE_TOPIC' => str_replace("%s", $board_config['topics_on_index'], $lang['marquee_topic']))); if (!($result = $db->sql_query($this->getFetchSql(), false, 'topics_recent_'))) { message_die(GENERAL_ERROR, 'Could not query recent posts marquee information', '', __LINE__, __FILE__); } if ($rows = $db->sql_fetchrowset($result)) { $db->sql_freeresult($result); } $topics = count($rows) <= $board_config['topics_on_index'] ? count($rows) : $board_config['topics_on_index']; for ($i = 0; $i < $topics; ++$i) { $topic = $rows[$i]; $mar_title = $topic["topic_title"]; // www.phpBB-SEO.com SEO TOOLKIT BEGIN if (!isset($phpbb_seo->seo_url['topic'][$topic['topic_id']])) { $phpbb_seo->seo_url['topic'][$topic['topic_id']] = $phpbb_seo->format_url($mar_title); } // www.phpBB-SEO.com SEO TOOLKIT END $mar_url = $get->url('viewtopic', array(POST_TOPIC_URL => $topic["topic_id"])); $mar_user = $topic["username"]; $pic = pic_for_topic($topic); if ($board_config['allow_smilies']) { $topic["topic_title"] = smilies_pass($topic["topic_title"]); } $topic_title = $topic['topic_title']; $qte->attr($topic_title, $topic['topic_attribute']); $template->assign_block_vars('marqueerow', array('FOLD_URL' => $pic, 'TOPIC_TITLE' => $topic_title, 'TOPIC_URL' => $get->url('viewtopic', array(POST_TOPIC_URL => $topic["topic_id"]), true), 'POST_URL' => $get->url('viewtopic', array('p' => $topic["post_id"]), true) . '#' . $topic["post_id"], 'STYLE' => $rcs->get_colors($topic), 'USERNAME' => $topic["username"], 'USER_PROF' => $get->url('userlist', array('mode' => 'viewprofile', POST_USERS_URL => $topic["user_id"]), true), 'POST_DATE' => create_date($board_config['default_dateformat'], $topic["post_time"], $board_config['board_timezone']))); } }
function get_related_topics($topic_id) { global $board_config, $db, $lang, $template, $theme, $images, $phpEx; global $userdata, $HTTP_COOKIE_VARS; global $rcs, $qte; // // Fetch all words that appear in the title of $topic_id // $sql = 'SELECT m.word_id FROM ' . SEARCH_MATCH_TABLE . ' m, ' . TOPICS_TABLE . ' t WHERE m.post_id = t.topic_first_post_id AND t.topic_id = ' . intval($topic_id); if (!($result = $db->sql_query($sql, false, 'search_match_t' . intval($topic_id) . '_'))) { message_die(GENERAL_ERROR, 'Could not retrieve word matches', '', __LINE__, __FILE__, $sql); } $word_ids = array(0); while ($row = $db->sql_fetchrow($result)) { $word_ids[] = intval($row['word_id']); } $word_id_sql = implode(', ', $word_ids); // // Only search for related topics in the forums where the user has read access // $is_auth = array(); $is_auth = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); $forum_ids = array(0); while (list($forum_id, $forum_auth) = @each($is_auth)) { if ($forum_auth['auth_read']) { $forum_ids[] = $forum_id; } } $forum_id_sql = implode(', ', $forum_ids); $sql = 'SELECT DISTINCT(t.topic_id) FROM ' . SEARCH_MATCH_TABLE . ' m, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t WHERE t.topic_id <> ' . intval($topic_id) . ' AND t.topic_status <> ' . TOPIC_MOVED . ' AND p.topic_id = t.topic_id AND p.post_id = m.post_id AND p.forum_id IN (' . $forum_id_sql . ') AND m.title_match = 1 AND m.word_id IN (' . $word_id_sql . ') LIMIT 0, 5'; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not retrieve related topics information', '', __LINE__, __FILE__, $sql); } $topic_ids = array(); while ($row = $db->sql_fetchrow($result)) { $topic_ids[] = $row['topic_id']; } $topic_id_sql = implode(', ', $topic_ids); // // No topics? Exit // if (count($topic_ids) == 0) { return; } // // Output to page // $template->set_filenames(array('related_topics' => 'viewtopic_related_body.tpl')); $template->assign_vars(array('L_RELATED_TOPICS' => $lang['Related_topics'], 'L_AUTHOR' => $lang['Author'], 'L_TOPICS' => $lang['Topics'], 'L_REPLIES' => $lang['Replies'], 'L_VIEWS' => $lang['Views'], 'L_LASTPOST' => $lang['Last_Post'])); // // Define censored word matches // $orig_word = array(); $replacement_word = array(); obtain_word_list($orig_word, $replacement_word); // // Fetch all topic information // $sql = 'SELECT t.*, u.username, u.user_id, u.user_level, u.user_color, u.user_group_id, u2.username as user2, u2.user_id as id2, u2.user_level as level2, u2.user_color as color2, u2.user_group_id as group_id2, p.post_username, p2.post_username AS post_username2, p2.post_time FROM ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . POSTS_TABLE . ' p, ' . POSTS_TABLE . ' p2, ' . USERS_TABLE . ' u2 WHERE t.topic_id IN (' . $topic_id_sql . ') AND t.topic_poster = u.user_id AND p.post_id = t.topic_first_post_id AND p2.post_id = t.topic_last_post_id AND u2.user_id = p2.poster_id ORDER BY t.topic_type DESC, t.topic_last_post_id DESC'; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not retrieve topic information', '', __LINE__, __FILE__, $sql); } $topic_row = array(); $topic_row = $db->sql_fetchrowset($result); $db->sql_freeresult($result); if (count($topic_row) == 0) { return; } $i = 0; foreach ($topic_row as $row) { $topic_id = $row['topic_id']; $forum_id = $row['forum_id']; $topic_title = $row['topic_title']; $qte->attr($topic_title, $row['topic_attribute']); if (count($orig_word)) { $topic_title = preg_replace($orig_word, $replacement_word, $topic_title); } $replies = $row['topic_replies']; $views = $row['topic_views']; $topic_type = topic_type_lang($row['topic_type']); if ($row['topic_vote']) { $topic_type .= $lang['Topic_Poll'] . ' '; } if ($row['topic_type'] == POST_ANNOUNCE) { $folder = $images['folder_announce']; $folder_new = $images['folder_announce_new']; } else { if ($row['topic_type'] == POST_STICKY) { $folder = $images['folder_sticky']; $folder_new = $images['folder_sticky_new']; } else { if ($row['topic_status'] == TOPIC_LOCKED) { $folder = $images['folder_locked']; $folder_new = $images['folder_locked_new']; } else { if ($replies >= $board_config['hot_threshold']) { $folder = $images['folder_hot']; $folder_new = $images['folder_hot_new']; } else { $folder = $images['folder']; $folder_new = $images['folder_new']; } } } } $newest_post_img = ''; $folder_image = pic_for_topic($row); $topic_author = $row['user_id'] != ANONYMOUS ? '<a href="' . append_sid("profile.{$phpEx}?mode=viewprofile&" . POST_USERS_URL . '=' . $row['user_id']) . '">' : ''; $topic_author .= $row['user_id'] != ANONYMOUS ? $rcs->get_colors($row, $row['username']) : ($row['post_username'] != '' ? $row['post_username'] : $lang['Guest']); $topic_author .= $row['user_id'] != ANONYMOUS ? '</a>' : ''; $first_post_time = create_date($board_config['default_dateformat'], $row['topic_time'], $board_config['board_timezone']); $last_post_time = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']); $last_post_author = $row['id2'] == ANONYMOUS ? $row['post_username2'] != '' ? $row['post_username2'] . ' ' : $lang['Guest'] . ' ' : '<a href="' . append_sid("profile.{$phpEx}?mode=viewprofile&" . POST_USERS_URL . '=' . $row['id2']) . '">' . $rcs->get_colors($row, $row['user2'], false, 'group_id2', 'color2', 'level2') . '</a>'; $last_post_url = '<a href="' . append_sid("viewtopic.{$phpEx}?" . POST_POST_URL . '=' . $row['topic_last_post_id']) . '#' . $row['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>'; $row_color = !($i % 2) ? $theme['td_color1'] : $theme['td_color2']; $row_class = !($i % 2) ? $theme['td_class1'] : $theme['td_class2']; $template->assign_block_vars('topicrow', array('ROW_COLOR' => '#' . $row_color, 'ROW_CLASS' => $row_class, 'L_TOPIC_FOLDER_ALT' => $folder_alt, 'U_VIEW_TOPIC' => append_sid("viewtopic.{$phpEx}?" . POST_TOPIC_URL . '=' . $row['topic_id']), 'TOPIC_FOLDER_IMG' => $folder_image, 'TOPIC_AUTHOR' => $topic_author, 'REPLIES' => $replies, 'NEWEST_POST_IMG' => $newest_post_img, 'TOPIC_TITLE' => $topic_title, 'TOPIC_TYPE' => $topic_type, 'VIEWS' => $views, 'LAST_POST_TIME' => $last_post_time, 'LAST_POST_AUTHOR' => $last_post_author, 'LAST_POST_IMG' => $last_post_url)); $i++; } $template->assign_var_from_handle('RELATED_TOPICS', 'related_topics'); return; }