Passed
Pull Request — development (#3800)
by Spuds
05:33
created

template_quicktopic_above()   C

Complexity

Conditions 14
Paths 17

Size

Total Lines 77
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 14
eloc 33
nc 17
nop 0
dl 0
loc 77
rs 6.2666
c 1
b 0
f 1

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
/**
4
 * @package   ElkArte Forum
5
 * @copyright ElkArte Forum contributors
6
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
7
 *
8
 * This file contains code covered by:
9
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
10
 *
11
 * @version 2.0 dev
12
 *
13
 */
14
15
use ElkArte\MessageTopicIcons;
16
17
/**
18
 * Loads the template used to display boards
19
 */
20
function template_MessageIndex_init()
21
{
22
	theme()->getTemplates()->load('GenericBoards');
23
}
24
25
/**
26
 * Used to display sub-boards.
27
 */
28
function template_display_child_boards_above()
29
{
30
	global $context, $txt;
31
32
	echo '
33
	<header class="category_header">
34
		', $txt['parent_boards'], '
35
	</header>
36
	<section id="board_', $context['current_board'], '_childboards" class="forum_category">';
37
38
	template_list_boards($context['boards'], 'board_' . $context['current_board'] . '_children');
39
40
	echo '
41
	</section>';
42
}
43
44
/**
45
 * Header bar and extra details above topic listing
46
 *  - board description
47
 *  - who is viewing
48
 *  - sort container
49
 */
50
function template_topic_listing_above()
51
{
52
	global $context, $settings, $txt, $options;
53
54
	if ($context['no_topic_listing'])
55
	{
56
		return;
57
	}
58
59
	template_pagesection('normal_buttons');
60
61
	echo '
62
		<header id="description_board">
63
			<h2 class="category_header">', $context['name'], '</h2>
64
			<div class="generalinfo">';
65
66
	// Show the board description
67
	if (!empty($context['description']))
68
	{
69
		echo '
70
				<div id="boarddescription">
71
					', $context['description'], '
72
				</div>';
73
	}
74
75
	if (!empty($context['moderators']))
76
	{
77
		echo '
78
				<div class="moderators"><i class="icon icon-small i-user colorize-orange"></i>', count($context['moderators']) === 1 ? $txt['moderator'] : $txt['moderators'], ': ', implode(', ', $context['link_moderators']), '.</div>';
79
	}
80
81
	echo '
82
				<div id="topic_sorting" class="flow_flex" >
83
					<div id="whoisviewing">';
84
85
	// If we are showing who is viewing this topic, build it out
86
	if (!empty($settings['display_who_viewing']))
87
	{
88
		if ($settings['display_who_viewing'] == 1)
89
		{
90
			echo '<i class="icon icon-small i-users"></i>', count($context['view_members']), ' ', count($context['view_members']) === 1 ? $txt['who_member'] : $txt['members'];
91
		}
92
		else
93
		{
94
			echo '<i class="icon icon-small i-users"></i>', empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
95
		}
96
97
		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_board'];
98
	}
99
100
	// Sort topics mumbo-jumbo
101
	echo '
102
					</div>
103
					<ul id="sort_by" class="no_js">';
104
105
	$current_header = $context['topics_headers'][$context['sort_by']];
106
	echo '
107
						<li class="listlevel1 topic_sorting_row">', $txt['sort_by'], ': <a href="', $current_header['url'], '">', $txt[$context['sort_by']], '</a>
108
							<ul class="menulevel2" id="sortby">';
109
110
	foreach ($context['topics_headers'] as $key => $value)
111
	{
112
		echo '
113
								<li class="listlevel2 sort_by_item" id="sort_by_item_', $key, '">
114
									<a href="', $value['url'], '" class="linklevel2">', $txt[$key], ' ', $value['sort_dir_img'], '</a>
115
								</li>';
116
	}
117
118
	echo '
119
							</ul>
120
						</li>
121
						<li class="listlevel1 topic_sorting_row">
122
							<a class="sort topicicon i-sort', $context['sort_direction'], '" href="', $current_header['url'], '" title="', $context['sort_title'], '"></a>
123
						</li>';
124
125
	if (!empty($context['can_quick_mod']) && !empty($options['display_quick_mod']))
126
	{
127
		echo '
128
						<li class="listlevel1 quickmod_select_all">
129
							<label for="select_all" class="hide">', $txt['all'], '</label>
130
							<input type="checkbox" id="select_all" onclick="invertAll(this, document.getElementById(\'quickModForm\'), \'topics[]\');" />
131
						</li>';
132
	}
133
134
	echo '					
135
					</ul>
136
				</div>
137
			</div>
138
		</header>';
139
}
140
141
/**
142
 * The actual topic listing.
143
 */
144
function template_topic_listing()
145
{
146
	global $context, $options, $scripturl, $txt, $modSettings;
147
148
	if (!$context['no_topic_listing'])
149
	{
150
		// If this person can approve items, and we have some awaiting approval tell them.
151
		if (!empty($context['unapproved_posts_message']))
152
		{
153
			echo '
154
		<div class="warningbox">', $context['unapproved_posts_message'], '</div>';
155
		}
156
157
		// Quick Topic enabled ?
158
		template_quicktopic_above();
159
160
		// If Quick Moderation is enabled start the form.
161
		if (!empty($context['can_quick_mod']) && !empty($options['display_quick_mod']) && !empty($context['topics']))
162
		{
163
			echo '
164
	<form action="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], '" method="post" accept-charset="UTF-8" class="clear" name="quickModForm" id="quickModForm">';
165
		}
166
167
		echo '
168
		<main>
169
		<ul class="topic_listing" id="messageindex">';
170
171
		// No topics.... just say, "sorry bub".
172
		if (empty($context['topics']))
173
		{
174
			echo '
175
			<li class="basic_row">
176
				<div class="topic_info">
177
					<div class="topic_name">
178
						<h4>
179
							<strong>', $txt['topic_alert_none'], '</strong>
180
						</h4>
181
					</div>
182
				</div>
183
			</li>';
184
		}
185
186
		foreach ($context['topics'] as $topic)
187
		{
188
			// Is this topic pending approval, or does it have any posts pending approval?
189
			if ($context['can_approve_posts'] && $topic['unapproved_posts'])
190
			{
191
				$color_class = $topic['approved'] ? 'approve_row' : 'approvetopic_row';
192
			}
193
			// We start with locked and sticky topics.
194
			elseif ($topic['is_sticky'] && $topic['is_locked'])
195
			{
196
				$color_class = 'locked_row sticky_row';
197
			}
198
			// Sticky topics should get a different color, too.
199
			elseif ($topic['is_sticky'])
200
			{
201
				$color_class = 'sticky_row';
202
			}
203
			// Locked topics get special treatment as well.
204
			elseif ($topic['is_locked'])
205
			{
206
				$color_class = 'locked_row';
207
			}
208
			// Last, but not least: regular topics.
209
			else
210
			{
211
				$color_class = 'basic_row';
212
			}
213
214
			// First up the message icon
215
			echo '
216
			<li class="', $color_class, '">
217
				<div class="topic_icons', empty($modSettings['messageIcons_enable']) ? ' topicicon i-' . $topic['first_post']['icon'] : '', '">';
218
219
			if (!empty($modSettings['messageIcons_enable']))
220
			{
221
				echo '
222
					<img src="', $topic['first_post']['icon_url'], '" alt="" />';
223
			}
224
225
			echo '
226
					', $topic['is_posted_in'] ? '<span class="fred topicicon i-profile"></span>' : '', '
227
				</div>';
228
229
			// The subject/poster section
230
			echo '
231
				<div class="topic_info">
232
233
					<div class="topic_name" ', (empty($topic['quick_mod']['modify']) ? '' : 'id="topic_' . $topic['first_post']['id'] . '"  ondblclick="oQuickModifyTopic.modify_topic(\'' . $topic['id'] . "', '" . $topic['first_post']['id'] . '\');"'), '>
234
						<h4>';
235
236
			// Is this topic new? (assuming they are logged in!)
237
			if ($topic['new'] && $context['user']['is_logged'])
238
			{
239
				echo '
240
							<a class="new_posts" href="', $topic['new_href'], '" id="newicon' . $topic['first_post']['id'] . '">' . $txt['new'] . '</a>';
241
			}
242
243
			// Is this an unapproved topic, and they can approve it?
244
			if ($context['can_approve_posts'] && !$topic['approved'])
245
			{
246
				echo '
247
							<span class="require_approval">' . $txt['awaiting_approval'] . '</span>';
248
			}
249
250
			echo '
251
							', $topic['is_sticky'] ? '<strong>' : '', '<span class="preview" title="', $topic['default_preview'], '"><span id="msg_' . $topic['first_post']['id'] . '">', $topic['first_post']['link'], '</span></span>', $topic['is_sticky'] ? '</strong>' : '', '
252
						</h4>
253
					</div>
254
					<div class="topic_starter">
255
						', sprintf($txt['topic_started_by'], $topic['first_post']['member']['link']), empty($topic['pages']) ? '' : '
256
						<ul class="small_pagelinks" id="pages' . $topic['first_post']['id'] . '">' . $topic['pages'] . '</ul>', '
257
					</div>
258
				</div>';
259
260
			// The last poster info, avatar, when
261
			echo '
262
				<div class="topic_latest">';
263
264
			if (!empty($topic['last_post']['member']['avatar']))
265
			{
266
				echo '
267
					<span class="board_avatar">
268
						<a href="', $topic['last_post']['member']['href'], '">
269
							<img class="avatar" src="', $topic['last_post']['member']['avatar']['href'], '" alt="', $topic['last_post']['member']['name'], '" loading="lazy" />
270
						</a>
271
					</span>';
272
			}
273
			else
274
			{
275
				echo '
276
					<span class="board_avatar">
277
						<a href="#"></a>
278
					</span>';
279
			}
280
281
			echo '
282
					<a class="topicicon i-last_post" href="', $topic['last_post']['href'], '" title="', $txt['last_post'], '"></a>
283
					', $topic['last_post']['html_time'], '<br />
284
					', $txt['by'], ' ', $topic['last_post']['member']['link'], '
285
				</div>';
286
287
			// The stats section
288
			echo '
289
				<div class="topic_stats">
290
					', $topic['replies'], ' ', $txt['replies'], '<br />
291
					', $topic['views'], ' ', $txt['views'];
292
293
			// Show likes?
294
			if (!empty($modSettings['likes_enabled']))
295
			{
296
				echo '
297
					<br />
298
						', $topic['likes'], ' ', $txt['likes'];
299
			}
300
301
			echo '
302
				</div>';
303
304
			// Show the quick moderation options?
305
			if (!empty($context['can_quick_mod']) && !empty($options['display_quick_mod']))
306
			{
307
				echo '
308
				<div class="topic_moderation">
309
					<input type="checkbox" name="topics[]" aria-label="check ', $topic['id'], '" value="', $topic['id'], '" />
310
				</div>';
311
			}
312
313
			echo '
314
			</li>';
315
		}
316
317
		echo '
318
		</ul>
319
		</main>';
320
321
		// Show the moderation buttons
322
		if (!empty($context['can_quick_mod']) && !empty($options['display_quick_mod']) && !empty($context['topics']))
323
		{
324
			echo '
325
			<div id="moderationbuttons">';
326
327
			template_button_strip($context['mod_buttons'], '', ['id' => 'moderationbuttons_strip']);
328
329
			// Show a list of boards they can move the topic to.
330
			if ($context['can_move'])
331
			{
332
				echo '
333
				<span id="quick_mod_jump_to">&nbsp;</span>';
334
			}
335
336
			echo '
337
			</div>
338
			<input type="hidden" name="qaction" id="qaction" value="na" />
339
			<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
340
		</form>';
341
		}
342
	}
343
}
344
345
/**
346
 * The lower icons and jump to.
347
 */
348
function template_topic_listing_below()
349
{
350
	global $context, $txt, $options;
351
352
	if ($context['no_topic_listing'])
353
	{
354
		return;
355
	}
356
357
	template_pagesection('normal_buttons');
358
359
	// Show breadcrumbs at the bottom too.
360
	theme_breadcrumbs();
361
362
	echo '
363
	<footer id="topic_icons" class="description">
364
		<div class="qaction_row" id="message_index_jump_to">&nbsp;</div>';
365
366
	if (!$context['no_topic_listing'])
367
	{
368
		template_basicicons_legend();
369
	}
370
371
	if (!empty($context['can_quick_mod']) && !empty($options['display_quick_mod']) && !empty($context['topics']))
372
	{
373
		theme()->addInlineJavascript('
374
			let oInTopicListModeration = new InTopicListModeration({
375
				aQmActions: ["restore", "markread", "merge", "sticky", "approve", "lock", "remove", "move"],
376
				sButtonStrip: "moderationbuttons",
377
				sButtonStripDisplay: "moderationbuttons_strip",
378
				bUseImageButton: false,
379
				bHideStrip: true,
380
				sFormId: "quickModForm",
381
				
382
				bCanRemove: ' . (empty($context['allow_qm']['can_remove']) ? 'false' : 'true') . ',
383
				aActionRemove: [' . implode(',', $context['allow_qm']['can_remove']) . '],
384
				sRemoveButtonLabel: "' . $txt['remove_topic'] . '",
385
				sRemoveButtonImage: "i-delete",
386
				sRemoveButtonConfirm: "' . $txt['quickmod_confirm'] . '",
387
				
388
				bCanMove: ' . (empty($context['allow_qm']['can_move']) ? 'false' : 'true') . ',
389
				aActionMove: [' . implode(',', $context['allow_qm']['can_move']) . '],
390
				sMoveButtonLabel: "' . $txt['move_topic'] . '",
391
				sMoveButtonImage: "i-move",
392
				sMoveButtonConfirm: "' . $txt['quickmod_confirm'] . '",
393
394
				bCanLock: ' . ($context['allow_qm']['can_lock'] ? 'true' : 'false') . ',
395
				aActionLock: [' . implode(',', $context['allow_qm']['can_lock']) . '],
396
				sLockButtonLabel: "' . $txt['set_lock'] . '",
397
				sLockButtonImage: "i-lock",
398
				
399
				bCanApprove: ' . (empty($context['allow_qm']['can_approve']) ? 'false' : 'true') . ',
400
				aActionApprove: [' . implode(',', $context['allow_qm']['can_approve']) . '],
401
				sApproveButtonLabel: "' . $txt['approve'] . '",
402
				sApproveButtonImage: "i-check",
403
				sApproveButtonConfirm: "' . $txt['quickmod_confirm'] . '",				
404
				
405
				bCanSticky: ' . ($context['can_sticky'] ? 'true' : 'false') . ',
406
				sStickyButtonLabel: "' . $txt['set_sticky'] . '",
407
				sStickyButtonImage: "i-pin",
408
				
409
				bCanMerge: ' . ($context['can_merge'] ? 'true' : 'false') . ',
410
				sMergeButtonLabel: "' . $txt['merge'] . '",
411
				sMergeButtonImage: "i-merge",
412
				
413
				bCanMarkread: ' . ($context['can_markread'] ? 'true' : 'false') . ',
414
				sMarkreadButtonLabel: "' . $txt['mark_read_short'] . '",
415
				sMarkreadButtonImage: "i-view",
416
				sMarkreadButtonConfirm: "' . $txt['mark_these_as_read_confirm'] . '",				
417
418
				bCanRestore: ' . ($context['can_restore'] ? 'true' : 'false') . ',
419
				sRestoreButtonLabel: "' . $txt['restore_topic'] . '",
420
				sRestoreButtonImage: "i-recycle",
421
				sRestoreButtonConfirm: "' . $txt['quickmod_confirm'] . '",
422
			});', true);
423
	}
424
425
	echo '
426
			<script>';
427
428
	if (!empty($context['using_relative_time']))
429
	{
430
		echo '
431
			document.querySelectorAll(".topic_latest").forEach(element => element.classList.add("relative"));';
432
	}
433
434
	if (!empty($context['can_quick_mod']) && !empty($options['display_quick_mod']) && !empty($context['topics']) && $context['can_move'])
435
	{
436
		echo '
437
			aJumpTo[aJumpTo.length] = new JumpTo({
438
				sContainerId: "quick_mod_jump_to",
439
				sJumpToTemplate: "%dropdown_list%",
440
				iCurBoardId: ', $context['current_board'], ',
441
				iCurBoardChildLevel: ', $context['jump_to']['child_level'], ',
442
				sCurBoardName: "', $context['jump_to']['board_name'], '",
443
				sBoardChildLevelIndicator: "&#8195;",
444
				sBoardPrefix: "&#10148;",
445
				sCatPrefix: "",
446
				sCatClass: "jump_to_header",
447
				sClassName: "qaction",
448
				bNoRedirect: true,
449
				sCustomName: "move_to",
450
				bOnLoad: true
451
			});';
452
	}
453
454
	echo '
455
			aJumpTo[aJumpTo.length] = new JumpTo({
456
				sContainerId: "message_index_jump_to",
457
				sJumpToTemplate: "<label class=\"smalltext\" for=\"%select_id%\">', $context['jump_to']['label'], ':<" + "/label> %dropdown_list%",
458
				iCurBoardId: ', $context['current_board'], ',
459
				iCurBoardChildLevel: ', $context['jump_to']['child_level'], ',
460
				sCurBoardName: "', $context['jump_to']['board_name'], '",
461
				sBoardChildLevelIndicator: "&#8195;",
462
				sBoardPrefix: "&#10148;",
463
				sCatPrefix: "",
464
				sCatClass: "jump_to_header",
465
				bOnLoad: true,
466
				sGoButtonLabel: "', $txt['quick_mod_go'], '"
467
			});
468
		</script>
469
	</footer>';
470
471
	// Javascript for inline editing, double-clicking to edit subject
472
	theme()->addInlineJavascript('
473
		let oQuickModifyTopic = new QuickModifyTopic({
474
			aHidePrefixes: Array("pages", "newicon"),
475
			bMouseOnDiv: false
476
		});', true
477
	);
478
479
	// Message preview when enabled
480
	if (!empty($context['message_index_preview']))
481
	{
482
		theme()->addInlineJavascript('
483
		if ((!is_mobile && !is_touch) || use_click_menu) {
484
			isFunctionLoaded("SiteTooltip").then((available) => {
485
				if (available) {
486
					let tooltip = new SiteTooltip();
487
					tooltip.create(".preview");
488
				}
489
			});
490
		};', true
491
		);
492
	}
493
}
494
495
/**
496
 * This is quick topic area above the topic listing, shown when the subject input gains focus
497
 */
498
function template_quicktopic_above()
499
{
500
	global $context, $options, $txt, $modSettings, $settings;
501
502
	// Using  quick topic, and you can start a new topic?
503
	if ($context['can_post_new'] && !empty($options['display_quick_reply']) && !$context['user']['is_guest'])
504
	{
505
		echo '
506
		<form  id="postmodify" action="', getUrl('action', ['action' => 'post2', 'board' => $context['current_board']]), '" method="post" accept-charset="UTF-8" name="postmodify" onsubmit="submitonce(this);', (empty($modSettings['mentions_enabled']) ? '' : "revalidateMentions('postmodify', '" . $context['post_box_name'] . "');"), '">
507
		<ul id="quicktopic" class="topic_listing" >
508
			<li class="basic_row">
509
				<div class="topic_icons', empty($modSettings['messageIcons_enable']) ? ' topicicon i-xx' : '', '">';
510
511
		if (!empty($modSettings['messageIcons_enable']))
512
		{
513
			$icon_sources = new MessageTopicIcons(!empty($modSettings['messageIconChecks_enable']), $settings['theme_dir']);
514
			echo '
515
					<img src="', $icon_sources->getIconURL(-1), '" alt="" />';
516
		}
517
518
		echo '
519
				</div>
520
				<div id="quicktopic_title">', $txt['start_new_topic'], '</div>
521
				<input id="quicktopic_subject" type="text" name="subject" tabindex="', $context['tabindex']++, '" size="70" maxlength="80" class="input_text"', ' placeholder="', $txt['subject'], '" required="required" />
522
				<div id="quicktopicbox" class="hide">
523
					<div class="post_wrapper', empty($options['hide_poster_area']) ? '' : '2', '">';
524
525
		if (empty($options['hide_poster_area']))
526
		{
527
			echo '
528
						<ul class="poster no_js">', template_build_poster_div($context['thisMember'], false), '</ul>';
529
		}
530
531
		echo '
532
						<div class="postarea', empty($options['hide_poster_area']) ? '' : '2', '">';
533
534
		// Is visual verification enabled?
535
		if (!empty($context['require_verification']))
536
		{
537
			template_verification_controls($context['visual_verification_id'], '<strong>' . $txt['verification'] . ':</strong>', '<br />');
538
		}
539
540
		template_control_richedit($context['post_box_name']);
541
542
		echo '
543
							', $context['becomes_approved'] ? '' : '<p class="infobox">' . $txt['wait_for_approval'] . '</p>';
544
545
		echo '
546
							<input type="hidden" name="topic" value="0" />
547
							<input type="hidden" name="icon" value="xx" />
548
							<input type="hidden" name="from_qr" value="1" />
549
							<input type="hidden" name="board" value="', $context['current_board'], '" />
550
							<input type="hidden" name="goback" value="', empty($options['return_to_post']) ? '0' : '1', '" />
551
							<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
552
							<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
553
							<div id="post_confirm_buttons" class="submitbutton">',
554
								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...
Bug introduced by
Are you sure template_control_richedi...ntext['post_box_name']) of type void can be used in echo? ( Ignorable by Annotation )

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

554
								/** @scrutinizer ignore-type */ template_control_richedit_buttons($context['post_box_name']), '
Loading history...
555
							</div>';
556
557
		// Show the draft last saved on area
558
		if (!empty($context['drafts_save']))
559
		{
560
			echo '
561
						<div class="draftautosave">
562
							<span id="throbber" class="hide"><i class="icon i-oval"></i>&nbsp;</span>
563
							<span id="draft_lastautosave"></span>
564
						</div>';
565
		}
566
567
		echo '
568
					</div>
569
				</div>
570
			</li>
571
		</ul>
572
		</form>';
573
574
		quickTopicToggle();
575
	}
576
}
577
578
/**
579
 * Adds needed JS to show the quick topic area
580
 */
581
function quickTopicToggle()
582
{
583
	theme()->addInlineJavascript('
584
		document.getElementById("quicktopic_subject").onfocus = function() {
585
			let quicktopicbox = document.getElementById("quicktopicbox");
586
			let isVisible = quicktopicbox && (quicktopicbox.style.display !== "none" && quicktopicbox.offsetHeight !== 0);
587
			
588
			if (!isVisible)
589
			{
590
				quicktopicbox.slideDown();
591
			}
592
		};', true);
593
}
594