1<?php 2 3use Fisharebest\Webtrees\Elements\AbstractXrefElement; 4use Fisharebest\Webtrees\Elements\XrefSource; 5use Fisharebest\Webtrees\Gedcom; 6use Fisharebest\Webtrees\GedcomRecord; 7use Fisharebest\Webtrees\I18N; 8use Fisharebest\Webtrees\Registry; 9use Fisharebest\Webtrees\Source; 10use Fisharebest\Webtrees\Tree; 11use Ramsey\Uuid\Uuid; 12 13/** 14 * @var string $gedcom 15 * @var string $parent e.g. "INDI:BIRT:DATE" 16 * @var Tree $tree 17 */ 18 19$hierarchy = explode(':', $parent); 20 21// Merge CONT records onto their parent line. 22$gedcom = preg_replace('/\n\d CONT ?/', "\r", $gedcom); 23 24preg_match_all('/^(\d+) (\w+) ?(.*)/m', $gedcom, $matches); 25[, $levels, $tags, $values] = $matches; 26$levels = array_map(static fn (string $x): int => (int) $x, $levels); 27$keys = array_keys($levels); 28$elements = []; 29 30$private_level = PHP_INT_MAX; 31 32foreach ($keys as $key) { 33 $hierarchy[$levels[$key]] = $tags[$key]; 34 $full_tag = implode(':', array_slice($hierarchy, 0, 1 + $levels[$key])); 35 $elements[$key] = Registry::elementFactory()->make($full_tag); 36 37 if ($elements[$key] instanceof AbstractXrefElement && preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $values[$key], $match) === 1) { 38 $record = Registry::gedcomRecordFactory()->make($match[1], $tree); 39 40 if ($record instanceof GedcomRecord && !$record->canShow()) { 41 $private_level = min($private_level, $levels[$key]); 42 } 43 } 44 45 if ($levels[$key] >= $private_level) { 46 $values[$key] = ''; 47 } else { 48 $private_level = PHP_INT_MAX; 49 } 50} 51 52?> 53 54<?php if ($elements[0] instanceof XrefSource && preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $values[0], $match) === 1) : ?> 55 <?php $source = Registry::sourceFactory()->make($match[1], $tree) ?> 56 <?php if ($source instanceof Source) : ?> 57 <?php $id = 'collapse-' . Uuid::uuid4()->toString() ?> 58 <?php $expanded = $tree->getPreference('EXPAND_SOURCES') === '1' ?> 59 <div class="fact_SOUR"> 60 <a href="#<?= e($id) ?>" role="button" data-bs-toggle="collapse" aria-controls="<?= e($id) ?>" aria-expanded="<?= $expanded ? 'true' : 'false' ?>"> 61 <?= view('icons/expand') ?> 62 <?= view('icons/collapse') ?> 63 </a> 64 65 <?php $label = '<span class="label">' . I18N::translate('Source') . '</span>' ?> 66 <?php $value = '<span class="field" dir="auto"><a href="' . e($source->url()) . '">' . $source->fullName() . '</a></span>' ?> 67 <?= I18N::translate('%1$s: %2$s', $label, $value) ?> 68 </div> 69 70 <div id="<?= e($id) ?>" class="ps-4 collapse <?= $expanded ? 'show' : '' ?>"> 71 <?php array_shift($keys) ?> 72 <?php foreach ($keys as $key) : ?> 73 <?php if ($values[$key] !== '') : ?> 74 <?= $elements[$key]->labelValue(strtr($values[$key], ["\r" => "\n"]), $tree) ?> 75 <?php endif ?> 76 <?php endforeach ?> 77 </div> 78 <?php endif ?> 79<?php else : ?> 80 <?php foreach ($keys as $key) : ?> 81 <?php if ($values[$key] !== '') : ?> 82 <?= $elements[$key]->labelValue(strtr($values[$key], ["\r" => "\n"]), $tree) ?> 83 <?php endif ?> 84 <?php endforeach ?> 85<?php endif ?> 86