Forum stats/Newest topic intergrated into website?

This forum is now closed as part of retiring phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
colegleason
Registered User
Posts: 8
Joined: Sun Feb 04, 2007 2:29 am

Forum stats/Newest topic intergrated into website?

Post by colegleason »

First off I would like to say that if this has already been made, please direct me there. I thought I saw it before somewhere.

What I would like to do is have some way of taking the latest topic posted or forum stats and integrating it into my personal web page. Just a little box that would say something like:
Forum Stats:

Online:20
Members:18
Guests:2
Newest Member:blah
Topics:4736
Posts:565645

or

Newest Topic in Forum:
Testing phpbb2
posted by: Cole

Please help me if possible.
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

colegleason
Registered User
Posts: 8
Joined: Sun Feb 04, 2007 2:29 am

Post by colegleason »

This is great!
Could someone help me format it though?
I would like to put it in a format like so:

Latest Forum Topics:
Topic 1
by Cole
Topic 2
by Cole
Topic 3
by Cole
Topic 4
by Cole
Topic 5
by Cole

I'm trying to get all of the topic names to act as links. Here's the code that phpbb fetch all gave me. I'm not really a programmer, so any help would be appreciated.

Code: Select all

<?php
$phpbb_root_path = '../../../';
define ('IN_PHPBB', true);
include_once ($phpbb_root_path . 'extension.inc');
include_once ($phpbb_root_path . 'common.' . $phpEx);
include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$news = phpbb_fetch_posts();
phpbb_disconnect();
?>
<ul>
<?php for ($i = 0; $i < count($news); $i++) { ?>
<li><?php echo $news[$i]['topic_title']; ?></li>
<?php } ?>
</ul>
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

I think you have picked the wrong code. Do you want to display the recent topics or the news (code quoted in your post)?

I suggest getting the sample portal in the examples directory to work first. If you have that running, it should be easy to copy the code over to your desired page.

This is the code for the recent topics:

Code: Select all

<!-- RECENT -->
<?php if (isset($recent)) { ?>
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="forumline">
  <tr>
    <td class="catHead" height="28"><span class="cattitle"><?php echo $lang['Topics']; ?></span></td>
  </tr>
  <tr>
    <td class="row1" align="left" width="100%">
      <span class="gensmall">
<?php for ($i = 0; $i < count($recent); $i++) { ?>
<?php echo create_date($board_config['default_dateformat'], $recent[$i]['post_time'], $board_config['board_timezone']); ?> <a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=viewprofile&u=' . $recent[$i]['user_id']); ?>"><?php echo $recent[$i]['username']; ?></a><br /><img src="<?php echo $phpbb_root_path; ?>templates/subSilver/images/icon_latest_reply.gif" border="0" align="absmiddle" /> <a href="<?php echo append_sid($phpbb_root_path . 'viewtopic.php?p=' . $recent[$i]['post_id'] . '#' . $recent[$i]['post_id']); ?>"><b><?php echo $recent[$i]['topic_title']; ?><?php if ($recent[$i]['topic_trimmed']) { echo '...'; } ?></b></a><br />
<?php } ?>
      </span>
    </td>
  </tr>
</table>
<br />
<?php } ?>
<!-- RECENT -->
You would only have to delete the post time and reorder topic title and author.
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

I think you have picked the wrong code. Do you want to display the recent topics or the news (code quoted in your post)?

I suggest getting the sample portal in the examples directory to work first. If you have that running, it should be easy to copy the code over to your desired page.

This is the code for the recent topics:

Code: Select all

<!-- RECENT -->
<?php if (isset($recent)) { ?>
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="forumline">
  <tr>
    <td class="catHead" height="28"><span class="cattitle"><?php echo $lang['Topics']; ?></span></td>
  </tr>
  <tr>
    <td class="row1" align="left" width="100%">
      <span class="gensmall">
<?php for ($i = 0; $i < count($recent); $i++) { ?>
<?php echo create_date($board_config['default_dateformat'], $recent[$i]['post_time'], $board_config['board_timezone']); ?> <a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=viewprofile&u=' . $recent[$i]['user_id']); ?>"><?php echo $recent[$i]['username']; ?></a><br /><img src="<?php echo $phpbb_root_path; ?>templates/subSilver/images/icon_latest_reply.gif" border="0" align="absmiddle" /> <a href="<?php echo append_sid($phpbb_root_path . 'viewtopic.php?p=' . $recent[$i]['post_id'] . '#' . $recent[$i]['post_id']); ?>"><b><?php echo $recent[$i]['topic_title']; ?><?php if ($recent[$i]['topic_trimmed']) { echo '...'; } ?></b></a><br />
<?php } ?>
      </span>
    </td>
  </tr>
</table>
<br />
<?php } ?>
<!-- RECENT -->
You would only have to delete the post time and reorder topic title and author.
colegleason
Registered User
Posts: 8
Joined: Sun Feb 04, 2007 2:29 am

Post by colegleason »

I'm sorry but I have no idea what I am doing.

The topics box in the portal example is fine as it is. I can just use the code for that. I have my homepage as an html file in Dreamweaver. I'm not sure what to do now. Should I just copy the code into the section of Dreamweaver I want? Create a php file?

Thanks for your help!
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

First you need to convert your html file into a php file by changing the extension to .php (instead of .html). Instead of renaming your original homepage file, you might want to copy it and rename the copy. In case anything goes wrong, you can just restore the original file.

Then you need to add this code to your home.php file into the section you want it to be displayed:

Code: Select all

<?php
$phpbb_root_path = './forum/';
 
define ('IN_PHPBB', true);
 
if (!file_exists($phpbb_root_path . 'extension.inc'))
{
 die ('<tt><b>phpBB Fetch All:</b>
  $phpbb_root_path is wrong and does not point to your forum.</tt>');
}
 
//
// phpBB related files
//
 
include_once ($phpbb_root_path . 'extension.inc');
include_once ($phpbb_root_path . 'common.' . $phpEx);
include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 
//
// Fetch All related files - we do need all these because the portal is a
// huge example
//
 
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/stats.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/users.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/polls.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/forums.' . $phpEx);
 
//
// start session management
//
 
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
 
//
// since we are demonstrating span pages we need to set the page offset
//
 
if (isset($HTTP_GET_VARS['start']) or isset($HTTP_POST_VARS['start']))
{
 $CFG['posts_span_pages_offset'] = isset($HTTP_GET_VARS['start'])
 ? $HTTP_GET_VARS['start'] : $HTTP_POST_VARS['start'];
 if (!intval($CFG['posts_span_pages_offset']))
 {
  $CFG['posts_span_pages_offset'] = 0;
 }
 if (!is_numeric($CFG['posts_span_pages_offset']))
 {
  $CFG['posts_span_pages_offset'] = 0;
 }
 if ($CFG['posts_span_pages_offset'] < 0) {
  $CFG['posts_span_pages_offset'] = 0;
 }
}
 
// fetch new posts since last visit
$new_posts = phpbb_fetch_new_posts();
 
// fetch user online, total posts, etc
$stats = phpbb_fetch_stats();
 
// fetch online users
$online = phpbb_fetch_online_users();
 
// fetch five users by total posts
$top_poster = phpbb_fetch_top_poster();
 
// fetch a random user
$random_user = phpbb_fetch_random_user();
 
// fetch forum structure
$forums = phpbb_fetch_forums();
 
// fetch user of a specific group
// This function is disabled because fetching without a specific
// user group can produces a lot of results (all registered users)
// and this may result in an internal server error. If you want to
// use this feature please specify the group id.
#$member = phpbb_fetch_users();
 
// fetch a poll
$poll = phpbb_fetch_poll();
 
// fetch a single topic by topic id
// You will need to specify a certain topic id to use this function.
// The first post of that topic will be displayed in a box to the upper right.
#$topic = phpbb_fetch_topics();
 
// fetch latest postings
$CFG['posts_trim_topic_number'] = 25;
$recent = phpbb_fetch_posts(null, POSTS_FETCH_LAST);
 
// fetch postings
$CFG['posts_trim_topic_number'] = 0;
$CFG['posts_span_pages']        = true;
$news = phpbb_fetch_posts();
 
//
// disconnect from the database
//
 
phpbb_disconnect();
?>
 
<!-- RECENT --> 
<?php if (isset($recent)) { ?> 
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="forumline"> 
  <tr> 
    <td class="catHead" height="28"><span class="cattitle"><?php echo $lang['Topics']; ?></span></td> 
  </tr> 
  <tr> 
    <td class="row1" align="left" width="100%"> 
      <span class="gensmall"> 
<?php for ($i = 0; $i < count($recent); $i++) { ?> 
<?php echo create_date($board_config['default_dateformat'], $recent[$i]['post_time'], $board_config['board_timezone']); ?> <a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=viewprofile&u=' . $recent[$i]['user_id']); ?>"><?php echo $recent[$i]['username']; ?></a><br /><img src="<?php echo $phpbb_root_path; ?>templates/subSilver/images/icon_latest_reply.gif" border="0" align="absmiddle" /> <a href="<?php echo append_sid($phpbb_root_path . 'viewtopic.php?p=' . $recent[$i]['post_id'] . '#' . $recent[$i]['post_id']); ?>"><b><?php echo $recent[$i]['topic_title']; ?><?php if ($recent[$i]['topic_trimmed']) { echo '...'; } ?></b></a><br /> 
<?php } ?> 
      </span> 
    </td> 
  </tr> 
</table> 
<br /> 
<?php } ?> 
<!-- RECENT -->
That code retrieves much more data than you need. If you do not need new posts, stats, online users, etc, you can delete those lines.

I am not a coder either, so you better backup your files.
colegleason
Registered User
Posts: 8
Joined: Sun Feb 04, 2007 2:29 am

Post by colegleason »

OK, I had tried it as a php file before, I'm not sure why it hadn't worked. But anyways, I tried this code and it's almost perfect.
I just get this error message that shows up above my Recent topics:
Warning: Cannot modify header information - headers already sent by (output started at /homepages/6/d195805014/htdocs/index.php:6) in /homepages/6/d195805014/htdocs/forum/includes/sessions.php on line 366

Warning: Cannot modify header information - headers already sent by (output started at /homepages/6/d195805014/htdocs/index.php:6) in /homepages/6/d195805014/htdocs/forum/includes/sessions.php on line 367


And it dosen't really matter, but how do I change the font size in php? Can I just use html tags outside the php script?
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

I think you need to split the code into two sections. At the very beginning of your file:

Code: Select all

<?php
$phpbb_root_path = './forum/';
 
define ('IN_PHPBB', true);
 
if (!file_exists($phpbb_root_path . 'extension.inc'))
{
 die ('<tt><b>phpBB Fetch All:</b>
  $phpbb_root_path is wrong and does not point to your forum.</tt>');
}
 
//
// phpBB related files
//
 
include_once ($phpbb_root_path . 'extension.inc');
include_once ($phpbb_root_path . 'common.' . $phpEx);
include_once ($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 
//
// Fetch All related files - we do need all these because the portal is a
// huge example
//
 
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/common.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/stats.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/users.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/polls.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/posts.' . $phpEx);
include_once ($phpbb_root_path . 'mods/phpbb_fetch_all/forums.' . $phpEx);
 
//
// start session management
//
 
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
 
//
// since we are demonstrating span pages we need to set the page offset
//
 
if (isset($HTTP_GET_VARS['start']) or isset($HTTP_POST_VARS['start']))
{
 $CFG['posts_span_pages_offset'] = isset($HTTP_GET_VARS['start'])
 ? $HTTP_GET_VARS['start'] : $HTTP_POST_VARS['start'];
 if (!intval($CFG['posts_span_pages_offset']))
 {
  $CFG['posts_span_pages_offset'] = 0;
 }
 if (!is_numeric($CFG['posts_span_pages_offset']))
 {
  $CFG['posts_span_pages_offset'] = 0;
 }
 if ($CFG['posts_span_pages_offset'] < 0) {
  $CFG['posts_span_pages_offset'] = 0;
 }
}
 
// fetch new posts since last visit
$new_posts = phpbb_fetch_new_posts();
 
// fetch user online, total posts, etc
$stats = phpbb_fetch_stats();
 
// fetch online users
$online = phpbb_fetch_online_users();
 
// fetch five users by total posts
$top_poster = phpbb_fetch_top_poster();
 
// fetch a random user
$random_user = phpbb_fetch_random_user();
 
// fetch forum structure
$forums = phpbb_fetch_forums();
 
// fetch user of a specific group
// This function is disabled because fetching without a specific
// user group can produces a lot of results (all registered users)
// and this may result in an internal server error. If you want to
// use this feature please specify the group id.
#$member = phpbb_fetch_users();
 
// fetch a poll
$poll = phpbb_fetch_poll();
 
// fetch a single topic by topic id
// You will need to specify a certain topic id to use this function.
// The first post of that topic will be displayed in a box to the upper right.
#$topic = phpbb_fetch_topics();
 
// fetch latest postings
$CFG['posts_trim_topic_number'] = 25;
$recent = phpbb_fetch_posts(null, POSTS_FETCH_LAST);
 
// fetch postings
$CFG['posts_trim_topic_number'] = 0;
$CFG['posts_span_pages']        = true;
$news = phpbb_fetch_posts();
 
//
// disconnect from the database
//
 
phpbb_disconnect();
?>
At the desired section in your html code:

Code: Select all

<!-- RECENT --> 
<?php if (isset($recent)) { ?> 
<table width="100%" cellpadding="3" cellspacing="1" border="0" class="forumline"> 
  <tr> 
    <td class="catHead" height="28"><span class="cattitle"><?php echo $lang['Topics']; ?></span></td> 
  </tr> 
  <tr> 
    <td class="row1" align="left" width="100%"> 
      <span class="gensmall"> 
<?php for ($i = 0; $i < count($recent); $i++) { ?> 
<?php echo create_date($board_config['default_dateformat'], $recent[$i]['post_time'], $board_config['board_timezone']); ?> <a href="<?php echo append_sid($phpbb_root_path . 'profile.php?mode=viewprofile&u=' . $recent[$i]['user_id']); ?>"><?php echo $recent[$i]['username']; ?></a><br /><img src="<?php echo $phpbb_root_path; ?>templates/subSilver/images/icon_latest_reply.gif" border="0" align="absmiddle" /> <a href="<?php echo append_sid($phpbb_root_path . 'viewtopic.php?p=' . $recent[$i]['post_id'] . '#' . $recent[$i]['post_id']); ?>"><b><?php echo $recent[$i]['topic_title']; ?><?php if ($recent[$i]['topic_trimmed']) { echo '...'; } ?></b></a><br /> 
<?php } ?> 
      </span> 
    </td> 
  </tr> 
</table> 
<br /> 
<?php } ?> 
<!-- RECENT -->
You can use normal html tags outside the php section. There are some html tags inside the php code, too.
colegleason
Registered User
Posts: 8
Joined: Sun Feb 04, 2007 2:29 am

Post by colegleason »

I'm still getting the errors, but now they appear at the top of the page, where I posted the first section of the code.
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

Sorry, this seems to be beyond my knowledge. I tried to bugfix following this post:
http://www.phpbbhacks.com/forums/viewtopic.php?t=21777

It still might be that reason, but I don' t know for sure. I have seen that error message before and it was not due to spaces. When I remember correctly it was due to a typo in the code.

Since the example portal seems to work fine, you might want to try this:

Put your html code into the portal file and delete everything of the html code you don' t need.
colegleason
Registered User
Posts: 8
Joined: Sun Feb 04, 2007 2:29 am

Post by colegleason »

OK, I fixed the problem! Before when i had put the first section at the top I had put it under the

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
tag. I found out that the php had to get the headers before any html was sent (or something). anyways thanks a lot for your help jerx!
jerx
Registered User
Posts: 167
Joined: Fri Sep 02, 2005 4:27 am

Post by jerx »

colegleason wrote: OK, I fixed the problem! Before when i had put the first section at the top I had put it under the

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
tag. I found out that the php had to get the headers before any html was sent (or something). anyways thanks a lot for your help jerx!


Bad bad boy, I told you to put it at the "very beginning". ;) I am glad it is fixed now.
Post Reply

Return to “[2.0.x] MOD Requests”