| Total Complexity | 87 |
| Total Lines | 716 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like MimetypesUtility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MimetypesUtility, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 33 | class MimetypesUtility |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * function add() |
||
| 37 | */ |
||
| 38 | public static function add(): void |
||
| 39 | { |
||
| 40 | global $mimetypeHandler, $limit, $start; |
||
| 41 | $helper = Helper::getInstance(); |
||
| 42 | |||
| 43 | if (Request::hasVar('add_mime', 'POST')) { |
||
| 44 | $has_errors = false; |
||
| 45 | $error = []; |
||
| 46 | $mime_ext = \Xmf\Request::getString('mime_ext', '', 'POST'); |
||
| 47 | $mime_name = \Xmf\Request::getString('mime_name', '', 'POST'); |
||
| 48 | $mime_types = \Xmf\Request::getString('mime_types', '', 'POST'); |
||
| 49 | $mime_admin = Request::getInt('mime_admin', 0, 'POST'); |
||
| 50 | $mime_user = Request::getInt('mime_user', 0, 'POST'); |
||
| 51 | |||
| 52 | //Validate Mimetype entry |
||
| 53 | if ('' === \trim($mime_ext)) { |
||
| 54 | $has_errors = true; |
||
| 55 | $error['mime_ext'][] = \_AM_XHELP_VALID_ERR_MIME_EXT; |
||
| 56 | } |
||
| 57 | |||
| 58 | if ('' === \trim($mime_name)) { |
||
| 59 | $has_errors = true; |
||
| 60 | $error['mime_name'][] = \_AM_XHELP_VALID_ERR_MIME_NAME; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ('' === \trim($mime_types)) { |
||
| 64 | $has_errors = true; |
||
| 65 | $error['mime_types'][] = \_AM_XHELP_VALID_ERR_MIME_TYPES; |
||
| 66 | } |
||
| 67 | |||
| 68 | if ($has_errors) { |
||
| 69 | $session = Session::getInstance(); |
||
| 70 | $mime = []; |
||
| 71 | $mime['mime_ext'] = $mime_ext; |
||
| 72 | $mime['mime_name'] = $mime_name; |
||
| 73 | $mime['mime_types'] = $mime_types; |
||
| 74 | $mime['mime_admin'] = $mime_admin; |
||
| 75 | $mime['mime_user'] = $mime_user; |
||
| 76 | $session->set('xhelp_addMime', $mime); |
||
| 77 | $session->set('xhelp_addMimeErr', $error); |
||
| 78 | \redirect_header(Utility::createURI(XHELP_ADMIN_URL . '/mimetypes.php', ['op' => 'add'], false)); |
||
|
|
|||
| 79 | } |
||
| 80 | |||
| 81 | $mimetype = $mimetypeHandler->create(); |
||
| 82 | $mimetype->setVar('mime_ext', $mime_ext); |
||
| 83 | $mimetype->setVar('mime_name', $mime_name); |
||
| 84 | $mimetype->setVar('mime_types', $mime_types); |
||
| 85 | $mimetype->setVar('mime_admin', $mime_admin); |
||
| 86 | $mimetype->setVar('mime_user', $mime_user); |
||
| 87 | |||
| 88 | if ($mimetypeHandler->insert($mimetype)) { |
||
| 89 | clearAddSessionVars(); |
||
| 90 | $helper->redirect("mimetypes.php?op=manage&limit=$limit&start=$start"); |
||
| 91 | } else { |
||
| 92 | $helper->redirect("mimetypes.php?op=manage&limit=$limit&start=$start", 3, \_AM_XHELP_MESSAGE_ADD_MIME_ERROR); |
||
| 93 | } |
||
| 94 | } else { |
||
| 95 | \xoops_cp_header(); |
||
| 96 | //echo $oAdminButton->renderButtons('mimetypes'); |
||
| 97 | $adminObject = Admin::getInstance(); |
||
| 98 | $adminObject->displayNavigation(\basename(__FILE__)); |
||
| 99 | |||
| 100 | $session = Session::getInstance(); |
||
| 101 | $mime_type = $session->get('xhelp_addMime'); |
||
| 102 | $mime_errors = $session->get('xhelp_addMimeErr'); |
||
| 103 | |||
| 104 | //Display any form errors |
||
| 105 | if (false === !$mime_errors) { |
||
| 106 | \xhelpRenderErrors($mime_errors, Utility::createURI(XHELP_ADMIN_URL . '/mimetypes.php', ['op' => 'clearAddSession'])); |
||
| 107 | } |
||
| 108 | |||
| 109 | if (false !== $mime_type) { |
||
| 110 | $mime_ext = $mime_type['mime_ext']; |
||
| 111 | $mime_name = $mime_type['mime_name']; |
||
| 112 | $mime_types = $mime_type['mime_types']; |
||
| 113 | $mime_admin = $mime_type['mime_admin']; |
||
| 114 | $mime_user = $mime_type['mime_user']; |
||
| 115 | } else { |
||
| 116 | $mime_ext = ''; |
||
| 117 | $mime_name = ''; |
||
| 118 | $mime_types = ''; |
||
| 119 | $mime_admin = 1; |
||
| 120 | $mime_user = 1; |
||
| 121 | } |
||
| 122 | |||
| 123 | // Display add form |
||
| 124 | echo "<form action='mimetypes.php?op=add' method='post'>"; |
||
| 125 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 126 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 127 | echo "<tr><th colspan='2'>" . \_AM_XHELP_MIME_CREATEF . '</th></tr>'; |
||
| 128 | echo "<tr valign='top'> |
||
| 129 | <td class='head'>" . \_AM_XHELP_MIME_EXTF . "</td> |
||
| 130 | <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mime_ext' size='5'></td> |
||
| 131 | </tr>"; |
||
| 132 | echo "<tr valign='top'> |
||
| 133 | <td class='head'>" . \_AM_XHELP_MIME_NAMEF . "</td> |
||
| 134 | <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mime_name'></td> |
||
| 135 | </tr>"; |
||
| 136 | echo "<tr valign='top'> |
||
| 137 | <td class='head'>" . \_AM_XHELP_MIME_TYPEF . "</td> |
||
| 138 | <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mime_types</textarea></td> |
||
| 139 | </tr>"; |
||
| 140 | echo "<tr valign='top'> |
||
| 141 | <td class='head'>" . \_AM_XHELP_MIME_ADMINF . "</td> |
||
| 142 | <td class='even'>"; |
||
| 143 | |||
| 144 | echo "<input type='radio' name='mime_admin' value='1' " . (1 === $mime_admin ? 'checked' : '') . '>' . \_XHELP_TEXT_YES; |
||
| 145 | echo "<input type='radio' name='mime_admin' value='0' " . (0 === $mime_admin ? 'checked' : '') . '>' . \_XHELP_TEXT_NO . ' |
||
| 146 | </td> |
||
| 147 | </tr>'; |
||
| 148 | echo "<tr valign='top'> |
||
| 149 | <td class='head'>" . \_AM_XHELP_MIME_USERF . "</td> |
||
| 150 | <td class='even'>"; |
||
| 151 | echo "<input type='radio' name='mime_user' value='1'" . (1 === $mime_user ? 'checked' : '') . '>' . \_XHELP_TEXT_YES; |
||
| 152 | echo "<input type='radio' name='mime_user' value='0'" . (0 === $mime_user ? 'checked' : '') . '>' . \_XHELP_TEXT_NO . ' |
||
| 153 | </td> |
||
| 154 | </tr>'; |
||
| 155 | echo "<tr valign='top'> |
||
| 156 | <td class='head'></td> |
||
| 157 | <td class='even'> |
||
| 158 | <input type='submit' name='add_mime' id='add_mime' value='" . \_AM_XHELP_BUTTON_SUBMIT . "' class='formButton'> |
||
| 159 | <input type='button' name='cancel' value='" . \_AM_XHELP_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton'> |
||
| 160 | </td> |
||
| 161 | </tr>"; |
||
| 162 | echo '</table></form>'; |
||
| 163 | // end of add form |
||
| 164 | |||
| 165 | // Find new mimetypes table |
||
| 166 | echo "<form action='https://www.filext.com' method='post'>"; |
||
| 167 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 168 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 169 | echo "<tr><th colspan='2'>" . \_AM_XHELP_MIME_FINDMIMETYPE . '</th></tr>'; |
||
| 170 | |||
| 171 | echo "<tr class='foot'> |
||
| 172 | <td colspan='2'><input type='submit' name='find_mime' id='find_mime' value='" . \_AM_XHELP_MIME_FINDIT . "' class='formButton'></td> |
||
| 173 | </tr>"; |
||
| 174 | |||
| 175 | echo '</table></form>'; |
||
| 176 | |||
| 177 | require_once \dirname(__DIR__) . '/admin/admin_footer.php'; |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | public static function delete(): void |
||
| 182 | { |
||
| 183 | global $mimetypeHandler, $start, $limit; |
||
| 184 | $mime_id = 0; |
||
| 185 | $helper = Helper::getInstance(); |
||
| 186 | |||
| 187 | if (Request::hasVar('id')) { |
||
| 188 | $mime_id = Request::getInt('id', 0, 'REQUEST'); |
||
| 189 | } else { |
||
| 190 | $helper->redirect('admin/mimetypes.php', 3, \_AM_XHELP_MESSAGE_NO_ID); |
||
| 191 | } |
||
| 192 | $mimetype = $mimetypeHandler->get($mime_id); // Retrieve mimetype object |
||
| 193 | if ($mimetype) { |
||
| 194 | if ($mimetypeHandler->delete($mimetype, true)) { |
||
| 195 | $helper->redirect("mimetypes.php?op=manage&limit=$limit&start=$start"); |
||
| 196 | } else { |
||
| 197 | $helper->redirect("mimetypes.php?op=manage&id=$mime_id&limit=$limit&start=$start", 3, \_AM_XHELP_MESSAGE_DELETE_MIME_ERROR); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | |||
| 202 | public static function edit(): void |
||
| 203 | { |
||
| 204 | global $mimetypeHandler, $start, $limit; |
||
| 205 | $mime_id = 0; |
||
| 206 | $helper = Helper::getInstance(); |
||
| 207 | $has_errors = false; |
||
| 208 | $error = []; |
||
| 209 | |||
| 210 | if (Request::hasVar('id')) { |
||
| 211 | $mime_id = Request::getInt('id', 0, 'REQUEST'); |
||
| 212 | } else { |
||
| 213 | $helper->redirect('admin/mimetypes.php', 3, \_AM_XHELP_MESSAGE_NO_ID); |
||
| 214 | } |
||
| 215 | $mimetype = $mimetypeHandler->get($mime_id); // Retrieve mimetype object |
||
| 216 | |||
| 217 | if (Request::hasVar('edit_mime', 'POST')) { |
||
| 218 | $mime_admin = 0; |
||
| 219 | $mime_user = 0; |
||
| 220 | if (Request::hasVar('mime_admin', 'POST') && 1 === $_POST['mime_admin']) { |
||
| 221 | $mime_admin = 1; |
||
| 222 | } |
||
| 223 | if (Request::hasVar('mime_user', 'POST') && 1 === $_POST['mime_user']) { |
||
| 224 | $mime_user = 1; |
||
| 225 | } |
||
| 226 | |||
| 227 | //Validate Mimetype entry |
||
| 228 | if ('' === \trim($_POST['mime_ext'])) { |
||
| 229 | $has_errors = true; |
||
| 230 | $error['mime_ext'][] = \_AM_XHELP_VALID_ERR_MIME_EXT; |
||
| 231 | } |
||
| 232 | |||
| 233 | if ('' === \trim(\Xmf\Request::getString('mime_name', '', 'POST'))) { |
||
| 234 | $has_errors = true; |
||
| 235 | $error['mime_name'][] = \_AM_XHELP_VALID_ERR_MIME_NAME; |
||
| 236 | } |
||
| 237 | |||
| 238 | if ('' === \trim($_POST['mime_types'])) { |
||
| 239 | $has_errors = true; |
||
| 240 | $error['mime_types'][] = \_AM_XHELP_VALID_ERR_MIME_TYPES; |
||
| 241 | } |
||
| 242 | |||
| 243 | if ($has_errors) { |
||
| 244 | $session = Session::getInstance(); |
||
| 245 | $mime = []; |
||
| 246 | $mime['mime_ext'] = \Xmf\Request::getString('mime_ext', '', 'POST'); |
||
| 247 | $mime['mime_name'] = \Xmf\Request::getString('mime_name', '', 'POST'); |
||
| 248 | $mime['mime_types'] = $_POST['mime_types']; |
||
| 249 | $mime['mime_admin'] = $mime_admin; |
||
| 250 | $mime['mime_user'] = $mime_user; |
||
| 251 | $session->set('xhelp_editMime_' . $mime_id, $mime); |
||
| 252 | $session->set('xhelp_editMimeErr_' . $mime_id, $error); |
||
| 253 | \redirect_header(Utility::createURI(XHELP_ADMIN_URL . '/mimetypes.php', ['op' => 'edit', 'id' => $mime_id], false)); |
||
| 254 | } |
||
| 255 | |||
| 256 | $mimetype->setVar('mime_ext', \Xmf\Request::getString('mime_ext', '', 'POST')); |
||
| 257 | $mimetype->setVar('mime_name', \Xmf\Request::getString('mime_name', '', 'POST')); |
||
| 258 | $mimetype->setVar('mime_types', $_POST['mime_types']); |
||
| 259 | $mimetype->setVar('mime_admin', $mime_admin); |
||
| 260 | $mimetype->setVar('mime_user', $mime_user); |
||
| 261 | |||
| 262 | if ($mimetypeHandler->insert($mimetype, true)) { |
||
| 263 | clearEditSessionVars($mime_id); |
||
| 264 | $helper->redirect("mimetypes.php?op=manage&limit=$limit&start=$start"); |
||
| 265 | } else { |
||
| 266 | $helper->redirect("mimetypes.php?op=edit&id=$mime_id", 3, \_AM_XHELP_MESSAGE_EDIT_MIME_ERROR); |
||
| 267 | } |
||
| 268 | } else { |
||
| 269 | $session = Session::getInstance(); |
||
| 270 | $mime_type = $session->get("xhelp_editMime_$mime_id"); |
||
| 271 | $mime_errors = $session->get("xhelp_editMimeErr_$mime_id"); |
||
| 272 | |||
| 273 | // Display header |
||
| 274 | \xoops_cp_header(); |
||
| 275 | //echo $oAdminButton->renderButtons('mimetypes'); |
||
| 276 | $adminObject = Admin::getInstance(); |
||
| 277 | $adminObject->displayNavigation(\basename(__FILE__)); |
||
| 278 | |||
| 279 | //Display any form errors |
||
| 280 | if (false === !$mime_errors) { |
||
| 281 | \xhelpRenderErrors($mime_errors, Utility::createURI(XHELP_ADMIN_URL . '/mimetypes.php', ['op' => 'clearEditSession', 'id' => $mime_id])); |
||
| 282 | } |
||
| 283 | |||
| 284 | if (false !== $mime_type) { |
||
| 285 | $mime_ext = $mime_type['mime_ext']; |
||
| 286 | $mime_name = $mime_type['mime_name']; |
||
| 287 | $mime_types = $mime_type['mime_types']; |
||
| 288 | $mime_admin = $mime_type['mime_admin']; |
||
| 289 | $mime_user = $mime_type['mime_user']; |
||
| 290 | } else { |
||
| 291 | $mime_ext = $mimetype->getVar('mime_ext'); |
||
| 292 | $mime_name = $mimetype->getVar('mime_name', 'e'); |
||
| 293 | $mime_types = $mimetype->getVar('mime_types', 'e'); |
||
| 294 | $mime_admin = $mimetype->getVar('mime_admin'); |
||
| 295 | $mime_user = $mimetype->getVar('mime_user'); |
||
| 296 | } |
||
| 297 | |||
| 298 | // Display edit form |
||
| 299 | echo "<form action='mimetypes.php?op=edit&id=" . $mime_id . "' method='post'>"; |
||
| 300 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 301 | echo "<input type='hidden' name='limit' value='" . $limit . "'>"; |
||
| 302 | echo "<input type='hidden' name='start' value='" . $start . "'>"; |
||
| 303 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 304 | echo "<tr><th colspan='2'>" . \_AM_XHELP_MIME_MODIFYF . '</th></tr>'; |
||
| 305 | echo "<tr valign='top'> |
||
| 306 | <td class='head'>" . \_AM_XHELP_MIME_EXTF . "</td> |
||
| 307 | <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mime_ext' size='5'></td> |
||
| 308 | </tr>"; |
||
| 309 | echo "<tr valign='top'> |
||
| 310 | <td class='head'>" . \_AM_XHELP_MIME_NAMEF . "</td> |
||
| 311 | <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mime_name'></td> |
||
| 312 | </tr>"; |
||
| 313 | echo "<tr valign='top'> |
||
| 314 | <td class='head'>" . \_AM_XHELP_MIME_TYPEF . "</td> |
||
| 315 | <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mime_types</textarea></td> |
||
| 316 | </tr>"; |
||
| 317 | echo "<tr valign='top'> |
||
| 318 | <td class='head'>" . \_AM_XHELP_MIME_ADMINF . "</td> |
||
| 319 | <td class='even'> |
||
| 320 | <input type='radio' name='mime_admin' value='1' " . (1 === $mime_admin ? 'checked' : '') . '>' . \_XHELP_TEXT_YES . " |
||
| 321 | <input type='radio' name='mime_admin' value='0' " . (0 === $mime_admin ? 'checked' : '') . '>' . \_XHELP_TEXT_NO . ' |
||
| 322 | </td> |
||
| 323 | </tr>'; |
||
| 324 | echo "<tr valign='top'> |
||
| 325 | <td class='head'>" . \_AM_XHELP_MIME_USERF . "</td> |
||
| 326 | <td class='even'> |
||
| 327 | <input type='radio' name='mime_user' value='1' " . (1 === $mime_user ? 'checked' : '') . '>' . \_XHELP_TEXT_YES . " |
||
| 328 | <input type='radio' name='mime_user' value='0' " . (0 === $mime_user ? 'checked' : '') . '>' . \_XHELP_TEXT_NO . ' |
||
| 329 | </td> |
||
| 330 | </tr>'; |
||
| 331 | echo "<tr valign='top'> |
||
| 332 | <td class='head'></td> |
||
| 333 | <td class='even'> |
||
| 334 | <input type='submit' name='edit_mime' id='edit_mime' value='" . \_AM_XHELP_BUTTON_UPDATE . "' class='formButton'> |
||
| 335 | <input type='button' name='cancel' value='" . \_AM_XHELP_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton'> |
||
| 336 | </td> |
||
| 337 | </tr>"; |
||
| 338 | echo '</table></form>'; |
||
| 339 | // end of edit form |
||
| 340 | |||
| 341 | require_once \dirname(__DIR__) . '/admin/admin_footer.php'; |
||
| 342 | } |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * function manage() |
||
| 347 | */ |
||
| 348 | public static function manage(): void |
||
| 349 | { |
||
| 350 | global $mimetypeHandler, $icons, $start, $limit, $aSortBy, $aOrderBy, $aLimitBy, $aSearchBy; |
||
| 351 | $helper = Helper::getInstance(); |
||
| 352 | |||
| 353 | if (Request::hasVar('deleteMimes', 'POST')) { |
||
| 354 | $aMimes = $_POST['mimes']; |
||
| 355 | |||
| 356 | $criteria = new \Criteria('mime_id', '(' . \implode(',', $aMimes) . ')', 'IN'); |
||
| 357 | |||
| 358 | if ($mimetypeHandler->deleteAll($criteria)) { |
||
| 359 | $helper->redirect("mimetypes.php?limit=$limit&start=$start"); |
||
| 360 | } else { |
||
| 361 | $helper->redirect("mimetypes.php?limit=$limit&start=$start", 3, \_AM_XHELP_MESSAGE_DELETE_MIME_ERROR); |
||
| 362 | } |
||
| 363 | } |
||
| 364 | if (Request::hasVar('add_mime', 'POST')) { |
||
| 365 | $helper->redirect("mimetypes.php?op=add&start=$start&limit=$limit"); |
||
| 366 | } |
||
| 367 | if (Request::hasVar('mime_search', 'POST')) { |
||
| 368 | $helper->redirect('admin/mimetypes.php?op=search'); |
||
| 369 | } |
||
| 370 | |||
| 371 | \xoops_cp_header(); |
||
| 372 | //echo $oAdminButton->renderButtons('mimetypes'); |
||
| 373 | $adminObject = Admin::getInstance(); |
||
| 374 | $adminObject->displayNavigation(\basename(__FILE__)); |
||
| 375 | |||
| 376 | $criteria = new \Criteria('', ''); |
||
| 377 | if (Request::hasVar('order', 'REQUEST')) { |
||
| 378 | $order = $_REQUEST['order']; |
||
| 379 | } else { |
||
| 380 | $order = 'ASC'; |
||
| 381 | } |
||
| 382 | if (Request::hasVar('sort', 'REQUEST')) { |
||
| 383 | $sort = $_REQUEST['sort']; |
||
| 384 | } else { |
||
| 385 | $sort = 'mime_ext'; |
||
| 386 | } |
||
| 387 | $criteria->setOrder($order); |
||
| 388 | $criteria->setStart($start); |
||
| 389 | $criteria->setLimit($limit); |
||
| 390 | $criteria->setSort($sort); |
||
| 391 | $mimetypes = $mimetypeHandler->getObjects($criteria); // Retrieve a list of all mimetypes |
||
| 392 | $mime_count = $mimetypeHandler->getCount(); |
||
| 393 | $nav = new \XoopsPageNav($mime_count, $limit, $start, 'start', "op=manage&limit=$limit"); |
||
| 394 | |||
| 395 | echo '<script type="text/javascript" src="' . \XHELP_BASE_URL . '/include/functions.js"></script>'; |
||
| 396 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 397 | echo "<tr><td colspan='6' align='right'>"; |
||
| 398 | echo "<form action='" . XHELP_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>"; |
||
| 399 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 400 | echo '<table>'; |
||
| 401 | echo '<tr>'; |
||
| 402 | echo "<td align='right'>" . \_AM_XHELP_TEXT_SEARCH_BY . '</td>'; |
||
| 403 | echo "<td align='left'><select name='search_by'>"; |
||
| 404 | foreach ($aSearchBy as $value => $text) { |
||
| 405 | ($sort == $value) ? $selected = 'selected' : $selected = ''; |
||
| 406 | echo "<option value='$value' $selected>$text</option>"; |
||
| 407 | } |
||
| 408 | echo '</select></td>'; |
||
| 409 | echo "<td align='right'>" . \_AM_XHELP_TEXT_SEARCH_TEXT . '</td>'; |
||
| 410 | echo "<td align='left'><input type='text' name='search_text' id='search_text' value=''></td>"; |
||
| 411 | echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . \_AM_XHELP_BUTTON_SEARCH . "'></td>"; |
||
| 412 | echo '</tr></table></form></td></tr>'; |
||
| 413 | |||
| 414 | echo "<tr><td colspan='6'>"; |
||
| 415 | echo "<form action='" . XHELP_ADMIN_URL . "/mimetypes.php?op=manage' style='margin:0; padding:0;' method='post'>"; |
||
| 416 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 417 | echo "<table width='100%'>"; |
||
| 418 | echo "<tr><td align='right'>" . \_AM_XHELP_TEXT_SORT_BY . " |
||
| 419 | <select name='sort'>"; |
||
| 420 | foreach ($aSortBy as $value => $text) { |
||
| 421 | ($sort == $value) ? $selected = 'selected' : $selected = ''; |
||
| 422 | echo "<option value='$value' $selected>$text</option>"; |
||
| 423 | } |
||
| 424 | echo '</select> |
||
| 425 | |
||
| 426 | ' . \_AM_XHELP_TEXT_ORDER_BY . " |
||
| 427 | <select name='order'>"; |
||
| 428 | foreach ($aOrderBy as $value => $text) { |
||
| 429 | ($order == $value) ? $selected = 'selected' : $selected = ''; |
||
| 430 | echo "<option value='$value' $selected>$text</option>"; |
||
| 431 | } |
||
| 432 | echo '</select> |
||
| 433 | |
||
| 434 | ' . \_AM_XHELP_TEXT_NUMBER_PER_PAGE . " |
||
| 435 | <select name='limit'>"; |
||
| 436 | foreach ($aLimitBy as $value => $text) { |
||
| 437 | ($limit == $value) ? $selected = 'selected' : $selected = ''; |
||
| 438 | echo "<option value='$value' $selected>$text</option>"; |
||
| 439 | } |
||
| 440 | echo "</select> |
||
| 441 | <input type='submit' name='mime_sort' id='mime_sort' value='" . \_AM_XHELP_BUTTON_SUBMIT . "'> |
||
| 442 | </td> |
||
| 443 | </tr>"; |
||
| 444 | echo '</table>'; |
||
| 445 | echo '</td></tr>'; |
||
| 446 | echo "<tr><th colspan='6'>" . \_AM_XHELP_MENU_MIMETYPES . '</th></tr>'; |
||
| 447 | echo "<tr class='head'> |
||
| 448 | <td>" . \_AM_XHELP_MIME_ID . '</td> |
||
| 449 | <td>' . \_AM_XHELP_MIME_NAME . '</td> |
||
| 450 | <td>' . \_AM_XHELP_MIME_EXT . '</td> |
||
| 451 | <td>' . \_AM_XHELP_MIME_ADMIN . '</td> |
||
| 452 | <td>' . \_AM_XHELP_MIME_USER . '</td> |
||
| 453 | <td>' . \_AM_XHELP_MINDEX_ACTION . '</td> |
||
| 454 | </tr>'; |
||
| 455 | foreach ($mimetypes as $mime) { |
||
| 456 | echo "<tr class='even'> |
||
| 457 | <td><input type='checkbox' name='mimes[]' value='" . $mime->getVar('mime_id') . "'>" . $mime->getVar('mime_id') . '</td> |
||
| 458 | <td>' . $mime->getVar('mime_name') . '</td> |
||
| 459 | <td>' . $mime->getVar('mime_ext') . "</td> |
||
| 460 | <td> |
||
| 461 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&id=' . $mime->getVar('mime_id') . '&mime_admin=' . $mime->getVar('mime_admin') . '&limit=' . $limit . '&start=' . $start . "'> |
||
| 462 | " . (($mime->getVar('mime_admin') && isset($icons['online'])) ? $icons['online'] : $icons['offline'] ?? '') . "</a> |
||
| 463 | </td> |
||
| 464 | <td> |
||
| 465 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&id=' . $mime->getVar('mime_id') . '&mime_user=' . $mime->getVar('mime_user') . '&limit=' . $limit . '&start=' . $start . "'> |
||
| 466 | " . ($mime->getVar('mime_user') ? $icons['online'] ?? '' : $icons['offline'] ?? '') . "</a> |
||
| 467 | </td> |
||
| 468 | <td> |
||
| 469 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=edit&id=' . $mime->getVar('mime_id') . '&limit=' . $limit . '&start=' . $start . "'>" . ($icons['edit'] ?? '') . "</a> |
||
| 470 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=delete&id=' . $mime->getVar('mime_id') . '&limit=' . $limit . '&start=' . $start . "'>" . ($icons['delete'] ?? '') . '</a> |
||
| 471 | </td> |
||
| 472 | </tr>'; |
||
| 473 | } |
||
| 474 | echo "<tr class='foot'> |
||
| 475 | <td colspan='6' valign='top'> |
||
| 476 | <a href='https://www.filext.com' style='float: right;' target='_blank'>" . \_AM_XHELP_MIME_FINDMIMETYPE . "</a> |
||
| 477 | <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);'> |
||
| 478 | <input type='submit' name='deleteMimes' id='deleteMimes' value='" . \_AM_XHELP_BUTTON_DELETE . "'> |
||
| 479 | <input type='submit' name='add_mime' id='add_mime' value='" . \_AM_XHELP_MIME_CREATEF . "' class='formButton'> |
||
| 480 | </td> |
||
| 481 | </tr>"; |
||
| 482 | echo '</table>'; |
||
| 483 | echo "<div id='staff_nav'>" . $nav->renderNav() . '</div>'; |
||
| 484 | |||
| 485 | require_once \dirname(__DIR__) . '/admin/admin_footer.php'; |
||
| 486 | } |
||
| 487 | |||
| 488 | public static function search(): void |
||
| 489 | { |
||
| 490 | global $mimetypeHandler, $limit, $start, $icons, $aSearchBy, $aOrderBy, $aLimitBy, $aSortBy; |
||
| 491 | $helper = Helper::getInstance(); |
||
| 492 | |||
| 493 | if (Request::hasVar('deleteMimes', 'POST')) { |
||
| 494 | $aMimes = $_POST['mimes']; |
||
| 495 | |||
| 496 | $criteria = new \Criteria('mime_id', '(' . \implode(',', $aMimes) . ')', 'IN'); |
||
| 497 | |||
| 498 | if ($mimetypeHandler->deleteAll($criteria)) { |
||
| 499 | $helper->redirect("mimetypes.php?limit=$limit&start=$start"); |
||
| 500 | } else { |
||
| 501 | $helper->redirect("mimetypes.php?limit=$limit&start=$start", 3, \_AM_XHELP_MESSAGE_DELETE_MIME_ERROR); |
||
| 502 | } |
||
| 503 | } |
||
| 504 | if (Request::hasVar('add_mime', 'POST')) { |
||
| 505 | $helper->redirect("mimetypes.php?op=add&start=$start&limit=$limit"); |
||
| 506 | } |
||
| 507 | if (Request::hasVar('order', 'REQUEST')) { |
||
| 508 | $order = \Xmf\Request::getString('order', '', 'REQUEST'); |
||
| 509 | } else { |
||
| 510 | $order = 'ASC'; |
||
| 511 | } |
||
| 512 | if (Request::hasVar('sort', 'REQUEST')) { |
||
| 513 | $sort = \Xmf\Request::getString('sort', '', 'REQUEST'); |
||
| 514 | } else { |
||
| 515 | $sort = 'mime_name'; |
||
| 516 | } |
||
| 517 | |||
| 518 | \xoops_cp_header(); |
||
| 519 | //echo $oAdminButton->renderButtons('mimetypes'); |
||
| 520 | $adminObject = Admin::getInstance(); |
||
| 521 | $adminObject->displayNavigation(\basename(__FILE__)); |
||
| 522 | |||
| 523 | if (Request::hasVar('mime_search')) { |
||
| 524 | $search_field = $_REQUEST['search_by']; |
||
| 525 | $search_text = $_REQUEST['search_text']; |
||
| 526 | |||
| 527 | $criteria = new \Criteria($search_field, "%$search_text%", 'LIKE'); |
||
| 528 | $criteria->setSort($sort); |
||
| 529 | $criteria->setOrder($order); |
||
| 530 | $criteria->setLimit($limit); |
||
| 531 | $criteria->setStart($start); |
||
| 532 | $mime_count = $mimetypeHandler->getCount($criteria); |
||
| 533 | $mimetypes = $mimetypeHandler->getObjects($criteria); |
||
| 534 | $nav = new \XoopsPageNav($mime_count, $limit, $start, 'start', "op=search&limit=$limit&order=$order&sort=$sort&mime_search=1&search_by=$search_field&search_text=$search_text"); |
||
| 535 | // Display results |
||
| 536 | echo '<script type="text/javascript" src="' . \XHELP_BASE_URL . '/include/functions.js"></script>'; |
||
| 537 | |||
| 538 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 539 | echo "<tr><td colspan='6' align='right'>"; |
||
| 540 | echo "<form action='" . XHELP_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>"; |
||
| 541 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 542 | echo '<table>'; |
||
| 543 | echo '<tr>'; |
||
| 544 | echo "<td align='right'>" . \_AM_XHELP_TEXT_SEARCH_BY . '</td>'; |
||
| 545 | echo "<td align='left'><select name='search_by'>"; |
||
| 546 | foreach ($aSearchBy as $value => $text) { |
||
| 547 | ($search_field == $value) ? $selected = 'selected' : $selected = ''; |
||
| 548 | echo "<option value='$value' $selected>$text</option>"; |
||
| 549 | } |
||
| 550 | echo '</select></td>'; |
||
| 551 | echo "<td align='right'>" . \_AM_XHELP_TEXT_SEARCH_TEXT . '</td>'; |
||
| 552 | echo "<td align='left'><input type='text' name='search_text' id='search_text' value='" . \htmlentities($search_text, \ENT_QUOTES) . "'></td>"; |
||
| 553 | echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . \_AM_XHELP_BUTTON_SEARCH . "'></td>"; |
||
| 554 | echo '</tr></table></form></td></tr>'; |
||
| 555 | |||
| 556 | echo "<tr><td colspan='6'>"; |
||
| 557 | echo "<form action='" . XHELP_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>"; |
||
| 558 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 559 | echo "<table width='100%'>"; |
||
| 560 | echo "<tr><td align='right'>" . \_AM_XHELP_TEXT_SORT_BY . " |
||
| 561 | <select name='sort'>"; |
||
| 562 | foreach ($aSortBy as $value => $text) { |
||
| 563 | ($sort == $value) ? $selected = 'selected' : $selected = ''; |
||
| 564 | echo "<option value='$value' $selected>$text</option>"; |
||
| 565 | } |
||
| 566 | echo '</select> |
||
| 567 | |
||
| 568 | ' . \_AM_XHELP_TEXT_ORDER_BY . " |
||
| 569 | <select name='order'>"; |
||
| 570 | foreach ($aOrderBy as $value => $text) { |
||
| 571 | ($order == $value) ? $selected = 'selected' : $selected = ''; |
||
| 572 | echo "<option value='$value' $selected>$text</option>"; |
||
| 573 | } |
||
| 574 | echo '</select> |
||
| 575 | |
||
| 576 | ' . \_AM_XHELP_TEXT_NUMBER_PER_PAGE . " |
||
| 577 | <select name='limit'>"; |
||
| 578 | foreach ($aLimitBy as $value => $text) { |
||
| 579 | ($limit == $value) ? $selected = 'selected' : $selected = ''; |
||
| 580 | echo "<option value='$value' $selected>$text</option>"; |
||
| 581 | } |
||
| 582 | echo "</select> |
||
| 583 | <input type='submit' name='mime_sort' id='mime_sort' value='" . \_AM_XHELP_BUTTON_SUBMIT . "'> |
||
| 584 | <input type='hidden' name='mime_search' id='mime_search' value='1'> |
||
| 585 | <input type='hidden' name='search_by' id='search_by' value='$search_field'> |
||
| 586 | <input type='hidden' name='search_text' id='search_text' value='" . \htmlentities($search_text, \ENT_QUOTES) . "'> |
||
| 587 | </td> |
||
| 588 | </tr>"; |
||
| 589 | echo '</table>'; |
||
| 590 | echo '</td></tr>'; |
||
| 591 | if (\count($mimetypes) > 0) { |
||
| 592 | echo "<tr><th colspan='6'>" . \_AM_XHELP_TEXT_SEARCH_MIME . '</th></tr>'; |
||
| 593 | echo "<tr class='head'> |
||
| 594 | <td>" . \_AM_XHELP_MIME_ID . '</td> |
||
| 595 | <td>' . \_AM_XHELP_MIME_NAME . '</td> |
||
| 596 | <td>' . \_AM_XHELP_MIME_EXT . '</td> |
||
| 597 | <td>' . \_AM_XHELP_MIME_ADMIN . '</td> |
||
| 598 | <td>' . \_AM_XHELP_MIME_USER . '</td> |
||
| 599 | <td>' . \_AM_XHELP_MINDEX_ACTION . '</td> |
||
| 600 | </tr>'; |
||
| 601 | foreach ($mimetypes as $mime) { |
||
| 602 | echo "<tr class='even'> |
||
| 603 | <td><input type='checkbox' name='mimes[]' value='" . $mime->getVar('mime_id') . "'>" . $mime->getVar('mime_id') . '</td> |
||
| 604 | <td>' . $mime->getVar('mime_name') . '</td> |
||
| 605 | <td>' . $mime->getVar('mime_ext') . "</td> |
||
| 606 | <td> |
||
| 607 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&id=' . $mime->getVar('mime_id') . '&mime_admin=' . $mime->getVar('mime_admin') . '&limit=' . $limit . '&start=' . $start . "'> |
||
| 608 | " . ($mime->getVar('mime_admin') ? $icons['online'] : $icons['offline']) . "</a> |
||
| 609 | </td> |
||
| 610 | <td> |
||
| 611 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&id=' . $mime->getVar('mime_id') . '&mime_user=' . $mime->getVar('mime_user') . '&limit=' . $limit . '&start=' . $start . "'> |
||
| 612 | " . ($mime->getVar('mime_user') ? $icons['online'] : $icons['offline']) . "</a> |
||
| 613 | </td> |
||
| 614 | <td> |
||
| 615 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=edit&id=' . $mime->getVar('mime_id') . '&limit=' . $limit . '&start=' . $start . "'>" . $icons['edit'] . "</a> |
||
| 616 | <a href='" . XHELP_ADMIN_URL . '/mimetypes.php?op=delete&id=' . $mime->getVar('mime_id') . '&limit=' . $limit . '&start=' . $start . "'>" . $icons['delete'] . '</a> |
||
| 617 | </td> |
||
| 618 | </tr>'; |
||
| 619 | } |
||
| 620 | echo "<tr class='foot'> |
||
| 621 | <td colspan='6' valign='top'> |
||
| 622 | <a href='https://www.filext.com' style='float: right;' target='_blank'>" . \_AM_XHELP_MIME_FINDMIMETYPE . "</a> |
||
| 623 | <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);'> |
||
| 624 | <input type='submit' name='deleteMimes' id='deleteMimes' value='" . \_AM_XHELP_BUTTON_DELETE . "'> |
||
| 625 | <input type='submit' name='add_mime' id='add_mime' value='" . \_AM_XHELP_MIME_CREATEF . "' class='formButton'> |
||
| 626 | </td> |
||
| 627 | </tr>"; |
||
| 628 | } else { |
||
| 629 | echo '<tr><th>' . \_AM_XHELP_TEXT_SEARCH_MIME . '</th></tr>'; |
||
| 630 | echo "<tr class='even'> |
||
| 631 | <td>" . \_AM_XHELP_TEXT_NO_RECORDS . '</td> |
||
| 632 | </tr>'; |
||
| 633 | } |
||
| 634 | echo '</table>'; |
||
| 635 | echo "<div id='pagenav'>" . $nav->renderNav() . '</div>'; |
||
| 636 | } else { |
||
| 637 | echo "<form action='mimetypes.php?op=search' method='post'>"; |
||
| 638 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 639 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 640 | echo "<tr><th colspan='2'>" . \_AM_XHELP_TEXT_SEARCH_MIME . '</th></tr>'; |
||
| 641 | echo "<tr><td class='head' width='20%'>" . \_AM_XHELP_TEXT_SEARCH_BY . "</td> |
||
| 642 | <td class='even'> |
||
| 643 | <select name='search_by'>"; |
||
| 644 | foreach ($aSortBy as $value => $text) { |
||
| 645 | echo "<option value='$value'>$text</option>"; |
||
| 646 | } |
||
| 647 | echo '</select> |
||
| 648 | </td> |
||
| 649 | </tr>'; |
||
| 650 | echo "<tr><td class='head'>" . \_AM_XHELP_TEXT_SEARCH_TEXT . "</td> |
||
| 651 | <td class='even'> |
||
| 652 | <input type='text' name='search_text' id='search_text' value=''> |
||
| 653 | </td> |
||
| 654 | </tr>"; |
||
| 655 | echo "<tr class='foot'> |
||
| 656 | <td colspan='2'> |
||
| 657 | <input type='submit' name='mime_search' id='mime_search' value='" . \_AM_XHELP_BUTTON_SEARCH . "'> |
||
| 658 | </td> |
||
| 659 | </tr>"; |
||
| 660 | echo '</table></form>'; |
||
| 661 | } |
||
| 662 | require_once \dirname(__DIR__) . '/admin/admin_footer.php'; |
||
| 663 | } |
||
| 664 | |||
| 665 | public static function updateMimeValue(): void |
||
| 666 | { |
||
| 667 | global $mimetypeHandler; |
||
| 668 | $limit = 0; |
||
| 669 | $start = 0; |
||
| 670 | $helper = Helper::getInstance(); |
||
| 671 | $mime_id = 0; |
||
| 672 | |||
| 673 | if (Request::hasVar('limit', 'GET')) { |
||
| 674 | $limit = Request::getInt('limit', 0, 'GET'); |
||
| 675 | } |
||
| 676 | if (Request::hasVar('start', 'GET')) { |
||
| 677 | $start = Request::getInt('start', 0, 'GET'); |
||
| 678 | } |
||
| 679 | |||
| 680 | if (Request::hasVar('id')) { |
||
| 681 | $mime_id = Request::getInt('id', 0, 'REQUEST'); |
||
| 682 | } else { |
||
| 683 | $helper->redirect('admin/mimetypes.php', 3, \_AM_XHELP_MESSAGE_NO_ID); |
||
| 684 | } |
||
| 685 | |||
| 686 | $mimetype = $mimetypeHandler->get($mime_id); |
||
| 687 | |||
| 688 | if (Request::hasVar('mime_admin', 'REQUEST')) { |
||
| 689 | $mime_admin = Request::getInt('mime_admin', 0, 'REQUEST'); |
||
| 690 | $mime_admin = self::changeMimeValue($mime_admin); |
||
| 691 | $mimetype->setVar('mime_admin', $mime_admin); |
||
| 692 | } |
||
| 693 | if (Request::hasVar('mime_user', 'REQUEST')) { |
||
| 694 | $mime_user = Request::getInt('mime_user', 0, 'REQUEST'); |
||
| 695 | $mime_user = self::changeMimeValue($mime_user); |
||
| 696 | $mimetype->setVar('mime_user', $mime_user); |
||
| 697 | } |
||
| 698 | if ($mimetypeHandler->insert($mimetype, true)) { |
||
| 699 | $helper->redirect("mimetypes.php?limit=$limit&start=$start"); |
||
| 700 | } else { |
||
| 701 | $helper->redirect("mimetypes.php?limit=$limit&start=$start", 3); |
||
| 702 | } |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * @param int $mime_value |
||
| 707 | * @return int |
||
| 708 | */ |
||
| 709 | public static function changeMimeValue(int $mime_value): int |
||
| 710 | { |
||
| 711 | if (1 === $mime_value) { |
||
| 712 | $mime_value = 0; |
||
| 713 | } else { |
||
| 714 | $mime_value = 1; |
||
| 715 | } |
||
| 716 | |||
| 717 | return $mime_value; |
||
| 718 | } |
||
| 719 | |||
| 720 | public static function clearAddSessionVars(): void |
||
| 725 | } |
||
| 726 | |||
| 727 | public static function clearAddSession(): void |
||
| 728 | { |
||
| 729 | clearAddSessionVars(); |
||
| 730 | \redirect_header(Utility::createURI(XHELP_ADMIN_URL . '/mimetypes.php', ['op' => 'add'], false)); |
||
| 731 | } |
||
| 732 | |||
| 733 | /** |
||
| 734 | * @param int|string $id |
||
| 735 | */ |
||
| 736 | public static function clearEditSessionVars($id): void |
||
| 737 | { |
||
| 738 | $id = (int)$id; |
||
| 739 | $session = Session::getInstance(); |
||
| 740 | $session->del("xhelp_editMime_$id"); |
||
| 741 | $session->del("xhelp_editMimeErr_$id"); |
||
| 742 | } |
||
| 743 | |||
| 744 | public static function clearEditSession(): void |
||
| 749 | } |
||
| 750 | } |
||
| 751 |