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; |
||
| 24 | use XoopsModules\Publisher\Utility; |
||
| 25 | |||
| 26 | require_once __DIR__ . '/header.php'; |
||
| 27 | |||
| 28 | $helper->loadLanguage('admin'); |
||
| 29 | //xoops_loadLanguage('admin', PUBLISHER_DIRNAME); |
||
| 30 | |||
| 31 | $op = Request::getString('op', Request::getString('op', '', 'GET'), 'POST'); |
||
| 32 | $fileid = Request::getInt('fileid', Request::getInt('fileid', 0, 'GET'), 'POST'); |
||
| 33 | |||
| 34 | if (0 == $fileid) { |
||
| 35 | redirect_header('index.php', 2, _MD_PUBLISHER_NOITEMSELECTED); |
||
| 36 | } |
||
| 37 | |||
| 38 | $fileObj = $helper->getHandler('File')->get($fileid); |
||
| 39 | |||
| 40 | // if the selected item was not found, exit |
||
| 41 | if (!$fileObj) { |
||
| 42 | redirect_header('index.php', 1, _NOPERM); |
||
| 43 | } |
||
| 44 | |||
| 45 | $itemObj = $helper->getHandler('Item')->get($fileObj->getVar('itemid')); |
||
| 46 | |||
| 47 | // if the user does not have permission to modify this file, exit |
||
| 48 | if (!(Utility::userIsAdmin() || Utility::userIsModerator($itemObj) || (is_object($GLOBALS['xoopsUser']) && $fileObj->getVar('uid') == $GLOBALS['xoopsUser']->getVar('uid')))) { |
||
| 49 | redirect_header('index.php', 1, _NOPERM); |
||
| 50 | } |
||
| 51 | |||
| 52 | /* -- Available operations -- */ |
||
| 53 | switch ($op) { |
||
| 54 | case 'default': |
||
| 55 | case 'mod': |
||
| 56 | require_once $GLOBALS['xoops']->path('header.php'); |
||
| 57 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||
| 58 | |||
| 59 | // FILES UPLOAD FORM |
||
| 60 | $uploadForm = $fileObj->getForm(); |
||
| 61 | $uploadForm->display(); |
||
| 62 | break; |
||
| 63 | case 'modify': |
||
| 64 | $fileid = Request::getInt('fileid', 0, 'POST'); |
||
| 65 | |||
| 66 | // Creating the file object |
||
| 67 | if (0 != $fileid) { |
||
| 68 | $fileObj = $helper->getHandler('File')->get($fileid); |
||
| 69 | } else { |
||
| 70 | redirect_header('index.php', 1, _NOPERM); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Putting the values in the file object |
||
| 74 | $fileObj->setVar('name', Request::getString('name')); |
||
| 75 | $fileObj->setVar('description', Request::getString('description')); |
||
| 76 | $fileObj->setVar('status', Request::getInt('file_status', 0, 'GET')); |
||
| 77 | |||
| 78 | // attach file if any |
||
| 79 | |||
| 80 | if ('' != Request::getString('item_upload_file', '', 'FILES')) { |
||
| 81 | $oldfile = $fileObj->getFilePath(); |
||
| 82 | |||
| 83 | // Get available mimetypes for file uploading |
||
| 84 | $allowedMimetypes = $helper->getHandler('Mimetype')->getArrayByType(); |
||
| 85 | // TODO : display the available mimetypes to the user |
||
| 86 | $errors = []; |
||
| 87 | |||
| 88 | // if ($helper->getConfig('perm_upload') && is_uploaded_file(Request::getArray('item_upload_file', array(), 'FILES')['tmp_name'])) { |
||
| 89 | $temp = Request::getArray('item_upload_file', [], 'FILES'); |
||
| 90 | if ($helper->getConfig('perm_upload') && is_uploaded_file($temp['tmp_name'])) { |
||
| 91 | if ($fileObj->checkUpload('item_upload_file', $allowedMimetypes, $errors)) { |
||
| 92 | if ($fileObj->storeUpload('item_upload_file', $allowedMimetypes, $errors)) { |
||
| 93 | unlink($oldfile); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if (!$helper->getHandler('File')->insert($fileObj)) { |
||
| 100 | redirect_header('item.php?itemid=' . $fileObj->itemid(), 3, _AM_PUBLISHER_FILE_EDITING_ERROR . Utility::formatErrors($fileObj->getErrors())); |
||
| 101 | } |
||
| 102 | |||
| 103 | redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_EDITING_SUCCESS); |
||
| 104 | break; |
||
| 105 | case 'clear': |
||
| 106 | //mb echo 'my time is now ' . now; |
||
| 107 | break; |
||
| 108 | case 'del': |
||
| 109 | $confirm = Request::getInt('confirm', '', 'POST'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 110 | |||
| 111 | if ($confirm) { |
||
| 112 | if (!$helper->getHandler('File')->delete($fileObj)) { |
||
| 113 | redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, _AM_PUBLISHER_FILE_DELETE_ERROR); |
||
| 114 | } |
||
| 115 | |||
| 116 | redirect_header('item.php?itemid=' . $fileObj->itemid(), 2, sprintf(_AM_PUBLISHER_FILEISDELETED, $fileObj->name())); |
||
| 117 | } else { |
||
| 118 | // no confirm: show deletion condition |
||
| 119 | |||
| 120 | require_once $GLOBALS['xoops']->path('header.php'); |
||
| 121 | xoops_confirm(['op' => 'del', 'fileid' => $fileObj->fileid(), 'confirm' => 1, 'name' => $fileObj->name()], 'file.php', _AM_PUBLISHER_DELETETHISFILE . ' <br>' . $fileObj->name() . ' <br> <br>', _AM_PUBLISHER_DELETE); |
||
| 122 | require_once $GLOBALS['xoops']->path('footer.php'); |
||
| 123 | } |
||
| 124 | exit(); |
||
| 125 | } |
||
| 126 | require_once $GLOBALS['xoops']->path('footer.php'); |
||
| 127 |