XoopsModules25x /
suico
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php declare(strict_types=1); |
||
| 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 | * @category Module |
||
| 14 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 15 | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 16 | * @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
||
| 17 | */ |
||
| 18 | |||
| 19 | use Xmf\Module\Helper\Permission; |
||
| 20 | use Xmf\Request; |
||
|
0 ignored issues
–
show
|
|||
| 21 | |||
| 22 | require_once __DIR__ . '/admin_header.php'; |
||
| 23 | xoops_cp_header(); |
||
| 24 | //It recovered the value of argument op in URL$ |
||
| 25 | $op = Request::getString('op', 'list'); |
||
| 26 | $order = Request::getString('order', 'desc'); |
||
| 27 | $sort = Request::getString('sort', ''); |
||
| 28 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 29 | $permHelper = new Permission(); |
||
| 30 | $uploadDir = XOOPS_UPLOAD_PATH . '/suico/images/'; |
||
| 31 | $uploadUrl = XOOPS_UPLOAD_URL . '/suico/images/'; |
||
| 32 | switch ($op) { |
||
| 33 | case 'new': |
||
| 34 | $adminObject->addItemButton(AM_SUICO_IMAGES_LIST, 'images.php', 'list'); |
||
| 35 | $adminObject->displayButton('left'); |
||
| 36 | $imagesObject = $imageHandler->create(); |
||
| 37 | $form = $imagesObject->getForm(); |
||
| 38 | $form->display(); |
||
| 39 | break; |
||
| 40 | case 'save': |
||
| 41 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
| 42 | redirect_header('images.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
| 43 | } |
||
| 44 | if (0 !== Request::getInt('image_id', 0)) { |
||
| 45 | $imagesObject = $imageHandler->get(Request::getInt('image_id', 0)); |
||
| 46 | } else { |
||
| 47 | $imagesObject = $imageHandler->create(); |
||
| 48 | } |
||
| 49 | // Form save fields |
||
| 50 | $imagesObject->setVar('title', Request::getVar('title', '')); |
||
| 51 | $imagesObject->setVar('caption', Request::getVar('caption', '')); |
||
| 52 | $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_created', '', 'POST')); |
||
| 53 | $imagesObject->setVar('date_created', $dateTimeObj->getTimestamp()); |
||
| 54 | $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_updated', '', 'POST')); |
||
| 55 | $imagesObject->setVar('date_updated', $dateTimeObj->getTimestamp()); |
||
| 56 | $imagesObject->setVar('uid_owner', Request::getVar('uid_owner', '')); |
||
| 57 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 58 | $uploadDir = XOOPS_UPLOAD_PATH . '/suico/images/'; |
||
| 59 | $uploader = new \XoopsMediaUploader( |
||
| 60 | $uploadDir, |
||
| 61 | $helper->getConfig('mimetypes'), |
||
| 62 | $helper->getConfig('maxsize'), |
||
| 63 | null, |
||
| 64 | null |
||
| 65 | ); |
||
| 66 | if ($uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0])) { |
||
| 67 | //$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , $_FILES['attachedfile']['name']); |
||
| 68 | //$imgName = str_replace(' ', '', $_POST['filename']).'.'.$extension; |
||
| 69 | $uploader->setPrefix('pic_'); |
||
| 70 | $uploader->fetchMedia(Request::getArray('xoops_upload_file', '', 'POST')[0]); |
||
| 71 | if ($uploader->upload()) { |
||
| 72 | $imagesObject->setVar('filename', $uploader->getSavedFileName()); |
||
| 73 | } else { |
||
| 74 | $errors = $uploader->getErrors(); |
||
| 75 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||
| 76 | } |
||
| 77 | } else { |
||
| 78 | $imagesObject->setVar('filename', Request::getVar('filename', '')); |
||
| 79 | } |
||
| 80 | $imagesObject->setVar('private', ((1 == \Xmf\Request::getInt('private', 0)) ? '1' : '0')); |
||
| 81 | if ($imageHandler->insert($imagesObject)) { |
||
| 82 | redirect_header('images.php?op=list', 2, AM_SUICO_FORMOK); |
||
| 83 | } |
||
| 84 | echo $imagesObject->getHtmlErrors(); |
||
| 85 | $form = $imagesObject->getForm(); |
||
| 86 | $form->display(); |
||
| 87 | break; |
||
| 88 | case 'edit': |
||
| 89 | $adminObject->addItemButton(AM_SUICO_ADD_IMAGES, 'images.php?op=new', 'add'); |
||
| 90 | $adminObject->addItemButton(AM_SUICO_IMAGES_LIST, 'images.php', 'list'); |
||
| 91 | $adminObject->displayButton('left'); |
||
| 92 | $imagesObject = $imageHandler->get(Request::getString('image_id', '')); |
||
| 93 | $form = $imagesObject->getForm(); |
||
| 94 | $form->display(); |
||
| 95 | break; |
||
| 96 | case 'delete': |
||
| 97 | $imagesObject = $imageHandler->get(Request::getString('image_id', '')); |
||
| 98 | if (1 === Request::getInt('ok', 0)) { |
||
| 99 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
| 100 | redirect_header('images.php', 3, implode(', ', $GLOBALS['xoopsSecurity']->getErrors())); |
||
| 101 | } |
||
| 102 | if ($imageHandler->delete($imagesObject)) { |
||
| 103 | redirect_header('images.php', 3, AM_SUICO_FORMDELOK); |
||
| 104 | } else { |
||
| 105 | echo $imagesObject->getHtmlErrors(); |
||
| 106 | } |
||
| 107 | } else { |
||
| 108 | xoops_confirm( |
||
| 109 | [ |
||
| 110 | 'ok' => 1, |
||
| 111 | 'image_id' => Request::getString('image_id', ''), |
||
| 112 | 'op' => 'delete', |
||
| 113 | ], |
||
| 114 | Request::getUrl('REQUEST_URI', '', 'SERVER'), |
||
| 115 | sprintf( |
||
| 116 | AM_SUICO_FORMSUREDEL, |
||
| 117 | $imagesObject->getVar('title') |
||
| 118 | ) |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | break; |
||
| 122 | case 'clone': |
||
| 123 | $id_field = Request::getString('image_id', ''); |
||
| 124 | if ($utility::cloneRecord('suico_images', 'image_id', $id_field)) { |
||
| 125 | redirect_header('images.php', 3, AM_SUICO_CLONED_OK); |
||
| 126 | } else { |
||
| 127 | redirect_header('images.php', 3, AM_SUICO_CLONED_FAILED); |
||
| 128 | } |
||
| 129 | break; |
||
| 130 | case 'list': |
||
| 131 | default: |
||
| 132 | $adminObject->addItemButton(AM_SUICO_ADD_IMAGES, 'images.php?op=new', 'add'); |
||
| 133 | $adminObject->displayButton('left'); |
||
| 134 | $start = Request::getInt('start', 0); |
||
| 135 | $imagesPaginationLimit = $helper->getConfig('userpager'); |
||
| 136 | $criteria = new CriteriaCompo(); |
||
| 137 | $criteria->setSort('image_id ASC, title'); |
||
| 138 | $criteria->setOrder('ASC'); |
||
| 139 | $criteria->setLimit($imagesPaginationLimit); |
||
| 140 | $criteria->setStart($start); |
||
| 141 | $imagesTempRows = $imageHandler->getCount(); |
||
| 142 | $imagesTempArray = $imageHandler->getAll($criteria); |
||
| 143 | /* |
||
| 144 | // |
||
| 145 | // |
||
| 146 | <th class='center width5'>".AM_SUICO_FORM_ACTION."</th> |
||
| 147 | // </tr>"; |
||
| 148 | // $class = "odd"; |
||
| 149 | */ |
||
| 150 | // Display Page Navigation |
||
| 151 | if ($imagesTempRows > $imagesPaginationLimit) { |
||
| 152 | xoops_load('XoopsPageNav'); |
||
| 153 | $pagenav = new \XoopsPageNav( |
||
| 154 | $imagesTempRows, |
||
| 155 | $imagesPaginationLimit, |
||
| 156 | $start, |
||
| 157 | 'start', |
||
| 158 | 'op=list' . '&sort=' . $sort . '&order=' . $order . '' |
||
| 159 | ); |
||
| 160 | $GLOBALS['xoopsTpl']->assign('pagenav', null === $pagenav ? $pagenav->renderNav() : ''); |
||
| 161 | } |
||
| 162 | $GLOBALS['xoopsTpl']->assign('imagesRows', $imagesTempRows); |
||
| 163 | $imagesArray = []; |
||
| 164 | // $fields = explode('|', image_id:int:11::NOT NULL::primary:image_id|title:varchar:255::NOT NULL:::title|date_created:date:0::NOT NULL:::date_created|date_updated:date:0::NOT NULL:::date_updated|uid_owner:varchar:50::NOT NULL:::uid_owner|filename:text:0::NOT NULL:::filename|private:varchar:1::NOT NULL:::private); |
||
| 165 | // $fieldsCount = count($fields); |
||
| 166 | $criteria = new CriteriaCompo(); |
||
| 167 | //$criteria->setOrder('DESC'); |
||
| 168 | $criteria->setSort($sort); |
||
| 169 | $criteria->setOrder($order); |
||
| 170 | $criteria->setLimit($imagesPaginationLimit); |
||
| 171 | $criteria->setStart($start); |
||
| 172 | $imagesCount = $imageHandler->getCount($criteria); |
||
| 173 | $imagesTempArray = $imageHandler->getAll($criteria); |
||
| 174 | // for ($i = 0; $i < $fieldsCount; ++$i) { |
||
| 175 | if ($imagesCount > 0) { |
||
| 176 | foreach (array_keys($imagesTempArray) as $i) { |
||
| 177 | // $field = explode(':', $fields[$i]); |
||
| 178 | $GLOBALS['xoopsTpl']->assign( |
||
| 179 | 'selectorimage_id', |
||
| 180 | AM_SUICO_IMAGES_IMAGE_ID |
||
| 181 | ); |
||
| 182 | $imagesArray['image_id'] = $imagesTempArray[$i]->getVar('image_id'); |
||
| 183 | $GLOBALS['xoopsTpl']->assign('selectortitle', AM_SUICO_IMAGES_TITLE); |
||
| 184 | $imagesArray['title'] = $imagesTempArray[$i]->getVar('title'); |
||
| 185 | $GLOBALS['xoopsTpl']->assign('selectorcaption', AM_SUICO_IMAGES_CAPTION); |
||
| 186 | $imagesArray['caption'] = $imagesTempArray[$i]->getVar('caption'); |
||
| 187 | $GLOBALS['xoopsTpl']->assign('selectordate_created', AM_SUICO_IMAGES_DATE_CREATED); |
||
| 188 | $imagesArray['date_created'] = formatTimestamp($imagesTempArray[$i]->getVar('date_created'), 's'); |
||
| 189 | $GLOBALS['xoopsTpl']->assign('selectordate_updated', AM_SUICO_IMAGES_DATE_UPDATED); |
||
| 190 | $imagesArray['date_updated'] = formatTimestamp($imagesTempArray[$i]->getVar('date_updated'), 's'); |
||
| 191 | $GLOBALS['xoopsTpl']->assign('selectoruid_owner', AM_SUICO_IMAGES_UID_OWNER); |
||
| 192 | $imagesArray['uid_owner'] = strip_tags( |
||
| 193 | XoopsUser::getUnameFromId($imagesTempArray[$i]->getVar('uid_owner')) |
||
| 194 | ); |
||
| 195 | $GLOBALS['xoopsTpl']->assign('selectorurl', AM_SUICO_IMAGES_URL); |
||
| 196 | $imagesArray['filename'] = "<img src='" . $uploadUrl . $imagesTempArray[$i]->getVar('filename') . "' name='" . 'name' . "' id=" . 'id' . " alt='' style='max-width:100px'>"; |
||
| 197 | $GLOBALS['xoopsTpl']->assign('selectorprivate', AM_SUICO_IMAGES_PRIVATE); |
||
| 198 | $imagesArray['private'] = $imagesTempArray[$i]->getVar('private'); |
||
| 199 | $imagesArray['edit_delete'] = "<a href='images.php?op=edit&image_id=" . $i . "'><img src=" . $pathIcon16 . "/edit.png alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
||
| 200 | <a href='images.php?op=delete&image_id=" . $i . "'><img src=" . $pathIcon16 . "/delete.png alt='" . _DELETE . "' title='" . _DELETE . "'></a> |
||
| 201 | <a href='images.php?op=clone&image_id=" . $i . "'><img src=" . $pathIcon16 . "/editcopy.png alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
||
| 202 | $GLOBALS['xoopsTpl']->append_by_ref('imagesArrays', $imagesArray); |
||
| 203 | unset($imagesArray); |
||
| 204 | } |
||
| 205 | unset($imagesTempArray); |
||
| 206 | // Display Navigation |
||
| 207 | if ($imagesCount > $imagesPaginationLimit) { |
||
| 208 | xoops_load('XoopsPageNav'); |
||
| 209 | $pagenav = new \XoopsPageNav( |
||
| 210 | $imagesCount, |
||
| 211 | $imagesPaginationLimit, |
||
| 212 | $start, |
||
| 213 | 'start', |
||
| 214 | 'op=list' . '&sort=' . $sort . '&order=' . $order . '' |
||
| 215 | ); |
||
| 216 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
||
| 217 | } |
||
| 218 | echo $GLOBALS['xoopsTpl']->fetch( |
||
| 219 | XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['xoopsModule']->getVar( |
||
| 220 | 'dirname' |
||
| 221 | ) . '/templates/admin/suico_admin_images.tpl' |
||
| 222 | ); |
||
| 223 | } |
||
| 224 | break; |
||
| 225 | } |
||
| 226 | require_once __DIR__ . '/admin_footer.php'; |
||
| 227 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: