xref: /webtrees/app/Module/ModuleThemeTrait.php (revision 86661454ca7b7e2d48e9e107905c03de74517d0c)
149a243cbSGreg Roach<?php
23976b470SGreg Roach
349a243cbSGreg Roach/**
449a243cbSGreg Roach * webtrees: online genealogy
549a243cbSGreg Roach * Copyright (C) 2019 webtrees development team
649a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
749a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
849a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
949a243cbSGreg Roach * (at your option) any later version.
1049a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1149a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1249a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1349a243cbSGreg Roach * GNU General Public License for more details.
1449a243cbSGreg Roach * You should have received a copy of the GNU General Public License
1549a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1649a243cbSGreg Roach */
17fcfa147eSGreg Roach
1849a243cbSGreg Roachdeclare(strict_types=1);
1949a243cbSGreg Roach
2049a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
2149a243cbSGreg Roach
22ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth;
23ade503dfSGreg Roachuse Fisharebest\Webtrees\Fact;
24ade503dfSGreg Roachuse Fisharebest\Webtrees\Gedcom;
25ade503dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
260c0910bfSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
2756f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\LoginPage;
2856f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\Logout;
297adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectLanguage;
307adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectTheme;
31ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N;
32ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual;
33ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu;
344ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
35ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree;
36f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees;
376ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
383976b470SGreg Roach
396ccdf4f0SGreg Roachuse function app;
407adfb8e5SGreg Roachuse function route;
41ade503dfSGreg Roach
4249a243cbSGreg Roach/**
4349a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface
4449a243cbSGreg Roach */
4549a243cbSGreg Roachtrait ModuleThemeTrait
4649a243cbSGreg Roach{
47ade503dfSGreg Roach    /**
48962ead51SGreg Roach     * @return string
49962ead51SGreg Roach     */
50962ead51SGreg Roach    abstract public function name(): string;
51962ead51SGreg Roach
52962ead51SGreg Roach    /**
53962ead51SGreg Roach     * @return string
54962ead51SGreg Roach     */
55962ead51SGreg Roach    abstract public function title(): string;
56962ead51SGreg Roach
57962ead51SGreg Roach    /**
583d8b2a8eSGreg Roach     * A sentence describing what this module does.
593d8b2a8eSGreg Roach     *
603d8b2a8eSGreg Roach     * @return string
613d8b2a8eSGreg Roach     */
623d8b2a8eSGreg Roach    public function description(): string
633d8b2a8eSGreg Roach    {
643d8b2a8eSGreg Roach        return I18N::translate('Theme') . ' — ' . $this->title();
653d8b2a8eSGreg Roach    }
663d8b2a8eSGreg Roach
673d8b2a8eSGreg Roach    /**
68ade503dfSGreg Roach     * Display an icon for this fact.
69ade503dfSGreg Roach     *
70e837ff07SGreg Roach     * @TODO use CSS for this
71e837ff07SGreg Roach     *
72ade503dfSGreg Roach     * @param Fact $fact
73ade503dfSGreg Roach     *
74ade503dfSGreg Roach     * @return string
75ade503dfSGreg Roach     */
76ade503dfSGreg Roach    public function icon(Fact $fact): string
77ade503dfSGreg Roach    {
78e837ff07SGreg Roach        $asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png';
79f397d0fdSGreg Roach        if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
80e837ff07SGreg Roach            return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">';
81ade503dfSGreg Roach        }
82ade503dfSGreg Roach
83ade503dfSGreg Roach        // Spacer image - for alignment - until we move to a sprite.
84e837ff07SGreg Roach        $asset = 'public/css/' . $this->name() . '/images/facts/NULL.png';
85f397d0fdSGreg Roach        if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
86e837ff07SGreg Roach            return '<img src="' . e(asset($asset)) . '">';
87ade503dfSGreg Roach        }
88ade503dfSGreg Roach
89ade503dfSGreg Roach        return '';
90ade503dfSGreg Roach    }
91ade503dfSGreg Roach
92ade503dfSGreg Roach    /**
93ade503dfSGreg Roach     * Generate the facts, for display in charts.
94ade503dfSGreg Roach     *
95ade503dfSGreg Roach     * @param Individual $individual
96ade503dfSGreg Roach     *
97ade503dfSGreg Roach     * @return string
98ade503dfSGreg Roach     */
99ade503dfSGreg Roach    public function individualBoxFacts(Individual $individual): string
100ade503dfSGreg Roach    {
101ade503dfSGreg Roach        $html = '';
102ade503dfSGreg Roach
103ade503dfSGreg Roach        $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
104ade503dfSGreg Roach        // Show BIRT or equivalent event
105ade503dfSGreg Roach        foreach (Gedcom::BIRTH_EVENTS as $birttag) {
10622d65e5aSGreg Roach            if (!in_array($birttag, $opt_tags, true)) {
107820b62dfSGreg Roach                $event = $individual->facts([$birttag])->first();
108820b62dfSGreg Roach                if ($event instanceof Fact) {
109ade503dfSGreg Roach                    $html .= $event->summary();
110ade503dfSGreg Roach                    break;
111ade503dfSGreg Roach                }
112ade503dfSGreg Roach            }
113ade503dfSGreg Roach        }
114ade503dfSGreg Roach        // Show optional events (before death)
115ade503dfSGreg Roach        foreach ($opt_tags as $key => $tag) {
11622d65e5aSGreg Roach            if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
117820b62dfSGreg Roach                $event = $individual->facts([$tag])->first();
118820b62dfSGreg Roach                if ($event instanceof Fact) {
119ade503dfSGreg Roach                    $html .= $event->summary();
120ade503dfSGreg Roach                    unset($opt_tags[$key]);
121ade503dfSGreg Roach                }
122ade503dfSGreg Roach            }
123ade503dfSGreg Roach        }
124ade503dfSGreg Roach        // Show DEAT or equivalent event
125ade503dfSGreg Roach        foreach (Gedcom::DEATH_EVENTS as $deattag) {
126820b62dfSGreg Roach            $event = $individual->facts([$deattag])->first();
127820b62dfSGreg Roach            if ($event instanceof Fact) {
128ade503dfSGreg Roach                $html .= $event->summary();
12922d65e5aSGreg Roach                if (in_array($deattag, $opt_tags, true)) {
13022d65e5aSGreg Roach                    unset($opt_tags[array_search($deattag, $opt_tags, true)]);
131ade503dfSGreg Roach                }
132ade503dfSGreg Roach                break;
133ade503dfSGreg Roach            }
134ade503dfSGreg Roach        }
135ade503dfSGreg Roach        // Show remaining optional events (after death)
136ade503dfSGreg Roach        foreach ($opt_tags as $tag) {
137820b62dfSGreg Roach            $event = $individual->facts([$tag])->first();
138820b62dfSGreg Roach            if ($event instanceof Fact) {
139ade503dfSGreg Roach                $html .= $event->summary();
140ade503dfSGreg Roach            }
141ade503dfSGreg Roach        }
142ade503dfSGreg Roach
143ade503dfSGreg Roach        return $html;
144ade503dfSGreg Roach    }
145ade503dfSGreg Roach
146ade503dfSGreg Roach    /**
147ade503dfSGreg Roach     * Links, to show in chart boxes;
148ade503dfSGreg Roach     *
149ade503dfSGreg Roach     * @param Individual $individual
150ade503dfSGreg Roach     *
151ade503dfSGreg Roach     * @return Menu[]
152ade503dfSGreg Roach     */
153ade503dfSGreg Roach    public function individualBoxMenu(Individual $individual): array
154ade503dfSGreg Roach    {
155ade503dfSGreg Roach        $menus = array_merge(
156ade503dfSGreg Roach            $this->individualBoxMenuCharts($individual),
157ade503dfSGreg Roach            $this->individualBoxMenuFamilyLinks($individual)
158ade503dfSGreg Roach        );
159ade503dfSGreg Roach
160ade503dfSGreg Roach        return $menus;
161ade503dfSGreg Roach    }
162ade503dfSGreg Roach
163ade503dfSGreg Roach    /**
164ade503dfSGreg Roach     * Chart links, to show in chart boxes;
165ade503dfSGreg Roach     *
166ade503dfSGreg Roach     * @param Individual $individual
167ade503dfSGreg Roach     *
168ade503dfSGreg Roach     * @return Menu[]
169ade503dfSGreg Roach     */
170ade503dfSGreg Roach    public function individualBoxMenuCharts(Individual $individual): array
171ade503dfSGreg Roach    {
172ade503dfSGreg Roach        $menus = [];
173f39638cfSGreg Roach        foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) {
174ade503dfSGreg Roach            $menu = $chart->chartBoxMenu($individual);
175ade503dfSGreg Roach            if ($menu) {
176ade503dfSGreg Roach                $menus[] = $menu;
177ade503dfSGreg Roach            }
178ade503dfSGreg Roach        }
179ade503dfSGreg Roach
1800b93976aSGreg Roach        usort($menus, static function (Menu $x, Menu $y): int {
181ade503dfSGreg Roach            return I18N::strcasecmp($x->getLabel(), $y->getLabel());
182ade503dfSGreg Roach        });
183ade503dfSGreg Roach
184ade503dfSGreg Roach        return $menus;
185ade503dfSGreg Roach    }
186ade503dfSGreg Roach
187ade503dfSGreg Roach    /**
188ade503dfSGreg Roach     * Family links, to show in chart boxes.
189ade503dfSGreg Roach     *
190ade503dfSGreg Roach     * @param Individual $individual
191ade503dfSGreg Roach     *
192ade503dfSGreg Roach     * @return Menu[]
193ade503dfSGreg Roach     */
194ade503dfSGreg Roach    public function individualBoxMenuFamilyLinks(Individual $individual): array
195ade503dfSGreg Roach    {
196ade503dfSGreg Roach        $menus = [];
197ade503dfSGreg Roach
19839ca88baSGreg Roach        foreach ($individual->spouseFamilies() as $family) {
199ade503dfSGreg Roach            $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url());
20039ca88baSGreg Roach            $spouse  = $family->spouse($individual);
201ade503dfSGreg Roach            if ($spouse && $spouse->canShowName()) {
20239ca88baSGreg Roach                $menus[] = new Menu($spouse->fullName(), $spouse->url());
203ade503dfSGreg Roach            }
20439ca88baSGreg Roach            foreach ($family->children() as $child) {
205ade503dfSGreg Roach                if ($child->canShowName()) {
20639ca88baSGreg Roach                    $menus[] = new Menu($child->fullName(), $child->url());
207ade503dfSGreg Roach                }
208ade503dfSGreg Roach            }
209ade503dfSGreg Roach        }
210ade503dfSGreg Roach
211ade503dfSGreg Roach        return $menus;
212ade503dfSGreg Roach    }
213ade503dfSGreg Roach
214ade503dfSGreg Roach    /**
215f567c3d8SGreg Roach     * Generate a menu item to change the blocks on the current tree/user page.
216ade503dfSGreg Roach     *
2170c8c69d4SGreg Roach     * @param Tree $tree
2180c8c69d4SGreg Roach     *
219ade503dfSGreg Roach     * @return Menu|null
220ade503dfSGreg Roach     */
221e364afe4SGreg Roach    public function menuChangeBlocks(Tree $tree): ?Menu
222ade503dfSGreg Roach    {
223eb235819SGreg Roach        /** @var ServerRequestInterface $request */
2246ccdf4f0SGreg Roach        $request = app(ServerRequestInterface::class);
225e6bcfa02SGreg Roach
2260d7461faSGreg Roach        $route = $request->getAttribute('route');
227eb235819SGreg Roach
228eb235819SGreg Roach        if (Auth::check() && $route === 'user-page') {
229d72b284aSGreg Roach            return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['tree' => $tree->name()]), 'menu-change-blocks');
230ade503dfSGreg Roach        }
231ade503dfSGreg Roach
232eb235819SGreg Roach        if (Auth::isManager($tree) && $route === 'tree-page') {
233d72b284aSGreg Roach            return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['tree' => $tree->name()]), 'menu-change-blocks');
234ade503dfSGreg Roach        }
235ade503dfSGreg Roach
236ade503dfSGreg Roach        return null;
237ade503dfSGreg Roach    }
238ade503dfSGreg Roach
239ade503dfSGreg Roach    /**
240ade503dfSGreg Roach     * Generate a menu item for the control panel.
241ade503dfSGreg Roach     *
2420c8c69d4SGreg Roach     * @param Tree $tree
2430c8c69d4SGreg Roach     *
244ade503dfSGreg Roach     * @return Menu|null
245ade503dfSGreg Roach     */
246e364afe4SGreg Roach    public function menuControlPanel(Tree $tree): ?Menu
247ade503dfSGreg Roach    {
248ade503dfSGreg Roach        if (Auth::isAdmin()) {
2490c0910bfSGreg Roach            return new Menu(I18N::translate('Control panel'), route(ControlPanel::class), 'menu-admin');
250ade503dfSGreg Roach        }
251ade503dfSGreg Roach
2520c8c69d4SGreg Roach        if (Auth::isManager($tree)) {
2530c0910bfSGreg Roach            return new Menu(I18N::translate('Control panel'), route('manage-trees'), 'menu-admin');
254ade503dfSGreg Roach        }
255ade503dfSGreg Roach
256ade503dfSGreg Roach        return null;
257ade503dfSGreg Roach    }
258ade503dfSGreg Roach
259ade503dfSGreg Roach    /**
260ade503dfSGreg Roach     * A menu to show a list of available languages.
261ade503dfSGreg Roach     *
262ade503dfSGreg Roach     * @return Menu|null
263ade503dfSGreg Roach     */
264e364afe4SGreg Roach    public function menuLanguages(): ?Menu
265ade503dfSGreg Roach    {
266ade503dfSGreg Roach        $menu = new Menu(I18N::translate('Language'), '#', 'menu-language');
267ade503dfSGreg Roach
268ade503dfSGreg Roach        foreach (I18N::activeLocales() as $locale) {
269ade503dfSGreg Roach            $language_tag = $locale->languageTag();
270ade503dfSGreg Roach            $class        = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : '');
271ade503dfSGreg Roach            $menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [
2727adfb8e5SGreg Roach                'data-post-url' => route(SelectLanguage::class, ['language' => $language_tag]),
273ade503dfSGreg Roach            ]));
274ade503dfSGreg Roach        }
275ade503dfSGreg Roach
276ade503dfSGreg Roach        if (count($menu->getSubmenus()) > 1) {
277ade503dfSGreg Roach            return $menu;
278ade503dfSGreg Roach        }
279ade503dfSGreg Roach
280ade503dfSGreg Roach        return null;
281ade503dfSGreg Roach    }
282ade503dfSGreg Roach
283ade503dfSGreg Roach    /**
284ade503dfSGreg Roach     * A login menu option (or null if we are already logged in).
285ade503dfSGreg Roach     *
286ade503dfSGreg Roach     * @return Menu|null
287ade503dfSGreg Roach     */
288e364afe4SGreg Roach    public function menuLogin(): ?Menu
289ade503dfSGreg Roach    {
290ade503dfSGreg Roach        if (Auth::check()) {
291ade503dfSGreg Roach            return null;
292ade503dfSGreg Roach        }
293ade503dfSGreg Roach
294*86661454SGreg Roach        $request = app(ServerRequestInterface::class);
295*86661454SGreg Roach
296ade503dfSGreg Roach        // Return to this page after login...
297*86661454SGreg Roach        $url = $request->getUri();
298ade503dfSGreg Roach
299ade503dfSGreg Roach        // ...but switch from the tree-page to the user-page
300ade503dfSGreg Roach        $url = str_replace('route=tree-page', 'route=user-page', $url);
301ade503dfSGreg Roach
302*86661454SGreg Roach        // Stay on the same tree page
303*86661454SGreg Roach        $tree = $request->getAttribute('tree');
304*86661454SGreg Roach        $url  = route(LoginPage::class, ['tree' => $tree instanceof Tree ? $tree->name() : null, 'url' => $url]);
305*86661454SGreg Roach
306*86661454SGreg Roach        return new Menu(I18N::translate('Sign in'), $url, 'menu-login', ['rel' => 'nofollow']);
307ade503dfSGreg Roach    }
308ade503dfSGreg Roach
309ade503dfSGreg Roach    /**
310ade503dfSGreg Roach     * A logout menu option (or null if we are already logged out).
311ade503dfSGreg Roach     *
312ade503dfSGreg Roach     * @return Menu|null
313ade503dfSGreg Roach     */
314e364afe4SGreg Roach    public function menuLogout(): ?Menu
315ade503dfSGreg Roach    {
316ade503dfSGreg Roach        if (Auth::check()) {
3170d7461faSGreg Roach            return new Menu(I18N::translate('Sign out'), '#', 'menu-logout', ['data-post-url' => route(Logout::class)]);
318ade503dfSGreg Roach        }
319ade503dfSGreg Roach
320ade503dfSGreg Roach        return null;
321ade503dfSGreg Roach    }
322ade503dfSGreg Roach
323ade503dfSGreg Roach    /**
324ade503dfSGreg Roach     * A link to allow users to edit their account settings.
325ade503dfSGreg Roach     *
326ade503dfSGreg Roach     * @return Menu|null
327ade503dfSGreg Roach     */
328e364afe4SGreg Roach    public function menuMyAccount(): ?Menu
329ade503dfSGreg Roach    {
330ade503dfSGreg Roach        if (Auth::check()) {
331ade503dfSGreg Roach            return new Menu(I18N::translate('My account'), route('my-account'));
332ade503dfSGreg Roach        }
333ade503dfSGreg Roach
334ade503dfSGreg Roach        return null;
335ade503dfSGreg Roach    }
336ade503dfSGreg Roach
337ade503dfSGreg Roach    /**
338ade503dfSGreg Roach     * A link to the user's individual record (individual.php).
339ade503dfSGreg Roach     *
3400c8c69d4SGreg Roach     * @param Tree $tree
3410c8c69d4SGreg Roach     *
342ade503dfSGreg Roach     * @return Menu|null
343ade503dfSGreg Roach     */
344e364afe4SGreg Roach    public function menuMyIndividualRecord(Tree $tree): ?Menu
345ade503dfSGreg Roach    {
3460c8c69d4SGreg Roach        $record = Individual::getInstance($tree->getUserPreference(Auth::user(), 'gedcomid'), $tree);
347ade503dfSGreg Roach
348ade503dfSGreg Roach        if ($record) {
349ade503dfSGreg Roach            return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord');
350ade503dfSGreg Roach        }
351ade503dfSGreg Roach
352ade503dfSGreg Roach        return null;
353ade503dfSGreg Roach    }
354ade503dfSGreg Roach
355ade503dfSGreg Roach    /**
356ade503dfSGreg Roach     * A link to the user's personal home page.
357ade503dfSGreg Roach     *
3580c8c69d4SGreg Roach     * @param Tree $tree
3590c8c69d4SGreg Roach     *
360ade503dfSGreg Roach     * @return Menu
361ade503dfSGreg Roach     */
3620c8c69d4SGreg Roach    public function menuMyPage(Tree $tree): Menu
363ade503dfSGreg Roach    {
364d72b284aSGreg Roach        return new Menu(I18N::translate('My page'), route('user-page', ['tree' => $tree->name()]), 'menu-mypage');
365ade503dfSGreg Roach    }
366ade503dfSGreg Roach
367ade503dfSGreg Roach    /**
368ade503dfSGreg Roach     * A menu for the user's personal pages.
369ade503dfSGreg Roach     *
3700c8c69d4SGreg Roach     * @param Tree|null $tree
3710c8c69d4SGreg Roach     *
372ade503dfSGreg Roach     * @return Menu|null
373ade503dfSGreg Roach     */
374e364afe4SGreg Roach    public function menuMyPages(?Tree $tree): ?Menu
375ade503dfSGreg Roach    {
3760c8c69d4SGreg Roach        if ($tree instanceof Tree && Auth::id()) {
377ade503dfSGreg Roach            return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([
3780c8c69d4SGreg Roach                $this->menuMyPage($tree),
3790c8c69d4SGreg Roach                $this->menuMyIndividualRecord($tree),
3800c8c69d4SGreg Roach                $this->menuMyPedigree($tree),
381ade503dfSGreg Roach                $this->menuMyAccount(),
3820c8c69d4SGreg Roach                $this->menuControlPanel($tree),
3830c8c69d4SGreg Roach                $this->menuChangeBlocks($tree),
384ade503dfSGreg Roach            ]));
385ade503dfSGreg Roach        }
386ade503dfSGreg Roach
387ade503dfSGreg Roach        return null;
388ade503dfSGreg Roach    }
389ade503dfSGreg Roach
390ade503dfSGreg Roach    /**
391ade503dfSGreg Roach     * A link to the user's individual record.
392ade503dfSGreg Roach     *
3930c8c69d4SGreg Roach     * @param Tree $tree
3940c8c69d4SGreg Roach     *
395ade503dfSGreg Roach     * @return Menu|null
396ade503dfSGreg Roach     */
397e364afe4SGreg Roach    public function menuMyPedigree(Tree $tree): ?Menu
398ade503dfSGreg Roach    {
3990c8c69d4SGreg Roach        $gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid');
400ade503dfSGreg Roach
4010c8c69d4SGreg Roach        $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
4020b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module): bool {
403ade503dfSGreg Roach                return $module instanceof PedigreeChartModule;
404ade503dfSGreg Roach            });
405ade503dfSGreg Roach
406ade503dfSGreg Roach        if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) {
407ade503dfSGreg Roach            return new Menu(
408ade503dfSGreg Roach                I18N::translate('My pedigree'),
409ade503dfSGreg Roach                route('pedigree', [
410ade503dfSGreg Roach                    'xref' => $gedcomid,
4119022ab66SGreg Roach                    'tree'  => $tree->name(),
412ade503dfSGreg Roach                ]),
413ade503dfSGreg Roach                'menu-mypedigree'
414ade503dfSGreg Roach            );
415ade503dfSGreg Roach        }
416ade503dfSGreg Roach
417ade503dfSGreg Roach        return null;
418ade503dfSGreg Roach    }
419ade503dfSGreg Roach
420ade503dfSGreg Roach    /**
421ade503dfSGreg Roach     * Create a pending changes menu.
422ade503dfSGreg Roach     *
4230c8c69d4SGreg Roach     * @param Tree|null $tree
4240c8c69d4SGreg Roach     *
425ade503dfSGreg Roach     * @return Menu|null
426ade503dfSGreg Roach     */
427e364afe4SGreg Roach    public function menuPendingChanges(?Tree $tree): ?Menu
428ade503dfSGreg Roach    {
4290c8c69d4SGreg Roach        if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) {
430ade503dfSGreg Roach            $url = route('show-pending', [
4319022ab66SGreg Roach                'tree' => $tree->name(),
432cf8c0692SGreg Roach                'url' => (string) app(ServerRequestInterface::class)->getUri(),
433ade503dfSGreg Roach            ]);
434ade503dfSGreg Roach
435ade503dfSGreg Roach            return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending');
436ade503dfSGreg Roach        }
437ade503dfSGreg Roach
438ade503dfSGreg Roach        return null;
439ade503dfSGreg Roach    }
440ade503dfSGreg Roach
441ade503dfSGreg Roach    /**
442ade503dfSGreg Roach     * Themes menu.
443ade503dfSGreg Roach     *
444ade503dfSGreg Roach     * @return Menu|null
445ade503dfSGreg Roach     */
446e364afe4SGreg Roach    public function menuThemes(): ?Menu
447ade503dfSGreg Roach    {
448b668782fSGreg Roach        $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true);
449df8baf00SGreg Roach
450cab242e7SGreg Roach        $current_theme = app(ModuleThemeInterface::class);
4518136679eSGreg Roach
4528136679eSGreg Roach        if ($themes->count() > 1) {
4530b5fd0a6SGreg Roach            $submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu {
4548136679eSGreg Roach                $active     = $theme->name() === $current_theme->name();
4558136679eSGreg Roach                $class      = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');
4568136679eSGreg Roach
4578136679eSGreg Roach                return new Menu($theme->title(), '#', $class, [
4587adfb8e5SGreg Roach                    'data-post-url' => route(SelectTheme::class, ['theme' => $theme->name()]),
459ade503dfSGreg Roach                ]);
460ade503dfSGreg Roach            });
461ade503dfSGreg Roach
4628136679eSGreg Roach            return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all());
463ade503dfSGreg Roach        }
464ade503dfSGreg Roach
465ade503dfSGreg Roach        return null;
466ade503dfSGreg Roach    }
467ade503dfSGreg Roach
468ade503dfSGreg Roach    /**
469ade503dfSGreg Roach     * Misecellaneous dimensions, fonts, styles, etc.
470ade503dfSGreg Roach     *
471ade503dfSGreg Roach     * @param string $parameter_name
472ade503dfSGreg Roach     *
473ade503dfSGreg Roach     * @return string|int|float
474ade503dfSGreg Roach     */
475ade503dfSGreg Roach    public function parameter($parameter_name)
476ade503dfSGreg Roach    {
477ade503dfSGreg Roach        return '';
478ade503dfSGreg Roach    }
479ade503dfSGreg Roach
480ade503dfSGreg Roach    /**
481ade503dfSGreg Roach     * Generate a list of items for the main menu.
482ade503dfSGreg Roach     *
4830c8c69d4SGreg Roach     * @param Tree|null $tree
4840c8c69d4SGreg Roach     *
485ade503dfSGreg Roach     * @return Menu[]
486ade503dfSGreg Roach     */
4870c8c69d4SGreg Roach    public function genealogyMenu(?Tree $tree): array
488ade503dfSGreg Roach    {
4890c8c69d4SGreg Roach        if ($tree === null) {
4900c8c69d4SGreg Roach            return [];
4910c8c69d4SGreg Roach        }
4920c8c69d4SGreg Roach
4930c8c69d4SGreg Roach        return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user())
4940b5fd0a6SGreg Roach            ->map(static function (ModuleMenuInterface $menu) use ($tree): ?Menu {
4950c8c69d4SGreg Roach                return $menu->getMenu($tree);
496ade503dfSGreg Roach            })
497ade503dfSGreg Roach            ->filter()
498ade503dfSGreg Roach            ->all();
499ade503dfSGreg Roach    }
500ade503dfSGreg Roach
501ade503dfSGreg Roach    /**
5020c8c69d4SGreg Roach     * Create the genealogy menu.
503ade503dfSGreg Roach     *
504ade503dfSGreg Roach     * @param Menu[] $menus
505ade503dfSGreg Roach     *
506ade503dfSGreg Roach     * @return string
507ade503dfSGreg Roach     */
5080c8c69d4SGreg Roach    public function genealogyMenuContent(array $menus): string
509ade503dfSGreg Roach    {
5100b5fd0a6SGreg Roach        return implode('', array_map(static function (Menu $menu): string {
511ade503dfSGreg Roach            return $menu->bootstrap4();
512ade503dfSGreg Roach        }, $menus));
513ade503dfSGreg Roach    }
514ade503dfSGreg Roach
515ade503dfSGreg Roach    /**
516ade503dfSGreg Roach     * Generate a list of items for the user menu.
517ade503dfSGreg Roach     *
5180c8c69d4SGreg Roach     * @param Tree|null $tree
5190c8c69d4SGreg Roach     *
520ade503dfSGreg Roach     * @return Menu[]
521ade503dfSGreg Roach     */
5220c8c69d4SGreg Roach    public function userMenu(?Tree $tree): array
523ade503dfSGreg Roach    {
524ade503dfSGreg Roach        return array_filter([
5250c8c69d4SGreg Roach            $this->menuPendingChanges($tree),
5260c8c69d4SGreg Roach            $this->menuMyPages($tree),
527ade503dfSGreg Roach            $this->menuThemes(),
528ade503dfSGreg Roach            $this->menuLanguages(),
529ade503dfSGreg Roach            $this->menuLogin(),
530ade503dfSGreg Roach            $this->menuLogout(),
531ade503dfSGreg Roach        ]);
532ade503dfSGreg Roach    }
533ade503dfSGreg Roach
534ade503dfSGreg Roach    /**
535ade503dfSGreg Roach     * A list of CSS files to include for this page.
536ade503dfSGreg Roach     *
537ade503dfSGreg Roach     * @return string[]
538ade503dfSGreg Roach     */
539ade503dfSGreg Roach    public function stylesheets(): array
540ade503dfSGreg Roach    {
541ade503dfSGreg Roach        return [];
542ade503dfSGreg Roach    }
54349a243cbSGreg Roach}
544