HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media


Welcome to TinyPortal. Please login or sign up.

May 23, 2024, 09:44:22 AM

Login with username, password and session length
  • Total Posts: 195,197
  • Total Topics: 21,221
  • Online today: 56
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 70
  • Total: 71
  • @rjen

[Block] Topic attachments list

Started by airali, January 28, 2013, 10:49:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Name of Snippet: Attachments in topic block
SMF/TP versions tested:: SMF 2.0.2
Block Type:: php
Author: ssboforum
Other Requirements: Attachments in topic mod
Description: While Attachments in topic mod shows the attachment list only in a pop-up, this code allows to view the same list in a block.
It's a list of links to each attachment posted in the current topic. There are also: a little icon that links to the post where the file has been attached, file size and downloads number.
Layout is optimized for viewing in header position, but with a few changes to the code you can easily adapt it for other positions.

Note that, at this time, you cannot set the block to be viewed only in topic with attachments. The best you can do is setting it to be viewed "in all boards" (or in some boards), unchecking "view in all pages and sections".
Still you'll see it in board index and in topics without attachments; in these pages, the block becomes a narrow light empty rectangle.

global $smcFunc, $topic, $txt, $context, $scripturl, $settings;

// Get the Number of Replies with Attachments
$dbrequest = $smcFunc['db_query']('', '
SELECT a.filename, a.size, a.downloads, a.id_attach, a.id_msg
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}attachments AS a ON (a.id_msg = m.id_msg)
WHERE m.id_topic = {int:topic_id}
  AND a.attachment_type = {int:attach_type}
  AND a.approved = {int:is_approved}
ORDER BY a.id_attach',
'attach_type' => 0,
'topic_id' => $topic,
'is_approved' => 1,
while($row = $smcFunc['db_fetch_assoc']($dbrequest)) {
$context['attachments'][] = array(
'id_attach' => $row['id_attach'],
'downloads' => $row['downloads'],
'filename' => $row['filename'],
'size' => round($row['size'] / 1024, 2) . ' ' . $txt['debug_kb'],
'id_msg' => $row['id_msg'],

echo '
<div class="padding windowbg">';

// Let's see the attachments
if(!empty($context['attachments'])) {
echo '
<table width="100%">
<tr class="titlebg">
<td width="60">
<b>'. $txt['attachment_in_topic']. '</b>
<td width="20" align="center">
<b>'. $txt['attachments_size']. '</b>
<td width="20" align="center">
<b>'. $txt['downloads']. '</b>

// Now let's set the default class and show the attachs
$windowclass = "windowbg";
foreach($context['attachments'] as $attach) {
echo '
<tr class="',$windowclass,'">
<td align="left" width="60">
<a href="'. $scripturl. '?action=dlattach;topic='. $topic. '.0;attach='. $attach['id_attach']. '" title="'. $txt['attachment_download']. '">'. $attach['filename']. '</a>
<a href="'. $scripturl. '?topic='. $topic. '.msg'. $attach['id_msg']. '#msg'. $attach['id_msg']. '" title="'. $txt['attachment_go']. '" target="_blank"><img src="'. $settings['images_url']. '/split_select.gif" alt="'. $txt['attachment_go']. '" valign="middle" /></a>
<td align="center">
'. $attach['size']. '
<td align="center">
'. $attach['downloads']. '

// Change the class for the next attach
$windowclass = ($windowclass == 'windowbg' ? 'windowbg2' : 'windowbg');


echo '

(Note for moderators: english is not my motherlanguage, I hope my description is understandable, otherwise you can correct it :) )