Completed
Push — release-2.1 ( a51b86...3c6b17 )
by Colin
08:06
created
Sources/ShowAttachments.php 1 patch
Braces   +59 added lines, -52 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
  * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count.
@@ -40,11 +41,11 @@  discard block
 block discarded – undo
40 41
 
41 42
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
42 43
 	{
43
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
44
-			$modSettings['enableCompressedOutput'] = 0;
45
-
46
-		else
47
-			ob_start('ob_gzhandler');
44
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
45
+					$modSettings['enableCompressedOutput'] = 0;
46
+		} else {
47
+					ob_start('ob_gzhandler');
48
+		}
48 49
 	}
49 50
 
50 51
 	if (empty($modSettings['enableCompressedOutput']))
@@ -76,8 +77,9 @@  discard block
 block discarded – undo
76 77
 	}
77 78
 
78 79
 	// Use cache when possible.
79
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
80
-		list($file, $thumbFile) = $cache;
80
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
81
+			list($file, $thumbFile) = $cache;
82
+	}
81 83
 
82 84
 	// Get the info from the DB.
83 85
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -85,10 +87,9 @@  discard block
 block discarded – undo
85 87
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
86 88
 		$attachRequest = null;
87 89
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
88
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
89
-			$request = $attachRequest;
90
-
91
-		else
90
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
91
+					$request = $attachRequest;
92
+		} else
92 93
 		{
93 94
 			// Make sure this attachment is on this board and load its info while we are at it.
94 95
 			$request = $smcFunc['db_query']('', '
@@ -181,13 +182,15 @@  discard block
 block discarded – undo
181 182
 		}
182 183
 
183 184
 		// Cache it.
184
-		if (!empty($file) || !empty($thumbFile))
185
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
185
+		if (!empty($file) || !empty($thumbFile)) {
186
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), mt_rand(850, 900));
187
+		}
186 188
 	}
187 189
 
188 190
 	// Replace the normal file with its thumbnail if it has one!
189
-	if (!empty($showThumb) && !empty($thumbFile))
190
-		$file = $thumbFile;
191
+	if (!empty($showThumb) && !empty($thumbFile)) {
192
+			$file = $thumbFile;
193
+	}
191 194
 
192 195
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
193 196
 	if (!file_exists($file['filePath']))
@@ -237,8 +240,8 @@  discard block
 block discarded – undo
237 240
 	}
238 241
 
239 242
 	// Update the download counter (unless it's a thumbnail or resuming an incomplete download).
240
-	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0)
241
-		$smcFunc['db_query']('', '
243
+	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) {
244
+			$smcFunc['db_query']('', '
242 245
 			UPDATE {db_prefix}attachments
243 246
 			SET downloads = downloads + 1
244 247
 			WHERE id_attach = {int:id_attach}',
@@ -246,12 +249,14 @@  discard block
 block discarded – undo
246 249
 				'id_attach' => $attachId,
247 250
 			)
248 251
 		);
252
+	}
249 253
 
250 254
 	// Send the attachment headers.
251 255
 	header('Pragma: ');
252 256
 
253
-	if (!isBrowser('gecko'))
254
-		header('Content-Transfer-Encoding: binary');
257
+	if (!isBrowser('gecko')) {
258
+			header('Content-Transfer-Encoding: binary');
259
+	}
255 260
 
256 261
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
257 262
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -260,18 +265,19 @@  discard block
 block discarded – undo
260 265
 	header('ETag: ' . $eTag);
261 266
 
262 267
 	// Make sure the mime type warrants an inline display.
263
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
264
-		unset($_REQUEST['image']);
268
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
269
+			unset($_REQUEST['image']);
270
+	}
265 271
 
266 272
 	// Does this have a mime type?
267
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
268
-		header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
269
-
270
-	else
273
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
274
+			header('Content-Type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
275
+	} else
271 276
 	{
272 277
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
273
-		if (isset($_REQUEST['image']))
274
-			unset($_REQUEST['image']);
278
+		if (isset($_REQUEST['image'])) {
279
+					unset($_REQUEST['image']);
280
+		}
275 281
 	}
276 282
 
277 283
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -279,24 +285,22 @@  discard block
 block discarded – undo
279 285
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
280 286
 
281 287
 	// Different browsers like different standards...
282
-	if (isBrowser('firefox'))
283
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
284
-
285
-	elseif (isBrowser('opera'))
286
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
287
-
288
-	elseif (isBrowser('ie'))
289
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
290
-
291
-	else
292
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
288
+	if (isBrowser('firefox')) {
289
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
290
+	} elseif (isBrowser('opera')) {
291
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
292
+	} elseif (isBrowser('ie')) {
293
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
294
+	} else {
295
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
296
+	}
293 297
 
294 298
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
295
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
296
-		header('Cache-Control: no-cache');
297
-
298
-	else
299
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
299
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
300
+			header('Cache-Control: no-cache');
301
+	} else {
302
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
303
+	}
300 304
 
301 305
 	// Multipart and resuming support
302 306
 	if (isset($_SERVER['HTTP_RANGE']))
@@ -304,9 +308,9 @@  discard block
 block discarded – undo
304 308
 		header("HTTP/1.1 206 Partial Content");
305 309
 		header("Content-Length: $new_length");
306 310
 		header("Content-Range: bytes $range-$range_end/$size");
311
+	} else {
312
+			header("Content-Length: " . $size);
307 313
 	}
308
-	else
309
-		header("Content-Length: " . $size);
310 314
 
311 315
 
312 316
 	// Try to buy some time...
@@ -315,8 +319,9 @@  discard block
 block discarded – undo
315 319
 	// For multipart/resumable downloads, send the requested chunk(s) of the file
316 320
 	if (isset($_SERVER['HTTP_RANGE']))
317 321
 	{
318
-		while (@ob_get_level() > 0)
319
-			@ob_end_clean();
322
+		while (@ob_get_level() > 0) {
323
+					@ob_end_clean();
324
+		}
320 325
 
321 326
 		// 40 kilobytes is a good-ish amount
322 327
 		$chunksize = 40 * 1024;
@@ -340,8 +345,9 @@  discard block
 block discarded – undo
340 345
 	elseif ($size > 4194304)
341 346
 	{
342 347
 		// Forcibly end any output buffering going on.
343
-		while (@ob_get_level() > 0)
344
-			@ob_end_clean();
348
+		while (@ob_get_level() > 0) {
349
+					@ob_end_clean();
350
+		}
345 351
 
346 352
 		$fp = fopen($file['filePath'], 'rb');
347 353
 		while (!feof($fp))
@@ -353,8 +359,9 @@  discard block
 block discarded – undo
353 359
 	}
354 360
 
355 361
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
356
-	elseif (@readfile($file['filePath']) === null)
357
-		echo file_get_contents($file['filePath']);
362
+	elseif (@readfile($file['filePath']) === null) {
363
+			echo file_get_contents($file['filePath']);
364
+	}
358 365
 
359 366
 	die();
360 367
 }
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +60 added lines, -47 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
  * Fetches a list of boards and (optional) categories including
@@ -37,11 +38,12 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
47 49
 	$result_boards = $smcFunc['db_query']('', '
@@ -74,10 +76,11 @@  discard block
 block discarded – undo
74 76
 	);
75 77
 
76 78
 	// Start with an empty array.
77
-	if ($boardIndexOptions['include_categories'])
78
-		$categories = array();
79
-	else
80
-		$this_category = array();
79
+	if ($boardIndexOptions['include_categories']) {
80
+			$categories = array();
81
+	} else {
82
+			$this_category = array();
83
+	}
81 84
 	$boards = array();
82 85
 
83 86
 	// Run through the categories and boards (or only boards)....
@@ -88,8 +91,9 @@  discard block
 block discarded – undo
88 91
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
89 92
 
90 93
 		// Add parent boards to the $boards list later used to fetch moderators
91
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
92
-			$boards[] = $row_board['id_board'];
94
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
95
+					$boards[] = $row_board['id_board'];
96
+		}
93 97
 
94 98
 		if ($boardIndexOptions['include_categories'])
95 99
 		{
@@ -111,8 +115,9 @@  discard block
 block discarded – undo
111 115
 			}
112 116
 
113 117
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
114
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
115
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
118
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
119
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
120
+			}
116 121
 
117 122
 			// Avoid showing category unread link where it only has redirection boards.
118 123
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -161,14 +166,12 @@  discard block
 block discarded – undo
161 166
 				{
162 167
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
163 168
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
164
-				}
165
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
169
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
166 170
 				{
167 171
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
168 172
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
169 173
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
170
-				}
171
-				else
174
+				} else
172 175
 				{
173 176
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
174 177
 				}
@@ -219,14 +222,16 @@  discard block
 block discarded – undo
219 222
 		// Child of a child... just add it on...
220 223
 		elseif (!empty($boardIndexOptions['countChildPosts']))
221 224
 		{
222
-			if (!isset($parent_map))
223
-				$parent_map = array();
225
+			if (!isset($parent_map)) {
226
+							$parent_map = array();
227
+			}
224 228
 
225
-			if (!isset($parent_map[$row_board['id_parent']]))
226
-				foreach ($this_category as $id => $board)
229
+			if (!isset($parent_map[$row_board['id_parent']])) {
230
+							foreach ($this_category as $id => $board)
227 231
 				{
228 232
 					if (!isset($board['children'][$row_board['id_parent']]))
229 233
 						continue;
234
+			}
230 235
 
231 236
 					$parent_map[$row_board['id_parent']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
232 237
 					$parent_map[$row_board['id_board']] = array(&$this_category[$id], &$this_category[$id]['children'][$row_board['id_parent']]);
@@ -247,8 +252,9 @@  discard block
 block discarded – undo
247 252
 			continue;
248 253
 		}
249 254
 		// Found a child of a child - skip.
250
-		else
251
-			continue;
255
+		else {
256
+					continue;
257
+		}
252 258
 
253 259
 		// Prepare the subject, and make sure it's not too long.
254 260
 		censorText($row_board['subject']);
@@ -269,12 +275,13 @@  discard block
 block discarded – undo
269 275
 			'topic' => $row_board['id_topic']
270 276
 		);
271 277
 
272
-		if (!empty($settings['avatars_on_boardIndex']))
273
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
278
+		if (!empty($settings['avatars_on_boardIndex'])) {
279
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
274 280
 				'avatar' => $row_board['avatar'],
275 281
 				'email' => $row_board['email_address'],
276 282
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
277 283
 			));
284
+		}
278 285
 
279 286
 		// Provide the href and link.
280 287
 		if ($row_board['subject'] != '')
@@ -286,8 +293,7 @@  discard block
 block discarded – undo
286 293
 			link, href, subject, start (where they should go for the first unread post.),
287 294
 			and member. (which has id, name, link, href, username in it.) */
288 295
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
289
-		}
290
-		else
296
+		} else
291 297
 		{
292 298
 			$this_last_post['href'] = '';
293 299
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -295,8 +301,9 @@  discard block
 block discarded – undo
295 301
 		}
296 302
 
297 303
 		// Set the last post in the parent board.
298
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])))
299
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
304
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && $this_category[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time']))) {
305
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
306
+		}
300 307
 		// Just in the child...?
301 308
 		if ($isChild)
302 309
 		{
@@ -306,15 +313,17 @@  discard block
 block discarded – undo
306 313
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
307 314
 		}
308 315
 		// No last post for this board?  It's not new then, is it..?
309
-		elseif ($row_board['poster_name'] == '')
310
-			$this_category[$row_board['id_board']]['new'] = false;
316
+		elseif ($row_board['poster_name'] == '') {
317
+					$this_category[$row_board['id_board']]['new'] = false;
318
+		}
311 319
 
312 320
 		// Determine a global most recent topic.
313
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
314
-			$latest_post = array(
321
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
322
+					$latest_post = array(
315 323
 				'timestamp' => $row_board['poster_time'],
316 324
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
317 325
 			);
326
+		}
318 327
 	}
319 328
 	$smcFunc['db_free_result']($result_boards);
320 329
 
@@ -331,8 +340,9 @@  discard block
 block discarded – undo
331 340
 				if (!empty($moderators[$board['id']]))
332 341
 				{
333 342
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
334
-					foreach ($moderators[$board['id']] as $moderator)
335
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
343
+					foreach ($moderators[$board['id']] as $moderator) {
344
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
345
+					}
336 346
 				}
337 347
 				if (!empty($groups[$board['id']]))
338 348
 				{
@@ -345,16 +355,16 @@  discard block
 block discarded – undo
345 355
 				}
346 356
 			}
347 357
 		}
348
-	}
349
-	else
358
+	} else
350 359
 	{
351 360
 		foreach ($this_category as $k => $board)
352 361
 		{
353 362
 			if (!empty($moderators[$board['id']]))
354 363
 			{
355 364
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
356
-				foreach ($moderators[$board['id']] as $moderator)
357
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
365
+				foreach ($moderators[$board['id']] as $moderator) {
366
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
367
+				}
358 368
 			}
359 369
 			if (!empty($groups[$board['id']]))
360 370
 			{
@@ -368,20 +378,23 @@  discard block
 block discarded – undo
368 378
 		}
369 379
 	}
370 380
 
371
-	if ($boardIndexOptions['include_categories'])
372
-		sortCategories($categories);
373
-	else
374
-		sortBoards($this_category);
381
+	if ($boardIndexOptions['include_categories']) {
382
+			sortCategories($categories);
383
+	} else {
384
+			sortBoards($this_category);
385
+	}
375 386
 
376 387
 	// By now we should know the most recent post...if we wanna know it that is.
377
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
378
-		$context['latest_post'] = $latest_post['ref'];
388
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
389
+			$context['latest_post'] = $latest_post['ref'];
390
+	}
379 391
 
380 392
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
381
-	if ($boardIndexOptions['include_categories'])
382
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
383
-	else
384
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
393
+	if ($boardIndexOptions['include_categories']) {
394
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
395
+	} else {
396
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
397
+	}
385 398
 
386 399
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
387 400
 }
Please login to merge, or discard this patch.
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 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
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => $smcFunc['json_encode'](array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'](), '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.
Sources/DbExtra-mysql.php 1 patch
Braces   +66 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -32,7 +33,8 @@  discard block
 block discarded – undo
32 33
 			'db_get_version' => 'smf_db_get_version',
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 		);
35
-}
36
+	}
37
+	}
36 38
 
37 39
 /**
38 40
  * Backup $table to $backup_table.
@@ -74,8 +76,9 @@  discard block
 block discarded – undo
74 76
 			));
75 77
 
76 78
 		// Old school or no school?
77
-		if ($request)
78
-			return $request;
79
+		if ($request) {
80
+					return $request;
81
+		}
79 82
 	}
80 83
 
81 84
 	// At this point, the quick method failed.
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	foreach ($create as $k => $l)
100 103
 	{
101 104
 		// Get the name of the auto_increment column.
102
-		if (strpos($l, 'auto_increment'))
103
-			$auto_inc = trim($l);
105
+		if (strpos($l, 'auto_increment')) {
106
+					$auto_inc = trim($l);
107
+		}
104 108
 
105 109
 		// For the engine type, see if we can work out what it is.
106 110
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -108,30 +112,36 @@  discard block
 block discarded – undo
108 112
 			// Extract the engine type.
109 113
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
110 114
 
111
-			if (!empty($match[1]))
112
-				$engine = $match[1];
115
+			if (!empty($match[1])) {
116
+							$engine = $match[1];
117
+			}
113 118
 
114
-			if (!empty($match[2]))
115
-				$engine = $match[2];
119
+			if (!empty($match[2])) {
120
+							$engine = $match[2];
121
+			}
116 122
 
117
-			if (!empty($match[5]))
118
-				$charset = $match[5];
123
+			if (!empty($match[5])) {
124
+							$charset = $match[5];
125
+			}
119 126
 
120
-			if (!empty($match[7]))
121
-				$collate = $match[7];
127
+			if (!empty($match[7])) {
128
+							$collate = $match[7];
129
+			}
122 130
 		}
123 131
 
124 132
 		// Skip everything but keys...
125
-		if (strpos($l, 'KEY') === false)
126
-			unset($create[$k]);
133
+		if (strpos($l, 'KEY') === false) {
134
+					unset($create[$k]);
135
+		}
127 136
 	}
128 137
 
129
-	if (!empty($create))
130
-		$create = '(
138
+	if (!empty($create)) {
139
+			$create = '(
131 140
 			' . implode('
132 141
 			', $create) . ')';
133
-	else
134
-		$create = '';
142
+	} else {
143
+			$create = '';
144
+	}
135 145
 
136 146
 	$request = $smcFunc['db_query']('', '
137 147
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -150,8 +160,9 @@  discard block
 block discarded – undo
150 160
 
151 161
 	if ($auto_inc != '')
152 162
 	{
153
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
154
-			$auto_inc = substr($auto_inc, 0, -1);
163
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
164
+					$auto_inc = substr($auto_inc, 0, -1);
165
+		}
155 166
 
156 167
 		$smcFunc['db_query']('', '
157 168
 			ALTER TABLE {raw:backup_table}
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 				'table' => $table,
196 207
 			)
197 208
 		);
198
-	if (!$request)
199
-		return -1;
209
+	if (!$request) {
210
+			return -1;
211
+	}
200 212
 
201 213
 	// How much left?
202 214
 	$request = $smcFunc['db_query']('', '
@@ -239,8 +251,9 @@  discard block
 block discarded – undo
239 251
 		)
240 252
 	);
241 253
 	$tables = array();
242
-	while ($row = $smcFunc['db_fetch_row']($request))
243
-		$tables[] = $row[0];
254
+	while ($row = $smcFunc['db_fetch_row']($request)) {
255
+			$tables[] = $row[0];
256
+	}
244 257
 	$smcFunc['db_free_result']($request);
245 258
 
246 259
 	return $tables;
@@ -284,8 +297,9 @@  discard block
 block discarded – undo
284 297
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
285 298
 		{
286 299
 			// Make a special case of auto-timestamp.
287
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
288
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
300
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
301
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
302
+			}
289 303
 			// Text shouldn't have a default.
290 304
 			elseif ($row['Default'] !== null)
291 305
 			{
@@ -320,14 +334,16 @@  discard block
 block discarded – undo
320 334
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
321 335
 
322 336
 		// Is this the first column in the index?
323
-		if (empty($indexes[$row['Key_name']]))
324
-			$indexes[$row['Key_name']] = array();
337
+		if (empty($indexes[$row['Key_name']])) {
338
+					$indexes[$row['Key_name']] = array();
339
+		}
325 340
 
326 341
 		// A sub part, like only indexing 15 characters of a varchar.
327
-		if (!empty($row['Sub_part']))
328
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
329
-		else
330
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
342
+		if (!empty($row['Sub_part'])) {
343
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
344
+		} else {
345
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
346
+		}
331 347
 	}
332 348
 	$smcFunc['db_free_result']($result);
333 349
 
@@ -365,8 +381,9 @@  discard block
 block discarded – undo
365 381
 {
366 382
 	static $ver;
367 383
 
368
-	if (!empty($ver))
369
-		return $ver;
384
+	if (!empty($ver)) {
385
+			return $ver;
386
+	}
370 387
 
371 388
 	global $smcFunc;
372 389
 
@@ -391,8 +408,9 @@  discard block
 block discarded – undo
391 408
 	global $smcFunc;
392 409
 	static $db_type;
393 410
 
394
-	if (!empty($db_type))
395
-		return $db_type;
411
+	if (!empty($db_type)) {
412
+			return $db_type;
413
+	}
396 414
 
397 415
 	$request = $smcFunc['db_query']('', 
398 416
 				'SELECT VARIABLE_VALUE
@@ -408,13 +426,15 @@  discard block
 block discarded – undo
408 426
 	// Skip these if we don't have a comment.
409 427
 	if (!empty($comment))
410 428
 	{
411
-		if (stripos($comment, 'percona') !== false)
412
-			return 'Percona';
413
-		if (stripos($comment, 'mariadb') !== false)
414
-			return 'MariaDB';
429
+		if (stripos($comment, 'percona') !== false) {
430
+					return 'Percona';
431
+		}
432
+		if (stripos($comment, 'mariadb') !== false) {
433
+					return 'MariaDB';
434
+		}
435
+	} else {
436
+			return 'fail';
415 437
 	}
416
-	else
417
-		return 'fail';
418 438
 
419 439
 	return 'MySQL';
420 440
 }
Please login to merge, or discard this patch.
cron.php 1 patch
Braces   +36 added lines, -28 removed lines patch added patch discarded remove patch
@@ -41,37 +41,43 @@  discard block
 block discarded – undo
41 41
 define('TIME_START', microtime(true));
42 42
 
43 43
 // Just being safe...
44
-foreach (array('db_character_set', 'cachedir') as $variable)
44
+foreach (array('db_character_set', 'cachedir') as $variable) {
45 45
 	if (isset($GLOBALS[$variable]))
46 46
 		unset($GLOBALS[$variable]);
47
+}
47 48
 
48 49
 // Get the forum's settings for database and file paths.
49 50
 require_once(dirname(__FILE__) . '/Settings.php');
50 51
 
51 52
 // Make absolutely sure the cache directory is defined.
52
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
53
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
53 54
 	$cachedir = $boarddir . '/cache';
55
+}
54 56
 
55 57
 // Don't do john didley if the forum's been shut down competely.
56
-if ($maintenance == 2)
58
+if ($maintenance == 2) {
57 59
 	die($mmessage);
60
+}
58 61
 
59 62
 // Fix for using the current directory as a path.
60
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
63
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
61 64
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
65
+}
62 66
 
63 67
 // Have we already turned this off? If so, exist gracefully.
64
-if (file_exists($cachedir . '/cron.lock'))
68
+if (file_exists($cachedir . '/cron.lock')) {
65 69
 	obExit_cron();
70
+}
66 71
 
67 72
 // Before we go any further, if this is not a CLI request, we need to do some checking.
68 73
 if (!FROM_CLI)
69 74
 {
70 75
 	// We will clean up $_GET shortly. But we want to this ASAP.
71 76
 	$ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0;
72
-	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20)
73
-		obExit_cron();
74
-}
77
+	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) {
78
+			obExit_cron();
79
+	}
80
+	}
75 81
 
76 82
 // Load the most important includes. In general, a background should be loading its own dependencies.
77 83
 require_once($sourcedir . '/Errors.php');
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
 	global $smcFunc;
124 130
 
125 131
 	// Check we haven't run over our time limit.
126
-	if (microtime(true) - TIME_START > MAX_CRON_TIME)
127
-		return false;
132
+	if (microtime(true) - TIME_START > MAX_CRON_TIME) {
133
+			return false;
134
+	}
128 135
 
129 136
 	// Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that,
130 137
 	// a task that was claimed but failed for whatever reason and failed long enough ago. We should not care
@@ -159,14 +166,12 @@  discard block
 block discarded – undo
159 166
 			// Update the time and go back.
160 167
 			$row['claimed_time'] = time();
161 168
 			return $row;
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any.
166 172
 			return fetch_task();
167 173
 		}
168
-	}
169
-	else
174
+	} else
170 175
 	{
171 176
 		// No dice. Clean up and go home.
172 177
 		$smcFunc['db_free_result']($request);
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	if (!empty($task_details['task_file']))
188 193
 	{
189 194
 		$include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
190
-		if (file_exists($include))
191
-			require_once($include);
195
+		if (file_exists($include)) {
196
+					require_once($include);
197
+		}
192 198
 	}
193 199
 
194 200
 	if (empty($task_details['task_class']))
@@ -204,8 +210,7 @@  discard block
 block discarded – undo
204 210
 		$details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true);
205 211
 		$bgtask = new $task_details['task_class']($details);
206 212
 		return $bgtask->execute();
207
-	}
208
-	else
213
+	} else
209 214
 	{
210 215
 		log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')');
211 216
 		return true; // So we clear it from the queue.
@@ -224,8 +229,9 @@  discard block
 block discarded – undo
224 229
 	$scripturl = $boardurl . '/index.php';
225 230
 
226 231
 	// These keys shouldn't be set...ever.
227
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
228
-		die('Invalid request variable.');
232
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
233
+			die('Invalid request variable.');
234
+	}
229 235
 
230 236
 	// Save some memory.. (since we don't use these anyway.)
231 237
 	unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']);
@@ -246,26 +252,28 @@  discard block
 block discarded – undo
246 252
 	global $modSettings;
247 253
 
248 254
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
249
-	if (error_reporting() == 0)
250
-		return;
255
+	if (error_reporting() == 0) {
256
+			return;
257
+	}
251 258
 
252 259
 	$error_type = 'cron';
253 260
 
254 261
 	log_error($error_level . ': ' . $error_string, $error_type, $file, $line);
255 262
 
256 263
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
257
-	if ($error_level % 255 == E_ERROR)
258
-		die('No direct access...');
259
-}
264
+	if ($error_level % 255 == E_ERROR) {
265
+			die('No direct access...');
266
+	}
267
+	}
260 268
 
261 269
 /**
262 270
  * The exit function
263 271
  */
264 272
 function obExit_cron()
265 273
 {
266
-	if (FROM_CLI)
267
-		die(0);
268
-	else
274
+	if (FROM_CLI) {
275
+			die(0);
276
+	} else
269 277
 	{
270 278
 		header('Content-Type: image/gif');
271 279
 		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");
Please login to merge, or discard this patch.