Skip to:
Content

BuddyPress.org

Changeset 2077 for trunk/bp-xprofile.php


Ignore:
Timestamp:
11/02/2009 07:54:21 PM (17 years ago)
Author:
apeatling
Message:

Merging 1.1 branch changes and syncing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile.php

    r2059 r2077  
    1515/* Include deprecated functions if settings allow */
    1616if ( !defined( 'BP_IGNORE_DEPRECATED' ) )
    17         require ( BP_PLUGIN_DIR . '/bp-xprofile/deprecated/bp-xprofile-deprecated.php' );       
     17        require ( BP_PLUGIN_DIR . '/bp-xprofile/deprecated/bp-xprofile-deprecated.php' );
    1818
    1919/* Assign the base group and fullname field names to constants to use in SQL statements */
    … …  
    2525 *
    2626 * Set up the database tables needed for the xprofile component.
    27  * 
     27 *
    2828 * @package BuddyPress XProfile
    2929 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    3636        if ( !empty($wpdb->charset) )
    3737                $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
    38        
     38
    3939        if ( '' == get_site_option( 'bp-xprofile-base-group-name' ) )
    4040                update_site_option( 'bp-xprofile-base-group-name', 'Base' );
    41        
     41
    4242        if ( '' == get_site_option( 'bp-xprofile-fullname-field-name' ) )
    43                 update_site_option( 'bp-xprofile-fullname-field-name', 'Name' );       
    44        
     43                update_site_option( 'bp-xprofile-fullname-field-name', 'Name' );
     44
    4545        $sql[] = "CREATE TABLE {$bp->profile->table_name_groups} (
    4646                          id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    … …  
    5050                          KEY can_delete (can_delete)
    5151        ) {$charset_collate};";
    52        
     52
    5353        $sql[] = "CREATE TABLE {$bp->profile->table_name_fields} (
    5454                          id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    … …  
    7070                          KEY is_required (is_required)
    7171        ) {$charset_collate};";
    72        
     72
    7373        $sql[] = "CREATE TABLE {$bp->profile->table_name_data} (
    7474                          id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    … …  
    8080                          KEY user_id (user_id)
    8181        ) {$charset_collate};";
    82        
     82
    8383        if ( '' == get_site_option( 'bp-xprofile-db-version' ) ) {
    8484                $sql[] = "INSERT INTO {$bp->profile->table_name_groups} VALUES ( 1, '" . get_site_option( 'bp-xprofile-base-group-name' ) . "', '', 0 );";
    85        
    86                 $sql[] = "INSERT INTO {$bp->profile->table_name_fields} ( 
     85
     86                $sql[] = "INSERT INTO {$bp->profile->table_name_fields} (
    8787                                        id, group_id, parent_id, type, name, is_required, can_delete
    8888                                  ) VALUES (
    … …  
    9090                                  );";
    9191        }
    92        
     92
    9393        require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
    9494        dbDelta($sql);
    95        
     95
    9696        if ( function_exists('bp_wire_install') )
    9797                xprofile_wire_install();
    98        
     98
    9999        update_site_option( 'bp-xprofile-db-version', BP_XPROFILE_DB_VERSION );
    100100}
    … …  
    124124 *
    125125 * Add the profile globals to the $bp global for use across the installation
    126  * 
     126 *
    127127 * @package BuddyPress XProfile
    128128 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    132132function xprofile_setup_globals() {
    133133        global $bp, $wpdb;
    134        
     134
    135135        /* For internal identification */
    136136        $bp->profile->id = 'profile';
    137                
     137
    138138        $bp->profile->table_name_groups = $wpdb->base_prefix . 'bp_xprofile_groups';
    139139        $bp->profile->table_name_fields = $wpdb->base_prefix . 'bp_xprofile_fields';
    … …  
    145145        /* Register this in the active components array */
    146146        $bp->active_components[$bp->profile->slug] = $bp->profile->id;
    147        
     147
    148148        /* Set the support field type ids */
    149149        $bp->profile->field_types = apply_filters( 'xprofile_field_types', array( 'textbox', 'textarea', 'radio', 'checkbox', 'selectbox', 'multiselectbox', 'datebox' ) );
    … …  
    151151        if ( function_exists( 'bp_wire_install' ) )
    152152                $bp->profile->table_name_wire = $wpdb->base_prefix . 'bp_xprofile_wire';
    153        
     153
    154154        do_action( 'xprofile_setup_globals' );
    155155}
    … …  
    162162 * Creates the administration interface menus and checks to see if the DB
    163163 * tables are set up.
    164  * 
     164 *
    165165 * @package BuddyPress XProfile
    166166 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    171171 * @uses add_submenu_page() Adds a submenu tab to a top level tab in the admin area
    172172 * @uses xprofile_install() Runs the DB table installation function
    173  * @return 
     173 * @return
    174174 */
    175175function xprofile_add_admin_menu() {
    176176        global $wpdb, $bp;
    177        
     177
    178178        if ( !is_site_admin() )
    179179                return false;
    180                        
     180
    181181        /* Add the administration tab under the "Site Admin" tab for site administrators */
    182182        add_submenu_page( 'bp-general-settings', __("Profile Field Setup", 'buddypress'), __("Profile Field Setup", 'buddypress'), 'manage-options', 'bp-profile-setup', "xprofile_admin" );
    … …  
    192192 *
    193193 * Sets up the navigation items for the xprofile component
    194  * 
     194 *
    195195 * @package BuddyPress XProfile
    196196 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    203203function xprofile_setup_nav() {
    204204        global $bp;
    205        
     205
    206206        /* Add 'Profile' to the main navigation */
    207207        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 ) );
    208208
    209209        $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . '/';
    210        
     210
    211211        /* Add the subnav items to the profile */
    212212        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 ) );
    … …  
    219219                } else {
    220220                        $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    221                         $bp->bp_options_title = $bp->displayed_user->fullname; 
     221                        $bp->bp_options_title = $bp->displayed_user->fullname;
    222222                }
    223223        }
    224        
     224
    225225        do_action( 'xprofile_setup_nav' );
    226226}
    … …  
    233233 *
    234234 * Adds an admin bar menu to any profile page providing site admin options for that user.
    235  * 
     235 *
    236236 * @package BuddyPress XProfile
    237237 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    239239function xprofile_setup_adminbar_menu() {
    240240        global $bp;
    241        
     241
    242242        if ( !$bp->displayed_user->id )
    243243                return false;
    244        
     244
    245245        /* Don't show this menu to non site admins or if you're viewing your own profile */
    246246        if ( !is_site_admin() || bp_is_home() )
    … …  
    249249        <li id="bp-adminbar-adminoptions-menu">
    250250                <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a>
    251                
     251
    252252                <ul>
    253253                        <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit/"><?php printf( __( "Edit %s's Profile", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    254254                        <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    255                        
     255
    256256                        <?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?>
    257257                                <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>
    … …  
    259259                                <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>
    260260                        <?php endif; ?>
    261                        
     261
    262262                        <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/delete-user/', 'delete-user' ) ?>" class="confirm"><?php printf( __( "Delete %s", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li>
    263                        
     263
    264264                        <?php do_action( 'xprofile_adminbar_menu_items' ) ?>
    265265                </ul>
    … …  
    281281 *
    282282 * Handles the display of the profile page by loading the correct template file.
    283  * 
     283 *
    284284 * @package BuddyPress Xprofile
    285285 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
    … …  
    292292        if ( isset($_GET['new']) )
    293293                bp_core_delete_notifications_for_user_by_item_id( $bp->loggedin_user->id, $bp->displayed_user->id, 'friends', 'friendship_accepted' );
    294        
     294
    295295        do_action( 'xprofile_screen_display_profile', $_GET['new'] );
    296296        bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'profile/index' ) );
    … …  
    302302 * Handles the display of the profile edit page by loading the correct template file.
    303303 * Also checks to make sure this can only be accessed for the logged in users profile.
    304  * 
     304 *
    305305 * @package BuddyPress Xprofile
    306306 * @uses bp_is_home() Checks to make sure the current user being viewed equals the logged in user
    … …  
    309309function xprofile_screen_edit_profile() {
    310310        global $bp;
    311        
     311
    312312        if ( !bp_is_home() && !is_site_admin() )
    313313                return false;
    314        
     314
    315315        /* Check to see if any new information has been submitted */
    316316        if ( isset($_POST['field_ids']) ) {
    317                
     317
    318318                /* Check the nonce */
    319319                check_admin_referer( 'bp_xprofile_edit' );
    320                
     320
    321321                /* Check we have field ID's */
    322322                if ( empty( $_POST['field_ids'] ) )
    323323                        bp_core_redirect( $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/' . $bp->action_variables[1] . '/' );
    324                
     324
    325325                /* Explode the posted field IDs into an array so we know which fields have been submitted */
    326326                $posted_field_ids = explode( ',', $_POST['field_ids'] );
    327                                
     327
    328328                /* Loop through the posted fields formatting any datebox values then validate the field */
    329                 foreach ( $posted_field_ids as $field_id ) {           
    330 
     329                foreach ( $posted_field_ids as $field_id ) {
    331330                        if ( !isset( $_POST['field_' . $field_id] ) ) {
    332331
    333332                                if ( is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
    334333                                        /* Concatenate the values. */
    335                                         $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . 
     334                                        $date_value = $_POST['field_' . $field_id . '_day'] . ' ' .
    336335                                                              $_POST['field_' . $field_id . '_month'] . ' ' .
    337336                                                                  $_POST['field_' . $field_id . '_year'];
    … …  
    348347
    349348                if ( $errors )
    350                         bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );                     
    351                 else {         
     349                        bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );
     350                else {
    352351                        /* Reset the errors var */
    353352                        $errors = false;
    354                
     353
    355354                        /* Now we've checked for required fields, lets save the values. */
    356                         foreach ( $posted_field_ids as $field_id ) {           
     355                        foreach ( $posted_field_ids as $field_id ) {
    357356                                if ( !xprofile_set_field_data( $field_id, $bp->displayed_user->id, $_POST['field_' . $field_id] ) )
    358357                                        $errors = true;
    … …  
    360359                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $_POST['field_' . $field_id] );
    361360                        }
    362                                
     361
    363362                        do_action( 'xprofile_updated_profile', $posted_field_ids, $errors );
    364                
     363
    365364                        /* Set the feedback messages */
    366365                        if ( $errors )
    367366                                bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' );
    368                         else 
     367                        else
    369368                                bp_core_add_message( __( 'Changes saved.', 'buddypress' ) );
    370369
    … …  
    375374
    376375        do_action( 'xprofile_screen_edit_profile' );
    377         bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'profile/edit' ) );                     
     376        bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'profile/edit' ) );
    378377}
    379378
    … …  
    382381 *
    383382 * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
    384  * 
     383 *
    385384 * @package BuddyPress Xprofile
    386385 * @uses bp_is_home() Checks to make sure the current user being viewed equals the logged in user
    … …  
    389388function xprofile_screen_change_avatar() {
    390389        global $bp;
    391        
     390
    392391        if ( !bp_is_home() && !is_site_admin() )
    393392                return false;
    394        
     393
    395394        $bp->avatar_admin->step = 'upload-image';
    396        
     395
    397396        if ( !empty( $_FILES ) ) {
    398                
     397
    399398                /* Check the nonce */
    400399                check_admin_referer( 'bp_avatar_upload' );
    401400
    402                 /* Pass the file to the avatar upload handler */               
    403                 if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {         
     401                /* Pass the file to the avatar upload handler */
     402                if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {
    404403                        $bp->avatar_admin->step = 'crop-image';
    405404
    … …  
    408407                }
    409408        }
    410        
     409
    411410        /* If the image cropping is done, crop the image and save a full/thumb version */
    412411        if ( isset( $_POST['avatar-crop-submit'] ) ) {
    413                
     412
    414413                /* Check the nonce */
    415414                check_admin_referer( 'bp_avatar_cropstore' );
    … …  
    424423
    425424        do_action( 'xprofile_screen_change_avatar' );
    426        
     425
    427426        bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'profile/change-avatar' ) );
    428427}
    … …  
    434433 * Settings are hooked into the function: bp_core_screen_notification_settings_content()
    435434 * in bp-core/bp-core-settings.php
    436  * 
     435 *
    437436 * @package BuddyPress Xprofile
    438437 * @global $current_user WordPress global variable containing current logged in user information
    439438 */
    440 function xprofile_screen_notification_settings() { 
     439function xprofile_screen_notification_settings() {
    441440        global $current_user; ?>
    442441        <?php if ( function_exists('bp_wire_install') ) { ?>
    … …  
    455454                        <td class="no"><input type="radio" name="notifications[notification_profile_wire_post]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_profile_wire_post' ) ) { ?>checked="checked" <?php } ?>/></td>
    456455                </tr>
    457                
     456
    458457                <?php do_action( 'xprofile_screen_notification_settings' ) ?>
    459458        </table>
    460459        <?php } ?>
    461 <?php   
     460<?php
    462461}
    463462add_action( 'bp_notification_settings', 'xprofile_screen_notification_settings', 1 );
    … …  
    479478 *
    480479 * The function will delete the active avatar for a user.
    481  * 
     480 *
    482481 * @package BuddyPress Xprofile
    483482 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    491490        if ( $bp->profile->slug != $bp->current_component || 'change-avatar' != $bp->current_action || 'delete-avatar' != $bp->action_variables[0] )
    492491                return false;
    493        
     492
    494493        /* Check the nonce */
    495494        check_admin_referer( 'bp_delete_avatar_link' );
    496        
     495
    497496        if ( !bp_is_home() && !is_site_admin() )
    498497                return false;
    499        
     498
    500499        if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->displayed_user->id ) ) )
    501500                bp_core_add_message( __( 'Your avatar was deleted successfully!', 'buddypress' ) );
    … …  
    503502                bp_core_add_message( __( 'There was a problem deleting that avatar, please try again.', 'buddypress' ), 'error' );
    504503
    505         bp_core_redirect( wp_get_referer() ); 
     504        bp_core_redirect( wp_get_referer() );
    506505}
    507506add_action( 'wp', 'xprofile_action_delete_avatar', 3 );
    … …  
    510509 * xprofile_action_new_wire_post()
    511510 *
    512  * Posts a new wire post to the users profile wire. 
    513  * 
     511 * Posts a new wire post to the users profile wire.
     512 *
    514513 * @package BuddyPress XProfile
    515514 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    523522        if ( $bp->current_component != $bp->wire->slug )
    524523                return false;
    525        
     524
    526525        if ( 'post' != $bp->current_action )
    527526                return false;
    528                
     527
    529528        /* Check the nonce */
    530         if ( !check_admin_referer( 'bp_wire_post' ) ) 
    531                 return false;
    532                
     529        if ( !check_admin_referer( 'bp_wire_post' ) )
     530                return false;
     531
    533532        if ( !$wire_post = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) {
    534533                bp_core_add_message( __( 'Wire message could not be posted. Please try again.', 'buddypress' ), 'error' );
    535534        } else {
    536535                bp_core_add_message( __( 'Wire message successfully posted.', 'buddypress' ) );
    537                
     536
    538537                /* Record the notification for the reciever if it's not on their own wire */
    539538                if ( !bp_is_home() )
    540                         bp_core_add_notification( $bp->loggedin_user->id, $bp->displayed_user->id, $bp->profile->id, 'new_wire_post' ); 
    541                
     539                        bp_core_add_notification( $bp->loggedin_user->id, $bp->displayed_user->id, $bp->profile->id, 'new_wire_post' );
     540
    542541                /* Record this on the poster's activity screen */
    543542                if ( ( $wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
    544543                        $from_user_link = bp_core_get_userlink($wire_post->user_id);
    545                         $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>';                         
    546                         $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true );       
     544                        $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>';
     545                        $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true );
    547546                } else if ( ( $wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
    548547                        $from_user_link = bp_core_get_userlink($wire_post->user_id);
    549548                        $to_user_link = bp_core_get_userlink( $wire_post->item_id, false, false, true, true );
    550                         $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>';                 
     549                        $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>';
    551550                        $primary_link = bp_core_get_userlink( $wire_post->item_id, false, true );
    552                 } 
    553                
     551                }
     552
    554553                $content .= '<blockquote>' . bp_create_excerpt($wire_post->content) . '</blockquote>';
    555554
    … …  
    563562                ) );
    564563
    565                 do_action( 'xprofile_new_wire_post', &$wire_post );     
     564                do_action( 'xprofile_new_wire_post', &$wire_post );
    566565        }
    567566
    … …  
    577576 * xprofile_action_delete_wire_post()
    578577 *
    579  * Deletes a wire post from the users profile wire. 
    580  * 
     578 * Deletes a wire post from the users profile wire.
     579 *
    581580 * @package BuddyPress XProfile
    582581 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    … …  
    588587function xprofile_action_delete_wire_post() {
    589588        global $bp;
    590        
     589
    591590        if ( $bp->current_component != $bp->wire->slug )
    592591                return false;
    593        
     592
    594593        if ( $bp->current_action != 'delete' )
    595594                return false;
    596        
     595
    597596        if ( !check_admin_referer( 'bp_wire_delete_link' ) )
    598597                return false;
    599                        
     598
    600599        $wire_post_id = $bp->action_variables[0];
    601600
    … …  
    605604                /* Delete the post from activity streams */
    606605                xprofile_delete_activity( array( 'item_id' => $wire_post_id, 'component_action' => 'new_wire_post' ) );
    607                
    608                 do_action( 'xprofile_delete_wire_post', $wire_post_id );                                               
     606
     607                do_action( 'xprofile_delete_wire_post', $wire_post_id );
    609608        } else {
    610609                bp_core_add_message( __('Wire post could not be deleted, please try again.', 'buddypress'), 'error' );
    611610        }
    612        
     611
    613612        if ( !strpos( wp_get_referer(), $bp->wire->slug ) ) {
    614613                bp_core_redirect( $bp->displayed_user->domain );
    … …  
    629628function xprofile_register_activity_actions() {
    630629        global $bp;
    631        
     630
    632631        if ( !function_exists( 'bp_activity_set_action' ) )
    633632                return false;
    … …  
    647646 * Records activity for the logged in user within the profile component so that
    648647 * it will show in the users activity stream (if installed)
    649  * 
     648 *
    650649 * @package BuddyPress XProfile
    651650 * @param $args Array containing all variables used after extract() call
    … …  
    655654function xprofile_record_activity( $args = true ) {
    656655        global $bp;
    657        
     656
    658657        if ( !function_exists( 'bp_activity_add' ) )
    659658                return false;
    … …  
    672671
    673672        $r = wp_parse_args( $args, $defaults );
    674         extract( $r, EXTR_SKIP );       
    675        
     673        extract( $r, EXTR_SKIP );
     674
    676675        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 ) );
    677676}
    … …  
    682681 * Deletes activity for a user within the profile component so that
    683682 * it will be removed from the users activity stream and sitewide stream (if installed)
    684  * 
     683 *
    685684 * @package BuddyPress XProfile
    686685 * @param $args Array containing all variables used after extract() call
    … …  
    690689function xprofile_delete_activity( $args = '' ) {
    691690        global $bp;
    692        
     691
    693692        if ( function_exists('bp_activity_delete_by_item_id') ) {
    694693                extract($args);
    … …  
    699698function xprofile_register_activity_action( $key, $value ) {
    700699        global $bp;
    701        
     700
    702701        if ( !function_exists( 'bp_activity_set_action' ) )
    703702                return false;
    704        
     703
    705704        return apply_filters( 'xprofile_register_activity_action', bp_activity_set_action( $bp->profile->id, $key, $value ), $key, $value );
    706705}
    … …  
    710709 *
    711710 * Format notifications into something that can be read and displayed
    712  * 
     711 *
    713712 * @package BuddyPress Xprofile
    714713 * @param $item_id The ID of the specific item for which the activity is recorded (could be a wire post id, user id etc)
    … …  
    724723        if ( 'new_wire_post' == $action ) {
    725724                if ( (int)$total_items > 1 ) {
    726                         return apply_filters( 'bp_xprofile_multiple_new_wire_post_notification', '<a href="' . $bp->loggedin_user->domain . $bp->wire->slug . '" title="' . __( 'Wire', 'buddypress' ) . '">' . sprintf( __( 'You have %d new posts on your wire', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );               
     725                        return apply_filters( 'bp_xprofile_multiple_new_wire_post_notification', '<a href="' . $bp->loggedin_user->domain . $bp->wire->slug . '" title="' . __( 'Wire', 'buddypress' ) . '">' . sprintf( __( 'You have %d new posts on your wire', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
    727726                } else {
    728727                        $user_fullname = bp_core_get_user_displayname( $item_id );
    … …  
    730729                }
    731730        }
    732        
     731
    733732        do_action( 'xprofile_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
    734        
     733
    735734        return false;
    736735}
    … …  
    758757
    759758        $r = wp_parse_args( $args, $defaults );
    760         extract( $r, EXTR_SKIP );       
     759        extract( $r, EXTR_SKIP );
    761760
    762761        if ( !$name )
    763762                return false;
    764                
     763
    765764        $field_group = new BP_XProfile_Group( $field_group_id );
    766765        $field_group->name = $name;
    767766        $field_group->description = $description;
    768767        $field_group->can_delete = $can_delete;
    769        
     768
    770769        return $field_group->save();
    771770}
    … …  
    785784function xprofile_insert_field( $args = '' ) {
    786785        global $bp;
    787        
     786
    788787        extract( $args );
    789        
     788
    790789        /**
    791790         * Possible parameters (pass as assoc array):
    … …  
    803802         *      'option_order'
    804803         */
    805        
     804
    806805        /* Check we have the minimum details */
    807806        if ( !$field_group_id )
    808807                return false;
    809        
     808
    810809        /* Check this is a valid field type */
    811810        if ( !in_array( $type, (array) $bp->profile->field_types ) )
    812811                return false;
    813        
     812
    814813        /* Instantiate a new field object */
    815814        if ( $field_id )
    … …  
    819818
    820819        $field->group_id = $field_group_id;
    821        
     820
    822821        if ( !empty( $parent_id ) )
    823822                $field->parent_id = $parent_id;
    824        
     823
    825824        if ( !empty( $type ) )
    826825                $field->type = $type;
    827        
     826
    828827        if ( !empty( $name ) )
    829828                $field->name = $name;
    … …  
    831830        if ( !empty( $description ) )
    832831                $field->description = $description;
    833        
     832
    834833        if ( !empty( $is_required ) )
    835834                $field->is_required = $is_required;
    836                
     835
    837836        if ( !empty( $can_delete ) )
    838837                $field->can_delete = $can_delete;
    839        
     838
    840839        if ( !empty( $field_order ) )
    841840                $field->field_order = $field_order;
    842        
     841
    843842        if ( !empty( $order_by ) )
    844843                $field->order_by = $order_by;
    845        
     844
    846845        if ( !empty( $is_default_option ) )
    847846                $field->is_default_option = $is_default_option;
    848        
     847
    849848        if ( !empty( $option_order ) )
    850849                $field->option_order = $option_order;
    851        
     850
    852851        if ( !$field->save() )
    853852                return false;
    … …  
    872871 *
    873872 * Fetches profile data for a specific field for the user.
    874  * 
     873 *
    875874 * @package BuddyPress Core
    876875 * @param $field The ID of the field, or the $name of the field.
    … …  
    882881function xprofile_get_field_data( $field, $user_id = null ) {
    883882        global $bp;
    884        
     883
    885884        if ( !$user_id )
    886885                $user_id = $bp->displayed_user->id;
    887        
     886
    888887        if ( !$user_id )
    889888                return false;
    … …  
    904903 *
    905904 * A simple function to set profile data for a specific field for a specific user.
    906  * 
     905 *
    907906 * @package BuddyPress Core
    908907 * @param $field The ID of the field, or the $name of the field.
    … …  
    918917        else
    919918                $field_id = xprofile_get_field_id_from_name( $field );
    920        
     919
    921920        if ( !$field_id )
    922921                return false;
    923        
     922
    924923        $field = new BP_XProfile_ProfileData();
    925924        $field->field_id = $field_id;
    926925        $field->user_id = $user_id;
    927926        $field->value = maybe_serialize( $value );
    928        
     927
    929928        return $field->save();
    930929}
    … …  
    935934        else
    936935                $field_id = xprofile_get_field_id_from_name( $field );
    937        
     936
    938937        if ( !$field_id )
    939938                return false;
    940        
     939
    941940        $field = new BP_XProfile_ProfileData( $field_id );
    942941        return $field->delete();
    … …  
    945944function xprofile_check_is_required_field( $field_id ) {
    946945        $field = new BP_Xprofile_Field( $field_id );
    947        
     946
    948947        if ( (int)$field->is_required )
    949948                return true;
    950        
     949
    951950        return false;
    952951}
    … …  
    956955 *
    957956 * Returns the ID for the field based on the field name.
    958  * 
     957 *
    959958 * @package BuddyPress Core
    960959 * @param $field_name The name of the field to get the ID for.
    … …  
    969968 *
    970969 * Fetches a random piece of profile data for the user.
    971  * 
     970 *
    972971 * @package BuddyPress Core
    973972 * @param $user_id User ID of the user to get random data for
    … …  
    982981        $field_data = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname );
    983982        $field_data[0]->value = xprofile_format_profile_field( $field_data[0]->type, $field_data[0]->value );
    984        
     983
    985984        if ( !$field_data[0]->value || empty( $field_data[0]->value ) )
    986985                return false;
    987        
     986
    988987        return apply_filters( 'xprofile_get_random_profile_data', $field_data );
    989988}
    … …  
    993992 *
    994993 * Formats a profile field according to its type. [ TODO: Should really be moved to filters ]
    995  * 
     994 *
    996995 * @package BuddyPress Core
    997996 * @param $field_type The type of field: datebox, selectbox, textbox etc
    … …  
    10031002        if ( !isset($field_value) || empty( $field_value ) )
    10041003                return false;
    1005                
     1004
    10061005        $field_value = bp_unserialize_profile_field( $field_value );
    1007                
     1006
    10081007        if ( 'datebox' == $field_type ) {
    10091008                $field_value = bp_format_time( $field_value, true );
    … …  
    10131012                $field_value = str_replace(']]>', ']]&gt;', $content);
    10141013        }
    1015        
     1014
    10161015        return stripslashes( stripslashes( $field_value ) );
    10171016}
    … …  
    10251024 *
    10261025 * Setup the avatar upload directory for a user.
    1027  * 
     1026 *
    10281027 * @package BuddyPress Core
    10291028 * @param $directory The root directory name
    … …  
    10361035        if ( !$user_id )
    10371036                $user_id = $bp->displayed_user->id;
    1038        
     1037
    10391038        if ( !$directory )
    10401039                $directory = 'avatars';
    … …  
    10451044
    10461045        $newbdir = $newdir;
    1047        
     1046
    10481047        if ( !file_exists( $newdir ) )
    10491048                @wp_mkdir_p( $newdir );
    … …  
    10601059 *
    10611060 * Syncs Xprofile data to the standard built in WordPress profile data.
    1062  * 
     1061 *
    10631062 * @package BuddyPress Core
    10641063 */
    10651064function xprofile_sync_wp_profile() {
    10661065        global $bp, $wpdb;
    1067        
     1066
    10681067        if ( (int)get_site_option( 'bp-disable-profile-sync' ) )
    10691068                return true;
    1070        
     1069
    10711070        $fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );
    10721071        $space = strpos( $fullname, ' ' );
    1073        
     1072
    10741073        if ( false === $space ) {
    10751074                $firstname = $fullname;
    … …  
    10771076        } else {
    10781077                $firstname = substr( $fullname, 0, $space );
    1079                 $lastname = trim( substr( $fullname, $space, strlen($fullname) ) );             
    1080         }
    1081        
     1078                $lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
     1079        }
     1080
    10821081        update_usermeta( $bp->loggedin_user->id, 'nickname', $fullname );
    10831082        update_usermeta( $bp->loggedin_user->id, 'first_name', $firstname );
    … …  
    10951094 * Removes notifications from the notification menu when a user clicks on them and
    10961095 * is taken to a specific screen.
    1097  * 
     1096 *
    10981097 * @package BuddyPress Core
    10991098 */
    11001099function xprofile_remove_screen_notifications() {
    11011100        global $bp;
    1102        
     1101
    11031102        bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->profile->id, 'new_wire_post' );
    11041103}
    … …  
    11111110 * profile data from each table. Also we need to clean anything up in the usermeta table
    11121111 * that this component uses.
    1113  * 
     1112 *
    11141113 * @package BuddyPress XProfile
    11151114 * @param $user_id The ID of the deleted user
    … …  
    11201119function xprofile_remove_data( $user_id ) {
    11211120        BP_XProfile_ProfileData::delete_data_for_user( $user_id );
    1122        
     1121
    11231122        // delete any avatar files.
    11241123        @unlink( get_usermeta( $user_id, 'bp_core_avatar_v1_path' ) );
    11251124        @unlink( get_usermeta( $user_id, 'bp_core_avatar_v2_path' ) );
    1126        
     1125
    11271126        // unset the usermeta for avatars from the usermeta table.
    11281127        delete_usermeta( $user_id, 'bp_core_avatar_v1' );
    … …  
    11441143
    11451144function xprofile_clear_profile_data_object_cache( $group_id ) {
    1146         global $bp;     
     1145        global $bp;
    11471146        wp_cache_delete( 'xprofile_fields_' . $group_id . '_' . $bp->loggedin_user->id, 'bp' );
    11481147        wp_cache_delete( 'bp_user_fullname_' . $bp->loggedin_user->id, 'bp' );
Note: See TracChangeset for help on using the changeset viewer.