-
Notifications
You must be signed in to change notification settings - Fork 398
/
Copy pathAppServiceProvider.php
92 lines (75 loc) · 3.1 KB
/
AppServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Providers;
use App\Helpers\ByteUnits;
use App\Helpers\HiddenCaptcha;
use App\Interfaces\ByteUnitsInterface;
use App\Models\User;
use App\View\Composers\FooterComposer;
use App\View\Composers\TopNavComposer;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* This service provider is a great spot to register your various container
* bindings with the application. As you can see, we are registering our
* "Registrar" implementation here. You can add your own bindings too!
*/
public function register(): void
{
// Hidden Captcha
$this->app->bind('hiddencaptcha', HiddenCaptcha::class);
// Gabrielelana byte-units
$this->app->bind(ByteUnitsInterface::class, ByteUnits::class);
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
// User Observer For Cache
// Hidden Captcha
Blade::directive('hiddencaptcha', fn ($mustBeEmptyField = '_username') => \sprintf('<?= App\Helpers\HiddenCaptcha::render(%s); ?>', $mustBeEmptyField));
// BBcode
Blade::directive('bbcode', fn (?string $bbcodeString) => "<?php echo (new \hdvinnie\LaravelJoyPixels\LaravelJoyPixels())->toImage((new \App\Helpers\Linkify())->linky((new \App\Helpers\Bbcode())->parse({$bbcodeString}))); ?>");
// Linkify
Blade::directive('linkify', fn (?string $contentString) => "<?php echo (new \App\Helpers\Linkify)->linky(e({$contentString})); ?>");
$this->app['validator']->extendImplicit(
'hiddencaptcha',
function ($attribute, $value, $parameters, $validator) {
$minLimit = (isset($parameters[0]) && is_numeric($parameters[0])) ? $parameters[0] : 0;
$maxLimit = (isset($parameters[1]) && is_numeric($parameters[1])) ? $parameters[1] : 1_200;
if (!HiddenCaptcha::check($validator, $minLimit, $maxLimit)) {
$validator->setCustomMessages(['hiddencaptcha' => 'Captcha error']);
return false;
}
return true;
}
);
// Add attributes to vite scripts and styles
Vite::useScriptTagAttributes([
'crossorigin' => 'anonymous',
]);
Vite::useStyleTagAttributes([
'crossorigin' => 'anonymous',
]);
View::composer('partials.footer', FooterComposer::class);
View::composer('partials.top_nav', TopNavComposer::class);
}
}