Completed
Pull Request — release-2.1 (#4272)
by Mert
08:21
created
Themes/default/ManageNews.template.php 1 patch
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -18,9 +18,10 @@  discard block
 block discarded – undo
18 18
 	global $context, $txt, $scripturl;
19 19
 
20 20
 	// Are we done sending the newsletter?
21
-	if (!empty($context['newsletter_sent']))
22
-		echo '
21
+	if (!empty($context['newsletter_sent'])) {
22
+			echo '
23 23
 	<div class="infobox">', $txt['admin_news_newsletter_' . $context['newsletter_sent']], '</div>';
24
+	}
24 25
 
25 26
 	echo '
26 27
 	<div id="admincenter">
@@ -39,9 +40,10 @@  discard block
 block discarded – undo
39 40
 					</dt>
40 41
 					<dd>';
41 42
 
42
-	foreach ($context['groups'] as $group)
43
-				echo '
43
+	foreach ($context['groups'] as $group) {
44
+					echo '
44 45
 						<label for="groups_', $group['id'], '"><input type="checkbox" name="groups[', $group['id'], ']" id="groups_', $group['id'], '" value="', $group['id'], '" checked> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br>';
46
+	}
45 47
 
46 48
 	echo '
47 49
 						<br>
@@ -82,9 +84,10 @@  discard block
 block discarded – undo
82 84
 						</dt>
83 85
 						<dd>';
84 86
 
85
-	foreach ($context['groups'] as $group)
86
-				echo '
87
+	foreach ($context['groups'] as $group) {
88
+					echo '
87 89
 							<label for="exclude_groups_', $group['id'], '"><input type="checkbox" name="exclude_groups[', $group['id'], ']" id="exclude_groups_', $group['id'], '" value="', $group['id'], '"> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em><br>';
90
+	}
88 91
 
89 92
 	echo '
90 93
 							<br>
@@ -228,9 +231,10 @@  discard block
 block discarded – undo
228 231
 				<div id="bbcBox_message"></div>';
229 232
 
230 233
 	// What about smileys?
231
-	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup']))
232
-		echo '
234
+	if (!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) {
235
+			echo '
233 236
 				<div id="smileyBox_message"></div>';
237
+	}
234 238
 
235 239
 	// Show BBC buttons, smileys and textbox.
236 240
 	echo '
@@ -251,9 +255,10 @@  discard block
 block discarded – undo
251 255
 			<input type="hidden" name="email_force" value="', $context['email_force'], '">
252 256
 			<input type="hidden" name="total_emails" value="', $context['total_emails'], '">';
253 257
 
254
-	foreach ($context['recipients'] as $key => $values)
255
-		echo '
258
+	foreach ($context['recipients'] as $key => $values) {
259
+			echo '
256 260
 			<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '">';
261
+	}
257 262
 
258 263
 	echo '
259 264
 		<script>';
@@ -408,9 +413,10 @@  discard block
 block discarded – undo
408 413
 				<input type="hidden" name="parse_html" value="', $context['parse_html'], '">';
409 414
 
410 415
 	// All the things we must remember!
411
-	foreach ($context['recipients'] as $key => $values)
412
-		echo '
416
+	foreach ($context['recipients'] as $key => $values) {
417
+			echo '
413 418
 				<input type="hidden" name="', $key, '" value="', implode(($key == 'emails' ? ';' : ','), $values), '">';
419
+	}
414 420
 
415 421
 	echo '
416 422
 			</div>
@@ -443,9 +449,10 @@  discard block
 block discarded – undo
443 449
 {
444 450
 	global $context, $txt;
445 451
 
446
-	if (!empty($context['saved_successful']))
447
-		echo '
452
+	if (!empty($context['saved_successful'])) {
453
+			echo '
448 454
 					<div class="infobox">', $txt['settings_saved'], '</div>';
455
+	}
449 456
 
450 457
 	template_show_list('news_lists');
451 458
 }
Please login to merge, or discard this patch.
Themes/default/ManageMembers.template.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 				</thead>
149 149
 				<tbody>';
150 150
 
151
-			foreach ($context['membergroups'] as $membergroup)
152
-				echo '
151
+			foreach ($context['membergroups'] as $membergroup) {
152
+							echo '
153 153
 					<tr class="windowbg">
154 154
 						<td>', $membergroup['name'], '</td>
155 155
 						<td class="centercol">
@@ -159,6 +159,7 @@  discard block
 block discarded – undo
159 159
 							', $membergroup['can_be_additional'] ? '<input type="checkbox" name="membergroups[2][]" value="' . $membergroup['id'] . '" checked>' : '', '
160 160
 						</td>
161 161
 					</tr>';
162
+			}
162 163
 
163 164
 			echo '
164 165
 					<tr class="windowbg">
@@ -185,8 +186,8 @@  discard block
 block discarded – undo
185 186
 				</thead>
186 187
 				<tbody>';
187 188
 
188
-			foreach ($context['postgroups'] as $postgroup)
189
-				echo '
189
+			foreach ($context['postgroups'] as $postgroup) {
190
+							echo '
190 191
 					<tr class="windowbg">
191 192
 						<td>
192 193
 							', $postgroup['name'], '
@@ -195,6 +196,7 @@  discard block
 block discarded – undo
195 196
 							<input type="checkbox" name="postgroups[]" value="', $postgroup['id'], '" checked>
196 197
 						</td>
197 198
 					</tr>';
199
+			}
198 200
 
199 201
 			echo '
200 202
 					<tr class="windowbg">
Please login to merge, or discard this patch.
Themes/default/ReportedContent.template.php 1 patch
Braces   +51 added lines, -34 removed lines patch added patch discarded remove patch
@@ -54,8 +54,9 @@  discard block
 block discarded – undo
54 54
 
55 55
 		// Prepare the comments...
56 56
 		$comments = array();
57
-		foreach ($report['comments'] as $comment)
58
-			$comments[$comment['member']['id']] = $comment['member']['link'];
57
+		foreach ($report['comments'] as $comment) {
58
+					$comments[$comment['member']['id']] = $comment['member']['link'];
59
+		}
59 60
 
60 61
 		echo '
61 62
 				', $txt['mc_reportedp_reported_by'], ': ', implode(', ', $comments), '
@@ -69,18 +70,21 @@  discard block
 block discarded – undo
69 70
 				<li><a href="', $scripturl, '?action=moderate;area=reportedposts;sa=handle;closed=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';', $context['mod-report-closed_token_var'], '=', $context['mod-report-closed_token'], '">', $close_button, '</a></li>';
70 71
 
71 72
 		// Delete message button.
72
-		if (!$report['closed'] && (is_array($context['report_remove_any_boards']) && in_array($report['topic']['id_board'], $context['report_remove_any_boards'])))
73
-			echo '
73
+		if (!$report['closed'] && (is_array($context['report_remove_any_boards']) && in_array($report['topic']['id_board'], $context['report_remove_any_boards']))) {
74
+					echo '
74 75
 				<li><a href="', $scripturl, '?action=deletemsg;topic=', $report['topic']['id'], '.0;msg=', $report['topic']['id_msg'], ';modcenter;', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['mc_reportedp_delete_confirm'], '" class="you_sure">', $delete_button, '</a></li>';
76
+		}
75 77
 
76 78
 		// Ban this user button.
77
-		if (!$report['closed'] && !empty($context['report_manage_bans']))
78
-			echo '
79
+		if (!$report['closed'] && !empty($context['report_manage_bans'])) {
80
+					echo '
79 81
 				<li><a href="', $scripturl, '?action=admin;area=ban;sa=add', (!empty($report['author']['id']) ? ';u=' . $report['author']['id'] : ';msg=' . $report['topic']['id_msg']), ';', $context['session_var'], '=', $context['session_id'], '">', $ban_button, '</a></li>';
82
+		}
80 83
 
81
-		if (!$context['view_closed'])
82
-			echo '
84
+		if (!$context['view_closed']) {
85
+					echo '
83 86
 				<li><input type="checkbox" name="close[]" value="' . $report['id'] . '"></li>';
87
+		}
84 88
 
85 89
 			echo '
86 90
 				</ul>
@@ -88,11 +92,12 @@  discard block
 block discarded – undo
88 92
 	}
89 93
 
90 94
 	// Were none found?
91
-	if (empty($context['reports']))
92
-		echo '
95
+	if (empty($context['reports'])) {
96
+			echo '
93 97
 		<div class="windowbg2">
94 98
 			<p class="centertext">', $txt['mc_reportedp_none_found'], '</p>
95 99
 		</div>';
100
+	}
96 101
 
97 102
 	echo '
98 103
 		<div class="pagesection">
@@ -125,18 +130,20 @@  discard block
 block discarded – undo
125 130
 			<div class="modbox">
126 131
 				<ul>';
127 132
 
128
-		foreach ($context['reported_posts'] as $report)
129
-			echo '
133
+		foreach ($context['reported_posts'] as $report) {
134
+					echo '
130 135
 					<li class="smalltext">
131 136
 						<a href="', $report['report_href'], '">', $report['subject'], '</a> ', $txt['mc_reportedp_by'], ' ', $report['author']['link'], '
132 137
 					</li>';
138
+		}
133 139
 
134 140
 		// Don't have any watched users right now?
135
-		if (empty($context['reported_posts']))
136
-			echo '
141
+		if (empty($context['reported_posts'])) {
142
+					echo '
137 143
 					<li>
138 144
 						<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
139 145
 					</li>';
146
+		}
140 147
 
141 148
 		echo '
142 149
 				</ul>
@@ -226,12 +233,13 @@  discard block
 block discarded – undo
226 233
 				<h3 class="catbg">', $txt['mc_modreport_whoreported_title'], '</h3>
227 234
 			</div>';
228 235
 
229
-	foreach ($context['report']['comments'] as $comment)
230
-		echo '
236
+	foreach ($context['report']['comments'] as $comment) {
237
+			echo '
231 238
 			<div class="windowbg">
232 239
 				<p class="smalltext">', sprintf($txt['mc_modreport_whoreported_data'], $comment['member']['link'] . (empty($comment['member']['id']) && !empty($comment['member']['ip']) ? ' (' . $comment['member']['ip'] . ')' : ''), $comment['time']), '</p>
233 240
 				<p>', $comment['message'], '</p>
234 241
 			</div>';
242
+	}
235 243
 
236 244
 	echo '
237 245
 			<br>
@@ -240,11 +248,12 @@  discard block
 block discarded – undo
240 248
 			</div>
241 249
 				<div>';
242 250
 
243
-	if (empty($context['report']['mod_comments']))
244
-		echo '
251
+	if (empty($context['report']['mod_comments'])) {
252
+			echo '
245 253
 				<div class="information">
246 254
 					<p class="centertext">', $txt['mc_modreport_no_mod_comment'], '</p>
247 255
 				</div>';
256
+	}
248 257
 
249 258
 	foreach ($context['report']['mod_comments'] as $comment)
250 259
 	{
@@ -334,18 +343,20 @@  discard block
 block discarded – undo
334 343
 			<div class="modbox">
335 344
 				<ul>';
336 345
 
337
-		foreach ($context['reported_members'] as $report)
338
-			echo '
346
+		foreach ($context['reported_members'] as $report) {
347
+					echo '
339 348
 					<li class="smalltext">
340 349
 						<a href="', $report['report_href'], '">', $report['user_name'], '</a>
341 350
 					</li>';
351
+		}
342 352
 
343 353
 		// Don't have any reported members right now?
344
-		if (empty($context['reported_members']))
345
-			echo '
354
+		if (empty($context['reported_members'])) {
355
+					echo '
346 356
 					<li>
347 357
 						<strong class="smalltext">', $txt['mc_recent_reports_none'], '</strong>
348 358
 					</li>';
359
+		}
349 360
 
350 361
 		echo '
351 362
 				</ul>
@@ -431,8 +442,9 @@  discard block
 block discarded – undo
431 442
 
432 443
 		// Prepare the comments...
433 444
 		$comments = array();
434
-		foreach ($report['comments'] as $comment)
435
-			$comments[$comment['member']['id']] = $comment['member']['link'];
445
+		foreach ($report['comments'] as $comment) {
446
+					$comments[$comment['member']['id']] = $comment['member']['link'];
447
+		}
436 448
 
437 449
 		echo '
438 450
 				', $txt['mc_reportedp_reported_by'], ': ', implode(', ', $comments), '
@@ -444,13 +456,15 @@  discard block
 block discarded – undo
444 456
 				<li><a href="', $scripturl, '?action=moderate;area=reportedmembers;sa=handle;closed=', (int) !$report['closed'], ';rid=', $report['id'], ';start=', $context['start'], ';', $context['session_var'], '=', $context['session_id'], ';', $context['mod-report-closed_token_var'], '=', $context['mod-report-closed_token'], '">', $close_button, '</a></li>';
445 457
 
446 458
 		// Ban this user button.
447
-		if (!$report['closed'] && !empty($context['report_manage_bans']) && !empty($report['user']['id']))
448
-			echo '
459
+		if (!$report['closed'] && !empty($context['report_manage_bans']) && !empty($report['user']['id'])) {
460
+					echo '
449 461
 				<li><a href="', $scripturl, '?action=admin;area=ban;sa=add;u=', $report['user']['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $ban_button, '</a></li>';
462
+		}
450 463
 
451
-		if (!$context['view_closed'])
452
-			echo '
464
+		if (!$context['view_closed']) {
465
+					echo '
453 466
 				<li><input type="checkbox" name="close[]" value="' . $report['id'] . '"></li>';
467
+		}
454 468
 
455 469
 			echo '
456 470
 				</ul>
@@ -458,11 +472,12 @@  discard block
 block discarded – undo
458 472
 	}
459 473
 
460 474
 	// Were none found?
461
-	if (empty($context['reports']))
462
-		echo '
475
+	if (empty($context['reports'])) {
476
+			echo '
463 477
 		<div class="windowbg2">
464 478
 			<p class="centertext">', $txt['mc_reportedp_none_found'], '</p>
465 479
 		</div>';
480
+	}
466 481
 
467 482
 	echo '
468 483
 		<div class="pagesection">
@@ -522,12 +537,13 @@  discard block
 block discarded – undo
522 537
 				<h3 class="catbg">', $txt['mc_memberreport_whoreported_title'], '</h3>
523 538
 			</div>';
524 539
 
525
-	foreach ($context['report']['comments'] as $comment)
526
-		echo '
540
+	foreach ($context['report']['comments'] as $comment) {
541
+			echo '
527 542
 			<div class="windowbg">
528 543
 				<p class="smalltext">', sprintf($txt['mc_modreport_whoreported_data'], $comment['member']['link'] . (empty($comment['member']['id']) && !empty($comment['member']['ip']) ? ' (' . $comment['member']['ip'] . ')' : ''), $comment['time']), '</p>
529 544
 				<p>', $comment['message'], '</p>
530 545
 			</div>';
546
+	}
531 547
 
532 548
 	echo '
533 549
 			<br>
@@ -536,11 +552,12 @@  discard block
 block discarded – undo
536 552
 			</div>
537 553
 				<div>';
538 554
 
539
-	if (empty($context['report']['mod_comments']))
540
-		echo '
555
+	if (empty($context['report']['mod_comments'])) {
556
+			echo '
541 557
 				<div class="information">
542 558
 					<p class="centertext">', $txt['mc_modreport_no_mod_comment'], '</p>
543 559
 				</div>';
560
+	}
544 561
 
545 562
 	foreach ($context['report']['mod_comments'] as $comment)
546 563
 	{
Please login to merge, or discard this patch.
Sources/ManageNews.php 1 patch
Braces   +140 added lines, -102 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The news dispatcher; doesn't do anything, just delegates.
@@ -67,8 +68,9 @@  discard block
 block discarded – undo
67 68
 	);
68 69
 
69 70
 	// Force the right area...
70
-	if (substr($_REQUEST['sa'], 0, 7) == 'mailing')
71
-		$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
71
+	if (substr($_REQUEST['sa'], 0, 7) == 'mailing') {
72
+			$context[$context['admin_menu_name']]['current_subsection'] = 'mailingmembers';
73
+	}
72 74
 
73 75
 	call_helper($subActions[$_REQUEST['sa']][0]);
74 76
 }
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		$temp_news = explode("\n", $modSettings['news']);
100 102
 
101 103
 		// Remove the items that were selected.
102
-		foreach ($temp_news as $i => $news)
103
-			if (in_array($i, $_POST['remove']))
104
+		foreach ($temp_news as $i => $news) {
105
+					if (in_array($i, $_POST['remove']))
104 106
 				unset($temp_news[$i]);
107
+		}
105 108
 
106 109
 		// Update the database.
107 110
 		updateSettings(array('news' => implode("\n", $temp_news)));
@@ -117,9 +120,9 @@  discard block
 block discarded – undo
117 120
 
118 121
 		foreach ($_POST['news'] as $i => $news)
119 122
 		{
120
-			if (trim($news) == '')
121
-				unset($_POST['news'][$i]);
122
-			else
123
+			if (trim($news) == '') {
124
+							unset($_POST['news'][$i]);
125
+			} else
123 126
 			{
124 127
 				$_POST['news'][$i] = $smcFunc['htmlspecialchars']($_POST['news'][$i], ENT_QUOTES);
125 128
 				preparsecode($_POST['news'][$i]);
@@ -154,11 +157,12 @@  discard block
 block discarded – undo
154 157
 				'data' => array(
155 158
 					'function' => function($news)
156 159
 					{
157
-						if (is_numeric($news['id']))
158
-							return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
160
+						if (is_numeric($news['id'])) {
161
+													return '<textarea id="data_' . $news['id'] . '" rows="3" cols="50" name="news[]" class="padding block">' . $news['unparsed'] . '</textarea>
159 162
 							<div class="floatleft" id="preview_' . $news['id'] . '"></div>';
160
-						else
161
-							return $news['unparsed'];
163
+						} else {
164
+													return $news['unparsed'];
165
+						}
162 166
 					},
163 167
 					'style' => 'width: 50%;',
164 168
 				),
@@ -183,10 +187,11 @@  discard block
 block discarded – undo
183 187
 				'data' => array(
184 188
 					'function' => function($news)
185 189
 					{
186
-						if (is_numeric($news['id']))
187
-							return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
188
-						else
189
-							return '';
190
+						if (is_numeric($news['id'])) {
191
+													return '<input type="checkbox" name="remove[]" value="' . $news['id'] . '">';
192
+						} else {
193
+													return '';
194
+						}
190 195
 					},
191 196
 					'class' => 'centercol',
192 197
 				),
@@ -280,12 +285,13 @@  discard block
 block discarded – undo
280 285
 
281 286
 	$admin_current_news = array();
282 287
 	// Ready the current news.
283
-	foreach (explode("\n", $modSettings['news']) as $id => $line)
284
-		$admin_current_news[$id] = array(
288
+	foreach (explode("\n", $modSettings['news']) as $id => $line) {
289
+			$admin_current_news[$id] = array(
285 290
 			'id' => $id,
286 291
 			'unparsed' => un_preparsecode($line),
287 292
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
288 293
 		);
294
+	}
289 295
 
290 296
 	$admin_current_news['last'] = array(
291 297
 		'id' => 'last',
@@ -352,10 +358,11 @@  discard block
 block discarded – undo
352 358
 			'member_count' => 0,
353 359
 		);
354 360
 
355
-		if ($row['min_posts'] == -1)
356
-			$normalGroups[$row['id_group']] = $row['id_group'];
357
-		else
358
-			$postGroups[$row['id_group']] = $row['id_group'];
361
+		if ($row['min_posts'] == -1) {
362
+					$normalGroups[$row['id_group']] = $row['id_group'];
363
+		} else {
364
+					$postGroups[$row['id_group']] = $row['id_group'];
365
+		}
359 366
 	}
360 367
 	$smcFunc['db_free_result']($request);
361 368
 
@@ -371,8 +378,9 @@  discard block
 block discarded – undo
371 378
 				'post_group_list' => $postGroups,
372 379
 			)
373 380
 		);
374
-		while ($row = $smcFunc['db_fetch_assoc']($query))
375
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
381
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
382
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
383
+		}
376 384
 		$smcFunc['db_free_result']($query);
377 385
 	}
378 386
 
@@ -388,8 +396,9 @@  discard block
 block discarded – undo
388 396
 				'normal_group_list' => $normalGroups,
389 397
 			)
390 398
 		);
391
-		while ($row = $smcFunc['db_fetch_assoc']($query))
392
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
399
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
400
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
401
+		}
393 402
 		$smcFunc['db_free_result']($query);
394 403
 
395 404
 		// Also do those who have it as an additional membergroup - this ones more yucky...
@@ -406,8 +415,9 @@  discard block
 block discarded – undo
406 415
 				'blank_string' => '',
407 416
 			)
408 417
 		);
409
-		while ($row = $smcFunc['db_fetch_assoc']($query))
410
-			$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
418
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
419
+					$context['groups'][$row['id_group']]['member_count'] += $row['member_count'];
420
+		}
411 421
 		$smcFunc['db_free_result']($query);
412 422
 	}
413 423
 
@@ -458,10 +468,11 @@  discard block
 block discarded – undo
458 468
 	{
459 469
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
460 470
 
461
-		if (empty($context[$key]) && empty($_REQUEST['xml']))
462
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
463
-		elseif (!empty($_REQUEST['xml']))
464
-			continue;
471
+		if (empty($context[$key]) && empty($_REQUEST['xml'])) {
472
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
473
+		} elseif (!empty($_REQUEST['xml'])) {
474
+					continue;
475
+		}
465 476
 
466 477
 		preparsecode($context[$key]);
467 478
 		if ($html)
@@ -540,10 +551,12 @@  discard block
 block discarded – undo
540 551
 
541 552
 	// Start by finding any members!
542 553
 	$toClean = array();
543
-	if (!empty($_POST['members']))
544
-		$toClean[] = 'members';
545
-	if (!empty($_POST['exclude_members']))
546
-		$toClean[] = 'exclude_members';
554
+	if (!empty($_POST['members'])) {
555
+			$toClean[] = 'members';
556
+	}
557
+	if (!empty($_POST['exclude_members'])) {
558
+			$toClean[] = 'exclude_members';
559
+	}
547 560
 	if (!empty($toClean))
548 561
 	{
549 562
 		require_once($sourcedir . '/Subs-Auth.php');
@@ -555,11 +568,13 @@  discard block
 block discarded – undo
555 568
 			preg_match_all('~"([^"]+)"~', $_POST[$type], $matches);
556 569
 			$_POST[$type] = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST[$type]))));
557 570
 
558
-			foreach ($_POST[$type] as $index => $member)
559
-				if (strlen(trim($member)) > 0)
571
+			foreach ($_POST[$type] as $index => $member) {
572
+							if (strlen(trim($member)) > 0)
560 573
 					$_POST[$type][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($member)));
561
-				else
562
-					unset($_POST[$type][$index]);
574
+			}
575
+				else {
576
+									unset($_POST[$type][$index]);
577
+				}
563 578
 
564 579
 			// Find the members
565 580
 			$_POST[$type] = implode(',', array_keys(findMembers($_POST[$type])));
@@ -569,16 +584,18 @@  discard block
 block discarded – undo
569 584
 	if (isset($_POST['member_list']) && is_array($_POST['member_list']))
570 585
 	{
571 586
 		$members = array();
572
-		foreach ($_POST['member_list'] as $member_id)
573
-			$members[] = (int) $member_id;
587
+		foreach ($_POST['member_list'] as $member_id) {
588
+					$members[] = (int) $member_id;
589
+		}
574 590
 		$_POST['members'] = implode(',', $members);
575 591
 	}
576 592
 
577 593
 	if (isset($_POST['exclude_member_list']) && is_array($_POST['exclude_member_list']))
578 594
 	{
579 595
 		$members = array();
580
-		foreach ($_POST['exclude_member_list'] as $member_id)
581
-			$members[] = (int) $member_id;
596
+		foreach ($_POST['exclude_member_list'] as $member_id) {
597
+					$members[] = (int) $member_id;
598
+		}
582 599
 		$_POST['exclude_members'] = implode(',', $members);
583 600
 	}
584 601
 
@@ -602,8 +619,9 @@  discard block
 block discarded – undo
602 619
 			'current_time' => time(),
603 620
 		)
604 621
 	);
605
-	while ($row = $smcFunc['db_fetch_assoc']($request))
606
-		$context['recipients']['exclude_members'][] = $row['id_member'];
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$context['recipients']['exclude_members'][] = $row['id_member'];
624
+	}
607 625
 	$smcFunc['db_free_result']($request);
608 626
 
609 627
 	$request = $smcFunc['db_query']('', '
@@ -638,8 +656,9 @@  discard block
 block discarded – undo
638 656
 			WHERE email_address IN(' . implode(', ', $condition_array) . ')',
639 657
 			$condition_array_params
640 658
 		);
641
-		while ($row = $smcFunc['db_fetch_assoc']($request))
642
-			$context['recipients']['exclude_members'][] = $row['id_member'];
659
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
660
+					$context['recipients']['exclude_members'][] = $row['id_member'];
661
+		}
643 662
 		$smcFunc['db_free_result']($request);
644 663
 	}
645 664
 
@@ -657,10 +676,11 @@  discard block
 block discarded – undo
657 676
 		);
658 677
 		while ($row = $smcFunc['db_fetch_assoc']($request))
659 678
 		{
660
-			if (in_array(3, $context['recipients']))
661
-				$context['recipients']['exclude_members'][] = $row['identifier'];
662
-			else
663
-				$context['recipients']['members'][] = $row['identifier'];
679
+			if (in_array(3, $context['recipients'])) {
680
+							$context['recipients']['exclude_members'][] = $row['identifier'];
681
+			} else {
682
+							$context['recipients']['members'][] = $row['identifier'];
683
+			}
664 684
 		}
665 685
 		$smcFunc['db_free_result']($request);
666 686
 	}
@@ -707,8 +727,9 @@  discard block
 block discarded – undo
707 727
 	$num_at_once = 1000;
708 728
 
709 729
 	// If by PM's I suggest we half the above number.
710
-	if (!empty($_POST['send_pm']))
711
-		$num_at_once /= 2;
730
+	if (!empty($_POST['send_pm'])) {
731
+			$num_at_once /= 2;
732
+	}
712 733
 
713 734
 	checkSession();
714 735
 
@@ -731,8 +752,7 @@  discard block
 block discarded – undo
731 752
 		);
732 753
 		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
733 754
 		$smcFunc['db_free_result']($request);
734
-	}
735
-	else
755
+	} else
736 756
 	{
737 757
 		$context['total_members'] = (int) $_REQUEST['total_members'];
738 758
 	}
@@ -750,32 +770,35 @@  discard block
 block discarded – undo
750 770
 	if (!empty($_POST['exclude_members']))
751 771
 	{
752 772
 		$members = explode(',', $_POST['exclude_members']);
753
-		foreach ($members as $member)
754
-			if ($member >= $context['start'])
773
+		foreach ($members as $member) {
774
+					if ($member >= $context['start'])
755 775
 				$context['recipients']['exclude_members'][] = (int) $member;
776
+		}
756 777
 	}
757 778
 
758 779
 	// What about members we *must* do?
759 780
 	if (!empty($_POST['members']))
760 781
 	{
761 782
 		$members = explode(',', $_POST['members']);
762
-		foreach ($members as $member)
763
-			if ($member >= $context['start'])
783
+		foreach ($members as $member) {
784
+					if ($member >= $context['start'])
764 785
 				$context['recipients']['members'][] = (int) $member;
786
+		}
765 787
 	}
766 788
 	// Cleaning groups is simple - although deal with both checkbox and commas.
767 789
 	if (isset($_POST['groups']))
768 790
 	{
769 791
 		if (is_array($_POST['groups']))
770 792
 		{
771
-			foreach ($_POST['groups'] as $group => $dummy)
772
-				$context['recipients']['groups'][] = (int) $group;
773
-		}
774
-		else
793
+			foreach ($_POST['groups'] as $group => $dummy) {
794
+							$context['recipients']['groups'][] = (int) $group;
795
+			}
796
+		} else
775 797
 		{
776 798
 			$groups = explode(',', $_POST['groups']);
777
-			foreach ($groups as $group)
778
-				$context['recipients']['groups'][] = (int) $group;
799
+			foreach ($groups as $group) {
800
+							$context['recipients']['groups'][] = (int) $group;
801
+			}
779 802
 		}
780 803
 	}
781 804
 	// Same for excluded groups
@@ -783,15 +806,17 @@  discard block
 block discarded – undo
783 806
 	{
784 807
 		if (is_array($_POST['exclude_groups']))
785 808
 		{
786
-			foreach ($_POST['exclude_groups'] as $group => $dummy)
787
-				$context['recipients']['exclude_groups'][] = (int) $group;
809
+			foreach ($_POST['exclude_groups'] as $group => $dummy) {
810
+							$context['recipients']['exclude_groups'][] = (int) $group;
811
+			}
788 812
 		}
789 813
 		// Ignore an empty string - we don't want to exclude "Regular Members" unless it's specifically selected
790 814
 		elseif ($_POST['exclude_groups'] != '')
791 815
 		{
792 816
 			$groups = explode(',', $_POST['exclude_groups']);
793
-			foreach ($groups as $group)
794
-				$context['recipients']['exclude_groups'][] = (int) $group;
817
+			foreach ($groups as $group) {
818
+							$context['recipients']['exclude_groups'][] = (int) $group;
819
+			}
795 820
 		}
796 821
 	}
797 822
 	// Finally - emails!
@@ -801,14 +826,16 @@  discard block
 block discarded – undo
801 826
 		foreach ($addressed as $curmem)
802 827
 		{
803 828
 			$curmem = trim($curmem);
804
-			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL))
805
-				$context['recipients']['emails'][$curmem] = $curmem;
829
+			if ($curmem != '' && filter_var($curmem, FILTER_VALIDATE_EMAIL)) {
830
+							$context['recipients']['emails'][$curmem] = $curmem;
831
+			}
806 832
 		}
807 833
 	}
808 834
 
809 835
 	// If we're only cleaning drop out here.
810
-	if ($clean_only)
811
-		return;
836
+	if ($clean_only) {
837
+			return;
838
+	}
812 839
 
813 840
 	require_once($sourcedir . '/Subs-Post.php');
814 841
 
@@ -824,16 +851,18 @@  discard block
 block discarded – undo
824 851
 	if (!$context['send_pm'] && !empty($_POST['send_html']))
825 852
 	{
826 853
 		// Prepare the message for HTML.
827
-		if (!empty($_POST['parse_html']))
828
-			$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
854
+		if (!empty($_POST['parse_html'])) {
855
+					$_POST['message'] = str_replace(array("\n", '  '), array('<br>' . "\n", '&nbsp; '), $_POST['message']);
856
+		}
829 857
 
830 858
 		// This is here to prevent spam filters from tagging this as spam.
831 859
 		if (preg_match('~\<html~i', $_POST['message']) == 0)
832 860
 		{
833
-			if (preg_match('~\<body~i', $_POST['message']) == 0)
834
-				$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
835
-			else
836
-				$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
861
+			if (preg_match('~\<body~i', $_POST['message']) == 0) {
862
+							$_POST['message'] = '<html><head><title>' . $_POST['subject'] . '</title></head>' . "\n" . '<body>' . $_POST['message'] . '</body></html>';
863
+			} else {
864
+							$_POST['message'] = '<html>' . $_POST['message'] . '</html>';
865
+			}
837 866
 		}
838 867
 	}
839 868
 
@@ -887,15 +916,17 @@  discard block
 block discarded – undo
887 916
 	foreach ($context['recipients']['emails'] as $k => $email)
888 917
 	{
889 918
 		// Done as many as we can?
890
-		if ($i >= $num_at_once)
891
-			break;
919
+		if ($i >= $num_at_once) {
920
+					break;
921
+		}
892 922
 
893 923
 		// Don't sent it twice!
894 924
 		unset($context['recipients']['emails'][$k]);
895 925
 
896 926
 		// Dammit - can't PM emails!
897
-		if ($context['send_pm'])
898
-			continue;
927
+		if ($context['send_pm']) {
928
+					continue;
929
+		}
899 930
 
900 931
 		$to_member = array(
901 932
 			$email,
@@ -929,8 +960,9 @@  discard block
 block discarded – undo
929 960
 					$queryBuild[] = 'mem.id_post_group = {int:group_' . $group . '}';
930 961
 				}
931 962
 			}
932
-			if (!empty($queryBuild))
933
-			$sendQuery .= implode(' OR ', $queryBuild);
963
+			if (!empty($queryBuild)) {
964
+						$sendQuery .= implode(' OR ', $queryBuild);
965
+			}
934 966
 		}
935 967
 		if (!empty($context['recipients']['members']))
936 968
 		{
@@ -949,8 +981,9 @@  discard block
 block discarded – undo
949 981
 		}
950 982
 
951 983
 		// Anything to exclude?
952
-		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups']))
953
-			$sendQuery .= ' AND mem.id_group != {int:regular_group}';
984
+		if (!empty($context['recipients']['exclude_groups']) && in_array(0, $context['recipients']['exclude_groups'])) {
985
+					$sendQuery .= ' AND mem.id_group != {int:regular_group}';
986
+		}
954 987
 		if (!empty($context['recipients']['exclude_members']))
955 988
 		{
956 989
 			$sendQuery .= ' AND mem.id_member NOT IN ({array_int:exclude_members})';
@@ -986,21 +1019,24 @@  discard block
 block discarded – undo
986 1019
 		foreach ($rows as $row)
987 1020
 		{
988 1021
 			// Force them to have it?
989
-			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements']))
990
-				continue;
1022
+			if (empty($context['email_force']) && empty($prefs[$row['id_member']]['announcements'])) {
1023
+							continue;
1024
+			}
991 1025
 
992 1026
 			// What groups are we looking at here?
993
-			if (empty($row['additional_groups']))
994
-				$groups = array($row['id_group'], $row['id_post_group']);
995
-			else
996
-				$groups = array_merge(
1027
+			if (empty($row['additional_groups'])) {
1028
+							$groups = array($row['id_group'], $row['id_post_group']);
1029
+			} else {
1030
+							$groups = array_merge(
997 1031
 					array($row['id_group'], $row['id_post_group']),
998 1032
 					explode(',', $row['additional_groups'])
999 1033
 				);
1034
+			}
1000 1035
 
1001 1036
 			// Excluded groups?
1002
-			if (array_intersect($groups, $context['recipients']['exclude_groups']))
1003
-				continue;
1037
+			if (array_intersect($groups, $context['recipients']['exclude_groups'])) {
1038
+							continue;
1039
+			}
1004 1040
 
1005 1041
 			// We might need this
1006 1042
 			$cleanMemberName = empty($_POST['send_html']) || $context['send_pm'] ? un_htmlspecialchars($row['real_name']) : $row['real_name'];
@@ -1023,10 +1059,11 @@  discard block
 block discarded – undo
1023 1059
 				), $_POST['subject']);
1024 1060
 
1025 1061
 			// Send the actual email - or a PM!
1026
-			if (!$context['send_pm'])
1027
-				sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1028
-			else
1029
-				sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1062
+			if (!$context['send_pm']) {
1063
+							sendmail($row['email_address'], $subject, $message, null, 'news', !empty($_POST['send_html']), 5);
1064
+			} else {
1065
+							sendpm(array('to' => array($row['id_member']), 'bcc' => array()), $subject, $message);
1066
+			}
1030 1067
 		}
1031 1068
 	}
1032 1069
 
@@ -1076,8 +1113,9 @@  discard block
 block discarded – undo
1076 1113
 
1077 1114
 	call_integration_hook('integrate_modify_news_settings', array(&$config_vars));
1078 1115
 
1079
-	if ($return_config)
1080
-		return $config_vars;
1116
+	if ($return_config) {
1117
+			return $config_vars;
1118
+	}
1081 1119
 
1082 1120
 	$context['page_title'] = $txt['admin_edit_news'] . ' - ' . $txt['settings'];
1083 1121
 	$context['sub_template'] = 'show_settings';
Please login to merge, or discard this patch.
Sources/Profile.php 1 patch
Braces   +155 added lines, -118 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * The main designating function for modifying profiles. Loads up info, determins what to do, etc.
@@ -29,18 +30,21 @@  discard block
 block discarded – undo
29 30
 	global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc;
30 31
 
31 32
 	// Don't reload this as we may have processed error strings.
32
-	if (empty($post_errors))
33
-		loadLanguage('Profile+Drafts');
33
+	if (empty($post_errors)) {
34
+			loadLanguage('Profile+Drafts');
35
+	}
34 36
 	loadTemplate('Profile');
35 37
 
36 38
 	require_once($sourcedir . '/Subs-Menu.php');
37 39
 
38 40
 	// Did we get the user by name...
39
-	if (isset($_REQUEST['user']))
40
-		$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
41
+	if (isset($_REQUEST['user'])) {
42
+			$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
43
+	}
41 44
 	// ... or by id_member?
42
-	elseif (!empty($_REQUEST['u']))
43
-		$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
45
+	elseif (!empty($_REQUEST['u'])) {
46
+			$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
47
+	}
44 48
 	// If it was just ?action=profile, edit your own profile, but only if you're not a guest.
45 49
 	else
46 50
 	{
@@ -50,8 +54,9 @@  discard block
 block discarded – undo
50 54
 	}
51 55
 
52 56
 	// Check if loadMemberData() has returned a valid result.
53
-	if (!$memberResult)
54
-		fatal_lang_error('not_a_user', false, 404);
57
+	if (!$memberResult) {
58
+			fatal_lang_error('not_a_user', false, 404);
59
+	}
55 60
 
56 61
 	// If all went well, we have a valid member ID!
57 62
 	list ($memID) = $memberResult;
@@ -67,8 +72,9 @@  discard block
 block discarded – undo
67 72
 
68 73
 	// Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
69 74
 	// And we care about what the current user can do, not what the user whose profile it is.
70
-	if ($user_info['mod_cache']['gq'] != '0=1')
71
-		$user_info['permissions'][] = 'approve_group_requests';
75
+	if ($user_info['mod_cache']['gq'] != '0=1') {
76
+			$user_info['permissions'][] = 'approve_group_requests';
77
+	}
72 78
 
73 79
 	// If paid subscriptions are enabled, make sure we actually have at least one subscription available...
74 80
 	$context['subs_available'] = false;
@@ -436,21 +442,25 @@  discard block
 block discarded – undo
436 442
 		foreach ($section['areas'] as $area_id => $area)
437 443
 		{
438 444
 			// If it said no permissions that meant it wasn't valid!
439
-			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
440
-				$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
445
+			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) {
446
+							$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
447
+			}
441 448
 			// Otherwise pick the right set.
442
-			else
443
-				$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
449
+			else {
450
+							$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
451
+			}
444 452
 
445 453
 			// Password required in most cases
446
-			if (!empty($area['password']))
447
-				$context['password_areas'][] = $area_id;
454
+			if (!empty($area['password'])) {
455
+							$context['password_areas'][] = $area_id;
456
+			}
448 457
 		}
449 458
 	}
450 459
 
451 460
 	// Is there an updated message to show?
452
-	if (isset($_GET['updated']))
453
-		$context['profile_updated'] = $txt['profile_updated_own'];
461
+	if (isset($_GET['updated'])) {
462
+			$context['profile_updated'] = $txt['profile_updated_own'];
463
+	}
454 464
 
455 465
 	// Set a few options for the menu.
456 466
 	$menuOptions = array(
@@ -465,8 +475,9 @@  discard block
 block discarded – undo
465 475
 	$profile_include_data = createMenu($profile_areas, $menuOptions);
466 476
 
467 477
 	// No menu means no access.
468
-	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
469
-		fatal_lang_error('no_access', false);
478
+	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) {
479
+			fatal_lang_error('no_access', false);
480
+	}
470 481
 
471 482
 	// Make a note of the Unique ID for this menu.
472 483
 	$context['profile_menu_id'] = $context['max_menu_id'];
@@ -492,8 +503,9 @@  discard block
 block discarded – undo
492 503
 			if ($current_area == $area_id)
493 504
 			{
494 505
 				// This can't happen - but is a security check.
495
-				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
496
-					fatal_lang_error('no_access', false);
506
+				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) {
507
+									fatal_lang_error('no_access', false);
508
+				}
497 509
 
498 510
 				// Are we saving data in a valid area?
499 511
 				if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
@@ -512,12 +524,14 @@  discard block
 block discarded – undo
512 524
 				}
513 525
 
514 526
 				// Does this require session validating?
515
-				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
516
-					$security_checks['validate'] = true;
527
+				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) {
528
+									$security_checks['validate'] = true;
529
+				}
517 530
 
518 531
 				// Permissions for good measure.
519
-				if (!empty($profile_include_data['permission']))
520
-					$security_checks['permission'] = $profile_include_data['permission'];
532
+				if (!empty($profile_include_data['permission'])) {
533
+									$security_checks['permission'] = $profile_include_data['permission'];
534
+				}
521 535
 
522 536
 				// Either way got something.
523 537
 				$found_area = true;
@@ -526,21 +540,26 @@  discard block
 block discarded – undo
526 540
 	}
527 541
 
528 542
 	// Oh dear, some serious security lapse is going on here... we'll put a stop to that!
529
-	if (!$found_area)
530
-		fatal_lang_error('no_access', false);
543
+	if (!$found_area) {
544
+			fatal_lang_error('no_access', false);
545
+	}
531 546
 
532 547
 	// Release this now.
533 548
 	unset($profile_areas);
534 549
 
535 550
 	// Now the context is setup have we got any security checks to carry out additional to that above?
536
-	if (isset($security_checks['session']))
537
-		checkSession($security_checks['session']);
538
-	if (isset($security_checks['validate']))
539
-		validateSession();
540
-	if (isset($security_checks['validateToken']))
541
-		validateToken($token_name, $token_type);
542
-	if (isset($security_checks['permission']))
543
-		isAllowedTo($security_checks['permission']);
551
+	if (isset($security_checks['session'])) {
552
+			checkSession($security_checks['session']);
553
+	}
554
+	if (isset($security_checks['validate'])) {
555
+			validateSession();
556
+	}
557
+	if (isset($security_checks['validateToken'])) {
558
+			validateToken($token_name, $token_type);
559
+	}
560
+	if (isset($security_checks['permission'])) {
561
+			isAllowedTo($security_checks['permission']);
562
+	}
544 563
 
545 564
 	// Create a token if needed.
546 565
 	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
@@ -550,8 +569,9 @@  discard block
 block discarded – undo
550 569
 	}
551 570
 
552 571
 	// File to include?
553
-	if (isset($profile_include_data['file']))
554
-		require_once($sourcedir . '/' . $profile_include_data['file']);
572
+	if (isset($profile_include_data['file'])) {
573
+			require_once($sourcedir . '/' . $profile_include_data['file']);
574
+	}
555 575
 
556 576
 	// Build the link tree.
557 577
 	$context['linktree'][] = array(
@@ -559,17 +579,19 @@  discard block
 block discarded – undo
559 579
 		'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
560 580
 	);
561 581
 
562
-	if (!empty($profile_include_data['label']))
563
-		$context['linktree'][] = array(
582
+	if (!empty($profile_include_data['label'])) {
583
+			$context['linktree'][] = array(
564 584
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
565 585
 			'name' => $profile_include_data['label'],
566 586
 		);
587
+	}
567 588
 
568
-	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
569
-		$context['linktree'][] = array(
589
+	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) {
590
+			$context['linktree'][] = array(
570 591
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
571 592
 			'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
572 593
 		);
594
+	}
573 595
 
574 596
 	// Set the template for this area and add the profile layer.
575 597
 	$context['sub_template'] = $profile_include_data['function'];
@@ -595,12 +617,14 @@  discard block
 block discarded – undo
595 617
 		if ($check_password)
596 618
 		{
597 619
 			// Check to ensure we're forcing SSL for authentication
598
-			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
599
-				fatal_lang_error('login_ssl_required');
620
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
621
+							fatal_lang_error('login_ssl_required');
622
+			}
600 623
 
601 624
 			// You didn't even enter a password!
602
-			if (trim($_POST['oldpasswrd']) == '')
603
-				$post_errors[] = 'no_password';
625
+			if (trim($_POST['oldpasswrd']) == '') {
626
+							$post_errors[] = 'no_password';
627
+			}
604 628
 
605 629
 			// Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
606 630
 			$_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
@@ -609,42 +633,43 @@  discard block
 block discarded – undo
609 633
 			$good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
610 634
 
611 635
 			// Bad password!!!
612
-			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd']))
613
-				$post_errors[] = 'bad_password';
636
+			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) {
637
+							$post_errors[] = 'bad_password';
638
+			}
614 639
 
615 640
 			// Warn other elements not to jump the gun and do custom changes!
616
-			if (in_array('bad_password', $post_errors))
617
-				$context['password_auth_failed'] = true;
641
+			if (in_array('bad_password', $post_errors)) {
642
+							$context['password_auth_failed'] = true;
643
+			}
618 644
 		}
619 645
 
620 646
 		// Change the IP address in the database.
621
-		if ($context['user']['is_owner'])
622
-			$profile_vars['member_ip'] = $user_info['ip'];
647
+		if ($context['user']['is_owner']) {
648
+					$profile_vars['member_ip'] = $user_info['ip'];
649
+		}
623 650
 
624 651
 		// Now call the sub-action function...
625 652
 		if ($current_area == 'activateaccount')
626 653
 		{
627
-			if (empty($post_errors))
628
-				activateAccount($memID);
629
-		}
630
-		elseif ($current_area == 'deleteaccount')
654
+			if (empty($post_errors)) {
655
+							activateAccount($memID);
656
+			}
657
+		} elseif ($current_area == 'deleteaccount')
631 658
 		{
632 659
 			if (empty($post_errors))
633 660
 			{
634 661
 				deleteAccount2($memID);
635 662
 				redirectexit();
636 663
 			}
637
-		}
638
-		elseif ($current_area == 'groupmembership' && empty($post_errors))
664
+		} elseif ($current_area == 'groupmembership' && empty($post_errors))
639 665
 		{
640 666
 			$msg = groupMembership2($profile_vars, $post_errors, $memID);
641 667
 
642 668
 			// Whatever we've done, we have nothing else to do here...
643 669
 			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : ''));
644
-		}
645
-		elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
646
-			saveProfileFields();
647
-		else
670
+		} elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) {
671
+					saveProfileFields();
672
+		} else
648 673
 		{
649 674
 			$force_redirect = true;
650 675
 			// Ensure we include this.
@@ -660,34 +685,36 @@  discard block
 block discarded – undo
660 685
 			// Load the language file so we can give a nice explanation of the errors.
661 686
 			loadLanguage('Errors');
662 687
 			$context['post_errors'] = $post_errors;
663
-		}
664
-		elseif (!empty($profile_vars))
688
+		} elseif (!empty($profile_vars))
665 689
 		{
666 690
 			// If we've changed the password, notify any integration that may be listening in.
667
-			if (isset($profile_vars['passwd']))
668
-				call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
691
+			if (isset($profile_vars['passwd'])) {
692
+							call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
693
+			}
669 694
 
670 695
 			updateMemberData($memID, $profile_vars);
671 696
 
672 697
 			// What if this is the newest member?
673
-			if ($modSettings['latestMember'] == $memID)
674
-				updateStats('member');
675
-			elseif (isset($profile_vars['real_name']))
676
-				updateSettings(array('memberlist_updated' => time()));
698
+			if ($modSettings['latestMember'] == $memID) {
699
+							updateStats('member');
700
+			} elseif (isset($profile_vars['real_name'])) {
701
+							updateSettings(array('memberlist_updated' => time()));
702
+			}
677 703
 
678 704
 			// If the member changed his/her birthdate, update calendar statistics.
679
-			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
680
-				updateSettings(array(
705
+			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) {
706
+							updateSettings(array(
681 707
 					'calendar_updated' => time(),
682 708
 				));
709
+			}
683 710
 
684 711
 			// Anything worth logging?
685 712
 			if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
686 713
 			{
687 714
 				$log_changes = array();
688 715
 				require_once($sourcedir . '/Logging.php');
689
-				foreach ($context['log_changes'] as $k => $v)
690
-					$log_changes[] = array(
716
+				foreach ($context['log_changes'] as $k => $v) {
717
+									$log_changes[] = array(
691 718
 						'action' => $k,
692 719
 						'log_type' => 'user',
693 720
 						'extra' => array_merge($v, array(
@@ -695,14 +722,16 @@  discard block
 block discarded – undo
695 722
 							'member_affected' => $memID,
696 723
 						)),
697 724
 					);
725
+				}
698 726
 
699 727
 				logActions($log_changes);
700 728
 			}
701 729
 
702 730
 			// Have we got any post save functions to execute?
703
-			if (!empty($context['profile_execute_on_save']))
704
-				foreach ($context['profile_execute_on_save'] as $saveFunc)
731
+			if (!empty($context['profile_execute_on_save'])) {
732
+							foreach ($context['profile_execute_on_save'] as $saveFunc)
705 733
 					$saveFunc();
734
+			}
706 735
 
707 736
 			// Let them know it worked!
708 737
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
@@ -716,27 +745,31 @@  discard block
 block discarded – undo
716 745
 	if (!empty($post_errors))
717 746
 	{
718 747
 		// Set all the errors so the template knows what went wrong.
719
-		foreach ($post_errors as $error_type)
720
-			$context['modify_error'][$error_type] = true;
748
+		foreach ($post_errors as $error_type) {
749
+					$context['modify_error'][$error_type] = true;
750
+		}
721 751
 	}
722 752
 	// If it's you then we should redirect upon save.
723
-	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
724
-		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
725
-	elseif (!empty($force_redirect))
726
-		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
753
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) {
754
+			redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
755
+	} elseif (!empty($force_redirect)) {
756
+			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
757
+	}
727 758
 
728 759
 
729 760
 	// Get the right callable.
730 761
 	$call = call_helper($profile_include_data['function'], true);
731 762
 
732 763
 	// Is it valid?
733
-	if (!empty($call))
734
-		call_user_func($call, $memID);
764
+	if (!empty($call)) {
765
+			call_user_func($call, $memID);
766
+	}
735 767
 
736 768
 	// Set the page title if it's not already set...
737
-	if (!isset($context['page_title']))
738
-		$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
739
-}
769
+	if (!isset($context['page_title'])) {
770
+			$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
771
+	}
772
+	}
740 773
 
741 774
 /**
742 775
  * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
@@ -859,16 +892,18 @@  discard block
 block discarded – undo
859 892
 	if (!allowedTo('admin_forum') && $area != 'register')
860 893
 	{
861 894
 		// If it's the owner they can see two types of private fields, regardless.
862
-		if ($memID == $user_info['id'])
863
-			$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
864
-		else
865
-			$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
895
+		if ($memID == $user_info['id']) {
896
+					$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
897
+		} else {
898
+					$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
899
+		}
866 900
 	}
867 901
 
868
-	if ($area == 'register')
869
-		$where .= ' AND show_reg != 0';
870
-	elseif ($area != 'summary')
871
-		$where .= ' AND show_profile = {string:area}';
902
+	if ($area == 'register') {
903
+			$where .= ' AND show_reg != 0';
904
+	} elseif ($area != 'summary') {
905
+			$where .= ' AND show_profile = {string:area}';
906
+	}
872 907
 
873 908
 	// Load all the relevant fields - and data.
874 909
 	$request = $smcFunc['db_query']('', '
@@ -894,13 +929,15 @@  discard block
 block discarded – undo
894 929
 		if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
895 930
 		{
896 931
 			$value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
897
-			if (in_array($row['field_type'], array('select', 'radio')))
898
-					$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
932
+			if (in_array($row['field_type'], array('select', 'radio'))) {
933
+								$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
934
+			}
899 935
 		}
900 936
 
901 937
 		// Don't show the "disabled" option for the "gender" field if we are on the "summary" area.
902
-		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled')
903
-			continue;
938
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') {
939
+					continue;
940
+		}
904 941
 
905 942
 		// HTML for the input form.
906 943
 		$output_html = $value;
@@ -909,8 +946,7 @@  discard block
 block discarded – undo
909 946
 			$true = (!$exists && $row['default_value']) || $value;
910 947
 			$input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . '>';
911 948
 			$output_html = $true ? $txt['yes'] : $txt['no'];
912
-		}
913
-		elseif ($row['field_type'] == 'select')
949
+		} elseif ($row['field_type'] == 'select')
914 950
 		{
915 951
 			$input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
916 952
 			$options = explode(',', $row['field_options']);
@@ -918,13 +954,13 @@  discard block
 block discarded – undo
918 954
 			{
919 955
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
920 956
 				$input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
921
-				if ($true)
922
-					$output_html = $v;
957
+				if ($true) {
958
+									$output_html = $v;
959
+				}
923 960
 			}
924 961
 
925 962
 			$input_html .= '</select>';
926
-		}
927
-		elseif ($row['field_type'] == 'radio')
963
+		} elseif ($row['field_type'] == 'radio')
928 964
 		{
929 965
 			$input_html = '<fieldset>';
930 966
 			$options = explode(',', $row['field_options']);
@@ -932,36 +968,37 @@  discard block
 block discarded – undo
932 968
 			{
933 969
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
934 970
 				$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>';
935
-				if ($true)
936
-					$output_html = $v;
971
+				if ($true) {
972
+									$output_html = $v;
973
+				}
937 974
 			}
938 975
 			$input_html .= '</fieldset>';
939
-		}
940
-		elseif ($row['field_type'] == 'text')
976
+		} elseif ($row['field_type'] == 'text')
941 977
 		{
942 978
 			$input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
943
-		}
944
-		else
979
+		} else
945 980
 		{
946 981
 			@list ($rows, $cols) = @explode(',', $row['default_value']);
947 982
 			$input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>';
948 983
 		}
949 984
 
950 985
 		// Parse BBCode
951
-		if ($row['bbc'])
952
-			$output_html = parse_bbc($output_html);
953
-		elseif ($row['field_type'] == 'textarea')
954
-			// Allow for newlines at least
986
+		if ($row['bbc']) {
987
+					$output_html = parse_bbc($output_html);
988
+		} elseif ($row['field_type'] == 'textarea') {
989
+					// Allow for newlines at least
955 990
 			$output_html = strtr($output_html, array("\n" => '<br>'));
991
+		}
956 992
 
957 993
 		// Enclosing the user input within some other text?
958
-		if (!empty($row['enclose']) && !empty($output_html))
959
-			$output_html = strtr($row['enclose'], array(
994
+		if (!empty($row['enclose']) && !empty($output_html)) {
995
+					$output_html = strtr($row['enclose'], array(
960 996
 				'{SCRIPTURL}' => $scripturl,
961 997
 				'{IMAGES_URL}' => $settings['images_url'],
962 998
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
963 999
 				'{INPUT}' => un_htmlspecialchars($output_html),
964 1000
 			));
1001
+		}
965 1002
 
966 1003
 		$context['custom_fields'][] = array(
967 1004
 			'name' => $row['field_name'],
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +224 added lines, -163 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
 	static $timezone_array = array();
134 136
 	require_once($sourcedir . '/Subs.php');
135 137
 	
136
-	if (empty($timezone_array['default']))
137
-		$timezone_array['default'] = timezone_open(date_default_timezone_get());
138
+	if (empty($timezone_array['default'])) {
139
+			$timezone_array['default'] = timezone_open(date_default_timezone_get());
140
+	}
138 141
 
139 142
 	$low_object = date_create($low_date);
140 143
 	$high_object = date_create($high_date);
@@ -161,8 +164,9 @@  discard block
 block discarded – undo
161 164
 	while ($row = $smcFunc['db_fetch_assoc']($result))
162 165
 	{
163 166
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
164
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
165
-			continue;
167
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
168
+					continue;
169
+		}
166 170
 
167 171
 		// Force a censor of the title - as often these are used by others.
168 172
 		censorText($row['title'], $use_permissions ? false : true);
@@ -170,12 +174,14 @@  discard block
 block discarded – undo
170 174
 		// Get the various time and date properties for this event
171 175
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
172 176
 		
173
-		if (empty($timezone_array[$tz]))
174
-			$timezone_array[$tz] = timezone_open($tz);
177
+		if (empty($timezone_array[$tz])) {
178
+					$timezone_array[$tz] = timezone_open($tz);
179
+		}
175 180
 
176 181
 		// Sanity check
177
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
178
-			continue;
182
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
183
+					continue;
184
+		}
179 185
 
180 186
 		// Get set up for the loop
181 187
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), $timezone_array[$tz]);
@@ -239,8 +245,8 @@  discard block
 block discarded – undo
239 245
 			);
240 246
 
241 247
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
242
-			if ($use_permissions)
243
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
248
+			if ($use_permissions) {
249
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
244 250
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
245 251
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
246 252
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -248,9 +254,10 @@  discard block
 block discarded – undo
248 254
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
249 255
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
250 256
 				));
257
+			}
251 258
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
252
-			else
253
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
259
+			else {
260
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
254 261
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
255 262
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
256 263
 					'can_edit' => false,
@@ -260,6 +267,7 @@  discard block
 block discarded – undo
260 267
 					'poster' => $row['id_member'],
261 268
 					'allowed_groups' => explode(',', $row['member_groups']),
262 269
 				));
270
+			}
263 271
 
264 272
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
265 273
 		}
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
270 278
 	if ($use_permissions)
271 279
 	{
272
-		foreach ($events as $mday => $array)
273
-			$events[$mday][count($array) - 1]['is_last'] = true;
280
+		foreach ($events as $mday => $array) {
281
+					$events[$mday][count($array) - 1]['is_last'] = true;
282
+		}
274 283
 	}
275 284
 
276 285
 	ksort($events);
@@ -290,11 +299,12 @@  discard block
 block discarded – undo
290 299
 	global $smcFunc;
291 300
 
292 301
 	// Get the lowest and highest dates for "all years".
293
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
294
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
302
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
303
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
295 304
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
296
-	else
297
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
305
+	} else {
306
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
307
+	}
298 308
 
299 309
 	// Find some holidays... ;).
300 310
 	$result = $smcFunc['db_query']('', '
@@ -314,10 +324,11 @@  discard block
 block discarded – undo
314 324
 	$holidays = array();
315 325
 	while ($row = $smcFunc['db_fetch_assoc']($result))
316 326
 	{
317
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
318
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
319
-		else
320
-			$event_year = substr($low_date, 0, 4);
327
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
328
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
329
+		} else {
330
+					$event_year = substr($low_date, 0, 4);
331
+		}
321 332
 
322 333
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
323 334
 	}
@@ -343,10 +354,12 @@  discard block
 block discarded – undo
343 354
 	isAllowedTo('calendar_post');
344 355
 
345 356
 	// No board?  No topic?!?
346
-	if (empty($board))
347
-		fatal_lang_error('missing_board_id', false);
348
-	if (empty($topic))
349
-		fatal_lang_error('missing_topic_id', false);
357
+	if (empty($board)) {
358
+			fatal_lang_error('missing_board_id', false);
359
+	}
360
+	if (empty($topic)) {
361
+			fatal_lang_error('missing_topic_id', false);
362
+	}
350 363
 
351 364
 	// Administrator, Moderator, or owner.  Period.
352 365
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -364,12 +377,14 @@  discard block
 block discarded – undo
364 377
 		if ($row = $smcFunc['db_fetch_assoc']($result))
365 378
 		{
366 379
 			// Not the owner of the topic.
367
-			if ($row['id_member_started'] != $user_info['id'])
368
-				fatal_lang_error('not_your_topic', 'user');
380
+			if ($row['id_member_started'] != $user_info['id']) {
381
+							fatal_lang_error('not_your_topic', 'user');
382
+			}
369 383
 		}
370 384
 		// Topic/Board doesn't exist.....
371
-		else
372
-			fatal_lang_error('calendar_no_topic', 'general');
385
+		else {
386
+					fatal_lang_error('calendar_no_topic', 'general');
387
+		}
373 388
 		$smcFunc['db_free_result']($result);
374 389
 	}
375 390
 }
@@ -457,14 +472,16 @@  discard block
 block discarded – undo
457 472
 	if (!empty($calendarOptions['start_day']))
458 473
 	{
459 474
 		$nShift -= $calendarOptions['start_day'];
460
-		if ($nShift < 0)
461
-			$nShift = 7 + $nShift;
475
+		if ($nShift < 0) {
476
+					$nShift = 7 + $nShift;
477
+		}
462 478
 	}
463 479
 
464 480
 	// Number of rows required to fit the month.
465 481
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
466
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
467
-		$nRows++;
482
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
483
+			$nRows++;
484
+	}
468 485
 
469 486
 	// Fetch the arrays for birthdays, posted events, and holidays.
470 487
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -477,8 +494,9 @@  discard block
 block discarded – undo
477 494
 	{
478 495
 		$calendarGrid['week_days'][] = $count;
479 496
 		$count++;
480
-		if ($count == 7)
481
-			$count = 0;
497
+		if ($count == 7) {
498
+					$count = 0;
499
+		}
482 500
 	}
483 501
 
484 502
 	// Iterate through each week.
@@ -495,8 +513,9 @@  discard block
 block discarded – undo
495 513
 		{
496 514
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
497 515
 
498
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
499
-				$nDay = 0;
516
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
517
+							$nDay = 0;
518
+			}
500 519
 
501 520
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
502 521
 
@@ -514,8 +533,9 @@  discard block
 block discarded – undo
514 533
 	}
515 534
 
516 535
 	// What is the last day of the month?
517
-	if ($is_previous === true)
518
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
536
+	if ($is_previous === true) {
537
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
538
+	}
519 539
 
520 540
 	// We'll use the shift in the template.
521 541
 	$calendarGrid['shift'] = $nShift;
@@ -549,8 +569,9 @@  discard block
 block discarded – undo
549 569
 	{
550 570
 		// Here we offset accordingly to get things to the real start of a week.
551 571
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
552
-		if ($date_diff < 0)
553
-			$date_diff += 7;
572
+		if ($date_diff < 0) {
573
+					$date_diff += 7;
574
+		}
554 575
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
555 576
 		$day = (int) strftime('%d', $new_timestamp);
556 577
 		$month = (int) strftime('%m', $new_timestamp);
@@ -680,18 +701,20 @@  discard block
 block discarded – undo
680 701
 	{
681 702
 		foreach ($date_events as $event_key => $event_val)
682 703
 		{
683
-			if (in_array($event_val['id'], $temp))
684
-				unset($calendarGrid['events'][$date][$event_key]);
685
-			else
686
-				$temp[] = $event_val['id'];
704
+			if (in_array($event_val['id'], $temp)) {
705
+							unset($calendarGrid['events'][$date][$event_key]);
706
+			} else {
707
+							$temp[] = $event_val['id'];
708
+			}
687 709
 		}
688 710
 	}
689 711
 
690 712
 	// Give birthdays and holidays a friendly format, without the year
691
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
692
-		$date_format = '%b %d';
693
-	else
694
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
713
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
714
+			$date_format = '%b %d';
715
+	} else {
716
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
717
+	}
695 718
 
696 719
 	foreach (array('birthdays', 'holidays') as $type)
697 720
 	{
@@ -790,8 +813,9 @@  discard block
 block discarded – undo
790 813
 		// Holidays between now and now + days.
791 814
 		for ($i = $now; $i < $now + $days_for_index; $i += 86400)
792 815
 		{
793
-			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
794
-				$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
816
+			if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
817
+							$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
818
+			}
795 819
 		}
796 820
 	}
797 821
 	
@@ -803,8 +827,9 @@  discard block
 block discarded – undo
803 827
 			$loop_date = strftime('%Y-%m-%d', $i);
804 828
 			if (isset($cached_data['birthdays'][$loop_date]))
805 829
 			{
806
-				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
807
-					$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
830
+				foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
831
+									$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
832
+				}
808 833
 				$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
809 834
 			}
810 835
 		}	
@@ -819,8 +844,9 @@  discard block
 block discarded – undo
819 844
 			$loop_date = strftime('%Y-%m-%d', $i);
820 845
 
821 846
 			// No events today? Check the next day.
822
-			if (empty($cached_data['events'][$loop_date]))
823
-				continue;
847
+			if (empty($cached_data['events'][$loop_date])) {
848
+							continue;
849
+			}
824 850
 
825 851
 			// Loop through all events to add a few last-minute values.
826 852
 			foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -833,9 +859,9 @@  discard block
 block discarded – undo
833 859
 				{
834 860
 					unset($cached_data['events'][$loop_date][$ev]);
835 861
 					continue;
862
+				} else {
863
+									$duplicates[$this_event['topic'] . $this_event['title']] = true;
836 864
 				}
837
-				else
838
-					$duplicates[$this_event['topic'] . $this_event['title']] = true;
839 865
 
840 866
 				// Might be set to true afterwards, depending on the permissions.
841 867
 				$this_event['can_edit'] = false;
@@ -843,16 +869,19 @@  discard block
 block discarded – undo
843 869
 				$this_event['date'] = $loop_date;
844 870
 			}
845 871
 
846
-			if (!empty($cached_data['events'][$loop_date]))
847
-				$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
872
+			if (!empty($cached_data['events'][$loop_date])) {
873
+							$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
874
+			}
848 875
 		}
849 876
 	}
850 877
 
851 878
 	// Mark the last item so that a list separator can be used in the template.
852
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
853
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
854
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
855
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
879
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
880
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
881
+	}
882
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
883
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
884
+	}
856 885
 
857 886
 	return array(
858 887
 		'data' => $return_data,
@@ -900,37 +929,46 @@  discard block
 block discarded – undo
900 929
 		if (isset($_POST['start_date']))
901 930
 		{
902 931
 			$d = date_parse($_POST['start_date']);
903
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
904
-				fatal_lang_error('invalid_date', false);
905
-			if (empty($d['year']))
906
-				fatal_lang_error('event_year_missing', false);
907
-			if (empty($d['month']))
908
-				fatal_lang_error('event_month_missing', false);
909
-		}
910
-		elseif (isset($_POST['start_datetime']))
932
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
933
+							fatal_lang_error('invalid_date', false);
934
+			}
935
+			if (empty($d['year'])) {
936
+							fatal_lang_error('event_year_missing', false);
937
+			}
938
+			if (empty($d['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+		} elseif (isset($_POST['start_datetime']))
911 942
 		{
912 943
 			$d = date_parse($_POST['start_datetime']);
913
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
914
-				fatal_lang_error('invalid_date', false);
915
-			if (empty($d['year']))
916
-				fatal_lang_error('event_year_missing', false);
917
-			if (empty($d['month']))
918
-				fatal_lang_error('event_month_missing', false);
944
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
945
+							fatal_lang_error('invalid_date', false);
946
+			}
947
+			if (empty($d['year'])) {
948
+							fatal_lang_error('event_year_missing', false);
949
+			}
950
+			if (empty($d['month'])) {
951
+							fatal_lang_error('event_month_missing', false);
952
+			}
919 953
 		}
920 954
 		// The 2.0 way
921 955
 		else
922 956
 		{
923 957
 			// No month?  No year?
924
-			if (!isset($_POST['month']))
925
-				fatal_lang_error('event_month_missing', false);
926
-			if (!isset($_POST['year']))
927
-				fatal_lang_error('event_year_missing', false);
958
+			if (!isset($_POST['month'])) {
959
+							fatal_lang_error('event_month_missing', false);
960
+			}
961
+			if (!isset($_POST['year'])) {
962
+							fatal_lang_error('event_year_missing', false);
963
+			}
928 964
 
929 965
 			// Check the month and year...
930
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
931
-				fatal_lang_error('invalid_month', false);
932
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
933
-				fatal_lang_error('invalid_year', false);
966
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
967
+							fatal_lang_error('invalid_month', false);
968
+			}
969
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
970
+							fatal_lang_error('invalid_year', false);
971
+			}
934 972
 		}
935 973
 	}
936 974
 
@@ -940,8 +978,9 @@  discard block
 block discarded – undo
940 978
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
941 979
 	if (isset($_POST['span']))
942 980
 	{
943
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
944
-			fatal_lang_error('invalid_days_numb', false);
981
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
982
+					fatal_lang_error('invalid_days_numb', false);
983
+		}
945 984
 	}
946 985
 
947 986
 	// There is no need to validate the following values if we are just deleting the event.
@@ -951,24 +990,29 @@  discard block
 block discarded – undo
951 990
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
952 991
 		{
953 992
 			// No day?
954
-			if (!isset($_POST['day']))
955
-				fatal_lang_error('event_day_missing', false);
993
+			if (!isset($_POST['day'])) {
994
+							fatal_lang_error('event_day_missing', false);
995
+			}
956 996
 
957 997
 			// Bad day?
958
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
959
-				fatal_lang_error('invalid_date', false);
998
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
999
+							fatal_lang_error('invalid_date', false);
1000
+			}
960 1001
 		}
961 1002
 
962
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
963
-			fatal_lang_error('event_title_missing', false);
964
-		elseif (!isset($_POST['evtitle']))
965
-			$_POST['evtitle'] = $_POST['subject'];
1003
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
1004
+					fatal_lang_error('event_title_missing', false);
1005
+		} elseif (!isset($_POST['evtitle'])) {
1006
+					$_POST['evtitle'] = $_POST['subject'];
1007
+		}
966 1008
 
967 1009
 		// No title?
968
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
969
-			fatal_lang_error('no_event_title', false);
970
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
971
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1010
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
1011
+					fatal_lang_error('no_event_title', false);
1012
+		}
1013
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
1014
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
1015
+		}
972 1016
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
973 1017
 	}
974 1018
 }
@@ -995,8 +1039,9 @@  discard block
 block discarded – undo
995 1039
 	);
996 1040
 
997 1041
 	// No results, return false.
998
-	if ($smcFunc['db_num_rows'] === 0)
999
-		return false;
1042
+	if ($smcFunc['db_num_rows'] === 0) {
1043
+			return false;
1044
+	}
1000 1045
 
1001 1046
 	// Grab the results and return.
1002 1047
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1130,8 +1175,9 @@  discard block
 block discarded – undo
1130 1175
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1131 1176
 
1132 1177
 	$column_clauses = array();
1133
-	foreach ($event_columns as $col => $crit)
1134
-		$column_clauses[] = $col . ' = ' . $crit;
1178
+	foreach ($event_columns as $col => $crit) {
1179
+			$column_clauses[] = $col . ' = ' . $crit;
1180
+	}
1135 1181
 
1136 1182
 	$smcFunc['db_query']('', '
1137 1183
 		UPDATE {db_prefix}calendar
@@ -1216,8 +1262,9 @@  discard block
 block discarded – undo
1216 1262
 	);
1217 1263
 
1218 1264
 	// If nothing returned, we are in poo, poo.
1219
-	if ($smcFunc['db_num_rows']($request) === 0)
1220
-		return false;
1265
+	if ($smcFunc['db_num_rows']($request) === 0) {
1266
+			return false;
1267
+	}
1221 1268
 
1222 1269
 	$row = $smcFunc['db_fetch_assoc']($request);
1223 1270
 	$smcFunc['db_free_result']($request);
@@ -1225,8 +1272,9 @@  discard block
 block discarded – undo
1225 1272
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1226 1273
 
1227 1274
 	// Sanity check
1228
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1229
-		return false;
1275
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1276
+			return false;
1277
+	}
1230 1278
 
1231 1279
 	$return_value = array(
1232 1280
 		'boards' => array(),
@@ -1363,24 +1411,27 @@  discard block
 block discarded – undo
1363 1411
 
1364 1412
 	// Set $span, in case we need it
1365 1413
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1366
-	if ($span > 0)
1367
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1414
+	if ($span > 0) {
1415
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1416
+	}
1368 1417
 
1369 1418
 	// Define the timezone for this event, falling back to the default if not provided
1370
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1371
-		$tz = $eventOptions['tz'];
1372
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1373
-		$tz = $_POST['tz'];
1374
-	else
1375
-		$tz = getUserTimezone();
1419
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1420
+			$tz = $eventOptions['tz'];
1421
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1422
+			$tz = $_POST['tz'];
1423
+	} else {
1424
+			$tz = getUserTimezone();
1425
+	}
1376 1426
 
1377 1427
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1378
-	if (isset($eventOptions['allday']))
1379
-		$allday = $eventOptions['allday'];
1380
-	elseif (empty($_POST['allday']))
1381
-		$allday = false;
1382
-	else
1383
-		$allday = true;
1428
+	if (isset($eventOptions['allday'])) {
1429
+			$allday = $eventOptions['allday'];
1430
+	} elseif (empty($_POST['allday'])) {
1431
+			$allday = false;
1432
+	} else {
1433
+			$allday = true;
1434
+	}
1384 1435
 
1385 1436
 	// Input might come as individual parameters...
1386 1437
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1407,10 +1458,12 @@  discard block
 block discarded – undo
1407 1458
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1408 1459
 
1409 1460
 	// If the date and time were given in separate strings, combine them
1410
-	if (empty($start_string) && isset($start_date_string))
1411
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1412
-	if (empty($end_string) && isset($end_date_string))
1413
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1461
+	if (empty($start_string) && isset($start_date_string)) {
1462
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1463
+	}
1464
+	if (empty($end_string) && isset($end_date_string)) {
1465
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1466
+	}
1414 1467
 
1415 1468
 	// If some form of string input was given, override individually defined options with it
1416 1469
 	if (isset($start_string))
@@ -1501,10 +1554,11 @@  discard block
 block discarded – undo
1501 1554
 	if ($start_object >= $end_object)
1502 1555
 	{
1503 1556
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1504
-		if ($span > 0)
1505
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1506
-		else
1507
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1557
+		if ($span > 0) {
1558
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1559
+		} else {
1560
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1561
+		}
1508 1562
 	}
1509 1563
 
1510 1564
 	// Is $end_object too late?
@@ -1517,9 +1571,9 @@  discard block
 block discarded – undo
1517 1571
 			{
1518 1572
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1519 1573
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1574
+			} else {
1575
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1520 1576
 			}
1521
-			else
1522
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1523 1577
 		}
1524 1578
 	}
1525 1579
 
@@ -1532,8 +1586,7 @@  discard block
 block discarded – undo
1532 1586
 		$start_time = null;
1533 1587
 		$end_time = null;
1534 1588
 		$tz = null;
1535
-	}
1536
-	else
1589
+	} else
1537 1590
 	{
1538 1591
 		$start_time = date_format($start_object, 'H:i:s');
1539 1592
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1559,19 +1612,21 @@  discard block
 block discarded – undo
1559 1612
 	// First, try to create a better date format, ignoring the "time" elements.
1560 1613
 	if (empty($date_format))
1561 1614
 	{
1562
-		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1563
-			$date_format = '%F';
1564
-		else
1565
-			$date_format = $matches[0];
1615
+		if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1616
+					$date_format = '%F';
1617
+		} else {
1618
+					$date_format = $matches[0];
1619
+		}
1566 1620
 	}
1567 1621
 
1568 1622
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1569 1623
 	if (empty($time_format))
1570 1624
 	{
1571
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1572
-			$time_format = '%k:%M';
1573
-		else
1574
-			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1625
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1626
+					$time_format = '%k:%M';
1627
+		} else {
1628
+					$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1629
+		}
1575 1630
 	}
1576 1631
 
1577 1632
 	// Should this be an all day event?
@@ -1581,11 +1636,13 @@  discard block
 block discarded – undo
1581 1636
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1582 1637
 
1583 1638
 	// We need to have a defined timezone in the steps below
1584
-	if (empty($row['timezone']))
1585
-		$row['timezone'] = getUserTimezone();
1639
+	if (empty($row['timezone'])) {
1640
+			$row['timezone'] = getUserTimezone();
1641
+	}
1586 1642
 
1587
-	if (empty($timezone_array[$row['timezone']]))
1588
-		$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1643
+	if (empty($timezone_array[$row['timezone']])) {
1644
+			$timezone_array[$row['timezone']] = timezone_open($row['timezone']);
1645
+	}
1589 1646
 
1590 1647
 	// Get most of the standard date information for the start and end datetimes
1591 1648
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1633,8 +1690,9 @@  discard block
 block discarded – undo
1633 1690
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1634 1691
 	static $member_cache = array();
1635 1692
 
1636
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1637
-		$id_member = $context['user']['id'];
1693
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1694
+			$id_member = $context['user']['id'];
1695
+	}
1638 1696
 
1639 1697
 	//check if the cache got the data
1640 1698
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1663,11 +1721,13 @@  discard block
 block discarded – undo
1663 1721
 		$smcFunc['db_free_result']($request);
1664 1722
 	}
1665 1723
 
1666
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1667
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1724
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1725
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1726
+	}
1668 1727
 
1669
-	if (isset($id_member))
1670
-		$member_cache[$id_member] = $timezone;
1728
+	if (isset($id_member)) {
1729
+			$member_cache[$id_member] = $timezone;
1730
+	}
1671 1731
 
1672 1732
 	return $timezone;
1673 1733
 }
@@ -1696,8 +1756,9 @@  discard block
 block discarded – undo
1696 1756
 		)
1697 1757
 	);
1698 1758
 	$holidays = array();
1699
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1700
-		$holidays[] = $row;
1759
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1760
+			$holidays[] = $row;
1761
+	}
1701 1762
 	$smcFunc['db_free_result']($request);
1702 1763
 
1703 1764
 	return $holidays;
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 		<strong>
29 29
 			', $context['error_title'], '
30 30
 		</strong><br>
31 31
 		<div ', $context['error_code'], 'class="padding">', $context['error_message'], '</div>';
32
-	else
32
+	} else
33 33
 	{
34 34
 		echo '
35 35
 	<div id="fatal_error">
@@ -82,21 +82,23 @@  discard block
 block discarded – undo
82 82
 						&nbsp;&nbsp;', $txt['apply_filter_of_type'], ':';
83 83
 
84 84
 	$error_types = array();
85
-	foreach ($context['error_types'] as $type => $details)
86
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
85
+	foreach ($context['error_types'] as $type => $details) {
86
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
87
+	}
87 88
 
88 89
 	echo '
89 90
 						', implode('&nbsp;|&nbsp;', $error_types), '
90 91
 					</td>
91 92
 				</tr>';
92 93
 
93
-	if ($context['has_filter'])
94
-		echo '
94
+	if ($context['has_filter']) {
95
+			echo '
95 96
 				<tr>
96 97
 					<td colspan="3" class="windowbg">
97 98
 						<strong>&nbsp;&nbsp;', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], '&nbsp;&nbsp;[<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
98 99
 					</td>
99 100
 				</tr>';
101
+	}
100 102
 
101 103
 	echo '
102 104
 				<tr>
@@ -107,11 +109,12 @@  discard block
 block discarded – undo
107 109
 				</tr>';
108 110
 
109 111
 	// No errors, then show a message
110
-	if (count($context['errors']) == 0)
111
-		echo '
112
+	if (count($context['errors']) == 0) {
113
+			echo '
112 114
 				<tr class="windowbg">
113 115
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
114 116
 				</tr>';
117
+	}
115 118
 
116 119
 	// we have some errors, must be some mods installed :P
117 120
 	foreach ($context['errors'] as $error)
@@ -125,19 +128,21 @@  discard block
 block discarded – undo
125 128
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
126 129
 							', $error['time'], '<br>';
127 130
 
128
-		if (!empty($error['member']['ip']))
129
-			echo '
131
+		if (!empty($error['member']['ip'])) {
132
+					echo '
130 133
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
131 134
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>&nbsp;&nbsp;<br>';
135
+		}
132 136
 
133 137
 		echo '
134 138
 						</div>
135 139
 						<div style="float: left; width: 50%; line-height: 1.8em; padding: 0 4px;">';
136 140
 
137
-		if ($error['member']['session'] != '')
138
-			echo '
141
+		if ($error['member']['session'] != '') {
142
+					echo '
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=error_type;value=', $error['error_type']['type'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_type'], '"><span class="generic_icons filter centericon"></span></a>
@@ -151,8 +156,8 @@  discard block
 block discarded – undo
151 156
 							<a style="display: table-cell;" href="', $error['url']['html'], '">', $error['url']['html'], '</a>
152 157
 						</div>';
153 158
 
154
-		if (!empty($error['file']))
155
-			echo '
159
+		if (!empty($error['file'])) {
160
+					echo '
156 161
 						<div style="float: left; width: 100%; padding: 4px 0; line-height: 1.6em; border-top: 1px solid #e3e3e3;">
157 162
 							<a style="display: table-cell; padding: 4px; width: 20px; vertical-align: top;" href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '"><span class="generic_icons filter"></span></a>
158 163
 							<div>
@@ -160,6 +165,7 @@  discard block
 block discarded – undo
160 165
 								', $txt['line'], ': ', $error['file']['line'], '
161 166
 							</div>
162 167
 						</div>';
168
+		}
163 169
 
164 170
 		echo '
165 171
 					</td>
@@ -187,9 +193,10 @@  discard block
 block discarded – undo
187 193
 				</div>
188 194
 			</div>';
189 195
 
190
-	if ($context['sort_direction'] == 'down')
191
-		echo '
196
+	if ($context['sort_direction'] == 'down') {
197
+			echo '
192 198
 			<input type="hidden" name="desc" value="1">';
199
+	}
193 200
 
194 201
 	echo '
195 202
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +158 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -127,10 +132,11 @@  discard block
 block discarded – undo
127 132
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
128 133
 
129 134
 			// If we're preserving the cookie, reset it with updated salt
130
-			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
131
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
132
-			else
133
-				setTFACookie(-3600, 0, '');
135
+			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
136
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
137
+			} else {
138
+							setTFACookie(-3600, 0, '');
139
+			}
134 140
 		}
135 141
 
136 142
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -141,20 +147,20 @@  discard block
 block discarded – undo
141 147
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
142 148
 	{
143 149
 		// Strike!  You're outta there!
144
-		if ($_GET['member'] != $user_info['id'])
145
-			fatal_lang_error('login_cookie_error', false);
150
+		if ($_GET['member'] != $user_info['id']) {
151
+					fatal_lang_error('login_cookie_error', false);
152
+		}
146 153
 
147 154
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
148 155
 
149 156
 		// Some whitelisting for login_url...
150
-		if (empty($_SESSION['login_url']))
151
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
152
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157
+		if (empty($_SESSION['login_url'])) {
158
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
159
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
153 160
 		{
154 161
 			unset ($_SESSION['login_url']);
155 162
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		}
157
-		else
163
+		} else
158 164
 		{
159 165
 			// Best not to clutter the session data too much...
160 166
 			$temp = $_SESSION['login_url'];
@@ -165,8 +171,9 @@  discard block
 block discarded – undo
165 171
 	}
166 172
 
167 173
 	// Beyond this point you are assumed to be a guest trying to login.
168
-	if (!$user_info['is_guest'])
169
-		redirectexit();
174
+	if (!$user_info['is_guest']) {
175
+			redirectexit();
176
+	}
170 177
 
171 178
 	// Are you guessing with a script?
172 179
 	checkSession();
@@ -174,18 +181,21 @@  discard block
 block discarded – undo
174 181
 	spamProtection('login');
175 182
 
176 183
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
177
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
178
-		$_SESSION['login_url'] = $_SESSION['old_url'];
184
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
185
+			$_SESSION['login_url'] = $_SESSION['old_url'];
186
+	}
179 187
 
180 188
 	// Been guessing a lot, haven't we?
181
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
182
-		fatal_lang_error('login_threshold_fail', 'login');
189
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
190
+			fatal_lang_error('login_threshold_fail', 'login');
191
+	}
183 192
 
184 193
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
185
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
186
-		$modSettings['cookieTime'] = 3153600;
187
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
188
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
194
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
195
+			$modSettings['cookieTime'] = 3153600;
196
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
197
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
198
+	}
189 199
 
190 200
 	loadLanguage('Login');
191 201
 	// Load the template stuff.
@@ -305,8 +315,9 @@  discard block
 block discarded – undo
305 315
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
306 316
 
307 317
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
308
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
309
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
318
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
319
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
320
+			}
310 321
 
311 322
 			// phpBB3 users new hashing.  We now support it as well ;).
312 323
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -326,27 +337,29 @@  discard block
 block discarded – undo
326 337
 			// Some common md5 ones.
327 338
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
328 339
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
329
-		}
330
-		elseif (strlen($user_settings['passwd']) == 40)
340
+		} elseif (strlen($user_settings['passwd']) == 40)
331 341
 		{
332 342
 			// Maybe they are using a hash from before the password fix.
333 343
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
334 344
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
335 345
 
336 346
 			// BurningBoard3 style of hashing.
337
-			if (!empty($modSettings['enable_password_conversion']))
338
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
347
+			if (!empty($modSettings['enable_password_conversion'])) {
348
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
349
+			}
339 350
 
340 351
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
341 352
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
342 353
 			{
343 354
 				// Try iconv first, for no particular reason.
344
-				if (function_exists('iconv'))
345
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
355
+				if (function_exists('iconv')) {
356
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
357
+				}
346 358
 
347 359
 				// Say it aint so, iconv failed!
348
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
349
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
360
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
361
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
362
+				}
350 363
 			}
351 364
 		}
352 365
 
@@ -376,8 +389,9 @@  discard block
 block discarded – undo
376 389
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
377 390
 
378 391
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
379
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
380
-				redirectexit('action=reminder');
392
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
393
+							redirectexit('action=reminder');
394
+			}
381 395
 			// We'll give you another chance...
382 396
 			else
383 397
 			{
@@ -388,8 +402,7 @@  discard block
 block discarded – undo
388 402
 				return;
389 403
 			}
390 404
 		}
391
-	}
392
-	elseif (!empty($user_settings['passwd_flood']))
405
+	} elseif (!empty($user_settings['passwd_flood']))
393 406
 	{
394 407
 		// Let's be sure they weren't a little hacker.
395 408
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -406,8 +419,9 @@  discard block
 block discarded – undo
406 419
 	}
407 420
 
408 421
 	// Check their activation status.
409
-	if (!checkActivation())
410
-		return;
422
+	if (!checkActivation()) {
423
+			return;
424
+	}
411 425
 
412 426
 	DoLogin();
413 427
 }
@@ -419,8 +433,9 @@  discard block
 block discarded – undo
419 433
 {
420 434
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
421 435
 
422
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
423
-		fatal_lang_error('no_access', false);
436
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
437
+			fatal_lang_error('no_access', false);
438
+	}
424 439
 
425 440
 	loadLanguage('Profile');
426 441
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -428,8 +443,9 @@  discard block
 block discarded – undo
428 443
 	$member = $context['tfa_member'];
429 444
 
430 445
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
431
-	if (time() - $member['last_login'] < 120)
432
-		fatal_lang_error('tfa_wait', false);
446
+	if (time() - $member['last_login'] < 120) {
447
+			fatal_lang_error('tfa_wait', false);
448
+	}
433 449
 
434 450
 	$totp = new \TOTP\Auth($member['tfa_secret']);
435 451
 	$totp->setRange(1);
@@ -443,8 +459,9 @@  discard block
 block discarded – undo
443 459
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
444 460
 	{
445 461
 		// Check to ensure we're forcing SSL for authentication
446
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
447
-			fatal_lang_error('login_ssl_required');
462
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
463
+					fatal_lang_error('login_ssl_required');
464
+		}
448 465
 
449 466
 		$code = $_POST['tfa_code'];
450 467
 
@@ -454,20 +471,19 @@  discard block
 block discarded – undo
454 471
 
455 472
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
456 473
 			redirectexit();
457
-		}
458
-		else
474
+		} else
459 475
 		{
460 476
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
461 477
 
462 478
 			$context['tfa_error'] = true;
463 479
 			$context['tfa_value'] = $_POST['tfa_code'];
464 480
 		}
465
-	}
466
-	elseif (!empty($_POST['tfa_backup']))
481
+	} elseif (!empty($_POST['tfa_backup']))
467 482
 	{
468 483
 		// Check to ensure we're forcing SSL for authentication
469
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
470
-			fatal_lang_error('login_ssl_required');
484
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
485
+					fatal_lang_error('login_ssl_required');
486
+		}
471 487
 
472 488
 		$backup = $_POST['tfa_backup'];
473 489
 
@@ -481,8 +497,7 @@  discard block
 block discarded – undo
481 497
 			));
482 498
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
483 499
 			redirectexit('action=profile;area=tfasetup;backup');
484
-		}
485
-		else
500
+		} else
486 501
 		{
487 502
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
488 503
 
@@ -505,8 +520,9 @@  discard block
 block discarded – undo
505 520
 {
506 521
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
507 522
 
508
-	if (!isset($context['login_errors']))
509
-		$context['login_errors'] = array();
523
+	if (!isset($context['login_errors'])) {
524
+			$context['login_errors'] = array();
525
+	}
510 526
 
511 527
 	// What is the true activation status of this account?
512 528
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -518,8 +534,9 @@  discard block
 block discarded – undo
518 534
 		return false;
519 535
 	}
520 536
 	// Awaiting approval still?
521
-	elseif ($activation_status == 3)
522
-		fatal_lang_error('still_awaiting_approval', 'user');
537
+	elseif ($activation_status == 3) {
538
+			fatal_lang_error('still_awaiting_approval', 'user');
539
+	}
523 540
 	// Awaiting deletion, changed their mind?
524 541
 	elseif ($activation_status == 4)
525 542
 	{
@@ -527,8 +544,7 @@  discard block
 block discarded – undo
527 544
 		{
528 545
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
529 546
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
530
-		}
531
-		else
547
+		} else
532 548
 		{
533 549
 			$context['disable_login_hashing'] = true;
534 550
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
569 585
 
570 586
 	// Reset the login threshold.
571
-	if (isset($_SESSION['failed_login']))
572
-		unset($_SESSION['failed_login']);
587
+	if (isset($_SESSION['failed_login'])) {
588
+			unset($_SESSION['failed_login']);
589
+	}
573 590
 
574 591
 	$user_info['is_guest'] = false;
575 592
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -591,16 +608,18 @@  discard block
 block discarded – undo
591 608
 			'id_member' => $user_info['id'],
592 609
 		)
593 610
 	);
594
-	if ($smcFunc['db_num_rows']($request) == 1)
595
-		$_SESSION['first_login'] = true;
596
-	else
597
-		unset($_SESSION['first_login']);
611
+	if ($smcFunc['db_num_rows']($request) == 1) {
612
+			$_SESSION['first_login'] = true;
613
+	} else {
614
+			unset($_SESSION['first_login']);
615
+	}
598 616
 	$smcFunc['db_free_result']($request);
599 617
 
600 618
 	// You've logged in, haven't you?
601 619
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
602
-	if (empty($user_settings['tfa_secret']))
603
-		$update['last_login'] = time();
620
+	if (empty($user_settings['tfa_secret'])) {
621
+			$update['last_login'] = time();
622
+	}
604 623
 	updateMemberData($user_info['id'], $update);
605 624
 
606 625
 	// Get rid of the online entry for that old guest....
@@ -614,8 +633,8 @@  discard block
 block discarded – undo
614 633
 	$_SESSION['log_time'] = 0;
615 634
 
616 635
 	// Log this entry, only if we have it enabled.
617
-	if (!empty($modSettings['loginHistoryDays']))
618
-		$smcFunc['db_insert']('insert',
636
+	if (!empty($modSettings['loginHistoryDays'])) {
637
+			$smcFunc['db_insert']('insert',
619 638
 			'{db_prefix}member_logins',
620 639
 			array(
621 640
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -627,13 +646,15 @@  discard block
 block discarded – undo
627 646
 				'id_member', 'time'
628 647
 			)
629 648
 		);
649
+	}
630 650
 
631 651
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
632
-	if (empty($maintenance) || allowedTo('admin_forum'))
633
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
634
-	else
635
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
636
-}
652
+	if (empty($maintenance) || allowedTo('admin_forum')) {
653
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
654
+	} else {
655
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
656
+	}
657
+	}
637 658
 
638 659
 /**
639 660
  * Logs the current user out of their account.
@@ -649,13 +670,15 @@  discard block
 block discarded – undo
649 670
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
650 671
 
651 672
 	// Make sure they aren't being auto-logged out.
652
-	if (!$internal)
653
-		checkSession('get');
673
+	if (!$internal) {
674
+			checkSession('get');
675
+	}
654 676
 
655 677
 	require_once($sourcedir . '/Subs-Auth.php');
656 678
 
657
-	if (isset($_SESSION['pack_ftp']))
658
-		$_SESSION['pack_ftp'] = null;
679
+	if (isset($_SESSION['pack_ftp'])) {
680
+			$_SESSION['pack_ftp'] = null;
681
+	}
659 682
 
660 683
 	// It won't be first login anymore.
661 684
 	unset($_SESSION['first_login']);
@@ -683,8 +706,9 @@  discard block
 block discarded – undo
683 706
 
684 707
 	// And some other housekeeping while we're at it.
685 708
 	$salt = substr(md5(mt_rand()), 0, 4);
686
-	if (!empty($user_info['id']))
687
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
709
+	if (!empty($user_info['id'])) {
710
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
711
+	}
688 712
 
689 713
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
690 714
 	{
@@ -693,10 +717,11 @@  discard block
 block discarded – undo
693 717
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
694 718
 
695 719
 		// If we're preserving the cookie, reset it with updated salt
696
-		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
697
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
698
-		else
699
-			setTFACookie(-3600, 0, '');
720
+		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
721
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
722
+		} else {
723
+					setTFACookie(-3600, 0, '');
724
+		}
700 725
 	}
701 726
 
702 727
 	session_destroy();
@@ -704,14 +729,13 @@  discard block
 block discarded – undo
704 729
 	// Off to the merry board index we go!
705 730
 	if ($redirect)
706 731
 	{
707
-		if (empty($_SESSION['logout_url']))
708
-			redirectexit('', $context['server']['needs_login_fix']);
709
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
732
+		if (empty($_SESSION['logout_url'])) {
733
+					redirectexit('', $context['server']['needs_login_fix']);
734
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
710 735
 		{
711 736
 			unset ($_SESSION['logout_url']);
712 737
 			redirectexit();
713
-		}
714
-		else
738
+		} else
715 739
 		{
716 740
 			$temp = $_SESSION['logout_url'];
717 741
 			unset($_SESSION['logout_url']);
@@ -744,8 +768,9 @@  discard block
 block discarded – undo
744 768
 function phpBB3_password_check($passwd, $passwd_hash)
745 769
 {
746 770
 	// Too long or too short?
747
-	if (strlen($passwd_hash) != 34)
748
-		return;
771
+	if (strlen($passwd_hash) != 34) {
772
+			return;
773
+	}
749 774
 
750 775
 	// Range of characters allowed.
751 776
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -756,8 +781,9 @@  discard block
 block discarded – undo
756 781
 	$salt = substr($passwd_hash, 4, 8);
757 782
 
758 783
 	$hash = md5($salt . $passwd, true);
759
-	for (; $count != 0; --$count)
760
-		$hash = md5($hash . $passwd, true);
784
+	for (; $count != 0; --$count) {
785
+			$hash = md5($hash . $passwd, true);
786
+	}
761 787
 
762 788
 	$output = substr($passwd_hash, 0, 12);
763 789
 	$i = 0;
@@ -766,21 +792,25 @@  discard block
 block discarded – undo
766 792
 		$value = ord($hash[$i++]);
767 793
 		$output .= $range[$value & 0x3f];
768 794
 
769
-		if ($i < 16)
770
-			$value |= ord($hash[$i]) << 8;
795
+		if ($i < 16) {
796
+					$value |= ord($hash[$i]) << 8;
797
+		}
771 798
 
772 799
 		$output .= $range[($value >> 6) & 0x3f];
773 800
 
774
-		if ($i++ >= 16)
775
-			break;
801
+		if ($i++ >= 16) {
802
+					break;
803
+		}
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 16;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 16;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 12) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785 815
 		$output .= $range[($value >> 18) & 0x3f];
786 816
 	}
@@ -812,8 +842,9 @@  discard block
 block discarded – undo
812 842
 		require_once($sourcedir . '/Subs-Auth.php');
813 843
 		setLoginCookie(-3600, 0);
814 844
 
815
-		if (isset($_SESSION['login_' . $cookiename]))
816
-			unset($_SESSION['login_' . $cookiename]);
845
+		if (isset($_SESSION['login_' . $cookiename])) {
846
+					unset($_SESSION['login_' . $cookiename]);
847
+		}
817 848
 	}
818 849
 
819 850
 	// We need a member!
@@ -827,8 +858,9 @@  discard block
 block discarded – undo
827 858
 	}
828 859
 
829 860
 	// Right, have we got a flood value?
830
-	if ($password_flood_value !== false)
831
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
861
+	if ($password_flood_value !== false) {
862
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
863
+	}
832 864
 
833 865
 	// Timestamp or number of tries invalid?
834 866
 	if (empty($number_tries) || empty($time_stamp))
@@ -844,15 +876,17 @@  discard block
 block discarded – undo
844 876
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
845 877
 
846 878
 		// They are trying too fast, make them wait longer
847
-		if ($time_stamp < time() - 10)
848
-			$time_stamp = time();
879
+		if ($time_stamp < time() - 10) {
880
+					$time_stamp = time();
881
+		}
849 882
 	}
850 883
 
851 884
 	$number_tries++;
852 885
 
853 886
 	// Broken the law?
854
-	if ($number_tries > 5)
855
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
887
+	if ($number_tries > 5) {
888
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
889
+	}
856 890
 
857 891
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
858 892
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.