getByString('hcard', $page);
if(count($hcard['preferred'])) {
$phcard = $hcard['preferred'][0];
} else {
if($hcard['all']) {
foreach($hcard['all'] as $card) {
if($card['uid'] == $userdata->user_url) { $phcard = $card; break; }
if(!is_array($card['url']) && $card['url'] == $url) { $phcard = $card; break; }
if(is_array($card['url']) && in_array($url,$card['url'])) { $phcard = $card; break; }
}//end foreach all
if(!$phcard) $phcard = $hcard['all'][0];
}//end if hcard all
}//end if-else preferred
return array('hcard' => $phcard, 'xml' => $hcard['xml']);
}//end function diso_profile_hcard_from_url
function diso_profile_hcard_import($userid,$override=false) {
$userdata = get_userdata($userid);
//GET HCARD
$data = diso_profile_hcard_from_url($userdata->user_url);
if((!$data['hcard'] || !count($data['hcard'])) && $data['xml']) {//if no hcard, follow rel=me
$relme = $data['xml']->xpath("//*[contains(concat(' ',normalize-space(@rel),' '),' me ')]");
foreach($relme as $tag) {
if(substr($tag['href'],0,4) != 'http') {
$domain = explode('/',$url);
$domain = $domain[2];
if(substr($tag['href'],0,1) == '/')
$tag['href'] = 'http://'.$domain.$tag['href'];
else
$tag['href'] = dirname($url).'/'.$tag['href'];
}//end if not http
$data = diso_profile_hcard_from_url($tag['href']);
if($data['hcard'] && count($data['hcard'])) break;
}//end foreach
}//end if ! hcard
$phcard = $data['hcard'];
if(substr($phcard['photo'],0,3) == '://') {//photo relative URL
$photo = substr($phcard['photo'],3);
$domain = explode('/',$userdata->user_url);
$domain = $domain[2];
if($photo{0} == '/')
$photo = 'http://'.$domain.$photo;
else
$photo = dirname($userdata->user_url).'/'.$photo;
$phcard['photo'] = $photo;
}//end if photo{0-3} == ://
//IMPORT INTO PROFILE
/* MAP KNOWN VALUES */
if(!is_array($phcard['n'])) $phcard['n'] = array();
if($phcard['fn']) update_usermeta($userid, 'display_name', $phcard['fn']);
if($phcard['nickname']) update_usermeta($userid, 'nickname', $phcard['nickname']);
if(($override || !$userdata->first_name) && $phcard['n']['given-name']) update_usermeta($userid, 'first_name', $phcard['n']['given-name']);
if(($override || !$userdata->additional_name) && $phcard['n']['additional-name']) update_usermeta($userid, 'additional_name', $phcard['n']['additional-name']);
if(($override || !$userdata->last_name) && $phcard['n']['family-name']) update_usermeta($userid, 'last_name', $phcard['n']['family-name']);
if(($override || !$userdata->description) && $phcard['note']) update_usermeta($userid, 'description', $phcard['note']);
if(($override || !$userdata->user_email) && $phcard['email']) update_usermeta($userid, 'user_email', $phcard['email']);
/* MAP ALL OTHER HCARD VALUES TO THEMSELVES */
$phcard['urls'] = $phcard['url']; unset($phcard['url']);
foreach($phcard as $key => $val)
if($key && $val && ($override || !$userdata->$key)) update_usermeta($userid, $key, $val);
}//end function diso_profile_hcard_import
add_action('user_register', 'diso_profile_hcard_import');
function diso_profile_extend() {
global $profileuser;
$userdata = $profileuser;
//PHOTO
echo '
Photo
';
echo '';
//ORGANIZATION AND ADDRESS
$fieldset = array(
'Miscellaneous' => array(
'org' => 'Organization',
),
'Address' => array(
'streetaddress' => 'Street Address',
'locality' => 'City',
'region' => 'Province/State',
'postalcode' => 'Postal Code',
'countryname' => 'Country',
'tel' => 'Telephone Number',
),
);
foreach($fieldset as $legend => $fields) {
echo ''.$legend.'
';
echo '';
}//end foreach fieldset
?>
Profile Preview
This is how your profile looks to people allowed to see all the information.
Preview Profile
Import hCard';
}//end finction diso_profile_extend_top
add_action('profile_personal_options', 'diso_profile_extend_top');
function diso_profile_extend_save($userid) {
if($_POST['do_manual_hcard']) {
diso_profile_hcard_import($userid, true);
} else {
$userdata = get_userdata($userid);
$n = $userdata->n ? $userdata->n : array();
$n['given-name'] = $_POST['first_name'];
$n['additional-name'] = $_POST['additional-name'];
$n['family-name'] = $_POST['last_name'];
update_usermeta($userdata->ID, 'n', $n);
$urls = preg_split('/[\s]+/',$_POST['urls']);
update_usermeta($userdata->ID, 'urls', $urls);
if (is_array($_POST['hcard'])) {
foreach($_POST['hcard'] as $key => $val)
update_usermeta($userdata->ID, $key, $val);
}
update_usermeta($userdata->ID, 'user_url', $_POST['url']);
update_usermeta($userdata->ID, 'display_name', $_POST['display_name']);
}
}//end function diso_profile_extend_save
add_action('profile_update', 'diso_profile_extend_save');
function diso_profile($userid='', $echo=true, $actionstream_aware=false) {
// ensure plugin doesn't break in the absence of the permissions plugin
if (!function_exists('diso_user_is')) { function diso_user_is() { return true; } }
$time = microtime(true);
if(!$userid) {//get administrator
global $wpdb;
$userid = $wpdb->get_var("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='wp_user_level' AND meta_value='10'");
}//end if ! userid
if(is_numeric($userid))
$userdata = get_userdata($userid);
else
$userdata = get_userdatabylogin($userid);
$template = '';
if($userdata->photo && diso_user_is($userdata->profile_permissions['photo'])) $template .= '
.')
'."\n";
$template .= '
'.htmlentities($userdata->display_name).'
';
if( $userdata->first_name || $userdata->additional-name || $userdata->last_name ) {
if($userdata->user_url)
$template .= '
';
else
$template .= '';
if($userdata->last_name && diso_user_is($userdata->profile_permissions['family-name'])) $template .= ''.htmlentities($userdata->last_name).','."\n";
if($userdata->first_name && diso_user_is($userdata->profile_permissions['given-name'])) $template .= ''.htmlentities($userdata->first_name).''."\n";
if($userdata->n['additional-name'] && diso_user_is($userdata->profile_permissions['additional-name'])) $template .= ''.htmlentities($userdata->n['additional-name']).''."\n";
if($userdata->user_url)
$template .= '';
else
$template .= '';
}//end if name
if($userdata->nickname && diso_user_is($userdata->profile_permissions['nickname'])) $template .= '"
'.htmlentities($userdata->nickname).'"'."\n";
if($userdata->org && diso_user_is($userdata->profile_permissions['org'])) $template .= '(
'.htmlentities($userdata->org).')'."\n";
if($userdata->description && diso_user_is($userdata->profile_permissions['note'])) $template .= '
'.htmlentities($userdata->description).'
'."\n";
$template .= '
Contact Information
';
$template .= '
';
if(!count($userdata->urls)) $userdata->urls = array($userdata->user_url);
if(count($userdata->urls) && diso_user_is($userdata->profile_permissions['urls'])) {
$template .= '- On the web:
-
'."\n";
}//end if urls
if($userdata->aim && diso_user_is($userdata->profile_permissions['aim'])) $template .= '- AIM:
- '.htmlentities($userdata->aim).'
'."\n";
if($userdata->yim && diso_user_is($userdata->profile_permissions['yim'])) $template .= '- Y!IM:
- '.htmlentities($userdata->yim).'
'."\n";
if($userdata->jabber && diso_user_is($userdata->profile_permissions['jabber'])) $template .= '- Jabber:
- '.htmlentities($userdata->jabber).'
'."\n";
if($userdata->user_email && diso_user_is($userdata->profile_permissions['email'])) $template .= '- Email:
- '.htmlentities($userdata->user_email).'
'."\n";
if($userdata->tel && diso_user_is($userdata->profile_permissions['tel'])) $template .= '- Telephone:
- '.htmlentities($userdata->tel).'
'."\n";
if( ($userdata->streetaddress || $userdata->locality || $userdata->region || $userdata->postalcode || $userdata->countryname) &&
(diso_user_is($userdata->profile_permissions['street-address']) || diso_user_is($userdata->profile_permissions['locality']) || diso_user_is($userdata->profile_permissions['region']) || diso_user_is($userdata->profile_permissions['postal-code']) || diso_user_is($userdata->profile_permissions['country-name']) ) ) {
$template .= '- Current Address:
- ';
if($userdata->streetaddress && diso_user_is($userdata->profile_permissions['street-address'])) $template .= '
'.htmlentities($userdata->streetaddress).'
'."\n";
if($userdata->locality && diso_user_is($userdata->profile_permissions['locality'])) $template .= ''.htmlentities($userdata->locality).','."\n";
if($userdata->region && diso_user_is($userdata->profile_permissions['region'])) $template .= ''.htmlentities($userdata->region).''."\n";
if($userdata->postalcode && diso_user_is($userdata->profile_permissions['postal-code'])) $template .= ''.htmlentities($userdata->postalcode).'
'."\n";
if($userdata->countryname && diso_user_is($userdata->profile_permissions['country-name'])) $template .= ''.htmlentities($userdata->countryname).'
'."\n";
$template .= ' ';
}//end if adr
$template .= '
';
$template .= '
';
if($echo) {echo $template; echo '';}
return $template;
}//end function diso_profile
function diso_profile_plugin_url() {
if (function_exists('plugins_url')) {
return plugins_url('wp-diso-profile');
} else {
return get_bloginfo('wpurl') . PLUGINDIR . '/wp-diso-profile';
}
}
function diso_profile_head() {
echo ' '."\n";
}//end function diso_profile_head
add_action('wp_head', 'diso_profile_head');
add_action('admin_head-profile.php', 'diso_profile_head');
add_action('admin_head-user-edit.php', 'diso_profile_head');
function diso_profile_load() {
add_thickbox();
wp_enqueue_script('diso-profile', diso_profile_plugin_url() . '/profile_preview.js', array('thickbox'));
}
add_action('load-profile.php', 'diso_profile_load');
add_action('load-user-edit.php', 'diso_profile_load');
function diso_profile_parse_page_token($content) {
if(preg_match('//',$content,$matches)) {
$parameter1 = $matches[1];
$content = preg_replace('//',diso_profile($parameter1,false), $content);
}//end if match
return $content;
}//end function diso_profile_parse_page_token
add_filter('the_content', 'diso_profile_parse_page_token');
// Extend WordPress OpenID plugin's SREG functions
function diso_profile_openid_sreg_country($value, $user_id) {
$country = get_usermeta($user_id, 'countryname');
return $country ? $country : $value;
}
add_filter('openid_server_sreg_country', 'diso_profile_openid_sreg_country', 10, 2);
function diso_profile_openid_sreg_postcode($value, $user_id) {
$postcode = get_usermeta($user_id, 'postalcode');
return $postcode ? $postcode : $value;
}
add_filter('openid_server_sreg_postcode', 'diso_profile_openid_sreg_postcode', 10, 2);
?>