Completed
Pull Request — master (#591)
by Richard
16:26
created

Wmp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 54.55%

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 77
ccs 12
cts 22
cp 0.5455
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDhtmlEditorSupport() 0 35 2
A registerExtensionProcessing() 0 18 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-2019 XOOPS Project (https://xoops.org)
24
 * @license   GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
25
 */
26
class Wmp extends ExtensionAbstract
27
{
28
    /**
29
     * @var array default configuration values
30
     */
31
    protected static $defaultConfiguration = [
32
        'enabled' => false,
33
        'enable_wmp_entry' => false,  // false to disable entry button in editor, existing content will still play
34
        ];
35
36
    /**
37
     * Provide button and javascript code used by the DhtmlTextArea
38
     *
39
     * @param string $textAreaId dom element id
40
     *
41
     * @return string[] editor button as HTML, supporting javascript
42
     */
43 3
    public function getDhtmlEditorSupport($textAreaId)
44
    {
45 3
        if (false === $this->config['enable_wmp_entry']) {
46 3
            return parent::getDhtmlEditorSupport($textAreaId);
47
        }
48
49
        $buttonCode = $this->getEditorButtonHtml(
50
            $textAreaId,
51
            'fa fa-fw fa-windows',
52
            \XoopsLocale::WMP,
53
            'xoopsCodeWmp',
54
            \XoopsLocale::WMP_URL,
55
            \XoopsLocale::HEIGHT,
56
            \XoopsLocale::WIDTH
57
        );
58
59
        $javascript = <<<EOH
60
            function xoopsCodeWmp(id, enterWmpPhrase, enterWmpHeightPhrase, enterWmpWidthPhrase) {
61
                var selection = xoopsGetSelect(id);
62
                if (selection.length > 0) {
63
                    var text = selection;
64
                } else {
65
                    var text = prompt(enterWmpPhrase, "");
66
                }
67
                var domobj = xoopsGetElementById(id);
68
                if ( text.length > 0 ) {
69
                    var text2 = prompt(enterWmpWidthPhrase, "480");
70
                    var text3 = prompt(enterWmpHeightPhrase, "330");
71
                    var result = "[wmp="+text2+","+text3+"]" + text + "[/wmp]";
72
                    xoopsInsertText(domobj, result);
73
                }
74
                domobj.focus();
75
            }
76
EOH;
77
        return [$buttonCode, $javascript];
78
    }
79
80
    /**
81
     * Register extension with the supplied sanitizer instance
82
     *
83
     * @return void
84
     */
85 6
    public function registerExtensionProcessing()
86
    {
87 6
        $this->shortcodes->addShortcode(
88 6
            'wmp',
89
            function ($attributes, $content, $tagName) {
0 ignored issues
show
Unused Code introduced by
The parameter $tagName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
            function ($attributes, $content, /** @scrutinizer ignore-unused */ $tagName) {

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

Loading history...
90 1
                $args = ltrim($attributes[0], '=');
91 1
                list($width, $height) = explode(',', $args);
92 1
                $url = $content;
93
94
                $template = '<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"'
95
                    . ' id="WindowsMediaPlayer" width="%2$s" height="%3$s">' . "\n"
96
                    . '<param name="URL" value="%1$s">'. "\n"
97
                    . '<param name="AutoStart" value="0">' . "\n"
98
                    . '<embed autostart="0" src="%1$s" type="video/x-ms-wmv" width="%2$s" height="%3$s"'
99
                    . ' controls="ImageWindow" console="cons"> </embed>' . "\n"
100 1
                    . '</object>' . "\n";
101 1
                $newContent = sprintf($template, $url, $width, $height);
102 1
                return $newContent;
103 6
            }
104
        );
105 6
    }
106
}
107