Advertisement:

Author Topic: Thumbnail view of images in the administration center and unapproved images  (Read 1111 times)

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
By default only links are shown for image attachments accessed via Administration Center » Attachments and Avatars » Browse Files.  The following code change displays a thumbnail sized (ie, max 150px x 150px) view of images above the link.

In ./Sources/ManageAttachments.php:

Find:
Code: [Select]
global $modSettings, $context, $scripturl;

$link = \'<a href="\';

// In case of a custom avatar URL attachments have a fixed directory.
if ($rowData[\'attachment_type\'] == 1)
$link .= sprintf(\'%1$s/%2$s\', $modSettings[\'custom_avatar_url\'], $rowData[\'filename\']);

// By default avatars are downloaded almost as attachments.
elseif ($context[\'browse_type\'] == \'avatars\')
$link .= sprintf(\'%1$s?action=dlattach;type=avatar;attach=%2$d\', $scripturl, $rowData[\'id_attach\']);

// Normal attachments are always linked to a topic ID.
else
$link .= sprintf(\'%1$s?action=dlattach;topic=%2$d.0;attach=%3$d\', $scripturl, $rowData[\'id_topic\'], $rowData[\'id_attach\']);

$link .= \'"\';

// Show a popup on click if it\'s a picture and we know its dimensions.
if (!empty($rowData[\'width\']) && !empty($rowData[\'height\']))
$link .= sprintf(\' onclick="return reqWin(this.href\' . ($rowData[\'attachment_type\'] == 1 ? \'\' : \' + \\\';image\\\'\') . \', %1$d, %2$d, true);"\', $rowData[\'width\'] + 20, $rowData[\'height\'] + 20);

$link .= sprintf(\'>%1$s</a>\', preg_replace(\'~&amp;#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~\', \'&#\\\\1;\', htmlspecialchars($rowData[\'filename\'])));

// Show the dimensions.
if (!empty($rowData[\'width\']) && !empty($rowData[\'height\']))
$link .= sprintf(\' <span class="smalltext">%1$dx%2$d</span>\', $rowData[\'width\'], $rowData[\'height\']);

return $link;

Replace With:
Code: [Select]
global $modSettings, $context, $scripturl;

// Work out if this is an image.
$isImage = (!empty($rowData[\'width\']) && !empty($rowData[\'height\']));

// In case of a custom avatar URL attachments have a fixed directory.
if ($rowData[\'attachment_type\'] == 1)
$attLink = sprintf(\'%1$s/%2$s\', $modSettings[\'custom_avatar_url\'], $rowData[\'filename\']);

// By default avatars are downloaded almost as attachments.
elseif ($context[\'browse_type\'] == \'avatars\')
$attLink = sprintf(\'%1$s?action=dlattach;type=avatar;attach=%2$d\', $scripturl, $rowData[\'id_attach\']);

// Normal attachments are always linked to a topic ID.
else
$attLink = sprintf(\'%1$s?action=dlattach;topic=%2$d.0;attach=%3$d\', $scripturl, $rowData[\'id_topic\'], $rowData[\'id_attach\']);

$link = \'<a href="\' . $attLink . \'"\';

// Show a popup on click if it\'s a picture and we know its dimensions.
// Also show a thumbnail sized view of the image.
if ($isImage)
$link .= sprintf(\' onclick="return reqWin(this.href\' . ($rowData[\'attachment_type\'] == 1 ? \'\' : \' + \\\';image\\\'\') . \', %1$d, %2$d, true);"\', $rowData[\'width\'] + 20, $rowData[\'height\'] + 20) . sprintf(\'><img style="width: auto; height: auto; max-width: 150px; max-height: 150px;" src="\'. $attLink . \'"><br /\');

$link .= sprintf(\'>%1$s</a>\', preg_replace(\'~&amp;#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~\', \'&#\\\\1;\', htmlspecialchars($rowData[\'filename\'])));

// Show the dimensions.
if ($isImage)
$link .= sprintf(\' <span class="smalltext">%1$dx%2$d</span>\', $rowData[\'width\'], $rowData[\'height\']);

return $link;




A similar solution can also be implemented for unapproved attachments (with the addition of download links for all attachment types):

In ./Sources/PostModeration.php

Find:
Code: [Select]
// Get all unapproved attachments.
$request = $smcFunc['db_query']('', '
SELECT a.id_attach, a.filename,

Add After:
Code: [Select]
a.width, a.height,

Find:
Code: [Select]
$context['unapproved_items'][] = array(
'id' => $row['id_attach'],
'alternate' => $i % 2,
'filename' => $row['filename'],

Add After:
Code: [Select]
'isImage' => (!empty($row['width']) && !empty($row['height']) ? true : false),
'attLink' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'],


In ./Themes/default/ModerationCenter.template.php

Find:
Code: [Select]
<td>
', $item['filename'], '
</td>

Replace With:
Code: [Select]
<td>
', '<a href="' . $item['attLink'] . ($item['isImage'] ? ';image"><img style="width: auto; height: auto; max-width: 150px; max-height: 150px;" src="' . $item['attLink'] . '"><br />' : '">') . $item['filename'] . '</a>', '
</td>
Life doesn't have to be perfect to be wonderful ...

Offline Antechinus

  • SMF Friend
  • SMF Master
  • *
  • Posts: 25,650
  • Master of BBC Abuse
That's a good one. :)

Offline Steve

  • Freak
  • Support Specialist
  • SMF Hero
  • *
  • Posts: 4,733
  • Gender: Male
  • I have not yet begun to procrastinate.
Indeed. Nicely done GL.   :D
Please do not PM me for support.

I just ordered a life alert bracelet so
if I get a life, I'll be notified immediately.

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 23,411
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Great tip!
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
That's a good one. :)
Indeed. Nicely done GL.   :D
Great tip!
Thanks folks - might even make it a mod with independent settings to enable/disable the image view in the admin center and for unapproved image attachments.
Life doesn't have to be perfect to be wonderful ...

Offline Steve

  • Freak
  • Support Specialist
  • SMF Hero
  • *
  • Posts: 4,733
  • Gender: Male
  • I have not yet begun to procrastinate.
Thanks folks - might even make it a mod with independent settings to enable/disable the image view in the admin center and for unapproved image attachments.

That would be awesome. :D
Please do not PM me for support.

I just ordered a life alert bracelet so
if I get a life, I'll be notified immediately.

Offline efk

  • Jr. Member
  • **
  • Posts: 387
  • Gender: Male
Thanks folks - might even make it a mod with independent settings to enable/disable the image view in the admin center and for unapproved image attachments.

That would be awesome. :D
Something like this should be available on every forum.

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
Thanks folks - might even make it a mod with independent settings to enable/disable the image view in the admin center and for unapproved image attachments.

That would be awesome. :D
Mod submitted.

Actually, I've never used moderation before so I was really surprised to discover that by default only the name of unapproved attachments is shown - not even a link so that they can be downloaded/viewed.  How is a moderator supposed to see what the contents of an attachment are before they approve/delete it?
Life doesn't have to be perfect to be wonderful ...

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
How is a moderator supposed to see what the contents of an attachment are before they approve/delete it?
OK - found the answer - admins/moderators have to click on the message link in the 'Date' column to see the message the unapproved attachment(s) are attached to.
Life doesn't have to be perfect to be wonderful ...

Offline efk

  • Jr. Member
  • **
  • Posts: 387
  • Gender: Male
Yes it sucks, only text name is available and link after in Moderate/Unapproved Attachments. From what I've heard before the only way to remove attachment is in Admin/Forum/Attachments and Avatars, so once uploaded it actually takes memory but is removed from topic view. Can someone confirm if this is true? I think I tested that in past.

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
Re: Thumbnail view of images in the administration center and unapproved images
« Reply #10 on: December 19, 2020, 03:34:02 AM »
From what I've heard before the only way to remove attachment is in Admin/Forum/Attachments and Avatars ...
That's not correct - both unapproved and approved attachments can be deleted from the message they are attached to.

To delete approved attachments you have to modify the message and clear the checkbox next to the attachment name.

To delete unapproved attachments you can either use the method described above or, because unapproved attachments are also shown in their own approval box/section below the body of the message (and below other attachments that are approved), you can delete them directly from the approval box/section.

Quote
... so once uploaded it actually takes memory but is removed from topic view.
When an attachment is uploaded, and regardless of whether or not it's approved, it uses disk space.  Typically only admins and moderators with the relevant privileges/board access can see unapproved attachments.
Life doesn't have to be perfect to be wonderful ...

Offline Steve

  • Freak
  • Support Specialist
  • SMF Hero
  • *
  • Posts: 4,733
  • Gender: Male
  • I have not yet begun to procrastinate.
Re: Thumbnail view of images in the administration center and unapproved images
« Reply #11 on: December 25, 2020, 08:14:35 PM »
GL, I just tried this on my forum and I have to tell you it's a thing of beauty. Well done! :)
Please do not PM me for support.

I just ordered a life alert bracelet so
if I get a life, I'll be notified immediately.

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
Re: Thumbnail view of images in the administration center and unapproved images
« Reply #12 on: December 26, 2020, 02:03:06 AM »
GL, I just tried this on my forum and I have to tell you it's a thing of beauty. Well done! :)
Thanks!

In the mod I've submitted I've also added options for Admins and members to view thumbnail-sized images of attachments in member profiles.
Life doesn't have to be perfect to be wonderful ...

Offline GL700Wing

  • Full Member
  • ***
  • Posts: 656
  • Gender: Female
In the mod I've submitted I've also added options for Admins and members to view thumbnail-sized images of attachments in member profiles.
Mod approved - see Image Attachment Thumbnail View (Thumbnail View of Images in Admin Center/Member Profiles and Unapproved Attachments for Moderators)
Life doesn't have to be perfect to be wonderful ...

Offline Steve

  • Freak
  • Support Specialist
  • SMF Hero
  • *
  • Posts: 4,733
  • Gender: Male
  • I have not yet begun to procrastinate.
Please do not PM me for support.

I just ordered a life alert bracelet so
if I get a life, I'll be notified immediately.

Offline GigaWatt

  • The Smiley Guy
  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,341
  • Gender: Male
    • MechDR on GitHub
    • Macedonian electronics forum
Yes it sucks, only text name is available and link after in Moderate/Unapproved Attachments. From what I've heard before the only way to remove attachment is in Admin/Forum/Attachments and Avatars, so once uploaded it actually takes memory but is removed from topic view. Can someone confirm if this is true? I think I tested that in past.

Yes, it is. I had the same problem when deleting attachments, but in 1.1.x. If you remove the attachment directly from the post, the only thing that gets deleted is the link to the attachment in the DB, not the actual attachment (the file in the attachments). You had to do it manually from the admin panel ::). Though this was happening on a somewhat manually customized SMF 1.1.x forum, so the previous admin (not me) could've messed something up (never did found out if he did, since upgrading to 2.0.x was way overdue and I just did the upgrade), but still, I tried the same on 2.0.x and... well... the outcomes are unpredictable. In some cases, the attachment gets deleted, in others, it doesn't. Don't know what triggers some files to get deleted and others not... it could be the thumbs, from what little forensics I've done, but I'm not sure.

Oh, and even if you delete an image attachment in 2.0.x, even from the admin panel, if it has a thumb, guess what... it doesn't get deleted ::). Tried it a few time on a vanilla 2.0.15 install, nope, it doesn't delete the thumb ::).

SMF is a pretty good piece of forum software, but it's attachment management system is... not terrible, but it's not really great either. For example, no Search function for attachments in the Admin panel :o. I was like "What :o? I'm supposed to manually find, for example, a 3 year old attachment :o ;D?".

Not to mention orphaned attachments. Yes, there is a way to remove orphaned DB entries, but not orphaned attachments on disk. Basically, there is no way to find and remove them, except doing it manually... and by manually, I mean doing it through an upgrade to 2.1, which adds extensions to the attachments and then, the ones that don't have extensions are, naturally, orphaned ::). I was expecting something in the lines of "scan the DB for attachments, scan the attachments dir, compare results, present the files that don't exist in the DB as attachments, preferably scan MIME types as well, so that the admin knows what type of file it is, and an option to download them locally, so that the admin can view them, would also be nice ;)".
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."