xref: /webtrees/app/Http/RequestHandlers/HelpText.php (revision d11be7027e34e3121be11cc025421873364403f9)
12d49f7deSGreg Roach<?php
22d49f7deSGreg Roach
32d49f7deSGreg Roach/**
42d49f7deSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
62d49f7deSGreg Roach * This program is free software: you can redistribute it and/or modify
72d49f7deSGreg Roach * it under the terms of the GNU General Public License as published by
82d49f7deSGreg Roach * the Free Software Foundation, either version 3 of the License, or
92d49f7deSGreg Roach * (at your option) any later version.
102d49f7deSGreg Roach * This program is distributed in the hope that it will be useful,
112d49f7deSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
122d49f7deSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132d49f7deSGreg Roach * GNU General Public License for more details.
142d49f7deSGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
162d49f7deSGreg Roach */
17fcfa147eSGreg Roach
182d49f7deSGreg Roachdeclare(strict_types=1);
192d49f7deSGreg Roach
202d49f7deSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
212d49f7deSGreg Roach
22d72b284aSGreg Roachuse Fisharebest\Webtrees\Auth;
23d72b284aSGreg Roachuse Fisharebest\Webtrees\Date;
242d49f7deSGreg Roachuse Fisharebest\Webtrees\I18N;
252d49f7deSGreg Roachuse Psr\Http\Message\ResponseInterface;
262d49f7deSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
2798b7e8b3SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
282d49f7deSGreg Roach
29d72b284aSGreg Roachuse function array_keys;
30d72b284aSGreg Roachuse function response;
31d72b284aSGreg Roachuse function strip_tags;
32d72b284aSGreg Roachuse function view;
33d72b284aSGreg Roach
342d49f7deSGreg Roach/**
35d72b284aSGreg Roach * Show help text.
362d49f7deSGreg Roach */
3798b7e8b3SGreg Roachclass HelpText implements RequestHandlerInterface
382d49f7deSGreg Roach{
39d72b284aSGreg Roach    private const FRENCH_DATES = [
40d72b284aSGreg Roach        '@#DFRENCH R@ 12',
41d72b284aSGreg Roach        '@#DFRENCH R@ VEND 12',
42d72b284aSGreg Roach        'ABT @#DFRENCH R@ BRUM 12',
43d72b284aSGreg Roach        'BET @#DFRENCH R@ FRIM 12 AND @#DFRENCH R@ NIVO 12',
44d72b284aSGreg Roach        'FROM @#DFRENCH R@ PLUV 12 TO @#DFRENCH R@ VENT 12',
45d72b284aSGreg Roach        'AFT @#DFRENCH R@ GERM 12',
46d72b284aSGreg Roach        'BEF @#DFRENCH R@ FLOR 12',
47d72b284aSGreg Roach        'ABT @#DFRENCH R@ PRAI 12',
48d72b284aSGreg Roach        'FROM @#DFRENCH R@ MESS 12',
49d72b284aSGreg Roach        'TO @#DFRENCH R@ THER 12',
50d72b284aSGreg Roach        'EST @#DFRENCH R@ FRUC 12',
51d72b284aSGreg Roach        '@#DFRENCH R@ 03 COMP 12',
52d72b284aSGreg Roach    ];
53d72b284aSGreg Roach
54d72b284aSGreg Roach    private const HIJRI_DATES = [
55d72b284aSGreg Roach        '@#DHIJRI@ 1497',
56d72b284aSGreg Roach        '@#DHIJRI@ MUHAR 1497',
57d72b284aSGreg Roach        'ABT @#DHIJRI@ SAFAR 1497',
58d72b284aSGreg Roach        'BET @#DHIJRI@ RABIA 1497 AND @#DHIJRI@ RABIT 1497',
59d72b284aSGreg Roach        'FROM @#DHIJRI@ JUMAA 1497 TO @#DHIJRI@ JUMAT 1497',
60d72b284aSGreg Roach        'AFT @#DHIJRI@ RAJAB 1497',
61d72b284aSGreg Roach        'BEF @#DHIJRI@ SHAAB 1497',
62d72b284aSGreg Roach        'ABT @#DHIJRI@ RAMAD 1497',
63d72b284aSGreg Roach        'FROM @#DHIJRI@ SHAWW 1497',
64d72b284aSGreg Roach        'TO @#DHIJRI@ DHUAQ 1497',
65d72b284aSGreg Roach        '@#DHIJRI@ 03 DHUAH 1497',
66d72b284aSGreg Roach    ];
67d72b284aSGreg Roach
68201ffa7eSGreg Roach    private const JALALI_DATES = [
69201ffa7eSGreg Roach        '@#DJALALI@ 1497',
70201ffa7eSGreg Roach        '@#DJALALI@ FARVA 1497',
71201ffa7eSGreg Roach        'ABT @#DJALALI@ ORDIB 1497',
72201ffa7eSGreg Roach        'BET @#DJALALI@ KHORD 1497 AND @#DHIJRI@ TIR 1497',
73201ffa7eSGreg Roach        'FROM @#DJALALI@ MORDA 1497 TO @#DHIJRI@ SHAHR 1497',
74201ffa7eSGreg Roach        'AFT @#DJALALI@ MEHR 1497',
75201ffa7eSGreg Roach        'BEF @#DJALALI@ ABAN 1497',
76201ffa7eSGreg Roach        'ABT @#DJALALI@ AZAR 1497',
77201ffa7eSGreg Roach        'FROM @#DJALALI@ DEY 1497',
78201ffa7eSGreg Roach        'TO @#DJALALI@ BAHMA 1497',
79201ffa7eSGreg Roach        '@#DJALALI@ 03 XXXXX 1497',
80201ffa7eSGreg Roach    ];
81201ffa7eSGreg Roach
82d72b284aSGreg Roach    private const JEWISH_DATES = [
83d72b284aSGreg Roach        '@#DHEBREW@ 5481',
84d72b284aSGreg Roach        '@#DHEBREW@ TSH 5481',
85d72b284aSGreg Roach        'ABT @#DHEBREW@ CSH 5481',
86d72b284aSGreg Roach        'BET @#DHEBREW@ KSL 5481 AND @#DHEBREW@ TVT 5481',
87d72b284aSGreg Roach        'FROM @#DHEBREW@ SHV 5481 TO @#DHEBREW@ ADR 5481',
88d72b284aSGreg Roach        'AFT @#DHEBREW@ ADR 5481',
89d72b284aSGreg Roach        'AFT @#DHEBREW@ ADS 5480',
90d72b284aSGreg Roach        'BEF @#DHEBREW@ NSN 5481',
91d72b284aSGreg Roach        'ABT @#DHEBREW@ IYR 5481',
92d72b284aSGreg Roach        'FROM @#DHEBREW@ SVN 5481',
93d72b284aSGreg Roach        'TO @#DHEBREW@ TMZ 5481',
94d72b284aSGreg Roach        'EST @#DHEBREW@ AAV 5481',
95d72b284aSGreg Roach        '@#DHEBREW@ 03 ELL 5481',
96d72b284aSGreg Roach    ];
97d72b284aSGreg Roach
98d72b284aSGreg Roach    private const JULIAN_DATES = [
99d72b284aSGreg Roach        '@#DJULIAN@ 14 JAN 1700',
100d72b284aSGreg Roach        '@#DJULIAN@ 44 B.C.',
101d72b284aSGreg Roach        '@#DJULIAN@ 20 FEB 1742/43',
102d72b284aSGreg Roach        'BET @#DJULIAN@ 01 SEP 1752 AND @#DGREGORIAN@ 30 SEP 1752',
103d72b284aSGreg Roach    ];
104d72b284aSGreg Roach
105d72b284aSGreg Roach    private const DATE_SHORTCUTS = [
106d72b284aSGreg Roach        '1900'           => [],
107d72b284aSGreg Roach        'JAN 1900'       => [],
108d72b284aSGreg Roach        'FEB 1900'       => [],
109d72b284aSGreg Roach        'MAR 1900'       => [],
110d72b284aSGreg Roach        'APR 1900'       => [],
111d72b284aSGreg Roach        'MAY 1900'       => [],
112d72b284aSGreg Roach        'JUN 1900'       => [],
113d72b284aSGreg Roach        'JUL 1900'       => [],
114d72b284aSGreg Roach        'AUG 1900'       => [],
115d72b284aSGreg Roach        'SEP 1900'       => [],
116d72b284aSGreg Roach        'OCT 1900'       => [],
117d72b284aSGreg Roach        'NOV 1900'       => [],
118d72b284aSGreg Roach        'DEC 1900'       => [],
119d72b284aSGreg Roach        'ABT 1900'       => ['~1900'],
120d72b284aSGreg Roach        'EST 1900'       => ['*1900'],
121d72b284aSGreg Roach        'CAL 1900'       => ['#1900'],
122d72b284aSGreg Roach        'INT 1900 (...)' => [],
123d72b284aSGreg Roach    ];
124d72b284aSGreg Roach
125d72b284aSGreg Roach    private const DATE_RANGE_SHORTCUTS = [
126d72b284aSGreg Roach        'BET 1900 AND 1910'         => ['1900-1910'],
127d72b284aSGreg Roach        'AFT 1900'                  => ['>1900'],
128d72b284aSGreg Roach        'BEF 1910'                  => ['<1910'],
129d72b284aSGreg Roach        'BET JAN 1900 AND MAR 1900' => ['Q1 1900'],
130d72b284aSGreg Roach        'BET APR 1900 AND JUN 1900' => ['Q2 1900'],
131d72b284aSGreg Roach        'BET JUL 1900 AND SEP 1900' => ['Q3 1900'],
132d72b284aSGreg Roach        'BET OCT 1900 AND DEC 1900' => ['Q4 1900'],
133d72b284aSGreg Roach    ];
134d72b284aSGreg Roach
135d72b284aSGreg Roach    private const DATE_PERIOD_SHORTCUTS = [
136d72b284aSGreg Roach        'FROM 1900 TO 1910' => ['1900~1910'],
137d72b284aSGreg Roach        'FROM 1900'         => ['1900-'],
138d72b284aSGreg Roach        'TO 1910'           => ['-1900'],
139d72b284aSGreg Roach    ];
140d72b284aSGreg Roach
141d72b284aSGreg Roach    private const DMY_SHORTCUTS = [
142d72b284aSGreg Roach        '11 DEC 1913' => [
143d72b284aSGreg Roach            '11/12/1913',
144d72b284aSGreg Roach            '11-12-1913',
145d72b284aSGreg Roach            '11.12.1913',
146d72b284aSGreg Roach        ],
147d72b284aSGreg Roach        '01 FEB 2003' => [
148d72b284aSGreg Roach            '01/02/03',
149d72b284aSGreg Roach            '01-02-03',
150d72b284aSGreg Roach            '01.02.03',
151d72b284aSGreg Roach        ],
152d72b284aSGreg Roach    ];
153d72b284aSGreg Roach
154d72b284aSGreg Roach    private const MDY_SHORTCUTS = [
155d72b284aSGreg Roach        '11 DEC 1913' => [
156d72b284aSGreg Roach            '12/11/1913',
157d72b284aSGreg Roach            '12-11-1913',
158d72b284aSGreg Roach            '12.11.1913',
159d72b284aSGreg Roach        ],
160d72b284aSGreg Roach        '01 FEB 2003' => [
161d72b284aSGreg Roach            '02/01/03',
162d72b284aSGreg Roach            '02-01-03',
163d72b284aSGreg Roach            '02.01.03',
164d72b284aSGreg Roach        ],
165d72b284aSGreg Roach    ];
166d72b284aSGreg Roach
167d72b284aSGreg Roach    private const YMD_SHORTCUTS = [
168d72b284aSGreg Roach        '11 DEC 1913' => [
169d72b284aSGreg Roach            '11/12/1913',
170d72b284aSGreg Roach            '11-12-1913',
171d72b284aSGreg Roach            '11.12.1913',
172d72b284aSGreg Roach        ],
173d72b284aSGreg Roach        '01 FEB 2003' => [
174d72b284aSGreg Roach            '03/02/01',
175d72b284aSGreg Roach            '03-02-01',
176d72b284aSGreg Roach            '03.02.01',
177d72b284aSGreg Roach        ],
178d72b284aSGreg Roach    ];
179d72b284aSGreg Roach
1802d49f7deSGreg Roach    /**
1812d49f7deSGreg Roach     * @param ServerRequestInterface $request
1822d49f7deSGreg Roach     *
1832d49f7deSGreg Roach     * @return ResponseInterface
1842d49f7deSGreg Roach     */
1852d49f7deSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
1862d49f7deSGreg Roach    {
187d72b284aSGreg Roach        $topic = $request->getAttribute('topic');
1882d49f7deSGreg Roach
1894a9a6095SGreg Roach        $dmy = I18N::language()->dateOrder();
190229b730cSGreg Roach
191d72b284aSGreg Roach        switch ($topic) {
192d72b284aSGreg Roach            case 'DATE':
193229b730cSGreg Roach                switch ($dmy) {
194d72b284aSGreg Roach                    case 'YMD':
1954ab41520SGreg Roach                        $date_shortcuts = self::DATE_SHORTCUTS + self::YMD_SHORTCUTS;
196d72b284aSGreg Roach                        break;
197d72b284aSGreg Roach                    case 'MDY':
1984ab41520SGreg Roach                        $date_shortcuts = self::DATE_SHORTCUTS + self::MDY_SHORTCUTS;
199d72b284aSGreg Roach                        break;
200d72b284aSGreg Roach                    case 'DMY':
2012d49f7deSGreg Roach                    default:
2024ab41520SGreg Roach                        $date_shortcuts = self::DATE_SHORTCUTS + self::DMY_SHORTCUTS;
2032d49f7deSGreg Roach                        break;
2042d49f7deSGreg Roach                }
2052d49f7deSGreg Roach
206d72b284aSGreg Roach                $title = I18N::translate('Date');
207d72b284aSGreg Roach                $text  = view('help/date', [
208d72b284aSGreg Roach                    'date_dates'            => $this->formatDates(array_keys($date_shortcuts)),
209d72b284aSGreg Roach                    'date_shortcuts'        => $date_shortcuts,
210d72b284aSGreg Roach                    'date_period_dates'     => $this->formatDates(array_keys(self::DATE_PERIOD_SHORTCUTS)),
211d72b284aSGreg Roach                    'date_period_shortcuts' => self::DATE_PERIOD_SHORTCUTS,
212d72b284aSGreg Roach                    'date_range_dates'      => $this->formatDates(array_keys(self::DATE_RANGE_SHORTCUTS)),
213d72b284aSGreg Roach                    'date_range_shortcuts'  => self::DATE_RANGE_SHORTCUTS,
214d72b284aSGreg Roach                    'french_dates'          => $this->formatDates(self::FRENCH_DATES),
215d72b284aSGreg Roach                    'hijri_dates'           => $this->formatDates(self::HIJRI_DATES),
216201ffa7eSGreg Roach                    'jalali_dates'          => $this->formatDates(self::JALALI_DATES),
217d72b284aSGreg Roach                    'jewish_dates'          => $this->formatDates(self::JEWISH_DATES),
218d72b284aSGreg Roach                    'julian_dates'          => $this->formatDates(self::JULIAN_DATES),
2192d49f7deSGreg Roach                ]);
220d72b284aSGreg Roach                break;
221d72b284aSGreg Roach
222d72b284aSGreg Roach            case 'NAME':
223d72b284aSGreg Roach                $title = I18N::translate('Name');
224d72b284aSGreg Roach                $text  = view('help/name');
225d72b284aSGreg Roach                break;
226d72b284aSGreg Roach
227d72b284aSGreg Roach            case 'SURN':
228d72b284aSGreg Roach                $title = I18N::translate('Surname');
229d72b284aSGreg Roach                $text  = view('help/surname');
230d72b284aSGreg Roach                break;
231d72b284aSGreg Roach
232d72b284aSGreg Roach            case 'OBJE':
233d72b284aSGreg Roach                $title = I18N::translate('Media object');
234d72b284aSGreg Roach                $text  = view('help/media-object');
235d72b284aSGreg Roach                break;
236d72b284aSGreg Roach
237d72b284aSGreg Roach            case 'PLAC':
238d72b284aSGreg Roach                $title = I18N::translate('Place');
239d72b284aSGreg Roach                $text  = view('help/place');
240d72b284aSGreg Roach                break;
241d72b284aSGreg Roach
242d72b284aSGreg Roach            case 'RESN':
243d72b284aSGreg Roach                $title = I18N::translate('Restriction');
244d72b284aSGreg Roach                $text  = view('help/restriction');
245d72b284aSGreg Roach                break;
246d72b284aSGreg Roach
247d72b284aSGreg Roach            case 'ROMN':
248d72b284aSGreg Roach                $title = I18N::translate('Romanized');
249d72b284aSGreg Roach                $text  = view('help/romanized');
250d72b284aSGreg Roach                break;
251d72b284aSGreg Roach
252d72b284aSGreg Roach            case '_HEB':
253d72b284aSGreg Roach                $title = I18N::translate('Hebrew');
254d72b284aSGreg Roach                $text  = view('help/hebrew');
255d72b284aSGreg Roach                break;
256d72b284aSGreg Roach
2573de8af15SGreg Roach            case 'data-fixes':
2583de8af15SGreg Roach                $title = I18N::translate('Data fixes');
2593de8af15SGreg Roach                $text  = view('help/data-fixes');
2603de8af15SGreg Roach                break;
2613de8af15SGreg Roach
262d72b284aSGreg Roach            case 'edit_SOUR_EVEN':
263d72b284aSGreg Roach                $title = I18N::translate('Associate events with this source');
264d72b284aSGreg Roach                $text  = view('help/source-events');
265d72b284aSGreg Roach                break;
266d72b284aSGreg Roach
267d72b284aSGreg Roach            case 'pending_changes':
268d72b284aSGreg Roach                $title = I18N::translate('Pending changes');
269d72b284aSGreg Roach                $text  = view('help/pending-changes', [
270d72b284aSGreg Roach                    'is_admin' => Auth::isAdmin(),
271d72b284aSGreg Roach                ]);
272d72b284aSGreg Roach                break;
273d72b284aSGreg Roach
274d72b284aSGreg Roach            case 'relationship-privacy':
275d72b284aSGreg Roach                $title = I18N::translate('Restrict to immediate family');
276d72b284aSGreg Roach                $text  = view('help/relationship-privacy');
277d72b284aSGreg Roach                break;
278d72b284aSGreg Roach
279d72b284aSGreg Roach            default:
280d72b284aSGreg Roach                $title = I18N::translate('Help');
281d72b284aSGreg Roach                $text  = I18N::translate('The help text has not been written for this item.');
282d72b284aSGreg Roach                break;
283d72b284aSGreg Roach        }
284d72b284aSGreg Roach
285d72b284aSGreg Roach        $html = view('modals/help', [
286d72b284aSGreg Roach            'title' => $title,
287d72b284aSGreg Roach            'text'  => $text,
288d72b284aSGreg Roach        ]);
289d72b284aSGreg Roach
290d72b284aSGreg Roach        return response($html);
291d72b284aSGreg Roach    }
292d72b284aSGreg Roach
293d72b284aSGreg Roach    /**
294d72b284aSGreg Roach     * Format GEDCOM dates in the local language.
295d72b284aSGreg Roach     *
29609482a55SGreg Roach     * @param array<string>|array<int> $gedcom_dates
297d72b284aSGreg Roach     *
29824f2a3afSGreg Roach     * @return array<string>
299d72b284aSGreg Roach     */
300d72b284aSGreg Roach    private function formatDates(array $gedcom_dates): array
301d72b284aSGreg Roach    {
302d72b284aSGreg Roach        $dates = [];
303d72b284aSGreg Roach
304d72b284aSGreg Roach        foreach ($gedcom_dates as $gedcom_date) {
305d72b284aSGreg Roach            // PHP converts numeric array keys ('1900') to integers (1900), so reverse this.
306d72b284aSGreg Roach            $gedcom_date = (string) $gedcom_date;
307d72b284aSGreg Roach
308d72b284aSGreg Roach            $date                = new Date($gedcom_date);
30966ecd017SGreg Roach            $dates[$gedcom_date] = strip_tags($date->display());
310d72b284aSGreg Roach        }
311d72b284aSGreg Roach
312d72b284aSGreg Roach        return $dates;
313d72b284aSGreg Roach    }
3142d49f7deSGreg Roach}
315