Completed
Push — release-2.1 ( e6c696...22bfba )
by Mathias
07:04
created

Post.template.php ➔ template_announce()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 44
Code Lines 17

Duplication

Lines 5
Ratio 11.36 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 0
dl 5
loc 44
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2016 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 3
11
 */
12
13
/**
14
 * The main template for the post page.
15
 */
16
function template_main()
0 ignored issues
show
Best Practice introduced by
The function template_main() has been defined more than once; this definition is ignored, only the first definition in Themes/default/BoardIndex.template.php (L56-178) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
17
{
18
	global $context, $options, $txt, $scripturl, $modSettings, $counter;
19
20
	// Start the javascript... and boy is there a lot.
21
	echo '
22
		<script>';
23
24
	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
	if (isBrowser('is_firefox'))
26
		echo '
27
			window.addEventListener("pageshow", reActivate, false);';
28
29
	// Start with message icons - and any missing from this theme.
30
	echo '
31
			var icon_urls = {';
32 View Code Duplication
	foreach ($context['icons'] as $icon)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
		echo '
34
				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
35
	echo '
36
			};';
37
38
	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
39
	if ($context['make_poll'])
40
		echo '
41
			var pollOptionNum = 0, pollTabIndex;
42
			var pollOptionId = ', $context['last_choice_id'], ';
43
			function addPollOption()
44
			{
45
				if (pollOptionNum == 0)
46
				{
47
					for (var i = 0, n = document.forms.postmodify.elements.length; i < n; i++)
48
						if (document.forms.postmodify.elements[i].id.substr(0, 8) == \'options-\')
49
						{
50
							pollOptionNum++;
51
							pollTabIndex = document.forms.postmodify.elements[i].tabIndex;
52
						}
53
				}
54
				pollOptionNum++
55
				pollOptionId++
56
57
				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('" class="input_text"></dd><p id="pollMoreOptions"></p>'), ');
58
			}';
59
60
	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
61
	if ($context['make_event'])
62
		echo '
63
			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
64
65
	// End of the javascript, start the form and display the link tree.
66
	echo '
67
		</script>
68
		<form action="', $scripturl, '?action=', $context['destination'], ';', empty($context['current_board']) ? '' : 'board=' . $context['current_board'], '" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="', ($context['becomes_approved'] ? '' : 'alert(\'' . $txt['js_post_will_require_approval'] . '\');'), 'submitonce(this);smc_saveEntities(\'postmodify\', [\'subject\', \'', $context['post_box_name'], '\', \'guestname\', \'evtitle\', \'question\'], \'options\');" enctype="multipart/form-data">';
69
70
	// If the user wants to see how their message looks - the preview section is where it's at!
71
	echo '
72
			<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
73
				<div class="cat_bar">
74
					<h3 class="catbg">
75
						<span id="preview_subject">', empty($context['preview_subject']) ? '&nbsp;' : $context['preview_subject'], '</span>
76
					</h3>
77
				</div>
78
				<div id="preview_body" class="windowbg noup">
79
					', empty($context['preview_message']) ? '<br>' : $context['preview_message'], '
80
				</div>
81
			</div><br>';
82
83 View Code Duplication
	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
		echo '
85
			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
86
87
	// Start the main table.
88
	echo '
89
			<div class="cat_bar">
90
				<h3 class="catbg">', $context['page_title'], '</h3>
91
			</div>
92
			<div id="post_area">
93
				<div class="roundframe noup">', isset($context['current_topic']) ? '
94
					<input type="hidden" name="topic" value="' . $context['current_topic'] . '">' : '';
95
96
	// If an error occurred, explain what happened.
97
	echo '
98
					<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']) ? ' style="display: none"' : '', ' id="errors">
99
						<dl>
100
							<dt>
101
								<strong id="error_serious">', $txt['error_while_submitting'], '</strong>
102
							</dt>
103
							<dd class="error" id="error_list">
104
								', empty($context['post_error']) ? '' : implode('<br>', $context['post_error']), '
105
							</dd>
106
						</dl>
107
					</div>';
108
109
	// If this won't be approved let them know!
110
	if (!$context['becomes_approved'])
111
	{
112
		echo '
113
					<p class="information">
114
						<em>', $txt['wait_for_approval'], '</em>
115
						<input type="hidden" name="not_approved" value="1">
116
					</p>';
117
	}
118
119
	// If it's locked, show a message to warn the replier.
120
	if (!empty($context['locked']))
121
	echo '
122
					<p class="errorbox">
123
						', $txt['topic_locked_no_reply'], '
124
					</p>';
125
126
	if (!empty($modSettings['drafts_post_enabled']))
127
		echo '
128
					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
129
						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
130
						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
131
					</div>';
132
133
	// The post header... important stuff
134
	echo '
135
					<dl id="post_header">';
136
137
	// Custom posting fields.
138
	if (!empty($context['posting_fields']) && is_array($context['posting_fields']))
139
		foreach ($context['posting_fields'] as $pf)
140
			echo '
141
						<dt>
142
							', $pf['dt'] ,'
143
						</dt>
144
						<dd>
145
							', $pf['dd'] ,'
146
						</dd>';
147
148
149
	// Guests have to put in their name and email...
150
	if (isset($context['name']) && isset($context['email']))
151
	{
152
		echo '
153
						<dt>
154
							<span', isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? ' class="error"' : '', ' id="caption_guestname">', $txt['name'], ':</span>
155
						</dt>
156
						<dd>
157
							<input type="text" name="guestname" size="25" value="', $context['name'], '" tabindex="', $context['tabindex']++, '" class="input_text">
158
						</dd>';
159
160
		if (empty($modSettings['guest_post_no_email']))
161
			echo '
162
						<dt>
163
							<span', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? ' class="error"' : '', ' id="caption_email">', $txt['email'], ':</span>
164
						</dt>
165
						<dd>
166
							<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" class="input_text" required>
167
						</dd>';
168
	}
169
170
	// Now show the subject box for this post.
171
	echo '
172
						<dt class="clear">
173
							<span', isset($context['post_error']['no_subject']) ? ' class="error"' : '', ' id="caption_subject">', $txt['subject'], ':</span>
174
						</dt>
175
						<dd>
176
							<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80"', isset($context['post_error']['no_subject']) ? ' class="error"' : ' class="input_text"', ' required>
177
						</dd>
178
						<dt class="clear_left">
179
							', $txt['message_icon'], ':
180
						</dt>
181
						<dd>
182
							<select name="icon" id="icon" onchange="showimage()">';
183
184
	// Loop through each message icon allowed, adding it to the drop down list.
185 View Code Duplication
	foreach ($context['icons'] as $icon)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
186
		echo '
187
								<option value="', $icon['value'], '"', $icon['value'] == $context['icon'] ? ' selected' : '', '>', $icon['name'], '</option>';
188
189
	echo '
190
							</select>
191
							<img src="', $context['icon_url'], '" id="icons" alt="">
192
						</dd>
193
					</dl>';
194
195
	// Are you posting a calendar event?
196
	if ($context['make_event'])
197
	{
198
		echo '
199
					<hr class="clear">
200
					<div id="post_event">
201
						<fieldset id="event_main">
202
							<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
203
							<input type="hidden" name="calendar" value="1">
204
							<div class="event_options_left" id="event_title">
205
								<div>
206
									<input type="text" id="evtitle" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '" class="input_text">
207
								</div>
208
							</div>';
209
210
			// If this is a new event let the user specify which board they want the linked post to be put into.
211
			if ($context['event']['new'] && $context['is_new_post'])
212
			{
213
				echo '
214
							<div class="event_options_right" id="event_board">
215
								<div>
216
									<span class="label">', $txt['calendar_post_in'], '</span>
217
									<select name="board">';
218 View Code Duplication
				foreach ($context['event']['categories'] as $category)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219
				{
220
					echo '
221
										<optgroup label="', $category['name'], '">';
222
					foreach ($category['boards'] as $board)
223
						echo '
224
											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
225
					echo '
226
										</optgroup>';
227
				}
228
				echo '
229
									</select>
230
								</div>
231
							</div>';
232
			}
233
234
			// Note to theme writers: The JavaScripts expect the input fields for the start and end dates & times to be contained in a wrapper element with the id "event_time_input"
235
			echo '
236
						</fieldset>
237
						<fieldset id="event_options">
238
							<legend>', $txt['calendar_event_options'], '</legend>
239
							<div class="event_options_left" id="event_time_input">
240
								<div>
241
									<span class="label">', $txt['start'], '</span>
242
									<input type="text" name="start_date" id="start_date" maxlength="10" value="', $context['event']['start_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input start" data-type="date">
243
									<input type="text" name="start_time" id="start_time" maxlength="11" value="', $context['event']['start_time'], '" tabindex="', $context['tabindex']++, '" class="input_text time_input start" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
244
								</div>
245
								<div>
246
									<span class="label">', $txt['end'], '</span>
247
									<input type="text" name="end_date" id="end_date" maxlength="10" value="', $context['event']['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date"', $modSettings['cal_maxspan'] == 1 ? ' disabled' : '', '>
248
									<input type="text" name="end_time" id="end_time" maxlength="11" value="', $context['event']['end_time'], '" tabindex="', $context['tabindex']++, '" class="input_text time_input end" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
249
								</div>
250
							</div>
251
							<div class="event_options_right" id="event_time_options">
252
								<div id="event_allday">
253
									<label for="allday"><span class="label">', $txt['calendar_allday'], '</span></label>
254
									<input type="checkbox" name="allday" id="allday"', !empty($context['event']['allday']) ? ' checked' : '', ' tabindex="', $context['tabindex']++, '">
255
								</div>
256
								<div id="event_timezone">
257
									<span class="label">', $txt['calendar_timezone'], '</span>
258
									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
259
260 View Code Duplication
			foreach ($context['all_timezones'] as $tz => $tzname)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
261
				echo '
262
										<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
263
264
			echo '
265
									</select>
266
								</div>
267
							</div>
268
							<div>
269
								<span class="label">', $txt['location'], '</span>
270
								<input type="text" name="event_location" id="event_location" maxlength="255" value="', $context['event']['location'], '" tabindex="', $context['tabindex']++, '" class="input_text">
271
							</div>
272
						</fieldset>
273
					</div>';
274
	}
275
276
	// If this is a poll then display all the poll options!
277
	if ($context['make_poll'])
278
	{
279
		echo '
280
					<hr class="clear">
281
					<div id="edit_poll">
282
						<fieldset id="poll_main">
283
							<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], '</span></legend>
284
							<dl class="settings poll_options">
285
								<dt>', $txt['poll_question'], '</dt>
286
								<dd><input type="text" name="question" value="', isset($context['question']) ? $context['question'] : '', '" tabindex="', $context['tabindex']++, '" size="80" class="input_text"></dd>';
287
288
		// Loop through all the choices and print them out.
289
		foreach ($context['choices'] as $choice)
290
		{
291
			echo '
292
								<dt>
293
									<label for="options-', $choice['id'], '">', $txt['option'], ' ', $choice['number'], '</label>:
294
								</dt>
295
								<dd>
296
									<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="255" class="input_text">
297
								</dd>';
298
		}
299
300
		echo '
301
								<p id="pollMoreOptions"></p>
302
							</dl>
303
							<strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
304
						</fieldset>
305
						<fieldset id="poll_options">
306
							<legend>', $txt['poll_options'], '</legend>
307
							<dl class="settings poll_options">
308
								<dt>
309
									<label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
310
								</dt>
311
								<dd>
312
									<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll_options']['max_votes'], '" class="input_text">
313
								</dd>
314
								<dt>
315
									<label for="poll_expire">', $txt['poll_run'], ':</label><br>
316
									<em class="smalltext">', $txt['poll_run_limit'], '</em>
317
								</dt>
318
								<dd>
319
									<input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll_options']['expire'], '" onchange="pollOptions();" maxlength="4" class="input_text"> ', $txt['days_word'], '
320
								</dd>
321
								<dt>
322
									<label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
323
								</dt>
324
								<dd>
325
									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', ' class="input_check">
326
								</dd>';
327
328 View Code Duplication
		if ($context['poll_options']['guest_vote_enabled'])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
329
			echo '
330
								<dt>
331
									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
332
								</dt>
333
								<dd>
334
									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', ' class="input_check">
335
								</dd>';
336
337
		echo '
338
								<dt>
339
									', $txt['poll_results_visibility'], ':
340
								</dt>
341
								<dd>
342
									<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll_options']['hide'] == 0 ? ' checked' : '', ' class="input_radio"> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br>
343
									<input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll_options']['hide'] == 1 ? ' checked' : '', ' class="input_radio"> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br>
344
									<input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll_options']['hide'] == 2 ? ' checked' : '', empty($context['poll_options']['expire']) ? ' disabled' : '', ' class="input_radio"> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
345
								</dd>
346
							</dl>
347
						</fieldset>
348
					</div>';
349
	}
350
351
	// Show the actual posting area...
352
	echo '
353
					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
0 ignored issues
show
Documentation introduced by
'smileyBox_message' is of type string, but the function expects a null|boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'bbcBox_message' is of type string, but the function expects a null|boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
354
355
	// If we're editing and displaying edit details, show a box where they can say why
356
	if (isset($context['editing']) && $modSettings['show_modify'])
357
		echo '
358
					<dl>
359
						<dt class="clear">
360
							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
361
						</dt>
362
						<dd>
363
							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text">
364
						</dd>
365
					</dl>';
366
367
	// If this message has been edited in the past - display when it was.
368
	if (isset($context['last_modified']))
369
		echo '
370
					<div class="padding smalltext">
371
						', $context['last_modified_text'], '
372
					</div>';
373
374
	// If the admin has enabled the hiding of the additional options - show a link and image for it.
375
	if (!empty($modSettings['additional_options_collapsable']))
376
		echo '
377
					<div id="postAdditionalOptionsHeader">
378
						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
379
					</div>';
380
381
	echo '
382
					<div id="postAdditionalOptions">';
383
384
	// Display the check boxes for all the standard options - if they are available to the user!
385
	echo '
386
						<div id="postMoreOptions" class="smalltext">
387
							<ul class="post_options">
388
								', $context['can_notify'] ? '<li><input type="hidden" name="notify" value="0"><label for="check_notify"><input type="checkbox" name="notify" id="check_notify"' . ($context['notify'] || !empty($options['auto_notify']) || $context['auto_notify'] ? ' checked' : '') . ' value="1" class="input_check"> ' . $txt['notify_replies'] . '</label></li>' : '', '
389
								', $context['can_lock'] ? '<li><input type="hidden" name="already_locked" value="' . $context['already_locked'] . '"><input type="hidden" name="lock" value="0"><label for="check_lock"><input type="checkbox" name="lock" id="check_lock"' . ($context['locked'] ? ' checked' : '') . ' value="1" class="input_check"> ' . $txt['lock_topic'] . '</label></li>' : '', '
390
								<li><label for="check_back"><input type="checkbox" name="goback" id="check_back"' . ($context['back_to_topic'] || !empty($options['return_to_post']) ? ' checked' : '') . ' value="1" class="input_check"> ' . $txt['back_to_topic'] . '</label></li>
391
								', $context['can_sticky'] ? '<li><input type="hidden" name="already_sticky" value="' . $context['already_sticky'] . '"><input type="hidden" name="sticky" value="0"><label for="check_sticky"><input type="checkbox" name="sticky" id="check_sticky"' . ($context['sticky'] ? ' checked' : '') . ' value="1" class="input_check"> ' . $txt['sticky_after'] . '</label></li>' : '', '
392
								<li><label for="check_smileys"><input type="checkbox" name="ns" id="check_smileys"', $context['use_smileys'] ? '' : ' checked', ' value="NS" class="input_check"> ', $txt['dont_use_smileys'], '</label></li>', '
393
								', $context['can_move'] ? '<li><input type="hidden" name="move" value="0"><label for="check_move"><input type="checkbox" name="move" id="check_move" value="1" class="input_check"' . (!empty($context['move']) ? ' checked" ' : '') . '> ' . $txt['move_after2'] . '</label></li>' : '', '
394
								', $context['can_announce'] && $context['is_first_post'] ? '<li><label for="check_announce"><input type="checkbox" name="announce_topic" id="check_announce" value="1" class="input_check"' . (!empty($context['announce']) ? ' checked' : '') . '> ' . $txt['announce_topic'] . '</label></li>' : '', '
395
								', $context['show_approval'] ? '<li><label for="approve"><input type="checkbox" name="approve" id="approve" value="2" class="input_check"' . ($context['show_approval'] === 2 ? ' checked' : '') . '> ' . $txt['approve_this_post'] . '</label></li>' : '', '
396
							</ul>
397
						</div>';
398
399
	// If this post already has attachments on it - give information about them.
400
	if (!empty($context['current_attachments']))
401
	{
402
		echo '
403
						<dl id="postAttachment">
404
							<dt>
405
								', $txt['attached'], ':
406
							</dt>
407
							<dd class="smalltext" style="width: 100%;">
408
								<input type="hidden" name="attach_del[]" value="0">
409
								', $txt['uncheck_unwatchd_attach'], ':
410
							</dd>';
411
		foreach ($context['current_attachments'] as $attachment)
412
			echo '
413
							<dd class="smalltext">
414
								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', ' class="input_check"> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
415
								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1028) / 1028), 0)) : '', '</label>
416
							</dd>';
417
418
		echo '
419
						</dl>';
420
421
		if (!empty($context['files_in_session_warning']))
422
			echo '
423
						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
424
	}
425
426
	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
427
	if ($context['can_post_attachment'])
428
	{
429
			// Print dropzone UI.
430
			echo '
431
						<div class="files" id="au-previews">
432
							<div id="au-template">
433
								<div class="attach-preview">
434
									<img data-dz-thumbnail />
435
								</div>
436
								<div class="attach-info">
437
									<p class="name" data-dz-name></p>
438
									<p class="error" data-dz-errormessage></p>
439
									<p class="size" data-dz-size></p>
440
									<p class="message" data-dz-message></p>
441
									<p class="attached_BBC">
442
										<input type="text" name="attachBBC" value="" readonly>
443
										<a class="button_submit insertBBC">', $txt['attached_insertBBC'] ,'</a>
444
									</p>
445
									<p class="progressBar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span></span></p>
446
								</div>
447
								<div class="attach-ui">
448
									<a data-dz-remove class="button_submit delete">', $txt['modify_cancel'] ,'</a>
449
									<a class="button_submit start">', $txt['upload'] ,'</a>
450
								</div>
451
							</div>
452
						</div>
453
						<div id ="maxFiles_progress" class="maxFiles_progress progressBar"><span></span></div>
454
						<div id ="maxFiles_progress_text"></div>';
455
456
		echo '
457
						<dl id="postAttachment2">';
458
459
460
		echo '
461
							<dt>
462
								', $txt['attach'], ':
463
							</dt>
464
							<dd class="smalltext fallback">
465
								<div id="attachUpload" class="descbox">
466
									<h5>', $txt['attach_drop_zone'] ,'</h5>
467
									<a class="button_submit" id="attach-cancelAll">', $txt['attached_cancelAll'] ,'</a>
468
									<a class="button_submit" id="attach-uploadAll">', $txt['attached_uploadAll'] ,'</a>
469
									<a class="button_submit fileinput-button">', $txt['attach_add'] ,'</a>
470
									<div id="total-progress" class="progressBar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span></span></div>
471
									<div class="fallback">
472
										<input type="file" multiple="multiple" name="attachment[]" id="attachment1" class="input_file fallback"> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)
473
								', empty($modSettings['attachmentSizeLimit']) ? '' : ('<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1028 . '">');
474
475
		// Show more boxes if they aren't approaching that limit.
476
		if ($context['num_allowed_attachments'] > 1)
477
			echo '
478
										<script>
479
											var allowed_attachments = ', $context['num_allowed_attachments'], ';
480
											var current_attachment = 1;
481
482
											function addAttachment()
483
											{
484
												allowed_attachments = allowed_attachments - 1;
485
												current_attachment = current_attachment + 1;
486
												if (allowed_attachments <= 0)
487
													return alert("', $txt['more_attachments_error'], '");
488
489
												setOuterHTML(document.getElementById("moreAttachments"), \'<dd class="smalltext"><input type="file" name="attachment[]" id="attachment\' + current_attachment + \'" class="input_file"> (<a href="javascript:void(0);" onclick="cleanFileInput(\\\'attachment\' + current_attachment + \'\\\');">', $txt['clean_attach'], '<\/a>)\' + \'<\/dd><dd class="smalltext" id="moreAttachments"><a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')<\' + \'/a><\' + \'/dd>\');
490
491
												return true;
492
											}
493
										</script>
494
										<a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')</a>
495
									</div>
496
								</div>
497
							</dd>';
498
		else
499
			echo '
500
							</dd>';
501
502
		// Add any template changes for an alternative upload system here.
503
		call_integration_hook('integrate_upload_template');
504
505
		echo '
506
							<dd class="smalltext">';
507
508
		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
509
		if (!empty($modSettings['attachmentCheckExtensions']))
510
			echo '
511
								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
512
513
		if (!empty($context['attachment_restrictions']))
514
			echo '
515
								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
516
517
		if ($context['num_allowed_attachments'] == 0)
518
			echo '
519
								', $txt['attach_limit_nag'], '<br>';
520
521
		if (!$context['can_post_attachment_unapproved'])
522
			echo '
523
								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
524
525
		echo '
526
							</dd>
527
						</dl>';
528
	}
529
530
		echo '
531
					</div>';
532
	// If the admin enabled the drafts feature, show a draft selection box
533 View Code Duplication
	if (!empty($modSettings['drafts_post_enabled']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
534
	{
535
		echo '
536
					<div id="postDraftOptionsHeader" class="title_bar title_top">
537
						<h4 class="titlebg">
538
							<span id="postDraftExpand" class="toggle_up floatright" style="display: none;"></span> <strong><a href="#" id="postDraftExpandLink">', $txt['draft_load'], '</a></strong>
539
						</h4>
540
					</div>
541
					<div id="postDraftOptions">
542
						<dl class="settings">
543
							<dt><strong>', $txt['subject'], '</strong></dt>
544
							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
545
546
		foreach ($context['drafts'] as $draft)
547
			echo '
548
							<dt>', $draft['link'], '</dt>
549
							<dd>', $draft['poster_time'], '</dd>';
550
		echo '
551
						</dl>
552
					</div>';
553
	}
554
555
	// Is visual verification enabled?
556
	if ($context['require_verification'])
557
	{
558
		echo '
559
					<div class="post_verification">
560
						<span', !empty($context['post_error']['need_qr_verification']) ? ' class="error"' : '', '>
561
							<strong>', $txt['verification'], ':</strong>
562
						</span>
563
						', template_control_verification($context['visual_verification_id'], 'all'), '
564
					</div>';
565
	}
566
567
	// Finally, the submit buttons.
568
	echo '
569
					<br class="clear_right">
570
					<span id="post_confirm_buttons">
571
						', template_control_richedit_buttons($context['post_box_name']);
572
573
	// Option to delete an event if user is editing one.
574
	if ($context['make_event'] && !$context['event']['new'])
575
		echo '
576
						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button_submit you_sure">';
577
578
	echo '
579
					</span>
580
				</div>
581
			</div>
582
			<br class="clear">';
583
584
	// Assuming this isn't a new topic pass across the last message id.
585
	if (isset($context['topic_last_message']))
586
		echo '
587
			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
588
589
	echo '
590
			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
591
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
592
			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
593
		</form>';
594
595
	echo '
596
		<script>';
597
598
	// The functions used to preview a posts without loading a new page.
599
	echo '
600
			var make_poll = ', $context['make_poll'] ? 'true' : 'false', ';
601
			var txt_preview_title = "', $txt['preview_title'], '";
602
			var txt_preview_fetch = "', $txt['preview_fetch'], '";
603
			var new_replies = new Array();
604
			var reply_counter = ', empty($counter) ? 0 : $counter, ';
605
			function previewPost()
606
			{
607
				if (window.XMLHttpRequest)
608
				{
609
					// Opera didn\'t support setRequestHeader() before 8.01.
610
					if (\'opera\' in window)
611
					{
612
						var test = new XMLHttpRequest();
613
						if (!(\'setRequestHeader\' in test))
614
							return submitThisOnce(document.forms.postmodify);
615
					}
616
					// @todo Currently not sending poll options and option checkboxes.
617
					var x = new Array();
618
					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', ', JavaScriptEscape($context['session_var']), ', \'icon\', \'guestname\', \'email\', \'evtitle\', \'question\', \'topic\'];
619
					var numericFields = [
620
						\'board\', \'topic\', \'last_msg\',
621
						\'eventid\', \'calendar\', \'year\', \'month\', \'day\',
622
						\'poll_max_votes\', \'poll_expire\', \'poll_change_vote\', \'poll_hide\'
623
					];
624
					var checkboxFields = [
625
						\'ns\'
626
					];
627
628
					for (var i = 0, n = textFields.length; i < n; i++)
629
						if (textFields[i] in document.forms.postmodify)
630
						{
631
							// Handle the WYSIWYG editor.
632
							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && $("#', $context['post_box_name'], '").data("sceditor") != undefined)
633
								x[x.length] = textFields[i] + \'=\' + $("#', $context['post_box_name'], '").data("sceditor").getText().replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
634
							else
635
								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.replace(/&#/g, \'&#38;#\').php_to8bit().php_urlencode();
636
						}
637
					for (var i = 0, n = numericFields.length; i < n; i++)
638
						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
639
							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
640
					for (var i = 0, n = checkboxFields.length; i < n; i++)
641
						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
642
							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
643
644
					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=post2\' + (current_board ? \';board=\' + current_board : \'\') + (make_poll ? \';poll\' : \'\') + \';preview;xml\', x.join(\'&\'), onDocSent);
645
646
					document.getElementById(\'preview_section\').style.display = \'\';
647
					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
648
					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
649
650
					return false;
651
				}
652
				else
653
					return submitThisOnce(document.forms.postmodify);
654
			}
655
			function onDocSent(XMLDoc)
656
			{
657
				if (!XMLDoc)
658
				{
659
					document.forms.postmodify.preview.onclick = new function ()
660
					{
661
						return true;
662
					}
663
					document.forms.postmodify.preview.click();
664
				}
665
666
				// Show the preview section.
667
				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
668
				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
669
670
				var bodyText = \'\';
671
				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
672
					if (preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue != null)
673
						bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
674
675
				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
676
				document.getElementById(\'preview_body\').className = \'windowbg\';
677
678
				// Show a list of errors (if any).
679
				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
680
				var errorList = new Array();
681
				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
682
					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
683
				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
684
				document.getElementById(\'errors\').className = errors.getAttribute(\'serious\') == 1 ? \'errorbox\' : \'noticebox\';
685
				document.getElementById(\'error_serious\').style.display = numErrors == 0 ? \'none\' : \'\';
686
				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br>\'));
687
688
				// Adjust the color of captions if the given data is erroneous.
689
				var captions = errors.getElementsByTagName(\'caption\');
690
				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
691
					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
692
						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
693
694
				if (errors.getElementsByTagName(\'post_error\').length == 1)
695
					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
696
				else if (document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red\' || document.forms.postmodify.', $context['post_box_name'], '.style.borderColor == \'red red red red\')
697
				{
698
					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
699
						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
700
					else
701
						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
702
				}
703
704
				// Set the new last message id.
705
				if (\'last_msg\' in document.forms.postmodify)
706
					document.forms.postmodify.last_msg.value = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'last_msg\')[0].firstChild.nodeValue;
707
708
				// Remove the new image from old-new replies!
709
				for (i = 0; i < new_replies.length; i++)
710
					document.getElementById(\'image_new_\' + new_replies[i]).style.display = \'none\';
711
				new_replies = new Array();
712
713
				var ignored_replies = new Array(), ignoring;
714
				var newPosts = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'new_posts\')[0] ? XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'new_posts\')[0].getElementsByTagName(\'post\') : {length: 0};
715
				var numNewPosts = newPosts.length;
716
				if (numNewPosts != 0)
717
				{
718
					var newPostsHTML = \'<span id="new_replies"><\' + \'/span>\';
719
					for (var i = 0; i < numNewPosts; i++)
720
					{
721
						new_replies[new_replies.length] = newPosts[i].getAttribute("id");
722
723
						ignoring = false;
724
						if (newPosts[i].getElementsByTagName("is_ignored")[0].firstChild.nodeValue != 0)
725
							ignored_replies[ignored_replies.length] = ignoring = newPosts[i].getAttribute("id");
726
727
						newPostsHTML += \'<div class="windowbg\' + (++reply_counter % 2 == 0 ? \'2\' : \'\') + \'"><div id="msg\' + newPosts[i].getAttribute("id") + \'"><div class="floatleft"><h5>', $txt['posted_by'], ': \' + newPosts[i].getElementsByTagName("poster")[0].firstChild.nodeValue + \'</h5><span class="smalltext">&#171;&nbsp;<strong>', $txt['on'], ':</strong> \' + newPosts[i].getElementsByTagName("time")[0].firstChild.nodeValue + \'&nbsp;&#187;</span> <span class="new_posts" id="image_new_\' + newPosts[i].getAttribute("id") + \'">', $txt['new'], '</span></div>\';';
728
729
	if ($context['can_quote'])
730
		echo '
731
						newPostsHTML += \'<ul class="quickbuttons" id="msg_\' + newPosts[i].getAttribute("id") + \'_quote"><li><a href="#postmodify" onclick="return insertQuoteFast(\\\'\' + newPosts[i].getAttribute("id") + \'\\\');" class="quote_button"><span>', $txt['quote'], '</span><\' + \'/a></li></ul>\';';
732
733
	echo '
734
						newPostsHTML += \'<br class="clear">\';
735
736
						if (ignoring)
737
							newPostsHTML += \'<div id="msg_\' + newPosts[i].getAttribute("id") + \'_ignored_prompt" class="smalltext">', $txt['ignoring_user'], '<a href="#" id="msg_\' + newPosts[i].getAttribute("id") + \'_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a></div>\';
738
739
						newPostsHTML += \'<div class="list_posts smalltext" id="msg_\' + newPosts[i].getAttribute("id") + \'_body">\' + newPosts[i].getElementsByTagName("message")[0].firstChild.nodeValue + \'<\' + \'/div></div></div>\';
740
					}
741
					setOuterHTML(document.getElementById(\'new_replies\'), newPostsHTML);
742
				}
743
744
				var numIgnoredReplies = ignored_replies.length;
745
				if (numIgnoredReplies != 0)
746
				{
747
					for (var i = 0; i < numIgnoredReplies; i++)
748
					{
749
						aIgnoreToggles[ignored_replies[i]] = new smc_Toggle({
750
							bToggleEnabled: true,
751
							bCurrentlyCollapsed: true,
752
							aSwappableContainers: [
753
								\'msg_\' + ignored_replies[i] + \'_body\',
754
								\'msg_\' + ignored_replies[i] + \'_quote\',
755
							],
756
							aSwapLinks: [
757
								{
758
									sId: \'msg_\' + ignored_replies[i] + \'_ignored_link\',
759
									msgExpanded: \'\',
760
									msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
761
								}
762
							]
763
						});
764
					}
765
				}
766
767
				location.hash = \'#\' + \'preview_section\';
768
769
				if (typeof(smf_codeFix) != \'undefined\')
770
					smf_codeFix();
771
			}';
772
773
	// Code for showing and hiding additional options.
774
	if (!empty($modSettings['additional_options_collapsable']))
775
		echo '
776
			var oSwapAdditionalOptions = new smc_Toggle({
777
				bToggleEnabled: true,
778
				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
779
				funcOnBeforeCollapse: function () {
780
					document.getElementById(\'additional_options\').value = \'0\';
781
				},
782
				funcOnBeforeExpand: function () {
783
					document.getElementById(\'additional_options\').value = \'1\';
784
				},
785
				aSwappableContainers: [
786
					\'postAdditionalOptions\',
787
				],
788
				aSwapImages: [
789
					{
790
						sId: \'postMoreExpandLink\',
791
						altExpanded: \'-\',
792
						altCollapsed: \'+\'
793
					}
794
				],
795
				aSwapLinks: [
796
					{
797
						sId: \'postMoreExpandLink\',
798
						msgExpanded: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), ',
799
						msgCollapsed: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), '
800
					}
801
				]
802
			});';
803
804
	// Code for showing and hiding drafts
805 View Code Duplication
	if (!empty($context['drafts']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
806
		echo '
807
			var oSwapDraftOptions = new smc_Toggle({
808
				bToggleEnabled: true,
809
				bCurrentlyCollapsed: true,
810
				aSwappableContainers: [
811
					\'postDraftOptions\',
812
				],
813
				aSwapImages: [
814
					{
815
						sId: \'postDraftExpand\',
816
						altExpanded: \'-\',
817
						altCollapsed: \'+\'
818
					}
819
				],
820
				aSwapLinks: [
821
					{
822
						sId: \'postDraftExpandLink\',
823
						msgExpanded: ', JavaScriptEscape($txt['draft_hide']), ',
824
						msgCollapsed: ', JavaScriptEscape($txt['draft_load']), '
825
					}
826
				]
827
			});';
828
829
	echo '
830
			var oEditorID = "', $context['post_box_name'] ,'";
831
			var oEditorObject = oEditorHandle_', $context['post_box_name'], ';
832
		</script>';
833
834
	// If the user is replying to a topic show the previous posts.
835
	if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
836
	{
837
		echo '
838
		<div id="recent" class="flow_hidden main_section">
839
			<div class="cat_bar">
840
				<h3 class="catbg">', $txt['topic_summary'], '</h3>
841
			</div>
842
			<span id="new_replies"></span>';
843
844
		$ignored_posts = array();
845
		foreach ($context['previous_posts'] as $post)
846
		{
847
			$ignoring = false;
848
			if (!empty($post['is_ignored']))
849
				$ignored_posts[] = $ignoring = $post['id'];
850
851
			echo '
852
			<div class="windowbg">
853
				<div id="msg', $post['id'], '">
854
					<h5 class="floatleft">
855
						<span>', $txt['posted_by'], '</span>&nbsp;', $post['poster'], '
856
					</h5>&nbsp;-&nbsp;', $post['time'];
857
858
			if ($context['can_quote'])
859
			{
860
				echo '
861
					<ul class="quickbuttons" id="msg_', $post['id'], '_quote">
862
						<li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>
863
						<li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');"><span class="generic_icons quote"></span>', $txt['quote'], '</a></li>
864
					</ul>';
865
			}
866
867
			echo '
868
					<br class="clear">';
869
870 View Code Duplication
			if ($ignoring)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
871
			{
872
				echo '
873
					<div id="msg_', $post['id'], '_ignored_prompt" class="smalltext">
874
						', $txt['ignoring_user'], '
875
						<a href="#" id="msg_', $post['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
876
					</div>';
877
			}
878
879
			echo '
880
					<div class="list_posts smalltext" id="msg_', $post['id'], '_body" data-msgid="', $post['id'], '">', $post['message'], '</div>
881
				</div>
882
			</div>';
883
		}
884
885
		echo '
886
		</div>
887
		<script>
888
			var aIgnoreToggles = new Array();';
889
890
		foreach ($ignored_posts as $post_id)
891
		{
892
			echo '
893
			aIgnoreToggles[', $post_id, '] = new smc_Toggle({
894
				bToggleEnabled: true,
895
				bCurrentlyCollapsed: true,
896
				aSwappableContainers: [
897
					\'msg_', $post_id, '_body\',
898
					\'msg_', $post_id, '_quote\',
899
				],
900
				aSwapLinks: [
901
					{
902
						sId: \'msg_', $post_id, '_ignored_link\',
903
						msgExpanded: \'\',
904
						msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
905
					}
906
				]
907
			});';
908
		}
909
910
		echo '
911
			function insertQuoteFast(messageid)
912
			{
913
				if (window.XMLHttpRequest)
914
					getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';xml;pb=', $context['post_box_name'], ';mode=0\', onDocReceived);
915
				else
916
					reqWin(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';pb=', $context['post_box_name'], ';mode=0\', 240, 90);
917
918
				return true;
919
			}
920
			function onDocReceived(XMLDoc)
921
			{
922
				var text = \'\';
923
924
				for (var i = 0, n = XMLDoc.getElementsByTagName(\'quote\')[0].childNodes.length; i < n; i++)
925
					text += XMLDoc.getElementsByTagName(\'quote\')[0].childNodes[i].nodeValue;
926
				$("#', $context['post_box_name'], '").data("sceditor").InsertText(text);
927
			}
928
			function onReceiveOpener(text)
929
			{
930
				$("#', $context['post_box_name'], '").data("sceditor").InsertText(text);
931
			}
932
		</script>';
933
	}
934
}
935
936
/**
937
 * The template for the spellchecker.
938
 */
939
function template_spellcheck()
940
{
941
	global $context, $settings, $txt, $modSettings;
942
943
	// The style information that makes the spellchecker look... like the forum hopefully!
944
	echo '<!DOCTYPE html>
945
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
946
	<head>
947
		<meta charset="', $context['character_set'], '">
948
		<title>', $txt['spell_check'], '</title>
949
		<link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'] ,'">
950
		<style>
951
			body, td
952
			{
953
				font-size: small;
954
				margin: 0;
955
				background: #f0f0f0;
956
				color: #000;
957
				padding: 10px;
958
			}
959
			.highlight
960
			{
961
				color: red;
962
				font-weight: bold;
963
			}
964
			#spellview
965
			{
966
				border-style: outset;
967
				border: 1px solid black;
968
				padding: 5px;
969
				width: 95%;
970
				height: 314px;
971
				overflow: auto;
972
				background: #ffffff;
973
			}';
974
975
	// As you may expect - we need a lot of javascript for this... load it form the separate files.
976
	echo '
977
		</style>
978
		<script>
979
			var spell_formname = window.opener.spell_formname;
980
			var spell_fieldname = window.opener.spell_fieldname;
981
		</script>
982
		<script src="', $settings['default_theme_url'], '/scripts/spellcheck.js', $modSettings['browser_cache'] ,'"></script>
983
		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script>
984
		<script>
985
			', $context['spell_js'], '
986
		</script>
987
	</head>
988
	<body onload="nextWord(false);">
989
		<form action="#" method="post" accept-charset="', $context['character_set'], '" name="spellingForm" id="spellingForm" onsubmit="return false;" style="margin: 0;">
990
			<div id="spellview">&nbsp;</div>
991
			<table width="100%"><tr class="windowbg">
992
				<td style="width: 50%; vertical-align: top">
993
					', $txt['spellcheck_change_to'], '<br>
994
					<input type="text" name="changeto" style="width: 98%;" class="input_text">
995
				</td>
996
				<td style="width: 50%">
997
					', $txt['spellcheck_suggest'], '<br>
998
					<select name="suggestions" style="width: 98%;" size="5" onclick="if (this.selectedIndex != -1) this.form.changeto.value = this.options[this.selectedIndex].text;" ondblclick="replaceWord();">
999
					</select>
1000
				</td>
1001
			</tr></table>
1002
			<div class="righttext" style="padding: 4px;">
1003
				<input type="button" name="change" value="', $txt['spellcheck_change'], '" onclick="replaceWord();" class="button_submit">
1004
				<input type="button" name="changeall" value="', $txt['spellcheck_change_all'], '" onclick="replaceAll();" class="button_submit">
1005
				<input type="button" name="ignore" value="', $txt['spellcheck_ignore'], '" onclick="nextWord(false);" class="button_submit">
1006
				<input type="button" name="ignoreall" value="', $txt['spellcheck_ignore_all'], '" onclick="nextWord(true);" class="button_submit">
1007
			</div>
1008
		</form>
1009
	</body>
1010
</html>';
1011
}
1012
1013
/**
1014
 * The template for the AJAX quote feature
1015
 */
1016
function template_quotefast()
1017
{
1018
	global $context, $settings, $txt, $modSettings;
1019
1020
	echo '<!DOCTYPE html>
1021
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
1022
	<head>
1023
		<meta charset="', $context['character_set'], '">
1024
		<title>', $txt['retrieving_quote'], '</title>
1025
		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script>
1026
	</head>
1027
	<body>
1028
		', $txt['retrieving_quote'], '
1029
		<div id="temporary_posting_area" style="display: none;"></div>
1030
		<script>';
1031
1032
	if ($context['close_window'])
1033
		echo '
1034
			window.close();';
1035
	else
1036
	{
1037
		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;).
1038
		echo '
1039
			var quote = \'', $context['quote']['text'], '\';
1040
			var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");
1041
1042
			if (\'DOMParser\' in window && !(\'opera\' in window))
1043
			{
1044
				var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
1045
				quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
1046
			}
1047
			else if (\'innerText\' in stage)
1048
			{
1049
				setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
1050
				quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
1051
			}
1052
1053
			if (\'opera\' in window)
1054
				quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");
1055
1056
			window.opener.onReceiveOpener(quote);
1057
1058
			window.focus();
1059
			setTimeout("window.close();", 400);';
1060
	}
1061
	echo '
1062
		</script>
1063
	</body>
1064
</html>';
1065
}
1066
1067
/**
1068
 * The form for sending out an announcement
1069
 */
1070
function template_announce()
1071
{
1072
	global $context, $txt, $scripturl;
1073
1074
	echo '
1075
	<div id="announcement">
1076
		<form action="', $scripturl, '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '">
1077
			<div class="cat_bar">
1078
				<h3 class="catbg">', $txt['announce_title'], '</h3>
1079
			</div>
1080
			<div class="information">
1081
				', $txt['announce_desc'], '
1082
			</div>
1083
			<div class="windowbg2">
1084
				<p>
1085
					', $txt['announce_this_topic'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0">', $context['topic_subject'], '</a>
1086
				</p>
1087
				<ul>';
1088
1089 View Code Duplication
	foreach ($context['groups'] as $group)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1090
		echo '
1091
					<li>
1092
						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked class="input_check"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
1093
					</li>';
1094
1095
	echo '
1096
					<li>
1097
						<label for="checkall"><input type="checkbox" id="checkall" class="input_check" onclick="invertAll(this, this.form);" checked> <em>', $txt['check_all'], '</em></label>
1098
					</li>
1099
				</ul>
1100
				<hr>
1101
				<div id="confirm_buttons">
1102
					<input type="submit" value="', $txt['post'], '" class="button_submit">
1103
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1104
					<input type="hidden" name="topic" value="', $context['current_topic'], '">
1105
					<input type="hidden" name="move" value="', $context['move'], '">
1106
					<input type="hidden" name="goback" value="', $context['go_back'], '">
1107
				</div>
1108
				<br class="clear_right">
1109
			</div>
1110
		</form>
1111
	</div>
1112
	<br>';
1113
}
1114
1115
/**
1116
 * The confirmation/progress page, displayed after the admin has clicked the button to send the announcement.
1117
 */
1118
function template_announcement_send()
1119
{
1120
	global $context, $txt, $scripturl;
1121
1122
	echo '
1123
	<div id="announcement">
1124
		<form action="' . $scripturl . '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
1125
			<div class="windowbg2">
1126
				<p>', $txt['announce_sending'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0" target="_blank" class="new_win">', $context['topic_subject'], '</a></p>
1127
				<div class="progress_bar">
1128
					<div class="full_bar">', $context['percentage_done'], '% ', $txt['announce_done'], '</div>
1129
					<div class="green_percent" style="width: ', $context['percentage_done'], '%;">&nbsp;</div>
1130
				</div>
1131
				<hr>
1132
				<div id="confirm_buttons">
1133
					<input type="submit" name="b" value="', $txt['announce_continue'], '" class="button_submit">
1134
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1135
					<input type="hidden" name="topic" value="', $context['current_topic'], '">
1136
					<input type="hidden" name="move" value="', $context['move'], '">
1137
					<input type="hidden" name="goback" value="', $context['go_back'], '">
1138
					<input type="hidden" name="start" value="', $context['start'], '">
1139
					<input type="hidden" name="membergroups" value="', $context['membergroups'], '">
1140
				</div>
1141
				<br class="clear_right">
1142
			</div>
1143
		</form>
1144
	</div>
1145
	<br>
1146
		<script>
1147
			var countdown = 2;
1148
			doAutoSubmit();
1149
1150
			function doAutoSubmit()
1151
			{
1152
				if (countdown == 0)
1153
					document.forms.autoSubmit.submit();
1154
				else if (countdown == -1)
1155
					return;
1156
1157
				document.forms.autoSubmit.b.value = "', $txt['announce_continue'], ' (" + countdown + ")";
1158
				countdown--;
1159
1160
				setTimeout("doAutoSubmit();", 1000);
1161
			}
1162
		</script>';
1163
}
1164
1165
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1166