These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||
14 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||
15 | * @package Publisher |
||
16 | * @subpackage Action |
||
17 | * @since 1.0 |
||
18 | * @author trabis <[email protected]> |
||
19 | * @author The SmartFactory <www.smartfactory.ca> |
||
20 | */ |
||
21 | |||
22 | include_once __DIR__ . '/header.php'; |
||
23 | xoops_loadLanguage('admin', PUBLISHER_DIRNAME); |
||
24 | |||
25 | // Get the total number of categories |
||
26 | $categoriesArray = $publisher->getHandler('category')->getCategoriesForSubmit(); |
||
27 | |||
28 | if (!$categoriesArray) { |
||
29 | redirect_header('index.php', 1, _MD_PUBLISHER_NEED_CATEGORY_ITEM); |
||
30 | // exit(); |
||
31 | } |
||
32 | |||
33 | $groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
34 | $gpermHandler = xoops_getModuleHandler('groupperm'); |
||
35 | $moduleId = $publisher->getModule()->getVar('mid'); |
||
36 | |||
37 | $itemId = XoopsRequest::getInt('itemid', XoopsRequest::getInt('itemid', 0, 'POST'), 'GET'); |
||
38 | if ($itemId != 0) { |
||
39 | // We are editing or deleting an article |
||
40 | $itemObj = $publisher->getHandler('item')->get($itemId); |
||
41 | if (!(publisherUserIsAdmin() || publisherUserIsAuthor($itemObj) || publisherUserIsModerator($itemObj))) { |
||
42 | redirect_header('index.php', 1, _NOPERM); |
||
43 | // exit(); |
||
44 | } |
||
45 | if (!publisherUserIsAdmin() || !publisherUserIsModerator($itemObj)) { |
||
46 | if ('del' === XoopsRequest::getString('op', '', 'GET') && !$publisher->getConfig('perm_delete')) { |
||
47 | redirect_header('index.php', 1, _NOPERM); |
||
48 | // exit(); |
||
49 | } elseif (!$publisher->getConfig('perm_edit')) { |
||
50 | redirect_header('index.php', 1, _NOPERM); |
||
51 | // exit(); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $categoryObj = $itemObj->getCategory(); |
||
56 | } else { |
||
57 | // we are submitting a new article |
||
58 | // if the user is not admin AND we don't allow user submission, exit |
||
59 | View Code Duplication | if (!(publisherUserIsAdmin() || ($publisher->getConfig('perm_submit') == 1 && (is_object($GLOBALS['xoopsUser']) || ($publisher->getConfig('perm_anon_submit') == 1))))) { |
|
60 | redirect_header('index.php', 1, _NOPERM); |
||
61 | // exit(); |
||
62 | } |
||
63 | $itemObj = $publisher->getHandler('item')->create(); |
||
64 | $categoryObj = $publisher->getHandler('category')->create(); |
||
65 | } |
||
66 | |||
67 | if ('clone' === XoopsRequest::getString('op', '', 'GET')) { |
||
68 | $formtitle = _MD_PUBLISHER_SUB_CLONE; |
||
69 | $itemObj->setNew(); |
||
70 | $itemObj->setVar('itemid', 0); |
||
71 | } else { |
||
72 | $formtitle = _MD_PUBLISHER_SUB_SMNAME; |
||
73 | } |
||
74 | |||
75 | //$op = ''; |
||
76 | $op = 'add'; |
||
77 | if (XoopsRequest::getString('additem', '', 'POST')) { |
||
78 | $op = 'post'; |
||
79 | } elseif (XoopsRequest::getString('preview', '', 'POST')) { |
||
80 | $op = 'preview'; |
||
81 | } |
||
82 | |||
83 | $op = XoopsRequest::getString('op', XoopsRequest::getString('op', $op, 'POST'), 'GET'); |
||
84 | |||
85 | $allowedEditors = publisherGetEditors($gpermHandler->getItemIds('editors', $groups, $moduleId)); |
||
86 | $formView = $gpermHandler->getItemIds('form_view', $groups, $moduleId); |
||
87 | |||
88 | // This code makes sure permissions are not manipulated |
||
89 | $elements = array( |
||
90 | 'summary', |
||
91 | 'available_page_wrap', |
||
92 | 'item_tag', |
||
93 | 'image_item', |
||
94 | 'item_upload_file', |
||
95 | 'uid', |
||
96 | 'datesub', |
||
97 | 'status', |
||
98 | 'item_short_url', |
||
99 | 'item_meta_keywords', |
||
100 | 'item_meta_description', |
||
101 | 'weight', |
||
102 | 'allowcomments', |
||
103 | 'dohtml', |
||
104 | 'dosmiley', |
||
105 | 'doxcode', |
||
106 | 'doimage', |
||
107 | 'dolinebreak', |
||
108 | 'notify', |
||
109 | 'subtitle', |
||
110 | 'author_alias'); |
||
111 | foreach ($elements as $element) { |
||
112 | if (XoopsRequest::getString('element', '', 'POST') && !in_array(constant('PublisherConstants::PUBLISHER_' . strtoupper($element)), $formView)) { |
||
113 | redirect_header('index.php', 1, _MD_PUBLISHER_SUBMIT_ERROR); |
||
114 | // exit(); |
||
115 | } |
||
116 | } |
||
117 | //unset($element); |
||
118 | |||
119 | $itemUploadFile = XoopsRequest::getArray('item_upload_file', array(), 'FILES'); |
||
120 | |||
121 | //stripcslashes |
||
122 | switch ($op) { |
||
123 | View Code Duplication | case 'del': |
|
124 | $confirm = XoopsRequest::getInt('confirm', '', 'POST'); |
||
125 | |||
126 | if ($confirm) { |
||
127 | if (!$publisher->getHandler('item')->delete($itemObj)) { |
||
128 | redirect_header('index.php', 2, _AM_PUBLISHER_ITEM_DELETE_ERROR . publisherFormatErrors($itemObj->getErrors())); |
||
129 | // exit(); |
||
130 | } |
||
131 | redirect_header('index.php', 2, sprintf(_AM_PUBLISHER_ITEMISDELETED, $itemObj->getTitle())); |
||
132 | // exit(); |
||
133 | } else { |
||
134 | include_once $GLOBALS['xoops']->path('header.php'); |
||
135 | xoops_confirm(array('op' => 'del', 'itemid' => $itemObj->itemid(), 'confirm' => 1, 'name' => $itemObj->getTitle()), 'submit.php', _AM_PUBLISHER_DELETETHISITEM . " <br>'" . $itemObj->getTitle() . "'. <br> <br>", _AM_PUBLISHER_DELETE); |
||
136 | include_once $GLOBALS['xoops']->path('footer.php'); |
||
137 | } |
||
138 | exit(); |
||
139 | break; |
||
140 | case 'preview': |
||
141 | // Putting the values about the ITEM in the ITEM object |
||
142 | $itemObj->setVarsFromRequest(); |
||
143 | |||
144 | $xoopsOption['template_main'] = 'publisher_submit.tpl'; |
||
145 | include_once $GLOBALS['xoops']->path('header.php'); |
||
146 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
147 | $xoTheme->addScript(PUBLISHER_URL . '/assets/js/publisher.js'); |
||
148 | include_once PUBLISHER_ROOT_PATH . '/footer.php'; |
||
149 | |||
150 | $categoryObj = $publisher->getHandler('category')->get(XoopsRequest::getInt('categoryid', 0, 'POST')); |
||
151 | |||
152 | $item = $itemObj->toArraySimple(); |
||
153 | $item['summary'] = $itemObj->body(); |
||
154 | $item['categoryPath'] = $categoryObj->getCategoryPath(true); |
||
155 | $item['who_when'] = $itemObj->getWhoAndWhen(); |
||
156 | $item['comments'] = -1; |
||
157 | $xoopsTpl->assign('item', $item); |
||
158 | |||
159 | $xoopsTpl->assign('op', 'preview'); |
||
160 | $xoopsTpl->assign('module_home', publisherModuleHome()); |
||
161 | |||
162 | if ($itemId) { |
||
163 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_EDIT_ARTICLE); |
||
164 | $xoopsTpl->assign('langIntroTitle', _MD_PUBLISHER_EDIT_ARTICLE); |
||
165 | $xoopsTpl->assign('langIntroText', ''); |
||
166 | View Code Duplication | } else { |
|
0 ignored issues
–
show
|
|||
167 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_SUB_SNEWNAME); |
||
168 | $xoopsTpl->assign('langIntroTitle', sprintf(_MD_PUBLISHER_SUB_SNEWNAME, ucwords($publisher->getModule()->name()))); |
||
169 | $xoopsTpl->assign('langIntroText', $publisher->getConfig('submit_intro_msg')); |
||
170 | } |
||
171 | |||
172 | $sform = $itemObj->getForm($formtitle, true); |
||
173 | $sform->assign($xoopsTpl); |
||
174 | include_once $GLOBALS['xoops']->path('footer.php'); |
||
175 | exit(); |
||
176 | |||
177 | break; |
||
178 | |||
179 | case 'post': |
||
180 | // Putting the values about the ITEM in the ITEM object |
||
181 | // print_r($itemObj->getVars()); |
||
182 | $itemObj->setVarsFromRequest(); |
||
183 | //print_r($_POST); |
||
184 | //print_r($itemObj->getVars()); |
||
185 | //exit; |
||
186 | |||
187 | // Storing the item object in the database |
||
188 | if (!$itemObj->store()) { |
||
189 | redirect_header('javascript:history.go(-1)', 2, _MD_PUBLISHER_SUBMIT_ERROR); |
||
190 | // exit(); |
||
191 | } |
||
192 | |||
193 | // attach file if any |
||
194 | if ($itemUploadFile && $itemUploadFile['name'] != '') { |
||
195 | $fileUploadResult = publisherUploadFile(false, true, $itemObj); |
||
196 | if ($fileUploadResult !== true) { |
||
197 | redirect_header('javascript:history.go(-1)', 3, $fileUploadResult); |
||
198 | exit; |
||
199 | } |
||
200 | } |
||
201 | |||
202 | // if autoapprove_submitted. This does not apply if we are editing an article |
||
203 | if (!$itemId) { |
||
204 | if ($itemObj->getVar('status') == PublisherConstants::PUBLISHER_STATUS_PUBLISHED /*$publisher->getConfig('perm_autoapprove'] == 1*/) { |
||
205 | // We do not not subscribe user to notification on publish since we publish it right away |
||
206 | |||
207 | // Send notifications |
||
208 | $itemObj->sendNotifications(array(PublisherConstants::PUBLISHER_NOTIFY_ITEM_PUBLISHED)); |
||
209 | |||
210 | $redirect_msg = _MD_PUBLISHER_ITEM_RECEIVED_AND_PUBLISHED; |
||
211 | redirect_header($itemObj->getItemUrl(), 2, $redirect_msg); |
||
212 | } else { |
||
213 | // Subscribe the user to On Published notification, if requested |
||
214 | if ($itemObj->getVar('notifypub')) { |
||
215 | include_once $GLOBALS['xoops']->path('include/notification_constants.php'); |
||
216 | $notificationHandler = xoops_getHandler('notification'); |
||
217 | $notificationHandler->subscribe('item', $itemObj->itemid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||
218 | } |
||
219 | // Send notifications |
||
220 | $itemObj->sendNotifications(array(PublisherConstants::PUBLISHER_NOTIFY_ITEM_SUBMITTED)); |
||
221 | |||
222 | $redirect_msg = _MD_PUBLISHER_ITEM_RECEIVED_NEED_APPROVAL; |
||
223 | } |
||
224 | } else { |
||
225 | $redirect_msg = _MD_PUBLISHER_ITEMMODIFIED; |
||
226 | redirect_header($itemObj->getItemUrl(), 2, $redirect_msg); |
||
227 | } |
||
228 | redirect_header('index.php', 2, $redirect_msg); |
||
229 | // exit(); |
||
230 | |||
231 | break; |
||
232 | |||
233 | case 'add': |
||
234 | default: |
||
235 | $xoopsOption['template_main'] = 'publisher_submit.tpl'; |
||
236 | include_once $GLOBALS['xoops']->path('header.php'); |
||
237 | $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
238 | $GLOBALS['xoTheme']->addScript(PUBLISHER_URL . '/assets/js/publisher.js'); |
||
239 | include_once PUBLISHER_ROOT_PATH . '/footer.php'; |
||
240 | |||
241 | //mb $itemObj->setVarsFromRequest(); |
||
242 | |||
243 | $xoopsTpl->assign('module_home', publisherModuleHome()); |
||
244 | if ('clone' === XoopsRequest::getString('op', '', 'GET')) { |
||
245 | $xoopsTpl->assign('categoryPath', _CO_PUBLISHER_CLONE); |
||
246 | $xoopsTpl->assign('langIntroTitle', _CO_PUBLISHER_CLONE); |
||
247 | } elseif ($itemId) { |
||
248 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_EDIT_ARTICLE); |
||
249 | $xoopsTpl->assign('langIntroTitle', _MD_PUBLISHER_EDIT_ARTICLE); |
||
250 | $xoopsTpl->assign('langIntroText', ''); |
||
251 | View Code Duplication | } else { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
252 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_SUB_SNEWNAME); |
||
253 | $xoopsTpl->assign('langIntroTitle', sprintf(_MD_PUBLISHER_SUB_SNEWNAME, ucwords($publisher->getModule()->name()))); |
||
254 | $xoopsTpl->assign('langIntroText', $publisher->getConfig('submit_intro_msg')); |
||
255 | } |
||
256 | $sform = $itemObj->getForm($formtitle, true); |
||
257 | $sform->assign($xoopsTpl); |
||
258 | |||
259 | include_once $GLOBALS['xoops']->path('footer.php'); |
||
260 | break; |
||
261 | } |
||
262 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.