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; 255bc7939cSBenuse Fisharebest\Webtrees\FlashMessages; 269e18e23bSGreg Roachuse Fisharebest\Webtrees\I18N; 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; 508d6560c4SGreg Roachuse Fisharebest\Webtrees\Module\CustomCssJsModule; 514ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DeathReportModule; 524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyChartModule; 534ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyModule; 544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyReportModule; 554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FabTheme; 564ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FactSourcesReportModule; 574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyBookChartModule; 584ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyGroupReportModule; 5967992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\FamilyListModule; 604ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyNavigatorModule; 614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule; 624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeNewsModule; 634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule; 644ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FanChartModule; 654ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule; 664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleAnalyticsModule; 674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule; 684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HitCountFooterModule; 694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HourglassChartModule; 704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HtmlBlockModule; 714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFactsTabModule; 724ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFamiliesReportModule; 7367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\IndividualListModule; 7409fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\IndividualMetadataModule; 754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualReportModule; 764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\InteractiveTreeModule; 7702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAfrikaans; 7802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAlbanian; 7902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageArabic; 8002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBosnian; 8102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBulgarian; 8202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCatalan; 8302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseSimplified; 8402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseTraditional; 8502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCroatian; 8602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCzech; 8702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDanish; 8802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDivehi; 8902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDutch; 9002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishAustralia; 9102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain; 9202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates; 9302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEstonian; 9402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFaroese; 9502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFarsi; 9602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFinnish; 9702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrench; 9802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrenchCanada; 9902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGalician; 10002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGeorgian; 10102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGerman; 10202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGreek; 10302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHebrew; 104*0f180719SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHindi; 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; 177b3a775f6SGreg Roachuse Fisharebest\Webtrees\Module\PrivacyPolicy; 1784ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RecentChangesModule; 1794ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelatedIndividualsReportModule; 1804ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule; 1814ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelativesTabModule; 1824ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReportsMenuModule; 18367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\RepositoryListModule; 1844ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ResearchTaskModule; 1854ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReviewChangesModule; 1864ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SearchMenuModule; 1874ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SiteMapModule; 1884ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SlideShowModule; 18967992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\SourceListModule; 1904ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SourcesTabModule; 1914ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatcounterModule; 1924ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatisticsChartModule; 1934ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StoriesModule; 1944ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ThemeSelectModule; 1954ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TimelineChartModule; 1964ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopGivenNamesModule; 1974ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopPageViewsModule; 1984ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopSurnamesModule; 1994ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule; 2004ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UpcomingAnniversariesModule; 2014ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserFavoritesModule; 2024ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserJournalModule; 2034ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserMessagesModule; 2044ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserWelcomeModule; 20509fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\USPresidents; 2064ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WebtreesTheme; 2074ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WelcomeBlockModule; 2084ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\XeneaTheme; 2094ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\YahrzeitModule; 2104ca7e03cSGreg Roachuse Fisharebest\Webtrees\Tree; 2114ca7e03cSGreg Roachuse Fisharebest\Webtrees\Webtrees; 2124ca7e03cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 2134ca7e03cSGreg Roachuse Illuminate\Support\Collection; 2144ca7e03cSGreg Roachuse Illuminate\Support\Str; 2154ca7e03cSGreg Roachuse stdClass; 2164ca7e03cSGreg Roachuse Throwable; 2174ca7e03cSGreg Roach 21871378461SGreg Roachuse function app; 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 241745968f0SGreg Roach // Components that have access levels. 242745968f0SGreg Roach private const COMPONENTS_WITH_ACCESS = [ 243745968f0SGreg Roach ModuleBlockInterface::class, 244745968f0SGreg Roach ModuleChartInterface::class, 245745968f0SGreg Roach ModuleListInterface::class, 246745968f0SGreg Roach ModuleMenuInterface::class, 247745968f0SGreg Roach ModuleReportInterface::class, 248745968f0SGreg Roach ModuleSidebarInterface::class, 249745968f0SGreg Roach ModuleTabInterface::class, 250745968f0SGreg Roach ]; 251745968f0SGreg Roach 252745968f0SGreg Roach // Components that are displayed in a particular order 253745968f0SGreg Roach private const COMPONENTS_WITH_SORT = [ 254745968f0SGreg Roach ModuleFooterInterface::class, 255745968f0SGreg Roach ModuleMenuInterface::class, 256745968f0SGreg Roach ModuleSidebarInterface::class, 257745968f0SGreg Roach ModuleTabInterface::class, 258745968f0SGreg Roach ]; 259745968f0SGreg Roach 2604ca7e03cSGreg Roach // Array keys are module names, and should match module names from earlier versions of webtrees. 2614ca7e03cSGreg Roach private const CORE_MODULES = [ 2624ca7e03cSGreg Roach 'GEDFact_assistant' => CensusAssistantModule::class, 2634ca7e03cSGreg Roach 'ahnentafel_report' => AhnentafelReportModule::class, 2644ca7e03cSGreg Roach 'ancestors_chart' => AncestorsChartModule::class, 2654ca7e03cSGreg Roach 'batch_update' => BatchUpdateModule::class, 2664ca7e03cSGreg Roach 'bdm_report' => BirthDeathMarriageReportModule::class, 2674ca7e03cSGreg Roach 'bing-webmaster-tools' => BingWebmasterToolsModule::class, 2684ca7e03cSGreg Roach 'birth_report' => BirthReportModule::class, 26967992b6aSRichard Cissee 'branches_list' => BranchesListModule::class, 27009fbf3e5SGreg Roach 'british-monarchs' => BritishMonarchs::class, 27109fbf3e5SGreg Roach 'british-prime-ministers' => BritishPrimeMinisters::class, 27209fbf3e5SGreg Roach 'british-social-history' => BritishSocialHistory::class, 2734ca7e03cSGreg Roach 'calendar-menu' => CalendarMenuModule::class, 2744ca7e03cSGreg Roach 'cemetery_report' => CemeteryReportModule::class, 2754ca7e03cSGreg Roach 'change_report' => ChangeReportModule::class, 2764ca7e03cSGreg Roach 'charts' => ChartsBlockModule::class, 2774ca7e03cSGreg Roach 'charts-menu' => ChartsMenuModule::class, 2784ca7e03cSGreg Roach 'ckeditor' => CkeditorModule::class, 2794ca7e03cSGreg Roach 'clippings' => ClippingsCartModule::class, 2804ca7e03cSGreg Roach 'clouds' => CloudsTheme::class, 2814ca7e03cSGreg Roach 'colors' => ColorsTheme::class, 2824ca7e03cSGreg Roach 'compact-chart' => CompactTreeChartModule::class, 2834ca7e03cSGreg Roach 'contact-links' => ContactsFooterModule::class, 2848d6560c4SGreg Roach 'custom-css-js' => CustomCssJsModule::class, 2854ca7e03cSGreg Roach 'death_report' => DeathReportModule::class, 2864ca7e03cSGreg Roach 'descendancy' => DescendancyModule::class, 2874ca7e03cSGreg Roach 'descendancy_chart' => DescendancyChartModule::class, 2884ca7e03cSGreg Roach 'descendancy_report' => DescendancyReportModule::class, 2898eaf8709SGreg Roach 'extra_info' => IndividualMetadataModule::class, 2904ca7e03cSGreg Roach 'fab' => FabTheme::class, 2914ca7e03cSGreg Roach 'fact_sources' => FactSourcesReportModule::class, 2924ca7e03cSGreg Roach 'family_book_chart' => FamilyBookChartModule::class, 2934ca7e03cSGreg Roach 'family_group_report' => FamilyGroupReportModule::class, 29467992b6aSRichard Cissee 'family_list' => FamilyListModule::class, 2954ca7e03cSGreg Roach 'family_nav' => FamilyNavigatorModule::class, 2964ca7e03cSGreg Roach 'fan_chart' => FanChartModule::class, 2974ca7e03cSGreg Roach 'faq' => FrequentlyAskedQuestionsModule::class, 2984ca7e03cSGreg Roach 'gedcom_block' => WelcomeBlockModule::class, 2994ca7e03cSGreg Roach 'gedcom_favorites' => FamilyTreeFavoritesModule::class, 3004ca7e03cSGreg Roach 'gedcom_news' => FamilyTreeNewsModule::class, 3014ca7e03cSGreg Roach 'gedcom_stats' => FamilyTreeStatisticsModule::class, 3024ca7e03cSGreg Roach 'google-analytics' => GoogleAnalyticsModule::class, 3034ca7e03cSGreg Roach 'google-webmaster-tools' => GoogleWebmasterToolsModule::class, 3044ca7e03cSGreg Roach 'hit-counter' => HitCountFooterModule::class, 3054ca7e03cSGreg Roach 'hourglass_chart' => HourglassChartModule::class, 3064ca7e03cSGreg Roach 'html' => HtmlBlockModule::class, 3074ca7e03cSGreg Roach 'individual_ext_report' => IndividualFamiliesReportModule::class, 30867992b6aSRichard Cissee 'individual_list' => IndividualListModule::class, 3094ca7e03cSGreg Roach 'individual_report' => IndividualReportModule::class, 31002086832SGreg Roach 'language-af' => LanguageAfrikaans::class, 31102086832SGreg Roach 'language-ar' => LanguageArabic::class, 31202086832SGreg Roach 'language-bs' => LanguageBosnian::class, 31302086832SGreg Roach 'language-bu' => LanguageBulgarian::class, 31402086832SGreg Roach 'language-ca' => LanguageCatalan::class, 31502086832SGreg Roach 'language-cs' => LanguageCzech::class, 31602086832SGreg Roach 'language-da' => LanguageDanish::class, 31702086832SGreg Roach 'language-de' => LanguageGerman::class, 31802086832SGreg Roach 'language-dv' => LanguageDivehi::class, 31902086832SGreg Roach 'language-el' => LanguageGreek::class, 32002086832SGreg Roach 'language-en-AU' => LanguageEnglishAustralia::class, 32102086832SGreg Roach 'language-en-GB' => LanguageEnglishGreatBritain::class, 32202086832SGreg Roach 'language-en-US' => LanguageEnglishUnitedStates::class, 32302086832SGreg Roach 'language-es' => LanguageSpanish::class, 32402086832SGreg Roach 'language-et' => LanguageEstonian::class, 32502086832SGreg Roach 'language-fa' => LanguageFarsi::class, 32602086832SGreg Roach 'language-fi' => LanguageFinnish::class, 32702086832SGreg Roach 'language-fo' => LanguageFaroese::class, 32802086832SGreg Roach 'language-fr' => LanguageFrench::class, 32902086832SGreg Roach 'language-fr-CA' => LanguageFrenchCanada::class, 33002086832SGreg Roach 'language-gl' => LanguageGalician::class, 33102086832SGreg Roach 'language-he' => LanguageHebrew::class, 332*0f180719SGreg Roach 'language-hi' => LanguageHindi::class, 33302086832SGreg Roach 'language-hr' => LanguageCroatian::class, 33402086832SGreg Roach 'language-hu' => LanguageHungarian::class, 33502086832SGreg Roach 'language-id' => LanguageIndonesian::class, 33602086832SGreg Roach 'language-is' => LanguageIcelandic::class, 33702086832SGreg Roach 'language-it' => LanguageItalian::class, 33802086832SGreg Roach 'language-ja' => LanguageJapanese::class, 33902086832SGreg Roach 'language-jv' => LanguageJavanese::class, 34002086832SGreg Roach 'language-ka' => LanguageGeorgian::class, 34102086832SGreg Roach 'language-kk' => LanguageKazhak::class, 34202086832SGreg Roach 'language-ko' => LanguageKorean::class, 34302086832SGreg Roach 'language-ln' => LanguageLingala::class, 34402086832SGreg Roach 'language-lt' => LanguageLithuanian::class, 34502086832SGreg Roach 'language-lv' => LanguageLatvian::class, 34602086832SGreg Roach 'language-mi' => LanguageMaori::class, 34702086832SGreg Roach 'language-mr' => LanguageMarathi::class, 34802086832SGreg Roach 'language-ms' => LanguageMalay::class, 34902086832SGreg Roach 'language-nb' => LanguageNorwegianBokmal::class, 35002086832SGreg Roach 'language-ne' => LanguageNepalese::class, 35102086832SGreg Roach 'language-nl' => LanguageDutch::class, 35202086832SGreg Roach 'language-nn' => LanguageNorwegianNynorsk::class, 35302086832SGreg Roach 'language-oc' => LanguageOccitan::class, 35402086832SGreg Roach 'language-pl' => LanguagePolish::class, 35502086832SGreg Roach 'language-pt' => LanguagePortuguese::class, 35602086832SGreg Roach 'language-pt-BR' => LanguagePortugueseBrazil::class, 35702086832SGreg Roach 'language-ro' => LanguageRomanian::class, 35802086832SGreg Roach 'language-ru' => LanguageRussian::class, 35902086832SGreg Roach 'language-sk' => LanguageSlovakian::class, 36002086832SGreg Roach 'language-sl' => LanguageSlovenian::class, 36102086832SGreg Roach 'language-sq' => LanguageAlbanian::class, 36202086832SGreg Roach 'language-sr' => LanguageSerbian::class, 36302086832SGreg Roach 'language-sr-Latn' => LanguageSerbianLatin::class, 36402086832SGreg Roach 'language-su' => LanguageSundanese::class, 36502086832SGreg Roach 'language-sv' => LanguageSwedish::class, 36602086832SGreg Roach 'language-sw' => LanguageSwahili::class, 36702086832SGreg Roach 'language-ta' => LanguageTamil::class, 36802086832SGreg Roach 'language-th' => LanguageThai::class, 36902086832SGreg Roach 'language-tr' => LanguageTurkish::class, 37002086832SGreg Roach 'language-tt' => LanguageTatar::class, 37102086832SGreg Roach 'language-uk' => LanguageUkranian::class, 37202086832SGreg Roach 'language-vi' => LanguageVietnamese::class, 37302086832SGreg Roach 'language-yi' => LanguageYiddish::class, 37402086832SGreg Roach 'language-zh-Hans' => LanguageChineseSimplified::class, 37502086832SGreg Roach 'language-zh-Hant' => LanguageChineseTraditional::class, 3764ca7e03cSGreg Roach 'lifespans_chart' => LifespansChartModule::class, 3774ca7e03cSGreg Roach 'lightbox' => AlbumModule::class, 3784ca7e03cSGreg Roach 'lists-menu' => ListsMenuModule::class, 3794ca7e03cSGreg Roach 'logged_in' => LoggedInUsersModule::class, 3804ca7e03cSGreg Roach 'login_block' => LoginBlockModule::class, 3814ca7e03cSGreg Roach 'marriage_report' => MarriageReportModule::class, 3824ca7e03cSGreg Roach 'matomo-analytics' => MatomoAnalyticsModule::class, 3834ca7e03cSGreg Roach 'media' => MediaTabModule::class, 38467992b6aSRichard Cissee 'media_list' => MediaListModule::class, 3854ca7e03cSGreg Roach 'minimal' => MinimalTheme::class, 3864ca7e03cSGreg Roach 'missing_facts_report' => MissingFactsReportModule::class, 3874ca7e03cSGreg Roach 'notes' => NotesTabModule::class, 38867992b6aSRichard Cissee 'note_list' => NoteListModule::class, 3894ca7e03cSGreg Roach 'occupation_report' => OccupationReportModule::class, 3904ca7e03cSGreg Roach 'pedigree-map' => PedigreeMapModule::class, 3914ca7e03cSGreg Roach 'pedigree_chart' => PedigreeChartModule::class, 3924ca7e03cSGreg Roach 'pedigree_report' => PedigreeReportModule::class, 3934ca7e03cSGreg Roach 'personal_facts' => IndividualFactsTabModule::class, 3944ca7e03cSGreg Roach 'places' => PlacesModule::class, 39567992b6aSRichard Cissee 'places_list' => PlaceHierarchyListModule::class, 3964ca7e03cSGreg Roach 'powered-by-webtrees' => PoweredByWebtreesModule::class, 397b3a775f6SGreg Roach 'privacy-policy' => PrivacyPolicy::class, 3984ca7e03cSGreg Roach 'random_media' => SlideShowModule::class, 3994ca7e03cSGreg Roach 'recent_changes' => RecentChangesModule::class, 4004ca7e03cSGreg Roach 'relationships_chart' => RelationshipsChartModule::class, 4014ca7e03cSGreg Roach 'relative_ext_report' => RelatedIndividualsReportModule::class, 4024ca7e03cSGreg Roach 'relatives' => RelativesTabModule::class, 4034ca7e03cSGreg Roach 'reports-menu' => ReportsMenuModule::class, 40467992b6aSRichard Cissee 'repository_list' => RepositoryListModule::class, 4054ca7e03cSGreg Roach 'review_changes' => ReviewChangesModule::class, 4064ca7e03cSGreg Roach 'search-menu' => SearchMenuModule::class, 4074ca7e03cSGreg Roach 'sitemap' => SiteMapModule::class, 40867992b6aSRichard Cissee 'source_list' => SourceListModule::class, 4094ca7e03cSGreg Roach 'sources_tab' => SourcesTabModule::class, 4104ca7e03cSGreg Roach 'statcounter' => StatcounterModule::class, 4114ca7e03cSGreg Roach 'statistics_chart' => StatisticsChartModule::class, 4124ca7e03cSGreg Roach 'stories' => StoriesModule::class, 4134ca7e03cSGreg Roach 'theme_select' => ThemeSelectModule::class, 4144ca7e03cSGreg Roach 'timeline_chart' => TimelineChartModule::class, 4154ca7e03cSGreg Roach 'todays_events' => OnThisDayModule::class, 4164ca7e03cSGreg Roach 'todo' => ResearchTaskModule::class, 4174ca7e03cSGreg Roach 'top10_givnnames' => TopGivenNamesModule::class, 4184ca7e03cSGreg Roach 'top10_pageviews' => TopPageViewsModule::class, 4194ca7e03cSGreg Roach 'top10_surnames' => TopSurnamesModule::class, 4204ca7e03cSGreg Roach 'tree' => InteractiveTreeModule::class, 4214ca7e03cSGreg Roach 'trees-menu' => TreesMenuModule::class, 4224ca7e03cSGreg Roach 'upcoming_events' => UpcomingAnniversariesModule::class, 42309fbf3e5SGreg Roach 'us-presidents' => USPresidents::class, 4244ca7e03cSGreg Roach 'user_blog' => UserJournalModule::class, 4254ca7e03cSGreg Roach 'user_favorites' => UserFavoritesModule::class, 4264ca7e03cSGreg Roach 'user_messages' => UserMessagesModule::class, 4274ca7e03cSGreg Roach 'user_welcome' => UserWelcomeModule::class, 4284ca7e03cSGreg Roach 'webtrees' => WebtreesTheme::class, 4294ca7e03cSGreg Roach 'xenea' => XeneaTheme::class, 4304ca7e03cSGreg Roach 'yahrzeit' => YahrzeitModule::class, 4314ca7e03cSGreg Roach ]; 4324ca7e03cSGreg Roach 4334ca7e03cSGreg Roach /** 434dedcf571SGreg Roach * A function to convert modules into their titles - to create option lists, etc. 435dedcf571SGreg Roach * 436dedcf571SGreg Roach * @return Closure 437dedcf571SGreg Roach */ 438dedcf571SGreg Roach public function titleMapper(): Closure 439dedcf571SGreg Roach { 4406c2179e2SGreg Roach return static function (ModuleInterface $module): string { 441dedcf571SGreg Roach return $module->title(); 442dedcf571SGreg Roach }; 443dedcf571SGreg Roach } 444dedcf571SGreg Roach 445dedcf571SGreg Roach /** 4464ca7e03cSGreg Roach * Modules which (a) provide a specific function and (b) we have permission to see. 4474ca7e03cSGreg Roach * 44887cca37cSGreg Roach * @param string $interface 4494ca7e03cSGreg Roach * @param Tree $tree 450e5a6b4d4SGreg Roach * @param UserInterface $user 4514ca7e03cSGreg Roach * 45254c7f8dfSGreg Roach * @return Collection 4534ca7e03cSGreg Roach */ 45487cca37cSGreg Roach public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection 4554ca7e03cSGreg Roach { 456b5979037SGreg Roach return $this->findByInterface($interface, false, true) 4570b5fd0a6SGreg Roach ->filter(static function (ModuleInterface $module) use ($interface, $tree, $user): bool { 45887cca37cSGreg Roach return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user); 4594ca7e03cSGreg Roach }); 4604ca7e03cSGreg Roach } 4614ca7e03cSGreg Roach 4624ca7e03cSGreg Roach /** 4634ca7e03cSGreg Roach * All modules which provide a specific function. 4644ca7e03cSGreg Roach * 4654ca7e03cSGreg Roach * @param string $interface 4664ca7e03cSGreg Roach * @param bool $include_disabled 467b5979037SGreg Roach * @param bool $sort 4684ca7e03cSGreg Roach * 46954c7f8dfSGreg Roach * @return Collection 4704ca7e03cSGreg Roach */ 471b5979037SGreg Roach public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection 4724ca7e03cSGreg Roach { 4739d627a9eSGreg Roach $modules = $this->all($include_disabled) 4749d627a9eSGreg Roach ->filter($this->interfaceFilter($interface)); 4754ca7e03cSGreg Roach 4764ca7e03cSGreg Roach switch ($interface) { 4774ca7e03cSGreg Roach case ModuleFooterInterface::class: 478bf57b580SGreg Roach return $modules->sort($this->footerSorter()); 4794ca7e03cSGreg Roach 4804ca7e03cSGreg Roach case ModuleMenuInterface::class: 481bf57b580SGreg Roach return $modules->sort($this->menuSorter()); 4824ca7e03cSGreg Roach 4834ca7e03cSGreg Roach case ModuleSidebarInterface::class: 484bf57b580SGreg Roach return $modules->sort($this->sidebarSorter()); 4854ca7e03cSGreg Roach 4864ca7e03cSGreg Roach case ModuleTabInterface::class: 487bf57b580SGreg Roach return $modules->sort($this->tabSorter()); 488b5979037SGreg Roach 489b5979037SGreg Roach default: 490b5979037SGreg Roach if ($sort) { 491b5979037SGreg Roach return $modules->sort($this->moduleSorter()); 4924ca7e03cSGreg Roach } 4934ca7e03cSGreg Roach 4944ca7e03cSGreg Roach return $modules; 4954ca7e03cSGreg Roach } 496b5979037SGreg Roach } 4974ca7e03cSGreg Roach 4984ca7e03cSGreg Roach /** 4998d6560c4SGreg Roach * All modules. 5008d6560c4SGreg Roach * 5018d6560c4SGreg Roach * @param bool $include_disabled 5028d6560c4SGreg Roach * 5038d6560c4SGreg Roach * @return Collection 5048d6560c4SGreg Roach */ 5058d6560c4SGreg Roach public function all(bool $include_disabled = false): Collection 5068d6560c4SGreg Roach { 5078d6560c4SGreg Roach return app('cache.array')->rememberForever('all_modules', function (): Collection { 5088d6560c4SGreg Roach // Modules have a default status, order etc. 5098d6560c4SGreg Roach // We can override these from database settings. 5108d6560c4SGreg Roach $module_info = DB::table('module') 5118d6560c4SGreg Roach ->get() 5120b5fd0a6SGreg Roach ->mapWithKeys(static function (stdClass $row): array { 5138d6560c4SGreg Roach return [$row->module_name => $row]; 5148d6560c4SGreg Roach }); 5158d6560c4SGreg Roach 5168d6560c4SGreg Roach return $this->coreModules() 5178d6560c4SGreg Roach ->merge($this->customModules()) 5180b5fd0a6SGreg Roach ->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface { 5198d6560c4SGreg Roach $info = $module_info->get($module->name()); 5208d6560c4SGreg Roach 5218d6560c4SGreg Roach if ($info instanceof stdClass) { 5228d6560c4SGreg Roach $module->setEnabled($info->status === 'enabled'); 5238d6560c4SGreg Roach 5248d6560c4SGreg Roach if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) { 5258d6560c4SGreg Roach $module->setFooterOrder((int) $info->footer_order); 5268d6560c4SGreg Roach } 5278d6560c4SGreg Roach 5288d6560c4SGreg Roach if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) { 5298d6560c4SGreg Roach $module->setMenuOrder((int) $info->menu_order); 5308d6560c4SGreg Roach } 5318d6560c4SGreg Roach 5328d6560c4SGreg Roach if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) { 5338d6560c4SGreg Roach $module->setSidebarOrder((int) $info->sidebar_order); 5348d6560c4SGreg Roach } 5358d6560c4SGreg Roach 5368d6560c4SGreg Roach if ($module instanceof ModuleTabInterface && $info->tab_order !== null) { 5378d6560c4SGreg Roach $module->setTabOrder((int) $info->tab_order); 5388d6560c4SGreg Roach } 5398d6560c4SGreg Roach } else { 5408d6560c4SGreg Roach $module->setEnabled($module->isEnabledByDefault()); 5418d6560c4SGreg Roach 5428d6560c4SGreg Roach DB::table('module')->insert([ 5438d6560c4SGreg Roach 'module_name' => $module->name(), 5448d6560c4SGreg Roach 'status' => $module->isEnabled() ? 'enabled' : 'disabled', 5458d6560c4SGreg Roach ]); 5468d6560c4SGreg Roach } 5478d6560c4SGreg Roach 5488d6560c4SGreg Roach return $module; 5498d6560c4SGreg Roach }); 5508d6560c4SGreg Roach })->filter($this->enabledFilter($include_disabled)); 5518d6560c4SGreg Roach } 5528d6560c4SGreg Roach 5538d6560c4SGreg Roach /** 5548d6560c4SGreg Roach * All core modules in the system. 5558d6560c4SGreg Roach * 5568d6560c4SGreg Roach * @return Collection 5578d6560c4SGreg Roach */ 5588d6560c4SGreg Roach private function coreModules(): Collection 5598d6560c4SGreg Roach { 5608d6560c4SGreg Roach return Collection::make(self::CORE_MODULES) 5610b5fd0a6SGreg Roach ->map(static function (string $class, string $name): ModuleInterface { 5628d6560c4SGreg Roach $module = app($class); 5638d6560c4SGreg Roach 5648d6560c4SGreg Roach $module->setName($name); 5658d6560c4SGreg Roach 5668d6560c4SGreg Roach return $module; 5678d6560c4SGreg Roach }); 5688d6560c4SGreg Roach } 5698d6560c4SGreg Roach 5708d6560c4SGreg Roach /** 5718d6560c4SGreg Roach * All custom modules in the system. Custom modules are defined in modules_v4/ 5728d6560c4SGreg Roach * 5738d6560c4SGreg Roach * @return Collection 5748d6560c4SGreg Roach */ 5758d6560c4SGreg Roach private function customModules(): Collection 5768d6560c4SGreg Roach { 577f397d0fdSGreg Roach $pattern = Webtrees::MODULES_DIR . '*/module.php'; 5788d6560c4SGreg Roach $filenames = glob($pattern, GLOB_NOSORT); 5798d6560c4SGreg Roach 5808d6560c4SGreg Roach return Collection::make($filenames) 5810b5fd0a6SGreg Roach ->filter(static function (string $filename): bool { 5828d6560c4SGreg Roach // Special characters will break PHP variable names. 5838d6560c4SGreg Roach // This also allows us to ignore modules called "foo.example" and "foo.disable" 5848d6560c4SGreg Roach $module_name = basename(dirname($filename)); 5858d6560c4SGreg Roach 5868d6560c4SGreg Roach return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30; 5878d6560c4SGreg Roach }) 5880b5fd0a6SGreg Roach ->map(static function (string $filename): ?ModuleCustomInterface { 5898d6560c4SGreg Roach try { 5908d6560c4SGreg Roach $module = self::load($filename); 5918d6560c4SGreg Roach 5928d6560c4SGreg Roach if ($module instanceof ModuleCustomInterface) { 5938d6560c4SGreg Roach $module_name = '_' . basename(dirname($filename)) . '_'; 5948d6560c4SGreg Roach 5958d6560c4SGreg Roach $module->setName($module_name); 5968d6560c4SGreg Roach } else { 5978d6560c4SGreg Roach return null; 5988d6560c4SGreg Roach } 5998d6560c4SGreg Roach 6008d6560c4SGreg Roach return $module; 6018d6560c4SGreg Roach } catch (Throwable $ex) { 6028d6560c4SGreg Roach // It would be nice to show this error in a flash-message or similar, but the framework 6038d6560c4SGreg Roach // has not yet been initialised so we have no themes, languages, sessions, etc. 6048d6560c4SGreg Roach throw $ex; 6058d6560c4SGreg Roach } 6068d6560c4SGreg Roach }) 6078d6560c4SGreg Roach ->filter() 6080b5fd0a6SGreg Roach ->mapWithKeys(static function (ModuleCustomInterface $module): array { 6098d6560c4SGreg Roach return [$module->name() => $module]; 6108d6560c4SGreg Roach }); 6118d6560c4SGreg Roach } 6128d6560c4SGreg Roach 6138d6560c4SGreg Roach /** 61402086832SGreg Roach * During setup, we'll need access to some languages. 61502086832SGreg Roach * 61602086832SGreg Roach * @return Collection 61702086832SGreg Roach */ 61802086832SGreg Roach public function setupLanguages(): Collection 61902086832SGreg Roach { 62002086832SGreg Roach return $this->coreModules() 6210b93976aSGreg Roach ->filter(static function (ModuleInterface $module): bool { 62202086832SGreg Roach return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault(); 62302086832SGreg Roach }) 6240b93976aSGreg Roach ->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y): int { 625c116a5ccSGreg Roach return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable(); 626c116a5ccSGreg Roach }); 62702086832SGreg Roach } 62802086832SGreg Roach 62902086832SGreg Roach /** 6305bc7939cSBen * Load a custom module in a static scope, to prevent it from modifying local or object variables. 6318d6560c4SGreg Roach * 6328d6560c4SGreg Roach * @param string $filename 6338d6560c4SGreg Roach * 6348d6560c4SGreg Roach * @return mixed 6358d6560c4SGreg Roach */ 6368d6560c4SGreg Roach private static function load(string $filename) 6378d6560c4SGreg Roach { 6385bc7939cSBen try { 6398d6560c4SGreg Roach return include $filename; 640ad602e4bSGreg Roach } catch (Throwable $exception) { 6415bc7939cSBen $module_name = basename(dirname($filename)); 642ad602e4bSGreg Roach $message = 'Fatal error in module: ' . $module_name; 643ad602e4bSGreg Roach $message .= '<br>' . $exception; 644ad602e4bSGreg Roach FlashMessages::addMessage($message, 'danger'); 6455bc7939cSBen } 6465bc7939cSBen return null; 6478d6560c4SGreg Roach } 6488d6560c4SGreg Roach 6498d6560c4SGreg Roach /** 6508d6560c4SGreg Roach * A function filter modules by enabled/disabled 6518d6560c4SGreg Roach * 6528d6560c4SGreg Roach * @param bool $include_disabled 6538d6560c4SGreg Roach * 6548d6560c4SGreg Roach * @return Closure 6558d6560c4SGreg Roach */ 6568d6560c4SGreg Roach private function enabledFilter(bool $include_disabled): Closure 6578d6560c4SGreg Roach { 6586c2179e2SGreg Roach return static function (ModuleInterface $module) use ($include_disabled): bool { 6598d6560c4SGreg Roach return $include_disabled || $module->isEnabled(); 6608d6560c4SGreg Roach }; 6618d6560c4SGreg Roach } 6628d6560c4SGreg Roach 6638d6560c4SGreg Roach /** 6648d6560c4SGreg Roach * A function filter modules by type 6658d6560c4SGreg Roach * 6668d6560c4SGreg Roach * @param string $interface 6678d6560c4SGreg Roach * 6688d6560c4SGreg Roach * @return Closure 6698d6560c4SGreg Roach */ 6708d6560c4SGreg Roach private function interfaceFilter(string $interface): Closure 6718d6560c4SGreg Roach { 6726c2179e2SGreg Roach return static function (ModuleInterface $module) use ($interface): bool { 6738d6560c4SGreg Roach return $module instanceof $interface; 6748d6560c4SGreg Roach }; 6758d6560c4SGreg Roach } 6768d6560c4SGreg Roach 6778d6560c4SGreg Roach /** 6788d6560c4SGreg Roach * A function to sort footers 6798d6560c4SGreg Roach * 6808d6560c4SGreg Roach * @return Closure 6818d6560c4SGreg Roach */ 6828d6560c4SGreg Roach private function footerSorter(): Closure 6838d6560c4SGreg Roach { 6846c2179e2SGreg Roach return static function (ModuleFooterInterface $x, ModuleFooterInterface $y): int { 6858d6560c4SGreg Roach return $x->getFooterOrder() <=> $y->getFooterOrder(); 6868d6560c4SGreg Roach }; 6878d6560c4SGreg Roach } 6888d6560c4SGreg Roach 6898d6560c4SGreg Roach /** 6908d6560c4SGreg Roach * A function to sort menus 6918d6560c4SGreg Roach * 6928d6560c4SGreg Roach * @return Closure 6938d6560c4SGreg Roach */ 6948d6560c4SGreg Roach private function menuSorter(): Closure 6958d6560c4SGreg Roach { 6966c2179e2SGreg Roach return static function (ModuleMenuInterface $x, ModuleMenuInterface $y): int { 6978d6560c4SGreg Roach return $x->getMenuOrder() <=> $y->getMenuOrder(); 6988d6560c4SGreg Roach }; 6998d6560c4SGreg Roach } 7008d6560c4SGreg Roach 7018d6560c4SGreg Roach /** 7028d6560c4SGreg Roach * A function to sort menus 7038d6560c4SGreg Roach * 7048d6560c4SGreg Roach * @return Closure 7058d6560c4SGreg Roach */ 7068d6560c4SGreg Roach private function sidebarSorter(): Closure 7078d6560c4SGreg Roach { 7086c2179e2SGreg Roach return static function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int { 7098d6560c4SGreg Roach return $x->getSidebarOrder() <=> $y->getSidebarOrder(); 7108d6560c4SGreg Roach }; 7118d6560c4SGreg Roach } 7128d6560c4SGreg Roach 7138d6560c4SGreg Roach /** 7148d6560c4SGreg Roach * A function to sort menus 7158d6560c4SGreg Roach * 7168d6560c4SGreg Roach * @return Closure 7178d6560c4SGreg Roach */ 7188d6560c4SGreg Roach private function tabSorter(): Closure 7198d6560c4SGreg Roach { 7206c2179e2SGreg Roach return static function (ModuleTabInterface $x, ModuleTabInterface $y): int { 7218d6560c4SGreg Roach return $x->getTabOrder() <=> $y->getTabOrder(); 7228d6560c4SGreg Roach }; 7238d6560c4SGreg Roach } 7248d6560c4SGreg Roach 7258d6560c4SGreg Roach /** 72602086832SGreg Roach * A function to sort modules by name. 72702086832SGreg Roach * 72802086832SGreg Roach * Languages have a "sortable" name, so that "British English" sorts as "English, British". 72902086832SGreg Roach * This provides a more natural order in the language menu. 7308d6560c4SGreg Roach * 7318d6560c4SGreg Roach * @return Closure 7328d6560c4SGreg Roach */ 7338d6560c4SGreg Roach private function moduleSorter(): Closure 7348d6560c4SGreg Roach { 7356c2179e2SGreg Roach return static function (ModuleInterface $x, ModuleInterface $y): int { 73602086832SGreg Roach $title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title(); 73702086832SGreg Roach $title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title(); 73802086832SGreg Roach 73902086832SGreg Roach return I18N::strcasecmp($title1, $title2); 7408d6560c4SGreg Roach }; 7418d6560c4SGreg Roach } 7428d6560c4SGreg Roach 7438d6560c4SGreg Roach /** 7444ca7e03cSGreg Roach * Find a specified module, if it is currently active. 7454ca7e03cSGreg Roach * 7464ca7e03cSGreg Roach * @param string $module_name 747321a89daSGreg Roach * @param bool $include_disabled 7484ca7e03cSGreg Roach * 7494ca7e03cSGreg Roach * @return ModuleInterface|null 7504ca7e03cSGreg Roach */ 751321a89daSGreg Roach public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface 7524ca7e03cSGreg Roach { 7539d627a9eSGreg Roach return $this->all($include_disabled) 7540797053bSGreg Roach ->first(static function (ModuleInterface $module) use ($module_name): bool { 755321a89daSGreg Roach return $module->name() === $module_name; 7560797053bSGreg Roach }); 7574ca7e03cSGreg Roach } 758bf57b580SGreg Roach 759bf57b580SGreg Roach /** 760bf57b580SGreg Roach * Configuration settings are available through the various "module component" pages. 761bf57b580SGreg Roach * For modules that do not provide a component, we need to list them separately. 762bf57b580SGreg Roach * 76309fbf3e5SGreg Roach * @param bool $include_disabled 76409fbf3e5SGreg Roach * 76554c7f8dfSGreg Roach * @return Collection 766bf57b580SGreg Roach */ 76709fbf3e5SGreg Roach public function otherModules(bool $include_disabled = false): Collection 768bf57b580SGreg Roach { 769abafa13cSGreg Roach return $this->findByInterface(ModuleInterface::class, $include_disabled, true) 7700b5fd0a6SGreg Roach ->filter(static function (ModuleInterface $module): bool { 771bf57b580SGreg Roach foreach (self::COMPONENTS as $interface) { 772bf57b580SGreg Roach if ($module instanceof $interface) { 773bf57b580SGreg Roach return false; 774bf57b580SGreg Roach } 775bf57b580SGreg Roach } 776bf57b580SGreg Roach 777bf57b580SGreg Roach return true; 778bf57b580SGreg Roach }); 779bf57b580SGreg Roach } 780bf57b580SGreg Roach 781bf57b580SGreg Roach /** 782bf57b580SGreg Roach * Generate a list of module names which exist in the database but not on disk. 783bf57b580SGreg Roach * 78454c7f8dfSGreg Roach * @return Collection 785bf57b580SGreg Roach */ 786bf57b580SGreg Roach public function deletedModules(): Collection 787bf57b580SGreg Roach { 788bf57b580SGreg Roach $database_modules = DB::table('module')->pluck('module_name'); 789bf57b580SGreg Roach 790d5d58984SGreg Roach $disk_modules = $this->all(true) 7910b5fd0a6SGreg Roach ->map(static function (ModuleInterface $module): string { 792bf57b580SGreg Roach return $module->name(); 793bf57b580SGreg Roach }); 794bf57b580SGreg Roach 795bf57b580SGreg Roach return $database_modules->diff($disk_modules); 796bf57b580SGreg Roach } 79771378461SGreg Roach 79871378461SGreg Roach /** 79971378461SGreg Roach * Boot all the modules. 80071378461SGreg Roach * 80171378461SGreg Roach * @param ModuleThemeInterface $current_theme 80271378461SGreg Roach */ 803c81b7bf1SGreg Roach public function bootModules(ModuleThemeInterface $current_theme): void 804c81b7bf1SGreg Roach { 8059e18e23bSGreg Roach foreach ($this->all() as $module) { 80671378461SGreg Roach // Only bootstrap the current theme. 80771378461SGreg Roach if ($module instanceof ModuleThemeInterface && $module !== $current_theme) { 80871378461SGreg Roach continue; 80971378461SGreg Roach } 81071378461SGreg Roach 8119e18e23bSGreg Roach $module->boot(); 81271378461SGreg Roach } 81371378461SGreg Roach } 814745968f0SGreg Roach 815745968f0SGreg Roach /** 816745968f0SGreg Roach * @return string[] 817745968f0SGreg Roach */ 818745968f0SGreg Roach public function componentsWithAccess(): array 819745968f0SGreg Roach { 820745968f0SGreg Roach return self::COMPONENTS_WITH_ACCESS; 821745968f0SGreg Roach } 822745968f0SGreg Roach 823745968f0SGreg Roach /** 824745968f0SGreg Roach * @return string[] 825745968f0SGreg Roach */ 826745968f0SGreg Roach public function componentsWithOrder(): array 827745968f0SGreg Roach { 828745968f0SGreg Roach return self::COMPONENTS_WITH_SORT; 829745968f0SGreg Roach } 8304ca7e03cSGreg Roach} 831