Passed
Push — master ( d34a4c...bd8813 )
by Michael
02:49 queued 28s
created

xtube_showvideo()   D

Complexity

Conditions 18
Paths 34

Size

Total Lines 109
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 18
eloc 66
c 1
b 0
f 0
nc 34
nop 4
dl 0
loc 109
rs 4.8666

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
 * @param $returnsource
6
 * @return
7
 */
8
9
function xtube_returnsource($returnsource)
10
{
11
    $returnsource = match ($returnsource) {
12
        0 => _AM_XTUBE_YOUTUBE,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_YOUTUBE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
        1 => _AM_XTUBE_METACAFE,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_METACAFE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
14
        2 => _AM_XTUBE_IFILM,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_IFILM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
15
        3 => _AM_XTUBE_PHOTOBUCKET,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_PHOTOBUCKET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
        4 => _AM_XTUBE_VIDDLER,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_VIDDLER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
17
        100 => _AM_XTUBE_GOOGLEVIDEO,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_GOOGLEVIDEO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
18
        101 => _AM_XTUBE_MYSPAVETV,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_MYSPAVETV was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
19
        102 => _AM_XTUBE_DAILYMOTION,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_DAILYMOTION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
20
        103 => _AM_XTUBE_BLIPTV,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_BLIPTV was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21
        104 => _AM_XTUBE_CLIPFISH,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_CLIPFISH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
22
        105 => _AM_XTUBE_LIVELEAK,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_LIVELEAK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
23
        106 => _AM_XTUBE_MAKTOOB,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_MAKTOOB was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
24
        107 => _AM_XTUBE_VEOH,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_VEOH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
        108 => _AM_XTUBE_VIMEO,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_VIMEO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
26
        109 => _AM_XTUBE_MEGAVIDEO,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_MEGAVIDEO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
        200 => _AM_XTUBE_XOOPSTUBE,
0 ignored issues
show
Bug introduced by
The constant _AM_XTUBE_XOOPSTUBE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
28
        default => $returnsource,
29
    };
30
31
    return $returnsource;
32
}
33
34
// *******************************************************
35
// Function for determining source for creating screenshot
36
// *******************************************************
37
/**
38
 * @param        $vidid
39
 * @param        $title
40
 * @param        $source
41
 * @param        $picurl
42
 * @param        $screenshot
43
 * @param string $width
44
 * @param string $height
45
 * @return string
46
 */
47
function xtube_videothumb($vidid, $title, $source, $picurl, $screenshot, $width = '', $height = '')
48
{
49
    global $xoopsModuleConfig;
50
    if ('' == $width || '' == $height) {
51
        $width  = $xoopsModuleConfig['shotwidth'];
52
        $height = $xoopsModuleConfig['shotheight'];
53
    }
54
    $thumb = '';
55
    switch ($source) {
56
        // YouTube
57
        case 0:
58
            $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;" />';
59
            break;
60
61
        // MetaCafe
62
        case 1:
63
            [$metaclip] = preg_split('[/]', (string) $vidid);
64
            $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...
65
            $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;" />';
66
            break;
67
68
        // iFilm/Spike
69
        case 2:
70
            $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;" />';
71
            break;
72
73
        // Photobucket
74
        case 3:
75
            $thumb = '<img src="https://i153.photobucket.com/albums/' . $vidid . '.jpg" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;" />';
76
            break;
77
78
        // Photobucket
79
        case 4:
80
            $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;" />';
81
            break;
82
83
        // Google Video, MySpace TV, DailyMotion, BrightCove, Blip.tv, ClipFish, LiveLeak, Maktoob, Veoh
84
        case 100:
85
        case 101:
86
        case 102:
87
        case 103:
88
        case 104:
89
        case 105:
90
        case 106:
91
        case 107:
92
        case 108:
93
        case 109:
94
            $thumb = '<img src="' . $picurl . '" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;" />';
95
            break;
96
97
        // Determine if video source is XoopsTube for thumbnail
98
        case 200:
99
            $thumb = '<img src="' . XOOPS_URL . '/' . $screenshot . '" width="' . $width . '" height="' . $height . '"  title="' . $title . '" alt="' . $title . '" style="padding: 0px; border-style: none;" />';
100
            break;
101
    }
102
103
    return $thumb;
104
}
105
106
// **********************************
107
// Function for determining publisher
108
// **********************************
109
/**
110
 * @param     $vidid
111
 * @param     $publisher
112
 * @param int $source
113
 * @return string
114
 */
115
function xtube_videopublisher($vidid, $publisher, $source = 0)
116
{
117
    switch ($source) {
118
        // Determine if video source YouTube for publisher
119
        case 0:
120
            $publisher = '<a href="https://www.youtube.com/profile?user=' . $publisher . '" target="_blank">' . $publisher . '</a>';
121
            break;
122
123
        // Determine if video source MetaCafe for publisher
124
        case 1:
125
            $publisher = '<a href="https://www.metacafe.com/channels/' . $publisher . '" target="_blank">' . $publisher . '</a>';
126
            break;
127
128
        // Determine if video source iFilm/Spike for publisher
129
        case 2:
130
            $publisher = '<a href="https://www.ifilm.com/profile/' . $publisher . '" target="_blank">' . $publisher . '</a>';
131
            break;
132
133
        // Determine if video source Photobucket for publisher
134
        case 3:
135
            $string = 'th_';
136
            [$photobucket] = explode($string, (string) $vidid);
137
            $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...
138
            $publisher                = '<a href="https://s39.photobucket.com/albums/' . $ppublisher['ppublisher'] . '" target="_blank">' . $publisher . '</a>';
139
            break;
140
141
        // Determine if video source is Viddler for publisher
142
        case 4:
143
            $publisher = '<a href="https://www.viddler.com/explore/' . $publisher . '/" target="_blank">' . $publisher . '</a>';
144
            break;
145
146
        // Determine if video source is Google Video for publisher
147
        case 100:
148
        case 101:
149
        case 103:
150
        case 106:
151
        case 108:
152
        case 109:
153
            $publisher = $publisher;
154
            break;
155
156
        // Determine if video source is DailyMotion for publisher
157
        case 102:
158
            $publisher = '<a href="https://www.dailymotion.com/' . $publisher . '" target="_blank">' . $publisher . '</a>';
159
            break;
160
161
        // Determine if video source is ClipFish for publisher
162
        case 104:
163
            $publisher = '<a href="https://www.clipfish.de/user/' . $publisher . '" target="_blank">' . $publisher . '</a>';
164
            break;
165
166
        // Determine if video source is LiveLeak for publisher
167
        case 105:
168
            $publisher = '<a href="https://www.liveleak.com/user/' . $publisher . '" target="_blank">' . $publisher . '</a>';
169
            break;
170
171
        // Determine if video source is Veoh for publisher
172
        case 107:
173
            $publisher = '<a href="https://www.veoh.com/users/' . $publisher . '" target="_blank">' . $publisher . '</a>';
174
            break;
175
176
        // Determine if video source is XoopsTube for publisher
177
        case 200:
178
            $publisher = $publisher;
179
            break;
180
    }
181
182
    return $publisher;
183
}
184
185
// ************************************************
186
//Function for displaying videoclip (embedded code)
187
// ************************************************
188
/**
189
 * @param $vidid
190
 * @param $source
191
 * @param $screenshot
192
 * @param $picurl
193
 * @return string
194
 */
195
function xtube_showvideo($vidid, $source, $screenshot, $picurl)
196
{
197
    global $xoopsModule, $xoopsModuleConfig;
198
    $showvideo = '';
199
    $autoplay  = $xoopsModuleConfig['autoplay'];
200
    if ($xoopsModuleConfig['autoplay']) {
201
        $autoplay2   = 'yes';
202
        $autoplay3   = 'true';
203
        $photobucket = '&ap=1';
204
        $google      = 'FlashVars="autoPlay=true"';
205
        $viddler     = 'flashvars="autoplay=t"';
206
    } else {
207
        $autoplay2   = 'no';
208
        $autoplay3   = 'false';
209
        $photobucket = '';
210
        $google      = '';
211
        $viddler     = '';
212
    }
213
214
    //    $hquality = '';
215
    //    if ($hq == 1) {
216
    //        $hquality = '&ap=%2526fmt%3D18&';
217
    //    }
218
219
    switch ($source) {
220
        // YouTube
221
        case 0:
222
            //  $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>';
223
            $showvideo = '<embed src="https://www.youtube.com/v/' . $vidid . '&autoplay=' . $autoplay . '&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="480"></embed>';
224
            break;
225
226
        // MetaCafe
227
        case 1:
228
            $showvideo = '<embed flashVars="playerVars=showStats=no|autoPlay=' . $autoplay2 . '" src="https://www.metacafe.com/fplayer/' . $vidid . '.swf" width="853" height="480" wmode="transparent" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
229
            break;
230
231
        // iFilm/Spike
232
        case 2:
233
            $showvideo = '<embed width="853" height="480" 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=' . $vidid . '" allowfullscreen="true"> </embed>';
234
            break;
235
236
        // Photobucket
237
        case 3:
238
            $vidid     = str_replace('th_', '', (string) $vidid);
239
            $showvideo = '<embed width="853" height="480" type="application/x-shockwave-flash" wmode="transparent" src="https://i51.photobucket.com/player.swf?file=https://vid51.photobucket.com/albums/' . $vidid . '.flv' . $photobucket . '"></embed>';
240
            break;
241
242
        // Viddler
243
        case 4:
244
            $showvideo = '<embed src="https://www.viddler.com/player/' . $vidid . '/" width="853" height="480" type="application/x-shockwave-flash" ' . $viddler . ' allowScriptAccess="always" allowFullScreen="true" name="viddler_' . $vidid . '" ></embed>';
245
            break;
246
247
        // Google Video
248
        case 100:
249
            $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>';
250
            break;
251
252
        // MySpace TV
253
        case 101:
254
            $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>';
255
            break;
256
257
        // DailyMotion
258
        case 102:
259
            $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>';
260
            break;
261
262
        // Blip.tv
263
        case 103:
264
            $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>';
265
            break;
266
267
        // ClipFish
268
        case 104:
269
            $showvideo = '<embed src="https://www.clipfish.de/videoplayer.swf?as=' . $autoplay . '&videoid=' . $vidid . '==&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
270
            break;
271
272
        // LiveLeak
273
        case 105:
274
            $showvideo = '<embed src="https://www.liveleak.com/e/' . $vidid . '" type="application/x-shockwave-flash" flashvars="autostart=' . $autoplay3 . '" wmode="transparent" width="450" height="370"></embed>';
275
            break;
276
277
        // Maktoob
278
        case 106:
279
            $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://' . $vidid . '.flv&enablejs=true&image=' . $picurl . '&lightcolor=0x557722&backcolor=0x000000&frontcolor=0xCCCCCC&showfsbutton=true&autostart=' . $autoplay3 . '&logo=https://clipat.maktoob.com/language/ar_sa/images/clipat-icon.png&displaywidth=448" />';
280
            break;
281
282
        // Veoh
283
        case 107:
284
            $showvideo = '<embed src="https://www.veoh.com/veohplayer.swf?permalinkId=' . $vidid . '&id=anonymous&player=videodetailsembedded&affiliateId=&videoAutoPlay=' . $autoplay . '" allowFullScreen="true" width="480" height="295" bgcolor="#FFFFFF" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer"></embed>';
285
            break;
286
287
        // Vimeo
288
        case 108:
289
            $showvideo = '<embed src="https://vimeo.com/moogaloop.swf?clip_id=' . $vidid . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1&autoplay=' . $autoplay . '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" quality="best" width="400" height="321"></embed>';
290
            break;
291
292
        // Megavideo
293
        case 109:
294
            $showvideo = '<object width="640" height="363"><param name="movie" value="https://www.megavideo.com/v/' . $vidid . '"></param><param name="allowFullScreen" value="true"></param><embed src="https://www.megavideo.com/v/' . $vidid . '" type="application/x-shockwave-flash" allowfullscreen="true" width="640" height="363"></embed></object>';
295
            break;
296
297
        // XoopsTube
298
        case 200:
299
            $showvideo = '<embed src="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/include/mediaplayer.swf" width="425" height="350" allowScriptAccess="always" allowFullScreen="true" flashvars="width=425&height=350&file=' . XOOPS_URL . '/' . $xoopsModuleConfig['videodir'] . '/' . $vidid . '&image=' . XOOPS_URL . '/' . $xoopsModuleConfig['videoimgdir'] . '/' . $screenshot . '&autostart=' . $autoplay3 . '"></embed>';
300
            break;
301
    }
302
303
    return $showvideo;
304
}
305