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