From bd6d058db8c50ee1e8360df5cfe61e943512e5cb Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Sat, 9 Jul 2022 02:01:09 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20MQ=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20-=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3=20=D1=81=20=D0=B1?= =?UTF-8?q?=D0=B0=D1=88=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +- core/lib/Core/MQTasks.class.php | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 62e5324..bfad3b6 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ ], "require": { "twig/twig": "^3.0", - "sentry/sdk": "^3.2" + "sentry/sdk": "^3.2", + "ext-iconv": "*" } } diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index 7405fd0..e4a1ee3 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -4,6 +4,8 @@ use Core\Helpers\SystemFunctions; use Core\Helpers\Thumbs; + use Core\ExternalServices\TelegramSender; + use Core\Models\DB; class MQTasks { @@ -24,4 +26,52 @@ return $saveImage; } + + public static function sendBash(...$args): ?string + { + /** @var DB $DB */ + $DB = DB::getInstance(); + + $file = file_get_contents('http://bashorg.org/random'); + $file = preg_match_all('|
(.+)
|U', $file, $frazes); + + $frazes = $frazes[1]; + $frazes = array_map(function ($e) { + return \iconv('windows-1251//IGNORE', 'UTF-8//IGNORE', $e); + }, $frazes); + + $i = 0; + foreach ($frazes as $post) { + $text = str_replace('
', PHP_EOL, $post); + $text = htmlspecialchars_decode($text); + $text = str_replace('\'', '\\\'', $text); + $hash = md5($text); + $res = $DB->query('SELECT * FROM bashorg WHERE hash="' . $hash . '"'); + if (!$res) { + $i++; + $DB->addItem('bashorg', ['hash' => $hash, 'text' => $text]); + } + } + sleep(2); + return 'Добавлено ' . $i . ' записей из ' . count($frazes); + } +/* + public static function sendBash2(...$args): void + { + + + $DB = DB::getInstance(); + + $html = file_get_contents('http://bashorg.org/random'); + + //$file = preg_match_all('|
(.+)
|U',$html,$frazes); + $file = preg_match_all('
(.+?)
',$html,$top); + +print_r($top); + $frazes = $frazes[1]; + $frazes = array_map(function($e){ + return \iconv('windows-1251//IGNORE', 'UTF-8//IGNORE', $e); + }, $frazes); + + }*/ } \ No newline at end of file