Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-15-2010, 12:48 PM
SelinaK SelinaK is offline
 
Join Date: Jul 2010
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default I'm making a vB/WP bridge and need some help

Because I needed a very simple vB-Wordpress bridge, I decided to make one, but my knowledge of scripting is so poor, I'd appreciate some help.

The bridge does just this: the user logs in in vB, then goes to the WP site. WP checks vB cookie and signs the user on. When loging out (the logout link from WP is redirected to vB logout), vB logs the user out and deletes the WP cookies, thus logs the user out from WP too.

The login and logout link in WP: I did this in the lame fashion - I edited general-template.php. Is this doable with a plugin? I changed the wp_logout_url and wp_login_url functions:

PHP Code:
function wp_logout_url($redirect '') {
    global 
$vbulletin;
        
    
$args = array( 'action' => 'logout' );
    if ( !empty(
$redirect) ) {
        
$args['redirect_to'] = urlencode$redirect );
    }

    
$hash $vbulletin->userinfo['logouthash'];
    
$logout_url=$vbulletin->options['bburl'].'/login.php?do=logout&logouthash='.$hash;

    return 
apply_filters('logout_url'$logout_url$redirect);


PHP Code:
function wp_login_url($redirect ''$force_reauth false) {
    global 
$vbulletin;
    
    
$login_url=$vbulletin->options['bburl'].'/login.php?do=login';
    return 
apply_filters('login_url'$login_url$redirect);
    

vB plugin: this is in fact the WP clear cookie code with the URLs edited. I would like to pull the Wordpress site url from its database, but I don't know how, so I hardcoded it for now (how do I read it from the database?).
The plugin is hooked to the logout_process in vB. I just added the code in the plugin manager.

PHP Code:
/**
     * Used to guarantee unique hash cookies
     * @since 1.5
     */
    
if ( !defined'COOKIEHASH' ) ) {
        
$siteurl 'here goes the site url';
        if ( 
$siteurl )
            
define'COOKIEHASH'md5$siteurl ) );
        else
            
define'COOKIEHASH''' );
    }

    
/**
     * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
     * @since 2.5.0
     */
    
$wp_default_secret_key 'put your unique phrase here';

    
/**
     * @since 2.0.0
     */
    
if ( !defined('USER_COOKIE') )
        
define('USER_COOKIE''wordpressuser_' COOKIEHASH);

    
/**
     * @since 2.0.0
     */
    
if ( !defined('PASS_COOKIE') )
        
define('PASS_COOKIE''wordpresspass_' COOKIEHASH);

    
/**
     * @since 2.5.0
     */
    
if ( !defined('AUTH_COOKIE') )
        
define('AUTH_COOKIE''wordpress_' COOKIEHASH);

    
/**
     * @since 2.6.0
     */
    
if ( !defined('SECURE_AUTH_COOKIE') )
        
define('SECURE_AUTH_COOKIE''wordpress_sec_' COOKIEHASH);

    
/**
     * @since 2.6.0
     */
    
if ( !defined('LOGGED_IN_COOKIE') )
        
define('LOGGED_IN_COOKIE''wordpress_logged_in_' COOKIEHASH);

    
/**
     * @since 2.3.0
     */
    
if ( !defined('TEST_COOKIE') )
        
define('TEST_COOKIE''wordpress_test_cookie');

    
/**
     * @since 1.2.0
     */
    
if ( !defined('COOKIEPATH') )
        
define('COOKIEPATH'preg_replace('|https?://[^/]+|i''''here goes the wordpress url' '/' ) );

    
/**
     * @since 1.5.0
     */
    
if ( !defined('SITECOOKIEPATH') )
        
define('SITECOOKIEPATH'preg_replace('|https?://[^/]+|i''''here goes the wordpress url' '/' ) );

    
/**
     * @since 2.6.0
     */
    
if ( !defined('ADMIN_COOKIE_PATH') )
        
define'ADMIN_COOKIE_PATH'SITECOOKIEPATH 'wp-admin' );

    
/**
     * @since 2.6.0
     */
    
if ( !defined('PLUGINS_COOKIE_PATH') )
        
define'PLUGINS_COOKIE_PATH'preg_replace('|https?://[^/]+|i'''WP_PLUGIN_URL)  );

    
/**
     * @since 2.0.0
     */
    
if ( !defined('COOKIE_DOMAIN') )
        
define('COOKIE_DOMAIN'false);



setcookie(AUTH_COOKIE' 'time() - 31536000ADMIN_COOKIE_PATHCOOKIE_DOMAIN);
setcookie(SECURE_AUTH_COOKIE' 'time() - 31536000ADMIN_COOKIE_PATHCOOKIE_DOMAIN);
setcookie(AUTH_COOKIE' 'time() - 31536000PLUGINS_COOKIE_PATHCOOKIE_DOMAIN);
setcookie(SECURE_AUTH_COOKIE' 'time() - 31536000PLUGINS_COOKIE_PATHCOOKIE_DOMAIN);
setcookie(LOGGED_IN_COOKIE' 'time() - 31536000COOKIEPATHCOOKIE_DOMAIN);
setcookie(LOGGED_IN_COOKIE' 'time() - 31536000SITECOOKIEPATHCOOKIE_DOMAIN); 
WP plugin: I used the Wordpress bridge by Jafo and stripped it of everything I don't need (the plugin lets vB handle WP comments, which I don't want).

PHP Code:
<?php
/*
Plugin Name: Simple Vbridge Plugin
Plugin URI: http://www.worldwidecreations.com/
Description: This plugin will bridge to VB so as to use shared userbases.
Version: 4.01.13
Author: WorldWideCreations.com
Author URI: http://www.WorldWideCreations.com/
*/ 

// Start of vB
##  Do not uncomment this.  
#define('SKIP_SESSIONCREATE', 1);
define('DIE_QUIETLY'1);
define('THIS_SCRIPT''vbridge');
define('NOSHUTDOWNFUNC'true);

## If you need to ENABLE hooks vbulletin hooks during this process (rarely) then comment out the next line.
define('DISABLE_HOOKS'true);

$cwd getcwd(); //this is the current working directory, i.e. Wordpress directory

if (!$vwd) {

    
chdir($_SERVER['DOCUMENT_ROOT'] . get_option('vbb_VBRPATH'));

    
$vwd getcwd();
    
$vwd $vwd."/newsite";
(Had to hardcode this again. The document root + vbb_vbrpath returns the website url, not the vB url. My site has this structure:
site.com - the current pages
site.com/newsite - here the vB is installed and I'm testing it before going live
site.com/newsite/web - wordpress
PHP Code:
    
    chdir
($cwd);
    
}

#if (basename($_SERVER['SCRIPT_NAME']) == 'upload.php') { return; }

if ($_GET[action] == 'activate' and $_GET[plugin] == plugin_basename(__FILE__)) {
    
    
$install true;

}


chdir($vwd);
require_once(
'global.php');
chdir($cwd);


add_action ("init","ZjistiUzivatele");


function 
ZjistiUzivatele() {
 global 
$vbulletin;
 
$info $vbulletin->userinfo;
  
 
$jmeno $vbulletin->userinfo['username'];
 
$uzivid $vbulletin->userinfo['userid'];
 
$heslo "pwd"
I put all the users in the WP database with a same password for now. I have no idea how to put the vB password in here and how to handle if the user changes his/her password in the forum
PHP Code:
 $email $vbulletin->userinfo['email'];
  
 require_once(
ABSPATH WPINC '/registration.php');
 
 
//no user signed on
 
if ($jmeno == "Unregistered") {
 }
 
 else {
 
  
//let's see if the user exists in Wordpress
  
if (!username_exists($jmeno)) {
  
    
//if not, we create him
    
wp_create_user($jmeno,$heslo,$email);
  
  }
  
  
$creds = array();
  
$creds['user_login']=$jmeno;
  
$creds['user_password']=$heslo;
  
$creds['remember']=true;
 
  
//now we log him in
  
  
$user1=wp_signon($creds,false);
  
 } 
 
}
     
?> 
Any help appreciated. It would be great if it could make it to the mods section, there are many people wanting this bridge...
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:51 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03459 seconds
  • Memory Usage 2,424KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete