MytsSoundcloud::myCallback()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Class MytsSoundcloud
5
 */
6
class MytsSoundcloud extends MyTextSanitizerExtension
7
{
8
    /**
9
     * @param $textarea_id
10
     *
11
     * @return array
12
     */
13
    public function encode($textarea_id)
14
    {
15
//        $config = parent::loadConfig(__DIR__);
16
17
        $code = "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeSoundCloud(\"{$textarea_id}\",\""
18
            . htmlspecialchars(_XOOPS_FORM_ENTER_SOUNDCLOUD_URL, ENT_QUOTES | ENT_HTML5)
19
            . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_SOUNDCLOUD
20
            . "'><span class='fa fa-fw fa-soundcloud' aria-hidden='true'></span></button>";
21
        $javascript = <<<EOH
22
            function xoopsCodeSoundCloud(id, enterSoundCloud)
23
            {
24
                var selection = xoopsGetSelect(id);
25
                if (selection.length > 0) {
26
                    var text = selection;
27
                } else {
28
                    var text = prompt(enterSoundCloud, "");
29
                }
30
31
                var domobj = xoopsGetElementById(id);
32
                if (text.length > 0) {
33
                xoopsInsertText(domobj, "[soundcloud]"+text+"[/soundcloud]");
34
                }
35
                domobj.focus();
36
            }
37
EOH;
38
39
        return array($code, $javascript);
40
    }
41
42
    /**
43
     * @param MyTextSanitizer $myts
44
     */
45
    public function load(MyTextSanitizer $myts)
46
    {
47
        $myts->callbackPatterns[] = "/\[soundcloud\](http[s]?:\/\/[^\"'<>]*)(.*)\[\/soundcloud\]/sU";
48
        $myts->callbacks[]        = __CLASS__ . '::myCallback';
49
    }
50
51
    /**
52
     * @param $match
53
     *
54
     * @return string
55
     */
56
    public static function myCallback($match)
57
    {
58
        $url    = $match[1] . $match[2];
59
        $config = parent::loadConfig(__DIR__);
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
60
        if (!preg_match("/^http[s]?:\/\/(www\.)?soundcloud\.com\/(.*)/i", $url, $matches)) {
61
            trigger_error("Not matched: {$url}", E_USER_WARNING);
62
63
            return '';
64
        }
65
66
        $code = '<object height="81" width="100%"><param name="movie" ' . 'value="https://player.soundcloud.com/player.swf?url=' . $url . '&amp;g=bb">' . '</param><param name="allowscriptaccess" value="always"></param>' . '<embed allowscriptaccess="always" height="81" ' . 'src="https://player.soundcloud.com/player.swf?url=' . $url . '&amp;g=bb" type="application/x-shockwave-flash" width="100%"></embed></object>' . '<a href="' . $url . '">' . $url . '</a>';
67
68
        return $code;
69
    }
70
71
    //   public static function decode($url1, $url2)
72
    //   {
73
    //   }
74
}
75