Completed
Push — master ( 16a09f...2bada9 )
by Michael
01:30
created

admin/main.php (10 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
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    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
require_once __DIR__ . '/admin_header.php';
21
xoops_cp_header();
22
23
xoops_load('XoopsheadlineUtility', $xoopsModule->getVar('dirname'));
24
$op = 'list';
25
26
if (isset($_GET['op']) && ($_GET['op'] === 'delete' || $_GET['op'] === 'edit' || $_GET['op'] === 'flush')) {
27
    $op          = $_GET['op'];
28
    $headline_id = (int)$_GET['headline_id'];
29
}
30
31
/* headline_id - an array of integers
32
 * headline_display
33
 * headline_asblock
34
 */
35
//@TODO: Replace following routine by only importing known variables
36
if (isset($_POST)) {
37
    foreach ($_POST as $k => $v) {
38
        ${$k} = $v;
39
    }
40
}
41
42
switch ($op) {
43
    case 'list':
44
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
45
        $hlman    = xoops_getModuleHandler('headline');
46
        $criteria = new CriteriaCompo();
47
        $criteria->setSort('headline_weight');
48
        $criteria->setOrder('ASC');
49
        $headlines = $hlman->getObjects($criteria);
50
        $count     = count($headlines);
51
52
        global $thisModDir;
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...
53
54
        $adminObject = \Xmf\Module\Admin::getInstance();
55
        $adminObject->displayNavigation(basename(__FILE__));
56
57
        echo "\n<div style='margin-bottom: 2em;'>\n"
58
             . '<h4>'
59
             . _AM_HEADLINES_HEADLINES
60
             . "</h4>\n"
61
             . "<form name='xoopsheadline_form' action='main.php' method='post'>\n"
62
             . "  <table class='outer' style='margin: 1px;' id='hllist'>\n"
63
             . "    <thead><tr style='text-align: left;'>\n"
64
             . '      <th>'
65
             . _AM_HEADLINES_ORDER
66
             . "</th>\n"
67
             . '      <th>'
68
             . _AM_HEADLINES_SITENAME
69
             . "</th>\n"
70
             . "      <th class='center'>"
71
             . _AM_HEADLINES_CACHETIME
72
             . "</th>\n"
73
             . "      <th class='center'>"
74
             . _AM_HEADLINES_ENCODING
75
             . "</th>\n"
76
             . "      <th class='center'>"
77
             . _AM_HEADLINES_DISPLAY
78
             . "</th>\n"
79
             . "      <th class='center'>"
80
             . _AM_HEADLINES_ASBLOCK
81
             . "</th>\n"
82
             . "      <th class='center'>"
83
             . _AM_HEADLINES_ACTIONS
84
             . "</th>\n"
85
             . "      <th>&nbsp;</th>\n"
86
             . "    </tr></thead>\n";
87
        $cachetime = array(
88
            '3600'    => sprintf(_HOUR, 1),
89
            '18000'   => sprintf(_HOURS, 5),
90
            '86400'   => sprintf(_DAY, 1),
91
            '259200'  => sprintf(_DAYS, 3),
92
            '604800'  => sprintf(_WEEK, 1),
93
            '2592000' => sprintf(_MONTH, 1)
94
        );
95
        $encodings = array('utf-8' => 'UTF-8', 'iso-8859-1' => 'ISO-8859-1', 'us-ascii' => 'US-ASCII');
96
        $tdclass   = 'odd';
97
        echo '    <tbody>';
98
        for ($i = 0; $i < $count; $i++) {
99
            echo "    <tr>\n"
100
                 . "      <td class='center {$tdclass}' style='vertical-align: middle;'><input style='text-align: right;' type='text' maxlength='3' size='4' name='headline_weight[]' value='"
101
                 . $headlines[$i]->getVar('headline_weight')
102
                 . "'></td>\n"
103
                 . "      <td class='{$tdclass}' style='vertical-align: middle; padding-left: 1em;'><a href='"
104
                 . XOOPS_URL
105
                 . "/modules/{$thisModDir}/index.php?id="
106
                 . $headlines[$i]->getVar('headline_id')
107
                 . "'>"
108
                 . $headlines[$i]->getVar('headline_name')
109
                 . "</a></td>\n"
110
                 //               . "      <td class='{$tdclass}' style='vertical-align: middle; padding-left: 1em;'>" . $headlines[$i]->getVar('headline_name') . "</td>\n"
111
                 . "      <td class='center {$tdclass}' style='vertical-align: middle;'><select name=\"headline_cachetime[]\">";
112 View Code Duplication
            foreach ($cachetime as $value => $name) {
113
                $sel = ($value == $headlines[$i]->getVar('headline_cachetime')) ? " selected=\"selected\"" : '';
114
                echo "<option value=\"{$value}\"{$sel}>{$name}</option>";
115
            }
116
            echo "</select></td>\n" . "      <td class='center {$tdclass}' style='vertical-align: middle;'><select name=\"headline_encoding[]\">";
117 View Code Duplication
            foreach ($encodings as $value => $name) {
118
                $sel = ($value == $headlines[$i]->getVar('headline_encoding')) ? " selected = \"selected\"" : '';
119
                echo "<option value=\"{$value}\"{$sel}>{$name}</option>";
120
            }
121
            $chkd = (1 == $headlines[$i]->getVar('headline_display')) ? " checked=\"checked\"" : '';
122
            $chkb = (1 == $headlines[$i]->getVar('headline_asblock')) ? " checked=\"checked\"" : '';
123
            echo "</select></td>\n"
124
                 . "      <td class='center {$tdclass}' style='vertical-align: middle;'><input type=\"checkbox\" value=\"1\" name=\"headline_display["
125
                 . $headlines[$i]->getVar('headline_id')
126
                 . "]\"{$chkd}></td>\n"
127
                 . "      <td class='center {$tdclass}' style='vertical-align: middle;'><input type=\"checkbox\" value=\"1\" name=\"headline_asblock["
128
                 . $headlines[$i]->getVar('headline_id')
129
                 . "]\"{$chkb}></td>\n"
130
                 . "      <td class='center {$tdclass}' style='vertical-align: middle;'><a href='main.php?op=edit&amp;headline_id="
131
                 . $headlines[$i]->getVar('headline_id')
132
                 . "'><img src={$pathIcon16}/edit.png alt='"
133
                 . _EDIT
134
                 . "' title='"
135
                 . _EDIT
136
                 . "'></a>&nbsp;\n"
137
                 . "          <a href='main.php?op=delete&amp;headline_id="
138
                 . $headlines[$i]->getVar('headline_id')
139
                 . "'><img src={$pathIcon16}/delete.png alt='"
140
                 . _DELETE
141
                 . "' title='"
142
                 . _DELETE
143
                 . "'></a>\n"
144
                 . "          <a href='main.php?op=flush&amp;headline_id="
145
                 . $headlines[$i]->getVar('headline_id')
146
                 . "'><img src='../assets/images/reload.png' alt='"
147
                 . _AM_HEADLINES_CACHEFL
148
                 . "' title='"
149
                 . _AM_HEADLINES_CACHEFL
150
                 . "'></a>\n"
151
                 . "          <input type='hidden' name='headline_id[]' value='"
152
                 . $headlines[$i]->getVar('headline_id')
153
                 . "'>\n"
154
                 . "      </td>\n"
155
                 . "    </tr>\n";
156
            $tdclass = ('odd' === $tdclass) ? 'even' : 'odd';
157
        }
158
159
        echo "    </tbody>\n"
160
             . "    <tfoot><tr><td class='center {$tdclass}' colspan='7' style='padding: .5em;'>\n"
161
             . "      <input type='hidden' name='op' value='update'>\n"
162
             . "      <input type='submit' name='headline_submit' value='"
163
             . _AM_HEADLINES_UPDATE
164
             . "'>\n"
165
             . "    </td></tr></tfoot>\n"
166
             . "  </table>\n"
167
             . "</form>\n"
168
             . "</div>\n"
169
             . "<div style='margin-bottom: 1em;'>\n"
170
             . "<h4 style='padding-left: 1em;'>"
171
             . _AM_HEADLINES_ADDHEADL
172
             . "</h4>\n";
173
        $form = new XoopsThemeForm(_AM_HEADLINES_ADDHEADL, 'xoopsheadline_form_new', 'main.php', 'post', true);
174
        $form->addElement(new XoopsFormText(_AM_HEADLINES_SITENAME, 'headline_name', 50, 255), true);
175
        $form->addElement(new XoopsFormText(_AM_HEADLINES_URL, 'headline_url', 50, 255, 'http://'), true);
176
        $form->addElement(new XoopsFormText(_AM_HEADLINES_URLEDFXML, 'headline_rssurl', 50, 255, 'http://'), true);
177
        $form->addElement(new XoopsFormText(_AM_HEADLINES_ORDER, 'headline_weight', 4, 3, 0));
178
179
        $enc_sel = new XoopsFormSelect(_AM_HEADLINES_ENCODING, 'headline_encoding', 'utf-8');
180
        $enc_sel->addOptionArray($encodings);
181
        $form->addElement($enc_sel);
182
183
        $cache_sel = new XoopsFormSelect(_AM_HEADLINES_CACHETIME, 'headline_cachetime', 86400);
184
        $cache_sel->addOptionArray(array(
185
                                       '3600'    => _HOUR,
186
                                       '18000'   => sprintf(_HOURS, 5),
187
                                       '86400'   => _DAY,
188
                                       '259200'  => sprintf(_DAYS, 3),
189
                                       '604800'  => _WEEK,
190
                                       '2592000' => _MONTH
191
                                   ));
192
        $form->addElement($cache_sel);
193
194
        $form->insertBreak("<span style=\"font-weight: bold; line-height: 3em;\">" . _AM_HEADLINES_MAINSETT . '</span>', 'center');
195
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPLAY, 'headline_display', 1, _YES, _NO));
196
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPIMG, 'headline_mainimg', 0, _YES, _NO));
197
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPFULL, 'headline_mainfull', 0, _YES, _NO));
198
199
        $mmax_sel = new XoopsFormSelect(_AM_HEADLINES_DISPMAX, 'headline_mainmax', 10);
200
        $mmax_sel->addOptionArray(array(
201
                                      '1'  => 1,
202
                                      '5'  => 5,
203
                                      '10' => 10,
204
                                      '15' => 15,
205
                                      '20' => 20,
206
                                      '25' => 25,
207
                                      '30' => 30
208
                                  ));
209
        $form->addElement($mmax_sel);
210
211
        $form->insertBreak("<span style=\"font-weight: bold; line-height: 3em;\">" . _AM_HEADLINES_BLOCKSETT . '</span>', 'center');
212
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_ASBLOCK, 'headline_asblock', 1, _YES, _NO));
213
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPIMG, 'headline_blockimg', 0, _YES, _NO));
214
215
        $bmax_sel = new XoopsFormSelect(_AM_HEADLINES_DISPMAX, 'headline_blockmax', 5);
216
        $bmax_sel->addOptionArray(array(
217
                                      '1'  => 1,
218
                                      '5'  => 5,
219
                                      '10' => 10,
220
                                      '15' => 15,
221
                                      '20' => 20,
222
                                      '25' => 25,
223
                                      '30' => 30
224
                                  ));
225
        $form->addElement($bmax_sel);
226
227
        $form->insertBreak();
228
        $form->addElement(new XoopsFormHidden('op', 'addgo'));
229
        $form->addElement(new XoopsFormButtonTray('headline_submit', _SUBMIT));
230
        $form->display();
231
        echo "</div>\n";
232
        require_once __DIR__ . '/admin_footer.php';
233
        break;
234
    case 'update':
235
        $hlman = xoops_getModuleHandler('headline');
236
        $i     = 0;
237
        $msg   = '';
238
        foreach ($headline_id as $id) {
239
            $hl =& $hlman->get($id);
240
            if (!is_object($hl)) {
241
                $i++;
242
                continue;
243
            }
244
            $headline_display[$id] = empty($headline_display[$id]) ? 0 : $headline_display[$id];
245
            $headline_asblock[$id] = empty($headline_asblock[$id]) ? 0 : $headline_asblock[$id];
246
            $old_cachetime         = $hl->getVar('headline_cachetime');
247
            $hl->setVar('headline_cachetime', $headline_cachetime[$i]);
248
            $old_display = $hl->getVar('headline_display');
249
            $hl->setVar('headline_display', $headline_display[$id]);
250
            $hl->setVar('headline_weight', $headline_weight[$i]);
251
            $old_asblock = $hl->getVar('headline_asblock');
252
            $hl->setVar('headline_asblock', $headline_asblock[$id]);
253
            $old_encoding = $hl->getVar('headline_encoding');
254
            if (!$hlman->insert($hl)) {
255
                $msg .= '<br>' . sprintf(_AM_HEADLINES_FAILUPDATE, $hl->getVar('headline_name'));
256 View Code Duplication
            } else {
257
                if ($hl->getVar('headline_xml') === '') {
258
                    $renderer = XoopsheadlineUtility::xoopsheadline_getrenderer($hl);
259
                    if (!$renderer->updateCache()) {
260
                        xoops_error($hl->getErrors(true));
261
                        require_once __DIR__ . '/admin_footer.php';
262
                    }
263
                }
264
            }
265
            $i++;
266
        }
267
        if ($msg != '') {
268
            xoops_cp_header();
269
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
270
            xoops_error($msg);
271
            require_once __DIR__ . '/admin_footer.php';
272
            exit();
273
        }
274
        redirect_header('main.php', 2, _AM_HEADLINES_DBUPDATED);
275
        break;
276
    case 'addgo':
277
        if ($GLOBALS['xoopsSecurity']->check()) {
278
            $hlman = xoops_getModuleHandler('headline', $xoopsModule->getVar('dirname', 'n'));
279
            $hl    = $hlman->create();
280
            $hl->setVar('headline_name', $headline_name);
281
            $hl->setVar('headline_url', $headline_url);
282
            $hl->setVar('headline_rssurl', $headline_rssurl);
283
            $hl->setVar('headline_display', $headline_display);
284
            $hl->setVar('headline_weight', $headline_weight);
285
            $hl->setVar('headline_asblock', $headline_asblock);
286
            $hl->setVar('headline_encoding', $headline_encoding);
287
            $hl->setVar('headline_cachetime', $headline_cachetime);
288
            $hl->setVar('headline_mainfull', $headline_mainfull);
289
            $hl->setVar('headline_mainimg', $headline_mainimg);
290
            $hl->setVar('headline_mainmax', $headline_mainmax);
291
            $hl->setVar('headline_blockimg', $headline_blockimg);
292
            $hl->setVar('headline_blockmax', $headline_blockmax);
293
            $hl->setVar('headline_xml', $headline_blockmax);
294
            $hlIdx = $hlman->insert($hl);
295
            if (!$hlIdx) {
296
                $msg         = sprintf(_AM_HEADLINES_FAILUPDATE, $hl->getVar('headline_name'));
297
                $msg         .= '<br>' . $hl->getErrors();
298
                $adminObject = \Xmf\Module\Admin::getInstance();
299
                $adminObject->displayNavigation(basename(__FILE__));
300
                echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
301
                xoops_error($msg);
302
                require_once __DIR__ . '/admin_footer.php';
303
                exit();
304
            } else {
305
                if ($hl->getVar('headline_xml') == '') {
306
                    $hlObj    = $hlman->get($hlIdx);
307
                    $renderer = XoopsheadlineUtility::xoopsheadline_getrenderer($hlObj);
308
                    if (!$renderer->updateCache()) {
309
                        xoops_error($hlObj->getErrors(true));
310
                        require_once __DIR__ . '/admin_footer.php';
311
                    }
312
                }
313
            }
314
        } else {
315
            redirect_header('main.php', 2, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
316
        }
317
        redirect_header('main.php', 2, _AM_HEADLINES_DBUPDATED);
318
        break;
319
    case 'edit':
320 View Code Duplication
        if ($headline_id <= 0) {
0 ignored issues
show
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...
321
            $adminObject = \Xmf\Module\Admin::getInstance();
322
            $adminObject->displayNavigation(basename(__FILE__));
323
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
324
            xoops_error(_AM_HEADLINES_INVALIDID);
325
            require_once __DIR__ . '/admin_footer.php';
326
            exit();
327
        }
328
        $hlman = xoops_getModuleHandler('headline');
329
        $hl    = $hlman->get($headline_id);
330 View Code Duplication
        if (!is_object($hl)) {
331
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
332
            xoops_error(_AM_HEADLINES_OBJECTNG);
333
            require_once __DIR__ . '/admin_footer.php';
334
            exit();
335
        }
336
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
337
        $form = new XoopsThemeForm(_AM_HEADLINES_EDITHEADL, 'xoopsheadline_form', 'main.php', 'post', true);
338
        $form->addElement(new XoopsFormText(_AM_HEADLINES_SITENAME, 'headline_name', 100, 255, $hl->getVar('headline_name')), true);
339
        $form->addElement(new XoopsFormText(_AM_HEADLINES_URL, 'headline_url', 100, 255, $hl->getVar('headline_url')), true);
340
        $form->addElement(new XoopsFormText(_AM_HEADLINES_URLEDFXML, 'headline_rssurl', 100, 255, $hl->getVar('headline_rssurl')), true);
341
        $form->addElement(new XoopsFormText(_AM_HEADLINES_ORDER, 'headline_weight', 4, 3, $hl->getVar('headline_weight')));
342
343
        $enc_sel = new XoopsFormSelect(_AM_HEADLINES_ENCODING, 'headline_encoding', $hl->getVar('headline_encoding'));
344
        $enc_sel->addOptionArray(array('utf-8' => 'UTF-8', 'iso-8859-1' => 'ISO-8859-1', 'us-ascii' => 'US-ASCII'));
345
        $form->addElement($enc_sel);
346
347
        $cache_sel = new XoopsFormSelect(_AM_HEADLINES_CACHETIME, 'headline_cachetime', $hl->getVar('headline_cachetime'));
348
        $cache_sel->addOptionArray(array(
349
                                       '3600'    => _HOUR,
350
                                       '18000'   => sprintf(_HOURS, 5),
351
                                       '86400'   => _DAY,
352
                                       '259200'  => sprintf(_DAYS, 3),
353
                                       '604800'  => _WEEK,
354
                                       '2592000' => _MONTH
355
                                   ));
356
        $form->addElement($cache_sel);
357
358
        $form->insertBreak("<span style=\"font-weight: bold; line-height: 3em;\">" . _AM_HEADLINES_MAINSETT . '</span>', 'center');
359
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPLAY, 'headline_display', $hl->getVar('headline_display'), _YES, _NO));
360
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPIMG, 'headline_mainimg', $hl->getVar('headline_mainimg'), _YES, _NO));
361
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPFULL, 'headline_mainfull', $hl->getVar('headline_mainfull'), _YES, _NO));
362
363
        $mmax_sel = new XoopsFormSelect(_AM_HEADLINES_DISPMAX, 'headline_mainmax', $hl->getVar('headline_mainmax'));
364
        $mmax_sel->addOptionArray(array(
365
                                      '1'  => 1,
366
                                      '5'  => 5,
367
                                      '10' => 10,
368
                                      '15' => 15,
369
                                      '20' => 20,
370
                                      '25' => 25,
371
                                      '30' => 30
372
                                  ));
373
        $form->addElement($mmax_sel);
374
375
        $form->insertBreak("<span style=\"font-weight: bold; line-height: 3em;\">" . _AM_HEADLINES_BLOCKSETT . '</span>', 'center');
376
        $form->insertBreak(_AM_HEADLINES_BLOCKSETT);
377
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_ASBLOCK, 'headline_asblock', $hl->getVar('headline_asblock'), _YES, _NO));
378
        $form->addElement(new XoopsFormRadioYN(_AM_HEADLINES_DISPIMG, 'headline_blockimg', $hl->getVar('headline_blockimg'), _YES, _NO));
379
380
        $bmax_sel = new XoopsFormSelect(_AM_HEADLINES_DISPMAX, 'headline_blockmax', $hl->getVar('headline_blockmax'));
381
        $bmax_sel->addOptionArray(array(
382
                                      '1'  => 1,
383
                                      '5'  => 5,
384
                                      '10' => 10,
385
                                      '15' => 15,
386
                                      '20' => 20,
387
                                      '25' => 25,
388
                                      '30' => 30
389
                                  ));
390
        $form->addElement($bmax_sel);
391
392
        $form->insertBreak();
393
        $form->addElement(new XoopsFormHidden('headline_id', $hl->getVar('headline_id')));
394
        $form->addElement(new XoopsFormHidden('op', 'editgo'));
395
        $form->addElement(new XoopsFormButtonTray('headline_submit', _SUBMIT));
396
        echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4><br>';
397
        //echo '<a href="main.php">'. _AM_HEADLINES_HLMAIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$hl->getVar('headline_name').'<br><br>';
398
        $form->display();
399
        require_once __DIR__ . '/admin_footer.php';
400
        exit();
401
        break;
402
    case 'editgo':
403
        $headline_id = (int)$headline_id;
404 View Code Duplication
        if ($headline_id <= 0) {
0 ignored issues
show
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...
405
            $adminObject = \Xmf\Module\Admin::getInstance();
406
            $adminObject->displayNavigation(basename(__FILE__));
407
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
408
            xoops_error(_AM_HEADLINES_INVALIDID);
409
            require_once __DIR__ . '/admin_footer.php';
410
            exit();
411
        }
412
        $hlman = xoops_getModuleHandler('headline');
413
        $hl    =& $hlman->get($headline_id);
414 View Code Duplication
        if (!is_object($hl)) {
0 ignored issues
show
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...
415
            $adminObject = \Xmf\Module\Admin::getInstance();
416
            $adminObject->displayNavigation(basename(__FILE__));
417
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
418
            xoops_error(_AM_HEADLINES_OBJECTNG);
419
            require_once __DIR__ . '/admin_footer.php';
420
            exit();
421
        }
422
        $hl->setVar('headline_name', $headline_name);
423
        $hl->setVar('headline_url', $headline_url);
424
        $hl->setVar('headline_encoding', $headline_encoding);
425
        $hl->setVar('headline_rssurl', $headline_rssurl);
426
        $hl->setVar('headline_display', $headline_display);
427
        $hl->setVar('headline_weight', $headline_weight);
428
        $hl->setVar('headline_asblock', $headline_asblock);
429
        $hl->setVar('headline_cachetime', $headline_cachetime);
430
        $hl->setVar('headline_mainfull', $headline_mainfull);
431
        $hl->setVar('headline_mainimg', $headline_mainimg);
432
        $hl->setVar('headline_mainmax', $headline_mainmax);
433
        $hl->setVar('headline_blockimg', $headline_blockimg);
434
        $hl->setVar('headline_blockmax', $headline_blockmax);
435
436
        if (!$GLOBALS['xoopsSecurity']->check() || !$hlman->insert($hl)) {
437
            $msg         = sprintf(_AM_HEADLINES_FAILUPDATE, $hl->getVar('headline_name'));
438
            $msg         .= '<br>' . $hl->getErrors();
439
            $msg         .= '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors());
440
            $adminObject = \Xmf\Module\Admin::getInstance();
441
            $adminObject->displayNavigation(basename(__FILE__));
442
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
443
            xoops_error($msg);
444
            require_once __DIR__ . '/admin_footer.php';
445
            exit();
446 View Code Duplication
        } else {
447
            if ($hl->getVar('headline_xml') == '') {
448
                $renderer = XoopsheadlineUtility::xoopsheadline_getrenderer($hl);
449
                if (!$renderer->updateCache()) {
450
                    xoops_error($hl->getErrors(true));
451
                    require_once __DIR__ . '/admin_footer.php';
452
                }
453
            }
454
        }
455
        redirect_header('main.php', 2, _AM_HEADLINES_DBUPDATED);
456
        break;
457
    case 'delete':
458 View Code Duplication
        if ($headline_id <= 0) {
0 ignored issues
show
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...
459
            $adminObject = \Xmf\Module\Admin::getInstance();
460
            $adminObject->displayNavigation(basename(__FILE__));
461
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
462
            xoops_error(_AM_HEADLINES_INVALIDID);
463
            require_once __DIR__ . '/admin_footer.php';
464
            exit();
465
        }
466
        $hlman = xoops_getModuleHandler('headline');
467
        $hl    =& $hlman->get($headline_id);
468 View Code Duplication
        if (!is_object($hl)) {
0 ignored issues
show
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...
469
            $adminObject = \Xmf\Module\Admin::getInstance();
470
            $adminObject->displayNavigation(basename(__FILE__));
471
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
472
            xoops_error(_AM_HEADLINES_OBJECTNG);
473
            require_once __DIR__ . '/admin_footer.php';
474
            exit();
475
        }
476
        $adminObject = \Xmf\Module\Admin::getInstance();
477
        $adminObject->displayNavigation(basename(__FILE__));
478
        $name = $hl->getVar('headline_name');
479
        echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
480
        //        echo '<a href="main.php">'. _AM_HEADLINES_HLMAIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$name.'<br><br>';
481
        xoops_confirm(array('op' => 'deletego', 'headline_id' => $hl->getVar('headline_id')), 'main.php', sprintf(_AM_HEADLINES_WANTDEL, $name));
482
        require_once __DIR__ . '/admin_footer.php';
483
        break;
484
    case 'deletego':
485
        $headline_id = (int)$headline_id;
486 View Code Duplication
        if ($headline_id <= 0) {
0 ignored issues
show
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...
487
            $adminObject = \Xmf\Module\Admin::getInstance();
488
            $adminObject->displayNavigation(basename(__FILE__));
489
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
490
            xoops_error(_AM_HEADLINES_INVALIDID);
491
            require_once __DIR__ . '/admin_footer.php';
492
            exit();
493
        }
494
        $hlman = xoops_getModuleHandler('headline');
495
        $hl    =& $hlman->get($headline_id);
496 View Code Duplication
        if (!is_object($hl)) {
0 ignored issues
show
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...
497
            $adminObject = \Xmf\Module\Admin::getInstance();
498
            $adminObject->displayNavigation(basename(__FILE__));
499
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
500
            xoops_error(_AM_HEADLINES_OBJECTNG);
501
            require_once __DIR__ . '/admin_footer.php';
502
            exit();
503
        }
504
        if (!$GLOBALS['xoopsSecurity']->check() || !$hlman->delete($hl)) {
505
            $adminObject = \Xmf\Module\Admin::getInstance();
506
            $adminObject->displayNavigation(basename(__FILE__));
507
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
508
            xoops_error(sprintf(_AM_HEADLINES_FAILUPDELETE, $hl->getVar('headline_name')) . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
509
            require_once __DIR__ . '/admin_footer.php';
510
            exit();
511
        }
512
        redirect_header('main.php', 2, _AM_HEADLINES_DBUPDATED);
513
        break;
514
    case 'flush':
515 View Code Duplication
        if ($headline_id <= 0) {
0 ignored issues
show
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...
516
            $adminObject = \Xmf\Module\Admin::getInstance();
517
            $adminObject->displayNavigation(basename(__FILE__));
518
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
519
            xoops_error(_AM_HEADLINES_INVALIDID);
520
            require_once __DIR__ . '/admin_footer.php';
521
            exit();
522
        }
523
        $hlman = xoops_getModuleHandler('headline');
524
        $hl    =& $hlman->get($headline_id);
525 View Code Duplication
        if (!is_object($hl)) {
526
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
527
            xoops_error(_AM_HEADLINES_OBJECTNG);
528
            require_once __DIR__ . '/admin_footer.php';
529
            exit();
530
        }
531
        $adminObject = \Xmf\Module\Admin::getInstance();
532
        $adminObject->displayNavigation(basename(__FILE__));
533
        $name = $hl->getVar('headline_name');
534
        echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
535
        xoops_confirm(array('op' => 'flushgo', 'headline_id' => $hl->getVar('headline_id')), 'main.php', sprintf(_AM_HEADLINES_WANTFLUSH, $name));
536
        require_once __DIR__ . '/admin_footer.php';
537
        break;
538
    case 'flushgo':
539 View Code Duplication
        if ($headline_id <= 0) {
0 ignored issues
show
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...
540
            $adminObject = \Xmf\Module\Admin::getInstance();
541
            $adminObject->displayNavigation(basename(__FILE__));
542
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
543
            xoops_error(_AM_HEADLINES_INVALIDID);
544
            require_once __DIR__ . '/admin_footer.php';
545
            exit();
546
        }
547
        $hlman = xoops_getModuleHandler('headline');
548
        $hl    =& $hlman->get($headline_id);
549 View Code Duplication
        if (!is_object($hl)) {
550
            echo '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>';
551
            xoops_error(_AM_HEADLINES_OBJECTNG);
552
            require_once __DIR__ . '/admin_footer.php';
553
            exit();
554
        }
555
        if (!$GLOBALS['xoopsSecurity']->check()) {
556
            $adminObject = \Xmf\Module\Admin::getInstance();
557
            $adminObject->displayNavigation(basename(__FILE__)) . '<h4>' . _AM_HEADLINES_HEADLINES . '</h4>' . "<div style='margin: 1em;'>\n";
558
            xoops_error(sprintf(_AM_HEADLINES_FAILFLUSH, $hl->getVar('headline_name')) . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
559
            echo "</div>\n";
560
            require_once __DIR__ . '/admin_footer.php';
561
            exit();
562
        }
563
        $renderer =& XoopsheadlineUtility::xoopsheadline_getrenderer($hl);
564
        if (!$renderer->updateCache()) {
565
            xoops_error($hl->getErrors(true));
566
            require_once __DIR__ . '/admin_footer.php';
567
            exit();
568
        }
569
        redirect_header('main.php', 2, _AM_HEADLINES_CACHEUPD);
570
        break;
571
}
572