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; 26a49d0e3fSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AccountEdit; 270c0910bfSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel; 289b541e4aSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\HomePage; 2956f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\LoginPage; 3056f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\Logout; 3122e73debSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\PendingChanges; 327adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectLanguage; 337adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectTheme; 34ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N; 35ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual; 36ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu; 374ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 38ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree; 39f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees; 406ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 413976b470SGreg Roach 426ccdf4f0SGreg Roachuse function app; 437adfb8e5SGreg Roachuse function route; 44ade503dfSGreg Roach 4549a243cbSGreg Roach/** 4649a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface 4749a243cbSGreg Roach */ 4849a243cbSGreg Roachtrait ModuleThemeTrait 4949a243cbSGreg Roach{ 50ade503dfSGreg Roach /** 51962ead51SGreg Roach * @return string 52962ead51SGreg Roach */ 53962ead51SGreg Roach abstract public function name(): string; 54962ead51SGreg Roach 55962ead51SGreg Roach /** 56962ead51SGreg Roach * @return string 57962ead51SGreg Roach */ 58962ead51SGreg Roach abstract public function title(): string; 59962ead51SGreg Roach 60962ead51SGreg Roach /** 613d8b2a8eSGreg Roach * A sentence describing what this module does. 623d8b2a8eSGreg Roach * 633d8b2a8eSGreg Roach * @return string 643d8b2a8eSGreg Roach */ 653d8b2a8eSGreg Roach public function description(): string 663d8b2a8eSGreg Roach { 673d8b2a8eSGreg Roach return I18N::translate('Theme') . ' — ' . $this->title(); 683d8b2a8eSGreg Roach } 693d8b2a8eSGreg Roach 703d8b2a8eSGreg Roach /** 71ade503dfSGreg Roach * Display an icon for this fact. 72ade503dfSGreg Roach * 73e837ff07SGreg Roach * @TODO use CSS for this 74e837ff07SGreg Roach * 75ade503dfSGreg Roach * @param Fact $fact 76ade503dfSGreg Roach * 77ade503dfSGreg Roach * @return string 78ade503dfSGreg Roach */ 79ade503dfSGreg Roach public function icon(Fact $fact): string 80ade503dfSGreg Roach { 81e837ff07SGreg Roach $asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png'; 82f397d0fdSGreg Roach if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) { 83e837ff07SGreg Roach return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">'; 84ade503dfSGreg Roach } 85ade503dfSGreg Roach 86ade503dfSGreg Roach // Spacer image - for alignment - until we move to a sprite. 87e837ff07SGreg Roach $asset = 'public/css/' . $this->name() . '/images/facts/NULL.png'; 88f397d0fdSGreg Roach if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) { 89e837ff07SGreg Roach return '<img src="' . e(asset($asset)) . '">'; 90ade503dfSGreg Roach } 91ade503dfSGreg Roach 92ade503dfSGreg Roach return ''; 93ade503dfSGreg Roach } 94ade503dfSGreg Roach 95ade503dfSGreg Roach /** 96ade503dfSGreg Roach * Generate the facts, for display in charts. 97ade503dfSGreg Roach * 98ade503dfSGreg Roach * @param Individual $individual 99ade503dfSGreg Roach * 100ade503dfSGreg Roach * @return string 101ade503dfSGreg Roach */ 102ade503dfSGreg Roach public function individualBoxFacts(Individual $individual): string 103ade503dfSGreg Roach { 104ade503dfSGreg Roach $html = ''; 105ade503dfSGreg Roach 106ade503dfSGreg Roach $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY); 107ade503dfSGreg Roach // Show BIRT or equivalent event 108ade503dfSGreg Roach foreach (Gedcom::BIRTH_EVENTS as $birttag) { 10922d65e5aSGreg Roach if (!in_array($birttag, $opt_tags, true)) { 110820b62dfSGreg Roach $event = $individual->facts([$birttag])->first(); 111820b62dfSGreg Roach if ($event instanceof Fact) { 112ade503dfSGreg Roach $html .= $event->summary(); 113ade503dfSGreg Roach break; 114ade503dfSGreg Roach } 115ade503dfSGreg Roach } 116ade503dfSGreg Roach } 117ade503dfSGreg Roach // Show optional events (before death) 118ade503dfSGreg Roach foreach ($opt_tags as $key => $tag) { 11922d65e5aSGreg Roach if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) { 120820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 121820b62dfSGreg Roach if ($event instanceof Fact) { 122ade503dfSGreg Roach $html .= $event->summary(); 123ade503dfSGreg Roach unset($opt_tags[$key]); 124ade503dfSGreg Roach } 125ade503dfSGreg Roach } 126ade503dfSGreg Roach } 127ade503dfSGreg Roach // Show DEAT or equivalent event 128ade503dfSGreg Roach foreach (Gedcom::DEATH_EVENTS as $deattag) { 129820b62dfSGreg Roach $event = $individual->facts([$deattag])->first(); 130820b62dfSGreg Roach if ($event instanceof Fact) { 131ade503dfSGreg Roach $html .= $event->summary(); 13222d65e5aSGreg Roach if (in_array($deattag, $opt_tags, true)) { 13322d65e5aSGreg Roach unset($opt_tags[array_search($deattag, $opt_tags, true)]); 134ade503dfSGreg Roach } 135ade503dfSGreg Roach break; 136ade503dfSGreg Roach } 137ade503dfSGreg Roach } 138ade503dfSGreg Roach // Show remaining optional events (after death) 139ade503dfSGreg Roach foreach ($opt_tags as $tag) { 140820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 141820b62dfSGreg Roach if ($event instanceof Fact) { 142ade503dfSGreg Roach $html .= $event->summary(); 143ade503dfSGreg Roach } 144ade503dfSGreg Roach } 145ade503dfSGreg Roach 146ade503dfSGreg Roach return $html; 147ade503dfSGreg Roach } 148ade503dfSGreg Roach 149ade503dfSGreg Roach /** 150ade503dfSGreg Roach * Links, to show in chart boxes; 151ade503dfSGreg Roach * 152ade503dfSGreg Roach * @param Individual $individual 153ade503dfSGreg Roach * 154ade503dfSGreg Roach * @return Menu[] 155ade503dfSGreg Roach */ 156ade503dfSGreg Roach public function individualBoxMenu(Individual $individual): array 157ade503dfSGreg Roach { 158ade503dfSGreg Roach $menus = array_merge( 159ade503dfSGreg Roach $this->individualBoxMenuCharts($individual), 160ade503dfSGreg Roach $this->individualBoxMenuFamilyLinks($individual) 161ade503dfSGreg Roach ); 162ade503dfSGreg Roach 163ade503dfSGreg Roach return $menus; 164ade503dfSGreg Roach } 165ade503dfSGreg Roach 166ade503dfSGreg Roach /** 167ade503dfSGreg Roach * Chart links, to show in chart boxes; 168ade503dfSGreg Roach * 169ade503dfSGreg Roach * @param Individual $individual 170ade503dfSGreg Roach * 171ade503dfSGreg Roach * @return Menu[] 172ade503dfSGreg Roach */ 173ade503dfSGreg Roach public function individualBoxMenuCharts(Individual $individual): array 174ade503dfSGreg Roach { 175ade503dfSGreg Roach $menus = []; 176f39638cfSGreg Roach foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) { 177ade503dfSGreg Roach $menu = $chart->chartBoxMenu($individual); 178ade503dfSGreg Roach if ($menu) { 179ade503dfSGreg Roach $menus[] = $menu; 180ade503dfSGreg Roach } 181ade503dfSGreg Roach } 182ade503dfSGreg Roach 1830b93976aSGreg Roach usort($menus, static function (Menu $x, Menu $y): int { 184ade503dfSGreg Roach return I18N::strcasecmp($x->getLabel(), $y->getLabel()); 185ade503dfSGreg Roach }); 186ade503dfSGreg Roach 187ade503dfSGreg Roach return $menus; 188ade503dfSGreg Roach } 189ade503dfSGreg Roach 190ade503dfSGreg Roach /** 191ade503dfSGreg Roach * Family links, to show in chart boxes. 192ade503dfSGreg Roach * 193ade503dfSGreg Roach * @param Individual $individual 194ade503dfSGreg Roach * 195ade503dfSGreg Roach * @return Menu[] 196ade503dfSGreg Roach */ 197ade503dfSGreg Roach public function individualBoxMenuFamilyLinks(Individual $individual): array 198ade503dfSGreg Roach { 199ade503dfSGreg Roach $menus = []; 200ade503dfSGreg Roach 20139ca88baSGreg Roach foreach ($individual->spouseFamilies() as $family) { 202ade503dfSGreg Roach $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()); 20339ca88baSGreg Roach $spouse = $family->spouse($individual); 204ade503dfSGreg Roach if ($spouse && $spouse->canShowName()) { 20539ca88baSGreg Roach $menus[] = new Menu($spouse->fullName(), $spouse->url()); 206ade503dfSGreg Roach } 20739ca88baSGreg Roach foreach ($family->children() as $child) { 208ade503dfSGreg Roach if ($child->canShowName()) { 20939ca88baSGreg Roach $menus[] = new Menu($child->fullName(), $child->url()); 210ade503dfSGreg Roach } 211ade503dfSGreg Roach } 212ade503dfSGreg Roach } 213ade503dfSGreg Roach 214ade503dfSGreg Roach return $menus; 215ade503dfSGreg Roach } 216ade503dfSGreg Roach 217ade503dfSGreg Roach /** 218f567c3d8SGreg Roach * Generate a menu item to change the blocks on the current tree/user page. 219ade503dfSGreg Roach * 2200c8c69d4SGreg Roach * @param Tree $tree 2210c8c69d4SGreg Roach * 222ade503dfSGreg Roach * @return Menu|null 223ade503dfSGreg Roach */ 224e364afe4SGreg Roach public function menuChangeBlocks(Tree $tree): ?Menu 225ade503dfSGreg Roach { 226eb235819SGreg Roach /** @var ServerRequestInterface $request */ 2276ccdf4f0SGreg Roach $request = app(ServerRequestInterface::class); 228e6bcfa02SGreg Roach 2290d7461faSGreg Roach $route = $request->getAttribute('route'); 230eb235819SGreg Roach 231eb235819SGreg Roach if (Auth::check() && $route === 'user-page') { 232d72b284aSGreg Roach return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['tree' => $tree->name()]), 'menu-change-blocks'); 233ade503dfSGreg Roach } 234ade503dfSGreg Roach 235eb235819SGreg Roach if (Auth::isManager($tree) && $route === 'tree-page') { 236d72b284aSGreg Roach return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['tree' => $tree->name()]), 'menu-change-blocks'); 237ade503dfSGreg Roach } 238ade503dfSGreg Roach 239ade503dfSGreg Roach return null; 240ade503dfSGreg Roach } 241ade503dfSGreg Roach 242ade503dfSGreg Roach /** 243ade503dfSGreg Roach * Generate a menu item for the control panel. 244ade503dfSGreg Roach * 2450c8c69d4SGreg Roach * @param Tree $tree 2460c8c69d4SGreg Roach * 247ade503dfSGreg Roach * @return Menu|null 248ade503dfSGreg Roach */ 249e364afe4SGreg Roach public function menuControlPanel(Tree $tree): ?Menu 250ade503dfSGreg Roach { 251ade503dfSGreg Roach if (Auth::isAdmin()) { 2520c0910bfSGreg Roach return new Menu(I18N::translate('Control panel'), route(ControlPanel::class), 'menu-admin'); 253ade503dfSGreg Roach } 254ade503dfSGreg Roach 2550c8c69d4SGreg Roach if (Auth::isManager($tree)) { 2560c0910bfSGreg Roach return new Menu(I18N::translate('Control panel'), route('manage-trees'), 'menu-admin'); 257ade503dfSGreg Roach } 258ade503dfSGreg Roach 259ade503dfSGreg Roach return null; 260ade503dfSGreg Roach } 261ade503dfSGreg Roach 262ade503dfSGreg Roach /** 263ade503dfSGreg Roach * A menu to show a list of available languages. 264ade503dfSGreg Roach * 265ade503dfSGreg Roach * @return Menu|null 266ade503dfSGreg Roach */ 267e364afe4SGreg Roach public function menuLanguages(): ?Menu 268ade503dfSGreg Roach { 269ade503dfSGreg Roach $menu = new Menu(I18N::translate('Language'), '#', 'menu-language'); 270ade503dfSGreg Roach 271ade503dfSGreg Roach foreach (I18N::activeLocales() as $locale) { 272ade503dfSGreg Roach $language_tag = $locale->languageTag(); 273ade503dfSGreg Roach $class = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : ''); 274ade503dfSGreg Roach $menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [ 2757adfb8e5SGreg Roach 'data-post-url' => route(SelectLanguage::class, ['language' => $language_tag]), 276ade503dfSGreg Roach ])); 277ade503dfSGreg Roach } 278ade503dfSGreg Roach 279ade503dfSGreg Roach if (count($menu->getSubmenus()) > 1) { 280ade503dfSGreg Roach return $menu; 281ade503dfSGreg Roach } 282ade503dfSGreg Roach 283ade503dfSGreg Roach return null; 284ade503dfSGreg Roach } 285ade503dfSGreg Roach 286ade503dfSGreg Roach /** 287ade503dfSGreg Roach * A login menu option (or null if we are already logged in). 288ade503dfSGreg Roach * 289ade503dfSGreg Roach * @return Menu|null 290ade503dfSGreg Roach */ 291e364afe4SGreg Roach public function menuLogin(): ?Menu 292ade503dfSGreg Roach { 293ade503dfSGreg Roach if (Auth::check()) { 294ade503dfSGreg Roach return null; 295ade503dfSGreg Roach } 296ade503dfSGreg Roach 29786661454SGreg Roach $request = app(ServerRequestInterface::class); 29886661454SGreg Roach 299ade503dfSGreg Roach // Return to this page after login... 30091c514e5SGreg Roach $redirect = (string) $request->getUri(); 301ade503dfSGreg Roach 302ade503dfSGreg Roach // ...but switch from the tree-page to the user-page 30391c514e5SGreg Roach if ($request->getAttribute('route') === 'tree-page') { 30491c514e5SGreg Roach $tree = $request->getAttribute('tree'); 305*75964c75SGreg Roach assert($tree instanceof Tree); 30691c514e5SGreg Roach $redirect = route('user-page', ['tree' => $tree->name()]); 30791c514e5SGreg Roach } 308ade503dfSGreg Roach 30986661454SGreg Roach // Stay on the same tree page 31086661454SGreg Roach $tree = $request->getAttribute('tree'); 31191c514e5SGreg Roach $url = route(LoginPage::class, ['tree' => $tree instanceof Tree ? $tree->name() : null, 'url' => $redirect]); 31286661454SGreg Roach 31386661454SGreg Roach return new Menu(I18N::translate('Sign in'), $url, 'menu-login', ['rel' => 'nofollow']); 314ade503dfSGreg Roach } 315ade503dfSGreg Roach 316ade503dfSGreg Roach /** 317ade503dfSGreg Roach * A logout menu option (or null if we are already logged out). 318ade503dfSGreg Roach * 319ade503dfSGreg Roach * @return Menu|null 320ade503dfSGreg Roach */ 321e364afe4SGreg Roach public function menuLogout(): ?Menu 322ade503dfSGreg Roach { 323ade503dfSGreg Roach if (Auth::check()) { 3249b541e4aSGreg Roach $parameters = [ 3259b541e4aSGreg Roach 'data-post-url' => route(Logout::class), 3269b541e4aSGreg Roach 'data-reload-url' => route(HomePage::class), 3279b541e4aSGreg Roach ]; 3289b541e4aSGreg Roach 3299b541e4aSGreg Roach return new Menu(I18N::translate('Sign out'), '#', 'menu-logout', $parameters); 330ade503dfSGreg Roach } 331ade503dfSGreg Roach 332ade503dfSGreg Roach return null; 333ade503dfSGreg Roach } 334ade503dfSGreg Roach 335ade503dfSGreg Roach /** 336ade503dfSGreg Roach * A link to allow users to edit their account settings. 337ade503dfSGreg Roach * 33865aec466SGreg Roach * @param Tree|null $tree 339a49d0e3fSGreg Roach * 340a49d0e3fSGreg Roach * @return Menu 341ade503dfSGreg Roach */ 342a49d0e3fSGreg Roach public function menuMyAccount(?Tree $tree): Menu 343ade503dfSGreg Roach { 344a49d0e3fSGreg Roach $url = route(AccountEdit::class, ['tree' => $tree instanceof Tree ? $tree->name() : null]); 345ade503dfSGreg Roach 346a49d0e3fSGreg Roach return new Menu(I18N::translate('My account'), $url); 347ade503dfSGreg Roach } 348ade503dfSGreg Roach 349ade503dfSGreg Roach /** 350ade503dfSGreg Roach * A link to the user's individual record (individual.php). 351ade503dfSGreg Roach * 3520c8c69d4SGreg Roach * @param Tree $tree 3530c8c69d4SGreg Roach * 354ade503dfSGreg Roach * @return Menu|null 355ade503dfSGreg Roach */ 356e364afe4SGreg Roach public function menuMyIndividualRecord(Tree $tree): ?Menu 357ade503dfSGreg Roach { 3580c8c69d4SGreg Roach $record = Individual::getInstance($tree->getUserPreference(Auth::user(), 'gedcomid'), $tree); 359ade503dfSGreg Roach 360ade503dfSGreg Roach if ($record) { 361ade503dfSGreg Roach return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord'); 362ade503dfSGreg Roach } 363ade503dfSGreg Roach 364ade503dfSGreg Roach return null; 365ade503dfSGreg Roach } 366ade503dfSGreg Roach 367ade503dfSGreg Roach /** 368ade503dfSGreg Roach * A link to the user's personal home page. 369ade503dfSGreg Roach * 3700c8c69d4SGreg Roach * @param Tree $tree 3710c8c69d4SGreg Roach * 372ade503dfSGreg Roach * @return Menu 373ade503dfSGreg Roach */ 3740c8c69d4SGreg Roach public function menuMyPage(Tree $tree): Menu 375ade503dfSGreg Roach { 376d72b284aSGreg Roach return new Menu(I18N::translate('My page'), route('user-page', ['tree' => $tree->name()]), 'menu-mypage'); 377ade503dfSGreg Roach } 378ade503dfSGreg Roach 379ade503dfSGreg Roach /** 380ade503dfSGreg Roach * A menu for the user's personal pages. 381ade503dfSGreg Roach * 3820c8c69d4SGreg Roach * @param Tree|null $tree 3830c8c69d4SGreg Roach * 384ade503dfSGreg Roach * @return Menu|null 385ade503dfSGreg Roach */ 386e364afe4SGreg Roach public function menuMyPages(?Tree $tree): ?Menu 387ade503dfSGreg Roach { 388a49d0e3fSGreg Roach if (Auth::id()) { 389a49d0e3fSGreg Roach if ($tree instanceof Tree) { 390ade503dfSGreg Roach return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([ 3910c8c69d4SGreg Roach $this->menuMyPage($tree), 3920c8c69d4SGreg Roach $this->menuMyIndividualRecord($tree), 3930c8c69d4SGreg Roach $this->menuMyPedigree($tree), 394a49d0e3fSGreg Roach $this->menuMyAccount($tree), 3950c8c69d4SGreg Roach $this->menuControlPanel($tree), 3960c8c69d4SGreg Roach $this->menuChangeBlocks($tree), 397ade503dfSGreg Roach ])); 398ade503dfSGreg Roach } 399ade503dfSGreg Roach 400a49d0e3fSGreg Roach return $this->menuMyAccount($tree); 401a49d0e3fSGreg Roach } 402a49d0e3fSGreg Roach 403ade503dfSGreg Roach return null; 404ade503dfSGreg Roach } 405ade503dfSGreg Roach 406ade503dfSGreg Roach /** 407ade503dfSGreg Roach * A link to the user's individual record. 408ade503dfSGreg Roach * 4090c8c69d4SGreg Roach * @param Tree $tree 4100c8c69d4SGreg Roach * 411ade503dfSGreg Roach * @return Menu|null 412ade503dfSGreg Roach */ 413e364afe4SGreg Roach public function menuMyPedigree(Tree $tree): ?Menu 414ade503dfSGreg Roach { 4150c8c69d4SGreg Roach $gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid'); 416ade503dfSGreg Roach 4170c8c69d4SGreg Roach $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 4180b5fd0a6SGreg Roach ->filter(static function (ModuleInterface $module): bool { 419ade503dfSGreg Roach return $module instanceof PedigreeChartModule; 420ade503dfSGreg Roach }); 421ade503dfSGreg Roach 422ade503dfSGreg Roach if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) { 423ade503dfSGreg Roach return new Menu( 424ade503dfSGreg Roach I18N::translate('My pedigree'), 425ade503dfSGreg Roach route('pedigree', [ 426ade503dfSGreg Roach 'xref' => $gedcomid, 4279022ab66SGreg Roach 'tree' => $tree->name(), 428ade503dfSGreg Roach ]), 429ade503dfSGreg Roach 'menu-mypedigree' 430ade503dfSGreg Roach ); 431ade503dfSGreg Roach } 432ade503dfSGreg Roach 433ade503dfSGreg Roach return null; 434ade503dfSGreg Roach } 435ade503dfSGreg Roach 436ade503dfSGreg Roach /** 437ade503dfSGreg Roach * Create a pending changes menu. 438ade503dfSGreg Roach * 4390c8c69d4SGreg Roach * @param Tree|null $tree 4400c8c69d4SGreg Roach * 441ade503dfSGreg Roach * @return Menu|null 442ade503dfSGreg Roach */ 443e364afe4SGreg Roach public function menuPendingChanges(?Tree $tree): ?Menu 444ade503dfSGreg Roach { 4450c8c69d4SGreg Roach if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) { 44622e73debSGreg Roach $url = route(PendingChanges::class, [ 4479022ab66SGreg Roach 'tree' => $tree->name(), 448cf8c0692SGreg Roach 'url' => (string) app(ServerRequestInterface::class)->getUri(), 449ade503dfSGreg Roach ]); 450ade503dfSGreg Roach 451ade503dfSGreg Roach return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending'); 452ade503dfSGreg Roach } 453ade503dfSGreg Roach 454ade503dfSGreg Roach return null; 455ade503dfSGreg Roach } 456ade503dfSGreg Roach 457ade503dfSGreg Roach /** 458ade503dfSGreg Roach * Themes menu. 459ade503dfSGreg Roach * 460ade503dfSGreg Roach * @return Menu|null 461ade503dfSGreg Roach */ 462e364afe4SGreg Roach public function menuThemes(): ?Menu 463ade503dfSGreg Roach { 464b668782fSGreg Roach $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true); 465df8baf00SGreg Roach 466cab242e7SGreg Roach $current_theme = app(ModuleThemeInterface::class); 4678136679eSGreg Roach 4688136679eSGreg Roach if ($themes->count() > 1) { 4690b5fd0a6SGreg Roach $submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu { 4708136679eSGreg Roach $active = $theme->name() === $current_theme->name(); 4718136679eSGreg Roach $class = 'menu-theme-' . $theme->name() . ($active ? ' active' : ''); 4728136679eSGreg Roach 4738136679eSGreg Roach return new Menu($theme->title(), '#', $class, [ 4747adfb8e5SGreg Roach 'data-post-url' => route(SelectTheme::class, ['theme' => $theme->name()]), 475ade503dfSGreg Roach ]); 476ade503dfSGreg Roach }); 477ade503dfSGreg Roach 4788136679eSGreg Roach return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all()); 479ade503dfSGreg Roach } 480ade503dfSGreg Roach 481ade503dfSGreg Roach return null; 482ade503dfSGreg Roach } 483ade503dfSGreg Roach 484ade503dfSGreg Roach /** 485ade503dfSGreg Roach * Misecellaneous dimensions, fonts, styles, etc. 486ade503dfSGreg Roach * 487ade503dfSGreg Roach * @param string $parameter_name 488ade503dfSGreg Roach * 489ade503dfSGreg Roach * @return string|int|float 490ade503dfSGreg Roach */ 491ade503dfSGreg Roach public function parameter($parameter_name) 492ade503dfSGreg Roach { 493ade503dfSGreg Roach return ''; 494ade503dfSGreg Roach } 495ade503dfSGreg Roach 496ade503dfSGreg Roach /** 497ade503dfSGreg Roach * Generate a list of items for the main menu. 498ade503dfSGreg Roach * 4990c8c69d4SGreg Roach * @param Tree|null $tree 5000c8c69d4SGreg Roach * 501ade503dfSGreg Roach * @return Menu[] 502ade503dfSGreg Roach */ 5030c8c69d4SGreg Roach public function genealogyMenu(?Tree $tree): array 504ade503dfSGreg Roach { 5050c8c69d4SGreg Roach if ($tree === null) { 5060c8c69d4SGreg Roach return []; 5070c8c69d4SGreg Roach } 5080c8c69d4SGreg Roach 5090c8c69d4SGreg Roach return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user()) 5100b5fd0a6SGreg Roach ->map(static function (ModuleMenuInterface $menu) use ($tree): ?Menu { 5110c8c69d4SGreg Roach return $menu->getMenu($tree); 512ade503dfSGreg Roach }) 513ade503dfSGreg Roach ->filter() 514ade503dfSGreg Roach ->all(); 515ade503dfSGreg Roach } 516ade503dfSGreg Roach 517ade503dfSGreg Roach /** 5180c8c69d4SGreg Roach * Create the genealogy menu. 519ade503dfSGreg Roach * 520ade503dfSGreg Roach * @param Menu[] $menus 521ade503dfSGreg Roach * 522ade503dfSGreg Roach * @return string 523ade503dfSGreg Roach */ 5240c8c69d4SGreg Roach public function genealogyMenuContent(array $menus): string 525ade503dfSGreg Roach { 5260b5fd0a6SGreg Roach return implode('', array_map(static function (Menu $menu): string { 527ade503dfSGreg Roach return $menu->bootstrap4(); 528ade503dfSGreg Roach }, $menus)); 529ade503dfSGreg Roach } 530ade503dfSGreg Roach 531ade503dfSGreg Roach /** 532ade503dfSGreg Roach * Generate a list of items for the user menu. 533ade503dfSGreg Roach * 5340c8c69d4SGreg Roach * @param Tree|null $tree 5350c8c69d4SGreg Roach * 536ade503dfSGreg Roach * @return Menu[] 537ade503dfSGreg Roach */ 5380c8c69d4SGreg Roach public function userMenu(?Tree $tree): array 539ade503dfSGreg Roach { 540ade503dfSGreg Roach return array_filter([ 5410c8c69d4SGreg Roach $this->menuPendingChanges($tree), 5420c8c69d4SGreg Roach $this->menuMyPages($tree), 543ade503dfSGreg Roach $this->menuThemes(), 544ade503dfSGreg Roach $this->menuLanguages(), 545ade503dfSGreg Roach $this->menuLogin(), 546ade503dfSGreg Roach $this->menuLogout(), 547ade503dfSGreg Roach ]); 548ade503dfSGreg Roach } 549ade503dfSGreg Roach 550ade503dfSGreg Roach /** 551ade503dfSGreg Roach * A list of CSS files to include for this page. 552ade503dfSGreg Roach * 553ade503dfSGreg Roach * @return string[] 554ade503dfSGreg Roach */ 555ade503dfSGreg Roach public function stylesheets(): array 556ade503dfSGreg Roach { 557ade503dfSGreg Roach return []; 558ade503dfSGreg Roach } 55949a243cbSGreg Roach} 560