Passed
Push — 1.7 ( 23cbb7...8df8a8 )
by Greg
08:15
created
mediafirewall.php 3 patches
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.
Switch Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -126,53 +126,53 @@
 block discarded – undo
126 126
 
127 127
 	// vertical and horizontal position of the text
128 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
-		}
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 176
 		break;
177 177
 	}
178 178
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,7 +34,8 @@  discard block
 block discarded – undo
34 34
 /**
35 35
  * Send a “Not found” error as an image
36 36
  */
37
-function send404AsImage() {
37
+function send404AsImage()
38
+{
38 39
 	$error = I18N::translate('The media file was not found in this family tree.');
39 40
 
40 41
 	$width  = mb_strlen($error) * 6.5 + 50;
@@ -61,7 +62,8 @@  discard block
 block discarded – undo
61 62
  *
62 63
  * @return resource
63 64
  */
64
-function applyWatermark($im, Tree $tree) {
65
+function applyWatermark($im, Tree $tree)
66
+{
65 67
 	// text to watermark with
66 68
 	$word1_text = $tree->getTitle();
67 69
 	// maximum font size for “word1” ; will be automaticaly reduced to fit in the image
@@ -100,7 +102,8 @@  discard block
 block discarded – undo
100 102
  * @param string   $vpos
101 103
  * @param string   $hpos
102 104
  */
103
-function embedText($im, $text, $maxsize, $color, $font, $vpos, $hpos) {
105
+function embedText($im, $text, $maxsize, $color, $font, $vpos, $hpos)
106
+{
104 107
 	global $useTTF;
105 108
 
106 109
 	// there are two ways to embed text with PHP
@@ -203,7 +206,8 @@  discard block
 block discarded – undo
203 206
  *
204 207
  * @return int
205 208
  */
206
-function textlength($t, $mxl, $text) {
209
+function textlength($t, $mxl, $text)
210
+{
207 211
 	$taille_c = $t;
208 212
 	$len      = mb_strlen($text);
209 213
 	while (($taille_c - 2) * $len > $mxl) {
@@ -225,7 +229,8 @@  discard block
 block discarded – undo
225 229
  *
226 230
  * @return bool
227 231
  */
228
-function imagettftextErrorHandler($errno, $errstr) {
232
+function imagettftextErrorHandler($errno, $errstr)
233
+{
229 234
 	global $useTTF, $serverFilename;
230 235
 	// log the error
231 236
 	Log::addErrorLog('Media Firewall error: >' . $errno . '/' . $errstr . '< while processing file >' . $serverFilename . '<');
@@ -243,7 +248,8 @@  discard block
 block discarded – undo
243 248
  *
244 249
  * @return string|false
245 250
  */
246
-function isImageTypeSupported($reqtype) {
251
+function isImageTypeSupported($reqtype)
252
+{
247 253
 	$supportByGD = array('jpg' => 'jpeg', 'jpeg' => 'jpeg', 'gif' => 'gif', 'png' => 'png');
248 254
 	$reqtype     = strtolower($reqtype);
249 255
 
Please login to merge, or discard this patch.
login.php 2 patches
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.
Switch Indentation   +370 added lines, -370 removed lines patch added patch discarded remove patch
@@ -68,89 +68,89 @@  discard block
 block discarded – undo
68 68
 $message = '';
69 69
 
70 70
 switch ($action) {
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;
148
-
149
-default:
150
-	$controller
151
-		->setPageTitle(I18N::translate('Sign in'))
152
-		->pageHeader()
153
-		->addInlineJavascript('
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;
148
+
149
+    default:
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,25 +160,25 @@  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
-	}
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 182
 
183 183
 	echo '</div>';
184 184
 	echo '<div id="login-box">';
@@ -233,181 +233,181 @@  discard block
 block discarded – undo
233 233
 	echo '</div>';
234 234
 	break;
235 235
 
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;
272
-
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
-	?>
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;
272
+
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
+	    ?>
404 404
 	<div id="login-register-page">
405 405
 		<h2><?php echo $controller->getPageTitle(); ?></h2>
406 406
 
407 407
 		<?php if (Site::getPreference('SHOW_REGISTER_CAUTION')): ?>
408
-		<div id="register-text">
408
+    		<div id="register-text">
409 409
 			<?php echo I18N::translate('<div class="largeError">Notice:</div><div class="error">By completing and submitting this form, you agree:<ul><li>to protect the privacy of living individuals listed on our site;</li><li>and in the text box below, to explain to whom you are related, or to provide us with information on someone who should be listed on our website.</li></ul></div>'); ?>
410
-		</div>
410
+    		</div>
411 411
 		<?php endif; ?>
412 412
 		<div id="register-box">
413 413
 			<form id="register-form" name="register-form" method="post" onsubmit="return checkform(this);" autocomplete="off">
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 				<div>
419 419
 					<label for="user_realname">
420 420
 						<?php echo I18N::translate('Real name'); ?>
421
-						<input type="text" id="user_realname" name="user_realname" required maxlength="64" value="<?php echo Filter::escapeHtml($user_realname); ?>" autofocus>
421
+    						<input type="text" id="user_realname" name="user_realname" required maxlength="64" value="<?php echo Filter::escapeHtml($user_realname); ?>" autofocus>
422 422
 					</label>
423 423
 					<p class="small text-muted">
424 424
 						<?php echo I18N::translate('This is your real name, as you would like it displayed on screen.'); ?>
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 				<div>
429 429
 					<label for="user_email">
430 430
 						<?php echo I18N::translate('Email address'); ?>
431
-						<input type="email" id="user_email" name="user_email" required maxlength="64" value="<?php echo Filter::escapeHtml($user_email); ?>">
431
+    						<input type="email" id="user_email" name="user_email" required maxlength="64" value="<?php echo Filter::escapeHtml($user_email); ?>">
432 432
 					</label>
433 433
 					<p class="small text-muted">
434 434
 						<?php echo I18N::translate('This email address will be used to send password reminders, website notifications, and messages from other family members who are registered on the website.'); ?>
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 				<div>
439 439
 					<label for="username">
440 440
 						<?php echo I18N::translate('Username'); ?>
441
-						<input type="text" id="username" name="user_name" required maxlength="32" value="<?php Filter::escapeHtml($user_name); ?>">
441
+    						<input type="text" id="username" name="user_name" required maxlength="32" value="<?php Filter::escapeHtml($user_name); ?>">
442 442
 					</label>
443 443
 					<p class="small text-muted">
444 444
 						<?php echo I18N::translate('Usernames are case-insensitive and ignore accented letters, so that “chloe”, “chloë”, and “Chloe” are considered to be the same.'); ?>
@@ -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
-case 'userverify':
507
-	if (!Site::getPreference('USE_REGISTRATION_MODULE')) {
508
-		header('Location: ' . WT_BASE_URL);
506
+    case 'userverify':
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;
543
-
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;
542
+	    break;
543
+
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;
625 625
 }
Please login to merge, or discard this patch.
block_edit.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,42 +30,42 @@
 block discarded – undo
30 30
 
31 31
 $block_id = Filter::getInteger('block_id');
32 32
 $block    = Database::prepare(
33
-	"SELECT * FROM `##block` WHERE block_id=?"
33
+    "SELECT * FROM `##block` WHERE block_id=?"
34 34
 )->execute(array($block_id))->fetchOneRow();
35 35
 
36 36
 // Check access. (1) the block must exist and be enabled, (2) gedcom blocks require
37 37
 // managers, (3) user blocks require the user or an admin
38 38
 $blocks = Module::getActiveBlocks($WT_TREE);
39 39
 if (
40
-	!$block ||
41
-	!array_key_exists($block->module_name, $blocks) ||
42
-	$block->gedcom_id && !Auth::isManager(Tree::findById($block->gedcom_id)) ||
43
-	$block->user_id && $block->user_id != Auth::id() && !Auth::isAdmin()
40
+    !$block ||
41
+    !array_key_exists($block->module_name, $blocks) ||
42
+    $block->gedcom_id && !Auth::isManager(Tree::findById($block->gedcom_id)) ||
43
+    $block->user_id && $block->user_id != Auth::id() && !Auth::isAdmin()
44 44
 ) {
45
-	header('Location: ' . WT_BASE_URL);
45
+    header('Location: ' . WT_BASE_URL);
46 46
 
47
-	return;
47
+    return;
48 48
 }
49 49
 
50 50
 $block = $blocks[$block->module_name];
51 51
 
52 52
 if (Filter::post('save')) {
53
-	$ctype = Filter::post('ctype', 'user', 'gedcom');
54
-	header('Location: ' . WT_BASE_URL . 'index.php?ctype=' . $ctype . '&ged=' . $WT_TREE->getNameUrl());
55
-	$block->configureBlock($block_id);
53
+    $ctype = Filter::post('ctype', 'user', 'gedcom');
54
+    header('Location: ' . WT_BASE_URL . 'index.php?ctype=' . $ctype . '&ged=' . $WT_TREE->getNameUrl());
55
+    $block->configureBlock($block_id);
56 56
 
57
-	return;
57
+    return;
58 58
 }
59 59
 
60 60
 $ctype = Filter::get('ctype', 'user', 'gedcom');
61 61
 
62 62
 $controller = new PageController;
63 63
 $controller
64
-	->setPageTitle($block->getTitle() . ' — ' . I18N::translate('Preferences'))
65
-	->pageHeader();
64
+    ->setPageTitle($block->getTitle() . ' — ' . I18N::translate('Preferences'))
65
+    ->pageHeader();
66 66
 
67 67
 if (Module::getModuleByName('ckeditor')) {
68
-	CkeditorModule::enableEditor($controller);
68
+    CkeditorModule::enableEditor($controller);
69 69
 }
70 70
 
71 71
 ?>
Please login to merge, or discard this patch.
expand_view.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -30,51 +30,51 @@
 block discarded – undo
30 30
 header('Content-Type: text/html; charset=UTF-8');
31 31
 $individual = Individual::getInstance(Filter::get('pid', WT_REGEX_XREF), $WT_TREE);
32 32
 if (!$individual || !$individual->canShow()) {
33
-	return I18N::translate('Private');
33
+    return I18N::translate('Private');
34 34
 }
35 35
 
36 36
 $facts = $individual->getFacts();
37 37
 foreach ($individual->getSpouseFamilies() as $family) {
38
-	foreach ($family->getFacts() as $fact) {
39
-		$facts[] = $fact;
40
-	}
38
+    foreach ($family->getFacts() as $fact) {
39
+        $facts[] = $fact;
40
+    }
41 41
 }
42 42
 Functions::sortFacts($facts);
43 43
 
44 44
 foreach ($facts as $fact) {
45
-	switch ($fact->getTag()) {
46
-	case 'ADDR':
47
-	case 'ALIA':
48
-	case 'ASSO':
49
-	case 'CHAN':
50
-	case 'CHIL':
51
-	case 'EMAIL':
52
-	case 'FAMC':
53
-	case 'FAMS':
54
-	case 'HUSB':
55
-	case 'NAME':
56
-	case 'NOTE':
57
-	case 'OBJE':
58
-	case 'PHON':
59
-	case 'RESI':
60
-	case 'RESN':
61
-	case 'SEX':
62
-	case 'SOUR':
63
-	case 'SSN':
64
-	case 'SUBM':
65
-	case 'TITL':
66
-	case 'URL':
67
-	case 'WIFE':
68
-	case 'WWW':
69
-	case '_EMAIL':
70
-	case '_TODO':
71
-	case '_UID':
72
-	case '_WT_OBJE_SORT':
73
-		// Do not show these
74
-		break;
75
-	default:
76
-		// Simple version of FunctionsPrintFacts::print_fact()
77
-		echo $fact->summary();
78
-		break;
79
-	}
45
+    switch ($fact->getTag()) {
46
+    case 'ADDR':
47
+    case 'ALIA':
48
+    case 'ASSO':
49
+    case 'CHAN':
50
+    case 'CHIL':
51
+    case 'EMAIL':
52
+    case 'FAMC':
53
+    case 'FAMS':
54
+    case 'HUSB':
55
+    case 'NAME':
56
+    case 'NOTE':
57
+    case 'OBJE':
58
+    case 'PHON':
59
+    case 'RESI':
60
+    case 'RESN':
61
+    case 'SEX':
62
+    case 'SOUR':
63
+    case 'SSN':
64
+    case 'SUBM':
65
+    case 'TITL':
66
+    case 'URL':
67
+    case 'WIFE':
68
+    case 'WWW':
69
+    case '_EMAIL':
70
+    case '_TODO':
71
+    case '_UID':
72
+    case '_WT_OBJE_SORT':
73
+        // Do not show these
74
+        break;
75
+    default:
76
+        // Simple version of FunctionsPrintFacts::print_fact()
77
+        echo $fact->summary();
78
+        break;
79
+    }
80 80
 }
Please login to merge, or discard this patch.
Switch Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -43,38 +43,38 @@
 block discarded – undo
43 43
 
44 44
 foreach ($facts as $fact) {
45 45
 	switch ($fact->getTag()) {
46
-	case 'ADDR':
47
-	case 'ALIA':
48
-	case 'ASSO':
49
-	case 'CHAN':
50
-	case 'CHIL':
51
-	case 'EMAIL':
52
-	case 'FAMC':
53
-	case 'FAMS':
54
-	case 'HUSB':
55
-	case 'NAME':
56
-	case 'NOTE':
57
-	case 'OBJE':
58
-	case 'PHON':
59
-	case 'RESI':
60
-	case 'RESN':
61
-	case 'SEX':
62
-	case 'SOUR':
63
-	case 'SSN':
64
-	case 'SUBM':
65
-	case 'TITL':
66
-	case 'URL':
67
-	case 'WIFE':
68
-	case 'WWW':
69
-	case '_EMAIL':
70
-	case '_TODO':
71
-	case '_UID':
72
-	case '_WT_OBJE_SORT':
73
-		// Do not show these
74
-		break;
75
-	default:
76
-		// Simple version of FunctionsPrintFacts::print_fact()
77
-		echo $fact->summary();
78
-		break;
46
+	    case 'ADDR':
47
+	    case 'ALIA':
48
+	    case 'ASSO':
49
+	    case 'CHAN':
50
+	    case 'CHIL':
51
+	    case 'EMAIL':
52
+	    case 'FAMC':
53
+	    case 'FAMS':
54
+	    case 'HUSB':
55
+	    case 'NAME':
56
+	    case 'NOTE':
57
+	    case 'OBJE':
58
+	    case 'PHON':
59
+	    case 'RESI':
60
+	    case 'RESN':
61
+	    case 'SEX':
62
+	    case 'SOUR':
63
+	    case 'SSN':
64
+	    case 'SUBM':
65
+	    case 'TITL':
66
+	    case 'URL':
67
+	    case 'WIFE':
68
+	    case 'WWW':
69
+	    case '_EMAIL':
70
+	    case '_TODO':
71
+	    case '_UID':
72
+	    case '_WT_OBJE_SORT':
73
+		    // Do not show these
74
+		    break;
75
+	    default:
76
+		    // Simple version of FunctionsPrintFacts::print_fact()
77
+		    echo $fact->summary();
78
+		    break;
79 79
 	}
80 80
 }
Please login to merge, or discard this patch.
edit_changes.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
 
32 32
 $controller = new SimpleController;
33 33
 $controller
34
-	->restrictAccess(Auth::isModerator($WT_TREE))
35
-	->setPageTitle(I18N::translate('Pending changes'))
36
-	->pageHeader()
37
-	->addInlineJavascript("
34
+    ->restrictAccess(Auth::isModerator($WT_TREE))
35
+    ->setPageTitle(I18N::translate('Pending changes'))
36
+    ->pageHeader()
37
+    ->addInlineJavascript("
38 38
 		function show_diff(diffurl) {
39 39
 			window.opener.location = diffurl;
40 40
 			return false;
@@ -50,203 +50,203 @@  discard block
 block discarded – undo
50 50
 
51 51
 switch ($action) {
52 52
 case 'undo':
53
-	$gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
54
-	$xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
55
-	// Undo a change, and subsequent changes to the same record
56
-	Database::prepare(
57
-		"UPDATE `##change`" .
58
-		" SET   status     = 'rejected'" .
59
-		" WHERE status     = 'pending'" .
60
-		" AND   gedcom_id  = ?" .
61
-		" AND   xref       = ?" .
62
-		" AND   change_id >= ?"
63
-	)->execute(array($gedcom_id, $xref, $change_id));
64
-	break;
53
+    $gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
54
+    $xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
55
+    // Undo a change, and subsequent changes to the same record
56
+    Database::prepare(
57
+        "UPDATE `##change`" .
58
+        " SET   status     = 'rejected'" .
59
+        " WHERE status     = 'pending'" .
60
+        " AND   gedcom_id  = ?" .
61
+        " AND   xref       = ?" .
62
+        " AND   change_id >= ?"
63
+    )->execute(array($gedcom_id, $xref, $change_id));
64
+    break;
65 65
 case 'accept':
66
-	$gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
67
-	$xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
68
-	// Accept a change, and all previous changes to the same record
69
-	$changes = Database::prepare(
70
-		"SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
71
-		" FROM  `##change` c" .
72
-		" JOIN  `##gedcom` g USING (gedcom_id)" .
73
-		" WHERE c.status   = 'pending'" .
74
-		" AND   gedcom_id  = ?" .
75
-		" AND   xref       = ?" .
76
-		" AND   change_id <= ?" .
77
-		" ORDER BY change_id"
78
-	)->execute(array($gedcom_id, $xref, $change_id))->fetchAll();
79
-	foreach ($changes as $change) {
80
-		if (empty($change->new_gedcom)) {
81
-			// delete
82
-			FunctionsImport::updateRecord($change->old_gedcom, $gedcom_id, true);
83
-		} else {
84
-			// add/update
85
-			FunctionsImport::updateRecord($change->new_gedcom, $gedcom_id, false);
86
-		}
87
-		Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
88
-		Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
89
-	}
90
-	break;
66
+    $gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
67
+    $xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
68
+    // Accept a change, and all previous changes to the same record
69
+    $changes = Database::prepare(
70
+        "SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
71
+        " FROM  `##change` c" .
72
+        " JOIN  `##gedcom` g USING (gedcom_id)" .
73
+        " WHERE c.status   = 'pending'" .
74
+        " AND   gedcom_id  = ?" .
75
+        " AND   xref       = ?" .
76
+        " AND   change_id <= ?" .
77
+        " ORDER BY change_id"
78
+    )->execute(array($gedcom_id, $xref, $change_id))->fetchAll();
79
+    foreach ($changes as $change) {
80
+        if (empty($change->new_gedcom)) {
81
+            // delete
82
+            FunctionsImport::updateRecord($change->old_gedcom, $gedcom_id, true);
83
+        } else {
84
+            // add/update
85
+            FunctionsImport::updateRecord($change->new_gedcom, $gedcom_id, false);
86
+        }
87
+        Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
88
+        Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
89
+    }
90
+    break;
91 91
 case 'undoall':
92
-	Database::prepare(
93
-		"UPDATE `##change`" .
94
-		" SET status='rejected'" .
95
-		" WHERE status='pending' AND gedcom_id=?"
96
-	)->execute(array($WT_TREE->getTreeId()));
97
-	break;
92
+    Database::prepare(
93
+        "UPDATE `##change`" .
94
+        " SET status='rejected'" .
95
+        " WHERE status='pending' AND gedcom_id=?"
96
+    )->execute(array($WT_TREE->getTreeId()));
97
+    break;
98 98
 case 'acceptall':
99
-	$changes = Database::prepare(
100
-		"SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
101
-		" FROM `##change` c" .
102
-		" JOIN `##gedcom` g USING (gedcom_id)" .
103
-		" WHERE c.status='pending' AND gedcom_id=?" .
104
-		" ORDER BY change_id"
105
-	)->execute(array($WT_TREE->getTreeId()))->fetchAll();
106
-	foreach ($changes as $change) {
107
-		if (empty($change->new_gedcom)) {
108
-			// delete
109
-			FunctionsImport::updateRecord($change->old_gedcom, $change->gedcom_id, true);
110
-		} else {
111
-			// add/update
112
-			FunctionsImport::updateRecord($change->new_gedcom, $change->gedcom_id, false);
113
-		}
114
-		Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
115
-		Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
116
-	}
117
-	break;
99
+    $changes = Database::prepare(
100
+        "SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
101
+        " FROM `##change` c" .
102
+        " JOIN `##gedcom` g USING (gedcom_id)" .
103
+        " WHERE c.status='pending' AND gedcom_id=?" .
104
+        " ORDER BY change_id"
105
+    )->execute(array($WT_TREE->getTreeId()))->fetchAll();
106
+    foreach ($changes as $change) {
107
+        if (empty($change->new_gedcom)) {
108
+            // delete
109
+            FunctionsImport::updateRecord($change->old_gedcom, $change->gedcom_id, true);
110
+        } else {
111
+            // add/update
112
+            FunctionsImport::updateRecord($change->new_gedcom, $change->gedcom_id, false);
113
+        }
114
+        Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
115
+        Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
116
+    }
117
+    break;
118 118
 }
119 119
 
120 120
 $changed_gedcoms = Database::prepare(
121
-	"SELECT g.gedcom_name" .
122
-	" FROM `##change` c" .
123
-	" JOIN `##gedcom` g USING (gedcom_id)" .
124
-	" WHERE c.status='pending'" .
125
-	" GROUP BY g.gedcom_name"
121
+    "SELECT g.gedcom_name" .
122
+    " FROM `##change` c" .
123
+    " JOIN `##gedcom` g USING (gedcom_id)" .
124
+    " WHERE c.status='pending'" .
125
+    " GROUP BY g.gedcom_name"
126 126
 )->fetchOneColumn();
127 127
 
128 128
 if ($changed_gedcoms) {
129
-	$changes = Database::prepare(
130
-		"SELECT c.*, UNIX_TIMESTAMP(c.change_time) + :offset AS change_timestamp, u.user_name, u.real_name, g.gedcom_name, new_gedcom, old_gedcom" .
131
-		" FROM `##change` c" .
132
-		" JOIN `##user`   u USING (user_id)" .
133
-		" JOIN `##gedcom` g USING (gedcom_id)" .
134
-		" WHERE c.status='pending'" .
135
-		" ORDER BY gedcom_id, c.xref, c.change_id"
136
-	)
137
-	->execute(array('offset' => WT_TIMESTAMP_OFFSET))
138
-	->fetchAll();
139
-
140
-	$output         = '<br><br><table class="list_table">';
141
-	$prev_xref      = null;
142
-	$prev_gedcom_id = null;
143
-	foreach ($changes as $change) {
144
-		$tree = Tree::findById($change->gedcom_id);
145
-		preg_match('/^0 (?:@' . WT_REGEX_XREF . '@ )?(' . WT_REGEX_TAG . ')/', $change->old_gedcom . $change->new_gedcom, $match);
146
-
147
-
148
-		switch ($match[1]) {
149
-		case 'INDI':
150
-			$record = new Individual($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
151
-			break;
152
-		case 'FAM':
153
-			$record = new Family($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
154
-			break;
155
-		case 'SOUR':
156
-			$record = new Source($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
157
-			break;
158
-		case 'REPO':
159
-			$record = new Repository($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
160
-			break;
161
-		case 'OBJE':
162
-			$record = new Media($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
163
-			break;
164
-		case 'NOTE':
165
-			$record = new Note($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
166
-			break;
167
-		default:
168
-			$record = new GedcomRecord($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
169
-			break;
170
-		}
171
-		if ($change->xref != $prev_xref || $change->gedcom_id != $prev_gedcom_id) {
172
-			if ($prev_xref) {
173
-				$output .= '</table></td></tr>';
174
-			}
175
-			$prev_xref      = $change->xref;
176
-			$prev_gedcom_id = $change->gedcom_id;
177
-			$output .= '<tr><td class="list_value">';
178
-			$output .= '<b><a href="#" onclick="return show_diff(\'' . $record->getHtmlUrl() . '\');"> ' . $record->getFullName() . '</a></b>';
179
-			$output .= '<div class="indent">';
180
-			$output .= '<table class="list_table"><tr>';
181
-			$output .= '<td class="list_label">' . I18N::translate('Accept') . '</td>';
182
-			$output .= '<td class="list_label">' . I18N::translate('Changes') . '</td>';
183
-			$output .= '<td class="list_label">' . I18N::translate('User') . '</td>';
184
-			$output .= '<td class="list_label">' . I18N::translate('Date') . '</td>';
185
-			$output .= '<td class="list_label">' . I18N::translate('Family tree') . '</td>';
186
-			$output .= '<td class="list_label">' . I18N::translate('Reject') . '</td>';
187
-			$output .= '</tr>';
188
-		}
189
-		$output .= '<td class="list_value"><a href="edit_changes.php?action=accept&amp;change_id=' . $change->change_id . '">' . I18N::translate('Accept') . '</a></td>';
190
-		$output .= '<td class="list_value">';
191
-		foreach ($record->getFacts() as $fact) {
192
-			if ($fact->getTag() != 'CHAN') {
193
-				if ($fact->isPendingAddition()) {
194
-					$output .= '<div class="new" title="' . strip_tags($fact->summary()) . '">' . $fact->getLabel() . '</div>';
195
-				} elseif ($fact->isPendingDeletion()) {
196
-					$output .= '<div class="old" title="' . strip_tags($fact->summary()) . '">' . $fact->getLabel() . '</div>';
197
-				}
198
-			}
199
-		}
200
-		echo '</td>';
201
-		$output .= '<td class="list_value"><a href="#" onclick="return reply(\'' . $change->user_name . '\', \'' . I18N::translate('Moderate pending changes') . '\')" title="' . I18N::translate('Send a message') . '">';
202
-		$output .= Filter::escapeHtml($change->real_name);
203
-		$output .= ' - ' . Filter::escapeHtml($change->user_name) . '</a></td>';
204
-		$output .= '<td class="list_value">' . FunctionsDate::formatTimestamp($change->change_timestamp) . '</td>';
205
-		$output .= '<td class="list_value">' . $change->gedcom_name . '</td>';
206
-		$output .= '<td class="list_value"><a href="edit_changes.php?action=undo&amp;change_id=' . $change->change_id . '">' . I18N::translate('Reject') . '</a></td>';
207
-		$output .= '</tr>';
208
-	}
209
-	$output .= '</table></td></tr></td></tr></table>';
210
-
211
-	//-- Now for the global Action bar:
212
-	$output2 = '<br><table class="list_table">';
213
-	// Row 1 column 1: title "Accept all"
214
-	$output2 .= '<tr><td class="list_label">' . I18N::translate('Accept all changes') . '</td>';
215
-	// Row 1 column 2: title "Undo all"
216
-	$output2 .= '<td class="list_label">' . I18N::translate('Reject all changes') . '</td></tr>';
217
-
218
-	// Row 2 column 1: action "Accept all"
219
-	$output2 .= '<tr><td class="list_value">';
220
-	$count = 0;
221
-	foreach ($changed_gedcoms as $gedcom_name) {
222
-		if ($count != 0) {
223
-			$output2 .= '<br>';
224
-		}
225
-		$output2 .= $gedcom_name . ' — ' . '<a href="edit_changes.php?action=acceptall&amp;ged=' . rawurlencode($gedcom_name) . '">' . I18N::translate('Accept all changes') . '</a>';
226
-		$count++;
227
-	}
228
-	$output2 .= '</td>';
229
-	// Row 2 column 2: action "Undo all"
230
-	$output2 .= '<td class="list_value">';
231
-	$count = 0;
232
-	foreach ($changed_gedcoms as $gedcom_name) {
233
-		if ($count != 0) {
234
-			$output2 .= '<br>';
235
-		}
236
-		$output2 .= $gedcom_name . ' — ' . '<a href="edit_changes.php?action=undoall&amp;ged=' . rawurlencode($gedcom_name) . '" onclick="return confirm(\'' . I18N::translate('Are you sure you want to reject all the changes to this family tree?') . '\');">' . I18N::translate('Reject all changes') . '</a>';
237
-		$count++;
238
-	}
239
-	$output2 .= '</td></tr></table>';
240
-
241
-	echo
242
-		$output2, $output, $output2,
243
-		'<br><br><br><br>',
244
-		'<p id="save-cancel">',
245
-		'<input type="button" class="cancel" value="', I18N::translate('close'), '" onclick="closePopupAndReloadParent();">',
246
-		'</p>';
129
+    $changes = Database::prepare(
130
+        "SELECT c.*, UNIX_TIMESTAMP(c.change_time) + :offset AS change_timestamp, u.user_name, u.real_name, g.gedcom_name, new_gedcom, old_gedcom" .
131
+        " FROM `##change` c" .
132
+        " JOIN `##user`   u USING (user_id)" .
133
+        " JOIN `##gedcom` g USING (gedcom_id)" .
134
+        " WHERE c.status='pending'" .
135
+        " ORDER BY gedcom_id, c.xref, c.change_id"
136
+    )
137
+    ->execute(array('offset' => WT_TIMESTAMP_OFFSET))
138
+    ->fetchAll();
139
+
140
+    $output         = '<br><br><table class="list_table">';
141
+    $prev_xref      = null;
142
+    $prev_gedcom_id = null;
143
+    foreach ($changes as $change) {
144
+        $tree = Tree::findById($change->gedcom_id);
145
+        preg_match('/^0 (?:@' . WT_REGEX_XREF . '@ )?(' . WT_REGEX_TAG . ')/', $change->old_gedcom . $change->new_gedcom, $match);
146
+
147
+
148
+        switch ($match[1]) {
149
+        case 'INDI':
150
+            $record = new Individual($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
151
+            break;
152
+        case 'FAM':
153
+            $record = new Family($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
154
+            break;
155
+        case 'SOUR':
156
+            $record = new Source($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
157
+            break;
158
+        case 'REPO':
159
+            $record = new Repository($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
160
+            break;
161
+        case 'OBJE':
162
+            $record = new Media($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
163
+            break;
164
+        case 'NOTE':
165
+            $record = new Note($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
166
+            break;
167
+        default:
168
+            $record = new GedcomRecord($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
169
+            break;
170
+        }
171
+        if ($change->xref != $prev_xref || $change->gedcom_id != $prev_gedcom_id) {
172
+            if ($prev_xref) {
173
+                $output .= '</table></td></tr>';
174
+            }
175
+            $prev_xref      = $change->xref;
176
+            $prev_gedcom_id = $change->gedcom_id;
177
+            $output .= '<tr><td class="list_value">';
178
+            $output .= '<b><a href="#" onclick="return show_diff(\'' . $record->getHtmlUrl() . '\');"> ' . $record->getFullName() . '</a></b>';
179
+            $output .= '<div class="indent">';
180
+            $output .= '<table class="list_table"><tr>';
181
+            $output .= '<td class="list_label">' . I18N::translate('Accept') . '</td>';
182
+            $output .= '<td class="list_label">' . I18N::translate('Changes') . '</td>';
183
+            $output .= '<td class="list_label">' . I18N::translate('User') . '</td>';
184
+            $output .= '<td class="list_label">' . I18N::translate('Date') . '</td>';
185
+            $output .= '<td class="list_label">' . I18N::translate('Family tree') . '</td>';
186
+            $output .= '<td class="list_label">' . I18N::translate('Reject') . '</td>';
187
+            $output .= '</tr>';
188
+        }
189
+        $output .= '<td class="list_value"><a href="edit_changes.php?action=accept&amp;change_id=' . $change->change_id . '">' . I18N::translate('Accept') . '</a></td>';
190
+        $output .= '<td class="list_value">';
191
+        foreach ($record->getFacts() as $fact) {
192
+            if ($fact->getTag() != 'CHAN') {
193
+                if ($fact->isPendingAddition()) {
194
+                    $output .= '<div class="new" title="' . strip_tags($fact->summary()) . '">' . $fact->getLabel() . '</div>';
195
+                } elseif ($fact->isPendingDeletion()) {
196
+                    $output .= '<div class="old" title="' . strip_tags($fact->summary()) . '">' . $fact->getLabel() . '</div>';
197
+                }
198
+            }
199
+        }
200
+        echo '</td>';
201
+        $output .= '<td class="list_value"><a href="#" onclick="return reply(\'' . $change->user_name . '\', \'' . I18N::translate('Moderate pending changes') . '\')" title="' . I18N::translate('Send a message') . '">';
202
+        $output .= Filter::escapeHtml($change->real_name);
203
+        $output .= ' - ' . Filter::escapeHtml($change->user_name) . '</a></td>';
204
+        $output .= '<td class="list_value">' . FunctionsDate::formatTimestamp($change->change_timestamp) . '</td>';
205
+        $output .= '<td class="list_value">' . $change->gedcom_name . '</td>';
206
+        $output .= '<td class="list_value"><a href="edit_changes.php?action=undo&amp;change_id=' . $change->change_id . '">' . I18N::translate('Reject') . '</a></td>';
207
+        $output .= '</tr>';
208
+    }
209
+    $output .= '</table></td></tr></td></tr></table>';
210
+
211
+    //-- Now for the global Action bar:
212
+    $output2 = '<br><table class="list_table">';
213
+    // Row 1 column 1: title "Accept all"
214
+    $output2 .= '<tr><td class="list_label">' . I18N::translate('Accept all changes') . '</td>';
215
+    // Row 1 column 2: title "Undo all"
216
+    $output2 .= '<td class="list_label">' . I18N::translate('Reject all changes') . '</td></tr>';
217
+
218
+    // Row 2 column 1: action "Accept all"
219
+    $output2 .= '<tr><td class="list_value">';
220
+    $count = 0;
221
+    foreach ($changed_gedcoms as $gedcom_name) {
222
+        if ($count != 0) {
223
+            $output2 .= '<br>';
224
+        }
225
+        $output2 .= $gedcom_name . ' — ' . '<a href="edit_changes.php?action=acceptall&amp;ged=' . rawurlencode($gedcom_name) . '">' . I18N::translate('Accept all changes') . '</a>';
226
+        $count++;
227
+    }
228
+    $output2 .= '</td>';
229
+    // Row 2 column 2: action "Undo all"
230
+    $output2 .= '<td class="list_value">';
231
+    $count = 0;
232
+    foreach ($changed_gedcoms as $gedcom_name) {
233
+        if ($count != 0) {
234
+            $output2 .= '<br>';
235
+        }
236
+        $output2 .= $gedcom_name . ' — ' . '<a href="edit_changes.php?action=undoall&amp;ged=' . rawurlencode($gedcom_name) . '" onclick="return confirm(\'' . I18N::translate('Are you sure you want to reject all the changes to this family tree?') . '\');">' . I18N::translate('Reject all changes') . '</a>';
237
+        $count++;
238
+    }
239
+    $output2 .= '</td></tr></table>';
240
+
241
+    echo
242
+        $output2, $output, $output2,
243
+        '<br><br><br><br>',
244
+        '<p id="save-cancel">',
245
+        '<input type="button" class="cancel" value="', I18N::translate('close'), '" onclick="closePopupAndReloadParent();">',
246
+        '</p>';
247 247
 } else {
248
-	// No pending changes - refresh the parent window and close this one
249
-	$controller->addInlineJavascript('closePopupAndReloadParent();');
248
+    // No pending changes - refresh the parent window and close this one
249
+    $controller->addInlineJavascript('closePopupAndReloadParent();');
250 250
 }
251 251
 
252 252
 echo '</div>';
Please login to merge, or discard this patch.
Switch Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -49,72 +49,72 @@  discard block
 block discarded – undo
49 49
 echo '<div id="pending"><h2>', I18N::translate('Pending changes'), '</h2>';
50 50
 
51 51
 switch ($action) {
52
-case 'undo':
53
-	$gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
54
-	$xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
55
-	// Undo a change, and subsequent changes to the same record
56
-	Database::prepare(
57
-		"UPDATE `##change`" .
58
-		" SET   status     = 'rejected'" .
59
-		" WHERE status     = 'pending'" .
60
-		" AND   gedcom_id  = ?" .
61
-		" AND   xref       = ?" .
62
-		" AND   change_id >= ?"
63
-	)->execute(array($gedcom_id, $xref, $change_id));
64
-	break;
65
-case 'accept':
66
-	$gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
67
-	$xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
68
-	// Accept a change, and all previous changes to the same record
69
-	$changes = Database::prepare(
70
-		"SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
71
-		" FROM  `##change` c" .
72
-		" JOIN  `##gedcom` g USING (gedcom_id)" .
73
-		" WHERE c.status   = 'pending'" .
74
-		" AND   gedcom_id  = ?" .
75
-		" AND   xref       = ?" .
76
-		" AND   change_id <= ?" .
77
-		" ORDER BY change_id"
78
-	)->execute(array($gedcom_id, $xref, $change_id))->fetchAll();
79
-	foreach ($changes as $change) {
80
-		if (empty($change->new_gedcom)) {
81
-			// delete
82
-			FunctionsImport::updateRecord($change->old_gedcom, $gedcom_id, true);
83
-		} else {
84
-			// add/update
85
-			FunctionsImport::updateRecord($change->new_gedcom, $gedcom_id, false);
86
-		}
87
-		Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
88
-		Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
89
-	}
90
-	break;
91
-case 'undoall':
92
-	Database::prepare(
93
-		"UPDATE `##change`" .
94
-		" SET status='rejected'" .
95
-		" WHERE status='pending' AND gedcom_id=?"
96
-	)->execute(array($WT_TREE->getTreeId()));
97
-	break;
98
-case 'acceptall':
99
-	$changes = Database::prepare(
100
-		"SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
101
-		" FROM `##change` c" .
102
-		" JOIN `##gedcom` g USING (gedcom_id)" .
103
-		" WHERE c.status='pending' AND gedcom_id=?" .
104
-		" ORDER BY change_id"
105
-	)->execute(array($WT_TREE->getTreeId()))->fetchAll();
106
-	foreach ($changes as $change) {
107
-		if (empty($change->new_gedcom)) {
108
-			// delete
109
-			FunctionsImport::updateRecord($change->old_gedcom, $change->gedcom_id, true);
110
-		} else {
111
-			// add/update
112
-			FunctionsImport::updateRecord($change->new_gedcom, $change->gedcom_id, false);
113
-		}
114
-		Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
115
-		Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
116
-	}
117
-	break;
52
+    case 'undo':
53
+	    $gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
54
+	    $xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
55
+	    // Undo a change, and subsequent changes to the same record
56
+	    Database::prepare(
57
+		    "UPDATE `##change`" .
58
+		    " SET   status     = 'rejected'" .
59
+		    " WHERE status     = 'pending'" .
60
+		    " AND   gedcom_id  = ?" .
61
+		    " AND   xref       = ?" .
62
+		    " AND   change_id >= ?"
63
+	    )->execute(array($gedcom_id, $xref, $change_id));
64
+	    break;
65
+    case 'accept':
66
+	    $gedcom_id = Database::prepare("SELECT gedcom_id FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
67
+	    $xref      = Database::prepare("SELECT xref      FROM `##change` WHERE change_id=?")->execute(array($change_id))->fetchOne();
68
+	    // Accept a change, and all previous changes to the same record
69
+	    $changes = Database::prepare(
70
+		    "SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
71
+		    " FROM  `##change` c" .
72
+		    " JOIN  `##gedcom` g USING (gedcom_id)" .
73
+		    " WHERE c.status   = 'pending'" .
74
+		    " AND   gedcom_id  = ?" .
75
+		    " AND   xref       = ?" .
76
+		    " AND   change_id <= ?" .
77
+		    " ORDER BY change_id"
78
+	    )->execute(array($gedcom_id, $xref, $change_id))->fetchAll();
79
+	    foreach ($changes as $change) {
80
+		    if (empty($change->new_gedcom)) {
81
+			    // delete
82
+			    FunctionsImport::updateRecord($change->old_gedcom, $gedcom_id, true);
83
+		    } else {
84
+			    // add/update
85
+			    FunctionsImport::updateRecord($change->new_gedcom, $gedcom_id, false);
86
+		    }
87
+		    Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
88
+		    Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
89
+	    }
90
+	    break;
91
+    case 'undoall':
92
+	    Database::prepare(
93
+		    "UPDATE `##change`" .
94
+		    " SET status='rejected'" .
95
+		    " WHERE status='pending' AND gedcom_id=?"
96
+	    )->execute(array($WT_TREE->getTreeId()));
97
+	    break;
98
+    case 'acceptall':
99
+	    $changes = Database::prepare(
100
+		    "SELECT change_id, gedcom_id, gedcom_name, xref, old_gedcom, new_gedcom" .
101
+		    " FROM `##change` c" .
102
+		    " JOIN `##gedcom` g USING (gedcom_id)" .
103
+		    " WHERE c.status='pending' AND gedcom_id=?" .
104
+		    " ORDER BY change_id"
105
+	    )->execute(array($WT_TREE->getTreeId()))->fetchAll();
106
+	    foreach ($changes as $change) {
107
+		    if (empty($change->new_gedcom)) {
108
+			    // delete
109
+			    FunctionsImport::updateRecord($change->old_gedcom, $change->gedcom_id, true);
110
+		    } else {
111
+			    // add/update
112
+			    FunctionsImport::updateRecord($change->new_gedcom, $change->gedcom_id, false);
113
+		    }
114
+		    Database::prepare("UPDATE `##change` SET status='accepted' WHERE change_id=?")->execute(array($change->change_id));
115
+		    Log::addEditLog("Accepted change {$change->change_id} for {$change->xref} / {$change->gedcom_name} into database");
116
+	    }
117
+	    break;
118 118
 }
119 119
 
120 120
 $changed_gedcoms = Database::prepare(
@@ -146,27 +146,27 @@  discard block
 block discarded – undo
146 146
 
147 147
 
148 148
 		switch ($match[1]) {
149
-		case 'INDI':
150
-			$record = new Individual($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
151
-			break;
152
-		case 'FAM':
153
-			$record = new Family($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
154
-			break;
155
-		case 'SOUR':
156
-			$record = new Source($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
157
-			break;
158
-		case 'REPO':
159
-			$record = new Repository($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
160
-			break;
161
-		case 'OBJE':
162
-			$record = new Media($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
163
-			break;
164
-		case 'NOTE':
165
-			$record = new Note($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
166
-			break;
167
-		default:
168
-			$record = new GedcomRecord($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
169
-			break;
149
+		    case 'INDI':
150
+			    $record = new Individual($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
151
+			    break;
152
+		    case 'FAM':
153
+			    $record = new Family($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
154
+			    break;
155
+		    case 'SOUR':
156
+			    $record = new Source($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
157
+			    break;
158
+		    case 'REPO':
159
+			    $record = new Repository($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
160
+			    break;
161
+		    case 'OBJE':
162
+			    $record = new Media($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
163
+			    break;
164
+		    case 'NOTE':
165
+			    $record = new Note($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
166
+			    break;
167
+		    default:
168
+			    $record = new GedcomRecord($change->xref, $change->old_gedcom, $change->new_gedcom, $tree);
169
+			    break;
170 170
 		}
171 171
 		if ($change->xref != $prev_xref || $change->gedcom_id != $prev_gedcom_id) {
172 172
 			if ($prev_xref) {
Please login to merge, or discard this patch.
admin_site_logs.php 2 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 
32 32
 $controller = new PageController;
33 33
 $controller
34
-	->restrictAccess(Auth::isManager($WT_TREE))
35
-	->setPageTitle(I18N::translate('Website logs'));
34
+    ->restrictAccess(Auth::isManager($WT_TREE))
35
+    ->setPageTitle(I18N::translate('Website logs'));
36 36
 
37 37
 $earliest = Database::prepare("SELECT IFNULL(DATE(MIN(log_time)), CURDATE()) FROM `##log`")->execute(array())->fetchOne();
38 38
 $latest   = Database::prepare("SELECT IFNULL(DATE(MAX(log_time)), CURDATE()) FROM `##log`")->execute(array())->fetchOne();
@@ -49,148 +49,148 @@  discard block
 block discarded – undo
49 49
 $search = isset($search['value']) ? $search['value'] : null;
50 50
 
51 51
 if (Auth::isAdmin()) {
52
-	// Administrators can see all logs
53
-	$gedc = Filter::get('gedc');
52
+    // Administrators can see all logs
53
+    $gedc = Filter::get('gedc');
54 54
 } else {
55
-	// Managers can only see logs relating to this gedcom
56
-	$gedc = $WT_TREE->getName();
55
+    // Managers can only see logs relating to this gedcom
56
+    $gedc = $WT_TREE->getName();
57 57
 }
58 58
 
59 59
 $sql_select =
60
-	"SELECT SQL_CALC_FOUND_ROWS log_id, log_time, log_type, log_message, ip_address, IFNULL(user_name, '<none>') AS user_name, IFNULL(gedcom_name, '<none>') AS gedcom_name" .
61
-	" FROM `##log`" .
62
-	" LEFT JOIN `##user` USING (user_id)" . // user may be deleted
63
-	" LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
60
+    "SELECT SQL_CALC_FOUND_ROWS log_id, log_time, log_type, log_message, ip_address, IFNULL(user_name, '<none>') AS user_name, IFNULL(gedcom_name, '<none>') AS gedcom_name" .
61
+    " FROM `##log`" .
62
+    " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
63
+    " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
64 64
 
65 65
 $where = " WHERE 1";
66 66
 $args  = array();
67 67
 if ($search) {
68
-	$where .= " AND log_message LIKE CONCAT('%', :search, '%')";
69
-	$args['search'] = $search;
68
+    $where .= " AND log_message LIKE CONCAT('%', :search, '%')";
69
+    $args['search'] = $search;
70 70
 }
71 71
 if ($from) {
72
-	$where .= " AND log_time >= :from";
73
-	$args['from'] = $from;
72
+    $where .= " AND log_time >= :from";
73
+    $args['from'] = $from;
74 74
 }
75 75
 if ($to) {
76
-	$where .= " AND log_time < TIMESTAMPADD(DAY, 1 , :to)"; // before end of the day
77
-	$args['to'] = $to;
76
+    $where .= " AND log_time < TIMESTAMPADD(DAY, 1 , :to)"; // before end of the day
77
+    $args['to'] = $to;
78 78
 }
79 79
 if ($type) {
80
-	$where .= " AND log_type = :type";
81
-	$args['type'] = $type;
80
+    $where .= " AND log_type = :type";
81
+    $args['type'] = $type;
82 82
 }
83 83
 if ($text) {
84
-	$where .= " AND log_message LIKE CONCAT('%', :text, '%')";
85
-	$args['text'] = $text;
84
+    $where .= " AND log_message LIKE CONCAT('%', :text, '%')";
85
+    $args['text'] = $text;
86 86
 }
87 87
 if ($ip) {
88
-	$where .= " AND ip_address LIKE CONCAT('%', :ip, '%')";
89
-	$args['ip'] = $ip;
88
+    $where .= " AND ip_address LIKE CONCAT('%', :ip, '%')";
89
+    $args['ip'] = $ip;
90 90
 }
91 91
 if ($user) {
92
-	$where .= " AND user_name LIKE CONCAT('%', :user, '%')";
93
-	$args['user'] = $user;
92
+    $where .= " AND user_name LIKE CONCAT('%', :user, '%')";
93
+    $args['user'] = $user;
94 94
 }
95 95
 if ($gedc) {
96
-	$where .= " AND gedcom_name LIKE CONCAT('%', :gedc, '%')";
97
-	$args['gedc'] = $gedc;
96
+    $where .= " AND gedcom_name LIKE CONCAT('%', :gedc, '%')";
97
+    $args['gedc'] = $gedc;
98 98
 }
99 99
 
100 100
 switch ($action) {
101 101
 case 'delete':
102
-	$sql_delete =
103
-		"DELETE `##log` FROM `##log`" .
104
-		" LEFT JOIN `##user` USING (user_id)" . // user may be deleted
105
-		" LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
102
+    $sql_delete =
103
+        "DELETE `##log` FROM `##log`" .
104
+        " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
105
+        " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
106 106
 
107
-	Database::prepare($sql_delete . $where)->execute($args);
108
-	break;
107
+    Database::prepare($sql_delete . $where)->execute($args);
108
+    break;
109 109
 
110 110
 case 'export':
111
-	header('Content-Type: text/csv');
112
-	header('Content-Disposition: attachment; filename="webtrees-logs.csv"');
113
-	$rows = Database::prepare($sql_select . $where . ' ORDER BY log_id')->execute($args)->fetchAll();
114
-	foreach ($rows as $row) {
115
-		echo
116
-			'"', $row->log_time, '",',
117
-			'"', $row->log_type, '",',
118
-			'"', str_replace('"', '""', $row->log_message), '",',
119
-			'"', $row->ip_address, '",',
120
-			'"', str_replace('"', '""', $row->user_name), '",',
121
-			'"', str_replace('"', '""', $row->gedcom_name), '"',
122
-			"\n";
123
-	}
124
-
125
-	return;
111
+    header('Content-Type: text/csv');
112
+    header('Content-Disposition: attachment; filename="webtrees-logs.csv"');
113
+    $rows = Database::prepare($sql_select . $where . ' ORDER BY log_id')->execute($args)->fetchAll();
114
+    foreach ($rows as $row) {
115
+        echo
116
+            '"', $row->log_time, '",',
117
+            '"', $row->log_type, '",',
118
+            '"', str_replace('"', '""', $row->log_message), '",',
119
+            '"', $row->ip_address, '",',
120
+            '"', str_replace('"', '""', $row->user_name), '",',
121
+            '"', str_replace('"', '""', $row->gedcom_name), '"',
122
+            "\n";
123
+    }
124
+
125
+    return;
126 126
 case 'load_json':
127
-	$start  = Filter::getInteger('start');
128
-	$length = Filter::getInteger('length');
129
-	$order  = Filter::getArray('order');
130
-
131
-	if ($order) {
132
-		$order_by = " ORDER BY ";
133
-		foreach ($order as $key => $value) {
134
-			if ($key > 0) {
135
-				$order_by .= ',';
136
-			}
137
-			// Datatables numbers columns 0, 1, 2
138
-			// MySQL numbers columns 1, 2, 3
139
-			switch ($value['dir']) {
140
-			case 'asc':
141
-				$order_by .= (1 + $value['column']) . " ASC ";
142
-				break;
143
-			case 'desc':
144
-				$order_by .= (1 + $value['column']) . " DESC ";
145
-				break;
146
-			}
147
-		}
148
-	} else {
149
-		$order_by = " ORDER BY 1 ASC";
150
-	}
151
-
152
-	if ($length) {
153
-		Auth::user()->setPreference('admin_site_log_page_size', $length);
154
-		$limit          = " LIMIT :limit OFFSET :offset";
155
-		$args['limit']  = $length;
156
-		$args['offset'] = $start;
157
-	} else {
158
-		$limit = "";
159
-	}
160
-
161
-	// This becomes a JSON list, not array, so need to fetch with numeric keys.
162
-	$data = Database::prepare($sql_select . $where . $order_by . $limit)->execute($args)->fetchAll(PDO::FETCH_NUM);
163
-	foreach ($data as &$datum) {
164
-		$datum[2] = Filter::escapeHtml($datum[2]);
165
-		$datum[3] = '<span dir="auto">' . Filter::escapeHtml($datum[3]) . '</span>';
166
-		$datum[4] = '<span dir="auto">' . Filter::escapeHtml($datum[4]) . '</span>';
167
-		$datum[5] = '<span dir="auto">' . Filter::escapeHtml($datum[5]) . '</span>';
168
-		$datum[6] = '<span dir="auto">' . Filter::escapeHtml($datum[6]) . '</span>';
169
-	}
170
-
171
-	// Total filtered/unfiltered rows
172
-	$recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
173
-	$recordsTotal    = (int) Database::prepare("SELECT COUNT(*) FROM `##log`")->fetchOne();
174
-
175
-	header('Content-type: application/json');
176
-	// See http://www.datatables.net/usage/server-side
177
-	echo json_encode(array(
178
-		'draw'            => Filter::getInteger('draw'),
179
-		'recordsTotal'    => $recordsTotal,
180
-		'recordsFiltered' => $recordsFiltered,
181
-		'data'            => $data,
182
-	));
183
-
184
-	return;
127
+    $start  = Filter::getInteger('start');
128
+    $length = Filter::getInteger('length');
129
+    $order  = Filter::getArray('order');
130
+
131
+    if ($order) {
132
+        $order_by = " ORDER BY ";
133
+        foreach ($order as $key => $value) {
134
+            if ($key > 0) {
135
+                $order_by .= ',';
136
+            }
137
+            // Datatables numbers columns 0, 1, 2
138
+            // MySQL numbers columns 1, 2, 3
139
+            switch ($value['dir']) {
140
+            case 'asc':
141
+                $order_by .= (1 + $value['column']) . " ASC ";
142
+                break;
143
+            case 'desc':
144
+                $order_by .= (1 + $value['column']) . " DESC ";
145
+                break;
146
+            }
147
+        }
148
+    } else {
149
+        $order_by = " ORDER BY 1 ASC";
150
+    }
151
+
152
+    if ($length) {
153
+        Auth::user()->setPreference('admin_site_log_page_size', $length);
154
+        $limit          = " LIMIT :limit OFFSET :offset";
155
+        $args['limit']  = $length;
156
+        $args['offset'] = $start;
157
+    } else {
158
+        $limit = "";
159
+    }
160
+
161
+    // This becomes a JSON list, not array, so need to fetch with numeric keys.
162
+    $data = Database::prepare($sql_select . $where . $order_by . $limit)->execute($args)->fetchAll(PDO::FETCH_NUM);
163
+    foreach ($data as &$datum) {
164
+        $datum[2] = Filter::escapeHtml($datum[2]);
165
+        $datum[3] = '<span dir="auto">' . Filter::escapeHtml($datum[3]) . '</span>';
166
+        $datum[4] = '<span dir="auto">' . Filter::escapeHtml($datum[4]) . '</span>';
167
+        $datum[5] = '<span dir="auto">' . Filter::escapeHtml($datum[5]) . '</span>';
168
+        $datum[6] = '<span dir="auto">' . Filter::escapeHtml($datum[6]) . '</span>';
169
+    }
170
+
171
+    // Total filtered/unfiltered rows
172
+    $recordsFiltered = (int) Database::prepare("SELECT FOUND_ROWS()")->fetchOne();
173
+    $recordsTotal    = (int) Database::prepare("SELECT COUNT(*) FROM `##log`")->fetchOne();
174
+
175
+    header('Content-type: application/json');
176
+    // See http://www.datatables.net/usage/server-side
177
+    echo json_encode(array(
178
+        'draw'            => Filter::getInteger('draw'),
179
+        'recordsTotal'    => $recordsTotal,
180
+        'recordsFiltered' => $recordsFiltered,
181
+        'data'            => $data,
182
+    ));
183
+
184
+    return;
185 185
 }
186 186
 
187 187
 $controller
188
-	->pageHeader()
189
-	->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
190
-	->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
191
-	->addExternalJavascript(WT_MOMENT_JS_URL)
192
-	->addExternalJavascript(WT_BOOTSTRAP_DATETIMEPICKER_JS_URL)
193
-	->addInlineJavascript('
188
+    ->pageHeader()
189
+    ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
190
+    ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
191
+    ->addExternalJavascript(WT_MOMENT_JS_URL)
192
+    ->addExternalJavascript(WT_BOOTSTRAP_DATETIMEPICKER_JS_URL)
193
+    ->addInlineJavascript('
194 194
 		jQuery(".table-site-logs").dataTable( {
195 195
 			processing: true,
196 196
 			serverSide: true,
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 $users_array = array();
230 230
 foreach (User::all() as $tmp_user) {
231
-	$users_array[$tmp_user->getUserName()] = $tmp_user->getUserName();
231
+    $users_array[$tmp_user->getUserName()] = $tmp_user->getUserName();
232 232
 }
233 233
 
234 234
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -137,12 +137,12 @@
 block discarded – undo
137 137
 			// Datatables numbers columns 0, 1, 2
138 138
 			// MySQL numbers columns 1, 2, 3
139 139
 			switch ($value['dir']) {
140
-			case 'asc':
141
-				$order_by .= (1 + $value['column']) . " ASC ";
142
-				break;
143
-			case 'desc':
144
-				$order_by .= (1 + $value['column']) . " DESC ";
145
-				break;
140
+			    case 'asc':
141
+				    $order_by .= (1 + $value['column']) . " ASC ";
142
+				    break;
143
+			    case 'desc':
144
+				    $order_by .= (1 + $value['column']) . " DESC ";
145
+				    break;
146 146
 			}
147 147
 		}
148 148
 	} else {
Please login to merge, or discard this patch.
admin_module_tabs.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -24,33 +24,33 @@  discard block
 block discarded – undo
24 24
 
25 25
 $controller = new PageController;
26 26
 $controller
27
-	->restrictAccess(Auth::isAdmin())
28
-	->setPageTitle(I18N::translate('Tabs'));
27
+    ->restrictAccess(Auth::isAdmin())
28
+    ->setPageTitle(I18N::translate('Tabs'));
29 29
 
30 30
 $action  = Filter::post('action');
31 31
 $modules = Module::getAllModulesByComponent('tab');
32 32
 
33 33
 if ($action === 'update_mods' && Filter::checkCsrf()) {
34
-	foreach ($modules as $module) {
35
-		foreach (Tree::getAll() as $tree) {
36
-			$access_level = Filter::post('access-' . $module->getName() . '-' . $tree->getTreeId(), WT_REGEX_INTEGER, $module->defaultAccessLevel());
37
-			Database::prepare(
38
-				"REPLACE INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)"
39
-			)->execute(array($module->getName(), $tree->getTreeId(), $access_level));
40
-		}
41
-		$order = Filter::post('order-' . $module->getName());
42
-		Database::prepare(
43
-			"UPDATE `##module` SET tab_order=? WHERE module_name=?"
44
-		)->execute(array($order, $module->getName()));
45
-	}
34
+    foreach ($modules as $module) {
35
+        foreach (Tree::getAll() as $tree) {
36
+            $access_level = Filter::post('access-' . $module->getName() . '-' . $tree->getTreeId(), WT_REGEX_INTEGER, $module->defaultAccessLevel());
37
+            Database::prepare(
38
+                "REPLACE INTO `##module_privacy` (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)"
39
+            )->execute(array($module->getName(), $tree->getTreeId(), $access_level));
40
+        }
41
+        $order = Filter::post('order-' . $module->getName());
42
+        Database::prepare(
43
+            "UPDATE `##module` SET tab_order=? WHERE module_name=?"
44
+        )->execute(array($order, $module->getName()));
45
+    }
46 46
 
47
-	header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
47
+    header('Location: ' . WT_BASE_URL . WT_SCRIPT_NAME);
48 48
 
49
-	return;
49
+    return;
50 50
 }
51 51
 
52 52
 $controller
53
-	->addInlineJavascript('
53
+    ->addInlineJavascript('
54 54
 		jQuery("#module_table").sortable({
55 55
 			items: ".sortme",
56 56
 			forceHelperSize: true,
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 			}
68 68
 		});
69 69
 	')
70
-	->pageHeader();
70
+    ->pageHeader();
71 71
 
72 72
 ?>
73 73
 <ol class="breadcrumb small">
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -98,8 +98,11 @@
 block discarded – undo
98 98
 				<td class="col-xs-1">
99 99
 					<?php if ($module instanceof ModuleConfigInterface): ?>
100 100
 					<a href="<?php echo $module->getConfigLink(); ?>"><?php echo $module->getTitle(); ?> <i class="fa fa-cogs"></i></a>
101
-					<?php else: ?>
102
-					<?php echo $module->getTitle(); ?>
101
+					<?php else {
102
+    : ?>
103
+					<?php echo $module->getTitle();
104
+}
105
+?>
103 106
 					<?php endif; ?>
104 107
 				</td>
105 108
 				<td class="col-xs-5"><?php echo $module->getDescription(); ?></td>
Please login to merge, or discard this patch.
mediaviewer.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -34,34 +34,34 @@  discard block
 block discarded – undo
34 34
 $controller = new MediaController($record);
35 35
 
36 36
 if ($controller->record && $controller->record->canShow()) {
37
-	if ($controller->record->isPendingDeletion()) {
38
-		if (Auth::isModerator($controller->record->getTree())) {
39
-			FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
40
-				'This media object has been deleted. You should review the deletion and then %1$s or %2$s it.',
41
-				'<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>',
42
-				'<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>'
43
-			) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
44
-		} elseif (Auth::isEditor($controller->record->getTree())) {
45
-			FlashMessages::addMessage(I18N::translate('This media object has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
46
-		}
47
-	} elseif ($controller->record->isPendingAddtion()) {
48
-		if (Auth::isModerator($controller->record->getTree())) {
49
-			FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
50
-				'This media object has been edited. You should review the changes and then %1$s or %2$s them.',
51
-				'<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>',
52
-				'<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>'
53
-			) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
54
-		} elseif (Auth::isEditor($controller->record->getTree())) {
55
-			FlashMessages::addMessage(I18N::translate('This media object has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
56
-		}
57
-	}
58
-	$controller->pageHeader();
37
+    if ($controller->record->isPendingDeletion()) {
38
+        if (Auth::isModerator($controller->record->getTree())) {
39
+            FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
40
+                'This media object has been deleted. You should review the deletion and then %1$s or %2$s it.',
41
+                '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'accept') . '</a>',
42
+                '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the deletion and then accept or reject it.', 'reject') . '</a>'
43
+            ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
44
+        } elseif (Auth::isEditor($controller->record->getTree())) {
45
+            FlashMessages::addMessage(I18N::translate('This media object has been deleted. The deletion will need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
46
+        }
47
+    } elseif ($controller->record->isPendingAddtion()) {
48
+        if (Auth::isModerator($controller->record->getTree())) {
49
+            FlashMessages::addMessage(/* I18N: %1$s is “accept”, %2$s is “reject”. These are links. */ I18N::translate(
50
+                'This media object has been edited. You should review the changes and then %1$s or %2$s them.',
51
+                '<a href="#" onclick="accept_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'accept') . '</a>',
52
+                '<a href="#" onclick="reject_changes(\'' . $controller->record->getXref() . '\');">' . I18N::translateContext('You should review the changes and then accept or reject them.', 'reject') . '</a>'
53
+            ) . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
54
+        } elseif (Auth::isEditor($controller->record->getTree())) {
55
+            FlashMessages::addMessage(I18N::translate('This media object has been edited. The changes need to be reviewed by a moderator.') . ' ' . FunctionsPrint::helpLink('pending_changes'), 'warning');
56
+        }
57
+    }
58
+    $controller->pageHeader();
59 59
 } else {
60
-	FlashMessages::addMessage(I18N::translate('This media object does not exist or you do not have permission to view it.'), 'danger');
61
-	http_response_code(404);
62
-	$controller->pageHeader();
60
+    FlashMessages::addMessage(I18N::translate('This media object does not exist or you do not have permission to view it.'), 'danger');
61
+    http_response_code(404);
62
+    $controller->pageHeader();
63 63
 
64
-	return;
64
+    return;
65 65
 }
66 66
 
67 67
 $controller->addInlineJavascript('
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
 			<tr>
133 133
 				<td style="text-align:center; width:150px;">
134 134
 				<?php
135
-					// When we have a pending edit, $controller->record shows the *old* data.
136
-					// As a temporary kludge, fetch a "normal" version of the record - which includes pending changes
137
-					// Perhaps check both, and use RED/BLUE boxes.
138
-					$tmp = Media::getInstance($controller->record->getXref(), $WT_TREE);
139
-					echo $tmp->displayImage();
140
-					if (!$tmp->isExternal()) {
141
-						if ($tmp->fileExists('main')) {
142
-							if ($WT_TREE->getPreference('SHOW_MEDIA_DOWNLOAD') >= Auth::accessLevel($WT_TREE)) {
143
-								echo '<p><a href="' . $tmp->getHtmlUrlDirect('main', true) . '">' . I18N::translate('Download file') . '</a></p>';
144
-							}
145
-						} else {
146
-							echo '<p class="ui-state-error">' . I18N::translate('The file “%s” does not exist.', $tmp->getFilename()) . '</p>';
147
-						}
148
-					}
149
-				?>
135
+                    // When we have a pending edit, $controller->record shows the *old* data.
136
+                    // As a temporary kludge, fetch a "normal" version of the record - which includes pending changes
137
+                    // Perhaps check both, and use RED/BLUE boxes.
138
+                    $tmp = Media::getInstance($controller->record->getXref(), $WT_TREE);
139
+                    echo $tmp->displayImage();
140
+                    if (!$tmp->isExternal()) {
141
+                        if ($tmp->fileExists('main')) {
142
+                            if ($WT_TREE->getPreference('SHOW_MEDIA_DOWNLOAD') >= Auth::accessLevel($WT_TREE)) {
143
+                                echo '<p><a href="' . $tmp->getHtmlUrlDirect('main', true) . '">' . I18N::translate('Download file') . '</a></p>';
144
+                            }
145
+                        } else {
146
+                            echo '<p class="ui-state-error">' . I18N::translate('The file “%s” does not exist.', $tmp->getFilename()) . '</p>';
147
+                        }
148
+                    }
149
+                ?>
150 150
 					</td>
151 151
 					<td>
152 152
 						<table class="facts_table">
153 153
 							<?php
154
-							foreach ($facts as $fact) {
155
-								FunctionsPrintFacts::printFact($fact, $controller->record);
156
-							}
157
-							?>
154
+                            foreach ($facts as $fact) {
155
+                                FunctionsPrintFacts::printFact($fact, $controller->record);
156
+                            }
157
+                            ?>
158 158
 						</table>
159 159
 					</td>
160 160
 				</tr>
Please login to merge, or discard this patch.
site-offline.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -33,25 +33,25 @@  discard block
 block discarded – undo
33 33
 define('WT_LOCALE', I18N::init());
34 34
 
35 35
 if (file_exists(WT_DATA_DIR . 'offline.txt')) {
36
-	$offline_txt = file_get_contents(WT_DATA_DIR . 'offline.txt');
36
+    $offline_txt = file_get_contents(WT_DATA_DIR . 'offline.txt');
37 37
 } else {
38
-	// offline.txt has gone - we're back online!
39
-	header('Location: index.php');
38
+    // offline.txt has gone - we're back online!
39
+    header('Location: index.php');
40 40
 
41
-	return;
41
+    return;
42 42
 }
43 43
 
44 44
 http_response_code(503);
45 45
 header('Content-Type: text/html; charset=UTF-8');
46 46
 
47 47
 echo
48
-	'<!DOCTYPE html>',
49
-	'<html ', I18N::htmlAttributes(), '>',
50
-	'<head>',
51
-	'<meta charset="UTF-8">',
52
-	'<title>', WT_WEBTREES, '</title>',
53
-	'<meta name="robots" content="noindex,follow">',
54
-	'<style type="text/css">
48
+    '<!DOCTYPE html>',
49
+    '<html ', I18N::htmlAttributes(), '>',
50
+    '<head>',
51
+    '<meta charset="UTF-8">',
52
+    '<title>', WT_WEBTREES, '</title>',
53
+    '<meta name="robots" content="noindex,follow">',
54
+    '<style type="text/css">
55 55
 		body {color: gray; background-color: white; font: 14px tahoma, arial, helvetica, sans-serif; padding:10px; }
56 56
 		a {color: #81A9CB; font-weight: bold; text-decoration: none;}
57 57
 		a:hover {text-decoration: underline;}
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 		.content { /*margin:auto; width:800px;*/ border:1px solid gray; padding:15px; border-radius:15px;}
62 62
 		.good {color: green;}
63 63
 	</style>',
64
-	'</head><body>',
65
-	'<h1>', I18N::translate('This website is temporarily unavailable'), '</h1>',
66
-	'<div class="content"><p>';
64
+    '</head><body>',
65
+    '<h1>', I18N::translate('This website is temporarily unavailable'), '</h1>',
66
+    '<div class="content"><p>';
67 67
 
68 68
 if ($offline_txt) {
69
-	echo $offline_txt;
69
+    echo $offline_txt;
70 70
 } else {
71
-	echo I18N::translate('This website is down for maintenance. You should <a href="index.php">try again</a> in a few minutes.');
71
+    echo I18N::translate('This website is down for maintenance. You should <a href="index.php">try again</a> in a few minutes.');
72 72
 }
73 73
 echo '</p>';
74 74
 echo '</div>';
Please login to merge, or discard this patch.