Changeset 2077
- Timestamp:
- 11/02/2009 07:54:21 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 118 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity.php
r2002 r2077 14 14 /* Include deprecated functions if settings allow */ 15 15 if ( !defined( 'BP_IGNORE_DEPRECATED' ) ) 16 require ( BP_PLUGIN_DIR . '/bp-activity/deprecated/bp-activity-deprecated.php' ); 17 16 require ( BP_PLUGIN_DIR . '/bp-activity/deprecated/bp-activity-deprecated.php' ); 17 18 18 function bp_activity_install() { 19 19 global $wpdb, $bp; 20 20 21 21 if ( !empty($wpdb->charset) ) 22 22 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 23 23 24 24 $sql[] = "CREATE TABLE {$bp->activity->table_name} ( 25 25 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 41 41 require_once( ABSPATH . 'wp-admin/upgrade-functions.php' ); 42 42 dbDelta($sql); 43 43 44 44 /* Drop the old sitewide and user activity tables */ 45 45 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->base_prefix}bp_activity_user_activity" ); 46 46 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->base_prefix}bp_activity_sitewide" ); 47 47 48 48 /* TODO: Rename the old user activity cached table */ 49 49 //$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" ); … … 57 57 /* Internal identifier */ 58 58 $bp->activity->id = 'activity'; 59 59 60 60 $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity_user_activity_cached'; 61 61 $bp->activity->slug = BP_ACTIVITY_SLUG; 62 62 63 63 /* Register this in the active components array */ 64 64 $bp->active_components[$bp->activity->slug] = $bp->activity->id; 65 65 66 66 do_action( 'bp_activity_setup_globals' ); 67 67 } … … 69 69 add_action( 'admin_menu', 'bp_activity_setup_globals', 2 ); 70 70 71 function bp_activity_check_installed() { 71 function bp_activity_check_installed() { 72 72 global $wpdb, $bp; 73 73 74 74 if ( get_site_option('bp-activity-db-version') < BP_ACTIVITY_DB_VERSION ) 75 75 bp_activity_install(); … … 100 100 } else { 101 101 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 102 $bp->bp_options_title = $bp->displayed_user->fullname; 102 $bp->bp_options_title = $bp->displayed_user->fullname; 103 103 } 104 104 } … … 120 120 function bp_activity_screen_my_activity() { 121 121 do_action( 'bp_activity_screen_my_activity' ); 122 bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'activity/just-me' ) ); 122 bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'activity/just-me' ) ); 123 123 } 124 124 125 125 function bp_activity_screen_friends_activity() { 126 126 do_action( 'bp_activity_screen_friends_activity' ); 127 bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'activity/my-friends' ) ); 127 bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'activity/my-friends' ) ); 128 128 } 129 129 … … 148 148 /* Check the nonce */ 149 149 check_admin_referer( 'bp_activity_delete_link' ); 150 150 151 151 $activity_id = $bp->action_variables[0]; 152 152 153 153 /* Check access */ 154 154 if ( !is_site_admin() ) { 155 155 $activity = new BP_Activity_Activity( $activity_id ); 156 156 157 157 if ( $activity->user_id != $bp->loggedin_user->id ) 158 158 return false; 159 159 } 160 160 161 161 /* Now delete the activity item */ 162 162 if ( bp_activity_delete_by_activity_id( $activity_id ) ) … … 164 164 else 165 165 bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' ); 166 166 167 167 do_action( 'bp_activity_action_delete_activity', $activity_id ); 168 168 169 169 bp_core_redirect( $_SERVER['HTTP_REFERER'] ); 170 170 } … … 187 187 188 188 function bp_activity_action_personal_feed() { 189 global $bp, $wp_query; 189 global $bp, $wp_query; 190 190 191 191 if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' ) 192 192 return false; 193 193 194 194 $wp_query->is_404 = false; 195 195 status_header( 200 ); … … 206 206 return false; 207 207 208 $wp_query->is_404 = false; 208 $wp_query->is_404 = false; 209 209 status_header( 200 ); 210 210 211 211 include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' ); 212 die; 212 die; 213 213 } 214 214 add_action( 'wp', 'bp_activity_action_friends_feed', 3 ); … … 226 226 function bp_activity_add( $args = '' ) { 227 227 global $bp, $wpdb; 228 228 229 229 $defaults = array( 230 230 'content' => false, // The content of the activity item … … 232 232 'component_name' => false, // The name/ID of the component e.g. groups, profile, mycomponent 233 233 'component_action' => false, // The component action e.g. new_wire_post, profile_updated 234 234 235 235 'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user. 236 236 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id, or wire_post_id … … 242 242 $r = wp_parse_args( $args, $defaults ); 243 243 extract( $r, EXTR_SKIP ); 244 244 245 245 /* Insert the "time-since" placeholder */ 246 246 if ( $content ) … … 257 257 $activity->date_recorded = $recorded_time; 258 258 $activity->hide_sitewide = $hide_sitewide; 259 259 260 260 if ( !$activity->save() ) 261 261 return false; 262 262 263 263 do_action( 'bp_activity_add', $args ); 264 264 265 265 return true; 266 266 } … … 296 296 do_action( 'bp_activity_delete_by_activity_id', $activity_id ); 297 297 298 return true; 298 return true; 299 299 } 300 300 … … 316 316 317 317 do_action( 'bp_activity_delete_for_user_by_component', $user_id, $component_name ); 318 318 319 319 return true; 320 320 } … … 322 322 function bp_activity_add_timesince_placeholder( $content ) { 323 323 /* Check a time-since span doesn't already exist */ 324 if ( false === strpos( $content, '<span class="time-since">' ) ) { 324 if ( false === strpos( $content, '<span class="time-since">' ) ) { 325 325 if ( !$pos = strpos( $content, '<blockquote' ) ) { 326 326 if ( !$pos = strpos( $content, '<div' ) ) { … … 331 331 } 332 332 } 333 333 334 334 if ( (int) $pos ) { 335 335 $before = substr( $content, 0, (int) $pos ); 336 336 $after = substr( $content, (int) $pos, strlen( $content ) ); 337 337 338 338 $content = $before . ' <span class="time-since">%s</span>' . $after; 339 339 } … … 342 342 } 343 343 344 function bp_activity_set_action( $component_id, $key, $value ) { 345 global $bp; 346 347 if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) 348 return false; 349 350 $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array( 351 'key' => $key, 352 'value' => $value 353 ), $component_id, $key, $value ); 354 } 355 356 function bp_activity_get_action( $component_id, $key ) { 357 global $bp; 358 359 if ( empty( $component_id ) || empty( $key ) ) 360 return false; 361 362 return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key ); 363 } 344 function bp_activity_set_action( $component_id, $key, $value ) { 345 global $bp; 346 347 if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) 348 return false; 349 350 $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array( 351 'key' => $key, 352 'value' => $value 353 ), $component_id, $key, $value ); 354 } 355 356 function bp_activity_get_action( $component_id, $key ) { 357 global $bp; 358 359 if ( empty( $component_id ) || empty( $key ) ) 360 return false; 361 362 return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key ); 363 } 364 364 365 365 function bp_activity_check_exists_by_content( $content ) { … … 389 389 // Clear the user's activity from the sitewide stream and clear their activity tables 390 390 BP_Activity_Activity::delete_for_user( $user_id ); 391 391 392 392 do_action( 'bp_activity_remove_data', $user_id ); 393 393 } … … 398 398 /* Ordering function - don't call this directly */ 399 399 function bp_activity_order_by_date( $a, $b ) { 400 return apply_filters( 'bp_activity_order_by_date', strcasecmp( $b['date_recorded'], $a['date_recorded'] ) ); 400 return apply_filters( 'bp_activity_order_by_date', strcasecmp( $b['date_recorded'], $a['date_recorded'] ) ); 401 401 } 402 402 -
trunk/bp-activity/bp-activity-classes.php
r2036 r2077 11 11 var $date_recorded; 12 12 var $hide_sitewide = false; 13 13 14 14 function bp_activity_activity( $id = false ) { 15 15 global $bp; 16 16 17 17 if ( $id ) { 18 18 $this->id = $id; … … 20 20 } 21 21 } 22 22 23 23 function populate() { 24 24 global $wpdb, $bp; 25 25 26 26 $activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ); 27 27 28 28 $this->id = $activity->id; 29 29 $this->item_id = $activity->item_id; … … 37 37 $this->hide_sitewide = $activity->hide_sitewide; 38 38 } 39 39 40 40 function save() { 41 41 global $wpdb, $bp, $current_user; 42 42 43 43 do_action( 'bp_activity_before_save', $this ); 44 44 45 45 if ( !$this->component_name || !$this->component_action ) 46 46 return false; 47 47 48 48 /*** 49 49 * Before v1.1 of BuddyPress, activity content was calculated at a later point. This is no longer the … … 54 54 if ( !$fetched_content = call_user_func( $bp->{$this->component_name}->format_activity_function, $this->item_id, $this->user_id, $this->component_action, $this->secondary_item_id, $this->for_secondary_user ) ) 55 55 return false; 56 56 57 57 $this->content = $fetched_content['content']; 58 58 $this->primary_link = $fetched_content['primary_link']; 59 59 } 60 60 } 61 61 62 62 if ( !$this->primary_link ) 63 63 $this->primary_link = $bp->loggedin_user->domain; 64 64 65 65 if ( $existing_activity_id = $this->exists() ) 66 66 BP_Activity_Activity::delete_by_activity_id( $existing_activity_id ); 67 67 68 68 /* If we have an existing ID, update the activity item, otherwise insert it. */ 69 69 if ( $this->id ) { … … 81 81 return false; 82 82 } 83 83 84 84 function exists() { 85 85 global $wpdb, $bp; 86 86 87 87 /* This doesn't seem to be working correctly at the moment, so it is disabled [TODO] */ 88 88 return false; 89 89 90 90 /* If we have an item id, try and match on that, if not do a content match */ 91 91 if ( $this->item_id ) { 92 92 if ( $this->secondary_item_id ) 93 93 $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %s", $secondary_item_id ); 94 95 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) ); 94 95 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) ); 96 96 } else { 97 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) ); 98 } 99 } 100 101 /* Static Functions */ 97 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) ); 98 } 99 } 100 101 /* Static Functions */ 102 102 103 103 function delete( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) { … … 106 106 if ( $secondary_item_id ) 107 107 $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id ); 108 108 109 109 if ( $component_action ) 110 110 $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action ); 111 111 112 112 if ( $user_id ) 113 113 $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id ); … … 115 115 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) ); 116 116 } 117 117 118 118 function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) { 119 119 return BP_Activity_Activity::delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ); … … 122 122 function delete_by_activity_id( $activity_id ) { 123 123 global $bp, $wpdb; 124 124 125 125 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE id = %d", $activity_id ) ); 126 126 } 127 127 128 128 function delete_by_content( $user_id, $content, $component_name, $component_action ) { 129 129 global $bp, $wpdb; 130 131 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) ); 132 } 133 130 131 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $user_id, $content, $component_name, $component_action ) ); 132 } 133 134 134 function delete_for_user_by_component( $user_id, $component_name ) { 135 135 global $bp, $wpdb; 136 137 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) ); 138 } 139 136 137 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d AND component_name = %s", $user_id, $component_name ) ); 138 } 139 140 140 function delete_for_user( $user_id ) { 141 141 global $wpdb, $bp; … … 143 143 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE user_id = %d", $user_id ) ); 144 144 } 145 145 146 146 function get_activity_for_user( $user_id, $max_items, $limit, $page, $filter ) { 147 147 global $wpdb, $bp; 148 148 149 149 if ( $limit && $page ) 150 150 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); … … 152 152 if ( $max_items ) 153 153 $max_sql = $wpdb->prepare( "LIMIT %d", $max_items ); 154 154 155 155 /* Sort out filtering */ 156 156 if ( $filter ) 157 157 $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ); 158 158 159 159 if ( $limit && $page && $max_items ) 160 160 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql", $user_id ) ); 161 161 else 162 162 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id ) ); 163 163 164 164 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id ) ); 165 165 166 166 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 167 167 } 168 168 169 169 function get_activity_for_friends( $user_id, $max_items, $max_items_per_friend, $limit, $page, $filter ) { 170 170 global $wpdb, $bp; 171 171 172 172 // TODO: Max items per friend not yet implemented. 173 173 174 174 if ( !function_exists('friends_get_friend_user_ids') ) 175 175 return false; … … 177 177 if ( $limit && $page ) 178 178 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 179 179 180 180 if ( $max_items ) 181 181 $max_sql = $wpdb->prepare( "LIMIT %d", $max_items ); … … 189 189 if ( !$friend_ids ) 190 190 return false; 191 191 192 192 $friend_ids = implode( ',', $friend_ids ); 193 193 194 194 if ( $limit && $page && $max_items ) 195 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql" ) ); 195 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql" ) ); 196 196 else 197 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) ); 198 199 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) ); 200 197 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT id, user_id, content, primary_link, date_recorded, component_name, component_action FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql" ) ); 198 199 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(user_id) FROM {$bp->activity->table_name} WHERE user_id IN ({$friend_ids}) $filter_sql ORDER BY date_recorded DESC $max_sql" ) ); 200 201 201 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 202 202 } 203 203 204 204 function get_sitewide_activity( $max, $limit, $page, $filter ) { 205 205 global $wpdb, $bp; 206 206 207 207 if ( $limit && $page ) 208 208 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 209 209 210 210 if ( $max ) 211 211 $max_sql = $wpdb->prepare( "LIMIT %d", $max ); 212 212 213 213 /* Sort out filtering */ 214 214 if ( $filter ) … … 224 224 return array( 'activities' => $activities, 'total' => (int)$total_activities ); 225 225 } 226 226 227 227 function get_recorded_component_names() { 228 228 global $wpdb, $bp; 229 229 230 230 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component_name FROM {$bp->activity->table_name} ORDER BY component_name ASC" ) ); 231 231 } 232 232 233 233 function get_sitewide_items_for_feed( $limit = 35 ) { 234 234 global $wpdb, $bp; 235 235 236 236 $activities = bp_activity_get_sitewide_activity( $limit ); 237 237 for ( $i = 0; $i < count($activities); $i++ ) { … … 244 244 } 245 245 246 return $activity_feed; 247 } 248 246 return $activity_feed; 247 } 248 249 249 function get_filter_sql( $filter_array ) { 250 250 global $wpdb; 251 251 252 252 if ( !empty( $filter_array['object'] ) ) { 253 253 $object_filter = explode( ',', $filter_array['object'] ); 254 254 $object_sql = ' AND ( '; 255 255 256 256 $counter = 1; 257 257 foreach( (array) $object_filter as $object ) { 258 258 $object_sql .= $wpdb->prepare( "component_name = %s", trim( $object ) ); 259 259 260 260 if ( $counter != count( $object_filter ) ) 261 261 $object_sql .= ' || '; 262 262 263 263 $counter++; 264 264 } 265 265 266 266 $object_sql .= ' )'; 267 267 } … … 270 270 $action_filter = explode( ',', $filter_array['action'] ); 271 271 $action_sql = ' AND ( '; 272 272 273 273 $counter = 1; 274 274 foreach( (array) $action_filter as $action ) { 275 275 $action_sql .= $wpdb->prepare( "component_action = %s", trim( $action ) ); 276 276 277 277 if ( $counter != count( $action_filter ) ) 278 278 $action_sql .= ' || '; 279 279 280 280 $counter++; 281 281 } 282 282 283 283 $action_sql .= ' )'; 284 284 } … … 287 287 $pid_filter = explode( ',', $filter_array['primary_id'] ); 288 288 $pid_sql = ' AND ( '; 289 289 290 290 $counter = 1; 291 291 foreach( (array) $pid_filter as $pid ) { 292 292 $pid_sql .= $wpdb->prepare( "item_id = %s", trim( $pid ) ); 293 293 294 294 if ( $counter != count( $pid_filter ) ) 295 295 $pid_sql .= ' || '; 296 296 297 297 $counter++; 298 298 } 299 299 300 300 $pid_sql .= ' )'; 301 301 } … … 304 304 $sid_filter = explode( ',', $filter_array['secondary_id'] ); 305 305 $sid_sql = ' AND ( '; 306 306 307 307 $counter = 1; 308 308 foreach( (array) $sid_filter as $sid ) { 309 309 $sid_sql .= $wpdb->prepare( "secondary_item_id = %s", trim( $sid ) ); 310 310 311 311 if ( $counter != count( $sid_filter ) ) 312 312 $sid_sql .= ' || '; 313 313 314 314 $counter++; 315 315 } 316 316 317 317 $sid_sql .= ' )'; 318 318 } 319 319 320 320 return $object_sql . $action_sql . $pid_sql . $sid_sql; 321 321 } 322 322 323 323 function get_last_updated() { 324 324 global $bp, $wpdb; 325 325 326 326 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) ); 327 327 } 328 328 329 329 function check_exists_by_content( $content ) { 330 330 global $wpdb, $bp; -
trunk/bp-activity/bp-activity-filters.php
r2055 r2077 15 15 function bp_activity_filter_kses( $content ) { 16 16 global $allowedtags; 17 17 18 18 $activity_allowedtags = $allowedtags; 19 19 $activity_allowedtags['span'] = array(); 20 20 $activity_allowedtags['span']['class'] = array(); 21 21 $activity_allowedtags['a']['class'] = array(); 22 $activity_allowedtags['img'] = array(); 22 $activity_allowedtags['img'] = array(); 23 23 $activity_allowedtags['img']['src'] = array(); 24 24 $activity_allowedtags['img']['alt'] = array(); -
trunk/bp-activity/bp-activity-templatetags.php
r2071 r2077 8 8 var $activity; 9 9 var $activity_type; 10 10 11 11 var $in_the_loop; 12 12 13 13 var $pag_page; 14 14 var $pag_num; … … 26 26 if ( $type == 'sitewide' ) 27 27 $this->activities = bp_activity_get_sitewide_activity( $max, $this->pag_num, $this->pag_page, $filter ); 28 28 29 29 if ( $type == 'personal' ) 30 30 $this->activities = bp_activity_get_user_activity( $user_id, $max, $this->pag_num, $this->pag_page, $filter ); … … 32 32 if ( $type == 'friends' && ( bp_is_home() || is_site_admin() || $bp->loggedin_user->id == $user_id ) ) 33 33 $this->activities = bp_activity_get_friends_activity( $user_id, $max, false, $this->pag_num, $this->pag_page, $filter ); 34 34 35 35 if ( !$max || $max >= (int)$this->activities['total'] ) 36 36 $this->total_activity_count = (int)$this->activities['total']; 37 37 else 38 38 $this->total_activity_count = (int)$max; 39 39 40 40 $this->activities = $this->activities['activities']; 41 41 42 42 if ( $max ) { 43 43 if ( $max >= count($this->activities) ) … … 48 48 $this->activity_count = count($this->activities); 49 49 } 50 50 51 51 $this->full_name = $bp->displayed_user->fullname; 52 52 … … 63 63 } 64 64 } 65 65 66 66 function has_activities() { 67 67 if ( $this->activity_count ) 68 68 return true; 69 69 70 70 return false; 71 71 } 72 72 73 73 function next_activity() { 74 74 $this->current_activity++; 75 75 $this->activity = $this->activities[$this->current_activity]; 76 76 77 77 return $this->activity; 78 78 } 79 79 80 80 function rewind_activities() { 81 81 $this->current_activity = -1; … … 84 84 } 85 85 } 86 87 function user_activities() { 86 87 function user_activities() { 88 88 if ( $this->current_activity + 1 < $this->activity_count ) { 89 89 return true; … … 97 97 return false; 98 98 } 99 99 100 100 function the_activity() { 101 101 global $activity; … … 103 103 $this->in_the_loop = true; 104 104 $this->activity = $this->next_activity(); 105 105 106 106 if ( is_array( $this->activity ) ) 107 107 $this->activity = (object) $this->activity; … … 114 114 function bp_has_activities( $args = '' ) { 115 115 global $bp, $activities_template; 116 116 117 117 /* Note: any params used for filtering can be a single value, or multiple values comma separated. */ 118 118 119 119 $defaults = array( 120 120 'type' => 'sitewide', … … 138 138 $per_page = $max; 139 139 } 140 140 141 141 if ( isset( $_GET['afilter'] ) ) 142 142 $filter = array( 'object' => $_GET['afilter'] ); 143 143 else 144 144 $filter = array( 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id ); 145 146 $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $filter ); 145 146 $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $filter ); 147 147 return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template ); 148 148 } … … 160 160 function bp_activity_pagination_count() { 161 161 global $bp, $activities_template; 162 162 163 163 $from_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1; 164 164 $to_num = ( $from_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $from_num + ( $activities_template->pag_num - 1) ; … … 173 173 function bp_get_activity_pagination_links() { 174 174 global $activities_template; 175 175 176 176 return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links ); 177 177 } … … 179 179 function bp_activities_title() { 180 180 global $bp_activity_title; 181 181 182 182 echo bp_get_activities_title(); 183 183 } … … 190 190 function bp_activities_no_activity() { 191 191 global $bp_activity_no_activity; 192 192 193 193 echo bp_get_activities_no_activity(); 194 194 } 195 195 function bp_get_activities_no_activity() { 196 196 global $bp_activity_no_activity; 197 197 198 198 return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity ); 199 199 } … … 218 218 'height' => 20, 219 219 'class' => 'avatar', 220 'alt' => __( 'Avatar', 'buddypress' ) 220 'alt' => __( 'Avatar', 'buddypress' ) 221 221 ); 222 222 223 223 $r = wp_parse_args( $args, $defaults ); 224 224 extract( $r, EXTR_SKIP ); 225 225 226 226 $item_id = false; 227 227 if ( (int)$activities_template->activity->user_id ) … … 235 235 if ( $bp->blogs->id == $activities_template->activity->component_name && !(int) $activities_template->activity->user_id ) 236 236 $object = 'blog'; 237 237 238 238 $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component_name, $object ); 239 239 240 240 return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height ) ) ); 241 241 } … … 248 248 249 249 if ( bp_is_home() && $activities_template->activity_type == 'personal' ) 250 $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name ); 250 $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name ); 251 251 else 252 252 $content = bp_activity_content_filter( $activities_template->activity->content, $activities_template->activity->date_recorded, $activities_template->full_name, true, false, false ); … … 254 254 /* Add 'the_content' filter to activity to allow existing plugins to replace text as they would on post text. (extra smilies etc) */ 255 255 $content = apply_filters( 'the_content', $content ); 256 256 257 257 return apply_filters( 'bp_get_activity_content', $content ); 258 258 } … … 260 260 function bp_activity_content_filter( $content, $date_recorded, $full_name, $insert_time = true, $filter_words = true, $filter_you = true ) { 261 261 global $activities_template, $bp; 262 262 263 263 if ( !$content ) 264 264 return false; 265 265 266 266 /* Split the content so we don't evaluate and replace text on content we don't want to */ 267 267 $content = explode( '%s', $content ); … … 273 273 if ( $insert_time ) 274 274 $content[0] = bp_activity_insert_time_since( $content[0], $date_recorded ); 275 275 276 276 // The "You" and "Your" conversion is only done in english, if a translation file is present 277 277 // then do not translate as it causes problems in other languages. … … 284 284 /* Remove the 'You' and replace if with the persons name */ 285 285 if ( $filter_you && $full_name != '' ) { 286 $content[0] = preg_replace( "/{$full_name}[<]/", 'You<', $content[0], 1 ); 286 $content[0] = preg_replace( "/{$full_name}[<]/", 'You<', $content[0], 1 ); 287 287 } 288 288 } … … 290 290 /* Add the delete link if the user has permission on this item */ 291 291 if ( ( $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || is_site_admin() ) 292 $content[1] = '</span> <span class="activity-delete-link">' . bp_get_activity_delete_link() . '</span>' . $content[1]; 293 292 $content[1] = '</span> <span class="activity-delete-link">' . bp_get_activity_delete_link() . '</span>' . $content[1]; 293 294 294 $content_new = ''; 295 295 296 296 for ( $i = 0; $i < count($content); $i++ ) 297 297 $content_new .= $content[$i]; 298 298 299 299 return apply_filters( 'bp_activity_content_filter', $content_new ); 300 300 } … … 306 306 // Make sure we don't have any URL encoding in links when trying to insert the time. 307 307 $content = urldecode($content); 308 308 309 309 return apply_filters( 'bp_activity_insert_time_since', @sprintf( $content, @sprintf( __( ' %s ago', 'buddypress' ), bp_core_time_since( strtotime( $date ) ) ) ) ); 310 310 } … … 315 315 function bp_get_activity_css_class() { 316 316 global $activities_template; 317 317 318 318 return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component_name ); 319 319 } … … 333 333 function bp_get_activity_filter_links( $args = false ) { 334 334 global $activities_template, $bp; 335 335 336 336 $defaults = array( 337 337 'style' => 'list' … … 340 340 $r = wp_parse_args( $args, $defaults ); 341 341 extract( $r, EXTR_SKIP ); 342 342 343 343 /* Fetch the names of components that have activity recorded in the DB */ 344 344 $component_names = BP_Activity_Activity::get_recorded_component_names(); 345 345 346 346 if ( !$component_names ) 347 347 return false; 348 348 349 349 foreach ( (array) $component_names as $component_name ) { 350 350 if ( isset( $_GET['afilter'] ) && $component_name == $_GET['afilter'] ) … … 352 352 else 353 353 unset($selected); 354 354 355 $component_name = attribute_escape( $component_name ); 356 355 357 $component_name = attribute_escape( $component_name ); 356 358 … … 372 374 break; 373 375 } 374 376 375 377 $link = add_query_arg( 'afilter', $component_name ); 376 378 $link = remove_query_arg( 'acpage' , $link ); 377 379 378 380 $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component_name ); 379 381 380 382 /* Make sure all core internal component names are translatable */ 381 383 $translatable_component_names = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) ); 382 384 383 385 $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component_name, 'buddypress' ) ) . '</a>' . $after; 384 386 } … … 388 390 if ( isset( $_GET['afilter'] ) ) 389 391 $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>'; 390 391 392 393 return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) ); 392 394 } 393 395 … … 410 412 return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/feed' ); 411 413 else 412 return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' ); 414 return apply_filters( 'bp_get_activities_member_rss_link', $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' ); 413 415 } 414 416 … … 421 423 global $activities_template; 422 424 423 return apply_filters( 'bp_get_activity_feed_item_title', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) ); 425 return apply_filters( 'bp_get_activity_feed_item_title', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) ); 424 426 } 425 427 … … 453 455 454 456 function bp_activity_feed_item_description() { 455 echo bp_get_activity_feed_item_description(); 457 echo bp_get_activity_feed_item_description(); 456 458 } 457 459 function bp_get_activity_feed_item_description() { 458 460 global $activities_template; 459 461 460 return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $activities_template->activity->content ), ENT_COMPAT, 'UTF-8' ) ); 462 return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $activities_template->activity->content ), ENT_COMPAT, 'UTF-8' ) ); 461 463 } 462 464 -
trunk/bp-activity/bp-activity-widgets.php
r1926 r2077 14 14 function widget($args, $instance) { 15 15 global $bp; 16 16 17 17 extract( $args ); 18 18 19 19 echo $before_widget; 20 20 echo $before_title 21 . $widget_name . 22 ' <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>' 21 . $widget_name . 22 ' <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>' 23 23 . $after_title; ?> 24 24 25 25 <?php if ( bp_has_activities( 'type=sitewide&max=' . $instance['max_items'] . '&per_page=' . $instance['per_page'] ) ) : ?> 26 26 … … 30 30 <?php bp_activity_pagination_count() ?> 31 31 </div> 32 32 33 33 <div class="pagination-links" id="activity-pag"> 34 34 <?php bp_activity_pagination_links() ?> 35 35 </div> 36 36 </div> 37 37 38 38 <ul id="activity-filter-links"> 39 39 <?php bp_activity_filter_links() ?> 40 40 </ul> 41 41 <?php endif; ?> 42 42 43 43 <ul id="site-wide-stream" class="activity-list"> 44 44 <?php while ( bp_activities() ) : bp_the_activity(); ?> … … 49 49 </div> 50 50 <?php endif; ?> 51 51 52 52 <?php bp_activity_content() ?> 53 53 </li> … … 61 61 </div> 62 62 <?php endif;?> 63 63 64 64 <?php echo $after_widget; ?> 65 65 <?php -
trunk/bp-activity/deprecated/bp-activity-deprecated.php
r1909 r2077 4 4 * 5 5 * This file contains functions that are deprecated. 6 * You should not under any circumstance use these functions as they are 6 * You should not under any circumstance use these functions as they are 7 7 * either no longer valid, or have been replaced with something much more awesome. 8 8 * … … 13 13 * Of course, things will still work if you use these functions but you will 14 14 * be the laughing stock of the BuddyPress community. We will all point and laugh at 15 * you. You'll also be making things harder for yourself in the long run, 15 * you. You'll also be making things harder for yourself in the long run, 16 16 * and you will miss out on lovely performance and functionality improvements. 17 * 17 * 18 18 * If you've checked you are not using any deprecated functions and finished your little 19 19 * dance, you can add the following line to your wp-config.php file to prevent any of … … 25 25 function bp_activity_deprecated_globals() { 26 26 global $bp; 27 27 28 28 /* If we are using a BuddyPress 1.1+ theme ignore this. */ 29 29 if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) ) … … 32 32 $bp->activity->image_base = BP_PLUGIN_URL . '/bp-activity/images'; 33 33 } 34 add_action( 'plugins_loaded', 'bp_activity_deprecated_globals', 5 ); 34 add_action( 'plugins_loaded', 'bp_activity_deprecated_globals', 5 ); 35 35 add_action( 'admin_menu', 'bp_activity_deprecated_globals', 2 ); 36 36 … … 38 38 function bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id = false, $user_id = false, $secondary_user_id = false, $recorded_time = false ) { 39 39 global $bp, $wpdb; 40 40 41 41 if ( !$user_id ) 42 42 $user_id = $bp->loggedin_user->id; … … 44 44 if ( !$recorded_time ) 45 45 $recorded_time = time(); 46 46 47 47 $args = compact( 'user_id', 'content', 'component_name', 'component_action', 'item_id', 'secondary_item_id', 'recorded_time' ); 48 48 bp_activity_add( $args ); 49 49 50 50 if ( $secondary_user_id ) { 51 51 $hide_sitewide = true; … … 53 53 bp_activity_add( $args ); 54 54 } 55 55 56 56 do_action( 'bp_activity_record', $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id ); 57 57 58 58 return true; 59 59 } 60 60 61 61 /* DEPRECATED - use bp_activity_delete_by_item_id() */ 62 function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) { 62 function bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id ) { 63 63 if ( !bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component_name' => $component_name, 'component_action' => $component_action, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) ) ) 64 64 return false; 65 65 66 66 do_action( 'bp_activity_delete', $item_id, $component_name, $component_action, $user_id, $secondary_item_id ); 67 67 68 68 return true; 69 69 } … … 72 72 function bp_activity_get_list( $user_id, $title, $no_activity, $limit = false ) { 73 73 global $bp_activity_user_id, $bp_activity_limit, $bp_activity_title, $bp_activity_no_activity; 74 74 75 75 $bp_activity_user_id = $user_id; 76 76 $bp_activity_limit = $limit; 77 77 $bp_activity_title = $title; 78 78 $bp_activity_no_activity = $no_activity; 79 79 80 80 locate_template( array( '/activity/activity-list.php' ), true ); 81 81 } … … 87 87 if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) ) 88 88 return $template; 89 89 90 90 /* Enqueue the structure CSS file to give basic positional formatting for components */ 91 wp_enqueue_style( 'bp-activity-structure', BP_PLUGIN_URL . '/bp-activity/deprecated/css/structure.css' ); 91 wp_enqueue_style( 'bp-activity-structure', BP_PLUGIN_URL . '/bp-activity/deprecated/css/structure.css' ); 92 92 } 93 93 add_action( 'bp_styles', 'bp_activity_add_structure_css' ); -
trunk/bp-blogs.php
r2055 r2077 13 13 /* Include deprecated functions if settings allow */ 14 14 if ( !defined( 'BP_IGNORE_DEPRECATED' ) ) 15 require ( BP_PLUGIN_DIR . '/bp-blogs/deprecated/bp-blogs-deprecated.php' ); 16 15 require ( BP_PLUGIN_DIR . '/bp-blogs/deprecated/bp-blogs-deprecated.php' ); 16 17 17 function bp_blogs_install() { 18 18 global $wpdb, $bp; 19 19 20 20 if ( !empty($wpdb->charset) ) 21 21 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 22 22 23 23 $sql[] = "CREATE TABLE {$bp->blogs->table_name} ( 24 24 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 52 52 KEY comment_post_id (comment_post_id) 53 53 ) {$charset_collate};"; 54 54 55 55 $sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} ( 56 56 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 61 61 KEY meta_key (meta_key) 62 62 ) {$charset_collate};"; 63 64 63 64 65 65 require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); 66 66 … … 69 69 // On first installation - record all existing blogs in the system. 70 70 if ( !(int)get_site_option( 'bp-blogs-first-install') ) { 71 71 72 72 bp_blogs_record_existing_blogs(); 73 73 add_site_option( 'bp-blogs-first-install', 1 ); 74 74 75 75 } else { 76 77 // Import blog titles and descriptions into the blogmeta table 76 77 // Import blog titles and descriptions into the blogmeta table 78 78 if ( get_site_option( 'bp-blogs-version' ) <= '0.1.5' ) { 79 79 $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $bp->blogs->table_name ) ); … … 82 82 $name = get_blog_option( $blog_ids[$i], 'blogname' ); 83 83 $desc = get_blog_option( $blog_ids[$i], 'blogdescription' ); 84 84 85 85 bp_blogs_update_blogmeta( $blog_ids[$i], 'name', $name ); 86 86 bp_blogs_update_blogmeta( $blog_ids[$i], 'description', $desc ); … … 88 88 } 89 89 } 90 91 } 92 90 91 } 92 93 93 update_site_option( 'bp-blogs-db-version', BP_BLOGS_DB_VERSION ); 94 94 } 95 95 96 function bp_blogs_check_installed() { 96 function bp_blogs_check_installed() { 97 97 global $wpdb, $bp, $userdata; 98 98 99 99 if ( is_site_admin() ) { 100 100 /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */ … … 107 107 function bp_blogs_setup_globals() { 108 108 global $bp, $wpdb; 109 109 110 110 /* For internal identification */ 111 111 $bp->blogs->id = 'blogs'; 112 112 113 113 $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs'; 114 114 $bp->blogs->table_name_blog_posts = $wpdb->base_prefix . 'bp_user_blogs_posts'; … … 117 117 $bp->blogs->format_notification_function = 'bp_blogs_format_notifications'; 118 118 $bp->blogs->slug = BP_BLOGS_SLUG; 119 119 120 120 /* Register this in the active components array */ 121 121 $bp->active_components[$bp->blogs->slug] = $bp->blogs->id; … … 123 123 do_action( 'bp_blogs_setup_globals' ); 124 124 } 125 add_action( 'plugins_loaded', 'bp_blogs_setup_globals', 5 ); 125 add_action( 'plugins_loaded', 'bp_blogs_setup_globals', 5 ); 126 126 add_action( 'admin_menu', 'bp_blogs_setup_globals', 2 ); 127 127 … … 136 136 * 137 137 * Adds "Blog" to the navigation arrays for the current and logged in user. 138 * 138 * 139 139 * @package BuddyPress Blogs 140 140 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 143 143 function bp_blogs_setup_nav() { 144 144 global $bp; 145 145 146 146 /* Add 'Blogs' to the main navigation */ 147 147 bp_core_new_nav_item( array( 'name' => __( 'Blogs', 'buddypress' ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) ); 148 148 149 149 $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/'; 150 150 151 151 /* Add the subnav items to the blogs nav item */ 152 152 bp_core_new_subnav_item( array( 'name' => __( 'My Blogs', 'buddypress' ), 'slug' => 'my-blogs', 'parent_url' => $blogs_link, 'parent_slug' => $bp->blogs->slug, 'screen_function' => 'bp_blogs_screen_my_blogs', 'position' => 10, 'item_css_id' => 'my-blogs-list' ) ); … … 159 159 if ( bp_is_home() ) { 160 160 if ( function_exists('xprofile_setup_nav') ) { 161 $bp->bp_options_title = __('My Blogs', 'buddypress'); 161 $bp->bp_options_title = __('My Blogs', 'buddypress'); 162 162 } 163 163 } else { 164 164 /* If we are not viewing the logged in user, set up the current users avatar and name */ 165 165 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 166 $bp->bp_options_title = $bp->displayed_user->fullname; 166 $bp->bp_options_title = $bp->displayed_user->fullname; 167 167 } 168 168 } 169 169 170 170 do_action( 'bp_blogs_setup_nav' ); 171 171 } … … 178 178 if ( $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) { 179 179 $bp->is_directory = true; 180 180 181 181 do_action( 'bp_blogs_directory_blogs_setup' ); 182 182 bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'directories/blogs/index' ) ); … … 196 196 function bp_blogs_screen_my_blogs() { 197 197 do_action( 'bp_blogs_screen_my_blogs' ); 198 bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'blogs/my-blogs' ) ); 198 bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'blogs/my-blogs' ) ); 199 199 } 200 200 … … 224 224 function bp_blogs_register_activity_actions() { 225 225 global $bp; 226 226 227 227 if ( !function_exists( 'bp_activity_set_action' ) ) 228 228 return false; … … 238 238 function bp_blogs_record_activity( $args = '' ) { 239 239 global $bp; 240 240 241 241 if ( !function_exists( 'bp_activity_add' ) ) 242 242 return false; 243 243 244 244 /* Because blog, comment, and blog post code execution happens before anything else 245 245 we may need to manually instantiate the activity component globals */ 246 246 if ( !$bp->activity && function_exists('bp_activity_setup_globals') ) 247 247 bp_activity_setup_globals(); 248 248 249 249 $defaults = array( 250 250 'user_id' => $bp->loggedin_user->id, … … 260 260 261 261 $r = wp_parse_args( $args, $defaults ); 262 extract( $r, EXTR_SKIP ); 263 262 extract( $r, EXTR_SKIP ); 263 264 264 return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) ); 265 265 } … … 268 268 if ( function_exists('bp_activity_delete_by_item_id') ) { 269 269 extract($args); 270 271 bp_activity_delete_by_item_id( array( 272 'item_id' => $item_id, 270 271 bp_activity_delete_by_item_id( array( 272 'item_id' => $item_id, 273 273 'component_name' => $component_name, 274 'component_action' => $component_action, 274 'component_action' => $component_action, 275 275 'user_id' => $user_id, 276 276 'secondary_item_id' => $secondary_item_id … … 292 292 293 293 $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE public = 1 AND mature = 0 AND spam = 0 AND deleted = 0" ) ); 294 294 295 295 if ( $blog_ids ) { 296 296 foreach( $blog_ids as $blog_id ) { … … 311 311 function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = true ) { 312 312 global $bp; 313 313 314 314 if ( !$user_id ) 315 315 $user_id = $bp->loggedin_user->id; 316 316 317 317 $name = get_blog_option( $blog_id, 'blogname' ); 318 318 $description = get_blog_option( $blog_id, 'blogdescription' ); 319 319 320 320 $recorded_blog = new BP_Blogs_Blog; 321 321 $recorded_blog->user_id = $user_id; … … 323 323 324 324 $recorded_blog_id = $recorded_blog->save(); 325 325 326 326 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); 327 327 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 328 328 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', time() ); 329 329 330 330 /* Only record this activity if the blog is public */ 331 331 if ( (int)$_POST['blog_public'] || !$no_activity ) { … … 333 333 bp_blogs_record_activity( array( 334 334 'user_id' => $recorded_blog->user_id, 335 'content' => apply_filters( 'bp_blogs_activity_created_blog', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ), 335 'content' => apply_filters( 'bp_blogs_activity_created_blog', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ), 336 336 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ), 337 337 'component_action' => 'new_blog', … … 339 339 ) ); 340 340 } 341 341 342 342 do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded ); 343 343 } … … 346 346 function bp_blogs_record_post( $post_id, $post, $user_id = false ) { 347 347 global $bp, $wpdb; 348 348 349 349 $post_id = (int)$post_id; 350 350 $blog_id = (int)$wpdb->blogid; 351 351 352 352 if ( !$user_id ) 353 353 $user_id = (int)$post->post_author; 354 355 354 /* This is to stop infinate loops with Donncha's sitewide tags plugin */ 356 355 if ( (int)get_site_option( 'tags_blog_id' ) == (int)$blog_id ) 357 356 return false; 358 357 359 358 /* Don't record this if it's not a post */ 360 359 if ( $post->post_type != 'post' ) 361 360 return false; 362 361 363 362 if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) { 364 363 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 365 364 366 365 $recorded_post = new BP_Blogs_Post; 367 366 $recorded_post->user_id = $user_id; … … 369 368 $recorded_post->post_id = $post_id; 370 369 $recorded_post->date_created = strtotime( $post->post_date ); 371 370 372 371 $recorded_post_id = $recorded_post->save(); 373 372 374 373 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', time() ); 375 374 … … 380 379 $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); 381 380 $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>"; 382 381 383 382 bp_blogs_record_activity( array( 384 383 'user_id' => (int)$post->post_author, 385 'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ), 384 'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ), 386 385 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 387 386 'component_action' => 'new_blog_post', … … 399 398 /* Delete the recorded post if the status is not published or it is password protected */ 400 399 if ( 'publish' != $post->post_status || '' != $post->post_password ) { 401 return bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 402 400 return bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 401 403 402 /* If the post author has changed, delete the post and re-add it. */ 404 403 } else if ( (int)$existing_post->user_id != (int)$post->post_author ) { 405 404 // Delete the existing recorded post 406 405 bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 407 406 408 407 // Re-record the post with the new author. 409 bp_blogs_record_post( $post_id ); 408 bp_blogs_record_post( $post_id ); 410 409 } 411 410 412 411 if ( (int)get_blog_option( $blog_id, 'blog_public' ) ) { 413 /* Now re-record the post in the activity streams */ 412 /* Now re-record the post in the activity streams */ 414 413 $post_permalink = bp_post_get_permalink( $post, $blog_id ); 415 414 416 415 $activity_content = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' ); 417 416 $activity_content .= "<blockquote>" . bp_create_excerpt( $post->post_content ) . "</blockquote>"; 418 417 419 418 /* Record this in activity streams */ 420 419 bp_blogs_record_activity( array( 421 420 'user_id' => (int)$post->post_author, 422 'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ), 421 'content' => apply_filters( 'bp_blogs_activity_new_post', $activity_content, &$post, $post_permalink ), 423 422 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 424 423 'component_action' => 'new_blog_post', … … 435 434 function bp_blogs_record_comment( $comment_id, $is_approved ) { 436 435 global $wpdb, $bp; 437 436 438 437 if ( !$is_approved ) 439 438 return false; 440 439 441 440 $comment = get_comment($comment_id); 442 441 $comment->post = get_post( $comment->comment_post_ID ); 443 442 444 443 /* Get the user_id from the author email. */ 445 444 $user = get_user_by_email( $comment->comment_author_email ); 446 445 $user_id = (int)$user->ID; 447 446 448 447 if ( !$user_id ) 449 448 return false; … … 457 456 458 457 $recorded_commment_id = $recorded_comment->save(); 459 458 460 459 bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', time() ); 461 460 … … 463 462 /* Record in activity streams */ 464 463 $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id ); 465 $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 464 $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 466 465 $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>'; 467 466 … … 469 468 bp_blogs_record_activity( array( 470 469 'user_id' => $recorded_comment->user_id, 471 'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ), 470 'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ), 472 471 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ), 473 472 'component_action' => 'new_blog_comment', … … 484 483 function bp_blogs_approve_comment( $comment_id, $comment_status ) { 485 484 global $bp, $wpdb; 486 485 487 486 if ( 'approve' != $comment_status ) 488 487 return false; … … 491 490 $comment = get_comment($comment_id); 492 491 $comment->post = get_post( $comment->comment_post_ID ); 493 492 494 493 bp_blogs_delete_activity( array( 'item_id' => $comment_id, 'secondary_item_id' => $recorded_comment->blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_comment' ) ); 495 494 … … 497 496 /* Record in activity streams */ 498 497 $comment_link = bp_post_get_permalink( $comment->post, $recorded_comment->blog_id ); 499 $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment->user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 498 $activity_content = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $recorded_comment->user_id ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' ); 500 499 $activity_content .= '<blockquote>' . bp_create_excerpt( $comment->comment_content ) . '</blockquote>'; 501 500 … … 503 502 bp_blogs_record_activity( array( 504 503 'user_id' => $recorded_comment->user_id, 505 'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ), 504 'content' => apply_filters( 'bp_blogs_activity_new_comment', $activity_content, &$comment, &$recorded_comment, $comment_link ), 506 505 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ), 507 506 'component_action' => 'new_blog_comment', 508 507 'item_id' => $comment_id, 509 508 'secondary_item_id' => $recorded_comment->blog_id, 510 'recorded_time' => $recorded_comment->date_created 509 'recorded_time' => $recorded_comment->date_created 511 510 ) ); 512 511 } … … 516 515 function bp_blogs_unapprove_comment( $comment_id, $comment_status ) { 517 516 if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status ) 518 bp_blogs_remove_comment( $comment_id ); 517 bp_blogs_remove_comment( $comment_id ); 519 518 } 520 519 add_action( 'wp_set_comment_status', 'bp_blogs_unapprove_comment', 10, 2 ); … … 538 537 539 538 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 540 539 541 540 // Delete activity stream item 542 541 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog' ) ); 543 542 544 543 do_action( 'bp_blogs_remove_blog', $blog_id ); 545 544 } … … 548 547 function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) { 549 548 global $current_user; 550 549 551 550 $blog_id = (int)$blog_id; 552 551 $user_id = (int)$user_id; … … 565 564 566 565 $post_id = (int)$post_id; 567 566 568 567 if ( !$blog_id ) 569 568 $blog_id = (int)$current_blog->blog_id; 570 569 571 570 if ( !$existing_post ) 572 571 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); … … 574 573 // Delete post from the bp_blogs table 575 574 BP_Blogs_Post::delete( $post_id, $blog_id ); 576 575 577 576 // Delete activity stream item 578 577 bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component_name' => $bp->blogs->slug, 'component_action' => 'new_blog_post' ) ); … … 586 585 587 586 $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id ); 588 BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid ); 587 BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid ); 589 588 590 589 // Delete activity stream item … … 597 596 function bp_blogs_remove_data_for_blog( $blog_id ) { 598 597 global $bp; 599 598 600 599 /* If this is regular blog, delete all data for that blog. */ 601 600 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 602 BP_Blogs_Post::delete_posts_for_blog( $blog_id ); 601 BP_Blogs_Post::delete_posts_for_blog( $blog_id ); 603 602 BP_Blogs_Comment::delete_comments_for_blog( $blog_id ); 604 603 … … 624 623 function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) { 625 624 global $bp; 626 625 627 626 if ( !is_numeric( $limit ) ) 628 627 $limit = 5; 629 628 630 629 return BP_Blogs_Post::get_latest_posts( $blog_id, $limit ); 631 630 } … … 645 644 function bp_blogs_total_post_count( $blog_id ) { 646 645 return BP_Blogs_Post::total_post_count( $blog_id ); 647 } 646 } 648 647 649 648 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) { 650 649 return BP_Blogs_Post::total_comment_count( $blog_id, $post_id ); 651 } 650 } 652 651 653 652 function bp_blogs_is_blog_hidden( $blog_id ) { … … 657 656 function bp_blogs_redirect_to_random_blog() { 658 657 global $bp, $wpdb; 659 658 660 659 if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) { 661 660 $blog = bp_blogs_get_random_blog(); … … 676 675 function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) { 677 676 global $wpdb, $bp; 678 677 679 678 if ( !is_numeric( $blog_id ) ) 680 679 return false; 681 680 682 681 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); 683 682 684 683 if ( is_array($meta_value) || is_object($meta_value) ) 685 684 $meta_value = serialize($meta_value); 686 685 687 686 $meta_value = trim( $meta_value ); 688 687 689 688 if ( !$meta_key ) { 690 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) ); 689 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) ); 691 690 } else if ( $meta_value ) { 692 691 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) ); … … 694 693 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) ); 695 694 } 696 695 697 696 // TODO need to look into using this. 698 697 // wp_cache_delete($group_id, 'groups'); … … 703 702 function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') { 704 703 global $wpdb, $bp; 705 704 706 705 $blog_id = (int) $blog_id; 707 706 … … 711 710 if ( !empty($meta_key) ) { 712 711 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); 713 712 714 713 // TODO need to look into using this. 715 714 //$user = wp_cache_get($user_id, 'users'); 716 715 717 716 // Check the cached user object 718 717 //if ( false !== $user && isset($user->$meta_key) ) … … 741 740 function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) { 742 741 global $wpdb, $bp; 743 742 744 743 if ( !is_numeric( $blog_id ) ) 745 744 return false; 746 745 747 746 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 748 747 749 748 if ( is_string($meta_value) ) 750 749 $meta_value = stripslashes($wpdb->escape($meta_value)); 751 750 752 751 $meta_value = maybe_serialize($meta_value); 753 752 … … 757 756 758 757 $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) ); 759 758 760 759 if ( !$cur ) { 761 760 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) ); … … 775 774 /* If this is regular blog, delete all data for that blog. */ 776 775 BP_Blogs_Blog::delete_blogs_for_user( $user_id ); 777 BP_Blogs_Post::delete_posts_for_user( $user_id ); 776 BP_Blogs_Post::delete_posts_for_user( $user_id ); 778 777 BP_Blogs_Comment::delete_comments_for_user( $user_id ); 779 778 -
trunk/bp-core.php
r2059 r2077 4 4 define( 'BP_CORE_DB_VERSION', '1800' ); 5 5 6 /*** 7 * Define the path and url of the BuddyPress plugins directory. 8 * It is important to use plugins_url() core function to obtain 9 * the correct scheme used (http or https). 6 /*** 7 * Define the path and url of the BuddyPress plugins directory. 8 * It is important to use plugins_url() core function to obtain 9 * the correct scheme used (http or https). 10 10 */ 11 11 define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' ); … … 66 66 if ( !defined( 'BP_HOME_BLOG_SLUG' ) ) 67 67 define( 'BP_HOME_BLOG_SLUG', 'blog' ); 68 68 69 /* Register BuddyPress themes contained within the theme folder */ 70 if ( function_exists( 'register_theme_folder' ) ) 71 register_theme_folder( 'buddypress/bp-themes' ); 72 69 73 /* Register BuddyPress themes contained within the theme folder */ 70 74 if ( function_exists( 'register_theme_folder' ) ) … … 94 98 global $displayed_user_id; 95 99 global $action_variables; 96 100 97 101 $current_user = wp_get_current_user(); 98 102 99 /* The domain for the root of the site where the main blog resides */ 103 /* The domain for the root of the site where the main blog resides */ 100 104 $bp->root_domain = bp_core_get_root_domain(); 101 105 102 106 /* The user ID of the user who is currently logged in. */ 103 107 $bp->loggedin_user->id = $current_user->ID; … … 105 109 /* The domain for the user currently logged in. eg: http://domain.com/members/andy */ 106 110 $bp->loggedin_user->domain = bp_core_get_user_domain($current_user->ID); 107 111 108 112 /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */ 109 113 $bp->displayed_user->id = $displayed_user_id; 110 114 111 115 /* The domain for the user currently being displayed */ 112 116 $bp->displayed_user->domain = bp_core_get_user_domain($displayed_user_id); 113 117 114 118 /* The component being used eg: http://domain.com/members/andy/ [profile] */ 115 119 $bp->current_component = $current_component; // type: string 116 120 117 121 /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */ 118 122 $bp->current_action = $current_action; // type: string 119 123 120 124 /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */ 121 125 $bp->action_variables = $action_variables; // type: array 122 126 123 127 /* Only used where a component has a sub item, e.g. groups: http://domain.com/members/andy/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/ 124 128 $bp->current_item = ''; // type: string … … 135 139 /* Sets up the array container for the component navigation rendered by bp_get_nav() */ 136 140 $bp->bp_nav = array(); 137 141 138 142 /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */ 139 143 $bp->bp_options_nav = array(); 140 144 141 145 /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */ 142 146 $bp->bp_options_title = ''; 143 147 144 148 /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */ 145 149 $bp->bp_options_avatar = ''; 146 150 147 151 /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */ 148 152 $bp->active_components = array(); 149 153 150 154 /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */ 151 155 $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', get_site_option( 'user-avatar-default' ) ); 152 156 $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' ); 153 157 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' ); 154 158 155 159 /* Fetch the full name for the logged in and current user */ 156 160 $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id ); … … 162 166 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ 163 167 $bp->is_item_admin = bp_is_home(); 164 168 165 169 /* Used to determine if the logged in user is a moderator for the current content. */ 166 170 $bp->is_item_mod = false; … … 170 174 if ( !$bp->current_component ) 171 175 $bp->current_component = $bp->default_component; 172 176 173 177 do_action( 'bp_core_setup_globals' ); 174 178 } … … 183 187 * 184 188 * For example: http://example.org/search or http://example.org/members 185 * 189 * 186 190 * @package BuddyPress Core 187 191 * @uses bp_core_add_root_component() Adds a slug to the root components global variable. … … 202 206 * 203 207 * Installs the core DB tables for BuddyPress. 204 * 208 * 205 209 * @package BuddyPress Core 206 210 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 211 215 function bp_core_install() { 212 216 global $wpdb, $bp; 213 217 214 218 if ( !empty($wpdb->charset) ) 215 219 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 216 220 217 221 $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} ( 218 222 id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 235 239 require_once( ABSPATH . 'wp-admin/upgrade-functions.php' ); 236 240 dbDelta( $sql ); 237 241 238 242 /* Add names of root components to the banned blog list to avoid conflicts */ 239 243 bp_core_add_illegal_names(); 240 244 241 245 update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION ); 242 246 } … … 246 250 * 247 251 * Checks to make sure the database tables are set up for the core component. 248 * 252 * 249 253 * @package BuddyPress Core 250 254 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 260 264 if ( !is_site_admin() ) 261 265 return false; 262 266 263 267 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' ); 264 268 … … 273 277 * 274 278 * Adds the "BuddyPress" admin submenu item to the Site Admin tab. 275 * 279 * 276 280 * @package BuddyPress Core 277 281 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 281 285 */ 282 286 function bp_core_add_admin_menu() { 283 global $wpdb, $bp, $menu;284 285 287 if ( !is_site_admin() ) 286 288 return false; 287 289 288 290 /* Add the administration tab under the "Site Admin" tab for site administrators */ 289 291 bp_core_add_admin_menu_page( array( … … 294 296 'position' => 2 295 297 ) ); 296 298 297 299 add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' ); 298 300 add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' ); … … 305 307 * Checks to see if a component's URL should be in the root, not under a member page: 306 308 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group 307 * 309 * 308 310 * @package BuddyPress Core 309 311 * @return true if root component, else false. … … 319 321 * 320 322 * Sets up the profile navigation item if the Xprofile component is not installed. 321 * 323 * 322 324 * @package BuddyPress Core 323 325 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 329 331 function bp_core_setup_nav() { 330 332 global $bp; 331 332 /*** 333 334 /*** 333 335 * If the extended profiles component is disabled, we need to revert to using the 334 336 * built in WordPress profile information … … 340 342 341 343 /* Add 'Profile' to the main navigation */ 342 bp_core_new_nav_item( array( 344 bp_core_new_nav_item( array( 343 345 'name' => __('Profile', 'buddypress'), 344 346 'slug' => $bp->core->profile->slug, … … 349 351 350 352 $profile_link = $bp->loggedin_user->domain . '/profile/'; 351 353 352 354 /* Add the subnav items to the profile */ 353 355 bp_core_new_subnav_item( array( … … 358 360 'screen_function' => 'bp_core_catch_profile_uri' 359 361 ) ); 360 362 361 363 362 364 if ( 'profile' == $bp->current_component ) { … … 365 367 } else { 366 368 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 367 $bp->bp_options_title = $bp->displayed_user->fullname; 369 $bp->bp_options_title = $bp->displayed_user->fullname; 368 370 } 369 371 } 370 } 372 } 371 373 } 372 374 add_action( 'plugins_loaded', 'bp_core_setup_nav' ); … … 397 399 * Listens to the $bp component and action variables to determine if the user is viewing the members 398 400 * directory page. If they are, it will set up the directory and load the members directory template. 399 * 401 * 400 402 * @package BuddyPress Core 401 403 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 421 423 * this action will fire and mark or unmark the user and their blogs as spam. 422 424 * Must be a site admin for this function to run. 423 * 425 * 424 426 * @package BuddyPress Core 425 427 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 427 429 function bp_core_action_set_spammer_status() { 428 430 global $bp; 429 431 430 432 if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id ) 431 433 return false; 432 434 433 435 if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) { 434 436 /* Check the nonce */ … … 437 439 /* Get the functions file */ 438 440 require( ABSPATH . 'wp-admin/includes/mu.php' ); 439 441 440 442 if ( 'mark-spammer' == $bp->current_action ) 441 443 $is_spam = 1; … … 445 447 /* Get the blogs for the user */ 446 448 $blogs = get_blogs_of_user( $bp->displayed_user->id, true ); 447 449 448 450 foreach ( (array) $blogs as $key => $details ) { 449 451 /* Do not mark the main or current root blog as spam */ 450 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 451 continue; 452 452 if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id ) 453 continue; 454 453 455 /* Update the blog status */ 454 456 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 455 457 456 458 /* Fire the standard WPMU hook */ 457 459 do_action( 'make_spam_blog', $details->userblog_id ); 458 460 } 459 461 460 462 /* Finally, mark this user as a spammer */ 461 463 update_user_status( $bp->displayed_user->id, 'spam', $is_spam, 1 ); 462 464 463 465 if ( $is_spam ) 464 466 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) ); 465 467 else 466 468 bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) ); 467 469 468 470 do_action( 'bp_core_action_set_spammer_status' ); 469 471 470 472 bp_core_redirect( wp_get_referer() ); 471 473 } … … 477 479 * 478 480 * Allows a site admin to delete a user from the adminbar menu. 479 * 481 * 480 482 * @package BuddyPress Core 481 483 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 483 485 function bp_core_action_delete_user() { 484 486 global $bp; 485 487 486 488 if ( !is_site_admin() || bp_is_home() || !$bp->displayed_user->id ) 487 489 return false; 488 490 489 491 if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) { 490 492 /* Check the nonce */ … … 492 494 493 495 $errors = false; 494 496 495 497 if ( bp_core_delete_account( $bp->displayed_user->id ) ) { 496 498 bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) ); … … 499 501 $errors = true; 500 502 } 501 503 502 504 do_action( 'bp_core_action_set_spammer_status', $errors ); 503 505 504 506 if ( $errors ) 505 507 bp_core_redirect( $bp->displayed_user->domain ); … … 525 527 * Returns the domain for the passed user: 526 528 * e.g. http://domain.com/members/andy/ 527 * 529 * 528 530 * @package BuddyPress Core 529 531 * @global $current_user WordPress global variable containing current logged in user information … … 533 535 function bp_core_get_user_domain( $user_id ) { 534 536 global $bp; 535 537 536 538 if ( !$user_id ) return; 537 539 538 540 $ud = get_userdata($user_id); 539 541 540 542 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 541 543 $username = $ud->user_login; 542 544 else 543 545 $username = $ud->user_nicename; 544 546 545 547 /* If we are using a members slug, include it. */ 546 548 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) 547 549 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/' ); 548 550 else 549 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' ); 551 return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' ); 550 552 } 551 553 … … 555 557 * Returns the domain for the root blog. 556 558 * eg: http://domain.com/ OR https://domain.com 557 * 559 * 558 560 * @package BuddyPress Core 559 561 * @uses get_blog_option() WordPress function to fetch blog meta. … … 562 564 function bp_core_get_root_domain() { 563 565 global $current_blog; 564 566 565 567 if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) 566 568 $domain = get_blog_option( $current_blog->blog_id, 'siteurl' ); … … 576 578 * Returns the user id for the user that is currently being displayed. 577 579 * eg: http://andy.domain.com/ or http://domain.com/andy/ 578 * 580 * 579 581 * @package BuddyPress Core 580 582 * @global $current_blog WordPress global containing information and settings for the current blog being viewed. … … 590 592 * 591 593 * Adds a navigation item to the main navigation array used in BuddyPress themes. 592 * 594 * 593 595 * @package BuddyPress Core 594 596 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 614 616 if ( empty($name) || empty($slug) ) 615 617 return false; 616 618 617 619 /* If this is for site admins only and the user is not one, don't create the subnav item */ 618 620 if ( $site_admin_only && !is_site_admin() ) 619 621 return false; 620 622 621 623 if ( empty( $item_css_id ) ) 622 624 $item_css_id = $slug; … … 637 639 if ( !$show_for_displayed_user && !bp_is_home() ) 638 640 return false; 639 641 640 642 /*** 641 643 * If we are not viewing a user, and this is a root component, don't attach the … … 660 662 * 661 663 * Modify the default subnav item to load when a top level nav item is clicked. 662 * 664 * 663 665 * @package BuddyPress Core 664 666 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 666 668 function bp_core_new_nav_default( $args = '' ) { 667 669 global $bp; 668 670 669 671 $defaults = array( 670 672 'parent_slug' => false, // Slug of the parent … … 692 694 * We can only sort nav items by their position integer at a later point in time, once all 693 695 * plugins have registered their navigation items. 694 * 696 * 695 697 * @package BuddyPress Core 696 698 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 698 700 function bp_core_sort_nav_items() { 699 701 global $bp; 700 702 701 703 if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) ) 702 704 return false; 703 705 704 706 foreach ( $bp->bp_nav as $slug => $nav_item ) { 705 707 if ( empty( $temp[$nav_item['position']]) ) … … 710 712 $nav_item['position']++; 711 713 } while ( !empty( $temp[$nav_item['position']] ) ); 712 714 713 715 $temp[$nav_item['position']] = $nav_item; 714 716 } 715 717 } 716 718 717 719 ksort( $temp ); 718 $bp->bp_nav = &$temp; 720 $bp->bp_nav = &$temp; 719 721 } 720 722 add_action( 'wp_head', 'bp_core_sort_nav_items' ); … … 724 726 * 725 727 * Removes a navigation item from the main navigation array. 726 * 728 * 727 729 * @package BuddyPress Core 728 730 * @param $slug The slug of the sub navigation item. … … 738 740 * 739 741 * Adds a navigation item to the sub navigation array used in BuddyPress themes. 740 * 742 * 741 743 * @package BuddyPress Core 742 744 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 756 758 'screen_function' => false // The name of the function to run when clicked 757 759 ); 758 760 759 761 $r = wp_parse_args( $args, $defaults ); 760 762 extract( $r, EXTR_SKIP ); … … 763 765 if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) ) 764 766 return false; 765 767 766 768 /* If this is for site admins only and the user is not one, don't create the subnav item */ 767 769 if ( $site_admin_only && !is_site_admin() ) 768 770 return false; 769 771 770 772 if ( empty( $item_css_id ) ) 771 773 $item_css_id = $slug; 772 774 773 775 $bp->bp_options_nav[$parent_slug][$slug] = array( 774 776 'name' => $name, … … 779 781 'user_has_access' => $user_has_access 780 782 ); 781 783 782 784 if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) { 783 785 if ( !is_object( $screen_function[0] ) ) … … 793 795 if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) ) 794 796 return false; 795 797 796 798 foreach ( $bp->bp_options_nav as $parent_slug => $subnav_items ) { 797 799 if ( !is_array( $subnav_items ) ) 798 800 continue; 799 801 800 802 foreach ( $subnav_items as $subnav_item ) { 801 803 if ( empty( $temp[$subnav_item['position']]) ) … … 806 808 $subnav_item['position']++; 807 809 } while ( !empty( $temp[$subnav_item['position']] ) ); 808 810 809 811 $temp[$subnav_item['position']] = $subnav_item; 810 812 } … … 821 823 * 822 824 * Removes a navigation item from the sub navigation array used in BuddyPress themes. 823 * 825 * 824 826 * @package BuddyPress Core 825 827 * @param $parent_id The id of the parent navigation item. … … 828 830 function bp_core_remove_subnav_item( $parent_id, $slug ) { 829 831 global $bp; 830 832 831 833 unset( $bp->bp_options_nav[$parent_id][$slug] ); 832 834 } … … 836 838 * 837 839 * Clear the subnav items for a specific nav item. 838 * 840 * 839 841 * @package BuddyPress Core 840 842 * @param $parent_id The id of the parent navigation item. … … 856 858 * Loads: 857 859 * wp-content/member-themes/[activated_theme]/profile/edit-profile.php 858 * 860 * 859 861 * @package BuddyPress Core 860 862 * @param $username str Username to check. … … 883 885 * http://community.domain.com/members/andy/friends 884 886 * http://domain.com/wpmu/members/andy/friends 885 * 887 * 886 888 * @package BuddyPress Core 887 889 * @param $slug str The slug of the component … … 898 900 * 899 901 * Returns the user_id for a user based on their username. 900 * 902 * 901 903 * @package BuddyPress Core 902 904 * @param $username str Username to check. … … 907 909 function bp_core_get_random_member() { 908 910 global $bp, $wpdb; 909 911 910 912 if ( isset( $_GET['random-member'] ) ) { 911 913 $user = BP_Core_User::get_random_users(1); 912 914 913 915 $ud = get_userdata( $user['users'][0]->user_id ); 914 915 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->user_id ) ); 916 917 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->user_id ) ); 916 918 } 917 919 } … … 922 924 * 923 925 * Returns the user_id for a user based on their username. 924 * 926 * 925 927 * @package BuddyPress Core 926 928 * @param $username str Username to check. … … 931 933 function bp_core_get_userid( $username ) { 932 934 global $wpdb; 933 935 934 936 if ( !empty( $username ) ) 935 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 937 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 936 938 } 937 939 … … 940 942 * 941 943 * Returns the username for a user based on their user id. 942 * 944 * 943 945 * @package BuddyPress Core 944 946 * @param $uid int User ID to check. … … 950 952 function bp_core_get_username( $uid ) { 951 953 global $userdata; 952 954 953 955 if ( $uid == $userdata->ID ) 954 956 $username = __( 'You', 'buddypress' ); 955 957 956 958 if ( !$ud = get_userdata($uid) ) 957 959 return false; 958 959 $username = $ud->user_login; 960 961 $username = $ud->user_login; 960 962 961 963 return apply_filters( 'bp_core_get_username', $username ); … … 966 968 * 967 969 * Returns the URL with no HTML markup for a user based on their user id. 968 * 970 * 969 971 * @package BuddyPress Core 970 972 * @param $uid int User ID to check. … … 976 978 function bp_core_get_userurl( $uid ) { 977 979 global $bp; 978 980 979 981 if ( !is_numeric($uid) ) 980 982 return false; … … 987 989 * 988 990 * Returns the email address for the user based on user ID 989 * 991 * 990 992 * @package BuddyPress Core 991 993 * @param $uid int User ID to check. … … 1005 1007 * eg: <a href="http://andy.domain.com/">Andy Peatling</a> 1006 1008 * Optional parameters will return just the name, or just the URL, or disable "You" text when 1007 * user matches the logged in user. 1009 * user matches the logged in user. 1008 1010 * 1009 1011 * [NOTES: This function needs to be cleaned up or split into separate functions] 1010 * 1012 * 1011 1013 * @package BuddyPress Core 1012 1014 * @param $uid int User ID to check. … … 1023 1025 function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false, $deprecated = false, $with_s = false ) { 1024 1026 global $userdata; 1025 1027 1026 1028 $ud = get_userdata($user_id); 1027 1029 1028 1030 if ( !$ud ) 1029 1031 return false; 1030 1032 1031 if ( function_exists('bp_fetch_user_fullname') ) { 1033 if ( function_exists('bp_fetch_user_fullname') ) { 1032 1034 $display_name = bp_core_get_user_displayname( $user_id ); 1033 1035 1034 1036 if ( $with_s ) 1035 1037 $display_name = sprintf( __( "%s's", 'buddypress' ), $display_name ); 1036 1038 1037 1039 } else { 1038 1040 $display_name = $ud->display_name; 1039 1041 } 1040 1042 1041 1043 if ( $no_anchor ) 1042 1044 return $display_name; … … 1044 1046 if ( !$url = bp_core_get_userurl($user_id) ) 1045 1047 return false; 1046 1048 1047 1049 if ( $just_link ) 1048 1050 return $url; 1049 1051 1050 return '<a href="' . $url . '">' . $display_name . '</a>'; 1052 return '<a href="' . $url . '">' . $display_name . '</a>'; 1051 1053 } 1052 1054 … … 1057 1059 * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed. 1058 1060 * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set. 1059 * 1061 * 1060 1062 * @package BuddyPress Core 1061 1063 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1068 1070 function bp_core_get_user_displayname( $user_id ) { 1069 1071 global $bp; 1070 1072 1071 1073 if ( !$user_id ) 1072 1074 return false; 1073 1075 1074 1076 if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) { 1075 1077 if ( function_exists('xprofile_install') ) { … … 1088 1090 } else { 1089 1091 $ud = get_userdata($user_id); 1090 1092 1091 1093 if ( !empty( $ud->display_name ) ) 1092 1094 $fullname = $ud->display_name; … … 1094 1096 $fullname = $ud->user_nicename; 1095 1097 } 1096 1098 1097 1099 wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' ); 1098 1100 } 1099 1101 1100 1102 return apply_filters( 'bp_core_get_user_displayname', $fullname ); 1101 1103 } … … 1109 1111 * 1110 1112 * Returns the user link for the user based on user email address 1111 * 1113 * 1112 1114 * @package BuddyPress Core 1113 1115 * @param $email str The email address for the user. … … 1125 1127 * 1126 1128 * Returns the user link for the user based on user's username 1127 * 1129 * 1128 1130 * @package BuddyPress Core 1129 1131 * @param $username str The username for the user. … … 1133 1135 function bp_core_get_userlink_by_username( $username ) { 1134 1136 global $wpdb; 1135 1136 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ); 1137 1138 $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ); 1137 1139 return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) ); 1138 1140 } … … 1149 1151 function bp_core_is_user_spammer( $user_id ) { 1150 1152 global $wpdb; 1151 1152 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1153 1154 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1153 1155 } 1154 1156 … … 1164 1166 function bp_core_is_user_deleted( $user_id ) { 1165 1167 global $wpdb; 1166 1167 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1168 1169 return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) ); 1168 1170 } 1169 1171 … … 1174 1176 if ( !$time ) 1175 1177 return false; 1176 1178 1177 1179 $date = date( "F j, Y ", $time ); 1178 1180 1179 1181 if ( !$just_date ) { 1180 1182 $date .= __('at', 'buddypress') . date( ' g:iA', $time ); 1181 1183 } 1182 1184 1183 1185 return $date; 1184 1186 } … … 1189 1191 * 1190 1192 * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads. 1191 * 1193 * 1192 1194 * @package BuddyPress Core 1193 1195 */ 1194 1196 function bp_core_add_message( $message, $type = false ) { 1195 1197 global $bp; 1196 1198 1197 1199 if ( !$type ) 1198 1200 $type = 'success'; 1199 1201 1200 1202 /* Send the values to the cookie for page reload display */ 1201 1203 @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH ); 1202 1204 @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH ); 1203 1205 1204 1206 /*** 1205 1207 * Send the values to the $bp global so we can still output messages … … 1218 1220 * After the message is displayed, it removes the message vars from the cookie so that the message 1219 1221 * is not shown to the user multiple times. 1220 * 1222 * 1221 1223 * @package BuddyPress Core 1222 1224 * @global $bp_message The message text … … 1229 1231 if ( empty( $bp->template_message ) ) 1230 1232 $bp->template_message = $_COOKIE['bp-message']; 1231 1233 1232 1234 if ( empty( $bp->template_message_type ) ) 1233 1235 $bp->template_message_type = $_COOKIE['bp-message-type']; 1234 1236 1235 1237 add_action( 'template_notices', 'bp_core_render_message' ); 1236 1238 1237 1239 @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH ); 1238 1240 @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH ); … … 1245 1247 * Renders a feedback message (either error or success message) to the theme template. 1246 1248 * The hook action 'template_notices' is used to call this function, it is not called directly. 1247 * 1249 * 1248 1250 * @package BuddyPress Core 1249 1251 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1251 1253 function bp_core_render_message() { 1252 1254 global $bp; 1253 1255 1254 1256 if ( $bp->template_message ) { 1255 1257 $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error'; … … 1260 1262 <?php 1261 1263 do_action( 'bp_core_render_message' ); 1262 } 1264 } 1263 1265 } 1264 1266 … … 1267 1269 * 1268 1270 * Based on function created by Dunstan Orchard - http://1976design.com 1269 * 1271 * 1270 1272 * This function will return an English representation of the time elapsed 1271 1273 * since a given date. … … 1273 1275 * eg: 4 days 1274 1276 * eg: 4 weeks and 6 days 1275 * 1277 * 1276 1278 * @package BuddyPress Core 1277 1279 * @param $older_date int Unix timestamp of date you want to calculate the time since for … … 1291 1293 array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) ) 1292 1294 ); 1293 1295 1294 1296 $older_date = strtotime( gmdate( 'Y-m-d H:i:s', $older_date ) ); 1295 1297 … … 1297 1299 /* $newer_date will have a value if we want to work out time elapsed between two known dates */ 1298 1300 $newer_date = ( !$newer_date ) ? ( strtotime( gmdate( 'Y-m-d H:i:s' ) ) + ( 60*60*0 ) ) : $newer_date; 1299 1301 1300 1302 /* Difference in seconds */ 1301 1303 $since = $newer_date - $older_date; 1302 1304 1303 1305 if ( 0 > $since ) 1304 1306 return __( '[Use GMT Timezone]', 'buddypress' ); … … 1327 1329 $seconds2 = $chunks[$i + 1][0]; 1328 1330 $name2 = $chunks[$i + 1][1]; 1329 1331 1330 1332 //if ( $chunks[$i + 1][1] == __( 'second', 'buddypress' ) ) return $output; 1331 1333 1332 1334 if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) { 1333 1335 /* Add to output var */ … … 1349 1351 * show the length of time since the user was last active. 1350 1352 * This function will update that time as a usermeta setting for the user every 5 minutes. 1351 * 1353 * 1352 1354 * @package BuddyPress Core 1353 1355 * @global $userdata WordPress user data for the current logged in user. … … 1356 1358 function bp_core_record_activity() { 1357 1359 global $bp; 1358 1360 1359 1361 if ( !is_user_logged_in() ) 1360 1362 return false; 1361 1363 1362 1364 $activity = get_usermeta( $bp->loggedin_user->id, 'last_activity' ); 1363 1365 1364 1366 if ( '' == $activity || time() >= strtotime( '+5 minutes', $activity ) ) 1365 1367 update_usermeta( $bp->loggedin_user->id, 'last_activity', time() ); … … 1372 1374 * 1373 1375 * Formats last activity based on time since date given. 1374 * 1376 * 1375 1377 * @package BuddyPress Core 1376 1378 * @param last_activity_date The date of last activity. … … 1384 1386 } else { 1385 1387 if ( strstr( $last_activity_date, '-' ) ) { 1386 $last_active = bp_core_time_since( strtotime( $last_activity_date ) ); 1388 $last_active = bp_core_time_since( strtotime( $last_activity_date ) ); 1387 1389 } else { 1388 $last_active = bp_core_time_since( $last_activity_date ); 1390 $last_active = bp_core_time_since( $last_activity_date ); 1389 1391 } 1390 1392 1391 1393 $last_active = sprintf( $string, $last_active ); 1392 1394 } 1393 1395 1394 1396 return $last_active; 1395 1397 } … … 1400 1402 * 1401 1403 * Fetch every post that is authored by the given user for the current blog. 1402 * 1404 * 1403 1405 * @package BuddyPress Core 1404 1406 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1408 1410 function bp_core_get_all_posts_for_user( $user_id = null ) { 1409 1411 global $bp, $wpdb; 1410 1412 1411 1413 if ( !$user_id ) 1412 1414 $user_id = $bp->displayed_user->id; 1413 1415 1414 1416 return $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type = 'post'", $user_id ) ); 1415 1417 } … … 1420 1422 * 1421 1423 * Get the path of of the current site. 1422 * 1424 * 1423 1425 * @package BuddyPress Core 1424 1426 * @global $comment WordPress comment global for the current comment. … … 1427 1429 function bp_core_get_site_path() { 1428 1430 global $current_site; 1429 1431 1430 1432 return $current_site->path; 1431 1433 } … … 1435 1437 * 1436 1438 * Performs a status safe wp_redirect() that is compatible with bp_catch_uri() 1437 * 1439 * 1438 1440 * @package BuddyPress Core 1439 1441 * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri() … … 1443 1445 function bp_core_redirect( $location, $status = 302 ) { 1444 1446 global $bp_no_status_set; 1445 1446 // Make sure we don't call status_header() in bp_core_do_catch_uri() 1447 1448 // Make sure we don't call status_header() in bp_core_do_catch_uri() 1447 1449 // as this conflicts with wp_redirect() 1448 1450 $bp_no_status_set = true; 1449 1451 1450 1452 wp_redirect( $location, $status ); 1451 1453 die; … … 1456 1458 * 1457 1459 * Returns the referrer URL without the http(s):// 1458 * 1460 * 1459 1461 * @package BuddyPress Core 1460 1462 * @return The referrer URL … … 1473 1475 * 1474 1476 * For example, it would stop someone creating a blog with the slug "groups". 1475 * 1477 * 1476 1478 * @package BuddyPress Core 1477 1479 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1479 1481 function bp_core_add_illegal_names() { 1480 1482 global $bp; 1481 1483 1482 1484 $current = maybe_unserialize( get_site_option( 'illegal_names' ) ); 1483 1485 $bp_illegal_names = $bp->root_components; 1484 1486 1485 1487 if ( is_array( $current ) ) { 1486 1488 foreach( $bp_illegal_names as $bp_illegal_name ) { … … 1501 1503 * 1502 1504 * Sets the "From" name in emails sent to the name of the site and not "WordPress" 1503 * 1505 * 1504 1506 * @package BuddyPress Core 1505 1507 * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table … … 1516 1518 * 1517 1519 * Sets the "From" address in emails sent 1518 * 1520 * 1519 1521 * @package BuddyPress Core 1520 1522 * @global $current_site Object containing current site metadata … … 1532 1534 * 1533 1535 * Allows a user to completely remove their account from the system 1534 * 1536 * 1535 1537 * @package BuddyPress Core 1536 1538 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1564 1566 * 1565 1567 * A javascript free implementation of the search functions in BuddyPress 1566 * 1568 * 1567 1569 * @package BuddyPress Core 1568 1570 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 1575 1577 $search_terms = $_POST['search-terms']; 1576 1578 $search_which = $_POST['search-which']; 1577 1579 1578 1580 if ( !$slug || empty( $slug ) ) { 1579 1581 switch ( $search_which ) { … … 1596 1598 } 1597 1599 } 1598 1600 1599 1601 $search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms ); 1600 1602 1601 1603 bp_core_redirect( $search_url ); 1602 1604 } … … 1607 1609 /** 1608 1610 * bp_core_ucfirst() 1609 * 1611 * 1610 1612 * Localization safe ucfirst() support. 1611 * 1613 * 1612 1614 * @package BuddyPress Core 1613 1615 */ … … 1615 1617 if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) { 1616 1618 $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) ); 1617 return $fc.mb_substr( $str, 1 ); 1619 return $fc.mb_substr( $str, 1 ); 1618 1620 } else { 1619 1621 return ucfirst( $str ); … … 1624 1626 /** 1625 1627 * bp_core_strip_username_spaces() 1626 * 1628 * 1627 1629 * Strips spaces from usernames that are created using add_user() and wp_insert_user() 1628 * 1630 * 1629 1631 * @package BuddyPress Core 1630 1632 */ … … 1637 1639 /** 1638 1640 * bp_core_clear_cache() 1639 * REQUIRES WP-SUPER-CACHE 1640 * 1641 * REQUIRES WP-SUPER-CACHE 1642 * 1641 1643 * When wp-super-cache is installed this function will clear cached pages 1642 1644 * so that success/error messages are not cached, or time sensitive content. 1643 * 1645 * 1644 1646 * @package BuddyPress Core 1645 1647 */ 1646 1648 function bp_core_clear_cache() { 1647 1649 global $cache_path, $cache_filename; 1648 1650 1649 1651 if ( function_exists( 'prune_super_cache' ) ) { 1650 1652 do_action( 'bp_core_clear_cache' ); 1651 1652 return prune_super_cache( $cache_path, true ); 1653 1654 return prune_super_cache( $cache_path, true ); 1653 1655 } 1654 1656 } … … 1656 1658 /** 1657 1659 * bp_core_print_generation_time() 1658 * 1660 * 1659 1661 * Prints the generation time in the footer of the site. 1660 * 1662 * 1661 1663 * @package BuddyPress Core 1662 1664 */ … … 1671 1673 /** 1672 1674 * bp_core_add_admin_menu_page() 1673 * 1675 * 1674 1676 * A better version of add_admin_menu_page() that allows positioning of menus. 1675 * 1677 * 1676 1678 * @package BuddyPress Core 1677 1679 */ … … 1691 1693 $r = wp_parse_args( $args, $defaults ); 1692 1694 extract( $r, EXTR_SKIP ); 1693 1695 1694 1696 $file = plugin_basename( $file ); 1695 1697 … … 1708 1710 $position++; 1709 1711 } while ( !empty( $menu[$position] ) ); 1710 1712 1711 1713 $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); 1712 1714 … … 1721 1723 * When a user logs in, check if they have been marked as a spammer. If then simply 1722 1724 * redirect them to the home page and stop them from logging in. 1723 * 1725 * 1724 1726 * @package BuddyPress Core 1725 1727 * @param $username The username of the user … … 1728 1730 function bp_core_boot_spammer( $auth_obj, $username ) { 1729 1731 global $bp; 1730 1732 1731 1733 $user = get_userdatabylogin( $username ); 1732 1734 … … 1740 1742 * 1741 1743 * Deletes usermeta for the user when the user is deleted. 1742 * 1744 * 1743 1745 * @package BuddyPress Core 1744 1746 * @param $user_id The user id for the user to delete usermeta for … … 1758 1760 /** 1759 1761 * bp_load_buddypress_textdomain() 1760 * 1762 * 1761 1763 * Load the buddypress translation file for current language 1762 * 1764 * 1763 1765 * @package BuddyPress Core 1764 1766 */ … … 1766 1768 $locale = apply_filters( 'buddypress_locale', get_locale() ); 1767 1769 $mofile = BP_PLUGIN_DIR . "/bp-languages/buddypress-$locale.mo"; 1768 1770 1769 1771 if ( file_exists( $mofile ) ) 1770 1772 load_textdomain( 'buddypress', $mofile ); … … 1781 1783 /** 1782 1784 * bp_core_update_message() 1783 * 1785 * 1784 1786 * Add an extra update message to the update plugin notification. 1785 * 1787 * 1786 1788 * @package BuddyPress Core 1787 1789 */ … … 1793 1795 /** 1794 1796 * bp_core_clear_user_object_cache() 1795 * 1797 * 1796 1798 * Clears all cached objects for a user, or a user is part of. 1797 * 1799 * 1798 1800 * @package BuddyPress Core 1799 1801 */ -
trunk/bp-core/bp-core-activation.php
r2025 r2077 3 3 function bp_core_screen_activation() { 4 4 global $bp, $wpdb; 5 5 6 6 if ( BP_ACTIVATION_SLUG != $bp->current_component ) 7 7 return false; 8 8 9 9 /* If we are using a BuddyPress 1.0 theme ignore this. */ 10 10 if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) ) 11 11 return false; 12 12 13 13 /* Check if an activation key has been passed */ 14 14 if ( isset( $_GET['key'] ) ) { 15 15 16 16 require_once( ABSPATH . WPINC . '/registration.php' ); 17 17 18 18 /* Activate the signup */ 19 19 $signup = apply_filters( 'bp_core_activate_account', wpmu_activate_signup( $_GET['key'] ) ); 20 20 21 21 /* If there was errors, add a message and redirect */ 22 22 if ( $signup->errors ) { … … 24 24 bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG ); 25 25 } 26 26 27 27 /* Set the password */ 28 28 if ( !empty( $signup['meta']['password'] ) ) 29 29 $wpdb->update( $wpdb->users, array( 'user_pass' => $signup['meta']['password'] ), array( 'ID' => $signup['user_id'] ), array( '%s' ), array( '%d' ) ); 30 31 /* Set any profile data */ 30 31 /* Set any profile data */ 32 32 if ( function_exists( 'xprofile_set_field_data' ) ) { 33 33 34 34 if ( !empty( $signup['meta']['profile_field_ids'] ) ) { 35 35 $profile_field_ids = explode( ',', $signup['meta']['profile_field_ids'] ); 36 36 37 37 foreach( $profile_field_ids as $field_id ) { 38 38 $current_field = $signup['meta']["field_{$field_id}"]; 39 39 40 40 if ( !empty( $current_field ) ) 41 41 xprofile_set_field_data( $field_id, $signup['user_id'], $current_field ); 42 42 } 43 43 } 44 44 45 45 } 46 46 47 47 /* Check for an uploaded avatar and move that to the correct user folder */ 48 48 $hashed_key = wp_hash( $_GET['key'] ); 49 49 50 50 /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */ 51 51 if ( file_exists( WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/signups/' . $hashed_key ) ) { 52 52 @rename( WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/signups/' . $hashed_key, WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/avatars/' . $signup['user_id'] ); 53 53 } 54 54 55 55 /* Record the new user in the activity streams */ 56 56 if ( function_exists( 'bp_activity_add' ) ) { 57 57 $userlink = bp_core_get_userlink( $signup['user_id'] ); 58 58 59 59 bp_activity_add( array( 60 60 'user_id' => $signup['user_id'], … … 62 62 'primary_link' => apply_filters( 'bp_core_actiivty_registered_member_primary_link', $userlink ), 63 63 'component_name' => 'profile', 64 'component_action' => 'new_member' 64 'component_action' => 'new_member' 65 65 ) ); 66 66 } … … 68 68 do_action( 'bp_core_account_activated', &$signup, $_GET['key'] ); 69 69 bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) ); 70 70 71 71 $bp->activation_complete = true; 72 72 } 73 73 74 74 if ( '' != locate_template( array( 'registration/activate' ), false ) ) 75 bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) ); 75 bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) ); 76 76 else 77 bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) ); 77 bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) ); 78 78 } 79 79 add_action( 'wp', 'bp_core_screen_activation', 3 ); … … 91 91 if ( '' == locate_template( array( 'registration/register.php' ), false ) && '' == locate_template( array( 'register.php' ), false ) ) 92 92 return true; 93 93 94 94 return false; 95 95 } -
trunk/bp-core/bp-core-admin.php
r2029 r2077 4 4 global $wpdb, $bp, $current_blog; 5 5 ?> 6 6 7 7 <?php 8 8 if ( isset( $_POST['bp-admin-submit'] ) && isset( $_POST['bp-admin'] ) ) { 9 9 if ( !check_admin_referer('bp-admin') ) 10 10 return false; 11 11 12 12 // Settings form submitted, now save the settings. 13 13 foreach ( $_POST['bp-admin'] as $key => $value ) { 14 14 15 15 if ( function_exists( 'xprofile_install' ) ) { 16 16 if ( 'bp-xprofile-base-group-name' == $key ) { 17 17 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s WHERE name = %s AND id = 1", $value, stripslashes( get_site_option('bp-xprofile-base-group-name') ) ) ); 18 18 } 19 19 20 20 if ( 'bp-xprofile-fullname-field-name' == $key ) { 21 21 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET name = %s WHERE name = %s AND group_id = 1", $value, stripslashes( get_site_option('bp-xprofile-fullname-field-name') ) ) ); 22 22 } 23 23 } 24 24 25 25 update_site_option( $key, $value ); 26 26 } 27 27 } 28 28 ?> 29 29 30 30 <div class="wrap"> 31 31 32 32 <h2><?php _e( 'BuddyPress Settings', 'buddypress' ) ?></h2> 33 33 … … 39 39 40 40 <form action="" method="post" id="bp-admin-form"> 41 41 42 42 <table class="form-table"> 43 43 <tbody> … … 47 47 <td> 48 48 <input name="bp-admin[bp-xprofile-base-group-name]" id="bp-xprofile-base-group-name" value="<?php echo get_site_option('bp-xprofile-base-group-name') ?>" /> 49 </td> 49 </td> 50 50 </tr> 51 51 <tr> … … 60 60 <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> 61 61 <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?> 62 </td> 62 </td> 63 63 </tr> 64 64 <?php endif; ?> … … 68 68 <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> 69 69 <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?> 70 </td> 70 </td> 71 71 </tr> 72 72 <tr> … … 83 83 <input type="radio" name="bp-admin[non-friend-wire-posting]"<?php if ( (int)get_site_option( 'non-friend-wire-posting' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-non-friend-wire-post" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> 84 84 <input type="radio" name="bp-admin[non-friend-wire-posting]"<?php if ( !(int)get_site_option( 'non-friend-wire-posting' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-non-friend-wire-post" value="0" /> <?php _e( 'No', 'buddypress' ) ?> 85 </td> 86 </tr> 87 <?php } ?> 85 </td> 86 </tr> 87 <?php } ?> 88 88 <tr> 89 89 <th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th> … … 91 91 <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> 92 92 <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) || '' == get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?> 93 </td> 93 </td> 94 94 </tr> 95 95 <?php if ( function_exists( 'bp_forums_setup') ) : ?> … … 99 99 <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> 100 100 <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) || '' == get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?> 101 </td> 102 </tr> 103 <?php endif; ?> 104 101 </td> 102 </tr> 103 <?php endif; ?> 104 105 105 <?php $themes = bp_core_get_buddypress_themes() ?> 106 106 <?php if ( $themes ) : ?> … … 109 109 <td> 110 110 <select name="bp-admin[active-member-theme]" id="active-member-theme"> 111 <?php 112 for ( $i = 0; $i < count($themes); $i++ ) { 111 <?php 112 for ( $i = 0; $i < count($themes); $i++ ) { 113 113 if ( $themes[$i]['template'] == get_site_option( 'active-member-theme' ) ) { 114 114 $selected = ' selected="selected"'; … … 120 120 <?php } ?> 121 121 </select> 122 </td> 122 </td> 123 123 </tr> 124 124 <?php else : ?> … … 129 129 <?php endif; ?> 130 130 <?php endif; ?> 131 131 132 132 <tr> 133 133 <th scope="row"><?php _e( 'Default User Avatar', 'buddypress' ) ?></th> … … 147 147 148 148 <?php do_action( 'bp_core_admin_screen' ) ?> 149 149 150 150 <p class="submit"> 151 151 <input class="button-primary" type="submit" name="bp-admin-submit" id="bp-admin-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/> … … 153 153 154 154 <?php wp_nonce_field( 'bp-admin' ) ?> 155 155 156 156 </form> 157 157 158 158 </div> 159 160 <?php 159 160 <?php 161 161 } 162 162 … … 164 164 global $wpdb, $bp; 165 165 ?> 166 166 167 167 <?php 168 168 if ( isset( $_POST['bp-admin-component-submit'] ) && isset( $_POST['bp_components'] ) ) { 169 169 if ( !check_admin_referer('bp-admin-component-setup') ) 170 170 return false; 171 171 172 172 // Settings form submitted, now save the settings. 173 173 foreach ( $_POST['bp_components'] as $key => $value ) { 174 174 if ( !(int) $value ) 175 $disabled[$key] = 1; 175 $disabled[$key] = 1; 176 176 } 177 177 update_site_option( 'bp-deactivated-components', $disabled ); 178 178 } 179 179 ?> 180 180 181 181 <div class="wrap"> 182 182 183 183 <h2><?php _e( 'BuddyPress Component Setup', 'buddypress' ) ?></h2> 184 184 185 185 <?php if ( isset( $_POST['bp-admin-component-submit'] ) ) : ?> 186 186 <div id="message" class="updated fade"> … … 188 188 </div> 189 189 <?php endif; ?> 190 190 191 191 <form action="" method="post" id="bp-admin-component-form"> 192 192 193 193 <p> 194 <?php _e( 195 'By default, all BuddyPress components are enabled. You can selectively disable any of the 194 <?php _e( 195 'By default, all BuddyPress components are enabled. You can selectively disable any of the 196 196 components by using the form below. Your BuddyPress installation will continue to function, however 197 197 the features of the disabled components will no longer be accessible to … … 199 199 ', 'buddypress' )?> 200 200 </p> 201 201 202 202 <?php $disabled_components = get_site_option( 'bp-deactivated-components' ); ?> 203 203 204 204 <table class="form-table" style="width: 80%"> 205 205 <tbody> … … 210 210 <input type="radio" name="bp_components[bp-activity.php]" value="1"<?php if ( !isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 211 211 <input type="radio" name="bp_components[bp-activity.php]" value="0"<?php if ( isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 212 </td> 212 </td> 213 213 </tr> 214 214 <?php endif; ?> … … 219 219 <input type="radio" name="bp_components[bp-blogs.php]" value="1"<?php if ( !isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 220 220 <input type="radio" name="bp_components[bp-blogs.php]" value="0"<?php if ( isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 221 </td> 221 </td> 222 222 </tr> 223 223 <?php endif; ?> … … 228 228 <input type="radio" name="bp_components[bp-forums.php]" value="1"<?php if ( !isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 229 229 <input type="radio" name="bp_components[bp-forums.php]" value="0"<?php if ( isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 230 </td> 230 </td> 231 231 </tr> 232 232 <?php endif; ?> … … 237 237 <input type="radio" name="bp_components[bp-friends.php]" value="1"<?php if ( !isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 238 238 <input type="radio" name="bp_components[bp-friends.php]" value="0"<?php if ( isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 239 </td> 239 </td> 240 240 </tr> 241 241 <?php endif; ?> … … 246 246 <input type="radio" name="bp_components[bp-groups.php]" value="1"<?php if ( !isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 247 247 <input type="radio" name="bp_components[bp-groups.php]" value="0"<?php if ( isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 248 </td> 248 </td> 249 249 </tr> 250 250 <?php endif; ?> … … 255 255 <input type="radio" name="bp_components[bp-messages.php]" value="1"<?php if ( !isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 256 256 <input type="radio" name="bp_components[bp-messages.php]" value="0"<?php if ( isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 257 </td> 257 </td> 258 258 </tr> 259 259 <?php endif; ?> … … 264 264 <input type="radio" name="bp_components[bp-wire.php]" value="1"<?php if ( !isset( $disabled_components['bp-wire.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> 265 265 <input type="radio" name="bp_components[bp-wire.php]" value="0"<?php if ( isset( $disabled_components['bp-wire.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?> 266 </td> 266 </td> 267 267 </tr> 268 268 <?php endif; ?> … … 287 287 </tbody> 288 288 </table> 289 289 290 290 <p class="submit"> 291 291 <input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/> 292 292 </p> 293 293 294 294 <?php wp_nonce_field( 'bp-admin-component-setup' ) ?> 295 295 296 296 </form> 297 297 298 298 </div> 299 300 <?php 299 300 <?php 301 301 } 302 302 -
trunk/bp-core/bp-core-adminbar.php
r1905 r2077 3 3 function bp_core_admin_bar() { 4 4 global $bp, $wpdb, $current_blog, $doing_admin_bar; 5 5 6 6 if ( defined( 'BP_DISABLE_ADMIN_BAR' ) ) 7 7 return false; 8 8 9 9 $doing_admin_bar = true; 10 10 11 11 if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) 12 12 return false; … … 18 18 19 19 echo '<ul class="main-nav">'; 20 20 21 21 // **** Do bp-adminbar-menus Actions ******** 22 22 do_action( 'bp_adminbar_menus' ); … … 29 29 function bp_adminbar_logo() { 30 30 global $bp; 31 31 32 32 echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>'; 33 33 } … … 37 37 global $bp; 38 38 39 if ( !is_user_logged_in() ) { 39 if ( !is_user_logged_in() ) { 40 40 echo '<li class="bp-login no-arrow"><a href="' . $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>'; 41 41 42 42 // Show "Sign Up" link if user registrations are allowed 43 43 if ( get_site_option( 'registration' ) != 'none' && get_site_option( 'registration' ) != 'blog' ) { … … 55 55 56 56 if ( is_user_logged_in() ) { 57 57 58 58 echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">'; 59 59 60 60 echo __( 'My Account', 'buddypress' ) . '</a>'; 61 61 echo '<ul>'; 62 62 63 63 /* Loop through each navigation item */ 64 64 $counter = 0; 65 65 foreach( $bp->bp_nav as $nav_item ) { 66 66 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 67 67 68 68 echo '<li' . $alt . '>'; 69 69 echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>'; 70 70 71 71 if ( is_array( $bp->bp_options_nav[$nav_item['css_id']] ) ) { 72 72 echo '<ul>'; … … 75 75 foreach( $bp->bp_options_nav[$nav_item['css_id']] as $subnav_item ) { 76 76 $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : ''; 77 echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>'; 77 echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>'; 78 78 $sub_counter++; 79 79 } 80 80 echo '</ul>'; 81 81 } 82 82 83 83 echo '</li>'; 84 84 85 85 $counter++; 86 86 } 87 87 88 88 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 89 89 90 if ( function_exists('wp_logout_url') ) { 91 echo '<li' . $alt . '><a id="bp-admin-logout" href="' . wp_logout_url(site_url()) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 92 } else { 93 echo '<li' . $alt . '><a id="bp-admin-logout" href="' . site_url() . '/wp-login.php?action=logout&redirect_to=' . site_url() . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 94 } 95 90 if ( function_exists('wp_logout_url') ) { 91 echo '<li' . $alt . '><a id="bp-admin-logout" href="' . wp_logout_url(site_url()) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 92 } else { 93 echo '<li' . $alt . '><a id="bp-admin-logout" href="' . site_url() . '/wp-login.php?action=logout&redirect_to=' . site_url() . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 94 } 95 96 96 echo '</ul>'; 97 97 echo '</li>'; … … 101 101 // return a string indicating user's role in that blog 102 102 function get_blog_role_for_user( $user, $blog ) { 103 103 104 104 // If the user is a site admin, just display admin. 105 if ( is_site_admin() ) 105 if ( is_site_admin() ) 106 106 return __( 'Admin', 'buddypress'); 107 107 108 108 $roles = get_usermeta( $user, 'wp_' . $blog . '_capabilities' ); 109 109 110 110 if ( isset( $roles['subscriber'] ) ) 111 $role = __( 'Subscriber', 'buddypress' ); 111 $role = __( 'Subscriber', 'buddypress' ); 112 112 elseif ( isset( $roles['contributor'] ) ) 113 113 $role = __( 'Contributor', 'buddypress' ); … … 120 120 else 121 121 return false; 122 122 123 123 return $role; 124 124 } … … 127 127 function bp_adminbar_blogs_menu() { 128 128 if ( is_user_logged_in() ) { 129 global $bp; 130 129 global $bp; 130 131 131 if ( function_exists('bp_blogs_install') ) { 132 132 133 133 if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id, 'bp' ) ) { 134 134 $blogs = get_blogs_of_user( $bp->loggedin_user->id ); … … 137 137 138 138 echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/my-blogs">'; 139 139 140 140 _e( 'My Blogs', 'buddypress' ); 141 141 142 142 echo '</a>'; 143 144 echo '<ul>'; 143 144 echo '<ul>'; 145 145 if ( is_array( $blogs )) { 146 146 147 147 $counter = 0; 148 148 foreach( $blogs as $blog ) { … … 157 157 echo '<li><a href="' . $blog->siteurl . '/wp-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>'; 158 158 echo '<li class="alt"><a href="' . $blog->siteurl . '/wp-admin/edit.php">' . __('Manage Posts', 'buddypress') . '</a></li>'; 159 echo '<li><a href="' . $blog->siteurl . '/wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>'; 160 if ( 'Admin' == $role ) { 161 echo '<li class="alt"><a href="' . $blog->siteurl . '/wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>'; 162 } 163 echo '</ul>'; 159 echo '<li><a href="' . $blog->siteurl . '/wp-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>'; 160 if ( 'Admin' == $role ) { 161 echo '<li class="alt"><a href="' . $blog->siteurl . '/wp-admin/themes.php">' . __('Switch Theme', 'buddypress') . '</a></li>'; 162 } 163 echo '</ul>'; 164 164 } 165 165 echo '</li>'; … … 167 167 } 168 168 } 169 169 170 170 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 171 171 172 172 if ( bp_blog_signup_enabled() ) { 173 173 echo '<li' . $alt . '>'; … … 175 175 echo '</li>'; 176 176 } 177 177 178 178 echo '</ul>'; 179 179 echo '</li>'; 180 180 } 181 181 } 182 } 182 } 183 183 184 184 // **** "Notifications" Menu ********* 185 function bp_adminbar_notifications_menu() { 185 function bp_adminbar_notifications_menu() { 186 186 if ( is_user_logged_in() ) { 187 187 global $bp; 188 188 189 189 echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">'; 190 190 _e( 'Notifications', 'buddypress' ); 191 191 192 192 if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?> 193 193 <span><?php echo count($notifications) ?></span> 194 194 <?php 195 195 } 196 196 197 197 echo '</a>'; 198 198 echo '<ul>'; 199 199 200 200 if ( $notifications ) { ?> 201 201 <?php $counter = 0; ?> … … 209 209 <?php 210 210 } 211 211 212 212 echo '</ul>'; 213 213 echo '</li>'; … … 218 218 function bp_adminbar_authors_menu() { 219 219 global $current_blog; 220 220 221 221 if ( $current_blog->blog_id > 1 ) { 222 $authors = get_users_of_blog(); 223 222 $authors = get_users_of_blog(); 223 224 224 if ( is_array( $authors ) ) { 225 225 /* This is a blog, render a menu with links to all authors */ … … 227 227 _e('Blog Authors', 'buddypress'); 228 228 echo '</a>'; 229 229 230 230 echo '<ul class="author-list">'; 231 231 foreach( $authors as $author ) { … … 246 246 } 247 247 } 248 248 249 249 // **** "Random" Menu (visible when not logged in) ******** 250 function bp_adminbar_random_menu() { 250 function bp_adminbar_random_menu() { 251 251 global $bp; ?> 252 252 <li class="align-right" id="bp-adminbar-visitrandom-menu"> … … 261 261 <?php if ( function_exists('bp_blogs_install') ) : ?> 262 262 <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li> 263 263 264 264 <?php endif; ?> 265 265 266 266 <?php do_action( 'bp_adminbar_random_menu' ) ?> 267 267 </ul> -
trunk/bp-core/bp-core-avatars.php
r2069 r2077 32 32 if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) ) 33 33 define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-xprofile/images/none-thumbnail.gif' ); 34 34 35 35 function bp_core_fetch_avatar( $args = '' ) { 36 36 global $bp, $current_blog; 37 37 38 38 $defaults = array( 39 39 'item_id' => false, … … 41 41 'type' => 'thumb', 42 42 'avatar_dir' => false, 43 'width' => false, 43 'width' => false, 44 44 'height' => false, 45 45 'class' => 'avatar', … … 50 50 51 51 $params = wp_parse_args( $args, $defaults ); 52 extract( $params, EXTR_SKIP ); 52 extract( $params, EXTR_SKIP ); 53 53 54 54 if ( !$item_id ) { … … 59 59 else if ( 'blog' == $object ) 60 60 $item_id = $current_blog->id; 61 61 62 62 $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object ); 63 63 64 64 if ( !$item_id ) return false; 65 65 } 66 66 67 67 if ( !$avatar_dir ) { 68 68 if ( 'user' == $object ) … … 72 72 else if ( 'blog' == $object ) 73 73 $avatar_dir = 'blog-avatars'; 74 74 75 75 $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object ); 76 77 if ( !$avatar_dir ) return false; 78 } 79 76 77 if ( !$avatar_dir ) return false; 78 } 79 80 80 if ( !$css_id ) 81 $css_id = $object . '-' . $item_id . '-avatar'; 82 81 $css_id = $object . '-' . $item_id . '-avatar'; 82 83 83 if ( $width ) 84 84 $html_width = " width='{$width}'"; 85 85 else 86 86 $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"'; 87 87 88 88 if ( $height ) 89 89 $html_height = " height='{$height}'"; 90 90 else 91 91 $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"'; 92 93 $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 94 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 92 93 $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 94 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 95 95 96 96 /**** … … 116 116 } 117 117 118 /* If no avatars have been uploaded for this item, display a gravatar */ 118 /* If no avatars have been uploaded for this item, display a gravatar */ 119 119 if ( !file_exists( $avatar_url ) && !$no_grav ) { 120 121 120 if ( empty( $bp->grav_default->{$object} ) ) 122 121 $default_grav = 'wavatar'; … … 129 128 else if ( 'full' == $type ) $grav_size = BP_AVATAR_FULL_WIDTH; 130 129 else if ( 'thumb' == $type ) $grav_size = BP_AVATAR_THUMB_WIDTH; 131 130 132 131 if ( 'user' == $object ) { 133 132 $ud = get_userdata( $item_id ); … … 136 135 $grav_email = "{$item_id}-{$object}@{$bp->root_domain}"; 137 136 } 138 139 $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object ); 137 138 $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object ); 140 139 $gravatar = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $grav_email ) . '?d=' . $default_grav . '&s=' . $grav_size; 141 140 142 141 return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params ); 143 144 142 } else if ( !file_exists( $avatar_url ) && $no_grav ) 145 143 return false; 146 147 144 } 148 145 149 146 function bp_core_delete_existing_avatar( $args = '' ) { 150 147 global $bp; 151 148 152 149 $defaults = array( 153 150 'item_id' => false, … … 157 154 158 155 $args = wp_parse_args( $args, $defaults ); 159 extract( $args, EXTR_SKIP ); 160 156 extract( $args, EXTR_SKIP ); 157 161 158 if ( !$item_id ) { 162 159 if ( 'user' == $object ) … … 166 163 else if ( 'blog' == $object ) 167 164 $item_id = $current_blog->id; 168 165 169 166 $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object ); 170 167 171 168 if ( !$item_id ) return false; 172 169 } 173 170 174 171 if ( !$avatar_dir ) { 175 172 if ( 'user' == $object ) … … 179 176 else if ( 'blog' == $object ) 180 177 $avatar_dir = 'blog-avatars'; 181 178 182 179 $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object ); 183 184 if ( !$avatar_dir ) return false; 180 181 if ( !$avatar_dir ) return false; 185 182 } 186 183 … … 193 190 } 194 191 195 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 192 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 196 193 197 194 if ( !file_exists( $avatar_folder_dir ) ) … … 201 198 while ( false !== ( $avatar_file = readdir($av_dir) ) ) { 202 199 if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file ) 203 @unlink( $avatar_folder_dir . '/' . $avatar_file ); 200 @unlink( $avatar_folder_dir . '/' . $avatar_file ); 204 201 } 205 202 } … … 215 212 function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) { 216 213 global $bp; 217 214 218 215 require_once( ABSPATH . '/wp-admin/includes/image.php' ); 219 216 require_once( ABSPATH . '/wp-admin/includes/file.php' ); 220 217 221 218 $uploadErrors = array( 222 0 => __("There is no error, the file uploaded with success", 'buddypress'), 223 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE), 219 0 => __("There is no error, the file uploaded with success", 'buddypress'), 220 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE), 224 221 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE), 225 222 3 => __("The uploaded file was only partially uploaded", 'buddypress'), … … 232 229 return false; 233 230 } 234 231 235 232 if ( !bp_core_check_avatar_size( $file ) ) { 236 233 bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' ); 237 234 return false; 238 235 } 239 236 240 237 if ( !bp_core_check_avatar_type( $file ) ) { 241 238 bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' ); 242 239 return false; 243 240 } 244 241 245 242 // Filter the upload location 246 243 add_filter( 'upload_dir', $upload_dir_filter, 10, 0 ); 247 244 248 245 $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) ); 249 246 … … 253 250 return false; 254 251 } 255 252 256 253 // Resize the image down to something manageable and then delete the original 257 254 if ( getimagesize( $bp->avatar_admin->original['file'] ) > BP_AVATAR_ORIGINAL_MAX_WIDTH ) { 258 255 $bp->avatar_admin->resized = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH ); 259 256 } 260 257 261 258 $bp->avatar_admin->image = new stdClass; 262 263 // We only want to handle one image after resize. 259 260 // We only want to handle one image after resize. 264 261 if ( empty( $bp->avatar_admin->resized ) ) 265 262 $bp->avatar_admin->image->dir = $bp->avatar_admin->original['file']; … … 268 265 @unlink( $bp->avatar_admin->original['file'] ); 269 266 } 270 267 271 268 /* Set the url value for the image */ 272 269 $bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $bp->avatar_admin->image->dir ); … … 277 274 function bp_core_avatar_handle_crop( $args = '' ) { 278 275 global $bp; 279 276 280 277 $defaults = array( 281 278 'object' => 'user', … … 297 294 if ( !file_exists( WP_CONTENT_DIR . '/' . $original_file ) ) 298 295 return false; 299 296 300 297 if ( !$item_id ) 301 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir ); 298 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir ); 302 299 else 303 300 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); … … 305 302 if ( !file_exists( $avatar_folder_dir ) ) 306 303 return false; 307 304 308 305 require_once( ABSPATH . '/wp-admin/includes/image.php' ); 309 306 require_once( ABSPATH . '/wp-admin/includes/file.php' ); … … 311 308 /* Delete the existing avatar files for the object */ 312 309 bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) ); 313 310 314 311 /* Make sure we at least have a width and height for cropping */ 315 312 if ( !(int)$crop_w ) 316 313 $crop_w = BP_AVATAR_FULL_WIDTH; 317 314 318 315 if ( !(int)$crop_h ) 319 316 $crop_h = BP_AVATAR_FULL_HEIGHT; … … 322 319 $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg'; 323 320 $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg'; 324 321 325 322 /* Crop the image */ 326 323 $full_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename ); … … 337 334 if ( is_object ( $id_or_email ) ) 338 335 $id_or_email = $id_or_email->user_id; 339 336 340 337 $bp_avatar = bp_core_fetch_avatar( array( 'no_grav' => true, 'item_id' => $id_or_email, 'width' => $size, 'height' => $size, 'alt' => $alt ) ); 341 338 … … 347 344 if ( $file['error'] ) 348 345 return false; 349 346 350 347 return true; 351 348 } … … 354 351 if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE ) 355 352 return false; 356 353 357 354 return true; 358 355 } … … 361 358 if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) ) 362 359 return false; 363 360 364 361 return true; 365 362 } -
trunk/bp-core/bp-core-catchuri.php
r2027 r2077 17 17 * - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... 18 18 * - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ... 19 * 19 * 20 20 * Example: 21 21 * - http://domain.com/members/andy/profile/edit/group/5/ … … 23 23 * - $bp->current_action: string 'edit' 24 24 * - $bp->action_variables: array ['group', 5] 25 * 25 * 26 26 * @package BuddyPress Core 27 27 */ … … 32 32 global $bp_unfiltered_uri; 33 33 global $bp, $current_blog; 34 34 35 35 if ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) { 36 36 /* Only catch URI's on the root blog if we are not running BP on multiple blogs */ … … 64 64 array_shift( $bp_uri ); 65 65 } 66 66 67 67 /* Set the indexes, these are incresed by one if we are not on a VHOST install */ 68 68 $component_index = 0; 69 69 $action_index = $component_index + 1; 70 70 71 71 // If this is a WordPress page, return from the function. 72 72 if ( is_page( $bp_uri[$component_index] ) ) 73 73 return false; 74 74 75 75 /* Get site path items */ 76 76 $paths = explode( '/', bp_core_get_site_path() ); … … 93 93 $bp_uri = array_merge( array(), $bp_uri ); 94 94 $bp_unfiltered_uri = $bp_uri; 95 95 96 96 /* If we are under anything with a members slug, set the correct globals */ 97 97 if ( $bp_uri[0] == BP_MEMBERS_SLUG ) { 98 98 $is_member_page = true; 99 $is_root_component = true; 99 $is_root_component = true; 100 100 } 101 101 102 102 /* Catch a member page and set the current member ID */ 103 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) { 104 if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) { 103 if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) { 104 if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) { 105 105 // We are within a member page, set up user id globals 106 106 $displayed_user_id = bp_core_get_displayed_userid( $bp_uri[1] ); … … 108 108 unset($bp_uri[0]); 109 109 unset($bp_uri[1]); 110 110 111 111 /* Reset the keys by merging with an empty array */ 112 112 $bp_uri = array_merge( array(), $bp_uri ); … … 116 116 $is_member_page = true; 117 117 $is_root_component = true; 118 118 119 119 // We are within a member page, set up user id globals 120 120 $displayed_user_id = bp_core_get_displayed_userid( $bp_uri[0] ); 121 121 122 122 unset($bp_uri[0]); 123 123 … … 126 126 } 127 127 } 128 128 129 129 if ( !isset($is_root_component) ) 130 130 $is_root_component = in_array( $bp_uri[0], $bp->root_components ); … … 137 137 /* Set the current component */ 138 138 $current_component = $bp_uri[$component_index]; 139 139 140 140 /* Set the current action */ 141 141 $current_action = $bp_uri[$action_index]; 142 142 143 143 /* Set the entire URI as the action variables, we will unset the current_component and action in a second */ 144 144 $action_variables = $bp_uri; … … 151 151 if ( 'no' == VHOST && !$is_root_component ) 152 152 array_shift($action_variables); 153 153 154 154 /* Reset the keys by merging with an empty array */ 155 155 $action_variables = array_merge( array(), $action_variables ); … … 162 162 * bp_catch_uri() 163 163 * 164 * Takes either a single page name or array of page names and 164 * Takes either a single page name or array of page names and 165 165 * loads the first template file that can be found. 166 166 * 167 167 * Please don't call this function directly anymore, use: bp_core_load_template() 168 * 168 * 169 169 * @package BuddyPress Core 170 170 * @global $bp_path BuddyPress global containing the template file names to use. … … 174 174 function bp_catch_uri( $pages, $skip_blog_check = false ) { 175 175 global $bp_path, $bp_skip_blog_check; 176 176 177 177 $bp_skip_blog_check = $skip_blog_check; 178 178 … … 189 189 * 190 190 * Loads the first template file found based on the $bp_path global. 191 * 191 * 192 192 * @package BuddyPress Core 193 193 * @global $bp_path BuddyPress global containing the template file names to use. … … 198 198 global $bp_no_status_set; 199 199 global $wp_query; 200 201 /* Can be a single template or an array of templates */ 200 201 /* Can be a single template or an array of templates */ 202 202 $templates = $bp_path; 203 203 204 204 /* Don't hijack any URLs on blog pages */ 205 205 if ( bp_is_blog_page() ) { … … 214 214 status_header( 200 ); 215 215 $wp_query->is_404 = false; 216 216 217 217 if ( $bp->current_component != BP_HOME_BLOG_SLUG ) 218 218 $wp_query->is_page = true; 219 219 } 220 220 221 221 foreach ( (array)$templates as $template ) 222 222 $filtered_templates[] = $template . '.php'; 223 223 224 224 if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) { 225 225 load_template( apply_filters( 'bp_load_template', $located_template ) ); … … 269 269 * If the extended profiles component is not installed we still need 270 270 * to catch the /profile URI's and display whatever we have installed. 271 * 271 * 272 272 */ 273 273 function bp_core_catch_profile_uri() { 274 274 global $bp; 275 275 276 276 if ( !function_exists('xprofile_install') ) 277 277 bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'profile/index' ) ); -
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 -
trunk/bp-core/bp-core-cssjs.php
r2069 r2077 5 5 * 6 6 * Add the CSS needed for the admin bar on blogs (other than the root) and in the admin area. 7 * 7 * 8 8 * @package BuddyPress Core 9 9 * @uses get_option() Selects a site setting from the DB. … … 11 11 function bp_core_add_admin_bar_css() { 12 12 global $current_blog; 13 13 14 14 if ( defined( 'BP_DISABLE_ADMIN_BAR' ) ) 15 15 return false; … … 32 32 * 33 33 * Add the minor JS needed for the admin bar. 34 * 34 * 35 35 * @package BuddyPress Core 36 36 * @uses get_option() Selects a site setting from the DB. … … 46 46 * 47 47 * Add a hover-able icon to the "BuddyPress" wp-admin area menu. 48 * 48 * 49 49 * @package BuddyPress Core 50 50 */ … … 60 60 } 61 61 add_action( 'admin_head', 'bp_core_admin_menu_icon_css' ); 62 62 63 63 function bp_core_confirmation_js() { 64 64 ?> … … 72 72 * 73 73 * Makes sure the jQuery jCrop library is loaded. 74 * 74 * 75 75 * @package BuddyPress Core 76 76 */ 77 77 function bp_core_add_jquery_cropper() { 78 78 wp_enqueue_script( 'jcrop', array( 'jquery' ) ); 79 add_action( 'wp_head', 'bp_core_add_cropper_inline_js' ); 80 add_action( 'wp_head', 'bp_core_add_cropper_inline_css' ); 79 add_action( 'wp_head', 'bp_core_add_cropper_inline_js' ); 80 add_action( 'wp_head', 'bp_core_add_cropper_inline_css' ); 81 81 } 82 82 … … 85 85 * 86 86 * Adds the inline JS needed for the cropper to work on a per-page basis. 87 * 87 * 88 88 * @package BuddyPress Core 89 89 */ 90 90 function bp_core_add_cropper_inline_js() { 91 91 global $bp; 92 92 93 93 $image = apply_filters( 'bp_inline_cropper_image', getimagesize( $bp->avatar_admin->image->dir ) ); 94 94 95 $aspect_ratio = 1; 96 95 $aspect_ratio = 1; 96 97 97 /* Calculate Aspect Ratio */ 98 if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) ) 98 if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) ) 99 99 $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' ); 100 100 ?> … … 131 131 }); 132 132 } 133 } 133 } 134 134 </script> 135 135 <?php … … 140 140 * 141 141 * Adds the inline CSS needed for the cropper to work on a per-page basis. 142 * 142 * 143 143 * @package BuddyPress Core 144 144 */ … … 166 166 * 167 167 * Adds AJAX target URL so themes can access the WordPress AJAX functionality. 168 * 168 * 169 169 * @package BuddyPress Core 170 170 */ 171 171 function bp_core_add_ajax_url_js() { 172 172 global $bp; 173 174 echo 173 174 echo 175 175 '<script type="text/javascript">var ajaxurl = "' . $bp->root_domain . str_replace( 'index.php', 'wp-load.php', $_SERVER['SCRIPT_NAME'] ) . '";</script> 176 176 '; … … 182 182 * 183 183 * Overrides the theme's admin bar CSS to hide the adminbar if disabled. 184 * 184 * 185 185 * @package BuddyPress Core 186 186 */ 187 function bp_core_override_adminbar_css() { 187 function bp_core_override_adminbar_css() { 188 188 if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) ) { 189 189 ?> -
trunk/bp-core/bp-core-notifications.php
r1905 r2077 3 3 function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) { 4 4 global $bp; 5 5 6 6 if ( !$date_notified ) 7 7 $date_notified = time(); 8 8 9 9 $notification = new BP_Core_Notification; 10 10 $notification->item_id = $item_id; … … 17 17 if ( $secondary_item_id ) 18 18 $notification->secondary_item_id = $secondary_item_id; 19 19 20 20 if ( !$notification->save() ) 21 21 return false; 22 22 23 23 return true; 24 24 } … … 27 27 if ( !bp_core_check_notification_access( $bp->loggedin_user->id, $id ) ) 28 28 return false; 29 29 30 30 return BP_Core_Notification::delete( $id ); 31 31 } 32 32 33 33 function bp_core_get_notification( $id ) { 34 return new BP_Core_Notification( $id ); 34 return new BP_Core_Notification( $id ); 35 35 } 36 36 37 37 function bp_core_get_notifications_for_user( $user_id ) { 38 38 global $bp; 39 39 40 40 $notifications = BP_Core_Notification::get_all_for_user( $user_id ); 41 41 42 42 /* Group notifications by component and component_action and provide totals */ 43 43 for ( $i = 0; $i < count($notifications); $i++ ) { 44 44 $notification = $notifications[$i]; 45 45 46 46 $grouped_notifications[$notification->component_name][$notification->component_action][] = $notification; 47 47 } 48 48 49 49 if ( !$grouped_notifications ) 50 50 return false; 51 51 52 52 /* Calculated a renderable outcome for each notification type */ 53 53 foreach ( $grouped_notifications as $component_name => $action_arrays ) { 54 54 if ( !$action_arrays ) 55 55 continue; 56 56 57 57 foreach ( $action_arrays as $component_action_name => $component_action_items ) { 58 58 $action_item_count = count($component_action_items); 59 59 60 60 if ( $action_item_count < 1 ) 61 61 continue; … … 65 65 } 66 66 } 67 } 68 67 } 68 69 69 return $renderable; 70 70 } … … 89 89 if ( !BP_Core_Notification::check_access( $user_id, $notification_id ) ) 90 90 return false; 91 91 92 92 return true; 93 93 } -
trunk/bp-core/bp-core-settings.php
r2059 r2077 3 3 if ( !defined( 'BP_SETTINGS_SLUG' ) ) 4 4 define( 'BP_SETTINGS_SLUG', 'settings' ); 5 5 6 6 function bp_core_add_settings_nav() { 7 7 global $bp; 8 8 9 9 /* Set up settings as a sudo-component for identification and nav selection */ 10 10 $bp->settings->id = 'settings'; 11 11 $bp->settings->slug = BP_SETTINGS_SLUG; 12 12 13 13 /* Register this in the active components array */ 14 14 $bp->active_components[$bp->settings->slug] = $bp->settings->id; … … 18 18 19 19 $settings_link = $bp->loggedin_user->domain . 'settings/'; 20 20 21 21 bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_home() ) ); 22 22 bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_home() ) ); 23 23 24 24 if ( !is_site_admin() && !(int) get_site_option( 'bp-disable-account-deletion' ) ) 25 25 bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_home() ) ); … … 32 32 function bp_core_screen_general_settings() { 33 33 global $current_user, $bp_settings_updated, $pass_error; 34 34 35 35 $bp_settings_updated = false; 36 36 $pass_error = false; 37 37 38 38 if ( isset($_POST['submit']) ) { 39 39 check_admin_referer('bp_settings_general'); 40 40 41 41 require_once( WPINC . '/registration.php' ); 42 42 43 43 // Form has been submitted and nonce checks out, lets do it. 44 44 45 45 if ( $_POST['email'] != '' ) 46 46 $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) ); … … 56 56 unset( $current_user->user_pass ); 57 57 } 58 58 59 59 if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) ) 60 60 $bp_settings_updated = true; 61 61 } 62 62 63 63 add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' ); 64 64 add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' ); 65 65