Changeset 158694
- Timestamp:
- 09/28/2009 07:34:45 PM (16 years ago)
- Location:
- openid/trunk
- Files:
-
- 2 added
- 2 deleted
- 18 edited
-
Auth/OpenID/BigMath.php (modified) (1 diff)
-
Auth/OpenID/Consumer.php (modified) (4 diffs)
-
Auth/OpenID/Message.php (modified) (1 diff)
-
Auth/OpenID/Server.php (modified) (2 diffs)
-
admin_panels.php (modified) (24 diffs)
-
comments.php (modified) (11 diffs)
-
common.php (modified) (24 diffs)
-
consumer.php (added)
-
f/ajax-loader.gif (added)
-
f/openid.css (modified) (3 diffs)
-
f/openid.js (modified) (2 diffs)
-
login.php (modified) (9 diffs)
-
openid.php (modified) (11 diffs)
-
screenshot-1.png (modified) (previous)
-
screenshot-3.png (modified) (previous)
-
screenshot-4.png (modified) (previous)
-
screenshot-5.png (modified) (previous)
-
screenshot-6.png (deleted)
-
screenshot-7.png (deleted)
-
server.php (modified) (12 diffs)
-
server_ext.php (modified) (4 diffs)
-
store.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
openid/trunk/Auth/OpenID/BigMath.php
r67133 r158694 375 375 376 376 // Try to load dynamic modules. 377 if (!$loaded ) {377 if (!$loaded && function_exists('dl')) { 378 378 foreach ($extension['modules'] as $module) { 379 379 if (@dl($module . "." . PHP_SHLIB_SUFFIX)) { -
openid/trunk/Auth/OpenID/Consumer.php
r67133 r158694 269 269 270 270 if ($consumer_cls !== null) { 271 $this->consumer = &new $consumer_cls($store);271 $this->consumer = new $consumer_cls($store); 272 272 } else { 273 $this->consumer = &new Auth_OpenID_GenericConsumer($store);273 $this->consumer = new Auth_OpenID_GenericConsumer($store); 274 274 } 275 275 … … 667 667 668 668 return call_user_func_array(array(&$this, $method), 669 array($message, $endpoint, $return_to));669 array($message, &$endpoint, $return_to)); 670 670 } 671 671 … … 1182 1182 list($unused, $services) = call_user_func($this->discoverMethod, 1183 1183 $claimed_id, 1184 $this->fetcher);1184 &$this->fetcher); 1185 1185 1186 1186 if (!$services) { … … 1296 1296 array('response_nonce', 1297 1297 'claimed_id', 1298 'assoc_handle')), 1298 'assoc_handle', 1299 'op_endpoint')), 1299 1300 Auth_OpenID_OPENID1_NS => array_merge($basic_sig_fields, 1300 1301 array('nonce')) -
openid/trunk/Auth/OpenID/Message.php
r67133 r158694 888 888 function getAliasedArg($aliased_key, $default = null) 889 889 { 890 if ($aliased_key == 'ns') { 891 // Return the namespace URI for the OpenID namespace 892 return $this->getOpenIDNamespace(); 893 } 894 890 895 $parts = explode('.', $aliased_key, 2); 891 896 -
openid/trunk/Auth/OpenID/Server.php
r67133 r158694 1098 1098 } 1099 1099 1100 $setup_request = &new Auth_OpenID_CheckIDRequest(1100 $setup_request = new Auth_OpenID_CheckIDRequest( 1101 1101 $this->identity, 1102 1102 $this->return_to, … … 1678 1678 { 1679 1679 $this->store =& $store; 1680 $this->signatory = &new Auth_OpenID_Signatory($this->store);1681 $this->encoder = &new Auth_OpenID_SigningEncoder($this->signatory);1682 $this->decoder = &new Auth_OpenID_Decoder($this);1680 $this->signatory = new Auth_OpenID_Signatory($this->store); 1681 $this->encoder = new Auth_OpenID_SigningEncoder($this->signatory); 1682 $this->decoder = new Auth_OpenID_Decoder($this); 1683 1683 $this->op_endpoint = $op_endpoint; 1684 1684 $this->negotiator =& Auth_OpenID_getDefaultNegotiator(); -
openid/trunk/admin_panels.php
r103625 r158694 1 1 <?php 2 2 /** 3 * All the code required for handling OpenID comments. These functions should not be considered public,3 * All the code required for handling OpenID administration. These functions should not be considered public, 4 4 * and may change without notice. 5 5 */ … … 7 7 8 8 // -- WordPress Hooks 9 add_action( 'admin_init', 'openid_admin_register_settings' ); 9 10 add_action( 'admin_menu', 'openid_admin_panels' ); 10 11 add_action( 'personal_options_update', 'openid_personal_options_update' ); 11 12 add_action( 'openid_finish_auth', 'openid_finish_verify', 10, 2 ); 12 13 add_filter( 'pre_update_option_openid_cap', 'openid_set_cap', 10, 2); 13 14 if (version_compare($wp_version, '2.5', '<')) {15 add_filter('pre_user_url', 'openid_compat_pre_user_url');16 }17 18 19 20 /**21 * Spam up the admin interface with warnings.22 **/23 function openid_admin_notices_plugin_problem_warning() {24 echo'<div class="error"><p><strong>'.__('The WordPress OpenID plugin is not active.', 'openid').'</strong>';25 printf(_('Check %sOpenID Options%s for a full diagnositic report.', 'openid'), '<a href="options-general.php?page=openid">', '</a>');26 echo '</p></div>';27 }28 14 29 15 … … 34 20 **/ 35 21 function openid_admin_panels() { 22 add_filter('plugin_action_links', 'openid_plugin_action_links', 10, 2); 23 36 24 // global options page 37 25 $hookname = add_options_page(__('OpenID options', 'openid'), __('OpenID', 'openid'), 8, 'openid', 'openid_options_page' ); 38 if (function_exists('add_thickbox')) { 39 add_action("load-$hookname", create_function('', 'add_thickbox();')); 40 } else { 41 add_action("load-$hookname", 'openid_js_setup' ); 42 } 43 add_action("admin_head-$hookname", 'openid_style' ); 44 add_filter('plugin_action_links', 'openid_plugin_action_links', 10, 2); 26 add_action("load-$hookname", create_function('', 'add_thickbox();')); 27 add_action("load-$hookname", 'openid_style'); 45 28 46 29 // all users can setup external OpenIDs 47 $hookname = add_users_page(__('Your OpenIDs', 'openid'), __('Your OpenIDs', 'openid'), 48 'read', 'your_openids', 'openid_profile_panel' ); 49 add_action("admin_head-$hookname", 'openid_style' ); 30 $hookname = add_users_page(__('Your OpenIDs', 'openid'), __('Your OpenIDs', 'openid'), 'read', 'your_openids', 'openid_profile_panel' ); 50 31 add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");')); 51 32 add_action("load-$hookname", 'openid_profile_management' ); 33 add_action("load-$hookname", 'openid_style' ); 52 34 53 35 // additional options for users authorized to use OpenID provider … … 56 38 add_action('show_user_profile', 'openid_extend_profile', 5); 57 39 add_action('profile_update', 'openid_profile_update'); 58 add_action('admin_head-profile.php', 'openid_style'); 40 add_action('user_profile_update_errors', 'openid_profile_update_errors', 10, 3); 41 add_action('load-profile.php', 'openid_style'); 59 42 60 43 if (!get_usermeta($user->ID, 'openid_delegate')) { 61 44 $hookname = add_submenu_page('profile.php', __('Your Trusted Sites', 'openid'), 62 45 __('Your Trusted Sites', 'openid'), 'read', 'openid_trusted_sites', 'openid_manage_trusted_sites' ); 63 add_action(" admin_head-$hookname", 'openid_style' );46 add_action("load-$hookname", 'openid_style' ); 64 47 add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");')); 65 48 } 66 49 } 50 51 if ( function_exists('is_site_admin') ) { 52 // add OpenID options to WPMU Site Admin page 53 add_action('wpmu_options', 'openid_wpmu_options'); 54 add_action('update_wpmu_options', 'openid_update_wpmu_options'); 55 } else { 56 // add OpenID options to General Settings page 57 add_settings_field('openid_general_settings', 'OpenID Settings', 'openid_general_settings', 'general', 'default'); 58 } 59 60 // add OpenID options to Discussion Settings page 61 add_settings_field('openid_disucssion_settings', 'OpenID Settings', 'openid_discussion_settings', 'discussion', 'default'); 62 } 63 64 65 /** 66 * Register OpenID admin settings. 67 */ 68 function openid_admin_register_settings() { 69 register_setting('general', 'openid_required_for_registration'); 70 71 register_setting('discussion', 'openid_no_require_name'); 72 register_setting('discussion', 'openid_enable_approval'); 73 register_setting('discussion', 'openid_enable_commentform'); 74 75 register_setting('openid', 'openid_blog_owner'); 76 register_setting('openid', 'openid_cap'); 67 77 } 68 78 … … 77 87 foreach ($wp_roles->role_names as $key => $name) { 78 88 $role = $wp_roles->get_role($key); 79 $option_set = $newvalue[htmlentities($key)] == 'on' ? true : false; 89 if (array_key_exists($key, $newvalue) && $newvalue[$key] == 'on') { 90 $option_set = true; 91 } else { 92 $option_set = false; 93 } 80 94 if ($role->has_cap('use_openid_provider')) { 81 95 if (!$option_set) $role->remove_cap('use_openid_provider'); … … 109 123 */ 110 124 function openid_options_page() { 111 global $wp _version, $wpdb, $wp_roles;125 global $wpdb, $wp_roles; 112 126 113 127 if ( isset($_REQUEST['action']) ) { … … 122 136 } 123 137 124 $openid_options = array(125 'openid_enable_commentform',126 'openid_enable_approval',127 'openid_no_require_name',128 'openid_enable_email_mapping',129 'openid_required_for_registration',130 'openid_blog_owner',131 'openid_cap',132 );133 134 138 // Display the options page form 135 139 136 if (function_exists('screen_icon')): 137 screen_icon('openid'); 140 screen_icon('openid'); 138 141 ?> 139 142 <style type="text/css"> 140 143 #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); } 141 144 </style> 142 <?php endif; ?>143 145 144 146 <div class="wrap"> 145 147 <form method="post" action="options.php"> 146 148 147 <h2><?php _e('OpenID Consumer Options', 'openid') ?></h2> 148 149 <?php if ($wp_version < '2.3') { ?> 150 <p class="submit"><input type="submit" class="button-primary" name="info_update" value="<?php _e('Save Changes') ?>" /></p> 151 <?php } ?> 152 153 <table class="form-table optiontable editform"> 154 <tr valign="top"> 155 <th scope="row"><?php _e('Comment Approval', 'openid') ?></th> 156 <td> 157 <p><input type="checkbox" name="openid_enable_approval" id="openid_enable_approval" <?php 158 echo get_option('openid_enable_approval') ? 'checked="checked"' : ''; ?> /> 159 <label for="openid_enable_approval"><?php _e('Automatically approve comments left with verified OpenIDs. ' 160 . 'These comments will bypass all comment moderation.', 'openid'); ?></label> 161 </p> 162 163 <?php if (get_option('require_name_email')) { ?> 164 <p><input type="checkbox" name="openid_no_require_name" id="openid_no_require_name" <?php 165 echo get_option('openid_no_require_name') ? 'checked="checked"' : ''; ?> /> 166 <label for="openid_no_require_name"><?php _e('Don\'t require name and e-mail for comments left with verified OpenIDs.', 'openid') ?></label> 167 </p> 168 <?php } ?> 169 170 </td> 171 </tr> 172 173 <tr valign="top"> 174 <th scope="row"><?php _e('Comment Form', 'openid') ?></th> 175 <td> 176 <p><input type="checkbox" name="openid_enable_commentform" id="openid_enable_commentform" <?php 177 if( get_option('openid_enable_commentform') ) echo 'checked="checked"' 178 ?> /> 179 <label for="openid_enable_commentform"><?php _e('Add OpenID help text to the comment form.', 'openid') ?></label></p> 180 181 <p><?php printf(__('This will work for most themes derived from Kubrick or Sandbox. ' 182 . 'Template authors can tweak the comment form as described in the %sreadme%s.', 'openid'), 183 '<a href="'.clean_url(openid_plugin_url().'/readme.txt').'">', '</a>') ?></p> 184 </td> 185 </tr> 186 187 <?php if (get_option('users_can_register')): ?> 188 <tr valign="top"> 189 <th scope="row"><?php _e('Require OpenID', 'openid') ?></th> 190 <td> 191 <p><input type="checkbox" name="openid_required_for_registration" id="openid_required_for_registration" <?php 192 if( get_option('openid_required_for_registration') ) echo 'checked="checked"' 193 ?> /> 194 <label for="openid_required_for_registration"><?php _e('New accounts can only be created with verified OpenIDs.', 'openid') ?></label></p> 195 </td> 196 </tr> 197 <?php endif; ?> 198 199 <?php /* 200 <tr valign="top"> 201 <th scope="row"><?php _e('Email Mapping:', 'openid') ?></th> 202 <td> 203 <p><input type="checkbox" name="enable_email_mapping" id="enable_email_mapping" <?php 204 if( get_option('openid_enable_email_mapping') ) echo 'checked="checked"' 205 ?> /> 206 <label for="enable_email_mapping"><?php _e('Enable email addresses to be mapped to OpenID URLs.', 'openid') ?></label></p> 207 208 <p><?php printf(__('This feature uses the Email-To-URL mapping specification to allow OpenID authentication' 209 . ' based on an email address. If enabled, commentors who do not supply a valid OpenID URL will have their' 210 . ' supplied email address mapped to an OpenID. If their email provider does not currently support email to' 211 . ' url mapping, the default provider %s will be used.', 'openid'), '<a href="http://emailtoid.net/" target="_blank">Emailtoid.net</a>') ?></p> 212 <br /> 213 </td> 214 </tr> 215 */ ?> 216 217 <tr valign="top"> 218 <th scope="row"><?php _e('Troubleshooting', 'openid') ?></th> 219 <td> 220 <?php openid_printSystemStatus(); ?> 221 222 <p><?php printf(__('If users are experiencing problems logging in with OpenID, it may help to %1$srefresh the cache%2$s.', 'openid'), 223 '<a href="' . wp_nonce_url(add_query_arg('action', 'rebuild_tables'), 'rebuild_tables') . '">', '</a>'); ?></p> 224 </td> 225 </tr> 226 227 </table> 228 229 <br class="clear" /> 230 231 232 <h2><?php _e('OpenID Provider Options', 'openid') ?></h2> 149 <h2><?php _e('OpenID Settings', 'openid') ?></h2> 150 151 <div class="updated fade"><p>Please note that all OpenID Consumer options have been moved to their respective sections of the 152 <a href="options-general.php">General Settings</a> and <a href="options-discussion.php">Discussion Settings</a> pages.</p></div> 153 154 233 155 <?php 234 156 $current_user = wp_get_current_user(); … … 250 172 <?php 251 173 foreach ($wp_roles->role_names as $key => $name) { 174 $name = _c($name); 252 175 $role = $wp_roles->get_role($key); 253 176 $checked = $role->has_cap('use_openid_provider') ? ' checked="checked"' : ''; … … 303 226 304 227 ?> 305 </td>306 </tr>228 </td> 229 </tr> 307 230 <?php endif; //!empty($users) ?> 308 </table> 309 310 <?php wp_nonce_field('update-options'); ?> 311 <input type="hidden" name="action" value="update" /> 312 <input type="hidden" name="page_options" value="<?php echo join(',', $openid_options); ?>" /> 231 </table> 232 233 <table class="form-table optiontable editform"> 234 <tr valign="top"> 235 <th scope="row"><?php _e('Troubleshooting', 'openid') ?></th> 236 <td> 237 <?php openid_printSystemStatus(); ?> 238 239 <p><?php printf(__('If users are experiencing problems logging in with OpenID, it may help to %1$srefresh the cache%2$s.', 'openid'), 240 '<a href="' . wp_nonce_url(add_query_arg('action', 'rebuild_tables'), 'rebuild_tables') . '">', '</a>'); ?></p> 241 </td> 242 </tr> 243 </table> 244 245 <?php settings_fields('openid'); ?> 313 246 <p class="submit"><input type="submit" class="button-primary" name="info_update" value="<?php _e('Save Changes') ?>" /></p> 314 247 </form> … … 345 278 } 346 279 347 if (function_exists('screen_icon')): 348 screen_icon('openid'); 280 screen_icon('openid'); 349 281 ?> 350 282 <style type="text/css"> 351 283 #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); } 352 284 </style> 353 <?php endif; ?>354 285 355 286 <div class="wrap"> … … 454 385 update_usermeta($user->ID, 'openid_trusted_sites', $trusted_sites); 455 386 echo '<div class="updated"><p>'; 456 printf( _ _ngettext('Added %d trusted site.', 'Added %d trusted sites.', $count, 'openid'), $count);387 printf( _n('Added %d trusted site.', 'Added %d trusted sites.', $count, 'openid'), $count); 457 388 echo '</p></div>'; 458 389 } … … 477 408 if ($count) { 478 409 echo '<div class="updated"><p>'; 479 printf( _ _ngettext('Deleted %d trusted site.', 'Deleted %d trusted sites.', $count, 'openid'), $count);410 printf( _n('Deleted %d trusted site.', 'Deleted %d trusted sites.', $count, 'openid'), $count); 480 411 echo '</p></div>'; 481 412 } … … 483 414 } 484 415 485 if (function_exists('screen_icon')): 486 screen_icon('openid'); 416 screen_icon('openid'); 487 417 ?> 488 418 <style type="text/css"> 489 419 #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); } 490 420 </style> 491 <?php endif; ?>492 421 493 422 <div class="wrap"> … … 679 608 echo '</div>'; 680 609 } 681 echo '</div>'; 682 echo ' 610 echo '</div> 683 611 <script type="text/javascript"> 684 jQuery("#openid_system_status").hide();'; 685 686 if (!function_exists('add_thickbox')) { 687 echo ' 688 jQuery("#openid_status_link").click( function() { 689 jQuery("#openid_system_status").toggle(); 690 return false; 691 });'; 692 } 693 694 echo ' 612 jQuery("#openid_system_status").hide(); 695 613 </script>'; 696 614 } … … 701 619 */ 702 620 function openid_profile_management() { 703 global $ wp_version;621 global $action; 704 622 705 switch( $_REQUEST['action'] ) { 623 wp_reset_vars( array('action') ); 624 625 switch( $action ) { 706 626 case 'add': 707 627 check_admin_referer('openid-add_openid'); … … 734 654 735 655 default: 736 if ($message = $_REQUEST['message']) { 656 if ( array_key_exists('message', $_REQUEST) ) { 657 $message = $_REQUEST['message']; 737 658 738 659 $messages = array( 739 660 '', 740 661 'Unable to authenticate OpenID.', 741 'OpenID assertion successful, but this URL is already associated with another user on this blog. This is probably a bug.',662 'OpenID assertion successful, but this URL is already associated with another user on this blog.', 742 663 'Added association with OpenID.', 743 664 ); … … 745 666 if (is_numeric($message)) { 746 667 $message = $messages[$message]; 668 } else { 669 $message = htmlentities2( $message ); 747 670 } 748 671 749 672 $message = __($message, 'openid'); 750 673 751 if ( $_REQUEST['update_url']) {674 if (array_key_exists('update_url', $_REQUEST) && $_REQUEST['update_url']) { 752 675 $message .= '<br />' . __('<strong>Note:</strong> For security reasons, your profile URL has been updated to match your OpenID.', 'openid'); 753 676 } … … 768 691 function openid_profile_delete_openids($delete) { 769 692 770 if (empty($delete) || $_REQUEST['cancel']) return;693 if (empty($delete) || array_key_exists('cancel', $_REQUEST)) return; 771 694 check_admin_referer('openid-delete_openids'); 772 695 … … 808 731 809 732 if ($count) { 810 openid_message( sprintf(_ _ngettext('Deleted %d OpenID association.', 'Deleted %d OpenID associations.', $count, 'openid'), $count) );733 openid_message( sprintf(_n('Deleted %d OpenID association.', 'Deleted %d OpenID associations.', $count, 'openid'), $count) ); 811 734 openid_status('success'); 812 735 … … 854 777 set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); 855 778 require_once 'Auth/OpenID.php'; 856 if ($GLOBALS['wp_version'] >= '2.3') { 857 require_once(ABSPATH . 'wp-admin/includes/admin.php'); 858 } else { 859 require_once(ABSPATH . WPINC . '/registration.php'); 860 } 779 require_once(ABSPATH . 'wp-admin/includes/admin.php'); 861 780 862 781 if (!openid_ensure_url_match($user)) { … … 870 789 $finish_url = add_query_arg('status', openid_status(), $finish_url); 871 790 $finish_url = add_query_arg('message', $message, $finish_url); 872 if ( $update_url) {791 if ( isset($update_url) && $update_url ) { 873 792 $finish_url = add_query_arg('update_url', $update_url, $finish_url); 874 793 } … … 876 795 wp_safe_redirect($finish_url); 877 796 exit; 878 }879 880 881 /**882 * Prior to WordPress 2.5, the 'personal_options_update' hook was called883 * AFTER updating the user's profile. We need to ensure the profile URL884 * matches before then.885 */886 function openid_compat_pre_user_url($url) {887 if ($_POST['from'] == 'profile') {888 openid_personal_options_update();889 }890 891 return $url;892 797 } 893 798 … … 928 833 929 834 835 /** 836 * Add OpenID options to the WordPress user profile page. 837 */ 930 838 function openid_extend_profile() { 931 839 $user = wp_get_current_user(); … … 947 855 } 948 856 857 858 /** 859 * Update OpenID options set from the WordPress user profile page. 860 */ 949 861 function openid_profile_update($user_id) { 950 if (empty($_POST['openid_delegate'])) { 862 global $openid_user_delegation_info; 863 864 if ( empty($_POST['openid_delegate']) ) { 951 865 delete_usermeta($user_id, 'openid_delegate'); 866 delete_usermeta($user_id, 'openid_delegate_services'); 952 867 } else { 953 $old_delegate = get_usermeta($user_id, 'openid_delegate'); 954 $delegate = Auth_OpenID::normalizeUrl($_POST['openid_delegate']); 955 956 if(openid_server_update_delegation_info($user_id, $delegate)) { 957 openid_message(sprintf(__('Gathered OpenID information for delegate URL %s', 'openid'), '<strong>'.$delegate.'</strong>')); 958 openid_status('success'); 959 } else { 960 openid_message(sprintf(__('Unable to find any OpenID information for delegate URL %s', 'openid'), '<strong>'.$delegate.'</strong>')); 961 openid_status('error'); 962 } 963 } 964 } 965 868 update_usermeta($user_id, 'openid_delegate', $openid_user_delegation_info['url']); 869 update_usermeta($user_id, 'openid_delegate_services', $openid_user_delegation_info['services']); 870 } 871 } 872 873 874 /** 875 * Report any OpenID errors during user profile updating. 876 */ 877 function openid_profile_update_errors($errors, $update, $user) { 878 global $openid_user_delegation_info; 879 880 $delegate = Auth_OpenID::normalizeUrl($_POST['openid_delegate']); 881 if ( empty($delegate) ) return $errors; 882 883 $openid_user_delegation_info = openid_server_get_delegation_info($user->ID, $delegate); 884 885 if (!$openid_user_delegation_info) { 886 $errors->add('openid_delegate', sprintf(__('Unable to find any OpenID information for delegate URL %s', 'openid'), '<strong>'.$delegate.'</strong>')); 887 } else { 888 $id_select_count = 0; 889 foreach ($openid_user_delegation_info['services'] as $service) { 890 if ( array_key_exists('LocalID', $service) && $service['LocalID'] == Auth_OpenID_IDENTIFIER_SELECT ) { 891 $id_select_count++; 892 } 893 } 894 895 if ( count($openid_user_delegation_info['services']) <= $id_select_count ) { 896 $errors->add('openid_delegate', sprintf(__('You cannot delegate to an OpenID provider which uses Identifier Select.', 'openid'))); 897 } 898 } 899 900 return $errors; 901 } 902 903 /** 904 * Add OpenID options to the WordPress MU site options page. 905 */ 906 function openid_wpmu_options() { 907 $registration = get_site_option('registration'); 908 if ( $registration == 'all' || $registration == 'user' ): 966 909 ?> 910 <table id="openid_options" class="form-table"> 911 <tr valign="top"> 912 <th scope="row"></th> 913 <td> 914 <label for="openid_required_for_registration"> 915 <input type="checkbox" name="openid_required_for_registration" id="openid_required_for_registration" value="1" 916 <?php checked(true, get_site_option('openid_required_for_registration')) ?> /> 917 <?php _e('New accounts can only be created with verified OpenIDs.', 'openid') ?> 918 </label> 919 </td> 920 </tr> 921 </table> 922 923 <script type="text/javascript"> 924 jQuery(function() { 925 jQuery('#openid_options').hide(); 926 var lastp = jQuery('td:has([name="registration"])').children("p:last"); 927 jQuery('#openid_required_for_registration').parent().insertBefore(lastp).wrap('<p></p>'); 928 }); 929 </script> 930 <?php 931 endif; 932 } 933 934 935 /** 936 * Update the OpenID options set from the WordPress MU site options page. 937 */ 938 function openid_update_wpmu_options() { 939 $openid_required = array_key_exists('openid_required_for_registration', $_POST); 940 if ($openid_required) { 941 update_site_option('openid_required_for_registration', '1'); 942 } else { 943 update_site_option('openid_required_for_registration', '0'); 944 } 945 } 946 947 948 /** 949 * Add OpenID options to the WordPress general settings page. 950 */ 951 function openid_general_settings() { 952 if ( get_option('users_can_register') ): ?> 953 <label for="openid_required_for_registration"> 954 <input type="checkbox" name="openid_required_for_registration" id="openid_required_for_registration" value="1" 955 <?php checked(true, get_option('openid_required_for_registration')) ?> /> 956 <?php _e('New accounts can only be created with verified OpenIDs', 'openid') ?> 957 </label> 958 <?php endif; ?> 959 960 <script type="text/javascript"> 961 jQuery(function() { 962 jQuery('tr:has(#openid_required_for_registration)').hide(); 963 jQuery('#openid_required_for_registration') 964 .parent().prepend('<br />').insertAfter('label:has(#users_can_register)'); 965 }); 966 </script> 967 <?php 968 } 969 970 971 /** 972 * Add OpenID options to the WordPress discussion settings page. 973 */ 974 function openid_discussion_settings() { 975 ?> 976 <label for="openid_enable_commentform"> 977 <input type="checkbox" name="openid_enable_commentform" id="openid_enable_commentform" value="1" <?php 978 echo checked(true, get_option('openid_enable_commentform')); ?> /> 979 <?php _e('Enable OpenID for comments', 'openid') ?> 980 </label> 981 <br /> 982 983 <?php if ( get_option('openid_enable_commentform') ): ?> 984 985 <?php if ( get_option('require_name_email') ): ?> 986 <label for="openid_no_require_name"> 987 <input type="checkbox" name="openid_no_require_name" id="openid_no_require_name" value="1" <?php 988 echo checked(true, get_option('openid_no_require_name')) ; ?> /> 989 <?php _e('Don\'t require name and e-mail for comments left with a verified OpenID', 'openid') ?> 990 </label> 991 <br /> 992 <?php endif; ?> 993 994 <label for="openid_enable_approval"> 995 <input type="checkbox" name="openid_enable_approval" id="openid_enable_approval" value="1" <?php 996 echo checked(true, get_option('openid_enable_approval')); ?> /> 997 <?php _e('Always approve comments left with a verified OpenID', 'openid'); ?> 998 </label> 999 <br /> 1000 1001 <?php endif; ?> 1002 <?php 1003 } 1004 1005 ?> -
openid/trunk/comments.php
r103625 r158694 8 8 // -- WordPress Hooks 9 9 add_action( 'preprocess_comment', 'openid_process_comment', -90); 10 if (function_exists('has_action') && has_action('preprocess_comment', 'akismet_auto_check_comment')) { 11 // ensure akismet runs before OpenID 12 remove_action('preprocess_comment', 'akismet_auto_check_comment', 1); 13 add_action('preprocess_comment', 'akismet_auto_check_comment', -99); 14 } 10 add_action( 'init', 'openid_setup_akismet'); 15 11 add_action( 'akismet_spam_caught', 'openid_akismet_spam_caught'); 16 12 add_action( 'comment_post', 'update_comment_openid', 5 ); … … 23 19 add_filter( 'get_comment_author_link', 'openid_comment_author_link'); 24 20 if( get_option('openid_enable_commentform') ) { 25 add_action( 'wp _head', 'openid_js_setup', 9);21 add_action( 'wp', 'openid_js_setup', 9); 26 22 add_action( 'wp_footer', 'openid_comment_profilelink', 10); 27 add_action( ' wp_footer', 'openid_comment_form', 10);23 add_action( 'comment_form', 'openid_comment_form', 10); 28 24 } 29 25 add_filter( 'openid_user_data', 'openid_get_user_data_form', 6, 2); … … 32 28 add_action( 'init', 'openid_recent_comments'); 33 29 30 31 /** 32 * Ensure akismet runs before OpenID. 33 */ 34 function openid_setup_akismet() { 35 if (has_filter('preprocess_comment', 'akismet_auto_check_comment')) { 36 remove_action('preprocess_comment', 'akismet_auto_check_comment', 1); 37 add_action('preprocess_comment', 'akismet_auto_check_comment', -99); 38 } 39 } 40 41 34 42 /** 35 43 * Akismet caught this comment as spam, so no need to do OpenID discovery on the URL. 36 44 */ 37 45 function openid_akismet_spam_caught() { 38 remove_action( 'preprocess_comment', 'openid_process_comment', -9 8);46 remove_action( 'preprocess_comment', 'openid_process_comment', -90); 39 47 } 40 48 … … 49 57 */ 50 58 function openid_process_comment( $comment ) { 59 if ( array_key_exists('openid_skip', $_REQUEST) && $_REQUEST['openid_skip'] ) return $comment; 60 if ( $comment['comment_type'] != '' ) return $comment; 61 62 if ( array_key_exists('openid_identifier', $_POST) ) { 63 $openid_url = $_POST['openid_identifier']; 64 } elseif ( $_REQUEST['login_with_openid'] ) { 65 $openid_url = $_POST['url']; 66 } 67 51 68 @session_start(); 52 53 if ($_REQUEST['openid_skip']) return $comment; 54 55 $openid_url = (array_key_exists('openid_identifier', $_POST) ? $_POST['openid_identifier'] : $_POST['url']); 56 57 if( !empty($openid_url) ) { // Comment form's OpenID url is filled in. 69 unset($_SESSION['openid_posted_comment']); 70 71 if ( !empty($openid_url) ) { // Comment form's OpenID url is filled in. 58 72 $_SESSION['openid_comment_post'] = $_POST; 59 73 $_SESSION['openid_comment_post']['comment_author_openid'] = $openid_url; … … 72 86 73 87 // duplicate name and email check from wp-comments-post.php 74 openid_require_name_email(); 88 if ( $comment['comment_type'] == '') { 89 openid_require_name_email(); 90 } 75 91 76 92 return $comment; … … 126 142 } 127 143 128 if ( $_REQUEST['openid_skip']) {144 if (array_key_exists('openid_skip', $_REQUEST) && $_REQUEST['openid_skip']) { 129 145 return get_option('openid_no_require_name') ? false : $value; 130 146 } … … 197 213 */ 198 214 function update_comment_openid($comment_ID) { 215 session_start(); 216 199 217 if ($_SESSION['openid_posted_comment']) { 200 218 set_comment_openid($comment_ID); … … 219 237 global $wp_scripts; 220 238 221 if ( !is_a($wp_scripts, 'WP_Scripts') ) { 222 $wp_scripts = new WP_Scripts(); 223 } 224 225 if ((is_single() || is_comments_popup()) && is_user_openid() && $wp_scripts->query('openid')) { 239 if (comments_open() && is_user_openid() && $wp_scripts->query('openid')) { 226 240 echo '<script type="text/javascript">stylize_profilelink()</script>'; 227 241 } … … 237 251 global $wp_scripts; 238 252 239 if ( !is_a($wp_scripts, 'WP_Scripts') ) { 240 $wp_scripts = new WP_Scripts(); 241 } 242 243 if (!is_user_logged_in() && (is_single() || is_comments_popup()) && isset($wp_scripts) && $wp_scripts->query('openid')) { 244 echo '<script type="text/javascript">add_openid_to_comment_form()</script>'; 253 if (comments_open() && !is_user_logged_in() && isset($wp_scripts) && $wp_scripts->query('openid')) { 254 ?> 255 <span id="openid_comment"> 256 <label> 257 <input type="checkbox" id="login_with_openid" name="login_with_openid" checked="checked" /> 258 <?php _e('Authenticate this comment using <span class="openid_link">OpenID</span>.'); ?> 259 </label> 260 </span> 261 <script type="text/javascript">jQuery(function(){ add_openid_to_comment_form('<?php echo site_url('index.php') ?>', '<?php echo wp_create_nonce('openid_ajax') ?>') })</script> 262 <?php 245 263 } 246 264 } … … 359 377 */ 360 378 function openid_get_user_data_form($data, $identity_url) { 361 $comment = $_SESSION['openid_comment_post']; 362 363 if (!$comment) { 379 if ( array_key_exists('openid_comment_post', $_SESSION) ) { 380 $comment = $_SESSION['openid_comment_post']; 381 } 382 383 if ( !isset($comment) || !$comment) { 364 384 return $data; 365 385 } … … 380 400 381 401 function openid_recent_comments() { 382 if ( is_active_widget('wp_widget_recent_comments')) {402 if ( is_active_widget('wp_widget_recent_comments') ) { 383 403 remove_action('wp_head', 'wp_widget_recent_comments_style'); 404 384 405 // most themes seem to handle the recent comments widget okay, so I don't think the following style addition is necessary. We'll leave it here just in case it's needed later. 385 //add_action('wp_head', create_function('', 'echo \'<style type="text/css">.recentcomments a{display:inline !important;padding: 0;margin: 0 !important;}</style>\';' )); 406 //add_action('wp_head', create_function('', 'echo \'<style type="text/css">.recentcomments a{padding: 0;margin: 0 !important;}</style>\';' )); 407 } else { 408 // WP 2.8 + 409 global $wp_widget_factory; 410 if ( $wp_widget_factory && array_key_exists('WP_Widget_Recent_Comments', $wp_widget_factory->widgets) ) { 411 remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')); 412 } 386 413 } 387 414 } -
openid/trunk/common.php
r103625 r158694 9 9 10 10 // include internal stylesheet 11 add_action( 'wp _head', 'openid_style');11 add_action( 'wp', 'openid_style'); 12 12 13 13 // parse request … … 16 16 add_action('generate_rewrite_rules', 'openid_rewrite_rules'); 17 17 18 add_action( 'delete_user', 'delete_user_openids' );19 18 add_action( 'cleanup_openid', 'openid_cleanup' ); 20 19 21 22 // hooks for getting user data23 add_filter('openid_auth_request_extensions', 'openid_add_sreg_extension', 10, 2);24 add_filter('openid_auth_request_extensions', 'openid_add_ax_extension', 10, 2);25 20 26 21 add_filter( 'openid_user_data', 'openid_get_user_data_sreg', 8, 2); 27 22 add_filter( 'openid_user_data', 'openid_get_user_data_ax', 10, 2); 28 23 29 add_filter( 'xrds_simple', 'openid_consumer_xrds_simple');30 24 31 25 … … 46 40 */ 47 41 function openid_textdomain() { 48 load_plugin_textdomain('openid', null, 'openid/lang'); 49 } 50 51 /** 52 * Soft verification of plugin activation 53 * 54 * @return boolean if the plugin is okay 55 */ 56 function openid_uptodate() { 57 58 if( get_option('openid_db_revision') != OPENID_DB_REVISION ) { 59 openid_enabled(false); 60 openid_debug('Plugin database is out of date: ' . get_option('openid_db_revision') . ' != ' . OPENID_DB_REVISION); 61 update_option('openid_plugin_enabled', false); 62 return false; 63 } 64 openid_enabled(get_option('openid_plugin_enabled') == true); 65 return openid_enabled(); 66 } 67 // XXX - figure out when to perform uptodate() checks and such (since late_bind is no more) 42 load_plugin_textdomain('openid', null, 'openid/localization'); 43 } 68 44 69 45 … … 85 61 86 62 /** 87 * Get the internal OpenID Consumer object. If it is not already initialized, do so. 88 * 89 * @return Auth_OpenID_Consumer OpenID consumer object 90 */ 91 function openid_getConsumer() { 92 static $consumer; 93 94 if (!$consumer) { 95 set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); 96 require_once 'Auth/OpenID/Consumer.php'; 97 restore_include_path(); 98 99 $store = openid_getStore(); 100 $consumer = new Auth_OpenID_Consumer($store); 101 if( null === $consumer ) { 102 openid_error('OpenID consumer could not be created properly.'); 103 openid_enabled(false); 104 } 105 106 } 107 108 return $consumer; 109 } 110 111 112 function openid_activate_wpmu() { 113 global $wpmu_version; 114 if ($wpmu_version && is_admin()) { 115 if (get_option('openid_db_revision') != OPENID_DB_REVISION) { 116 openid_activate_plugin(); 117 } 118 } 119 } 120 121 /** 122 * Called on plugin activation. 63 * Called on plugin activation and upgrading. 123 64 * 124 65 * @see register_activation_hook … … 146 87 add_option( 'openid_db_revision', 0 ); 147 88 add_option( 'openid_enable_approval', false ); 148 add_option( 'openid_enable_email_mapping', false );149 89 add_option( 'openid_xrds_returnto', true ); 150 add_option( 'openid_xrds_idib', true );151 add_option( 'openid_xrds_eaut', true );152 90 add_option( 'openid_comment_displayname_length', 12 ); 153 91 … … 160 98 161 99 // flush rewrite rules 162 if ( !isset($wp_rewrite)) { $wp_rewrite = new WP_Rewrite(); }100 if ( !isset($wp_rewrite) ) { $wp_rewrite = new WP_Rewrite(); } 163 101 $wp_rewrite->flush_rules(); 164 102 … … 190 128 delete_option('force_openid_registration'); 191 129 delete_option('openid_skip_require_name'); 130 131 delete_option('openid_enable_email_mapping'); 132 delete_option('openid_xrds_idib'); 133 delete_option('openid_xrds_eaut'); 192 134 } 193 135 … … 220 162 delete_option('openid_db_revision'); 221 163 delete_option('openid_enable_approval'); 222 delete_option('openid_enable_email_mapping');223 164 delete_option('openid_xrds_returnto'); 224 delete_option('openid_xrds_idib');225 delete_option('openid_xrds_eaut');226 165 delete_option('openid_comment_displayname_length'); 227 166 delete_option('openid_associations'); … … 270 209 271 210 openid_error( "Library Error $errno: $errmsg in $filename :$linenum"); 272 }273 274 275 /**276 * Send the user to their OpenID provider to authenticate.277 *278 * @param Auth_OpenID_AuthRequest $auth_request OpenID authentication request object279 * @param string $trust_root OpenID trust root280 * @param string $return_to URL where the OpenID provider should return the user281 */282 function openid_redirect($auth_request, $trust_root, $return_to) {283 do_action('openid_redirect', $auth_request, $trust_root, $return_to);284 285 $message = $auth_request->getMessage($trust_root, $return_to, false);286 287 if (Auth_OpenID::isFailure($message)) {288 return openid_error('Could not redirect to server: '.$message->message);289 }290 291 $_SESSION['openid_return_to'] = $message->getArg(Auth_OpenID_OPENID_NS, 'return_to');292 293 // send 302 redirect or POST294 if ($auth_request->shouldSendRedirect()) {295 $redirect_url = $auth_request->redirectURL($trust_root, $return_to);296 wp_redirect( $redirect_url );297 } else {298 openid_repost($auth_request->endpoint->server_url, $message->toPostArgs());299 }300 }301 302 303 /**304 * Finish OpenID Authentication.305 *306 * @return String authenticated identity URL, or null if authentication failed.307 */308 function finish_openid_auth() {309 @session_start();310 311 $consumer = openid_getConsumer();312 $openid_return_to = $_SESSION['openid_return_to'];313 if (empty($openid_return_to)) {314 $openid_return_to = openid_service_url('openid', 'consumer');315 }316 317 $response = $consumer->complete($openid_return_to);318 319 unset($_SESSION['openid_return_to']);320 openid_response($response);321 322 switch( $response->status ) {323 case Auth_OpenID_CANCEL:324 openid_message(__('OpenID login was cancelled.', 'openid'));325 openid_status('error');326 break;327 328 case Auth_OpenID_FAILURE:329 openid_message(sprintf(__('OpenID login failed: %s', 'openid'), $response->message));330 openid_status('error');331 break;332 333 case Auth_OpenID_SUCCESS:334 openid_message(__('OpenID login successful', 'openid'));335 openid_status('success');336 337 $identity_url = $response->identity_url;338 $escaped_url = htmlspecialchars($identity_url, ENT_QUOTES);339 return $escaped_url;340 341 default:342 openid_message(__('Unknown Status. Bind not successful. This is probably a bug.', 'openid'));343 openid_status('error');344 }345 346 return null;347 211 } 348 212 … … 366 230 continue; 367 231 } 232 // TODO: add hook 368 233 return $username; 369 234 } … … 379 244 * @param string $username username to be normalized 380 245 * @return string normalized username 246 * @uses apply_filters() Calls 'openid_normalize_username' just before returning normalized username 381 247 */ 382 248 function openid_normalize_username($username) { 383 $username = preg_replace('|^https?://(xri.net/([^@]!?)?)?|', '', $username); 384 $username = preg_replace('|^xri://([^@]!?)?|', '', $username); 385 $username = preg_replace('|/$|', '', $username); 386 $username = sanitize_user( $username ); 387 $username = preg_replace('|[^a-z0-9 _.\-@]+|i', '-', $username); 388 return $username; 389 } 390 391 392 /** 393 * Begin login by activating the OpenID consumer. 394 * 395 * @param string $url claimed ID 396 * @return Auth_OpenID_Request OpenID Request 397 */ 398 function openid_begin_consumer($url) { 399 static $request; 400 401 @session_start(); 402 if ($request == NULL) { 403 set_error_handler( 'openid_customer_error_handler'); 404 405 if (is_email($url)) { 406 $_SESSION['openid_login_email'] = $url; 407 set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); 408 require_once 'Auth/Yadis/Email.php'; 409 $mapped_url = Auth_Yadis_Email_getID($url, trailingslashit(get_option('home'))); 410 if ($mapped_url) { 411 $url = $mapped_url; 412 } 413 } 414 415 $consumer = openid_getConsumer(); 416 $request = $consumer->begin($url); 417 418 restore_error_handler(); 419 } 420 421 return $request; 422 } 423 424 425 /** 426 * Start the OpenID authentication process. 427 * 428 * @param string $claimed_url claimed OpenID URL 429 * @param string $action OpenID action being performed 430 * @param string $finish_url stored in user session for later redirect 431 * @uses apply_filters() Calls 'openid_auth_request_extensions' to gather extensions to be attached to auth request 432 */ 433 function openid_start_login( $claimed_url, $action, $finish_url = null) { 434 if ( empty($claimed_url) ) return; // do nothing. 435 436 $auth_request = openid_begin_consumer( $claimed_url ); 437 438 if ( null === $auth_request ) { 439 openid_status('error'); 440 openid_message(sprintf( 441 __('Could not discover an OpenID identity server endpoint at the url: %s', 'openid'), 442 htmlentities($claimed_url) 443 )); 444 if( strpos( $claimed_url, '@' ) ) { 445 openid_message(openid_message() . '<br />' . __('It looks like you entered an email address, but it ' 446 . 'was not able to be transformed into a valid OpenID.', 'openid')); 447 } 448 return; 449 } 450 451 @session_start(); 452 $_SESSION['openid_action'] = $action; 453 $_SESSION['openid_finish_url'] = $finish_url; 454 455 $extensions = apply_filters('openid_auth_request_extensions', array(), $auth_request); 456 foreach ($extensions as $e) { 457 if (is_a($e, 'Auth_OpenID_Extension')) { 458 $auth_request->addExtension($e); 459 } 460 } 461 462 $return_to = openid_service_url('openid', 'consumer', 'login_post'); 463 $return_to = apply_filters('openid_return_to', $return_to); 464 465 $trust_root = openid_trust_root($return_to); 466 467 openid_redirect($auth_request, $trust_root, $return_to); 468 exit(0); 249 $normalized = $username; 250 251 $normalized = preg_replace('|^https?://(xri.net/([^@]!?)?)?|', '', $normalized); 252 $normalized = preg_replace('|^xri://([^@]!?)?|', '', $normalized); 253 $normalized = preg_replace('|/$|', '', $normalized); 254 $normalized = sanitize_user( $normalized ); 255 $normalized = preg_replace('|[^a-z0-9 _.\-@]+|i', '-', $normalized); 256 257 $normalized = apply_filters('openid_normalize_username', $normalized, $username); 258 259 return $normalized; 469 260 } 470 261 … … 486 277 $trust_root = apply_filters('openid_trust_root', $trust_root, $return_to); 487 278 return $trust_root; 488 }489 490 491 /**492 * Build an Attribute Exchange attribute query extension if we've never seen this OpenID before.493 */494 function openid_add_ax_extension($extensions, $auth_request) {495 if(!get_user_by_openid($auth_request->endpoint->claimed_id)) {496 set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );497 require_once('Auth/OpenID/AX.php');498 restore_include_path();499 500 if ($auth_request->endpoint->usesExtension(Auth_OpenID_AX_NS_URI)) {501 $ax_request = new Auth_OpenID_AX_FetchRequest();502 $ax_request->add(Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/friendly', 1, true));503 $ax_request->add(Auth_OpenID_AX_AttrInfo::make('http://axschema.org/contact/email', 1, true));504 $ax_request->add(Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson', 1, true));505 506 $extensions[] = $ax_request;507 }508 }509 510 return $extensions;511 }512 513 514 /**515 * Build an SReg attribute query extension if we've never seen this OpenID before.516 */517 function openid_add_sreg_extension($extensions, $auth_request) {518 if(!get_user_by_openid($auth_request->endpoint->claimed_id)) {519 set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );520 require_once('Auth/OpenID/SReg.php');521 restore_include_path();522 523 if ($auth_request->endpoint->usesExtension(Auth_OpenID_SREG_NS_URI_1_0) || $auth_request->endpoint->usesExtension(Auth_OpenID_SREG_NS_URI_1_1)) {524 $extensions[] = Auth_OpenID_SRegRequest::build(array(),array('nickname','email','fullname'));525 }526 }527 528 return $extensions;529 279 } 530 280 … … 548 298 549 299 $user = set_current_user($user_id); 550 551 if (function_exists('wp_set_auth_cookie')) { 552 wp_set_auth_cookie($user->ID, $remember); 553 } else { 554 wp_setcookie($user->user_login, md5($user->user_pass), true, '', '', $remember); 555 } 300 wp_set_auth_cookie($user->ID, $remember); 556 301 557 302 do_action('wp_login', $user->user_login); 558 }559 560 561 /**562 * Finish OpenID authentication.563 *564 * @param string $action login action that is being performed565 * @uses do_action() Calls 'openid_finish_auth' hook action after processing the authentication response.566 */567 function finish_openid($action) {568 $identity_url = finish_openid_auth();569 do_action('openid_finish_auth', $identity_url, $action);570 303 } 571 304 … … 585 318 @include_once( ABSPATH . WPINC . '/registration-functions.php'); // 2.0.4 586 319 587 // use email address for username if URL is from emailtoid.net588 if (null != $_SESSION['openid_login_email'] and strpos($identity_url, 'http://emailtoid.net/') === 0) {589 if (empty($user_data['user_email'])) {590 $user_data['user_email'] = $_SESSION['openid_login_email'];591 }592 $username = openid_generate_new_username($_SESSION['openid_login_email']);593 unset($_SESSION['openid_login_email']);594 }595 596 320 // otherwise, try to use preferred username 597 if ( empty($username) && $user_data['nickname']) {321 if ( empty($username) && array_key_exists('nickname', $user_data) ) { 598 322 $username = openid_generate_new_username($user_data['nickname'], false); 599 323 } … … 782 506 783 507 /** 784 *785 * @uses apply_filters() Calls 'openid_consumer_return_urls' to collect return_to URLs to be included in XRDS document.786 */787 function openid_consumer_xrds_simple($xrds) {788 789 if (get_option('openid_xrds_returnto')) {790 // OpenID Consumer Service791 $return_urls = array_unique(apply_filters('openid_consumer_return_urls', array(openid_service_url('openid', 'consumer', 'login_post'))));792 if (!empty($return_urls)) {793 $xrds = xrds_add_simple_service($xrds, 'OpenID Consumer Service', 'http://specs.openid.net/auth/2.0/return_to', $return_urls);794 }795 }796 797 if (get_option('openid_xrds_idib')) {798 // Identity in the Browser Login Service799 $xrds = xrds_add_service($xrds, 'main', 'Identity in the Browser Login Service',800 array(801 'Type' => array(array('content' => 'http://specs.openid.net/idib/1.0/login') ),802 'URI' => array(803 array(804 'simple:httpMethod' => 'POST',805 'content' => site_url('/wp-login.php', 'login_post'),806 ),807 ),808 )809 );810 811 // Identity in the Browser Indicator Service812 $xrds = xrds_add_simple_service($xrds, 'Identity in the Browser Indicator Service',813 'http://specs.openid.net/idib/1.0/indicator', openid_service_url('openid', 'check_login'));814 }815 816 return $xrds;817 }818 819 820 /**821 508 * Parse the WordPress request. If the query var 'openid' is present, then 822 509 * handle the request accordingly. … … 840 527 $action = 'login'; 841 528 if (empty($_SESSION['openid_finish_url'])) { 842 $_SESSION['openid_finish_url'] = get_option('home');529 //$_SESSION['openid_finish_url'] = get_option('home'); 843 530 } 844 531 } … … 851 538 break; 852 539 853 case 'check_login': 854 // IDIB Request 855 echo is_user_logged_in() ? 'true' : 'false'; 856 exit; 540 case 'ajax': 541 if ( check_admin_referer('openid_ajax') ) { 542 header('Content-Type: application/json'); 543 echo '{ valid:' . ( is_url_openid( $_REQUEST['url'] ) ? 'true' : 'false' ) . ', nonce:"' . wp_create_nonce('openid_ajax') . '" }'; 544 exit; 545 } 857 546 } 858 547 } 548 } 549 550 551 /** 552 * Check if the provided URL is a valid OpenID. 553 * 554 * @param string $url URL to check 555 * @return boolean true if the URL is a valid OpenID 556 */ 557 function is_url_openid( $url ) { 558 $auth_request = openid_begin_consumer( $url ); 559 return ( $auth_request != null ); 859 560 } 860 561 … … 903 604 * Build an OpenID service URL. 904 605 * 905 * @param string $name service name to build URL for 906 * @param string $value service value to build URL for 606 * @param string $service service to build URL for 907 607 * @param string $scheme URL scheme to use for URL (see site_url()) 908 * @param boolean $absolute should we return an absolute URL909 608 * @return string service URL 910 609 * @see site_url 911 610 */ 912 function openid_service_url($ name, $value, $scheme = null, $absolute = true) {611 function openid_service_url($service, $scheme = null) { 913 612 global $wp_rewrite; 914 613 if (!$wp_rewrite) $wp_rewrite = new WP_Rewrite(); 915 614 916 if ($absolute) { 917 if (!defined('OPENID_SSL') || !OPENID_SSL) $scheme = null; 918 $url = site_url('/', $scheme); 615 if (!defined('OPENID_SSL') || !OPENID_SSL) $scheme = null; 616 $url = site_url('/', $scheme); 617 618 if ($wp_rewrite->using_permalinks()) { 619 $url .= 'index.php/openid/' . $service; 919 620 } else { 920 $site_url = get_option('siteurl'); 921 $home_url = get_option('home'); 922 923 if ($site_url != $home_url) { 924 $url = substr(trailingslashit($site_url), strlen($home_url)+1); 925 } else { 926 $url = ''; 927 } 928 } 929 930 if ($wp_rewrite->using_permalinks()) { 931 if ($wp_rewrite->using_index_permalinks()) { 932 $url .= 'index.php/'; 933 } 934 $url .= $name . '/' . $value; 935 } else { 936 $url .= '?' . $name . '=' . $value; 621 $url .= '?openid=' . $service; 937 622 } 938 623 939 624 return $url; 940 625 } 626 941 627 942 628 /** … … 945 631 function openid_rewrite_rules($wp_rewrite) { 946 632 $openid_rules = array( 947 openid_service_url('openid', '(.+)', null, false) => 'index.php?openid=$matches[1]', 948 openid_service_url('eaut', '(.+)', null, false) => 'index.php?eaut=$matches[1]', 633 'openid/(.+)' => 'index.php?openid=$matches[1]', 949 634 ); 950 635 … … 958 643 function openid_query_vars($vars) { 959 644 $vars[] = 'openid'; 960 $vars[] = 'eaut';961 645 return $vars; 962 }963 964 965 /**966 * Delete user.967 */968 function delete_user_openids($userid) {969 openid_drop_all_identities($userid);970 }971 972 973 function openid_add_user_identity($user_id, $identity_url) {974 openid_add_identity($user_id, $identity_url);975 646 } 976 647 … … 1031 702 ?> 1032 703 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 1033 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) )language_attributes(); ?>>704 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> 1034 705 <head> 1035 706 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> … … 1055 726 1056 727 /** 1057 * Enqueue required javascript libraries .728 * Enqueue required javascript libraries on appropriate pages. 1058 729 * 1059 730 * @action: init 1060 731 **/ 1061 732 function openid_js_setup() { 1062 if (is_single() || is_comments_popup() || is_admin()) { 1063 wp_enqueue_script( 'jquery' ); 1064 //wp_enqueue_script( 'jquery-ui-sortable' ); 1065 wp_enqueue_script('jquery.textnode', openid_plugin_url() . '/f/jquery.textnode.min.js', 1066 array('jquery'), OPENID_PLUGIN_REVISION); 1067 wp_enqueue_script('jquery.xpath', openid_plugin_url() . '/f/jquery.xpath.min.js', 1068 array('jquery'), OPENID_PLUGIN_REVISION); 1069 1070 $js_file = (defined('WP_DEBUG') && WP_DEBUG) ? 'openid.js' : 'openid.min.js'; 1071 wp_enqueue_script('openid', openid_plugin_url() . '/f/' . $js_file, 1072 array('jquery','jquery.textnode'), OPENID_PLUGIN_REVISION); 1073 } 1074 } 1075 1076 1077 /** 1078 * Get opend plugin URL, keeping in mind that for WordPress MU, it may be in either the normal 1079 * plugins directory or mu-plugins. 1080 */ 1081 function openid_plugin_url() { 1082 static $openid_plugin_url; 1083 1084 if (!$openid_plugin_url) { 1085 if (defined('MUPLUGINDIR') && file_exists(ABSPATH . MUPLUGINDIR . '/openid')) { 1086 $openid_plugin_url = trailingslashit(get_option('siteurl')) . MUPLUGINDIR . '/openid'; 1087 } else { 1088 $openid_plugin_url = plugins_url('openid'); 1089 } 1090 } 1091 1092 return $openid_plugin_url; 1093 } 1094 1095 1096 /** 1097 * Include internal stylesheet. 1098 * 1099 * @action: wp_head, login_head 733 if (have_comments() || comments_open() || is_admin()) { 734 wp_enqueue_script('openid', plugins_url('openid/f/openid.js'), array('jquery'), OPENID_PLUGIN_REVISION); 735 } 736 } 737 738 739 /** 740 * Include OpenID stylesheet. 741 * 742 * "Intelligently" decides whether to enqueue or print the CSS file, based on whether * the 'wp_print_styles' 743 * action has been run. (This logic taken from the core wp_admin_css function) 1100 744 **/ 1101 745 function openid_style() { 1102 $css_file = (defined('WP_DEBUG') && WP_DEBUG) ? 'openid.css' : 'openid.min.css'; 1103 $css_path = openid_plugin_url() . '/f/' . $css_file . '?ver=' . OPENID_PLUGIN_REVISION; 1104 1105 echo ' 1106 <link rel="stylesheet" type="text/css" href="'.clean_url($css_path).'" />'; 746 if ( !wp_style_is('openid', 'registered') ) { 747 wp_register_style('openid', plugins_url('openid/f/openid.css'), array(), OPENID_PLUGIN_REVISION); 748 } 749 750 if ( did_action('wp_print_styles') ) { 751 wp_print_styles('openid'); 752 } else { 753 wp_enqueue_style('openid'); 754 } 755 } 756 757 758 759 // ---------------------- // 760 // OpenID User Management // 761 // ---------------------- // 762 763 764 /** 765 * When a WordPress user is deleted, make sure all associated OpenIDs are deleted as well. 766 */ 767 function delete_user_openids($userid) { 768 openid_drop_all_identities($userid); 769 } 770 add_action( 'delete_user', 'delete_user_openids' ); 771 772 773 /** 774 * Add the specified identity URL to the user. 775 * 776 * @param int $user_id user id 777 * @param string $identity_url identity url to add 778 */ 779 function openid_add_user_identity($user_id, $identity_url) { 780 openid_add_identity($user_id, $identity_url); 1107 781 } 1108 782 … … 1116 790 function openid_add_identity($user_id, $url) { 1117 791 global $wpdb; 1118 return $wpdb->query( wpdb_prepare('INSERT INTO '.openid_identity_table().' (user_id,url,hash) VALUES ( %s, %s, MD5(%s) )', $user_id, $url, $url) ); 1119 } 1120 1121 1122 /** 1123 * Get OpenIDs for the specified user. 792 $sql = $wpdb->prepare('INSERT INTO ' . openid_identity_table() . ' (user_id,url,hash) VALUES ( %s, %s, MD5(%s) )', $user_id, $url, $url); 793 return $wpdb->query( $sql ); 794 } 795 796 797 /** 798 * Remove identity url from user. 1124 799 * 1125 800 * @param int $user_id user id 1126 * @ return array OpenIDs for the user1127 */ 1128 function _get_user_openids($user_id) {801 * @param string $identity_url identity url to remove 802 */ 803 function openid_drop_identity($user_id, $identity_url) { 1129 804 global $wpdb; 1130 return $wpdb->get_col( wpdb_prepare('SELECT url FROM '.openid_identity_table().' WHERE user_id = %s', $user_id) ); 1131 } 1132 805 return $wpdb->query( $wpdb->prepare('DELETE FROM '.openid_identity_table().' WHERE user_id = %s AND url = %s', $user_id, $identity_url) ); 806 } 807 808 809 /** 810 * Remove all identity urls from user. 811 * 812 * @param int $user_id user id 813 */ 814 function openid_drop_all_identities($user_id) { 815 global $wpdb; 816 return $wpdb->query( $wpdb->prepare('DELETE FROM '.openid_identity_table().' WHERE user_id = %s', $user_id ) ); 817 } 818 819 820 821 // -------------- // 822 // Other Function // 823 // -------------- // 1133 824 1134 825 /** … … 1142 833 1143 834 1144 /**1145 * Remove identity url from user.1146 *1147 * @param int $user_id user id1148 * @param string $identity_url identity url to remove1149 */1150 function openid_drop_identity($user_id, $identity_url) {1151 global $wpdb;1152 return $wpdb->query( wpdb_prepare('DELETE FROM '.openid_identity_table().' WHERE user_id = %s AND url = %s', $user_id, $identity_url) );1153 }1154 1155 1156 /**1157 * Remove all identity urls from user.1158 *1159 * @param int $user_id user id1160 */1161 function openid_drop_all_identities($user_id) {1162 global $wpdb;1163 return $wpdb->query( wpdb_prepare('DELETE FROM '.openid_identity_table().' WHERE user_id = %s', $user_id ) );1164 }1165 1166 1167 835 function openid_error($msg) { 1168 836 error_log('[OpenID] ' . $msg); -
openid/trunk/f/openid.css
r88142 r158694 10 10 } 11 11 12 .openid_loading { 13 background: url('ajax-loader.gif') right center no-repeat; 14 } 15 12 16 body.login #openid_identifier { 13 17 width: 92%; … … 19 23 } 20 24 25 #openid_comment { 26 margin: 0.8em 1em; 27 } 28 #openid_comment input { 29 width: auto; 30 } 31 21 32 /* fix link color on wp-login.php */ 22 33 body.login form#loginform a.legacy, … … 25 36 } 26 37 27 #openid_rollup {28 margin-top: 1em;29 }30 31 #openid_rollup div div { margin: 0.5em; }32 #openid_rollup ul { margin: 0; padding: 0 0 0 5em; } -
openid/trunk/f/openid.js
r88142 r158694 1 // use yuicompress (http://developer.yahoo.com/yui/compressor/) to generate openid.min.js 1 /* yuicompress openid.js -o openid.min.js 2 * @see http://developer.yahoo.com/yui/compressor/ 3 */ 2 4 3 5 jQuery(function() { … … 11 13 12 14 function stylize_profilelink() { 13 jQuery("#commentform a[ @href$='profile.php']").addClass('openid_link');15 jQuery("#commentform a[href$='profile.php']").addClass('openid_link'); 14 16 } 15 17 16 function add_openid_to_comment_form() { 18 /** 19 * Properly integrate the 'Authenticate with OpenID' checkbox into the comment form. 20 * This will move the checkbox below the Website field, and add an AJAX hook to 21 * show/hide the checkbox depending on whether the given URL is a valid OpenID. 22 */ 23 function add_openid_to_comment_form(wp_url, nonce) { 24 var openid_nonce = nonce; 17 25 18 jQuery('#commentform').addClass('openid'); 26 var openid_comment = jQuery('#openid_comment'); 27 var openid_checkbox = jQuery('#login_with_openid'); 28 var url = jQuery('#url'); 19 29 20 var html = ' <a id="openid_enabled_link" href="http://openid.net">(OpenID Enabled)</a> ' + 21 '<div id="openid_text">' + 22 'If you have an OpenID, you may fill it in here. If your OpenID provider provides ' + 23 'a name and email, those values will be used instead of the values here. ' + 24 '<a href="http://openid.net/what/">Learn more about OpenID</a> or ' + 25 '<a href="http://openid.net/get/">find an OpenID provider</a>.' + 26 '</div> '; 30 jQuery('label[for="url"],#url').filter(':last').after(openid_comment.hide()); 27 31 28 jQuery('#commentform #url').attr('maxlength', '100'); 29 var label = jQuery('#commentform label[@for=url]'); 30 var children = jQuery(':visible:hastext', label); 32 if ( url.val() ) check_openid( url ); 33 url.blur( function() { check_openid(jQuery(this)); } ); 31 34 32 if (children.length > 0)33 children.filter(':last').appendToText(html);34 else if (label.is(':hastext'))35 label.appendToText(html);36 else37 label.append(html);38 35 39 // setup action 40 jQuery('#openid_text').hide(); 41 jQuery('#openid_enabled_link').click( function() { 42 jQuery('#openid_text').toggle(200); 43 return false; 44 }); 36 /** 37 * Make AJAX call to WordPress to check if the given URL is a valid OpenID. 38 * AJAX response should be a JSON structure with two values: 39 * 'valid' - (boolean) whether or not the given URL is a valid OpenID 40 * 'nonce' - (string) new nonce to use for next AJAX call 41 */ 42 function check_openid( url ) { 43 url.addClass('openid_loading'); 44 45 if ( url.val() == '' ) { 46 openid_checkbox.attr('checked', ''); 47 openid_comment.slideUp(); 48 return; 49 } 50 51 jQuery.getJSON(wp_url + '?openid=ajax', {url: url.val(), _wpnonce: openid_nonce}, function(data, textStatus) { 52 url.removeClass('openid_loading'); 53 if ( data.valid ) { 54 openid_checkbox.attr('checked', 'checked'); 55 openid_comment.slideDown(); 56 } else { 57 openid_checkbox.attr('checked', ''); 58 openid_comment.slideUp(); 59 } 60 openid_nonce = data.nonce; 61 }); 62 } 45 63 } 46 64 -
openid/trunk/login.php
r137082 r158694 6 6 7 7 8 // add OpenID input field to wp-login.php9 8 add_action( 'login_head', 'openid_wp_login_head'); 10 9 add_action( 'login_form', 'openid_wp_login_form'); 11 10 add_action( 'register_form', 'openid_wp_register_form', 9); 12 11 add_action( 'register_post', 'openid_register_post', 10, 3); 13 add_action( 'wp_authenticate', 'openid_wp_authenticate' );14 12 add_action( 'openid_finish_auth', 'openid_finish_login', 10, 2); 15 13 add_filter( 'registration_errors', 'openid_clean_registration_errors', -99); … … 17 15 add_action( 'init', 'openid_login_errors' ); 18 16 19 // WordPress 2.5 has wp_authenticate in the wrong place 20 if (version_compare($wp_version, '2.5', '>=') && version_compare($wp_version, '2.6', '<')) { 21 add_action( 'init', 'wp25_login_openid' ); 22 } 23 24 25 /** 26 * If we're doing openid authentication ($_POST['openid_identifier'] is set), start the consumer & redirect 27 * Otherwise, return and let WordPress handle the login and/or draw the form. 28 * 29 * @param string $credentials username and password provided in login form 30 */ 31 function openid_wp_authenticate(&$credentials) { 32 if (!empty($_POST['openid_identifier'])) { 33 $finish_url = $_REQUEST['redirect_to']; 34 openid_start_login($_POST['openid_identifier'], 'login', $finish_url); 17 18 /** 19 * Authenticate user to WordPress using OpenID. 20 * 21 * @param mixed $user authenticated user object, or WP_Error or null 22 */ 23 function openid_authenticate($user) { 24 if ( array_key_exists('openid_identifier', $_POST) && $_POST['openid_identifier'] ) { 25 26 $redirect_to = array_key_exists('redirect_to', $_REQUEST) ? $_REQUEST['redirect_to'] : null; 27 openid_start_login($_POST['openid_identifier'], 'login', $redirect_to); 35 28 36 29 // if we got this far, something is wrong 37 30 global $error; 38 31 $error = openid_message(); 39 } 32 $user = new WP_Error( 'openid_login_error', $error ); 33 34 } else if ( array_key_exists('finish_openid', $_REQUEST) ) { 35 36 $identity_url= $_REQUEST['identity_url']; 37 38 if ( !wp_verify_nonce($_REQUEST['_wpnonce'], 'openid_login_' . md5($identity_url)) ) { 39 $user = new WP_Error('openid_login_error', 'Error during OpenID authentication. Please try again. (invalid nonce)'); 40 } 41 42 if ( $identity_url ) { 43 $user_id = get_user_by_openid($identity_url); 44 if ( $user_id ) { 45 $user = new WP_User($user_id); 46 } else { 47 $user = new WP_Error('openid_registration_closed', __('Your have entered a valid OpenID, but this site is not currently accepting new accounts.', 'openid')); 48 } 49 } else if ( array_key_exists('openid_error', $_REQUEST) ) { 50 $user = new WP_Error('openid_login_error', htmlentities2($_REQUEST['openid_error'])); 51 } 52 53 } 54 55 return $user; 56 } 57 add_action( 'authenticate', 'openid_authenticate' ); 58 59 60 /** 61 * Action method for completing the 'login' action. This action is used when a user is logging in from 62 * wp-login.php. 63 * 64 * @param string $identity_url verified OpenID URL 65 */ 66 function openid_finish_login($identity_url, $action) { 67 if ($action != 'login') return; 68 69 // create new user account if appropriate 70 $user_id = get_user_by_openid($identity_url); 71 if ( $identity_url && !$user_id && get_option('users_can_register') ) { 72 $user_data =& openid_get_user_data($identity_url); 73 openid_create_new_user($identity_url, $user_data); 74 } 75 76 // return to wp-login page 77 $url = get_option('siteurl') . '/wp-login.php'; 78 if (empty($identity_url)) { 79 $url = add_query_arg('openid_error', openid_message(), $url); 80 } 81 82 $url = add_query_arg( array( 83 'finish_openid' => 1, 84 'identity_url' => urlencode($identity_url), 85 'redirect_to' => $_SESSION['openid_finish_url'], 86 '_wpnonce' => wp_create_nonce('openid_login_' . md5($identity_url)), 87 ), $url); 88 89 wp_safe_redirect($url); 90 exit; 40 91 } 41 92 … … 46 97 function openid_login_errors() { 47 98 $self = basename( $GLOBALS['pagenow'] ); 48 49 99 if ($self != 'wp-login.php') return; 50 100 51 if ( $_REQUEST['openid_error']) {101 if ( array_key_exists('openid_error', $_REQUEST) ) { 52 102 global $error; 53 103 $error = htmlentities2($_REQUEST['openid_error']); 54 104 } 55 56 if ($_REQUEST['registration_closed']) {57 global $error;58 $error = __('Your have entered a valid OpenID, but this site is not currently accepting new accounts.', 'openid');59 }60 105 } 61 106 … … 66 111 function openid_wp_login_head() { 67 112 openid_style(); 68 wp_enqueue_script('jquery.xpath', openid_plugin_url() . '/f/jquery.xpath.min.js',69 array('jquery'), OPENID_PLUGIN_REVISION);70 wp_print_scripts(array('jquery.xpath'));71 113 } 72 114 … … 78 120 **/ 79 121 function openid_wp_login_form() { 80 global $wp_version;81 82 122 echo '<hr id="openid_split" style="clear: both; margin-bottom: 1.0em; border: 0; border-top: 1px solid #999; height: 1px;" />'; 83 123 84 124 echo ' 85 125 <p style="margin-bottom: 8px;"> 86 <label style="display: block; margin-bottom: 5px;">' . __('Or login using an OpenID', 'openid') . '< /label>126 <label style="display: block; margin-bottom: 5px;">' . __('Or login using an OpenID', 'openid') . '<br /> 87 127 <input type="text" name="openid_identifier" id="openid_identifier" class="input openid_identifier" value="" size="20" tabindex="25" /></label> 88 128 </p> … … 100 140 **/ 101 141 function openid_wp_register_form() { 102 global $wp_version;103 104 142 echo ' 105 143 <div style="width:100%;">'; //Added to fix IE problem … … 134 172 echo ' 135 173 <p> 136 <label style="display: block; margin-bottom: 5px;">' . $label . '< /label>174 <label style="display: block; margin-bottom: 5px;">' . $label . '<br /> 137 175 <input type="text" name="openid_identifier" id="openid_identifier" class="input openid_identifier" value="" size="20" tabindex="25" /></label> 138 176 </p> … … 144 182 </div>'; 145 183 146 }147 148 149 /**150 * Action method for completing the 'login' action. This action is used when a user is logging in from151 * wp-login.php.152 *153 * @param string $identity_url verified OpenID URL154 */155 function openid_finish_login($identity_url, $action) {156 if ($action != 'login') return;157 158 $redirect_to = $_SESSION['openid_finish_url'];159 160 if (empty($identity_url)) {161 $url = get_option('siteurl') . '/wp-login.php?openid_error=' . urlencode(openid_message());162 wp_safe_redirect($url);163 exit;164 }165 166 openid_set_current_user($identity_url);167 168 if (!is_user_logged_in()) {169 if ( get_option('users_can_register') ) {170 $user_data =& openid_get_user_data($identity_url);171 $user = openid_create_new_user($identity_url, $user_data);172 openid_set_current_user($user->ID);173 } else {174 // TODO - Start a registration loop in WPMU.175 $url = get_option('siteurl') . '/wp-login.php?registration_closed=1';176 wp_safe_redirect($url);177 exit;178 }179 180 }181 182 if (empty($redirect_to)) {183 $redirect_to = 'wp-admin/';184 }185 if ($redirect_to == 'wp-admin/') {186 if (!current_user_can('edit_posts')) {187 $redirect_to .= 'profile.php';188 }189 }190 if (!preg_match('#^(http|\/)#', $redirect_to)) {191 $wpp = parse_url(get_option('siteurl'));192 $redirect_to = $wpp['path'] . '/' . $redirect_to;193 }194 195 wp_safe_redirect( $redirect_to );196 exit;197 }198 199 200 /**201 * Intercept login requests on wp-login.php if they include an 'openid_identifier'202 * value and start OpenID authentication. This hook is only necessary in203 * WordPress 2.5.x because it has the 'wp_authenticate' action call in the204 * wrong place.205 */206 function wp25_login_openid() {207 $self = basename( $GLOBALS['pagenow'] );208 209 if ($self == 'wp-login.php' && !empty($_POST['openid_identifier'])) {210 wp_signon(array('user_login'=>'openid', 'user_password'=>'openid'));211 }212 184 } 213 185 … … 253 225 */ 254 226 function openid_register_post($username, $password, $errors) { 255 if ( !empty($_POST['openid_identifier'])) {256 wp_signon( array('user_login'=>'openid', 'user_password'=>'openid'));227 if ( !empty($_POST['openid_identifier']) ) { 228 wp_signon(); 257 229 } 258 230 } -
openid/trunk/openid.php
r103625 r158694 19 19 20 20 $openid_include_path = dirname(__FILE__); 21 if (file_exists(dirname(__FILE__) . '/openid')) {22 // for WPMU mu-plugins folder23 $openid_include_path .= PATH_SEPARATOR . dirname(__FILE__) . '/openid';24 }25 21 26 22 // check source of randomness 27 if (!@is_readable('/dev/urandom')) define( 'Auth_OpenID_RAND_SOURCE', null ); 23 if ( !@is_readable('/dev/urandom') ) { 24 define('Auth_OpenID_RAND_SOURCE', null); 25 } 28 26 29 27 set_include_path( $openid_include_path . PATH_SEPARATOR . get_include_path() ); 30 28 require_once 'common.php'; 31 require_once 'co mpatibility.php';29 require_once 'consumer.php'; 32 30 require_once 'admin_panels.php'; 33 31 require_once 'comments.php'; … … 40 38 register_activation_hook('openid/openid.php', 'openid_activate_plugin'); 41 39 register_deactivation_hook('openid/openid.php', 'openid_deactivate_plugin'); 42 if ( function_exists('register_uninstall_hook') ) { 43 register_uninstall_hook('openid/openid.php', 'openid_uninstall_plugin'); 44 } 45 add_action( 'init', 'openid_activate_wpmu' ); // wpmu activation 40 register_uninstall_hook('openid/openid.php', 'openid_uninstall_plugin'); 46 41 47 42 // run activation function if new revision of plugin 48 if ( get_option('openid_plugin_revision') === false || OPENID_PLUGIN_REVISION != get_option('openid_plugin_revision')) {43 if ( get_option('openid_plugin_revision') === false || OPENID_PLUGIN_REVISION != get_option('openid_plugin_revision') ) { 49 44 add_action('admin_init', 'openid_activate_plugin'); 50 45 } 51 46 52 47 53 // -- public functions 48 // ---------------- // 49 // Public Functions // 50 // ---------------- // 54 51 55 52 /** … … 62 59 function is_user_openid($user = null) { 63 60 $urls = get_user_openids($user); 64 return ( !empty($urls));61 return ( !empty($urls) ); 65 62 } 66 63 … … 76 73 */ 77 74 function is_comment_openid($id = null) { 78 if ( is_numeric($id)) {75 if ( is_numeric($id) ) { 79 76 $comment = get_comment($id); 80 77 } else { … … 83 80 84 81 $openid_comments = get_post_meta($comment->comment_post_ID, 'openid_comments', true); 85 if (!is_array($openid_comments)) return false; 86 return (in_array($comment->comment_ID, $openid_comments)); 82 83 if ( is_array($openid_comments) ) { 84 if ( in_array($comment->comment_ID, $openid_comments) ) { 85 return true; 86 } 87 } 88 89 return false; 87 90 } 88 91 … … 98 101 function get_user_openids($id_or_name = null) { 99 102 $user = get_userdata_by_various($id_or_name); 100 return _get_user_openids($user->ID); 103 104 if ( $user ) { 105 global $wpdb; 106 return $wpdb->get_col( $wpdb->prepare('SELECT url FROM '.openid_identity_table().' WHERE user_id = %s', $user_id) ); 107 } else { 108 return array(); 109 } 101 110 } 102 111 … … 112 121 function get_user_by_openid($url) { 113 122 global $wpdb; 114 return $wpdb->get_var( wpdb_prepare('SELECT user_id FROM '.openid_identity_table().' WHERE url = %s', $url) );123 return $wpdb->get_var( $wpdb->prepare('SELECT user_id FROM '.openid_identity_table().' WHERE url = %s', $url) ); 115 124 } 116 125 … … 137 146 if (!function_exists('get_userdata_by_various')) : 138 147 function get_userdata_by_various($id_or_name = null) { 139 if ( $id_or_name === null) {148 if ( $id_or_name === null ) { 140 149 $user = wp_get_current_user(); 141 150 if ($user == null) return false; 142 151 return $user->data; 143 } else if ( is_numeric($id_or_name)) {152 } else if ( is_numeric($id_or_name) ) { 144 153 return get_userdata($id_or_name); 145 154 } else { … … 150 159 151 160 // -- end of public functions 161 152 162 153 163 /** … … 162 172 static $file; 163 173 164 if ( empty($file)) {174 if ( empty($file) ) { 165 175 $path = 'openid'; 166 176 167 177 $base = plugin_basename(__FILE__); 168 if ( $base != __FILE__) {178 if ( $base != __FILE__ ) { 169 179 $path = basename(dirname($base)); 170 180 } … … 176 186 } 177 187 178 ?> -
openid/trunk/server.php
r103625 r158694 3 3 require_once 'Auth/OpenID/Server.php'; 4 4 require_once 'server_ext.php'; 5 require_once 'server_eaut.php';6 5 7 6 add_filter( 'xrds_simple', 'openid_provider_xrds_simple'); 8 7 add_action( 'wp_head', 'openid_provider_link_tags'); 8 9 10 /** 11 * Get the URL of the OpenID server endpoint. 12 * 13 * @see openid_service_url 14 */ 15 function openid_server_url() { 16 return openid_service_url('server', 'login_post'); 17 } 9 18 10 19 … … 67 76 $services[] = array( 68 77 'Type' => $types, 69 'URI' => openid_serv ice_url('openid', 'server', 'login_post'),78 'URI' => openid_server_url(), 70 79 'LocalID' => get_author_posts_url($user->ID), 71 80 ); … … 78 87 $services[] = array( 79 88 'Type' => $types, 80 'URI' => openid_serv ice_url('openid', 'server', 'login_post'),89 'URI' => openid_server_url(), 81 90 'openid:Delegate' => get_author_posts_url($user->ID), 82 91 ); … … 86 95 array( 87 96 'Type' => array(array('content' => 'http://specs.openid.net/auth/2.0/server')), 88 'URI' => openid_serv ice_url('openid', 'server', 'login_post'),97 'URI' => openid_server_url(), 89 98 'LocalID' => 'http://specs.openid.net/auth/2.0/identifier_select', 90 99 ) … … 318 327 319 328 if (!$server || !is_a($server, 'Auth_OpenID_Server')) { 320 $server = new Auth_OpenID_Server(openid_getStore(), openid_serv ice_url('openid', 'server', 'login_post'));329 $server = new Auth_OpenID_Server(openid_getStore(), openid_server_url()); 321 330 } 322 331 … … 339 348 } 340 349 341 if ( $user) {350 if ( isset($user) && $user) { 342 351 // if user doesn't have capability, bail 343 352 $user_object = new WP_User($user->ID); … … 365 374 } 366 375 } else { 367 $server = openid_serv ice_url('openid', 'server', 'login_post');376 $server = openid_server_url(); 368 377 $identifier = get_author_posts_url($user->ID); 369 378 … … 446 455 if (is_user_logged_in()) { 447 456 $user = wp_get_current_user(); 448 $logout_url = site_url('wp-login.php?action=logout&redirect_to=' . urlencode(openid_serv ice_url('openid', 'server', 'login_post')), 'login');457 $logout_url = site_url('wp-login.php?action=logout&redirect_to=' . urlencode(openid_server_url()), 'login'); 449 458 echo ' 450 459 <div id="loggedin">' . sprintf(__('Logged in as %1$s (%2$s). <a href="%3$s">Use a different account?</a>', 'openid'), $user->display_name, $user->user_login, $logout_url ) . '</div>'; … … 454 463 </div> 455 464 456 <form action="' . openid_serv ice_url('openid', 'server', 'login_post') . '" method="post">465 <form action="' . openid_server_url() . '" method="post"> 457 466 <h1>'.__('Verify Your Identity', 'openid').'</h1> 458 467 <p style="margin: 1.5em 0 1em 0;">' … … 468 477 echo ' 469 478 <p class="submit" style="text-align: center; margin-top: 2.4em;"> 470 <a href="' . add_query_arg('openid_trust', 'cancel', openid_serv ice_url('openid', 'server', 'login_post')) . '">'.__('Cancel and go back', 'openid').'</a>479 <a href="' . add_query_arg('openid_trust', 'cancel', openid_server_url()) . '">'.__('Cancel and go back', 'openid').'</a> 471 480 <input type="submit" id="submit" name="openid_trust" value="'.__('Continue', 'openid').'" /> 472 481 </p> … … 501 510 * @return bool true if successful 502 511 */ 503 function openid_server_ update_delegation_info($userid, $url = null) {512 function openid_server_get_delegation_info($userid, $url = null) { 504 513 if (empty($url)) $url = get_usermeta($userid, 'openid_delegate'); 505 514 if (empty($url)) return false; … … 567 576 if (empty($services)) return false; 568 577 569 update_usermeta($userid, 'openid_delegate', $url); 570 update_usermeta($userid, 'openid_delegate_services', $services); 571 return true; 578 return array( 579 'url' => $url, 580 'services' => $services 581 ); 572 582 } 573 583 -
openid/trunk/server_ext.php
r88142 r158694 11 11 return $types; 12 12 } 13 14 13 15 /** 14 16 * See if the OpenID authentication request includes SReg and add additional hooks if so. … … 18 20 if ($sreg_request) { 19 21 $GLOBALS['openid_server_sreg_request'] = $sreg_request; 20 add_action('openid_server_trust_form', 'openid_server_sreg_trust_form'); 22 add_action('openid_server_trust_form', 'openid_server_attributes_trust_form'); 23 add_filter('openid_server_trust_form_attributes', 'openid_server_sreg_trust_form'); 21 24 add_action('openid_server_trust_submit', 'openid_server_sreg_trust_submit', 10, 2); 22 25 add_filter('openid_server_store_trusted_site', 'openid_server_sreg_store_trusted_site'); … … 29 32 * Add SReg input fields to the OpenID Trust Form 30 33 */ 31 function openid_server_sreg_trust_form( ) {34 function openid_server_sreg_trust_form( $attributes ) { 32 35 $sreg_request = $GLOBALS['openid_server_sreg_request']; 33 36 $sreg_fields = $sreg_request->allRequestedFields(); 34 37 35 38 if (!empty($sreg_fields)) { 36 $display_fields = array();37 39 foreach ($sreg_fields as $field) { 38 40 $value = openid_server_sreg_from_profile($field); 39 41 if (!empty($value)) { 40 $ display_fields[] = strtolower($GLOBALS['Auth_OpenID_sreg_data_fields'][$field]);42 $attributes[] = strtolower($GLOBALS['Auth_OpenID_sreg_data_fields'][$field]); 41 43 } 42 44 } 45 } 43 46 44 if (!empty($display_fields)) {45 $fields = openid_server_sreg_field_string($display_fields); 47 return $attributes; 48 } 46 49 47 echo '48 <p class="trust_form_add" style="padding: 0">49 <input type="checkbox" id="include_sreg" name="include_sreg" checked="checked" style="display: block; float: left; margin: 0.8em;" />50 <label for="include_sreg" style="display: block; padding: 0.5em 2em;">'.sprintf(__('Also grant access to see my %s.', 'openid'), $fields) . '</label>51 </p>';52 }53 50 51 /** 52 * Add attribute input fields to the OpenID Trust Form 53 */ 54 function openid_server_attributes_trust_form() { 55 $attributes = apply_filters('openid_server_trust_form_attributes', array()); 56 57 if (!empty($attributes)) { 58 $attr_string = openid_server_attributes_string($attributes); 59 60 echo ' 61 <p class="trust_form_add" style="padding: 0"> 62 <input type="checkbox" id="include_sreg" name="include_sreg" checked="checked" style="display: block; float: left; margin: 0.8em;" /> 63 <label for="include_sreg" style="display: block; padding: 0.5em 2em;">'.sprintf(__('Also grant access to see my %s.', 'openid'), $attr_string) . '</label> 64 </p>'; 54 65 } 55 66 } 56 67 57 function openid_server_sreg_field_string($fields, $string = '') { 68 69 /** 70 * Convert list of attribute names to human readable string. 71 */ 72 function openid_server_attributes_string($fields, $string = '') { 58 73 if (empty($fields)) return $string; 59 74 … … 68 83 } 69 84 70 return openid_server_ sreg_field_string($fields, $string);85 return openid_server_attributes_string($fields, $string); 71 86 } 72 87 -
openid/trunk/store.php
r88142 r158694 234 234 function openid_create_tables() 235 235 { 236 global $wp _version, $wpdb;236 global $wpdb; 237 237 238 238 $store = openid_getStore(); 239 239 240 if ($wp_version >= '2.3') { 241 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 242 } else { 243 require_once(ABSPATH . 'wp-admin/admin-db.php'); 244 require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); 245 } 240 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 246 241 247 242 // Create the SQL and call the WP schema upgrade function … … 272 267 global $wpdb; 273 268 $wpdb->query('DROP TABLE IF EXISTS ' . openid_identity_table()); 274 $wpdb->query( wpdb_prepare('DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key=%s', 'openid_comments'));269 $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key=%s', 'openid_comments') ); 275 270 276 271 // old database changes... just to make sure … … 282 277 if ($openid_column) { 283 278 $wpdb->query('ALTER table ' . $comments_table . ' DROP COLUMN openid'); 284 $wpdb->query( wpdb_prepare('UPDATE ' . $comments_table . ' SET comment_type=%s WHERE comment_type=%s', '', 'openid'));279 $wpdb->query( $wpdb->prepare('UPDATE ' . $comments_table . ' SET comment_type=%s WHERE comment_type=%s', '', 'openid') ); 285 280 } 286 281 } … … 302 297 // migrate them en masse rather than using set_comment_openid() 303 298 $comments_table = openid_table_prefix(true) . 'comments'; 304 $comment_data = $wpdb->get_results( wpdb_prepare('SELECT comment_ID, comment_post_ID from ' . $comments_table . ' WHERE openid=%s OR comment_type=%s', 1, 'openid'));299 $comment_data = $wpdb->get_results( $wpdb->prepare('SELECT comment_ID, comment_post_ID from ' . $comments_table . ' WHERE openid=%s OR comment_type=%s', 1, 'openid') ); 305 300 if (!empty($comment_data)) { 306 301 $openid_comments = array(); … … 320 315 321 316 $wpdb->query('ALTER table ' . $comments_table . ' DROP COLUMN openid'); 322 $wpdb->query( wpdb_prepare('UPDATE ' . $comments_table . ' SET comment_type=%s WHERE comment_type=%s', '', 'openid'));317 $wpdb->query( $wpdb->prepare('UPDATE ' . $comments_table . ' SET comment_type=%s WHERE comment_type=%s', '', 'openid') ); 323 318 } 324 319 … … 326 321 // remove old style of marking openid users 327 322 $usermeta_table = defined('CUSTOM_USER_META_TABLE') ? CUSTOM_USER_META_TABLE : openid_table_prefix() . 'usermeta'; 328 $wpdb->query( wpdb_prepare('DELETE FROM ' . $usermeta_table . ' WHERE meta_key=%s OR meta_key=%s', 'has_openid', 'registered_with_openid'));323 $wpdb->query( $wpdb->prepare('DELETE FROM ' . $usermeta_table . ' WHERE meta_key=%s OR meta_key=%s', 'has_openid', 'registered_with_openid') ); 329 324 } 330 325
Note: See TracChangeset
for help on using the changeset viewer.