1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees: online genealogy |
5
|
|
|
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees; |
21
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\GedcomElements\UnknownElement; |
23
|
|
|
use Ramsey\Uuid\Uuid; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Static GEDCOM data for tags |
27
|
|
|
* |
28
|
|
|
* @deprecated since 2.0.5. Will be removed in 2.1.0 - Use Factory::elementFactory() instead |
29
|
|
|
*/ |
30
|
|
|
class GedcomTag |
31
|
|
|
{ |
32
|
|
|
/** @var string[] Possible values for the Object-File-Format types */ |
33
|
|
|
private const OBJE_FILE_FORM_TYPE = [ |
34
|
|
|
'audio', |
35
|
|
|
'book', |
36
|
|
|
'card', |
37
|
|
|
'certificate', |
38
|
|
|
'coat', |
39
|
|
|
'document', |
40
|
|
|
'electronic', |
41
|
|
|
'fiche', |
42
|
|
|
'film', |
43
|
|
|
'magazine', |
44
|
|
|
'manuscript', |
45
|
|
|
'map', |
46
|
|
|
'newspaper', |
47
|
|
|
'photo', |
48
|
|
|
'tombstone', |
49
|
|
|
'video', |
50
|
|
|
'painting', |
51
|
|
|
'other', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Is $tag one of our known tags? |
56
|
|
|
* |
57
|
|
|
* @param string $tag |
58
|
|
|
* |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public static function isTag($tag): bool |
62
|
|
|
{ |
63
|
|
|
return !Registry::elementFactory()->make($tag) instanceof UnknownElement; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Translate a tag, for an (optional) record |
68
|
|
|
* |
69
|
|
|
* @param string $tag |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public static function getLabel($tag): string |
74
|
|
|
{ |
75
|
|
|
return Registry::elementFactory()->make($tag)->label(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Translate a label/value pair, such as “Occupation: Farmer” |
80
|
|
|
* |
81
|
|
|
* @param string $tag |
82
|
|
|
* @param string $value |
83
|
|
|
* @param GedcomRecord|null $record |
84
|
|
|
* @param string|null $element |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public static function getLabelValue($tag, $value, GedcomRecord $record = null, $element = 'div'): string |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
return |
91
|
|
|
'<' . $element . ' class="fact_' . $tag . '">' . |
92
|
|
|
/* I18N: a label/value pair, such as “Occupation: Farmer”. Some languages may need to change the punctuation. */ |
93
|
|
|
I18N::translate('<span class="label">%1$s:</span> <span class="field" dir="auto">%2$s</span>', self::getLabel($tag), $value) . |
94
|
|
|
'</' . $element . '>'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get a list of facts, for use in the "fact picker" edit control |
99
|
|
|
* |
100
|
|
|
* @param string $fact_type |
101
|
|
|
* |
102
|
|
|
* @return string[] |
103
|
|
|
*/ |
104
|
|
|
public static function getPicklistFacts($fact_type): array |
105
|
|
|
{ |
106
|
|
|
switch ($fact_type) { |
107
|
|
|
case Individual::RECORD_TYPE: |
108
|
|
|
$tags = [ |
109
|
|
|
// Facts, attributes for individuals (no links to FAMs) |
110
|
|
|
'RESN', |
111
|
|
|
'NAME', |
112
|
|
|
'SEX', |
113
|
|
|
'BIRT', |
114
|
|
|
'CHR', |
115
|
|
|
'DEAT', |
116
|
|
|
'BURI', |
117
|
|
|
'CREM', |
118
|
|
|
'ADOP', |
119
|
|
|
'BAPM', |
120
|
|
|
'BARM', |
121
|
|
|
'BASM', |
122
|
|
|
'BLES', |
123
|
|
|
'CHRA', |
124
|
|
|
'CONF', |
125
|
|
|
'FCOM', |
126
|
|
|
'ORDN', |
127
|
|
|
'NATU', |
128
|
|
|
'EMIG', |
129
|
|
|
'IMMI', |
130
|
|
|
'CENS', |
131
|
|
|
'PROB', |
132
|
|
|
'WILL', |
133
|
|
|
'GRAD', |
134
|
|
|
'RETI', |
135
|
|
|
'EVEN', |
136
|
|
|
'CAST', |
137
|
|
|
'DSCR', |
138
|
|
|
'EDUC', |
139
|
|
|
'IDNO', |
140
|
|
|
'NATI', |
141
|
|
|
'NCHI', |
142
|
|
|
'NMR', |
143
|
|
|
'OCCU', |
144
|
|
|
'PROP', |
145
|
|
|
'RELI', |
146
|
|
|
'RESI', |
147
|
|
|
'SSN', |
148
|
|
|
'TITL', |
149
|
|
|
'FACT', |
150
|
|
|
'BAPL', |
151
|
|
|
'CONL', |
152
|
|
|
'ENDL', |
153
|
|
|
'SLGC', |
154
|
|
|
'SUBM', |
155
|
|
|
'ASSO', |
156
|
|
|
'ALIA', |
157
|
|
|
'ANCI', |
158
|
|
|
'DESI', |
159
|
|
|
'RFN', |
160
|
|
|
'AFN', |
161
|
|
|
'REFN', |
162
|
|
|
'RIN', |
163
|
|
|
'CHAN', |
164
|
|
|
'NOTE', |
165
|
|
|
'SHARED_NOTE', |
166
|
|
|
'SOUR', |
167
|
|
|
'OBJE', |
168
|
|
|
// non standard tags |
169
|
|
|
'_BRTM', |
170
|
|
|
'_DEG', |
171
|
|
|
'_DNA', |
172
|
|
|
'_EYEC', |
173
|
|
|
'_FNRL', |
174
|
|
|
'_HAIR', |
175
|
|
|
'_HEIG', |
176
|
|
|
'_HNM', |
177
|
|
|
'_HOL', |
178
|
|
|
'_INTE', |
179
|
|
|
'_MDCL', |
180
|
|
|
'_MEDC', |
181
|
|
|
'_MILI', |
182
|
|
|
'_MILT', |
183
|
|
|
'_NAME', |
184
|
|
|
'_NAMS', |
185
|
|
|
'_NLIV', |
186
|
|
|
'_NMAR', |
187
|
|
|
'_PRMN', |
188
|
|
|
'_TODO', |
189
|
|
|
'_UID', |
190
|
|
|
'_WEIG', |
191
|
|
|
'_YART', |
192
|
|
|
]; |
193
|
|
|
break; |
194
|
|
|
|
195
|
|
|
case Family::RECORD_TYPE: |
196
|
|
|
$tags = [ |
197
|
|
|
// Facts for families, left out HUSB, WIFE & CHIL links |
198
|
|
|
'RESN', |
199
|
|
|
'ANUL', |
200
|
|
|
'CENS', |
201
|
|
|
'DIV', |
202
|
|
|
'DIVF', |
203
|
|
|
'ENGA', |
204
|
|
|
'MARB', |
205
|
|
|
'MARC', |
206
|
|
|
'MARR', |
207
|
|
|
'MARL', |
208
|
|
|
'MARS', |
209
|
|
|
'RESI', |
210
|
|
|
'EVEN', |
211
|
|
|
'NCHI', |
212
|
|
|
'SUBM', |
213
|
|
|
'SLGS', |
214
|
|
|
'REFN', |
215
|
|
|
'RIN', |
216
|
|
|
'CHAN', |
217
|
|
|
'NOTE', |
218
|
|
|
'SHARED_NOTE', |
219
|
|
|
'SOUR', |
220
|
|
|
'OBJE', |
221
|
|
|
// non standard tags |
222
|
|
|
'_NMR', |
223
|
|
|
'MARR_CIVIL', |
224
|
|
|
'MARR_RELIGIOUS', |
225
|
|
|
'MARR_PARTNERS', |
226
|
|
|
'MARR_UNKNOWN', |
227
|
|
|
'_COML', |
228
|
|
|
'_MBON', |
229
|
|
|
'_MARI', |
230
|
|
|
'_SEPR', |
231
|
|
|
'_TODO', |
232
|
|
|
]; |
233
|
|
|
break; |
234
|
|
|
|
235
|
|
|
case Source::RECORD_TYPE: |
236
|
|
|
$tags = [ |
237
|
|
|
// Facts for sources |
238
|
|
|
'DATA', |
239
|
|
|
'AUTH', |
240
|
|
|
'TITL', |
241
|
|
|
'ABBR', |
242
|
|
|
'PUBL', |
243
|
|
|
'TEXT', |
244
|
|
|
'REPO', |
245
|
|
|
'REFN', |
246
|
|
|
'RIN', |
247
|
|
|
'CHAN', |
248
|
|
|
'NOTE', |
249
|
|
|
'SHARED_NOTE', |
250
|
|
|
'OBJE', |
251
|
|
|
'RESN', |
252
|
|
|
]; |
253
|
|
|
break; |
254
|
|
|
|
255
|
|
|
case Repository::RECORD_TYPE: |
256
|
|
|
$tags = [ |
257
|
|
|
// Facts for repositories |
258
|
|
|
'NAME', |
259
|
|
|
'ADDR', |
260
|
|
|
'PHON', |
261
|
|
|
'EMAIL', |
262
|
|
|
'FAX', |
263
|
|
|
'WWW', |
264
|
|
|
'NOTE', |
265
|
|
|
'SHARED_NOTE', |
266
|
|
|
'REFN', |
267
|
|
|
'RIN', |
268
|
|
|
'CHAN', |
269
|
|
|
'RESN', |
270
|
|
|
]; |
271
|
|
|
break; |
272
|
|
|
|
273
|
|
|
case 'PLAC': |
274
|
|
|
$tags = [ |
275
|
|
|
// Facts for places |
276
|
|
|
'FONE', |
277
|
|
|
'ROMN', |
278
|
|
|
// non standard tags |
279
|
|
|
'_GOV', |
280
|
|
|
'_HEB', |
281
|
|
|
]; |
282
|
|
|
break; |
283
|
|
|
|
284
|
|
|
case 'NAME': |
285
|
|
|
$tags = [ |
286
|
|
|
// Facts subordinate to NAME |
287
|
|
|
'FONE', |
288
|
|
|
'ROMN', |
289
|
|
|
// non standard tags |
290
|
|
|
'_HEB', |
291
|
|
|
'_AKA', |
292
|
|
|
'_MARNM', |
293
|
|
|
]; |
294
|
|
|
break; |
295
|
|
|
|
296
|
|
|
default: |
297
|
|
|
$tags = []; |
298
|
|
|
break; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$facts = []; |
302
|
|
|
foreach ($tags as $tag) { |
303
|
|
|
$facts[$tag] = self::getLabel($tag); |
304
|
|
|
} |
305
|
|
|
uasort($facts, '\Fisharebest\Webtrees\I18N::strcasecmp'); |
306
|
|
|
|
307
|
|
|
return $facts; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Translate the value for 1 FILE/2 FORM/3 TYPE |
312
|
|
|
* |
313
|
|
|
* @param string $type |
314
|
|
|
* |
315
|
|
|
* @return string |
316
|
|
|
*/ |
317
|
|
|
public static function getFileFormTypeValue(string $type): string |
318
|
|
|
{ |
319
|
|
|
switch (strtolower($type)) { |
320
|
|
|
case 'audio': |
321
|
|
|
/* I18N: Type of media object */ |
322
|
|
|
return I18N::translate('Audio'); |
323
|
|
|
case 'book': |
324
|
|
|
/* I18N: Type of media object */ |
325
|
|
|
return I18N::translate('Book'); |
326
|
|
|
case 'card': |
327
|
|
|
/* I18N: Type of media object */ |
328
|
|
|
return I18N::translate('Card'); |
329
|
|
|
case 'certificate': |
330
|
|
|
/* I18N: Type of media object */ |
331
|
|
|
return I18N::translate('Certificate'); |
332
|
|
|
case 'coat': |
333
|
|
|
/* I18N: Type of media object */ |
334
|
|
|
return I18N::translate('Coat of arms'); |
335
|
|
|
case 'document': |
336
|
|
|
/* I18N: Type of media object */ |
337
|
|
|
return I18N::translate('Document'); |
338
|
|
|
case 'electronic': |
339
|
|
|
/* I18N: Type of media object */ |
340
|
|
|
return I18N::translate('Electronic'); |
341
|
|
|
case 'fiche': |
342
|
|
|
/* I18N: Type of media object */ |
343
|
|
|
return I18N::translate('Microfiche'); |
344
|
|
|
case 'film': |
345
|
|
|
/* I18N: Type of media object */ |
346
|
|
|
return I18N::translate('Microfilm'); |
347
|
|
|
case 'magazine': |
348
|
|
|
/* I18N: Type of media object */ |
349
|
|
|
return I18N::translate('Magazine'); |
350
|
|
|
case 'manuscript': |
351
|
|
|
/* I18N: Type of media object */ |
352
|
|
|
return I18N::translate('Manuscript'); |
353
|
|
|
case 'map': |
354
|
|
|
/* I18N: Type of media object */ |
355
|
|
|
return I18N::translate('Map'); |
356
|
|
|
case 'newspaper': |
357
|
|
|
/* I18N: Type of media object */ |
358
|
|
|
return I18N::translate('Newspaper'); |
359
|
|
|
case 'photo': |
360
|
|
|
/* I18N: Type of media object */ |
361
|
|
|
return I18N::translate('Photo'); |
362
|
|
|
case 'tombstone': |
363
|
|
|
/* I18N: Type of media object */ |
364
|
|
|
return I18N::translate('Tombstone'); |
365
|
|
|
case 'video': |
366
|
|
|
/* I18N: Type of media object */ |
367
|
|
|
return I18N::translate('Video'); |
368
|
|
|
case 'painting': |
369
|
|
|
/* I18N: Type of media object */ |
370
|
|
|
return I18N::translate('Painting'); |
371
|
|
|
default: |
372
|
|
|
/* I18N: Type of media object */ |
373
|
|
|
return I18N::translate('Other'); |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* A list of all possible values for 1 FILE/2 FORM/3 TYPE |
379
|
|
|
* |
380
|
|
|
* @return string[] |
381
|
|
|
*/ |
382
|
|
|
public static function getFileFormTypes(): array |
383
|
|
|
{ |
384
|
|
|
$values = array_map(static function (string $keyword): string { |
385
|
|
|
return self::getFileFormTypeValue($keyword); |
386
|
|
|
}, array_combine(self::OBJE_FILE_FORM_TYPE, self::OBJE_FILE_FORM_TYPE)); |
387
|
|
|
|
388
|
|
|
uasort($values, '\Fisharebest\Webtrees\I18N::strcasecmp'); |
389
|
|
|
|
390
|
|
|
return $values; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Generate a value for a new _UID field. |
395
|
|
|
* Instead of RFC4122-compatible UUIDs, generate ones that |
396
|
|
|
* are compatible with PAF, Legacy, RootsMagic, etc. |
397
|
|
|
* In these, the string is upper-cased, dashes are removed, |
398
|
|
|
* and a two-byte checksum is added. |
399
|
|
|
* |
400
|
|
|
* @return string |
401
|
|
|
* @deprecated - Use PafUid |
402
|
|
|
*/ |
403
|
|
|
public static function createUid(): string |
404
|
|
|
{ |
405
|
|
|
$uid = str_replace('-', '', Uuid::uuid4()->toString()); |
406
|
|
|
|
407
|
|
|
$checksum_a = 0; // a sum of the bytes |
408
|
|
|
$checksum_b = 0; // a sum of the incremental values of $checksum_a |
409
|
|
|
|
410
|
|
|
// Compute checksums |
411
|
|
|
for ($i = 0; $i < 32; $i += 2) { |
412
|
|
|
$checksum_a += hexdec(substr($uid, $i, 2)); |
413
|
|
|
$checksum_b += $checksum_a & 0xff; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
return strtoupper($uid . substr(dechex($checksum_a), -2) . substr(dechex($checksum_b), -2)); |
|
|
|
|
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.