Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

etc
Developer
Registered: 2010-11-11
Posts: 5,128
Website GitHub

Re: How to intercept file_download callback with a plugin

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

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,128
Website GitHub

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.

Offline

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

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
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: 976
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: 5,128
Website GitHub

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('etc_output_file', 'file_download');

function etc_output_file($event) {
    global $pretext;

    if (empty($pretext['skin']))
        $pretext['skin'] = safe_field("skin", "txp_section", "name = 'default'");

    parse_form('file_download_header');
}

some file category, say inline-pdf, and a file-type file_download_header form under the skin of default section:

<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>

Now clicking on a inline-pdf category file download link will open it in browser (if allowed). If you prefer to embed them (on the public side), the following should do:

<object data="<txp:file_download_link id="1" />" type="application/pdf" width="100%" height="640px">
    <embed src="<txp:file_download_link id="1" />" type="application/pdf">
        <p><a href="<txp:file_download_link id="1" />">Download PDF</a></p>
    </embed>
</object>

Adjust the forms to fit your needs.

Compiled plugin:

# Name: etc_output_file v0.1 
# Type: Public plugin
# Display files in capable browsers
# Author: Oleg Loukianov
# URL: http://www.iut-fbleau.fr/projet/etc/
# Recommended load order: 5

# .....................................................................
# This is a plugin for Textpattern CMS - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# .....................................................................

YToxMTp7czo0OiJuYW1lIjtzOjE1OiJldGNfb3V0cHV0X2ZpbGUiO3M6NjoiYXV0aG9yIjtz
OjE0OiJPbGVnIExvdWtpYW5vdiI7czoxMDoiYXV0aG9yX3VyaSI7czozNjoiaHR0cDovL3d3
dy5pdXQtZmJsZWF1LmZyL3Byb2pldC9ldGMvIjtzOjc6InZlcnNpb24iO3M6MzoiMC4xIjtz
OjExOiJkZXNjcmlwdGlvbiI7czozMzoiRGlzcGxheSBmaWxlcyBpbiBjYXBhYmxlIGJyb3dz
ZXJzIjtzOjQ6ImNvZGUiO3M6Mjc5OiJyZWdpc3Rlcl9jYWxsYmFjaygnZXRjX291dHB1dF9m
aWxlJywgJ2ZpbGVfZG93bmxvYWQnKTsNCg0KZnVuY3Rpb24gZXRjX291d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: How to intercept file_download callback with a plugin

A test page published.

Offline

Board footer

Powered by FluxBB