StewardManscat
05-22-2005, 02:26 PM
Some of our forums are nothing but single posts. Not much discussion. A news format would make sense: less clicking to open up posts.
(In fact, when I first got vb, I was crestfallen to realize this was not something easily configurable).
vbadvanced to the rescue!
Here is a rough overview of the hack. Sorry, no detailed, carefully debugged, tested and perfected step by step instructions. I'm just wondering if I am wasting my time anyway. Maybe there is a better way to do this?
No screen snaps. It looks like your news pages, but the news block has forum page navigation at top and bottom. First,1,2,3, etc.
First and ugliest
If you went with the default "page variable" that comes with CMPS (default settings), this has to go. Because vb uses the variable "page" for paging. After experimenting, I changed my CMPS page variable to "content".
Make a copy of news.php
Either just backup while you test, or rename it and create a new module that uses it.
If you rename it, find
if ($omods['identifier'] == 'news' AND in_array($omods['modid'], explode(',', $pages['modules'])))
and replace 'news' with the new name. Say I saved news.php as quickies.php:
if ($omods['identifier'] == 'quickies' AND in_array($omods['modid'], explode(',', $pages['modules'])))
Optional next step. Which forums to pull posts out of? Currently I am looking at one module I can use for all forums, and providing a 'display mode' link so people can choose their preference. In this case the forum id is variable.
So I find:
unset($omods);
Add after:
globalize($_REQUEST,array('f'=>STR));
if ($_REQUEST['f'])
{
$vba_options['portal_news_forumid'] = $f;
}
Note you can still use mutliple forums, eg "23,4,51"
Next step: find the huge query statement. There's just one. Above it add:
// Strip down original query to get only a count
$newsquery =
"SELECT count(*) AS count
FROM " . TABLE_PREFIX . "thread AS thread
$deljoin
WHERE forumid IN($vba_options[portal_news_forumid]) AND thread.visible = 1 AND thread.open != 10 $notdeleted
";
// Initialize page navigation
globalize($_REQUEST, array(
'perpage' => INT,
'pagenumber' => INT ));
if (!isset($limitlower))
{
$limitlower=0;
}
if ($perpage==0)
{
$perpage=20;
}
// Get the counts and work out the limits
$newscount=$DB_site->query_first($newsquery);
$totalrows=$newscount['count'];
sanitize_pageresults($totalrows, $pagenumber, $perpage, 200, $vboptions['maxthreads']);
$limitlower = ($pagenumber - 1) * $perpage;
$limitupper = ($pagenumber) * $perpage;
if ($limitupper > $totalrows)
{
$limitupper = $totalrows;
if ($limitlower > $totalrows)
{
$limitlower = ($totalrows - $perpage) - 1;
}
}
if ($limitlower < 0)
{
$limitlower = 0;
}
$pagenav = construct_page_nav($totalrows, "lobby.php?$session[sessionurl]", "&content=test&f=$f&pp=$perpage");
Notice that last line that sets up the page navigation links. 'lobby.php' is my original cmps_index page. 'content' is my new page variable. And I added f=$f to carry the forum id string around.
Now you are about to execute the original giant query. The last line needs to be replaced:
Find
ORDER BY " . iif($vboptions['stickynewsthreads'], 'sticky DESC,') . " postdateline DESC
$newslimit";
Replace with
ORDER BY " . iif($vboptions['stickynewsthreads'], 'sticky DESC,') . " postdateline DESC
LIMIT $limitlower, $perpage
The only thing left to do now is include the page navigation in the template. I took the shortcut, and slapped them in using the code. Something was running interference, I forget what, and it needed some more thinking. To be avoided at all costs of course. Or at least put off for another day.
So I concatenated the page blocks onto the front and back of the content in code:
Find
while ($news = $DB_site->fetch_array($getnews))
Replace
$home[$newsid]['content'] .= $pagenav;
while ($news = $DB_site->fetch_array($getnews))
Find
if ($showarchive AND $newsarchivebits)
Replace
$home[$newsid]['content'] .= $pagenav;
if ($showarchive AND $newsarchivebits)
Done. Pretty quick and gratifying, my favourite kind of hacking experience.
At this point the code for the module needs to be cleaned up: I don't think there's any point supporting archives.
But the basic plan is there, and it seems to be working great. I'm thrilled. For browsing forums where most all posts are small and have no replies, this is very cool. Or maybe just because you want to have paged news instead of the archive at the bottom
Appreciate hearing about other solutions of a similar nature.
Happy paging.
(In fact, when I first got vb, I was crestfallen to realize this was not something easily configurable).
vbadvanced to the rescue!
Here is a rough overview of the hack. Sorry, no detailed, carefully debugged, tested and perfected step by step instructions. I'm just wondering if I am wasting my time anyway. Maybe there is a better way to do this?
No screen snaps. It looks like your news pages, but the news block has forum page navigation at top and bottom. First,1,2,3, etc.
First and ugliest
If you went with the default "page variable" that comes with CMPS (default settings), this has to go. Because vb uses the variable "page" for paging. After experimenting, I changed my CMPS page variable to "content".
Make a copy of news.php
Either just backup while you test, or rename it and create a new module that uses it.
If you rename it, find
if ($omods['identifier'] == 'news' AND in_array($omods['modid'], explode(',', $pages['modules'])))
and replace 'news' with the new name. Say I saved news.php as quickies.php:
if ($omods['identifier'] == 'quickies' AND in_array($omods['modid'], explode(',', $pages['modules'])))
Optional next step. Which forums to pull posts out of? Currently I am looking at one module I can use for all forums, and providing a 'display mode' link so people can choose their preference. In this case the forum id is variable.
So I find:
unset($omods);
Add after:
globalize($_REQUEST,array('f'=>STR));
if ($_REQUEST['f'])
{
$vba_options['portal_news_forumid'] = $f;
}
Note you can still use mutliple forums, eg "23,4,51"
Next step: find the huge query statement. There's just one. Above it add:
// Strip down original query to get only a count
$newsquery =
"SELECT count(*) AS count
FROM " . TABLE_PREFIX . "thread AS thread
$deljoin
WHERE forumid IN($vba_options[portal_news_forumid]) AND thread.visible = 1 AND thread.open != 10 $notdeleted
";
// Initialize page navigation
globalize($_REQUEST, array(
'perpage' => INT,
'pagenumber' => INT ));
if (!isset($limitlower))
{
$limitlower=0;
}
if ($perpage==0)
{
$perpage=20;
}
// Get the counts and work out the limits
$newscount=$DB_site->query_first($newsquery);
$totalrows=$newscount['count'];
sanitize_pageresults($totalrows, $pagenumber, $perpage, 200, $vboptions['maxthreads']);
$limitlower = ($pagenumber - 1) * $perpage;
$limitupper = ($pagenumber) * $perpage;
if ($limitupper > $totalrows)
{
$limitupper = $totalrows;
if ($limitlower > $totalrows)
{
$limitlower = ($totalrows - $perpage) - 1;
}
}
if ($limitlower < 0)
{
$limitlower = 0;
}
$pagenav = construct_page_nav($totalrows, "lobby.php?$session[sessionurl]", "&content=test&f=$f&pp=$perpage");
Notice that last line that sets up the page navigation links. 'lobby.php' is my original cmps_index page. 'content' is my new page variable. And I added f=$f to carry the forum id string around.
Now you are about to execute the original giant query. The last line needs to be replaced:
Find
ORDER BY " . iif($vboptions['stickynewsthreads'], 'sticky DESC,') . " postdateline DESC
$newslimit";
Replace with
ORDER BY " . iif($vboptions['stickynewsthreads'], 'sticky DESC,') . " postdateline DESC
LIMIT $limitlower, $perpage
The only thing left to do now is include the page navigation in the template. I took the shortcut, and slapped them in using the code. Something was running interference, I forget what, and it needed some more thinking. To be avoided at all costs of course. Or at least put off for another day.
So I concatenated the page blocks onto the front and back of the content in code:
Find
while ($news = $DB_site->fetch_array($getnews))
Replace
$home[$newsid]['content'] .= $pagenav;
while ($news = $DB_site->fetch_array($getnews))
Find
if ($showarchive AND $newsarchivebits)
Replace
$home[$newsid]['content'] .= $pagenav;
if ($showarchive AND $newsarchivebits)
Done. Pretty quick and gratifying, my favourite kind of hacking experience.
At this point the code for the module needs to be cleaned up: I don't think there's any point supporting archives.
But the basic plan is there, and it seems to be working great. I'm thrilled. For browsing forums where most all posts are small and have no replies, this is very cool. Or maybe just because you want to have paged news instead of the archive at the bottom
Appreciate hearing about other solutions of a similar nature.
Happy paging.