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