Post and PM Inline Attachments

Started by dougiefresh, July 26, 2014, 09:14:08 PM

Previous topic - Next topic

GL700Wing

A little tweak for this mod when used in conjunction with Custom View of Attachments to display the information about attachments that are not inline in the same way it is displayed for attachments that are inline (ie, using ellipsis for long names, displaying size and dimensions for images, setting maximum horizontal width for non-image attachments, and displaying attachment information on second line) and displaying approve/delete links on third line:

In ./Sources/Subs-CustomView.php
Find:
if ($modSettings['custom_view_attachments'] != 2)
{
$title = $attachment['name'];
$name = $attachment['width'] < $modSettings['attachmentThumbWidth'] ? $smcFunc['substr']($attachment['name'], 0, round($attachment['width']/7, 0)) : $smcFunc['substr']($attachment['name'], 0, round($modSettings['attachmentThumbWidth']/7, 0));
echo '
<img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" />&nbsp;<a href="' . $attachment['href'] . '" title="' . $title . '">' . $name . '</a> ';
}
}
else
echo '

<img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" />&nbsp;<a href="' . $attachment['href'] . '">' . $attachment['name'] . '</a><br />';

if (!$attachment['is_approved'])
echo '
[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>]&nbsp;|&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';


if (!$attachment['is_image'])
echo '(' . $attachment['size'] . ' ~ ' . (!$attachment['is_image'] ? $txt['custom_view_attachments_downloads'] : $txt['custom_view_attachments_views']) . $attachment['downloads'] . ')';


Replace With:
if ($modSettings['custom_view_attachments'] != 2)
echo '
<span style="display:block; ' . 'width:' . ($attachment['width'] > 0 ? (!empty($modSettings['attachmentThumbWidth']) && $modSettings['attachmentThumbWidth'] < $attachment['width'] ? $modSettings['attachmentThumbWidth'] : $attachment['width']) : 150) . 'px;">
<img class="ila_img" src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" />
<a class="ila_link" href="' . $attachment['href'] . '" title="' . $attachment['name'] . '">' . $attachment['name'] . '</a></span><br /><span>
<span class="ila_span" style="margin-top:-1.5em;">(', $attachment['size'] . ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ')</span>';
}
else
echo '
<span style="display:block; ' . 'max-width:' . (!empty($modSettings['attachmentThumbWidth']) ? $modSettings['attachmentThumbWidth'] : 150) . 'px;">
<img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" />&nbsp;
<a class="ila_link" style="margin-top:-2.0em;" href="' . $attachment['href'] . '" title="' . $attachment['name'] . '">' . $attachment['name'] . '</a></span><br />' .
($modSettings['custom_view_attachments'] != 2 ? '<span class="ila_span" style="margin-top:-1.5em;">(' . $attachment['size'] . ' ~ ' . $txt['custom_view_attachments_downloads'] . $attachment['downloads'] . ')</span>' : '');

if (!$attachment['is_approved'])
echo '
[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>]&nbsp;|&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';




Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

dougiefresh

Uploaded v6.10 - April 3rd, 2018
o Per GL700Wing's post, modified Custom Views of Attachments mod to match attachment viewing modifications.




@GL700Wing:  Busy little beaver you are!  Thanks again for the code contributions!  They've been included in this version!

pepa

Hi Dougie

I'm running version 6.8 on SMF 2.0.15 Responsive Curve 1.0.0

Do I need to uninstall before installing the latest update for the Mod?

Also a problem ... I checked the option "Should first attachment should be numbered "1"?", clicked OK, but when I clicked save at the bottom I received the error message in the attached file.  I haven't installed the PM Attachments Mod as I didn't want that functionality ... is that the source of this error and do I need to be concerned?


GL700Wing

Quote from: pepa on April 25, 2018, 04:47:48 AM
I'm running version 6.8 on SMF 2.0.15 Responsive Curve 1.0.0

Do I need to uninstall before installing the latest update for the Mod?
Yes.

QuoteAlso a problem ... I checked the option "Should first attachment should be numbered "1"?", clicked OK, but when I clicked save at the bottom I received the error message in the attached file.
I've been helping Doug with some of his mods and I've just fixed this problem today - just waiting for him to let me know if I can update the mod on his behalf.

QuoteI haven't installed the PM Attachments Mod as I didn't want that functionality ... is that the source of this error and do I need to be concerned?
The error is caused by a bug in this mod and it prevents the renumbering of image attachments in existing messages - in V6.11 you will need to disable/save then re-enable/save the the Should first attachment should be numbered "1"? option for renumbering of image attachments in existing messages to occur.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

pepa

Thanks GL700Wing : )  Guess I'll wait for the next updated mod with the error fixed before I uninstall and then install the latest version.

GL700Wing

Uploaded v6.11 - April 27th, 2018
o As per pepa's post fixed issue that was causing change of Should first attachment should be numbered "1"? option to throw error for SQL query.
o For SMF 2.0: Re-added code to display a label if an attachment in a post which is being edited is awaiting approval.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

@rjen

Problem with the new version: EVERY attachment is now numbered as attachment 0...

Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

Find the dutch language files attached...
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

GL700Wing

v6.12 - April 28th, 2018
o Per @rjen - added Dutch language files.
o Added UTF8 language files for English.




Thanks @rjen for the Dutch language files.

Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

GL700Wing

Quote from: @rjen on April 27, 2018, 11:13:01 AM
Problem with the new version: EVERY attachment is now numbered as attachment 0...
This issue was caused by a bug in v5.0 of the Automatic Attachment Rotation (and Resize) mod and has been fixed in v5.1.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

BellGab.com

Thanks for continuing to develop this.

Beowulf1976

OK, so first off, I am pretty sure *I* have made this error by not reading the readme.txt before installing and running "Automatic Attachment Rotation (and Resize)"


I already had Post and PM Inline Attachments mod installed.... all my inline attachments were working just fine...


but when I installed your attachment resize mod, I now have some very borked attachments. (apologies in advance for the next four lines of text!)


Some people report that the images are resized nicely and they can see them whilst logged in, and not logged in.
Some people report that whether they are logged in or not, they see "invalid attachment" (yet when I modify the post they talk about, your image attachment coding is still there and looks fine)
Some people report that they can only see the images when logged in, and cannot when logged out.
Some people report that they can only see the images when NOT logged in, and "invalid attachment" is there when logged in.


I have asked all testers to erase their cache to ensure that either problem is not being caused by cache.

When looking in the error logs, I have over 100k errors that state there is an issue with:
8: Undefined index: thumb_hash
File: *******************/forum/Sources/Display.php
Line: 1825

First the entire section of coding so you know what you're looking at:

// End Automatic Attachment Rotation (and Resize) mod.


$attachmentData[$i]['real_width'] = $attachment['width'];
$attachmentData[$i]['width'] = $attachment['width'];
$attachmentData[$i]['real_height'] = $attachment['height'];
$attachmentData[$i]['height'] = $attachment['height'];


// Let's see, do we want thumbs?
if (!empty($modSettings['attachmentThumbnails']) && !empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachment['width'] > $modSettings['attachmentThumbWidth'] || $attachment['height'] > $modSettings['attachmentThumbHeight']) && strlen($attachment['filename']) < 249)
{
// A proper thumb doesn't exist yet? Create one!
if (empty($attachment['id_thumb']) || $attachment['thumb_width'] > $modSettings['attachmentThumbWidth'] || $attachment['thumb_height'] > $modSettings['attachmentThumbHeight'] || ($attachment['thumb_width'] < $modSettings['attachmentThumbWidth'] && $attachment['thumb_height'] < $modSettings['attachmentThumbHeight']))
{
$filename = getAttachmentFilename($attachment['filename'], $attachment['id_attach'], $attachment['id_folder']);


require_once($sourcedir . '/Subs-Graphics.php');
if (createThumbnail($filename, $modSettings['attachmentThumbWidth'], $modSettings['attachmentThumbHeight']))
{
// So what folder are we putting this image in?
if (!empty($modSettings['currentAttachmentUploadDir']))
{
if (!is_array($modSettings['attachmentUploadDir']))
$modSettings['attachmentUploadDir'] = safe_unserialize($modSettings['attachmentUploadDir']);
$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
}
else
{
$path = $modSettings['attachmentUploadDir'];
$id_folder_thumb = 1;
}


// Calculate the size of the created thumbnail.
$size = @getimagesize($filename . '_thumb');
list ($attachment['thumb_width'], $attachment['thumb_height']) = $size;
$thumb_size = filesize($filename . '_thumb');


// These are the only valid image types for SMF.
$validImageTypes = array(1 => 'gif', 2 => 'jpeg', 3 => 'png', 5 => 'psd', 6 => 'bmp', 7 => 'tiff', 8 => 'tiff', 9 => 'jpeg', 14 => 'iff');


// What about the extension?
$thumb_ext = isset($validImageTypes[$size[2]]) ? $validImageTypes[$size[2]] : '';


// Figure out the mime type.
if (!empty($size['mime']))
$thumb_mime = $size['mime'];
else
$thumb_mime = 'image/' . $thumb_ext;


$thumb_filename = $attachment['filename'] . '_thumb';
$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);


// Add this beauty to the database.
$smcFunc['db_insert']('',
'{db_prefix}attachments',
array('id_folder' => 'int', 'id_msg' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'size' => 'int', 'width' => 'int', 'height' => 'int', 'fileext' => 'string', 'mime_type' => 'string'),
array($id_folder_thumb, $id_msg, 3, $thumb_filename, $thumb_hash, (int) $thumb_size, (int) $attachment['thumb_width'], (int) $attachment['thumb_height'], $thumb_ext, $thumb_mime),
array('id_attach')
);
$old_id_thumb = $attachment['id_thumb'];
$attachment['id_thumb'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
if (!empty($attachment['id_thumb']))
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}attachments
SET id_thumb = {int:id_thumb}
WHERE id_attach = {int:id_attach}',
array(
'id_thumb' => $attachment['id_thumb'],
'id_attach' => $attachment['id_attach'],
)
);


$thumb_realname = getAttachmentFilename($thumb_filename, $attachment['id_thumb'], $id_folder_thumb, false, $thumb_hash);
rename($filename . '_thumb', $thumb_realname);


// Do we need to remove an old thumbnail?
if (!empty($old_id_thumb))
{
require_once($sourcedir . '/ManageAttachments.php');
removeAttachments(array('id_attach' => $old_id_thumb), '', false, false);
}
}
}
}
else
$thumb_realname = getAttachmentFilename($attachment['thumb_name'], $attachment['id_thumb'], $attachment['thumb_folder'], false, $attachment['thumb_hash']);


// Get timestamp for thumbnail image:
$time = !empty($thumb_realname) && file_exists($thumb_realname) ? filemtime($thumb_realname) : false;


// Only adjust dimensions on successful thumbnail creation.
if (!empty($attachment['thumb_width']) && !empty($attachment['thumb_height']))
{
$attachmentData[$i]['width'] = $attachment['thumb_width'];
$attachmentData[$i]['height'] = $attachment['thumb_height'];
}
}


if (!empty($attachment['id_thumb']))
$attachmentData[$i]['thumbnail'] = array(
'id' => $attachment['id_thumb'],
'href' => $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attachment['id_thumb'] . ';image' . ';ts=' . $time,
);
$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);


// If thumbnails are disabled, check the maximum size of the image.
if (!$attachmentData[$i]['thumbnail']['has_thumb'] && ((!empty($modSettings['max_image_width']) && $attachment['width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachment['height'] > $modSettings['max_image_height'])))
{
if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $attachment['height'] * $modSettings['max_image_width'] / $attachment['width'] <= $modSettings['max_image_height']))
{
$attachmentData[$i]['width'] = $modSettings['max_image_width'];
$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
}
elseif (!empty($modSettings['max_image_width']))
{
$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
$attachmentData[$i]['height'] = $modSettings['max_image_height'];
}
}
elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
{
// If the image is too large to show inline, make it a popup.
if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
else
$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
}


if (!$attachmentData[$i]['thumbnail']['has_thumb'])
$attachmentData[$i]['downloads']++;
}
}


// Do we need to instigate a sort?
if ($have_unapproved)
usort($attachmentData, 'approved_attach_sort');


return $attachmentData;
}


// A sort function for putting unapproved attachments first.
function approved_attach_sort($a, $b)
{
if ($a['is_approved'] == $b['is_approved'])
return 0;


return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
}



Then, the actual line where the error is supposedly:


1825: $thumb_realname = getAttachmentFilename($attachment['thumb_name'], $attachment['id_thumb'], $attachment['thumb_folder'], false, $attachment['thumb_hash']);


I haven't remotely tried to fix anything because I'm thick af when it comes to all this...


and like I said, this COULD be an issue I have caused myself by NOT doing what your readme.txt file says prior to resizing current attachments.


Is there a way I can fix this, without going into each individual post and re-attributing the attachment to its coding (ie re-inserting them again)

(as far as I can tell, all the images are still attached at the bottom of the posts, they're just not positioned inline)


I'm not lazy, I have 2,222 posts to go through and 595 attachments to find :P :D


I hope you can help me, and not tell me off too much.
"Them as can do has to do for them as can't. And someone has to speak up for them as has no voices."

GL700Wing

Did you uninstall the Post and PM Inline Attachments mod before installing the latest version of this mod (ie, the version that includes the resize feature)?
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Beowulf1976

#793
They are completely different mods. They do different things.


I have the mods pictured below.

Neither of them say that they replace the other.


However, the readme.txt file in the autoattach gives instructions for the post and pm inline attachments mod before "activating" the auto attachment resize mod. I am afraid I did my usual and didn't read the readme, because I never expected to find that one borked the other if I didn't do as it says in the readme.


If you read my post thoroughly it explains all this. :) (I think it does, I have aphasia - so even though I've been using the English language for 40+ years, I now struggle sometimes as if it is a foreign language. So if I haven't explained it clearly, I am sorry.)




I have a desperate fight between getting people to use the forum and them being lazy Facebook goers and using Facebook to view images instead. IF I cannot get this fixed I will lose that fight and the $30 a month I pay for hosting and website builder will all be for nought. *sob*


A NEW image that someone posted today has "invalid Attachment" in its place for some people. I KNOW I probably caused this myself but I was hoping for help with a way to fix it?
"Them as can do has to do for them as can't. And someone has to speak up for them as has no voices."

GL700Wing

QuoteThey are completely different mods. They do different things.
They are the same mod - the latest version includes the automatic resizing feature.

You should uninstall both versions in the reverse/opposite order to which you installed them and then reinstall only the latest version.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Beowulf1976

#795
Quote from: GL700Wing on June 07, 2018, 10:49:43 PM
QuoteThey are completely different mods. They do different things.
They are the same mod - the latest version includes the automatic resizing feature.

You should uninstall both versions in the reverse/opposite order to which you installed them and then reinstall only the latest version.

They are not the same mod, considering I have lost my inline attachments option!


Now I cannot reinstall the inline attachments mod because of a multitude of test failed. Cheers, it seems to have broken my forum. My authors are not going to be pleased that their images are no longer inline and I cannot fix it.
"Them as can do has to do for them as can't. And someone has to speak up for them as has no voices."

Beowulf1976

I am restoring the database and uploading my backup to resort back to both mods still being installed and running. When I said that they were not the same, I meant they are not the same. If they were the same, then the inline attachments option would be available in the "newer mod", but it's not. Therefore they are not the same mod.
"Them as can do has to do for them as can't. And someone has to speak up for them as has no voices."

Beowulf1976

arggghh no, now all the images are corrupt. Like proper stripey messes. :'(
"Them as can do has to do for them as can't. And someone has to speak up for them as has no voices."

GL700Wing

@Beowulf1976 - please accept my apologies for the confusion caused by my previous replies.  I misread your posts and misunderstood the issues you are experiencing which resulted in me providing incorrect information.

This mod (ie, "Post and PM Inline Attachments") does not modify any image attachment information in the database - it simply allows users to insert attachments in either forum posts or PMs (if the PM Attachments mod is already installed).

However, the Automatic Attachment Rotation (and Resize) mod can modify information in the database for existing images if the "Resize existing images" option is enabled.  That said, the problems you are describing are unusual because a variety of your users are experiencing different issues under different circumstances.

I'd be happy to help you identify the cause of the issues and also let you know what needs to be done to resolve them.  If you'd like my help please send me a PM to let me know.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

GL700Wing

v6.13 - June 9th, 2018
o Added message for PM preview to indicate attachment has not been uploaded yet.
o Updated installation code for SMF 2.0.x to enable this mod to be installed and/or uninstalled before and/or after the Automatic Attachment Rotation (and Resize) mod without generating errors in Display.php.


Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Advertisement: