Changeset 3790
- Timestamp:
- 01/21/2011 11:03:05 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r3617 r3790 19 19 global $bp; 20 20 21 if ( $id) {21 if ( !empty( $id ) ) { 22 22 $this->id = $id; 23 23 $this->populate(); … … 28 28 global $wpdb, $bp; 29 29 30 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ); 31 if ( $row ) { 32 $this->id = $row->id; 33 $this->item_id = $row->item_id; 30 if ( $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ) ) { 31 $this->id = $row->id; 32 $this->item_id = $row->item_id; 34 33 $this->secondary_item_id = $row->secondary_item_id; 35 $this->user_id = $row->user_id;36 $this->primary_link = $row->primary_link;37 $this->component = $row->component;38 $this->type = $row->type;39 $this->action = $row->action;40 $this->content = $row->content;41 $this->date_recorded = $row->date_recorded;42 $this->hide_sitewide = $row->hide_sitewide;43 $this->mptt_left = $row->mptt_left;44 $this->mptt_right = $row->mptt_right;34 $this->user_id = $row->user_id; 35 $this->primary_link = $row->primary_link; 36 $this->component = $row->component; 37 $this->type = $row->type; 38 $this->action = $row->action; 39 $this->content = $row->content; 40 $this->date_recorded = $row->date_recorded; 41 $this->hide_sitewide = $row->hide_sitewide; 42 $this->mptt_left = $row->mptt_left; 43 $this->mptt_right = $row->mptt_right; 45 44 } 46 45 } … … 51 50 do_action( 'bp_activity_before_save', &$this ); 52 51 53 $this->id = apply_filters( 'bp_activity_id_before_save', $this->id,&$this );54 $this->item_id = apply_filters( 'bp_activity_item_id_before_save', $this->item_id,&$this );52 $this->id = apply_filters( 'bp_activity_id_before_save', $this->id, &$this ); 53 $this->item_id = apply_filters( 'bp_activity_item_id_before_save', $this->item_id, &$this ); 55 54 $this->secondary_item_id = apply_filters( 'bp_activity_secondary_item_id_before_save', $this->secondary_item_id, &$this ); 56 $this->user_id = apply_filters( 'bp_activity_user_id_before_save', $this->user_id,&$this );57 $this->primary_link = apply_filters( 'bp_activity_primary_link_before_save', $this->primary_link,&$this );58 $this->component = apply_filters( 'bp_activity_component_before_save', $this->component,&$this );59 $this->type = apply_filters( 'bp_activity_type_before_save', $this->type,&$this );60 $this->action = apply_filters( 'bp_activity_action_before_save', $this->action,&$this );61 $this->content = apply_filters( 'bp_activity_content_before_save', $this->content,&$this );62 $this->date_recorded = apply_filters( 'bp_activity_date_recorded_before_save', $this->date_recorded,&$this );63 $this->hide_sitewide = apply_filters( 'bp_activity_hide_sitewide_before_save', $this->hide_sitewide,&$this );64 $this->mptt_left = apply_filters( 'bp_activity_mptt_left_before_save', $this->mptt_left,&$this );65 $this->mptt_right = apply_filters( 'bp_activity_mptt_right_before_save', $this->mptt_right,&$this );55 $this->user_id = apply_filters( 'bp_activity_user_id_before_save', $this->user_id, &$this ); 56 $this->primary_link = apply_filters( 'bp_activity_primary_link_before_save', $this->primary_link, &$this ); 57 $this->component = apply_filters( 'bp_activity_component_before_save', $this->component, &$this ); 58 $this->type = apply_filters( 'bp_activity_type_before_save', $this->type, &$this ); 59 $this->action = apply_filters( 'bp_activity_action_before_save', $this->action, &$this ); 60 $this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this ); 61 $this->date_recorded = apply_filters( 'bp_activity_date_recorded_before_save', $this->date_recorded, &$this ); 62 $this->hide_sitewide = apply_filters( 'bp_activity_hide_sitewide_before_save', $this->hide_sitewide, &$this ); 63 $this->mptt_left = apply_filters( 'bp_activity_mptt_left_before_save', $this->mptt_left, &$this ); 64 $this->mptt_right = apply_filters( 'bp_activity_mptt_right_before_save', $this->mptt_right, &$this ); 66 65 67 66 if ( !$this->component || !$this->type ) … … 129 128 } 130 129 131 // Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity 132 if ( !$display_comments || 'threaded' == $display_comments ) { 130 // Alter the query based on whether we want to show activity item 131 // comments in the stream like normal comments or threaded below 132 // the activity. 133 if ( !$display_comments || 'threaded' == $display_comments ) 133 134 $where_conditions[] = "a.type != 'activity_comment'"; 134 }135 135 136 136 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); … … 148 148 149 149 // Get the fullnames of users so we don't have to query in the loop 150 if ( bp_is_active( ' xprofile' ) && $activities ) {150 if ( bp_is_active( 'profile' ) && $activities ) { 151 151 foreach ( (array)$activities as $activity ) { 152 152 if ( (int)$activity->user_id ) … … 246 246 247 247 $defaults = array( 248 'id' => false,249 'action' => false,250 'content' => false,251 'component' => false,252 'type' => false,253 'primary_link' => false,254 'user_id' => false,255 'item_id' => false,248 'id' => false, 249 'action' => false, 250 'content' => false, 251 'component' => false, 252 'type' => false, 253 'primary_link' => false, 254 'user_id' => false, 255 'item_id' => false, 256 256 'secondary_item_id' => false, 257 'date_recorded' => false,258 'hide_sitewide' => false257 'date_recorded' => false, 258 'hide_sitewide' => false 259 259 ); 260 260 … … 299 299 return false; 300 300 301 / * Fetch the activity IDs so we can delete any comments for this activity item */301 // Fetch the activity IDs so we can delete any comments for this activity item 302 302 $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) ); 303 303 … … 360 360 361 361 if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) { 362 /* Select the user's fullname with the query so we don't have to fetch it for each comment */ 363 if ( bp_is_active( 'xprofile' ) ) { 362 // Select the user's fullname with the query so we don't have to 363 // fetch it for each comment 364 if ( bp_is_active( 'profile' ) ) { 364 365 $fullname_select = ", pd.value as user_fullname"; 365 366 $fullname_from = ", {$bp->profile->table_name_data} pd "; … … 367 368 } 368 369 369 / * Retrieve all descendants of the $root node */370 // Retrieve all descendants of the $root node 370 371 $descendants = $wpdb->get_results( apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right ) ); 371 372 372 / * Loop descendants and build an assoc array */373 // Loop descendants and build an assoc array 373 374 foreach ( (array)$descendants as $d ) { 374 375 376 / * If we have a reference on the parent */377 378 379 380 381 / * If we don't have a reference on the parent, put in the root level */382 383 384 385 375 $d->children = array(); 376 377 // If we have a reference on the parent 378 if ( isset( $ref[ $d->secondary_item_id ] ) ) { 379 $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d; 380 $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ]; 381 382 // If we don't have a reference on the parent, put in the root level 383 } else { 384 $comments[ $d->id ] = $d; 385 $ref[ $d->id ] =& $comments[ $d->id ]; 386 } 386 387 } 387 388 wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' ); … … 394 395 global $wpdb, $bp; 395 396 396 / * The right value of this node is the left value + 1 */397 // The right value of this node is the left value + 1 397 398 $right = $left + 1; 398 399 399 / * Get all descendants of this node */400 // Get all descendants of this node 400 401 $descendants = BP_Activity_Activity::get_child_comments( $parent_id ); 401 402 402 / * Loop the descendants and recalculate the left and right values */403 // Loop the descendants and recalculate the left and right values 403 404 foreach ( (array)$descendants as $descendant ) 404 405 $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right ); 405 406 406 /* We've got the left value, and now that we've processed the children of this node we also know the right value */ 407 // We've got the left value, and now that we've processed the children 408 // of this node we also know the right value 407 409 if ( 1 == $left ) 408 410 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) ); … … 410 412 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) ); 411 413 412 / * Return the right value of this node + 1 */414 // Return the right value of this node + 1 413 415 return $right + 1; 414 416 } -
trunk/bp-core/admin/bp-core-admin.php
r3777 r3790 101 101 foreach ( (array)$_POST['bp-admin'] as $key => $value ) { 102 102 103 if ( bp_is_active( ' xprofile' ) ) {103 if ( bp_is_active( 'profile' ) ) { 104 104 if ( 'bp-xprofile-base-group-name' == $key ) 105 105 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s WHERE id = 1", stripslashes( $value ) ) ); … … 130 130 <tbody> 131 131 132 <?php if ( bp_is_active( ' xprofile' ) ) : ?>132 <?php if ( bp_is_active( 'profile' ) ) : ?> 133 133 134 134 <tr> -
trunk/bp-core/bp-core-catchuri.php
r3780 r3790 289 289 global $bp; 290 290 291 if ( !bp_is_active( ' xprofile' ) )291 if ( !bp_is_active( 'profile' ) ) 292 292 bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) ); 293 293 } -
trunk/bp-core/bp-core-classes.php
r3778 r3790 56 56 */ 57 57 function populate() { 58 if ( bp_is_active( ' xprofile' ) )58 if ( bp_is_active( 'profile' ) ) 59 59 $this->profile_data = $this->get_profile_data(); 60 60 … … 125 125 $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID"; 126 126 127 if ( $search_terms && bp_is_active( ' xprofile' ) || 'alphabetical' == $type )127 if ( $search_terms && bp_is_active( 'profile' ) || 'alphabetical' == $type ) 128 128 $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; 129 129 … … 167 167 } 168 168 169 if ( $search_terms && bp_is_active( ' xprofile' ) ) {169 if ( $search_terms && bp_is_active( 'profile' ) ) { 170 170 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 171 171 $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'"; … … 348 348 349 349 /* Fetch the user's full name */ 350 if ( bp_is_active( ' xprofile' ) && 'alphabetical' != $type ) {350 if ( bp_is_active( 'profile' ) && 'alphabetical' != $type ) { 351 351 /* Ensure xprofile globals are set */ 352 352 if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) ) -
trunk/bp-core/bp-core-loader.php
r3767 r3790 110 110 * built in WordPress profile information 111 111 */ 112 if ( !bp_is_active( ' xprofile' ) ) {112 if ( !bp_is_active( 'profile' ) ) { 113 113 114 114 // Fallback values if xprofile is disabled -
trunk/bp-core/bp-core-template.php
r3778 r3790 351 351 */ 352 352 function bp_search_form_enabled() { 353 if ( bp_is_active( ' xprofile' )353 if ( bp_is_active( 'profile' ) 354 354 || bp_is_active( 'groups' ) 355 355 || ( bp_is_active( 'blogs' ) && is_multisite() ) … … 382 382 $options = array(); 383 383 384 if ( bp_is_active( ' xprofile' ) )384 if ( bp_is_active( 'profile' ) ) 385 385 $options['members'] = __( 'Members', 'buddypress' ); 386 386 … … 866 866 867 867 function bp_is_profile_component() { 868 if ( bp_is_current_component( ' xprofile' ) )868 if ( bp_is_current_component( 'profile' ) ) 869 869 return true; 870 870 … … 954 954 global $bp; 955 955 956 if ( bp_is_current_component( ' xprofile' ) )956 if ( bp_is_current_component( 'profile' ) ) 957 957 return true; 958 958 … … 963 963 global $bp; 964 964 965 if ( bp_is_current_component( ' xprofile' ) && 'edit' == $bp->current_action )965 if ( bp_is_current_component( 'profile' ) && 'edit' == $bp->current_action ) 966 966 return true; 967 967 … … 972 972 global $bp; 973 973 974 if ( bp_is_current_component( ' xprofile' ) && 'change-avatar' == $bp->current_action )974 if ( bp_is_current_component( 'profile' ) && 'change-avatar' == $bp->current_action ) 975 975 return true; 976 976 -
trunk/bp-forums/bp-forums-loader.php
r3778 r3790 432 432 433 433 // Fetch fullname for the topic's last poster 434 if ( bp_is_active( ' xprofile' ) ) {434 if ( bp_is_active( 'profile' ) ) { 435 435 $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) ); 436 436 for ( $i = 0; $i < count( $topics ); $i++ ) { … … 550 550 551 551 // Fetch fullname for each poster. 552 if ( bp_is_active( ' xprofile' ) ) {552 if ( bp_is_active( 'profile' ) ) { 553 553 $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) ); 554 554 for ( $i = 0; $i < count( $posts ); $i++ ) { -
trunk/bp-friends/bp-friends-classes.php
r3778 r3790 159 159 160 160 // filter the user_ids based on the search criteria. 161 if ( bp_is_active( ' xprofile' ) ) {161 if ( bp_is_active( 'profile' ) ) { 162 162 $sql = "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE user_id IN ($fids) AND value LIKE '$filter%%' {$pag_sql}"; 163 163 $total_sql = "SELECT COUNT(DISTINCT user_id) FROM {$bp->profile->table_name_data} WHERE user_id IN ($fids) AND value LIKE '$filter%%'"; … … 225 225 226 226 // filter the user_ids based on the search criteria. 227 if ( bp_is_active( ' xprofile' ) ) {227 if ( bp_is_active( 'profile' ) ) { 228 228 $sql = $wpdb->prepare( "SELECT DISTINCT d.user_id as id FROM {$bp->profile->table_name_data} d, $users_table u WHERE d.user_id = u.id AND d.value LIKE '$filter%%' ORDER BY d.value DESC $pag_sql" ); 229 229 } else { … … 248 248 249 249 // filter the user_ids based on the search criteria. 250 if ( bp_is_active( ' xprofile' ) ) {250 if ( bp_is_active( 'profile' ) ) { 251 251 $sql = $wpdb->prepare( "SELECT COUNT(DISTINCT d.user_id) FROM {$bp->profile->table_name_data} d, $users_table u WHERE d.user_id = u.id AND d.value LIKE '$filter%%'" ); 252 252 } else { … … 265 265 global $wpdb, $bp; 266 266 267 if ( !bp_is_active( ' xprofile' ) )267 if ( !bp_is_active( 'profile' ) ) 268 268 return false; 269 269 -
trunk/bp-groups/bp-groups-classes.php
r3778 r3790 1022 1022 $exclude_sql = $wpdb->prepare( " AND m.user_id NOT IN ({$exclude})" ); 1023 1023 1024 if ( bp_is_active( ' xprofile' ) )1024 if ( bp_is_active( 'profile' ) ) 1025 1025 $members = $wpdb->get_results( $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, pd.value as display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u, {$bp->profile->table_name_data} pd WHERE u.ID = m.user_id AND u.ID = pd.user_id AND pd.field_id = 1 AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ); 1026 1026 else -
trunk/bp-themes/bp-default/members/index.php
r3771 r3790 31 31 <option value="newest"><?php _e( 'Newest Registered', 'buddypress' ) ?></option> 32 32 33 <?php if ( bp_is_active( ' xprofile' ) ) : ?>33 <?php if ( bp_is_active( 'profile' ) ) : ?> 34 34 <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ) ?></option> 35 35 <?php endif; ?> -
trunk/bp-themes/bp-default/members/single/home.php
r3771 r3790 7 7 8 8 <div id="item-header" role="complementary"> 9 <?php locate_template( array( 'members/single/member-header.php' ), true ) ?> 9 10 <?php locate_template( array( 'members/single/member-header.php' ), true ); ?> 11 10 12 </div><!-- #item-header --> 11 13 … … 13 15 <div class="item-list-tabs no-ajax" id="object-nav" role="navigation"> 14 16 <ul> 17 15 18 <?php bp_get_displayed_user_nav() ?> 16 19 17 20 <?php do_action( 'bp_member_options_nav' ) ?> 21 18 22 </ul> 19 23 </div> … … 21 25 22 26 <div id="item-body"> 23 <?php do_action( 'bp_before_member_body' ) ?>27 <?php do_action( 'bp_before_member_body' ); ?> 24 28 25 29 <?php if ( bp_is_user_activity() || !bp_current_component() ) : ?> 26 <?php locate_template( array( 'members/single/activity.php' ), true ) ?>30 <?php locate_template( array( 'members/single/activity.php' ), true ); ?> 27 31 28 32 <?php elseif ( bp_is_user_blogs() ) : ?> 29 <?php locate_template( array( 'members/single/blogs.php' ), true ) ?>33 <?php locate_template( array( 'members/single/blogs.php' ), true ); ?> 30 34 31 35 <?php elseif ( bp_is_user_friends() ) : ?> 32 <?php locate_template( array( 'members/single/friends.php' ), true ) ?>36 <?php locate_template( array( 'members/single/friends.php' ), true ); ?> 33 37 34 38 <?php elseif ( bp_is_user_groups() ) : ?> 35 <?php locate_template( array( 'members/single/groups.php' ), true ) ?>39 <?php locate_template( array( 'members/single/groups.php' ), true ); ?> 36 40 37 41 <?php elseif ( bp_is_user_messages() ) : ?> 38 <?php locate_template( array( 'members/single/messages.php' ), true ) ?>42 <?php locate_template( array( 'members/single/messages.php' ), true ); ?> 39 43 40 44 <?php elseif ( bp_is_user_profile() ) : ?> 41 <?php locate_template( array( 'members/single/profile.php' ), true ) ?>45 <?php locate_template( array( 'members/single/profile.php' ), true ); ?> 42 46 43 47 <?php else : ?> 44 48 <?php 45 / * If nothing sticks, just load a member front template if one exists. */49 // If nothing sticks, load a generic template 46 50 locate_template( array( 'members/single/front.php' ), true ); 47 51 ?> 48 52 <?php endif; ?> 49 53 50 <?php do_action( 'bp_after_member_body' ) ?>54 <?php do_action( 'bp_after_member_body' ); ?> 51 55 52 56 </div><!-- #item-body --> 53 57 54 <?php do_action( 'bp_after_member_home_content' ) ?>58 <?php do_action( 'bp_after_member_home_content' ); ?> 55 59 56 60 </div><!-- .padder --> 57 61 </div><!-- #content --> 58 62 59 <?php get_sidebar() ?> 60 63 <?php get_sidebar(); ?> 61 64 <?php get_footer() ?> -
trunk/bp-themes/bp-default/members/single/profile/profile-loop.php
r3771 r3790 1 1 <?php do_action( 'bp_before_profile_loop_content' ) ?> 2 2 3 <?php if ( bp_is_active( ' xprofile' ) ) : ?>3 <?php if ( bp_is_active( 'profile' ) ) : ?> 4 4 5 5 <?php if ( bp_has_profile() ) : ?> -
trunk/bp-themes/bp-default/page-members.php
r3751 r3790 46 46 <option value="newest"><?php _e( 'Newest Registered', 'buddypress' ) ?></option> 47 47 48 <?php if ( bp_is_active( ' xprofile' ) ) : ?>48 <?php if ( bp_is_active( 'profile' ) ) : ?> 49 49 50 50 <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ) ?></option> -
trunk/bp-themes/bp-default/registration/register.php
r3771 r3790 48 48 <?php /***** Extra Profile Details ******/ ?> 49 49 50 <?php if ( bp_is_active( ' xprofile' ) ) : ?>50 <?php if ( bp_is_active( 'profile' ) ) : ?> 51 51 52 52 <?php do_action( 'bp_before_signup_profile_fields' ) ?> … … 57 57 58 58 <?php /* Use the profile field loop to render input fields for the 'base' profile field group */ ?> 59 <?php if ( bp_is_active( ' xprofile' ) ) : if ( bp_has_profile( 'profile_group_id=1' ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>59 <?php if ( bp_is_active( 'profile' ) ) : if ( bp_has_profile( 'profile_group_id=1' ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 60 60 61 61 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> -
trunk/bp-users/bp-users-functions.php
r3784 r3790 393 393 394 394 if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) { 395 if ( bp_is_active( ' xprofile' ) ) {395 if ( bp_is_active( 'profile' ) ) { 396 396 $fullname = xprofile_get_field_data( stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ), $user_id ); 397 397 -
trunk/bp-users/bp-users-template.php
r3778 r3790 403 403 global $members_template; 404 404 405 if ( !bp_is_active( ' xprofile' ) )405 if ( !bp_is_active( 'profile' ) ) 406 406 return false; 407 407 -
trunk/bp-xprofile/bp-xprofile-admin.php
r3643 r3790 1 1 <?php 2 2 3 /************************************************************************** 4 xprofile_admin() 5 6 Handles all actions for the admin area for creating, editing and deleting 7 profile groups and fields. 8 **************************************************************************/ 9 3 /** 4 * Creates the administration interface menus and checks to see if the DB 5 * tables are set up. 6 * 7 * @package BuddyPress XProfile 8 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 9 * @global $wpdb WordPress DB access object. 10 * @uses is_super_admin() returns true if the current user is a site admin, false if not 11 * @uses bp_xprofile_install() runs the installation of DB tables for the xprofile component 12 * @uses wp_enqueue_script() Adds a JS file to the JS queue ready for output 13 * @uses add_submenu_page() Adds a submenu tab to a top level tab in the admin area 14 * @uses xprofile_install() Runs the DB table installation function 15 * @return 16 */ 17 function xprofile_add_admin_menu() { 18 global $wpdb, $bp; 19 20 if ( !is_super_admin() ) 21 return false; 22 23 // Add the administration tab under the "Site Admin" tab for site administrators 24 add_submenu_page( 'bp-general-settings', __( 'Profile Field Setup', 'buddypress' ), __( 'Profile Field Setup', 'buddypress' ), 'manage_options', 'bp-profile-setup', 'xprofile_admin' ); 25 } 26 add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'xprofile_add_admin_menu' ); 27 28 /** 29 * Adds an admin bar menu to any profile page providing site admin options 30 * for that user. 31 * 32 * @package BuddyPress XProfile 33 * @global $bp BuddyPress 34 */ 35 function xprofile_setup_adminbar_menu() { 36 global $bp; 37 38 if ( !$bp->displayed_user->id ) 39 return false; 40 41 // Don't show this menu to non site admins or if you're viewing your own profile 42 if ( !is_super_admin() || bp_is_my_profile() ) 43 return false; ?> 44 45 <li id="bp-adminbar-adminoptions-menu"> 46 <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a> 47 48 <ul> 49 <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit/"><?php printf( __( "Edit %s's Profile", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> 50 <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> 51 52 <?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?> 53 54 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li> 55 56 <?php else : ?> 57 58 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Not a Spammer", 'buddypress' ) ?></a></li> 59 60 <?php endif; ?> 61 62 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/delete-user/', 'delete-user' ) ?>" class="confirm"><?php printf( __( "Delete %s", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> 63 64 <?php do_action( 'xprofile_adminbar_menu_items' ) ?> 65 66 </ul> 67 </li> 68 69 <?php 70 } 71 add_action( 'bp_adminbar_menus', 'xprofile_setup_adminbar_menu', 20 ); 72 73 /** 74 * Handles all actions for the admin area for creating, editing and deleting 75 * profile groups and fields. 76 */ 10 77 function xprofile_admin( $message = '', $type = 'error' ) { 11 78 global $bp; … … 44 111 <div class="icon32" id="icon-tools"><br></div> 45 112 <h2> 113 46 114 <?php _e( 'Profile Field Setup', 'buddypress'); ?> 115 47 116 <a id="add_group" class="button add-new-h2" href="admin.php?page=bp-profile-setup&mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a> 48 117 </h2> 118 49 119 <p><?php _e( 'Your users will distinguish themselves through their profile page. You must give them profile fields that allow them to describe themselves in a way that is relevant to the theme of your social network.', 'buddypress'); ?></p> 50 120 <p><?php echo sprintf( __( 'NOTE: Any fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( get_site_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p> 51 121 52 122 <form action="" id="profile-field-form" method="post"> 123 53 124 <?php wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); ?> 54 125 55 126 <?php wp_nonce_field( 'bp_reorder_groups', '_wpnonce_reorder_groups', false ); 56 127 57 if ( $message != '') :128 if ( !empty( $message ) ) : 58 129 $type = ( $type == 'error' ) ? 'error' : 'updated'; ?> 59 130 … … 61 132 <p><?php echo esc_html( esc_attr( $message ) ); ?></p> 62 133 </div> 134 63 135 <?php endif; ?> 64 136 … … 66 138 <ul id="field-group-tabs"> 67 139 <?php 68 if ( $groups) :140 if ( !empty( $groups ) ) : 69 141 foreach ( $groups as $group ) { ?> 142 70 143 <li id="group_<?php echo $group->id; ?>"><a href="#tabs-<?php echo $group->id; ?>" class="ui-tab"><?php echo esc_attr( $group->name ); ?><?php if ( !$group->can_delete ) : ?> <?php _e( '(Core)', 'buddypress'); endif; ?></a></li> 144 71 145 <?php } 72 146 endif; ?> 147 73 148 </ul> 74 149 75 <?php if ( $groups) :150 <?php if ( !empty( $groups ) ) : 76 151 foreach ( $groups as $group ) { ?> 152 77 153 <noscript> 78 <h3><?php echo esc_attr( $group->name ) ?></h3>154 <h3><?php echo esc_attr( $group->name ); ?></h3> 79 155 </noscript> 156 80 157 <div id="tabs-<?php echo $group->id; ?>" class="tab-wrapper"> 81 158 <div class="tab-toolbar"> … … 83 160 <a class="button" href="admin.php?page=bp-profile-setup&group_id=<?php echo esc_attr( $group->id ); ?>&mode=add_field"><?php _e( 'Add New Field', 'buddypress' ); ?></a> 84 161 <a class="button edit" href="admin.php?page=bp-profile-setup&mode=edit_group&group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Edit Group', 'buddypress' ); ?></a> 162 85 163 <?php if ( $group->can_delete ) : ?> 164 86 165 <a class="button delete" href="admin.php?page=bp-profile-setup&mode=delete_group&group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Delete Group', 'buddypress' ); ?></a> 166 87 167 <?php endif; ?> 168 88 169 </div> 89 170 </div> 90 171 91 172 <fieldset id="<?php echo $group->id; ?>" class="connectedSortable field-group"> 173 92 174 <?php if( $group->description ) : ?> 175 93 176 <legend><?php echo esc_attr( $group->description ) ?></legend> 177 94 178 <?php endif; 95 179 … … 97 181 foreach ( $group->fields as $field ) { 98 182 99 / * Load the field */183 // Load the field 100 184 $field = new BP_XProfile_Field( $field->id ); 101 185 … … 109 193 xprofile_admin_field( $field, $group, $class ); 110 194 111 } / * end for */112 113 else : / * !$group->fields */195 } // end for 196 197 else : // !$group->fields 114 198 ?> 115 199 116 200 <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p> 117 <?php 118 endif; /* end $group->fields */ 201 202 <?php 203 endif; // end $group->fields 119 204 ?> 205 120 206 </fieldset> 121 207 </div> 122 <?php 123 } /* End For */ ?> 208 209 <?php 210 } // End For ?> 211 124 212 </div> 125 213 <?php 126 214 else : 127 215 ?> 216 128 217 <div id="message" class="error"><p><?php _e( 'You have no groups.', 'buddypress' ); ?></p></div> 129 218 <p><a href="admin.php?page=bp-profile-setup&mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a></p> 219 130 220 <?php 131 221 endif; … … 155 245 if ( !$group->save() ) { 156 246 $message = __( 'There was an error saving the group. Please try again', 'buddypress' ); 157 $type = 'error';247 $type = 'error'; 158 248 } else { 159 249 $message = __( 'The group was saved successfully.', 'buddypress' ); 160 $type = 'success';250 $type = 'success'; 161 251 162 252 do_action( 'xprofile_groups_saved_group', $group ); … … 187 277 if ( !$group->delete() ) { 188 278 $message = __( 'There was an error deleting the group. Please try again', 'buddypress' ); 189 $type = 'error';279 $type = 'error'; 190 280 } else { 191 281 $message = __( 'The group was deleted successfully.', 'buddypress' ); 192 $type = 'success';282 $type = 'success'; 193 283 194 284 do_action( 'xprofile_groups_deleted_group', $group ); … … 214 304 if ( isset( $_POST['saveField'] ) ) { 215 305 if ( BP_XProfile_Field::admin_validate() ) { 216 $field->name = wp_filter_kses( $_POST['title'] );306 $field->name = wp_filter_kses( $_POST['title'] ); 217 307 $field->description = wp_filter_kses( $_POST['description'] ); 218 308 $field->is_required = wp_filter_kses( $_POST['required'] ); 219 $field->type = wp_filter_kses( $_POST['fieldtype'] ); 309 $field->type = wp_filter_kses( $_POST['fieldtype'] ); 310 220 311 if ( !empty( $_POST["sort_order_{$field->type}"] ) ) 221 312 $field->order_by = wp_filter_kses( $_POST["sort_order_{$field->type}"] ); 222 313 223 314 $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) ); 315 224 316 if ( !$field->field_order ) { 225 317 $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) ); … … 289 381 global $bp; 290 382 291 / * Check the nonce */383 // Check the nonce 292 384 check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); 293 385 … … 312 404 global $bp; 313 405 314 / * Check the nonce */406 // Check the nonce 315 407 check_admin_referer( 'bp_reorder_groups', '_wpnonce_reorder_groups' ); 316 408 … … 334 426 global $field; 335 427 336 $field = $admin_field; 337 ?> 428 $field = $admin_field; ?> 429 338 430 <fieldset id="field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( $class ) echo ' ' . $class; ?>"> 339 431 <legend><?php bp_the_profile_field_name(); ?> <?php if( !$field->can_delete ) : ?> <?php _e( '(Core)', 'buddypress' ); endif; ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ) ?><?php endif; ?></legend> 340 432 <div class="field-wrapper"> 433 341 434 <?php 342 435 switch ( $field->type ) { … … 344 437 345 438 <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="" /> 439 346 440 <?php break; case 'textarea' : ?> 347 441 348 442 <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"></textarea> 443 349 444 <?php break; case 'selectbox' : ?> 350 445 … … 368 463 369 464 <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a> 465 370 466 <?php endif; ?> 371 467 … … 401 497 402 498 </div> 499 403 500 <?php if ( $field->description ) : ?> 501 404 502 <p class="description"><?php echo esc_attr( $field->description ); ?></p> 503 405 504 <?php endif; ?> 505 406 506 </div> 407 507 </fieldset> -
trunk/bp-xprofile/bp-xprofile-loader.php
r3757 r3790 1 1 <?php 2 2 3 // Required files 4 require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-cssjs.php' ); 5 require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-admin.php' ); 6 require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-classes.php' ); 7 require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-filters.php' ); 8 require ( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-template.php' ); 3 /** 4 * BuddyPress XProfile Loader 5 * 6 * An extended profile component for users. This allows site admins to create 7 * groups of fields for users to enter information about themselves. 8 * 9 * @package BuddyPress 10 * @subpackage XProfile Core 11 */ 9 12 10 /** 11 * Add the profile globals to the $bp global for use across the installation 12 * 13 * @package BuddyPress XProfile 14 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 15 * @global $wpdb WordPress DB access object. 16 * @uses site_url() Returns the site URL 17 */ 18 function xprofile_setup_globals() { 19 global $bp, $wpdb; 13 class BP_XProfile_Component extends BP_Component { 20 14 21 if ( isset( $bp->profile->id ) ) 22 return; 15 /** 16 * Start the xprofile component creation process 17 * 18 * @since BuddyPress {unknown} 19 */ 20 function BP_XProfile_Component() { 21 parent::start( 'profile', __( 'Extended Profiles', 'buddypress' ) ); 22 } 23 23 24 if ( !defined( 'BP_XPROFILE_SLUG' ) ) 25 define ( 'BP_XPROFILE_SLUG', 'profile' ); 24 /** 25 * Setup globals 26 * 27 * The BP_XPROFILE_SLUG constant is deprecated, and only used here for 28 * backwards compatibility. 29 * 30 * @since BuddyPress {unknown} 31 * @global obj $bp 32 */ 33 function _setup_globals() { 34 global $bp; 26 35 27 // Assign the base group and fullname field names to constants to use 28 // in SQL statements 29 define ( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( $bp->site_options['bp-xprofile-base-group-name'] ) ); 30 define ( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ) ); 36 // Define a slug, if necessary 37 if ( !defined( 'BP_XPROFILE_SLUG' ) ) 38 define( 'BP_XPROFILE_SLUG', 'profile' ); 31 39 32 // For internal identification 33 $bp->profile->id = 'profile'; 40 // Assign the base group and fullname field names to constants to use 41 // in SQL statements 42 define ( 'BP_XPROFILE_BASE_GROUP_NAME', stripslashes( $bp->site_options['bp-xprofile-base-group-name'] ) ); 43 define ( 'BP_XPROFILE_FULLNAME_FIELD_NAME', stripslashes( $bp->site_options['bp-xprofile-fullname-field-name'] ) ); 34 44 35 // Slug 36 $bp->profile->slug = BP_XPROFILE_SLUG; 45 // Do some slug checks 46 $this->slug = BP_XPROFILE_SLUG; 47 $this->root_slug = isset( $bp->pages->xprofile->slug ) ? $bp->pages->xprofile->slug : $this->slug; 37 48 38 // Tables39 $bp->profile->table_name_data = $bp->table_prefix . 'bp_xprofile_data';40 $bp->profile->table_name_groups = $bp->table_prefix . 'bp_xprofile_groups';41 $bp->profile->table_name_fields = $bp->table_prefix . 'bp_xprofile_fields';42 $bp->profile->table_name_meta= $bp->table_prefix . 'bp_xprofile_meta';49 // Tables 50 $this->table_name_data = $bp->table_prefix . 'bp_xprofile_data'; 51 $this->table_name_groups = $bp->table_prefix . 'bp_xprofile_groups'; 52 $this->table_name_fields = $bp->table_prefix . 'bp_xprofile_fields'; 53 $this->table_name_meta = $bp->table_prefix . 'bp_xprofile_meta'; 43 54 44 // Notifications45 $bp->profile->notification_callback = 'xprofile_format_notifications';55 // Notifications 56 $this->notification_callback = 'xprofile_format_notifications'; 46 57 47 // Register this in the active components array48 $bp->active_components[$bp->profile->slug] = $bp->profile->id;58 // Register this in the active components array 59 $bp->active_components[$this->id] = $this->id; 49 60 50 // Set the support field type ids 51 $bp->profile->field_types = apply_filters( 'xprofile_field_types', array( 'textbox', 'textarea', 'radio', 'checkbox', 'selectbox', 'multiselectbox', 'datebox' ) ); 61 // Set the support field type ids 62 $this->field_types = apply_filters( 'xprofile_field_types', array( 63 'textbox', 64 'textarea', 65 'radio', 66 'checkbox', 67 'selectbox', 68 'multiselectbox', 69 'datebox' 70 ) ); 71 } 52 72 53 do_action( 'xprofile_setup_globals' ); 54 } 55 add_action( 'bp_setup_globals', 'xprofile_setup_globals' ); 73 /** 74 * Include files 75 */ 76 function _includes() { 77 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-cssjs.php' ); 78 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-admin.php' ); 79 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-actions.php' ); 80 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-screens.php' ); 81 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-classes.php' ); 82 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-filters.php' ); 83 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-template.php' ); 84 require_once( BP_PLUGIN_DIR . '/bp-xprofile/bp-xprofile-functions.php' ); 85 } 56 86 57 /** 58 * Creates the administration interface menus and checks to see if the DB 59 * tables are set up. 60 * 61 * @package BuddyPress XProfile 62 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 63 * @global $wpdb WordPress DB access object. 64 * @uses is_super_admin() returns true if the current user is a site admin, false if not 65 * @uses bp_xprofile_install() runs the installation of DB tables for the xprofile component 66 * @uses wp_enqueue_script() Adds a JS file to the JS queue ready for output 67 * @uses add_submenu_page() Adds a submenu tab to a top level tab in the admin area 68 * @uses xprofile_install() Runs the DB table installation function 69 * @return 70 */ 71 function xprofile_add_admin_menu() { 72 global $wpdb, $bp; 87 /** 88 * Setup BuddyBar navigation 89 * 90 * @global obj $bp 91 */ 92 function _setup_nav() { 93 global $bp; 73 94 74 if ( !is_super_admin() ) 75 return false; 95 // Add 'Profile' to the main navigation 96 bp_core_new_nav_item( array( 97 'name' => __( 'Profile', 'buddypress' ), 98 'slug' => $this->slug, 99 'position' => 20, 100 'screen_function' => 'xprofile_screen_display_profile', 101 'default_subnav_slug' => 'public', 102 'item_css_id' => $this->id 103 ) ); 76 104 77 // Add the administration tab under the "Site Admin" tab for site administrators 78 add_submenu_page( 'bp-general-settings', __( 'Profile Field Setup', 'buddypress' ), __( 'Profile Field Setup', 'buddypress' ), 'manage_options', 'bp-profile-setup', 'xprofile_admin' ); 79 } 80 add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'xprofile_add_admin_menu' ); 105 $profile_link = trailingslashit( $bp->loggedin_user->domain . $this->slug ); 81 106 82 /** 83 * Sets up the navigation items for the xprofile component 84 * 85 * @package BuddyPress XProfile 86 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 87 * @uses bp_core_new_nav_item() Adds a navigation item to the top level buddypress navigation 88 * @uses bp_core_new_subnav_item() Adds a sub navigation item to a nav item 89 * @uses bp_is_my_profile() Returns true if the current user being viewed is equal the logged in user 90 * @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed 91 */ 92 function xprofile_setup_nav() { 93 global $bp; 107 // Add the subnav items to the profile 108 bp_core_new_subnav_item( array( 109 'name' => __( 'Public', 'buddypress' ), 110 'slug' => 'public', 111 'parent_url' => $profile_link, 112 'parent_slug' => $this->slug, 113 'screen_function' => 'xprofile_screen_display_profile', 114 'position' => 10 115 ) ); 94 116 95 // Add 'Profile' to the main navigation 96 bp_core_new_nav_item( array( 'name' => __( 'Profile', 'buddypress' ), 'slug' => $bp->profile->slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $bp->profile->id ) ); 117 // Edit Profile 118 bp_core_new_subnav_item( array( 119 'name' => __( 'Edit Profile', 'buddypress' ), 120 'slug' => 'edit', 121 'parent_url' => $profile_link, 122 'parent_slug' => $this->slug, 123 'screen_function' => 'xprofile_screen_edit_profile', 124 'position' => 20 125 ) ); 97 126 98 $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . '/'; 127 // Change Avatar 128 bp_core_new_subnav_item( array( 129 'name' => __( 'Change Avatar', 'buddypress' ), 130 'slug' => 'change-avatar', 131 'parent_url' => $profile_link, 132 'parent_slug' => $this->slug, 133 'screen_function' => 'xprofile_screen_change_avatar', 134 'position' => 30 135 ) ); 99 136 100 // Add the subnav items to the profile 101 bp_core_new_subnav_item( array( 'name' => __( 'Public', 'buddypress' ), 'slug' => 'public', 'parent_url' => $profile_link, 'parent_slug' => $bp->profile->slug, 'screen_function' => 'xprofile_screen_display_profile', 'position' => 10 ) ); 102 bp_core_new_subnav_item( array( 'name' => __( 'Edit Profile', 'buddypress' ), 'slug' => 'edit', 'parent_url' => $profile_link, 'parent_slug' => $bp->profile->slug, 'screen_function' => 'xprofile_screen_edit_profile', 'position' => 20 ) ); 103 bp_core_new_subnav_item( array( 'name' => __( 'Change Avatar', 'buddypress' ), 'slug' => 'change-avatar', 'parent_url' => $profile_link, 'parent_slug' => $bp->profile->slug, 'screen_function' => 'xprofile_screen_change_avatar', 'position' => 30 ) ); 104 105 if ( $bp->current_component == $bp->profile->slug ) { 106 if ( bp_is_my_profile() ) { 107 $bp->bp_options_title = __( 'My Profile', 'buddypress' ); 108 } else { 109 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 110 $bp->bp_options_title = $bp->displayed_user->fullname; 137 if ( $bp->current_component == $this->id ) { 138 if ( bp_is_my_profile() ) { 139 $bp->bp_options_title = __( 'My Profile', 'buddypress' ); 140 } else { 141 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 142 'item_id' => $bp->displayed_user->id, 143 'type' => 'thumb' 144 ) ); 145 $bp->bp_options_title = $bp->displayed_user->fullname; 146 } 111 147 } 112 148 } 113 114 do_action( 'xprofile_setup_nav' );115 149 } 116 add_action( 'bp_setup_nav', 'xprofile_setup_nav' ); 117 118 /** 119 * Adds an admin bar menu to any profile page providing site admin options for that user. 120 * 121 * @package BuddyPress XProfile 122 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 123 */ 124 function xprofile_setup_adminbar_menu() { 125 global $bp; 126 127 if ( !$bp->displayed_user->id ) 128 return false; 129 130 // Don't show this menu to non site admins or if you're viewing your own profile 131 if ( !is_super_admin() || bp_is_my_profile() ) 132 return false; ?> 133 134 <li id="bp-adminbar-adminoptions-menu"> 135 <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a> 136 137 <ul> 138 <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit/"><?php printf( __( "Edit %s's Profile", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> 139 <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> 140 141 <?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?> 142 143 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li> 144 145 <?php else : ?> 146 147 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Not a Spammer", 'buddypress' ) ?></a></li> 148 149 <?php endif; ?> 150 151 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/delete-user/', 'delete-user' ) ?>" class="confirm"><?php printf( __( "Delete %s", 'buddypress' ), esc_attr( $bp->displayed_user->fullname ) ) ?></a></li> 152 153 <?php do_action( 'xprofile_adminbar_menu_items' ) ?> 154 155 </ul> 156 </li> 157 158 <?php 159 } 160 add_action( 'bp_adminbar_menus', 'xprofile_setup_adminbar_menu', 20 ); 161 162 /******************************************************************************** 163 * Screen Functions 164 * 165 * Screen functions are the controllers of BuddyPress. They will execute when their 166 * specific URL is caught. They will first save or manipulate data using business 167 * functions, then pass on the user to a template file. 168 */ 169 170 /** 171 * Handles the display of the profile page by loading the correct template file. 172 * 173 * @package BuddyPress Xprofile 174 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 175 */ 176 function xprofile_screen_display_profile() { 177 global $bp; 178 179 if ( isset( $_GET['new'] ) ) 180 $new = $_GET['new']; 181 else 182 $new = ''; 183 184 do_action( 'xprofile_screen_display_profile', $new ); 185 bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'members/single/home' ) ); 186 } 187 188 /** 189 * Handles the display of the profile edit page by loading the correct template file. 190 * Also checks to make sure this can only be accessed for the logged in users profile. 191 * 192 * @package BuddyPress Xprofile 193 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user 194 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 195 */ 196 function xprofile_screen_edit_profile() { 197 global $bp; 198 199 if ( !bp_is_my_profile() && !is_super_admin() ) 200 return false; 201 202 // Make sure a group is set. 203 if ( empty( $bp->action_variables[1] ) ) 204 bp_core_redirect( $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/1' ); 205 206 // Check the field group exists 207 if ( !xprofile_get_field_group( $bp->action_variables[1] ) ) 208 bp_core_redirect( $bp->root_domain ); 209 210 // Check to see if any new information has been submitted 211 if ( isset( $_POST['field_ids'] ) ) { 212 213 // Check the nonce 214 check_admin_referer( 'bp_xprofile_edit' ); 215 216 // Check we have field ID's 217 if ( empty( $_POST['field_ids'] ) ) 218 bp_core_redirect( $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/' . $bp->action_variables[1] . '/' ); 219 220 // Explode the posted field IDs into an array so we know which 221 // fields have been submitted 222 $posted_field_ids = explode( ',', $_POST['field_ids'] ); 223 224 $is_required = array(); 225 226 // Loop through the posted fields formatting any datebox values 227 // then validate the field 228 foreach ( (array)$posted_field_ids as $field_id ) { 229 if ( !isset( $_POST['field_' . $field_id] ) ) { 230 231 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && is_numeric( $_POST['field_' . $field_id . '_day'] ) ) { 232 // Concatenate the values 233 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . 234 $_POST['field_' . $field_id . '_month'] . ' ' . 235 $_POST['field_' . $field_id . '_year']; 236 237 // Turn the concatenated value into a timestamp 238 $_POST['field_' . $field_id] = strtotime( $date_value ); 239 } 240 241 } 242 243 $is_required[$field_id] = xprofile_check_is_required_field( $field_id ); 244 if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) 245 $errors = true; 246 } 247 248 if ( !empty( $errors ) ) 249 bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' ); 250 else { 251 // Reset the errors var 252 $errors = false; 253 254 // Now we've checked for required fields, lets save the values. 255 foreach ( (array)$posted_field_ids as $field_id ) { 256 257 // Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit. 258 if ( empty( $_POST['field_' . $field_id] ) ) 259 $value = array(); 260 else 261 $value = $_POST['field_' . $field_id]; 262 263 if ( !xprofile_set_field_data( $field_id, $bp->displayed_user->id, $value, $is_required[$field_id] ) ) 264 $errors = true; 265 else 266 do_action( 'xprofile_profile_field_data_updated', $field_id, $value ); 267 } 268 269 do_action( 'xprofile_updated_profile', $bp->displayed_user->id, $posted_field_ids, $errors ); 270 271 // Set the feedback messages 272 if ( $errors ) 273 bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' ); 274 else 275 bp_core_add_message( __( 'Changes saved.', 'buddypress' ) ); 276 277 // Redirect back to the edit screen to display the updates and message 278 bp_core_redirect( $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/' . $bp->action_variables[1] . '/' ); 279 } 280 } 281 282 do_action( 'xprofile_screen_edit_profile' ); 283 bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'members/single/home' ) ); 284 } 285 286 /** 287 * Handles the uploading and cropping of a user avatar. Displays the change avatar page. 288 * 289 * @package BuddyPress Xprofile 290 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user 291 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 292 */ 293 function xprofile_screen_change_avatar() { 294 global $bp; 295 296 if ( !bp_is_my_profile() && !is_super_admin() ) 297 return false; 298 299 $bp->avatar_admin->step = 'upload-image'; 300 301 if ( !empty( $_FILES ) ) { 302 303 // Check the nonce 304 check_admin_referer( 'bp_avatar_upload' ); 305 306 // Pass the file to the avatar upload handler 307 if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) { 308 $bp->avatar_admin->step = 'crop-image'; 309 310 // Make sure we include the jQuery jCrop file for image cropping 311 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 312 } 313 } 314 315 // If the image cropping is done, crop the image and save a full/thumb version 316 if ( isset( $_POST['avatar-crop-submit'] ) ) { 317 318 // Check the nonce 319 check_admin_referer( 'bp_avatar_cropstore' ); 320 321 if ( !bp_core_avatar_handle_crop( array( 'item_id' => $bp->displayed_user->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) ) 322 bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' ); 323 else { 324 bp_core_add_message( __( 'Your new avatar was uploaded successfully!', 'buddypress' ) ); 325 do_action( 'xprofile_avatar_uploaded' ); 326 } 327 } 328 329 do_action( 'xprofile_screen_change_avatar' ); 330 331 bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/home' ) ); 332 } 333 334 /******************************************************************************** 335 * Action Functions 336 * 337 * Action functions are exactly the same as screen functions, however they do not 338 * have a template screen associated with them. Usually they will send the user 339 * back to the default screen after execution. 340 */ 341 342 /** 343 * This function runs when an action is set for a screen: 344 * example.com/members/andy/profile/change-avatar/ [delete-avatar] 345 * 346 * The function will delete the active avatar for a user. 347 * 348 * @package BuddyPress Xprofile 349 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 350 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user. 351 * @uses add_action() Runs a specific function for an action when it fires. 352 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) 353 */ 354 function xprofile_action_delete_avatar() { 355 global $bp; 356 357 if ( $bp->profile->slug != $bp->current_component || 'change-avatar' != $bp->current_action || !isset( $bp->action_variables[0] ) || 'delete-avatar' != $bp->action_variables[0] ) 358 return false; 359 360 // Check the nonce 361 check_admin_referer( 'bp_delete_avatar_link' ); 362 363 if ( !bp_is_my_profile() && !is_super_admin() ) 364 return false; 365 366 if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->displayed_user->id ) ) ) 367 bp_core_add_message( __( 'Your avatar was deleted successfully!', 'buddypress' ) ); 368 else 369 bp_core_add_message( __( 'There was a problem deleting that avatar, please try again.', 'buddypress' ), 'error' ); 370 371 bp_core_redirect( wp_get_referer() ); 372 } 373 add_action( 'wp', 'xprofile_action_delete_avatar', 3 ); 374 375 /******************************************************************************** 376 * Activity & Notification Functions 377 * 378 * These functions handle the recording, deleting and formatting of activity and 379 * notifications for the user and for this specific component. 380 */ 381 382 function xprofile_register_activity_actions() { 383 global $bp; 384 385 if ( !function_exists( 'bp_activity_set_action' ) ) 386 return false; 387 388 // Register the activity stream actions for this component 389 bp_activity_set_action( $bp->profile->id, 'new_member', __( 'New member registered', 'buddypress' ) ); 390 bp_activity_set_action( $bp->profile->id, 'updated_profile', __( 'Updated Profile', 'buddypress' ) ); 391 392 do_action( 'xprofile_register_activity_actions' ); 393 } 394 add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' ); 395 396 /** 397 * Records activity for the logged in user within the profile component so that 398 * it will show in the users activity stream (if installed) 399 * 400 * @package BuddyPress XProfile 401 * @param $args Array containing all variables used after extract() call 402 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 403 * @uses bp_activity_record() Adds an entry to the activity component tables for a specific activity 404 */ 405 function xprofile_record_activity( $args = true ) { 406 global $bp; 407 408 if ( !function_exists( 'bp_activity_add' ) ) 409 return false; 410 411 $defaults = array ( 412 'user_id' => $bp->loggedin_user->id, 413 'action' => '', 414 'content' => '', 415 'primary_link' => '', 416 'component' => $bp->profile->id, 417 'type' => false, 418 'item_id' => false, 419 'secondary_item_id' => false, 420 'recorded_time' => bp_core_current_time(), 421 'hide_sitewide' => false 422 ); 423 424 $r = wp_parse_args( $args, $defaults ); 425 extract( $r, EXTR_SKIP ); 426 427 return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) ); 428 } 429 430 /** 431 * Deletes activity for a user within the profile component so that 432 * it will be removed from the users activity stream and sitewide stream (if installed) 433 * 434 * @package BuddyPress XProfile 435 * @param $args Array containing all variables used after extract() call 436 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 437 * @uses bp_activity_delete() Deletes an entry to the activity component tables for a specific activity 438 */ 439 function xprofile_delete_activity( $args = '' ) { 440 global $bp; 441 442 if ( function_exists('bp_activity_delete_by_item_id') ) { 443 extract( $args ); 444 bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component' => $bp->profile->id, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) ); 445 } 446 } 447 448 function xprofile_register_activity_action( $key, $value ) { 449 global $bp; 450 451 if ( !function_exists( 'bp_activity_set_action' ) ) 452 return false; 453 454 return apply_filters( 'xprofile_register_activity_action', bp_activity_set_action( $bp->profile->id, $key, $value ), $key, $value ); 455 } 456 457 458 /******************************************************************************** 459 * Business Functions 460 * 461 * Business functions are where all the magic happens in BuddyPress. They will 462 * handle the actual saving or manipulation of information. Usually they will 463 * hand off to a database class for data access, then return 464 * true or false on success or failure. 465 */ 466 467 /*** Field Group Management **************************************************/ 468 469 function xprofile_insert_field_group( $args = '' ) { 470 $defaults = array( 471 'field_group_id' => false, 472 'name' => false, 473 'description' => '', 474 'can_delete' => true 475 ); 476 477 $r = wp_parse_args( $args, $defaults ); 478 extract( $r, EXTR_SKIP ); 479 480 if ( !$name ) 481 return false; 482 483 $field_group = new BP_XProfile_Group( $field_group_id ); 484 $field_group->name = $name; 485 $field_group->description = $description; 486 $field_group->can_delete = $can_delete; 487 488 return $field_group->save(); 489 } 490 491 function xprofile_get_field_group( $field_group_id ) { 492 $field_group = new BP_XProfile_Group( $field_group_id ); 493 494 if ( empty( $field_group->id ) ) 495 return false; 496 497 return $field_group; 498 } 499 500 function xprofile_delete_field_group( $field_group_id ) { 501 $field_group = new BP_XProfile_Group( $field_group_id ); 502 return $field_group->delete(); 503 } 504 505 function xprofile_update_field_group_position( $field_group_id, $position ) { 506 return BP_XProfile_Group::update_position( $field_group_id, $position ); 507 } 508 509 510 /*** Field Management *********************************************************/ 511 512 function xprofile_insert_field( $args = '' ) { 513 global $bp; 514 515 extract( $args ); 516 517 /** 518 * Possible parameters (pass as assoc array): 519 * 'field_id' 520 * 'field_group_id' 521 * 'parent_id' 522 * 'type' 523 * 'name' 524 * 'description' 525 * 'is_required' 526 * 'can_delete' 527 * 'field_order' 528 * 'order_by' 529 * 'is_default_option' 530 * 'option_order' 531 */ 532 533 // Check we have the minimum details 534 if ( !$field_group_id ) 535 return false; 536 537 // Check this is a valid field type 538 if ( !in_array( $type, (array) $bp->profile->field_types ) ) 539 return false; 540 541 // Instantiate a new field object 542 if ( $field_id ) 543 $field = new BP_XProfile_Field( $field_id ); 544 else 545 $field = new BP_XProfile_Field; 546 547 $field->group_id = $field_group_id; 548 549 if ( !empty( $parent_id ) ) 550 $field->parent_id = $parent_id; 551 552 if ( !empty( $type ) ) 553 $field->type = $type; 554 555 if ( !empty( $name ) ) 556 $field->name = $name; 557 558 if ( !empty( $description ) ) 559 $field->description = $description; 560 561 if ( !empty( $is_required ) ) 562 $field->is_required = $is_required; 563 564 if ( !empty( $can_delete ) ) 565 $field->can_delete = $can_delete; 566 567 if ( !empty( $field_order ) ) 568 $field->field_order = $field_order; 569 570 if ( !empty( $order_by ) ) 571 $field->order_by = $order_by; 572 573 if ( !empty( $is_default_option ) ) 574 $field->is_default_option = $is_default_option; 575 576 if ( !empty( $option_order ) ) 577 $field->option_order = $option_order; 578 579 if ( !$field->save() ) 580 return false; 581 582 return true; 583 } 584 585 function xprofile_get_field( $field_id ) { 586 return new BP_XProfile_Field( $field_id ); 587 } 588 589 function xprofile_delete_field( $field_id ) { 590 $field = new BP_XProfile_Field( $field_id ); 591 return $field->delete(); 592 } 593 594 595 /*** Field Data Management *****************************************************/ 596 597 /** 598 * Fetches profile data for a specific field for the user. 599 * 600 * When the field value is serialized, this function unserializes and filters each item in the array 601 * that results. 602 * 603 * @package BuddyPress Core 604 * @param mixed $field The ID of the field, or the $name of the field. 605 * @param int $user_id The ID of the user 606 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 607 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed. 608 * @return mixed The profile field data. 609 */ 610 function xprofile_get_field_data( $field, $user_id = 0 ) { 611 global $bp; 612 613 // This is required because of a call to bp_core_get_user_displayname() in bp_core_setup_globals() 614 if ( !isset( $bp->profile->id ) ) 615 xprofile_setup_globals(); 616 617 if ( empty( $user_id ) ) 618 $user_id = $bp->displayed_user->id; 619 620 if ( empty( $user_id ) ) 621 return false; 622 623 if ( is_numeric( $field ) ) 624 $field_id = $field; 625 else 626 $field_id = xprofile_get_field_id_from_name( $field ); 627 628 if ( empty( $field_id ) ) 629 return false; 630 631 $values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) ); 632 633 if ( is_array( $values ) ) { 634 $data = array(); 635 foreach( (array)$values as $value ) { 636 $data[] = apply_filters( 'xprofile_get_field_data', $value ); 637 } 638 } else { 639 $data = apply_filters( 'xprofile_get_field_data', $values ); 640 } 641 642 return $data; 643 } 644 645 /** 646 * A simple function to set profile data for a specific field for a specific user. 647 * 648 * @package BuddyPress Core 649 * @param $field The ID of the field, or the $name of the field. 650 * @param $user_id The ID of the user 651 * @param $value The value for the field you want to set for the user. 652 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 653 * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name. 654 * @return true on success, false on failure. 655 */ 656 function xprofile_set_field_data( $field, $user_id, $value, $is_required = false ) { 657 if ( is_numeric( $field ) ) 658 $field_id = $field; 659 else 660 $field_id = xprofile_get_field_id_from_name( $field ); 661 662 if ( empty( $field_id ) ) 663 return false; 664 665 if ( $is_required && ( empty( $value ) || !is_array( $value ) && !strlen( trim( $value ) ) ) ) 666 return false; 667 668 $field = new BP_XProfile_Field( $field_id ); 669 670 // If the value is empty, then delete any field data that exists, unless the field is of a 671 // type where null values are semantically meaningful 672 if ( empty( $value ) && 'checkbox' != $field->type && 'multiselectbox' != $field->type ) { 673 xprofile_delete_field_data( $field_id, $user_id ); 674 return true; 675 } 676 677 // Check the value is an acceptable value 678 if ( 'checkbox' == $field->type || 'radio' == $field->type || 'selectbox' == $field->type || 'multiselectbox' == $field->type ) { 679 $options = $field->get_children(); 680 681 foreach( $options as $option ) 682 $possible_values[] = $option->name; 683 684 if ( is_array( $value ) ) { 685 foreach( $value as $i => $single ) { 686 if ( !in_array( $single, (array)$possible_values ) ) 687 unset( $value[$i] ); 688 } 689 690 // Reset the keys by merging with an empty array 691 $value = array_merge( array(), $value ); 692 } else { 693 if ( !in_array( $value, (array)$possible_values ) ) 694 return false; 695 } 696 } 697 698 $field = new BP_XProfile_ProfileData(); 699 $field->field_id = $field_id; 700 $field->user_id = $user_id; 701 $field->value = maybe_serialize( $value ); 702 703 return $field->save(); 704 } 705 706 function xprofile_delete_field_data( $field, $user_id ) { 707 if ( is_numeric( $field ) ) 708 $field_id = $field; 709 else 710 $field_id = xprofile_get_field_id_from_name( $field ); 711 712 if ( empty( $field_id ) || empty( $user_id ) ) 713 return false; 714 715 $field = new BP_XProfile_ProfileData( $field_id, $user_id ); 716 return $field->delete(); 717 } 718 719 function xprofile_check_is_required_field( $field_id ) { 720 $field = new BP_Xprofile_Field( $field_id ); 721 722 if ( (int)$field->is_required ) 723 return true; 724 725 return false; 726 } 727 728 /** 729 * Returns the ID for the field based on the field name. 730 * 731 * @package BuddyPress Core 732 * @param $field_name The name of the field to get the ID for. 733 * @return int $field_id on success, false on failure. 734 */ 735 function xprofile_get_field_id_from_name( $field_name ) { 736 return BP_Xprofile_Field::get_id_from_name( $field_name ); 737 } 738 739 /** 740 * Fetches a random piece of profile data for the user. 741 * 742 * @package BuddyPress Core 743 * @param $user_id User ID of the user to get random data for 744 * @param $exclude_fullname whether or not to exclude the full name field as random data. 745 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 746 * @global $wpdb WordPress DB access object. 747 * @global $current_user WordPress global variable containing current logged in user information 748 * @uses xprofile_format_profile_field() Formats profile field data so it is suitable for display. 749 * @return $field_data The fetched random data for the user. 750 */ 751 function xprofile_get_random_profile_data( $user_id, $exclude_fullname = true ) { 752 $field_data = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname ); 753 $field_data[0]->value = xprofile_format_profile_field( $field_data[0]->type, $field_data[0]->value ); 754 755 if ( !$field_data[0]->value || empty( $field_data[0]->value ) ) 756 return false; 757 758 return apply_filters( 'xprofile_get_random_profile_data', $field_data ); 759 } 760 761 /** 762 * Formats a profile field according to its type. [ TODO: Should really be moved to filters ] 763 * 764 * @package BuddyPress Core 765 * @param $field_type The type of field: datebox, selectbox, textbox etc 766 * @param $field_value The actual value 767 * @uses bp_format_time() Formats a time value based on the WordPress date format setting 768 * @return $field_value The formatted value 769 */ 770 function xprofile_format_profile_field( $field_type, $field_value ) { 771 if ( !isset( $field_value ) || empty( $field_value ) ) 772 return false; 773 774 $field_value = bp_unserialize_profile_field( $field_value ); 775 776 if ( 'datebox' == $field_type ) { 777 $field_value = bp_format_time( $field_value, true ); 778 } else { 779 $content = $field_value; 780 $field_value = str_replace( ']]>', ']]>', $content ); 781 } 782 783 return stripslashes_deep( $field_value ); 784 } 785 786 function xprofile_update_field_position( $field_id, $position, $field_group_id ) { 787 return BP_XProfile_Field::update_position( $field_id, $position, $field_group_id ); 788 } 789 790 /** 791 * Setup the avatar upload directory for a user. 792 * 793 * @package BuddyPress Core 794 * @param $directory The root directory name 795 * @param $user_id The user ID. 796 * @return array() containing the path and URL plus some other settings. 797 */ 798 function xprofile_avatar_upload_dir( $directory = false, $user_id = 0 ) { 799 global $bp; 800 801 if ( empty( $user_id ) ) 802 $user_id = $bp->displayed_user->id; 803 804 if ( empty( $directory ) ) 805 $directory = 'avatars'; 806 807 $path = BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id; 808 $newbdir = $path; 809 810 if ( !file_exists( $path ) ) 811 @wp_mkdir_p( $path ); 812 813 $newurl = BP_AVATAR_URL . '/avatars/' . $user_id; 814 $newburl = $newurl; 815 $newsubdir = '/avatars/' . $user_id; 816 817 return apply_filters( 'xprofile_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) ); 818 } 819 820 /** 821 * Syncs Xprofile data to the standard built in WordPress profile data. 822 * 823 * @package BuddyPress Core 824 */ 825 function xprofile_sync_wp_profile( $user_id = 0 ) { 826 global $bp, $wpdb; 827 828 if ( !empty( $bp->site_options['bp-disable-profile-sync'] ) && (int)$bp->site_options['bp-disable-profile-sync'] ) 829 return true; 830 831 if ( empty( $user_id ) ) 832 $user_id = $bp->loggedin_user->id; 833 834 if ( empty( $user_id ) ) 835 return false; 836 837 $fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id ); 838 $space = strpos( $fullname, ' ' ); 839 840 if ( false === $space ) { 841 $firstname = $fullname; 842 $lastname = ''; 843 } else { 844 $firstname = substr( $fullname, 0, $space ); 845 $lastname = trim( substr( $fullname, $space, strlen( $fullname ) ) ); 846 } 847 848 update_user_meta( $user_id, 'nickname', $fullname ); 849 update_user_meta( $user_id, 'first_name', $firstname ); 850 update_user_meta( $user_id, 'last_name', $lastname ); 851 852 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id ) ); 853 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain( $user_id ), $user_id ) ); 854 } 855 add_action( 'xprofile_updated_profile', 'xprofile_sync_wp_profile' ); 856 add_action( 'bp_core_signup_user', 'xprofile_sync_wp_profile' ); 857 858 859 /** 860 * Syncs the standard built in WordPress profile data to XProfile. 861 * 862 * @since 1.2.4 863 * @package BuddyPress Core 864 */ 865 function xprofile_sync_bp_profile( &$errors, $update, &$user ) { 866 global $bp; 867 868 if ( ( !empty( $bp->site_options['bp-disable-profile-sync'] ) && (int)$bp->site_options['bp-disable-profile-sync'] ) || !$update || $errors->get_error_codes() ) 869 return; 870 871 xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user->ID, $user->display_name ); 872 } 873 add_action( 'user_profile_update_errors', 'xprofile_sync_bp_profile', 10, 3 ); 874 875 876 /** 877 * When a user is deleted, we need to clean up the database and remove all the 878 * profile data from each table. Also we need to clean anything up in the usermeta table 879 * that this component uses. 880 * 881 * @package BuddyPress XProfile 882 * @param $user_id The ID of the deleted user 883 * @uses get_user_meta() Get a user meta value based on meta key from wp_usermeta 884 * @uses delete_user_meta() Delete user meta value based on meta key from wp_usermeta 885 * @uses delete_data_for_user() Removes all profile data from the xprofile tables for the user 886 */ 887 function xprofile_remove_data( $user_id ) { 888 BP_XProfile_ProfileData::delete_data_for_user( $user_id ); 889 890 // delete any avatar files. 891 @unlink( get_user_meta( $user_id, 'bp_core_avatar_v1_path', true ) ); 892 @unlink( get_user_meta( $user_id, 'bp_core_avatar_v2_path', true ) ); 893 894 // unset the usermeta for avatars from the usermeta table. 895 delete_user_meta( $user_id, 'bp_core_avatar_v1' ); 896 delete_user_meta( $user_id, 'bp_core_avatar_v1_path' ); 897 delete_user_meta( $user_id, 'bp_core_avatar_v2' ); 898 delete_user_meta( $user_id, 'bp_core_avatar_v2_path' ); 899 } 900 add_action( 'wpmu_delete_user', 'xprofile_remove_data' ); 901 add_action( 'delete_user', 'xprofile_remove_data' ); 902 add_action( 'bp_make_spam_user', 'xprofile_remove_data' ); 903 904 /*** XProfile Meta ****************************************************/ 905 906 function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false ) { 907 global $wpdb, $bp; 908 909 $object_id = (int) $object_id; 910 911 if ( !$object_id ) 912 return false; 913 914 if ( !isset( $object_type ) ) 915 return false; 916 917 if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) ) 918 return false; 919 920 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 921 922 if ( is_array( $meta_value ) || is_object( $meta_value ) ) 923 $meta_value = serialize( $meta_value ); 924 925 $meta_value = trim( $meta_value ); 926 927 if ( !$meta_key ) 928 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s", $object_id, $object_type ) ); 929 else if ( $meta_value ) 930 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s AND meta_key = %s AND meta_value = %s", $object_id, $object_type, $meta_key, $meta_value ) ); 931 else 932 $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key ) ); 933 934 // Delete the cached object 935 wp_cache_delete( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp' ); 936 937 return true; 938 } 939 940 function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '') { 941 global $wpdb, $bp; 942 943 $object_id = (int) $object_id; 944 945 if ( !$object_id ) 946 return false; 947 948 if ( !isset( $object_type ) ) 949 return false; 950 951 if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) ) 952 return false; 953 954 if ( !empty( $meta_key ) ) { 955 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 956 957 if ( !$metas = wp_cache_get( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp' ) ) { 958 $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key ) ); 959 wp_cache_set( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $metas, 'bp' ); 960 } 961 } else { 962 $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s", $object_id, $object_type ) ); 963 } 964 965 if ( empty( $metas ) ) { 966 if ( empty( $meta_key ) ) { 967 return array(); 968 } else { 969 return ''; 970 } 971 } 972 973 $metas = array_map( 'maybe_unserialize', (array)$metas ); 974 975 if ( 1 == count( $metas ) ) 976 return $metas[0]; 977 else 978 return $metas; 979 } 980 981 function bp_xprofile_update_meta( $object_id, $object_type, $meta_key, $meta_value ) { 982 global $wpdb, $bp; 983 984 $object_id = (int) $object_id; 985 986 if ( !$object_id ) 987 return false; 988 989 if ( !isset( $object_type ) ) 990 return false; 991 992 if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) ) 993 return false; 994 995 $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key ); 996 997 if ( is_string( $meta_value ) ) 998 $meta_value = stripslashes( $wpdb->escape( $meta_value ) ); 999 1000 $meta_value = maybe_serialize( $meta_value ); 1001 1002 if ( empty( $meta_value ) ) 1003 return bp_xprofile_delete_meta( $object_id, $object_type, $meta_key ); 1004 1005 $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key ) ); 1006 1007 if ( !$cur ) 1008 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->profile->table_name_meta . " ( object_id, object_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )", $object_id, $object_type, $meta_key, $meta_value ) ); 1009 else if ( $cur->meta_value != $meta_value ) 1010 $wpdb->query( $wpdb->prepare( "UPDATE " . $bp->profile->table_name_meta . " SET meta_value = %s WHERE object_id = %d AND object_type = %s AND meta_key = %s", $meta_value, $object_id, $object_type, $meta_key ) ); 1011 else 1012 return false; 1013 1014 // Update the cached object and recache 1015 wp_cache_set( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $meta_value, 'bp' ); 1016 1017 return true; 1018 } 1019 1020 function bp_xprofile_update_fieldgroup_meta( $field_group_id, $meta_key, $meta_value ) { 1021 return bp_xprofile_update_meta( $field_group_id, 'group', $meta_key, $meta_value ); 1022 } 1023 1024 function bp_xprofile_update_field_meta( $field_id, $meta_key, $meta_value ) { 1025 return bp_xprofile_update_meta( $field_id, 'field', $meta_key, $meta_value ); 1026 } 1027 1028 function bp_xprofile_update_fielddata_meta( $field_data_id, $meta_key, $meta_value ) { 1029 return bp_xprofile_update_meta( $field_data_id, 'data', $meta_key, $meta_value ); 1030 } 1031 1032 /******************************************************************************** 1033 * Caching 1034 * 1035 * Caching functions handle the clearing of cached objects and pages on specific 1036 * actions throughout BuddyPress. 1037 */ 1038 1039 function xprofile_clear_profile_groups_object_cache( $group_obj ) { 1040 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' ); 1041 wp_cache_delete( 'xprofile_group_' . $group_obj->id ); 1042 } 1043 1044 function xprofile_clear_profile_data_object_cache( $group_id ) { 1045 global $bp; 1046 wp_cache_delete( 'bp_user_fullname_' . $bp->loggedin_user->id, 'bp' ); 1047 } 1048 1049 // List actions to clear object caches on 1050 add_action( 'xprofile_groups_deleted_group', 'xprofile_clear_profile_groups_object_cache' ); 1051 add_action( 'xprofile_groups_saved_group', 'xprofile_clear_profile_groups_object_cache' ); 1052 add_action( 'xprofile_updated_profile', 'xprofile_clear_profile_data_object_cache' ); 1053 1054 // List actions to clear super cached pages on, if super cache is installed 1055 add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' ); 150 // Create the xprofile component 151 if ( !isset( $bp->profile->id ) ) 152 $bp->profile = new BP_XProfile_Component(); 1056 153 1057 154 ?> -
trunk/bp-xprofile/bp-xprofile-template.php
r3757 r3790 739 739 bp_button( array ( 740 740 'id' => 'edit_profile', 741 'component' => ' xprofile',741 'component' => 'profile', 742 742 'must_be_logged_in' => true, 743 743 'block_self' => true,
Note: See TracChangeset
for help on using the changeset viewer.