Need a query to fetch threads with most replies?
#11
Hi, is there a way to make your plugin pull latest threads from the category?

I would like to include latest threads in the category that has 5 forums?
Reply
#12
Hi marcus

try this

<?php
/**
 * MyBB 1.6
 * Copyright 2012 My-BB.Ir Group, All Rights Reserved
 *
 * Website: http://my-bb.ir
 *
 * $Id: mybbirlastthreadsprofile.php AliReza_Tofighi $
 */
 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("forumdisplay_start", "threadinfid");


function threadinfid_info()
{
	return array(
		"name"			=> "Last Threads in in forums",
		"description"	=> "",
		"website"		=> "http://my-bb.ir",
		"author"		=> "AliReza_Tofighi edit by Supryk",
		"authorsite"	=> "http://my-bb.ir",
		"version"		=> "1.00",
		"guid" 			=> "",
		"compatibility" => "*",
	);
}


function threadinfid()
{
	global $db, $mybb, $memprofile, $theme, $lang, $threadinfid, $forumsinfo;
	$threadlimit = 5;
	$query = $db->query("
		SELECT t.*, t.subject AS threadsubject, u.username, u.usergroup, u.displaygroup, i.*, i.name AS iconname,
		t.dateline AS threaddate, t.lastpost AS threadlastpost
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."icons i ON (i.iid=t.icon)
		LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
		LEFT JOIN ".TABLE_PREFIX."users u ON (t.lastposter=u.username)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (t.fid=f.fid)
		WHERE ".threadinfid_build_where()." AND ".intval($mybb->input['fid'])." IN(f.parentlist)
		GROUP BY t.tid
		ORDER BY t.replies DESC
		LIMIT 5
	");
/*	$query = $db->query("
		SELECT t.*, t.subject AS threadsubject, u.username, u.usergroup, u.displaygroup, i.*, i.name AS iconname,
		t.dateline AS threaddate, t.lastpost AS threadlastpost
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."icons i ON (i.iid=t.icon)
		LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
		LEFT JOIN ".TABLE_PREFIX."users u ON (t.lastposter=u.username)
		WHERE ".threadinfid_build_where()." AND t.fid = ".intval($mybb->input['fid'])."
		GROUP BY t.tid
		ORDER BY t.replies DESC
		LIMIT 5
	");*/

	while($threads = $db->fetch_array($query))
	{
echo $threads['parentlist'];
		if($threads['icon'] > 0)
		{
			$icon = "<img src=\"{$threads['path']}\" alt=\"{$threads['iconname']}\" title=\"{$threads['iconname']}\" />";
		}
		else
		{
			$icon = "&nbsp;";
		}

		if(strlen($threads['threadsubject']) > "40")
		{
			$threadsthreadsubject = my_substr($threads['threadsubject'],0,40)."...";
		}
		else
		{
			$threadsthreadsubject = $threads['threadsubject'];
		}

		if(strlen($threads['forumname']) > "20")
		{
			$threadsforumname = my_substr($threads['forumname'],0,20)."...";
		}
		else
		{
			$threadsforumname = $threads['forumname'];
		}

		$threadlink = get_thread_link($threads['tid']);
		$forumlink = get_forum_link($threads['fid']);
		$replies = my_number_format($threads['replies']);
		$views = my_number_format($threads['views']);
		$threadprefix = build_prefixes($threads['prefix']);
		$prefix = $threadprefix['displaystyle'].'&nbsp;';
		$lastpostdate = my_date($mybb->settings['dateformat'], $threads['threadlastpost']);
		$lastposttime = my_date($mybb->settings['timeformat'], $threads['threadlastpost']);
		$lastposter = format_name($threads['username'], $threads['usergroup'], $threads['displaygroup']);
		$lastposter = build_profile_link($lastposter, $threads['lastposteruid']);

		$last_thread .= "<tr>
			<td class=\"trow2\">$prefix<a href=\"$threadlink\" title=\"$threads[threadsubject]\">$threadsthreadsubject</a></td>
			<td class=\"trow1\" align=\"center\">$replies</td>
			<td class=\"trow2\" align=\"center\">$views</td>
			<td class=\"trow1\"><span class=\"smalltext\">$lastpostdate $lastposttime<br />Ostatni post: $lastposter</span></td>
	</tr>";

	}
	if(!$last_thread){
		$last_thread = "<tr><td class=\"trow1\" colspan=\"5\">Ten użytkownik nie napisał jeszcze żadnego tematu</td></tr>";
	}
	$threadinfid = "<br /><table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
			<tr>
				<td class=\"thead\" colspan=\"6\"><strong>Ostatnie tematy</strong></td>
			</tr>
				<tr>
					<td class=\"tcat\" width=\"45%\"><span class=\"smalltext\"><strong>Temat</strong></span></td>
					<td class=\"tcat\" width=\"10%\" align=\"center\"><span class=\"smalltext\"><strong>Odpowiedzi</strong></span></td>
					<td class=\"tcat\" width=\"10%\" align=\"center\"><span class=\"smalltext\"><strong>Wyświetleń</strong></span></td>
					<td class=\"tcat\" width=\"30%\" align=\"center\"><span class=\"smalltext\"><strong>Ostatni post</strong></span></td>
				</tr>
			<tbody>
			{$last_thread}
			</tbody>
		</table>";
}

function threadinfid_build_where()
{
    static $where;

    if ($where != '')
    {
        return $where;
    }
    $where = "t.visible = 1 AND t.closed NOT LIKE 'moved|%'";
    $onlyusfids = array();
    $group_permissions = forum_permissions();
    foreach ($group_permissions as $fid => $forum_permissions)
    {
        if ($forum_permissions['canonlyviewownthreads'] == 1)
        {
            $onlyusfids[] = $fid;
        }
    }
    if (!empty($onlyusfids))
    {
        $where .= " AND ((t.fid IN(" . implode(',', $onlyusfids) . ") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(" . implode(',', $onlyusfids) . "))";
    }
    if (!function_exists('get_unsearchable_forums'))
    {        
        if (THIS_SCRIPT == 'index.php')
        {
            global $permissioncache;
            $permissioncache = false;
        } 
        require_once MYBB_ROOT."inc/functions_search.php";   
        $unsearchforums = get_unsearchable_forums();
        if ($unsearchforums)
        {                              
            $where .= " AND t.fid NOT IN ($unsearchforums)";
        }   
    }
    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
    {
        $where .= " AND t.fid NOT IN ($inactiveforums)";
    } 
    return $where;
}

?>

And this will be work in forums and categories

<?php
/**
 * MyBB 1.6
 * Copyright 2012 My-BB.Ir Group, All Rights Reserved
 *
 * Website: http://my-bb.ir
 *
 * $Id: mybbirlastthreadsprofile.php AliReza_Tofighi $
 */
 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("forumdisplay_start", "threadinfid");


function threadinfid_info()
{
	return array(
		"name"			=> "Last Threads in in forums",
		"description"	=> "",
		"website"		=> "http://my-bb.ir",
		"author"		=> "AliReza_Tofighi edit by Supryk",
		"authorsite"	=> "http://my-bb.ir",
		"version"		=> "1.00",
		"guid" 			=> "",
		"compatibility" => "*",
	);
}


function threadinfid()
{
	global $db, $mybb, $memprofile, $theme, $lang, $threadinfid, $forumsinfo;
	$threadlimit = 5;
	$query = $db->query("
		SELECT t.*, t.subject AS threadsubject, u.username, u.usergroup, u.displaygroup, i.*, i.name AS iconname,
		t.dateline AS threaddate, t.lastpost AS threadlastpost, f.parentlist, f.fid
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."icons i ON (i.iid=t.icon)
		LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
		LEFT JOIN ".TABLE_PREFIX."users u ON (t.lastposter=u.username)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (t.fid=f.fid)
		WHERE ".threadinfid_build_where()." AND ".intval($mybb->input['fid'])." IN(f.parentlist) OR t.fid = ".intval($mybb->input['fid'])."
		GROUP BY t.tid
		ORDER BY t.replies DESC
		LIMIT 5
	");

	while($threads = $db->fetch_array($query))
	{
echo $threads['parentlist'];
		if($threads['icon'] > 0)
		{
			$icon = "<img src=\"{$threads['path']}\" alt=\"{$threads['iconname']}\" title=\"{$threads['iconname']}\" />";
		}
		else
		{
			$icon = "&nbsp;";
		}

		if(strlen($threads['threadsubject']) > "40")
		{
			$threadsthreadsubject = my_substr($threads['threadsubject'],0,40)."...";
		}
		else
		{
			$threadsthreadsubject = $threads['threadsubject'];
		}

		if(strlen($threads['forumname']) > "20")
		{
			$threadsforumname = my_substr($threads['forumname'],0,20)."...";
		}
		else
		{
			$threadsforumname = $threads['forumname'];
		}

		$threadlink = get_thread_link($threads['tid']);
		$forumlink = get_forum_link($threads['fid']);
		$replies = my_number_format($threads['replies']);
		$views = my_number_format($threads['views']);
		$threadprefix = build_prefixes($threads['prefix']);
		$prefix = $threadprefix['displaystyle'].'&nbsp;';
		$lastpostdate = my_date($mybb->settings['dateformat'], $threads['threadlastpost']);
		$lastposttime = my_date($mybb->settings['timeformat'], $threads['threadlastpost']);
		$lastposter = format_name($threads['username'], $threads['usergroup'], $threads['displaygroup']);
		$lastposter = build_profile_link($lastposter, $threads['lastposteruid']);

		$last_thread .= "<tr>
			<td class=\"trow2\">$prefix<a href=\"$threadlink\" title=\"$threads[threadsubject]\">$threadsthreadsubject</a></td>
			<td class=\"trow1\" align=\"center\">$replies</td>
			<td class=\"trow2\" align=\"center\">$views</td>
			<td class=\"trow1\"><span class=\"smalltext\">$lastpostdate $lastposttime<br />Ostatni post: $lastposter</span></td>
	</tr>";

	}
	if(!$last_thread){
		$last_thread = "<tr><td class=\"trow1\" colspan=\"5\">Ten użytkownik nie napisał jeszcze żadnego tematu</td></tr>";
	}
	$threadinfid = "<br /><table border=\"0\" cellspacing=\"".$theme['borderwidth']."\" cellpadding=\"".$theme['tablespace']."\" class=\"tborder\">
			<tr>
				<td class=\"thead\" colspan=\"6\"><strong>Ostatnie tematy</strong></td>
			</tr>
				<tr>
					<td class=\"tcat\" width=\"45%\"><span class=\"smalltext\"><strong>Temat</strong></span></td>
					<td class=\"tcat\" width=\"10%\" align=\"center\"><span class=\"smalltext\"><strong>Odpowiedzi</strong></span></td>
					<td class=\"tcat\" width=\"10%\" align=\"center\"><span class=\"smalltext\"><strong>Wyświetleń</strong></span></td>
					<td class=\"tcat\" width=\"30%\" align=\"center\"><span class=\"smalltext\"><strong>Ostatni post</strong></span></td>
				</tr>
			<tbody>
			{$last_thread}
			</tbody>
		</table>";
}

function threadinfid_build_where()
{
    static $where;

    if ($where != '')
    {
        return $where;
    }
    $where = "t.visible = 1 AND t.closed NOT LIKE 'moved|%'";
    $onlyusfids = array();
    $group_permissions = forum_permissions();
    foreach ($group_permissions as $fid => $forum_permissions)
    {
        if ($forum_permissions['canonlyviewownthreads'] == 1)
        {
            $onlyusfids[] = $fid;
        }
    }
    if (!empty($onlyusfids))
    {
        $where .= " AND ((t.fid IN(" . implode(',', $onlyusfids) . ") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(" . implode(',', $onlyusfids) . "))";
    }
    if (!function_exists('get_unsearchable_forums'))
    {        
        if (THIS_SCRIPT == 'index.php')
        {
            global $permissioncache;
            $permissioncache = false;
        } 
        require_once MYBB_ROOT."inc/functions_search.php";   
        $unsearchforums = get_unsearchable_forums();
        if ($unsearchforums)
        {                              
            $where .= " AND t.fid NOT IN ($unsearchforums)";
        }   
    }
    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
    {
        $where .= " AND t.fid NOT IN ($inactiveforums)";
    } 
    return $where;
}

?>
My Plugins

PM only paid support
Reply
#13
@Supryk my man you are awesome thanks very much love ya.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)