PunBB Resource

Your ultimate PunBB resource!

Keywords:

    (Extended)

You are not logged in.

#1 2008-01-20 19:39:44

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Pagination on PunPortal

I am looking for someone who is interested in adding pagination to the bottom of punportal pages (see: http://reviewstash.com) at the bottom of punportal's index to see previous postings.

Offline

 

#2 2008-01-20 19:46:13

Mark
Moderator
From: North West England
Registered: 2005-06-06
Posts: 1165

Re: Pagination on PunPortal

have you have a look at the mini portal on the wiki?


Cant find something you want? try searching
Also try the wiki

Offline

 

#3 2008-01-20 20:04:05

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Re: Pagination on PunPortal

I don't see anything about pagination on there.

Offline

 

#4 2008-01-20 20:47:57

utchin
Member
Registered: 2007-08-07
Posts: 161

Re: Pagination on PunPortal

Its rather easy to add pagination to well anything...


Just look at the userlist.php and copy that and edit it... i will do it, but having problems with vista....

Offline

 

#5 2008-01-20 21:15:09

MattF
Member
From: South Yorkshire, England
Registered: 2007-03-16
Posts: 415

Re: Pagination on PunPortal

utchin wrote:

Its rather easy to add pagination to well anything...

Only if one has any knowledge of, (or inclination to), code. One shouldn't assume that everyone can, or wishes to, write code.

Offline

 

#6 2008-01-20 21:23:06

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Re: Pagination on PunPortal

Code:

// Generate paging links
$paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'userlist.php?username='.urlencode($username).'&show_group='.$show_group.'&sort_by='.$sort_by.'&sort_dir='.strtoupper($sort_dir));


?>
<div class="linkst">
    <div class="inbox">
        <p class="pagelink"><?php echo $paging_links ?></p>
    </div>
</div>

That's what I got out of the userlist file, however I have no idea where to go from here, so here's my index file.

Code:

<?php
 
define('PUN_ROOT', './');
require_once PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars('reviewstash / by the stash, for the stash');

define('PUN_ALLOW_INDEX', 1);
require_once PUN_ROOT.'header.php';
require_once PUN_ROOT.'include/parser.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/login.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

//----------------------------------------------------------------------//

//These are the forums from which the news is retrieved - You may add more forums in the array. Make sure to seperate them with a (,)
$forumids = array(8,6,7);

//This is the overall limit for how many news items will be displayed
$master_limit = '10';

//This is the amount of characters above which truncation will occur
$trunc_chars = '1000';

//----------------------------------------------------------------------//

if ($pun_config['o_index_message_show'] == 1)
{
?>
    <div class="block">
        <h2><span><?php echo pun_htmlspecialchars($pun_config['o_index_message_head']) ?></span></h2>
        <div class="box">
            <div class="inbox">
            <?php echo $pun_config['o_index_message'] ?>
            </div>
        </div>
    </div>
<?php
}
?>
<?php
//----------------------------------------------------------------------//

function close_tags($string)
{
    if (preg_match_all ('/<([a-z]+)[ >]/', $string, $start_tags))
    {
        $start_tags = $start_tags[1];

        if (preg_match_all ('/<\/([a-z]+)>/', $string, $end_tags))
        {
            $complete_tags = array();
            $end_tags = $end_tags[1];

            foreach ($start_tags as $key => $val)
            {
                $posb = array_search ($val, $end_tags);
                if (is_integer ($posb))
                {
                    unset ($end_tags[$posb]);
                }
                else
                {
                    $complete_tags[] = $val;
                }
            }
        }
        else
        {
            $complete_tags = $start_tags;
        }

        $complete_tags = array_reverse ($complete_tags);
        for ($i = 0; $i < count ($complete_tags); $i++)
        {
            $string .= '</' . $complete_tags[$i] . '>';
        }
    }

        // Removes irrelevant tags
    $xhtml_tags = array ('</img>', '</hr>', '</br>');
    $string = str_replace ($xhtml_tags, '', $string);
    return $string;
}

//----------------------------------------------------------------------//

function truncate($string)
{
global $pun_config;
$trunc_chars = '350';
$length = $trunc_chars;
$append = '...';

    if (strlen ($string) <= $length)
    {
        return $string;
    }
    else if ($length > 0)
    {
        preg_match ('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$length.',}\b#U', $string, $matches);
        $string = $matches[0];
        $string = close_tags (preg_replace ('#\s*<[^>]+>?\s*$#', '', $string).$append);
        return $string;
    }
}

$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, u.use_avatar, u.num_posts, u.registered, u.title, p.id AS pid, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id IN ('.implode(',', $forumids).') AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$master_limit) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());

if ($db->num_rows($result))
{
    while($cur_post = $db->fetch_assoc($result))
    {
        echo '<div class="block">';
        if ($pun_config['o_avatars'] == '1' && $cur_post['use_avatar'] == '1' && $pun_user['show_avatars'] != '0')
        {
            if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif'))
            {
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.gif" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            }
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg'))
            {
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.jpg" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            }
            else if ($img_size = @getimagesize($pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png'))
            {
                $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="'.$pun_config['o_avatars_dir'].'/'.$cur_post['poster_id'].'.png" '.$img_size[3].' title="'.$cur_post['poster'].'\'s Avatar" alt="'.$cur_post['poster'].'\'s Avatar" /></a>';
            }
        }
        else
        {
            $user_avatar = '<a href="profile.php?id=' . $cur_post['poster_id'] . '"><img src="img/noimage.gif" alt=""/></a>';
        }

      $news_message = parse_message($cur_post['message'], $cur_post['hide_smilies']);

        if (pun_strlen($news_message) > $trunc_chars)
        {
            $news_message = truncate($news_message);
            $read_more = '&nbsp;|&nbsp;<a href="viewtopic.php?id='.$cur_post['id'].'">Read More</a>&nbsp;|&nbsp;';
        }
        else
        {
            $read_more = '&nbsp;|&nbsp;';
        }

        if ($cur_post['num_replies'] != '0')
        {
            $replies = '&nbsp;<a href="viewtopic.php?id='.$cur_post['id'].'#p'.$cur_post['last_post_id'].'">Replies</a>:&nbsp;'.$cur_post['num_replies'].'&nbsp;';
        }
        else
        {
            $replies = '&nbsp;Replies: '.$cur_post['num_replies'].'&nbsp;';
        }

echo "\t\t\t\t\t\t\t".'<h2><strong><a href="forum.php">Forum</a>&nbsp;&raquo;&nbsp;<a href="viewforum.php?id='.$cur_post['forum_id'].'">'.pun_htmlspecialchars($cur_post['forum_name']).'</a>'.'</strong></h2>'."\n";
?>
    <div class="box">
        <div class="inbox">
<ul><li>
<table width="100%" border="0">
    <tr>
        <td style="border: 0px; padding: 0px 10px 7px 7px;"><a class="news_subject" href="viewtopic.php?id=<?php echo $cur_post['id']; ?>"><?php echo $cur_post['subject']; ?></a></td>
    </tr>
</table> 
<table width="100%" border="0">
    <tr>
        <td style="text-align: left; border: 0px; padding-top: 0px;" valign="top"><?php echo $news_message."\n" ?></td>
    </tr>
</table>

    <div style="padding-bottom: 20px;" class="news_footer"><div style="padding: 5px 5px 0px 5px;">

<?php

                if ($cur_post['poster_id'] == $pun_user['id'] || $pun_user['g_id'] < PUN_GUEST){
                echo "\t\t\t\t\t\t\t".'<span class="user" style="float:left">Posted: '.format_time($cur_post['posted']).' by:<span class="user'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'">&nbsp;<a class="poster" href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['poster']).'</a>'.$read_more.'Views: '.$cur_post['num_views'].'&nbsp;|'.$replies.'</span></span>'."\n\n\n\n";
                echo "\t\t\t\t\t\t\t".'<a href="viewtopic.php?id='.$cur_post['id'].'">'.pun_htmlspecialchars($lang_portal['Visit_Topic']).'</a>'.'<span style="white-space: nowrap; float:right">'.'<a href="misc.php?report='.$cur_post['pid'].'">'.$lang_topic['Report'].'</a>'.' | <a href="delete.php?id='.$cur_post['pid'].'">'.$lang_topic['Delete'].'</a> | <a href="edit.php?id='.$cur_post['pid'].'">'.$lang_topic['Edit'].'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'">'.'Reply'.'</a>'.' | <a href="post.php?tid='.$cur_post['id'].'&amp;qid='.$cur_post['pid'].'">'.$lang_topic['Quote'].'</a>'.'</span></div></div>'."\n\n\n\n";
            }else{
                echo "\t\t\t\t\t\t\t".'<span class="user" style="float:left">Posted: '.format_time($cur_post['posted']).' by:<span class="user'.(isset($cur_post['g_title']) ? ' '.strtolower(str_replace(' ', '', $cur_post['g_title'])) : '').'">&nbsp;<a class="poster" href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['poster']).'</a>'.$read_more.'Views: '.$cur_post['num_views'].'&nbsp;|'.$replies.'</span></span></div></div>'."\n";
}
?>   
</li></ul>
        </div>
    </div>
</div>
<?php
    }
}

require PUN_ROOT.'footer.php';

?>

Also, does Miniportal out of the box suport pagination, because if so I'll just switch over. Thanks

Offline

 

#7 2008-01-20 21:37:14

MattF
Member
From: South Yorkshire, England
Registered: 2007-03-16
Posts: 415

Re: Pagination on PunPortal

Also, does Miniportal out of the box suport pagination

Nope. The general theory behind the index page is that it provides an at a glance overview of what's recently happened. Multiple pages defeat that purpose somewhat. smile

Offline

 

#8 2008-01-20 22:16:36

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Re: Pagination on PunPortal

Then how would I go about integrating pagination?

Offline

 

#9 2008-01-20 22:53:17

utchin
Member
Registered: 2007-08-07
Posts: 161

Re: Pagination on PunPortal

Sorry about that, i ment to say that the concept is easy...I went into doing this without a clue... but then i relised you just count the articals/users/posts then devide that by the ammount of items on that page then echo...sounds easy but once you know it, it does become usefull....

(ill help you soon, gotta reinstall my software sad )

Offline

 

#10 2008-01-20 23:02:04

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Re: Pagination on PunPortal

Awesome, thanks. It is a simple yet helpful core concept. It's just not exactly easy for me to implement with my sub-par coding abilities.

Offline

 

#11 2008-01-21 00:04:17

utchin
Member
Registered: 2007-08-07
Posts: 161

Re: Pagination on PunPortal

ok not tested...

Add this to the top of the page, you want to edit it, to count the artical...

Code:

// Fetch artical count
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'clans AS u WHERE u.id>1 ') or error('Unable to fetch list count', __FILE__, __LINE__, $db->error());
$num_users = $db->result($result);

$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
$start_from = 50 * ($p - 1);

// Generate paging links
$paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, '******.php?'.strtoupper($sort_dir));

now add this to the bottem/top or where you want it

Code:

<div class="linkst">
    <div class="inbox">
        <p class="pagelink"><?php echo $paging_links ?></p>
    </div>
</div>

then you need to add this to the MAIN select query..

Code:

LIMIT '.$start_from.', 50

Sorry its not related to punportal

Last edited by utchin (2008-01-21 00:09:36)

Offline

 

#12 2008-01-23 04:35:04

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Re: Pagination on PunPortal

Uh, so what do I do?

Offline

 

#13 2008-02-09 18:34:13

xSDMx
Member
Registered: 2007-12-06
Posts: 25
Website

Re: Pagination on PunPortal

Anyone figure this out? I'd be willing to pay.

Offline

 

Board footer

Based on PunBB
© Copyright 2002–2005 Rickard Andersson

© Copyright 2004–2006 Kristoffer Jansson

User contributed files are property of their respective owners.