Topic: vanilla style front page (active topics)

im looking to make a vanilla style front page (which has just the active topics aka new posts and ones that get replied) as my index.php while i renamed the old index as forum.php

im using this code found here
http://punbb.org/forums/viewtopic.php?pid=25650#p25650

did some editing since its not compatible with 1.3 but i still have errors

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 40

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 47

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 130

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\include\functions.php on line 478

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\include\functions.php on line 481

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\include\functions.php on line 505

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\include\functions.php on line 506

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\include\functions.php on line 506

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\include\functions.php on line 507

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\footer.php on line 39

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 75

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 83

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 88

Notice: Use of undefined constant PUN_PAGE - assumed 'PUN_PAGE' in C:\xampplite\htdocs\punbbbeta\header.php on line 119

so heres my new index.php with problems
plz help kthxbye

<?php

if (!defined('PUN_ROOT'))
    define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

($hook = get_hook('in_start')) ? eval($hook) : null;

if ($pun_user['g_read_board'] == '0')
    message($lang_common['No view']);

// Load the index.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';

$page_title = htmlspecialchars($pun_config['o_board_title']).' / Active Topics';
require PUN_ROOT.'header.php';

$day_limit = 2; // make this the auto number of days you want to be displayed.

$days = isset($_POST['days']) ? $_POST['days'] : $day_limit;
$posts_since = mktime(date("H"), date("i"), date("s"), date("m"), (date("d")-$days), date("Y"));

$latest = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.last_poster, t.num_replies, 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 f.admmod_only=0
AND t.last_post>'.$posts_since.'
ORDER BY last_post DESC');
?>
<table class="punspacer" cellspacing="1" cellpadding="4">
    <tr>
        <td style="width: 14%;"><b><a href="index.php"><?php echo htmlspecialchars($pun_config['o_board_title']) ?></a> / Active Topics</b></td>
        <td class="punright"><form method="post" action="">Days to show: <input type="text" name="days" value="<?php echo $days; ?>" size="3"> <input type="submit" value="Go"></form></td>
    </tr>
</table>
<table class="punmain" cellspacing="1" cellpadding="4">
    <tr class="punhead">
        <td class="punhead"><?php echo $lang_common['Topic'] ?></td>
        <td class="punhead" style="width: 5%; white-space: nowrap">Replies</td>
        <td class="punhead" style="width: 14%; white-space: nowrap">Last Poster</td>
        <td class="punhead" style="width: 14%; white-space: nowrap"><?php echo $lang_common['Last post'] ?></td>
    </tr>
<?php
while ($ak_post = $db->fetch_assoc($latest)) {
    $subject_new_posts = '[ <a href="viewtopic.php?id='.$ak_post['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]';
?>
    <tr class="puntopic">
        <td class="puncon2"><a href="viewtopic.php?id=<?php echo $ak_post['id'] ?>&action=new"><?php echo pun_htmlspecialchars($ak_post['subject']) ?></a> <?php echo $subject_new_posts; ?></td>
        <td class="puncon2"><?php echo pun_htmlspecialchars($ak_post['num_replies']) ?></td>
        <td class="puncon2"><?php echo pun_htmlspecialchars($ak_post['last_poster']) ?></td>
        <td class="puncon2" style="white-space: nowrap"><?php echo format_time($ak_post['last_post']) ?></td>
    </tr>
<?php
}
?>
</table>


<table class="punspacer" cellspacing="1" cellpadding="4"><tr><td> </td></tr></table>
<?php
require $pun_root.'footer.php';

Re: vanilla style front page (active topics)

ok i got rid of those errors but i think im missing some of those new hook codes but wateva, tell me where to add them if their important

<?php

if (!defined('PUN_ROOT'))
    define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

($hook = get_hook('in_start')) ? eval($hook) : null;

if ($pun_user['g_read_board'] == '0')
    message($lang_common['No view']);

// Load the index.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';


$page_title = htmlspecialchars($pun_config['o_board_title']).' / Active Topics';
define('PUN_ALLOW_INDEX', 1);
define('PUN_PAGE', 'index');
require PUN_ROOT.'header.php';

$day_limit = 2; // make this the auto number of days you want to be displayed.

$days = isset($_POST['days']) ? $_POST['days'] : $day_limit;
$posts_since = mktime(date("H"), date("i"), date("s"), date("m"), (date("d")-$days), date("Y"));

$latest = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.last_poster, t.num_replies, 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 f.admmod_only=0
AND t.last_post>'.$posts_since.'
ORDER BY last_post DESC');
?>
<table class="punspacer" cellspacing="1" cellpadding="4">
    <tr>
        <td style="width: 14%;"><b><a href="index.php"><?php echo htmlspecialchars($pun_config['o_board_title']) ?></a> / Active Topics</b></td>
        <td class="punright"><form method="post" action="">Days to show: <input type="text" name="days" value="<?php echo $days; ?>" size="3"> <input type="submit" value="Go"></form></td>
    </tr>
</table>
<table class="punmain" cellspacing="1" cellpadding="4">
    <tr class="punhead">
        <td class="punhead"><?php echo $lang_common['Topic'] ?></td>
        <td class="punhead" style="width: 5%; white-space: nowrap">Replies</td>
        <td class="punhead" style="width: 14%; white-space: nowrap">Last Poster</td>
        <td class="punhead" style="width: 14%; white-space: nowrap"><?php echo $lang_common['Last post'] ?></td>
    </tr>
<?php
while ($ak_post = $db->fetch_assoc($latest)) {
    $subject_new_posts = '[ <a href="viewtopic.php?id='.$ak_post['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]';
?>
    <tr class="puntopic">
        <td class="puncon2"><a href="viewtopic.php?id=<?php echo $ak_post['id'] ?>&action=new"><?php echo pun_htmlspecialchars($ak_post['subject']) ?></a> <?php echo $subject_new_posts; ?></td>
        <td class="puncon2"><?php echo pun_htmlspecialchars($ak_post['num_replies']) ?></td>
        <td class="puncon2"><?php echo pun_htmlspecialchars($ak_post['last_poster']) ?></td>
        <td class="puncon2" style="white-space: nowrap"><?php echo format_time($ak_post['last_post']) ?></td>
    </tr>
<?php
}
?>
</table>


<table class="punspacer" cellspacing="1" cellpadding="4"><tr><td> </td></tr></table>
<?php
($hook = get_hook('in_end')) ? eval($hook) : null;

require PUN_ROOT.'footer.php';

ok now no errors, but it doesnt show any of the active topics

Re: vanilla style front page (active topics)

lol i fixed it and it works
changed it to alexking's code
and made it display like the topics in the forum

<?php

if (!defined('PUN_ROOT'))
    define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

($hook = get_hook('in_start')) ? eval($hook) : null;

if ($pun_user['g_read_board'] == '0')
    message($lang_common['No view']);

// Load the index.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';

define('PUN_ALLOW_INDEX', 1);
define('PUN_PAGE', 'index');
require PUN_ROOT.'header.php';

$ak_limit = 25; // change this to the number of active topics you want to display.

$result = $db->query('
    SELECT t.* 
    FROM '.$db->prefix.'topics AS t 
    INNER JOIN '.$db->prefix.'forums AS f 
    ON f.id=t.forum_id 
    LEFT JOIN '.$db->prefix.'forum_perms AS fp 
    ON (
        fp.forum_id=f.id 
        AND fp.group_id='.$pun_user['g_id'].'
    ) 
    WHERE (
        fp.read_forum IS NULL 
        OR fp.read_forum=1
    ) 
    ORDER BY t.last_post DESC
    LIMIT '.$ak_limit
) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

?>
<div id="pun-main" class="main">

    <div class="main-head">
        <h2><span>Active Topics</span></h2>
    </div>


        <div id="category1" class="main-content category">
            <table cellspacing="0">
            <thead>
                <tr>
                    <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
                    <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
                    <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
                    <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
                </tr>
            </thead>
            <tbody class="statused">
<?php
// If there are topics in this forum.
if ($db->num_rows($result))
{
    while ($cur_topic = $db->fetch_assoc($result))
    {

        if ($cur_topic['moved_to'] == null)
            $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.htmlspecialchars($cur_topic['last_poster']).'</span>';
        else
            $last_post = ' ';

        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);

        if ($cur_topic['moved_to'] != 0)
            $subject = $lang_forum['Moved'].': <a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
        else if ($cur_topic['closed'] == '0')
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.htmlspecialchars($cur_topic['poster']).'</span>';
        else
        {
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.htmlspecialchars($cur_topic['poster']).'</span>';
        }

        if (!$pun_user['is_guest'] && $cur_topic['last_post'] > $pun_user['last_visit'] && $cur_topic['moved_to'] == null)
        {
            $subject = '<strong>'.$subject.'</strong>';
            $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>';
        }
        else
            $subject_new_posts = null;

        // Should we display the dot or not? :)
        if (1 == 0 && !$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1')
        {
            if ($cur_topic['has_posted'] == $pun_user['id'])
                $subject = '<strong>·</strong> '.$subject;
            else
                $subject = '  '.$subject;
        }

        if ($cur_topic['sticky'] == '1')
        {
            $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
        }

        $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);

        if ($num_pages_topic > 1)
            $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
        else
            $subject_multipage = null;

        // Should we show the "New posts" and/or the multipage links?
        if (!empty($subject_new_posts) || !empty($subject_multipage))
        {
            $subject .= '  '.(!empty($subject_new_posts) ? $subject_new_posts : '');
            $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
        }

?>
                <tr id="forum1" class="odd normal">
                    <td class="tcl">
                        <span class="status normal" title="Forum"><img src="http://localhost/punbbbeta/style/Oxygen/status.png" alt="Forum" /></span><?php echo $subject."\n" ?>
                    </td>
                    <td class="tc2"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_replies'] : ' ' ?></td>
                    <td class="tc3"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_views'] : ' ' ?></td>
                    <td class="tcr"><?php echo $last_post ?></td>
                </tr>
<?php

    }
}
else
{

?>
                <tr>
                    <td class="tcl" colspan="4"><?php echo $lang_forum['Empty forum'] ?></td>
                </tr>
<?php

}

?>
            </tbody>
            </table>
            </div>
<?php
($hook = get_hook('in_end')) ? eval($hook) : null;

require PUN_ROOT.'footer.php';

Re: vanilla style front page (active topics)

It's nice, but there are a couple problems:
A. It uses identical hook names to index.php
B. It doesn't use query builder
C. It has two hooks and the variable scheme doesn't use the $pun_page stuff: it isn't extensible.

5 (edited by raptrex 2008-03-25 21:55)

Re: vanilla style front page (active topics)

it used the same names as index because thats where i copied them from, do i really need the hooks there?
im new to the 1.3beta so i dont know how to use the query builder yet (someone wanna do this for me??)
is making this extensible better? if not should i just take out the hooks?

6

Re: vanilla style front page (active topics)

As for 'B' (the query builder), it's just a conventional way of writing requests in punbb 1.3.
Just have a look at any file from punbb 1.3, and inspire from it (basically, u just have to split ur requests in an array..)

For the other points ('A' & 'C'), maybe we didn't understand what u really want to do (based on the subject).

Re: vanilla style front page (active topics)

well the script is suppose to show active topics
i just put in the hook part because the index file had them
do i really need hooks in my script? can i just take them out and it will still work?
i cant really test this out since im on vacation tongue

Re: vanilla style front page (active topics)

It will work without hooks but the entire point of hooks is to make it possible for others to extend/change your code without physically modifying it.