Passed
Branch master (a5e4e1)
by Michael
12:01
created

class/Form/ItemForm.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Publisher\Form;
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
 *  Publisher form class
17
 *
18
 * @copyright       The XUUPS Project https://sourceforge.net/projects/xuups/
19
 * @license         https://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @since           1.0
21
 * @author          trabis <[email protected]>
22
 */
23
24
use Xmf\Request;
25
use XoopsModules\Publisher\Common\Configurator;
26
use XoopsModules\Publisher\Constants;
27
use XoopsModules\Publisher\Form;
28
use XoopsModules\Publisher\FormDateTime;
29
use XoopsModules\Publisher\Helper;
30
use XoopsModules\Publisher\Item;
31
use XoopsModules\Publisher\ThemeTabForm;
32
use XoopsModules\Publisher\Utility;
33
34
require_once \dirname(__DIR__, 2) . '/include/common.php';
35
36
\xoops_load('XoopsFormLoader');
37
\xoops_load('XoopsLists');
38
require_once $GLOBALS['xoops']->path('class/tree.php');
39
//require_once PUBLISHER_ROOT_PATH . '/class/formdatetime.php';
40
//require_once PUBLISHER_ROOT_PATH . '/class/themetabform.php';
41
42
/**
43
 * Class ItemForm
44
 */
45
class ItemForm extends ThemeTabForm
46
{
47
    public $checkperm = true;
48
    public $tabs      = [
49
        \_CO_PUBLISHER_TAB_MAIN   => 'mainTab',
50
        \_CO_PUBLISHER_TAB_IMAGES => 'imagesTab',
51
        \_CO_PUBLISHER_TAB_FILES  => 'filesTab',
52
        \_CO_PUBLISHER_TAB_OTHERS => 'othersTab',
53
    ];
54
    public $mainTab   = [
55
        Constants::PUBLISHER_SUBTITLE,
56
        Constants::PUBLISHER_ITEM_SHORT_URL,
57
        Constants::PUBLISHER_ITEM_TAG,
58
        Constants::PUBLISHER_SUMMARY,
59
        Constants::PUBLISHER_DOHTML,
60
        Constants::PUBLISHER_DOSMILEY,
61
        Constants::PUBLISHER_DOXCODE,
62
        Constants::PUBLISHER_DOIMAGE,
63
        Constants::PUBLISHER_DOLINEBREAK,
64
        Constants::PUBLISHER_DATESUB,
65
        Constants::PUBLISHER_STATUS,
66
        Constants::PUBLISHER_AUTHOR_ALIAS,
67
        Constants::PUBLISHER_NOTIFY,
68
        Constants::PUBLISHER_AVAILABLE_PAGE_WRAP,
69
        Constants::PUBLISHER_UID,
70
        Constants::PUBLISHER_VOTETYPE,
71
    ];
72
    public $imagesTab = [
73
        Constants::PUBLISHER_IMAGE_ITEM,
74
    ];
75
    public $filesTab  = [
76
        Constants::PUBLISHER_ITEM_UPLOAD_FILE,
77
    ];
78
    public $othersTab = [
79
        Constants::PUBLISHER_ITEM_META_KEYWORDS,
80
        Constants::PUBLISHER_ITEM_META_DESCRIPTION,
81
        Constants::PUBLISHER_WEIGHT,
82
        Constants::PUBLISHER_ALLOWCOMMENTS,
83
    ];
84
85
    /**
86
     * @param $checkperm
87
     */
88
    public function setCheckPermissions($checkperm): void
89
    {
90
        $this->checkperm = (bool)$checkperm;
91
    }
92
93
    /**
94
     * @param $item
95
     *
96
     * @return bool
97
     */
98
    public function isGranted($item)
99
    {
100
        $helper = Helper::getInstance();
101
        $ret    = false;
102
        if (!$this->checkperm || $helper->getHandler('Permission')->isGranted('form_view', $item)) {
103
            $ret = true;
104
        }
105
106
        return $ret;
107
    }
108
109
    /**
110
     * @param $tab
111
     *
112
     * @return bool
113
     */
114
    public function hasTab($tab)
115
    {
116
        if (!isset($tab, $this->tabs[$tab])) {
117
            return false;
118
        }
119
120
        $tabRef = $this->tabs[$tab];
121
        $items  = $this->$tabRef;
122
        foreach ($items as $item) {
123
            if ($this->isGranted($item)) {
124
                return true;
125
            }
126
        }
127
128
        return false;
129
    }
130
131
    /**
132
     * @param Item $obj
133
     *
134
     * @return $this
135
     */
136
    public function createElements($obj)
137
    {
138
        $helper       = Helper::getInstance();
139
        $timeoffset   = null;
140
        $configurator = new Configurator();
141
        $icons        = $configurator->icons;
142
143
        $allowedEditors = Utility::getEditors($helper->getHandler('Permission')->getGrantedItems('editors'));
144
145
        if (\is_object($GLOBALS['xoopsUser'])) {
146
            $group      = $GLOBALS['xoopsUser']->getGroups();
147
            $currentUid = $GLOBALS['xoopsUser']->uid();
148
            $timeoffset = $GLOBALS['xoopsUser']->getVar('timezone_offset');
149
        } else {
150
            $group      = [XOOPS_GROUP_ANONYMOUS];
151
            $currentUid = 0;
152
        }
153
154
        $this->setExtra('enctype="multipart/form-data"');
155
156
        $this->startTab(\_CO_PUBLISHER_TAB_MAIN);
157
158
        // Category
159
        $categoryFormSelect = new \XoopsFormSelect(\_CO_PUBLISHER_CATEGORY, 'categoryid', $obj->getVar('categoryid', 'e'));
160
        $categoryFormSelect->setDescription(\_CO_PUBLISHER_CATEGORY_DSC);
161
        $categoryFormSelect->addOptionArray($helper->getHandler('Category')->getCategoriesForSubmit());
162
        $this->addElement($categoryFormSelect);
163
164
        // ITEM TITLE
165
        $this->addElement(new \XoopsFormText(\_CO_PUBLISHER_TITLE, 'title', 50, 255, $obj->getVar('title', 'e')), true);
166
167
        // SUBTITLE
168
        if ($this->isGranted(Constants::PUBLISHER_SUBTITLE)) {
169
            $this->addElement(new \XoopsFormText(\_CO_PUBLISHER_SUBTITLE, 'subtitle', 50, 255, $obj->getVar('subtitle', 'e')));
170
        }
171
172
        // SHORT URL
173
        if ($this->isGranted(Constants::PUBLISHER_ITEM_SHORT_URL)) {
174
            $textShortUrl = new \XoopsFormText(\_CO_PUBLISHER_ITEM_SHORT_URL, 'item_short_url', 50, 255, $obj->short_url('e'));
175
            $textShortUrl->setDescription(\_CO_PUBLISHER_ITEM_SHORT_URL_DSC);
176
            $this->addElement($textShortUrl);
177
        }
178
179
        // TAGS
180
        if (\xoops_isActiveModule('tag')  && \class_exists(\XoopsModules\Tag\FormTag::class) && $this->isGranted(Constants::PUBLISHER_ITEM_TAG)) {
181
            $textTags = new \XoopsModules\Tag\FormTag('item_tag', 60, 255, $obj->getVar('item_tag', 'e'), 0);
182
            $textTags->setClass('form-control');
183
            $this->addElement($textTags);
184
        }
185
186
        // SELECT EDITOR
187
        $nohtml = !$obj->dohtml();
188
        if (1 === \count($allowedEditors)) {
189
            $editor = $allowedEditors[0];
190
        } elseif (\count($allowedEditors) > 0) {
191
            $editor = Request::getString('editor', '', 'POST');
192
            if (!empty($editor)) {
193
                Utility::setCookieVar('publisher_editor', $editor);
194
            } else {
195
                $editor = Utility::getCookieVar('publisher_editor');
196
                if (empty($editor) && \is_object($GLOBALS['xoopsUser'])) {
197
                    //                    $editor = @ $GLOBALS['xoopsUser']->getVar('publisher_editor'); // Need set through user profile
198
                    $editor = $GLOBALS['xoopsUser']->getVar('publisher_editor') ?? ''; // Need set through user profile
199
                }
200
            }
201
            $editor = (empty($editor) || !\in_array($editor, $allowedEditors, true)) ? $helper->getConfig('submit_editor') : $editor;
202
203
            $formEditor = new \XoopsFormSelectEditor($this, 'editor', $editor, $nohtml, $allowedEditors);
204
            $this->addElement($formEditor);
205
        } else {
206
            $editor = $helper->getConfig('submit_editor');
207
        }
208
209
        $editorConfigs           = [];
210
        $editorConfigs['rows']   = !$helper->getConfig('submit_editor_rows') ? 35 : $helper->getConfig('submit_editor_rows');
211
        $editorConfigs['cols']   = !$helper->getConfig('submit_editor_cols') ? 60 : $helper->getConfig('submit_editor_cols');
212
        $editorConfigs['width']  = !$helper->getConfig('submit_editor_width') ? '100%' : $helper->getConfig('submit_editor_width');
213
        $editorConfigs['height'] = !$helper->getConfig('submit_editor_height') ? '400px' : $helper->getConfig('submit_editor_height');
214
215
        // SUMMARY
216
        if ($this->isGranted(Constants::PUBLISHER_SUMMARY)) {
217
            // Description
218
            //$summaryText = new \XoopsFormTextArea(_CO_PUBLISHER_SUMMARY, 'summary', $obj->getVar('summary', 'e'), 7, 60);
219
            $editorConfigs['name']  = 'summary';
220
            $editorConfigs['value'] = $obj->getVar('summary', 'e');
221
            $summaryText            = new \XoopsFormEditor(\_CO_PUBLISHER_SUMMARY, $editor, $editorConfigs, $nohtml, $onfailure = null);
222
            $summaryText->setDescription(\_CO_PUBLISHER_SUMMARY_DSC);
223
            $this->addElement($summaryText);
224
        }
225
226
        // BODY
227
        $editorConfigs['name']  = 'body';
228
        $editorConfigs['value'] = $obj->getVar('body', 'e');
229
        $bodyText               = new \XoopsFormEditor(\_CO_PUBLISHER_BODY, $editor, $editorConfigs, $nohtml, $onfailure = null);
230
        $bodyText->setDescription(\_CO_PUBLISHER_BODY_DSC);
231
        $this->addElement($bodyText);
232
233
        // VARIOUS OPTIONS
234
        if ($this->isGranted(Constants::PUBLISHER_DOHTML)
235
            || $this->isGranted(Constants::PUBLISHER_DOSMILEY)
236
            || $this->isGranted(Constants::PUBLISHER_DOXCODE)
237
            || $this->isGranted(Constants::PUBLISHER_DOIMAGE)
238
            || $this->isGranted(Constants::PUBLISHER_DOLINEBREAK)) {
239
            if ($this->isGranted(Constants::PUBLISHER_DOHTML)) {
240
                $htmlRadio = new \XoopsFormRadioYN(\_CO_PUBLISHER_DOHTML, 'dohtml', $obj->dohtml(), _YES, _NO);
241
                $this->addElement($htmlRadio);
242
            }
243
            if ($this->isGranted(Constants::PUBLISHER_DOSMILEY)) {
244
                $smiley_radio = new \XoopsFormRadioYN(\_CO_PUBLISHER_DOSMILEY, 'dosmiley', $obj->dosmiley(), _YES, _NO);
245
                $this->addElement($smiley_radio);
246
            }
247
            if ($this->isGranted(Constants::PUBLISHER_DOXCODE)) {
248
                $xcode_radio = new \XoopsFormRadioYN(\_CO_PUBLISHER_DOXCODE, 'doxcode', $obj->doxcode(), _YES, _NO);
249
                $this->addElement($xcode_radio);
250
            }
251
            if ($this->isGranted(Constants::PUBLISHER_DOIMAGE)) {
252
                $image_radio = new \XoopsFormRadioYN(\_CO_PUBLISHER_DOIMAGE, 'doimage', $obj->doimage(), _YES, _NO);
253
                $this->addElement($image_radio);
254
            }
255
            if ($this->isGranted(Constants::PUBLISHER_DOLINEBREAK)) {
256
                $linebreak_radio = new \XoopsFormRadioYN(\_CO_PUBLISHER_DOLINEBREAK, 'dolinebreak', $obj->dobr(), _YES, _NO);
257
                $this->addElement($linebreak_radio);
258
            }
259
        }
260
261
        // Available pages to wrap
262
        if ($this->isGranted(Constants::PUBLISHER_AVAILABLE_PAGE_WRAP)) {
263
            $wrapPages              = \XoopsLists::getHtmlListAsArray(Utility::getUploadDir(true, 'content'));
264
            $availableWrapPagesText = [];
265
            foreach ($wrapPages as $page) {
266
                $availableWrapPagesText[] = "<span onclick='publisherPageWrap(\"body\", \"[pagewrap=$page] \");' onmouseover='style.cursor=\"pointer\"'>$page</span>";
267
            }
268
            $availableWrapPages = new \XoopsFormLabel(\_CO_PUBLISHER_AVAILABLE_PAGE_WRAP, \implode(', ', $availableWrapPagesText));
269
            $availableWrapPages->setDescription(\_CO_PUBLISHER_AVAILABLE_PAGE_WRAP_DSC);
270
            $this->addElement($availableWrapPages);
271
        }
272
273
        //VOTING TYPE =====================================
274
        //        if ($this->isGranted(Constants::PUBLISHER_VOTETYPE)) {
275
        $groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
276
        /** @var GroupPermHandler $grouppermHandler */
277
        $grouppermHandler = $helper->getHandler('GroupPerm');
278
        $moduleId         = $helper->getModule()->getVar('mid');
279
        if ($helper->getConfig('perm_rating') && $grouppermHandler->checkRight('global', \_PUBLISHER_RATE, $groups, $moduleId)) {
280
            $options = [
281
                Constants::RATING_NONE     => \_MI_PUBLISHER_RATING_NONE,
282
                Constants::RATING_5STARS   => \_MI_PUBLISHER_RATING_5STARS,
283
                Constants::RATING_10STARS  => \_MI_PUBLISHER_RATING_10STARS,
284
                Constants::RATING_LIKES    => \_MI_PUBLISHER_RATING_LIKES,
285
                Constants::RATING_10NUM    => \_MI_PUBLISHER_RATING_10NUM,
286
                Constants::RATING_REACTION => \_MI_PUBLISHER_RATING_REACTION,
287
            ];
288
289
            $votetypeSelect = new \XoopsFormSelect(\_MI_PUBLISHER_RATINGBARS, 'votetype', $obj->getVar('votetype'));
290
            $votetypeSelect->addOptionArray($options);
291
            //                $votetypeSelect->setDescription(\_MI_PUBLISHER_RATINGBARS_DESC);
292
            $this->addElement($votetypeSelect);
293
            unset($votetypeSelect);
294
        }
295
        //        }
296
        //VOTING TYPE END =====================================
297
298
        $userUid = $obj->getVar('itemid') > 0 ? $obj->uid() : $currentUid;
299
        if ($this->isGranted(Constants::PUBLISHER_UID)) {
300
            $this->addElement(new \XoopsFormSelectUser(\_CO_PUBLISHER_UID, 'uid', false, $userUid, 1, false), false);
301
        }
302
303
        // Uid
304
        /*  We need to retreive the users manually because for some reason, on the frxoops.org server,
305
         the method users::getobjects encounters a memory error
306
         */ // Trabis : well, maybe is because you are getting 6000 objects into memory , no??? LOL
307
        /*
308
        if ($this->isGranted(Constants::PUBLISHER_UID)) {
309
            $uidSelect = new \XoopsFormSelect(_CO_PUBLISHER_UID, 'uid', $obj->uid(), 1, false);
310
            $uidSelect->setDescription(_CO_PUBLISHER_UID_DSC);
311
            $sql           = 'SELECT uid, uname FROM ' . $obj->db->prefix('users') . ' ORDER BY uname ASC';
312
            $result        = $obj->db->query($sql);
313
            $usersArray     = [];
314
            $usersArray[0] = $GLOBALS['xoopsConfig']['anonymous'];
315
            while (($myrow = $obj->db->fetchArray($result)) !== false) {
316
                $usersArray[$myrow['uid']] = $myrow['uname'];
317
            }
318
            $uidSelect->addOptionArray($usersArray);
319
            $this->addElement($uidSelect);
320
        }
321
        */
322
323
        /* else {
324
        $hidden = new \XoopsFormHidden('uid', $obj->uid());
325
        $this->addElement($hidden);
326
        unset($hidden);
327
        }*/
328
329
        // Author ALias
330
        if ($this->isGranted(Constants::PUBLISHER_AUTHOR_ALIAS)) {
331
            $element = new \XoopsFormText(\_CO_PUBLISHER_AUTHOR_ALIAS, 'author_alias', 50, 255, $obj->getVar('author_alias', 'e'));
332
            $element->setDescription(\_CO_PUBLISHER_AUTHOR_ALIAS_DSC);
333
            $this->addElement($element);
334
            unset($element);
335
        }
336
337
        // STATUS
338
        if ($this->isGranted(Constants::PUBLISHER_STATUS)) {
339
            $options      = [
340
                Constants::PUBLISHER_STATUS_SUBMITTED => \_CO_PUBLISHER_SUBMITTED,
341
                Constants::PUBLISHER_STATUS_PUBLISHED => \_CO_PUBLISHER_PUBLISHED,
342
                Constants::PUBLISHER_STATUS_OFFLINE   => \_CO_PUBLISHER_OFFLINE,
343
                Constants::PUBLISHER_STATUS_REJECTED  => \_CO_PUBLISHER_REJECTED,
344
            ];
345
            $statusSelect = new \XoopsFormSelect(\_CO_PUBLISHER_STATUS, 'status', $obj->getVar('status'));
346
            $statusSelect->addOptionArray($options);
347
            $statusSelect->setDescription(\_CO_PUBLISHER_STATUS_DSC);
348
            $this->addElement($statusSelect);
349
            unset($statusSelect);
350
        }
351
352
        // Datesub
353
        if ($this->isGranted(Constants::PUBLISHER_DATESUB)) {
354
            if ($obj->isNew()) {
355
                $datesub = \time();
356
            } else {
357
                $datesub = (0 == $obj->getVar('datesub')) ? \time() : $obj->getVar('datesub');
358
            }
359
            $datesub_datetime = new FormDateTime(\_CO_PUBLISHER_DATESUB, 'datesub', $size = 15, $datesub, true, true);
360
            // $datesub_datetime = new \XoopsFormDateTime(_CO_PUBLISHER_DATESUB, 'datesub', $size = 15, $datesub, true, true);
361
362
            $datesub_datetime->setDescription(\_CO_PUBLISHER_DATESUB_DSC);
363
            $this->addElement($datesub_datetime);
364
        }
365
366
        // Date expire
367
        if ($this->isGranted(Constants::PUBLISHER_DATEEXPIRE)) {
368
            if ($obj->isNew()) {
369
                $dateexpire     = \time();
370
                $dateexpire_opt = 0;
371
            } elseif (0 == $obj->getVar('dateexpire')) {
372
                $dateexpire_opt = 0;
373
                $dateexpire     = \time();
374
            } else {
375
                $dateexpire_opt = 1;
376
                $dateexpire     = $obj->getVar('dateexpire');
377
            }
378
379
            $dateExpireYesNo     = new \XoopsFormRadioYN('', 'use_expire_yn', $dateexpire_opt);
380
            $dateexpire          = (int)\formatTimestamp($dateexpire, 'U', $timeoffset); //set to user timezone
381
            $dateexpire_datetime = new \XoopsFormDateTime('', 'dateexpire', $size = 15, $dateexpire, true);
382
            if (0 == $dateexpire_opt) {
383
                $dateexpire_datetime->setExtra('disabled="disabled"');
384
            }
385
386
            $dateExpireTray = new \XoopsFormElementTray(\_CO_PUBLISHER_DATEEXPIRE, '');
387
            $dateExpireTray->setDescription(\_CO_PUBLISHER_DATEEXPIRE_DSC);
388
            $dateExpireTray->addElement($dateExpireYesNo);
389
            $dateExpireTray->addElement($dateexpire_datetime);
390
            $this->addElement($dateExpireTray);
391
        }
392
393
        // NOTIFY ON PUBLISH
394
        if ($this->isGranted(Constants::PUBLISHER_NOTIFY)) {
395
            $notify_radio = new \XoopsFormRadioYN(\_CO_PUBLISHER_NOTIFY, 'notify', $obj->notifypub(), _YES, _NO);
396
            $this->addElement($notify_radio);
397
        }
398
399
        if ($this->hasTab(\_CO_PUBLISHER_TAB_IMAGES)) {
400
            $this->startTab(\_CO_PUBLISHER_TAB_IMAGES);
401
        }
402
403
        // IMAGE ---------------------------------------
404
        if ($this->isGranted(Constants::PUBLISHER_IMAGE_ITEM)) {
405
            $objimages      = $obj->getImages();
406
            $mainarray      = \is_object($objimages['main']) ? [$objimages['main']] : [];
407
            $mergedimages   = \array_merge($mainarray, $objimages['others']);
408
            $objimage_array = [];
409
            foreach ($mergedimages as $imageObj) {
410
                $objimage_array[$imageObj->getVar('image_name')] = $imageObj->getVar('image_nicename');
411
            }
412
413
            /** @var \XoopsImagecategoryHandler $imgcatHandler */
414
            $imgcatHandler = \xoops_getHandler('imagecategory');
415
            if (\method_exists($imgcatHandler, 'getListByPermission')) {
416
                $catlist = $imgcatHandler->getListByPermission($group, 'imgcat_read', 1);
417
            } else {
418
                $catlist = $imgcatHandler->getList($group, 'imgcat_read', 1);
419
            }
420
            $imgcatConfig = $helper->getConfig('submit_imgcat');
421
            if (\in_array(Constants::PUBLISHER_IMGCAT_ALL, $imgcatConfig, true)) {
422
                $catids = \array_keys($catlist);
423
            } else {
424
                // compare selected in options with readable of user
425
                $catlist = \array_intersect($catlist, $imgcatConfig);
426
                $catids  = \array_keys($catlist);
427
            }
428
429
            $imageObjs = [];
430
            if (!empty($catids)) {
431
                /** @var \XoopsImageHandler $imageHandler */
432
                $imageHandler = \xoops_getHandler('image');
433
                $criteria     = new \CriteriaCompo(new \Criteria('imgcat_id', '(' . \implode(',', $catids) . ')', 'IN'));
434
                $criteria->add(new \Criteria('image_display', 1));
435
                $criteria->setSort('image_nicename');
436
                $criteria->order = 'ASC'; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method
437
                $imageObjs       = $imageHandler->getObjects($criteria, true);
438
                unset($criteria);
439
            }
440
            $image_array = [];
441
            foreach ($imageObjs as $imageObj) {
442
                $image_array[$imageObj->getVar('image_name')] = $imageObj->getVar('image_nicename');
443
            }
444
445
            $image_array = \array_diff($image_array, $objimage_array);
446
447
            $imageSelect = new \XoopsFormSelect('', 'image_notused', '', 5);
448
            $imageSelect->addOptionArray($image_array);
449
            $imageSelect->setExtra("onchange='showImgSelected(\"image_display\", \"image_notused\", \"uploads/\", \"\", \"" . XOOPS_URL . "\")'");
450
            //$imageSelect->setExtra( "onchange='appendMySelectOption(\"image_notused\", \"image_item\")'");
451
            unset($image_array);
452
453
            $imageSelect2 = new \XoopsFormSelect('', 'image_item', '', 5, true);
454
            $imageSelect2->addOptionArray($objimage_array);
455
            $imageSelect2->setExtra("onchange='publisher_updateSelectOption(\"image_item\", \"image_featured\"), showImgSelected(\"image_display\", \"image_item\", \"uploads/\", \"\", \"" . XOOPS_URL . "\")'");
456
457
            $buttonadd = new \XoopsFormButton('', 'buttonadd', \_CO_PUBLISHER_ADD);
458
            $buttonadd->setExtra("onclick='publisher_appendSelectOption(\"image_notused\", \"image_item\"), publisher_updateSelectOption(\"image_item\", \"image_featured\")'");
459
460
            $buttonremove = new \XoopsFormButton('', 'buttonremove', \_CO_PUBLISHER_REMOVE);
461
            $buttonremove->setExtra("onclick='publisher_appendSelectOption(\"image_item\", \"image_notused\"), publisher_updateSelectOption(\"image_item\", \"image_featured\")'");
462
463
            $opentable  = new \XoopsFormLabel('', '<table><tr><td>');
464
            $addcol     = new \XoopsFormLabel('', '</td><td>');
465
            $addbreak   = new \XoopsFormLabel('', '<br>');
466
            $closetable = new \XoopsFormLabel('', '</td></tr></table>');
467
468
            $GLOBALS['xoTheme']->addScript(PUBLISHER_URL . '/assets/js/ajaxupload.3.9.js');
469
            $js_data  = new \XoopsFormLabel(
470
                '', '
471
472
<script type= "text/javascript">
473
$publisher(document).ready(function () {
474
    var button = $publisher("#publisher_upload_button"), interval;
475
    new AjaxUpload(button,{
476
        action: "' . PUBLISHER_URL . '/include/ajax_upload.php", // I disabled uploads in this example for security reasons
477
        responseType: "text/html",
478
        name: "publisher_upload_file",
479
        onSubmit : function (file, ext) {
480
            // change button text, when user selects file
481
            $publisher("#publisher_upload_message").html(" ");
482
            button.html("<img src=\'' . PUBLISHER_URL . '/assets/images/loadingbar.gif\'>"); this.setData({
483
                "image_nicename": $publisher("#image_nicename").val(),
484
                "imgcat_id" : $publisher("#imgcat_id").val()
485
            });
486
            // If you want to allow uploading only 1 file at time,
487
            // you can disable upload button
488
            //this.disable();
489
            interval = window.setInterval(function () {
490
            }, 200);
491
        },
492
        onComplete: function (file, response) {
493
            button.text("' . \_CO_PUBLISHER_IMAGE_UPLOAD_NEW . '");
494
            window.clearInterval(interval);
495
            // enable upload button
496
            this.enable();
497
            // add file to the list
498
            var result = eval(response);
499
            if ("success" == result[0]) {
500
                 $publisher("#image_item").append("<option value=\'" + result[1] + "\' selected=\'selected\'>" + result[2] + "</option>");
501
                 publisher_updateSelectOption(\'image_item\', \'image_featured\');
502
                 showImgSelected(\'image_display\', \'image_item\', \'uploads/\', \'\', \'' . XOOPS_URL . '\')
503
            } else {
504
                 $publisher("#publisher_upload_message").html("<div class=\'errorMsg\'>" + result[1] + "</div>");
505
            }
506
        }
507
    });
508
});
509
</script>
510
511
'
512
            );
513
            $messages = new \XoopsFormLabel('', "<div id='publisher_upload_message'></div>");
514
            $button   = new \XoopsFormLabel('', "<div id='publisher_upload_button'>" . \_CO_PUBLISHER_IMAGE_UPLOAD_NEW . '</div>');
515
            $nicename = new \XoopsFormText('', 'image_nicename', 30, 30, \_CO_PUBLISHER_IMAGE_NICENAME);
516
517
            // $imgcatHandler = xoops_getHandler('imagecategory');
518
            // if (method_exists($imgcatHandler, 'getListByPermission')) {
519
            // $catlist = $imgcatHandler->getListByPermission($group, 'imgcat_read', 1);
520
            // } else {
521
            // $catlist = $imgcatHandler->getList($group, 'imgcat_read', 1);
522
            // }
523
            $imagecat = new \XoopsFormSelect('', 'imgcat_id', '', 1);
524
            $imagecat->addOptionArray($catlist);
525
526
            $imageUploadTray = new \XoopsFormElementTray(\_CO_PUBLISHER_IMAGE_UPLOAD, '');
527
            $imageUploadTray->addElement($js_data);
528
            $imageUploadTray->addElement($messages);
529
            $imageUploadTray->addElement($opentable);
530
            $imageUploadTray->addElement($imagecat);
531
            $imageUploadTray->addElement($addbreak);
532
            $imageUploadTray->addElement($nicename);
533
            $imageUploadTray->addElement($addbreak);
534
            $imageUploadTray->addElement($button);
535
            $imageUploadTray->addElement($closetable);
536
            $this->addElement($imageUploadTray);
537
538
            $imageTray = new \XoopsFormElementTray(\_CO_PUBLISHER_IMAGE_ITEMS, '');
539
            $imageTray->addElement($opentable);
540
541
            $imageTray->addElement($imageSelect);
542
            $imageTray->addElement($addbreak);
543
            $imageTray->addElement($buttonadd);
544
545
            $imageTray->addElement($addcol);
546
547
            $imageTray->addElement($imageSelect2);
548
            $imageTray->addElement($addbreak);
549
            $imageTray->addElement($buttonremove);
550
551
            $imageTray->addElement($closetable);
552
            $imageTray->setDescription(\_CO_PUBLISHER_IMAGE_ITEMS_DSC);
553
            $this->addElement($imageTray);
554
555
            $imagename    = \is_object($objimages['main']) ? $objimages['main']->getVar('image_name') : '';
556
            $imageforpath = ('' != $imagename) ? $imagename : 'blank.gif';
557
558
            $imageSelect3 = new \XoopsFormSelect(\_CO_PUBLISHER_IMAGE_ITEM, 'image_featured', $imagename, 1);
559
            $imageSelect3->addOptionArray($objimage_array);
560
            $imageSelect3->setExtra("onchange='showImgSelected(\"image_display\", \"image_featured\", \"uploads/\", \"\", \"" . XOOPS_URL . "\")'");
561
            $imageSelect3->setDescription(\_CO_PUBLISHER_IMAGE_ITEM_DSC);
562
            $this->addElement($imageSelect3);
563
564
            $image_preview = new \XoopsFormLabel(\_CO_PUBLISHER_IMAGE_PREVIEW, "<img src='" . XOOPS_URL . '/uploads/' . $imageforpath . "' name='image_display' id='image_display' alt=''>");
565
            $this->addElement($image_preview);
566
        }
567
568
        // FILES -----------------------------------
569
        if ($this->hasTab(\_CO_PUBLISHER_TAB_FILES)) {
570
            $this->startTab(\_CO_PUBLISHER_TAB_FILES);
571
        }
572
        // File upload UPLOAD
573
        if ($this->isGranted(Constants::PUBLISHER_ITEM_UPLOAD_FILE)) {
574
            // NAME
575
            $nameText = new \XoopsFormText(\_CO_PUBLISHER_FILENAME, 'item_file_name', 50, 255, '');
576
            $nameText->setDescription(\_CO_PUBLISHER_FILE_NAME_DSC);
577
            $this->addElement($nameText);
578
            unset($nameText);
579
580
            // DESCRIPTION
581
            $descriptionText = new \XoopsFormTextArea(\_CO_PUBLISHER_FILE_DESCRIPTION, 'item_file_description', '');
582
            $descriptionText->setDescription(\_CO_PUBLISHER_FILE_DESCRIPTION_DSC);
583
            $this->addElement($descriptionText);
584
            unset($descriptionText);
585
586
            $statusSelect = new \XoopsFormRadioYN(\_CO_PUBLISHER_FILE_STATUS, 'item_file_status', 1); //1 - active
587
            $statusSelect->setDescription(\_CO_PUBLISHER_FILE_STATUS_DSC);
588
            $this->addElement($statusSelect);
589
            unset($statusSelect);
590
591
            $fileBox = new \XoopsFormFile(\_CO_PUBLISHER_ITEM_UPLOAD_FILE, 'item_upload_file', 0);
592
            $fileBox->setDescription(\_CO_PUBLISHER_ITEM_UPLOAD_FILE_DSC);
593
            $fileBox->setExtra("size ='50'");
594
            $this->addElement($fileBox);
595
            unset($fileBox);
596
597
            if (!$obj->isNew()) {
598
                $filesObj = $helper->getHandler('File')->getAllFiles($obj->itemid());
599
                if (\count($filesObj) > 0) {
600
                    $table = '';
601
                    $table .= "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
602
                    $table .= '<tr>';
603
                    $table .= "<td width='50' class='bg3' align='center'><strong>ID</strong></td>";
604
                    $table .= "<td width='150' class='bg3' align='left'><strong>" . \_AM_PUBLISHER_FILENAME . '</strong></td>';
605
                    $table .= "<td class='bg3' align='left'><strong>" . \_AM_PUBLISHER_DESCRIPTION . '</strong></td>';
606
                    $table .= "<td width='60' class='bg3' align='center'><strong>" . \_AM_PUBLISHER_HITS . '</strong></td>';
607
                    $table .= "<td width='100' class='bg3' align='center'><strong>" . \_AM_PUBLISHER_UPLOADED_DATE . '</strong></td>';
608
                    $table .= "<td width='60' class='bg3' align='center'><strong>" . \_AM_PUBLISHER_ACTION . '</strong></td>';
609
                    $table .= '</tr>';
610
611
                    foreach ($filesObj as $fileObj) {
612
                        $modify      = "<a href='file.php?op=mod&fileid=" . $fileObj->fileid() . "'>" . $icons['edit'] . '</a>';
613
                        $delete      = "<a href='file.php?op=del&fileid=" . $fileObj->fileid() . "'>" . $icons['delete'] . '</a>';
614
                        $not_visible = '';
615
                        if (0 == $fileObj->status()) {
616
                            $not_visible = "<img src='" . PUBLISHER_URL . "/assets/images/no.gif'>";
617
                        }
618
                        $table .= '<tr>';
619
                        $table .= "<td class='head' align='center'>" . $fileObj->getVar('fileid') . '</td>';
620
                        $table .= "<td class='odd' align='left'>" . $not_visible . $fileObj->getFileLink() . '</td>';
621
                        $table .= "<td class='even' align='left'>" . $fileObj->description() . '</td>';
622
                        $table .= "<td class='even' align='center'>" . $fileObj->counter() . '';
623
                        $table .= "<td class='even' align='center'>" . $fileObj->getDatesub() . '</td>';
624
                        $table .= "<td class='even' align='center'> $modify $delete </td>";
625
                        $table .= '</tr>';
626
                    }
627
                    $table .= '</table>';
628
629
                    $files_box = new \XoopsFormLabel(\_CO_PUBLISHER_FILES_LINKED, $table);
630
                    $this->addElement($files_box);
631
                    unset($files_box, $filesObj, $fileObj);
632
                }
633
            }
634
        }
635
636
        // OTHERS -----------------------------------
637
        if ($this->hasTab(\_CO_PUBLISHER_TAB_OTHERS)) {
638
            $this->startTab(\_CO_PUBLISHER_TAB_OTHERS);
639
        }
640
        //$this->startTab(_CO_PUBLISHER_TAB_META);
641
        // Meta Keywords
642
        if ($this->isGranted(Constants::PUBLISHER_ITEM_META_KEYWORDS)) {
643
            $text_meta_keywords = new \XoopsFormTextArea(\_CO_PUBLISHER_ITEM_META_KEYWORDS, 'item_meta_keywords', $obj->meta_keywords('e'), 7, 60);
644
            $text_meta_keywords->setDescription(\_CO_PUBLISHER_ITEM_META_KEYWORDS_DSC);
645
            $this->addElement($text_meta_keywords);
646
        }
647
648
        // Meta Description
649
        if ($this->isGranted(Constants::PUBLISHER_ITEM_META_DESCRIPTION)) {
650
            $text_meta_description = new \XoopsFormTextArea(\_CO_PUBLISHER_ITEM_META_DESCRIPTION, 'item_meta_description', $obj->meta_description('e'), 7, 60);
651
            $text_meta_description->setDescription(\_CO_PUBLISHER_ITEM_META_DESCRIPTION_DSC);
652
            $this->addElement($text_meta_description);
653
        }
654
655
        //$this->startTab(_CO_PUBLISHER_TAB_PERMISSIONS);
656
657
        // COMMENTS
658
        if ($this->isGranted(Constants::PUBLISHER_ALLOWCOMMENTS)) {
659
            $addcomments_radio = new \XoopsFormRadioYN(\_CO_PUBLISHER_ALLOWCOMMENTS, 'allowcomments', $obj->cancomment(), _YES, _NO);
660
            $this->addElement($addcomments_radio);
661
        }
662
663
        // WEIGHT
664
        if ($this->isGranted(Constants::PUBLISHER_WEIGHT)) {
665
            $this->addElement(new \XoopsFormText(\_CO_PUBLISHER_WEIGHT, 'weight', 5, 5, $obj->weight()));
666
        }
667
668
        $this->endTabs();
669
670
        //COMMON TO ALL TABS
671
672
        $buttonTray = new \XoopsFormElementTray('', '');
673
674
        if ($obj->isNew()) {
675
            $buttonTray->addElement(new \XoopsFormButton('', 'additem', \_CO_PUBLISHER_CREATE, 'submit'));
676
            $buttonTray->addElement(new \XoopsFormButton('', '', \_CO_PUBLISHER_CLEAR, 'reset'));
677
        } else {
678
            $buttonTray->addElement(new \XoopsFormButton('', 'additem', _SUBMIT, 'submit')); //orclone
679
        }
680
681
        $buttonTray->addElement(new \XoopsFormButton('', 'preview', \_CO_PUBLISHER_PREVIEW, 'submit'));
682
683
        $butt_cancel = new \XoopsFormButton('', '', \_CO_PUBLISHER_CANCEL, 'button');
684
        $butt_cancel->setExtra('onclick="history.go(-1)"');
685
        $buttonTray->addElement($butt_cancel);
686
687
        $this->addElement($buttonTray);
688
689
        $hidden = new \XoopsFormHidden('itemid', $obj->itemid());
0 ignored issues
show
It seems like $obj->itemid() can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

689
        $hidden = new \XoopsFormHidden('itemid', /** @scrutinizer ignore-type */ $obj->itemid());
Loading history...
690
        $this->addElement($hidden);
691
        unset($hidden);
692
693
        return $this;
694
    }
695
}
696