mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Service provider and other cleanup
- Removed old 'exposeTranslations' system to instead use new component option system. - Extracted validation rules into their own service provider. - Cleaned up some formatting/comments in the repos.
This commit is contained in:
@ -124,6 +124,7 @@ return [
|
||||
BookStack\Providers\EventServiceProvider::class,
|
||||
BookStack\Providers\RouteServiceProvider::class,
|
||||
BookStack\Providers\CustomFacadeProvider::class,
|
||||
BookStack\Providers\CustomValidationServiceProvider::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -6,11 +6,9 @@ use BookStack\Entities\Book;
|
||||
use BookStack\Entities\Managers\TrashCan;
|
||||
use BookStack\Exceptions\ImageUploadException;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Exceptions\NotifyException;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Uploads\ImageRepo;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Collection;
|
||||
@ -24,7 +22,6 @@ class BookRepo
|
||||
|
||||
/**
|
||||
* BookRepo constructor.
|
||||
* @param $tagRepo
|
||||
*/
|
||||
public function __construct(BaseRepo $baseRepo, TagRepo $tagRepo, ImageRepo $imageRepo)
|
||||
{
|
||||
|
@ -18,7 +18,6 @@ class BookshelfRepo
|
||||
|
||||
/**
|
||||
* BookshelfRepo constructor.
|
||||
* @param $baseRepo
|
||||
*/
|
||||
public function __construct(BaseRepo $baseRepo)
|
||||
{
|
||||
|
@ -11,7 +11,6 @@ use BookStack\Entities\Page;
|
||||
use BookStack\Entities\PageRevision;
|
||||
use BookStack\Exceptions\MoveOperationException;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Exceptions\NotifyException;
|
||||
use BookStack\Exceptions\PermissionsException;
|
||||
use BookStack\Facades\Activity;
|
||||
use Exception;
|
||||
|
@ -13,7 +13,6 @@ use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Schema;
|
||||
use URL;
|
||||
use Validator;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@ -32,37 +31,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
URL::forceScheme($isHttps ? 'https' : 'http');
|
||||
}
|
||||
|
||||
// Custom validation methods
|
||||
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
|
||||
$validImageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
|
||||
return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
|
||||
});
|
||||
|
||||
Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
|
||||
$uploadName = $value->getClientOriginalName();
|
||||
return substr_count($uploadName, '.') < 2;
|
||||
});
|
||||
|
||||
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
|
||||
$cleanLinkName = strtolower(trim($value));
|
||||
$isJs = strpos($cleanLinkName, 'javascript:') === 0;
|
||||
$isData = strpos($cleanLinkName, 'data:') === 0;
|
||||
return !$isJs && !$isData;
|
||||
});
|
||||
|
||||
// Custom blade view directives
|
||||
Blade::directive('icon', function ($expression) {
|
||||
return "<?php echo icon($expression); ?>";
|
||||
});
|
||||
|
||||
Blade::directive('exposeTranslations', function ($expression) {
|
||||
return "<?php \$__env->startPush('translations'); ?>" .
|
||||
"<?php foreach({$expression} as \$key): ?>" .
|
||||
'<meta name="translation" key="<?php echo e($key); ?>" value="<?php echo e(trans($key)); ?>">' . "\n" .
|
||||
"<?php endforeach; ?>" .
|
||||
'<?php $__env->stopPush(); ?>';
|
||||
});
|
||||
|
||||
// Allow longer string lengths after upgrade to utf8mb4
|
||||
Schema::defaultStringLength(191);
|
||||
|
||||
|
33
app/Providers/CustomValidationServiceProvider.php
Normal file
33
app/Providers/CustomValidationServiceProvider.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class CustomValidationServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Register our custom validation rules when the application boots.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
|
||||
$validImageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
|
||||
return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions);
|
||||
});
|
||||
|
||||
Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) {
|
||||
$uploadName = $value->getClientOriginalName();
|
||||
return substr_count($uploadName, '.') < 2;
|
||||
});
|
||||
|
||||
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
|
||||
$cleanLinkName = strtolower(trim($value));
|
||||
$isJs = strpos($cleanLinkName, 'javascript:') === 0;
|
||||
$isData = strpos($cleanLinkName, 'data:') === 0;
|
||||
return !$isJs && !$isData;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user