Completed
Push — master ( c1777d...d193e2 )
by Michael
13:22
created

blocksadmin.inc.php ➔ myblocksadmin_update_blockinstance()   B

Complexity

Conditions 7
Paths 18

Size

Total Lines 66
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 50
nc 18
nop 11
dl 0
loc 66
rs 7.0832
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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

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
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project http://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18
 */
19
20
21
if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) {
22
    exit('Access Denied');
23
}
24
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
25
include XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blocksadmin.php';
26
27
$op = 'list';
28
29
if (!empty($_POST['op'])) {
30
    $op = $_POST['op'];
31
}
32
if (!empty($_POST['bid'])) {
33
    $bid = (int)$_POST['bid'];
34
}
35
36
if (isset($_GET['op'])) {
37
    if ($_GET['op'] === 'edit' || $_GET['op'] === 'delete' || $_GET['op'] === 'delete_ok'
38
        || $_GET['op'] === 'clone' /* || $_GET['op'] == 'previewpopup'*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
39
    ) {
40
        $op  = $_GET['op'];
41
        $bid = isset($_GET['bid']) ? (int)$_GET['bid'] : 0;
42
    }
43
}
44
45
if (isset($_POST['previewblock'])) {
46
    //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
47
    //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
48
    //}
49
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
50
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
51
    }
52
53
    if (empty($bid)) {
54
        die('Invalid bid.');
55
    }
56
57
    if (!empty($_POST['bside'])) {
58
        $bside = (int)$_POST['bside'];
59
    } else {
60
        $bside = 0;
61
    }
62
    if (!empty($_POST['bweight'])) {
63
        $bweight = (int)$_POST['bweight'];
64
    } else {
65
        $bweight = 0;
66
    }
67
    if (!empty($_POST['bvisible'])) {
68
        $bvisible = (int)$_POST['bvisible'];
69
    } else {
70
        $bvisible = 0;
71
    }
72
    if (!empty($_POST['bmodule'])) {
73
        $bmodule = $_POST['bmodule'];
74
    } else {
75
        $bmodule = array();
76
    }
77
    if (!empty($_POST['btitle'])) {
78
        $btitle = $_POST['btitle'];
79
    } else {
80
        $btitle = '';
81
    }
82
    if (!empty($_POST['bcontent'])) {
83
        $bcontent = $_POST['bcontent'];
84
    } else {
85
        $bcontent = '';
86
    }
87
    if (!empty($_POST['bctype'])) {
88
        $bctype = $_POST['bctype'];
89
    } else {
90
        $bctype = '';
91
    }
92
    if (!empty($_POST['bcachetime'])) {
93
        $bcachetime = (int)$_POST['bcachetime'];
94
    } else {
95
        $bcachetime = 0;
96
    }
97
98
    xoops_cp_header();
99
    include_once XOOPS_ROOT_PATH . '/class/template.php';
100
    $xoopsTpl = new XoopsTpl();
101
    $xoopsTpl->xoops_setCaching(0);
102
    $block['bid'] = $bid;
103
104
    if ($op === 'clone_ok') {
105
        $block['form_title']    = _AM_CLONEBLOCK;
106
        $block['submit_button'] = _CLONE;
107
        $myblock                = new XoopsBlock();
108
        $myblock->setVar('block_type', 'C');
109
    } else {
110
        $op                     = 'update';
111
        $block['form_title']    = _AM_EDITBLOCK;
112
        $block['submit_button'] = _SUBMIT;
113
        $myblock                = new XoopsBlock($bid);
114
        $block['name']          = $myblock->getVar('name');
115
    }
116
117
    $myts = MyTextSanitizer::getInstance();
118
    $myblock->setVar('title', $myts->stripSlashesGPC($btitle));
119
    $myblock->setVar('content', $myts->stripSlashesGPC($bcontent));
120
    //  $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.$xoopsConfig['sitename'].'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'" /></head><body><table><tr><th>'.$myblock->getVar('title').'</th></tr><tr><td>'.$myblock->getContent('S', $bctype).'</td></tr></table></body></html>';
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...
121
122
    /* $dummyfile = '_dummyfile_'.time().'.html';
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
123
    $fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w');
124
    fwrite($fp, $dummyhtml);
125
    fclose($fp);*/
126
    $block['edit_form'] = false;
127
    $block['template']  = '';
128
    $block['op']        = $op;
129
    $block['side']      = $bside;
130
    $block['weight']    = $bweight;
131
    $block['visible']   = $bvisible;
132
    $block['title']     = $myblock->getVar('title', 'E');
133
    $block['content']   = $myblock->getVar('content', 'n');
134
    $block['modules']   =& $bmodule;
135
    $block['ctype']     = isset($bctype) ? $bctype : $myblock->getVar('c_type');
136
    $block['is_custom'] = true;
137
    $block['cachetime'] = (int)$bcachetime;
138
    echo '<a href="myblocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . $block['form_title'] . '<br><br>';
139
    include __DIR__ . '/../admin/myblockform.php'; //GIJ
140
    //echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$block['form_title'].'<br><br>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
141
    //include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
142
    $xoopsGTicket->addTicketXoopsFormElement($form, __LINE__, 1800, 'myblocksadmin'); //GIJ
143
    $form->display();
144
145
    $original_level = error_reporting(E_ALL);
146
    echo "
147
    <table width='100%' class='outer' cellspacing='1'>
148
      <tr>
149
        <th>" . $myblock->getVar('title') . "</th>
150
      </tr>
151
      <tr>
152
        <td class='odd'>" . $myblock->getContent('S', $bctype) . "</td>
153
      </tr>
154
    </table>\n";
155
    error_reporting($original_level);
156
157
    xoops_cp_footer();
158
    /* echo '<script type="text/javascript">
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
159
    preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file='.$dummyfile.'", "popup", 250, 200);
160
    </script>';*/
161
162
    exit();
163
}
164
165
/* if ($op == 'previewpopup') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
166
  if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
167
    exit('Invalid Referer');
168
  }
169
  $file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($_GET['file']));
170
  if (file_exists($file)) {
171
    include $file;
172
    @unlink($file);
173
  }
174
  exit();
175
} */
176
177
/* if ($op == "list") {
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...
178
  xoops_cp_header();
179
  list_blocks();
180
  xoops_cp_footer();
181
  exit();
182
} */
183
184
if ($op === 'order') {
185
    //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
186
    //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
187
    //}
188
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
189
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
190
    }
191
    if (!empty($_POST['side'])) {
192
        $side = $_POST['side'];
193
    }
194
    //  if ( !empty($_POST['weight']) ) { $weight = $_POST['weight']; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
195
    if (!empty($_POST['visible'])) {
196
        $visible = $_POST['visible'];
197
    }
198
    //  if ( !empty($_POST['oldside']) ) { $oldside = $_POST['oldside']; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
199
    //  if ( !empty($_POST['oldweight']) ) { $oldweight = $_POST['oldweight']; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
200
    //  if ( !empty($_POST['oldvisible']) ) { $oldvisible = $_POST['oldvisible']; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
201
    if (!empty($_POST['bid'])) {
202
        $bid = $_POST['bid'];
203
    } else {
204
        $bid = array();
205
    }
206
    // GIJ start
207 View Code Duplication
    foreach (array_keys($bid) as $i) {
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...
208
        if ($side[$i] < 0) {
209
            $visible[$i] = 0;
210
            $side[$i]    = -1;
211
        } else {
212
            $visible[$i] = 1;
213
        }
214
215
        $bmodule = (isset($_POST['bmodule'][$i])
216
                    && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1);
217
218
        myblocksadmin_update_block($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null, null, $_POST['bcachetime'][$i], $bmodule, array());
219
220
        //    if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] )
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
221
        //    order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% 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...
222
    }
223
    $query4redirect = '?dirname=' . urlencode(strip_tags(substr($_POST['query4redirect'], 9)));
224
    redirect_header("myblocksadmin.php$query4redirect", 1, _AM_DBUPDATED);
225
    // GIJ end
226
}
227
228
if ($op === 'order2') {
229
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
230
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
231
    }
232
233
    if (isset($_POST['addblock']) && is_array($_POST['addblock'])) {
234
235
        // addblock
236
        foreach ($_POST['addblock'] as $bid => $val) {
237
            myblocksadmin_update_blockinstance(0, 0, 0, 0, '', null, null, 0, array(), array(), (int)$bid);
238
        }
239
    } else {
240
241
        // else change order
242
        if (!empty($_POST['side'])) {
243
            $side = $_POST['side'];
244
        }
245
        if (!empty($_POST['visible'])) {
246
            $visible = $_POST['visible'];
247
        }
248
        if (!empty($_POST['id'])) {
249
            $id = $_POST['id'];
250
        } else {
251
            $id = array();
252
        }
253
254 View Code Duplication
        foreach (array_keys($id) as $i) {
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...
255
            // separate side and visible
256
            if ($side[$i] < 0) {
257
                $visible[$i] = 0;
258
                $side[$i]    = -1;  // for not to destroy the original position
259
            } else {
260
                $visible[$i] = 1;
261
            }
262
263
            $bmodule = (isset($_POST['bmodule'][$i])
264
                        && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1);
265
266
            myblocksadmin_update_blockinstance($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null, null, $_POST['bcachetime'][$i], $bmodule, array());
267
        }
268
    }
269
270
    $query4redirect = '?dirname=' . urlencode(strip_tags(substr($_POST['query4redirect'], 9)));
271
    redirect_header("myblocksadmin.php$query4redirect", 1, _MD_AM_DBUPDATED);
272
    exit;
273
}
274
275
/* if ($op == 'save') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
276
  if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
277
    exit('Invalid Referer');
278
  }
279
  if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) {
280
    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
281
  }
282
  if ( !empty($_POST['bside']) ) { $bside = (int)($_POST['bside']); } else { $bside = 0; }
283
  if ( !empty($_POST['bweight']) ) { $bweight = (int)($_POST['bweight']); } else { $bweight = 0; }
284
  if ( !empty($_POST['bvisible']) ) { $bvisible = (int)($_POST['bvisible']); } else { $bvisible = 0; }
285
  if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); }
286
  if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; }
287
  if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; }
288
  if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; }
289
  if ( !empty($_POST['bcachetime']) ) { $bcachetime = (int)($_POST['bcachetime']); } else { $bcachetime = 0; }
290
  save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime);
291
  exit();
292
} */
293
294
if ($op === 'update') {
295
    //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
296
    //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
297
    //}
298
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
299
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
300
    }
301
    /*  if ( !empty($_POST['bside']) ) { $bside = (int)($_POST['bside']); } else { $bside = 0; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
302
      if ( !empty($_POST['bweight']) ) { $bweight = (int)($_POST['bweight']); } else { $bweight = 0; }
303
      if ( !empty($_POST['bvisible']) ) { $bvisible = (int)($_POST['bvisible']); } else { $bvisible = 0; }
304
      if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; }
305
      if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; }
306
      if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; }
307
      if ( !empty($_POST['bcachetime']) ) { $bcachetime = (int)($_POST['bcachetime']); } else { $bcachetime = 0; }
308
      if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); }
309
      if ( !empty($_POST['options']) ) { $options = $_POST['options']; } else { $options = array(); }
310
      update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options);*/
311
312
    $bcachetime = isset($_POST['bcachetime']) ? (int)$_POST['bcachetime'] : 0;
313
    $options    = isset($_POST['options']) ? $_POST['options'] : array();
314
    $bcontent   = isset($_POST['bcontent']) ? $_POST['bcontent'] : '';
315
    $bctype     = isset($_POST['bctype']) ? $_POST['bctype'] : '';
316
    $bmodule    = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1); // GIJ +
317
    $msg        = myblocksadmin_update_block($_POST['bid'], $_POST['bside'], $_POST['bweight'], $_POST['bvisible'], $_POST['btitle'], $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ !
318
    redirect_header('myblocksadmin.php', 1, $msg);
319
}
320
321
if ($op === 'delete_ok') {
322
    //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
323
    //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
324
    //}
325
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
326
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
327
    }
328
    // delete_block_ok($bid); GIJ imported from blocksadmin.php
329
    $myblock = new XoopsBlock($bid);
330
    if ($myblock->getVar('block_type') !== 'D' && $myblock->getVar('block_type') !== 'C') {
331
        redirect_header('myblocksadmin.php', 4, 'Invalid block');
332
    }
333
    $myblock->delete();
334
    if ($myblock->getVar('template') != '' && !defined('XOOPS_ORETEKI')) {
335
        $tplfileHandler = xoops_getHandler('tplfile');
336
        $btemplate      =& $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
337
        if (count($btemplate) > 0) {
338
            $tplman->delete($btemplate[0]);
339
        }
340
    }
341
    redirect_header('myblocksadmin.php', 1, _AM_DBUPDATED);
342
343
    // end of delete_block_ok() GIJ
344
}
345
346
if ($op === 'delete') {
347
    xoops_cp_header();
348
    // delete_block($bid); GIJ imported from blocksadmin.php
349
    $myblock = new XoopsBlock($bid);
350
    if ($myblock->getVar('block_type') === 'S') {
351
        $message = _AM_SYSTEMCANT;
352
        redirect_header('admin.php?fct=blocksadmin', 4, $message);
353
    } elseif ($myblock->getVar('block_type') === 'M') {
354
        $message = _AM_MODULECANT;
355
        redirect_header('admin.php?fct=blocksadmin', 4, $message);
356
    } else {
357
        xoops_confirm(array('fct' => 'blocksadmin', 'op' => 'delete_ok', 'bid' => $myblock->getVar('bid')) + $xoopsGTicket->getTicketArray(__LINE__, 1800, 'myblocksadmin'), 'admin.php',
358
                      sprintf(_AM_RUSUREDEL, $myblock->getVar('title')));
359
    }
360
    // end of delete_block() GIJ
361
    xoops_cp_footer();
362
    exit();
363
}
364
365 View Code Duplication
if ($op === 'edit') {
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...
366
    xoops_cp_header();
367
    // edit_block($bid); GIJ imported from blocksadmin.php
368
    $myblock = new XoopsBlock($bid);
369
370
    $db      = XoopsDatabaseFactory::getDatabaseConnection();
371
    $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
372
    $result  = $db->query($sql);
373
    $modules = array();
374
    while ($row = $db->fetchArray($result)) {
375
        $modules[] = (int)$row['module_id'];
376
    }
377
    $is_custom = ($myblock->getVar('block_type') === 'C' || $myblock->getVar('block_type') === 'E') ? true : false;
378
    $block     = array(
379
        'form_title'    => _AM_EDITBLOCK,
380
        'name'          => $myblock->getVar('name'),
381
        'side'          => $myblock->getVar('side'),
382
        'weight'        => $myblock->getVar('weight'),
383
        'visible'       => $myblock->getVar('visible'),
384
        'title'         => $myblock->getVar('title', 'E'),
385
        'content'       => $myblock->getVar('content', 'n'),
386
        'modules'       => $modules,
387
        'is_custom'     => $is_custom,
388
        'ctype'         => $myblock->getVar('c_type'),
389
        'cachetime'     => $myblock->getVar('bcachetime'),
390
        'op'            => 'update',
391
        'bid'           => $myblock->getVar('bid'),
392
        'edit_form'     => $myblock->getOptions(),
393
        'template'      => $myblock->getVar('template'),
394
        'options'       => $myblock->getVar('options'),
395
        'submit_button' => _SUBMIT
396
    );
397
398
    echo '<a href="myblocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_EDITBLOCK . '<br><br>';
399
    include __DIR__ . '/../admin/myblockform.php'; //GIJ
400
    $xoopsGTicket->addTicketXoopsFormElement($form, __LINE__, 1800, 'myblocksadmin'); //GIJ
401
    $form->display();
402
    // end of edit_block() GIJ
403
    xoops_cp_footer();
404
    exit();
405
}
406
407 View Code Duplication
if ($op === 'clone') {
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...
408
    xoops_cp_header();
409
    $myblock = new XoopsBlock($bid);
410
411
    $db      = XoopsDatabaseFactory::getDatabaseConnection();
412
    $sql     = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
413
    $result  = $db->query($sql);
414
    $modules = array();
415
    while ($row = $db->fetchArray($result)) {
416
        $modules[] = (int)$row['module_id'];
417
    }
418
    $is_custom = ($myblock->getVar('block_type') === 'C' || $myblock->getVar('block_type') === 'E') ? true : false;
419
    $block     = array(
420
        'form_title'    => _AM_CLONEBLOCK,
421
        'name'          => $myblock->getVar('name'),
422
        'side'          => $myblock->getVar('side'),
423
        'weight'        => $myblock->getVar('weight'),
424
        'visible'       => $myblock->getVar('visible'),
425
        'content'       => $myblock->getVar('content', 'N'),
426
        'title'         => $myblock->getVar('title', 'E'),
427
        'modules'       => $modules,
428
        'is_custom'     => $is_custom,
429
        'ctype'         => $myblock->getVar('c_type'),
430
        'cachetime'     => $myblock->getVar('bcachetime'),
431
        'op'            => 'clone_ok',
432
        'bid'           => $myblock->getVar('bid'),
433
        'edit_form'     => $myblock->getOptions(),
434
        'template'      => $myblock->getVar('template'),
435
        'options'       => $myblock->getVar('options'),
436
        'submit_button' => _CLONE
437
    );
438
    echo '<a href="myblocksadmin.php">' . _AM_BADMIN . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . _AM_CLONEBLOCK . '<br><br>';
439
    include __DIR__ . '/../admin/myblockform.php';
440
    $xoopsGTicket->addTicketXoopsFormElement($form, __LINE__, 1800, 'myblocksadmin'); //GIJ
441
    $form->display();
442
    xoops_cp_footer();
443
    exit();
444
}
445
446
if ($op === 'clone_ok') {
447
    // Ticket Check
448
    if (!$xoopsGTicket->check(true, 'myblocksadmin')) {
449
        redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors());
450
    }
451
452
    $block = new XoopsBlock($bid);
453
454
    // block type check
455
    $block_type = $block->getVar('block_type');
456
    if ($block_type !== 'C' && $block_type !== 'M' && $block_type !== 'D') {
457
        redirect_header('myblocksadmin.php', 4, 'Invalid block');
458
    }
459
460
    if (empty($_POST['options'])) {
461
        $options = array();
462
    } elseif (is_array($_POST['options'])) {
463
        $options = $_POST['options'];
464
    } else {
465
        $options = explode('|', $_POST['options']);
466
    }
467
468
    // for backward compatibility
469
    // $cblock =& $block->clone(); or $cblock =& $block->xoopsClone();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
470
    $cblock = new XoopsBlock();
471
    foreach ($block->vars as $k => $v) {
472
        $cblock->assignVar($k, $v['value']);
473
    }
474
    $cblock->setNew();
475
476
    $myts = MyTextSanitizer::getInstance();
477
    $cblock->setVar('side', $_POST['bside']);
478
    $cblock->setVar('weight', $_POST['bweight']);
479
    $cblock->setVar('visible', $_POST['bvisible']);
480
    $cblock->setVar('title', $_POST['btitle']);
481
    $cblock->setVar('content', @$_POST['bcontent']);
482
    $cblock->setVar('c_type', @$_POST['bctype']);
483
    $cblock->setVar('bcachetime', $_POST['bcachetime']);
484 View Code Duplication
    if (isset($options) && (count($options) > 0)) {
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...
485
        $options = implode('|', $options);
486
        $cblock->setVar('options', $options);
487
    }
488
    $cblock->setVar('bid', 0);
489
    $cblock->setVar('block_type', $block_type === 'C' ? 'C' : 'D');
490
    $cblock->setVar('func_num', 255);
491
    $newid = $cblock->store();
492
    if (!$newid) {
493
        xoops_cp_header();
494
        $cblock->getHtmlErrors();
495
        xoops_cp_footer();
496
        exit();
497
    }
498
    /*  if ($cblock->getVar('template') != '') {
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...
499
            $tplfileHandler = xoops_getHandler('tplfile');
500
            $btemplate =& $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
501
            if (count($btemplate) > 0) {
502
                $tplclone =& $btemplate[0]->clone();
503
                $tplclone->setVar('tpl_id', 0);
504
                $tplclone->setVar('tpl_refid', $newid);
505
                $tplman->insert($tplclone);
506
            }
507
        } */
508
    $db      = XoopsDatabaseFactory::getDatabaseConnection();
509
    $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1); // GIJ +
510
    foreach ($bmodule as $bmid) {
511
        $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
512
        $db->query($sql);
513
    }
514
515
    /*  global $xoopsUser;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
516
        $groups =& $xoopsUser->getGroups();
517
        $count = count($groups);
518
        for ($i = 0; $i < $count; ++$i) {
519
            $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')";
520
            $db->query($sql);
521
        }
522
    */
523
524
    $sql    = 'SELECT gperm_groupid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name='block_read' AND gperm_modid='1' AND gperm_itemid='$bid'";
525
    $result = $db->query($sql);
526
    while (list($gid) = $db->fetchRow($result)) {
527
        $sql = 'INSERT INTO ' . $db->prefix('group_permission') . " (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ($gid, $newid, 1, 'block_read')";
528
        $db->query($sql);
529
    }
530
531
    redirect_header('myblocksadmin.php', 1, _AM_DBUPDATED);
532
}
533
534
// import from modules/system/admin/blocksadmin/blocksadmin.php
535
/**
536
 * @param         $bid
537
 * @param         $bside
538
 * @param         $bweight
539
 * @param         $bvisible
540
 * @param         $btitle
541
 * @param         $bcontent
542
 * @param         $bctype
543
 * @param         $bcachetime
544
 * @param         $bmodule
545
 * @param  array  $options
546
 * @return string
547
 */
548
function myblocksadmin_update_block(
549
    $bid,
550
    $bside,
551
    $bweight,
552
    $bvisible,
553
    $btitle,
554
    $bcontent,
555
    $bctype,
556
    $bcachetime,
557
    $bmodule,
558
    $options = array()
559
) {
560
    global $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...
561
    /* if (empty($bmodule)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
562
        xoops_cp_header();
563
        xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
564
        xoops_cp_footer();
565
        exit();
566
    } */
567
    $myblock = new XoopsBlock($bid);
568
    // $myblock->setVar('side', $bside); GIJ -
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
569
    if ($bside >= 0) {
570
        $myblock->setVar('side', $bside);
571
    } // GIJ +
572
    $myblock->setVar('weight', $bweight);
573
    $myblock->setVar('visible', $bvisible);
574
    $myblock->setVar('title', $btitle);
575
    if (isset($bcontent)) {
576
        $myblock->setVar('content', $bcontent);
577
    }
578
    if (isset($bctype)) {
579
        $myblock->setVar('c_type', $bctype);
580
    }
581
    $myblock->setVar('bcachetime', $bcachetime);
582 View Code Duplication
    if (isset($options) && (count($options) > 0)) {
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...
583
        $options = implode('|', $options);
584
        $myblock->setVar('options', $options);
585
    }
586
    if ($myblock->getVar('block_type') === 'C') {
587
        switch ($myblock->getVar('c_type')) {
588
            case 'H':
589
                $name = _AM_CUSTOMHTML;
590
                break;
591
            case 'P':
592
                $name = _AM_CUSTOMPHP;
593
                break;
594
            case 'S':
595
                $name = _AM_CUSTOMSMILE;
596
                break;
597
            default:
598
                $name = _AM_CUSTOMNOSMILE;
599
                break;
600
        }
601
        $myblock->setVar('name', $name);
602
    }
603
    $msg = _AM_DBUPDATED;
604
    if ($myblock->store() !== false) {
605
        $db  = XoopsDatabaseFactory::getDatabaseConnection();
606
        $sql = sprintf('DELETE FROM %s WHERE block_id = %u', $db->prefix('block_module_link'), $bid);
607
        $db->query($sql);
608
        foreach ($bmodule as $bmid) {
609
            $sql = sprintf('INSERT INTO %s (block_id, module_id) VALUES (%u, %d)', $db->prefix('block_module_link'), $bid, (int)$bmid);
610
            $db->query($sql);
611
        }
612
        include_once XOOPS_ROOT_PATH . '/class/template.php';
613
        $xoopsTpl = new XoopsTpl();
614
        $xoopsTpl->xoops_setCaching(2);
615
        if ($myblock->getVar('template') != '') {
616
            if ($xoopsTpl->is_cached('db:' . $myblock->getVar('template'))) {
617
                if (!$xoopsTpl->clear_cache('db:' . $myblock->getVar('template'))) {
618
                    $msg = 'Unable to clear cache for block ID' . $bid;
619
                }
620
            }
621
        } else {
622
            if ($xoopsTpl->is_cached('db:system_dummy.tpl', 'block' . $bid)) {
623
                if (!$xoopsTpl->clear_cache('db:system_dummy.tpl', 'block' . $bid)) {
624
                    $msg = 'Unable to clear cache for block ID' . $bid;
625
                }
626
            }
627
        }
628
    } else {
629
        $msg = 'Failed update of block. ID:' . $bid;
630
    }
631
    // redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,$msg);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
632
    // exit(); GIJ -
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
633
    return $msg; // GIJ +
634
}
635
636
// update block instance for 2.2
637
/**
638
 * @param         $id
639
 * @param         $bside
640
 * @param         $bweight
641
 * @param         $bvisible
642
 * @param         $btitle
643
 * @param         $bcontent
644
 * @param         $bctype
645
 * @param         $bcachetime
646
 * @param         $bmodule
647
 * @param  array  $options
648
 * @param  null   $bid
649
 * @return string
650
 */
651
function myblocksadmin_update_blockinstance(
0 ignored issues
show
Coding Style introduced by
myblocksadmin_update_blockinstance uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
652
    $id,
653
    $bside,
654
    $bweight,
655
    $bvisible,
656
    $btitle,
657
    $bcontent,
0 ignored issues
show
Unused Code introduced by
The parameter $bcontent is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
658
    $bctype,
0 ignored issues
show
Unused Code introduced by
The parameter $bctype is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
659
    $bcachetime,
660
    $bmodule,
661
    $options = array(),
662
    $bid = null
663
) {
664
    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...
665
666
    $instanceHandler = xoops_getHandler('blockinstance');
667
    $blockHandler    = xoops_getHandler('block');
668
    if ($id > 0) {
669
        // update
670
        $instance =& $instanceHandler->get($id);
671
        if ($bside >= 0) {
672
            $instance->setVar('side', $bside);
673
        }
674
        if (!empty($options)) {
675
            $instance->setVar('options', $options);
676
        }
677
    } else {
678
        // insert
679
        $instance = $instanceHandler->create();
680
        $instance->setVar('bid', $bid);
681
        $instance->setVar('side', $bside);
682
        $block = $blockHandler->get($bid);
683
        $instance->setVar('options', $block->getVar('options'));
684
        if (empty($btitle)) {
685
            $btitle = $block->getVar('name');
686
        }
687
    }
688
    $instance->setVar('weight', $bweight);
689
    $instance->setVar('visible', $bvisible);
690
    $instance->setVar('title', $btitle);
691
    // if( isset( $bcontent ) ) $instance->setVar('content', $bcontent);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
692
    // if( isset( $bctype ) ) $instance->setVar('c_type', $bctype);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
693
    $instance->setVar('bcachetime', $bcachetime);
694
695
    if ($instanceHandler->insert($instance)) {
696
        $GLOBALS['xoopsDB']->query('DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' WHERE block_id=' . $instance->getVar('instanceid'));
697
        foreach ($bmodule as $mid) {
698
            $page   = explode('-', $mid);
699
            $mid    = $page[0];
700
            $pageid = $page[1];
701
            $GLOBALS['xoopsDB']->query('INSERT INTO '
702
                                       . $GLOBALS['xoopsDB']->prefix('block_module_link')
703
                                       . ' VALUES ('
704
                                       . $instance->getVar('instanceid')
705
                                       . ', '
706
                                       . (int)$mid
707
                                       . ', '
708
                                       . (int)$pageid
709
                                       . ')');
710
        }
711
712
        return _MD_AM_DBUPDATED;
713
    }
714
715
    return 'Failed update of block instance. ID:' . $id;
716
}
717
718
// TODO  edit2, delete2, customblocks
719