Passed
Branch master (acf800)
by Michael
02:26
created

MimetypesUtility   F

Complexity

Total Complexity 80

Size/Duplication

Total Lines 752
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 475
dl 0
loc 752
rs 2
c 0
b 0
f 0
wmc 80

12 Methods

Rating   Name   Duplication   Size   Complexity  
F manage() 0 145 16
A clearAddSessionVars() 0 5 1
A delete() 0 18 3
F edit() 0 142 16
F search() 0 182 19
A changeMimeValue() 0 9 2
A updateMimeValue() 0 27 2
C add() 0 142 13
A clearEditSessionVars() 0 6 1
A clearAddSession() 0 4 1
A confirmUpdateMimeValue() 0 26 5
A clearEditSession() 0 5 1

How to fix   Complexity   

Complex Class

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
2
3
namespace XoopsModules\Publisher;
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
 *  Publisher class
17
 *
18
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
19
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @package         Publisher
21
 * @since           1.0
22
 * @author          trabis <[email protected]>
23
 * @author          The SmartFactory <www.smartfactory.ca>
24
 */
25
26
use XoopsModules\Publisher;
27
28
/**
29
 * Class MimetypesUtility
30
 */
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')) {
0 ignored issues
show
Bug introduced by
The type XoopsModules\Publisher\Request was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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']));
0 ignored issues
show
Bug introduced by
It seems like $mimeErrors can also be of type false; however, parameter $errArray of XoopsModules\Publisher\Utility::renderErrors() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
                Publisher\Utility::renderErrors(/** @scrutinizer ignore-type */ $mimeErrors, Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'clearAddSession']));
Loading history...
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
189
        } else {
190
            $mimeId = Request::getInt('id', 0, 'GET');
191
        }
192
        $mimeType = $mimetypeHandler->get($mimeId); // Retrieve mimetype object
193
        if (!$mimetypeHandler->delete($mimeType, true)) {
0 ignored issues
show
Bug introduced by
It seems like $mimeType can also be of type boolean; however, parameter $obj of XoopsModules\Publisher\BaseObjectHandler::delete() does only seem to accept XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

193
        if (!$mimetypeHandler->delete(/** @scrutinizer ignore-type */ $mimeType, true)) {
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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]));
0 ignored issues
show
Bug introduced by
It seems like $mimeErrors can also be of type false; however, parameter $errArray of XoopsModules\Publisher\Utility::renderErrors() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

230
                Publisher\Utility::renderErrors(/** @scrutinizer ignore-type */ $mimeErrors, Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'clearEditSession', 'id' => $mimeId]));
Loading history...
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&amp;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)) {
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeObj can also be of type boolean; however, parameter $obj of XoopsModules\Publisher\BaseObjectHandler::insert() does only seem to accept XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

337
            if (!$mimetypeHandler->insert(/** @scrutinizer ignore-type */ $mimeTypeObj, true)) {
Loading history...
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()
347
    {
348
        /** @var Publisher\Helper $helper */
349
        $helper = Publisher\Helper::getInstance();
350
        /** @var Publisher\Utility $utility */
351
        $utility = new Publisher\Utility();
0 ignored issues
show
Unused Code introduced by
The assignment to $utility is dead and can be removed.
Loading history...
352
        /** @var Publisher\MimetypeHandler $mimetypeHandler */
353
        $mimetypeHandler = $helper->getHandler('Mimetype');
354
        global $imagearray, $start, $limit, $aSortBy, $aOrderBy, $aLimitBy, $aSearchBy;
355
356
        if (Request::getString('deleteMimes', '', 'POST')) {
357
            $aMimes = Request::getArray('mimes', [], 'POST');
358
359
            $crit = new \Criteria('mime_id', '(' . implode($aMimes, ',') . ')', 'IN');
0 ignored issues
show
Bug introduced by
',' of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

359
            $crit = new \Criteria('mime_id', '(' . implode($aMimes, /** @scrutinizer ignore-type */ ',') . ')', 'IN');
Loading history...
360
361
            if ($mimetypeHandler->deleteAll($crit)) {
362
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
363
            } else {
364
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
365
            }
366
        }
367
        if (Request::getString('add_mime', '', 'POST')) {
368
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
369
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit", 3, _AM_PUBLISHER_MIME_CREATEF);
370
            //        exit();
371
        }
372
        if (Request::getString('mime_search', '', 'POST')) {
373
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search");
374
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php?op=search', 3, _AM_PUBLISHER_MIME_SEARCH);
375
            //        exit();
376
        }
377
378
        Publisher\Utility::cpHeader();
379
        ////publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES);
380
        Publisher\Utility::openCollapsableBar('mimemanagetable', 'mimemanageicon', _AM_PUBLISHER_MIME_MANAGE_TITLE, _AM_PUBLISHER_MIME_INFOTEXT);
381
        $crit  = new \CriteriaCompo();
382
        $order = Request::getString('order', 'ASC', 'POST');
383
        $sort  = Request::getString('sort', 'mime_ext', 'POST');
384
385
        $crit->setOrder($order);
386
        $crit->setStart($start);
387
        $crit->setLimit($limit);
388
        $crit->setSort($sort);
389
        $mimetypes = $mimetypeHandler->getObjects($crit); // Retrieve a list of all mimetypes
390
        $mimeCount = $mimetypeHandler->getCount();
391
        $nav       = new \XoopsPageNav($mimeCount, $limit, $start, 'start', "op=manage&amp;limit=$limit");
392
393
        echo "<table width='100%' cellspacing='1' class='outer'>";
394
        echo "<tr><td colspan='6' align='right'>";
395
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
396
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
397
        echo '<table>';
398
        echo '<tr>';
399
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
400
        echo "<td align='left'><select name='search_by'>";
401
        foreach ($aSearchBy as $value => $text) {
402
            ($sort == $value) ? $selected = 'selected' : $selected = '';
403
            echo "<option value='$value' $selected>$text</option>";
404
        }
405
        unset($value, $text);
406
        echo '</select></td>';
407
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
408
        echo "<td align='left'><input type='text' name='search_text' id='search_text' value=''></td>";
409
        echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "'></td>";
410
        echo '</tr></table></form></td></tr>';
411
412
        echo "<tr><td colspan='6'>";
413
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage' style='margin:0; padding:0;' method='post'>";
414
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
415
        echo "<table width='100%'>";
416
        echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
417
    <select name='sort'>";
418
        foreach ($aSortBy as $value => $text) {
419
            ($sort == $value) ? $selected = 'selected' : $selected = '';
420
            echo "<option value='$value' $selected>$text</option>";
421
        }
422
        unset($value, $text);
423
        echo '</select>
424
    &nbsp;&nbsp;&nbsp;
425
    ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
426
    <select name='order'>";
427
        foreach ($aOrderBy as $value => $text) {
428
            ($order == $value) ? $selected = 'selected' : $selected = '';
429
            echo "<option value='$value' $selected>$text</option>";
430
        }
431
        unset($value, $text);
432
        echo '</select>
433
    &nbsp;&nbsp;&nbsp;
434
    ' . _AM_PUBLISHER_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
        unset($value, $text);
441
        echo "</select>
442
    <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "'>
443
    </td>
444
    </tr>";
445
        echo '</table>';
446
        echo '</td></tr>';
447
        echo "<tr><th colspan='6'>" . _AM_PUBLISHER_MIME_MANAGE_TITLE . '</th></tr>';
448
        echo "<tr class='head'>
449
    <td>" . _AM_PUBLISHER_MIME_ID . '</td>
450
    <td>' . _AM_PUBLISHER_MIME_NAME . "</td>
451
    <td align='center'>" . _AM_PUBLISHER_MIME_EXT . "</td>
452
    <td align='center'>" . _AM_PUBLISHER_MIME_ADMIN . "</td>
453
    <td align='center'>" . _AM_PUBLISHER_MIME_USER . "</td>
454
    <td align='center'>" . _AM_PUBLISHER_MINDEX_ACTION . '</td>
455
    </tr>';
456
        foreach ($mimetypes as $mime) {
457
            echo "<tr class='even'>
458
        <td><input type='checkbox' name='mimes[]' value='" . $mime->getVar('mime_id') . "'>" . $mime->getVar('mime_id') . '</td>
459
        <td>' . $mime->getVar('mime_name') . "</td>
460
        <td align='center'>" . $mime->getVar('mime_ext') . "</td>
461
        <td align='center'>
462
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_admin=' . $mime->getVar('mime_admin') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>
463
        " . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline']) . "</a>
464
        </td>
465
        <td align='center'>
466
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_user=' . $mime->getVar('mime_user') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>
467
        " . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline']) . "</a>
468
        </td>
469
        <td align='center'>
470
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=edit&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['editimg'] . "</a>
471
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=delete&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['deleteimg'] . '</a>
472
        </td>
473
        </tr>';
474
        }
475
        //        unset($mime);
476
        echo "<tr class='foot'>
477
    <td colspan='6' valign='top'>
478
    <a href='http://www.filext.com' style='float: right;' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
479
    <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);'>
480
    <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "'>
481
    <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton'>
482
    </td>
483
    </tr>";
484
        echo '</table>';
485
        echo "<div id='staff_nav'>" . $nav->renderNav() . '</div><br>';
486
487
        Publisher\Utility::closeCollapsableBar('mimemanagetable', 'mimemanageicon');
488
489
        //        xoops_cp_footer();
490
        require_once __DIR__ . '/admin_footer.php';
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');
0 ignored issues
show
Bug introduced by
',' of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

504
            $crit = new \Criteria('mime_id', '(' . implode($aMimes, /** @scrutinizer ignore-type */ ',') . ')', 'IN');
Loading history...
505
506
            if ($mimetypeHandler->deleteAll($crit)) {
507
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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&amp;limit=$limit&amp;order=$order&amp;sort=$sort&amp;mime_search=1&amp;search_by=$searchField&amp;search_text=" . htmlentities($searchText, ENT_QUOTES));
565
            // Display results
566
            echo '<script type="text/javascript" src="' . PUBLISHER_URL . '/include/functions.js"></script>';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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
        &nbsp;&nbsp;&nbsp;
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
        &nbsp;&nbsp;&nbsp;
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&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_admin=' . $mime->getVar('mime_admin') . '&amp;limit=' . $limit . '&amp;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&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_user=' . $mime->getVar('mime_user') . '&amp;limit=' . $limit . '&amp;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&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['editimg'] . "</a>
650
                <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=delete&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;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'));
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeObj->getVar('mime_name') can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

696
            $msg                   = sprintf(_AM_PUBLISHER_MIME_ACCESS_CONFIRM_ADMIN, /** @scrutinizer ignore-type */ $mimeTypeObj->getVar('mime_name'));
Loading history...
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';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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)) {
0 ignored issues
show
Bug introduced by
It seems like $mimeTypeObj can also be of type boolean; however, parameter $obj of XoopsModules\Publisher\BaseObjectHandler::insert() does only seem to accept XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

731
        if ($mimetypeHandler->insert(/** @scrutinizer ignore-type */ $mimeTypeObj, true)) {
Loading history...
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()
755
    {
756
        $session = Publisher\Session::getInstance();
757
        $session->del('publisher_addMime');
758
        $session->del('publisher_addMimeErr');
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));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
765
    }
766
767
    /**
768
     * @param $id
769
     */
770
    public static function clearEditSessionVars($id)
771
    {
772
        $id      = (int)$id;
773
        $session = Publisher\Session::getInstance();
774
        $session->del("publisher_editMime_$id");
775
        $session->del("publisher_editMimeErr_$id");
776
    }
777
778
    public static function clearEditSession()
779
    {
780
        $mimeid = Request::getInt('id', '', 'GET');
781
        self::clearEditSessionVars($mimeid);
782
        header('Location: ' . Publisher\Utility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'edit', 'id' => $mimeid], false));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_ADMIN_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
783
    }
784
}
785
786