1 (edited by Connorhd 2005-04-09 14:26)

Topic: PunBB Miniportal v1.2.x

Ok this is part one, which is adding a portal page with (live!) news from the forum of your choice, part 2 will be adding a sidebar and i'll post that later today i hope big_smile (btw sorry for the delays with this i guess i'm just plain lazy)

For a full guide with a nicer layout by hcgtv Click Here


Step 1:

Rename index.php to forum.php

Step 2:

Create a new index.php based on the one below

<?php

define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';

$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';

function pun_news($fid='', $show=15, $truncate=1)
{
    global $lang_common, $db, $pun_config, $db_prefix;
    $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 f.id='.$fid.' AND t.moved_to IS NULL 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 .= "</div></div>";
            }
            $temp .= '<div class="block"><h2><span>'.$thisdate.'</span></h2><div class="box"><div class="inbox"><p>';
            $saveddate = $thisdate;
        }
        else {
            $temp .= '<div class="inbox"><p>';
        }
        $temp .= $newsheading.'</p><p>';
        $id = $cur_topic['id'];
        $msg = $db->query('SELECT id, poster, poster_id, poster_ip, poster_email, message, 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 (isset($paragraph[1])) {
                $cur_post['message'] = $paragraph[0] . "...";
            }
        }
        $cur_post['message'] = parse_message($cur_post['message'], 0);
        $temp .= $cur_post['message'];
        $temp .= "</p></div>";
        if (isset($output)) {
            $output .= $temp;
        }
        else {
            $output = $temp;
        }
        ++$show_count;
    } // end of while
    $output .= "</div></div>";
    return $output;
}
?>
        <div class="block">
            <h2><span>Welcome</span></h2>
            <div class="box">
                <div class="inbox">
                    <p>
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent augue. Nulla facilisi. Fusce bibendum accumsan erat. Quisque sollicitudin mattis neque. Sed dapibus. Integer a lectus eu sem consequat pellentesque. Morbi rhoncus nulla. Duis adipiscing interdum velit. Fusce ante. Ut vitae enim sit amet magna sodales hendrerit. In sed tortor at sapien convallis eleifend. Proin mauris. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut metus. Cras ac arcu et arcu porttitor blandit. Nam vitae lectus eget mauris sollicitudin placerat. Suspendisse vestibulum. Donec varius libero. Duis velit tellus, euismod vitae, consequat sed, consectetuer ut, purus.
                    </p>
                    <p>
                    Praesent viverra venenatis magna. Etiam in dolor. Ut in justo ac nibh malesuada cursus. Duis urna arcu, aliquam vitae, consequat nec, tincidunt non, mi. Nunc lobortis. Nunc pharetra. Sed porttitor. Maecenas turpis tortor, blandit nec, dignissim in, porttitor eu, odio. In hac habitasse platea dictumst. Suspendisse augue odio, ornare a, elementum ac, tincidunt varius, orci. Nulla libero ante, hendrerit ac, consectetuer eu, sollicitudin et, eros. Duis sapien. Suspendisse ornare enim sit amet dui. Donec ullamcorper diam.
                    </p>
                </div>
            </div>
        </div>
<?php
echo pun_news(1, 5, 0);

require PUN_ROOT.'footer.php';

put what you want in the welcome block,
pun_news(1, 5, 0); is the news generator the syntax is pun_news(forum id, number of news to display, truncate news);

Step 3:

Add forums.php to the menu:

open functions.php

find (line 235):

$links[] = '<li id="navindex"><a href="index.php">'.$lang_common['Index'].'</a>';

after add

$links[] = '<li id="navforum"><a href="forum.php">'.$lang_common['Forum'].'</a>';

Step 4:

Replace links to the forum index in viewtopic and viewforum

simply open up both viewforum.php and viewtopic.php and replace index.php with forum.php
you should have to replace it twice in both

wow, your done big_smile ( i hope )

part 2 (adding a sidebar coming soon)

Re: PunBB Miniportal v1.2.x

Part 2:

how to add a sidebar (you do not need part 1 to use part 2)

Step 1:

replace main.tpl with

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html dir="<pun_content_direction>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<pun_char_encoding>" />
<pun_head>
<style type="text/css">
    #left {
        width: 120px;
        float: left;
    }
    #main {
        margin-left: 130px;
    }
    #container {
        width: 100%;
        float: right;
        margin-left: -120px;
    }
</style>
</head>
<body>

<div id="punwrap">
<div id="pun<pun_page>" class="pun">

<div id="brdheader" class="block">
    <div class="box">
        <div id="brdtitle" class="inbox">
            <pun_title>
            <pun_desc>
        </div>
        <pun_navlinks>
        <pun_status>
    </div>
</div>

<div id="container">
    <div id="main">
    
        <pun_announcement>
    
        <pun_main>
        
    </div>    
</div>

<div id="left">    
    <div class="block">
        <h2><span>Menu</span></h2>
        <div class="box">
        <pun_sidelinks>            
        </div>
    </div>
    <div class="block">
        <h2 class="block2"><span>More Links</span></h2>
        <div class="box">
            <div class="inbox">
                <ul>
                    <li><a href="index.php">Link 1</a></li>
                    <li><a href="index.php">Link 2</a></li>
                    <li><a href="index.php">Link 3</a></li>
                    <li><a href="index.php">Link 4</a></li>
                </ul>        
            </div>
        </div>
    </div>
</div>

<div class="clearer"></div>

<pun_footer>

</div>
</div>

</body>
</html>

Step 2:

open header.php

find

// START SUBST - <pun_navlinks>
$tpl_main = str_replace('<pun_navlinks>','<div id="brdmenu" class="inbox">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_navlinks>

after add

// START SUBST - <pun_sidelinks>
$tpl_main = str_replace('<pun_sidelinks>','<div class="inbox">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_sidelinks>

that will add a sidebar on the left with the navlinks from the top plus some extra links which you can change/remove

if you want to add another box like the old miniportal mod with a login box and a whos online bit then hang tight i'm gonna do that next wink

3

Re: PunBB Miniportal v1.2.x

Nice, placed this up on my wiki, hope it's cool.

http://nupusi.net/punbb:tutorials:miniportal

Re: PunBB Miniportal v1.2.x

wow neat, i hope it all works lol

5

Re: PunBB Miniportal v1.2.x

When I was adding part 1, you were adding part 2 smile

Will add part 2 now.

Re: PunBB Miniportal v1.2.x

yeh i expected it to take a bit longer but i found that way to do it which only requires one edit of the php (infact i think i can do it without any edits of the php but then you have messy css)

7

Re: PunBB Miniportal v1.2.x

Ok part 2 is in: http://nupusi.net/punbb:tutorials:minip … _a_sidebar

I've been meaning to get my wiki going, and this post is an excellent example of why wink

Thanks.

8 (edited by Connorhd 2005-04-09 16:10)

Re: PunBB Miniportal v1.2.x

yeh its a really nice way of doing integration stuff,

Sorry this didn't work in IE, there are some more instructions at the end and an updated function
anyway, an addon to part 2:

this will add a whos online block to the sidebar

open header.php

find the code you added before

// START SUBST - <pun_sidelinks>
$tpl_main = str_replace('<pun_sidelinks>','<div class="inbox">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_sidelinks>

after add

// START SUBST - <pun_online>
$tpl_main = str_replace('<pun_online>','<div class="inbox">'."\n\t\t\t". generate_whosonline()."\n\t\t".'</div>', $tpl_main);
// END SUBST - <pun_online>

add this to functions.php (the end is fine)

//
// Generate the whos online block
//
function generate_whosonline()
{
    global $pun_config, $lang_common, $pun_user, $db;
    
    if ($pun_user['is_guest'])
    {
        require PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
        return 'Welcome Guest!<br />
            Please login.<br />
            <form id="login" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
                <input type="hidden" name="form_sent" value="1" />
                <input type="hidden" name="redirect_url" value="index.php" />
                <label><strong>Username</strong><br /><input type="text" name="req_username" size="13" maxlength="25" tabindex="1" /><br /></label>
                <label><strong>Password</strong><br /><input type="password" name="req_password" size="13" maxlength="16" tabindex="2" /><br /></label>
                <p><a href="register.php" tabindex="4">'.$lang_login['Not registered'].'</a><br />
                <a href="login.php?action=forget" tabindex="5">'.$lang_login['Forgotten pass'].'</a></p>
                <p><input type="submit" name="login" value="Login" tabindex="3" /></p>
            </form>';
    }
    else
    {
        require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
        $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);
        
        $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);
        
        if ($pun_config['o_users_online'] == '1')
        {
            // Fetch users online info and generate strings for output
            $num_guests = 0;
            $users = array();
            $online = array();
            $result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
        
            while ($pun_user_online = $db->fetch_assoc($result))
            {
                if ($pun_user_online['user_id'] > 1)
                    $users[] = "\n\t\t\t\t".'<a href="profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a><br />';
                else
                    ++$num_guests;
            }
        
            $num_users = count($users);
            $online[] = "\t\t\t\t".$lang_index['Users online'].': <strong>'.$num_users.'</strong><br />'."\n\t\t\t\t".$lang_index['Guests online'].': <strong>'.$num_guests.'</strong>'."\n\t\t\t"."\n";
        
        
            if ($num_users > 0 && $num_users < 10)
                $online[] = "\t\t\t"."\n\t\t\t\t".'<strong>'.$lang_index['Online'].': </strong>'."\t\t\t\t".implode($users)."\n";
            else
                $online[] = "\t\t\t".'<div class="clearer"></div>'."\n";
        
        }
        
        return 'Welcome <strong>'.$pun_user['username'].'</strong><br /><br />
            '.implode($online,'').'<br />
            Users: <strong>'. $stats['total_users'].'</strong><br />
            Topics: <strong>'.$stats['total_topics'].'</strong><br />
            Posts: <strong>'.$stats['total_posts'].'</strong><br />';
    }
}

then within

<div id="left">    
.....
</div>

in main.tpl

add

    <div class="block">
        <h2 class="block2"><span>Whos Online?</span></h2>
        <div class="box">
        <pun_online>
        </div>
    </div>

you will also need to change the width of the bar in the cssat the top of main.tpl

<style type="text/css">
    #left {
        width: 140px;
        float: left;
    }
    #main {
        margin-left: 150px;
    }
    #container {
        width: 100%;
        float: right;
        margin-left: -140px;
    }
</style>

this will add something along the lines of

Welcome Connorhd

Registered users online: 1
Guests online: 0
Online:  Connorhd

Users: 1
Topics: 3
Posts: 3

only problem is Users: Topics: and Posts: aren't translated to different languages and it won't show more than 10 users online to stop it being too big


on another note you can see the side bar and news generator on http://forum.mypunbb.com/ and http://www.mypunbb.com/

9

Re: PunBB Miniportal v1.2.x

Connorhd wrote:

yeh its a really nice way of doing integration stuff

Yeah, you need a way to keep all your documents in one place plus all the tidbits of information you find along the way.

I updated the tutorial with the who's online bloc: http://nupusi.net/punbb:tutorials:minip … hos_online

I'm going to start looking through the forum and see what else can be added to the tutorials section.

Ctrl-C, Ctrl-V is your friend wink

Re: PunBB Miniportal v1.2.x

ok cool i've added a link to your site to the top big_smile

btw heres a little one that might be useful http://punbb.org/forums/viewtopic.php?id=6379

11

Re: PunBB Miniportal v1.2.x

Connorhd wrote:

ok cool i've added a link to your site to the top big_smile

Great, thanks.

Connorhd wrote:

btw heres a little one that might be useful http://punbb.org/forums/viewtopic.php?id=6379

Decided to add it the to faq:
http://nupusi.net/punbb:faq#3.8_-_how_c … ew_windows

Disclaimer: My wiki is not the official docs, it's for my own personal use and for those that may find it useful. But we can use the wiki as a basis for generating the official docs at time of release.

Re: PunBB Miniportal v1.2.x

this totaly pwnz my portal

Thanks connornd this saves me a lot of work smile

Re: PunBB Miniportal v1.2.x

i've updated the whos online block to display properly in IE i forgot to test it hmm

14 (edited by Ludo 2005-04-09 16:27)

Re: PunBB Miniportal v1.2.x

I'll try it as soon as I can.
wouldn't it have been possible to do an index page totally independant of punbb, without modifying punbb code. I mean just an index using what punbb unmodified permit.
Well, I'll try and then I'll write my questions if needed.
somebody has tried? example?

Ludo,

Re: PunBB Miniportal v1.2.x

Can make a log in block to the side navigation?

Re: PunBB Miniportal v1.2.x

Ludo wrote:

I'll try it as soon as I can.
wouldn't it have been possible to do an index page totally independant of punbb, without modifying punbb code. I mean just an index using what punbb unmodified permit.
Well, I'll try and then I'll write my questions if needed.
somebody has tried? example?

Ludo,

well no since you would at least need to rename index.php and part one only needs a couple of edits

shinko_metsuo wrote:

Can make a log in block to the side navigation?

yeh the whos online block has a login form for guests smile

17

Re: PunBB Miniportal v1.2.x

does it look like this http://66.98.138.31/~connorhd/pundev/index.htm ?

Ludo,

Re: PunBB Miniportal v1.2.x

Connorhd wrote:
Ludo wrote:

I'll try it as soon as I can.
wouldn't it have been possible to do an index page totally independant of punbb, without modifying punbb code. I mean just an index using what punbb unmodified permit.
Well, I'll try and then I'll write my questions if needed.
somebody has tried? example?

Ludo,

well no since you would at least need to rename index.php and part one only needs a couple of edits

shinko_metsuo wrote:

Can make a log in block to the side navigation?

yeh the whos online block has a login form for guests smile

ok thanks ^_^

Re: PunBB Miniportal v1.2.x

Ludo wrote:

does it look like this http://66.98.138.31/~connorhd/pundev/index.htm ?

Ludo,

no its a miniportal not a cms

Re: PunBB Miniportal v1.2.x

latest forum post would be nice to add

I would do it with extern.php but I have ads and they follow when I do the include sad

Re: PunBB Miniportal v1.2.x

unfortunatly you can't just use pun_include

to add a latest posts block you could do this as long as you don't use pun_include already:

open footer.php

replace

// START SUBST - <pun_include "*">
while (preg_match('/<pun_include "(.*?)">/', $tpl_main, $cur_include))
{
    ob_start();
    include PUN_ROOT.$cur_include[1];
    $tpl_temp = ob_get_contents();
    $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
    ob_end_clean();
}
// END SUBST - <pun_include "*">

with

// START SUBST - <pun_include "*">
while (preg_match('/<pun_include "(.*?)">/', $tpl_main, $cur_include))
{
    ob_start();
    include $cur_include[1];
    $tpl_temp = ob_get_contents();
    $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
    ob_end_clean();
}
// END SUBST - <pun_include "*">

you can then use

    <div class="block">
        <h2 class="block2"><span>Latest Posts</span></h2>
        <div class="box">
            <div class="inbox">
                <ul>
                    <pun_include "http://yoursite.com/forum/extern.php?action=active">
                </ul>        
            </div>
        </div>
    </div>

in main.tpl remember to change the extern.php url

Re: PunBB Miniportal v1.2.x

didn't work sad I got the same problem

23

Re: PunBB Miniportal v1.2.x

I added the following to profile.php (more design issue).

// Tell header.php to use the admin template
define('PUN_ADMIN_CONSOLE', 1);


Thanks Connorhd for real nice mod. Its seems to work out fine.

Re: PunBB Miniportal v1.2.x

ahh yeh otherwise you get 2 left bars... bit messy wink

Re: PunBB Miniportal v1.2.x

someone got a demo of this up and running?

~James
FluxBB - Less is more