Completed
Push — master ( ded118...cf7347 )
by Michael
02:48
created

entries_spot.php ➔ b_lxspot_show()   F

Complexity

Conditions 17
Paths 1280

Size

Total Lines 120
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 17
eloc 77
c 1
b 0
f 0
nc 1280
nop 1
dl 0
loc 120
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 14 and the first side effect is on line 11.

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
 * $Id: entries_spot.php v 1.0 18 dec 2011 Yerres Exp $
4
 * Module: Lexikon
5
 * Version: v 1.0
6
 * Release Date: 18 dec 2011
7
 * credits: hsalazar, Smartfactory, Eric Juden & ackbarr ->Project XHelp
8
 * Licence: GNU
9
 */
10
 
11
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die( 'XOOPS root path not defined' ) ;
12
13
/* This function spotlights a category, with a spotlight definition and links to others */
14
function b_lxspot_show( $options )
15
    {
16
    global $xoopsDB, $xoopsUser;
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...
17
    $myts = & MyTextSanitizer :: getInstance();
18
    xoops_load('XoopsUserUtility');
19
20
    $module_name = 'lexikon' ;
0 ignored issues
show
Unused Code introduced by
$module_name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21
    $module_handler = &xoops_gethandler('module');
22
    $lexikon = &$module_handler->getByDirname('lexikon');
23
    if (!isset($lxConfig)) {
0 ignored issues
show
Bug introduced by
The variable $lxConfig seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
24
        $config_handler = &xoops_gethandler('config');
25
        $lxConfig = &$config_handler->getConfigsByCat(0, $lexikon->getVar('mid'));
26
    }
27
28
    $gperm_handler =& xoops_gethandler('groupperm');
29
  $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
30
    $module_id = $lexikon->getVar('mid');
31
    /*$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
32
    $catids = implode(',', $allowed_cats);
33
    $catperms = " AND categoryID IN ($catids) ";*/
34
35
    $block = array();
36
37
    // To handle options in the template
38
    if ( $options[2] == 1 ) {
39
        $block['showdateask'] = 1;
40
    } else {
41
        $block['showdateask'] = 0;
42
    }
43
    if ( $options[3] == 1 ) {
44
        $block['showbylineask'] = 1;
45
    } else {
46
        $block['showbylineask'] = 0;
47
    }
48
    if ( $options[4] == 1 ) {
49
        $block['showstatsask'] = 1;
50
    } else {
51
        $block['showstatsask'] = 0;
52
    }
53
    if ( $options[5] == 'ver' ) {
54
        $block['verticaltemplate'] = 1;
55
    } else {
56
        $block['verticaltemplate'] = 0;
57
    }
58
    if ( $options[6] == 1 ) {
59
        $block['showpicask'] = 1;
60
    } else {
61
        $block['showpicask'] = 0;
62
    }
63
    
64
    // Retrieve the latest terms in the selected category
65
    $resultA = $xoopsDB -> query( "SELECT entryID, categoryID, term, definition, uid, datesub, counter, html, smiley, xcodes, breaks, comments
66
                                 FROM " . $xoopsDB -> prefix( "lxentries" ) . "
67
                                 WHERE categoryID = " . $options[0] . " AND submit = '0' AND offline = 0 AND block= 1
68
                                 ORDER BY datesub DESC",
69
                                 //ORDER BY " . $options[7] . " DESC ",
70
                                  1, 0
71
                                 );
72
                                
73
    list( $entryID, $categoryID, $term, $definition, $authorID, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $comments) = $xoopsDB->fetchRow($resultA);
0 ignored issues
show
Unused Code introduced by
The assignment to $categoryID is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $smiley is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
74
    $eID = intval($entryID);
75
    // If there's no result - which means there's no definition yet...
76
    if ($eID == 0) {
77
        $block['display'] = 0;
78
    } else {
79
        $block['display'] = 1;
80
    }
81
82
    // Retrieve the category name
83
    $resultB = $xoopsDB -> query( "SELECT name, logourl FROM ". $xoopsDB -> prefix( "lxcategories" ) . " WHERE categoryID = " . $options[0] . " " );
84
    list ( $name, $logourl ) = $xoopsDB -> fetchRow( $resultB );
85
    if ($lexikon =& $module_handler->getByDirname('lexikon')){
86
        if ( $gperm_handler -> checkRight( 'lexikon_view', $options[0], $groups, $module_id ) ){
87
            // get the items
88
            $block['userID'] = (intval( $authorID ));
89
            $block['authorname'] =    XoopsUserUtility::getUnameFromId(intval( $authorID ));
90
            $block['name']  = xoops_substr($name , 0, intval($options[9]) )  ;
91
            $block['catID'] = intval ( $options[0] );
92
            $block['catimage'] = stripslashes($logourl);
93
            $block['termID'] = intval ( $entryID );
94
            $block['title'] = $myts -> htmlSpecialChars( $term );
95
            $block['introtext'] = xoops_substr( $myts -> displayTarea( $definition, $html, 1, $xcodes, 1 ,$breaks), 0, intval($options[8]) );
96
            
97
            $block['moduledir'] = $lexikon->dirname();
98
            $block['date'] = formatTimestamp( $datesub, 'd M Y' );
99
            //$block['date'] = formatTimestamp( $datesub, $lxConfig['dateformat'] );
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
100
            $block['hits'] = intval( $counter );
101
            if (($lxConfig['com_rule'] != 0) || (($lxConfig['com_rule'] != 0) && is_object($xoopsUser))) {
102
                if ($comments != 0) {
103
                    $block['comments'] = "<a href='".XOOPS_URL."/modules/" .$lexikon->dirname(). "/entry.php?entryID=".$block['termID']."'>"._COMMENTS."&nbsp;:&nbsp; ".$comments."</a>";
104
                } else {
105
                    $block['comments'] = "<a href='".XOOPS_URL."/modules/" .$lexikon->dirname(). "/entry.php?entryID=".$block['termID']."'>"._COMMENTS."?</a>";
106
                }
107
            }
108
109
            // get the other terms
110
            $resultC = $xoopsDB -> query( "SELECT entryID, term, datesub FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE categoryID = " . $options[0] . " AND entryID != ". $block['termID'] . " AND submit = 0 AND offline = 0 AND block= 1 ORDER BY " . $options[7] . " DESC ", $options[1], 0 );
111
112
            $i = 0;
113
            while ( $myrow = $xoopsDB -> fetchArray ( $resultC )){
114
                if ( $i < $options[1]){
115
                    $morelinks = array();
116
                    $morelinks['id'] = $myrow['entryID'];
117
                    $morelinks['head']  = xoops_substr($myts -> htmlSpecialChars($myrow['term']) , 0, intval($options[9]) )  ;
118
                    
119
                    $morelinks['subdate'] = formatTimestamp( $datesub, 'd M Y' );
120
                    //$morelinks['subdate'] = formatTimestamp( $datesub, $lxConfig['dateformat'] );
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
121
                    $i++;
122
                    $block['links'][] = $morelinks;
123
                    }
124
                }
125
            } else { // if permissions are not granted
126
                $block['display'] = 0;
127
            }
128
        }
129
130
    //------------
131
132
    return $block;
133
    }
134
135
function b_lxspot_edit( $options ){
136
    global $xoopsDB;
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...
137
    $myts = & MyTextSanitizer :: getInstance();
138
    $resultcat = $xoopsDB -> query ( "SELECT categoryID, name FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY categoryID" );
139
    $form  = "<table border='0'>";
140
    $form .= "<tr><td>"._MB_LEXIKON_SELECTCAT."</td><td><select name=\"options[]\">";
141
    while (list( $categoryID, $name) = $xoopsDB->fetchRow($resultcat)){
142
        $form .= "<option value=".$categoryID." ".(($options[0]==$categoryID)?" selected='selected'":"").">$categoryID : $name</option>\n";
143
        }
144
    $form .= "</select><br /></td></tr>\n";
145
146
    $form .= "<tr><td>"._MB_LEXIKON_TERMSTOSHOW."</td><td><input type='text' name='options[]' value='" . $options[1] . "' />&nbsp; "._MB_LEXIKON_TERMS.".<br /></td></tr>";
147
148
    $form .= "<tr><td>"._MB_LEXIKON_SHOWDATE."</td><td>";
149
    $form .= "<input type='radio' name='options[2]' value='1'".(($options[2]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
150
    $form .= "<input type='radio' name='options[2]' value='0'".(($options[2]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
151
152
    $form .= "<tr><td>"._MB_LEXIKON_SHOWBYLINE."</td><td>";
153
    $form .= "<input type='radio' name='options[3]' value='1'".(($options[3]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
154
    $form .= "<input type='radio' name='options[3]' value='0'".(($options[3]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
155
    
156
    $form .= "<tr><td>"._MB_LEXIKON_SHOWSTATS."</td><td>";
157
    $form .= "<input type='radio' name='options[4]' value='1'".(($options[4]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
158
    $form .= "<input type='radio' name='options[4]' value='0'".(($options[4]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
159
160
    $form .= "<tr><td>"._MB_LEXIKON_TEMPLATE."</td><td><select name='options[]'>";
161
    $form .= "<option value='ver' ".(($options[5]=='ver')?" selected='selected'":"").">"._MB_LEXIKON_VERTICAL."</option>\n";
162
    $form .= "<option value='hor' ".(($options[5]=='hor')?" selected='selected'":"").">"._MB_LEXIKON_HORIZONTAL."</option>\n";
163
    $form .= "</select><br /></td></tr>";
164
165
    $form .= "<tr><td>"._MB_LEXIKON_SHOWPIC."</td><td>";
166
    $form .= "<input type='radio' name='options[6]' value='1'".(($options[6]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
167
    $form .= "<input type='radio' name='options[6]' value='0'".(($options[6]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
168
169
    $form .= "<tr><td>" . _MB_LEXIKON_ORDER . "</td><td>&nbsp;<select name='options[7]'>";
170
    $form .= "<option value='datesub' ".(($options[7]=='datesub')?" selected='selected'":"").">"._MB_LEXIKON_DATE."</option>\n";
171
    $form .= "<option value='counter' ".(($options[7]=='counter')?" selected='selected'":"").">"._MB_LEXIKON_HITS."</option>\n";
172
    $form .= "<option value='term' ".(($options[7]=='term')?" selected='selected'":"").">"._MB_LEXIKON_NAME."</option>\n";
173
    $form .= "</select>\n";
174
175
    $form .= "&nbsp;<tr><td style='vertical-align: top;'>" . _MB_LEXIKON_CHARS . "</td><td>&nbsp;<input type='text' name='options[8]' value='" . $myts->htmlSpecialChars($options[8]) . "' />&nbsp;" . _MB_LEXIKON_LENGTH . "";
176
    $form .= "&nbsp;<tr><td style='vertical-align: top;'>" . _MB_LEXIKON_CHARSTERM . "</td><td>&nbsp;<input type='text' name='options[9]' value='" . $myts->htmlSpecialChars($options[9]) . "' />&nbsp;" . _MB_LEXIKON_LENGTH . "";
177
178
    $form .= "</td></tr>";
179
    $form .= "</table>";
180
181
    //------------
182
183
    return $form;
184
    }
185