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