Plugin Directory

Changeset 158694


Ignore:
Timestamp:
09/28/2009 07:34:45 PM (16 years ago)
Author:
wnorris
Message:

first set of changes copied over from Google Code

Location:
openid/trunk
Files:
2 added
2 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • openid/trunk/Auth/OpenID/BigMath.php

    r67133 r158694  
    375375
    376376        // Try to load dynamic modules.
    377         if (!$loaded) {
     377        if (!$loaded && function_exists('dl')) {
    378378            foreach ($extension['modules'] as $module) {
    379379                if (@dl($module . "." . PHP_SHLIB_SUFFIX)) {
  • openid/trunk/Auth/OpenID/Consumer.php

    r67133 r158694  
    269269
    270270        if ($consumer_cls !== null) {
    271             $this->consumer =& new $consumer_cls($store);
     271            $this->consumer = new $consumer_cls($store);
    272272        } else {
    273             $this->consumer =& new Auth_OpenID_GenericConsumer($store);
     273            $this->consumer = new Auth_OpenID_GenericConsumer($store);
    274274        }
    275275
     
    667667
    668668        return call_user_func_array(array(&$this, $method),
    669                                     array($message, $endpoint, $return_to));
     669                                    array($message, &$endpoint, $return_to));
    670670    }
    671671
     
    11821182        list($unused, $services) = call_user_func($this->discoverMethod,
    11831183                                                  $claimed_id,
    1184                                                   $this->fetcher);
     1184                                                  &$this->fetcher);
    11851185
    11861186        if (!$services) {
     
    12961296                                                  array('response_nonce',
    12971297                                                        'claimed_id',
    1298                                                         'assoc_handle')),
     1298                                                        'assoc_handle',
     1299                                                        'op_endpoint')),
    12991300            Auth_OpenID_OPENID1_NS => array_merge($basic_sig_fields,
    13001301                                                  array('nonce'))
  • openid/trunk/Auth/OpenID/Message.php

    r67133 r158694  
    888888    function getAliasedArg($aliased_key, $default = null)
    889889    {
     890        if ($aliased_key == 'ns') {
     891            // Return the namespace URI for the OpenID namespace
     892            return $this->getOpenIDNamespace();
     893        }
     894
    890895        $parts = explode('.', $aliased_key, 2);
    891896
  • openid/trunk/Auth/OpenID/Server.php

    r67133 r158694  
    10981098                }
    10991099
    1100                 $setup_request =& new Auth_OpenID_CheckIDRequest(
     1100                $setup_request = new Auth_OpenID_CheckIDRequest(
    11011101                                                $this->identity,
    11021102                                                $this->return_to,
     
    16781678    {
    16791679        $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);
    16831683        $this->op_endpoint = $op_endpoint;
    16841684        $this->negotiator =& Auth_OpenID_getDefaultNegotiator();
  • openid/trunk/admin_panels.php

    r103625 r158694  
    11<?php
    22/**
    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,
    44 * and may change without notice.
    55 */
     
    77
    88// -- WordPress Hooks
     9add_action( 'admin_init', 'openid_admin_register_settings' );
    910add_action( 'admin_menu', 'openid_admin_panels' );
    1011add_action( 'personal_options_update', 'openid_personal_options_update' );
    1112add_action( 'openid_finish_auth', 'openid_finish_verify', 10, 2 );
    1213add_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 }
    2814
    2915
     
    3420 **/
    3521function openid_admin_panels() {
     22    add_filter('plugin_action_links', 'openid_plugin_action_links', 10, 2);
     23
    3624    // global options page
    3725    $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');
    4528   
    4629    // 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' );
    5031    add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");'));
    5132    add_action("load-$hookname", 'openid_profile_management' );
     33    add_action("load-$hookname", 'openid_style' );
    5234
    5335    // additional options for users authorized to use OpenID provider
     
    5638        add_action('show_user_profile', 'openid_extend_profile', 5);
    5739        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');
    5942
    6043        if (!get_usermeta($user->ID, 'openid_delegate')) {
    6144            $hookname = add_submenu_page('profile.php', __('Your Trusted Sites', 'openid'),
    6245                __('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' );
    6447            add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");'));
    6548        }
    6649    }
     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 */
     68function 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');
    6777}
    6878
     
    7787    foreach ($wp_roles->role_names as $key => $name) {
    7888        $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        }
    8094        if ($role->has_cap('use_openid_provider')) {
    8195            if (!$option_set) $role->remove_cap('use_openid_provider');
     
    109123 */
    110124function openid_options_page() {
    111     global $wp_version, $wpdb, $wp_roles;
     125    global $wpdb, $wp_roles;
    112126
    113127    if ( isset($_REQUEST['action']) ) {
     
    122136    }
    123137
    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    
    134138    // Display the options page form
    135139
    136     if (function_exists('screen_icon')):
    137         screen_icon('openid');
     140    screen_icon('openid');
    138141    ?>
    139142    <style type="text/css">
    140143        #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); }
    141144    </style>
    142     <?php endif; ?>
    143145
    144146    <div class="wrap">
    145147        <form method="post" action="options.php">
    146148
    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
    233155            <?php
    234156                $current_user = wp_get_current_user();
     
    250172                            <?php
    251173                foreach ($wp_roles->role_names as $key => $name) {
     174                    $name = _c($name);
    252175                    $role = $wp_roles->get_role($key);
    253176                    $checked = $role->has_cap('use_openid_provider') ? ' checked="checked"' : '';
     
    303226
    304227            ?>
    305                         </td>
    306                     </tr>
     228                    </td>
     229                </tr>
    307230            <?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'); ?>
    313246            <p class="submit"><input type="submit" class="button-primary" name="info_update" value="<?php _e('Save Changes') ?>" /></p>
    314247        </form>
     
    345278    }
    346279
    347     if (function_exists('screen_icon')):
    348         screen_icon('openid');
     280    screen_icon('openid');
    349281    ?>
    350282    <style type="text/css">
    351283        #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); }
    352284    </style>
    353     <?php endif; ?>
    354285
    355286    <div class="wrap">
     
    454385            update_usermeta($user->ID, 'openid_trusted_sites', $trusted_sites);
    455386            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);
    457388            echo '</p></div>';
    458389        }
     
    477408        if ($count) {
    478409            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);
    480411            echo '</p></div>';
    481412        }
     
    483414    }
    484415
    485     if (function_exists('screen_icon')):
    486         screen_icon('openid');
     416    screen_icon('openid');
    487417    ?>
    488418    <style type="text/css">
    489419        #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); }
    490420    </style>
    491     <?php endif; ?>
    492421
    493422    <div class="wrap">
     
    679608        echo '</div>';
    680609    }
    681     echo '</div>';
    682     echo '
     610    echo '</div>
    683611    <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();
    695613    </script>';
    696614}
     
    701619 */
    702620function openid_profile_management() {
    703     global $wp_version;
     621    global $action;
    704622   
    705     switch( $_REQUEST['action'] ) {
     623    wp_reset_vars( array('action') );
     624
     625    switch( $action ) {
    706626        case 'add':
    707627            check_admin_referer('openid-add_openid');
     
    734654
    735655        default:
    736             if ($message = $_REQUEST['message']) {
     656            if ( array_key_exists('message', $_REQUEST) ) {
     657                $message = $_REQUEST['message'];
    737658
    738659                $messages = array(
    739660                    '',
    740661                    '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.',
    742663                    'Added association with OpenID.',
    743664                );
     
    745666                if (is_numeric($message)) {
    746667                    $message = $messages[$message];
     668                } else {
     669                    $message = htmlentities2( $message );
    747670                }
    748671
    749672                $message = __($message, 'openid');
    750673
    751                 if ($_REQUEST['update_url']) {
     674                if (array_key_exists('update_url', $_REQUEST) && $_REQUEST['update_url']) {
    752675                    $message .= '<br />' .  __('<strong>Note:</strong> For security reasons, your profile URL has been updated to match your OpenID.', 'openid');
    753676                }
     
    768691function openid_profile_delete_openids($delete) {
    769692
    770     if (empty($delete) || $_REQUEST['cancel']) return;
     693    if (empty($delete) || array_key_exists('cancel', $_REQUEST)) return;
    771694    check_admin_referer('openid-delete_openids');
    772695
     
    808731
    809732    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) );
    811734        openid_status('success');
    812735
     
    854777            set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
    855778            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');
    861780
    862781            if (!openid_ensure_url_match($user)) {
     
    870789    $finish_url = add_query_arg('status', openid_status(), $finish_url);
    871790    $finish_url = add_query_arg('message', $message, $finish_url);
    872     if ($update_url) {
     791    if ( isset($update_url) && $update_url ) {
    873792        $finish_url = add_query_arg('update_url', $update_url, $finish_url);
    874793    }
     
    876795    wp_safe_redirect($finish_url);
    877796    exit;
    878 }
    879 
    880 
    881 /**
    882  * Prior to WordPress 2.5, the 'personal_options_update' hook was called
    883  * AFTER updating the user's profile.  We need to ensure the profile URL
    884  * 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;
    892797}
    893798
     
    928833
    929834
     835/**
     836 * Add OpenID options to the WordPress user profile page.
     837 */
    930838function openid_extend_profile() {
    931839    $user = wp_get_current_user();
     
    947855}
    948856
     857
     858/**
     859 * Update OpenID options set from the WordPress user profile page.
     860 */
    949861function openid_profile_update($user_id) {
    950     if (empty($_POST['openid_delegate'])) {
     862    global $openid_user_delegation_info;
     863
     864    if ( empty($_POST['openid_delegate']) ) {
    951865        delete_usermeta($user_id, 'openid_delegate');
     866        delete_usermeta($user_id, 'openid_delegate_services');
    952867    } 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 */
     877function 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 */
     906function openid_wpmu_options() {
     907    $registration = get_site_option('registration');
     908    if ( $registration == 'all' || $registration == 'user' ):
    966909?>
     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 */
     938function 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 */
     951function 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 */
     974function 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  
    88// -- WordPress Hooks
    99add_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 }
     10add_action( 'init', 'openid_setup_akismet');
    1511add_action( 'akismet_spam_caught', 'openid_akismet_spam_caught');
    1612add_action( 'comment_post', 'update_comment_openid', 5 );
     
    2319add_filter( 'get_comment_author_link', 'openid_comment_author_link');
    2420if( get_option('openid_enable_commentform') ) {
    25     add_action( 'wp_head', 'openid_js_setup', 9);
     21    add_action( 'wp', 'openid_js_setup', 9);
    2622    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);
    2824}
    2925add_filter( 'openid_user_data', 'openid_get_user_data_form', 6, 2);
     
    3228add_action( 'init', 'openid_recent_comments');
    3329
     30
     31/**
     32 * Ensure akismet runs before OpenID.
     33 */
     34function 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
    3442/**
    3543 * Akismet caught this comment as spam, so no need to do OpenID discovery on the URL.
    3644 */
    3745function openid_akismet_spam_caught() {
    38     remove_action( 'preprocess_comment', 'openid_process_comment', -98);
     46    remove_action( 'preprocess_comment', 'openid_process_comment', -90);
    3947}
    4048
     
    4957 */
    5058function 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
    5168    @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.
    5872        $_SESSION['openid_comment_post'] = $_POST;
    5973        $_SESSION['openid_comment_post']['comment_author_openid'] = $openid_url;
     
    7286
    7387    // 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    }
    7591
    7692    return $comment;
     
    126142    }
    127143
    128     if ($_REQUEST['openid_skip']) {
     144    if (array_key_exists('openid_skip', $_REQUEST) && $_REQUEST['openid_skip']) {
    129145        return get_option('openid_no_require_name') ? false : $value;
    130146    }
     
    197213 */
    198214function update_comment_openid($comment_ID) {
     215    session_start();
     216
    199217    if ($_SESSION['openid_posted_comment']) {
    200218        set_comment_openid($comment_ID);
     
    219237    global $wp_scripts;
    220238
    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')) {
    226240        echo '<script type="text/javascript">stylize_profilelink()</script>';
    227241    }
     
    237251    global $wp_scripts;
    238252
    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
    245263    }
    246264}
     
    359377 */
    360378function 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) {
    364384        return $data;
    365385    }
     
    380400
    381401function openid_recent_comments() {
    382     if (is_active_widget('wp_widget_recent_comments')) {
     402    if ( is_active_widget('wp_widget_recent_comments') ) {
    383403        remove_action('wp_head', 'wp_widget_recent_comments_style');
     404
    384405        // 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        }
    386413    }
    387414}
  • openid/trunk/common.php

    r103625 r158694  
    99
    1010// include internal stylesheet
    11 add_action( 'wp_head', 'openid_style');
     11add_action( 'wp', 'openid_style');
    1212
    1313// parse request
     
    1616add_action('generate_rewrite_rules', 'openid_rewrite_rules');
    1717
    18 add_action( 'delete_user', 'delete_user_openids' );
    1918add_action( 'cleanup_openid', 'openid_cleanup' );
    2019
    21 
    22 // hooks for getting user data
    23 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);
    2520
    2621add_filter( 'openid_user_data', 'openid_get_user_data_sreg', 8, 2);
    2722add_filter( 'openid_user_data', 'openid_get_user_data_ax', 10, 2);
    2823
    29 add_filter( 'xrds_simple', 'openid_consumer_xrds_simple');
    3024
    3125
     
    4640 */
    4741function 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}
    6844
    6945
     
    8561
    8662/**
    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.
    12364 *
    12465 * @see register_activation_hook
     
    14687    add_option( 'openid_db_revision', 0 );
    14788    add_option( 'openid_enable_approval', false );
    148     add_option( 'openid_enable_email_mapping', false );
    14989    add_option( 'openid_xrds_returnto', true );
    150     add_option( 'openid_xrds_idib', true );
    151     add_option( 'openid_xrds_eaut', true );
    15290    add_option( 'openid_comment_displayname_length', 12 );
    15391
     
    16098
    16199    // flush rewrite rules
    162     if (!isset($wp_rewrite)) { $wp_rewrite = new WP_Rewrite(); }
     100    if ( !isset($wp_rewrite) ) { $wp_rewrite = new WP_Rewrite(); }
    163101    $wp_rewrite->flush_rules();
    164102
     
    190128    delete_option('force_openid_registration');
    191129    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');
    192134}
    193135
     
    220162    delete_option('openid_db_revision');
    221163    delete_option('openid_enable_approval');
    222     delete_option('openid_enable_email_mapping');
    223164    delete_option('openid_xrds_returnto');
    224     delete_option('openid_xrds_idib');
    225     delete_option('openid_xrds_eaut');
    226165    delete_option('openid_comment_displayname_length');
    227166    delete_option('openid_associations');
     
    270209
    271210    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 object
    279  * @param string $trust_root OpenID trust root
    280  * @param string $return_to URL where the OpenID provider should return the user
    281  */
    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 POST
    294     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;
    347211}
    348212
     
    366230            continue;
    367231        }
     232        // TODO: add hook
    368233        return $username;
    369234    }
     
    379244 * @param string $username username to be normalized
    380245 * @return string normalized username
     246 * @uses apply_filters() Calls 'openid_normalize_username' just before returning normalized username
    381247 */
    382248function 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;
    469260}
    470261
     
    486277    $trust_root = apply_filters('openid_trust_root', $trust_root, $return_to);
    487278    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;
    529279}
    530280
     
    548298
    549299    $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);
    556301
    557302    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 performed
    565  * @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);
    570303}
    571304
     
    585318    @include_once( ABSPATH . WPINC . '/registration-functions.php'); // 2.0.4
    586319
    587     // use email address for username if URL is from emailtoid.net
    588     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 
    596320    // otherwise, try to use preferred username
    597     if (empty($username) && $user_data['nickname']) {
     321    if ( empty($username) && array_key_exists('nickname', $user_data) ) {
    598322        $username = openid_generate_new_username($user_data['nickname'], false);
    599323    }
     
    782506
    783507/**
    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 Service
    791         $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 Service
    799         $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 Service
    812         $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 /**
    821508 * Parse the WordPress request.  If the query var 'openid' is present, then
    822509 * handle the request accordingly.
     
    840527                    $action = 'login';
    841528                    if (empty($_SESSION['openid_finish_url'])) {
    842                         $_SESSION['openid_finish_url'] = get_option('home');
     529                        //$_SESSION['openid_finish_url'] = get_option('home');
    843530                    }
    844531                }
     
    851538                break;
    852539
    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                }
    857546        }
    858547    }
     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 */
     557function is_url_openid( $url ) {
     558    $auth_request = openid_begin_consumer( $url );
     559    return ( $auth_request != null );
    859560}
    860561
     
    903604 * Build an OpenID service URL.
    904605 *
    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
    907607 * @param string $scheme URL scheme to use for URL (see site_url())
    908  * @param boolean $absolute should we return an absolute URL
    909608 * @return string service URL
    910609 * @see site_url
    911610 */
    912 function openid_service_url($name, $value, $scheme = null, $absolute = true) {
     611function openid_service_url($service, $scheme = null) {
    913612    global $wp_rewrite;
    914613    if (!$wp_rewrite) $wp_rewrite = new WP_Rewrite();
    915614
    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;
    919620    } 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;
    937622    }
    938623
    939624    return $url;
    940625}
     626
    941627
    942628/**
     
    945631function openid_rewrite_rules($wp_rewrite) {
    946632    $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]',
    949634    );
    950635
     
    958643function openid_query_vars($vars) {
    959644    $vars[] = 'openid';
    960     $vars[] = 'eaut';
    961645    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);
    975646}
    976647
     
    1031702?>
    1032703<!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(); ?>>
    1034705<head>
    1035706    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     
    1055726
    1056727/**
    1057  * Enqueue required javascript libraries.
     728 * Enqueue required javascript libraries on appropriate pages.
    1058729 *
    1059730 * @action: init
    1060731 **/
    1061732function 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)
    1100744 **/
    1101745function 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 */
     767function delete_user_openids($userid) {
     768    openid_drop_all_identities($userid);
     769}
     770add_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 */
     779function openid_add_user_identity($user_id, $identity_url) {
     780    openid_add_identity($user_id, $identity_url);
    1107781}
    1108782
     
    1116790function openid_add_identity($user_id, $url) {
    1117791    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.
    1124799 *
    1125800 * @param int $user_id user id
    1126  * @return array OpenIDs for the user
    1127  */
    1128 function _get_user_openids($user_id) {
     801 * @param string $identity_url identity url to remove
     802 */
     803function openid_drop_identity($user_id, $identity_url) {
    1129804    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 */
     814function 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// -------------- //
    1133824
    1134825/**
     
    1142833
    1143834
    1144 /**
    1145  * Remove identity url from user.
    1146  *
    1147  * @param int $user_id user id
    1148  * @param string $identity_url identity url to remove
    1149  */
    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 id
    1160  */
    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 
    1167835function openid_error($msg) {
    1168836    error_log('[OpenID] ' . $msg);
  • openid/trunk/f/openid.css

    r88142 r158694  
    1010}
    1111
     12.openid_loading {
     13    background: url('ajax-loader.gif') right center no-repeat;
     14}
     15
    1216body.login #openid_identifier {
    1317    width: 92%;
     
    1923}
    2024
     25#openid_comment {
     26    margin: 0.8em 1em;
     27}
     28#openid_comment input {
     29    width: auto;
     30}
     31
    2132/* fix link color on wp-login.php */
    2233body.login form#loginform a.legacy,
     
    2536}
    2637
    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 */
    24
    35jQuery(function() {
     
    1113
    1214function stylize_profilelink() {
    13     jQuery("#commentform a[@href$='profile.php']").addClass('openid_link');
     15    jQuery("#commentform a[href$='profile.php']").addClass('openid_link');
    1416}
    1517
    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 */
     23function add_openid_to_comment_form(wp_url, nonce) {
     24    var openid_nonce = nonce;
    1725
    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');
    1929
    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());
    2731
    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)); } );
    3134
    32     if (children.length > 0)
    33         children.filter(':last').appendToText(html);
    34     else if (label.is(':hastext'))
    35         label.appendToText(html);
    36     else
    37         label.append(html);
    3835
    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    }
    4563}
    4664
  • openid/trunk/login.php

    r137082 r158694  
    66
    77
    8 // add OpenID input field to wp-login.php
    98add_action( 'login_head', 'openid_wp_login_head');
    109add_action( 'login_form', 'openid_wp_login_form');
    1110add_action( 'register_form', 'openid_wp_register_form', 9);
    1211add_action( 'register_post', 'openid_register_post', 10, 3);
    13 add_action( 'wp_authenticate', 'openid_wp_authenticate' );
    1412add_action( 'openid_finish_auth', 'openid_finish_login', 10, 2);
    1513add_filter( 'registration_errors', 'openid_clean_registration_errors', -99);
     
    1715add_action( 'init', 'openid_login_errors' );
    1816
    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 */
     23function 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);
    3528
    3629        // if we got this far, something is wrong
    3730        global $error;
    3831        $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}
     57add_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 */
     66function 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;
    4091}
    4192
     
    4697function openid_login_errors() {
    4798    $self = basename( $GLOBALS['pagenow'] );
    48        
    4999    if ($self != 'wp-login.php') return;
    50100
    51     if ($_REQUEST['openid_error']) {
     101    if ( array_key_exists('openid_error', $_REQUEST) ) {
    52102        global $error;
    53103        $error = htmlentities2($_REQUEST['openid_error']);
    54104    }
    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     }
    60105}
    61106
     
    66111function openid_wp_login_head() {
    67112    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'));
    71113}
    72114
     
    78120 **/
    79121function openid_wp_login_form() {
    80     global $wp_version;
    81 
    82122    echo '<hr id="openid_split" style="clear: both; margin-bottom: 1.0em; border: 0; border-top: 1px solid #999; height: 1px;" />';
    83123
    84124    echo '
    85125    <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 />
    87127        <input type="text" name="openid_identifier" id="openid_identifier" class="input openid_identifier" value="" size="20" tabindex="25" /></label>
    88128    </p>
     
    100140 **/
    101141function openid_wp_register_form() {
    102     global $wp_version;
    103 
    104142    echo '
    105143    <div style="width:100%;">'; //Added to fix IE problem
     
    134172    echo '
    135173        <p>
    136             <label style="display: block; margin-bottom: 5px;">' . $label . '</label>
     174            <label style="display: block; margin-bottom: 5px;">' . $label . '<br />
    137175            <input type="text" name="openid_identifier" id="openid_identifier" class="input openid_identifier" value="" size="20" tabindex="25" /></label>
    138176        </p>
     
    144182    </div>';
    145183
    146 }
    147 
    148 
    149 /**
    150  * Action method for completing the 'login' action.  This action is used when a user is logging in from
    151  * wp-login.php.
    152  *
    153  * @param string $identity_url verified OpenID URL
    154  */
    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 in
    203  * WordPress 2.5.x because it has the 'wp_authenticate' action call in the
    204  * 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     }
    212184}
    213185
     
    253225 */
    254226function 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();
    257229    }
    258230}
  • openid/trunk/openid.php

    r103625 r158694  
    1919
    2020$openid_include_path = dirname(__FILE__);
    21 if (file_exists(dirname(__FILE__) . '/openid')) {
    22     // for WPMU mu-plugins folder
    23     $openid_include_path .= PATH_SEPARATOR . dirname(__FILE__) . '/openid';
    24 }
    2521
    2622// check source of randomness
    27 if (!@is_readable('/dev/urandom')) define( 'Auth_OpenID_RAND_SOURCE', null );
     23if ( !@is_readable('/dev/urandom') ) {
     24    define('Auth_OpenID_RAND_SOURCE', null);
     25}
    2826
    2927set_include_path( $openid_include_path . PATH_SEPARATOR . get_include_path() );
    3028require_once 'common.php';
    31 require_once 'compatibility.php';
     29require_once 'consumer.php';
    3230require_once 'admin_panels.php';
    3331require_once 'comments.php';
     
    4038register_activation_hook('openid/openid.php', 'openid_activate_plugin');
    4139register_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
     40register_uninstall_hook('openid/openid.php', 'openid_uninstall_plugin');
    4641
    4742// run activation function if new revision of plugin
    48 if (get_option('openid_plugin_revision') === false || OPENID_PLUGIN_REVISION != get_option('openid_plugin_revision')) {
     43if ( get_option('openid_plugin_revision') === false || OPENID_PLUGIN_REVISION != get_option('openid_plugin_revision') ) {
    4944    add_action('admin_init', 'openid_activate_plugin');
    5045}
    5146
    5247
    53 // -- public functions
     48// ---------------- //
     49// Public Functions //
     50// ---------------- //
    5451
    5552/**
     
    6259function is_user_openid($user = null) {
    6360    $urls = get_user_openids($user);
    64     return (!empty($urls));
     61    return ( !empty($urls) );
    6562}
    6663
     
    7673 */
    7774function is_comment_openid($id = null) {
    78     if (is_numeric($id)) {
     75    if ( is_numeric($id) ) {
    7976        $comment = get_comment($id);
    8077    } else {
     
    8380
    8481    $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;
    8790}
    8891
     
    98101function get_user_openids($id_or_name = null) {
    99102    $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    }
    101110}
    102111
     
    112121function get_user_by_openid($url) {
    113122    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) );
    115124}
    116125
     
    137146if (!function_exists('get_userdata_by_various')) :
    138147function get_userdata_by_various($id_or_name = null) {
    139     if ($id_or_name === null) {
     148    if ( $id_or_name === null ) {
    140149        $user = wp_get_current_user();
    141150        if ($user == null) return false;
    142151        return $user->data;
    143     } else if (is_numeric($id_or_name)) {
     152    } else if ( is_numeric($id_or_name) ) {
    144153        return get_userdata($id_or_name);
    145154    } else {
     
    150159
    151160// -- end of public functions
     161
    152162
    153163/**
     
    162172    static $file;
    163173
    164     if (empty($file)) {
     174    if ( empty($file) ) {
    165175        $path = 'openid';
    166176
    167177        $base = plugin_basename(__FILE__);
    168         if ($base != __FILE__) {
     178        if ( $base != __FILE__ ) {
    169179            $path = basename(dirname($base));
    170180        }
     
    176186}
    177187
    178 ?>
  • openid/trunk/server.php

    r103625 r158694  
    33require_once 'Auth/OpenID/Server.php';
    44require_once 'server_ext.php';
    5 require_once 'server_eaut.php';
    65
    76add_filter( 'xrds_simple', 'openid_provider_xrds_simple');
    87add_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 */
     15function openid_server_url() {
     16    return openid_service_url('server', 'login_post');
     17}
    918
    1019
     
    6776            $services[] = array(
    6877                            'Type' => $types,
    69                             'URI' => openid_service_url('openid', 'server', 'login_post'),
     78                            'URI' => openid_server_url(),
    7079                            'LocalID' => get_author_posts_url($user->ID),
    7180                        );
     
    7887            $services[] = array(
    7988                            'Type' => $types,
    80                             'URI' => openid_service_url('openid', 'server', 'login_post'),
     89                            'URI' => openid_server_url(),
    8190                            'openid:Delegate' => get_author_posts_url($user->ID),
    8291                        );
     
    8695            array(
    8796                'Type' => array(array('content' => 'http://specs.openid.net/auth/2.0/server')),
    88                 'URI' => openid_service_url('openid', 'server', 'login_post'),
     97                'URI' => openid_server_url(),
    8998                'LocalID' => 'http://specs.openid.net/auth/2.0/identifier_select',
    9099            )
     
    318327
    319328    if (!$server || !is_a($server, 'Auth_OpenID_Server')) {
    320         $server = new Auth_OpenID_Server(openid_getStore(), openid_service_url('openid', 'server', 'login_post'));
     329        $server = new Auth_OpenID_Server(openid_getStore(), openid_server_url());
    321330    }
    322331
     
    339348    }
    340349
    341     if ($user) {
     350    if ( isset($user) && $user) {
    342351        // if user doesn't have capability, bail
    343352        $user_object = new WP_User($user->ID);
     
    365374            }
    366375        } else  {
    367             $server = openid_service_url('openid', 'server', 'login_post');
     376            $server = openid_server_url();
    368377            $identifier = get_author_posts_url($user->ID);
    369378
     
    446455        if (is_user_logged_in()) {
    447456            $user = wp_get_current_user();
    448             $logout_url = site_url('wp-login.php?action=logout&redirect_to=' . urlencode(openid_service_url('openid', 'server', 'login_post')), 'login');
     457            $logout_url = site_url('wp-login.php?action=logout&redirect_to=' . urlencode(openid_server_url()), 'login');
    449458            echo '
    450459                <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>';
     
    454463            </div>
    455464
    456             <form action="' . openid_service_url('openid', 'server', 'login_post') . '" method="post">
     465            <form action="' . openid_server_url() . '" method="post">
    457466            <h1>'.__('Verify Your Identity', 'openid').'</h1>
    458467            <p style="margin: 1.5em 0 1em 0;">'
     
    468477        echo '
    469478            <p class="submit" style="text-align: center; margin-top: 2.4em;">
    470                 <a href="' . add_query_arg('openid_trust', 'cancel', openid_service_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>
    471480                <input type="submit" id="submit" name="openid_trust" value="'.__('Continue', 'openid').'" />
    472481            </p>
     
    501510 * @return bool true if successful
    502511 */
    503 function openid_server_update_delegation_info($userid, $url = null) {
     512function openid_server_get_delegation_info($userid, $url = null) {
    504513    if (empty($url)) $url = get_usermeta($userid, 'openid_delegate');
    505514    if (empty($url)) return false;
     
    567576    if (empty($services)) return false;
    568577
    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    );
    572582}
    573583
  • openid/trunk/server_ext.php

    r88142 r158694  
    1111    return $types;
    1212}
     13
     14
    1315/**
    1416 * See if the OpenID authentication request includes SReg and add additional hooks if so.
     
    1820    if ($sreg_request) {
    1921        $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');
    2124        add_action('openid_server_trust_submit', 'openid_server_sreg_trust_submit', 10, 2);
    2225        add_filter('openid_server_store_trusted_site', 'openid_server_sreg_store_trusted_site');
     
    2932 * Add SReg input fields to the OpenID Trust Form
    3033 */
    31 function openid_server_sreg_trust_form() {
     34function openid_server_sreg_trust_form( $attributes ) {
    3235    $sreg_request = $GLOBALS['openid_server_sreg_request'];
    3336    $sreg_fields = $sreg_request->allRequestedFields();
    3437
    3538    if (!empty($sreg_fields)) {
    36         $display_fields = array();
    3739        foreach ($sreg_fields as $field) {
    3840            $value = openid_server_sreg_from_profile($field);
    3941            if (!empty($value)) {
    40                 $display_fields[] = strtolower($GLOBALS['Auth_OpenID_sreg_data_fields'][$field]);
     42                $attributes[] = strtolower($GLOBALS['Auth_OpenID_sreg_data_fields'][$field]);
    4143            }
    4244        }
     45    }
    4346
    44         if (!empty($display_fields)) {
    45             $fields = openid_server_sreg_field_string($display_fields);
     47    return $attributes;
     48}
    4649
    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         }
    5350
     51/**
     52 * Add attribute input fields to the OpenID Trust Form
     53 */
     54function 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>';
    5465    }
    5566}
    5667
    57 function openid_server_sreg_field_string($fields, $string = '') {
     68
     69/**
     70 * Convert list of attribute names to human readable string.
     71 */
     72function openid_server_attributes_string($fields, $string = '') {
    5873    if (empty($fields)) return $string;
    5974
     
    6883    }
    6984
    70     return openid_server_sreg_field_string($fields, $string);
     85    return openid_server_attributes_string($fields, $string);
    7186}
    7287
  • openid/trunk/store.php

    r88142 r158694  
    234234function openid_create_tables()
    235235{
    236     global $wp_version, $wpdb;
     236    global $wpdb;
    237237
    238238    $store = openid_getStore();
    239239
    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');
    246241
    247242    // Create the SQL and call the WP schema upgrade function
     
    272267    global $wpdb;
    273268    $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') );
    275270   
    276271    // old database changes... just to make sure
     
    282277    if ($openid_column) {
    283278        $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') );
    285280    }
    286281}
     
    302297        // migrate them en masse rather than using set_comment_openid()
    303298        $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') );
    305300        if (!empty($comment_data)) {
    306301            $openid_comments = array();
     
    320315
    321316        $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') );
    323318    }
    324319
     
    326321    // remove old style of marking openid users
    327322    $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') );
    329324}
    330325
Note: See TracChangeset for help on using the changeset viewer.