1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
23:
24: 25: 26:
27: class MytsWiki extends MyTextSanitizerExtension
28: {
29: 30: 31: 32: 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: 70: 71: 72:
73: public static function myCallback($match)
74: {
75: return self::decode($match[1],0 ,0);
76: }
77:
78: 79: 80:
81: public function load($ts)
82: {
83:
84:
85:
86: $ts->callbackPatterns[] = "/\[\[([^\]]*)\]\]/sU";
87: $ts->callbacks[] = __CLASS__ . '::myCallback';
88:
89: }
90:
91: 92: 93: 94: 95:
96: public static function decode($text, $width, $height)
97: {
98: $config = parent::loadConfig(__DIR__);
99: if (empty($text) || empty($config['link'])) {
100: return $text;
101: }
102: $charset = !empty($config['charset']) ? $config['charset'] : 'UTF-8';
103: xoops_load('XoopsLocal');
104: $ret = "<a href='" . sprintf($config['link'], urlencode(XoopsLocal::convert_encoding($text, $charset))) . "' rel='external' title=''>{$text}</a>";
105:
106: return $ret;
107: }
108: }
109: