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