This is how I set up the forum block in the "Forum Blocks Manager":
This is the PHP code:
PHP Code:
global $vbulletin, $db;
$number_of_attachments = 5;
$output = '';
$last_attachments = $vbulletin->db->query_read_slave("
SELECT attachment.*, user.*, post.postid, post.threadid, thread.title, filedata.filesize
FROM " . TABLE_PREFIX . "attachment
INNER JOIN " . TABLE_PREFIX . "user
ON user.userid = attachment.userid
INNER JOIN " . TABLE_PREFIX . "post
ON post.postid = attachment.contentid
INNER JOIN " . TABLE_PREFIX . "thread
ON thread.threadid = post.threadid
INNER JOIN " . TABLE_PREFIX . "filedata
ON filedata.filedataid = attachment.filedataid
ORDER BY attachment.dateline DESC
LIMIT " . $number_of_attachments
);
$n = 0;
while ($attachment = $db->fetch_array($last_attachments))
{
$output .= '<div';
if ($n++)
{
$output .= ' style="border-top: 1px solid #CCCCCC"';
}
$output .= '>Posted By: <div style="display: inline-block">' . attach_user_link($attachment) . '</div><div title="Uploaded: ' . vbdate($vbulletin->options['dateformat'], $attachment['dateline'], 1) . ' at ' . vbdate($vbulletin->options['timeformat'], $attachment['dateline']) . PHP_EOL . 'Views: ' . $attachment['counter'] . PHP_EOL . 'Size: ' . number_format($attachment['filesize']/1024,1) . ' KB">' . $attachment['filename'] . '</div><a title="Go To Post With Attachment" href="showthread.php?' . $attachment['threadid'] . '-' . str_replace(' ', '-', $attachment['title']) . '&p=' . $attachment['contentid'] . '&viewfull=1#post' . $attachment['contentid'] . '">' . $attachment['title'] . '</a></div>';
}
return $output;
function attach_user_link($user_name)
{
global $vbulletin;
$link = 'member.php?do=getinfo&username=' . $user_name['username'];
if ($user_name['displaygroupid'])
{
$groupid = $user_name['displaygroupid'];
}
else
{
$groupid = $user_name['usergroupid'];
}
$open_tag = $vbulletin->usergroupcache[$groupid]['opentag'];
$close_tag = $vbulletin->usergroupcache[$groupid]['closetag'];
return '<a title="Go To ' . $user_name['username'] . '\'s Profile" href="' . $link . '">' . $open_tag . $user_name['username'] . $close_tag . '</a>';
}
And this is the result on my local dev site:
The usernames are shown in their usergroup HTML markup, and link to their profiles. The attachment filename has a tooltip that shows when it was uploaded, the number of views and the size of the file (in KB).
Below the filename is a link to the post containing the attachment.
You can edit the PHP code, the second line, to change the number of most recent attachments to display...replace the "5" with whatever positive integer you want.
Please let me know of any changes you would like.