pixelfed/app/Providers/AppServiceProvider.php

76 lines
2 KiB
PHP
Raw Normal View History

2018-04-15 23:56:48 +00:00
<?php
namespace App\Providers;
use App\Observers\UserObserver;
2018-08-28 03:07:36 +00:00
use App\User;
use Auth;
use Horizon;
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()
{
2018-06-01 23:39:45 +00:00
Schema::defaultStringLength(191);
2018-05-22 23:58:48 +00:00
User::observe(UserObserver::class);
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) {
2018-05-22 23:58:48 +00:00
$size = intval($expression);
$precision = 0;
$short = true;
$units = $short ?
2018-08-28 03:07:36 +00:00
['B', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] :
['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
for ($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) {
}
2018-05-22 23:58:48 +00:00
$res = round($size, $precision).$units[$i];
2018-08-28 03:07:36 +00:00
2018-05-22 23:58:48 +00:00
return "<?php echo '$res'; ?>";
});
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()
{
//
}
}