Completed
Pull Request — master (#554)
by Richard
06:59
created

Mp3   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerExtensionProcessing() 0 15 1
B getDhtmlEditorSupport() 0 31 1
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 <[email protected]>
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 1
    public function getDhtmlEditorSupport($textAreaId)
45
    {
46 1
        $buttonCode = $this->getEditorButtonHtml(
47 1
            $textAreaId,
48 1
            'mp3.gif',
49 1
            \XoopsLocale::MP3,
50 1
            'xoopsCodeMp3',
51 1
            \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 1
        return [$buttonCode, $javascript];
74
    }
75
76
    /**
77
     * Register extension with the supplied sanitizer instance
78
     *
79
     * @return void
80
     */
81 2
    public function registerExtensionProcessing()
82
    {
83 2
        $this->shortcodes->addShortcode(
84 2
            'mp3',
85 2
            function ($attributes, $content, $tagName) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
                $defaults = [
87 1
                    'url'    => trim($content),
88
                ];
89 1
                $cleanAttributes = $this->shortcodes->shortcodeAttributes($defaults, $attributes);
90 1
                $newContent = sprintf($this->config['template'], $cleanAttributes['url']);
91
92 1
                return $newContent;
93 2
            }
94
        );
95 2
    }
96
}
97