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