Post and PM Inline Attachments

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

Previous topic - Next topic

Parmaster

Hi!

I Installed successfully your mod, but I can't insert an attachment. I see the links but when I click on it nothing happens.

And in PM's it's not possible to send an attachment.

And why is in every PHP file which the mod edited this CDATA? It seems that there is a failure with editing the files. Or doesn't it affect anything?

dougiefresh

Quote from: aegersz on September 13, 2017, 01:50:50 AM
@dougie, i noticed that you handle pdf files in some way (was looking at the settings) but i have attached both pdf and text files but there was no display unlike your picture processing.
Evidentally, Google has changed their software so that you HAVE to be logged in in order to view a PDF document.  I am going to change the code to use an embed or object HTML tag, which may require the user to have Adobe Reader installed on the system....

Quote from: Parmaster on September 13, 2017, 07:12:24 AM
I Installed successfully your mod, but I can't insert an attachment. I see the links but when I click on it nothing happens.
Hmmmmm.....  Let me look into this.

Quote from: Parmaster on September 13, 2017, 07:12:24 AM
And in PM's it's not possible to send an attachment.
This mod doesn't give the forum the ability to sent PM attachments, but enhances the PM Attachments mod to allow you to insert the attachment into the message, much like using the img tag.

Quote from: Parmaster on September 13, 2017, 07:12:24 AM
And why is in every PHP file which the mod edited this CDATA? It seems that there is a failure with editing the files. Or doesn't it affect anything?
Huh?

pellet_newb


Parmaster

@dougiefresh:

don't worry, I solved it. I don't know if it's related to the theme I use or SMF directly, but it only works if WYSIWYG is off (in my forum).

Ah ok, then I have to look about this mod.

It wasn't your mod alone that included the CDATA crap into the files, I saw many of them also in other files in which your mod haven't changed anything, so something is broken and I don't know what.


dougiefresh

Quote from: pellet_newb on September 14, 2017, 11:37:26 AM
What about Tapatalk support?
UPDATE:  My forum is now online with Tapatalk, so I can now do testing with it to try to make it work with this mod.

pellet_newb

Quote from: dougiefresh on September 15, 2017, 11:41:51 PM
Quote from: pellet_newb on September 14, 2017, 11:37:26 AM
What about Tapatalk support?
UPDATE:  My forum is now online with Tapatalk, so I can now do testing with it to try to make it work with this mod.

SWEET, fingers crossed!

pellet_newb

Have you made any progress with Tapatalk?  Thanks

GL700Wing

Found an issue that results in the wrong error message (ie, '] Invalid Attachment [' instead of '[ Attachment has not been uploaded yet ]') being displayed when previewing either a new or modified message that includes a new inline attachment.  Fixed by moving a slightly modified preview message test to before the permissions tests.

Also, suggest that test for determining if attachments can be viewed is done at very beginning so that 'ila_nopermission' message is displayed instead of 'ila_invalid' message.

In /.Sources/Subs-InlineAttachments.php

Find:
function ILA_Build_HTML(&$tag, &$id)
{
global $context, $modSettings, $settings, $txt, $sourcedir, $user_info, $smcFunc, $forum_version;

// If the "one-based numbering" option is set, subtract 1 from the attachment ID to make it compatible:
$id = $id - intval(!empty($modSettings['ila_one_based_numbering']));

// Make sure that we can access other messages:
$allowed = (isset($modSettings['ila_allow_quoted_images']) && !empty($modSettings['ila_allow_quoted_images']) && !file_exists($sourcedir . '/Subs-Tapatalk.php'));
if (isset($context['ila_params']['msg']))
$msg = ($allowed || (isset($context['ila']['msg']) && $context['ila_params']['msg'] == $context['ila']['msg']) ? $context['ila_params']['msg'] : -1);
else
$msg = (isset($context['ila']['msg']) ? $context['ila']['msg'] : -1);

// Are attachments enabled and can we see them?  If not, return no permission message:
if (!isset($context['ila']['attachments'][$msg][$id]))
return $txt['ila_invalid'];
$attachment = &$context['ila']['attachments'][$msg][$id];
if (empty($context['ila']['pm_attach']) && empty($modSettings['attachmentEnable']))
return $txt['ila_nopermission'];
if (!empty($context['ila']['pm_attach']) && (empty($modSettings['pmAttachmentEnable']) || empty($context['ila']['pm_view_attachments'])))
return $txt['ila_nopermission'];

// This part is done after board permission check because we don't want to give user false hope.
// If we are previewing the post, return "attachment not uploaded yet" message:
if (!isset($context['ila']['attachments'][$msg]) && (isset($_REQUEST['action']) ? $_REQUEST['action'] : '') == 'post2')
return $txt['ila_not_uploaded'];


Replace With:
function ILA_Build_HTML(&$tag, &$id)
{
global $context, $modSettings, $settings, $txt, $sourcedir, $user_info, $smcFunc, $forum_version;

// Are we allowed to view attachments?  If not, return no permission message
if (!allowedTo('view_attachments'))
return $txt['ila_nopermission'];

// If the "one-based numbering" option is set, subtract 1 from the attachment ID to make it compatible:
$id = $id - intval(!empty($modSettings['ila_one_based_numbering']));

// Make sure that we can access other messages:
$allowed = (isset($modSettings['ila_allow_quoted_images']) && !empty($modSettings['ila_allow_quoted_images']) && !file_exists($sourcedir . '/Subs-Tapatalk.php'));
if (isset($context['ila_params']['msg']))
$msg = ($allowed || (isset($context['ila']['msg']) && $context['ila_params']['msg'] == $context['ila']['msg']) ? $context['ila_params']['msg'] : -1);
else
$msg = (isset($context['ila']['msg']) ? $context['ila']['msg'] : -1);

// If we are previewing the post, return "attachment not uploaded yet" message:
if (((isset($_REQUEST['action']) ? $_REQUEST['action'] : '') == 'post2') && (!isset($context['ila']['attachments'][$msg][$id])))
return $txt['ila_not_uploaded'];

// Are attachments enabled and can we see them?  If not, return no permission message:
if (!isset($context['ila']['attachments'][$msg][$id]))
return $txt['ila_invalid'];
$attachment = &$context['ila']['attachments'][$msg][$id];
if (empty($context['ila']['pm_attach']) && empty($modSettings['attachmentEnable']))
return $txt['ila_nopermission'];
if (!empty($context['ila']['pm_attach']) && (empty($modSettings['pmAttachmentEnable']) || empty($context['ila']['pm_view_attachments'])))
return $txt['ila_nopermission'];

// This part is done after board permission check because we don't want to give user false hope.


Also, found a bug in 5.10 that is not present in 5.6 whereby a new attachment is not inserted inline when an existing message is modified - it is only attached (see attachments).
Life doesn't have to be perfect to be wonderful ...

dougiefresh

#669
Uploaded v5.11 - October 18th, 2017
o Modified code to return already-build attachment context array if available.
o Fixed reporting invalid attachment when viewing attachments on board wasn't possible.




@GL700Wing:  Thanks for reporting those bugs. 

The suggested code change would solve the immediate issue of the message, but it wouldn't solve this particular scenario: On a board where viewing attachments isn't possible, a message containing an inline attachment tag, which referrs to an attachment on a board where viewing attachments is allowed, would not be viewable, despite the fact that it is viewable on that board.  I've fixed the code in several spots to fix the whole issue on order to deal with the scenario specified.....

Quote from: GL700Wing on October 02, 2017, 01:03:47 AM
Also, found a bug in 5.10 that is not present in 5.6 whereby a new attachment is not inserted inline when an existing message is modified - it is only attached (see attachments).
Okay, that's weird....  I'll have to look into this bug report....

Quote from: pellet_newb on September 26, 2017, 11:33:49 AM
Have you made any progress with Tapatalk?  Thanks
@pellet_newb: I wish I could say that I have definitely made some progress, however, I THINK I've fixed an issue that keeps from reporting the attachments correctly to the Tapatalk script....  I haven't have time to test it against Tapatalk code, though....

I strongly suspect that since the Tapatalk mod does it's own parsing before and after called SMF's parsing function, that it is somehow messing up the attachments.  Not sure, though....

@rjen

Nice work, I was just wondering: did you ever find time to look into the incorrect presentation thing I reported before when two attachments are posted side by side? I tried finding a solution myself, but I was not successfull...

Quote from: @rjen on July 11, 2017, 04:47:13 AM
Issue Number 2:
I cannot seem to get two attachments showing next to each other: the attachment information seems to break the alignment, is there a solution for this?

If I deactivate the 'Download link and counter setting:' in admin it works, but when I activate it I get below display
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

dougiefresh

#671
Quote from: @rjen on October 19, 2017, 09:06:09 AM
Nice work, I was just wondering: did you ever find time to look into the incorrect presentation thing I reported before when two attachments are posted side by side? I tried finding a solution myself, but I was not successfull...

Quote from: @rjen on July 11, 2017, 04:47:13 AM
Issue Number 2:
I cannot seem to get two attachments showing next to each other: the attachment information seems to break the alignment, is there a solution for this?

If I deactivate the 'Download link and counter setting:' in admin it works, but when I activate it I get below display
The only thing I've come up with for this is to use the float=left parameter in the inline attachment tag for both tags.....  The biggest problem that I can see with this solution is if text is involved, as floating the image to the left or right may screw with the intented appearance.....

You could also try a table declaration, surrounding each image with the [tr] tags.....

Quote from: GL700Wing on October 02, 2017, 01:03:47 AM
Also, found a bug in 5.10 that is not present in 5.6 whereby a new attachment is not inserted inline when an existing message is modified - it is only attached (see attachments).
Issue confirmed with version 5.11.

@rjen

Problem is that I Cannot find where to do that...
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

dougiefresh

Insert float=left just after the id parameter.  That should work....

@rjen

Can you tell me what file the dit needs to be in?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

dougiefresh

In the message that you are inlining an attachment.  Change something like this:
Code (Starting Example) Select
[attachment id=1 msg=1234]
to something like this:
Code (Change to) Select
[attachment id=1 float=left msg=1234]

@rjen

Quote from: dougiefresh on October 19, 2017, 08:42:53 PM
In the message that you are inlining an attachment.  Change something like this:
Code (Starting Example) Select
[attachment id=1 msg=1234]
to something like this:
Code (Change to) Select
[attachment id=1 float=left msg=1234]

That does the trick indeed, thanks! I was hoping for a more 'permanent'  fix though.

I now notice that when I include this float statement within the [ attachment ] code, an additional < div > is generated under the < inner > div.
This  div is what I was looking for: <div style="float: left;">

Without the style added into the attachment statement this div is not even generated, so there is nothing to influence from css.
Is there a way to always generate this div with the style so users will not have to manually type this additional float?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

Quote from: @rjen on October 20, 2017, 02:58:14 AM
I now notice that when I include this float statement within the [ attachment ] code, an additional < div > is generated under the < inner > div.
This  div is what I was looking for: <div style="float: left;">

Without the style added into the attachment statement this div is not even generated, so there is nothing to influence from css.
Is there a way to always generate this div with the style so users will not have to manually type this additional float?

mmm, I just realized the float is not ideal, because it would make all text float around the inline attachments permanently.
It would probably be better to have a standard <div> around the img and text defined as inline-block?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

I managed to make the change myself!
This fix does exactly what I was looking for: it by default creates the < div > as an inline-block, but when a float is used it works as a floated div. This way when a user puts three attachments on one line they will nicely show on the line without the text issues I highlighted. On smaller screens the divs are positioned below each other if needed.

You may want to include this in your next update as well?

In file: Subs-InlineAttachments.php

Find:
// Add the margin and float params to the rest of the HTML:
if (isset($context['ila_params']['float']) && $context['ila_params']['float'] == 'center')


Replace with:
// Add the margin and float params to the rest of the HTML:
if (!isset($context['ila_params']['float']))
$html = '<div style="display: inline-block;">' . $html . '</div>';
elseif (isset($context['ila_params']['float']) && $context['ila_params']['float'] == 'center')


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

dougiefresh

Hmmm.....  Code seems to work well enough, but I made another change to ensure other CSS style stuff gets included as well.  Here is that block of code:
// Add the margin and float params to the rest of the HTML:
if (isset($context['ila_params']['float']) && $context['ila_params']['float'] == 'center')
$html = '<div style="margin-left: auto; margin-right: auto; display: block;">' . $html . '</div>';
elseif (isset($context['ila_params']['float']))
$html = '<div style="display: inline-block; float: ' . $context['ila_params']['float'] . ';' . (!empty($style) ? $style : '') . '">' . $html . '</div>';
elseif (!empty($style))
{
if ((!empty($modSettings['ila_download_count']) && $tag['tag'] != 'attachmini') || $tag['tag'] == 'attachurl')
$html = '<div style="display: inline-block; ' . (!empty($style) ? $style : '') . '">' . $html . '</div>';
else
$html = str_replace('<img src="', '<img style="' . $style . '" src="', $html);
}
else
$html = '<div style="display: inline-block;">' . $html . '</div>';

It will be included in the next version of the mod!  Thanks, @rjen!

Advertisement: