function get_topic($id, $cache = true)
{
    global $bbdb;
    if (!is_numeric($id)) {
        list($slug, $sql) = bb_get_sql_from_slug('topic', $id);
        $id = wp_cache_get($slug, 'bb_topic_slug');
    }
    // not else
    if (is_numeric($id)) {
        $id = (int) $id;
        $sql = "topic_id = {$id}";
    }
    if (0 === $id || !$sql) {
        return false;
    }
    // &= not =&
    $cache &= 'AND topic_status = 0' == ($where = apply_filters('get_topic_where', 'AND topic_status = 0'));
    if (($cache || !$where) && is_numeric($id) && false !== ($topic = wp_cache_get($id, 'bb_topic'))) {
        return $topic;
    }
    // $where is NOT bbdb:prepared
    $topic = $bbdb->get_row("SELECT * FROM {$bbdb->topics} WHERE {$sql} {$where}");
    $topic = bb_append_meta($topic, 'topic');
    if ($cache) {
        wp_cache_set($topic->topic_id, $topic, 'bb_topic');
        wp_cache_add($topic->topic_slug, $topic->topic_id, 'bb_topic_slug');
    }
    return $topic;
}
Example #2
0
function bb_get_id_from_slug($table, $slug, $slug_length = 255)
{
    global $bbdb;
    $tablename = $table . 's';
    list($_slug, $sql) = bb_get_sql_from_slug($table, $slug, $slug_length);
    if (!$_slug || !$sql) {
        return 0;
    }
    return (int) $bbdb->get_var("SELECT {$table}_id FROM {$bbdb->{$tablename}} WHERE {$sql}");
}
function bb_get_forum($id)
{
    global $bbdb;
    if (!is_numeric($id)) {
        list($slug, $sql) = bb_get_sql_from_slug('forum', $id);
        $id = wp_cache_get($slug, 'bb_forum_slug');
    }
    // not else
    if (is_numeric($id)) {
        $id = (int) $id;
        $sql = "forum_id = {$id}";
    }
    if (0 === $id || !$sql) {
        return false;
    }
    // $where is NOT bbdb:prepared
    if ($where = apply_filters('get_forum_where', '')) {
        $forum = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->forums} WHERE forum_id = %d", $id) . " {$where}");
        return bb_append_meta($forum, 'forum');
    }
    if (is_numeric($id) && false !== ($forum = wp_cache_get($id, 'bb_forum'))) {
        return $forum;
    }
    $forum = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->forums} WHERE {$sql}", $id));
    $forum = bb_append_meta($forum, 'forum');
    wp_cache_set($forum->forum_id, $forum, 'bb_forum');
    wp_cache_add($forum->forum_slug, $forum, 'bb_forum_slug');
    return $forum;
}