vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   I'm making a vB/WP bridge and need some help (https://vborg.vbsupport.ru/showthread.php?t=246600)

SelinaK 07-15-2010 12:48 PM

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...


All times are GMT. The time now is 08:25 PM.

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.01107 seconds
  • Memory Usage 1,784KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete