ajustes
This commit is contained in:
@@ -78,7 +78,7 @@ class OrderController
|
|||||||
|
|
||||||
$title = $_POST['title'];
|
$title = $_POST['title'];
|
||||||
$type = $_POST['type'];
|
$type = $_POST['type'];
|
||||||
$content = $_POST['content'];
|
$content = \App\Utils\TextFormatter::normalizeLineBreaks($_POST['content']);
|
||||||
$received_at = $_POST['received_at'];
|
$received_at = $_POST['received_at'];
|
||||||
|
|
||||||
$conn = \App\Config\Database::getInstance()->getConnection();
|
$conn = \App\Config\Database::getInstance()->getConnection();
|
||||||
|
|||||||
58
app/Utils/TextFormatter.php
Normal file
58
app/Utils/TextFormatter.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Utils;
|
||||||
|
|
||||||
|
class TextFormatter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Formata conteúdo de texto para exibição HTML segura.
|
||||||
|
* - Escapa caracteres especiais HTML (segurança XSS)
|
||||||
|
* - Converte URLs em links clicáveis
|
||||||
|
* - Converte quebras de linha em <br>
|
||||||
|
*
|
||||||
|
* @param string|null $text Texto a ser formatado
|
||||||
|
* @return string Texto formatado para HTML
|
||||||
|
*/
|
||||||
|
public static function formatContent(?string $text): string
|
||||||
|
{
|
||||||
|
if (empty($text)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Escapa caracteres especiais HTML (segurança contra XSS)
|
||||||
|
$text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
// 2. Converte URLs em links clicáveis
|
||||||
|
// Padrão para URLs HTTP/HTTPS
|
||||||
|
$urlPattern = '/(https?:\/\/[^\s\)\]]+)/i';
|
||||||
|
$text = preg_replace_callback($urlPattern, function ($matches) {
|
||||||
|
$url = rtrim($matches[1], '.,;:!?)\'\"'); // Remove pontuação final
|
||||||
|
$displayUrl = strlen($url) > 60 ? substr($url, 0, 57) . '...' : $url;
|
||||||
|
return '<a href="' . $url . '" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:text-blue-800 underline">' . $displayUrl . '</a>';
|
||||||
|
}, $text);
|
||||||
|
|
||||||
|
// 3. Converte quebras de linha em <br>
|
||||||
|
$text = nl2br($text);
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limpa e normaliza quebras de linha no texto.
|
||||||
|
* Útil para normalizar dados antes de salvar no banco.
|
||||||
|
*
|
||||||
|
* @param string|null $text Texto a ser normalizado
|
||||||
|
* @return string Texto com quebras de linha normalizadas
|
||||||
|
*/
|
||||||
|
public static function normalizeLineBreaks(?string $text): string
|
||||||
|
{
|
||||||
|
if (empty($text)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normaliza todas as variações de quebra de linha para \n
|
||||||
|
$text = str_replace(["\r\n", "\r"], "\n", $text);
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
303
database/exports/dnsblock_production_20251207.sql
Normal file
303
database/exports/dnsblock_production_20251207.sql
Normal file
File diff suppressed because one or more lines are too long
89
database/migrations/2025_12_07_migrate_from_old_app.sql
Normal file
89
database/migrations/2025_12_07_migrate_from_old_app.sql
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
-- =============================================================================
|
||||||
|
-- Script de Migração: dados_antigos.sql → dnsblock
|
||||||
|
-- Data: 2025-12-07
|
||||||
|
-- Descrição: Migra ORDENS e DOMÍNIOS da aplicação antiga para a nova estrutura
|
||||||
|
-- =============================================================================
|
||||||
|
--
|
||||||
|
-- INSTRUÇÕES:
|
||||||
|
-- 1. Faça backup do banco de destino antes de executar
|
||||||
|
-- 2. PRIMEIRO importe o arquivo dados_antigos.sql no banco dnsblock:
|
||||||
|
-- mysql -u usuario -p dnsblock < dados_antigos.sql
|
||||||
|
-- 3. DEPOIS execute este script no banco dnsblock:
|
||||||
|
-- mysql -u usuario -p dnsblock < 2025_12_07_migrate_from_old_app.sql
|
||||||
|
--
|
||||||
|
-- O dados_antigos.sql cria as tabelas:
|
||||||
|
-- - dnsblock_ordens (ordens de bloqueio/desbloqueio)
|
||||||
|
-- - dnsblock_dominios (domínios associados às ordens)
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- 1. MIGRAR ORDENS (dnsblock_ordens → orders)
|
||||||
|
-- =============================================================================
|
||||||
|
INSERT INTO orders (id, title, type, content, received_at, created_at)
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
descricao AS title,
|
||||||
|
CASE
|
||||||
|
WHEN tipo_ordem = 'bloqueio' THEN 'block'
|
||||||
|
WHEN tipo_ordem = 'desbloqueio' THEN 'unblock'
|
||||||
|
ELSE 'block'
|
||||||
|
END AS type,
|
||||||
|
notas AS content,
|
||||||
|
data_ordem AS received_at,
|
||||||
|
data_cadastro AS created_at
|
||||||
|
FROM dnsblock_ordens
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
title = VALUES(title),
|
||||||
|
type = VALUES(type),
|
||||||
|
content = VALUES(content);
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- 2. MIGRAR DOMÍNIOS (dnsblock_dominios → domains)
|
||||||
|
-- =============================================================================
|
||||||
|
-- Domínios únicos com status e última ordem
|
||||||
|
INSERT INTO domains (name, status, last_order_id, created_at, updated_at)
|
||||||
|
SELECT
|
||||||
|
dominio AS name,
|
||||||
|
CASE WHEN status = 1 THEN 'blocked' ELSE 'unblocked' END AS status,
|
||||||
|
(SELECT MAX(ordem_id) FROM dnsblock_dominios d2 WHERE d2.dominio = d1.dominio) AS last_order_id,
|
||||||
|
MIN(data_cadastro) AS created_at,
|
||||||
|
MAX(data_cadastro) AS updated_at
|
||||||
|
FROM dnsblock_dominios d1
|
||||||
|
GROUP BY dominio
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
status = VALUES(status),
|
||||||
|
last_order_id = VALUES(last_order_id),
|
||||||
|
updated_at = VALUES(updated_at);
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- 3. MIGRAR ITENS DE ORDEM (dnsblock_dominios → order_items)
|
||||||
|
-- =============================================================================
|
||||||
|
INSERT INTO order_items (order_id, domain_id, action)
|
||||||
|
SELECT DISTINCT
|
||||||
|
dd.ordem_id AS order_id,
|
||||||
|
dom.id AS domain_id,
|
||||||
|
o.type AS action
|
||||||
|
FROM dnsblock_dominios dd
|
||||||
|
JOIN domains dom ON dom.name = dd.dominio
|
||||||
|
JOIN orders o ON o.id = dd.ordem_id
|
||||||
|
ON DUPLICATE KEY UPDATE action = VALUES(action);
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- LIMPEZA (remover tabelas do banco antigo após migração)
|
||||||
|
-- =============================================================================
|
||||||
|
-- Descomente as linhas abaixo após verificar que a migração foi bem sucedida:
|
||||||
|
-- DROP TABLE IF EXISTS dnsblock_dominios;
|
||||||
|
-- DROP TABLE IF EXISTS dnsblock_ordens;
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- FINALIZAÇÃO
|
||||||
|
-- =============================================================================
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|
||||||
|
-- Verificação
|
||||||
|
SELECT 'Ordens migradas:' AS info, COUNT(*) AS total FROM orders;
|
||||||
|
SELECT 'Domínios migrados:' AS info, COUNT(*) AS total FROM domains;
|
||||||
|
SELECT 'Itens de ordem:' AS info, COUNT(*) AS total FROM order_items;
|
||||||
@@ -24,7 +24,8 @@
|
|||||||
color: #1e40af;
|
color: #1e40af;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class="mt-2 text-gray-600 text-sm prose max-w-none"><?= $order['content'] ?></div>
|
<div class="mt-2 text-gray-600 text-sm prose max-w-none">
|
||||||
|
<?= \App\Utils\TextFormatter::formatContent($order['content'] ?? '') ?></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,8 @@
|
|||||||
color: #1e40af;
|
color: #1e40af;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class="prose max-w-none text-gray-700"><?= $order['content'] ?></div>
|
<div class="prose max-w-none text-gray-700">
|
||||||
|
<?= \App\Utils\TextFormatter::formatContent($order['content'] ?? '') ?></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user