1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Core\Text\Sanitizer\Extensions;
13:
14: use Xoops\Core\Text\Sanitizer;
15: use Xoops\Core\Text\Sanitizer\ExtensionAbstract;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class SoundCloud extends ExtensionAbstract
28: {
29: 30: 31:
32: protected static $defaultConfiguration = [
33: 'enabled' => false,
34: 'params' => "color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false",
35: 'width' => "100%",
36: 'height' => "166",
37: ];
38:
39: 40: 41: 42: 43: 44: 45:
46: public function getDhtmlEditorSupport($textAreaId)
47: {
48: $buttonCode = $this->getEditorButtonHtml(
49: $textAreaId,
50: 'soundcloud.png',
51: \XoopsLocale::SOUNDCLOUD,
52: 'xoopsCodeSoundCloud',
53: \XoopsLocale::SOUNDCLOUD_URL
54: );
55:
56: $javascript = <<<EOH
57: function xoopsCodeSoundCloud(id, enterSoundCloud)
58: {
59: var selection = xoopsGetSelect(id);
60: if (selection.length > 0) {
61: var text = selection;
62: } else {
63: var text = prompt(enterSoundCloud, "");
64: }
65:
66: var domobj = xoopsGetElementById(id);
67: if (text.length > 0) {
68: xoopsInsertText(domobj, '[soundcloud url="'+text+'" /]');
69: }
70: domobj.focus();
71: }
72: EOH;
73:
74: return [$buttonCode, $javascript];
75: }
76:
77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90:
91: public function registerExtensionProcessing()
92: {
93: $shortcodes = $this->shortcodes;
94: $shortcodes->addShortcode(
95: 'soundcloud',
96: function ($attributes, $content, $tagName) use ($shortcodes) {
97: $defaults = [
98: 'url' => trim($content),
99: 'params' => $this->config['params'],
100: 'width' => $this->config['width'],
101: 'height' => $this->config['height'],
102: ];
103: $cleanAttributes = $shortcodes->shortcodeAttributes($defaults, $attributes);
104:
105: parse_str($defaults['params'], $defaultParams);
106: parse_str($cleanAttributes['params'], $inputParams);
107: $cleanParams = $shortcodes->shortcodeAttributes($defaultParams, $inputParams);
108: $cleanAttributes = array_filter($cleanAttributes, 'urlencode');
109: $cleanParams = array_filter($cleanParams, 'urlencode');
110:
111: $template = '<iframe width="%2$s" height="%3$s" scrolling="no" frameborder="no"'
112: .' src="https://w.soundcloud.com/player/?url=%1$s&color=%4$s&auto_play=%5$s'
113: . '&hide_related=%6$s&show_comments=%7$s&show_user=%8$s&'
114: . 'show_reposts=%9$s"></iframe>';
115:
116: $newContent = sprintf(
117: $template,
118: $cleanAttributes['url'],
119: $cleanAttributes['width'],
120: $cleanAttributes['height'],
121: $cleanParams['color'],
122: $cleanParams['auto_play'],
123: $cleanParams['hide_related'],
124: $cleanParams['show_comments'],
125: $cleanParams['show_user'],
126: $cleanParams['show_reposts']
127: );
128: return $newContent;
129: }
130: );
131: }
132: }
133: