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