MyBB Community Forums

Full Version: HELP PLEASE; RecentPostsIndex - Exclude certain FID
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using the recent posts plugin: http://mods.mybb.com/view/recent-posts-forum-index

I would like to exclude certain forums. Is there a way to enter in a line of code that would exclude certain forum fids?

The code:

<?php

//Latest Posts Board Index Mod by Borbole

//Trying to access directly the file, are we :D

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

//Hooking into index_start with our function
$plugins->add_hook("index_start", "recentposts_box");


//Show some info about our mod
function recentpostsindex_info()
{
	return array(
		"name"			=> "Recent Posts Forum Index",
		"description"	=> "It shows the recent posts on your board index.",
		"website"		=> "http://www.forumservices.eu/mybb",
		"version"		=> "1.0",
		"author"		=> "borbole",
		"authorsite"	=> "http://www.forumservices.eu/mybb",
		"compatibility"  => "16*",
		'guid'        => 'f8cd8d11a353a4f58a29fbc0d72ec9c3'
	);
}

//Activate it
function recentpostsindex_activate()
{
	global $db;
	
	//Insert the mod settings in the forumhome settinggroup. It looks beter there :D
	
	$query = $db->simple_select("settinggroups", "gid", "name='forumhome'");
	$gid = $db->fetch_field($query, "gid");
	
	
	$setting = array(
		'name' => 'enable',
		'title' => 'Recent Posts Forum Index',
		'description' => 'Would you like to display the Recent Posts Box at your board index?',
		'optionscode' => 'yesno',
		'value' => '1',
		'disporder' => '90',
		'gid' => intval($gid)
	);
	$db->insert_query('settings',$setting);
	
	$setting = array(
		"name" => "limit_posts_nr",
		"title" => "Recent Posts!",
		"description" => "Enter here the number of the recent posts that you would like to show at the forum index. By default it set to show 5 posts.",
		"optionscode" => "text",
		"value" => "5",
		"disporder" => "91",
		"gid" => intval($gid),
		);
	$db->insert_query("settings", $setting);	
	
	rebuild_settings();
	
   //Add our custom var in the index template to display the latest posts box
   require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

   find_replace_templatesets("index", "#".preg_quote('{$header}') . "#i", '{$header}' . "\n" . '{$recentposts}');

}


//Don't want to use it anymore? Let 's deactivate it then and drop the settings and the custom var as well

function recentpostsindex_deactivate()
{
	global $db;
	
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='enable'");	
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='limit_posts_nr'");

rebuild_settings();	
	
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

find_replace_templatesets("index", "#".preg_quote('{$header}' . "\n" . '{$recentposts}') . "#i", '{$header}',0);

}


//Insert our function 
function recentposts_box()
{
	global $db, $mybb, $lang, $theme, $recentposts;
	
	//Enable it
    if($mybb->settings['enable'] == 1 )
	{
	    //Load the language files and set up the table for the recent posts box
	    $lang->load('recentpostsindex');

	    $recentposts .= '
		<table width=100% cellspacing=1 cellpadding=0>
            
           ';

	    //Preserve the forum viewing permissions intact
		
		$fids = "";
        $unviewablefids = get_unviewable_forums();
		
        if($unviewablefids)
        {
            $fids = "WHERE t.fid NOT IN ({$unviewablefids})";
        }
        
		//Exclude inactive forums from showing up
		
		$inactivefids = get_inactive_forums();
	    if ($inactivefids)
		{
		    $fids .= " WHERE t.fid NOT IN ($inactivefids)";
	    }		
		
       			 


        //Run the query to get the most recent posts along with their posters, time and forums
		
	   $query = $db->query("
	   SELECT t.tid, t.fid, t.subject, t.lastpost, 
	   t.lastposter, t.lastposteruid, f.name,
	   u.usergroup, u.displaygroup
	   FROM ".TABLE_PREFIX."threads AS t
       INNER JOIN ".TABLE_PREFIX."forums as f
	   ON (f.fid = t.fid)
	   LEFT JOIN " . TABLE_PREFIX . "users AS u 
	   ON (t.lastposteruid = u.uid)
	   {$fids}
	   AND t.visible = '1'
	   GROUP BY t.tid
	   ORDER BY t.lastpost DESC 
	   LIMIT " . $mybb->settings['limit_posts_nr']);
	
	    while($row = $db->fetch_array($query))
	    {
		   $recentposts .= '
		   <tr>';
		   
		   //Trim the thread titles if they are over 49 characters
		   
		   $subject = htmlspecialchars_uni($row['subject']);
		   
		   if (strlen($subject) > 25)
		   {
	          $subject = substr($subject, 0, 25) . "..."; 
		   }
		   
		   //Trim the usernames if they are over 9 characters
		   
		   if (strlen($row['lastposter']) > 15)
		   {
	          $row['lastposter'] = substr($row['lastposter'], 0, 15) . "..."; 
		   }
		   
		    //Trim the forum names if they are over 19 characters so everything will be in porpotion
		   if (strlen($row['name']) > 25)
		   {
	          $row['name'] = substr($row['name'], 0, 25) . "..."; 
		   }
		   
		   //Get the date and time of the most recent posts
		   
		   $lastpostdate = my_date($mybb->settings['dateformat'], $row['lastpost']);
		   $lastposttime = my_date($mybb->settings['timeformat'], $row['lastpost']);
		   $postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost'], '', 0);


		   //Get the usernames and make them pretty too with the group styling
		   
		   $username = build_profile_link(format_name($row['lastposter'],$row['usergroup'],$row['displaygroup']), $row['lastposteruid']);
		   
		   //Display them all trimmed up and pretty :D
		   
		   $recentposts .= '
		   <td width=60% class="' . $row['name'] . '"><div class="trow1" style="padding:5px;">

		      <a href="showthread.php?tid=' . $row['tid'] . '&amp;action=lastpost">' . $subject .'</a> <small><i>...by ' . $username . '</i></small>
		 </div>  </td>
		   
		   
		   <td class="' . $row['name'] . '"><div class="trow1" style="padding:5px;">
<CENTER>
		       <a href="forumdisplay.php?&amp;fid=' . $row['fid'] . '">' . $row['name'] . '</a> </div>
		   </CENTER> </td>

		   <td class="' . $row['name'] . '">
		  <div class="trow1" style="padding:5px;"><CENTER>
 ' .$postdate. '   </CENTER>
		  </div> </td>
		   
		   
		  </tr>';
	    }
          
		  //End of mod. I hope you enjoy it as much as I did coding it :)
		  
          $recentposts .= "</tbody></table><br /><br />";

   }

}

?>
Here is my website if it helps to get an idea of what I am trying to do. If you look on the page where it says RP Posts it lists all the right forums that are located under the category 'Roleplay'

Now I would like to show all OOC posts that are located under the category OOC to show up on the bottom part of the page where it says 'Recent OOC Posts'

http://www.aurial.net/rpg/blackstone
Edit: please ignore replacement code. see post #5

replace below code

$query = $db->query("
       SELECT t.tid, t.fid, t.subject, t.lastpost,
       t.lastposter, t.lastposteruid, f.name,
       u.usergroup, u.displaygroup
       FROM ".TABLE_PREFIX."threads AS t
       INNER JOIN ".TABLE_PREFIX."forums as f
       ON (f.fid = t.fid)
       LEFT JOIN " . TABLE_PREFIX . "users AS u
       ON (t.lastposteruid = u.uid)
       {$fids}
       AND t.visible = '1'
       GROUP BY t.tid
       ORDER BY t.lastpost DESC
       LIMIT " . $mybb->settings['limit_posts_nr']);

with
$query = $db->query("
       SELECT t.tid, t.fid, t.subject, t.lastpost,
       t.lastposter, t.lastposteruid, f.name,
       u.usergroup, u.displaygroup
       FROM ".TABLE_PREFIX."threads AS t
       INNER JOIN ".TABLE_PREFIX."forums as f
       ON (f.fid = t.fid)
       LEFT JOIN " . TABLE_PREFIX . "users AS u
       ON (t.lastposteruid = u.uid)
       {$fids}
       AND t.visible = '1'
       GROUP BY t.tid
       AND t.fid NOT IN(A,B,C,D)
       ORDER BY t.lastpost DESC
       LIMIT " . $mybb->settings['limit_posts_nr']);


added code AND t.fid NOT IN(A,B,C,D) where A,B,C,D are forum IDs. (can be any number of forums separated by comma)
Thank you for your help,

I have replaced the code with said code, and it seems to work but it only includes one topic from that specific forum...not sure why that is. And when I add more fid it will show one other topic that is in another forum in that specific fid...not sure why but its strange and a little hard to explain.
please change the code to
$query = $db->query("
       SELECT t.tid, t.fid, t.subject, t.lastpost,
       t.lastposter, t.lastposteruid, f.name,
       u.usergroup, u.displaygroup
       FROM ".TABLE_PREFIX."threads AS t
       INNER JOIN ".TABLE_PREFIX."forums as f
       ON (f.fid = t.fid)
       AND t.fid NOT IN(A,B,C,D)
       LEFT JOIN " . TABLE_PREFIX . "users AS u
       ON (t.lastposteruid = u.uid)
       {$fids}
       AND t.visible = '1'
       GROUP BY t.tid
       ORDER BY t.lastpost DESC
       LIMIT " . $mybb->settings['limit_posts_nr']); 

where A,B,C,D are forum IDs. (can be any number of forums separated by comma)
Perfect! Thank you for all your help this is just what I needed my board looks so much better with this done. I really appreciate the time you took! I am linking this topic on my forum as well as my RPG resource for others who may have been in the same boat. Again thanks so much!!

Regards,
Leah