Browse code

Update

Benjamin Roth authored on26/07/2023 13:13:48
Showing14 changed files
... ...
@@ -18,7 +18,8 @@
18 18
         "contao/core-bundle": "^4.13",
19 19
         "symfony/config": "^5.4",
20 20
         "symfony/dependency-injection": "^5.4",
21
-        "symfony/http-kernel": "^5.4"
21
+        "symfony/http-kernel": "^5.4",
22
+        "terminal42/notification_center": "1.6.10"
22 23
     },
23 24
     "require-dev": {
24 25
         "bamarni/composer-bin-plugin": "^1.5",
... ...
@@ -43,7 +44,8 @@
43 44
         "allow-plugins": {
44 45
             "bamarni/composer-bin-plugin": true,
45 46
             "contao-components/installer": true,
46
-            "contao/manager-plugin": true
47
+            "contao/manager-plugin": true,
48
+            "contao-community-alliance/composer-plugin": true
47 49
         }
48 50
     },
49 51
     "extra": {
... ...
@@ -1,9 +1,11 @@
1 1
 <?php
2 2
 
3
-/**
4
- * SecureDownloads for Contao
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of memberfiles bundle.
5 7
  *
6
- * Copyright (c) 2017 Benjamin Roth
8
+ * (c) vonRotenberg
7 9
  *
8 10
  * @license commercial
9 11
  */
... ...
@@ -8,6 +8,7 @@
8 8
  * @license commercial
9 9
  */
10 10
 
11
+use vonRotenberg\MemberfilesBundle\Model\SecureDownloadsModel;
11 12
 
12 13
 /**
13 14
  * Config
... ...
@@ -20,46 +21,7 @@ $GLOBALS['TL_DCA']['tl_member']['config']['ctable'][] = 'tl_member_secureDownloa
20 21
 $GLOBALS['TL_DCA']['tl_member']['list']['operations']['secureDownloads'] = array
21 22
 (
22 23
   'label'               => &$GLOBALS['TL_LANG']['tl_member']['secureDownloads'],
23
-  'href'                => 'table='.\eSM_secureDownloads\SecureDownloadsModel::getTable(),
24
-  'icon'                => 'system/modules/eSM_secureDownloads/assets/images/sec_files.png',
25
-  'button_callback'     => array('tl_member_eSM_secureDownloads', 'showDownloads')
24
+  'href'                => 'table='.SecureDownloadsModel::getTable(),
25
+  'icon'                => 'bundles/vonrotenbergmemberfiles/images/sec_files.png',
26 26
 
27 27
 );
28
-
29
-
30
-class tl_member_eSM_secureDownloads extends \Backend
31
-{
32
-  /**
33
-   * Import the back end user object
34
-   */
35
-  public function __construct()
36
-  {
37
-    parent::__construct();
38
-    $this->import('BackendUser', 'User');
39
-  }
40
-
41
-
42
-  /**
43
-   * Generate a "showDownloads" button and return it as string
44
-   *
45
-   * @param array  $row
46
-   * @param string $href
47
-   * @param string $label
48
-   * @param string $title
49
-   * @param string $icon
50
-   *
51
-   * @return string
52
-   */
53
-  public function showDownloads($row, $href, $label, $title, $icon)
54
-  {
55
-    if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access'))
56
-    {
57
-      return '';
58
-    }
59
-
60
-    $href .= '&amp;id='.$row['id'];
61
-
62
-    return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'">'.Image::getHtml($icon, $label).'</a> ';
63
-  }
64
-
65
-}
66 28
\ No newline at end of file
... ...
@@ -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 .= '&amp;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 .= '&amp;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
+);
... ...
@@ -8,11 +8,19 @@
8 8
  * @license LGPL-3.0+
9 9
  */
10 10
 
11
+use Contao\CoreBundle\DataContainer\PaletteManipulator;
12
+
11 13
 /**
12 14
  * Palettes
13 15
  */
16
+
17
+PaletteManipulator::create()
18
+    ->addLegend('sec_dl_legend','publish_legend',PaletteManipulator::POSITION_BEFORE)
19
+    ->addField('secureDownloadsEnabled','sec_dl_legend',PaletteManipulator::POSITION_APPEND)
20
+    ->applyToPalette('root','tl_page')
21
+    ->applyToPalette('rootfallback','tl_page');
22
+
14 23
 $GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'secureDownloadsEnabled';
15
-$GLOBALS['TL_DCA']['tl_page']['palettes']['root'] = str_replace(';{publish_legend}', ';{sec_dl_legend},secureDownloadsEnabled;{publish_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['root']);
16 24
 $GLOBALS['TL_DCA']['tl_page']['subpalettes']['secureDownloadsEnabled'] = 'secureDownloadsSRC,secureDownloadsTarget,secureDownloadsRegExp,secureDownloadsFields,sd_nc_enable,sd_nc_notification';
17 25
 
18 26
 
... ...
@@ -82,55 +90,3 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['sd_nc_notification'] = array
82 90
   'eval'                      => array('mandatory'=>true,'includeBlankOption'=>true, 'chosen'=>true, 'tl_class'=>'w50'),
83 91
   'sql'                       => "int(10) unsigned NOT NULL default '0'"
84 92
 );
85
-
86
-class tl_page_eSM_secureDownloads extends \Backend
87
-{
88
-  /**
89
-   * Import the back end user object
90
-   */
91
-  public function __construct()
92
-  {
93
-    parent::__construct();
94
-    $this->import('BackendUser', 'User');
95
-  }
96
-
97
-  /**
98
-   * Return all fields of table tl_member
99
-   *
100
-   * @return array
101
-   */
102
-  public function getMemberProperties()
103
-  {
104
-    $return = array('id'=>'ID');
105
-
106
-    System::loadLanguageFile('tl_member');
107
-    $this->loadDataContainer('tl_member');
108
-
109
-    foreach ($GLOBALS['TL_DCA']['tl_member']['fields'] as $k=>$v)
110
-    {
111
-      if (is_array($v['label']))
112
-      {
113
-        $return[$k] = $GLOBALS['TL_DCA']['tl_member']['fields'][$k]['label'][0];
114
-      }
115
-    }
116
-
117
-    return $return;
118
-  }
119
-
120
-  /**
121
-   * Get notification choices
122
-   *
123
-   * @return array
124
-   */
125
-  public function getNotificationChoices()
126
-  {
127
-    $arrChoices = array();
128
-    $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='secDownloads_submitted' ORDER BY title");
129
-
130
-    while ($objNotifications->next()) {
131
-      $arrChoices[$objNotifications->id] = $objNotifications->title;
132
-    }
133
-
134
-    return $arrChoices;
135
-  }
136
-}
137 93
\ No newline at end of file
... ...
@@ -8,12 +8,16 @@
8 8
  * @license commercial
9 9
  */
10 10
 
11
+use Contao\CoreBundle\DataContainer\PaletteManipulator;
11 12
 
12 13
 /**
13 14
  * Extend a tl_user_group palette
14 15
  */
15
-$GLOBALS['TL_DCA']['tl_user']['palettes']['extend'] = str_replace(array('{account_legend}', '{account_legend:hide}'), '{sec_dl_legend:hide},sec_dl_access;{account_legend}', $GLOBALS['TL_DCA']['tl_user']['palettes']['extend']);
16
-$GLOBALS['TL_DCA']['tl_user']['palettes']['custom'] = str_replace(array('{account_legend}', '{account_legend:hide}'), '{sec_dl_legend:hide},sec_dl_access;{account_legend}', $GLOBALS['TL_DCA']['tl_user']['palettes']['custom']);
16
+PaletteManipulator::create()
17
+    ->addLegend('sec_dl_legend','account_legend',PaletteManipulator::POSITION_BEFORE)
18
+    ->addField('sec_dl_access','sec_dl_legend',PaletteManipulator::POSITION_APPEND)
19
+    ->applyToPalette('extend')
20
+    ->applyToPalette('custom');
17 21
 
18 22
 
19 23
 /**
... ...
@@ -27,4 +31,4 @@ $GLOBALS['TL_DCA']['tl_user']['fields']['sec_dl_access'] = array
27 31
     'inputType'             => 'checkbox',
28 32
     'sql'                   => "char(1) NOT NULL default ''"
29 33
 
30
-);
31 34
\ No newline at end of file
35
+);
... ...
@@ -8,12 +8,15 @@
8 8
  * @license commercial
9 9
  */
10 10
 
11
+use Contao\CoreBundle\DataContainer\PaletteManipulator;
11 12
 
12 13
 /**
13 14
  * Extend a tl_user_group palette
14 15
  */
15
-$GLOBALS['TL_DCA']['tl_user_group']['palettes']['default'] = str_replace(array('{alexf_legend}', '{alexf_legend:hide}'), '{sec_dl_legend:hide},sec_dl_access;{alexf_legend}', $GLOBALS['TL_DCA']['tl_user_group']['palettes']['default']);
16
-
16
+PaletteManipulator::create()
17
+    ->addLegend('sec_dl_legend','alexf_legend',PaletteManipulator::POSITION_BEFORE)
18
+    ->addField('sec_dl_access','sec_dl_legend',PaletteManipulator::POSITION_APPEND)
19
+    ->applyToPalette('default');
17 20
 
18 21
 /**
19 22
  * Add fields to tl_user_group
... ...
@@ -26,4 +29,4 @@ $GLOBALS['TL_DCA']['tl_user_group']['fields']['sec_dl_access'] = array
26 29
     'inputType'             => 'checkbox',
27 30
     'sql'                   => "char(1) NOT NULL default ''"
28 31
 
29
-);
30 32
\ No newline at end of file
33
+);
31 34
new file mode 100644
32 35
Binary files /dev/null and b/public/images/sec_files.png differ
... ...
@@ -10,7 +10,7 @@ declare(strict_types=1);
10 10
  * @license commercial
11 11
  */
12 12
 
13
-namespace VonRotenberg\MemberfilesBundle\ContaoManager;
13
+namespace vonRotenberg\MemberfilesBundle\ContaoManager;
14 14
 
15 15
 use Contao\CoreBundle\ContaoCoreBundle;
16 16
 use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
... ...
@@ -10,7 +10,7 @@ declare(strict_types=1);
10 10
  * @license commercial
11 11
  */
12 12
 
13
-namespace VonRotenberg\MemberfilesBundle\DependencyInjection;
13
+namespace vonRotenberg\MemberfilesBundle\DependencyInjection;
14 14
 
15 15
 use Symfony\Component\Config\FileLocator;
16 16
 use Symfony\Component\DependencyInjection\ContainerBuilder;
17 17
new file mode 100644
... ...
@@ -0,0 +1,64 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of memberfiles bundle.
7
+ *
8
+ * (c) vonRotenberg
9
+ *
10
+ * @license commercial
11
+ */
12
+
13
+namespace vonRotenberg\MemberfilesBundle\EventListener\DataContainer;
14
+
15
+use Contao\Backend;
16
+use Contao\BackendUser;
17
+use Contao\CoreBundle\ServiceAnnotation\Callback;
18
+use Contao\DataContainer;
19
+use Contao\File;
20
+use Contao\Image;
21
+use Contao\Input;
22
+use Contao\StringUtil;
23
+use Contao\System;
24
+use Contao\Date;
25
+use Contao\Config;
26
+use vonRotenberg\MemberfilesBundle\Model\SecureDownloadsModel;
27
+
28
+class MemberListener {
29
+
30
+    /**
31
+     * @var BackendUser
32
+     */
33
+    protected $User;
34
+
35
+    public function __construct()
36
+    {
37
+        $this->User = BackendUser::getInstance();
38
+    }
39
+
40
+    /**
41
+     * @Callback(table="tl_member", target="list.operations.secureDownloads.button"
42
+     */
43
+    public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44
+    {
45
+        if (Input::get('popup'))
46
+        {
47
+            return '';
48
+        } else
49
+        {
50
+            $objSecFile = SecureDownloadsModel::findByPk($row['id']);
51
+            $objFile = $objSecFile->getRelated('uuid');
52
+            $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'][1], $objFile->name);
53
+
54
+            if ($objFile !== null)
55
+            {
56
+                return '<a href="contao/popup.php?src=' . base64_encode($objFile->path) . '" title="' . StringUtil::specialchars($title, false, true) . '"' . $attributes . ' onclick="Backend.openModalIframe({\'width\':600,\'title\':\'' . str_replace("'", "\\'", StringUtil::specialchars($objFile->name, false, true)) . '\',\'url\':this.href,\'height\':300});return false">' . Image::getHtml($icon, $label) . '</a> ';
57
+            } else
58
+            {
59
+                return '';
60
+            }
61
+        }
62
+    }
63
+
64
+}
... ...
@@ -10,13 +10,20 @@ declare(strict_types=1);
10 10
  * @license commercial
11 11
  */
12 12
 
13
-namespace VonRotenberg\MemberfilesBundle\EventListener\DataContainer;
13
+namespace vonRotenberg\MemberfilesBundle\EventListener\DataContainer;
14 14
 
15
+use Contao\Backend;
15 16
 use Contao\BackendUser;
16 17
 use Contao\CoreBundle\ServiceAnnotation\Callback;
18
+use Contao\DataContainer;
19
+use Contao\File;
20
+use Contao\Image;
21
+use Contao\Input;
22
+use Contao\StringUtil;
17 23
 use Contao\System;
18 24
 use Contao\Date;
19 25
 use Contao\Config;
26
+use vonRotenberg\MemberfilesBundle\Model\SecureDownloadsModel;
20 27
 
21 28
 class MemberSecureDownloadsListener {
22 29
 
... ...
@@ -24,6 +31,7 @@ class MemberSecureDownloadsListener {
24 31
      * @var BackendUser
25 32
      */
26 33
     protected $User;
34
+
27 35
     public function __construct()
28 36
     {
29 37
         $this->User = BackendUser::getInstance();
... ...
@@ -39,4 +47,172 @@ class MemberSecureDownloadsListener {
39 47
 
40 48
         return '<div class="tl_content_left">' . ($objFile !== null ? $objFile->name : '') . ' <span style="color:#b3b3b3;padding-left:3px">[' . Date::parse(Config::get('datimFormat'), $row['ctime']) . ']</span></div>';
41 49
     }
50
+
51
+    /**
52
+     * @Callback(table="tl_member_secureDownloads", target="list.operations.edit.button"
53
+     */
54
+    public function onListEditOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
55
+    {
56
+        if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access'))
57
+        {
58
+            return '';
59
+        }
60
+
61
+        $objSecFile = SecureDownloadsModel::findByPk($row['id']);
62
+        $objFile = $objSecFile->getRelated('uuid');
63
+        $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['edit'][1],$objFile->name);
64
+
65
+        $href .= '&amp;id='.$row['id'];
66
+
67
+        return '<a href="'.Backend::addToUrl($href).'" title="'.StringUtil::specialchars($title).'">'.Image::getHtml($icon, $label).'</a> ';
68
+    }
69
+
70
+    /**
71
+     * @Callback(table="tl_member_secureDownloads", target="list.operations.delete.button"
72
+     */
73
+    public function onListDeleteOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
74
+    {
75
+        if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access'))
76
+        {
77
+            return '';
78
+        }
79
+
80
+        $objSecFile = SecureDownloadsModel::findByPk($row['id']);
81
+        $objFile = $objSecFile->getRelated('uuid');
82
+        $attributes = ' onclick="if(!confirm(\'' . sprintf($GLOBALS['TL_LANG']['MSC']['deleteConfirmFile'],$objFile->name) . '\'))return false;Backend.getScrollOffset()"';
83
+        $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['delete'][1],$objFile->name);
84
+
85
+        $href .= '&amp;id='.$row['id'];
86
+
87
+        return '<a href="'.Backend::addToUrl($href).'" title="'.StringUtil::specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ';
88
+    }
89
+
90
+    /**
91
+     * @Callback(table="tl_member_secureDownloads", target="list.operations.show.button"
92
+     */
93
+    public function onListShowOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
94
+    {
95
+        if (Input::get('popup'))
96
+        {
97
+            return '';
98
+        }
99
+        else
100
+        {
101
+            $objSecFile = SecureDownloadsModel::findByPk($row['id']);
102
+            $objFile = $objSecFile->getRelated('uuid');
103
+            $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'][1],$objFile->name);
104
+
105
+            if ($objFile !== null)
106
+            {
107
+                return '<a href="contao/popup.php?src=' . base64_encode($objFile->path) . '" title="'.StringUtil::specialchars($title, false, true).'"'.$attributes.' onclick="Backend.openModalIframe({\'width\':600,\'title\':\''.str_replace("'", "\\'", StringUtil::specialchars($objFile->name, false, true)).'\',\'url\':this.href,\'height\':300});return false">'.Image::getHtml($icon, $label).'</a> ';
108
+            } else {
109
+                return '';
110
+            }
111
+        }
112
+    }
113
+
114
+    /**
115
+     * @Callback(table="tl_member_secureDownloads", target="config.ondelete")
116
+     */
117
+    public function onConfigDeleteCallback(DataContainer $dc)
118
+    {
119
+        $objSecFile = SecureDownloadsModel::findByPk($dc->id);
120
+        $objFile = $objSecFile->getRelated('uuid');
121
+
122
+        if ($objFile !== null) {
123
+            $File = new File($objFile->path,true);
124
+            $File->delete();
125
+        }
126
+    }
127
+
128
+    /**
129
+     * @Callbacktable="tl_member_secureDownloads", target="fields.name.load")
130
+     */
131
+    public function onNameLoadCallback($varValue, DataContainer $dc)
132
+    {
133
+        $objSecFile = SecureDownloadsModel::findByPk($dc->id);
134
+        $objFile = $objSecFile->getRelated('uuid');
135
+
136
+        if ($objFile !== null) {
137
+            return $objFile->name;
138
+        }
139
+
140
+        return null;
141
+    }
142
+
143
+    /**
144
+     * @Callbacktable="tl_member_secureDownloads", target="fields.name.save")
145
+     */
146
+    public function onNameSaveCallback($varValue, DataContainer $dc)
147
+    {
148
+        $varValue = str_replace('"', '', $varValue);
149
+        $chunks = array_filter(explode('/', $varValue), 'strlen');
150
+
151
+        if (count($chunks) < 1)
152
+        {
153
+            return '';
154
+        }
155
+
156
+        // Only allow slashes when creating new folders
157
+        if ($dc->value != '__new__' && count($chunks) > 1)
158
+        {
159
+            throw new Exception($GLOBALS['TL_LANG']['ERR']['invalidName']);
160
+        }
161
+
162
+        foreach ($chunks as $chunk)
163
+        {
164
+            if (preg_match('/\.$/', $chunk))
165
+            {
166
+                throw new Exception($GLOBALS['TL_LANG']['ERR']['invalidName']);
167
+            }
168
+        }
169
+
170
+        // Check the length without the file extension
171
+        if ($dc->activeRecord)
172
+        {
173
+            $intMaxlength = $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['maxlength'] ?? null;
174
+
175
+            if ($intMaxlength)
176
+            {
177
+                if ($dc->activeRecord->type == 'file')
178
+                {
179
+                    $intMaxlength -= (strlen($dc->activeRecord->extension) + 1);
180
+                }
181
+
182
+                foreach ($chunks as $chunk)
183
+                {
184
+                    if (mb_strlen($chunk) > $intMaxlength)
185
+                    {
186
+                        throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['maxlength'], $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['label'][0], $intMaxlength));
187
+                    }
188
+                }
189
+            }
190
+        }
191
+
192
+        $objSecFile = SecureDownloadsModel::findByPk($dc->id);
193
+        $objFile = $objSecFile->getRelated('uuid');
194
+        $File = new File($objFile->path,true);
195
+
196
+        if (!$File->exists())
197
+        {
198
+            throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'],'1'.$varValue));
199
+        }
200
+
201
+        $strDirectory = dirname($objFile->path);
202
+        if (!$File->renameTo($strDirectory.'/'.$varValue))
203
+        {
204
+            throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['invalidFile'],'2'.$varValue));
205
+        }
206
+
207
+        if (($objFile = $File->getModel()) !== null) {
208
+            $objSecFile = \SecureDownloadsModel::findByPk($dc->id);
209
+
210
+            if ($objSecFile !== null){
211
+                $objSecFile->uuid = $objFile->uuid;
212
+                $objSecFile->save();
213
+            }
214
+        }
215
+
216
+        return null;
217
+    }
42 218
 }
43 219
new file mode 100644
... ...
@@ -0,0 +1,69 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of memberfiles bundle.
7
+ *
8
+ * (c) vonRotenberg
9
+ *
10
+ * @license commercial
11
+ */
12
+
13
+namespace vonRotenberg\MemberfilesBundle\EventListener\DataContainer;
14
+
15
+use Contao\BackendUser;
16
+use Contao\Controller;
17
+use Contao\CoreBundle\ServiceAnnotation\Callback;
18
+use Contao\DataContainer;
19
+use Contao\System;
20
+
21
+class PageListener {
22
+
23
+    /**
24
+     * @var BackendUser
25
+     */
26
+    protected $User;
27
+
28
+    public function __construct()
29
+    {
30
+        $this->User = BackendUser::getInstance();
31
+    }
32
+
33
+    /**
34
+     * @Callback(table="tl_page", target="fields.secureDownloadsFields.options"
35
+     */
36
+    public function onSecureDownloadsFieldsOptionsCallback(?DataContainer $dc)
37
+    {
38
+        $return = array('id'=>'ID');
39
+
40
+        System::loadLanguageFile('tl_member');
41
+        Controller::loadDataContainer('tl_member');
42
+
43
+        foreach ($GLOBALS['TL_DCA']['tl_member']['fields'] as $k=>$v)
44
+        {
45
+            if (is_array($v['label']))
46
+            {
47
+                $return[$k] = $GLOBALS['TL_DCA']['tl_member']['fields'][$k]['label'][0];
48
+            }
49
+        }
50
+
51
+        return $return;
52
+    }
53
+
54
+    /**
55
+     * @Callback(table="tl_page", target="fields.sd_nc_notification.options"
56
+     */
57
+    public function onSdNcNotificationOptionsCallback(?DataContainer $dc)
58
+    {
59
+        $arrChoices = array();
60
+        $objNotifications = \Database::getInstance()->execute("SELECT id,title FROM tl_nc_notification WHERE type='secDownloads_submitted' ORDER BY title");
61
+
62
+        while ($objNotifications->next()) {
63
+            $arrChoices[$objNotifications->id] = $objNotifications->title;
64
+        }
65
+
66
+        return $arrChoices;
67
+    }
68
+
69
+}
... ...
@@ -10,7 +10,7 @@ declare(strict_types=1);
10 10
  * @license commercial
11 11
  */
12 12
 
13
-namespace VonRotenberg\MemberfilesBundle;
13
+namespace vonRotenberg\MemberfilesBundle;
14 14
 
15 15
 use Symfony\Component\HttpKernel\Bundle\Bundle;
16 16