|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
namespace XoopsModules\Wgfilemanager; |
|
7
|
|
|
|
|
8
|
|
|
/* |
|
9
|
|
|
You may not change or alter any portion of this comment or credits |
|
10
|
|
|
of supporting developers from this source code or any supporting source code |
|
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
|
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* wgFileManager module for xoops |
|
20
|
|
|
* |
|
21
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
|
22
|
|
|
* @license GPL 2.0 or later |
|
23
|
|
|
* @package wgfilemanager |
|
24
|
|
|
* @since 1.0 |
|
25
|
|
|
* @min_xoops 2.5.9 |
|
26
|
|
|
* @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
use XoopsModules\Wgfilemanager; |
|
30
|
|
|
|
|
31
|
|
|
\defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Class Object Mimetype |
|
35
|
|
|
*/ |
|
36
|
|
|
class Mimetype extends \XoopsObject |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var int |
|
40
|
|
|
*/ |
|
41
|
|
|
public $start = 0; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var int |
|
45
|
|
|
*/ |
|
46
|
|
|
public $limit = 0; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Constructor |
|
50
|
|
|
* |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->initVar('id', \XOBJ_DTYPE_INT); |
|
55
|
|
|
$this->initVar('extension', \XOBJ_DTYPE_TXTBOX); |
|
56
|
|
|
$this->initVar('mimetype', \XOBJ_DTYPE_TXTBOX); |
|
57
|
|
|
$this->initVar('desc', \XOBJ_DTYPE_TXTBOX); |
|
58
|
|
|
$this->initVar('admin', \XOBJ_DTYPE_INT); |
|
59
|
|
|
$this->initVar('user', \XOBJ_DTYPE_INT); |
|
60
|
|
|
$this->initVar('category', \XOBJ_DTYPE_INT); |
|
61
|
|
|
$this->initVar('date_created', \XOBJ_DTYPE_INT); |
|
62
|
|
|
$this->initVar('submitter', \XOBJ_DTYPE_INT); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @static function &getInstance |
|
67
|
|
|
* |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function getInstance() |
|
70
|
|
|
{ |
|
71
|
|
|
static $instance = false; |
|
72
|
|
|
if (!$instance) { |
|
73
|
|
|
$instance = new self(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* The new inserted $Id |
|
79
|
|
|
* @return integer |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getNewInsertedIdMimetype() |
|
82
|
|
|
{ |
|
83
|
|
|
return $GLOBALS['xoopsDB']->getInsertId(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @public function getForm |
|
88
|
|
|
* @param bool $action |
|
89
|
|
|
* @return \XoopsThemeForm |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getFormMimetype($action = false) |
|
92
|
|
|
{ |
|
93
|
|
|
//$helper = \XoopsModules\Wgfilemanager\Helper::getInstance(); |
|
94
|
|
|
if (!$action) { |
|
95
|
|
|
$action = $_SERVER['REQUEST_URI']; |
|
96
|
|
|
} |
|
97
|
|
|
//$isAdmin = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()) : false; |
|
98
|
|
|
// Title |
|
99
|
|
|
$title = $this->isNew() ? \_AM_WGFILEMANAGER_MIMETYPE_ADD : \_AM_WGFILEMANAGER_MIMETYPE_EDIT; |
|
100
|
|
|
// Get Theme Form |
|
101
|
|
|
\xoops_load('XoopsFormLoader'); |
|
102
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
|
103
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
|
104
|
|
|
// Form Text mimeExtension |
|
105
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGFILEMANAGER_MIMETYPE_EXTENSION, 'extension', 50, 255, $this->getVar('extension')), true); |
|
|
|
|
|
|
106
|
|
|
// Form Text mimeMimetype |
|
107
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGFILEMANAGER_MIMETYPE_MIMETYPE, 'mimetype', 50, 255, $this->getVar('mimetype')), true); |
|
108
|
|
|
// Form Text mimeDesc |
|
109
|
|
|
$form->addElement(new \XoopsFormText(\_AM_WGFILEMANAGER_MIMETYPE_DESC, 'desc', 50, 255, $this->getVar('desc')), true); |
|
110
|
|
|
// Form Radio Yes/No mimeAdmin |
|
111
|
|
|
$mimeAdmin = $this->isNew() ? 1 : $this->getVar('admin'); |
|
112
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGFILEMANAGER_MIMETYPE_ADMIN, 'admin', $mimeAdmin)); |
|
|
|
|
|
|
113
|
|
|
// Form Radio Yes/No mimeUser |
|
114
|
|
|
$mimeUser = $this->isNew() ? 0 : $this->getVar('user'); |
|
115
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_WGFILEMANAGER_MIMETYPE_USER, 'user', $mimeUser)); |
|
116
|
|
|
// Form Select mimeCategory |
|
117
|
|
|
$mimeCategorySelect = new \XoopsFormSelect(\_AM_WGFILEMANAGER_MIMETYPE_CAT, 'category', $this->getVar('category')); |
|
118
|
|
|
$mimeCategorySelect->addOption(Constants::MIMETYPE_CAT_NONE, \_AM_WGFILEMANAGER_MIMETYPE_CAT_NONE); |
|
119
|
|
|
$mimeCategorySelect->addOption(Constants::MIMETYPE_CAT_IMAGE, \_AM_WGFILEMANAGER_MIMETYPE_CAT_IMAGE); |
|
120
|
|
|
$mimeCategorySelect->addOption(Constants::MIMETYPE_CAT_PDF, \_AM_WGFILEMANAGER_MIMETYPE_CAT_PDF); |
|
121
|
|
|
$form->addElement($mimeCategorySelect, true); |
|
122
|
|
|
// Form Text Date Select mimeDate_created |
|
123
|
|
|
$mimeDate_created = $this->isNew() ? \time() : $this->getVar('date_created'); |
|
124
|
|
|
$form->addElement(new \XoopsFormTextDateSelect(\_AM_WGFILEMANAGER_MIMETYPE_DATE_CREATED, 'date_created', '', $mimeDate_created)); |
|
|
|
|
|
|
125
|
|
|
// Form Select User mimeSubmitter |
|
126
|
|
|
$uidCurrent = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
|
127
|
|
|
$mimeSubmitter = $this->isNew() ? $uidCurrent : $this->getVar('submitter'); |
|
128
|
|
|
$form->addElement(new \XoopsFormSelectUser(\_AM_WGFILEMANAGER_MIMETYPE_SUBMITTER, 'submitter', false, $mimeSubmitter)); |
|
129
|
|
|
// To Save |
|
130
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save')); |
|
131
|
|
|
$form->addElement(new \XoopsFormHidden('start', $this->start)); |
|
132
|
|
|
$form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
|
133
|
|
|
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
|
134
|
|
|
return $form; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Get Values |
|
139
|
|
|
* @param null $keys |
|
|
|
|
|
|
140
|
|
|
* @param null $format |
|
|
|
|
|
|
141
|
|
|
* @param null $maxDepth |
|
|
|
|
|
|
142
|
|
|
* @return array |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getValuesMimetype($keys = null, $format = null, $maxDepth = null) |
|
145
|
|
|
{ |
|
146
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth); |
|
147
|
|
|
$ret['admin_text'] = (int)$this->getVar('admin') > 0 ? _YES : _NO; |
|
148
|
|
|
$ret['user_text'] = (int)$this->getVar('user') > 0 ? _YES : _NO; |
|
149
|
|
|
$ret['category_text'] = $this->getCategoryMimetype((int)$this->getVar('category')); |
|
150
|
|
|
$ret['date_created_text'] = \formatTimestamp($this->getVar('date_created'), 's'); |
|
151
|
|
|
$ret['submitter_text'] = \XoopsUser::getUnameFromId($this->getVar('submitter')); |
|
152
|
|
|
return $ret; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Returns the description for mime type Category |
|
157
|
|
|
* |
|
158
|
|
|
* @return string |
|
159
|
|
|
*/ |
|
160
|
|
|
private function getCategoryMimetype($category) |
|
161
|
|
|
{ |
|
162
|
|
|
switch ($category) { |
|
163
|
|
|
case Constants::MIMETYPE_CAT_PDF: |
|
164
|
|
|
return \_AM_WGFILEMANAGER_MIMETYPE_CAT_PDF; |
|
165
|
|
|
case Constants::MIMETYPE_CAT_IMAGE: |
|
166
|
|
|
return \_AM_WGFILEMANAGER_MIMETYPE_CAT_IMAGE; |
|
167
|
|
|
case 0: |
|
168
|
|
|
default: |
|
169
|
|
|
return \_AM_WGFILEMANAGER_MIMETYPE_CAT_NONE; |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
/** |
|
173
|
|
|
* Returns an array representation of the object |
|
174
|
|
|
* |
|
175
|
|
|
* @return array |
|
176
|
|
|
*/ |
|
177
|
|
|
public function toArrayMimetype() |
|
178
|
|
|
{ |
|
179
|
|
|
$ret = []; |
|
180
|
|
|
$vars = $this->getVars(); |
|
181
|
|
|
foreach (\array_keys($vars) as $var) { |
|
182
|
|
|
$ret[$var] = $this->getVar($var); |
|
183
|
|
|
} |
|
184
|
|
|
return $ret; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|