Need a little help - phpBB3

JohnMac

Acquaintance
Joined
Jan 18, 2009
Messages
26
Reaction score
0
FP$
6
I really like the template you have for the homepage..

I have a phpBB forum under /forums/ on my directory and cannot find a way to implement the phpBB login system on a template for the main site.

Could you provide any help with this? I see you have it so it shows the login/register buttons when you are a guest and it changes once you Login.

Is there anyone I can pay to have this done for me?
 
Benefits of integrating your site around phpBB3 include security, session handling, same design and the use of the many useful phpBB3 functions such as request_var().

This guide is only for standard prosilver, you subsilver2 people, sorry!

Let’s say your forum is located relative to your root directory in /phpBB3/ (ie. Mysite.com/phpBB3/). This is very important.

Create a new file in /phpBB3/includes/ called website_functions.php. This file will hold all of our website php functions and code.

In your website_functions.php file put this code.
Code:
<?php
/**
*
*@ SETTINGS / CUSTOMIZING
*@ 
*@ $forum_id = 2 
*@ Change the 2 variable to which FORUM ID you want the annoucnements to be pulled from.
*@ $number_to_show = 8
*@ Change the 8 variable to how ever many announcements you want displayed.
*
*/
function phpbb_fetch_home_announcements($forum_id = 2, $number_to_show = 8)
{
    global $db, $user, $template;
    global $phpbb_root_path, $phpEx;
        
    //$forum_id = 2; 
    //$number_to_show = 8;
        
    $sql = 'SELECT 
        t.forum_id,
        t.topic_id,
        t.topic_last_post_id,
        t.topic_time,
        t.topic_title,
        t.topic_poster,
        u.username,
        u.user_id,
        u.user_type,
        u.user_colour
    FROM 
        ' . TOPICS_TABLE . ' AS t,
        ' . USERS_TABLE . ' AS u
    WHERE
        t.forum_id = ' . $forum_id . ' AND
        t.topic_poster = u.user_id
    ORDER BY
        t.topic_time DESC';
    $result = $db->sql_query_limit($sql, $number_to_show);

    while ($row = $db->sql_fetchrow($result))
    {
        $template->assign_block_vars('announcement_row', array(
            'TITLE'                    => $row['topic_title'],
            'U_ANNOUNCEMENT'     => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
                'TIME'                         => $user->format_date($row['topic_time']),
            'POSTER_FULL'            => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
        ));
    }
    $db->sql_freeresult($result);
}
?>

That code holds our function to fetch the recent announcements. You'll want to use that file to hold all of your website functions.

Create a new file in your site root path called index.php, in that file put this code.
Code:
<?php
// phpbb stuff
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
$site_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/website_functions.' . $phpEx);

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

// execute function to fetch announcemetns :)
phpbb_fetch_home_announcements();

// Page Title (We are hardcoding text here :P)
page_header('Home');

// template file...
$template->set_filenames(array(
    'body' => 'home_body.html')
);

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();

?>

Now create a new template file in /prosilver/template/ called home_body.html, this will hold all of your HTML.
Code:
<!-- INCLUDE overall_header.html -->

<div id="site_content" style="width:70%;float:left;">
<h2>Welcome to My phpBB3 Forum!</h2>

<p>Text and whatnot can go here. :)</p>   

</div>            

<div id="sidebar" style="width:28%;float:right;">
   
<!-- IF not S_USER_LOGGED_IN -->
   <div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
   <h3>Forum Login</h3>
   <form method="post" action="{ROOT_PATH}ucp.php?mode=login">
   <fieldset>
      <dl>
         <dt><label for="username">Username:</label></dt>
         <dd><input type="text" class="inputbox autowidth" name="username" id="username" value="" size="15" /></dd>
      </dl>
      <dl>
         <dt><label for="password">Password:</label></dt>
         <dd><input type="password" class="inputbox autowidth" name="password" id="password" value="" size="15" /></dd>
      </dl>
      <input class="button1" name="login" type="submit" value="Login" accesskey="s" />
   </fieldset>
   </form>
   <span class="corners-bottom"><span></span></span></div>
   </div>
<!-- ENDIF -->

   <div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
   <h3>Recent Announcements</h3>

   <!-- BEGIN announcement_row -->
   <div style="margin-bottom: 4px;">
   <strong><a href="{announcement_row.U_ANNOUNCEMENT}">{announcement_row.TITLE}</a></strong><br />
   Posted by {announcement_row.POSTER_FULL} on {announcement_row.TIME}
   </div>
   <!-- END announcement_row -->
   
   <span class="corners-bottom"><span></span></span></div>
   </div>

</div>

<br style="clear: both;" />

<!-- INCLUDE overall_footer.html -->

You should now have a functioning file in mysite.com/index.php, if you don’t you did something wrong.

This is only intended to be an ‘example’ of how you can do this, the code included is quite “basic”, you will need to code up some stuff on your own to further the functionality of this. A great link on phpBB3 coding, functions and similar - http://www.phpbb.com/mods/documentation/

Extras:

Want the page to only be accesable to logged in users? Place this code at the top of the page after the $user->setup(); line:
Code:
// is the user logged in?
if (!$user->data['is_registered'])
{
    login_box('', 'LOGIN');
}

That will immediately prompt the user to login to view the page, once logged in they will be redirected back to that page and able to view it's content.
 
Code:
    <?php
    // phpbb stuff
    define('IN_PHPBB', true);
    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/';
    $site_path = './';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/website_functions.' . $phpEx);

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

    // execute function to fetch announcemetns :)
    phpbb_fetch_home_announcements();

    // Page Title (We are hardcoding text here :P)
    page_header('Home');

    // template file...
    $template->set_filenames(array(
        'body' => 'home_body.html')
    );

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

    page_footer();

    ?>


Do I change the './forum/';"
To where ever my forums are located? In my case they are located at /forums/
 
Back
Top Bottom