Topic: punbb miniportal
This is for PunBB 1.1.5
ok, well i made a portal type thing for my site and a few people have seen it and requested i release it as a mod, i'm not going to make a proper release as this will probably be different for everyone but more a set of instructions to build your site around punbb
first of all, creating a new index.php with news selected from one of the forums:
1) Rename your current forums index.php to forum.php
2) Create a new index.php based on the one below
index.php:
<?php
$pun_root = './';
define('PUN_QUIET_VISIT', 1);
require $pun_root.'include/common.php';
require $pun_root.'include/parser.php';
function pun_news($fid='', $show=15, $truncate=1)
{
global $lang_common, $db, $pun_config;
$max_subject_length = 30;
$show_max_topics = 50;
$fid = intval($fid);
$order_by = 't.posted';
$forum_sql = '';
// Was a forum ID supplied?
if ( $fid ) $forum_sql = 'f.id='.$fid.' AND ';
$show = intval($show);
if ($show < 1 || $show > $show_max_topics)
$show = 15;
$saveddate="";
// Fetch $show topics
$result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, f.id AS fid, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON t.forum_id=f.id WHERE t.moved_to IS NULL AND '.$forum_sql.'f.admmod_only=0 ORDER BY '.$order_by.' DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
$show_count = 0;
if ( !$db->num_rows($result) ) return $output;
while ( ($show_count < $show) && ($cur_topic = $db->fetch_assoc($result)) ) {
$temp = '';
if ($pun_config['o_censoring'] == '1')
$cur_topic['subject'] = censor_words($cur_topic['subject']);
if (pun_strlen($cur_topic['subject']) > $max_subject_length)
$subject_truncated = trim(substr($cur_topic['subject'], 0, ($max_subject_length-5))).' ...';
else
$subject_truncated = $cur_topic['subject'];
$newsheading = '<a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.pun_htmlspecialchars($subject_truncated).'</a> - <em>Posted by '.$cur_topic['poster'].' at '.date('h:i A', $cur_topic['posted']).'</em><br>';
// Group posts by date
$thisdate = date('l, d F Y', $cur_topic['posted']);
if ($thisdate != $saveddate)
{
if ($saveddate)
{
$temp .= "</table><br>";
}
$temp .= '<table class="punmain" cellspacing="1" cellpadding="4"><tr class="punhead"><td class="punhead">'.$thisdate.'</td></tr>';
$saveddate = $thisdate;
}
$temp .= '<tr><td class="puncon2">'.$newsheading.'<br>';
$id = $cur_topic['id'];
$msg = $db->query('SELECT id, poster, poster_id, poster_ip, poster_email, message, smilies, posted, edited, edited_by FROM '.$db->prefix.'posts WHERE topic_id='.$id.' LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
if ( !$db->num_rows($msg) ) continue;
$cur_post = $db->fetch_assoc($msg);
// Display first paragraph only (comment out next four lines to turn off)
if ($truncate == 1)
{
$paragraph = preg_split("/\s*\n+/", $cur_post['message']);
if ($paragraph[1]) {
$cur_post['message'] = $paragraph[0] . "...";
}
}
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['smilies']);
$temp .= $cur_post['message'].'<br>';
$temp .= "</td></tr>";
$output .= $temp;
++$show_count;
} // end of while
$output .= "</table><br>";
return $output;
}
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Home Page';
require $pun_root.'header.php';
?>
<table cellspacing="1" cellpadding="4" class="punspacer"><tr><td> </td></tr></table>
<table class="punmain" cellspacing="1" cellpadding="4">
<tr class="punhead">
<td class="punhead"><?php echo $lang_common['Announcement'] ?></td>
</tr>
<tr>
<td class="puncon2">
<?php echo $pun_config['o_announcement_message'] ?><br><br>
</td>
</tr>
</table>
<table cellspacing="1" cellpadding="4" class="punspacer"><tr><td> </td></tr></table>
<?php
echo pun_news(1, 5, 1);
require $pun_root.'footer.php';
?>
this is a page with the announcement box at the top (make sure announcment is turned off or you will get 2 boxes) and the last 5 news articles from forum id 1 using pun_news with the syntax
echo pun_news(forumid, number of articles, only show first paragraph either 1 for yes or 0 for show all);
3) we now need to rename the links to the forum to forum.php and add a link to the forum to the menubar at the top
replace index.php with forum.php in viewtopic.php (about line 180) and viewforum.php (about line 100)
replace
$links[] = '<a href="index.php">'.$lang_common['Home'].'</a> | <a href="userlist.php">'.$lang_common['User list'].'</a>';
with
$links[] = '<a href="index.php">'.$lang_common['Home'].'</a> | <a href="forum.php">'.$lang_common['Forum'].'</a> | <a href="userlist.php">'.$lang_common['User list'].'</a>';
in functions.php
if this is all you want from your portal you can stop here, if you want other pages of your own and a navagation bar on the left then keep reading
4) add menubar on the left
replace
<pun_main>
with
<table class="punspacer" width="100%" cellspacing="0" cellpadding="0">
<tr class="punspacer">
<td width="100" valign="top" class="punhead">
<table cellspacing="1" cellpadding="4" class="punspacer"><tr><td> </td></tr></table>
<table class="punmain" cellspacing="1" cellpadding="4">
<tr class="punhead">
<td class="punhead">Menu</td>
</tr>
<tr>
<td class="puncon2">
<a href="index.php">Home</a></
</td>
</tr>
<tr>
<td class="puncon3" colspan="6"><a href="forum.php">Forums</a></td>
</tr>
<tr>
<td class="puncon2">
<pun_menulinks>
</td>
</tr>
<tr>
<td class="puncon3" colspan="6"><a href="#">Section 2</a></td>
</tr>
<tr>
<td class="puncon2">
<a href="#">link 1</a>
<br><a href="#">link 2</a>
<br><a href="#">link 3</a>
<br><a href="#">link 4</a>
</td>
</tr>
</table>
<br>
<table class="punmain" cellspacing="1" cellpadding="4">
<tr class="punhead">
<td class="punhead">Whos Online</td>
</tr>
<tr>
<td class="puncon2">
<pun_menustats>
</td>
</tr>
</table>
<table cellspacing="1" cellpadding="4" class="punspacer"><tr><td> </td></tr></table>
</td>
<td width="8" valign="top" class="punhead"></td>
<td class="punspacer" valign="top"><pun_main></td>
</tr>
</table>
in main.tpl (include/templates)
you will need to edit the links on this but i would do that at the end of setting this up
open header.php
find
// START SUBST - <pun_navlinks>
$tpl_main = str_replace('<pun_navlinks>', generate_navlinks(), $tpl_main);
// END SUBST - <pun_navlinks>
after add
// START SUBST - <pun_menulinks>
$tpl_main = str_replace('<pun_menulinks>', generate_menulinks(), $tpl_main);
// END SUBST - <pun_navlinks>
// START SUBST - <pun_menustats>
$tpl_main = str_replace('<pun_menustats>', generate_menustats(), $tpl_main);
// END SUBST - <pun_menustats>
open functions.php
find
//
// Update posts, topics, last_post, last_post_id and last_poster for a forum (redirect topics are not included)
// If $transaction == PUN_TRANS_END, this function will end the current transaction
//
before add
//
// Generate the "forum menu" that appears at the left of every page
//
function generate_menulinks()
{
global $pun_config, $lang_common, $cookie, $cur_user;
// Home and Userlist should always be displayed
$links[] = '<a href="userlist.php">'.$lang_common['User list'].'</a><br>';
if ($pun_config['o_rules'] == '1')
$links[] = '<a href="misc.php?action=rules">'.$lang_common['Rules'].'</a><br>';
if ($cookie['is_guest'])
{
if ($pun_config['o_search'] == '1' && $pun_config['p_guests_search'] == '1')
$links[] = '<a href="search.php">'.$lang_common['Search'].'</a><br>';
$info = $lang_common['Not logged in'];
}
else
{
if ($cur_user['status'] < PUN_MOD)
{
if ($pun_config['o_search'] == '1')
$links[] = '<a href="search.php">'.$lang_common['Search'].'</a><br>';
$links[] = '<a href="profile.php?id='.$cur_user['id'].'">'.$lang_common['Profile'].'</a><br>';
}
else
{
$links[] = '<a href="search.php">'.$lang_common['Search'].'</a><br>';
$links[] = '<a href="profile.php?id='.$cur_user['id'].'">'.$lang_common['Profile'].'</a><br>';
$links[] = '<a href="admin_index.php">'.$lang_common['Admin'].'</a><br>';
}
}
return implode('', $links);
}
//
// Generate the user stats for the left of the page
//
function generate_menustats()
{
global $pun_config, $lang_common, $cookie, $cur_user, $db;
// Stats always displayed
$links[] = 'Hello ';
$links[] = $cur_user['username'].'!';
if ($cookie['is_guest'])
{
$links[] = '<form method="post" action="login.php?action=in" id="login" onsubmit="return process_form(this)"><input type="hidden" name="form_sent" value="1"><input type="hidden" name="redirect_url" value="http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"].'"><br>Username<br><input type="text" name="req_username" size="10" maxlength="25"><br>Password<br><input type="password" name="req_password" size="10" maxlength="16"><br><input type="submit" name="login" value="Login"><br><a href="register.php">Register</a><br><a href="login.php?action=forget">Forgotten your password?</a></form>';
}
else
{
// Collect some statistics from the database
$result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
$stats['total_users'] = $db->result($result, 0);
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
$stats['last_user'] = $db->fetch_assoc($result);
$result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
$links[] = "<br>We have ";
$links[] = $stats['total_users'];
$links[] = " users, and ";
$links[] = $stats['total_posts'];
$links[] = " posts in ";
$links[] = $stats['total_topics'];
$links[] = " topics.<br>";
if ($pun_config['o_users_online'] == '1')
{
// Fetch users online info and generate strings for output
$num_guests = 0;
$result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online ORDER BY ident') or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
while ($cur_user_online = $db->fetch_assoc($result))
{
if ($cur_user_online['user_id'] > 0)
$users[] = '<a href="profile.php?id='.$cur_user_online['user_id'].'">'.pun_htmlspecialchars($cur_user_online['ident']).'</a>';
else
++$num_guests;
}
$num_users = count($users);
$links[] = $num_users.' Users and '.$num_guests.' Guests Currently Online<br>';
}
$links[] = '<a href="login.php?action=out">'.$lang_common['Logout'].'</a><br>';
}
return implode('', $links);
}
upload all your files and admire your handywork, edit main.tpl and index.php to suit your site
for any other pages you want to make
<?php
$pun_root = './';
define('PUN_QUIET_VISIT', 1);
require $pun_root.'include/common.php';
require $pun_root.'header.php';
?>
<table cellspacing="1" cellpadding="4" class="punspacer"><tr><td> </td></tr></table>
<table class="punmain" cellspacing="1" cellpadding="4">
<tr class="punhead">
<td class="punhead">Page Title</td>
</tr>
<tr>
<td class="puncon2">
Page Content<br><br>
</td>
</tr>
</table>
<table cellspacing="1" cellpadding="4" class="punspacer"><tr><td> </td></tr></table>
<?php
require $pun_root.'footer.php';
?>
any questions? just ask i'll try to answer, if i have made any mistakes or missed anything please tell me!