Changeset 867

Show
Ignore:
Timestamp:
06/20/07 19:03:53 (1 year ago)
Author:
mdawaffe
Message:

Back out [827] in branches/0.8. Fixes #666. See #665

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/0.8/bb-admin/admin-functions.php

    r850 r867  
    170170 
    171171function bb_get_ids_by_role( $role = 'moderator', $sort = 0, $limit_str = '' ) { 
    172         global $bbdb, $bb_table_prefix
     172        global $bbdb, $bb_table_prefix, $bb_last_countable_query
    173173        $sort = $sort ? 'DESC' : 'ASC'; 
    174174        $key = $bb_table_prefix . 'capabilities'; 
     
    177177        else 
    178178                $and_where = "meta_value LIKE '%$role%'"; 
    179         if ( $ids = (array) $bbdb->get_col("SELECT SQL_CALC_FOUND_ROWS user_id FROM $bbdb->usermeta WHERE meta_key = '$key' AND $and_where ORDER BY user_id $sort" . $limit_str) ) 
     179        $bb_last_countable_query = "SELECT user_id FROM $bbdb->usermeta WHERE meta_key = '$key' AND $and_where ORDER BY user_id $sort" . $limit_str; 
     180        if ( $ids = (array) $bbdb->get_col($bb_last_countable_query) ) 
    180181                bb_cache_users( $ids ); 
    181182        return $ids; 
  • branches/0.8/bb-includes/bozo.php

    r827 r867  
    1717// Gets those users with the bozo bit.  Does not grab users who have been bozoed on a specific topic. 
    1818function bb_get_bozos( $page = 1 ) { 
    19         global $bbdb, $bb_table_prefix
     19        global $bbdb, $bb_table_prefix, $bb_last_countable_query
    2020        $page = (int) $page; 
    2121        $limit = bb_get_option('page_topics'); 
     
    2323                $limit = ($limit * ($page - 1)) . ", $limit"; 
    2424        $bozo_mkey = $bb_table_prefix . 'bozo_topics'; 
    25         if ( $ids = (array) $bbdb->get_col("SELECT SQL_CALC_FOUND_ROWS user_id FROM $bbdb->usermeta WHERE meta_key='is_bozo' AND meta_value='1' ORDER BY umeta_id DESC LIMIT $limit") ) 
     25        $bb_last_countable_query = "SELECT user_id FROM $bbdb->usermeta WHERE meta_key='is_bozo' AND meta_value='1' ORDER BY umeta_id DESC LIMIT $limit"; 
     26        if ( $ids = (array) $bbdb->get_col($bb_last_countable_query) ) 
    2627                bb_cache_users( $ids ); 
    2728        return $ids; 
  • branches/0.8/bb-includes/functions.php

    r863 r867  
    116116 
    117117function get_latest_topics( $forum = 0, $page = 1, $exclude = '') { 
    118         global $bbdb
     118        global $bbdb, $bb_last_countable_query
    119119        $forum = (int) $forum; 
    120120        $page = (int) $page; 
     
    133133        if ( 1 < $page ) 
    134134                $limit = ($limit * ($page - 1)) . ", $limit"; 
    135         if ( $topics = $bbdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $bbdb->topics $where ORDER BY $order_by LIMIT $limit") ) 
     135        $bb_last_countable_query = "SELECT * FROM $bbdb->topics $where ORDER BY $order_by LIMIT $limit"; 
     136        if ( $topics = $bbdb->get_results($bb_last_countable_query) ) 
    136137                return bb_append_meta( $topics, 'topic' ); 
    137138        else 
     
    140141 
    141142function get_sticky_topics( $forum = 0, $display = 1 ) { 
    142         global $bbdb
     143        global $bbdb, $bb_last_countable_query
    143144        if ( 1 != $display ) 
    144145                return false; 
     
    151152        $where = apply_filters('get_sticky_topics_where', $where); 
    152153        $order_by = apply_filters('get_sticky_topics_order_by', 'topic_time DESC' ); 
    153         if ( $stickies = $bbdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $bbdb->topics $where ORDER BY $order_by") ) 
     154        $bb_last_countable_query = "SELECT * FROM $bbdb->topics $where ORDER BY $order_by"; 
     155        if ( $stickies = $bbdb->get_results($bb_last_countable_query) ) 
    154156                return bb_append_meta( $stickies, 'topic' );     
    155157        else    return false; 
     
    157159 
    158160function get_recent_user_threads( $user_id ) { 
    159         global $bbdb, $page
     161        global $bbdb, $page, $bb_last_countable_query
    160162        $limit = bb_get_option('page_topics'); 
    161163        if ( 1 < $page ) 
     
    164166        $where = apply_filters('get_recent_user_threads_where', 'AND topic_status = 0', $user_id); 
    165167        $order_by = apply_filters( 'get_recent_user_threads_order_by', 'topic_start_time DESC', $user_id); 
    166         if ( $topics = $bbdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $bbdb->topics $join WHERE topic_poster = $user_id $where ORDER BY $order_by LIMIT $limit") ) 
     168        $bb_last_countable_query = "SELECT * FROM $bbdb->topics $join WHERE topic_poster = $user_id $where ORDER BY $order_by LIMIT $limit"; 
     169        if ( $topics = $bbdb->get_results($bb_last_countable_query) ) 
    167170                $topics = bb_append_meta( $topics, 'topic' ); 
    168171        return $topics; 
     
    670673 
    671674function get_recent_user_replies( $user_id ) { 
    672         global $bbdb, $bb_post_cache, $page
     675        global $bbdb, $bb_post_cache, $page, $bb_last_countable_query
    673676        $limit = bb_get_option('page_topics'); 
    674677        if ( 1 < $page ) 
     
    683686                } 
    684687                $topic_ids = join(',', $topics); 
    685                 $topics = $bbdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $bbdb->topics WHERE topic_id IN ($topic_ids)"); 
     688                $bb_last_countable_query = "SELECT * FROM $bbdb->topics WHERE topic_id IN ($topic_ids)"; 
     689                $topics = $bbdb->get_results($bb_last_countable_query); 
    686690                bb_append_meta( $topics, 'topic' ); 
    687691                return $posts; 
     
    935939 
    936940function get_tagged_topics( $tag_id, $page = 1 ) { 
    937         global $bbdb
     941        global $bbdb, $bb_last_countable_query
    938942        if ( !$topic_ids = get_tagged_topic_ids( $tag_id ) ) 
    939943                return false; 
     
    943947                $limit = ($limit * ($page - 1)) . ", $limit"; 
    944948        $order_by = apply_filters('get_tagged_topics_order_by', 'topic_time DESC' ); 
    945         if ( $topics = $bbdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $bbdb->topics WHERE topic_id IN ($topic_ids) AND topic_status = 0 ORDER BY $order_by LIMIT $limit") ) 
     949        $bb_last_countable_query = "SELECT * FROM $bbdb->topics WHERE topic_id IN ($topic_ids) AND topic_status = 0 ORDER BY $order_by LIMIT $limit"; 
     950        if ( $topics = $bbdb->get_results($bb_last_countable_query) ) 
    946951                return bb_append_meta( $topics, 'topic' ); 
    947952        else    return false; 
     
    19271932function bb_count_last_query() { 
    19281933        global $bbdb, $bb_last_countable_query; 
    1929         if ( !$bb_last_countable_query ) 
    1930                 return $bbdb->get_var( "SELECT FOUND_ROWS()" ); 
    1931  
    1932         if ( false === strpos($bb_last_countable_query, 'SELECT') ) 
    1933                 return false; 
    1934  
    1935         $bb_last_countable_query = preg_replace( 
     1934        if ( $bb_last_countable_query ) 
     1935                $q = $bb_last_countable_query; 
     1936        else 
     1937                $q = $bbdb->last_query; 
     1938 
     1939        if ( false === strpos($q, 'SELECT') ) 
     1940                return false; 
     1941 
     1942        $q = preg_replace( 
    19361943                array('/SELECT.*?\s+FROM/', '/LIMIT [0-9]+(\s*,\s*[0-9]+)?/', '/ORDER BY\s+[\S]+/', '/DESC/', '/ASC/'), 
    19371944                array('SELECT COUNT(*) FROM', ''), 
    1938                 $bb_last_countable_query 
     1945                $q 
    19391946        ); 
    1940  
    19411947        $bb_last_countable_query = ''; 
    1942         return $bbdb->get_var($bb_last_countable_query); 
     1948        return $bbdb->get_var($q); 
    19431949} 
    19441950 
     
    20142020/* Search Functions */ 
    20152021function bb_user_search( $args = '' ) { 
    2016         global $bbdb
     2022        global $bbdb, $bb_last_countable_query
    20172023 
    20182024        if ( $args && is_string($args) && false === strpos($args, '=') ) 
     
    20442050 
    20452051        if ( $query && $user_meta ) : 
    2046                 $sql = "SELECT SQL_CALC_FOUND_ROWS user_id FROM $bbdb->usermeta WHERE meta_value LIKE ('%$likeit')"; 
     2052                $bb_last_countable_query = "SELECT user_id FROM $bbdb->usermeta WHERE meta_value LIKE ('%$likeit')"; 
    20472053                if ( empty($fields) ) 
    2048                         $sql .= " LIMIT $limit"; 
    2049                 $user_meta_ids = $bbdb->get_col($sql); 
     2054                        $bb_last_countable_query .= " LIMIT $limit"; 
     2055                $user_meta_ids = $bbdb->get_col($bb_last_countable_query); 
    20502056                if ( empty($fields) ) : 
    20512057                        bb_cache_users( $user_meta_ids ); 
     
    20702076                return new WP_Error( 'invalid-query', __('Your query parameters are invalid') ); 
    20712077 
    2072         $sql .= ( $sql_terms ? ' WHERE ' . implode(' OR ', $sql_terms) : '' ) . " LIMIT $limit"; 
     2078        $bb_last_countable_query = $sql .= ( $sql_terms ? ' WHERE ' . implode(' OR ', $sql_terms) : '' ) . " LIMIT $limit"; 
    20732079 
    20742080        if ( ( $users = $bbdb->get_results($sql) ) && $append_meta ) 
     
    20792085 
    20802086function bb_tag_search( $args = '' ) { 
    2081         global $page, $bbdb, $tag_cache; 
     2087        global $page, $bbdb, $bb_last_countable_query, $tag_cache; 
    20822088 
    20832089        if ( $args && is_string($args) && false === strpos($args, '=') ) 
     
    20992105        $likeit = preg_replace('/\s+/', '%', $query); 
    21002106 
    2101         foreach ( (array) $tags = $bbdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $bbdb->tags WHERE raw_tag LIKE ('%$likeit%') LIMIT $limit" ) as $tag ) 
     2107        $bb_last_countable_query = "SELECT * FROM $bbdb->tags WHERE raw_tag LIKE ('%$likeit%') LIMIT $limit"; 
     2108 
     2109        foreach ( (array) $tags = $bbdb->get_results( $bb_last_countable_query ) as $tag ) 
    21022110                $tag_cache[$tag->tag] = $tag; 
    21032111