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

entries_new.php ➔ b_lxentries_new_show()   F

Complexity

Conditions 12
Paths 1024

Size

Total Lines 48
Code Lines 35

Duplication

Lines 48
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 35
c 1
b 0
f 0
nc 1024
nop 1
dl 48
loc 48
rs 2.5843

How to fix   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 13 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_new.php v 1.0 8 May 2004 hsalazar Exp $
4
 * Module: Lexikon - glossary module
5
 * Version: v 1.00
6
 * Release Date: 8 May 2004
7
 * Author: hsalazar
8
 * Licence: GNU
9
 */
10
11
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die( 'XOOPS root path not defined' ) ;
12
13 View Code Duplication
function b_lxentries_new_show( $options ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
14
    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...
15
16
    $myts = & MyTextSanitizer :: getInstance();
17
18
    $module_handler = &xoops_gethandler('module');
19
    $lexikon = &$module_handler->getByDirname('lexikon');
20
    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...
21
        $config_handler = &xoops_gethandler('config');
22
        $lxConfig = &$config_handler->getConfigsByCat(0, $lexikon->getVar('mid'));
23
    }
24
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
25
    $gperm_handler =& xoops_gethandler('groupperm');
26
    $module_id = $lexikon->getVar('mid');
27
    $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
28
    $catids = implode(',', $allowed_cats);
29
    $catperms = " AND categoryID IN ($catids) ";
30
    
31
    $words = $xoopsDB -> query( "SELECT entryID FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE offline = '0' AND submit='0' AND request='0' AND block = '1' " );
32
    $totalwords = $xoopsDB -> getRowsNum( $words );
33
34
    $block = array();
35
    $block['marquee'] = ($options[2]==1)? 1:0;
36
    $block['alternate'] = ($options[3]==1)? 1:0;
37
    $block['showdate'] = ($options[4]==1)? 1:0;
38
    $block['direction'] = $options[5];
39
    $block['speed'] = isset($options[6]) && $options[6] != '' ?  $options[6] : '2';
40
    $block['bgcolor'] = isset($options[7]) && $options[7] != '' ?  $options[7] : '#FFFFFF';
41
    
42
    $sql = "SELECT entryID, categoryID, term, datesub FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE datesub < ".time()." AND datesub > 0 AND offline = '0' ".$catperms." ORDER BY " . $options[0] . " DESC";
43
    $result = $xoopsDB->query ($sql, $options[1], 0);
44
45
    if ( $totalwords > 0 ) // If there are definitions
46
    {
47
        while (list( $entryID, $categoryID, $term, $datesub ) = $xoopsDB->fetchRow($result)) {
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...
48
            $newentries = array();
49
            $linktext = ucfirst($myts -> htmlSpecialChars( $term ));
50
            $newentries['dir'] = $lexikon->dirname();
51
            $newentries['linktext'] = $linktext;
52
            $newentries['id'] = intval($entryID);
53
            $newentries['date'] = formatTimestamp( $datesub, $lxConfig['dateformat'] );
54
55
            $block['newstuff'][] = $newentries;
56
        }
57
    }
58
59
    return $block;
60
}
61
62 View Code Duplication
function b_lxentries_new_edit( $options ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
63
    $form  = "<table width='100%' border='0'  class='bg2'>";
64
    $form .= "<tr><th width='50%'>"._OPTIONS."</th><th width='50%'>"._MB_LEXIKON_SETTINGS."</th></tr>";
65
    $form .= "<tr><td class='even'>"._MB_LEXIKON_ORDER."</td><td class='odd'>";
66
    $form .= "&nbsp;<select name='options[0]'>";
67
    $form .= "<option value='datesub' ".(($options[0]=='datesub')?" selected='selected'":"").">"._MB_LEXIKON_DATE."</option>\n";
68
    $form .= "<option value='counter' ".(($options[0]=='counter')?" selected='selected'":"").">"._MB_LEXIKON_HITS."</option>\n";
69
    $form .= "<option value='term' ".(($options[0]=='term')?" selected='selected'":"").">"._MB_LEXIKON_NAME."</option>\n";
70
    $form .= "</select>\n<br /></td></tr>";
71
    //---
72
  $form .= "<tr><td class='even'>" . _MB_LEXIKON_DISP . "</td><td class='odd'><input type='text' name='options[]' value='" . $options[1] . "' />&nbsp;" . _MB_LEXIKON_TERMS . "<br /></td></tr>";
73
  //---
74
    $form .= "<tr><td class='even'>"._MB_LEXIKON_MARQUEE."</td><td class='odd'>";
75
    $form .= "<input type='radio' name='options[2]' value='1'".(($options[2]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
76
    $form .= "<input type='radio' name='options[2]' value='0'".(($options[2]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
77
  //---
78
  $form .= "<tr><td class='even'>"._MB_LEXIKON_ALTERNATE."</td><td class='odd'>";
79
    $form .= "<input type='radio' name='options[3]' value='1'".(($options[3]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
80
    $form .= "<input type='radio' name='options[3]' value='0'".(($options[3]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
81
  $form .= "</td></tr>";
82
  //---
83
    $form .= "<tr><td class='even'>"._MB_LEXIKON_SHOWDATE."</td><td class='odd'>";
84
    $form .= "<input type='radio' name='options[4]' value='1'".(($options[4]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
85
    $form .= "<input type='radio' name='options[4]' value='0'".(($options[4]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
86
  //---
87
  $form .= "<tr><td class='even'>"._MB_LEXIKON_DIRECTION."</td><td class='odd'><select name='options[5]'>";
88
  $form .= "<option value='up' ".(($options[5]=='up')?" selected='selected'":"").">"._MB_LEXIKON_UP."</option>\n";
89
  $form .= "<option value='down' ".(($options[5]=='down')?" selected='selected'":"").">"._MB_LEXIKON_DOWN."</option>\n";
90
  $form .= "</select></td></tr>\n";
91
  //---
92
    $form .= "<tr><td class='even'>"._MB_LEXIKON_BSPEED."</td><td class='odd'><input type='text' name='options[6]' size='16' maxlength=2 value='".$options[6]."' /></td></tr>";
93
  $form .= "<tr><td class='even'>"._MB_LEXIKON_BACKGROUNDCOLOR."</td><td class='odd'><input type='text' name='options[7]' size='16'  value='".$options[7]."' /></td></tr>";
94
  $form .= "</table>";
95
    //----
96
  return $form;
97
}
98