Mod Name / Version: Paginate PMs
Description: This mod puts your PMs into pages (much like forum threads are), which is especially helpful to your users who keep a lot of their PMs lying around.
This code is a simple cut and paste from this functionality found within postlist.php, adapted for use with PMs.
Working Under: UBB.Threads 6.4
Mod Status: Beta
Any pre-requisites:
Author(s): bostongio
Date: 06/20/05
Credits: UBBthreads
Files Altered: viewmessages.php
templates/default/viewmessages.tmpl
New Files:
Database Altered: No
Info/Instructions: In viewmessages.php
Find:
Code:
// ---------------------------------------------------------
// Ok, we found the profile, now lets put it all onto a page
$html -> send_header("$ubbt_lang[$box]",$Cat,0,$user);
Replace with:
Code:
// ---------------------------------------------------------
// Ok, we found the profile, now lets put it all onto a page
$html -> send_header("$ubbt_lang[$box]",$Cat,0,$user);
// -----------------------------------------
// Find out how many posts to show per page
if (!$PostsPer) {
$PostsPer = $theme['postsperpage'];
}
// ---------------------------------------------------------------------
// Now we calculate which posts to grab for this page. We want to grab
// one from the previous page and one from the next page so we know what
// the previous and nexts posts will be
if (!($page > 0)) {
$Totalgrab = $PostsPer + 1;
$Posts = $PostsPer + 1;
}
else {
$Startat = $page * $PostsPer;
$Posts = $PostsPer + 1;
$Totalgrab = "$Startat, $Posts";
}
$endpage = 1;
$limit = "LIMIT $Totalgrab";
-------------------------------------------------------------------
Find:
Code:
// -------------------------
// Get any private messages.
$username_q = addslashes($Username);
$query = "
SELECT t1.M_Status, t1.M_Subject, t1.M_Sender, t1.M_Sent, t1.M_Number, t2.U_Username
FROM {$config['tbprefix']}Messages AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.M_Uid = '{$user['U_Number']}'
AND t1.M_Status $extra 'X'
AND t1.M_Sender = t2.U_Number
ORDER BY t1.M_Sent DESC
";
$sth = $dbh -> do_query($query);
$i = 0;
Replace with:
Code:
// -------------------------
// Get any private messages.
$username_q = addslashes($Username);
$query = "
SELECT t1.M_Status, t1.M_Subject, t1.M_Sender, t1.M_Sent, t1.M_Number, t2.U_Username
FROM {$config['tbprefix']}Messages AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.M_Uid = '{$user['U_Number']}'
AND t1.M_Status $extra 'X'
AND t1.M_Sender = t2.U_Number
ORDER BY t1.M_Sent DESC
$limit
";
$sth = $dbh -> do_query($query);
$i = 0;
// -------------------------------------------------------------------
// If $page is greater than 0 then we need a link to the previous page
if ($page > 0) {
$prev = $page - 1;
$prevstart = "<a class=\"noun\" href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&box=$box&page
=$prev&sb=$sb&o=$o\">";
$prevoption = "previous.gif";
$prevstop = "</a>";
}
else {
$prevoption = "greyprevious.gif";
}
// ----------------------------------------------------------------------
// If total parent posts is greater than $PostsPer*Page then we give them
// a link to the next page
if ($nums >= ($PostsPer + 1) ) {
$next = $page + 1;
$nextstart = "<a class=\"noun\" href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&box=$box&page
=$next&sb=$sb&o=$o\">";
$nextstop = "</a>";
$nextoption = "next.gif";
}
else {
$nextoption = "greynext.gif";
}
--------------------------------------------------------------------
Find:
Code:
$messagesize = "0";
if (isset($message)) {
$messagesize = sizeof($message);
}
Replace with:
Code:
$messagesize = "0";
if (isset($message)) {
$messagesize = sizeof($message);
}
$query = "
SELECT COUNT(*)
FROM {$config['tbprefix']}Messages AS t1,
{$config['tbprefix']}Users AS t2
WHERE t1.M_Uid = '{$user['U_Number']}'
AND t1.M_Status $extra 'X'
AND t1.M_Sender = t2.U_Number
";
$sth = $dbh -> do_query($query);
list($totaltopics) = $dbh -> fetch_array($sth);
$dbh -> finish_sth($sth);
$Threads = $totaltopics;
$TotalP = ceil($Threads/$PostsPer);
if ($TotalP > 0) { $pagejumpers = "Page "; }
$Startpage = $page - 5;
$Endpage = $page + 5;
if ($Startpage < 0) {
$Endpage = $Endpage - $Startpage;
$Startpage = 0;
}
if ($Endpage > $TotalP) {
$Endpage = $TotalP;
$Startpage = $Endpage - 10;
}
if ($Startpage < 0) { $Startpage = 0; }
if ($Startpage > 0) {
$midprint = intval($Startpage / 2) - 1;
$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=0&box=$box&sb=$sb&am
p;o=$o\">1</a> ";
$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$midprint&box=$box&sb=
$sb&o=$o\">...</a> ";
}
if ($Threads > $PostsPer) {
for ($i = $Startpage; $i <= $Endpage; $i++) {
$printedpage = $i + 1;
if ($i == $page) {
$pagejumpers .= "<strong>[$printedpage]</strong> ";
} else {
if ($printedpage <= $Endpage) {
$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$i&view=$view&box=$box
&sb=$sb&o=$o\">$printedpage</a> ";
}
}
}
}
else {
$pagejumpers .= "1";
}
if ($Endpage < $TotalP) {
$Totalprint = $TotalP - 1;
$midprint = $TotalP - intval(($TotalP - $Endpage) / 2);
$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$midprint&box=$box&a
mp;sb=$sb&o=$o\">...</a> ";
$pagejumpers .= "<a href=\"{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$Totalprint&box=$box
&sb=$sb&o=$o\">$TotalP</a> ";
}
$pagejumpers .= "</font>";
===============================================================
In templates/default/viewmessages.tmpl
Find at the bottom of the file:
Code:
</td>
</tr>
$tbclose
</form>
UBBTPRINT;
/* UBBTREMARK */ ?>
Replace with:
Code:
</td>
</tr>
<tr>
<td colspan="8" class="tdheader" align="right">
$pagejumpers
</td></tr>
$tbclose
</form>
UBBTPRINT;
/* UBBTREMARK */ ?>
Disclaimer: Please backup every file that you intend to modify.
If the modification modifies the database, it's a good idea to backup your database before doing so.
Note: If you modify your UBB.Threads code, you may be giving up your right for "official" support from Infopop.If you need official support, you'll need to restore unmodified files.