AppServiceProvider.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Providers;
  3. use App\Models\UsefulLink;
  4. use App\Settings\GeneralSettings;
  5. use App\Settings\MailSettings;
  6. use Exception;
  7. use Illuminate\Pagination\Paginator;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Schema;
  10. use Illuminate\Support\Facades\URL;
  11. use Illuminate\Support\Facades\Validator;
  12. use Illuminate\Support\ServiceProvider;
  13. use Qirolab\Theme\Theme;
  14. class AppServiceProvider extends ServiceProvider
  15. {
  16. /**
  17. * Register any application services.
  18. *
  19. * @return void
  20. */
  21. public function register()
  22. {
  23. //
  24. }
  25. /**
  26. * Bootstrap any application services.
  27. *
  28. * @return void
  29. */
  30. public function boot()
  31. {
  32. Paginator::useBootstrap();
  33. Schema::defaultStringLength(191);
  34. Validator::extend('multiple_date_format', function ($attribute, $value, $parameters, $validator) {
  35. $ok = true;
  36. $result = [];
  37. // iterate through all formats
  38. foreach ($parameters as $parameter) {
  39. //validate with laravels standard date format validation
  40. $result[] = $validator->validateDateFormat($attribute, $value, [$parameter]);
  41. }
  42. //if none of result array is true. it sets ok to false
  43. if (!in_array(true, $result)) {
  44. $ok = false;
  45. $validator->setCustomMessages(['multiple_date_format' => 'The format must be one of ' . implode(',', $parameters)]);
  46. }
  47. return $ok;
  48. });
  49. // Force HTTPS if APP_URL is set to https
  50. if (config('app.url') && parse_url(config('app.url'), PHP_URL_SCHEME) === 'https') {
  51. URL::forceScheme('https');
  52. }
  53. //get the Github Branch the panel is running on
  54. try {
  55. $stringfromfile = file(base_path() . '/.git/HEAD');
  56. $firstLine = $stringfromfile[0]; //get the string from the array
  57. $explodedstring = explode('/', $firstLine, 3); //seperate out by the "/" in the string
  58. $branchname = $explodedstring[2]; //get the one that is always the branch name
  59. } catch (Exception $e) {
  60. $branchname = 'unknown';
  61. Log::notice($e);
  62. }
  63. config(['BRANCHNAME' => $branchname]);
  64. // Do not run this code if no APP_KEY is set
  65. if (config('app.key') == null) return;
  66. try {
  67. if (Schema::hasColumn('useful_links', 'position')) {
  68. $useful_links = UsefulLink::where("position", "like", "%topbar%")->get()->sortby("id");
  69. view()->share('useful_links', $useful_links);
  70. }
  71. } catch (Exception $e) {
  72. Log::error("Couldnt find useful_links. Probably the installation is not completet. " . $e);
  73. }
  74. try {
  75. $generalSettings = $this->app->make(GeneralSettings::class);
  76. if (!file_exists(base_path('themes') . "/" . $generalSettings->theme)) {
  77. $generalSettings->theme = "default";
  78. }
  79. if ($generalSettings->theme && $generalSettings->theme !== config('theme.active')) {
  80. Theme::set($generalSettings->theme, "default");
  81. } else {
  82. Theme::set("default", "default");
  83. }
  84. $settings = $this->app->make(MailSettings::class);
  85. $settings->setConfig();
  86. } catch (Exception $e) {
  87. Log::error("Couldnt load Settings. Probably the installation is not completet. " . $e);
  88. }
  89. }
  90. }