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