-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfact-gedcom-fields.phtml
130 lines (107 loc) · 5.47 KB
/
fact-gedcom-fields.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types=1);
namespace Jefferson49\Webtrees\Module\RepositoryHierarchyNamespace;
use Cissee\WebtreesExt\MoreI18N;
use Fisharebest\Webtrees\Elements\AbstractXrefElement;
use Fisharebest\Webtrees\Elements\XrefSource;
use Fisharebest\Webtrees\Gedcom;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Tree;
/**
* @var string $gedcom
* @var string $parent e.g. "INDI:BIRT:DATE"
* @var Tree $tree
*/
$module_service = new ModuleService();
$repository_hierarchy = $module_service->findByName(RepositoryHierarchy::activeModuleName());
$showSourceCitationIcon = false;
//If copy source citation icon shall be shown, check if individual or family view and wether editable
if (boolval($repository_hierarchy->getPreference(RepositoryHierarchy::PREF_ENABLE_COPY_PASTE_CITATIONS, '0'))) {
if ((Session::get('last_page_name') === "individual.php") && Session::has('last_page_parameter')){
$individual = Registry::individualFactory()->make(Session::get('last_page_parameter'), $tree);
$showSourceCitationIcon = $individual->canEdit();
}
elseif ((Session::get('last_page_name') === "family.php") && Session::has('last_page_parameter')){
$family = Registry::familyFactory()->make(Session::get('last_page_parameter'), $tree);
$showSourceCitationIcon = $family->canEdit();
}
}
$hierarchy = explode(':', $parent);
// Merge CONT records onto their parent line.
$gedcom_with_cont = $gedcom;
$gedcom = preg_replace('/\n\d CONT ?/', "\r", $gedcom);
preg_match_all('/^(\d+) (\w+) ?(.*)/m', $gedcom, $matches);
[, $levels, $tags, $values] = $matches;
$levels = array_map(static fn (string $x): int => (int) $x, $levels);
$keys = array_keys($levels);
$elements = [];
$private_level = PHP_INT_MAX;
foreach ($keys as $key) {
$hierarchy[$levels[$key]] = $tags[$key];
$full_tag = implode(':', array_slice($hierarchy, 0, 1 + $levels[$key]));
$elements[$key] = Registry::elementFactory()->make($full_tag);
if ($elements[$key] instanceof AbstractXrefElement && preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $values[$key], $match) === 1) {
$record = Registry::gedcomRecordFactory()->make($match[1], $tree);
if ($record instanceof GedcomRecord && !$record->canShow()) {
$private_level = min($private_level, $levels[$key]);
}
}
if ($levels[$key] >= $private_level) {
$values[$key] = '';
} else {
$private_level = PHP_INT_MAX;
}
}
?>
<?php if ($elements[0] instanceof XrefSource && preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $values[0], $match) === 1) : ?>
<?php $source = Registry::sourceFactory()->make($match[1], $tree) ?>
<?php if ($source instanceof Source) : ?>
<?php $id = Registry::idFactory()->id() ?>
<?php $expanded = $tree->getPreference('EXPAND_SOURCES') === '1' ?>
<div>
<button type="button" class="btn btn-text p-0" href="#<?= e($id) ?>" data-bs-toggle="collapse" aria-controls="<?= e($id) ?>" aria-expanded="<?= $expanded ? 'true' : 'false' ?>">
<?= view('icons/expand') ?>
<?= view('icons/collapse') ?>
</button>
<?php $label = '<span class="label">' . MoreI18N::xlate('Source') . '</span>' ?>
<?php $value = '<span class="field" dir="auto"><a href="' . e($source->url()) . '">' . $source->fullName() . '</a></span>' ?>
<?= MoreI18N::xlate('%1$s: %2$s', $label, $value) ?>
<?php //Additionally show icon to copy source citation?>
<?php if ($showSourceCitationIcon) : ?>
<?= view(RepositoryHierarchy::viewsNamespace() . '::edit/icon-source-citation-copy', ['tree' => $tree, 'gedcom' => $gedcom_with_cont,]) ?>
<?php endif ?>
</div>
<div id="<?= e($id) ?>" class="ps-4 collapse <?= $expanded ? 'show' : '' ?>">
<?php //Additionally show source facts within citations?>
<?= view(RepositoryHierarchy::viewsNamespace() . '::source-facts-within-citation', ['tree' => $tree, 'source' => $source]) ?>
<?php array_shift($keys) ?>
<?php foreach ($keys as $key) : ?>
<?php if ( ($values[$key] !== '') &&
!((get_class($elements[$key]) === 'Fisharebest\Webtrees\Elements\XrefMedia') && (boolval($repository_hierarchy->getPreference(RepositoryHierarchy::PREF_SHOW_MEDIA_AFTER_CITATIONS, '0'))))
) : ?>
<?= $elements[$key]->labelValue(strtr($values[$key], ["\r" => "\n"]), $tree) ?>
<?php endif ?>
<?php endforeach ?>
</div>
<?php //Additionally show media objects after source citation?>
<?php if (boolval($repository_hierarchy->getPreference(RepositoryHierarchy::PREF_SHOW_MEDIA_AFTER_CITATIONS, '0'))) : ?>
<?php foreach ($keys as $key) : ?>
<?php if ($values[$key] !== '') : ?>
<?php if (get_class($elements[$key]) === 'Fisharebest\Webtrees\Elements\XrefMedia') : ?>
<?= $elements[$key]->labelValue(strtr($values[$key], ["\r" => "\n"]), $tree) ?>
<?php endif ?>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endif ?>
<?php else : ?>
<?php foreach ($keys as $key) : ?>
<?php if ($values[$key] !== '') : ?>
<?= $elements[$key]->labelValue(strtr($values[$key], ["\r" => "\n"]), $tree) ?>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>