Changeset 867
- Timestamp:
- 06/20/07 19:03:53 (1 year ago)
- Files:
-
- branches/0.8/bb-admin/admin-functions.php (modified) (2 diffs)
- branches/0.8/bb-includes/bozo.php (modified) (2 diffs)
- branches/0.8/bb-includes/functions.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/0.8/bb-admin/admin-functions.php
r850 r867 170 170 171 171 function 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; 173 173 $sort = $sort ? 'DESC' : 'ASC'; 174 174 $key = $bb_table_prefix . 'capabilities'; … … 177 177 else 178 178 $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) ) 180 181 bb_cache_users( $ids ); 181 182 return $ids; branches/0.8/bb-includes/bozo.php
r827 r867 17 17 // Gets those users with the bozo bit. Does not grab users who have been bozoed on a specific topic. 18 18 function bb_get_bozos( $page = 1 ) { 19 global $bbdb, $bb_table_prefix ;19 global $bbdb, $bb_table_prefix, $bb_last_countable_query; 20 20 $page = (int) $page; 21 21 $limit = bb_get_option('page_topics'); … … 23 23 $limit = ($limit * ($page - 1)) . ", $limit"; 24 24 $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) ) 26 27 bb_cache_users( $ids ); 27 28 return $ids; branches/0.8/bb-includes/functions.php
r863 r867 116 116 117 117 function get_latest_topics( $forum = 0, $page = 1, $exclude = '') { 118 global $bbdb ;118 global $bbdb, $bb_last_countable_query; 119 119 $forum = (int) $forum; 120 120 $page = (int) $page; … … 133 133 if ( 1 < $page ) 134 134 $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) ) 136 137 return bb_append_meta( $topics, 'topic' ); 137 138 else … … 140 141 141 142 function get_sticky_topics( $forum = 0, $display = 1 ) { 142 global $bbdb ;143 global $bbdb, $bb_last_countable_query; 143 144 if ( 1 != $display ) 144 145 return false; … … 151 152 $where = apply_filters('get_sticky_topics_where', $where); 152 153 $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) ) 154 156 return bb_append_meta( $stickies, 'topic' ); 155 157 else return false; … … 157 159 158 160 function get_recent_user_threads( $user_id ) { 159 global $bbdb, $page ;161 global $bbdb, $page, $bb_last_countable_query; 160 162 $limit = bb_get_option('page_topics'); 161 163 if ( 1 < $page ) … … 164 166 $where = apply_filters('get_recent_user_threads_where', 'AND topic_status = 0', $user_id); 165 167 $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) ) 167 170 $topics = bb_append_meta( $topics, 'topic' ); 168 171 return $topics; … … 670 673 671 674 function get_recent_user_replies( $user_id ) { 672 global $bbdb, $bb_post_cache, $page ;675 global $bbdb, $bb_post_cache, $page, $bb_last_countable_query; 673 676 $limit = bb_get_option('page_topics'); 674 677 if ( 1 < $page ) … … 683 686 } 684 687 $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); 686 690 bb_append_meta( $topics, 'topic' ); 687 691 return $posts; … … 935 939 936 940 function get_tagged_topics( $tag_id, $page = 1 ) { 937 global $bbdb ;941 global $bbdb, $bb_last_countable_query; 938 942 if ( !$topic_ids = get_tagged_topic_ids( $tag_id ) ) 939 943 return false; … … 943 947 $limit = ($limit * ($page - 1)) . ", $limit"; 944 948 $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) ) 946 951 return bb_append_meta( $topics, 'topic' ); 947 952 else return false; … … 1927 1932 function bb_count_last_query() { 1928 1933 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( 1936 1943 array('/SELECT.*?\s+FROM/', '/LIMIT [0-9]+(\s*,\s*[0-9]+)?/', '/ORDER BY\s+[\S]+/', '/DESC/', '/ASC/'), 1937 1944 array('SELECT COUNT(*) FROM', ''), 1938 $ bb_last_countable_query1945 $q 1939 1946 ); 1940 1941 1947 $bb_last_countable_query = ''; 1942 return $bbdb->get_var($ bb_last_countable_query);1948 return $bbdb->get_var($q); 1943 1949 } 1944 1950 … … 2014 2020 /* Search Functions */ 2015 2021 function bb_user_search( $args = '' ) { 2016 global $bbdb ;2022 global $bbdb, $bb_last_countable_query; 2017 2023 2018 2024 if ( $args && is_string($args) && false === strpos($args, '=') ) … … 2044 2050 2045 2051 if ( $query && $user_meta ) : 2046 $ sql = "SELECT SQL_CALC_FOUND_ROWSuser_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')"; 2047 2053 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); 2050 2056 if ( empty($fields) ) : 2051 2057 bb_cache_users( $user_meta_ids ); … … 2070 2076 return new WP_Error( 'invalid-query', __('Your query parameters are invalid') ); 2071 2077 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"; 2073 2079 2074 2080 if ( ( $users = $bbdb->get_results($sql) ) && $append_meta ) … … 2079 2085 2080 2086 function bb_tag_search( $args = '' ) { 2081 global $page, $bbdb, $ tag_cache;2087 global $page, $bbdb, $bb_last_countable_query, $tag_cache; 2082 2088 2083 2089 if ( $args && is_string($args) && false === strpos($args, '=') ) … … 2099 2105 $likeit = preg_replace('/\s+/', '%', $query); 2100 2106 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 ) 2102 2110 $tag_cache[$tag->tag] = $tag; 2103 2111