PageRenderTime 51ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/ianloic/wordpress-ianloic
PHP | 204 lines | 112 code | 47 blank | 45 comment | 14 complexity | 77fd463702af541d939f284ae9cba20c MD5 | raw file
  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.1.7
  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: 35773 $') ); // 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 $path;
  27. var $fullpath;
  28. var $logic;
  29. var $interface;
  30. var $log;
  31. var $status = array();
  32. function WordpressOpenID($log) {
  33. $this->set_path();
  34. $this->fullpath = get_option('siteurl').$this->path;
  35. $this->log =& $log;
  36. $this->logic = new WordpressOpenIDLogic($this);
  37. $this->interface = new WordpressOpenIDInterface($this);
  38. }
  39. /**
  40. * This is the main bootstrap method that gets things started.
  41. */
  42. function startup() {
  43. $this->log->debug("Status: userinterface hooks: " . ($this->logic->enabled? 'Enabled':'Disabled' )
  44. . ' (finished including and instantiating, passing control back to WordPress)' );
  45. // -- register actions and filters -- //
  46. add_action( 'admin_menu', array( $this->interface, 'add_admin_panels' ) );
  47. // Kickstart
  48. register_activation_hook( $this->path.'/core.php', array( $this->logic, 'activate_plugin' ) );
  49. register_deactivation_hook( $this->path.'/core.php', array( $this->logic, 'deactivate_plugin' ) );
  50. // Add hooks to handle actions in WordPress
  51. add_action( 'wp_authenticate', array( $this->logic, 'wp_authenticate' ) ); // openid loop start
  52. add_action( 'init', array( $this->logic, 'finish_login' ) ); // openid loop done
  53. // Comment filtering
  54. add_action( 'preprocess_comment', array( $this->logic, 'comment_tagging' ), -99999 );
  55. add_action( 'comment_post', array( $this->logic, 'check_author_openid' ), 5 );
  56. add_filter( 'option_require_name_email', array( $this->logic, 'bypass_option_require_name_email') );
  57. add_filter( 'comments_array', array( $this->logic, 'comments_awaiting_moderation'), 10, 2);
  58. add_action( 'sanitize_comment_cookies', array( $this->logic, 'sanitize_comment_cookies'), 15);
  59. // If user is dropped from database, remove their identities too.
  60. $this->logic->late_bind();
  61. add_action( 'delete_user', array( $this->logic->store, 'drop_all_identities_for_user' ) );
  62. // include internal stylesheet
  63. add_action( 'wp_head', array( $this->interface, 'style'));
  64. add_action( 'login_head', array( $this->interface, 'style'));
  65. add_action( 'init', array( $this->interface, 'js_setup'));
  66. add_filter( 'get_comment_author_link', array( $this->interface, 'comment_author_link'));
  67. add_action( 'comment_form', array( $this->interface, 'comment_profilelink'));
  68. if( get_option('oid_enable_commentform') ) {
  69. add_action( 'comment_form', array( $this->interface, 'comment_form'));
  70. }
  71. // add OpenID input field to wp-login.php
  72. add_action( 'login_form', array( $this->interface, 'login_form'));
  73. add_action( 'register_form', array( $this->interface, 'register_form'));
  74. add_filter( 'login_errors', array( $this->interface, 'login_form_hide_username_password_errors'));
  75. // Add custom OpenID options
  76. add_option( 'oid_enable_commentform', true );
  77. add_option( 'oid_plugin_enabled', true );
  78. add_option( 'oid_plugin_revision', 0 );
  79. add_option( 'oid_db_revision', 0 );
  80. add_option( 'oid_enable_approval', false );
  81. }
  82. /**
  83. * Set the path for the plugin. This should allow users to rename the plugin directory
  84. * if they choose to. If unable to determine the directory (often due to symlinks),
  85. * default to 'openid'
  86. **/
  87. function set_path() {
  88. $plugin = 'openid';
  89. $base = plugin_basename(__FILE__);
  90. if ($base != __FILE__) {
  91. $plugin = dirname($base);
  92. }
  93. $this->path = '/wp-content/plugins/'.$plugin;
  94. }
  95. /**
  96. * Set Status.
  97. **/
  98. function setStatus($slug, $state, $message) {
  99. $this->status[$slug] = array('state'=>$state,'message'=>$message);
  100. if( $state === true ) {
  101. $_state = 'ok';
  102. }
  103. elseif( $state === false ) {
  104. $_state = 'fail';
  105. }
  106. else {
  107. $_state = ''.($state);
  108. }
  109. $this->log->debug('Status: ' . strip_tags($slug) . " [$_state]" . ( ($_state==='ok') ? '': strip_tags(str_replace('<br/>'," ", ': ' . $message)) ) );
  110. }
  111. }
  112. }
  113. // The variable in use here should probably be something other than $log. Too great a chance of collision. Probably causing http://willnorris.com/2007/10/plugin-updates#comment-13625
  114. if (isset($wp_version)) {
  115. #$wpopenid_log = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'WPOpenID');
  116. $wpopenid_log = &Log::singleton('file', ABSPATH . get_option('upload_path') . '/php.log', 'WPOpenID');
  117. // Set the log level
  118. $wpopenid_log_level = constant('PEAR_LOG_' . strtoupper(WPOPENID_LOG_LEVEL));
  119. $wpopenid_log->setMask(Log::UPTO($wpopenid_log_level));
  120. $openid = new WordpressOpenID($wpopenid_log);
  121. $openid->startup();
  122. }
  123. // ---------------------------------------------------------------------
  124. // Exposed functions designed for use in templates, specifically inside
  125. // `foreach ($comments as $comment)` in comments.php
  126. // ---------------------------------------------------------------------
  127. /**
  128. * Get a simple OpenID input field, used for disabling unobtrusive mode.
  129. */
  130. if( !function_exists( 'openid_input' ) ) {
  131. function openid_input() {
  132. return '<input type="text" id="openid_url" name="openid_url" />';
  133. }
  134. }
  135. /**
  136. * If the current comment was submitted with OpenID, return true
  137. * useful for <?php echo ( is_comment_openid() ? 'Submitted with OpenID' : '' ); ?>
  138. */
  139. if( !function_exists( 'is_comment_openid' ) ) {
  140. function is_comment_openid() {
  141. global $comment;
  142. return ( $comment->openid == 1 );
  143. }
  144. }
  145. /**
  146. * If the current user registered with OpenID, return true
  147. */
  148. if( !function_exists('is_user_openid') ) {
  149. function is_user_openid($id = null) {
  150. global $current_user;
  151. if ($id === null && $current_user !== null) {
  152. $id = $current_user->ID;
  153. }
  154. return $id === null ? false : get_usermeta($id, 'has_openid');
  155. }
  156. }
  157. ?>