e107 bridge for 2.0 RC 1.2

Started by Darwin94, September 26, 2009, 01:17:44 PM

Previous topic - Next topic

Darwin94

Does anbody know, how i can make the e107 bridge work with 2.0 RC1.2? i just get a blank page, when using it (current version of e107 and SMF). the changes need to be made in the following file, but i dont know what :-[

<?php
/**********************************************************************************
* smf.php                                                                         *
***********************************************************************************
* SMF: Simple Machines Forum                                                      *
* Open-Source Project Inspired by Zef Hemel ([email protected])                    *
* =============================================================================== *
* Software Version:           SMF 1.1                                             *
* Software by:                Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006 by:          Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
* Support, News, Updates at:  http://www.simplemachines.org                       *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version can always be found at http://www.simplemachines.org.        *
**********************************************************************************/

global $context$pref;

@
ini_set('memory_limit''32M');

define('SMF_INTEGRATION_SETTINGS'serialize(array(
'integrate_change_email' => 'integrate_change_email',
'integrate_change_member_data' => 'integrate_change_member_data',
'integrate_reset_pass' => 'integrate_reset_pass',
'integrate_exit' => 'e107_smf_exit',
'integrate_logout' => 'integrate_logout',
'integrate_outgoing_email' => 'integrate_outgoing_email',
'integrate_login' => 'integrate_login',
'integrate_validate_login' => 'integrate_validate_login',
'integrate_redirect' => 'integrate_redirect',
'integrate_delete_member' => 'integrate_delete_member',
'integrate_register' => 'integrate_register',
'integrate_pre_load' => 'integrate_pre_load',
'integrate_verify_user' => 'integrate_verify_user',
)));

$_SERVER['QUERY_STRING'] = str_replace('&amp;''&'$_SERVER['QUERY_STRING']);
$_SERVER['QUERY_STRING'] = str_replace(';''&'$_SERVER['QUERY_STRING']);
   
// always include the class2.php file - this is the main e107 file
   
require_once("../../class2.php");



   
// Include plugin language file, check first for site's preferred language
   
include_lan(e_PLUGIN."smf/languages/smf_".e_LANGUAGE.".php");

if (
$pref['wrapped']=='true')   
require_once(HEADERF);
ob_start('ob_e107fix');
ob_start();

require(
$pref['smf_path'] . '/index.php');
$buffer ob_get_contents();
ob_end_clean();

if (
$pref['wrapped']=='true'){
   
$ns->tablerender($context['page_title'], $buffer);
   require_once(
FOOTERF);
} else {
echo ob_e107fix($buffer);
}


function 
ob_e107fix($buffer) {

global $scripturl$sc;

$buffer str_replace($scripturlSITEURL.'e107_plugins/smf/smf.php'$buffer);
$buffer str_replace(SITEURL.'e107_plugins/smf/smf.php?action=dlattach'$scripturl.'?action=dlattach'$buffer);
$buffer str_replace(SITEURL.'e107_plugins/smf/smf.php?action=verificationcode'$scripturl.'?action=verificationcode'$buffer);
$buffer str_replace('action=admin;g=;e107=;e107_plugins=;smf=;smf_php?action=admin''action=admin'$buffer);
$buffer str_replace('name="seqnum" value="0"''name="seqnum" value="1"'$buffer);


return $buffer;
}

function 
e107_smf_exit($with_output) {

global $context$ns$sql$pref$e107_popup$ph$compression_level$queryinfo$server_support$mySQLdefaultdb$db_name$mySQLprefix;
$buffer ob_get_contents();
ob_end_clean();
$pref['compression_level'] = 6;
//If the admin has chosen Unwrapped, or the page is one that shouldn't be wrapped
if (!$with_output || $pref['wrapped']!='true'){
echo ob_e107fix($buffer);
exit();
}

   
// Ensure the pages HTML is rendered using the theme layout.
   
$ns->tablerender($context['page_title'], $buffer);
   
      
// this generates all the HTML (menus etc.) after the end of the main section
   
require_once(FOOTERF);

   exit();
}

function 
integrate_pre_load ()
{
global $context;

$context['disable_login_hashing'] = true;
}

function 
integrate_redirect (&$setLocation$refresh)
{
global $boardurl;

if ($setLocation == '')
$setLocation e_PLUGIN.'smf/smf.php';

$setLocation un_htmlspecialchars(ob_e107fix($setLocation));

return true;
}

function 
integrate_login ($username$password$cookietime)
{
global $pref$mySQLdefaultdb$sql$db_name$e_event$user_settings$e107;

if (!isset($password) || $password == '' || $password == null)
$password 'migrated';

mysql_select_db($mySQLdefaultdb);

// Let's see if the user already exists in e107
if (!$sql->db_Select("user""*""user_loginname = '".$username."' ")){
//if the user doesn't exist in e107, they've already been verified by SMF, so register them into e107 as well

//we're going to need some more info from SMF first.
mysql_select_db($db_name);
$query mysql_query("
SELECT realName
FROM 
{$db_prefix}members
WHERE memberName = '" 
$username "'");
list($name) = mysql_fetch_row($query);
mysql_select_db($mySQLdefaultdb);
$ip $e107->getip();
$time time();
$u_key md5(uniqid(rand(), 1));
$nid $sql->db_Insert("user""0, '{$name}', '{$username}', '', '{$password}', '{$u_key}', '" $user_settings['emailAddress'] . "', '', '', '', '', '".$time."', '0', '".$time."', '0', '0', '0', '0', '".$ip."', '0', '0', '', '', '0', '0', '{$username}', '', '', '', '0', '' ");
}

$sql->db_Select("user""*""user_loginname = '".$username."' ");
$lode $sql -> db_Fetch();
$user_id intval($lode['user_id']);
$user_name $lode['user_name'];
$user_xup $lode['user_xup'];
$pwd md5($lode['user_password']);

$cookieval $user_id.".".$pwd;

if ($pref['user_tracking'] == "session") {
$_SESSION[$pref['cookie_name']] = $cookieval;
} else {
cookie($pref['cookie_name'], $cookieval, (time() + 3600 24 30));
}

$edata_li = array("user_id" => $user_id"user_name" => $username);
$e_event->trigger("login"$edata_li);
mysql_select_db($db_name);
}

function 
integrate_logout()
{
global $e107$pref$sql$e_event;

$ip $e107->getip();
$udata=(USER === TRUE) ? USERID.".".USERNAME "0";
$sql->db_Update("online""online_user_id = '0', online_pagecount=online_pagecount+1 WHERE online_user_id = '{$udata}' LIMIT 1");

if ($pref['user_tracking'] == "session") {
session_destroy();
$_SESSION[$pref['cookie_name']]="";
}

cookie($pref['cookie_name'], "", (time() - 2592000));
}

function 
integrate_register($Options$theme_vars){

global $db_name$db_prefix$e107$pref$sql$e_event$mySQLdefaultdb$tp;

//What if the realName field isn't being used?
if (!isset($Options['register_vars']['realName']) || $Options['register_vars']['realName']=='')
$Options['register_vars']['realName'] = $Options['register_vars']['memberName'];

$ip $e107->getip();
$time time();

mysql_select_db($mySQLdefaultdb);
$u_key md5(uniqid(rand(), 1));
$username =  $Options['register_vars']['realName'];
$loginname $Options['register_vars']['memberName'];
$nid $sql->db_Insert("user""0, {$username}{$loginname}, '', '"md5($Options['password']) ."', '{$u_key}', ".$Options['register_vars']['emailAddress'] .", '', '', '', '', '".$time."', '0', '".$time."', '0', '0', '0', '0', '".$ip."', '0', '0', '', '', '0', '0', ".$Options['register_vars']['realName'].", '', '', '', '0', '' ");

mysql_select_db($db_name);
}

function 
integrate_outgoing_email($subject, &$message$headers){

global $boardurl;

$message un_htmlspecialchars(ob_e107fix($message));

return true;
}

function 
integrate_validate_login($username$password$cookietime){

global $db_name$db_prefix$mySQLdefaultdb$sql;

// Check if the user already exists in SMF.
mysql_select_db($db_name);
$request mysql_query("
SELECT ID_MEMBER
FROM 
{$db_prefix}members
WHERE memberName = '
$username'
LIMIT 1"
);
if ($request !== false && mysql_num_rows($request) === 1)
{
mysql_free_result($request);
return false;
}

//OK, so no user in SMF.  Does this user exist in e107?
else
{
mysql_select_db($mySQLdefaultdb);

//No user in e107, either.  This guy is just guessing....
if (!$sql->db_Select("user""*""user_loginname='$username'")){
mysql_select_db($db_name);
return false;
}
$row $sql -> db_Fetch();
//If there's no user in SMF, and the e107 user isn't activated or is banned, we don't want them logging in
if ($row['user_ban'] != '0')
fatal_lang_error('still_awaiting_approval');

migrate_e107_to_smf($username$row['user_name'], $row['user_password'], $row['user_email'], $row['user_signature'], $row['user_ip']);

//Retry so that the password can be migrated correctly
return 'retry';
}
}

function 
integrate_reset_pass($old_username$username$password){

global $db_name$mySQLdefaultdb$sql;

$newpass md5($password);

mysql_select_db($mySQLdefaultdb);

$sql->db_Update("user""user_password='$newpass', user_loginname = '$username' WHERE user_loginname='$old_username' ");

mysql_select_db($db_name);

return true;
}

function 
integrate_delete_member($user){

global $db_name$db_prefix$mySQLdefaultdb$sql;

$query1 mysql_query ("
SELECT memberName, realName
FROM 
{$db_prefix}members
WHERE ID_MEMBER = '
$user'");
list($username$name) = mysql_fetch_row($query1);

mysql_select_db($mySQLdefaultdb);

$sql->db_Delete("user""user_loginname='$username' AND user_name='$name' ");

mysql_select_db($db_name);

}

function 
integrate_change_member_data($memberNames$var$value){

global $db_name$db_prefix$mySQLdefaultdb$sql;

$synch_e107_fields = array(
   
'memberName' => 'user_loginname',
'realName' => 'user_name',
'emailAddress' => 'user_email',
'ID_GROUP' => '',
'gender'=>'',
'birthdate'=>'',
'websiteTitle'=>'',
'websiteUrl'=>'',
'location'=>'',
'hideEmail'=>'',
'timeFormat'=>'',
'timeOffset'=>'',
'avatar'=>'',
'lngfile'=>'',
);

$field $synch_e107_fields[$var];

if ($field != ''){
mysql_select_db($mySQLdefaultdb);

foreach ($memberNames as $memberName){
$sql->db_Update("user""$field = $value WHERE user_loginname = '$memberName' LIMIT 1");
}
mysql_select_db($db_name);
}
}

function 
integrate_verify_user ()
{
global $db_name$db_prefix$sql$mySQLdefaultdb;

//if the user is logged into e107, tell SMF to log in as well
if (defined('USERNAME') && USERNAME !=''){
$query mysql_query("
SELECT ID_MEMBER
FROM 
{$db_prefix}members
WHERE realName = '" 
USERNAME "'");
//list($ID_MEMBER) = mysql_fetch_row($query);

//what if this user doesn't exist in SMF yet?
if (!(list($ID_MEMBER) = mysql_fetch_row($query))){
mysql_select_db($mySQLdefaultdb);
if (!$sql->db_Select("user""*""user_name='" USERNAME "'")){
mysql_select_db($db_name);
return false;
}
$row $sql -> db_Fetch();
$ID_MEMBER migrate_e107_to_smf($row['user_loginname'], $row['user_name'], $row['user_password'], $row['user_email'], $row['user_signature'], $row['user_ip']);
}
}
mysql_select_db($db_name);
return $ID_MEMBER;
}

function 
migrate_e107_to_smf($username$name$password$email$signature=''$ip=''){

global $db_name$db_prefix;
mysql_select_db($db_name);
$join_date time();
mysql_query("
INSERT INTO 
{$db_prefix}members 
(memberName, realName, passwd, emailAddress, dateRegistered, ID_POST_GROUP, lngfile, buddy_list, pm_ignore_list, messageLabels, personalText, websiteTitle, websiteUrl, location, ICQ, MSN, signature, avatar, usertitle, memberIP, memberIP2, secretQuestion, additionalGroups)
VALUES ('
$username', '$name', '$password', '$email', $join_date, '4', '', '', '', '', '', '', '', '', '', '', '$signature', '', '', '$ip', '', '', '')");
$memberID mysql_insert_id();

updateStats('member'$memberID$name);

mysql_query("
UPDATE 
{$db_prefix}log_activity 
SET registers = registers + 1 
WHERE date ='" 
date("Y-m-d") . "' 
LIMIT 1"
);
return $memberID;
}
?>

Darwin94

it was blank because i used backslashes (\). now it works for guests, but when i try to login on SMF i get
QuotePassword security has recently been upgraded. Please enter your password again.

and when i am logged in (in e107) it just says "no_access".

What to do?

Orstio

The code in this bridge will not work with SMF 2.0.  All database table fields have been changed from camelCode to lower case only, for example, so any queries in the code will be broken.

You'd be best to try SMF 1.1.x, or wait for the team to make a compatible bridge.

Darwin94

#3
Quote from: Orstio on September 27, 2009, 10:16:55 AM
You'd be best to try SMF 1.1.x,

is downgrading possible?

Quote from: Orstio on September 27, 2009, 10:16:55 AM
or wait for the team to make a compatible bridge.

any idea when?

Edit: mmh, actually there cant be such a big difference, there are just two errors in the log (ok, the bannerlan thing is with multiple numbers, but actually it's the same)

Quote
8: Use of undefined constant BANNERLAN_16 - assumed 'BANNERLAN_16'
?http://.../e107_plugins/smf/smf.php

8: Undefined variable: BANNER_TABLE_IP
?http://.../e107_plugins/smf/smf.php

Orstio

BANNERLAN_16 and BANNER_TABLE_IP are e107 constants not used anywhere in smf.php to my knowledge.  There is something far more wrong there than it appears at first glance.

TheDisturbedOne

The bridge doesn't connect the users AFAIK, it just adds a tab to the menu.

Orstio

Quote from: TheDisturbedOne on September 27, 2009, 06:38:53 PM
The bridge doesn't connect the users AFAIK, it just adds a tab to the menu.

You couldn't be more wrong.

TheDisturbedOne

Quote from: Orstio on September 27, 2009, 06:44:35 PM
Quote from: TheDisturbedOne on September 27, 2009, 06:38:53 PM
The bridge doesn't connect the users AFAIK, it just adds a tab to the menu.

You couldn't be more wrong.
Explain more then.  Have you ran it?

Orstio

Quote from: TheDisturbedOne on September 27, 2009, 07:15:21 PM
Quote from: Orstio on September 27, 2009, 06:44:35 PM
Quote from: TheDisturbedOne on September 27, 2009, 06:38:53 PM
The bridge doesn't connect the users AFAIK, it just adds a tab to the menu.

You couldn't be more wrong.
Explain more then.  Have you ran it?

I built/wrote it.  Tested it.  Used a live site as a sandbox for it.

TheDisturbedOne

Hmm.  Can you explain how to configure it?  I corrected the path but got:
Content Encoding Error

The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

    *   Please contact the website owners to inform them of this problem.

Unfortunately contacting myself won't do much of anything lol :D

Orstio

Turn off compressed output in SMF.

TheDisturbedOne

#11
Worked like a charm.
Thanks for writing it, and for the help. 

EDIT: I tried with a new account, and the bridge didn't work.  Any suggestions?

Orstio


TheDisturbedOne

http://disturbedmb.com
http://disturbedmb.com/site for the e107

It won't let people register on e107 for some reason.

Orstio

#14
You have some sort of SEO mod installed in SMF?

The bridge works by rewriting URLs back to itself.  If those URLs are rewritten by a mod like an SEO mod, the bridge can't find them in the page to rewrite them properly.

TheDisturbedOne

Yeah, Pretty URLs for topic and boards, but not actions.

Orstio

If you want to use a bridge, you need to remove that.  If you want SEO URLs, you need something from e107, not SMF.

BTW:  Registering on your e107 and clicking on the Forum tab transferred me over and logged me in flawlessly.

TheDisturbedOne

So would my forum's new URL be the smf.php one or could I just use the current URL at the domain?

I'll just have them register at the forum, since it works that way.

Orstio

Quote from: TheDisturbedOne on September 27, 2009, 08:49:08 PM
So would my forum's new URL be the smf.php one or could I just use the current URL at the domain?

I'll just have them register at the forum, since it works that way.

I want to be careful how I answer that.

The smf.php is the URL at which everyone should access the forum.

You do not ever want to redirect from the current URL to the smf.php, in terms of a .htaccess file, for example.

You do not ever want to change the Forum URL in the SMF settings.


Advertisement: