Example #1
0
/**
 * Get the internal OpenID Consumer object.  If it is not already initialized, do so.
 *
 * @return Auth_OpenID_Consumer OpenID consumer object
 */
function openid_getConsumer()
{
    static $consumer;
    if (!$consumer) {
        require_once 'Auth/OpenID/Consumer.php';
        $store = openid_getStore();
        $consumer = new Auth_OpenID_Consumer($store);
        if (null === $consumer) {
            openid_error('OpenID consumer could not be created properly.');
            openid_enabled(false);
        }
    }
    return $consumer;
}
Example #2
0
/**
 * Get the internal OpenID Consumer object.  If it is not already initialized, do so.
 *
 * @return Auth_OpenID_Consumer OpenID consumer object
 */
function openid_getConsumer() {
	static $consumer;

	if (!$consumer) {
		set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
		require_once 'Auth/OpenID/Consumer.php';
		restore_include_path();

		$store = openid_getStore();
		$consumer = new Auth_OpenID_Consumer($store);
		if( null === $consumer ) {
			openid_error('OpenID consumer could not be created properly.');
			openid_enabled(false);
		}

	}

	return $consumer;
}
Example #3
0
/**
 * Create OpenID related tables in the WordPress database.
 */
function openid_create_tables()
{
	global $wpdb;

	$store = openid_getStore();

	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

	// Create the SQL and call the WP schema upgrade function
	$statements = array(
		"CREATE TABLE ".openid_identity_table()." (
		uurl_id bigint(20) NOT NULL auto_increment,
		user_id bigint(20) NOT NULL default '0',
		url text,
		hash char(32),
		PRIMARY KEY  (uurl_id),
		UNIQUE KEY uurl (hash),
		KEY url (url(30)),
		KEY user_id (user_id)
		)",
	);

	$sql = implode(';', $statements);
	dbDelta($sql);

	update_option('openid_db_revision', OPENID_DB_REVISION);
}
Example #4
0
/**
 * Get Auth_OpenID_Server singleton.
 *
 * @return object Auth_OpenID_Server singleton instance
 */
function openid_server()
{
    static $server;
    if (!$server || !is_a($server, 'Auth_OpenID_Server')) {
        $server = new Auth_OpenID_Server(openid_getStore(), trailingslashit(get_option('siteurl')) . '?openid_server=1');
    }
    return $server;
}
Example #5
0
/**
 * Cleanup expired nonces and associations from the OpenID store.
 */
function openid_cleanup()
{
    $store =& openid_getStore();
    $store->cleanupNonces();
    $store->cleanupAssociations();
}
Example #6
0
function openid_options_page()
{
    global $wp_version, $wpdb, $wp_roles;
    if (isset($_REQUEST['action'])) {
        switch ($_REQUEST['action']) {
            case 'rebuild_tables':
                check_admin_referer('openid-rebuild_tables');
                $store = openid_getStore();
                $store->reset();
                echo '<div class="updated"><p><strong>' . __('OpenID cache refreshed.', 'openid') . '</strong></p></div>';
                break;
        }
    }
    // if we're posted back an update, let's set the values here
    if (isset($_POST['info_update'])) {
        check_admin_referer('openid-info_update');
        $error = '';
        update_option('openid_enable_commentform', isset($_POST['enable_commentform']) ? true : false);
        update_option('openid_enable_approval', isset($_POST['enable_approval']) ? true : false);
        update_option('openid_no_require_name', isset($_POST['no_require_name']) ? true : false);
        update_option('openid_enable_email_mapping', isset($_POST['enable_email_mapping']) ? true : false);
        update_option('openid_required_for_registration', isset($_POST['openid_required_for_registration']) ? true : false);
        update_option('openid_blog_owner', $_POST['openid_blog_owner']);
        // set OpenID Capability
        foreach ($wp_roles->role_names as $key => $name) {
            $role = $wp_roles->get_role($key);
            $option_set = $_POST['openid_cap_' . htmlentities($key)] == 'on' ? true : false;
            if ($role->has_cap('use_openid_provider')) {
                if (!$option_set) {
                    $role->remove_cap('use_openid_provider');
                }
            } else {
                if ($option_set) {
                    $role->add_cap('use_openid_provider');
                }
            }
        }
        if ($error !== '') {
            echo '<div class="error"><p><strong>' . __('At least one of OpenID options was NOT updated', 'openid') . '</strong>' . $error . '</p></div>';
        } else {
            echo '<div class="updated"><p><strong>' . __('OpenID options updated', 'openid') . '</strong></p></div>';
        }
    }
    // Display the options page form
    $siteurl = get_option('home');
    if (substr($siteurl, -1, 1) !== '/') {
        $siteurl .= '/';
    }
    ?>
	<div class="wrap">
		<form method="post">

			<h2><?php 
    _e('OpenID Consumer Options', 'openid');
    ?>
</h2>

			<?php 
    openid_printSystemStatus();
    ?>

			<?php 
    if ($wp_version < '2.3') {
        ?>
			<p class="submit"><input type="submit" name="info_update" value="<?php 
        _e('Update Options');
        ?>
 &raquo;" /></p>
			<?php 
    }
    ?>

			<table class="form-table optiontable editform" cellspacing="2" cellpadding="5" width="100%">
				<tr valign="top">
					<th scope="row"><?php 
    _e('Comment Approval', 'openid');
    ?>
</th>
					<td>
						<p><input type="checkbox" name="enable_approval" id="enable_approval" <?php 
    echo get_option('openid_enable_approval') ? 'checked="checked"' : '';
    ?>
 />
							<label for="enable_approval"><?php 
    _e('Automatically approve comments left with verified OpenIDs.  ' . 'These comments will bypass all comment moderation.', 'openid');
    ?>
</label>
						</p>

						<?php 
    if (get_option('require_name_email')) {
        ?>
						<p><input type="checkbox" name="no_require_name" id="no_require_name" <?php 
        echo get_option('openid_no_require_name') ? 'checked="checked"' : '';
        ?>
 />
							<label for="no_require_name"><?php 
        _e('Don\'t require name and e-mail for comments left with verified OpenIDs.', 'openid');
        ?>
</label>
						</p>
						<?php 
    }
    ?>
						
					</td>
				</tr>

				<tr valign="top">
					<th scope="row"><?php 
    _e('Comment Form', 'openid');
    ?>
</th>
					<td>
						<p><input type="checkbox" name="enable_commentform" id="enable_commentform" <?php 
    if (get_option('openid_enable_commentform')) {
        echo 'checked="checked"';
    }
    ?>
 />
							<label for="enable_commentform"><?php 
    _e('Add OpenID help text to the comment form.', 'openid');
    ?>
</label></p>

						<p><?php 
    printf(__('This will work for most themes derived from Kubrick or Sandbox.  ' . 'Template authors can tweak the comment form as described in the %sreadme%s.', 'openid'), '<a href="' . clean_url(openid_plugin_url() . '/readme.txt') . '">', '</a>');
    ?>
</p>
						<br />
					</td>
				</tr>

				<?php 
    if (get_option('users_can_register')) {
        ?>
				<tr valign="top">
					<th scope="row"><?php 
        _e('Require OpenID', 'openid');
        ?>
</th>
					<td>
						<p><input type="checkbox" name="openid_required_for_registration" id="openid_required_for_registration" <?php 
        if (get_option('openid_required_for_registration')) {
            echo 'checked="checked"';
        }
        ?>
 />
							<label for="openid_required_for_registration"><?php 
        _e('New accounts can only be created with verified OpenIDs.', 'openid');
        ?>
</label></p>
					</td>
				</tr>
				<?php 
    }
    ?>

				<?php 
    /*
    <tr valign="top">
    	<th scope="row"><?php _e('Email Mapping:', 'openid') ?></th>
    	<td>
    		<p><input type="checkbox" name="enable_email_mapping" id="enable_email_mapping" <?php
    		if( get_option('openid_enable_email_mapping') ) echo 'checked="checked"'
    		?> />
    			<label for="enable_email_mapping"><?php _e('Enable email addresses to be mapped to OpenID URLs.', 'openid') ?></label></p>
    
    		<p><?php printf(__('This feature uses the Email-To-URL mapping specification to allow OpenID authentication'
    		. ' based on an email address.  If enabled, commentors who do not supply a valid OpenID URL will have their'
    		. ' supplied email address mapped to an OpenID.  If their email provider does not currently support email to'
    		. ' url mapping, the default provider %s will be used.', 'openid'), '<a href="http://emailtoid.net/" target="_blank">Emailtoid.net</a>') ?></p>
    		<br />
    	</td>
    </tr>
    */
    ?>

				<tr valign="top">
					<th scope="row"><?php 
    _e('Troubleshooting', 'openid');
    ?>
</th>
					<td>
						<p>

						<p><?php 
    printf(__('If users are experiencing problems logging in with OpenID, it may help to %1$srefresh the cache%2$s.', 'openid'), '<a href="' . wp_nonce_url(add_query_arg('action', 'rebuild_tables'), 'openid-rebuild_tables') . '">', '</a>');
    ?>
</p>
					</td>
				</tr>

			</table>

			<br class="clear" />


			<h2><?php 
    _e('OpenID Provider Options', 'openid');
    ?>
</h2>
			<?php 
    $current_user = wp_get_current_user();
    $current_user_url = get_author_posts_url($current_user->ID);
    ?>

			<p><?php 
    _e('The OpenID Provider allows authorized ' . 'users to use their author URL as an OpenID, either using their ' . 'local WordPress username and password, or by delegating to another OpenID Provider.', 'openid');
    ?>
</p>

			<table class="form-table optiontable editform" cellspacing="2" cellpadding="5" width="100%">
				<tr valign="top">
					<th scope="row"><?php 
    _e('Enable OpenID', 'openid');
    ?>
</th>
					<td>

						<p><?php 
    _e('Enable the local OpenID Provider for these roles:', 'openid');
    ?>
</p>

						<p>
							<?php 
    foreach ($wp_roles->role_names as $key => $name) {
        $role = $wp_roles->get_role($key);
        $checked = $role->has_cap('use_openid_provider') ? ' checked="checked"' : '';
        $option_name = 'openid_cap_' . htmlentities($key);
        echo '<input type="checkbox" id="' . $option_name . '" name="' . $option_name . '"' . $checked . ' /><label for="' . $option_name . '"> ' . $name . '</label><br />' . "\n";
    }
    ?>
						</p>
					</td>
				</tr>

			<?php 
    $users = get_users_of_blog();
    $users = array_filter($users, create_function('$u', '$u = new WP_User($u->user_id); return $u->has_cap("use_openid_provider");'));
    if (!empty($users)) {
        ?>
				<tr valign="top">
					<th scope="row"><?php 
        _e('Blog Owner', 'openid');
        ?>
</th>
					<td>

						<p><?php 
        printf(__('Authorized accounts on this blog can use their author URL (i.e. <em>%1$s</em>) as an OpenID. ' . 'The Blog Owner will be able to use the blog address (%2$s) as their OpenID.  If this is a ' . 'single-user blog, you should set this to your account.', 'openid'), sprintf('<a href="%1$s">%1$s</a>', $current_user_url), sprintf('<a href="%1$s">%1$s</a>', trailingslashit(get_option('home'))));
        ?>
						</p>

			<?php 
        if (defined('OPENID_DISALLOW_OWNER') && OPENID_DISALLOW_OWNER) {
            echo '
						<p class="error">' . __('A Blog Owner cannot be set for this blog.  To set a Blog Owner, ' . 'first remove the following line from your <code>wp-config.php</code>:', 'openid') . '<br /><code style="margin:1em;">define("OPENID_DISALLOW_OWNER", 1);</code>
						</p>';
        } else {
            $blog_owner = get_option('openid_blog_owner');
            if (empty($blog_owner) || $blog_owner == $current_user->user_login) {
                echo '<select id="openid_blog_owner" name="openid_blog_owner"><option value="">(none)</option>';
                foreach ($users as $user) {
                    $selected = get_option('openid_blog_owner') == $user->user_login ? ' selected="selected"' : '';
                    echo '<option value="' . $user->user_login . '"' . $selected . '>' . $user->user_login . '</option>';
                }
                echo '</select>';
            } else {
                echo '<p class="error">' . sprintf(__('Only the current Blog Owner (%s) can change this setting.', 'openid'), $blog_owner) . '</p>';
            }
        }
        ?>
						</td>
					</tr>
			<?php 
    }
    //!empty($users)
    ?>
				</table>

			<?php 
    wp_nonce_field('openid-info_update');
    ?>
			<p class="submit"><input type="submit" name="info_update" value="<?php 
    _e('Update Options');
    ?>
 &raquo;" /></p>
		</form>
	</div>
		<?php 
}
Example #7
0
/**
 * Get Auth_OpenID_Server singleton.
 *
 * @return object Auth_OpenID_Server singleton instance
 */
function openid_server() {
	static $server;

	if (!$server || !is_a($server, 'Auth_OpenID_Server')) {
		$server = new Auth_OpenID_Server(openid_getStore(), openid_server_url());
	}

	return $server;
}
function openid_options_page()
{
    global $wpdb, $wp_roles;
    if (isset($_REQUEST['action'])) {
        switch ($_REQUEST['action']) {
            case 'rebuild_tables':
                check_admin_referer('rebuild_tables');
                $store = openid_getStore();
                $store->reset();
                echo '<div class="updated"><p><strong>' . __('OpenID cache refreshed.', 'openid') . '</strong></p></div>';
                break;
        }
    }
    // Display the options page form
    screen_icon('openid');
    ?>
	<style type="text/css">
		#icon-openid { background-image: url("<?php 
    echo plugins_url('openid/f/icon.png');
    ?>
"); }
	</style>

	<div class="wrap">
		<form method="post" action="options.php">

			<h2><?php 
    _e('OpenID Settings', 'openid');
    ?>
</h2>

			<div class="updated fade"><p><?php 
    _e('Please note that all OpenID Consumer options have been moved to their respective sections of the ' . '<a href="options-general.php">General Settings</a> and <a href="options-discussion.php">Discussion Settings</a> pages.', 'openid');
    ?>
</p></div>


			<?php 
    $current_user = wp_get_current_user();
    $current_user_url = get_author_posts_url($current_user->ID);
    ?>

			<p><?php 
    _e('The OpenID Provider allows authorized ' . 'users to use their author URL as an OpenID, either using their ' . 'local WordPress username and password, or by delegating to another OpenID Provider.', 'openid');
    ?>
</p>

			<table class="form-table optiontable editform">
				<tr valign="top">
					<th scope="row"><?php 
    _e('Enable OpenID', 'openid');
    ?>
</th>
					<td>

						<p><?php 
    _e('Enable the local OpenID Provider for these roles:', 'openid');
    ?>
</p>

						<p>
							<?php 
    foreach ($wp_roles->role_names as $key => $name) {
        $name = _x($name, null);
        $role = $wp_roles->get_role($key);
        $checked = $role->has_cap('use_openid_provider') ? ' checked="checked"' : '';
        $option_name = 'openid_cap[' . htmlentities($key) . ']';
        echo '<input type="checkbox" id="' . $option_name . '" name="' . $option_name . '"' . $checked . ' /><label for="' . $option_name . '"> ' . $name . '</label><br />' . "\n";
    }
    ?>
						</p>
					</td>
				</tr>

			<?php 
    $users = get_users_of_blog();
    $users = array_filter($users, create_function('$u', '$u = new WP_User($u->user_id); return $u->has_cap("use_openid_provider");'));
    if (!empty($users)) {
        ?>
				<tr valign="top">
					<th scope="row"><?php 
        _e('Blog Owner', 'openid');
        ?>
</th>
					<td>

						<p><?php 
        printf(__('Authorized accounts on this blog can use their author URL (i.e. <em>%1$s</em>) as an OpenID. ' . 'The Blog Owner will be able to use the blog address (%2$s) as their OpenID.  If this is a ' . 'single-user blog, you should set this to your account.', 'openid'), sprintf('<a href="%1$s">%1$s</a>', $current_user_url), sprintf('<a href="%1$s">%1$s</a>', trailingslashit(get_option('home'))));
        ?>
						</p>

			<?php 
        if (defined('OPENID_DISALLOW_OWNER') && OPENID_DISALLOW_OWNER) {
            echo '
						<p class="error">' . __('A Blog Owner cannot be set for this blog.  To set a Blog Owner, ' . 'first remove the following line from your <code>wp-config.php</code>:', 'openid') . '<br /><code style="margin:1em;">define("OPENID_DISALLOW_OWNER", 1);</code>
						</p>';
        } else {
            $blog_owner = get_option('openid_blog_owner');
            if (empty($blog_owner) || $blog_owner == $current_user->user_login) {
                echo '<select id="openid_blog_owner" name="openid_blog_owner"><option value="">' . __('(none)', 'openid') . '</option>';
                foreach ($users as $user) {
                    $selected = get_option('openid_blog_owner') == $user->user_login ? ' selected="selected"' : '';
                    echo '<option value="' . $user->user_login . '"' . $selected . '>' . $user->user_login . '</option>';
                }
                echo '</select>';
            } else {
                echo '<p class="error">' . sprintf(__('Only the current Blog Owner (%s) can change this setting.', 'openid'), $blog_owner) . '</p>';
            }
        }
        ?>
					</td>
				</tr>
			<?php 
    }
    //!empty($users)
    ?>
			</table>

			<table class="form-table optiontable editform">
				<tr valign="top">
					<th scope="row"><?php 
    _e('Troubleshooting', 'openid');
    ?>
</th>
					<td>
						<?php 
    openid_printSystemStatus();
    ?>

						<p><?php 
    printf(__('If users are experiencing problems logging in with OpenID, it may help to %1$srefresh the cache%2$s.', 'openid'), '<a href="' . wp_nonce_url(add_query_arg('action', 'rebuild_tables'), 'rebuild_tables') . '">', '</a>');
    ?>
</p>
					</td>
				</tr>
			</table>

			<?php 
    settings_fields('openid');
    ?>
			<p class="submit"><input type="submit" class="button-primary" name="info_update" value="<?php 
    _e('Save Changes');
    ?>
" /></p>
		</form>
	</div>
		<?php 
}
Example #9
0
/**
 * Create OpenID related tables in the WordPress database.
 */
function openid_create_tables()
{
    global $wp_version, $wpdb;
    $store = openid_getStore();
    if ($wp_version >= '2.3') {
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    } else {
        require_once ABSPATH . 'wp-admin/admin-db.php';
        require_once ABSPATH . 'wp-admin/upgrade-functions.php';
    }
    // Create the SQL and call the WP schema upgrade function
    $statements = array("CREATE TABLE " . openid_identity_table() . " (\n\t\tuurl_id bigint(20) NOT NULL auto_increment,\n\t\tuser_id bigint(20) NOT NULL default '0',\n\t\turl text,\n\t\thash char(32),\n\t\tPRIMARY KEY  (uurl_id),\n\t\tUNIQUE KEY uurl (hash),\n\t\tKEY url (url(30)),\n\t\tKEY user_id (user_id)\n\t\t)");
    $sql = implode(';', $statements);
    dbDelta($sql);
    update_option('openid_db_revision', OPENID_DB_REVISION);
}