Completed
Pull Request — release-2.1 (#4156)
by 01
13:04 queued 03:20
created
Sources/Subs-List.php 1 patch
Braces   +85 added lines, -59 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  * @version 2.1 Beta 4
13 13
  */
14 14
 
15
-if (!defined('SMF'))
15
+if (!defined('SMF')) {
16 16
 	die('No direct access...');
17
+}
17 18
 
18 19
 /**
19 20
  * Create a new list
@@ -41,21 +42,21 @@  discard block
 block discarded – undo
41 42
 	{
42 43
 		$list_context['sort'] = array();
43 44
 		$sort = '1=1';
44
-	}
45
-	else
45
+	} else
46 46
 	{
47 47
 		$request_var_sort = isset($listOptions['request_vars']['sort']) ? $listOptions['request_vars']['sort'] : 'sort';
48 48
 		$request_var_desc = isset($listOptions['request_vars']['desc']) ? $listOptions['request_vars']['desc'] : 'desc';
49
-		if (isset($_REQUEST[$request_var_sort], $listOptions['columns'][$_REQUEST[$request_var_sort]], $listOptions['columns'][$_REQUEST[$request_var_sort]]['sort']))
50
-			$list_context['sort'] = array(
49
+		if (isset($_REQUEST[$request_var_sort], $listOptions['columns'][$_REQUEST[$request_var_sort]], $listOptions['columns'][$_REQUEST[$request_var_sort]]['sort'])) {
50
+					$list_context['sort'] = array(
51 51
 				'id' => $_REQUEST[$request_var_sort],
52 52
 				'desc' => isset($_REQUEST[$request_var_desc]) && isset($listOptions['columns'][$_REQUEST[$request_var_sort]]['sort']['reverse']),
53 53
 			);
54
-		else
55
-			$list_context['sort'] = array(
54
+		} else {
55
+					$list_context['sort'] = array(
56 56
 				'id' => $listOptions['default_sort_col'],
57 57
 				'desc' => (!empty($listOptions['default_sort_dir']) && $listOptions['default_sort_dir'] == 'desc') || (!empty($listOptions['columns'][$listOptions['default_sort_col']]['sort']['default']) && substr($listOptions['columns'][$listOptions['default_sort_col']]['sort']['default'], -4, 4) == 'desc') ? true : false,
58 58
 			);
59
+		}
59 60
 
60 61
 		// Set the database column sort.
61 62
 		$sort = $listOptions['columns'][$list_context['sort']['id']]['sort'][$list_context['sort']['desc'] ? 'reverse' : 'default'];
@@ -72,8 +73,9 @@  discard block
 block discarded – undo
72 73
 	else
73 74
 	{
74 75
 		// First get an impression of how many items to expect.
75
-		if (isset($listOptions['get_count']['file']))
76
-			require_once($listOptions['get_count']['file']);
76
+		if (isset($listOptions['get_count']['file'])) {
77
+					require_once($listOptions['get_count']['file']);
78
+		}
77 79
 
78 80
 		$call = call_helper($listOptions['get_count']['function'], true);
79 81
 		$list_context['total_num_items'] = call_user_func_array($call, empty($listOptions['get_count']['params']) ? array() : $listOptions['get_count']['params']);
@@ -83,14 +85,15 @@  discard block
 block discarded – undo
83 85
 		$list_context['items_per_page'] = $listOptions['items_per_page'];
84 86
 
85 87
 		// Then create a page index.
86
-		if ($list_context['total_num_items'] > $list_context['items_per_page'])
87
-			$list_context['page_index'] = constructPageIndex($listOptions['base_href'] . (empty($list_context['sort']) ? '' : ';' . $request_var_sort . '=' . $list_context['sort']['id'] . ($list_context['sort']['desc'] ? ';' . $request_var_desc : '')) . ($list_context['start_var_name'] != 'start' ? ';' . $list_context['start_var_name'] . '=%1$d' : ''), $list_context['start'], $list_context['total_num_items'], $list_context['items_per_page'], $list_context['start_var_name'] != 'start');
88
+		if ($list_context['total_num_items'] > $list_context['items_per_page']) {
89
+					$list_context['page_index'] = constructPageIndex($listOptions['base_href'] . (empty($list_context['sort']) ? '' : ';' . $request_var_sort . '=' . $list_context['sort']['id'] . ($list_context['sort']['desc'] ? ';' . $request_var_desc : '')) . ($list_context['start_var_name'] != 'start' ? ';' . $list_context['start_var_name'] . '=%1$d' : ''), $list_context['start'], $list_context['total_num_items'], $list_context['items_per_page'], $list_context['start_var_name'] != 'start');
90
+		}
88 91
 	}
89 92
 
90 93
 	// Prepare the headers of the table.
91 94
 	$list_context['headers'] = array();
92
-	foreach ($listOptions['columns'] as $column_id => $column)
93
-		$list_context['headers'][] = array(
95
+	foreach ($listOptions['columns'] as $column_id => $column) {
96
+			$list_context['headers'][] = array(
94 97
 			'id' => $column_id,
95 98
 			'label' => isset($column['header']['eval']) ? eval($column['header']['eval']) : (isset($column['header']['value']) ? $column['header']['value'] : ''),
96 99
 			'href' => empty($listOptions['default_sort_col']) || empty($column['sort']) ? '' : $listOptions['base_href'] . ';' . $request_var_sort . '=' . $column_id . ($column_id === $list_context['sort']['id'] && !$list_context['sort']['desc'] && isset($column['sort']['reverse']) ? ';' . $request_var_desc : '') . (empty($list_context['start']) ? '' : ';' . $list_context['start_var_name'] . '=' . $list_context['start']),
@@ -99,14 +102,16 @@  discard block
 block discarded – undo
99 102
 			'style' => isset($column['header']['style']) ? $column['header']['style'] : '',
100 103
 			'colspan' => isset($column['header']['colspan']) ? $column['header']['colspan'] : '',
101 104
 		);
105
+	}
102 106
 
103 107
 	// We know the amount of columns, might be useful for the template.
104 108
 	$list_context['num_columns'] = count($listOptions['columns']);
105 109
 	$list_context['width'] = isset($listOptions['width']) ? $listOptions['width'] : '0';
106 110
 
107 111
 	// Get the file with the function for the item list.
108
-	if (isset($listOptions['get_items']['file']))
109
-		require_once($listOptions['get_items']['file']);
112
+	if (isset($listOptions['get_items']['file'])) {
113
+			require_once($listOptions['get_items']['file']);
114
+	}
110 115
 
111 116
 	// Call the function and include which items we want and in what order.
112 117
 	$call = call_helper($listOptions['get_items']['function'], true);
@@ -123,51 +128,61 @@  discard block
 block discarded – undo
123 128
 			$cur_data = array();
124 129
 
125 130
 			// A value straight from the database?
126
-			if (isset($column['data']['db']))
127
-				$cur_data['value'] = $list_item[$column['data']['db']];
131
+			if (isset($column['data']['db'])) {
132
+							$cur_data['value'] = $list_item[$column['data']['db']];
133
+			}
128 134
 
129 135
 			// Take the value from the database and make it HTML safe.
130
-			elseif (isset($column['data']['db_htmlsafe']))
131
-				$cur_data['value'] = $smcFunc['htmlspecialchars']($list_item[$column['data']['db_htmlsafe']]);
136
+			elseif (isset($column['data']['db_htmlsafe'])) {
137
+							$cur_data['value'] = $smcFunc['htmlspecialchars']($list_item[$column['data']['db_htmlsafe']]);
138
+			}
132 139
 
133 140
 			// Using sprintf is probably the most readable way of injecting data.
134 141
 			elseif (isset($column['data']['sprintf']))
135 142
 			{
136 143
 				$params = array();
137
-				foreach ($column['data']['sprintf']['params'] as $sprintf_param => $htmlsafe)
138
-					$params[] = $htmlsafe ? $smcFunc['htmlspecialchars']($list_item[$sprintf_param]) : $list_item[$sprintf_param];
144
+				foreach ($column['data']['sprintf']['params'] as $sprintf_param => $htmlsafe) {
145
+									$params[] = $htmlsafe ? $smcFunc['htmlspecialchars']($list_item[$sprintf_param]) : $list_item[$sprintf_param];
146
+				}
139 147
 				$cur_data['value'] = vsprintf($column['data']['sprintf']['format'], $params);
140 148
 			}
141 149
 
142 150
 			// The most flexible way probably is applying a custom function.
143
-			elseif (isset($column['data']['function']))
144
-				$cur_data['value'] = call_user_func_array($column['data']['function'], array($list_item));
151
+			elseif (isset($column['data']['function'])) {
152
+							$cur_data['value'] = call_user_func_array($column['data']['function'], array($list_item));
153
+			}
145 154
 
146 155
 			// A modified value (inject the database values).
147
-			elseif (isset($column['data']['eval']))
148
-				$cur_data['value'] = eval(preg_replace('~%([a-zA-Z0-9\-_]+)%~', '$list_item[\'$1\']', $column['data']['eval']));
156
+			elseif (isset($column['data']['eval'])) {
157
+							$cur_data['value'] = eval(preg_replace('~%([a-zA-Z0-9\-_]+)%~', '$list_item[\'$1\']', $column['data']['eval']));
158
+			}
149 159
 
150 160
 			// A literal value.
151
-			elseif (isset($column['data']['value']))
152
-				$cur_data['value'] = $column['data']['value'];
161
+			elseif (isset($column['data']['value'])) {
162
+							$cur_data['value'] = $column['data']['value'];
163
+			}
153 164
 
154 165
 			// Empty value.
155
-			else
156
-				$cur_data['value'] = '';
166
+			else {
167
+							$cur_data['value'] = '';
168
+			}
157 169
 
158 170
 			// Allow for basic formatting.
159
-			if (!empty($column['data']['comma_format']))
160
-				$cur_data['value'] = comma_format($cur_data['value']);
161
-			elseif (!empty($column['data']['timeformat']))
162
-				$cur_data['value'] = timeformat($cur_data['value']);
171
+			if (!empty($column['data']['comma_format'])) {
172
+							$cur_data['value'] = comma_format($cur_data['value']);
173
+			} elseif (!empty($column['data']['timeformat'])) {
174
+							$cur_data['value'] = timeformat($cur_data['value']);
175
+			}
163 176
 
164 177
 			// Set a style class for this column?
165
-			if (isset($column['data']['class']))
166
-				$cur_data['class'] = $column['data']['class'];
178
+			if (isset($column['data']['class'])) {
179
+							$cur_data['class'] = $column['data']['class'];
180
+			}
167 181
 
168 182
 			// Fully customized styling for the cells in this column only.
169
-			if (isset($column['data']['style']))
170
-				$cur_data['style'] = $column['data']['style'];
183
+			if (isset($column['data']['style'])) {
184
+							$cur_data['style'] = $column['data']['style'];
185
+			}
171 186
 
172 187
 			// Add the data cell properties to the current row.
173 188
 			$cur_row[$column_id] = $cur_data;
@@ -176,10 +191,12 @@  discard block
 block discarded – undo
176 191
 		// Maybe we wat set a custom class for the row based on the data in the row itself
177 192
 		if (isset($listOptions['data_check']))
178 193
 		{
179
-			if (isset($listOptions['data_check']['class']))
180
-				$list_context['rows'][$item_id]['class'] = $listOptions['data_check']['class']($list_item);
181
-			if (isset($listOptions['data_check']['style']))
182
-				$list_context['rows'][$item_id]['style'] = $listOptions['data_check']['style']($list_item);
194
+			if (isset($listOptions['data_check']['class'])) {
195
+							$list_context['rows'][$item_id]['class'] = $listOptions['data_check']['class']($list_item);
196
+			}
197
+			if (isset($listOptions['data_check']['style'])) {
198
+							$list_context['rows'][$item_id]['style'] = $listOptions['data_check']['style']($list_item);
199
+			}
183 200
 		}
184 201
 
185 202
 		// Insert the row into the list.
@@ -187,34 +204,39 @@  discard block
 block discarded – undo
187 204
 	}
188 205
 
189 206
 	// The title is currently optional.
190
-	if (isset($listOptions['title']))
191
-		$list_context['title'] = $listOptions['title'];
207
+	if (isset($listOptions['title'])) {
208
+			$list_context['title'] = $listOptions['title'];
209
+	}
192 210
 
193 211
 	// In case there's a form, share it with the template context.
194 212
 	if (isset($listOptions['form']))
195 213
 	{
196 214
 		$list_context['form'] = $listOptions['form'];
197 215
 
198
-		if (!isset($list_context['form']['hidden_fields']))
199
-			$list_context['form']['hidden_fields'] = array();
216
+		if (!isset($list_context['form']['hidden_fields'])) {
217
+					$list_context['form']['hidden_fields'] = array();
218
+		}
200 219
 
201 220
 		// Always add a session check field.
202 221
 		$list_context['form']['hidden_fields'][$context['session_var']] = $context['session_id'];
203 222
 
204 223
 		// Will this do a token check?
205
-		if (isset($listOptions['form']['token']))
206
-			$list_context['form']['hidden_fields'][$context[$listOptions['form']['token'] . '_token_var']] = $context[$listOptions['form']['token'] . '_token'];
224
+		if (isset($listOptions['form']['token'])) {
225
+					$list_context['form']['hidden_fields'][$context[$listOptions['form']['token'] . '_token_var']] = $context[$listOptions['form']['token'] . '_token'];
226
+		}
207 227
 
208 228
 		// Include the starting page as hidden field?
209
-		if (!empty($list_context['form']['include_start']) && !empty($list_context['start']))
210
-			$list_context['form']['hidden_fields'][$list_context['start_var_name']] = $list_context['start'];
229
+		if (!empty($list_context['form']['include_start']) && !empty($list_context['start'])) {
230
+					$list_context['form']['hidden_fields'][$list_context['start_var_name']] = $list_context['start'];
231
+		}
211 232
 
212 233
 		// If sorting needs to be the same after submitting, add the parameter.
213 234
 		if (!empty($list_context['form']['include_sort']) && !empty($list_context['sort']))
214 235
 		{
215 236
 			$list_context['form']['hidden_fields']['sort'] = $list_context['sort']['id'];
216
-			if ($list_context['sort']['desc'])
217
-				$list_context['form']['hidden_fields']['desc'] = 1;
237
+			if ($list_context['sort']['desc']) {
238
+							$list_context['form']['hidden_fields']['desc'] = 1;
239
+			}
218 240
 		}
219 241
 	}
220 242
 
@@ -231,24 +253,28 @@  discard block
 block discarded – undo
231 253
 		$list_context['additional_rows'] = array();
232 254
 		foreach ($listOptions['additional_rows'] as $row)
233 255
 		{
234
-			if (empty($row))
235
-				continue;
256
+			if (empty($row)) {
257
+							continue;
258
+			}
236 259
 
237 260
 			// Supported row positions: top_of_list, after_title,
238 261
 			// above_column_headers, below_table_data, bottom_of_list.
239
-			if (!isset($list_context['additional_rows'][$row['position']]))
240
-				$list_context['additional_rows'][$row['position']] = array();
262
+			if (!isset($list_context['additional_rows'][$row['position']])) {
263
+							$list_context['additional_rows'][$row['position']] = array();
264
+			}
241 265
 			$list_context['additional_rows'][$row['position']][] = $row;
242 266
 		}
243 267
 	}
244 268
 
245 269
 	// Add an option for inline JavaScript.
246
-	if (isset($listOptions['javascript']))
247
-		$list_context['javascript'] = $listOptions['javascript'];
270
+	if (isset($listOptions['javascript'])) {
271
+			$list_context['javascript'] = $listOptions['javascript'];
272
+	}
248 273
 
249 274
 	// We want a menu.
250
-	if (isset($listOptions['list_menu']))
251
-		$list_context['list_menu'] = $listOptions['list_menu'];
275
+	if (isset($listOptions['list_menu'])) {
276
+			$list_context['list_menu'] = $listOptions['list_menu'];
277
+	}
252 278
 
253 279
 	// Make sure the template is loaded.
254 280
 	loadTemplate('GenericList');
Please login to merge, or discard this patch.
Sources/Register.php 1 patch
Braces   +168 added lines, -122 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Begin the registration process.
@@ -29,19 +30,23 @@  discard block
 block discarded – undo
29 30
 	global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile;
30 31
 
31 32
 	// Is this an incoming AJAX check?
32
-	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck')
33
-		return RegisterCheckUsername();
33
+	if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') {
34
+			return RegisterCheckUsername();
35
+	}
34 36
 
35 37
 	// Check if the administrator has it disabled.
36
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3')
37
-		fatal_lang_error('registration_disabled', false);
38
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') {
39
+			fatal_lang_error('registration_disabled', false);
40
+	}
38 41
 
39 42
 	// If this user is an admin - redirect them to the admin registration page.
40
-	if (allowedTo('moderate_forum') && !$user_info['is_guest'])
41
-		redirectexit('action=admin;area=regcenter;sa=register');
43
+	if (allowedTo('moderate_forum') && !$user_info['is_guest']) {
44
+			redirectexit('action=admin;area=regcenter;sa=register');
45
+	}
42 46
 	// You are not a guest, so you are a member - and members don't get to register twice!
43
-	elseif (empty($user_info['is_guest']))
44
-		redirectexit();
47
+	elseif (empty($user_info['is_guest'])) {
48
+			redirectexit();
49
+	}
45 50
 
46 51
 	loadLanguage('Login');
47 52
 	loadTemplate('Register');
@@ -82,16 +87,18 @@  discard block
 block discarded – undo
82 87
 		}
83 88
 	}
84 89
 	// Make sure they don't squeeze through without agreeing.
85
-	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement'])
86
-		$current_step = 1;
90
+	elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) {
91
+			$current_step = 1;
92
+	}
87 93
 
88 94
 	// Show the user the right form.
89 95
 	$context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form';
90 96
 	$context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form'];
91 97
 
92 98
 	// Kinda need this.
93
-	if ($context['sub_template'] == 'registration_form')
94
-		loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
99
+	if ($context['sub_template'] == 'registration_form') {
100
+			loadJavaScriptFile('register.js', array('defer' => false), 'smf_register');
101
+	}
95 102
 
96 103
 	// Add the register chain to the link tree.
97 104
 	$context['linktree'][] = array(
@@ -100,24 +107,26 @@  discard block
 block discarded – undo
100 107
 	);
101 108
 
102 109
 	// Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one.
103
-	if (!isset($_SESSION['register']))
104
-		$_SESSION['register'] = array(
110
+	if (!isset($_SESSION['register'])) {
111
+			$_SESSION['register'] = array(
105 112
 			'timenow' => time(),
106 113
 			'limit' => 10, // minimum number of seconds required on this page for registration
107 114
 		);
108
-	else
109
-		$_SESSION['register']['timenow'] = time();
115
+	} else {
116
+			$_SESSION['register']['timenow'] = time();
117
+	}
110 118
 
111 119
 	// If you have to agree to the agreement, it needs to be fetched from the file.
112 120
 	if ($context['require_agreement'])
113 121
 	{
114 122
 		// Have we got a localized one?
115
-		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
116
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
117
-		elseif (file_exists($boarddir . '/agreement.txt'))
118
-			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
119
-		else
120
-			$context['agreement'] = '';
123
+		if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
124
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
125
+		} elseif (file_exists($boarddir . '/agreement.txt')) {
126
+					$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
127
+		} else {
128
+					$context['agreement'] = '';
129
+		}
121 130
 
122 131
 		// Nothing to show, lets disable registration and inform the admin of this error
123 132
 		if (empty($context['agreement']))
@@ -133,8 +142,9 @@  discard block
 block discarded – undo
133 142
 		$selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language'];
134 143
 
135 144
 		// Do we have any languages?
136
-		if (empty($context['languages']))
137
-			getLanguages();
145
+		if (empty($context['languages'])) {
146
+					getLanguages();
147
+		}
138 148
 
139 149
 		// Try to find our selected language.
140 150
 		foreach ($context['languages'] as $key => $lang)
@@ -142,8 +152,9 @@  discard block
 block discarded – undo
142 152
 			$context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => ''));
143 153
 
144 154
 			// Found it!
145
-			if ($selectedLanguage == $lang['filename'])
146
-				$context['languages'][$key]['selected'] = true;
155
+			if ($selectedLanguage == $lang['filename']) {
156
+							$context['languages'][$key]['selected'] = true;
157
+			}
147 158
 		}
148 159
 	}
149 160
 
@@ -167,9 +178,10 @@  discard block
 block discarded – undo
167 178
 		$reg_fields = explode(',', $modSettings['registration_fields']);
168 179
 
169 180
 		// We might have had some submissions on this front - go check.
170
-		foreach ($reg_fields as $field)
171
-			if (isset($_POST[$field]))
181
+		foreach ($reg_fields as $field) {
182
+					if (isset($_POST[$field]))
172 183
 				$cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]);
184
+		}
173 185
 
174 186
 		// Load all the fields in question.
175 187
 		setupProfileContext($reg_fields);
@@ -186,8 +198,9 @@  discard block
 block discarded – undo
186 198
 		$context['visual_verification_id'] = $verificationOptions['id'];
187 199
 	}
188 200
 	// Otherwise we have nothing to show.
189
-	else
190
-		$context['visual_verification'] = false;
201
+	else {
202
+			$context['visual_verification'] = false;
203
+	}
191 204
 
192 205
 
193 206
 	$context += array(
@@ -198,8 +211,9 @@  discard block
 block discarded – undo
198 211
 
199 212
 	// Were there any errors?
200 213
 	$context['registration_errors'] = array();
201
-	if (!empty($reg_errors))
202
-		$context['registration_errors'] = $reg_errors;
214
+	if (!empty($reg_errors)) {
215
+			$context['registration_errors'] = $reg_errors;
216
+	}
203 217
 
204 218
 	createToken('register');
205 219
 }
@@ -216,27 +230,32 @@  discard block
 block discarded – undo
216 230
 	validateToken('register');
217 231
 
218 232
 	// Check to ensure we're forcing SSL for authentication
219
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
220
-		fatal_lang_error('register_ssl_required');
233
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
234
+			fatal_lang_error('register_ssl_required');
235
+	}
221 236
 
222 237
 	// Start collecting together any errors.
223 238
 	$reg_errors = array();
224 239
 
225 240
 	// You can't register if it's disabled.
226
-	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3)
227
-		fatal_lang_error('registration_disabled', false);
241
+	if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) {
242
+			fatal_lang_error('registration_disabled', false);
243
+	}
228 244
 
229 245
 	// Well, if you don't agree, you can't register.
230
-	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed']))
231
-		redirectexit();
246
+	if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) {
247
+			redirectexit();
248
+	}
232 249
 
233 250
 	// Make sure they came from *somewhere*, have a session.
234
-	if (!isset($_SESSION['old_url']))
235
-		redirectexit('action=signup');
251
+	if (!isset($_SESSION['old_url'])) {
252
+			redirectexit('action=signup');
253
+	}
236 254
 
237 255
 	// If we don't require an agreement, we need a extra check for coppa.
238
-	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge']))
239
-		$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
256
+	if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) {
257
+			$_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']);
258
+	}
240 259
 	// Are they under age, and under age users are banned?
241 260
 	if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa']))
242 261
 	{
@@ -245,8 +264,9 @@  discard block
 block discarded – undo
245 264
 	}
246 265
 
247 266
 	// Check the time gate for miscreants. First make sure they came from somewhere that actually set it up.
248
-	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit']))
249
-		redirectexit('action=signup');
267
+	if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) {
268
+			redirectexit('action=signup');
269
+	}
250 270
 	// Failing that, check the time on it.
251 271
 	if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit'])
252 272
 	{
@@ -266,15 +286,17 @@  discard block
 block discarded – undo
266 286
 		if (is_array($context['visual_verification']))
267 287
 		{
268 288
 			loadLanguage('Errors');
269
-			foreach ($context['visual_verification'] as $error)
270
-				$reg_errors[] = $txt['error_' . $error];
289
+			foreach ($context['visual_verification'] as $error) {
290
+							$reg_errors[] = $txt['error_' . $error];
291
+			}
271 292
 		}
272 293
 	}
273 294
 
274 295
 	foreach ($_POST as $key => $value)
275 296
 	{
276
-		if (!is_array($_POST[$key]))
277
-			$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
297
+		if (!is_array($_POST[$key])) {
298
+					$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
299
+		}
278 300
 	}
279 301
 
280 302
 	// Collect all extra registration fields someone might have filled in.
@@ -304,12 +326,14 @@  discard block
 block discarded – undo
304 326
 		$reg_fields = explode(',', $modSettings['registration_fields']);
305 327
 
306 328
 		// Website is a little different
307
-		if (in_array('website', $reg_fields))
308
-			$possible_strings += array('website_url', 'website_title');
329
+		if (in_array('website', $reg_fields)) {
330
+					$possible_strings += array('website_url', 'website_title');
331
+		}
309 332
 	}
310 333
 
311
-	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '')
312
-		$_POST['secret_answer'] = md5($_POST['secret_answer']);
334
+	if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') {
335
+			$_POST['secret_answer'] = md5($_POST['secret_answer']);
336
+	}
313 337
 
314 338
 	// Needed for isReservedName() and registerMember().
315 339
 	require_once($sourcedir . '/Subs-Members.php');
@@ -318,32 +342,37 @@  discard block
 block discarded – undo
318 342
 	if (isset($_POST['real_name']) && (allowedTo('profile_displayed_name') || allowedTo('moderate_forum')))
319 343
 	{
320 344
 		$_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name']));
321
-		if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60)
322
-			$possible_strings[] = 'real_name';
345
+		if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) {
346
+					$possible_strings[] = 'real_name';
347
+		}
323 348
 	}
324 349
 
325 350
 	// Handle a string as a birthdate...
326
-	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '')
327
-		$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
351
+	if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') {
352
+			$_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate']));
353
+	}
328 354
 	// Or birthdate parts...
329
-	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2']))
330
-		$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
355
+	elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) {
356
+			$_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']);
357
+	}
331 358
 
332 359
 	// Validate the passed language file.
333 360
 	if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage']))
334 361
 	{
335 362
 		// Do we have any languages?
336
-		if (empty($context['languages']))
337
-			getLanguages();
363
+		if (empty($context['languages'])) {
364
+					getLanguages();
365
+		}
338 366
 
339 367
 		// Did we find it?
340
-		if (isset($context['languages'][$_POST['lngfile']]))
341
-			$_SESSION['language'] = $_POST['lngfile'];
342
-		else
368
+		if (isset($context['languages'][$_POST['lngfile']])) {
369
+					$_SESSION['language'] = $_POST['lngfile'];
370
+		} else {
371
+					unset($_POST['lngfile']);
372
+		}
373
+	} else {
343 374
 			unset($_POST['lngfile']);
344 375
 	}
345
-	else
346
-		unset($_POST['lngfile']);
347 376
 
348 377
 	// Set the options needed for registration.
349 378
 	$regOptions = array(
@@ -363,22 +392,27 @@  discard block
 block discarded – undo
363 392
 	);
364 393
 
365 394
 	// Include the additional options that might have been filled in.
366
-	foreach ($possible_strings as $var)
367
-		if (isset($_POST[$var]))
395
+	foreach ($possible_strings as $var) {
396
+			if (isset($_POST[$var]))
368 397
 			$regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES);
369
-	foreach ($possible_ints as $var)
370
-		if (isset($_POST[$var]))
398
+	}
399
+	foreach ($possible_ints as $var) {
400
+			if (isset($_POST[$var]))
371 401
 			$regOptions['extra_register_vars'][$var] = (int) $_POST[$var];
372
-	foreach ($possible_floats as $var)
373
-		if (isset($_POST[$var]))
402
+	}
403
+	foreach ($possible_floats as $var) {
404
+			if (isset($_POST[$var]))
374 405
 			$regOptions['extra_register_vars'][$var] = (float) $_POST[$var];
375
-	foreach ($possible_bools as $var)
376
-		if (isset($_POST[$var]))
406
+	}
407
+	foreach ($possible_bools as $var) {
408
+			if (isset($_POST[$var]))
377 409
 			$regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1;
410
+	}
378 411
 
379 412
 	// Registration options are always default options...
380
-	if (isset($_POST['default_options']))
381
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
413
+	if (isset($_POST['default_options'])) {
414
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
415
+	}
382 416
 	$regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array();
383 417
 
384 418
 	// Make sure they are clean, dammit!
@@ -398,12 +432,14 @@  discard block
 block discarded – undo
398 432
 	while ($row = $smcFunc['db_fetch_assoc']($request))
399 433
 	{
400 434
 		// Don't allow overriding of the theme variables.
401
-		if (isset($regOptions['theme_vars'][$row['col_name']]))
402
-			unset($regOptions['theme_vars'][$row['col_name']]);
435
+		if (isset($regOptions['theme_vars'][$row['col_name']])) {
436
+					unset($regOptions['theme_vars'][$row['col_name']]);
437
+		}
403 438
 
404 439
 		// Not actually showing it then?
405
-		if (!$row['show_reg'])
406
-			continue;
440
+		if (!$row['show_reg']) {
441
+					continue;
442
+		}
407 443
 
408 444
 		// Prepare the value!
409 445
 		$value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : '';
@@ -412,24 +448,27 @@  discard block
 block discarded – undo
412 448
 		if (!in_array($row['field_type'], array('check', 'select', 'radio')))
413 449
 		{
414 450
 			// Is it too long?
415
-			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value))
416
-				$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
451
+			if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) {
452
+							$custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length']));
453
+			}
417 454
 
418 455
 			// Any masks to apply?
419 456
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
420 457
 			{
421
-				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
422
-					$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
423
-				elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value))
424
-					$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
425
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
426
-					$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
458
+				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) {
459
+									$custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name']));
460
+				} elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) {
461
+									$custom_field_errors[] = array('custom_field_not_number', array($row['field_name']));
462
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) {
463
+									$custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name']));
464
+				}
427 465
 			}
428 466
 		}
429 467
 
430 468
 		// Is this required but not there?
431
-		if (trim($value) == '' && $row['show_reg'] > 1)
432
-			$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
469
+		if (trim($value) == '' && $row['show_reg'] > 1) {
470
+					$custom_field_errors[] = array('custom_field_empty', array($row['field_name']));
471
+		}
433 472
 	}
434 473
 	$smcFunc['db_free_result']($request);
435 474
 
@@ -437,8 +476,9 @@  discard block
 block discarded – undo
437 476
 	if (!empty($custom_field_errors))
438 477
 	{
439 478
 		loadLanguage('Errors');
440
-		foreach ($custom_field_errors as $error)
441
-			$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
479
+		foreach ($custom_field_errors as $error) {
480
+					$reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]);
481
+		}
442 482
 	}
443 483
 
444 484
 	// Lets check for other errors before trying to register the member.
@@ -483,8 +523,9 @@  discard block
 block discarded – undo
483 523
 	}
484 524
 
485 525
 	// If COPPA has been selected then things get complicated, setup the template.
486
-	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']))
487
-		redirectexit('action=coppa;member=' . $memberID);
526
+	if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) {
527
+			redirectexit('action=coppa;member=' . $memberID);
528
+	}
488 529
 	// Basic template variable setup.
489 530
 	elseif (!empty($modSettings['registration_method']))
490 531
 	{
@@ -496,8 +537,7 @@  discard block
 block discarded – undo
496 537
 			'sub_template' => 'after',
497 538
 			'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration']
498 539
 		);
499
-	}
500
-	else
540
+	} else
501 541
 	{
502 542
 		call_integration_hook('integrate_activate', array($regOptions['username']));
503 543
 
@@ -517,16 +557,18 @@  discard block
 block discarded – undo
517 557
 	global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info;
518 558
 
519 559
 	// Logged in users should not bother to activate their accounts
520
-	if (!empty($user_info['id']))
521
-		redirectexit();
560
+	if (!empty($user_info['id'])) {
561
+			redirectexit();
562
+	}
522 563
 
523 564
 	loadLanguage('Login');
524 565
 	loadTemplate('Login');
525 566
 
526 567
 	if (empty($_REQUEST['u']) && empty($_POST['user']))
527 568
 	{
528
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3')
529
-			fatal_lang_error('no_access', false);
569
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') {
570
+					fatal_lang_error('no_access', false);
571
+		}
530 572
 
531 573
 		$context['member_id'] = 0;
532 574
 		$context['sub_template'] = 'resend';
@@ -566,11 +608,13 @@  discard block
 block discarded – undo
566 608
 	// Change their email address? (they probably tried a fake one first :P.)
567 609
 	if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2))
568 610
 	{
569
-		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3)
570
-			fatal_lang_error('no_access', false);
611
+		if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) {
612
+					fatal_lang_error('no_access', false);
613
+		}
571 614
 
572
-		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
573
-			fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
615
+		if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
616
+					fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false);
617
+		}
574 618
 
575 619
 		// Make sure their email isn't banned.
576 620
 		isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']);
@@ -586,8 +630,9 @@  discard block
 block discarded – undo
586 630
 			)
587 631
 		);
588 632
 
589
-		if ($smcFunc['db_num_rows']($request) != 0)
590
-			fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
633
+		if ($smcFunc['db_num_rows']($request) != 0) {
634
+					fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email'])));
635
+		}
591 636
 		$smcFunc['db_free_result']($request);
592 637
 
593 638
 		updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
@@ -625,9 +670,9 @@  discard block
 block discarded – undo
625 670
 	// Quit if this code is not right.
626 671
 	if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
627 672
 	{
628
-		if (!empty($row['is_activated']))
629
-			fatal_lang_error('already_activated', false);
630
-		elseif ($row['validation_code'] == '')
673
+		if (!empty($row['is_activated'])) {
674
+					fatal_lang_error('already_activated', false);
675
+		} elseif ($row['validation_code'] == '')
631 676
 		{
632 677
 			loadLanguage('Profile');
633 678
 			fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false);
@@ -677,8 +722,9 @@  discard block
 block discarded – undo
677 722
 	loadTemplate('Register');
678 723
 
679 724
 	// No User ID??
680
-	if (!isset($_GET['member']))
681
-		fatal_lang_error('no_access', false);
725
+	if (!isset($_GET['member'])) {
726
+			fatal_lang_error('no_access', false);
727
+	}
682 728
 
683 729
 	// Get the user details...
684 730
 	$request = $smcFunc['db_query']('', '
@@ -691,8 +737,9 @@  discard block
 block discarded – undo
691 737
 			'is_coppa' => 5,
692 738
 		)
693 739
 	);
694
-	if ($smcFunc['db_num_rows']($request) == 0)
695
-		fatal_lang_error('no_access', false);
740
+	if ($smcFunc['db_num_rows']($request) == 0) {
741
+			fatal_lang_error('no_access', false);
742
+	}
696 743
 	list ($username) = $smcFunc['db_fetch_row']($request);
697 744
 	$smcFunc['db_free_result']($request);
698 745
 
@@ -730,8 +777,7 @@  discard block
 block discarded – undo
730 777
 			echo $data;
731 778
 			obExit(false);
732 779
 		}
733
-	}
734
-	else
780
+	} else
735 781
 	{
736 782
 		$context += array(
737 783
 			'page_title' => $txt['coppa_title'],
@@ -784,8 +830,9 @@  discard block
 block discarded – undo
784 830
 	{
785 831
 		require_once($sourcedir . '/Subs-Graphics.php');
786 832
 
787
-		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code))
788
-			header('HTTP/1.1 400 Bad Request');
833
+		if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) {
834
+					header('HTTP/1.1 400 Bad Request');
835
+		}
789 836
 
790 837
 		// Otherwise just show a pre-defined letter.
791 838
 		elseif (isset($_REQUEST['letter']))
@@ -803,14 +850,13 @@  discard block
 block discarded – undo
803 850
 			header('Content-Type: image/gif');
804 851
 			die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B");
805 852
 		}
806
-	}
807
-
808
-	elseif ($_REQUEST['format'] === '.wav')
853
+	} elseif ($_REQUEST['format'] === '.wav')
809 854
 	{
810 855
 		require_once($sourcedir . '/Subs-Sound.php');
811 856
 
812
-		if (!createWaveFile($code))
813
-			header('HTTP/1.1 400 Bad Request');
857
+		if (!createWaveFile($code)) {
858
+					header('HTTP/1.1 400 Bad Request');
859
+		}
814 860
 	}
815 861
 
816 862
 	// We all die one day...
Please login to merge, or discard this patch.
Sources/Subs-Categories.php 1 patch
Braces   +44 added lines, -29 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
  * Edit the position and properties of a category.
@@ -42,8 +43,9 @@  discard block
 block discarded – undo
42 43
 		$cat_order = array();
43 44
 
44 45
 		// Setting 'move_after' to '0' moves the category to the top.
45
-		if ($catOptions['move_after'] == 0)
46
-			$cats[] = $category_id;
46
+		if ($catOptions['move_after'] == 0) {
47
+					$cats[] = $category_id;
48
+		}
47 49
 
48 50
 		// Grab the categories sorted by cat_order.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -55,17 +57,19 @@  discard block
 block discarded – undo
55 57
 		);
56 58
 		while ($row = $smcFunc['db_fetch_assoc']($request))
57 59
 		{
58
-			if ($row['id_cat'] != $category_id)
59
-				$cats[] = $row['id_cat'];
60
-			if ($row['id_cat'] == $catOptions['move_after'])
61
-				$cats[] = $category_id;
60
+			if ($row['id_cat'] != $category_id) {
61
+							$cats[] = $row['id_cat'];
62
+			}
63
+			if ($row['id_cat'] == $catOptions['move_after']) {
64
+							$cats[] = $category_id;
65
+			}
62 66
 			$cat_order[$row['id_cat']] = $row['cat_order'];
63 67
 		}
64 68
 		$smcFunc['db_free_result']($request);
65 69
 
66 70
 		// Set the new order for the categories.
67
-		foreach ($cats as $index => $cat)
68
-			if ($index != $cat_order[$cat])
71
+		foreach ($cats as $index => $cat) {
72
+					if ($index != $cat_order[$cat])
69 73
 				$smcFunc['db_query']('', '
70 74
 					UPDATE {db_prefix}categories
71 75
 					SET cat_order = {int:new_order}
@@ -75,6 +79,7 @@  discard block
 block discarded – undo
75 79
 						'current_category' => $cat,
76 80
 					)
77 81
 				);
82
+		}
78 83
 
79 84
 		// If the category order changed, so did the board order.
80 85
 		require_once($sourcedir . '/Subs-Boards.php');
@@ -117,8 +122,9 @@  discard block
 block discarded – undo
117 122
 			))
118 123
 		);
119 124
 
120
-		if (empty($catOptions['dont_log']))
121
-			logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
125
+		if (empty($catOptions['dont_log'])) {
126
+					logAction('edit_cat', array('catname' => isset($catOptions['cat_name']) ? $catOptions['cat_name'] : $category_id), 'admin');
127
+		}
122 128
 	}
123 129
 }
124 130
 
@@ -135,16 +141,20 @@  discard block
 block discarded – undo
135 141
 	global $smcFunc;
136 142
 
137 143
 	// Check required values.
138
-	if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '')
139
-		trigger_error('createCategory(): A category name is required', E_USER_ERROR);
144
+	if (!isset($catOptions['cat_name']) || trim($catOptions['cat_name']) == '') {
145
+			trigger_error('createCategory(): A category name is required', E_USER_ERROR);
146
+	}
140 147
 
141 148
 	// Set default values.
142
-	if (!isset($catOptions['cat_desc']))
143
-		$catOptions['cat_desc'] = '';
144
-	if (!isset($catOptions['move_after']))
145
-		$catOptions['move_after'] = 0;
146
-	if (!isset($catOptions['is_collapsible']))
147
-		$catOptions['is_collapsible'] = true;
149
+	if (!isset($catOptions['cat_desc'])) {
150
+			$catOptions['cat_desc'] = '';
151
+	}
152
+	if (!isset($catOptions['move_after'])) {
153
+			$catOptions['move_after'] = 0;
154
+	}
155
+	if (!isset($catOptions['is_collapsible'])) {
156
+			$catOptions['is_collapsible'] = true;
157
+	}
148 158
 	// Don't log an edit right after.
149 159
 	$catOptions['dont_log'] = true;
150 160
 
@@ -210,21 +220,24 @@  discard block
 block discarded – undo
210 220
 			)
211 221
 		);
212 222
 		$boards_inside = array();
213
-		while ($row = $smcFunc['db_fetch_assoc']($request))
214
-			$boards_inside[] = $row['id_board'];
223
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
224
+					$boards_inside[] = $row['id_board'];
225
+		}
215 226
 		$smcFunc['db_free_result']($request);
216 227
 
217
-		if (!empty($boards_inside))
218
-			deleteBoards($boards_inside, null);
228
+		if (!empty($boards_inside)) {
229
+					deleteBoards($boards_inside, null);
230
+		}
219 231
 	}
220 232
 
221 233
 	// Make sure the safe category is really safe.
222
-	elseif (in_array($moveBoardsTo, $categories))
223
-		trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
234
+	elseif (in_array($moveBoardsTo, $categories)) {
235
+			trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
236
+	}
224 237
 
225 238
 	// Move the boards inside the categories to a safe category.
226
-	else
227
-		$smcFunc['db_query']('', '
239
+	else {
240
+			$smcFunc['db_query']('', '
228 241
 			UPDATE {db_prefix}boards
229 242
 			SET id_cat = {int:new_parent_cat}
230 243
 			WHERE id_cat IN ({array_int:category_list})',
@@ -233,6 +246,7 @@  discard block
 block discarded – undo
233 246
 				'new_parent_cat' => $moveBoardsTo,
234 247
 			)
235 248
 		);
249
+	}
236 250
 
237 251
 	// Do the deletion of the category itself
238 252
 	$smcFunc['db_query']('', '
@@ -244,8 +258,9 @@  discard block
 block discarded – undo
244 258
 	);
245 259
 
246 260
 	// Log what we've done.
247
-	foreach ($categories as $category)
248
-		logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
261
+	foreach ($categories as $category) {
262
+			logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
263
+	}
249 264
 
250 265
 	// Get all boards back into the right order.
251 266
 	reorderBoards();
Please login to merge, or discard this patch.
Sources/MessageIndex.php 1 patch
Braces   +264 added lines, -197 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'], $maxindex, true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $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'], $maxindex, true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $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);
@@ -257,8 +270,9 @@  discard block
 block discarded – undo
257 270
 	$context['sort_direction'] = $ascending ? 'up' : 'down';
258 271
 	$txt['starter'] = $txt['started_by'];
259 272
 
260
-	foreach ($sort_methods as $key => $val)
261
-		$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>';
273
+	foreach ($sort_methods as $key => $val) {
274
+			$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>';
275
+	}
262 276
 
263 277
 	// Calculate the fastest way to get the topics.
264 278
 	$start = (int) $_REQUEST['start'];
@@ -268,14 +282,15 @@  discard block
 block discarded – undo
268 282
 		$fake_ascending = true;
269 283
 		$maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex;
270 284
 		$start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex;
285
+	} else {
286
+			$fake_ascending = false;
271 287
 	}
272
-	else
273
-		$fake_ascending = false;
274 288
 
275 289
 	// Setup the default topic icons...
276 290
 	$context['icon_sources'] = array();
277
-	foreach ($context['stable_icons'] as $icon)
278
-		$context['icon_sources'][$icon] = 'images_url';
291
+	foreach ($context['stable_icons'] as $icon) {
292
+			$context['icon_sources'][$icon] = 'images_url';
293
+	}
279 294
 
280 295
 	$topic_ids = array();
281 296
 	$context['topics'] = array();
@@ -306,8 +321,9 @@  discard block
 block discarded – undo
306 321
 			)
307 322
 		);
308 323
 		$topic_ids = array();
309
-		while ($row = $smcFunc['db_fetch_assoc']($request))
310
-			$topic_ids[] = $row['id_topic'];
324
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
325
+					$topic_ids[] = $row['id_topic'];
326
+		}
311 327
 	}
312 328
 
313 329
 	// Grab the appropriate topic information...
@@ -363,11 +379,13 @@  discard block
 block discarded – undo
363 379
 		// Begin 'printing' the message index for current board.
364 380
 		while ($row = $smcFunc['db_fetch_assoc']($result))
365 381
 		{
366
-			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
367
-				continue;
382
+			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
383
+							continue;
384
+			}
368 385
 
369
-			if (!$pre_query)
370
-				$topic_ids[] = $row['id_topic'];
386
+			if (!$pre_query) {
387
+							$topic_ids[] = $row['id_topic'];
388
+			}
371 389
 
372 390
 			// Reference the main color class.
373 391
 			$colorClass = 'windowbg';
@@ -377,8 +395,9 @@  discard block
 block discarded – undo
377 395
 			{
378 396
 				// Limit them to $modSettings['preview_characters'] characters
379 397
 				$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
380
-				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
381
-					$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
398
+				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
399
+									$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
400
+				}
382 401
 
383 402
 				// Censor the subject and message preview.
384 403
 				censorText($row['first_subject']);
@@ -389,27 +408,27 @@  discard block
 block discarded – undo
389 408
 				{
390 409
 					$row['last_subject'] = $row['first_subject'];
391 410
 					$row['last_body'] = $row['first_body'];
392
-				}
393
-				else
411
+				} else
394 412
 				{
395 413
 					$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
396
-					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
397
-						$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
414
+					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
415
+											$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
416
+					}
398 417
 
399 418
 					censorText($row['last_subject']);
400 419
 					censorText($row['last_body']);
401 420
 				}
402
-			}
403
-			else
421
+			} else
404 422
 			{
405 423
 				$row['first_body'] = '';
406 424
 				$row['last_body'] = '';
407 425
 				censorText($row['first_subject']);
408 426
 
409
-				if ($row['id_first_msg'] == $row['id_last_msg'])
410
-					$row['last_subject'] = $row['first_subject'];
411
-				else
412
-					censorText($row['last_subject']);
427
+				if ($row['id_first_msg'] == $row['id_last_msg']) {
428
+									$row['last_subject'] = $row['first_subject'];
429
+				} else {
430
+									censorText($row['last_subject']);
431
+				}
413 432
 			}
414 433
 
415 434
 			// Decide how many pages the topic should have.
@@ -420,42 +439,50 @@  discard block
 block discarded – undo
420 439
 				$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
421 440
 
422 441
 				// If we can use all, show all.
423
-				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
424
-					$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
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>';
444
+				}
445
+			} else {
446
+							$pages = '';
425 447
 			}
426
-			else
427
-				$pages = '';
428 448
 
429 449
 			// We need to check the topic icons exist...
430 450
 			if (!empty($modSettings['messageIconChecks_enable']))
431 451
 			{
432
-				if (!isset($context['icon_sources'][$row['first_icon']]))
433
-					$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
434
-				if (!isset($context['icon_sources'][$row['last_icon']]))
435
-					$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
436
-			}
437
-			else
452
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
453
+									$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
454
+				}
455
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
456
+									$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
457
+				}
458
+			} else
438 459
 			{
439
-				if (!isset($context['icon_sources'][$row['first_icon']]))
440
-					$context['icon_sources'][$row['first_icon']] = 'images_url';
441
-				if (!isset($context['icon_sources'][$row['last_icon']]))
442
-					$context['icon_sources'][$row['last_icon']] = 'images_url';
460
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
461
+									$context['icon_sources'][$row['first_icon']] = 'images_url';
462
+				}
463
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
464
+									$context['icon_sources'][$row['last_icon']] = 'images_url';
465
+				}
443 466
 			}
444 467
 
445
-			if (!empty($board_info['recycle']))
446
-				$row['first_icon'] = 'recycled';
468
+			if (!empty($board_info['recycle'])) {
469
+							$row['first_icon'] = 'recycled';
470
+			}
447 471
 
448 472
 			// Is this topic pending approval, or does it have any posts pending approval?
449
-			if ($context['can_approve_posts'] && $row['unapproved_posts'])
450
-				$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
473
+			if ($context['can_approve_posts'] && $row['unapproved_posts']) {
474
+							$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
475
+			}
451 476
 
452 477
 			// Sticky topics should get a different color, too.
453
-			if ($row['is_sticky'])
454
-				$colorClass .= ' sticky';
478
+			if ($row['is_sticky']) {
479
+							$colorClass .= ' sticky';
480
+			}
455 481
 
456 482
 			// Locked topics get special treatment as well.
457
-			if ($row['locked'])
458
-				$colorClass .= ' locked';
483
+			if ($row['locked']) {
484
+							$colorClass .= ' locked';
485
+			}
459 486
 
460 487
 			// 'Print' the topic info.
461 488
 			$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -536,8 +563,9 @@  discard block
 block discarded – undo
536 563
 		$smcFunc['db_free_result']($result);
537 564
 
538 565
 		// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
539
-		if ($fake_ascending)
540
-			$context['topics'] = array_reverse($context['topics'], true);
566
+		if ($fake_ascending) {
567
+					$context['topics'] = array_reverse($context['topics'], true);
568
+		}
541 569
 
542 570
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids))
543 571
 		{
@@ -554,8 +582,9 @@  discard block
 block discarded – undo
554 582
 					'limit' => count($topic_ids),
555 583
 				)
556 584
 			);
557
-			while ($row = $smcFunc['db_fetch_assoc']($result))
558
-				$context['topics'][$row['id_topic']]['is_posted_in'] = true;
585
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
586
+							$context['topics'][$row['id_topic']]['is_posted_in'] = true;
587
+			}
559 588
 			$smcFunc['db_free_result']($result);
560 589
 		}
561 590
 	}
@@ -580,9 +609,9 @@  discard block
 block discarded – undo
580 609
 		// Can we restore topics?
581 610
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
582 611
 
583
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
584
-			$context['can_move_any'] = true;
585
-		else
612
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
613
+					$context['can_move_any'] = true;
614
+		} else
586 615
 		{
587 616
 			// We'll use this in a minute
588 617
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -609,11 +638,13 @@  discard block
 block discarded – undo
609 638
 		}
610 639
 
611 640
 		// Can we use quick moderation checkboxes?
612
-		if ($options['display_quick_mod'] == 1)
613
-			$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'];
641
+		if ($options['display_quick_mod'] == 1) {
642
+					$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'];
643
+		}
614 644
 		// Or the icons?
615
-		else
616
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
645
+		else {
646
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
647
+		}
617 648
 	}
618 649
 
619 650
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -647,13 +678,15 @@  discard block
 block discarded – undo
647 678
 			);
648 679
 
649 680
 			// We've seen all these boards now!
650
-			foreach ($board_info['parent_boards'] as $k => $dummy)
651
-				if (isset($_SESSION['topicseen_cache'][$k]))
681
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
682
+							if (isset($_SESSION['topicseen_cache'][$k]))
652 683
 					unset($_SESSION['topicseen_cache'][$k]);
684
+			}
653 685
 		}
654 686
 
655
-		if (isset($_SESSION['topicseen_cache'][$board]))
656
-			unset($_SESSION['topicseen_cache'][$board]);
687
+		if (isset($_SESSION['topicseen_cache'][$board])) {
688
+					unset($_SESSION['topicseen_cache'][$board]);
689
+		}
657 690
 
658 691
 		$request = $smcFunc['db_query']('', '
659 692
 			SELECT id_topic, id_board, sent
@@ -674,8 +707,9 @@  discard block
 block discarded – undo
674 707
 				$context['is_marked_notify'] = true;
675 708
 				$board_sent = $row['sent'];
676 709
 			}
677
-			if (!empty($row['id_topic']))
678
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
710
+			if (!empty($row['id_topic'])) {
711
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
712
+			}
679 713
 		}
680 714
 		$smcFunc['db_free_result']($request);
681 715
 
@@ -699,8 +733,7 @@  discard block
 block discarded – undo
699 733
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
700 734
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
701 735
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
702
-	}
703
-	else
736
+	} else
704 737
 	{
705 738
 		$context['is_marked_notify'] = false;
706 739
 		$context['board_notification_mode'] = 1;
@@ -713,23 +746,27 @@  discard block
 block discarded – undo
713 746
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
714 747
 
715 748
 	// Don't want to show this forever...
716
-	if ($context['becomesUnapproved'])
717
-		unset($_SESSION['becomesUnapproved']);
749
+	if ($context['becomesUnapproved']) {
750
+			unset($_SESSION['becomesUnapproved']);
751
+	}
718 752
 
719 753
 	// Build the message index button array.
720 754
 	$context['normal_buttons'] = array();
721 755
 
722
-	if ($context['can_post_new'])
723
-		$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);
756
+	if ($context['can_post_new']) {
757
+			$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);
758
+	}
724 759
 
725
-	if ($context['can_post_poll'])
726
-		$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');
760
+	if ($context['can_post_poll']) {
761
+			$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');
762
+	}
727 763
 
728
-	if (!$context['user']['is_logged'])
729
-		$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']);
764
+	if (!$context['user']['is_logged']) {
765
+			$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']);
766
+	}
730 767
 
731
-	if ($context['can_mark_notify'])
732
-		$context['normal_buttons']['notify'] = array(
768
+	if ($context['can_mark_notify']) {
769
+			$context['normal_buttons']['notify'] = array(
733 770
 			'lang' => true,
734 771
 			'text' => 'notify_board_' . $context['board_notification_mode'],
735 772
 			'sub_buttons' => array(
@@ -747,6 +784,7 @@  discard block
 block discarded – undo
747 784
 				),
748 785
 			),
749 786
 		);
787
+	}
750 788
 
751 789
 	// Javascript for inline editing.
752 790
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -768,18 +806,21 @@  discard block
 block discarded – undo
768 806
 	checkSession('request');
769 807
 
770 808
 	// Lets go straight to the restore area.
771
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
772
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
809
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
810
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
811
+	}
773 812
 
774
-	if (isset($_SESSION['topicseen_cache']))
775
-		$_SESSION['topicseen_cache'] = array();
813
+	if (isset($_SESSION['topicseen_cache'])) {
814
+			$_SESSION['topicseen_cache'] = array();
815
+	}
776 816
 
777 817
 	// This is going to be needed to send off the notifications and for updateLastMessages().
778 818
 	require_once($sourcedir . '/Subs-Post.php');
779 819
 
780 820
 	// Remember the last board they moved things to.
781
-	if (isset($_REQUEST['move_to']))
782
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
821
+	if (isset($_REQUEST['move_to'])) {
822
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
823
+	}
783 824
 
784 825
 	// Only a few possible actions.
785 826
 	$possibleActions = array();
@@ -799,8 +840,7 @@  discard block
 block discarded – undo
799 840
 		);
800 841
 
801 842
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
802
-	}
803
-	else
843
+	} else
804 844
 	{
805 845
 		/**
806 846
 		 * @todo Ugly. There's no getting around this, is there?
@@ -818,8 +858,7 @@  discard block
 block discarded – undo
818 858
 		if (!empty($board))
819 859
 		{
820 860
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
821
-		}
822
-		else
861
+		} else
823 862
 		{
824 863
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
825 864
 		}
@@ -830,55 +869,67 @@  discard block
 block discarded – undo
830 869
 		}
831 870
 	}
832 871
 
833
-	if (!$user_info['is_guest'])
834
-		$possibleActions[] = 'markread';
835
-	if (!empty($boards_can['make_sticky']))
836
-		$possibleActions[] = 'sticky';
837
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
838
-		$possibleActions[] = 'move';
839
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
840
-		$possibleActions[] = 'remove';
841
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
842
-		$possibleActions[] = 'lock';
843
-	if (!empty($boards_can['merge_any']))
844
-		$possibleActions[] = 'merge';
845
-	if (!empty($boards_can['approve_posts']))
846
-		$possibleActions[] = 'approve';
872
+	if (!$user_info['is_guest']) {
873
+			$possibleActions[] = 'markread';
874
+	}
875
+	if (!empty($boards_can['make_sticky'])) {
876
+			$possibleActions[] = 'sticky';
877
+	}
878
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
879
+			$possibleActions[] = 'move';
880
+	}
881
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
882
+			$possibleActions[] = 'remove';
883
+	}
884
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
885
+			$possibleActions[] = 'lock';
886
+	}
887
+	if (!empty($boards_can['merge_any'])) {
888
+			$possibleActions[] = 'merge';
889
+	}
890
+	if (!empty($boards_can['approve_posts'])) {
891
+			$possibleActions[] = 'approve';
892
+	}
847 893
 
848 894
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
849 895
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
850 896
 	if (!empty($_REQUEST['topics']))
851 897
 	{
852 898
 		// If the action isn't valid, just quit now.
853
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
854
-			redirectexit($redirect_url);
899
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
900
+					redirectexit($redirect_url);
901
+		}
855 902
 
856 903
 		// Merge requires all topics as one parameter and can be done at once.
857 904
 		if ($_REQUEST['qaction'] == 'merge')
858 905
 		{
859 906
 			// Merge requires at least two topics.
860
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
861
-				redirectexit($redirect_url);
907
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
908
+							redirectexit($redirect_url);
909
+			}
862 910
 
863 911
 			require_once($sourcedir . '/SplitTopics.php');
864 912
 			return MergeExecute($_REQUEST['topics']);
865 913
 		}
866 914
 
867 915
 		// Just convert to the other method, to make it easier.
868
-		foreach ($_REQUEST['topics'] as $topic)
869
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
916
+		foreach ($_REQUEST['topics'] as $topic) {
917
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
918
+		}
870 919
 	}
871 920
 
872 921
 	// Weird... how'd you get here?
873
-	if (empty($_REQUEST['actions']))
874
-		redirectexit($redirect_url);
922
+	if (empty($_REQUEST['actions'])) {
923
+			redirectexit($redirect_url);
924
+	}
875 925
 
876 926
 	// Validate each action.
877 927
 	$temp = array();
878 928
 	foreach ($_REQUEST['actions'] as $topic => $action)
879 929
 	{
880
-		if (in_array($action, $possibleActions))
881
-			$temp[(int) $topic] = $action;
930
+		if (in_array($action, $possibleActions)) {
931
+					$temp[(int) $topic] = $action;
932
+		}
882 933
 	}
883 934
 	$_REQUEST['actions'] = $temp;
884 935
 
@@ -899,27 +950,31 @@  discard block
 block discarded – undo
899 950
 		{
900 951
 			if (!empty($board))
901 952
 			{
902
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
903
-					unset($_REQUEST['actions'][$row['id_topic']]);
904
-			}
905
-			else
953
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
954
+									unset($_REQUEST['actions'][$row['id_topic']]);
955
+				}
956
+			} else
906 957
 			{
907 958
 				// Don't allow them to act on unapproved posts they can't see...
908
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
909
-					unset($_REQUEST['actions'][$row['id_topic']]);
959
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
960
+									unset($_REQUEST['actions'][$row['id_topic']]);
961
+				}
910 962
 				// Goodness, this is fun.  We need to validate the action.
911
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
912
-					unset($_REQUEST['actions'][$row['id_topic']]);
913
-				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']))))
914
-					unset($_REQUEST['actions'][$row['id_topic']]);
915
-				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']))))
916
-					unset($_REQUEST['actions'][$row['id_topic']]);
963
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
964
+									unset($_REQUEST['actions'][$row['id_topic']]);
965
+				} 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'])))) {
966
+									unset($_REQUEST['actions'][$row['id_topic']]);
967
+				} 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'])))) {
968
+									unset($_REQUEST['actions'][$row['id_topic']]);
969
+				}
917 970
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
918
-				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']))))
919
-					unset($_REQUEST['actions'][$row['id_topic']]);
971
+				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'])))) {
972
+									unset($_REQUEST['actions'][$row['id_topic']]);
973
+				}
920 974
 				// If the topic is approved then you need permission to approve the posts within.
921
-				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']))))
922
-					unset($_REQUEST['actions'][$row['id_topic']]);
975
+				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'])))) {
976
+									unset($_REQUEST['actions'][$row['id_topic']]);
977
+				}
923 978
 			}
924 979
 		}
925 980
 		$smcFunc['db_free_result']($request);
@@ -937,11 +992,11 @@  discard block
 block discarded – undo
937 992
 	{
938 993
 		$topic = (int) $topic;
939 994
 
940
-		if ($action == 'markread')
941
-			$markCache[] = $topic;
942
-		elseif ($action == 'sticky')
943
-			$stickyCache[] = $topic;
944
-		elseif ($action == 'move')
995
+		if ($action == 'markread') {
996
+					$markCache[] = $topic;
997
+		} elseif ($action == 'sticky') {
998
+					$stickyCache[] = $topic;
999
+		} elseif ($action == 'move')
945 1000
 		{
946 1001
 			require_once($sourcedir . '/MoveTopic.php');
947 1002
 			moveTopicConcurrence();
@@ -949,23 +1004,25 @@  discard block
 block discarded – undo
949 1004
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
950 1005
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
951 1006
 
952
-			if (empty($moveCache[1][$topic]))
953
-				continue;
1007
+			if (empty($moveCache[1][$topic])) {
1008
+							continue;
1009
+			}
954 1010
 
955 1011
 			$moveCache[0][] = $topic;
1012
+		} elseif ($action == 'remove') {
1013
+					$removeCache[] = $topic;
1014
+		} elseif ($action == 'lock') {
1015
+					$lockCache[] = $topic;
1016
+		} elseif ($action == 'approve') {
1017
+					$approveCache[] = $topic;
956 1018
 		}
957
-		elseif ($action == 'remove')
958
-			$removeCache[] = $topic;
959
-		elseif ($action == 'lock')
960
-			$lockCache[] = $topic;
961
-		elseif ($action == 'approve')
962
-			$approveCache[] = $topic;
963 1019
 	}
964 1020
 
965
-	if (empty($board))
966
-		$affectedBoards = array();
967
-	else
968
-		$affectedBoards = array($board => array(0, 0));
1021
+	if (empty($board)) {
1022
+			$affectedBoards = array();
1023
+	} else {
1024
+			$affectedBoards = array($board => array(0, 0));
1025
+	}
969 1026
 
970 1027
 	// Do all the stickies...
971 1028
 	if (!empty($stickyCache))
@@ -1025,14 +1082,16 @@  discard block
 block discarded – undo
1025 1082
 		{
1026 1083
 			$to = $moveCache[1][$row['id_topic']];
1027 1084
 
1028
-			if (empty($to))
1029
-				continue;
1085
+			if (empty($to)) {
1086
+							continue;
1087
+			}
1030 1088
 
1031 1089
 			// Does this topic's board count the posts or not?
1032 1090
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1033 1091
 
1034
-			if (!isset($moveTos[$to]))
1035
-				$moveTos[$to] = array();
1092
+			if (!isset($moveTos[$to])) {
1093
+							$moveTos[$to] = array();
1094
+			}
1036 1095
 
1037 1096
 			$moveTos[$to][] = $row['id_topic'];
1038 1097
 
@@ -1046,8 +1105,9 @@  discard block
 block discarded – undo
1046 1105
 		require_once($sourcedir . '/MoveTopic.php');
1047 1106
 
1048 1107
 		// Do the actual moves...
1049
-		foreach ($moveTos as $to => $topics)
1050
-			moveTopics($topics, $to);
1108
+		foreach ($moveTos as $to => $topics) {
1109
+					moveTopics($topics, $to);
1110
+		}
1051 1111
 
1052 1112
 		// Does the post counts need to be updated?
1053 1113
 		if (!empty($moveTos))
@@ -1096,20 +1156,23 @@  discard block
 block discarded – undo
1096 1156
 
1097 1157
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1098 1158
 				{
1099
-					if (!isset($members[$row['id_member']]))
1100
-						$members[$row['id_member']] = 0;
1159
+					if (!isset($members[$row['id_member']])) {
1160
+											$members[$row['id_member']] = 0;
1161
+					}
1101 1162
 
1102
-					if ($topicRecounts[$row['id_topic']] === '+')
1103
-						$members[$row['id_member']] += 1;
1104
-					else
1105
-						$members[$row['id_member']] -= 1;
1163
+					if ($topicRecounts[$row['id_topic']] === '+') {
1164
+											$members[$row['id_member']] += 1;
1165
+					} else {
1166
+											$members[$row['id_member']] -= 1;
1167
+					}
1106 1168
 				}
1107 1169
 
1108 1170
 				$smcFunc['db_free_result']($request);
1109 1171
 
1110 1172
 				// And now update them member's post counts
1111
-				foreach ($members as $id_member => $post_adj)
1112
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1173
+				foreach ($members as $id_member => $post_adj) {
1174
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1175
+				}
1113 1176
 
1114 1177
 			}
1115 1178
 		}
@@ -1189,8 +1252,9 @@  discard block
 block discarded – undo
1189 1252
 			approveTopics($approveCache);
1190 1253
 
1191 1254
 			// Time for some logging!
1192
-			foreach ($approveCache as $topic)
1193
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1255
+			foreach ($approveCache as $topic) {
1256
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1257
+			}
1194 1258
 		}
1195 1259
 	}
1196 1260
 
@@ -1225,8 +1289,7 @@  discard block
 block discarded – undo
1225 1289
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1226 1290
 			}
1227 1291
 			$smcFunc['db_free_result']($result);
1228
-		}
1229
-		else
1292
+		} else
1230 1293
 		{
1231 1294
 			$result = $smcFunc['db_query']('', '
1232 1295
 				SELECT id_topic, locked, id_board
@@ -1276,13 +1339,15 @@  discard block
 block discarded – undo
1276 1339
 			)
1277 1340
 		);
1278 1341
 		$logged_topics = array();
1279
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1280
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1342
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1343
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1344
+		}
1281 1345
 		$smcFunc['db_free_result']($request);
1282 1346
 
1283 1347
 		$markArray = array();
1284
-		foreach ($markCache as $topic)
1285
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1348
+		foreach ($markCache as $topic) {
1349
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1350
+		}
1286 1351
 
1287 1352
 		$smcFunc['db_insert']('replace',
1288 1353
 			'{db_prefix}log_topics',
@@ -1295,8 +1360,9 @@  discard block
 block discarded – undo
1295 1360
 	foreach ($moveCache as $topic)
1296 1361
 	{
1297 1362
 		// Didn't actually move anything!
1298
-		if (!isset($topic[0]))
1299
-			break;
1363
+		if (!isset($topic[0])) {
1364
+					break;
1365
+		}
1300 1366
 
1301 1367
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1302 1368
 		sendNotifications($topic[0], 'move');
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 		'calendar_updated' => time(),
1319 1385
 	));
1320 1386
 
1321
-	if (!empty($affectedBoards))
1322
-		updateLastMessages(array_keys($affectedBoards));
1387
+	if (!empty($affectedBoards)) {
1388
+			updateLastMessages(array_keys($affectedBoards));
1389
+	}
1323 1390
 
1324 1391
 	redirectexit($redirect_url);
1325 1392
 }
Please login to merge, or discard this patch.
Sources/Session.php 1 patch
Braces   +31 added lines, -21 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 4
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -65,19 +68,21 @@  discard block
 block discarded – undo
65 68
 			@ini_set('session.serialize_handler', 'php');
66 69
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
67 70
 			@ini_set('session.gc_probability', '1');
71
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
72
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
68 73
 		}
69
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
70
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
71 74
 
72 75
 		// Use cache setting sessions?
73
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
74
-			call_integration_hook('integrate_session_handlers');
76
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
77
+					call_integration_hook('integrate_session_handlers');
78
+		}
75 79
 
76 80
 		session_start();
77 81
 
78 82
 		// Change it so the cache settings are a little looser than default.
79
-		if (!empty($modSettings['databaseSession_loose']))
80
-			header('Cache-Control: private');
83
+		if (!empty($modSettings['databaseSession_loose'])) {
84
+					header('Cache-Control: private');
85
+		}
81 86
 	}
82 87
 
83 88
 	// Set the randomly generated code.
@@ -123,8 +128,9 @@  discard block
 block discarded – undo
123 128
 {
124 129
 	global $smcFunc;
125 130
 
126
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
127
-		return '';
131
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
132
+			return '';
133
+	}
128 134
 
129 135
 	// Look for it in the database.
130 136
 	$result = $smcFunc['db_query']('', '
@@ -153,8 +159,9 @@  discard block
 block discarded – undo
153 159
 {
154 160
 	global $smcFunc;
155 161
 
156
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
157
-		return false;
162
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
163
+			return false;
164
+	}
158 165
 
159 166
 	// First try to update an existing row...
160 167
 	$smcFunc['db_query']('', '
@@ -169,13 +176,14 @@  discard block
 block discarded – undo
169 176
 	);
170 177
 
171 178
 	// If that didn't work, try inserting a new one.
172
-	if ($smcFunc['db_affected_rows']() == 0)
173
-		$smcFunc['db_insert']('ignore',
179
+	if ($smcFunc['db_affected_rows']() == 0) {
180
+			$smcFunc['db_insert']('ignore',
174 181
 			'{db_prefix}sessions',
175 182
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
176 183
 			array($session_id, $data, time()),
177 184
 			array('session_id')
178 185
 		);
186
+	}
179 187
 
180 188
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
181 189
 }
@@ -190,8 +198,9 @@  discard block
 block discarded – undo
190 198
 {
191 199
 	global $smcFunc;
192 200
 
193
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
194
-		return false;
201
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
202
+			return false;
203
+	}
195 204
 
196 205
 	// Just delete the row...
197 206
 	$smcFunc['db_query']('', '
@@ -217,8 +226,9 @@  discard block
 block discarded – undo
217 226
 	global $modSettings, $smcFunc;
218 227
 
219 228
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
220
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
221
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
229
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
230
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
231
+	}
222 232
 
223 233
 	// Clean up after yerself ;).
224 234
 	$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +158 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -268,14 +274,15 @@  discard block
 block discarded – undo
268 274
 		call_integration_hook('integrate_view_members_params', array(&$params));
269 275
 
270 276
 		$search_params = array();
271
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
272
-			$search_params = smf_json_decode(base64_decode($_REQUEST['params']), true);
273
-		elseif (!empty($_POST))
277
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
278
+					$search_params = smf_json_decode(base64_decode($_REQUEST['params']), true);
279
+		} elseif (!empty($_POST))
274 280
 		{
275 281
 			$search_params['types'] = $_POST['types'];
276
-			foreach ($params as $param_name => $param_info)
277
-				if (isset($_POST[$param_name]))
282
+			foreach ($params as $param_name => $param_info) {
283
+							if (isset($_POST[$param_name]))
278 284
 					$search_params[$param_name] = $_POST[$param_name];
285
+			}
279 286
 		}
280 287
 
281 288
 		$search_url_params = isset($search_params) ? base64_encode(json_encode($search_params)) : null;
@@ -288,18 +295,21 @@  discard block
 block discarded – undo
288 295
 		foreach ($params as $param_name => $param_info)
289 296
 		{
290 297
 			// Not filled in?
291
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
292
-				continue;
298
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
299
+							continue;
300
+			}
293 301
 
294 302
 			// Make sure numeric values are really numeric.
295
-			if (in_array($param_info['type'], array('int', 'age')))
296
-				$search_params[$param_name] = (int) $search_params[$param_name];
303
+			if (in_array($param_info['type'], array('int', 'age'))) {
304
+							$search_params[$param_name] = (int) $search_params[$param_name];
305
+			}
297 306
 			// Date values have to match the specified format.
298 307
 			elseif ($param_info['type'] == 'date')
299 308
 			{
300 309
 				// Check if this date format is valid.
301
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
302
-					continue;
310
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
311
+									continue;
312
+				}
303 313
 
304 314
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
305 315
 			}
@@ -308,8 +318,9 @@  discard block
 block discarded – undo
308 318
 			if (!empty($param_info['range']))
309 319
 			{
310 320
 				// Default to '=', just in case...
311
-				if (empty($range_trans[$search_params['types'][$param_name]]))
312
-					$search_params['types'][$param_name] = '=';
321
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
322
+									$search_params['types'][$param_name] = '=';
323
+				}
313 324
 
314 325
 				// Handle special case 'age'.
315 326
 				if ($param_info['type'] == 'age')
@@ -337,29 +348,30 @@  discard block
 block discarded – undo
337 348
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
338 349
 				{
339 350
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
351
+				} else {
352
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
340 353
 				}
341
-				else
342
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
343 354
 			}
344 355
 			// Checkboxes.
345 356
 			elseif ($param_info['type'] == 'checkbox')
346 357
 			{
347 358
 				// Each checkbox or no checkbox at all is checked -> ignore.
348
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
349
-					continue;
359
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
360
+									continue;
361
+				}
350 362
 
351 363
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
352 364
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
353
-			}
354
-			else
365
+			} else
355 366
 			{
356 367
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
357 368
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
358 369
 
359
-				if ($smcFunc['db_case_sensitive'])
360
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
361
-				else
362
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
370
+				if ($smcFunc['db_case_sensitive']) {
371
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
372
+				} else {
373
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
374
+				}
363 375
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
364 376
 			}
365 377
 		}
@@ -375,16 +387,18 @@  discard block
 block discarded – undo
375 387
 		}
376 388
 
377 389
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
378
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
379
-			foreach ($search_params['membergroups'][2] as $mg)
390
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
391
+					foreach ($search_params['membergroups'][2] as $mg)
380 392
 			{
381 393
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
394
+		}
382 395
 				$where_params['add_group_' . $mg] = $mg;
383 396
 			}
384 397
 
385 398
 		// Combine the one or two membergroup parts into one query part linked with an OR.
386
-		if (!empty($mg_query_parts))
387
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
399
+		if (!empty($mg_query_parts)) {
400
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
401
+		}
388 402
 
389 403
 		// Get all selected post count related membergroups.
390 404
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -396,9 +410,9 @@  discard block
 block discarded – undo
396 410
 		// Construct the where part of the query.
397 411
 		$where = empty($query_parts) ? '1=1' : implode('
398 412
 			AND ', $query_parts);
413
+	} else {
414
+			$search_url_params = null;
399 415
 	}
400
-	else
401
-		$search_url_params = null;
402 416
 
403 417
 	// Construct the additional URL part with the query info in it.
404 418
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -521,28 +535,32 @@  discard block
 block discarded – undo
521 535
 					'function' => function($rowData) use ($txt)
522 536
 					{
523 537
 						// Calculate number of days since last online.
524
-						if (empty($rowData['last_login']))
525
-							$difference = $txt['never'];
526
-						else
538
+						if (empty($rowData['last_login'])) {
539
+													$difference = $txt['never'];
540
+						} else
527 541
 						{
528 542
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
529 543
 
530 544
 							// Today.
531
-							if (empty($num_days_difference))
532
-								$difference = $txt['viewmembers_today'];
545
+							if (empty($num_days_difference)) {
546
+															$difference = $txt['viewmembers_today'];
547
+							}
533 548
 
534 549
 							// Yesterday.
535
-							elseif ($num_days_difference == 1)
536
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
550
+							elseif ($num_days_difference == 1) {
551
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
552
+							}
537 553
 
538 554
 							// X days ago.
539
-							else
540
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
555
+							else {
556
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
557
+							}
541 558
 						}
542 559
 
543 560
 						// Show it in italics if they're not activated...
544
-						if ($rowData['is_activated'] % 10 != 1)
545
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
561
+						if ($rowData['is_activated'] % 10 != 1) {
562
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
563
+						}
546 564
 
547 565
 						return $difference;
548 566
 					},
@@ -594,8 +612,9 @@  discard block
 block discarded – undo
594 612
 	);
595 613
 
596 614
 	// Without enough permissions, don't show 'delete members' checkboxes.
597
-	if (!allowedTo('profile_remove_any'))
598
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
615
+	if (!allowedTo('profile_remove_any')) {
616
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
617
+	}
599 618
 
600 619
 	require_once($sourcedir . '/Subs-List.php');
601 620
 	createList($listOptions);
@@ -638,17 +657,18 @@  discard block
 block discarded – undo
638 657
 	);
639 658
 	while ($row = $smcFunc['db_fetch_assoc']($request))
640 659
 	{
641
-		if ($row['min_posts'] == -1)
642
-			$context['membergroups'][] = array(
660
+		if ($row['min_posts'] == -1) {
661
+					$context['membergroups'][] = array(
643 662
 				'id' => $row['id_group'],
644 663
 				'name' => $row['group_name'],
645 664
 				'can_be_additional' => true
646 665
 			);
647
-		else
648
-			$context['postgroups'][] = array(
666
+		} else {
667
+					$context['postgroups'][] = array(
649 668
 				'id' => $row['id_group'],
650 669
 				'name' => $row['group_name']
651 670
 			);
671
+		}
652 672
 	}
653 673
 	$smcFunc['db_free_result']($request);
654 674
 
@@ -675,8 +695,9 @@  discard block
 block discarded – undo
675 695
 	$context['page_title'] = $txt['admin_members'];
676 696
 	$context['sub_template'] = 'admin_browse';
677 697
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
678
-	if (isset($context['tabs'][$context['browse_type']]))
679
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
698
+	if (isset($context['tabs'][$context['browse_type']])) {
699
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
700
+	}
680 701
 
681 702
 	// Allowed filters are those we can have, in theory.
682 703
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -687,18 +708,20 @@  discard block
 block discarded – undo
687 708
 	foreach ($context['activation_numbers'] as $type => $amount)
688 709
 	{
689 710
 		// We have some of these...
690
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
691
-			$context['available_filters'][] = array(
711
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
712
+					$context['available_filters'][] = array(
692 713
 				'type' => $type,
693 714
 				'amount' => $amount,
694 715
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
695 716
 				'selected' => $type == $context['current_filter']
696 717
 			);
718
+		}
697 719
 	}
698 720
 
699 721
 	// If the filter was not sent, set it to whatever has people in it!
700
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
701
-		$context['current_filter'] = $context['available_filters'][0]['type'];
722
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
723
+			$context['current_filter'] = $context['available_filters'][0]['type'];
724
+	}
702 725
 
703 726
 	// This little variable is used to determine if we should flag where we are looking.
704 727
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -713,44 +736,47 @@  discard block
 block discarded – undo
713 736
 	);
714 737
 
715 738
 	// Are we showing duplicate information?
716
-	if (isset($_GET['showdupes']))
717
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
739
+	if (isset($_GET['showdupes'])) {
740
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
741
+	}
718 742
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
719 743
 
720 744
 	// Determine which actions we should allow on this page.
721 745
 	if ($context['browse_type'] == 'approve')
722 746
 	{
723 747
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
724
-		if ($context['current_filter'] == 4)
725
-			$context['allowed_actions'] = array(
748
+		if ($context['current_filter'] == 4) {
749
+					$context['allowed_actions'] = array(
726 750
 				'reject' => $txt['admin_browse_w_approve_deletion'],
727 751
 				'ok' => $txt['admin_browse_w_reject'],
728 752
 			);
729
-		else
730
-			$context['allowed_actions'] = array(
753
+		} else {
754
+					$context['allowed_actions'] = array(
731 755
 				'ok' => $txt['admin_browse_w_approve'],
732 756
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
733 757
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
734 758
 				'reject' => $txt['admin_browse_w_reject'],
735 759
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
736 760
 			);
737
-	}
738
-	elseif ($context['browse_type'] == 'activate')
739
-		$context['allowed_actions'] = array(
761
+		}
762
+	} elseif ($context['browse_type'] == 'activate') {
763
+			$context['allowed_actions'] = array(
740 764
 			'ok' => $txt['admin_browse_w_activate'],
741 765
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
742 766
 			'delete' => $txt['admin_browse_w_delete'],
743 767
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
744 768
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
745 769
 		);
770
+	}
746 771
 
747 772
 	// Create an option list for actions allowed to be done with selected members.
748 773
 	$allowed_actions = '
749 774
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
750 775
 			<option value="" disabled>-----------------------------</option>';
751
-	foreach ($context['allowed_actions'] as $key => $desc)
752
-		$allowed_actions .= '
776
+	foreach ($context['allowed_actions'] as $key => $desc) {
777
+			$allowed_actions .= '
753 778
 			<option value="' . $key . '">' . $desc . '</option>';
779
+	}
754 780
 
755 781
 	// Setup the Javascript function for selecting an action for the list.
756 782
 	$javascript = '
@@ -762,15 +788,16 @@  discard block
 block discarded – undo
762 788
 			var message = "";';
763 789
 
764 790
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
765
-	if ($context['current_filter'] == 4)
766
-		$javascript .= '
791
+	if ($context['current_filter'] == 4) {
792
+			$javascript .= '
767 793
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
768 794
 				message = "' . $txt['admin_browse_w_delete'] . '";
769 795
 			else
770 796
 				message = "' . $txt['admin_browse_w_reject'] . '";';
797
+	}
771 798
 	// Otherwise a nice standard message.
772
-	else
773
-		$javascript .= '
799
+	else {
800
+			$javascript .= '
774 801
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
775 802
 				message = "' . $txt['admin_browse_w_delete'] . '";
776 803
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -779,6 +806,7 @@  discard block
 block discarded – undo
779 806
 				message = "' . $txt['admin_browse_w_remind'] . '";
780 807
 			else
781 808
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
809
+	}
782 810
 	$javascript .= '
783 811
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
784 812
 				document.forms.postForm.submit();
@@ -911,10 +939,11 @@  discard block
 block discarded – undo
911 939
 						$member_links = array();
912 940
 						foreach ($rowData['duplicate_members'] as $member)
913 941
 						{
914
-							if ($member['id'])
915
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
916
-							else
917
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
942
+							if ($member['id']) {
943
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
944
+							} else {
945
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
946
+							}
918 947
 						}
919 948
 						return implode(', ', $member_links);
920 949
 					},
@@ -963,14 +992,16 @@  discard block
 block discarded – undo
963 992
 	);
964 993
 
965 994
 	// Pick what column to actually include if we're showing duplicates.
966
-	if ($context['show_duplicates'])
967
-		unset($listOptions['columns']['email']);
968
-	else
969
-		unset($listOptions['columns']['duplicates']);
995
+	if ($context['show_duplicates']) {
996
+			unset($listOptions['columns']['email']);
997
+	} else {
998
+			unset($listOptions['columns']['duplicates']);
999
+	}
970 1000
 
971 1001
 	// Only show hostname on duplicates as it takes a lot of time.
972
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
973
-		unset($listOptions['columns']['hostname']);
1002
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1003
+			unset($listOptions['columns']['hostname']);
1004
+	}
974 1005
 
975 1006
 	// Is there any need to show filters?
976 1007
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -978,9 +1009,10 @@  discard block
 block discarded – undo
978 1009
 		$filterOptions = '
979 1010
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
980 1011
 			<select name="filter" onchange="this.form.submit();">';
981
-		foreach ($context['available_filters'] as $filter)
982
-			$filterOptions .= '
1012
+		foreach ($context['available_filters'] as $filter) {
1013
+					$filterOptions .= '
983 1014
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1015
+		}
984 1016
 		$filterOptions .= '
985 1017
 			</select>
986 1018
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit"></noscript>';
@@ -992,12 +1024,13 @@  discard block
 block discarded – undo
992 1024
 	}
993 1025
 
994 1026
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
995
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
996
-		$listOptions['additional_rows'][] = array(
1027
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1028
+			$listOptions['additional_rows'][] = array(
997 1029
 			'position' => 'above_column_headers',
998 1030
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
999 1031
 			'class' => 'smalltext floatright',
1000 1032
 		);
1033
+	}
1001 1034
 
1002 1035
 	// Now that we have all the options, create the list.
1003 1036
 	require_once($sourcedir . '/Subs-List.php');
@@ -1027,12 +1060,14 @@  discard block
 block discarded – undo
1027 1060
 	$current_filter = (int) $_REQUEST['orig_filter'];
1028 1061
 
1029 1062
 	// If we are applying a filter do just that - then redirect.
1030
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1031
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1063
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1064
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1065
+	}
1032 1066
 
1033 1067
 	// Nothing to do?
1034
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1035
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1068
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1069
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1070
+	}
1036 1071
 
1037 1072
 	// Are we dealing with members who have been waiting for > set amount of time?
1038 1073
 	if (isset($_POST['time_passed']))
@@ -1045,8 +1080,9 @@  discard block
 block discarded – undo
1045 1080
 	else
1046 1081
 	{
1047 1082
 		$members = array();
1048
-		foreach ($_POST['todoAction'] as $id)
1049
-			$members[] = (int) $id;
1083
+		foreach ($_POST['todoAction'] as $id) {
1084
+					$members[] = (int) $id;
1085
+		}
1050 1086
 		$condition = '
1051 1087
 			AND id_member IN ({array_int:members})';
1052 1088
 	}
@@ -1067,8 +1103,9 @@  discard block
 block discarded – undo
1067 1103
 	$member_count = $smcFunc['db_num_rows']($request);
1068 1104
 
1069 1105
 	// If no results then just return!
1070
-	if ($member_count == 0)
1071
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1106
+	if ($member_count == 0) {
1107
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1108
+	}
1072 1109
 
1073 1110
 	$member_info = array();
1074 1111
 	$members = array();
@@ -1107,8 +1144,9 @@  discard block
 block discarded – undo
1107 1144
 		// Do we have to let the integration code know about the activations?
1108 1145
 		if (!empty($modSettings['integrate_activate']))
1109 1146
 		{
1110
-			foreach ($member_info as $member)
1111
-				call_integration_hook('integrate_activate', array($member['username']));
1147
+			foreach ($member_info as $member) {
1148
+							call_integration_hook('integrate_activate', array($member['username']));
1149
+			}
1112 1150
 		}
1113 1151
 
1114 1152
 		// Check for email.
@@ -1238,20 +1276,23 @@  discard block
 block discarded – undo
1238 1276
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1239 1277
 
1240 1278
 		require_once($sourcedir . '/Logging.php');
1241
-		foreach ($member_info as $member)
1242
-			logAction($log_action, array('member' => $member['id']), 'admin');
1279
+		foreach ($member_info as $member) {
1280
+					logAction($log_action, array('member' => $member['id']), 'admin');
1281
+		}
1243 1282
 	}
1244 1283
 
1245 1284
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1246
-	if (in_array($current_filter, array(3, 4, 5)))
1247
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1285
+	if (in_array($current_filter, array(3, 4, 5))) {
1286
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1287
+	}
1248 1288
 
1249 1289
 	// Update the member's stats. (but, we know the member didn't change their name.)
1250 1290
 	updateStats('member', false);
1251 1291
 
1252 1292
 	// If they haven't been deleted, update the post group statistics on them...
1253
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1254
-		updateStats('postgroups', $members);
1293
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1294
+			updateStats('postgroups', $members);
1295
+	}
1255 1296
 
1256 1297
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1257 1298
 }
@@ -1276,10 +1317,11 @@  discard block
 block discarded – undo
1276 1317
 	$dis = time() - $old;
1277 1318
 
1278 1319
 	// Before midnight?
1279
-	if ($dis < $sinceMidnight)
1280
-		return 0;
1281
-	else
1282
-		$dis -= $sinceMidnight;
1320
+	if ($dis < $sinceMidnight) {
1321
+			return 0;
1322
+	} else {
1323
+			$dis -= $sinceMidnight;
1324
+	}
1283 1325
 
1284 1326
 	// Divide out the seconds in a day to get the number of days.
1285 1327
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 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
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['validImageTypes'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
562
+				if (isset($context['validImageTypes'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['validImageTypes'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
713
+		elseif (isset($context['validImageTypes'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['validImageTypes'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1235,11 +1306,12 @@  discard block
 block discarded – undo
1235 1306
 				}
1236 1307
 			}
1237 1308
 
1238
-			if (!empty($attachment['id_thumb']))
1239
-				$attachmentData[$i]['thumbnail'] = array(
1309
+			if (!empty($attachment['id_thumb'])) {
1310
+							$attachmentData[$i]['thumbnail'] = array(
1240 1311
 					'id' => $attachment['id_thumb'],
1241 1312
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1242 1313
 				);
1314
+			}
1243 1315
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1244 1316
 
1245 1317
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1249,30 +1321,31 @@  discard block
 block discarded – undo
1249 1321
 				{
1250 1322
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1251 1323
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1252
-				}
1253
-				elseif (!empty($modSettings['max_image_width']))
1324
+				} elseif (!empty($modSettings['max_image_width']))
1254 1325
 				{
1255 1326
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1256 1327
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1257 1328
 				}
1258
-			}
1259
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1329
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1260 1330
 			{
1261 1331
 				// If the image is too large to show inline, make it a popup.
1262
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1263
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1264
-				else
1265
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1332
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1333
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1334
+				} else {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1336
+				}
1266 1337
 			}
1267 1338
 
1268
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1269
-				$attachmentData[$i]['downloads']++;
1339
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1340
+							$attachmentData[$i]['downloads']++;
1341
+			}
1270 1342
 		}
1271 1343
 	}
1272 1344
 
1273 1345
 	// Do we need to instigate a sort?
1274
-	if ($have_unapproved)
1275
-		usort($attachmentData, 'approved_attach_sort');
1346
+	if ($have_unapproved) {
1347
+			usort($attachmentData, 'approved_attach_sort');
1348
+	}
1276 1349
 
1277 1350
 	return $attachmentData;
1278 1351
 }
Please login to merge, or discard this patch.
Sources/Packages.php 1 patch
Braces   +599 added lines, -484 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
  * This is the notoriously defunct package manager..... :/.
@@ -57,10 +58,11 @@  discard block
 block discarded – undo
57 58
 	);
58 59
 
59 60
 	// Work out exactly who it is we are calling.
60
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
61
-		$context['sub_action'] = $_REQUEST['sa'];
62
-	else
63
-		$context['sub_action'] = 'browse';
61
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
62
+			$context['sub_action'] = $_REQUEST['sa'];
63
+	} else {
64
+			$context['sub_action'] = 'browse';
65
+	}
64 66
 
65 67
 	// Set up some tabs...
66 68
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -82,8 +84,9 @@  discard block
 block discarded – undo
82 84
 		),
83 85
 	);
84 86
 
85
-	if ($context['sub_action'] == 'browse')
86
-		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
87
+	if ($context['sub_action'] == 'browse') {
88
+			loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
89
+	}
87 90
 
88 91
 	call_integration_hook('integrate_manage_packages', array(&$subActions));
89 92
 
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings;
100 103
 
101 104
 	// You have to specify a file!!
102
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
103
-		redirectexit('action=admin;area=packages');
105
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
106
+			redirectexit('action=admin;area=packages');
107
+	}
104 108
 	$context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']);
105 109
 
106 110
 	// Do we have an existing id, for uninstalls and the like.
@@ -112,8 +116,9 @@  discard block
 block discarded – undo
112 116
 	create_chmod_control();
113 117
 
114 118
 	// Make sure temp directory exists and is empty.
115
-	if (file_exists($packagesdir . '/temp'))
116
-		deltree($packagesdir . '/temp', false);
119
+	if (file_exists($packagesdir . '/temp')) {
120
+			deltree($packagesdir . '/temp', false);
121
+	}
117 122
 
118 123
 	if (!mktree($packagesdir . '/temp', 0755))
119 124
 	{
@@ -124,8 +129,9 @@  discard block
 block discarded – undo
124 129
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true));
125 130
 
126 131
 			deltree($packagesdir . '/temp', false);
127
-			if (!mktree($packagesdir . '/temp', 0777))
128
-				fatal_lang_error('package_cant_download', false);
132
+			if (!mktree($packagesdir . '/temp', 0777)) {
133
+							fatal_lang_error('package_cant_download', false);
134
+			}
129 135
 		}
130 136
 	}
131 137
 
@@ -151,25 +157,26 @@  discard block
 block discarded – undo
151 157
 	{
152 158
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
153 159
 
154
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
155
-			foreach ($context['extracted_files'] as $file)
160
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
161
+					foreach ($context['extracted_files'] as $file)
156 162
 				if (basename($file['filename']) == 'package-info.xml')
157 163
 				{
158 164
 					$context['base_path'] = dirname($file['filename']) . '/';
165
+		}
159 166
 					break;
160 167
 				}
161 168
 
162
-		if (!isset($context['base_path']))
163
-			$context['base_path'] = '';
164
-	}
165
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
169
+		if (!isset($context['base_path'])) {
170
+					$context['base_path'] = '';
171
+		}
172
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
166 173
 	{
167 174
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
168 175
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
169 176
 		$context['base_path'] = '';
177
+	} else {
178
+			fatal_lang_error('no_access', false);
170 179
 	}
171
-	else
172
-		fatal_lang_error('no_access', false);
173 180
 
174 181
 	// Load up any custom themes we may want to install into...
175 182
 	$request = $smcFunc['db_query']('', '
@@ -185,15 +192,17 @@  discard block
 block discarded – undo
185 192
 		)
186 193
 	);
187 194
 	$theme_paths = array();
188
-	while ($row = $smcFunc['db_fetch_assoc']($request))
189
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
195
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
196
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
197
+	}
190 198
 	$smcFunc['db_free_result']($request);
191 199
 
192 200
 	// Get the package info...
193 201
 	$packageInfo = getPackageInfo($context['filename']);
194 202
 
195
-	if (!is_array($packageInfo))
196
-		fatal_lang_error($packageInfo);
203
+	if (!is_array($packageInfo)) {
204
+			fatal_lang_error($packageInfo);
205
+	}
197 206
 
198 207
 	$packageInfo['filename'] = $context['filename'];
199 208
 	$context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
@@ -227,18 +236,19 @@  discard block
 block discarded – undo
227 236
 	$smcFunc['db_free_result']($request);
228 237
 
229 238
 	$context['database_changes'] = array();
230
-	if (isset($packageInfo['uninstall']['database']))
231
-		$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
232
-	elseif (!empty($db_changes))
239
+	if (isset($packageInfo['uninstall']['database'])) {
240
+			$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
241
+	} elseif (!empty($db_changes))
233 242
 	{
234 243
 		foreach ($db_changes as $change)
235 244
 		{
236
-			if (isset($change[2]) && isset($txt['package_db_' . $change[0]]))
237
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
238
-			elseif (isset($txt['package_db_' . $change[0]]))
239
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
240
-			else
241
-				$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
245
+			if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
246
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
247
+			} elseif (isset($txt['package_db_' . $change[0]])) {
248
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
249
+			} else {
250
+							$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
251
+			}
242 252
 		}
243 253
 	}
244 254
 
@@ -265,31 +275,33 @@  discard block
 block discarded – undo
265 275
 		$context['themes_locked'] = true;
266 276
 
267 277
 		// Only let them uninstall themes it was installed into.
268
-		foreach ($theme_paths as $id => $data)
269
-			if ($id != 1 && !in_array($id, $old_themes))
278
+		foreach ($theme_paths as $id => $data) {
279
+					if ($id != 1 && !in_array($id, $old_themes))
270 280
 				unset($theme_paths[$id]);
271
-	}
272
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
281
+		}
282
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
273 283
 	{
274 284
 		// Look for an upgrade...
275 285
 		$actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version);
276 286
 
277 287
 		// There was no upgrade....
278
-		if (empty($actions))
279
-			$context['is_installed'] = true;
280
-		else
288
+		if (empty($actions)) {
289
+					$context['is_installed'] = true;
290
+		} else
281 291
 		{
282 292
 			// Otherwise they can only upgrade themes from the first time around.
283
-			foreach ($theme_paths as $id => $data)
284
-				if ($id != 1 && !in_array($id, $old_themes))
293
+			foreach ($theme_paths as $id => $data) {
294
+							if ($id != 1 && !in_array($id, $old_themes))
285 295
 					unset($theme_paths[$id]);
296
+			}
286 297
 		}
298
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
299
+			$context['is_installed'] = true;
287 300
 	}
288
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
289
-		$context['is_installed'] = true;
290 301
 
291
-	if (!isset($old_version) || $context['is_installed'])
292
-		$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
302
+	if (!isset($old_version) || $context['is_installed']) {
303
+			$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
304
+	}
293 305
 
294 306
 	$context['actions'] = array();
295 307
 	$context['ftp_needed'] = false;
@@ -297,8 +309,9 @@  discard block
 block discarded – undo
297 309
 	$chmod_files = array();
298 310
 
299 311
 	// no actions found, return so we can display an error
300
-	if (empty($actions))
301
-		return;
312
+	if (empty($actions)) {
313
+			return;
314
+	}
302 315
 
303 316
 	// This will hold data about anything that can be installed in other themes.
304 317
 	$themeFinds = array(
@@ -317,14 +330,14 @@  discard block
 block discarded – undo
317 330
 		{
318 331
 			$chmod_files[] = $action['filename'];
319 332
 			continue;
320
-		}
321
-		elseif ($action['type'] == 'readme' || $action['type'] == 'license')
333
+		} elseif ($action['type'] == 'readme' || $action['type'] == 'license')
322 334
 		{
323 335
 			$type = 'package_' . $action['type'];
324
-			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
325
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
326
-			elseif (file_exists($action['filename']))
327
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
336
+			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
337
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
338
+			} elseif (file_exists($action['filename'])) {
339
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
340
+			}
328 341
 
329 342
 			if (!empty($action['parse_bbc']))
330 343
 			{
@@ -332,24 +345,24 @@  discard block
 block discarded – undo
332 345
 				$context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]);
333 346
 				preparsecode($context[$type]);
334 347
 				$context[$type] = parse_bbc($context[$type]);
348
+			} else {
349
+							$context[$type] = nl2br($context[$type]);
335 350
 			}
336
-			else
337
-				$context[$type] = nl2br($context[$type]);
338 351
 
339 352
 			continue;
340 353
 		}
341 354
 		// Don't show redirects.
342
-		elseif ($action['type'] == 'redirect')
343
-			continue;
344
-		elseif ($action['type'] == 'error')
355
+		elseif ($action['type'] == 'redirect') {
356
+					continue;
357
+		} elseif ($action['type'] == 'error')
345 358
 		{
346 359
 			$context['has_failure'] = true;
347
-			if (isset($action['error_msg']) && isset($action['error_var']))
348
-				$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
349
-			elseif (isset($action['error_msg']))
350
-				$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
351
-		}
352
-		elseif ($action['type'] == 'modification')
360
+			if (isset($action['error_msg']) && isset($action['error_var'])) {
361
+							$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
362
+			} elseif (isset($action['error_msg'])) {
363
+							$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
364
+			}
365
+		} elseif ($action['type'] == 'modification')
353 366
 		{
354 367
 			if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
355 368
 			{
@@ -361,52 +374,54 @@  discard block
 block discarded – undo
361 374
 					'description' => $txt['package_action_missing'],
362 375
 					'failed' => true,
363 376
 				);
364
-			}
365
-			else
377
+			} else
366 378
 			{
367 379
 
368
-				if ($action['boardmod'])
369
-					$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
370
-				else
371
-					$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
380
+				if ($action['boardmod']) {
381
+									$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
382
+				} else {
383
+									$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
384
+				}
372 385
 
373
-				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-')
374
-					$mod_actions[0]['filename'] = $action['filename'];
386
+				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
387
+									$mod_actions[0]['filename'] = $action['filename'];
388
+				}
375 389
 
376 390
 				foreach ($mod_actions as $key => $mod_action)
377 391
 				{
378 392
 					// Lets get the last section of the file name.
379
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
380
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
381
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
382
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
383
-					else
384
-						$actual_filename = $key;
385
-
386
-					if ($mod_action['type'] == 'opened')
387
-						$failed = false;
388
-					elseif ($mod_action['type'] == 'failure')
393
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
394
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
395
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
396
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
397
+					} else {
398
+											$actual_filename = $key;
399
+					}
400
+
401
+					if ($mod_action['type'] == 'opened') {
402
+											$failed = false;
403
+					} elseif ($mod_action['type'] == 'failure')
389 404
 					{
390
-						if (empty($mod_action['is_custom']))
391
-							$context['has_failure'] = true;
405
+						if (empty($mod_action['is_custom'])) {
406
+													$context['has_failure'] = true;
407
+						}
392 408
 						$failed = true;
393
-					}
394
-					elseif ($mod_action['type'] == 'chmod')
409
+					} elseif ($mod_action['type'] == 'chmod')
395 410
 					{
396 411
 						$chmod_files[] = $mod_action['filename'];
397
-					}
398
-					elseif ($mod_action['type'] == 'saved')
412
+					} elseif ($mod_action['type'] == 'saved')
399 413
 					{
400 414
 						if (!empty($mod_action['is_custom']))
401 415
 						{
402
-							if (!isset($context['theme_actions'][$mod_action['is_custom']]))
403
-								$context['theme_actions'][$mod_action['is_custom']] = array(
416
+							if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
417
+															$context['theme_actions'][$mod_action['is_custom']] = array(
404 418
 									'name' => $theme_paths[$mod_action['is_custom']]['name'],
405 419
 									'actions' => array(),
406 420
 									'has_failure' => $failed,
407 421
 								);
408
-							else
409
-								$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
422
+							} else {
423
+															$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
424
+							}
410 425
 
411 426
 							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array(
412 427
 								'type' => $txt['execute_modification'],
@@ -414,8 +429,7 @@  discard block
 block discarded – undo
414 429
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
415 430
 								'failed' => $failed,
416 431
 							);
417
-						}
418
-						elseif (!isset($context['actions'][$actual_filename]))
432
+						} elseif (!isset($context['actions'][$actual_filename]))
419 433
 						{
420 434
 							$context['actions'][$actual_filename] = array(
421 435
 								'type' => $txt['execute_modification'],
@@ -423,22 +437,19 @@  discard block
 block discarded – undo
423 437
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
424 438
 								'failed' => $failed,
425 439
 							);
426
-						}
427
-						else
440
+						} else
428 441
 						{
429 442
 								$context['actions'][$actual_filename]['failed'] |= $failed;
430 443
 								$context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
431 444
 						}
432
-					}
433
-					elseif ($mod_action['type'] == 'skipping')
445
+					} elseif ($mod_action['type'] == 'skipping')
434 446
 					{
435 447
 						$context['actions'][$actual_filename] = array(
436 448
 							'type' => $txt['execute_modification'],
437 449
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
438 450
 							'description' => $txt['package_action_skipping']
439 451
 						);
440
-					}
441
-					elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
452
+					} elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
442 453
 					{
443 454
 						$context['has_failure'] = true;
444 455
 						$context['actions'][$actual_filename] = array(
@@ -447,32 +458,33 @@  discard block
 block discarded – undo
447 458
 							'description' => $txt['package_action_missing'],
448 459
 							'failed' => true,
449 460
 						);
450
-					}
451
-					elseif ($mod_action['type'] == 'error')
452
-						$context['actions'][$actual_filename] = array(
461
+					} elseif ($mod_action['type'] == 'error') {
462
+											$context['actions'][$actual_filename] = array(
453 463
 							'type' => $txt['execute_modification'],
454 464
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
455 465
 							'description' => $txt['package_action_error'],
456 466
 							'failed' => true,
457 467
 						);
468
+					}
458 469
 				}
459 470
 
460 471
 				// We need to loop again just to get the operations down correctly.
461 472
 				foreach ($mod_actions as $operation_key => $mod_action)
462 473
 				{
463 474
 					// Lets get the last section of the file name.
464
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
465
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
466
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
467
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
468
-					else
469
-						$actual_filename = $key;
475
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
476
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
477
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
478
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
479
+					} else {
480
+											$actual_filename = $key;
481
+					}
470 482
 
471 483
 					// We just need it for actual parse changes.
472 484
 					if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod')))
473 485
 					{
474
-						if (empty($mod_action['is_custom']))
475
-							$context['actions'][$actual_filename]['operations'][] = array(
486
+						if (empty($mod_action['is_custom'])) {
487
+													$context['actions'][$actual_filename]['operations'][] = array(
476 488
 								'type' => $txt['execute_modification'],
477 489
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
478 490
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -483,10 +495,11 @@  discard block
 block discarded – undo
483 495
 								'failed' => $mod_action['failed'],
484 496
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
485 497
 							);
498
+						}
486 499
 
487 500
 						// Themes are under the saved type.
488
-						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']]))
489
-							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
501
+						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
502
+													$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
490 503
 								'type' => $txt['execute_modification'],
491 504
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
492 505
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -497,59 +510,55 @@  discard block
 block discarded – undo
497 510
 								'failed' => $mod_action['failed'],
498 511
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
499 512
 							);
513
+						}
500 514
 					}
501 515
 				}
502 516
 			}
503
-		}
504
-		elseif ($action['type'] == 'code')
517
+		} elseif ($action['type'] == 'code')
505 518
 		{
506 519
 			$thisAction = array(
507 520
 				'type' => $txt['execute_code'],
508 521
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
509 522
 			);
510
-		}
511
-		elseif ($action['type'] == 'database')
523
+		} elseif ($action['type'] == 'database')
512 524
 		{
513 525
 			$thisAction = array(
514 526
 				'type' => $txt['execute_database_changes'],
515 527
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
516 528
 			);
517
-		}
518
-		elseif (in_array($action['type'], array('create-dir', 'create-file')))
529
+		} elseif (in_array($action['type'], array('create-dir', 'create-file')))
519 530
 		{
520 531
 			$thisAction = array(
521 532
 				'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']),
522 533
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
523 534
 			);
524
-		}
525
-		elseif ($action['type'] == 'hook')
535
+		} elseif ($action['type'] == 'hook')
526 536
 		{
527 537
 			$action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success'];
528 538
 
529
-			if (!isset($action['hook'], $action['function']))
530
-				$context['has_failure'] = true;
539
+			if (!isset($action['hook'], $action['function'])) {
540
+							$context['has_failure'] = true;
541
+			}
531 542
 
532 543
 			$thisAction = array(
533 544
 				'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'],
534 545
 				'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])),
535 546
 			);
536
-		}
537
-		elseif ($action['type'] == 'credits')
547
+		} elseif ($action['type'] == 'credits')
538 548
 		{
539 549
 			$thisAction = array(
540 550
 				'type' => $txt['execute_credits_add'],
541 551
 				'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])),
542 552
 			);
543
-		}
544
-		elseif ($action['type'] == 'requires')
553
+		} elseif ($action['type'] == 'requires')
545 554
 		{
546 555
 			$installed = false;
547 556
 			$version = true;
548 557
 
549 558
 			// package missing required values?
550
-			if (!isset($action['id']))
551
-				$context['has_failure'] = true;
552
-			else
559
+			if (!isset($action['id'])) {
560
+							$context['has_failure'] = true;
561
+			} else
553 562
 			{
554 563
 				// See if this dependancy is installed
555 564
 				$request = $smcFunc['db_query']('', '
@@ -565,8 +574,9 @@  discard block
 block discarded – undo
565 574
 					)
566 575
 				);
567 576
 				$installed = ($smcFunc['db_num_rows']($request) !== 0);
568
-				if ($installed)
569
-					list ($version) = $smcFunc['db_fetch_row']($request);
577
+				if ($installed) {
578
+									list ($version) = $smcFunc['db_fetch_row']($request);
579
+				}
570 580
 				$smcFunc['db_free_result']($request);
571 581
 
572 582
 				// do a version level check (if requested) in the most basic way
@@ -581,8 +591,7 @@  discard block
 block discarded – undo
581 591
 				'type' => $txt['package_requires'],
582 592
 				'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''),
583 593
 			);
584
-		}
585
-		elseif (in_array($action['type'], array('require-dir', 'require-file')))
594
+		} elseif (in_array($action['type'], array('require-dir', 'require-file')))
586 595
 		{
587 596
 			// Do this one...
588 597
 			$thisAction = array(
@@ -596,26 +605,29 @@  discard block
 block discarded – undo
596 605
 				// Is the action already stated?
597 606
 				$theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
598 607
 				// If it's not auto do we think we have something we can act upon?
599
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
600
-					$theme_action = '';
608
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
609
+									$theme_action = '';
610
+				}
601 611
 				// ... or if it's auto do we even want to do anything?
602
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
603
-					$theme_action = '';
612
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
613
+									$theme_action = '';
614
+				}
604 615
 
605 616
 				// So, we still want to do something?
606
-				if ($theme_action != '')
607
-					$themeFinds['candidates'][] = $action;
617
+				if ($theme_action != '') {
618
+									$themeFinds['candidates'][] = $action;
619
+				}
608 620
 				// Otherwise is this is going into another theme record it.
609
-				elseif ($matches[1] == 'themes_dir')
610
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
621
+				elseif ($matches[1] == 'themes_dir') {
622
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
623
+				}
611 624
 			}
612
-		}
613
-		elseif (in_array($action['type'], array('move-dir', 'move-file')))
614
-			$thisAction = array(
625
+		} elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
626
+					$thisAction = array(
615 627
 				'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']),
616 628
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
617 629
 			);
618
-		elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
630
+		} elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
619 631
 		{
620 632
 			$thisAction = array(
621 633
 				'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']),
@@ -631,30 +643,36 @@  discard block
 block discarded – undo
631 643
 				$action['unparsed_destination'] = $action['unparsed_filename'];
632 644
 
633 645
 				// If it's not auto do we think we have something we can act upon?
634
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
635
-					$theme_action = '';
646
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
647
+									$theme_action = '';
648
+				}
636 649
 				// ... or if it's auto do we even want to do anything?
637
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
638
-					$theme_action = '';
650
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
651
+									$theme_action = '';
652
+				}
639 653
 
640 654
 				// So, we still want to do something?
641
-				if ($theme_action != '')
642
-					$themeFinds['candidates'][] = $action;
655
+				if ($theme_action != '') {
656
+									$themeFinds['candidates'][] = $action;
657
+				}
643 658
 				// Otherwise is this is going into another theme record it.
644
-				elseif ($matches[1] == 'themes_dir')
645
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
659
+				elseif ($matches[1] == 'themes_dir') {
660
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
661
+				}
646 662
 			}
647 663
 		}
648 664
 
649
-		if (empty($thisAction))
650
-			continue;
665
+		if (empty($thisAction)) {
666
+					continue;
667
+		}
651 668
 
652 669
 		if (!in_array($action['type'], array('hook', 'credits')))
653 670
 		{
654
-			if ($context['uninstalling'])
655
-				$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
656
-			else
657
-				$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
671
+			if ($context['uninstalling']) {
672
+							$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
673
+			} else {
674
+							$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
675
+			}
658 676
 		}
659 677
 
660 678
 		// Don't fail if a file/directory we're trying to create doesn't exist...
@@ -669,8 +687,9 @@  discard block
 block discarded – undo
669 687
 		}
670 688
 
671 689
 		// @todo None given?
672
-		if (empty($thisAction['description']))
673
-			$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
690
+		if (empty($thisAction['description'])) {
691
+					$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
692
+		}
674 693
 
675 694
 		$context['actions'][] = $thisAction;
676 695
 	}
@@ -683,18 +702,21 @@  discard block
 block discarded – undo
683 702
 			// Get the part of the file we'll be dealing with.
684 703
 			preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
685 704
 
686
-			if ($matches[1] == 'imagesdir')
687
-				$path = '/' . basename($settings['default_images_url']);
688
-			elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir')
689
-				$path = '/languages';
690
-			else
691
-				$path = '';
705
+			if ($matches[1] == 'imagesdir') {
706
+							$path = '/' . basename($settings['default_images_url']);
707
+			} elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
708
+							$path = '/languages';
709
+			} else {
710
+							$path = '';
711
+			}
692 712
 
693
-			if (!empty($matches[3]))
694
-				$path .= $matches[3];
713
+			if (!empty($matches[3])) {
714
+							$path .= $matches[3];
715
+			}
695 716
 
696
-			if (!$context['uninstalling'])
697
-				$path .= '/' . basename($action_data['filename']);
717
+			if (!$context['uninstalling']) {
718
+							$path .= '/' . basename($action_data['filename']);
719
+			}
698 720
 
699 721
 			// Loop through each custom theme to note it's candidacy!
700 722
 			foreach ($theme_paths as $id => $theme_data)
@@ -710,36 +732,40 @@  discard block
 block discarded – undo
710 732
 						if (!mktree(dirname($real_path), false))
711 733
 						{
712 734
 							$temp = dirname($real_path);
713
-							while (!file_exists($temp) && strlen($temp) > 1)
714
-								$temp = dirname($temp);
735
+							while (!file_exists($temp) && strlen($temp) > 1) {
736
+															$temp = dirname($temp);
737
+							}
715 738
 							$chmod_files[] = $temp;
716 739
 						}
717 740
 
718
-						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path))))
719
-							$chmod_files[] = $real_path;
741
+						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
742
+													$chmod_files[] = $real_path;
743
+						}
720 744
 
721
-						if (!isset($context['theme_actions'][$id]))
722
-							$context['theme_actions'][$id] = array(
745
+						if (!isset($context['theme_actions'][$id])) {
746
+													$context['theme_actions'][$id] = array(
723 747
 								'name' => $theme_data['name'],
724 748
 								'actions' => array(),
725 749
 							);
750
+						}
726 751
 
727
-						if ($context['uninstalling'])
728
-							$context['theme_actions'][$id]['actions'][] = array(
752
+						if ($context['uninstalling']) {
753
+													$context['theme_actions'][$id]['actions'][] = array(
729 754
 								'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
730 755
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
731 756
 								'description' => '',
732 757
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))),
733 758
 								'not_mod' => true,
734 759
 							);
735
-						else
736
-							$context['theme_actions'][$id]['actions'][] = array(
760
+						} else {
761
+													$context['theme_actions'][$id]['actions'][] = array(
737 762
 								'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
738 763
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
739 764
 								'description' => '',
740 765
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))),
741 766
 								'not_mod' => true,
742 767
 							);
768
+						}
743 769
 					}
744 770
 				}
745 771
 			}
@@ -749,8 +775,9 @@  discard block
 block discarded – undo
749 775
 	// Trash the cache... which will also check permissions for us!
750 776
 	package_flush_cache(true);
751 777
 
752
-	if (file_exists($packagesdir . '/temp'))
753
-		deltree($packagesdir . '/temp');
778
+	if (file_exists($packagesdir . '/temp')) {
779
+			deltree($packagesdir . '/temp');
780
+	}
754 781
 
755 782
 	if (!empty($chmod_files))
756 783
 	{
@@ -775,8 +802,9 @@  discard block
 block discarded – undo
775 802
 	checkSession();
776 803
 
777 804
 	// If there's no file, what are we installing?
778
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
779
-		redirectexit('action=admin;area=packages');
805
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
806
+			redirectexit('action=admin;area=packages');
807
+	}
780 808
 	$context['filename'] = $_REQUEST['package'];
781 809
 
782 810
 	// If this is an uninstall, we'll have an id.
@@ -797,51 +825,55 @@  discard block
 block discarded – undo
797 825
 
798 826
 	$context['sub_template'] = 'extract_package';
799 827
 
800
-	if (!file_exists($packagesdir . '/' . $context['filename']))
801
-		fatal_lang_error('package_no_file', false);
828
+	if (!file_exists($packagesdir . '/' . $context['filename'])) {
829
+			fatal_lang_error('package_no_file', false);
830
+	}
802 831
 
803 832
 	// Load up the package FTP information?
804 833
 	create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
805 834
 
806 835
 	// Make sure temp directory exists and is empty!
807
-	if (file_exists($packagesdir . '/temp'))
808
-		deltree($packagesdir . '/temp', false);
809
-	else
810
-		mktree($packagesdir . '/temp', 0777);
836
+	if (file_exists($packagesdir . '/temp')) {
837
+			deltree($packagesdir . '/temp', false);
838
+	} else {
839
+			mktree($packagesdir . '/temp', 0777);
840
+	}
811 841
 
812 842
 	// Let the unpacker do the work.
813 843
 	if (is_file($packagesdir . '/' . $context['filename']))
814 844
 	{
815 845
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
816 846
 
817
-		if (!file_exists($packagesdir . '/temp/package-info.xml'))
818
-			foreach ($context['extracted_files'] as $file)
847
+		if (!file_exists($packagesdir . '/temp/package-info.xml')) {
848
+					foreach ($context['extracted_files'] as $file)
819 849
 				if (basename($file['filename']) == 'package-info.xml')
820 850
 				{
821 851
 					$context['base_path'] = dirname($file['filename']) . '/';
852
+		}
822 853
 					break;
823 854
 				}
824 855
 
825
-		if (!isset($context['base_path']))
826
-			$context['base_path'] = '';
827
-	}
828
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
856
+		if (!isset($context['base_path'])) {
857
+					$context['base_path'] = '';
858
+		}
859
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
829 860
 	{
830 861
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
831 862
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
832 863
 		$context['base_path'] = '';
864
+	} else {
865
+			fatal_lang_error('no_access', false);
833 866
 	}
834
-	else
835
-		fatal_lang_error('no_access', false);
836 867
 
837 868
 	// Are we installing this into any custom themes?
838 869
 	$custom_themes = array(1);
839 870
 	$known_themes = explode(',', $modSettings['knownThemes']);
840 871
 	if (!empty($_POST['custom_theme']))
841 872
 	{
842
-		foreach ($_POST['custom_theme'] as $tid)
843
-			if (in_array($tid, $known_themes))
873
+		foreach ($_POST['custom_theme'] as $tid) {
874
+					if (in_array($tid, $known_themes))
844 875
 				$custom_themes[] = (int) $tid;
876
+		}
845 877
 	}
846 878
 
847 879
 	// Now load up the paths of the themes that we need to know about.
@@ -858,8 +890,9 @@  discard block
 block discarded – undo
858 890
 	);
859 891
 	$theme_paths = array();
860 892
 	$themes_installed = array(1);
861
-	while ($row = $smcFunc['db_fetch_assoc']($request))
862
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
893
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
894
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
895
+	}
863 896
 	$smcFunc['db_free_result']($request);
864 897
 
865 898
 	// Are there any theme copying that we want to take place?
@@ -871,11 +904,13 @@  discard block
 block discarded – undo
871 904
 	{
872 905
 		foreach ($_POST['theme_changes'] as $change)
873 906
 		{
874
-			if (empty($change))
875
-				continue;
907
+			if (empty($change)) {
908
+							continue;
909
+			}
876 910
 			$theme_data = smf_json_decode(base64_decode($change), true);
877
-			if (empty($theme_data['type']))
878
-				continue;
911
+			if (empty($theme_data['type'])) {
912
+							continue;
913
+			}
879 914
 
880 915
 			$themes_installed[] = $theme_data['id'];
881 916
 			$context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
@@ -884,8 +919,9 @@  discard block
 block discarded – undo
884 919
 
885 920
 	// Get the package info...
886 921
 	$packageInfo = getPackageInfo($context['filename']);
887
-	if (!is_array($packageInfo))
888
-		fatal_lang_error($packageInfo);
922
+	if (!is_array($packageInfo)) {
923
+			fatal_lang_error($packageInfo);
924
+	}
889 925
 
890 926
 	$packageInfo['filename'] = $context['filename'];
891 927
 
@@ -897,8 +933,9 @@  discard block
 block discarded – undo
897 933
 	{
898 934
 		$_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
899 935
 		$result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
900
-		if (!$result)
901
-			fatal_lang_error('could_not_package_backup', false);
936
+		if (!$result) {
937
+					fatal_lang_error('could_not_package_backup', false);
938
+		}
902 939
 	}
903 940
 
904 941
 	// The mod isn't installed.... unless proven otherwise.
@@ -938,35 +975,38 @@  discard block
 block discarded – undo
938 975
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
939 976
 
940 977
 		// Gadzooks!  There's no uninstaller at all!?
941
-		if (empty($install_log))
942
-			fatal_lang_error('package_uninstall_cannot', false);
978
+		if (empty($install_log)) {
979
+					fatal_lang_error('package_uninstall_cannot', false);
980
+		}
943 981
 
944 982
 		// They can only uninstall from what it was originally installed into.
945
-		foreach ($theme_paths as $id => $data)
946
-			if ($id != 1 && !in_array($id, $old_themes))
983
+		foreach ($theme_paths as $id => $data) {
984
+					if ($id != 1 && !in_array($id, $old_themes))
947 985
 				unset($theme_paths[$id]);
948
-	}
949
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
986
+		}
987
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
950 988
 	{
951 989
 		// Look for an upgrade...
952 990
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version);
953 991
 
954 992
 		// There was no upgrade....
955
-		if (empty($install_log))
956
-			$context['is_installed'] = true;
957
-		else
993
+		if (empty($install_log)) {
994
+					$context['is_installed'] = true;
995
+		} else
958 996
 		{
959 997
 			// Upgrade previous themes only!
960
-			foreach ($theme_paths as $id => $data)
961
-				if ($id != 1 && !in_array($id, $old_themes))
998
+			foreach ($theme_paths as $id => $data) {
999
+							if ($id != 1 && !in_array($id, $old_themes))
962 1000
 					unset($theme_paths[$id]);
1001
+			}
963 1002
 		}
1003
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
1004
+			$context['is_installed'] = true;
964 1005
 	}
965
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
966
-		$context['is_installed'] = true;
967 1006
 
968
-	if (!isset($old_version) || $context['is_installed'])
969
-		$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1007
+	if (!isset($old_version) || $context['is_installed']) {
1008
+			$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1009
+	}
970 1010
 
971 1011
 	$context['install_finished'] = false;
972 1012
 
@@ -983,37 +1023,39 @@  discard block
 block discarded – undo
983 1023
 
984 1024
 			if ($action['type'] == 'modification' && !empty($action['filename']))
985 1025
 			{
986
-				if ($action['boardmod'])
987
-					$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
988
-				else
989
-					$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1026
+				if ($action['boardmod']) {
1027
+									$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1028
+				} else {
1029
+									$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1030
+				}
990 1031
 
991 1032
 				// Any errors worth noting?
992 1033
 				foreach ($mod_actions as $key => $modAction)
993 1034
 				{
994
-					if ($modAction['type'] == 'failure')
995
-						$failed_steps[] = array(
1035
+					if ($modAction['type'] == 'failure') {
1036
+											$failed_steps[] = array(
996 1037
 							'file' => $modAction['filename'],
997 1038
 							'large_step' => $failed_count,
998 1039
 							'sub_step' => $key,
999 1040
 							'theme' => 1,
1000 1041
 						);
1042
+					}
1001 1043
 
1002 1044
 					// Gather the themes we installed into.
1003
-					if (!empty($modAction['is_custom']))
1004
-						$themes_installed[] = $modAction['is_custom'];
1045
+					if (!empty($modAction['is_custom'])) {
1046
+											$themes_installed[] = $modAction['is_custom'];
1047
+					}
1005 1048
 				}
1006
-			}
1007
-			elseif ($action['type'] == 'code' && !empty($action['filename']))
1049
+			} elseif ($action['type'] == 'code' && !empty($action['filename']))
1008 1050
 			{
1009 1051
 				// This is just here as reference for what is available.
1010 1052
 				global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
1011 1053
 
1012 1054
 				// Now include the file and be done with it ;).
1013
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1014
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1015
-			}
1016
-			elseif ($action['type'] == 'credits')
1055
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1056
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1057
+				}
1058
+			} elseif ($action['type'] == 'credits')
1017 1059
 			{
1018 1060
 				// Time to build the billboard
1019 1061
 				$credits_tag = array(
@@ -1023,13 +1065,13 @@  discard block
 block discarded – undo
1023 1065
 					'copyright' => $action['copyright'],
1024 1066
 					'title' => $action['title'],
1025 1067
 				);
1026
-			}
1027
-			elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1068
+			} elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1028 1069
 			{
1029
-				if ($action['reverse'])
1030
-					remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1031
-				else
1032
-					add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1070
+				if ($action['reverse']) {
1071
+									remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1072
+				} else {
1073
+									add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1074
+				}
1033 1075
 			}
1034 1076
 			// Only do the database changes on uninstall if requested.
1035 1077
 			elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes'])))
@@ -1042,8 +1084,9 @@  discard block
 block discarded – undo
1042 1084
 				db_extend('packages');
1043 1085
 
1044 1086
 				// Let the file work its magic ;)
1045
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1046
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1087
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1088
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1089
+				}
1047 1090
 			}
1048 1091
 			// Handle a redirect...
1049 1092
 			elseif ($action['type'] == 'redirect' && !empty($action['redirect_url']))
@@ -1125,8 +1168,9 @@  discard block
 block discarded – undo
1125 1168
 			reloadSettings();
1126 1169
 
1127 1170
 			// Any db changes from older version?
1128
-			if (!empty($old_db_changes))
1129
-				$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1171
+			if (!empty($old_db_changes)) {
1172
+							$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1173
+			}
1130 1174
 
1131 1175
 			// If there are some database changes we might want to remove then filter them out.
1132 1176
 			if (!empty($db_package_log))
@@ -1142,22 +1186,24 @@  discard block
 block discarded – undo
1142 1186
 				 */
1143 1187
 				function sort_table_first($a, $b)
1144 1188
 				{
1145
-					if ($a[0] == $b[0])
1146
-						return 0;
1189
+					if ($a[0] == $b[0]) {
1190
+											return 0;
1191
+					}
1147 1192
 					return $a[0] == 'remove_table' ? -1 : 1;
1148 1193
 				}
1149 1194
 				usort($db_package_log, 'sort_table_first');
1150 1195
 				foreach ($db_package_log as $k => $log)
1151 1196
 				{
1152
-					if ($log[0] == 'remove_table')
1153
-						$tables[] = $log[1];
1154
-					elseif (in_array($log[1], $tables))
1155
-						unset($db_package_log[$k]);
1197
+					if ($log[0] == 'remove_table') {
1198
+											$tables[] = $log[1];
1199
+					} elseif (in_array($log[1], $tables)) {
1200
+											unset($db_package_log[$k]);
1201
+					}
1156 1202
 				}
1157 1203
 				$db_changes = json_encode($db_package_log);
1204
+			} else {
1205
+							$db_changes = '';
1158 1206
 			}
1159
-			else
1160
-				$db_changes = '';
1161 1207
 
1162 1208
 			// What themes did we actually install?
1163 1209
 			$themes_installed = array_unique($themes_installed);
@@ -1206,18 +1252,20 @@  discard block
 block discarded – undo
1206 1252
 
1207 1253
 		foreach ($db_changes as $change)
1208 1254
 		{
1209
-			if ($change[0] == 'remove_table' && isset($change[1]))
1210
-				$smcFunc['db_drop_table']($change[1]);
1211
-			elseif ($change[0] == 'remove_column' && isset($change[2]))
1212
-				$smcFunc['db_remove_column']($change[1], $change[2]);
1213
-			elseif ($change[0] == 'remove_index' && isset($change[2]))
1214
-				$smcFunc['db_remove_index']($change[1], $change[2]);
1255
+			if ($change[0] == 'remove_table' && isset($change[1])) {
1256
+							$smcFunc['db_drop_table']($change[1]);
1257
+			} elseif ($change[0] == 'remove_column' && isset($change[2])) {
1258
+							$smcFunc['db_remove_column']($change[1], $change[2]);
1259
+			} elseif ($change[0] == 'remove_index' && isset($change[2])) {
1260
+							$smcFunc['db_remove_index']($change[1], $change[2]);
1261
+			}
1215 1262
 		}
1216 1263
 	}
1217 1264
 
1218 1265
 	// Clean house... get rid of the evidence ;).
1219
-	if (file_exists($packagesdir . '/temp'))
1220
-		deltree($packagesdir . '/temp');
1266
+	if (file_exists($packagesdir . '/temp')) {
1267
+			deltree($packagesdir . '/temp');
1268
+	}
1221 1269
 
1222 1270
 	// Log what we just did.
1223 1271
 	logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin');
@@ -1239,8 +1287,9 @@  discard block
 block discarded – undo
1239 1287
 	require_once($sourcedir . '/Subs-Package.php');
1240 1288
 
1241 1289
 	// No package?  Show him or her the door.
1242
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1243
-		redirectexit('action=admin;area=packages');
1290
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1291
+			redirectexit('action=admin;area=packages');
1292
+	}
1244 1293
 
1245 1294
 	$context['linktree'][] = array(
1246 1295
 		'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'],
@@ -1253,11 +1302,12 @@  discard block
 block discarded – undo
1253 1302
 	$context['filename'] = $_REQUEST['package'];
1254 1303
 
1255 1304
 	// Let the unpacker do the work.
1256
-	if (is_file($packagesdir . '/' . $context['filename']))
1257
-		$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1258
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1259
-		$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1260
-}
1305
+	if (is_file($packagesdir . '/' . $context['filename'])) {
1306
+			$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1307
+	} elseif (is_dir($packagesdir . '/' . $context['filename'])) {
1308
+			$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1309
+	}
1310
+	}
1261 1311
 
1262 1312
 /**
1263 1313
  * Display one of the files in a package.
@@ -1269,22 +1319,25 @@  discard block
 block discarded – undo
1269 1319
 	require_once($sourcedir . '/Subs-Package.php');
1270 1320
 
1271 1321
 	// No package?  Show him or her the door.
1272
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1273
-		redirectexit('action=admin;area=packages');
1322
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1323
+			redirectexit('action=admin;area=packages');
1324
+	}
1274 1325
 
1275 1326
 	// No file?  Show him or her the door.
1276
-	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '')
1277
-		redirectexit('action=admin;area=packages');
1327
+	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') {
1328
+			redirectexit('action=admin;area=packages');
1329
+	}
1278 1330
 
1279 1331
 	$_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_')));
1280 1332
 	$_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']);
1281 1333
 
1282 1334
 	if (isset($_REQUEST['raw']))
1283 1335
 	{
1284
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1285
-			echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1286
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1287
-			echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1336
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1337
+					echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1338
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1339
+					echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1340
+		}
1288 1341
 
1289 1342
 		obExit(false);
1290 1343
 	}
@@ -1301,17 +1354,19 @@  discard block
 block discarded – undo
1301 1354
 	$context['filename'] = $_REQUEST['file'];
1302 1355
 
1303 1356
 	// Let the unpacker do the work.... but make sure we handle images properly.
1304
-	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png')))
1305
-		$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1306
-	else
1357
+	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) {
1358
+			$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1359
+	} else
1307 1360
 	{
1308
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1309
-			$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1310
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1311
-			$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1361
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1362
+					$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1363
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1364
+					$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1365
+		}
1312 1366
 
1313
-		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php')
1314
-			$context['filedata'] = highlight_php_code($context['filedata']);
1367
+		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') {
1368
+					$context['filedata'] = highlight_php_code($context['filedata']);
1369
+		}
1315 1370
 	}
1316 1371
 }
1317 1372
 
@@ -1326,8 +1381,9 @@  discard block
 block discarded – undo
1326 1381
 	checkSession('get');
1327 1382
 
1328 1383
 	// Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
1329
-	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups')
1330
-		redirectexit('action=admin;area=packages;sa=browse');
1384
+	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') {
1385
+			redirectexit('action=admin;area=packages;sa=browse');
1386
+	}
1331 1387
 	$_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
1332 1388
 
1333 1389
 	// Can't delete what's not there.
@@ -1335,9 +1391,9 @@  discard block
 block discarded – undo
1335 1391
 	{
1336 1392
 		create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true));
1337 1393
 
1338
-		if (is_dir($packagesdir . '/' . $_GET['package']))
1339
-			deltree($packagesdir . '/' . $_GET['package']);
1340
-		else
1394
+		if (is_dir($packagesdir . '/' . $_GET['package'])) {
1395
+					deltree($packagesdir . '/' . $_GET['package']);
1396
+		} else
1341 1397
 		{
1342 1398
 			smf_chmod($packagesdir . '/' . $_GET['package'], 0777);
1343 1399
 			unlink($packagesdir . '/' . $_GET['package']);
@@ -1385,8 +1441,9 @@  discard block
 block discarded – undo
1385 1441
 					'data' => array(
1386 1442
 						'function' => function($package_md5) use ($type, &$context)
1387 1443
 						{
1388
-							if (isset($context['available_' . $type . ''][$package_md5]))
1389
-								return $context['available_' . $type . ''][$package_md5]['sort_id'];
1444
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1445
+															return $context['available_' . $type . ''][$package_md5]['sort_id'];
1446
+							}
1390 1447
 						},
1391 1448
 					),
1392 1449
 					'sort' => array(
@@ -1402,8 +1459,9 @@  discard block
 block discarded – undo
1402 1459
 					'data' => array(
1403 1460
 						'function' => function($package_md5) use ($type, &$context)
1404 1461
 						{
1405
-							if (isset($context['available_' . $type . ''][$package_md5]))
1406
-								return $context['available_' . $type . ''][$package_md5]['name'];
1462
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1463
+															return $context['available_' . $type . ''][$package_md5]['name'];
1464
+							}
1407 1465
 						},
1408 1466
 					),
1409 1467
 					'sort' => array(
@@ -1418,8 +1476,9 @@  discard block
 block discarded – undo
1418 1476
 					'data' => array(
1419 1477
 						'function' => function($package_md5) use ($type, &$context)
1420 1478
 						{
1421
-							if (isset($context['available_' . $type . ''][$package_md5]))
1422
-								return $context['available_' . $type . ''][$package_md5]['version'];
1479
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1480
+															return $context['available_' . $type . ''][$package_md5]['version'];
1481
+							}
1423 1482
 						},
1424 1483
 					),
1425 1484
 					'sort' => array(
@@ -1434,8 +1493,9 @@  discard block
 block discarded – undo
1434 1493
 					'data' => array(
1435 1494
 						'function' => function($package_md5) use ($type, $txt, &$context)
1436 1495
 						{
1437
-							if (isset($context['available_' . $type . ''][$package_md5]))
1438
-								return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1496
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1497
+															return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1498
+							}
1439 1499
 						},
1440 1500
 						'class' => 'smalltext',
1441 1501
 					),
@@ -1451,28 +1511,30 @@  discard block
 block discarded – undo
1451 1511
 					'data' => array(
1452 1512
 						'function' => function($package_md5) use ($type, &$context, $scripturl, $txt)
1453 1513
 						{
1454
-							if (!isset($context['available_' . $type . ''][$package_md5]))
1455
-								return '';
1514
+							if (!isset($context['available_' . $type . ''][$package_md5])) {
1515
+															return '';
1516
+							}
1456 1517
 
1457 1518
 							// Rewrite shortcut
1458 1519
 							$package = $context['available_' . $type . ''][$package_md5];
1459 1520
 							$return = '';
1460 1521
 
1461
-							if ($package['can_uninstall'])
1462
-								$return = '
1522
+							if ($package['can_uninstall']) {
1523
+															$return = '
1463 1524
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>';
1464
-							elseif ($package['can_emulate_uninstall'])
1465
-								$return = '
1525
+							} elseif ($package['can_emulate_uninstall']) {
1526
+															$return = '
1466 1527
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>';
1467
-							elseif ($package['can_upgrade'])
1468
-								$return = '
1528
+							} elseif ($package['can_upgrade']) {
1529
+															$return = '
1469 1530
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>';
1470
-							elseif ($package['can_install'])
1471
-								$return = '
1531
+							} elseif ($package['can_install']) {
1532
+															$return = '
1472 1533
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>';
1473
-							elseif ($package['can_emulate_install'])
1474
-								$return = '
1534
+							} elseif ($package['can_emulate_install']) {
1535
+															$return = '
1475 1536
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>';
1537
+							}
1476 1538
 
1477 1539
 							return $return . '
1478 1540
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a>
@@ -1537,12 +1599,14 @@  discard block
 block discarded – undo
1537 1599
 	static $packages, $installed_mods;
1538 1600
 
1539 1601
 	// Start things up
1540
-	if (!isset($packages[$params]))
1541
-		$packages[$params] = array();
1602
+	if (!isset($packages[$params])) {
1603
+			$packages[$params] = array();
1604
+	}
1542 1605
 
1543 1606
 	// We need the packages directory to be writable for this.
1544
-	if (!@is_writable($packagesdir))
1545
-		create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1607
+	if (!@is_writable($packagesdir)) {
1608
+			create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1609
+	}
1546 1610
 
1547 1611
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1548 1612
 
@@ -1550,41 +1614,44 @@  discard block
 block discarded – undo
1550 1614
 	if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version)
1551 1615
 	{
1552 1616
 		unset($_SESSION['version_emulate']);
1553
-	}
1554
-	elseif (isset($_GET['version_emulate']))
1617
+	} elseif (isset($_GET['version_emulate']))
1555 1618
 	{
1556
-		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate']))
1557
-			unset($_SESSION['version_emulate']);
1558
-		elseif ($_GET['version_emulate'] !== 0)
1559
-			$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1619
+		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) {
1620
+					unset($_SESSION['version_emulate']);
1621
+		} elseif ($_GET['version_emulate'] !== 0) {
1622
+					$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1623
+		}
1560 1624
 	}
1561 1625
 	if (!empty($_SESSION['version_emulate']))
1562 1626
 	{
1563 1627
 		$context['forum_version'] = 'SMF ' . $_SESSION['version_emulate'];
1564 1628
 		$the_version = $_SESSION['version_emulate'];
1565 1629
 	}
1566
-	if (isset($_SESSION['single_version_emulate']))
1567
-		unset($_SESSION['single_version_emulate']);
1630
+	if (isset($_SESSION['single_version_emulate'])) {
1631
+			unset($_SESSION['single_version_emulate']);
1632
+	}
1568 1633
 
1569 1634
 	if (empty($installed_mods))
1570 1635
 	{
1571 1636
 		$instmods = loadInstalledPackages();
1572 1637
 		$installed_mods = array();
1573 1638
 		// Look through the list of installed mods...
1574
-		foreach ($instmods as $installed_mod)
1575
-			$installed_mods[$installed_mod['package_id']] = array(
1639
+		foreach ($instmods as $installed_mod) {
1640
+					$installed_mods[$installed_mod['package_id']] = array(
1576 1641
 				'id' => $installed_mod['id'],
1577 1642
 				'version' => $installed_mod['version'],
1578 1643
 				'time_installed' => $installed_mod['time_installed'],
1579 1644
 			);
1645
+		}
1580 1646
 
1581 1647
 		// Get a list of all the ids installed, so the latest packages won't include already installed ones.
1582 1648
 		$context['installed_mods'] = array_keys($installed_mods);
1583 1649
 	}
1584 1650
 
1585
-	if (empty($packages))
1586
-		foreach ($context['modification_types'] as $type)
1651
+	if (empty($packages)) {
1652
+			foreach ($context['modification_types'] as $type)
1587 1653
 			$packages[$type] = array();
1654
+	}
1588 1655
 
1589 1656
 	if ($dir = @opendir($packagesdir))
1590 1657
 	{
@@ -1600,50 +1667,56 @@  discard block
 block discarded – undo
1600 1667
 
1601 1668
 		while ($package = readdir($dir))
1602 1669
 		{
1603
-			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
1604
-				continue;
1670
+			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
1671
+							continue;
1672
+			}
1605 1673
 
1606 1674
 			$skip = false;
1607
-			foreach ($context['modification_types'] as $type)
1608
-				if (isset($context['available_' . $type][md5($package)]))
1675
+			foreach ($context['modification_types'] as $type) {
1676
+							if (isset($context['available_' . $type][md5($package)]))
1609 1677
 					$skip = true;
1678
+			}
1610 1679
 
1611
-			if ($skip)
1612
-				continue;
1680
+			if ($skip) {
1681
+							continue;
1682
+			}
1613 1683
 
1614 1684
 			// Skip directories or files that are named the same.
1615 1685
 			if (is_dir($packagesdir . '/' . $package))
1616 1686
 			{
1617
-				if (in_array($package, $dirs))
1618
-					continue;
1687
+				if (in_array($package, $dirs)) {
1688
+									continue;
1689
+				}
1619 1690
 				$dirs[] = $package;
1620
-			}
1621
-			elseif (substr(strtolower($package), -7) == '.tar.gz')
1691
+			} elseif (substr(strtolower($package), -7) == '.tar.gz')
1622 1692
 			{
1623
-				if (in_array(substr($package, 0, -7), $dirs))
1624
-					continue;
1693
+				if (in_array(substr($package, 0, -7), $dirs)) {
1694
+									continue;
1695
+				}
1625 1696
 				$dirs[] = substr($package, 0, -7);
1626
-			}
1627
-			elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1697
+			} elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1628 1698
 			{
1629
-				if (in_array(substr($package, 0, -4), $dirs))
1630
-					continue;
1699
+				if (in_array(substr($package, 0, -4), $dirs)) {
1700
+									continue;
1701
+				}
1631 1702
 				$dirs[] = substr($package, 0, -4);
1632 1703
 			}
1633 1704
 
1634 1705
 			$packageInfo = getPackageInfo($package);
1635
-			if (!is_array($packageInfo))
1636
-				continue;
1706
+			if (!is_array($packageInfo)) {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (!empty($packageInfo))
1639 1711
 			{
1640 1712
 				$packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0;
1641 1713
 				$packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0;
1642 1714
 
1643
-				if (!isset($sort_id[$packageInfo['type']]))
1644
-					$packageInfo['sort_id'] = $sort_id['unknown'];
1645
-				else
1646
-					$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1715
+				if (!isset($sort_id[$packageInfo['type']])) {
1716
+									$packageInfo['sort_id'] = $sort_id['unknown'];
1717
+				} else {
1718
+									$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1719
+				}
1647 1720
 
1648 1721
 				$packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]);
1649 1722
 				$packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']);
@@ -1692,10 +1765,11 @@  discard block
 block discarded – undo
1692 1765
 					foreach ($upgrades as $upgrade)
1693 1766
 					{
1694 1767
 						// Even if it is for this SMF, is it for the installed version of the mod?
1695
-						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for')))
1696
-							if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1768
+						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) {
1769
+													if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1697 1770
 							{
1698 1771
 								$packageInfo['can_upgrade'] = true;
1772
+						}
1699 1773
 								break;
1700 1774
 							}
1701 1775
 					}
@@ -1772,10 +1846,11 @@  discard block
 block discarded – undo
1772 1846
 
1773 1847
 	if (isset($_GET['type']) && $_GET['type'] == $params)
1774 1848
 	{
1775
-		if (isset($_GET['desc']))
1776
-			krsort($packages[$params]);
1777
-		else
1778
-			ksort($packages[$params]);
1849
+		if (isset($_GET['desc'])) {
1850
+					krsort($packages[$params]);
1851
+		} else {
1852
+					ksort($packages[$params]);
1853
+		}
1779 1854
 	}
1780 1855
 
1781 1856
 	return $packages[$params];
@@ -1804,10 +1879,11 @@  discard block
 block discarded – undo
1804 1879
 		redirectexit('action=admin;area=packages;sa=options');
1805 1880
 	}
1806 1881
 
1807
-	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1808
-		$default_username = $match[1];
1809
-	else
1810
-		$default_username = '';
1882
+	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) {
1883
+			$default_username = $match[1];
1884
+	} else {
1885
+			$default_username = '';
1886
+	}
1811 1887
 
1812 1888
 	$context['page_title'] = $txt['package_settings'];
1813 1889
 	$context['sub_template'] = 'install_options';
@@ -1836,8 +1912,9 @@  discard block
 block discarded – undo
1836 1912
 	isAllowedTo('admin_forum');
1837 1913
 
1838 1914
 	// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
1839
-	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key']))
1840
-		fatal_lang_error('operation_invalid', 'general');
1915
+	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
1916
+			fatal_lang_error('operation_invalid', 'general');
1917
+	}
1841 1918
 
1842 1919
 	// Load the required file.
1843 1920
 	require_once($sourcedir . '/Subs-Package.php');
@@ -1853,18 +1930,19 @@  discard block
 block discarded – undo
1853 1930
 	{
1854 1931
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1855 1932
 
1856
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
1857
-			foreach ($context['extracted_files'] as $file)
1933
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
1934
+					foreach ($context['extracted_files'] as $file)
1858 1935
 				if (basename($file['filename']) == 'package-info.xml')
1859 1936
 				{
1860 1937
 					$context['base_path'] = dirname($file['filename']) . '/';
1938
+		}
1861 1939
 					break;
1862 1940
 				}
1863 1941
 
1864
-		if (!isset($context['base_path']))
1865
-			$context['base_path'] = '';
1866
-	}
1867
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1942
+		if (!isset($context['base_path'])) {
1943
+					$context['base_path'] = '';
1944
+		}
1945
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
1868 1946
 	{
1869 1947
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1870 1948
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
@@ -1885,8 +1963,9 @@  discard block
 block discarded – undo
1885 1963
 		)
1886 1964
 	);
1887 1965
 	$theme_paths = array();
1888
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1889
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1968
+	}
1890 1969
 	$smcFunc['db_free_result']($request);
1891 1970
 
1892 1971
 	// If we're viewing uninstall operations, only consider themes that
@@ -1911,19 +1990,21 @@  discard block
 block discarded – undo
1911 1990
 				list ($old_themes) = $smcFunc['db_fetch_row']($request);
1912 1991
 				$old_themes = explode(',', $old_themes);
1913 1992
 
1914
-				foreach ($theme_paths as $id => $data)
1915
-					if ($id != 1 && !in_array($id, $old_themes))
1993
+				foreach ($theme_paths as $id => $data) {
1994
+									if ($id != 1 && !in_array($id, $old_themes))
1916 1995
 						unset($theme_paths[$id]);
1996
+				}
1917 1997
 			}
1918 1998
 			$smcFunc['db_free_result']($request);
1919 1999
 		}
1920 2000
 	}
1921 2001
 
1922 2002
 	// Boardmod?
1923
-	if (isset($_REQUEST['boardmod']))
1924
-		$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
1925
-	else
1926
-		$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2003
+	if (isset($_REQUEST['boardmod'])) {
2004
+			$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2005
+	} else {
2006
+			$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2007
+	}
1927 2008
 
1928 2009
 	// Ok lets get the content of the file.
1929 2010
 	$context['operations'] = array(
@@ -1979,9 +2060,9 @@  discard block
 block discarded – undo
1979 2060
 			'path' => $detect_path,
1980 2061
 			'form_elements_only' => true,
1981 2062
 		);
2063
+	} else {
2064
+			$context['ftp_connected'] = true;
1982 2065
 	}
1983
-	else
1984
-		$context['ftp_connected'] = true;
1985 2066
 
1986 2067
 	// Define the template.
1987 2068
 	$context['page_title'] = $txt['package_file_perms'];
@@ -2094,18 +2175,19 @@  discard block
 block discarded – undo
2094 2175
 	{
2095 2176
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2096 2177
 
2097
-		if (!is_array($modSettings['attachmentUploadDir']))
2098
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2178
+		if (!is_array($modSettings['attachmentUploadDir'])) {
2179
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2180
+		}
2099 2181
 
2100 2182
 		// @todo Should we suggest non-current directories be read only?
2101
-		foreach ($modSettings['attachmentUploadDir'] as $dir)
2102
-			$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2183
+		foreach ($modSettings['attachmentUploadDir'] as $dir) {
2184
+					$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2103 2185
 			'type' => 'dir',
2104 2186
 			'writable_on' => 'restrictive',
2105 2187
 		);
2188
+		}
2106 2189
 
2107
-	}
2108
-	elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2190
+	} elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2109 2191
 	{
2110 2192
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2111 2193
 		$context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array(
@@ -2155,8 +2237,8 @@  discard block
 block discarded – undo
2155 2237
 	);
2156 2238
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2157 2239
 	{
2158
-		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes'))
2159
-			$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2240
+		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) {
2241
+					$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2160 2242
 				'type' => 'dir_recursive',
2161 2243
 				'list_contents' => true,
2162 2244
 				'contents' => array(
@@ -2166,7 +2248,7 @@  discard block
 block discarded – undo
2166 2248
 					),
2167 2249
 				),
2168 2250
 			);
2169
-		else
2251
+		} else
2170 2252
 		{
2171 2253
 			$context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array(
2172 2254
 				'type' => 'dir_recursive',
@@ -2183,28 +2265,33 @@  discard block
 block discarded – undo
2183 2265
 	$smcFunc['db_free_result']($request);
2184 2266
 
2185 2267
 	// If we're submitting then let's move on to another function to keep things cleaner..
2186
-	if (isset($_POST['action_changes']))
2187
-		return PackagePermissionsAction();
2268
+	if (isset($_POST['action_changes'])) {
2269
+			return PackagePermissionsAction();
2270
+	}
2188 2271
 
2189 2272
 	$context['look_for'] = array();
2190 2273
 	// Are we looking for a particular tree - normally an expansion?
2191
-	if (!empty($_REQUEST['find']))
2192
-		$context['look_for'][] = base64_decode($_REQUEST['find']);
2274
+	if (!empty($_REQUEST['find'])) {
2275
+			$context['look_for'][] = base64_decode($_REQUEST['find']);
2276
+	}
2193 2277
 	// Only that tree?
2194 2278
 	$context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : '';
2195
-	if ($context['only_find'])
2196
-		$context['look_for'][] = $context['only_find'];
2279
+	if ($context['only_find']) {
2280
+			$context['look_for'][] = $context['only_find'];
2281
+	}
2197 2282
 
2198 2283
 	// Have we got a load of back-catalogue trees to expand from a submit etc?
2199 2284
 	if (!empty($_GET['back_look']))
2200 2285
 	{
2201 2286
 		$potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true);
2202
-		foreach ($potententialTrees as $tree)
2203
-			$context['look_for'][] = $tree;
2287
+		foreach ($potententialTrees as $tree) {
2288
+					$context['look_for'][] = $tree;
2289
+		}
2204 2290
 	}
2205 2291
 	// ... maybe posted?
2206
-	if (!empty($_POST['back_look']))
2207
-		$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2292
+	if (!empty($_POST['back_look'])) {
2293
+			$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2294
+	}
2208 2295
 
2209 2296
 	$context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15)));
2210 2297
 
@@ -2243,9 +2330,9 @@  discard block
 block discarded – undo
2243 2330
 				'chmod' => @is_writable($path),
2244 2331
 				'perms' => @fileperms($path),
2245 2332
 			);
2333
+		} else {
2334
+					unset($context['file_tree'][$path]);
2246 2335
 		}
2247
-		else
2248
-			unset($context['file_tree'][$path]);
2249 2336
 	}
2250 2337
 
2251 2338
 	// Is this actually xml?
@@ -2269,22 +2356,25 @@  discard block
 block discarded – undo
2269 2356
 	global $context;
2270 2357
 
2271 2358
 	$isLikelyPath = false;
2272
-	foreach ($context['look_for'] as $possiblePath)
2273
-		if (substr($possiblePath, 0, strlen($path)) == $path)
2359
+	foreach ($context['look_for'] as $possiblePath) {
2360
+			if (substr($possiblePath, 0, strlen($path)) == $path)
2274 2361
 			$isLikelyPath = true;
2362
+	}
2275 2363
 
2276 2364
 	// Is this where we stop?
2277
-	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath)
2278
-		return;
2279
-	elseif ($level > $context['default_level'] && !$isLikelyPath)
2280
-		return;
2365
+	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) {
2366
+			return;
2367
+	} elseif ($level > $context['default_level'] && !$isLikelyPath) {
2368
+			return;
2369
+	}
2281 2370
 
2282 2371
 	// Are we actually interested in saving this data?
2283 2372
 	$save_data = empty($context['only_find']) || $context['only_find'] == $path;
2284 2373
 
2285 2374
 	// @todo Shouldn't happen - but better error message?
2286
-	if (!is_dir($path))
2287
-		fatal_lang_error('no_access', false);
2375
+	if (!is_dir($path)) {
2376
+			fatal_lang_error('no_access', false);
2377
+	}
2288 2378
 
2289 2379
 	// This is where we put stuff we've found for sorting.
2290 2380
 	$foundData = array(
@@ -2299,11 +2389,13 @@  discard block
 block discarded – undo
2299 2389
 		if (is_file($path . '/' . $entry))
2300 2390
 		{
2301 2391
 			// Are we listing PHP files in this directory?
2302
-			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php')
2303
-				$foundData['files'][$entry] = true;
2392
+			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') {
2393
+							$foundData['files'][$entry] = true;
2394
+			}
2304 2395
 			// A file we were looking for.
2305
-			elseif ($save_data && isset($data['contents'][$entry]))
2306
-				$foundData['files'][$entry] = true;
2396
+			elseif ($save_data && isset($data['contents'][$entry])) {
2397
+							$foundData['files'][$entry] = true;
2398
+			}
2307 2399
 		}
2308 2400
 		// It's a directory - we're interested one way or another, probably...
2309 2401
 		elseif ($entry != '.' && $entry != '..')
@@ -2311,32 +2403,36 @@  discard block
 block discarded – undo
2311 2403
 			// Going further?
2312 2404
 			if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive'))))
2313 2405
 			{
2314
-				if (!isset($data['contents'][$entry]))
2315
-					$foundData['folders'][$entry] = 'dir_recursive';
2316
-				else
2317
-					$foundData['folders'][$entry] = true;
2406
+				if (!isset($data['contents'][$entry])) {
2407
+									$foundData['folders'][$entry] = 'dir_recursive';
2408
+				} else {
2409
+									$foundData['folders'][$entry] = true;
2410
+				}
2318 2411
 
2319 2412
 				// If this wasn't expected inherit the recusiveness...
2320
-				if (!isset($data['contents'][$entry]))
2321
-					// We need to do this as we will be going all recursive.
2413
+				if (!isset($data['contents'][$entry])) {
2414
+									// We need to do this as we will be going all recursive.
2322 2415
 					$data['contents'][$entry] = array(
2323 2416
 						'type' => 'dir_recursive',
2324 2417
 					);
2418
+				}
2325 2419
 
2326 2420
 				// Actually do the recursive stuff...
2327 2421
 				fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1);
2328 2422
 			}
2329 2423
 			// Maybe it is a folder we are not descending into.
2330
-			elseif (isset($data['contents'][$entry]))
2331
-				$foundData['folders'][$entry] = true;
2424
+			elseif (isset($data['contents'][$entry])) {
2425
+							$foundData['folders'][$entry] = true;
2426
+			}
2332 2427
 			// Otherwise we stop here.
2333 2428
 		}
2334 2429
 	}
2335 2430
 	closedir($dh);
2336 2431
 
2337 2432
 	// Nothing to see here?
2338
-	if (!$save_data)
2339
-		return;
2433
+	if (!$save_data) {
2434
+			return;
2435
+	}
2340 2436
 
2341 2437
 	// Now actually add the data, starting with the folders.
2342 2438
 	ksort($foundData['folders']);
@@ -2348,8 +2444,9 @@  discard block
 block discarded – undo
2348 2444
 				'perms' => @fileperms($path . '/' . $folder),
2349 2445
 			),
2350 2446
 		);
2351
-		if ($type !== true)
2352
-			$additional_data['type'] = $type;
2447
+		if ($type !== true) {
2448
+					$additional_data['type'] = $type;
2449
+		}
2353 2450
 
2354 2451
 		// If there's an offset ignore any folders in XML mode.
2355 2452
 		if (isset($_GET['xml']) && $context['file_offset'] == 0)
@@ -2368,13 +2465,13 @@  discard block
 block discarded – undo
2368 2465
 				),
2369 2466
 				'value' => $folder,
2370 2467
 			);
2371
-		}
2372
-		elseif (!isset($_GET['xml']))
2468
+		} elseif (!isset($_GET['xml']))
2373 2469
 		{
2374
-			if (isset($data['contents'][$folder]))
2375
-				$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2376
-			else
2377
-				$data['contents'][$folder] = $additional_data;
2470
+			if (isset($data['contents'][$folder])) {
2471
+							$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2472
+			} else {
2473
+							$data['contents'][$folder] = $additional_data;
2474
+			}
2378 2475
 		}
2379 2476
 	}
2380 2477
 
@@ -2386,11 +2483,13 @@  discard block
 block discarded – undo
2386 2483
 		$counter++;
2387 2484
 
2388 2485
 		// Have we reached our offset?
2389
-		if ($context['file_offset'] > $counter)
2390
-			continue;
2486
+		if ($context['file_offset'] > $counter) {
2487
+					continue;
2488
+		}
2391 2489
 		// Gone too far?
2392
-		if ($counter > ($context['file_offset'] + $context['file_limit']))
2393
-			continue;
2490
+		if ($counter > ($context['file_offset'] + $context['file_limit'])) {
2491
+					continue;
2492
+		}
2394 2493
 
2395 2494
 		$additional_data = array(
2396 2495
 			'perms' => array(
@@ -2416,13 +2515,13 @@  discard block
 block discarded – undo
2416 2515
 				),
2417 2516
 				'value' => $file,
2418 2517
 			);
2419
-		}
2420
-		elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2518
+		} elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2421 2519
 		{
2422
-			if (isset($data['contents'][$file]))
2423
-				$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2424
-			else
2425
-				$data['contents'][$file] = $additional_data;
2520
+			if (isset($data['contents'][$file])) {
2521
+							$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2522
+			} else {
2523
+							$data['contents'][$file] = $additional_data;
2524
+			}
2426 2525
 		}
2427 2526
 	}
2428 2527
 }
@@ -2444,8 +2543,9 @@  discard block
 block discarded – undo
2444 2543
 	$context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array();
2445 2544
 
2446 2545
 	// Skipping use of FTP?
2447
-	if (empty($package_ftp))
2448
-		$context['skip_ftp'] = true;
2546
+	if (empty($package_ftp)) {
2547
+			$context['skip_ftp'] = true;
2548
+	}
2449 2549
 
2450 2550
 	// We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place.
2451 2551
 	if ($context['method'] == 'individual')
@@ -2455,8 +2555,9 @@  discard block
 block discarded – undo
2455 2555
 		$context['custom_value'] = (int) $_POST['custom_value'];
2456 2556
 
2457 2557
 		// Continuing?
2458
-		if (isset($_POST['toProcess']))
2459
-			$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2558
+		if (isset($_POST['toProcess'])) {
2559
+					$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2560
+		}
2460 2561
 
2461 2562
 		if (isset($_POST['permStatus']))
2462 2563
 		{
@@ -2465,22 +2566,27 @@  discard block
 block discarded – undo
2465 2566
 			foreach ($_POST['permStatus'] as $path => $status)
2466 2567
 			{
2467 2568
 				// Nothing to see here?
2468
-				if ($status == 'no_change')
2469
-					continue;
2569
+				if ($status == 'no_change') {
2570
+									continue;
2571
+				}
2470 2572
 				$legal = false;
2471
-				foreach ($legal_roots as $root)
2472
-					if (substr($path, 0, strlen($root)) == $root)
2573
+				foreach ($legal_roots as $root) {
2574
+									if (substr($path, 0, strlen($root)) == $root)
2473 2575
 						$legal = true;
2576
+				}
2474 2577
 
2475
-				if (!$legal)
2476
-					continue;
2578
+				if (!$legal) {
2579
+									continue;
2580
+				}
2477 2581
 
2478 2582
 				// Check it exists.
2479
-				if (!file_exists($path))
2480
-					continue;
2583
+				if (!file_exists($path)) {
2584
+									continue;
2585
+				}
2481 2586
 
2482
-				if ($status == 'custom')
2483
-					$validate_custom = true;
2587
+				if ($status == 'custom') {
2588
+									$validate_custom = true;
2589
+				}
2484 2590
 
2485 2591
 				// Now add it.
2486 2592
 				$context['to_process'][$path] = $status;
@@ -2490,17 +2596,20 @@  discard block
 block discarded – undo
2490 2596
 			// Make sure the chmod status is valid?
2491 2597
 			if ($validate_custom)
2492 2598
 			{
2493
-				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false)
2494
-					fatal_error($txt['chmod_value_invalid']);
2599
+				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) {
2600
+									fatal_error($txt['chmod_value_invalid']);
2601
+				}
2495 2602
 			}
2496 2603
 
2497 2604
 			// Nothing to do?
2498
-			if (empty($context['to_process']))
2499
-				redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2605
+			if (empty($context['to_process'])) {
2606
+							redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2607
+			}
2500 2608
 		}
2501 2609
 		// Should never get here,
2502
-		else
2503
-			fatal_lang_error('no_access', false);
2610
+		else {
2611
+					fatal_lang_error('no_access', false);
2612
+		}
2504 2613
 
2505 2614
 		// Setup the custom value.
2506 2615
 		$custom_value = octdec('0' . $context['custom_value']);
@@ -2508,26 +2617,27 @@  discard block
 block discarded – undo
2508 2617
 		// Start processing items.
2509 2618
 		foreach ($context['to_process'] as $path => $status)
2510 2619
 		{
2511
-			if (in_array($status, array('execute', 'writable', 'read')))
2512
-				package_chmod($path, $status);
2513
-			elseif ($status == 'custom' && !empty($custom_value))
2620
+			if (in_array($status, array('execute', 'writable', 'read'))) {
2621
+							package_chmod($path, $status);
2622
+			} elseif ($status == 'custom' && !empty($custom_value))
2514 2623
 			{
2515 2624
 				// Use FTP if we have it.
2516 2625
 				if (!empty($package_ftp) && !empty($_SESSION['pack_ftp']))
2517 2626
 				{
2518 2627
 					$ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => ''));
2519 2628
 					$package_ftp->chmod($ftp_file, $custom_value);
2629
+				} else {
2630
+									smf_chmod($path, $custom_value);
2520 2631
 				}
2521
-				else
2522
-					smf_chmod($path, $custom_value);
2523 2632
 			}
2524 2633
 
2525 2634
 			// This fish is fried...
2526 2635
 			unset($context['to_process'][$path]);
2527 2636
 
2528 2637
 			// See if we're out of time?
2529
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2530
-				return false;
2638
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2639
+							return false;
2640
+			}
2531 2641
 		}
2532 2642
 	}
2533 2643
 	// If predefined this is a little different.
@@ -2595,23 +2705,27 @@  discard block
 block discarded – undo
2595 2705
 			{
2596 2706
 				global $context;
2597 2707
 
2598
-				if (!empty($data['writable_on']))
2599
-					if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2708
+				if (!empty($data['writable_on'])) {
2709
+									if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2600 2710
 						$context['special_files'][$path] = 1;
2711
+				}
2601 2712
 
2602
-				if (!empty($data['contents']))
2603
-					foreach ($data['contents'] as $name => $contents)
2713
+				if (!empty($data['contents'])) {
2714
+									foreach ($data['contents'] as $name => $contents)
2604 2715
 						build_special_files__recursive($path . '/' . $name, $contents);
2716
+				}
2605 2717
 			}
2606 2718
 
2607
-			foreach ($context['file_tree'] as $path => $data)
2608
-				build_special_files__recursive($path, $data);
2719
+			foreach ($context['file_tree'] as $path => $data) {
2720
+							build_special_files__recursive($path, $data);
2721
+			}
2609 2722
 		}
2610 2723
 		// Free doesn't need special files.
2611
-		elseif ($context['predefined_type'] == 'free')
2612
-			$context['special_files'] = array();
2613
-		else
2614
-			$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2724
+		elseif ($context['predefined_type'] == 'free') {
2725
+					$context['special_files'] = array();
2726
+		} else {
2727
+					$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2728
+		}
2615 2729
 
2616 2730
 		// Now we definitely know where we are, we need to go through again doing the chmod!
2617 2731
 		foreach ($context['directory_list'] as $path => $dummy)
@@ -2656,8 +2770,9 @@  discard block
 block discarded – undo
2656 2770
 			unset($context['directory_list'][$path]);
2657 2771
 
2658 2772
 			// See if we're out of time?
2659
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2660
-				return false;
2773
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2774
+							return false;
2775
+			}
2661 2776
 		}
2662 2777
 	}
2663 2778
 
Please login to merge, or discard this patch.
Sources/Poll.php 1 patch
Braces   +163 added lines, -119 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
  * Allow the user to vote.
@@ -51,8 +52,9 @@  discard block
 block discarded – undo
51 52
 			'not_guest' => 0,
52 53
 		)
53 54
 	);
54
-	if ($smcFunc['db_num_rows']($request) == 0)
55
-		fatal_lang_error('poll_error', false);
55
+	if ($smcFunc['db_num_rows']($request) == 0) {
56
+			fatal_lang_error('poll_error', false);
57
+	}
56 58
 	$row = $smcFunc['db_fetch_assoc']($request);
57 59
 	$smcFunc['db_free_result']($request);
58 60
 
@@ -60,8 +62,9 @@  discard block
 block discarded – undo
60 62
 	if ($user_info['is_guest'])
61 63
 	{
62 64
 		// Guest voting disabled?
63
-		if (!$row['guest_vote'])
64
-			fatal_lang_error('guest_vote_disabled');
65
+		if (!$row['guest_vote']) {
66
+					fatal_lang_error('guest_vote_disabled');
67
+		}
65 68
 		// Guest already voted?
66 69
 		elseif (!empty($_COOKIE['guest_poll_vote']) && preg_match('~^[0-9,;]+$~', $_COOKIE['guest_poll_vote']) && strpos($_COOKIE['guest_poll_vote'], ';' . $row['id_poll'] . ',') !== false)
67 70
 		{
@@ -71,32 +74,36 @@  discard block
 block discarded – undo
71 74
 			foreach ($guestinfo as $i => $guestvoted)
72 75
 			{
73 76
 				$guestvoted = explode(',', $guestvoted);
74
-				if ($guestvoted[0] == $row['id_poll'])
75
-					break;
77
+				if ($guestvoted[0] == $row['id_poll']) {
78
+									break;
79
+				}
76 80
 			}
77 81
 			// Has the poll been reset since guest voted?
78 82
 			if ($row['reset_poll'] > $guestvoted[1])
79 83
 			{
80 84
 				// Remove the poll info from the cookie to allow guest to vote again
81 85
 				unset($guestinfo[$i]);
82
-				if (!empty($guestinfo))
83
-					$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
84
-				else
85
-					unset($_COOKIE['guest_poll_vote']);
86
+				if (!empty($guestinfo)) {
87
+									$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
88
+				} else {
89
+									unset($_COOKIE['guest_poll_vote']);
90
+				}
91
+			} else {
92
+							fatal_lang_error('poll_error', false);
86 93
 			}
87
-			else
88
-				fatal_lang_error('poll_error', false);
89 94
 			unset($guestinfo, $guestvoted, $i);
90 95
 		}
91 96
 	}
92 97
 
93 98
 	// Is voting locked or has it expired?
94
-	if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
95
-		fatal_lang_error('poll_error', false);
99
+	if (!empty($row['voting_locked']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
100
+			fatal_lang_error('poll_error', false);
101
+	}
96 102
 
97 103
 	// If they have already voted and aren't allowed to change their vote - hence they are outta here!
98
-	if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote']))
99
-		fatal_lang_error('poll_error', false);
104
+	if (!$user_info['is_guest'] && $row['selected'] != -1 && empty($row['change_vote'])) {
105
+			fatal_lang_error('poll_error', false);
106
+	}
100 107
 	// Otherwise if they can change their vote yet they haven't sent any options... remove their vote and redirect.
101 108
 	elseif (!empty($row['change_vote']) && !$user_info['is_guest'] && empty($_POST['options']))
102 109
 	{
@@ -114,8 +121,9 @@  discard block
 block discarded – undo
114 121
 				'id_poll' => $row['id_poll'],
115 122
 			)
116 123
 		);
117
-		while ($choice = $smcFunc['db_fetch_row']($request))
118
-			$pollOptions[] = $choice[0];
124
+		while ($choice = $smcFunc['db_fetch_row']($request)) {
125
+					$pollOptions[] = $choice[0];
126
+		}
119 127
 		$smcFunc['db_free_result']($request);
120 128
 
121 129
 		// Just skip it if they had voted for nothing before.
@@ -148,19 +156,22 @@  discard block
 block discarded – undo
148 156
 		}
149 157
 
150 158
 		// Redirect back to the topic so the user can vote again!
151
-		if (empty($_POST['options']))
152
-			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
159
+		if (empty($_POST['options'])) {
160
+					redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
161
+		}
153 162
 	}
154 163
 
155 164
 	checkSession('request');
156 165
 
157 166
 	// Make sure the option(s) are valid.
158
-	if (empty($_POST['options']))
159
-		fatal_lang_error('didnt_select_vote', false);
167
+	if (empty($_POST['options'])) {
168
+			fatal_lang_error('didnt_select_vote', false);
169
+	}
160 170
 
161 171
 	// Too many options checked!
162
-	if (count($_REQUEST['options']) > $row['max_votes'])
163
-		fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
172
+	if (count($_REQUEST['options']) > $row['max_votes']) {
173
+			fatal_lang_error('poll_too_many_votes', false, array($row['max_votes']));
174
+	}
164 175
 
165 176
 	$pollOptions = array();
166 177
 	$inserts = array();
@@ -250,24 +261,30 @@  discard block
 block discarded – undo
250 261
 	list ($memberID, $pollID, $voting_locked) = $smcFunc['db_fetch_row']($request);
251 262
 
252 263
 	// If the user _can_ modify the poll....
253
-	if (!allowedTo('poll_lock_any'))
254
-		isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any'));
264
+	if (!allowedTo('poll_lock_any')) {
265
+			isAllowedTo('poll_lock_' . ($user_info['id'] == $memberID ? 'own' : 'any'));
266
+	}
255 267
 
256 268
 	// It's been locked by a non-moderator.
257
-	if ($voting_locked == '1')
258
-		$voting_locked = '0';
269
+	if ($voting_locked == '1') {
270
+			$voting_locked = '0';
271
+	}
259 272
 	// Locked by a moderator, and this is a moderator.
260
-	elseif ($voting_locked == '2' && allowedTo('moderate_board'))
261
-		$voting_locked = '0';
273
+	elseif ($voting_locked == '2' && allowedTo('moderate_board')) {
274
+			$voting_locked = '0';
275
+	}
262 276
 	// Sorry, a moderator locked it.
263
-	elseif ($voting_locked == '2' && !allowedTo('moderate_board'))
264
-		fatal_lang_error('locked_by_admin', 'user');
277
+	elseif ($voting_locked == '2' && !allowedTo('moderate_board')) {
278
+			fatal_lang_error('locked_by_admin', 'user');
279
+	}
265 280
 	// A moderator *is* locking it.
266
-	elseif ($voting_locked == '0' && allowedTo('moderate_board'))
267
-		$voting_locked = '2';
281
+	elseif ($voting_locked == '0' && allowedTo('moderate_board')) {
282
+			$voting_locked = '2';
283
+	}
268 284
 	// Well, it's gonna be locked one way or another otherwise...
269
-	else
270
-		$voting_locked = '1';
285
+	else {
286
+			$voting_locked = '1';
287
+	}
271 288
 
272 289
 	// Lock!  *Poof* - no one can vote.
273 290
 	$smcFunc['db_query']('', '
@@ -302,8 +319,9 @@  discard block
 block discarded – undo
302 319
 {
303 320
 	global $txt, $user_info, $context, $topic, $board, $smcFunc, $sourcedir, $scripturl;
304 321
 
305
-	if (empty($topic))
306
-		fatal_lang_error('no_access', false);
322
+	if (empty($topic)) {
323
+			fatal_lang_error('no_access', false);
324
+	}
307 325
 
308 326
 	loadLanguage('Post');
309 327
 	loadTemplate('Poll');
@@ -327,24 +345,28 @@  discard block
 block discarded – undo
327 345
 	);
328 346
 
329 347
 	// Assume the the topic exists, right?
330
-	if ($smcFunc['db_num_rows']($request) == 0)
331
-		fatal_lang_error('no_board');
348
+	if ($smcFunc['db_num_rows']($request) == 0) {
349
+			fatal_lang_error('no_board');
350
+	}
332 351
 	// Get the poll information.
333 352
 	$pollinfo = $smcFunc['db_fetch_assoc']($request);
334 353
 	$smcFunc['db_free_result']($request);
335 354
 
336 355
 	// If we are adding a new poll - make sure that there isn't already a poll there.
337
-	if (!$context['is_edit'] && !empty($pollinfo['id_poll']))
338
-		fatal_lang_error('poll_already_exists');
356
+	if (!$context['is_edit'] && !empty($pollinfo['id_poll'])) {
357
+			fatal_lang_error('poll_already_exists');
358
+	}
339 359
 	// Otherwise, if we're editing it, it does exist I assume?
340
-	elseif ($context['is_edit'] && empty($pollinfo['id_poll']))
341
-		fatal_lang_error('poll_not_found');
360
+	elseif ($context['is_edit'] && empty($pollinfo['id_poll'])) {
361
+			fatal_lang_error('poll_not_found');
362
+	}
342 363
 
343 364
 	// Can you do this?
344
-	if ($context['is_edit'] && !allowedTo('poll_edit_any'))
345
-		isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any'));
346
-	elseif (!$context['is_edit'] && !allowedTo('poll_add_any'))
347
-		isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any'));
365
+	if ($context['is_edit'] && !allowedTo('poll_edit_any')) {
366
+			isAllowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any'));
367
+	} elseif (!$context['is_edit'] && !allowedTo('poll_add_any')) {
368
+			isAllowedTo('poll_add_' . ($user_info['id'] == $pollinfo['id_member_started'] ? 'own' : 'any'));
369
+	}
348 370
 	$context['can_moderate_poll'] = isset($_REQUEST['add']) ? true : allowedTo('poll_edit_' . ($user_info['id'] == $pollinfo['id_member_started'] || ($pollinfo['poll_starter'] != 0 && $user_info['id'] == $pollinfo['poll_starter']) ? 'own' : 'any'));
349 371
 
350 372
 	// Do we enable guest voting?
@@ -386,12 +408,14 @@  discard block
 block discarded – undo
386 408
 			while ($row = $smcFunc['db_fetch_assoc']($request))
387 409
 			{
388 410
 				// Get the highest id so we can add more without reusing.
389
-				if ($row['id_choice'] >= $last_id)
390
-					$last_id = $row['id_choice'] + 1;
411
+				if ($row['id_choice'] >= $last_id) {
412
+									$last_id = $row['id_choice'] + 1;
413
+				}
391 414
 
392 415
 				// They cleared this by either omitting it or emptying it.
393
-				if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '')
394
-					continue;
416
+				if (!isset($_POST['options'][$row['id_choice']]) || $_POST['options'][$row['id_choice']] == '') {
417
+									continue;
418
+				}
395 419
 
396 420
 				censorText($row['label']);
397 421
 
@@ -409,9 +433,10 @@  discard block
 block discarded – undo
409 433
 
410 434
 		// Work out how many options we have, so we get the 'is_last' field right...
411 435
 		$totalPostOptions = 0;
412
-		foreach ($_POST['options'] as $id => $label)
413
-			if ($label != '')
436
+		foreach ($_POST['options'] as $id => $label) {
437
+					if ($label != '')
414 438
 				$totalPostOptions++;
439
+		}
415 440
 
416 441
 		$count = 1;
417 442
 		// If an option exists, update it.  If it is new, add it - but don't reuse ids!
@@ -420,30 +445,32 @@  discard block
 block discarded – undo
420 445
 			$label = $smcFunc['htmlspecialchars']($label);
421 446
 			censorText($label);
422 447
 
423
-			if (isset($context['choices'][$id]))
424
-				$context['choices'][$id]['label'] = $label;
425
-			elseif ($label != '')
426
-				$context['choices'][] = array(
448
+			if (isset($context['choices'][$id])) {
449
+							$context['choices'][$id]['label'] = $label;
450
+			} elseif ($label != '') {
451
+							$context['choices'][] = array(
427 452
 					'id' => $last_id++,
428 453
 					'number' => $number++,
429 454
 					'label' => $label,
430 455
 					'votes' => -1,
431 456
 					'is_last' => $count++ == $totalPostOptions && $totalPostOptions > 1 ? true : false,
432 457
 				);
458
+			}
433 459
 		}
434 460
 
435 461
 		// Make sure we have two choices for sure!
436 462
 		if ($totalPostOptions < 2)
437 463
 		{
438 464
 			// Need two?
439
-			if ($totalPostOptions == 0)
440
-				$context['choices'][] = array(
465
+			if ($totalPostOptions == 0) {
466
+							$context['choices'][] = array(
441 467
 					'id' => $last_id++,
442 468
 					'number' => $number++,
443 469
 					'label' => '',
444 470
 					'votes' => -1,
445 471
 					'is_last' => false
446 472
 				);
473
+			}
447 474
 			$poll_errors[] = 'poll_few';
448 475
 		}
449 476
 
@@ -458,12 +485,14 @@  discard block
 block discarded – undo
458 485
 
459 486
 		$context['last_choice_id'] = $last_id;
460 487
 
461
-		if ($context['can_moderate_poll'])
462
-			$context['poll']['expiration'] = $_POST['poll_expire'];
488
+		if ($context['can_moderate_poll']) {
489
+					$context['poll']['expiration'] = $_POST['poll_expire'];
490
+		}
463 491
 
464 492
 		// Check the question/option count for errors.
465
-		if (trim($_POST['question']) == '' && empty($context['poll_error']))
466
-			$poll_errors[] = 'no_question';
493
+		if (trim($_POST['question']) == '' && empty($context['poll_error'])) {
494
+					$poll_errors[] = 'no_question';
495
+		}
467 496
 
468 497
 		// No check is needed, since nothing is really posted.
469 498
 		checkSubmitOnce('free');
@@ -480,8 +509,7 @@  discard block
 block discarded – undo
480 509
 				$context['poll_error']['messages'][] = $txt['error_' . $poll_error];
481 510
 			}
482 511
 		}
483
-	}
484
-	else
512
+	} else
485 513
 	{
486 514
 		// Basic theme info...
487 515
 		$context['poll'] = array(
@@ -596,18 +624,22 @@  discard block
 block discarded – undo
596 624
 	global $user_info, $smcFunc, $sourcedir;
597 625
 
598 626
 	// Sneaking off, are we?
599
-	if (empty($_POST))
600
-		redirectexit('action=editpoll;topic=' . $topic . '.0');
627
+	if (empty($_POST)) {
628
+			redirectexit('action=editpoll;topic=' . $topic . '.0');
629
+	}
601 630
 
602
-	if (checkSession('post', '', false) != '')
603
-		$poll_errors[] = 'session_timeout';
631
+	if (checkSession('post', '', false) != '') {
632
+			$poll_errors[] = 'session_timeout';
633
+	}
604 634
 
605
-	if (isset($_POST['preview']))
606
-		return EditPoll();
635
+	if (isset($_POST['preview'])) {
636
+			return EditPoll();
637
+	}
607 638
 
608 639
 	// HACKERS (!!) can't edit :P.
609
-	if (empty($topic))
610
-		fatal_lang_error('no_access', false);
640
+	if (empty($topic)) {
641
+			fatal_lang_error('no_access', false);
642
+	}
611 643
 
612 644
 	// Is this a new poll, or editing an existing?
613 645
 	$isEdit = isset($_REQUEST['add']) ? 0 : 1;
@@ -623,23 +655,27 @@  discard block
 block discarded – undo
623 655
 			'current_topic' => $topic,
624 656
 		)
625 657
 	);
626
-	if ($smcFunc['db_num_rows']($request) == 0)
627
-		fatal_lang_error('no_board');
658
+	if ($smcFunc['db_num_rows']($request) == 0) {
659
+			fatal_lang_error('no_board');
660
+	}
628 661
 	$bcinfo = $smcFunc['db_fetch_assoc']($request);
629 662
 	$smcFunc['db_free_result']($request);
630 663
 
631 664
 	// Check their adding/editing is valid.
632
-	if (!$isEdit && !empty($bcinfo['id_poll']))
633
-		fatal_lang_error('poll_already_exists');
665
+	if (!$isEdit && !empty($bcinfo['id_poll'])) {
666
+			fatal_lang_error('poll_already_exists');
667
+	}
634 668
 	// Are we editing a poll which doesn't exist?
635
-	elseif ($isEdit && empty($bcinfo['id_poll']))
636
-		fatal_lang_error('poll_not_found');
669
+	elseif ($isEdit && empty($bcinfo['id_poll'])) {
670
+			fatal_lang_error('poll_not_found');
671
+	}
637 672
 
638 673
 	// Check if they have the power to add or edit the poll.
639
-	if ($isEdit && !allowedTo('poll_edit_any'))
640
-		isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any'));
641
-	elseif (!$isEdit && !allowedTo('poll_add_any'))
642
-		isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any'));
674
+	if ($isEdit && !allowedTo('poll_edit_any')) {
675
+			isAllowedTo('poll_edit_' . ($user_info['id'] == $bcinfo['id_member_started'] || ($bcinfo['poll_starter'] != 0 && $user_info['id'] == $bcinfo['poll_starter']) ? 'own' : 'any'));
676
+	} elseif (!$isEdit && !allowedTo('poll_add_any')) {
677
+			isAllowedTo('poll_add_' . ($user_info['id'] == $bcinfo['id_member_started'] ? 'own' : 'any'));
678
+	}
643 679
 
644 680
 	$optionCount = 0;
645 681
 	$idCount = 0;
@@ -652,14 +688,16 @@  discard block
 block discarded – undo
652 688
 			$idCount = max($idCount, $k);
653 689
 		}
654 690
 	}
655
-	if ($optionCount < 2)
656
-		$poll_errors[] = 'poll_few';
657
-	elseif ($optionCount > 256 || $idCount > 255)
658
-		$poll_errors[] = 'poll_many';
691
+	if ($optionCount < 2) {
692
+			$poll_errors[] = 'poll_few';
693
+	} elseif ($optionCount > 256 || $idCount > 255) {
694
+			$poll_errors[] = 'poll_many';
695
+	}
659 696
 
660 697
 	// Also - ensure they are not removing the question.
661
-	if (trim($_POST['question']) == '')
662
-		$poll_errors[] = 'no_question';
698
+	if (trim($_POST['question']) == '') {
699
+			$poll_errors[] = 'no_question';
700
+	}
663 701
 
664 702
 	// Got any errors to report?
665 703
 	if (!empty($poll_errors))
@@ -695,8 +733,9 @@  discard block
 block discarded – undo
695 733
 	{
696 734
 		require_once($sourcedir . '/Subs-Members.php');
697 735
 		$allowedGroups = groupsAllowedTo('poll_vote', $board);
698
-		if (!in_array(-1, $allowedGroups['allowed']))
699
-			$_POST['poll_guest_vote'] = 0;
736
+		if (!in_array(-1, $allowedGroups['allowed'])) {
737
+					$_POST['poll_guest_vote'] = 0;
738
+		}
700 739
 	}
701 740
 
702 741
 	// Ensure that the number options allowed makes sense, and the expiration date is valid.
@@ -704,17 +743,19 @@  discard block
 block discarded – undo
704 743
 	{
705 744
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
706 745
 
707
-		if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
708
-			$_POST['poll_hide'] = 1;
709
-		elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24)))
710
-			$_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24;
711
-		else
712
-			$_POST['poll_expire'] = $bcinfo['expire_time'];
746
+		if (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
747
+					$_POST['poll_hide'] = 1;
748
+		} elseif (!$isEdit || $_POST['poll_expire'] != ceil($bcinfo['expire_time'] <= time() ? -1 : ($bcinfo['expire_time'] - time()) / (3600 * 24))) {
749
+					$_POST['poll_expire'] = empty($_POST['poll_expire']) ? '0' : time() + $_POST['poll_expire'] * 3600 * 24;
750
+		} else {
751
+					$_POST['poll_expire'] = $bcinfo['expire_time'];
752
+		}
713 753
 
714
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
715
-			$_POST['poll_max_votes'] = 1;
716
-		else
717
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
754
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
755
+					$_POST['poll_max_votes'] = 1;
756
+		} else {
757
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
758
+		}
718 759
 	}
719 760
 
720 761
 	// If we're editing, let's commit the changes.
@@ -779,8 +820,9 @@  discard block
 block discarded – undo
779 820
 		)
780 821
 	);
781 822
 	$choices = array();
782
-	while ($row = $smcFunc['db_fetch_assoc']($request))
783
-		$choices[] = $row['id_choice'];
823
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+			$choices[] = $row['id_choice'];
825
+	}
784 826
 	$smcFunc['db_free_result']($request);
785 827
 
786 828
 	$delete_options = array();
@@ -793,8 +835,9 @@  discard block
 block discarded – undo
793 835
 		if (trim($option) == '')
794 836
 		{
795 837
 			// They want it deleted.  Bye.
796
-			if (in_array($k, $choices))
797
-				$delete_options[] = $k;
838
+			if (in_array($k, $choices)) {
839
+							$delete_options[] = $k;
840
+			}
798 841
 
799 842
 			// Skip the rest...
800 843
 			continue;
@@ -804,8 +847,8 @@  discard block
 block discarded – undo
804 847
 		$option = $smcFunc['htmlspecialchars']($option);
805 848
 
806 849
 		// If it's already there, update it.  If it's not... add it.
807
-		if (in_array($k, $choices))
808
-			$smcFunc['db_query']('', '
850
+		if (in_array($k, $choices)) {
851
+					$smcFunc['db_query']('', '
809 852
 				UPDATE {db_prefix}poll_choices
810 853
 				SET label = {string:option_name}
811 854
 				WHERE id_poll = {int:id_poll}
@@ -816,8 +859,8 @@  discard block
 block discarded – undo
816 859
 					'option_name' => $option,
817 860
 				)
818 861
 			);
819
-		else
820
-			$smcFunc['db_insert']('',
862
+		} else {
863
+					$smcFunc['db_insert']('',
821 864
 				'{db_prefix}poll_choices',
822 865
 				array(
823 866
 					'id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255', 'votes' => 'int',
@@ -827,6 +870,7 @@  discard block
 block discarded – undo
827 870
 				),
828 871
 				array()
829 872
 			);
873
+		}
830 874
 	}
831 875
 
832 876
 	// I'm sorry, but... well, no one was choosing you.  Poor options, I'll put you out of your misery.
@@ -892,13 +936,11 @@  discard block
 block discarded – undo
892 936
 	{
893 937
 		// Added a poll
894 938
 		logAction('add_poll', array('topic' => $topic));
895
-	}
896
-	elseif (isset($_REQUEST['deletevotes']))
939
+	} elseif (isset($_REQUEST['deletevotes']))
897 940
 	{
898 941
 		// Reset votes
899 942
 		logAction('reset_poll', array('topic' => $topic));
900
-	}
901
-	else
943
+	} else
902 944
 	{
903 945
 		// Something else
904 946
 		logAction('editpoll', array('topic' => $topic));
@@ -921,8 +963,9 @@  discard block
 block discarded – undo
921 963
 	global $topic, $user_info, $smcFunc;
922 964
 
923 965
 	// Make sure the topic is not empty.
924
-	if (empty($topic))
925
-		fatal_lang_error('no_access', false);
966
+	if (empty($topic)) {
967
+			fatal_lang_error('no_access', false);
968
+	}
926 969
 
927 970
 	// Verify the session.
928 971
 	checkSession('get');
@@ -940,8 +983,9 @@  discard block
 block discarded – undo
940 983
 				'current_topic' => $topic,
941 984
 			)
942 985
 		);
943
-		if ($smcFunc['db_num_rows']($request) == 0)
944
-			fatal_lang_error('no_access', false);
986
+		if ($smcFunc['db_num_rows']($request) == 0) {
987
+					fatal_lang_error('no_access', false);
988
+		}
945 989
 		list ($topicStarter, $pollStarter) = $smcFunc['db_fetch_row']($request);
946 990
 		$smcFunc['db_free_result']($request);
947 991
 
Please login to merge, or discard this patch.