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 | include __DIR__ . '/../../mainfile.php'; |
||
21 | xoops_load('XoopsheadlineUtility', $xoopsModule->getVar('dirname')); |
||
22 | |||
23 | $hlman = xoops_getModuleHandler('headline'); |
||
24 | $hlid = (!empty($_GET['id']) && ((int)$_GET['id'] > 0)) ? (int)$_GET['id'] : 0; |
||
25 | |||
26 | $GLOBALS['xoopsOption']['template_main'] = 'xoopsheadline_index.tpl'; |
||
27 | include XOOPS_ROOT_PATH . '/header.php'; |
||
28 | |||
29 | $criteria = new CriteriaCompo(); |
||
30 | $criteria->add(new Criteria('headline_display', 1, '=')); |
||
31 | $criteria->add(new Criteria('headline_xml', '', '!=')); |
||
32 | View Code Duplication | switch ((int)$xoopsModuleConfig['sortby']) { |
|
0 ignored issues
–
show
|
|||
33 | case 1: |
||
34 | $criteria->setSort('headline_name'); |
||
35 | $criteria->setOrder('DESC'); |
||
36 | break; |
||
37 | case 2: |
||
38 | $criteria->setSort('headline_name'); |
||
39 | $criteria->setOrder('ASC'); |
||
40 | break; |
||
41 | case 3: |
||
42 | $criteria->setSort('headline_weight'); |
||
43 | $criteria->setOrder('DESC'); |
||
44 | break; |
||
45 | case 4: |
||
46 | default: |
||
47 | $criteria->setSort('headline_weight'); |
||
48 | $criteria->setOrder('ASC'); |
||
49 | break; |
||
50 | } |
||
51 | $headlines = $hlman->getObjects($criteria); |
||
52 | |||
53 | global $xoopsModule; |
||
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
54 | $pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16);; |
||
55 | $moduleDirName = $xoopsModule->getVar('dirname'); |
||
56 | |||
57 | $userIsAdmin = (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) ? true : false; |
||
58 | $count = count($headlines); |
||
59 | for ($i = 0; $i < $count; $i++) { |
||
60 | $thisId = $headlines[$i]->getVar('headline_id'); |
||
61 | $editUrl = $userIsAdmin ? " <a href='" . XOOPS_URL . "/modules/{$moduleDirName}/admin/main.php?op=edit&headline_id={$thisId}'><img src='" . $pathIcon16 . "/edit.png' alt='" . _EDIT . "' title='" . _EDIT . "'></a>" : ''; |
||
62 | $xoopsTpl->append('feed_sites', array('id' => $thisId, 'name' => $headlines[$i]->getVar('headline_name'), 'editurl' => $editUrl)); |
||
63 | } |
||
64 | $xoopsTpl->assign('lang_headlines', _MD_HEADLINES_HEADLINES); |
||
65 | if (0 == $hlid) { |
||
66 | $hlid = $headlines[0]->getVar('headline_id'); |
||
67 | } |
||
68 | if ($hlid > 0) { |
||
69 | $headline = $hlman->get($hlid); |
||
70 | if (is_object($headline)) { |
||
71 | $renderer = XoopsheadlineUtility::xoopsheadline_getrenderer($headline); |
||
72 | if (!$renderer->renderFeed()) { |
||
73 | if (2 == $xoopsConfig['debug_mode']) { |
||
74 | $xoopsTpl->assign('headline', '<p>' . sprintf(_MD_HEADLINES_FAILGET, $headline->getVar('headline_name')) . '<br>' . $renderer->getErrors() . '</p>'); |
||
75 | } |
||
76 | } else { |
||
77 | $xoopsTpl->assign('headline', $renderer->getFeed()); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
82 |
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.