diff options
Diffstat (limited to 'app/Functions/FunctionsPrintFacts.php')
| -rw-r--r-- | app/Functions/FunctionsPrintFacts.php | 227 |
1 files changed, 49 insertions, 178 deletions
diff --git a/app/Functions/FunctionsPrintFacts.php b/app/Functions/FunctionsPrintFacts.php index d278ec0881..fb238b41f9 100644 --- a/app/Functions/FunctionsPrintFacts.php +++ b/app/Functions/FunctionsPrintFacts.php @@ -21,12 +21,11 @@ namespace Fisharebest\Webtrees\Functions; use Fisharebest\Webtrees\Age; use Fisharebest\Webtrees\Auth; -use Fisharebest\Webtrees\Contracts\UserInterface; -use Fisharebest\Webtrees\Date; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\Gedcom; +use Fisharebest\Webtrees\Elements\UnknownElement; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\Http\RequestHandlers\EditFactPage; @@ -38,11 +37,7 @@ use Fisharebest\Webtrees\Module\ModuleInterface; use Fisharebest\Webtrees\Module\RelationshipsChartModule; use Fisharebest\Webtrees\Note; use Fisharebest\Webtrees\Registry; -use Fisharebest\Webtrees\Repository; use Fisharebest\Webtrees\Services\ModuleService; -use Fisharebest\Webtrees\Services\UserService; -use Fisharebest\Webtrees\Submission; -use Fisharebest\Webtrees\Submitter; use Fisharebest\Webtrees\Tree; use Ramsey\Uuid\Uuid; @@ -57,10 +52,8 @@ use function ob_start; use function preg_match; use function preg_match_all; use function preg_replace; -use function preg_split; use function route; use function str_contains; -use function str_replace; use function strip_tags; use function strlen; use function strpos; @@ -130,8 +123,7 @@ class FunctionsPrintFacts // These links were once used internally to record the sort order. return; default: - // Hide unrecognized/custom tags? - if ($hide_errors && !GedcomTag::isTag($tag)) { + if ($element instanceof UnknownElement && $hide_errors) { return; } break; @@ -201,85 +193,9 @@ class FunctionsPrintFacts } // Print the value of this fact/event - switch ($tag) { - case 'ADDR': - case 'AFN': - case 'LANG': - case 'PUBL': - case 'RESN': - echo '<div class="field">' . $element->value($value, $tree) . '</div>'; - break; - case 'ASSO': - // we handle this later, in format_asso_rela_record() - break; - case 'EMAIL': - case 'EMAI': - case '_EMAIL': - echo '<div class="field"><a href="mailto:', e($value), '">', e($value), '</a></div>'; - break; - case 'REPO': - $repository = $fact->target(); - if ($repository instanceof Repository) { - echo '<div><a class="field" href="', e($repository->url()), '">', $repository->fullName(), '</a></div>'; - } else { - echo '<div class="error">', e($value), '</div>'; - } - break; - case 'SUBM': - $submitter = $fact->target(); - if ($submitter instanceof Submitter) { - echo '<div><a class="field" href="', e($submitter->url()), '">', $submitter->fullName(), '</a></div>'; - } else { - echo '<div class="error">', e($value), '</div>'; - } - break; - case 'SUBN': - $submission = $fact->target(); - if ($submission instanceof Submission) { - echo '<div><a class="field" href="', e($submission->url()), '">', $submission->fullName(), '</a></div>'; - } else { - echo '<div class="error">', e($value), '</div>'; - } - break; - case 'URL': - case '_URL': - case 'WWW': - echo '<div class="field"><a href="', e($value), '">', e($value), '</a></div>'; - break; - case 'TEXT': // 0 SOUR / 1 TEXT - echo Filter::formatText($value, $tree); - break; - case '_GOV': - echo '<div class="field"><a href="https://gov.genealogy.net/item/show/', e($value), '">', e($value), '</a></div>'; - break; - default: - // Display the value for all other facts/events - switch ($value) { - case '': - case 'CLOSE_RELATIVE': - // Nothing to display - break; - case 'N': - // Not valid GEDCOM - echo '<div class="field">', I18N::translate('No'), '</div>'; - break; - case 'Y': - echo '<div class="field">', I18N::translate('Yes'), '</div>'; - break; - default: - if (preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $value, $match)) { - $target = $fact->target(); - if ($target instanceof GedcomRecord) { - echo '<div><a href="', e($target->url()), '">', $target->fullName(), '</a></div>'; - } else { - echo '<div class="error">', e($value), '</div>'; - } - } else { - echo '<div class="field"><span dir="auto">', e($value), '</span></div>'; - } - break; - } - break; + // we handle ASSO later, in format_asso_rela_record() + if ($tag !== 'ASSO') { + echo '<div class="field">', $element->value($value, $tree), '</div>'; } // Print the type of this fact/event @@ -313,14 +229,10 @@ class FunctionsPrintFacts } // Print any other "2 XXXX" attributes, in the order in which they appear. - preg_match_all('/\n2 (' . Gedcom::REGEX_TAG . ') (.+)/', $fact->gedcom(), $matches, PREG_SET_ORDER); - - //0 SOUR / 1 DATA / 2 EVEN / 3 DATE and 3 PLAC must be collected separately - preg_match_all('/\n2 EVEN .*((\n[3].*)*)/', $fact->gedcom(), $evenMatches, PREG_SET_ORDER); - $currentEvenMatch = 0; + preg_match_all('/\n2 (' . Gedcom::REGEX_TAG . ') ?(.*)((\n[3-9].*)*)/', $fact->gedcom(), $l2_matches, PREG_SET_ORDER); - foreach ($matches as $match) { - switch ($match[1]) { + foreach ($l2_matches as $l2_match) { + switch ($l2_match[1]) { case 'DATE': case 'TIME': case 'AGE': @@ -343,93 +255,52 @@ class FunctionsPrintFacts case 'SOUR': // These will be shown at the end break; - case '_UID': - case 'RIN': - // These don't belong at level 2, so do not display them. - // They are only shown when editing. - break; - case 'EVEN': // 0 SOUR / 1 DATA / 2 EVEN / 3 DATE / 3 PLAC - $events = []; - foreach (preg_split('/ *, */', $match[2]) as $event) { - $events[] = GedcomTag::getLabel($event); - } - echo GedcomTag::getLabelValue('EVEN', implode(I18N::$list_separator, $events)); + default: + $subtag = $record::RECORD_TYPE . ':' . $tag . ':' . $l2_match[1]; + $element = Registry::elementFactory()->make($subtag); - if (preg_match('/\n3 DATE (.+)/', $evenMatches[$currentEvenMatch][0], $date_match)) { - $date = new Date($date_match[1]); - echo GedcomTag::getLabelValue('DATE', $date->display()); - } - if (preg_match('/\n3 PLAC (.+)/', $evenMatches[$currentEvenMatch][0], $plac_match)) { - echo GedcomTag::getLabelValue('PLAC', $plac_match[1]); + if ($element instanceof UnknownElement && $hide_errors) { + break; } - $currentEvenMatch++; - break; - case 'FAMC': // 0 INDI / 1 ADOP / 2 FAMC / 3 ADOP - $family = Registry::familyFactory()->make(str_replace('@', '', $match[2]), $tree); - if ($family instanceof Family) { - echo GedcomTag::getLabelValue('FAM', '<a href="' . e($family->url()) . '">' . $family->fullName() . '</a>'); - if (preg_match('/\n3 ADOP (HUSB|WIFE|BOTH)/', $fact->gedcom(), $adop_match)) { - echo Registry::elementFactory()->make('INDI:ADOP:FAMC:ADOP')->labelValue($adop_match[1], $tree); - } - } else { - echo GedcomTag::getLabelValue('FAM', '<span class="error">' . $match[2] . '</span>'); - } - break; - case '_WT_USER': - if (Auth::check()) { - $user = (new UserService())->findByIdentifier($match[2]); // may not exist - if ($user instanceof UserInterface) { - echo GedcomTag::getLabelValue('_WT_USER', '<span dir="auto">' . e($user->realName()) . '</span>'); - } else { - echo GedcomTag::getLabelValue('_WT_USER', e($match[2])); + echo $element->labelValue($l2_match[2], $tree); + + preg_match_all('/\n3 (' . Gedcom::REGEX_TAG . ') ?(.*)((\n[4-9].*)*)/', $l2_match[3], $l3_matches, PREG_SET_ORDER); + + foreach ($l3_matches as $l3_match) { + $subsubtag = $subtag . ':' . $l3_match[1]; + $element = Registry::elementFactory()->make($subsubtag); + + if ($element instanceof UnknownElement && $hide_errors) { + continue; } - } - break; - case 'RESN': - switch ($match[2]) { - case 'none': - // Note: "2 RESN none" is not valid gedcom. - // However, webtrees privacy rules will interpret it as "show an otherwise private fact to public". - echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-none"></i> ' . I18N::translate('Show to visitors')); - break; - case 'privacy': - echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-privacy"></i> ' . I18N::translate('Show to members')); - break; - case 'confidential': - echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-confidential"></i> ' . I18N::translate('Show to managers')); - break; - case 'locked': - echo GedcomTag::getLabelValue('RESN', '<i class="icon-resn-locked"></i> ' . I18N::translate('Only managers can edit')); - break; - default: - echo GedcomTag::getLabelValue('RESN', e($match[2])); - break; - } - break; - case 'CALN': - echo GedcomTag::getLabelValue('CALN', Filter::expandUrls($match[2], $tree)); - break; - case 'URL': - case '_URL': - case 'WWW': - $link = '<a href="' . e($match[2]) . '">' . e($match[2]) . '</a>'; - echo GedcomTag::getLabelValue($tag . ':' . $match[1], $link); - break; - default: - if (!$hide_errors || GedcomTag::isTag($match[1])) { - if (preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $match[2], $xmatch)) { - // Links - $linked_record = Registry::gedcomRecordFactory()->make($xmatch[1], $tree); - if ($linked_record) { - $link = '<a href="' . e($linked_record->url()) . '">' . $linked_record->fullName() . '</a>'; - echo GedcomTag::getLabelValue($tag . ':' . $match[1], $link); - } else { - echo GedcomTag::getLabelValue($tag . ':' . $match[1], e($match[2])); + + echo $element->labelValue($l3_match[2], $tree); + + preg_match_all('/\n4 (' . Gedcom::REGEX_TAG . ') ?(.*)((\n[5-9].*)*)/', $l3_match[3], $l4_matches, PREG_SET_ORDER); + + foreach ($l4_matches as $l4_match) { + $subsubsubtag = $subsubtag . ':' . $l4_match[1]; + $element = Registry::elementFactory()->make($subsubsubtag); + + if ($element instanceof UnknownElement && $hide_errors) { + continue; + } + + echo $element->labelValue($l4_match[2], $tree); + + preg_match_all('/\n5 (' . Gedcom::REGEX_TAG . ') ?(.*)((\n[6-9].*)*)/', $l4_match[3], $l5_matches, PREG_SET_ORDER); + + foreach ($l5_matches as $l5_match) { + $subsubsubsubtag = $subsubsubtag . ':' . $l5_match[1]; + $element = Registry::elementFactory()->make($subsubsubsubtag); + + if ($element instanceof UnknownElement && $hide_errors) { + continue; + } + + echo $element->labelValue($l5_match[2], $tree); } - } else { - // Non links - echo GedcomTag::getLabelValue($tag . ':' . $match[1], e($match[2])); } } break; |
