Passed
Push — 1.7 ( 3d00e4...1c891b )
by Greg
07:29
created
includes/session.php 1 patch
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
 
26 26
 // WT_SCRIPT_NAME is defined in each script that the user is permitted to load.
27 27
 if (!defined('WT_SCRIPT_NAME')) {
28
-	http_response_code(403);
28
+    http_response_code(403);
29 29
 
30
-	return;
30
+    return;
31 31
 }
32 32
 
33 33
 /**
@@ -50,41 +50,41 @@  discard block
 block discarded – undo
50 50
 define('WT_STATIC_URL', getenv('STATIC_URL')); // We could set this to load our own static resources from a cookie-free domain.
51 51
 
52 52
 if (getenv('USE_CDN')) {
53
-	// Caution, using a CDN will break support for responsive features in IE8, as respond.js
54
-	// needs to be on the same domain as all the CSS files.
55
-	define('WT_BOOTSTRAP_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css');
56
-	define('WT_BOOTSTRAP_DATETIMEPICKER_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css');
57
-	define('WT_BOOTSTRAP_DATETIMEPICKER_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js');
58
-	define('WT_BOOTSTRAP_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js');
59
-	define('WT_BOOTSTRAP_RTL_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.2.0-rc2/css/bootstrap-rtl.min.css'); // Cloudflare is out of date
60
-	//define('WT_DATATABLES_BOOTSTRAP_CSS_URL', '//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css');
61
-	define('WT_DATATABLES_BOOTSTRAP_JS_URL', '//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.js');
62
-	define('WT_FONT_AWESOME_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css');
63
-	define('WT_JQUERYUI_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js');
64
-	define('WT_JQUERYUI_TOUCH_PUNCH_URL', '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js');
65
-	define('WT_JQUERY_DATATABLES_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.min.js');
66
-	define('WT_JQUERY_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js');
67
-	define('WT_JQUERY2_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js');
68
-	define('WT_MODERNIZR_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js');
69
-	define('WT_MOMENT_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment-with-locales.min.js');
70
-	define('WT_RESPOND_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js');
53
+    // Caution, using a CDN will break support for responsive features in IE8, as respond.js
54
+    // needs to be on the same domain as all the CSS files.
55
+    define('WT_BOOTSTRAP_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css');
56
+    define('WT_BOOTSTRAP_DATETIMEPICKER_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css');
57
+    define('WT_BOOTSTRAP_DATETIMEPICKER_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js');
58
+    define('WT_BOOTSTRAP_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js');
59
+    define('WT_BOOTSTRAP_RTL_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.2.0-rc2/css/bootstrap-rtl.min.css'); // Cloudflare is out of date
60
+    //define('WT_DATATABLES_BOOTSTRAP_CSS_URL', '//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css');
61
+    define('WT_DATATABLES_BOOTSTRAP_JS_URL', '//cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.js');
62
+    define('WT_FONT_AWESOME_CSS_URL', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css');
63
+    define('WT_JQUERYUI_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js');
64
+    define('WT_JQUERYUI_TOUCH_PUNCH_URL', '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js');
65
+    define('WT_JQUERY_DATATABLES_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.min.js');
66
+    define('WT_JQUERY_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js');
67
+    define('WT_JQUERY2_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js');
68
+    define('WT_MODERNIZR_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js');
69
+    define('WT_MOMENT_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment-with-locales.min.js');
70
+    define('WT_RESPOND_JS_URL', '//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js');
71 71
 } else {
72
-	define('WT_BOOTSTRAP_CSS_URL', WT_STATIC_URL . 'packages/bootstrap-3.3.6/css/bootstrap.min.css');
73
-	define('WT_BOOTSTRAP_DATETIMEPICKER_CSS_URL', WT_STATIC_URL . 'packages/bootstrap-datetimepicker-4.17.37/css/bootstrap-datetimepicker.min.css');
74
-	define('WT_BOOTSTRAP_DATETIMEPICKER_JS_URL', WT_STATIC_URL . 'packages/bootstrap-datetimepicker-4.17.37/js/bootstrap-datetimepicker.min.js');
75
-	define('WT_BOOTSTRAP_JS_URL', WT_STATIC_URL . 'packages/bootstrap-3.3.6/js/bootstrap.min.js');
76
-	define('WT_BOOTSTRAP_RTL_CSS_URL', WT_STATIC_URL . 'packages/bootstrap-rtl-3.3.4/css/bootstrap-rtl.min.css');
77
-	//define('WT_DATATABLES_BOOTSTRAP_CSS_URL', WT_STATIC_URL . 'packages/datatables-1.10.7/plugins/dataTables.bootstrap.css');
78
-	define('WT_DATATABLES_BOOTSTRAP_JS_URL', WT_STATIC_URL . 'packages/datatables-1.10.7/plugins/dataTables.bootstrap.js');
79
-	define('WT_FONT_AWESOME_CSS_URL', WT_STATIC_URL . 'packages/font-awesome-4.4.0/css/font-awesome.min.css');
80
-	define('WT_JQUERYUI_JS_URL', WT_STATIC_URL . 'packages/jquery-ui-1.11.4/js/jquery-ui.min.js');
81
-	define('WT_JQUERYUI_TOUCH_PUNCH_URL', WT_STATIC_URL . 'packages/jqueryui-touch-punch-0.2.3/jquery.ui.touch-punch.min.js');
82
-	define('WT_JQUERY_DATATABLES_JS_URL', WT_STATIC_URL . 'packages/datatables-1.10.7/js/jquery.dataTables.min.js');
83
-	define('WT_JQUERY_JS_URL', WT_STATIC_URL . 'packages/jquery-1.12.1/jquery.min.js');
84
-	define('WT_JQUERY2_JS_URL', WT_STATIC_URL . 'packages/jquery-2.2.1/jquery.min.js');
85
-	define('WT_MODERNIZR_JS_URL', WT_STATIC_URL . 'packages/modernizr-2.8.3/modernizr.min.js');
86
-	define('WT_MOMENT_JS_URL', WT_STATIC_URL . 'packages/moment-2.11.2/moment-with-locales.min.js');
87
-	define('WT_RESPOND_JS_URL', WT_STATIC_URL . 'packages/respond-1.4.2/respond.min.js');
72
+    define('WT_BOOTSTRAP_CSS_URL', WT_STATIC_URL . 'packages/bootstrap-3.3.6/css/bootstrap.min.css');
73
+    define('WT_BOOTSTRAP_DATETIMEPICKER_CSS_URL', WT_STATIC_URL . 'packages/bootstrap-datetimepicker-4.17.37/css/bootstrap-datetimepicker.min.css');
74
+    define('WT_BOOTSTRAP_DATETIMEPICKER_JS_URL', WT_STATIC_URL . 'packages/bootstrap-datetimepicker-4.17.37/js/bootstrap-datetimepicker.min.js');
75
+    define('WT_BOOTSTRAP_JS_URL', WT_STATIC_URL . 'packages/bootstrap-3.3.6/js/bootstrap.min.js');
76
+    define('WT_BOOTSTRAP_RTL_CSS_URL', WT_STATIC_URL . 'packages/bootstrap-rtl-3.3.4/css/bootstrap-rtl.min.css');
77
+    //define('WT_DATATABLES_BOOTSTRAP_CSS_URL', WT_STATIC_URL . 'packages/datatables-1.10.7/plugins/dataTables.bootstrap.css');
78
+    define('WT_DATATABLES_BOOTSTRAP_JS_URL', WT_STATIC_URL . 'packages/datatables-1.10.7/plugins/dataTables.bootstrap.js');
79
+    define('WT_FONT_AWESOME_CSS_URL', WT_STATIC_URL . 'packages/font-awesome-4.4.0/css/font-awesome.min.css');
80
+    define('WT_JQUERYUI_JS_URL', WT_STATIC_URL . 'packages/jquery-ui-1.11.4/js/jquery-ui.min.js');
81
+    define('WT_JQUERYUI_TOUCH_PUNCH_URL', WT_STATIC_URL . 'packages/jqueryui-touch-punch-0.2.3/jquery.ui.touch-punch.min.js');
82
+    define('WT_JQUERY_DATATABLES_JS_URL', WT_STATIC_URL . 'packages/datatables-1.10.7/js/jquery.dataTables.min.js');
83
+    define('WT_JQUERY_JS_URL', WT_STATIC_URL . 'packages/jquery-1.12.1/jquery.min.js');
84
+    define('WT_JQUERY2_JS_URL', WT_STATIC_URL . 'packages/jquery-2.2.1/jquery.min.js');
85
+    define('WT_MODERNIZR_JS_URL', WT_STATIC_URL . 'packages/modernizr-2.8.3/modernizr.min.js');
86
+    define('WT_MOMENT_JS_URL', WT_STATIC_URL . 'packages/moment-2.11.2/moment-with-locales.min.js');
87
+    define('WT_RESPOND_JS_URL', WT_STATIC_URL . 'packages/respond-1.4.2/respond.min.js');
88 88
 }
89 89
 
90 90
 // We can't load these from a CDN, as these have been patched.
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 
177 177
 // Ignore the default port.
178 178
 if ($protocol === 'http' && $port === '80' || $protocol === 'https' && $port === '443') {
179
-	$port = '';
179
+    $port = '';
180 180
 } else {
181
-	$port = ':' . $port;
181
+    $port = ':' . $port;
182 182
 }
183 183
 
184 184
 // REDIRECT_URL should be set when Apache is following a RedirectRule
@@ -197,98 +197,98 @@  discard block
 block discarded – undo
197 197
 });
198 198
 
199 199
 set_exception_handler(function ($ex) {
200
-	$message = $ex->getFile() . ':' . $ex->getLine() . ' ' . $ex->getMessage() . PHP_EOL;
201
-
202
-	foreach ($ex->getTrace() as $level => $frame) {
203
-		$frame += array('args' => array(), 'file' => 'unknown', 'line' => 'unknown');
204
-		array_walk($frame['args'], function (&$arg) {
205
-			switch (gettype($arg)) {
206
-			case 'boolean':
207
-			case 'integer':
208
-			case 'double':
209
-			case 'null':
210
-				$arg = var_export($arg, true);
211
-				break;
212
-			case 'string':
213
-				if (mb_strlen($arg) > 30) {
214
-					$arg = substr($arg, 0, 30) . '…';
215
-				}
216
-				$arg = var_export($arg, true);
217
-				break;
218
-			case 'object':
219
-				$reflection = new \ReflectionClass($arg);
220
-				if (is_object($arg) && method_exists($arg, '__toString')) {
221
-					$arg = '[' . $reflection->getShortName() . ' ' . (string) $arg . ']';
222
-				} else {
223
-					$arg = '[' . $reflection->getShortName() . ']';
224
-				}
225
-				break;
226
-			default:
227
-				$arg = '[' . gettype($arg) . ']';
228
-				break;
229
-			}
230
-		});
231
-		$frame['file'] = str_replace(dirname(__DIR__), '', $frame['file']);
232
-		$message .= '#' . $level . ' ' . $frame['file'] . ':' . $frame['line'] . ' ';
233
-		if ($level) {
234
-			$message .= $frame['function'] . '(' . implode(', ', $frame['args']) . ')' . PHP_EOL;
235
-		} else {
236
-			$message .= get_class($ex) . '("' . $ex->getMessage() . '")' . PHP_EOL;
237
-		}
238
-	}
239
-
240
-	if (error_reporting() & $ex->getCode()) {
241
-		echo $message;
242
-	}
243
-
244
-	Log::addErrorLog($message);
200
+    $message = $ex->getFile() . ':' . $ex->getLine() . ' ' . $ex->getMessage() . PHP_EOL;
201
+
202
+    foreach ($ex->getTrace() as $level => $frame) {
203
+        $frame += array('args' => array(), 'file' => 'unknown', 'line' => 'unknown');
204
+        array_walk($frame['args'], function (&$arg) {
205
+            switch (gettype($arg)) {
206
+            case 'boolean':
207
+            case 'integer':
208
+            case 'double':
209
+            case 'null':
210
+                $arg = var_export($arg, true);
211
+                break;
212
+            case 'string':
213
+                if (mb_strlen($arg) > 30) {
214
+                    $arg = substr($arg, 0, 30) . '…';
215
+                }
216
+                $arg = var_export($arg, true);
217
+                break;
218
+            case 'object':
219
+                $reflection = new \ReflectionClass($arg);
220
+                if (is_object($arg) && method_exists($arg, '__toString')) {
221
+                    $arg = '[' . $reflection->getShortName() . ' ' . (string) $arg . ']';
222
+                } else {
223
+                    $arg = '[' . $reflection->getShortName() . ']';
224
+                }
225
+                break;
226
+            default:
227
+                $arg = '[' . gettype($arg) . ']';
228
+                break;
229
+            }
230
+        });
231
+        $frame['file'] = str_replace(dirname(__DIR__), '', $frame['file']);
232
+        $message .= '#' . $level . ' ' . $frame['file'] . ':' . $frame['line'] . ' ';
233
+        if ($level) {
234
+            $message .= $frame['function'] . '(' . implode(', ', $frame['args']) . ')' . PHP_EOL;
235
+        } else {
236
+            $message .= get_class($ex) . '("' . $ex->getMessage() . '")' . PHP_EOL;
237
+        }
238
+    }
239
+
240
+    if (error_reporting() & $ex->getCode()) {
241
+        echo $message;
242
+    }
243
+
244
+    Log::addErrorLog($message);
245 245
 });
246 246
 
247 247
 // Load our configuration file, so we can connect to the database
248 248
 if (file_exists(WT_ROOT . 'data/config.ini.php')) {
249
-	$dbconfig = parse_ini_file(WT_ROOT . 'data/config.ini.php');
250
-	// Invalid/unreadable config file?
251
-	if (!is_array($dbconfig)) {
252
-		header('Location: ' . WT_BASE_URL . 'site-unavailable.php');
253
-		exit;
254
-	}
255
-	// Down for maintenance?
256
-	if (file_exists(WT_ROOT . 'data/offline.txt')) {
257
-		header('Location: ' . WT_BASE_URL . 'site-offline.php');
258
-		exit;
259
-	}
249
+    $dbconfig = parse_ini_file(WT_ROOT . 'data/config.ini.php');
250
+    // Invalid/unreadable config file?
251
+    if (!is_array($dbconfig)) {
252
+        header('Location: ' . WT_BASE_URL . 'site-unavailable.php');
253
+        exit;
254
+    }
255
+    // Down for maintenance?
256
+    if (file_exists(WT_ROOT . 'data/offline.txt')) {
257
+        header('Location: ' . WT_BASE_URL . 'site-offline.php');
258
+        exit;
259
+    }
260 260
 } else {
261
-	// No config file. Set one up.
262
-	header('Location: ' . WT_BASE_URL . 'setup.php');
263
-	exit;
261
+    // No config file. Set one up.
262
+    header('Location: ' . WT_BASE_URL . 'setup.php');
263
+    exit;
264 264
 }
265 265
 
266 266
 // What is the remote client's IP address
267 267
 if (Filter::server('HTTP_CLIENT_IP') !== null) {
268
-	define('WT_CLIENT_IP', Filter::server('HTTP_CLIENT_IP'));
268
+    define('WT_CLIENT_IP', Filter::server('HTTP_CLIENT_IP'));
269 269
 } elseif (Filter::server('HTTP_X_FORWARDED_FOR') !== null) {
270
-	define('WT_CLIENT_IP', Filter::server('HTTP_X_FORWARDED_FOR'));
270
+    define('WT_CLIENT_IP', Filter::server('HTTP_X_FORWARDED_FOR'));
271 271
 } else {
272
-	define('WT_CLIENT_IP', Filter::server('REMOTE_ADDR', WT_REGEX_IPV4, '127.0.0.1'));
272
+    define('WT_CLIENT_IP', Filter::server('REMOTE_ADDR', WT_REGEX_IPV4, '127.0.0.1'));
273 273
 }
274 274
 
275 275
 // Connect to the database
276 276
 try {
277
-	Database::createInstance($dbconfig['dbhost'], $dbconfig['dbport'], $dbconfig['dbname'], $dbconfig['dbuser'], $dbconfig['dbpass']);
278
-	define('WT_TBLPREFIX', $dbconfig['tblpfx']);
279
-	unset($dbconfig);
280
-	// Some of the FAMILY JOIN HUSBAND JOIN WIFE queries can excede the MAX_JOIN_SIZE setting
281
-	Database::exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci', SQL_BIG_SELECTS=1");
282
-	// Update the database schema
283
-	$updated = Database::updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION);
284
-	if ($updated) {
285
-		// updateSchema() might load custom modules - which we cannot load again.
286
-		header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''));
287
-		exit;
288
-	}
277
+    Database::createInstance($dbconfig['dbhost'], $dbconfig['dbport'], $dbconfig['dbname'], $dbconfig['dbuser'], $dbconfig['dbpass']);
278
+    define('WT_TBLPREFIX', $dbconfig['tblpfx']);
279
+    unset($dbconfig);
280
+    // Some of the FAMILY JOIN HUSBAND JOIN WIFE queries can excede the MAX_JOIN_SIZE setting
281
+    Database::exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci', SQL_BIG_SELECTS=1");
282
+    // Update the database schema
283
+    $updated = Database::updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION);
284
+    if ($updated) {
285
+        // updateSchema() might load custom modules - which we cannot load again.
286
+        header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''));
287
+        exit;
288
+    }
289 289
 } catch (PDOException $ex) {
290
-	header('Location: ' . WT_BASE_URL . 'site-unavailable.php?message=' . rawurlencode($ex->getMessage()));
291
-	exit;
290
+    header('Location: ' . WT_BASE_URL . 'site-unavailable.php?message=' . rawurlencode($ex->getMessage()));
291
+    exit;
292 292
 }
293 293
 
294 294
 // The config.ini.php file must always be in a fixed location.
@@ -298,120 +298,120 @@  discard block
 block discarded – undo
298 298
 // If we have a preferred URL (e.g. www.example.com instead of www.isp.com/~example), then redirect to it.
299 299
 $SERVER_URL = Site::getPreference('SERVER_URL');
300 300
 if ($SERVER_URL && $SERVER_URL != WT_BASE_URL) {
301
-	header('Location: ' . $SERVER_URL . WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''), true, 301);
302
-	exit;
301
+    header('Location: ' . $SERVER_URL . WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : ''), true, 301);
302
+    exit;
303 303
 }
304 304
 
305 305
 // Request more resources - if we can/want to
306 306
 if (!ini_get('safe_mode')) {
307
-	$memory_limit = Site::getPreference('MEMORY_LIMIT');
308
-	if ($memory_limit && strpos(ini_get('disable_functions'), 'ini_set') === false) {
309
-		ini_set('memory_limit', $memory_limit);
310
-	}
311
-	$max_execution_time = Site::getPreference('MAX_EXECUTION_TIME');
312
-	if ($max_execution_time && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
313
-		set_time_limit($max_execution_time);
314
-	}
307
+    $memory_limit = Site::getPreference('MEMORY_LIMIT');
308
+    if ($memory_limit && strpos(ini_get('disable_functions'), 'ini_set') === false) {
309
+        ini_set('memory_limit', $memory_limit);
310
+    }
311
+    $max_execution_time = Site::getPreference('MAX_EXECUTION_TIME');
312
+    if ($max_execution_time && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
313
+        set_time_limit($max_execution_time);
314
+    }
315 315
 }
316 316
 
317 317
 $rule = Database::prepare(
318
-	"SELECT rule FROM `##site_access_rule`" .
319
-	" WHERE IFNULL(INET_ATON(?), 0) BETWEEN ip_address_start AND ip_address_end" .
320
-	" AND ? LIKE user_agent_pattern" .
321
-	" ORDER BY ip_address_end LIMIT 1"
318
+    "SELECT rule FROM `##site_access_rule`" .
319
+    " WHERE IFNULL(INET_ATON(?), 0) BETWEEN ip_address_start AND ip_address_end" .
320
+    " AND ? LIKE user_agent_pattern" .
321
+    " ORDER BY ip_address_end LIMIT 1"
322 322
 )->execute(array(WT_CLIENT_IP, Filter::server('HTTP_USER_AGENT', null, '')))->fetchOne();
323 323
 
324 324
 switch ($rule) {
325 325
 case 'allow':
326
-	$SEARCH_SPIDER = false;
327
-	break;
326
+    $SEARCH_SPIDER = false;
327
+    break;
328 328
 case 'deny':
329
-	http_response_code(403);
330
-	exit;
329
+    http_response_code(403);
330
+    exit;
331 331
 case 'robot':
332 332
 case 'unknown':
333
-	// Search engines don’t send cookies, and so create a new session with every visit.
334
-	// Make sure they always use the same one
335
-	Session::setId('search-engine-' . str_replace('.', '-', WT_CLIENT_IP));
336
-	$SEARCH_SPIDER = true;
337
-	break;
333
+    // Search engines don’t send cookies, and so create a new session with every visit.
334
+    // Make sure they always use the same one
335
+    Session::setId('search-engine-' . str_replace('.', '-', WT_CLIENT_IP));
336
+    $SEARCH_SPIDER = true;
337
+    break;
338 338
 case '':
339
-	Database::prepare(
340
-		"INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, comment) VALUES (IFNULL(INET_ATON(?), 0), IFNULL(INET_ATON(?), 4294967295), ?, '')"
341
-	)->execute(array(WT_CLIENT_IP, WT_CLIENT_IP, Filter::server('HTTP_USER_AGENT', null, '')));
342
-	$SEARCH_SPIDER = true;
343
-	break;
339
+    Database::prepare(
340
+        "INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, comment) VALUES (IFNULL(INET_ATON(?), 0), IFNULL(INET_ATON(?), 4294967295), ?, '')"
341
+    )->execute(array(WT_CLIENT_IP, WT_CLIENT_IP, Filter::server('HTTP_USER_AGENT', null, '')));
342
+    $SEARCH_SPIDER = true;
343
+    break;
344 344
 }
345 345
 
346 346
 // Store our session data in the database.
347 347
 session_set_save_handler(
348
-	// open
349
-	function () {
350
-		return true;
351
-	},
352
-	// close
353
-	function () {
354
-		return true;
355
-	},
356
-	// read
357
-	function ($id) {
358
-		return (string) Database::prepare("SELECT session_data FROM `##session` WHERE session_id=?")->execute(array($id))->fetchOne();
359
-	},
360
-	// write
361
-	function ($id, $data) {
362
-		// Only update the session table once per minute, unless the session data has actually changed.
363
-		Database::prepare(
364
-			"INSERT INTO `##session` (session_id, user_id, ip_address, session_data, session_time)" .
365
-			" VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP))" .
366
-			" ON DUPLICATE KEY UPDATE" .
367
-			" user_id      = VALUES(user_id)," .
368
-			" ip_address   = VALUES(ip_address)," .
369
-			" session_data = VALUES(session_data)," .
370
-			" session_time = CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP)"
371
-		)->execute(array($id, (int) Auth::id(), WT_CLIENT_IP, $data));
372
-
373
-		return true;
374
-	},
375
-	// destroy
376
-	function ($id) {
377
-		Database::prepare("DELETE FROM `##session` WHERE session_id=?")->execute(array($id));
378
-
379
-		return true;
380
-	},
381
-	// gc
382
-	function ($maxlifetime) {
383
-		Database::prepare("DELETE FROM `##session` WHERE session_time < DATE_SUB(NOW(), INTERVAL ? SECOND)")->execute(array($maxlifetime));
384
-
385
-		return true;
386
-	}
348
+    // open
349
+    function () {
350
+        return true;
351
+    },
352
+    // close
353
+    function () {
354
+        return true;
355
+    },
356
+    // read
357
+    function ($id) {
358
+        return (string) Database::prepare("SELECT session_data FROM `##session` WHERE session_id=?")->execute(array($id))->fetchOne();
359
+    },
360
+    // write
361
+    function ($id, $data) {
362
+        // Only update the session table once per minute, unless the session data has actually changed.
363
+        Database::prepare(
364
+            "INSERT INTO `##session` (session_id, user_id, ip_address, session_data, session_time)" .
365
+            " VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP))" .
366
+            " ON DUPLICATE KEY UPDATE" .
367
+            " user_id      = VALUES(user_id)," .
368
+            " ip_address   = VALUES(ip_address)," .
369
+            " session_data = VALUES(session_data)," .
370
+            " session_time = CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP)"
371
+        )->execute(array($id, (int) Auth::id(), WT_CLIENT_IP, $data));
372
+
373
+        return true;
374
+    },
375
+    // destroy
376
+    function ($id) {
377
+        Database::prepare("DELETE FROM `##session` WHERE session_id=?")->execute(array($id));
378
+
379
+        return true;
380
+    },
381
+    // gc
382
+    function ($maxlifetime) {
383
+        Database::prepare("DELETE FROM `##session` WHERE session_time < DATE_SUB(NOW(), INTERVAL ? SECOND)")->execute(array($maxlifetime));
384
+
385
+        return true;
386
+    }
387 387
 );
388 388
 
389 389
 Session::start(array(
390
-	'gc_maxlifetime' => Site::getPreference('SESSION_TIME'),
391
-	'cookie_path'    => implode('/', array_map('rawurlencode', explode('/', parse_url(WT_BASE_URL, PHP_URL_PATH)))),
390
+    'gc_maxlifetime' => Site::getPreference('SESSION_TIME'),
391
+    'cookie_path'    => implode('/', array_map('rawurlencode', explode('/', parse_url(WT_BASE_URL, PHP_URL_PATH)))),
392 392
 ));
393 393
 
394 394
 if (!Auth::isSearchEngine() && !Session::get('initiated')) {
395
-	// A new session, so prevent session fixation attacks by choosing a new PHPSESSID.
396
-	Session::regenerate(true);
397
-	Session::put('initiated', true);
395
+    // A new session, so prevent session fixation attacks by choosing a new PHPSESSID.
396
+    Session::regenerate(true);
397
+    Session::put('initiated', true);
398 398
 } else {
399
-	// An existing session
399
+    // An existing session
400 400
 }
401 401
 
402 402
 // Set the tree for the page; (1) the request, (2) the session, (3) the site default, (4) any tree
403 403
 foreach (array(Filter::post('ged'), Filter::get('ged'), Session::get('GEDCOM'), Site::getPreference('DEFAULT_GEDCOM')) as $tree_name) {
404
-	$WT_TREE = Tree::findByName($tree_name);
405
-	if ($WT_TREE) {
406
-		Session::put('GEDCOM', $tree_name);
407
-		break;
408
-	}
404
+    $WT_TREE = Tree::findByName($tree_name);
405
+    if ($WT_TREE) {
406
+        Session::put('GEDCOM', $tree_name);
407
+        break;
408
+    }
409 409
 }
410 410
 // No chosen tree? Use any one.
411 411
 if (!$WT_TREE) {
412
-	foreach (Tree::getAll() as $WT_TREE) {
413
-		break;
414
-	}
412
+    foreach (Tree::getAll() as $WT_TREE) {
413
+        break;
414
+    }
415 415
 }
416 416
 
417 417
 // With no parameters, init() looks to the environment to choose a language
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 
424 424
 // Users get their own time-zone. Visitors get the site time-zone.
425 425
 if (Auth::check()) {
426
-	date_default_timezone_set(Auth::user()->getPreference('TIMEZONE', 'UTC'));
426
+    date_default_timezone_set(Auth::user()->getPreference('TIMEZONE', 'UTC'));
427 427
 } else {
428
-	date_default_timezone_set(Site::getPreference('TIMEZONE') ?: 'UTC');
428
+    date_default_timezone_set(Site::getPreference('TIMEZONE') ?: 'UTC');
429 429
 }
430 430
 define('WT_TIMESTAMP_OFFSET', date_offset_get(new \DateTime('now')));
431 431
 
@@ -433,79 +433,79 @@  discard block
 block discarded – undo
433 433
 
434 434
 // The login URL must be an absolute URL, and can be user-defined
435 435
 if (Site::getPreference('LOGIN_URL')) {
436
-	define('WT_LOGIN_URL', Site::getPreference('LOGIN_URL'));
436
+    define('WT_LOGIN_URL', Site::getPreference('LOGIN_URL'));
437 437
 } else {
438
-	define('WT_LOGIN_URL', WT_BASE_URL . 'login.php');
438
+    define('WT_LOGIN_URL', WT_BASE_URL . 'login.php');
439 439
 }
440 440
 
441 441
 // If there is no current tree and we need one, then redirect somewhere
442 442
 if (WT_SCRIPT_NAME != 'admin_trees_manage.php' && WT_SCRIPT_NAME != 'admin_pgv_to_wt.php' && WT_SCRIPT_NAME != 'login.php' && WT_SCRIPT_NAME != 'logout.php' && WT_SCRIPT_NAME != 'import.php' && WT_SCRIPT_NAME != 'help_text.php' && WT_SCRIPT_NAME != 'message.php' && WT_SCRIPT_NAME != 'action.php') {
443
-	if (!$WT_TREE || !$WT_TREE->getPreference('imported')) {
444
-		if (Auth::isAdmin()) {
445
-			header('Location: ' . WT_BASE_URL . 'admin_trees_manage.php');
446
-		} else {
447
-			// We're not an administrator, so we can only log in if there is a tree.
448
-			if (Auth::id()) {
449
-				Auth::logout();
450
-				FlashMessages::addMessage(
451
-					I18N::translate('This user account does not have access to any tree.')
452
-				);
453
-			}
454
-			header('Location: ' . WT_LOGIN_URL . '?url=' . rawurlencode(WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')), true, 301);
455
-
456
-		}
457
-		exit;
458
-	}
443
+    if (!$WT_TREE || !$WT_TREE->getPreference('imported')) {
444
+        if (Auth::isAdmin()) {
445
+            header('Location: ' . WT_BASE_URL . 'admin_trees_manage.php');
446
+        } else {
447
+            // We're not an administrator, so we can only log in if there is a tree.
448
+            if (Auth::id()) {
449
+                Auth::logout();
450
+                FlashMessages::addMessage(
451
+                    I18N::translate('This user account does not have access to any tree.')
452
+                );
453
+            }
454
+            header('Location: ' . WT_LOGIN_URL . '?url=' . rawurlencode(WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')), true, 301);
455
+
456
+        }
457
+        exit;
458
+    }
459 459
 }
460 460
 
461 461
 // Update the last-login time no more than once a minute
462 462
 if (WT_TIMESTAMP - Session::get('activity_time') >= 60) {
463
-	if (Session::get('masquerade') === null) {
464
-		Auth::user()->setPreference('sessiontime', WT_TIMESTAMP);
465
-	}
466
-	Session::put('activity_time', WT_TIMESTAMP);
463
+    if (Session::get('masquerade') === null) {
464
+        Auth::user()->setPreference('sessiontime', WT_TIMESTAMP);
465
+    }
466
+    Session::put('activity_time', WT_TIMESTAMP);
467 467
 }
468 468
 
469 469
 // Set the theme
470 470
 if (substr(WT_SCRIPT_NAME, 0, 5) === 'admin' || WT_SCRIPT_NAME === 'module.php' && substr(Filter::get('mod_action'), 0, 5) === 'admin') {
471
-	// Administration scripts begin with “admin” and use a special administration theme
472
-	Theme::theme(new AdministrationTheme)->init($WT_TREE);
471
+    // Administration scripts begin with “admin” and use a special administration theme
472
+    Theme::theme(new AdministrationTheme)->init($WT_TREE);
473 473
 } else {
474
-	// Last theme used?
475
-	$theme_id = Session::get('theme_id');
476
-	// Default for tree
477
-	if (!array_key_exists($theme_id, Theme::themeNames()) && $WT_TREE) {
478
-		$theme_id = $WT_TREE->getPreference('THEME_DIR');
479
-	}
480
-	// Default for site
481
-	if (!array_key_exists($theme_id, Theme::themeNames())) {
482
-		$theme_id = Site::getPreference('THEME_DIR');
483
-	}
484
-	// Default
485
-	if (!array_key_exists($theme_id, Theme::themeNames())) {
486
-		$theme_id = 'webtrees';
487
-	}
488
-	foreach (Theme::installedThemes() as $theme) {
489
-		if ($theme->themeId() === $theme_id) {
490
-			Theme::theme($theme)->init($WT_TREE);
491
-			// Remember this setting
492
-			if (Site::getPreference('ALLOW_USER_THEMES')) {
493
-				Session::put('theme_id', $theme_id);
494
-			}
495
-			break;
496
-		}
497
-	}
474
+    // Last theme used?
475
+    $theme_id = Session::get('theme_id');
476
+    // Default for tree
477
+    if (!array_key_exists($theme_id, Theme::themeNames()) && $WT_TREE) {
478
+        $theme_id = $WT_TREE->getPreference('THEME_DIR');
479
+    }
480
+    // Default for site
481
+    if (!array_key_exists($theme_id, Theme::themeNames())) {
482
+        $theme_id = Site::getPreference('THEME_DIR');
483
+    }
484
+    // Default
485
+    if (!array_key_exists($theme_id, Theme::themeNames())) {
486
+        $theme_id = 'webtrees';
487
+    }
488
+    foreach (Theme::installedThemes() as $theme) {
489
+        if ($theme->themeId() === $theme_id) {
490
+            Theme::theme($theme)->init($WT_TREE);
491
+            // Remember this setting
492
+            if (Site::getPreference('ALLOW_USER_THEMES')) {
493
+                Session::put('theme_id', $theme_id);
494
+            }
495
+            break;
496
+        }
497
+    }
498 498
 }
499 499
 
500 500
 // Search engines are only allowed to see certain pages.
501 501
 if (Auth::isSearchEngine() && !in_array(WT_SCRIPT_NAME, array(
502
-	'index.php', 'indilist.php', 'module.php', 'mediafirewall.php',
503
-	'individual.php', 'family.php', 'mediaviewer.php', 'note.php', 'repo.php', 'source.php',
502
+    'index.php', 'indilist.php', 'module.php', 'mediafirewall.php',
503
+    'individual.php', 'family.php', 'mediaviewer.php', 'note.php', 'repo.php', 'source.php',
504 504
 ))) {
505
-	http_response_code(403);
506
-	$controller = new PageController;
507
-	$controller->setPageTitle(I18N::translate('Search engine'));
508
-	$controller->pageHeader();
509
-	echo '<p class="ui-state-error">', I18N::translate('You do not have permission to view this page.'), '</p>';
510
-	exit;
505
+    http_response_code(403);
506
+    $controller = new PageController;
507
+    $controller->setPageTitle(I18N::translate('Search engine'));
508
+    $controller->pageHeader();
509
+    echo '<p class="ui-state-error">', I18N::translate('You do not have permission to view this page.'), '</p>';
510
+    exit;
511 511
 }
Please login to merge, or discard this patch.