TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 07:57:27 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 143
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 77
  • Total: 77

[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.

airali

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',
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 :) )