1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Services; 21 22use Closure; 23use Fisharebest\Webtrees\Auth; 24use Fisharebest\Webtrees\Contracts\UserInterface; 25use Fisharebest\Webtrees\FlashMessages; 26use Fisharebest\Webtrees\I18N; 27use Fisharebest\Webtrees\Module\AhnentafelReportModule; 28use Fisharebest\Webtrees\Module\AlbumModule; 29use Fisharebest\Webtrees\Module\AncestorsChartModule; 30use Fisharebest\Webtrees\Module\AustrianHistoricEvents; 31use Fisharebest\Webtrees\Module\AustrianPresidents; 32use Fisharebest\Webtrees\Module\BingWebmasterToolsModule; 33use Fisharebest\Webtrees\Module\BirthDeathMarriageReportModule; 34use Fisharebest\Webtrees\Module\BirthReportModule; 35use Fisharebest\Webtrees\Module\BranchesListModule; 36use Fisharebest\Webtrees\Module\BritishMonarchs; 37use Fisharebest\Webtrees\Module\BritishPrimeMinisters; 38use Fisharebest\Webtrees\Module\BritishSocialHistory; 39use Fisharebest\Webtrees\Module\CalendarMenuModule; 40use Fisharebest\Webtrees\Module\CemeteryReportModule; 41use Fisharebest\Webtrees\Module\CensusAssistantModule; 42use Fisharebest\Webtrees\Module\ChangeReportModule; 43use Fisharebest\Webtrees\Module\ChartsBlockModule; 44use Fisharebest\Webtrees\Module\ChartsMenuModule; 45use Fisharebest\Webtrees\Module\CkeditorModule; 46use Fisharebest\Webtrees\Module\ClippingsCartModule; 47use Fisharebest\Webtrees\Module\CloudsTheme; 48use Fisharebest\Webtrees\Module\ColorsTheme; 49use Fisharebest\Webtrees\Module\CompactTreeChartModule; 50use Fisharebest\Webtrees\Module\ContactsFooterModule; 51use Fisharebest\Webtrees\Module\CustomCssJsModule; 52use Fisharebest\Webtrees\Module\CustomTagsAldfaer; 53use Fisharebest\Webtrees\Module\CustomTagsAncestry; 54use Fisharebest\Webtrees\Module\CustomTagsBrothersKeeper; 55use Fisharebest\Webtrees\Module\CustomTagsFamilySearch; 56use Fisharebest\Webtrees\Module\CustomTagsFamilyTreeBuilder; 57use Fisharebest\Webtrees\Module\CustomTagsFamilyTreeMaker; 58use Fisharebest\Webtrees\Module\CustomTagsGedcom53; 59use Fisharebest\Webtrees\Module\CustomTagsGedcomL; 60use Fisharebest\Webtrees\Module\CustomTagsGenPluswin; 61use Fisharebest\Webtrees\Module\CustomTagsLegacy; 62use Fisharebest\Webtrees\Module\CustomTagsPersonalAncestralFile; 63use Fisharebest\Webtrees\Module\CustomTagsPhpGedView; 64use Fisharebest\Webtrees\Module\CustomTagsReunion; 65use Fisharebest\Webtrees\Module\CustomTagsRootsMagic; 66use Fisharebest\Webtrees\Module\CustomTagsTheMasterGenealogist; 67use Fisharebest\Webtrees\Module\CustomTagsWebtrees; 68use Fisharebest\Webtrees\Module\CzechMonarchsAndPresidents; 69use Fisharebest\Webtrees\Module\DeathReportModule; 70use Fisharebest\Webtrees\Module\DescendancyChartModule; 71use Fisharebest\Webtrees\Module\DescendancyModule; 72use Fisharebest\Webtrees\Module\DescendancyReportModule; 73use Fisharebest\Webtrees\Module\DutchMonarchs; 74use Fisharebest\Webtrees\Module\DutchPrimeMinisters; 75use Fisharebest\Webtrees\Module\EsriMaps; 76use Fisharebest\Webtrees\Module\FabTheme; 77use Fisharebest\Webtrees\Module\FactSourcesReportModule; 78use Fisharebest\Webtrees\Module\FamilyBookChartModule; 79use Fisharebest\Webtrees\Module\FamilyGroupReportModule; 80use Fisharebest\Webtrees\Module\FamilyListModule; 81use Fisharebest\Webtrees\Module\FamilyNavigatorModule; 82use Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule; 83use Fisharebest\Webtrees\Module\FamilyTreeNewsModule; 84use Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule; 85use Fisharebest\Webtrees\Module\FanChartModule; 86use Fisharebest\Webtrees\Module\FixCemeteryTag; 87use Fisharebest\Webtrees\Module\FixDuplicateLinks; 88use Fisharebest\Webtrees\Module\FixMissingDeaths; 89use Fisharebest\Webtrees\Module\FixNameSlashesAndSpaces; 90use Fisharebest\Webtrees\Module\FixNameTags; 91use Fisharebest\Webtrees\Module\FixPlaceNames; 92use Fisharebest\Webtrees\Module\FixPrimaryTag; 93use Fisharebest\Webtrees\Module\FixSearchAndReplace; 94use Fisharebest\Webtrees\Module\FrenchHistory; 95use Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule; 96use Fisharebest\Webtrees\Module\GeonamesAutocomplete; 97use Fisharebest\Webtrees\Module\GoogleAnalyticsModule; 98use Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule; 99use Fisharebest\Webtrees\Module\HereMaps; 100use Fisharebest\Webtrees\Module\HitCountFooterModule; 101use Fisharebest\Webtrees\Module\HourglassChartModule; 102use Fisharebest\Webtrees\Module\HtmlBlockModule; 103use Fisharebest\Webtrees\Module\IndividualFactsTabModule; 104use Fisharebest\Webtrees\Module\IndividualFamiliesReportModule; 105use Fisharebest\Webtrees\Module\IndividualListModule; 106use Fisharebest\Webtrees\Module\IndividualMetadataModule; 107use Fisharebest\Webtrees\Module\IndividualReportModule; 108use Fisharebest\Webtrees\Module\InteractiveTreeModule; 109use Fisharebest\Webtrees\Module\LanguageAfrikaans; 110use Fisharebest\Webtrees\Module\LanguageAlbanian; 111use Fisharebest\Webtrees\Module\LanguageArabic; 112use Fisharebest\Webtrees\Module\LanguageBosnian; 113use Fisharebest\Webtrees\Module\LanguageBulgarian; 114use Fisharebest\Webtrees\Module\LanguageCatalan; 115use Fisharebest\Webtrees\Module\LanguageChineseSimplified; 116use Fisharebest\Webtrees\Module\LanguageChineseTraditional; 117use Fisharebest\Webtrees\Module\LanguageCroatian; 118use Fisharebest\Webtrees\Module\LanguageCzech; 119use Fisharebest\Webtrees\Module\LanguageDanish; 120use Fisharebest\Webtrees\Module\LanguageDivehi; 121use Fisharebest\Webtrees\Module\LanguageDutch; 122use Fisharebest\Webtrees\Module\LanguageEnglishAustralia; 123use Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain; 124use Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates; 125use Fisharebest\Webtrees\Module\LanguageEstonian; 126use Fisharebest\Webtrees\Module\LanguageFaroese; 127use Fisharebest\Webtrees\Module\LanguageFarsi; 128use Fisharebest\Webtrees\Module\LanguageFinnish; 129use Fisharebest\Webtrees\Module\LanguageFrench; 130use Fisharebest\Webtrees\Module\LanguageFrenchCanada; 131use Fisharebest\Webtrees\Module\LanguageGalician; 132use Fisharebest\Webtrees\Module\LanguageGeorgian; 133use Fisharebest\Webtrees\Module\LanguageGerman; 134use Fisharebest\Webtrees\Module\LanguageGreek; 135use Fisharebest\Webtrees\Module\LanguageHebrew; 136use Fisharebest\Webtrees\Module\LanguageHindi; 137use Fisharebest\Webtrees\Module\LanguageHungarian; 138use Fisharebest\Webtrees\Module\LanguageIcelandic; 139use Fisharebest\Webtrees\Module\LanguageIndonesian; 140use Fisharebest\Webtrees\Module\LanguageItalian; 141use Fisharebest\Webtrees\Module\LanguageJapanese; 142use Fisharebest\Webtrees\Module\LanguageJavanese; 143use Fisharebest\Webtrees\Module\LanguageKazhak; 144use Fisharebest\Webtrees\Module\LanguageKorean; 145use Fisharebest\Webtrees\Module\LanguageKurdish; 146use Fisharebest\Webtrees\Module\LanguageLatvian; 147use Fisharebest\Webtrees\Module\LanguageLingala; 148use Fisharebest\Webtrees\Module\LanguageLithuanian; 149use Fisharebest\Webtrees\Module\LanguageMalay; 150use Fisharebest\Webtrees\Module\LanguageMaori; 151use Fisharebest\Webtrees\Module\LanguageMarathi; 152use Fisharebest\Webtrees\Module\LanguageNepalese; 153use Fisharebest\Webtrees\Module\LanguageNorwegianBokmal; 154use Fisharebest\Webtrees\Module\LanguageNorwegianNynorsk; 155use Fisharebest\Webtrees\Module\LanguageOccitan; 156use Fisharebest\Webtrees\Module\LanguagePolish; 157use Fisharebest\Webtrees\Module\LanguagePortuguese; 158use Fisharebest\Webtrees\Module\LanguagePortugueseBrazil; 159use Fisharebest\Webtrees\Module\LanguageRomanian; 160use Fisharebest\Webtrees\Module\LanguageRussian; 161use Fisharebest\Webtrees\Module\LanguageSerbian; 162use Fisharebest\Webtrees\Module\LanguageSerbianLatin; 163use Fisharebest\Webtrees\Module\LanguageSlovakian; 164use Fisharebest\Webtrees\Module\LanguageSlovenian; 165use Fisharebest\Webtrees\Module\LanguageSpanish; 166use Fisharebest\Webtrees\Module\LanguageSundanese; 167use Fisharebest\Webtrees\Module\LanguageSwahili; 168use Fisharebest\Webtrees\Module\LanguageSwedish; 169use Fisharebest\Webtrees\Module\LanguageTagalog; 170use Fisharebest\Webtrees\Module\LanguageTamil; 171use Fisharebest\Webtrees\Module\LanguageTatar; 172use Fisharebest\Webtrees\Module\LanguageThai; 173use Fisharebest\Webtrees\Module\LanguageTurkish; 174use Fisharebest\Webtrees\Module\LanguageUkranian; 175use Fisharebest\Webtrees\Module\LanguageUrdu; 176use Fisharebest\Webtrees\Module\LanguageVietnamese; 177use Fisharebest\Webtrees\Module\LanguageWelsh; 178use Fisharebest\Webtrees\Module\LanguageYiddish; 179use Fisharebest\Webtrees\Module\LifespansChartModule; 180use Fisharebest\Webtrees\Module\ListsMenuModule; 181use Fisharebest\Webtrees\Module\LocationListModule; 182use Fisharebest\Webtrees\Module\LoggedInUsersModule; 183use Fisharebest\Webtrees\Module\LoginBlockModule; 184use Fisharebest\Webtrees\Module\LowCountriesRulers; 185use Fisharebest\Webtrees\Module\MapBox; 186use Fisharebest\Webtrees\Module\MapLinkBing; 187use Fisharebest\Webtrees\Module\MapLinkGoogle; 188use Fisharebest\Webtrees\Module\MapLinkOpenStreetMap; 189use Fisharebest\Webtrees\Module\MapGeoLocationGeonames; 190use Fisharebest\Webtrees\Module\MapGeoLocationNominatim; 191use Fisharebest\Webtrees\Module\MapGeoLocationOpenRouteService; 192use Fisharebest\Webtrees\Module\BingMaps; 193use Fisharebest\Webtrees\Module\GoogleMaps; 194use Fisharebest\Webtrees\Module\ModuleMapAutocompleteInterface; 195use Fisharebest\Webtrees\Module\OpenRouteServiceAutocomplete; 196use Fisharebest\Webtrees\Module\OpenStreetMap; 197use Fisharebest\Webtrees\Module\MarriageReportModule; 198use Fisharebest\Webtrees\Module\MatomoAnalyticsModule; 199use Fisharebest\Webtrees\Module\MediaListModule; 200use Fisharebest\Webtrees\Module\MediaTabModule; 201use Fisharebest\Webtrees\Module\MinimalTheme; 202use Fisharebest\Webtrees\Module\MissingFactsReportModule; 203use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 204use Fisharebest\Webtrees\Module\ModuleBlockInterface; 205use Fisharebest\Webtrees\Module\ModuleChartInterface; 206use Fisharebest\Webtrees\Module\ModuleCustomInterface; 207use Fisharebest\Webtrees\Module\ModuleCustomTagsInterface; 208use Fisharebest\Webtrees\Module\ModuleDataFixInterface; 209use Fisharebest\Webtrees\Module\ModuleFooterInterface; 210use Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface; 211use Fisharebest\Webtrees\Module\ModuleInterface; 212use Fisharebest\Webtrees\Module\ModuleLanguageInterface; 213use Fisharebest\Webtrees\Module\ModuleListInterface; 214use Fisharebest\Webtrees\Module\ModuleMapLinkInterface; 215use Fisharebest\Webtrees\Module\ModuleMapGeoLocationInterface; 216use Fisharebest\Webtrees\Module\ModuleMapProviderInterface; 217use Fisharebest\Webtrees\Module\ModuleMenuInterface; 218use Fisharebest\Webtrees\Module\ModuleReportInterface; 219use Fisharebest\Webtrees\Module\ModuleShareInterface; 220use Fisharebest\Webtrees\Module\ModuleSidebarInterface; 221use Fisharebest\Webtrees\Module\ModuleTabInterface; 222use Fisharebest\Webtrees\Module\ModuleThemeInterface; 223use Fisharebest\Webtrees\Module\NoteListModule; 224use Fisharebest\Webtrees\Module\NotesTabModule; 225use Fisharebest\Webtrees\Module\OccupationReportModule; 226use Fisharebest\Webtrees\Module\OnThisDayModule; 227use Fisharebest\Webtrees\Module\OrdnanceSurveyHistoricMaps; 228use Fisharebest\Webtrees\Module\PedigreeChartModule; 229use Fisharebest\Webtrees\Module\PedigreeMapModule; 230use Fisharebest\Webtrees\Module\PedigreeReportModule; 231use Fisharebest\Webtrees\Module\PlaceHierarchyListModule; 232use Fisharebest\Webtrees\Module\PlacesModule; 233use Fisharebest\Webtrees\Module\PoweredByWebtreesModule; 234use Fisharebest\Webtrees\Module\PrivacyPolicy; 235use Fisharebest\Webtrees\Module\RecentChangesModule; 236use Fisharebest\Webtrees\Module\RedirectLegacyUrlsModule; 237use Fisharebest\Webtrees\Module\RelatedIndividualsReportModule; 238use Fisharebest\Webtrees\Module\RelationshipsChartModule; 239use Fisharebest\Webtrees\Module\RelativesTabModule; 240use Fisharebest\Webtrees\Module\ReportsMenuModule; 241use Fisharebest\Webtrees\Module\RepositoryListModule; 242use Fisharebest\Webtrees\Module\ResearchTaskModule; 243use Fisharebest\Webtrees\Module\ReviewChangesModule; 244use Fisharebest\Webtrees\Module\SearchMenuModule; 245use Fisharebest\Webtrees\Module\ShareAnniversaryModule; 246use Fisharebest\Webtrees\Module\ShareUrlModule; 247use Fisharebest\Webtrees\Module\SiteMapModule; 248use Fisharebest\Webtrees\Module\SlideShowModule; 249use Fisharebest\Webtrees\Module\SourceListModule; 250use Fisharebest\Webtrees\Module\SourcesTabModule; 251use Fisharebest\Webtrees\Module\StatcounterModule; 252use Fisharebest\Webtrees\Module\StatisticsChartModule; 253use Fisharebest\Webtrees\Module\StoriesModule; 254use Fisharebest\Webtrees\Module\SubmitterListModule; 255use Fisharebest\Webtrees\Module\ThemeSelectModule; 256use Fisharebest\Webtrees\Module\TimelineChartModule; 257use Fisharebest\Webtrees\Module\TopGivenNamesModule; 258use Fisharebest\Webtrees\Module\TopPageViewsModule; 259use Fisharebest\Webtrees\Module\TopSurnamesModule; 260use Fisharebest\Webtrees\Module\TreesMenuModule; 261use Fisharebest\Webtrees\Module\UpcomingAnniversariesModule; 262use Fisharebest\Webtrees\Module\UserFavoritesModule; 263use Fisharebest\Webtrees\Module\UserJournalModule; 264use Fisharebest\Webtrees\Module\UserMessagesModule; 265use Fisharebest\Webtrees\Module\UserWelcomeModule; 266use Fisharebest\Webtrees\Module\USPresidents; 267use Fisharebest\Webtrees\Module\WebtreesTheme; 268use Fisharebest\Webtrees\Module\WelcomeBlockModule; 269use Fisharebest\Webtrees\Module\XeneaTheme; 270use Fisharebest\Webtrees\Module\YahrzeitModule; 271use Fisharebest\Webtrees\Registry; 272use Fisharebest\Webtrees\Tree; 273use Fisharebest\Webtrees\Webtrees; 274use Illuminate\Database\Capsule\Manager as DB; 275use Illuminate\Support\Collection; 276use Throwable; 277 278use function app; 279use function basename; 280use function dirname; 281use function glob; 282use function is_object; 283use function str_contains; 284use function strlen; 285 286use const GLOB_NOSORT; 287 288/** 289 * Functions for managing and maintaining modules. 290 */ 291class ModuleService 292{ 293 // Components are pieces of user-facing functionality, are managed together in the control panel. 294 private const COMPONENTS = [ 295 ModuleAnalyticsInterface::class, 296 ModuleBlockInterface::class, 297 ModuleChartInterface::class, 298 ModuleCustomTagsInterface::class, 299 ModuleDataFixInterface::class, 300 ModuleFooterInterface::class, 301 ModuleHistoricEventsInterface::class, 302 ModuleLanguageInterface::class, 303 ModuleListInterface::class, 304 ModuleMapAutocompleteInterface::class, 305 ModuleMapLinkInterface::class, 306 ModuleMapProviderInterface::class, 307 ModuleMapGeoLocationInterface::class, 308 ModuleMenuInterface::class, 309 ModuleReportInterface::class, 310 ModuleShareInterface::class, 311 ModuleSidebarInterface::class, 312 ModuleTabInterface::class, 313 ModuleThemeInterface::class, 314 ]; 315 316 // Components that have access levels. 317 private const COMPONENTS_WITH_ACCESS = [ 318 ModuleBlockInterface::class, 319 ModuleChartInterface::class, 320 ModuleListInterface::class, 321 ModuleMenuInterface::class, 322 ModuleReportInterface::class, 323 ModuleSidebarInterface::class, 324 ModuleTabInterface::class, 325 ]; 326 327 // Components that are displayed in a particular order 328 private const COMPONENTS_WITH_SORT = [ 329 ModuleFooterInterface::class, 330 ModuleMenuInterface::class, 331 ModuleSidebarInterface::class, 332 ModuleTabInterface::class, 333 ]; 334 335 // Array keys are module names, and should match module names from earlier versions of webtrees. 336 private const CORE_MODULES = [ 337 'GEDFact_assistant' => CensusAssistantModule::class, 338 'ahnentafel_report' => AhnentafelReportModule::class, 339 'ancestors_chart' => AncestorsChartModule::class, 340 'austrian-history' => AustrianHistoricEvents::class, 341 'austrian-presidents' => AustrianPresidents::class, 342 'bdm_report' => BirthDeathMarriageReportModule::class, 343 'bing-maps' => BingMaps::class, 344 'bing-webmaster-tools' => BingWebmasterToolsModule::class, 345 'birth_report' => BirthReportModule::class, 346 'branches_list' => BranchesListModule::class, 347 'british-monarchs' => BritishMonarchs::class, 348 'british-prime-ministers' => BritishPrimeMinisters::class, 349 'british-social-history' => BritishSocialHistory::class, 350 'calendar-menu' => CalendarMenuModule::class, 351 'cemetery_report' => CemeteryReportModule::class, 352 'change_report' => ChangeReportModule::class, 353 'charts' => ChartsBlockModule::class, 354 'charts-menu' => ChartsMenuModule::class, 355 'ckeditor' => CkeditorModule::class, 356 'clippings' => ClippingsCartModule::class, 357 'clouds' => CloudsTheme::class, 358 'colors' => ColorsTheme::class, 359 'compact-chart' => CompactTreeChartModule::class, 360 'contact-links' => ContactsFooterModule::class, 361 'czech-leaders' => CzechMonarchsAndPresidents::class, 362 'custom-css-js' => CustomCssJsModule::class, 363 'custom-tags-aldfaer' => CustomTagsAldfaer::class, 364 'custom-tags-ancestry' => CustomTagsAncestry::class, 365 'custom-tags-bk' => CustomTagsBrothersKeeper::class, 366 'custom-tags-gedcom-53' => CustomTagsGedcom53::class, 367 'custom-tags-gedcom-l' => CustomTagsGedcomL::class, 368 'custom-tags-genpluswin' => CustomTagsGenPluswin::class, 369 'custom-tags-legacy' => CustomTagsLegacy::class, 370 'custom-tags-fam-search' => CustomTagsFamilySearch::class, 371 'custom-tags-ftb' => CustomTagsFamilyTreeBuilder::class, 372 'custom-tags-ftm' => CustomTagsFamilyTreeMaker::class, 373 'custom-tags-paf' => CustomTagsPersonalAncestralFile::class, 374 'custom-tags-phpgedview' => CustomTagsPhpGedView::class, 375 'custom-tags-reunion' => CustomTagsReunion::class, 376 'custom-tags-roots-magic' => CustomTagsRootsMagic::class, 377 'custom-tags-tmg' => CustomTagsTheMasterGenealogist::class, 378 'custom-tags-webtrees' => CustomTagsWebtrees::class, 379 'death_report' => DeathReportModule::class, 380 'descendancy' => DescendancyModule::class, 381 'descendancy_chart' => DescendancyChartModule::class, 382 'descendancy_report' => DescendancyReportModule::class, 383 'dutch_monarchs' => DutchMonarchs::class, 384 'dutch_prime_ministers' => DutchPrimeMinisters::class, 385 'esri-maps' => EsriMaps::class, 386 'extra_info' => IndividualMetadataModule::class, 387 'fab' => FabTheme::class, 388 'fact_sources' => FactSourcesReportModule::class, 389 'family_book_chart' => FamilyBookChartModule::class, 390 'family_group_report' => FamilyGroupReportModule::class, 391 'family_list' => FamilyListModule::class, 392 'family_nav' => FamilyNavigatorModule::class, 393 'fan_chart' => FanChartModule::class, 394 'faq' => FrequentlyAskedQuestionsModule::class, 395 'french-history' => FrenchHistory::class, 396 'fix-add-death' => FixMissingDeaths::class, 397 'fix-ceme-tag' => FixCemeteryTag::class, 398 'fix-duplicate-links' => FixDuplicateLinks::class, 399 'fix-name-slashes-spaces' => FixNameSlashesAndSpaces::class, 400 'fix-name-tags' => FixNameTags::class, 401 'fix-place-names' => FixPlaceNames::class, 402 'fix-prim-tag' => FixPrimaryTag::class, 403 'fix-search-and-replace' => FixSearchAndReplace::class, 404 'gedcom_block' => WelcomeBlockModule::class, 405 'gedcom_favorites' => FamilyTreeFavoritesModule::class, 406 'gedcom_news' => FamilyTreeNewsModule::class, 407 'gedcom_stats' => FamilyTreeStatisticsModule::class, 408 'geonames' => GeonamesAutocomplete::class, 409 'google-analytics' => GoogleAnalyticsModule::class, 410 'google-maps' => GoogleMaps::class, 411 'google-webmaster-tools' => GoogleWebmasterToolsModule::class, 412 'here-maps' => HereMaps::class, 413 'hit-counter' => HitCountFooterModule::class, 414 'hourglass_chart' => HourglassChartModule::class, 415 'html' => HtmlBlockModule::class, 416 'individual_ext_report' => IndividualFamiliesReportModule::class, 417 'individual_list' => IndividualListModule::class, 418 'individual_report' => IndividualReportModule::class, 419 'language-af' => LanguageAfrikaans::class, 420 'language-ar' => LanguageArabic::class, 421 'language-bg' => LanguageBulgarian::class, 422 'language-bs' => LanguageBosnian::class, 423 'language-ca' => LanguageCatalan::class, 424 'language-cs' => LanguageCzech::class, 425 'language-cy' => LanguageWelsh::class, 426 'language-da' => LanguageDanish::class, 427 'language-de' => LanguageGerman::class, 428 'language-dv' => LanguageDivehi::class, 429 'language-el' => LanguageGreek::class, 430 'language-en-AU' => LanguageEnglishAustralia::class, 431 'language-en-GB' => LanguageEnglishGreatBritain::class, 432 'language-en-US' => LanguageEnglishUnitedStates::class, 433 'language-es' => LanguageSpanish::class, 434 'language-et' => LanguageEstonian::class, 435 'language-fa' => LanguageFarsi::class, 436 'language-fi' => LanguageFinnish::class, 437 'language-fo' => LanguageFaroese::class, 438 'language-fr' => LanguageFrench::class, 439 'language-fr-CA' => LanguageFrenchCanada::class, 440 'language-gl' => LanguageGalician::class, 441 'language-he' => LanguageHebrew::class, 442 'language-hi' => LanguageHindi::class, 443 'language-hr' => LanguageCroatian::class, 444 'language-hu' => LanguageHungarian::class, 445 'language-id' => LanguageIndonesian::class, 446 'language-is' => LanguageIcelandic::class, 447 'language-it' => LanguageItalian::class, 448 'language-ja' => LanguageJapanese::class, 449 'language-jv' => LanguageJavanese::class, 450 'language-ka' => LanguageGeorgian::class, 451 'language-kk' => LanguageKazhak::class, 452 'language-ko' => LanguageKorean::class, 453 'language-ku' => LanguageKurdish::class, 454 'language-ln' => LanguageLingala::class, 455 'language-lt' => LanguageLithuanian::class, 456 'language-lv' => LanguageLatvian::class, 457 'language-mi' => LanguageMaori::class, 458 'language-mr' => LanguageMarathi::class, 459 'language-ms' => LanguageMalay::class, 460 'language-nb' => LanguageNorwegianBokmal::class, 461 'language-ne' => LanguageNepalese::class, 462 'language-nl' => LanguageDutch::class, 463 'language-nn' => LanguageNorwegianNynorsk::class, 464 'language-oc' => LanguageOccitan::class, 465 'language-pl' => LanguagePolish::class, 466 'language-pt' => LanguagePortuguese::class, 467 'language-pt-BR' => LanguagePortugueseBrazil::class, 468 'language-ro' => LanguageRomanian::class, 469 'language-ru' => LanguageRussian::class, 470 'language-sk' => LanguageSlovakian::class, 471 'language-sl' => LanguageSlovenian::class, 472 'language-sq' => LanguageAlbanian::class, 473 'language-sr' => LanguageSerbian::class, 474 'language-sr-Latn' => LanguageSerbianLatin::class, 475 'language-su' => LanguageSundanese::class, 476 'language-sv' => LanguageSwedish::class, 477 'language-sw' => LanguageSwahili::class, 478 'language-ta' => LanguageTamil::class, 479 'language-th' => LanguageThai::class, 480 'language-tl' => LanguageTagalog::class, 481 'language-tr' => LanguageTurkish::class, 482 'language-tt' => LanguageTatar::class, 483 'language-uk' => LanguageUkranian::class, 484 'language-ur' => LanguageUrdu::class, 485 'language-vi' => LanguageVietnamese::class, 486 'language-yi' => LanguageYiddish::class, 487 'language-zh-Hans' => LanguageChineseSimplified::class, 488 'language-zh-Hant' => LanguageChineseTraditional::class, 489 'legacy-urls' => RedirectLegacyUrlsModule::class, 490 'lifespans_chart' => LifespansChartModule::class, 491 'lightbox' => AlbumModule::class, 492 'lists-menu' => ListsMenuModule::class, 493 'location_list' => LocationListModule::class, 494 'logged_in' => LoggedInUsersModule::class, 495 'login_block' => LoginBlockModule::class, 496 'low_countries_rulers' => LowCountriesRulers::class, 497 'map-link-bing' => MapLinkBing::class, 498 'map-link-google' => MapLinkGoogle::class, 499 'map-link-openstreetmap' => MapLinkOpenStreetMap::class, 500 'map-location-geonames' => MapGeoLocationGeonames::class, 501 'map-location-nominatim' => MapGeoLocationNominatim::class, 502 'map-location-ors' => MapGeoLocationOpenRouteService::class, 503 'mapbox' => MapBox::class, 504 'marriage_report' => MarriageReportModule::class, 505 'matomo-analytics' => MatomoAnalyticsModule::class, 506 'media' => MediaTabModule::class, 507 'media_list' => MediaListModule::class, 508 'minimal' => MinimalTheme::class, 509 'missing_facts_report' => MissingFactsReportModule::class, 510 'notes' => NotesTabModule::class, 511 'note_list' => NoteListModule::class, 512 'occupation_report' => OccupationReportModule::class, 513 'openrouteservice' => OpenRouteServiceAutocomplete::class, 514 'openstreetmap' => OpenStreetMap::class, 515 'osgb-historic' => OrdnanceSurveyHistoricMaps::class, 516 'pedigree-map' => PedigreeMapModule::class, 517 'pedigree_chart' => PedigreeChartModule::class, 518 'pedigree_report' => PedigreeReportModule::class, 519 'personal_facts' => IndividualFactsTabModule::class, 520 'places' => PlacesModule::class, 521 'places_list' => PlaceHierarchyListModule::class, 522 'powered-by-webtrees' => PoweredByWebtreesModule::class, 523 'privacy-policy' => PrivacyPolicy::class, 524 'random_media' => SlideShowModule::class, 525 'recent_changes' => RecentChangesModule::class, 526 'relationships_chart' => RelationshipsChartModule::class, 527 'relative_ext_report' => RelatedIndividualsReportModule::class, 528 'relatives' => RelativesTabModule::class, 529 'reports-menu' => ReportsMenuModule::class, 530 'repository_list' => RepositoryListModule::class, 531 'review_changes' => ReviewChangesModule::class, 532 'search-menu' => SearchMenuModule::class, 533 'share-anniversary' => ShareAnniversaryModule::class, 534 'share-url' => ShareUrlModule::class, 535 'sitemap' => SiteMapModule::class, 536 'source_list' => SourceListModule::class, 537 'sources_tab' => SourcesTabModule::class, 538 'statcounter' => StatcounterModule::class, 539 'statistics_chart' => StatisticsChartModule::class, 540 'stories' => StoriesModule::class, 541 'submitter_list' => SubmitterListModule::class, 542 'theme_select' => ThemeSelectModule::class, 543 'timeline_chart' => TimelineChartModule::class, 544 'todays_events' => OnThisDayModule::class, 545 'todo' => ResearchTaskModule::class, 546 'top10_givnnames' => TopGivenNamesModule::class, 547 'top10_pageviews' => TopPageViewsModule::class, 548 'top10_surnames' => TopSurnamesModule::class, 549 'tree' => InteractiveTreeModule::class, 550 'trees-menu' => TreesMenuModule::class, 551 'upcoming_events' => UpcomingAnniversariesModule::class, 552 'us-presidents' => USPresidents::class, 553 'user_blog' => UserJournalModule::class, 554 'user_favorites' => UserFavoritesModule::class, 555 'user_messages' => UserMessagesModule::class, 556 'user_welcome' => UserWelcomeModule::class, 557 'webtrees' => WebtreesTheme::class, 558 'xenea' => XeneaTheme::class, 559 'yahrzeit' => YahrzeitModule::class, 560 ]; 561 562 /** 563 * A function to convert modules into their titles - to create option lists, etc. 564 * 565 * @return Closure 566 */ 567 public function titleMapper(): Closure 568 { 569 return static function (ModuleInterface $module): string { 570 return $module->title(); 571 }; 572 } 573 574 /** 575 * Modules which (a) provide a specific function and (b) we have permission to see. 576 * 577 * @param string $interface 578 * @param Tree $tree 579 * @param UserInterface $user 580 * 581 * @return Collection<string,ModuleInterface> 582 */ 583 public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection 584 { 585 return $this->findByInterface($interface, false, true) 586 ->filter(static function (ModuleInterface $module) use ($interface, $tree, $user): bool { 587 return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user); 588 }); 589 } 590 591 /** 592 * All modules which provide a specific function. 593 * 594 * @param string $interface 595 * @param bool $include_disabled 596 * @param bool $sort 597 * 598 * @return Collection<string,ModuleInterface> 599 */ 600 public function findByInterface(string $interface, bool $include_disabled = false, bool $sort = false): Collection 601 { 602 $modules = $this->all($include_disabled) 603 ->filter($this->interfaceFilter($interface)); 604 605 switch ($interface) { 606 case ModuleFooterInterface::class: 607 return $modules->sort($this->footerComparator()); 608 609 case ModuleMenuInterface::class: 610 return $modules->sort($this->menuComparator()); 611 612 case ModuleSidebarInterface::class: 613 return $modules->sort($this->sidebarComparator()); 614 615 case ModuleTabInterface::class: 616 return $modules->sort($this->tabComparator()); 617 618 default: 619 if ($sort) { 620 return $modules->sort($this->moduleComparator()); 621 } 622 623 return $modules; 624 } 625 } 626 627 /** 628 * All modules. 629 * 630 * @param bool $include_disabled 631 * 632 * @return Collection<string,ModuleInterface> 633 */ 634 public function all(bool $include_disabled = false): Collection 635 { 636 return Registry::cache()->array()->remember('all-modules', function (): Collection { 637 // Modules have a default status, order etc. 638 // We can override these from database settings. 639 $module_info = DB::table('module') 640 ->get() 641 ->mapWithKeys(static function (object $row): array { 642 return [$row->module_name => $row]; 643 }); 644 645 return $this->coreModules() 646 ->merge($this->customModules()) 647 ->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface { 648 $info = $module_info->get($module->name()); 649 650 if (is_object($info)) { 651 $module->setEnabled($info->status === 'enabled'); 652 653 if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) { 654 $module->setFooterOrder((int) $info->footer_order); 655 } 656 657 if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) { 658 $module->setMenuOrder((int) $info->menu_order); 659 } 660 661 if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) { 662 $module->setSidebarOrder((int) $info->sidebar_order); 663 } 664 665 if ($module instanceof ModuleTabInterface && $info->tab_order !== null) { 666 $module->setTabOrder((int) $info->tab_order); 667 } 668 } else { 669 $module->setEnabled($module->isEnabledByDefault()); 670 671 DB::table('module')->insert([ 672 'module_name' => $module->name(), 673 'status' => $module->isEnabled() ? 'enabled' : 'disabled', 674 ]); 675 } 676 677 return $module; 678 }); 679 })->filter($this->enabledFilter($include_disabled)); 680 } 681 682 /** 683 * All core modules in the system. 684 * 685 * @return Collection<string,ModuleInterface> 686 */ 687 private function coreModules(): Collection 688 { 689 return Collection::make(self::CORE_MODULES) 690 ->map(static function (string $class, string $name): ModuleInterface { 691 $module = app($class); 692 assert($module instanceof ModuleInterface); 693 694 $module->setName($name); 695 696 return $module; 697 }); 698 } 699 700 /** 701 * All custom modules in the system. Custom modules are defined in modules_v4/ 702 * 703 * @return Collection<string,ModuleCustomInterface> 704 */ 705 private function customModules(): Collection 706 { 707 $pattern = Webtrees::MODULES_DIR . '*/module.php'; 708 $filenames = glob($pattern, GLOB_NOSORT); 709 710 return Collection::make($filenames) 711 ->filter(static function (string $filename): bool { 712 // Special characters will break PHP variable names. 713 // This also allows us to ignore modules called "foo.example" and "foo.disable" 714 $module_name = basename(dirname($filename)); 715 716 foreach (['.', ' ', '[', ']'] as $character) { 717 if (str_contains($module_name, $character)) { 718 return false; 719 } 720 } 721 722 return strlen($module_name) <= 30; 723 }) 724 ->map(static function (string $filename): ?ModuleCustomInterface { 725 $module = self::load($filename); 726 727 if ($module instanceof ModuleCustomInterface) { 728 $module->setName('_' . basename(dirname($filename)) . '_'); 729 730 return $module; 731 } 732 733 return null; 734 }) 735 ->filter() 736 ->mapWithKeys(static function (ModuleCustomInterface $module): array { 737 return [$module->name() => $module]; 738 }); 739 } 740 741 /** 742 * Load a custom module in a static scope, to prevent it from modifying local or object variables. 743 * 744 * @param string $filename 745 * 746 * @return ModuleInterface|null 747 */ 748 private static function load(string $filename): ?ModuleInterface 749 { 750 try { 751 return include $filename; 752 } catch (Throwable $exception) { 753 $module_name = basename(dirname($filename)); 754 $message = 'Fatal error in module: ' . $module_name . '<br>' . $exception; 755 FlashMessages::addMessage($message, 'danger'); 756 } 757 758 return null; 759 } 760 761 /** 762 * A function filter modules by enabled/disabled 763 * 764 * @param bool $include_disabled 765 * 766 * @return Closure 767 */ 768 private function enabledFilter(bool $include_disabled): Closure 769 { 770 return static function (ModuleInterface $module) use ($include_disabled): bool { 771 return $include_disabled || $module->isEnabled(); 772 }; 773 } 774 775 /** 776 * A function filter modules by type 777 * 778 * @param string $interface 779 * 780 * @return Closure 781 */ 782 private function interfaceFilter(string $interface): Closure 783 { 784 return static function (ModuleInterface $module) use ($interface): bool { 785 return $module instanceof $interface; 786 }; 787 } 788 789 /** 790 * A function to sort footers 791 * 792 * @return Closure 793 */ 794 private function footerComparator(): Closure 795 { 796 return static function (ModuleFooterInterface $x, ModuleFooterInterface $y): int { 797 return $x->getFooterOrder() <=> $y->getFooterOrder(); 798 }; 799 } 800 801 /** 802 * A function to sort menus 803 * 804 * @return Closure 805 */ 806 private function menuComparator(): Closure 807 { 808 return static function (ModuleMenuInterface $x, ModuleMenuInterface $y): int { 809 return $x->getMenuOrder() <=> $y->getMenuOrder(); 810 }; 811 } 812 813 /** 814 * A function to sort menus 815 * 816 * @return Closure 817 */ 818 private function sidebarComparator(): Closure 819 { 820 return static function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int { 821 return $x->getSidebarOrder() <=> $y->getSidebarOrder(); 822 }; 823 } 824 825 /** 826 * A function to sort menus 827 * 828 * @return Closure 829 */ 830 private function tabComparator(): Closure 831 { 832 return static function (ModuleTabInterface $x, ModuleTabInterface $y): int { 833 return $x->getTabOrder() <=> $y->getTabOrder(); 834 }; 835 } 836 837 /** 838 * A function to sort modules by name. 839 * 840 * Languages have a "sortable" name, so that "British English" sorts as "English, British". 841 * This provides a more natural order in the language menu. 842 * 843 * @return Closure 844 */ 845 private function moduleComparator(): Closure 846 { 847 return static function (ModuleInterface $x, ModuleInterface $y): int { 848 $title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title(); 849 $title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title(); 850 851 return I18N::comparator()($title1, $title2); 852 }; 853 } 854 855 /** 856 * During setup, we'll need access to some languages. 857 * 858 * @return Collection<string,ModuleLanguageInterface> 859 */ 860 public function setupLanguages(): Collection 861 { 862 return $this->coreModules() 863 ->filter(static function (ModuleInterface $module): bool { 864 return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault(); 865 }) 866 ->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y): int { 867 return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable(); 868 }); 869 } 870 871 /** 872 * Find a specified module, if it is currently active. 873 * 874 * @param string $module_name 875 * @param bool $include_disabled 876 * 877 * @return ModuleInterface|null 878 */ 879 public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface 880 { 881 return $this->all($include_disabled) 882 ->first(static function (ModuleInterface $module) use ($module_name): bool { 883 return $module->name() === $module_name; 884 }); 885 } 886 887 /** 888 * Configuration settings are available through the various "module component" pages. 889 * For modules that do not provide a component, we need to list them separately. 890 * 891 * @param bool $include_disabled 892 * 893 * @return Collection<string,ModuleInterface> 894 */ 895 public function otherModules(bool $include_disabled = false): Collection 896 { 897 return $this->findByInterface(ModuleInterface::class, $include_disabled, true) 898 ->filter(static function (ModuleInterface $module): bool { 899 foreach (self::COMPONENTS as $interface) { 900 if ($module instanceof $interface) { 901 return false; 902 } 903 } 904 905 return true; 906 }); 907 } 908 909 /** 910 * Generate a list of module names which exist in the database but not on disk. 911 * 912 * @return Collection<int,string> 913 */ 914 public function deletedModules(): Collection 915 { 916 $database_modules = DB::table('module')->pluck('module_name'); 917 918 $disk_modules = $this->all(true) 919 ->map(static function (ModuleInterface $module): string { 920 return $module->name(); 921 }); 922 923 return $database_modules->diff($disk_modules); 924 } 925 926 /** 927 * Boot all the modules. 928 * 929 * @param ModuleThemeInterface $current_theme 930 */ 931 public function bootModules(ModuleThemeInterface $current_theme): void 932 { 933 foreach ($this->all() as $module) { 934 // Only bootstrap the current theme. 935 if ($module instanceof ModuleThemeInterface && $module !== $current_theme) { 936 continue; 937 } 938 939 $module->boot(); 940 } 941 } 942 943 /** 944 * @return Collection<int,string> 945 */ 946 public function componentsWithAccess(): Collection 947 { 948 return new Collection(self::COMPONENTS_WITH_ACCESS); 949 } 950 951 /** 952 * @return Collection<int,string> 953 */ 954 public function componentsWithOrder(): Collection 955 { 956 return new Collection(self::COMPONENTS_WITH_SORT); 957 } 958} 959