[Tutorial] Integrate your website around phpBB3

How-to's, little tricks, tutorials, code examples (snippets) and read-me's.

Re: [Tutorial] Integrate your website around phpBB3

Postby eviL3 » 15 Jan 2008, 09:31

CoC wrote:Just a question is it possible to use language files outside of the forum directory?

The problem is that the languages are relative to language/{lang}/. You could overwrite $user->lang_path, but only do so if you know what you're doing ;)
Image
User avatar
eviL3    
MOD Author
MOD Author
 
Posts: 1002
Joined: 05 Nov 2006, 08:14
Location: Cooking in the MODs kitchen
Gender: Male


Re: [Tutorial] Integrate your website around phpBB3

Postby Highway of Life » 15 Jan 2008, 10:05

Mark,

There is either whitespace (most likely) before the <?php in your 404error.php file.
If there is no whitespace, it could be saved as UTF-8 with BOM, which basically puts a couple of UTF-8 chars at the beginning of the file (before the <?php)
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [Tutorial] Integrate your website around phpBB3

Postby Shadow of Wishes » 15 Jan 2008, 10:59

Here is the 404error.php:
error.JPG
404error.php code
Image
PHPBB3DB Portal: Community Portal
Developer Portal: Your PHPBB3DB Community

Shadow of Wishes    
Translator
Translator
 
Posts: 382
Joined: 18 May 2006, 13:56
Location: All around the world....why, do you miss me? :D
Favorite Team: The one i choose
Gender: Male
phpBB Knowledge: 5

Re: [Tutorial] Integrate your website around phpBB3

Postby eviL3 » 15 Jan 2008, 12:44

Dreamweaver may hide the BOM, i'm not sure. Perhaps try an other editor, for example PSPad.
Image
User avatar
eviL3    
MOD Author
MOD Author
 
Posts: 1002
Joined: 05 Nov 2006, 08:14
Location: Cooking in the MODs kitchen
Gender: Male

Re: [Tutorial] Integrate your website around phpBB3

Postby Shadow of Wishes » 16 Jan 2008, 01:53

Nice little program eviL3. Ok, and now if i want to create a 500 for example, the code would have to look like this:

We?ll call your siteroot: /www
Your forum is located at: /www/phpBB3

Create a new file: /www/common.php
Code: Select all
<?php
/**
*
* @author David Lewis ( http://startrekguide.com ) Highway of Life
* @package STG
* @version $Id: common.php 165 2007-12-23 05:21:41Z Highway of Life $
* @copyright (c) 2007 Star Trek Guide Group
*
*/

if (!defined('IN_PHPBB') || !defined('ROOT_PATH'))
{
    exit;
}

/**
 * @ignore
 */
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH ROOT_PATH 'phpBB3/';
$phpEx substr(strrchr(__FILE__'.'), 1);
include(
$phpbb_root_path 'common.' $phpEx);
include(
ROOT_PATH 'includes/functions_website.' $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);

// void setup ([ $lang_set = false], [ $style = false])
// language and style setup, we?ll use $style = 1 (prosilver)
$user->setup(false1);

// set your custom template path
// void set_custom_template ( $template_path,  $template_name)
$template->set_custom_template(ROOT_PATH 'template''website');

// Set some basic (global) template variables
$template->assign_vars(array(
    
'U_WEBSITE_STYLESHEET'    => ROOT_PATH 'theme/stylesheet.css',
    
'U_HOME'                => append_sid(ROOT_PATH),
    
'U_FORUM'                => append_sid($phpbb_root_path),
));

?>


Every new page in the ?website? will call the website common.php file.
Each new file will require IN_PHPBB and ROOT_PATH to be defined.

In this tutorial, our new pages will be error pages, namely 404, 500, 403, etc error pages.
They are pretty easy to setup, but first, our new website functions file:

Create a new file: /www/includes/functions_website.php
Code: Select all
<?php
/**
*
* @package STG
* @version $Id: functions_website.php 240 2008-01-04 01:35:39Z Highway of Life $
* @copyright (c) 2007 Star Trek Guide Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
    exit;
}

/**
 * Log Error
 * Error types are standard HTTP error codes (404, 403, 500 etc)
 *
 * @param int $error_type
 */
function log_error($error_type 500)
{
    global 
$user$phpbb_root_path;

    
$error_timestamp date('d-M-Y  H:i:s Z');
    
$user_ip $user->ip;
    
$user_page $user->page['page'];
    
$referer = (isset($_SERVER['HTTP_REFERER'])) ? ' [Referer ' $_SERVER['HTTP_REFERER'] . ']' '';
    
error_log("[$error_timestamp] [$error_type Error] [Client $user_ip] [File $user_page]$referer \n"3$phpbb_root_path 'store/http_error.log');
}
?>


Create a new file: /www/theme/stylesheet.css
Code: Select all
/**
*
* @package STG
* @version $Id$
* @copyright (c) 2007 Star Trek Guide Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/* Some CSS styles for your website (specifically) */


Create a new file: /www/errordocs/500error.php
Code: Select all
<?php
/**
*
* @package phpBB3
* @version $Id: 404error.php 295 2008-01-14 15:28:34Z Highway of Life $
* @copyright (c) 2007 Star Trek Guide Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB'true);
define('ROOT_PATH''./../');
$phpEx substr(strrchr(__FILE__'.'), 1);
include(
ROOT_PATH 'common.' $phpEx);

// since we?re only using one language (en), I?ll just hardcode this...
// void page_header ([ $page_title = ''], [ $display_online_list = true])
page_header('500 Error - Internal server error'false);

// this template file will be located in the custom templates directory
$template->set_filenames(array(
    
'body' => 'errordocs/500_error.html'
));

// log the error
// void log_error ([ $error_type = 500])
log_error(500);

// void page_footer ([ $run_cron = true])
page_footer(false);

?>


Create new file: /www/template/errordocs/500_error.html
Code: Select all
<!-- INCLUDE overall_header.html -->

<
ul class="linklist navlinks">
    <
li><a href="{U_HOME}">Home</a></li>
</
ul>

<
div id="main">
    <
h2 class="imgrep error500">Error 500Internal server error</h2>
    <
h3>The Page you have requested was destroyed.</h3>
    <
p>Our internal server have went to picnic with his familyHell be back at 5 am.</p>
    
</
div>

<!-- INCLUDE 
overall_footer.html -->     


Create new file: /www/.htaccess (assuming one does not already exist)
Add line:
Code: Select all
ErrorDocument 500 /errordocs/500error.php
Image
PHPBB3DB Portal: Community Portal
Developer Portal: Your PHPBB3DB Community

Shadow of Wishes    
Translator
Translator
 
Posts: 382
Joined: 18 May 2006, 13:56
Location: All around the world....why, do you miss me? :D
Favorite Team: The one i choose
Gender: Male
phpBB Knowledge: 5

Re: [Tutorial] Integrate your website around phpBB3

Postby Shadow of Wishes » 18 Jan 2008, 04:27

I've found a bug in this tutorial: if you trey ty\o use this error page on http://site_name.com/folder/error_page.php it works fine , but if i' looking for a page from http://site_name.com/folder/folder2/eror_page.php it prints out the error but there is no stylsheet.

I've added the whole theme directory from the forum in the theme directory needed by the script. I've looked up in the code and the error it's because i have in there
Code: Select all
define('ROOT_PATH''./../');  
and all the styles are tring to take out the design from ./../folder2/styles/theme_name/theme/ and it doesn't find that.

Is there a way to add {SITENAME} instead of ./../ ?
Image
PHPBB3DB Portal: Community Portal
Developer Portal: Your PHPBB3DB Community

Shadow of Wishes    
Translator
Translator
 
Posts: 382
Joined: 18 May 2006, 13:56
Location: All around the world....why, do you miss me? :D
Favorite Team: The one i choose
Gender: Male
phpBB Knowledge: 5

Re: [Tutorial] Integrate your website around phpBB3

Postby CoC » 18 Jan 2008, 05:30

In http://site_name.com/error_page.php - the root path is
Code: Select all
define('ROOT_PATH', './'); 

In http://site_name.com/folder1/error_page.php - the root path is
Code: Select all
define('ROOT_PATH', './../'); 

In http://site_name.com/folder1/folder2/error_page.php - the root path is
Code: Select all
define('ROOT_PATH', './../../'); 

In http://site_name.com/folder1/folder2/folder3/error_page.php - the root path is
Code: Select all
define('ROOT_PATH', './../../../');  


and carry on.
User avatar
CoC    
MOD Author
MOD Author
 
Posts: 490
Joined: 23 Jan 2007, 11:09
Location: Coventry
Favorite Team: Coventry City
Gender: Male
phpBB Knowledge: 8

Re: [Tutorial] Integrate your website around phpBB3

Postby Tilt » 20 Jan 2008, 08:26

Hi, im trying to use this turtorial.. guess im not as good as i think :p

What i realy want is to just be abel to keep the Forum session on "the site" and to restrict access on some pages using user groups.
i dont know if thats where im heading if i use this turtorial. (but thats what it says)

My website look like this

index.php
folder/

forum/index.php
forum/folder/

i guess thats how most have it.
Anyway when i try to use the code here all i get is a blank page and no errors.
Code: Select all
if (!defined('IN_PHPBB') || !define('ROOT_PATH'))
{
    exit;
}

/**
* @ignore
*/
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . 'forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include(ROOT_PATH . 'include/functions_website.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);


So i shanged phpBB3 to forum instead. but that dident change anything.
Code: Select all
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . 'phpBB3/';

Code: Select all
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . 'forum/';


what else is there i should edit?

Allso. im not rly intrested in integrating the theme from the forum since im verry happy with the one i use to the website. im not sure but is it "ok" to just remove the rest of the code?

basicly i did this to test
Code: Select all
// Start session management
$user->session_begin();
$auth->acl($user->data);

// void setup ([ $lang_set = false], [ $style = false])
// language and style setup, we?ll use $style = 1 (prosilver)
//$user->setup(false, 1);

// set your custom template path
// void set_custom_template ( $template_path,  $template_name)
//$template->set_custom_template(ROOT_PATH . 'template', 'website');

// Set some basic (global) template variables
//$template->assign_vars(array(
//    'U_WEBSITE_STYLESHEET'    => ROOT_PATH . 'theme/stylesheet.css',
//    'U_HOME'                => append_sid(ROOT_PATH),
//    'U_FORUM'                => append_sid($phpbb_root_path),
//));

?>


Or will that cause errors? :o

Here are the files i have

.htaccess
index.php (begins with including common.php)
/errordocs/404error.php
/forum/index.php
/include/common.php
/include/functions_website.php
/template/overall_footer.html
/template/overall_header.html
/template/errordocs/404_error.html

The only file i have edited is common.php. In my world thats the only file of intrest for me? But custom error pages wold be cool so... :p

Hope i have been clear enough and that some one can help me.
Tilt
Crewman
Crewman
 
Posts: 4
Joined: 20 Jan 2008, 07:56
Gender: Male

Re: [Tutorial] Integrate your website around phpBB3

Postby wkheathjr » 20 Jan 2008, 15:16

What is the difference between the common.php provided on this thread vs the common.php file that currently exist in the forum folder?

I have used similar integrated code provided but kept getting error message that common.php file doesn't exist. I can see that common.php file in this thread is much shorter than the common.php file that exist in the forum.
wkheathjr    
Cadet I
Cadet I
 
Posts: 18
Joined: 20 Jan 2008, 15:11
Gender: Male

Re: [Tutorial] Integrate your website around phpBB3

Postby CoC » 20 Jan 2008, 18:15

You seem to have most things correct other than the common.php file,

/.htaccess
/index.php
/common.php
/errordocs/404error.php
/forum/~ (All phpBB Files)
/include/functions_website.php
/template/overall_footer.html
/template/overall_header.html
/template/errordocs/404_error.html
User avatar
CoC    
MOD Author
MOD Author
 
Posts: 490
Joined: 23 Jan 2007, 11:09
Location: Coventry
Favorite Team: Coventry City
Gender: Male
phpBB Knowledge: 8

PreviousNext

Return to Tutorials and How-Tos

Who is online

Users browsing this forum: Exabot [Bot], JikeSpider and 6 guests