MyBB Community Forums

Full Version: get_unviewable_forums() and get_inactive_forums()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

i create simple plugin to show latest user thread in his profile (tabs)
in portal php is ready-made solution, I use it in my plugin

function ostatnie_tematy()

{
    global $mybb, $db, $templates, $theme, $ostatnie_tematy, $memprofile, $parser, $forum_cache;
    
    $altbg = alt_trow();
    $ostatnie_tematy_row = "";
    $memprofileuid = $memprofile['uid'];
    
    // get forums user cannot view
    $unviewable = get_unviewable_forums(true);
    if($unviewable)
    {
        $unviewwhere = " AND fid NOT IN ($unviewable)";
        $tunviewwhere = " AND t.fid NOT IN ($unviewable)";
    }
    else
    {
        $unviewwhere = '';
    }

    // get inactive forums
    $inactive = get_inactive_forums();
    if($inactive)
    {
        $inactivewhere = " AND fid NOT IN ($inactive)";
        $tinactivewhere = " AND t.fid NOT IN ($inactive)";
    }
    else
    {
        $inactivewhere = '';
    }
/*
    $excludeforums = '';
    if(!empty($mybb->settings['portal_excludediscussion']))
    {
        $excludeforums = "AND t.fid NOT IN ({$mybb->settings['portal_excludediscussion']})";
    }
    */

    $query = $db->query("
        SELECT t.tid, t.fid, t.uid, t.subject, t.replies, t.views, t.dateline, t.firstpost, p.pid, p.message
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."posts p ON (t.firstpost=p.pid)
        WHERE 1=1 AND t.uid={$memprofileuid} {$excludeforums}{$tunviewwhere}{$tinactivewhere} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.dateline DESC
        LIMIT 0, 5
    ");
    while($thread = $db->fetch_array($query))
    {
        $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
        $thread['threadlink'] = get_thread_link($thread['tid']);
        $thread['dateline'] = my_date('relative', $thread['dateline']);
        require_once MYBB_ROOT."inc/class_parser.php";
        $parser = new postParser;
        $parser_options = array("allow_html" => 0, "allow_mycode" => 1, "allow_smilies" => 1, "allow_imgcode" => 1, "allow_videocode" => 1, "filter_badwords" => 1);
        $thread['message'] = $parser->parse_message($thread['message'], $parser_options); 
        eval("\$ostatnie_tematy_row .= \"".$templates->get("ostatnie_tematy_row")."\";");
        $altbg = alt_trow();
    }
//    if(!$ostatnie_tematy_row)
//    {
//        eval("\$ostatnie_tematy_row = \"".$templates->get("ostatnie_tematy_row_empty")."\";");
//    }
    
    eval("\$ostatnie_tematy = \"".$templates->get("ostatnie_tematy")."\";");
    return $ostatnie_tematy;
}

but
get_unviewable_forums not work, guest can see thread from forums when thay don't have permissions
get_inactive_forums(); is OK
You should use get_unsearchable_forums. That's what I use for my Recent Threads on Index Plugin.
that fix my problem, thanks
why you in your plugin use double forum_permissions();, this variable is used one time $fpermissions

	$fpermissions = forum_permissions();
	$onlyusfids = array();
		// Check group permissions if we can't view threads not started by us
		$group_permissions = forum_permissions();
Left over code. I don't recall if the get_unsearchable_forums function actually checks if they can only view their own thread or not. I actually aim to submit a new build later today.