コード例 #1
0
 function generate_post_sql($_part_of_topic_query = false)
 {
     global $bbdb;
     $q =& $this->query_vars;
     $distinct = '';
     $sql_calc_found_rows = 'found_rows' === $q['count'] ? 'SQL_CALC_FOUND_ROWS' : '';
     // unfiltered
     $fields = 'p.*';
     $index_hint = '';
     $join = '';
     $where = '';
     $group_by = '';
     $having = '';
     $order_by = '';
     $topic_where = '';
     $topic_queries = array('topic_author_id', 'topic_author', 'topic_status', 'post_count', 'tag_count', 'started', 'updated', 'open', 'sticky', 'meta_key', 'meta_value', 'topic_title');
     if (!$_part_of_topic_query && array_diff($topic_queries, $this->not_set)) {
         $join .= " JOIN {$bbdb->topics} as t ON ( t.topic_id = p.topic_id )";
         $topic_where = $this->generate_topic_sql(true);
     }
     if (!$_part_of_topic_query) {
         if ($q['post_id']) {
             $where .= $this->parse_value('p.post_id', $q['post_id']);
         }
         if ($q['topic_id']) {
             $where .= $this->parse_value('p.topic_id', $q['topic_id']);
         } elseif ($q['topic']) {
             if (!($q['topic_id'] = bb_get_id_from_slug('topic', $q['topic']))) {
                 $this->error('query_var:topic', 'No topic by that name');
             }
             $where .= " AND p.topic_id = " . $q['topic_id'];
         }
         if ($q['forum_id']) {
             $where .= $this->parse_value('p.forum_id', $q['forum_id']);
         } elseif ($q['forum']) {
             if (!($q['forum_id'] = bb_get_id_from_slug('forum', $q['forum']))) {
                 $this->error('query_var:forum', 'No forum by that name');
             }
             $where .= " AND p.forum_id = " . $q['forum_id'];
         }
         if ($q['tag'] && !is_int($q['tag_id'])) {
             $q['tag_id'] = (int) bb_get_tag_id($q['tag']);
         }
         if (is_numeric($q['tag_id'])) {
             $join .= " JOIN `{$bbdb->term_relationships}` AS tr ON ( p.`topic_id` = tr.`object_id` AND tr.`term_taxonomy_id` = {$q['tag_id']} )";
         }
         if (is_numeric($q['favorites']) && ($f_user = bb_get_user($q['favorites']))) {
             $where .= $this->parse_value('p.topic_id', $f_user->favorites);
         }
     }
     // !_part_of_topic_query
     if ($q['post_text']) {
         $where .= ' AND ' . $this->generate_post_text_sql($q['post_text']);
         if ($this->match_query) {
             $fields .= ", {$this->match_query} AS search_score";
             if (!$q['order_by']) {
                 $q['order_by'] = 'search_score';
             }
         } else {
             $fields .= ', 0 AS search_score';
         }
     }
     if ($q['posted']) {
         $where .= $this->date('p.post_time', $q['posted']);
     }
     if ($q['post_author_id']) {
         $where .= $this->parse_value('p.poster_id', $q['post_author_id']);
     } elseif ($q['post_author']) {
         $user = bb_get_user($q['post_author'], array('by' => 'login'));
         if (!($q['post_author_id'] = (int) $user->ID)) {
             $this->error('query_var:user', 'No user by that name');
         }
         $where .= " AND p.poster_id = {$q['post_author_id']}";
     }
     if (!$q['post_status']) {
         $where .= " AND p.post_status = '0'";
     } elseif (false === strpos($q['post_status'], 'all')) {
         $stati = array('normal' => 0, 'deleted' => 1);
         $q['post_status'] = str_replace(array_keys($stati), array_values($stati), $q['post_status']);
         $where .= $this->parse_value('p.post_status', $q['post_status']);
     }
     if (false !== $q['position']) {
         $where .= $this->parse_value('p.post_position', $q['position']);
     }
     if (false !== $q['poster_ip']) {
         $where .= " AND poster_ip = '" . $q['poster_ip'] . "'";
     }
     // Just getting post part for inclusion in topic query
     if ($_part_of_topic_query) {
         return $where;
     }
     $where .= $topic_where;
     if ($where) {
         // Get rid of initial " AND " (this is pre-filters)
         $where = substr($where, 5);
     }
     if ($q['index_hint']) {
         $index_hint = $q['index_hint'];
     }
     if ($q['order_by']) {
         $order_by = $q['order_by'];
     } else {
         $order_by = 'p.post_time';
     }
     $bits = compact(array('distinct', 'sql_calc_found_rows', 'fields', 'index_hint', 'join', 'where', 'group_by', 'having', 'order_by'));
     $this->request = $this->_filter_sql($bits, "{$bbdb->posts} AS p");
     return $this->request;
 }
コード例 #2
0
function bp_forums_get_topic_id_from_slug($topic_slug)
{
    do_action('bbpress_init');
    if (empty($topic_slug)) {
        return false;
    }
    return bb_get_id_from_slug('topic', $topic_slug);
}
コード例 #3
0
/**
 * Get the numeric ID of a topic from the topic slug.
 *
 * Wrapper for {@link bb_get_id_from_slug()}.
 *
 * @param string $topic_slug Slug of the topic.
 * @return int|bool ID of the topic (if found), false on failure.
 */
function bp_forums_get_topic_id_from_slug($topic_slug)
{
    /** This action is documented in bp-forums/bp-forums-screens */
    do_action('bbpress_init');
    if (empty($topic_slug)) {
        return false;
    }
    return bb_get_id_from_slug('topic', $topic_slug);
}
コード例 #4
0
ファイル: bp-forums.php プロジェクト: n-sane/zaroka
function bp_forums_get_topic_id_from_slug( $topic_slug ) {
	do_action( 'bbpress_init' );
	return bb_get_id_from_slug( 'topic', $topic_slug );
}