From 3519853bb63904f1f5311fc59addd1ed7792f852 Mon Sep 17 00:00:00 2001 From: nickpons666 Date: Thu, 19 Feb 2026 15:58:39 -0600 Subject: [PATCH] =?UTF-8?q?Fix:=20Preservar=20saltos=20de=20l=C3=ADnea=20e?= =?UTF-8?q?n=20traducciones=20de=20Telegram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - El patrón /\s+/ estaba colapsando TODOS los espacios en blanco incluyendo \n - Cambiar a /[ \t]+/ para colapsar solo espacios horizontales - Agregar limpieza de saltos de línea múltiples preservando estructura - Aplicado en: create_message.php, process_queue.php, discord_bot.php, telegram_bot_webhook.php Soluciona: 'Hola a todos, El orden de la lista\n\nMiguel\n\nnickpons\n\nLuis' se traducía como 'Olá a todos, A ordem da listaMiguelnickponsLuis' (sin saltos) --- create_message.php | 13 +++++++++++-- discord_bot.php | 4 +++- process_queue.php | 13 +++++++++++-- telegram/webhook/telegram_bot_webhook.php | 3 +++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/create_message.php b/create_message.php index 3c21951..ede545d 100755 --- a/create_message.php +++ b/create_message.php @@ -125,8 +125,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $sender = \Common\Helpers\SenderFactory::create($schedule['platform']); // Obtener botones de traducción (convertir HTML a texto plano) - $plainText = html_entity_decode(strip_tags($schedule['content']), ENT_QUOTES | ENT_HTML5, 'UTF-8'); - $plainText = preg_replace('/\s+/', ' ', $plainText); + $plainText = $schedule['content']; + // Convertir saltos de párrafo a saltos de línea + $plainText = preg_replace('/<\/p>/i', "\n", $plainText); + $plainText = preg_replace('/]*>/i', '', $plainText); + $plainText = preg_replace('//i', "\n", $plainText); + // Eliminar HTML + $plainText = html_entity_decode(strip_tags($plainText), ENT_QUOTES | ENT_HTML5, 'UTF-8'); + // Limpiar espacios múltiples pero preservar saltos de línea + $plainText = preg_replace('/[ \t]+/', ' ', $plainText); + $plainText = preg_replace('/\n\s*\n/', "\n", $plainText); + $plainText = trim($plainText); $translationButtons = getTranslationButtons($pdo, $plainText); $segments = $sender->parseContent($schedule['content']); diff --git a/discord_bot.php b/discord_bot.php index 36aabe3..7ce2d7c 100755 --- a/discord_bot.php +++ b/discord_bot.php @@ -228,7 +228,9 @@ function handleSlashCommand(PDO $pdo, Message $message, string $content): void // Convertir HTML a texto plano para botones de traducción $plainText = html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8'); - $plainText = preg_replace('/\s+/', ' ', $plainText); + // Limpiar espacios múltiples pero preservar saltos de línea + $plainText = preg_replace('/[ \t]+/', ' ', $plainText); + $plainText = preg_replace('/\n\s*\n/', "\n", $plainText); $translationButtons = getDiscordTranslationButtons($pdo, $plainText); $sender = new \Discord\DiscordSender(); diff --git a/process_queue.php b/process_queue.php index d2133f0..2822d58 100755 --- a/process_queue.php +++ b/process_queue.php @@ -103,8 +103,17 @@ function processScheduledMessages(): array $sender = SenderFactory::create($schedule['platform']); // Obtener botones de traducción (convertir HTML a texto plano) - $plainText = html_entity_decode(strip_tags($schedule['content']), ENT_QUOTES | ENT_HTML5, 'UTF-8'); - $plainText = preg_replace('/\s+/', ' ', $plainText); + $plainText = $schedule['content']; + // Convertir saltos de párrafo a saltos de línea + $plainText = preg_replace('/<\/p>/i', "\n", $plainText); + $plainText = preg_replace('/]*>/i', '', $plainText); + $plainText = preg_replace('//i', "\n", $plainText); + // Eliminar HTML + $plainText = html_entity_decode(strip_tags($plainText), ENT_QUOTES | ENT_HTML5, 'UTF-8'); + // Limpiar espacios múltiples pero preservar saltos de línea + $plainText = preg_replace('/[ \t]+/', ' ', $plainText); + $plainText = preg_replace('/\n\s*\n/', "\n", $plainText); + $plainText = trim($plainText); $translationButtons = getTranslationButtons($pdo, $plainText); // Parsear el contenido HTML en segmentos manteniendo el orden diff --git a/telegram/webhook/telegram_bot_webhook.php b/telegram/webhook/telegram_bot_webhook.php index 1ee1462..77af1cc 100755 --- a/telegram/webhook/telegram_bot_webhook.php +++ b/telegram/webhook/telegram_bot_webhook.php @@ -317,6 +317,9 @@ function sendTemplateByCommand(PDO $pdo, Telegram\TelegramSender $sender, int $c $plainText = preg_replace('/]*>/i', '', $plainText); $plainText = strip_tags($plainText); $plainText = html_entity_decode($plainText, ENT_QUOTES | ENT_HTML5, 'UTF-8'); + // Limpiar espacios múltiples pero preservar saltos de línea + $plainText = preg_replace('/[ \t]+/', ' ', $plainText); + $plainText = preg_replace('/\n\s*\n/', "\n", $plainText); $plainText = trim($plainText); $translationButtons = getTelegramTranslationButtons($pdo, $plainText);