From ff7ff9309d020ab0c6843405551eba1603116bbd Mon Sep 17 00:00:00 2001 From: Charles Teh Date: Wed, 29 Nov 2023 11:55:44 +0800 Subject: [PATCH] Update (rss): block links that have less then 250 words --- app/Helpers/Global/string_helper.php | 14 ++++++++++++++ app/Jobs/Tasks/ParseRssPostMetadataTask.php | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/app/Helpers/Global/string_helper.php b/app/Helpers/Global/string_helper.php index 6056036..48a09ee 100644 --- a/app/Helpers/Global/string_helper.php +++ b/app/Helpers/Global/string_helper.php @@ -3,6 +3,20 @@ use GrahamCampbell\Markdown\Facades\Markdown; use Illuminate\Support\Str; +if (! function_exists('count_words')) { + function count_words($string) { + // Remove punctuation and line breaks + $cleanString = preg_replace('/[\p{P}\s]/u', ' ', $string); + + // Split the string into words + $words = preg_split('/\s+/', $cleanString, -1, PREG_SPLIT_NO_EMPTY); + + // Count the words + return count($words); + } +} + + if (! function_exists('get_country_names')) { function get_country_names($lowercase = false) { $countryCodes = config('platform.country_codes'); diff --git a/app/Jobs/Tasks/ParseRssPostMetadataTask.php b/app/Jobs/Tasks/ParseRssPostMetadataTask.php index aacbf54..ce8cfb7 100644 --- a/app/Jobs/Tasks/ParseRssPostMetadataTask.php +++ b/app/Jobs/Tasks/ParseRssPostMetadataTask.php @@ -18,6 +18,14 @@ public static function handle(int $rss_post_id) return; } + if (count_words($rss_post->body) < 250) + { + $rss_post->status = 'blocked'; + $rss_post->save(); + + return; + } + if (in_array($rss_post->status, ['blocked', 'trashed'])) { return; }