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);