... | ... |
@@ -111,6 +111,12 @@ $GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
111 | 111 |
'flag' => 6, |
112 | 112 |
'sql' => "int(10) unsigned NOT NULL default '0'" |
113 | 113 |
), |
114 |
+ 'opened' => array |
|
115 |
+ ( |
|
116 |
+ 'exclude' => true, |
|
117 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['opened'], |
|
118 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
119 |
+ ), |
|
114 | 120 |
/*'name' => array |
115 | 121 |
( |
116 | 122 |
'exclude' => true, |
... | ... |
@@ -11,13 +11,16 @@ |
11 | 11 |
/** |
12 | 12 |
* Table tl_member_secureDownloads |
13 | 13 |
*/ |
14 |
+ |
|
15 |
+use Contao\DC_Table; |
|
16 |
+ |
|
14 | 17 |
$GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
15 | 18 |
( |
16 | 19 |
|
17 | 20 |
// Config |
18 | 21 |
'config' => array |
19 | 22 |
( |
20 |
- 'dataContainer' => 'Table', |
|
23 |
+ 'dataContainer' => DC_Table::class, |
|
21 | 24 |
'ptable' => 'tl_member', |
22 | 25 |
'closed' => true, |
23 | 26 |
'doNotCopyRecords' => true, |
... | ... |
@@ -107,7 +107,7 @@ $GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
107 | 107 |
'flag' => 6, |
108 | 108 |
'sql' => "int(10) unsigned NOT NULL default '0'" |
109 | 109 |
), |
110 |
- 'name' => array |
|
110 |
+ /*'name' => array |
|
111 | 111 |
( |
112 | 112 |
'exclude' => true, |
113 | 113 |
'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['name'], |
... | ... |
@@ -115,8 +115,8 @@ $GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
115 | 115 |
'flag' => 1, |
116 | 116 |
'inputType' => 'text', |
117 | 117 |
'eval' => array('mandatory' => true, 'maxlength' => 255, 'decodeEntities' => true, 'doNotSaveEmpty' => true), |
118 |
-// 'sql' => "varchar(255) NOT NULL default ''" |
|
119 |
- ), |
|
118 |
+ 'sql' => "varchar(255) NOT NULL default ''" |
|
119 |
+ ),*/ |
|
120 | 120 |
/*'path' => array |
121 | 121 |
( |
122 | 122 |
'sql' => "varchar(1022) NOT NULL default ''", |
... | ... |
@@ -20,6 +20,7 @@ $GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
20 | 20 |
'dataContainer' => 'Table', |
21 | 21 |
'ptable' => 'tl_member', |
22 | 22 |
'closed' => true, |
23 |
+ 'doNotCopyRecords' => true, |
|
23 | 24 |
'sql' => array |
24 | 25 |
( |
25 | 26 |
'keys' => array |
... | ... |
@@ -93,7 +94,7 @@ $GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
93 | 94 |
( |
94 | 95 |
'foreignKey' => 'tl_files.name', |
95 | 96 |
'sql' => "binary(16) NULL", |
96 |
- 'relation' => array('type' => 'belongsTo', 'load' => 'eager', 'field' => 'uuid') |
|
97 |
+ 'relation' => array('type' => 'belongsTo', 'load' => 'lazy', 'field' => 'uuid') |
|
97 | 98 |
), |
98 | 99 |
'tstamp' => array |
99 | 100 |
( |
... | ... |
@@ -14,295 +14,115 @@ |
14 | 14 |
$GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
15 | 15 |
( |
16 | 16 |
|
17 |
- // Config |
|
18 |
- 'config' => array |
|
19 |
- ( |
|
20 |
- 'dataContainer' => 'Table', |
|
21 |
- 'ptable' => 'tl_member', |
|
22 |
- 'closed' => true, |
|
23 |
- 'ondelete_callback' => array |
|
17 |
+ // Config |
|
18 |
+ 'config' => array |
|
24 | 19 |
( |
25 |
- array('tl_member_secureDownloads','deleteFileCallback') |
|
20 |
+ 'dataContainer' => 'Table', |
|
21 |
+ 'ptable' => 'tl_member', |
|
22 |
+ 'closed' => true, |
|
23 |
+ 'sql' => array |
|
24 |
+ ( |
|
25 |
+ 'keys' => array |
|
26 |
+ ( |
|
27 |
+ 'id' => 'primary', |
|
28 |
+ 'pid' => 'index' |
|
29 |
+ ) |
|
30 |
+ ) |
|
26 | 31 |
), |
27 |
- 'sql' => array |
|
28 |
- ( |
|
29 |
- 'keys' => array |
|
30 |
- ( |
|
31 |
- 'id' => 'primary', |
|
32 |
- 'pid' => 'index' |
|
33 |
- ) |
|
34 |
- ) |
|
35 |
- ), |
|
36 | 32 |
|
37 |
- // List |
|
38 |
- 'list' => array |
|
39 |
- ( |
|
40 |
- 'sorting' => array |
|
41 |
- ( |
|
42 |
- 'mode' => 4, |
|
43 |
- 'fields' => array('ctime'), |
|
44 |
- 'headerFields' => array('firstname','lastname', 'username','memberno'), |
|
45 |
- 'disableGrouping' => false, |
|
46 |
- 'flag' => 6, |
|
47 |
- 'panelLayout' => 'filter;sort,search,limit', |
|
48 |
- 'child_record_callback' => array('tl_member_secureDownloads','listDownloads') |
|
49 |
- ), |
|
50 |
- 'global_operations' => array |
|
51 |
- ( |
|
52 |
- |
|
53 |
- ), |
|
54 |
- 'operations' => array |
|
55 |
- ( |
|
56 |
- 'edit' => array |
|
57 |
- ( |
|
58 |
- 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['edit'], |
|
59 |
- 'href' => 'act=edit', |
|
60 |
- 'icon' => 'edit.gif', |
|
61 |
- 'button_callback' => array('tl_member_secureDownloads', 'editFile') |
|
62 |
-), |
|
63 |
- 'delete' => array |
|
64 |
- ( |
|
65 |
- 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['delete'], |
|
66 |
- 'href' => 'act=delete', |
|
67 |
- 'icon' => 'delete.gif', |
|
68 |
- 'button_callback' => array('tl_member_secureDownloads', 'deleteFile') |
|
69 |
- ), |
|
70 |
- 'show' => array |
|
71 |
- ( |
|
72 |
- 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'], |
|
73 |
- 'icon' => 'show.gif', |
|
74 |
- 'button_callback' => array('tl_member_secureDownloads', 'showFile') |
|
75 |
- ), |
|
76 |
- ) |
|
77 |
- ), |
|
78 |
- |
|
79 |
- // Palettes |
|
80 |
- 'palettes' => array |
|
81 |
- ( |
|
82 |
- 'default' => '{sec_dl_legend},name' |
|
83 |
- ), |
|
84 |
- |
|
85 |
- // Subpalettes |
|
86 |
- 'subpalettes' => array |
|
87 |
- ( |
|
88 |
- ), |
|
89 |
- |
|
90 |
- // Fields |
|
91 |
- 'fields' => array |
|
92 |
- ( |
|
93 |
- 'id' => array |
|
94 |
- ( |
|
95 |
- 'sql' => "int(10) unsigned NOT NULL auto_increment" |
|
96 |
- ), |
|
97 |
- 'pid' => array |
|
98 |
- ( |
|
99 |
- 'foreignKey' => 'tl_member.name', |
|
100 |
- 'sql' => "int(10) unsigned NOT NULL default '0'", |
|
101 |
- 'relation' => array('type'=>'belongsTo', 'load'=>'lazy') |
|
102 |
- ), |
|
103 |
- 'uuid' => array |
|
33 |
+ // List |
|
34 |
+ 'list' => array |
|
104 | 35 |
( |
105 |
- 'foreignKey' => 'tl_files.name', |
|
106 |
- 'sql' => "binary(16) NULL", |
|
107 |
- 'relation' => array('type'=>'belongsTo', 'load'=>'eager', 'field'=>'uuid') |
|
36 |
+ 'sorting' => array |
|
37 |
+ ( |
|
38 |
+ 'mode' => 4, |
|
39 |
+ 'fields' => array('ctime'), |
|
40 |
+ 'headerFields' => array('firstname', 'lastname', 'username', 'memberno'), |
|
41 |
+ 'disableGrouping' => false, |
|
42 |
+ 'flag' => 6, |
|
43 |
+ 'panelLayout' => 'filter;sort,search,limit', |
|
44 |
+ ), |
|
45 |
+ 'global_operations' => array |
|
46 |
+ (), |
|
47 |
+ 'operations' => array |
|
48 |
+ ( |
|
49 |
+ 'edit' => array |
|
50 |
+ ( |
|
51 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['edit'], |
|
52 |
+ 'href' => 'act=edit', |
|
53 |
+ 'icon' => 'edit.gif', |
|
54 |
+ ), |
|
55 |
+ 'delete' => array |
|
56 |
+ ( |
|
57 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['delete'], |
|
58 |
+ 'href' => 'act=delete', |
|
59 |
+ 'icon' => 'delete.gif', |
|
60 |
+ ), |
|
61 |
+ 'show' => array |
|
62 |
+ ( |
|
63 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'], |
|
64 |
+ 'icon' => 'show.gif', |
|
65 |
+ ), |
|
66 |
+ ) |
|
108 | 67 |
), |
109 |
- 'tstamp' => array |
|
110 |
- ( |
|
111 |
- 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
112 |
- ), |
|
113 |
- 'ctime' => array |
|
114 |
- ( |
|
115 |
- 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['ctime'], |
|
116 |
- 'sorting' => true, |
|
117 |
- 'flag' => 6, |
|
118 |
- 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
119 |
- ), |
|
120 |
- 'name' => array |
|
121 |
- ( |
|
122 |
- 'exclude' => true, |
|
123 |
- 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['name'], |
|
124 |
- 'sorting' => true, |
|
125 |
- 'flag' => 1, |
|
126 |
- 'inputType' => 'text', |
|
127 |
- 'eval' => array('mandatory'=>true, 'maxlength'=>255, 'decodeEntities'=>true, 'doNotSaveEmpty'=>true), |
|
128 |
- 'load_callback' => array |
|
129 |
- ( |
|
130 |
- array('tl_member_secureDownloads', 'getFilename') |
|
131 |
- ), |
|
132 |
- 'save_callback' => array |
|
133 |
- ( |
|
134 |
- array('tl_member_secureDownloads', 'checkFilename') |
|
135 |
- ), |
|
136 |
-// 'sql' => "varchar(255) NOT NULL default ''" |
|
137 |
- ), |
|
138 |
- /*'path' => array |
|
139 |
- ( |
|
140 |
- 'sql' => "varchar(1022) NOT NULL default ''", |
|
141 |
- ),*/ |
|
142 |
- 'nc_sent' => array |
|
68 |
+ |
|
69 |
+ // Palettes |
|
70 |
+ 'palettes' => array |
|
143 | 71 |
( |
144 |
- 'sql' => "char(1) NOT NULL default ''" |
|
72 |
+ 'default' => '{sec_dl_legend},name' |
|
145 | 73 |
), |
146 |
- ) |
|
147 |
-); |
|
148 |
- |
|
149 |
- |
|
150 |
-class tl_member_secureDownloads extends \Backend |
|
151 |
-{ |
|
152 |
- /** |
|
153 |
- * Import the back end user object |
|
154 |
- */ |
|
155 |
- public function __construct() |
|
156 |
- { |
|
157 |
- parent::__construct(); |
|
158 |
- $this->import('BackendUser', 'User'); |
|
159 |
- } |
|
160 |
- |
|
161 |
- public function listDownloads($arrRow) |
|
162 |
- { |
|
163 |
- $objSecFile = \SecureDownloadsModel::findByPk($arrRow['id']); |
|
164 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
165 |
- |
|
166 |
- return '<div class="tl_content_left">' . ($objFile !== null ? $objFile->name : '') . ' <span style="color:#b3b3b3;padding-left:3px">[' . Date::parse(Config::get('datimFormat'), $arrRow['ctime']) . ']</span></div>'; |
|
167 |
- } |
|
168 |
- |
|
169 |
- public function editFile($row, $href, $label, $title, $icon, $attributes) |
|
170 |
- { |
|
171 |
- if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access')) |
|
172 |
- { |
|
173 |
- return ''; |
|
174 |
- } |
|
175 |
- |
|
176 |
- $objSecFile = \SecureDownloadsModel::findByPk($row['id']); |
|
177 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
178 |
- $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['edit'][1],$objFile->name); |
|
179 |
- |
|
180 |
- $href .= '&id='.$row['id']; |
|
181 |
- |
|
182 |
- return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'">'.Image::getHtml($icon, $label).'</a> '; |
|
183 |
- } |
|
184 |
- |
|
185 |
- public function deleteFile($row, $href, $label, $title, $icon, $attributes) |
|
186 |
- { |
|
187 |
- if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access')) |
|
188 |
- { |
|
189 |
- return ''; |
|
190 |
- } |
|
191 |
- |
|
192 |
- $objSecFile = \SecureDownloadsModel::findByPk($row['id']); |
|
193 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
194 |
- $attributes = ' onclick="if(!confirm(\'' . sprintf($GLOBALS['TL_LANG']['MSC']['deleteConfirmFile'],$objFile->name) . '\'))return false;Backend.getScrollOffset()"'; |
|
195 |
- $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['delete'][1],$objFile->name); |
|
196 |
- |
|
197 |
- $href .= '&id='.$row['id']; |
|
198 | 74 |
|
199 |
- return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> '; |
|
200 |
- } |
|
75 |
+ // Subpalettes |
|
76 |
+ 'subpalettes' => array |
|
77 |
+ (), |
|
201 | 78 |
|
202 |
- public function showFile($row, $href, $label, $title, $icon, $attributes) |
|
203 |
- { |
|
204 |
- if (Input::get('popup')) |
|
205 |
- { |
|
206 |
- return ''; |
|
207 |
- } |
|
208 |
- else |
|
209 |
- { |
|
210 |
- $objSecFile = \SecureDownloadsModel::findByPk($row['id']); |
|
211 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
212 |
- $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'][1],$objFile->name); |
|
213 |
- |
|
214 |
- if ($objFile !== null) |
|
215 |
- { |
|
216 |
- return '<a href="contao/popup.php?src=' . base64_encode($objFile->path) . '" title="'.specialchars($title, false, true).'"'.$attributes.' onclick="Backend.openModalIframe({\'width\':600,\'title\':\''.str_replace("'", "\\'", specialchars($objFile->name, false, true)).'\',\'url\':this.href,\'height\':300});return false">'.Image::getHtml($icon, $label).'</a> '; |
|
217 |
- } else { |
|
218 |
- return ''; |
|
219 |
- } |
|
220 |
- } |
|
221 |
- } |
|
222 |
- |
|
223 |
- public function deleteFileCallback(DataContainer $dc) |
|
224 |
- { |
|
225 |
- $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
226 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
227 |
- |
|
228 |
- if ($objFile !== null) { |
|
229 |
- $File = new \File($objFile->path,true); |
|
230 |
- $File->delete(); |
|
231 |
- } |
|
232 |
- } |
|
233 |
- |
|
234 |
- public function getFilename($varValue, DataContainer $dc) |
|
235 |
- { |
|
236 |
- $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
237 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
238 |
- |
|
239 |
- if ($objFile !== null) { |
|
240 |
- return $objFile->name; |
|
241 |
- } |
|
242 |
- |
|
243 |
- return null; |
|
244 |
- } |
|
245 |
- |
|
246 |
- /** |
|
247 |
- * Check a file name and romanize it |
|
248 |
- * |
|
249 |
- * @param string $varValue |
|
250 |
- * @param DataContainer|DC_Folder $dc |
|
251 |
- * |
|
252 |
- * @return mixed |
|
253 |
- * |
|
254 |
- * @throws Exception |
|
255 |
- */ |
|
256 |
- public function checkFilename($varValue, DataContainer $dc) |
|
257 |
- { |
|
258 |
- $varValue = utf8_romanize($varValue); |
|
259 |
- $varValue = str_replace('"', '', $varValue); |
|
260 |
- |
|
261 |
- if (strpos($varValue, '/') !== false || preg_match('/\.$/', $varValue)) |
|
262 |
- { |
|
263 |
- throw new Exception($GLOBALS['TL_LANG']['ERR']['invalidName']); |
|
264 |
- } |
|
265 |
- |
|
266 |
- // Check the length without the file extension |
|
267 |
- if ($dc->activeRecord && $varValue != '') |
|
268 |
- { |
|
269 |
- $intMaxlength = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['maxlength']; |
|
270 |
- |
|
271 |
- if ($dc->activeRecord->type == 'file') |
|
272 |
- { |
|
273 |
- $intMaxlength -= (strlen($dc->activeRecord->extension) + 1); |
|
274 |
- } |
|
275 |
- |
|
276 |
- if ($intMaxlength && utf8_strlen($varValue) > $intMaxlength) |
|
277 |
- { |
|
278 |
- throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['maxlength'], $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['label'][0], $intMaxlength)); |
|
279 |
- } |
|
280 |
- } |
|
281 |
- |
|
282 |
- $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
283 |
- $objFile = $objSecFile->getRelated('uuid'); |
|
284 |
- $File = new \File($objFile->path,true); |
|
285 |
- |
|
286 |
- if (!$File->exists()) |
|
287 |
- { |
|
288 |
- throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'],'1'.$varValue)); |
|
289 |
- } |
|
290 |
- |
|
291 |
- $strDirectory = dirname($objFile->path); |
|
292 |
- if (!$File->renameTo($strDirectory.'/'.$varValue)) |
|
293 |
- { |
|
294 |
- throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'],'2'.$varValue)); |
|
295 |
- } |
|
296 |
- |
|
297 |
- if (($objFile = $File->getModel()) !== null) { |
|
298 |
- $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
299 |
- |
|
300 |
- if ($objSecFile !== null){ |
|
301 |
- $objSecFile->uuid = $objFile->uuid; |
|
302 |
- $objSecFile->save(); |
|
303 |
- } |
|
304 |
- } |
|
305 |
- |
|
306 |
- return null; |
|
307 |
- } |
|
308 |
-} |
|
79 |
+ // Fields |
|
80 |
+ 'fields' => array |
|
81 |
+ ( |
|
82 |
+ 'id' => array |
|
83 |
+ ( |
|
84 |
+ 'sql' => "int(10) unsigned NOT NULL auto_increment" |
|
85 |
+ ), |
|
86 |
+ 'pid' => array |
|
87 |
+ ( |
|
88 |
+ 'foreignKey' => 'tl_member.name', |
|
89 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'", |
|
90 |
+ 'relation' => array('type' => 'belongsTo', 'load' => 'lazy') |
|
91 |
+ ), |
|
92 |
+ 'uuid' => array |
|
93 |
+ ( |
|
94 |
+ 'foreignKey' => 'tl_files.name', |
|
95 |
+ 'sql' => "binary(16) NULL", |
|
96 |
+ 'relation' => array('type' => 'belongsTo', 'load' => 'eager', 'field' => 'uuid') |
|
97 |
+ ), |
|
98 |
+ 'tstamp' => array |
|
99 |
+ ( |
|
100 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
101 |
+ ), |
|
102 |
+ 'ctime' => array |
|
103 |
+ ( |
|
104 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['ctime'], |
|
105 |
+ 'sorting' => true, |
|
106 |
+ 'flag' => 6, |
|
107 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
108 |
+ ), |
|
109 |
+ 'name' => array |
|
110 |
+ ( |
|
111 |
+ 'exclude' => true, |
|
112 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['name'], |
|
113 |
+ 'sorting' => true, |
|
114 |
+ 'flag' => 1, |
|
115 |
+ 'inputType' => 'text', |
|
116 |
+ 'eval' => array('mandatory' => true, 'maxlength' => 255, 'decodeEntities' => true, 'doNotSaveEmpty' => true), |
|
117 |
+// 'sql' => "varchar(255) NOT NULL default ''" |
|
118 |
+ ), |
|
119 |
+ /*'path' => array |
|
120 |
+ ( |
|
121 |
+ 'sql' => "varchar(1022) NOT NULL default ''", |
|
122 |
+ ),*/ |
|
123 |
+ 'nc_sent' => array |
|
124 |
+ ( |
|
125 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
126 |
+ ), |
|
127 |
+ ) |
|
128 |
+); |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,308 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * SecureDownloads for Contao |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2017 Benjamin Roth |
|
7 |
+ * |
|
8 |
+ * @license commercial |
|
9 |
+ */ |
|
10 |
+ |
|
11 |
+/** |
|
12 |
+ * Table tl_member_secureDownloads |
|
13 |
+ */ |
|
14 |
+$GLOBALS['TL_DCA']['tl_member_secureDownloads'] = array |
|
15 |
+( |
|
16 |
+ |
|
17 |
+ // Config |
|
18 |
+ 'config' => array |
|
19 |
+ ( |
|
20 |
+ 'dataContainer' => 'Table', |
|
21 |
+ 'ptable' => 'tl_member', |
|
22 |
+ 'closed' => true, |
|
23 |
+ 'ondelete_callback' => array |
|
24 |
+ ( |
|
25 |
+ array('tl_member_secureDownloads','deleteFileCallback') |
|
26 |
+ ), |
|
27 |
+ 'sql' => array |
|
28 |
+ ( |
|
29 |
+ 'keys' => array |
|
30 |
+ ( |
|
31 |
+ 'id' => 'primary', |
|
32 |
+ 'pid' => 'index' |
|
33 |
+ ) |
|
34 |
+ ) |
|
35 |
+ ), |
|
36 |
+ |
|
37 |
+ // List |
|
38 |
+ 'list' => array |
|
39 |
+ ( |
|
40 |
+ 'sorting' => array |
|
41 |
+ ( |
|
42 |
+ 'mode' => 4, |
|
43 |
+ 'fields' => array('ctime'), |
|
44 |
+ 'headerFields' => array('firstname','lastname', 'username','memberno'), |
|
45 |
+ 'disableGrouping' => false, |
|
46 |
+ 'flag' => 6, |
|
47 |
+ 'panelLayout' => 'filter;sort,search,limit', |
|
48 |
+ 'child_record_callback' => array('tl_member_secureDownloads','listDownloads') |
|
49 |
+ ), |
|
50 |
+ 'global_operations' => array |
|
51 |
+ ( |
|
52 |
+ |
|
53 |
+ ), |
|
54 |
+ 'operations' => array |
|
55 |
+ ( |
|
56 |
+ 'edit' => array |
|
57 |
+ ( |
|
58 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['edit'], |
|
59 |
+ 'href' => 'act=edit', |
|
60 |
+ 'icon' => 'edit.gif', |
|
61 |
+ 'button_callback' => array('tl_member_secureDownloads', 'editFile') |
|
62 |
+), |
|
63 |
+ 'delete' => array |
|
64 |
+ ( |
|
65 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['delete'], |
|
66 |
+ 'href' => 'act=delete', |
|
67 |
+ 'icon' => 'delete.gif', |
|
68 |
+ 'button_callback' => array('tl_member_secureDownloads', 'deleteFile') |
|
69 |
+ ), |
|
70 |
+ 'show' => array |
|
71 |
+ ( |
|
72 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'], |
|
73 |
+ 'icon' => 'show.gif', |
|
74 |
+ 'button_callback' => array('tl_member_secureDownloads', 'showFile') |
|
75 |
+ ), |
|
76 |
+ ) |
|
77 |
+ ), |
|
78 |
+ |
|
79 |
+ // Palettes |
|
80 |
+ 'palettes' => array |
|
81 |
+ ( |
|
82 |
+ 'default' => '{sec_dl_legend},name' |
|
83 |
+ ), |
|
84 |
+ |
|
85 |
+ // Subpalettes |
|
86 |
+ 'subpalettes' => array |
|
87 |
+ ( |
|
88 |
+ ), |
|
89 |
+ |
|
90 |
+ // Fields |
|
91 |
+ 'fields' => array |
|
92 |
+ ( |
|
93 |
+ 'id' => array |
|
94 |
+ ( |
|
95 |
+ 'sql' => "int(10) unsigned NOT NULL auto_increment" |
|
96 |
+ ), |
|
97 |
+ 'pid' => array |
|
98 |
+ ( |
|
99 |
+ 'foreignKey' => 'tl_member.name', |
|
100 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'", |
|
101 |
+ 'relation' => array('type'=>'belongsTo', 'load'=>'lazy') |
|
102 |
+ ), |
|
103 |
+ 'uuid' => array |
|
104 |
+ ( |
|
105 |
+ 'foreignKey' => 'tl_files.name', |
|
106 |
+ 'sql' => "binary(16) NULL", |
|
107 |
+ 'relation' => array('type'=>'belongsTo', 'load'=>'eager', 'field'=>'uuid') |
|
108 |
+ ), |
|
109 |
+ 'tstamp' => array |
|
110 |
+ ( |
|
111 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
112 |
+ ), |
|
113 |
+ 'ctime' => array |
|
114 |
+ ( |
|
115 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['ctime'], |
|
116 |
+ 'sorting' => true, |
|
117 |
+ 'flag' => 6, |
|
118 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
119 |
+ ), |
|
120 |
+ 'name' => array |
|
121 |
+ ( |
|
122 |
+ 'exclude' => true, |
|
123 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member_secureDownloads']['name'], |
|
124 |
+ 'sorting' => true, |
|
125 |
+ 'flag' => 1, |
|
126 |
+ 'inputType' => 'text', |
|
127 |
+ 'eval' => array('mandatory'=>true, 'maxlength'=>255, 'decodeEntities'=>true, 'doNotSaveEmpty'=>true), |
|
128 |
+ 'load_callback' => array |
|
129 |
+ ( |
|
130 |
+ array('tl_member_secureDownloads', 'getFilename') |
|
131 |
+ ), |
|
132 |
+ 'save_callback' => array |
|
133 |
+ ( |
|
134 |
+ array('tl_member_secureDownloads', 'checkFilename') |
|
135 |
+ ), |
|
136 |
+// 'sql' => "varchar(255) NOT NULL default ''" |
|
137 |
+ ), |
|
138 |
+ /*'path' => array |
|
139 |
+ ( |
|
140 |
+ 'sql' => "varchar(1022) NOT NULL default ''", |
|
141 |
+ ),*/ |
|
142 |
+ 'nc_sent' => array |
|
143 |
+ ( |
|
144 |
+ 'sql' => "char(1) NOT NULL default ''" |
|
145 |
+ ), |
|
146 |
+ ) |
|
147 |
+); |
|
148 |
+ |
|
149 |
+ |
|
150 |
+class tl_member_secureDownloads extends \Backend |
|
151 |
+{ |
|
152 |
+ /** |
|
153 |
+ * Import the back end user object |
|
154 |
+ */ |
|
155 |
+ public function __construct() |
|
156 |
+ { |
|
157 |
+ parent::__construct(); |
|
158 |
+ $this->import('BackendUser', 'User'); |
|
159 |
+ } |
|
160 |
+ |
|
161 |
+ public function listDownloads($arrRow) |
|
162 |
+ { |
|
163 |
+ $objSecFile = \SecureDownloadsModel::findByPk($arrRow['id']); |
|
164 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
165 |
+ |
|
166 |
+ return '<div class="tl_content_left">' . ($objFile !== null ? $objFile->name : '') . ' <span style="color:#b3b3b3;padding-left:3px">[' . Date::parse(Config::get('datimFormat'), $arrRow['ctime']) . ']</span></div>'; |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ public function editFile($row, $href, $label, $title, $icon, $attributes) |
|
170 |
+ { |
|
171 |
+ if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access')) |
|
172 |
+ { |
|
173 |
+ return ''; |
|
174 |
+ } |
|
175 |
+ |
|
176 |
+ $objSecFile = \SecureDownloadsModel::findByPk($row['id']); |
|
177 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
178 |
+ $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['edit'][1],$objFile->name); |
|
179 |
+ |
|
180 |
+ $href .= '&id='.$row['id']; |
|
181 |
+ |
|
182 |
+ return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'">'.Image::getHtml($icon, $label).'</a> '; |
|
183 |
+ } |
|
184 |
+ |
|
185 |
+ public function deleteFile($row, $href, $label, $title, $icon, $attributes) |
|
186 |
+ { |
|
187 |
+ if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access')) |
|
188 |
+ { |
|
189 |
+ return ''; |
|
190 |
+ } |
|
191 |
+ |
|
192 |
+ $objSecFile = \SecureDownloadsModel::findByPk($row['id']); |
|
193 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
194 |
+ $attributes = ' onclick="if(!confirm(\'' . sprintf($GLOBALS['TL_LANG']['MSC']['deleteConfirmFile'],$objFile->name) . '\'))return false;Backend.getScrollOffset()"'; |
|
195 |
+ $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['delete'][1],$objFile->name); |
|
196 |
+ |
|
197 |
+ $href .= '&id='.$row['id']; |
|
198 |
+ |
|
199 |
+ return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> '; |
|
200 |
+ } |
|
201 |
+ |
|
202 |
+ public function showFile($row, $href, $label, $title, $icon, $attributes) |
|
203 |
+ { |
|
204 |
+ if (Input::get('popup')) |
|
205 |
+ { |
|
206 |
+ return ''; |
|
207 |
+ } |
|
208 |
+ else |
|
209 |
+ { |
|
210 |
+ $objSecFile = \SecureDownloadsModel::findByPk($row['id']); |
|
211 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
212 |
+ $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'][1],$objFile->name); |
|
213 |
+ |
|
214 |
+ if ($objFile !== null) |
|
215 |
+ { |
|
216 |
+ return '<a href="contao/popup.php?src=' . base64_encode($objFile->path) . '" title="'.specialchars($title, false, true).'"'.$attributes.' onclick="Backend.openModalIframe({\'width\':600,\'title\':\''.str_replace("'", "\\'", specialchars($objFile->name, false, true)).'\',\'url\':this.href,\'height\':300});return false">'.Image::getHtml($icon, $label).'</a> '; |
|
217 |
+ } else { |
|
218 |
+ return ''; |
|
219 |
+ } |
|
220 |
+ } |
|
221 |
+ } |
|
222 |
+ |
|
223 |
+ public function deleteFileCallback(DataContainer $dc) |
|
224 |
+ { |
|
225 |
+ $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
226 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
227 |
+ |
|
228 |
+ if ($objFile !== null) { |
|
229 |
+ $File = new \File($objFile->path,true); |
|
230 |
+ $File->delete(); |
|
231 |
+ } |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ public function getFilename($varValue, DataContainer $dc) |
|
235 |
+ { |
|
236 |
+ $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
237 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
238 |
+ |
|
239 |
+ if ($objFile !== null) { |
|
240 |
+ return $objFile->name; |
|
241 |
+ } |
|
242 |
+ |
|
243 |
+ return null; |
|
244 |
+ } |
|
245 |
+ |
|
246 |
+ /** |
|
247 |
+ * Check a file name and romanize it |
|
248 |
+ * |
|
249 |
+ * @param string $varValue |
|
250 |
+ * @param DataContainer|DC_Folder $dc |
|
251 |
+ * |
|
252 |
+ * @return mixed |
|
253 |
+ * |
|
254 |
+ * @throws Exception |
|
255 |
+ */ |
|
256 |
+ public function checkFilename($varValue, DataContainer $dc) |
|
257 |
+ { |
|
258 |
+ $varValue = utf8_romanize($varValue); |
|
259 |
+ $varValue = str_replace('"', '', $varValue); |
|
260 |
+ |
|
261 |
+ if (strpos($varValue, '/') !== false || preg_match('/\.$/', $varValue)) |
|
262 |
+ { |
|
263 |
+ throw new Exception($GLOBALS['TL_LANG']['ERR']['invalidName']); |
|
264 |
+ } |
|
265 |
+ |
|
266 |
+ // Check the length without the file extension |
|
267 |
+ if ($dc->activeRecord && $varValue != '') |
|
268 |
+ { |
|
269 |
+ $intMaxlength = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['maxlength']; |
|
270 |
+ |
|
271 |
+ if ($dc->activeRecord->type == 'file') |
|
272 |
+ { |
|
273 |
+ $intMaxlength -= (strlen($dc->activeRecord->extension) + 1); |
|
274 |
+ } |
|
275 |
+ |
|
276 |
+ if ($intMaxlength && utf8_strlen($varValue) > $intMaxlength) |
|
277 |
+ { |
|
278 |
+ throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['maxlength'], $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['label'][0], $intMaxlength)); |
|
279 |
+ } |
|
280 |
+ } |
|
281 |
+ |
|
282 |
+ $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
283 |
+ $objFile = $objSecFile->getRelated('uuid'); |
|
284 |
+ $File = new \File($objFile->path,true); |
|
285 |
+ |
|
286 |
+ if (!$File->exists()) |
|
287 |
+ { |
|
288 |
+ throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'],'1'.$varValue)); |
|
289 |
+ } |
|
290 |
+ |
|
291 |
+ $strDirectory = dirname($objFile->path); |
|
292 |
+ if (!$File->renameTo($strDirectory.'/'.$varValue)) |
|
293 |
+ { |
|
294 |
+ throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'],'2'.$varValue)); |
|
295 |
+ } |
|
296 |
+ |
|
297 |
+ if (($objFile = $File->getModel()) !== null) { |
|
298 |
+ $objSecFile = \SecureDownloadsModel::findByPk($dc->id); |
|
299 |
+ |
|
300 |
+ if ($objSecFile !== null){ |
|
301 |
+ $objSecFile->uuid = $objFile->uuid; |
|
302 |
+ $objSecFile->save(); |
|
303 |
+ } |
|
304 |
+ } |
|
305 |
+ |
|
306 |
+ return null; |
|
307 |
+ } |
|
308 |
+} |