1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 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: 19: 20: 21: 22: 23: 24: 25: 26:
27: class Flash extends ExtensionAbstract
28: {
29: 30: 31:
32: protected static $defaultConfiguration = [
33: 'enabled' => true,
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: 42: 43: 44: 45: 46:
47: public function getDhtmlEditorSupport($textAreaId)
48: {
49: $buttonCode = $this->getEditorButtonHtml(
50: $textAreaId,
51: 'swf.gif',
52: \XoopsLocale::FLASH,
53: 'xoopsCodeFlash',
54: \XoopsLocale::FLASH_URL,
55: \XoopsLocale::HEIGHT,
56: \XoopsLocale::WIDTH,
57: $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: return [$buttonCode, $javascript];
88: }
89:
90: 91: 92: 93: 94:
95: public function registerExtensionProcessing()
96: {
97: $function = function ($attributes, $content, $tagName) {
98: if (array_key_exists(0, $attributes) && '=' === substr($attributes[0], 0, 1)) {
99: $args = ltrim($attributes[0], '=');
100: list($width, $height) = explode(',', $args);
101: $url = $content;
102: } else {
103: $defaults = [
104: 'url' => trim($content),
105: 'width' => null,
106: 'height' => null,
107: ];
108: $cleanAttributes = $this->shortcodes->shortcodeAttributes($defaults, $attributes);
109: $url = $cleanAttributes['url'];
110: $width = $cleanAttributes['width'];
111: $height = $cleanAttributes['height'];
112: }
113: 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: if (empty($width) || empty($height)) {
120: $width = $this->config['fallback_width'];
121: $height = $this->config['fallback_height'];
122: }
123:
124: $template = $this->config['template'];
125: $newcontent = sprintf($template, $url, $width, $height);
126: return $newcontent;
127: };
128:
129: $this->shortcodes->addShortcode('flash', $function);
130: $this->shortcodes->addShortcode('swf', $function);
131: }
132: }
133: