Completed
Branch master (da9c5e)
by Michael
03:00
created

PublisherMimetypesUtility   F

Complexity

Total Complexity 77

Size/Duplication

Total Lines 805
Duplicated Lines 20.37 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 164
loc 805
rs 1.7391
c 0
b 0
f 0
wmc 77
lcom 0
cbo 3

11 Methods

Rating   Name   Duplication   Size   Complexity  
D add() 16 140 13
A delete() 10 17 3
F edit() 21 141 16
F manage() 51 191 16
D search() 51 229 18
B updateMimeValue() 15 32 5
A changeMimeValue() 0 10 2
A clearAddSessionVars() 0 6 1
A clearAddSession() 0 5 1
A clearEditSessionVars() 0 7 1
A clearEditSession() 0 6 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like PublisherMimetypesUtility 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

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 PublisherMimetypesUtility, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 92 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Admin
16
 * @subpackage      Action
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
use \Xmf\Request;
23
24
require_once __DIR__ . '/admin_header.php';
25
xoops_load('XoopsPagenav');
26
27
//$start = $limit = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
//if (isset($_GET['limit'])) {
29
//    $limit = Request::getInt('limit', 0, 'GET');
30
//} elseif (isset($_POST['limit'])) {
31
//    $limit = Request::getInt('limit', 0, 'POST');
32
//} else {
33
//    $limit = 15;
34
//}
35
36
$start = Request::getInt('start', 0, 'GET');
37
$limit = Request::getInt('limit', Request::getInt('limit', 15, 'GET'), 'POST');
38
39
$aSortBy   = array(
40
    'mime_id'    => _AM_PUBLISHER_MIME_ID,
41
    'mime_name'  => _AM_PUBLISHER_MIME_NAME,
42
    'mime_ext'   => _AM_PUBLISHER_MIME_EXT,
43
    'mime_admin' => _AM_PUBLISHER_MIME_ADMIN,
44
    'mime_user'  => _AM_PUBLISHER_MIME_USER
45
);
46
$aOrderBy  = array('ASC' => _AM_PUBLISHER_TEXT_ASCENDING, 'DESC' => _AM_PUBLISHER_TEXT_DESCENDING);
47
$aLimitBy  = array('10' => 10, '15' => 15, '20' => 20, '25' => 25, '50' => 50, '100' => 100);
48
$aSearchBy = array('mime_id' => _AM_PUBLISHER_MIME_ID, 'mime_name' => _AM_PUBLISHER_MIME_NAME, 'mime_ext' => _AM_PUBLISHER_MIME_EXT);
49
50
$error = array();
51
52
$op = Request::getString('op', 'default', 'GET');
53
54
switch ($op) {
55
    case 'add':
56
        PublisherMimetypesUtility::add();
57
        break;
58
59
    case 'delete':
60
        delete();
61
        break;
62
63
    case 'edit':
64
        PublisherMimetypesUtility::edit();
65
        break;
66
67
    case 'search':
68
        PublisherMimetypesUtility::search();
69
        break;
70
71
    case 'updateMimeValue':
72
        PublisherMimetypesUtility::updateMimeValue();
73
        break;
74
75
    case 'clearAddSession':
76
        PublisherMimetypesUtility::clearAddSession();
77
        break;
78
79
    case 'clearEditSession':
80
        PublisherMimetypesUtility::clearEditSession();
81
        break;
82
83
    case 'manage':
84
    default:
85
        PublisherMimetypesUtility::manage();
86
        break;
87
}
88
89
/**
90
 * Class PublisherMimetypesUtility
91
 */
92
class PublisherMimetypesUtility
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
93
{
94
    public static function add()
95
    {
96
        $publisher = PublisherPublisher::getInstance();
97
        global $limit, $start;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
98
        $error = array();
99
        if (!Request::getString('add_mime', '', 'POST')) {
100
            PublisherUtility::cpHeader();
101
            //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
102
103
            PublisherUtility::openCollapsableBar('mimemaddtable', 'mimeaddicon', _AM_PUBLISHER_MIME_ADD_TITLE);
104
105
            $session    = PublisherSession::getInstance();
106
            $mimeType   = $session->get('publisher_addMime');
107
            $mimeErrors = $session->get('publisher_addMimeErr');
108
109
            //Display any form errors
110 View Code Duplication
            if (!$mimeErrors === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
                PublisherUtility::renderErrors($mimeErrors, PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'clearAddSession')));
112
            }
113
114
            if ($mimeType === false) {
115
                $mimeExt   = '';
116
                $mimeName  = '';
117
                $mimeTypes = '';
118
                $mimeAdmin = 1;
119
                $mimeUser  = 1;
120 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
                $mimeExt   = $mimeType['mime_ext'];
122
                $mimeName  = $mimeType['mime_name'];
123
                $mimeTypes = $mimeType['mime_types'];
124
                $mimeAdmin = $mimeType['mime_admin'];
125
                $mimeUser  = $mimeType['mime_user'];
126
            }
127
128
            // Display add form
129
            echo "<form action='mimetypes.php?op=add' method='post'>";
130
            echo "<table width='100%' cellspacing='1' class='outer'>";
131
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_CREATEF . '</th></tr>';
132
            echo "<tr valign='top'>
133
        <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td>
134
        <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mimeExt' size='5' /></td>
135
        </tr>";
136
            echo "<tr valign='top'>
137
        <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td>
138
        <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mimeName' /></td>
139
        </tr>";
140
            echo "<tr valign='top'>
141
        <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td>
142
        <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mimeTypes</textarea></td>
143
        </tr>";
144
            echo "<tr valign='top'>
145
        <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td>
146
        <td class='even'>";
147
            echo "<input type='radio' name='mime_admin' value='1' " . ($mimeAdmin == 1 ? 'checked' : '') . ' />' . _YES;
148
            echo "<input type='radio' name='mime_admin' value='0' " . ($mimeAdmin == 0 ? 'checked' : '') . ' />' . _NO . '
149
        </td>
150
        </tr>';
151
            echo "<tr valign='top'>
152
        <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td>
153
        <td class='even'>";
154
            echo "<input type='radio' name='mime_user' value='1'" . ($mimeUser == 1 ? 'checked' : '') . ' />' . _YES;
155
            echo "<input type='radio' name='mime_user' value='0'" . ($mimeUser == 0 ? 'checked' : '') . '/>' . _NO . '
156
        </td>
157
        </tr>';
158
            echo "<tr valign='top'>
159
        <td class='head'>" . _AM_PUBLISHER_MIME_MANDATORY_FIELD . "</td>
160
        <td class='even'>
161
        <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' class='formButton' />
162
        <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton' />
163
        </td>
164
        </tr>";
165
            echo '</table></form>';
166
            // end of add form
167
168
            // Find new mimetypes table
169
            echo "<form action='http://www.filext.com' method='post'>";
170
            echo "<table width='100%' cellspacing='1' class='outer'>";
171
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . '</th></tr>';
172
173
            echo "<tr class='foot'>
174
        <td colspan='2'><input type='submit' name='find_mime' id='find_mime' value='" . _AM_PUBLISHER_MIME_FINDIT . "' class='formButton' /></td>
175
        </tr>";
176
177
            echo '</table></form>';
178
179
            PublisherUtility::closeCollapsableBar('mimeaddtable', 'mimeaddicon');
180
181
            xoops_cp_footer();
182
        } else {
183
            $hasErrors = false;
184
            $mimeExt   = Request::getString('mime_ext', '', 'POST');
185
            $mimeName  = Request::getString('mime_name', '', 'POST');
186
            $mimeTypes = Request::getText('mime_types', '', 'POST');
187
            $mimeAdmin = Request::getInt('mime_admin', 0, 'POST');
188
            $mimeUser  = Request::getInt('mime_user', 0, 'POST');
189
190
            //Validate Mimetype entry
191
            if ('' === trim($mimeExt)) {
192
                $hasErrors           = true;
193
                $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT;
194
            }
195
196
            if ('' === trim($mimeName)) {
197
                $hasErrors            = true;
198
                $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME;
199
            }
200
201
            if ('' === trim($mimeTypes)) {
202
                $hasErrors             = true;
203
                $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES;
204
            }
205
206
            if ($hasErrors) {
207
                $session            = PublisherSession::getInstance();
208
                $mime               = array();
209
                $mime['mime_ext']   = $mimeExt;
210
                $mime['mime_name']  = $mimeName;
211
                $mime['mime_types'] = $mimeTypes;
212
                $mime['mime_admin'] = $mimeAdmin;
213
                $mime['mime_user']  = $mimeUser;
214
                $session->set('publisher_addMime', $mime);
215
                $session->set('publisher_addMimeErr', $error);
216
                header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'add'), false));
217
            }
218
219
            $mimeType = $publisher->getHandler('mimetype')->create();
220
            $mimeType->setVar('mime_ext', $mimeExt);
221
            $mimeType->setVar('mime_name', $mimeName);
222
            $mimeType->setVar('mime_types', $mimeTypes);
223
            $mimeType->setVar('mime_admin', $mimeAdmin);
224
            $mimeType->setVar('mime_user', $mimeUser);
225
226 View Code Duplication
            if (!$publisher->getHandler('mimetype')->insert($mimeType)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_ADD_MIME_ERROR);
228
            } else {
229
                self::clearAddSessionVars();
230
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
231
            }
232
        }
233
    }
234
235
    public static function delete()
236
    {
237
        $publisher = PublisherPublisher::getInstance();
238
        global $start, $limit;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
239
        $mimeId = 0;
240 View Code Duplication
        if (0 == Request::getInt('id', 0, 'GET')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
241
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
242
        } else {
243
            $mimeId = Request::getInt('id', 0, 'GET');
244
        }
245
        $mimeType = $publisher->getHandler('mimetype')->get($mimeId); // Retrieve mimetype object
246 View Code Duplication
        if (!$publisher->getHandler('mimetype')->delete($mimeType, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
247
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&id=$mimeId&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
248
        } else {
249
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
250
        }
251
    }
252
253
    public static function edit()
254
    {
255
        $publisher = PublisherPublisher::getInstance();
256
        global $start, $limit;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
257
        $mimeId    = 0;
258
        $error     = array();
259
        $hasErrors = false;
260 View Code Duplication
        if (0 == Request::getInt('id', 0, 'GET')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
261
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
262
        } else {
263
            $mimeId = Request::getInt('id', 0, 'GET');
264
        }
265
        $mimeTypeObj = $publisher->getHandler('mimetype')->get($mimeId); // Retrieve mimetype object
266
267
        if (!Request::getString('edit_mime', '', 'POST')) {
268
            $session    = PublisherSession::getInstance();
269
            $mimeType   = $session->get('publisher_editMime_' . $mimeId);
270
            $mimeErrors = $session->get('publisher_editMimeErr_' . $mimeId);
271
272
            // Display header
273
            PublisherUtility::cpHeader();
274
            //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_EDIT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
275
276
            PublisherUtility::openCollapsableBar('mimemedittable', 'mimeediticon', _AM_PUBLISHER_MIME_EDIT_TITLE);
277
278
            //Display any form errors
279 View Code Duplication
            if (!$mimeErrors === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
280
                PublisherUtility::renderErrors($mimeErrors, PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'clearEditSession', 'id' => $mimeId)));
281
            }
282
283
            if ($mimeType === false) {
284
                $mimeExt   = $mimeTypeObj->getVar('mime_ext');
285
                $mimeName  = $mimeTypeObj->getVar('mime_name', 'e');
286
                $mimeTypes = $mimeTypeObj->getVar('mime_types', 'e');
287
                $mimeAdmin = $mimeTypeObj->getVar('mime_admin');
288
                $mimeUser  = $mimeTypeObj->getVar('mime_user');
289 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
                $mimeExt   = $mimeType['mime_ext'];
291
                $mimeName  = $mimeType['mime_name'];
292
                $mimeTypes = $mimeType['mime_types'];
293
                $mimeAdmin = $mimeType['mime_admin'];
294
                $mimeUser  = $mimeType['mime_user'];
295
            }
296
297
            // Display edit form
298
            echo "<form action='mimetypes.php?op=edit&amp;id=" . $mimeId . "' method='post'>";
299
            echo "<input type='hidden' name='limit' value='" . $limit . "' />";
300
            echo "<input type='hidden' name='start' value='" . $start . "' />";
301
            echo "<table width='100%' cellspacing='1' class='outer'>";
302
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_MODIFYF . '</th></tr>';
303
            echo "<tr valign='top'>
304
        <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td>
305
        <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mimeExt' size='5' /></td>
306
        </tr>";
307
            echo "<tr valign='top'>
308
        <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td>
309
        <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mimeName' /></td>
310
        </tr>";
311
            echo "<tr valign='top'>
312
        <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td>
313
        <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mimeTypes</textarea></td>
314
        </tr>";
315
            echo "<tr valign='top'>
316
        <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td>
317
        <td class='even'>
318
        <input type='radio' name='mime_admin' value='1' " . ($mimeAdmin == 1 ? 'checked' : '') . ' />' . _YES . "
319
        <input type='radio' name='mime_admin' value='0' " . ($mimeAdmin == 0 ? 'checked' : '') . ' />' . _NO . '
320
        </td>
321
        </tr>';
322
            echo "<tr valign='top'>
323
        <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td>
324
        <td class='even'>
325
        <input type='radio' name='mime_user' value='1' " . ($mimeUser == 1 ? 'checked' : '') . ' />' . _YES . "
326
        <input type='radio' name='mime_user' value='0' " . ($mimeUser == 0 ? 'checked' : '') . ' />' . _NO . '
327
        </td>
328
        </tr>';
329
            echo "<tr valign='top'>
330
        <td class='head'></td>
331
        <td class='even'>
332
        <input type='submit' name='edit_mime' id='edit_mime' value='" . _AM_PUBLISHER_BUTTON_UPDATE . "' class='formButton' />
333
        <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton' />
334
        </td>
335
        </tr>";
336
            echo '</table></form>';
337
            // end of edit form
338
            PublisherUtility::closeCollapsableBar('mimeedittable', 'mimeediticon');
339
            //            xoops_cp_footer();
340
            require_once __DIR__ . '/admin_footer.php';
341
        } else {
342
            $mimeAdmin = 0;
343
            $mimeUser  = 0;
344
            if (1 == Request::getInt('mime_admin', 0, 'POST')) {
345
                $mimeAdmin = 1;
346
            }
347
            if (1 == Request::getInt('mime_user', 0, 'POST')) {
348
                $mimeUser = 1;
349
            }
350
351
            //Validate Mimetype entry
352
            if ('' === Request::getString('mime_ext', '', 'POST')) {
353
                $hasErrors           = true;
354
                $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT;
355
            }
356
357
            if ('' === Request::getString('mime_name', '', 'POST')) {
358
                $hasErrors            = true;
359
                $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME;
360
            }
361
362
            if ('' === Request::getString('mime_types', '', 'POST')) {
363
                $hasErrors             = true;
364
                $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES;
365
            }
366
367
            if ($hasErrors) {
368
                $session            = PublisherSession::getInstance();
369
                $mime               = array();
370
                $mime['mime_ext']   = Request::getString('mime_ext', '', 'POST');
371
                $mime['mime_name']  = Request::getString('mime_name', '', 'POST');
372
                $mime['mime_types'] = Request::getText('mime_types', '', 'POST');
373
                $mime['mime_admin'] = $mimeAdmin;
374
                $mime['mime_user']  = $mimeUser;
375
                $session->set('publisher_editMime_' . $mimeId, $mime);
376
                $session->set('publisher_editMimeErr_' . $mimeId, $error);
377
                header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'edit', 'id' => $mimeId), false));
378
            }
379
380
            $mimeTypeObj->setVar('mime_ext', Request::getString('mime_ext', '', 'POST'));
381
            $mimeTypeObj->setVar('mime_name', Request::getString('mime_name', '', 'POST'));
382
            $mimeTypeObj->setVar('mime_types', Request::getText('mime_types', '', 'POST'));
383
            $mimeTypeObj->setVar('mime_admin', $mimeAdmin);
384
            $mimeTypeObj->setVar('mime_user', $mimeUser);
385
386 View Code Duplication
            if (!$publisher->getHandler('mimetype')->insert($mimeTypeObj, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
387
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=edit&id=$mimeId", 3, _AM_PUBLISHER_MESSAGE_EDIT_MIME_ERROR);
388
            } else {
389
                self::clearEditSessionVars($mimeId);
390
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
391
            }
392
        }
393
    }
394
395
    public static function manage()
396
    {
397
        $publisher = PublisherPublisher::getInstance();
398
        global $imagearray, $start, $limit, $aSortBy, $aOrderBy, $aLimitBy, $aSearchBy;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
399
400 View Code Duplication
        if (Request::getString('deleteMimes', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
401
            $aMimes = Request::getArray('mimes', array(), 'POST');
402
403
            $crit = new Criteria('mime_id', '(' . implode($aMimes, ',') . ')', 'IN');
404
405
            if ($publisher->getHandler('mimetype')->deleteAll($crit)) {
406
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
407
            } else {
408
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
409
            }
410
        }
411 View Code Duplication
        if (Request::getString('add_mime', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
412
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
413
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit", 3, _AM_PUBLISHER_MIME_CREATEF);
414
            //        exit();
415
        }
416
        if (Request::getString('mime_search', '', 'POST')) {
417
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search");
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
418
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php?op=search', 3, _AM_PUBLISHER_MIME_SEARCH);
419
            //        exit();
420
        }
421
422
        PublisherUtility::cpHeader();
423
        ////publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES);
424
        PublisherUtility::openCollapsableBar('mimemanagetable', 'mimemanageicon', _AM_PUBLISHER_MIME_MANAGE_TITLE, _AM_PUBLISHER_MIME_INFOTEXT);
425
        $crit  = new CriteriaCompo();
426
        $order = Request::getString('order', 'ASC', 'POST');
427
        $sort  = Request::getString('sort', 'mime_ext', 'POST');
428
429
        $crit->setOrder($order);
430
        $crit->setStart($start);
431
        $crit->setLimit($limit);
432
        $crit->setSort($sort);
433
        $mimetypes = $publisher->getHandler('mimetype')->getObjects($crit); // Retrieve a list of all mimetypes
434
        $mimeCount = $publisher->getHandler('mimetype')->getCount();
435
        $nav       = new XoopsPageNav($mimeCount, $limit, $start, 'start', "op=manage&amp;limit=$limit");
436
437
        echo "<table width='100%' cellspacing='1' class='outer'>";
438
        echo "<tr><td colspan='6' align='right'>";
439
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
440
        echo '<table>';
441
        echo '<tr>';
442
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
443
        echo "<td align='left'><select name='search_by'>";
444 View Code Duplication
        foreach ($aSearchBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
445
            ($sort == $value) ? $selected = 'selected' : $selected = '';
446
            echo "<option value='$value' $selected>$text</option>";
447
        }
448
        unset($value, $text);
449
        echo '</select></td>';
450
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
451
        echo "<td align='left'><input type='text' name='search_text' id='search_text' value='' /></td>";
452
        echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "' /></td>";
453
        echo '</tr></table></form></td></tr>';
454
455
        echo "<tr><td colspan='6'>";
456
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage' style='margin:0; padding:0;' method='post'>";
457
        echo "<table width='100%'>";
458
        echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
459
    <select name='sort'>";
460 View Code Duplication
        foreach ($aSortBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
461
            ($sort == $value) ? $selected = 'selected' : $selected = '';
462
            echo "<option value='$value' $selected>$text</option>";
463
        }
464
        unset($value, $text);
465
        echo '</select>
466
    &nbsp;&nbsp;&nbsp;
467
    ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
468
    <select name='order'>";
469 View Code Duplication
        foreach ($aOrderBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
470
            ($order == $value) ? $selected = 'selected' : $selected = '';
471
            echo "<option value='$value' $selected>$text</option>";
472
        }
473
        unset($value, $text);
474
        echo '</select>
475
    &nbsp;&nbsp;&nbsp;
476
    ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . "
477
    <select name='limit'>";
478 View Code Duplication
        foreach ($aLimitBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
479
            ($limit == $value) ? $selected = 'selected' : $selected = '';
480
            echo "<option value='$value' $selected>$text</option>";
481
        }
482
        unset($value, $text);
483
        echo "</select>
484
    <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' />
485
    </td>
486
    </tr>";
487
        echo '</table>';
488
        echo '</td></tr>';
489
        echo "<tr><th colspan='6'>" . _AM_PUBLISHER_MIME_MANAGE_TITLE . '</th></tr>';
490
        echo "<tr class='head'>
491
    <td>" . _AM_PUBLISHER_MIME_ID . '</td>
492
    <td>' . _AM_PUBLISHER_MIME_NAME . "</td>
493
    <td align='center'>" . _AM_PUBLISHER_MIME_EXT . "</td>
494
    <td align='center'>" . _AM_PUBLISHER_MIME_ADMIN . "</td>
495
    <td align='center'>" . _AM_PUBLISHER_MIME_USER . "</td>
496
    <td align='center'>" . _AM_PUBLISHER_MINDEX_ACTION . '</td>
497
    </tr>';
498 View Code Duplication
        foreach ($mimetypes as $mime) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
499
            echo "<tr class='even'>
500
        <td><input type='checkbox' name='mimes[]' value='"
501
                 . $mime->getVar('mime_id')
502
                 . "' />"
503
                 . $mime->getVar('mime_id')
504
                 . '</td>
505
        <td>'
506
                 . $mime->getVar('mime_name')
507
                 . "</td>
508
        <td align='center'>"
509
                 . $mime->getVar('mime_ext')
510
                 . "</td>
511
        <td align='center'>
512
        <a href='"
513
                 . PUBLISHER_ADMIN_URL
514
                 . '/mimetypes.php?op=updateMimeValue&amp;id='
515
                 . $mime->getVar('mime_id')
516
                 . '&amp;mime_admin='
517
                 . $mime->getVar('mime_admin')
518
                 . '&amp;limit='
519
                 . $limit
520
                 . '&amp;start='
521
                 . $start
522
                 . "'>
523
        "
524
                 . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline'])
525
                 . "</a>
526
        </td>
527
        <td align='center'>
528
        <a href='"
529
                 . PUBLISHER_ADMIN_URL
530
                 . '/mimetypes.php?op=updateMimeValue&amp;id='
531
                 . $mime->getVar('mime_id')
532
                 . '&amp;mime_user='
533
                 . $mime->getVar('mime_user')
534
                 . '&amp;limit='
535
                 . $limit
536
                 . '&amp;start='
537
                 . $start
538
                 . "'>
539
        "
540
                 . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline'])
541
                 . "</a>
542
        </td>
543
        <td align='center'>
544
        <a href='"
545
                 . PUBLISHER_ADMIN_URL
546
                 . '/mimetypes.php?op=edit&amp;id='
547
                 . $mime->getVar('mime_id')
548
                 . '&amp;limit='
549
                 . $limit
550
                 . '&amp;start='
551
                 . $start
552
                 . "'>"
553
                 . $imagearray['editimg']
554
                 . "</a>
555
        <a href='"
556
                 . PUBLISHER_ADMIN_URL
557
                 . '/mimetypes.php?op=delete&amp;id='
558
                 . $mime->getVar('mime_id')
559
                 . '&amp;limit='
560
                 . $limit
561
                 . '&amp;start='
562
                 . $start
563
                 . "'>"
564
                 . $imagearray['deleteimg']
565
                 . '</a>
566
        </td>
567
        </tr>';
568
        }
569
        //        unset($mime);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
570
        echo "<tr class='foot'>
571
    <td colspan='6' valign='top'>
572
    <a href='http://www.filext.com' style='float: right;' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
573
    <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);' />
574
    <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "' />
575
    <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton' />
576
    </td>
577
    </tr>";
578
        echo '</table>';
579
        echo "<div id='staff_nav'>" . $nav->renderNav() . '</div><br>';
580
581
        PublisherUtility::closeCollapsableBar('mimemanagetable', 'mimemanageicon');
582
583
        //        xoops_cp_footer();
584
        require_once __DIR__ . '/admin_footer.php';
585
    }
586
587
    public static function search()
588
    {
589
        $publisher = PublisherPublisher::getInstance();
590
        global $limit, $start, $imagearray, $aSearchBy, $aOrderBy, $aLimitBy, $aSortBy;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
591
592 View Code Duplication
        if (Request::getString('deleteMimes', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
593
            $aMimes = Request::getArray('mimes', array(), 'POST');
594
595
            $crit = new Criteria('mime_id', '(' . implode($aMimes, ',') . ')', 'IN');
596
597
            if ($publisher->getHandler('mimetype')->deleteAll($crit)) {
598
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
599
            } else {
600
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
601
            }
602
        }
603 View Code Duplication
        if (Request::getString('add_mime', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
604
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
605
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit", 3, _AM_PUBLISHER_MIME_CREATEF);
606
            //        exit();
607
        }
608
609
        $order = Request::getString('order', 'ASC', 'POST');
610
        $sort  = Request::getString('sort', 'mime_name', 'POST');
611
612
        PublisherUtility::cpHeader();
613
        //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_SEARCH);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
614
615
        PublisherUtility::openCollapsableBar('mimemsearchtable', 'mimesearchicon', _AM_PUBLISHER_MIME_SEARCH);
616
617
        if (!Request::getString('mime_search', '', 'POST')) {
618
            echo "<form action='mimetypes.php?op=search' method='post'>";
619
            echo "<table width='100%' cellspacing='1' class='outer'>";
620
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
621
            echo "<tr><td class='head' width='20%'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . "</td>
622
        <td class='even'>
623
        <select name='search_by'>";
624
            foreach ($aSortBy as $value => $text) {
625
                echo "<option value='$value'>$text</option>";
626
            }
627
            unset($value, $text);
628
            echo '</select>
629
        </td>
630
        </tr>';
631
            echo "<tr><td class='head'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . "</td>
632
        <td class='even'>
633
        <input type='text' name='search_text' id='search_text' value='' />
634
        </td>
635
        </tr>";
636
            echo "<tr class='foot'>
637
        <td colspan='2'>
638
        <input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "' />
639
        </td>
640
        </tr>";
641
            echo '</table></form>';
642
        } else {
643
            $searchField = Request::getString('search_by', '', 'POST');
644
            $searchText  = Request::getString('search_text', '', 'POST');
645
646
            $crit = new Criteria($searchField, "%$searchText%", 'LIKE');
647
            $crit->setSort($sort);
648
            $crit->setOrder($order);
649
            $crit->setLimit($limit);
650
            $crit->setStart($start);
651
            $mimeCount = $publisher->getHandler('mimetype')->getCount($crit);
652
            $mimetypes = $publisher->getHandler('mimetype')->getObjects($crit);
653
            $nav       = new XoopsPageNav($mimeCount, $limit, $start, 'start',
654
                                          "op=search&amp;limit=$limit&amp;order=$order&amp;sort=$sort&amp;mime_search=1&amp;search_by=$searchField&amp;search_text=$searchText");
655
            // Display results
656
            echo '<script type="text/javascript" src="' . PUBLISHER_URL . '/include/functions.js"></script>';
657
658
            echo "<table width='100%' cellspacing='1' class='outer'>";
659
            echo "<tr><td colspan='6' align='right'>";
660
            echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
661
            echo '<table>';
662
            echo '<tr>';
663
            echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
664
            echo "<td align='left'><select name='search_by'>";
665 View Code Duplication
            foreach ($aSearchBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
666
                ($searchField == $value) ? $selected = 'selected' : $selected = '';
667
                echo "<option value='$value' $selected>$text</option>";
668
            }
669
            unset($value, $text);
670
            echo '</select></td>';
671
            echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
672
            echo "<td align='left'><input type='text' name='search_text' id='search_text' value='$searchText' /></td>";
673
            echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "' /></td>";
674
            echo '</tr></table></form></td></tr>';
675
676
            echo "<tr><td colspan='6'>";
677
            echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
678
            echo "<table width='100%'>";
679
            echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
680
        <select name='sort'>";
681 View Code Duplication
            foreach ($aSortBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
682
                ($sort == $value) ? $selected = 'selected' : $selected = '';
683
                echo "<option value='$value' $selected>$text</option>";
684
            }
685
            unset($value, $text);
686
            echo '</select>
687
        &nbsp;&nbsp;&nbsp;
688
        ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
689
        <select name='order'>";
690 View Code Duplication
            foreach ($aOrderBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
691
                ($order == $value) ? $selected = 'selected' : $selected = '';
692
                echo "<option value='$value' $selected>$text</option>";
693
            }
694
            unset($value, $text);
695
            echo '</select>
696
        &nbsp;&nbsp;&nbsp;
697
        ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . "
698
        <select name='limit'>";
699 View Code Duplication
            foreach ($aLimitBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
700
                ($limit == $value) ? $selected = 'selected' : $selected = '';
701
                echo "<option value='$value' $selected>$text</option>";
702
            }
703
            unset($value, $text);
704
            echo "</select>
705
        <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' />
706
        <input type='hidden' name='mime_search' id='mime_search' value='1' />
707
        <input type='hidden' name='search_by' id='search_by' value='$searchField' />
708
        <input type='hidden' name='search_text' id='search_text' value='$searchText' />
709
        </td>
710
        </tr>";
711
            echo '</table>';
712
            echo '</td></tr>';
713
            if (count($mimetypes) > 0) {
714
                echo "<tr><th colspan='6'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
715
                echo "<tr class='head'>
716
            <td>" . _AM_PUBLISHER_MIME_ID . '</td>
717
            <td>' . _AM_PUBLISHER_MIME_NAME . "</td>
718
            <td align='center'>" . _AM_PUBLISHER_MIME_EXT . "</td>
719
            <td align='center'>" . _AM_PUBLISHER_MIME_ADMIN . "</td>
720
            <td align='center'>" . _AM_PUBLISHER_MIME_USER . "</td>
721
            <td align='center'>" . _AM_PUBLISHER_MINDEX_ACTION . '</td>
722
            </tr>';
723 View Code Duplication
                foreach ($mimetypes as $mime) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
724
                    echo "<tr class='even'>
725
                <td><input type='checkbox' name='mimes[]' value='"
726
                         . $mime->getVar('mime_id')
727
                         . "' />"
728
                         . $mime->getVar('mime_id')
729
                         . '</td>
730
                <td>'
731
                         . $mime->getVar('mime_name')
732
                         . "</td>
733
                <td align='center'>"
734
                         . $mime->getVar('mime_ext')
735
                         . "</td>
736
                <td align='center'>
737
                <a href='"
738
                         . PUBLISHER_ADMIN_URL
739
                         . '/mimetypes.php?op=updateMimeValue&amp;id='
740
                         . $mime->getVar('mime_id')
741
                         . '&amp;mime_admin='
742
                         . $mime->getVar('mime_admin')
743
                         . '&amp;limit='
744
                         . $limit
745
                         . '&amp;start='
746
                         . $start
747
                         . "'>
748
                "
749
                         . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline'])
750
                         . "</a>
751
                </td>
752
                <td align='center'>
753
                <a href='"
754
                         . PUBLISHER_ADMIN_URL
755
                         . '/mimetypes.php?op=updateMimeValue&amp;id='
756
                         . $mime->getVar('mime_id')
757
                         . '&amp;mime_user='
758
                         . $mime->getVar('mime_user')
759
                         . '&amp;limit='
760
                         . $limit
761
                         . '&amp;start='
762
                         . $start
763
                         . "'>
764
                "
765
                         . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline'])
766
                         . "</a>
767
                </td>
768
                <td align='center'>
769
                <a href='"
770
                         . PUBLISHER_ADMIN_URL
771
                         . '/mimetypes.php?op=edit&amp;id='
772
                         . $mime->getVar('mime_id')
773
                         . '&amp;limit='
774
                         . $limit
775
                         . '&amp;start='
776
                         . $start
777
                         . "'>"
778
                         . $imagearray['editimg']
779
                         . "</a>
780
                <a href='"
781
                         . PUBLISHER_ADMIN_URL
782
                         . '/mimetypes.php?op=delete&amp;id='
783
                         . $mime->getVar('mime_id')
784
                         . '&amp;limit='
785
                         . $limit
786
                         . '&amp;start='
787
                         . $start
788
                         . "'>"
789
                         . $imagearray['deleteimg']
790
                         . '</a>
791
                </td>
792
                </tr>';
793
                }
794
                //                unset($mime);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
795
                echo "<tr class='foot'>
796
            <td colspan='6' valign='top'>
797
            <a href='http://www.filext.com' style='float: right;' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
798
            <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);' />
799
            <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "' />
800
            <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton' />
801
            </td>
802
            </tr>";
803
            } else {
804
                echo '<tr><th>' . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
805
                echo "<tr class='even'>
806
            <td>" . _AM_PUBLISHER_TEXT_NO_RECORDS . '</td>
807
            </tr>';
808
            }
809
            echo '</table>';
810
            echo "<div id='pagenav'>" . $nav->renderNav() . '</div>';
811
        }
812
        PublisherUtility::closeCollapsableBar('mimesearchtable', 'mimesearchicon');
813
        //        require_once __DIR__ . '/admin_footer.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
814
        xoops_cp_footer();
815
    }
816
817
    public static function updateMimeValue()
818
    {
819
        $mimeId    = 0;
820
        $publisher = PublisherPublisher::getInstance();
821
822
        $limit = Request::getInt('limit', 0, 'GET');
823
        $start = Request::getInt('start', 0, 'GET');
824
825 View Code Duplication
        if (!Request::getString('id', '', 'GET')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
826
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
827
        } else {
828
            $mimeId = Request::getInt('id', 0, 'GET');
829
        }
830
831
        $mimeTypeObj = $publisher->getHandler('mimetype')->get($mimeId);
832
833 View Code Duplication
        if ('' !== ($mimeAdmin = Request::getString('mime_admin', '', 'GET'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
834
            //            $mimeAdmin = Request::getInt('mime_admin', 0, 'GET');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
835
            $mimeAdmin = self::changeMimeValue($mimeAdmin);
836
            $mimeTypeObj->setVar('mime_admin', $mimeAdmin);
837
        }
838 View Code Duplication
        if ('' !== ($mimeUser = Request::getString('mime_user', '', 'GET'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
839
            //            $mimeUser = Request::getInt('mime_user', 0, 'GET');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
840
            $mimeUser = self::changeMimeValue($mimeUser);
841
            $mimeTypeObj->setVar('mime_user', $mimeUser);
842
        }
843
        if ($publisher->getHandler('mimetype')->insert($mimeTypeObj, true)) {
844
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
845
        } else {
846
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3);
847
        }
848
    }
849
850
    /**
851
     * @param $mimeValue
852
     *
853
     * @return int
854
     */
855
    protected static function changeMimeValue($mimeValue)
856
    {
857
        if ((int)$mimeValue === 1) {
858
            $mimeValue = 0;
859
        } else {
860
            $mimeValue = 1;
861
        }
862
863
        return $mimeValue;
864
    }
865
866
    protected static function clearAddSessionVars()
867
    {
868
        $session = PublisherSession::getInstance();
869
        $session->del('publisher_addMime');
870
        $session->del('publisher_addMimeErr');
871
    }
872
873
    public static function clearAddSession()
874
    {
875
        self::clearAddSessionVars();
876
        header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'add'), false));
877
    }
878
879
    /**
880
     * @param $id
881
     */
882
    public static function clearEditSessionVars($id)
883
    {
884
        $id      = (int)$id;
885
        $session = PublisherSession::getInstance();
886
        $session->del("publisher_editMime_$id");
887
        $session->del("publisher_editMimeErr_$id");
888
    }
889
890
    public static function clearEditSession()
891
    {
892
        $mimeid = Request::getInt('id', '', 'GET');
893
        self::clearEditSessionVars($mimeid);
894
        header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'edit', 'id' => $mimeid), false));
895
    }
896
}
897