PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/openid/core.php

https://github.com/alx/alexgirard.com-blog
PHP | 202 lines | 117 code | 49 blank | 36 comment | 13 complexity | 128807ea13fa7f494e4280314ae07192 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. Plugin Name: WP-OpenID
  4. Plugin URI: http://wordpress.org/extend/plugins/openid
  5. Description: Allows the use of OpenID for account registration, authentication, and commenting. <em>By <a href="http://verselogic.net">Alan Castonguay</a>.</em>
  6. Author: Will Norris
  7. Author URI: http://willnorris.com/
  8. Version: 2.2.2
  9. License: Dual GPL (http://www.fsf.org/licensing/licenses/info/GPLv2.html) and Modified BSD (http://www.fsf.org/licensing/licenses/index_html#ModifiedBSD)
  10. */
  11. define ( 'WPOPENID_PLUGIN_REVISION', preg_replace( '/\$Rev: (.+) \$/', 'svn-\\1',
  12. '$Rev: 58444 $') ); // this needs to be on a separate line so that svn:keywords can work its magic
  13. define ( 'WPOPENID_DB_REVISION', 24426); // last plugin revision that required database schema changes
  14. define ( 'WPOPENID_LOG_LEVEL', 'warning'); // valid values are debug, info, notice, warning, err, crit, alert, emerg
  15. set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); // Add plugin directory to include path temporarily
  16. require_once('logic.php');
  17. require_once('interface.php');
  18. @include_once('Log.php'); // Try loading PEAR_Log from normal include_path.
  19. if (!class_exists('Log')) { // If we can't find it, include the copy of
  20. require_once('OpenIDLog.php'); // PEAR_Log bundled with the plugin
  21. }
  22. restore_include_path();
  23. @session_start();
  24. if (!class_exists('WordPressOpenID')):
  25. class WordPressOpenID {
  26. var $store;
  27. var $consumer;
  28. var $log;
  29. var $status = array();
  30. var $message; // Message to be displayed to the user.
  31. var $action; // Internal action tag. 'success', 'warning', 'error', 'redirect'.
  32. var $response;
  33. var $enabled = true;
  34. var $bind_done = false;
  35. function WordPressOpenID() {
  36. $this->log = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'OpenID');
  37. //$this->log = &Log::singleton('file', ABSPATH . get_option('upload_path') . '/php.log', 'WPOpenID');
  38. // Set the log level
  39. $wpopenid_log_level = constant('PEAR_LOG_' . strtoupper(WPOPENID_LOG_LEVEL));
  40. $this->log->setMask(Log::UPTO($wpopenid_log_level));
  41. }
  42. /**
  43. * Set Status.
  44. **/
  45. function setStatus($slug, $state, $message) {
  46. $this->status[$slug] = array('state'=>$state,'message'=>$message);
  47. }
  48. function textdomain() {
  49. $lang_folder = PLUGINDIR . '/openid/lang';
  50. load_plugin_textdomain('openid', $lang_folder);
  51. }
  52. function table_prefix() {
  53. global $wpdb;
  54. return isset($wpdb->base_prefix) ? $wpdb->base_prefix : $wpdb->prefix;
  55. }
  56. function associations_table_name() { return WordPressOpenID::table_prefix() . 'openid_associations'; }
  57. function nonces_table_name() { return WordPressOpenID::table_prefix() . 'openid_nonces'; }
  58. function identity_table_name() { return WordPressOpenID::table_prefix() . 'openid_identities'; }
  59. function comments_table_name() { return WordPressOpenID::table_prefix() . 'comments'; }
  60. function usermeta_table_name() { return WordPressOpenID::table_prefix() . 'usermeta'; }
  61. }
  62. endif;
  63. if (!function_exists('openid_init')):
  64. function openid_init() {
  65. if ($GLOBALS['openid'] && is_a($GLOBALS['openid'], 'WordPressOpenID')) {
  66. return;
  67. }
  68. $GLOBALS['openid'] = new WordPressOpenID();
  69. }
  70. endif;
  71. // -- Register actions and filters -- //
  72. register_activation_hook('openid/core.php', array('WordPressOpenID_Logic', 'activate_plugin'));
  73. register_deactivation_hook('openid/core.php', array('WordPressOpenID_Logic', 'deactivate_plugin'));
  74. add_action( 'admin_menu', array( 'WordPressOpenID_Interface', 'add_admin_panels' ) );
  75. // Add hooks to handle actions in WordPress
  76. add_action( 'wp_authenticate', array( 'WordPressOpenID_Logic', 'wp_authenticate' ) ); // openid loop start
  77. add_action( 'init', array( 'WordPressOpenID_Logic', 'wp_login_openid' ) ); // openid loop done
  78. add_action( 'init', array( 'WordPressOpenID', 'textdomain' ) ); // load textdomain
  79. // Comment filtering
  80. add_action( 'preprocess_comment', array( 'WordPressOpenID_Logic', 'comment_tagging' ), -99 );
  81. add_action( 'comment_post', array( 'WordPressOpenID_Logic', 'check_author_openid' ), 5 );
  82. add_filter( 'option_require_name_email', array( 'WordPressOpenID_Logic', 'bypass_option_require_name_email') );
  83. add_filter( 'comments_array', array( 'WordPressOpenID_Logic', 'comments_awaiting_moderation'), 10, 2);
  84. add_action( 'sanitize_comment_cookies', array( 'WordPressOpenID_Logic', 'sanitize_comment_cookies'), 15);
  85. add_filter( 'comment_post_redirect', array( 'WordPressOpenID_Logic', 'comment_post_redirect'), 0, 2);
  86. if( get_option('oid_enable_approval') ) {
  87. add_filter( 'pre_comment_approved', array('WordPressOpenID_Logic', 'comment_approval'));
  88. }
  89. // include internal stylesheet
  90. add_action( 'wp_head', array( 'WordPressOpenID_Interface', 'style'));
  91. add_action( 'login_head', array( 'WordPressOpenID_Interface', 'style'));
  92. add_filter( 'get_comment_author_link', array( 'WordPressOpenID_Interface', 'comment_author_link'));
  93. if( get_option('oid_enable_commentform') ) {
  94. add_action( 'wp_head', array( 'WordPressOpenID_Interface', 'js_setup'), 9);
  95. add_action( 'wp_footer', array( 'WordPressOpenID_Interface', 'comment_profilelink'), 10);
  96. add_action( 'wp_footer', array( 'WordPressOpenID_Interface', 'comment_form'), 10);
  97. }
  98. // add OpenID input field to wp-login.php
  99. add_action( 'login_form', array( 'WordPressOpenID_Interface', 'login_form'));
  100. add_action( 'register_form', array( 'WordPressOpenID_Interface', 'register_form'));
  101. add_filter( 'login_errors', array( 'WordPressOpenID_Interface', 'login_form_hide_username_password_errors'));
  102. add_filter( 'init', array( 'WordPressOpenID_Interface', 'init_errors'));
  103. // parse request
  104. add_action('parse_request', array('WordPressOpenID_Logic', 'parse_request'));
  105. // Add custom OpenID options
  106. add_option( 'oid_enable_commentform', true );
  107. add_option( 'oid_plugin_enabled', true );
  108. add_option( 'oid_plugin_revision', 0 );
  109. add_option( 'oid_db_revision', 0 );
  110. add_option( 'oid_enable_approval', false );
  111. add_option( 'oid_enable_email_mapping', false );
  112. add_action( 'delete_user', array( 'WordPressOpenID_Logic', 'delete_user' ) );
  113. add_action( 'cleanup_openid', array( 'WordPressOpenID_Logic', 'cleanup_nonces' ) );
  114. add_action( 'personal_options_update', array( 'WordPressOpenID_Logic', 'personal_options_update' ) );
  115. // hooks for getting user data
  116. add_filter( 'openid_user_data', array('WordPressOpenID_Logic', 'get_user_data_form'), 10, 2);
  117. add_filter( 'openid_user_data', array('WordPressOpenID_Logic', 'get_user_data_sreg'), 10, 2);
  118. add_filter('xrds_simple', array('WordPressOpenID_Logic', 'xrds_simple'));
  119. // ---------------------------------------------------------------------
  120. // Exposed functions designed for use in templates, specifically inside
  121. // `foreach ($comments as $comment)` in comments.php
  122. // ---------------------------------------------------------------------
  123. /**
  124. * Get a simple OpenID input field, used for disabling unobtrusive mode.
  125. */
  126. if(!function_exists('openid_input')):
  127. function openid_input() {
  128. return '<input type="text" id="openid_url" name="openid_url" />';
  129. }
  130. endif;
  131. /**
  132. * If the current comment was submitted with OpenID, return true
  133. * useful for <?php echo ( is_comment_openid() ? 'Submitted with OpenID' : '' ); ?>
  134. */
  135. if(!function_exists('is_comment_openid')):
  136. function is_comment_openid() {
  137. global $comment;
  138. return ( $comment->openid == 1 );
  139. }
  140. endif;
  141. /**
  142. * If the current user registered with OpenID, return true
  143. */
  144. if(!function_exists('is_user_openid')):
  145. function is_user_openid($id = null) {
  146. global $current_user;
  147. if ($id === null && $current_user !== null) {
  148. $id = $current_user->ID;
  149. }
  150. return $id === null ? false : get_usermeta($id, 'has_openid');
  151. }
  152. endif;
  153. ?>