Welcome, Guest. Please login or register.
Did you miss your activation email?
April 24, 2014, 04:58:03 AM

Login with username, password and session length

Last 25 Topics



Note:  Clicking the link above will open a new tab in your browser !!

Recent

Members
  • Total Members: 3400
  • Latest: tvl
Stats
  • Total Posts: 173440
  • Total Topics: 19804
  • Online Today: 80
  • Online Ever: 278
  • (October 31, 2012, 08:52:18 AM)
Users Online
Users: 1
Guests: 66
Total: 67

Donate

Help us to keep the support site
going, Please consider a small donation.

Thank you
Please read the Posting Guidelines

Author Topic: [Block] Topic attachments list  (Read 1233 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',
array(
'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'],
);
}
$smcFunc['db_free_result']($dbrequest);

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>
<td width="20" align="center">
<b>'. $txt['attachments_size']. '</b>
</td>
<td width="20" align="center">
<b>'. $txt['downloads']. '</b>
</td>
</tr>';

// 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>
<td align="center">
'. $attach['size']. '
</td>
<td align="center">
'. $attach['downloads']. '
</td>
</tr>';

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

echo'
</table>';
}

echo '
</div>';

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