<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][3791] trunk/bp-xprofile: Add missing xprofile files from previous commit.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd>3791</dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2011-01-21 11:05:31 +0000 (Fri, 21 Jan 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add missing xprofile files from previous commit.</pre>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkbpxprofilebpxprofileactionsphp">trunk/bp-xprofile/bp-xprofile-actions.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilefunctionsphp">trunk/bp-xprofile/bp-xprofile-functions.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilescreensphp">trunk/bp-xprofile/bp-xprofile-screens.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpxprofilebpxprofileactionsphp"></a>
<div class="addfile"><h4>Added: trunk/bp-xprofile/bp-xprofile-actions.php (0 => 3791)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-actions.php                                (rev 0)
+++ trunk/bp-xprofile/bp-xprofile-actions.php        2011-01-21 11:05:31 UTC (rev 3791)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+&lt;?php
+
+/*******************************************************************************
+ * Action functions are exactly the same as screen functions, however they do
+ * not have a template screen associated with them. Usually they will send the
+ * user back to the default screen after execution.
+ */
+
+/**
+ * This function runs when an action is set for a screen:
+ * example.com/members/andy/profile/change-avatar/ [delete-avatar]
+ *
+ * The function will delete the active avatar for a user.
+ *
+ * @package BuddyPress Xprofile
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user.
+ * @uses add_action() Runs a specific function for an action when it fires.
+ * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
+ */
+function xprofile_action_delete_avatar() {
+        global $bp;
+
+        if ( $bp-&gt;profile-&gt;id != $bp-&gt;current_component || 'change-avatar' != $bp-&gt;current_action || !isset( $bp-&gt;action_variables[0] ) || 'delete-avatar' != $bp-&gt;action_variables[0] )
+                return false;
+
+        // Check the nonce
+        check_admin_referer( 'bp_delete_avatar_link' );
+
+        if ( !bp_is_my_profile() &amp;&amp; !is_super_admin() )
+                return false;
+
+        if ( bp_core_delete_existing_avatar( array( 'item_id' =&gt; $bp-&gt;displayed_user-&gt;id ) ) )
+                bp_core_add_message( __( 'Your avatar was deleted successfully!', 'buddypress' ) );
+        else
+                bp_core_add_message( __( 'There was a problem deleting that avatar, please try again.', 'buddypress' ), 'error' );
+
+        bp_core_redirect( wp_get_referer() );
+}
+add_action( 'wp', 'xprofile_action_delete_avatar', 3 );
+
+?&gt;
</ins></span></pre></div>
<a id="trunkbpxprofilebpxprofilefunctionsphp"></a>
<div class="addfile"><h4>Added: trunk/bp-xprofile/bp-xprofile-functions.php (0 => 3791)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-functions.php                                (rev 0)
+++ trunk/bp-xprofile/bp-xprofile-functions.php        2011-01-21 11:05:31 UTC (rev 3791)
</span><span class="lines">@@ -0,0 +1,712 @@
</span><ins>+&lt;?php
+
+/*******************************************************************************
+ * These functions handle the recording, deleting and formatting of activity and
+ * notifications for the user and for this specific component.
+ */
+
+function xprofile_register_activity_actions() {
+        global $bp;
+
+        if ( bp_is_active( 'activity' ) )
+                return false;
+
+        // Register the activity stream actions for this component
+        bp_activity_set_action( $bp-&gt;profile-&gt;id, 'new_member',      __( 'New member registered', 'buddypress' ) );
+        bp_activity_set_action( $bp-&gt;profile-&gt;id, 'updated_profile', __( 'Updated Profile',       'buddypress' ) );
+
+        do_action( 'xprofile_register_activity_actions' );
+}
+add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' );
+
+/**
+ * Records activity for the logged in user within the profile component so that
+ * it will show in the users activity stream (if installed)
+ *
+ * @package BuddyPress XProfile
+ * @param $args Array containing all variables used after extract() call
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @uses bp_activity_record() Adds an entry to the activity component tables for a specific activity
+ */
+function xprofile_record_activity( $args = true ) {
+        global $bp;
+
+        if ( !bp_is_active( 'activity' ) )
+                return false;
+
+        $defaults = array (
+                'user_id'           =&gt; $bp-&gt;loggedin_user-&gt;id,
+                'action'            =&gt; '',
+                'content'           =&gt; '',
+                'primary_link'      =&gt; '',
+                'component'         =&gt; $bp-&gt;profile-&gt;id,
+                'type'              =&gt; false,
+                'item_id'           =&gt; false,
+                'secondary_item_id' =&gt; false,
+                'recorded_time'     =&gt; bp_core_current_time(),
+                'hide_sitewide'     =&gt; false
+        );
+
+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );
+
+        return bp_activity_add( array(
+                'user_id'           =&gt; $user_id,
+                'action'            =&gt; $action,
+                'content'           =&gt; $content,
+                'primary_link'      =&gt; $primary_link,
+                'component'         =&gt; $component,
+                'type'              =&gt; $type,
+                'item_id'           =&gt; $item_id,
+                'secondary_item_id' =&gt; $secondary_item_id,
+                'recorded_time'     =&gt; $recorded_time,
+                'hide_sitewide'     =&gt; $hide_sitewide
+        ) );
+}
+
+/**
+ * Deletes activity for a user within the profile component so that
+ * it will be removed from the users activity stream and sitewide stream (if installed)
+ *
+ * @package BuddyPress XProfile
+ * @param $args Array containing all variables used after extract() call
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @uses bp_activity_delete() Deletes an entry to the activity component tables for a specific activity
+ */
+function xprofile_delete_activity( $args = '' ) {
+        global $bp;
+
+        if ( bp_is_active( 'activity' ) ) {
+
+                extract( $args );
+
+                bp_activity_delete_by_item_id( array(
+                        'item_id'           =&gt; $item_id,
+                        'component'         =&gt; $bp-&gt;profile-&gt;id,
+                        'type'              =&gt; $type,
+                        'user_id'           =&gt; $user_id,
+                        'secondary_item_id' =&gt; $secondary_item_id
+                ) );
+        }
+}
+
+function xprofile_register_activity_action( $key, $value ) {
+        global $bp;
+
+        if ( !bp_is_active( 'activity' ) )
+                return false;
+
+        return apply_filters( 'xprofile_register_activity_action', bp_activity_set_action( $bp-&gt;profile-&gt;id, $key, $value ), $key, $value );
+}
+
+
+/********************************************************************************
+ * Business Functions
+ *
+ * Business functions are where all the magic happens in BuddyPress. They will
+ * handle the actual saving or manipulation of information. Usually they will
+ * hand off to a database class for data access, then return
+ * true or false on success or failure.
+ */
+
+/*** Field Group Management **************************************************/
+
+function xprofile_insert_field_group( $args = '' ) {
+        $defaults = array(
+                'field_group_id' =&gt; false,
+                'name'           =&gt; false,
+                'description'    =&gt; '',
+                'can_delete'     =&gt; true
+        );
+
+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );
+
+        if ( !$name )
+                return false;
+
+        $field_group              = new BP_XProfile_Group( $field_group_id );
+        $field_group-&gt;name        = $name;
+        $field_group-&gt;description = $description;
+        $field_group-&gt;can_delete  = $can_delete;
+
+        return $field_group-&gt;save();
+}
+
+function xprofile_get_field_group( $field_group_id ) {
+        $field_group = new BP_XProfile_Group( $field_group_id );
+
+        if ( empty( $field_group-&gt;id ) )
+                return false;
+
+        return $field_group;
+}
+
+function xprofile_delete_field_group( $field_group_id ) {
+        $field_group = new BP_XProfile_Group( $field_group_id );
+        return $field_group-&gt;delete();
+}
+
+function xprofile_update_field_group_position( $field_group_id, $position ) {
+        return BP_XProfile_Group::update_position( $field_group_id, $position );
+}
+
+
+/*** Field Management *********************************************************/
+
+function xprofile_insert_field( $args = '' ) {
+        global $bp;
+
+        extract( $args );
+
+        /**
+         * Possible parameters (pass as assoc array):
+         *        'field_id'
+         *        'field_group_id'
+         *        'parent_id'
+         *        'type'
+         *        'name'
+         *        'description'
+         *        'is_required'
+         *        'can_delete'
+         *        'field_order'
+         *        'order_by'
+         *        'is_default_option'
+         *        'option_order'
+         */
+
+        // Check we have the minimum details
+        if ( !$field_group_id )
+                return false;
+
+        // Check this is a valid field type
+        if ( !in_array( $type, (array) $bp-&gt;profile-&gt;field_types ) )
+                return false;
+
+        // Instantiate a new field object
+        if ( $field_id )
+                $field = new BP_XProfile_Field( $field_id );
+        else
+                $field = new BP_XProfile_Field;
+
+        $field-&gt;group_id = $field_group_id;
+
+        if ( !empty( $parent_id ) )
+                $field-&gt;parent_id = $parent_id;
+
+        if ( !empty( $type ) )
+                $field-&gt;type = $type;
+
+        if ( !empty( $name ) )
+                $field-&gt;name = $name;
+
+        if ( !empty( $description ) )
+                $field-&gt;description = $description;
+
+        if ( !empty( $is_required ) )
+                $field-&gt;is_required = $is_required;
+
+        if ( !empty( $can_delete ) )
+                $field-&gt;can_delete = $can_delete;
+
+        if ( !empty( $field_order ) )
+                $field-&gt;field_order = $field_order;
+
+        if ( !empty( $order_by ) )
+                $field-&gt;order_by = $order_by;
+
+        if ( !empty( $is_default_option ) )
+                $field-&gt;is_default_option = $is_default_option;
+
+        if ( !empty( $option_order ) )
+                $field-&gt;option_order = $option_order;
+
+        if ( !$field-&gt;save() )
+                return false;
+
+        return true;
+}
+
+function xprofile_get_field( $field_id ) {
+        return new BP_XProfile_Field( $field_id );
+}
+
+function xprofile_delete_field( $field_id ) {
+        $field = new BP_XProfile_Field( $field_id );
+        return $field-&gt;delete();
+}
+
+
+/*** Field Data Management *****************************************************/
+
+/**
+ * Fetches profile data for a specific field for the user.
+ *
+ * When the field value is serialized, this function unserializes and filters each item in the array
+ * that results.
+ *
+ * @package BuddyPress Core
+ * @param mixed $field The ID of the field, or the $name of the field.
+ * @param int $user_id The ID of the user
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.
+ * @return mixed The profile field data.
+ */
+function xprofile_get_field_data( $field, $user_id = 0 ) {
+        global $bp;
+
+        // This is required because of a call to bp_core_get_user_displayname() in bp_core_setup_globals()
+        if ( !isset( $bp-&gt;profile-&gt;id ) )
+                xprofile_setup_globals();
+
+        if ( empty( $user_id ) )
+                $user_id = $bp-&gt;displayed_user-&gt;id;
+
+        if ( empty( $user_id ) )
+                return false;
+
+        if ( is_numeric( $field ) )
+                $field_id = $field;
+        else
+                $field_id = xprofile_get_field_id_from_name( $field );
+
+        if ( empty( $field_id ) )
+                return false;
+
+        $values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) );
+
+        if ( is_array( $values ) ) {
+                $data = array();
+                foreach( (array)$values as $value ) {
+                        $data[] = apply_filters( 'xprofile_get_field_data', $value );
+                }
+        } else {
+                $data = apply_filters( 'xprofile_get_field_data', $values );
+        }
+
+        return $data;
+}
+
+/**
+ * A simple function to set profile data for a specific field for a specific user.
+ *
+ * @package BuddyPress Core
+ * @param $field The ID of the field, or the $name of the field.
+ * @param $user_id The ID of the user
+ * @param $value The value for the field you want to set for the user.
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @uses xprofile_get_field_id_from_name() Gets the ID for the field based on the name.
+ * @return true on success, false on failure.
+ */
+function xprofile_set_field_data( $field, $user_id, $value, $is_required = false ) {
+
+        if ( is_numeric( $field ) )
+                $field_id = $field;
+        else
+                $field_id = xprofile_get_field_id_from_name( $field );
+
+        if ( empty( $field_id ) )
+                return false;
+
+        if ( $is_required &amp;&amp; ( empty( $value ) || !is_array( $value ) &amp;&amp; !strlen( trim( $value ) ) ) )
+                return false;
+
+        $field = new BP_XProfile_Field( $field_id );
+
+        // If the value is empty, then delete any field data that exists, unless the field is of a
+        // type where null values are semantically meaningful
+        if ( empty( $value ) &amp;&amp; 'checkbox' != $field-&gt;type &amp;&amp; 'multiselectbox' != $field-&gt;type ) {
+                xprofile_delete_field_data( $field_id, $user_id );
+                return true;
+        }
+
+        // Check the value is an acceptable value
+        if ( 'checkbox' == $field-&gt;type || 'radio' == $field-&gt;type || 'selectbox' == $field-&gt;type || 'multiselectbox' == $field-&gt;type ) {
+                $options = $field-&gt;get_children();
+
+                foreach( $options as $option )
+                        $possible_values[] = $option-&gt;name;
+
+                if ( is_array( $value ) ) {
+                        foreach( $value as $i =&gt; $single ) {
+                                if ( !in_array( $single, (array)$possible_values ) ) {
+                                        unset( $value[$i] );
+                                }
+                        }
+
+                        // Reset the keys by merging with an empty array
+                        $value = array_merge( array(), $value );
+                } else {
+                        if ( !in_array( $value, (array)$possible_values ) ) {
+                                return false;
+                        }
+                }
+        }
+
+        $field           = new BP_XProfile_ProfileData();
+        $field-&gt;field_id = $field_id;
+        $field-&gt;user_id  = $user_id;
+        $field-&gt;value    = maybe_serialize( $value );
+
+        return $field-&gt;save();
+}
+
+function xprofile_delete_field_data( $field, $user_id ) {
+        if ( is_numeric( $field ) )
+                $field_id = $field;
+        else
+                $field_id = xprofile_get_field_id_from_name( $field );
+
+        if ( empty( $field_id ) || empty( $user_id ) )
+                return false;
+
+        $field = new BP_XProfile_ProfileData( $field_id, $user_id );
+        return $field-&gt;delete();
+}
+
+function xprofile_check_is_required_field( $field_id ) {
+        $field = new BP_Xprofile_Field( $field_id );
+
+        if ( (int)$field-&gt;is_required )
+                return true;
+
+        return false;
+}
+
+/**
+ * Returns the ID for the field based on the field name.
+ *
+ * @package BuddyPress Core
+ * @param $field_name The name of the field to get the ID for.
+ * @return int $field_id on success, false on failure.
+ */
+function xprofile_get_field_id_from_name( $field_name ) {
+        return BP_Xprofile_Field::get_id_from_name( $field_name );
+}
+
+/**
+ * Fetches a random piece of profile data for the user.
+ *
+ * @package BuddyPress Core
+ * @param $user_id User ID of the user to get random data for
+ * @param $exclude_fullname whether or not to exclude the full name field as random data.
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @global $wpdb WordPress DB access object.
+ * @global $current_user WordPress global variable containing current logged in user information
+ * @uses xprofile_format_profile_field() Formats profile field data so it is suitable for display.
+ * @return $field_data The fetched random data for the user.
+ */
+function xprofile_get_random_profile_data( $user_id, $exclude_fullname = true ) {
+        $field_data           = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname );
+        $field_data[0]-&gt;value = xprofile_format_profile_field( $field_data[0]-&gt;type, $field_data[0]-&gt;value );
+
+        if ( !$field_data[0]-&gt;value || empty( $field_data[0]-&gt;value ) )
+                return false;
+
+        return apply_filters( 'xprofile_get_random_profile_data', $field_data );
+}
+
+/**
+ * Formats a profile field according to its type. [ TODO: Should really be moved to filters ]
+ *
+ * @package BuddyPress Core
+ * @param $field_type The type of field: datebox, selectbox, textbox etc
+ * @param $field_value The actual value
+ * @uses bp_format_time() Formats a time value based on the WordPress date format setting
+ * @return $field_value The formatted value
+ */
+function xprofile_format_profile_field( $field_type, $field_value ) {
+        if ( !isset( $field_value ) || empty( $field_value ) )
+                return false;
+
+        $field_value = bp_unserialize_profile_field( $field_value );
+
+        if ( 'datebox' == $field_type ) {
+                $field_value = bp_format_time( $field_value, true );
+        } else {
+                $content = $field_value;
+                $field_value = str_replace( ']]&gt;', ']]&amp;gt;', $content );
+        }
+
+        return stripslashes_deep( $field_value );
+}
+
+function xprofile_update_field_position( $field_id, $position, $field_group_id ) {
+        return BP_XProfile_Field::update_position( $field_id, $position, $field_group_id );
+}
+
+/**
+ * Setup the avatar upload directory for a user.
+ *
+ * @package BuddyPress Core
+ * @param $directory The root directory name
+ * @param $user_id The user ID.
+ * @return array() containing the path and URL plus some other settings.
+ */
+function xprofile_avatar_upload_dir( $directory = false, $user_id = 0 ) {
+        global $bp;
+
+        if ( empty( $user_id ) )
+                $user_id = $bp-&gt;displayed_user-&gt;id;
+
+        if ( empty( $directory ) )
+                $directory = 'avatars';
+
+        $path    = BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id;
+        $newbdir = $path;
+
+        if ( !file_exists( $path ) )
+                @wp_mkdir_p( $path );
+
+        $newurl    = BP_AVATAR_URL . '/avatars/' . $user_id;
+        $newburl   = $newurl;
+        $newsubdir = '/avatars/' . $user_id;
+
+        return apply_filters( 'xprofile_avatar_upload_dir', array(
+                'path'    =&gt; $path,
+                'url'     =&gt; $newurl,
+                'subdir'  =&gt; $newsubdir,
+                'basedir' =&gt; $newbdir,
+                'baseurl' =&gt; $newburl,
+                'error'   =&gt; false
+        ) );
+}
+
+/**
+ * Syncs Xprofile data to the standard built in WordPress profile data.
+ *
+ * @package BuddyPress Core
+ */
+function xprofile_sync_wp_profile( $user_id = 0 ) {
+        global $bp, $wpdb;
+
+        if ( !empty( $bp-&gt;site_options['bp-disable-profile-sync'] ) &amp;&amp; (int)$bp-&gt;site_options['bp-disable-profile-sync'] )
+                return true;
+
+        if ( empty( $user_id ) )
+                $user_id = $bp-&gt;loggedin_user-&gt;id;
+
+        if ( empty( $user_id ) )
+                return false;
+
+        $fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
+        $space    = strpos( $fullname, ' ' );
+
+        if ( false === $space ) {
+                $firstname = $fullname;
+                $lastname = '';
+        } else {
+                $firstname = substr( $fullname, 0, $space );
+                $lastname = trim( substr( $fullname, $space, strlen( $fullname ) ) );
+        }
+
+        update_user_meta( $user_id, 'nickname',   $fullname  );
+        update_user_meta( $user_id, 'first_name', $firstname );
+        update_user_meta( $user_id, 'last_name',  $lastname  );
+
+        $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;UPDATE {$wpdb-&gt;users} SET display_name = %s WHERE ID = %d&quot;, $fullname, $user_id ) );
+        $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;UPDATE {$wpdb-&gt;users} SET user_url = %s WHERE ID = %d&quot;, bp_core_get_user_domain( $user_id ), $user_id ) );
+}
+add_action( 'xprofile_updated_profile', 'xprofile_sync_wp_profile' );
+add_action( 'bp_core_signup_user', 'xprofile_sync_wp_profile' );
+
+
+/**
+ * Syncs the standard built in WordPress profile data to XProfile.
+ *
+ * @since 1.2.4
+ * @package BuddyPress Core
+ */
+function xprofile_sync_bp_profile( &amp;$errors, $update, &amp;$user ) {
+        global $bp;
+
+        if ( ( !empty( $bp-&gt;site_options['bp-disable-profile-sync'] ) &amp;&amp; (int)$bp-&gt;site_options['bp-disable-profile-sync'] ) || !$update || $errors-&gt;get_error_codes() )
+                return;
+
+        xprofile_set_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user-&gt;ID, $user-&gt;display_name );
+}
+add_action( 'user_profile_update_errors', 'xprofile_sync_bp_profile', 10, 3 );
+
+
+/**
+ * When a user is deleted, we need to clean up the database and remove all the
+ * profile data from each table. Also we need to clean anything up in the usermeta table
+ * that this component uses.
+ *
+ * @package BuddyPress XProfile
+ * @param $user_id The ID of the deleted user
+ * @uses get_user_meta() Get a user meta value based on meta key from wp_usermeta
+ * @uses delete_user_meta() Delete user meta value based on meta key from wp_usermeta
+ * @uses delete_data_for_user() Removes all profile data from the xprofile tables for the user
+ */
+function xprofile_remove_data( $user_id ) {
+        BP_XProfile_ProfileData::delete_data_for_user( $user_id );
+
+        // delete any avatar files.
+        @unlink( get_user_meta( $user_id, 'bp_core_avatar_v1_path', true ) );
+        @unlink( get_user_meta( $user_id, 'bp_core_avatar_v2_path', true ) );
+
+        // unset the usermeta for avatars from the usermeta table.
+        delete_user_meta( $user_id, 'bp_core_avatar_v1'      );
+        delete_user_meta( $user_id, 'bp_core_avatar_v1_path' );
+        delete_user_meta( $user_id, 'bp_core_avatar_v2'      );
+        delete_user_meta( $user_id, 'bp_core_avatar_v2_path' );
+}
+add_action( 'wpmu_delete_user',  'xprofile_remove_data' );
+add_action( 'delete_user',       'xprofile_remove_data' );
+add_action( 'bp_make_spam_user', 'xprofile_remove_data' );
+
+/*** XProfile Meta ****************************************************/
+
+function bp_xprofile_delete_meta( $object_id, $object_type, $meta_key = false, $meta_value = false ) {
+        global $wpdb, $bp;
+
+        $object_id = (int) $object_id;
+
+        if ( !$object_id )
+                return false;
+
+        if ( !isset( $object_type ) )
+                return false;
+
+        if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) )
+                return false;
+
+        $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
+
+        if ( is_array( $meta_value ) || is_object( $meta_value ) )
+                $meta_value = serialize( $meta_value );
+
+        $meta_value = trim( $meta_value );
+
+        if ( !$meta_key )
+                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; WHERE object_id = %d AND object_type = %s&quot;, $object_id, $object_type ) );
+        else if ( $meta_value )
+                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; WHERE object_id = %d AND object_type = %s AND meta_key = %s AND meta_value = %s&quot;, $object_id, $object_type, $meta_key, $meta_value ) );
+        else
+                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; WHERE object_id = %d AND object_type = %s AND meta_key = %s&quot;, $object_id, $object_type, $meta_key ) );
+
+        // Delete the cached object
+        wp_cache_delete( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp' );
+
+        return true;
+}
+
+function bp_xprofile_get_meta( $object_id, $object_type, $meta_key = '') {
+        global $wpdb, $bp;
+
+        $object_id = (int) $object_id;
+
+        if ( !$object_id )
+                return false;
+
+        if ( !isset( $object_type ) )
+                return false;
+
+        if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) )
+                return false;
+
+        if ( !empty( $meta_key ) ) {
+                $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
+
+                if ( !$metas = wp_cache_get( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp' ) ) {
+                        $metas = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT meta_value FROM &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; WHERE object_id = %d AND object_type = %s AND meta_key = %s&quot;, $object_id, $object_type, $meta_key ) );
+                        wp_cache_set( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $metas, 'bp' );
+                }
+        } else {
+                $metas = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT meta_value FROM &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; WHERE object_id = %d AND object_type = %s&quot;, $object_id, $object_type ) );
+        }
+
+        if ( empty( $metas ) ) {
+                if ( empty( $meta_key ) ) {
+                        return array();
+                } else {
+                        return '';
+                }
+        }
+
+        $metas = array_map( 'maybe_unserialize', (array)$metas );
+
+        if ( 1 == count( $metas ) )
+                return $metas[0];
+        else
+                return $metas;
+}
+
+function bp_xprofile_update_meta( $object_id, $object_type, $meta_key, $meta_value ) {
+        global $wpdb, $bp;
+
+        $object_id = (int) $object_id;
+
+        if ( empty( $object_id ) )
+                return false;
+
+        if ( !isset( $object_type ) )
+                return false;
+
+        if ( !in_array( $object_type, array( 'group', 'field', 'data' ) ) )
+                return false;
+
+        $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
+
+        if ( is_string( $meta_value ) )
+                $meta_value = stripslashes( $wpdb-&gt;escape( $meta_value ) );
+
+        $meta_value = maybe_serialize( $meta_value );
+
+        if ( empty( $meta_value ) )
+                return bp_xprofile_delete_meta( $object_id, $object_type, $meta_key );
+
+        $cur = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; WHERE object_id = %d AND object_type = %s AND meta_key = %s&quot;, $object_id, $object_type, $meta_key ) );
+
+        if ( empty( $cur ) )
+                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;INSERT INTO &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; ( object_id, object_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )&quot;, $object_id, $object_type,  $meta_key, $meta_value ) );
+        else if ( $cur-&gt;meta_value != $meta_value )
+                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;UPDATE &quot; . $bp-&gt;profile-&gt;table_name_meta . &quot; SET meta_value = %s WHERE object_id = %d AND object_type = %s AND meta_key = %s&quot;, $meta_value, $object_id, $object_type, $meta_key ) );
+        else
+                return false;
+
+        // Update the cached object and recache
+        wp_cache_set( 'bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $meta_value, 'bp' );
+
+        return true;
+}
+
+function bp_xprofile_update_fieldgroup_meta( $field_group_id, $meta_key, $meta_value ) {
+        return bp_xprofile_update_meta( $field_group_id, 'group', $meta_key, $meta_value );
+}
+
+function bp_xprofile_update_field_meta( $field_id, $meta_key, $meta_value ) {
+        return bp_xprofile_update_meta( $field_id, 'field', $meta_key, $meta_value );
+}
+
+function bp_xprofile_update_fielddata_meta( $field_data_id, $meta_key, $meta_value ) {
+        return bp_xprofile_update_meta( $field_data_id, 'data', $meta_key, $meta_value );
+}
+
+/********************************************************************************
+ * Caching
+ *
+ * Caching functions handle the clearing of cached objects and pages on specific
+ * actions throughout BuddyPress.
+ */
+
+function xprofile_clear_profile_groups_object_cache( $group_obj ) {
+        wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
+        wp_cache_delete( 'xprofile_group_' . $group_obj-&gt;id );
+}
+
+function xprofile_clear_profile_data_object_cache( $group_id ) {
+        global $bp;
+        wp_cache_delete( 'bp_user_fullname_' . $bp-&gt;loggedin_user-&gt;id, 'bp' );
+}
+
+// List actions to clear object caches on
+add_action( 'xprofile_groups_deleted_group', 'xprofile_clear_profile_groups_object_cache' );
+add_action( 'xprofile_groups_saved_group',   'xprofile_clear_profile_groups_object_cache' );
+add_action( 'xprofile_updated_profile',      'xprofile_clear_profile_data_object_cache'   );
+
+// List actions to clear super cached pages on, if super cache is installed
+add_action( 'xprofile_updated_profile', 'bp_core_clear_cache' );
+
+?&gt;
</ins></span></pre></div>
<a id="trunkbpxprofilebpxprofilescreensphp"></a>
<div class="addfile"><h4>Added: trunk/bp-xprofile/bp-xprofile-screens.php (0 => 3791)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-screens.php                                (rev 0)
+++ trunk/bp-xprofile/bp-xprofile-screens.php        2011-01-21 11:05:31 UTC (rev 3791)
</span><span class="lines">@@ -0,0 +1,170 @@
</span><ins>+&lt;?php
+
+/*******************************************************************************
+ * Screen functions are the controllers of BuddyPress. They will execute when
+ * their specific URL is caught. They will first save or manipulate data using
+ * business functions, then pass on the user to a template file.
+ */
+
+/**
+ * Handles the display of the profile page by loading the correct template file.
+ *
+ * @package BuddyPress XProfile
+ * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
+ */
+function xprofile_screen_display_profile() {
+        $new = isset( $_GET['new'] ) ? $_GET['new'] : '';
+
+        do_action( 'xprofile_screen_display_profile', $new );
+        bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'members/single/home' ) );
+}
+
+/**
+ * Handles the display of the profile edit page by loading the correct template file.
+ * Also checks to make sure this can only be accessed for the logged in users profile.
+ *
+ * @package BuddyPress XProfile
+ * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
+ * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
+ */
+function xprofile_screen_edit_profile() {
+        global $bp;
+
+        if ( !bp_is_my_profile() &amp;&amp; !is_super_admin() )
+                return false;
+
+        // Make sure a group is set.
+        if ( empty( $bp-&gt;action_variables[1] ) )
+                bp_core_redirect( $bp-&gt;displayed_user-&gt;domain . $bp-&gt;profile-&gt;slug . '/edit/group/1' );
+
+        // Check the field group exists
+        if ( !xprofile_get_field_group( $bp-&gt;action_variables[1] ) )
+                bp_core_redirect( $bp-&gt;root_domain );
+
+        // Check to see if any new information has been submitted
+        if ( isset( $_POST['field_ids'] ) ) {
+
+                // Check the nonce
+                check_admin_referer( 'bp_xprofile_edit' );
+
+                // Check we have field ID's
+                if ( empty( $_POST['field_ids'] ) )
+                        bp_core_redirect( trailingslashit( $bp-&gt;displayed_user-&gt;domain . $bp-&gt;profile-&gt;slug . '/edit/group/' . $bp-&gt;action_variables[1] ) );
+
+                // Explode the posted field IDs into an array so we know which
+                // fields have been submitted
+                $posted_field_ids = explode( ',', $_POST['field_ids'] );
+                $is_required      = array();
+
+                // Loop through the posted fields formatting any datebox values
+                // then validate the field
+                foreach ( (array)$posted_field_ids as $field_id ) {
+                        if ( !isset( $_POST['field_' . $field_id] ) ) {
+
+                                if ( !empty( $_POST['field_' . $field_id . '_day'] ) &amp;&amp; is_numeric( $_POST['field_' . $field_id . '_day'] ) ) {
+                                        // Concatenate the values
+                                        $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' .
+                                                                        $_POST['field_' . $field_id . '_month'] . ' ' .
+                                                                        $_POST['field_' . $field_id . '_year'];
+
+                                        // Turn the concatenated value into a timestamp
+                                        $_POST['field_' . $field_id] = strtotime( $date_value );
+                                }
+
+                        }
+
+                        $is_required[$field_id] = xprofile_check_is_required_field( $field_id );
+                        if ( $is_required[$field_id] &amp;&amp; empty( $_POST['field_' . $field_id] ) )
+                                $errors = true;
+                }
+
+                // There are errors
+                if ( !empty( $errors ) ) {
+                        bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );
+
+                // No errors
+                } else {
+                        // Reset the errors var
+                        $errors = false;
+
+                        // Now we've checked for required fields, lets save the values.
+                        foreach ( (array)$posted_field_ids as $field_id ) {
+
+                                // 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.
+                                if ( empty( $_POST['field_' . $field_id] ) )
+                                        $value = array();
+                                else
+                                        $value = $_POST['field_' . $field_id];
+
+                                if ( !xprofile_set_field_data( $field_id, $bp-&gt;displayed_user-&gt;id, $value, $is_required[$field_id] ) )
+                                        $errors = true;
+                                else
+                                        do_action( 'xprofile_profile_field_data_updated', $field_id, $value );
+                        }
+
+                        do_action( 'xprofile_updated_profile', $bp-&gt;displayed_user-&gt;id, $posted_field_ids, $errors );
+
+                        // Set the feedback messages
+                        if ( $errors )
+                                bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' );
+                        else
+                                bp_core_add_message( __( 'Changes saved.', 'buddypress' ) );
+
+                        // Redirect back to the edit screen to display the updates and message
+                        bp_core_redirect( trailingslashit( $bp-&gt;displayed_user-&gt;domain . $bp-&gt;profile-&gt;slug . '/edit/group/' . $bp-&gt;action_variables[1] ) );
+                }
+        }
+
+        do_action( 'xprofile_screen_edit_profile' );
+        bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'members/single/home' ) );
+}
+
+/**
+ * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
+ *
+ * @package BuddyPress XProfile
+ * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
+ * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
+ */
+function xprofile_screen_change_avatar() {
+        global $bp;
+
+        if ( !bp_is_my_profile() &amp;&amp; !is_super_admin() )
+                return false;
+
+        $bp-&gt;avatar_admin-&gt;step = 'upload-image';
+
+        if ( !empty( $_FILES ) ) {
+
+                // Check the nonce
+                check_admin_referer( 'bp_avatar_upload' );
+
+                // Pass the file to the avatar upload handler
+                if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {
+                        $bp-&gt;avatar_admin-&gt;step = 'crop-image';
+
+                        // Make sure we include the jQuery jCrop file for image cropping
+                        add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
+                }
+        }
+
+        // If the image cropping is done, crop the image and save a full/thumb version
+        if ( isset( $_POST['avatar-crop-submit'] ) ) {
+
+                // Check the nonce
+                check_admin_referer( 'bp_avatar_cropstore' );
+
+                if ( !bp_core_avatar_handle_crop( array( 'item_id' =&gt; $bp-&gt;displayed_user-&gt;id, 'original_file' =&gt; $_POST['image_src'], 'crop_x' =&gt; $_POST['x'], 'crop_y' =&gt; $_POST['y'], 'crop_w' =&gt; $_POST['w'], 'crop_h' =&gt; $_POST['h'] ) ) )
+                        bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
+                else {
+                        bp_core_add_message( __( 'Your new avatar was uploaded successfully!', 'buddypress' ) );
+                        do_action( 'xprofile_avatar_uploaded' );
+                }
+        }
+
+        do_action( 'xprofile_screen_change_avatar' );
+
+        bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/home' ) );
+}
+
+?&gt;
</ins></span></pre>
</div>
</div>

</body>
</html>