Skip to content

Commit

Permalink
Merge pull request #5 from fisharebest/main
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
FrankWarius authored Dec 21, 2022
2 parents ba5ca5f + 3a3594e commit 6bd4818
Show file tree
Hide file tree
Showing 23 changed files with 577 additions and 543 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-version: ['8.0', '8.1', '8.2']
php-version: ['8.1', '8.2']

steps:
- uses: shivammathur/setup-php@master
Expand Down
9 changes: 6 additions & 3 deletions app/Elements/MultimediaFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

namespace Fisharebest\Webtrees\Elements;

use Fisharebest\Webtrees\Services\MediaFileService;

use function strtoupper;

/**
Expand All @@ -33,6 +31,11 @@
*/
class MultimediaFormat extends AbstractElement
{
protected const EXTENSION_TO_FORM = [
'JPEG' => 'JPG',
'TIFF' => 'TIF',
];

protected const SUBTAGS = [
'TYPE' => '0:1',
];
Expand All @@ -48,6 +51,6 @@ public function canonical(string $value): string
{
$value = strtoupper(parent::canonical($value));

return MediaFileService::EXTENSION_TO_FORM[$value] ?? $value;
return static::EXTENSION_TO_FORM[$value] ?? $value;
}
}
1 change: 1 addition & 0 deletions app/Http/Middleware/BadBotBlocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class BadBotBlocker implements MiddlewareInterface
'Barkrowler',
'BLEXBot',
'DataForSEO',
'DataForSeoBot', // https://dataforseo.com/dataforseo-bot
'DotBot',
'Grapeshot',
'Honolulu-bot', // Aggressive crawer, no info available
Expand Down
3 changes: 3 additions & 0 deletions app/Http/RequestHandlers/AddMediaFileAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$title = Validator::parsedBody($request)->string('title');
$type = Validator::parsedBody($request)->string('type');

$type = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->canonical($type);
$title = Registry::elementFactory()->make('OBJE:FILE:TITL')->canonical($title);

$file = $this->media_file_service->uploadFile($request);

if ($file === '') {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/RequestHandlers/ChangeFamilyMembersAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface

$HUSB = Validator::parsedBody($request)->isXref()->string('HUSB', '');
$WIFE = Validator::parsedBody($request)->isXref()->string('WIFE', '');
$CHIL = Validator::parsedBody($request)->isXref()->array('CHIL');
$CHIL = Validator::parsedBody($request)->array('CHIL');

// Current family members
$old_father = $family->husband();
Expand Down
7 changes: 4 additions & 3 deletions app/Http/RequestHandlers/CreateLocationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ class CreateLocationAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$name = Validator::parsedBody($request)->string('name');
$name = Validator::parsedBody($request)->isNotEmpty()->string('name');

$gedcom = "0 @@ _LOC\n1 NAME " . $name;
$name = Registry::elementFactory()->make('_LOC:NAME')->canonical($name);

$gedcom = "0 @@ _LOC\n1 NAME " . strtr($name, ["\n" => "\n2 CONT "]);

$record = $tree->createRecord($gedcom);
$record = Registry::locationFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// value and text are for autocomplete
// html is for interactive modals
Expand Down
10 changes: 7 additions & 3 deletions app/Http/RequestHandlers/CreateMediaObjectAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$note = Validator::parsedBody($request)->string('media-note');
$title = Validator::parsedBody($request)->string('title');
$type = Validator::parsedBody($request)->string('type');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');
$restriction = Validator::parsedBody($request)->string('restriction');

$note = Registry::elementFactory()->make('OBJE:NOTE')->canonical($note);
$type = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->canonical($type);
$title = Registry::elementFactory()->make('OBJE:FILE:TITL')->canonical($title);
$restriction = Registry::elementFactory()->make('OBJE:RESN')->canonical($restriction);

$file = $this->media_file_service->uploadFile($request);

Expand All @@ -76,11 +81,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$gedcom = "0 @@ OBJE\n" . $this->media_file_service->createMediaFileGedcom($file, $type, $title, $note);

if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
$gedcom .= "\n1 RESN " . strtr($restriction, ["\n" => "\n2 CONT "]);
}

$record = $tree->createMediaObject($gedcom);
$record = Registry::mediaFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// Accept the new record to keep the filesystem synchronized with the genealogy.
$this->pending_changes_service->acceptRecord($record);
Expand Down
22 changes: 14 additions & 8 deletions app/Http/RequestHandlers/CreateMediaObjectFromFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Fisharebest\Webtrees\Http\RequestHandlers;

use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\MediaFileService;
use Fisharebest\Webtrees\Services\PendingChangesService;
use Fisharebest\Webtrees\Validator;
Expand Down Expand Up @@ -54,19 +55,24 @@ public function __construct(MediaFileService $media_file_service, PendingChanges
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$file = Validator::parsedBody($request)->string('file');
$type = Validator::parsedBody($request)->string('type');
$title = Validator::parsedBody($request)->string('title');
$note = Validator::parsedBody($request)->string('note');
$tree = Validator::attributes($request)->tree();
$file = Validator::parsedBody($request)->string('file');
$type = Validator::parsedBody($request)->string('type');
$title = Validator::parsedBody($request)->string('title');
$note = Validator::parsedBody($request)->string('note');

$file = Registry::elementFactory()->make('OBJE:FILE')->canonical($file);
$note = Registry::elementFactory()->make('OBJE:NOTE')->canonical($note);
$type = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->canonical($type);
$title = Registry::elementFactory()->make('OBJE:FILE:TITL')->canonical($title);

$gedcom = "0 @@ OBJE\n" . $this->media_file_service->createMediaFileGedcom($file, $type, $title, $note);

$media_object = $tree->createRecord($gedcom);
$record = $tree->createRecord($gedcom);

// Accept the new record. Rejecting it would leave the filesystem out-of-sync with the genealogy
$this->pending_changes_service->acceptRecord($media_object);
$this->pending_changes_service->acceptRecord($record);

return redirect($media_object->url());
return redirect($record->url());
}
}
13 changes: 6 additions & 7 deletions app/Http/RequestHandlers/CreateNoteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ class CreateNoteAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$note = Validator::parsedBody($request)->string('note');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');
$note = Validator::parsedBody($request)->isNotEmpty()->string('note');
$restriction = Validator::parsedBody($request)->string('restriction');

// Convert HTML line endings to GEDCOM continuations
$note = strtr($note, ["\r\n" => "\n1 CONT "]);
$note = Registry::elementFactory()->make('NOTE:CONT')->canonical($note);
$restriction = Registry::elementFactory()->make('NOTE:RESN')->canonical($restriction);

$gedcom = '0 @@ NOTE ' . $note;
$gedcom = '0 @@ NOTE ' . strtr($note, ["\n" => "\n1 CONT "]);

if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
$gedcom .= "\n1 RESN " . strtr($restriction, ["\n" => "\n2 CONT "]);
}

$record = $tree->createRecord($gedcom);
$record = Registry::noteFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// value and text are for autocomplete
// html is for interactive modals
Expand Down
21 changes: 10 additions & 11 deletions app/Http/RequestHandlers/CreateRepositoryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function preg_replace;
use function response;
use function trim;
use function view;

/**
Expand All @@ -44,30 +42,31 @@ class CreateRepositoryAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$name = Validator::parsedBody($request)->string('name');
$name = Validator::parsedBody($request)->isNotEmpty()->string('name');
$address = Validator::parsedBody($request)->string('address');
$url = Validator::parsedBody($request)->string('url');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');
$restriction = Validator::parsedBody($request)->string('restriction');

// Fix non-printing characters
$name = trim(preg_replace('/\s+/', ' ', $name));
$name = Registry::elementFactory()->make('REPO:NAME')->canonical($name);
$address = Registry::elementFactory()->make('REPO:ADDR')->canonical($address);
$url = Registry::elementFactory()->make('REPO:WWW')->canonical($url);
$restriction = Registry::elementFactory()->make('REPO:RESN')->canonical($restriction);

$gedcom = "0 @@ REPO\n1 NAME " . $name;
$gedcom = "0 @@ REPO\n1 NAME " . strtr($name, ["\n" => "\n2 CONT "]);

if ($address !== '') {
$gedcom .= "\n1 ADDR " . strtr($address, ["\r\n" => "\n2 CONT "]);
$gedcom .= "\n1 ADDR " . strtr($address, ["\n" => "\n2 CONT "]);
}

if ($url !== '') {
$gedcom .= "\n1 WWW " . $url;
$gedcom .= "\n1 WWW " . strtr($url, ["\n" => "\n2 CONT "]);
}

if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
$gedcom .= "\n1 RESN " . strtr($restriction, ["\n" => "\n2 CONT "]);
}

$record = $tree->createRecord($gedcom);
$record = Registry::repositoryFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// value and text are for autocomplete
// html is for interactive modals
Expand Down
39 changes: 18 additions & 21 deletions app/Http/RequestHandlers/CreateSourceAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,58 +39,55 @@ class CreateSourceAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$title = Validator::parsedBody($request)->string('source-title');
$title = Validator::parsedBody($request)->isNotEmpty()->string('source-title');
$abbreviation = Validator::parsedBody($request)->string('source-abbreviation');
$author = Validator::parsedBody($request)->string('source-author');
$publication = Validator::parsedBody($request)->string('source-publication');
$repository = Validator::parsedBody($request)->string('source-repository');
$repository = Validator::parsedBody($request)->isXref()->string('source-repository', '');
$call_number = Validator::parsedBody($request)->string('source-call-number');
$text = Validator::parsedBody($request)->string('source-text');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');
$restriction = Validator::parsedBody($request)->string('restriction');

// Fix non-printing characters
$title = trim(preg_replace('/\s+/', ' ', $title));
$abbreviation = trim(preg_replace('/\s+/', ' ', $abbreviation));
$author = trim(preg_replace('/\s+/', ' ', $author));
$publication = trim(preg_replace('/\s+/', ' ', $publication));
$repository = trim(preg_replace('/\s+/', ' ', $repository));
$call_number = trim(preg_replace('/\s+/', ' ', $call_number));
$title = Registry::elementFactory()->make('SOUR:TITL')->canonical($title);
$abbreviation = Registry::elementFactory()->make('SOUR:ABBR')->canonical($abbreviation);
$author = Registry::elementFactory()->make('SOUR:AUTH')->canonical($author);
$publication = Registry::elementFactory()->make('SOUR:PUBL')->canonical($publication);
$repository = Registry::elementFactory()->make('SOUR:REPO')->canonical($repository);
$call_number = Registry::elementFactory()->make('SOUR:REPO:CALN')->canonical($call_number);
$text = Registry::elementFactory()->make('SOUR:TEXT')->canonical($text);
$restriction = Registry::elementFactory()->make('SOUR:RESN')->canonical($restriction);

// Convert HTML line endings to GEDCOM continuations
$text = strtr($text, ["\r\n" => "\n2 CONT "]);

$gedcom = "0 @@ SOUR\n\n1 TITL " . $title;
$gedcom = "0 @@ SOUR\n1 TITL " . strtr($title, ["\n" => "\n2 CONT "]);

if ($abbreviation !== '') {
$gedcom .= "\n1 ABBR " . $abbreviation;
$gedcom .= "\n1 ABBR " . strtr($abbreviation, ["\n" => "\n2 CONT "]);
}

if ($author !== '') {
$gedcom .= "\n1 AUTH " . $author;
$gedcom .= "\n1 AUTH " . strtr($author, ["\n" => "\n2 CONT "]);
}

if ($publication !== '') {
$gedcom .= "\n1 PUBL " . $publication;
$gedcom .= "\n1 PUBL " . strtr($publication, ["\n" => "\n2 CONT "]);
}

if ($text !== '') {
$gedcom .= "\n1 TEXT " . $text;
$gedcom .= "\n1 TEXT " . strtr($text, ["\n" => "\n2 CONT "]);
}

if ($repository !== '') {
$gedcom .= "\n1 REPO @" . $repository . '@';

if ($call_number !== '') {
$gedcom .= "\n2 CALN " . $call_number;
$gedcom .= "\n2 CALN " . strtr($call_number, ["\n" => "\n3 CONT "]);
}
}

if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
$gedcom .= "\n1 RESN " . strtr($restriction, ["\n" => "\n2 CONT "]);
}

$record = $tree->createRecord($gedcom);
$record = Registry::sourceFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// value and text are for autocomplete
// html is for interactive modals
Expand Down
5 changes: 3 additions & 2 deletions app/Http/RequestHandlers/CreateSubmissionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ class CreateSubmissionAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$submitter = Validator::parsedBody($request)->string('submitter');
$submitter = Validator::parsedBody($request)->isXref()->string('submitter');

$submitter = Registry::elementFactory()->make('SUBN:SUBM')->canonical($submitter);

$gedcom = "0 @@ SUBN\n1 SUBM @" . $submitter . '@';

$record = $tree->createRecord($gedcom);
$record = Registry::submissionFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// value and text are for autocomplete
// html is for interactive modals
Expand Down
22 changes: 12 additions & 10 deletions app/Http/RequestHandlers/CreateSubmitterAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,37 @@ class CreateSubmitterAction implements RequestHandlerInterface
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$name = Validator::parsedBody($request)->string('submitter_name');
$name = Validator::parsedBody($request)->isNotEmpty()->string('submitter_name');
$address = Validator::parsedBody($request)->string('submitter_address');
$email = Validator::parsedBody($request)->string('submitter_email');
$phone = Validator::parsedBody($request)->string('submitter_phone');
$restriction = Validator::parsedBody($request)->isInArray(['', 'NONE', 'PRIVACY', 'CONFIDENTIAL', 'LOCKED'])->string('restriction');
$restriction = Validator::parsedBody($request)->string('restriction');

// Fix non-printing characters
$name = trim(preg_replace('/\s+/', ' ', $name));
$name = Registry::elementFactory()->make('SUBM:NAME')->canonical($name);
$address = Registry::elementFactory()->make('SUBM:ADDR')->canonical($address);
$email = Registry::elementFactory()->make('SUBM:EMAIL')->canonical($email);
$phone = Registry::elementFactory()->make('SUBM:PHON')->canonical($phone);
$restriction = Registry::elementFactory()->make('SUBM:RESN')->canonical($restriction);

$gedcom = "0 @@ SUBM\n1 NAME " . $name;
$gedcom = "0 @@ SUBM\n1 NAME " . strtr($name, ["\n" => "\n2 CONT "]);

if ($address !== '') {
$gedcom .= "\n1 ADDR " . $address;
$gedcom .= "\n1 ADDR " . strtr($address, ["\n" => "\n2 CONT "]);
}

if ($email !== '') {
$gedcom .= "\n1 EMAIL " . $email;
$gedcom .= "\n1 EMAIL " . strtr($email, ["\n" => "\n2 CONT "]);
}

if ($phone !== '') {
$gedcom .= "\n1 PHON " . $phone;
$gedcom .= "\n1 PHON " . strtr($phone, ["\n" => "\n2 CONT "]);
}

if ($restriction !== '') {
$gedcom .= "\n1 RESN " . $restriction;
$gedcom .= "\n1 RESN " . strtr($restriction, ["\n" => "\n2 CONT "]);
}

$record = $tree->createRecord($gedcom);
$record = Registry::submitterFactory()->new($record->xref(), $record->gedcom(), null, $tree);

// value and text are for autocomplete
// html is for interactive modals
Expand Down
5 changes: 2 additions & 3 deletions app/Http/RequestHandlers/EditMediaFileAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$media = Registry::mediaFactory()->make($xref, $tree);
$media = Auth::checkMediaAccess($media, true);

// Tidy non-printing characters
$type = trim(preg_replace('/\s+/', ' ', $type));
$title = trim(preg_replace('/\s+/', ' ', $title));
$type = Registry::elementFactory()->make('OBJE:FILE:FORM:TYPE')->canonical($type);
$title = Registry::elementFactory()->make('OBJE:FILE:TITL')->canonical($title);

// Find the fact to edit
$media_file = $media->mediaFiles()
Expand Down
Loading

0 comments on commit 6bd4818

Please sign in to comment.