xref: /webtrees/app/Services/ModuleService.php (revision 5bc7939cce6be037a822f50e9745ac9406a0b5ae)
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 */
17fcfa147eSGreg Roach
184ca7e03cSGreg Roachdeclare(strict_types=1);
194ca7e03cSGreg Roach
204ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services;
214ca7e03cSGreg Roach
224ca7e03cSGreg Roachuse Closure;
234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Auth;
24e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
254ca7e03cSGreg Roachuse Fisharebest\Webtrees\I18N;
26*5bc7939cSBenuse Fisharebest\Webtrees\FlashMessages;
274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AhnentafelReportModule;
284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AlbumModule;
294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AncestorsChartModule;
304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BatchUpdateModule;
314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BingWebmasterToolsModule;
324ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthDeathMarriageReportModule;
334ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthReportModule;
3467992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\BranchesListModule;
3509fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishMonarchs;
3609fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishPrimeMinisters;
3709fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishSocialHistory;
384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CalendarMenuModule;
394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CemeteryReportModule;
404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CensusAssistantModule;
414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChangeReportModule;
424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsBlockModule;
434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsMenuModule;
444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CkeditorModule;
454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ClippingsCartModule;
464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CloudsTheme;
474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ColorsTheme;
484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CompactTreeChartModule;
494ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ContactsFooterModule;
504ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CookieWarningModule;
518d6560c4SGreg Roachuse Fisharebest\Webtrees\Module\CustomCssJsModule;
524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DeathReportModule;
534ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyChartModule;
544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyModule;
554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyReportModule;
564ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FabTheme;
574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FactSourcesReportModule;
584ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyBookChartModule;
594ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyGroupReportModule;
6067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\FamilyListModule;
614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyNavigatorModule;
624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule;
634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeNewsModule;
644ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule;
654ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FanChartModule;
664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule;
674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleAnalyticsModule;
684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule;
694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HitCountFooterModule;
704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HourglassChartModule;
714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HtmlBlockModule;
724ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFactsTabModule;
734ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFamiliesReportModule;
7467992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\IndividualListModule;
7509fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\IndividualMetadataModule;
764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualReportModule;
774ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\InteractiveTreeModule;
7802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAfrikaans;
7902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAlbanian;
8002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageArabic;
8102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBosnian;
8202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBulgarian;
8302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCatalan;
8402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseSimplified;
8502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseTraditional;
8602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCroatian;
8702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCzech;
8802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDanish;
8902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDivehi;
9002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDutch;
9102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishAustralia;
9202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain;
9302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates;
9402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEstonian;
9502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFaroese;
9602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFarsi;
9702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFinnish;
9802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrench;
9902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrenchCanada;
10002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGalician;
10102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGeorgian;
10202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGerman;
10302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGreek;
10402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHebrew;
10502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHungarian;
10602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageIcelandic;
10702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageIndonesian;
10802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageItalian;
10902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageJapanese;
11002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageJavanese;
11102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageKazhak;
11202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageKorean;
11302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLatvian;
11402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLingala;
11502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLithuanian;
11602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMalay;
11702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMaori;
11802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMarathi;
11902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNepalese;
12002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNorwegianBokmal;
12102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNorwegianNynorsk;
12202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageOccitan;
12302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePolish;
12402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePortuguese;
12502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePortugueseBrazil;
12602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageRomanian;
12702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageRussian;
12802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSerbian;
12902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSerbianLatin;
13002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSlovakian;
13102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSlovenian;
13202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSpanish;
13302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSundanese;
13402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSwahili;
13502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSwedish;
13602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTamil;
13702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTatar;
13802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageThai;
13902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTurkish;
14002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageUkranian;
14102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageVietnamese;
14202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageYiddish;
1434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LifespansChartModule;
1444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ListsMenuModule;
1454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoggedInUsersModule;
1464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoginBlockModule;
1474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MarriageReportModule;
1484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MatomoAnalyticsModule;
14967992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\MediaListModule;
1504ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MediaTabModule;
1514ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MinimalTheme;
1524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MissingFactsReportModule;
153bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
1544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
1554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
1564ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface;
1574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleFooterInterface;
158bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
1594ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface;
160bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface;
16167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\ModuleListInterface;
1624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface;
1634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface;
1644ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
1654ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
166bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface;
16767992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\NoteListModule;
1684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\NotesTabModule;
1694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OccupationReportModule;
1704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OnThisDayModule;
1714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeChartModule;
1724ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeMapModule;
1734ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeReportModule;
17467992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
1754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PlacesModule;
1764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PoweredByWebtreesModule;
1774ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RecentChangesModule;
1784ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelatedIndividualsReportModule;
1794ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule;
1804ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelativesTabModule;
1814ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReportsMenuModule;
18267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\RepositoryListModule;
1834ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ResearchTaskModule;
1844ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReviewChangesModule;
1854ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SearchMenuModule;
1864ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SiteMapModule;
1874ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SlideShowModule;
18867992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\SourceListModule;
1894ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SourcesTabModule;
1904ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatcounterModule;
1914ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatisticsChartModule;
1924ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StoriesModule;
1934ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ThemeSelectModule;
1944ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TimelineChartModule;
1954ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopGivenNamesModule;
1964ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopPageViewsModule;
1974ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopSurnamesModule;
1984ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule;
1994ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UpcomingAnniversariesModule;
2004ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserFavoritesModule;
2014ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserJournalModule;
2024ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserMessagesModule;
2034ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserWelcomeModule;
20409fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\USPresidents;
2054ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WebtreesTheme;
2064ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WelcomeBlockModule;
2074ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\XeneaTheme;
2084ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\YahrzeitModule;
2094ca7e03cSGreg Roachuse Fisharebest\Webtrees\Tree;
2104ca7e03cSGreg Roachuse Fisharebest\Webtrees\Webtrees;
2114ca7e03cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
2124ca7e03cSGreg Roachuse Illuminate\Support\Collection;
2134ca7e03cSGreg Roachuse Illuminate\Support\Str;
2144ca7e03cSGreg Roachuse stdClass;
2154ca7e03cSGreg Roachuse Throwable;
2164ca7e03cSGreg Roach
21771378461SGreg Roachuse function app;
21871378461SGreg Roachuse function method_exists;
21971378461SGreg Roach
2204ca7e03cSGreg Roach/**
2214ca7e03cSGreg Roach * Functions for managing and maintaining modules.
2224ca7e03cSGreg Roach */
2234ca7e03cSGreg Roachclass ModuleService
2244ca7e03cSGreg Roach{
225362b8464SGreg Roach    // Components are pieces of user-facing functionality, are managed together in the control panel.
2264ca7e03cSGreg Roach    private const COMPONENTS = [
22787cca37cSGreg Roach        ModuleAnalyticsInterface::class,
22887cca37cSGreg Roach        ModuleBlockInterface::class,
22987cca37cSGreg Roach        ModuleChartInterface::class,
23087cca37cSGreg Roach        ModuleFooterInterface::class,
23187cca37cSGreg Roach        ModuleHistoricEventsInterface::class,
23287cca37cSGreg Roach        ModuleLanguageInterface::class,
23387cca37cSGreg Roach        ModuleListInterface::class,
23487cca37cSGreg Roach        ModuleMenuInterface::class,
23587cca37cSGreg Roach        ModuleReportInterface::class,
23687cca37cSGreg Roach        ModuleSidebarInterface::class,
23787cca37cSGreg Roach        ModuleTabInterface::class,
23887cca37cSGreg Roach        ModuleThemeInterface::class,
2394ca7e03cSGreg Roach    ];
2404ca7e03cSGreg Roach
2414ca7e03cSGreg Roach    // Array keys are module names, and should match module names from earlier versions of webtrees.
2424ca7e03cSGreg Roach    private const CORE_MODULES = [
2434ca7e03cSGreg Roach        'GEDFact_assistant'       => CensusAssistantModule::class,
2444ca7e03cSGreg Roach        'ahnentafel_report'       => AhnentafelReportModule::class,
2454ca7e03cSGreg Roach        'ancestors_chart'         => AncestorsChartModule::class,
2464ca7e03cSGreg Roach        'batch_update'            => BatchUpdateModule::class,
2474ca7e03cSGreg Roach        'bdm_report'              => BirthDeathMarriageReportModule::class,
2484ca7e03cSGreg Roach        'bing-webmaster-tools'    => BingWebmasterToolsModule::class,
2494ca7e03cSGreg Roach        'birth_report'            => BirthReportModule::class,
25067992b6aSRichard Cissee        'branches_list'           => BranchesListModule::class,
25109fbf3e5SGreg Roach        'british-monarchs'        => BritishMonarchs::class,
25209fbf3e5SGreg Roach        'british-prime-ministers' => BritishPrimeMinisters::class,
25309fbf3e5SGreg Roach        'british-social-history'  => BritishSocialHistory::class,
2544ca7e03cSGreg Roach        'calendar-menu'           => CalendarMenuModule::class,
2554ca7e03cSGreg Roach        'cemetery_report'         => CemeteryReportModule::class,
2564ca7e03cSGreg Roach        'change_report'           => ChangeReportModule::class,
2574ca7e03cSGreg Roach        'charts'                  => ChartsBlockModule::class,
2584ca7e03cSGreg Roach        'charts-menu'             => ChartsMenuModule::class,
2594ca7e03cSGreg Roach        'ckeditor'                => CkeditorModule::class,
2604ca7e03cSGreg Roach        'clippings'               => ClippingsCartModule::class,
2614ca7e03cSGreg Roach        'clouds'                  => CloudsTheme::class,
2624ca7e03cSGreg Roach        'colors'                  => ColorsTheme::class,
2634ca7e03cSGreg Roach        'compact-chart'           => CompactTreeChartModule::class,
2644ca7e03cSGreg Roach        'contact-links'           => ContactsFooterModule::class,
2654ca7e03cSGreg Roach        'cookie-warning'          => CookieWarningModule::class,
2668d6560c4SGreg Roach        'custom-css-js'           => CustomCssJsModule::class,
2674ca7e03cSGreg Roach        'death_report'            => DeathReportModule::class,
2684ca7e03cSGreg Roach        'descendancy'             => DescendancyModule::class,
2694ca7e03cSGreg Roach        'descendancy_chart'       => DescendancyChartModule::class,
2704ca7e03cSGreg Roach        'descendancy_report'      => DescendancyReportModule::class,
2718eaf8709SGreg Roach        'extra_info'              => IndividualMetadataModule::class,
2724ca7e03cSGreg Roach        'fab'                     => FabTheme::class,
2734ca7e03cSGreg Roach        'fact_sources'            => FactSourcesReportModule::class,
2744ca7e03cSGreg Roach        'family_book_chart'       => FamilyBookChartModule::class,
2754ca7e03cSGreg Roach        'family_group_report'     => FamilyGroupReportModule::class,
27667992b6aSRichard Cissee        'family_list'             => FamilyListModule::class,
2774ca7e03cSGreg Roach        'family_nav'              => FamilyNavigatorModule::class,
2784ca7e03cSGreg Roach        'fan_chart'               => FanChartModule::class,
2794ca7e03cSGreg Roach        'faq'                     => FrequentlyAskedQuestionsModule::class,
2804ca7e03cSGreg Roach        'gedcom_block'            => WelcomeBlockModule::class,
2814ca7e03cSGreg Roach        'gedcom_favorites'        => FamilyTreeFavoritesModule::class,
2824ca7e03cSGreg Roach        'gedcom_news'             => FamilyTreeNewsModule::class,
2834ca7e03cSGreg Roach        'gedcom_stats'            => FamilyTreeStatisticsModule::class,
2844ca7e03cSGreg Roach        'google-analytics'        => GoogleAnalyticsModule::class,
2854ca7e03cSGreg Roach        'google-webmaster-tools'  => GoogleWebmasterToolsModule::class,
2864ca7e03cSGreg Roach        'hit-counter'             => HitCountFooterModule::class,
2874ca7e03cSGreg Roach        'hourglass_chart'         => HourglassChartModule::class,
2884ca7e03cSGreg Roach        'html'                    => HtmlBlockModule::class,
2894ca7e03cSGreg Roach        'individual_ext_report'   => IndividualFamiliesReportModule::class,
29067992b6aSRichard Cissee        'individual_list'         => IndividualListModule::class,
2914ca7e03cSGreg Roach        'individual_report'       => IndividualReportModule::class,
29202086832SGreg Roach        'language-af'             => LanguageAfrikaans::class,
29302086832SGreg Roach        'language-ar'             => LanguageArabic::class,
29402086832SGreg Roach        'language-bs'             => LanguageBosnian::class,
29502086832SGreg Roach        'language-bu'             => LanguageBulgarian::class,
29602086832SGreg Roach        'language-ca'             => LanguageCatalan::class,
29702086832SGreg Roach        'language-cs'             => LanguageCzech::class,
29802086832SGreg Roach        'language-da'             => LanguageDanish::class,
29902086832SGreg Roach        'language-de'             => LanguageGerman::class,
30002086832SGreg Roach        'language-dv'             => LanguageDivehi::class,
30102086832SGreg Roach        'language-el'             => LanguageGreek::class,
30202086832SGreg Roach        'language-en-AU'          => LanguageEnglishAustralia::class,
30302086832SGreg Roach        'language-en-GB'          => LanguageEnglishGreatBritain::class,
30402086832SGreg Roach        'language-en-US'          => LanguageEnglishUnitedStates::class,
30502086832SGreg Roach        'language-es'             => LanguageSpanish::class,
30602086832SGreg Roach        'language-et'             => LanguageEstonian::class,
30702086832SGreg Roach        'language-fa'             => LanguageFarsi::class,
30802086832SGreg Roach        'language-fi'             => LanguageFinnish::class,
30902086832SGreg Roach        'language-fo'             => LanguageFaroese::class,
31002086832SGreg Roach        'language-fr'             => LanguageFrench::class,
31102086832SGreg Roach        'language-fr-CA'          => LanguageFrenchCanada::class,
31202086832SGreg Roach        'language-gl'             => LanguageGalician::class,
31302086832SGreg Roach        'language-he'             => LanguageHebrew::class,
31402086832SGreg Roach        'language-hr'             => LanguageCroatian::class,
31502086832SGreg Roach        'language-hu'             => LanguageHungarian::class,
31602086832SGreg Roach        'language-id'             => LanguageIndonesian::class,
31702086832SGreg Roach        'language-is'             => LanguageIcelandic::class,
31802086832SGreg Roach        'language-it'             => LanguageItalian::class,
31902086832SGreg Roach        'language-ja'             => LanguageJapanese::class,
32002086832SGreg Roach        'language-jv'             => LanguageJavanese::class,
32102086832SGreg Roach        'language-ka'             => LanguageGeorgian::class,
32202086832SGreg Roach        'language-kk'             => LanguageKazhak::class,
32302086832SGreg Roach        'language-ko'             => LanguageKorean::class,
32402086832SGreg Roach        'language-ln'             => LanguageLingala::class,
32502086832SGreg Roach        'language-lt'             => LanguageLithuanian::class,
32602086832SGreg Roach        'language-lv'             => LanguageLatvian::class,
32702086832SGreg Roach        'language-mi'             => LanguageMaori::class,
32802086832SGreg Roach        'language-mr'             => LanguageMarathi::class,
32902086832SGreg Roach        'language-ms'             => LanguageMalay::class,
33002086832SGreg Roach        'language-nb'             => LanguageNorwegianBokmal::class,
33102086832SGreg Roach        'language-ne'             => LanguageNepalese::class,
33202086832SGreg Roach        'language-nl'             => LanguageDutch::class,
33302086832SGreg Roach        'language-nn'             => LanguageNorwegianNynorsk::class,
33402086832SGreg Roach        'language-oc'             => LanguageOccitan::class,
33502086832SGreg Roach        'language-pl'             => LanguagePolish::class,
33602086832SGreg Roach        'language-pt'             => LanguagePortuguese::class,
33702086832SGreg Roach        'language-pt-BR'          => LanguagePortugueseBrazil::class,
33802086832SGreg Roach        'language-ro'             => LanguageRomanian::class,
33902086832SGreg Roach        'language-ru'             => LanguageRussian::class,
34002086832SGreg Roach        'language-sk'             => LanguageSlovakian::class,
34102086832SGreg Roach        'language-sl'             => LanguageSlovenian::class,
34202086832SGreg Roach        'language-sq'             => LanguageAlbanian::class,
34302086832SGreg Roach        'language-sr'             => LanguageSerbian::class,
34402086832SGreg Roach        'language-sr-Latn'        => LanguageSerbianLatin::class,
34502086832SGreg Roach        'language-su'             => LanguageSundanese::class,
34602086832SGreg Roach        'language-sv'             => LanguageSwedish::class,
34702086832SGreg Roach        'language-sw'             => LanguageSwahili::class,
34802086832SGreg Roach        'language-ta'             => LanguageTamil::class,
34902086832SGreg Roach        'language-th'             => LanguageThai::class,
35002086832SGreg Roach        'language-tr'             => LanguageTurkish::class,
35102086832SGreg Roach        'language-tt'             => LanguageTatar::class,
35202086832SGreg Roach        'language-uk'             => LanguageUkranian::class,
35302086832SGreg Roach        'language-vi'             => LanguageVietnamese::class,
35402086832SGreg Roach        'language-yi'             => LanguageYiddish::class,
35502086832SGreg Roach        'language-zh-Hans'        => LanguageChineseSimplified::class,
35602086832SGreg Roach        'language-zh-Hant'        => LanguageChineseTraditional::class,
3574ca7e03cSGreg Roach        'lifespans_chart'         => LifespansChartModule::class,
3584ca7e03cSGreg Roach        'lightbox'                => AlbumModule::class,
3594ca7e03cSGreg Roach        'lists-menu'              => ListsMenuModule::class,
3604ca7e03cSGreg Roach        'logged_in'               => LoggedInUsersModule::class,
3614ca7e03cSGreg Roach        'login_block'             => LoginBlockModule::class,
3624ca7e03cSGreg Roach        'marriage_report'         => MarriageReportModule::class,
3634ca7e03cSGreg Roach        'matomo-analytics'        => MatomoAnalyticsModule::class,
3644ca7e03cSGreg Roach        'media'                   => MediaTabModule::class,
36567992b6aSRichard Cissee        'media_list'              => MediaListModule::class,
3664ca7e03cSGreg Roach        'minimal'                 => MinimalTheme::class,
3674ca7e03cSGreg Roach        'missing_facts_report'    => MissingFactsReportModule::class,
3684ca7e03cSGreg Roach        'notes'                   => NotesTabModule::class,
36967992b6aSRichard Cissee        'note_list'               => NoteListModule::class,
3704ca7e03cSGreg Roach        'occupation_report'       => OccupationReportModule::class,
3714ca7e03cSGreg Roach        'pedigree-map'            => PedigreeMapModule::class,
3724ca7e03cSGreg Roach        'pedigree_chart'          => PedigreeChartModule::class,
3734ca7e03cSGreg Roach        'pedigree_report'         => PedigreeReportModule::class,
3744ca7e03cSGreg Roach        'personal_facts'          => IndividualFactsTabModule::class,
3754ca7e03cSGreg Roach        'places'                  => PlacesModule::class,
37667992b6aSRichard Cissee        'places_list'             => PlaceHierarchyListModule::class,
3774ca7e03cSGreg Roach        'powered-by-webtrees'     => PoweredByWebtreesModule::class,
3784ca7e03cSGreg Roach        'random_media'            => SlideShowModule::class,
3794ca7e03cSGreg Roach        'recent_changes'          => RecentChangesModule::class,
3804ca7e03cSGreg Roach        'relationships_chart'     => RelationshipsChartModule::class,
3814ca7e03cSGreg Roach        'relative_ext_report'     => RelatedIndividualsReportModule::class,
3824ca7e03cSGreg Roach        'relatives'               => RelativesTabModule::class,
3834ca7e03cSGreg Roach        'reports-menu'            => ReportsMenuModule::class,
38467992b6aSRichard Cissee        'repository_list'         => RepositoryListModule::class,
3854ca7e03cSGreg Roach        'review_changes'          => ReviewChangesModule::class,
3864ca7e03cSGreg Roach        'search-menu'             => SearchMenuModule::class,
3874ca7e03cSGreg Roach        'sitemap'                 => SiteMapModule::class,
38867992b6aSRichard Cissee        'source_list'             => SourceListModule::class,
3894ca7e03cSGreg Roach        'sources_tab'             => SourcesTabModule::class,
3904ca7e03cSGreg Roach        'statcounter'             => StatcounterModule::class,
3914ca7e03cSGreg Roach        'statistics_chart'        => StatisticsChartModule::class,
3924ca7e03cSGreg Roach        'stories'                 => StoriesModule::class,
3934ca7e03cSGreg Roach        'theme_select'            => ThemeSelectModule::class,
3944ca7e03cSGreg Roach        'timeline_chart'          => TimelineChartModule::class,
3954ca7e03cSGreg Roach        'todays_events'           => OnThisDayModule::class,
3964ca7e03cSGreg Roach        'todo'                    => ResearchTaskModule::class,
3974ca7e03cSGreg Roach        'top10_givnnames'         => TopGivenNamesModule::class,
3984ca7e03cSGreg Roach        'top10_pageviews'         => TopPageViewsModule::class,
3994ca7e03cSGreg Roach        'top10_surnames'          => TopSurnamesModule::class,
4004ca7e03cSGreg Roach        'tree'                    => InteractiveTreeModule::class,
4014ca7e03cSGreg Roach        'trees-menu'              => TreesMenuModule::class,
4024ca7e03cSGreg Roach        'upcoming_events'         => UpcomingAnniversariesModule::class,
40309fbf3e5SGreg Roach        'us-presidents'           => USPresidents::class,
4044ca7e03cSGreg Roach        'user_blog'               => UserJournalModule::class,
4054ca7e03cSGreg Roach        'user_favorites'          => UserFavoritesModule::class,
4064ca7e03cSGreg Roach        'user_messages'           => UserMessagesModule::class,
4074ca7e03cSGreg Roach        'user_welcome'            => UserWelcomeModule::class,
4084ca7e03cSGreg Roach        'webtrees'                => WebtreesTheme::class,
4094ca7e03cSGreg Roach        'xenea'                   => XeneaTheme::class,
4104ca7e03cSGreg Roach        'yahrzeit'                => YahrzeitModule::class,
4114ca7e03cSGreg Roach    ];
4124ca7e03cSGreg Roach
4134ca7e03cSGreg Roach    /**
414dedcf571SGreg Roach     * A function to convert modules into their titles - to create option lists, etc.
415dedcf571SGreg Roach     *
416dedcf571SGreg Roach     * @return Closure
417dedcf571SGreg Roach     */
418dedcf571SGreg Roach    public function titleMapper(): Closure
419dedcf571SGreg Roach    {
4206c2179e2SGreg Roach        return static function (ModuleInterface $module): string {
421dedcf571SGreg Roach            return $module->title();
422dedcf571SGreg Roach        };
423dedcf571SGreg Roach    }
424dedcf571SGreg Roach
425dedcf571SGreg Roach    /**
4264ca7e03cSGreg Roach     * Modules which (a) provide a specific function and (b) we have permission to see.
4274ca7e03cSGreg Roach     *
42887cca37cSGreg Roach     * @param string        $interface
4294ca7e03cSGreg Roach     * @param Tree          $tree
430e5a6b4d4SGreg Roach     * @param UserInterface $user
4314ca7e03cSGreg Roach     *
43254c7f8dfSGreg Roach     * @return Collection
4334ca7e03cSGreg Roach     */
43487cca37cSGreg Roach    public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection
4354ca7e03cSGreg Roach    {
436b5979037SGreg Roach        return $this->findByInterface($interface, false, true)
4370b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module) use ($interface, $tree, $user): bool {
43887cca37cSGreg Roach                return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user);
4394ca7e03cSGreg Roach            });
4404ca7e03cSGreg Roach    }
4414ca7e03cSGreg Roach
4424ca7e03cSGreg Roach    /**
4434ca7e03cSGreg Roach     * All modules which provide a specific function.
4444ca7e03cSGreg Roach     *
4454ca7e03cSGreg Roach     * @param string $interface
4464ca7e03cSGreg Roach     * @param bool   $include_disabled
447b5979037SGreg Roach     * @param bool   $sort
4484ca7e03cSGreg Roach     *
44954c7f8dfSGreg Roach     * @return Collection
4504ca7e03cSGreg Roach     */
451b5979037SGreg Roach    public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
4524ca7e03cSGreg Roach    {
4539d627a9eSGreg Roach        $modules = $this->all($include_disabled)
4549d627a9eSGreg Roach            ->filter($this->interfaceFilter($interface));
4554ca7e03cSGreg Roach
4564ca7e03cSGreg Roach        switch ($interface) {
4574ca7e03cSGreg Roach            case ModuleFooterInterface::class:
458bf57b580SGreg Roach                return $modules->sort($this->footerSorter());
4594ca7e03cSGreg Roach
4604ca7e03cSGreg Roach            case ModuleMenuInterface::class:
461bf57b580SGreg Roach                return $modules->sort($this->menuSorter());
4624ca7e03cSGreg Roach
4634ca7e03cSGreg Roach            case ModuleSidebarInterface::class:
464bf57b580SGreg Roach                return $modules->sort($this->sidebarSorter());
4654ca7e03cSGreg Roach
4664ca7e03cSGreg Roach            case ModuleTabInterface::class:
467bf57b580SGreg Roach                return $modules->sort($this->tabSorter());
468b5979037SGreg Roach
469b5979037SGreg Roach            default:
470b5979037SGreg Roach                if ($sort) {
471b5979037SGreg Roach                    return $modules->sort($this->moduleSorter());
4724ca7e03cSGreg Roach                }
4734ca7e03cSGreg Roach
4744ca7e03cSGreg Roach                return $modules;
4754ca7e03cSGreg Roach        }
476b5979037SGreg Roach    }
4774ca7e03cSGreg Roach
4784ca7e03cSGreg Roach    /**
4798d6560c4SGreg Roach     * All modules.
4808d6560c4SGreg Roach     *
4818d6560c4SGreg Roach     * @param bool $include_disabled
4828d6560c4SGreg Roach     *
4838d6560c4SGreg Roach     * @return Collection
4848d6560c4SGreg Roach     */
4858d6560c4SGreg Roach    public function all(bool $include_disabled = false): Collection
4868d6560c4SGreg Roach    {
4878d6560c4SGreg Roach        return app('cache.array')->rememberForever('all_modules', function (): Collection {
4888d6560c4SGreg Roach            // Modules have a default status, order etc.
4898d6560c4SGreg Roach            // We can override these from database settings.
4908d6560c4SGreg Roach            $module_info = DB::table('module')
4918d6560c4SGreg Roach                ->get()
4920b5fd0a6SGreg Roach                ->mapWithKeys(static function (stdClass $row): array {
4938d6560c4SGreg Roach                    return [$row->module_name => $row];
4948d6560c4SGreg Roach                });
4958d6560c4SGreg Roach
4968d6560c4SGreg Roach            return $this->coreModules()
4978d6560c4SGreg Roach                ->merge($this->customModules())
4980b5fd0a6SGreg Roach                ->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface {
4998d6560c4SGreg Roach                    $info = $module_info->get($module->name());
5008d6560c4SGreg Roach
5018d6560c4SGreg Roach                    if ($info instanceof stdClass) {
5028d6560c4SGreg Roach                        $module->setEnabled($info->status === 'enabled');
5038d6560c4SGreg Roach
5048d6560c4SGreg Roach                        if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
5058d6560c4SGreg Roach                            $module->setFooterOrder((int) $info->footer_order);
5068d6560c4SGreg Roach                        }
5078d6560c4SGreg Roach
5088d6560c4SGreg Roach                        if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
5098d6560c4SGreg Roach                            $module->setMenuOrder((int) $info->menu_order);
5108d6560c4SGreg Roach                        }
5118d6560c4SGreg Roach
5128d6560c4SGreg Roach                        if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
5138d6560c4SGreg Roach                            $module->setSidebarOrder((int) $info->sidebar_order);
5148d6560c4SGreg Roach                        }
5158d6560c4SGreg Roach
5168d6560c4SGreg Roach                        if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
5178d6560c4SGreg Roach                            $module->setTabOrder((int) $info->tab_order);
5188d6560c4SGreg Roach                        }
5198d6560c4SGreg Roach                    } else {
5208d6560c4SGreg Roach                        $module->setEnabled($module->isEnabledByDefault());
5218d6560c4SGreg Roach
5228d6560c4SGreg Roach                        DB::table('module')->insert([
5238d6560c4SGreg Roach                            'module_name' => $module->name(),
5248d6560c4SGreg Roach                            'status'      => $module->isEnabled() ? 'enabled' : 'disabled',
5258d6560c4SGreg Roach                        ]);
5268d6560c4SGreg Roach                    }
5278d6560c4SGreg Roach
5288d6560c4SGreg Roach                    return $module;
5298d6560c4SGreg Roach                });
5308d6560c4SGreg Roach        })->filter($this->enabledFilter($include_disabled));
5318d6560c4SGreg Roach    }
5328d6560c4SGreg Roach
5338d6560c4SGreg Roach    /**
5348d6560c4SGreg Roach     * All core modules in the system.
5358d6560c4SGreg Roach     *
5368d6560c4SGreg Roach     * @return Collection
5378d6560c4SGreg Roach     */
5388d6560c4SGreg Roach    private function coreModules(): Collection
5398d6560c4SGreg Roach    {
5408d6560c4SGreg Roach        return Collection::make(self::CORE_MODULES)
5410b5fd0a6SGreg Roach            ->map(static function (string $class, string $name): ModuleInterface {
5428d6560c4SGreg Roach                $module = app($class);
5438d6560c4SGreg Roach
5448d6560c4SGreg Roach                $module->setName($name);
5458d6560c4SGreg Roach
5468d6560c4SGreg Roach                return $module;
5478d6560c4SGreg Roach            });
5488d6560c4SGreg Roach    }
5498d6560c4SGreg Roach
5508d6560c4SGreg Roach    /**
5518d6560c4SGreg Roach     * All custom modules in the system.  Custom modules are defined in modules_v4/
5528d6560c4SGreg Roach     *
5538d6560c4SGreg Roach     * @return Collection
5548d6560c4SGreg Roach     */
5558d6560c4SGreg Roach    private function customModules(): Collection
5568d6560c4SGreg Roach    {
557f397d0fdSGreg Roach        $pattern   = Webtrees::MODULES_DIR . '*/module.php';
5588d6560c4SGreg Roach        $filenames = glob($pattern, GLOB_NOSORT);
5598d6560c4SGreg Roach
5608d6560c4SGreg Roach        return Collection::make($filenames)
5610b5fd0a6SGreg Roach            ->filter(static function (string $filename): bool {
5628d6560c4SGreg Roach                // Special characters will break PHP variable names.
5638d6560c4SGreg Roach                // This also allows us to ignore modules called "foo.example" and "foo.disable"
5648d6560c4SGreg Roach                $module_name = basename(dirname($filename));
5658d6560c4SGreg Roach
5668d6560c4SGreg Roach                return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30;
5678d6560c4SGreg Roach            })
5680b5fd0a6SGreg Roach            ->map(static function (string $filename): ?ModuleCustomInterface {
5698d6560c4SGreg Roach                try {
5708d6560c4SGreg Roach                    $module = self::load($filename);
5718d6560c4SGreg Roach
5728d6560c4SGreg Roach                    if ($module instanceof ModuleCustomInterface) {
5738d6560c4SGreg Roach                        $module_name = '_' . basename(dirname($filename)) . '_';
5748d6560c4SGreg Roach
5758d6560c4SGreg Roach                        $module->setName($module_name);
5768d6560c4SGreg Roach                    } else {
5778d6560c4SGreg Roach                        return null;
5788d6560c4SGreg Roach                    }
5798d6560c4SGreg Roach
5808d6560c4SGreg Roach                    return $module;
5818d6560c4SGreg Roach                } catch (Throwable $ex) {
5828d6560c4SGreg Roach                    // It would be nice to show this error in a flash-message or similar, but the framework
5838d6560c4SGreg Roach                    // has not yet been initialised so we have no themes, languages, sessions, etc.
5848d6560c4SGreg Roach                    throw $ex;
5858d6560c4SGreg Roach                }
5868d6560c4SGreg Roach            })
5878d6560c4SGreg Roach            ->filter()
5880b5fd0a6SGreg Roach            ->mapWithKeys(static function (ModuleCustomInterface $module): array {
5898d6560c4SGreg Roach                return [$module->name() => $module];
5908d6560c4SGreg Roach            });
5918d6560c4SGreg Roach    }
5928d6560c4SGreg Roach
5938d6560c4SGreg Roach    /**
59402086832SGreg Roach     * During setup, we'll need access to some languages.
59502086832SGreg Roach     *
59602086832SGreg Roach     * @return Collection
59702086832SGreg Roach     */
59802086832SGreg Roach    public function setupLanguages(): Collection
59902086832SGreg Roach    {
60002086832SGreg Roach        return $this->coreModules()
6010b93976aSGreg Roach            ->filter(static function (ModuleInterface $module): bool {
60202086832SGreg Roach                return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault();
60302086832SGreg Roach            })
6040b93976aSGreg Roach            ->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y): int {
605c116a5ccSGreg Roach                return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable();
606c116a5ccSGreg Roach            });
60702086832SGreg Roach    }
60802086832SGreg Roach
60902086832SGreg Roach    /**
610*5bc7939cSBen     * Load a custom module in a static scope, to prevent it from modifying local or object variables.
6118d6560c4SGreg Roach     *
6128d6560c4SGreg Roach     * @param string $filename
6138d6560c4SGreg Roach     *
6148d6560c4SGreg Roach     * @return mixed
6158d6560c4SGreg Roach     */
6168d6560c4SGreg Roach    private static function load(string $filename)
6178d6560c4SGreg Roach    {
618*5bc7939cSBen        try {
6198d6560c4SGreg Roach            return include $filename;
620*5bc7939cSBen        } catch (Throwable $loading_exception) {
621*5bc7939cSBen            $module_name = basename(dirname($filename));
622*5bc7939cSBen            FlashMessages::addMessage(I18N::translate('Module %s errored while loading.', $module_name) . '<br>' . $loading_exception->getMessage(), 'danger');
623*5bc7939cSBen        }
624*5bc7939cSBen        return null;
6258d6560c4SGreg Roach    }
6268d6560c4SGreg Roach
6278d6560c4SGreg Roach    /**
6288d6560c4SGreg Roach     * A function filter modules by enabled/disabled
6298d6560c4SGreg Roach     *
6308d6560c4SGreg Roach     * @param bool $include_disabled
6318d6560c4SGreg Roach     *
6328d6560c4SGreg Roach     * @return Closure
6338d6560c4SGreg Roach     */
6348d6560c4SGreg Roach    private function enabledFilter(bool $include_disabled): Closure
6358d6560c4SGreg Roach    {
6366c2179e2SGreg Roach        return static function (ModuleInterface $module) use ($include_disabled): bool {
6378d6560c4SGreg Roach            return $include_disabled || $module->isEnabled();
6388d6560c4SGreg Roach        };
6398d6560c4SGreg Roach    }
6408d6560c4SGreg Roach
6418d6560c4SGreg Roach    /**
6428d6560c4SGreg Roach     * A function filter modules by type
6438d6560c4SGreg Roach     *
6448d6560c4SGreg Roach     * @param string $interface
6458d6560c4SGreg Roach     *
6468d6560c4SGreg Roach     * @return Closure
6478d6560c4SGreg Roach     */
6488d6560c4SGreg Roach    private function interfaceFilter(string $interface): Closure
6498d6560c4SGreg Roach    {
6506c2179e2SGreg Roach        return static function (ModuleInterface $module) use ($interface): bool {
6518d6560c4SGreg Roach            return $module instanceof $interface;
6528d6560c4SGreg Roach        };
6538d6560c4SGreg Roach    }
6548d6560c4SGreg Roach
6558d6560c4SGreg Roach    /**
6568d6560c4SGreg Roach     * A function to sort footers
6578d6560c4SGreg Roach     *
6588d6560c4SGreg Roach     * @return Closure
6598d6560c4SGreg Roach     */
6608d6560c4SGreg Roach    private function footerSorter(): Closure
6618d6560c4SGreg Roach    {
6626c2179e2SGreg Roach        return static function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
6638d6560c4SGreg Roach            return $x->getFooterOrder() <=> $y->getFooterOrder();
6648d6560c4SGreg Roach        };
6658d6560c4SGreg Roach    }
6668d6560c4SGreg Roach
6678d6560c4SGreg Roach    /**
6688d6560c4SGreg Roach     * A function to sort menus
6698d6560c4SGreg Roach     *
6708d6560c4SGreg Roach     * @return Closure
6718d6560c4SGreg Roach     */
6728d6560c4SGreg Roach    private function menuSorter(): Closure
6738d6560c4SGreg Roach    {
6746c2179e2SGreg Roach        return static function (ModuleMenuInterface $x, ModuleMenuInterface $y): int {
6758d6560c4SGreg Roach            return $x->getMenuOrder() <=> $y->getMenuOrder();
6768d6560c4SGreg Roach        };
6778d6560c4SGreg Roach    }
6788d6560c4SGreg Roach
6798d6560c4SGreg Roach    /**
6808d6560c4SGreg Roach     * A function to sort menus
6818d6560c4SGreg Roach     *
6828d6560c4SGreg Roach     * @return Closure
6838d6560c4SGreg Roach     */
6848d6560c4SGreg Roach    private function sidebarSorter(): Closure
6858d6560c4SGreg Roach    {
6866c2179e2SGreg Roach        return static function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int {
6878d6560c4SGreg Roach            return $x->getSidebarOrder() <=> $y->getSidebarOrder();
6888d6560c4SGreg Roach        };
6898d6560c4SGreg Roach    }
6908d6560c4SGreg Roach
6918d6560c4SGreg Roach    /**
6928d6560c4SGreg Roach     * A function to sort menus
6938d6560c4SGreg Roach     *
6948d6560c4SGreg Roach     * @return Closure
6958d6560c4SGreg Roach     */
6968d6560c4SGreg Roach    private function tabSorter(): Closure
6978d6560c4SGreg Roach    {
6986c2179e2SGreg Roach        return static function (ModuleTabInterface $x, ModuleTabInterface $y): int {
6998d6560c4SGreg Roach            return $x->getTabOrder() <=> $y->getTabOrder();
7008d6560c4SGreg Roach        };
7018d6560c4SGreg Roach    }
7028d6560c4SGreg Roach
7038d6560c4SGreg Roach    /**
70402086832SGreg Roach     * A function to sort modules by name.
70502086832SGreg Roach     *
70602086832SGreg Roach     * Languages have a "sortable" name, so that "British English" sorts as "English, British".
70702086832SGreg Roach     * This provides a more natural order in the language menu.
7088d6560c4SGreg Roach     *
7098d6560c4SGreg Roach     * @return Closure
7108d6560c4SGreg Roach     */
7118d6560c4SGreg Roach    private function moduleSorter(): Closure
7128d6560c4SGreg Roach    {
7136c2179e2SGreg Roach        return static function (ModuleInterface $x, ModuleInterface $y): int {
71402086832SGreg Roach            $title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title();
71502086832SGreg Roach            $title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title();
71602086832SGreg Roach
71702086832SGreg Roach            return I18N::strcasecmp($title1, $title2);
7188d6560c4SGreg Roach        };
7198d6560c4SGreg Roach    }
7208d6560c4SGreg Roach
7218d6560c4SGreg Roach    /**
7224ca7e03cSGreg Roach     * Find a specified module, if it is currently active.
7234ca7e03cSGreg Roach     *
7244ca7e03cSGreg Roach     * @param string $module_name
725321a89daSGreg Roach     * @param bool   $include_disabled
7264ca7e03cSGreg Roach     *
7274ca7e03cSGreg Roach     * @return ModuleInterface|null
7284ca7e03cSGreg Roach     */
729321a89daSGreg Roach    public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
7304ca7e03cSGreg Roach    {
7319d627a9eSGreg Roach        return $this->all($include_disabled)
7320797053bSGreg Roach            ->first(static function (ModuleInterface $module) use ($module_name): bool {
733321a89daSGreg Roach                return $module->name() === $module_name;
7340797053bSGreg Roach            });
7354ca7e03cSGreg Roach    }
736bf57b580SGreg Roach
737bf57b580SGreg Roach    /**
738bf57b580SGreg Roach     * Configuration settings are available through the various "module component" pages.
739bf57b580SGreg Roach     * For modules that do not provide a component, we need to list them separately.
740bf57b580SGreg Roach     *
74109fbf3e5SGreg Roach     * @param bool $include_disabled
74209fbf3e5SGreg Roach     *
74354c7f8dfSGreg Roach     * @return Collection
744bf57b580SGreg Roach     */
74509fbf3e5SGreg Roach    public function otherModules(bool $include_disabled = false): Collection
746bf57b580SGreg Roach    {
747abafa13cSGreg Roach        return $this->findByInterface(ModuleInterface::class, $include_disabled, true)
7480b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module): bool {
749bf57b580SGreg Roach                foreach (self::COMPONENTS as $interface) {
750bf57b580SGreg Roach                    if ($module instanceof $interface) {
751bf57b580SGreg Roach                        return false;
752bf57b580SGreg Roach                    }
753bf57b580SGreg Roach                }
754bf57b580SGreg Roach
755bf57b580SGreg Roach                return true;
756bf57b580SGreg Roach            });
757bf57b580SGreg Roach    }
758bf57b580SGreg Roach
759bf57b580SGreg Roach    /**
760bf57b580SGreg Roach     * Generate a list of module names which exist in the database but not on disk.
761bf57b580SGreg Roach     *
76254c7f8dfSGreg Roach     * @return Collection
763bf57b580SGreg Roach     */
764bf57b580SGreg Roach    public function deletedModules(): Collection
765bf57b580SGreg Roach    {
766bf57b580SGreg Roach        $database_modules = DB::table('module')->pluck('module_name');
767bf57b580SGreg Roach
768d5d58984SGreg Roach        $disk_modules = $this->all(true)
7690b5fd0a6SGreg Roach            ->map(static function (ModuleInterface $module): string {
770bf57b580SGreg Roach                return $module->name();
771bf57b580SGreg Roach            });
772bf57b580SGreg Roach
773bf57b580SGreg Roach        return $database_modules->diff($disk_modules);
774bf57b580SGreg Roach    }
77571378461SGreg Roach
77671378461SGreg Roach    /**
77771378461SGreg Roach     * Boot all the modules.
77871378461SGreg Roach     *
77971378461SGreg Roach     * @param ModuleThemeInterface $current_theme
78071378461SGreg Roach     */
781c81b7bf1SGreg Roach    public function bootModules(ModuleThemeInterface $current_theme): void
782c81b7bf1SGreg Roach    {
78371378461SGreg Roach        $bootable_modules = $this->all()->filter(static function (ModuleInterface $module) {
78471378461SGreg Roach            return method_exists($module, 'boot');
78571378461SGreg Roach        });
78671378461SGreg Roach
78771378461SGreg Roach        foreach ($bootable_modules as $module) {
78871378461SGreg Roach            // Only bootstrap the current theme.
78971378461SGreg Roach            if ($module instanceof ModuleThemeInterface && $module !== $current_theme) {
79071378461SGreg Roach                continue;
79171378461SGreg Roach            }
79271378461SGreg Roach
79371378461SGreg Roach            app()->dispatch($module, 'boot');
79471378461SGreg Roach        }
79571378461SGreg Roach    }
7964ca7e03cSGreg Roach}
797