Completed
Push — release-2.1 ( 4c82a0...64d581 )
by Rick
09:29
created
Themes/default/Printpage.template.php 1 patch
Braces   +12 added lines, -9 removed lines patch added patch discarded remove patch
@@ -145,11 +145,12 @@  discard block
 block discarded – undo
145 145
 				<div class="question">', $txt['poll_question'], ': <strong>', $context['poll']['question'], '</strong>';
146 146
 
147 147
 		$options = 1;
148
-		foreach ($context['poll']['options'] as $option)
149
-			echo '
148
+		foreach ($context['poll']['options'] as $option) {
149
+					echo '
150 150
 					<div class="', $option['voted_this'] ? 'voted' : '', '">', $txt['option'], ' ', $options++, ': <strong>', $option['option'], '</strong>
151 151
 						', $context['allow_poll_view'] ? $txt['votes'] . ': ' . $option['votes'] . '' : '', '
152 152
 					</div>';
153
+		}
153 154
 
154 155
 		echo '
155 156
 			</div>';
@@ -171,9 +172,10 @@  discard block
 block discarded – undo
171 172
 			echo '
172 173
 				<hr>';
173 174
 
174
-			foreach ($context['printattach'][$post['id_msg']] as $attach)
175
-				echo '
175
+			foreach ($context['printattach'][$post['id_msg']] as $attach) {
176
+							echo '
176 177
 					<img width="' . $attach['width'] . '" height="' . $attach['height'] . '" src="', $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attach['id_attach'] . '" alt="">';
178
+			}
177 179
 		}
178 180
 
179 181
 		echo '
@@ -213,11 +215,12 @@  discard block
 block discarded – undo
213 215
 		<div class="print_options">';
214 216
 
215 217
 	// which option is set, text or text&images
216
-	if (isset($_REQUEST['images']))
217
-		echo '
218
+	if (isset($_REQUEST['images'])) {
219
+			echo '
218 220
 			<a href="', $url_text, '">', $txt['print_page_text'], '</a> | <strong><a href="', $url_images, '">', $txt['print_page_images'], '</a></strong>';
219
-	else
220
-		echo '
221
+	} else {
222
+			echo '
221 223
 			<strong><a href="', $url_text, '">', $txt['print_page_text'], '</a></strong> | <a href="', $url_images, '">', $txt['print_page_images'], '</a>';
222
-}
224
+	}
225
+	}
223 226
 ?>
224 227
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	echo '
65 65
 			<div class="cat_bar">
66 66
 				<h3 class="catbg">
67
-					<a href="', $scripturl, '?action=helpadmin;help=error_log" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'],'"></span></a> ', $txt['errlog'], '
67
+					<a href="', $scripturl, '?action=helpadmin;help=error_log" onclick="return reqOverlayDiv(this.href);" class="help"><span class="generic_icons help" title="', $txt['help'], '"></span></a> ', $txt['errlog'], '
68 68
 				</h3>
69 69
 			</div>
70 70
 			<div class="pagesection">
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 					', $context['page_index'], '
73 73
 				</div>
74 74
 				<div class="floatright">
75
-					<input type="submit" name="removeSelection" value="', $txt['remove_selection'] ,'" data-confirm="', $txt['remove_selection_confirm'] ,'" class="button_submit you_sure">
76
-					<input type="submit" name="delall" value="', ($context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all']) ,'" data-confirm="', ($context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove']) ,'" class="button_submit you_sure">
75
+					<input type="submit" name="removeSelection" value="', $txt['remove_selection'], '" data-confirm="', $txt['remove_selection_confirm'], '" class="button_submit you_sure">
76
+					<input type="submit" name="delall" value="', ($context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all']), '" data-confirm="', ($context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove']), '" class="button_submit you_sure">
77 77
 				</div>
78 78
 			</div>
79 79
 			<table class="table_grid" id="error_log">
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 					', $context['page_index'], '
185 185
 				</div>
186 186
 				<div class="floatright">
187
-					<input type="submit" name="removeSelection" value="', $txt['remove_selection'] ,'" data-confirm="', $txt['remove_selection_confirm'] ,'" class="button_submit you_sure">
188
-					<input type="submit" name="delall" value="', ($context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all']) ,'" data-confirm="', ($context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove']) ,'" class="button_submit you_sure">
187
+					<input type="submit" name="removeSelection" value="', $txt['remove_selection'], '" data-confirm="', $txt['remove_selection_confirm'], '" class="button_submit you_sure">
188
+					<input type="submit" name="delall" value="', ($context['has_filter'] ? $txt['remove_filtered_results'] : $txt['remove_all']), '" data-confirm="', ($context['has_filter'] ? $txt['remove_filtered_results_confirm'] : $txt['sure_about_errorlog_remove']), '" class="button_submit you_sure">
189 189
 				</div>
190 190
 			</div>
191 191
 			<br>';
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	<head>
216 216
 		<meta charset="', $context['character_set'], '">
217 217
 		<title>', $context['file_data']['file'], '</title>
218
-		<link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'] ,'">
218
+		<link rel="stylesheet" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css', $modSettings['browser_cache'], '">
219 219
 	</head>
220 220
 	<body>
221 221
 		<table class="errorfile_table">';
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
 		$is_target = $line_num == $context['file_data']['target'];
226 226
 		echo '
227 227
 			<tr>
228
-				<td class="righttext', $is_target ? ' current">==&gt;' : '">', $line_num , ':</td>
229
-				<td style="white-space: nowrap;', $is_target ? ' border: 1px solid black;border-width: 1px 1px 1px 0;':'','">', $line, '</td>
228
+				<td class="righttext', $is_target ? ' current">==&gt;' : '">', $line_num, ':</td>
229
+				<td style="white-space: nowrap;', $is_target ? ' border: 1px solid black;border-width: 1px 1px 1px 0;' : '', '">', $line, '</td>
230 230
 			</tr>';
231 231
 	}
232 232
 	echo '
Please login to merge, or discard this patch.
Themes/default/BoardIndex.template.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 		foreach ($context['news_lines'] as $news)
35 35
 		{
36 36
 			echo '
37
-			<li>', $news,'</li>';
37
+			<li>', $news, '</li>';
38 38
 		}
39 39
 
40 40
 		echo '
41 41
 		</ul>
42 42
 		<script>
43 43
 			jQuery("#smf_slider").slippry({
44
-				pause: ', $settings['newsfader_time'],',
44
+				pause: ', $settings['newsfader_time'], ',
45 45
 				adaptiveHeight: 0,
46 46
 				captions: 0,
47 47
 				controls: 0,
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 		// If this category even can collapse, show a link to collapse it.
79 79
 		if ($category['can_collapse'])
80 80
 			echo '
81
-					<span id="category_', $category['id'], '_upshrink" class="', $category['is_collapsed'] ? 'toggle_down' : 'toggle_up', ' floatright" data-collapsed="', (int) $category['is_collapsed'], '" title="', !$category['is_collapsed'] ? $txt['hide_category'] : $txt['show_category'] ,'" style="display: none;"></span>';
81
+					<span id="category_', $category['id'], '_upshrink" class="', $category['is_collapsed'] ? 'toggle_down' : 'toggle_up', ' floatright" data-collapsed="', (int) $category['is_collapsed'], '" title="', !$category['is_collapsed'] ? $txt['hide_category'] : $txt['show_category'], '" style="display: none;"></span>';
82 82
 
83 83
 		echo '
84 84
 					', $category['link'], '
85 85
 				</h3>', !empty($category['description']) ? '
86 86
 				<div class="desc">' . $category['description'] . '</div>' : '', '
87 87
 			</div>
88
-			<div id="category_', $category['id'], '_boards" ', (!empty($category['css_class']) ? ('class="'. $category['css_class'] .'"') : '') ,'>';
88
+			<div id="category_', $category['id'], '_boards" ', (!empty($category['css_class']) ? ('class="' . $category['css_class'] . '"') : ''), '>';
89 89
 
90 90
 			/* Each board in each category's boards has:
91 91
 			new (is it new?), id, name, description, moderators (see below), link_moderators (just a list.),
@@ -94,14 +94,14 @@  discard block
 block discarded – undo
94 94
 			foreach ($category['boards'] as $board)
95 95
 			{
96 96
 				echo '
97
-				<div id="board_', $board['id'], '" class="up_contain ', (!empty($board['css_class']) ? $board['css_class'] : '') ,'">
97
+				<div id="board_', $board['id'], '" class="up_contain ', (!empty($board['css_class']) ? $board['css_class'] : ''), '">
98 98
 					<div class="board_icon">
99 99
 						<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '" class="board_', $board['board_class'], '"', !empty($board['board_tooltip']) ? ' title="' . $board['board_tooltip'] . '"' : '', '></a>
100 100
 					</div>
101 101
 					<div class="info">
102 102
 						<a class="subject mobile_subject" href="', $board['href'], '" id="b', $board['id'], '">
103 103
 							', $board['name'], '
104
-							<p class="board_description mobile_display">', $board['description'] , '</p>
104
+							<p class="board_description mobile_display">', $board['description'], '</p>
105 105
 						</a>';
106 106
 
107 107
 				// Has it outstanding posts for approval?
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
111 111
 
112 112
 				echo '
113
-						<p class="board_description">', $board['description'] , '</p>';
113
+						<p class="board_description">', $board['description'], '</p>';
114 114
 
115 115
 				// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
116 116
 				if (!empty($board['link_moderators']))
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 						', $board['is_redirect'] ? '' : '<br> ' . comma_format($board['topics']) . ' ' . $txt['board_topics'], '
126 126
 						</p>
127 127
 					</div>
128
-					<div class="lastpost ',!empty($board['last_post']['id']) ? 'lpr_border' : 'hidden','">';
128
+					<div class="lastpost ',!empty($board['last_post']['id']) ? 'lpr_border' : 'hidden', '">';
129 129
 
130 130
 				if (!empty($board['last_post']['id']))
131 131
 					echo '
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 				</h4>
375 375
 			</div>
376 376
 			<p class="inline">
377
-				', $context['common_stats']['boardindex_total_posts'], '', !empty($settings['show_latest_member']) ? ' - '. $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', '<br>
377
+				', $context['common_stats']['boardindex_total_posts'], '', !empty($settings['show_latest_member']) ? ' - ' . $txt['latest_member'] . ': <strong> ' . $context['common_stats']['latest_member']['link'] . '</strong>' : '', '<br>
378 378
 				', (!empty($context['latest_post']) ? $txt['latest_post'] . ': <strong>&quot;' . $context['latest_post']['link'] . '&quot;</strong>  (' . $context['latest_post']['time'] . ')<br>' : ''), '
379 379
 				<a href="', $scripturl, '?action=recent">', $txt['recent_view'], '</a>
380 380
 			</p>';
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 		// Showing membergroups?
423 423
 		if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
424 424
 			echo '
425
-				<span class="membergroups">' . implode(',&nbsp;', $context['membergroups']). '</span>';
425
+				<span class="membergroups">' . implode(',&nbsp;', $context['membergroups']) . '</span>';
426 426
 	}
427 427
 
428 428
 	echo '
Please login to merge, or discard this patch.
Themes/default/MessageIndex.template.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 					<div class="info">
45 45
 						<a class="subject mobile_subject" href="', $board['href'], '" id="b', $board['id'], '">
46 46
 							', $board['name'], '
47
-							<p class="board_description mobile_display">', $board['description'] , '</p>
47
+							<p class="board_description mobile_display">', $board['description'], '</p>
48 48
 						</a>';
49 49
 
50 50
 			// Has it outstanding posts for approval?
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 						<a href="', $scripturl, '?action=moderate;area=postmod;sa=', ($board['unapproved_topics'] > 0 ? 'topics' : 'posts'), ';brd=', $board['id'], ';', $context['session_var'], '=', $context['session_id'], '" title="', sprintf($txt['unapproved_posts'], $board['unapproved_topics'], $board['unapproved_posts']), '" class="moderation_link">(!)</a>';
54 54
 
55 55
 			echo '
56
-						<p class="board_description">', $board['description'] , '</p>';
56
+						<p class="board_description">', $board['description'], '</p>';
57 57
 
58 58
 			// Show the "Moderators: ". Each has name, href, link, and id. (but we're gonna use link_moderators.)
59 59
 			if (!empty($board['moderators']) || !empty($board['moderator_groups']))
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	// Mobile action buttons (top)
120 120
 	echo '
121 121
 		<div class="mobile_buttons floatright">
122
-			<a class="button mobile_act">', $txt['mobile_action'],'</a>
122
+			<a class="button mobile_act">', $txt['mobile_action'], '</a>
123 123
 		</div>';
124 124
 
125 125
 		echo '
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 					<img src="', $topic['first_post']['icon_url'], '" alt="">
220 220
 					', $topic['is_posted_in'] ? '<img class="posted" src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="">' : '', '
221 221
 				</div>
222
-					<div class="info', !empty($context['can_quick_mod']) ? '' : ' info_block','">
222
+					<div class="info', !empty($context['can_quick_mod']) ? '' : ' info_block', '">
223 223
 						<div ', (!empty($topic['quick_mod']['modify']) ? 'id="topic_' . $topic['first_post']['id'] . '"  ondblclick="oQuickModifyTopic.modify_topic(\'' . $topic['id'] . '\', \'' . $topic['first_post']['id'] . '\');"' : ''), '>';
224 224
 
225 225
 			// Now we handle the icons
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 								</span>
252 252
 							</div>
253 253
 							<p class="floatleft">', $txt['started_by'], ' ', $topic['first_post']['member']['link'], '</p>
254
-							', !empty($topic['pages']) ? '<span id="pages'. $topic['first_post']['id']. '" class="topic_pages">&nbsp;'. $topic['pages']. '</span>' : '','
254
+							', !empty($topic['pages']) ? '<span id="pages' . $topic['first_post']['id'] . '" class="topic_pages">&nbsp;' . $topic['pages'] . '</span>' : '', '
255 255
 							<br class="clear">
256 256
 						</div>
257 257
 					</div>
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 			foreach ($context['qmod_actions'] as $qmod_action)
306 306
 				if ($context['can_' . $qmod_action])
307 307
 					echo '
308
-						<option value="' . $qmod_action . '">' . $txt['quick_mod_'  . $qmod_action] . '</option>';
308
+						<option value="' . $qmod_action . '">' . $txt['quick_mod_' . $qmod_action] . '</option>';
309 309
 
310 310
 			echo '
311 311
 					</select>';
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	// Mobile action buttons (bottom)
333 333
 	echo '
334 334
 		<div class="mobile_buttons floatright">
335
-			<a class="button mobile_act">', $txt['mobile_action'],'</a>
335
+			<a class="button mobile_act">', $txt['mobile_action'], '</a>
336 336
 		</div>';
337 337
 
338 338
 		echo '
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	echo '
383 383
 			<div id="mobile_action" class="popup_container">
384 384
 				<div class="popup_window description">
385
-					<div class="popup_heading">', $txt['mobile_action'],'
385
+					<div class="popup_heading">', $txt['mobile_action'], '
386 386
 					<a href="javascript:void(0);" class="generic_icons hide_popup"></a></div>
387 387
 					', template_button_strip($context['normal_buttons']), '
388 388
 				</div>
Please login to merge, or discard this patch.
Themes/default/Xml.template.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 <smf>
48 48
 	<subject><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>
49 49
 	<message id="msg_', $context['message']['id'], '"><![CDATA[', cleanXml($context['message']['body']), ']]></message>
50
-	<reason time="', $context['message']['reason']['time'] ,'" name="', $context['message']['reason']['name'] ,'"><![CDATA[', cleanXml($context['message']['reason']['text']), ']]></reason>
50
+	<reason time="', $context['message']['reason']['time'], '" name="', $context['message']['reason']['name'], '"><![CDATA[', cleanXml($context['message']['reason']['text']), ']]></reason>
51 51
 </smf>';
52 52
 
53 53
 }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		// Build our string of info about when and why it was modified
68 68
 
69 69
 		$modified = empty($context['message']['modified']['time']) ? '' : sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']);
70
-		$modified .= empty($context['message']['modified']['reason']) ? '' : ' '. sprintf($txt['last_edit_reason'], $context['message']['modified']['reason']);
70
+		$modified .= empty($context['message']['modified']['reason']) ? '' : ' ' . sprintf($txt['last_edit_reason'], $context['message']['modified']['reason']);
71 71
 
72 72
 		echo '
73 73
 		<modified><![CDATA[', empty($modified) ? '' : cleanXml('&#171; <em>' . $modified . '</em>&#187;'), ']]></modified>
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 						$replacement[$key] = 'null';
253 253
 					if (!isValidIP($value))
254 254
 						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
255
-					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
255
+					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
256 256
 				}
257 257
 
258 258
 				return implode(', ', $replacement);
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
  * @param bool $translate_human_wildcards If true, turns human readable wildcards into SQL wildcards.
812 812
  * @return string The escaped string
813 813
  */
814
-function smf_db_escape_wildcard_string($string, $translate_human_wildcards=false)
814
+function smf_db_escape_wildcard_string($string, $translate_human_wildcards = false)
815 815
 {
816 816
 	$replacements = array(
817 817
 		'%' => '\%',
Please login to merge, or discard this patch.
Braces   +225 added lines, -164 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc, $mysql_set_mode;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc')
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'mysql_fetch_assoc') {
38
+			$smcFunc += array(
38 39
 			'db_query' => 'smf_db_query',
39 40
 			'db_quote' => 'smf_db_quote',
40 41
 			'db_fetch_assoc' => 'mysql_fetch_assoc',
@@ -58,36 +59,42 @@  discard block
 block discarded – undo
58 59
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
59 60
 			'db_is_resource' => 'is_resource',
60 61
 		);
62
+	}
61 63
 
62
-	if (!empty($db_options['port']))
63
-		$db_server .= ':' . $db_options['port'];
64
+	if (!empty($db_options['port'])) {
65
+			$db_server .= ':' . $db_options['port'];
66
+	}
64 67
 	
65 68
 	$flags = 2; //#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
66 69
 
67
-	if (!empty($db_options['persist']))
68
-		$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
69
-	else
70
-		$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
70
+	if (!empty($db_options['persist'])) {
71
+			$connection = @mysql_pconnect($db_server, $db_user, $db_passwd, $flags);
72
+	} else {
73
+			$connection = @mysql_connect($db_server, $db_user, $db_passwd, false, $flags);
74
+	}
71 75
 
72 76
 	// Something's wrong, show an error if its fatal (which we assume it is)
73 77
 	if (!$connection)
74 78
 	{
75
-		if (!empty($db_options['non_fatal']))
76
-			return null;
77
-		else
78
-			display_db_error();
79
+		if (!empty($db_options['non_fatal'])) {
80
+					return null;
81
+		} else {
82
+					display_db_error();
83
+		}
79 84
 	}
80 85
 
81 86
 	// Select the database, unless told not to
82
-	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal']))
83
-		display_db_error();
87
+	if (empty($db_options['dont_select_db']) && !@mysql_select_db($db_name, $connection) && empty($db_options['non_fatal'])) {
88
+			display_db_error();
89
+	}
84 90
 
85 91
 	// This makes it possible to have SMF automatically change the sql_mode and autocommit if needed.
86
-	if (isset($mysql_set_mode) && $mysql_set_mode === true)
87
-		$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
92
+	if (isset($mysql_set_mode) && $mysql_set_mode === true) {
93
+			$smcFunc['db_query']('', 'SET sql_mode = \'\', AUTOCOMMIT = 1',
88 94
 		array(),
89 95
 		false
90 96
 	);
97
+	}
91 98
 
92 99
 	return $connection;
93 100
 }
@@ -134,37 +141,46 @@  discard block
 block discarded – undo
134 141
 	list ($values, $connection) = $db_callback;
135 142
 
136 143
 	// Connection gone???  This should *never* happen at this point, yet it does :'(
137
-	if (!is_resource($connection))
138
-		display_db_error();
144
+	if (!is_resource($connection)) {
145
+			display_db_error();
146
+	}
139 147
 
140
-	if ($matches[1] === 'db_prefix')
141
-		return $db_prefix;
148
+	if ($matches[1] === 'db_prefix') {
149
+			return $db_prefix;
150
+	}
142 151
 
143
-	if ($matches[1] === 'query_see_board')
144
-		return $user_info['query_see_board'];
152
+	if ($matches[1] === 'query_see_board') {
153
+			return $user_info['query_see_board'];
154
+	}
145 155
 
146
-	if ($matches[1] === 'query_wanna_see_board')
147
-		return $user_info['query_wanna_see_board'];
156
+	if ($matches[1] === 'query_wanna_see_board') {
157
+			return $user_info['query_wanna_see_board'];
158
+	}
148 159
 
149
-	if ($matches[1] === 'empty')
150
-		return '\'\'';
160
+	if ($matches[1] === 'empty') {
161
+			return '\'\'';
162
+	}
151 163
 
152
-	if (!isset($matches[2]))
153
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
164
+	if (!isset($matches[2])) {
165
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
166
+	}
154 167
 
155
-	if ($matches[1] === 'literal')
156
-		return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
168
+	if ($matches[1] === 'literal') {
169
+			return '\'' . mysql_real_escape_string($matches[2], $connection) . '\'';
170
+	}
157 171
 
158
-	if (!isset($values[$matches[2]]))
159
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
172
+	if (!isset($values[$matches[2]])) {
173
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
174
+	}
160 175
 
161 176
 	$replacement = $values[$matches[2]];
162 177
 
163 178
 	switch ($matches[1])
164 179
 	{
165 180
 		case 'int':
166
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
167
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
182
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+			}
168 184
 			return (string) (int) $replacement;
169 185
 		break;
170 186
 
@@ -176,49 +192,55 @@  discard block
 block discarded – undo
176 192
 		case 'array_int':
177 193
 			if (is_array($replacement))
178 194
 			{
179
-				if (empty($replacement))
180
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
195
+				if (empty($replacement)) {
196
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
197
+				}
181 198
 
182 199
 				foreach ($replacement as $key => $value)
183 200
 				{
184
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
185
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
201
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
202
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203
+					}
186 204
 
187 205
 					$replacement[$key] = (string) (int) $value;
188 206
 				}
189 207
 
190 208
 				return implode(', ', $replacement);
209
+			} else {
210
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
191 211
 			}
192
-			else
193
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194 212
 
195 213
 		break;
196 214
 
197 215
 		case 'array_string':
198 216
 			if (is_array($replacement))
199 217
 			{
200
-				if (empty($replacement))
201
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
218
+				if (empty($replacement)) {
219
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220
+				}
202 221
 
203
-				foreach ($replacement as $key => $value)
204
-					$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
222
+				foreach ($replacement as $key => $value) {
223
+									$replacement[$key] = sprintf('\'%1$s\'', mysql_real_escape_string($value, $connection));
224
+				}
205 225
 
206 226
 				return implode(', ', $replacement);
227
+			} else {
228
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
207 229
 			}
208
-			else
209
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210 230
 		break;
211 231
 
212 232
 		case 'date':
213
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
214
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
-			else
216
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
234
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
235
+			} else {
236
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+			}
217 238
 		break;
218 239
 
219 240
 		case 'float':
220
-			if (!is_numeric($replacement))
221
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			if (!is_numeric($replacement)) {
242
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243
+			}
222 244
 			return (string) (float) $replacement;
223 245
 		break;
224 246
 
@@ -232,10 +254,12 @@  discard block
 block discarded – undo
232 254
 		break;
233 255
 
234 256
 		case 'inet':
235
-			if ($replacement == 'null' || $replacement == '')
236
-				return 'null';
237
-			if (!isValidIP($replacement))
238
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
257
+			if ($replacement == 'null' || $replacement == '') {
258
+							return 'null';
259
+			}
260
+			if (!isValidIP($replacement)) {
261
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			}
239 263
 			//we don't use the native support of mysql > 5.6.2
240 264
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
241 265
 		break;
@@ -243,22 +267,25 @@  discard block
 block discarded – undo
243 267
 		case 'array_inet':
244 268
 			if (is_array($replacement))
245 269
 			{
246
-				if (empty($replacement))
247
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+				if (empty($replacement)) {
271
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+				}
248 273
 
249 274
 				foreach ($replacement as $key => $value)
250 275
 				{
251
-					if ($replacement == 'null' || $replacement == '')
252
-						$replacement[$key] = 'null';
253
-					if (!isValidIP($value))
254
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
276
+					if ($replacement == 'null' || $replacement == '') {
277
+											$replacement[$key] = 'null';
278
+					}
279
+					if (!isValidIP($value)) {
280
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+					}
255 282
 					$replacement[$key] =  sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
256 283
 				}
257 284
 
258 285
 				return implode(', ', $replacement);
286
+			} else {
287
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
259 288
 			}
260
-			else
261
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262 289
 		break;
263 290
 
264 291
 		default:
@@ -329,18 +356,20 @@  discard block
 block discarded – undo
329 356
 	// One more query....
330 357
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
331 358
 
332
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
333
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
359
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
360
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
361
+	}
334 362
 
335 363
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
336 364
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
337 365
 	{
338 366
 		// Add before LIMIT
339
-		if ($pos = strpos($db_string, 'LIMIT '))
340
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
341
-		else
342
-			// Append it.
367
+		if ($pos = strpos($db_string, 'LIMIT ')) {
368
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
369
+		} else {
370
+					// Append it.
343 371
 			$db_string .= "\n\t\t\tORDER BY null";
372
+		}
344 373
 	}
345 374
 
346 375
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -362,8 +391,9 @@  discard block
 block discarded – undo
362 391
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
363 392
 
364 393
 		// Initialize $db_cache if not already initialized.
365
-		if (!isset($db_cache))
366
-			$db_cache = array();
394
+		if (!isset($db_cache)) {
395
+					$db_cache = array();
396
+		}
367 397
 
368 398
 		if (!empty($_SESSION['debug_redirect']))
369 399
 		{
@@ -389,17 +419,18 @@  discard block
 block discarded – undo
389 419
 		while (true)
390 420
 		{
391 421
 			$pos = strpos($db_string, '\'', $pos + 1);
392
-			if ($pos === false)
393
-				break;
422
+			if ($pos === false) {
423
+							break;
424
+			}
394 425
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
395 426
 
396 427
 			while (true)
397 428
 			{
398 429
 				$pos1 = strpos($db_string, '\'', $pos + 1);
399 430
 				$pos2 = strpos($db_string, '\\', $pos + 1);
400
-				if ($pos1 === false)
401
-					break;
402
-				elseif ($pos2 == false || $pos2 > $pos1)
431
+				if ($pos1 === false) {
432
+									break;
433
+				} elseif ($pos2 == false || $pos2 > $pos1)
403 434
 				{
404 435
 					$pos = $pos1;
405 436
 					break;
@@ -415,29 +446,35 @@  discard block
 block discarded – undo
415 446
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
416 447
 
417 448
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
418
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
419
-			$fail = true;
449
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
450
+					$fail = true;
451
+		}
420 452
 		// Trying to change passwords, slow us down, or something?
421
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
422
-			$fail = true;
423
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
424
-			$fail = true;
453
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
454
+					$fail = true;
455
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
456
+					$fail = true;
457
+		}
425 458
 
426
-		if (!empty($fail) && function_exists('log_error'))
427
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
459
+		if (!empty($fail) && function_exists('log_error')) {
460
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
461
+		}
428 462
 	}
429 463
 
430
-	if (empty($db_unbuffered))
431
-		$ret = @mysql_query($db_string, $connection);
432
-	else
433
-		$ret = @mysql_unbuffered_query($db_string, $connection);
464
+	if (empty($db_unbuffered)) {
465
+			$ret = @mysql_query($db_string, $connection);
466
+	} else {
467
+			$ret = @mysql_unbuffered_query($db_string, $connection);
468
+	}
434 469
 
435
-	if ($ret === false && empty($db_values['db_error_skip']))
436
-		$ret = smf_db_error($db_string, $connection);
470
+	if ($ret === false && empty($db_values['db_error_skip'])) {
471
+			$ret = smf_db_error($db_string, $connection);
472
+	}
437 473
 
438 474
 	// Debugging.
439
-	if (isset($db_show_debug) && $db_show_debug === true)
440
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
475
+	if (isset($db_show_debug) && $db_show_debug === true) {
476
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
477
+	}
441 478
 
442 479
 	return $ret;
443 480
 }
@@ -486,12 +523,13 @@  discard block
 block discarded – undo
486 523
 	// Decide which connection to use
487 524
 	$connection = $connection === null ? $db_connection : $connection;
488 525
 
489
-	if ($type == 'begin')
490
-		return @mysql_query('BEGIN', $connection);
491
-	elseif ($type == 'rollback')
492
-		return @mysql_query('ROLLBACK', $connection);
493
-	elseif ($type == 'commit')
494
-		return @mysql_query('COMMIT', $connection);
526
+	if ($type == 'begin') {
527
+			return @mysql_query('BEGIN', $connection);
528
+	} elseif ($type == 'rollback') {
529
+			return @mysql_query('ROLLBACK', $connection);
530
+	} elseif ($type == 'commit') {
531
+			return @mysql_query('COMMIT', $connection);
532
+	}
495 533
 
496 534
 	return false;
497 535
 }
@@ -531,8 +569,9 @@  discard block
 block discarded – undo
531 569
 	//    2013: Lost connection to server during query.
532 570
 
533 571
 	// Log the error.
534
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
535
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
572
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
573
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
574
+	}
536 575
 
537 576
 	// Database error auto fixing ;).
538 577
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -541,8 +580,9 @@  discard block
 block discarded – undo
541 580
 		$old_cache = @$modSettings['cache_enable'];
542 581
 		$modSettings['cache_enable'] = '1';
543 582
 
544
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
545
-			$db_last_error = max(@$db_last_error, $temp);
583
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
584
+					$db_last_error = max(@$db_last_error, $temp);
585
+		}
546 586
 
547 587
 		if (@$db_last_error < time() - 3600 * 24 * 3)
548 588
 		{
@@ -558,8 +598,9 @@  discard block
 block discarded – undo
558 598
 					foreach ($tables as $table)
559 599
 					{
560 600
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
561
-						if (trim($table) != '')
562
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
601
+						if (trim($table) != '') {
602
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
603
+						}
563 604
 					}
564 605
 				}
565 606
 
@@ -568,8 +609,9 @@  discard block
 block discarded – undo
568 609
 			// Table crashed.  Let's try to fix it.
569 610
 			elseif ($query_errno == 1016)
570 611
 			{
571
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
572
-					$fix_tables = array('`' . $match[1] . '`');
612
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
613
+									$fix_tables = array('`' . $match[1] . '`');
614
+				}
573 615
 			}
574 616
 			// Indexes crashed.  Should be easy to fix!
575 617
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -588,13 +630,15 @@  discard block
 block discarded – undo
588 630
 
589 631
 			// Make a note of the REPAIR...
590 632
 			cache_put_data('db_last_error', time(), 600);
591
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
592
-				updateSettingsFile(array('db_last_error' => time()));
633
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
634
+							updateSettingsFile(array('db_last_error' => time()));
635
+			}
593 636
 
594 637
 			// Attempt to find and repair the broken table.
595
-			foreach ($fix_tables as $table)
596
-				$smcFunc['db_query']('', "
638
+			foreach ($fix_tables as $table) {
639
+							$smcFunc['db_query']('', "
597 640
 					REPAIR TABLE $table", false, false);
641
+			}
598 642
 
599 643
 			// And send off an email!
600 644
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -603,11 +647,12 @@  discard block
 block discarded – undo
603 647
 
604 648
 			// Try the query again...?
605 649
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
606
-			if ($ret !== false)
607
-				return $ret;
650
+			if ($ret !== false) {
651
+							return $ret;
652
+			}
653
+		} else {
654
+					$modSettings['cache_enable'] = $old_cache;
608 655
 		}
609
-		else
610
-			$modSettings['cache_enable'] = $old_cache;
611 656
 
612 657
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
613 658
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -617,22 +662,25 @@  discard block
 block discarded – undo
617 662
 				// Are we in SSI mode?  If so try that username and password first
618 663
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
619 664
 				{
620
-					if (empty($db_persist))
621
-						$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
622
-					else
623
-						$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
665
+					if (empty($db_persist)) {
666
+											$db_connection = @mysql_connect($db_server, $ssi_db_user, $ssi_db_passwd);
667
+					} else {
668
+											$db_connection = @mysql_pconnect($db_server, $ssi_db_user, $ssi_db_passwd);
669
+					}
624 670
 				}
625 671
 				// Fall back to the regular username and password if need be
626 672
 				if (!$db_connection)
627 673
 				{
628
-					if (empty($db_persist))
629
-						$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
630
-					else
631
-						$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
674
+					if (empty($db_persist)) {
675
+											$db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
676
+					} else {
677
+											$db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
678
+					}
632 679
 				}
633 680
 
634
-				if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
635
-					$db_connection = false;
681
+				if (!$db_connection || !@mysql_select_db($db_name, $db_connection)) {
682
+									$db_connection = false;
683
+				}
636 684
 			}
637 685
 
638 686
 			if ($db_connection)
@@ -643,24 +691,27 @@  discard block
 block discarded – undo
643 691
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
644 692
 
645 693
 					$new_errno = mysql_errno($db_connection);
646
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
647
-						break;
694
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
695
+											break;
696
+					}
648 697
 				}
649 698
 
650 699
 				// If it failed again, shucks to be you... we're not trying it over and over.
651
-				if ($ret !== false)
652
-					return $ret;
700
+				if ($ret !== false) {
701
+									return $ret;
702
+				}
653 703
 			}
654 704
 		}
655 705
 		// Are they out of space, perhaps?
656 706
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
657 707
 		{
658
-			if (!isset($txt))
659
-				$query_error .= ' - check database storage space.';
660
-			else
708
+			if (!isset($txt)) {
709
+							$query_error .= ' - check database storage space.';
710
+			} else
661 711
 			{
662
-				if (!isset($txt['mysql_error_space']))
663
-					loadLanguage('Errors');
712
+				if (!isset($txt['mysql_error_space'])) {
713
+									loadLanguage('Errors');
714
+				}
664 715
 
665 716
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
666 717
 			}
@@ -668,15 +719,17 @@  discard block
 block discarded – undo
668 719
 	}
669 720
 
670 721
 	// Nothing's defined yet... just die with it.
671
-	if (empty($context) || empty($txt))
672
-		die($query_error);
722
+	if (empty($context) || empty($txt)) {
723
+			die($query_error);
724
+	}
673 725
 
674 726
 	// Show an error message, if possible.
675 727
 	$context['error_title'] = $txt['database_error'];
676
-	if (allowedTo('admin_forum'))
677
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
678
-	else
679
-		$context['error_message'] = $txt['try_again'];
728
+	if (allowedTo('admin_forum')) {
729
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
730
+	} else {
731
+			$context['error_message'] = $txt['try_again'];
732
+	}
680 733
 
681 734
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
682 735
 	{
@@ -705,25 +758,28 @@  discard block
 block discarded – undo
705 758
 	$connection = $connection === null ? $db_connection : $connection;
706 759
 
707 760
 	// With nothing to insert, simply return.
708
-	if (empty($data))
709
-		return;
761
+	if (empty($data)) {
762
+			return;
763
+	}
710 764
 
711 765
 	// Replace the prefix holder with the actual prefix.
712 766
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
713 767
 
714 768
 	// Inserting data as a single row can be done as a single array.
715
-	if (!is_array($data[array_rand($data)]))
716
-		$data = array($data);
769
+	if (!is_array($data[array_rand($data)])) {
770
+			$data = array($data);
771
+	}
717 772
 
718 773
 	// Create the mold for a single row insert.
719 774
 	$insertData = '(';
720 775
 	foreach ($columns as $columnName => $type)
721 776
 	{
722 777
 		// Are we restricting the length?
723
-		if (strpos($type, 'string-') !== false)
724
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
725
-		else
726
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
778
+		if (strpos($type, 'string-') !== false) {
779
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
780
+		} else {
781
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
782
+		}
727 783
 	}
728 784
 	$insertData = substr($insertData, 0, -2) . ')';
729 785
 
@@ -732,8 +788,9 @@  discard block
 block discarded – undo
732 788
 
733 789
 	// Here's where the variables are injected to the query.
734 790
 	$insertRows = array();
735
-	foreach ($data as $dataRow)
736
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
791
+	foreach ($data as $dataRow) {
792
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
793
+	}
737 794
 
738 795
 	// Determine the method of insertion.
739 796
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -764,8 +821,9 @@  discard block
 block discarded – undo
764 821
  */
765 822
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
766 823
 {
767
-	if (empty($log_message))
768
-		$log_message = $error_message;
824
+	if (empty($log_message)) {
825
+			$log_message = $error_message;
826
+	}
769 827
 
770 828
 	foreach (debug_backtrace() as $step)
771 829
 	{
@@ -784,12 +842,14 @@  discard block
 block discarded – undo
784 842
 	}
785 843
 
786 844
 	// A special case - we want the file and line numbers for debugging.
787
-	if ($error_type == 'return')
788
-		return array($file, $line);
845
+	if ($error_type == 'return') {
846
+			return array($file, $line);
847
+	}
789 848
 
790 849
 	// Is always a critical error.
791
-	if (function_exists('log_error'))
792
-		log_error($log_message, 'critical', $file, $line);
850
+	if (function_exists('log_error')) {
851
+			log_error($log_message, 'critical', $file, $line);
852
+	}
793 853
 
794 854
 	if (function_exists('fatal_error'))
795 855
 	{
@@ -797,12 +857,12 @@  discard block
 block discarded – undo
797 857
 
798 858
 		// Cannot continue...
799 859
 		exit;
860
+	} elseif ($error_type) {
861
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
862
+	} else {
863
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
864
+	}
800 865
 	}
801
-	elseif ($error_type)
802
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
803
-	else
804
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
805
-}
806 866
 
807 867
 /**
808 868
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -819,10 +879,11 @@  discard block
 block discarded – undo
819 879
 		'\\' => '\\\\',
820 880
 	);
821 881
 
822
-	if ($translate_human_wildcards)
823
-		$replacements += array(
882
+	if ($translate_human_wildcards) {
883
+			$replacements += array(
824 884
 			'*' => '%',
825 885
 		);
886
+	}
826 887
 
827 888
 	return strtr($string, $replacements);
828 889
 }
Please login to merge, or discard this patch.
Sources/Memberlist.php 1 patch
Braces   +78 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Shows a listing of registered members.
@@ -110,8 +111,9 @@  discard block
 block discarded – undo
110 111
 
111 112
 	$context['custom_profile_fields'] = getCustFieldsMList();
112 113
 
113
-	if (!empty($context['custom_profile_fields']['columns']))
114
-		$context['columns'] += $context['custom_profile_fields']['columns'];
114
+	if (!empty($context['custom_profile_fields']['columns'])) {
115
+			$context['columns'] += $context['custom_profile_fields']['columns'];
116
+	}
115 117
 
116 118
 	$context['colspan'] = 0;
117 119
 	$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
@@ -147,12 +149,12 @@  discard block
 block discarded – undo
147 149
 	call_integration_hook('integrate_memberlist_buttons');
148 150
 
149 151
 	// Jump to the sub action.
150
-	if (isset($subActions[$context['listing_by']]))
151
-		call_helper($subActions[$context['listing_by']][1]);
152
-
153
-	else
154
-		call_helper($subActions['all'][1]);
155
-}
152
+	if (isset($subActions[$context['listing_by']])) {
153
+			call_helper($subActions[$context['listing_by']][1]);
154
+	} else {
155
+			call_helper($subActions['all'][1]);
156
+	}
157
+	}
156 158
 
157 159
 /**
158 160
  * List all members, page by page, with sorting.
@@ -177,8 +179,9 @@  discard block
 block discarded – undo
177 179
 	if ($use_cache)
178 180
 	{
179 181
 		// Maybe there's something cached already.
180
-		if (!empty($modSettings['memberlist_cache']))
181
-			$memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true);
182
+		if (!empty($modSettings['memberlist_cache'])) {
183
+					$memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true);
184
+		}
182 185
 
183 186
 		// The chunk size for the cached index.
184 187
 		$cache_step_size = 500;
@@ -234,13 +237,15 @@  discard block
 block discarded – undo
234 237
 	}
235 238
 
236 239
 	// Set defaults for sort (real_name) and start. (0)
237
-	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
238
-		$_REQUEST['sort'] = 'real_name';
240
+	if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
241
+			$_REQUEST['sort'] = 'real_name';
242
+	}
239 243
 
240 244
 	if (!is_numeric($_REQUEST['start']))
241 245
 	{
242
-		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0)
243
-			fatal_error('Hacker?', false);
246
+		if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) {
247
+					fatal_error('Hacker?', false);
248
+		}
244 249
 
245 250
 		$_REQUEST['start'] = $match[0];
246 251
 
@@ -259,16 +264,18 @@  discard block
 block discarded – undo
259 264
 	}
260 265
 
261 266
 	$context['letter_links'] = '';
262
-	for ($i = 97; $i < 123; $i++)
263
-		$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
267
+	for ($i = 97; $i < 123; $i++) {
268
+			$context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
269
+	}
264 270
 
265 271
 	// Sort out the column information.
266 272
 	foreach ($context['columns'] as $col => $column_details)
267 273
 	{
268 274
 		$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0';
269 275
 
270
-		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
271
-			$context['columns'][$col]['href'] .= ';desc';
276
+		if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
277
+					$context['columns'][$col]['href'] .= ';desc';
278
+		}
272 279
 
273 280
 		$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
274 281
 		$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -317,8 +324,9 @@  discard block
 block discarded – undo
317 324
 	elseif ($use_cache && $_REQUEST['sort'] === 'real_name')
318 325
 	{
319 326
 		$first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
320
-		if ($first_offset < 0)
321
-			$first_offset = 0;
327
+		if ($first_offset < 0) {
328
+					$first_offset = 0;
329
+		}
322 330
 		$second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
323 331
 
324 332
 		$where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}';
@@ -395,12 +403,13 @@  discard block
 block discarded – undo
395 403
 		)
396 404
 	);
397 405
 	$context['custom_search_fields'] = array();
398
-	while ($row = $smcFunc['db_fetch_assoc']($request))
399
-		$context['custom_search_fields'][$row['col_name']] = array(
406
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
407
+			$context['custom_search_fields'][$row['col_name']] = array(
400 408
 			'colname' => $row['col_name'],
401 409
 			'name' => $row['field_name'],
402 410
 			'desc' => $row['field_desc'],
403 411
 		);
412
+	}
404 413
 	$smcFunc['db_free_result']($request);
405 414
 
406 415
 	// They're searching..
@@ -413,23 +422,27 @@  discard block
 block discarded – undo
413 422
 		$context['old_search_value'] = urlencode($_REQUEST['search']);
414 423
 
415 424
 		// No fields?  Use default...
416
-		if (empty($_POST['fields']))
417
-			$_POST['fields'] = array('name');
425
+		if (empty($_POST['fields'])) {
426
+					$_POST['fields'] = array('name');
427
+		}
418 428
 
419 429
 		// Set defaults for how the results are sorted
420
-		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
421
-			$_REQUEST['sort'] = 'real_name';
430
+		if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) {
431
+					$_REQUEST['sort'] = 'real_name';
432
+		}
422 433
 
423 434
 		// Build the column link / sort information.
424 435
 		foreach ($context['columns'] as $col => $column_details)
425 436
 		{
426 437
 			$context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col;
427 438
 
428
-			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
429
-				$context['columns'][$col]['href'] .= ';desc';
439
+			if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) {
440
+							$context['columns'][$col]['href'] .= ';desc';
441
+			}
430 442
 
431
-			if (isset($_POST['search']) && isset($_POST['fields']))
432
-				$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
443
+			if (isset($_POST['search']) && isset($_POST['fields'])) {
444
+							$context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']);
445
+			}
433 446
 
434 447
 			$context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
435 448
 			$context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
@@ -452,8 +465,7 @@  discard block
 block discarded – undo
452 465
 		{
453 466
 			$fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name');
454 467
 			$search_fields[] = 'name';
455
-		}
456
-		else
468
+		} else
457 469
 		{
458 470
 			$fields = array();
459 471
 			$search_fields = array();
@@ -478,9 +490,10 @@  discard block
 block discarded – undo
478 490
 			$search_fields[] = 'email';
479 491
 		}
480 492
 
481
-		if ($smcFunc['db_case_sensitive'])
482
-			foreach ($fields as $key => $field)
493
+		if ($smcFunc['db_case_sensitive']) {
494
+					foreach ($fields as $key => $field)
483 495
 				$fields[$key] = 'LOWER(' . $field . ')';
496
+		}
484 497
 
485 498
 		$customJoin = array();
486 499
 		$customCount = 10;
@@ -499,8 +512,9 @@  discard block
 block discarded – undo
499 512
 		}
500 513
 
501 514
 		// No search fields? That means you're trying to hack things
502
-		if (empty($search_fields))
503
-			fatal_lang_error('invalid_search_string', false);
515
+		if (empty($search_fields)) {
516
+					fatal_lang_error('invalid_search_string', false);
517
+		}
504 518
 
505 519
 		$query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}');
506 520
 
@@ -538,8 +552,7 @@  discard block
 block discarded – undo
538 552
 		);
539 553
 		printMemberListRows($request);
540 554
 		$smcFunc['db_free_result']($request);
541
-	}
542
-	else
555
+	} else
543 556
 	{
544 557
 		// These are all the possible fields.
545 558
 		$context['search_fields'] = array(
@@ -554,14 +567,14 @@  discard block
 block discarded – undo
554 567
 		{
555 568
 			unset($context['search_fields']['email']);
556 569
 			$context['search_defaults'] = array('name');
557
-		}
558
-		else
570
+		} else
559 571
 		{
560 572
 			$context['search_defaults'] = array('name', 'email');
561 573
 		}
562 574
 
563
-		foreach ($context['custom_search_fields'] as $field)
564
-			$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
575
+		foreach ($context['custom_search_fields'] as $field) {
576
+					$context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
577
+		}
565 578
 
566 579
 		$context['sub_template'] = 'search';
567 580
 		$context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : '');
@@ -603,12 +616,14 @@  discard block
 block discarded – undo
603 616
 	$smcFunc['db_free_result']($result);
604 617
 
605 618
 	// Avoid division by zero...
606
-	if ($most_posts == 0)
607
-		$most_posts = 1;
619
+	if ($most_posts == 0) {
620
+			$most_posts = 1;
621
+	}
608 622
 
609 623
 	$members = array();
610
-	while ($row = $smcFunc['db_fetch_assoc']($request))
611
-		$members[] = $row['id_member'];
624
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
625
+			$members[] = $row['id_member'];
626
+	}
612 627
 
613 628
 	// Load all the members for display.
614 629
 	loadMemberData($members);
@@ -616,8 +631,9 @@  discard block
 block discarded – undo
616 631
 	$context['members'] = array();
617 632
 	foreach ($members as $member)
618 633
 	{
619
-		if (!loadMemberContext($member))
620
-			continue;
634
+		if (!loadMemberContext($member)) {
635
+					continue;
636
+		}
621 637
 
622 638
 		$context['members'][$member] = $memberContext[$member];
623 639
 		$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts);
@@ -634,20 +650,21 @@  discard block
 block discarded – undo
634 650
 					continue;
635 651
 				}
636 652
 
637
-				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key]))
638
-					$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
639
-
640
-				elseif ($column['type'] == 'check')
641
-					$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
653
+				if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) {
654
+									$context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key]));
655
+				} elseif ($column['type'] == 'check') {
656
+									$context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
657
+				}
642 658
 
643 659
 				// Enclosing the user input within some other text?
644
-				if (!empty($column['enclose']))
645
-					$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
660
+				if (!empty($column['enclose'])) {
661
+									$context['members'][$member]['options'][$key] = strtr($column['enclose'], array(
646 662
 						'{SCRIPTURL}' => $scripturl,
647 663
 						'{IMAGES_URL}' => $settings['images_url'],
648 664
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
649 665
 						'{INPUT}' => $context['members'][$member]['options'][$key],
650 666
 					));
667
+				}
651 668
 			}
652 669
 		}
653 670
 	}
@@ -688,17 +705,17 @@  discard block
 block discarded – undo
688 705
 		);
689 706
 
690 707
 		// Get the right sort method depending on the cust field type.
691
-		if ($row['field_type'] != 'check')
692
-			$cpf['columns'][$row['col_name']]['sort'] = array(
708
+		if ($row['field_type'] != 'check') {
709
+					$cpf['columns'][$row['col_name']]['sort'] = array(
693 710
 				'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, "") DESC',
694 711
 				'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, "") ASC'
695 712
 			);
696
-
697
-		else
698
-			$cpf['columns'][$row['col_name']]['sort'] = array(
713
+		} else {
714
+					$cpf['columns'][$row['col_name']]['sort'] = array(
699 715
 				'down' => 't' . $row['col_name'] . '.value DESC',
700 716
 				'up' => 't' . $row['col_name'] . '.value ASC'
701 717
 			);
718
+		}
702 719
 
703 720
 		$cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' .  $row['col_name'] . ' ON (t' .  $row['col_name'] . '.variable = {literal:' .  $row['col_name'] . '} AND t' .  $row['col_name'] . '.id_theme = 1 AND t' .  $row['col_name'] . '.id_member = mem.id_member)';
704 721
 	}
Please login to merge, or discard this patch.
Sources/Logging.php 1 patch
Braces   +134 added lines, -96 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Put this user in the online log.
@@ -33,8 +34,9 @@  discard block
 block discarded – undo
33 34
 		// Don't update for every page - this isn't wholly accurate but who cares.
34 35
 		if ($topic)
35 36
 		{
36
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
37
-				$force = false;
37
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
38
+							$force = false;
39
+			}
38 40
 			$_SESSION['last_topic_id'] = $topic;
39 41
 		}
40 42
 	}
@@ -47,22 +49,24 @@  discard block
 block discarded – undo
47 49
 	}
48 50
 
49 51
 	// Don't mark them as online more than every so often.
50
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
51
-		return;
52
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
53
+			return;
54
+	}
52 55
 
53 56
 	if (!empty($modSettings['who_enabled']))
54 57
 	{
55 58
 		$serialized = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
56 59
 
57 60
 		// In the case of a dlattach action, session_var may not be set.
58
-		if (!isset($context['session_var']))
59
-			$context['session_var'] = $_SESSION['session_var'];
61
+		if (!isset($context['session_var'])) {
62
+					$context['session_var'] = $_SESSION['session_var'];
63
+		}
60 64
 
61 65
 		unset($serialized['sesc'], $serialized[$context['session_var']]);
62 66
 		$serialized = json_encode($serialized);
67
+	} else {
68
+			$serialized = '';
63 69
 	}
64
-	else
65
-		$serialized = '';
66 70
 
67 71
 	// Guests use 0, members use their session ID.
68 72
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -102,17 +106,18 @@  discard block
 block discarded – undo
102 106
 		);
103 107
 
104 108
 		// Guess it got deleted.
105
-		if ($smcFunc['db_affected_rows']() == 0)
109
+		if ($smcFunc['db_affected_rows']() == 0) {
110
+					$_SESSION['log_time'] = 0;
111
+		}
112
+	} else {
106 113
 			$_SESSION['log_time'] = 0;
107 114
 	}
108
-	else
109
-		$_SESSION['log_time'] = 0;
110 115
 
111 116
 	// Otherwise, we have to delete and insert.
112 117
 	if (empty($_SESSION['log_time']))
113 118
 	{
114
-		if ($do_delete || !empty($user_info['id']))
115
-			$smcFunc['db_query']('', '
119
+		if ($do_delete || !empty($user_info['id'])) {
120
+					$smcFunc['db_query']('', '
116 121
 				DELETE FROM {db_prefix}log_online
117 122
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
118 123
 				array(
@@ -120,6 +125,7 @@  discard block
 block discarded – undo
120 125
 					'log_time' => time() - $modSettings['lastActive'] * 60,
121 126
 				)
122 127
 			);
128
+		}
123 129
 
124 130
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
125 131
 			'{db_prefix}log_online',
@@ -133,21 +139,24 @@  discard block
 block discarded – undo
133 139
 	$_SESSION['log_time'] = time();
134 140
 
135 141
 	// Well, they are online now.
136
-	if (empty($_SESSION['timeOnlineUpdated']))
137
-		$_SESSION['timeOnlineUpdated'] = time();
142
+	if (empty($_SESSION['timeOnlineUpdated'])) {
143
+			$_SESSION['timeOnlineUpdated'] = time();
144
+	}
138 145
 
139 146
 	// Set their login time, if not already done within the last minute.
140 147
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
141 148
 	{
142 149
 		// Don't count longer than 15 minutes.
143
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
144
-			$_SESSION['timeOnlineUpdated'] = time();
150
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
151
+					$_SESSION['timeOnlineUpdated'] = time();
152
+		}
145 153
 
146 154
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
147 155
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
148 156
 
149
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
150
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
157
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
158
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
159
+		}
151 160
 
152 161
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
153 162
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -184,8 +193,7 @@  discard block
 block discarded – undo
184 193
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
185 194
 			// Copy the file back and run for your life!
186 195
 			@copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php');
187
-		}
188
-		else
196
+		} else
189 197
 		{
190 198
 			@touch($boarddir . '/' . 'Settings.php');
191 199
 			return true;
@@ -205,22 +213,27 @@  discard block
 block discarded – undo
205 213
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
206 214
 
207 215
 	// Add to Settings.php if you want to show the debugging information.
208
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
209
-		return;
216
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
217
+			return;
218
+	}
210 219
 
211
-	if (empty($_SESSION['view_queries']))
212
-		$_SESSION['view_queries'] = 0;
213
-	if (empty($context['debug']['language_files']))
214
-		$context['debug']['language_files'] = array();
215
-	if (empty($context['debug']['sheets']))
216
-		$context['debug']['sheets'] = array();
220
+	if (empty($_SESSION['view_queries'])) {
221
+			$_SESSION['view_queries'] = 0;
222
+	}
223
+	if (empty($context['debug']['language_files'])) {
224
+			$context['debug']['language_files'] = array();
225
+	}
226
+	if (empty($context['debug']['sheets'])) {
227
+			$context['debug']['sheets'] = array();
228
+	}
217 229
 
218 230
 	$files = get_included_files();
219 231
 	$total_size = 0;
220 232
 	for ($i = 0, $n = count($files); $i < $n; $i++)
221 233
 	{
222
-		if (file_exists($files[$i]))
223
-			$total_size += filesize($files[$i]);
234
+		if (file_exists($files[$i])) {
235
+					$total_size += filesize($files[$i]);
236
+		}
224 237
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
225 238
 	}
226 239
 
@@ -229,8 +242,9 @@  discard block
 block discarded – undo
229 242
 	{
230 243
 		foreach ($db_cache as $q => $qq)
231 244
 		{
232
-			if (!empty($qq['w']))
233
-				$warnings += count($qq['w']);
245
+			if (!empty($qq['w'])) {
246
+							$warnings += count($qq['w']);
247
+			}
234 248
 		}
235 249
 
236 250
 		$_SESSION['debug'] = &$db_cache;
@@ -251,12 +265,14 @@  discard block
 block discarded – undo
251 265
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
252 266
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
253 267
 
254
-	if (function_exists('memory_get_peak_usage'))
255
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
268
+	if (function_exists('memory_get_peak_usage')) {
269
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
270
+	}
256 271
 
257 272
 	// What tokens are active?
258
-	if (isset($_SESSION['token']))
259
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
273
+	if (isset($_SESSION['token'])) {
274
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
275
+	}
260 276
 
261 277
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
262 278
 	{
@@ -269,10 +285,12 @@  discard block
 block discarded – undo
269 285
 			$total_t += $cache_hit['t'];
270 286
 			$total_s += $cache_hit['s'];
271 287
 		}
272
-		if (!isset($cache_misses))
273
-			$cache_misses = array();
274
-		foreach ($cache_misses as $missed)
275
-			$missed_entires[] = $missed['d'] . ' ' . $missed['k'];
288
+		if (!isset($cache_misses)) {
289
+					$cache_misses = array();
290
+		}
291
+		foreach ($cache_misses as $missed) {
292
+					$missed_entires[] = $missed['d'] . ' ' . $missed['k'];
293
+		}
276 294
 
277 295
 		echo '
278 296
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -283,38 +301,44 @@  discard block
 block discarded – undo
283 301
 	<a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
284 302
 	<br>';
285 303
 
286
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
287
-		foreach ($db_cache as $q => $qq)
304
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
305
+			foreach ($db_cache as $q => $qq)
288 306
 		{
289 307
 			$is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0;
308
+	}
290 309
 			// Temporary tables created in earlier queries are not explainable.
291 310
 			if ($is_select)
292 311
 			{
293
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
294
-					if (strpos(trim($qq['q']), $tmp) !== false)
312
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
313
+									if (strpos(trim($qq['q']), $tmp) !== false)
295 314
 					{
296 315
 						$is_select = false;
316
+				}
297 317
 						break;
298 318
 					}
299 319
 			}
300 320
 			// But actual creation of the temporary tables are.
301
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0)
302
-				$is_select = true;
321
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) {
322
+							$is_select = true;
323
+			}
303 324
 
304 325
 			// Make the filenames look a bit better.
305
-			if (isset($qq['f']))
306
-				$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
326
+			if (isset($qq['f'])) {
327
+							$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
328
+			}
307 329
 
308 330
 			echo '
309 331
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
310 332
 	&nbsp;&nbsp;&nbsp;';
311
-			if (!empty($qq['f']) && !empty($qq['l']))
312
-				echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
333
+			if (!empty($qq['f']) && !empty($qq['l'])) {
334
+							echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
335
+			}
313 336
 
314
-			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at']))
315
-				echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
316
-			elseif (isset($qq['t']))
317
-				echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
337
+			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) {
338
+							echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
339
+			} elseif (isset($qq['t'])) {
340
+							echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
341
+			}
318 342
 			echo '
319 343
 	<br>';
320 344
 		}
@@ -339,12 +363,14 @@  discard block
 block discarded – undo
339 363
 	global $modSettings, $smcFunc;
340 364
 	static $cache_stats = array();
341 365
 
342
-	if (empty($modSettings['trackStats']))
343
-		return false;
344
-	if (!empty($stats))
345
-		return $cache_stats = array_merge($cache_stats, $stats);
346
-	elseif (empty($cache_stats))
347
-		return false;
366
+	if (empty($modSettings['trackStats'])) {
367
+			return false;
368
+	}
369
+	if (!empty($stats)) {
370
+			return $cache_stats = array_merge($cache_stats, $stats);
371
+	} elseif (empty($cache_stats)) {
372
+			return false;
373
+	}
348 374
 
349 375
 	$setStringUpdate = '';
350 376
 	$insert_keys = array();
@@ -357,10 +383,11 @@  discard block
 block discarded – undo
357 383
 		$setStringUpdate .= '
358 384
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
359 385
 
360
-		if ($change === '+')
361
-			$cache_stats[$field] = 1;
362
-		else
363
-			$update_parameters[$field] = $change;
386
+		if ($change === '+') {
387
+					$cache_stats[$field] = 1;
388
+		} else {
389
+					$update_parameters[$field] = $change;
390
+		}
364 391
 		$insert_keys[$field] = 'int';
365 392
 	}
366 393
 
@@ -424,43 +451,50 @@  discard block
 block discarded – undo
424 451
 	);
425 452
 
426 453
 	// Make sure this particular log is enabled first...
427
-	if (empty($modSettings['modlog_enabled']))
428
-		unset ($log_types['moderate']);
429
-	if (empty($modSettings['userlog_enabled']))
430
-		unset ($log_types['user']);
431
-	if (empty($modSettings['adminlog_enabled']))
432
-		unset ($log_types['admin']);
454
+	if (empty($modSettings['modlog_enabled'])) {
455
+			unset ($log_types['moderate']);
456
+	}
457
+	if (empty($modSettings['userlog_enabled'])) {
458
+			unset ($log_types['user']);
459
+	}
460
+	if (empty($modSettings['adminlog_enabled'])) {
461
+			unset ($log_types['admin']);
462
+	}
433 463
 
434 464
 	call_integration_hook('integrate_log_types', array(&$log_types));
435 465
 
436 466
 	foreach ($logs as $log)
437 467
 	{
438
-		if (!isset($log_types[$log['log_type']]))
439
-			return false;
468
+		if (!isset($log_types[$log['log_type']])) {
469
+					return false;
470
+		}
440 471
 
441
-		if (!is_array($log['extra']))
442
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
472
+		if (!is_array($log['extra'])) {
473
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
474
+		}
443 475
 
444 476
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
445 477
 		if (isset($log['extra']['topic']))
446 478
 		{
447
-			if (!is_numeric($log['extra']['topic']))
448
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
479
+			if (!is_numeric($log['extra']['topic'])) {
480
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
481
+			}
449 482
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
450 483
 			unset($log['extra']['topic']);
484
+		} else {
485
+					$topic_id = 0;
451 486
 		}
452
-		else
453
-			$topic_id = 0;
454 487
 
455 488
 		if (isset($log['extra']['message']))
456 489
 		{
457
-			if (!is_numeric($log['extra']['message']))
458
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
490
+			if (!is_numeric($log['extra']['message'])) {
491
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
492
+			}
459 493
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
460 494
 			unset($log['extra']['message']);
495
+		} else {
496
+					$msg_id = 0;
461 497
 		}
462
-		else
463
-			$msg_id = 0;
464 498
 
465 499
 		// @todo cache this?
466 500
 		// Is there an associated report on this?
@@ -487,23 +521,26 @@  discard block
 block discarded – undo
487 521
 			$smcFunc['db_free_result']($request);
488 522
 		}
489 523
 
490
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
491
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
524
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
525
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
526
+		}
492 527
 
493 528
 		if (isset($log['extra']['board']))
494 529
 		{
495
-			if (!is_numeric($log['extra']['board']))
496
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
530
+			if (!is_numeric($log['extra']['board'])) {
531
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
532
+			}
497 533
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
498 534
 			unset($log['extra']['board']);
535
+		} else {
536
+					$board_id = 0;
499 537
 		}
500
-		else
501
-			$board_id = 0;
502 538
 
503 539
 		if (isset($log['extra']['board_to']))
504 540
 		{
505
-			if (!is_numeric($log['extra']['board_to']))
506
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
541
+			if (!is_numeric($log['extra']['board_to'])) {
542
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
543
+			}
507 544
 			if (empty($board_id))
508 545
 			{
509 546
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -511,10 +548,11 @@  discard block
 block discarded – undo
511 548
 			}
512 549
 		}
513 550
 
514
-		if (isset($log['extra']['member_affected']))
515
-			$memID = $log['extra']['member_affected'];
516
-		else
517
-			$memID = $user_info['id'];
551
+		if (isset($log['extra']['member_affected'])) {
552
+					$memID = $log['extra']['member_affected'];
553
+		} else {
554
+					$memID = $user_info['id'];
555
+		}
518 556
 
519 557
 		$inserts[] = array(
520 558
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.
Sources/Subs-Themes.php 1 patch
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Gets a single theme's info.
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	global $smcFunc, $modSettings;
28 29
 
29 30
 	// No data, no fun!
30
-	if (empty($id))
31
-		return false;
31
+	if (empty($id)) {
32
+			return false;
33
+	}
32 34
 
33 35
 	// Make sure $id is an int.
34 36
 	$id = (int) $id;
@@ -171,8 +173,9 @@  discard block
 block discarded – undo
171 173
 	global $sourcedir, $forum_version, $txt, $scripturl, $context;
172 174
 	global $explicit_images;
173 175
 
174
-	if (empty($path))
175
-		return false;
176
+	if (empty($path)) {
177
+			return false;
178
+	}
176 179
 
177 180
 	$xml_data = array();
178 181
 	$explicit_images = false;
@@ -229,9 +232,10 @@  discard block
 block discarded – undo
229 232
 	);
230 233
 
231 234
 	// Assign the values to be stored.
232
-	foreach ($xml_elements as $var => $name)
233
-		if (!empty($theme_info_xml[$name]))
235
+	foreach ($xml_elements as $var => $name) {
236
+			if (!empty($theme_info_xml[$name]))
234 237
 			$xml_data[$var] = $theme_info_xml[$name];
238
+	}
235 239
 
236 240
 	// Add the supported versions.
237 241
 	$xml_data['install_for'] = $install_versions;
@@ -243,8 +247,9 @@  discard block
 block discarded – undo
243 247
 		$explicit_images = true;
244 248
 	}
245 249
 
246
-	if (!empty($theme_info_xml['extra']))
247
-		$xml_data += smf_json_decode($theme_info_xml['extra'], true);
250
+	if (!empty($theme_info_xml['extra'])) {
251
+			$xml_data += smf_json_decode($theme_info_xml['extra'], true);
252
+	}
248 253
 
249 254
 	return $xml_data;
250 255
 }
@@ -262,12 +267,14 @@  discard block
 block discarded – undo
262 267
 	global $settings, $explicit_images;
263 268
 
264 269
 	// External use? no problem!
265
-	if ($to_install)
266
-		$context['to_install'] = $to_install;
270
+	if ($to_install) {
271
+			$context['to_install'] = $to_install;
272
+	}
267 273
 
268 274
 	// One last check.
269
-	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes')
270
-		fatal_lang_error('theme_install_invalid_dir', false);
275
+	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') {
276
+			fatal_lang_error('theme_install_invalid_dir', false);
277
+	}
271 278
 
272 279
 	// OK, is this a newer version of an already installed theme?
273 280
 	if (!empty($context['to_install']['version']))
@@ -292,8 +299,8 @@  discard block
 block discarded – undo
292 299
 		$smcFunc['db_free_result']($request);
293 300
 
294 301
 		// Got something, lets figure it out what to do next.
295
-		if (!empty($to_update) && !empty($to_update['version']))
296
-			switch (compareVersions($context['to_install']['version'], $to_update['version']))
302
+		if (!empty($to_update) && !empty($to_update['version'])) {
303
+					switch (compareVersions($context['to_install']['version'], $to_update['version']))
297 304
 			{
298 305
 				case 1: // Got a newer version, update the old entry.
299 306
 					$smcFunc['db_query']('', '
@@ -307,6 +314,7 @@  discard block
 block discarded – undo
307 314
 							'id_theme' => $to_update['id_theme'],
308 315
 						)
309 316
 					);
317
+		}
310 318
 
311 319
 					// Done with the update, tell the user about it.
312 320
 					$context['to_install']['updated'] = true;
@@ -372,13 +380,15 @@  discard block
 block discarded – undo
372 380
 				$context['to_install']['base_theme_url'] = $temp['theme_url'];
373 381
 				$context['to_install']['base_theme_dir'] = $temp['theme_dir'];
374 382
 
375
-				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url']))
376
-					$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
383
+				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) {
384
+									$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
385
+				}
377 386
 			}
378 387
 
379 388
 			// Nope, sorry, couldn't find any theme already installed.
380
-			else
381
-				fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
389
+			else {
390
+							fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
391
+			}
382 392
 		}
383 393
 
384 394
 		unset($context['to_install']['based_on']);
@@ -401,16 +411,18 @@  discard block
 block discarded – undo
401 411
 	call_integration_hook('integrate_theme_install', array(&$context['to_install'], $id_theme));
402 412
 
403 413
 	$inserts = array();
404
-	foreach ($context['to_install'] as $var => $val)
405
-		$inserts[] = array($id_theme, $var, $val);
414
+	foreach ($context['to_install'] as $var => $val) {
415
+			$inserts[] = array($id_theme, $var, $val);
416
+	}
406 417
 
407
-	if (!empty($inserts))
408
-		$smcFunc['db_insert']('insert',
418
+	if (!empty($inserts)) {
419
+			$smcFunc['db_insert']('insert',
409 420
 			'{db_prefix}themes',
410 421
 			array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
411 422
 			$inserts,
412 423
 			array('id_theme', 'variable')
413 424
 		);
425
+	}
414 426
 
415 427
 	// Update the known and enable Theme's settings.
416 428
 	$known = strtr($modSettings['knownThemes'] . ',' . $id_theme, array(',,' => ','));
@@ -429,21 +441,24 @@  discard block
 block discarded – undo
429 441
  */
430 442
 function remove_dir($path)
431 443
 {
432
-	if (empty($path))
433
-		return false;
444
+	if (empty($path)) {
445
+			return false;
446
+	}
434 447
 
435 448
 	if (is_dir($path))
436 449
 	{
437 450
 		$objects = scandir($path);
438 451
 
439
-		foreach ($objects as $object)
440
-			if ($object != '.' && $object != '..')
452
+		foreach ($objects as $object) {
453
+					if ($object != '.' && $object != '..')
441 454
 			{
442 455
 				if (filetype($path .'/'. $object) == 'dir')
443 456
 					remove_dir($path .'/'.$object);
457
+		}
444 458
 
445
-				else
446
-					unlink($path .'/'. $object);
459
+				else {
460
+									unlink($path .'/'. $object);
461
+				}
447 462
 			}
448 463
 	}
449 464
 
@@ -462,8 +477,9 @@  discard block
 block discarded – undo
462 477
 	global $smcFunc, $modSettings;
463 478
 
464 479
 	// Can't delete the default theme, sorry!
465
-	if (empty($themeID) || $themeID == 1)
466
-		return false;
480
+	if (empty($themeID) || $themeID == 1) {
481
+			return false;
482
+	}
467 483
 
468 484
 	$known = explode(',', $modSettings['knownThemes']);
469 485
 	$enable = explode(',', $modSettings['enableThemes']);
@@ -513,8 +529,9 @@  discard block
 block discarded – undo
513 529
 	updateSettings(array('enableThemes' => $enable, 'knownThemes' => $known));
514 530
 
515 531
 	// Fix it if the theme was the overall default theme.
516
-	if ($modSettings['theme_guests'] == $themeID)
517
-		updateSettings(array('theme_guests' => '1'));
532
+	if ($modSettings['theme_guests'] == $themeID) {
533
+			updateSettings(array('theme_guests' => '1'));
534
+	}
518 535
 
519 536
 	return true;
520 537
 }
@@ -531,13 +548,15 @@  discard block
 block discarded – undo
531 548
 	global $scripturl, $txt, $context;
532 549
 
533 550
 	// Is it even a directory?
534
-	if (!is_dir($path))
535
-		fatal_lang_error('error_invalid_dir', 'critical');
551
+	if (!is_dir($path)) {
552
+			fatal_lang_error('error_invalid_dir', 'critical');
553
+	}
536 554
 
537 555
 	$dir = dir($path);
538 556
 	$entries = array();
539
-	while ($entry = $dir->read())
540
-		$entries[] = $entry;
557
+	while ($entry = $dir->read()) {
558
+			$entries[] = $entry;
559
+	}
541 560
 	$dir->close();
542 561
 
543 562
 	natcasesort($entries);
@@ -548,11 +567,12 @@  discard block
 block discarded – undo
548 567
 	foreach ($entries as $entry)
549 568
 	{
550 569
 		// Skip all dot files, including .htaccess.
551
-		if (substr($entry, 0, 1) == '.' || $entry == 'CVS')
552
-			continue;
570
+		if (substr($entry, 0, 1) == '.' || $entry == 'CVS') {
571
+					continue;
572
+		}
553 573
 
554
-		if (is_dir($path . '/' . $entry))
555
-			$listing1[] = array(
574
+		if (is_dir($path . '/' . $entry)) {
575
+					$listing1[] = array(
556 576
 				'filename' => $entry,
557 577
 				'is_writable' => is_writable($path . '/' . $entry),
558 578
 				'is_directory' => true,
@@ -562,13 +582,14 @@  discard block
 block discarded – undo
562 582
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $relative . $entry,
563 583
 				'size' => '',
564 584
 			);
565
-		else
585
+		} else
566 586
 		{
567 587
 			$size = filesize($path . '/' . $entry);
568
-			if ($size > 2048 || $size == 1024)
569
-				$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
570
-			else
571
-				$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
588
+			if ($size > 2048 || $size == 1024) {
589
+							$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
590
+			} else {
591
+							$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
592
+			}
572 593
 
573 594
 			$listing2[] = array(
574 595
 				'filename' => $entry,
Please login to merge, or discard this patch.