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

entries_scrolling.php ➔ b_scrolling_term_show()   F

Complexity

Conditions 16
Paths 1536

Size

Total Lines 65
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 16
eloc 48
c 1
b 0
f 0
nc 1536
nop 1
dl 0
loc 65
rs 2.7615

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 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
/** entries_scrolling.php v.1
3
  * XOOPS - PHP Content Management System
4
  * Copyright (c) 2011 <http://www.xoops.org/>
5
  *
6
  * Module: lexikon 1.5 beta
7
  * Author : Yerres
8
  * Licence : GPL
9
  *
10
*/
11
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die( 'XOOPS root path not defined' ) ;
12
13
function b_scrolling_term_show( $options ) {
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
    $myts = & MyTextSanitizer :: getInstance();
16
17
    $module_handler = &xoops_gethandler('module');
18
    $lexikon = &$module_handler->getByDirname('lexikon');
19
    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...
20
        $config_handler = &xoops_gethandler('config');
21
        $lxConfig = &$config_handler->getConfigsByCat(0, $lexikon->getVar('mid'));
22
    }
23
    include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/functions.php';
24
    
25
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
26
    $gperm_handler =& xoops_gethandler('groupperm');
27
    $module_id = $lexikon->getVar('mid');
28
    $allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
29
        
30
    $block = array();
31
    $block['speed'] = isset($options[1]) && $options[1] != '' ?  $options[1] : '';
32
    $block['bgcolor'] = isset($options[2]) && $options[2] != '' ?  $options[2] : '#FFFFFF';
33
    $block['direction'] = $options[3];
34
    $block['alternate'] = isset($options[4])? 1:0;
35
    $block['includedate'] = isset($options[6])? 1:0;
36
    $block['style'] = $options[7];
37
38
    if (!empty($options[10])) $categories = array_filter(array_slice($options, 10));
39
     else $categories = $allowed_cats;
40
    $categories = array_intersect($categories, $allowed_cats);
41
    $categories = implode(',', $categories);
42
    if( count($categories) == 0 )  return $block;
43
44
    $sql = $xoopsDB -> query ("
45
      SELECT entryID, term, definition, datesub, html
46
      FROM " . $xoopsDB -> prefix( 'lxentries' ) . "
47
      WHERE datesub < ".time()." AND datesub > 0 AND offline = '0' AND submit = '0' AND request = '0' AND  categoryID IN (" . $categories . ")
48
      ORDER BY " . $options[8] . " " . $options[9] . "
49
      LIMIT 0, " . $options[0] . " ");
50
     $totals = $xoopsDB -> getRowsNum ( $sql );
51
52
    if ($totals > 1) {
53
      while (list( $entryID, $term , $definition, $datesub, $html) = $xoopsDB->fetchRow($sql)) {
54
          $items = array();
55
          $userlink = '<a style="cursor:help;background-color: transparent;" href=\"'.XOOPS_URL.'/modules/' .$lexikon->dirname(). '/entry.php?entryID='.intval($entryID).'\">';
56
          $items['id'] = intval($entryID);
57
          $items['term'] = $myts -> htmlSpecialChars( $term );
58
          if ($options[5] > 0) {
59
            $html = $html == 1 ? 1 : 0;
60
            $definition= preg_replace("/'/", "�", $definition);
61
            $items['definition'] = lx_truncate_tagsafe($myts->displayTarea($definition, $html), $options[5]+3);
62
            // terms with images
63
            //$items['definition'] = lx_truncate_tagsafe(strip_tags($myts->displayTarea($definition, $html), $options[5]+3));
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
64
          } else {
65
            $items['definition'] = '';
66
          }
67
          if ($options[6] == "1")
68
            //$items['date'] = formatTimestamp( $datesub, 'M d, Y g:i:s A' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
69
            $items['date'] = formatTimestamp( $datesub, $lxConfig['dateformat'] );
70
          $items['url'] = $userlink ;
71
          $block['scrollitems'][] = $items;
72
          
73
        }
74
    }
75
76
    return $block;
77
}
78
79
function b_scrolling_term_edit( $options ){
80
    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...
81
    $myts = & MyTextSanitizer :: getInstance();
82
    $form  = "<table width='100%' border='0'  class='bg2'>";
83
    $form .= "<tr><th width='50%'>"._OPTIONS."</th><th width='50%'>"._MB_LEXIKON_SETTINGS."</th></tr>";
84
    $form .= "<tr><td class='even'>"._MB_LEXIKON_BLIMIT."</td><td class='odd'><input type='text' name='options[0]' size='16' maxlength=3 value='".$options[0]."' /></td></tr>";
85
    $form .= "<tr><td class='even'>"._MB_LEXIKON_BSPEED."</td><td class='odd'><input type='text' name='options[1]' size='16' maxlength=2 value='".$options[1]."' /></td></tr>";
86
    $form .= "<tr><td class='even'>"._MB_LEXIKON_BACKGROUNDCOLOR."</td><td class='odd'><input type='text' name='options[2]' size='16'  value='".$options[2]."' /></td></tr>";
87
  //---
88
  $form .= "<tr><td class='even'>"._MB_LEXIKON_DIRECTION."</td><td class='odd'><select name='options[3]'>";
89
  $form .= "<option value='up' ".(($options[3]=='up')?" selected='selected'":"").">"._MB_LEXIKON_UP."</option>\n";
90
  $form .= "<option value='down' ".(($options[3]=='down')?" selected='selected'":"").">"._MB_LEXIKON_DOWN."</option>\n";
91
  //$form .= "<option value='left' ".(($options[3]=='left')?" selected='selected'":"").">"._LEFT."</option>\n";
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...
92
  //$form .= "<option value='right' ".(($options[3]=='right')?" selected='selected'":"").">"._RIGHT."</option>\n";
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...
93
  $form .= "</select></td></tr>\n";
94
  //---
95
  $form .= "<tr><td class='even'>"._MB_LEXIKON_ALTERNATE."</td><td class='odd'>";
96
    $form .= "<input type='radio' name='options[4]' value='1'".(($options[4]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
97
    $form .= "<input type='radio' name='options[4]' value='0'".(($options[4]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
98
    //---
99
  $form .= "<tr><td class='even'>"._MB_LEXIKON_CHARS." </td><td class='odd'><input type='text' name='options[5]' value='".$options[5]."' /></td></tr>";
100
  //---
101
    $form .= "<tr><td class='even'>"._MB_LEXIKON_TERMSTOSHOW." "._MB_LEXIKON_SHOWDATE."</td><td class='odd'>";
102
    $form .= "<input type='radio' name='options[6]' value='1'".(($options[6]==1)?" checked='checked'":"")." />"._YES."&nbsp;";
103
    $form .= "<input type='radio' name='options[6]' value='0'".(($options[6]==0)?" checked='checked'":"")." />"._NO."<br /></td></tr>";
104
  //---
105
  $form .= "<tr><td class='even'>"._MB_LEXIKON_DISP."</td><td class='odd'><select name='options[7]'>";
106
  $form .= "<option value='0' ".(($options[7]=='0')?" selected='selected'":"").">"._MB_LEXIKON_MARQUEE."</option>\n";
107
  $form .= "<option value='1' ".(($options[7]=='1')?" selected='selected'":"").">"._MB_LEXIKON_PAUSESCROLLER."</option>\n";
108
  $form .= "<option value='2' ".(($options[7]=='2')?" selected='selected'":"").">"._MB_LEXIKON_DOMTICKER."</option>\n";
109
  $form .= "</select></td></tr>\n";
110
  //---
111
    $form .= "<tr><td class='even'>"._MB_LEXIKON_SORT."</td><td class='odd'><select name='options[8]'>";
112
    $form .= "<option value='RAND()' ".(($options[8]=='RAND()')?" selected='selected'":"").">"._MB_LEXIKON_RANDOM."</option>\n";
113
    $form .= "<option value='datesub' ".(($options[8]=='datesub')?" selected='selected'":"").">"._MB_LEXIKON_DATE."</option>\n";
114
    $form .= "<option value='counter' ".(($options[8]=='counter')?" selected='selected'":"").">"._MB_LEXIKON_HITS."</option>\n";
115
    $form .= "<option value='term' ".(($options[8]=='term')?" selected='selected'":"").">"._MB_LEXIKON_NAME."</option>\n";
116
    $form .= "</select></td></tr>\n";
117
  //---
118
  $form .= "<tr><td class='even'>"._MB_LEXIKON_ORDER."</td><td class='odd'><select name='options[9]'>";
119
  $form .= "<option value='ASC' ".(($options[9]=='ASC')?" selected='selected'":"").">"._ASCENDING."</option>\n";
120
  $form .= "<option value='DESC' ".(($options[9]=='DESC')?" selected='selected'":"").">"._DESCENDING."</option>\n";
121
  $form .= "</select></td></tr>\n";
122
  //--- get allowed categories
123
  $isAll = empty($options[10]) ? true : false;
124
  $options_cat = array_slice($options, 10);
125
  $form .= "<tr><td class='even'>"._MB_LEXIKON_CATEGORY."</td><td class='odd'><select name=\"options[]\" multiple=\"multiple\">";
126
  $form .= "<option value=\"0\" ";
127
  if ($isAll) $form .= " selected=\"selected\"";
128
  $form .= ">"._ALL."</option>";
129
  $resultcat = $xoopsDB -> query ( "SELECT categoryID, name FROM " . $xoopsDB -> prefix ( "lxcategories") . " ORDER BY categoryID ASC" );
130
    while (list( $categoryID, $name) = $xoopsDB->fetchRow($resultcat)){
131
      $sel = ($isAll || in_array($categoryID, $options_cat))?" selected":"";
132
      $form .= "<option value=".$categoryID." $sel>$categoryID : $name</option>\n";
133
      }
134
  $form .= "</select></td></tr>\n";
135
  $form .= "</table>";
136
  
137
    //--------
138
        
139
    return $form;
140
}
141