boonebgorges / buddypress-docs

GNU General Public License v3.0
106 stars 44 forks source link

view attachments directly #659

Closed mowglisjungle closed 5 years ago

mowglisjungle commented 5 years ago

Hi,

my clients would preferably have the option to view the attachments in stead of a download link for the buddypress docs attachments. Any suggestions to solve this? Kind regards, Dirk

boonebgorges commented 5 years ago

Hello - Do you mean you'd like to display the images directly inline, and that other content (video, etc) would somehow be embedded?

mowglisjungle commented 5 years ago

Hello, thank you for the reply. The users of the website I build prefer that their uploaded attachments rather just open then they have to download it first. Is something like this is possible?

boonebgorges commented 5 years ago

Ah, I see what you're asking. ccb3421 adds a new filter that will allow you to set the Content-Disposition header, like this:

add_filter(
  'bp_docs_attachments_http_headers',
  function( $headers, $filename ) {
    $filename_parts = pathinfo( $filename );
    $headers['Content-Disposition'] = 'download; filename="' . $filename_parts['basename'] . '"';
    return $headers;
  },
  10,
  2
);
boonebgorges commented 5 years ago

The filter will be available in the next release of Docs, or you can patch your installation. The add_filter() code can go in your theme's functions.php or some other file.

robink89 commented 4 years ago

Hey! What he was asking for and what i also want is that if attached files could open in for example Google docs viewer instead of downloading it to your device. Would it be possible ?

boonebgorges commented 4 years ago

Hello - Something like what's described above should change the way that the browser handles the file (forcing download rather than browser view, etc). I don't know how to open a document in Google Docs, but you may be able to use a similar header for this.

robink89 commented 4 years ago

hey again! first of all, love your work! secondly, ive added the code but it still downloads all attached files to my pc when i click them.

would it be possible for you to add google viewer as a option when uploading the attatchment? all you gotta do is have a option to edit the URL for the document attached to docs with this: https://docs.google.com/viewer?url= www.yourdocumentsurlfile.com

boonebgorges commented 4 years ago

I'm afraid I can't add an option for this, but you can probably do it yourself with a simple filter. This is untested, but the idea is that it should replace the download URL with the Google-embedded one:

add_filter(
  'bp_docs_attachment_url_base'
  function( $url, $attachment ) {
    return 'https://docs.google.com/viewer?url=' . urlencode( wp_get_attachment_url( $attachment->ID ) );
  },
  10,
  2
);

It's possible that this will not work with non-public attachments.

robink89 commented 4 years ago

Hey man! works like a charm, thank you so much for your time

robink89 commented 4 years ago

Hey again! As you Said only public documents can be used with the code you gave me, do you have any other way to open non-public files in website instead of downloading it to your device ?

boonebgorges commented 4 years ago

Best I can offer is that you play with Content-Disposition. https://github.com/boonebgorges/buddypress-docs/issues/659#issuecomment-521731262 https://coderanch.com/t/561315/java/display-pdf-file-broswer and other Google hits.

rn2web commented 3 years ago

Hey again! As you Said only public documents can be used with the code you gave me, do you have any other way to open non-public files in website instead of downloading it to your device ?

hello, this is a good request, i'm need it too :( very nice work with this plugin so far