ggoffy /
wgfilemanager
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | You may not change or alter any portion of this comment or credits |
||
| 7 | of supporting developers from this source code or any supporting source code |
||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, |
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 13 | */ |
||
| 14 | |||
| 15 | /** |
||
| 16 | * wgFileManager module for xoops |
||
| 17 | * |
||
| 18 | * @copyright 2021 XOOPS Project (https://xoops.org) |
||
| 19 | * @license GPL 2.0 or later |
||
| 20 | * @package wgfilemanager |
||
| 21 | * @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
||
| 22 | */ |
||
| 23 | |||
| 24 | use Xmf\Request; |
||
|
0 ignored issues
–
show
|
|||
| 25 | use XoopsModules\Wgfilemanager; |
||
| 26 | use XoopsModules\Wgfilemanager\Constants; |
||
| 27 | |||
| 28 | require __DIR__ . '/header.php'; |
||
| 29 | // Get all request values |
||
| 30 | $op = Request::getCmd('op', 'list'); |
||
| 31 | $dirId = Request::getInt('dir_id', 1); |
||
| 32 | $start = Request::getInt('start'); |
||
| 33 | $limit = Request::getInt('limit', $helper->getConfig('userpager')); |
||
| 34 | |||
| 35 | $GLOBALS['xoopsOption']['template_main'] = 'wgfilemanager_index.tpl'; |
||
| 36 | require_once \XOOPS_ROOT_PATH . '/header.php'; |
||
| 37 | // Define Stylesheet |
||
| 38 | foreach ($styles as $style) { |
||
| 39 | $GLOBALS['xoTheme']->addStylesheet($style, null); |
||
| 40 | } |
||
| 41 | $GLOBALS['xoTheme']->addStylesheet(\WGFILEMANAGER_URL . '/assets/css/default.css'); |
||
| 42 | |||
| 43 | $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js'); |
||
| 44 | // Paths |
||
| 45 | $GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGFILEMANAGER_URL.'/index.php'); |
||
| 46 | $GLOBALS['xoopsTpl']->assign('xoops_icons32_url', \XOOPS_ICONS32_URL); |
||
| 47 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_icon_bi_url', \WGFILEMANAGER_ICONS_URL . '/bootstrap/'); |
||
| 48 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL); |
||
| 49 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL); |
||
| 50 | $GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL); |
||
| 51 | //preferences |
||
| 52 | $GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type')); |
||
| 53 | $GLOBALS['xoopsTpl']->assign('panel_type', $helper->getConfig('panel_type')); |
||
| 54 | $indexDirPosition = (string)$helper->getConfig('indexdirposition'); |
||
| 55 | $GLOBALS['xoopsTpl']->assign('indexDirPosLeft', 'left' === $indexDirPosition); |
||
| 56 | $GLOBALS['xoopsTpl']->assign('indexDirPosTop', 'top' === $indexDirPosition); |
||
| 57 | $GLOBALS['xoopsTpl']->assign('indexDirPosNone', 'none' === $indexDirPosition); |
||
| 58 | $GLOBALS['xoopsTpl']->assign('useBroken', (bool)$helper->getConfig('use_broken')); |
||
| 59 | $GLOBALS['xoopsTpl']->assign('useFavorites', (bool)$helper->getConfig('use_favorites')); |
||
| 60 | $iconSet = $helper->getConfig('iconset'); |
||
| 61 | // Keywords |
||
| 62 | $keywords = []; |
||
| 63 | //get param list |
||
| 64 | $params = '&dir_id=' . $dirId; |
||
| 65 | $params .= '&start=' . $start; |
||
| 66 | $params .= '&limit=' . $limit; |
||
| 67 | $GLOBALS['xoopsTpl']->assign('params', $params); |
||
| 68 | |||
| 69 | $cookieStyle = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexstyle'; |
||
| 70 | $cookiePreview = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexpreview'; |
||
| 71 | $cookieSorting = $GLOBALS['xoopsConfig']['usercookie'] . '_wgf_indexsort'; |
||
| 72 | |||
| 73 | switch ($op) { |
||
| 74 | case 'list': |
||
| 75 | default: |
||
| 76 | $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js'); |
||
| 77 | // handle cookies |
||
| 78 | // cookie style |
||
| 79 | $cookieIndexstyle = Request::getString($cookieStyle, 'none', 'COOKIE'); |
||
| 80 | if ('none' === $cookieIndexstyle) { |
||
| 81 | $cookieIndexstyle = Constants::COOKIE_STYLE_DEFAULT; |
||
| 82 | xoops_setcookie($cookieStyle, $cookieIndexstyle, time() + 60 * 60 * 24 * 30); |
||
| 83 | } else { |
||
| 84 | $cookieIndexstyle = $_COOKIE[$cookieStyle]; |
||
| 85 | } |
||
| 86 | $GLOBALS['xoopsTpl']->assign('wgfindexstyle', $cookieIndexstyle); |
||
| 87 | $GLOBALS['xoopsTpl']->assign('styledefault', Constants::COOKIE_STYLE_DEFAULT); |
||
| 88 | $GLOBALS['xoopsTpl']->assign('stylegrouped', Constants::COOKIE_STYLE_GROUPED); |
||
| 89 | $GLOBALS['xoopsTpl']->assign('stylecard', Constants::COOKIE_STYLE_CARD); |
||
| 90 | $GLOBALS['xoopsTpl']->assign('stylecardbig', Constants::COOKIE_STYLE_CARDBIG); |
||
| 91 | |||
| 92 | // cookie preview |
||
| 93 | $cookieIndexPreview = Request::getString($cookiePreview, 'none', 'COOKIE'); |
||
| 94 | if ('none' === $cookieIndexPreview) { |
||
| 95 | $cookieIndexPreview = Constants::COOKIE_NOPREVIEW; |
||
| 96 | xoops_setcookie($cookiePreview, $cookieIndexPreview, time() + 60 * 60 * 24 * 30); |
||
| 97 | } else { |
||
| 98 | $cookieIndexPreview = $_COOKIE[$cookiePreview]; |
||
| 99 | } |
||
| 100 | $GLOBALS['xoopsTpl']->assign('wgfindexpreview', (int)$cookieIndexPreview); |
||
| 101 | $GLOBALS['xoopsTpl']->assign('previewshow', Constants::COOKIE_PREVIEW); |
||
| 102 | $GLOBALS['xoopsTpl']->assign('previewhide', Constants::COOKIE_NOPREVIEW); |
||
| 103 | |||
| 104 | // cookie sorting |
||
| 105 | $cookieIndexSort = Request::getString($cookieSorting, 'none', 'COOKIE'); |
||
| 106 | if ('none' === $cookieIndexSort) { |
||
| 107 | $cookieIndexSort = Constants::COOKIE_SORT_NAME_ASC; |
||
| 108 | xoops_setcookie($cookieSorting, $cookieIndexSort, time() + 60 * 60 * 24 * 30); |
||
| 109 | } else { |
||
| 110 | $cookieIndexSort = $_COOKIE[$cookieSorting]; |
||
| 111 | } |
||
| 112 | $GLOBALS['xoopsTpl']->assign('wgfindexsort', $cookieIndexSort); |
||
| 113 | $GLOBALS['xoopsTpl']->assign('sortnameasc', Constants::COOKIE_SORT_NAME_ASC); |
||
| 114 | $GLOBALS['xoopsTpl']->assign('sortnamedesc', Constants::COOKIE_SORT_NAME_DESC); |
||
| 115 | $GLOBALS['xoopsTpl']->assign('sortctimeasc', Constants::COOKIE_SORT_CTIME_ASC); |
||
| 116 | $GLOBALS['xoopsTpl']->assign('sortctimedesc', Constants::COOKIE_SORT_CTIME_DESC); |
||
| 117 | $GLOBALS['xoopsTpl']->assign('sortdatecreateasc', Constants::COOKIE_SORT_DATE_CREATE_ASC); |
||
| 118 | $GLOBALS['xoopsTpl']->assign('sortdatecreatedesc', Constants::COOKIE_SORT_DATE_CREATE_DESC); |
||
| 119 | switch ($cookieIndexSort) { |
||
| 120 | case Constants::COOKIE_SORT_NAME_ASC: |
||
| 121 | default: |
||
| 122 | $sortby = 'name'; |
||
| 123 | $orderby = 'ASC'; |
||
| 124 | break; |
||
| 125 | case Constants::COOKIE_SORT_NAME_DESC: |
||
| 126 | $sortby = 'name'; |
||
| 127 | $orderby = 'DESC'; |
||
| 128 | break; |
||
| 129 | case Constants::COOKIE_SORT_CTIME_ASC: |
||
| 130 | $sortby = 'ctime'; |
||
| 131 | $orderby = 'ASC'; |
||
| 132 | break; |
||
| 133 | case Constants::COOKIE_SORT_CTIME_DESC: |
||
| 134 | $sortby = 'ctime'; |
||
| 135 | $orderby = 'DESC'; |
||
| 136 | break; |
||
| 137 | case Constants::COOKIE_SORT_DATE_CREATE_ASC: |
||
| 138 | $sortby = 'date_create'; |
||
| 139 | $orderby = 'ASC'; |
||
| 140 | break; |
||
| 141 | case Constants::COOKIE_SORT_DATE_CREATE_DESC: |
||
| 142 | $sortby = 'date_create'; |
||
| 143 | $orderby = 'DESC'; |
||
| 144 | break; |
||
| 145 | } |
||
| 146 | |||
| 147 | // Breadcrumbs |
||
| 148 | if ($dirId > 1) { |
||
| 149 | $xoBreadcrumbs[] = ['title' => \_MA_WGFILEMANAGER_INDEX, 'link' => 'index.php']; |
||
| 150 | $dirArray = $directoryHandler->getDirListBreadcrumb($dirId); |
||
| 151 | $dirListBreadcrumb = array_reverse($dirArray, true); |
||
| 152 | foreach ($dirListBreadcrumb as $key => $value) { |
||
| 153 | if ($key == array_key_last($dirListBreadcrumb)) { |
||
| 154 | $xoBreadcrumbs[] = ['title' => $value]; |
||
| 155 | } else { |
||
| 156 | $xoBreadcrumbs[] = ['title' => $value, 'link' => 'index.php?dir_id=' . $key]; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } else { |
||
| 160 | $xoBreadcrumbs[] = ['title' => \_MA_WGFILEMANAGER_INDEX]; |
||
| 161 | } |
||
| 162 | |||
| 163 | //get permissions |
||
| 164 | $GLOBALS['xoopsTpl']->assign('permCreateDir', $permissionsHandler->getPermSubmitDirectory($dirId)); |
||
| 165 | $GLOBALS['xoopsTpl']->assign('permEditDir', $permissionsHandler->getPermSubmitDirectory($dirId)); |
||
| 166 | $GLOBALS['xoopsTpl']->assign('permEditFile', $permissionsHandler->getPermSubmitDirectory($dirId)); |
||
| 167 | $GLOBALS['xoopsTpl']->assign('permDownloadFileFromDir', $permissionsHandler->getPermDownloadFileFromDir($dirId)); |
||
| 168 | $GLOBALS['xoopsTpl']->assign('permUploadFileToDir', $permissionsHandler->getPermUploadFileToDir($dirId)); |
||
| 169 | $GLOBALS['xoopsTpl']->assign('permViewDirectory', $permissionsHandler->getPermViewDirectory($dirId)); |
||
| 170 | $GLOBALS['xoopsTpl']->assign('showBtnDetails', true); |
||
| 171 | |||
| 172 | //get directory list |
||
| 173 | $dirList = $directoryHandler->getDirList(0, $dirId); |
||
| 174 | $GLOBALS['xoopsTpl']->assign('dir_list', $dirList); |
||
| 175 | $GLOBALS['xoopsTpl']->assign('dirId', $dirId); |
||
| 176 | $indexDirList = $directoryHandler->getSubDirList($dirId); |
||
| 177 | $GLOBALS['xoopsTpl']->assign('indexDirlist', $indexDirList); |
||
| 178 | $GLOBALS['xoopsTpl']->assign('indexDirlistIcon', WGFILEMANAGER_ICONS_URL . '/foldericons/folder2.png'); |
||
| 179 | |||
| 180 | // get files |
||
| 181 | $crFile = new \CriteriaCompo(); |
||
| 182 | $crFile->add(new \Criteria('directory_id', $dirId)); |
||
| 183 | $fileCount = $fileHandler->getCount($crFile); |
||
| 184 | |||
| 185 | $fileList = []; |
||
| 186 | $crFile->setStart($start); |
||
| 187 | $crFile->setLimit($limit); |
||
| 188 | $crFile->setSort($sortby); |
||
| 189 | $crFile->setOrder($orderby); |
||
| 190 | if ($fileCount > 0) { |
||
| 191 | $fileIcons = []; |
||
| 192 | if ('none' !== $iconSet) { |
||
| 193 | $fileIcons = $fileHandler->getFileIconCollection($iconSet); |
||
| 194 | } |
||
| 195 | $fileAll = $fileHandler->getAll($crFile); |
||
| 196 | foreach (\array_keys($fileAll) as $i) { |
||
| 197 | $file = $fileAll[$i]->getValuesFile(); |
||
| 198 | $ext = ''; |
||
| 199 | if (strpos($file['name'],'.') > 0) { |
||
| 200 | $ext = substr(strrchr($file['name'], '.'), 1); |
||
| 201 | } |
||
| 202 | $fileCategory = isset($fileIcons['files'][$ext]) ? (int)$fileIcons['files'][$ext]['category'] : 0; |
||
| 203 | $file['category'] = $fileCategory; |
||
| 204 | $file['icon_url'] = isset($fileIcons['files'][$ext]) ? $fileIcons['files'][$ext]['src'] : $fileIcons['default']; |
||
| 205 | $file['image'] = false; |
||
| 206 | $file['image_url'] = ''; |
||
| 207 | $file['pdf'] = false; |
||
| 208 | $file['pdf_url'] = ''; |
||
| 209 | switch ($fileCategory) { |
||
| 210 | case 0: |
||
| 211 | break; |
||
| 212 | case Constants::MIMETYPE_CAT_IMAGE: |
||
| 213 | $file['image'] = true; |
||
| 214 | $file['image_url'] = $file['real_url']; |
||
| 215 | break; |
||
| 216 | case Constants::MIMETYPE_CAT_PDF: |
||
| 217 | $file['pdf'] = true; |
||
| 218 | $file['pdf_url'] = $file['real_url']; |
||
| 219 | break; |
||
| 220 | } |
||
| 221 | $fileList[$i] = $file; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | $GLOBALS['xoopsTpl']->assign('indexFilelist', $fileList); |
||
| 225 | |||
| 226 | $block['fav_list'] = []; |
||
| 227 | if ((bool)$helper->getConfig('use_favorites')) { |
||
| 228 | //get fav list |
||
| 229 | $favList = []; |
||
| 230 | //get directory fav list |
||
| 231 | $favList['dirs'] = $directoryHandler->getFavDirList(); |
||
| 232 | //get directory fav list |
||
| 233 | $favList['files'] = $fileHandler->getFavFileList(); |
||
| 234 | $GLOBALS['xoopsTpl']->assign('fav_list', $favList); |
||
| 235 | } |
||
| 236 | // Display Navigation |
||
| 237 | if ($fileCount > $limit) { |
||
| 238 | require_once \XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 239 | $pagenav = new \XoopsPageNav($fileCount, $limit, $start, 'start', 'op=list&limit=' . $limit . '&dir_id=' . $dirId); |
||
| 240 | $GLOBALS['xoopsTpl']->assign('pagenavFile', $pagenav->renderNav()); |
||
| 241 | } |
||
| 242 | break; |
||
| 243 | |||
| 244 | case 'setstyle': |
||
| 245 | // set cookies and reload |
||
| 246 | $styleType = Request::getString('style'); |
||
| 247 | xoops_setcookie($cookieStyle, $styleType, time() + 60 * 60 * 24 * 30); |
||
| 248 | \redirect_header('index.php?op=list' . $params, 0); |
||
| 249 | break; |
||
| 250 | case 'setpreview': |
||
| 251 | // set cookies and reload |
||
| 252 | $previewType = Request::getInt('preview'); |
||
| 253 | xoops_setcookie($cookiePreview, $previewType, time() + 60 * 60 * 24 * 30); |
||
| 254 | |||
| 255 | \redirect_header('index.php?op=list' . $params, 0); |
||
| 256 | break; |
||
| 257 | case 'setsort': |
||
| 258 | // set cookies and reload |
||
| 259 | $sortType = Request::getInt('sort'); |
||
| 260 | xoops_setcookie($cookieSorting, $sortType, time() + 60 * 60 * 24 * 30); |
||
| 261 | |||
| 262 | \redirect_header('index.php?op=list' . $params, 0); |
||
| 263 | break; |
||
| 264 | } |
||
| 265 | |||
| 266 | // Keywords |
||
| 267 | wgfilemanagerMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords)); |
||
| 268 | unset($keywords); |
||
| 269 | |||
| 270 | require __DIR__ . '/footer.php'; |
||
| 271 |
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: