1 (edited by Connorhd 2005-01-05 16:00)

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 wink

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!

2

Re: punbb miniportal

where demo ?

Re: punbb miniportal

theres a reply only mod somewhere you can use that, personally i don't mind people posting news and if it shouldn't be in news i just delete or move it

Re: punbb miniportal

Rewozz wrote:

anyone can post new topics though hmm

just wait for 1.2, it has the option to only let admins post topics

Indocron
$theQuestion = (2*b) || !(2*b);

5 (edited by Patrik 2004-12-05 13:38)

Re: punbb miniportal

Hi. I think this mod was great. I do saw that there was a javascript error when trying to login, but I fixed it with this javascript in a .js file

function no_error()
{ return true; }
window.onerror=no_error;

Re: punbb miniportal

glad it helped and thx for the javascript thing i didnt notice it

7

Re: punbb miniportal

Connorhd wrote:

for any other pages you want to make

you've forgotten
require $pun_root.'header.php';

Re: punbb miniportal

fixed thx wink

Re: punbb miniportal

That's a good mod but is there a version for PunBB 1.2 ?

Will it be made ?

[img]http://www.famfamfam.com/lab/icons/silk/icons/error.png[/img] /me speaks French and bad English [img]http://www.famfamfam.com/lab/icons/silk/icons/error.png[/img]

Re: punbb miniportal

Gary13579 is making a blog/portal addon using the template i made for my CMS which looks very cool and i think hes going to release that with admin plugins and stuff, if thats not what everyone wants i'll make this for 1.2

11

Re: punbb miniportal

Yop
Could you tell me how to change the annonce and add news ones ?

12 (edited by mulder 2004-12-29 05:35)

Re: punbb miniportal

Thanks for the good work Connorhd!

I've tried it on PunBB 1.2 (not the latest one though)
http://lae.sytes.net:8080/bbn

Everything seems to ok except some lil problems. Of course, the code is changed in 1.2, so it needs some more work..

Yes please make it for 1.2 if possible.

13 (edited by HackVoid 2005-01-05 02:26)

Re: punbb miniportal

Not sure what I did wrong... Acutlly. preety sure I did everything right. Well heres the error I got.

The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.

Re: punbb miniportal

this is NOT for 1.2 its for 1.1.5 one similar will be done for 1.2

Re: punbb miniportal

aye, thats what i thought it was...

Re: punbb miniportal

Does anyone have a n active demo of this miniportal?

Re: punbb miniportal

Click on the sig of Connorhd.

[img]http://www.famfamfam.com/lab/icons/silk/icons/error.png[/img] /me speaks French and bad English [img]http://www.famfamfam.com/lab/icons/silk/icons/error.png[/img]

Re: punbb miniportal

thank you smile

Re: punbb miniportal

my sig is a heavily modded version of punbb e.g. everything except the database and template system have been taken out, so its not excatly like the miniportal, and yes when i get mypunbb.com finished for 1.2 i'll make a 1.2 miniportal wink

Re: punbb miniportal

i think it would be interesting making a portal out of punBB.

i would make an admin section for the front page layout and an admin section for content...
the admin section would be laid out in differnt area's, lets say the theme is sectioned.... ie logo, TOP, topmenu, banner, left, static_center (content that doest change, mabe like a description above the news), centernews, bottombanner, bottom, eula/copywrite, Right....

then have a option to add a component of types, like a menu component, or poll component, or news component and add it to the desired location area, including its order, ie main menu above polls on the left side, (hrm, this goes below im lazy tongue - with main menu having a section for desired links added to it).


then each component would be changed or edited or added in the content section... ie polls, news, menu's etc, click it, and click add or edit on the desiired item to edit it. each post would be an item.... news items would obviously make its own section (visiable or not) in the main forums so users can add comments.

however i dont know PHP programming tongue i used to code stuff like this in ASP but i since stoped doing so cause it annoyed me to work on windows machines sad

Re: punbb miniportal

thats sort of the kind of thing i was going to for the punbb based cms i'm going to try to make, thats why this is a miniportal not a portal since its just a hack really to add some extra pages, its not a proper system with admin etc

Re: punbb miniportal

well i hope you do make the CMS, its a great idea, we need a fast cms that can post news and articles, and additianl things... tho support for additional addons and modualar system might be a bit harder to incorperate. keep it simple, and secure.

23 (edited by HackVoid 2005-01-25 20:21)

Re: punbb miniportal

i help devlop WebsiteBaker, a cms that does all those things, all the people that use wb are offered punBB forums for their site because they are the best in my opinion.

24 (edited by erissiva 2005-02-24 05:19)

Re: punbb miniportal

*sits on topic and drools over ConnorHD's portal page*

Ooo...It's working with 1.2
Pritty. tongue

Can't wait 'til it becomes public.

Re: punbb miniportal

yeh i am working on it, i'm just a bit behind since i have had about 10 other punbb things to do wink