Completed
Push — master ( c39b68...a1acf8 )
by Michael
03:03
created

tdmdownloads_top.php ➔ b_tdmdownloads_top_edit()   B

Complexity

Conditions 7
Paths 48

Size

Total Lines 62
Code Lines 54

Duplication

Lines 21
Ratio 33.87 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 7
eloc 54
c 3
b 0
f 0
nc 48
nop 1
dl 21
loc 62
rs 7.3333

How to fix   Long Method   

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
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
function b_tdmdownloads_top_show($options)
18
{
19
    require_once XOOPS_ROOT_PATH."/modules/TDMDownloads/include/functions.php";
20
    //appel de la class
21
    $downloads_Handler =& xoops_getModuleHandler('tdmdownloads_downloads', 'TDMDownloads');
22
    $block = array();
23
    $type_block = $options[0];
24
    $nb_entree = $options[1];
25
    $lenght_title = $options[2];
26
    $use_logo = $options[3];
27
    $use_description = $options[4];
28
    $show_inforation = $options[5];
29
    $logo_float = $options[6];
30
    $logo_white = $options[7];
31
32
    array_shift($options);
33
    array_shift($options);
34
    array_shift($options);
35
    array_shift($options);
36
    array_shift($options);
37
    array_shift($options);
38
    array_shift($options);
39
    array_shift($options);
40
41
    // Add styles
42
    global $xoTheme;
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...
43
    $xoTheme->addStylesheet(XOOPS_URL . '/modules/TDMDownloads/css/blocks.css', null);
44
45
    $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads');
46
    $criteria = new CriteriaCompo();
47
    $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
48
    if (!(count($options) == 1 && $options[0] == 0)) {
49
        $criteria->add(new Criteria('cid', '(' . implode(',', $options) . ')','IN'));
50
    }
51
    $criteria->add(new Criteria('status', 0, '!='));
52
    switch ($type_block) {    // pour le bloc: dernier fichier
53
        case "date":
54
            $criteria->setSort('date');
55
            $criteria->setOrder('DESC');
56
        break;
57
        // pour le bloc: plus t�l�charg�
58
        case "hits":
59
            $criteria->setSort('hits');
60
            $criteria->setOrder('DESC');
61
        break;
62
        // pour le bloc: mieux not�
63
        case "rating":
64
            $criteria->setSort('rating');
65
            $criteria->setOrder('DESC');
66
        break;
67
        // pour le bloc: al�atoire
68
        case "random":
69
            $criteria->setSort('RAND()');
70
        break;
71
    }
72
    $criteria->setLimit($nb_entree);
73
    $downloads_arr = $downloads_Handler->getall($criteria);
74
    foreach (array_keys($downloads_arr) as $i) {
75
        $block[$i]['lid'] = $downloads_arr[$i]->getVar('lid');
76
        $block[$i]['title'] = strlen($downloads_arr[$i]->getVar('title')) > $lenght_title ? substr($downloads_arr[$i]->getVar('title'),0,($lenght_title))."..." : $downloads_arr[$i]->getVar('title');
77
        $description_short = '';
78
        if ($use_description == true) {
79
            $description = $downloads_arr[$i]->getVar('description');
80
            //permet d'afficher uniquement la description courte
81
            if (strpos($description,'[pagebreak]')==false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($description, '[pagebreak]') of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
82
                $description_short = mb_substr($description,0,400,'utf-8') . ' ...';
83
            } else {
84
                $description_short = mb_substr($description,0,strpos($description,'[pagebreak]'),'utf-8') . ' ...';
85
            }
86
        }
87
        $block[$i]['description'] = $description_short;
88
        $logourl = '';
89
        if ($use_logo == true) {
90
            if ($downloads_arr[$i]->getVar('logourl') == 'blank.gif') {
91
                $logourl = '';
92
            } else {
93
                $logourl = XOOPS_URL . '/uploads/TDMDownloads/images/shots/'. $downloads_arr[$i]->getVar('logourl');
94
            }
95
        }
96
        $block[$i]['logourl'] = $logourl;
97
        $block[$i]['logourl_class'] = $logo_float;
98
        $block[$i]['logourl_width'] = $logo_white;
99
        $block[$i]['hits'] = $downloads_arr[$i]->getVar("hits");
100
        $block[$i]['rating'] = number_format($downloads_arr[$i]->getVar("rating"),1);
101
        $block[$i]['date'] = formatTimeStamp($downloads_arr[$i]->getVar("date"),"s");
102
        $block[$i]['submitter'] = XoopsUser::getUnameFromId($downloads_arr[$i]->getVar('submitter'));
103
        $block[$i]['inforation'] = $show_inforation;
104
105
    }
106
107
    return $block;
108
}
109
110
function b_tdmdownloads_top_edit($options)
111
{
112
    //appel de la class
113
    $downloadscat_Handler =& xoops_getModuleHandler('tdmdownloads_cat', 'TDMDownloads');
114
    $criteria = new CriteriaCompo();
0 ignored issues
show
Unused Code introduced by
$criteria 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...
115
    $criteria = new CriteriaCompo();
116
    $criteria->setSort('cat_weight ASC, cat_title');
117
    $criteria->setOrder('ASC');
118
    $downloadscat_arr = $downloadscat_Handler->getall($criteria);
119
    $form = _MB_TDMDOWNLOADS_DISP . "&nbsp;\n";
120
    $form .= "<input type=\"hidden\" name=\"options[0]\" value=\"" . $options[0] . "\" />\n";
121
    $form .= "<input name=\"options[1]\" size=\"5\" maxlength=\"255\" value=\"" . $options[1] . "\" type=\"text\" />&nbsp;" . _MB_TDMDOWNLOADS_FILES . "<br />\n";
122
    $form .= _MB_TDMDOWNLOADS_CHARS . " : <input name=\"options[2]\" size=\"5\" maxlength=\"255\" value=\"" . $options[2] . "\" type=\"text\" /><br />\n";
123 View Code Duplication
    if ($options[3] == false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
124
        $checked_yes = '';
125
        $checked_no = 'checked="checked"';
126
    } else {
127
        $checked_yes = 'checked="checked"';
128
        $checked_no = '';
129
    }
130
    $form .= _MB_TDMDOWNLOADS_LOGO . " : <input name=\"options[3]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . "&nbsp;\n";
131
    $form .= "<input name=\"options[3]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br />\n";
132 View Code Duplication
    if ($options[4] == false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
133
        $checked_yes = '';
134
        $checked_no = 'checked="checked"';
135
    } else {
136
        $checked_yes = 'checked="checked"';
137
        $checked_no = '';
138
    }
139
    $form .= _MB_TDMDOWNLOADS_DESCRIPTION . " : <input name=\"options[4]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . "&nbsp;\n";
140
    $form .= "<input name=\"options[4]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br />\n";
141 View Code Duplication
    if ($options[5] == false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
142
        $checked_yes = '';
143
        $checked_no = 'checked="checked"';
144
    } else {
145
        $checked_yes = 'checked="checked"';
146
        $checked_no = '';
147
    }
148
    $form .= _MB_TDMDOWNLOADS_INFORMATIONS . " : <input name=\"options[5]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . "&nbsp;\n";
149
    $form .= "<input name=\"options[5]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br /><br />\n";
150
    $floatelect = new XoopsFormSelect(_MB_TDMDOWNLOADS_FLOAT, 'options[6]',$options[6]);
151
     $floatelect->addOption("left", _MB_TDMDOWNLOADS_FLOAT_LEFT);
152
     $floatelect->addOption("right", _MB_TDMDOWNLOADS_FLOAT_RIGHT);
153
     $form .= _MB_TDMDOWNLOADS_FLOAT." : ".$floatelect->render().'<br />';
154
    $form .= _MB_TDMDOWNLOADS_WHITE . " : <input name=\"options[7]\" size=\"5\" maxlength=\"255\" value=\"" . $options[7] . "\" type=\"text\" /><br />\n";
155
    array_shift($options);
156
    array_shift($options);
157
    array_shift($options);
158
    array_shift($options);
159
    array_shift($options);
160
    array_shift($options);
161
    array_shift($options);
162
    array_shift($options);
163
    $form .= _MB_TDMDOWNLOADS_CATTODISPLAY . "<br /><select name=\"options[]\" multiple=\"multiple\" size=\"5\">\n";
164
    $form .= "<option value=\"0\" " . (array_search(0, $options) === false ? '' : 'selected="selected"') . ">" . _MB_TDMDOWNLOADS_ALLCAT . "</option>\n";
165
    foreach (array_keys($downloadscat_arr) as $i) {
166
        $form .= "<option value=\"" . $downloadscat_arr[$i]->getVar('cat_cid') . "\" " . (array_search($downloadscat_arr[$i]->getVar('cat_cid'), $options) === false ? '' : 'selected="selected"') . ">".$downloadscat_arr[$i]->getVar('cat_title')."</option>\n";
167
    }
168
    $form .= "</select>\n";
169
170
    return $form;
171
}
172