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: /**
13: * TextSanitizer extension
14: *
15: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
16: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
17: * @package class
18: * @subpackage textsanitizer
19: * @since 2.3.0
20: * @author Taiwen Jiang <phppp@users.sourceforge.net>
21: */
22: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
23:
24: /**
25: * Class MytsWiki
26: */
27: class MytsWiki extends MyTextSanitizerExtension
28: {
29: /**
30: * @param $textarea_id
31: *
32: * @return array
33: */
34: public function encode($textarea_id)
35: {
36: $config = parent::loadConfig(__DIR__);
37: $code = "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeWiki(\"{$textarea_id}\",\""
38: . htmlspecialchars(_XOOPS_FORM_ENTERWIKITERM, ENT_QUOTES)
39: . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALTWIKI
40: . "'><span class='fa fa-fw fa-globe' aria-hidden='true'></span></button>";
41:
42: $javascript = <<<EOH
43: function xoopsCodeWiki(id, enterWikiPhrase)
44: {
45: if (enterWikiPhrase == null) {
46: enterWikiPhrase = "Enter the word to be linked to Wiki:";
47: }
48: var selection = xoopsGetSelect(id);
49: if (selection.length > 0) {
50: var text = selection;
51: } else {
52: var text = prompt(enterWikiPhrase, "");
53: }
54: var domobj = xoopsGetElementById(id);
55: if (text != null && text != "") {
56: var result = "[[" + text + "]]";
57: xoopsInsertText(domobj, result);
58: }
59: domobj.focus();
60: }
61: EOH;
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[1],0 ,0);
76: }
77:
78: /**
79: * @param MyTextSanitizer $myts
80: */
81: public function load(MyTextSanitizer $myts)
82: {
83: $myts->callbackPatterns[] = "/\[\[([^\]]*)\]\]/sU";
84: $myts->callbacks[] = __CLASS__ . '::myCallback';
85: }
86:
87: /**
88: * @param $text
89: *
90: * @return string
91: */
92: public static function decode($text, $width, $height)
93: {
94: $config = parent::loadConfig(__DIR__);
95: if (empty($text) || empty($config['link'])) {
96: return $text;
97: }
98: $charset = !empty($config['charset']) ? $config['charset'] : 'UTF-8';
99: xoops_load('XoopsLocal');
100: $ret = "<a href='" . sprintf($config['link'], urlencode(XoopsLocal::convert_encoding($text, $charset))) . "' rel='external' title=''>{$text}</a>";
101:
102: return $ret;
103: }
104: }
105: