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

Mms::getDhtmlEditorSupport()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.8204

Importance

Changes 0
Metric Value
cc 2
eloc 31
nc 2
nop 1
dl 0
loc 37
ccs 3
cts 13
cp 0.2308
crap 3.8204
rs 9.424
c 0
b 0
f 0
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 Mms extends ExtensionAbstract
27
{
28
    /**
29
     * @var array default configuration values
30
     */
31
    protected static $defaultConfiguration = [
32
        'enabled' => false,
33
        'enable_mms_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_mms_entry']) {
46 3
            return parent::getDhtmlEditorSupport($textAreaId);
47
        }
48
49
        $buttonCode = $this->getEditorButtonHtml(
50
            $textAreaId,
51
            'fa fa-fw fa-server',
52
            \XoopsLocale::MMS,
53
            'xoopsCodeWmp',
54
            \XoopsLocale::MMS_URL,
55
            \XoopsLocale::HEIGHT,
56
            \XoopsLocale::WIDTH
57
        );
58
59
        $javascript = <<<EOH
60
            function xoopsCodeMms(id, enterMmsPhrase, enterMmsHeightPhrase, enterMmsWidthPhrase)
61
            {
62
                var selection = xoopsGetSelect(id);
63
                if (selection.length > 0) {
64
                    var selection="mms://"+selection;
65
                    var text = selection;
66
                } else {
67
                    var text = prompt(enterMmsPhrase+"       mms or http", "mms://");
68
                }
69
                var domobj = xoopsGetElementById(id);
70
                if ( text.length > 0 && text != "mms://") {
71
                    var text2 = prompt(enterMmsWidthPhrase, "480");
72
                    var text3 = prompt(enterMmsHeightPhrase, "330");
73
                    var result = "[mms="+text2+","+text3+"]" + text + "[/mms]";
74
                    xoopsInsertText(domobj, result);
75
                }
76
                domobj.focus();
77
            }
78
EOH;
79
        return [$buttonCode, $javascript];
80
    }
81
82
    /**
83
     * Register extension with the supplied sanitizer instance
84
     *
85
     * @return void
86
     */
87 14
    public function registerExtensionProcessing()
88
    {
89 14
        $this->shortcodes->addShortcode(
90 14
            'mms',
91
            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

91
            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...
92 1
                $args = ltrim($attributes[0], '=');
93 1
                list($width, $height) = explode(',', $args);
94 1
                $url = $content;
95
96
                $template = <<<'EOT'
97 1
    <object id=videowindow1 height="%3$s" width="%2$s" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6">
98
        <param name="URL" value="%1$s">
99
        <param name="rate" value="1">
100
        <param name="balance" value="0">
101
        <param name="currentPosition" value="0">
102
        <param name="defaultFrame" value="">
103
        <param name="playCount" value="1">
104
        <param name="autoStart" value="0">
105
        <param name="currentMarker" value="0">
106
        <param name="invokeURLs" value="-1">
107
        <param name="baseURL" value="">
108
        <param name="volume" value="50">
109
        <param name="mute" value="0">
110
        <param name="uiMode" value="full">
111
        <param name="stretchToFit" value="0">
112
        <param name="windowlessVideo" value="0">
113
        <param name="enabled" value="-1">
114
        <param name="enableContextMenu" value="-1">
115
        <param name="fullScreen" value="0">
116
        <param name="SAMIStyle" value="">
117
        <param name="SAMILang" value="">
118
        <param name="SAMIFilename" value="">
119
        <param name="captioningID" value="">
120
        <param name="enableErrorDialogs" value="0">
121
        <param name="_cx" value="12700">
122
        <param name="_cy" value="8731">
123
    </object>
124
EOT;
125
126 1
                $newContent = sprintf($template, $url, $width, $height);
127 1
                return $newContent;
128 14
            }
129
        );
130 14
    }
131
}
132