function sf_add_new_topic_tag($forumid, $linktext = "Add new topic in the %FORUMNAME% forum", $beforelink = '', $afterlink = '', $beforetext = '', $aftertext = '')
{
    global $current_user;
    sf_initialise_globals($forumid);
    if (sf_can_view_forum($forum_id)) {
        $forum = sf_get_forum_record($forumid);
        $linktext = str_replace("%FORUMNAME%", $forum->forum_name, $linktext);
        $url = trailingslashit(sf_build_url($forum->forum_slug, '', 0, 0));
        $url = sf_get_sfqurl($url) . 'new=topic';
        $out = '<p>' . $beforelink . '<a href="' . $url . '">' . $beforetext . $linktext . $aftertext . '</a>' . $afterlink . '</p>';
        echo $out;
    }
    return;
}
function sf_latest_posts($limit = 5)
{
    global $wpdb, $current_user, $sfvars;
    sf_initialise_globals($sfvars['forumid']);
    $out = '';
    $where = " WHERE " . SFPOSTS . ".post_status = 0";
    # limit to viewable forums based on permissions
    if (!$current_user->forumadmin) {
        $allforums = sf_get_forum_memberships($current_user->ID);
        if ($allforums) {
            $forum_ids = '';
            foreach ($allforums as $thisforum) {
                if (sf_can_view_forum($thisforum->forum_id)) {
                    $forum_ids[] = $thisforum->forum_id;
                }
            }
        } else {
            return '';
        }
        # create where clause based on forums that current user can view
        if ($forum_ids != '') {
            $where .= " AND forum_id IN (" . implode(",", $forum_ids) . ") ";
        }
    }
    $posts = $wpdb->get_results("SELECT post_id, topic_id, forum_id, post_content, post_index, " . sf_zone_datetime('post_date') . ",\n\t\t\t " . SFPOSTS . ".user_id, guest_name, " . SFMEMBERS . ".display_name FROM " . SFPOSTS . "\n\t\t\t LEFT JOIN " . SFMEMBERS . " ON " . SFPOSTS . ".user_id = " . SFMEMBERS . ".user_id\n\t\t\t " . $where . "\n\t\t\t ORDER BY post_date DESC\n\t\t\t LIMIT " . $limit);
    $out .= '<div class="sf-latest">';
    if ($posts) {
        foreach ($posts as $post) {
            $thisforum = sf_get_forum_record($post->forum_id);
            $poster = sf_build_name_display($post->user_id, stripslashes($post->display_name));
            if (empty($poster)) {
                $poster = apply_filters('sf_show_post_name', stripslashes($post->guest_name));
            }
            $topic = sf_get_topic_record($post->topic_id);
            $out .= '<div class="sf-latest-header">';
            $out .= $poster . __(' posted ', "sforum");
            $out .= '<a href="' . sf_build_url($thisforum->forum_slug, $topic->topic_slug, 1, $post->post_id, $post->post_index) . '">';
            $out .= stripslashes($topic->topic_name) . '</a>';
            $out .= __(' in ', "sforum");
            $out .= '<a href="' . sf_build_url($thisforum->forum_slug, '', 1, 0) . '">' . sf_get_forum_name($thisforum->forum_slug) . '</a>';
            $out .= '<br />' . mysql2date(SFDATES, $post->post_date);
            $out .= '</div>';
            $out .= '<div class="sf-latest-content">';
            $text = sf_filter_content(stripslashes($post->post_content), '');
            $text = sf_rss_excerpt($text);
            $out .= $text;
            $out .= '</div>';
            $out .= '<br />';
        }
    } else {
        $out .= '<div class="sf-latest-header">';
        $out .= '<p>' . __("No Topics to Display", "sforum") . '</p>' . "\n";
        $out .= '</div>';
    }
    $out .= '</div>';
    echo $out;
    return;
}