Skip to main content
Re: attachmentz Started by emanuele · · Read 24174 times 0 Members and 1 Guest are viewing this topic. previous topic - next topic - Topic derived from attachmentz

Re: attachmentz

One thing I was thinking it that attachments are now "rather" detached from the actual posting of the message (they are saved and then the info stored in the session until the post is actually saved and only then the attachments are created and linked to the post) and it may even be possible to easily implement an "upload-before-post" kind of thing...similar to github (and others)... and at that point, the "inline-attachment" may even be simply an img bbcode...
It wouldn't give a preview, but tweaking something...maybe...

Disclaimer: at the moment I can't work on it...
Bugs creator.
Features destroyer.
Template killer.

Re: Re: attachmentz

Reply #1

QuoteDisclaimer: at the moment I can't work on it...
You are a terrible tease  :P

Re: Re: attachmentz

Reply #2

 emanuele whistles innocently. :P
Bugs creator.
Features destroyer.
Template killer.

Re: Re: attachmentz

Reply #3

Well, lets get some codes to dance around as I've got a project regarding the same, where the client has asked a functionality to drag drop the attachments. Moreover, I've the skeleton code ready (without any security checks  ;D)somewhere and its eager to explode into some nice plugin/core functionality.

Client === 'Joker™'

When can we expect a demo - by end of coming week :P

Re: Re: attachmentz

Reply #4

Dunno if you already have all the js, a while ago I was looking at that one:
http://www.elkarte.net/community/index.php?topic=112.0
Bugs creator.
Features destroyer.
Template killer.

Re: Re: attachmentz

Reply #5

Quote from: emanuele – Dunno if you already have all the js, a while ago I was looking at that one:
http://www.elkarte.net/community/index.php?topic=112.0
I'll surely take a look at that too, but I've already wrote down some intial code for drag and drop functionality. I'll have to take a look at elkarte code for attachment process, specially after reading this comment,

Quote from: TestMonkey – To (quick) note:
I favor the refactoring: detach of the upload files functionality in Elkarte, from strictly attachments to posts. It should be reusable for something like "attachments" to articles of SP.

If we do that, the replacement of the implementation with this implementation might be even easier.

Re: Re: attachmentz

Reply #6

Yep, the attachments processing has changed quite a bit...
If you look into Post.controller.php, the code to create an attachment is rather simple:
Code: [Select]
		// Then try to upload any attachments.
$context['can_post_attachment'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
if ($context['can_post_attachment'] && empty($_POST['from_qr']))
{
require_once(SUBSDIR . '/Attachments.subs.php');
if (isset($_REQUEST['msg']))
processAttachments((int) $_REQUEST['msg']);
else
processAttachments();
}
and slightly below:
Code: [Select]
		// Any mistakes?
if ($post_errors->hasErrors() || $attach_errors->hasErrors())
{
// Previewing.
$_REQUEST['preview'] = true;

return $this->action_post();
}
and finally the block after the comment:
Code: [Select]
// ...or attach a new file...
Attachments are not yet that independent from messages, but at least their processing is.

In your case, you should be able to prepare the attachments with just the first block of code (the one containing processAttachments()), and then Post.controller.php will take care of associating the attachment to the proper message... I think/hope. :P
And you can use the static class:
Code: [Select]
$attach_errors = attachment_Error_Context::context();
to catch any error while attaching a file.
Bugs creator.
Features destroyer.
Template killer.

Re: attachmentz

Reply #7

Okzz, I got few free hrs in workplace today and was able to pull out a drag drop prototype with very basic JS/HTML.

This is a complete security nightmare for now, but I'm trying to write JS more as a plugin so that we can utilise drag drop functionality  whereever we like, where we can :P

Edit - @emanuele with the first code block, it seems like most of the php side work can be accomplished within few hrs only :)

Re: attachmentz

Reply #8

Cool!! 8)

With a couple of minor changes seems to work pretty well, see the attachment!

Though I think there is some bug in the attachment handling at the moment... :-\
I fixed one, but I feel there is more when dealing with data lost from session and so on, needs debugging.

Re: attachmentz

Reply #9

Thanks a lot for the code @emanuele

I was thinking of extending the 'Attachment.controller.php'. Currently the attachment controller only has

- action_index method, which calls
- action_dlattach, which downloads the attachment

So, how about adding few more functions for drag drop attachments in the same
- Upload attachments
- Remove attachments


Check this out 8).

Noobish question, is attachment permission that who can attach etc etc for Elkarte is same as SMF?

Re: Re: attachmentz

Reply #10

Interesting, the @ failed... let me try: @Joker™
or maybe @Spuds
Darn, the dropdown is broken again with multiple names collecting around...  >:(

Quote from: Joker™ – Thanks a lot for the code @emanuele
You are welcome! :D
Thank you for the contribution! ;D

Quote from: Joker™ – I was thinking of extending the 'Attachment.controller.php'. Currently the attachment controller only has

- action_index method, which calls
- action_dlattach, which downloads the attachment

So, how about adding few more functions for drag drop attachments in the same
- Upload attachments
- Remove attachments
Yep, I think it's the way to go, and once that methods are there it should be possible to use them from the other controllers as well in order to remove duplication.

Quote from: Joker™ – Check this out 8).

Noobish question, is attachment permission that who can attach etc etc for Elkarte is same as SMF?
Yes, I don't remember any change in the permissions.

I'm not sure if this will be a trend (I hope so) and I'm not sure this is relevant to your question (but since I wrote it I'll post it :P), I just pushed this code with the aim of staring to organize $context. For the moment I touched just the attachments related settings in the Post controller, so that anything related to attachments is "child" of $context['attachments'], so I moved permissions to $context['attachments]['can'], for example this line:
Code: [Select]
$context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
Bugs creator.
Features destroyer.
Template killer.


Re: Re: attachmentz

Reply #12

Quote from: emanuele – Interesting, the @ failed... let me try: @Joker™
or maybe @Spuds
Darn, the dropdown is broken again with multiple names collecting around...  >:(

Quote from: Joker™ – Thanks a lot for the code @emanuele
You are welcome! :D
Thank you for the contribution! ;D

Quote from: Joker™ – I was thinking of extending the 'Attachment.controller.php'. Currently the attachment controller only has

- action_index method, which calls
- action_dlattach, which downloads the attachment

So, how about adding few more functions for drag drop attachments in the same
- Upload attachments
- Remove attachments
Yep, I think it's the way to go, and once that methods are there it should be possible to use them from the other controllers as well in order to remove duplication.

Quote from: Joker™ – Check this out 8).

Noobish question, is attachment permission that who can attach etc etc for Elkarte is same as SMF?
Yes, I don't remember any change in the permissions.

I'm not sure if this will be a trend (I hope so) and I'm not sure this is relevant to your question (but since I wrote it I'll post it :P), I just pushed this code with the aim of staring to organize $context. For the moment I touched just the attachments related settings in the Post controller, so that anything related to attachments is "child" of $context['attachments'], so I moved permissions to $context['attachments]['can'], for example this line:
Code: [Select]
$context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));



Thats some nice info.

@emanuele & @Spuds, ema has sent me a 'PM' on elkarte but I can't see it anywhere on site, strange.

Also ema has bought this into my notice that elkarte is supporting minimum PHP version 5.1, so to make drag drop work properly we can port the json function from 'Like post' mod, thoughts?

Re: Re: attachmentz

Reply #13

The PM text has been separated from the PM list, so to read the PM you have to click on the title. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: Re: attachmentz

Reply #14

Quote from: emanuele – The PM text has been separated from the PM list, so to read the PM you have to click on the title. ;)
Please refer to the 2 screen shots attached, one of my inbox and other of my settings. I must be missing something really bad.