| Total Complexity | 80 |
| Total Lines | 752 |
| Duplicated Lines | 0 % |
| Changes | 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 |
||
| 31 | class MimetypesUtility |
||
| 32 | { |
||
| 33 | public static function add() |
||
| 34 | { |
||
| 35 | /** @var Publisher\Helper $helper */ |
||
| 36 | $helper = Publisher\Helper::getInstance(); |
||
| 37 | /** @var Publisher\MimetypeHandler $mimetypeHandler */ |
||
| 38 | $mimetypeHandler = $helper->getHandler('Mimetype'); |
||
| 39 | global $limit, $start; |
||
| 40 | $error = []; |
||
| 41 | if (!Request::getString('add_mime', '', 'POST')) { |
||
|
|
|||
| 42 | Publisher\Utility::cpHeader(); |
||
| 43 | //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES); |
||
| 44 | |||
| 45 | Publisher\Utility::openCollapsableBar('mimemaddtable', 'mimeaddicon', _AM_PUBLISHER_MIME_ADD_TITLE); |
||
| 46 | |||
| 47 | $session = Publisher\Session::getInstance(); |
||
| 48 | $mimeType = $session->get('publisher_addMime'); |
||
| 49 | $mimeErrors = $session->get('publisher_addMimeErr'); |
||
| 50 | |||
| 51 | //Display any form errors |
||
| 52 | if (false === !$mimeErrors) { |
||
| 53 | Publisher\Utility::renderErrors($mimeErrors, Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'clearAddSession'])); |
||
| 54 | } |
||
| 55 | |||
| 56 | if (false === $mimeType) { |
||
| 57 | $mimeExt = ''; |
||
| 58 | $mimeName = ''; |
||
| 59 | $mimeTypes = ''; |
||
| 60 | $mimeAdmin = 1; |
||
| 61 | $mimeUser = 1; |
||
| 62 | } else { |
||
| 63 | $mimeExt = $mimeType['mime_ext']; |
||
| 64 | $mimeName = $mimeType['mime_name']; |
||
| 65 | $mimeTypes = $mimeType['mime_types']; |
||
| 66 | $mimeAdmin = $mimeType['mime_admin']; |
||
| 67 | $mimeUser = $mimeType['mime_user']; |
||
| 68 | } |
||
| 69 | |||
| 70 | // Display add form |
||
| 71 | echo "<form action='mimetypes.php?op=add' method='post'>"; |
||
| 72 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 73 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 74 | echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_CREATEF . '</th></tr>'; |
||
| 75 | echo "<tr valign='top'> |
||
| 76 | <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td> |
||
| 77 | <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mimeExt' size='5'></td> |
||
| 78 | </tr>"; |
||
| 79 | echo "<tr valign='top'> |
||
| 80 | <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td> |
||
| 81 | <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mimeName'></td> |
||
| 82 | </tr>"; |
||
| 83 | echo "<tr valign='top'> |
||
| 84 | <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td> |
||
| 85 | <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mimeTypes</textarea></td> |
||
| 86 | </tr>"; |
||
| 87 | echo "<tr valign='top'> |
||
| 88 | <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td> |
||
| 89 | <td class='even'>"; |
||
| 90 | echo "<input type='radio' name='mime_admin' value='1' " . (1 == $mimeAdmin ? 'checked' : '') . '>' . _YES; |
||
| 91 | echo "<input type='radio' name='mime_admin' value='0' " . (0 == $mimeAdmin ? 'checked' : '') . '>' . _NO . ' |
||
| 92 | </td> |
||
| 93 | </tr>'; |
||
| 94 | echo "<tr valign='top'> |
||
| 95 | <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td> |
||
| 96 | <td class='even'>"; |
||
| 97 | echo "<input type='radio' name='mime_user' value='1'" . (1 == $mimeUser ? 'checked' : '') . '>' . _YES; |
||
| 98 | echo "<input type='radio' name='mime_user' value='0'" . (0 == $mimeUser ? 'checked' : '') . '>' . _NO . ' |
||
| 99 | </td> |
||
| 100 | </tr>'; |
||
| 101 | echo "<tr valign='top'> |
||
| 102 | <td class='head'>" . _AM_PUBLISHER_MIME_MANDATORY_FIELD . "</td> |
||
| 103 | <td class='even'> |
||
| 104 | <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' class='formButton'> |
||
| 105 | <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton'> |
||
| 106 | </td> |
||
| 107 | </tr>"; |
||
| 108 | echo '</table></form>'; |
||
| 109 | // end of add form |
||
| 110 | |||
| 111 | // Find new mimetypes table |
||
| 112 | echo "<form action='http://www.filext.com' method='post'>"; |
||
| 113 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 114 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 115 | echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . '</th></tr>'; |
||
| 116 | |||
| 117 | echo "<tr class='foot'> |
||
| 118 | <td colspan='2'><input type='submit' name='find_mime' id='find_mime' value='" . _AM_PUBLISHER_MIME_FINDIT . "' class='formButton'></td> |
||
| 119 | </tr>"; |
||
| 120 | |||
| 121 | echo '</table></form>'; |
||
| 122 | |||
| 123 | Publisher\Utility::closeCollapsableBar('mimeaddtable', 'mimeaddicon'); |
||
| 124 | |||
| 125 | xoops_cp_footer(); |
||
| 126 | } else { |
||
| 127 | $hasErrors = false; |
||
| 128 | $mimeExt = Request::getString('mime_ext', '', 'POST'); |
||
| 129 | $mimeName = Request::getString('mime_name', '', 'POST'); |
||
| 130 | $mimeTypes = Request::getText('mime_types', '', 'POST'); |
||
| 131 | $mimeAdmin = Request::getInt('mime_admin', 0, 'POST'); |
||
| 132 | $mimeUser = Request::getInt('mime_user', 0, 'POST'); |
||
| 133 | |||
| 134 | //Validate Mimetype entry |
||
| 135 | if ('' === trim($mimeExt)) { |
||
| 136 | $hasErrors = true; |
||
| 137 | $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT; |
||
| 138 | } |
||
| 139 | |||
| 140 | if ('' === trim($mimeName)) { |
||
| 141 | $hasErrors = true; |
||
| 142 | $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME; |
||
| 143 | } |
||
| 144 | |||
| 145 | if ('' === trim($mimeTypes)) { |
||
| 146 | $hasErrors = true; |
||
| 147 | $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES; |
||
| 148 | } |
||
| 149 | |||
| 150 | if ($hasErrors) { |
||
| 151 | $session = Publisher\Session::getInstance(); |
||
| 152 | $mime = []; |
||
| 153 | $mime['mime_ext'] = $mimeExt; |
||
| 154 | $mime['mime_name'] = $mimeName; |
||
| 155 | $mime['mime_types'] = $mimeTypes; |
||
| 156 | $mime['mime_admin'] = $mimeAdmin; |
||
| 157 | $mime['mime_user'] = $mimeUser; |
||
| 158 | $session->set('publisher_addMime', $mime); |
||
| 159 | $session->set('publisher_addMimeErr', $error); |
||
| 160 | header('Location: ' . Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'add'], false)); |
||
| 161 | } |
||
| 162 | |||
| 163 | $mimeType = $mimetypeHandler->create(); |
||
| 164 | $mimeType->setVar('mime_ext', $mimeExt); |
||
| 165 | $mimeType->setVar('mime_name', $mimeName); |
||
| 166 | $mimeType->setVar('mime_types', $mimeTypes); |
||
| 167 | $mimeType->setVar('mime_admin', $mimeAdmin); |
||
| 168 | $mimeType->setVar('mime_user', $mimeUser); |
||
| 169 | |||
| 170 | if (!$mimetypeHandler->insert($mimeType)) { |
||
| 171 | redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_ADD_MIME_ERROR); |
||
| 172 | } else { |
||
| 173 | self::clearAddSessionVars(); |
||
| 174 | header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start"); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | public static function delete() |
||
| 180 | { |
||
| 181 | /** @var Publisher\Helper $helper */ |
||
| 182 | $helper = Publisher\Helper::getInstance(); |
||
| 183 | /** @var Publisher\MimetypeHandler $mimetypeHandler */ |
||
| 184 | $mimetypeHandler = $helper->getHandler('Mimetype'); |
||
| 185 | global $start, $limit; |
||
| 186 | $mimeId = 0; |
||
| 187 | if (0 == Request::getInt('id', 0, 'GET')) { |
||
| 188 | redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID); |
||
| 189 | } else { |
||
| 190 | $mimeId = Request::getInt('id', 0, 'GET'); |
||
| 191 | } |
||
| 192 | $mimeType = $mimetypeHandler->get($mimeId); // Retrieve mimetype object |
||
| 193 | if (!$mimetypeHandler->delete($mimeType, true)) { |
||
| 194 | redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&id=$mimeId&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR); |
||
| 195 | } else { |
||
| 196 | header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start"); |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | public static function edit() |
||
| 201 | { |
||
| 202 | /** @var Publisher\Helper $helper */ |
||
| 203 | $helper = Publisher\Helper::getInstance(); |
||
| 204 | /** @var Publisher\MimetypeHandler $mimetypeHandler */ |
||
| 205 | $mimetypeHandler = $helper->getHandler('Mimetype'); |
||
| 206 | global $start, $limit; |
||
| 207 | $mimeId = 0; |
||
| 208 | $error = []; |
||
| 209 | $hasErrors = false; |
||
| 210 | if (0 == Request::getInt('id', 0, 'GET')) { |
||
| 211 | redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID); |
||
| 212 | } else { |
||
| 213 | $mimeId = Request::getInt('id', 0, 'GET'); |
||
| 214 | } |
||
| 215 | $mimeTypeObj = $mimetypeHandler->get($mimeId); // Retrieve mimetype object |
||
| 216 | |||
| 217 | if (!Request::getString('edit_mime', '', 'POST')) { |
||
| 218 | $session = Publisher\Session::getInstance(); |
||
| 219 | $mimeType = $session->get('publisher_editMime_' . $mimeId); |
||
| 220 | $mimeErrors = $session->get('publisher_editMimeErr_' . $mimeId); |
||
| 221 | |||
| 222 | // Display header |
||
| 223 | Publisher\Utility::cpHeader(); |
||
| 224 | //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_EDIT); |
||
| 225 | |||
| 226 | Publisher\Utility::openCollapsableBar('mimemedittable', 'mimeediticon', _AM_PUBLISHER_MIME_EDIT_TITLE); |
||
| 227 | |||
| 228 | //Display any form errors |
||
| 229 | if (false === !$mimeErrors) { |
||
| 230 | Publisher\Utility::renderErrors($mimeErrors, Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'clearEditSession', 'id' => $mimeId])); |
||
| 231 | } |
||
| 232 | |||
| 233 | if (false === $mimeType) { |
||
| 234 | $mimeExt = $mimeTypeObj->getVar('mime_ext'); |
||
| 235 | $mimeName = $mimeTypeObj->getVar('mime_name', 'e'); |
||
| 236 | $mimeTypes = $mimeTypeObj->getVar('mime_types', 'e'); |
||
| 237 | $mimeAdmin = $mimeTypeObj->getVar('mime_admin'); |
||
| 238 | $mimeUser = $mimeTypeObj->getVar('mime_user'); |
||
| 239 | } else { |
||
| 240 | $mimeExt = $mimeType['mime_ext']; |
||
| 241 | $mimeName = $mimeType['mime_name']; |
||
| 242 | $mimeTypes = $mimeType['mime_types']; |
||
| 243 | $mimeAdmin = $mimeType['mime_admin']; |
||
| 244 | $mimeUser = $mimeType['mime_user']; |
||
| 245 | } |
||
| 246 | |||
| 247 | // Display edit form |
||
| 248 | echo "<form action='mimetypes.php?op=edit&id=" . $mimeId . "' method='post'>"; |
||
| 249 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 250 | echo "<input type='hidden' name='limit' value='" . $limit . "'>"; |
||
| 251 | echo "<input type='hidden' name='start' value='" . $start . "'>"; |
||
| 252 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 253 | echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_MODIFYF . '</th></tr>'; |
||
| 254 | echo "<tr valign='top'> |
||
| 255 | <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td> |
||
| 256 | <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mimeExt' size='5'></td> |
||
| 257 | </tr>"; |
||
| 258 | echo "<tr valign='top'> |
||
| 259 | <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td> |
||
| 260 | <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mimeName'></td> |
||
| 261 | </tr>"; |
||
| 262 | echo "<tr valign='top'> |
||
| 263 | <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td> |
||
| 264 | <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mimeTypes</textarea></td> |
||
| 265 | </tr>"; |
||
| 266 | echo "<tr valign='top'> |
||
| 267 | <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td> |
||
| 268 | <td class='even'> |
||
| 269 | <input type='radio' name='mime_admin' value='1' " . (1 == $mimeAdmin ? 'checked' : '') . '>' . _YES . " |
||
| 270 | <input type='radio' name='mime_admin' value='0' " . (0 == $mimeAdmin ? 'checked' : '') . '>' . _NO . ' |
||
| 271 | </td> |
||
| 272 | </tr>'; |
||
| 273 | echo "<tr valign='top'> |
||
| 274 | <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td> |
||
| 275 | <td class='even'> |
||
| 276 | <input type='radio' name='mime_user' value='1' " . (1 == $mimeUser ? 'checked' : '') . '>' . _YES . " |
||
| 277 | <input type='radio' name='mime_user' value='0' " . (0 == $mimeUser ? 'checked' : '') . '>' . _NO . ' |
||
| 278 | </td> |
||
| 279 | </tr>'; |
||
| 280 | echo "<tr valign='top'> |
||
| 281 | <td class='head'></td> |
||
| 282 | <td class='even'> |
||
| 283 | <input type='submit' name='edit_mime' id='edit_mime' value='" . _AM_PUBLISHER_BUTTON_UPDATE . "' class='formButton'> |
||
| 284 | <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton'> |
||
| 285 | </td> |
||
| 286 | </tr>"; |
||
| 287 | echo '</table></form>'; |
||
| 288 | // end of edit form |
||
| 289 | Publisher\Utility::closeCollapsableBar('mimeedittable', 'mimeediticon'); |
||
| 290 | // xoops_cp_footer(); |
||
| 291 | require_once __DIR__ . '/admin_footer.php'; |
||
| 292 | } else { |
||
| 293 | $mimeAdmin = 0; |
||
| 294 | $mimeUser = 0; |
||
| 295 | if (1 == Request::getInt('mime_admin', 0, 'POST')) { |
||
| 296 | $mimeAdmin = 1; |
||
| 297 | } |
||
| 298 | if (1 == Request::getInt('mime_user', 0, 'POST')) { |
||
| 299 | $mimeUser = 1; |
||
| 300 | } |
||
| 301 | |||
| 302 | //Validate Mimetype entry |
||
| 303 | if ('' === Request::getString('mime_ext', '', 'POST')) { |
||
| 304 | $hasErrors = true; |
||
| 305 | $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT; |
||
| 306 | } |
||
| 307 | |||
| 308 | if ('' === Request::getString('mime_name', '', 'POST')) { |
||
| 309 | $hasErrors = true; |
||
| 310 | $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME; |
||
| 311 | } |
||
| 312 | |||
| 313 | if ('' === Request::getString('mime_types', '', 'POST')) { |
||
| 314 | $hasErrors = true; |
||
| 315 | $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES; |
||
| 316 | } |
||
| 317 | |||
| 318 | if ($hasErrors) { |
||
| 319 | $session = Publisher\Session::getInstance(); |
||
| 320 | $mime = []; |
||
| 321 | $mime['mime_ext'] = Request::getString('mime_ext', '', 'POST'); |
||
| 322 | $mime['mime_name'] = Request::getString('mime_name', '', 'POST'); |
||
| 323 | $mime['mime_types'] = Request::getText('mime_types', '', 'POST'); |
||
| 324 | $mime['mime_admin'] = $mimeAdmin; |
||
| 325 | $mime['mime_user'] = $mimeUser; |
||
| 326 | $session->set('publisher_editMime_' . $mimeId, $mime); |
||
| 327 | $session->set('publisher_editMimeErr_' . $mimeId, $error); |
||
| 328 | header('Location: ' . Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'edit', 'id' => $mimeId], false)); |
||
| 329 | } |
||
| 330 | |||
| 331 | $mimeTypeObj->setVar('mime_ext', Request::getString('mime_ext', '', 'POST')); |
||
| 332 | $mimeTypeObj->setVar('mime_name', Request::getString('mime_name', '', 'POST')); |
||
| 333 | $mimeTypeObj->setVar('mime_types', Request::getText('mime_types', '', 'POST')); |
||
| 334 | $mimeTypeObj->setVar('mime_admin', $mimeAdmin); |
||
| 335 | $mimeTypeObj->setVar('mime_user', $mimeUser); |
||
| 336 | |||
| 337 | if (!$mimetypeHandler->insert($mimeTypeObj, true)) { |
||
| 338 | redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=edit&id=$mimeId", 3, _AM_PUBLISHER_MESSAGE_EDIT_MIME_ERROR); |
||
| 339 | } else { |
||
| 340 | self::clearEditSessionVars($mimeId); |
||
| 341 | header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start"); |
||
| 342 | } |
||
| 343 | } |
||
| 344 | } |
||
| 345 | |||
| 346 | public static function manage() |
||
| 491 | } |
||
| 492 | |||
| 493 | public static function search() |
||
| 494 | { |
||
| 495 | /** @var Publisher\Helper $helper */ |
||
| 496 | $helper = Publisher\Helper::getInstance(); |
||
| 497 | /** @var Publisher\MimetypeHandler $mimetypeHandler */ |
||
| 498 | $mimetypeHandler = $helper->getHandler('Mimetype'); |
||
| 499 | global $limit, $start, $imagearray, $aSearchBy, $aOrderBy, $aLimitBy, $aSortBy; |
||
| 500 | |||
| 501 | if (Request::getString('deleteMimes', '', 'POST')) { |
||
| 502 | $aMimes = Request::getArray('mimes', [], 'POST'); |
||
| 503 | |||
| 504 | $crit = new \Criteria('mime_id', '(' . implode($aMimes, ',') . ')', 'IN'); |
||
| 505 | |||
| 506 | if ($mimetypeHandler->deleteAll($crit)) { |
||
| 507 | header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start"); |
||
| 508 | } else { |
||
| 509 | redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR); |
||
| 510 | } |
||
| 511 | } |
||
| 512 | if (Request::getString('add_mime', '', 'POST')) { |
||
| 513 | // header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit"); |
||
| 514 | redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit", 3, _AM_PUBLISHER_MIME_CREATEF); |
||
| 515 | // exit(); |
||
| 516 | } |
||
| 517 | |||
| 518 | $order = Request::getString('order', 'ASC'); |
||
| 519 | $sort = Request::getString('sort', 'mime_name'); |
||
| 520 | |||
| 521 | Publisher\Utility::cpHeader(); |
||
| 522 | //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_SEARCH); |
||
| 523 | |||
| 524 | Publisher\Utility::openCollapsableBar('mimemsearchtable', 'mimesearchicon', _AM_PUBLISHER_MIME_SEARCH); |
||
| 525 | |||
| 526 | if (!Request::hasVar('mime_search')) { |
||
| 527 | echo "<form action='mimetypes.php?op=search' method='post'>"; |
||
| 528 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 529 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 530 | echo "<tr><th colspan='2'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>'; |
||
| 531 | echo "<tr><td class='head' width='20%'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . "</td> |
||
| 532 | <td class='even'> |
||
| 533 | <select name='search_by'>"; |
||
| 534 | foreach ($aSortBy as $value => $text) { |
||
| 535 | echo "<option value='$value'>$text</option>"; |
||
| 536 | } |
||
| 537 | unset($value, $text); |
||
| 538 | echo '</select> |
||
| 539 | </td> |
||
| 540 | </tr>'; |
||
| 541 | echo "<tr><td class='head'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . "</td> |
||
| 542 | <td class='even'> |
||
| 543 | <input type='text' name='search_text' id='search_text' value=''> |
||
| 544 | </td> |
||
| 545 | </tr>"; |
||
| 546 | echo "<tr class='foot'> |
||
| 547 | <td colspan='2'> |
||
| 548 | <input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "'> |
||
| 549 | </td> |
||
| 550 | </tr>"; |
||
| 551 | echo '</table></form>'; |
||
| 552 | } else { |
||
| 553 | $searchField = Request::getString('search_by', ''); |
||
| 554 | $searchField = isset($aSearchBy[$searchField]) ? $searchField : 'mime_ext'; |
||
| 555 | $searchText = Request::getString('search_text', ''); |
||
| 556 | |||
| 557 | $crit = new \Criteria($searchField, '%' . $GLOBALS['xoopsDB']->escape($searchText) . '%', 'LIKE'); |
||
| 558 | $crit->setSort($sort); |
||
| 559 | $crit->setOrder($order); |
||
| 560 | $crit->setLimit($limit); |
||
| 561 | $crit->setStart($start); |
||
| 562 | $mimeCount = $mimetypeHandler->getCount($crit); |
||
| 563 | $mimetypes = $mimetypeHandler->getObjects($crit); |
||
| 564 | $nav = new \XoopsPageNav($mimeCount, $limit, $start, 'start', "op=search&limit=$limit&order=$order&sort=$sort&mime_search=1&search_by=$searchField&search_text=" . htmlentities($searchText, ENT_QUOTES)); |
||
| 565 | // Display results |
||
| 566 | echo '<script type="text/javascript" src="' . PUBLISHER_URL . '/include/functions.js"></script>'; |
||
| 567 | |||
| 568 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
| 569 | echo "<tr><td colspan='6' align='right'>"; |
||
| 570 | echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>"; |
||
| 571 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 572 | echo '<table>'; |
||
| 573 | echo '<tr>'; |
||
| 574 | echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>'; |
||
| 575 | echo "<td align='left'><select name='search_by'>"; |
||
| 576 | foreach ($aSearchBy as $value => $text) { |
||
| 577 | ($searchField == $value) ? $selected = 'selected' : $selected = ''; |
||
| 578 | echo "<option value='$value' $selected>$text</option>"; |
||
| 579 | } |
||
| 580 | unset($value, $text); |
||
| 581 | echo '</select></td>'; |
||
| 582 | echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>'; |
||
| 583 | echo "<td align='left'><input type='text' name='search_text' id='search_text' value='" . htmlentities($searchText, ENT_QUOTES) . "'></td>"; |
||
| 584 | echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "'></td>"; |
||
| 585 | echo '</tr></table></form></td></tr>'; |
||
| 586 | |||
| 587 | echo "<tr><td colspan='6'>"; |
||
| 588 | echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>"; |
||
| 589 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 590 | echo "<table width='100%'>"; |
||
| 591 | echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . " |
||
| 592 | <select name='sort'>"; |
||
| 593 | foreach ($aSortBy as $value => $text) { |
||
| 594 | ($sort == $value) ? $selected = 'selected' : $selected = ''; |
||
| 595 | echo "<option value='$value' $selected>$text</option>"; |
||
| 596 | } |
||
| 597 | unset($value, $text); |
||
| 598 | echo '</select> |
||
| 599 | |
||
| 600 | ' . _AM_PUBLISHER_TEXT_ORDER_BY . " |
||
| 601 | <select name='order'>"; |
||
| 602 | foreach ($aOrderBy as $value => $text) { |
||
| 603 | ($order == $value) ? $selected = 'selected' : $selected = ''; |
||
| 604 | echo "<option value='$value' $selected>$text</option>"; |
||
| 605 | } |
||
| 606 | unset($value, $text); |
||
| 607 | echo '</select> |
||
| 608 | |
||
| 609 | ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . " |
||
| 610 | <select name='limit'>"; |
||
| 611 | foreach ($aLimitBy as $value => $text) { |
||
| 612 | ($limit == $value) ? $selected = 'selected' : $selected = ''; |
||
| 613 | echo "<option value='$value' $selected>$text</option>"; |
||
| 614 | } |
||
| 615 | unset($value, $text); |
||
| 616 | echo "</select> |
||
| 617 | <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "'> |
||
| 618 | <input type='hidden' name='mime_search' id='mime_search' value='1'> |
||
| 619 | <input type='hidden' name='search_by' id='search_by' value='$searchField'> |
||
| 620 | <input type='hidden' name='search_text' id='search_text' value='" . htmlentities($searchText, ENT_QUOTES) . "'> |
||
| 621 | </td> |
||
| 622 | </tr>"; |
||
| 623 | echo '</table>'; |
||
| 624 | echo '</td></tr>'; |
||
| 625 | if (count($mimetypes) > 0) { |
||
| 626 | echo "<tr><th colspan='6'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>'; |
||
| 627 | echo "<tr class='head'> |
||
| 628 | <td>" . _AM_PUBLISHER_MIME_ID . '</td> |
||
| 629 | <td>' . _AM_PUBLISHER_MIME_NAME . "</td> |
||
| 630 | <td align='center'>" . _AM_PUBLISHER_MIME_EXT . "</td> |
||
| 631 | <td align='center'>" . _AM_PUBLISHER_MIME_ADMIN . "</td> |
||
| 632 | <td align='center'>" . _AM_PUBLISHER_MIME_USER . "</td> |
||
| 633 | <td align='center'>" . _AM_PUBLISHER_MINDEX_ACTION . '</td> |
||
| 634 | </tr>'; |
||
| 635 | foreach ($mimetypes as $mime) { |
||
| 636 | echo "<tr class='even'> |
||
| 637 | <td><input type='checkbox' name='mimes[]' value='" . $mime->getVar('mime_id') . "'>" . $mime->getVar('mime_id') . '</td> |
||
| 638 | <td>' . $mime->getVar('mime_name') . "</td> |
||
| 639 | <td align='center'>" . $mime->getVar('mime_ext') . "</td> |
||
| 640 | <td align='center'> |
||
| 641 | <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&id=' . $mime->getVar('mime_id') . '&mime_admin=' . $mime->getVar('mime_admin') . '&limit=' . $limit . '&start=' . $start . "'> |
||
| 642 | " . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline']) . "</a> |
||
| 643 | </td> |
||
| 644 | <td align='center'> |
||
| 645 | <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&id=' . $mime->getVar('mime_id') . '&mime_user=' . $mime->getVar('mime_user') . '&limit=' . $limit . '&start=' . $start . "'> |
||
| 646 | " . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline']) . "</a> |
||
| 647 | </td> |
||
| 648 | <td align='center'> |
||
| 649 | <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=edit&id=' . $mime->getVar('mime_id') . '&limit=' . $limit . '&start=' . $start . "'>" . $imagearray['editimg'] . "</a> |
||
| 650 | <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=delete&id=' . $mime->getVar('mime_id') . '&limit=' . $limit . '&start=' . $start . "'>" . $imagearray['deleteimg'] . '</a> |
||
| 651 | </td> |
||
| 652 | </tr>'; |
||
| 653 | } |
||
| 654 | // unset($mime); |
||
| 655 | echo "<tr class='foot'> |
||
| 656 | <td colspan='6' valign='top'> |
||
| 657 | <a href='http://www.filext.com' style='float: right;' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a> |
||
| 658 | <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);'> |
||
| 659 | <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "'> |
||
| 660 | <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton'> |
||
| 661 | </td> |
||
| 662 | </tr>"; |
||
| 663 | } else { |
||
| 664 | echo '<tr><th>' . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>'; |
||
| 665 | echo "<tr class='even'> |
||
| 666 | <td>" . _AM_PUBLISHER_TEXT_NO_RECORDS . '</td> |
||
| 667 | </tr>'; |
||
| 668 | } |
||
| 669 | echo '</table>'; |
||
| 670 | echo "<div id='pagenav'>" . $nav->renderNav() . '</div>'; |
||
| 671 | } |
||
| 672 | Publisher\Utility::closeCollapsableBar('mimesearchtable', 'mimesearchicon'); |
||
| 673 | // require_once __DIR__ . '/admin_footer.php'; |
||
| 674 | xoops_cp_footer(); |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * confirm update to mime access, resubmit as POST, including TOKEN |
||
| 679 | */ |
||
| 680 | public static function updateMimeValue() |
||
| 681 | { |
||
| 682 | // op=updateMimeValue&id=65&mime_admin=0&limit=15&start=0 |
||
| 683 | Publisher\Utility::cpHeader(); |
||
| 684 | $hiddens = [ |
||
| 685 | 'id' => Request::getInt('id', 0, 'GET'), |
||
| 686 | 'start' => Request::getInt('start', 0, 'GET'), |
||
| 687 | 'limit' => Request::getInt('limit', 15, 'GET'), |
||
| 688 | ]; |
||
| 689 | |||
| 690 | /** @var Publisher\Helper $helper */ |
||
| 691 | $helper = Publisher\Helper::getInstance(); |
||
| 692 | /** @var Publisher\MimetypeHandler $mimetypeHandler */ |
||
| 693 | $mimeTypeObj = $helper->getHandler('Mimetype')->get($hiddens['id']); |
||
| 694 | if (Request::hasVar('mime_admin')) { |
||
| 695 | $hiddens['mime_admin'] = Request::getInt('mime_admin', 0, 'GET'); |
||
| 696 | $msg = sprintf(_AM_PUBLISHER_MIME_ACCESS_CONFIRM_ADMIN, $mimeTypeObj->getVar('mime_name')); |
||
| 697 | } else { |
||
| 698 | $hiddens['mime_user'] = Request::getInt('mime_user', 0, 'GET'); |
||
| 699 | $msg = sprintf(_AM_PUBLISHER_MIME_ACCESS_CONFIRM_USER, $mimeTypeObj->getVar('mime_name')); |
||
| 700 | } |
||
| 701 | |||
| 702 | $action = PUBLISHER_ADMIN_URL . '/mimetypes.php?op=confirmUpdateMimeValue'; |
||
| 703 | $submit = _AM_PUBLISHER_MIME_ACCESS_CONFIRM; |
||
| 704 | |||
| 705 | xoops_confirm($hiddens, $action, $msg, $submit, true); |
||
| 706 | xoops_cp_footer(); |
||
| 707 | } |
||
| 708 | |||
| 709 | public static function confirmUpdateMimeValue() |
||
| 710 | { |
||
| 711 | /** @var Publisher\Helper $helper */ |
||
| 712 | $helper = Publisher\Helper::getInstance(); |
||
| 713 | /** @var Publisher\MimetypeHandler $mimetypeHandler */ |
||
| 714 | $mimetypeHandler = $helper->getHandler('Mimetype'); |
||
| 715 | $limit = Request::getInt('limit', 0, 'POST'); |
||
| 716 | $start = Request::getInt('start', 0, 'POST'); |
||
| 717 | $mimeId = Request::getInt('id', 0, 'POST'); |
||
| 718 | if (0 === $mimeId) { |
||
| 719 | redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID); |
||
| 720 | } |
||
| 721 | |||
| 722 | $mimeTypeObj = $mimetypeHandler->get($mimeId); |
||
| 723 | |||
| 724 | if (-1 !== ($mimeAdmin = Request::getInt('mime_admin', -1, 'POST'))) { |
||
| 725 | $mimeAdmin = self::changeMimeValue($mimeAdmin); |
||
| 726 | $mimeTypeObj->setVar('mime_admin', $mimeAdmin); |
||
| 727 | } elseif (-1 !== ($mimeUser = Request::getInt('mime_user', -1, 'POST'))) { |
||
| 728 | $mimeUser = self::changeMimeValue($mimeUser); |
||
| 729 | $mimeTypeObj->setVar('mime_user', $mimeUser); |
||
| 730 | } |
||
| 731 | if ($mimetypeHandler->insert($mimeTypeObj, true)) { |
||
| 732 | header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start"); |
||
| 733 | } else { |
||
| 734 | redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3); |
||
| 735 | } |
||
| 736 | } |
||
| 737 | |||
| 738 | /** |
||
| 739 | * @param $mimeValue |
||
| 740 | * |
||
| 741 | * @return int |
||
| 742 | */ |
||
| 743 | protected static function changeMimeValue($mimeValue) |
||
| 744 | { |
||
| 745 | if (1 === (int)$mimeValue) { |
||
| 746 | $mimeValue = 0; |
||
| 747 | } else { |
||
| 748 | $mimeValue = 1; |
||
| 749 | } |
||
| 750 | |||
| 751 | return $mimeValue; |
||
| 752 | } |
||
| 753 | |||
| 754 | protected static function clearAddSessionVars() |
||
| 759 | } |
||
| 760 | |||
| 761 | public static function clearAddSession() |
||
| 762 | { |
||
| 763 | self::clearAddSessionVars(); |
||
| 764 | header('Location: ' . Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'add'], false)); |
||
| 765 | } |
||
| 766 | |||
| 767 | /** |
||
| 768 | * @param $id |
||
| 769 | */ |
||
| 770 | public static function clearEditSessionVars($id) |
||
| 776 | } |
||
| 777 | |||
| 778 | public static function clearEditSession() |
||
| 786 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths