Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media


Welcome, Guest. Please login or register.
Did you miss your activation email?

August 12, 2022, 08:36:41 AM

Login with username, password and session length
  • Total Members: 3842
  • Latest: Kokoro
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 50
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 44
Total: 44

Author Topic: [Block] Topic attachments list  (Read 4980 times)

0 Members and 1 Guest are viewing this topic.

Offline airali

  • Jr. Member
  • **
  • Posts: 5
[Block] Topic attachments list
« on: January 28, 2013, 03:49:04 PM »
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.

Code: [Select]
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 :) )