Completed
Push — 1.7 ( 284d8b...6ce0c4 )
by
unknown
07:17
created
admin_modules.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -32,85 +32,85 @@
 block discarded – undo
32 32
 
33 33
 $controller = new PageController;
34 34
 $controller
35
-	->restrictAccess(Auth::isAdmin())
36
-	->setPageTitle(I18N::translate('Module administration'));
35
+    ->restrictAccess(Auth::isAdmin())
36
+    ->setPageTitle(I18N::translate('Module administration'));
37 37
 
38 38
 $modules       = Module::getInstalledModules('disabled');
39 39
 $module_status = Database::prepare("SELECT module_name, status FROM `##module`")->fetchAssoc();
40 40
 
41 41
 uasort($modules, function (AbstractModule $x, AbstractModule $y) {
42
-	return I18N::strcasecmp($x->getTitle(), $y->getTitle());
42
+    return I18N::strcasecmp($x->getTitle(), $y->getTitle());
43 43
 });
44 44
 
45 45
 if (Filter::post('action') === 'update_mods' && Filter::checkCsrf()) {
46
-	foreach ($modules as $module) {
47
-		$new_status = Filter::post('status-' . $module->getName(), '[01]');
48
-		if ($new_status !== null) {
49
-			$new_status = $new_status ? 'enabled' : 'disabled';
50
-			$old_status = $module_status[$module->getName()];
51
-			if ($new_status !== $old_status) {
52
-				Database::prepare("UPDATE `##module` SET status=? WHERE module_name=?")->execute(array($new_status, $module->getName()));
53
-				if ($new_status === 'disabled') {
54
-					FlashMessages::addMessage(I18N::translate('The module “%s” has been disabled.', $module->getTitle()), 'success');
55
-				} else {
56
-					FlashMessages::addMessage(I18N::translate('The module “%s” has been enabled.', $module->getTitle()), 'success');
57
-				}
58
-			}
59
-		}
60
-	}
46
+    foreach ($modules as $module) {
47
+        $new_status = Filter::post('status-' . $module->getName(), '[01]');
48
+        if ($new_status !== null) {
49
+            $new_status = $new_status ? 'enabled' : 'disabled';
50
+            $old_status = $module_status[$module->getName()];
51
+            if ($new_status !== $old_status) {
52
+                Database::prepare("UPDATE `##module` SET status=? WHERE module_name=?")->execute(array($new_status, $module->getName()));
53
+                if ($new_status === 'disabled') {
54
+                    FlashMessages::addMessage(I18N::translate('The module “%s” has been disabled.', $module->getTitle()), 'success');
55
+                } else {
56
+                    FlashMessages::addMessage(I18N::translate('The module “%s” has been enabled.', $module->getTitle()), 'success');
57
+                }
58
+            }
59
+        }
60
+    }
61 61
 
62
-	header('Location: ' . WT_BASE_URL . 'admin_modules.php');
62
+    header('Location: ' . WT_BASE_URL . 'admin_modules.php');
63 63
 
64
-	return;
64
+    return;
65 65
 }
66 66
 
67 67
 if (Filter::post('action') === 'delete' && Filter::checkCsrf()) {
68
-	$module_name = Filter::post('module_name');
69
-	Database::prepare(
70
-		"DELETE `##block_setting`" .
71
-		" FROM `##block_setting`" .
72
-		" JOIN `##block` USING (block_id)" .
73
-		" JOIN `##module` USING (module_name)" .
74
-		" WHERE module_name=?"
75
-	)->execute(array($module_name));
76
-	Database::prepare(
77
-		"DELETE `##block`" .
78
-		" FROM `##block`" .
79
-		" JOIN `##module` USING (module_name)" .
80
-		" WHERE module_name=?"
81
-	)->execute(array($module_name));
82
-	Database::prepare("DELETE FROM `##module_setting` WHERE module_name=?")->execute(array($module_name));
83
-	Database::prepare("DELETE FROM `##module_privacy` WHERE module_name=?")->execute(array($module_name));
84
-	Database::prepare("DELETE FROM `##module` WHERE module_name=?")->execute(array($module_name));
68
+    $module_name = Filter::post('module_name');
69
+    Database::prepare(
70
+        "DELETE `##block_setting`" .
71
+        " FROM `##block_setting`" .
72
+        " JOIN `##block` USING (block_id)" .
73
+        " JOIN `##module` USING (module_name)" .
74
+        " WHERE module_name=?"
75
+    )->execute(array($module_name));
76
+    Database::prepare(
77
+        "DELETE `##block`" .
78
+        " FROM `##block`" .
79
+        " JOIN `##module` USING (module_name)" .
80
+        " WHERE module_name=?"
81
+    )->execute(array($module_name));
82
+    Database::prepare("DELETE FROM `##module_setting` WHERE module_name=?")->execute(array($module_name));
83
+    Database::prepare("DELETE FROM `##module_privacy` WHERE module_name=?")->execute(array($module_name));
84
+    Database::prepare("DELETE FROM `##module` WHERE module_name=?")->execute(array($module_name));
85 85
 
86
-	FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been deleted.', $module_name), 'success');
86
+    FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been deleted.', $module_name), 'success');
87 87
 
88
-	header('Location: ' . WT_BASE_URL . 'admin_modules.php');
88
+    header('Location: ' . WT_BASE_URL . 'admin_modules.php');
89 89
 
90
-	return;
90
+    return;
91 91
 }
92 92
 
93 93
 // The module can’t be found on disk?
94 94
 // Don't delete it automatically. It may be temporarily missing, after a re-installation, etc.
95 95
 foreach ($module_status as $module_name => $status) {
96
-	if (!array_key_exists($module_name, $modules)) {
97
-		$html =
98
-			I18N::translate('Preferences exist for the module “%s”, but this module no longer exists.', '<span dir="ltr">' . $module_name . '</span>') .
99
-			'<form method="post" class="form-inline">' .
100
-			Filter::getCsrf() .
101
-			'<input type="hidden" name="action" value="delete">' .
102
-			'<input type="hidden" name="module_name" value="' . $module_name . '">' .
103
-			'<button type="submit" class="btn btn-link">' . I18N::translate('Delete the preferences for this module.') . '</button>' .
104
-			'</form>';
105
-		FlashMessages::addMessage($html, 'warning');
106
-	}
96
+    if (!array_key_exists($module_name, $modules)) {
97
+        $html =
98
+            I18N::translate('Preferences exist for the module “%s”, but this module no longer exists.', '<span dir="ltr">' . $module_name . '</span>') .
99
+            '<form method="post" class="form-inline">' .
100
+            Filter::getCsrf() .
101
+            '<input type="hidden" name="action" value="delete">' .
102
+            '<input type="hidden" name="module_name" value="' . $module_name . '">' .
103
+            '<button type="submit" class="btn btn-link">' . I18N::translate('Delete the preferences for this module.') . '</button>' .
104
+            '</form>';
105
+        FlashMessages::addMessage($html, 'warning');
106
+    }
107 107
 }
108 108
 
109 109
 $controller
110
-	->pageHeader()
111
-	->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
112
-	->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
113
-	->addInlineJavascript('
110
+    ->pageHeader()
111
+    ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
112
+    ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
113
+    ->addInlineJavascript('
114 114
 		function reindexMods(id) {
115 115
 			jQuery("#" + id + " input").each(
116 116
 				function (index, value) {
Please login to merge, or discard this patch.
admin_site_clean.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -23,45 +23,45 @@  discard block
 block discarded – undo
23 23
 
24 24
 $to_delete = Filter::postArray('to_delete');
25 25
 if ($to_delete && Filter::checkCsrf()) {
26
-	foreach ($to_delete as $path) {
27
-		$is_dir = is_dir(WT_DATA_DIR . $path);
28
-		if (File::delete(WT_DATA_DIR . $path)) {
29
-			if ($is_dir) {
30
-				FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', Filter::escapeHtml($path)), 'success');
31
-			} else {
32
-				FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', Filter::escapeHtml($path)), 'success');
33
-			}
34
-		} else {
35
-			if ($is_dir) {
36
-				FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', Filter::escapeHtml($path)), 'danger');
37
-			} else {
38
-				FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', Filter::escapeHtml($path)), 'danger');
39
-			}
40
-		}
41
-	}
42
-
43
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
44
-
45
-	return;
26
+    foreach ($to_delete as $path) {
27
+        $is_dir = is_dir(WT_DATA_DIR . $path);
28
+        if (File::delete(WT_DATA_DIR . $path)) {
29
+            if ($is_dir) {
30
+                FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', Filter::escapeHtml($path)), 'success');
31
+            } else {
32
+                FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', Filter::escapeHtml($path)), 'success');
33
+            }
34
+        } else {
35
+            if ($is_dir) {
36
+                FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', Filter::escapeHtml($path)), 'danger');
37
+            } else {
38
+                FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', Filter::escapeHtml($path)), 'danger');
39
+            }
40
+        }
41
+    }
42
+
43
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
44
+
45
+    return;
46 46
 }
47 47
 
48 48
 $controller = new PageController;
49 49
 $controller
50
-	->restrictAccess(Auth::isAdmin())
51
-	->setPageTitle(/* I18N: The “Data folder” is a configuration setting */ I18N::translate('Clean up data folder'))
52
-	->pageHeader();
50
+    ->restrictAccess(Auth::isAdmin())
51
+    ->setPageTitle(/* I18N: The “Data folder” is a configuration setting */ I18N::translate('Clean up data folder'))
52
+    ->pageHeader();
53 53
 
54 54
 $do_not_delete = array('index.php', 'config.ini.php', 'language');
55 55
 
56 56
 // If we are storing the media in the data folder (this is the default), then don’t delete it.
57 57
 foreach (Tree::getAll() as $tree) {
58
-	$MEDIA_DIRECTORY = $tree->getPreference('MEDIA_DIRECTORY');
58
+    $MEDIA_DIRECTORY = $tree->getPreference('MEDIA_DIRECTORY');
59 59
 
60
-	if (substr($MEDIA_DIRECTORY, 0, 3) != '../') {
61
-		// Just need to add the first part of the path
62
-		$tmp             = explode('/', $MEDIA_DIRECTORY);
63
-		$do_not_delete[] = $tmp[0];
64
-	}
60
+    if (substr($MEDIA_DIRECTORY, 0, 3) != '../') {
61
+        // Just need to add the first part of the path
62
+        $tmp             = explode('/', $MEDIA_DIRECTORY);
63
+        $do_not_delete[] = $tmp[0];
64
+    }
65 65
 }
66 66
 
67 67
 $locked_icon = '<i class="fa fa-ban text-danger"></i>';
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 $dir     = dir(WT_DATA_DIR);
70 70
 $entries = array();
71 71
 while (false !== ($entry = $dir->read())) {
72
-	if ($entry[0] != '.') {
73
-		$entries[] = $entry;
74
-	}
72
+    if ($entry[0] != '.') {
73
+        $entries[] = $entry;
74
+    }
75 75
 }
76 76
 
77 77
 sort($entries);
@@ -94,20 +94,20 @@  discard block
 block discarded – undo
94 94
 		<legend class="sr-only"><?php echo $controller->getPageTitle(); ?></legend>
95 95
 		<ul class="fa-ul">
96 96
 			<?php
97
-			foreach ($entries as $entry) {
98
-				if (in_array($entry, $do_not_delete)) {
99
-					echo '<li><i class="fa-li fa fa-ban text-danger"></i>', Filter::escapeHtml($entry), '</li>';
100
-				} else {
101
-					$id = 'input-' . Uuid::uuid4();
102
-					echo '<li><i class="fa-li fa fa-trash-o"></i>';
103
-					echo '<label for="', $id, '">';
104
-					echo '<input type="checkbox" id="', $id, '" name="to_delete[]" value="', Filter::escapeHtml($entry), '"> ';
105
-					echo Filter::escapeHtml($entry);
106
-					echo '</label></li>';
107
-				}
108
-			}
109
-			$dir->close();
110
-			?>
97
+            foreach ($entries as $entry) {
98
+                if (in_array($entry, $do_not_delete)) {
99
+                    echo '<li><i class="fa-li fa fa-ban text-danger"></i>', Filter::escapeHtml($entry), '</li>';
100
+                } else {
101
+                    $id = 'input-' . Uuid::uuid4();
102
+                    echo '<li><i class="fa-li fa fa-trash-o"></i>';
103
+                    echo '<label for="', $id, '">';
104
+                    echo '<input type="checkbox" id="', $id, '" name="to_delete[]" value="', Filter::escapeHtml($entry), '"> ';
105
+                    echo Filter::escapeHtml($entry);
106
+                    echo '</label></li>';
107
+                }
108
+            }
109
+            $dir->close();
110
+            ?>
111 111
 		</ul>
112 112
 	</fieldset>
113 113
 	<button class="btn btn-danger" type="submit">
Please login to merge, or discard this patch.
admin_trees_places.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -34,56 +34,56 @@
 block discarded – undo
34 34
 $changes = array();
35 35
 
36 36
 if ($search && $replace) {
37
-	$rows = Database::prepare(
38
-		"SELECT i_id AS xref, i_gedcom AS gedcom" .
39
-		" FROM `##individuals`" .
40
-		" LEFT JOIN `##change` ON (i_id = xref AND i_file=gedcom_id AND status='pending')" .
41
-		" WHERE i_file = ?" .
42
-		" AND COALESCE(new_gedcom, i_gedcom) REGEXP CONCAT('\n2 PLAC ([^\n]*, )*', ?, '(\n|$)')"
43
-	)->execute(array($WT_TREE->getTreeId(), preg_quote($search)))->fetchAll();
44
-	foreach ($rows as $row) {
45
-		$record = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
46
-		foreach ($record->getFacts() as $fact) {
47
-			$old_place = $fact->getAttribute('PLAC');
48
-			if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) {
49
-				$new_place           = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place);
50
-				$changes[$old_place] = $new_place;
51
-				if ($confirm == 'update') {
52
-					$gedcom = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->getGedcom());
53
-					$record->updateFact($fact->getFactId(), $gedcom, false);
54
-				}
55
-			}
56
-		}
57
-	}
58
-	$rows = Database::prepare(
59
-		"SELECT f_id AS xref, f_gedcom AS gedcom" .
60
-		" FROM `##families`" .
61
-		" LEFT JOIN `##change` ON (f_id = xref AND f_file=gedcom_id AND status='pending')" .
62
-		" WHERE f_file = ?" .
63
-		" AND COALESCE(new_gedcom, f_gedcom) REGEXP CONCAT('\n2 PLAC ([^\n]*, )*', ?, '(\n|$)')"
64
-	)->execute(array($WT_TREE->getTreeId(), preg_quote($search)))->fetchAll();
65
-	foreach ($rows as $row) {
66
-		$record = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
67
-		foreach ($record->getFacts() as $fact) {
68
-			$old_place = $fact->getAttribute('PLAC');
69
-			if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) {
70
-				$new_place           = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place);
71
-				$changes[$old_place] = $new_place;
72
-				if ($confirm == 'update') {
73
-					$gedcom = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->getGedcom());
74
-					$record->updateFact($fact->getFactId(), $gedcom, false);
75
-				}
76
-			}
77
-		}
78
-	}
37
+    $rows = Database::prepare(
38
+        "SELECT i_id AS xref, i_gedcom AS gedcom" .
39
+        " FROM `##individuals`" .
40
+        " LEFT JOIN `##change` ON (i_id = xref AND i_file=gedcom_id AND status='pending')" .
41
+        " WHERE i_file = ?" .
42
+        " AND COALESCE(new_gedcom, i_gedcom) REGEXP CONCAT('\n2 PLAC ([^\n]*, )*', ?, '(\n|$)')"
43
+    )->execute(array($WT_TREE->getTreeId(), preg_quote($search)))->fetchAll();
44
+    foreach ($rows as $row) {
45
+        $record = Individual::getInstance($row->xref, $WT_TREE, $row->gedcom);
46
+        foreach ($record->getFacts() as $fact) {
47
+            $old_place = $fact->getAttribute('PLAC');
48
+            if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) {
49
+                $new_place           = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place);
50
+                $changes[$old_place] = $new_place;
51
+                if ($confirm == 'update') {
52
+                    $gedcom = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->getGedcom());
53
+                    $record->updateFact($fact->getFactId(), $gedcom, false);
54
+                }
55
+            }
56
+        }
57
+    }
58
+    $rows = Database::prepare(
59
+        "SELECT f_id AS xref, f_gedcom AS gedcom" .
60
+        " FROM `##families`" .
61
+        " LEFT JOIN `##change` ON (f_id = xref AND f_file=gedcom_id AND status='pending')" .
62
+        " WHERE f_file = ?" .
63
+        " AND COALESCE(new_gedcom, f_gedcom) REGEXP CONCAT('\n2 PLAC ([^\n]*, )*', ?, '(\n|$)')"
64
+    )->execute(array($WT_TREE->getTreeId(), preg_quote($search)))->fetchAll();
65
+    foreach ($rows as $row) {
66
+        $record = Family::getInstance($row->xref, $WT_TREE, $row->gedcom);
67
+        foreach ($record->getFacts() as $fact) {
68
+            $old_place = $fact->getAttribute('PLAC');
69
+            if (preg_match('/(^|, )' . preg_quote($search, '/') . '$/i', $old_place)) {
70
+                $new_place           = preg_replace('/(^|, )' . preg_quote($search, '/') . '$/i', '$1' . $replace, $old_place);
71
+                $changes[$old_place] = $new_place;
72
+                if ($confirm == 'update') {
73
+                    $gedcom = preg_replace('/(\n2 PLAC (?:.*, )*)' . preg_quote($search, '/') . '(\n|$)/i', '$1' . $replace . '$2', $fact->getGedcom());
74
+                    $record->updateFact($fact->getFactId(), $gedcom, false);
75
+                }
76
+            }
77
+        }
78
+    }
79 79
 }
80 80
 
81 81
 $controller = new PageController;
82 82
 $controller
83
-	->restrictAccess(Auth::isManager($WT_TREE))
84
-	->setPageTitle(I18N::translate('Update all the place names in a family tree') . ' — ' . $WT_TREE->getTitleHtml())
85
-	->addInlineJavascript('autocomplete();')
86
-	->pageHeader();
83
+    ->restrictAccess(Auth::isManager($WT_TREE))
84
+    ->setPageTitle(I18N::translate('Update all the place names in a family tree') . ' — ' . $WT_TREE->getTitleHtml())
85
+    ->addInlineJavascript('autocomplete();')
86
+    ->pageHeader();
87 87
 ?>
88 88
 
89 89
 <ol class="breadcrumb small">
Please login to merge, or discard this patch.
family.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -33,38 +33,38 @@  discard block
 block discarded – undo
33 33
 $controller = new FamilyController($record);
34 34
 
35 35
 if ($controller->record && $controller->record->canShow()) {
36
-	if ($controller->record->isPendingDeletion()) {
37
-		if (Auth::isModerator($controller->record->getTree())) {
38
-			FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
39
-				'This family has been deleted. You should review the deletion and then %1$s or %2$s it.',
40
-				'<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>',
41
-				'<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>'
42
-			) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
43
-		} elseif (Auth::isEditor($controller->record->getTree())) {
44
-			FlashMessages::addMessage(I18N::translate('This family has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
45
-		}
46
-	} elseif ($controller->record->isPendingAddtion()) {
47
-		if (Auth::isModerator($controller->record->getTree())) {
48
-			FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
49
-				'This family has been edited. You should review the changes and then %1$s or %2$s them.',
50
-				'<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>',
51
-				'<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>'
52
-			) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
53
-		} elseif (Auth::isEditor($controller->record->getTree())) {
54
-			FlashMessages::addMessage(I18N::translate('This family has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
55
-		}
56
-	}
57
-	$controller->pageHeader();
36
+    if ($controller->record->isPendingDeletion()) {
37
+        if (Auth::isModerator($controller->record->getTree())) {
38
+            FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
39
+                'This family has been deleted. You should review the deletion and then %1$s or %2$s it.',
40
+                '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>',
41
+                '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>'
42
+            ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
43
+        } elseif (Auth::isEditor($controller->record->getTree())) {
44
+            FlashMessages::addMessage(I18N::translate('This family has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
45
+        }
46
+    } elseif ($controller->record->isPendingAddtion()) {
47
+        if (Auth::isModerator($controller->record->getTree())) {
48
+            FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
49
+                'This family has been edited. You should review the changes and then %1$s or %2$s them.',
50
+                '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>',
51
+                '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>'
52
+            ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
53
+        } elseif (Auth::isEditor($controller->record->getTree())) {
54
+            FlashMessages::addMessage(I18N::translate('This family has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
55
+        }
56
+    }
57
+    $controller->pageHeader();
58 58
 } elseif ($controller->record && $controller->record->getTree()->getPreference('SHOW_PRIVATE_RELATIONSHIPS')) {
59
-	$controller->pageHeader();
60
-	// Continue - to display the children/parents/grandparents.
61
-	// We'll check for showing the details again later
59
+    $controller->pageHeader();
60
+    // Continue - to display the children/parents/grandparents.
61
+    // We'll check for showing the details again later
62 62
 } else {
63
-	FlashMessages::addMessage(I18N::translate('This family does not exist or you do not have permission to view it.'), 'danger');
64
-	http_response_code(404);
65
-	$controller->pageHeader();
63
+    FlashMessages::addMessage(I18N::translate('This family does not exist or you do not have permission to view it.'), 'danger');
64
+    http_response_code(404);
65
+    $controller->pageHeader();
66 66
 
67
-	return;
67
+    return;
68 68
 }
69 69
 
70 70
 ?>
@@ -85,32 +85,32 @@  discard block
 block discarded – undo
85 85
 					<tr>
86 86
 						<td colspan="2">
87 87
 							<?php
88
-							FunctionsCharts::printFamilyParents($controller->record);
89
-							if (Auth::isEditor($controller->record->getTree())) {
90
-								$husb = $controller->record->getHusband();
91
-								if (!$husb) {
92
-									echo '<a href="#" onclick="return add_spouse_to_family(\'', $controller->record->getXref(), '\', \'HUSB\');">', I18N::translate('Add a father'), '</a><br>';
93
-								}
94
-								$wife = $controller->record->getWife();
95
-								if (!$wife) {
96
-									echo '<a href="#" onclick="return add_spouse_to_family(\'', $controller->record->getXref(), '\', \'WIFE\');">', I18N::translate('Add a mother'), '</a><br>';
97
-								}
98
-							}
99
-							?>
88
+                            FunctionsCharts::printFamilyParents($controller->record);
89
+                            if (Auth::isEditor($controller->record->getTree())) {
90
+                                $husb = $controller->record->getHusband();
91
+                                if (!$husb) {
92
+                                    echo '<a href="#" onclick="return add_spouse_to_family(\'', $controller->record->getXref(), '\', \'HUSB\');">', I18N::translate('Add a father'), '</a><br>';
93
+                                }
94
+                                $wife = $controller->record->getWife();
95
+                                if (!$wife) {
96
+                                    echo '<a href="#" onclick="return add_spouse_to_family(\'', $controller->record->getXref(), '\', \'WIFE\');">', I18N::translate('Add a mother'), '</a><br>';
97
+                                }
98
+                            }
99
+                            ?>
100 100
 						</td>
101 101
 					</tr>
102 102
 					<tr>
103 103
 						<td colspan="2">
104 104
 							<span class="subheaders"><?php echo I18N::translate('Family group information'); ?></span>
105 105
 							<?php
106
-							if ($controller->record->canShow()) {
107
-								echo '<table class="facts_table">';
108
-								$controller->printFamilyFacts();
109
-								echo '</table>';
110
-							} else {
111
-								echo '<p>', I18N::translate('The details of this family are private.'), '</p>';
112
-							}
113
-							?>
106
+                            if ($controller->record->canShow()) {
107
+                                echo '<table class="facts_table">';
108
+                                $controller->printFamilyFacts();
109
+                                echo '</table>';
110
+                            } else {
111
+                                echo '<p>', I18N::translate('The details of this family are private.'), '</p>';
112
+                            }
113
+                            ?>
114 114
 						</td>
115 115
 					</tr>
116 116
 				</table>
Please login to merge, or discard this patch.
admin_site_change.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 
33 33
 $controller = new PageController;
34 34
 $controller
35
-	->restrictAccess(Auth::isManager($WT_TREE))
36
-	->setPageTitle(I18N::translate('Changes'));
35
+    ->restrictAccess(Auth::isManager($WT_TREE))
36
+    ->setPageTitle(I18N::translate('Changes'));
37 37
 
38 38
 $earliest = Database::prepare("SELECT IFNULL(DATE(MIN(change_time)), CURDATE()) FROM `##change`")->execute(array())->fetchOne();
39 39
 $latest   = Database::prepare("SELECT IFNULL(DATE(MAX(change_time)), CURDATE()) FROM `##change`")->execute(array())->fetchOne();
@@ -51,197 +51,197 @@  discard block
 block discarded – undo
51 51
 $search = isset($search['value']) ? $search['value'] : null;
52 52
 
53 53
 $statuses = array(
54
-	'accepted' => /* I18N: the status of an edit accepted/rejected/pending */ I18N::translate('accepted'),
55
-	'rejected' => /* I18N: the status of an edit accepted/rejected/pending */ I18N::translate('rejected'),
56
-	'pending'  => /* I18N: the status of an edit accepted/rejected/pending */ I18N::translate('pending'),
54
+    'accepted' => /* I18N: the status of an edit accepted/rejected/pending */ I18N::translate('accepted'),
55
+    'rejected' => /* I18N: the status of an edit accepted/rejected/pending */ I18N::translate('rejected'),
56
+    'pending'  => /* I18N: the status of an edit accepted/rejected/pending */ I18N::translate('pending'),
57 57
 );
58 58
 
59 59
 if (Auth::isAdmin()) {
60
-	// Administrators can see all logs
61
-	$gedc = Filter::get('gedc');
60
+    // Administrators can see all logs
61
+    $gedc = Filter::get('gedc');
62 62
 } else {
63
-	// Managers can only see logs relating to this gedcom
64
-	$gedc = $WT_TREE->getName();
63
+    // Managers can only see logs relating to this gedcom
64
+    $gedc = $WT_TREE->getName();
65 65
 }
66 66
 
67 67
 $sql_select =
68
-	"SELECT SQL_CALC_FOUND_ROWS change_id, change_time, status, xref, old_gedcom, new_gedcom, IFNULL(user_name, '<none>') AS user_name, IFNULL(gedcom_name, '<none>') AS gedcom_name" .
69
-	" FROM `##change`" .
70
-	" LEFT JOIN `##user` USING (user_id)" . // user may be deleted
71
-	" LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
68
+    "SELECT SQL_CALC_FOUND_ROWS change_id, change_time, status, xref, old_gedcom, new_gedcom, IFNULL(user_name, '<none>') AS user_name, IFNULL(gedcom_name, '<none>') AS gedcom_name" .
69
+    " FROM `##change`" .
70
+    " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
71
+    " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
72 72
 
73 73
 $where = " WHERE 1";
74 74
 $args  = array();
75 75
 if ($search) {
76
-	$where .= " AND (old_gedcom LIKE CONCAT('%', :search_1, '%') OR new_gedcom LIKE CONCAT('%', :search_2, '%'))";
77
-	$args['search_1'] = $search;
78
-	$args['search_2'] = $search;
76
+    $where .= " AND (old_gedcom LIKE CONCAT('%', :search_1, '%') OR new_gedcom LIKE CONCAT('%', :search_2, '%'))";
77
+    $args['search_1'] = $search;
78
+    $args['search_2'] = $search;
79 79
 }
80 80
 if ($from) {
81
-	$where .= " AND change_time >= :from";
82
-	$args['from'] = $from;
81
+    $where .= " AND change_time >= :from";
82
+    $args['from'] = $from;
83 83
 }
84 84
 if ($to) {
85
-	$where .= " AND change_time < TIMESTAMPADD(DAY, 1 , :to)"; // before end of the day
86
-	$args['to'] = $to;
85
+    $where .= " AND change_time < TIMESTAMPADD(DAY, 1 , :to)"; // before end of the day
86
+    $args['to'] = $to;
87 87
 }
88 88
 if ($type) {
89
-	$where .= " AND status = :status";
90
-	$args['status'] = $type;
89
+    $where .= " AND status = :status";
90
+    $args['status'] = $type;
91 91
 }
92 92
 if ($oldged) {
93
-	$where .= " AND old_gedcom LIKE CONCAT('%', :old_ged, '%')";
94
-	$args['old_ged'] = $oldged;
93
+    $where .= " AND old_gedcom LIKE CONCAT('%', :old_ged, '%')";
94
+    $args['old_ged'] = $oldged;
95 95
 }
96 96
 if ($newged) {
97
-	$where .= " AND new_gedcom LIKE CONCAT('%', :new_ged, '%')";
98
-	$args['new_ged'] = $newged;
97
+    $where .= " AND new_gedcom LIKE CONCAT('%', :new_ged, '%')";
98
+    $args['new_ged'] = $newged;
99 99
 }
100 100
 if ($xref) {
101
-	$where .= " AND xref = :xref";
102
-	$args['xref'] = $xref;
101
+    $where .= " AND xref = :xref";
102
+    $args['xref'] = $xref;
103 103
 }
104 104
 if ($user) {
105
-	$where .= " AND user_name LIKE CONCAT('%', :user, '%')";
106
-	$args['user'] = $user;
105
+    $where .= " AND user_name LIKE CONCAT('%', :user, '%')";
106
+    $args['user'] = $user;
107 107
 }
108 108
 if ($gedc) {
109
-	$where .= " AND gedcom_name LIKE CONCAT('%', :gedc, '%')";
110
-	$args['gedc'] = $gedc;
109
+    $where .= " AND gedcom_name LIKE CONCAT('%', :gedc, '%')";
110
+    $args['gedc'] = $gedc;
111 111
 }
112 112
 
113 113
 switch ($action) {
114 114
 case 'delete':
115
-	$sql_delete =
116
-		"DELETE `##change` FROM `##change`" .
117
-		" LEFT JOIN `##user` USING (user_id)" . // user may be deleted
118
-		" LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
115
+    $sql_delete =
116
+        "DELETE `##change` FROM `##change`" .
117
+        " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
118
+        " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
119 119
 
120
-	Database::prepare($sql_delete . $where)->execute($args);
121
-	break;
120
+    Database::prepare($sql_delete . $where)->execute($args);
121
+    break;
122 122
 
123 123
 case 'export':
124
-	header('Content-Type: text/csv');
125
-	header('Content-Disposition: attachment; filename="webtrees-changes.csv"');
126
-	$rows = Database::prepare($sql_select . $where . ' ORDER BY change_id')->execute($args)->fetchAll();
127
-	foreach ($rows as $row) {
128
-		echo
129
-			'"', $row->change_time, '",',
130
-			'"', $row->status, '",',
131
-			'"', $row->xref, '",',
132
-			'"', str_replace('"', '""', $row->old_gedcom), '",',
133
-			'"', str_replace('"', '""', $row->new_gedcom), '",',
134
-			'"', str_replace('"', '""', $row->user_name), '",',
135
-			'"', str_replace('"', '""', $row->gedcom_name), '"',
136
-			"\n";
137
-	}
138
-
139
-	return;
124
+    header('Content-Type: text/csv');
125
+    header('Content-Disposition: attachment; filename="webtrees-changes.csv"');
126
+    $rows = Database::prepare($sql_select . $where . ' ORDER BY change_id')->execute($args)->fetchAll();
127
+    foreach ($rows as $row) {
128
+        echo
129
+            '"', $row->change_time, '",',
130
+            '"', $row->status, '",',
131
+            '"', $row->xref, '",',
132
+            '"', str_replace('"', '""', $row->old_gedcom), '",',
133
+            '"', str_replace('"', '""', $row->new_gedcom), '",',
134
+            '"', str_replace('"', '""', $row->user_name), '",',
135
+            '"', str_replace('"', '""', $row->gedcom_name), '"',
136
+            "\n";
137
+    }
138
+
139
+    return;
140 140
 case 'load_json':
141
-	$start  = Filter::getInteger('start');
142
-	$length = Filter::getInteger('length');
143
-	$order  = Filter::getArray('order');
144
-
145
-	if ($order) {
146
-		$order_by = " ORDER BY ";
147
-		foreach ($order as $key => $value) {
148
-			if ($key > 0) {
149
-				$order_by .= ',';
150
-			}
151
-			// Datatables numbers columns 0, 1, 2
152
-			// MySQL numbers columns 1, 2, 3
153
-			switch ($value['dir']) {
154
-			case 'asc':
155
-				$order_by .= (1 + $value['column']) . " ASC ";
156
-				break;
157
-			case 'desc':
158
-				$order_by .= (1 + $value['column']) . " DESC ";
159
-				break;
160
-			}
161
-		}
162
-	} else {
163
-		$order_by = " ORDER BY 1 DESC";
164
-	}
165
-
166
-	if ($length) {
167
-		Auth::user()->setPreference('admin_site_change_page_size', $length);
168
-		$limit          = " LIMIT :limit OFFSET :offset";
169
-		$args['limit']  = $length;
170
-		$args['offset'] = $start;
171
-	} else {
172
-		$limit = "";
173
-	}
174
-
175
-	// This becomes a JSON list, not array, so need to fetch with numeric keys.
176
-	$rows = Database::prepare($sql_select . $where . $order_by . $limit)->execute($args)->fetchAll(PDO::FETCH_OBJ);
177
-	// Total filtered/unfiltered rows
178
-	$recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
179
-	$recordsTotal    = (int) Database::prepare("SELECT COUNT(*) FROM `##change`")->fetchOne();
180
-
181
-	$data      = array();
182
-	$algorithm = new MyersDiff;
183
-
184
-	foreach ($rows as $row) {
185
-		$old_lines = preg_split('/[\n]+/', $row->old_gedcom, -1, PREG_SPLIT_NO_EMPTY);
186
-		$new_lines = preg_split('/[\n]+/', $row->new_gedcom, -1, PREG_SPLIT_NO_EMPTY);
187
-
188
-		$differences = $algorithm->calculate($old_lines, $new_lines);
189
-		$diff_lines  = array();
190
-
191
-		foreach ($differences as $difference) {
192
-			switch ($difference[1]) {
193
-			case MyersDiff::DELETE:
194
-				$diff_lines[] = '<del>' . $difference[0] . '</del>';
195
-				break;
196
-			case MyersDiff::INSERT:
197
-				$diff_lines[] = '<ins>' . $difference[0] . '</ins>';
198
-				break;
199
-			default:
200
-				$diff_lines[] = $difference[0];
201
-			}
202
-		}
203
-
204
-		// Only convert valid xrefs to links
205
-		$record = GedcomRecord::getInstance($row->xref, Tree::findByName($gedc));
206
-		$data[] = array(
207
-			$row->change_id,
208
-			$row->change_time,
209
-			I18N::translate($row->status),
210
-			$record ? '<a href="' . $record->getHtmlUrl() . '">' . $record->getXref() . '</a>' : $row->xref,
211
-			'<div class="gedcom-data" dir="ltr">' .
212
-				preg_replace_callback('/@(' . WT_REGEX_XREF . ')@/',
213
-					function ($match) use ($gedc) {
214
-						$record = GedcomRecord::getInstance($match[1], Tree::findByName($gedc));
215
-
216
-						return $record ? '<a href="#" onclick="return edit_raw(\'' . $match[1] . '\');">' . $match[0] . '</a>' : $match[0];
217
-					},
218
-					implode("\n", $diff_lines)
219
-				) .
220
-			'</div>',
221
-			$row->user_name,
222
-			$row->gedcom_name,
223
-		);
224
-	}
225
-
226
-	header('Content-type: application/json');
227
-	// See http://www.datatables.net/usage/server-side
228
-	echo json_encode(array(
229
-		'draw'            => Filter::getInteger('draw'),
230
-		'recordsTotal'    => $recordsTotal,
231
-		'recordsFiltered' => $recordsFiltered,
232
-		'data'            => $data,
233
-	));
234
-
235
-	return;
141
+    $start  = Filter::getInteger('start');
142
+    $length = Filter::getInteger('length');
143
+    $order  = Filter::getArray('order');
144
+
145
+    if ($order) {
146
+        $order_by = " ORDER BY ";
147
+        foreach ($order as $key => $value) {
148
+            if ($key > 0) {
149
+                $order_by .= ',';
150
+            }
151
+            // Datatables numbers columns 0, 1, 2
152
+            // MySQL numbers columns 1, 2, 3
153
+            switch ($value['dir']) {
154
+            case 'asc':
155
+                $order_by .= (1 + $value['column']) . " ASC ";
156
+                break;
157
+            case 'desc':
158
+                $order_by .= (1 + $value['column']) . " DESC ";
159
+                break;
160
+            }
161
+        }
162
+    } else {
163
+        $order_by = " ORDER BY 1 DESC";
164
+    }
165
+
166
+    if ($length) {
167
+        Auth::user()->setPreference('admin_site_change_page_size', $length);
168
+        $limit          = " LIMIT :limit OFFSET :offset";
169
+        $args['limit']  = $length;
170
+        $args['offset'] = $start;
171
+    } else {
172
+        $limit = "";
173
+    }
174
+
175
+    // This becomes a JSON list, not array, so need to fetch with numeric keys.
176
+    $rows = Database::prepare($sql_select . $where . $order_by . $limit)->execute($args)->fetchAll(PDO::FETCH_OBJ);
177
+    // Total filtered/unfiltered rows
178
+    $recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
179
+    $recordsTotal    = (int) Database::prepare("SELECT COUNT(*) FROM `##change`")->fetchOne();
180
+
181
+    $data      = array();
182
+    $algorithm = new MyersDiff;
183
+
184
+    foreach ($rows as $row) {
185
+        $old_lines = preg_split('/[\n]+/', $row->old_gedcom, -1, PREG_SPLIT_NO_EMPTY);
186
+        $new_lines = preg_split('/[\n]+/', $row->new_gedcom, -1, PREG_SPLIT_NO_EMPTY);
187
+
188
+        $differences = $algorithm->calculate($old_lines, $new_lines);
189
+        $diff_lines  = array();
190
+
191
+        foreach ($differences as $difference) {
192
+            switch ($difference[1]) {
193
+            case MyersDiff::DELETE:
194
+                $diff_lines[] = '<del>' . $difference[0] . '</del>';
195
+                break;
196
+            case MyersDiff::INSERT:
197
+                $diff_lines[] = '<ins>' . $difference[0] . '</ins>';
198
+                break;
199
+            default:
200
+                $diff_lines[] = $difference[0];
201
+            }
202
+        }
203
+
204
+        // Only convert valid xrefs to links
205
+        $record = GedcomRecord::getInstance($row->xref, Tree::findByName($gedc));
206
+        $data[] = array(
207
+            $row->change_id,
208
+            $row->change_time,
209
+            I18N::translate($row->status),
210
+            $record ? '<a href="' . $record->getHtmlUrl() . '">' . $record->getXref() . '</a>' : $row->xref,
211
+            '<div class="gedcom-data" dir="ltr">' .
212
+                preg_replace_callback('/@(' . WT_REGEX_XREF . ')@/',
213
+                    function ($match) use ($gedc) {
214
+                        $record = GedcomRecord::getInstance($match[1], Tree::findByName($gedc));
215
+
216
+                        return $record ? '<a href="#" onclick="return edit_raw(\'' . $match[1] . '\');">' . $match[0] . '</a>' : $match[0];
217
+                    },
218
+                    implode("\n", $diff_lines)
219
+                ) .
220
+            '</div>',
221
+            $row->user_name,
222
+            $row->gedcom_name,
223
+        );
224
+    }
225
+
226
+    header('Content-type: application/json');
227
+    // See http://www.datatables.net/usage/server-side
228
+    echo json_encode(array(
229
+        'draw'            => Filter::getInteger('draw'),
230
+        'recordsTotal'    => $recordsTotal,
231
+        'recordsFiltered' => $recordsFiltered,
232
+        'data'            => $data,
233
+    ));
234
+
235
+    return;
236 236
 }
237 237
 
238 238
 $controller
239
-	->pageHeader()
240
-	->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
241
-	->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
242
-	->addExternalJavascript(WT_MOMENT_JS_URL)
243
-	->addExternalJavascript(WT_BOOTSTRAP_DATETIMEPICKER_JS_URL)
244
-	->addInlineJavascript('
239
+    ->pageHeader()
240
+    ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
241
+    ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
242
+    ->addExternalJavascript(WT_MOMENT_JS_URL)
243
+    ->addExternalJavascript(WT_BOOTSTRAP_DATETIMEPICKER_JS_URL)
244
+    ->addInlineJavascript('
245 245
 		jQuery(".table-site-changes").dataTable( {
246 246
 			processing: true,
247 247
 			serverSide: true,
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
 $users_array = array();
282 282
 foreach (User::all() as $tmp_user) {
283
-	$users_array[$tmp_user->getUserName()] = $tmp_user->getUserName();
283
+    $users_array[$tmp_user->getUserName()] = $tmp_user->getUserName();
284 284
 }
285 285
 
286 286
 ?>
Please login to merge, or discard this patch.
admin_users.php 1 patch
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -36,248 +36,248 @@  discard block
 block discarded – undo
36 36
 
37 37
 // Valid values for form variables
38 38
 $ALL_EDIT_OPTIONS = array(
39
-	'none'   => /* I18N: Listbox entry; name of a role */ I18N::translate('Visitor'),
40
-	'access' => /* I18N: Listbox entry; name of a role */ I18N::translate('Member'),
41
-	'edit'   => /* I18N: Listbox entry; name of a role */ I18N::translate('Editor'),
42
-	'accept' => /* I18N: Listbox entry; name of a role */ I18N::translate('Moderator'),
43
-	'admin'  => /* I18N: Listbox entry; name of a role */ I18N::translate('Manager'),
39
+    'none'   => /* I18N: Listbox entry; name of a role */ I18N::translate('Visitor'),
40
+    'access' => /* I18N: Listbox entry; name of a role */ I18N::translate('Member'),
41
+    'edit'   => /* I18N: Listbox entry; name of a role */ I18N::translate('Editor'),
42
+    'accept' => /* I18N: Listbox entry; name of a role */ I18N::translate('Moderator'),
43
+    'admin'  => /* I18N: Listbox entry; name of a role */ I18N::translate('Manager'),
44 44
 );
45 45
 
46 46
 // Form actions
47 47
 switch (Filter::post('action')) {
48 48
 case 'save':
49
-	if (Filter::checkCsrf()) {
50
-		$user_id        = Filter::postInteger('user_id');
51
-		$user           = User::find($user_id);
52
-		$username       = Filter::post('username');
53
-		$real_name      = Filter::post('real_name');
54
-		$email          = Filter::postEmail('email');
55
-		$pass1          = Filter::post('pass1', WT_REGEX_PASSWORD);
56
-		$pass2          = Filter::post('pass2', WT_REGEX_PASSWORD);
57
-		$theme          = Filter::post('theme', implode('|', array_keys(Theme::themeNames())), '');
58
-		$language       = Filter::post('language');
59
-		$timezone       = Filter::post('timezone');
60
-		$contact_method = Filter::post('contact_method');
61
-		$comment        = Filter::post('comment');
62
-		$auto_accept    = Filter::postBool('auto_accept');
63
-		$canadmin       = Filter::postBool('canadmin');
64
-		$visible_online = Filter::postBool('visible_online');
65
-		$verified       = Filter::postBool('verified');
66
-		$approved       = Filter::postBool('approved');
67
-
68
-		if ($user_id === 0) {
69
-			// Create a new user
70
-			if (User::findByUserName($username)) {
71
-				FlashMessages::addMessage(I18N::translate('Duplicate username. A user with that username already exists. Please choose another username.'));
72
-			} elseif (User::findByEmail($email)) {
73
-				FlashMessages::addMessage(I18N::translate('Duplicate email address. A user with that email already exists.'));
74
-			} elseif ($pass1 !== $pass2) {
75
-				FlashMessages::addMessage(I18N::translate('The passwords do not match.'));
76
-			} else {
77
-				$user = User::create($username, $real_name, $email, $pass1);
78
-				$user->setPreference('reg_timestamp', date('U'))->setPreference('sessiontime', '0');
79
-				Log::addAuthenticationLog('User ->' . $username . '<- created');
80
-			}
81
-		} else {
82
-			$user = User::find($user_id);
83
-			if ($user && $username && $real_name) {
84
-				$user->setEmail($email);
85
-				$user->setUserName($username);
86
-				$user->setRealName($real_name);
87
-				if ($pass1 !== null && $pass1 === $pass2) {
88
-					$user->setPassword($pass1);
89
-				}
90
-			}
91
-		}
92
-
93
-		if ($user) {
94
-			// Approving for the first time? Send a confirmation email
95
-			if ($approved && !$user->getPreference('verified_by_admin') && $user->getPreference('sessiontime') == 0) {
96
-				I18N::init($user->getPreference('language'));
97
-				Mail::systemMessage(
98
-					$WT_TREE,
99
-					$user,
100
-					I18N::translate('Approval of account at %s', WT_BASE_URL),
101
-					I18N::translate('The administrator at the webtrees site %s has approved your application for an account. You may now sign in by accessing the following link: %s', WT_BASE_URL, WT_BASE_URL)
102
-				);
103
-			}
104
-
105
-			$user
106
-				->setPreference('theme', $theme)
107
-				->setPreference('language', $language)
108
-				->setPreference('TIMEZONE', $timezone)
109
-				->setPreference('contactmethod', $contact_method)
110
-				->setPreference('comment', $comment)
111
-				->setPreference('auto_accept', $auto_accept ? '1' : '0')
112
-				->setPreference('visibleonline', $visible_online ? '1' : '0')
113
-				->setPreference('verified', $verified ? '1' : '0')
114
-				->setPreference('verified_by_admin', $approved ? '1' : '0');
115
-
116
-			// We cannot change our own admin status. Another admin will need to do it.
117
-			if ($user->getUserId() !== Auth::id()) {
118
-				$user->setPreference('canadmin', $canadmin ? '1' : '0');
119
-			}
120
-
121
-			foreach (Tree::getAll() as $tree) {
122
-				$tree->setUserPreference($user, 'gedcomid', Filter::post('gedcomid' . $tree->getTreeId(), WT_REGEX_XREF));
123
-				$tree->setUserPreference($user, 'canedit', Filter::post('canedit' . $tree->getTreeId(), implode('|', array_keys($ALL_EDIT_OPTIONS))));
124
-				if (Filter::post('gedcomid' . $tree->getTreeId(), WT_REGEX_XREF)) {
125
-					$tree->setUserPreference($user, 'RELATIONSHIP_PATH_LENGTH', Filter::postInteger('RELATIONSHIP_PATH_LENGTH' . $tree->getTreeId(), 0, 10, 0));
126
-				} else {
127
-					// Do not allow a path length to be set if the individual ID is not
128
-					$tree->setUserPreference($user, 'RELATIONSHIP_PATH_LENGTH', null);
129
-				}
130
-			}
131
-		}
132
-	}
133
-
134
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
135
-
136
-	return;
49
+    if (Filter::checkCsrf()) {
50
+        $user_id        = Filter::postInteger('user_id');
51
+        $user           = User::find($user_id);
52
+        $username       = Filter::post('username');
53
+        $real_name      = Filter::post('real_name');
54
+        $email          = Filter::postEmail('email');
55
+        $pass1          = Filter::post('pass1', WT_REGEX_PASSWORD);
56
+        $pass2          = Filter::post('pass2', WT_REGEX_PASSWORD);
57
+        $theme          = Filter::post('theme', implode('|', array_keys(Theme::themeNames())), '');
58
+        $language       = Filter::post('language');
59
+        $timezone       = Filter::post('timezone');
60
+        $contact_method = Filter::post('contact_method');
61
+        $comment        = Filter::post('comment');
62
+        $auto_accept    = Filter::postBool('auto_accept');
63
+        $canadmin       = Filter::postBool('canadmin');
64
+        $visible_online = Filter::postBool('visible_online');
65
+        $verified       = Filter::postBool('verified');
66
+        $approved       = Filter::postBool('approved');
67
+
68
+        if ($user_id === 0) {
69
+            // Create a new user
70
+            if (User::findByUserName($username)) {
71
+                FlashMessages::addMessage(I18N::translate('Duplicate username. A user with that username already exists. Please choose another username.'));
72
+            } elseif (User::findByEmail($email)) {
73
+                FlashMessages::addMessage(I18N::translate('Duplicate email address. A user with that email already exists.'));
74
+            } elseif ($pass1 !== $pass2) {
75
+                FlashMessages::addMessage(I18N::translate('The passwords do not match.'));
76
+            } else {
77
+                $user = User::create($username, $real_name, $email, $pass1);
78
+                $user->setPreference('reg_timestamp', date('U'))->setPreference('sessiontime', '0');
79
+                Log::addAuthenticationLog('User ->' . $username . '<- created');
80
+            }
81
+        } else {
82
+            $user = User::find($user_id);
83
+            if ($user && $username && $real_name) {
84
+                $user->setEmail($email);
85
+                $user->setUserName($username);
86
+                $user->setRealName($real_name);
87
+                if ($pass1 !== null && $pass1 === $pass2) {
88
+                    $user->setPassword($pass1);
89
+                }
90
+            }
91
+        }
92
+
93
+        if ($user) {
94
+            // Approving for the first time? Send a confirmation email
95
+            if ($approved && !$user->getPreference('verified_by_admin') && $user->getPreference('sessiontime') == 0) {
96
+                I18N::init($user->getPreference('language'));
97
+                Mail::systemMessage(
98
+                    $WT_TREE,
99
+                    $user,
100
+                    I18N::translate('Approval of account at %s', WT_BASE_URL),
101
+                    I18N::translate('The administrator at the webtrees site %s has approved your application for an account. You may now sign in by accessing the following link: %s', WT_BASE_URL, WT_BASE_URL)
102
+                );
103
+            }
104
+
105
+            $user
106
+                ->setPreference('theme', $theme)
107
+                ->setPreference('language', $language)
108
+                ->setPreference('TIMEZONE', $timezone)
109
+                ->setPreference('contactmethod', $contact_method)
110
+                ->setPreference('comment', $comment)
111
+                ->setPreference('auto_accept', $auto_accept ? '1' : '0')
112
+                ->setPreference('visibleonline', $visible_online ? '1' : '0')
113
+                ->setPreference('verified', $verified ? '1' : '0')
114
+                ->setPreference('verified_by_admin', $approved ? '1' : '0');
115
+
116
+            // We cannot change our own admin status. Another admin will need to do it.
117
+            if ($user->getUserId() !== Auth::id()) {
118
+                $user->setPreference('canadmin', $canadmin ? '1' : '0');
119
+            }
120
+
121
+            foreach (Tree::getAll() as $tree) {
122
+                $tree->setUserPreference($user, 'gedcomid', Filter::post('gedcomid' . $tree->getTreeId(), WT_REGEX_XREF));
123
+                $tree->setUserPreference($user, 'canedit', Filter::post('canedit' . $tree->getTreeId(), implode('|', array_keys($ALL_EDIT_OPTIONS))));
124
+                if (Filter::post('gedcomid' . $tree->getTreeId(), WT_REGEX_XREF)) {
125
+                    $tree->setUserPreference($user, 'RELATIONSHIP_PATH_LENGTH', Filter::postInteger('RELATIONSHIP_PATH_LENGTH' . $tree->getTreeId(), 0, 10, 0));
126
+                } else {
127
+                    // Do not allow a path length to be set if the individual ID is not
128
+                    $tree->setUserPreference($user, 'RELATIONSHIP_PATH_LENGTH', null);
129
+                }
130
+            }
131
+        }
132
+    }
133
+
134
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
135
+
136
+    return;
137 137
 }
138 138
 
139 139
 switch (Filter::get('action')) {
140 140
 case 'load_json':
141
-	// Generate an AJAX/JSON response for datatables to load a block of rows
142
-	$search = Filter::postArray('search');
143
-	$search = $search['value'];
144
-	$start  = Filter::postInteger('start');
145
-	$length = Filter::postInteger('length');
146
-	$order  = Filter::postArray('order');
147
-
148
-	$sql_select =
149
-		"SELECT SQL_CALC_FOUND_ROWS '', u.user_id, user_name, real_name, email, us1.setting_value, us2.setting_value, NULL, us3.setting_value, NULL, us4.setting_value, us5.setting_value" .
150
-		" FROM `##user` u" .
151
-		" LEFT JOIN `##user_setting` us1 ON (u.user_id=us1.user_id AND us1.setting_name='language')" .
152
-		" LEFT JOIN `##user_setting` us2 ON (u.user_id=us2.user_id AND us2.setting_name='reg_timestamp')" .
153
-		" LEFT JOIN `##user_setting` us3 ON (u.user_id=us3.user_id AND us3.setting_name='sessiontime')" .
154
-		" LEFT JOIN `##user_setting` us4 ON (u.user_id=us4.user_id AND us4.setting_name='verified')" .
155
-		" LEFT JOIN `##user_setting` us5 ON (u.user_id=us5.user_id AND us5.setting_name='verified_by_admin')" .
156
-		" WHERE u.user_id > 0";
157
-
158
-	$args = array();
159
-
160
-	if ($search) {
161
-		$sql_select .= " AND (user_name LIKE CONCAT('%', :search_1, '%') OR real_name LIKE CONCAT('%', :search_2, '%') OR email LIKE CONCAT('%', :search_3, '%'))";
162
-		$args['search_1'] = $search;
163
-		$args['search_2'] = $search;
164
-		$args['search_3'] = $search;
165
-	}
166
-
167
-	if ($order) {
168
-		$sql_select .= " ORDER BY ";
169
-		foreach ($order as $key => $value) {
170
-			if ($key > 0) {
171
-				$sql_select .= ',';
172
-			}
173
-			// Datatables numbers columns 0, 1, 2
174
-			// MySQL numbers columns 1, 2, 3
175
-			switch ($value['dir']) {
176
-			case 'asc':
177
-				$sql_select .= (1 + $value['column']) . " ASC ";
178
-				break;
179
-			case 'desc':
180
-				$sql_select .= (1 + $value['column']) . " DESC ";
181
-				break;
182
-			}
183
-		}
184
-	} else {
185
-		$sql_select = " ORDER BY 1 ASC";
186
-	}
187
-
188
-	if ($length) {
189
-		Auth::user()->setPreference('admin_users_page_size', $length);
190
-		$sql_select .= " LIMIT :limit OFFSET :offset";
191
-		$args['limit']  = $length;
192
-		$args['offset'] = $start;
193
-	}
194
-
195
-	// This becomes a JSON list, not array, so need to fetch with numeric keys.
196
-	$data = Database::prepare($sql_select)->execute($args)->fetchAll(PDO::FETCH_NUM);
197
-
198
-	$installed_languages = array();
199
-	foreach (I18N::installedLocales() as $installed_locale) {
200
-		$installed_languages[$installed_locale->languageTag()] = $installed_locale->endonym();
201
-	}
202
-
203
-	// Reformat various columns for display
204
-	foreach ($data as &$datum) {
205
-		$user_id   = $datum[1];
206
-		$user_name = $datum[2];
207
-
208
-		if ($user_id != Auth::id()) {
209
-			$admin_options = '<li><a href="#" onclick="return masquerade(' . $user_id . ')"><i class="fa fa-fw fa-user"></i> ' . /* I18N: Pretend to be another user, by logging in as them */
210
-				I18N::translate('Masquerade as this user') . '</a></li>' . '<li><a href="#" onclick="delete_user(\'' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs($user_name)) . '\', \'' . Filter::escapeJs($user_id) . '\');"><i class="fa fa-fw fa-trash-o"></i> ' . I18N::translate('Delete') . '</a></li>';
211
-		} else {
212
-			// Do not delete ourself!
213
-			$admin_options = '';
214
-		}
215
-
216
-		$datum[0] = '<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-pencil"></i> <span class="caret"></span></button><ul class="dropdown-menu" role="menu"><li><a href="?action=edit&amp;user_id=' . $user_id . '"><i class="fa fa-fw fa-pencil"></i> ' . I18N::translate('Edit') . '</a></li><li class="divider"><li><a href="index_edit.php?user_id=' . $user_id . '"><i class="fa fa-fw fa-th-large"></i> ' . I18N::translate('Change the blocks on this user’s “My page”') . '</a></li>' . $admin_options . '</ul></div>';
217
-		// $datum[1] is the user ID
218
-		// $datum[3] is the real name
219
-		$datum[3] = '<span dir="auto">' . Filter::escapeHtml($datum[3]) . '</span>';
220
-		// $datum[4] is the email address
221
-		if ($user_id != Auth::id()) {
222
-			$datum[4] = '<a href="#" onclick="return message(\'' . Filter::escapeHtml($datum[2]) . '\', \'\', \'\');">' . Filter::escapeHtml($datum[4]) . '</i></a>';
223
-		}
224
-		// $datum[2] is the username
225
-		$datum[2] = '<span dir="auto">' . Filter::escapeHtml($datum[2]) . '</span>';
226
-		// $datum[5] is the langauge
227
-		if (array_key_exists($datum[5], $installed_languages)) {
228
-			$datum[5] = $installed_languages[$datum[5]];
229
-		}
230
-		// $datum[6] is the sortable registration timestamp
231
-		$datum[7] = $datum[6] ? FunctionsDate::formatTimestamp($datum[6] + WT_TIMESTAMP_OFFSET) : '';
232
-		if (date("U") - $datum[6] > 604800 && !$datum[10]) {
233
-			$datum[7] = '<span class="red">' . $datum[7] . '</span>';
234
-		}
235
-		// $datum[8] is the sortable last-login timestamp
236
-		if ($datum[8]) {
237
-			$datum[9] = FunctionsDate::formatTimestamp($datum[8] + WT_TIMESTAMP_OFFSET) . '<br>' . I18N::timeAgo(WT_TIMESTAMP - $datum[8]);
238
-		} else {
239
-			$datum[9] = I18N::translate('Never');
240
-		}
241
-		$datum[10] = $datum[10] ? I18N::translate('yes') : I18N::translate('no');
242
-		$datum[11] = $datum[11] ? I18N::translate('yes') : I18N::translate('no');
243
-	}
244
-
245
-	// Total filtered/unfiltered rows
246
-	$recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
247
-	$recordsTotal    = User::count();
248
-
249
-	header('Content-type: application/json');
250
-	// See http://www.datatables.net/usage/server-side
251
-	echo json_encode(array(
252
-		'draw'            => Filter::getInteger('draw'),
253
-		'recordsTotal'    => $recordsTotal,
254
-		'recordsFiltered' => $recordsFiltered,
255
-		'data'            => $data,
256
-	));
257
-
258
-	return;
141
+    // Generate an AJAX/JSON response for datatables to load a block of rows
142
+    $search = Filter::postArray('search');
143
+    $search = $search['value'];
144
+    $start  = Filter::postInteger('start');
145
+    $length = Filter::postInteger('length');
146
+    $order  = Filter::postArray('order');
147
+
148
+    $sql_select =
149
+        "SELECT SQL_CALC_FOUND_ROWS '', u.user_id, user_name, real_name, email, us1.setting_value, us2.setting_value, NULL, us3.setting_value, NULL, us4.setting_value, us5.setting_value" .
150
+        " FROM `##user` u" .
151
+        " LEFT JOIN `##user_setting` us1 ON (u.user_id=us1.user_id AND us1.setting_name='language')" .
152
+        " LEFT JOIN `##user_setting` us2 ON (u.user_id=us2.user_id AND us2.setting_name='reg_timestamp')" .
153
+        " LEFT JOIN `##user_setting` us3 ON (u.user_id=us3.user_id AND us3.setting_name='sessiontime')" .
154
+        " LEFT JOIN `##user_setting` us4 ON (u.user_id=us4.user_id AND us4.setting_name='verified')" .
155
+        " LEFT JOIN `##user_setting` us5 ON (u.user_id=us5.user_id AND us5.setting_name='verified_by_admin')" .
156
+        " WHERE u.user_id > 0";
157
+
158
+    $args = array();
159
+
160
+    if ($search) {
161
+        $sql_select .= " AND (user_name LIKE CONCAT('%', :search_1, '%') OR real_name LIKE CONCAT('%', :search_2, '%') OR email LIKE CONCAT('%', :search_3, '%'))";
162
+        $args['search_1'] = $search;
163
+        $args['search_2'] = $search;
164
+        $args['search_3'] = $search;
165
+    }
166
+
167
+    if ($order) {
168
+        $sql_select .= " ORDER BY ";
169
+        foreach ($order as $key => $value) {
170
+            if ($key > 0) {
171
+                $sql_select .= ',';
172
+            }
173
+            // Datatables numbers columns 0, 1, 2
174
+            // MySQL numbers columns 1, 2, 3
175
+            switch ($value['dir']) {
176
+            case 'asc':
177
+                $sql_select .= (1 + $value['column']) . " ASC ";
178
+                break;
179
+            case 'desc':
180
+                $sql_select .= (1 + $value['column']) . " DESC ";
181
+                break;
182
+            }
183
+        }
184
+    } else {
185
+        $sql_select = " ORDER BY 1 ASC";
186
+    }
187
+
188
+    if ($length) {
189
+        Auth::user()->setPreference('admin_users_page_size', $length);
190
+        $sql_select .= " LIMIT :limit OFFSET :offset";
191
+        $args['limit']  = $length;
192
+        $args['offset'] = $start;
193
+    }
194
+
195
+    // This becomes a JSON list, not array, so need to fetch with numeric keys.
196
+    $data = Database::prepare($sql_select)->execute($args)->fetchAll(PDO::FETCH_NUM);
197
+
198
+    $installed_languages = array();
199
+    foreach (I18N::installedLocales() as $installed_locale) {
200
+        $installed_languages[$installed_locale->languageTag()] = $installed_locale->endonym();
201
+    }
202
+
203
+    // Reformat various columns for display
204
+    foreach ($data as &$datum) {
205
+        $user_id   = $datum[1];
206
+        $user_name = $datum[2];
207
+
208
+        if ($user_id != Auth::id()) {
209
+            $admin_options = '<li><a href="#" onclick="return masquerade(' . $user_id . ')"><i class="fa fa-fw fa-user"></i> ' . /* I18N: Pretend to be another user, by logging in as them */
210
+                I18N::translate('Masquerade as this user') . '</a></li>' . '<li><a href="#" onclick="delete_user(\'' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs($user_name)) . '\', \'' . Filter::escapeJs($user_id) . '\');"><i class="fa fa-fw fa-trash-o"></i> ' . I18N::translate('Delete') . '</a></li>';
211
+        } else {
212
+            // Do not delete ourself!
213
+            $admin_options = '';
214
+        }
215
+
216
+        $datum[0] = '<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-pencil"></i> <span class="caret"></span></button><ul class="dropdown-menu" role="menu"><li><a href="?action=edit&amp;user_id=' . $user_id . '"><i class="fa fa-fw fa-pencil"></i> ' . I18N::translate('Edit') . '</a></li><li class="divider"><li><a href="index_edit.php?user_id=' . $user_id . '"><i class="fa fa-fw fa-th-large"></i> ' . I18N::translate('Change the blocks on this user’s “My page”') . '</a></li>' . $admin_options . '</ul></div>';
217
+        // $datum[1] is the user ID
218
+        // $datum[3] is the real name
219
+        $datum[3] = '<span dir="auto">' . Filter::escapeHtml($datum[3]) . '</span>';
220
+        // $datum[4] is the email address
221
+        if ($user_id != Auth::id()) {
222
+            $datum[4] = '<a href="#" onclick="return message(\'' . Filter::escapeHtml($datum[2]) . '\', \'\', \'\');">' . Filter::escapeHtml($datum[4]) . '</i></a>';
223
+        }
224
+        // $datum[2] is the username
225
+        $datum[2] = '<span dir="auto">' . Filter::escapeHtml($datum[2]) . '</span>';
226
+        // $datum[5] is the langauge
227
+        if (array_key_exists($datum[5], $installed_languages)) {
228
+            $datum[5] = $installed_languages[$datum[5]];
229
+        }
230
+        // $datum[6] is the sortable registration timestamp
231
+        $datum[7] = $datum[6] ? FunctionsDate::formatTimestamp($datum[6] + WT_TIMESTAMP_OFFSET) : '';
232
+        if (date("U") - $datum[6] > 604800 && !$datum[10]) {
233
+            $datum[7] = '<span class="red">' . $datum[7] . '</span>';
234
+        }
235
+        // $datum[8] is the sortable last-login timestamp
236
+        if ($datum[8]) {
237
+            $datum[9] = FunctionsDate::formatTimestamp($datum[8] + WT_TIMESTAMP_OFFSET) . '<br>' . I18N::timeAgo(WT_TIMESTAMP - $datum[8]);
238
+        } else {
239
+            $datum[9] = I18N::translate('Never');
240
+        }
241
+        $datum[10] = $datum[10] ? I18N::translate('yes') : I18N::translate('no');
242
+        $datum[11] = $datum[11] ? I18N::translate('yes') : I18N::translate('no');
243
+    }
244
+
245
+    // Total filtered/unfiltered rows
246
+    $recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
247
+    $recordsTotal    = User::count();
248
+
249
+    header('Content-type: application/json');
250
+    // See http://www.datatables.net/usage/server-side
251
+    echo json_encode(array(
252
+        'draw'            => Filter::getInteger('draw'),
253
+        'recordsTotal'    => $recordsTotal,
254
+        'recordsFiltered' => $recordsFiltered,
255
+        'data'            => $data,
256
+    ));
257
+
258
+    return;
259 259
 
260 260
 case 'edit':
261
-	$user_id = Filter::getInteger('user_id');
262
-
263
-	if ($user_id === 0) {
264
-		$controller->setPageTitle(I18N::translate('Add a user'));
265
-		$tmp            = new \stdClass;
266
-		$tmp->user_id   = '';
267
-		$tmp->user_name = '';
268
-		$tmp->real_name = '';
269
-		$tmp->email     = '';
270
-		$user           = new User($tmp);
271
-	} else {
272
-		$controller->setPageTitle(I18N::translate('Edit the user'));
273
-		$user = User::find($user_id);
274
-	}
275
-
276
-	$controller
277
-		->pageHeader()
278
-		->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
279
-		->addInlineJavascript('autocomplete();')
280
-		->addInlineJavascript('
261
+    $user_id = Filter::getInteger('user_id');
262
+
263
+    if ($user_id === 0) {
264
+        $controller->setPageTitle(I18N::translate('Add a user'));
265
+        $tmp            = new \stdClass;
266
+        $tmp->user_id   = '';
267
+        $tmp->user_name = '';
268
+        $tmp->real_name = '';
269
+        $tmp->email     = '';
270
+        $user           = new User($tmp);
271
+    } else {
272
+        $controller->setPageTitle(I18N::translate('Edit the user'));
273
+        $user = User::find($user_id);
274
+    }
275
+
276
+    $controller
277
+        ->pageHeader()
278
+        ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
279
+        ->addInlineJavascript('autocomplete();')
280
+        ->addInlineJavascript('
281 281
 			jQuery(".relpath").change(function() {
282 282
 				var fieldIDx = jQuery(this).attr("id");
283 283
 				var idNum = fieldIDx.replace("RELATIONSHIP_PATH_LENGTH","");
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 			}
293 293
 		');
294 294
 
295
-	?>
295
+    ?>
296 296
 	<ol class="breadcrumb small">
297 297
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
298 298
 		<li><a href="admin_users.php"><?php echo I18N::translate('User administration'); ?></a></li>
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 				<?php echo FunctionsEdit::editFieldContact('contact_method', $user->getPreference('contactmethod')); ?>
475 475
 				<p class="small text-muted">
476 476
 					<?php echo /* I18N: Help text for the “Preferred contact method” configuration setting */
477
-					I18N::translate('Site members can send each other messages. You can choose to how these messages are sent to you, or choose not receive them at all.'); ?>
477
+                    I18N::translate('Site members can send each other messages. You can choose to how these messages are sent to you, or choose not receive them at all.'); ?>
478 478
 				</p>
479 479
 			</div>
480 480
 		</div>
@@ -656,15 +656,15 @@  discard block
 block discarded – undo
656 656
 	</form>
657 657
 	<?php
658 658
 
659
-	return;
659
+    return;
660 660
 
661 661
 case 'cleanup':
662 662
 
663
-	$controller
664
-		->setPageTitle(I18N::translate('Delete inactive users'))
665
-		->pageHeader();
663
+    $controller
664
+        ->setPageTitle(I18N::translate('Delete inactive users'))
665
+        ->pageHeader();
666 666
 
667
-	?>
667
+    ?>
668 668
 	<ol class="breadcrumb small">
669 669
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
670 670
 		<li><a href="admin_users.php"><?php echo I18N::translate('User administration'); ?></a></li>
@@ -675,30 +675,30 @@  discard block
 block discarded – undo
675 675
 	<form method="post" action="?action=cleanup2">
676 676
 	<table class="table table-bordered">
677 677
 	<?php
678
-	// Check for idle users
679
-	$month = Filter::getInteger('month', 1, 12, 6);
680
-	echo '<tr><th colspan="2">', I18N::translate('Number of months since the last sign-in for a user’s account to be considered inactive: '), '</th>';
681
-	echo '<td><select onchange="document.location=options[selectedIndex].value;">';
682
-	for ($i = 1; $i <= 12; $i++) {
683
-		echo '<option value="admin_users.php?action=cleanup&amp;month=' . $i . '" ';
684
-		if ($i === $month) {
685
-			echo 'selected';
686
-		}
687
-		echo '>', $i, '</option>';
688
-	}
689
-	echo '</select></td></tr>';
690
-
691
-	// Check users not logged in too long
692
-	$ucnt = 0;
693
-	foreach (User::all() as $user) {
694
-		if ($user->getPreference('sessiontime') === '0') {
695
-			$datelogin = (int) $user->getPreference('reg_timestamp');
696
-		} else {
697
-			$datelogin = (int) $user->getPreference('sessiontime');
698
-		}
699
-		if (mktime(0, 0, 0, (int) date('m') - $month, (int) date('d'), (int) date('Y')) > $datelogin && $user->getPreference('verified') && $user->getPreference('verified_by_admin')) {
700
-			$ucnt++;
701
-			?>
678
+    // Check for idle users
679
+    $month = Filter::getInteger('month', 1, 12, 6);
680
+    echo '<tr><th colspan="2">', I18N::translate('Number of months since the last sign-in for a user’s account to be considered inactive: '), '</th>';
681
+    echo '<td><select onchange="document.location=options[selectedIndex].value;">';
682
+    for ($i = 1; $i <= 12; $i++) {
683
+        echo '<option value="admin_users.php?action=cleanup&amp;month=' . $i . '" ';
684
+        if ($i === $month) {
685
+            echo 'selected';
686
+        }
687
+        echo '>', $i, '</option>';
688
+    }
689
+    echo '</select></td></tr>';
690
+
691
+    // Check users not logged in too long
692
+    $ucnt = 0;
693
+    foreach (User::all() as $user) {
694
+        if ($user->getPreference('sessiontime') === '0') {
695
+            $datelogin = (int) $user->getPreference('reg_timestamp');
696
+        } else {
697
+            $datelogin = (int) $user->getPreference('sessiontime');
698
+        }
699
+        if (mktime(0, 0, 0, (int) date('m') - $month, (int) date('d'), (int) date('Y')) > $datelogin && $user->getPreference('verified') && $user->getPreference('verified_by_admin')) {
700
+            $ucnt++;
701
+            ?>
702 702
 			<tr>
703 703
 				<td>
704 704
 					<a href="?action=edit&amp;user_id=<?php echo $user->getUserId(); ?>">
@@ -715,14 +715,14 @@  discard block
 block discarded – undo
715 715
 				</td>
716 716
 			</tr>
717 717
 		<?php
718
-		}
719
-	}
720
-
721
-	// Check unverified users
722
-	foreach (User::all() as $user) {
723
-		if (((date('U') - (int) $user->getPreference('reg_timestamp')) > 604800) && !$user->getPreference('verified')) {
724
-			$ucnt++;
725
-			?>
718
+        }
719
+    }
720
+
721
+    // Check unverified users
722
+    foreach (User::all() as $user) {
723
+        if (((date('U') - (int) $user->getPreference('reg_timestamp')) > 604800) && !$user->getPreference('verified')) {
724
+            $ucnt++;
725
+            ?>
726 726
 			<tr>
727 727
 				<td>
728 728
 					<a href="?action=edit&amp;user_id=<?php echo $user->getUserId(); ?>">
@@ -739,14 +739,14 @@  discard block
 block discarded – undo
739 739
 				</td>
740 740
 			</tr>
741 741
 			<?php
742
-		}
743
-	}
744
-
745
-	// Check users not verified by admin
746
-	foreach (User::all() as $user) {
747
-		if ($user->getUserId() !== Auth::id() && !$user->getPreference('verified_by_admin') && $user->getPreference('verified')) {
748
-			$ucnt++;
749
-			?>
742
+        }
743
+    }
744
+
745
+    // Check users not verified by admin
746
+    foreach (User::all() as $user) {
747
+        if ($user->getUserId() !== Auth::id() && !$user->getPreference('verified_by_admin') && $user->getPreference('verified')) {
748
+            $ucnt++;
749
+            ?>
750 750
 			<tr>
751 751
 				<td>
752 752
 					<a href="?action=edit&amp;user_id=<?php echo $user->getUserId(); ?>">
@@ -763,9 +763,9 @@  discard block
 block discarded – undo
763 763
 				</td>
764 764
 			</tr>
765 765
 			<?php
766
-		}
767
-	}
768
-		?>
766
+        }
767
+    }
768
+        ?>
769 769
 		</table>
770 770
 		<p>
771 771
 		<?php if ($ucnt): ?>
@@ -776,25 +776,25 @@  discard block
 block discarded – undo
776 776
 		</p>
777 777
 	</form>
778 778
 	<?php
779
-	break;
779
+    break;
780 780
 
781 781
 case 'cleanup2':
782
-	foreach (User::all() as $user) {
783
-		if (Filter::post('del_' . $user->getUserId()) == '1') {
784
-			Log::addAuthenticationLog('Deleted user: ' . $user->getUserName());
785
-			$user->delete();
786
-			I18N::translate('The user %s has been deleted.', Filter::escapeHtml($user->getUserName()));
787
-		}
788
-	}
789
-
790
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
791
-	break;
782
+    foreach (User::all() as $user) {
783
+        if (Filter::post('del_' . $user->getUserId()) == '1') {
784
+            Log::addAuthenticationLog('Deleted user: ' . $user->getUserName());
785
+            $user->delete();
786
+            I18N::translate('The user %s has been deleted.', Filter::escapeHtml($user->getUserName()));
787
+        }
788
+    }
789
+
790
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
791
+    break;
792 792
 default:
793
-	$controller
794
-		->setPageTitle(I18N::translate('User administration'))
795
-		->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
796
-		->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
797
-		->addInlineJavascript('
793
+    $controller
794
+        ->setPageTitle(I18N::translate('User administration'))
795
+        ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
796
+        ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
797
+        ->addInlineJavascript('
798 798
 			jQuery(".table-user-list").dataTable({
799 799
 				' . I18N::datatablesI18N() . ',
800 800
 				stateSave: true,
@@ -828,9 +828,9 @@  discard block
 block discarded – undo
828 828
 			})
829 829
 			.fnFilter("' . Filter::get('filter') . '"); // View the details of a newly created user
830 830
 		')
831
-		->pageHeader();
831
+        ->pageHeader();
832 832
 
833
-	?>
833
+    ?>
834 834
 	<ol class="breadcrumb small">
835 835
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
836 836
 		<li class="active"><?php echo $controller->getPageTitle(); ?></li>
@@ -858,5 +858,5 @@  discard block
 block discarded – undo
858 858
 		</tbody>
859 859
 	</table>
860 860
 	<?php
861
-	break;
861
+    break;
862 862
 }
Please login to merge, or discard this patch.
admin_site_access.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -23,218 +23,218 @@  discard block
 block discarded – undo
23 23
 require './includes/session.php';
24 24
 
25 25
 $rules_display = array(
26
-	'unknown' => I18N::translate('unknown'),
27
-	'allow'   => /* I18N: An access rule - allow access to the site */ I18N::translate('allow'),
28
-	'deny'    => /* I18N: An access rule - deny access to the site */ I18N::translate('deny'),
29
-	'robot'   => /* I18N: http://en.wikipedia.org/wiki/Web_crawler */ I18N::translate('robot'),
26
+    'unknown' => I18N::translate('unknown'),
27
+    'allow'   => /* I18N: An access rule - allow access to the site */ I18N::translate('allow'),
28
+    'deny'    => /* I18N: An access rule - deny access to the site */ I18N::translate('deny'),
29
+    'robot'   => /* I18N: http://en.wikipedia.org/wiki/Web_crawler */ I18N::translate('robot'),
30 30
 );
31 31
 
32 32
 $rules_edit = array(
33
-	'unknown' => I18N::translate('unknown'),
34
-	'allow'   => /* I18N: An access rule - allow access to the site */ I18N::translate('allow'),
35
-	'deny'    => /* I18N: An access rule - deny access to the site */ I18N::translate('deny'),
36
-	'robot'   => /* I18N: http://en.wikipedia.org/wiki/Web_crawler */ I18N::translate('robot'),
33
+    'unknown' => I18N::translate('unknown'),
34
+    'allow'   => /* I18N: An access rule - allow access to the site */ I18N::translate('allow'),
35
+    'deny'    => /* I18N: An access rule - deny access to the site */ I18N::translate('deny'),
36
+    'robot'   => /* I18N: http://en.wikipedia.org/wiki/Web_crawler */ I18N::translate('robot'),
37 37
 );
38 38
 
39 39
 // Form actions
40 40
 switch (Filter::post('action')) {
41 41
 case 'save':
42
-	if (Filter::checkCsrf()) {
43
-		$site_access_rule_id = Filter::postInteger('site_access_rule_id');
44
-		$ip_address_start    = Filter::post('ip_address_start', WT_REGEX_IPV4);
45
-		$ip_address_end      = Filter::post('ip_address_end', WT_REGEX_IPV4);
46
-		$user_agent_pattern  = Filter::post('user_agent_pattern');
47
-		$rule                = Filter::post('rule', 'allow|deny|robot');
48
-		$comment             = Filter::post('comment');
49
-		$user_agent_string   = Filter::server('HTTP_USER_AGENT');
50
-		$ip_address          = WT_CLIENT_IP;
51
-
52
-		if ($ip_address_start !== null && $ip_address_end !== null && $user_agent_pattern !== null && $rule !== null) {
53
-			// This doesn't work with named placeholders. The :user_agent_string parameter is not recognised.
54
-			$oops = $rule !== 'allow' && Database::prepare(
55
-				"SELECT INET_ATON(:ip_address) BETWEEN INET_ATON(:ip_address_start) AND INET_ATON(:ip_address_end)" .
56
-				" AND :user_agent_string LIKE :user_agent_pattern"
57
-			)->execute(array(
58
-				'ip_address'         => $ip_address,
59
-				'ip_address_start'   => $ip_address_start,
60
-				'ip_address_end'     => $ip_address_end,
61
-				'user_agent_string'  => $user_agent_string,
62
-				'user_agent_pattern' => $user_agent_pattern,
63
-			))->fetchOne();
64
-
65
-			if ($oops) {
66
-				FlashMessages::addMessage(I18N::translate('You cannot create a rule which would prevent yourself from accessing the website.'), 'danger');
67
-			} elseif ($site_access_rule_id === null) {
68
-				Database::prepare(
69
-					"INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, rule, comment) VALUES (INET_ATON(:ip_address_start), INET_ATON(:ip_address_end), :user_agent_pattern, :rule, :comment)"
70
-				)->execute(array(
71
-					'ip_address_start'    => $ip_address_start,
72
-					'ip_address_end'      => $ip_address_end,
73
-					'user_agent_pattern'  => $user_agent_pattern,
74
-					'rule'                => $rule,
75
-					'comment'             => $comment,
76
-				));
77
-				FlashMessages::addMessage(I18N::translate('The website access rule has been created.'), 'success');
78
-			} else {
79
-				Database::prepare(
80
-					"UPDATE `##site_access_rule` SET ip_address_start = INET_ATON(:ip_address_start), ip_address_end = INET_ATON(:ip_address_end), user_agent_pattern = :user_agent_pattern, rule = :rule, comment = :comment WHERE site_access_rule_id = :site_access_rule_id"
81
-				)->execute(array(
82
-					'ip_address_start'    => $ip_address_start,
83
-					'ip_address_end'      => $ip_address_end,
84
-					'user_agent_pattern'  => $user_agent_pattern,
85
-					'rule'                => $rule,
86
-					'comment'             => $comment,
87
-					'site_access_rule_id' => $site_access_rule_id,
88
-				));
89
-				FlashMessages::addMessage(I18N::translate('The website access rule has been updated.'), 'success');
90
-			}
91
-		}
92
-	}
93
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
94
-
95
-	return;
42
+    if (Filter::checkCsrf()) {
43
+        $site_access_rule_id = Filter::postInteger('site_access_rule_id');
44
+        $ip_address_start    = Filter::post('ip_address_start', WT_REGEX_IPV4);
45
+        $ip_address_end      = Filter::post('ip_address_end', WT_REGEX_IPV4);
46
+        $user_agent_pattern  = Filter::post('user_agent_pattern');
47
+        $rule                = Filter::post('rule', 'allow|deny|robot');
48
+        $comment             = Filter::post('comment');
49
+        $user_agent_string   = Filter::server('HTTP_USER_AGENT');
50
+        $ip_address          = WT_CLIENT_IP;
51
+
52
+        if ($ip_address_start !== null && $ip_address_end !== null && $user_agent_pattern !== null && $rule !== null) {
53
+            // This doesn't work with named placeholders. The :user_agent_string parameter is not recognised.
54
+            $oops = $rule !== 'allow' && Database::prepare(
55
+                "SELECT INET_ATON(:ip_address) BETWEEN INET_ATON(:ip_address_start) AND INET_ATON(:ip_address_end)" .
56
+                " AND :user_agent_string LIKE :user_agent_pattern"
57
+            )->execute(array(
58
+                'ip_address'         => $ip_address,
59
+                'ip_address_start'   => $ip_address_start,
60
+                'ip_address_end'     => $ip_address_end,
61
+                'user_agent_string'  => $user_agent_string,
62
+                'user_agent_pattern' => $user_agent_pattern,
63
+            ))->fetchOne();
64
+
65
+            if ($oops) {
66
+                FlashMessages::addMessage(I18N::translate('You cannot create a rule which would prevent yourself from accessing the website.'), 'danger');
67
+            } elseif ($site_access_rule_id === null) {
68
+                Database::prepare(
69
+                    "INSERT INTO `##site_access_rule` (ip_address_start, ip_address_end, user_agent_pattern, rule, comment) VALUES (INET_ATON(:ip_address_start), INET_ATON(:ip_address_end), :user_agent_pattern, :rule, :comment)"
70
+                )->execute(array(
71
+                    'ip_address_start'    => $ip_address_start,
72
+                    'ip_address_end'      => $ip_address_end,
73
+                    'user_agent_pattern'  => $user_agent_pattern,
74
+                    'rule'                => $rule,
75
+                    'comment'             => $comment,
76
+                ));
77
+                FlashMessages::addMessage(I18N::translate('The website access rule has been created.'), 'success');
78
+            } else {
79
+                Database::prepare(
80
+                    "UPDATE `##site_access_rule` SET ip_address_start = INET_ATON(:ip_address_start), ip_address_end = INET_ATON(:ip_address_end), user_agent_pattern = :user_agent_pattern, rule = :rule, comment = :comment WHERE site_access_rule_id = :site_access_rule_id"
81
+                )->execute(array(
82
+                    'ip_address_start'    => $ip_address_start,
83
+                    'ip_address_end'      => $ip_address_end,
84
+                    'user_agent_pattern'  => $user_agent_pattern,
85
+                    'rule'                => $rule,
86
+                    'comment'             => $comment,
87
+                    'site_access_rule_id' => $site_access_rule_id,
88
+                ));
89
+                FlashMessages::addMessage(I18N::translate('The website access rule has been updated.'), 'success');
90
+            }
91
+        }
92
+    }
93
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
94
+
95
+    return;
96 96
 
97 97
 case 'delete':
98
-	if (Filter::checkCsrf()) {
99
-		$site_access_rule_id = Filter::postInteger('site_access_rule_id');
100
-		Database::prepare(
101
-			"DELETE FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
102
-		)->execute(array(
103
-			'site_access_rule_id' => $site_access_rule_id,
104
-		));
105
-		FlashMessages::addMessage(I18N::translate('The website access rule has been deleted.'), 'success');
106
-	}
107
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
108
-
109
-	return;
98
+    if (Filter::checkCsrf()) {
99
+        $site_access_rule_id = Filter::postInteger('site_access_rule_id');
100
+        Database::prepare(
101
+            "DELETE FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
102
+        )->execute(array(
103
+            'site_access_rule_id' => $site_access_rule_id,
104
+        ));
105
+        FlashMessages::addMessage(I18N::translate('The website access rule has been deleted.'), 'success');
106
+    }
107
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
108
+
109
+    return;
110 110
 }
111 111
 
112 112
 // Delete any "unknown" visitors that are now "known".
113 113
 // This could happen every time we create/update a rule.
114 114
 Database::exec(
115
-	"DELETE unknown" .
116
-	" FROM `##site_access_rule` AS unknown" .
117
-	" JOIN `##site_access_rule` AS known ON (unknown.user_agent_pattern LIKE known.user_agent_pattern)" .
118
-	" WHERE unknown.rule='unknown' AND known.rule<>'unknown'" .
119
-	" AND unknown.ip_address_start BETWEEN known.ip_address_start AND known.ip_address_end"
115
+    "DELETE unknown" .
116
+    " FROM `##site_access_rule` AS unknown" .
117
+    " JOIN `##site_access_rule` AS known ON (unknown.user_agent_pattern LIKE known.user_agent_pattern)" .
118
+    " WHERE unknown.rule='unknown' AND known.rule<>'unknown'" .
119
+    " AND unknown.ip_address_start BETWEEN known.ip_address_start AND known.ip_address_end"
120 120
 );
121 121
 
122 122
 $controller = new PageController;
123 123
 $controller
124
-	->restrictAccess(Auth::isAdmin())
125
-	->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
126
-	->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
127
-	->setPageTitle(I18N::translate('Website access rules'));
124
+    ->restrictAccess(Auth::isAdmin())
125
+    ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
126
+    ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
127
+    ->setPageTitle(I18N::translate('Website access rules'));
128 128
 
129 129
 $action = Filter::get('action');
130 130
 switch ($action) {
131 131
 case 'load':
132
-	// AJAX callback for datatables
133
-	$search = Filter::get('search');
134
-	$search = $search['value'];
135
-	$start  = Filter::getInteger('start');
136
-	$length = Filter::getInteger('length');
137
-
138
-	$sql =
139
-		"SELECT SQL_CALC_FOUND_ROWS" .
140
-		" '', INET_NTOA(ip_address_start), ip_address_start, INET_NTOA(ip_address_end), ip_address_end, user_agent_pattern, rule, comment, site_access_rule_id" .
141
-		" FROM `##site_access_rule`";
142
-	$args = array();
143
-
144
-	if ($search) {
145
-		$sql .=
146
-			" WHERE (INET_ATON(:search_1) BETWEEN ip_address_start AND ip_address_end" .
147
-			" OR INET_NTOA(ip_address_start) LIKE CONCAT('%', :search_2, '%')" .
148
-			" OR INET_NTOA(ip_address_end) LIKE CONCAT('%', :search_3, '%')" .
149
-			" OR user_agent_pattern LIKE CONCAT('%', :search_4, '%')" .
150
-			" OR comment LIKE CONCAT('%', :search_5, '%'))";
151
-		$args['search_1'] = Filter::escapeLike($search);
152
-		$args['search_2'] = Filter::escapeLike($search);
153
-		$args['search_3'] = Filter::escapeLike($search);
154
-		$args['search_4'] = Filter::escapeLike($search);
155
-		$args['search_5'] = Filter::escapeLike($search);
156
-	}
157
-
158
-	$order = Filter::getArray('order');
159
-	$sql .= ' ORDER BY';
160
-	if ($order) {
161
-		foreach ($order as $key => $value) {
162
-			if ($key > 0) {
163
-				$sql .= ',';
164
-			}
165
-			// Datatables numbers columns 0, 1, 2
166
-			// MySQL numbers columns 1, 2, 3
167
-			switch ($value['dir']) {
168
-			case 'asc':
169
-				$sql .= " :col_" . $key . " ASC";
170
-				break;
171
-			case 'desc':
172
-				$sql .= " :col_" . $key . " DESC";
173
-				break;
174
-			}
175
-			$args['col_' . $key] = 1 + $value['column'];
176
-		}
177
-	} else {
178
-		$sql .= ' 1 ASC';
179
-	}
180
-
181
-	if ($length > 0) {
182
-		$sql .= " LIMIT :length OFFSET :start";
183
-		$args['length'] = $length;
184
-		$args['start']  = $start;
185
-	}
186
-
187
-	// This becomes a JSON list, not a JSON array, so we need numeric keys.
188
-	$data = Database::prepare($sql)->execute($args)->fetchAll(PDO::FETCH_NUM);
189
-	// Reformat the data for display
190
-	foreach ($data as &$datum) {
191
-		$site_access_rule_id = $datum[8];
192
-
193
-		$datum[0] = '<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-pencil"></i> <span class="caret"></span></button><ul class="dropdown-menu" role="menu"><li><a href="?action=edit&amp;site_access_rule_id=' . $site_access_rule_id . '"><i class="fa fa-fw fa-pencil"></i> ' . I18N::translate('Edit') . '</a></li><li class="divider"><li><a href="#" onclick="if (confirm(\'' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs($datum[5])) . '\')) delete_site_access_rule(' . $site_access_rule_id . '); return false;"><i class="fa fa-fw fa-trash-o"></i> ' . I18N::translate('Delete') . '</a></li></ul></div>';
194
-		$datum[5] = '<span dir="ltr">' . $datum[5] . '</span>';
195
-		$datum[6] = $rules_display[$datum[6]];
196
-		$datum[7] = '<span dir="auto">' . $datum[7] . '</span>';
197
-	}
198
-
199
-	// Total filtered/unfiltered rows
200
-	$recordsFiltered = Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
201
-	$recordsTotal    = Database::prepare("SELECT COUNT(*) FROM `##site_access_rule`")->fetchOne();
202
-
203
-	header('Content-type: application/json');
204
-	// See http://www.datatables.net/usage/server-side
205
-	echo json_encode(array(
206
-		'draw'            => Filter::getInteger('draw'),
207
-		'recordsTotal'    => $recordsTotal,
208
-		'recordsFiltered' => $recordsFiltered,
209
-		'data'            => $data,
210
-	));
211
-	break;
132
+    // AJAX callback for datatables
133
+    $search = Filter::get('search');
134
+    $search = $search['value'];
135
+    $start  = Filter::getInteger('start');
136
+    $length = Filter::getInteger('length');
137
+
138
+    $sql =
139
+        "SELECT SQL_CALC_FOUND_ROWS" .
140
+        " '', INET_NTOA(ip_address_start), ip_address_start, INET_NTOA(ip_address_end), ip_address_end, user_agent_pattern, rule, comment, site_access_rule_id" .
141
+        " FROM `##site_access_rule`";
142
+    $args = array();
143
+
144
+    if ($search) {
145
+        $sql .=
146
+            " WHERE (INET_ATON(:search_1) BETWEEN ip_address_start AND ip_address_end" .
147
+            " OR INET_NTOA(ip_address_start) LIKE CONCAT('%', :search_2, '%')" .
148
+            " OR INET_NTOA(ip_address_end) LIKE CONCAT('%', :search_3, '%')" .
149
+            " OR user_agent_pattern LIKE CONCAT('%', :search_4, '%')" .
150
+            " OR comment LIKE CONCAT('%', :search_5, '%'))";
151
+        $args['search_1'] = Filter::escapeLike($search);
152
+        $args['search_2'] = Filter::escapeLike($search);
153
+        $args['search_3'] = Filter::escapeLike($search);
154
+        $args['search_4'] = Filter::escapeLike($search);
155
+        $args['search_5'] = Filter::escapeLike($search);
156
+    }
157
+
158
+    $order = Filter::getArray('order');
159
+    $sql .= ' ORDER BY';
160
+    if ($order) {
161
+        foreach ($order as $key => $value) {
162
+            if ($key > 0) {
163
+                $sql .= ',';
164
+            }
165
+            // Datatables numbers columns 0, 1, 2
166
+            // MySQL numbers columns 1, 2, 3
167
+            switch ($value['dir']) {
168
+            case 'asc':
169
+                $sql .= " :col_" . $key . " ASC";
170
+                break;
171
+            case 'desc':
172
+                $sql .= " :col_" . $key . " DESC";
173
+                break;
174
+            }
175
+            $args['col_' . $key] = 1 + $value['column'];
176
+        }
177
+    } else {
178
+        $sql .= ' 1 ASC';
179
+    }
180
+
181
+    if ($length > 0) {
182
+        $sql .= " LIMIT :length OFFSET :start";
183
+        $args['length'] = $length;
184
+        $args['start']  = $start;
185
+    }
186
+
187
+    // This becomes a JSON list, not a JSON array, so we need numeric keys.
188
+    $data = Database::prepare($sql)->execute($args)->fetchAll(PDO::FETCH_NUM);
189
+    // Reformat the data for display
190
+    foreach ($data as &$datum) {
191
+        $site_access_rule_id = $datum[8];
192
+
193
+        $datum[0] = '<div class="btn-group"><button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-pencil"></i> <span class="caret"></span></button><ul class="dropdown-menu" role="menu"><li><a href="?action=edit&amp;site_access_rule_id=' . $site_access_rule_id . '"><i class="fa fa-fw fa-pencil"></i> ' . I18N::translate('Edit') . '</a></li><li class="divider"><li><a href="#" onclick="if (confirm(\'' . I18N::translate('Are you sure you want to delete “%s”?', Filter::escapeJs($datum[5])) . '\')) delete_site_access_rule(' . $site_access_rule_id . '); return false;"><i class="fa fa-fw fa-trash-o"></i> ' . I18N::translate('Delete') . '</a></li></ul></div>';
194
+        $datum[5] = '<span dir="ltr">' . $datum[5] . '</span>';
195
+        $datum[6] = $rules_display[$datum[6]];
196
+        $datum[7] = '<span dir="auto">' . $datum[7] . '</span>';
197
+    }
198
+
199
+    // Total filtered/unfiltered rows
200
+    $recordsFiltered = Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
201
+    $recordsTotal    = Database::prepare("SELECT COUNT(*) FROM `##site_access_rule`")->fetchOne();
202
+
203
+    header('Content-type: application/json');
204
+    // See http://www.datatables.net/usage/server-side
205
+    echo json_encode(array(
206
+        'draw'            => Filter::getInteger('draw'),
207
+        'recordsTotal'    => $recordsTotal,
208
+        'recordsFiltered' => $recordsFiltered,
209
+        'data'            => $data,
210
+    ));
211
+    break;
212 212
 
213 213
 case 'edit':
214 214
 case 'create':
215
-	if (Filter::get('action') === 'edit') {
216
-		$controller->setPageTitle(I18N::translate('Edit a website access rule'));
217
-	} else {
218
-		$controller->setPageTitle(I18N::translate('Create a website access rule'));
219
-	}
220
-
221
-	$controller->pageHeader();
222
-
223
-	$site_access_rule = Database::prepare(
224
-		"SELECT site_access_rule_id, INET_NTOA(ip_address_start) AS ip_address_start, INET_NTOA(ip_address_end) AS ip_address_end, user_agent_pattern, rule, comment" .
225
-		" FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
226
-	)->execute(array(
227
-		'site_access_rule_id' => Filter::getInteger('site_access_rule_id'),
228
-	))->fetchOneRow();
229
-
230
-	$site_access_rule_id = $site_access_rule ? $site_access_rule->site_access_rule_id : null;
231
-	$ip_address_start    = $site_access_rule ? $site_access_rule->ip_address_start : '0.0.0.0';
232
-	$ip_address_end      = $site_access_rule ? $site_access_rule->ip_address_end : '255.255.255.255';
233
-	$user_agent_pattern  = $site_access_rule ? $site_access_rule->user_agent_pattern : '%';
234
-	$rule                = $site_access_rule ? $site_access_rule->rule : 'allow';
235
-	$comment             = $site_access_rule ? $site_access_rule->comment : '';
236
-
237
-	?>
215
+    if (Filter::get('action') === 'edit') {
216
+        $controller->setPageTitle(I18N::translate('Edit a website access rule'));
217
+    } else {
218
+        $controller->setPageTitle(I18N::translate('Create a website access rule'));
219
+    }
220
+
221
+    $controller->pageHeader();
222
+
223
+    $site_access_rule = Database::prepare(
224
+        "SELECT site_access_rule_id, INET_NTOA(ip_address_start) AS ip_address_start, INET_NTOA(ip_address_end) AS ip_address_end, user_agent_pattern, rule, comment" .
225
+        " FROM `##site_access_rule` WHERE site_access_rule_id = :site_access_rule_id"
226
+    )->execute(array(
227
+        'site_access_rule_id' => Filter::getInteger('site_access_rule_id'),
228
+    ))->fetchOneRow();
229
+
230
+    $site_access_rule_id = $site_access_rule ? $site_access_rule->site_access_rule_id : null;
231
+    $ip_address_start    = $site_access_rule ? $site_access_rule->ip_address_start : '0.0.0.0';
232
+    $ip_address_end      = $site_access_rule ? $site_access_rule->ip_address_end : '255.255.255.255';
233
+    $user_agent_pattern  = $site_access_rule ? $site_access_rule->user_agent_pattern : '%';
234
+    $rule                = $site_access_rule ? $site_access_rule->rule : 'allow';
235
+    $comment             = $site_access_rule ? $site_access_rule->comment : '';
236
+
237
+    ?>
238 238
 	<ol class="breadcrumb small">
239 239
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
240 240
 		<li><a href="admin_site_access.php"><?php echo I18N::translate('Website access rules'); ?></a></li>
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
 	</form>
312 312
 
313 313
 	<?php
314
-	break;
314
+    break;
315 315
 
316 316
 default:
317
-	$controller
318
-		->pageHeader()
319
-		->addInlineJavascript('
317
+    $controller
318
+        ->pageHeader()
319
+        ->addInlineJavascript('
320 320
 			jQuery.fn.dataTableExt.oSort["unicode-asc" ]=function(a,b) {return a.replace(/<[^<]*>/, "").localeCompare(b.replace(/<[^<]*>/, ""))};
321 321
 			jQuery.fn.dataTableExt.oSort["unicode-desc"]=function(a,b) {return b.replace(/<[^<]*>/, "").localeCompare(a.replace(/<[^<]*>/, ""))};
322 322
 			jQuery(".table-site-access-rules").dataTable({
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 			});
341 341
 		');
342 342
 
343
-	?>
343
+    ?>
344 344
 	<ol class="breadcrumb small">
345 345
 		<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
346 346
 		<li class="active"><?php echo $controller->getPageTitle(); ?></li>
@@ -381,5 +381,5 @@  discard block
 block discarded – undo
381 381
 		}
382 382
 	</script>
383 383
 	<?php
384
-	break;
384
+    break;
385 385
 }
Please login to merge, or discard this patch.
mediafirewall.php 1 patch
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
  * Send a “Not found” error as an image
36 36
  */
37 37
 function send404AsImage() {
38
-	$error = I18N::translate('The media file was not found in this family tree.');
38
+    $error = I18N::translate('The media file was not found in this family tree.');
39 39
 
40
-	$width  = mb_strlen($error) * 6.5 + 50;
41
-	$height = 60;
42
-	$im     = imagecreatetruecolor($width, $height); /* Create a black image */
43
-	$bgc    = imagecolorallocate($im, 255, 255, 255); /* set background color */
44
-	imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */
40
+    $width  = mb_strlen($error) * 6.5 + 50;
41
+    $height = 60;
42
+    $im     = imagecreatetruecolor($width, $height); /* Create a black image */
43
+    $bgc    = imagecolorallocate($im, 255, 255, 255); /* set background color */
44
+    imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */
45 45
 
46
-	embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left');
46
+    embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left');
47 47
 
48
-	http_response_code(404);
49
-	header('Content-Type: image/png');
50
-	imagepng($im);
51
-	imagedestroy($im);
48
+    http_response_code(404);
49
+    header('Content-Type: image/png');
50
+    imagepng($im);
51
+    imagedestroy($im);
52 52
 }
53 53
 
54 54
 /**
@@ -62,31 +62,31 @@  discard block
 block discarded – undo
62 62
  * @return resource
63 63
  */
64 64
 function applyWatermark($im, Tree $tree) {
65
-	// text to watermark with
66
-	$word1_text = $tree->getTitle();
67
-	// maximum font size for “word1” ; will be automaticaly reduced to fit in the image
68
-	$word1_maxsize = 100;
69
-	// rgb color codes for text
70
-	$word1_color = '0,0,0';
71
-	// ttf font file to use
72
-	$word1_font = WT_ROOT . Config::FONT_DEJAVU_SANS_TTF;
73
-	// vertical position for the text to past; possible values are: top, middle or bottom, across
74
-	$word1_vpos = 'across';
75
-	// horizontal position for the text to past in media file; possible values are: left, right, top2bottom, bottom2top
76
-	// this value is used only if $word1_vpos=across
77
-	$word1_hpos = 'left';
78
-
79
-	$word2_text    = $_SERVER['HTTP_HOST'];
80
-	$word2_maxsize = 20;
81
-	$word2_color   = '0,0,0';
82
-	$word2_font    = WT_ROOT . Config::FONT_DEJAVU_SANS_TTF;
83
-	$word2_vpos    = 'top';
84
-	$word2_hpos    = 'top2bottom';
85
-
86
-	embedText($im, $word1_text, $word1_maxsize, $word1_color, $word1_font, $word1_vpos, $word1_hpos);
87
-	embedText($im, $word2_text, $word2_maxsize, $word2_color, $word2_font, $word2_vpos, $word2_hpos);
88
-
89
-	return $im;
65
+    // text to watermark with
66
+    $word1_text = $tree->getTitle();
67
+    // maximum font size for “word1” ; will be automaticaly reduced to fit in the image
68
+    $word1_maxsize = 100;
69
+    // rgb color codes for text
70
+    $word1_color = '0,0,0';
71
+    // ttf font file to use
72
+    $word1_font = WT_ROOT . Config::FONT_DEJAVU_SANS_TTF;
73
+    // vertical position for the text to past; possible values are: top, middle or bottom, across
74
+    $word1_vpos = 'across';
75
+    // horizontal position for the text to past in media file; possible values are: left, right, top2bottom, bottom2top
76
+    // this value is used only if $word1_vpos=across
77
+    $word1_hpos = 'left';
78
+
79
+    $word2_text    = $_SERVER['HTTP_HOST'];
80
+    $word2_maxsize = 20;
81
+    $word2_color   = '0,0,0';
82
+    $word2_font    = WT_ROOT . Config::FONT_DEJAVU_SANS_TTF;
83
+    $word2_vpos    = 'top';
84
+    $word2_hpos    = 'top2bottom';
85
+
86
+    embedText($im, $word1_text, $word1_maxsize, $word1_color, $word1_font, $word1_vpos, $word1_hpos);
87
+    embedText($im, $word2_text, $word2_maxsize, $word2_color, $word2_font, $word2_vpos, $word2_hpos);
88
+
89
+    return $im;
90 90
 }
91 91
 
92 92
 /**
@@ -101,96 +101,96 @@  discard block
 block discarded – undo
101 101
  * @param string   $hpos
102 102
  */
103 103
 function embedText($im, $text, $maxsize, $color, $font, $vpos, $hpos) {
104
-	global $useTTF;
105
-
106
-	// there are two ways to embed text with PHP
107
-	// (preferred) using GD and FreeType you can embed text using any True Type font
108
-	// (fall back) if that is not available, you can insert basic monospaced text
109
-
110
-	$col       = explode(',', $color);
111
-	$textcolor = imagecolorallocate($im, $col[0], $col[1], $col[2]);
112
-
113
-	// make adjustments to settings that imagestring and imagestringup can’t handle
114
-	if (!$useTTF) {
115
-		// imagestringup only writes up, can’t use top2bottom
116
-		if ($hpos === 'top2bottom') {
117
-			$hpos = 'bottom2top';
118
-		}
119
-	}
120
-
121
-	$text       = I18N::reverseText($text);
122
-	$height     = imagesy($im);
123
-	$width      = imagesx($im);
124
-	$calc_angle = rad2deg(atan($height / $width));
125
-	$hypoth     = $height / sin(deg2rad($calc_angle));
126
-
127
-	// vertical and horizontal position of the text
128
-	switch ($vpos) {
129
-	default:
130
-	case 'top':
131
-		$taille   = textlength($maxsize, $width, $text);
132
-		$pos_y    = $height * 0.15 + $taille;
133
-		$pos_x    = $width * 0.15;
134
-		$rotation = 0;
135
-		break;
136
-	case 'middle':
137
-		$taille   = textlength($maxsize, $width, $text);
138
-		$pos_y    = ($height + $taille) / 2;
139
-		$pos_x    = $width * 0.15;
140
-		$rotation = 0;
141
-		break;
142
-	case 'bottom':
143
-		$taille   = textlength($maxsize, $width, $text);
144
-		$pos_y    = ($height * .85 - $taille);
145
-		$pos_x    = $width * 0.15;
146
-		$rotation = 0;
147
-		break;
148
-	case 'across':
149
-		switch ($hpos) {
150
-		default:
151
-		case 'left':
152
-			$taille   = textlength($maxsize, $hypoth, $text);
153
-			$pos_y    = ($height * .85 - $taille);
154
-			$pos_x    = $width * 0.15;
155
-			$rotation = $calc_angle;
156
-			break;
157
-		case 'right':
158
-			$taille   = textlength($maxsize, $hypoth, $text);
159
-			$pos_y    = ($height * .15 - $taille);
160
-			$pos_x    = $width * 0.85;
161
-			$rotation = $calc_angle + 180;
162
-			break;
163
-		case 'top2bottom':
164
-			$taille   = textlength($maxsize, $height, $text);
165
-			$pos_y    = ($height * .15 - $taille);
166
-			$pos_x    = ($width * .90 - $taille);
167
-			$rotation = -90;
168
-			break;
169
-		case 'bottom2top':
170
-			$taille   = textlength($maxsize, $height, $text);
171
-			$pos_y    = $height * 0.85;
172
-			$pos_x    = $width * 0.15;
173
-			$rotation = 90;
174
-			break;
175
-		}
176
-		break;
177
-	}
178
-
179
-	// apply the text
180
-	if ($useTTF) {
181
-		// if imagettftext throws errors, catch them with a custom error handler
182
-		set_error_handler('\Fisharebest\Webtrees\\imagettftextErrorHandler');
183
-		imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text);
184
-		restore_error_handler();
185
-	}
186
-	// Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false
187
-	if (!$useTTF) {
188
-		if ($rotation !== 90) {
189
-			imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor);
190
-		} else {
191
-			imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor);
192
-		}
193
-	}
104
+    global $useTTF;
105
+
106
+    // there are two ways to embed text with PHP
107
+    // (preferred) using GD and FreeType you can embed text using any True Type font
108
+    // (fall back) if that is not available, you can insert basic monospaced text
109
+
110
+    $col       = explode(',', $color);
111
+    $textcolor = imagecolorallocate($im, $col[0], $col[1], $col[2]);
112
+
113
+    // make adjustments to settings that imagestring and imagestringup can’t handle
114
+    if (!$useTTF) {
115
+        // imagestringup only writes up, can’t use top2bottom
116
+        if ($hpos === 'top2bottom') {
117
+            $hpos = 'bottom2top';
118
+        }
119
+    }
120
+
121
+    $text       = I18N::reverseText($text);
122
+    $height     = imagesy($im);
123
+    $width      = imagesx($im);
124
+    $calc_angle = rad2deg(atan($height / $width));
125
+    $hypoth     = $height / sin(deg2rad($calc_angle));
126
+
127
+    // vertical and horizontal position of the text
128
+    switch ($vpos) {
129
+    default:
130
+    case 'top':
131
+        $taille   = textlength($maxsize, $width, $text);
132
+        $pos_y    = $height * 0.15 + $taille;
133
+        $pos_x    = $width * 0.15;
134
+        $rotation = 0;
135
+        break;
136
+    case 'middle':
137
+        $taille   = textlength($maxsize, $width, $text);
138
+        $pos_y    = ($height + $taille) / 2;
139
+        $pos_x    = $width * 0.15;
140
+        $rotation = 0;
141
+        break;
142
+    case 'bottom':
143
+        $taille   = textlength($maxsize, $width, $text);
144
+        $pos_y    = ($height * .85 - $taille);
145
+        $pos_x    = $width * 0.15;
146
+        $rotation = 0;
147
+        break;
148
+    case 'across':
149
+        switch ($hpos) {
150
+        default:
151
+        case 'left':
152
+            $taille   = textlength($maxsize, $hypoth, $text);
153
+            $pos_y    = ($height * .85 - $taille);
154
+            $pos_x    = $width * 0.15;
155
+            $rotation = $calc_angle;
156
+            break;
157
+        case 'right':
158
+            $taille   = textlength($maxsize, $hypoth, $text);
159
+            $pos_y    = ($height * .15 - $taille);
160
+            $pos_x    = $width * 0.85;
161
+            $rotation = $calc_angle + 180;
162
+            break;
163
+        case 'top2bottom':
164
+            $taille   = textlength($maxsize, $height, $text);
165
+            $pos_y    = ($height * .15 - $taille);
166
+            $pos_x    = ($width * .90 - $taille);
167
+            $rotation = -90;
168
+            break;
169
+        case 'bottom2top':
170
+            $taille   = textlength($maxsize, $height, $text);
171
+            $pos_y    = $height * 0.85;
172
+            $pos_x    = $width * 0.15;
173
+            $rotation = 90;
174
+            break;
175
+        }
176
+        break;
177
+    }
178
+
179
+    // apply the text
180
+    if ($useTTF) {
181
+        // if imagettftext throws errors, catch them with a custom error handler
182
+        set_error_handler('\Fisharebest\Webtrees\\imagettftextErrorHandler');
183
+        imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text);
184
+        restore_error_handler();
185
+    }
186
+    // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false
187
+    if (!$useTTF) {
188
+        if ($rotation !== 90) {
189
+            imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor);
190
+        } else {
191
+            imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor);
192
+        }
193
+    }
194 194
 
195 195
 }
196 196
 
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
  * @return int
205 205
  */
206 206
 function textlength($t, $mxl, $text) {
207
-	$taille_c = $t;
208
-	$len      = mb_strlen($text);
209
-	while (($taille_c - 2) * $len > $mxl) {
210
-		$taille_c--;
211
-		if ($taille_c == 2) {
212
-			break;
213
-		}
214
-	}
215
-
216
-	return $taille_c;
207
+    $taille_c = $t;
208
+    $len      = mb_strlen($text);
209
+    while (($taille_c - 2) * $len > $mxl) {
210
+        $taille_c--;
211
+        if ($taille_c == 2) {
212
+            break;
213
+        }
214
+    }
215
+
216
+    return $taille_c;
217 217
 }
218 218
 
219 219
 /**
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
  * @return bool
227 227
  */
228 228
 function imagettftextErrorHandler($errno, $errstr) {
229
-	global $useTTF, $serverFilename;
230
-	// log the error
231
-	Log::addErrorLog('Media Firewall error: >' . $errno . '/' . $errstr . '< while processing file >' . $serverFilename . '<');
229
+    global $useTTF, $serverFilename;
230
+    // log the error
231
+    Log::addErrorLog('Media Firewall error: >' . $errno . '/' . $errstr . '< while processing file >' . $serverFilename . '<');
232 232
 
233
-	// change value of useTTF to false so the fallback watermarking can be used.
234
-	$useTTF = false;
233
+    // change value of useTTF to false so the fallback watermarking can be used.
234
+    $useTTF = false;
235 235
 
236
-	return true;
236
+    return true;
237 237
 }
238 238
 
239 239
 /**
@@ -244,19 +244,19 @@  discard block
 block discarded – undo
244 244
  * @return string|false
245 245
  */
246 246
 function isImageTypeSupported($reqtype) {
247
-	$supportByGD = array('jpg' => 'jpeg', 'jpeg' => 'jpeg', 'gif' => 'gif', 'png' => 'png');
248
-	$reqtype     = strtolower($reqtype);
247
+    $supportByGD = array('jpg' => 'jpeg', 'jpeg' => 'jpeg', 'gif' => 'gif', 'png' => 'png');
248
+    $reqtype     = strtolower($reqtype);
249 249
 
250
-	if (empty($supportByGD[$reqtype])) {
251
-		return false;
252
-	}
253
-	$type = $supportByGD[$reqtype];
250
+    if (empty($supportByGD[$reqtype])) {
251
+        return false;
252
+    }
253
+    $type = $supportByGD[$reqtype];
254 254
 
255
-	if (function_exists('imagecreatefrom' . $type) && function_exists('image' . $type)) {
256
-		return $type;
257
-	}
255
+    if (function_exists('imagecreatefrom' . $type) && function_exists('image' . $type)) {
256
+        return $type;
257
+    }
258 258
 
259
-	return false;
259
+    return false;
260 260
 }
261 261
 
262 262
 // this needs to be a global variable so imagettftextErrorHandler can set it
@@ -264,24 +264,24 @@  discard block
 block discarded – undo
264 264
 
265 265
 // Media object missing/private?
266 266
 if (!$media || !$media->canShow()) {
267
-	send404AsImage();
267
+    send404AsImage();
268 268
 
269
-	return;
269
+    return;
270 270
 }
271 271
 // media file somewhere else?
272 272
 if ($media->isExternal()) {
273
-	header('Location: ' . $media->getFilename());
273
+    header('Location: ' . $media->getFilename());
274 274
 
275
-	return;
275
+    return;
276 276
 }
277 277
 
278 278
 $which          = $thumb ? 'thumb' : 'main';
279 279
 $serverFilename = $media->getServerFilename($which);
280 280
 
281 281
 if (!file_exists($serverFilename)) {
282
-	send404AsImage();
282
+    send404AsImage();
283 283
 
284
-	return;
284
+    return;
285 285
 }
286 286
 
287 287
 $mimetype       = $media->mimeType();
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT';
291 291
 $expireOffset   = 3600 * 24; // tell browser to cache this image for 24 hours
292 292
 if (Filter::get('cb')) {
293
-	$expireOffset = $expireOffset * 7;
293
+    $expireOffset = $expireOffset * 7;
294 294
 } // if cb parameter was sent, cache for 7 days
295 295
 $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $expireOffset) . ' GMT';
296 296
 
@@ -298,46 +298,46 @@  discard block
 block discarded – undo
298 298
 $usewatermark = false;
299 299
 // if this image supports watermarks and the watermark module is intalled...
300 300
 if ($type) {
301
-	// if this is not a thumbnail, or WATERMARK_THUMB is true
302
-	if (($which === 'main') || $WT_TREE->getPreference('WATERMARK_THUMB')) {
303
-		// if the user’s priv’s justify it...
304
-		if (Auth::accessLevel($WT_TREE) > $WT_TREE->getPreference('SHOW_NO_WATERMARK')) {
305
-			// add a watermark
306
-			$usewatermark = true;
307
-		}
308
-	}
301
+    // if this is not a thumbnail, or WATERMARK_THUMB is true
302
+    if (($which === 'main') || $WT_TREE->getPreference('WATERMARK_THUMB')) {
303
+        // if the user’s priv’s justify it...
304
+        if (Auth::accessLevel($WT_TREE) > $WT_TREE->getPreference('SHOW_NO_WATERMARK')) {
305
+            // add a watermark
306
+            $usewatermark = true;
307
+        }
308
+    }
309 309
 }
310 310
 
311 311
 // determine whether we have enough memory to watermark this image
312 312
 if ($usewatermark) {
313
-	if (!FunctionsMedia::hasMemoryForImage($serverFilename)) {
314
-		// not enough memory to watermark this file
315
-		$usewatermark = false;
316
-	}
313
+    if (!FunctionsMedia::hasMemoryForImage($serverFilename)) {
314
+        // not enough memory to watermark this file
315
+        $usewatermark = false;
316
+    }
317 317
 }
318 318
 
319 319
 $watermarkfile     = '';
320 320
 $generatewatermark = false;
321 321
 
322 322
 if ($usewatermark) {
323
-	if ($which === 'thumb') {
324
-		$watermarkfile = WT_DATA_DIR . $WT_TREE->getPreference('MEDIA_DIRECTORY') . 'watermark/' . $WT_TREE->getName() . '/thumb/' . $media->getFilename();
325
-	} else {
326
-		$watermarkfile = WT_DATA_DIR . $WT_TREE->getPreference('MEDIA_DIRECTORY') . 'watermark/' . $WT_TREE->getName() . '/' . $media->getFilename();
327
-	}
328
-
329
-	if (!file_exists($watermarkfile)) {
330
-		// no saved watermark file exists
331
-		// generate the watermark file
332
-		$generatewatermark = true;
333
-	} else {
334
-		$watermarktime = filemtime($watermarkfile);
335
-		if ($filetime > $watermarktime) {
336
-			// if the original image was updated after the saved file was created
337
-			// generate the watermark file
338
-			$generatewatermark = true;
339
-		}
340
-	}
323
+    if ($which === 'thumb') {
324
+        $watermarkfile = WT_DATA_DIR . $WT_TREE->getPreference('MEDIA_DIRECTORY') . 'watermark/' . $WT_TREE->getName() . '/thumb/' . $media->getFilename();
325
+    } else {
326
+        $watermarkfile = WT_DATA_DIR . $WT_TREE->getPreference('MEDIA_DIRECTORY') . 'watermark/' . $WT_TREE->getName() . '/' . $media->getFilename();
327
+    }
328
+
329
+    if (!file_exists($watermarkfile)) {
330
+        // no saved watermark file exists
331
+        // generate the watermark file
332
+        $generatewatermark = true;
333
+    } else {
334
+        $watermarktime = filemtime($watermarkfile);
335
+        if ($filetime > $watermarktime) {
336
+            // if the original image was updated after the saved file was created
337
+            // generate the watermark file
338
+            $generatewatermark = true;
339
+        }
340
+    }
341 341
 }
342 342
 
343 343
 $etag = $media->getEtag($which);
@@ -345,13 +345,13 @@  discard block
 block discarded – undo
345 345
 // parse IF_MODIFIED_SINCE header from client
346 346
 $if_modified_since = 'x';
347 347
 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
348
-	$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
348
+    $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
349 349
 }
350 350
 
351 351
 // parse IF_NONE_MATCH header from client
352 352
 $if_none_match = 'x';
353 353
 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
354
-	$if_none_match = str_replace('"', '', $_SERVER['HTTP_IF_NONE_MATCH']);
354
+    $if_none_match = str_replace('"', '', $_SERVER['HTTP_IF_NONE_MATCH']);
355 355
 }
356 356
 
357 357
 // add caching headers. allow browser to cache file, but not proxy
@@ -363,12 +363,12 @@  discard block
 block discarded – undo
363 363
 // if this file is already in the user’s cache, don’t resend it
364 364
 // first check if the if_modified_since param matches
365 365
 if ($if_modified_since === $filetimeHeader) {
366
-	// then check if the etag matches
367
-	if ($if_none_match === $etag) {
368
-		http_response_code(304);
366
+    // then check if the etag matches
367
+    if ($if_none_match === $etag) {
368
+        http_response_code(304);
369 369
 
370
-		return;
371
-	}
370
+        return;
371
+    }
372 372
 }
373 373
 
374 374
 // send headers for the image
@@ -376,41 +376,41 @@  discard block
 block discarded – undo
376 376
 header('Content-Disposition: filename="' . addslashes(basename($media->getFilename())) . '"');
377 377
 
378 378
 if ($generatewatermark) {
379
-	// generate the watermarked image
380
-	$imCreateFunc = 'imagecreatefrom' . $type;
381
-	$imSendFunc   = 'image' . $type;
382
-
383
-	if (function_exists($imCreateFunc) && function_exists($imSendFunc)) {
384
-		$im = $imCreateFunc($serverFilename);
385
-		$im = applyWatermark($im, $WT_TREE);
386
-
387
-		// save the image, if preferences allow
388
-		if ($which === 'thumb' && $WT_TREE->getPreference('SAVE_WATERMARK_THUMB') || $which === 'main' && $WT_TREE->getPreference('SAVE_WATERMARK_IMAGE')) {
389
-			// make sure the folder exists
390
-			File::mkdir(dirname($watermarkfile));
391
-			// save the image
392
-			$imSendFunc($im, $watermarkfile);
393
-		}
394
-
395
-		// send the image
396
-		$imSendFunc($im);
397
-		imagedestroy($im);
398
-
399
-		return;
400
-	} else {
401
-		// this image is defective. log it
402
-		Log::addMediaLog('Media Firewall error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage());
403
-
404
-		// set usewatermark to false so image will simply be passed through below
405
-		$usewatermark = false;
406
-	}
379
+    // generate the watermarked image
380
+    $imCreateFunc = 'imagecreatefrom' . $type;
381
+    $imSendFunc   = 'image' . $type;
382
+
383
+    if (function_exists($imCreateFunc) && function_exists($imSendFunc)) {
384
+        $im = $imCreateFunc($serverFilename);
385
+        $im = applyWatermark($im, $WT_TREE);
386
+
387
+        // save the image, if preferences allow
388
+        if ($which === 'thumb' && $WT_TREE->getPreference('SAVE_WATERMARK_THUMB') || $which === 'main' && $WT_TREE->getPreference('SAVE_WATERMARK_IMAGE')) {
389
+            // make sure the folder exists
390
+            File::mkdir(dirname($watermarkfile));
391
+            // save the image
392
+            $imSendFunc($im, $watermarkfile);
393
+        }
394
+
395
+        // send the image
396
+        $imSendFunc($im);
397
+        imagedestroy($im);
398
+
399
+        return;
400
+    } else {
401
+        // this image is defective. log it
402
+        Log::addMediaLog('Media Firewall error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage());
403
+
404
+        // set usewatermark to false so image will simply be passed through below
405
+        $usewatermark = false;
406
+    }
407 407
 }
408 408
 
409 409
 // pass the image through without manipulating it
410 410
 
411 411
 if ($usewatermark) {
412
-	// the stored watermarked image is good, lets use it
413
-	$serverFilename = $watermarkfile;
412
+    // the stored watermarked image is good, lets use it
413
+    $serverFilename = $watermarkfile;
414 414
 }
415 415
 
416 416
 // determine filesize of image (could be original or watermarked version)
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 
422 422
 // Some servers disable fpassthru() and readfile()
423 423
 if (function_exists('readfile')) {
424
-	readfile($serverFilename);
424
+    readfile($serverFilename);
425 425
 } else {
426
-	$fp = fopen($serverFilename, 'rb');
427
-	if (function_exists('fpassthru')) {
428
-		fpassthru($fp);
429
-	} else {
430
-		while (!feof($fp)) {
431
-			echo fread($fp, 65536);
432
-		}
433
-	}
434
-	fclose($fp);
426
+    $fp = fopen($serverFilename, 'rb');
427
+    if (function_exists('fpassthru')) {
428
+        fpassthru($fp);
429
+    } else {
430
+        while (!feof($fp)) {
431
+            echo fread($fp, 65536);
432
+        }
433
+    }
434
+    fclose($fp);
435 435
 }
Please login to merge, or discard this patch.
login.php 1 patch
Indentation   +388 added lines, -388 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 
32 32
 // If we are already logged in, then go to the “Home page”
33 33
 if (Auth::check() && $WT_TREE) {
34
-	header('Location: ' . WT_BASE_URL);
34
+    header('Location: ' . WT_BASE_URL);
35 35
 
36
-	return;
36
+    return;
37 37
 }
38 38
 
39 39
 $controller = new PageController;
@@ -53,104 +53,104 @@  discard block
 block discarded – undo
53 53
 
54 54
 // These parameters may come from the URL which is emailed to users.
55 55
 if (!$action) {
56
-	$action = Filter::get('action');
56
+    $action = Filter::get('action');
57 57
 }
58 58
 if (!$user_name) {
59
-	$user_name = Filter::get('user_name');
59
+    $user_name = Filter::get('user_name');
60 60
 }
61 61
 if (!$user_hashcode) {
62
-	$user_hashcode = Filter::get('user_hashcode');
62
+    $user_hashcode = Filter::get('user_hashcode');
63 63
 }
64 64
 if (!$url) {
65
-	$url = Filter::get('url');
65
+    $url = Filter::get('url');
66 66
 }
67 67
 
68 68
 $message = '';
69 69
 
70 70
 switch ($action) {
71 71
 case 'login':
72
-	try {
73
-		if (!$_COOKIE) {
74
-			Log::addAuthenticationLog('Login failed (no session cookies): ' . $username);
75
-			throw new \Exception(I18N::translate('You cannot sign in because your browser does not accept cookies.'));
76
-		}
77
-
78
-		$user = User::findByIdentifier($username);
79
-
80
-		if (!$user) {
81
-			Log::addAuthenticationLog('Login failed (no such user/email): ' . $username);
82
-			throw new \Exception(I18N::translate('The username or password is incorrect.'));
83
-		}
84
-
85
-		if (!$user->checkPassword($password)) {
86
-			Log::addAuthenticationLog('Login failed (incorrect password): ' . $username);
87
-			throw new \Exception(I18N::translate('The username or password is incorrect.'));
88
-		}
89
-
90
-		if (!$user->getPreference('verified')) {
91
-			Log::addAuthenticationLog('Login failed (not verified by user): ' . $username);
92
-			throw new \Exception(I18N::translate('This account has not been verified. Please check your email for a verification message.'));
93
-		}
94
-
95
-		if (!$user->getPreference('verified_by_admin')) {
96
-			Log::addAuthenticationLog('Login failed (not approved by admin): ' . $username);
97
-			throw new \Exception(I18N::translate('This account has not been approved. Please wait for an administrator to approve it.'));
98
-		}
99
-
100
-		Auth::login($user);
101
-		Log::addAuthenticationLog('Login: ' . Auth::user()->getUserName() . '/' . Auth::user()->getRealName());
102
-		Auth::user()->setPreference('sessiontime', WT_TIMESTAMP);
103
-
104
-		Session::put('locale', Auth::user()->getPreference('language'));
105
-		Session::put('theme_id', Auth::user()->getPreference('theme'));
106
-		I18N::init(Auth::user()->getPreference('language'));
107
-
108
-		// We're logging in as an administrator
109
-		if (Auth::isAdmin()) {
110
-			// Check for updates
111
-			$latest_version_txt = Functions::fetchLatestVersion();
112
-			if (preg_match('/^[0-9.]+\|[0-9.]+\|/', $latest_version_txt)) {
113
-				list($latest_version, $earliest_version, $download_url) = explode('|', $latest_version_txt);
114
-				if (version_compare(WT_VERSION, $latest_version) < 0) {
115
-					FlashMessages::addMessage(
116
-						I18N::translate('A new version of webtrees is available.') .
117
-						' <a href="admin_site_upgrade.php"><b>' .
118
-						I18N::translate('Upgrade to webtrees %s.', '<span dir="ltr">' . $latest_version . '</span>') .
119
-						'</b></a>'
120
-					);
121
-				}
122
-			}
123
-		}
124
-
125
-		// If we were on a "home page", redirect to "my page"
126
-		if ($url === '' || strpos($url, 'index.php?ctype=gedcom') === 0) {
127
-			$url = 'index.php?ctype=user';
128
-			// Switch to a tree where we have a genealogy record (or keep to the current/default).
129
-			$tree = Database::prepare(
130
-				"SELECT gedcom_name FROM `##gedcom` JOIN `##user_gedcom_setting` USING (gedcom_id)" .
131
-				" WHERE setting_name = 'gedcomid' AND user_id = :user_id" .
132
-				" ORDER BY gedcom_id = :tree_id DESC"
133
-			)->execute(array(
134
-				'user_id' => Auth::user()->getUserId(),
135
-				'tree_id' => $WT_TREE->getTreeId(),
136
-			))->fetchOne();
137
-			$url .= '&ged=' . Filter::escapeUrl($tree);
138
-		}
139
-
140
-		// Redirect to the target URL
141
-		header('Location: ' . WT_BASE_URL . $url);
142
-
143
-		return;
144
-	} catch (\Exception $ex) {
145
-		$message = $ex->getMessage();
146
-	}
147
-	// No break;
72
+    try {
73
+        if (!$_COOKIE) {
74
+            Log::addAuthenticationLog('Login failed (no session cookies): ' . $username);
75
+            throw new \Exception(I18N::translate('You cannot sign in because your browser does not accept cookies.'));
76
+        }
77
+
78
+        $user = User::findByIdentifier($username);
79
+
80
+        if (!$user) {
81
+            Log::addAuthenticationLog('Login failed (no such user/email): ' . $username);
82
+            throw new \Exception(I18N::translate('The username or password is incorrect.'));
83
+        }
84
+
85
+        if (!$user->checkPassword($password)) {
86
+            Log::addAuthenticationLog('Login failed (incorrect password): ' . $username);
87
+            throw new \Exception(I18N::translate('The username or password is incorrect.'));
88
+        }
89
+
90
+        if (!$user->getPreference('verified')) {
91
+            Log::addAuthenticationLog('Login failed (not verified by user): ' . $username);
92
+            throw new \Exception(I18N::translate('This account has not been verified. Please check your email for a verification message.'));
93
+        }
94
+
95
+        if (!$user->getPreference('verified_by_admin')) {
96
+            Log::addAuthenticationLog('Login failed (not approved by admin): ' . $username);
97
+            throw new \Exception(I18N::translate('This account has not been approved. Please wait for an administrator to approve it.'));
98
+        }
99
+
100
+        Auth::login($user);
101
+        Log::addAuthenticationLog('Login: ' . Auth::user()->getUserName() . '/' . Auth::user()->getRealName());
102
+        Auth::user()->setPreference('sessiontime', WT_TIMESTAMP);
103
+
104
+        Session::put('locale', Auth::user()->getPreference('language'));
105
+        Session::put('theme_id', Auth::user()->getPreference('theme'));
106
+        I18N::init(Auth::user()->getPreference('language'));
107
+
108
+        // We're logging in as an administrator
109
+        if (Auth::isAdmin()) {
110
+            // Check for updates
111
+            $latest_version_txt = Functions::fetchLatestVersion();
112
+            if (preg_match('/^[0-9.]+\|[0-9.]+\|/', $latest_version_txt)) {
113
+                list($latest_version, $earliest_version, $download_url) = explode('|', $latest_version_txt);
114
+                if (version_compare(WT_VERSION, $latest_version) < 0) {
115
+                    FlashMessages::addMessage(
116
+                        I18N::translate('A new version of webtrees is available.') .
117
+                        ' <a href="admin_site_upgrade.php"><b>' .
118
+                        I18N::translate('Upgrade to webtrees %s.', '<span dir="ltr">' . $latest_version . '</span>') .
119
+                        '</b></a>'
120
+                    );
121
+                }
122
+            }
123
+        }
124
+
125
+        // If we were on a "home page", redirect to "my page"
126
+        if ($url === '' || strpos($url, 'index.php?ctype=gedcom') === 0) {
127
+            $url = 'index.php?ctype=user';
128
+            // Switch to a tree where we have a genealogy record (or keep to the current/default).
129
+            $tree = Database::prepare(
130
+                "SELECT gedcom_name FROM `##gedcom` JOIN `##user_gedcom_setting` USING (gedcom_id)" .
131
+                " WHERE setting_name = 'gedcomid' AND user_id = :user_id" .
132
+                " ORDER BY gedcom_id = :tree_id DESC"
133
+            )->execute(array(
134
+                'user_id' => Auth::user()->getUserId(),
135
+                'tree_id' => $WT_TREE->getTreeId(),
136
+            ))->fetchOne();
137
+            $url .= '&ged=' . Filter::escapeUrl($tree);
138
+        }
139
+
140
+        // Redirect to the target URL
141
+        header('Location: ' . WT_BASE_URL . $url);
142
+
143
+        return;
144
+    } catch (\Exception $ex) {
145
+        $message = $ex->getMessage();
146
+    }
147
+    // No break;
148 148
 
149 149
 default:
150
-	$controller
151
-		->setPageTitle(I18N::translate('Sign in'))
152
-		->pageHeader()
153
-		->addInlineJavascript('
150
+    $controller
151
+        ->setPageTitle(I18N::translate('Sign in'))
152
+        ->pageHeader()
153
+        ->addInlineJavascript('
154 154
 			jQuery("#new_passwd_form").hide();
155 155
 			jQuery("#passwd_click").click(function() {
156 156
 				jQuery("#new_passwd_form").slideToggle(100, function() {
@@ -160,247 +160,247 @@  discard block
 block discarded – undo
160 160
 			});
161 161
 		');
162 162
 
163
-	echo '<div id="login-page">';
164
-	echo '<div id="login-text">';
165
-
166
-	echo '<p class="center"><strong>' . I18N::translate('Welcome to this genealogy website') . '</strong></p>';
167
-
168
-	switch (Site::getPreference('WELCOME_TEXT_AUTH_MODE')) {
169
-	case 1:
170
-		echo '<p>' . I18N::translate('Anyone with a user account can access this website.') . ' ' . I18N::translate('You can apply for an account using the link below.') . '</p>';
171
-		break;
172
-	case 2:
173
-		echo '<p>' . I18N::translate('You need to be an authorized user to access this website.') . ' ' . I18N::translate('You can apply for an account using the link below.') . '</p>';
174
-		break;
175
-	case 3:
176
-		echo '<p>' . I18N::translate('You need to be a family member to access this website.') . ' ' . I18N::translate('You can apply for an account using the link below.') . '</p>';
177
-		break;
178
-	case 4:
179
-		echo '<p style="white-space: pre-wrap;">', Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE), '</p>';
180
-		break;
181
-	}
182
-
183
-	echo '</div>';
184
-	echo '<div id="login-box">';
185
-		if ($message) {
186
-			echo '<p class="error">', $message, '</p>';
187
-		}
188
-	echo '<form id="login-form" name="login-form" method="post" action="', WT_LOGIN_URL, '">
163
+    echo '<div id="login-page">';
164
+    echo '<div id="login-text">';
165
+
166
+    echo '<p class="center"><strong>' . I18N::translate('Welcome to this genealogy website') . '</strong></p>';
167
+
168
+    switch (Site::getPreference('WELCOME_TEXT_AUTH_MODE')) {
169
+    case 1:
170
+        echo '<p>' . I18N::translate('Anyone with a user account can access this website.') . ' ' . I18N::translate('You can apply for an account using the link below.') . '</p>';
171
+        break;
172
+    case 2:
173
+        echo '<p>' . I18N::translate('You need to be an authorized user to access this website.') . ' ' . I18N::translate('You can apply for an account using the link below.') . '</p>';
174
+        break;
175
+    case 3:
176
+        echo '<p>' . I18N::translate('You need to be a family member to access this website.') . ' ' . I18N::translate('You can apply for an account using the link below.') . '</p>';
177
+        break;
178
+    case 4:
179
+        echo '<p style="white-space: pre-wrap;">', Site::getPreference('WELCOME_TEXT_AUTH_MODE_' . WT_LOCALE), '</p>';
180
+        break;
181
+    }
182
+
183
+    echo '</div>';
184
+    echo '<div id="login-box">';
185
+        if ($message) {
186
+            echo '<p class="error">', $message, '</p>';
187
+        }
188
+    echo '<form id="login-form" name="login-form" method="post" action="', WT_LOGIN_URL, '">
189 189
 		<input type="hidden" name="action" value="login">
190 190
 		<input type="hidden" name="url" value="', Filter::escapeHtml($url), '">';
191
-		echo '<div>
191
+        echo '<div>
192 192
 			<label for="username">', I18N::translate('Username'),
193
-			'<input type="text" id="username" name="username" value="', Filter::escapeHtml($username), '" class="formField" autofocus>
193
+            '<input type="text" id="username" name="username" value="', Filter::escapeHtml($username), '" class="formField" autofocus>
194 194
 			</label>
195 195
 		</div>
196 196
 		<div>
197 197
 			<label for="password">', I18N::translate('Password'),
198
-				'<input type="password" id="password" name="password" class="formField">
198
+                '<input type="password" id="password" name="password" class="formField">
199 199
 			</label>
200 200
 		</div>
201 201
 		<div>
202 202
 			<input type="submit" value="', /* I18N: A button label. */ I18N::translate('sign in'), '">
203 203
 		</div>
204 204
 		';
205
-		// Emails are sent from a TREE, not from a SITE. Therefore if there is no
206
-		// tree available (initial setup or all trees private), then we can't send email.
207
-		if ($WT_TREE) {
208
-			echo '
205
+        // Emails are sent from a TREE, not from a SITE. Therefore if there is no
206
+        // tree available (initial setup or all trees private), then we can't send email.
207
+        if ($WT_TREE) {
208
+            echo '
209 209
 			<div>
210 210
 				<a href="#" id="passwd_click">', I18N::translate('Forgot password?'), '</a>
211 211
 			</div>';
212
-			if (Site::getPreference('USE_REGISTRATION_MODULE')) {
213
-				echo '<div><a href="' . WT_LOGIN_URL . '?action=register">', I18N::translate('Request a new user account'), '</a></div>';
214
-			}
215
-		}
216
-	echo '</form>';
217
-
218
-	// hidden New Password block
219
-	echo '<div id="new_passwd">
212
+            if (Site::getPreference('USE_REGISTRATION_MODULE')) {
213
+                echo '<div><a href="' . WT_LOGIN_URL . '?action=register">', I18N::translate('Request a new user account'), '</a></div>';
214
+            }
215
+        }
216
+    echo '</form>';
217
+
218
+    // hidden New Password block
219
+    echo '<div id="new_passwd">
220 220
 		<form id="new_passwd_form" name="new_passwd_form" action="' . WT_LOGIN_URL . '" method="post">
221 221
 		<input type="hidden" name="action" value="requestpw">
222 222
 		<h4>', I18N::translate('Request a new password'), '</h4>
223 223
 		<div>
224 224
 			<label for="new_passwd_username">', I18N::translate('Username or email address'),
225
-				'<input type="text" id="new_passwd_username" name="new_passwd_username" value="">
225
+                '<input type="text" id="new_passwd_username" name="new_passwd_username" value="">
226 226
 			</label>
227 227
 		</div>
228 228
 		<div><input type="submit" value="', /* I18N: A button label. */ I18N::translate('continue'), '"></div>
229 229
 		</form>
230 230
 	</div>';
231
-	echo '</div>';
231
+    echo '</div>';
232 232
 
233
-	echo '</div>';
234
-	break;
233
+    echo '</div>';
234
+    break;
235 235
 
236 236
 case 'requestpw':
237
-	$user_name = Filter::post('new_passwd_username');
238
-	$user      = User::findByIdentifier($user_name);
239
-
240
-	if ($user) {
241
-		$passchars   = 'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
242
-		$user_new_pw = '';
243
-		$max         = strlen($passchars) - 1;
244
-		for ($i = 0; $i < 8; $i++) {
245
-			$index = rand(0, $max);
246
-			$user_new_pw .= $passchars{$index};
247
-		}
248
-
249
-		$user->setPassword($user_new_pw);
250
-		Log::addAuthenticationLog('Password request was sent to user: ' . $user->getUserName());
251
-
252
-		Mail::systemMessage(
253
-			$WT_TREE,
254
-			$user,
255
-			I18N::translate('Lost password request'),
256
-			I18N::translate('Hello %s…', $user->getRealNameHtml()) . Mail::EOL . Mail::EOL .
257
-			I18N::translate('A new password has been requested for your username.') . Mail::EOL . Mail::EOL .
258
-			I18N::translate('Username') . ": " . Filter::escapeHtml($user->getUserName()) . Mail::EOL .
259
-			I18N::translate('Password') . ": " . $user_new_pw . Mail::EOL . Mail::EOL .
260
-			I18N::translate('After you have signed in, select the “My account” link under the “My pages” menu and fill in the password fields to change your password.') . Mail::EOL . Mail::EOL .
261
-			'<a href="' . WT_BASE_URL . 'login.php?ged=' . $WT_TREE->getNameUrl() . '">' . WT_BASE_URL . 'login.php?ged=' . $WT_TREE->getNameUrl() . '</a>'
262
-		);
263
-
264
-		FlashMessages::addMessage(I18N::translate('A new password has been created and emailed to %s. You can change this password after you sign in.', Filter::escapeHtml($user_name)), 'success');
265
-	} else {
266
-		FlashMessages::addMessage(I18N::translate('There is no account with the username or email “%s”.', Filter::escapeHtml($user_name)), 'danger');
267
-	}
268
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
269
-
270
-	return;
271
-	break;
237
+    $user_name = Filter::post('new_passwd_username');
238
+    $user      = User::findByIdentifier($user_name);
239
+
240
+    if ($user) {
241
+        $passchars   = 'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
242
+        $user_new_pw = '';
243
+        $max         = strlen($passchars) - 1;
244
+        for ($i = 0; $i < 8; $i++) {
245
+            $index = rand(0, $max);
246
+            $user_new_pw .= $passchars{$index};
247
+        }
248
+
249
+        $user->setPassword($user_new_pw);
250
+        Log::addAuthenticationLog('Password request was sent to user: ' . $user->getUserName());
251
+
252
+        Mail::systemMessage(
253
+            $WT_TREE,
254
+            $user,
255
+            I18N::translate('Lost password request'),
256
+            I18N::translate('Hello %s…', $user->getRealNameHtml()) . Mail::EOL . Mail::EOL .
257
+            I18N::translate('A new password has been requested for your username.') . Mail::EOL . Mail::EOL .
258
+            I18N::translate('Username') . ": " . Filter::escapeHtml($user->getUserName()) . Mail::EOL .
259
+            I18N::translate('Password') . ": " . $user_new_pw . Mail::EOL . Mail::EOL .
260
+            I18N::translate('After you have signed in, select the “My account” link under the “My pages” menu and fill in the password fields to change your password.') . Mail::EOL . Mail::EOL .
261
+            '<a href="' . WT_BASE_URL . 'login.php?ged=' . $WT_TREE->getNameUrl() . '">' . WT_BASE_URL . 'login.php?ged=' . $WT_TREE->getNameUrl() . '</a>'
262
+        );
263
+
264
+        FlashMessages::addMessage(I18N::translate('A new password has been created and emailed to %s. You can change this password after you sign in.', Filter::escapeHtml($user_name)), 'success');
265
+    } else {
266
+        FlashMessages::addMessage(I18N::translate('There is no account with the username or email “%s”.', Filter::escapeHtml($user_name)), 'danger');
267
+    }
268
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
269
+
270
+    return;
271
+    break;
272 272
 
273 273
 case 'register':
274
-	if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
275
-		header('Location: ' . WT_BASE_URL);
276
-
277
-		return;
278
-	}
279
-
280
-	$controller->setPageTitle(I18N::translate('Request a new user account'));
281
-
282
-	// The form parameters are mandatory, and the validation errors are shown in the client.
283
-	if (Session::get('good_to_send') && $user_name && $user_password01 && $user_password01 == $user_password02 && $user_realname && $user_email && $user_comments) {
284
-
285
-		// These validation errors cannot be shown in the client.
286
-		if (User::findByUserName($user_name)) {
287
-			FlashMessages::addMessage(I18N::translate('Duplicate username. A user with that username already exists. Please choose another username.'));
288
-		} elseif (User::findByEmail($user_email)) {
289
-			FlashMessages::addMessage(I18N::translate('Duplicate email address. A user with that email already exists.'));
290
-		} elseif (preg_match('/(?!' . preg_quote(WT_BASE_URL, '/') . ')(((?:ftp|http|https):\/\/)[a-zA-Z0-9.-]+)/', $user_comments, $match)) {
291
-			FlashMessages::addMessage(
292
-				I18N::translate('You are not allowed to send messages that contain external links.') . ' ' .
293
-				I18N::translate('You should delete the “%1$s” from “%2$s” and try again.', $match[2], $match[1])
294
-			);
295
-			Log::addAuthenticationLog('Possible spam registration from "' . $user_name . '"/"' . $user_email . '" comments="' . $user_comments . '"');
296
-		} else {
297
-			// Everything looks good - create the user
298
-			$controller->pageHeader();
299
-			Log::addAuthenticationLog('User registration requested for: ' . $user_name);
300
-
301
-			$user = User::create($user_name, $user_realname, $user_email, $user_password01);
302
-			$user
303
-				->setPreference('language', WT_LOCALE)
304
-				->setPreference('verified', '0')
305
-				->setPreference('verified_by_admin', 0)
306
-				->setPreference('reg_timestamp', date('U'))
307
-				->setPreference('reg_hashcode', md5(Uuid::uuid4()))
308
-				->setPreference('contactmethod', 'messaging2')
309
-				->setPreference('comment', $user_comments)
310
-				->setPreference('visibleonline', '1')
311
-				->setPreference('auto_accept', '0')
312
-				->setPreference('canadmin', '0')
313
-				->setPreference('sessiontime', '0');
314
-
315
-			// Generate an email in the admin’s language
316
-			$webmaster = User::find($WT_TREE->getPreference('WEBMASTER_USER_ID'));
317
-			I18N::init($webmaster->getPreference('language'));
318
-
319
-			$mail1_body =
320
-				I18N::translate('Hello administrator…') . Mail::EOL . Mail::EOL .
321
-				/* I18N: %s is a server name/URL */
322
-				I18N::translate('A prospective user has registered with webtrees at %s.', WT_BASE_URL . ' ' . $WT_TREE->getTitleHtml()) . Mail::EOL . Mail::EOL .
323
-				I18N::translate('Username') . ' ' . Filter::escapeHtml($user->getUserName()) . Mail::EOL .
324
-				I18N::translate('Real name') . ' ' . $user->getRealNameHtml() . Mail::EOL .
325
-				I18N::translate('Email address') . ' ' . Filter::escapeHtml($user->getEmail()) . Mail::EOL .
326
-				I18N::translate('Comments') . ' ' . Filter::escapeHtml($user_comments) . Mail::EOL . Mail::EOL .
327
-				I18N::translate('The user has been sent an email with the information necessary to confirm the access request.') . Mail::EOL . Mail::EOL .
328
-				I18N::translate('You will be informed by email when this prospective user has confirmed the request. You can then complete the process by activating the username. The new user will not be able to sign in until you activate the account.');
329
-
330
-			$mail1_subject = /* I18N: %s is a server name/URL */ I18N::translate('New registration at %s', WT_BASE_URL . ' ' . $WT_TREE->getTitle());
331
-			I18N::init(WT_LOCALE);
332
-
333
-			echo '<div id="login-register-page">';
334
-
335
-			// Generate an email in the user’s language
336
-			$mail2_body =
337
-				I18N::translate('Hello %s…', $user->getRealNameHtml()) .
338
-				Mail::EOL . Mail::EOL .
339
-				/* I18N: %1$s is the site URL and %2$s is an email address */
340
-				I18N::translate('You (or someone claiming to be you) has requested an account at %1$s using the email address %2$s.', WT_BASE_URL . ' ' . $WT_TREE->getTitleHtml(), $user->getEmail()) .
341
-				Mail::EOL . Mail::EOL .
342
-				I18N::translate('Follow this link to verify your email address.') .
343
-				Mail::EOL . Mail::EOL .
344
-				'<a href="' . WT_LOGIN_URL . '?user_name=' . Filter::escapeUrl($user->getUserName()) . '&amp;user_hashcode=' . $user->getPreference('reg_hashcode') . '&amp;action=userverify&amp;ged=' . $WT_TREE->getNameUrl() . '">' .
345
-				WT_LOGIN_URL . "?user_name=" . Filter::escapeHtml($user->getUserName()) . "&amp;user_hashcode=" . urlencode($user->getPreference('reg_hashcode')) . '&amp;action=userverify&amp;ged=' . $WT_TREE->getNameHtml() .
346
-				'</a>' . Mail::EOL . Mail::EOL .
347
-				I18N::translate('Username') . " - " . Filter::escapeHtml($user->getUserName()) . Mail::EOL .
348
-				I18N::translate('Comments') . " - " . $user->getPreference('comment') . Mail::EOL .
349
-				I18N::translate('If you didn’t request an account, you can just delete this message.') . Mail::EOL;
350
-			$mail2_subject = /* I18N: %s is a server name/URL */ I18N::translate('Your registration at %s', WT_BASE_URL);
351
-			$mail2_to      = $user->getEmail();
352
-			$mail2_from    = $WT_TREE->getPreference('WEBTREES_EMAIL');
353
-
354
-			// Send user message by email only
355
-			Mail::send(
356
-				// “From:” header
357
-				$WT_TREE,
358
-				// “To:” header
359
-				$mail2_to,
360
-				$mail2_to,
361
-				// “Reply-To:” header
362
-				$mail2_from,
363
-				$mail2_from,
364
-				// Message body
365
-				$mail2_subject,
366
-				$mail2_body
367
-			);
368
-
369
-			// Send admin message by email and/or internal messaging
370
-			Mail::send(
371
-				// “From:” header
372
-				$WT_TREE,
373
-				// “To:” header
374
-				$webmaster->getEmail(),
375
-				$webmaster->getRealName(),
376
-				// “Reply-To:” header
377
-				$user->getEmail(),
378
-				$user->getRealName(),
379
-				// Message body
380
-				$mail1_subject,
381
-				$mail1_body
382
-			);
383
-			$mail1_method = $webmaster->getPreference('contact_method');
384
-			if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') {
385
-				Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")
386
-					->execute(array($user->getEmail(), WT_CLIENT_IP, $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body)));
387
-			}
388
-
389
-			echo '<div class="confirm"><p>', I18N::translate('Hello %s…<br>Thank you for your registration.', $user->getRealNameHtml()), '</p>';
390
-			echo '<p>', I18N::translate('We will now send a confirmation email to the address <b>%s</b>. You must verify your account request by following instructions in the confirmation email. If you do not confirm your account request within seven days, your application will be rejected automatically. You will have to apply again.<br><br>After you have followed the instructions in the confirmation email, the administrator still has to approve your request before your account can be used.<br><br>To sign in to this website, you will need to know your username and password.', $user->getEmail()), '</p>';
391
-			echo '</div>';
392
-			echo '</div>';
393
-
394
-			return;
395
-		}
396
-	}
397
-
398
-	Session::put('good_to_send', true);
399
-	$controller
400
-		->pageHeader()
401
-		->addInlineJavascript('function regex_quote(str) {return str.replace(/[\\\\.?+*()[\](){}|]/g, "\\\\$&");}');
402
-
403
-	?>
274
+    if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
275
+        header('Location: ' . WT_BASE_URL);
276
+
277
+        return;
278
+    }
279
+
280
+    $controller->setPageTitle(I18N::translate('Request a new user account'));
281
+
282
+    // The form parameters are mandatory, and the validation errors are shown in the client.
283
+    if (Session::get('good_to_send') && $user_name && $user_password01 && $user_password01 == $user_password02 && $user_realname && $user_email && $user_comments) {
284
+
285
+        // These validation errors cannot be shown in the client.
286
+        if (User::findByUserName($user_name)) {
287
+            FlashMessages::addMessage(I18N::translate('Duplicate username. A user with that username already exists. Please choose another username.'));
288
+        } elseif (User::findByEmail($user_email)) {
289
+            FlashMessages::addMessage(I18N::translate('Duplicate email address. A user with that email already exists.'));
290
+        } elseif (preg_match('/(?!' . preg_quote(WT_BASE_URL, '/') . ')(((?:ftp|http|https):\/\/)[a-zA-Z0-9.-]+)/', $user_comments, $match)) {
291
+            FlashMessages::addMessage(
292
+                I18N::translate('You are not allowed to send messages that contain external links.') . ' ' .
293
+                I18N::translate('You should delete the “%1$s” from “%2$s” and try again.', $match[2], $match[1])
294
+            );
295
+            Log::addAuthenticationLog('Possible spam registration from "' . $user_name . '"/"' . $user_email . '" comments="' . $user_comments . '"');
296
+        } else {
297
+            // Everything looks good - create the user
298
+            $controller->pageHeader();
299
+            Log::addAuthenticationLog('User registration requested for: ' . $user_name);
300
+
301
+            $user = User::create($user_name, $user_realname, $user_email, $user_password01);
302
+            $user
303
+                ->setPreference('language', WT_LOCALE)
304
+                ->setPreference('verified', '0')
305
+                ->setPreference('verified_by_admin', 0)
306
+                ->setPreference('reg_timestamp', date('U'))
307
+                ->setPreference('reg_hashcode', md5(Uuid::uuid4()))
308
+                ->setPreference('contactmethod', 'messaging2')
309
+                ->setPreference('comment', $user_comments)
310
+                ->setPreference('visibleonline', '1')
311
+                ->setPreference('auto_accept', '0')
312
+                ->setPreference('canadmin', '0')
313
+                ->setPreference('sessiontime', '0');
314
+
315
+            // Generate an email in the admin’s language
316
+            $webmaster = User::find($WT_TREE->getPreference('WEBMASTER_USER_ID'));
317
+            I18N::init($webmaster->getPreference('language'));
318
+
319
+            $mail1_body =
320
+                I18N::translate('Hello administrator…') . Mail::EOL . Mail::EOL .
321
+                /* I18N: %s is a server name/URL */
322
+                I18N::translate('A prospective user has registered with webtrees at %s.', WT_BASE_URL . ' ' . $WT_TREE->getTitleHtml()) . Mail::EOL . Mail::EOL .
323
+                I18N::translate('Username') . ' ' . Filter::escapeHtml($user->getUserName()) . Mail::EOL .
324
+                I18N::translate('Real name') . ' ' . $user->getRealNameHtml() . Mail::EOL .
325
+                I18N::translate('Email address') . ' ' . Filter::escapeHtml($user->getEmail()) . Mail::EOL .
326
+                I18N::translate('Comments') . ' ' . Filter::escapeHtml($user_comments) . Mail::EOL . Mail::EOL .
327
+                I18N::translate('The user has been sent an email with the information necessary to confirm the access request.') . Mail::EOL . Mail::EOL .
328
+                I18N::translate('You will be informed by email when this prospective user has confirmed the request. You can then complete the process by activating the username. The new user will not be able to sign in until you activate the account.');
329
+
330
+            $mail1_subject = /* I18N: %s is a server name/URL */ I18N::translate('New registration at %s', WT_BASE_URL . ' ' . $WT_TREE->getTitle());
331
+            I18N::init(WT_LOCALE);
332
+
333
+            echo '<div id="login-register-page">';
334
+
335
+            // Generate an email in the user’s language
336
+            $mail2_body =
337
+                I18N::translate('Hello %s…', $user->getRealNameHtml()) .
338
+                Mail::EOL . Mail::EOL .
339
+                /* I18N: %1$s is the site URL and %2$s is an email address */
340
+                I18N::translate('You (or someone claiming to be you) has requested an account at %1$s using the email address %2$s.', WT_BASE_URL . ' ' . $WT_TREE->getTitleHtml(), $user->getEmail()) .
341
+                Mail::EOL . Mail::EOL .
342
+                I18N::translate('Follow this link to verify your email address.') .
343
+                Mail::EOL . Mail::EOL .
344
+                '<a href="' . WT_LOGIN_URL . '?user_name=' . Filter::escapeUrl($user->getUserName()) . '&amp;user_hashcode=' . $user->getPreference('reg_hashcode') . '&amp;action=userverify&amp;ged=' . $WT_TREE->getNameUrl() . '">' .
345
+                WT_LOGIN_URL . "?user_name=" . Filter::escapeHtml($user->getUserName()) . "&amp;user_hashcode=" . urlencode($user->getPreference('reg_hashcode')) . '&amp;action=userverify&amp;ged=' . $WT_TREE->getNameHtml() .
346
+                '</a>' . Mail::EOL . Mail::EOL .
347
+                I18N::translate('Username') . " - " . Filter::escapeHtml($user->getUserName()) . Mail::EOL .
348
+                I18N::translate('Comments') . " - " . $user->getPreference('comment') . Mail::EOL .
349
+                I18N::translate('If you didn’t request an account, you can just delete this message.') . Mail::EOL;
350
+            $mail2_subject = /* I18N: %s is a server name/URL */ I18N::translate('Your registration at %s', WT_BASE_URL);
351
+            $mail2_to      = $user->getEmail();
352
+            $mail2_from    = $WT_TREE->getPreference('WEBTREES_EMAIL');
353
+
354
+            // Send user message by email only
355
+            Mail::send(
356
+                // “From:” header
357
+                $WT_TREE,
358
+                // “To:” header
359
+                $mail2_to,
360
+                $mail2_to,
361
+                // “Reply-To:” header
362
+                $mail2_from,
363
+                $mail2_from,
364
+                // Message body
365
+                $mail2_subject,
366
+                $mail2_body
367
+            );
368
+
369
+            // Send admin message by email and/or internal messaging
370
+            Mail::send(
371
+                // “From:” header
372
+                $WT_TREE,
373
+                // “To:” header
374
+                $webmaster->getEmail(),
375
+                $webmaster->getRealName(),
376
+                // “Reply-To:” header
377
+                $user->getEmail(),
378
+                $user->getRealName(),
379
+                // Message body
380
+                $mail1_subject,
381
+                $mail1_body
382
+            );
383
+            $mail1_method = $webmaster->getPreference('contact_method');
384
+            if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') {
385
+                Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")
386
+                    ->execute(array($user->getEmail(), WT_CLIENT_IP, $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body)));
387
+            }
388
+
389
+            echo '<div class="confirm"><p>', I18N::translate('Hello %s…<br>Thank you for your registration.', $user->getRealNameHtml()), '</p>';
390
+            echo '<p>', I18N::translate('We will now send a confirmation email to the address <b>%s</b>. You must verify your account request by following instructions in the confirmation email. If you do not confirm your account request within seven days, your application will be rejected automatically. You will have to apply again.<br><br>After you have followed the instructions in the confirmation email, the administrator still has to approve your request before your account can be used.<br><br>To sign in to this website, you will need to know your username and password.', $user->getEmail()), '</p>';
391
+            echo '</div>';
392
+            echo '</div>';
393
+
394
+            return;
395
+        }
396
+    }
397
+
398
+    Session::put('good_to_send', true);
399
+    $controller
400
+        ->pageHeader()
401
+        ->addInlineJavascript('function regex_quote(str) {return str.replace(/[\\\\.?+*()[\](){}|]/g, "\\\\$&");}');
402
+
403
+    ?>
404 404
 	<div id="login-register-page">
405 405
 		<h2><?php echo $controller->getPageTitle(); ?></h2>
406 406
 
@@ -501,24 +501,24 @@  discard block
 block discarded – undo
501 501
 		</div>
502 502
 	</div>
503 503
 	<?php
504
-	break;
504
+    break;
505 505
 
506 506
 case 'userverify':
507
-	if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
508
-		header('Location: ' . WT_BASE_URL);
507
+    if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
508
+        header('Location: ' . WT_BASE_URL);
509 509
 
510
-		return;
511
-	}
510
+        return;
511
+    }
512 512
 
513
-	// Change to the new user’s language
514
-	$user = User::findByUserName($user_name);
513
+    // Change to the new user’s language
514
+    $user = User::findByUserName($user_name);
515 515
 
516
-	I18N::init($user->getPreference('language'));
516
+    I18N::init($user->getPreference('language'));
517 517
 
518
-	$controller->setPageTitle(I18N::translate('User verification'));
519
-	$controller->pageHeader();
518
+    $controller->setPageTitle(I18N::translate('User verification'));
519
+    $controller->pageHeader();
520 520
 
521
-	echo '<div id="login-register-page">
521
+    echo '<div id="login-register-page">
522 522
 		<form id="verify-form" name="verify-form" method="post" action="', WT_LOGIN_URL, '">
523 523
 			<input type="hidden" name="action" value="verify_hash">
524 524
 			<h4>', I18N::translate('User verification'), '</h4>
@@ -539,87 +539,87 @@  discard block
 block discarded – undo
539 539
 			</div>
540 540
 		</form>
541 541
 	</div>';
542
-	break;
542
+    break;
543 543
 
544 544
 case 'verify_hash':
545
-	if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
546
-		header('Location: ' . WT_BASE_URL);
547
-
548
-		return;
549
-	}
550
-
551
-	// switch language to webmaster settings
552
-	$webmaster = User::find($WT_TREE->getPreference('WEBMASTER_USER_ID'));
553
-	I18N::init($webmaster->getPreference('language'));
554
-
555
-	$user          = User::findByUserName($user_name);
556
-	$edit_user_url = WT_BASE_URL . "admin_users.php?action=edit&amp;user_id=" . $user->getUserId();
557
-	$mail1_body    =
558
-		I18N::translate('Hello administrator…') .
559
-		Mail::EOL . Mail::EOL .
560
-		/* I18N: %1$s is a real-name, %2$s is a username, %3$s is an email address */ I18N::translate(
561
-			'A new user (%1$s) has requested an account (%2$s) and verified an email address (%3$s).',
562
-			$user->getRealNameHtml(),
563
-			Filter::escapeHtml($user->getUserName()),
564
-			Filter::escapeHtml($user->getEmail())
565
-		) .
566
-		Mail::EOL . Mail::EOL .
567
-		I18N::translate('You need to review the account details.') .
568
-		Mail::EOL . Mail::EOL .
569
-		'<a href="' . $edit_user_url . '">' . $edit_user_url . '</a>' .
570
-		Mail::EOL . Mail::EOL .
571
-		/* I18N: You need to: */ I18N::translate('Set the status to “approved”.') .
572
-		Mail::EOL .
573
-		/* I18N: You need to: */ I18N::translate('Set the access level for each tree.') .
574
-		Mail::EOL .
575
-		/* I18N: You need to: */ I18N::translate('Link the user account to an individual.');
576
-
577
-	$mail1_subject = /* I18N: %s is a server name/URL */ I18N::translate('New user at %s', WT_BASE_URL . ' ' . $WT_TREE->getTitle());
578
-
579
-	// Change to the new user’s language
580
-	I18N::init($user->getPreference('language'));
581
-
582
-	$controller->setPageTitle(I18N::translate('User verification'));
583
-	$controller->pageHeader();
584
-
585
-	echo '<div id="login-register-page">';
586
-	echo '<h2>' . I18N::translate('User verification') . '</h2>';
587
-	echo '<div id="user-verify">';
588
-	if ($user && $user->checkPassword($user_password) && $user->getPreference('reg_hashcode') === $user_hashcode) {
589
-		Mail::send(
590
-		// “From:” header
591
-			$WT_TREE,
592
-			// “To:” header
593
-			$webmaster->getEmail(),
594
-			$webmaster->getRealName(),
595
-			// “Reply-To:” header
596
-			$WT_TREE->getPreference('WEBTREES_EMAIL'),
597
-			$WT_TREE->getPreference('WEBTREES_EMAIL'),
598
-			// Message body
599
-			$mail1_subject,
600
-			$mail1_body
601
-		);
602
-		$mail1_method = $webmaster->getPreference('CONTACT_METHOD');
603
-		if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') {
604
-			Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")
605
-				->execute(array($user_name, WT_CLIENT_IP, $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body)));
606
-		}
607
-
608
-		$user
609
-			->setPreference('verified', '1')
610
-			->setPreference('reg_timestamp', date('U'))
611
-			->deletePreference('reg_hashcode');
612
-
613
-		Log::addAuthenticationLog('User ' . $user_name . ' verified their email address');
614
-
615
-		echo '<p>', I18N::translate('You have confirmed your request to become a registered user.'), '</p>';
616
-		echo '<p>', I18N::translate('The administrator has been informed. As soon as they give you permission to sign in, you can sign in with your username and password.'), '</p>';
617
-	} else {
618
-		echo '<p class="warning">';
619
-		echo I18N::translate('Could not verify the information you entered. Please try again or contact the site administrator for more information.');
620
-		echo '</p>';
621
-	}
622
-	echo '</div>';
623
-	echo '</div>';
624
-	break;
545
+    if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
546
+        header('Location: ' . WT_BASE_URL);
547
+
548
+        return;
549
+    }
550
+
551
+    // switch language to webmaster settings
552
+    $webmaster = User::find($WT_TREE->getPreference('WEBMASTER_USER_ID'));
553
+    I18N::init($webmaster->getPreference('language'));
554
+
555
+    $user          = User::findByUserName($user_name);
556
+    $edit_user_url = WT_BASE_URL . "admin_users.php?action=edit&amp;user_id=" . $user->getUserId();
557
+    $mail1_body    =
558
+        I18N::translate('Hello administrator…') .
559
+        Mail::EOL . Mail::EOL .
560
+        /* I18N: %1$s is a real-name, %2$s is a username, %3$s is an email address */ I18N::translate(
561
+            'A new user (%1$s) has requested an account (%2$s) and verified an email address (%3$s).',
562
+            $user->getRealNameHtml(),
563
+            Filter::escapeHtml($user->getUserName()),
564
+            Filter::escapeHtml($user->getEmail())
565
+        ) .
566
+        Mail::EOL . Mail::EOL .
567
+        I18N::translate('You need to review the account details.') .
568
+        Mail::EOL . Mail::EOL .
569
+        '<a href="' . $edit_user_url . '">' . $edit_user_url . '</a>' .
570
+        Mail::EOL . Mail::EOL .
571
+        /* I18N: You need to: */ I18N::translate('Set the status to “approved”.') .
572
+        Mail::EOL .
573
+        /* I18N: You need to: */ I18N::translate('Set the access level for each tree.') .
574
+        Mail::EOL .
575
+        /* I18N: You need to: */ I18N::translate('Link the user account to an individual.');
576
+
577
+    $mail1_subject = /* I18N: %s is a server name/URL */ I18N::translate('New user at %s', WT_BASE_URL . ' ' . $WT_TREE->getTitle());
578
+
579
+    // Change to the new user’s language
580
+    I18N::init($user->getPreference('language'));
581
+
582
+    $controller->setPageTitle(I18N::translate('User verification'));
583
+    $controller->pageHeader();
584
+
585
+    echo '<div id="login-register-page">';
586
+    echo '<h2>' . I18N::translate('User verification') . '</h2>';
587
+    echo '<div id="user-verify">';
588
+    if ($user && $user->checkPassword($user_password) && $user->getPreference('reg_hashcode') === $user_hashcode) {
589
+        Mail::send(
590
+        // “From:” header
591
+            $WT_TREE,
592
+            // “To:” header
593
+            $webmaster->getEmail(),
594
+            $webmaster->getRealName(),
595
+            // “Reply-To:” header
596
+            $WT_TREE->getPreference('WEBTREES_EMAIL'),
597
+            $WT_TREE->getPreference('WEBTREES_EMAIL'),
598
+            // Message body
599
+            $mail1_subject,
600
+            $mail1_body
601
+        );
602
+        $mail1_method = $webmaster->getPreference('CONTACT_METHOD');
603
+        if ($mail1_method != 'messaging3' && $mail1_method != 'mailto' && $mail1_method != 'none') {
604
+            Database::prepare("INSERT INTO `##message` (sender, ip_address, user_id, subject, body) VALUES (? ,? ,? ,? ,?)")
605
+                ->execute(array($user_name, WT_CLIENT_IP, $webmaster->getUserId(), $mail1_subject, Filter::unescapeHtml($mail1_body)));
606
+        }
607
+
608
+        $user
609
+            ->setPreference('verified', '1')
610
+            ->setPreference('reg_timestamp', date('U'))
611
+            ->deletePreference('reg_hashcode');
612
+
613
+        Log::addAuthenticationLog('User ' . $user_name . ' verified their email address');
614
+
615
+        echo '<p>', I18N::translate('You have confirmed your request to become a registered user.'), '</p>';
616
+        echo '<p>', I18N::translate('The administrator has been informed. As soon as they give you permission to sign in, you can sign in with your username and password.'), '</p>';
617
+    } else {
618
+        echo '<p class="warning">';
619
+        echo I18N::translate('Could not verify the information you entered. Please try again or contact the site administrator for more information.');
620
+        echo '</p>';
621
+    }
622
+    echo '</div>';
623
+    echo '</div>';
624
+    break;
625 625
 }
Please login to merge, or discard this patch.