Ajde_Embed_Mixcloud::getThumbnail()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Ajde_Embed_Mixcloud extends Ajde_Embed
4
{
5
    public function convertUrlToEmbed()
6
    {
7
        if (substr($this->_code, 0, 7) == 'http://' || substr($this->_code, 0, 8) == 'https://') {
8
            $this->_code = '<div><object width="480" height="480"><param name="movie" value="http://www.mixcloud.com/media/swf/player/mixcloudLoader.swf?feed='.urlencode($this->_code).'&embed_type=widget_standard"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="opaque"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.mixcloud.com/media/swf/player/mixcloudLoader.swf?feed='.urlencode($this->_code).'&embed_type=widget_standard" type="application/x-shockwave-flash" wmode="opaque" allowscriptaccess="always" allowfullscreen="true" width="480" height="480"></embed></object><div style="clear:both; height:3px;"></div><div style="clear:both; height:3px;"></div></div>';
9
        }
10
    }
11
12
    public function getCode()
13
    {
14
        $this->convertUrlToEmbed();
15
        $this->_setHeight();
16
        $this->_setWidth();
17
        $this->stripTags();
18
19
        return $this->_code;
20
    }
21
22
    private function _getMixcloudUrl()
23
    {
24
        if (substr($this->_code, 0, 7) == 'http://' || substr($this->_code, 0, 8) == 'https://') {
25
            return $this->_code;
26
        } else {
27
            $matches = [];
28
            preg_match('%mixcloudLoader\.swf\?feed=(.+?)&embed_uuid%', $this->_code, $matches);
29
30
            return isset($matches[1]) ? urldecode($matches[1]) : null;
31
        }
32
    }
33
34
    public function getThumbnail()
35
    {
36
        $url = $this->_getMixcloudUrl();
37
        if ($url) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $url of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
38
            $html = Ajde_Http_Curl::get($url);
39
            $matches = [];
40
            preg_match('%og:image\" content=\"(.+?)\"%', $html, $matches);
41
            // we get .png, we want .jpg
42
            if (isset($matches[1])) {
43
                return $matches[1];
44
            }
45
46
            return;
47
        }
48
    }
49
}
50