Changeset 5683 for trunk/bp-core/bp-core-classes.php
- Timestamp:
- 02/09/2012 09:38:45 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-classes.php
r5595 r5683 137 137 * Populate the instantiated class with data based on the User ID provided. 138 138 * 139 * @global object $bp Global BuddyPress settings object140 139 * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id 141 140 * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text … … 146 145 */ 147 146 function populate() { 148 global $bp;149 147 150 148 if ( bp_is_active( 'xprofile' ) ) … … 178 176 /** 179 177 * Populates extra fields such as group and friendship counts. 180 *181 * @global object $bp Global BuddyPress settings object182 178 */ 183 179 function populate_extras() { 184 global $bp; 185 186 if ( bp_is_active( 'friends' ) ) 180 181 if ( bp_is_active( 'friends' ) ) { 187 182 $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id ); 183 } 188 184 189 185 if ( bp_is_active( 'groups' ) ) { … … 206 202 $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email"; 207 203 208 if ( 'active' == $type || 'online' == $type || 'newest' == $type ) 204 if ( 'active' == $type || 'online' == $type || 'newest' == $type ) { 209 205 $sql['select_active'] = ", um.meta_value as last_activity"; 210 211 if ( 'popular' == $type ) 206 } 207 208 if ( 'popular' == $type ) { 212 209 $sql['select_popular'] = ", um.meta_value as total_friend_count"; 213 214 if ( 'alphabetical' == $type ) 210 } 211 212 if ( 'alphabetical' == $type ) { 215 213 $sql['select_alpha'] = ", pd.value as fullname"; 214 } 216 215 217 216 if ( $meta_key ) { 218 217 $sql['select_meta'] = ", umm.meta_key"; 219 218 220 if ( $meta_value ) 219 if ( $meta_value ) { 221 220 $sql['select_meta'] .= ", umm.meta_value"; 221 } 222 222 } 223 223 … … 225 225 226 226 // We search against xprofile fields, so we must join the table 227 if ( $search_terms && bp_is_active( 'xprofile' ) ) 227 if ( $search_terms && bp_is_active( 'xprofile' ) ) { 228 228 $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id"; 229 } 229 230 230 231 // Alphabetical sorting is done by the xprofile Full Name field 231 if ( 'alphabetical' == $type ) 232 if ( 'alphabetical' == $type ) { 232 233 $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; 233 234 if ( $meta_key ) 234 } 235 236 if ( $meta_key ) { 235 237 $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID"; 238 } 236 239 237 240 $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' ); 238 241 239 if ( 'active' == $type || 'online' == $type || 'newest' == $type ) 242 if ( 'active' == $type || 'online' == $type || 'newest' == $type ) { 240 243 $sql['where_active'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) ); 241 242 if ( 'popular' == $type ) 244 } 245 246 if ( 'popular' == $type ) { 243 247 $sql['where_popular'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) ); 244 245 if ( 'online' == $type ) 248 } 249 250 if ( 'online' == $type ) { 246 251 $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()"; 247 248 if ( 'alphabetical' == $type ) 252 } 253 254 if ( 'alphabetical' == $type ) { 249 255 $sql['where_alpha'] = "AND pd.field_id = 1"; 250 251 if ( !empty( $exclude ) ) 256 } 257 258 if ( !empty( $exclude ) ) { 252 259 $sql['where_exclude'] = "AND u.ID NOT IN ({$exclude})"; 260 } 253 261 254 262 if ( $include ) { 255 if ( is_array( $include ) ) 263 if ( is_array( $include ) ) { 256 264 $uids = $wpdb->escape( implode( ',', (array)$include ) ); 257 else265 } else { 258 266 $uids = $wpdb->escape( $include ); 259 260 if ( !empty( $uids ) ) 267 } 268 269 if ( !empty( $uids ) ) { 261 270 $sql['where_users'] = "AND u.ID IN ({$uids})"; 262 } 263 264 else if ( $user_id && bp_is_active( 'friends' ) ) { 271 } 272 } elseif ( $user_id && bp_is_active( 'friends' ) ) { 265 273 $friend_ids = friends_get_friend_user_ids( $user_id ); 266 274 $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) ); 267 275 268 if ( !empty( $friend_ids ) ) 276 if ( !empty( $friend_ids ) ) { 269 277 $sql['where_friends'] = "AND u.ID IN ({$friend_ids})"; 270 278 271 279 // User has no friends, return false since there will be no users to fetch. 272 else280 } else { 273 281 return false; 274 282 } 275 283 } 276 284 … … 307 315 } 308 316 309 if ( $limit && $page ) 317 if ( $limit && $page ) { 310 318 $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 319 } 311 320 312 321 // Get paginated results … … 317 326 unset( $sql['select_main'] ); 318 327 319 if ( !empty( $sql['select_active'] ) ) 328 if ( !empty( $sql['select_active'] ) ) { 320 329 unset( $sql['select_active'] ); 321 322 if ( !empty( $sql['select_popular'] ) ) 330 } 331 332 if ( !empty( $sql['select_popular'] ) ) { 323 333 unset( $sql['select_popular'] ); 324 325 if ( !empty( $sql['select_alpha'] ) ) 334 } 335 336 if ( !empty( $sql['select_alpha'] ) ) { 326 337 unset( $sql['select_alpha'] ); 327 328 if ( !empty( $sql['pagination'] ) ) 338 } 339 340 if ( !empty( $sql['pagination'] ) ) { 329 341 unset( $sql['pagination'] ); 342 } 330 343 331 344 array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" ); … … 342 355 $user_ids = array(); 343 356 344 foreach ( (array)$paged_users as $user ) 357 foreach ( (array)$paged_users as $user ) { 345 358 $user_ids[] = $user->id; 359 } 346 360 347 361 $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) ); … … 372 386 373 387 $pag_sql = ''; 374 if ( $limit && $page ) 388 if ( $limit && $page ) { 375 389 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 390 } 376 391 377 392 // Multibyte compliance … … 398 413 399 414 /*** 400 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list. 401 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join) 415 * Lets fetch some other useful data in a separate queries, this will be 416 * faster than querying the data for every user in a list. We can't add 417 * these to the main query above since only users who have this 418 * information will be returned (since the much of the data is in 419 * usermeta and won't support any type of directional join) 402 420 */ 403 421 $user_ids = array(); … … 407 425 $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) ); 408 426 409 / * Add additional data to the returned results */410 if ( $populate_extras ) 427 // Add additional data to the returned results 428 if ( $populate_extras ) { 411 429 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); 430 } 412 431 413 432 return array( 'users' => $paged_users, 'total' => $total_users ); … … 417 436 * Get details of specific users from the database 418 437 * 419 * @global object $bp Global BuddyPress settings object420 438 * @global wpdb $wpdb WordPress database object 421 439 * @param array $user_ids The user IDs of the users who we wish to fetch information on. … … 427 445 */ 428 446 function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) { 429 global $ bp, $wpdb;447 global $wpdb; 430 448 431 449 $pag_sql = ''; … … 433 451 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 434 452 453 // @todo remove? $user_sql is not used here 435 454 $user_sql = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) "; 436 455 $status_sql = bp_core_get_status_sql(); … … 443 462 444 463 /*** 445 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list. 446 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join) 464 * Lets fetch some other useful data in a separate queries, this will be 465 * faster than querying the data for every user in a list. We can't add 466 * these to the main query above since only users who have this 467 * information will be returned (since the much of the data is in 468 * usermeta and won't support any type of directional join) 447 469 */ 448 470 449 / * Add additional data to the returned results */450 if ( $populate_extras )471 // Add additional data to the returned results 472 if ( !empty( $populate_extras ) ) { 451 473 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); 474 } 452 475 453 476 return array( 'users' => $paged_users, 'total' => $total_users ); … … 1028 1051 1029 1052 // Wrapper ID 1030 if ( !empty( $wrapper_id ) ) 1053 if ( !empty( $wrapper_id ) ) { 1031 1054 $this->wrapper_id = ' id="' . $wrapper_id . '"'; 1055 } 1032 1056 1033 1057 // Wrapper class 1034 if ( !empty( $wrapper_class ) ) 1058 if ( !empty( $wrapper_class ) ) { 1035 1059 $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"'; 1036 else1060 } else { 1037 1061 $this->wrapper_class = ' class="generic-button"'; 1062 } 1038 1063 1039 1064 // Set before and after … … 1174 1199 foreach ( $handlers as $hid => $handler ) { 1175 1200 if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { 1176 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) 1201 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) { 1177 1202 return apply_filters( 'embed_handler_html', $return, $url, $attr ); 1203 } 1178 1204 } 1179 1205 }
Note: See TracChangeset
for help on using the changeset viewer.