Advertisement:

Author Topic: Show attachments (or links) in Recent Posts like templates.  (Read 4023 times)

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Show attachments (or links) in Recent Posts like templates.
« on: March 08, 2011, 04:43:31 AM »
I'm wondering if it's trivial / just a theme option to increase attachment visibility by including the attachment like download links in the likes of the Recent Posts page.

It's hard to tell, but the $context variable thru which stuff is served seems like it might be, well different, in different contexts. I suspect it might be limited anyway to what the core query code expects is required on any given page.

Is there a way to get at the attachments in this context anyway? Or would they have to be pulled directly from the DB?

Thanks always,

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,123
    • StoryBB/StoryBB on GitHub
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #1 on: March 08, 2011, 09:42:23 AM »
They would have to be pulled from the database first since they're not loaded there at all. Then you'd have to add the code into the template to display them.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #2 on: March 09, 2011, 12:52:09 AM »
Can you (or anyone) suggest best way to do that from within the theme template code?

Please.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,123
    • StoryBB/StoryBB on GitHub
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #3 on: March 09, 2011, 06:48:25 AM »
Well, the whole point of the system is that you shouldn't be putting logic in primarily presentational code.

What exactly are you trying to display where in the template?
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #4 on: March 10, 2011, 08:56:21 AM »
Querying the DB is probably no big deal unless it's very cache optimized.

The idea is attachments are important. I mainly use the Recent Posts view to read any BBS. It's the only way I find to be sure not to miss out on anything. I encourage others to do the same. It's very convenient too. The only problem is that you get no indicator of attachments in these types of views. And again attachments are very important.

So in short it seems like a real deficit on SMF's part. I'm just trying to get the job done.

What exactly? The Recent.template.php file needs to be able to display attachment download links/descriptions at the bottom of the post message, like they are in the thread view. Previews like thumbnails are probably not desirable because they'd in theory chew up bandwidth / make the page longer than it already is. So they can be left out.

I may be wrong, but I think the other "digest" views are handled in the same template.

Thanks

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,123
    • StoryBB/StoryBB on GitHub
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #5 on: March 10, 2011, 09:06:10 AM »
Quote
Querying the DB is probably no big deal unless it's very cache optimized.

It's not a *huge* deal to do, certainly, but it does add some load to the page.

Interesting, from all the people I've spoken to here, very few use recent posts to manage what they've read - many by far use unread/unreadreplies to manage them, but that's just my experience. The idea is that recent posts is simply a quick view of the most recent posts, rather than presenting them in the full context (a la in thread)

Quote
I may be wrong, but I think the other "digest" views are handled in the same template.

Which digest views, exactly? Unread/unreadreplies isn't, at least not the same direct template function because they have a totally different layout (much closer to the thread listing, rather than the recent layout) but just for fun, the same files handle all of them (Recent.php / Recent.template.php)

This is why I'm asking what you're trying to do, to be specific, because I'm trying to get to the position where you write the code in as few places as possible. If you put it into the template, there's up to three places to put it to get the data and display it, more if you plan on having this be supported across multiple themes...

Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #6 on: March 13, 2011, 09:20:17 AM »
Quote
Querying the DB is probably no big deal unless it's very cache optimized.

It's not a *huge* deal to do, certainly, but it does add some load to the page.

Interesting, from all the people I've spoken to here, very few use recent posts to manage what they've read - many by far use unread/unreadreplies to manage them, but that's just my experience. The idea is that recent posts is simply a quick view of the most recent posts, rather than presenting them in the full context (a la in thread)

I don't personally trust to use the "viewed" post framework, because it's not really reliable (in that the user may've actually done something else) and is anyway, quite scattered. It's easier to see everything in a list. If you're following the threads more or less anyway, it's a very quick/easy way to stay catched up with everything and be sure not to miss anything. The context is usually known, if you want to reply, you can jump to the thread from the recent view to do so. Beats clicking around a bunch of pages hands down. From a power user pov nothing comes close.

For forums with many boards / languages, being able to filter the recent posts page to just the boards you follow would be a great builtin feature. It's not too hard to implement from a theme pov however. Assuming filtering at the presentation level is good enough.

Quote
Quote
I may be wrong, but I think the other "digest" views are handled in the same template.

Which digest views, exactly? Unread/unreadreplies isn't, at least not the same direct template function because they have a totally different layout (much closer to the thread listing, rather than the recent layout) but just for fun, the same files handle all of them (Recent.php / Recent.template.php)

This is why I'm asking what you're trying to do, to be specific, because I'm trying to get to the position where you write the code in as few places as possible. If you put it into the template, there's up to three places to put it to get the data and display it, more if you plan on having this be supported across multiple themes...

I think you have the right thing in mind. I was just saying they are all in the same theme file I think. They are in separate functions. So assuming so you'd just want to add a query function to that file, that can be called from inside each of the different template functions.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,123
    • StoryBB/StoryBB on GitHub
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #7 on: March 13, 2011, 09:48:11 AM »
Quote
I don't personally trust to use the "viewed" post framework, because it's not really reliable (in that the user may've actually done something else) and is anyway, quite scattered.

Except it's organised by topic while recent posts isn't. On a smaller forum, it's possible to follow, but on a forum of any real size it's not because you can't track what you've actually seen before or not.

Quote
So assuming so you'd just want to add a query function to that file, that can be called from inside each of the different template functions.

Apart from the fact it violates the first principle of SMF's design to do that (separate core logic from presentation), there are (much) more efficient ways of doing it than randomly shoving it into the template even in its own function. Especially since it's only going to be called from the recent template, not the unread/unreadreplies ones.

Code: (Recent.php, find this code) [Select]
// There might be - and are - different permissions between any and own.
Code: (Before it, add this) [Select]
// Get any attachments of these posts.
$posts = array_keys($context['posts']);
$query = $smcFunc['db_query']('', '
SELECT id_attach, id_msg, filename
FROM {db_prefix}attachments
WHERE id_msg IN ({array_int:posts})
AND attachment_type = 0
AND id_member = 0',
array(
'posts' => $posts,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
{
if (!isset($context['posts'][$row['id_msg']]['attachments']))
$context['posts'][$row['id_msg']]['attachments'] = array();
$context['posts'][$row['id_msg']]['attachments'][] = array(
'filename' => $row['filename'],
'href' => $scripturl . '?action=dlattach;topic=' . $context['posts'][$row['id_msg']]['topic'] . '.0;attach=' . $row['id_attach'],
);
}
$smcFunc['db_free_result']($query);

That takes care of getting the information. I'm not sure how you want to display it exactly, so I'm going to make the assumption that it's a simple list of items, e.g. "Attachments: file1.zip, file2.zip"

Code: (Recent.template.php, find this code) [Select]
echo '
<span class="botslice clear"><span></span></span>
</div>';

Code: (Before it, add this) [Select]
if (!empty($post['attachments']))
{
echo '
<div>Attachments: ';

$first = true;
foreach ($post['attachments'] as $attach)
{
if (!$first)
echo ', ';
echo '<a href="', $attach['href'], '">', $attach['filename'], '</a>';
}

echo '
</div>';
}

Not tested but should work.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #8 on: March 15, 2011, 11:11:20 AM »
^Will give it a try.

PS: I do intend to include the attachments in the unread/replies listing as well. Attachments are a very essential part of a post. And should be visible for administration purposes. I'm assuming it's an oversight they are not included (which will eventually be fixed)

I would still read a massive forum via the recent posts view if I was considerably invested in it. Otherwise I rely upon either notifications, or finding my own posts via my profile view / leaving tabs open in browsers. The problem with tracking viewed posts is it's easy to technically view a post but neglect to read it. Then it becomes a blind spot you'd never see again, and that can lead to misunderstandings if someone assumes you read it. That's irresponsible in my opinion, so I consider it unreliable.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,123
    • StoryBB/StoryBB on GitHub
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #9 on: March 15, 2011, 11:13:59 AM »
Quote
I'm assuming it's an oversight they are not included.

Hardly, see my quote.

That takes care of getting the information. I'm not sure how you want to display it exactly, so I'm going to make the assumption that it's a simple list of items, e.g. "Attachments: file1.zip, file2.zip"

Quote
I would still read a massive forum via the recent posts view if I was considerably invested in it.

Doesn't really work in practice on an actually busy forum like this one. I tried it for a month, just to see whether it was viable, but I ended up missing posts and not being aware of what I'd read etc. Bear in mind that when I was part of the team I was making up to 5,000 posts per month.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #10 on: April 10, 2011, 01:18:56 AM »
Hi again....

I've been really distracted the last few weeks. I'm resolved anyway to get this done tomorrow.

I would like to just toss something out there in the hope an answer might manifest in the meantime (I realize it's the weekend)

I would feel a lot more comfortable if everything was inside Recent.template.php (versus Recent.php) ... is there a quick changeroo for that? I realize it may incur some overhead. But I'd prefer to keep everything in the theme. Especially so updates don't become problematic.

Also if that can be done. Is there a simple check that can be done at the top, in order to detect if future versions have already filled out the necessary fields? Would hate to be doing this twice or breaking something, should someone here decide attachments are as much a part of a post as everything else (I mean, it's not as if the recent posts are displayed as excerpts)

Thanks / please staff, consider making this a non-issue in the future. Make it an "Attachments and Avatars" setting if necessary 8)

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #11 on: April 10, 2011, 09:44:05 PM »
@Arantor,

The changes worked fine. Thanks a lot.

FYI: In your example, $first is never modified. And I'm curious myself if the two very similar lines in the following code is intentional...

Quote
Code: [Select]
if (!isset($context['posts'][$row['id_msg']]['attachments']))
$context['posts'][$row['id_msg']]['attachments'] = array();
$context['posts'][$row['id_msg']]['attachments'][] = array(

For the record, appears to work fine with the second line commented out.

I would not mind having the file size in the query at least also. If anyone has that on the tip of their tongue, I would appreciate it ::)
« Last Edit: April 10, 2011, 09:47:25 PM by I Agree »

Offline I Agree

  • Jr. Member
  • **
  • Posts: 186
Re: Show attachments (or links) in Recent Posts like templates.
« Reply #12 on: April 10, 2011, 11:20:07 PM »
Hello again,


In a post I saw today (which I was pointed  to) something was mentioned...

Quote
This mod works soley off of SMF's integration hooks that are only available in RC4+.

I'm wondering myself if I can add hooks to my install to do the "recent.php" stuff that won't affect the sources code itself.

That would be the best of all possible worlds O:) O:)