1: <?php
2:
3: namespace ModHelper;
4:
5: 6: 7: 8: 9: 10:
11: class Editor
12: {
13: private $id;
14: private $sanitized = '';
15:
16: public function __construct($id)
17: {
18: $this->id = $id;
19: }
20:
21: public function getId()
22: {
23: return $this->id;
24: }
25:
26: public function initialize($editorOptions)
27: {
28: global $sourcedir, $context;
29: require_once($sourcedir . '/Subs-Editor.php');
30: $defaults = array(
31: 'id' => $this->id,
32: 'value' => '',
33: 'height' => '175px',
34: 'width' => '100%',
35: 'preview_type' => 0,
36: );
37: $editorOptions = array_merge($defaults, $editorOptions);
38: create_control_richedit($editorOptions);
39:
40: if (isset($editorOptions['js'])) {
41: $context['controls']['richedit'][$editorOptions['id']]['js'] = $editorOptions['js'];
42: }
43: }
44:
45: public function outputEditor()
46: {
47: global $context;
48: if ($context['show_bbc']) {
49: echo '
50: <div id="bbcBox_', $this->id, '"></div>';
51: }
52: if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) {
53: echo '
54: <div id="smileyBox_', $this->id, '"></div>';
55: }
56: echo '
57: ', template_control_richedit($this->id, 'smileyBox_' . $this->id, 'bbcBox_' . $this->id);
58: }
59:
60: public function outputButtons()
61: {
62: global $context, $txt;
63:
64: $editor_context = & $context['controls']['richedit'][$this->id];
65: echo '
66: <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
67: <p id="post_confirm_buttons" class="righttext">
68: <input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" tabindex="', $context['tabindex']++, '"', isset($editor_context['js']['post_button']) ? ' onclick="' . $editor_context['js']['post_button'] . '"' : '', ' class="button_submit" />';
69: if ($editor_context['preview_type']) {
70: echo '
71: <input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', $context['tabindex']++, '"', isset($editor_context['js']['preview_button']) ? ' onclick="' . $editor_context['js']['preview_button'] . '"' : '', ' class="button_submit" />';
72: }
73: echo '
74: </p>';
75: }
76:
77: private function prepareWYSIWYG()
78: {
79: global $sourcedir;
80: if (!empty($_REQUEST[$this->id . '_mode']) && isset($_REQUEST[$this->id])) {
81: require_once($sourcedir . '/Subs-Editor.php');
82: $_REQUEST[$this->id] = html_to_bbc($_REQUEST[$this->id]);
83: $_REQUEST[$this->id] = un_htmlspecialchars($_REQUEST[$this->id]);
84: $_POST[$this->id] = $_REQUEST[$this->id];
85: }
86: }
87:
88: public function isEmpty()
89: {
90: global $smcFunc;
91: $this->prepareWYSIWYG();
92:
93: return (empty($_POST[$this->id]) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST[$this->id]), ENT_QUOTES) === '');
94: }
95:
96: public function sanitizeContent()
97: {
98: global $smcFunc, $sourcedir;
99: require_once($sourcedir . '/Subs-Post.php');
100: preparsecode($this->sanitized = $smcFunc['htmlspecialchars']($_POST[$this->id], ENT_QUOTES));
101:
102: return !($smcFunc['htmltrim'](strip_tags(parse_bbc($this->sanitized, false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($this->sanitized, '[html]') === false));
103: }
104:
105: public function getForDB()
106: {
107: return $this->sanitized;
108: }
109:
110: public function getForForm($comment = null)
111: {
112: global $sourcedir;
113: require_once($sourcedir . '/Subs-Post.php');
114: censorText(un_preparsecode($comment === null ? $this->sanitized : $comment));
115:
116: return str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $comment);
117: }
118: }
119:
120: ?>