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