Changeset 2077 for trunk/bp-core/bp-core-classes.php
- Timestamp:
- 11/02/2009 07:54:21 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-classes.php
r2055 r2077 3 3 * BP_Core_User class can be used by any component. It will fetch useful 4 4 * details for any user when provided with a user_id. 5 * 5 * 6 6 * Example: 7 7 * $user = new BP_Core_User( $user_id ); … … 10 10 * $user_status = $user->status; 11 11 * etc. 12 * 12 * 13 13 * @package BuddyPress Core 14 14 */ … … 20 20 var $fullname; 21 21 var $email; 22 22 23 23 var $user_url; 24 24 var $user_link; 25 25 26 26 var $last_active; 27 27 var $profile_last_updated; … … 31 31 var $total_blogs; 32 32 var $total_groups; 33 33 34 34 function bp_core_user( $user_id, $populate_extras = false ) { 35 35 if ( $user_id ) { 36 36 $this->id = $user_id; 37 37 $this->populate(); 38 38 39 39 if ( $populate_extras ) 40 40 $this->populate_extras(); 41 41 } 42 } 43 42 } 43 44 44 /** 45 45 * populate() 46 46 * 47 47 * Populate the instantiated class with data based on the User ID provided. 48 * 48 * 49 49 * @package BuddyPress Core 50 50 * @global $userdata WordPress user data for the current logged in user. … … 59 59 $this->user_url = bp_core_get_userurl( $this->id ); 60 60 $this->user_link = bp_core_get_userlink( $this->id ); 61 61 62 62 $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) ); 63 63 $this->email = attribute_escape( bp_core_get_user_email( $this->id ) ); … … 68 68 $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ); 69 69 } 70 70 71 71 function populate_extras() { 72 72 global $bp; 73 74 if ( function_exists('friends_install') ) { 73 74 if ( function_exists('friends_install') ) { 75 75 $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id ); 76 76 … … 80 80 else 81 81 $this->total_friends .= ' ' . __( 'friends', 'buddypress' ); 82 82 83 83 $this->total_friends = '<a href="' . $this->user_url . $bp->friends->slug . '" title="' . sprintf( __( "%s's friend list", 'buddypress' ), $this->fullname ) . '">' . $this->total_friends . '</a>'; 84 84 } 85 85 } 86 86 87 if ( function_exists('bp_blogs_install') ) { 87 if ( function_exists('bp_blogs_install') ) { 88 88 if ( $this->total_blogs ) { 89 89 if ( 1 == $this->total_blogs ) 90 90 $this->total_blogs .= ' ' . __( 'blog', 'buddypress' ); 91 91 else 92 $this->total_blogs .= ' ' . __( 'blogs', 'buddypress' ); 93 92 $this->total_blogs .= ' ' . __( 'blogs', 'buddypress' ); 93 94 94 $this->total_blogs = '<a href="' . $this->user_url . $bp->blogs->slug . '" title="' . sprintf( __( "%s's blog list", 'buddypress' ), $this->fullname ) . '">' . $this->total_blogs . '</a>'; 95 95 } 96 96 } 97 97 98 98 if ( function_exists('groups_install') ) { 99 99 $this->total_groups = BP_Groups_Member::total_group_count( $this->id ); 100 100 101 101 if ( $this->total_groups ) { 102 102 if ( 1 == $this->total_groups ) … … 109 109 } 110 110 } 111 111 112 112 /* Static Functions */ 113 113 114 114 function get_newest_users( $limit = null, $page = 1 ) { 115 115 global $wpdb; 116 117 if ( $limit && $page ) 118 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 119 116 117 if ( $limit && $page ) 118 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 119 120 120 $total_users_sql = apply_filters( 'bp_core_newest_users_count_sql', "SELECT DISTINCT count(ID) FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC" ); 121 121 $paged_users_sql = apply_filters( 'bp_core_newest_users_sql', "SELECT DISTINCT ID as user_id, DATE_ADD( user_registered, INTERVAL " . get_option('gmt_offset') . " HOUR ) as user_registered FROM " . CUSTOM_USER_TABLE . " WHERE spam = 0 AND deleted = 0 AND user_status = 0 ORDER BY user_registered DESC{$pag_sql}", $pag_sql ); 122 123 $total_users = $wpdb->get_var( $total_users_sql ); 124 $paged_users = $wpdb->get_results( $paged_users_sql ); 125 126 return array( 'users' => $paged_users, 'total' => $total_users ); 127 } 128 122 123 $total_users = $wpdb->get_var( $total_users_sql ); 124 $paged_users = $wpdb->get_results( $paged_users_sql ); 125 126 return array( 'users' => $paged_users, 'total' => $total_users ); 127 } 128 129 129 function get_active_users( $limit = null, $page = 1 ) { 130 130 global $wpdb; … … 135 135 $total_users_sql = apply_filters( 'bp_core_active_users_count_sql', "SELECT DISTINCT count(um.user_id) FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY FROM_UNIXTIME(um.meta_value) DESC" ); 136 136 $paged_users_sql = apply_filters( 'bp_core_active_users_sql', "SELECT DISTINCT user_id FROM " . CUSTOM_USER_META_TABLE . " um LEFT JOIN " . CUSTOM_USER_TABLE . " u ON u.ID = um.user_id WHERE um.meta_key = 'last_activity' AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}", $pag_sql ); 137 138 $total_users = $wpdb->get_var( $total_users_sql ); 139 $paged_users = $wpdb->get_results( $paged_users_sql ); 140 137 138 $total_users = $wpdb->get_var( $total_users_sql ); 139 $paged_users = $wpdb->get_results( $paged_users_sql ); 140 141 141 return array( 'users' => $paged_users, 'total' => $total_users ); 142 142 } … … 144 144 function get_popular_users( $limit = null, $page = 1 ) { 145 145 global $wpdb; 146 146 147 147 if ( !function_exists('friends_install') ) 148 148 return false; 149 149 150 150 if ( $limit && $page ) 151 151 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 156 156 $total_users = $wpdb->get_var( $total_users_sql ); 157 157 $paged_users = $wpdb->get_results( $paged_users_sql ); 158 159 return array( 'users' => $paged_users, 'total' => $total_users ); 160 } 161 158 159 return array( 'users' => $paged_users, 'total' => $total_users ); 160 } 161 162 162 function get_random_users( $limit = null, $page = 1 ) { 163 163 global $wpdb, $bp; 164 164 165 165 if ( $limit && $page ) 166 166 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 171 171 $total_users = $wpdb->get_var( $total_users_sql ); 172 172 $paged_users = $wpdb->get_results( $paged_users_sql ); 173 174 return array( 'users' => $paged_users, 'total' => $total_users ); 175 } 176 173 174 return array( 'users' => $paged_users, 'total' => $total_users ); 175 } 176 177 177 function get_online_users( $limit = null, $page = 1 ) { 178 178 global $wpdb; 179 179 180 180 if ( $limit && $page ) 181 181 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 189 189 return array( 'users' => $paged_users, 'total' => $total_users ); 190 190 } 191 191 192 192 function get_alphabetical_users( $limit = null, $page = 1 ) { 193 193 global $wpdb, $bp; … … 195 195 if ( !function_exists( 'xprofile_install' ) ) 196 196 return BP_Core_User::get_active_users( $limit, $page ); 197 197 198 198 if ( $limit && $page ) 199 199 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 207 207 return array( 'users' => $paged_users, 'total' => $total_users ); 208 208 } 209 209 210 210 function get_users_by_letter( $letter, $limit = null, $page = 1 ) { 211 211 global $wpdb, $bp; 212 212 213 213 if ( !function_exists('xprofile_install') ) 214 214 return BP_Core_User::get_active_users( $limit, $page ); 215 216 if ( $limit && $page ) 217 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 218 215 216 if ( $limit && $page ) 217 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 218 219 219 if ( strlen($letter) > 1 || is_numeric($letter) || !$letter ) 220 220 return false; 221 221 222 222 $letter = like_escape( $wpdb->escape( $letter ) ); 223 223 … … 227 227 $total_users = $wpdb->get_var( $total_users_sql ); 228 228 $paged_users = $wpdb->get_results( $paged_users_sql ); 229 230 return array( 'users' => $paged_users, 'total' => $total_users ); 231 } 232 229 230 return array( 'users' => $paged_users, 'total' => $total_users ); 231 } 232 233 233 function search_users( $search_terms, $limit = null, $page = 1 ) { 234 234 global $wpdb, $bp; 235 235 236 236 if ( !function_exists('xprofile_install') ) 237 237 return BP_Core_User::get_active_users( $limit, $page ); 238 239 if ( $limit && $page ) 240 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 241 242 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 238 239 if ( $limit && $page ) 240 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 241 242 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 243 243 244 244 $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT DISTINCT count(u.ID) as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms ); … … 247 247 $total_users = $wpdb->get_var( $total_users_sql ); 248 248 $paged_users = $wpdb->get_results( $paged_users_sql ); 249 249 250 250 return array( 'users' => $paged_users, 'total' => $total_users ); 251 251 } … … 256 256 * BP_Core_Notification class can be used by any component. 257 257 * It will handle the fetching, saving and deleting of a user notification. 258 * 258 * 259 259 * @package BuddyPress Core 260 260 */ … … 269 269 var $date_notified; 270 270 var $is_new; 271 271 272 272 function bp_core_notification( $id = false ) { 273 273 if ( $id ) { … … 276 276 } 277 277 } 278 278 279 279 function populate() { 280 280 global $wpdb, $bp; 281 281 282 282 if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) { 283 283 $this->item_id = $notification->item_id; … … 289 289 $this->is_new = $notification->is_new; 290 290 } 291 } 292 291 } 292 293 293 function save() { 294 294 global $wpdb, $bp; 295 295 296 296 if ( $this->id ) { 297 297 // Update … … 310 310 311 311 /* Static functions */ 312 312 313 313 function check_access( $user_id, $notification_id ) { 314 314 global $wpdb, $bp; 315 315 316 316 return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) ); 317 317 } 318 318 319 319 function get_all_for_user( $user_id ) { 320 320 global $wpdb, $bp; … … 322 322 return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) ); 323 323 } 324 324 325 325 function delete_for_user_by_type( $user_id, $component_name, $component_action ) { 326 326 global $wpdb, $bp; 327 327 328 328 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) ); 329 329 } 330 330 331 331 function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) { 332 332 global $wpdb, $bp; 333 333 334 334 if ( $secondary_item_id ) 335 335 $secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ); 336 336 337 337 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) ); 338 338 } 339 339 340 340 function delete_from_user_by_type( $user_id, $component_name, $component_action ) { 341 341 global $wpdb, $bp; 342 342 343 343 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) ); 344 344 } 345 345 346 346 function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) { 347 347 global $wpdb, $bp; 348 348 349 349 if ( $component_action ) 350 350 $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action ); 351 351 352 352 if ( $secondary_item_id ) 353 353 $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id ); 354 354 355 355 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) ); 356 356 } 357 } 357 } 358 358 359 359
Note: See TracChangeset
for help on using the changeset viewer.