Passed
Push — release-2.1 ( b72c2e...2f6e03 )
by Jon
05:51 queued 10s
created

template_replies()   F

Complexity

Conditions 32
Paths 144

Size

Total Lines 171
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 32
eloc 70
c 1
b 0
f 0
nc 144
nop 0
dl 0
loc 171
rs 3.8

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 2021 Simple Machines and individual contributors
8
 * @license https://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 RC4
11
 */
12
13
/**
14
 * Template for showing recent posts
15
 */
16
function template_recent()
17
{
18
	global $context, $txt, $scripturl;
19
20
	echo '
21
	<div id="recent" class="main_section">
22
		<div class="cat_bar">
23
			<h3 class="catbg">
24
				<span class="xx"></span>', $txt['recent_posts'], '
25
			</h3>
26
		</div>
27
		<div class="pagesection">', $context['page_index'], '</div>';
28
29
	if (empty($context['posts']))
30
		echo '
31
		<div class="windowbg">', $txt['no_messages'], '</div>';
32
33
	foreach ($context['posts'] as $post)
34
	{
35
		echo '
36
		<div class="', $post['css_class'], '">
37
			<div class="counter">', $post['counter'], '</div>
38
			<div class="topic_details">
39
				<h5>', $post['board']['link'], ' / ', $post['link'], '</h5>
40
				<span class="smalltext">', $txt['last_poster'], ' <strong>', $post['poster']['link'], ' </strong> - ', $post['time'], '</span>
41
			</div>
42
			<div class="list_posts">', $post['message'], '</div>';
43
44
		// Post options
45
		template_quickbuttons($post['quickbuttons'], 'recent');
46
47
		echo '
48
		</div><!-- $post[css_class] -->';
49
	}
50
51
	echo '
52
		<div class="pagesection">', $context['page_index'], '</div>
53
	</div><!-- #recent -->';
54
}
55
56
/**
57
 * Template for showing unread posts
58
 */
59
function template_unread()
60
{
61
	global $context, $settings, $txt, $scripturl, $modSettings;
62
63
	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
64
	if (!empty($context['recent_buttons']))
65
		echo '
66
	<div id="mobile_action" class="popup_container">
67
		<div class="popup_window description">
68
			<div class="popup_heading">
69
				', $txt['mobile_action'], '
70
				<a href="javascript:void(0);" class="main_icons hide_popup"></a>
71
			</div>
72
			', template_button_strip($context['recent_buttons']), '
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_button_strip($context['recent_buttons']) 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...
73
		</div>
74
	</div>';
75
76
	echo '
77
	<div id="recent" class="main_content">';
78
79
	if ($context['showCheckboxes'])
80
		echo '
81
		<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm">
82
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
83
			<input type="hidden" name="qaction" value="markread">
84
			<input type="hidden" name="redirect_url" value="action=unread', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '">';
85
86
	if (!empty($context['topics']))
87
	{
88
		echo '
89
			<div class="pagesection">
90
				', $context['menu_separator'], '
91
				<div class="pagelinks floatleft">
92
					<a href="#bot" class="button">', $txt['go_down'], '</a>
93
					', $context['page_index'], '
94
				</div>
95
				', !empty($context['recent_buttons']) ? template_button_strip($context['recent_buttons'], 'right') : '';
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_button_strip($c...ent_buttons'], 'right') 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...
96
97
		// Mobile action (top)
98
		if (!empty($context['recent_buttons']))
99
			echo '
100
				<div class="mobile_buttons floatright">
101
					<a class="button mobile_act">', $txt['mobile_action'], '</a>
102
				</div>';
103
104
		echo '
105
			</div>';
106
107
		echo '
108
			<div id="unread">
109
				<div id="topic_header" class="title_bar">
110
					<div class="board_icon"></div>
111
					<div class="info">
112
						<a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['subject'], $context['sort_by'] == 'subject' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
113
					</div>
114
					<div class="board_stats centertext">
115
						<a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=replies', $context['sort_by'] == 'replies' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['replies'], $context['sort_by'] == 'replies' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
116
					</div>
117
					<div class="lastpost">
118
						<a href="', $scripturl, '?action=unread', $context['showing_all_topics'] ? ';all' : '', $context['querystring_board_limits'], ';sort=last_post', $context['sort_by'] == 'last_post' && $context['sort_direction'] == 'up' ? ';desc' : '', '">', $txt['last_post'], $context['sort_by'] == 'last_post' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
119
					</div>';
120
121
		// Show a "select all" box for quick moderation?
122
		if ($context['showCheckboxes'])
123
			echo '
124
					<div class="moderation">
125
						<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
126
					</div>';
127
128
		echo '
129
				</div><!-- #topic_header -->
130
				<div id="topic_container">';
131
132
		foreach ($context['topics'] as $topic)
133
		{
134
			echo '
135
					<div class="', $topic['css_class'], '">
136
						<div class="board_icon">
137
							<img src="', $topic['first_post']['icon_url'], '" alt="">
138
							', $topic['is_posted_in'] ? '<img class="posted" src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="">' : '', '
139
						</div>
140
						<div class="info">';
141
142
			// Now we handle the icons
143
			echo '
144
							<div class="icons floatright">';
145
146
			if ($topic['is_locked'])
147
				echo '
148
								<span class="main_icons lock"></span>';
149
150
			if ($topic['is_sticky'])
151
				echo '
152
								<span class="main_icons sticky"></span>';
153
154
			if ($topic['is_poll'])
155
				echo '
156
								<span class="main_icons poll"></span>';
157
158
			echo '
159
							</div>';
160
161
			echo '
162
							<div class="recent_title">
163
								<a href="', $topic['new_href'], '" id="newicon', $topic['first_post']['id'], '" class="new_posts">' . $txt['new'] . '</a>
164
								', $topic['is_sticky'] ? '<strong>' : '', '<span class="preview" title="', $topic[(empty($modSettings['message_index_preview_first']) ? 'last_post' : 'first_post')]['preview'], '"><span id="msg_' . $topic['first_post']['id'] . '">', $topic['first_post']['link'], '</span></span>', $topic['is_sticky'] ? '</strong>' : '', '
165
							</div>
166
							<p class="floatleft">
167
								', $topic['first_post']['started_by'], '
168
							</p>
169
							', !empty($topic['pages']) ? '<span id="pages' . $topic['first_post']['id'] . '" class="topic_pages">' . $topic['pages'] . '</span>' : '', '
170
						</div><!-- .info -->
171
						<div class="board_stats centertext">
172
							<p>
173
								', $topic['replies'], ' ', $txt['replies'], '
174
								<br>
175
								', $topic['views'], ' ', $txt['views'], '
176
							</p>
177
						</div>
178
						<div class="lastpost">
179
							', sprintf($txt['last_post_topic'], '<a href="' . $topic['last_post']['href'] . '">' . $topic['last_post']['time'] . '</a>', $topic['last_post']['member']['link']), '
180
						</div>';
181
182
			if ($context['showCheckboxes'])
183
				echo '
184
						<div class="moderation">
185
							<input type="checkbox" name="topics[]" value="', $topic['id'], '">
186
						</div>';
187
188
			echo '
189
					</div><!-- $topic[css_class] -->';
190
		}
191
192
		if (empty($context['topics']))
193
			echo '
194
					<div style="display: none;"></div>';
195
196
		echo '
197
				</div><!-- #topic_container -->
198
			</div><!-- #unread -->';
199
200
		echo '
201
			<div class="pagesection">
202
				', !empty($context['recent_buttons']) ? template_button_strip($context['recent_buttons'], 'right') : '', '
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_button_strip($c...ent_buttons'], 'right') 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...
203
				', $context['menu_separator'], '
204
				<div class="pagelinks floatleft">
205
					<a href="#recent" class="button">', $txt['go_up'], '</a>
206
					', $context['page_index'], '
207
				</div>';
208
209
		// Mobile action (bottom)
210
		if (!empty($context['recent_buttons']))
211
		echo '
212
				<div class="mobile_buttons floatright">
213
					<a class="button mobile_act">', $txt['mobile_action'], '</a>
214
				</div>';
215
216
		echo '
217
			</div>';
218
	}
219
	else
220
		echo '
221
			<div class="cat_bar">
222
				<h3 class="catbg centertext">
223
					', $context['showing_all_topics'] ? $txt['topic_alert_none'] : sprintf($txt['unread_topics_visit_none'], $scripturl), '
224
				</h3>
225
			</div>';
226
227
	if ($context['showCheckboxes'])
228
		echo '
229
		</form>';
230
231
	echo '
232
	</div><!-- #recent -->';
233
234
	if (empty($context['no_topic_listing']))
235
		template_topic_legend();
236
}
237
238
/**
239
 * Template for showing unread replies (eg new replies to topics you've posted in)
240
 */
241
function template_replies()
242
{
243
	global $context, $settings, $txt, $scripturl, $modSettings;
244
245
	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
246
	if (!empty($context['recent_buttons']))
247
		echo '
248
	<div id="mobile_action" class="popup_container">
249
		<div class="popup_window description">
250
			<div class="popup_heading">
251
				', $txt['mobile_action'], '
252
				<a href="javascript:void(0);" class="main_icons hide_popup"></a>
253
			</div>
254
			', template_button_strip($context['recent_buttons']), '
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_button_strip($context['recent_buttons']) 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...
255
		</div>
256
	</div>';
257
258
	echo '
259
	<div id="recent">';
260
261
	if ($context['showCheckboxes'])
262
		echo '
263
		<form action="', $scripturl, '?action=quickmod" method="post" accept-charset="', $context['character_set'], '" name="quickModForm" id="quickModForm">
264
			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
265
			<input type="hidden" name="qaction" value="markread">
266
			<input type="hidden" name="redirect_url" value="action=unreadreplies', (!empty($context['showing_all_topics']) ? ';all' : ''), $context['querystring_board_limits'], '">';
267
268
	if (!empty($context['topics']))
269
	{
270
		echo '
271
			<div class="pagesection">
272
				', $context['menu_separator'], '
273
				<div class="pagelinks floatleft">
274
					<a href="#bot" class="button">', $txt['go_down'], '</a>
275
					', $context['page_index'], '
276
				</div>
277
				', !empty($context['recent_buttons']) ? template_button_strip($context['recent_buttons'], 'right') : '';
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_button_strip($c...ent_buttons'], 'right') 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...
278
279
		// Mobile action (top)
280
		if (!empty($context['recent_buttons']))
281
			echo '
282
				<div class="mobile_buttons floatright">
283
					<a class="button mobile_act">', $txt['mobile_action'], '</a>
284
				</div>';
285
286
		echo '
287
			</div>';
288
289
		echo '
290
			<div id="unreadreplies">
291
				<div id="topic_header" class="title_bar">
292
					<div class="board_icon"></div>
293
					<div class="info">
294
						<a href="', $scripturl, '?action=unreadreplies', $context['querystring_board_limits'], ';sort=subject', $context['sort_by'] === 'subject' && $context['sort_direction'] === 'up' ? ';desc' : '', '">', $txt['subject'], $context['sort_by'] === 'subject' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
295
					</div>
296
					<div class="board_stats centertext">
297
						<a href="', $scripturl, '?action=unreadreplies', $context['querystring_board_limits'], ';sort=replies', $context['sort_by'] === 'replies' && $context['sort_direction'] === 'up' ? ';desc' : '', '">', $txt['replies'], $context['sort_by'] === 'replies' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
298
					</div>
299
					<div class="lastpost">
300
						<a href="', $scripturl, '?action=unreadreplies', $context['querystring_board_limits'], ';sort=last_post', $context['sort_by'] === 'last_post' && $context['sort_direction'] === 'up' ? ';desc' : '', '">', $txt['last_post'], $context['sort_by'] === 'last_post' ? ' <span class="main_icons sort_' . $context['sort_direction'] . '"></span>' : '', '</a>
301
					</div>';
302
303
		// Show a "select all" box for quick moderation?
304
		if ($context['showCheckboxes'])
305
			echo '
306
					<div class="moderation">
307
						<input type="checkbox" onclick="invertAll(this, this.form, \'topics[]\');">
308
					</div>';
309
310
		echo '
311
				</div><!-- #topic_header -->
312
				<div id="topic_container">';
313
314
		foreach ($context['topics'] as $topic)
315
		{
316
			echo '
317
					<div class="', $topic['css_class'], '">
318
						<div class="board_icon">
319
							<img src="', $topic['first_post']['icon_url'], '" alt="">
320
							', $topic['is_posted_in'] ? '<img class="posted" src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="">' : '', '
321
						</div>
322
						<div class="info">';
323
324
			// Now we handle the icons
325
			echo '
326
							<div class="icons floatright">';
327
328
			if ($topic['is_locked'])
329
				echo '
330
								<span class="main_icons lock"></span>';
331
332
			if ($topic['is_sticky'])
333
				echo '
334
								<span class="main_icons sticky"></span>';
335
336
			if ($topic['is_poll'])
337
				echo '
338
								<span class="main_icons poll"></span>';
339
340
			echo '
341
							</div>';
342
343
			echo '
344
							<div class="recent_title">
345
								<a href="', $topic['new_href'], '" id="newicon', $topic['first_post']['id'], '" class="new_posts">' . $txt['new'] . '</a>
346
								', $topic['is_sticky'] ? '<strong>' : '', '<span title="', $topic[(empty($modSettings['message_index_preview_first']) ? 'last_post' : 'first_post')]['preview'], '"><span id="msg_' . $topic['first_post']['id'] . '">', $topic['first_post']['link'], '</span>', $topic['is_sticky'] ? '</strong>' : '', '
347
							</div>
348
							<p class="floatleft">
349
								', $topic['first_post']['started_by'], '
350
							</p>
351
							', !empty($topic['pages']) ? '<span id="pages' . $topic['first_post']['id'] . '" class="topic_pages">' . $topic['pages'] . '</span>' : '', '
352
						</div><!-- .info -->
353
						<div class="board_stats centertext">
354
							<p>
355
								', $topic['replies'], ' ', $txt['replies'], '
356
								<br>
357
								', $topic['views'], ' ', $txt['views'], '
358
							</p>
359
						</div>
360
						<div class="lastpost">
361
							', sprintf($txt['last_post_topic'], '<a href="' . $topic['last_post']['href'] . '">' . $topic['last_post']['time'] . '</a>', $topic['last_post']['member']['link']), '
362
						</div>';
363
364
			if ($context['showCheckboxes'])
365
				echo '
366
						<div class="moderation">
367
							<input type="checkbox" name="topics[]" value="', $topic['id'], '">
368
						</div>';
369
370
			echo '
371
					</div><!-- $topic[css_class] -->';
372
		}
373
374
		echo '
375
				</div><!-- #topic_container -->
376
			</div><!-- #unreadreplies -->
377
			<div class="pagesection">
378
				', !empty($context['recent_buttons']) ? template_button_strip($context['recent_buttons'], 'right') : '', '
0 ignored issues
show
Bug introduced by
Are you sure the usage of template_button_strip($c...ent_buttons'], 'right') 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...
379
				', $context['menu_separator'], '
380
				<div class="pagelinks floatleft">
381
					<a href="#recent" class="button">', $txt['go_up'], '</a>
382
					', $context['page_index'], '
383
				</div>';
384
385
		// Mobile action (bottom)
386
		if (!empty($context['recent_buttons']))
387
			echo '
388
				<div class="mobile_buttons floatright">
389
					<a class="button mobile_act">', $txt['mobile_action'], '</a>
390
				</div>';
391
392
		echo '
393
			</div>';
394
	}
395
	else
396
		echo '
397
			<div class="cat_bar">
398
				<h3 class="catbg centertext">
399
					', $context['showing_all_topics'] ? $txt['topic_alert_none'] : $txt['updated_topics_visit_none'], '
400
				</h3>
401
			</div>';
402
403
	if ($context['showCheckboxes'])
404
		echo '
405
		</form>';
406
407
	echo '
408
	</div><!-- #recent -->';
409
410
	if (empty($context['no_topic_listing']))
411
		template_topic_legend();
412
}
413
414
?>