Completed
Push — release-2.1 ( d322d4...5b3f1b )
by Colin
08:15
created
Sources/SearchAPI-Fulltext.php 2 patches
Braces   +47 added lines, -36 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Class fulltext_search
@@ -98,8 +99,9 @@  discard block
 block discarded – undo
98 99
 			$smcFunc['db_free_result']($request);
99 100
 		}
100 101
 		// 4 is the MySQL default...
101
-		else
102
-			$min_word_length = 4;
102
+		else {
103
+					$min_word_length = 4;
104
+		}
103 105
 
104 106
 		return $min_word_length;
105 107
 	}
@@ -138,8 +140,7 @@  discard block
 block discarded – undo
138 140
 					$wordsSearch['words'][] = trim($word, "/*- ");
139 141
 					$wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"';
140 142
 				}
141
-			}
142
-			elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143
+			} elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length)
143 144
 			{
144 145
 				// short words have feelings too
145 146
 				$wordsSearch['words'][] = trim($word, "/*- ");
@@ -149,8 +150,9 @@  discard block
 block discarded – undo
149 150
 
150 151
 		$fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"';
151 152
 		$wordsSearch['indexed_words'][] = $fulltextWord;
152
-		if ($isExcluded)
153
-			$wordsExclude[] = $fulltextWord;
153
+		if ($isExcluded) {
154
+					$wordsExclude[] = $fulltextWord;
155
+		}
154 156
 	}
155 157
 
156 158
 	/**
@@ -166,44 +168,54 @@  discard block
 block discarded – undo
166 168
 		$query_where = array();
167 169
 		$query_params = $search_data['params'];
168 170
 
169
-		if( $smcFunc['db_title'] == "PostgreSQL")
170
-			$modSettings['search_simple_fulltext'] = true;
171
+		if( $smcFunc['db_title'] == "PostgreSQL") {
172
+					$modSettings['search_simple_fulltext'] = true;
173
+		}
171 174
 
172
-		if ($query_params['id_search'])
173
-			$query_select['id_search'] = '{int:id_search}';
175
+		if ($query_params['id_search']) {
176
+					$query_select['id_search'] = '{int:id_search}';
177
+		}
174 178
 
175 179
 		$count = 0;
176
-		if (empty($modSettings['search_simple_fulltext']))
177
-			foreach ($words['words'] as $regularWord)
180
+		if (empty($modSettings['search_simple_fulltext'])) {
181
+					foreach ($words['words'] as $regularWord)
178 182
 			{
179 183
 				$query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}';
184
+		}
180 185
 				$query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
181 186
 			}
182 187
 
183
-		if ($query_params['user_query'])
184
-			$query_where[] = '{raw:user_query}';
185
-		if ($query_params['board_query'])
186
-			$query_where[] = 'm.id_board {raw:board_query}';
188
+		if ($query_params['user_query']) {
189
+					$query_where[] = '{raw:user_query}';
190
+		}
191
+		if ($query_params['board_query']) {
192
+					$query_where[] = 'm.id_board {raw:board_query}';
193
+		}
187 194
 
188
-		if ($query_params['topic'])
189
-			$query_where[] = 'm.id_topic = {int:topic}';
190
-		if ($query_params['min_msg_id'])
191
-			$query_where[] = 'm.id_msg >= {int:min_msg_id}';
192
-		if ($query_params['max_msg_id'])
193
-			$query_where[] = 'm.id_msg <= {int:max_msg_id}';
195
+		if ($query_params['topic']) {
196
+					$query_where[] = 'm.id_topic = {int:topic}';
197
+		}
198
+		if ($query_params['min_msg_id']) {
199
+					$query_where[] = 'm.id_msg >= {int:min_msg_id}';
200
+		}
201
+		if ($query_params['max_msg_id']) {
202
+					$query_where[] = 'm.id_msg <= {int:max_msg_id}';
203
+		}
194 204
 
195 205
 		$count = 0;
196
-		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index']))
197
-			foreach ($query_params['excluded_phrases'] as $phrase)
206
+		if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) {
207
+					foreach ($query_params['excluded_phrases'] as $phrase)
198 208
 			{
199 209
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}';
210
+		}
200 211
 				$query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]';
201 212
 			}
202 213
 		$count = 0;
203
-		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index']))
204
-			foreach ($query_params['excluded_subject_words'] as $excludedWord)
214
+		if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) {
215
+					foreach ($query_params['excluded_subject_words'] as $excludedWord)
205 216
 			{
206 217
 				$query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}';
218
+		}
207 219
 				$query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]';
208 220
 			}
209 221
 
@@ -215,12 +227,11 @@  discard block
 block discarded – undo
215 227
 
216 228
 				$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})';
217 229
 				$query_params['language_ftx'] = $language_ftx;
230
+			} else {
231
+							$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
218 232
 			}
219
-			else
220
-				$query_where[] = 'MATCH (body) AGAINST ({string:body_match})';
221 233
 			$query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words']));
222
-		}
223
-		else
234
+		} else
224 235
 		{
225 236
 			$query_params['boolean_match'] = '';
226 237
 
@@ -234,10 +245,10 @@  discard block
 block discarded – undo
234 245
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' ';
235 246
 					$row++;
236 247
 				}
237
-			}
238
-			else
239
-				foreach ($words['indexed_words'] as $fulltextWord)
248
+			} else {
249
+							foreach ($words['indexed_words'] as $fulltextWord)
240 250
 					$query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' ';
251
+			}
241 252
 
242 253
 			$query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1);
243 254
 
@@ -249,9 +260,9 @@  discard block
 block discarded – undo
249 260
 
250 261
 					$query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})';
251 262
 					$query_params['language_ftx'] = $language_ftx;
263
+				} else {
264
+									$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
252 265
 				}
253
-				else
254
-					$query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)';
255 266
 			}
256 267
 
257 268
 		}
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 		$query_where = array();
167 167
 		$query_params = $search_data['params'];
168 168
 
169
-		if( $smcFunc['db_title'] == "PostgreSQL")
169
+		if ($smcFunc['db_title'] == "PostgreSQL")
170 170
 			$modSettings['search_simple_fulltext'] = true;
171 171
 
172 172
 		if ($query_params['id_search'])
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			// if we have bool terms to search, add them in
247 247
 			if ($query_params['boolean_match'])
248 248
 			{
249
-				if($smcFunc['db_title'] == "PostgreSQL")
249
+				if ($smcFunc['db_title'] == "PostgreSQL")
250 250
 				{
251 251
 					$language_ftx = $smcFunc['db_search_language']();
252 252
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 			}
259 259
 		}
260 260
 
261
-		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( '
261
+		$ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ('
262 262
 			INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . '
263 263
 				(' . implode(', ', array_keys($query_select)) . ')') : '') . '
264 264
 			SELECT ' . implode(', ', $query_select) . '
Please login to merge, or discard this patch.
Sources/CacheAPI-postgres.php 2 patches
Braces   +28 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('Hacking attempt...');
16
+}
16 17
 
17 18
 /**
18 19
  * PostgreSQL Cache API class
@@ -49,8 +50,9 @@  discard block
 block discarded – undo
49 50
 
50 51
 		$result = pg_execute($db_connection, '', array('public', $db_prefix . 'cache'));
51 52
 
52
-		if (pg_affected_rows($result) === 0)
53
-			pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');			
53
+		if (pg_affected_rows($result) === 0) {
54
+					pg_query($db_connection, 'CREATE UNLOGGED TABLE ' . $db_prefix . 'cache (key text, value text, ttl bigint, PRIMARY KEY (key))');
55
+		}
54 56
 	}
55 57
 
56 58
 	/**
@@ -60,14 +62,16 @@  discard block
 block discarded – undo
60 62
 	{
61 63
 		global $smcFunc, $db_connection;
62 64
 
63
-		if ($smcFunc['db_title'] !== 'PostgreSQL')
64
-			return false;
65
+		if ($smcFunc['db_title'] !== 'PostgreSQL') {
66
+					return false;
67
+		}
65 68
 
66 69
 		$result = pg_query($db_connection, 'SHOW server_version_num');
67 70
 		$res = pg_fetch_assoc($result);
68 71
 		
69
-		if ($res['server_version_num'] < 90500)
70
-			return false;
72
+		if ($res['server_version_num'] < 90500) {
73
+					return false;
74
+		}
71 75
 		
72 76
 		return $test ? true : parent::isSupported();
73 77
 	}
@@ -81,13 +85,15 @@  discard block
 block discarded – undo
81 85
 
82 86
 		$ttl = time() - $ttl;
83 87
 		
84
-		if (empty($this->pg_get_data_prep))
85
-			$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
88
+		if (empty($this->pg_get_data_prep)) {
89
+					$this->pg_get_data_prep = pg_prepare($db_connection, 'smf_cache_get_data', 'SELECT value FROM ' . $db_prefix . 'cache WHERE key = $1 AND ttl >= $2 LIMIT 1');
90
+		}
86 91
 			
87 92
 		$result = pg_execute($db_connection, 'smf_cache_get_data', array($key, $ttl));
88 93
 		
89
-		if (pg_affected_rows($result) === 0)
90
-			return null;
94
+		if (pg_affected_rows($result) === 0) {
95
+					return null;
96
+		}
91 97
 
92 98
 		$res = pg_fetch_assoc($result);
93 99
 
@@ -101,23 +107,26 @@  discard block
 block discarded – undo
101 107
 	{
102 108
 		global  $db_prefix, $db_connection;
103 109
 
104
-		if (!isset($value))
105
-			$value = '';
110
+		if (!isset($value)) {
111
+					$value = '';
112
+		}
106 113
 
107 114
 		$ttl = time() + $ttl;
108 115
 
109
-		if (empty($this->pg_put_data_prep))
110
-			$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
116
+		if (empty($this->pg_put_data_prep)) {
117
+					$this->pg_put_data_prep = pg_prepare($db_connection, 'smf_cache_put_data',
111 118
 				'INSERT INTO ' . $db_prefix . 'cache(key,value,ttl) VALUES($1,$2,$3)
112 119
 				ON CONFLICT(key) DO UPDATE SET value = excluded.value, ttl = excluded.ttl'
113 120
 			);
121
+		}
114 122
 
115 123
 		$result = pg_execute($db_connection, 'smf_cache_put_data', array($key, $value, $ttl));
116 124
 
117
-		if (pg_affected_rows($result) > 0)
118
-			return true;
119
-		else
120
-			return false;
125
+		if (pg_affected_rows($result) > 0) {
126
+					return true;
127
+		} else {
128
+					return false;
129
+		}
121 130
 	}
122 131
 
123 132
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	{
166 166
 		global $db_connection, $db_prefix;
167 167
 		
168
-		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time() );
168
+		pg_query($db_connection, 'CREATE LOCAL TEMP TABLE IF NOT EXISTS ' . $db_prefix . 'cache_tmp AS SELECT * FROM ' . $db_prefix . 'cache WHERE ttl >= ' . time());
169 169
 	}
170 170
 	
171 171
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	{
190 190
 		global $db_connection, $db_prefix;
191 191
 		
192
-		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM '. $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
192
+		pg_query($db_connection, 'INSERT INTO ' . $db_prefix . 'cache SELECT * FROM ' . $db_prefix . 'cache_tmp ON CONFLICT DO NOTHING');
193 193
 	}
194 194
 }
195 195
 
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" rel="noopener" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/MessageIndex.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -349,7 +349,7 @@
 block discarded – undo
349 349
 			SELECT
350 350
 				t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
351 351
 				' . ($user_info['is_guest'] ? '0' : 'COALESCE(lt.id_msg, COALESCE(lmr.id_msg, -1)) + 1') . ' AS new_from,
352
-				' . ( $enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
352
+				' . ($enableParticipation ? ' COALESCE(( SELECT 1 FROM {db_prefix}messages AS parti WHERE t.id_topic = parti.id_topic and parti.id_member = {int:current_member} LIMIT 1) , 0) as is_posted_in,
353 353
 				'	: '') . '
354 354
 				t.id_last_msg, t.approved, t.unapproved_posts, ml.poster_time AS last_poster_time, t.id_redirect_topic,
355 355
 				ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
Please login to merge, or discard this patch.
Braces   +266 added lines, -199 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Show the list of topics in this board, along with any child boards.
@@ -56,8 +57,9 @@  discard block
 block discarded – undo
56 57
 
57 58
 	$context['name'] = $board_info['name'];
58 59
 	$context['description'] = $board_info['description'];
59
-	if (!empty($board_info['description']))
60
-		$context['meta_description'] = strip_tags($board_info['description']);
60
+	if (!empty($board_info['description'])) {
61
+			$context['meta_description'] = strip_tags($board_info['description']);
62
+	}
61 63
 
62 64
 	// How many topics do we have in total?
63 65
 	$board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
@@ -73,12 +75,14 @@  discard block
 block discarded – undo
73 75
 		$session_name = session_name();
74 76
 		foreach ($_GET as $k => $v)
75 77
 		{
76
-			if (!in_array($k, array('board', 'start', $session_name)))
77
-				$context['robot_no_index'] = true;
78
+			if (!in_array($k, array('board', 'start', $session_name))) {
79
+							$context['robot_no_index'] = true;
80
+			}
78 81
 		}
79 82
 	}
80
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
81
-		$context['robot_no_index'] = true;
83
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
84
+			$context['robot_no_index'] = true;
85
+	}
82 86
 
83 87
 	// If we can view unapproved messages and there are some build up a list.
84 88
 	if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts']))
@@ -89,14 +93,16 @@  discard block
 block discarded – undo
89 93
 	}
90 94
 
91 95
 	// We only know these.
92
-	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post')))
93
-		$_REQUEST['sort'] = 'last_post';
96
+	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) {
97
+			$_REQUEST['sort'] = 'last_post';
98
+	}
94 99
 
95 100
 	// Make sure the starting place makes sense and construct the page index.
96
-	if (isset($_REQUEST['sort']))
97
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
101
+	if (isset($_REQUEST['sort'])) {
102
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $context['maxindex'], true);
105
+	}
100 106
 	$context['start'] = &$_REQUEST['start'];
101 107
 
102 108
 	// Set a canonical URL for this page.
@@ -132,14 +138,16 @@  discard block
 block discarded – undo
132 138
 	$context['link_moderators'] = array();
133 139
 	if (!empty($board_info['moderators']))
134 140
 	{
135
-		foreach ($board_info['moderators'] as $mod)
136
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
141
+		foreach ($board_info['moderators'] as $mod) {
142
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
143
+		}
137 144
 	}
138 145
 	if (!empty($board_info['moderator_groups']))
139 146
 	{
140 147
 		// By default just tack the moderator groups onto the end of the members
141
-		foreach ($board_info['moderator_groups'] as $mod_group)
142
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
148
+		foreach ($board_info['moderator_groups'] as $mod_group) {
149
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
150
+		}
143 151
 	}
144 152
 
145 153
 	// Now we tack the info onto the end of the linktree
@@ -191,20 +199,24 @@  discard block
 block discarded – undo
191 199
 		);
192 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
193 201
 		{
194
-			if (empty($row['id_member']))
195
-				continue;
202
+			if (empty($row['id_member'])) {
203
+							continue;
204
+			}
196 205
 
197
-			if (!empty($row['online_color']))
198
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
199
-			else
200
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
206
+			if (!empty($row['online_color'])) {
207
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
208
+			} else {
209
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
210
+			}
201 211
 
202 212
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
203
-			if ($is_buddy)
204
-				$link = '<strong>' . $link . '</strong>';
213
+			if ($is_buddy) {
214
+							$link = '<strong>' . $link . '</strong>';
215
+			}
205 216
 
206
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
207
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
217
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
218
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
219
+			}
208 220
 			// @todo why are we filling this array of data that are just counted (twice) and discarded? ???
209 221
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
210 222
 				'id' => $row['id_member'],
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 				'hidden' => empty($row['show_online']),
218 230
 			);
219 231
 
220
-			if (empty($row['show_online']))
221
-				$context['view_num_hidden']++;
232
+			if (empty($row['show_online'])) {
233
+							$context['view_num_hidden']++;
234
+			}
222 235
 		}
223 236
 		$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
224 237
 		$smcFunc['db_free_result']($request);
@@ -260,8 +273,9 @@  discard block
 block discarded – undo
260 273
 	// Bring in any changes we want to make before the query.
261 274
 	call_integration_hook('integrate_pre_messageindex', array(&$sort_methods));
262 275
 
263
-	foreach ($sort_methods as $key => $val)
264
-		$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
276
+	foreach ($sort_methods as $key => $val) {
277
+			$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
278
+	}
265 279
 
266 280
 	// Calculate the fastest way to get the topics.
267 281
 	$start = (int) $_REQUEST['start'];
@@ -271,14 +285,15 @@  discard block
 block discarded – undo
271 285
 		$fake_ascending = true;
272 286
 		$context['maxindex'] = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? $board_info['total_topics'] - $start : $context['maxindex'];
273 287
 		$start = $board_info['total_topics'] < $start + $context['maxindex'] + 1 ? 0 : $board_info['total_topics'] - $start - $context['maxindex'];
288
+	} else {
289
+			$fake_ascending = false;
274 290
 	}
275
-	else
276
-		$fake_ascending = false;
277 291
 
278 292
 	// Setup the default topic icons...
279 293
 	$context['icon_sources'] = array();
280
-	foreach ($context['stable_icons'] as $icon)
281
-		$context['icon_sources'][$icon] = 'images_url';
294
+	foreach ($context['stable_icons'] as $icon) {
295
+			$context['icon_sources'][$icon] = 'images_url';
296
+	}
282 297
 
283 298
 	$topic_ids = array();
284 299
 	$context['topics'] = array();
@@ -316,8 +331,9 @@  discard block
 block discarded – undo
316 331
 			$message_pre_index_parameters
317 332
 		);
318 333
 		$topic_ids = array();
319
-		while ($row = $smcFunc['db_fetch_assoc']($request))
320
-			$topic_ids[] = $row['id_topic'];
334
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
335
+					$topic_ids[] = $row['id_topic'];
336
+		}
321 337
 	}
322 338
 
323 339
 	// Grab the appropriate topic information...
@@ -340,10 +356,11 @@  discard block
 block discarded – undo
340 356
 		$message_index_wheres = array();
341 357
 		call_integration_hook('integrate_message_index', array(&$message_index_selects, &$message_index_tables, &$message_index_parameters, &$message_index_wheres, &$topic_ids));
342 358
 
343
-		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
344
-			$enableParticipation = true;
345
-		else
346
-			$enableParticipation = false;
359
+		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) {
360
+					$enableParticipation = true;
361
+		} else {
362
+					$enableParticipation = false;
363
+		}
347 364
 
348 365
 		$result = $smcFunc['db_query']('substring', '
349 366
 			SELECT
@@ -382,11 +399,13 @@  discard block
 block discarded – undo
382 399
 		// Begin 'printing' the message index for current board.
383 400
 		while ($row = $smcFunc['db_fetch_assoc']($result))
384 401
 		{
385
-			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
386
-				continue;
402
+			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
403
+							continue;
404
+			}
387 405
 
388
-			if (!$pre_query)
389
-				$topic_ids[] = $row['id_topic'];
406
+			if (!$pre_query) {
407
+							$topic_ids[] = $row['id_topic'];
408
+			}
390 409
 
391 410
 			// Reference the main color class.
392 411
 			$colorClass = 'windowbg';
@@ -396,8 +415,9 @@  discard block
 block discarded – undo
396 415
 			{
397 416
 				// Limit them to $modSettings['preview_characters'] characters
398 417
 				$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
399
-				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
400
-					$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
418
+				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
419
+									$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
420
+				}
401 421
 
402 422
 				// Censor the subject and message preview.
403 423
 				censorText($row['first_subject']);
@@ -408,27 +428,27 @@  discard block
 block discarded – undo
408 428
 				{
409 429
 					$row['last_subject'] = $row['first_subject'];
410 430
 					$row['last_body'] = $row['first_body'];
411
-				}
412
-				else
431
+				} else
413 432
 				{
414 433
 					$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
415
-					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
416
-						$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
434
+					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
435
+											$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
436
+					}
417 437
 
418 438
 					censorText($row['last_subject']);
419 439
 					censorText($row['last_body']);
420 440
 				}
421
-			}
422
-			else
441
+			} else
423 442
 			{
424 443
 				$row['first_body'] = '';
425 444
 				$row['last_body'] = '';
426 445
 				censorText($row['first_subject']);
427 446
 
428
-				if ($row['id_first_msg'] == $row['id_last_msg'])
429
-					$row['last_subject'] = $row['first_subject'];
430
-				else
431
-					censorText($row['last_subject']);
447
+				if ($row['id_first_msg'] == $row['id_last_msg']) {
448
+									$row['last_subject'] = $row['first_subject'];
449
+				} else {
450
+									censorText($row['last_subject']);
451
+				}
432 452
 			}
433 453
 
434 454
 			// Decide how many pages the topic should have.
@@ -439,42 +459,50 @@  discard block
 block discarded – undo
439 459
 				$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
440 460
 
441 461
 				// If we can use all, show all.
442
-				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
443
-					$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
462
+				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) {
463
+									$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
464
+				}
465
+			} else {
466
+							$pages = '';
444 467
 			}
445
-			else
446
-				$pages = '';
447 468
 
448 469
 			// We need to check the topic icons exist...
449 470
 			if (!empty($modSettings['messageIconChecks_enable']))
450 471
 			{
451
-				if (!isset($context['icon_sources'][$row['first_icon']]))
452
-					$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
453
-				if (!isset($context['icon_sources'][$row['last_icon']]))
454
-					$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
455
-			}
456
-			else
472
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
473
+									$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
474
+				}
475
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
476
+									$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
477
+				}
478
+			} else
457 479
 			{
458
-				if (!isset($context['icon_sources'][$row['first_icon']]))
459
-					$context['icon_sources'][$row['first_icon']] = 'images_url';
460
-				if (!isset($context['icon_sources'][$row['last_icon']]))
461
-					$context['icon_sources'][$row['last_icon']] = 'images_url';
480
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
481
+									$context['icon_sources'][$row['first_icon']] = 'images_url';
482
+				}
483
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
484
+									$context['icon_sources'][$row['last_icon']] = 'images_url';
485
+				}
462 486
 			}
463 487
 
464
-			if (!empty($board_info['recycle']))
465
-				$row['first_icon'] = 'recycled';
488
+			if (!empty($board_info['recycle'])) {
489
+							$row['first_icon'] = 'recycled';
490
+			}
466 491
 
467 492
 			// Is this topic pending approval, or does it have any posts pending approval?
468
-			if ($context['can_approve_posts'] && $row['unapproved_posts'])
469
-				$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
493
+			if ($context['can_approve_posts'] && $row['unapproved_posts']) {
494
+							$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
495
+			}
470 496
 
471 497
 			// Sticky topics should get a different color, too.
472
-			if ($row['is_sticky'])
473
-				$colorClass .= ' sticky';
498
+			if ($row['is_sticky']) {
499
+							$colorClass .= ' sticky';
500
+			}
474 501
 
475 502
 			// Locked topics get special treatment as well.
476
-			if ($row['locked'])
477
-				$colorClass .= ' locked';
503
+			if ($row['locked']) {
504
+							$colorClass .= ' locked';
505
+			}
478 506
 
479 507
 			// 'Print' the topic info.
480 508
 			$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -555,8 +583,9 @@  discard block
 block discarded – undo
555 583
 		$smcFunc['db_free_result']($result);
556 584
 
557 585
 		// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
558
-		if ($fake_ascending)
559
-			$context['topics'] = array_reverse($context['topics'], true);
586
+		if ($fake_ascending) {
587
+					$context['topics'] = array_reverse($context['topics'], true);
588
+		}
560 589
 	}
561 590
 
562 591
 	$context['jump_to'] = array(
@@ -579,9 +608,9 @@  discard block
 block discarded – undo
579 608
 		// Can we restore topics?
580 609
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
581 610
 
582
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
583
-			$context['can_move_any'] = true;
584
-		else
611
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
612
+					$context['can_move_any'] = true;
613
+		} else
585 614
 		{
586 615
 			// We'll use this in a minute
587 616
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -608,11 +637,13 @@  discard block
 block discarded – undo
608 637
 		}
609 638
 
610 639
 		// Can we use quick moderation checkboxes?
611
-		if ($options['display_quick_mod'] == 1)
612
-			$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
640
+		if ($options['display_quick_mod'] == 1) {
641
+					$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
642
+		}
613 643
 		// Or the icons?
614
-		else
615
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
644
+		else {
645
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
646
+		}
616 647
 	}
617 648
 
618 649
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -646,13 +677,15 @@  discard block
 block discarded – undo
646 677
 			);
647 678
 
648 679
 			// We've seen all these boards now!
649
-			foreach ($board_info['parent_boards'] as $k => $dummy)
650
-				if (isset($_SESSION['topicseen_cache'][$k]))
680
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
681
+							if (isset($_SESSION['topicseen_cache'][$k]))
651 682
 					unset($_SESSION['topicseen_cache'][$k]);
683
+			}
652 684
 		}
653 685
 
654
-		if (isset($_SESSION['topicseen_cache'][$board]))
655
-			unset($_SESSION['topicseen_cache'][$board]);
686
+		if (isset($_SESSION['topicseen_cache'][$board])) {
687
+					unset($_SESSION['topicseen_cache'][$board]);
688
+		}
656 689
 
657 690
 		$request = $smcFunc['db_query']('', '
658 691
 			SELECT id_topic, id_board, sent
@@ -673,8 +706,9 @@  discard block
 block discarded – undo
673 706
 				$context['is_marked_notify'] = true;
674 707
 				$board_sent = $row['sent'];
675 708
 			}
676
-			if (!empty($row['id_topic']))
677
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
709
+			if (!empty($row['id_topic'])) {
710
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
711
+			}
678 712
 		}
679 713
 		$smcFunc['db_free_result']($request);
680 714
 
@@ -698,8 +732,7 @@  discard block
 block discarded – undo
698 732
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
699 733
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
700 734
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
701
-	}
702
-	else
735
+	} else
703 736
 	{
704 737
 		$context['is_marked_notify'] = false;
705 738
 		$context['board_notification_mode'] = 1;
@@ -712,23 +745,27 @@  discard block
 block discarded – undo
712 745
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
713 746
 
714 747
 	// Don't want to show this forever...
715
-	if ($context['becomesUnapproved'])
716
-		unset($_SESSION['becomesUnapproved']);
748
+	if ($context['becomesUnapproved']) {
749
+			unset($_SESSION['becomesUnapproved']);
750
+	}
717 751
 
718 752
 	// Build the message index button array.
719 753
 	$context['normal_buttons'] = array();
720 754
 
721
-	if ($context['can_post_new'])
722
-		$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
755
+	if ($context['can_post_new']) {
756
+			$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
757
+	}
723 758
 
724
-	if ($context['can_post_poll'])
725
-		$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
759
+	if ($context['can_post_poll']) {
760
+			$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
761
+	}
726 762
 
727
-	if ($context['user']['is_logged'])
728
-		$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
763
+	if ($context['user']['is_logged']) {
764
+			$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
765
+	}
729 766
 
730
-	if ($context['can_mark_notify'])
731
-		$context['normal_buttons']['notify'] = array(
767
+	if ($context['can_mark_notify']) {
768
+			$context['normal_buttons']['notify'] = array(
732 769
 			'lang' => true,
733 770
 			'text' => 'notify_board_' . $context['board_notification_mode'],
734 771
 			'sub_buttons' => array(
@@ -746,6 +783,7 @@  discard block
 block discarded – undo
746 783
 				),
747 784
 			),
748 785
 		);
786
+	}
749 787
 
750 788
 	// Javascript for inline editing.
751 789
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -767,18 +805,21 @@  discard block
 block discarded – undo
767 805
 	checkSession('request');
768 806
 
769 807
 	// Lets go straight to the restore area.
770
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
771
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
808
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
809
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
810
+	}
772 811
 
773
-	if (isset($_SESSION['topicseen_cache']))
774
-		$_SESSION['topicseen_cache'] = array();
812
+	if (isset($_SESSION['topicseen_cache'])) {
813
+			$_SESSION['topicseen_cache'] = array();
814
+	}
775 815
 
776 816
 	// This is going to be needed to send off the notifications and for updateLastMessages().
777 817
 	require_once($sourcedir . '/Subs-Post.php');
778 818
 
779 819
 	// Remember the last board they moved things to.
780
-	if (isset($_REQUEST['move_to']))
781
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
820
+	if (isset($_REQUEST['move_to'])) {
821
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
822
+	}
782 823
 
783 824
 	// Only a few possible actions.
784 825
 	$possibleActions = array();
@@ -798,8 +839,7 @@  discard block
 block discarded – undo
798 839
 		);
799 840
 
800 841
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
801
-	}
802
-	else
842
+	} else
803 843
 	{
804 844
 		/**
805 845
 		 * @todo Ugly. There's no getting around this, is there?
@@ -817,8 +857,7 @@  discard block
 block discarded – undo
817 857
 		if (!empty($board))
818 858
 		{
819 859
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
820
-		}
821
-		else
860
+		} else
822 861
 		{
823 862
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
824 863
 		}
@@ -829,55 +868,67 @@  discard block
 block discarded – undo
829 868
 		}
830 869
 	}
831 870
 
832
-	if (!$user_info['is_guest'])
833
-		$possibleActions[] = 'markread';
834
-	if (!empty($boards_can['make_sticky']))
835
-		$possibleActions[] = 'sticky';
836
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
837
-		$possibleActions[] = 'move';
838
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
839
-		$possibleActions[] = 'remove';
840
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
841
-		$possibleActions[] = 'lock';
842
-	if (!empty($boards_can['merge_any']))
843
-		$possibleActions[] = 'merge';
844
-	if (!empty($boards_can['approve_posts']))
845
-		$possibleActions[] = 'approve';
871
+	if (!$user_info['is_guest']) {
872
+			$possibleActions[] = 'markread';
873
+	}
874
+	if (!empty($boards_can['make_sticky'])) {
875
+			$possibleActions[] = 'sticky';
876
+	}
877
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
878
+			$possibleActions[] = 'move';
879
+	}
880
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
881
+			$possibleActions[] = 'remove';
882
+	}
883
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
884
+			$possibleActions[] = 'lock';
885
+	}
886
+	if (!empty($boards_can['merge_any'])) {
887
+			$possibleActions[] = 'merge';
888
+	}
889
+	if (!empty($boards_can['approve_posts'])) {
890
+			$possibleActions[] = 'approve';
891
+	}
846 892
 
847 893
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
848 894
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
849 895
 	if (!empty($_REQUEST['topics']))
850 896
 	{
851 897
 		// If the action isn't valid, just quit now.
852
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
853
-			redirectexit($redirect_url);
898
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
899
+					redirectexit($redirect_url);
900
+		}
854 901
 
855 902
 		// Merge requires all topics as one parameter and can be done at once.
856 903
 		if ($_REQUEST['qaction'] == 'merge')
857 904
 		{
858 905
 			// Merge requires at least two topics.
859
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
860
-				redirectexit($redirect_url);
906
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
907
+							redirectexit($redirect_url);
908
+			}
861 909
 
862 910
 			require_once($sourcedir . '/SplitTopics.php');
863 911
 			return MergeExecute($_REQUEST['topics']);
864 912
 		}
865 913
 
866 914
 		// Just convert to the other method, to make it easier.
867
-		foreach ($_REQUEST['topics'] as $topic)
868
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
915
+		foreach ($_REQUEST['topics'] as $topic) {
916
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
917
+		}
869 918
 	}
870 919
 
871 920
 	// Weird... how'd you get here?
872
-	if (empty($_REQUEST['actions']))
873
-		redirectexit($redirect_url);
921
+	if (empty($_REQUEST['actions'])) {
922
+			redirectexit($redirect_url);
923
+	}
874 924
 
875 925
 	// Validate each action.
876 926
 	$temp = array();
877 927
 	foreach ($_REQUEST['actions'] as $topic => $action)
878 928
 	{
879
-		if (in_array($action, $possibleActions))
880
-			$temp[(int) $topic] = $action;
929
+		if (in_array($action, $possibleActions)) {
930
+					$temp[(int) $topic] = $action;
931
+		}
881 932
 	}
882 933
 	$_REQUEST['actions'] = $temp;
883 934
 
@@ -898,27 +949,31 @@  discard block
 block discarded – undo
898 949
 		{
899 950
 			if (!empty($board))
900 951
 			{
901
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
902
-					unset($_REQUEST['actions'][$row['id_topic']]);
903
-			}
904
-			else
952
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
953
+									unset($_REQUEST['actions'][$row['id_topic']]);
954
+				}
955
+			} else
905 956
 			{
906 957
 				// Don't allow them to act on unapproved posts they can't see...
907
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
908
-					unset($_REQUEST['actions'][$row['id_topic']]);
958
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
959
+									unset($_REQUEST['actions'][$row['id_topic']]);
960
+				}
909 961
 				// Goodness, this is fun.  We need to validate the action.
910
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
911
-					unset($_REQUEST['actions'][$row['id_topic']]);
912
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
913
-					unset($_REQUEST['actions'][$row['id_topic']]);
914
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
915
-					unset($_REQUEST['actions'][$row['id_topic']]);
962
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
963
+									unset($_REQUEST['actions'][$row['id_topic']]);
964
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) {
965
+									unset($_REQUEST['actions'][$row['id_topic']]);
966
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) {
967
+									unset($_REQUEST['actions'][$row['id_topic']]);
968
+				}
916 969
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
917
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))))
918
-					unset($_REQUEST['actions'][$row['id_topic']]);
970
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) {
971
+									unset($_REQUEST['actions'][$row['id_topic']]);
972
+				}
919 973
 				// If the topic is approved then you need permission to approve the posts within.
920
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))))
921
-					unset($_REQUEST['actions'][$row['id_topic']]);
974
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) {
975
+									unset($_REQUEST['actions'][$row['id_topic']]);
976
+				}
922 977
 			}
923 978
 		}
924 979
 		$smcFunc['db_free_result']($request);
@@ -936,11 +991,11 @@  discard block
 block discarded – undo
936 991
 	{
937 992
 		$topic = (int) $topic;
938 993
 
939
-		if ($action == 'markread')
940
-			$markCache[] = $topic;
941
-		elseif ($action == 'sticky')
942
-			$stickyCache[] = $topic;
943
-		elseif ($action == 'move')
994
+		if ($action == 'markread') {
995
+					$markCache[] = $topic;
996
+		} elseif ($action == 'sticky') {
997
+					$stickyCache[] = $topic;
998
+		} elseif ($action == 'move')
944 999
 		{
945 1000
 			require_once($sourcedir . '/MoveTopic.php');
946 1001
 			moveTopicConcurrence();
@@ -948,23 +1003,25 @@  discard block
 block discarded – undo
948 1003
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
949 1004
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
950 1005
 
951
-			if (empty($moveCache[1][$topic]))
952
-				continue;
1006
+			if (empty($moveCache[1][$topic])) {
1007
+							continue;
1008
+			}
953 1009
 
954 1010
 			$moveCache[0][] = $topic;
1011
+		} elseif ($action == 'remove') {
1012
+					$removeCache[] = $topic;
1013
+		} elseif ($action == 'lock') {
1014
+					$lockCache[] = $topic;
1015
+		} elseif ($action == 'approve') {
1016
+					$approveCache[] = $topic;
955 1017
 		}
956
-		elseif ($action == 'remove')
957
-			$removeCache[] = $topic;
958
-		elseif ($action == 'lock')
959
-			$lockCache[] = $topic;
960
-		elseif ($action == 'approve')
961
-			$approveCache[] = $topic;
962 1018
 	}
963 1019
 
964
-	if (empty($board))
965
-		$affectedBoards = array();
966
-	else
967
-		$affectedBoards = array($board => array(0, 0));
1020
+	if (empty($board)) {
1021
+			$affectedBoards = array();
1022
+	} else {
1023
+			$affectedBoards = array($board => array(0, 0));
1024
+	}
968 1025
 
969 1026
 	// Do all the stickies...
970 1027
 	if (!empty($stickyCache))
@@ -1024,14 +1081,16 @@  discard block
 block discarded – undo
1024 1081
 		{
1025 1082
 			$to = $moveCache[1][$row['id_topic']];
1026 1083
 
1027
-			if (empty($to))
1028
-				continue;
1084
+			if (empty($to)) {
1085
+							continue;
1086
+			}
1029 1087
 
1030 1088
 			// Does this topic's board count the posts or not?
1031 1089
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1032 1090
 
1033
-			if (!isset($moveTos[$to]))
1034
-				$moveTos[$to] = array();
1091
+			if (!isset($moveTos[$to])) {
1092
+							$moveTos[$to] = array();
1093
+			}
1035 1094
 
1036 1095
 			$moveTos[$to][] = $row['id_topic'];
1037 1096
 
@@ -1045,8 +1104,9 @@  discard block
 block discarded – undo
1045 1104
 		require_once($sourcedir . '/MoveTopic.php');
1046 1105
 
1047 1106
 		// Do the actual moves...
1048
-		foreach ($moveTos as $to => $topics)
1049
-			moveTopics($topics, $to);
1107
+		foreach ($moveTos as $to => $topics) {
1108
+					moveTopics($topics, $to);
1109
+		}
1050 1110
 
1051 1111
 		// Does the post counts need to be updated?
1052 1112
 		if (!empty($moveTos))
@@ -1095,20 +1155,23 @@  discard block
 block discarded – undo
1095 1155
 
1096 1156
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1097 1157
 				{
1098
-					if (!isset($members[$row['id_member']]))
1099
-						$members[$row['id_member']] = 0;
1158
+					if (!isset($members[$row['id_member']])) {
1159
+											$members[$row['id_member']] = 0;
1160
+					}
1100 1161
 
1101
-					if ($topicRecounts[$row['id_topic']] === '+')
1102
-						$members[$row['id_member']] += 1;
1103
-					else
1104
-						$members[$row['id_member']] -= 1;
1162
+					if ($topicRecounts[$row['id_topic']] === '+') {
1163
+											$members[$row['id_member']] += 1;
1164
+					} else {
1165
+											$members[$row['id_member']] -= 1;
1166
+					}
1105 1167
 				}
1106 1168
 
1107 1169
 				$smcFunc['db_free_result']($request);
1108 1170
 
1109 1171
 				// And now update them member's post counts
1110
-				foreach ($members as $id_member => $post_adj)
1111
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1172
+				foreach ($members as $id_member => $post_adj) {
1173
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1174
+				}
1112 1175
 			}
1113 1176
 		}
1114 1177
 	}
@@ -1187,8 +1250,9 @@  discard block
 block discarded – undo
1187 1250
 			approveTopics($approveCache);
1188 1251
 
1189 1252
 			// Time for some logging!
1190
-			foreach ($approveCache as $topic)
1191
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1253
+			foreach ($approveCache as $topic) {
1254
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1255
+			}
1192 1256
 		}
1193 1257
 	}
1194 1258
 
@@ -1223,8 +1287,7 @@  discard block
 block discarded – undo
1223 1287
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1224 1288
 			}
1225 1289
 			$smcFunc['db_free_result']($result);
1226
-		}
1227
-		else
1290
+		} else
1228 1291
 		{
1229 1292
 			$result = $smcFunc['db_query']('', '
1230 1293
 				SELECT id_topic, locked, id_board
@@ -1274,13 +1337,15 @@  discard block
 block discarded – undo
1274 1337
 			)
1275 1338
 		);
1276 1339
 		$logged_topics = array();
1277
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1278
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1340
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1341
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1342
+		}
1279 1343
 		$smcFunc['db_free_result']($request);
1280 1344
 
1281 1345
 		$markArray = array();
1282
-		foreach ($markCache as $topic)
1283
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1346
+		foreach ($markCache as $topic) {
1347
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1348
+		}
1284 1349
 
1285 1350
 		$smcFunc['db_insert']('replace',
1286 1351
 			'{db_prefix}log_topics',
@@ -1293,8 +1358,9 @@  discard block
 block discarded – undo
1293 1358
 	foreach ($moveCache as $topic)
1294 1359
 	{
1295 1360
 		// Didn't actually move anything!
1296
-		if (!isset($topic[0]))
1297
-			break;
1361
+		if (!isset($topic[0])) {
1362
+					break;
1363
+		}
1298 1364
 
1299 1365
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1300 1366
 		sendNotifications($topic[0], 'move');
@@ -1316,8 +1382,9 @@  discard block
 block discarded – undo
1316 1382
 		'calendar_updated' => time(),
1317 1383
 	));
1318 1384
 
1319
-	if (!empty($affectedBoards))
1320
-		updateLastMessages(array_keys($affectedBoards));
1385
+	if (!empty($affectedBoards)) {
1386
+			updateLastMessages(array_keys($affectedBoards));
1387
+	}
1321 1388
 
1322 1389
 	redirectexit($redirect_url);
1323 1390
 }
Please login to merge, or discard this patch.
other/install.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1697,8 +1697,7 @@  discard block
 block discarded – undo
1697 1697
 	updateStats('topic');
1698 1698
 
1699 1699
 	// This function is needed to do the updateStats('subject') call.
1700
-	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1701
-		function($string){
1700
+	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1702 1701
 			global $sourcedir;
1703 1702
 			if (function_exists('mb_strtolower'))
1704 1703
 				return mb_strtolower($string, 'UTF-8');
@@ -1767,7 +1766,7 @@  discard block
 block discarded – undo
1767 1766
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1768 1767
 		{
1769 1768
 			// Set the ten lines to nothing.
1770
-			for ($j=0; $j < 10; $j++)
1769
+			for ($j = 0; $j < 10; $j++)
1771 1770
 				$settingsArray[$i++] = '';
1772 1771
 
1773 1772
 			continue;
Please login to merge, or discard this patch.
Braces   +470 added lines, -350 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -313,10 +325,11 @@  discard block
 block discarded – undo
313 325
 	}
314 326
 
315 327
 	// Override the language file?
316
-	if (isset($_GET['lang_file']))
317
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
318
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
319
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
328
+	if (isset($_GET['lang_file'])) {
329
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
331
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
332
+	}
320 333
 
321 334
 	// Make sure it exists, if it doesn't reset it.
322 335
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -325,8 +338,9 @@  discard block
 block discarded – undo
325 338
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
326 339
 
327 340
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
328
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
329
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
341
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
342
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
343
+		}
330 344
 	}
331 345
 
332 346
 	// And now include the actual language file itself.
@@ -343,15 +357,18 @@  discard block
 block discarded – undo
343 357
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
344 358
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
345 359
 
346
-	if (empty($sourcedir))
347
-		$sourcedir = dirname(__FILE__) . '/Sources';
360
+	if (empty($sourcedir)) {
361
+			$sourcedir = dirname(__FILE__) . '/Sources';
362
+	}
348 363
 
349 364
 	// Need this to check whether we need the database password.
350 365
 	require(dirname(__FILE__) . '/Settings.php');
351
-	if (!defined('SMF'))
352
-		define('SMF', 1);
353
-	if (empty($smcFunc))
354
-		$smcFunc = array();
366
+	if (!defined('SMF')) {
367
+			define('SMF', 1);
368
+	}
369
+	if (empty($smcFunc)) {
370
+			$smcFunc = array();
371
+	}
355 372
 
356 373
 	$modSettings['disableQueryCheck'] = true;
357 374
 
@@ -359,8 +376,9 @@  discard block
 block discarded – undo
359 376
 	if (!$db_connection)
360 377
 	{
361 378
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
362
-		if (version_compare(PHP_VERSION, '5', '<'))
363
-			require_once($sourcedir . '/Subs-Compat.php');
379
+		if (version_compare(PHP_VERSION, '5', '<')) {
380
+					require_once($sourcedir . '/Subs-Compat.php');
381
+		}
364 382
 
365 383
 		$db_options = array('persist' => $db_persist);
366 384
 		$port = '';
@@ -371,19 +389,20 @@  discard block
 block discarded – undo
371 389
 			if ($db_type == 'mysql')
372 390
 			{
373 391
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
374
-			}
375
-			elseif ($db_type == 'postgresql')
392
+			} elseif ($db_type == 'postgresql')
376 393
 			{
377 394
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
378 395
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
379 396
 			}
380 397
 		}
381 398
 
382
-		if (!empty($port))
383
-			$db_options['port'] = $port;
399
+		if (!empty($port)) {
400
+					$db_options['port'] = $port;
401
+		}
384 402
 
385
-		if (!$db_connection)
386
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
403
+		if (!$db_connection) {
404
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
405
+		}
387 406
 	}
388 407
 }
389 408
 
@@ -411,8 +430,9 @@  discard block
 block discarded – undo
411 430
 		// @todo REMOVE THIS!!
412 431
 		else
413 432
 		{
414
-			if (function_exists('doStep' . $_GET['step']))
415
-				call_user_func('doStep' . $_GET['step']);
433
+			if (function_exists('doStep' . $_GET['step'])) {
434
+							call_user_func('doStep' . $_GET['step']);
435
+			}
416 436
 		}
417 437
 		// Show the footer.
418 438
 		template_install_below();
@@ -430,8 +450,9 @@  discard block
 block discarded – undo
430 450
 	$incontext['sub_template'] = 'welcome_message';
431 451
 
432 452
 	// Done the submission?
433
-	if (isset($_POST['contbutt']))
434
-		return true;
453
+	if (isset($_POST['contbutt'])) {
454
+			return true;
455
+	}
435 456
 
436 457
 	// See if we think they have already installed it?
437 458
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -439,14 +460,17 @@  discard block
 block discarded – undo
439 460
 		$probably_installed = 0;
440 461
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
441 462
 		{
442
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
443
-				$probably_installed++;
444
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
445
-				$probably_installed++;
463
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
464
+							$probably_installed++;
465
+			}
466
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
467
+							$probably_installed++;
468
+			}
446 469
 		}
447 470
 
448
-		if ($probably_installed == 2)
449
-			$incontext['warning'] = $txt['error_already_installed'];
471
+		if ($probably_installed == 2) {
472
+					$incontext['warning'] = $txt['error_already_installed'];
473
+		}
450 474
 	}
451 475
 
452 476
 	// Is some database support even compiled in?
@@ -461,45 +485,54 @@  discard block
 block discarded – undo
461 485
 				$databases[$key]['supported'] = false;
462 486
 				$notFoundSQLFile = true;
463 487
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
488
+			} else {
489
+							$incontext['supported_databases'][] = $db;
464 490
 			}
465
-			else
466
-				$incontext['supported_databases'][] = $db;
467 491
 		}
468 492
 	}
469 493
 
470 494
 	// Check the PHP version.
471
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
472
-		$error = 'error_php_too_low';
495
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
496
+			$error = 'error_php_too_low';
497
+	}
473 498
 	// Make sure we have a supported database
474
-	elseif (empty($incontext['supported_databases']))
475
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
499
+	elseif (empty($incontext['supported_databases'])) {
500
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
501
+	}
476 502
 	// How about session support?  Some crazy sysadmin remove it?
477
-	elseif (!function_exists('session_start'))
478
-		$error = 'error_session_missing';
503
+	elseif (!function_exists('session_start')) {
504
+			$error = 'error_session_missing';
505
+	}
479 506
 	// Make sure they uploaded all the files.
480
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
481
-		$error = 'error_missing_files';
507
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
508
+			$error = 'error_missing_files';
509
+	}
482 510
 	// Very simple check on the session.save_path for Windows.
483 511
 	// @todo Move this down later if they don't use database-driven sessions?
484
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
485
-		$error = 'error_session_save_path';
512
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
513
+			$error = 'error_session_save_path';
514
+	}
486 515
 
487 516
 	// Since each of the three messages would look the same, anyway...
488
-	if (isset($error))
489
-		$incontext['error'] = $txt[$error];
517
+	if (isset($error)) {
518
+			$incontext['error'] = $txt[$error];
519
+	}
490 520
 
491 521
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
492
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
493
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
522
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
523
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
524
+	}
494 525
 
495 526
 	// Confirm mbstring is loaded...
496
-	if (!extension_loaded('mbstring'))
497
-		$incontext['error'] = $txt['install_no_mbstring'];
527
+	if (!extension_loaded('mbstring')) {
528
+			$incontext['error'] = $txt['install_no_mbstring'];
529
+	}
498 530
 
499 531
 	// Check for https stream support.
500 532
 	$supported_streams = stream_get_wrappers();
501
-	if (!in_array('https', $supported_streams))
502
-		$incontext['warning'] = $txt['install_no_https'];
533
+	if (!in_array('https', $supported_streams)) {
534
+			$incontext['warning'] = $txt['install_no_https'];
535
+	}
503 536
 
504 537
 	return false;
505 538
 }
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 		'Settings_bak.php',
525 558
 	);
526 559
 
527
-	foreach ($incontext['detected_languages'] as $lang => $temp)
528
-		$extra_files[] = 'Themes/default/languages/' . $lang;
560
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
561
+			$extra_files[] = 'Themes/default/languages/' . $lang;
562
+	}
529 563
 
530 564
 	// With mod_security installed, we could attempt to fix it with .htaccess.
531
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
532
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
565
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
566
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
567
+	}
533 568
 
534 569
 	$failed_files = array();
535 570
 
@@ -541,20 +576,23 @@  discard block
 block discarded – undo
541 576
 		foreach ($writable_files as $file)
542 577
 		{
543 578
 			// Some files won't exist, try to address up front
544
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
545
-				@touch(dirname(__FILE__) . '/' . $file);
579
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
580
+							@touch(dirname(__FILE__) . '/' . $file);
581
+			}
546 582
 			// NOW do the writable check...
547 583
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
548 584
 			{
549 585
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
550 586
 
551 587
 				// Well, 755 hopefully worked... if not, try 777.
552
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
553
-					$failed_files[] = $file;
588
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
589
+									$failed_files[] = $file;
590
+				}
554 591
 			}
555 592
 		}
556
-		foreach ($extra_files as $file)
557
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
593
+		foreach ($extra_files as $file) {
594
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
595
+		}
558 596
 	}
559 597
 	// Windows is trickier.  Let's try opening for r+...
560 598
 	else
@@ -564,30 +602,35 @@  discard block
 block discarded – undo
564 602
 		foreach ($writable_files as $file)
565 603
 		{
566 604
 			// Folders can't be opened for write... but the index.php in them can ;)
567
-			if (is_dir(dirname(__FILE__) . '/' . $file))
568
-				$file .= '/index.php';
605
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
606
+							$file .= '/index.php';
607
+			}
569 608
 
570 609
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
571 610
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
572 611
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
573 612
 
574 613
 			// Hmm, okay, try just for write in that case...
575
-			if (!is_resource($fp))
576
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
614
+			if (!is_resource($fp)) {
615
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
616
+			}
577 617
 
578
-			if (!is_resource($fp))
579
-				$failed_files[] = $file;
618
+			if (!is_resource($fp)) {
619
+							$failed_files[] = $file;
620
+			}
580 621
 
581 622
 			@fclose($fp);
582 623
 		}
583
-		foreach ($extra_files as $file)
584
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
624
+		foreach ($extra_files as $file) {
625
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
626
+		}
585 627
 	}
586 628
 
587 629
 	$failure = count($failed_files) >= 1;
588 630
 
589
-	if (!isset($_SERVER))
590
-		return !$failure;
631
+	if (!isset($_SERVER)) {
632
+			return !$failure;
633
+	}
591 634
 
592 635
 	// Put the list into context.
593 636
 	$incontext['failed_files'] = $failed_files;
@@ -635,19 +678,23 @@  discard block
 block discarded – undo
635 678
 
636 679
 		if (!isset($ftp) || $ftp->error !== false)
637 680
 		{
638
-			if (!isset($ftp))
639
-				$ftp = new ftp_connection(null);
681
+			if (!isset($ftp)) {
682
+							$ftp = new ftp_connection(null);
683
+			}
640 684
 			// Save the error so we can mess with listing...
641
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
642
-				$incontext['ftp_errors'][] = $ftp->last_message;
685
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
686
+							$incontext['ftp_errors'][] = $ftp->last_message;
687
+			}
643 688
 
644 689
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
645 690
 
646
-			if (empty($_POST['ftp_path']) && $found_path)
647
-				$_POST['ftp_path'] = $detect_path;
691
+			if (empty($_POST['ftp_path']) && $found_path) {
692
+							$_POST['ftp_path'] = $detect_path;
693
+			}
648 694
 
649
-			if (!isset($_POST['ftp_username']))
650
-				$_POST['ftp_username'] = $username;
695
+			if (!isset($_POST['ftp_username'])) {
696
+							$_POST['ftp_username'] = $username;
697
+			}
651 698
 
652 699
 			// Set the username etc, into context.
653 700
 			$incontext['ftp'] = array(
@@ -659,8 +706,7 @@  discard block
 block discarded – undo
659 706
 			);
660 707
 
661 708
 			return false;
662
-		}
663
-		else
709
+		} else
664 710
 		{
665 711
 			$_SESSION['installer_temp_ftp'] = array(
666 712
 				'server' => $_POST['ftp_server'],
@@ -674,10 +720,12 @@  discard block
 block discarded – undo
674 720
 
675 721
 			foreach ($failed_files as $file)
676 722
 			{
677
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
678
-					$ftp->chmod($file, 0755);
679
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
680
-					$ftp->chmod($file, 0777);
723
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
724
+									$ftp->chmod($file, 0755);
725
+				}
726
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
727
+									$ftp->chmod($file, 0777);
728
+				}
681 729
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
682 730
 				{
683 731
 					$failed_files_updated[] = $file;
@@ -733,15 +781,17 @@  discard block
 block discarded – undo
733 781
 
734 782
 			if (!$foundOne)
735 783
 			{
736
-				if (isset($db['default_host']))
737
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
784
+				if (isset($db['default_host'])) {
785
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
786
+				}
738 787
 				if (isset($db['default_user']))
739 788
 				{
740 789
 					$incontext['db']['user'] = ini_get($db['default_user']);
741 790
 					$incontext['db']['name'] = ini_get($db['default_user']);
742 791
 				}
743
-				if (isset($db['default_password']))
744
-					$incontext['db']['pass'] = ini_get($db['default_password']);
792
+				if (isset($db['default_password'])) {
793
+									$incontext['db']['pass'] = ini_get($db['default_password']);
794
+				}
745 795
 
746 796
 				// For simplicity and less confusion, leave the port blank by default
747 797
 				$incontext['db']['port'] = '';
@@ -760,10 +810,10 @@  discard block
 block discarded – undo
760 810
 		$incontext['db']['server'] = $_POST['db_server'];
761 811
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
762 812
 
763
-		if (!empty($_POST['db_port']))
764
-			$incontext['db']['port'] = $_POST['db_port'];
765
-	}
766
-	else
813
+		if (!empty($_POST['db_port'])) {
814
+					$incontext['db']['port'] = $_POST['db_port'];
815
+		}
816
+	} else
767 817
 	{
768 818
 		$incontext['db']['prefix'] = 'smf_';
769 819
 	}
@@ -799,10 +849,11 @@  discard block
 block discarded – undo
799 849
 		if (!empty($_POST['db_port']))
800 850
 		{
801 851
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
802
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
803
-				$vars['db_port'] = (int) $_POST['db_port'];
804
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
805
-				$vars['db_port'] = (int) $_POST['db_port'];
852
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
853
+							$vars['db_port'] = (int) $_POST['db_port'];
854
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
855
+							$vars['db_port'] = (int) $_POST['db_port'];
856
+			}
806 857
 		}
807 858
 
808 859
 		// God I hope it saved!
@@ -815,8 +866,9 @@  discard block
 block discarded – undo
815 866
 		// Make sure it works.
816 867
 		require(dirname(__FILE__) . '/Settings.php');
817 868
 
818
-		if (empty($sourcedir))
819
-			$sourcedir = dirname(__FILE__) . '/Sources';
869
+		if (empty($sourcedir)) {
870
+					$sourcedir = dirname(__FILE__) . '/Sources';
871
+		}
820 872
 
821 873
 		// Better find the database file!
822 874
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -826,18 +878,21 @@  discard block
 block discarded – undo
826 878
 		}
827 879
 
828 880
 		// Now include it for database functions!
829
-		if (!defined('SMF'))
830
-			define('SMF', 1);
881
+		if (!defined('SMF')) {
882
+					define('SMF', 1);
883
+		}
831 884
 
832 885
 		$modSettings['disableQueryCheck'] = true;
833
-		if (empty($smcFunc))
834
-			$smcFunc = array();
886
+		if (empty($smcFunc)) {
887
+					$smcFunc = array();
888
+		}
835 889
 
836 890
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
837 891
 
838 892
 		// What - running PHP4? The shame!
839
-		if (version_compare(PHP_VERSION, '5', '<'))
840
-			require_once($sourcedir . '/Subs-Compat.php');
893
+		if (version_compare(PHP_VERSION, '5', '<')) {
894
+					require_once($sourcedir . '/Subs-Compat.php');
895
+		}
841 896
 
842 897
 		// Attempt a connection.
843 898
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -925,12 +980,14 @@  discard block
 block discarded – undo
925 980
 	$incontext['page_title'] = $txt['install_settings'];
926 981
 
927 982
 	// Let's see if we got the database type correct.
928
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
929
-		$db_type = $_POST['db_type'];
983
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
984
+			$db_type = $_POST['db_type'];
985
+	}
930 986
 
931 987
 	// Else we'd better be able to get the connection.
932
-	else
933
-		load_database();
988
+	else {
989
+			load_database();
990
+	}
934 991
 
935 992
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
936 993
 
@@ -939,10 +996,11 @@  discard block
 block discarded – undo
939 996
 
940 997
 		$secure = false;
941 998
 
942
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
943
-			$secure = true;
944
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
945
-			$secure = true;
999
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1000
+					$secure = true;
1001
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1002
+					$secure = true;
1003
+		}
946 1004
 
947 1005
 	// Now, to put what we've learned together... and add a path.
948 1006
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -974,18 +1032,21 @@  discard block
 block discarded – undo
974 1032
 	// Submitting?
975 1033
 	if (isset($_POST['boardurl']))
976 1034
 	{
977
-		if (substr($_POST['boardurl'], -10) == '/index.php')
978
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
979
-		elseif (substr($_POST['boardurl'], -1) == '/')
980
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
981
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
982
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1035
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1036
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1037
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1038
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1039
+		}
1040
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1041
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1042
+		}
983 1043
 
984 1044
 		//Make sure boardurl is aligned with ssl setting
985
-		if (empty($_POST['force_ssl']))
986
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
987
-		else
988
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1045
+		if (empty($_POST['force_ssl'])) {
1046
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1047
+		} else {
1048
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1049
+		}
989 1050
 
990 1051
 		// Save these variables.
991 1052
 		$vars = array(
@@ -1024,10 +1085,10 @@  discard block
 block discarded – undo
1024 1085
 			{
1025 1086
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1026 1087
 				return false;
1027
-			}
1028
-			else
1029
-				// Set the character set here.
1088
+			} else {
1089
+							// Set the character set here.
1030 1090
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1091
+			}
1031 1092
 		}
1032 1093
 
1033 1094
 		// Good, skip on.
@@ -1047,8 +1108,9 @@  discard block
 block discarded – undo
1047 1108
 	$incontext['continue'] = 1;
1048 1109
 
1049 1110
 	// Already done?
1050
-	if (isset($_POST['pop_done']))
1051
-		return true;
1111
+	if (isset($_POST['pop_done'])) {
1112
+			return true;
1113
+	}
1052 1114
 
1053 1115
 	// Reload settings.
1054 1116
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1066,8 +1128,9 @@  discard block
 block discarded – undo
1066 1128
 	$modSettings = array();
1067 1129
 	if ($result !== false)
1068 1130
 	{
1069
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1070
-			$modSettings[$row['variable']] = $row['value'];
1131
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1132
+					$modSettings[$row['variable']] = $row['value'];
1133
+		}
1071 1134
 		$smcFunc['db_free_result']($result);
1072 1135
 
1073 1136
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1080,20 +1143,22 @@  discard block
 block discarded – undo
1080 1143
 	$modSettings['disableQueryCheck'] = true;
1081 1144
 
1082 1145
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1083
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1084
-		$smcFunc['db_query']('', '
1146
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1147
+			$smcFunc['db_query']('', '
1085 1148
 			SET NAMES {string:utf8}',
1086 1149
 			array(
1087 1150
 				'db_error_skip' => true,
1088 1151
 				'utf8' => 'utf8',
1089 1152
 			)
1090 1153
 		);
1154
+	}
1091 1155
 
1092 1156
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1093
-	if (substr(__DIR__, -1) == '\\')
1094
-		$attachdir = __DIR__ . 'attachments';
1095
-	else
1096
-		$attachdir = __DIR__ . '/attachments';
1157
+	if (substr(__DIR__, -1) == '\\') {
1158
+			$attachdir = __DIR__ . 'attachments';
1159
+	} else {
1160
+			$attachdir = __DIR__ . '/attachments';
1161
+	}
1097 1162
 
1098 1163
 	$replaces = array(
1099 1164
 		'{$db_prefix}' => $db_prefix,
@@ -1110,8 +1175,9 @@  discard block
 block discarded – undo
1110 1175
 
1111 1176
 	foreach ($txt as $key => $value)
1112 1177
 	{
1113
-		if (substr($key, 0, 8) == 'default_')
1114
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1178
+		if (substr($key, 0, 8) == 'default_') {
1179
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1180
+		}
1115 1181
 	}
1116 1182
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1117 1183
 
@@ -1126,8 +1192,9 @@  discard block
 block discarded – undo
1126 1192
 
1127 1193
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1128 1194
 		{
1129
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1130
-				$engines[] = $row['Engine'];
1195
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1196
+							$engines[] = $row['Engine'];
1197
+			}
1131 1198
 		}
1132 1199
 
1133 1200
 		// Done with this now
@@ -1151,8 +1218,7 @@  discard block
 block discarded – undo
1151 1218
 			$replaces['START TRANSACTION;'] = '';
1152 1219
 			$replaces['COMMIT;'] = '';
1153 1220
 		}
1154
-	}
1155
-	else
1221
+	} else
1156 1222
 	{
1157 1223
 		$has_innodb = false;
1158 1224
 	}
@@ -1174,21 +1240,24 @@  discard block
 block discarded – undo
1174 1240
 	foreach ($sql_lines as $count => $line)
1175 1241
 	{
1176 1242
 		// No comments allowed!
1177
-		if (substr(trim($line), 0, 1) != '#')
1178
-			$current_statement .= "\n" . rtrim($line);
1243
+		if (substr(trim($line), 0, 1) != '#') {
1244
+					$current_statement .= "\n" . rtrim($line);
1245
+		}
1179 1246
 
1180 1247
 		// Is this the end of the query string?
1181
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1182
-			continue;
1248
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1249
+					continue;
1250
+		}
1183 1251
 
1184 1252
 		// Does this table already exist?  If so, don't insert more data into it!
1185 1253
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1186 1254
 		{
1187 1255
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1188
-			if (!empty($matches[0]))
1189
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1190
-			else
1191
-				$incontext['sql_results']['insert_dups']++;
1256
+			if (!empty($matches[0])) {
1257
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1258
+			} else {
1259
+							$incontext['sql_results']['insert_dups']++;
1260
+			}
1192 1261
 
1193 1262
 			$current_statement = '';
1194 1263
 			continue;
@@ -1197,8 +1266,9 @@  discard block
 block discarded – undo
1197 1266
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1198 1267
 		{
1199 1268
 			// Use the appropriate function based on the DB type
1200
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1201
-				$db_errorno = $db_type . '_errno';
1269
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1270
+							$db_errorno = $db_type . '_errno';
1271
+			}
1202 1272
 
1203 1273
 			// Error 1050: Table already exists!
1204 1274
 			// @todo Needs to be made better!
@@ -1213,18 +1283,18 @@  discard block
 block discarded – undo
1213 1283
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1214 1284
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1215 1285
 			}
1216
-		}
1217
-		else
1286
+		} else
1218 1287
 		{
1219
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1220
-				$incontext['sql_results']['tables']++;
1221
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1288
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1289
+							$incontext['sql_results']['tables']++;
1290
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1222 1291
 			{
1223 1292
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1224
-				if (!empty($matches[0]))
1225
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1226
-				else
1227
-					$incontext['sql_results']['inserts']++;
1293
+				if (!empty($matches[0])) {
1294
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1295
+				} else {
1296
+									$incontext['sql_results']['inserts']++;
1297
+				}
1228 1298
 			}
1229 1299
 		}
1230 1300
 
@@ -1237,15 +1307,17 @@  discard block
 block discarded – undo
1237 1307
 	// Sort out the context for the SQL.
1238 1308
 	foreach ($incontext['sql_results'] as $key => $number)
1239 1309
 	{
1240
-		if ($number == 0)
1241
-			unset($incontext['sql_results'][$key]);
1242
-		else
1243
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1310
+		if ($number == 0) {
1311
+					unset($incontext['sql_results'][$key]);
1312
+		} else {
1313
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1314
+		}
1244 1315
 	}
1245 1316
 
1246 1317
 	// Make sure UTF will be used globally.
1247
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1248
-		$newSettings[] = array('global_character_set', 'UTF-8');
1318
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1319
+			$newSettings[] = array('global_character_set', 'UTF-8');
1320
+	}
1249 1321
 
1250 1322
 	// Auto-detect local & global cookie settings
1251 1323
 	$url_parts = parse_url($boardurl);
@@ -1274,15 +1346,19 @@  discard block
 block discarded – undo
1274 1346
 
1275 1347
 		// Look for subfolder, if found, set localCookie
1276 1348
 		// Checking for len > 1 ensures you don't have just a slash...
1277
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1278
-			$localCookies = '1';
1349
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1350
+					$localCookies = '1';
1351
+		}
1279 1352
 
1280
-		if (isset($globalCookies))
1281
-			$newSettings[] = array('globalCookies', $globalCookies);
1282
-		if (isset($globalCookiesDomain))
1283
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1284
-		if (isset($localCookies))
1285
-			$newSettings[] = array('localCookies', $localCookies);
1353
+		if (isset($globalCookies)) {
1354
+					$newSettings[] = array('globalCookies', $globalCookies);
1355
+		}
1356
+		if (isset($globalCookiesDomain)) {
1357
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1358
+		}
1359
+		if (isset($localCookies)) {
1360
+					$newSettings[] = array('localCookies', $localCookies);
1361
+		}
1286 1362
 	}
1287 1363
 
1288 1364
 	// Are we allowing stat collection?
@@ -1300,16 +1376,17 @@  discard block
 block discarded – undo
1300 1376
 			fwrite($fp, $out);
1301 1377
 
1302 1378
 			$return_data = '';
1303
-			while (!feof($fp))
1304
-				$return_data .= fgets($fp, 128);
1379
+			while (!feof($fp)) {
1380
+							$return_data .= fgets($fp, 128);
1381
+			}
1305 1382
 
1306 1383
 			fclose($fp);
1307 1384
 
1308 1385
 			// Get the unique site ID.
1309 1386
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1310 1387
 
1311
-			if (!empty($ID[1]))
1312
-				$smcFunc['db_insert']('replace',
1388
+			if (!empty($ID[1])) {
1389
+							$smcFunc['db_insert']('replace',
1313 1390
 					$db_prefix . 'settings',
1314 1391
 					array('variable' => 'string', 'value' => 'string'),
1315 1392
 					array(
@@ -1318,11 +1395,12 @@  discard block
 block discarded – undo
1318 1395
 					),
1319 1396
 					array('variable')
1320 1397
 				);
1398
+			}
1321 1399
 		}
1322 1400
 	}
1323 1401
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1324
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1325
-		$smcFunc['db_query']('', '
1402
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1403
+			$smcFunc['db_query']('', '
1326 1404
 			DELETE FROM {db_prefix}settings
1327 1405
 			WHERE variable = {string:enable_sm_stats}',
1328 1406
 			array(
@@ -1330,20 +1408,23 @@  discard block
 block discarded – undo
1330 1408
 				'db_error_skip' => true,
1331 1409
 			)
1332 1410
 		);
1411
+	}
1333 1412
 
1334 1413
 	// Are we enabling SSL?
1335
-	if (!empty($_POST['force_ssl']))
1336
-		$newSettings[] = array('force_ssl', 1);
1414
+	if (!empty($_POST['force_ssl'])) {
1415
+			$newSettings[] = array('force_ssl', 1);
1416
+	}
1337 1417
 
1338 1418
 	// Setting a timezone is required.
1339 1419
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1340 1420
 	{
1341 1421
 		// Get PHP's default timezone, if set
1342 1422
 		$ini_tz = ini_get('date.timezone');
1343
-		if (!empty($ini_tz))
1344
-			$timezone_id = $ini_tz;
1345
-		else
1346
-			$timezone_id = '';
1423
+		if (!empty($ini_tz)) {
1424
+					$timezone_id = $ini_tz;
1425
+		} else {
1426
+					$timezone_id = '';
1427
+		}
1347 1428
 
1348 1429
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1349 1430
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1352,8 +1433,9 @@  discard block
 block discarded – undo
1352 1433
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1353 1434
 		}
1354 1435
 
1355
-		if (date_default_timezone_set($timezone_id))
1356
-			$newSettings[] = array('default_timezone', $timezone_id);
1436
+		if (date_default_timezone_set($timezone_id)) {
1437
+					$newSettings[] = array('default_timezone', $timezone_id);
1438
+		}
1357 1439
 	}
1358 1440
 
1359 1441
 	if (!empty($newSettings))
@@ -1384,16 +1466,18 @@  discard block
 block discarded – undo
1384 1466
 	}
1385 1467
 
1386 1468
 	// MySQL specific stuff
1387
-	if (substr($db_type, 0, 5) != 'mysql')
1388
-		return false;
1469
+	if (substr($db_type, 0, 5) != 'mysql') {
1470
+			return false;
1471
+	}
1389 1472
 
1390 1473
 	// Find database user privileges.
1391 1474
 	$privs = array();
1392 1475
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1393 1476
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1394 1477
 	{
1395
-		if ($row['Privilege'] == 'Alter')
1396
-			$privs[] = $row['Privilege'];
1478
+		if ($row['Privilege'] == 'Alter') {
1479
+					$privs[] = $row['Privilege'];
1480
+		}
1397 1481
 	}
1398 1482
 	$smcFunc['db_free_result']($get_privs);
1399 1483
 
@@ -1423,8 +1507,9 @@  discard block
 block discarded – undo
1423 1507
 	$incontext['continue'] = 1;
1424 1508
 
1425 1509
 	// Skipping?
1426
-	if (!empty($_POST['skip']))
1427
-		return true;
1510
+	if (!empty($_POST['skip'])) {
1511
+			return true;
1512
+	}
1428 1513
 
1429 1514
 	// Need this to check whether we need the database password.
1430 1515
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1441,18 +1526,22 @@  discard block
 block discarded – undo
1441 1526
 	// We need this to properly hash the password for Admin
1442 1527
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1443 1528
 			global $sourcedir;
1444
-			if (function_exists('mb_strtolower'))
1445
-				return mb_strtolower($string, 'UTF-8');
1529
+			if (function_exists('mb_strtolower')) {
1530
+							return mb_strtolower($string, 'UTF-8');
1531
+			}
1446 1532
 			require_once($sourcedir . '/Subs-Charset.php');
1447 1533
 			return utf8_strtolower($string);
1448 1534
 		};
1449 1535
 
1450
-	if (!isset($_POST['username']))
1451
-		$_POST['username'] = '';
1452
-	if (!isset($_POST['email']))
1453
-		$_POST['email'] = '';
1454
-	if (!isset($_POST['server_email']))
1455
-		$_POST['server_email'] = '';
1536
+	if (!isset($_POST['username'])) {
1537
+			$_POST['username'] = '';
1538
+	}
1539
+	if (!isset($_POST['email'])) {
1540
+			$_POST['email'] = '';
1541
+	}
1542
+	if (!isset($_POST['server_email'])) {
1543
+			$_POST['server_email'] = '';
1544
+	}
1456 1545
 
1457 1546
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1458 1547
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1471,8 +1560,9 @@  discard block
 block discarded – undo
1471 1560
 			'admin_group' => 1,
1472 1561
 		)
1473 1562
 	);
1474
-	if ($smcFunc['db_num_rows']($request) != 0)
1475
-		$incontext['skip'] = 1;
1563
+	if ($smcFunc['db_num_rows']($request) != 0) {
1564
+			$incontext['skip'] = 1;
1565
+	}
1476 1566
 	$smcFunc['db_free_result']($request);
1477 1567
 
1478 1568
 	// Trying to create an account?
@@ -1503,8 +1593,9 @@  discard block
 block discarded – undo
1503 1593
 		}
1504 1594
 
1505 1595
 		// Update the webmaster's email?
1506
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1507
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1596
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1597
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1598
+		}
1508 1599
 
1509 1600
 		// Work out whether we're going to have dodgy characters and remove them.
1510 1601
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1527,32 +1618,27 @@  discard block
 block discarded – undo
1527 1618
 			$smcFunc['db_free_result']($result);
1528 1619
 
1529 1620
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1530
-		}
1531
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1621
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1532 1622
 		{
1533 1623
 			// Try the previous step again.
1534 1624
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1535 1625
 			return false;
1536
-		}
1537
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1626
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1538 1627
 		{
1539 1628
 			// Try the previous step again.
1540 1629
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1541 1630
 			return false;
1542
-		}
1543
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1631
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1544 1632
 		{
1545 1633
 			// One step back, this time fill out a proper admin email address.
1546 1634
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1547 1635
 			return false;
1548
-		}
1549
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1636
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1550 1637
 		{
1551 1638
 			// One step back, this time fill out a proper admin email address.
1552 1639
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1553 1640
 			return false;
1554
-		}
1555
-		elseif ($_POST['username'] != '')
1641
+		} elseif ($_POST['username'] != '')
1556 1642
 		{
1557 1643
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1558 1644
 
@@ -1620,17 +1706,19 @@  discard block
 block discarded – undo
1620 1706
 	reloadSettings();
1621 1707
 
1622 1708
 	// Bring a warning over.
1623
-	if (!empty($incontext['account_existed']))
1624
-		$incontext['warning'] = $incontext['account_existed'];
1709
+	if (!empty($incontext['account_existed'])) {
1710
+			$incontext['warning'] = $incontext['account_existed'];
1711
+	}
1625 1712
 
1626
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1627
-		$smcFunc['db_query']('', '
1713
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1714
+			$smcFunc['db_query']('', '
1628 1715
 			SET NAMES {string:db_character_set}',
1629 1716
 			array(
1630 1717
 				'db_character_set' => $db_character_set,
1631 1718
 				'db_error_skip' => true,
1632 1719
 			)
1633 1720
 		);
1721
+	}
1634 1722
 
1635 1723
 	// As track stats is by default enabled let's add some activity.
1636 1724
 	$smcFunc['db_insert']('ignore',
@@ -1651,14 +1739,16 @@  discard block
 block discarded – undo
1651 1739
 	// Only proceed if we can load the data.
1652 1740
 	if ($request)
1653 1741
 	{
1654
-		while ($row = $smcFunc['db_fetch_row']($request))
1655
-			$modSettings[$row[0]] = $row[1];
1742
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1743
+					$modSettings[$row[0]] = $row[1];
1744
+		}
1656 1745
 		$smcFunc['db_free_result']($request);
1657 1746
 	}
1658 1747
 
1659 1748
 	// Automatically log them in ;)
1660
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1661
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1749
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1750
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1751
+	}
1662 1752
 
1663 1753
 	$result = $smcFunc['db_query']('', '
1664 1754
 		SELECT value
@@ -1669,13 +1759,14 @@  discard block
 block discarded – undo
1669 1759
 			'db_error_skip' => true,
1670 1760
 		)
1671 1761
 	);
1672
-	if ($smcFunc['db_num_rows']($result) != 0)
1673
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1762
+	if ($smcFunc['db_num_rows']($result) != 0) {
1763
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1764
+	}
1674 1765
 	$smcFunc['db_free_result']($result);
1675 1766
 
1676
-	if (empty($db_sessions))
1677
-		$_SESSION['admin_time'] = time();
1678
-	else
1767
+	if (empty($db_sessions)) {
1768
+			$_SESSION['admin_time'] = time();
1769
+	} else
1679 1770
 	{
1680 1771
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1681 1772
 
@@ -1699,8 +1790,9 @@  discard block
 block discarded – undo
1699 1790
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1700 1791
 		function($string){
1701 1792
 			global $sourcedir;
1702
-			if (function_exists('mb_strtolower'))
1703
-				return mb_strtolower($string, 'UTF-8');
1793
+			if (function_exists('mb_strtolower')) {
1794
+							return mb_strtolower($string, 'UTF-8');
1795
+			}
1704 1796
 			require_once($sourcedir . '/Subs-Charset.php');
1705 1797
 			return utf8_strtolower($string);
1706 1798
 		};
@@ -1716,8 +1808,9 @@  discard block
 block discarded – undo
1716 1808
 		)
1717 1809
 	);
1718 1810
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1719
-	if ($smcFunc['db_num_rows']($request) > 0)
1720
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1811
+	if ($smcFunc['db_num_rows']($request) > 0) {
1812
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1813
+	}
1721 1814
 	$smcFunc['db_free_result']($request);
1722 1815
 
1723 1816
 	// Now is the perfect time to fetch the SM files.
@@ -1736,8 +1829,9 @@  discard block
 block discarded – undo
1736 1829
 
1737 1830
 	// Check if we need some stupid MySQL fix.
1738 1831
 	$server_version = $smcFunc['db_server_info']();
1739
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1740
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1832
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1833
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1834
+	}
1741 1835
 
1742 1836
 	// Some final context for the template.
1743 1837
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1757,8 +1851,9 @@  discard block
 block discarded – undo
1757 1851
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1758 1852
 
1759 1853
 	// @todo Do we just want to read the file in clean, and split it this way always?
1760
-	if (count($settingsArray) == 1)
1761
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1854
+	if (count($settingsArray) == 1) {
1855
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1856
+	}
1762 1857
 
1763 1858
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1764 1859
 	{
@@ -1766,25 +1861,29 @@  discard block
 block discarded – undo
1766 1861
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1767 1862
 		{
1768 1863
 			// Set the ten lines to nothing.
1769
-			for ($j=0; $j < 10; $j++)
1770
-				$settingsArray[$i++] = '';
1864
+			for ($j=0; $j < 10; $j++) {
1865
+							$settingsArray[$i++] = '';
1866
+			}
1771 1867
 
1772 1868
 			continue;
1773 1869
 		}
1774 1870
 
1775
-		if (trim($settingsArray[$i]) == '?' . '>')
1776
-			$settingsArray[$i] = '';
1871
+		if (trim($settingsArray[$i]) == '?' . '>') {
1872
+					$settingsArray[$i] = '';
1873
+		}
1777 1874
 
1778 1875
 		// Don't trim or bother with it if it's not a variable.
1779
-		if (substr($settingsArray[$i], 0, 1) != '$')
1780
-			continue;
1876
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1877
+					continue;
1878
+		}
1781 1879
 
1782 1880
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1783 1881
 
1784
-		foreach ($vars as $var => $val)
1785
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1882
+		foreach ($vars as $var => $val) {
1883
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1786 1884
 			{
1787 1885
 				$comment = strstr($settingsArray[$i], '#');
1886
+		}
1788 1887
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1789 1888
 				unset($vars[$var]);
1790 1889
 			}
@@ -1794,36 +1893,41 @@  discard block
 block discarded – undo
1794 1893
 	if (!empty($vars))
1795 1894
 	{
1796 1895
 		$settingsArray[$i++] = '';
1797
-		foreach ($vars as $var => $val)
1798
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1896
+		foreach ($vars as $var => $val) {
1897
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1898
+		}
1799 1899
 	}
1800 1900
 
1801 1901
 	// Blank out the file - done to fix a oddity with some servers.
1802 1902
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1803
-	if (!$fp)
1804
-		return false;
1903
+	if (!$fp) {
1904
+			return false;
1905
+	}
1805 1906
 	fclose($fp);
1806 1907
 
1807 1908
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1808 1909
 
1809 1910
 	// Gotta have one of these ;)
1810
-	if (trim($settingsArray[0]) != '<?php')
1811
-		fwrite($fp, "<?php\n");
1911
+	if (trim($settingsArray[0]) != '<?php') {
1912
+			fwrite($fp, "<?php\n");
1913
+	}
1812 1914
 
1813 1915
 	$lines = count($settingsArray);
1814 1916
 	for ($i = 0; $i < $lines - 1; $i++)
1815 1917
 	{
1816 1918
 		// Don't just write a bunch of blank lines.
1817
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1818
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1919
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1920
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1921
+		}
1819 1922
 	}
1820 1923
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1821 1924
 	fclose($fp);
1822 1925
 
1823 1926
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1824 1927
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1825
-	if (function_exists('opcache_invalidate'))
1826
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1928
+	if (function_exists('opcache_invalidate')) {
1929
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1930
+	}
1827 1931
 
1828 1932
 	return true;
1829 1933
 }
@@ -1833,10 +1937,11 @@  discard block
 block discarded – undo
1833 1937
 	global $cachedir;
1834 1938
 
1835 1939
 	// Write out the db_last_error file with the error timestamp
1836
-	if (!empty($cachedir) && is_writable($cachedir))
1837
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1838
-	else
1839
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1940
+	if (!empty($cachedir) && is_writable($cachedir)) {
1941
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1942
+	} else {
1943
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1944
+	}
1840 1945
 
1841 1946
 	return true;
1842 1947
 }
@@ -1853,9 +1958,9 @@  discard block
 block discarded – undo
1853 1958
 	SecFilterScanPOST Off
1854 1959
 </IfModule>';
1855 1960
 
1856
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1857
-		return true;
1858
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1961
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1962
+			return true;
1963
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1859 1964
 	{
1860 1965
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1861 1966
 
@@ -1867,29 +1972,28 @@  discard block
 block discarded – undo
1867 1972
 				fwrite($ht_handle, $htaccess_addition);
1868 1973
 				fclose($ht_handle);
1869 1974
 				return true;
1975
+			} else {
1976
+							return false;
1870 1977
 			}
1871
-			else
1872
-				return false;
1978
+		} else {
1979
+					return true;
1873 1980
 		}
1874
-		else
1875
-			return true;
1876
-	}
1877
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1878
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1879
-	elseif (is_writable(dirname(__FILE__)))
1981
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1982
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1983
+	} elseif (is_writable(dirname(__FILE__)))
1880 1984
 	{
1881 1985
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1882 1986
 		{
1883 1987
 			fwrite($ht_handle, $htaccess_addition);
1884 1988
 			fclose($ht_handle);
1885 1989
 			return true;
1990
+		} else {
1991
+					return false;
1886 1992
 		}
1887
-		else
1993
+	} else {
1888 1994
 			return false;
1889 1995
 	}
1890
-	else
1891
-		return false;
1892
-}
1996
+	}
1893 1997
 
1894 1998
 function template_install_above()
1895 1999
 {
@@ -1927,9 +2031,10 @@  discard block
 block discarded – undo
1927 2031
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1928 2032
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1929 2033
 
1930
-		foreach ($incontext['detected_languages'] as $lang => $name)
1931
-			echo '
2034
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2035
+					echo '
1932 2036
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2037
+		}
1933 2038
 
1934 2039
 		echo '
1935 2040
 								</select>
@@ -1949,9 +2054,10 @@  discard block
 block discarded – undo
1949 2054
 						<h2>', $txt['upgrade_progress'], '</h2>
1950 2055
 						<ul>';
1951 2056
 
1952
-	foreach ($incontext['steps'] as $num => $step)
1953
-		echo '
2057
+	foreach ($incontext['steps'] as $num => $step) {
2058
+			echo '
1954 2059
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2060
+	}
1955 2061
 
1956 2062
 	echo '
1957 2063
 						</ul>
@@ -1976,20 +2082,23 @@  discard block
 block discarded – undo
1976 2082
 		echo '
1977 2083
 								<div class="floatright">';
1978 2084
 
1979
-		if (!empty($incontext['continue']))
1980
-			echo '
2085
+		if (!empty($incontext['continue'])) {
2086
+					echo '
1981 2087
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button" />';
1982
-		if (!empty($incontext['skip']))
1983
-			echo '
2088
+		}
2089
+		if (!empty($incontext['skip'])) {
2090
+					echo '
1984 2091
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button" />';
2092
+		}
1985 2093
 		echo '
1986 2094
 								</div>';
1987 2095
 	}
1988 2096
 
1989 2097
 	// Show the closing form tag and other data only if not in the last step
1990
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1991
-		echo '
2098
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2099
+			echo '
1992 2100
 							</form>';
2101
+	}
1993 2102
 
1994 2103
 	echo '
1995 2104
 						</div>
@@ -2024,13 +2133,15 @@  discard block
 block discarded – undo
2024 2133
 		</div>';
2025 2134
 
2026 2135
 	// Show the warnings, or not.
2027
-	if (template_warning_divs())
2028
-		echo '
2136
+	if (template_warning_divs()) {
2137
+			echo '
2029 2138
 		<h3>', $txt['install_all_lovely'], '</h3>';
2139
+	}
2030 2140
 
2031 2141
 	// Say we want the continue button!
2032
-	if (empty($incontext['error']))
2033
-		$incontext['continue'] = 1;
2142
+	if (empty($incontext['error'])) {
2143
+			$incontext['continue'] = 1;
2144
+	}
2034 2145
 
2035 2146
 	// For the latest version stuff.
2036 2147
 	echo '
@@ -2064,8 +2175,8 @@  discard block
 block discarded – undo
2064 2175
 	global $txt, $incontext;
2065 2176
 
2066 2177
 	// Errors are very serious..
2067
-	if (!empty($incontext['error']))
2068
-		echo '
2178
+	if (!empty($incontext['error'])) {
2179
+			echo '
2069 2180
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2070 2181
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2071 2182
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -2073,9 +2184,10 @@  discard block
 block discarded – undo
2073 2184
 				', $incontext['error'], '
2074 2185
 			</div>
2075 2186
 		</div>';
2187
+	}
2076 2188
 	// A warning message?
2077
-	elseif (!empty($incontext['warning']))
2078
-		echo '
2189
+	elseif (!empty($incontext['warning'])) {
2190
+			echo '
2079 2191
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2080 2192
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2081 2193
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2083,6 +2195,7 @@  discard block
 block discarded – undo
2083 2195
 				', $incontext['warning'], '
2084 2196
 			</div>
2085 2197
 		</div>';
2198
+	}
2086 2199
 
2087 2200
 	return empty($incontext['error']) && empty($incontext['warning']);
2088 2201
 }
@@ -2098,27 +2211,30 @@  discard block
 block discarded – undo
2098 2211
 			<li>', $incontext['failed_files']), '</li>
2099 2212
 		</ul>';
2100 2213
 
2101
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2102
-		echo '
2214
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2215
+			echo '
2103 2216
 		<hr>
2104 2217
 		<p>', $txt['chmod_linux_info'], '</p>
2105 2218
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2219
+	}
2106 2220
 
2107 2221
 	// This is serious!
2108
-	if (!template_warning_divs())
2109
-		return;
2222
+	if (!template_warning_divs()) {
2223
+			return;
2224
+	}
2110 2225
 
2111 2226
 	echo '
2112 2227
 		<hr>
2113 2228
 		<p>', $txt['ftp_setup_info'], '</p>';
2114 2229
 
2115
-	if (!empty($incontext['ftp_errors']))
2116
-		echo '
2230
+	if (!empty($incontext['ftp_errors'])) {
2231
+			echo '
2117 2232
 		<div class="error_message">
2118 2233
 			', $txt['error_ftp_no_connect'], '<br><br>
2119 2234
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2120 2235
 		</div>
2121 2236
 		<br>';
2237
+	}
2122 2238
 
2123 2239
 	echo '
2124 2240
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2178,17 +2294,17 @@  discard block
 block discarded – undo
2178 2294
 				<td>
2179 2295
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2180 2296
 
2181
-	foreach ($incontext['supported_databases'] as $key => $db)
2182
-			echo '
2297
+	foreach ($incontext['supported_databases'] as $key => $db) {
2298
+				echo '
2183 2299
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2300
+	}
2184 2301
 
2185 2302
 	echo '
2186 2303
 					</select>
2187 2304
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2188 2305
 				</td>
2189 2306
 			</tr>';
2190
-	}
2191
-	else
2307
+	} else
2192 2308
 	{
2193 2309
 		echo '
2194 2310
 			<tr style="display: none;">
@@ -2381,9 +2497,10 @@  discard block
 block discarded – undo
2381 2497
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2382 2498
 				<ul>';
2383 2499
 
2384
-		foreach ($incontext['failures'] as $line => $fail)
2385
-			echo '
2500
+		foreach ($incontext['failures'] as $line => $fail) {
2501
+					echo '
2386 2502
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2503
+		}
2387 2504
 
2388 2505
 		echo '
2389 2506
 				</ul>';
@@ -2444,15 +2561,16 @@  discard block
 block discarded – undo
2444 2561
 			</tr>
2445 2562
 		</table>';
2446 2563
 
2447
-	if ($incontext['require_db_confirm'])
2448
-		echo '
2564
+	if ($incontext['require_db_confirm']) {
2565
+			echo '
2449 2566
 		<h2>', $txt['user_settings_database'], '</h2>
2450 2567
 		<p>', $txt['user_settings_database_info'], '</p>
2451 2568
 
2452 2569
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2453 2570
 			<input type="password" name="password3" size="30" />
2454 2571
 		</div>';
2455
-}
2572
+	}
2573
+	}
2456 2574
 
2457 2575
 // Tell them it's done, and to delete.
2458 2576
 function template_delete_install()
@@ -2465,14 +2583,15 @@  discard block
 block discarded – undo
2465 2583
 	template_warning_divs();
2466 2584
 
2467 2585
 	// Install directory still writable?
2468
-	if ($incontext['dir_still_writable'])
2469
-		echo '
2586
+	if ($incontext['dir_still_writable']) {
2587
+			echo '
2470 2588
 		<em>', $txt['still_writable'], '</em><br>
2471 2589
 		<br>';
2590
+	}
2472 2591
 
2473 2592
 	// Don't show the box if it's like 99% sure it won't work :P.
2474
-	if ($incontext['probably_delete_install'])
2475
-		echo '
2593
+	if ($incontext['probably_delete_install']) {
2594
+			echo '
2476 2595
 		<div style="margin: 1ex; font-weight: bold;">
2477 2596
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2478 2597
 		</div>
@@ -2488,6 +2607,7 @@  discard block
 block discarded – undo
2488 2607
 			}
2489 2608
 		</script>
2490 2609
 		<br>';
2610
+	}
2491 2611
 
2492 2612
 	echo '
2493 2613
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 
256 256
 		case 'datetime':
257 257
 			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
258
-				return 'str_to_date('.
259
-					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
258
+				return 'str_to_date(' .
259
+					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) .
260 260
 					',\'%Y-%m-%d %h:%i:%s\')';
261 261
 			else
262 262
 				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		$old_pos = 0;
461 461
 		$pos = -1;
462 462
 		// Remove the string escape for better runtime
463
-		$db_string_1 = str_replace('\\\'','',$db_string);
463
+		$db_string_1 = str_replace('\\\'', '', $db_string);
464 464
 		while (true)
465 465
 		{
466 466
 			$pos = strpos($db_string_1, '\'', $pos + 1);
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 	{
843 843
 		$count = count($insertRows);
844 844
 		$ai = 0;
845
-		for($i = 0; $i < $count; $i++)
845
+		for ($i = 0; $i < $count; $i++)
846 846
 		{
847 847
 			$old_id = $smcFunc['db_insert_id']();
848 848
 
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 				$count2 = count($indexed_columns);
869 869
 				for ($x = 0; $x < $count2; $x++)
870 870
 				{
871
-					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
871
+					$where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x];
872 872
 					if (($x + 1) < $count2)
873 873
 						$where_string += ' AND ';
874 874
 				}
875 875
 
876
-				$request = $smcFunc['db_query']('','
877
-					SELECT `'. $keys[0] . '` FROM ' . $table .'
876
+				$request = $smcFunc['db_query']('', '
877
+					SELECT `'. $keys[0] . '` FROM ' . $table . '
878 878
 					WHERE ' . $where_string . ' LIMIT 1',
879 879
 					array()
880 880
 				);
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 			$return_var = array();
904 904
 			$count = count($insertRows);
905 905
 			$start = smf_db_insert_id($table, $keys[0]);
906
-			for ($i = 0; $i < $count; $i++ )
906
+			for ($i = 0; $i < $count; $i++)
907 907
 				$return_var[] = $start + $i;
908 908
 		}
909 909
 		return $return_var;
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
1037 1037
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
1038 1038
 		$error_array[7], $error_array[8]);
1039
-	mysqli_stmt_execute ($mysql_error_data_prep);
1039
+	mysqli_stmt_execute($mysql_error_data_prep);
1040 1040
 }
1041 1041
 
1042 1042
 /**
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
  */
1051 1051
 function smf_db_custom_order($field, $array_values, $desc = false)
1052 1052
 {
1053
-	$return = 'CASE '. $field . ' ';
1053
+	$return = 'CASE ' . $field . ' ';
1054 1054
 	$count = count($array_values);
1055 1055
 	$then = ($desc ? ' THEN -' : ' THEN ');
1056 1056
 
Please login to merge, or discard this patch.
Braces   +254 added lines, -187 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -64,9 +65,11 @@  discard block
 block discarded – undo
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 			'db_native_replace'			=> 'smf_db_native_replace',
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$db_server = 'p:' . $db_server;
70
+	if (!empty($db_options['persist'])) {
71
+			$db_server = 'p:' . $db_server;
72
+	}
70 73
 
71 74
 	$connection = mysqli_init();
72 75
 
@@ -76,24 +79,27 @@  discard block
 block discarded – undo
76 79
 
77 80
 	if ($connection)
78 81
 	{
79
-		if (!empty($db_options['port']))
80
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
81
-		else
82
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
82
+		if (!empty($db_options['port'])) {
83
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
84
+		} else {
85
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
86
+		}
83 87
 	}
84 88
 
85 89
 	// Something's wrong, show an error if its fatal (which we assume it is)
86 90
 	if ($success === false)
87 91
 	{
88
-		if (!empty($db_options['non_fatal']))
89
-			return null;
90
-		else
91
-			display_db_error();
92
+		if (!empty($db_options['non_fatal'])) {
93
+					return null;
94
+		} else {
95
+					display_db_error();
96
+		}
92 97
 	}
93 98
 
94 99
 	// Select the database, unless told not to
95
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
96
-		display_db_error();
100
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
101
+			display_db_error();
102
+	}
97 103
 
98 104
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
99 105
 
@@ -166,34 +172,42 @@  discard block
 block discarded – undo
166 172
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
167 173
 
168 174
 	list ($values, $connection) = $db_callback;
169
-	if (!is_object($connection))
170
-		display_db_error();
175
+	if (!is_object($connection)) {
176
+			display_db_error();
177
+	}
171 178
 
172
-	if ($matches[1] === 'db_prefix')
173
-		return $db_prefix;
179
+	if ($matches[1] === 'db_prefix') {
180
+			return $db_prefix;
181
+	}
174 182
 
175
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
176
-		return $user_info[$matches[1]];
183
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
184
+			return $user_info[$matches[1]];
185
+	}
177 186
 
178
-	if ($matches[1] === 'empty')
179
-		return '\'\'';
187
+	if ($matches[1] === 'empty') {
188
+			return '\'\'';
189
+	}
180 190
 
181
-	if (!isset($matches[2]))
182
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
191
+	if (!isset($matches[2])) {
192
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
193
+	}
183 194
 
184
-	if ($matches[1] === 'literal')
185
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
195
+	if ($matches[1] === 'literal') {
196
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
197
+	}
186 198
 
187
-	if (!isset($values[$matches[2]]))
188
-		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__);
199
+	if (!isset($values[$matches[2]])) {
200
+			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__);
201
+	}
189 202
 
190 203
 	$replacement = $values[$matches[2]];
191 204
 
192 205
 	switch ($matches[1])
193 206
 	{
194 207
 		case 'int':
195
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
196
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
208
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
209
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+			}
197 211
 			return (string) (int) $replacement;
198 212
 		break;
199 213
 
@@ -205,65 +219,73 @@  discard block
 block discarded – undo
205 219
 		case 'array_int':
206 220
 			if (is_array($replacement))
207 221
 			{
208
-				if (empty($replacement))
209
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222
+				if (empty($replacement)) {
223
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+				}
210 225
 
211 226
 				foreach ($replacement as $key => $value)
212 227
 				{
213
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
214
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
229
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
230
+					}
215 231
 
216 232
 					$replacement[$key] = (string) (int) $value;
217 233
 				}
218 234
 
219 235
 				return implode(', ', $replacement);
236
+			} else {
237
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
220 238
 			}
221
-			else
222
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223 239
 
224 240
 		break;
225 241
 
226 242
 		case 'array_string':
227 243
 			if (is_array($replacement))
228 244
 			{
229
-				if (empty($replacement))
230
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245
+				if (empty($replacement)) {
246
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+				}
231 248
 
232
-				foreach ($replacement as $key => $value)
233
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
249
+				foreach ($replacement as $key => $value) {
250
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
251
+				}
234 252
 
235 253
 				return implode(', ', $replacement);
254
+			} else {
255
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236 256
 			}
237
-			else
238
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239 257
 		break;
240 258
 
241 259
 		case 'date':
242
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
243
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
244
-			else
245
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
260
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
261
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
262
+			} else {
263
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
264
+			}
246 265
 		break;
247 266
 
248 267
 		case 'time':
249
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
250
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
251
-			else
252
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
269
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
270
+			} else {
271
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
272
+			}
253 273
 		break;
254 274
 
255 275
 		case 'datetime':
256
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
257
-				return 'str_to_date('.
276
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
277
+							return 'str_to_date('.
258 278
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
259 279
 					',\'%Y-%m-%d %h:%i:%s\')';
260
-			else
261
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
280
+			} else {
281
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			}
262 283
 		break;
263 284
 
264 285
 		case 'float':
265
-			if (!is_numeric($replacement))
266
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
286
+			if (!is_numeric($replacement)) {
287
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+			}
267 289
 			return (string) (float) $replacement;
268 290
 		break;
269 291
 
@@ -277,32 +299,37 @@  discard block
 block discarded – undo
277 299
 		break;
278 300
 
279 301
 		case 'inet':
280
-			if ($replacement == 'null' || $replacement == '')
281
-				return 'null';
282
-			if (!isValidIP($replacement))
283
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
302
+			if ($replacement == 'null' || $replacement == '') {
303
+							return 'null';
304
+			}
305
+			if (!isValidIP($replacement)) {
306
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
307
+			}
284 308
 			//we don't use the native support of mysql > 5.6.2
285 309
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
286 310
 
287 311
 		case 'array_inet':
288 312
 			if (is_array($replacement))
289 313
 			{
290
-				if (empty($replacement))
291
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
314
+				if (empty($replacement)) {
315
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
316
+				}
292 317
 
293 318
 				foreach ($replacement as $key => $value)
294 319
 				{
295
-					if ($replacement == 'null' || $replacement == '')
296
-						$replacement[$key] = 'null';
297
-					if (!isValidIP($value))
298
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
320
+					if ($replacement == 'null' || $replacement == '') {
321
+											$replacement[$key] = 'null';
322
+					}
323
+					if (!isValidIP($value)) {
324
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+					}
299 326
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
300 327
 				}
301 328
 
302 329
 				return implode(', ', $replacement);
330
+			} else {
331
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
303 332
 			}
304
-			else
305
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
306 333
 		break;
307 334
 
308 335
 		default:
@@ -373,18 +400,20 @@  discard block
 block discarded – undo
373 400
 	// One more query....
374 401
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
375 402
 
376
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
377
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
403
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
404
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
405
+	}
378 406
 
379 407
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
380 408
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
381 409
 	{
382 410
 		// Add before LIMIT
383
-		if ($pos = strpos($db_string, 'LIMIT '))
384
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
385
-		else
386
-			// Append it.
411
+		if ($pos = strpos($db_string, 'LIMIT ')) {
412
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
413
+		} else {
414
+					// Append it.
387 415
 			$db_string .= "\n\t\t\tORDER BY null";
416
+		}
388 417
 	}
389 418
 
390 419
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -410,17 +439,18 @@  discard block
 block discarded – undo
410 439
 		while (true)
411 440
 		{
412 441
 			$pos = strpos($db_string_1, '\'', $pos + 1);
413
-			if ($pos === false)
414
-				break;
442
+			if ($pos === false) {
443
+							break;
444
+			}
415 445
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
416 446
 
417 447
 			while (true)
418 448
 			{
419 449
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
420 450
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
421
-				if ($pos1 === false)
422
-					break;
423
-				elseif ($pos2 === false || $pos2 > $pos1)
451
+				if ($pos1 === false) {
452
+									break;
453
+				} elseif ($pos2 === false || $pos2 > $pos1)
424 454
 				{
425 455
 					$pos = $pos1;
426 456
 					break;
@@ -436,16 +466,19 @@  discard block
 block discarded – undo
436 466
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
437 467
 
438 468
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
439
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
440
-			$fail = true;
469
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
470
+					$fail = true;
471
+		}
441 472
 		// Trying to change passwords, slow us down, or something?
442
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
443
-			$fail = true;
444
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
445
-			$fail = true;
473
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
474
+					$fail = true;
475
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
476
+					$fail = true;
477
+		}
446 478
 
447
-		if (!empty($fail) && function_exists('log_error'))
448
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
479
+		if (!empty($fail) && function_exists('log_error')) {
480
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
481
+		}
449 482
 	}
450 483
 
451 484
 	// Debugging.
@@ -455,8 +488,9 @@  discard block
 block discarded – undo
455 488
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
456 489
 
457 490
 		// Initialize $db_cache if not already initialized.
458
-		if (!isset($db_cache))
459
-			$db_cache = array();
491
+		if (!isset($db_cache)) {
492
+					$db_cache = array();
493
+		}
460 494
 
461 495
 		if (!empty($_SESSION['debug_redirect']))
462 496
 		{
@@ -472,17 +506,20 @@  discard block
 block discarded – undo
472 506
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
473 507
 	}
474 508
 
475
-	if (empty($db_unbuffered))
476
-		$ret = @mysqli_query($connection, $db_string);
477
-	else
478
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
509
+	if (empty($db_unbuffered)) {
510
+			$ret = @mysqli_query($connection, $db_string);
511
+	} else {
512
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
513
+	}
479 514
 
480
-	if ($ret === false && empty($db_values['db_error_skip']))
481
-		$ret = smf_db_error($db_string, $connection);
515
+	if ($ret === false && empty($db_values['db_error_skip'])) {
516
+			$ret = smf_db_error($db_string, $connection);
517
+	}
482 518
 
483 519
 	// Debugging.
484
-	if (isset($db_show_debug) && $db_show_debug === true)
485
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
520
+	if (isset($db_show_debug) && $db_show_debug === true) {
521
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
522
+	}
486 523
 
487 524
 	return $ret;
488 525
 }
@@ -529,12 +566,13 @@  discard block
 block discarded – undo
529 566
 	// Decide which connection to use
530 567
 	$connection = $connection === null ? $db_connection : $connection;
531 568
 
532
-	if ($type == 'begin')
533
-		return @mysqli_query($connection, 'BEGIN');
534
-	elseif ($type == 'rollback')
535
-		return @mysqli_query($connection, 'ROLLBACK');
536
-	elseif ($type == 'commit')
537
-		return @mysqli_query($connection, 'COMMIT');
569
+	if ($type == 'begin') {
570
+			return @mysqli_query($connection, 'BEGIN');
571
+	} elseif ($type == 'rollback') {
572
+			return @mysqli_query($connection, 'ROLLBACK');
573
+	} elseif ($type == 'commit') {
574
+			return @mysqli_query($connection, 'COMMIT');
575
+	}
538 576
 
539 577
 	return false;
540 578
 }
@@ -572,8 +610,9 @@  discard block
 block discarded – undo
572 610
 	//    1213: Deadlock found.
573 611
 
574 612
 	// Log the error.
575
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
576
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
613
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
614
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
615
+	}
577 616
 
578 617
 	// Database error auto fixing ;).
579 618
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -582,8 +621,9 @@  discard block
 block discarded – undo
582 621
 		$old_cache = @$modSettings['cache_enable'];
583 622
 		$modSettings['cache_enable'] = '1';
584 623
 
585
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
586
-			$db_last_error = max(@$db_last_error, $temp);
624
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
625
+					$db_last_error = max(@$db_last_error, $temp);
626
+		}
587 627
 
588 628
 		if (@$db_last_error < time() - 3600 * 24 * 3)
589 629
 		{
@@ -599,8 +639,9 @@  discard block
 block discarded – undo
599 639
 					foreach ($tables as $table)
600 640
 					{
601 641
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
602
-						if (trim($table) != '')
603
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
642
+						if (trim($table) != '') {
643
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
644
+						}
604 645
 					}
605 646
 				}
606 647
 
@@ -609,8 +650,9 @@  discard block
 block discarded – undo
609 650
 			// Table crashed.  Let's try to fix it.
610 651
 			elseif ($query_errno == 1016)
611 652
 			{
612
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
613
-					$fix_tables = array('`' . $match[1] . '`');
653
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
654
+									$fix_tables = array('`' . $match[1] . '`');
655
+				}
614 656
 			}
615 657
 			// Indexes crashed.  Should be easy to fix!
616 658
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -629,13 +671,15 @@  discard block
 block discarded – undo
629 671
 
630 672
 			// Make a note of the REPAIR...
631 673
 			cache_put_data('db_last_error', time(), 600);
632
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
633
-				updateSettingsFile(array('db_last_error' => time()));
674
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
675
+							updateSettingsFile(array('db_last_error' => time()));
676
+			}
634 677
 
635 678
 			// Attempt to find and repair the broken table.
636
-			foreach ($fix_tables as $table)
637
-				$smcFunc['db_query']('', "
679
+			foreach ($fix_tables as $table) {
680
+							$smcFunc['db_query']('', "
638 681
 					REPAIR TABLE $table", false, false);
682
+			}
639 683
 
640 684
 			// And send off an email!
641 685
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -644,11 +688,12 @@  discard block
 block discarded – undo
644 688
 
645 689
 			// Try the query again...?
646 690
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
647
-			if ($ret !== false)
648
-				return $ret;
691
+			if ($ret !== false) {
692
+							return $ret;
693
+			}
694
+		} else {
695
+					$modSettings['cache_enable'] = $old_cache;
649 696
 		}
650
-		else
651
-			$modSettings['cache_enable'] = $old_cache;
652 697
 
653 698
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
654 699
 		if (in_array($query_errno, array(1205, 1213)))
@@ -661,24 +706,27 @@  discard block
 block discarded – undo
661 706
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
662 707
 
663 708
 					$new_errno = mysqli_errno($db_connection);
664
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
665
-						break;
709
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
710
+											break;
711
+					}
666 712
 				}
667 713
 
668 714
 				// If it failed again, shucks to be you... we're not trying it over and over.
669
-				if ($ret !== false)
670
-					return $ret;
715
+				if ($ret !== false) {
716
+									return $ret;
717
+				}
671 718
 			}
672 719
 		}
673 720
 		// Are they out of space, perhaps?
674 721
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
675 722
 		{
676
-			if (!isset($txt))
677
-				$query_error .= ' - check database storage space.';
678
-			else
723
+			if (!isset($txt)) {
724
+							$query_error .= ' - check database storage space.';
725
+			} else
679 726
 			{
680
-				if (!isset($txt['mysql_error_space']))
681
-					loadLanguage('Errors');
727
+				if (!isset($txt['mysql_error_space'])) {
728
+									loadLanguage('Errors');
729
+				}
682 730
 
683 731
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
684 732
 			}
@@ -686,15 +734,17 @@  discard block
 block discarded – undo
686 734
 	}
687 735
 
688 736
 	// Nothing's defined yet... just die with it.
689
-	if (empty($context) || empty($txt))
690
-		die($query_error);
737
+	if (empty($context) || empty($txt)) {
738
+			die($query_error);
739
+	}
691 740
 
692 741
 	// Show an error message, if possible.
693 742
 	$context['error_title'] = $txt['database_error'];
694
-	if (allowedTo('admin_forum'))
695
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
696
-	else
697
-		$context['error_message'] = $txt['try_again'];
743
+	if (allowedTo('admin_forum')) {
744
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
745
+	} else {
746
+			$context['error_message'] = $txt['try_again'];
747
+	}
698 748
 
699 749
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
700 750
 	{
@@ -726,8 +776,9 @@  discard block
 block discarded – undo
726 776
 	$return_var = null;
727 777
 
728 778
 	// With nothing to insert, simply return.
729
-	if (empty($data))
730
-		return;
779
+	if (empty($data)) {
780
+			return;
781
+	}
731 782
 
732 783
 	// Replace the prefix holder with the actual prefix.
733 784
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -737,23 +788,26 @@  discard block
 block discarded – undo
737 788
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
738 789
 	{
739 790
 		$with_returning = true;
740
-		if ($returnmode == 2)
741
-			$return_var = array();
791
+		if ($returnmode == 2) {
792
+					$return_var = array();
793
+		}
742 794
 	}
743 795
 
744 796
 	// Inserting data as a single row can be done as a single array.
745
-	if (!is_array($data[array_rand($data)]))
746
-		$data = array($data);
797
+	if (!is_array($data[array_rand($data)])) {
798
+			$data = array($data);
799
+	}
747 800
 
748 801
 	// Create the mold for a single row insert.
749 802
 	$insertData = '(';
750 803
 	foreach ($columns as $columnName => $type)
751 804
 	{
752 805
 		// Are we restricting the length?
753
-		if (strpos($type, 'string-') !== false)
754
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
755
-		else
756
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
806
+		if (strpos($type, 'string-') !== false) {
807
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
808
+		} else {
809
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
810
+		}
757 811
 	}
758 812
 	$insertData = substr($insertData, 0, -2) . ')';
759 813
 
@@ -762,8 +816,9 @@  discard block
 block discarded – undo
762 816
 
763 817
 	// Here's where the variables are injected to the query.
764 818
 	$insertRows = array();
765
-	foreach ($data as $dataRow)
766
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
819
+	foreach ($data as $dataRow) {
820
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
821
+	}
767 822
 
768 823
 	// Determine the method of insertion.
769 824
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -782,8 +837,7 @@  discard block
 block discarded – undo
782 837
 			),
783 838
 			$connection
784 839
 		);
785
-	}
786
-	else //special way for ignore method with returning
840
+	} else //special way for ignore method with returning
787 841
 	{
788 842
 		$count = count($insertRows);
789 843
 		$ai = 0;
@@ -803,19 +857,21 @@  discard block
 block discarded – undo
803 857
 			);
804 858
 			$new_id = $smcFunc['db_insert_id']();
805 859
 
806
-			if ($last_id != $new_id) //the inserted value was new
860
+			if ($last_id != $new_id) {
861
+				//the inserted value was new
807 862
 			{
808 863
 				$ai = $new_id;
809 864
 			}
810
-			else	// the inserted value already exists we need to find the pk
865
+			} else	// the inserted value already exists we need to find the pk
811 866
 			{
812 867
 				$where_string = '';
813 868
 				$count2 = count($indexed_columns);
814 869
 				for ($x = 0; $x < $count2; $x++)
815 870
 				{
816 871
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
817
-					if (($x + 1) < $count2)
818
-						$where_string += ' AND ';
872
+					if (($x + 1) < $count2) {
873
+											$where_string += ' AND ';
874
+					}
819 875
 				}
820 876
 
821 877
 				$request = $smcFunc['db_query']('','
@@ -831,25 +887,27 @@  discard block
 block discarded – undo
831 887
 				}
832 888
 			}
833 889
 
834
-			if ($returnmode == 1)
835
-				$return_var = $ai;
836
-			else if ($returnmode == 2)
837
-				$return_var[] = $ai;
890
+			if ($returnmode == 1) {
891
+							$return_var = $ai;
892
+			} else if ($returnmode == 2) {
893
+							$return_var[] = $ai;
894
+			}
838 895
 		}
839 896
 	}
840 897
 
841 898
 
842 899
 	if ($with_returning)
843 900
 	{
844
-		if ($returnmode == 1 && empty($return_var))
845
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
846
-		else if ($returnmode == 2 && empty($return_var))
901
+		if ($returnmode == 1 && empty($return_var)) {
902
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
903
+		} else if ($returnmode == 2 && empty($return_var))
847 904
 		{
848 905
 			$return_var = array();
849 906
 			$count = count($insertRows);
850 907
 			$start = smf_db_insert_id($table, $keys[0]);
851
-			for ($i = 0; $i < $count; $i++ )
852
-				$return_var[] = $start + $i;
908
+			for ($i = 0; $i < $count; $i++ ) {
909
+							$return_var[] = $start + $i;
910
+			}
853 911
 		}
854 912
 		return $return_var;
855 913
 	}
@@ -867,8 +925,9 @@  discard block
 block discarded – undo
867 925
  */
868 926
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
869 927
 {
870
-	if (empty($log_message))
871
-		$log_message = $error_message;
928
+	if (empty($log_message)) {
929
+			$log_message = $error_message;
930
+	}
872 931
 
873 932
 	foreach (debug_backtrace() as $step)
874 933
 	{
@@ -887,12 +946,14 @@  discard block
 block discarded – undo
887 946
 	}
888 947
 
889 948
 	// A special case - we want the file and line numbers for debugging.
890
-	if ($error_type == 'return')
891
-		return array($file, $line);
949
+	if ($error_type == 'return') {
950
+			return array($file, $line);
951
+	}
892 952
 
893 953
 	// Is always a critical error.
894
-	if (function_exists('log_error'))
895
-		log_error($log_message, 'critical', $file, $line);
954
+	if (function_exists('log_error')) {
955
+			log_error($log_message, 'critical', $file, $line);
956
+	}
896 957
 
897 958
 	if (function_exists('fatal_error'))
898 959
 	{
@@ -900,12 +961,12 @@  discard block
 block discarded – undo
900 961
 
901 962
 		// Cannot continue...
902 963
 		exit;
964
+	} elseif ($error_type) {
965
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
966
+	} else {
967
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
968
+	}
903 969
 	}
904
-	elseif ($error_type)
905
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
906
-	else
907
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
908
-}
909 970
 
910 971
 /**
911 972
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -922,10 +983,11 @@  discard block
 block discarded – undo
922 983
 		'\\' => '\\\\',
923 984
 	);
924 985
 
925
-	if ($translate_human_wildcards)
926
-		$replacements += array(
986
+	if ($translate_human_wildcards) {
987
+			$replacements += array(
927 988
 			'*' => '%',
928 989
 		);
990
+	}
929 991
 
930 992
 	return strtr($string, $replacements);
931 993
 }
@@ -939,8 +1001,9 @@  discard block
 block discarded – undo
939 1001
  */
940 1002
 function smf_is_resource($result)
941 1003
 {
942
-	if ($result instanceof mysqli_result)
943
-		return true;
1004
+	if ($result instanceof mysqli_result) {
1005
+			return true;
1006
+	}
944 1007
 
945 1008
 	return false;
946 1009
 }
@@ -969,19 +1032,22 @@  discard block
 block discarded – undo
969 1032
 	static $mysql_error_data_prep;
970 1033
 
971 1034
 	// without database we can't do anything
972
-	if (empty($db_connection))
973
-		return;
1035
+	if (empty($db_connection)) {
1036
+			return;
1037
+	}
974 1038
 
975
-	if (empty($mysql_error_data_prep))
976
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1039
+	if (empty($mysql_error_data_prep)) {
1040
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
977 1041
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line)
978 1042
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?)'
979 1043
 			);
1044
+	}
980 1045
 
981
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
982
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
983
-	else
984
-		$error_array[2] = null;
1046
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1047
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1048
+	} else {
1049
+			$error_array[2] = null;
1050
+	}
985 1051
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi',
986 1052
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
987 1053
 		$error_array[7], $error_array[8]);
@@ -1003,8 +1069,9 @@  discard block
 block discarded – undo
1003 1069
 	$count = count($array_values);
1004 1070
 	$then = ($desc ? ' THEN -' : ' THEN ');
1005 1071
 
1006
-	for ($i = 0; $i < $count; $i++)
1007
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1072
+	for ($i = 0; $i < $count; $i++) {
1073
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1074
+	}
1008 1075
 
1009 1076
 	$return .= 'END';
1010 1077
 	return $return;
Please login to merge, or discard this patch.
Themes/default/Login.template.php 1 patch
Braces   +35 added lines, -24 removed lines patch added patch discarded remove patch
@@ -28,15 +28,17 @@  discard block
 block discarded – undo
28 28
 				<form class="login" action="', $context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '">';
29 29
 
30 30
 	// Did they make a mistake last time?
31
-	if (!empty($context['login_errors']))
32
-		echo '
31
+	if (!empty($context['login_errors'])) {
32
+			echo '
33 33
 					<div class="errorbox">', implode('<br>', $context['login_errors']), '</div>
34 34
 					<br>';
35
+	}
35 36
 
36 37
 	// Or perhaps there's some special description for this time?
37
-	if (isset($context['description']))
38
-		echo '
38
+	if (isset($context['description'])) {
39
+			echo '
39 40
 					<div class="information">', $context['description'], '</div>';
41
+	}
40 42
 
41 43
 	// Now just get the basic information - username, password, etc.
42 44
 	echo '
@@ -61,10 +63,11 @@  discard block
 block discarded – undo
61 63
 						</dd>';
62 64
 
63 65
 	// If they have deleted their account, give them a chance to change their mind.
64
-	if (isset($context['login_show_undelete']))
65
-		echo '
66
+	if (isset($context['login_show_undelete'])) {
67
+			echo '
66 68
 						<dt class="alert">', $txt['undelete_account'], ':</dt>
67 69
 						<dd><input type="checkbox" name="undelete"></dd>';
70
+	}
68 71
 
69 72
 	echo '
70 73
 					</dl>
@@ -82,8 +85,8 @@  discard block
 block discarded – undo
82 85
 							document.getElementById("', !empty($context['from_ajax']) ? 'ajax_' : '', isset($context['default_username']) && $context['default_username'] != '' ? 'loginpass' : 'loginuser', '").focus();
83 86
 						}, 150);';
84 87
 
85
-	if (!empty($context['from_ajax']))
86
-		echo '
88
+	if (!empty($context['from_ajax'])) {
89
+			echo '
87 90
 						form = $("#frmLogin");
88 91
 						form.submit(function(e) {
89 92
 							e.preventDefault();
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 
117 120
 							return false;
118 121
 						});';
122
+	}
119 123
 
120 124
 	echo '
121 125
 					</script>
122 126
 				</form>';
123 127
 
124 128
 	// It is a long story as to why we have this when we're clearly not going to use it.
125
-	if (!empty($context['from_ajax']))
126
-		echo '
129
+	if (!empty($context['from_ajax'])) {
130
+			echo '
127 131
 				<br>
128 132
 				<a href="javascript:self.close();"></a>';
133
+	}
129 134
 
130 135
 	echo '
131 136
 			</div><!-- .roundframe -->
@@ -148,11 +153,12 @@  discard block
 block discarded – undo
148 153
 			</div>
149 154
 			<div class="roundframe noup">';
150 155
 
151
-	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
152
-		echo '
156
+	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error'])) {
157
+			echo '
153 158
 				<div class="error">
154 159
 					', $txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' : 'backup_') . 'invalid'], '
155 160
 				</div>';
161
+	}
156 162
 
157 163
 	echo '
158 164
 				<form action="', $context['tfa_url'], '" method="post" id="frmTfa">
@@ -181,8 +187,8 @@  discard block
 block discarded – undo
181 187
 				<script>
182 188
 					form = $("#frmTfa");';
183 189
 
184
-	if (!empty($context['from_ajax']))
185
-		echo '
190
+	if (!empty($context['from_ajax'])) {
191
+			echo '
186 192
 					form.submit(function(e) {
187 193
 						// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
188 194
 						if (form.find("input[name=tfa_backup]:first").val().length > 0)
@@ -201,6 +207,7 @@  discard block
 block discarded – undo
201 207
 
202 208
 						return false;
203 209
 					});';
210
+	}
204 211
 
205 212
 	echo '
206 213
 					form.find("input[name=backup]").click(function(e) {
@@ -232,10 +239,11 @@  discard block
 block discarded – undo
232 239
 			<p class="information centertext">
233 240
 				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';
234 241
 
235
-	if ($context['can_register'])
236
-		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
237
-	else
238
-		echo $txt['login_below'];
242
+	if ($context['can_register']) {
243
+			echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
244
+	} else {
245
+			echo $txt['login_below'];
246
+	}
239 247
 
240 248
 	// And now the login information.
241 249
 	echo '
@@ -335,9 +343,10 @@  discard block
 block discarded – undo
335 343
 			</div>
336 344
 			<div class="roundframe centertext noup">';
337 345
 
338
-	if (!empty($context['incorrect_password']))
339
-		echo '
346
+	if (!empty($context['incorrect_password'])) {
347
+			echo '
340 348
 				<div class="error">', $txt['admin_incorrect_password'], '</div>';
349
+	}
341 350
 
342 351
 	echo '
343 352
 				<strong>', $txt['password'], ':</strong>
@@ -378,10 +387,11 @@  discard block
 block discarded – undo
378 387
 				<dl>';
379 388
 
380 389
 	// You didn't even have an ID?
381
-	if (empty($context['member_id']))
382
-		echo '
390
+	if (empty($context['member_id'])) {
391
+			echo '
383 392
 					<dt>', $txt['invalid_activation_username'], ':</dt>
384 393
 					<dd><input type="text" name="user" size="30"></dd>';
394
+	}
385 395
 
386 396
 	echo '
387 397
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
@@ -418,13 +428,14 @@  discard block
 block discarded – undo
418 428
 					<dd><input type="password" name="passwd" size="30"></dd>
419 429
 				</dl>';
420 430
 
421
-	if ($context['can_activate'])
422
-		echo '
431
+	if ($context['can_activate']) {
432
+			echo '
423 433
 				<p>', $txt['invalid_activation_known'], '</p>
424 434
 				<dl>
425 435
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
426 436
 					<dd><input type="text" name="code" size="30"></dd>
427 437
 				</dl>';
438
+	}
428 439
 
429 440
 	echo '
430 441
 				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button"></p>
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -430,8 +430,8 @@
 block discarded – undo
430 430
 	$real_name = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
431 431
 
432 432
 	// Searches.
433
-	$member_name_search = $member_name . ' ' . $comparison . ' ' . implode( ' OR ' . $member_name . ' ' . $comparison . ' ', $names_list);
434
-	$real_name_search = $real_name . ' ' . $comparison . ' ' . implode( ' OR ' . $real_name . ' ' . $comparison . ' ', $names_list);
433
+	$member_name_search = $member_name . ' ' . $comparison . ' ' . implode(' OR ' . $member_name . ' ' . $comparison . ' ', $names_list);
434
+	$real_name_search = $real_name . ' ' . $comparison . ' ' . implode(' OR ' . $real_name . ' ' . $comparison . ' ', $names_list);
435 435
 
436 436
 	// Search by username, display name, and email address.
437 437
 	$request = $smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Braces   +165 added lines, -119 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -47,8 +48,9 @@  discard block
 block discarded – undo
47 48
 	if (isset($_COOKIE[$cookiename]))
48 49
 	{
49 50
 		// First check for 2.1 json-format cookie
50
-		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1)
51
-			list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
51
+		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) {
52
+					list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
53
+		}
52 54
 
53 55
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
54 56
 		elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1)
@@ -58,15 +60,17 @@  discard block
 block discarded – undo
58 60
 			$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
59 61
 
60 62
 			// Maybe we need to temporarily pretend to be using local cookies
61
-			if ($cookie_state == 0 && $old_state == 1)
62
-				list($old_domain, $old_path) = url_parts(true, false);
63
-			else
64
-				list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
63
+			if ($cookie_state == 0 && $old_state == 1) {
64
+							list($old_domain, $old_path) = url_parts(true, false);
65
+			} else {
66
+							list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
67
+			}
65 68
 		}
66 69
 
67 70
 		// Out with the old, in with the new!
68
-		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1])
69
-			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
71
+		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) {
72
+					smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
73
+		}
70 74
 	}
71 75
 
72 76
 	// Get the data and path to set it on.
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
 	smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
83 87
 
84 88
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
85
-	if (empty($id) && !empty($modSettings['globalCookies']))
86
-		smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
89
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
90
+			smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
91
+	}
87 92
 
88 93
 	// Any alias URLs?  This is mainly for use with frames, etc.
89 94
 	if (!empty($modSettings['forum_alias_urls']))
@@ -99,8 +104,9 @@  discard block
 block discarded – undo
99 104
 
100 105
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
101 106
 
102
-			if ($cookie_url[0] == '')
103
-				$cookie_url[0] = strtok($alias, '/');
107
+			if ($cookie_url[0] == '') {
108
+							$cookie_url[0] = strtok($alias, '/');
109
+			}
104 110
 
105 111
 			$alias_data = $smcFunc['json_decode']($data, true);
106 112
 			$alias_data[3] = $cookie_url[0];
@@ -159,8 +165,9 @@  discard block
 block discarded – undo
159 165
 	smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
160 166
 
161 167
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
162
-	if (empty($id) && !empty($modSettings['globalCookies']))
163
-		smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
168
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
169
+			smf_setcookie($identifier, $data, $expiry_time, $cookie_url[1], '');
170
+	}
164 171
 
165 172
 	$_COOKIE[$identifier] = $data;
166 173
 }
@@ -182,23 +189,28 @@  discard block
 block discarded – undo
182 189
 	$parsed_url = parse_url($boardurl);
183 190
 
184 191
 	// Is local cookies off?
185
-	if (empty($parsed_url['path']) || !$local)
186
-		$parsed_url['path'] = '';
192
+	if (empty($parsed_url['path']) || !$local) {
193
+			$parsed_url['path'] = '';
194
+	}
187 195
 
188
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
189
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
196
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
197
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
198
+	}
190 199
 
191 200
 	// Globalize cookies across domains (filter out IP-addresses)?
192
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
193
-		$parsed_url['host'] = '.' . $parts[1];
201
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
202
+			$parsed_url['host'] = '.' . $parts[1];
203
+	}
194 204
 
195 205
 	// We shouldn't use a host at all if both options are off.
196
-	elseif (!$local && !$global)
197
-		$parsed_url['host'] = '';
206
+	elseif (!$local && !$global) {
207
+			$parsed_url['host'] = '';
208
+	}
198 209
 
199 210
 	// The host also shouldn't be set if there aren't any dots in it.
200
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
201
-		$parsed_url['host'] = '';
211
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
212
+			$parsed_url['host'] = '';
213
+	}
202 214
 
203 215
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
204 216
 }
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 	createToken('login');
218 230
 
219 231
 	// Never redirect to an attachment
220
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
221
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
232
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
233
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
234
+	}
222 235
 
223 236
 	$context['sub_template'] = 'kick_guest';
224 237
 	$context['page_title'] = $txt['login'];
@@ -273,10 +286,12 @@  discard block
 block discarded – undo
273 286
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
274 287
 		log_error($txt['security_wrong'], 'critical');
275 288
 
276
-		if (isset($_POST[$type . '_hash_pass']))
277
-			unset($_POST[$type . '_hash_pass']);
278
-		if (isset($_POST[$type . '_pass']))
279
-			unset($_POST[$type . '_pass']);
289
+		if (isset($_POST[$type . '_hash_pass'])) {
290
+					unset($_POST[$type . '_hash_pass']);
291
+		}
292
+		if (isset($_POST[$type . '_pass'])) {
293
+					unset($_POST[$type . '_pass']);
294
+		}
280 295
 
281 296
 		$context['incorrect_password'] = true;
282 297
 	}
@@ -289,15 +304,17 @@  discard block
 block discarded – undo
289 304
 
290 305
 	// Now go through $_POST.  Make sure the session hash is sent.
291 306
 	$_POST[$context['session_var']] = $context['session_id'];
292
-	foreach ($_POST as $k => $v)
293
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
307
+	foreach ($_POST as $k => $v) {
308
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
309
+	}
294 310
 
295 311
 	// Now we'll use the admin_login sub template of the Login template.
296 312
 	$context['sub_template'] = 'admin_login';
297 313
 
298 314
 	// And title the page something like "Login".
299
-	if (!isset($context['page_title']))
300
-		$context['page_title'] = $txt['login'];
315
+	if (!isset($context['page_title'])) {
316
+			$context['page_title'] = $txt['login'];
317
+	}
301 318
 
302 319
 	// The type of action.
303 320
 	$context['sessionCheckType'] = $type;
@@ -320,14 +337,15 @@  discard block
 block discarded – undo
320 337
 {
321 338
 	global $smcFunc;
322 339
 
323
-	if (!is_array($v))
324
-		return '
340
+	if (!is_array($v)) {
341
+			return '
325 342
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
326
-	else
343
+	} else
327 344
 	{
328 345
 		$ret = '';
329
-		foreach ($v as $k2 => $v2)
330
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
346
+		foreach ($v as $k2 => $v2) {
347
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
348
+		}
331 349
 
332 350
 		return $ret;
333 351
 	}
@@ -354,18 +372,20 @@  discard block
 block discarded – undo
354 372
 		foreach ($get as $k => $v)
355 373
 		{
356 374
 			// Only if it's not already in the $scripturl!
357
-			if (!isset($temp[$k]))
358
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
375
+			if (!isset($temp[$k])) {
376
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
377
+			}
359 378
 			// If it changed, put it out there, but with an ampersand.
360
-			elseif ($temp[$k] != $get[$k])
361
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
379
+			elseif ($temp[$k] != $get[$k]) {
380
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
381
+			}
362 382
 		}
363
-	}
364
-	else
383
+	} else
365 384
 	{
366 385
 		// Add up all the data from $_GET into get_data.
367
-		foreach ($get as $k => $v)
368
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
386
+		foreach ($get as $k => $v) {
387
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
388
+		}
369 389
 	}
370 390
 
371 391
 	$query_string = substr($query_string, 0, -1);
@@ -388,8 +408,9 @@  discard block
 block discarded – undo
388 408
 	global $scripturl, $user_info, $smcFunc;
389 409
 
390 410
 	// If it's not already an array, make it one.
391
-	if (!is_array($names))
392
-		$names = explode(',', $names);
411
+	if (!is_array($names)) {
412
+			$names = explode(',', $names);
413
+	}
393 414
 
394 415
 	$maybe_email = false;
395 416
 	$names_list = array();
@@ -401,10 +422,11 @@  discard block
 block discarded – undo
401 422
 		$maybe_email |= strpos($name, '@') !== false;
402 423
 
403 424
 		// Make it so standard wildcards will work. (* and ?)
404
-		if ($use_wildcards)
405
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
406
-		else
407
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
425
+		if ($use_wildcards) {
426
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
427
+		} else {
428
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
429
+		}
408 430
 
409 431
 		$names_list[] = '{string:lookup_name_' . $i . '}';
410 432
 		$where_params['lookup_name_' . $i] = $names[$i];
@@ -417,11 +439,12 @@  discard block
 block discarded – undo
417 439
 	$results = array();
418 440
 
419 441
 	// This ensures you can't search someones email address if you can't see it.
420
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
421
-		$email_condition = '
442
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
443
+			$email_condition = '
422 444
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
423
-	else
424
-		$email_condition = '';
445
+	} else {
446
+			$email_condition = '';
447
+	}
425 448
 
426 449
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
427 450
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -480,10 +503,11 @@  discard block
 block discarded – undo
480 503
 	$context['template_layers'] = array();
481 504
 	$context['sub_template'] = 'find_members';
482 505
 
483
-	if (isset($_REQUEST['search']))
484
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
485
-	else
486
-		$_REQUEST['start'] = 0;
506
+	if (isset($_REQUEST['search'])) {
507
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
508
+	} else {
509
+			$_REQUEST['start'] = 0;
510
+	}
487 511
 
488 512
 	// Allow the user to pass the input to be added to to the box.
489 513
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -524,10 +548,10 @@  discard block
 block discarded – undo
524 548
 		);
525 549
 
526 550
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
551
+	} else {
552
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
553
+	}
527 554
 	}
528
-	else
529
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
530
-}
531 555
 
532 556
 /**
533 557
  * Outputs each member name on its own line.
@@ -543,8 +567,9 @@  discard block
 block discarded – undo
543 567
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
544 568
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
545 569
 
546
-	if (function_exists('iconv'))
547
-		header('content-type: text/plain; charset=UTF-8');
570
+	if (function_exists('iconv')) {
571
+			header('content-type: text/plain; charset=UTF-8');
572
+	}
548 573
 
549 574
 	$request = $smcFunc['db_query']('', '
550 575
 		SELECT real_name
@@ -564,14 +589,16 @@  discard block
 block discarded – undo
564 589
 		if (function_exists('iconv'))
565 590
 		{
566 591
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
567
-			if ($utf8)
568
-				$row['real_name'] = $utf8;
592
+			if ($utf8) {
593
+							$row['real_name'] = $utf8;
594
+			}
569 595
 		}
570 596
 
571 597
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
572 598
 
573
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
574
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
599
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
600
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
601
+		}
575 602
 
576 603
 		echo $row['real_name'], "\n";
577 604
 	}
@@ -628,9 +655,9 @@  discard block
 block discarded – undo
628 655
 
629 656
 		// Update the database...
630 657
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
658
+	} else {
659
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
631 660
 	}
632
-	else
633
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
634 661
 
635 662
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
636 663
 
@@ -661,31 +688,37 @@  discard block
 block discarded – undo
661 688
 	$errors = array();
662 689
 
663 690
 	// Don't use too long a name.
664
-	if ($smcFunc['strlen']($username) > 25)
665
-		$errors[] = array('lang', 'error_long_name');
691
+	if ($smcFunc['strlen']($username) > 25) {
692
+			$errors[] = array('lang', 'error_long_name');
693
+	}
666 694
 
667 695
 	// No name?!  How can you register with no name?
668
-	if ($username == '')
669
-		$errors[] = array('lang', 'need_username');
696
+	if ($username == '') {
697
+			$errors[] = array('lang', 'need_username');
698
+	}
670 699
 
671 700
 	// Only these characters are permitted.
672
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
673
-		$errors[] = array('lang', 'error_invalid_characters_username');
701
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
702
+			$errors[] = array('lang', 'error_invalid_characters_username');
703
+	}
674 704
 
675
-	if (stristr($username, $txt['guest_title']) !== false)
676
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
705
+	if (stristr($username, $txt['guest_title']) !== false) {
706
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
707
+	}
677 708
 
678 709
 	if ($check_reserved_name)
679 710
 	{
680 711
 		require_once($sourcedir . '/Subs-Members.php');
681
-		if (isReservedName($username, $memID, false))
682
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
712
+		if (isReservedName($username, $memID, false)) {
713
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
714
+		}
683 715
 	}
684 716
 
685
-	if ($return_error)
686
-		return $errors;
687
-	elseif (empty($errors))
688
-		return null;
717
+	if ($return_error) {
718
+			return $errors;
719
+	} elseif (empty($errors)) {
720
+			return null;
721
+	}
689 722
 
690 723
 	loadLanguage('Errors');
691 724
 	$error = $errors[0];
@@ -711,22 +744,26 @@  discard block
 block discarded – undo
711 744
 	global $modSettings, $smcFunc;
712 745
 
713 746
 	// Perform basic requirements first.
714
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
715
-		return 'short';
747
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
748
+			return 'short';
749
+	}
716 750
 
717 751
 	// Is this enough?
718
-	if (empty($modSettings['password_strength']))
719
-		return null;
752
+	if (empty($modSettings['password_strength'])) {
753
+			return null;
754
+	}
720 755
 
721 756
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
722
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
723
-		return 'restricted_words';
724
-	elseif ($smcFunc['strpos']($password, $username) !== false)
725
-		return 'restricted_words';
757
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
758
+			return 'restricted_words';
759
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
760
+			return 'restricted_words';
761
+	}
726 762
 
727 763
 	// If just medium, we're done.
728
-	if ($modSettings['password_strength'] == 1)
729
-		return null;
764
+	if ($modSettings['password_strength'] == 1) {
765
+			return null;
766
+	}
730 767
 
731 768
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
732 769
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -758,14 +795,16 @@  discard block
 block discarded – undo
758 795
 			)
759 796
 		);
760 797
 		$groups = array();
761
-		while ($row = $smcFunc['db_fetch_assoc']($request))
762
-			$groups[] = $row['id_group'];
798
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+					$groups[] = $row['id_group'];
800
+		}
763 801
 		$smcFunc['db_free_result']($request);
764 802
 
765
-		if (empty($groups))
766
-			$group_query = '0=1';
767
-		else
768
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
803
+		if (empty($groups)) {
804
+					$group_query = '0=1';
805
+		} else {
806
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
807
+		}
769 808
 	}
770 809
 
771 810
 	// Then, same again, just the boards this time!
@@ -775,10 +814,11 @@  discard block
 block discarded – undo
775 814
 	{
776 815
 		$boards = boardsAllowedTo('moderate_board', true);
777 816
 
778
-		if (empty($boards))
779
-			$board_query = '0=1';
780
-		else
781
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
817
+		if (empty($boards)) {
818
+					$board_query = '0=1';
819
+		} else {
820
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
821
+		}
782 822
 	}
783 823
 
784 824
 	// What boards are they the moderator of?
@@ -793,8 +833,9 @@  discard block
 block discarded – undo
793 833
 				'current_member' => $user_info['id'],
794 834
 			)
795 835
 		);
796
-		while ($row = $smcFunc['db_fetch_assoc']($request))
797
-			$boards_mod[] = $row['id_board'];
836
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
837
+					$boards_mod[] = $row['id_board'];
838
+		}
798 839
 		$smcFunc['db_free_result']($request);
799 840
 
800 841
 		// Can any of the groups they're in moderate any of the boards?
@@ -806,8 +847,9 @@  discard block
 block discarded – undo
806 847
 				'groups' => $user_info['groups'],
807 848
 			)
808 849
 		);
809
-		while ($row = $smcFunc['db_fetch_assoc']($request))
810
-			$boards_mod[] = $row['id_board'];
850
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
851
+					$boards_mod[] = $row['id_board'];
852
+		}
811 853
 		$smcFunc['db_free_result']($request);
812 854
 
813 855
 		// Just in case we've got duplicates here...
@@ -852,10 +894,12 @@  discard block
 block discarded – undo
852 894
 	global $modSettings;
853 895
 
854 896
 	// In case a customization wants to override the default settings
855
-	if ($httponly === null)
856
-		$httponly = !empty($modSettings['httponlyCookies']);
857
-	if ($secure === null)
858
-		$secure = !empty($modSettings['secureCookies']);
897
+	if ($httponly === null) {
898
+			$httponly = !empty($modSettings['httponlyCookies']);
899
+	}
900
+	if ($secure === null) {
901
+			$secure = !empty($modSettings['secureCookies']);
902
+	}
859 903
 
860 904
 	// Intercept cookie?
861 905
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -875,8 +919,9 @@  discard block
 block discarded – undo
875 919
 function hash_password($username, $password, $cost = null)
876 920
 {
877 921
 	global $sourcedir, $smcFunc, $modSettings;
878
-	if (!function_exists('password_hash'))
879
-		require_once($sourcedir . '/Subs-Password.php');
922
+	if (!function_exists('password_hash')) {
923
+			require_once($sourcedir . '/Subs-Password.php');
924
+	}
880 925
 
881 926
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
882 927
 
@@ -908,8 +953,9 @@  discard block
 block discarded – undo
908 953
 function hash_verify_password($username, $password, $hash)
909 954
 {
910 955
 	global $sourcedir, $smcFunc;
911
-	if (!function_exists('password_verify'))
912
-		require_once($sourcedir . '/Subs-Password.php');
956
+	if (!function_exists('password_verify')) {
957
+			require_once($sourcedir . '/Subs-Password.php');
958
+	}
913 959
 
914 960
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
915 961
 }
Please login to merge, or discard this patch.