' . __('Status information:', 'openid') . ' ' . __('All Systems Nominal', 'openid')
. ' (' . __('Toggle More/Less', 'openid') . ')
';
} else {
echo '
' . __('Plugin is currently disabled. Fix the problem, then Deactivate/Reactivate the plugin.', 'openid')
. '
';
}
echo '
';
foreach( $status as $s ) {
list ($name, $state, $message) = $s;
echo '
';
if( $state === false ) {
echo "[".__('FAIL', 'openid')."] $name";
} elseif( $state === true ) {
echo "[".__('OK', 'openid')."] $name";
} else {
echo "[".__('INFO', 'openid')."] $name";
}
echo ($message ? ': ' : '') . '';
echo (is_array($message) ? '
- ' . implode('
- ', $message) . '
' : $message);
echo '
';
}
echo '
';
}
/**
* Handle OpenID profile management.
*/
function openid_profile_management() {
global $wp_version;
if( !isset( $_REQUEST['action'] )) return;
switch( $_REQUEST['action'] ) {
case 'verify':
finish_openid($_REQUEST['action']);
break;
case 'add':
check_admin_referer('openid-add_openid');
$user = wp_get_current_user();
$auth_request = openid_begin_consumer($_POST['openid_identifier']);
$userid = get_user_by_openid($auth_request->endpoint->claimed_id);
if ($userid) {
global $error;
if ($user->ID == $userid) {
$error = __('You already have this OpenID!', 'openid');
} else {
$error = __('This OpenID is already associated with another user.', 'openid');
}
return;
}
$return_to = admin_url(current_user_can('edit_users') ? 'users.php' : 'profile.php');
openid_start_login($_POST['openid_identifier'], 'verify', array('page' => $_REQUEST['page']), $return_to);
break;
case 'delete':
openid_profile_delete_openids($_REQUEST['delete']);
break;
}
}
/**
* Remove identity URL from current user account.
*
* @param int $id id of identity URL to remove
*/
function openid_profile_delete_openids($delete) {
if (empty($delete) || $_REQUEST['cancel']) return;
check_admin_referer('openid-delete_openids');
$user = wp_get_current_user();
$urls = get_user_openids($user->ID);
if (sizeof($urls) == sizeof($delete) && !$_REQUEST['confirm']) {
$html = '
'.__('OpenID Warning', 'openid').'
';
openid_page($html, __('OpenID Warning', 'openid'));
return;
}
$count = 0;
foreach ($urls as $url) {
if (in_array(md5($url), $_REQUEST['delete'])) {
if (openid_drop_identity($user->ID, $url)) {
$count++;
}
}
}
if ($count) {
openid_message(sprintf(__('Deleted %1$s OpenID association%2$s.', 'openid'), $count, ($count>1 ? 's' : '')));
openid_status('success');
// ensure that profile URL is still a verified OpenID
set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
require_once 'Auth/OpenID.php';
@include_once(ABSPATH . WPINC . '/registration.php'); // WP < 2.3
@include_once(ABSPATH . 'wp-admin/includes/admin.php'); // WP >= 2.3
if (!openid_ensure_url_match($user)) {
$identities = get_user_openids($user->ID);
wp_update_user( array('ID' => $user->ID, 'user_url' => $identities[0]) );
openid_message(openid_message() . '
'.__('
Note: For security reasons, your profile URL has been updated to match your OpenID.', 'openid'));
}
return;
}
openid_message(__('OpenID association delete failed: Unknown reason.', 'openid'));
openid_status('error');
}
/**
* Action method for completing the 'verify' action. This action is used adding an identity URL to a
* WordPress user through the admin interface.
*
* @param string $identity_url verified OpenID URL
*/
function openid_finish_verify($identity_url) {
if ($_REQUEST['action'] != 'verify') return;
$user = wp_get_current_user();
if (empty($identity_url)) {
$message = openid_message();
if (empty($message)) openid_message('Unable to authenticate OpenID.');
} else {
if( !openid_add_identity($user->ID, $identity_url) ) {
openid_message(__('OpenID assertion successful, but this URL is already associated with '
. 'another user on this blog. This is probably a bug.', 'openid'));
} else {
openid_message(sprintf(__('Added association with OpenID: %s', 'openid'), openid_display_identity($identity_url) ));
openid_status('success');
// ensure that profile URL is a verified OpenID
set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
require_once 'Auth/OpenID.php';
if ($GLOBALS['wp_version'] >= '2.3') {
require_once(ABSPATH . 'wp-admin/includes/admin.php');
} else {
require_once(ABSPATH . WPINC . '/registration.php');
}
if (!openid_ensure_url_match($user)) {
wp_update_user( array('ID' => $user->ID, 'user_url' => $identity_url) );
openid_message(openid_message() . '
'.__('
Note: For security reasons, your profile URL has been updated to match your OpenID.', 'openid'));
}
}
}
return;
}
/**
* Prior to WordPress 2.5, the 'personal_options_update' hook was called
* AFTER updating the user's profile. We need to ensure the profile URL
* matches before then.
*/
function openid_compat_pre_user_url($url) {
if ($_POST['from'] == 'profile') {
openid_personal_options_update();
}
return $url;
}
/**
* hook in and call when user is updating their profile URL... make sure it is an OpenID they control.
*/
function openid_personal_options_update() {
$user = wp_get_current_user();
if (!openid_ensure_url_match($user, $_POST['url'])) {
wp_die(sprintf(__('For security reasons, your profile URL must be one of your claimed OpenIDs: %s'),
'
- ' . join('
- ', get_user_openids($user->ID)) . '
'));
}
}
/**
* Ensure that the user's profile URL matches one of their OpenIDs
*/
function openid_ensure_url_match($user, $url = null) {
$identities = get_user_openids($user->ID);
if (empty($identities)) return true;
set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
require_once 'Auth/OpenID.php';
if ($url == null) $url = $user->user_url;
$url = Auth_OpenID::normalizeUrl($url);
foreach ($identities as $id) {
if ($id == $url) return true;
}
return false;
}
function openid_admin_return_url($urls) {
$urls[] = admin_url('users.php');
$urls[] = admin_url('profile.php');
return $urls;
}
function openid_extend_profile() {
$user = wp_get_current_user();
echo '
';
}
function openid_profile_update($user_id) {
if (empty($_POST['openid_delegate'])) {
delete_usermeta($user_id, 'openid_delegate');
} else {
$old_delegate = get_usermeta($user_id, 'openid_delegate');
$delegate = Auth_OpenID::normalizeUrl($_POST['openid_delegate']);
if(openid_server_update_delegation_info($user_id, $delegate)) {
openid_message(sprintf(__('Gathered OpenID information for delegate URL %s', 'openid'), '
'.$delegate.''));
openid_status('success');
} else {
openid_message(sprintf(__('Unable to find any OpenID information for delegate URL %s', 'openid'), '
'.$delegate.''));
openid_status('error');
}
}
}
?>