Authorization means phpBB/XenForo

About a year ago I needed to allow the users registered on the forum (phpBB) to authenticate on the website (modX). At that time, the forum has worked and users actively communicated. Decisions MODxBB did not yet exist and had to dream.

the the result is something like this
the
<?php 
global $modx, $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template, $auth; 

$phpbb_root_path = $modx- > config['base_path'] . 'forum/'; 
define('IN_PHPBB', true); 
$phpEx = "php"; 

include($phpbb_root_path . 'includes/functions_install.' . $phpEx); 
include($phpbb_root_path . 'includes/functions_display.' . $phpEx); 
include($phpbb_root_path . 'common.' . $phpEx); 
include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); 

$user->session_begin(); 
$auth- > acl($user->data); 

$user- > setup('ucp'); 

$login = array(); 

if(isset($_POST['logoutForum']) && $user->data['user_id'] != ANONYMOUS) $user->session_kill(); //Leave the room 

if(isset($_POST['login']) && $user->data['user_id'] == ANONYMOUS){ 
$username = request_var('username', ", true); 
$password = request_var('password', ", true); 
$autologin = (!empty($_POST['autologin'])) ? true : false; 
$viewonline = (!empty($_POST['viewonline'])) ? false : true; 
$login = $auth->login($username, $password, $autologin, $viewonline); 
} 

header('Content-type: text/html; charset=UTF-8'); 
header('Cache-Control: private, no-cache="set-cookie"'); 
header('Expires: 0'); 
header('Pragma: no-cache'); 

if((!empty($login) && $login['status'] == LOGIN_SUCCESS) || $user- > data['user_id'] != ANONYMOUS){ 
if(!empty($login)) $auth- > acl($user->data); 

$modx- > setPlaceholder('UserName',get_username_string('full', $user->data['user_id'], $user->data['username'], $user->data['user_colour'])); 
echo $modx- > getChunk('ExitBlock'); 
/* 
Hello [+UserName+] <form method="post" action="/[~[*id*]~]"><input type="submit" name="logoutForum" value="Exit" /></form> 
*/ 
} 
else{ 
if(isset($login['error_msg']) && $login['error_msg']){ //error Handling 
$err = $user- > lang[$login['error_msg']]; 
if ($login['error_msg'] == 'LOGIN_ERROR_USERNAME' || $login['error_msg'] == 'LOGIN_ERROR_PASSWORD'){ 
$err = (!$config['board_contact']) ? sprintf($user- > lang[$login['error_msg']], ", ") : sprintf($user- > lang[$login['error_msg']], '<a hrеf="mailtо:' . htmlspecialchars($config['board_contact']) . '">', '</a>'); 
} 

if($login['error_msg']=='LOGIN_ERROR_ATTEMPTS'){ //Brutus? 
$captcha = & phpbb_captcha_factory::get_instance($config['captcha_plugin']); 
$captcha->init(CONFIRM_LOGIN); 
$template- > assign_vars(array('CAPTCHA_TEMPLATE' => $captcha->get_template())); 
$err = $user- > lang[$login['error_msg']]; 
$err.='<br /><img GS="/forum/ucp.php?mode=confirm&confirm_id='.$template- > _rootref['CONFIRM_IMAGE_LINK'].'" alt="verification Code" /><br /> 
Code below: <input type="text" name="confirm_code" id="confirm_code" size="8" maxlength="8" title="confirmation Code" /><input type="hidden" name="confirm_id" id="confirm_id" value="'.$template- > _rootref['CONFIRM_ID'].'" title="verification Code" /><br />'; 
} 
$modx- > setPlaceholder('ErrorMsg',$err); 
} 
echo $modx- > getChunk('forumLoginForm'); 
/* 
<form method="post" action=""> 
[+ErrorMsg+]<BR> 
Login: <input type="text" name="username" id="username" size="10" title="login" /><br /> 
Password: <input type="password" name="password" id="password" size="10" title="password" /><br /> 
<input type="submit" name="login" value="Login" /> 
</form> 
*/ 
} 
?>


The code is certainly not perfect, but it worked flawlessly.
The topic would be ended if one day came up with the idea to change the engine forum. After having browsed the web it was decided to put XenForo. The determining factors were the following:
    the
  1. Social buns out of the box
  2. the
  3. Ability to import users, topics and posts from phpBB forum 3.0
  4. the
  5. code Comfort
  6. the
  7. of the Active community


the Download, Install, Import... And import was done with preservation of ID-shnik, to be able without problems to redirect the user visits the site at the link of the old forum to the new page.
Now it was necessary to restore the authorization form on the site. As it turned out it is not so difficult, because XenForo code is very clear.
the
<?php 
$noauth=isset($noauth)? $noauth : "; //not yet registred for what? 

$fileDir=$modx- > config['base_path'].'forum/'; 
$startTime = microtime(true); 
require ($fileDir . '/library/XenForo/Autoloader.php'); 
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library'); 

XenForo_Application::modxParserActive(); //Say XenForo that we  have  our own  error  handler 
XenForo_Application::initialize($fileDir . '/library', $fileDir); 
XenForo_Application::set('page_start_time', $startTime); 

XenForo_Session::startPublicSession(); 
$xfUser = XenForo_Visitor::getInstance(); 
$data=array(); 

if($xfUser->get('user_id')=='0'){ 
$data['back']=isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'/'; 
$data['linkauth']='forum/login/login'; 
$data['noauth']=$modx- > getChunk($noauth); //You need to login 
echo $modx- > parseChunk('forumLoginForm', $data,'[+','+]'); 
/*[+noauth+]<BR> 
<form action="/[+linkauth+]" mеthod="post" class I="xenForm" id="login" style="display: block"> 

<inрut type="hidden" name="remember" value="1" id="ctrl_remember"> 
<inрut type="hidden" name="cookie_check" value="1"> 
<inрut type="hidden" name="redirect" value="[+back,+]"> 
<inрut type="hidden" name="_xfToken" value=""> 
</fоrm>*/ 

}else{ 
$data['UserName']=$xfUser->get('username'); 
echo $modx- > parseChunk('ExitBlock', $data,'[+','+]'); 
} 
?>


And now begins the most interesting: I will explain what is this mysterious function modxParserActive.

Open the file Application.php from the folder library/XenForo/ in the class XenForo_Application appends the definition of a new variable
the
protected static $_modxParser = false;

Then define a new function

the
public static function modxParserActive() 
{ 
self::$_modxParser = true; 
} 
public static function GetModxParser() 
{ 
return self::$_modxParser; 
}

And the final touch. In function beginApplication wrap code
the
@ini_set('output_buffering', false); 

// see http://bugs.php.net/bug.php?id=36514 
if (!@ini_get('output_handler')) while (@ob_end_clean()); 

error_reporting(E_ALL | E_STRICT &~8192); 
set_error_handler(array('XenForo_Application', 'handlePhpError')); 
set_exception_handler(array('XenForo_Application', 'handleException'));


in the following condition

the
if(!self::GetModxParser()){ 
...... 
}


Yes, I know that the climb code engine is not the best idea, but it is exactly this that was the whole point. This post. While this is the only way I was able to override the compatibility conflict modx and XenForo. The fact that modx parse the chunks, snippets using ob_end_clean; And since this function was previously called modx receives an empty buffer with all its consequences.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

ODBC Firebird, Postgresql, executing queries in Powershell

garage48 for the first time in Kiev!

The Ministry of communications wants to ban phones without GLONASS