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: namespace Xoops\Core\Text\Sanitizer\Extensions;
13:
14: use Xoops\Core\Text\Sanitizer;
15: use Xoops\Core\Text\Sanitizer\ExtensionAbstract;
16:
17: /**
18: * TextSanitizer extension
19: *
20: * @category Sanitizer
21: * @package Xoops\Core\Text
22: * @author Taiwen Jiang <phppp@users.sourceforge.net>
23: * @copyright 2000-2015 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: */
27: class Wiki extends ExtensionAbstract
28: {
29: /**
30: * @var array default configuration values
31: */
32: protected static $defaultConfiguration = [
33: 'enabled' => false,
34: 'link' => 'modules/mediawiki/?title=%s', // The link to wiki module
35: 'template' => '<a href="%1$s" rel="external">%2$s</a>',
36: ];
37:
38: /**
39: * Provide button and javascript code used by the DhtmlTextArea
40: *
41: * @param string $textAreaId dom element id
42: *
43: * @return string[] editor button as HTML, supporting javascript
44: */
45: public function getDhtmlEditorSupport($textAreaId)
46: {
47: $buttonCode = $this->getEditorButtonHtml(
48: $textAreaId,
49: 'wiki.gif',
50: \XoopsLocale::WIKI,
51: 'xoopsCodeWiki',
52: \XoopsLocale::WIKI_WORD_TO_LINK
53: );
54:
55: $javascript = <<<EOH
56: function xoopsCodeWiki(id, enterWikiPhrase){
57: if (enterWikiPhrase == null) {
58: enterWikiPhrase = "Enter the word to be linked to Wiki:";
59: }
60: var selection = xoopsGetSelect(id);
61: if (selection.length > 0) {
62: var text = selection;
63: }else {
64: var text = prompt(enterWikiPhrase, "");
65: }
66: var domobj = xoopsGetElementById(id);
67: if ( text != null && text != "" ) {
68: var result = "[[" + text + "]]";
69: xoopsInsertText(domobj, result);
70: }
71: domobj.focus();
72: }
73: EOH;
74: return [$buttonCode, $javascript];
75: }
76:
77: /**
78: * Register extension with the supplied sanitizer instance
79: *
80: * @return void
81: */
82: public function registerExtensionProcessing()
83: {
84: $this->ts->addPatternCallback(
85: "/\[\[([^\]]*)\]\]/sU",
86: [$this, 'decode']
87: );
88: }
89:
90: /**
91: * build link to wiki page
92: *
93: * @param array $match from preg_match of wiki resource
94: *
95: * @return string
96: */
97: public function decode($match)
98: {
99: $wikiWord = $match[1];
100: if (empty($wikiWord) || empty($this->config['link'])) {
101: return $wikiWord;
102: }
103: $url = \Xoops::getInstance()->url(sprintf($this->config['link'], urlencode($wikiWord)));
104:
105: $newContent = sprintf($this->config['template'], $url, $wikiWord);
106: return $newContent;
107: }
108: }
109: