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