These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | // |
||
3 | // ------------------------------------------------------------------------ // |
||
4 | // XOOPS - PHP Content Management System // |
||
5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
6 | // <http://xoops.org/> // |
||
7 | // ------------------------------------------------------------------------ // |
||
8 | // This program is free software; you can redistribute it and/or modify // |
||
9 | // it under the terms of the GNU General Public License as published by // |
||
10 | // the Free Software Foundation; either version 2 of the License, or // |
||
11 | // (at your option) any later version. // |
||
12 | // // |
||
13 | // You may not change or alter any portion of this comment or credits // |
||
14 | // of supporting developers from this source code or any supporting // |
||
15 | // source code which is considered copyrighted (c) material of the // |
||
16 | // original comment or credit authors. // |
||
17 | // // |
||
18 | // This program is distributed in the hope that it will be useful, // |
||
19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
21 | // GNU General Public License for more details. // |
||
22 | // // |
||
23 | // You should have received a copy of the GNU General Public License // |
||
24 | // along with this program; if not, write to the Free Software // |
||
25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
26 | // ------------------------------------------------------------------------ // |
||
27 | |||
28 | include dirname(dirname(__DIR__)) . '/mainfile.php'; |
||
29 | xoops_load('XoopsheadlineUtility', $xoopsModule->getVar('dirname')); |
||
30 | |||
31 | $hlman = xoops_getModuleHandler('headline'); |
||
32 | $hlid = (!empty($_GET['id']) && ((int)$_GET['id'] > 0)) ? (int)$_GET['id'] : 0; |
||
33 | |||
34 | $xoopsOption['template_main'] = 'xoopsheadline_index.tpl'; |
||
35 | include XOOPS_ROOT_PATH . '/header.php'; |
||
36 | |||
37 | $criteria = new CriteriaCompo(); |
||
38 | $criteria->add(new Criteria('headline_display', 1, '=')); |
||
39 | $criteria->add(new Criteria('headline_xml', '', '!=')); |
||
40 | View Code Duplication | switch ((int)$xoopsModuleConfig['sortby']) { |
|
0 ignored issues
–
show
|
|||
41 | case 1: |
||
42 | $criteria->setSort('headline_name'); |
||
43 | $criteria->setOrder('DESC'); |
||
44 | break; |
||
45 | case 2: |
||
46 | $criteria->setSort('headline_name'); |
||
47 | $criteria->setOrder('ASC'); |
||
48 | break; |
||
49 | case 3: |
||
50 | $criteria->setSort('headline_weight'); |
||
51 | $criteria->setOrder('DESC'); |
||
52 | break; |
||
53 | case 4: |
||
54 | default: |
||
55 | $criteria->setSort('headline_weight'); |
||
56 | $criteria->setOrder('ASC'); |
||
57 | break; |
||
58 | } |
||
59 | $headlines = $hlman->getObjects($criteria); |
||
60 | |||
61 | 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
}
}
![]() |
|||
62 | $pathIcon16 = $xoopsModule->getInfo('icons16'); |
||
63 | $moduleDirName = $xoopsModule->getVar('dirname'); |
||
64 | |||
65 | $userIsAdmin = (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) ? true : false; |
||
66 | $count = count($headlines); |
||
67 | for ($i = 0; $i < $count; $i++) { |
||
68 | $thisId = $headlines[$i]->getVar('headline_id'); |
||
69 | $editUrl = $userIsAdmin ? " <a href='" . XOOPS_URL |
||
70 | . "/modules/{$moduleDirName}/admin/main.php?op=edit&headline_id={$thisId}'><img src='" |
||
71 | . $pathIcon16 . "/edit.png' alt='" . _EDIT . "' title='" . _EDIT . "'></a>" : ''; |
||
72 | $xoopsTpl->append('feed_sites', |
||
73 | array('id' => $thisId, 'name' => $headlines[$i]->getVar('headline_name'), 'editurl' => $editUrl)); |
||
74 | } |
||
75 | $xoopsTpl->assign('lang_headlines', _MD_HEADLINES_HEADLINES); |
||
76 | if (0 == $hlid) { |
||
77 | $hlid = $headlines[0]->getVar('headline_id'); |
||
78 | } |
||
79 | if ($hlid > 0) { |
||
80 | $headline = $hlman->get($hlid); |
||
81 | if (is_object($headline)) { |
||
82 | $renderer = XoopsheadlineUtility::xoopsheadline_getrenderer($headline); |
||
83 | if (!$renderer->renderFeed()) { |
||
84 | if (2 == $xoopsConfig['debug_mode']) { |
||
85 | $xoopsTpl->assign('headline', |
||
86 | '<p>' . sprintf(_MD_HEADLINES_FAILGET, $headline->getVar('headline_name')) . '<br>' |
||
87 | . $renderer->getErrors() . '</p>'); |
||
88 | } |
||
89 | } else { |
||
90 | $xoopsTpl->assign('headline', $renderer->getFeed()); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
95 |
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.