09-19-2001, 10:00 PM
Vision 2.1
i promised to reduse the extra queries to 1. in this 1 query, we can get the last post title, last thread title and last icon... so it have a shorter load time...
i still believe my this hack Release is the simplest mode to display the last post titles in Forumhome & Forumdisplay Page, because it dosen't need any action in database, and just modify 2 places in 2 files... furthermore, now the new vision have reduced the load time very much...
many thanks to PPN for his help...
OK, let's go!
1. change index.php and forumdisplay.php:
find in index.php:
// prepare template vars
if (!$showforumdescription) {
$forum['description']='';
}
find in forumdisplay.php:
// dates
if ($forum['lastpost']>0) {
$forum['lastpostdate']=vbdate($dateformat,$forum['lastpost']);
$forum['lastposttime']=vbdate($timeformat,$forum['lastpost']);
below these add:
// start last post title hack by cx
$lasttitle = '';
$lasticon = '';
if ($forumperms['canview']) {
$forum_this = $DB_site->query_first("SELECT post.title AS posttitle,thread.title AS threadtitle,post.iconid,icon.title AS icontitle,iconpath FROM thread LEFT JOIN post USING (threadid) LEFT JOIN icon USING (iconid) WHERE post.username='$forum[lastposter]' AND post.dateline=$forum[lastpost]");
$lasttitle = $forum_this[posttitle];
if ($lasttitle == '') {
$lasttitle = 'Re: '.$forum_this[threadtitle];
}
$lasttitle_raw = $lasttitle;
if (strlen($lasttitle) > 30) {
$lasttitle = substr($lasttitle, 0, 28);
$lasttitle .= '..';
}
if ($forum_this[iconid] > 0) {
$lasticon = "<img src=$forum_this[iconpath] alt=\"$forum_this[icontitle]\" align=absbottom>";
}
}
// end last post title hack by cx
2. i have made the post icons display... so change the template forumhome_lastpostby to:
<table cellpadding="0" cellspacing="0" border="0" width="100%" id="ltlink"><tr align="right">
<td nowrap><smallfont>$lasticon <a href="showthread.php?s=$session[sessionhash]&goto=lastpost&forumid=$forum[forumid]" title="Go to last post: $lasttitle_row">$lasttitle</a><br>
by <a href="member.php?s=$session[sessionhash]&action=getinfo&find=lastposter&forumid=$forum[forumid]">$forum[lastposter]</a> @ $forum[lastpostdate] <font color="#666686">$forum[lastposttime]</font>
</smallfont></td>
<td nowrap> <a href="showthread.php?s=$session[sessionhash]&goto=lastpost&forumid=$forum[forumid]"><img src="images/lastpost.gif" border="0" alt="Go to last post: $lasttitle_raw"></a></td>
</tr></table>
DONE!
------------------------------------------------------------------------------
The Older Vision
a PHP+MySQL newbie's bad exercise...
if you find interest in this you can compare it with the last Release...
someone has posted this type hack, but this Release has a little difference. and in the other's release there's some bugs(about the subforums' last post title), now it has been fixed:
1. change index.php and forumdisplay.php:
find in index.php:
// prepare template vars
if (!$showforumdescription) {
$forum['description']='';
}
find in forumdisplay.php:
// dates
if ($forum['lastpost']>0) {
$forum['lastpostdate']=vbdate($dateformat,$forum['lastpost']);
$forum['lastposttime']=vbdate($timeformat,$forum['lastpost']);
below these add:
// start last post title hack by cx
$forum_this = $DB_site->query_first("SELECT parentlist FROM forum WHERE forumid=$forum[forumid]");
$forum_this_parents = explode(',', $forum_this[parentlist]);
$forum_this_parents_count = count($forum_this_parents);
$forum_sons = $DB_site->query('SELECT parentlist,forumid FROM forum');
while ($forum_son = $DB_site->fetch_array($forum_sons)) {
$forum_parentlist = $forum_son[parentlist];
$forum_parents = explode(',', $forum_parentlist);
$forum_parents_count = count($forum_parents);
if ($forum_parents[$forum_parents_count - $forum_this_parents_count] == $forum[forumid]) {
$forum_son_all[] = $forum_son[forumid];
}
}
if ($forum_son_all != '') {
$forum_sons = implode(',', $forum_son_all);
$lastposttitlex = $DB_site->query_first("SELECT post.title FROM thread,post WHERE thread.forumid IN($forum_sons) AND post.threadid=thread.threadid AND post.visible=1 ORDER BY post.dateline DESC");
$lastposttitle = ''.$lastposttitlex[title];
if ($lastposttitle == '') {
$lastposttitlex = $DB_site->query_first("SELECT title FROM thread WHERE forumid IN($forum_sons) AND visible=1 ORDER BY lastpost DESC");
$lastposttitle = 'RE: '.$lastposttitlex[title];
}
if (strlen($lastposttitle) > 30) {
$lastposttitle = substr($lastposttitle, 0, 28);
$lastposttitle .= '..';
}
}
// end last post title hack by cx
2. change the template forumhome_lastpostby to:
<div align=right><smallfontbr><nobr><a href="showthread.php?s=$session[sessionhash]&goto=lastpost&forumid=$forum[forumid]" title="turn to last new post">$lastposttitle</a></nobr><br><nobr>$forum[lastpostdate] <font color="#666686">$forum[lastposttime]</font></nobr><br><nobr>by <a href="member.php?s=$session[sessionhash]&action=getinfo&find=lastposter&forumid=$forum[forumid]">$forum[lastposter]</a></nobr></smallfont></div>
3. done! easy and funny job :)
i promised to reduse the extra queries to 1. in this 1 query, we can get the last post title, last thread title and last icon... so it have a shorter load time...
i still believe my this hack Release is the simplest mode to display the last post titles in Forumhome & Forumdisplay Page, because it dosen't need any action in database, and just modify 2 places in 2 files... furthermore, now the new vision have reduced the load time very much...
many thanks to PPN for his help...
OK, let's go!
1. change index.php and forumdisplay.php:
find in index.php:
// prepare template vars
if (!$showforumdescription) {
$forum['description']='';
}
find in forumdisplay.php:
// dates
if ($forum['lastpost']>0) {
$forum['lastpostdate']=vbdate($dateformat,$forum['lastpost']);
$forum['lastposttime']=vbdate($timeformat,$forum['lastpost']);
below these add:
// start last post title hack by cx
$lasttitle = '';
$lasticon = '';
if ($forumperms['canview']) {
$forum_this = $DB_site->query_first("SELECT post.title AS posttitle,thread.title AS threadtitle,post.iconid,icon.title AS icontitle,iconpath FROM thread LEFT JOIN post USING (threadid) LEFT JOIN icon USING (iconid) WHERE post.username='$forum[lastposter]' AND post.dateline=$forum[lastpost]");
$lasttitle = $forum_this[posttitle];
if ($lasttitle == '') {
$lasttitle = 'Re: '.$forum_this[threadtitle];
}
$lasttitle_raw = $lasttitle;
if (strlen($lasttitle) > 30) {
$lasttitle = substr($lasttitle, 0, 28);
$lasttitle .= '..';
}
if ($forum_this[iconid] > 0) {
$lasticon = "<img src=$forum_this[iconpath] alt=\"$forum_this[icontitle]\" align=absbottom>";
}
}
// end last post title hack by cx
2. i have made the post icons display... so change the template forumhome_lastpostby to:
<table cellpadding="0" cellspacing="0" border="0" width="100%" id="ltlink"><tr align="right">
<td nowrap><smallfont>$lasticon <a href="showthread.php?s=$session[sessionhash]&goto=lastpost&forumid=$forum[forumid]" title="Go to last post: $lasttitle_row">$lasttitle</a><br>
by <a href="member.php?s=$session[sessionhash]&action=getinfo&find=lastposter&forumid=$forum[forumid]">$forum[lastposter]</a> @ $forum[lastpostdate] <font color="#666686">$forum[lastposttime]</font>
</smallfont></td>
<td nowrap> <a href="showthread.php?s=$session[sessionhash]&goto=lastpost&forumid=$forum[forumid]"><img src="images/lastpost.gif" border="0" alt="Go to last post: $lasttitle_raw"></a></td>
</tr></table>
DONE!
------------------------------------------------------------------------------
The Older Vision
a PHP+MySQL newbie's bad exercise...
if you find interest in this you can compare it with the last Release...
someone has posted this type hack, but this Release has a little difference. and in the other's release there's some bugs(about the subforums' last post title), now it has been fixed:
1. change index.php and forumdisplay.php:
find in index.php:
// prepare template vars
if (!$showforumdescription) {
$forum['description']='';
}
find in forumdisplay.php:
// dates
if ($forum['lastpost']>0) {
$forum['lastpostdate']=vbdate($dateformat,$forum['lastpost']);
$forum['lastposttime']=vbdate($timeformat,$forum['lastpost']);
below these add:
// start last post title hack by cx
$forum_this = $DB_site->query_first("SELECT parentlist FROM forum WHERE forumid=$forum[forumid]");
$forum_this_parents = explode(',', $forum_this[parentlist]);
$forum_this_parents_count = count($forum_this_parents);
$forum_sons = $DB_site->query('SELECT parentlist,forumid FROM forum');
while ($forum_son = $DB_site->fetch_array($forum_sons)) {
$forum_parentlist = $forum_son[parentlist];
$forum_parents = explode(',', $forum_parentlist);
$forum_parents_count = count($forum_parents);
if ($forum_parents[$forum_parents_count - $forum_this_parents_count] == $forum[forumid]) {
$forum_son_all[] = $forum_son[forumid];
}
}
if ($forum_son_all != '') {
$forum_sons = implode(',', $forum_son_all);
$lastposttitlex = $DB_site->query_first("SELECT post.title FROM thread,post WHERE thread.forumid IN($forum_sons) AND post.threadid=thread.threadid AND post.visible=1 ORDER BY post.dateline DESC");
$lastposttitle = ''.$lastposttitlex[title];
if ($lastposttitle == '') {
$lastposttitlex = $DB_site->query_first("SELECT title FROM thread WHERE forumid IN($forum_sons) AND visible=1 ORDER BY lastpost DESC");
$lastposttitle = 'RE: '.$lastposttitlex[title];
}
if (strlen($lastposttitle) > 30) {
$lastposttitle = substr($lastposttitle, 0, 28);
$lastposttitle .= '..';
}
}
// end last post title hack by cx
2. change the template forumhome_lastpostby to:
<div align=right><smallfontbr><nobr><a href="showthread.php?s=$session[sessionhash]&goto=lastpost&forumid=$forum[forumid]" title="turn to last new post">$lastposttitle</a></nobr><br><nobr>$forum[lastpostdate] <font color="#666686">$forum[lastposttime]</font></nobr><br><nobr>by <a href="member.php?s=$session[sessionhash]&action=getinfo&find=lastposter&forumid=$forum[forumid]">$forum[lastposter]</a></nobr></smallfont></div>
3. done! easy and funny job :)