2014-06-07, 10:43 PM
Could you help me to pool the latest threads from forums in the category?
To save time here you have some code to work with:
To save time here you have some code to work with:
<?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 User's Threads in Profile",
"description" => "",
"website" => "http://my-bb.ir",
"author" => "AliReza_Tofighi edit by Supryk",
"authorsite" => "http://my-bb.ir",
"version" => "1.00",
"guid" => "d0ed7e9cd568bf8806067c016b480be4",
"compatibility" => "*",
);
}
function threadinfid()
{
global $db, $mybb, $memprofile, $theme, $lang, $threadinfid;
$threadlimit = 5;
$query = $db->query("
SELECT t.*, t.subject AS threadsubject, u.username, u.usergroup, u.displaygroup,
t.dateline AS threaddate, t.lastpost AS threadlastpost
FROM ".TABLE_PREFIX."threads t
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.lastpost DESC
LIMIT 0, {$threadlimit}
");
while($threads = $db->fetch_array($query))
{
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'].' ';
$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;
}
?>