xref: /webtrees/app/Services/ModuleService.php (revision c81b7bf19f35fbd9d805aa3658f596ace2d433d9)
14ca7e03cSGreg Roach<?php
23976b470SGreg Roach
34ca7e03cSGreg Roach/**
44ca7e03cSGreg Roach * webtrees: online genealogy
54ca7e03cSGreg Roach * Copyright (C) 2019 webtrees development team
64ca7e03cSGreg Roach * This program is free software: you can redistribute it and/or modify
74ca7e03cSGreg Roach * it under the terms of the GNU General Public License as published by
84ca7e03cSGreg Roach * the Free Software Foundation, either version 3 of the License, or
94ca7e03cSGreg Roach * (at your option) any later version.
104ca7e03cSGreg Roach * This program is distributed in the hope that it will be useful,
114ca7e03cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
124ca7e03cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
134ca7e03cSGreg Roach * GNU General Public License for more details.
144ca7e03cSGreg Roach * You should have received a copy of the GNU General Public License
154ca7e03cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
164ca7e03cSGreg Roach */
174ca7e03cSGreg Roachdeclare(strict_types=1);
184ca7e03cSGreg Roach
194ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services;
204ca7e03cSGreg Roach
214ca7e03cSGreg Roachuse Closure;
224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Auth;
23e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
244ca7e03cSGreg Roachuse Fisharebest\Webtrees\I18N;
254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AhnentafelReportModule;
264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AlbumModule;
274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AncestorsChartModule;
284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BatchUpdateModule;
294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BingWebmasterToolsModule;
304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthDeathMarriageReportModule;
314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthReportModule;
3267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\BranchesListModule;
3309fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishMonarchs;
3409fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishPrimeMinisters;
3509fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishSocialHistory;
364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CalendarMenuModule;
374ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CemeteryReportModule;
384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CensusAssistantModule;
394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChangeReportModule;
404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsBlockModule;
414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsMenuModule;
424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CkeditorModule;
434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ClippingsCartModule;
444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CloudsTheme;
454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ColorsTheme;
464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CompactTreeChartModule;
474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ContactsFooterModule;
484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CookieWarningModule;
498d6560c4SGreg Roachuse Fisharebest\Webtrees\Module\CustomCssJsModule;
504ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DeathReportModule;
514ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyChartModule;
524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyModule;
534ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyReportModule;
544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FabTheme;
554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FactSourcesReportModule;
564ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyBookChartModule;
574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyGroupReportModule;
5867992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\FamilyListModule;
594ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyNavigatorModule;
604ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule;
614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeNewsModule;
624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule;
634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FanChartModule;
644ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule;
654ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleAnalyticsModule;
664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule;
674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HitCountFooterModule;
684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HourglassChartModule;
694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HtmlBlockModule;
704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFactsTabModule;
714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFamiliesReportModule;
7267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\IndividualListModule;
7309fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\IndividualMetadataModule;
744ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualReportModule;
754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\InteractiveTreeModule;
7602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAfrikaans;
7702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAlbanian;
7802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageArabic;
7902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBosnian;
8002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBulgarian;
8102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCatalan;
8202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseSimplified;
8302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseTraditional;
8402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCroatian;
8502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCzech;
8602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDanish;
8702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDivehi;
8802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDutch;
8902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishAustralia;
9002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain;
9102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates;
9202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEstonian;
9302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFaroese;
9402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFarsi;
9502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFinnish;
9602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrench;
9702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrenchCanada;
9802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGalician;
9902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGeorgian;
10002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGerman;
10102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGreek;
10202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHebrew;
10302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHungarian;
10402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageIcelandic;
10502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageIndonesian;
10602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageItalian;
10702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageJapanese;
10802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageJavanese;
10902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageKazhak;
11002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageKorean;
11102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLatvian;
11202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLingala;
11302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLithuanian;
11402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMalay;
11502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMaori;
11602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMarathi;
11702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNepalese;
11802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNorwegianBokmal;
11902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNorwegianNynorsk;
12002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageOccitan;
12102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePolish;
12202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePortuguese;
12302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePortugueseBrazil;
12402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageRomanian;
12502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageRussian;
12602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSerbian;
12702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSerbianLatin;
12802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSlovakian;
12902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSlovenian;
13002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSpanish;
13102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSundanese;
13202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSwahili;
13302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSwedish;
13402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTamil;
13502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTatar;
13602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageThai;
13702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTurkish;
13802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageUkranian;
13902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageVietnamese;
14002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageYiddish;
1414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LifespansChartModule;
1424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ListsMenuModule;
1434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoggedInUsersModule;
1444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoginBlockModule;
1454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MarriageReportModule;
1464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MatomoAnalyticsModule;
14767992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\MediaListModule;
1484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MediaTabModule;
1494ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MinimalTheme;
1504ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MissingFactsReportModule;
151bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
1524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
1534ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
1544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface;
1554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleFooterInterface;
156bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
1574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface;
158bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface;
15967992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\ModuleListInterface;
1604ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface;
1614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface;
1624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
1634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
164bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface;
16567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\NoteListModule;
1664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\NotesTabModule;
1674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OccupationReportModule;
1684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OnThisDayModule;
1694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeChartModule;
1704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeMapModule;
1714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeReportModule;
17267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
1734ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PlacesModule;
1744ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PoweredByWebtreesModule;
1754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RecentChangesModule;
1764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelatedIndividualsReportModule;
1774ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule;
1784ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelativesTabModule;
1794ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReportsMenuModule;
18067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\RepositoryListModule;
1814ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ResearchTaskModule;
1824ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReviewChangesModule;
1834ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SearchMenuModule;
1844ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SiteMapModule;
1854ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SlideShowModule;
18667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\SourceListModule;
1874ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SourcesTabModule;
1884ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatcounterModule;
1894ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatisticsChartModule;
1904ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StoriesModule;
1914ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ThemeSelectModule;
1924ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TimelineChartModule;
1934ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopGivenNamesModule;
1944ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopPageViewsModule;
1954ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopSurnamesModule;
1964ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule;
1974ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UpcomingAnniversariesModule;
1984ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserFavoritesModule;
1994ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserJournalModule;
2004ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserMessagesModule;
2014ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserWelcomeModule;
20209fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\USPresidents;
2034ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WebtreesTheme;
2044ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WelcomeBlockModule;
2054ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\XeneaTheme;
2064ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\YahrzeitModule;
2074ca7e03cSGreg Roachuse Fisharebest\Webtrees\Tree;
2084ca7e03cSGreg Roachuse Fisharebest\Webtrees\Webtrees;
2094ca7e03cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
2104ca7e03cSGreg Roachuse Illuminate\Support\Collection;
2114ca7e03cSGreg Roachuse Illuminate\Support\Str;
2124ca7e03cSGreg Roachuse stdClass;
2134ca7e03cSGreg Roachuse Throwable;
2144ca7e03cSGreg Roach
21571378461SGreg Roachuse function app;
21671378461SGreg Roachuse function method_exists;
21771378461SGreg Roach
2184ca7e03cSGreg Roach/**
2194ca7e03cSGreg Roach * Functions for managing and maintaining modules.
2204ca7e03cSGreg Roach */
2214ca7e03cSGreg Roachclass ModuleService
2224ca7e03cSGreg Roach{
223362b8464SGreg Roach    // Components are pieces of user-facing functionality, are managed together in the control panel.
2244ca7e03cSGreg Roach    private const COMPONENTS = [
22587cca37cSGreg Roach        ModuleAnalyticsInterface::class,
22687cca37cSGreg Roach        ModuleBlockInterface::class,
22787cca37cSGreg Roach        ModuleChartInterface::class,
22887cca37cSGreg Roach        ModuleFooterInterface::class,
22987cca37cSGreg Roach        ModuleHistoricEventsInterface::class,
23087cca37cSGreg Roach        ModuleLanguageInterface::class,
23187cca37cSGreg Roach        ModuleListInterface::class,
23287cca37cSGreg Roach        ModuleMenuInterface::class,
23387cca37cSGreg Roach        ModuleReportInterface::class,
23487cca37cSGreg Roach        ModuleSidebarInterface::class,
23587cca37cSGreg Roach        ModuleTabInterface::class,
23687cca37cSGreg Roach        ModuleThemeInterface::class,
2374ca7e03cSGreg Roach    ];
2384ca7e03cSGreg Roach
2394ca7e03cSGreg Roach    // Array keys are module names, and should match module names from earlier versions of webtrees.
2404ca7e03cSGreg Roach    private const CORE_MODULES = [
2414ca7e03cSGreg Roach        'GEDFact_assistant'       => CensusAssistantModule::class,
2424ca7e03cSGreg Roach        'ahnentafel_report'       => AhnentafelReportModule::class,
2434ca7e03cSGreg Roach        'ancestors_chart'         => AncestorsChartModule::class,
2444ca7e03cSGreg Roach        'batch_update'            => BatchUpdateModule::class,
2454ca7e03cSGreg Roach        'bdm_report'              => BirthDeathMarriageReportModule::class,
2464ca7e03cSGreg Roach        'bing-webmaster-tools'    => BingWebmasterToolsModule::class,
2474ca7e03cSGreg Roach        'birth_report'            => BirthReportModule::class,
24867992b6aSRichard Cissee        'branches_list'           => BranchesListModule::class,
24909fbf3e5SGreg Roach        'british-monarchs'        => BritishMonarchs::class,
25009fbf3e5SGreg Roach        'british-prime-ministers' => BritishPrimeMinisters::class,
25109fbf3e5SGreg Roach        'british-social-history'  => BritishSocialHistory::class,
2524ca7e03cSGreg Roach        'calendar-menu'           => CalendarMenuModule::class,
2534ca7e03cSGreg Roach        'cemetery_report'         => CemeteryReportModule::class,
2544ca7e03cSGreg Roach        'change_report'           => ChangeReportModule::class,
2554ca7e03cSGreg Roach        'charts'                  => ChartsBlockModule::class,
2564ca7e03cSGreg Roach        'charts-menu'             => ChartsMenuModule::class,
2574ca7e03cSGreg Roach        'ckeditor'                => CkeditorModule::class,
2584ca7e03cSGreg Roach        'clippings'               => ClippingsCartModule::class,
2594ca7e03cSGreg Roach        'clouds'                  => CloudsTheme::class,
2604ca7e03cSGreg Roach        'colors'                  => ColorsTheme::class,
2614ca7e03cSGreg Roach        'compact-chart'           => CompactTreeChartModule::class,
2624ca7e03cSGreg Roach        'contact-links'           => ContactsFooterModule::class,
2634ca7e03cSGreg Roach        'cookie-warning'          => CookieWarningModule::class,
2648d6560c4SGreg Roach        'custom-css-js'           => CustomCssJsModule::class,
2654ca7e03cSGreg Roach        'death_report'            => DeathReportModule::class,
2664ca7e03cSGreg Roach        'descendancy'             => DescendancyModule::class,
2674ca7e03cSGreg Roach        'descendancy_chart'       => DescendancyChartModule::class,
2684ca7e03cSGreg Roach        'descendancy_report'      => DescendancyReportModule::class,
2698eaf8709SGreg Roach        'extra_info'              => IndividualMetadataModule::class,
2704ca7e03cSGreg Roach        'fab'                     => FabTheme::class,
2714ca7e03cSGreg Roach        'fact_sources'            => FactSourcesReportModule::class,
2724ca7e03cSGreg Roach        'family_book_chart'       => FamilyBookChartModule::class,
2734ca7e03cSGreg Roach        'family_group_report'     => FamilyGroupReportModule::class,
27467992b6aSRichard Cissee        'family_list'             => FamilyListModule::class,
2754ca7e03cSGreg Roach        'family_nav'              => FamilyNavigatorModule::class,
2764ca7e03cSGreg Roach        'fan_chart'               => FanChartModule::class,
2774ca7e03cSGreg Roach        'faq'                     => FrequentlyAskedQuestionsModule::class,
2784ca7e03cSGreg Roach        'gedcom_block'            => WelcomeBlockModule::class,
2794ca7e03cSGreg Roach        'gedcom_favorites'        => FamilyTreeFavoritesModule::class,
2804ca7e03cSGreg Roach        'gedcom_news'             => FamilyTreeNewsModule::class,
2814ca7e03cSGreg Roach        'gedcom_stats'            => FamilyTreeStatisticsModule::class,
2824ca7e03cSGreg Roach        'google-analytics'        => GoogleAnalyticsModule::class,
2834ca7e03cSGreg Roach        'google-webmaster-tools'  => GoogleWebmasterToolsModule::class,
2844ca7e03cSGreg Roach        'hit-counter'             => HitCountFooterModule::class,
2854ca7e03cSGreg Roach        'hourglass_chart'         => HourglassChartModule::class,
2864ca7e03cSGreg Roach        'html'                    => HtmlBlockModule::class,
2874ca7e03cSGreg Roach        'individual_ext_report'   => IndividualFamiliesReportModule::class,
28867992b6aSRichard Cissee        'individual_list'         => IndividualListModule::class,
2894ca7e03cSGreg Roach        'individual_report'       => IndividualReportModule::class,
29002086832SGreg Roach        'language-af'             => LanguageAfrikaans::class,
29102086832SGreg Roach        'language-ar'             => LanguageArabic::class,
29202086832SGreg Roach        'language-bs'             => LanguageBosnian::class,
29302086832SGreg Roach        'language-bu'             => LanguageBulgarian::class,
29402086832SGreg Roach        'language-ca'             => LanguageCatalan::class,
29502086832SGreg Roach        'language-cs'             => LanguageCzech::class,
29602086832SGreg Roach        'language-da'             => LanguageDanish::class,
29702086832SGreg Roach        'language-de'             => LanguageGerman::class,
29802086832SGreg Roach        'language-dv'             => LanguageDivehi::class,
29902086832SGreg Roach        'language-el'             => LanguageGreek::class,
30002086832SGreg Roach        'language-en-AU'          => LanguageEnglishAustralia::class,
30102086832SGreg Roach        'language-en-GB'          => LanguageEnglishGreatBritain::class,
30202086832SGreg Roach        'language-en-US'          => LanguageEnglishUnitedStates::class,
30302086832SGreg Roach        'language-es'             => LanguageSpanish::class,
30402086832SGreg Roach        'language-et'             => LanguageEstonian::class,
30502086832SGreg Roach        'language-fa'             => LanguageFarsi::class,
30602086832SGreg Roach        'language-fi'             => LanguageFinnish::class,
30702086832SGreg Roach        'language-fo'             => LanguageFaroese::class,
30802086832SGreg Roach        'language-fr'             => LanguageFrench::class,
30902086832SGreg Roach        'language-fr-CA'          => LanguageFrenchCanada::class,
31002086832SGreg Roach        'language-gl'             => LanguageGalician::class,
31102086832SGreg Roach        'language-he'             => LanguageHebrew::class,
31202086832SGreg Roach        'language-hr'             => LanguageCroatian::class,
31302086832SGreg Roach        'language-hu'             => LanguageHungarian::class,
31402086832SGreg Roach        'language-id'             => LanguageIndonesian::class,
31502086832SGreg Roach        'language-is'             => LanguageIcelandic::class,
31602086832SGreg Roach        'language-it'             => LanguageItalian::class,
31702086832SGreg Roach        'language-ja'             => LanguageJapanese::class,
31802086832SGreg Roach        'language-jv'             => LanguageJavanese::class,
31902086832SGreg Roach        'language-ka'             => LanguageGeorgian::class,
32002086832SGreg Roach        'language-kk'             => LanguageKazhak::class,
32102086832SGreg Roach        'language-ko'             => LanguageKorean::class,
32202086832SGreg Roach        'language-ln'             => LanguageLingala::class,
32302086832SGreg Roach        'language-lt'             => LanguageLithuanian::class,
32402086832SGreg Roach        'language-lv'             => LanguageLatvian::class,
32502086832SGreg Roach        'language-mi'             => LanguageMaori::class,
32602086832SGreg Roach        'language-mr'             => LanguageMarathi::class,
32702086832SGreg Roach        'language-ms'             => LanguageMalay::class,
32802086832SGreg Roach        'language-nb'             => LanguageNorwegianBokmal::class,
32902086832SGreg Roach        'language-ne'             => LanguageNepalese::class,
33002086832SGreg Roach        'language-nl'             => LanguageDutch::class,
33102086832SGreg Roach        'language-nn'             => LanguageNorwegianNynorsk::class,
33202086832SGreg Roach        'language-oc'             => LanguageOccitan::class,
33302086832SGreg Roach        'language-pl'             => LanguagePolish::class,
33402086832SGreg Roach        'language-pt'             => LanguagePortuguese::class,
33502086832SGreg Roach        'language-pt-BR'          => LanguagePortugueseBrazil::class,
33602086832SGreg Roach        'language-ro'             => LanguageRomanian::class,
33702086832SGreg Roach        'language-ru'             => LanguageRussian::class,
33802086832SGreg Roach        'language-sk'             => LanguageSlovakian::class,
33902086832SGreg Roach        'language-sl'             => LanguageSlovenian::class,
34002086832SGreg Roach        'language-sq'             => LanguageAlbanian::class,
34102086832SGreg Roach        'language-sr'             => LanguageSerbian::class,
34202086832SGreg Roach        'language-sr-Latn'        => LanguageSerbianLatin::class,
34302086832SGreg Roach        'language-su'             => LanguageSundanese::class,
34402086832SGreg Roach        'language-sv'             => LanguageSwedish::class,
34502086832SGreg Roach        'language-sw'             => LanguageSwahili::class,
34602086832SGreg Roach        'language-ta'             => LanguageTamil::class,
34702086832SGreg Roach        'language-th'             => LanguageThai::class,
34802086832SGreg Roach        'language-tr'             => LanguageTurkish::class,
34902086832SGreg Roach        'language-tt'             => LanguageTatar::class,
35002086832SGreg Roach        'language-uk'             => LanguageUkranian::class,
35102086832SGreg Roach        'language-vi'             => LanguageVietnamese::class,
35202086832SGreg Roach        'language-yi'             => LanguageYiddish::class,
35302086832SGreg Roach        'language-zh-Hans'        => LanguageChineseSimplified::class,
35402086832SGreg Roach        'language-zh-Hant'        => LanguageChineseTraditional::class,
3554ca7e03cSGreg Roach        'lifespans_chart'         => LifespansChartModule::class,
3564ca7e03cSGreg Roach        'lightbox'                => AlbumModule::class,
3574ca7e03cSGreg Roach        'lists-menu'              => ListsMenuModule::class,
3584ca7e03cSGreg Roach        'logged_in'               => LoggedInUsersModule::class,
3594ca7e03cSGreg Roach        'login_block'             => LoginBlockModule::class,
3604ca7e03cSGreg Roach        'marriage_report'         => MarriageReportModule::class,
3614ca7e03cSGreg Roach        'matomo-analytics'        => MatomoAnalyticsModule::class,
3624ca7e03cSGreg Roach        'media'                   => MediaTabModule::class,
36367992b6aSRichard Cissee        'media_list'              => MediaListModule::class,
3644ca7e03cSGreg Roach        'minimal'                 => MinimalTheme::class,
3654ca7e03cSGreg Roach        'missing_facts_report'    => MissingFactsReportModule::class,
3664ca7e03cSGreg Roach        'notes'                   => NotesTabModule::class,
36767992b6aSRichard Cissee        'note_list'               => NoteListModule::class,
3684ca7e03cSGreg Roach        'occupation_report'       => OccupationReportModule::class,
3694ca7e03cSGreg Roach        'pedigree-map'            => PedigreeMapModule::class,
3704ca7e03cSGreg Roach        'pedigree_chart'          => PedigreeChartModule::class,
3714ca7e03cSGreg Roach        'pedigree_report'         => PedigreeReportModule::class,
3724ca7e03cSGreg Roach        'personal_facts'          => IndividualFactsTabModule::class,
3734ca7e03cSGreg Roach        'places'                  => PlacesModule::class,
37467992b6aSRichard Cissee        'places_list'             => PlaceHierarchyListModule::class,
3754ca7e03cSGreg Roach        'powered-by-webtrees'     => PoweredByWebtreesModule::class,
3764ca7e03cSGreg Roach        'random_media'            => SlideShowModule::class,
3774ca7e03cSGreg Roach        'recent_changes'          => RecentChangesModule::class,
3784ca7e03cSGreg Roach        'relationships_chart'     => RelationshipsChartModule::class,
3794ca7e03cSGreg Roach        'relative_ext_report'     => RelatedIndividualsReportModule::class,
3804ca7e03cSGreg Roach        'relatives'               => RelativesTabModule::class,
3814ca7e03cSGreg Roach        'reports-menu'            => ReportsMenuModule::class,
38267992b6aSRichard Cissee        'repository_list'         => RepositoryListModule::class,
3834ca7e03cSGreg Roach        'review_changes'          => ReviewChangesModule::class,
3844ca7e03cSGreg Roach        'search-menu'             => SearchMenuModule::class,
3854ca7e03cSGreg Roach        'sitemap'                 => SiteMapModule::class,
38667992b6aSRichard Cissee        'source_list'             => SourceListModule::class,
3874ca7e03cSGreg Roach        'sources_tab'             => SourcesTabModule::class,
3884ca7e03cSGreg Roach        'statcounter'             => StatcounterModule::class,
3894ca7e03cSGreg Roach        'statistics_chart'        => StatisticsChartModule::class,
3904ca7e03cSGreg Roach        'stories'                 => StoriesModule::class,
3914ca7e03cSGreg Roach        'theme_select'            => ThemeSelectModule::class,
3924ca7e03cSGreg Roach        'timeline_chart'          => TimelineChartModule::class,
3934ca7e03cSGreg Roach        'todays_events'           => OnThisDayModule::class,
3944ca7e03cSGreg Roach        'todo'                    => ResearchTaskModule::class,
3954ca7e03cSGreg Roach        'top10_givnnames'         => TopGivenNamesModule::class,
3964ca7e03cSGreg Roach        'top10_pageviews'         => TopPageViewsModule::class,
3974ca7e03cSGreg Roach        'top10_surnames'          => TopSurnamesModule::class,
3984ca7e03cSGreg Roach        'tree'                    => InteractiveTreeModule::class,
3994ca7e03cSGreg Roach        'trees-menu'              => TreesMenuModule::class,
4004ca7e03cSGreg Roach        'upcoming_events'         => UpcomingAnniversariesModule::class,
40109fbf3e5SGreg Roach        'us-presidents'           => USPresidents::class,
4024ca7e03cSGreg Roach        'user_blog'               => UserJournalModule::class,
4034ca7e03cSGreg Roach        'user_favorites'          => UserFavoritesModule::class,
4044ca7e03cSGreg Roach        'user_messages'           => UserMessagesModule::class,
4054ca7e03cSGreg Roach        'user_welcome'            => UserWelcomeModule::class,
4064ca7e03cSGreg Roach        'webtrees'                => WebtreesTheme::class,
4074ca7e03cSGreg Roach        'xenea'                   => XeneaTheme::class,
4084ca7e03cSGreg Roach        'yahrzeit'                => YahrzeitModule::class,
4094ca7e03cSGreg Roach    ];
4104ca7e03cSGreg Roach
4114ca7e03cSGreg Roach    /**
412dedcf571SGreg Roach     * A function to convert modules into their titles - to create option lists, etc.
413dedcf571SGreg Roach     *
414dedcf571SGreg Roach     * @return Closure
415dedcf571SGreg Roach     */
416dedcf571SGreg Roach    public function titleMapper(): Closure
417dedcf571SGreg Roach    {
4186c2179e2SGreg Roach        return static function (ModuleInterface $module): string {
419dedcf571SGreg Roach            return $module->title();
420dedcf571SGreg Roach        };
421dedcf571SGreg Roach    }
422dedcf571SGreg Roach
423dedcf571SGreg Roach    /**
4244ca7e03cSGreg Roach     * Modules which (a) provide a specific function and (b) we have permission to see.
4254ca7e03cSGreg Roach     *
42687cca37cSGreg Roach     * @param string        $interface
4274ca7e03cSGreg Roach     * @param Tree          $tree
428e5a6b4d4SGreg Roach     * @param UserInterface $user
4294ca7e03cSGreg Roach     *
43054c7f8dfSGreg Roach     * @return Collection
4314ca7e03cSGreg Roach     */
43287cca37cSGreg Roach    public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection
4334ca7e03cSGreg Roach    {
434b5979037SGreg Roach        return $this->findByInterface($interface, false, true)
4350b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module) use ($interface, $tree, $user): bool {
43687cca37cSGreg Roach                return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user);
4374ca7e03cSGreg Roach            });
4384ca7e03cSGreg Roach    }
4394ca7e03cSGreg Roach
4404ca7e03cSGreg Roach    /**
4414ca7e03cSGreg Roach     * All modules which provide a specific function.
4424ca7e03cSGreg Roach     *
4434ca7e03cSGreg Roach     * @param string $interface
4444ca7e03cSGreg Roach     * @param bool   $include_disabled
445b5979037SGreg Roach     * @param bool   $sort
4464ca7e03cSGreg Roach     *
44754c7f8dfSGreg Roach     * @return Collection
4484ca7e03cSGreg Roach     */
449b5979037SGreg Roach    public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
4504ca7e03cSGreg Roach    {
4519d627a9eSGreg Roach        $modules = $this->all($include_disabled)
4529d627a9eSGreg Roach            ->filter($this->interfaceFilter($interface));
4534ca7e03cSGreg Roach
4544ca7e03cSGreg Roach        switch ($interface) {
4554ca7e03cSGreg Roach            case ModuleFooterInterface::class:
456bf57b580SGreg Roach                return $modules->sort($this->footerSorter());
4574ca7e03cSGreg Roach
4584ca7e03cSGreg Roach            case ModuleMenuInterface::class:
459bf57b580SGreg Roach                return $modules->sort($this->menuSorter());
4604ca7e03cSGreg Roach
4614ca7e03cSGreg Roach            case ModuleSidebarInterface::class:
462bf57b580SGreg Roach                return $modules->sort($this->sidebarSorter());
4634ca7e03cSGreg Roach
4644ca7e03cSGreg Roach            case ModuleTabInterface::class:
465bf57b580SGreg Roach                return $modules->sort($this->tabSorter());
466b5979037SGreg Roach
467b5979037SGreg Roach            default:
468b5979037SGreg Roach                if ($sort) {
469b5979037SGreg Roach                    return $modules->sort($this->moduleSorter());
4704ca7e03cSGreg Roach                }
4714ca7e03cSGreg Roach
4724ca7e03cSGreg Roach                return $modules;
4734ca7e03cSGreg Roach        }
474b5979037SGreg Roach    }
4754ca7e03cSGreg Roach
4764ca7e03cSGreg Roach    /**
4778d6560c4SGreg Roach     * All modules.
4788d6560c4SGreg Roach     *
4798d6560c4SGreg Roach     * @param bool $include_disabled
4808d6560c4SGreg Roach     *
4818d6560c4SGreg Roach     * @return Collection
4828d6560c4SGreg Roach     */
4838d6560c4SGreg Roach    public function all(bool $include_disabled = false): Collection
4848d6560c4SGreg Roach    {
4858d6560c4SGreg Roach        return app('cache.array')->rememberForever('all_modules', function (): Collection {
4868d6560c4SGreg Roach            // Modules have a default status, order etc.
4878d6560c4SGreg Roach            // We can override these from database settings.
4888d6560c4SGreg Roach            $module_info = DB::table('module')
4898d6560c4SGreg Roach                ->get()
4900b5fd0a6SGreg Roach                ->mapWithKeys(static function (stdClass $row): array {
4918d6560c4SGreg Roach                    return [$row->module_name => $row];
4928d6560c4SGreg Roach                });
4938d6560c4SGreg Roach
4948d6560c4SGreg Roach            return $this->coreModules()
4958d6560c4SGreg Roach                ->merge($this->customModules())
4960b5fd0a6SGreg Roach                ->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface {
4978d6560c4SGreg Roach                    $info = $module_info->get($module->name());
4988d6560c4SGreg Roach
4998d6560c4SGreg Roach                    if ($info instanceof stdClass) {
5008d6560c4SGreg Roach                        $module->setEnabled($info->status === 'enabled');
5018d6560c4SGreg Roach
5028d6560c4SGreg Roach                        if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
5038d6560c4SGreg Roach                            $module->setFooterOrder((int) $info->footer_order);
5048d6560c4SGreg Roach                        }
5058d6560c4SGreg Roach
5068d6560c4SGreg Roach                        if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
5078d6560c4SGreg Roach                            $module->setMenuOrder((int) $info->menu_order);
5088d6560c4SGreg Roach                        }
5098d6560c4SGreg Roach
5108d6560c4SGreg Roach                        if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
5118d6560c4SGreg Roach                            $module->setSidebarOrder((int) $info->sidebar_order);
5128d6560c4SGreg Roach                        }
5138d6560c4SGreg Roach
5148d6560c4SGreg Roach                        if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
5158d6560c4SGreg Roach                            $module->setTabOrder((int) $info->tab_order);
5168d6560c4SGreg Roach                        }
5178d6560c4SGreg Roach                    } else {
5188d6560c4SGreg Roach                        $module->setEnabled($module->isEnabledByDefault());
5198d6560c4SGreg Roach
5208d6560c4SGreg Roach                        DB::table('module')->insert([
5218d6560c4SGreg Roach                            'module_name' => $module->name(),
5228d6560c4SGreg Roach                            'status'      => $module->isEnabled() ? 'enabled' : 'disabled',
5238d6560c4SGreg Roach                        ]);
5248d6560c4SGreg Roach                    }
5258d6560c4SGreg Roach
5268d6560c4SGreg Roach                    return $module;
5278d6560c4SGreg Roach                });
5288d6560c4SGreg Roach        })->filter($this->enabledFilter($include_disabled));
5298d6560c4SGreg Roach    }
5308d6560c4SGreg Roach
5318d6560c4SGreg Roach    /**
5328d6560c4SGreg Roach     * All core modules in the system.
5338d6560c4SGreg Roach     *
5348d6560c4SGreg Roach     * @return Collection
5358d6560c4SGreg Roach     */
5368d6560c4SGreg Roach    private function coreModules(): Collection
5378d6560c4SGreg Roach    {
5388d6560c4SGreg Roach        return Collection::make(self::CORE_MODULES)
5390b5fd0a6SGreg Roach            ->map(static function (string $class, string $name): ModuleInterface {
5408d6560c4SGreg Roach                $module = app($class);
5418d6560c4SGreg Roach
5428d6560c4SGreg Roach                $module->setName($name);
5438d6560c4SGreg Roach
5448d6560c4SGreg Roach                return $module;
5458d6560c4SGreg Roach            });
5468d6560c4SGreg Roach    }
5478d6560c4SGreg Roach
5488d6560c4SGreg Roach    /**
5498d6560c4SGreg Roach     * All custom modules in the system.  Custom modules are defined in modules_v4/
5508d6560c4SGreg Roach     *
5518d6560c4SGreg Roach     * @return Collection
5528d6560c4SGreg Roach     */
5538d6560c4SGreg Roach    private function customModules(): Collection
5548d6560c4SGreg Roach    {
555f397d0fdSGreg Roach        $pattern   = Webtrees::MODULES_DIR . '*/module.php';
5568d6560c4SGreg Roach        $filenames = glob($pattern, GLOB_NOSORT);
5578d6560c4SGreg Roach
5588d6560c4SGreg Roach        return Collection::make($filenames)
5590b5fd0a6SGreg Roach            ->filter(static function (string $filename): bool {
5608d6560c4SGreg Roach                // Special characters will break PHP variable names.
5618d6560c4SGreg Roach                // This also allows us to ignore modules called "foo.example" and "foo.disable"
5628d6560c4SGreg Roach                $module_name = basename(dirname($filename));
5638d6560c4SGreg Roach
5648d6560c4SGreg Roach                return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30;
5658d6560c4SGreg Roach            })
5660b5fd0a6SGreg Roach            ->map(static function (string $filename): ?ModuleCustomInterface {
5678d6560c4SGreg Roach                try {
5688d6560c4SGreg Roach                    $module = self::load($filename);
5698d6560c4SGreg Roach
5708d6560c4SGreg Roach                    if ($module instanceof ModuleCustomInterface) {
5718d6560c4SGreg Roach                        $module_name = '_' . basename(dirname($filename)) . '_';
5728d6560c4SGreg Roach
5738d6560c4SGreg Roach                        $module->setName($module_name);
5748d6560c4SGreg Roach                    } else {
5758d6560c4SGreg Roach                        return null;
5768d6560c4SGreg Roach                    }
5778d6560c4SGreg Roach
5788d6560c4SGreg Roach                    return $module;
5798d6560c4SGreg Roach                } catch (Throwable $ex) {
5808d6560c4SGreg Roach                    // It would be nice to show this error in a flash-message or similar, but the framework
5818d6560c4SGreg Roach                    // has not yet been initialised so we have no themes, languages, sessions, etc.
5828d6560c4SGreg Roach                    throw $ex;
5838d6560c4SGreg Roach                }
5848d6560c4SGreg Roach            })
5858d6560c4SGreg Roach            ->filter()
5860b5fd0a6SGreg Roach            ->mapWithKeys(static function (ModuleCustomInterface $module): array {
5878d6560c4SGreg Roach                return [$module->name() => $module];
5888d6560c4SGreg Roach            });
5898d6560c4SGreg Roach    }
5908d6560c4SGreg Roach
5918d6560c4SGreg Roach    /**
59202086832SGreg Roach     * During setup, we'll need access to some languages.
59302086832SGreg Roach     *
59402086832SGreg Roach     * @return Collection
59502086832SGreg Roach     */
59602086832SGreg Roach    public function setupLanguages(): Collection
59702086832SGreg Roach    {
59802086832SGreg Roach        return $this->coreModules()
5990b93976aSGreg Roach            ->filter(static function (ModuleInterface $module): bool {
60002086832SGreg Roach                return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault();
60102086832SGreg Roach            })
6020b93976aSGreg Roach            ->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y): int {
603c116a5ccSGreg Roach                return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable();
604c116a5ccSGreg Roach            });
60502086832SGreg Roach    }
60602086832SGreg Roach
60702086832SGreg Roach    /**
6088d6560c4SGreg Roach     * Load a module in a static scope, to prevent it from modifying local or object variables.
6098d6560c4SGreg Roach     *
6108d6560c4SGreg Roach     * @param string $filename
6118d6560c4SGreg Roach     *
6128d6560c4SGreg Roach     * @return mixed
6138d6560c4SGreg Roach     */
6148d6560c4SGreg Roach    private static function load(string $filename)
6158d6560c4SGreg Roach    {
6168d6560c4SGreg Roach        return include $filename;
6178d6560c4SGreg Roach    }
6188d6560c4SGreg Roach
6198d6560c4SGreg Roach    /**
6208d6560c4SGreg Roach     * A function filter modules by enabled/disabled
6218d6560c4SGreg Roach     *
6228d6560c4SGreg Roach     * @param bool $include_disabled
6238d6560c4SGreg Roach     *
6248d6560c4SGreg Roach     * @return Closure
6258d6560c4SGreg Roach     */
6268d6560c4SGreg Roach    private function enabledFilter(bool $include_disabled): Closure
6278d6560c4SGreg Roach    {
6286c2179e2SGreg Roach        return static function (ModuleInterface $module) use ($include_disabled): bool {
6298d6560c4SGreg Roach            return $include_disabled || $module->isEnabled();
6308d6560c4SGreg Roach        };
6318d6560c4SGreg Roach    }
6328d6560c4SGreg Roach
6338d6560c4SGreg Roach    /**
6348d6560c4SGreg Roach     * A function filter modules by type
6358d6560c4SGreg Roach     *
6368d6560c4SGreg Roach     * @param string $interface
6378d6560c4SGreg Roach     *
6388d6560c4SGreg Roach     * @return Closure
6398d6560c4SGreg Roach     */
6408d6560c4SGreg Roach    private function interfaceFilter(string $interface): Closure
6418d6560c4SGreg Roach    {
6426c2179e2SGreg Roach        return static function (ModuleInterface $module) use ($interface): bool {
6438d6560c4SGreg Roach            return $module instanceof $interface;
6448d6560c4SGreg Roach        };
6458d6560c4SGreg Roach    }
6468d6560c4SGreg Roach
6478d6560c4SGreg Roach    /**
6488d6560c4SGreg Roach     * A function to sort footers
6498d6560c4SGreg Roach     *
6508d6560c4SGreg Roach     * @return Closure
6518d6560c4SGreg Roach     */
6528d6560c4SGreg Roach    private function footerSorter(): Closure
6538d6560c4SGreg Roach    {
6546c2179e2SGreg Roach        return static function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
6558d6560c4SGreg Roach            return $x->getFooterOrder() <=> $y->getFooterOrder();
6568d6560c4SGreg Roach        };
6578d6560c4SGreg Roach    }
6588d6560c4SGreg Roach
6598d6560c4SGreg Roach    /**
6608d6560c4SGreg Roach     * A function to sort menus
6618d6560c4SGreg Roach     *
6628d6560c4SGreg Roach     * @return Closure
6638d6560c4SGreg Roach     */
6648d6560c4SGreg Roach    private function menuSorter(): Closure
6658d6560c4SGreg Roach    {
6666c2179e2SGreg Roach        return static function (ModuleMenuInterface $x, ModuleMenuInterface $y): int {
6678d6560c4SGreg Roach            return $x->getMenuOrder() <=> $y->getMenuOrder();
6688d6560c4SGreg Roach        };
6698d6560c4SGreg Roach    }
6708d6560c4SGreg Roach
6718d6560c4SGreg Roach    /**
6728d6560c4SGreg Roach     * A function to sort menus
6738d6560c4SGreg Roach     *
6748d6560c4SGreg Roach     * @return Closure
6758d6560c4SGreg Roach     */
6768d6560c4SGreg Roach    private function sidebarSorter(): Closure
6778d6560c4SGreg Roach    {
6786c2179e2SGreg Roach        return static function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int {
6798d6560c4SGreg Roach            return $x->getSidebarOrder() <=> $y->getSidebarOrder();
6808d6560c4SGreg Roach        };
6818d6560c4SGreg Roach    }
6828d6560c4SGreg Roach
6838d6560c4SGreg Roach    /**
6848d6560c4SGreg Roach     * A function to sort menus
6858d6560c4SGreg Roach     *
6868d6560c4SGreg Roach     * @return Closure
6878d6560c4SGreg Roach     */
6888d6560c4SGreg Roach    private function tabSorter(): Closure
6898d6560c4SGreg Roach    {
6906c2179e2SGreg Roach        return static function (ModuleTabInterface $x, ModuleTabInterface $y): int {
6918d6560c4SGreg Roach            return $x->getTabOrder() <=> $y->getTabOrder();
6928d6560c4SGreg Roach        };
6938d6560c4SGreg Roach    }
6948d6560c4SGreg Roach
6958d6560c4SGreg Roach    /**
69602086832SGreg Roach     * A function to sort modules by name.
69702086832SGreg Roach     *
69802086832SGreg Roach     * Languages have a "sortable" name, so that "British English" sorts as "English, British".
69902086832SGreg Roach     * This provides a more natural order in the language menu.
7008d6560c4SGreg Roach     *
7018d6560c4SGreg Roach     * @return Closure
7028d6560c4SGreg Roach     */
7038d6560c4SGreg Roach    private function moduleSorter(): Closure
7048d6560c4SGreg Roach    {
7056c2179e2SGreg Roach        return static function (ModuleInterface $x, ModuleInterface $y): int {
70602086832SGreg Roach            $title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title();
70702086832SGreg Roach            $title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title();
70802086832SGreg Roach
70902086832SGreg Roach            return I18N::strcasecmp($title1, $title2);
7108d6560c4SGreg Roach        };
7118d6560c4SGreg Roach    }
7128d6560c4SGreg Roach
7138d6560c4SGreg Roach    /**
7144ca7e03cSGreg Roach     * Find a specified module, if it is currently active.
7154ca7e03cSGreg Roach     *
7164ca7e03cSGreg Roach     * @param string $module_name
717321a89daSGreg Roach     * @param bool   $include_disabled
7184ca7e03cSGreg Roach     *
7194ca7e03cSGreg Roach     * @return ModuleInterface|null
7204ca7e03cSGreg Roach     */
721321a89daSGreg Roach    public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
7224ca7e03cSGreg Roach    {
7239d627a9eSGreg Roach        return $this->all($include_disabled)
7240797053bSGreg Roach            ->first(static function (ModuleInterface $module) use ($module_name): bool {
725321a89daSGreg Roach                return $module->name() === $module_name;
7260797053bSGreg Roach            });
7274ca7e03cSGreg Roach    }
728bf57b580SGreg Roach
729bf57b580SGreg Roach    /**
730bf57b580SGreg Roach     * Configuration settings are available through the various "module component" pages.
731bf57b580SGreg Roach     * For modules that do not provide a component, we need to list them separately.
732bf57b580SGreg Roach     *
73309fbf3e5SGreg Roach     * @param bool $include_disabled
73409fbf3e5SGreg Roach     *
73554c7f8dfSGreg Roach     * @return Collection
736bf57b580SGreg Roach     */
73709fbf3e5SGreg Roach    public function otherModules(bool $include_disabled = false): Collection
738bf57b580SGreg Roach    {
739abafa13cSGreg Roach        return $this->findByInterface(ModuleInterface::class, $include_disabled, true)
7400b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module): bool {
741bf57b580SGreg Roach                foreach (self::COMPONENTS as $interface) {
742bf57b580SGreg Roach                    if ($module instanceof $interface) {
743bf57b580SGreg Roach                        return false;
744bf57b580SGreg Roach                    }
745bf57b580SGreg Roach                }
746bf57b580SGreg Roach
747bf57b580SGreg Roach                return true;
748bf57b580SGreg Roach            });
749bf57b580SGreg Roach    }
750bf57b580SGreg Roach
751bf57b580SGreg Roach    /**
752bf57b580SGreg Roach     * Generate a list of module names which exist in the database but not on disk.
753bf57b580SGreg Roach     *
75454c7f8dfSGreg Roach     * @return Collection
755bf57b580SGreg Roach     */
756bf57b580SGreg Roach    public function deletedModules(): Collection
757bf57b580SGreg Roach    {
758bf57b580SGreg Roach        $database_modules = DB::table('module')->pluck('module_name');
759bf57b580SGreg Roach
760d5d58984SGreg Roach        $disk_modules = $this->all(true)
7610b5fd0a6SGreg Roach            ->map(static function (ModuleInterface $module): string {
762bf57b580SGreg Roach                return $module->name();
763bf57b580SGreg Roach            });
764bf57b580SGreg Roach
765bf57b580SGreg Roach        return $database_modules->diff($disk_modules);
766bf57b580SGreg Roach    }
76771378461SGreg Roach
76871378461SGreg Roach    /**
76971378461SGreg Roach     * Boot all the modules.
77071378461SGreg Roach     *
77171378461SGreg Roach     * @param ModuleThemeInterface $current_theme
77271378461SGreg Roach     */
773*c81b7bf1SGreg Roach    public function bootModules(ModuleThemeInterface $current_theme): void
774*c81b7bf1SGreg Roach    {
77571378461SGreg Roach        $bootable_modules = $this->all()->filter(static function (ModuleInterface $module) {
77671378461SGreg Roach            return method_exists($module, 'boot');
77771378461SGreg Roach        });
77871378461SGreg Roach
77971378461SGreg Roach        foreach ($bootable_modules as $module) {
78071378461SGreg Roach            // Only bootstrap the current theme.
78171378461SGreg Roach            if ($module instanceof ModuleThemeInterface && $module !== $current_theme) {
78271378461SGreg Roach                continue;
78371378461SGreg Roach            }
78471378461SGreg Roach
78571378461SGreg Roach            app()->dispatch($module, 'boot');
78671378461SGreg Roach        }
78771378461SGreg Roach    }
7884ca7e03cSGreg Roach}
789