|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees: online genealogy |
|
5
|
|
|
* Copyright (C) 2025 webtrees development team |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Elements; |
|
21
|
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\Date; |
|
23
|
|
|
use Fisharebest\Webtrees\Html; |
|
24
|
|
|
use Fisharebest\Webtrees\I18N; |
|
|
|
|
|
|
25
|
|
|
use Fisharebest\Webtrees\Tree; |
|
26
|
|
|
|
|
27
|
|
|
use function e; |
|
28
|
|
|
use function preg_replace_callback; |
|
29
|
|
|
use function view; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* DATE_VALUE := {Size=1:35} |
|
33
|
|
|
* [ <DATE> | <DATE_PERIOD> | <DATE_RANGE>| <DATE_APPROXIMATED> | INT <DATE> (<DATE_PHRASE>) | (<DATE_PHRASE>) ] |
|
34
|
|
|
* The DATE_VALUE represents the date of an activity, attribute, or event where: |
|
35
|
|
|
* INT = Interpreted from knowledge about the associated date phrase included in parentheses. |
|
36
|
|
|
* An acceptable alternative to the date phrase choice is to use one of the other choices such as |
|
37
|
|
|
* <DATE_APPROXIMATED> choice as the DATE line value and then include the date phrase value as a |
|
38
|
|
|
* NOTE value subordinate to the DATE line tag. |
|
39
|
|
|
* The date value can take on the date form of just a date, an approximated date, between a date |
|
40
|
|
|
* and another date, and from one date to another date. The preferred form of showing date |
|
41
|
|
|
* imprecision, is to show, for example, MAY 1890 rather than ABT 12 MAY 1890. This is because |
|
42
|
|
|
* limits have not been assigned to the precision of the prefixes such as ABT or EST. |
|
43
|
|
|
*/ |
|
44
|
|
|
class DateValue extends AbstractElement |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* An edit control for this data. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $id |
|
50
|
|
|
* @param string $name |
|
51
|
|
|
* @param string $value |
|
52
|
|
|
* @param Tree $tree |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function edit(string $id, string $name, string $value, Tree $tree): string |
|
57
|
|
|
{ |
|
58
|
|
|
// Need to know if the user prefers DMY/MDY/YMD so we can validate dates properly. |
|
59
|
|
|
$dmy = I18N::language()->dateOrder(); |
|
60
|
|
|
|
|
61
|
|
|
$attributes = [ |
|
62
|
|
|
'class' => 'form-control', |
|
63
|
|
|
'dir' => 'ltr', |
|
64
|
|
|
'type' => 'text', |
|
65
|
|
|
'id' => $id, |
|
66
|
|
|
'name' => $name, |
|
67
|
|
|
'value' => $value, |
|
68
|
|
|
'onchange' => 'webtrees.reformatDate(this, \'' . e($dmy) . '\')', |
|
69
|
|
|
'maxlength' => static::MAXIMUM_LENGTH, |
|
70
|
|
|
'pattern' => static::PATTERN, |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
return |
|
74
|
|
|
'<div class="input-group">' . |
|
75
|
|
|
'<input ' . Html::attributes($attributes) . ' />' . |
|
76
|
|
|
view('edit/input-addon-calendar', ['id' => $id]) . |
|
77
|
|
|
view('edit/input-addon-help', ['topic' => 'DATE']) . |
|
78
|
|
|
'</div>' . |
|
79
|
|
|
'<div id="caldiv' . $id . '" style="position:absolute;visibility:hidden;background-color:white;z-index:1000"></div>' . |
|
80
|
|
|
'<div class="form-text">' . (new Date($value))->display() . '</div>'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Should we collapse the children of this element when editing? |
|
85
|
|
|
* |
|
86
|
|
|
* @return bool |
|
87
|
|
|
*/ |
|
88
|
|
|
public function collapseChildren(): bool |
|
89
|
|
|
{ |
|
90
|
|
|
return true; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Escape @ signs in a GEDCOM export. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $value |
|
97
|
|
|
* |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function escape(string $value): string |
|
101
|
|
|
{ |
|
102
|
|
|
// Only escape @ signs in an INT phrase |
|
103
|
|
|
return preg_replace_callback('/\(.*@.*\)/', static fn (array $matches): string => strtr($matches[0], ['@' => '@@']), $value); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Display the value of this type of element. |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $value |
|
110
|
|
|
* @param Tree $tree |
|
111
|
|
|
* |
|
112
|
|
|
* @return string |
|
113
|
|
|
*/ |
|
114
|
|
|
public function value(string $value, Tree $tree): string |
|
115
|
|
|
{ |
|
116
|
|
|
$canonical = $this->canonical($value); |
|
117
|
|
|
|
|
118
|
|
|
$date = new Date($canonical); |
|
119
|
|
|
|
|
120
|
|
|
return $date->display(); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths