mambax7 /
publisher
| 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 | use Xmf\Request; |
||
| 23 | use XoopsModules\Publisher; |
||
| 24 | use XoopsModules\Publisher\Constants; |
||
| 25 | |||
| 26 | require_once __DIR__ . '/header.php'; |
||
| 27 | $helper->loadLanguage('admin'); |
||
| 28 | |||
| 29 | // Get the total number of categories |
||
| 30 | $categoriesArray = $helper->getHandler('Category')->getCategoriesForSubmit(); |
||
| 31 | |||
| 32 | if (!$categoriesArray) { |
||
| 33 | redirect_header('index.php', 1, _MD_PUBLISHER_NEED_CATEGORY_ITEM); |
||
| 34 | // exit(); |
||
| 35 | } |
||
| 36 | |||
| 37 | $groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 38 | /* @var $grouppermHandler \XoopsModules\Publisher\GroupPermHandler */ |
||
| 39 | $grouppermHandler = \XoopsModules\Publisher\Helper::getInstance()->getHandler('GroupPerm'); //xoops_getModuleHandler('groupperm'); |
||
| 40 | $moduleId = $helper->getModule()->getVar('mid'); |
||
| 41 | |||
| 42 | $itemId = Request::getInt('itemid', Request::getInt('itemid', 0, 'POST'), 'GET'); |
||
| 43 | if (0 != $itemId) { |
||
| 44 | // We are editing or deleting an article |
||
| 45 | /* @var $itemObj Publisher\Item */ |
||
| 46 | $itemObj = $helper->getHandler('Item')->get($itemId); |
||
| 47 | if (!(Publisher\Utility::userIsAdmin() || Publisher\Utility::userIsAuthor($itemObj) || Publisher\Utility::userIsModerator($itemObj))) { |
||
| 48 | redirect_header('index.php', 1, _NOPERM); |
||
| 49 | // exit(); |
||
| 50 | } |
||
| 51 | if (!Publisher\Utility::userIsAdmin() || !Publisher\Utility::userIsModerator($itemObj)) { |
||
| 52 | if ('del' === Request::getString('op', '', 'GET') && !$helper->getConfig('perm_delete')) { |
||
| 53 | redirect_header('index.php', 1, _NOPERM); |
||
| 54 | // exit(); |
||
| 55 | } elseif (!$helper->getConfig('perm_edit')) { |
||
| 56 | redirect_header('index.php', 1, _NOPERM); |
||
| 57 | // exit(); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | /* @var $categoryObj Publisher\Category */ |
||
| 61 | $categoryObj = $itemObj->getCategory(); |
||
| 62 | } else { |
||
| 63 | // we are submitting a new article |
||
| 64 | // if the user is not admin AND we don't allow user submission, exit |
||
| 65 | if (!(Publisher\Utility::userIsAdmin() || (1 == $helper->getConfig('perm_submit') && (is_object($GLOBALS['xoopsUser']) || (1 == $helper->getConfig('perm_anon_submit')))))) { |
||
| 66 | redirect_header('index.php', 1, _NOPERM); |
||
| 67 | // exit(); |
||
| 68 | } |
||
| 69 | /* @var $itemObj Publisher\Item */ |
||
| 70 | $itemObj = $helper->getHandler('Item')->create(); |
||
| 71 | /* @var $categoryObj Publisher\Category */ |
||
| 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 = Publisher\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)) { |
||
| 131 | redirect_header('index.php', 1, _MD_PUBLISHER_SUBMIT_ERROR); |
||
| 132 | // exit(); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | //unset($element); |
||
| 136 | |||
| 137 | $itemUploadFile = Request::getArray('item_upload_file', [], 'FILES'); |
||
| 138 | |||
| 139 | //stripcslashes |
||
| 140 | switch ($op) { |
||
| 141 | case 'del': |
||
| 142 | $confirm = Request::getInt('confirm', '', 'POST'); |
||
| 143 | |||
| 144 | if ($confirm) { |
||
| 145 | if (!$helper->getHandler('Item')->delete($itemObj)) { |
||
| 146 | redirect_header('index.php', 2, _AM_PUBLISHER_ITEM_DELETE_ERROR . Publisher\Utility::formatErrors($itemObj->getErrors())); |
||
| 147 | // exit(); |
||
| 148 | } |
||
| 149 | redirect_header('index.php', 2, sprintf(_AM_PUBLISHER_ITEMISDELETED, $itemObj->getTitle())); |
||
| 150 | // exit(); |
||
| 151 | } else { |
||
| 152 | require_once $GLOBALS['xoops']->path('header.php'); |
||
| 153 | 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); |
||
| 154 | require_once $GLOBALS['xoops']->path('footer.php'); |
||
| 155 | } |
||
| 156 | exit(); |
||
| 157 | break; |
||
| 158 | case 'preview': |
||
| 159 | // Putting the values about the ITEM in the ITEM object |
||
| 160 | $itemObj->setVarsFromRequest(); |
||
| 161 | |||
| 162 | $GLOBALS['xoopsOption']['template_main'] = 'publisher_submit.tpl'; |
||
| 163 | require_once $GLOBALS['xoops']->path('header.php'); |
||
| 164 | $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 165 | $xoTheme->addScript(PUBLISHER_URL . '/assets/js/publisher.js'); |
||
| 166 | require_once PUBLISHER_ROOT_PATH . '/footer.php'; |
||
| 167 | |||
| 168 | $categoryObj = $helper->getHandler('Category')->get(Request::getInt('categoryid', 0, 'POST')); |
||
| 169 | |||
| 170 | $item = $itemObj->toArraySimple(); |
||
| 171 | $item['summary'] = $itemObj->body(); |
||
| 172 | $item['categoryPath'] = $categoryObj->getCategoryPath(true); |
||
| 173 | $item['who_when'] = $itemObj->getWhoAndWhen(); |
||
| 174 | $item['comments'] = -1; |
||
| 175 | $xoopsTpl->assign('item', $item); |
||
| 176 | |||
| 177 | $xoopsTpl->assign('op', 'preview'); |
||
| 178 | $xoopsTpl->assign('module_home', Publisher\Utility::moduleHome()); |
||
| 179 | |||
| 180 | if ($itemId) { |
||
| 181 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_EDIT_ARTICLE); |
||
| 182 | $xoopsTpl->assign('langIntroTitle', _MD_PUBLISHER_EDIT_ARTICLE); |
||
| 183 | $xoopsTpl->assign('langIntroText', ''); |
||
| 184 | } else { |
||
| 185 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_SUB_SNEWNAME); |
||
| 186 | $xoopsTpl->assign('langIntroTitle', sprintf(_MD_PUBLISHER_SUB_SNEWNAME, ucwords($helper->getModule()->name()))); |
||
| 187 | $xoopsTpl->assign('langIntroText', $helper->getConfig('submit_intro_msg')); |
||
| 188 | } |
||
| 189 | if ($tokenError) { |
||
| 190 | $xoopsTpl->assign('langIntroText', _CO_PUBLISHER_BAD_TOKEN); |
||
| 191 | } |
||
| 192 | |||
| 193 | $sform = $itemObj->getForm($formtitle, true); |
||
| 194 | $sform->assign($xoopsTpl); |
||
| 195 | require_once $GLOBALS['xoops']->path('footer.php'); |
||
| 196 | exit(); |
||
| 197 | |||
| 198 | break; |
||
| 199 | |||
| 200 | case 'post': |
||
| 201 | // Putting the values about the ITEM in the ITEM object |
||
| 202 | // print_r($itemObj->getVars()); |
||
| 203 | $itemObj->setVarsFromRequest(); |
||
| 204 | //print_r($_POST); |
||
| 205 | //print_r($itemObj->getVars()); |
||
| 206 | //exit; |
||
| 207 | |||
| 208 | // Storing the item object in the database |
||
| 209 | if (!$itemObj->store()) { |
||
| 210 | redirect_header('javascript:history.go(-1)', 2, _MD_PUBLISHER_SUBMIT_ERROR); |
||
| 211 | // exit(); |
||
| 212 | } |
||
| 213 | |||
| 214 | // attach file if any |
||
| 215 | if ($itemUploadFile && '' != $itemUploadFile['name']) { |
||
|
0 ignored issues
–
show
|
|||
| 216 | $fileUploadResult = Publisher\Utility::uploadFile(false, true, $itemObj); |
||
| 217 | if (true !== $fileUploadResult) { |
||
| 218 | redirect_header('javascript:history.go(-1)', 3, $fileUploadResult); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | |||
| 222 | // if autoapprove_submitted. This does not apply if we are editing an article |
||
| 223 | if (!$itemId) { |
||
| 224 | if (Constants::PUBLISHER_STATUS_PUBLISHED == $itemObj->getVar('status') /*$helper->getConfig('perm_autoapprove'] == 1*/) { |
||
| 225 | // We do not not subscribe user to notification on publish since we publish it right away |
||
| 226 | |||
| 227 | // Send notifications |
||
| 228 | $itemObj->sendNotifications([Constants::PUBLISHER_NOTIFY_ITEM_PUBLISHED]); |
||
| 229 | |||
| 230 | $redirect_msg = _MD_PUBLISHER_ITEM_RECEIVED_AND_PUBLISHED; |
||
| 231 | redirect_header($itemObj->getItemUrl(), 2, $redirect_msg); |
||
| 232 | } else { |
||
| 233 | // Subscribe the user to On Published notification, if requested |
||
| 234 | if ($itemObj->getVar('notifypub')) { |
||
| 235 | require_once $GLOBALS['xoops']->path('include/notification_constants.php'); |
||
| 236 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||
| 237 | $notificationHandler = xoops_getHandler('notification'); |
||
| 238 | $notificationHandler->subscribe('item', $itemObj->itemid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||
| 239 | } |
||
| 240 | // Send notifications |
||
| 241 | $itemObj->sendNotifications([Constants::PUBLISHER_NOTIFY_ITEM_SUBMITTED]); |
||
| 242 | |||
| 243 | $redirect_msg = _MD_PUBLISHER_ITEM_RECEIVED_NEED_APPROVAL; |
||
| 244 | } |
||
| 245 | } else { |
||
| 246 | $redirect_msg = _MD_PUBLISHER_ITEMMODIFIED; |
||
| 247 | redirect_header($itemObj->getItemUrl(), 2, $redirect_msg); |
||
| 248 | } |
||
| 249 | redirect_header('index.php', 2, $redirect_msg); |
||
| 250 | // exit(); |
||
| 251 | |||
| 252 | break; |
||
| 253 | |||
| 254 | case 'add': |
||
| 255 | default: |
||
| 256 | $GLOBALS['xoopsOption']['template_main'] = 'publisher_submit.tpl'; |
||
| 257 | require_once $GLOBALS['xoops']->path('header.php'); |
||
| 258 | $GLOBALS['xoTheme']->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js'); |
||
| 259 | $GLOBALS['xoTheme']->addScript(PUBLISHER_URL . '/assets/js/publisher.js'); |
||
| 260 | require_once PUBLISHER_ROOT_PATH . '/footer.php'; |
||
| 261 | |||
| 262 | //mb $itemObj->setVarsFromRequest(); |
||
| 263 | |||
| 264 | $xoopsTpl->assign('module_home', Publisher\Utility::moduleHome()); |
||
| 265 | if ('clone' === Request::getString('op', '', 'GET')) { |
||
| 266 | $xoopsTpl->assign('categoryPath', _CO_PUBLISHER_CLONE); |
||
| 267 | $xoopsTpl->assign('langIntroTitle', _CO_PUBLISHER_CLONE); |
||
| 268 | } elseif ($itemId) { |
||
| 269 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_EDIT_ARTICLE); |
||
| 270 | $xoopsTpl->assign('langIntroTitle', _MD_PUBLISHER_EDIT_ARTICLE); |
||
| 271 | $xoopsTpl->assign('langIntroText', ''); |
||
| 272 | } else { |
||
| 273 | $xoopsTpl->assign('categoryPath', _MD_PUBLISHER_SUB_SNEWNAME); |
||
| 274 | $xoopsTpl->assign('langIntroTitle', sprintf(_MD_PUBLISHER_SUB_SNEWNAME, ucwords($helper->getModule()->name()))); |
||
| 275 | $xoopsTpl->assign('langIntroText', $helper->getConfig('submit_intro_msg')); |
||
| 276 | } |
||
| 277 | $sform = $itemObj->getForm($formtitle, true); |
||
| 278 | $sform->assign($xoopsTpl); |
||
| 279 | |||
| 280 | require_once $GLOBALS['xoops']->path('footer.php'); |
||
| 281 | break; |
||
| 282 | } |
||
| 283 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.