| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: |
|
| 6: | class MytsSoundcloud extends MyTextSanitizerExtension
|
| 7: | {
|
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: |
|
| 13: | public function encode($textarea_id)
|
| 14: | {
|
| 15: |
|
| 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)
|
| 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: | |
| 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: | |
| 53: | |
| 54: | |
| 55: |
|
| 56: | public static function myCallback($match)
|
| 57: | {
|
| 58: | $url = $match[1] . $match[2];
|
| 59: | $config = parent::loadConfig(__DIR__);
|
| 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 . '&g=bb">' . '</param><param name="allowscriptaccess" value="always"></param>' . '<embed allowscriptaccess="always" height="81" ' . 'src="https://player.soundcloud.com/player.swf?url=' . $url . '&g=bb" type="application/x-shockwave-flash" width="100%"></embed></object>' . '<a href="' . $url . '">' . $url . '</a>';
|
| 67: |
|
| 68: | return $code;
|
| 69: | }
|
| 70: |
|
| 71: |
|
| 72: |
|
| 73: |
|
| 74: | }
|
| 75: | |