Passed
Push — release-2.1 ( 0009c2...7b18b6 )
by Mathias
08:04 queued 13s
created

template_single_pm()   F

Complexity

Conditions 77
Paths > 20000

Size

Total Lines 327
Code Lines 152

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 77
eloc 152
nop 1
dl 0
loc 327
rs 0
c 1
b 0
f 0
nc 1925480448

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 https://www.simplemachines.org
7
 * @copyright 2020 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 RC2
11
 */
12
13
/**
14
 * This is for stuff above the menu in the personal messages section
15
 */
16
function template_pm_above()
17
{
18
	global $context, $txt;
19
20
	echo '
21
	<div id="personal_messages">';
22
23
	// Show the capacity bar, if available.
24
	if (!empty($context['limit_bar']))
25
		echo '
26
		<div class="cat_bar">
27
			<h3 class="catbg">
28
				<span class="floatleft">', $txt['pm_capacity'], ':</span>
29
				<span class="floatleft capacity_bar">
30
					<span class="', $context['limit_bar']['percent'] > 85 ? 'full' : ($context['limit_bar']['percent'] > 40 ? 'filled' : 'empty'), '" style="width: ', $context['limit_bar']['percent'] / 10, 'em;"></span>
31
				</span>
32
				<span class="floatright', $context['limit_bar']['percent'] > 90 ? ' alert' : '', '">', $context['limit_bar']['text'], '</span>
33
			</h3>
34
		</div>';
35
36
	// Message sent? Show a small indication.
37
	if (isset($context['pm_sent']))
38
		echo '
39
		<div class="infobox">
40
			', $txt['pm_sent'], '
41
		</div>';
42
}
43
44
/**
45
 * Just the end of the index bar, nothing special.
46
 */
47
function template_pm_below()
48
{
49
	echo '
50
	</div><!-- #personal_messages -->';
51
}
52
53
function template_pm_popup()
54
{
55
	global $context, $txt, $scripturl;
56
57
	// Unlike almost every other template, this is designed to be included into the HTML directly via $().load()
58
	echo '
59
		<div class="pm_bar">
60
			<div class="pm_sending block">
61
				', $context['can_send_pm'] ? '<a href="' . $scripturl . '?action=pm;sa=send">' . $txt['pm_new_short'] . '</a> | ' : '', '
62
				', $context['can_draft'] ? '<a href="' . $scripturl . '?action=pm;sa=showpmdrafts">' . $txt['pm_drafts_short'] . '</a>' : '', '
63
				<a href="', $scripturl, '?action=pm;sa=settings" class="floatright">', $txt['pm_settings_short'], '</a>
64
			</div>
65
			<div class="pm_mailbox centertext">
66
				<a href="', $scripturl, '?action=pm" class="button">', $txt['inbox'], '</a>
67
			</div>
68
		</div>
69
		<div class="pm_unread">';
70
71
	if (empty($context['unread_pms']))
72
		echo '
73
			<div class="no_unread">', $txt['pm_no_unread'], '</div>';
74
	else
75
	{
76
		foreach ($context['unread_pms'] as $id_pm => $pm_details)
77
			echo '
78
			<div class="unread_notify">
79
				<div class="unread_notify_image">
80
					', !empty($pm_details['member']) ? $pm_details['member']['avatar']['image'] : '', '
81
				</div>
82
				<div class="details">
83
					<div class="subject">', $pm_details['pm_link'], '</div>
84
					<div class="sender">
85
						', $pm_details['replied_to_you'] ? '<span class="main_icons replied centericon" style="margin-right: 4px" title="' . $txt['pm_you_were_replied_to'] . '"></span>' : '<span class="main_icons im_off centericon" style="margin-right: 4px" title="' . $txt['pm_was_sent_to_you'] . '"></span>',
86
						!empty($pm_details['member']) ? $pm_details['member']['link'] : $pm_details['member_from'], ' - ', $pm_details['time'], '
87
					</div>
88
				</div>
89
			</div>';
90
	}
91
92
	echo '
93
		</div><!-- #pm_unread -->';
94
}
95
96
/**
97
 * Shows a particular folder (eg inbox or outbox), all the PMs in it, etc.
98
 */
99
function template_folder()
100
{
101
	global $context, $scripturl, $txt;
102
103
	// The every helpful javascript!
104
	echo '
105
		<script>
106
			var allLabels = {};
107
			var currentLabels = {};
108
			function loadLabelChoices()
109
			{
110
				var listing = document.forms.pmFolder.elements;
111
				var theSelect = document.forms.pmFolder.pm_action;
112
				var add, remove, toAdd = {length: 0}, toRemove = {length: 0};
113
114
				if (theSelect.childNodes.length == 0)
115
					return;
116
117
				// This is done this way for internationalization reasons.
118
				if (!(\'-1\' in allLabels))
119
				{
120
					for (var o = 0; o < theSelect.options.length; o++)
121
						if (theSelect.options[o].value.substr(0, 4) == "rem_")
122
							allLabels[theSelect.options[o].value.substr(4)] = theSelect.options[o].text;
123
				}
124
125
				for (var i = 0; i < listing.length; i++)
126
				{
127
					if (listing[i].name != "pms[]" || !listing[i].checked)
128
						continue;
129
130
					var alreadyThere = [], x;
131
					for (x in currentLabels[listing[i].value])
132
					{
133
						if (!(x in toRemove))
134
						{
135
							toRemove[x] = allLabels[x];
136
							toRemove.length++;
137
						}
138
						alreadyThere[x] = allLabels[x];
139
					}
140
141
					for (x in allLabels)
142
					{
143
						if (!(x in alreadyThere))
144
						{
145
							toAdd[x] = allLabels[x];
146
							toAdd.length++;
147
						}
148
					}
149
				}
150
151
				while (theSelect.options.length > 2)
152
					theSelect.options[2] = null;
153
154
				if (toAdd.length != 0)
155
				{
156
					theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_apply'], '", "");
157
					setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_apply'], '");
158
					theSelect.options[theSelect.options.length - 1].disabled = true;
159
160
					for (i in toAdd)
161
					{
162
						if (i != "length")
163
							theSelect.options[theSelect.options.length] = new Option(toAdd[i], "add_" + i);
164
					}
165
				}
166
167
				if (toRemove.length != 0)
168
				{
169
					theSelect.options[theSelect.options.length] = new Option("', $txt['pm_msg_label_remove'], '", "");
170
					setInnerHTML(theSelect.options[theSelect.options.length - 1], "', $txt['pm_msg_label_remove'], '");
171
					theSelect.options[theSelect.options.length - 1].disabled = true;
172
173
					for (i in toRemove)
174
					{
175
						if (i != "length")
176
							theSelect.options[theSelect.options.length] = new Option(toRemove[i], "rem_" + i);
177
					}
178
				}
179
			}
180
		</script>';
181
182
	echo '
183
		<form class="flow_hidden" action="', $scripturl, '?action=pm;sa=pmactions;', $context['display_mode'] == 2 ? 'conversation;' : '', 'f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '" method="post" accept-charset="', $context['character_set'], '" name="pmFolder" id="pmFolder">';
184
185
	// If we are not in single display mode show the subjects on the top!
186
	if ($context['display_mode'] != 1)
187
	{
188
		template_subject_list();
189
190
		echo '
191
			<div class="clear_right"><br></div>';
192
	}
193
194
	// Got some messages to display?
195
	if ($context['get_pmessage']('message', true))
196
	{
197
		// Show a few buttons if we are in conversation mode and outputting the first message.
198
		if ($context['display_mode'] == 2)
199
		{
200
			// This bit uses info set in template_subject_list, so it's wrapped
201
			// in an if just in case a mod or custom theme breaks it.
202
			if (!empty($context['current_pm_subject']))
203
			{
204
				echo '
205
			<div class="cat_bar">
206
				<h3 class="catbg">
207
					<span>', $txt['conversation'], '</span>
208
				</h3>
209
			</div>
210
			<div class="roundframe">
211
				<div class="display_title">', $context['current_pm_subject'], '</div>
212
				<p>', $txt['started_by'], ' ', $context['current_pm_author'], ', ', $context['current_pm_time'], '</p>';
213
			}
214
			else
215
			{
216
				echo '
217
			<div class="roundframe">';
218
			}
219
220
			// Show the conversation buttons.
221
			template_button_strip($context['conversation_buttons'], 'right');
222
223
			echo '
224
			</div>';
225
		}
226
227
		while ($message = $context['get_pmessage']('message'))
228
			template_single_pm($message);
229
230
		if (empty($context['display_mode']))
231
			echo '
232
			<div class="pagesection">
233
				<div class="floatleft">', $context['page_index'], '</div>
234
				<div class="floatright">
235
					<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">
236
				</div>
237
			</div>';
238
239
		// Show a few buttons if we are in conversation mode and outputting the first message.
240
		elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons']))
241
		{
242
			echo '
243
			<div class="pagesection">';
244
245
			template_button_strip($context['conversation_buttons'], 'right');
246
247
			echo '
248
			</div>';
249
		}
250
251
		echo '
252
			<br>';
253
	}
254
255
	// Individual messages = buttom list!
256
	if ($context['display_mode'] == 1)
257
	{
258
		template_subject_list();
259
		echo '<br>';
260
	}
261
262
	echo '
263
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
264
		</form>';
265
}
266
267
/**
268
 * Template for displaying a single personal message.
269
 *
270
 * @param array $message An array of information about the message to display.
271
 */
272
function template_single_pm($message)
273
{
274
	global $context, $scripturl, $txt, $settings, $options, $modSettings;
275
276
	echo '
277
	<div class="windowbg">
278
		<div class="post_wrapper">
279
			<div class="poster">';
280
281
	// Are there any custom fields above the member name?
282
	if (!empty($message['custom_fields']['above_member']))
283
	{
284
		echo '
285
				<div class="custom_fields_above_member">
286
					<ul class="nolist">';
287
288
		foreach ($message['custom_fields']['above_member'] as $custom)
289
			echo '
290
						<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
291
292
		echo '
293
					</ul>
294
				</div>';
295
	}
296
297
	echo '
298
				<h4>
299
					<a id="msg', $message['id'], '"></a>';
300
301
	// Show online and offline buttons?
302
	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
303
		echo '
304
					<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>';
305
306
	// Custom fields BEFORE the username?
307
	if (!empty($message['custom_fields']['before_member']))
308
		foreach ($message['custom_fields']['before_member'] as $custom)
309
			echo '
310
					<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
311
312
	// Show a link to the member's profile.
313
	echo '
314
		', $message['member']['link'];
315
316
	// Custom fields AFTER the username?
317
	if (!empty($message['custom_fields']['after_member']))
318
		foreach ($message['custom_fields']['after_member'] as $custom)
319
			echo '
320
					<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
321
322
	echo '
323
				</h4>';
324
325
	echo '
326
				<ul class="user_info">';
327
328
	// Show the user's avatar.
329
	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
330
		echo '
331
					<li class="avatar">
332
						<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">', $message['member']['avatar']['image'], '</a>
333
					</li>';
334
335
	// Are there any custom fields below the avatar?
336
	if (!empty($message['custom_fields']['below_avatar']))
337
		foreach ($message['custom_fields']['below_avatar'] as $custom)
338
			echo '
339
					<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
340
341
	if (!$message['member']['is_guest'])
342
		echo '
343
					<li class="icons">', $message['member']['group_icons'], '</li>';
344
	// Show the member's primary group (like 'Administrator') if they have one.
345
	if (isset($message['member']['group']) && $message['member']['group'] != '')
346
		echo '
347
					<li class="membergroup">', $message['member']['group'], '</li>';
348
349
	// Show the member's custom title, if they have one.
350
	if (isset($message['member']['title']) && $message['member']['title'] != '')
351
		echo '
352
					<li class="title">', $message['member']['title'], '</li>';
353
354
	// Don't show these things for guests.
355
	if (!$message['member']['is_guest'])
356
	{
357
		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
358
		if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
359
			echo '
360
					<li class="postgroup">', $message['member']['post_group'], '</li>';
361
362
		// Show how many posts they have made.
363
		if (!isset($context['disabled_fields']['posts']))
364
			echo '
365
					<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
366
367
		// Show their personal text?
368
		if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '')
369
			echo '
370
					<li class="blurb">', $message['member']['blurb'], '</li>';
371
372
		// Any custom fields to show as icons?
373
		if (!empty($message['custom_fields']['icons']))
374
		{
375
			echo '
376
					<li class="im_icons">
377
						<ol>';
378
379
			foreach ($message['custom_fields']['icons'] as $custom)
380
				echo '
381
							<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
382
383
			echo '
384
						</ol>
385
					</li>';
386
		}
387
388
		// Show the IP to this user for this post - because you can moderate?
389
		if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
390
			echo '
391
					<li class="poster_ip">
392
						<a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a>
393
					</li>';
394
395
		// Or, should we show it because this is you?
396
		elseif ($message['can_see_ip'])
397
			echo '
398
					<li class="poster_ip">
399
						<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a>
400
					</li>';
401
402
		// Okay, you are logged in, then we can show something about why IPs are logged...
403
		else
404
			echo '
405
					<li class="poster_ip">
406
						<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a>
407
					</li>';
408
409
		// Show the profile, website, email address, and personal message buttons.
410
		if ($message['member']['show_profile_buttons'])
411
		{
412
			echo '
413
					<li class="profile">
414
						<ol class="profile_icons">';
415
416
			// Show the profile button
417
			if ($message['member']['can_view_profile'])
418
				echo '
419
							<li><a href="', $message['member']['href'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="' . $txt['view_profile'] . '" title="' . $txt['view_profile'] . '">' : $txt['view_profile']), '</a></li>';
420
421
			// Don't show an icon if they haven't specified a website.
422
			if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website']))
423
				echo '
424
							<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="main_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
425
426
			// Don't show the email address if they want it hidden.
427
			if ($message['member']['show_email'])
428
				echo '
429
							<li><a href="mailto:', $message['member']['email'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="main_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
430
431
			// Since we know this person isn't a guest, you *can* message them.
432
			if ($context['can_send_pm'])
433
				echo '
434
							<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="main_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
435
436
			echo '
437
						</ol>
438
					</li>';
439
		}
440
441
		// Any custom fields for standard placement?
442
		if (!empty($message['custom_fields']['standard']))
443
			foreach ($message['custom_fields']['standard'] as $custom)
444
				echo '
445
					<li class="custom ', $custom['col_name'], '">', $custom['title'], ': ', $custom['value'], '</li>';
446
447
		// Are we showing the warning status?
448
		if ($message['member']['can_see_warning'])
449
			echo '
450
					<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="main_icons warning_', $message['member']['warning_status'], '"></span>', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
451
452
		// Are there any custom fields to show at the bottom of the poster info?
453
		if (!empty($message['custom_fields']['bottom_poster']))
454
			foreach ($message['custom_fields']['bottom_poster'] as $custom)
455
				echo '
456
					<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
457
	}
458
459
	// Done with the information about the poster... on to the post itself.
460
	echo '
461
				</ul>
462
			</div><!-- .poster -->
463
			<div class="postarea">
464
				<div class="flow_hidden">
465
					<div class="keyinfo">
466
						<h5 id="subject_', $message['id'], '">
467
							', $message['subject'], '
468
						</h5>';
469
470
	// Show who the message was sent to.
471
	echo '
472
						<span class="smalltext">&#171; <strong> ', $txt['sent_to'], ':</strong> ';
473
474
	// People it was sent directly to....
475
	if (!empty($message['recipients']['to']))
476
		echo implode(', ', $message['recipients']['to']);
477
478
	// Otherwise, we're just going to say "some people"...
479
	elseif ($context['folder'] != 'sent')
480
		echo '(', $txt['pm_undisclosed_recipients'], ')';
481
482
	echo '
483
							<strong> ', $txt['on'], ':</strong> ', $message['time'], ' &#187;
484
						</span>';
485
486
	// If we're in the sent items, show who it was sent to besides the "To:" people.
487
	if (!empty($message['recipients']['bcc']))
488
		echo '<br>
489
						<span class="smalltext">&#171; <strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' &#187;</span>';
490
491
	if (!empty($message['is_replied_to']))
492
		echo '<br>
493
						<span class="smalltext">&#171; ', $context['folder'] == 'sent' ? $txt['pm_sent_is_replied_to'] : $txt['pm_is_replied_to'], ' &#187;</span>';
494
495
	echo '
496
					</div><!-- .keyinfo -->
497
				</div><!-- .flow_hidden -->
498
				<div class="post">
499
					<div class="inner" id="msg_', $message['id'], '"', '>
500
						', $message['body'], '
501
					</div>
502
				</div><!-- .post -->
503
				<div class="under_message">';
504
505
	// Message options
506
	template_quickbuttons($message['quickbuttons'], 'pm');
507
508
	echo '
509
				</div><!-- .under_message -->
510
			</div><!-- .postarea -->
511
			<div class="moderatorbar">';
512
513
	// Are there any custom profile fields for above the signature?
514
	if (!empty($message['custom_fields']['above_signature']))
515
	{
516
		echo '
517
				<div class="custom_fields_above_signature">
518
					<ul class="nolist">';
519
520
		foreach ($message['custom_fields']['above_signature'] as $custom)
521
			echo '
522
						<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
523
524
		echo '
525
					</ul>
526
				</div>';
527
	}
528
529
	// Show the member's signature?
530
	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
531
		echo '
532
				<div class="signature">
533
					', $message['member']['signature'], '
534
				</div>';
535
536
	// Are there any custom profile fields for below the signature?
537
	if (!empty($message['custom_fields']['below_signature']))
538
	{
539
		echo '
540
				<div class="custom_fields_below_signature">
541
					<ul class="nolist">';
542
543
		foreach ($message['custom_fields']['below_signature'] as $custom)
544
			echo '
545
						<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
546
547
		echo '
548
					</ul>
549
				</div>';
550
	}
551
552
	// Add an extra line at the bottom if we have labels enabled.
553
	if ($context['folder'] != 'sent' && !empty($context['currently_using_labels']) && $context['display_mode'] != 2)
554
	{
555
		echo '
556
				<div class="labels righttext flow_auto">';
557
558
		// Add the label drop down box.
559
		if (!empty($context['currently_using_labels']))
560
		{
561
			echo '
562
					<select name="pm_actions[', $message['id'], ']" onchange="if (this.options[this.selectedIndex].value) form.submit();">
563
						<option value="">', $txt['pm_msg_label_title'], ':</option>
564
						<option value="" disabled>---------------</option>';
565
566
			// Are there any labels which can be added to this?
567
			if (!$message['fully_labeled'])
568
			{
569
				echo '
570
						<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
571
572
				foreach ($context['labels'] as $label)
573
					if (!isset($message['labels'][$label['id']]))
574
						echo '
575
						<option value="', $label['id'], '">', $label['name'], '</option>';
576
			}
577
578
			// ... and are there any that can be removed?
579
			if (!empty($message['labels']) && (count($message['labels']) > 1 || !isset($message['labels'][-1])))
580
			{
581
				echo '
582
						<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
583
584
				foreach ($message['labels'] as $label)
585
					echo '
586
						<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
587
			}
588
			echo '
589
					</select>
590
					<noscript>
591
						<input type="submit" value="', $txt['pm_apply'], '" class="button">
592
					</noscript>';
593
		}
594
		echo '
595
				</div><!-- .labels -->';
596
	}
597
598
	echo '
599
			</div><!-- .moderatorbar -->
600
		</div><!-- .post_wrapper -->
601
	</div><!-- .windowbg -->';
602
}
603
604
/**
605
 * Just list all the personal message subjects - to make templates easier.
606
 */
607
function template_subject_list()
608
{
609
	global $context, $settings, $txt, $scripturl;
610
611
	echo '
612
	<table class="table_grid">
613
		<thead>
614
			<tr class="title_bar">
615
				<th class="centercol table_icon pm_icon">
616
					<a href="', $scripturl, '?action=pm;view;f=', $context['folder'], ';start=', $context['start'], ';sort=', $context['sort_by'], ($context['sort_direction'] == 'up' ? '' : ';desc'), ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''), '"> <span class="main_icons switch" title="', $txt['pm_change_view'], '"></span></a>
617
				</th>
618
				<th class="lefttext quarter_table pm_time">
619
					<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=date', $context['sort_by'] == 'date' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['date'], $context['sort_by'] == 'date' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
620
				</th>
621
				<th class="lefttext half_table pm_subject">
622
					<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
623
				</th>
624
				<th class="lefttext pm_from_to">
625
					<a href="', $scripturl, '?action=pm;f=', $context['folder'], ';start=', $context['start'], ';sort=name', $context['sort_by'] == 'name' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', '">', ($context['from_or_to'] == 'from' ? $txt['from'] : $txt['to']), $context['sort_by'] == 'name' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
626
				</th>
627
				<th class="centercol table_icon pm_moderation">
628
					<input type="checkbox" onclick="invertAll(this, this.form);">
629
				</th>
630
			</tr>
631
		</thead>
632
		<tbody>';
633
634
	if (!$context['show_delete'])
635
		echo '
636
			<tr class="windowbg">
637
				<td colspan="5">', $txt['pm_alert_none'], '</td>
638
			</tr>';
639
640
	while ($message = $context['get_pmessage']('subject'))
641
	{
642
		// Used for giving extra info in conversation view
643
		if ($context['current_pm'] == $message['id'])
644
		{
645
			$context['current_pm_subject'] = $message['subject'];
646
			$context['current_pm_time'] = $message['time'];
647
			$context['current_pm_author'] = $message['member']['link'];
648
		}
649
650
		echo '
651
			<tr class="windowbg', $message['is_unread'] ? ' unread_pm' : '', '">
652
				<td class="table_icon pm_icon">
653
					<script>
654
						currentLabels[', $message['id'], '] = {';
655
656
		if (!empty($message['labels']))
657
		{
658
			$first = true;
659
			foreach ($message['labels'] as $label)
660
			{
661
				echo $first ? '' : ',', '
662
				"', $label['id'], '": "', $label['name'], '"';
663
				$first = false;
664
			}
665
		}
666
667
		echo '
668
						};
669
					</script>
670
					', $message['is_replied_to'] ? '<span class="main_icons replied" title="' . $txt['pm_replied'] . '"></span>' : '<span class="main_icons im_off" title="' . $txt['pm_read'] . '"></span>', '
671
				</td>
672
				<td class="pm_time">', $message['time'], '</td>
673
				<td class="pm_subject">
674
					', ($context['display_mode'] != 0 && $context['current_pm'] == $message['id'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt="*">' : ''), '<a href="', ($context['display_mode'] == 0 || $context['current_pm'] == $message['id'] ? '' : ($scripturl . '?action=pm;pmid=' . $message['id'] . ';kstart;f=' . $context['folder'] . ';start=' . $context['start'] . ';sort=' . $context['sort_by'] . ($context['sort_direction'] == 'up' ? ';' : ';desc') . ($context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : ''))), '#msg', $message['id'], '">', $message['subject'], $message['is_unread'] ? '&nbsp;<span class="new_posts">' . $txt['new'] . '</span>' : '', '</a>
675
					<span class="pm_inline_time"><span class="main_icons ', ($context['from_or_to'] == 'to' && count($message['recipients']['to']) > 1) ? 'people' : 'members', '"></span> ', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '  <span class="main_icons time_online"></span> ', $message['time'], '</span>
676
				</td>
677
				<td class="pm_from_to">
678
					', ($context['from_or_to'] == 'from' ? $message['member']['link'] : (empty($message['recipients']['to']) ? '' : implode(', ', $message['recipients']['to']))), '
679
				</td>
680
				<td class="centercol table_icon pm_moderation">
681
					<input type="checkbox" name="pms[]" id="deletelisting', $message['id'], '" value="', $message['id'], '"', $message['is_selected'] ? ' checked' : '', ' onclick="if (document.getElementById(\'deletedisplay', $message['id'], '\')) document.getElementById(\'deletedisplay', $message['id'], '\').checked = this.checked;">
682
				</td>
683
			</tr>';
684
	}
685
686
	echo '
687
		</tbody>
688
	</table>
689
	<div class="pagesection">
690
		<div class="floatleft">', $context['page_index'], '</div>
691
		<div class="floatright">&nbsp;';
692
693
	if ($context['show_delete'])
694
	{
695
		if (!empty($context['currently_using_labels']) && $context['folder'] != 'sent')
696
		{
697
			echo '
698
			<select name="pm_action" onchange="if (this.options[this.selectedIndex].value) this.form.submit();" onfocus="loadLabelChoices();">
699
				<option value="">', $txt['pm_sel_label_title'], ':</option>
700
				<option value="" disabled>---------------</option>
701
				<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
702
703
			foreach ($context['labels'] as $label)
704
			{
705
				if ($label['id'] != $context['current_label_id'])
706
					echo '
707
				<option value="add_', $label['id'], '">&nbsp;', $label['name'], '</option>';
708
			}
709
710
			echo '
711
				<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
712
713
			foreach ($context['labels'] as $label)
714
				echo '
715
				<option value="rem_', $label['id'], '">&nbsp;', $label['name'], '</option>';
716
717
			echo '
718
			</select>
719
			<noscript>
720
				<input type="submit" value="', $txt['pm_apply'], '" class="button">
721
			</noscript>';
722
		}
723
724
		echo '
725
			<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">';
726
	}
727
728
	echo '
729
		</div><!-- .floatright -->
730
	</div><!-- .pagesection -->';
731
}
732
733
/**
734
 * The form for the PM search feature
735
 */
736
function template_search()
737
{
738
	global $context, $scripturl, $txt;
739
740
	if (!empty($context['search_errors']))
741
		echo '
742
		<div class="errorbox">
743
			', implode('<br>', $context['search_errors']['messages']), '
744
		</div>';
745
746
	echo '
747
	<form action="', $scripturl, '?action=pm;sa=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
748
		<div class="cat_bar">
749
			<h3 class="catbg">', $txt['pm_search_title'], '</h3>
750
		</div>
751
		<div id="advanced_search" class="roundframe">
752
			<input type="hidden" name="advanced" value="1">
753
			<dl id="search_options" class="settings">
754
				<dt>
755
					<strong><label for="searchfor">', $txt['pm_search_text'], ':</label></strong>
756
				</dt>
757
				<dd>
758
					<input type="search" name="search"', !empty($context['search_params']['search']) ? ' value="' . $context['search_params']['search'] . '"' : '', ' size="40">
759
					<script>
760
						createEventListener(window);
761
						window.addEventListener("load", initSearch, false);
762
					</script>
763
				</dd>
764
				<dt>
765
					<label for="searchtype">', $txt['search_match'], ':</label>
766
				</dt>
767
				<dd>
768
					<select name="searchtype">
769
						<option value="1"', empty($context['search_params']['searchtype']) ? ' selected' : '', '>', $txt['pm_search_match_all'], '</option>
770
						<option value="2"', !empty($context['search_params']['searchtype']) ? ' selected' : '', '>', $txt['pm_search_match_any'], '</option>
771
					</select>
772
				</dd>
773
				<dt>
774
					<label for="userspec">', $txt['pm_search_user'], ':</label>
775
				</dt>
776
				<dd>
777
					<input type="text" name="userspec" value="', empty($context['search_params']['userspec']) ? '*' : $context['search_params']['userspec'], '" size="40">
778
				</dd>
779
				<dt>
780
					<label for="sort">', $txt['pm_search_order'], ':</label>
781
				</dt>
782
				<dd>
783
					<select name="sort">
784
						<option value="relevance|desc">', $txt['pm_search_orderby_relevant_first'], '</option>
785
						<option value="id_pm|desc">', $txt['pm_search_orderby_recent_first'], '</option>
786
						<option value="id_pm|asc">', $txt['pm_search_orderby_old_first'], '</option>
787
					</select>
788
				</dd>
789
				<dt class="options">
790
					', $txt['pm_search_options'], ':
791
				</dt>
792
				<dd class="options">
793
					<label for="show_complete">
794
						<input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked' : '', '> ', $txt['pm_search_show_complete'], '
795
					</label><br>
796
					<label for="subject_only">
797
						<input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked' : '', '> ', $txt['pm_search_subject_only'], '
798
					</label>
799
				</dd>
800
				<dt class="between">
801
					', $txt['pm_search_post_age'], ':
802
				</dt>
803
				<dd>
804
					', $txt['pm_search_between'], '
805
					<input type="number" name="minage" value="', empty($context['search_params']['minage']) ? '0' : $context['search_params']['minage'], '" size="5" maxlength="5" min="0" max="9999">
806
					', $txt['pm_search_between_and'], '
807
					<input type="number" name="maxage" value="', empty($context['search_params']['maxage']) ? '9999' : $context['search_params']['maxage'], '" size="5" maxlength="5" min="0" max="9999">
808
					', $txt['pm_search_between_days'], '
809
				</dd>
810
			</dl>';
811
812
	if (!$context['currently_using_labels'])
813
		echo '
814
				<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button floatright">';
815
816
	echo '
817
		</div><!-- .roundframe -->';
818
819
	// Do we have some labels setup? If so offer to search by them!
820
	if ($context['currently_using_labels'])
821
	{
822
		echo '
823
		<fieldset class="labels">
824
			<div class="roundframe alt">
825
				<div class="title_bar">
826
					<h3 class="titlebg">
827
						<span id="advanced_panel_toggle" class="toggle_up floatright" style="display: none;"></span><a href="#" id="advanced_panel_link">', $txt['pm_search_choose_label'], '</a>
828
					</h3>
829
				</div>
830
				<div id="advanced_panel_div">
831
					<ul id="search_labels">';
832
833
		foreach ($context['search_labels'] as $label)
834
			echo '
835
						<li>
836
							<label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '"', $label['checked'] ? ' checked' : '', '>
837
							', $label['name'], '</label>
838
						</li>';
839
840
		echo '
841
					</ul>
842
				</div>
843
				<br class="clear">
844
				<div class="padding">
845
					<input type="checkbox" name="all" id="check_all" value=""', $context['check_all'] ? ' checked' : '', ' onclick="invertAll(this, this.form, \'searchlabel\');">
846
					<label for="check_all"><em>', $txt['check_all'], '</em></label>
847
					<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button floatright">
848
				</div class="padding">
849
			</div><!-- .roundframe -->
850
		</fieldset>';
851
852
		// Some javascript for the advanced toggling
853
		echo '
854
		<script>
855
			var oAdvancedPanelToggle = new smc_Toggle({
856
				bToggleEnabled: true,
857
				bCurrentlyCollapsed: true,
858
				aSwappableContainers: [
859
					\'advanced_panel_div\'
860
				],
861
				aSwapImages: [
862
					{
863
						sId: \'advanced_panel_toggle\',
864
						altExpanded: ', JavaScriptEscape($txt['hide']), ',
865
						altCollapsed: ', JavaScriptEscape($txt['show']), '
866
					}
867
				],
868
				aSwapLinks: [
869
					{
870
						sId: \'advanced_panel_link\',
871
						msgExpanded: ', JavaScriptEscape($txt['pm_search_choose_label']), ',
872
						msgCollapsed: ', JavaScriptEscape($txt['pm_search_choose_label']), '
873
					}
874
				]
875
			});
876
		</script>';
877
	}
878
879
	echo '
880
	</form>';
881
}
882
883
/**
884
 * Displays results from a PM search
885
 */
886
function template_search_results()
887
{
888
	global $context, $txt;
889
890
	echo '
891
		<div class="cat_bar">
892
			<h3 class="catbg">', $txt['pm_search_results'], '</h3>
893
		</div>
894
		<div class="roundframe noup">
895
			', sprintf($txt['pm_search_results_info'], $context['num_results'], sentence_list($context['search_in'])), '
896
		</div>
897
		<div class="pagesection">
898
			', $context['page_index'], '
899
		</div>';
900
901
	// Complete results?
902
	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
903
		echo '
904
		<table class="table_grid">
905
			<thead>
906
				<tr class="title_bar">
907
					<th class="lefttext quarter_table">', $txt['date'], '</th>
908
					<th class="lefttext half_table">', $txt['subject'], '</th>
909
					<th class="lefttext quarter_table">', $txt['from'], '</th>
910
				</tr>
911
			</thead>
912
			<tbody>';
913
914
	// Print each message out...
915
	foreach ($context['personal_messages'] as $message)
916
	{
917
		// Are we showing it all?
918
		if (!empty($context['search_params']['show_complete']))
919
			template_single_pm($message);
920
921
		// Otherwise just a simple list!
922
		// @todo No context at all of the search?
923
		else
924
			echo '
925
				<tr class="windowbg">
926
					<td>', $message['time'], '</td>
927
					<td>', $message['link'], '</td>
928
					<td>', $message['member']['link'], '</td>
929
				</tr>';
930
	}
931
932
	// Finish off the page...
933
	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
934
		echo '
935
			</tbody>
936
		</table>';
937
938
	// No results?
939
	if (empty($context['personal_messages']))
940
		echo '
941
		<div class="windowbg">
942
			<p class="centertext">', $txt['pm_search_none_found'], '</p>
943
		</div>';
944
945
	echo '
946
		<div class="pagesection">
947
			', $context['page_index'], '
948
		</div>';
949
950
}
951
952
/**
953
 * The form for sending a new PM
954
 */
955
function template_send()
956
{
957
	global $context, $options, $scripturl, $modSettings, $txt;
958
959
	// Show which messages were sent successfully and which failed.
960
	if (!empty($context['send_log']))
961
	{
962
		echo '
963
		<div class="cat_bar">
964
			<h3 class="catbg">', $txt['pm_send_report'], '</h3>
965
		</div>
966
		<div class="windowbg">';
967
968
		if (!empty($context['send_log']['sent']))
969
			foreach ($context['send_log']['sent'] as $log_entry)
970
				echo '
971
			<span class="error">', $log_entry, '</span><br>';
972
973
		if (!empty($context['send_log']['failed']))
974
			foreach ($context['send_log']['failed'] as $log_entry)
975
				echo '
976
			<span class="error">', $log_entry, '</span><br>';
977
978
		echo '
979
		</div>
980
		<br>';
981
	}
982
983
	// Show the preview of the personal message.
984
	echo '
985
		<div id="preview_section"', isset($context['preview_message']) ? '' : ' class="hidden"', '>
986
			<div class="cat_bar">
987
				<h3 class="catbg">
988
					<span id="preview_subject">', empty($context['preview_subject']) ? '' : $context['preview_subject'], '</span>
989
				</h3>
990
			</div>
991
			<div class="windowbg">
992
				<div class="post" id="preview_body">
993
					', empty($context['preview_message']) ? '<br>' : $context['preview_message'], '
994
				</div>
995
			</div>
996
			<br class="clear">
997
		</div>';
998
999
	// Main message editing box.
1000
	echo '
1001
		<form action="', $scripturl, '?action=pm;sa=send2" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify" class="flow_hidden" onsubmit="submitonce(this);">
1002
			<div class="cat_bar">
1003
				<h3 class="catbg">
1004
					<span class="main_icons inbox icon" title="', $txt['new_message'], '"></span> ', $txt['new_message'], '
1005
				</h3>
1006
			</div>
1007
			<div class="roundframe">';
1008
1009
	// If there were errors for sending the PM, show them.
1010
	echo '
1011
				<div class="', empty($context['error_type']) || $context['error_type'] != 'serious' ? 'noticebox' : 'errorbox', '', empty($context['post_error']['messages']) ? ' hidden' : '', '" id="errors">
1012
					<dl>
1013
						<dt>
1014
							<strong id="error_serious">', $txt['error_while_submitting'], '</strong>
1015
						</dt>
1016
						<dd class="error" id="error_list">
1017
							', empty($context['post_error']['messages']) ? '' : implode('<br>', $context['post_error']['messages']), '
1018
						</dd>
1019
					</dl>
1020
				</div>';
1021
1022
	if (!empty($modSettings['drafts_pm_enabled']))
1023
		echo '
1024
				<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
1025
					sprintf($txt['draft_pm_saved'], $scripturl . '?action=pm;sa=showpmdrafts'), '
1026
					', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
1027
				</div>';
1028
1029
	echo '
1030
				<dl id="post_header">';
1031
1032
	// To and bcc. Include a button to search for members.
1033
	echo '
1034
					<dt>
1035
						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), ' id="caption_to">', $txt['pm_to'], ':</span>
1036
					</dt>';
1037
1038
	// Autosuggest will be added by the JavaScript later on.
1039
	echo '
1040
					<dd id="pm_to" class="clear_right">
1041
						<input type="text" name="to" id="to_control" value="', $context['to_value'], '" tabindex="', $context['tabindex']++, '" size="20">';
1042
1043
	// A link to add BCC, only visible with JavaScript enabled.
1044
	echo '
1045
						<span class="smalltext" id="bcc_link_container" style="display: none;"></span>';
1046
1047
	// A div that'll contain the items found by the autosuggest.
1048
	echo '
1049
						<div id="to_item_list_container"></div>';
1050
1051
	echo '
1052
					</dd>';
1053
1054
	// This BCC row will be hidden by default if JavaScript is enabled.
1055
	echo '
1056
					<dt  class="clear_left" id="bcc_div">
1057
						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), ' id="caption_bbc">', $txt['pm_bcc'], ':</span>
1058
					</dt>
1059
					<dd id="bcc_div2">
1060
						<input type="text" name="bcc" id="bcc_control" value="', $context['bcc_value'], '" tabindex="', $context['tabindex']++, '" size="20">
1061
						<div id="bcc_item_list_container"></div>
1062
					</dd>';
1063
1064
	// The subject of the PM.
1065
	echo '
1066
					<dt class="clear_left">
1067
						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
1068
					</dt>
1069
					<dd id="pm_subject">
1070
						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="80"', isset($context['post_error']['no_subject']) ? ' class="error"' : '', '>
1071
					</dd>
1072
				</dl>';
1073
1074
	// Show BBC buttons, smileys and textbox.
1075
	echo '
1076
				', 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

1076
				', 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

1076
				', template_control_richedit($context['post_box_name'], /** @scrutinizer ignore-type */ 'smileyBox_message', 'bbcBox_message');
Loading history...
1077
1078
	// If the admin enabled the pm drafts feature, show a draft selection box
1079
	if (!empty($context['drafts_pm_save']) && !empty($context['drafts']) && !empty($options['drafts_show_saved_enabled']))
1080
	{
1081
		echo '
1082
				<div id="post_draft_options_header" class="title_bar">
1083
					<h4 class="titlebg">
1084
						<span id="postDraftExpand" class="toggle_up floatright" style="display: none;"></span> <strong><a href="#" id="postDraftExpandLink">', $txt['drafts_show'], '</a></strong>
1085
					</h4>
1086
				</div>
1087
				<div id="post_draft_options">
1088
					<dl class="settings">
1089
						<dt><strong>', $txt['subject'], '</strong></dt>
1090
						<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
1091
1092
		foreach ($context['drafts'] as $draft)
1093
			echo '
1094
						<dt>', $draft['link'], '</dt>
1095
						<dd>', $draft['poster_time'], '</dd>';
1096
		echo '
1097
					</dl>
1098
				</div>';
1099
	}
1100
1101
	// Require an image to be typed to save spamming?
1102
	if ($context['require_verification'])
1103
		echo '
1104
				<div class="post_verification">
1105
					<strong>', $txt['pm_visual_verification_label'], ':</strong>
1106
					', template_control_verification($context['visual_verification_id'], 'all'), '
1107
				</div>';
1108
1109
	// Send, Preview, spellcheck buttons.
1110
	echo '
1111
				<span id="post_confirm_buttons">
1112
					', 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...
1113
				</span>
1114
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1115
				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">
1116
				<input type="hidden" name="replied_to" value="', !empty($context['quoted_message']['id']) ? $context['quoted_message']['id'] : 0, '">
1117
				<input type="hidden" name="pm_head" value="', !empty($context['quoted_message']['pm_head']) ? $context['quoted_message']['pm_head'] : 0, '">
1118
				<input type="hidden" name="f" value="', isset($context['folder']) ? $context['folder'] : '', '">
1119
				<input type="hidden" name="l" value="', isset($context['current_label_id']) ? $context['current_label_id'] : -1, '">
1120
				<br class="clear_right">
1121
			</div><!-- .roundframe -->
1122
		</form>';
1123
1124
	echo '
1125
		<script>';
1126
1127
	// The functions used to preview a personal message without loading a new page.
1128
	echo '
1129
			var txt_preview_title = "', $txt['preview_title'], '";
1130
			var txt_preview_fetch = "', $txt['preview_fetch'], '";
1131
			function previewPost()
1132
			{
1133
				if (window.XMLHttpRequest)
1134
				{
1135
					// Opera didn\'t support setRequestHeader() before 8.01.
1136
					// @todo Remove support for old browsers
1137
					if (\'opera\' in window)
1138
					{
1139
						var test = new XMLHttpRequest();
1140
						if (!(\'setRequestHeader\' in test))
1141
							return submitThisOnce(document.forms.postmodify);
1142
					}
1143
					// @todo Currently not sending poll options and option checkboxes.
1144
					var x = new Array();
1145
					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'to\', \'bcc\'];
1146
					var numericFields = [\'recipient_to[]\', \'recipient_bcc[]\'];
1147
					var checkboxFields = [];
1148
1149
					for (var i = 0, n = textFields.length; i < n; i++)
1150
						if (textFields[i] in document.forms.postmodify)
1151
						{
1152
							// Handle the WYSIWYG editor.
1153
							if (textFields[i] == ', JavaScriptEscape($context['post_box_name']), ' && ', JavaScriptEscape('oEditorHandle_' . $context['post_box_name']), ' in window && oEditorHandle_', $context['post_box_name'], '.bRichTextEnabled)
1154
								x[x.length] = \'message_mode=1&\' + textFields[i] + \'=\' + oEditorHandle_', $context['post_box_name'], '.getText(false).php_to8bit().php_urlencode();
1155
							else
1156
								x[x.length] = textFields[i] + \'=\' + document.forms.postmodify[textFields[i]].value.php_to8bit().php_urlencode();
1157
						}
1158
					for (var i = 0, n = numericFields.length; i < n; i++)
1159
						if (numericFields[i] in document.forms.postmodify && \'value\' in document.forms.postmodify[numericFields[i]])
1160
							x[x.length] = numericFields[i] + \'=\' + parseInt(document.forms.postmodify.elements[numericFields[i]].value);
1161
					for (var i = 0, n = checkboxFields.length; i < n; i++)
1162
						if (checkboxFields[i] in document.forms.postmodify && document.forms.postmodify.elements[checkboxFields[i]].checked)
1163
							x[x.length] = checkboxFields[i] + \'=\' + document.forms.postmodify.elements[checkboxFields[i]].value;
1164
1165
					sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + \'action=pm;sa=send2;preview;xml\', x.join(\'&\'), onDocSent);
1166
1167
					document.getElementById(\'preview_section\').style.display = \'\';
1168
					setInnerHTML(document.getElementById(\'preview_subject\'), txt_preview_title);
1169
					setInnerHTML(document.getElementById(\'preview_body\'), txt_preview_fetch);
1170
1171
					return false;
1172
				}
1173
				else
1174
					return submitThisOnce(document.forms.postmodify);
1175
			}
1176
			function onDocSent(XMLDoc)
1177
			{
1178
				if (!XMLDoc)
1179
				{
1180
					document.forms.postmodify.preview.onclick = new function ()
1181
					{
1182
						return true;
1183
					}
1184
					document.forms.postmodify.preview.click();
1185
				}
1186
1187
				// Show the preview section.
1188
				var preview = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'preview\')[0];
1189
				setInnerHTML(document.getElementById(\'preview_subject\'), preview.getElementsByTagName(\'subject\')[0].firstChild.nodeValue);
1190
1191
				var bodyText = \'\';
1192
				for (var i = 0, n = preview.getElementsByTagName(\'body\')[0].childNodes.length; i < n; i++)
1193
					bodyText += preview.getElementsByTagName(\'body\')[0].childNodes[i].nodeValue;
1194
1195
				setInnerHTML(document.getElementById(\'preview_body\'), bodyText);
1196
				document.getElementById(\'preview_body\').className = \'post\';
1197
1198
				// Show a list of errors (if any).
1199
				var errors = XMLDoc.getElementsByTagName(\'smf\')[0].getElementsByTagName(\'errors\')[0];
1200
				var errorList = new Array();
1201
				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
1202
					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
1203
				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
1204
				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br>\'));
1205
1206
				// Adjust the color of captions if the given data is erroneous.
1207
				var captions = errors.getElementsByTagName(\'caption\');
1208
				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)
1209
					if (document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')))
1210
						document.getElementById(\'caption_\' + captions[i].getAttribute(\'name\')).className = captions[i].getAttribute(\'class\');
1211
1212
				if (errors.getElementsByTagName(\'post_error\').length == 1)
1213
					document.forms.postmodify.', $context['post_box_name'], '.style.border = \'1px solid red\';
1214
				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\')
1215
				{
1216
					if (\'runtimeStyle\' in document.forms.postmodify.', $context['post_box_name'], ')
1217
						document.forms.postmodify.', $context['post_box_name'], '.style.borderColor = \'\';
1218
					else
1219
						document.forms.postmodify.', $context['post_box_name'], '.style.border = null;
1220
				}
1221
				location.hash = \'#\' + \'preview_section\';
1222
			}';
1223
1224
	// Code for showing and hiding drafts
1225
	if (!empty($context['drafts']))
1226
		echo '
1227
			var oSwapDraftOptions = new smc_Toggle({
1228
				bToggleEnabled: true,
1229
				bCurrentlyCollapsed: true,
1230
				aSwappableContainers: [
1231
					\'post_draft_options\',
1232
				],
1233
				aSwapImages: [
1234
					{
1235
						sId: \'postDraftExpand\',
1236
						altExpanded: \'-\',
1237
						altCollapsed: \'+\'
1238
					}
1239
				],
1240
				aSwapLinks: [
1241
					{
1242
						sId: \'postDraftExpandLink\',
1243
						msgExpanded: ', JavaScriptEscape($txt['draft_hide']), ',
1244
						msgCollapsed: ', JavaScriptEscape($txt['drafts_show']), '
1245
					}
1246
				]
1247
			});';
1248
1249
	echo '
1250
		</script>';
1251
1252
	// Show the message you're replying to.
1253
	if ($context['reply'])
1254
		echo '
1255
		<br><br>
1256
		<div class="cat_bar">
1257
			<h3 class="catbg">', $txt['subject'], ': ', $context['quoted_message']['subject'], '</h3>
1258
		</div>
1259
		<div class="windowbg">
1260
			<div class="clear">
1261
				<span class="smalltext floatright">', $txt['on'], ': ', $context['quoted_message']['time'], '</span>
1262
				<strong>', $txt['from'], ': ', $context['quoted_message']['member']['name'], '</strong>
1263
			</div>
1264
			<hr>
1265
			', $context['quoted_message']['body'], '
1266
		</div>
1267
		<br class="clear">';
1268
1269
	echo '
1270
		<script>
1271
			var oPersonalMessageSend = new smf_PersonalMessageSend({
1272
				sSelf: \'oPersonalMessageSend\',
1273
				sSessionId: smf_session_id,
1274
				sSessionVar: smf_session_var,
1275
				sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
1276
				sToControlId: \'to_control\',
1277
				aToRecipients: [';
1278
1279
	foreach ($context['recipients']['to'] as $i => $member)
1280
		echo '
1281
					{
1282
						sItemId: ', JavaScriptEscape($member['id']), ',
1283
						sItemName: ', JavaScriptEscape($member['name']), '
1284
					}', $i == count($context['recipients']['to']) - 1 ? '' : ',';
1285
1286
	echo '
1287
				],
1288
				aBccRecipients: [';
1289
1290
	foreach ($context['recipients']['bcc'] as $i => $member)
1291
		echo '
1292
					{
1293
						sItemId: ', JavaScriptEscape($member['id']), ',
1294
						sItemName: ', JavaScriptEscape($member['name']), '
1295
					}', $i == count($context['recipients']['bcc']) - 1 ? '' : ',';
1296
1297
	echo '
1298
				],
1299
				sBccControlId: \'bcc_control\',
1300
				sBccDivId: \'bcc_div\',
1301
				sBccDivId2: \'bcc_div2\',
1302
				sBccLinkId: \'bcc_link\',
1303
				sBccLinkContainerId: \'bcc_link_container\',
1304
				bBccShowByDefault: ', empty($context['recipients']['bcc']) && empty($context['bcc_value']) ? 'false' : 'true', ',
1305
				sShowBccLinkTemplate: ', JavaScriptEscape('
1306
					<a href="#" id="bcc_link">' . $txt['make_bcc'] . '</a> <a href="' . $scripturl . '?action=helpadmin;help=pm_bcc" onclick="return reqOverlayDiv(this.href);">(?)</a>'
1307
				), '
1308
			});';
1309
1310
	echo '
1311
		</script>';
1312
}
1313
1314
/**
1315
 * This template asks the user whether they wish to empty out their folder/messages.
1316
 */
1317
function template_ask_delete()
1318
{
1319
	global $context, $scripturl, $txt;
1320
1321
	echo '
1322
		<div class="cat_bar">
1323
			<h3 class="catbg">
1324
				', ($context['delete_all'] ? $txt['delete_message'] : $txt['delete_all']), '
1325
			</h3>
1326
		</div>
1327
		<div class="windowbg">
1328
			<p>', $txt['delete_all_confirm'], '</p>
1329
			<br>
1330
			<strong><a href="', $scripturl, '?action=pm;sa=removeall2;f=', $context['folder'], ';', $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="javascript:history.go(-1);">', $txt['no'], '</a></strong>
1331
		</div>';
1332
}
1333
1334
/**
1335
 * This template asks the user what messages they want to prune.
1336
 */
1337
function template_prune()
1338
{
1339
	global $context, $scripturl, $txt;
1340
1341
	echo '
1342
		<div class="cat_bar">
1343
			<h3 class="catbg">', $txt['pm_prune'], '</h3>
1344
		</div>
1345
		<div class="windowbg">
1346
			<form action="', $scripturl, '?action=pm;sa=prune" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirm(\'', $txt['pm_prune_warning'], '\');">
1347
				<p>', $txt['pm_prune_desc1'], ' <input type="text" name="age" size="3" value="14"> ', $txt['pm_prune_desc2'], '</p>
1348
				<input type="submit" value="', $txt['delete'], '" class="button">
1349
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1350
			</form>
1351
		</div>
1352
		<div class="windowbg">
1353
			<form action="', $scripturl, '?action=pm;sa=removeall2" method="post" onsubmit="return confirm(\'', $txt['pm_remove_all_warning'], '\');">
1354
				<p>', $txt['pm_remove_all'], '</p>
1355
				<input type="submit" value="', $txt['delete_all_prune'], '" class="button">
1356
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1357
			</form>
1358
		</div>';
1359
}
1360
1361
/**
1362
 * Here we allow the user to setup labels, remove labels and change rules for labels (i.e, do quite a bit)
1363
 */
1364
function template_labels()
1365
{
1366
	global $context, $scripturl, $txt;
1367
1368
	echo '
1369
	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
1370
		<div class="cat_bar">
1371
			<h3 class="catbg">', $txt['pm_manage_labels'], '</h3>
1372
		</div>
1373
		<div class="information">
1374
			', $txt['pm_labels_desc'], '
1375
		</div>
1376
		<table class="table_grid">
1377
			<thead>
1378
				<tr class="title_bar">
1379
					<th class="lefttext">
1380
						', $txt['pm_label_name'], '
1381
					</th>
1382
					<th class="centertext table_icon">';
1383
1384
	if (count($context['labels']) > 2)
1385
		echo '
1386
						<input type="checkbox" onclick="invertAll(this, this.form);">';
1387
1388
	echo '
1389
					</th>
1390
				</tr>
1391
			</thead>
1392
			<tbody>';
1393
	if (count($context['labels']) < 2)
1394
		echo '
1395
				<tr class="windowbg">
1396
					<td colspan="2">', $txt['pm_labels_no_exist'], '</td>
1397
				</tr>';
1398
	else
1399
	{
1400
		foreach ($context['labels'] as $label)
1401
		{
1402
			if ($label['id'] == -1)
1403
				continue;
1404
1405
			echo '
1406
				<tr class="windowbg">
1407
					<td>
1408
						<input type="text" name="label_name[', $label['id'], ']" value="', $label['name'], '" size="30" maxlength="30">
1409
					</td>
1410
					<td class="table_icon"><input type="checkbox" name="delete_label[', $label['id'], ']"></td>
1411
				</tr>';
1412
		}
1413
	}
1414
	echo '
1415
			</tbody>
1416
		</table>';
1417
1418
	if (!count($context['labels']) < 2)
1419
		echo '
1420
		<div class="block righttext">
1421
			<input type="submit" name="save" value="', $txt['save'], '" class="button">
1422
			<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" data-confirm="', $txt['pm_labels_delete'], '" class="button you_sure">
1423
		</div>';
1424
1425
	echo '
1426
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1427
	</form>
1428
	<form action="', $scripturl, '?action=pm;sa=manlabels" method="post" accept-charset="', $context['character_set'], '">
1429
		<div class="cat_bar">
1430
			<h3 class="catbg">', $txt['pm_label_add_new'], '</h3>
1431
		</div>
1432
		<div class="windowbg">
1433
			<dl class="settings">
1434
				<dt>
1435
					<strong><label for="add_label">', $txt['pm_label_name'], '</label>:</strong>
1436
				</dt>
1437
				<dd>
1438
					<input type="text" id="add_label" name="label" value="" size="30" maxlength="30">
1439
				</dd>
1440
			</dl>
1441
			<input type="submit" name="add" value="', $txt['pm_label_add_new'], '" class="button floatright">
1442
		</div>
1443
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1444
	</form>
1445
	<br>';
1446
}
1447
1448
/**
1449
 * Template for reporting a personal message.
1450
 */
1451
function template_report_message()
1452
{
1453
	global $context, $txt, $scripturl;
1454
1455
	echo '
1456
	<form action="', $scripturl, '?action=pm;sa=report;l=', $context['current_label_id'], '" method="post" accept-charset="', $context['character_set'], '">
1457
		<input type="hidden" name="pmsg" value="', $context['pm_id'], '">
1458
		<div class="information">
1459
			', $txt['pm_report_desc'], '
1460
		</div>
1461
		<div class="cat_bar">
1462
			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
1463
		</div>
1464
		<div class="windowbg">
1465
			<dl class="settings">';
1466
1467
	// If there is more than one admin on the forum, allow the user to choose the one they want to direct to.
1468
	// @todo Why?
1469
	if ($context['admin_count'] > 1)
1470
	{
1471
		echo '
1472
				<dt>
1473
					<strong>', $txt['pm_report_admins'], ':</strong>
1474
				</dt>
1475
				<dd>
1476
					<select name="id_admin">
1477
						<option value="0">', $txt['pm_report_all_admins'], '</option>';
1478
1479
		foreach ($context['admins'] as $id => $name)
1480
			echo '
1481
						<option value="', $id, '">', $name, '</option>';
1482
1483
		echo '
1484
					</select>
1485
				</dd>';
1486
	}
1487
1488
	echo '
1489
				<dt>
1490
					<strong>', $txt['pm_report_reason'], ':</strong>
1491
				</dt>
1492
				<dd>
1493
					<textarea name="reason" rows="4" cols="70" style="width: 80%;"></textarea>
1494
				</dd>
1495
			</dl>
1496
			<div class="righttext">
1497
				<input type="submit" name="report" value="', $txt['pm_report_message'], '" class="button">
1498
			</div>
1499
		</div><!-- .windowbg -->
1500
		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1501
	</form>';
1502
}
1503
1504
/**
1505
 * Little template just to say "Yep, it's been submitted"
1506
 */
1507
function template_report_message_complete()
1508
{
1509
	global $context, $txt, $scripturl;
1510
1511
	echo '
1512
		<div class="cat_bar">
1513
			<h3 class="catbg">', $txt['pm_report_title'], '</h3>
1514
		</div>
1515
		<div class="windowbg">
1516
			<p>', $txt['pm_report_done'], '</p>
1517
			<a href="', $scripturl, '?action=pm;l=', $context['current_label_id'], '">', $txt['pm_report_return'], '</a>
1518
		</div>';
1519
}
1520
1521
/**
1522
 * Manage rules.
1523
 */
1524
function template_rules()
1525
{
1526
	global $context, $txt, $scripturl;
1527
1528
	echo '
1529
	<form action="', $scripturl, '?action=pm;sa=manrules" method="post" accept-charset="', $context['character_set'], '" name="manRules" id="manrules">
1530
		<div class="cat_bar">
1531
			<h3 class="catbg">', $txt['pm_manage_rules'], '</h3>
1532
		</div>
1533
		<div class="information">
1534
			', $txt['pm_manage_rules_desc'], '
1535
		</div>
1536
		<table class="table_grid">
1537
			<thead>
1538
				<tr class="title_bar">
1539
					<th class="lefttext">
1540
						', $txt['pm_rule_title'], '
1541
					</th>
1542
					<th class="centertext table_icon">';
1543
1544
	if (!empty($context['rules']))
1545
		echo '
1546
						<input type="checkbox" onclick="invertAll(this, this.form);">';
1547
1548
	echo '
1549
					</th>
1550
				</tr>
1551
			</thead>
1552
			<tbody>';
1553
1554
	if (empty($context['rules']))
1555
		echo '
1556
				<tr class="windowbg">
1557
					<td colspan="2">
1558
						', $txt['pm_rules_none'], '
1559
					</td>
1560
				</tr>';
1561
1562
	foreach ($context['rules'] as $rule)
1563
		echo '
1564
				<tr class="windowbg">
1565
					<td>
1566
						<a href="', $scripturl, '?action=pm;sa=manrules;add;rid=', $rule['id'], '">', $rule['name'], '</a>
1567
					</td>
1568
					<td class="table_icon">
1569
						<input type="checkbox" name="delrule[', $rule['id'], ']">
1570
					</td>
1571
				</tr>';
1572
1573
	echo '
1574
			</tbody>
1575
		</table>
1576
		<div class="righttext">
1577
			<a class="button" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>';
1578
1579
	if (!empty($context['rules']))
1580
		echo '
1581
			[<a href="', $scripturl, '?action=pm;sa=manrules;apply;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['pm_js_apply_rules_confirm'], '\');">', $txt['pm_apply_rules'], '</a>]';
1582
1583
	if (!empty($context['rules']))
1584
		echo '
1585
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1586
			<input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" data-confirm="', $txt['pm_js_delete_rule_confirm'], '" class="button smalltext you_sure">';
1587
1588
	echo '
1589
		</div>
1590
	</form>';
1591
1592
}
1593
1594
/**
1595
 * Template for adding/editing a rule.
1596
 */
1597
function template_add_rule()
1598
{
1599
	global $context, $txt, $scripturl;
1600
1601
	echo '
1602
	<script>
1603
		var criteriaNum = 0;
1604
		var actionNum = 0;
1605
		var groups = new Array()
1606
		var labels = new Array()';
1607
1608
	foreach ($context['groups'] as $id => $title)
1609
		echo '
1610
		groups[', $id, '] = "', addslashes($title), '";';
1611
1612
	foreach ($context['labels'] as $label)
1613
		if ($label['id'] != -1)
1614
			echo '
1615
		labels[', ($label['id']), '] = "', addslashes($label['name']), '";';
1616
1617
	echo '
1618
		function addCriteriaOption()
1619
		{
1620
			if (criteriaNum == 0)
1621
			{
1622
				for (var i = 0; i < document.forms.addrule.elements.length; i++)
1623
					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
1624
						criteriaNum++;
1625
			}
1626
			criteriaNum++
1627
1628
			setOuterHTML(document.getElementById("criteriaAddHere"), \'<br><select name="ruletype[\' + criteriaNum + \']" id="ruletype\' + criteriaNum + \'" onchange="updateRuleDef(\' + criteriaNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_criteria_pick']), ':<\' + \'/option><option value="mid">', addslashes($txt['pm_rule_mid']), '<\' + \'/option><option value="gid">', addslashes($txt['pm_rule_gid']), '<\' + \'/option><option value="sub">', addslashes($txt['pm_rule_sub']), '<\' + \'/option><option value="msg">', addslashes($txt['pm_rule_msg']), '<\' + \'/option><option value="bud">', addslashes($txt['pm_rule_bud']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="defdiv\' + criteriaNum + \'" style="display: none;"><input type="text" name="ruledef[\' + criteriaNum + \']" id="ruledef\' + criteriaNum + \'" onkeyup="rebuildRuleDesc();" value=""><\' + \'/span><span id="defseldiv\' + criteriaNum + \'" style="display: none;"><select name="ruledefgroup[\' + criteriaNum + \']" id="ruledefgroup\' + criteriaNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_group']), '<\' + \'/option>';
1629
1630
	foreach ($context['groups'] as $id => $group)
1631
		echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
1632
1633
	echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\');
1634
			}
1635
1636
			function addActionOption()
1637
			{
1638
				if (actionNum == 0)
1639
				{
1640
					for (var i = 0; i < document.forms.addrule.elements.length; i++)
1641
						if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
1642
							actionNum++;
1643
				}
1644
				actionNum++
1645
1646
				setOuterHTML(document.getElementById("actionAddHere"), \'<br><select name="acttype[\' + actionNum + \']" id="acttype\' + actionNum + \'" onchange="updateActionDef(\' + actionNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_action']), ':<\' + \'/option><option value="lab">', addslashes($txt['pm_rule_label']), '<\' + \'/option><option value="del">', addslashes($txt['pm_rule_delete']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="labdiv\' + actionNum + \'" style="display: none;"><select name="labdef[\' + actionNum + \']" id="labdef\' + actionNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_label']), '<\' + \'/option>';
1647
1648
	foreach ($context['labels'] as $label)
1649
		if ($label['id'] != -1)
1650
			echo '<option value="', ($label['id']), '">', addslashes($label['name']), '<\' + \'/option>';
1651
1652
	echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\');
1653
			}
1654
1655
			// Rebuild the rule description!
1656
			function rebuildRuleDesc()
1657
			{
1658
				// Start with nothing.
1659
				var text = "";
1660
				var joinText = "";
1661
				var actionText = "";
1662
				var hadBuddy = false;
1663
				var foundCriteria = false;
1664
				var foundAction = false;
1665
				var curNum, curVal, curDef;
1666
1667
				for (var i = 0; i < document.forms.addrule.elements.length; i++)
1668
				{
1669
					if (document.forms.addrule.elements[i].id.substr(0, 8) == "ruletype")
1670
					{
1671
						if (foundCriteria)
1672
							joinText = document.getElementById("logic").value == \'and\' ? ', JavaScriptEscape(' <em>' . $txt['pm_readable_and'] . '</em> '), ' : ', JavaScriptEscape(' <em>' . $txt['pm_readable_or'] . '</em> '), ';
1673
						else
1674
							joinText = \'\';
1675
						foundCriteria = true;
1676
1677
						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
1678
						curVal = document.forms.addrule.elements[i].value;
1679
						if (curVal == "gid")
1680
							curDef = document.getElementById("ruledefgroup" + curNum).value.php_htmlspecialchars();
1681
						else if (curVal != "bud")
1682
							curDef = document.getElementById("ruledef" + curNum).value.php_htmlspecialchars();
1683
						else
1684
							curDef = "";
1685
1686
						// What type of test is this?
1687
						if (curVal == "mid" && curDef)
1688
							text += joinText + ', JavaScriptEscape($txt['pm_readable_member']), '.replace("{MEMBER}", curDef);
1689
						else if (curVal == "gid" && curDef && groups[curDef])
1690
							text += joinText + ', JavaScriptEscape($txt['pm_readable_group']), '.replace("{GROUP}", groups[curDef]);
1691
						else if (curVal == "sub" && curDef)
1692
							text += joinText + ', JavaScriptEscape($txt['pm_readable_subject']), '.replace("{SUBJECT}", curDef);
1693
						else if (curVal == "msg" && curDef)
1694
							text += joinText + ', JavaScriptEscape($txt['pm_readable_body']), '.replace("{BODY}", curDef);
1695
						else if (curVal == "bud" && !hadBuddy)
1696
						{
1697
							text += joinText + ', JavaScriptEscape($txt['pm_readable_buddy']), ';
1698
							hadBuddy = true;
1699
						}
1700
					}
1701
					if (document.forms.addrule.elements[i].id.substr(0, 7) == "acttype")
1702
					{
1703
						if (foundAction)
1704
							joinText = ', JavaScriptEscape(' <em>' . $txt['pm_readable_and'] . '</em> '), ';
1705
						else
1706
							joinText = "";
1707
						foundAction = true;
1708
1709
						curNum = document.forms.addrule.elements[i].id.match(/\d+/);
1710
						curVal = document.forms.addrule.elements[i].value;
1711
						if (curVal == "lab")
1712
							curDef = document.getElementById("labdef" + curNum).value.php_htmlspecialchars();
1713
						else
1714
							curDef = "";
1715
1716
						// Now pick the actions.
1717
						if (curVal == "lab" && curDef && labels[curDef])
1718
							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_label']), '.replace("{LABEL}", labels[curDef]);
1719
						else if (curVal == "del")
1720
							actionText += joinText + ', JavaScriptEscape($txt['pm_readable_delete']), ';
1721
					}
1722
				}
1723
1724
				// If still nothing make it default!
1725
				if (text == "" || !foundCriteria)
1726
					text = "', $txt['pm_rule_not_defined'], '";
1727
				else
1728
				{
1729
					if (actionText != "")
1730
						text += ', JavaScriptEscape(' <strong>' . $txt['pm_readable_then'] . '</strong> '), ' + actionText;
1731
					text = ', JavaScriptEscape($txt['pm_readable_start']), ' + text + ', JavaScriptEscape($txt['pm_readable_end']), ';
1732
				}
1733
1734
				// Set the actual HTML!
1735
				setInnerHTML(document.getElementById("ruletext"), text);
1736
			}
1737
	</script>';
1738
1739
	echo '
1740
	<form action="', $scripturl, '?action=pm;sa=manrules;save;rid=', $context['rid'], '" method="post" accept-charset="', $context['character_set'], '" name="addrule" id="addrule" class="flow_hidden">
1741
		<div class="cat_bar">
1742
			<h3 class="catbg">', $context['rid'] == 0 ? $txt['pm_add_rule'] : $txt['pm_edit_rule'], '</h3>
1743
		</div>
1744
		<div class="windowbg">
1745
			<dl class="addrules">
1746
				<dt class="floatleft">
1747
					<strong>', $txt['pm_rule_name'], ':</strong><br>
1748
					<span class="smalltext">', $txt['pm_rule_name_desc'], '</span>
1749
				</dt>
1750
				<dd class="floatleft">
1751
					<input type="text" name="rule_name" value="', empty($context['rule']['name']) ? $txt['pm_rule_name_default'] : $context['rule']['name'], '" size="50">
1752
				</dd>
1753
			</dl>
1754
			<fieldset>
1755
				<legend>', $txt['pm_rule_criteria'], '</legend>';
1756
1757
	// Add a dummy criteria to allow expansion for none js users.
1758
	$context['rule']['criteria'][] = array('t' => '', 'v' => '');
1759
1760
	// For each criteria print it out.
1761
	$isFirst = true;
1762
	foreach ($context['rule']['criteria'] as $k => $criteria)
1763
	{
1764
		if (!$isFirst && $criteria['t'] == '')
1765
			echo '<div id="removeonjs1">';
1766
1767
		elseif (!$isFirst)
1768
			echo '<br>';
1769
1770
		echo '
1771
				<select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();">
1772
					<option value="">', $txt['pm_rule_criteria_pick'], ':</option>';
1773
1774
		foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr)
1775
			echo '
1776
					<option value="', $cr, '"', $criteria['t'] == $cr ? ' selected' : '', '>', $txt['pm_rule_' . $cr], '</option>';
1777
1778
		echo '
1779
				</select>
1780
				<span id="defdiv', $k, '" ', !in_array($criteria['t'], array('gid', 'bud')) ? '' : 'style="display: none;"', '>
1781
					<input type="text" name="ruledef[', $k, ']" id="ruledef', $k, '" onkeyup="rebuildRuleDesc();" value="', in_array($criteria['t'], array('mid', 'sub', 'msg')) ? $criteria['v'] : '', '">
1782
				</span>
1783
				<span id="defseldiv', $k, '" ', $criteria['t'] == 'gid' ? '' : 'style="display: none;"', '>
1784
					<select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();">
1785
						<option value="">', $txt['pm_rule_sel_group'], '</option>';
1786
1787
		foreach ($context['groups'] as $id => $group)
1788
			echo '
1789
						<option value="', $id, '"', $criteria['t'] == 'gid' && $criteria['v'] == $id ? ' selected' : '', '>', $group, '</option>';
1790
		echo '
1791
					</select>
1792
				</span>';
1793
1794
		// If this is the dummy we add a means to hide for non js users.
1795
		if ($isFirst)
1796
			$isFirst = false;
1797
1798
		elseif ($criteria['t'] == '')
1799
			echo '</div><!-- .removeonjs1 -->';
1800
	}
1801
1802
	echo '
1803
				<span id="criteriaAddHere"></span><br>
1804
				<a href="#" onclick="addCriteriaOption(); return false;" id="addonjs1" style="display: none;">(', $txt['pm_rule_criteria_add'], ')</a>
1805
				<br><br>
1806
				', $txt['pm_rule_logic'], ':
1807
				<select name="rule_logic" id="logic" onchange="rebuildRuleDesc();">
1808
					<option value="and"', $context['rule']['logic'] == 'and' ? ' selected' : '', '>', $txt['pm_rule_logic_and'], '</option>
1809
					<option value="or"', $context['rule']['logic'] == 'or' ? ' selected' : '', '>', $txt['pm_rule_logic_or'], '</option>
1810
				</select>
1811
			</fieldset>
1812
			<fieldset>
1813
				<legend>', $txt['pm_rule_actions'], '</legend>';
1814
1815
	// As with criteria - add a dummy action for "expansion".
1816
	$context['rule']['actions'][] = array('t' => '', 'v' => '');
1817
1818
	// Print each action.
1819
	$isFirst = true;
1820
	foreach ($context['rule']['actions'] as $k => $action)
1821
	{
1822
		if (!$isFirst && $action['t'] == '')
1823
			echo '<div id="removeonjs2">';
1824
		elseif (!$isFirst)
1825
			echo '<br>';
1826
1827
		echo '
1828
				<select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();">
1829
					<option value="">', $txt['pm_rule_sel_action'], ':</option>
1830
					<option value="lab"', $action['t'] == 'lab' ? ' selected' : '', '>', $txt['pm_rule_label'], '</option>
1831
					<option value="del"', $action['t'] == 'del' ? ' selected' : '', '>', $txt['pm_rule_delete'], '</option>
1832
				</select>
1833
				<span id="labdiv', $k, '">
1834
					<select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();">
1835
						<option value="">', $txt['pm_rule_sel_label'], '</option>';
1836
1837
		foreach ($context['labels'] as $label)
1838
			if ($label['id'] != -1)
1839
				echo '
1840
						<option value="', ($label['id']), '"', $action['t'] == 'lab' && $action['v'] == $label['id'] ? ' selected' : '', '>', $label['name'], '</option>';
1841
1842
		echo '
1843
					</select>
1844
				</span>';
1845
1846
		if ($isFirst)
1847
			$isFirst = false;
1848
1849
		elseif ($action['t'] == '')
1850
			echo '</div><!-- .removeonjs2 -->';
1851
	}
1852
1853
	echo '
1854
				<span id="actionAddHere"></span><br>
1855
				<a href="#" onclick="addActionOption(); return false;" id="addonjs2" style="display: none;">(', $txt['pm_rule_add_action'], ')</a>
1856
			</fieldset>
1857
			<div class="cat_bar">
1858
				<h3 class="catbg">', $txt['pm_rule_description'], '</h3>
1859
			</div>
1860
			<div class="information">
1861
				<div id="ruletext">', $txt['pm_rule_js_disabled'], '</div>
1862
			</div>
1863
			<div class="righttext">
1864
				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1865
				<input type="submit" name="save" value="', $txt['pm_rule_save'], '" class="button">
1866
			</div>
1867
		</div><!-- .windowbg -->
1868
	</form>';
1869
1870
	// Now setup all the bits!
1871
	echo '
1872
	<script>';
1873
1874
	foreach ($context['rule']['criteria'] as $k => $c)
1875
		echo '
1876
			updateRuleDef(', $k, ');';
1877
1878
	foreach ($context['rule']['actions'] as $k => $c)
1879
		echo '
1880
			updateActionDef(', $k, ');';
1881
1882
	echo '
1883
			rebuildRuleDesc();';
1884
1885
	// If this isn't a new rule and we have JS enabled remove the JS compatibility stuff.
1886
	if ($context['rid'])
1887
		echo '
1888
			document.getElementById("removeonjs1").style.display = "none";
1889
			document.getElementById("removeonjs2").style.display = "none";';
1890
1891
	echo '
1892
			document.getElementById("addonjs1").style.display = "";
1893
			document.getElementById("addonjs2").style.display = "";';
1894
1895
	echo '
1896
		</script>';
1897
}
1898
1899
/**
1900
 * Template for showing all of a user's PM drafts.
1901
 */
1902
function template_showPMDrafts()
1903
{
1904
	global $context, $scripturl, $txt;
1905
1906
	echo '
1907
		<div class="cat_bar">
1908
			<h3 class="catbg">
1909
				<span class="main_icons inbox"></span> ', $txt['drafts_show'], '
1910
			</h3>
1911
		</div>
1912
		<div class="pagesection">
1913
			<span>', $context['page_index'], '</span>
1914
		</div>';
1915
1916
	// No drafts? Just show an informative message.
1917
	if (empty($context['drafts']))
1918
		echo '
1919
		<div class="windowbg centertext">
1920
			', $txt['draft_none'], '
1921
		</div>';
1922
	else
1923
	{
1924
		// For every draft to be displayed, give it its own div, and show the important details of the draft.
1925
		foreach ($context['drafts'] as $draft)
1926
		{
1927
			echo '
1928
		<div class="windowbg">
1929
			<div class="counter">', $draft['counter'], '</div>
1930
			<div class="topic_details">
1931
				<div class="floatright smalltext righttext">
1932
					<div class="recipient_to">&#171;&nbsp;<strong>', $txt['to'], ':</strong> ', implode(', ', $draft['recipients']['to']), '&nbsp;&#187;</div>';
1933
1934
			if(!empty($draft['recipients']['bcc']))
1935
				echo'
1936
					<div class="pm_bbc">&#171;&nbsp;<strong>', $txt['pm_bcc'], ':</strong> ', implode(', ', $draft['recipients']['bcc']), '&nbsp;&#187;</div>';
1937
1938
			echo '
1939
				</div>
1940
				<h5>
1941
					<strong>', $draft['subject'], '</strong>
1942
				</h5>
1943
				<span class="smalltext">&#171;&nbsp;<strong>', $txt['draft_saved_on'], ':</strong> ', sprintf($txt['draft_days_ago'], $draft['age']), (!empty($draft['remaining']) ? ', ' . sprintf($txt['draft_retain'], $draft['remaining']) : ''), '&#187;</span><br>
1944
			</div>
1945
			<div class="list_posts">
1946
				', $draft['body'], '
1947
			</div>';
1948
1949
			// Draft buttons
1950
			template_quickbuttons($draft['quickbuttons'], 'pm_drafts');
1951
1952
			echo '
1953
		</div><!-- .windowbg -->';
1954
		}
1955
	}
1956
1957
	// Show page numbers.
1958
	echo '
1959
	<div class="pagesection">
1960
		<span>', $context['page_index'], '</span>
1961
	</div>';
1962
}
1963
1964
?>