function cms_block_recent_topics() { global $db, $cache, $config, $template, $user, $lang, $block_id, $cms_config_vars; $template->_tpldata['recent_topic_row.'] = array(); $except_forums = build_exclusion_forums_list(); $current_time = time(); $extra = "AND t.topic_time <= {$current_time}"; $sql = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username, u.user_active, u.user_color\n\t\t\tFROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . USERS_TABLE . " AS u\n\t\t\tWHERE t.forum_id NOT IN (" . $except_forums . ")\n\t\t\t\tAND t.topic_status <> 2\n\t\t\t\tAND p.post_id = t.topic_last_post_id\n\t\t\t\tAND p.poster_id = u.user_id\n\t\t\t\t{$extra}\n\t\t\tORDER BY p.post_time DESC\n\t\t\tLIMIT " . $cms_config_vars['md_num_recent_topics'][$block_id]; $result = $db->sql_query($sql); $number_recent_topics = $db->sql_numrows($result); $recent_topic_row = array(); while ($row1 = $db->sql_fetchrow($result)) { $recent_topic_row[] = $row1; } $db->sql_freeresult($result); if ($cms_config_vars['md_recent_topics_style'][$block_id]) { $style_row = 'scroll'; } else { $style_row = 'static'; } $template->assign_block_vars($style_row, ''); for ($i = 0; $i < $number_recent_topics; $i++) { $recent_topic_row[$i]['topic_title'] = censor_text($recent_topic_row[$i]['topic_title']); // Convert and clean special chars! $topic_title = htmlspecialchars_clean($recent_topic_row[$i]['topic_title']); $template->assign_block_vars($style_row . '.recent_topic_row', array('U_TITLE' => append_sid(CMS_PAGE_VIEWTOPIC . '?' . POST_FORUM_URL . '=' . $recent_topic_row[$i]['forum_id'] . '&' . POST_TOPIC_URL . '=' . $recent_topic_row[$i]['topic_id'] . '&' . POST_POST_URL . '=' . $recent_topic_row[$i]['post_id']) . '#p' . $recent_topic_row[$i]['post_id'], 'L_TITLE' => $topic_title, 'L_BY' => $lang['By'], 'L_ON' => $lang['POSTED_ON'], 'S_POSTER' => colorize_username($recent_topic_row[$i]['user_id'], $recent_topic_row[$i]['username'], $recent_topic_row[$i]['user_color'], $recent_topic_row[$i]['user_active']), 'S_POSTTIME' => create_date_ip($config['default_dateformat'], $recent_topic_row[$i]['post_time'], $config['board_timezone']))); } }
} } else { $mode = $set_mode; } } $psort_types = array('time', 'cat'); $psort = request_var('psort', $psort_types[0]); $psort = check_var_value($psort, $psort_types); $nav_server_url = create_server_url(); $breadcrumbs['address'] = $lang['Nav_Separator'] . '<a href="' . $nav_server_url . append_sid('recent.' . PHP_EXT) . '" class="nav-current">' . $lang['Recent_topics'] . '</a>'; $except_forums = build_exclusion_forums_list(); $where_forums = ($special_forums == '0') ? 't.forum_id NOT IN (' . $except_forums . ')' : 't.forum_id NOT IN (' . $except_forums . ') AND t.forum_id IN (' . $forum_ids . ')'; $sql_sort = ' ORDER BY t.topic_last_post_id DESC '; if ($psort == 'cat') { $sql_sort = ' ORDER BY f.forum_id ASC, t.topic_last_post_id DESC '; } $extra_tables = ''; $extra_fields = ''; if ($mode == 'utview') { $extra_fields = ", tv.view_time, tv.view_count"; $extra_tables = ", " . TOPIC_VIEW_TABLE . " tv"; }
function fetch_posts($forum_sql, $number_of_posts, $text_length, $show_portal = false, $sort_mode = 0, $single_post = false, $only_auth_view = true) { global $db, $cache, $config, $user, $bbcode, $lofi; if (!class_exists('bbcode') || empty($bbcode)) { @(include_once IP_ROOT_PATH . 'includes/bbcode.' . PHP_EXT); } $except_forums = build_exclusion_forums_list($only_auth_view); $add_to_sql = ''; if (empty($single_post) && !empty($forum_sql)) { $except_forums_exp = explode(',', str_replace(' ', '', $except_forums)); $allowed_forums_exp = explode(',', str_replace(' ', '', $forum_sql)); $except_forums = ''; for ($e = 0; $e < sizeof($except_forums_exp); $e++) { if (!in_array($except_forums_exp[$e], $allowed_forums_exp)) { $except_forums .= $except_forums == '' ? $except_forums_exp[$e] : ', ' . $except_forums_exp[$e]; } } $add_to_sql .= ' AND t.forum_id IN (' . $forum_sql . ')'; $add_to_sql .= ' AND t.forum_id NOT IN (' . $except_forums . ')'; } else { $add_to_sql .= ' AND t.forum_id NOT IN (' . $except_forums . ')'; } if (!empty($show_portal)) { $add_to_sql .= ' AND t.topic_show_portal = 1'; } if ($sort_mode == 1) { // Random $order_sql = 'RAND()'; } elseif ($sort_mode == 2) { // Alphabetical $order_sql = 't.topic_title ASC'; } else { // Recent $order_sql = 't.topic_time DESC'; } if ($number_of_posts != 0) { $limit_sql = ' LIMIT 0,' . $number_of_posts; } else { $limit_sql = ''; } if (!empty($single_post)) { $single_post_id = $forum_sql; $sql = "SELECT p.post_id, p.topic_id, p.forum_id, p.enable_html, p.enable_bbcode, p.enable_smilies, p.post_attachment, p.enable_autolinks_acronyms, p.post_text, p.post_text_compiled, t.forum_id, t.topic_time, t.topic_title, t.topic_first_post_id, t.topic_attachment, t.topic_views, t.topic_replies, u.username, u.user_id, u.user_active, u.user_color\n\t\t\t\t\tFROM " . POSTS_TABLE . " AS p, " . TOPICS_TABLE . " AS t, " . USERS_TABLE . " AS u\n\t\t\t\t\tWHERE p.post_id = '" . $single_post_id . "'\n\t\t\t\t\t\t" . $add_to_sql . "\n\t\t\t\t\t\tAND t.topic_id = p.topic_id\n\t\t\t\t\t\tAND p.poster_id = u.user_id"; } else { $sql = "SELECT t.topic_id, t.topic_time, t.topic_title, t.forum_id, t.topic_poster, t.topic_first_post_id, t.topic_status, t.topic_show_portal, t.topic_attachment, t.topic_views, t.topic_replies, u.username, u.user_id, u.user_active, u.user_color, p.post_id, p.enable_html, p.enable_bbcode, p.enable_smilies, p.post_attachment, p.enable_autolinks_acronyms, p.post_text, p.post_text_compiled\n\t\t\t\t\tFROM " . TOPICS_TABLE . " AS t, " . USERS_TABLE . " AS u, " . POSTS_TABLE . " AS p\n\t\t\t\t\tWHERE t.topic_time <= " . time() . "\n\t\t\t\t\t\t" . $add_to_sql . "\n\t\t\t\t\t\tAND t.topic_poster = u.user_id\n\t\t\t\t\t\tAND t.topic_first_post_id = p.post_id\n\t\t\t\t\t\tAND t.topic_status <> 2\n\t\t\t\t\tORDER BY " . $order_sql . $limit_sql; } // query the database $result = $db->sql_query($sql); // fetch all postings $posts = array(); if ($row = $db->sql_fetchrow($result)) { $i = 0; do { $posts[$i]['enable_bbcode'] = $row['enable_bbcode']; $posts[$i]['enable_html'] = $row['enable_html']; $posts[$i]['enable_smilies'] = $row['enable_smilies']; $posts[$i]['enable_autolinks_acronyms'] = $row['enable_autolinks_acronyms']; $posts[$i]['post_text'] = $row['post_text']; $posts[$i]['forum_id'] = $row['forum_id']; $posts[$i]['topic_id'] = $row['topic_id']; $posts[$i]['topic_first_post_id'] = $row['topic_first_post_id']; $posts[$i]['topic_views'] = $row['topic_views']; $posts[$i]['topic_replies'] = $row['topic_replies']; $posts[$i]['topic_time'] = create_date_ip($config['default_dateformat'], $row['topic_time'], $config['board_timezone']); $posts[$i]['topic_title'] = $row['topic_title']; $posts[$i]['user_id'] = $row['user_id']; $posts[$i]['username'] = $row['username']; $posts[$i]['user_active'] = $row['user_active']; $posts[$i]['user_color'] = $row['user_color']; $posts[$i]['topic_attachment'] = $row['topic_attachment']; $posts[$i]['post_id'] = $row['post_id']; $posts[$i]['post_attachment'] = $row['post_attachment']; if ($text_length >= 0) { $message = $posts[$i]['post_text']; $message_compiled = empty($posts[$i]['post_text_compiled']) || !empty($user->data['session_logged_in']) || !empty($config['posts_precompiled']) ? false : $posts[$i]['post_text_compiled']; $bbcode->allow_bbcode = $config['allow_bbcode'] && $user->data['user_allowbbcode'] && $posts[$i]['enable_bbcode'] ? true : false; $bbcode->allow_html = ($config['allow_html'] && $user->data['user_allowhtml'] || $config['allow_html_only_for_admins']) && $posts[$i]['enable_html'] ? true : false; $bbcode->allow_smilies = $config['allow_smilies'] && $posts[$i]['enable_smilies'] && !$lofi ? true : false; $clean_tags = false; if (strlen($posts[$i]['post_text']) > $text_length && $text_length > 0) { $clean_tags = true; $posts[$i]['striped'] = 1; } $posts[$i]['post_text'] = $message_compiled === false ? $bbcode->parse($posts[$i]['post_text'], '', false, $clean_tags) : $message_compiled; if (!empty($clean_tags)) { $posts[$i]['post_text'] = strlen($posts[$i]['post_text']) > $text_length ? truncate_html_string($posts[$i]['post_text'], $text_length) : $posts[$i]['post_text']; } $posts[$i]['post_text'] = censor_text($posts[$i]['post_text']); //Acronyms, AutoLinks - BEGIN if ($posts[$i]['enable_autolinks_acronyms']) { $posts[$i]['post_text'] = $bbcode->acronym_pass($posts[$i]['post_text']); $posts[$i]['post_text'] = $bbcode->autolink_text($posts[$i]['post_text'], '999999'); } //Acronyms, AutoLinks - END } $posts[$i]['topic_title'] = censor_text($posts[$i]['topic_title']); $i++; } while ($row = $db->sql_fetchrow($result)); } $db->sql_freeresult($result); // return the result return $posts; }