forked from elkarte/Elkarte
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenericControls.template.php
197 lines (175 loc) · 7.74 KB
/
GenericControls.template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* This software is a derived product, based on:
*
* Simple Machines Forum (SMF)
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
* license: BSD, See included LICENSE.TXT for terms and conditions.
*
* @version 1.0 Beta 2
*
*/
/**
* This function displays all the goodies you get with a richedit box - BBC, smileys etc.
*
* @param string $editor_id
* @param string|null $smileyContainer if set show the smiley container id
* @param string|null $bbcContainer show the bbc container id
*/
function template_control_richedit($editor_id, $smileyContainer = null, $bbcContainer = null)
{
global $context, $settings, $options;
$editor_context = &$context['controls']['richedit'][$editor_id];
echo '
<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" tabindex="', $context['tabindex']++, '" style="width:', $editor_context['width'], ';height: ', $editor_context['height'], ';', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '" required="required">', $editor_context['value'], '</textarea>
<input type="hidden" name="', $editor_id, '_mode" id="', $editor_id, '_mode" value="0" />
<script><!-- // --><![CDATA[
$(document).ready(function(){',
!empty($context['bbcodes_handlers']) ? $context['bbcodes_handlers'] : '', '
$("#', $editor_id, '").sceditor({
style: "', $settings['default_theme_url'], '/css/jquery.sceditor.elk.css",
width: "100%",
height: "100%",
resizeWidth: false,
resizeMaxHeight: -1,
emoticonsCompat: true,
locale: "', !empty($editor_context['locale']) ? $editor_context['locale'] : 'en_US', '",
colors: "black,red,yellow,pink,green,orange,purple,blue,beige,brown,teal,navy,maroon,limegreen,white",
enablePasteFiltering: true,
plugins: "bbcode, splittag', !empty($context['mentions_enabled']) ? ', mention' : '', (!empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled']) ? ', draft",
draftOptions: {
sLastNote: \'draft_lastautosave\',
sSceditorID: \'' . $editor_id . '\',
sType: \'post\',
iBoard: ' . (empty($context['current_board']) ? 0 : $context['current_board']) . ',
iFreq: ' . $context['drafts_autosave_frequency'] . ',' . (!empty($context['drafts_save']) ?
'sLastID: \'id_draft\'' : 'sLastID: \'id_pm_draft\', bPM: true') . '
},' : '",'), (!empty($context['mentions_enabled']) ? '
mentionOptions: {
editor_id: \'' . $editor_id . '\',
cache: {
mentions: [],
queries: [],
names: []
}
},' : ''), '
parserOptions: {
quoteType: $.sceditor.BBCodeParser.QuoteType.auto
}';
// Show the smileys.
if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
{
echo ',
emoticons:
{';
$countLocations = count($context['smileys']);
foreach ($context['smileys'] as $location => $smileyRows)
{
$countLocations--;
if ($location === 'postform')
echo '
dropdown:
{';
elseif ($location === 'popup')
echo '
popup:
{';
$numRows = count($smileyRows);
// This is needed because otherwise the editor will remove all the duplicate (empty) keys and leave only 1 additional line
$emptyPlaceholder = 0;
foreach ($smileyRows as $smileyRow)
{
foreach ($smileyRow['smileys'] as $smiley)
{
echo '
', JavaScriptEscape($smiley['code']), ': {url: ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), ', tooltip: ', JavaScriptEscape($smiley['description']), '}', empty($smiley['isLast']) ? ',' : '';
}
if (empty($smileyRow['isLast']) && $numRows !== 1)
echo ',
\'-', $emptyPlaceholder++, '\': \'\',';
}
echo '
}', $countLocations != 0 ? ',' : '';
}
echo '
}';
}
else
echo ',
emoticons:
{}';
// Show all the editor command buttons
if ($context['show_bbc'] && $bbcContainer !== null)
{
echo ',
toolbar: "';
// Create the tooltag rows to display the buttons in the editor
foreach ($context['bbc_toolbar'] as $i => $buttonRow)
echo implode('', $buttonRow), '||';
echo ',emoticon",';
}
else
echo ',
toolbar: "source,emoticon",';
echo '
});
$("#', $editor_id, '").data("sceditor").createPermanentDropDown();
$(".sceditor-container").width("100%").height("100%");', $editor_context['rich_active'] ? '' : '
$("#' . $editor_id . '").data("sceditor").setTextMode();';
// The white-space: pre is necessary to avoid the editor mess with tabs in code blocks
echo '
$("#' . $editor_id . '").data("sceditor").css(\'code {white-space: pre;}\');', '
if (!(is_ie || is_ff || is_opera || is_safari || is_chrome))
$(".sceditor-button-source").hide();
', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
$(".sceditor-container").find("textarea").each(function() {$(this).css({border: "1px solid red"})});
$(".sceditor-container").find("iframe").each(function() {$(this).css({border: "1px solid red"})});' : '', '
});
// ]]></script>';
}
/**
* Shows the buttons that the user can see .. preview, spellchecker, drafts, etc
*
* @param string $editor_id
*/
function template_control_richedit_buttons($editor_id)
{
global $context, $settings, $options, $txt;
$editor_context = &$context['controls']['richedit'][$editor_id];
// Create an area to show the draft last saved on
if (!empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled']))
echo '
<span class="draftautosave smalltext">
<span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon" /> </span>
<span id="draft_lastautosave" ></span>
</span>';
echo '
<span class="smalltext floatleft">
', $context['shortcuts_text'], '
</span>
<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" tabindex="', $context['tabindex']++, '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />';
if ($editor_context['preview_type'])
echo '
<input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', $context['tabindex']++, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewControl();' : 'return submitThisOnce(this);', '" accesskey="p" class="button_submit" />';
if ($context['show_spellchecking'])
echo '
<input type="button" value="', $txt['spell_check'], '" tabindex="', $context['tabindex']++, '" onclick="spellCheckStart();" class="button_submit" />';
if (!empty($context['drafts_save']))
{
// Show the save draft button
echo '
<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', $context['tabindex']++, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button_submit" />
<input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '" />';
}
if (!empty($context['drafts_pm_save']))
{
// The PM draft save button
echo '
<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', $context['tabindex']++, '" onclick="submitThisOnce(this);" accesskey="d" class="button_submit" />
<input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '" />';
}
}