xhp_block_latest.php ➔ b_XHP_latest_show()   B
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 27
nc 8
nop 1
dl 0
loc 33
rs 8.5806
c 0
b 0
f 0
1
<?php
2
// $Id: xhp_block_latest.php 11919 2013-08-14 14:07:10Z beckmi $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.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
// $options[0]: sorting order <DESC or ''> //
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
29
// $options[1]: num to list //
30
// $options[2]: module dirname //
31
32
/**
33
 * @param $options
34
 * @return array
35
 */
36
function b_XHP_latest_show($options)
37
{
38
    global $xoopsDB, $xoopsUser, $xoopsConfig;
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...
39
    $myts      = MyTextSanitizer::getInstance();
40
    $block     = array();
41
    $mydirname = $options[2];
42
    $mymodpath = "modules/$mydirname";
43
    include "$mymodpath/module_prefix.php";
44
    if (file_exists("$mymodpath/language/" . $xoopsConfig['language'] . '/main.php')) {
45
        include "$mymodpath/language/" . $xoopsConfig['language'] . '/main.php';
46
    } else {
47
        include "$mymodpath/language/english/main.php";
48
    }
49
    $mytablename = $xoopsDB->prefix($module_prefix . '_quiz');
0 ignored issues
show
Bug introduced by
The variable $module_prefix does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
50
    if ($xoopsUser) {
51
        $alert = '';
52
    } else {
53
        $alert = " onClick='alert(\"" . _MD_ALERTGUEST . "\")'";
54
    }
55
    $sql    = "SELECT artid, secid, title, posted, counter, display, expire FROM $mytablename WHERE display=1  ORDER BY posted $options[0] LIMIT $options[1]";
56
    $result = $xoopsDB->query($sql);
57
    while ($myrow = $xoopsDB->fetchArray($result)) {
58
        $items            = array();
59
        $items['ref']     = $mymodpath . '/index.php?op=viewarticle&amp;artid=' . $myrow['artid'];
60
        $items['title']   = $myts->makeTboxData4Show($myrow['title']);
61
        $items['posted']  = $myrow['posted'];
62
        $items['counter'] = $myrow['counter'];
63
        $items['alert']   = $alert;
64
        $block['items'][] = $items;
65
    }
66
67
    return $block;
68
}
69
70
/**
71
 * @param $options
72
 * @return string
73
 */
74
function b_XHP_latest_edit($options)
75
{
76
    $form = _MB_XHP_ITEMS_ORDER . "&nbsp;<select name='options[]'>";
77
    $form .= "<option value='DESC'";
78
    if ($options[0] === 'DESC') {
79
        $form .= " selected='selected'";
80
    }
81
    $form .= '>' . _MB_XHP_ITEMS_DESC . "</option>\n";
82
    $form .= "<option value=''";
83
    if ($options[0] === '') {
84
        $form .= " selected='selected'";
85
    }
86
    $form .= '>' . _MB_XHP_ITEMS_ASCEND . "</option>\n";
87
    $form .= "</select>\n";
88
    $form .= '&nbsp;' . _MB_XHP_ITEMS_DISP . "&nbsp;<input type='text'  size=5 name='options[]' value='" . $options[1] . "' />&nbsp;" . _MB_XHP_ITEMS_ARTCLS . '';
89
    $form .= "<input type='hidden' name='options[]' value='" . $options[2] . "'>";
90
91
    return $form;
92
}
93