XoopsModules25x /
tdmdownloads
| 1 | <?php declare(strict_types=1); |
||||||
| 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 2020 XOOPS Project (https://xoops.org) |
||||||
| 17 | * @license GNU GPL 2 or later (https://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 | /** |
||||||
| 25 | * Class Object Images |
||||||
| 26 | */ |
||||||
| 27 | class Images extends \XoopsObject |
||||||
| 28 | { |
||||||
| 29 | /** |
||||||
| 30 | * Constructor |
||||||
| 31 | * |
||||||
| 32 | * @param null |
||||||
| 33 | */ |
||||||
| 34 | public function __construct() |
||||||
| 35 | { |
||||||
| 36 | $this->initVar('img_id', \XOBJ_DTYPE_INT); |
||||||
| 37 | |||||||
| 38 | $this->initVar('img_title', \XOBJ_DTYPE_TXTBOX); |
||||||
| 39 | |||||||
| 40 | $this->initVar('img_desc', \XOBJ_DTYPE_TXTAREA); |
||||||
| 41 | |||||||
| 42 | $this->initVar('img_name', \XOBJ_DTYPE_TXTBOX); |
||||||
| 43 | |||||||
| 44 | $this->initVar('img_namelarge', \XOBJ_DTYPE_TXTBOX); |
||||||
| 45 | |||||||
| 46 | $this->initVar('img_nameorig', \XOBJ_DTYPE_TXTBOX); |
||||||
| 47 | |||||||
| 48 | $this->initVar('img_mimetype', \XOBJ_DTYPE_TXTBOX); |
||||||
| 49 | |||||||
| 50 | $this->initVar('img_size', \XOBJ_DTYPE_INT); |
||||||
| 51 | |||||||
| 52 | $this->initVar('img_resx', \XOBJ_DTYPE_INT); |
||||||
| 53 | |||||||
| 54 | $this->initVar('img_resy', \XOBJ_DTYPE_INT); |
||||||
| 55 | |||||||
| 56 | $this->initVar('img_downloads', \XOBJ_DTYPE_INT); |
||||||
| 57 | |||||||
| 58 | $this->initVar('img_ratinglikes', \XOBJ_DTYPE_INT); |
||||||
| 59 | |||||||
| 60 | $this->initVar('img_votes', \XOBJ_DTYPE_INT); |
||||||
| 61 | |||||||
| 62 | $this->initVar('img_weight', \XOBJ_DTYPE_INT); |
||||||
| 63 | |||||||
| 64 | $this->initVar('img_albid', \XOBJ_DTYPE_INT); |
||||||
| 65 | |||||||
| 66 | $this->initVar('img_state', \XOBJ_DTYPE_INT); |
||||||
| 67 | |||||||
| 68 | $this->initVar('img_date', \XOBJ_DTYPE_INT); |
||||||
| 69 | |||||||
| 70 | $this->initVar('img_submitter', \XOBJ_DTYPE_INT); |
||||||
| 71 | |||||||
| 72 | $this->initVar('img_ip', \XOBJ_DTYPE_TXTAREA); |
||||||
| 73 | |||||||
| 74 | $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false); |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | /** |
||||||
| 78 | * @static function &getInstance |
||||||
| 79 | * |
||||||
| 80 | * @param null |
||||||
| 81 | */ |
||||||
| 82 | public static function getInstance() |
||||||
| 83 | { |
||||||
| 84 | static $instance = false; |
||||||
| 85 | |||||||
| 86 | if (!$instance) { |
||||||
| 87 | $instance = new self(); |
||||||
| 88 | } |
||||||
| 89 | } |
||||||
| 90 | |||||||
| 91 | /** |
||||||
| 92 | * @return int |
||||||
| 93 | */ |
||||||
| 94 | public function getNewInsertedIdImages() |
||||||
| 95 | { |
||||||
| 96 | return $GLOBALS['xoopsDB']->getInsertId(); |
||||||
| 97 | } |
||||||
| 98 | |||||||
| 99 | /** |
||||||
| 100 | * @public function getForm |
||||||
| 101 | * @param bool $action |
||||||
| 102 | * @return \XoopsThemeForm |
||||||
| 103 | */ |
||||||
| 104 | public function getFormImages($action = false) |
||||||
| 105 | { |
||||||
| 106 | $moduleDirName = \basename(\dirname(\dirname(__DIR__))); |
||||||
| 107 | |||||||
| 108 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||||||
| 109 | |||||||
| 110 | $helper = Tdmdownloads\Helper::getInstance(); |
||||||
| 111 | |||||||
| 112 | if (!$action) { |
||||||
| 113 | $action = $_SERVER['REQUEST_URI']; |
||||||
| 114 | } |
||||||
| 115 | |||||||
| 116 | // Title |
||||||
| 117 | |||||||
| 118 | $title = $this->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_EDIT')); |
||||||
| 119 | |||||||
| 120 | // Get Theme Form |
||||||
| 121 | |||||||
| 122 | \xoops_load('XoopsFormLoader'); |
||||||
| 123 | |||||||
| 124 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||||||
| 125 | |||||||
| 126 | $form->setExtra('enctype="multipart/form-data"'); |
||||||
| 127 | |||||||
| 128 | // Form Text ImgTitle |
||||||
| 129 | |||||||
| 130 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_TITLE'), 'img_title', 50, 255, $this->getVar('img_title'))); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 131 | |||||||
| 132 | // Form editor ImgDesc |
||||||
| 133 | |||||||
| 134 | $editorConfigs = []; |
||||||
| 135 | |||||||
| 136 | $editorConfigs['name'] = 'img_desc'; |
||||||
| 137 | |||||||
| 138 | $editorConfigs['value'] = $this->getVar('img_desc', 'e'); |
||||||
| 139 | |||||||
| 140 | $editorConfigs['rows'] = 5; |
||||||
| 141 | |||||||
| 142 | $editorConfigs['cols'] = 40; |
||||||
| 143 | |||||||
| 144 | $editorConfigs['width'] = '100%'; |
||||||
| 145 | |||||||
| 146 | $editorConfigs['height'] = '400px'; |
||||||
| 147 | |||||||
| 148 | $editorConfigs['editor'] = $helper->getConfig('editor'); |
||||||
| 149 | |||||||
| 150 | $form->addElement(new \XoopsFormEditor(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DESC'), 'img_desc', $editorConfigs)); |
||||||
| 151 | |||||||
| 152 | // Form Text ImgName |
||||||
| 153 | |||||||
| 154 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAME'), 'img_name', 50, 255, $this->getVar('img_name')), true); |
||||||
| 155 | |||||||
| 156 | // Form Text ImgNameLarge |
||||||
| 157 | |||||||
| 158 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMELARGE'), 'img_namelarge', 50, 255, $this->getVar('img_namelarge')), true); |
||||||
| 159 | |||||||
| 160 | // Form Text ImgOrigname |
||||||
| 161 | |||||||
| 162 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMEORIG'), 'img_nameorig', 50, 255, $this->getVar('img_nameorig')), true); |
||||||
| 163 | |||||||
| 164 | // Form Text ImgMimetype |
||||||
| 165 | |||||||
| 166 | $imgMimetype = $this->isNew() ? '0' : $this->getVar('img_mimetype'); |
||||||
| 167 | |||||||
| 168 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_MIMETYPE'), 'img_mimetype', 20, 150, $imgMimetype)); |
||||||
| 169 | |||||||
| 170 | // Form Text ImgSize |
||||||
| 171 | |||||||
| 172 | $imgSize = $this->isNew() ? '0' : $this->getVar('img_size'); |
||||||
| 173 | |||||||
| 174 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_SIZE'), 'img_size', 20, 150, $imgSize)); |
||||||
| 175 | |||||||
| 176 | // Form Text ImgResx |
||||||
| 177 | |||||||
| 178 | $imgResx = $this->isNew() ? '0' : $this->getVar('img_resx'); |
||||||
| 179 | |||||||
| 180 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESX'), 'img_resx', 20, 150, $imgResx)); |
||||||
| 181 | |||||||
| 182 | // Form Text ImgResy |
||||||
| 183 | |||||||
| 184 | $imgResy = $this->isNew() ? '0' : $this->getVar('img_resy'); |
||||||
| 185 | |||||||
| 186 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESY'), 'img_resy', 20, 150, $imgResy)); |
||||||
| 187 | |||||||
| 188 | // Form Text ImgDownloads |
||||||
| 189 | |||||||
| 190 | $imgDownloads = $this->isNew() ? '0' : $this->getVar('img_downloads'); |
||||||
| 191 | |||||||
| 192 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DOWNLOADS'), 'img_downloads', 20, 150, $imgDownloads)); |
||||||
| 193 | |||||||
| 194 | // Form Text ImgRatinglikes |
||||||
| 195 | |||||||
| 196 | $imgRatinglikes = $this->isNew() ? '0' : $this->getVar('img_ratinglikes'); |
||||||
| 197 | |||||||
| 198 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RATINGLIKES'), 'img_ratinglikes', 20, 150, $imgRatinglikes)); |
||||||
| 199 | |||||||
| 200 | // Form Text ImgVotes |
||||||
| 201 | |||||||
| 202 | $imgVotes = $this->isNew() ? '0' : $this->getVar('img_votes'); |
||||||
| 203 | |||||||
| 204 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_VOTES'), 'img_votes', 20, 150, $imgVotes)); |
||||||
| 205 | |||||||
| 206 | // Form Text ImgWeight |
||||||
| 207 | |||||||
| 208 | $imgWeight = $this->isNew() ? '0' : $this->getVar('img_weight'); |
||||||
| 209 | |||||||
| 210 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WEIGHT'), 'img_weight', 20, 150, $imgWeight)); |
||||||
| 211 | |||||||
| 212 | // Form Table albums |
||||||
| 213 | |||||||
| 214 | $albumsHandler = $helper->getHandler('Albums'); |
||||||
| 215 | |||||||
| 216 | $imgAlbidSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ALBID'), 'img_albid', $this->getVar('img_albid')); |
||||||
| 217 | |||||||
| 218 | $imgAlbidSelect->addOptionArray($albumsHandler->getList()); |
||||||
|
0 ignored issues
–
show
The method
getList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsImageHandler or XoopsRankHandler or XoopsCommentHandler or XoopsTplsetHandler or XoopsAvatarHandler or XoopsBlockHandler or XoopsImagesetHandler or XoopsPersistableObjectHandler or XoopsImagecategoryHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 219 | |||||||
| 220 | $form->addElement($imgAlbidSelect, true); |
||||||
| 221 | |||||||
| 222 | // Images handler |
||||||
| 223 | |||||||
| 224 | $imagesHandler = $helper->getHandler('Images'); |
||||||
| 225 | |||||||
| 226 | // Form Select Images |
||||||
| 227 | |||||||
| 228 | $imgStateSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_STATE'), 'img_state', $this->getVar('img_state')); |
||||||
| 229 | |||||||
| 230 | $imgStateSelect->addOption('Empty'); |
||||||
| 231 | |||||||
| 232 | $imgStateSelect->addOptionArray($imagesHandler->getList()); |
||||||
| 233 | |||||||
| 234 | $form->addElement($imgStateSelect, true); |
||||||
| 235 | |||||||
| 236 | // Form Text Date Select ImgDate |
||||||
| 237 | |||||||
| 238 | $imgDate = $this->isNew() ? 0 : $this->getVar('img_date'); |
||||||
| 239 | |||||||
| 240 | $form->addElement(new \XoopsFormTextDateSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'DATE'), 'img_date', '', $imgDate)); |
||||||
|
0 ignored issues
–
show
'' of type string is incompatible with the type integer expected by parameter $size of XoopsFormTextDateSelect::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 241 | |||||||
| 242 | // Form Select User ImgSubmitter |
||||||
| 243 | |||||||
| 244 | $form->addElement(new \XoopsFormSelectUser(\constant('CO_' . $moduleDirNameUpper . '_' . 'SUBMITTER'), 'img_submitter', false, $this->getVar('img_submitter'))); |
||||||
| 245 | |||||||
| 246 | // Form Text ImgIp |
||||||
| 247 | |||||||
| 248 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_IP'), 'img_ip', 50, 255, $this->getVar('img_ip'))); |
||||||
| 249 | |||||||
| 250 | // To Save |
||||||
| 251 | |||||||
| 252 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||||||
| 253 | |||||||
| 254 | $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
||||||
| 255 | |||||||
| 256 | return $form; |
||||||
| 257 | } |
||||||
| 258 | |||||||
| 259 | /** |
||||||
| 260 | * Get Values |
||||||
| 261 | * @param null $keys |
||||||
|
0 ignored issues
–
show
|
|||||||
| 262 | * @param null $format |
||||||
|
0 ignored issues
–
show
|
|||||||
| 263 | * @param null $maxDepth |
||||||
|
0 ignored issues
–
show
|
|||||||
| 264 | * @return array |
||||||
| 265 | */ |
||||||
| 266 | public function getValuesImages($keys = null, $format = null, $maxDepth = null) |
||||||
| 267 | { |
||||||
| 268 | $moduleDirName = \basename(\dirname(\dirname(__DIR__))); |
||||||
| 269 | |||||||
| 270 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||||||
| 271 | |||||||
| 272 | $helper = Tdmdownloads\Helper::getInstance(); |
||||||
| 273 | |||||||
| 274 | $ret = $this->getValues($keys, $format, $maxDepth); |
||||||
| 275 | |||||||
| 276 | $ret['id'] = $this->getVar('img_id'); |
||||||
| 277 | |||||||
| 278 | $ret['title'] = $this->getVar('img_title'); |
||||||
| 279 | |||||||
| 280 | $ret['desc'] = $this->getVar('img_desc', 'n'); |
||||||
| 281 | |||||||
| 282 | $ret['name'] = $this->getVar('img_name'); |
||||||
| 283 | |||||||
| 284 | $ret['namelarge'] = $this->getVar('img_namelarge'); |
||||||
| 285 | |||||||
| 286 | $ret['nameorig'] = $this->getVar('img_nameorig'); |
||||||
| 287 | |||||||
| 288 | $ret['mimetype'] = $this->getVar('img_mimetype'); |
||||||
| 289 | |||||||
| 290 | $ret['size'] = $this->getVar('img_size'); |
||||||
| 291 | |||||||
| 292 | $ret['resx'] = $this->getVar('img_resx'); |
||||||
| 293 | |||||||
| 294 | $ret['resy'] = $this->getVar('img_resy'); |
||||||
| 295 | |||||||
| 296 | $ret['downloads'] = $this->getVar('img_downloads'); |
||||||
| 297 | |||||||
| 298 | $ret['ratinglikes'] = $this->getVar('img_ratinglikes'); |
||||||
| 299 | |||||||
| 300 | $ret['votes'] = $this->getVar('img_votes'); |
||||||
| 301 | |||||||
| 302 | $ret['weight'] = $this->getVar('img_weight'); |
||||||
| 303 | |||||||
| 304 | $ret['albid'] = $this->getVar('img_albid'); |
||||||
| 305 | |||||||
| 306 | //$albums = $helper->getHandler('Albums'); |
||||||
| 307 | |||||||
| 308 | //$albumsObj = $albums->get($this->getVar('img_albid')); |
||||||
| 309 | |||||||
| 310 | //if (isset($albumsObj) && is_object($albumsObj)) { |
||||||
| 311 | |||||||
| 312 | //$ret['alb_name'] = $albumsObj->getVar('alb_name'); |
||||||
| 313 | |||||||
| 314 | //} |
||||||
| 315 | |||||||
| 316 | $ret['state'] = $this->getVar('img_state'); |
||||||
| 317 | |||||||
| 318 | $ret['state_text'] = $helper->getStateText($this->getVar('img_state')); |
||||||
|
0 ignored issues
–
show
The method
getStateText() does not exist on XoopsModules\Tdmdownloads\Helper.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 319 | |||||||
| 320 | $ret['date'] = \formatTimestamp($this->getVar('img_date'), 's'); |
||||||
| 321 | |||||||
| 322 | $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('img_submitter')); |
||||||
| 323 | |||||||
| 324 | $ret['ip'] = $this->getVar('img_ip'); |
||||||
| 325 | |||||||
| 326 | $ret['large'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/large/' . $this->getVar('img_namelarge'); |
||||||
| 327 | |||||||
| 328 | $ret['medium'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/medium/' . $this->getVar('img_name'); |
||||||
| 329 | |||||||
| 330 | $ret['thumb'] = \constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_URL') . '/thumbs/' . $this->getVar('img_name'); |
||||||
| 331 | |||||||
| 332 | return $ret; |
||||||
| 333 | } |
||||||
| 334 | |||||||
| 335 | /** |
||||||
| 336 | * Returns an array representation of the object |
||||||
| 337 | * |
||||||
| 338 | * @return array |
||||||
| 339 | */ |
||||||
| 340 | public function toArrayImages() |
||||||
| 341 | { |
||||||
| 342 | $ret = []; |
||||||
| 343 | |||||||
| 344 | $vars = $this->getVars(); |
||||||
| 345 | |||||||
| 346 | foreach (\array_keys($vars) as $var) { |
||||||
| 347 | $ret[$var] = $this->getVar('"{$var}"'); |
||||||
| 348 | } |
||||||
| 349 | |||||||
| 350 | return $ret; |
||||||
| 351 | } |
||||||
| 352 | } |
||||||
| 353 |