1: <?php
2: /**
3: * TextSanitizer extension
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2017 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @package class
15: * @subpackage textsanitizer
16: * @since 2.3.0
17: * @author Taiwen Jiang <phppp@users.sourceforge.net>
18: */
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: /**
22: * Class MytsFlash
23: */
24: class MytsFlash extends MyTextSanitizerExtension
25: {
26: /**
27: * @param $textarea_id
28: *
29: * @return array
30: */
31: public function encode($textarea_id)
32: {
33: $config = parent::loadConfig(__DIR__);
34: if ($config['enable_flash_entry'] === false) {
35: return array();
36: }
37: $code = "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeFlash(\"{$textarea_id}\",\""
38: . htmlspecialchars(_XOOPS_FORM_ENTERFLASHURL, ENT_QUOTES) . "\",\""
39: . htmlspecialchars(_XOOPS_FORM_ALT_ENTERHEIGHT, ENT_QUOTES) . "\",\""
40: . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\", \""
41: . $config['detect_dimension'] . "\");' onmouseover='style.cursor=\"hand\"' title='"
42: . _XOOPS_FORM_ALTFLASH . "'><span class='fa fa-fw fa-flash' aria-hidden='true'></span></button>";
43: $javascript = <<<EOF
44: function xoopsCodeFlash(id, enterFlashPhrase, enterFlashHeightPhrase, enterFlashWidthPhrase, enableDimensionDetect)
45: {
46: var selection = xoopsGetSelect(id);
47: if (selection.length > 0) {
48: var text = selection;
49: } else {
50: var text = prompt(enterFlashPhrase, "");
51: }
52: var domobj = xoopsGetElementById(id);
53: if (text.length > 0) {
54: var text2 = enableDimensionDetect ? "" : prompt(enterFlashWidthPhrase, "");
55: var text3 = enableDimensionDetect ? "" : prompt(enterFlashHeightPhrase, "");
56: var result = "[flash="+text2+","+text3+"]" + text + "[/flash]";
57: xoopsInsertText(domobj, result);
58: }
59: domobj.focus();
60: }
61: EOF;
62:
63: return array(
64: $code,
65: $javascript);
66: }
67:
68: /**
69: * @param $match
70: *
71: * @return string
72: */
73: public static function myCallback($match)
74: {
75: return self::decode($match[5], $match[3], $match[4]);
76: }
77:
78: /**
79: * @param MyTextSanitizer $myts
80: *
81: * @return bool
82: */
83: public function load(MyTextSanitizer $myts)
84: {
85: $myts->callbackPatterns[] = "/\[(swf|flash)=(['\"]?)([^\"']*),([^\"']*)\\2]([^\"]*)\[\/\\1\]/sU";
86: $myts->callbacks[] = __CLASS__ . '::myCallback';
87:
88: return true;
89: }
90:
91: /**
92: * @param $url
93: * @param $width
94: * @param $height
95: *
96: * @return string
97: */
98: public static function decode($url, $width, $height)
99: {
100: $config = parent::loadConfig(__DIR__);
101:
102: if ((empty($width) || empty($height)) && !empty($config['detect_dimension'])) {
103: if (!$dimension = @getimagesize($url)) {
104: return "<a href='{$url}' rel='external' title=''>{$url}</a>";
105: }
106: if (!empty($width)) {
107: $height = $dimension[1] * $width / $dimension[0];
108: } elseif (!empty($height)) {
109: $width = $dimension[0] * $height / $dimension[1];
110: } else {
111: list($width, $height) = array(
112: $dimension[0],
113: $dimension[1]);
114: }
115: }
116:
117: $rp = "<object width='{$width}' height='{$height}' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>";
118: $rp .= "<param name='movie' value='{$url}'>";
119: $rp .= "<param name='QUALITY' value='high'>";
120: $rp .= "<PARAM NAME='bgcolor' VALUE='#FFFFFF'>";
121: $rp .= "<param name='wmode' value='transparent'>";
122: $rp .= "<embed src='{$url}' width='{$width}' height='{$height}' quality='high' bgcolor='#FFFFFF' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed>";
123: $rp .= '</object>';
124:
125: return $rp;
126: }
127: }
128: