'.__('The WordPress OpenID plugin is not active.', 'openid').'';
printf(_('Check %sOpenID Options%s for a full diagnositic report.', 'openid'), '', '');
echo '
';
}
/**
* Setup admin menus for OpenID options and ID management.
*
* @action: admin_menu
**/
function openid_admin_panels() {
// global options page
$hookname = add_options_page(__('OpenID options', 'openid'), __('OpenID', 'openid'), 8, 'openid', 'openid_options_page' );
if (function_exists('add_thickbox')) {
add_action("load-$hookname", create_function('', 'add_thickbox();'));
} else {
add_action("load-$hookname", 'openid_js_setup' );
}
add_action("admin_head-$hookname", 'openid_style' );
add_filter('plugin_action_links', 'openid_plugin_action_links', 10, 2);
// all users can setup external OpenIDs
$hookname = add_users_page(__('Your OpenIDs', 'openid'), __('Your OpenIDs', 'openid'),
'read', 'your_openids', 'openid_profile_panel' );
add_action("admin_head-$hookname", 'openid_style' );
add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");'));
add_action("load-$hookname", 'openid_profile_management' );
// additional options for users authorized to use OpenID provider
$user = wp_get_current_user();
if ($user->has_cap('use_openid_provider')) {
add_action('show_user_profile', 'openid_extend_profile', 5);
add_action('profile_update', 'openid_profile_update');
add_action('admin_head-profile.php', 'openid_style');
if (!get_usermeta($user->ID, 'openid_delegate')) {
$hookname = add_submenu_page('profile.php', __('Your Trusted Sites', 'openid'),
__('Your Trusted Sites', 'openid'), 'read', 'openid_trusted_sites', 'openid_manage_trusted_sites' );
add_action("admin_head-$hookname", 'openid_style' );
add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");'));
}
}
}
/**
* Intercept the call to set the openid_cap option. Instead of storing
* this in the options table, set the capability on the appropriate roles.
*/
function openid_set_cap($newvalue, $oldvalue) {
global $wp_roles;
foreach ($wp_roles->role_names as $key => $name) {
$role = $wp_roles->get_role($key);
$option_set = $newvalue[htmlentities($key)] == 'on' ? true : false;
if ($role->has_cap('use_openid_provider')) {
if (!$option_set) $role->remove_cap('use_openid_provider');
} else {
if ($option_set) $role->add_cap('use_openid_provider');
}
}
return $oldvalue;
}
/**
* Add settings link to plugin page.
*/
function openid_plugin_action_links($links, $file) {
$this_plugin = openid_plugin_file();
if($file == $this_plugin) {
$links[] = '' . __('Settings') . '';
}
return $links;
}
/*
* Display and handle updates from the Admin screen options page.
*
* @options_page
*/
function openid_options_page() {
global $wp_version, $wpdb, $wp_roles;
if ( isset($_REQUEST['action']) ) {
switch($_REQUEST['action']) {
case 'rebuild_tables' :
check_admin_referer('rebuild_tables');
$store = openid_getStore();
$store->reset();
echo '
'.__('OpenID cache refreshed.', 'openid').'
';
break;
}
}
$openid_options = array(
'openid_enable_commentform',
'openid_enable_approval',
'openid_no_require_name',
'openid_enable_email_mapping',
'openid_required_for_registration',
'openid_blog_owner',
'openid_cap',
);
// Display the options page form
if (function_exists('screen_icon')):
screen_icon('openid');
?>
'.__('Success:', 'openid').' '.openid_message().'
';
}
elseif( 'warning' == $status ) {
echo '
'.__('Warning:', 'openid').' '.openid_message().'
';
}
elseif( 'error' == $status ) {
echo '
'.__('Error:', 'openid').' '.openid_message().'
';
}
if (!empty($error)) {
echo '
'.__('Error:', 'openid').' '.$error.'
';
unset($error);
}
if (function_exists('screen_icon')):
screen_icon('openid');
?>
';
echo '
';
}
/**
* Handle OpenID profile management.
*/
function openid_profile_management() {
global $wp_version;
switch( $_REQUEST['action'] ) {
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;
}
$finish_url = admin_url(current_user_can('edit_users') ? 'users.php' : 'profile.php');
$finish_url = add_query_arg('page', $_REQUEST['page'], $finish_url);
openid_start_login($_POST['openid_identifier'], 'verify', $finish_url);
break;
case 'delete':
openid_profile_delete_openids($_REQUEST['delete']);
break;
default:
if ($message = $_REQUEST['message']) {
$messages = array(
'',
'Unable to authenticate OpenID.',
'OpenID assertion successful, but this URL is already associated with another user on this blog. This is probably a bug.',
'Added association with OpenID.',
);
if (is_numeric($message)) {
$message = $messages[$message];
}
$message = __($message, 'openid');
if ($_REQUEST['update_url']) {
$message .= ' ' . __('Note: For security reasons, your profile URL has been updated to match your OpenID.', 'openid');
}
openid_message($message);
openid_status($_REQUEST['status']);
}
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(__ngettext('Deleted %d OpenID association.', 'Deleted %d OpenID associations.', $count, 'openid'), $count) );
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, $action) {
if ($action != 'verify') return;
$message;
$user = wp_get_current_user();
if (empty($identity_url)) {
$message = openid_message();
if (empty($message)) $message = 1;
} else {
if( !openid_add_identity($user->ID, $identity_url) ) {
$message = 2;
} else {
$message = 3;
// 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) );
$update_url = 1;
}
}
}
$finish_url = $_SESSION['openid_finish_url'];
$finish_url = add_query_arg('status', openid_status(), $finish_url);
$finish_url = add_query_arg('message', $message, $finish_url);
if ($update_url) {
$finish_url = add_query_arg('update_url', $update_url, $finish_url);
}
wp_safe_redirect($finish_url);
exit;
}
/**
* 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', 'openid'),
'
' . 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) {
$id = Auth_OpenID::normalizeUrl($id);
if ($id == $url) return true;
}
return false;
}
function openid_extend_profile() {
$user = wp_get_current_user();
echo '
'.__('OpenID Delegation allows you to use an external OpenID provider of your choice.', 'openid').'
To delegate, enter a valid OpenID. Otherwise leave this blank.
';
}
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');
}
}
}
?>