|
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
|
|
|
* Sanitizer extension for flash content |
|
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 Flash extends ExtensionAbstract |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var array default configuration values |
|
31
|
|
|
*/ |
|
32
|
|
|
protected static $defaultConfiguration = [ |
|
33
|
|
|
'enabled' => false, |
|
34
|
|
|
'detect_dimension' => '1', |
|
35
|
|
|
'template' => '<object type="application/x-shockwave-flash" data="%1$s" width="%2$d" height="%3$d"></object>', |
|
36
|
|
|
'fallback_width' => "320", |
|
37
|
|
|
'fallback_height' => "240", |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Provide button and javascript code used by the DhtmlTextArea |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $textAreaId dom element id |
|
44
|
|
|
* |
|
45
|
|
|
* @return string[] editor button as HTML, supporting javascript |
|
46
|
|
|
*/ |
|
47
|
1 |
|
public function getDhtmlEditorSupport($textAreaId) |
|
48
|
|
|
{ |
|
49
|
1 |
|
$buttonCode = $this->getEditorButtonHtml( |
|
50
|
1 |
|
$textAreaId, |
|
51
|
1 |
|
'swf.gif', |
|
52
|
1 |
|
\XoopsLocale::FLASH, |
|
53
|
1 |
|
'xoopsCodeFlash', |
|
54
|
1 |
|
\XoopsLocale::FLASH_URL, |
|
55
|
1 |
|
\XoopsLocale::HEIGHT, |
|
56
|
1 |
|
\XoopsLocale::WIDTH, |
|
57
|
1 |
|
$this->config['detect_dimension'] |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$javascript = <<<EOF |
|
61
|
|
|
|
|
62
|
|
|
function xoopsCodeFlash(id, enterFlashPhrase, enterFlashHeightPhrase, enterFlashWidthPhrase, enableDimensionDetect) |
|
63
|
|
|
{ |
|
64
|
|
|
enableDimensionDetect = Boolean(parseInt(enableDimensionDetect)); |
|
65
|
|
|
var selection = xoopsGetSelect(id); |
|
66
|
|
|
if (selection.length > 0) { |
|
67
|
|
|
var text = selection; |
|
68
|
|
|
} else { |
|
69
|
|
|
var text = prompt(enterFlashPhrase, ""); |
|
70
|
|
|
} |
|
71
|
|
|
var domobj = xoopsGetElementById(id); |
|
72
|
|
|
if ( text.length > 0 ) { |
|
73
|
|
|
var text2 = enableDimensionDetect ? "" : prompt(enterFlashWidthPhrase, ""); |
|
74
|
|
|
var text3 = enableDimensionDetect ? "" : prompt(enterFlashHeightPhrase, ""); |
|
75
|
|
|
if (text2.length == 0 && text2.length == 0) { |
|
76
|
|
|
var result = '[flash url="'+text+'" /]'; |
|
77
|
|
|
} else { |
|
78
|
|
|
var result = '[flash url="'+text+'" width='+text2+' height='+text3+' /]'; |
|
79
|
|
|
} |
|
80
|
|
|
xoopsInsertText(domobj, result); |
|
81
|
|
|
} |
|
82
|
|
|
domobj.focus(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
EOF; |
|
86
|
|
|
|
|
87
|
1 |
|
return [$buttonCode, $javascript]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Register extension with the supplied sanitizer instance |
|
92
|
|
|
* |
|
93
|
|
|
* @return void |
|
94
|
|
|
*/ |
|
95
|
|
|
public function registerExtensionProcessing() |
|
96
|
|
|
{ |
|
97
|
1 |
|
$function = function ($attributes, $content, $tagName) { |
|
|
|
|
|
|
98
|
1 |
|
if (array_key_exists(0, $attributes) && '=' === substr($attributes[0], 0, 1)) { |
|
99
|
1 |
|
$args = ltrim($attributes[0], '='); |
|
100
|
1 |
|
list($width, $height) = explode(',', $args); |
|
101
|
1 |
|
$url = $content; |
|
102
|
|
|
} else { |
|
103
|
|
|
$defaults = [ |
|
104
|
1 |
|
'url' => trim($content), |
|
105
|
|
|
'width' => null, |
|
106
|
|
|
'height' => null, |
|
107
|
|
|
]; |
|
108
|
1 |
|
$cleanAttributes = $this->shortcodes->shortcodeAttributes($defaults, $attributes); |
|
109
|
1 |
|
$url = $cleanAttributes['url']; |
|
110
|
1 |
|
$width = $cleanAttributes['width']; |
|
111
|
1 |
|
$height = $cleanAttributes['height']; |
|
112
|
|
|
} |
|
113
|
1 |
|
if ((empty($width) || empty($height)) && (bool)$this->config['detect_dimension']) { |
|
114
|
|
|
$dimension = @getimagesize($content); |
|
115
|
|
|
if ($dimension !== false) { |
|
116
|
|
|
list($width, $height) = $dimension; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
1 |
|
if (empty($width) || empty($height)) { |
|
120
|
|
|
$width = $this->config['fallback_width']; |
|
121
|
|
|
$height = $this->config['fallback_height']; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
1 |
|
$template = $this->config['template']; |
|
125
|
1 |
|
$newcontent = sprintf($template, $url, $width, $height); |
|
126
|
1 |
|
return $newcontent; |
|
127
|
1 |
|
}; |
|
128
|
|
|
|
|
129
|
|
|
$this->shortcodes->addShortcode('flash', $function); |
|
130
|
|
|
$this->shortcodes->addShortcode('swf', $function); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.