1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Tdmdownloads\Common; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
You may not change or alter any portion of this comment or credits |
9
|
|
|
of supporting developers from this source code or any supporting source code |
10
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @copyright 2020 XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
20
|
|
|
* @link https://xoops.org |
21
|
|
|
* @author Wedega - Email:<[email protected]> - Website:<https://wedega.com> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
use XoopsModules\Tdmdownloads\{ |
25
|
|
|
Helper |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class Object Images |
30
|
|
|
*/ |
31
|
|
|
class Images extends \XoopsObject |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Constructor |
35
|
|
|
* |
36
|
|
|
* @param null |
37
|
|
|
*/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->initVar('img_id', \XOBJ_DTYPE_INT); |
41
|
|
|
$this->initVar('img_title', \XOBJ_DTYPE_TXTBOX); |
42
|
|
|
$this->initVar('img_desc', \XOBJ_DTYPE_TXTAREA); |
43
|
|
|
$this->initVar('img_name', \XOBJ_DTYPE_TXTBOX); |
44
|
|
|
$this->initVar('img_namelarge', \XOBJ_DTYPE_TXTBOX); |
45
|
|
|
$this->initVar('img_nameorig', \XOBJ_DTYPE_TXTBOX); |
46
|
|
|
$this->initVar('img_mimetype', \XOBJ_DTYPE_TXTBOX); |
47
|
|
|
$this->initVar('img_size', \XOBJ_DTYPE_INT); |
48
|
|
|
$this->initVar('img_resx', \XOBJ_DTYPE_INT); |
49
|
|
|
$this->initVar('img_resy', \XOBJ_DTYPE_INT); |
50
|
|
|
$this->initVar('img_downloads', \XOBJ_DTYPE_INT); |
51
|
|
|
$this->initVar('img_ratinglikes', \XOBJ_DTYPE_INT); |
52
|
|
|
$this->initVar('img_votes', \XOBJ_DTYPE_INT); |
53
|
|
|
$this->initVar('img_weight', \XOBJ_DTYPE_INT); |
54
|
|
|
$this->initVar('img_albid', \XOBJ_DTYPE_INT); |
55
|
|
|
$this->initVar('img_state', \XOBJ_DTYPE_INT); |
56
|
|
|
$this->initVar('img_date', \XOBJ_DTYPE_INT); |
57
|
|
|
$this->initVar('img_submitter', \XOBJ_DTYPE_INT); |
58
|
|
|
$this->initVar('img_ip', \XOBJ_DTYPE_TXTAREA); |
59
|
|
|
$this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @static function &getInstance |
64
|
|
|
* |
65
|
|
|
* @param null |
66
|
|
|
*/ |
67
|
|
|
public static function getInstance() |
68
|
|
|
{ |
69
|
|
|
static $instance = false; |
70
|
|
|
if (!$instance) { |
71
|
|
|
$instance = new self(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getNewInsertedIdImages() |
79
|
|
|
{ |
80
|
|
|
return $GLOBALS['xoopsDB']->getInsertId(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @public function getForm |
85
|
|
|
* @param bool $action |
86
|
|
|
* @return \XoopsThemeForm |
87
|
|
|
*/ |
88
|
|
|
public function getFormImages($action = false) |
89
|
|
|
{ |
90
|
|
|
$moduleDirName = \basename(\dirname(__DIR__, 2)); |
91
|
|
|
$moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
92
|
|
|
$helper = Helper::getInstance(); |
93
|
|
|
if (!$action) { |
94
|
|
|
$action = $_SERVER['REQUEST_URI']; |
95
|
|
|
} |
96
|
|
|
// Title |
97
|
|
|
$title = $this->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_EDIT')); |
98
|
|
|
// Get Theme Form |
99
|
|
|
\xoops_load('XoopsFormLoader'); |
100
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
101
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
102
|
|
|
// Form Text ImgTitle |
103
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_TITLE'), 'img_title', 50, 255, $this->getVar('img_title'))); |
|
|
|
|
104
|
|
|
// Form editor ImgDesc |
105
|
|
|
$editorConfigs = []; |
106
|
|
|
$editorConfigs['name'] = 'img_desc'; |
107
|
|
|
$editorConfigs['value'] = $this->getVar('img_desc', 'e'); |
108
|
|
|
$editorConfigs['rows'] = 5; |
109
|
|
|
$editorConfigs['cols'] = 40; |
110
|
|
|
$editorConfigs['width'] = '100%'; |
111
|
|
|
$editorConfigs['height'] = '400px'; |
112
|
|
|
$editorConfigs['editor'] = $helper->getConfig('editor'); |
113
|
|
|
$form->addElement(new \XoopsFormEditor(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DESC'), 'img_desc', $editorConfigs)); |
114
|
|
|
// Form Text ImgName |
115
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAME'), 'img_name', 50, 255, $this->getVar('img_name')), true); |
116
|
|
|
// Form Text ImgNameLarge |
117
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMELARGE'), 'img_namelarge', 50, 255, $this->getVar('img_namelarge')), true); |
118
|
|
|
// Form Text ImgOrigname |
119
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMEORIG'), 'img_nameorig', 50, 255, $this->getVar('img_nameorig')), true); |
120
|
|
|
// Form Text ImgMimetype |
121
|
|
|
$imgMimetype = $this->isNew() ? '0' : $this->getVar('img_mimetype'); |
122
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_MIMETYPE'), 'img_mimetype', 20, 150, $imgMimetype)); |
123
|
|
|
// Form Text ImgSize |
124
|
|
|
$imgSize = $this->isNew() ? '0' : $this->getVar('img_size'); |
125
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_SIZE'), 'img_size', 20, 150, $imgSize)); |
126
|
|
|
// Form Text ImgResx |
127
|
|
|
$imgResx = $this->isNew() ? '0' : $this->getVar('img_resx'); |
128
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESX'), 'img_resx', 20, 150, $imgResx)); |
129
|
|
|
// Form Text ImgResy |
130
|
|
|
$imgResy = $this->isNew() ? '0' : $this->getVar('img_resy'); |
131
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESY'), 'img_resy', 20, 150, $imgResy)); |
132
|
|
|
// Form Text ImgDownloads |
133
|
|
|
$imgDownloads = $this->isNew() ? '0' : $this->getVar('img_downloads'); |
134
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DOWNLOADS'), 'img_downloads', 20, 150, $imgDownloads)); |
135
|
|
|
// Form Text ImgRatinglikes |
136
|
|
|
$imgRatinglikes = $this->isNew() ? '0' : $this->getVar('img_ratinglikes'); |
137
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RATINGLIKES'), 'img_ratinglikes', 20, 150, $imgRatinglikes)); |
138
|
|
|
// Form Text ImgVotes |
139
|
|
|
$imgVotes = $this->isNew() ? '0' : $this->getVar('img_votes'); |
140
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_VOTES'), 'img_votes', 20, 150, $imgVotes)); |
141
|
|
|
// Form Text ImgWeight |
142
|
|
|
$imgWeight = $this->isNew() ? '0' : $this->getVar('img_weight'); |
143
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WEIGHT'), 'img_weight', 20, 150, $imgWeight)); |
144
|
|
|
// Form Table albums |
145
|
|
|
/** @var \XoopsModules\Tdmdownloads\Common\ImagesHandler $albumsHandler */ |
146
|
|
|
$albumsHandler = $helper->getHandler('Albums'); |
147
|
|
|
$imgAlbidSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ALBID'), 'img_albid', $this->getVar('img_albid')); |
148
|
|
|
$imgAlbidSelect->addOptionArray($albumsHandler->getList()); |
149
|
|
|
$form->addElement($imgAlbidSelect, true); |
150
|
|
|
// Images handler |
151
|
|
|
$imagesHandler = $helper->getHandler('Images'); |
152
|
|
|
// Form Select Images |
153
|
|
|
$imgStateSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_STATE'), 'img_state', $this->getVar('img_state')); |
154
|
|
|
$imgStateSelect->addOption('Empty'); |
155
|
|
|
$imgStateSelect->addOptionArray($imagesHandler->getList()); |
|
|
|
|
156
|
|
|
$form->addElement($imgStateSelect, true); |
157
|
|
|
// Form Text Date Select ImgDate |
158
|
|
|
$imgDate = $this->isNew() ? 0 : $this->getVar('img_date'); |
159
|
|
|
$form->addElement(new \XoopsFormTextDateSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'DATE'), 'img_date', '', $imgDate)); |
|
|
|
|
160
|
|
|
// Form Select User ImgSubmitter |
161
|
|
|
$form->addElement(new \XoopsFormSelectUser(\constant('CO_' . $moduleDirNameUpper . '_' . 'SUBMITTER'), 'img_submitter', false, $this->getVar('img_submitter'))); |
162
|
|
|
// Form Text ImgIp |
163
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_IP'), 'img_ip', 50, 255, $this->getVar('img_ip'))); |
164
|
|
|
// To Save |
165
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save')); |
166
|
|
|
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
167
|
|
|
return $form; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get Values |
172
|
|
|
* @param null $keys |
|
|
|
|
173
|
|
|
* @param null $format |
|
|
|
|
174
|
|
|
* @param null $maxDepth |
|
|
|
|
175
|
|
|
* @return array |
176
|
|
|
*/ |
177
|
|
|
public function getValuesImages($keys = null, $format = null, $maxDepth = null) |
178
|
|
|
{ |
179
|
|
|
$moduleDirName = \basename(\dirname(__DIR__, 2)); |
180
|
|
|
$moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
181
|
|
|
$helper = Helper::getInstance(); |
182
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth); |
183
|
|
|
$ret['id'] = $this->getVar('img_id'); |
184
|
|
|
$ret['title'] = $this->getVar('img_title'); |
185
|
|
|
$ret['desc'] = $this->getVar('img_desc', 'n'); |
186
|
|
|
$ret['name'] = $this->getVar('img_name'); |
187
|
|
|
$ret['namelarge'] = $this->getVar('img_namelarge'); |
188
|
|
|
$ret['nameorig'] = $this->getVar('img_nameorig'); |
189
|
|
|
$ret['mimetype'] = $this->getVar('img_mimetype'); |
190
|
|
|
$ret['size'] = $this->getVar('img_size'); |
191
|
|
|
$ret['resx'] = $this->getVar('img_resx'); |
192
|
|
|
$ret['resy'] = $this->getVar('img_resy'); |
193
|
|
|
$ret['downloads'] = $this->getVar('img_downloads'); |
194
|
|
|
$ret['ratinglikes'] = $this->getVar('img_ratinglikes'); |
195
|
|
|
$ret['votes'] = $this->getVar('img_votes'); |
196
|
|
|
$ret['weight'] = $this->getVar('img_weight'); |
197
|
|
|
$ret['albid'] = $this->getVar('img_albid'); |
198
|
|
|
//$albums = $helper->getHandler('Albums'); |
199
|
|
|
//$albumsObj = $albums->get($this->getVar('img_albid')); |
200
|
|
|
//if (isset($albumsObj) && is_object($albumsObj)) { |
201
|
|
|
//$ret['alb_name'] = $albumsObj->getVar('alb_name'); |
202
|
|
|
//} |
203
|
|
|
$ret['state'] = $this->getVar('img_state'); |
204
|
|
|
$ret['state_text'] = $helper->getStateText($this->getVar('img_state')); |
|
|
|
|
205
|
|
|
$ret['date'] = \formatTimestamp($this->getVar('img_date'), 's'); |
206
|
|
|
$ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('img_submitter')); |
207
|
|
|
$ret['ip'] = $this->getVar('img_ip'); |
208
|
|
|
$ret['large'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/large/' . $this->getVar('img_namelarge'); |
209
|
|
|
$ret['medium'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/medium/' . $this->getVar('img_name'); |
210
|
|
|
$ret['thumb'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/thumbs/' . $this->getVar('img_name'); |
211
|
|
|
return $ret; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Returns an array representation of the object |
216
|
|
|
* |
217
|
|
|
* @return array |
218
|
|
|
*/ |
219
|
|
|
public function toArrayImages() |
220
|
|
|
{ |
221
|
|
|
$ret = []; |
222
|
|
|
$vars = $this->getVars(); |
223
|
|
|
foreach (\array_keys($vars) as $var) { |
224
|
|
|
$ret[$var] = $this->getVar('"{$var}"'); |
225
|
|
|
} |
226
|
|
|
return $ret; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|