MyBB Community Forums

Full Version: search (get) New Post from special forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi my friend
i want add a link to "forumbit_depth2_forum" template and when anyone click on thah link in index page , get new post of that forum !

can anyone give me that code ?
thank .
Hi,

In the template you should be able to add:

<a href="search.php?action=getnew&fid={$forum['fid']}">View New Posts</a>

It should show results for that forum only.
I had to change two things for i got it to work with a specific fid. When i didn't changed a thing i got a sql error
mySQL error: 1064
You have an error in your SQL syntax near '' at line 1
Query: SELECT f.fid FROM mybb_forums f LEFT JOIN mybb_forumpermissions p ON (f.fid=p.fid AND p.gid='4') WHERE INSTR(CONCAT(',',parentlist,','),',13,') > 0 AND (ISNULL(p.fid) OR (p.cansearch='yes' AND p.canview='yes')

In the action = "getnew" (search.php)

if($mybb->input['fid']) became if(!$mybb->input['fid'])

And in the wheresql i needed to add f.fid='".$mybb->input['fid']."'
i use that code but i receive this SQL error too :

mySQL error: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query: SELECT f.fid FROM mybb_forums f LEFT JOIN mybb_forumpermissions p ON (f.fid=p.fid AND p.gid='4') WHERE INSTR(CONCAT(',',parentlist,','),',22,') > 0 AND (ISNULL(p.fid) OR (p.cansearch='yes' AND p.canview='yes')

can you solve this for me ?!
i cant understand mean of LeX-messenge !
thank!
Open search.php

Find

elseif($mybb->input['action'] == "getdaily")

Add above

elseif($mybb->input['action'] == "newspecforum")
{
	if(!$mybb->input['days'] < 1)
	{
		$days = 1;
	}
	else
	{
		$days = intval($mybb->input['days']);
	}

	$wheresql = "1=1";
	$wheresql .= " AND f.fid='".$mybb->input['fid']."' AND t.lastpost BETWEEN '".$mybb->user[lastvisit]."' AND '".time()."'";
	$searcharray = array(
		"uid" => $mybb->user['uid'],
		"dateline" => time(),
		"ipaddress" => $ipaddress,
		"wheresql" => addslashes($wheresql),
		"lookin" => "p.message",
		"showposts" => 1
		);
	$plugins->run_hooks("search_do_search_process");
	$db->insert_query(TABLE_PREFIX."searchlog", $searcharray);
	$sid = $db->insert_id();

	eval("\$redirect = \"".$templates->get("redirect_searchresults")."\";");
	redirect("search.php?action=results&sid=$sid", $lang->redirect_searchresults);
}

Then if you add in that template

<a href="search.php?action=newspecforum&fid={$forum['fid']}">View New Posts</a>

It should work =P
tnx LeX-.
this work ! but must change "eval("$redirect = \"".$templates->get("redirect_searchresults")."\";");" to "eval("\redirect = \"".$templates->get("redirect_searchresults")."\";");"

and i have a question :
can you change above code to this :
if forum Contain new post then show "View New Posts" link in index page ! else not show any link !
can you make this ?
thank.
mehdi_rm_666m Wrote:tnx LeX-.
this work ! but must change "eval("$redirect = \"".$templates->get("redirect_searchresults")."\";");" to "eval("\redirect = \"".$templates->get("redirect_searchresults")."\";");"

and i have a question :
can you change above code to this :
if forum Contain new post then show "View New Posts" link in index page ! else not show any link !
can you make this ?
thank.

Open index.php

Find

$altonoff = $lang->new_posts;

Add below

						$newposts = "<a href=\"search.php?action=newspecforum&fid={$forum['fid']}\">View New Posts</a>";

Then open that same template (forumbit_depth2_forum) and add $newposts in the place of the link you've added earlier. When there are new posts in a forum the icon changes, that's were i've added when to show the link for the new posts, seems to me the easiest way Wink
This code allows sql injection as you do not verify the content of the variable $mybb->input['fid'] to be a number.
To fix this search for:
$wheresql .= " AND f.fid='".$mybb->input['fid']."' AND t.lastpost BETWEEN '".$mybb->user[lastvisit]."' AND '".time()."'";
Add above:
$mybb->input['fid'] = intval($mybb->input['fid']);