ElkArte Community

Elk Development => Feature Discussion => Exterminated Features => Topic started by: emanuele on September 26, 2013, 06:08:48 am

Title: Re: attachmentz
Post by: emanuele on September 26, 2013, 06:08:48 am
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...
Title: Re: Re: attachmentz
Post by: Spuds on September 26, 2013, 09:28:52 am
QuoteDisclaimer: at the moment I can't work on it...
You are a terrible tease  :P
Title: Re: Re: attachmentz
Post by: emanuele on September 26, 2013, 10:08:32 am
/me whistles innocently. :P
Title: Re: Re: attachmentz
Post by: Joker™ on January 19, 2014, 11:18:03 am
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
Title: Re: Re: attachmentz
Post by: emanuele on January 19, 2014, 12:01:07 pm
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
Title: Re: Re: attachmentz
Post by: Joker™ on January 20, 2014, 09:04:59 am
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.
Title: Re: Re: attachmentz
Post by: emanuele on January 20, 2014, 02:02:52 pm
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.
Title: Re: attachmentz
Post by: Joker™ on January 22, 2014, 09:55:40 am
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 :)
Title: Re: attachmentz
Post by: emanuele on January 22, 2014, 06:38:58 pm
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.
Title: Re: attachmentz
Post by: Joker™ on January 25, 2014, 06:05:56 am
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 (https://github.com/siddhartha-gupta/Elkarte/commits/dropAttachmebts) out 8).

Noobish question, is attachment permission that who can attach etc etc for Elkarte is same as SMF?
Title: Re: Re: attachmentz
Post by: emanuele on January 25, 2014, 07:44:25 am
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.

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 (https://github.com/elkarte/Elkarte/pull/1295) 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 (https://github.com/elkarte/Elkarte/pull/1295/files#diff-0fbfb4e443daaff0d9389cb77cbe7418R610):
$context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));
Title: Re: Re: attachmentz
Post by: emanuele on January 25, 2014, 07:54:53 am
xref: https://github.com/elkarte/Elkarte/issues/224
Title: Re: Re: attachmentz
Post by: Joker™ on January 26, 2014, 01:58:08 am
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 (https://github.com/siddhartha-gupta/Elkarte/commits/dropAttachmebts) 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 (https://github.com/elkarte/Elkarte/pull/1295) 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 (https://github.com/elkarte/Elkarte/pull/1295/files#diff-0fbfb4e443daaff0d9389cb77cbe7418R610):
$context['attachments']['can']['post'] = !empty($modSettings['attachmentEnable']) && $modSettings['attachmentEnable'] == 1 && (allowedTo('post_attachment') || ($modSettings['postmod_active'] && allowedTo('post_unapproved_attachments')));


Quote from: emanuele – xref: https://github.com/elkarte/Elkarte/issues/224

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 (https://github.com/siddhartha-gupta/SMF-Likes/blob/master/Sources/LikePosts.php#L105)' mod, thoughts?
Title: Re: Re: attachmentz
Post by: emanuele on January 26, 2014, 03:28:33 am
The PM text has been separated from the PM list, so to read the PM you have to click on the title. ;)
Title: Re: Re: attachmentz
Post by: Joker™ on January 26, 2014, 07:56:52 am
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.
Title: Re: Re: attachmentz
Post by: emanuele on January 26, 2014, 08:06:35 am
Then that's a bug! :P
As a workaround, I'd suggest to set the visualization as "discussion", that will let you access it. ;)
Title: Re: attachmentz
Post by: Spuds on January 26, 2014, 10:17:22 am
QuotePlease refer to the 2 screen shots attached, one of my inbox and other of my settings. I must be missing something really bad.
Yup a bug it is !  Gosh darn, have I mentioned how much I hate that section of code :

QuoteAlso 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 '
Indeed 5.1 (5.1.2 to be specific) ... for sure we could port that function over, I think it would be useful for addon writers, so perhaps it can be added in Subs.php as a support function.  Thats what we did with an array slicer function to help people inject new items in the the menus. 


ETA: one other thing ... in those screen shots I noticed the search drop down box is small compared to the input and select button on either side of it.  If you get a moment could you debug that?  I don't have access to Mac stuff so can't do that myself :(

Title: Re: Re: attachmentz
Post by: [SiNaN] on January 26, 2014, 01:11:05 pm
Quote from: Spuds – ETA: one other thing ... in those screen shots I noticed the search drop down box is small compared to the input and select button on either side of it.  If you get a moment could you debug that?  I don't have access to Mac stuff so can't do that myself :(

OSX forces its own style on select boxes. I think you need to use something like -webkit-appearance: none; for the select boxes you are styling. Also, use of semi-bold fonts (the family) part for key areas (as you define it) doesn't seem to be working well for me. Attached a screenshot for that.
Title: Re: attachmentz
Post by: Spuds on January 26, 2014, 02:12:00 pm
Quote from: [SiNaN] – OSX forces its own style on select boxes. I think you need to use something like -webkit-appearance: none; for the select boxes you are styling
Good to know, thanks.
Quote from: [SiNaN. Also, use of semi-bold fonts (the family) part for key areas (as you define it) doesn't seem to be working well for me. Attached a screenshot for that.
Is that OSx as well or other? Looks like plain old bold in those pics which is the fallback state if its unable to find the demi font face.    I know it will not work on *nix at this point and of course it will do that if it can't find the demi bold face on any OS.   Windows uses Segoe UI,.  OSx should use Helvetica Neue.

Messing with these font faces is just ugly and the only way I know to address is font-face, like this but with a 600 weight and use Open Sans for those areas (all go all out and use it everywhere) ... downside, its not local, upside its probably already in your cache.
Code: [Select]
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 400;
  src: local('Open Sans'), local('OpenSans'), url(http://themes.googleusercontent.com/static/fonts/opensans/v7/cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff) format('woff');
}
Title: Re: Re: attachmentz
Post by: [SiNaN] on January 26, 2014, 04:03:12 pm
Yep, that's OSX too.
Title: Re: Re: attachmentz
Post by: Spuds on January 26, 2014, 04:52:27 pm
This should be the family, so the question is do any of them have a 600 weight font, or even a bold that render demi. 

Right now of OSx the 600 weight should be calling Helvetica Neue Medium, maybe that needs to be bold with that face to be demi (fonts are weird).   If not do any of the family provide a nice 600 semi-demi-almost-bold look?

Helvetica Neue
Helvetica Neue Bold
Helvetica Neue Italic
Helvetica Neue Bold Italic
Helvetica Neue Condensed Bold
Helvetica Neue UltraLight
 Helvetica Neue UltraLight Italic
Helvetica Neue Light
Helvetica Neue Light Italic
Helvetica Neue Condensed Black
Helvetica Neue Medium
Helvetica Neue Medium Italic
Helvetica Neue Thin
Helvetica Neue Thin Italic

Any help is appreciated !
Title: Re: Re: attachmentz
Post by: [SiNaN] on January 26, 2014, 05:46:47 pm
Sure. I have tried most of those but anything other than "Helvetica Neue" is not recognized at all. I think I have a fairly regular setup (OSX 10.8.5) and I'm using Chrome (32.0.1700.77). I'm not sure how it's supposed to look, so I'm attaching some screenshots. Let me know if there's anything else I can do to help with this one.
Title: Re: attachmentz
Post by: Spuds on January 26, 2014, 09:13:06 pm
Thank you for those images, that does help.

It looks like the current one does have less "weight:" to the bold font, just not as much as what I see under windows.  

Reading a bit on the web it appears that adding -webkit-font-smoothing: antialiased; to the demi declaration may help de-emphasize it a bit further so I may add that to the css to see if it helps.
Title: Re: Re: attachmentz
Post by: [SiNaN] on January 27, 2014, 01:14:18 am
Attached a screenshot with that one added. It looks better and might really be might you're after.
Title: Re: attachmentz
Post by: Spuds on January 27, 2014, 09:52:32 am
That is looking better, thanks for testing, the change will be in the next update.

The idea was in select areas bold had to much visual punch, so a gentler one was wanted.  That lead to the 600 weight being added some time ago with some known limitations in certain combinations.   Over time we kept finding more combinations that did not work, seems that's always the way.  Now I think we are back to having more, combinations work as expected.
Title: Re: attachmentz
Post by: Joker™ on January 31, 2014, 09:00:59 am
Apologies for not able to reply to the topic early.

Guys to check out the PR (https://github.com/elkarte/Elkarte/pull/1304) 8).

On my todo list for drag drop attachments:
- Pass language strings to javascript from php to remove hardcoded text strings
- Make all sorts of check like file extensions, file size etc in 'Attachment.controller.php' 'action_ulattach'

All suggestions, advices, rants, scoldings are most welcomed.

Coming back to dropdown issue as pointed out by
@Spuds
- I've working very closely with iOS and OSX(in job) and what I've observed over the years is if one uses the font size in even numbers, the fonts are rendered more smoothly and crisp. I'll try to see all the test forum pages on mac and come out with solutions for UI etc.

Happzzz codingzz :D
Title: Re: Re: attachmentz
Post by: Joshua Dickerson on January 31, 2014, 10:32:24 am
You should avoid using die(). You should set the templates/layers to empty and then let the script finish executing. Also, maybe add some hooks in there? I can definitely see someone wanting to change where these attachments go and how they get processed. Just suggestions though, because if it works, add it.
Title: Re: Re: attachmentz
Post by: Joker™ on January 31, 2014, 12:04:52 pm
Quote from: groundup – You should avoid using die(). You should set the templates/layers to empty and then let the script finish executing.
Like XML templates?
- we would be calling a function
- settings values in a global array
- echoing the data from template layer

By the way whats any specific reason of not using die except that it terminates the script on my terms :-X ?

Quote from: groundup – Also, maybe add some hooks in there?
Ummm, please elaborate.
Title: Re: Re: attachmentz
Post by: Joshua Dickerson on January 31, 2014, 01:04:16 pm
That's the point - it's on your terms, not on the whole application's terms. There might be things that need to happen after that. Just saying it is generally regarded as not good programming practices.

I can see a want to have attachment uploads do something different when uploaded via AJAX. Maybe add a "integration" hook in there to allow pre and post processing. What if someone wants to change the result or make the data different.
Title: Re: Re: attachmentz
Post by: Joker™ on February 01, 2014, 06:53:14 am
Progress
- Attachments uploaded in a queue, as earlier if someone dropped multiple attachments only the last one was added
- Removed die() and utilised template layers via Json.template.php
- Placed checks for session
- Checks in JS to account if any file is already attached/size etc while modifying a post
- Bug fixes for regex and minor tweaks

Also for passing language strings from PHP to JS can we use something like this (http://www.elkarte.net/community/index.php?topic=888.msg6830#msg6830)?
Title: Re: Re: attachmentz
Post by: [SiNaN] on February 01, 2014, 11:23:20 am
Quote from: Spuds – That is looking better, thanks for testing, the change will be in the next update.
Just want to say I'm really looking forward to that change. As it is now, it's painful to browse the site for me. I'm using the old default (light) variant, by the way.

Also on that matter, just as I opened the site I got a mixture of two variants and it didn't go away for a good while. I tried a hard refresh and changing the variant but it was the same until it turned back to normal at some point without me doing anything other than browsing the site. Now as I hit the Preview button on quick reply to attach a screenshot, the problem is back. It seems to be something related to caching.
Title: Re: Re: attachmentz
Post by: Spuds on February 01, 2014, 03:31:00 pm
Quote from: [SiNaN] –
Quote from: Spuds – That is looking better, thanks for testing, the change will be in the next update.
Just want to say I'm really looking forward to that change. As it is now, it's painful to browse the site for me. I'm using the old default (light) variant, by the way.
I did update things, but only for the demi-bold weight font ... I think you are indicating that you want that for the OSx font in general?  If so as an experiment I just added that setting to the body tag so let me know how that works.
Quote from: [SiNaNAlso on that matter, just as I opened the site I got a mixture of two variants and it didn't go away for a good while. I tried a hard refresh and changing the variant but it was the same until it turned back to normal at some point without me doing anything other than browsing the site. Now as I hit the Preview button on quick reply to attach a screenshot, the problem is back. It seems to be something related to caching.
@emanuele found the bug with that so I patched the site and turned the cache back on, looks like it fixed the issue (now I've jinxed us !)
Title: Re: Re: attachmentz
Post by: [SiNaN] on February 01, 2014, 04:22:29 pm
I was actually talking about this part:

Code: [Select]
/* Use demi bold font weight for some key areas */
.codeheader, .quoteheader,
.expand_pages,
.table_head>th,
.topic_sorting_row>h3, .topic_name h4 a,
.poster .name,
.keyinfo h5 a, .keyinfo h5 a strong,
.ui-tabs .ui-tabs-nav .ui-state-active a, .ui-tabs .ui-tabs-nav .ui-state-active,
.ui-dialog .ui-dialog-titlebar,
.popup_heading {
    font-weight: 600;
-webkit-font-smoothing: antialiased;
    font-family: "Segoe UI Semibold", "Helvetica Neue Medium";
}

Just add "Helvetica Neue" as the third option as a fallback, since those two isn't recognized, at least for me. Also, that antialiasing thing might be better if only used for that part as well and not for the body tag. The site feels blurry otherwise.

The cache issue seems to be fixed, at least for now. ;)
Title: Re: attachmentz
Post by: Spuds on February 01, 2014, 04:38:00 pm
Done real time ... any better now?
Title: Re: Re: attachmentz
Post by: [SiNaN] on February 01, 2014, 05:17:57 pm
Yeah, it's looking good now. Thanks!
Title: Re: Re: attachmentz
Post by: emanuele on February 08, 2014, 04:23:13 am
Spuds, I was thinking: instead of using a "real div", why not use javascript instead?
Code: [Select]
$('select').wrap('<div class="styled-select"></div>');
should be enough and simplify the markup and maintenance.
Title: Re: Re: attachmentz
Post by: Spuds on February 08, 2014, 10:28:35 am
We sure could, and I thought about "fixing" the select boxes with JS to begin with.

For that to work you also, in addition to the wrap,  have to turn off some other select box css but all that could be done as well.  I just felt, right or wrong, that having those things css based would just respond / feel better on the page load (since the box will change somewhat in size you get one of those pages that moves on load).

There is also the non JS problem, should we want the page to render OK without it, non styled selects need positional tweaks to get them to align depending on where they are used.  So if those are added back in, even wrapping them in the style would require other tweaks on the wrapping to get them to align as well.