Ticket #732: wp-openid-wpmu.diff

File wp-openid-wpmu.diff, 12.3 kB (added by jdub, 6 months ago)

Updated to fix some mildly annoying bugs

  • openid/core.php

    old new  
    5353                        $this->interface = new WordpressOpenIDInterface($this); 
    5454                } 
    5555 
     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 
    5687                /** 
    5788                 * This is the main bootstrap method that gets things started. 
    5889                 */ 
     
    80111                        add_action( 'sanitize_comment_cookies', array( $this->logic, 'sanitize_comment_cookies'), 15); 
    81112                         
    82113                        // If user is dropped from database, remove their identities too. 
    83                         $this->logic->late_bind(); 
    84114                        add_action( 'delete_user', array( $this->logic->store, 'drop_all_identities_for_user' ) );       
    85115 
    86116                        // include internal stylesheet 
     
    92122                        add_filter( 'get_comment_author_link', array( $this->interface, 'comment_author_link')); 
    93123                        add_action( 'comment_form', array( $this->interface, 'comment_profilelink')); 
    94124 
    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')); 
    98126 
    99127                        // add OpenID input field to wp-login.php 
    100128                        add_action( 'login_form', array( $this->interface, 'login_form')); 
     
    102130                        add_filter( 'login_errors', array( $this->interface, 'login_form_hide_username_password_errors')); 
    103131 
    104132                        // 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 ); 
    110138                } 
    111139 
    112140                /**  
     
    122150                                $plugin = dirname($base); 
    123151                        } 
    124152 
    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                        } 
    126159                } 
    127160 
    128161 
     
    149182// 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 
    150183if (isset($wp_version)) { 
    151184        #$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'); 
    153187 
    154188        // Set the log level 
    155189        $wpopenid_log_level = constant('PEAR_LOG_' . strtoupper(WPOPENID_LOG_LEVEL)); 
  • openid/interface.php

    old new  
    125125         **/ 
    126126        function comment_form() { 
    127127                global $user_ID; 
    128                 if (!$user_ID) { 
     128                if (!$user_ID && $this->core->get_option('oid_enable_commentform') ) { 
    129129                        echo '<script type="text/javascript">add_openid_to_comment_form()</script>'; 
    130130                } 
    131131        } 
     
    147147         * @action: admin_menu 
    148148         **/ 
    149149        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                } 
    152157 
    153158                if( $this->logic->enabled ) { 
    154159                        $hookname =     add_submenu_page('profile.php', 'Your Identity URLs', 'Your Identity URLs',  
     
    187192 
    188193                                $error = ''; 
    189194                                 
    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 ); 
    192197 
    193198                                if ($error !== '') { 
    194199                                        echo '<div class="error"><p><strong>At least one of OpenID options was NOT updated</strong>'.$error.'</p></div>'; 
     
    217222                                                        <th style="width: 33%" scope="row">Automatic Approval:</th> 
    218223                                                        <td> 
    219224                                                                <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"' : ''; ?> /> 
    221226                                                                <label for="enable_approval">Enable OpenID comment auto-approval</label> 
    222227 
    223228                                                                <p>For now this option will cause comments made with OpenIDs to be automatically  
     
    238243                                                        <th style="width: 33%" scope="row">Comment Form:</th> 
    239244                                                        <td> 
    240245                                                                <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"' 
    242247                                                                ?> /> 
    243248                                                                <label for="enable_commentform">Add OpenID text to the WordPress post  
    244249                                                                comment form.</label></p> 
     
    398403                 
    399404                $this->core->setStatus( 'Plugin Revision', 'info', WPOPENID_PLUGIN_REVISION); 
    400405                $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') . '.' ); 
    402407                 
    403408                $this->core->setStatus( '<strong>Overall Plugin Status</strong>', ($this->logic->enabled),  
    404409                        'There are problems above that must be dealt with before the plugin can be used.' ); 
  • openid/logic.php

    old new  
    3333                /* Soft verification of plugin activation OK */ 
    3434                function uptodate() { 
    3535                        $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 ) {   
    3737                                // Database version mismatch, force dbDelta() in admin interface. 
    3838                                $this->enabled = false; 
    3939                                $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); 
    4242                                return false; 
    4343                        } 
    44                         $this->enabled = (get_option('oid_plugin_enabled') == true ); 
     44                        $this->enabled = ($this->core->get_option('oid_plugin_enabled') == true ); 
    4545                        return $this->enabled; 
    4646                } 
    4747                 
     
    132132                                $this->enabled = $store->check_tables(); 
    133133 
    134134                                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 ); 
    138138                                        $this->uptodate(); 
    139139                                } 
    140140                        } else { 
    141141                                $this->error = 'WPOpenID Core is Disabled!'; 
    142                                 update_option('oid_plugin_enabled', false); 
     142                                $this->core->update_option('oid_plugin_enabled', false); 
    143143                        } 
    144144 
    145145                        return $this->enabled; 
     
    834834                        }        
    835835 
    836836                        // comment approval 
    837                         if ( get_option('oid_enable_approval') ) { 
     837                        if ( $this->core->get_option('oid_enable_approval') ) { 
    838838                                add_filter('pre_comment_approved', array($this, 'comment_approval')); 
    839839                        } 
    840840 
     
    865865                 */ 
    866866                function set_comment_openid($comment_ID) { 
    867867                        global $wpdb; 
     868                        $this->late_bind(); 
    868869 
    869870                        $comments_table = $this->store->comments_table_name; 
     871                        $this->store->create_comment_field(); 
    870872                        $wpdb->query("UPDATE $comments_table SET openid='1' WHERE comment_ID='$comment_ID' LIMIT 1"); 
    871873                } 
    872874 
     
    970972                 */ 
    971973                function comments_awaiting_moderation(&$comments, $post_id) { 
    972974                        global $wpdb, $user_ID; 
     975                        $this->late_bind(); 
    973976 
    974977                        $commenter = wp_get_current_commenter(); 
    975978                        extract($commenter); 
     
    981984                        if ($url_db) { 
    982985                                $store =& $this->getStore(); 
    983986                                $comments_table = $store->comments_table_name; 
     987                                $this->store->create_comment_field(); 
    984988                                $additional = $wpdb->get_results( 
    985989                                        "SELECT * FROM $comments_table" 
    986990                                        . " WHERE comment_post_ID = '$post_id'" 
  • openid/store.php

    old new  
    3131                        $this->associations_table_name = $this->table_prefix . 'openid_associations'; 
    3232                        $this->nonces_table_name = $this->table_prefix . 'openid_nonces'; 
    3333                        $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'; 
    3636 
    3737                        $conn = new WordpressOpenIDConnection( $wpdb ); 
    3838                        parent::Auth_OpenID_MySQLStore( 
     
    126126                        $sql = implode(';', $statements); 
    127127                        dbDelta($sql); 
    128128 
     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 
    129142                        // add column to comments table 
    130143                        $result = maybe_add_column($this->comments_table_name, 'openid',  
    131144                                "ALTER TABLE $this->comments_table_name ADD `openid` TINYINT(1) NOT NULL DEFAULT '0'"); 
     
    133146                        if (!$result) { 
    134147                                $this->core->log->error('unable to add column `openid` to comments table.'); 
    135148                        } 
    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                        } 
    139152                } 
    140153 
    141154                function destroy_tables() {