1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
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: * TextSanitizer extension
19: *
20: * @category Sanitizer
21: * @package Xoops\Core\Text
22: * @author Taiwen Jiang <phppp@users.sourceforge.net>
23: * @copyright 2000-2015 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: */
27: class Mp3 extends ExtensionAbstract
28: {
29: /**
30: * @var array default configuration values
31: */
32: protected static $defaultConfiguration = [
33: 'enabled' => true,
34: 'template' => '<audio controls><source src="%1$s" type="audio/mpeg"></audio>',
35: ];
36:
37: /**
38: * Provide button and javascript code used by the DhtmlTextArea
39: *
40: * @param string $textAreaId dom element id
41: *
42: * @return string[] editor button as HTML, supporting javascript
43: */
44: public function getDhtmlEditorSupport($textAreaId)
45: {
46: $buttonCode = $this->getEditorButtonHtml(
47: $textAreaId,
48: 'mp3.gif',
49: \XoopsLocale::MP3,
50: 'xoopsCodeMp3',
51: \XoopsLocale::MP3_URL
52: );
53:
54: $javascript = <<<EOF
55:
56: function xoopsCodeMp3(id, enterMp3Phrase)
57: {
58: var selection = xoopsGetSelect(id);
59: if (selection.length > 0) {
60: var text = selection;
61: } else {
62: var text = prompt(enterMp3Phrase, "");
63: }
64: var domobj = xoopsGetElementById(id);
65: if ( text.length > 0 ) {
66: xoopsInsertText(domobj, '[mp3 url="'+text+'" /]');
67: }
68: domobj.focus();
69: }
70:
71: EOF;
72:
73: return [$buttonCode, $javascript];
74: }
75:
76: /**
77: * Register extension with the supplied sanitizer instance
78: *
79: * @return void
80: */
81: public function registerExtensionProcessing()
82: {
83: $this->shortcodes->addShortcode(
84: 'mp3',
85: function ($attributes, $content, $tagName) {
86: $defaults = [
87: 'url' => trim($content),
88: ];
89: $cleanAttributes = $this->shortcodes->shortcodeAttributes($defaults, $attributes);
90: $newContent = sprintf($this->config['template'], $cleanAttributes['url']);
91:
92: return $newContent;
93: }
94: );
95: }
96: }
97: