Import hCard';
}
/**
* Save extended profile attributes.
*
* @param int $userid ID of user
* @uses apply_filters() Calls 'pre_ext_profile_$name' before saving each profile attribute.
* @access private
*/
function ext_profile_update($userid) {
if($_POST['do_manual_hcard']) {
ext_profile_hcard_import($userid, true);
} else {
$additional_urls = preg_split('/[\s]+/',$_POST['additional_urls']);
$urls = array();
foreach ($additional_urls as $u) {
$urls[] = apply_filters('pre_ext_profile_url', $u);
}
update_usermeta($userid, 'additional_urls', array_filter($urls));
if (is_array($_POST['hcard'])) {
foreach($_POST['hcard'] as $key => $value) {
$value = apply_filters("pre_ext_profile_$key", $value);
update_usermeta($userid, $key, $value);
}
}
}
}
/**
* Get the microformatted profile for the specified user.
*
* @param mixed $userid username or ID of user to get profile for. If not specified, the queried author will be used.
* @param string|array $args arguments to overwrite the defaults. List of arguments:
* before - (string) markup printed before the generated profile (default: '
')
* after - (string) markup printed after the generated profile (default: '
')
* activity_stream - (boolean) Whether activity stream services should be included in the generated profile (default: false)
*
* @return string microformatted profile
*
* @uses do_action() Calls 'extended_profile' to build the user profile
* @uses apply_filters() Calls 'post_extended_profile' after building the entire profile, but before returning it.
* @access private
*/
function get_extended_profile( $userid, $args=NULL ) {
$defaults = array(
'before' => '
',
'after' => '
',
'activity_stream' => false
);
extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
// ensure plugin doesn't break in the absence of the permissions plugin
if (!function_exists('diso_user_is')) { function diso_user_is() { return true; } }
// Use queried author if userid not provided
if (empty($userid) && is_author()) {
global $wp_query;
$user = $wp_query->get_queried_object();
$userid = $user->ID;
}
// Get user data
if(is_numeric($userid))
$userdata = get_userdata($userid);
else
$userdata = get_userdatabylogin($userid);
if (!$userdata) return;
$time = microtime(true);
// Build profile
ob_start();
do_action('extended_profile', $userdata->ID, $activity_stream);
$profile = ob_get_contents();
ob_end_clean();
$profile = $before . $profile . $after;
$profile = apply_filters('post_extended_profile', $profile, $userdata->ID);
if (defined('WP_DEBUG') && WP_DEBUG) error_log('extended-profile build time = ' . (microtime(true) - $time) . ' seconds');
return $profile;
}
/**
* Print the microformatted photo for the user.
*
* @param int $userid ID of user to get profile information for.
* @uses apply_filters() Calls 'extended_profile_photo' after generating the photo markup
* @access private
*/
function extended_profile_photo($userid) {
$userdata = get_userdata($userid);
if (@$userdata->photo && diso_user_is(@$userdata->profile_permissions['photo'])) {
$photo = '';
$photo = apply_filters('extended_profile_photo', $photo, $userdata->ID);
if ($photo) echo $photo . "\n";
}
}
add_action('extended_profile', 'extended_profile_photo', 0);
/**
* Print the microformatted name for the user.
*
* @param int $userid ID of user to get profile information for.
* @uses apply_filters() Calls 'extended_profile_{field}' after generating the
* markup for each of the following individual fields
* (last_name, first_name, additional_name, fn)
* @uses apply_filters() Calls 'extended_profile_{field}' after generating the
* markup for each of the following combined fields
* (n, name)
* @access private
*/
function extended_profile_name($userid) {
$userdata = get_userdata($userid);
// N (individual name components)
$n = '';
if (@$userdata->last_name && diso_user_is(@$userdata->profile_permissions['family-name'])) {
$last_name = '' . $userdata->last_name . '';
$last_name = apply_filters('extended_profile_last_name', $last_name, $userdata->ID);
if ($last_name) $n .= $last_name . ', ';
}
if (@$userdata->first_name && diso_user_is(@$userdata->profile_permissions['given-name'])) {
$first_name = '' . $userdata->first_name . '';
$first_name = apply_filters('extended_profile_first_name', $first_name, $userdata->ID);
if ($first_name) $n .= $first_name . ' ';
}
if (@$userdata->additional_name && diso_user_is(@$userdata->profile_permissions['additional-name'])) {
$additional_name = '' . $userdata->additional_name . '';
$additional_name = apply_filters('extended_profile_additional_name', $additional_name, $userdata->ID);
if ($additional_name) $n .= $additional_name;
}
if ($n) $n = '' . $n . '';
$n = apply_filters('extended_profile_n', $n, $userdata->ID);
// FN (formatted name)
$fn = $userdata->display_name;
if (!@$additional_name) {
// if display_name is equal to the un-marked-up name concatenation, then just use the marked-up concatenation
// checking for the trimmed concatenation covers the use case where the user profile only has one name
if ($fn == trim(strip_tags($first_name . ' ' . $last_name))) {
$fn = trim($first_name . ' ' . $last_name);
$n = '';
} else if ($fn == strip_tags($userdata->last_name . ' ' . $userdata->first_name)) {
$fn = $last_name . ' ' . $first_name;
$n = '';
}
}
$fn = '
' . $fn . '
';
$fn = apply_filters('extended_profile_fn', $fn, $userdata->ID);
$name = '';
if ($fn) $name .= $fn;
if ($n) $name .= $n;
$name = apply_filters('extended_profile_name', $name, $userdata->ID);
if ($name) echo $name . "\n";
}
add_action('extended_profile', 'extended_profile_name', 2);
/**
* Print the microformatted nickname for the user.
*
* @param int $userid ID of user to get profile information for.
* @uses apply_filters() Calls 'extended_profile_nickname' after generating the nickname markup
* @access private
*/
function extended_profile_nickname($userid) {
$userdata = get_userdata($userid);
if (@$userdata->nickname && diso_user_is(@$userdata->profile_permissions['nickname'])) {
$nickname = '' . $userdata->nickname . '';
$nickname = apply_filters('extended_profile_nickname', $nickname, $userdata->ID);
if ($nickname) echo $nickname . "\n";
}
}
add_action('extended_profile', 'extended_profile_nickname', 4);
/**
* Print the microformatted org for the user.
*
* @param int $userid ID of user to get profile information for.
* @uses apply_filters() Calls 'extended_profile_org' after generating the org markup
* @access private
*/
function extended_profile_org($userid) {
$userdata = get_userdata($userid);
if (@$userdata->org && diso_user_is(@$userdata->profile_permissions['org'])) {
$org = '' . $userdata->org . '';
$org = apply_filters('extended_profile_org', $org, $userdata->ID);
if ($org) echo $org . "\n";
}
}
add_action('extended_profile', 'extended_profile_org', 6);
/**
* Print the microformatted note for the user.
*
* @param int $userid ID of user to get profile information for.
* @uses apply_filters() Calls 'extended_profile_note' after generating the note markup
* @access private
*/
function extended_profile_note($userid) {
$userdata = get_userdata($userid);
if (@$userdata->description && diso_user_is(@$userdata->profile_permissions['note'])) {
$note = '
' . $userdata->description . '
';
$note = apply_filters('extended_profile_note', $note, $userdata->ID);
if ($note) echo $note . "\n";
}
}
add_action('extended_profile', 'extended_profile_note', 8);
/**
* Print the microformatted contact information for the user.
*
* @param int $userid ID of user to get profile information for.
* @uses apply_filters() Calls 'extended_profile_{field}' after generating the
* markup for each of the following individual fields
* (urls, aim, yim, jabber, email, tel)
* locality, region, postal_code, country_name
* @uses apply_filters() Calls 'extended_profile_{field}' after generating the
* markup for each of the following combined fields
* (adr, contact)
* @access private
*/
function extended_profile_contact($userid, $actionstream_aware) {
$userdata = get_userdata($userid);
$contact = '';
// URLs
$user_urls = array_merge(array($userdata->user_url), (array) @$userdata->additional_urls);
$user_urls = array_unique(array_filter($user_urls));
if (count($user_urls) && diso_user_is(@$userdata->profile_permissions['urls'])) {
if ($actionstream_aware && function_exists('actionstream_services')) {
$actionstream = actionstream_services($userdata->ID, true);
}
$urls = '';
foreach($user_urls as $url) {
// treat primary website special
if ($url == $userdata->user_url) {
$urls .= '
'."\n";
if (@$userdata->locality && diso_user_is(@$userdata->profile_permissions['locality']))
$adr .= '' . $userdata->locality . ','."\n";
if (@$userdata->region && diso_user_is(@$userdata->profile_permissions['region']))
$adr .= '' . $userdata->region . ''."\n";
if (@$userdata->postal_code && diso_user_is(@$userdata->profile_permissions['postal-code']))
$adr .= '
' . $userdata->postal_code . '
'."\n";
if (@$userdata->country_name && diso_user_is(@$userdata->profile_permissions['country-name']))
$adr .= '
' . $userdata->country_name . '
'."\n";
if ($adr) {
$adr = '
Current Address:
' . $adr . '
';
}
$adr = apply_filters('extended_profile_adr', $adr, $userdata->ID);
if ($adr) $contact .= $adr;
// Finish up
if ($contact) {
$contact = '
Contact Information
' . $contact . '
';
}
$contact = apply_filters('extended_profile_contact', $contact, $userdata->ID);
if ($contact) echo $contact;
}
add_action('extended_profile', 'extended_profile_contact', 10, 2);
/**
* Cleanup URL for display in profile. The URL scheme is hidden, along with
* the preceding 'www.' portion of the hostname if present. If the URL path
* includes only '/', it is hidden.
*
* @param string $url URL to be cleaned up for display
* @return string the cleaned up URL
* @access private
*/
function ext_profile_display_url($url) {
$parts = parse_url($url);
$url = preg_replace('/^www\./', '', $parts['host']);
if ($parts['path'] != '/') $url .= $parts['path'];
return $url;
}
/**
* Provide value of 'country' SREG attribute.
*
* @param string $value current value for attribute
* @param id $user_id ID of user to get attribute for
* @return string new value for attribute
* @access private
*/
function ext_profile_openid_sreg_country($value, $user_id) {
$country = get_usermeta($user_id, 'country_name');
return $country ? $country : $value;
}
add_filter('openid_server_sreg_country', 'ext_profile_openid_sreg_country', 10, 2);
/**
* Provide value of 'postcode' SREG attribute.
*
* @param string $value current value for attribute
* @param id $user_id ID of user to get attribute for
* @return string new value for attribute
* @access private
*/
function ext_profile_openid_sreg_postcode($value, $user_id) {
$postcode = get_usermeta($user_id, 'postal_code');
return $postcode ? $postcode : $value;
}
add_filter('openid_server_sreg_postcode', 'ext_profile_openid_sreg_postcode', 10, 2);
/**
* Migrate old user data for all users.
*
* @access private
*/
function ext_profile_migrate_profile_data() {
$users = get_users_of_blog();
foreach ($users as $user) {
update_usermeta($user->user_id, 'postal_code', get_usermeta($user->user_id, 'postalcode'));
delete_usermeta($user->user_id, 'postalcode');
update_usermeta($user->user_id, 'street_address', get_usermeta($user->user_id, 'streetaddress'));
delete_usermeta($user->user_id, 'streetaddress');
update_usermeta($user->user_id, 'country_name', get_usermeta($user->user_id, 'countryname'));
delete_usermeta($user->user_id, 'countryname');
update_usermeta($user->user_id, 'additional_urls', get_usermeta($user->user_id, 'urls'));
delete_usermeta($user->user_id, 'urls');
$n = get_usermeta($user->user_id, 'n');
update_usermeta($user->user_id, 'additional_name', @$n['additional_name']);
delete_usermeta($user->user_id, 'n');
delete_usermeta($user->user_id, 'fn');
delete_usermeta($user->user_id, 'user_url');
delete_usermeta($user->user_id, 'display_name');
}
}