xtubeShowVideo()   F
last analyzed

Complexity

Conditions 18
Paths 34

Size

Total Lines 143
Code Lines 98

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 98
nc 34
nop 4
dl 0
loc 143
rs 3.9369
c 0
b 0
f 0

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
2
3
/**
4
 * Module: XoopsTube
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * PHP version 5
11
 *
12
 * @param $returnsource
13
 *
14
 * @return string
15
 * @author          XOOPS Development Team
16
 * @copyright       2001-2016 XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 * @link            https://xoops.org/
19
 * @since           1.0.6
20
 *
21
 * @category        Module
22
 * @package         Xoopstube
23
 */
24
function xtubeReturnSource($returnsource)
25
{
26
    switch ($returnsource) {
27
        case 0:
28
            $returnsource = _AM_XOOPSTUBE_YOUTUBE;
29
            break;
30
        case 1:
31
            $returnsource = _AM_XOOPSTUBE_METACAFE;
32
            break;
33
        case 2:
34
            $returnsource = _AM_XOOPSTUBE_IFILM;
35
            break;
36
        case 3:
37
            $returnsource = _AM_XOOPSTUBE_PHOTOBUCKET;
38
            break;
39
        case 4:
40
            $returnsource = _AM_XOOPSTUBE_VIDDLER;
41
            break;
42
        case 100:
43
            $returnsource = _AM_XOOPSTUBE_GOOGLEVIDEO;
44
            break;
45
        case 101:
46
            $returnsource = _AM_XOOPSTUBE_MYSPAVETV;
47
            break;
48
        case 102:
49
            $returnsource = _AM_XOOPSTUBE_DAILYMOTION;
50
            break;
51
        case 103:
52
            $returnsource = _AM_XOOPSTUBE_BLIPTV;
53
            break;
54
        case 104:
55
            $returnsource = _AM_XOOPSTUBE_CLIPFISH;
56
            break;
57
        case 105:
58
            $returnsource = _AM_XOOPSTUBE_LIVELEAK;
59
            break;
60
        case 106:
61
            $returnsource = _AM_XOOPSTUBE_MAKTOOB;
62
            break;
63
        case 107:
64
            $returnsource = _AM_XOOPSTUBE_VEOH;
65
            break;
66
        case 108:
67
            $returnsource = _AM_XOOPSTUBE_VIMEO;
68
            break;
69
        case 109:
70
            $returnsource = _AM_XOOPSTUBE_MEGAVIDEO;
71
            break;
72
        case 200:
73
            $returnsource = _AM_XOOPSTUBE_XOOPSTUBE;
74
            break;
75
    }
76
77
    return $returnsource;
78
}
79
80
// *******************************************************
81
// Function for determining source for creating screenshot
82
// *******************************************************
83
/**
84
 * @param        $vidid
85
 * @param        $title
86
 * @param        $source
87
 * @param        $picurl
88
 * @param        $screenshot
89
 * @param string $width
90
 * @param string $height
91
 *
92
 * @return string
93
 */
94
function xtubeGetVideoThumb($vidid, $title, $source, $picurl, $screenshot, $width = '', $height = '')
95
{
96
    if ('' === $width || '' === $height) {
97
        $width  = $GLOBALS['xoopsModuleConfig']['shotwidth'];
98
        $height = $GLOBALS['xoopsModuleConfig']['shotheight'];
99
    }
100
    $thumb = '';
101
    switch ($source) {
102
        // YouTube
103
        case 0:
104
            $thumb = '<img src="https://img.youtube.com/vi/' . $vidid . '/default.jpg"  title="' . $title . '" alt="' . $title . '" width="' . $width . '" height="' . $height . '" style="padding: 0px; border-style: none;">';
105
            break;
106
        // MetaCafe
107
        case 1:
108
            [$metaclip] = explode('[/]', $vidid);
109
            $videothumb['metathumb'] = $metaclip;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$videothumb was never initialized. Although not strictly required by PHP, it is generally a good practice to add $videothumb = array(); before regardless.
Loading history...
110
            $thumb                   = '<img src="https://www.metacafe.com/thumb/' . $videothumb['metathumb'] . '.jpg" title="' . $title . '" alt="' . $title . '" width="' . $width . '" height="' . $height . '" style="padding: 0px; border-style: none;">';
111
            break;
112
        // iFilm/Spike
113
        case 2:
114
            $thumb = '<img src="https://img3.ifilmpro.com/resize/image/stills/films/resize/istd/' . $vidid . '.jpg?width=' . $width . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;">';
115
            break;
116
        // Photobucket
117
        case 3:
118
            $thumb = '<img src="https://i153.photobucket.com/albums/' . $vidid . '.jpg" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;">';
119
            break;
120
        // Photobucket
121
        case 4:
122
            $thumb = '<img src="https://cdn-thumbs.viddler.com/thumbnail_2_' . $vidid . '.jpg" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;">';
123
            break;
124
        // Google Video, MySpace TV, DailyMotion, BrightCove, Blip.tv, ClipFish, LiveLeak, Maktoob, Veoh
125
        case 100:
126
        case 101:
127
        case 102:
128
        case 103:
129
        case 104:
130
        case 105:
131
        case 106:
132
        case 107:
133
        case 108:
134
        case 109:
135
            $thumb = '<img src="' . $picurl . '" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;">';
136
            break;
137
        // Determine if video source is XoopsTube for thumbnail
138
        case 200:
139
            $thumb = '<img src="' . XOOPS_URL . '/' . $screenshot . '" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;">';
140
            break;
141
    }
142
143
    return $thumb;
144
}
145
146
// **********************************
147
// Function for determining publisher
148
// **********************************
149
/**
150
 * @param     $vidid
151
 * @param     $publisher
152
 * @param int $source
153
 *
154
 * @return string
155
 */
156
function xtubeGetVideoPublisher($vidid, $publisher, $source = 0)
157
{
158
    switch ($source) {
159
        // Determine if video source YouTube for publisher
160
        case 0:
161
            $publisher = '<a href="https://www.youtube.com/profile?user=' . $publisher . '" target="_blank">' . $publisher . '</a>';
162
            break;
163
        // Determine if video source MetaCafe for publisher
164
        case 1:
165
            $publisher = '<a href="https://www.metacafe.com/channels/' . $publisher . '" target="_blank">' . $publisher . '</a>';
166
            break;
167
        // Determine if video source iFilm/Spike for publisher
168
        case 2:
169
            $publisher = '<a href="https://www.ifilm.com/profile/' . $publisher . '" target="_blank">' . $publisher . '</a>';
170
            break;
171
        // Determine if video source Photobucket for publisher
172
        case 3:
173
            $string = 'th_';
174
            [$photobucket] = explode($string, $vidid);
175
            $ppublisher['ppublisher'] = $photobucket;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ppublisher was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ppublisher = array(); before regardless.
Loading history...
176
            $publisher                = '<a href="https://s39.photobucket.com/albums/' . $ppublisher['ppublisher'] . '" target="_blank">' . $publisher . '</a>';
177
            break;
178
        // Determine if video source is Viddler for publisher
179
        case 4:
180
            $publisher = '<a href="https://www.viddler.com/explore/' . $publisher . '/" target="_blank">' . $publisher . '</a>';
181
            break;
182
        // Determine if video source is Google Video for publisher
183
        case 100:
184
        case 101:
185
        case 103:
186
        case 106:
187
        case 108:
188
        case 109:
189
            //            $publisher = $publisher;
190
            break;
191
        // Determine if video source is DailyMotion for publisher
192
        case 102:
193
            $publisher = '<a href="https://www.dailymotion.com/' . $publisher . '" target="_blank">' . $publisher . '</a>';
194
            break;
195
        // Determine if video source is ClipFish for publisher
196
        case 104:
197
            $publisher = '<a href="https://www.clipfish.de/user/' . $publisher . '" target="_blank">' . $publisher . '</a>';
198
            break;
199
        // Determine if video source is LiveLeak for publisher
200
        case 105:
201
            $publisher = '<a href="https://www.liveleak.com/user/' . $publisher . '" target="_blank">' . $publisher . '</a>';
202
            break;
203
        // Determine if video source is Veoh for publisher
204
        case 107:
205
            $publisher = '<a href="https://www.veoh.com/users/' . $publisher . '" target="_blank">' . $publisher . '</a>';
206
            break;
207
        // Determine if video source is XoopsTube for publisher
208
        case 200:
209
            //            $publisher = $publisher;
210
            break;
211
    }
212
213
    return $publisher;
214
}
215
216
// ************************************************
217
//Function for displaying videoclip (embedded code)
218
// ************************************************
219
/**
220
 * @param $vidid
221
 * @param $source
222
 * @param $screenshot
223
 * @param $picurl
224
 *
225
 * @return string
226
 */
227
function xtubeShowVideo($vidid, $source, $screenshot, $picurl)
0 ignored issues
show
Unused Code introduced by
The parameter $screenshot is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

227
function xtubeShowVideo($vidid, $source, /** @scrutinizer ignore-unused */ $screenshot, $picurl)

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

Loading history...
228
{
229
    global $xoopsModule;
230
    $showvideo = '';
231
    $autoplay  = $GLOBALS['xoopsModuleConfig']['autoplay'];
232
    if ($GLOBALS['xoopsModuleConfig']['autoplay']) {
233
        $autoplay2   = 'yes';
234
        $autoplay3   = 'true';
235
        $photobucket = '&ap=1';
236
        $google      = 'FlashVars="autoPlay=true"';
237
        $viddler     = 'flashvars="autoplay=t"';
238
    } else {
239
        $autoplay2   = 'no';
240
        $autoplay3   = 'false';
241
        $photobucket = '';
242
        $google      = '';
243
        $viddler     = '';
244
    }
245
246
    //  $hquality = '';
247
    //  if ($hq == 1) {
248
    //      $hquality = '&ap=%2526fmt%3D18&';
249
    //  }
250
251
    switch ($source) {
252
        // YouTube
253
        case 0:
254
            //  $showvideo = '<object width="480" height="295"><param name="movie" value="https://www.youtube.com/v/' . $vidid . '&ap=%2526fmt%3D18&&autoplay=' . $autoplay . '&rel=1&fs=1&color1=0x999999&color2=0x999999&border=0&loop=0"></param><param name="wmode" value="transparent"></param><embed src="https://www.youtube.com/v/' . $vidid . '&ap=%2526fmt%3D18&&autoplay=' . $autoplay . '&rel=1&fs=1&color1=0x999999&color2=0x999999&border=0&loop=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="480" height="295"></embed></object>';
255
            //            $showvideo = '<embed src="https://www.youtube.com/v/' . $vidid . '&autoplay=' . $autoplay
256
            //                         . '&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed>';
257
258
            $showvideo = '<iframe src="https://www.youtube.com/embed/' . $vidid . '?html5=1&amp;rel=0&amp;hl=en_US&amp;version=3' . '&autoplay=' . $autoplay . '&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></iframe>';
259
            break;
260
        // MetaCafe
261
        case 1:
262
            $showvideo = '<embed flashVars="playerVars=showStats=no|autoPlay='
263
                         . $autoplay2
264
                         . '" src="https://www.metacafe.com/fplayer/'
265
                         . $vidid
266
                         . '.swf" width="480" height="295" wmode="transparent" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
267
            break;
268
        // iFilm/Spike
269
        case 2:
270
            $showvideo = '<embed width="480" height="295" src="https://www.spike.com/efp" quality="high" bgcolor="000000" name="efp" align="middle" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" flashvars="flvbaseclip='
271
                         . $vidid
272
                         . '" allowfullscreen="true"> </embed>';
273
            break;
274
        // Photobucket
275
        case 3:
276
            $vidid     = str_replace('th_', '', $vidid);
277
            $showvideo = '<embed width="480" height="295" type="application/x-shockwave-flash" wmode="transparent" src="https://i51.photobucket.com/player.swf?file=https://vid51.photobucket.com/albums/' . $vidid . '.flv' . $photobucket . '"></embed>';
278
            break;
279
        // Viddler
280
        case 4:
281
            $showvideo = '<embed src="https://www.viddler.com/player/' . $vidid . '/" width="480" height="295" type="application/x-shockwave-flash" ' . $viddler . ' allowScriptAccess="always" allowFullScreen="true" name="viddler_' . $vidid . '" ></embed>';
282
            break;
283
        // Google Video
284
        case 100:
285
            $showvideo = '<embed style="width:480px; height:295px;" id="VideoPlayback" type="application/x-shockwave-flash" src="https://video.google.com/googleplayer.swf?docId=' . $vidid . '&hl=en" ' . $google . '> </embed>';
286
            break;
287
        // MySpace TV
288
        case 101:
289
            $showvideo = '<embed src="https://mediaservices.myspace.com/services/media/embed.aspx/m=' . $vidid . ',t=1,mt=video,ap=' . $autoplay . '" width="480" height="295" allowFullScreen="true" type="application/x-shockwave-flash"></embed>';
290
            break;
291
        // DailyMotion
292
        case 102:
293
            $showvideo = '<embed src="https://www.dailymotion.com/swf/' . $vidid . '&autoPlay=' . $autoplay . '" type="application/x-shockwave-flash" width="480" height="295" allowFullScreen="true" allowScriptAccess="always"></embed>';
294
            break;
295
        // Blip.tv
296
        case 103:
297
            $showvideo = '<embed src="https://blip.tv/play/' . $vidid . '" type="application/x-shockwave-flash" width="480" height="295" allowscriptaccess="always" allowfullscreen="true" flashvars="autostart=' . $autoplay3 . '"></embed>';
298
            break;
299
        // ClipFish
300
        case 104:
301
            $showvideo = '<embed src="https://www.clipfish.de/videoplayer.swf?as='
302
                         . $autoplay
303
                         . '&videoid='
304
                         . $vidid
305
                         . '==&r=1&c=0067B3" quality="high" bgcolor="#0067B3" width="464" height="380" name="player" align="middle" allowFullScreen="true" allowScriptAccess="always"  type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer"></embed>'; // Change c=0067B3 for different player color
306
            break;
307
        // LiveLeak
308
        case 105:
309
            $showvideo = '<embed src="https://www.liveleak.com/e/' . $vidid . '" type="application/x-shockwave-flash" flashvars="autostart=' . $autoplay3 . '" wmode="transparent" width="450" height="370"></embed>';
310
            break;
311
        // Maktoob
312
        case 106:
313
            $showvideo = '<embed width="448" height="320" align="middle" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="flvplayer" bgcolor="#ffffff" devicefont="true" wmode="transparent" quality="high" src="https://clipat.maktoob.com/flvplayerOurJS.swf?file=https://'
314
                         . $vidid
315
                         . '.flv&enablejs=true&image='
316
                         . $picurl
317
                         . '&lightcolor=0x557722&backcolor=0x000000&frontcolor=0xCCCCCC&showfsbutton=true&autostart='
318
                         . $autoplay3
319
                         . '&logo=https://clipat.maktoob.com/language/ar_sa/images/clipat-icon.png&displaywidth=448">';
320
            break;
321
        // Veoh
322
        case 107:
323
            $showvideo = '<embed src="https://www.veoh.com/veohplayer.swf?permalinkId='
324
                         . $vidid
325
                         . '&id=anonymous&player=videodetailsembedded&affiliateId=&videoAutoPlay='
326
                         . $autoplay
327
                         . '" allowFullScreen="true" width="480" height="295" bgcolor="#FFFFFF" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer"></embed>';
328
            break;
329
        // Vimeo
330
        case 108:
331
            $showvideo = '<embed src="https://vimeo.com/moogaloop.swf?clip_id='
332
                         . $vidid
333
                         . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1&autoplay='
334
                         . $autoplay
335
                         . '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" quality="best" width="400" height="321"></embed>';
336
            break;
337
        // Megavideo
338
        case 109:
339
            $showvideo = '<object width="640" height="363"><param name="movie" value="https://www.megavideo.com/v/'
340
                         . $vidid
341
                         . '"></param><param name="allowFullScreen" value="true"></param><embed src="https://www.megavideo.com/v/'
342
                         . $vidid
343
                         . '" type="application/x-shockwave-flash" allowfullscreen="true" width="640" height="363"></embed></object>';
344
            break;
345
        // XoopsTube
346
        case 200:
347
            //        $showvideo = '<embed src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname')
348
            //            . '/include/mediaplayer.swf" width="425" height="350" allowScriptAccess="always" allowFullScreen="true" flashvars="width=425&height=350&file='
349
            //            . XOOPS_URL . '/' . $GLOBALS['xoopsModuleConfig']['videodir'] . '/' . $vidid . '&image=' . XOOPS_URL . '/'
350
            //            . $GLOBALS['xoopsModuleConfig']['videoimgdir'] . '/' . $screenshot . '&autostart=' . $autoplay3 . '"></embed>';
351
352
            $showvideo = '
353
                     <script type="text/javascript" src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/flvplayer/flowplayer/flowplayer.min.js"></script>
354
                     <a href="' . XOOPS_URL . '/' . $xoopsModule->getVar('dirname') . '/' . $vidid . '" style="display: block; width: 520px; height: 330px;" id="player"></a>
355
                     <script>
356
                         flowplayer("player", "' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/flvplayer/flowplayer/flowplayer.swf", {
357
                             clip: {
358
                                 autoPlay: ' . $autoplay3 . ',
359
                                 autoBuffering: true
360
                                 }
361
                             }
362
                         );
363
                     </script>
364
                     ';
365
366
            break;
367
    }
368
369
    return $showvideo;
370
}
371