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 XOOPS Project (https://xoops.org) |
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\Category; |
26
|
|
|
use XoopsModules\Publisher\Helper; |
27
|
|
|
use XoopsModules\Publisher\Utility; |
28
|
|
|
|
29
|
|
|
// require_once \dirname(__DIR__, 2) . '/include/common.php'; |
30
|
|
|
|
31
|
|
|
\xoops_load('XoopsFormLoader'); |
32
|
|
|
require_once $GLOBALS['xoops']->path('class/tree.php'); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class CategoryForm |
36
|
|
|
*/ |
37
|
|
|
class CategoryForm extends \XoopsThemeForm |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* @var Helper |
41
|
|
|
*/ |
42
|
|
|
public $helper; |
43
|
|
|
public $targetObject; |
44
|
|
|
public $subCatsCount = 4; |
45
|
|
|
public $userGroups = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Category $target |
49
|
|
|
* @param int $subCatsCount |
50
|
|
|
*/ |
51
|
|
|
public function __construct(&$target, $subCatsCount = 4) |
52
|
|
|
{ |
53
|
|
|
/** @var Helper $this- >helper */ |
54
|
|
|
$this->helper = Helper::getInstance(); |
55
|
|
|
|
56
|
|
|
$this->targetObject = &$target; |
57
|
|
|
$this->subCatsCount = $subCatsCount; |
58
|
|
|
|
59
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
60
|
|
|
$memberHandler = \xoops_getHandler('member'); |
61
|
|
|
$this->userGroups = $memberHandler->getGroupList(); |
62
|
|
|
|
63
|
|
|
parent::__construct(\_AM_PUBLISHER_CATEGORY, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
64
|
|
|
$this->setExtra('enctype="multipart/form-data"'); |
65
|
|
|
|
66
|
|
|
$this->createElements(); |
67
|
|
|
$this->createButtons(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function createElements(): void |
71
|
|
|
{ |
72
|
|
|
// require_once \dirname(__DIR__, 2) . '/include/common.php'; |
73
|
|
|
// Category |
74
|
|
|
$criteria = new \Criteria(null); |
75
|
|
|
$criteria->setSort('weight'); |
76
|
|
|
$criteria->order = 'ASC'; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method |
77
|
|
|
$myTree = new \XoopsObjectTree( |
78
|
|
|
$this->helper->getHandler('Category') |
79
|
|
|
->getObjects($criteria), 'categoryid', 'parentid' |
80
|
|
|
); |
81
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
82
|
|
|
$module = \XoopsModule::getByDirname($moduleDirName); |
|
|
|
|
83
|
|
|
$catSelect = $myTree->makeSelectElement('parentid', 'name', '--', $this->targetObject->parentid(), true, 0, '', \_AM_PUBLISHER_PARENT_CATEGORY_EXP); |
|
|
|
|
84
|
|
|
$this->addElement($catSelect); |
85
|
|
|
|
86
|
|
|
// Name |
87
|
|
|
$this->addElement(new \XoopsFormText(\_AM_PUBLISHER_CATEGORY, 'name', 50, 255, $this->targetObject->name('e')), true); |
|
|
|
|
88
|
|
|
|
89
|
|
|
// Description |
90
|
|
|
$this->addElement(new \XoopsFormTextArea(\_AM_PUBLISHER_COLDESCRIPT, 'description', $this->targetObject->description('e'), 7, 60)); |
|
|
|
|
91
|
|
|
|
92
|
|
|
// EDITOR |
93
|
|
|
$groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
94
|
|
|
$grouppermHandler = $this->helper->getHandler('GroupPerm'); |
95
|
|
|
$moduleId = $this->helper->getModule() |
96
|
|
|
->mid(); |
97
|
|
|
$allowedEditors = Utility::getEditors($grouppermHandler->getItemIds('editors', $groups, $moduleId)); |
98
|
|
|
$nohtml = false; |
99
|
|
|
if (\count($allowedEditors) > 0) { |
100
|
|
|
$editor = Request::getString('editor', '', 'POST'); |
101
|
|
|
if (!empty($editor)) { |
102
|
|
|
Utility::setCookieVar('publisher_editor', $editor); |
103
|
|
|
} else { |
104
|
|
|
$editor = Utility::getCookieVar('publisher_editor'); |
105
|
|
|
if (empty($editor) && \is_object($GLOBALS['xoopsUser'])) { |
106
|
|
|
$editor = $GLOBALS['xoopsUser']->getVar('publisher_editor') ?? ''; // Need set through user profile |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
$editor = (empty($editor) || !\in_array($editor, $allowedEditors, true)) ? $this->helper->getConfig('submit_editor') : $editor; |
110
|
|
|
$formEditor = new \XoopsFormSelectEditor($this, 'editor', $editor, $nohtml, $allowedEditors); |
|
|
|
|
111
|
|
|
$this->addElement($formEditor); |
112
|
|
|
} else { |
113
|
|
|
$editor = $this->helper->getConfig('submit_editor'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$editorConfigs = []; |
117
|
|
|
$editorConfigs['rows'] = '' == $this->helper->getConfig('submit_editor_rows') ? 35 : $this->helper->getConfig('submit_editor_rows'); |
118
|
|
|
$editorConfigs['cols'] = '' == $this->helper->getConfig('submit_editor_cols') ? 60 : $this->helper->getConfig('submit_editor_cols'); |
119
|
|
|
$editorConfigs['width'] = '' == $this->helper->getConfig('submit_editor_width') ? '100%' : $this->helper->getConfig('submit_editor_width'); |
120
|
|
|
$editorConfigs['height'] = '' == $this->helper->getConfig('submit_editor_height') ? '400px' : $this->helper->getConfig('submit_editor_height'); |
121
|
|
|
|
122
|
|
|
$editorConfigs['name'] = 'header'; |
123
|
|
|
$editorConfigs['value'] = $this->targetObject->header('e'); |
|
|
|
|
124
|
|
|
|
125
|
|
|
$textHeader = new \XoopsFormEditor(\_AM_PUBLISHER_CATEGORY_HEADER, $editor, $editorConfigs, $nohtml, $onfailure = null); |
126
|
|
|
$textHeader->setDescription(\_AM_PUBLISHER_CATEGORY_HEADER_DSC); |
127
|
|
|
$this->addElement($textHeader); |
128
|
|
|
|
129
|
|
|
// IMAGE |
130
|
|
|
$imageArray = \XoopsLists::getImgListAsArray(Utility::getImageDir('category')); |
131
|
|
|
$imageSelect = new \XoopsFormSelect('', 'image', $this->targetObject->getImage()); |
132
|
|
|
//$imageSelect -> addOption ('-1', '---------------'); |
133
|
|
|
$imageSelect->addOptionArray($imageArray); |
134
|
|
|
$imageSelect->setExtra("onchange='showImgSelected(\"image3\", \"image\", \"" . 'uploads/' . $this->helper->getDirname() . '/images/category/' . '", "", "' . XOOPS_URL . "\")'"); |
135
|
|
|
$imageTray = new \XoopsFormElementTray(\_AM_PUBLISHER_IMAGE, ' '); |
136
|
|
|
$imageTray->addElement($imageSelect); |
137
|
|
|
$imageTray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . Utility::getImageDir('category', false) . $this->targetObject->getImage() . "' name='image3' id='image3' alt=''>")); |
138
|
|
|
$imageTray->setDescription(\_AM_PUBLISHER_IMAGE_DSC); |
139
|
|
|
$this->addElement($imageTray); |
140
|
|
|
|
141
|
|
|
// IMAGE UPLOAD |
142
|
|
|
$maxSize = 5000000; |
143
|
|
|
$fileBox = new \XoopsFormFile(\_AM_PUBLISHER_IMAGE_UPLOAD, 'image_file', $maxSize); |
144
|
|
|
$fileBox->setExtra("size ='45'"); |
145
|
|
|
$fileBox->setDescription(\_AM_PUBLISHER_IMAGE_UPLOAD_DSC); |
146
|
|
|
$this->addElement($fileBox); |
147
|
|
|
|
148
|
|
|
// Short url |
149
|
|
|
$textShortUrl = new \XoopsFormText(\_AM_PUBLISHER_CATEGORY_SHORT_URL, 'short_url', 50, 255, $this->targetObject->short_url('e')); |
|
|
|
|
150
|
|
|
$textShortUrl->setDescription(\_AM_PUBLISHER_CATEGORY_SHORT_URL_DSC); |
151
|
|
|
$this->addElement($textShortUrl); |
152
|
|
|
|
153
|
|
|
// Meta Keywords |
154
|
|
|
$textMetaKeywords = new \XoopsFormTextArea(\_AM_PUBLISHER_CATEGORY_META_KEYWORDS, 'meta_keywords', $this->targetObject->meta_keywords('e'), 7, 60); |
|
|
|
|
155
|
|
|
$textMetaKeywords->setDescription(\_AM_PUBLISHER_CATEGORY_META_KEYWORDS_DSC); |
156
|
|
|
$this->addElement($textMetaKeywords); |
157
|
|
|
|
158
|
|
|
// Meta Description |
159
|
|
|
$textMetaDescription = new \XoopsFormTextArea(\_AM_PUBLISHER_CATEGORY_META_DESCRIPTION, 'meta_description', $this->targetObject->meta_description('e'), 7, 60); |
|
|
|
|
160
|
|
|
$textMetaDescription->setDescription(\_AM_PUBLISHER_CATEGORY_META_DESCRIPTION_DSC); |
161
|
|
|
$this->addElement($textMetaDescription); |
162
|
|
|
|
163
|
|
|
// Weight |
164
|
|
|
$this->addElement(new \XoopsFormText(\_AM_PUBLISHER_COLPOSIT, 'weight', 4, 4, $this->targetObject->weight())); |
|
|
|
|
165
|
|
|
|
166
|
|
|
// Added by skalpa: custom template support for Category view |
167
|
|
|
// $this->addElement(new \XoopsFormText('Custom template', 'template', 50, 255, $this->targetObject->getTemplate('e')), false); |
168
|
|
|
|
169
|
|
|
$dir = $this->helper->path('templates/custom/category'); |
170
|
|
|
$availableTemplates = []; |
171
|
|
|
if (\is_dir($dir)) { |
172
|
|
|
$templateList = \XoopsLists::getFileListAsArray($dir); |
173
|
|
|
foreach ($templateList as $file) { |
174
|
|
|
if (\preg_match('/(\.tpl)$/i', $file)) { |
175
|
|
|
$availableTemplates[$file] = $file; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$categoryTemplate = new \XoopsFormSelect(\_AM_PUBLISHER_CUSTOM_CATEGORY_TEMPLATE, 'template', $this->targetObject->getVar('template')); |
181
|
|
|
|
182
|
|
|
$categoryTemplate->addOption('', ''); |
183
|
|
|
$categoryTemplate->addOptionArray($availableTemplates); |
184
|
|
|
|
185
|
|
|
$this->addElement($categoryTemplate, false); |
186
|
|
|
|
187
|
|
|
// CUSTOM TEMPLATE FOR ARTICLES in Particular Category |
188
|
|
|
$dirCategoryItem = $this->helper->path('templates/custom/categoryitem'); |
189
|
|
|
$availableItemTemplates = []; |
190
|
|
|
if (\is_dir($dirCategoryItem)) { |
191
|
|
|
$templateItemList = \XoopsLists::getFileListAsArray($dirCategoryItem); |
192
|
|
|
foreach ($templateItemList as $file) { |
193
|
|
|
if (\preg_match('/(\.tpl)$/i', $file)) { |
194
|
|
|
$availableItemTemplates[$file] = $file; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$categoryItemTemplate = new \XoopsFormSelect(\_AM_PUBLISHER_CUSTOM_CATEGORY_ITEM_TEMPLATE, 'template_item', $this->targetObject->getVar('template_item')); |
200
|
|
|
|
201
|
|
|
$categoryItemTemplate->addOption('', ''); |
202
|
|
|
$categoryItemTemplate->addOptionArray($availableItemTemplates); |
203
|
|
|
|
204
|
|
|
$this->addElement($categoryItemTemplate, false); |
205
|
|
|
|
206
|
|
|
// READ PERMISSIONS |
207
|
|
|
$readPermissionsTray = new \XoopsFormElementTray(\_AM_PUBLISHER_PERMISSIONS_CAT_READ, ''); |
208
|
|
|
$selectAllReadCheckbox = new \XoopsFormCheckBox('', 'adminbox', 1); |
209
|
|
|
$selectAllReadCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
210
|
|
|
$selectAllReadCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox\" , \"groupsRead[]\");' "); |
211
|
|
|
$selectAllReadCheckbox->setClass('xo-checkall'); |
212
|
|
|
$readPermissionsTray->addElement($selectAllReadCheckbox); |
213
|
|
|
|
214
|
|
|
$groupsReadCheckbox = new \XoopsFormCheckBox('', 'groupsRead[]', $this->targetObject->getGroupsRead()); |
215
|
|
|
|
216
|
|
|
foreach ($this->userGroups as $groupId => $groupName) { |
217
|
|
|
$groupsReadCheckbox->addOption($groupId, $groupName); |
218
|
|
|
} |
219
|
|
|
$readPermissionsTray->addElement($groupsReadCheckbox); |
220
|
|
|
$this->addElement($readPermissionsTray); |
221
|
|
|
|
222
|
|
|
// SUBMIT PERMISSIONS |
223
|
|
|
$submitPermissionsTray = new \XoopsFormElementTray(\_AM_PUBLISHER_PERMISSIONS_CAT_SUBMIT, ''); |
224
|
|
|
$submitPermissionsTray->setDescription(\_AM_PUBLISHER_PERMISSIONS_CAT_SUBMIT_DSC); |
225
|
|
|
|
226
|
|
|
$selectAllSubmitCheckbox = new \XoopsFormCheckBox('', 'adminbox2', 1); |
227
|
|
|
$selectAllSubmitCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
228
|
|
|
$selectAllSubmitCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox2\" , \"groupsSubmit[]\");' "); |
229
|
|
|
$selectAllSubmitCheckbox->setClass('xo-checkall'); |
230
|
|
|
$submitPermissionsTray->addElement($selectAllSubmitCheckbox); |
231
|
|
|
|
232
|
|
|
$groupsSubmitCheckbox = new \XoopsFormCheckBox('', 'groupsSubmit[]', $this->targetObject->getGroupsSubmit()); |
233
|
|
|
foreach ($this->userGroups as $groupId => $groupName) { |
234
|
|
|
$groupsSubmitCheckbox->addOption($groupId, $groupName); |
235
|
|
|
} |
236
|
|
|
$submitPermissionsTray->addElement($groupsSubmitCheckbox); |
237
|
|
|
$this->addElement($submitPermissionsTray); |
238
|
|
|
|
239
|
|
|
// MODERATION PERMISSIONS |
240
|
|
|
$moderatePermissionsTray = new \XoopsFormElementTray(\_AM_PUBLISHER_PERMISSIONS_CAT_MODERATOR, ''); |
241
|
|
|
$moderatePermissionsTray->setDescription(\_AM_PUBLISHER_PERMISSIONS_CAT_MODERATOR_DSC); |
242
|
|
|
|
243
|
|
|
$selectAllModerateCheckbox = new \XoopsFormCheckBox('', 'adminbox3', 1); |
244
|
|
|
$selectAllModerateCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
245
|
|
|
$selectAllModerateCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox3\" , \"groupsModeration[]\");' "); |
246
|
|
|
$selectAllModerateCheckbox->setClass('xo-checkall'); |
247
|
|
|
$moderatePermissionsTray->addElement($selectAllModerateCheckbox); |
248
|
|
|
|
249
|
|
|
$groupsModerationCheckbox = new \XoopsFormCheckBox('', 'groupsModeration[]', $this->targetObject->getGroupsModeration()); |
250
|
|
|
|
251
|
|
|
foreach ($this->userGroups as $groupId => $groupName) { |
252
|
|
|
$groupsModerationCheckbox->addOption($groupId, $groupName); |
253
|
|
|
} |
254
|
|
|
$moderatePermissionsTray->addElement($groupsModerationCheckbox); |
255
|
|
|
$this->addElement($moderatePermissionsTray); |
256
|
|
|
|
257
|
|
|
$moderator = new \XoopsFormSelectUser(\_AM_PUBLISHER_CATEGORY_MODERATOR, 'moderator', true, $this->targetObject->moderator('e'), 1, false); |
|
|
|
|
258
|
|
|
$moderator->setDescription(\_AM_PUBLISHER_CATEGORY_MODERATOR_DSC); |
259
|
|
|
$this->addElement($moderator); |
260
|
|
|
|
261
|
|
|
//SUBCATEGORY |
262
|
|
|
$catTray = new \XoopsFormElementTray(\_AM_PUBLISHER_SCATEGORYNAME, '<br><br>'); |
263
|
|
|
for ($i = 0; $i < $this->subCatsCount; ++$i) { |
264
|
|
|
$subname = ''; |
265
|
|
|
if ($i < (($scname = Request::getArray('scname', [], 'POST')) ? \count($scname) : 0)) { |
266
|
|
|
$temp = Request::getArray('scname', [], 'POST'); |
267
|
|
|
$subname = ($scname = Request::getArray('scname', '', 'POST')) ? $temp[$i] : ''; |
|
|
|
|
268
|
|
|
} |
269
|
|
|
$catTray->addElement(new \XoopsFormText('', 'scname[' . $i . ']', 50, 255, $subname)); |
270
|
|
|
} |
271
|
|
|
$t = new \XoopsFormText('', 'nb_subcats', 3, 2); |
272
|
|
|
$l = new \XoopsFormLabel('', \sprintf(\_AM_PUBLISHER_ADD_OPT, $t->render())); |
273
|
|
|
$b = new \XoopsFormButton('', 'submit_subcats', \_AM_PUBLISHER_ADD_OPT_SUBMIT, 'submit'); |
274
|
|
|
|
275
|
|
|
if ($this->targetObject->categoryid()) { |
|
|
|
|
276
|
|
|
$b->setExtra('onclick="this.form.elements.op.value=\'mod\'"'); |
277
|
|
|
} else { |
278
|
|
|
$b->setExtra('onclick="this.form.elements.op.value=\'addsubcats\'"'); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
$r = new \XoopsFormElementTray(''); |
282
|
|
|
$r->addElement($l); |
283
|
|
|
$r->addElement($b); |
284
|
|
|
$catTray->addElement($r); |
285
|
|
|
$this->addElement($catTray); |
286
|
|
|
|
287
|
|
|
$this->addElement(new \XoopsFormHidden('categoryid', $this->targetObject->categoryid())); |
|
|
|
|
288
|
|
|
$this->addElement(new \XoopsFormHidden('nb_sub_yet', $this->subCatsCount)); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
public function createButtons(): void |
292
|
|
|
{ |
293
|
|
|
// Action buttons tray |
294
|
|
|
$buttonTray = new \XoopsFormElementTray('', ''); |
295
|
|
|
|
296
|
|
|
// No ID for category -- then it's new category, button says 'Create' |
297
|
|
|
if ($this->targetObject->categoryid()) { |
298
|
|
|
$buttonTray->addElement(new \XoopsFormButton('', 'addcategory', \_AM_PUBLISHER_MODIFY, 'submit')); |
299
|
|
|
$buttCancel = new \XoopsFormButton('', '', \_AM_PUBLISHER_CANCEL, 'button'); |
300
|
|
|
$buttCancel->setExtra('onclick="history.go(-1)"'); |
301
|
|
|
$buttonTray->addElement($buttCancel); |
302
|
|
|
|
303
|
|
|
$this->addElement($buttonTray); |
304
|
|
|
} else { |
305
|
|
|
$buttonTray->addElement(new \XoopsFormButton('', 'addcategory', \_AM_PUBLISHER_CREATE, 'submit')); |
306
|
|
|
|
307
|
|
|
$buttClear = new \XoopsFormButton('', '', \_AM_PUBLISHER_CLEAR, 'reset'); |
308
|
|
|
$buttonTray->addElement($buttClear); |
309
|
|
|
|
310
|
|
|
$buttCancel = new \XoopsFormButton('', '', \_AM_PUBLISHER_CANCEL, 'button'); |
311
|
|
|
$buttCancel->setExtra('onclick="history.go(-1)"'); |
312
|
|
|
$buttonTray->addElement($buttCancel); |
313
|
|
|
|
314
|
|
|
$this->addElement($buttonTray); |
315
|
|
|
} |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|