Passed
Push — release-2.1 ( 0c2197...207d2d )
by Jeremy
05:47
created

template_post_header()   F

Complexity

Conditions 67
Paths 1028

Size

Total Lines 250
Code Lines 122

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 67
eloc 122
c 2
b 0
f 0
nop 0
dl 0
loc 250
rs 0
nc 1028

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2018 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 4
11
 */
12
13
/**
14
 * The main template for the post page.
15
 */
16
function template_main()
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
33
	foreach ($context['icons'] as $icon)
34
		echo '
35
				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
36
37
	echo '
38
			};';
39
40
	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
41
	if ($context['make_poll'])
42
		echo '
43
			var pollOptionNum = 0, pollTabIndex;
44
			var pollOptionId = ', $context['last_choice_id'], ';
45
			function addPollOption()
46
			{
47
				if (pollOptionNum == 0)
48
				{
49
					for (var i = 0, n = document.forms.postmodify.elements.length; i < n; i++)
50
						if (document.forms.postmodify.elements[i].id.substr(0, 8) == \'options-\')
51
						{
52
							pollOptionNum++;
53
							pollTabIndex = document.forms.postmodify.elements[i].tabIndex;
54
						}
55
				}
56
				pollOptionNum++
57
				pollOptionId++
58
59
				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('"></dd><p id="pollMoreOptions"></p>'), ');
60
			}';
61
62
	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
63
	if ($context['make_event'])
64
		echo '
65
			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
66
67
	// End of the javascript, start the form and display the link tree.
68
	echo '
69
		</script>
70
		<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);" enctype="multipart/form-data">';
71
72
	// If the user wants to see how their message looks - the preview section is where it's at!
73
	echo '
74
			<div id="preview_section"', isset($context['preview_message']) ? '' : ' style="display: none;"', '>
75
				<div class="cat_bar">
76
					<h3 class="catbg">
77
						<span id="preview_subject">', empty($context['preview_subject']) ? '&nbsp;' : $context['preview_subject'], '</span>
78
					</h3>
79
				</div>
80
				<div id="preview_body" class="windowbg">
81
					', empty($context['preview_message']) ? '<br>' : $context['preview_message'], '
82
				</div>
83
			</div>
84
			<br>';
85
86
	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
87
		echo '
88
			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
89
90
	// Start the main table.
91
	echo '
92
			<div class="cat_bar">
93
				<h3 class="catbg">', $context['page_title'], '</h3>
94
			</div>
95
			<div id="post_area">
96
				<div class="roundframe">', isset($context['current_topic']) ? '
97
					<input type="hidden" name="topic" value="' . $context['current_topic'] . '">' : '';
98
99
	// If an error occurred, explain what happened.
100
	echo '
101
					<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '"', empty($context['post_error']) ? ' style="display: none"' : '', ' id="errors">
102
						<dl>
103
							<dt>
104
								<strong id="error_serious">', $txt['error_while_submitting'], '</strong>
105
							</dt>
106
							<dd class="error" id="error_list">
107
								', empty($context['post_error']) ? '' : implode('<br>', $context['post_error']), '
108
							</dd>
109
						</dl>
110
					</div>';
111
112
	// If this won't be approved let them know!
113
	if (!$context['becomes_approved'])
114
		echo '
115
					<div class="noticebox">
116
						<em>', $txt['wait_for_approval'], '</em>
117
						<input type="hidden" name="not_approved" value="1">
118
					</div>';
119
120
	// If it's locked, show a message to warn the replier.
121
	if (!empty($context['locked']))
122
	echo '
123
					<div class="errorbox">
124
						', $txt['topic_locked_no_reply'], '
125
					</div>';
126
127
	if (!empty($modSettings['drafts_post_enabled']))
128
		echo '
129
					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
130
						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
131
						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
132
					</div>';
133
134
	// The post header... important stuff
135
	template_post_header();
136
137
	// Are you posting a calendar event?
138
	if ($context['make_event'])
139
	{
140
		echo '
141
					<hr class="clear">
142
					<div id="post_event">
143
						<fieldset id="event_main">
144
							<legend><span', isset($context['post_error']['no_event']) ? ' class="error"' : '', '>', $txt['calendar_event_title'], '</span></legend>
145
							<input type="hidden" name="calendar" value="1">
146
							<div class="event_options_left" id="event_title">
147
								<div>
148
									<input type="text" id="evtitle" name="evtitle" maxlength="255" size="55" value="', $context['event']['title'], '" tabindex="', $context['tabindex']++, '">
149
								</div>
150
							</div>';
151
152
		// If this is a new event let the user specify which board they want the linked post to be put into.
153
		if ($context['event']['new'] && $context['is_new_post'])
154
		{
155
			echo '
156
							<div class="event_options_right" id="event_board">
157
								<div>
158
									<span class="label">', $txt['calendar_post_in'], '</span>
159
								<select name="board">';
160
			foreach ($context['event']['categories'] as $category)
161
			{
162
				echo '
163
										<optgroup label="', $category['name'], '">';
164
165
				foreach ($category['boards'] as $board)
166
					echo '
167
											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
168
				echo '
169
										</optgroup>';
170
			}
171
			echo '
172
									</select>
173
								</div>
174
							</div><!-- #event_board -->';
175
		}
176
177
		// 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"
178
		echo '
179
						</fieldset>
180
						<fieldset id="event_options">
181
							<legend>', $txt['calendar_event_options'], '</legend>
182
							<div class="event_options_left" id="event_time_input">
183
								<div>
184
									<span class="label">', $txt['start'], '</span>
185
									<input type="text" name="start_date" id="start_date" maxlength="10" value="', $context['event']['start_date'], '" tabindex="', $context['tabindex']++, '" class="date_input start" data-type="date">
186
									<input type="text" name="start_time" id="start_time" maxlength="11" value="', $context['event']['start_time'], '" tabindex="', $context['tabindex']++, '" class="time_input start" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
187
								</div>
188
								<div>
189
									<span class="label">', $txt['end'], '</span>
190
									<input type="text" name="end_date" id="end_date" maxlength="10" value="', $context['event']['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date"', $modSettings['cal_maxspan'] == 1 ? ' disabled' : '', '>
191
									<input type="text" name="end_time" id="end_time" maxlength="11" value="', $context['event']['end_time'], '" tabindex="', $context['tabindex']++, '" class="time_input end" data-type="time"', !empty($context['event']['allday']) ? ' disabled' : '', '>
192
								</div>
193
							</div>
194
							<div class="event_options_right" id="event_time_options">
195
								<div id="event_allday">
196
									<label for="allday"><span class="label">', $txt['calendar_allday'], '</span></label>
197
									<input type="checkbox" name="allday" id="allday"', !empty($context['event']['allday']) ? ' checked' : '', ' tabindex="', $context['tabindex']++, '">
198
								</div>
199
								<div id="event_timezone">
200
									<span class="label">', $txt['calendar_timezone'], '</span>
201
									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
202
203
		foreach ($context['all_timezones'] as $tz => $tzname)
204
			echo '
205
										<option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
206
207
		echo '
208
									</select>
209
								</div>
210
							</div><!-- #event_time_options -->
211
							<div>
212
								<span class="label">', $txt['location'], '</span>
213
								<input type="text" name="event_location" id="event_location" maxlength="255" value="', $context['event']['location'], '" tabindex="', $context['tabindex']++, '">
214
							</div>
215
						</fieldset>
216
					</div><!-- #post_event -->';
217
	}
218
219
	// If this is a poll then display all the poll options!
220
	if ($context['make_poll'])
221
	{
222
		echo '
223
					<hr class="clear">
224
					<div id="edit_poll">
225
						<fieldset id="poll_main">
226
							<legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], '</span></legend>
227
							<dl class="settings poll_options">
228
								<dt>', $txt['poll_question'], '</dt>
229
								<dd>
230
									<input type="text" name="question" value="', isset($context['question']) ? $context['question'] : '', '" tabindex="', $context['tabindex']++, '" size="80">
231
								</dd>';
232
233
		// Loop through all the choices and print them out.
234
		foreach ($context['choices'] as $choice)
235
			echo '
236
								<dt>
237
									<label for="options-', $choice['id'], '">', $txt['option'], ' ', $choice['number'], '</label>:
238
								</dt>
239
								<dd>
240
									<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="255">
241
								</dd>';
242
243
		echo '
244
								<p id="pollMoreOptions"></p>
245
							</dl>
246
							<strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
247
						</fieldset>
248
						<fieldset id="poll_options">
249
							<legend>', $txt['poll_options'], '</legend>
250
							<dl class="settings poll_options">
251
								<dt>
252
									<label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
253
								</dt>
254
								<dd>
255
									<input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll_options']['max_votes'], '">
256
								</dd>
257
								<dt>
258
									<label for="poll_expire">', $txt['poll_run'], ':</label><br>
259
									<em class="smalltext">', $txt['poll_run_limit'], '</em>
260
								</dt>
261
								<dd>
262
									<input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll_options']['expire'], '" onchange="pollOptions();" maxlength="4"> ', $txt['days_word'], '
263
								</dd>
264
								<dt>
265
									<label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
266
								</dt>
267
								<dd>
268
									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', '>
269
								</dd>';
270
271
		if ($context['poll_options']['guest_vote_enabled'])
272
			echo '
273
								<dt>
274
									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
275
								</dt>
276
								<dd>
277
									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', '>
278
								</dd>';
279
280
		echo '
281
								<dt>
282
									', $txt['poll_results_visibility'], ':
283
								</dt>
284
								<dd>
285
									<input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll_options']['hide'] == 0 ? ' checked' : '', '> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br>
286
									<input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll_options']['hide'] == 1 ? ' checked' : '', '> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br>
287
									<input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll_options']['hide'] == 2 ? ' checked' : '', empty($context['poll_options']['expire']) ? ' disabled' : '', '> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
288
								</dd>
289
							</dl>
290
						</fieldset>
291
					</div><!-- #edit_poll -->';
292
	}
293
294
	// Show the actual posting area...
295
	echo '
296
					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_control_richedi...age', 'bbcBox_message') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
'bbcBox_message' of type string is incompatible with the type boolean|null expected by parameter $bbcContainer of template_control_richedit(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

296
					', template_control_richedit($context['post_box_name'], 'smileyBox_message', /** @scrutinizer ignore-type */ 'bbcBox_message');
Loading history...
Bug introduced by
'smileyBox_message' of type string is incompatible with the type boolean|null expected by parameter $smileyContainer of template_control_richedit(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

296
					', template_control_richedit($context['post_box_name'], /** @scrutinizer ignore-type */ 'smileyBox_message', 'bbcBox_message');
Loading history...
297
298
	// If we're editing and displaying edit details, show a box where they can say why
299
	if (isset($context['editing']) && $modSettings['show_modify'])
300
		echo '
301
					<dl>
302
						<dt class="clear">
303
							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
304
						</dt>
305
						<dd>
306
							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80">
307
						</dd>
308
					</dl>';
309
310
	// If this message has been edited in the past - display when it was.
311
	if (isset($context['last_modified']))
312
		echo '
313
					<div class="padding smalltext">
314
						', $context['last_modified_text'], '
315
					</div>';
316
317
	// If the admin has enabled the hiding of the additional options - show a link and image for it.
318
	if (!empty($modSettings['additional_options_collapsable']))
319
		echo '
320
					<div id="postAdditionalOptionsHeader">
321
						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
322
					</div>';
323
324
	echo '
325
					<div id="postAdditionalOptions">';
326
327
	// Display the checkboxes for all the standard options - if they are available to the user!
328
	echo '
329
						<div id="postMoreOptions" class="smalltext">
330
							<ul class="post_options">
331
								', $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"> ' . $txt['notify_replies'] . '</label></li>' : '', '
332
								', $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"> ' . $txt['lock_topic'] . '</label></li>' : '', '
333
								<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"> ' . $txt['back_to_topic'] . '</label></li>
334
								', $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"> ' . $txt['sticky_after'] . '</label></li>' : '', '
335
								<li><label for="check_smileys"><input type="checkbox" name="ns" id="check_smileys"', $context['use_smileys'] ? '' : ' checked', ' value="NS"> ', $txt['dont_use_smileys'], '</label></li>', '
336
								', $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"' . (!empty($context['move']) ? ' checked" ' : '') . '> ' . $txt['move_after2'] . '</label></li>' : '', '
337
								', $context['can_announce'] && $context['is_first_post'] ? '<li><label for="check_announce"><input type="checkbox" name="announce_topic" id="check_announce" value="1"' . (!empty($context['announce']) ? ' checked' : '') . '> ' . $txt['announce_topic'] . '</label></li>' : '', '
338
								', $context['show_approval'] ? '<li><label for="approve"><input type="checkbox" name="approve" id="approve" value="2"' . ($context['show_approval'] === 2 ? ' checked' : '') . '> ' . $txt['approve_this_post'] . '</label></li>' : '', '
339
							</ul>
340
						</div><!-- #postMoreOptions -->';
341
342
	// If this post already has attachments on it - give information about them.
343
	if (!empty($context['current_attachments']))
344
	{
345
		echo '
346
						<dl id="postAttachment">
347
							<dt>
348
								', $txt['attached'], ':
349
							</dt>
350
							<dd class="smalltext" style="width: 100%;">
351
								<input type="hidden" name="attach_del[]" value="0">
352
								', $txt['uncheck_unwatchd_attach'], ':
353
							</dd>';
354
355
		foreach ($context['current_attachments'] as $attachment)
356
			echo '
357
							<dd class="smalltext">
358
								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', '> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
359
								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1024) / 1024), 0)) : '', '</label>
360
							</dd>';
361
362
		echo '
363
						</dl>';
364
365
		if (!empty($context['files_in_session_warning']))
366
			echo '
367
						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
368
	}
369
370
	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
371
	if ($context['can_post_attachment'])
372
	{
373
		// Print dropzone UI.
374
		echo '
375
						<div class="files" id="au-previews">
376
							<div id="au-template">
377
								<div class="attach-preview">
378
									<img data-dz-thumbnail />
379
								</div>
380
								<div class="attach-info">
381
									<div>
382
										<span class="name" data-dz-name></span>
383
										<span class="error" data-dz-errormessage></span>
384
										<span class="size" data-dz-size></span>
385
										<span class="message" data-dz-message></span>
386
									</div>
387
									<div class="attached_BBC">
388
										<input type="text" name="attachBBC" value="" readonly>
389
										<div class="attached_BBC_width_height">
390
											<div class="attached_BBC_width">
391
												<label for="attached_BBC_width">', $txt['attached_insertwidth'], '</label>
392
												<input type="number" name="attached_BBC_width" min="0" value="" placeholder="auto">
393
											</div>
394
											<div class="attached_BBC_height">
395
												<label for="attached_BBC_height">', $txt['attached_insertheight'], '</label>
396
												<input type="number" name="attached_BBC_height" min="0" value="" placeholder="auto">
397
											</div>
398
										</div>
399
									</div><!-- .attached_BBC -->
400
									<div class="progress_bar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
401
										<div class="bar"></div>
402
									</div>
403
									<div class="attach-ui">
404
										<a data-dz-remove class="button cancel">', $txt['modify_cancel'] ,'</a>
405
										<a class="button upload">', $txt['upload'] ,'</a>
406
									</div>
407
								</div><!-- .attach-info -->
408
							</div><!-- #au-template -->
409
						</div><!-- #au-previews -->
410
						<div id ="maxFiles_progress" class="maxFiles_progress progress_bar">
411
							<div class="bar"></div>
412
						</div>
413
						<div id ="maxFiles_progress_text"></div>';
414
415
		echo '
416
						<dl id="postAttachment2">
417
							<dt>
418
								', $txt['attach'], ':
419
							</dt>
420
							<dd class="smalltext fallback">
421
								<div id="attachUpload" class="descbox">
422
									<h5>', $txt['attach_drop_zone'] ,'</h5>
423
									<a class="button" id="attach-cancelAll">', $txt['attached_cancelAll'] ,'</a>
424
									<a class="button" id="attach-uploadAll">', $txt['attached_uploadAll'] ,'</a>
425
									<a class="button fileinput-button">', $txt['attach_add'] ,'</a>
426
									<div id="total-progress" class="progress_bar" role="progressBar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
427
										<div class="bar"></div>
428
									</div>
429
									<div class="fallback">
430
										<input type="file" multiple="multiple" name="attachment[]" id="attachment1" class="fallback"> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
431
432
		if (!empty($modSettings['attachmentSizeLimit']))
433
			echo '
434
										<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1024 . '">';
435
436
		// Show more boxes if they aren't approaching that limit.
437
		if ($context['num_allowed_attachments'] > 1)
438
			echo '
439
										<script>
440
											var allowed_attachments = ', $context['num_allowed_attachments'], ';
441
											var current_attachment = 1;
442
443
											function addAttachment()
444
											{
445
												allowed_attachments = allowed_attachments - 1;
446
												current_attachment = current_attachment + 1;
447
												if (allowed_attachments <= 0)
448
													return alert("', $txt['more_attachments_error'], '");
449
450
												setOuterHTML(document.getElementById("moreAttachments"), \'<dd class="smalltext"><input type="file" name="attachment[]" id="attachment\' + current_attachment + \'"> (<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>\');
451
452
												return true;
453
											}
454
										</script>
455
										<a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')</a>
456
									</div><!-- .fallback -->
457
								</div><!-- #attachUpload -->';
458
459
		echo '
460
							</dd>';
461
462
		// Add any template changes for an alternative upload system here.
463
		call_integration_hook('integrate_upload_template');
464
465
		echo '
466
							<dd class="smalltext">';
467
468
		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
469
		if (!empty($modSettings['attachmentCheckExtensions']))
470
			echo '
471
								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
472
473
		if (!empty($context['attachment_restrictions']))
474
			echo '
475
								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
476
477
		if ($context['num_allowed_attachments'] == 0)
478
			echo '
479
								', $txt['attach_limit_nag'], '<br>';
480
481
		if (!$context['can_post_attachment_unapproved'])
482
			echo '
483
								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
484
485
		echo '
486
							</dd>
487
						</dl>';
488
	}
489
490
	echo '
491
					</div><!-- #postAdditionalOptions -->';
492
493
	// If the admin enabled the drafts feature, show a draft selection box
494
	if (!empty($modSettings['drafts_post_enabled']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']))
495
	{
496
		echo '
497
					<div id="postDraftOptionsHeader" class="title_bar">
498
						<h4 class="titlebg">
499
							<span id="postDraftExpand" class="toggle_up floatright" style="display: none;"></span> <strong><a href="#" id="postDraftExpandLink">', $txt['drafts_show'], '</a></strong>
500
						</h4>
501
					</div>
502
					<div id="postDraftOptions">
503
						<dl class="settings">
504
							<dt><strong>', $txt['subject'], '</strong></dt>
505
							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
506
507
		foreach ($context['drafts'] as $draft)
508
			echo '
509
							<dt>', $draft['link'], '</dt>
510
							<dd>', $draft['poster_time'], '</dd>';
511
		echo '
512
						</dl>
513
					</div>';
514
	}
515
516
	// Is visual verification enabled?
517
	if ($context['require_verification'])
518
		echo '
519
					<div class="post_verification">
520
						<span', !empty($context['post_error']['need_qr_verification']) ? ' class="error"' : '', '>
521
							<strong>', $txt['verification'], ':</strong>
522
						</span>
523
						', template_control_verification($context['visual_verification_id'], 'all'), '
524
					</div>';
525
526
	// Finally, the submit buttons.
527
	echo '
528
					<br class="clear_right">
529
					<span id="post_confirm_buttons" class="floatright">
530
						', template_control_richedit_buttons($context['post_box_name']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_control_richedi...ntext['post_box_name']) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
531
532
	// Option to delete an event if user is editing one.
533
	if ($context['make_event'] && !$context['event']['new'])
534
		echo '
535
						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button you_sure">';
536
537
	echo '
538
					</span>
539
				</div><!-- .roundframe -->
540
			</div><!-- #post_area -->
541
			<br class="clear">';
542
543
	// Assuming this isn't a new topic pass across the last message id.
544
	if (isset($context['topic_last_message']))
545
		echo '
546
			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
547
548
	echo '
549
			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
550
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
551
			<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
552
		</form>';
553
554
	echo '
555
		<script>';
556
557
	$newPostsHTML = '
558
		<span id="new_replies"></span>
559
		<div class="windowbg">
560
			<div id="msg%PostID%">
561
			<h5 class="floatleft">
562
				<span>' . $txt['posted_by'] . '</span>
563
				%PosterName%
564
			</h5>
565
			&nbsp;-&nbsp;%PostTime%&nbsp;&#187; <span class="new_posts" id="image_new_%PostID%">' . $txt['new'] . '</span>';
566
567
	if ($context['can_quote'])
568
		$newPostsHTML .= '
569
			<ul class="quickbuttons sf-js-enabled sf-arrows" id="msg_%PostID%_quote" style="touch-action: pan-y;">
570
				<li id="post_modify">
571
					<a href="#postmodify" onclick="return insertQuoteFast(%PostID%);" class="quote_button"><span class="generic_icons quote"></span>' . $txt['quote'] . '</a>
572
				</li>
573
			</ul>';
574
575
	$newPostsHTML .= '
576
			<br class="clear">
577
			<div id="msg_%PostID%_ignored_prompt" class="smalltext" style="display: none;">' . $txt['ignoring_user'] .  '<a href="#" id="msg_%PostID%_ignored_link" style="%IgnoredStyle%">' . $txt['show_ignore_user_post'] . '</a></div>
578
			<div class="list_posts smalltext" id="msg_%PostID%_body">%PostBody%</div>
579
		</div>';
580
581
	// The functions used to preview a posts without loading a new page.
582
	echo '
583
			var oPreviewPost = new smc_preview_post({
584
				sPreviewSectionContainerID: "preview_section",
585
				sPreviewSubjectContainerID: "preview_subject",
586
				sPreviewBodyContainerID: "preview_body",
587
				sErrorsContainerID: "errors",
588
				sErrorsSeriousContainerID: "error_serious",
589
				sErrorsListContainerID: "error_list",
590
				sCaptionContainerID: "caption_%ID%",
591
				sNewImageContainerID: "image_new_%ID%",
592
				sPostBoxContainerID: ', JavaScriptEscape($context['post_box_name']), ',
593
				bMakePoll: ', $context['make_poll'] ? 'true' : 'false', ',
594
				sTxtPreviewTitle: ', JavaScriptEscape($txt['preview_title']), ',
595
				sTxtPreviewFetch: ', JavaScriptEscape($txt['preview_fetch']), ',
596
				sSessionVar: ', JavaScriptEscape($context['session_var']), ',
597
				newPostsTemplate:', JavaScriptEscape($newPostsHTML);
598
599
	if (!empty($context['current_board']))
600
		echo ',
601
				iCurrentBoard: ', $context['current_board'], '';
602
603
	echo '
604
			});';
605
606
	// Code for showing and hiding additional options.
607
	if (!empty($modSettings['additional_options_collapsable']))
608
		echo '
609
			var oSwapAdditionalOptions = new smc_Toggle({
610
				bToggleEnabled: true,
611
				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
612
				funcOnBeforeCollapse: function () {
613
					document.getElementById(\'additional_options\').value = \'0\';
614
				},
615
				funcOnBeforeExpand: function () {
616
					document.getElementById(\'additional_options\').value = \'1\';
617
				},
618
				aSwappableContainers: [
619
					\'postAdditionalOptions\',
620
				],
621
				aSwapImages: [
622
					{
623
						sId: \'postMoreExpandLink\',
624
						altExpanded: \'-\',
625
						altCollapsed: \'+\'
626
					}
627
				],
628
				aSwapLinks: [
629
					{
630
						sId: \'postMoreExpandLink\',
631
						msgExpanded: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), ',
632
						msgCollapsed: ', JavaScriptEscape($context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt']), '
633
					}
634
				]
635
			});';
636
637
	// Code for showing and hiding drafts
638
	if (!empty($context['drafts']))
639
		echo '
640
			var oSwapDraftOptions = new smc_Toggle({
641
				bToggleEnabled: true,
642
				bCurrentlyCollapsed: true,
643
				aSwappableContainers: [
644
					\'postDraftOptions\',
645
				],
646
				aSwapImages: [
647
					{
648
						sId: \'postDraftExpand\',
649
						altExpanded: \'-\',
650
						altCollapsed: \'+\'
651
					}
652
				],
653
				aSwapLinks: [
654
					{
655
						sId: \'postDraftExpandLink\',
656
						msgExpanded: ', JavaScriptEscape($txt['draft_hide']), ',
657
						msgCollapsed: ', JavaScriptEscape($txt['drafts_show']), '
658
					}
659
				]
660
			});';
661
662
	echo '
663
			var oEditorID = "', $context['post_box_name'] ,'";
664
			var oEditorObject = oEditorHandle_', $context['post_box_name'], ';
665
		</script>';
666
667
	// If the user is replying to a topic show the previous posts.
668
	if (isset($context['previous_posts']) && count($context['previous_posts']) > 0)
669
	{
670
		echo '
671
		<div id="recent" class="flow_hidden main_section">
672
			<div class="cat_bar">
673
				<h3 class="catbg">', $txt['topic_summary'], '</h3>
674
			</div>
675
			<span id="new_replies"></span>';
676
677
		$ignored_posts = array();
678
		foreach ($context['previous_posts'] as $post)
679
		{
680
			$ignoring = false;
681
			if (!empty($post['is_ignored']))
682
				$ignored_posts[] = $ignoring = $post['id'];
683
684
			echo '
685
			<div class="windowbg">
686
				<div id="msg', $post['id'], '">
687
					<h5 class="floatleft">
688
						<span>', $txt['posted_by'], '</span> ', $post['poster'], '
689
					</h5>
690
					&nbsp;-&nbsp;', $post['time'];
691
692
			if ($context['can_quote'])
693
				echo '
694
					<ul class="quickbuttons" id="msg_', $post['id'], '_quote">
695
						<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>
696
						<li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');"><span class="generic_icons quote"></span>', $txt['quote'], '</a></li>
697
					</ul>';
698
699
			echo '
700
					<br class="clear">';
701
702
			if ($ignoring)
703
				echo '
704
					<div id="msg_', $post['id'], '_ignored_prompt" class="smalltext">
705
						', $txt['ignoring_user'], '
706
						<a href="#" id="msg_', $post['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
707
					</div>';
708
709
			echo '
710
					<div class="list_posts smalltext" id="msg_', $post['id'], '_body" data-msgid="', $post['id'], '">', $post['message'], '</div>
711
				</div><!-- #msg[id] -->
712
			</div><!-- .windowbg -->';
713
		}
714
715
		echo '
716
		</div><!-- #recent -->
717
		<script>
718
			var aIgnoreToggles = new Array();';
719
720
		foreach ($ignored_posts as $post_id)
721
		{
722
			echo '
723
			aIgnoreToggles[', $post_id, '] = new smc_Toggle({
724
				bToggleEnabled: true,
725
				bCurrentlyCollapsed: true,
726
				aSwappableContainers: [
727
					\'msg_', $post_id, '_body\',
728
					\'msg_', $post_id, '_quote\',
729
				],
730
				aSwapLinks: [
731
					{
732
						sId: \'msg_', $post_id, '_ignored_link\',
733
						msgExpanded: \'\',
734
						msgCollapsed: ', JavaScriptEscape($txt['show_ignore_user_post']), '
735
					}
736
				]
737
			});';
738
		}
739
740
		echo '
741
			function insertQuoteFast(messageid)
742
			{
743
				if (window.XMLHttpRequest)
744
					getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';xml;pb=', $context['post_box_name'], ';mode=0\', onDocReceived);
745
				else
746
					reqWin(smf_prepareScriptUrl(smf_scripturl) + \'action=quotefast;quote=\' + messageid + \';pb=', $context['post_box_name'], ';mode=0\', 240, 90);
747
748
				return true;
749
			}
750
			function onDocReceived(XMLDoc)
751
			{
752
				var text = \'\';
753
				var e = $("#', $context['post_box_name'], '").get(0);
754
755
				for (var i = 0, n = XMLDoc.getElementsByTagName(\'quote\')[0].childNodes.length; i < n; i++)
756
					text += XMLDoc.getElementsByTagName(\'quote\')[0].childNodes[i].nodeValue;
757
				sceditor.instance(e).InsertText(text);
758
			}
759
			function onReceiveOpener(text)
760
			{
761
				sceditor.instance(e).InsertText(text);
762
			}
763
		</script>';
764
	}
765
}
766
767
/**
768
 * The template for the spellchecker.
769
 */
770
function template_spellcheck()
771
{
772
	global $context, $settings, $txt, $modSettings;
773
774
	// The style information that makes the spellchecker look... like the forum hopefully!
775
	echo '<!DOCTYPE html>
776
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
777
	<head>
778
		<meta charset="', $context['character_set'], '">
779
		<title>', $txt['spell_check'], '</title>
780
		<link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'] ,'">
781
		<style>
782
			body, td {
783
				font-size: small;
784
				margin: 0;
785
				background: #f0f0f0;
786
				color: #000;
787
				padding: 10px;
788
			}
789
			.highlight {
790
				color: red;
791
				font-weight: bold;
792
			}
793
			#spellview {
794
				border-style: outset;
795
				border: 1px solid black;
796
				padding: 5px;
797
				width: 95%;
798
				height: 314px;
799
				overflow: auto;
800
				background: #ffffff;
801
			}';
802
803
	// As you may expect - we need a lot of javascript for this... load it from the separate files.
804
	echo '
805
		</style>
806
		<script>
807
			var spell_formname = window.opener.spell_formname;
808
			var spell_fieldname = window.opener.spell_fieldname;
809
		</script>
810
		<script src="', $settings['default_theme_url'], '/scripts/spellcheck.js', $modSettings['browser_cache'] ,'"></script>
811
		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script>
812
		<script>
813
			', $context['spell_js'], '
814
		</script>
815
	</head>
816
	<body onload="nextWord(false);">
817
		<form action="#" method="post" accept-charset="', $context['character_set'], '" name="spellingForm" id="spellingForm" onsubmit="return false;">
818
			<div id="spellview">&nbsp;</div>
819
			<table width="100%">
820
				<tr class="windowbg">
821
					<td style="width: 50%; vertical-align: top">
822
						', $txt['spellcheck_change_to'], '<br>
823
						<input type="text" name="changeto" style="width: 98%;">
824
					</td>
825
					<td style="width: 50%">
826
						', $txt['spellcheck_suggest'], '<br>
827
						<select name="suggestions" style="width: 98%;" size="5" onclick="if (this.selectedIndex != -1) this.form.changeto.value = this.options[this.selectedIndex].text;" ondblclick="replaceWord();">
828
						</select>
829
					</td>
830
				</tr>
831
			</table>
832
			<div class="righttext" style="padding: 4px;">
833
				<input type="button" name="change" value="', $txt['spellcheck_change'], '" onclick="replaceWord();" class="button">
834
				<input type="button" name="changeall" value="', $txt['spellcheck_change_all'], '" onclick="replaceAll();" class="button">
835
				<input type="button" name="ignore" value="', $txt['spellcheck_ignore'], '" onclick="nextWord(false);" class="button">
836
				<input type="button" name="ignoreall" value="', $txt['spellcheck_ignore_all'], '" onclick="nextWord(true);" class="button">
837
			</div>
838
		</form>
839
	</body>
840
</html>';
841
}
842
843
/**
844
 * The template for the AJAX quote feature
845
 */
846
function template_quotefast()
847
{
848
	global $context, $settings, $txt, $modSettings;
849
850
	echo '<!DOCTYPE html>
851
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
852
	<head>
853
		<meta charset="', $context['character_set'], '">
854
		<title>', $txt['retrieving_quote'], '</title>
855
		<script src="', $settings['default_theme_url'], '/scripts/script.js', $modSettings['browser_cache'] ,'"></script>
856
	</head>
857
	<body>
858
		', $txt['retrieving_quote'], '
859
		<div id="temporary_posting_area" style="display: none;"></div>
860
		<script>';
861
862
	if ($context['close_window'])
863
		echo '
864
			window.close();';
865
	else
866
	{
867
		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;)
868
		echo '
869
			var quote = \'', $context['quote']['text'], '\';
870
			var stage = \'createElement\' in document ? document.createElement("DIV") : document.getElementById("temporary_posting_area");
871
872
			if (\'DOMParser\' in window && !(\'opera\' in window))
873
			{
874
				var xmldoc = new DOMParser().parseFromString("<temp>" + \'', $context['quote']['mozilla'], '\'.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_") + "</temp>", "text/xml");
875
				quote = xmldoc.childNodes[0].textContent.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
876
			}
877
			else if (\'innerText\' in stage)
878
			{
879
				setInnerHTML(stage, quote.replace(/\n/g, "_SMF-BREAK_").replace(/\t/g, "_SMF-TAB_").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
880
				quote = stage.innerText.replace(/_SMF-BREAK_/g, "\n").replace(/_SMF-TAB_/g, "\t");
881
			}
882
883
			if (\'opera\' in window)
884
				quote = quote.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, \'"\').replace(/&amp;/g, "&");
885
886
			window.opener.onReceiveOpener(quote);
887
888
			window.focus();
889
			setTimeout("window.close();", 400);';
890
	}
891
	echo '
892
		</script>
893
	</body>
894
</html>';
895
}
896
897
/**
898
 * The form for sending out an announcement
899
 */
900
function template_announce()
901
{
902
	global $context, $txt, $scripturl;
903
904
	echo '
905
	<div id="announcement">
906
		<form action="', $scripturl, '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '">
907
			<div class="cat_bar">
908
				<h3 class="catbg">', $txt['announce_title'], '</h3>
909
			</div>
910
			<div class="information">
911
				', $txt['announce_desc'], '
912
			</div>
913
			<div class="windowbg">
914
				<p>
915
					', $txt['announce_this_topic'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0">', $context['topic_subject'], '</a>
916
				</p>
917
				<ul>';
918
919
	foreach ($context['groups'] as $group)
920
		echo '
921
					<li>
922
						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
923
					</li>';
924
925
	echo '
926
					<li>
927
						<label for="checkall"><input type="checkbox" id="checkall" onclick="invertAll(this, this.form);" checked> <em>', $txt['check_all'], '</em></label>
928
					</li>
929
				</ul>
930
				<hr>
931
				<div id="confirm_buttons">
932
					<input type="submit" value="', $txt['post'], '" class="button">
933
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
934
					<input type="hidden" name="topic" value="', $context['current_topic'], '">
935
					<input type="hidden" name="move" value="', $context['move'], '">
936
					<input type="hidden" name="goback" value="', $context['go_back'], '">
937
				</div>
938
				<br class="clear_right">
939
			</div><!-- .windowbg -->
940
		</form>
941
	</div><!-- #announcement -->
942
	<br>';
943
}
944
945
/**
946
 * The confirmation/progress page, displayed after the admin has clicked the button to send the announcement.
947
 */
948
function template_announcement_send()
949
{
950
	global $context, $txt, $scripturl;
951
952
	echo '
953
	<div id="announcement">
954
		<form action="', $scripturl, '?action=announce;sa=send" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit">
955
			<div class="windowbg">
956
				<p>
957
					', $txt['announce_sending'], ' <a href="', $scripturl, '?topic=', $context['current_topic'], '.0" target="_blank" rel="noopener">', $context['topic_subject'], '</a>
958
				</p>
959
				<div class="progress_bar">
960
					<span>', $context['percentage_done'], '% ', $txt['announce_done'], '</span>
961
					<div class="bar" style="width: ', $context['percentage_done'], '%;"></div>
962
				</div>
963
				<hr>
964
				<div id="confirm_buttons">
965
					<input type="submit" name="b" value="', $txt['announce_continue'], '" class="button">
966
					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
967
					<input type="hidden" name="topic" value="', $context['current_topic'], '">
968
					<input type="hidden" name="move" value="', $context['move'], '">
969
					<input type="hidden" name="goback" value="', $context['go_back'], '">
970
					<input type="hidden" name="start" value="', $context['start'], '">
971
					<input type="hidden" name="membergroups" value="', $context['membergroups'], '">
972
				</div>
973
				<br class="clear_right">
974
			</div><!-- .windowbg -->
975
		</form>
976
	</div><!-- #announcement -->
977
	<br>
978
	<script>
979
		var countdown = 2;
980
		doAutoSubmit();
981
982
		function doAutoSubmit()
983
		{
984
			if (countdown == 0)
985
				document.forms.autoSubmit.submit();
986
			else if (countdown == -1)
987
				return;
988
989
			document.forms.autoSubmit.b.value = "', $txt['announce_continue'], ' (" + countdown + ")";
990
			countdown--;
991
992
			setTimeout("doAutoSubmit();", 1000);
993
		}
994
	</script>';
995
}
996
997
/**
998
 * Prints the input fields in the form's header (subject, message icon, guest name & email, etc.)
999
 *
1000
 * Mod authors can use the 'integrate_post_end' hook to modify or add to these (see Post.php).
1001
 *
1002
 * Theme authors can customize the output in a couple different ways:
1003
 * 1. Change specific values in the $context['posting_fields'] array.
1004
 * 2. Add an 'html' element to the 'label' and/or 'input' elements of the field they want to
1005
 *    change. This should contain the literal HTML string to be printed.
1006
 */
1007
function template_post_header()
1008
{
1009
	global $context, $txt;
1010
1011
	// Sanity check: submitting the form won't work without at least a subject field
1012
	if (empty($context['posting_fields']['subject']) || !is_array($context['posting_fields']['subject']))
1013
	{
1014
		$context['posting_fields']['subject'] = array(
1015
				'label' => array('html' => '<label for="subject" id="caption_subject">' . $txt['subject'] . '</label>'),
1016
				'input' => array('html' => '<input type="text" name="subject" value="' . $context['subject'] . '" size="80" maxlength="80" required>')
1017
			);
1018
	}
1019
1020
1021
	// THEME AUTHORS: Above this line is a great place to make customizations to the posting_fields array
1022
1023
	// Start printing the header
1024
	echo '
1025
					<dl id="post_header">';
1026
1027
	foreach ($context['posting_fields'] as $pfid => $pf)
1028
	{
1029
		// We need both a label and an input
1030
		if (empty($pf['label']) || empty($pf['input']))
1031
			continue;
1032
1033
		// The labels are pretty simple...
1034
		echo '
1035
						<dt class="clear pf_', $pfid, '">';
1036
1037
		// Any leading HTML before the label
1038
		if (!empty($pf['label']['before']))
1039
			echo '
1040
							', $pf['label']['before'];
1041
1042
		if (!empty($pf['label']['html']))
1043
			echo $pf['label']['html'];
1044
		else
1045
			echo '
1046
							<label for="', !empty($pf['input']['attributes']['name']) ? $pf['input']['attributes']['name'] : $pfid, '" id="caption_', $pfid, '"', !empty($pf['label']['class']) ? ' class="' . $pf['label']['class'] . '"' : '', '>', $pf['label']['text'], '</label>';
1047
1048
		// Any trailing HTML after the label
1049
		if (!empty($pf['label']['after']))
1050
			echo '
1051
							', $pf['label']['after'];
1052
1053
		echo '
1054
						</dt>';
1055
1056
		// Here's where the fun begins...
1057
		echo '
1058
						<dd class="pf_', $pfid, '">';
1059
1060
		// Any leading HTML before the main input
1061
		if (!empty($pf['input']['before']))
1062
			echo '
1063
							', $pf['input']['before'];
1064
1065
		// If there is a literal HTML string already defined, just print it.
1066
		if (!empty($pf['input']['html']))
1067
		{
1068
			echo $pf['input']['html'];
1069
		}
1070
		// Simple text inputs and checkboxes
1071
		elseif (in_array($pf['input']['type'], array('text', 'password', 'color', 'date', 'datetime-local', 'email', 'month', 'number', 'range', 'tel', 'time', 'url', 'week', 'checkbox')))
1072
		{
1073
			echo '
1074
							<input type="', $pf['input']['type'], '"';
1075
1076
			if (empty($pf['input']['attributes']['name']))
1077
				echo ' name="', $pfid, '"';
1078
1079
			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1080
			{
1081
				foreach ($pf['input']['attributes'] as $attribute => $value)
1082
				{
1083
					if (is_bool($value))
1084
						echo $value ? ' ' . $attribute : '';
1085
					else
1086
						echo ' ', $attribute, '="', $value, '"';
1087
				}
1088
			}
1089
1090
			echo ' tabindex="', $context['tabindex']++, '">';
1091
		}
1092
		// textarea
1093
		elseif ($pf['input']['type'] === 'textarea')
1094
		{
1095
			echo '
1096
							<textarea';
1097
1098
			if (empty($pf['input']['attributes']['name']))
1099
				echo ' name="', $pfid, '"';
1100
1101
			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1102
			{
1103
				foreach ($pf['input']['attributes'] as $attribute => $value)
1104
				{
1105
					if ($attribute === 'value')
1106
						continue;
1107
					elseif (is_bool($value))
1108
						echo $value ? ' ' . $attribute : '';
1109
					else
1110
						echo ' ', $attribute, '="', $value, '"';
1111
				}
1112
			}
1113
1114
			echo ' tabindex="', $context['tabindex']++, '">', !empty($pf['input']['attributes']['value']) ? $pf['input']['attributes']['value'] : '', '</textarea>';
1115
		}
1116
		// Select menus are more complicated
1117
		elseif ($pf['input']['type'] === 'select' && is_array($pf['input']['options']))
1118
		{
1119
			// The select element itself
1120
			echo '
1121
							<select';
1122
1123
			if (empty($pf['input']['attributes']['name']))
1124
				echo ' name="', $pfid, '"';
1125
1126
			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1127
			{
1128
				foreach ($pf['input']['attributes'] as $attribute => $value)
1129
				{
1130
					if (is_bool($value))
1131
						echo $value ? ' ' . $attribute : '';
1132
					else
1133
						echo ' ', $attribute, '="', $value, '"';
1134
				}
1135
			}
1136
1137
			echo ' tabindex="', $context['tabindex']++, '">';
1138
1139
			// The options
1140
			foreach ($pf['input']['options'] as $optlabel => $option)
1141
			{
1142
				// An option containing options is an optgroup
1143
				if (!empty($option['options']) && is_array($option['options']))
1144
				{
1145
					echo '
1146
								<optgroup';
1147
1148
					if (empty($option['attributes']['label']))
1149
						echo ' label="', $optlabel, '"';
1150
1151
					if (!empty($option['attributes']) && is_array($option['attributes']))
1152
					{
1153
						foreach ($option['attributes'] as $attribute => $value)
1154
						{
1155
							if (is_bool($value))
1156
								echo $value ? ' ' . $attribute : '';
1157
							else
1158
								echo ' ', $attribute, '="', $value, '"';
1159
						}
1160
					}
1161
1162
					echo '">';
1163
1164
					foreach ($option['options'] as $grouped_optlabel => $grouped_option)
1165
					{
1166
						echo '
1167
									<option';
1168
1169
						foreach ($grouped_option['attributes'] as $attribute => $value)
1170
						{
1171
							if (is_bool($value))
1172
								echo $value ? ' ' . $attribute : '';
1173
							else
1174
								echo ' ', $attribute, '="', $value, '"';
1175
						}
1176
1177
						echo '>', $grouped_optlabel, '</option>';
1178
1179
					}
1180
1181
					echo '
1182
								</optgroup>';
1183
				}
1184
				// Simple option
1185
				else
1186
				{
1187
					echo '
1188
								<option';
1189
1190
					foreach ($option['attributes'] as $attribute => $value)
1191
					{
1192
						if (is_bool($value))
1193
							echo $value ? ' ' . $attribute : '';
1194
						else
1195
							echo ' ', $attribute, '="', $value, '"';
1196
					}
1197
1198
					echo '>', $optlabel, '</option>';
1199
				}
1200
			}
1201
1202
			// Close the select element
1203
			echo '
1204
							</select>';
1205
		}
1206
		// Radio_select makes a div with some radio buttons in it
1207
		elseif ($pf['input']['type'] === 'radio_select' && is_array($pf['input']['options']))
1208
		{
1209
			echo '
1210
							<div';
1211
1212
			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1213
			{
1214
				foreach ($pf['input']['attributes'] as $attribute => $value)
1215
				{
1216
					if ($attribute === 'name')
1217
						continue;
1218
					elseif (is_bool($value))
1219
						echo $value ? ' ' . $attribute : '';
1220
					else
1221
						echo ' ', $attribute, '="', $value, '"';
1222
				}
1223
			}
1224
1225
			echo '>';
1226
1227
			foreach ($pf['input']['options'] as $optlabel => $option)
1228
			{
1229
				echo '
1230
							<input type="radio" name="', !empty($pf['input']['attributes']['name']) ? $pf['input']['attributes']['name'] : $pfid, '"';
1231
1232
				foreach ($option['attributes'] as $attribute => $value)
1233
				{
1234
					if (is_bool($value))
1235
						echo $value ? ' ' . $attribute : '';
1236
					else
1237
						echo ' ', $attribute, '="', $value, '"';
1238
				}
1239
1240
				echo ' tabindex="', $context['tabindex']++, '">', $optlabel, '</input>';
1241
			}
1242
1243
			echo '
1244
							</div>';
1245
		}
1246
1247
		// Any trailing HTML after the main input
1248
		if (!empty($pf['input']['after']))
1249
			echo '
1250
							', $pf['input']['after'];
1251
1252
		echo '
1253
						</dd>';
1254
	}
1255
1256
	echo '
1257
					</dl>';
1258
}
1259
1260
?>