Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
433 views
in Plugins by
When users post, they might copy images from external sites. But these images might disappear after sometime (for example FB deletes the link for the images). So, is it possible to download those images when user posts? If a plugin is made, should this be done as part of editor or as an event module?
Q2A version: 1.8

3 Answers

+2 votes
by

they might copy images from external sites

Assuming you meant they might copy a link to an image here are some random thoughts on this:

  • Q2A modifies the images when uploaded so the image won't be exactly the same
  • A plugin (regardless of the module used) will have to perform an HTTP request to fetch every link (actually a HEAD request first and the a full fetch with a GET), regardless whether it is an image or not. Depending on the content type returned by the request then it can be determined whether it is an image or not and proceed with the storing
  • An event module has the advantage that it executes after the question is posted so you don't perform additional work during the question post (that is dynamic while writing it) but rather once at the end of the posting process
  • An event module won't be able to display the user the final expected post (with the local image) before the user creates the post
  • An editor module will be, IMO, more complex if done right as it will require images (all links, actually) to be fetched dynamically (most likely with JS) while writing and storing the image locally, although some editors might already support this and provide a simple-to-use API
  • A Q2A site can only have one editor enabled at a given time while it can have many event modules so users are not forced to change their favourite editor
by
Thank you pupi. Yes, I meant copy a link to image.
I'll try event module to start.
+2 votes
by
I understand your needs. However, we need to think carefully about copyright and netiquette before realization method. Copying external site data to your server programmatically may violate copyright of the content author. And, this process may be misunderstood as an invalid crawler. One solution would be to find external links in the content and to correct HTML tags that returns 404 error in the Basic Viewer process.
by
yes, I do not want to copy content. But images going missing after some days make the site look ugly.
"correct HTML tags that returns 404 error in the Basic Viewer process"
How can this be possible as image is no longer available?
by
Thank you. Guess that makes more sense. It is better to show these links to admins and let them handle it manually. At least in my site, I usually convert images to text wherever possible and so, these can be done with priority.
+1 vote
by

Putting aside copyright issues, simply put a static note or even dynamic, so that your users know that they have pasted in an image with external src. 

Then give them the option to go back and copy the actual image to their clipboard and paste directly into the editor. The editor should take care everything - between AJAX and PHP.

This method is what I already use. I have not yet released it on github.

@pupi1985:  An editor module will be, IMO, more complex if done right as it will require images (all links, actually) to be fetched dynamically (most likely with JS) while writing and storing the image locally, although some editors might already support this and provide a simple-to-use API

I have a powerful TinyMCE plugin called Rapid Image. This acts much like how Slack or Ryver grabs images from clipboard and automatically uploads to the server

This uses the sweet TinyMCE API

@pupi1985:  An editor module will be, IMO, more complex if done right as it will require images (all links, actually) to be fetched dynamically (most likely with JS) while writing and storing the image locally, although some editors might already support this and provide a simple-to-use API

...