News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Thumbnail view of images in the administration center and unapproved images

Started by GL700Wing, December 17, 2020, 05:38:06 AM

Previous topic - Next topic

GL700Wing

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:
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:
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:
// Get all unapproved attachments.
$request = $smcFunc['db_query']('', '
SELECT a.id_attach, a.filename,


Add After:
a.width, a.height,


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


Add After:
'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:
<td>
', $item['filename'], '
</td>


Replace With:
<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 ...


Steve

DO NOT pm me for support!

vbgamer45

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

GL700Wing

Quote from: Antechinus on December 17, 2020, 09:54:42 AM
That's a good one. :)
Quote from: Steve on December 17, 2020, 12:47:30 PM
Indeed. Nicely done GL.   :D
Quote from: vbgamer45 on December 17, 2020, 03:32:12 PM
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 ...

Steve

Quote from: GL700Wing on December 17, 2020, 04:00:38 PMThanks 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
DO NOT pm me for support!

efk

Quote from: Steve on December 18, 2020, 10:51:58 AM
Quote from: GL700Wing on December 17, 2020, 04:00:38 PMThanks 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.

GL700Wing

Quote from: Steve on December 18, 2020, 10:51:58 AM
Quote from: GL700Wing on December 17, 2020, 04:00:38 PMThanks 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 ...

GL700Wing

Quote from: GL700Wing on December 18, 2020, 09:16:33 PM
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 ...

efk

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.

GL700Wing

Quote from: efk on December 19, 2020, 01:12:40 AMFrom 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 ...

Steve

GL, I just tried this on my forum and I have to tell you it's a thing of beauty. Well done! :)
DO NOT pm me for support!

GL700Wing

Quote from: Steve 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! :)
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 ...

GL700Wing

Quote from: GL700Wing on December 26, 2020, 02:03:06 AM
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 ...

Steve

DO NOT pm me for support!

GigaWatt

Quote from: efk on December 19, 2020, 01:12:40 AM
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?"..."

Advertisement: