Próbuję samodzielnie zintegrować logowanie w moim serwisie z forum phpbb3, ale moje pytanie jest bardziej ogólne.
Mam plik index.php:
<?php
header('Content-Type: text/html; charset=iso-8859-2');
define('SKIN_NAME' , 'darktower'); define('SRC_DIR' , './sources/'); define('CLASS_DIR' , SRC_DIR
. 'classes/'); define('SUB_DIR' , SRC_DIR
. 'sub/'); define('HTML_DIR' , './skin/' . SKIN_NAME
. '/'); //Tells PhpBB we're not hackers. Includes the common.php file from the forums.
$phpbb_root_path = '../forum/';
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management. This allows us access to some of the user's information when they are logged in.
$user->session_begin();
$auth->acl($user->data);
$user->setup();
//Some common thing's you'll use. $username gives the username, and $userid gives the unique ID of the loggedin user.
$username = $user->data['username'];
$userid = $user->data['user_id'];
require_once 'config.php';
require_once SRC_DIR . 'functions.php';
$input = getInput();
require_once CLASS_DIR . 'class_mysql.php';
require_once CLASS_DIR . 'class_core.php';
$db = new mysql($sql['host'], $sql['login'], $sql['passw'], $sql['db']);
$res = $db->query('SELECT * FROM `config`');
while(!$res->EOF)
{
$config[$res->field['name']] = $res->field['content'];
$res->moveNext();
}
$sess = new session;
if(empty($input['page'])) {
$input['page'] = 'wiesci';
}
else
{
$input['page'] = basename($input['page']);
{
$input['page'] = 'wiesci';
}
}
require SUB_DIR . $input['page'] . '.php';
$screen = new SubPage($db, $sess, $config, $input);
$screen->msg($message);
// Po co niby destruktor...
$screen->finalDisplay();
?>
I jak mogę sprawić, żeby zmienne $username itd. działały także w innych plikach, np. class_core.php?
<?php
class core
{
public $html = '';
public $db = NULL;
public $sess = NULL;
public $config = array(); public $subpage;
public $global_msg = '';
public $access;
protected $online = null;
public $noTemplate = 0;
protected $groups = false;
public function __construct($db, $sess, $config, $input)
{
$this->db = $db;
$this->sess = $sess;
$this->config = $config;
$this->input = $input;
$this->access = $this->getUserAccessLevel($user->data['site_id']);
$this->loadSkin();
}
public function finalDisplay()
{
$this->runSubPage();
if($this->config['page_enabled'] == 0 && !$this->config['disabled_page'])
{
die ( '<br /><br /><center>' . $this->config['disabled_message'] . '</center>'); }
elseif($this->config['page_enabled'] == 0 && $this->config['disabled_page'])
{
header('Location: ' . $this->config['disabled_page']); }
if($this->noTemplate == 0)
{
$out = $this->tpl['page_index'];
$out = str_replace('<%HEADER%>' , $this->tpl['header'] , $out ); $out = str_replace('<%HTML_START%>', $this->tpl['html_start'] , $out ); $out = str_replace('<%PAGE_TOP%>' , $this->tpl['page_top'] , $out ); $out = str_replace('<%PAGE_LEFT%>' , $this->tpl['page_left'] , $out ); $out = str_replace('<%LOGIN_BOX%>' , $user->data['is_registered'] ?
$this->tpl['loginbox_logged'] : $this->tpl['loginbox_not_logged'], $out); $out = str_replace('<%BANNERS%>' , $this->tpl['banners'] , $out ); $out = str_replace('<%PAGE_MAIN%>' , $this->tpl['page_main'] , $out );
$out = str_replace('<%PAGE_FOOT%>' , $this->tpl['page_foot'] , $out ); $out = str_replace('<%CATEGORY_LIST%>', $this->createCategoryList() , $out ); $out = str_replace('<%POOL%>' , $this->createPool() , $out ); $out = str_replace('<%LINKS%>' , $this->createLinks() , $out ); $out = str_replace('<%BASE_HREF%>' , $this->config['base_href'] , $out ); $out = str_replace('<%GLOBAL_TITLE%>' , $this->config['global_title'], $out );
$out = str_replace('<%SUBPAGE%>' , $this->getSubpageHtml(), $out); $out = str_replace('<%GLOBAL_MESSAGE%>', $this->global_msg , $out); $out = str_replace('<%TOP_NEWS%>' , $this->getTopNews() , $out); $out = str_replace('<%TOP_ARTS%>' , $this->getTopArts() , $out); }
else
{
$out = $this->getSubpageHtml();
}
}
private function loadSkin ()
{
// Pobieramy glowny kod htmla z bazy
$res = $this -> db -> select ( "html" );
while ( !$res -> EOF )
{
$this -> tpl [$res -> field ['name']] = $res -> field ['html'];
$res -> movenext();
}
}
function getSubpageHtml ()
{
return $this -> html;
}
}
?>