2020-11-21 12:52:49 -05:00
|
|
|
<?php
|
|
|
|
|
2023-05-17 12:56:55 -04:00
|
|
|
namespace BookStack\App\Providers;
|
2020-11-21 12:52:49 -05:00
|
|
|
|
2021-10-31 20:24:42 -04:00
|
|
|
use BookStack\Uploads\ImageService;
|
2020-11-21 12:52:49 -05:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
2022-09-26 21:48:05 -04:00
|
|
|
class ValidationRuleServiceProvider extends ServiceProvider
|
2020-11-21 12:52:49 -05:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register our custom validation rules when the application boots.
|
|
|
|
*/
|
|
|
|
public function boot(): void
|
|
|
|
{
|
|
|
|
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
|
2021-10-31 20:24:42 -04:00
|
|
|
$extension = strtolower($value->getClientOriginalExtension());
|
2021-11-01 09:26:02 -04:00
|
|
|
|
2021-10-31 20:24:42 -04:00
|
|
|
return ImageService::isExtensionSupported($extension);
|
2020-11-21 12:52:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Validator::extend('safe_url', function ($attribute, $value, $parameters, $validator) {
|
|
|
|
$cleanLinkName = strtolower(trim($value));
|
2023-02-20 08:05:23 -05:00
|
|
|
$isJs = str_starts_with($cleanLinkName, 'javascript:');
|
|
|
|
$isData = str_starts_with($cleanLinkName, 'data:');
|
2021-06-26 11:23:15 -04:00
|
|
|
|
2020-11-21 12:52:49 -05:00
|
|
|
return !$isJs && !$isData;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|