diff options
| author | Greg Roach <fisharebest@gmail.com> | 2021-04-07 07:51:51 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2021-04-07 07:52:14 +0100 |
| commit | 0f16bc5deb178e50ea62d90b8878d07245c81dff (patch) | |
| tree | 8a6e5f9e46ef97783bf53c9f6421a935740a824f | |
| parent | fdb2be4ea046a54bc31fa2776688ba915b0a372f (diff) | |
| download | webtrees-0f16bc5deb178e50ea62d90b8878d07245c81dff.tar.gz webtrees-0f16bc5deb178e50ea62d90b8878d07245c81dff.tar.bz2 webtrees-0f16bc5deb178e50ea62d90b8878d07245c81dff.zip | |
Add support for _FSFTID tags
| -rw-r--r-- | app/Elements/AbstractExternalLink.php | 47 | ||||
| -rw-r--r-- | app/Elements/AncestralFileNumber.php | 24 | ||||
| -rw-r--r-- | app/Elements/FamilySearchFamilyTreeId.php | 50 | ||||
| -rw-r--r-- | app/Factories/ElementFactory.php | 6 | ||||
| -rw-r--r-- | tests/app/Elements/AncestralFileNumberTest.php | 1 | ||||
| -rw-r--r-- | tests/app/Elements/FamilySearchFamilyTreeIdTest.php | 50 |
6 files changed, 156 insertions, 22 deletions
diff --git a/app/Elements/AbstractExternalLink.php b/app/Elements/AbstractExternalLink.php new file mode 100644 index 0000000000..72d36dc0e5 --- /dev/null +++ b/app/Elements/AbstractExternalLink.php @@ -0,0 +1,47 @@ +<?php + +/** + * webtrees: online genealogy + * Copyright (C) 2021 webtrees development team + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Elements; + +use Fisharebest\Webtrees\I18N; +use Fisharebest\Webtrees\Tree; + +use function e; + +/** + * Events which can take "Y" to indicate that they occurred, but date/place are unknown. + */ +class AbstractExternalLink extends AbstractElement +{ + /** + * Display the value of this type of element. + * + * @param string $value + * @param Tree $tree + * + * @return string + */ + public function value(string $value, Tree $tree): string + { + $canonical = $this->canonical($value); + $url = strtr(static::EXTERNAL_URL, ['{ID}' => rawurlencode($canonical)]); + + return '<a dir="ltr" href="' . e($url) . '" rel="nofollow">' . e($canonical) . '</a>'; + } +} diff --git a/app/Elements/AncestralFileNumber.php b/app/Elements/AncestralFileNumber.php index 0f1b077041..237e3eb561 100644 --- a/app/Elements/AncestralFileNumber.php +++ b/app/Elements/AncestralFileNumber.php @@ -19,10 +19,6 @@ declare(strict_types=1); namespace Fisharebest\Webtrees\Elements; -use Fisharebest\Webtrees\Tree; - -use function e; -use function rawurlencode; use function strtoupper; /** @@ -30,9 +26,9 @@ use function strtoupper; * A unique permanent record number of an individual record contained in the * Family History Department's Ancestral File. */ -class AncestralFileNumber extends AbstractElement +class AncestralFileNumber extends AbstractExternalLink { - protected const EXTERNAL_URL = 'https://www.familysearch.org/search/family-trees/results?q.afnId='; + protected const EXTERNAL_URL = 'https://www.familysearch.org/search/family-trees/results?q.afnId={ID}'; protected const MAXIMUM_LENGTH = 12; @@ -47,20 +43,4 @@ class AncestralFileNumber extends AbstractElement { return strtoupper(parent::canonical($value)); } - - /** - * Display the value of this type of element. - * - * @param string $value - * @param Tree $tree - * - * @return string - */ - public function value(string $value, Tree $tree): string - { - $canonical = $this->canonical($value); - $url = static::EXTERNAL_URL . rawurlencode($canonical); - - return '<a dir="ltr" href="' . e($url) . '" rel="nofollow">' . e($canonical) . '</a>'; - } } diff --git a/app/Elements/FamilySearchFamilyTreeId.php b/app/Elements/FamilySearchFamilyTreeId.php new file mode 100644 index 0000000000..7fe785d109 --- /dev/null +++ b/app/Elements/FamilySearchFamilyTreeId.php @@ -0,0 +1,50 @@ +<?php + +/** + * webtrees: online genealogy + * Copyright (C) 2021 webtrees development team + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Elements; + +use Fisharebest\Webtrees\Tree; + +use function e; +use function rawurlencode; +use function strtoupper; + +/** + * ANCESTRAL_FILE_NUMBER := {Size=1:12} + * A unique permanent record number of an individual record contained in the + * Family History Department's Ancestral File. + */ +class FamilySearchFamilyTreeId extends AbstractExternalLink +{ + protected const EXTERNAL_URL = 'https://ancestors.familysearch.org/en/{ID}'; + + protected const MAXIMUM_LENGTH = 8; + + /** + * Convert a value to a canonical form. + * + * @param string $value + * + * @return string + */ + public function canonical(string $value): string + { + return strtoupper(parent::canonical($value)); + } +} diff --git a/app/Factories/ElementFactory.php b/app/Factories/ElementFactory.php index d4ee95d964..2163a6da79 100644 --- a/app/Factories/ElementFactory.php +++ b/app/Factories/ElementFactory.php @@ -81,6 +81,7 @@ use Fisharebest\Webtrees\Elements\EventOrFactClassification; use Fisharebest\Webtrees\Elements\EventsRecorded; use Fisharebest\Webtrees\Elements\EventTypeCitedFrom; use Fisharebest\Webtrees\Elements\FamilyRecord; +use Fisharebest\Webtrees\Elements\FamilySearchFamilyTreeId; use Fisharebest\Webtrees\Elements\FamilyStatusText; use Fisharebest\Webtrees\Elements\FileName; use Fisharebest\Webtrees\Elements\FirstCommunion; @@ -797,6 +798,11 @@ class ElementFactory implements ElementFactoryInterface // 2 RELA Witness at event _EVN ## ]); + // familysearch.org extensions + $this->register([ + 'INDI:_FSFTID' => /* I18N: familysearch.org */ new FamilySearchFamilyTreeId(I18N::translate('FamilySearch ID')), + ]); + // Family Tree Builder extensions $this->register([ '*:_UPD' => new CustomElement(I18N::translate('Last change')), // e.g. "1 _UPD 14 APR 2012 00:14:10 GMT-5" diff --git a/tests/app/Elements/AncestralFileNumberTest.php b/tests/app/Elements/AncestralFileNumberTest.php index e9535fa0e6..ee05232255 100644 --- a/tests/app/Elements/AncestralFileNumberTest.php +++ b/tests/app/Elements/AncestralFileNumberTest.php @@ -23,6 +23,7 @@ namespace Fisharebest\Webtrees\Elements; * Test harness for the class AncestralFileNumber * * @covers \Fisharebest\Webtrees\Elements\AbstractElement + * @covers \Fisharebest\Webtrees\Elements\AbstractExternalLink * @covers \Fisharebest\Webtrees\Elements\AncestralFileNumber */ class AncestralFileNumberTest extends AbstractElementTest diff --git a/tests/app/Elements/FamilySearchFamilyTreeIdTest.php b/tests/app/Elements/FamilySearchFamilyTreeIdTest.php new file mode 100644 index 0000000000..5d374ffad2 --- /dev/null +++ b/tests/app/Elements/FamilySearchFamilyTreeIdTest.php @@ -0,0 +1,50 @@ +<?php + +/** + * webtrees: online genealogy + * Copyright (C) 2021 webtrees development team + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +declare(strict_types=1); + +namespace Fisharebest\Webtrees\Elements; + +/** + * Test harness for the class FamilySearchFamilyTreeId + * + * @covers \Fisharebest\Webtrees\Elements\AbstractElement + * @covers \Fisharebest\Webtrees\Elements\AbstractExternalLink + * @covers \Fisharebest\Webtrees\Elements\FamilySearchFamilyTreeId + */ +class FamilySearchFamilyTreeIdTest extends AbstractElementTest +{ + /** + * Standard tests for all elements. + */ + public static function setupBeforeClass(): void + { + parent::setUpBeforeClass(); + + self::$element = new AncestralFileNumber('label'); + } + + /** + * @return void + */ + public function testCanonical(): void + { + self::assertSame('FOO BAR BAZ', self::$element->canonical("Foo bAr baZ")); + self::assertSame('FOO BAR BAZ', self::$element->canonical("\t Foo\t bAr \tbaZ\t ")); + self::assertSame('FOO BAR BAZ', self::$element->canonical("\nFoo \n\r bAr \r\n baZ\r")); + } +} |
