CoreCommunity ExtensionsIncubatorDistributionsTYPO3 4.5 ProjectsTYPO3 4.7 ProjectsTYPO3 6.0 ProjectsTYPO3 6.1 ProjectsTYPO3 6.2 Projects (+)

PMK Forced Download

Version 22 (Peter Klein, 2009-09-29 19:35)

1 1
h1. PMK Forced Download
2 1
3 12 Peter Klein
Force a download on links to files. With this extension it's possible to force download of files like images, PDFs, MP3 ect., overriding the browser settings.
4 12 Peter Klein
(Normally when you click on a TYPO3 link to a file like an image, the image will open in the browser.) 
5 12 Peter Klein
6 12 Peter Klein
Works by extending the *stdWrap/typolink* function. So the extension can be used in other extensions which uses the standard TYPO3 typolink functionality when linking.
7 12 Peter Klein
8 13 Peter Klein
h2. Usage
9 13 Peter Klein
10 7 Peter Klein
h3. Example of usage as extended stdWrap parameter (Requires TYPO3 v4.2+):
11 1
12 1
<pre>
13 1
10 = TEXT
14 1
10.value = download
15 1
10.typolink.parameter = fileadmin/templates/images/dwarf_male120x.gif
16 21 Peter Klein
10.typolink.parameter.makeDownloadLink = 1
17 1
</pre>
18 1
19 7 Peter Klein
h3. Example of usage as userFunction:
20 1
21 1
<pre>
22 1
10 = TEXT
23 1
10.value = download
24 1
10.typolink.parameter = fileadmin/templates/images/dwarf_male120x.gif
25 17 Peter Klein
10.typolink.parameter.postUserFunc = tx_pmkfdl->makeDownloadLink
26 1
</pre>
27 2 Peter Klein
28 2 Peter Klein
If the typolink points to a valid file, then the link will be modified to something like this:
29 2 Peter Klein
30 2 Peter Klein
<pre>
31 1
http://www.mydomain.com/index.php?eID=pmkfdl&file=fileadmin%2Ftemplates%2Fimages%2Fdwarf_male120x.gif&ck=a94fad5a0262b2e00e1aa72e8aac4c30
32 1
</pre>
33 11 Peter Klein
34 11 Peter Klein
This link will open up a requester in the browser, asking the user what he wants to do with the file (Save, Open etc.)
35 1
36 4 Peter Klein
A MD5 checksum is added as a 2nd parameter to insure that it is the correct file that is being downloaded.
37 1
(If the MD5 checksum doesn't match the file, then the download will be terminated.)
38 4 Peter Klein
39 7 Peter Klein
h2. Forced download
40 8 Peter Klein
41 6 Peter Klein
If you want to force a download, without opening up the browser requester, you can add a special option/parameter called "forcedl"
42 6 Peter Klein
43 7 Peter Klein
h3. Example of usage as extended stdWrap parameter, with "forcedl" set (Requires TYPO3 v4.2+):
44 6 Peter Klein
45 6 Peter Klein
<pre>
46 6 Peter Klein
10 = TEXT
47 6 Peter Klein
10.value = download
48 1
10.typolink.parameter = fileadmin/templates/images/dwarf_male120x.gif
49 21 Peter Klein
10.typolink.parameter.makeDownloadLink = forcedl
50 6 Peter Klein
</pre>
51 6 Peter Klein
52 7 Peter Klein
h3. Example of usage as userFunction, with "forcedl" set:
53 6 Peter Klein
54 6 Peter Klein
<pre>
55 6 Peter Klein
10 = TEXT
56 6 Peter Klein
10.value = download
57 6 Peter Klein
10.typolink.parameter = fileadmin/templates/images/dwarf_male120x.gif
58 17 Peter Klein
10.typolink.parameter.postUserFunc = tx_pmkfdl->makeDownloadLink
59 21 Peter Klein
10.typolink.parameter.postUserFunc.makeDownloadLink = forcedl
60 6 Peter Klein
</pre>
61 9 Peter Klein
62 22 Peter Klein
h2. Special "register" values.
63 22 Peter Klein
64 22 Peter Klein
After creating a download link, 2 special register values are available:
65 22 Peter Klein
66 22 Peter Klein
* filesize - This contains the size of the file. (in bytes) 
67 22 Peter Klein
* filetype - This contains the type of the file. (gif, pdf, zip etc.)
68 22 Peter Klein
69 22 Peter Klein
h3. Example of using the register value:
70 22 Peter Klein
71 22 Peter Klein
<pre>
72 22 Peter Klein
10 = COA
73 22 Peter Klein
10 {
74 22 Peter Klein
	# Display the filelink
75 22 Peter Klein
	10 = TEXT
76 22 Peter Klein
	10.value = download
77 22 Peter Klein
	10.typolink.parameter = fileadmin/templates/images/dwarf_male120x.gif
78 22 Peter Klein
	10.typolink.parameter.postUserFunc = tx_pmkfdl->makeDownloadLink
79 22 Peter Klein
	10.typolink.parameter.postUserFunc.makeDownloadLink = forcedl
80 22 Peter Klein
	
81 22 Peter Klein
	# Display the filesize from register value
82 22 Peter Klein
	20 = TEXT
83 22 Peter Klein
	20.data = register:filesize
84 22 Peter Klein
	20.bytes = 1
85 22 Peter Klein
	20.wrap = <div>Filesize:&nbsp;|</div>
86 22 Peter Klein
87 22 Peter Klein
	# Display the filetype from register value
88 22 Peter Klein
	30 = TEXT
89 22 Peter Klein
	30.data = register:filetype
90 22 Peter Klein
	30.wrap = <div>Filetype:&nbsp;|</div>
91 22 Peter Klein
}
92 22 Peter Klein
</pre>
93 22 Peter Klein
94 22 Peter Klein
95 22 Peter Klein
h3. Advanced example of using the register value for displaying a filetype icon:
96 22 Peter Klein
97 22 Peter Klein
<pre>
98 22 Peter Klein
10 = COA
99 22 Peter Klein
10 {
100 22 Peter Klein
101 22 Peter Klein
	wrap = <div>|</div>
102 22 Peter Klein
103 22 Peter Klein
	# First we store the link in a register value, since
104 22 Peter Klein
	# we want to display an icon BEFORE the link.
105 22 Peter Klein
	10 = LOAD_REGISTER
106 22 Peter Klein
	10.filelink.cObject = TEXT
107 22 Peter Klein
	10.filelink.cObject {
108 22 Peter Klein
		value = download stdWrap
109 22 Peter Klein
		typolink.parameter = fileadmin/templates/images/dwarf_male120x.gif
110 22 Peter Klein
		typolink.parameter.makeDownloadLink = 1
111 22 Peter Klein
	}
112 22 Peter Klein
	
113 22 Peter Klein
	# Display the fileicon and filelink
114 22 Peter Klein
	20 = CASE
115 22 Peter Klein
	20 {
116 22 Peter Klein
		# Wrapping of image, incl. the filelink from previously created register value
117 22 Peter Klein
		stdWrap.dataWrap = | {register:filelink}
118 22 Peter Klein
119 22 Peter Klein
		# Case key is the filetype (from register value)
120 22 Peter Klein
		key.data = register:filetype
121 22 Peter Klein
122 22 Peter Klein
		default = IMAGE
123 22 Peter Klein
		default.file = fileadmin/fileicons/default.gif
124 22 Peter Klein
125 22 Peter Klein
		gif < .default
126 22 Peter Klein
		gif.file = fileadmin/fileicons/gif.gif
127 22 Peter Klein
		# You can add more types here
128 22 Peter Klein
	}
129 22 Peter Klein
	
130 22 Peter Klein
	# Display the filesize ( from register value)
131 22 Peter Klein
	30 = TEXT
132 22 Peter Klein
	30.data = register:filesize
133 22 Peter Klein
	30.bytes = 1
134 22 Peter Klein
	30.wrap = &nbsp;(|)
135 22 Peter Klein
}
136 22 Peter Klein
</pre>
137 22 Peter Klein
138 14 Peter Klein
139 16 Peter Klein
h2. Enabling the functionality for links created in the RTE.
140 14 Peter Klein
141 14 Peter Klein
Since the extension works on standard typolink generated links, it's quite easy to implement it for RTE generated links too. Just add the following line to your Typoscript Setup:
142 14 Peter Klein
143 14 Peter Klein
<pre>
144 17 Peter Klein
lib.parseFunc_RTE.tags.link.typolink.parameter.postUserFunc = tx_pmkfdl->makeDownloadLink
145 14 Peter Klein
</pre>
146 14 Peter Klein
147 10 Peter Klein
h2. Known Problems
148 1
149 10 Peter Klein
Due to a (still unfixed) bug in interface.tslib_content_stdwraphook.php (See Bugtracker http://bugs.typo3.org/view.php?id=9058), it is recommended to use the extension as a userFunc until this bug is fixed! 
150 9 Peter Klein
151 10 Peter Klein
_The bug still exists 1.5 years after reporting it, so I guess bugfixing is not high on the TYPO3 core members priority list :(_