function bb_get_topic_from_uri($uri)
{
    // Extract the topic id or slug of the uri
    if ('topic' === bb_get_path(0, false, $uri)) {
        $topic_id_or_slug = bb_get_path(1, false, $uri);
    } else {
        if ($parsed_uri = parse_url($uri)) {
            if (preg_match('@/topic\\.php$@', $parsed_uri['path'])) {
                $args = wp_parse_args($parsed_uri['query']);
                if (isset($args['id'])) {
                    $topic_id_or_slug = $args['id'];
                }
            }
        }
    }
    if (!$topic_id_or_slug) {
        return false;
    }
    return get_topic($topic_id_or_slug);
}
Exemplo n.º 2
0
function socialit_get_current_rss_link()
{
    switch (bb_get_location()) {
        case 'profile-page':
            if ($tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2)) {
                if ($tab != 'favorites') {
                    break;
                }
            }
            $feed = get_favorites_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            break;
        case 'topic-page':
            $feed = get_topic_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            break;
        case 'tag-page':
            if (bb_is_tag()) {
                $feed = bb_get_tag_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            }
            break;
        case 'forum-page':
            $feed = bb_get_forum_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            break;
        case 'front-page':
            $feed = bb_get_posts_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            break;
        case 'view-page':
            global $bb_views, $view;
            if ($bb_views[$view]['feed']) {
                $feed = bb_get_view_rss_link(null, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            }
            break;
        default:
            $feed = bb_get_posts_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED);
            break;
    }
    return $feed;
}
Exemplo n.º 3
0
function bb_repermalink()
{
    global $page;
    $location = bb_get_location();
    $uri = $_SERVER['REQUEST_URI'];
    if (isset($_GET['id'])) {
        $id = $_GET['id'];
    } else {
        $id = bb_get_path();
    }
    $_original_id = $id;
    do_action('pre_permalink', $id);
    $id = apply_filters('bb_repermalink', $id);
    switch ($location) {
        case 'front-page':
            $path = null;
            $querystring = null;
            if ($page > 1) {
                if (bb_get_option('mod_rewrite')) {
                    $path = 'page/' . $page;
                } else {
                    $querystring = array('page' => $page);
                }
            }
            $permalink = bb_get_uri($path, $querystring, BB_URI_CONTEXT_HEADER);
            $issue_404 = true;
            break;
        case 'forum-page':
            if (empty($id)) {
                $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER);
                break;
            }
            global $forum_id, $forum;
            $forum = bb_get_forum($id);
            $forum_id = $forum->forum_id;
            $permalink = get_forum_link($forum->forum_id, $page);
            break;
        case 'topic-edit-page':
        case 'topic-page':
            if (empty($id)) {
                $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER);
                break;
            }
            global $topic_id, $topic;
            $topic = get_topic($id);
            $topic_id = $topic->topic_id;
            $permalink = get_topic_link($topic->topic_id, $page);
            break;
        case 'profile-page':
            // This handles the admin side of the profile as well.
            global $user_id, $user, $profile_hooks, $self;
            if (isset($_GET['id'])) {
                $id = $_GET['id'];
            } elseif (isset($_GET['username'])) {
                $id = $_GET['username'];
            } else {
                $id = bb_get_path();
            }
            $_original_id = $id;
            if (!$id) {
                $user = bb_get_current_user();
                // Attempt to go to the current users profile
            } else {
                if (bb_get_option('mod_rewrite') === 'slugs') {
                    if (!($user = bb_get_user_by_nicename($id))) {
                        $user = bb_get_user($id);
                    }
                } else {
                    if (!($user = bb_get_user($id))) {
                        $user = bb_get_user_by_nicename($id);
                    }
                }
            }
            if (!$user || 1 == $user->user_status && !bb_current_user_can('moderate')) {
                bb_die(__('User not found.'), '', 404);
            }
            $user_id = $user->ID;
            bb_global_profile_menu_structure();
            $valid = false;
            if ($tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2)) {
                foreach ($profile_hooks as $valid_tab => $valid_file) {
                    if ($tab == $valid_tab) {
                        $valid = true;
                        $self = $valid_file;
                    }
                }
            }
            if ($valid) {
                $permalink = get_profile_tab_link($user->ID, $tab, $page);
            } else {
                $permalink = get_user_profile_link($user->ID, $page);
                unset($self, $tab);
            }
            break;
        case 'favorites-page':
            $permalink = get_favorites_link();
            break;
        case 'tag-page':
            // It's not an integer and tags.php pulls double duty.
            $id = isset($_GET['tag']) ? $_GET['tag'] : false;
            if (!$id || !bb_get_tag((string) $id)) {
                $permalink = bb_get_tag_page_link();
            } else {
                global $tag, $tag_name;
                $tag_name = $id;
                $tag = bb_get_tag((string) $id);
                $permalink = bb_get_tag_link(0, $page);
                // 0 => grabs $tag from global.
            }
            break;
        case 'view-page':
            // Not an integer
            if (isset($_GET['view'])) {
                $id = $_GET['view'];
            } else {
                $id = bb_get_path();
            }
            $_original_id = $id;
            global $view;
            $view = $id;
            $permalink = get_view_link($view, $page);
            break;
        default:
            return;
            break;
    }
    nxt_parse_str($_SERVER['QUERY_STRING'], $args);
    $args = urlencode_deep($args);
    if ($args) {
        $permalink = add_query_arg($args, $permalink);
        if (bb_get_option('mod_rewrite')) {
            $pretty_args = array('id', 'page', 'tag', 'tab', 'username');
            // these are already specified in the path
            if ($location == 'view-page') {
                $pretty_args[] = 'view';
            }
            foreach ($pretty_args as $pretty_arg) {
                $permalink = remove_query_arg($pretty_arg, $permalink);
            }
        }
    }
    $permalink = apply_filters('bb_repermalink_result', $permalink, $location);
    $domain = bb_get_option('domain');
    $domain = preg_replace('/^https?/', '', $domain);
    $check = preg_replace('|^.*' . trim($domain, ' /') . '|', '', $permalink, 1);
    $uri = rtrim($uri, " \t\n\r\v?");
    $uri = str_replace('/index.php', '/', $uri);
    global $bb_log;
    $bb_log->debug($uri, 'bb_repermalink() ' . __('REQUEST_URI'));
    $bb_log->debug($check, 'bb_repermalink() ' . __('should be'));
    $bb_log->debug($permalink, 'bb_repermalink() ' . __('full permalink'));
    $bb_log->debug(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null, 'bb_repermalink() ' . __('PATH_INFO'));
    if ($check != $uri && $check != str_replace(urlencode($_original_id), $_original_id, $uri)) {
        if ($issue_404 && rtrim($check, " \t\n\r\v/") !== rtrim($uri, " \t\n\r\v/")) {
            status_header(404);
            bb_load_template('404.php');
        } else {
            nxt_redirect($permalink);
        }
        exit;
    }
    do_action('post_permalink', $permalink);
}
Exemplo n.º 4
0
function get_path($level = 1, $base = false, $request = false)
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_get_path');
    return bb_get_path($level, $base, $request);
}
function bb_feed_head()
{
    $feeds = array();
    switch (bb_get_location()) {
        case 'profile-page':
            if ($tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2)) {
                if ($tab != 'favorites') {
                    break;
                }
            }
            $feeds[] = array('title' => sprintf(__('%1$s » User Favorites: %2$s'), bb_get_option('name'), get_user_name()), 'href' => get_favorites_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            break;
        case 'topic-page':
            $feeds[] = array('title' => sprintf(__('%1$s » Topic: %2$s'), bb_get_option('name'), get_topic_title()), 'href' => get_topic_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            break;
        case 'tag-page':
            if (bb_is_tag()) {
                $feeds[] = array('title' => sprintf(__('%1$s » Tag: %2$s - Recent Posts'), bb_get_option('name'), bb_get_tag_name()), 'href' => bb_get_tag_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
                $feeds[] = array('title' => sprintf(__('%1$s » Tag: %2$s - Recent Topics'), bb_get_option('name'), bb_get_tag_name()), 'href' => bb_get_tag_topics_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            }
            break;
        case 'forum-page':
            $feeds[] = array('title' => sprintf(__('%1$s » Forum: %2$s - Recent Posts'), bb_get_option('name'), get_forum_name()), 'href' => bb_get_forum_posts_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            $feeds[] = array('title' => sprintf(__('%1$s » Forum: %2$s - Recent Topics'), bb_get_option('name'), get_forum_name()), 'href' => bb_get_forum_topics_rss_link(0, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            break;
        case 'front-page':
            $feeds[] = array('title' => sprintf(__('%1$s » Recent Posts'), bb_get_option('name')), 'href' => bb_get_posts_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            $feeds[] = array('title' => sprintf(__('%1$s » Recent Topics'), bb_get_option('name')), 'href' => bb_get_topics_rss_link(BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            break;
        case 'view-page':
            global $bb_views, $view;
            if ($bb_views[$view]['feed']) {
                $feeds[] = array('title' => sprintf(__('%1$s » View: %2$s'), bb_get_option('name'), get_view_name()), 'href' => bb_get_view_rss_link(null, BB_URI_CONTEXT_LINK_ALTERNATE_HREF + BB_URI_CONTEXT_BB_FEED));
            }
            break;
    }
    if (count($feeds)) {
        $feed_links = array();
        foreach ($feeds as $feed) {
            $link = '<link rel="alternate" type="application/rss+xml" ';
            $link .= 'title="' . esc_attr($feed['title']) . '" ';
            $link .= 'href="' . esc_attr($feed['href']) . '" />';
            $feed_links[] = $link;
        }
        $feed_links = join("\n", $feed_links);
    } else {
        $feed_links = '';
    }
    echo apply_filters('bb_feed_head', $feed_links);
}
Exemplo n.º 6
0
    } else {
        // Tag recent posts
        $feed = 'tag-posts';
    }
    $feed_id = isset($_GET['tag']) ? $_GET['tag'] : bb_get_path(2);
} elseif (isset($_GET['forum']) || bb_get_path() == 'forum') {
    if (isset($_GET['topics']) || bb_get_path(3) == 'topics') {
        // Forum recent topics
        $feed = 'forum-topics';
    } else {
        // Forum recent posts
        $feed = 'forum-posts';
    }
    $forum = bb_get_forum(isset($_GET['forum']) ? $_GET['forum'] : bb_get_path(2));
    $feed_id = $forum->forum_id;
} elseif (isset($_GET['topics']) || bb_get_path() == 'topics') {
    // Recent topics
    $feed = 'all-topics';
} else {
    // Recent posts
    $feed = 'all-posts';
}
// Initialise the override variable
$bb_db_override = false;
do_action('bb_rss.php_pre_db');
if (!$bb_db_override) {
    // Get the posts and the title for the given feed
    switch ($feed) {
        case 'view':
            if (!isset($bb_views[$feed_id])) {
                die;