Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2017-01-06 11:50:14

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 959
Website

Re: How to intercept file_download callback with a plugin

johnstephens wrote #303509:

@maverick, I’d love to know. Can you point me to the plugin you have in mind?

I don’t see any file_download-related plugins on etc’s website or Github account.

I linked the word “plugin” above, but you must not have seen it. etc linked below as well. It was an unofficial plugin posted in the thread discussing this from 2010/11.

Offline

#12 2017-01-06 12:19:27

etc
Developer
Registered: 2010-11-11
Posts: 3,017
Website

Re: How to intercept file_download callback with a plugin

Bloke wrote #303518:

Disadvantage: security. Even passing the type might be a risk as it could be manipulated to serve a file as something else.

Valid point. We can not prevent bad guys from misusing Textpattern (say, by serving some evil js), but, at least, external sites shouldn’t be able to cheat with txp-served files. What are possible abuse scenarios?


etc_[ query | search | pagination | date | tree | cache ]

Offline

#13 2017-01-06 15:06:18

etc
Developer
Registered: 2010-11-11
Posts: 3,017
Website

Re: How to intercept file_download callback with a plugin

I have modified the plugin to restrict framing from external sites, for more security.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#14 2017-01-06 21:36:56

etc
Developer
Registered: 2010-11-11
Posts: 3,017
Website

Re: How to intercept file_download callback with a plugin

colak wrote #303517:

+1. I guess the best way would be to have a preference on a per file or per file category basis deciding for a download or web browser read.

Not sure (needs testing) that would be flexible enough to provide a fallback like

<object data="mypdf.pdf?view=inline" type="application/pdf">
  <p>You don't have a PDF plugin, but you can <a href="myfile.pdf">download the PDF file.</a></p>
</object>

Alternatively (and probably impossible to do), view on web browser but also keep a track of download numbers.

This is quite easy, it’s what the plugin does. But it implies a db write on each page visit, unless the file is cached by the browser.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#15 2017-01-06 22:14:02

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 981
Website

Re: How to intercept file_download callback with a plugin

Thank you maverick and etc!

Sorry for the misunderstanding. It was after dark here, and I was reading your message with a darkroom filter provided by f.lux running, and the link wasn’t distinguishable from the text.

The etc_file_embed code works perfectly for my use-case. I just need to update the PDF file links in my templates and content.

Thank you again!

And if this conversation leads to more robust options for dealing with this in Textpattern core, cheers to that.

Offline

#16 2017-01-06 22:47:23

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 959
Website

Re: How to intercept file_download callback with a plugin

Not a problem. I’ve had similar experiences. Glad etc’s plugin works. Thanks for this etc!

johnstephens wrote #303524:

Thank you maverick and etc!

Sorry for the misunderstanding. It was after dark here, and I was reading your message with a darkroom filter provided by f.lux running, and the link wasn’t distinguishable from the text.

The etc_file_embed code works perfectly for my use-case. I just need to update the PDF file links in my templates and content.

Thank you again!

And if this conversation leads to more robust options for dealing with this in Textpattern core, cheers to that.

p.

Offline

#17 2018-12-20 15:16:31

etc
Developer
Registered: 2010-11-11
Posts: 3,017
Website

Re: How to intercept file_download callback with a plugin

In 4.7.2 things are dead simple: create the following public-side plugin

register_callback('abc_output_file', 'file_download');

function abc_output_file($event) {
    parse_form('file_download_header');
}

some file category, say inline_pdf, and a file-type file_download_header form

<txp:evaluate query='<txp:file_download_category escape="quote" />="inline_pdf"'>
<txp:header name="Content-Disposition" value="inline" />
<txp:header name="Content-Type" value="application/pdf" />
</txp:evaluate>

Adjust as needed.


etc_[ query | search | pagination | date | tree | cache ]

Offline

Board footer

Powered by FluxBB