PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/app/omb/plugins/wp-plugins/plugins/enabled/wp-openid/core.php

https://github.com/tjgillies/openmicroblogger
PHP | 203 lines | 115 code | 48 blank | 40 comment | 13 complexity | e641e20e87834b3e70d8686c4d8863f8 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. Plugin Name: 0_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: trunk
  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: 291 $') ); // 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', 'debug'); // 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 $error; // User friendly error message, defaults to ''.
  31. var $action; // Internal action tag. '', 'error', 'redirect'.
  32. var $response;
  33. var $enabled = true;
  34. var $bind_done = false;
  35. function WordPressOpenID() {
  36. #$wpopenid_log = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'WPOpenID');
  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. $start_mem = memory_get_usage();
  69. $GLOBALS['openid'] = new WordPressOpenID();
  70. //WordPressOpenID_Logic::late_bind();
  71. //WordPressOpenID_Logic::getStore();
  72. //WordPressOpenID_Logic::getConsumer();
  73. //set_include_path( dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
  74. //require_once 'store.php';
  75. $GLOBALS['openid']->log->warning("memory usage: " . (int)((memory_get_usage() - $start_mem) / 1000));
  76. }
  77. endif;
  78. // -- Register actions and filters -- //
  79. register_activation_hook('openid/core.php', array('WordPressOpenID_Logic', 'activate_plugin'));
  80. register_deactivation_hook('openid/core.php', array('WordPressOpenID_Logic', 'deactivate_plugin'));
  81. add_action( 'admin_menu', array( 'WordPressOpenID_Interface', 'add_admin_panels' ) );
  82. // Add hooks to handle actions in WordPress
  83. add_action( 'wp_authenticate', array( 'WordPressOpenID_Logic', 'wp_authenticate' ) ); // openid loop start
  84. add_action( 'init', array( 'WordPressOpenID_Logic', 'wp_login_openid' ) ); // openid loop done
  85. add_action( 'init', array( 'WordPressOpenID', 'textdomain' ) ); // load textdomain
  86. // Comment filtering
  87. add_action( 'preprocess_comment', array( 'WordPressOpenID_Logic', 'comment_tagging' ), -99 );
  88. add_action( 'comment_post', array( 'WordPressOpenID_Logic', 'check_author_openid' ), 5 );
  89. add_filter( 'option_require_name_email', array( 'WordPressOpenID_Logic', 'bypass_option_require_name_email') );
  90. add_filter( 'comments_array', array( 'WordPressOpenID_Logic', 'comments_awaiting_moderation'), 10, 2);
  91. add_action( 'sanitize_comment_cookies', array( 'WordPressOpenID_Logic', 'sanitize_comment_cookies'), 15);
  92. add_filter( 'comment_post_redirect', array( 'WordPressOpenID_Logic', 'comment_post_redirect'), 0, 2);
  93. if( get_option('oid_enable_approval') ) {
  94. add_filter( 'pre_comment_approved', array('WordPressOpenID_Logic', 'comment_approval'));
  95. }
  96. // include internal stylesheet
  97. add_action( 'wp_head', array( 'WordPressOpenID_Interface', 'style'));
  98. add_action( 'login_head', array( 'WordPressOpenID_Interface', 'style'));
  99. add_filter( 'get_comment_author_link', array( 'WordPressOpenID_Interface', 'comment_author_link'));
  100. if( get_option('oid_enable_commentform') ) {
  101. add_action( 'wp_head', array( 'WordPressOpenID_Interface', 'js_setup'), 9);
  102. add_action( 'wp_footer', array( 'WordPressOpenID_Interface', 'js_setup_foot'));
  103. add_action( 'wp_footer', array( 'WordPressOpenID_Interface', 'comment_profilelink'), 10);
  104. add_action( 'wp_footer', array( 'WordPressOpenID_Interface', 'comment_form'), 10);
  105. }
  106. // add OpenID input field to wp-login.php
  107. add_action( 'login_form', array( 'WordPressOpenID_Interface', 'login_form'));
  108. add_action( 'register_form', array( 'WordPressOpenID_Interface', 'register_form'));
  109. add_filter( 'login_errors', array( 'WordPressOpenID_Interface', 'login_form_hide_username_password_errors'));
  110. add_filter( 'init', array( 'WordPressOpenID_Interface', 'init_errors'));
  111. // parse request
  112. add_action('parse_request', array('WordPressOpenID_Logic', 'parse_request'));
  113. // Add custom OpenID options
  114. add_option( 'oid_enable_commentform', true );
  115. add_option( 'oid_plugin_enabled', true );
  116. add_option( 'oid_plugin_revision', 0 );
  117. add_option( 'oid_db_revision', 0 );
  118. add_option( 'oid_enable_approval', false );
  119. add_action( 'delete_user', array( 'WordPressOpenID_Store', 'drop_all_identities_for_user' ) );
  120. add_action( 'cleanup_openid', array( 'WordPressOpenID_Logic', 'cleanup_nonces' ) );
  121. // ---------------------------------------------------------------------
  122. // Exposed functions designed for use in templates, specifically inside
  123. // `foreach ($comments as $comment)` in comments.php
  124. // ---------------------------------------------------------------------
  125. /**
  126. * Get a simple OpenID input field, used for disabling unobtrusive mode.
  127. */
  128. if(!function_exists('openid_input')):
  129. function openid_input() {
  130. return '<input type="text" id="openid_url" name="openid_url" />';
  131. }
  132. endif;
  133. /**
  134. * If the current comment was submitted with OpenID, return true
  135. * useful for <?php echo ( is_comment_openid() ? 'Submitted with OpenID' : '' ); ?>
  136. */
  137. if(!function_exists('is_comment_openid')):
  138. function is_comment_openid() {
  139. global $comment;
  140. return ( $comment->openid == 1 );
  141. }
  142. endif;
  143. /**
  144. * If the current user registered with OpenID, return true
  145. */
  146. if(!function_exists('is_user_openid')):
  147. function is_user_openid($id = null) {
  148. global $current_user;
  149. if ($id === null && $current_user !== null) {
  150. $id = $current_user->ID;
  151. }
  152. return $id === null ? false : get_usermeta($id, 'has_openid');
  153. }
  154. endif;
  155. ?>