rendered paste body<?php/******************************************************************************* smf.php ********************************************************************************* SMF: Simple Machines Forum ** Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) ** =========================================================================== ** Software Version: SMF 1.1 RC2 ** Software by: Simple Machines (http://www.simplemachines.org) ** Copyright 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 Lewis Media. ** ** 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. *******************************************************************************//* This file is the core of the Mambo-SMF bridge component string ob_mambofix(string $buffer) - fixes URLs in SMF to point to Mambo component bool integrate_redirect (&$setLocation, $refresh) - sets redirection in forum for form submissions mambo_smf_exit(string $with_output) - exits SMF securely integrate_change_email($username, $email) - updates Mambo with email changes made in SMF integrate_reset_pass($old_username, $username, $password) - updates Mambo username and password changes made in SMF integrate_logout($username) - logs user out of Mambo integrate_outgoing_email($subject, &$message, $headers) - fixes URLs in outgoing emails to direct traffic to the component correctly integrate_login($username, $passwd, $cookielength) - writes user into Mambo if user doesn't already exist - logs user into Mambo integrate_validate_login($username, $password, $cookietime) - validates the existence of the user in Mambo - checks for user in SMF - writes user to SMF if none exists integrate_delete_member($user) - deletes mamber from Mambo when admin deletes SMF member integrate_register($regOptions, $theme_vars) - writes user into Mambo upon registration in SMF. Function for use with "SMF Registration" option in Mambo admin panel.*///This helps Mambo allow posts with HTML. Please note that this does not necessarily work with all installations.if (!defined('_MOS_ALLOWHTML')) define('_MOS_ALLOWHTML', 0x0002);global $params, $database, $mosConfig_dbprefix, $db_prefix, $mosConfig_db;global $mosConfig_absolute_path, $wrapped, $mosConfig_live_site, $mosConfig_sef;global $bridge_reg, $menu, $Itemid, $context, $cb_reg;// Get the configuration. This will tell Mambo where SMF is, and some integration settingsrequire($mosConfig_absolute_path . '/administrator/components/com_smf/config.smf.php');require($mosConfig_absolute_path . '/administrator/components/com_smf_registration/config.smf_registration.php');//Retrofit the query string$_SERVER['QUERY_STRING'] = strtr($_SERVER['QUERY_STRING'], array('&?' => '&', '&?' => '&' , '#' => '.'));//define the integration functionsdefine('SMF_INTEGRATION_SETTINGS', serialize(array( 'integrate_change_email' => 'integrate_change_email', 'integrate_reset_pass' => 'integrate_reset_pass', 'integrate_exit' => 'mambo_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')));// Are Mambo and SMF using the same database connection?if (empty($Itemid) && $database->_resource == $db_connection){ $database->setQuery(" SELECT id FROM #__menu WHERE link = 'index.php?option=com_smf' LIMIT 1"); $Itemid = $database->loadResult();}// This fixes automatic links that might look like Itemid=43?action=...if (strpos($_SERVER['QUERY_STRING'], 'Itemid=' . $Itemid . '?') !== false) $_SERVER['QUERY_STRING'] = strtr($_SERVER['QUERY_STRING'], array('Itemid=' . $Itemid . '?' => 'Itemid=' . $Itemid . '&'));// Just in case it gets flushed in the middle for any reason..ob_start('ob_mambofix');ob_start();require($smf_path . '/index.php');$buffer = ob_get_contents();ob_end_clean();ob_start();// --- This means that the buffer may be mambofix'd twice - see above ob_start.echo ob_mambofix($buffer);// Ignore notices from Mambo.error_reporting(E_ALL & !E_NOTICE);if ($database->_resource == $db_connection) mysql_select_db($mosConfig_db);// --- Changed to use action in a notice-friendly way. I would still recommend instead: (more mod friendly!)if ($wrapped != true || !in_array('main', $context['template_layers'])){ mysql_select_db($db_name); die;}echo '<div class="componentheading"> ', $menu->name, '</div>';// Rewrite URLs to include the session ID.function ob_mambofix($buffer){ global $scripturl, $mosConfig_live_site, $mosConfig_sef, $boardurl; global $bridge_reg, $Itemid; $myurl = $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf&Itemid=' . $Itemid . '&'; $buffer = str_replace('"?board=', $mosConfig_sef=='1' ? '"/board,' : '"&board=', $buffer); $buffer = str_replace('"?action=', $mosConfig_sef=='1' ? '"/action,' : '"&action=', $buffer); $buffer = str_replace('href="#', 'href="'.$mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) .'?'.$_SERVER['QUERY_STRING'].'#', $buffer); $buffer = str_replace('"' . $scripturl . '?', '"' . $myurl, $buffer); $buffer = str_replace('"' . $scripturl . '"', '"' . substr($myurl, 0, -5) . '"', $buffer); $buffer = str_replace('\'' . $scripturl, '\'' . $myurl, $buffer); $buffer = str_replace($scripturl . '#', substr($myurl, 0, -5) . '#', $buffer); $buffer = str_replace('option=com_smf;Itemid=' . $Itemid . ';', '', $buffer); // New bridged profile options. Not yet available //$buffer = str_replace($scripturl . 'action=profile;', $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf_profile&task=view&', $buffer); //$buffer = str_replace($scripturl . 'action=profile', $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf_profile&task=view', $buffer); // Bridge registration links if ($bridge_reg==true) { $buffer = str_replace($myurl . 'action=register', $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=register', $buffer); $buffer = str_replace($myurl . 'action=activate', $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=lostCode', $buffer); $buffer = str_replace($myurl . 'action=reminder', $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=lostPassword', $buffer); } //Obsolete // $buffer = str_replace('action=login2', 'action=mambo_login' , $buffer); // $buffer = str_replace('action=logout', 'action=mambo_logout' , $buffer); // Don't forget attachments $buffer = str_replace($myurl . 'action=dlattach', $boardurl . '/' . basename($_SERVER['PHP_SELF']) . '?action=dlattach', $buffer); // and now for SEF if (!empty($mosConfig_sef) && $mosConfig_sef == '1') { preg_match_all('~[\(=]' . preg_quote('"' . $mosConfig_live_site . '/index.php?option=com_smf') . '([^"]*)"{1}~', $buffer, $nonsefurls); foreach($nonsefurls[0] as $nonsefurl) { $sefurl = sefReltoAbs(substr($nonsefurl, strlen($mosConfig_live_site) + 3, strlen($nonsefurl) - strlen($mosConfig_live_site) - 4)); $sefurl = str_replace(";", "/", $sefurl); $sefurl = substr($sefurl, 0, strpos($sefurl, 'option')) . preg_replace('/(\/)([^,]*)(#)/', '$1$2,$2$3', substr($sefurl, strpos($sefurl, 'option'), strlen($sefurl))); $sefurl = substr($sefurl, 0, strpos($sefurl, 'option')) . preg_replace('/(\/)([^,]*)(\/)/', '$1$2,$2$3', substr($sefurl, strpos($sefurl, 'option'), strlen($sefurl))); if (substr($sefurl, strlen($sefurl) - 1, 1) == '/') $sefurl = substr($sefurl, 0, strlen($sefurl) - 1); $buffer = str_replace(substr($nonsefurl,1,strlen($nonsefurl)), '"' . $sefurl . '"', $buffer); } } return $buffer;}function mambo_smf_url($url){ global $scripturl, $Itemid, $mosConfig_live_site; if ($Itemid == 0) $Itemid = (int) $_REQUEST['Itemid']; $myurl = $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?option=com_smf&Itemid=' . $Itemid . '&'; $url = str_replace($scripturl . '?', $myurl, $url); $url = str_replace($scripturl, $myurl, $url); return $url;}function mambo_smf_exit($with_output){ global $wrapped, $mosConfig_db, $database, $cur_template; $buffer = ob_get_contents(); ob_end_clean(); header('Content-Encoding: none'); if (!$with_output || !$wrapped) { echo ob_mambofix($buffer); exit; } foreach ($GLOBALS as $name => $value) $$name = &$GLOBALS[$name]; $_MOS_OPTION['buffer'] = ob_mambofix($buffer); if ($database->_resource == $db_connection) mysql_select_db($mosConfig_db); // Ignore notices from Mambo. error_reporting(0); initGzip(); // Loads template file. if (!file_exists('templates/' . $cur_template . '/index.php')) echo _TEMPLATE_WARN . $cur_template; else { require_once('templates/' . $cur_template . '/index.php'); echo '<!-- ' . time() . ' -->'; } // Displays queries performed for page. if ($mosConfig_debug) { echo $database->_ticker . ' queries executed'; echo '<pre>'; foreach ($database->_log as $k => $sql) echo $k + 1, "\n", $sql, '<hr />'; } doGzip(); die;}function integrate_reset_pass($old_username, $username, $password){ global $mosConfig_db, $mosConfig_dbprefix, $db_name; $newpass = md5($password); mysql_select_db($mosConfig_db); $request = mysql_query(" UPDATE {$mosConfig_dbprefix}users SET password = '$newpass', username = '$username' WHERE username = '" . addslashes($old_username) . "' LIMIT 1"); mysql_select_db($db_name); return true;}function integrate_change_email($username, $email){ global $mosConfig_db, $mosConfig_dbprefix, $db_name; mysql_select_db($mosConfig_db); $request = mysql_query(" UPDATE {$mosConfig_dbprefix}users SET emailAddress = '$email' WHERE username = '" . addslashes($username) . "' LIMIT 1"); mysql_select_db($db_name); return true;}function integrate_outgoing_email($subject, &$message, $headers){ global $boardurl, $mosConfig_live_site, $Itemid, $scripturl, $mosConfig_sef; if (strpos($message, $scripturl) != 0) { $message = str_replace ($scripturl, '="' . $scripturl, $message); $message = un_htmlspecialchars(ob_mambofix($message)); $message = str_replace ('="', '', $message); if ($mosConfig_sef == '1'){ $message = str_replace ($mosConfig_live_site . '/index.php', 'index.php', $message); preg_match ('~index\.php.+~', $message, $url); if (isset($url[0])){ $new_url = sefReltoAbs($url[0]); $new_url = str_replace(';', '/', $new_url); $message = str_replace($url[0], $new_url, $message); } } }}function integrate_login($username, $passwd, $cookielength){ global $mosConfig_db, $mosConfig_dbprefix, $user_settings, $db_name; global $scripturl, $cb_reg, $mosConfig_absolute_path, $mosConfig_live_site; require($mosConfig_absolute_path . '/administrator/components/com_smf_registration/config.smf_registration.php'); if (!isset($passwd) || $passwd == '' || $passwd == null) $passwd = 'migrated'; mysql_select_db($mosConfig_db); // Let's see if the user already exists in Mambo $mos_sql = " SELECT username, block, password FROM {$mosConfig_dbprefix}users WHERE username = '$username';"; $mos_result = mysql_query($mos_sql); $mos_array = mysql_fetch_array($mos_result); $mos_user = $mos_array[0]; //if the user doesn't exist in Mambo, they've already been verified by SMF, so register them into Mambo as well if (!isset($mos_user)) { $mos_write = mysql_query(" INSERT INTO {$mosConfig_dbprefix}users (name,username,email,password,gid) VALUES ('$username', '$username', '$user_settings[emailAddress]', '$passwd', '18')"); $mos_find_id = mysql_query(" SELECT id FROM {$mosConfig_dbprefix}users WHERE name = '$username' LIMIT 1"); $mos_id_array = mysql_fetch_array($mos_find_id); $mos_id = $mos_id_array[0]; $mos_write = mysql_query(" INSERT INTO {$mosConfig_dbprefix}core_acl_aro (section_value, value, order_value, name, hidden) VALUES ('users', '$mos_id', '0', '$username', '0');"); $mos_map_sql = mysql_query(" SELECT aro_id FROM {$mosConfig_dbprefix}core_acl_aro WHERE name = '$username' LIMIT 1"); $mos_map_array = mysql_fetch_array($mos_map_sql); $aro_id = $mos_map_array[0]; $mos_write = mysql_query (" INSERT INTO {$mosConfig_dbprefix}core_acl_groups_aro_map (group_id, section_value, aro_id) VALUES ('18', '', '$aro_id');"); //Do you have Community Builder? Might has well get them in there too... if ($cb_reg=="on") $sql = mysql_query(" INSERT INTO {$mosConfig_dbprefix}comprofiler (id, user_id) VALUES ('$mos_id', '$mos_id')"); //maybe this user exists, but has not yet activated their account? } elseif ($mos_array[1] == 1) { echo ' <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[ alert("' . _LOGIN_BLOCKED . '"); window.history.go(-1); // ]]></script>', "\n"; exit(); } $mos_pwd_qry = mysql_query(" SELECT password FROM {$mosConfig_dbprefix}users WHERE username = '$username' LIMIT 1"); list($passwd) = mysql_fetch_row($mos_pwd_qry); $currentDate = date("Y-m-d\TH:i:s"); mysql_query(" UPDATE {$mosConfig_dbprefix}users SET lastvisitDate = '$currentDate' WHERE username = '$username'"); // Get rid of the online entry for that old guest.... // Log into Mambo now..... $request = mysql_query(" SELECT id, gid, block, usertype FROM {$mosConfig_dbprefix}users WHERE username = '$username' AND password = '$passwd'"); $row = mysql_fetch_array($request); // Fudge the group stuff. $session =& $this['_session']; $session['guest'] = 0; $session['username'] = $username; $session['userid'] = intval($row['id']); $session['usertype'] = $row['usertype']; $session['gid'] = intval($row['gid']); $currentDate = date("Y-m-d\TH:i:s"); mysql_query(" UPDATE {$mosConfig_dbprefix}users SET lastvisitDate = '$currentDate' WHERE id = '$session[userid]'"); $lifetime = time() + (60 * $cookielength); setcookie('usercookie[username]', $username, $lifetime, '/'); setcookie('usercookie[password]', $passwd, $lifetime, '/'); setcookie('sessioncookie', '', -3600, '/'); //Let's make sure this works in both Mambo and Joomla $sessionCookieName = md5('site' . $mosConfig_live_site); setcookie($sessionCookieName, '', -3600, '/'); //Let's try to minimize the effects of those nasty extra sessions $sql = mysql_query(" DELETE FROM {$mosConfig_dbprefix}session WHERE username = '$username'"); //Try to set the redirect by the login module params... $sql = mysql_query (" SELECT params FROM {$mosConfig_dbprefix}modules WHERE module='mod_smf_login'"); $result = mysql_fetch_array($sql); $paramlist = $result[0]; $paramslogin = mosParseParams($paramlist); $returncheck = $paramslogin->login; // Default, in case we couldn't find anything, or the admin forgot to configure the login module // direct to SMF => 1 // direct to frontpage => 0 // option 2 cannot be used for default if (empty($_SESSION['return']) && ($returncheck == '' || $returncheck == '2')) $returncheck = '1'; //Set the redirection URL switch ($returncheck) { //Redirect to Mambo case '0'; $_SESSION['login_url'] = $GLOBALS['mosConfig_live_site']; break; //Redirect to SMF case '1'; $_SESSION['login_url'] = $scripturl; break; //Redirect back to login page case '2'; $_SESSION['login_url'] = sefReltoAbs($_SESSION['return']); break; //There still might be nothing.... case ''; $_SESSION['login_url'] = $GLOBALS['mosConfig_live_site']; break; } mysql_select_db($db_name); return true;}function integrate_redirect (&$setLocation, $refresh){ global $boardurl, $mosConfig_live_site, $mosConfig_sef; $myurl = sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_smf&Itemid=' . $_REQUEST['Itemid'] . '&' ); if ($setLocation == '') $setLocation = $myurl; // Certain URLs need to be done this way if (substr($setLocation, 0, 4) == 'http' && $_REQUEST['action'] != 'logout' && (!isset($_REQUEST['sa']) || $_REQUEST['sa'] != 'check')) { $setLocation = mambo_smf_url($setLocation); $setLocation = un_htmlspecialchars(ob_mambofix($setLocation)); $setLocation = substr($setLocation, strlen($mosConfig_live_site) + 1, strlen($setLocation) - 1); if ($mosConfig_sef == 1){ $setLocation = sefReltoAbs($setLocation); } else { $setLocation = $mosConfig_live_site . '/' . $setLocation; } } // and others like this else { if ($mosConfig_sef == 1){ $setLocation = sefReltoAbs($setLocation); } else { if (substr($setLocation, 0, 4) != 'http'){ $setLocation = $mosConfig_live_site . '/' . $setLocation; } } $setLocation = un_htmlspecialchars(ob_mambofix($setLocation)); } if(substr($setLocation, strlen($setLocation) - 1, strlen($setLocation)) == '/') { $setLocation = substr($setLocation, 0, strlen($setLocation) - 1); $setLocation = str_replace(';', '/', $setLocation); }}function integrate_logout ($username){ global $mosConfig_db, $mosConfig_dbprefix, $db_name, $mosConfig_live_site, $scripturl; setcookie('usercookie[username]', $username, time() - 3600, '/'); setcookie('usercookie[password]', '', time() - 3600, '/'); setcookie('sessioncookie' , '' , time() - 3600 , '/'); //Let's make sure this works in both Mambo and Joomla $sessionCookieName = md5('site' . $mosConfig_live_site); setcookie($sessionCookieName, '', time() - 3600, '/'); mysql_select_db($mosConfig_db); // Let's try to minimize the effects of those nasty extra sessions. $sql = mysql_query(" DELETE FROM {$mosConfig_dbprefix}session WHERE username = '$username'"); //Try to set up the logout redirection if (!isset($_REQUEST['returnurl'])) { $sql = mysql_query(" SELECT params FROM {$mosConfig_dbprefix}modules WHERE module='mod_smf_login'"); $result = mysql_fetch_array($sql); $paramlist = $result[0]; $paramslogin = mosParseParams($paramlist); $returncheck = $paramslogin->logout; } else $returncheck = $_REQUEST['returnurl']; // Default, in case we couldn't find anything, or the admin forgot to configure the login module // direct to SMF => 1 // direct to frontpage => 0 // option 2 cannot be used for default if (empty($_SESSION['return']) && ($returncheck == '' || $returncheck == '2')) $returncheck = "1"; //Set the redirection URL switch ($returncheck) { //Redirect to Mambo frontpage case "0"; $_SESSION['logout_url'] = $GLOBALS['mosConfig_live_site']; break; //Redirect to SMF case "1"; $_SESSION['logout_url'] = sefReltoAbs($scripturl); break; //Redirect back to logout page case "2"; $_SESSION['logout_url'] = sefReltoAbs($_SESSION['return']); break; } mysql_select_db($db_name);}function integrate_delete_member($user){ global $db_name, $db_prefix, $mosConfig_db, $mosConfig_dbprefix; $query = mysql_query (" SELECT memberName FROM {$db_prefix}members WHERE ID_MEMBER = '$user'"); list($username) = mysql_fetch_row($query); mysql_select_db($mosConfig_db); $query = mysql_query (" DELETE FROM {$mosConfig_dbprefix}users WHERE username = '$username'"); mysql_select_db($db_name);}function integrate_validate_login($username, $password, $cookietime){ global $db_name, $db_prefix, $mosConfig_db, $mosConfig_dbprefix; // 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'"); 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 Mambo? else { mysql_select_db($mosConfig_db); //!!! How about sendEmail and activation? $request = mysql_query(" SELECT name, password, email, UNIX_TIMESTAMP(registerDate) AS dateRegistered, activation FROM {$mosConfig_dbprefix}users WHERE username = '$username'"); //No user in Mambo, either. This guy is just guessing.... if (mysql_num_rows($request) === 0){ mysql_select_db($db_name); return false; } $mos_user = mysql_fetch_assoc($request); mysql_free_result($request); //If there's no user in SMF, and the Mambo/Joomla user isn't activated, we don't want them logging in if ($mos_user['activation']!='') fatal_lang_error('still_awaiting_approval'); mysql_select_db($db_name); //There must be a result, so let's write this one into SMF.... mysql_query(" INSERT INTO {$db_prefix}members (memberName, realName, passwd, emailAddress, dateRegistered, lngfile, buddy_list, pm_ignore_list, messageLabels, personalText, websiteTitle, websiteUrl, location, ICQ, MSN, signature, avatar, usertitle, memberIP, secretQuestion, additionalGroups) VALUES ('$username', '$mos_user[name]', '$mos_user[password]', '$mos_user[email]', $mos_user[dateRegistered], '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')"); return 'retry'; }}function integrate_register($regOptions, $theme_vars){ global $db_name, $db_prefix, $mosConfig_db, $mosConfig_dbprefix; global $regOptions, $cb_reg; mysql_select_db($mosConfig_db); mysql_query(" INSERT INTO {$mosConfig_dbprefix}users (name, username, email, password, gid) VALUES ('" . $regOptions['register_vars']['realName'] . "', '" . $regOptions['register_vars']['memberName'] . "', '" . $regOptions['register_vars']['emailAddress'] . "', '" . md5($regOptions['password']) . "', '18')"); $mos_find_userid = mysql_query(" SELECT `id` FROM {$mosConfig_dbprefix}users WHERE username = '".$regOptions['register_vars']['memberName']."' LIMIT 1"); list($mos_id) = mysql_fetch_row($mos_find_userid); mysql_query( " INSERT INTO {$mosConfig_dbprefix}core_acl_aro (aro_id, section_value, value, order_value, name, hidden) VALUES ('', 'users', '$mos_id', '0', '" . $regOptions['register_vars']['realName'] . "', '0');"); $mos_map_sql = mysql_query(" SELECT aro_id FROM {$mosConfig_dbprefix}core_acl_aro WHERE name = '".$regOptions['register_vars']['realName']."' LIMIT 1"); list($aro_id) = mysql_fetch_row($mos_map_sql); mysql_query (" INSERT INTO {$mosConfig_dbprefix}core_acl_groups_aro_map (group_id, section_value, aro_id) VALUES ('18', '', '" . $aro_id . "');"); //Do you have Community Builder? Might has well get them in there too... if ($cb_reg == 'on') mysql_query(" INSERT INTO {$mosConfig_dbprefix}comprofiler (id, user_id) VALUES ('$mos_id', '$mos_id')"); mysql_select_db($db_name);}?>