From 9445929d5f9f37df75d419fcccc59064453c1629 Mon Sep 17 00:00:00 2001 From: Yasser Elgammal Date: Fri, 8 Nov 2024 21:56:11 +0200 Subject: [PATCH] Besm Allah --- .gitignore | 1 + README.md | 2 ++ composer.json | 24 +++++++++++++++++++++ config/badwords.php | 6 ++++++ src/PureTextServiceProvider.php | 28 +++++++++++++++++++++++++ src/Services/PureTextFilterService.php | 22 +++++++++++++++++++ src/Traits/PureTextFilterable.php | 29 ++++++++++++++++++++++++++ 7 files changed, 112 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 composer.json create mode 100644 config/badwords.php create mode 100644 src/PureTextServiceProvider.php create mode 100644 src/Services/PureTextFilterService.php create mode 100644 src/Traits/PureTextFilterable.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61ead86 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c57776 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +## Pure Text Package +for pure content diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6ec7bd5 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "yasser-elgammal/pure-text", + "description": "Filter Bad Words", + "license": "MIT", + "autoload": { + "psr-4": { + "YasserElgammal\\PureText\\": "src/" + } + }, + "authors": [ + { + "name": "YasserElgammal", + "email": "yassermelgammal@gmail.com" + } + ], + "minimum-stability": "dev", + "extra": { + "laravel": { + "providers": [ + "YasserElgammal\\PureText\\PureTextServiceProvider" + ] + } + } +} diff --git a/config/badwords.php b/config/badwords.php new file mode 100644 index 0000000..2e35b72 --- /dev/null +++ b/config/badwords.php @@ -0,0 +1,6 @@ + ['badword1', 'badword2', 'badword3'], // List of bad words to filter + 'replacement' => '***', // Replacement text for bad words +]; diff --git a/src/PureTextServiceProvider.php b/src/PureTextServiceProvider.php new file mode 100644 index 0000000..0edf455 --- /dev/null +++ b/src/PureTextServiceProvider.php @@ -0,0 +1,28 @@ +publishes([ + __DIR__ . '/../config/badwords.php' => config_path('badwords.php'), + ], 'config'); + } + + public function register() + { + $this->mergeConfigFrom( + __DIR__ . '/../config/badwords.php', + 'badwords' + ); + + $this->app->singleton(PureTextFilterService::class, function () { + return new PureTextFilterService(); + }); + } +} diff --git a/src/Services/PureTextFilterService.php b/src/Services/PureTextFilterService.php new file mode 100644 index 0000000..67a60e9 --- /dev/null +++ b/src/Services/PureTextFilterService.php @@ -0,0 +1,22 @@ +filterableAttributes() as $attribute) { + if (isset($model->$attribute)) { + $model->$attribute = app(PureTextFilterService::class)->filter($model->$attribute); + } + } + }); + } + + /** + * Define the list of attributes that need to be filtered. + * @return array + */ + public function filterableAttributes() + { + return property_exists($this, 'filterable') ? $this->filterable : []; + } +}