2020-11-21 17:52:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-05-17 17:56:55 +01:00
|
|
|
namespace BookStack\App\Providers;
|
2020-11-21 17:52:49 +00:00
|
|
|
|
2021-11-01 00:24:42 +00:00
|
|
|
use BookStack\Uploads\ImageService;
|
2026-06-30 23:50:11 +01:00
|
|
|
use BookStack\Util\UrlFilter;
|
2020-11-21 17:52:49 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
2022-09-27 02:48:05 +01:00
|
|
|
class ValidationRuleServiceProvider extends ServiceProvider
|
2020-11-21 17:52:49 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Register our custom validation rules when the application boots.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
|
2021-11-01 00:24:42 +00:00
|
|
|
$extension = strtolower($value->getClientOriginalExtension());
|
2021-11-01 13:26:02 +00:00
|
|
|
|
2021-11-01 00:24:42 +00:00
|
|
|
return ImageService::isExtensionSupported($extension);
|
2020-11-21 17:52:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
|
|
|
|
|
$cleanLinkName = strtolower(trim($value));
|
2026-06-30 23:50:11 +01:00
|
|
|
$filter = new UrlFilter($cleanLinkName);
|
|
|
|
|
return $filter->isAllowed();
|
2020-11-21 17:52:49 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|