I own a student's forum, where there's a topic for each subject.
In each topic, people can post attachments, like book summaries or lecture notes releted to that subject.
The problem is that if someone is looking for an attached summary, he has to scroll down and read each post in order to find those posts which contain the attachments.
So, I'd like to have a block, next to each topic, which lists all the attachments published in that topic (and only in that topic).
In this way, if I need help with "History", I can read the topic about that subject and, at the same time, I can see a clickable list of all the published files about "History", immediately available for downloading, even if I don't want to read the whole topic.
Is this possible to do?
Hi airali,
Welcome to the TinyPortal Support Site.
You can render a block in a specific board or in a specific article or even with a specific action, but, at this time, there is no way to show a block in just a specific topic. Sorry.
ZarPrime
What about this SMF mod? Attachments in Topics (http://custom.simplemachines.org/mods/index.php?mod=2285)
Thank you for your reply.
Quote from: lurkalot on January 27, 2013, 09:37:54 AM
What about this SMF mod? Attachments in Topics (http://custom.simplemachines.org/mods/index.php?mod=2285)
I had tried this mod, but it shows attachments in a pop-up window, not in a block. Also, you can open pop-up window only from the board page, where all topics are listed, clicking on an icon next to each topic title, before you open the topic.
Do you think it is possible to move the pop-up code to a block in some way, so that pop-up content is shown in the block, in the topic page?
Also: do you think that other systems, like simpleportal, have the feature I need?
Update: problem solved.
- I installed Attachments in Topics (http://custom.simplemachines.org/mods/index.php?mod=2285)
- I created a block "php code" with the following code:
global $smcFunc, $topic, $txt, $context, $modSettings;
// if (empty($topic))
// fatal_lang_error('not_a_topic', false);
// Get the Number of Replies with Attachments
$id_msg = array();
$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);
global $context, $settings, $options, $txt;
echo ' <div class="padding windowbg">';
global $context, $settings, $options, $txt, $scripturl, $topic;
// 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
if ($windowclass == "windowbg")
$windowclass = "windowbg2";
else
$windowclass = "windowbg";
}
echo'</table>';
}
else
echo '</div>';
echo ' </div>
</div>';
- I set it to be viewed only in all boards (or in some board.. it's the same).
- The layout is good if you position the block in the header, otherwise you may want to make some changes.
I think the code not to be "nice and clean" because I don't know anything of php ::), I managed to do this only by trial and error. If someone wants to check and clean it I could then post it in "Block codes and snippets" section.
However.. it works!
You beat me to it.
Was wondering if this could be adapted to work in a block. Glad you got it working. I'm no coder, so one of the other guys would need to take a look at your code to make sure it's ok. Provided they have the time to do so of course. ;)
Looks good to me, I would have used commas when echoing but that's my preference. Some say it is slightly faster, but you probably wouldn't notice it.
You do seem to have two loose closing DIV tags at the end that do not appear to close anything....
Your code looks great. Cleaned up just a few small things. Concatenating strings is actually faster. But for such a minor thing, it doesn't really matter in this case IMO.
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>';
Awesome!
I tested it and it's ok. I'm going to publish that in snippets.
Thank you all for your help!
(It's the first time that I find a support community really active and helping :) )
Quote from: IchBin™ on January 28, 2013, 08:00:20 PM
Concatenating strings is actually faster.
Using period is faster ? I read the opposite...
Airali, thanks for the block code, very nice :)
Take a read here Freddy. These are the types of posts I've read in the past. The speed difference is very marginal. But if you had a big application, it would probably make quite a difference. The first answer on this page gives some pretty good info.
http://stackoverflow.com/questions/13620/speed-difference-in-using-inline-strings-vs-concatenation-in-php5
Thanks, learnt something new O0