1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Providers/AppServiceProvider.php

83 lines
2.1 KiB
PHP
Raw Normal View History

2018-04-15 23:56:48 +00:00
<?php
namespace App\Providers;
2019-02-12 08:05:43 +00:00
use App\Observers\{
AvatarObserver,
2019-05-01 04:44:20 +00:00
NotificationObserver,
StatusHashtagObserver,
UserObserver,
UserFilterObserver,
2019-02-12 08:05:43 +00:00
};
2019-05-01 04:44:20 +00:00
use App\{
Avatar,
Notification,
StatusHashtag,
User,
UserFilter
2019-05-01 04:44:20 +00:00
};
2019-02-12 07:57:49 +00:00
use Auth, Horizon, URL;
2018-05-22 23:58:48 +00:00
use Illuminate\Support\Facades\Blade;
2018-06-01 23:39:45 +00:00
use Illuminate\Support\Facades\Schema;
2018-04-15 23:56:48 +00:00
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2019-02-24 19:16:18 +00:00
URL::forceScheme('https');
2018-06-01 23:39:45 +00:00
Schema::defaultStringLength(191);
2019-02-12 08:05:43 +00:00
Avatar::observe(AvatarObserver::class);
2019-05-01 04:44:20 +00:00
Notification::observe(NotificationObserver::class);
StatusHashtag::observe(StatusHashtagObserver::class);
2018-05-22 23:58:48 +00:00
User::observe(UserObserver::class);
UserFilter::observe(UserFilterObserver::class);
2018-05-22 23:58:48 +00:00
Horizon::auth(function ($request) {
return Auth::check() && $request->user()->is_admin;
});
2018-08-28 03:07:36 +00:00
Blade::directive('prettyNumber', function ($expression) {
2018-05-22 23:58:48 +00:00
$num = $expression;
2018-08-28 03:07:36 +00:00
$abbrevs = [12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => ''];
foreach ($abbrevs as $exponent => $abbrev) {
if ($expression >= pow(10, $exponent)) {
$display_num = $expression / pow(10, $exponent);
$num = number_format($display_num, 0).$abbrev;
return "<?php echo '$num'; ?>";
2018-05-22 23:58:48 +00:00
}
}
2018-08-28 03:07:36 +00:00
2018-05-22 23:58:48 +00:00
return "<?php echo $num; ?>";
});
2018-08-28 03:07:36 +00:00
Blade::directive('prettySize', function ($expression) {
2019-02-12 07:57:49 +00:00
$size = \App\Util\Lexer\PrettyNumber::size($expression);
return "<?php echo '$size'; ?>";
2018-05-22 23:58:48 +00:00
});
2018-08-28 03:07:36 +00:00
Blade::directive('maxFileSize', function () {
$value = config('pixelfed.max_photo_size');
return \App\Util\Lexer\PrettyNumber::size($value, true);
});
2018-04-15 23:56:48 +00:00
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}