|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Mymodule2; |
|
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
|
|
|
* My Module 2 module for xoops |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright 2020 XOOPS Project (https://xooops.org) |
|
19
|
|
|
* @license GPL 2.0 or later |
|
20
|
|
|
* @package mymodule2 |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
* @min_xoops 2.5.9 |
|
23
|
|
|
* @author TDM XOOPS - Email:<[email protected]> - Website:<http://xoops.org> |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
use XoopsModules\Mymodule2; |
|
27
|
|
|
|
|
28
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class Object Articles |
|
32
|
|
|
*/ |
|
33
|
|
|
class Articles extends \XoopsObject |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Constructor |
|
37
|
|
|
* |
|
38
|
|
|
* @param null |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->initVar('art_id', XOBJ_DTYPE_INT); |
|
43
|
|
|
$this->initVar('art_cat', XOBJ_DTYPE_INT); |
|
44
|
|
|
$this->initVar('art_title', XOBJ_DTYPE_TXTBOX); |
|
45
|
|
|
$this->initVar('art_descr', XOBJ_DTYPE_TXTAREA); |
|
46
|
|
|
$this->initVar('art_img', XOBJ_DTYPE_TXTBOX); |
|
47
|
|
|
$this->initVar('art_status', XOBJ_DTYPE_INT); |
|
48
|
|
|
$this->initVar('art_file', XOBJ_DTYPE_TXTBOX); |
|
49
|
|
|
$this->initVar('art_created', XOBJ_DTYPE_INT); |
|
50
|
|
|
$this->initVar('art_submitter', XOBJ_DTYPE_INT); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @static function &getInstance |
|
55
|
|
|
* |
|
56
|
|
|
* @param null |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function getInstance() |
|
59
|
|
|
{ |
|
60
|
|
|
static $instance = false; |
|
61
|
|
|
if (!$instance) { |
|
62
|
|
|
$instance = new self(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* The new inserted $Id |
|
68
|
|
|
* @return inserted id |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
|
|
public function getNewInsertedIdArticles() |
|
71
|
|
|
{ |
|
72
|
|
|
$newInsertedId = $GLOBALS['xoopsDB']->getInsertId(); |
|
73
|
|
|
return $newInsertedId; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @public function getForm |
|
78
|
|
|
* @param bool $action |
|
79
|
|
|
* @return XoopsThemeForm |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
public function getFormArticles($action = false) |
|
82
|
|
|
{ |
|
83
|
|
|
$helper = \XoopsModules\Mymodule2\Helper::getInstance(); |
|
84
|
|
|
if (false === $action) { |
|
85
|
|
|
$action = $_SERVER['REQUEST_URI']; |
|
86
|
|
|
} |
|
87
|
|
|
// Permissions for uploader |
|
88
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
|
89
|
|
|
$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
90
|
|
|
if ($GLOBALS['xoopsUser']) { |
|
91
|
|
|
if (!$GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) { |
|
92
|
|
|
$permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
|
|
|
|
|
|
93
|
|
|
} else { |
|
94
|
|
|
$permissionUpload = true; |
|
95
|
|
|
} |
|
96
|
|
|
} else { |
|
97
|
|
|
$permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false; |
|
98
|
|
|
} |
|
99
|
|
|
// Title |
|
100
|
|
|
$title = $this->isNew() ? sprintf(_AM_MYMODULE2_ARTICLE_ADD) : sprintf(_AM_MYMODULE2_ARTICLE_EDIT); |
|
101
|
|
|
// Get Theme Form |
|
102
|
|
|
xoops_load('XoopsFormLoader'); |
|
103
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
|
104
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
|
105
|
|
|
// Use tag module |
|
106
|
|
|
$dirTag = is_dir(XOOPS_ROOT_PATH . '/modules/tag') ? true : false; |
|
107
|
|
|
if (($helper->getConfig('usetag') == 1) && $dirTag) { |
|
108
|
|
|
$tagId = $this->isNew() ? 0 : $this->getVar('art_id'); |
|
109
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php'; |
|
110
|
|
|
$form->addElement(new \XoopsFormTag( 'tag', 60, 255, $tagId, 0 ), true); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
// Form Table categories |
|
113
|
|
|
$categoriesHandler = $helper->getHandler('categories'); |
|
114
|
|
|
$artCatSelect = new \XoopsFormSelect( _AM_MYMODULE2_ARTICLE_CAT, 'art_cat', $this->getVar('art_cat')); |
|
115
|
|
|
$artCatSelect->addOptionArray($categoriesHandler->getList()); |
|
|
|
|
|
|
116
|
|
|
$form->addElement($artCatSelect, true); |
|
117
|
|
|
// Form Text ArtTitle |
|
118
|
|
|
$form->addElement(new \XoopsFormText( _AM_MYMODULE2_ARTICLE_TITLE, 'art_title', 50, 255, $this->getVar('art_title') ), true); |
|
|
|
|
|
|
119
|
|
|
// Form editor ArtDescr |
|
120
|
|
|
$editorConfigs = []; |
|
121
|
|
|
$editorConfigs['name'] = 'art_descr'; |
|
122
|
|
|
$editorConfigs['value'] = $this->getVar('art_descr', 'e'); |
|
123
|
|
|
$editorConfigs['rows'] = 5; |
|
124
|
|
|
$editorConfigs['cols'] = 40; |
|
125
|
|
|
$editorConfigs['width'] = '100%'; |
|
126
|
|
|
$editorConfigs['height'] = '400px'; |
|
127
|
|
|
$editorConfigs['editor'] = $helper->getConfig('editor_descr'); |
|
128
|
|
|
$form->addElement(new \XoopsFormEditor( _AM_MYMODULE2_ARTICLE_DESCR, 'art_descr', $editorConfigs), true); |
|
129
|
|
|
// Form Image ArtImg |
|
130
|
|
|
// Form Image ArtImg: Select Uploaded Image |
|
131
|
|
|
$getArtImg = $this->getVar('art_img'); |
|
132
|
|
|
$artImg = $getArtImg ? $getArtImg : 'blank.gif'; |
|
133
|
|
|
$imageDirectory = '/uploads/mymodule2/images/articles'; |
|
134
|
|
|
$imageTray = new \XoopsFormElementTray(_AM_MYMODULE2_ARTICLE_IMG, '<br>' ); |
|
135
|
|
|
$imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE2_ARTICLE_IMG_UPLOADS, ".{$imageDirectory}/"), 'art_img', $artImg, 5); |
|
136
|
|
|
$imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory ); |
|
137
|
|
|
foreach($imageArray as $image1) { |
|
138
|
|
|
$imageSelect->addOption("{$image1}", $image1); |
|
139
|
|
|
} |
|
140
|
|
|
$imageSelect->setExtra("onchange='showImgSelected(\"imglabel_art_img\", \"art_img\", \"".$imageDirectory."\", \"\", \"".XOOPS_URL."\")'"); |
|
141
|
|
|
$imageTray->addElement($imageSelect, false); |
|
142
|
|
|
$imageTray->addElement(new \XoopsFormLabel('', "<br><img src='".XOOPS_URL."/".$imageDirectory."/".$artImg."' name='imglabel_art_img' id='imglabel_art_img' alt='' style='max-width:100px' />")); |
|
143
|
|
|
// Form Image ArtImg: Upload new image |
|
144
|
|
|
if ($permissionUpload) { |
|
145
|
|
|
$maxsize = $helper->getConfig('maxsize_image'); |
|
146
|
|
|
$imageTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE2_FORM_UPLOAD_NEW, 'art_img', $maxsize )); |
|
147
|
|
|
$imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE2_FORM_UPLOAD_SIZE_MB)); |
|
148
|
|
|
$imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px')); |
|
149
|
|
|
$imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px')); |
|
150
|
|
|
} else { |
|
151
|
|
|
$imageTray->addElement(new \XoopsFormHidden( 'art_img', $artImg )); |
|
152
|
|
|
} |
|
153
|
|
|
$form->addElement($imageTray, ); |
|
154
|
|
|
// Form Select Articles |
|
155
|
|
|
$artStatusSelect = new \XoopsFormSelect( _AM_MYMODULE2_ARTICLE_STATUS, 'art_status', $this->getVar('art_status')); |
|
156
|
|
|
$artStatusSelect->addOption(Constants::STATUS_NONE, _AM_MYMODULE2_STATUS_NONE); |
|
157
|
|
|
$artStatusSelect->addOption(Constants::STATUS_OFFLINE, _AM_MYMODULE2_STATUS_OFFLINE); |
|
158
|
|
|
$artStatusSelect->addOption(Constants::STATUS_SUBMITTED, _AM_MYMODULE2_STATUS_SUBMITTED); |
|
159
|
|
|
$artStatusSelect->addOption(Constants::STATUS_APPROVED, _AM_MYMODULE2_STATUS_APPROVED); |
|
160
|
|
|
$form->addElement($artStatusSelect, true); |
|
161
|
|
|
// Form File ArtFile |
|
162
|
|
|
$artFile = $this->isNew() ? '' : $this->getVar('art_file'); |
|
163
|
|
|
if ($permissionUpload) { |
|
164
|
|
|
$fileUploadTray = new \XoopsFormElementTray(_AM_MYMODULE2_ARTICLE_FILE, '<br>' ); |
|
165
|
|
|
$fileDirectory = '/uploads/mymodule2/files/articles'; |
|
166
|
|
|
if (!$this->isNew()) { |
|
167
|
|
|
$fileUploadTray->addElement(new \XoopsFormLabel(sprintf(_AM_MYMODULE2_ARTICLE_FILE_UPLOADS, ".{$fileDirectory}/"), $artFile)); |
|
|
|
|
|
|
168
|
|
|
} |
|
169
|
|
|
$maxsize = $helper->getConfig('maxsize_file'); |
|
170
|
|
|
$fileUploadTray->addElement(new \XoopsFormFile( '', 'art_file', $maxsize )); |
|
171
|
|
|
$fileUploadTray->addElement(new \XoopsFormLabel(_AM_MYMODULE2_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . _AM_MYMODULE2_FORM_UPLOAD_SIZE_MB)); |
|
172
|
|
|
$form->addElement($fileUploadTray, ); |
|
173
|
|
|
} else { |
|
174
|
|
|
$form->addElement(new \XoopsFormHidden( 'art_file', $artFile )); |
|
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
// Form Text Date Select ArtCreated |
|
177
|
|
|
$artCreated = $this->isNew() ? 0 : $this->getVar('art_created'); |
|
178
|
|
|
$form->addElement(new \XoopsFormTextDateSelect( _AM_MYMODULE2_ARTICLE_CREATED, 'art_created', '', $artCreated )); |
|
|
|
|
|
|
179
|
|
|
// Form Select User ArtSubmitter |
|
180
|
|
|
$form->addElement(new \XoopsFormSelectUser( _AM_MYMODULE2_ARTICLE_SUBMITTER, 'art_submitter', false, $this->getVar('art_submitter') )); |
|
181
|
|
|
// Permissions |
|
182
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
183
|
|
|
$groupList = $memberHandler->getGroupList(); |
|
|
|
|
|
|
184
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
|
185
|
|
|
$fullList[] = array_keys($groupList); |
|
|
|
|
|
|
186
|
|
|
if (!$this->isNew()) { |
|
187
|
|
|
$groupsIdsApprove = $grouppermHandler->getGroupIds('mymodule2_approve_articles', $this->getVar('art_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
|
|
|
|
|
188
|
|
|
$groupsIdsApprove[] = array_values($groupsIdsApprove); |
|
189
|
|
|
$groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_APPROVE, 'groups_approve_articles[]', $groupsIdsApprove); |
|
190
|
|
|
$groupsIdsSubmit = $grouppermHandler->getGroupIds('mymodule2_submit_articles', $this->getVar('art_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
191
|
|
|
$groupsIdsSubmit[] = array_values($groupsIdsSubmit); |
|
192
|
|
|
$groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_SUBMIT, 'groups_submit_articles[]', $groupsIdsSubmit); |
|
193
|
|
|
$groupsIdsView = $grouppermHandler->getGroupIds('mymodule2_view_articles', $this->getVar('art_id'), $GLOBALS['xoopsModule']->getVar('mid')); |
|
194
|
|
|
$groupsIdsView[] = array_values($groupsIdsView); |
|
195
|
|
|
$groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_VIEW, 'groups_view_articles[]', $groupsIdsView); |
|
196
|
|
|
} else { |
|
197
|
|
|
$groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_APPROVE, 'groups_approve_articles[]', $fullList); |
|
198
|
|
|
$groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_SUBMIT, 'groups_submit_articles[]', $fullList); |
|
199
|
|
|
$groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE2_PERMISSIONS_VIEW, 'groups_view_articles[]', $fullList); |
|
200
|
|
|
} |
|
201
|
|
|
// To Approve |
|
202
|
|
|
$groupsCanApproveCheckbox->addOptionArray($groupList); |
|
203
|
|
|
$form->addElement($groupsCanApproveCheckbox); |
|
204
|
|
|
// To Submit |
|
205
|
|
|
$groupsCanSubmitCheckbox->addOptionArray($groupList); |
|
206
|
|
|
$form->addElement($groupsCanSubmitCheckbox); |
|
207
|
|
|
// To View |
|
208
|
|
|
$groupsCanViewCheckbox->addOptionArray($groupList); |
|
209
|
|
|
$form->addElement($groupsCanViewCheckbox); |
|
210
|
|
|
// To Save |
|
211
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save')); |
|
212
|
|
|
$form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
|
213
|
|
|
return $form; |
|
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Get Values |
|
218
|
|
|
* @param null $keys |
|
|
|
|
|
|
219
|
|
|
* @param null $format |
|
|
|
|
|
|
220
|
|
|
* @param null$maxDepth |
|
221
|
|
|
* @return array |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getValuesArticles($keys = null, $format = null, $maxDepth = null) |
|
224
|
|
|
{ |
|
225
|
|
|
$helper = \XoopsModules\Mymodule2\Helper::getInstance(); |
|
226
|
|
|
$ret = $this->getValues($keys, $format, $maxDepth); |
|
227
|
|
|
$ret['id'] = $this->getVar('art_id'); |
|
228
|
|
|
$categories = $helper->getHandler('categories'); |
|
229
|
|
|
$categoriesObj = $categories->get($this->getVar('art_cat')); |
|
230
|
|
|
$ret['cat'] = $categoriesObj->getVar('cat_name'); |
|
231
|
|
|
$ret['title'] = $this->getVar('art_title'); |
|
232
|
|
|
$ret['descr'] = strip_tags($this->getVar('art_descr')); |
|
|
|
|
|
|
233
|
|
|
$ret['img'] = $this->getVar('art_img'); |
|
234
|
|
|
$ret['status'] = $this->getVar('art_status'); |
|
235
|
|
|
$ret['file'] = $this->getVar('art_file'); |
|
236
|
|
|
$ret['created'] = formatTimeStamp($this->getVar('art_created'), 's'); |
|
237
|
|
|
$ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('art_submitter')); |
|
238
|
|
|
return $ret; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Returns an array representation of the object |
|
243
|
|
|
* |
|
244
|
|
|
* @return array |
|
245
|
|
|
*/ |
|
246
|
|
|
public function toArrayArticles() |
|
247
|
|
|
{ |
|
248
|
|
|
$ret = []; |
|
249
|
|
|
$vars = $this->getVars(); |
|
250
|
|
|
foreach(array_keys($vars) as $var) { |
|
251
|
|
|
$ret[$var] = $this->getVar('"{$var}"'); |
|
252
|
|
|
} |
|
253
|
|
|
return $ret; |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths