Ticket #732: wp-openid-wpmu.diff
| File wp-openid-wpmu.diff, 12.3 kB (added by jdub, 6 months ago) |
|---|
-
openid/core.php
old new 53 53 $this->interface = new WordpressOpenIDInterface($this); 54 54 } 55 55 56 function add_option($key, $value) { 57 if( defined('MUPLUGINDIR') ) { 58 return add_site_option($key, $value); 59 } 60 else { 61 return add_option($key, $value); 62 } 63 } 64 65 function update_option($key, $value) { 66 if( defined('MUPLUGINDIR') ) { 67 return update_site_option($key, $value); 68 } 69 else { 70 return update_option($key, $value); 71 } 72 } 73 74 function get_option($key, $default = false) { 75 if( defined('MUPLUGINDIR') ) { 76 return get_site_option($key, $default); 77 } 78 else { 79 $value = get_option($key); 80 if( false === $value ) { 81 $value = $default; 82 } 83 return $value; 84 } 85 } 86 56 87 /** 57 88 * This is the main bootstrap method that gets things started. 58 89 */ … … 80 111 add_action( 'sanitize_comment_cookies', array( $this->logic, 'sanitize_comment_cookies'), 15); 81 112 82 113 // If user is dropped from database, remove their identities too. 83 $this->logic->late_bind();84 114 add_action( 'delete_user', array( $this->logic->store, 'drop_all_identities_for_user' ) ); 85 115 86 116 // include internal stylesheet … … 92 122 add_filter( 'get_comment_author_link', array( $this->interface, 'comment_author_link')); 93 123 add_action( 'comment_form', array( $this->interface, 'comment_profilelink')); 94 124 95 if( get_option('oid_enable_commentform') ) { 96 add_action( 'comment_form', array( $this->interface, 'comment_form')); 97 } 125 add_action( 'comment_form', array( $this->interface, 'comment_form')); 98 126 99 127 // add OpenID input field to wp-login.php 100 128 add_action( 'login_form', array( $this->interface, 'login_form')); … … 102 130 add_filter( 'login_errors', array( $this->interface, 'login_form_hide_username_password_errors')); 103 131 104 132 // Add custom OpenID options 105 add_option( 'oid_enable_commentform', true );106 add_option( 'oid_plugin_enabled', true );107 add_option( 'oid_plugin_revision', 0 );108 add_option( 'oid_db_revision', 0 );109 add_option( 'oid_enable_approval', false );133 $this->get_option( 'oid_enable_commentform', true ); 134 $this->get_option( 'oid_plugin_enabled', true ); 135 $this->get_option( 'oid_plugin_revision', 0 ); 136 $this->get_option( 'oid_db_revision', 0 ); 137 $this->get_option( 'oid_enable_approval', false ); 110 138 } 111 139 112 140 /** … … 122 150 $plugin = dirname($base); 123 151 } 124 152 125 $this->path = '/wp-content/plugins/'.$plugin; 153 if( defined('MUPLUGINDIR') ) { 154 $this->path = '/'.MUPLUGINDIR.'/'.$plugin; 155 } 156 else { 157 $this->path = '/wp-content/plugins/'.$plugin; 158 } 126 159 } 127 160 128 161 … … 149 182 // 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 150 183 if (isset($wp_version)) { 151 184 #$wpopenid_log = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'WPOpenID'); 152 $wpopenid_log = &Log::singleton('file', ABSPATH . get_option('upload_path') . '/php.log', 'WPOpenID'); 185 $wpopenid_log = defined('MUPLUGINDIR') ? 'wp-content/blogs.dir' : get_option('upload_path'); 186 $wpopenid_log = &Log::singleton('file', ABSPATH . $wpopenid_log . '/php.log', 'WPOpenID'); 153 187 154 188 // Set the log level 155 189 $wpopenid_log_level = constant('PEAR_LOG_' . strtoupper(WPOPENID_LOG_LEVEL)); -
openid/interface.php
old new 125 125 **/ 126 126 function comment_form() { 127 127 global $user_ID; 128 if (!$user_ID ) {128 if (!$user_ID && $this->core->get_option('oid_enable_commentform') ) { 129 129 echo '<script type="text/javascript">add_openid_to_comment_form()</script>'; 130 130 } 131 131 } … … 147 147 * @action: admin_menu 148 148 **/ 149 149 function add_admin_panels() { 150 add_options_page('OpenID options', 'WP-OpenID', 8, 'global-openid-options', 151 array( $this, 'options_page') ); 150 if( defined('MUPLUGINDIR') ) { 151 add_submenu_page('wpmu-admin.php', 'OpenID options', 'WP-OpenID', 'manage_options', 'global-openid-options', array($this, 'options_page')); 152 } 153 else { 154 add_options_page('OpenID options', 'WP-OpenID', 8, 'global-openid-options', 155 array( $this, 'options_page') ); 156 } 152 157 153 158 if( $this->logic->enabled ) { 154 159 $hookname = add_submenu_page('profile.php', 'Your Identity URLs', 'Your Identity URLs', … … 187 192 188 193 $error = ''; 189 194 190 update_option( 'oid_enable_commentform', isset($_POST['enable_commentform']) ? true : false );191 update_option( 'oid_enable_approval', isset($_POST['enable_approval']) ? true : false );195 $this->core->update_option( 'oid_enable_commentform', isset($_POST['enable_commentform']) ? true : false ); 196 $this->core->update_option( 'oid_enable_approval', isset($_POST['enable_approval']) ? true : false ); 192 197 193 198 if ($error !== '') { 194 199 echo '<div class="error"><p><strong>At least one of OpenID options was NOT updated</strong>'.$error.'</p></div>'; … … 217 222 <th style="width: 33%" scope="row">Automatic Approval:</th> 218 223 <td> 219 224 <p><input type="checkbox" name="enable_approval" id="enable_approval" <?php 220 echo get_option('oid_enable_approval') ? 'checked="checked"' : ''; ?> />225 echo $this->core->get_option('oid_enable_approval') ? 'checked="checked"' : ''; ?> /> 221 226 <label for="enable_approval">Enable OpenID comment auto-approval</label> 222 227 223 228 <p>For now this option will cause comments made with OpenIDs to be automatically … … 238 243 <th style="width: 33%" scope="row">Comment Form:</th> 239 244 <td> 240 245 <p><input type="checkbox" name="enable_commentform" id="enable_commentform" <?php 241 if( get_option('oid_enable_commentform') ) echo 'checked="checked"'246 if( $this->core->get_option('oid_enable_commentform') ) echo 'checked="checked"' 242 247 ?> /> 243 248 <label for="enable_commentform">Add OpenID text to the WordPress post 244 249 comment form.</label></p> … … 398 403 399 404 $this->core->setStatus( 'Plugin Revision', 'info', WPOPENID_PLUGIN_REVISION); 400 405 $this->core->setStatus( 'Plugin Database Revision', 'info', 'Plugin database is currently at revision ' 401 . get_option('oid_db_revision') . '.' );406 . $this->core->get_option('oid_db_revision') . '.' ); 402 407 403 408 $this->core->setStatus( '<strong>Overall Plugin Status</strong>', ($this->logic->enabled), 404 409 'There are problems above that must be dealt with before the plugin can be used.' ); -
openid/logic.php
old new 33 33 /* Soft verification of plugin activation OK */ 34 34 function uptodate() { 35 35 $this->core->log->debug('checking if database is up to date'); 36 if( get_option('oid_db_revision') != WPOPENID_DB_REVISION ) {36 if( $this->core->get_option('oid_db_revision') != WPOPENID_DB_REVISION ) { 37 37 // Database version mismatch, force dbDelta() in admin interface. 38 38 $this->enabled = false; 39 39 $this->core->setStatus('Plugin Database Version', false, 'Plugin database is out of date. ' 40 . get_option('oid_db_revision') . ' != ' . WPOPENID_DB_REVISION );41 update_option('oid_plugin_enabled', false);40 . $this->core->get_option('oid_db_revision') . ' != ' . WPOPENID_DB_REVISION ); 41 $this->core->update_option('oid_plugin_enabled', false); 42 42 return false; 43 43 } 44 $this->enabled = ( get_option('oid_plugin_enabled') == true );44 $this->enabled = ($this->core->get_option('oid_plugin_enabled') == true ); 45 45 return $this->enabled; 46 46 } 47 47 … … 132 132 $this->enabled = $store->check_tables(); 133 133 134 134 if( !$this->uptodate() ) { 135 update_option('oid_plugin_enabled', true);136 update_option('oid_plugin_revision', WPOPENID_PLUGIN_REVISION );137 update_option('oid_db_revision', WPOPENID_DB_REVISION );135 $this->core->update_option('oid_plugin_enabled', true); 136 $this->core->update_option('oid_plugin_revision', WPOPENID_PLUGIN_REVISION ); 137 $this->core->update_option('oid_db_revision', WPOPENID_DB_REVISION ); 138 138 $this->uptodate(); 139 139 } 140 140 } else { 141 141 $this->error = 'WPOpenID Core is Disabled!'; 142 update_option('oid_plugin_enabled', false);142 $this->core->update_option('oid_plugin_enabled', false); 143 143 } 144 144 145 145 return $this->enabled; … … 834 834 } 835 835 836 836 // comment approval 837 if ( get_option('oid_enable_approval') ) {837 if ( $this->core->get_option('oid_enable_approval') ) { 838 838 add_filter('pre_comment_approved', array($this, 'comment_approval')); 839 839 } 840 840 … … 865 865 */ 866 866 function set_comment_openid($comment_ID) { 867 867 global $wpdb; 868 $this->late_bind(); 868 869 869 870 $comments_table = $this->store->comments_table_name; 871 $this->store->create_comment_field(); 870 872 $wpdb->query("UPDATE $comments_table SET openid='1' WHERE comment_ID='$comment_ID' LIMIT 1"); 871 873 } 872 874 … … 970 972 */ 971 973 function comments_awaiting_moderation(&$comments, $post_id) { 972 974 global $wpdb, $user_ID; 975 $this->late_bind(); 973 976 974 977 $commenter = wp_get_current_commenter(); 975 978 extract($commenter); … … 981 984 if ($url_db) { 982 985 $store =& $this->getStore(); 983 986 $comments_table = $store->comments_table_name; 987 $this->store->create_comment_field(); 984 988 $additional = $wpdb->get_results( 985 989 "SELECT * FROM $comments_table" 986 990 . " WHERE comment_post_ID = '$post_id'" -
openid/store.php
old new 31 31 $this->associations_table_name = $this->table_prefix . 'openid_associations'; 32 32 $this->nonces_table_name = $this->table_prefix . 'openid_nonces'; 33 33 $this->identity_table_name = $this->table_prefix . 'openid_identities'; 34 $this->comments_table_name = $ this->table_prefix . 'comments';35 $this->usermeta_table_name = $ wpdb->prefix . 'usermeta';34 $this->comments_table_name = $wpdb->prefix . 'comments'; 35 $this->usermeta_table_name = $this->table_prefix . 'usermeta'; 36 36 37 37 $conn = new WordpressOpenIDConnection( $wpdb ); 38 38 parent::Auth_OpenID_MySQLStore( … … 126 126 $sql = implode(';', $statements); 127 127 dbDelta($sql); 128 128 129 $wpdb->query("update $this->usermeta_table_name set `meta_key`='has_openid' where `meta_key`='registered_with_openid'"); 130 } 131 132 function create_comment_field() { 133 global $wp_version, $wpdb; 134 135 if ($wp_version >= '2.3') { 136 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 137 } else { 138 require_once(ABSPATH . 'wp-admin/admin-db.php'); 139 require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); 140 } 141 129 142 // add column to comments table 130 143 $result = maybe_add_column($this->comments_table_name, 'openid', 131 144 "ALTER TABLE $this->comments_table_name ADD `openid` TINYINT(1) NOT NULL DEFAULT '0'"); … … 133 146 if (!$result) { 134 147 $this->core->log->error('unable to add column `openid` to comments table.'); 135 148 } 136 137 $wpdb->query("update $this->comments_table_name set `comment_type`='', `openid`=1 where `comment_type`='openid'");138 $wpdb->query("update $this->usermeta_table_name set `meta_key`='has_openid' where `meta_key`='registered_with_openid'");149 else { 150 $wpdb->query("update $this->comments_table_name set `comment_type`='', `openid`=1 where `comment_type`='openid'"); 151 } 139 152 } 140 153 141 154 function destroy_tables() {
