Plugin Directory

Changeset 494420


Ignore:
Timestamp:
01/24/2012 04:04:16 AM (14 years ago)
Author:
forgueam
Message:

Update to 0.2

Location:
vbpress/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • vbpress/trunk/core/views/settings.php

    r403077 r494420  
    77    </form>
    88   
    9     <?php if ( !empty( $options['vbpress_enabled'] ) ) { ?>
     9    <?php if ( false && !empty( $options['vbpress_enabled'] ) ) { ?>
    1010        <h2><?php _e( 'vBulletin Status', 'vbpress' ); ?></h2>
    1111        <?php if ( !empty( $current_user_info ) ) { ?>
  • vbpress/trunk/readme.txt

    r403077 r494420  
    33Tags: vbulletin, integrate, forum, bridge, vb, login, merge, member, user, thread, post, comment
    44Requires at least: 3.0.5
    5 Tested up to: 3.1.4
    6 Stable tag: 0.1.0-2
     5Tested up to: 3.3.1
     6Stable tag: 0.2
    77
    88vBPress seamlessly integrates WordPress with vBulletin
     
    1111
    1212[vBPress](http://www.vbpress.com/) is a WordPress plugin that seamlessly integrates WordPress with vBulletin.
    13 
    14 PLEASE NOTE: This plugin is still under active development and is not yet fully functional. Set your expectations accordingly.
    1513
    1614== Installation ==
     
    2321= There's not much, what's going on? =
    2422
    25 It's version 0.1.0. Patience.
     23It's version 0.3. Patience.
    2624
    2725== Changelog ==
     26
     27= 0.2 =
     28* Added setting to create vBulletin user account when a WordPress user account is created
     29* Added setting to enable auto-login
    2830
    2931= 0.1.0-2 =
  • vbpress/trunk/vbpress.php

    r403077 r494420  
    3535    function Vbpress() {
    3636   
     37        // Create settings menu in admin control panel
    3738        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
     39   
     40        $options = get_option( 'vbpress_options' );
     41       
     42        // Create user hook
     43        if ( !empty( $options['sync_wp_users_into_vb'] ) ) {
     44            add_action( 'user_register', array( $this, 'create_vb_user' ) );
     45            add_action( 'wp_authenticate', array( $this, 'update_vb_password_on_authenticate' ) );
     46        }
     47
     48        // Auto-login hook
     49        if ( !empty( $options['auto_login_vb_user'] ) ) {
     50            add_action( 'wp_login', array( $this, 'login_vb_user' ) );
     51        }
    3852       
    3953    }
     
    5973        $vbpress_settings = Vbpress_Settings::init();
    6074        $hook = add_menu_page( 'vBPress', 'vBPress', 'manage_options', 'vbpress_settings', array( &$vbpress_settings, 'settings' ), '' );
     75    }
     76   
     77    /**
     78     * Create a vBulletin user and associate it to the WP account
     79     */
     80    function create_vb_user( $wp_user_id ) {
     81   
     82        $wp_user_data = get_userdata( $wp_user_id );
     83       
     84        $vb_user_id = Vbpress_Vb::create_user( $wp_user_id, $wp_user_data->user_email, $wp_user_data->user_login, wp_generate_password( 12, false ) );
     85       
     86        if ( !empty( $vb_user_id ) ) {
     87            update_user_meta( $wp_user_id, 'vbulletin_user_id', $vb_user_id );
     88        }
     89    }
     90   
     91    /**
     92     * There's no way to get the user's raw password when registering. This
     93     * function attempts to snag it upon login so that vB can be updated.
     94     */
     95    function update_vb_password_on_authenticate( $user_login ) {
     96   
     97        if ( empty( $user_login ) ) { return; }
     98       
     99        $wp_user_data = get_userdatabylogin( $user_login );
     100        $vb_user_id = get_user_meta( $wp_user_data->ID, 'vbulletin_user_id', true );
     101       
     102        Vbpress_Vb::set_user_password( $vb_user_id, $_POST['pwd'] );
     103       
     104    }
     105   
     106    /**
     107     * Logs in the vBulletin user associated with the WordPress user
     108     */
     109    function login_vb_user( $user_login ) {
     110       
     111        $wp_user_data = get_userdatabylogin( $user_login );
     112        $vb_user_id = get_user_meta( $wp_user_data->ID, 'vbulletin_user_id', true );
     113       
     114        if ( empty( $vb_user_id ) ) {
     115            return;
     116        }
     117       
     118        Vbpress_Vb::login_user_by_id( $vb_user_id );
    61119    }
    62120}
     
    98156     * logged-in user
    99157     */
     158    function create_user( $wp_user_id, $email, $username, $password ) {
     159
     160        $vb_user_data =& datamanager_init( 'User', $GLOBALS['vbulletin'], ERRTYPE_ARRAY );
     161        $vb_user_data->set( 'email', $email );
     162        $vb_user_data->set( 'username', $username );
     163        $vb_user_data->set( 'password', $password );
     164
     165        $vb_user_data->pre_save();
     166
     167        if ( empty( $vb_user_data->errors ) ) {
     168            return $vb_user_data->save();
     169        } else {
     170            // TODO: Error, vBulletin threw errors when attempting to create user
     171        }
     172       
     173    }
     174   
     175    /**
     176     * If available, returns an array of user info for the currently
     177     * logged-in user
     178     */
    100179    function get_current_user_info() {
    101180        if ( !empty($this->vbulletin->userinfo['userid']) ) {
     
    113192        return fetch_userinfo($user_id);
    114193    }
     194
     195    /**
     196     * Logs in the vBulletin user associated with the WordPress user
     197     */
     198    function login_user_by_id( $vb_user_id ) {
     199       
     200        $options = get_option( 'vbpress_options' );
     201   
     202        if ( empty( $options['vbulletin_path'] ) || !file_exists( $options['vbulletin_path'] . '/includes/functions_login.php' ) ) {
     203            return;
     204        }
     205
     206        include_once( $options['vbulletin_path'] . '/includes/functions_login.php' );
     207        $GLOBALS['vbulletin']->userinfo = verify_id( 'user', $vb_user_id, true, true, 0 );
     208        process_new_login( null, 0, null );
     209        $GLOBALS['vbulletin']->session->save();
     210       
     211    }
     212
     213    /**
     214     * Logs in the vBulletin user associated with the WordPress user
     215     */
     216    function set_user_password( $vb_user_id, $user_pass ) {
     217
     218        $vb_user_data =& datamanager_init( 'User', $GLOBALS['vbulletin'], ERRTYPE_ARRAY );
     219        $vb_user_data->set_existing( Vbpress_Vb::get_user_info( $vb_user_id ) ); 
     220        $vb_user_data->set( 'password', $_POST['pwd'] );
     221        $vb_user_data->pre_save();
     222
     223        if ( empty( $vb_user_data->errors ) ) {
     224            $vb_user_data->save();
     225        } else {
     226            // TODO: Error, vBulletin threw errors when attempting to create user
     227        }
     228       
     229    }
    115230   
    116231}
     
    145260        add_settings_field( 'vbpress_enabled', __( 'Enable vBPress', 'vbpress' ), array( $this, 'output_option_vbpress_enabled' ), 'vbpress', 'vbpress_options_general' );
    146261        add_settings_field( 'vbulletin_path', __( 'vBulletin Path', 'vbpress' ), array( $this, 'output_option_vbulletin_path' ), 'vbpress', 'vbpress_options_general' );
     262        add_settings_field( 'sync_wp_users_into_vb', __( 'Sync WordPress Users Into vBulletin', 'vbpress' ), array( $this, 'output_option_sync_wp_users_into_vb' ), 'vbpress', 'vbpress_options_general' );
     263        add_settings_field( 'auto_login_vb_user', __( 'Automatically log in to vBulletin', 'vbpress' ), array( $this, 'output_option_auto_login_vb_user' ), 'vbpress', 'vbpress_options_general' );
    147264    }
    148265
     
    186303        $options = get_option( 'vbpress_options' );
    187304        require( dirname( __FILE__ ) . '/core/views/option_field_vbulletin_path.php' );
     305    }
     306
     307    /**
     308     * Output option field HTML
     309     */
     310    function output_option_sync_wp_users_into_vb() {
     311        $options = get_option( 'vbpress_options' );
     312        require( dirname( __FILE__ ) . '/core/views/option_field_sync_wp_users_into_vb.php' );
     313    }
     314
     315    /**
     316     * Output option field HTML
     317     */
     318    function output_option_auto_login_vb_user() {
     319        $options = get_option( 'vbpress_options' );
     320        require( dirname( __FILE__ ) . '/core/views/option_field_auto_login_vb_user.php' );
    188321    }
    189322
Note: See TracChangeset for help on using the changeset viewer.