View Full Version : Get new posts within a certain forum, not all- how?
Ryan Little
02-27-2001, 01:44 AM
I want to search for new posts within a certain forum, but not within each and every forum.
Achieving that wasn't really that hard. In the old 1.1.X version it was a simple link. However with the new search engine the link wouldn't work anymore.
What I did is went in and look at the "GetNew" function in the search engine. This brings all the new posts for all forums the member can see. Too broad for this application.
So I changed it to:
// ###################### Start get latest #######################
if ($action=="getlatest") {
// generate query
// do it!
if ($bbuserinfo[userid]!=0 or $bbuserinfo[lastvisit]!=0) {
$forumsql=" AND forumid=$forumid";
// get date:
$datesql=" AND thread.lastpost>=".$bbuserinfo[lastvisit];
$wheresql="1=1".$forumsql.$datesql;
$wheresql.=" AND thread.open<>10";
if ($getsearch=$DB_site->query_first("SELECT searchid FROM search WHERE query='".addslashes($wheresql)."'")) {
$searchid=$getsearch[searchid];
} else {
// get last search for this user and check floodcheck
if ($prevsearch=$DB_site->query_first("SELECT searchid,dateline FROM search WHERE ".iif($bbuserinfo[userid]==0,"ipaddress='$ipaddress'","userid=$bbuserinfo[userid]")." ORDER BY dateline DESC LIMIT 1")) {
if (time()-$prevsearch[dateline]<$searchfloodcheck and $searchfloodcheck!=0) { // and !ismoderator()) {
eval("standarderror(\"".gettemplate("error_pmfloodcheck")."\");");
exit;
}
}
// insert query into db
$DB_site->query("INSERT INTO search (searchid,query,dateline,querystring,showposts,use rid,ipaddress) VALUES (NULL,'".addslashes($wheresql)."',".time().",'".addslashes($query)."',0,$bbuserinfo[userid],'".addslashes($ipaddress)."')");
$searchid=$DB_site->insert_id();
}
eval("standardredirect(\"".gettemplate("redirect_search")."\",\"search.php?s=$session[sessionhash]&action=showresults&getnew=true&searchid=$searchid\");");
} else {
$action="getdaily";
}
}
Copy the above code into search.php and you will be able to get the latest posts for a single forum.
The url to use would be:
http://www.yourforumdomain.com/pathtoforums/search.php?action=getlatest&forumid=XX
Where XX equals the forum. I simply stuck this in my "forumhome_forumbit_levelX_post" and "forumdisplay_forumbit_levelX_post" templates.
Thanks for the code wayne!
(dev team, is there a reason this isnt standard in v2?)
exactly what i need as well :D
wayne, how could i do it to get new posts from a number of forums? I don't mind hard coding it so setting an array in searchphp for say $stargate=3,4,63,23,53,34; and then search.php?group=stargate
would be fine but i am not quite sure how to.
Is it just a change of
$forumsql=" AND forumid=$forumid";
or do i need to do more?
Any update on this one?
I also need to search more than one forum (but not all) for new posts.
/j
I was about to ask for this, Wayne. :D I saw it on SitePoint and spent a while the other night trying to cobble together my own little version of it and failed miserably.
thx for the code. i needed that one
GimmeTech
05-01-2001, 06:00 AM
WLuke,
This function is fabulous and I having working. My question is if you meant to "change" the Get new as you mention on top or just "Copy the above code into search.php" as you mentioned below. I did the second of the two. I didn't change the Get New but added the new code underneath that part of the code. It works, I just wanted to see if having both of the codes in the search.php would cause any problems that you know of.
Thank You for sharing your knowledge.
the_sisko
05-01-2001, 08:48 PM
How can I protect my private forums???
Wayne Luke
06-08-2001, 11:55 PM
I forgot about this thread.
To get multiple forums you will have to pass multiple forums to the function...
Instead of 1 you would pass 1,2,3,4,5,6
You also have to change one line of the code...
Where it says:
$forumsql=" AND forumid=$forumid";
Change it to:
$forumsql=" AND forumid IN (0,$forumid)";
Hooper:
You did it correctly. I added a new function as well.
chrispadfield
06-10-2001, 10:44 AM
thanks wayne!
Wayne Luke
06-10-2001, 03:17 PM
Originally posted by The_Sisko
How can I protect my private forums???
PRivate forums are protected by vBulletin's permission system. If you have them set to hidden then the person can't access them or see them.
Lesane
12-21-2001, 04:12 PM
A litte bit late but thnx for the code :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.