PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/admin_panels.php

https://github.com/abitgone/wordpress-openid
PHP | 1030 lines | 752 code | 190 blank | 88 comment | 125 complexity | e99997cc30ad00c093797a813504c34a MD5 | raw file
  1. <?php
  2. /**
  3. * All the code required for handling OpenID administration. These functions should not be considered public,
  4. * and may change without notice.
  5. */
  6. // -- WordPress Hooks
  7. add_action( 'admin_init', 'openid_admin_register_settings' );
  8. add_action( 'admin_menu', 'openid_admin_panels' );
  9. add_action( 'personal_options_update', 'openid_personal_options_update' );
  10. add_action( 'openid_finish_auth', 'openid_finish_verify', 10, 2 );
  11. add_filter( 'pre_update_option_openid_cap', 'openid_set_cap', 10, 2);
  12. /**
  13. * Setup admin menus for OpenID options and ID management.
  14. *
  15. * @action: admin_menu
  16. **/
  17. function openid_admin_panels() {
  18. add_filter('plugin_action_links', 'openid_plugin_action_links', 10, 2);
  19. // global options page
  20. $hookname = add_options_page(__('OpenID options', 'openid'), __('OpenID', 'openid'), 'manage_options', 'openid', 'openid_options_page' );
  21. add_action("load-$hookname", create_function('', 'add_thickbox();'));
  22. add_action("load-$hookname", 'openid_style');
  23. // all users can setup external OpenIDs
  24. $hookname = add_users_page(__('Your OpenIDs', 'openid'), __('Your OpenIDs', 'openid'), 'read', 'your_openids', 'openid_profile_panel' );
  25. add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");'));
  26. add_action("load-$hookname", 'openid_profile_management' );
  27. add_action("load-$hookname", 'openid_style' );
  28. // additional options for users authorized to use OpenID provider
  29. $user = wp_get_current_user();
  30. if ($user->has_cap('use_openid_provider')) {
  31. add_action('show_user_profile', 'openid_extend_profile', 5);
  32. add_action('profile_update', 'openid_profile_update');
  33. add_action('user_profile_update_errors', 'openid_profile_update_errors', 10, 3);
  34. add_action('load-profile.php', 'openid_style');
  35. if (!get_user_meta($user->ID, 'openid_delegate', true)) {
  36. $hookname = add_submenu_page('profile.php', __('Your Trusted Sites', 'openid'),
  37. __('Your Trusted Sites', 'openid'), 'read', 'openid_trusted_sites', 'openid_manage_trusted_sites' );
  38. add_action("load-$hookname", 'openid_style' );
  39. add_action("load-$hookname", create_function('', 'wp_enqueue_script("admin-forms");'));
  40. }
  41. }
  42. if ( function_exists('is_site_admin') ) {
  43. // add OpenID options to WPMU Site Admin page
  44. add_action('wpmu_options', 'openid_wpmu_options');
  45. add_action('update_wpmu_options', 'openid_update_wpmu_options');
  46. } else {
  47. // add OpenID options to General Settings page. For now, the only option on this page is dependent on the
  48. // 'users_can_register' option, so only add the OpenID Settings if that is set. If additional OpenID settings
  49. // are added to the General Settings page, this check may no longer be necessary
  50. if ( get_option('users_can_register') ) {
  51. add_settings_field('openid_general_settings', __('OpenID Settings', 'openid'), 'openid_general_settings',
  52. 'general', 'default');
  53. }
  54. }
  55. // add OpenID options to Discussion Settings page
  56. add_settings_field('openid_disucssion_settings', __('OpenID Settings', 'openid'), 'openid_discussion_settings', 'discussion', 'default');
  57. }
  58. /**
  59. * Register OpenID admin settings.
  60. */
  61. function openid_admin_register_settings() {
  62. register_setting('general', 'openid_required_for_registration');
  63. register_setting('discussion', 'openid_no_require_name');
  64. register_setting('discussion', 'openid_enable_approval');
  65. register_setting('discussion', 'openid_enable_commentform');
  66. register_setting('openid', 'openid_blog_owner');
  67. register_setting('openid', 'openid_cap');
  68. register_setting('openid', 'openid_secure_profile_urls');
  69. }
  70. /**
  71. * Intercept the call to set the openid_cap option. Instead of storing
  72. * this in the options table, set the capability on the appropriate roles.
  73. */
  74. function openid_set_cap($newvalue, $oldvalue) {
  75. global $wp_roles;
  76. $newvalue = (array) $newvalue;
  77. foreach ($wp_roles->role_names as $key => $name) {
  78. $role = $wp_roles->get_role($key);
  79. if (array_key_exists($key, $newvalue) && $newvalue[$key] == 'on') {
  80. $option_set = true;
  81. } else {
  82. $option_set = false;
  83. }
  84. if ($role->has_cap('use_openid_provider')) {
  85. if (!$option_set) $role->remove_cap('use_openid_provider');
  86. } else {
  87. if ($option_set) $role->add_cap('use_openid_provider');
  88. }
  89. }
  90. return $oldvalue;
  91. }
  92. /**
  93. * Add settings link to plugin page.
  94. */
  95. function openid_plugin_action_links($links, $file) {
  96. $this_plugin = openid_plugin_file();
  97. if($file == $this_plugin) {
  98. $links[] = '<a href="options-general.php?page=openid">' . __('Settings') . '</a>';
  99. }
  100. return $links;
  101. }
  102. /*
  103. * Display and handle updates from the Admin screen options page.
  104. *
  105. * @options_page
  106. */
  107. function openid_options_page() {
  108. global $wpdb, $wp_roles;
  109. if ( isset($_REQUEST['action']) ) {
  110. switch($_REQUEST['action']) {
  111. case 'rebuild_tables' :
  112. check_admin_referer('rebuild_tables');
  113. $store = openid_getStore();
  114. $store->reset();
  115. echo '<div class="updated"><p><strong>'.__('OpenID cache refreshed.', 'openid').'</strong></p></div>';
  116. break;
  117. }
  118. }
  119. // Display the options page form
  120. screen_icon('openid');
  121. ?>
  122. <style type="text/css">
  123. #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); }
  124. </style>
  125. <div class="wrap">
  126. <form method="post" action="options.php">
  127. <h2><?php _e('OpenID Settings', 'openid') ?></h2>
  128. <div class="updated fade"><p><?php _e('Please note that all OpenID Consumer options have been moved to their respective sections of the '
  129. . '<a href="options-general.php">General Settings</a> and <a href="options-discussion.php">Discussion Settings</a> pages.', 'openid') ?></p></div>
  130. <?php
  131. $current_user = wp_get_current_user();
  132. $current_user_url = get_author_posts_url($current_user->ID);
  133. ?>
  134. <p><?php _e('The OpenID Provider allows authorized '
  135. . 'users to use their author URL as an OpenID, either using their '
  136. . 'local WordPress username and password, or by delegating to another OpenID Provider.', 'openid'); ?></p>
  137. <table class="form-table optiontable editform">
  138. <tr valign="top">
  139. <th scope="row"><?php _e('Enable OpenID', 'openid') ?></th>
  140. <td>
  141. <p><?php _e('Enable the local OpenID Provider for these roles:', 'openid'); ?></p>
  142. <p>
  143. <?php
  144. foreach ($wp_roles->role_names as $key => $name) {
  145. $name = _x($name, null);
  146. $role = $wp_roles->get_role($key);
  147. $checked = $role->has_cap('use_openid_provider') ? ' checked="checked"' : '';
  148. $option_name = 'openid_cap[' . htmlentities($key) . ']';
  149. echo '<input type="checkbox" id="'.$option_name.'" name="'.$option_name.'"'.$checked.' /><label for="'.$option_name.'"> '.$name.'</label><br />' . "\n";
  150. }
  151. ?>
  152. </p>
  153. </td>
  154. </tr>
  155. <?php
  156. $users = get_users_of_blog();
  157. $users = array_filter($users, create_function('$u', '$u = new WP_User($u->user_id); return $u->has_cap("use_openid_provider");'));
  158. if (!empty($users)):
  159. ?>
  160. <tr valign="top">
  161. <th scope="row"><?php _e('Blog Owner', 'openid') ?></th>
  162. <td>
  163. <p><?php printf(__('Authorized accounts on this blog can use their author URL (i.e. <em>%1$s</em>) as an OpenID. '
  164. . 'The Blog Owner will be able to use the blog address (%2$s) as their OpenID. If this is a '
  165. . 'single-user blog, you should set this to your account.', 'openid'),
  166. sprintf('<a href="%1$s">%1$s</a>', $current_user_url), sprintf('<a href="%1$s">%1$s</a>', trailingslashit(get_option('home')))
  167. ); ?>
  168. </p>
  169. <?php
  170. if (defined('OPENID_DISALLOW_OWNER') && OPENID_DISALLOW_OWNER) {
  171. echo '
  172. <p class="error">' . __('A Blog Owner cannot be set for this blog. To set a Blog Owner, '
  173. . 'first remove the following line from your <code>wp-config.php</code>:', 'openid')
  174. . '<br /><code style="margin:1em;">define("OPENID_DISALLOW_OWNER", 1);</code>
  175. </p>';
  176. } else {
  177. $blog_owner = get_option('openid_blog_owner');
  178. if (empty($blog_owner) || $blog_owner == $current_user->user_login) {
  179. echo '<select id="openid_blog_owner" name="openid_blog_owner"><option value="">' . __('(none)', 'openid') . '</option>';
  180. foreach ($users as $user) {
  181. $selected = (get_option('openid_blog_owner') == $user->user_login) ? ' selected="selected"' : '';
  182. echo '<option value="'.$user->user_login.'"'.$selected.'>'.$user->user_login.'</option>';
  183. }
  184. echo '</select>';
  185. } else {
  186. echo '<p class="error">' . sprintf(__('Only the current Blog Owner (%s) can change this setting.', 'openid'), $blog_owner) . '</p>';
  187. }
  188. }
  189. ?>
  190. </td>
  191. </tr>
  192. <?php endif; //!empty($users) ?>
  193. <tr>
  194. <th scope="row"><?php _e('Security Settings', 'openid') ?></td>
  195. <td>
  196. <strong><?php _e('You can secure the OpenID plugin with the following options:', 'openid') ?></strong>
  197. <?php
  198. $opt_secure_profile_urls = get_option('openid_secure_profile_urls');
  199. ?>
  200. <p><label>
  201. <input type="checkbox" name="openid_secure_profile_urls" value="true"<?php checked($opt_secure_profile_urls == 'true', true) ?> />
  202. <?php _e('Require that users set their profile URL to one of their claimed OpenID URLs') ?>
  203. </label></p>
  204. </td>
  205. </tr>
  206. </table>
  207. <table class="form-table optiontable editform">
  208. <tr valign="top">
  209. <th scope="row"><?php _e('Troubleshooting', 'openid') ?></th>
  210. <td>
  211. <?php openid_printSystemStatus(); ?>
  212. <p><?php printf(__('If users are experiencing problems logging in with OpenID, it may help to %1$srefresh the cache%2$s.', 'openid'),
  213. '<a href="' . wp_nonce_url(add_query_arg('action', 'rebuild_tables'), 'rebuild_tables') . '">', '</a>'); ?></p>
  214. </td>
  215. </tr>
  216. </table>
  217. <?php settings_fields('openid'); ?>
  218. <p class="submit"><input type="submit" class="button-primary" name="info_update" value="<?php _e('Save Changes') ?>" /></p>
  219. </form>
  220. </div>
  221. <?php
  222. }
  223. /**
  224. * Handle user management of OpenID associations.
  225. *
  226. * @submenu_page: profile.php
  227. **/
  228. function openid_profile_panel() {
  229. global $error;
  230. if( !current_user_can('read') ) return;
  231. $user = wp_get_current_user();
  232. $status = openid_status();
  233. if( 'success' == $status ) {
  234. echo '<div class="updated"><p><strong>'.__('Success:', 'openid').'</strong> '.openid_message().'</p></div>';
  235. }
  236. elseif( 'warning' == $status ) {
  237. echo '<div class="error"><p><strong>'.__('Warning:', 'openid').'</strong> '.openid_message().'</p></div>';
  238. }
  239. elseif( 'error' == $status ) {
  240. echo '<div class="error"><p><strong>'.__('Error:', 'openid').'</strong> '.openid_message().'</p></div>';
  241. }
  242. if (!empty($error)) {
  243. echo '<div class="error"><p><strong>'.__('Error:', 'openid').'</strong> '.$error.'</p></div>';
  244. unset($error);
  245. }
  246. screen_icon('openid');
  247. ?>
  248. <style type="text/css">
  249. #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); }
  250. </style>
  251. <div class="wrap">
  252. <form action="<?php printf('%s?page=%s', $_SERVER['PHP_SELF'], $_REQUEST['page']); ?>" method="post">
  253. <h2><?php _e('Your Verified OpenIDs', 'openid') ?></h2>
  254. <p><?php _e('You may associate one or more OpenIDs with your account. This will '
  255. . 'allow you to login to WordPress with your OpenID instead of a username and password. '
  256. . '<a href="http://openid.net/what/" target="_blank">Learn more...</a>', 'openid')?></p>
  257. <div class="tablenav">
  258. <div class="alignleft actions">
  259. <select name="action">
  260. <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
  261. <option value="delete"><?php _e('Delete'); ?></option>
  262. </select>
  263. <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  264. <?php wp_nonce_field('openid-delete_openids'); ?>
  265. </div>
  266. <div class="clear"></div>
  267. </div>
  268. <div class="clear"></div>
  269. <table class="widefat">
  270. <thead>
  271. <tr>
  272. <th scope="col" class="check-column"><input type="checkbox" /></th>
  273. <th scope="col"><?php _e('Account', 'openid'); ?></th>
  274. </tr>
  275. </thead>
  276. <tbody>
  277. <?php
  278. $urls = get_user_openids($user->ID);
  279. if (empty($urls)) {
  280. echo '<tr><td colspan="2">'.__('No Verified Accounts.', 'openid').'</td></tr>';
  281. } else {
  282. foreach ($urls as $url) {
  283. echo '
  284. <tr>
  285. <th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="'.md5($url).'" /></th>
  286. <td>'.openid_display_identity($url).'</td>
  287. </tr>';
  288. }
  289. }
  290. ?>
  291. </tbody>
  292. </table>
  293. </form>
  294. <form method="post">
  295. <table class="form-table">
  296. <tr>
  297. <th scope="row"><label for="openid_identifier"><?php _e('Add OpenID', 'openid') ?></label></th>
  298. <td><input id="openid_identifier" name="openid_identifier" /></td>
  299. </tr>
  300. </table>
  301. <?php wp_nonce_field('openid-add_openid'); ?>
  302. <p class="submit">
  303. <input type="submit" class="button-primary" value="<?php _e('Add OpenID', 'openid') ?>" />
  304. <input type="hidden" name="action" value="add" >
  305. </p>
  306. </form>
  307. </div>
  308. <?php
  309. }
  310. function openid_manage_trusted_sites() {
  311. $user = wp_get_current_user();
  312. switch (@$_REQUEST['action']) {
  313. case 'add':
  314. check_admin_referer('openid-add_trusted_sites');
  315. $trusted_sites = get_user_meta($user->ID, 'openid_trusted_sites', true);
  316. if (!is_array($trusted_sites)) $trusted_sites = array();
  317. $sites = split("\n", $_REQUEST['sites']);
  318. $count = 0;
  319. foreach ($sites as $site) {
  320. $site = trim($site);
  321. if (empty($site)) continue;
  322. if (strpos($site, 'http') === false || strpos($sites, 'http') != 0) {
  323. $site = 'http://' . $site;
  324. }
  325. $site = esc_url($site);
  326. $site_hash = md5($site);
  327. if (array_key_exists($site_hash, $trusted_sites)) continue;
  328. $count++;
  329. $trusted_sites[$site_hash] = array('url' => $site);
  330. }
  331. if ($count) {
  332. update_user_meta($user->ID, 'openid_trusted_sites', $trusted_sites);
  333. echo '<div class="updated"><p>';
  334. printf( _n('Added %d trusted site.', 'Added %d trusted sites.', $count, 'openid'), $count);
  335. echo '</p></div>';
  336. }
  337. break;
  338. case 'delete':
  339. if (empty($_REQUEST['delete'])) break;
  340. check_admin_referer('openid-delete_trusted_sites');
  341. $trusted_sites = get_user_meta($user->ID, 'openid_trusted_sites', true);
  342. $count = 0;
  343. foreach ($_REQUEST['delete'] as $site_hash) {
  344. if (array_key_exists($site_hash, $trusted_sites)) {
  345. $trusted_sites[$site_hash] = null;
  346. $count++;
  347. }
  348. }
  349. update_user_meta($user->ID, 'openid_trusted_sites', array_filter($trusted_sites));
  350. if ($count) {
  351. echo '<div class="updated"><p>';
  352. printf( _n('Deleted %d trusted site.', 'Deleted %d trusted sites.', $count, 'openid'), $count);
  353. echo '</p></div>';
  354. }
  355. break;
  356. }
  357. screen_icon('openid');
  358. ?>
  359. <style type="text/css">
  360. #icon-openid { background-image: url("<?php echo plugins_url('openid/f/icon.png'); ?>"); }
  361. </style>
  362. <div class="wrap">
  363. <h2><?php _e('Your Trusted Sites', 'openid'); ?></h2>
  364. <p><?php _e('This is a list of sites that you can automatically login to using your OpenID account. '
  365. . 'You will not be asked to approve OpenID login requests for your trusted sites.' , 'openid'); ?></p>
  366. <form method="post">
  367. <div class="tablenav">
  368. <div class="alignleft actions">
  369. <select name="action">
  370. <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
  371. <option value="delete"><?php _e('Delete'); ?></option>
  372. </select>
  373. <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
  374. <?php wp_nonce_field('openid-delete_trusted_sites'); ?>
  375. </div>
  376. <div class="clear"></div>
  377. </div>
  378. <div class="clear"></div>
  379. <table class="widefat">
  380. <thead>
  381. <tr>
  382. <th scope="col" class="check-column"><input type="checkbox" /></th>
  383. <th scope="col"><?php _e('URL'); ?></th>
  384. <th scope="col"><?php _e('Last Login', 'openid'); ?></th>
  385. </tr>
  386. </thead>
  387. <tbody>
  388. <?php
  389. $trusted_sites = get_user_meta($user->ID, 'openid_trusted_sites', true);
  390. if(empty($trusted_sites)) {
  391. echo '<tr><td colspan="3">'.__('No Trusted Sites.', 'openid').'</td></tr>';
  392. } else {
  393. foreach( $trusted_sites as $site_hash => $site ) {
  394. if (array_key_exists('last_login', $site) && $site['last_login']) {
  395. $last_login = date(get_option('date_format') . ' - ' . get_option('time_format'), $site['last_login']);
  396. } else {
  397. $last_login = '-';
  398. }
  399. echo '
  400. <tr>
  401. <th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="'.$site_hash.'" /></th>
  402. <td>'.$site['url'].'</td>
  403. <td>'.$last_login.'</td>
  404. </tr>';
  405. }
  406. }
  407. ?>
  408. </tbody>
  409. </table>
  410. <div class="tablenav">
  411. <br class="clear" />
  412. </div>
  413. </form>
  414. <br class="clear" />
  415. <form method="post">
  416. <h3><?php _e('Import Trusted Sites', 'openid'); ?></h3>
  417. <p><?php _e('Enter a list of URLs to be added to your Trusted Sites.', 'openid'); ?></p>
  418. <table class="form-table" style="margin-top: 0">
  419. <tr>
  420. <th scope="row"><label for="sites"><?php _e('Add Sites', 'openid') ?></label></th>
  421. <td>
  422. <textarea id="sites" name="sites" cols="60" rows="5"></textarea><br /><?php _e('(One URL per line)', 'openid'); ?>
  423. </td>
  424. </tr>
  425. </table>
  426. <?php wp_nonce_field('openid-add_trusted_sites'); ?>
  427. <p class="submit">
  428. <input type="submit" class="button-primary" value="<?php _e('Add Sites', 'openid') ?>" />
  429. <input type="hidden" name="action" value="add" >
  430. </p>
  431. </form>
  432. </div>
  433. <?php
  434. }
  435. /**
  436. * Print the status of various system libraries. This is displayed on the main OpenID options page.
  437. **/
  438. function openid_printSystemStatus() {
  439. global $wp_version, $wpdb;
  440. $paths = explode(PATH_SEPARATOR, get_include_path());
  441. for($i=0; $i<sizeof($paths); $i++ ) {
  442. $paths[$i] = @realpath($paths[$i]);
  443. if (empty($paths[$i])) unset($paths[$i]);
  444. }
  445. $status = array();
  446. $status[] = array( 'PHP version', 'info', phpversion() );
  447. $status[] = array( 'PHP memory limit', 'info', ini_get('memory_limit') );
  448. $status[] = array( 'Include Path', 'info', $paths );
  449. $status[] = array( 'WordPress version', 'info', $wp_version );
  450. $status[] = array( 'PHP OpenID Library Version', 'info', Auth_OpenID_VERSION );
  451. $status[] = array( 'MySQL version', 'info', function_exists('mysql_get_client_info') ? mysql_get_client_info() : 'Mysql client information not available. Very strange, as WordPress requires MySQL.' );
  452. $status[] = array('WordPress\' table prefix', 'info', isset($wpdb->base_prefix) ? $wpdb->base_prefix : $wpdb->prefix );
  453. if ( extension_loaded('suhosin') ) {
  454. $status[] = array( 'Curl', false, 'Hardened php (suhosin) extension active -- curl version checking skipped.' );
  455. } else {
  456. $curl_message = '';
  457. if( function_exists('curl_version') ) {
  458. $curl_version = curl_version();
  459. if(isset($curl_version['version']))
  460. $curl_message .= 'Version ' . $curl_version['version'] . '. ';
  461. if(isset($curl_version['ssl_version']))
  462. $curl_message .= 'SSL: ' . $curl_version['ssl_version'] . '. ';
  463. if(isset($curl_message['libz_version']))
  464. $curl_message .= 'zlib: ' . $curl_version['libz_version'] . '. ';
  465. if(isset($curl_version['protocols'])) {
  466. if (is_array($curl_version['protocols'])) {
  467. $curl_message .= 'Supports: ' . implode(', ',$curl_version['protocols']) . '. ';
  468. } else {
  469. $curl_message .= 'Supports: ' . $curl_version['protocols'] . '. ';
  470. }
  471. }
  472. } else {
  473. $curl_message = 'This PHP installation does not have support for libcurl. Some functionality, such as '
  474. . 'fetching https:// URLs, will be missing and performance will slightly impared. See '
  475. . '<a href="http://www.php.net/manual/en/ref.curl.php">php.net/manual/en/ref.curl.php</a> about '
  476. . 'enabling libcurl support for PHP.';
  477. }
  478. $status[] = array( 'Curl Support', isset($curl_version), $curl_message );
  479. }
  480. if (extension_loaded('gmp') and @gmp_init(1)) {
  481. $status[] = array( 'Big Integer support', true, 'GMP is installed.' );
  482. } elseif (extension_loaded('bcmath') and @bcadd(1,1)==2) {
  483. $status[] = array( 'Big Integer support', true, 'BCMath is installed (though <a href="http://www.php.net/gmp">GMP</a> is preferred).' );
  484. } elseif (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
  485. $status[] = array( 'Big Integer support', false, 'The OpenID Library is operating in Dumb Mode. Recommend installing <a href="http://www.php.net/gmp">GMP</a> support.' );
  486. }
  487. $status[] = array( 'Plugin Revision', 'info', OPENID_PLUGIN_REVISION);
  488. $status[] = array( 'Plugin Database Revision', 'info', get_option('openid_db_revision'));
  489. if (function_exists('xrds_meta')) {
  490. $status[] = array( 'XRDS-Simple', 'info', 'XRDS-Simple plugin is installed.');
  491. } else {
  492. $status[] = array( 'XRDS-Simple', false, '<a href="http://wordpress.org/extend/plugins/xrds-simple/">XRDS-Simple</a> plugin is not installed. Some features may not work properly (including providing OpenIDs).');
  493. }
  494. $openid_enabled = openid_enabled();
  495. $status[] = array( '<strong>Overall Plugin Status</strong>', ($openid_enabled),
  496. ($openid_enabled ? '' : 'There are problems above that must be dealt with before the plugin can be used.') );
  497. if( $openid_enabled ) { // Display status information
  498. echo settings_fields('openid');
  499. echo'<p><strong>' . __('Status information:', 'openid') . '</strong> ' . __('All Systems Nominal', 'openid')
  500. . '<small> (<a href="#TB_inline?height=600&width=800&inlineId=openid_system_status" id="openid_status_link" class="thickbox" title="' . __('System Status', 'openid') . '">' . __('Toggle More/Less', 'openid') . '</a>)</small> </p>';
  501. } else {
  502. echo '<p><strong>' . __('Plugin is currently disabled. Fix the problem, then Deactivate/Reactivate the plugin.', 'openid')
  503. . '</strong></p>';
  504. }
  505. echo '<div id="openid_system_status" class="updated">';
  506. foreach( $status as $s ) {
  507. list ($name, $state, $message) = $s;
  508. echo '<div><strong>';
  509. if( $state === false ) {
  510. echo "<span style='color:red;'>[".__('FAIL', 'openid')."]</span> $name";
  511. } elseif( $state === true ) {
  512. echo "<span style='color:green;'>[".__('OK', 'openid')."]</span> $name";
  513. } else {
  514. echo "<span style='color:grey;'>[".__('INFO', 'openid')."]</span> $name";
  515. }
  516. echo ($message ? ': ' : '') . '</strong>';
  517. echo (is_array($message) ? '<ul><li>' . implode('</li><li>', $message) . '</li></ul>' : $message);
  518. echo '</div>';
  519. }
  520. echo '</div>
  521. <script type="text/javascript">
  522. jQuery("#openid_system_status").hide();
  523. </script>';
  524. }
  525. /**
  526. * Handle OpenID profile management.
  527. */
  528. function openid_profile_management() {
  529. global $action;
  530. wp_reset_vars( array('action') );
  531. switch( $action ) {
  532. case 'add':
  533. check_admin_referer('openid-add_openid');
  534. $user = wp_get_current_user();
  535. $auth_request = openid_begin_consumer($_POST['openid_identifier']);
  536. $userid = get_user_by_openid($auth_request->endpoint->claimed_id);
  537. if ($userid) {
  538. global $error;
  539. if ($user->ID == $userid) {
  540. $error = __('You already have this OpenID!', 'openid');
  541. } else {
  542. $error = __('This OpenID is already associated with another user.', 'openid');
  543. }
  544. return;
  545. }
  546. $finish_url = admin_url(current_user_can('edit_users') ? 'users.php' : 'profile.php');
  547. $finish_url = add_query_arg('page', $_REQUEST['page'], $finish_url);
  548. openid_start_login($_POST['openid_identifier'], 'verify', $finish_url);
  549. break;
  550. case 'delete':
  551. openid_profile_delete_openids($_REQUEST['delete']);
  552. break;
  553. default:
  554. if ( array_key_exists('message', $_REQUEST) ) {
  555. $message = $_REQUEST['message'];
  556. $messages = array(
  557. '',
  558. __('Unable to authenticate OpenID.', 'openid'),
  559. __('OpenID assertion successful, but this URL is already associated with another user on this blog.', 'openid'),
  560. __('Added association with OpenID.', 'openid')
  561. );
  562. if (is_numeric($message)) {
  563. $message = $messages[$message];
  564. } else {
  565. $message = htmlentities2( $message );
  566. }
  567. $message = __($message, 'openid');
  568. $opt_secure_profile_urls = get_option('openid_secure_profile_urls');
  569. if (array_key_exists('update_url', $_REQUEST) && $_REQUEST['update_url'] && opt_secure_profile_urls === true) {
  570. $message .= '<br />' . __('<strong>Note:</strong> For security reasons, your profile URL has been updated to match your OpenID.', 'openid');
  571. }
  572. openid_message($message);
  573. openid_status($_REQUEST['status']);
  574. }
  575. break;
  576. }
  577. }
  578. /**
  579. * Remove identity URL from current user account.
  580. *
  581. * @param int $id id of identity URL to remove
  582. */
  583. function openid_profile_delete_openids($delete) {
  584. if (empty($delete) || array_key_exists('cancel', $_REQUEST)) return;
  585. check_admin_referer('openid-delete_openids');
  586. $user = wp_get_current_user();
  587. $urls = get_user_openids($user->ID);
  588. if (sizeof($urls) == sizeof($delete) && !@$_REQUEST['confirm']) {
  589. $html = '
  590. <h1>'.__('OpenID Warning', 'openid').'</h1>
  591. <form action='.sprintf('%s?page=%s', $_SERVER['PHP_SELF'], $_REQUEST['page']).' method="post">
  592. <p>'.__('Are you sure you want to delete all of your OpenID associations? Doing so may prevent you from logging in.', 'openid').'</p>
  593. <div class="submit">
  594. <input type="submit" name="confirm" value="'.__("Yes I'm sure. Delete.", 'openid').'" />
  595. <input type="submit" name="cancel" value="'.__("No, don't delete.", 'openid').'" />
  596. </div>';
  597. foreach ($delete as $d) {
  598. $html .= '<input type="hidden" name="delete[]" value="'.$d.'" />';
  599. }
  600. $html .= wp_nonce_field('openid-delete_openids', '_wpnonce', true, false) . '
  601. <input type="hidden" name="action" value="delete" />
  602. </form>';
  603. openid_page($html, __('OpenID Warning', 'openid'));
  604. return;
  605. }
  606. $count = 0;
  607. foreach ($urls as $url) {
  608. if (in_array(md5($url), $_REQUEST['delete'])) {
  609. if (openid_drop_identity($user->ID, $url)) {
  610. $count++;
  611. }
  612. }
  613. }
  614. if ($count) {
  615. openid_message( sprintf(_n('Deleted %d OpenID association.', 'Deleted %d OpenID associations.', $count, 'openid'), $count) );
  616. openid_status('success');
  617. // ensure that profile URL is still a verified OpenID if opt_secure_profile_urls is set to true
  618. require_once 'Auth/OpenID.php';
  619. @include_once(ABSPATH . WPINC . '/registration.php'); // WP < 2.3
  620. @include_once(ABSPATH . 'wp-admin/includes/admin.php'); // WP >= 2.3
  621. $opt_secure_profile_urls = get_option('openid_secure_profile_urls');
  622. if ($opt_secure_profile_urls === true && !openid_ensure_url_match($user)) {
  623. $identities = get_user_openids($user->ID);
  624. wp_update_user( array('ID' => $user->ID, 'user_url' => $identities[0]) );
  625. openid_message(openid_message() . '<br />'.__('<strong>Note:</strong> For security reasons, your profile URL has been updated to match your OpenID.', 'openid'));
  626. }
  627. return;
  628. }
  629. openid_message(__('OpenID association delete failed: Unknown reason.', 'openid'));
  630. openid_status('error');
  631. }
  632. /**
  633. * Action method for completing the 'verify' action. This action is used adding an identity URL to a
  634. * WordPress user through the admin interface.
  635. *
  636. * @param string $identity_url verified OpenID URL
  637. */
  638. function openid_finish_verify($identity_url, $action) {
  639. if ($action != 'verify') return;
  640. $message;
  641. $user = wp_get_current_user();
  642. if (empty($identity_url)) {
  643. $message = openid_message();
  644. if (empty($message)) $message = 1;
  645. } else {
  646. if( !openid_add_identity($user->ID, $identity_url) ) {
  647. $message = 2;
  648. } else {
  649. $message = 3;
  650. // ensure that profile URL is a verified OpenID if opt_secure_profile_urls is set to true
  651. require_once 'Auth/OpenID.php';
  652. require_once(ABSPATH . 'wp-admin/includes/admin.php');
  653. $opt_secure_profile_urls = get_option('openid_secure_profile_urls');
  654. if ($opt_secure_profile_urls === true && !openid_ensure_url_match($user)) {
  655. wp_update_user( array('ID' => $user->ID, 'user_url' => $identity_url) );
  656. $update_url = 1;
  657. }
  658. }
  659. }
  660. $finish_url = $_SESSION['openid_finish_url'];
  661. $finish_url = add_query_arg('status', openid_status(), $finish_url);
  662. $finish_url = add_query_arg('message', $message, $finish_url);
  663. if ( isset($update_url) && $update_url ) {
  664. $finish_url = add_query_arg('update_url', $update_url, $finish_url);
  665. }
  666. wp_safe_redirect($finish_url);
  667. exit;
  668. }
  669. /**
  670. * hook in and call when user is updating their profile URL... make sure it is an OpenID they control.
  671. */
  672. function openid_personal_options_update() {
  673. if (!get_option('openid_secure_profile_urls') === true) return;
  674. $user = wp_get_current_user();
  675. if (!openid_ensure_url_match($user, $_POST['url'])) {
  676. wp_die(sprintf(__('For security reasons, your profile URL must be one of your claimed OpenIDs: %s', 'openid'),
  677. '<ul><li>' . join('</li><li>', get_user_openids($user->ID)) . '</li></ul>'));
  678. }
  679. }
  680. /**
  681. * Ensure that the user's profile URL matches one of their OpenIDs if opt_secure_profile_urls is set to true
  682. */
  683. function openid_ensure_url_match($user, $url = null) {
  684. $identities = get_user_openids($user->ID);
  685. if (empty($identities)) return true;
  686. require_once 'Auth/OpenID.php';
  687. if ($url == null) $url = $user->user_url;
  688. $url = Auth_OpenID::normalizeUrl($url);
  689. foreach ($identities as $id) {
  690. $id = Auth_OpenID::normalizeUrl($id);
  691. if ($id == $url) return true;
  692. }
  693. return false;
  694. }
  695. /**
  696. * Add OpenID options to the WordPress user profile page.
  697. */
  698. function openid_extend_profile() {
  699. $user = wp_get_current_user();
  700. echo '
  701. <table class="form-table">
  702. <tr>
  703. <th><label for="openid_delegate">'.__('OpenID Delegation', 'openid').'</label></th>
  704. <td>
  705. <p style="margin-top:0;">'.__('OpenID Delegation allows you to use an external OpenID provider of your choice.', 'openid').'</p>
  706. <p>
  707. <input type="text" id="openid_delegate" name="openid_delegate" class="openid_link" value="'.get_user_meta($user->ID, 'openid_delegate', true).'" /> '
  708. . __('To delegate, enter a valid OpenID. Otherwise leave this blank.', 'openid')
  709. . '</p>
  710. </td>
  711. </tr>
  712. </table>
  713. ';
  714. }
  715. /**
  716. * Update OpenID options set from the WordPress user profile page.
  717. */
  718. function openid_profile_update($user_id) {
  719. global $openid_user_delegation_info;
  720. if ( empty($_POST['openid_delegate']) ) {
  721. delete_user_meta($user_id, 'openid_delegate');
  722. delete_user_meta($user_id, 'openid_delegate_services');
  723. } else {
  724. update_user_meta($user_id, 'openid_delegate', $openid_user_delegation_info['url']);
  725. update_user_meta($user_id, 'openid_delegate_services', $openid_user_delegation_info['services']);
  726. }
  727. }
  728. /**
  729. * Report any OpenID errors during user profile updating.
  730. */
  731. function openid_profile_update_errors($errors, $update, $user) {
  732. global $openid_user_delegation_info;
  733. $delegate = Auth_OpenID::normalizeUrl($_POST['openid_delegate']);
  734. if ( empty($delegate) ) return $errors;
  735. $openid_user_delegation_info = openid_server_get_delegation_info($user->ID, $delegate);
  736. if (!$openid_user_delegation_info) {
  737. $errors->add('openid_delegate', sprintf(__('Unable to find any OpenID information for delegate URL %s', 'openid'), '<strong>'.$delegate.'</strong>'));
  738. } else {
  739. $id_select_count = 0;
  740. foreach ($openid_user_delegation_info['services'] as $service) {
  741. if ( array_key_exists('LocalID', $service) && $service['LocalID'] == Auth_OpenID_IDENTIFIER_SELECT ) {
  742. $id_select_count++;
  743. }
  744. }
  745. if ( count($openid_user_delegation_info['services']) <= $id_select_count ) {
  746. $errors->add('openid_delegate', sprintf(__('You cannot delegate to an OpenID provider which uses Identifier Select.', 'openid')));
  747. }
  748. }
  749. return $errors;
  750. }
  751. /**
  752. * Add OpenID options to the WordPress MU site options page.
  753. */
  754. function openid_wpmu_options() {
  755. $registration = get_site_option('registration');
  756. if ( $registration == 'all' || $registration == 'user' ):
  757. ?>
  758. <table id="openid_options" class="form-table">
  759. <tr valign="top">
  760. <th scope="row"></th>
  761. <td>
  762. <label for="openid_required_for_registration">
  763. <input type="checkbox" name="openid_required_for_registration" id="openid_required_for_registration" value="1"
  764. <?php checked(true, get_site_option('openid_required_for_registration')) ?> />
  765. <?php _e('New accounts can only be created with verified OpenIDs.', 'openid') ?>
  766. </label>
  767. </td>
  768. </tr>
  769. </table>
  770. <script type="text/javascript">
  771. jQuery(function() {
  772. jQuery('#openid_options').hide();
  773. var lastp = jQuery('td:has([name="registration"])').children("p:last");
  774. jQuery('#openid_required_for_registration').parent().insertBefore(lastp).wrap('<p></p>');
  775. });
  776. </script>
  777. <?php
  778. endif;
  779. }
  780. /**
  781. * Update the OpenID options set from the WordPress MU site options page.
  782. */
  783. function openid_update_wpmu_options() {
  784. $openid_required = array_key_exists('openid_required_for_registration', $_POST);
  785. if ($openid_required) {
  786. update_site_option('openid_required_for_registration', '1');
  787. } else {
  788. update_site_option('openid_required_for_registration', '0');
  789. }
  790. }
  791. /**
  792. * Add OpenID options to the WordPress general settings page.
  793. */
  794. function openid_general_settings() {
  795. if ( get_option('users_can_register') ): ?>
  796. <label for="openid_required_for_registration">
  797. <input type="checkbox" name="openid_required_for_registration" id="openid_required_for_registration" value="1"
  798. <?php checked(true, get_option('openid_required_for_registration')) ?> />
  799. <?php _e('New accounts can only be created with verified OpenIDs', 'openid') ?>
  800. </label>
  801. <?php endif; ?>
  802. <script type="text/javascript">
  803. jQuery(function() {
  804. jQuery('tr:has(#openid_required_for_registration)').hide();
  805. jQuery('#openid_required_for_registration')
  806. .parent().prepend('<br />').insertAfter('label:has(#users_can_register)');
  807. });
  808. </script>
  809. <?php
  810. }
  811. /**
  812. * Add OpenID options to the WordPress discussion settings page.
  813. */
  814. function openid_discussion_settings() {
  815. ?>
  816. <label for="openid_enable_commentform">
  817. <input type="checkbox" name="openid_enable_commentform" id="openid_enable_commentform" value="1" <?php
  818. echo checked(true, get_option('openid_enable_commentform')); ?> />
  819. <?php _e('Enable OpenID for comments', 'openid') ?>
  820. </label>
  821. <br />
  822. <?php if ( get_option('openid_enable_commentform') ): ?>
  823. <?php if ( get_option('require_name_email') ): ?>
  824. <label for="openid_no_require_name">
  825. <input type="checkbox" name="openid_no_require_name" id="openid_no_require_name" value="1" <?php
  826. echo checked(true, get_option('openid_no_require_name')) ; ?> />
  827. <?php _e('Do not require name and e-mail for comments left with a verified OpenID', 'openid') ?>
  828. </label>
  829. <br />
  830. <?php endif; ?>
  831. <label for="openid_enable_approval">
  832. <input type="checkbox" name="openid_enable_approval" id="openid_enable_approval" value="1" <?php
  833. echo checked(true, get_option('openid_enable_approval')); ?> />
  834. <?php _e('Always approve comments left with a verified OpenID', 'openid'); ?>
  835. </label>
  836. <br />
  837. <?php endif; ?>
  838. <?php
  839. }
  840. ?>