Completed
Push — master ( 8ca430...3024c9 )
by Michael
03:12
created

main.php ➔ edit()   F

Complexity

Conditions 35
Paths > 20000

Size

Total Lines 276
Code Lines 196

Duplication

Lines 25
Ratio 9.06 %

Importance

Changes 0
Metric Value
cc 35
eloc 196
c 0
b 0
f 0
nc 3221225473
nop 1
dl 25
loc 276
rs 2

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 21.

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
 * Module: XoopsTube
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
 *
9
 * PHP version 5
10
 *
11
 * @category        Module
12
 * @package         Xoopstube
13
 * @author          XOOPS Development Team
14
 * @copyright       2001-2013 The XOOPS Project
15
 * @link            http://sourceforge.net/projects/xoops/
16
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @since           1.0.6
18
 * @version         $Id: $
19
 */
20
21
include_once __DIR__ . '/admin_header.php';
22
global $xoopsModule, $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...
23
24
$mytree = new XoopstubeTree($xoopsDB->prefix('xoopstube_cat'), 'cid', 'pid');
25
26
$op  = xtubeCleanRequestVars($_REQUEST, 'op', '');
27
$lid = xtubeCleanRequestVars($_REQUEST, 'lid', 0);
28
29
/**
30
 * @param int $lid
31
 *
32
 * @return null
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
33
 */
34
function edit($lid = 0)
35
{
36
    global $xoopsDB, $xtubemyts, $mytree, $xtubeImageArray, $xoopsModuleConfig;
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...
37
38
    $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE lid=' . $lid;
39
    if (!$result = $xoopsDB->query($sql)) {
40
        XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
41
42
        return false;
43
    }
44
    $video_array  = $xoopsDB->fetchArray($xoopsDB->query($sql));
45
    $directory    = $xoopsModuleConfig['videoimgdir'];
0 ignored issues
show
Unused Code introduced by
$directory 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...
46
    $lid          = $video_array['lid'] ? $video_array['lid'] : 0;
47
    $cid          = $video_array['cid'] ? $video_array['cid'] : 0;
48
    $title        = $video_array['title'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['title']) : '';
49
    $vidid        = $video_array['vidid'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['vidid']) : '';
50
    $picurl       = $video_array['picurl'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['picurl']) : 'http://';
51
    $publisher    = $video_array['publisher'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['publisher']) : '';
52
    $screenshot   = $video_array['screenshot'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['screenshot']) : '';
0 ignored issues
show
Unused Code introduced by
$screenshot 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...
53
    $descriptionb = $video_array['description'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['description']) : '';
54
    $published    = $video_array['published'] ? $video_array['published'] : time();
55
    $expired      = $video_array['expired'] ? $video_array['expired'] : 0;
56
    $updated      = $video_array['updated'] ? $video_array['updated'] : 0;
57
    $offline      = $video_array['offline'] ? $video_array['offline'] : 0;
58
    $vidsource    = $video_array['vidsource'] ? $video_array['vidsource'] : 0;
59
    $ipaddress    = $video_array['ipaddress'] ? $video_array['ipaddress'] : 0;
60
    $notifypub    = $video_array['notifypub'] ? $video_array['notifypub'] : 0;
61
    $time         = $video_array['time'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['time']) : '0:00:00';
62
    $keywords     = $video_array['keywords'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['keywords']) : '';
63
    $item_tag     = $video_array['item_tag'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['item_tag']) : '';
0 ignored issues
show
Unused Code introduced by
$item_tag 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...
64
65
    include_once __DIR__ . '/admin_header.php';
66
    xoops_cp_header();
67
    //xtubeRenderAdminMenu( _AM_XOOPSTUBE_MVIDEOS );
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
68
69
    if ($lid) {
70
        $_vote_data = xtubeGetVoteDetails($lid);
71
        $text_info
72
                    = '
73
            <table width="100%" style="font-size: 90%;">
74
             <tr>
75
              <td style="width: 25%; border-right: #E8E8E8 1px solid; vertical-align: top; padding-left: 10px;">
76
               <div><b>' . _AM_XOOPSTUBE_VIDEO_ID . ' </b>' . $lid . '</div>
77
               <div><b>' . _AM_XOOPSTUBE_MINDEX_SUBMITTED . ': </b>' . xtubeGetTimestamp(
78
                formatTimestamp($video_array['date'], $xoopsModuleConfig['dateformat'])
79
            ) . '</div>
80
               <div><b>' . _AM_XOOPSTUBE_MOD_MODIFYSUBMITTER . ' </b>' . xtubeGetLinkedUserNameFromId(
81
                $video_array['submitter']
82
            ) . '</div>
83
               <div><b>' . _AM_XOOPSTUBE_VIDEO_IP . ' </b>' . $ipaddress . '</div>
84
               <div><b>' . _AM_XOOPSTUBE_VIDEO_VIEWS . ' </b>' . $video_array['hits'] . '</div>
85
              </td>
86
              <td style="width: 25%; border-right: #E8E8E8 1px solid; vertical-align: top; padding-left: 10px;">
87
               <div><b>' . _AM_XOOPSTUBE_VOTE_TOTALRATE . ': </b>' . intval($_vote_data['rate']) . '</div>
88
               <div><b>' . _AM_XOOPSTUBE_VOTE_USERAVG . ': </b>' . intval(round($_vote_data['avg_rate'], 2)) . '</div>
89
               <div><b>' . _AM_XOOPSTUBE_VOTE_MAXRATE . ': </b>' . intval($_vote_data['min_rate']) . '</div>
90
               <div><b>' . _AM_XOOPSTUBE_VOTE_MINRATE . ': </b>' . intval($_vote_data['max_rate']) . '</div>
91
              </td>
92
              <td style="width: 25%; border-right: #E8E8E8 1px solid; vertical-align: top; padding-left: 10px;">
93
               <div><b>' . _AM_XOOPSTUBE_VOTE_MOSTVOTEDTITLE . ': </b>' . intval($_vote_data['max_title']) . '</div>
94
               <div><b>' . _AM_XOOPSTUBE_VOTE_LEASTVOTEDTITLE . ': </b>' . intval($_vote_data['min_title']) . '</div>
95
               <div><b>' . _AM_XOOPSTUBE_VOTE_REGISTERED . ': </b>' . (intval(
96
                $_vote_data['rate'] - $_vote_data['null_ratinguser']
97
            )) . '</div>
98
               <div><b>' . _AM_XOOPSTUBE_VOTE_NONREGISTERED . ': </b>' . intval($_vote_data['null_ratinguser']) . '</div>
99
              </td>
100
              <td style="width: 25%; vertical-align: top; padding-left: 10px;">
101
                <div>' . xtubeGetVideoThumb(
102
                $video_array['vidid'],
103
                $video_array['title'],
104
                $video_array['vidsource'],
105
                $video_array['picurl'],
106
                $video_array['screenshot']
107
            ) . '</div>
108
              </td>
109
             </tr>
110
            </table>';
111
        echo '
112
            <fieldset style="border: #E8E8E8 1px solid;"><legend style="display: inline; font-weight: bold; color: #0A3760;">' . _AM_XOOPSTUBE_INFORMATION . '</legend>
113
            <div style="padding: 8px;">' . $text_info . '</div>
114
        <!--	<div style="padding: 8px;"><li>' . $xtubeImageArray['deleteimg'] . ' ' . _AM_XOOPSTUBE_VOTE_DELETEDSC . '</li></div>\n    -->
115
            </fieldset>
116
            <br />';
117
    }
118
    unset($_vote_data);
119
120
    $caption = ($lid) ? _AM_XOOPSTUBE_VIDEO_MODIFYFILE : _AM_XOOPSTUBE_VIDEO_CREATENEWFILE;
121
122
    $sform = new XoopsThemeForm($caption, 'storyform', xoops_getenv('PHP_SELF'));
123
    $sform->setExtra('enctype="multipart / form - data"');
124
125
// Video title
126
    $sform->addElement(new XoopsFormText(_AM_XOOPSTUBE_VIDEO_TITLE, 'title', 70, 255, $title), true);
127
128
// Video source
129
    $vidsource_array  = array(
130
        0   => _AM_XOOPSTUBE_YOUTUBE,
131
        1   => _AM_XOOPSTUBE_METACAFE,
132
        2   => _AM_XOOPSTUBE_IFILM,
133
        3   => _AM_XOOPSTUBE_PHOTOBUCKET,
134
        4   => _AM_XOOPSTUBE_VIDDLER,
135
        100 => _AM_XOOPSTUBE_GOOGLEVIDEO,
136
        101 => _AM_XOOPSTUBE_MYSPAVETV,
137
        102 => _AM_XOOPSTUBE_DAILYMOTION,
138
        103 => _AM_XOOPSTUBE_BLIPTV,
139
        104 => _AM_XOOPSTUBE_CLIPFISH,
140
        105 => _AM_XOOPSTUBE_LIVELEAK,
141
        106 => _AM_XOOPSTUBE_MAKTOOB,
142
        107 => _AM_XOOPSTUBE_VEOH,
143
        108 => _AM_XOOPSTUBE_VIMEO,
144
        109 => _MD_XOOPSTUBE_MEGAVIDEO,
145
        200 => _MD_XOOPSTUBE_XOOPSTUBE
146
    ); // #200 is reserved for XoopsTube's internal FLV player
147
    $vidsource_select = new XoopsFormSelect(_AM_XOOPSTUBE_VIDSOURCE, 'vidsource', $vidsource);
148
    $vidsource_select->addOptionArray($vidsource_array);
149
    $sform->addElement($vidsource_select);
150
151
// Video code
152
    $videocode = new XoopsFormText(_AM_XOOPSTUBE_VIDEO_DLVIDID, 'vidid', 70, 512, $vidid);
153
    $videocode->setDescription('<br /><span style="font-size: small;">' . _AM_XOOPSTUBE_VIDEO_DLVIDIDDSC . '</span>');
154
    $sform->addElement($videocode, true);
155
    $note = _AM_XOOPSTUBE_VIDEO_DLVIDID_NOTE;
156
    $sform->addElement(new XoopsFormLabel('', $note));
157
158
// Picture url
159
    $picurl = new XoopsFormText(_AM_XOOPSTUBE_VIDEO_PICURL, 'picurl', 70, 255, $picurl);
160
    $picurl->setDescription(
161
        '<br /><span style="font-weight: normal;font-size: smaller;">' . _AM_XOOPSTUBE_VIDEO_PICURLNOTE . '</span>'
162
    );
163
    $sform->addElement($picurl, false);
164
165
// Video publisher
166
    $sform->addElement(new XoopsFormText(_AM_XOOPSTUBE_VIDEO_PUBLISHER, 'publisher', 70, 255, $publisher), true);
167
168
// Time form
169
    $timeform = new XoopsFormText(_AM_XOOPSTUBE_TIME, 'time', 7, 7, $time);
170
    $timeform->setDescription('<span style="font-size: small;">(h:mm:ss)</span>');
171
    $sform->addElement($timeform, false);
172
173
// Category menu
174
    ob_start();
175
    $mytree->makeMySelBox('title', 'title', $cid, 0);
176
    $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_VIDEO_CATEGORY, ob_get_contents()));
177
    ob_end_clean();
178
179
// Description form
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
180
//    $editor = xtube_getWysiwygForm( _AM_XOOPSTUBE_VIDEO_DESCRIPTION, 'descriptionb', $descriptionb );
181
//    $sform -> addElement( $editor, false );
182
183
    $optionsTrayNote = new XoopsFormElementTray(_AM_XOOPSTUBE_VIDEO_DESCRIPTION, '<br />');
184 View Code Duplication
    if (class_exists('XoopsFormEditor')) {
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...
185
        $options['name']   = 'descriptionb';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
186
        $options['value']  = $descriptionb;
187
        $options['rows']   = 5;
188
        $options['cols']   = '100%';
189
        $options['width']  = '100%';
190
        $options['height'] = '200px';
191
        $descriptionb      = new XoopsFormEditor('', $xoopsModuleConfig['form_options'], $options, $nohtml = false, $onfailure = 'textarea');
192
        $optionsTrayNote->addElement($descriptionb);
193
    } else {
194
        $descriptionb = new XoopsFormDhtmlTextArea(
195
            '', 'descriptionb', $item->getVar(
0 ignored issues
show
Bug introduced by
The variable $item does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
196
                'descriptionb',
197
                'e'
198
            ), '100%', '100%'
199
        );
200
        $optionsTrayNote->addElement($descriptionb);
201
    }
202
203
    $sform->addElement($optionsTrayNote, false);
204
205
// Meta keywords form
206
    $keywords = new XoopsFormTextArea(_AM_XOOPSTUBE_KEYWORDS, 'keywords', $keywords, 7, 60, false);
207
    $keywords->setDescription(
208
        "<br /><br /><br /><br /><span style='font-size: smaller;'>" . _AM_XOOPSTUBE_KEYWORDS_NOTE . "</span>"
209
    );
210
    $sform->addElement($keywords);
211
212
// Insert tags if Tag-module is installed
213 View Code Duplication
    if (xtubeIsModuleTagInstalled()) {
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...
214
        include_once XOOPS_ROOT_PATH . "/modules/tag/include/formtag.php";
215
        $text_tags = new XoopsFormTag("item_tag", 70, 255, $video_array['item_tag'], 0);
216
        $sform->addElement($text_tags);
217
    } else {
218
        $sform->addElement(new XoopsFormHidden('item_tag', $video_array['item_tag']));
219
    }
220
221
// Video Publish Date
222
    $sform->addElement(new XoopsFormDateTime(_AM_XOOPSTUBE_VIDEO_SETPUBLISHDATE, 'published', $size = 15, $published));
223
224
    if ($lid) {
225
        $sform->addElement(new XoopsFormHidden('was_published', $published));
226
        $sform->addElement(new XoopsFormHidden('was_expired', $expired));
227
    }
228
229
// Video Expire Date
230
    $isexpired           = ($expired > time()) ? 1 : 0;
231
    $expiredates         = ($expired > time()) ? _AM_XOOPSTUBE_VIDEO_EXPIREDATESET . xtubeGetTimestamp(
232
            formatTimestamp($expired, $xoopsModuleConfig['dateformat'])
233
        ) : _AM_XOOPSTUBE_VIDEO_SETDATETIMEEXPIRE;
234
    $warning             = ($published > $expired && $expired > time()) ? _AM_XOOPSTUBE_VIDEO_EXPIREWARNING : '';
235
    $expiredate_checkbox = new XoopsFormCheckBox('', 'expiredateactivate', $isexpired);
236
    $expiredate_checkbox->addOption(1, $expiredates . " <br /> <br /> ");
237
238
    $expiredate_tray = new XoopsFormElementTray(_AM_XOOPSTUBE_VIDEO_EXPIREDATE . $warning, '');
239
    $expiredate_tray->addElement($expiredate_checkbox);
240
    $expiredate_tray->addElement(
241
        new XoopsFormDateTime(_AM_XOOPSTUBE_VIDEO_SETEXPIREDATE . " <br /> ", 'expired', 15, $expired)
242
    );
243
    $expiredate_tray->addElement(
244
        new XoopsFormRadioYN(_AM_XOOPSTUBE_VIDEO_CLEAREXPIREDATE, 'clearexpire', 0, ' ' . _YES . '', ' ' . _NO . '')
245
    );
246
    $sform->addElement($expiredate_tray);
247
248
// Set video offline yes/no
249
    $videostatus_radio = new XoopsFormRadioYN(
250
        _AM_XOOPSTUBE_VIDEO_FILESSTATUS, 'offline', $offline, ' ' . _YES . '', ' ' . _NO . ''
251
    );
252
    $sform->addElement($videostatus_radio);
253
254
// Set video status as updated yes/no
255
    $up_dated            = ($updated == 0) ? 0 : 1;
256
    $video_updated_radio = new XoopsFormRadioYN(
257
        _AM_XOOPSTUBE_VIDEO_SETASUPDATED, 'up_dated', $up_dated, ' ' . _YES . '', ' ' . _NO . ''
258
    );
259
    $sform->addElement($video_updated_radio);
260
261
    $result = $xoopsDB->query(
262
        "SELECT COUNT( * ) FROM " . $xoopsDB->prefix('xoopstube_broken') . " WHERE lid = " . $lid
263
    );
264
    list ($broken_count) = $xoopsDB->fetchRow($result);
265
    if ($broken_count > 0) {
266
        $video_updated_radio = new XoopsFormRadioYN(
0 ignored issues
show
Unused Code introduced by
$video_updated_radio 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...
267
            _AM_XOOPSTUBE_VIDEO_DELEDITMESS, 'delbroken', 1, ' ' . _YES . '', ' ' . _NO . ''
268
        );
269
        $sform->addElement($editmess_radio);
0 ignored issues
show
Bug introduced by
The variable $editmess_radio does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
270
    }
271
272
    if ($lid && $published == 0) {
273
        $approved         = ($published == 0) ? 0 : 1;
0 ignored issues
show
Unused Code introduced by
$approved 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...
274
        $approve_checkbox = new XoopsFormCheckBox(_AM_XOOPSTUBE_VIDEO_EDITAPPROVE, "approved", 1);
275
        $approve_checkbox->addOption(1, " ");
276
        $sform->addElement($approve_checkbox);
277
    }
278
279
    if (!$lid) {
280
        $button_tray = new XoopsFormElementTray('', '');
281
        $button_tray->addElement(new XoopsFormHidden('status', 1));
282
        $button_tray->addElement(new XoopsFormHidden('notifypub', $notifypub));
283
        $button_tray->addElement(new XoopsFormHidden('op', 'save'));
284
        $button_tray->addElement(new XoopsFormButton('', '', _AM_XOOPSTUBE_BSAVE, 'submit'));
285
        $sform->addElement($button_tray);
286
    } else {
287
        $button_tray = new XoopsFormElementTray('', '');
288
        $button_tray->addElement(new XoopsFormHidden('lid', $lid));
289
        $button_tray->addElement(new XoopsFormHidden('status', 2));
290
        $hidden = new XoopsFormHidden('op', 'save');
291
        $button_tray->addElement($hidden);
292
293
        $butt_dup = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMODIFY, 'submit');
294
        $butt_dup->setExtra('onclick="this . form . elements . op . value = \'save\'"');
295
        $button_tray->addElement($butt_dup);
296
        $butt_dupct = new XoopsFormButton('', '', _AM_XOOPSTUBE_BDELETE, 'submit');
297
        $butt_dupct->setExtra('onclick="this.form.elements.op.value=\'delete\'"');
298
        $button_tray->addElement($butt_dupct);
299
        $butt_dupct2 = new XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'submit');
300
        $butt_dupct2->setExtra('onclick="this.form.elements.op.value=\'videosConfigMenu\'"');
301
        $button_tray->addElement($butt_dupct2);
302
        $sform->addElement($button_tray);
303
    }
304
    $sform->display();
305
    unset($hidden);
306
    include_once __DIR__ . '/admin_footer.php';
307
308
    return null;
309
}
310
311
switch (strtolower($op)) {
312
    case 'edit':
313
        edit($lid);
314
        break;
315
316
    case 'save':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
317
318
        $groups    = isset($_POST['groups']) ? $_POST['groups'] : array();
319
        $lid       = (!empty($_POST['lid'])) ? $_POST['lid'] : 0;
320
        $cid       = (!empty($_POST['cid'])) ? $_POST['cid'] : 0;
321
        $vidrating = (!empty($_POST['vidrating'])) ? $_POST['vidrating'] : 6;
322
        $status    = (!empty($_POST['status'])) ? $_POST['status'] : 2;
323
324
// Get data from form
325
        $vidid        = $xtubemyts->addslashes(trim($_POST['vidid']));
326
        $picurl       = ($_POST['picurl'] != 'http://') ? $xtubemyts->addslashes($_POST['picurl']) : '';
327
        $title        = $xtubemyts->addslashes(trim($_POST['title']));
328
        $descriptionb = $xtubemyts->addslashes(trim($_POST['descriptionb']));
329
        $time         = $xtubemyts->addslashes(trim($_POST['time']));
330
        $keywords     = $xtubemyts->addslashes(trim($_POST['keywords']));
331
        $item_tag     = $xtubemyts->addslashes(trim($_POST['item_tag']));
332
        $submitter    = $xoopsUser->uid();
333
        $publisher    = $xtubemyts->addslashes(trim($_POST['publisher']));
334
        $vidsource    = (!empty($_POST['vidsource'])) ? $_POST['vidsource'] : 0;
335
        $updated      = (isset($_POST['was_published']) && $_POST['was_published'] == 0) ? 0 : time();
336
        $published    = strtotime($_POST['published']['date']) + $_POST['published']['time'];
337
338
        if ($_POST['up_dated'] == 0) {
339
            $updated = 0;
340
            $status  = 1;
341
        }
342
343
        $offline   = ($_POST['offline'] == 1) ? 1 : 0;
344
        $approved  = (isset($_POST['approved']) && $_POST['approved'] == 1) ? 1 : 0;
345
        $notifypub = (isset($_POST['notifypub']) && $_POST['notifypub'] == 1);
346
347
        if (!$lid) {
348
            $date        = time();
349
            $publishdate = time();
350
            $expiredate  = '0';
351
        } else {
352
            $publishdate = $_POST['was_published'];
353
            $expiredate  = $_POST['was_expired'];
354
        }
355
        if ($approved == 1 && empty($publishdate)) {
356
            $publishdate = time();
357
        }
358
        if (isset($_POST['expiredateactivate'])) {
359
            $expiredate = strtotime($_POST['expired']['date']) + $_POST['expired']['time'];
360
        }
361
        if ($_POST['clearexpire']) {
362
            $expiredate = '0';
363
        }
364
365
// Update or insert linkload data into database
366
        if (!$lid) {
367
            $date        = time();
368
            $publishdate = time();
369
            $ipaddress   = $_SERVER['REMOTE_ADDR'];
370
            $sql         = "INSERT INTO " . $xoopsDB->prefix('xoopstube_videos')
371
                . " (lid, cid, title, vidid, screenshot, submitter, publisher, status, date, hits, rating, votes, comments, vidsource, published, expired, updated, offline, description, ipaddress, notifypub, vidrating, time, keywords, item_tag, picurl )";
372
            $sql .= " VALUES 	(NULL, $cid, '$title', '$vidid', '', '$submitter', '$publisher', '$status', '$date', 0, 0, 0, 0, '$vidsource', '$published', '$expiredate', '$updated', '$offline', '$descriptionb', '$ipaddress', '0', '$vidrating', '$time', '$keywords', '$item_tag', '$picurl')";
373
            //    $newid = $xoopsDB -> getInsertId();
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
374
        } else {
375
            $sql = "UPDATE " . $xoopsDB->prefix('xoopstube_videos') . " SET cid = $cid, title='$title', vidid='$vidid', screenshot='', publisher='$publisher', status='$status', vidsource='$vidsource', published='$published', expired='$expiredate', updated='$updated', offline='$offline', description='$descriptionb', vidrating='$vidrating', time='$time', keywords='$keywords', item_tag='$item_tag', picurl='$picurl' WHERE lid="
376
                . $lid;
377
        }
378
379
        if (!$result = $xoopsDB->queryF($sql)) {
380
            XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
381
382
            return false;
383
        }
384
385
        $newid = mysql_insert_id();
386
387
// Add item_tag to Tag-module
388 View Code Duplication
        if (!$lid) {
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...
389
            $tagupdate = xtubeUpdateTag($newid, $item_tag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tagupdate is correct as xtubeUpdateTag($newid, $item_tag) (which targets xtubeUpdateTag()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
390
        } else {
391
            $tagupdate = xtubeUpdateTag($lid, $item_tag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tagupdate is correct as xtubeUpdateTag($lid, $item_tag) (which targets xtubeUpdateTag()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
392
        }
393
394
// Send notifications
395
        if (!$lid) {
396
            $tags               = array();
397
            $tags['VIDEO_NAME'] = $title;
398
            $tags['VIDEO_URL']
399
                                   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/singlevideo.php?cid=' . $cid . '&amp;lid=' . $newid;
400
            $sql                   = 'SELECT title FROM ' . $xoopsDB->prefix('xoopstube_cat') . ' WHERE cid=' . $cid;
401
            $result                = $xoopsDB->query($sql);
402
            $row                   = $xoopsDB->fetchArray($xoopsDB->query($sql));
403
            $tags['CATEGORY_NAME'] = $row['title'];
404
            $tags['CATEGORY_URL']
405
                                   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $cid;
406
            $notification_handler  = & xoops_gethandler('notification');
407
            $notification_handler->triggerEvent('global', 0, 'new_video', $tags);
408
            $notification_handler->triggerEvent('category', $cid, 'new_video', $tags);
409
        }
410
        if ($lid && $approved && $notifypub) {
411
            $tags               = array();
412
            $tags['VIDEO_NAME'] = $title;
413
            $tags['VIDEO_URL']
414
                                   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/singlevideo.php?cid=' . $cid . '&amp;lid=' . $lid;
415
            $sql                   = 'SELECT title FROM ' . $xoopsDB->prefix('xoopstube_cat') . ' WHERE cid=' . $cid;
416
            $result                = $xoopsDB->query($sql);
417
            $row                   = $xoopsDB->fetchArray($result);
418
            $tags['CATEGORY_NAME'] = $row['title'];
419
            $tags['CATEGORY_URL']
420
                                   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $cid;
421
            $notification_handler  = & xoops_gethandler('notification');
422
            $notification_handler->triggerEvent('global', 0, 'new_video', $tags);
423
            $notification_handler->triggerEvent('category', $cid, 'new_video', $tags);
424
            $notification_handler->triggerEvent('video', $lid, 'approve', $tags);
425
        }
426
        $message = (!$lid) ? _AM_XOOPSTUBE_VIDEO_NEWFILEUPLOAD : _AM_XOOPSTUBE_VIDEO_FILEMODIFIEDUPDATE;
427
        $message = ($lid && !$_POST['was_published'] && $approved) ? _AM_XOOPSTUBE_VIDEO_FILEAPPROVED : $message;
428
429
        if (xtubeCleanRequestVars($_REQUEST, 'delbroken', 0)) {
430
            $sql = 'DELETE FROM ' . $xoopsDB->prefix('xoopstube_broken') . ' WHERE lid=' . $lid;
431
            if (!$result = $xoopsDB->queryF($sql)) {
432
                XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
433
434
                return false;
435
            }
436
        }
437
438
        redirect_header('main.php', 1, $message);
439
440
        break;
441
442
    case 'delete':
443
        if (xtubeCleanRequestVars($_REQUEST, 'confirm', 0)) {
444
            $title = xtubeCleanRequestVars($_REQUEST, 'title', 0);
445
446
            // delete video
447
            $sql = 'DELETE FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE lid=' . $lid;
448
            if (!$result = $xoopsDB->query($sql)) {
449
                XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
450
451
                return false;
452
            }
453
454
            // delete altcat
455
            $sql = 'DELETE FROM ' . $xoopsDB->prefix('xoopstube_altcat') . ' WHERE lid=' . $lid;
456
            if (!$result = $xoopsDB->query($sql)) {
457
                XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
458
459
                return false;
460
            }
461
462
            // delete vote data
463
            $sql = 'DELETE FROM ' . $xoopsDB->prefix('xoopstube_votedata') . ' WHERE lid=' . $lid;
464
            if (!$result = $xoopsDB->query($sql)) {
465
                XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
466
467
                return false;
468
            }
469
470
            // delete comments
471
            xoops_comment_delete($xoopsModule->getVar('mid'), $lid);
472
            redirect_header('main.php', 1, sprintf(_AM_XOOPSTUBE_VIDEO_FILEWASDELETED, $title));
473
474
            exit();
475
        } else {
476
            $sql = 'SELECT lid, title, item_tag, vidid FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE lid=' . $lid;
477
            if (!$result = $xoopsDB->query($sql)) {
478
                XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
479
480
                return false;
481
            }
482
            list($lid, $title) = $xoopsDB->fetchrow($result);
483
            $item_tag = $result['item_tag'];
484
485
            xoops_cp_header();
486
            //xtubeRenderAdminMenu( _AM_XOOPSTUBE_BINDEX );
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
487
488
            xoops_confirm(
489
                array(
490
                    'op'      => 'delete',
491
                    'lid'     => $lid,
492
                    'confirm' => 1,
493
                    'title'   => $title
494
                ),
495
                'main.php',
496
                _AM_XOOPSTUBE_VIDEO_REALLYDELETEDTHIS . '<br /><br />' . $title,
497
                _DELETE
498
            );
499
500
            // Remove item_tag from Tag-module
501
            $tagupdate = xtubeUpdateTag($lid, $item_tag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tagupdate is correct as xtubeUpdateTag($lid, $item_tag) (which targets xtubeUpdateTag()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
502
503
            include_once __DIR__ . '/admin_footer.php';
504
        }
505
        break;
506
507
    case 'toggle':
508
        if (isset($_REQUEST['lid'])) {
509
            $lid = intval($_REQUEST['lid']);
510
            if (isset($_REQUEST['offline'])) {
511
                $offline = intval($_REQUEST['offline']);
512
                xtubeToggleOffline($lid, $offline);
513
            }
514
        }
515
        break;
516
517
    case 'delvote':
518
        $rid = xtubeCleanRequestVars($_REQUEST, 'rid', 0);
519
        $sql = 'DELETE FROM ' . $xoopsDB->prefix('xoopstube_votedata') . ' WHERE ratingid=' . $rid;
520
        if (!$result = $xoopsDB->queryF($sql)) {
521
            XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
522
523
            return false;
524
        }
525
        xtubeUpdateRating($rid);
526
        redirect_header('main.php', 1, _AM_XOOPSTUBE_VOTE_VOTEDELETED);
527
        break;
528
529
    case 'main':
530
    default:
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
531
532
        $start     = xtubeCleanRequestVars($_REQUEST, 'start', 0);
533
        $start1    = xtubeCleanRequestVars($_REQUEST, 'start1', 0);
534
        $start2    = xtubeCleanRequestVars($_REQUEST, 'start2', 0);
535
        $start3    = xtubeCleanRequestVars($_REQUEST, 'start3', 0);
536
        $start4    = xtubeCleanRequestVars($_REQUEST, 'start4', 0);
537
        $start5    = xtubeCleanRequestVars($_REQUEST, 'start5', 0);
538
        $totalcats = xtubeGetTotalCategoryCount();
539
540
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('xoopstube_broken'));
541
        list($totalbrokenvideos) = $xoopsDB->fetchRow($result);
542
        $result2 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('xoopstube_mod'));
543
        list($totalmodrequests) = $xoopsDB->fetchRow($result2);
544
        $result3 = $xoopsDB->query(
545
            'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE published = 0'
546
        );
547
        list($totalnewvideos) = $xoopsDB->fetchRow($result3);
548
        $result4 = $xoopsDB->query(
549
            'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE published > 0'
550
        );
551
        list($totalvideos) = $xoopsDB->fetchRow($result4);
552
553
        xoops_cp_header();
554
555
        $indexAdmin = new ModuleAdmin();
556
        echo $indexAdmin->addNavigation('main.php');
557
        $indexAdmin->addItemButton(_MI_XOOPSTUBE_ADD_VIDEO, 'main.php?op=edit', 'add', '');
558
        $indexAdmin->addItemButton(_MI_XOOPSTUBE_ADD_CATEGORY, 'category.php', 'add', '');
559
        echo $indexAdmin->renderButton('right', '');
560
561
        //xtubeRenderAdminMenu( _AM_XOOPSTUBE_BINDEX );
562
//    echo '
563
//			<fieldset style="border: #E8E8E8 1px solid;">
564
//			<legend style="display: inline; font-weight: bold; color: #0A3760;">' . _AM_XOOPSTUBE_MINDEX_VIDEOSUMMARY . '</legend>
565
//			<div style="padding: 8px;">
566
//			<span style="font-size: small;">
567
//			<a href="category.php">' . _AM_XOOPSTUBE_SCATEGORY . '</a><b>' . $totalcats . '</b> |
568
//			<a href="main.php">' . _AM_XOOPSTUBE_SFILES . '</a><b>' . $totalvideos . '</b> |
569
//			<a href="newvideos.php">' . _AM_XOOPSTUBE_SNEWFILESVAL . '</a><b>' . $totalnewvideos . '</b> |
570
//			<a href="modifications.php">' . _AM_XOOPSTUBE_SMODREQUEST . '</a><b>' . $totalmodrequests . '</b> |
571
//			<a href="brokenvideo.php">' . _AM_XOOPSTUBE_SBROKENSUBMIT . '</a><b>' . $totalbrokenvideos . '</b>
572
//			</span>
573
//			</div>
574
//			</fieldset>';
575
576
        if ($totalcats > 0) {
577
            $sform = new XoopsThemeForm(_AM_XOOPSTUBE_CCATEGORY_MODIFY, 'category', 'category.php');
578
            ob_start();
579
            $mytree->makeMySelBox('title', 'title');
580
            $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_CCATEGORY_MODIFY_TITLE, ob_get_contents()));
581
            ob_end_clean();
582
            $dup_tray = new XoopsFormElementTray('', '');
583
            $dup_tray->addElement(new XoopsFormHidden('op', 'modCat'));
584
            $butt_dup = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMODIFY, 'submit');
585
            $butt_dup->setExtra('onclick="this.form.elements.op.value=\'modCat\'"');
586
            $dup_tray->addElement($butt_dup);
587
            $butt_dupct = new XoopsFormButton('', '', _AM_XOOPSTUBE_BDELETE, 'submit');
588
            $butt_dupct->setExtra('onclick="this.form.elements.op.value=\'del\'"');
589
            $dup_tray->addElement($butt_dupct);
590
            $sform->addElement($dup_tray);
591
            $sform->display();
592
593
//TODO add table with categories
594
595
596
//            $sql='SELECT * FROM ' . $xoopsDB->prefix('xoopstube_cat') . ' ORDER BY cid DESC';
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
597
//            $published_array       = $xoopsDB->query($sql, $xoopsModuleConfig['admin_perpage'], $start);
598
//            $published_array_count = $xoopsDB->getRowsNum($xoopsDB->query($sql));
599
//            xtubeRenderCategoryListHeader(_AM_XOOPSTUBE_MINDEX_PUBLISHEDVIDEO);
600
//            xtubeSetPageNavigationCategoryList($published_array_count, $start, 'art', '', 'left');
601
//            if ($published_array_count > 0) {
602
//                while ($published = $xoopsDB->fetchArray($published_array)) {
603
//                    xtubeRenderCategoryListBody($published);
604
//                }
605
//                echo '</table>';
606
//            } else {
607
//                xtubeRenderCategoryListFooter();
608
//            }
609
//            xtubeSetPageNavigationCategoryList($published_array_count, $start, 'art', '', 'right');
610
611
612
        }
613
614
        if ($totalvideos > 0) {
615
            $sql
616
                                   = 'SELECT * FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE published > 0  ORDER BY lid DESC';
617
            $published_array       = $xoopsDB->query($sql, $xoopsModuleConfig['admin_perpage'], $start);
618
            $published_array_count = $xoopsDB->getRowsNum($xoopsDB->query($sql));
619
            xtubeRenderVideoListHeader(_AM_XOOPSTUBE_MINDEX_PUBLISHEDVIDEO);
620
            xtubeSetPageNavigationVideoList($published_array_count, $start, 'art', '', 'left');
621
            if ($published_array_count > 0) {
622
                while ($published = $xoopsDB->fetchArray($published_array)) {
623
                    xtubeRenderVideoListBody($published);
624
                }
625
                echo '</table>';
626
            } else {
627
                xtubeRenderVideoListFooter();
628
            }
629
            xtubeSetPageNavigationVideoList($published_array_count, $start, 'art', '', 'right');
630
        }
631
        include_once __DIR__ . '/admin_footer.php';
632
        break;
633
}
634
/**
635
 * @param $lid
636
 * @param $offline
637
 *
638
 * @return bool|null
639
 */
640
function xtubeToggleOffline($lid, $offline)
641
{
642
    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...
643
    $message = '';
0 ignored issues
show
Unused Code introduced by
$message 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...
644
    $offline = ($offline == 1) ? 0 : 1;
645
646
    if ($offline) {
647
        $message = _AM_XOOPSTUBE_TOGGLE_OFFLINE_SUCCESS;
648
    } else {
649
        $message = _AM_XOOPSTUBE_TOGGLE_ONLINE_SUCCESS;
650
    }
651
652
//    $this_handler   =& xoops_getModuleHandler('xoopstube_videos', 'xoopstube');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
653
//    $obj            = $this_handler->get($lid);
654
//    $obj->setVar('offline', $offline);
655
//    if ($this_handler->insert($obj, true)) {
656
//        redirect_header('main.php', 1, _AM_XOOPSTUBE_TOGGLE_SUCCESS);
657
//    } else {
658
//        redirect_header('main.php', 1, _AM_XOOPSTUBE_TOGGLE_FAILED);
659
//    }
660
661
    $sql = "UPDATE " . $xoopsDB->prefix('xoopstube_videos') . " SET  offline='$offline' WHERE lid=" . $lid;
662
663
    if (!$result = $xoopsDB->queryF($sql)) {
664
        redirect_header('main.php', 1, _AM_XOOPSTUBE_TOGGLE_FAILED);
665
666
        return false;
667
    } else {
668
        redirect_header('main.php', 1, $message);
669
    }
670
671
    return null;
672
}
673