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 MytsMp3
23: */
24: class MytsMp3 extends MyTextSanitizerExtension
25: {
26: /**
27: * @param $textarea_id
28: *
29: * @return array
30: */
31: public function encode($textarea_id)
32: {
33: $code = "<button type='button' class='btn btn-default' onclick='xoopsCodeMp3(\"{$textarea_id}\",\""
34: . htmlspecialchars(_XOOPS_FORM_ENTERMP3URL, ENT_QUOTES)
35: . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALTMP3
36: . "'><span class='fa fa-fw fa-music' aria-hidden='true'></span></button>";
37:
38: $javascript = <<<EOF
39: function xoopsCodeMp3(id, enterMp3Phrase)
40: {
41: var selection = xoopsGetSelect(id);
42: if (selection.length > 0) {
43: var text = selection;
44: } else {
45: var text = prompt(enterMp3Phrase, "");
46: }
47: var domobj = xoopsGetElementById(id);
48: if (text.length > 0) {
49: var result = "[mp3]" + text + "[/mp3]";
50: xoopsInsertText(domobj, result);
51: }
52: domobj.focus();
53: }
54: EOF;
55:
56: return array(
57: $code,
58: $javascript);
59: }
60:
61: /**
62: * @param $match
63: *
64: * @return string
65: */
66: public static function myCallback($match)
67: {
68: return self::decode($match[1]);
69: }
70:
71: /**
72: * @param MyTextSanitizer $myts
73: *
74: * @return bool
75: */
76: public function load(MyTextSanitizer $myts)
77: {
78: $myts->callbackPatterns[] = "/\[mp3\](.*?)\[\/mp3\]/s";
79: $myts->callbacks[] = __CLASS__ . '::myCallback';
80:
81: return true;
82: }
83:
84: /**
85: * @param $url
86: *
87: * @return string
88: */
89: public static function decode($url, $width, $height)
90: {
91: $rp = "<embed flashvars=\"playerID=1&amp;bg=0xf8f8f8&amp;leftbg=0x3786b3&amp;lefticon=0x78bee3&amp;rightbg=0x3786b3&amp;rightbghover=0x78bee3&amp;righticon=0x78bee3&amp;righticonhover=0x3786b3&amp;text=0x666666&amp;slider=0x3786b3&amp;track=0xcccccc&amp;border=0x666666&amp;loader=0x78bee3&amp;loop=no&amp;soundFile={$url}\" quality='high' menu='false' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' src='" . XOOPS_URL . "/images/form/player.swf' width=290 height=24 type='application/x-shockwave-flash'></embed>";
92:
93: return $rp;
94: }
95: }
96: