<?php
if (function_exists('session_status')) {
    if (session_status() === PHP_SESSION_NONE) {
        @session_start();
    }
} elseif (session_id() === '') {
    @session_start();
}



function limpiar_html_nota($html) {
    $html = (string)$html;

    // Espacios raros / nbsp roto
    $html = str_replace(array("\xC2\xA0", "Â ", "Â&nbsp;"), ' ', $html);

    /*
      Repara mojibake típico:
      Ã¡ Ã© Ã¨ Ã  Ã± Å› â€œ â€ â€™ etc.
      No convierte todo el texto, solo los pedazos rotos,
      para no romper acentos que ya estén bien.
    */
    if (preg_match('/(?:Ã.|Â.|Å.|â..)/u', $html)) {
        $html = preg_replace_callback('/(?:Ã.|Â.|Å.|â..)+/u', function($m) {
            $s = $m[0];

            if (function_exists('mb_convert_encoding')) {
                $fix = @mb_convert_encoding($s, 'Windows-1252', 'UTF-8');
                if ($fix !== false && $fix !== '') {
                    return $fix;
                }
            }

            $fix = @utf8_decode($s);
            return ($fix !== false && $fix !== '') ? $fix : $s;
        }, $html);
    }

    // Limpieza final
    $html = str_replace(array("\xC2\xA0", "Â "), ' ', $html);
    $html = preg_replace('/[ \t]+/u', ' ', $html);

    return trim($html);
}


$tablet_browser = 0;
$mobile_browser = 0;
$body_class = 'desktop';

$http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
$http_accept     = isset($_SERVER['HTTP_ACCEPT']) ? strtolower($_SERVER['HTTP_ACCEPT']) : '';

if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', $http_user_agent)) {
    $tablet_browser++;
    $body_class = 'tablet';
}
if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|android|iemobile)/i', $http_user_agent)) {
    $mobile_browser++;
    $body_class = 'mobile';
}
if ((strpos($http_accept, 'application/vnd.wap.xhtml+xml') !== false) || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
    $mobile_browser++;
    $body_class = 'mobile';
}

$mobile_ua = strtolower(substr($http_user_agent, 0, 4));
$mobile_agents = array(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','palm','pana','pant','phil','play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda ','xda-'
);
if (in_array($mobile_ua, $mobile_agents, true)) {
    $mobile_browser++;
}
if (strpos($http_user_agent, 'opera mini') !== false) {
    $mobile_browser++;
    $stock_ua = strtolower(
        isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])
            ? $_SERVER['HTTP_X_OPERAMINI_PHONE_UA']
            : (isset($_SERVER['HTTP_DEVICE_STOCK_UA']) ? $_SERVER['HTTP_DEVICE_STOCK_UA'] : '')
    );
    if (preg_match('/(tablet|ipad|playbook)|(android(?!.*mobile))/i', $stock_ua)) {
        $tablet_browser++;
    }
}
if ($tablet_browser > 0) {
    $es_tablet = 'si';
} elseif ($mobile_browser > 0) {
    $es_movil = 'si';
}

include 'url_amigable.php';
include 'concha.php';

/* =========================================================
   FIX UTF-8 PARA COMENTARIOS Y RESPUESTAS
   ========================================================= */
if (isset($conn) && is_object($conn)) {
    if (method_exists($conn, 'set_charset')) {
        @$conn->set_charset('utf8mb4');
    }
    @mysqli_set_charset($conn, 'utf8mb4');
    @$conn->query("SET NAMES utf8mb4");
    @$conn->query("SET CHARACTER SET utf8mb4");
    @$conn->query("SET SESSION collation_connection = 'utf8mb4_unicode_ci'");
}

if ($lang_actual == 'es' || $lang_actual == '') {
    include 'lang_es_no_panel.php';
}
if ($lang_actual == 'pt') {
    include 'langes_pt_no_panel.php';
}

$ID = isset($_GET['ID']) ? (int)$_GET['ID'] : 0;
$ID_NOTA = $ID;
if ($ID <= 0) {
    exit;
}

$sql = "SELECT * FROM notas WHERE ID = '$ID' LIMIT 1";
$consulta = $conn->query($sql);
if (!$consulta || $consulta->num_rows === 0) {
    exit;
}
while ($row = $consulta->fetch_assoc()) {
    $ID = $row['ID'];
    $ID_NOTA = $row['ID'];
    $carpetafoto = $row['carpetafoto'];
    $foto = $row['foto'];
    $ext_img = $row['ext_img'];
    $cat_no = $row['cat'];
    $titulo = $row['titulo'];
    $texto = $row['texto'];
    $texto = str_replace('<div', '<span', $texto);
    $texto = str_replace('</div>', '</span>', $texto);
    $bajada = $row['bajada'];
    $audio = $row['audio'];
    $d = $row['d'];
    $m = $row['m'];
    $m2 = $row['m'];
    $a = $row['a'];
    $tag1 = $row['tag1'];
    $tag2 = $row['tag2'];
    $tag3 = $row['tag3'];
    $tag4 = $row['tag4'];
    $tag5 = $row['tag5'];
    $youtube = $row['youtube'];
    $visitas = $row['visitas'];
    $html = $row['html'];
    $ext_img = $row['ext_img'];
    $ID_editor = $row['editor'];
    $pie_foto = $row['pie_foto'];
    $ejemplo_marca_de_agua = $row['ejemplo_marca_de_agua'];
}
$consulta->free_result();

$visitas = (int)$visitas + 1;
$sSQL = "UPDATE `$basedatos`.`notas` SET `visitas` = '$visitas' WHERE ID = '$ID_NOTA'";
$conn->query($sSQL);

if (!function_exists('nm_h')) {
    function nm_h($v)
    {
        return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
    }
}
if (!function_exists('nm_bad_input')) {
    function nm_bad_input($s)
    {
        $s = trim((string)$s);
        if ($s === '') {
            return true;
        }
        if (stripos($s, 'http') !== false) {
            return true;
        }
        if (stripos($s, 'html') !== false) {
            return true;
        }
        if (strpos($s, '<') !== false || strpos($s, '>') !== false) {
            return true;
        }
        return false;
    }
}
if (!function_exists('nm_len')) {
    function nm_len($s)
    {
        return function_exists('mb_strlen') ? mb_strlen($s, 'UTF-8') : strlen($s);
    }
}
if (!function_exists('nm_sub')) {
    function nm_sub($s, $start, $len)
    {
        return function_exists('mb_substr') ? mb_substr($s, $start, $len, 'UTF-8') : substr($s, $start, $len);
    }
}
if (!function_exists('nm_generate_captcha')) {
    function nm_generate_captcha($largo)
    {
        $caracteres = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
        $max = strlen($caracteres) - 1;
        $codigo = '';
        for ($i = 0; $i < $largo; $i++) {
            if (function_exists('random_int')) {
                $codigo .= $caracteres[random_int(0, $max)];
            } else {
                $codigo .= $caracteres[mt_rand(0, $max)];
            }
        }
        return $codigo;
    }
}
if (!function_exists('nm_current_request_uri')) {
    function nm_current_request_uri()
    {
        $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
        if ($uri === '') {
            $query = isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] !== '' ? ('?' . $_SERVER['QUERY_STRING']) : '';
            $uri = 'nota.magazine.php' . $query;
        }
        return $uri;
    }
}
if (!function_exists('nm_build_note_url')) {
    function nm_build_note_url($dom, $id, $titulo)
    {
        return rtrim((string)$dom, '/') . '/nota/' . (int)$id . '/' . urls_amigables($titulo);
    }
}
if (!function_exists('nm_is_ajax_request')) {
    function nm_is_ajax_request()
    {
        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower((string)$_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
            return true;
        }
        if (isset($_POST['ajax']) && (string)$_POST['ajax'] === '1') {
            return true;
        }
        return false;
    }
}
if (!function_exists('nm_json_exit')) {
    function nm_json_exit(array $payload)
    {
        header('Content-Type: application/json; charset=utf-8');
        echo json_encode($payload, JSON_UNESCAPED_UNICODE);
        exit;
    }
}
if (!function_exists('nm_comment_publish_data')) {
    function nm_comment_publish_data($modo)
    {
        $ver = 'si';
        $status = 'publicado';

        if ($modo === 'facebook') {
            $ver = 'no';
            $status = 'moderado';
        } elseif ($modo === 'captcha') {
            $ver = 'si';
            $status = 'publicado';
        } else {
            $ver = 'si';
            $status = 'publicado';
        }

        return array($ver, $status);
    }
}
if (!function_exists('nm_render_reply_form')) {
    function nm_render_reply_form($ID_NOTA, $ID_comentario)
    {
        ob_start();
        ?>
        <div class="rn-reply-box" id="replyBox_<?php echo (int)$ID_comentario; ?>" style="display:none;">
            <form class="js-reply-form" method="post" action="<?php echo nm_h(nm_current_request_uri()); ?>#comentarios">
                <input type="hidden" name="accion_comentario" value="guardar_respuesta">
                <input type="hidden" name="IDD" value="<?php echo (int)$ID_NOTA; ?>">
                <input type="hidden" name="ID_comentario" value="<?php echo (int)$ID_comentario; ?>">
                <div class="js-reply-status"></div>

                <div class="form-group mb-2">
                    <label for="nombre_respuesta_<?php echo (int)$ID_comentario; ?>">Nombre</label>
                    <input
                        name="nombre_respuesta"
                        type="text"
                        class="form-control"
                        id="nombre_respuesta_<?php echo (int)$ID_comentario; ?>"
                        value=""
                        placeholder="Tu nombre"
                        autocomplete="off"
                        required
                    />
                </div>

                <div class="form-group mb-2">
                    <label for="texto_respuesta_<?php echo (int)$ID_comentario; ?>">Respuesta</label>
                    <textarea
                        name="texto_respuesta"
                        rows="3"
                        class="form-control"
                        id="texto_respuesta_<?php echo (int)$ID_comentario; ?>"
                        placeholder="Escribí tu respuesta..."
                        required
                    ></textarea>
                </div>

                <div class="d-flex justify-content-end">
                    <button type="submit" class="btn btn-sm btn-outline-primary js-reply-submit">Enviar</button>
                </div>
            </form>
        </div>
        <?php
        return ob_get_clean();
    }
}
if (!function_exists('nm_render_subcomments')) {
    function nm_render_subcomments($conn, $ID_comentario)
    {
        $ID_comentario = (int)$ID_comentario;
        $html = '';

        $sql33 = "SELECT * FROM comentarios WHERE sub_comentario = '$ID_comentario' AND ver = 'si' ORDER BY ID ASC";
        $consulta33 = $conn->query($sql33);
        if ($consulta33) {
            while ($row33 = $consulta33->fetch_assoc()) {
                $nombre33 = $row33['nombre'];
                $mensaje33 = $row33['texto'];

                $html .= '<div class="rn-sub">';
                $html .= '<p class="rn-comm-name mb-0">' . nl2br(nm_h($nombre33)) . '</p>';
                $html .= '<div class="rn-comm-meta">Respuesta</div>';
                $html .= '<div class="rn-comm-bubble">' . nl2br(nm_h($mensaje33)) . '</div>';
                $html .= '</div>';
            }
            $consulta33->free_result();
        }

        return $html;
    }
}
if (!function_exists('nm_render_comments_panel')) {
    function nm_render_comments_panel($conn, $ID_NOTA)
    {
        $ID_NOTA = (int)$ID_NOTA;
        ob_start();
        $c = 0;

        $sql = "SELECT * FROM comentarios WHERE IDD = '$ID_NOTA' AND ver = 'si' AND (sub_comentario = 0 OR sub_comentario IS NULL) ORDER BY ID DESC";
        $consulta = $conn->query($sql);
        if ($consulta) {
            while ($row = $consulta->fetch_assoc()) {
                $c++;
                $ID_comentario = (int)$row['ID'];
                $nombre_comentario = $row['nombre'];
                $texto_comentario = $row['texto'];
                ?>
                <div class="rn-comm-item" id="commentItem_<?php echo $ID_comentario; ?>">
                    <div class="d-flex justify-content-between align-items-start">
                        <div class="pr-3">
                            <p class="rn-comm-name"><?php echo nl2br(nm_h($nombre_comentario)); ?></p>
                            <div class="rn-comm-meta">Comentario</div>
                        </div>
                        <button
                            type="button"
                            class="btn btn-sm btn-outline-primary js-toggle-reply"
                            data-target="replyBox_<?php echo $ID_comentario; ?>"
                        >Responder</button>
                    </div>

                    <div class="rn-comm-bubble"><?php echo nl2br(nm_h($texto_comentario)); ?></div>

                    <?php echo nm_render_reply_form($ID_NOTA, $ID_comentario); ?>
                    <?php echo nm_render_subcomments($conn, $ID_comentario); ?>
                </div>
                <?php
            }
            $consulta->free_result();
        }

        if ($c == 0) {
            ?>
            <div class="rn-empty">Aun no hay comentarios, sé el primero en escribir uno.</div>
            <?php
        }

        return ob_get_clean();
    }
}

$comentarios = isset($comentarios) ? trim(strtolower((string)$comentarios)) : '';
if ($comentarios === '') {
    $comentarios = 'ninguna';
}
if ($comentarios !== 'facebook' && $comentarios !== 'captcha' && $comentarios !== 'ninguna') {
    $comentarios = 'ninguna';
}

$titulo_xx = ($utf == 1) ? utf8_decode($titulo) : $titulo;
$nota_url = nm_build_note_url($dom, $ID, $titulo);
$comentario_error = '';
$comentario_ok = '';
$comentario_post_nombre = '';
$comentario_post_texto = '';
$comentario_status = '';
$comentario_anchor = '#comentarios';
$captcha_session_key = 'nota_comment_captcha_' . (int)$ID_NOTA;
$es_ajax_request = nm_is_ajax_request();

if (isset($_SESSION['nota_comment_flash']) && is_array($_SESSION['nota_comment_flash']) && isset($_SESSION['nota_comment_flash'][$ID_NOTA])) {
    $flash = $_SESSION['nota_comment_flash'][$ID_NOTA];
    if (isset($flash['ok']) && $flash['ok'] !== '') {
        $comentario_ok = (string)$flash['ok'];
    }
    if (isset($flash['status']) && $flash['status'] !== '') {
        $comentario_status = (string)$flash['status'];
    }
    unset($_SESSION['nota_comment_flash'][$ID_NOTA]);
}

/* =========================================================
   AJAX / POST COMENTARIOS Y RESPUESTAS
   ========================================================= */
if (
    isset($_SERVER['REQUEST_METHOD'])
    && strtoupper($_SERVER['REQUEST_METHOD']) === 'POST'
    && isset($_POST['IDD'])
    && (int)$_POST['IDD'] === (int)$ID_NOTA
) {
    $accion_comentario = isset($_POST['accion_comentario']) ? (string)$_POST['accion_comentario'] : '';

    if ($accion_comentario === 'refrescar_captcha') {
        if ($comentarios === 'captcha') {
            $captcha_actual = nm_generate_captcha(5);
            $_SESSION[$captcha_session_key] = $captcha_actual;

            if ($es_ajax_request) {
                nm_json_exit(array(
                    'ok' => 1,
                    'captcha' => $captcha_actual
                ));
            }
        }
    }

    if ($accion_comentario === 'guardar_comentario' || $accion_comentario === 'guardar_respuesta') {
        $es_respuesta = ($accion_comentario === 'guardar_respuesta');
        $parent_id = 0;

        if ($es_respuesta) {
            $comentario_post_nombre = trim(isset($_POST['nombre_respuesta']) ? (string)$_POST['nombre_respuesta'] : (isset($_POST['nombre']) ? (string)$_POST['nombre'] : ''));
            $comentario_post_texto = trim(isset($_POST['texto_respuesta']) ? (string)$_POST['texto_respuesta'] : (isset($_POST['mensaje']) ? (string)$_POST['mensaje'] : (isset($_POST['texto']) ? (string)$_POST['texto'] : '')));
            $parent_id = isset($_POST['ID_comentario']) ? (int)$_POST['ID_comentario'] : 0;
        } else {
            $comentario_post_nombre = trim(isset($_POST['nombre']) ? (string)$_POST['nombre'] : '');
            $comentario_post_texto = trim(isset($_POST['texto']) ? (string)$_POST['texto'] : '');
        }

        if ($comentario_post_nombre === '') {
            $comentario_error = 'Debes escribir tu nombre.';
        } elseif ($comentario_post_texto === '') {
            $comentario_error = $es_respuesta ? 'Debes escribir una respuesta.' : 'Debes escribir un comentario.';
        } elseif (nm_bad_input($comentario_post_nombre) || nm_bad_input($comentario_post_texto)) {
            $comentario_error = 'No escribas links, mails ni etiquetas HTML.';
        } else {
            if (nm_len($comentario_post_nombre) > 80) {
                $comentario_post_nombre = nm_sub($comentario_post_nombre, 0, 80);
            }
            if (nm_len($comentario_post_texto) > 1500) {
                $comentario_post_texto = nm_sub($comentario_post_texto, 0, 1500);
            }

            if (!$es_respuesta && $comentarios === 'captcha') {
                $captcha_ingresado = strtoupper(trim(isset($_POST['captcha_texto']) ? (string)$_POST['captcha_texto'] : ''));
                $captcha_real = isset($_SESSION[$captcha_session_key]) ? strtoupper((string)$_SESSION[$captcha_session_key]) : '';
                if ($captcha_ingresado === '' || $captcha_real === '' || $captcha_ingresado !== $captcha_real) {
                    $comentario_error = 'El captcha no coincide.';
                }
            }

            if ($es_respuesta && $parent_id <= 0) {
                $comentario_error = 'No se encontró el comentario a responder.';
            }

            if ($es_respuesta && $comentario_error === '') {
                $sqlParent = "SELECT ID FROM comentarios WHERE ID = '" . (int)$parent_id . "' AND IDD = '" . (int)$ID_NOTA . "' LIMIT 1";
                $consultaParent = $conn->query($sqlParent);
                if (!$consultaParent || $consultaParent->num_rows === 0) {
                    $comentario_error = 'El comentario original no existe.';
                }
                if ($consultaParent) {
                    $consultaParent->free_result();
                }
            }
        }

        if ($comentario_error === '') {
            $IP_c = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
            list($ver, $comentario_status) = nm_comment_publish_data($comentarios);
            $sub = $es_respuesta ? (int)$parent_id : 0;

            $stmtIns = $conn->prepare('INSERT INTO comentarios (nombre, texto, IDD, ver, IP, sub_comentario) VALUES (?, ?, ?, ?, ?, ?)');
            if (!$stmtIns) {
                $comentario_error = 'Error interno al preparar el comentario.';
            } else {
                $stmtIns->bind_param('ssissi', $comentario_post_nombre, $comentario_post_texto, $ID_NOTA, $ver, $IP_c, $sub);
                if (!$stmtIns->execute()) {
                    $comentario_error = 'Error interno al guardar el comentario.';
                }
                $stmtIns->close();
            }

            if ($comentario_error === '') {
                if ($es_respuesta) {
                    if ($comentarios === 'facebook') {
                        $comentario_ok = 'Gracias. Tu respuesta fue enviada y quedó pendiente de moderación.';
                    } else {
                        $comentario_ok = 'Gracias. Tu respuesta fue publicada correctamente.';
                    }
                } else {
                    if ($comentarios === 'facebook') {
                        $comentario_ok = 'Gracias. Tu comentario fue enviado y quedó pendiente de moderación.';
                    } else {
                        $comentario_ok = 'Gracias. Tu comentario fue publicado correctamente.';
                    }
                }

                if (($e_email ?? '') === 'si') {
                    $recipiente = isset($emailsitio) ? (string)$emailsitio : '';
                    if ($recipiente !== '') {
                        $asunto = $es_respuesta ? 'NUEVA RESPUESTA EN UNA NOTA' : 'NUEVO MENSAJE EN UNA NOTA';
                        $msg = "-----------------------------------------------------\n"
                             . ($es_respuesta ? "NUEVA RESPUESTA:\n" : "NUEVO MENSAJE:\n")
                             . $comentario_post_texto . "\n"
                             . "-----------------------------------------------------\n"
                             . "PARA REVISARLO INGRESA AL PANEL " . (isset($dom) ? $dom : '') . "/panel\n";

                        $from = isset($email) ? (string)$email : (isset($emailsitio) ? (string)$emailsitio : '');
                        $headers = '';
                        if ($from !== '') {
                            $from = str_replace(array("\r", "\n"), '', $from);
                            $headers = 'From: ' . $from;
                        }
                        @mail($recipiente, $asunto, $msg, $headers);
                    }
                }

                unset($_SESSION[$captcha_session_key]);

                if ($es_ajax_request) {
                    $response = array(
                        'ok' => 1,
                        'message' => $comentario_ok,
                        'status' => $comentario_status,
                        'action' => $accion_comentario,
                        'list_html' => nm_render_comments_panel($conn, $ID_NOTA)
                    );

                    if ($es_respuesta) {
                        $response['parent_id'] = (int)$parent_id;
                    }

                    if ($comentarios === 'captcha') {
                        $captcha_actual = nm_generate_captcha(5);
                        $_SESSION[$captcha_session_key] = $captcha_actual;
                        $response['captcha'] = $captcha_actual;
                    }

                    nm_json_exit($response);
                }

                $_SESSION['nota_comment_flash'][$ID_NOTA] = array(
                    'ok' => $comentario_ok,
                    'status' => $comentario_status,
                );

                header('Location: ' . nm_current_request_uri() . $comentario_anchor);
                exit;
            }
        }

        if ($es_ajax_request) {
            $response = array(
                'ok' => 0,
                'message' => $comentario_error,
                'action' => $accion_comentario
            );

            if ($es_respuesta) {
                $response['parent_id'] = (int)$parent_id;
            }

            if ($comentarios === 'captcha') {
                $captcha_actual = nm_generate_captcha(5);
                $_SESSION[$captcha_session_key] = $captcha_actual;
                $response['captcha'] = $captcha_actual;
            }

            nm_json_exit($response);
        }
    }
}

$captcha_actual = '';
if ($comentarios === 'captcha') {
    $captcha_actual = nm_generate_captcha(5);
    $_SESSION[$captcha_session_key] = $captcha_actual;
}
?>
<!DOCTYPE html>
<html lang="<?php echo $lang_actual; ?>">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <?php $link_titulo = str_replace('http://', 'https://', $link_titulo); echo $link_titulo; ?>
    <?php $link_bajada = str_replace('http://', 'https://', $link_bajada); echo $link_bajada; ?>
    <?php $link_menu = str_replace('http://', 'https://', $link_menu); echo $link_menu; ?>
    <title><?php if ($utf == 1) { echo utf8_decode($titulo); } else { echo $titulo; } ?></title>
    <?php $bajada1 = str_replace('"', '', $bajada); ?>
    <meta name="description" content="<?php echo $bajada1; ?>" />
    <meta name="keywords" content="<?php echo $tag1; ?>, <?php echo $tag2; ?>, <?php echo $tag3; ?>, <?php echo $tag4; ?>, <?php echo $tag5; ?>">
    <meta name="language" content="<?php echo $lang_actual; ?>" />
    <meta property="og:type" content="article" />
    <meta property="og:title" content='<?php echo str_replace('"', '&#x22;', utf8_decode($titulo)); ?>' />
    <meta property="og:description" content="<?php echo utf8_decode($bajada1); ?>" />
    <meta property="og:url" content="<?php echo $dom; ?>/nota/<?php echo $ID; ?>/<?php echo urls_amigables($titulo); ?>" />
    <?php if ($foto == '') { ?>
        <meta property="og:image" content="https://x7.com.ar/gero/nofoto.png" />
    <?php } else { ?>
        <?php if ($domold != '') { $dom_bandera = $dom; $dom = $domold; } ?>
        <meta property="og:image" content="<?php echo $dom; ?>/<?php echo $carpetafoto; ?>/resize_<?php echo $foto; ?><?php echo $ext_img; ?>" />
        <?php $dom = $dom_bandera; ?>
    <?php } ?>
    <meta name="date" content="<?php echo $a; ?>-<?php echo str_pad($m, 2, '0', STR_PAD_LEFT); ?>-<?php echo str_pad($d, 2, '0', STR_PAD_LEFT); ?>" scheme="YYYY-MM-DD">
    <?php echo $head_en_concha; ?>
    <?php
    $sql2 = "SELECT * FROM audios WHERE nota = '$ID' ORDER BY ID LIMIT 1";
    $consulta2 = $conn->query($sql2);
    while ($row2 = $consulta2->fetch_assoc()) {
        $audio = $row2['mp3'];
    }
    $consulta2->free_result();
    $catba = isset($_GET['cat']) ? $_GET['cat'] : '';
    $i_publi = 10000000;
    ?>
    <link rel="shortcut icon" href="<?php echo $dom; ?>/icono.ico" type="image/x-icon" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link href="https://recursos.x7.com.ar/css/delalora<?php echo $estiloweb; ?>new.css" rel="stylesheet">
    <link rel="stylesheet" href="https://recursos.x7.com.ar/fli/flickity-master/dist/flickity.min.css" />
    <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
    <link rel="stylesheet" href="https://recursos.x7.com.ar/css/css/lightbox.min.css">
    <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
        (function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/es_LA/all.js#xfbml=1&appId=427523193949843";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    </script>
    <style>
        body {
            <?php
            $e = substr((string)$d_color_fondo, 0, 1);
            $e1 = substr((string)$d_color_fondo, 0, 4);
            if ($e == '#') {
                ?>background-color:<?php echo $d_color_fondo; ?>;<?php
            } else {
                if ($e1 == 'http') {
                    ?>background-image:url(<?php echo $d_color_fondo; ?>);background-repeat:repeat;<?php
                } else {
                    ?>
                    background-image:url("https://recursos.x7.com.ar/recursos.radiosnethosting.com/fondos/<?php echo $d_color_fondo; ?>");
                    background-attachment:fixed;
                    -webkit-background-size:cover;
                    -moz-background-size:cover;
                    -o-background-size:cover;
                    background-size:cover;
                    <?php
                }
            }
            ?>
            overflow-x:hidden;
            margin:0 auto;
        }
        h1, h2, h3, h4, h5, h6 {
            margin-bottom:10px;
            line-height:1.1em;
            font-weight:600;
            margin-top:0;
            color:<?php echo $d_color_titulo; ?>;
            font-family:<?php echo $style_titulo; ?>;
        }
        p { font-family:<?php echo $style_bajada; ?>; }
        .h3, h3 { font-size:1rem; }
        h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { display:block; color:<?php echo $d_color_menu; ?>; }
        a:hover { color:<?php echo $d_color_menu_sobre; ?>; }
        p > a { display:initial; color:#111; text-decoration:underline !important; }
        .navbar-nav .dropdown-menu { position:absolute; background-color:<?php echo $d_color_fondo_menu; ?>; }
        .dropdown:hover>ul { display:block !important; }
        .dropdown ul li a { color:<?php echo $d_color_menu; ?>; }
        .navbar-light .navbar-nav .nav-link:focus, .navbar-light .navbar-nav { color:<?php echo $d_color_menu; ?>; }
        .nav-link:hover { color:<?php echo $d_color_menu_sobre; ?>; }
        #logo { max-width:3.2rem; }
        #logo:hover path { fill:<?php echo $d_color_menu; ?>; }
        #logo:hover { color:<?php echo $d_color_menu_sobre; ?>; }
        #logo2 { fill:<?php echo $d_color_weather2; ?>; max-width:48px; }
        #logo3 { fill:<?php echo $d_color_weather2; ?>; max-width:18px; }
        .color { color:<?php echo $d_color_menu; ?>; }
        .btn-outline-primary.active,
        .btn-outline-primary:active,
        .show>.btn-outline-primary.dropdown-toggle {
            color:<?php echo $d_color_fondo_menu; ?>;
            background-color:<?php echo $d_color_menu; ?>;
            border:3px solid <?php echo $d_color_fondo_menu; ?>;
        }
        .btn-outline-primary:hover {
            color:<?php echo $d_color_fondo_menu; ?>;
            background-color:<?php echo $d_color_menu; ?>;
            border:3px solid <?php echo $d_color_fondo_menu; ?>;
        }
        .btn-outline-primary {
            color:<?php echo $d_color_menu; ?>;
            background-color:<?php echo $d_color_fondo_menu; ?>;
            border:3px solid <?php echo $d_color_menu; ?>;
        }
        footer p {
            margin-bottom:.25rem;
            color:<?php echo $d_color_menu; ?>;
            font-weight:300;
        }
        .facebook {
            display:block;
            float:right;
            background:<?php echo $d_color_menu; ?>;
            margin-right:37px !important;
        }
        .twitter {
            display:block;
            float:right;
            background:<?php echo $d_color_menu; ?>;
        }
        .flickity-page-dots .dot { background:<?php echo $d_color_menu; ?>; }
        .sidebar { will-change:min-height; }
        .sidebar__inner {
            transform:translate(0, 0);
            transform:translate3d(0, 0, 0);
            will-change:position, transform;
        }
        .sidebar .widget .widget-title { font-size:20px; }
        <?php
        $hexa = substr((string)$d_color_fondo_menu, 1);
        $decimal = hexdec($hexa);
        if ($decimal <= 10066329) {
            $color_titulo_barra = '250,250,250,0.9';
        } else {
            $color_titulo_barra = '0,0,0,0.9';
        }
        ?>
        .widget-head { background-color:<?php echo $d_color_fondo_menu; ?> !important; }
        .widget-title {
            font-size:25px;
            font-weight:900;
            line-height:1;
            text-transform:uppercase;
            margin-bottom:0;
            color:<?php echo $d_color_menu; ?>;
            font-family:<?php echo $style_titulo; ?>;
        }
        .topbar {
            border-bottom:0;
            background-color:<?php echo $d_color_fondo_menu; ?>;
            color:<?php echo $d_color_menu; ?>;
        }
        .header {
            min-height:130px;
            display:flex;
            align-items:center;
            <?php
            if ($textura == null && $logo_g == null) {
                ?>background-color:<?php echo $d_color_fondo_cabecera; ?>;<?php
            } elseif ($textura != null) {
                ?>
                background-position:center center;
                background-size:cover;
                background-repeat:no-repeat;
                background-image:url(<?php $textura = str_replace('http://', 'https://', $textura); $textura = str_replace('www.radiosnet.com.ar', 'recursos.x7.com.ar/recursos.radiosnethosting.com', $textura); echo $textura; ?>);
                -moz-background-size:cover;
                -webkit-background-size:cover;
                <?php
            } else {
                ?>
                background-position:center center;
                background-size:cover;
                background-repeat:no-repeat;
                background-image:url(<?php echo $logo_g; ?>);
                -moz-background-size:cover;
                -webkit-background-size:cover;
                <?php
            }
            ?>
            clear:both;
        }
        .header-right { float:right; }
        .logo { max-width:80%; }
        .bg-light { background-color:#fff !important; }
        article { background:transparent; }
        .colorTitulo {
            color:<?php echo $d_color_titulo; ?>;
            font-weight:800;
            letter-spacing:1px;
        }
        .facebook {
            display:block;
            float:right;
            background-color:<?php echo $color_cat; ?> !important;
            margin-right:37px !important;
        }
        .twitter {
            display:block;
            float:right;
            background-color:<?php echo $color_cat; ?> !important;
        }
        p.displaytitulo {
            height:0;
            margin:0;
            font-family:'Montserrat', sans-serif !important;
            letter-spacing:1px;
        }
        .carousel-caption {
            z-index:10;
            padding:4px 20px;
            background-color:<?php echo $d_color_fondo_menu; ?>99;
        }
        .carousel-caption h2 {
            color:<?php echo $d_color_menu; ?> !important;
            font-weight:700;
            margin:0;
            font-size:2.5vw;
        }
        .localidad {
            font-family:<?php echo $style_titulo; ?>;
            color:<?php echo $d_color_weather2; ?>;
            line-height:1;
        }
        .titulo {
            display:none;
            position:absolute;
            bottom:0;
            height:100%;
            width:100%;
            padding:20px 15px;
            background-color:<?php echo $d_color_fondo_menu; ?>;
            opacity:0.7;
        }
        .cub3r-caption {
            position:absolute;
            bottom:0;
            left:0;
            background-color:<?php echo $d_color_fondo_menu; ?>99;
            width:100%;
            padding:0.5rem 0.75rem;
        }
        .cub3r-caption-text { color:<?php echo $d_color_menu; ?> !important; }
        .html-marquee {
            font-weight:200;
            height:40px !important;
            width:100%;
            background-color:transparent !important;
            font-family:'Montserrat', sans-serif !important;
            font-size:inherit !important;
            color:<?php echo $d_color_menu; ?> !important;
            letter-spacing:0.5px;
        }
        marquee p { color:<?php echo $d_color_menu; ?> !important; }
        .texto-fecha { color:<?php echo $d_color_menu; ?>; }
        .navbar-toggler-icon { color:<?php echo $d_color_menu; ?>; }
        .share-x-icon {
            display:inline-flex;
            align-items:center;
            justify-content:center;
            width:30px;
            height:30px;
            color:#111111;
        }
        .share-x-icon svg {
            width:24px;
            height:24px;
            fill:currentColor;
            display:block;
        }
        .nm-comment-help {
            font-size:13px;
            color:rgba(0,0,0,.6);
            margin-top:6px;
        }
        .nm-captcha-box {
            margin-top:10px;
            padding:12px;
            border:1px solid #ddd;
            background:#f8f9fa;
            border-radius:12px;
        }
        .nm-captcha-code {
            font-size:24px;
            font-weight:700;
            letter-spacing:6px;
            background:#fff;
            border:1px solid #ccc;
            padding:10px;
            text-align:center;
            margin-bottom:10px;
            border-radius:10px;
        }
        .rn-reply-box {
            margin-top:12px;
            padding:14px;
            background:#fafafa;
            border:1px solid rgba(0,0,0,.08);
            border-radius:12px;
        }
        .rn-reply-box label {
            font-size:12px;
            font-weight:700;
            color:rgba(0,0,0,.65);
            margin-bottom:6px;
        }
        .rn-reply-box .form-control {
            border-radius:10px;
            border-color:rgba(0,0,0,.14);
        }
        .rn-reply-box .form-control:focus {
            border-color:rgba(0,123,255,.45);
            box-shadow:0 0 0 .2rem rgba(0,123,255,.12);
        }
        .js-reply-status .alert {
            margin-bottom:12px;
        }
    </style>
</head>
<body>
<?php if ($estiloweb == 72) { include 'menu_magazine.php'; } ?>
<div class="bg-light <?php if ($opcion101 == 1) { echo 'container-fluid'; } if ($opcion101 == 0) { echo 'container'; } ?> pt-3">
    <div id="main-content" class="row main">
        <div id="content" class="content col-12 col-sm-8 p-0 col-md-8 col-lg-8 ">
            <div class="col-lg-12 col-12 base-box2" style="display:flex;justify-content:space-between;">
                <?php
                $Y = $a;
                $M = $m2;
                $D = $d;
                $date = "$Y$M$D";
                if ($M == '01') { $m = 'enero'; }
                if ($M == '02') { $m = 'febrero'; }
                if ($M == '03') { $m = 'marzo'; }
                if ($M == '04') { $m = 'abril'; }
                if ($M == '05') { $m = 'mayo'; }
                if ($M == '06') { $m = 'junio'; }
                if ($M == '07') { $m = 'julio'; }
                if ($M == '08') { $m = 'agosto'; }
                if ($M == '09') { $m = 'septiembre'; }
                if ($M == '10') { $m = 'octubre'; }
                if ($M == '11') { $m = 'noviembre'; }
                if ($M == '12') { $m = 'diciembre'; }
                ?>
                <?php if ($cat_no != 0) {
                    $sql2 = "SELECT * FROM categorias WHERE ID = '$cat_no' LIMIT 1";
                    $consulta2 = $conn->query($sql2);
                    while ($row2 = $consulta2->fetch_assoc()) {
                        $cat_nom = $row2['nombre'];
                        $color_cat = $row2['color'];
                    }
                    $consulta2->free_result();
                    if ($cat_nom != '' || $cat_nom != null) {
                        ?>
                        <div style="background-color:<?php if ($color_cat == '' || $color_cat == '#FFFFFF') { echo '#666666'; } else { echo $color_cat; } ?>;">
                            <p class="m-0 py-1 px-2" style="font-family:<?php echo $style_titulo; ?>;color:#FFFFFF;">
                                <?php echo strtoupper($cat_nom); ?>
                            </p>
                        </div>
                    <?php } else { ?>
                        <div>
                            <p class="m-0 py-1 px-2"><?php echo strtoupper($cat_nom); ?></p>
                        </div>
                    <?php }
                } ?>
                <?php if ($apagar_la_fecha != 1) { ?>
                    <div>
                        <p class="m-0 py-1 px-2" style="font-family:<?php echo $style_titulo; ?>;font-size:14px;color:<?php echo $d_color_titulo; ?>;">
                            <?php echo $D; ?> de <?php echo $m; ?> de <?php echo $a; ?>
                        </p>
                    </div>
                <?php } ?>
            </div>
            <div class="col-lg-12 col-12 base-box2 p-0 px-md-3">
                <div class="mb-3">
                    <h2 style="padding:15px;font-family:<?php echo $style_titulo; ?>;color:<?php echo $d_color_titulo; ?>;"><?php if ($utf == 1) { echo utf8_decode($titulo); } else { echo $titulo; } ?></h2>
                </div>
                <?php if ($foto != null) { ?>
                    <?php if ($domold != '') { $dom_bandera = $dom; $dom = $domold; } ?>
                    <div class="col-lg-12 col-12 p-0">
                        <?php if ($ejemplo_marca_de_agua == null) { ?>
                            <?php if ($domold != '') { $dom_bandera = $dom; $dom = $domold; } ?>
                            <div align="left">
                                <img class="<?php if ($estiloweb <= 3) { echo 'img-responsive'; } else { echo 'img-fluid'; } ?>" src="<?php $fotojj = substr($foto, 0, 4); if ($fotojj == 'http') { echo $foto; } else { echo $dom; ?>/<?php echo $carpetafoto; ?>/resize_<?php echo $foto; ?><?php echo $ext_img; ?><?php } ?>" />
                            </div>
                            <?php $dom = $dom_bandera; ?>
                        <?php } else { ?>
                            <div align="left">
                                <img class="<?php if ($estiloweb <= 3) { echo 'img-responsive'; } else { echo 'img-fluid'; } ?>" src="<?php echo $dom; ?>/<?php echo $ejemplo_marca_de_agua; ?>?i=<?php echo $carpetafoto; ?>/resize_<?php echo $foto; ?><?php echo $ext_img; ?>" />
                            </div>
                        <?php } ?>
                        <?php $dom = $dom_bandera; ?>
                        <?php if ($pie_foto != '') { ?>
                            <p style="padding:0;font-size:13px;line-height:18px;color:rgb(175, 174, 174);font-family:Roboto, sans-serif;font-weight:700;margin-left:0 !important;letter-spacing:1px;"><?php echo $pie_foto; ?></p>
                        <?php } ?>
                    </div>
                <?php } ?>

                <?php
                if ($ID_editor != 0) {
                    $sql65 = "SELECT * FROM editores WHERE ID = '$ID_editor' LIMIT 1";
                    $consulta65 = $conn->query($sql65);
                    while ($row65 = $consulta65->fetch_assoc()) {
                        $nombre_editor = $row65['nombre'];
                        $telefono_editor = $row65['telefono'];
                        $email_editor = $row65['email'];
                        $instagram_editor = $row65['instagram'];
                        $facebook_editor = $row65['facebook'];
                        $twitter_editor = $row65['twitter'];
                        $foto_editor = $row65['foto'];
                        $ID_editor = $row65['ID'];
                    }
                    $consulta65->free_result();
                    ?>
                    <div class="row">
                        <div class="col-2 col-sm-2 col-md-2 col-lg-2" style="padding:10px;">
                            <img class="img-fluid img-responsive" src="<?php echo $foto_editor; ?>" data-hidpi="#" style="max-height:60px;margin:0 auto;border-radius:50%!important;">
                        </div>
                        <div class="col-10 col-sm-10 col-md-10 col-lg-10" style="padding:10px;">
                            <b>Por: <?php echo $nombre_editor; ?></b>
                            <ul class="navbar-nav ml-auto" style="display:inline-block;">
                                <?php if ($facebook_editor != '') { ?>
                                    <li class="nav-item2" style="display:inline-flex;margin-right:10px;">
                                        <a href="<?php echo $facebook_editor; ?>" style="padding:0;" target="_blank">
                                            <h4 style="margin:0; padding:0.5em;"><i class="fab fa-facebook-square" style="font-size:1.5em;"></i></h4>
                                        </a>
                                    </li>
                                <?php } ?>
                                <?php if ($twitter_editor != '') { ?>
                                    <li class="nav-item2" style="display:inline-flex;margin-right:10px;">
                                        <a href="<?php echo $twitter_editor; ?>" style="padding:0;" target="_blank">
                                            <h4 style="margin:0; padding:0.5em;"><i class="fab fa-twitter-square" style="font-size:1.5em;"></i></h4>
                                        </a>
                                    </li>
                                <?php } ?>
                                <?php if ($instagram_editor != '') { ?>
                                    <li class="nav-item2" style="display:inline-flex;margin-right:10px;">
                                        <a href="<?php echo $instagram_editor; ?>" style="padding:0;" target="_blank">
                                            <h4 style="margin:0; padding:0.5em;"><i class="fab fa-instagram" style="font-size:1.5em;"></i></h4>
                                        </a>
                                    </li>
                                <?php } ?>
                                <?php if ($email_editor != '') { ?>
                                    <li class="nav-item2" style="display:inline-flex;margin-right:10px;">
                                        <a href="mailto:<?php echo $email_editor; ?>" style="padding:0;" target="_blank">
                                            <h4 style="margin:0; padding:0.5em;"><i class="fas fa-envelope" style="font-size:1.5em;"></i></h4>
                                        </a>
                                    </li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                <?php } ?>

                <div class="grid mt-3 fg">
                    <?php
                    $sql65 = "SELECT * FROM fotos_notas WHERE noticia = '$ID'";
                    $consulta65 = $conn->query($sql65);
                    while ($row65 = $consulta65->fetch_assoc()) {
                        $carpetafoto1 = $row65['carpetafoto'];
                        $ID_foto = $row65['ID'];
                        $foto_galeria = $row65['foto'];
                        ?>
                        <div class="grid-item col-lg-2 col-md-3 col-sm-12 col-12" style="margin-bottom:15px;">
                            <?php if ($domold != '') { $dom_bandera = $dom; $dom = $domold; } ?>
                            <a data-lightbox="example-set" href="<?php echo $dom; ?>/<?php echo $carpetafoto1; ?>/resize_<?php echo $foto_galeria; ?>.jpg" title="<?php echo $titulo; ?>">
                                <img src="<?php echo $dom; ?>/<?php echo $carpetafoto1; ?>/thumbnail_<?php echo $foto_galeria; ?>.jpg" class="img-fluid" />
                            </a>
                            <?php $dom = $dom_bandera; ?>
                        </div>
                    <?php }
                    $consulta65->free_result();

                    $sql65 = "SELECT * FROM fotosnotasfull WHERE ID_nota = '$ID'";
                    $consulta65 = $conn->query($sql65);
                    while ($row65 = $consulta65->fetch_assoc()) {
                        $ID_foto = $row65['ID'];
                        $img = $row65['img'];
                        ?>
                        <div class="grid-item col-lg-2 col-md-3 col-sm-12 col-12" style="margin-bottom:15px;">
                            <a href="<?php echo $img; ?>" rel="lightbox[<?php echo $ID; ?>]" title="<?php echo $titulo; ?>"><img src="<?php echo $dom; ?>/timthumb.php?src=<?php echo $img; ?>&w=500&q=80" class="img-fluid" /></a>
                        </div>
                    <?php }
                    $consulta65->free_result(); ?>
                </div>

                <div class="col-lg-12 col-12 mb-3">
                    <p style="font-family:<?php echo $style_bajada; ?>;"><?php if ($utf == 1) { echo utf8_decode($bajada); } else { echo $bajada; } ?></p>
                </div>

                <?php echo $ads_bajada_1; ?>

                <?php if ($audio != null) { ?>
                    <div class="col-lg-12 col-12 mb-3"><?php include 'audio_new.php'; ?></div>
                <?php } ?>

                <?php if ($youtube != null) { ?>
                    <div class="col-lg-12 col-12 mb-3">
                        <div style="position:relative;padding-bottom:56.25%;">
                            <iframe style="position:absolute;width:100%;height:100%;" src="https://www.youtube.com/embed/<?php echo $youtube; ?>" frameborder="0" allowfullscreen></iframe>
                        </div>
                    </div>
                <?php } ?>

                <div class="col-lg-12 col-12 mb-3">
                    <div id="fb-root"></div>
                    <div class="col-lg-12 col-12 p-0 mb-3 d-flex justify-content-center py-3">
                        <?php include 'rotativas_random_arriba.php'; ?>
                    </div>
                    <div class="col-lg-12 col-12 p-0">
                        <?php
                        $texto = str_replace('<img', '<img class="img-fluid"', $texto);
$texto = limpiar_html_nota($texto);

                        $need_x = false;
                        $need_tiktok = false;

                        if (!function_exists('sc_h')) {
                            function sc_h($s) { return htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); }
                        }
                        if (!function_exists('sc_norm_url')) {
                            function sc_norm_url($u) {
                                $u = trim((string)$u);
                                if ($u === '') return '';
                                if (!preg_match('~^https?://~i', $u)) $u = 'https://' . ltrim($u, '/');
                                return $u;
                            }
                        }
                        if (!function_exists('sc_youtube_id')) {
                            function sc_youtube_id($u) {
                                $u = trim((string)$u);
                                if ($u === '') return '';
                                if (preg_match('~^[A-Za-z0-9_-]{6,}$~', $u)) return $u;
                                $u = sc_norm_url($u);
                                if (preg_match('~youtu\.be/([A-Za-z0-9_-]{6,})~', $u, $m)) return $m[1];
                                if (preg_match('~[?&]v=([A-Za-z0-9_-]{6,})~', $u, $m)) return $m[1];
                                if (preg_match('~/(shorts|embed)/([A-Za-z0-9_-]{6,})~', $u, $m)) return $m[2];
                                return '';
                            }
                        }
                        if (!function_exists('sc_instagram_parts')) {
                            function sc_instagram_parts($u) {
                                $u = trim((string)$u);
                                if ($u === '') return array('', '');
                                if (preg_match('~^[A-Za-z0-9_-]+$~', $u)) return array('p', $u);
                                $u = sc_norm_url($u);
                                if (preg_match('~/(p|reel|tv)/([^/?#]+)~', $u, $m)) {
                                    return array($m[1], $m[2]);
                                }
                                return array('', '');
                            }
                        }

                        $texto = preg_replace_callback('~\[\s*img\s*\](.*?)\[\s*/\s*img\s*\]~is', function($m) {
                            $u = trim($m[1]);
                            if ($u === '') return $m[0];
                            $href = sc_norm_url($u);
                            $thumb = '../../timthumb.php?src=' . $href . '&w=1000&q=80';
                            return '<a href="'.sc_h($href).'" data-lightbox="nota-img" style="display:block;">'
                                 . '<img style="display:block;width:100%;height:auto;background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);cursor:zoom-in;" class="img-fluid" src="'.sc_h($thumb).'">'
                                 . '</a>';
                        }, $texto);

                        $texto = preg_replace('~\[\s*hr\s*\]\s*\[\s*/\s*hr\s*\]~i', '<hr>', $texto);
                        $texto = preg_replace_callback('~\[\s*alert\s*\](.*?)\[\s*/\s*alert\s*\]~is', function($m) {
                            $inner = trim($m[1]);
                            return '<div class="alert alert-info" role="alert" style="margin:18px 0 26px;">'.$inner.'</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*youtube\s*\](.*?)\[\s*/\s*youtube\s*\]~is', function($m) {
                            $id = sc_youtube_id($m[1]);
                            if ($id === '') return $m[0];
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<div style="position:relative;padding-bottom:56.25%;">'
                                 . '<iframe style="position:absolute;width:100%;height:100%;border:0;" src="https://www.youtube.com/embed/'.sc_h($id).'" frameborder="0" allowfullscreen loading="lazy"></iframe>'
                                 . '</div>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*ig\s*\](.*?)\[\s*/\s*ig\s*\]~is', function($m) {
                            $code = trim($m[1]);
                            if ($code === '') return $m[0];
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px auto 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;max-width:760px;">'
                                 . '<div style="max-width:540px;margin:0 auto;">'
                                 . '<iframe src="https://www.instagram.com/p/'.sc_h($code).'/embed/" style="display:block;width:100%;height:1060px;border:0;overflow:hidden;" frameborder="0" scrolling="no" allowtransparency="true" loading="lazy"></iframe>'
                                 . '</div>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*instagram\s*\](.*?)\[\s*/\s*instagram\s*\]~is', function($m) {
                            list($tipo, $code) = sc_instagram_parts($m[1]);
                            if ($tipo === '' || $code === '') return $m[0];
                            $permalink = 'https://www.instagram.com/' . trim($tipo) . '/' . trim($code) . '/';
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px auto 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;max-width:760px;">'
                                 . '<div style="max-width:540px;margin:0 auto;">'
                                 . '<iframe src="'.sc_h($permalink).'embed/" style="display:block;width:100%;height:1060px;border:0;overflow:hidden;" frameborder="0" scrolling="no" allowtransparency="true" loading="lazy"></iframe>'
                                 . '</div>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*xpost\s*\](.*?)\[\s*/\s*xpost\s*\]~is', function($m) use (&$need_x) {
                            $need_x = true;
                            $url = sc_norm_url($m[1]);
                            if ($url === '') return $m[0];
                            $url = preg_replace('~^https?://(www\.)?x\.com/~i', 'https://twitter.com/', $url);
                            $url = preg_replace('~\?.*$~', '', $url);
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<div style="max-width:550px;margin:0 auto;">'
                                 . '<blockquote class="twitter-tweet" data-dnt="true" style="margin:0 auto;">'
                                 . '<a href="'.sc_h($url).'"></a>'
                                 . '</blockquote>'
                                 . '</div>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*facebook\s*\](.*?)\[\s*/\s*facebook\s*\]~is', function($m) {
                            $url = sc_norm_url($m[1]);
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<div style="max-width:550px;margin:0 auto;">'
                                 . '<div class="fb-post" data-href="'.sc_h($url).'" data-width="500"></div>'
                                 . '</div>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*tiktok\s*\](.*?)\[\s*/\s*tiktok\s*\]~is', function($m) use (&$need_tiktok) {
                            $need_tiktok = true;
                            $url = sc_norm_url($m[1]);
                            $vid = '';
                            if (preg_match('~/video/(\d+)~', $url, $mm)) $vid = $mm[1];
                            if ($vid !== '') {
                                return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                     . '<blockquote class="tiktok-embed" cite="'.sc_h($url).'" data-video-id="'.sc_h($vid).'" style="max-width:605px;min-width:325px;margin:0 auto;"><section></section></blockquote>'
                                     . '</div>';
                            }
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<blockquote class="tiktok-embed" cite="'.sc_h($url).'" style="max-width:605px;min-width:325px;margin:0 auto;"><section><a href="'.sc_h($url).'" target="_blank" rel="noopener">Ver en TikTok</a></section></blockquote>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*spotify\s*\](.*?)\[\s*/\s*spotify\s*\]~is', function($m) {
                            $url = sc_norm_url($m[1]);
                            if (preg_match('~^https?://open\.spotify\.com/([^/?#]+)/([^/?#]+)~i', $url, $mm)) {
                                $url = 'https://open.spotify.com/embed/' . $mm[1] . '/' . $mm[2];
                            }
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<iframe style="border-radius:12px;display:block;width:100%;border:0;" src="'.sc_h($url).'" width="100%" height="152" frameborder="0" allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture" loading="lazy"></iframe>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*soundcloud\s*\](.*?)\[\s*/\s*soundcloud\s*\]~is', function($m) {
                            $url = sc_norm_url($m[1]);
                            $src = 'https://w.soundcloud.com/player/?url=' . rawurlencode($url) . '&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true';
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<iframe style="display:block;width:100%;border:0;" width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="'.sc_h($src).'" loading="lazy"></iframe>'
                                 . '</div>';
                        }, $texto);

                        $texto = preg_replace_callback('~\[\s*map\s*\](.*?)\[\s*/\s*map\s*\]~is', function($m) {
                            $url = sc_norm_url($m[1]);
                            if (strpos($url, '/maps/embed') !== false) {
                                $src = $url;
                            } else {
                                $src = 'https://www.google.com/maps?output=embed&q=' . rawurlencode($url);
                            }
                            return '<div style="background:#fff;padding:10px;border:1px solid rgba(0,0,0,.08);border-radius:12px;margin:18px 0 26px;box-shadow:0 10px 22px rgba(0,0,0,.10);overflow:hidden;">'
                                 . '<div style="position:relative;padding-bottom:56.25%;">'
                                 . '<iframe style="position:absolute;width:100%;height:100%;border:0;" src="'.sc_h($src).'" frameborder="0" loading="lazy"></iframe>'
                                 . '</div>'
                                 . '</div>';
                        }, $texto);
                        ?>

                        <?php if ($adsense != ' ') { echo $adsense; } ?>
                        <div style="font-size:18px;line-height:1.85;color:rgba(0,0,0,.88);max-width:760px;overflow-wrap:break-word;word-wrap:break-word;"><?php echo $texto; ?></div>
                        <?php if ($adsense != ' ') { echo $adsense; } ?>

                        <?php
                        if ($need_x) {
                            echo '<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>';
                            echo '<script>(function(){function renderX(){if(window.twttr&&twttr.widgets&&typeof twttr.widgets.load==="function"){twttr.widgets.load();return true;}return false;}if(!renderX()){var n=0;var t=setInterval(function(){n++;if(renderX()||n>40) clearInterval(t);},250);}})();</script>';
                        }
                        if ($need_tiktok) {
                            echo '<script async src="https://www.tiktok.com/embed.js"></script>';
                        }
                        ?>
                    </div>

                    <?php echo $ads_bajada_2; ?>

                    <?php if ($html != null) { ?>
                        <div style="position:relative;padding-bottom:56.25%;"><?php echo $html; ?></div>
                    <?php } ?>

                    <?php
                    $sql65 = "SELECT * FROM videos WHERE ID_nota = '$ID' LIMIT 1";
                    $consulta65 = $conn->query($sql65);
                    while ($row65 = $consulta65->fetch_assoc()) {
                        $ID_video = $row65['ID'];
                        $video = $row65['video'];
                        if ($video) {
                            ?>
                            <div class="col-lg-12 col-12 mb-3">
                                <div>
                                    <video controls style="width:100%;">
                                        <source src="<?php echo $video; ?>" type="video/mp4">
                                        Su Navegador no Soporta Video
                                    </video>
                                </div>
                            </div>
                            <?php
                        }
                    }
                    $consulta65->free_result();
                    ?>

                    <div class="col-lg-12 col-12">
                        <style>
                            .fb-like > span > iframe { width:2100% !important; }
                        </style>
                        <div class="fb-like" data-href="<?php echo $dom; ?>/nota/<?php echo $ID; ?>/<?php echo urls_amigables($titulo); ?>" data-layout="button_count" data-action="like" data-size="large" data-show-faces="true" data-share="true"></div>
                    </div>

                    <div class="col-lg-12 col-12">
                        <?php
                        $sql65 = "SELECT * FROM archivos WHERE ID_nota = '$ID_NOTA'";
                        $consulta65 = $conn->query($sql65);
                        while ($row65 = $consulta65->fetch_assoc()) {
                            $ruta = $row65['ruta'];
                            $tipo = $row65['tipo'];
                            if ($tipo == 'pdf') {
                                echo "<iframe src='$ruta' width='100%' height='500px'></iframe>";
                            }
                            ?>
                            <a class="btn" target="_blank" href="<?php echo $ruta; ?>"><img src="<?php
                                if ($tipo == 'xls' || $tipo == 'xlsx') { echo 'https://radiosnet.com.ar/xls.png'; }
                                if ($tipo == 'doc' || $tipo == 'docx') { echo 'https://radiosnet.com.ar/doc.png'; }
                            ?>" /></a>
                            <?php
                        }
                        $consulta65->free_result();
                        ?>
                    </div>

                    <div class="col-lg-12 col-12 p-0 mb-3 d-flex justify-content-center py-3">
                        <?php include 'rotativas_random_abajo.php'; ?>
                    </div>

                    <div class="col-lg-12 col-12">
                        <h4>COMPARTIR:</h4>
                        <?php
                        $share_url = $dom . '/nota/' . $ID . '/' . urls_amigables($titulo_xx);
                        $share_url_encoded = rawurlencode($share_url);
                        $share_title_encoded = rawurlencode($titulo_xx);
                        ?>
                        <ul class="navbar-nav flex-row ml-md-auto d-md-flex">
                            <li class="nav-item">
                                <a style="margin-left:10px;" target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $share_url; ?>&t=<?php echo $titulo_xx; ?>">
                                    <i class="fab fa-facebook" style="font-size:30px;color:#111111;" aria-hidden="true"></i>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a style="margin-left:10px;" target="_blank" href="https://twitter.com/intent/tweet?text=<?php echo $share_title_encoded; ?>&url=<?php echo $share_url_encoded; ?>" aria-label="Compartir en X" title="Compartir en X">
                                    <span class="share-x-icon" aria-hidden="true">
                                        <svg viewBox="0 0 1200 1227" xmlns="http://www.w3.org/2000/svg" role="img" focusable="false">
                                            <path d="M714.163 519.284 1160.89 0H1055.27L667.137 450.887 357.328 0H0L468.492 681.821 0 1226.37H105.618L515.239 750.218 842.672 1226.37H1200L714.137 519.284h.026ZM568.703 688.783l-47.349-67.894L144.011 80.694h162.604l304.797 436.204 47.349 67.894 395.459 566.09H891.616L568.703 688.809v-.026Z"/>
                                        </svg>
                                    </span>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a style="margin-left:10px;" target="_blank" href="https://api.whatsapp.com/send?text=*<?php echo rawurlencode($titulo_xx); ?>.*%20%20<?php echo $share_url_encoded; ?>">
                                    <i class="fab fa-whatsapp" style="font-size:30px;color:#111111;" aria-hidden="true"></i>
                                </a>
                            </li>
                        </ul>
                    </div>

                    <div class="col-lg-12 col-12 my-3 px-0 py-3">
                        <div class="col-12 col-lg-12 my-3 p-0">
                            <h3 style="font-family:<?php echo $style_titulo; ?>;color:<?php echo $d_color_titulo; ?>;">Notas Relacionadas</h3>
                        </div>
                        <style>
                            .rel3-grid { margin:0 -10px; }
                            .rel3-grid > [class*="col-"] { padding:0 10px; }
                            .rel3-card {
                                background:#fff;
                                border:1px solid rgba(0,0,0,.08);
                                border-radius:14px;
                                overflow:hidden;
                                box-shadow:0 10px 22px rgba(0,0,0,.08);
                                height:100%;
                                transition:transform .18s ease, box-shadow .18s ease;
                            }
                            .rel3-card:hover {
                                transform:translateY(-2px);
                                box-shadow:0 14px 28px rgba(0,0,0,.12);
                            }
                            .rel3-media { position:relative; background:#eee; }
                            .rel3-img { display:block; width:100%; height:190px; object-fit:cover; background:#eee; }
                            .rel3-badge {
                                position:absolute;
                                top:10px;
                                left:10px;
                                z-index:2;
                                border-radius:999px;
                                padding:5px 9px;
                                font-size:10px;
                                font-weight:700;
                                letter-spacing:.06em;
                                text-transform:uppercase;
                                color:#fff;
                                box-shadow:0 10px 22px rgba(0,0,0,.15);
                            }
                            .rel3-body { padding:12px 12px 14px; }
                            .rel3-title {
                                margin:0;
                                font-size:16px;
                                line-height:1.22;
                                font-weight:800;
                                color:#111;
                                font-family:<?php echo $style_titulo; ?>;
                            }
                            .rel3-title a { color:inherit; text-decoration:none; }
                            .rel3-title a:hover { text-decoration:underline; }
                            .rel3-sub {
                                margin-top:8px;
                                font-size:12px;
                                line-height:1.2;
                                color:rgba(0,0,0,.55);
                                font-family:<?php echo $style_bajada; ?>;
                                display:block;
                            }
                        </style>

                        <div class="row rel3-grid" style="margin-top:6px;">
                            <?php
                            $dom_img = $dom;
                            if (isset($domold) && $domold != '') { $dom_img = $domold; }
                            $dom_img = str_replace('http://', 'https://', $dom_img);
                            $ID_NOTA_INT = (int)$ID_NOTA;
                            $CAT_INT = (int)$cat_no;

                            if ($CAT_INT > 0) {
                                $sql_rel = "
                                    SELECT n.ID, n.titulo, n.bajada, n.carpetafoto, n.foto, n.ext_img, n.cat,
                                           c.nombre AS cat_name, c.color AS cat_color
                                    FROM notas n
                                    LEFT JOIN categorias c ON c.ID = n.cat
                                    WHERE n.ver='si' AND n.ID <> $ID_NOTA_INT
                                    ORDER BY (n.cat = $CAT_INT) DESC, n.ID DESC
                                    LIMIT 3
                                ";
                            } else {
                                $sql_rel = "
                                    SELECT n.ID, n.titulo, n.bajada, n.carpetafoto, n.foto, n.ext_img, n.cat,
                                           c.nombre AS cat_name, c.color AS cat_color
                                    FROM notas n
                                    LEFT JOIN categorias c ON c.ID = n.cat
                                    WHERE n.ver='si' AND n.ID <> $ID_NOTA_INT
                                    ORDER BY n.ID DESC
                                    LIMIT 3
                                ";
                            }

                            $consulta_rel = $conn->query($sql_rel);
                            $printed = 0;
                            if ($consulta_rel) {
                                while ($rowr = $consulta_rel->fetch_assoc()) {
                                    $printed++;
                                    $ID2 = (int)$rowr['ID'];
                                    $titulo2 = $rowr['titulo'];
                                    $bajada2 = $rowr['bajada'];
                                    $carpetafoto2 = $rowr['carpetafoto'];
                                    $foto2 = $rowr['foto'];
                                    $ext_img2 = $rowr['ext_img'];
                                    $cat_name2 = $rowr['cat_name'];
                                    $cat_color2 = $rowr['cat_color'];
                                    $href = $dom . '/nota/' . $ID2 . '/' . urls_amigables($titulo2);
                                    $has_img = false;
                                    $img_src = '';
                                    if ($foto2 != '' && $foto2 != null) {
                                        $fotojj = strtolower(substr($foto2, 0, 4));
                                        if ($fotojj == 'http') {
                                            $img_src = str_replace('http://', 'https://', $foto2);
                                            $has_img = true;
                                        } else {
                                            $img_src = $dom_img . '/' . $carpetafoto2 . '/resize_' . $foto2 . $ext_img2;
                                            $has_img = true;
                                        }
                                    }
                                    if ($cat_color2 == '' || $cat_color2 == '#FFFFFF') { $cat_color2 = '#666666'; }
                                    ?>
                                    <div class="col-12 col-md-4 d-flex mb-3">
                                        <div class="rel3-card w-100">
                                            <div class="rel3-media">
                                                <?php if ($cat_name2 != '' && $cat_name2 != null) { ?>
                                                    <div class="rel3-badge" style="background:<?php echo $cat_color2; ?>;"><?php echo $cat_name2; ?></div>
                                                <?php } ?>
                                                <a href="<?php echo $href; ?>" style="display:block;">
                                                    <?php if ($has_img) { ?>
                                                        <img class="rel3-img" src="<?php echo $img_src; ?>" alt="<?php echo htmlspecialchars(utf8_decode($titulo2), ENT_QUOTES, 'UTF-8'); ?>">
                                                    <?php } else { ?>
                                                        <div class="rel3-img" style="display:flex;align-items:center;justify-content:center;background:#dcdcdc;color:#444;font-weight:800;letter-spacing:.08em;text-transform:uppercase;font-size:12px;">SIN IMAGEN</div>
                                                    <?php } ?>
                                                </a>
                                            </div>
                                            <div class="rel3-body">
                                                <h4 class="rel3-title"><a href="<?php echo $href; ?>"><?php echo utf8_decode($titulo2); ?></a></h4>
                                                <?php if ($bajada2 != '' && $bajada2 != null) { ?>
                                                    <span class="rel3-sub"><?php echo utf8_decode($bajada2); ?></span>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php }
                                $consulta_rel->free_result();
                            }
                            for ($k = $printed; $k < 3; $k++) {
                                ?>
                                <div class="col-12 col-md-4 d-flex mb-3">
                                    <div class="rel3-card w-100">
                                        <div class="rel3-media">
                                            <div style="height:190px;background:#dcdcdc;display:flex;align-items:center;justify-content:center;color:#444;font-weight:800;letter-spacing:.08em;text-transform:uppercase;font-size:12px;">SIN IMAGEN</div>
                                        </div>
                                        <div class="rel3-body">
                                            <div style="height:14px;background:#efefef;border-radius:6px;margin:8px 0;"></div>
                                            <div style="height:14px;background:#efefef;border-radius:6px;margin:8px 0;width:78%;"></div>
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                    </div>

                    <div class="col-12" id="comentarios">
                        <?php if ($opcion3 == 'si') { ?>
                            <div class="col-12"><h3>Comentarios</h3></div>
                            <div class="col-12">
                                <form id="formComentarioNota" name="formComentarioNota" method="post" action="<?php echo nm_h(nm_current_request_uri()); ?>#comentarios" onsubmit="return validarComentarioNota();">
                                    <input type="hidden" name="accion_comentario" value="guardar_comentario">
                                    <input type="hidden" name="IDD" value="<?php echo (int)$ID_NOTA; ?>">

                                    <style>
                                        .rn-form-wrap { max-width:860px; margin:18px auto 18px; }
                                        .rn-form-card {
                                            background:#fff;
                                            border:1px solid rgba(0,0,0,.08);
                                            border-radius:14px;
                                            box-shadow:0 10px 22px rgba(0,0,0,.06);
                                            overflow:hidden;
                                        }
                                        .rn-form-head {
                                            padding:12px 16px;
                                            border-bottom:1px solid rgba(0,0,0,.06);
                                            font-weight:800;
                                        }
                                        .rn-form-body { padding:16px; }
                                        .rn-form-body label {
                                            font-size:12px;
                                            font-weight:700;
                                            color:rgba(0,0,0,.65);
                                            margin-bottom:6px;
                                        }
                                        .rn-form-body .form-control {
                                            border-radius:10px;
                                            border-color:rgba(0,0,0,.14);
                                        }
                                        .rn-form-body .form-control:focus {
                                            border-color:rgba(0,123,255,.45);
                                            box-shadow:0 0 0 .2rem rgba(0,123,255,.12);
                                        }
                                        .rn-form-body textarea.form-control { resize:vertical; min-height:120px; }
                                        .rn-form-body .rn-btn {
                                            border-radius:999px;
                                            padding:.55rem 1.1rem;
                                            font-weight:700;
                                        }
                                        .rn-form-sub {
                                            font-size:12px;
                                            color:rgba(0,0,0,.55);
                                            margin-top:2px;
                                        }
                                    </style>

                                    <div class="rn-form-wrap">
                                        <div class="rn-form-card">
                                            <div class="rn-form-head">Escribir un comentario</div>
                                            <div class="rn-form-body">
                                                <div id="comentariosAjaxMsg"></div>

                                                <?php if ($comentario_error != '') { ?>
                                                    <div class="alert alert-danger" role="alert"><?php echo nm_h($comentario_error); ?></div>
                                                <?php } ?>
                                                <?php if ($comentario_ok != '') { ?>
                                                    <div class="alert alert-success" role="alert"><?php echo nm_h($comentario_ok); ?></div>
                                                <?php } ?>

                                                <div class="form-group mb-3">
                                                    <label for="nombre">Nombre</label>
                                                    <input name="nombre" type="text" class="form-control" id="nombre" value="<?php echo nm_h($comentario_post_nombre); ?>" placeholder="Tu nombre" autocomplete="off" required>
                                                </div>

                                                <div class="form-group mb-3">
                                                    <label for="texto">Comentario</label>
                                                    <textarea name="texto" rows="4" class="form-control" id="texto" placeholder="Escribí tu comentario..." required><?php echo nm_h($comentario_post_texto); ?></textarea>
                                                </div>

                                                <?php if ($comentarios == 'captcha') { ?>
                                                    <div class="nm-captcha-box">
                                                        <label for="captcha_texto" style="display:block;margin-bottom:8px;font-weight:bold;">Escribí este código:</label>
                                                        <div class="nm-captcha-code" id="nmCaptchaCode"><?php echo nm_h($captcha_actual); ?></div>
                                                        <input type="text" name="captcha_texto" id="captcha_texto" class="form-control" maxlength="10" autocomplete="off" placeholder="Copiá el código" required>
                                                        <div style="margin-top:8px;text-align:right;">
                                                            <button type="button" class="btn btn-sm btn-outline-secondary js-reload-captcha" data-note="<?php echo (int)$ID_NOTA; ?>">Recargar</button>
                                                        </div>
                                                    </div>
                                                <?php } ?>

                                                <div class="nm-comment-help">
                                                    <?php if ($comentarios == 'facebook') { ?>
                                                        Los comentarios se envían y quedan pendientes de moderación.
                                                    <?php } elseif ($comentarios == 'captcha') { ?>
                                                        Completá el captcha para publicar tu comentario sin salir de la nota.
                                                    <?php } else { ?>
                                                        Tu comentario se publica directamente al enviarlo.
                                                    <?php } ?>
                                                </div>

                                                <div class="d-flex justify-content-end" style="margin-top:14px;">
                                                    <button name="button" type="submit" id="buttonComentarioNota" value="Enviar" class="btn btn-primary rn-btn">Enviar</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <div class="col-12">
                                <style>
                                    .rn-comms-wrap { max-width:860px; margin:20px auto 10px; }
                                    .rn-comms-card {
                                        background:#fff;
                                        border:1px solid rgba(0,0,0,.08);
                                        border-radius:14px;
                                        box-shadow:0 10px 22px rgba(0,0,0,.06);
                                        overflow:hidden;
                                    }
                                    .rn-comms-card .rn-comms-head {
                                        padding:12px 16px;
                                        border-bottom:1px solid rgba(0,0,0,.06);
                                        font-weight:800;
                                    }
                                    .rn-comms-card .rn-comms-body { padding:16px; }
                                    .rn-comm-item { padding:16px 0; border-top:1px solid rgba(0,0,0,.06); }
                                    .rn-comm-item:first-child { border-top:0; padding-top:0; }
                                    .rn-comm-name { font-weight:800; color:rgba(0,0,0,.86); margin:0; }
                                    .rn-comm-meta { font-size:12px; color:rgba(0,0,0,.55); }
                                    .rn-comm-bubble {
                                        margin-top:10px;
                                        background:#f8f9fa;
                                        border:1px solid rgba(0,0,0,.08);
                                        border-radius:12px;
                                        padding:14px 16px;
                                        line-height:1.55;
                                        color:rgba(0,0,0,.88);
                                        word-break:break-word;
                                    }
                                    .rn-comms-wrap .btn-outline-primary { border-width:1px !important; border-radius:999px !important; }
                                    .rn-comms-wrap .btn-outline-primary:hover { border-width:1px !important; }
                                    .rn-sub {
                                        margin-top:12px;
                                        margin-left:26px;
                                        padding-left:14px;
                                        border-left:2px solid rgba(0,0,0,.10);
                                    }
                                    .rn-sub .rn-comm-bubble { background:#fff; }
                                    .rn-empty {
                                        border:1px dashed rgba(0,0,0,.18);
                                        border-radius:12px;
                                        padding:14px 16px;
                                        background:#fbfbfb;
                                        color:rgba(0,0,0,.65);
                                    }
                                </style>

                                <div class="rn-comms-wrap">
                                    <div class="rn-comms-card">
                                        <div class="rn-comms-head">Comentarios</div>
                                        <div class="rn-comms-body" id="commentsListContainer">
                                            <?php echo nm_render_comments_panel($conn, $ID_NOTA); ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
        <div id="sidebar" class="sidebar col-12 col-sm-4 col-md-4 p-0 col-lg-4 ">
            <div class="sidebar__inner">
                <?php include 'propagandas_div.php'; ?>
            </div>
        </div>
    </div>
</div>

<?php if ($estiloweb == 72) { include 'footer.magazine.php'; } ?>
<?php include 'clix_footer.php'; ?>

<script>
window.lazyLoadOptions = {
    elements_selector: ".lazy"
};
</script>
<script async src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@12.4.0/dist/lazyload.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
<script>
// new WOW().init();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://recursos.x7.com.ar/css/js/lightbox-plus-jquery.min.js"></script>
<script src="<?php echo $dom; ?>/js/jquery.fittext.js"></script>
<script src="https://recursos.x7.com.ar/isot/isotope-master/dist/isotope.pkgd.min.js"></script>
<script src="https://recursos.x7.com.ar/fli/flickity-master/dist/flickity.pkgd.min.js"></script>
<script type="text/javascript">
window.setInterval(function(){
    /*$('.grid').isotope({itemSelector: '.grid-item'});*/
});
</script>
<script type="text/javascript">
window.setInterval(function(){
    $('.grid2').isotope({ itemSelector: '.grid-item2' });
}, 2000);
</script>
<script>
function ventanaSecundaria56(URL){
    window.open(URL, "ventana1", "width=960,height=630,scrollbars=NO");
}

function validarComentarioNota() {
    var nombre = document.getElementById('nombre');
    var texto = document.getElementById('texto');
    var captcha = document.getElementById('captcha_texto');
    var boton = document.getElementById('buttonComentarioNota');

    if (!nombre || nombre.value.replace(/^\s+|\s+$/g, '') === '') {
        alert('Debes escribir tu nombre.');
        if (nombre) { nombre.focus(); }
        return false;
    }
    if (!texto || texto.value.replace(/^\s+|\s+$/g, '') === '') {
        alert('Debes escribir un comentario.');
        if (texto) { texto.focus(); }
        return false;
    }
    <?php if ($comentarios == 'captcha') { ?>
    if (!captcha || captcha.value.replace(/^\s+|\s+$/g, '') === '') {
        alert('Debes completar el captcha.');
        if (captcha) { captcha.focus(); }
        return false;
    }
    <?php } ?>
    if (boton) {
        boton.disabled = true;
        boton.innerHTML = 'Enviando...';
    }
    return true;
}
</script>

<script>
(function() {
    function escapeHtml(str) {
        return String(str)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#039;');
    }

    function showAlert(container, type, message) {
        if (!container) return;
        container.innerHTML = '<div class="alert alert-' + type + '" role="alert">' + escapeHtml(message) + '</div>';
    }

    function clearAlert(container) {
        if (!container) return;
        container.innerHTML = '';
    }

    function updateCaptcha(code) {
        var captchaBox = document.getElementById('nmCaptchaCode');
        var captchaInput = document.getElementById('captcha_texto');
        if (captchaBox && typeof code !== 'undefined') {
            captchaBox.textContent = code;
        }
        if (captchaInput) {
            captchaInput.value = '';
        }
    }

    function sendAjaxForm(form, callback) {
        var fd = new FormData(form);
        fd.append('ajax', '1');

        fetch(form.getAttribute('action') || window.location.href, {
            method: 'POST',
            body: fd,
            headers: {
                'X-Requested-With': 'XMLHttpRequest'
            },
            credentials: 'same-origin'
        })
        .then(function(r) {
            return r.json();
        })
        .then(function(data) {
            callback(null, data);
        })
        .catch(function(err) {
            callback(err || true, null);
        });
    }

    document.addEventListener('click', function(e) {
        var toggleBtn = e.target.closest('.js-toggle-reply');
        if (toggleBtn) {
            e.preventDefault();
            var targetId = toggleBtn.getAttribute('data-target');
            var target = document.getElementById(targetId);

            if (!target) return;

            var allBoxes = document.querySelectorAll('.rn-reply-box');
            for (var i = 0; i < allBoxes.length; i++) {
                if (allBoxes[i].id !== targetId) {
                    allBoxes[i].style.display = 'none';
                }
            }

            target.style.display = (target.style.display === 'none' || target.style.display === '') ? 'block' : 'none';

            if (target.style.display === 'block') {
                var input = target.querySelector('input[name="nombre_respuesta"]');
                if (input) input.focus();
            }
            return;
        }

        var reloadCaptchaBtn = e.target.closest('.js-reload-captcha');
        if (reloadCaptchaBtn) {
            e.preventDefault();

            var noteId = reloadCaptchaBtn.getAttribute('data-note') || '';
            var fd = new FormData();
            fd.append('accion_comentario', 'refrescar_captcha');
            fd.append('IDD', noteId);
            fd.append('ajax', '1');

            fetch('<?php echo nm_h(nm_current_request_uri()); ?>', {
                method: 'POST',
                body: fd,
                headers: {
                    'X-Requested-With': 'XMLHttpRequest'
                },
                credentials: 'same-origin'
            })
            .then(function(r) { return r.json(); })
            .then(function(data) {
                if (data && data.ok && data.captcha) {
                    updateCaptcha(data.captcha);
                }
            })
            .catch(function() {});
            return;
        }
    });

    document.addEventListener('submit', function(e) {
        var form = e.target;
        var commentsList = document.getElementById('commentsListContainer');
        var globalMsg = document.getElementById('comentariosAjaxMsg');

        if (form && form.id === 'formComentarioNota') {
            e.preventDefault();

            var nombre = document.getElementById('nombre');
            var texto = document.getElementById('texto');
            var captcha = document.getElementById('captcha_texto');
            var boton = document.getElementById('buttonComentarioNota');

            clearAlert(globalMsg);

            if (!nombre || nombre.value.replace(/^\s+|\s+$/g, '') === '') {
                showAlert(globalMsg, 'danger', 'Debes escribir tu nombre.');
                if (nombre) nombre.focus();
                if (boton) {
                    boton.disabled = false;
                    boton.innerHTML = 'Enviar';
                }
                return false;
            }
            if (!texto || texto.value.replace(/^\s+|\s+$/g, '') === '') {
                showAlert(globalMsg, 'danger', 'Debes escribir un comentario.');
                if (texto) texto.focus();
                if (boton) {
                    boton.disabled = false;
                    boton.innerHTML = 'Enviar';
                }
                return false;
            }
            <?php if ($comentarios == 'captcha') { ?>
            if (!captcha || captcha.value.replace(/^\s+|\s+$/g, '') === '') {
                showAlert(globalMsg, 'danger', 'Debes completar el captcha.');
                if (captcha) captcha.focus();
                if (boton) {
                    boton.disabled = false;
                    boton.innerHTML = 'Enviar';
                }
                return false;
            }
            <?php } ?>

            if (boton) {
                boton.disabled = true;
                boton.innerHTML = 'Enviando...';
            }

            sendAjaxForm(form, function(err, data) {
                if (boton) {
                    boton.disabled = false;
                    boton.innerHTML = 'Enviar';
                }

                if (err || !data) {
                    showAlert(globalMsg, 'danger', 'Ocurrió un error al enviar el comentario.');
                    return;
                }

                if (typeof data.captcha !== 'undefined') {
                    updateCaptcha(data.captcha);
                }

                if (data.ok) {
                    form.reset();
                    showAlert(globalMsg, 'success', data.message || 'Comentario enviado correctamente.');
                    if (commentsList && typeof data.list_html !== 'undefined') {
                        commentsList.innerHTML = data.list_html;
                    }
                } else {
                    showAlert(globalMsg, 'danger', data.message || 'No se pudo enviar el comentario.');
                }
            });

            return false;
        }

        if (form && form.classList.contains('js-reply-form')) {
            e.preventDefault();

            var localMsg = form.querySelector('.js-reply-status');
            var submitBtn = form.querySelector('.js-reply-submit');

            if (localMsg) clearAlert(localMsg);

            var inputNombre = form.querySelector('input[name="nombre_respuesta"]');
            var inputTexto = form.querySelector('textarea[name="texto_respuesta"]');

            if (!inputNombre || inputNombre.value.replace(/^\s+|\s+$/g, '') === '') {
                showAlert(localMsg, 'danger', 'Debes escribir tu nombre.');
                if (inputNombre) inputNombre.focus();
                return false;
            }
            if (!inputTexto || inputTexto.value.replace(/^\s+|\s+$/g, '') === '') {
                showAlert(localMsg, 'danger', 'Debes escribir una respuesta.');
                if (inputTexto) inputTexto.focus();
                return false;
            }

            if (submitBtn) {
                submitBtn.disabled = true;
                submitBtn.innerHTML = 'Enviando...';
            }

            sendAjaxForm(form, function(err, data) {
                if (submitBtn) {
                    submitBtn.disabled = false;
                    submitBtn.innerHTML = 'Enviar';
                }

                if (err || !data) {
                    showAlert(localMsg, 'danger', 'Ocurrió un error al enviar la respuesta.');
                    return;
                }

                if (data.ok) {
                    if (commentsList && typeof data.list_html !== 'undefined') {
                        commentsList.innerHTML = data.list_html;
                    }

                    if (globalMsg) {
                        showAlert(globalMsg, 'success', data.message || 'Respuesta enviada correctamente.');
                    }

                    if (typeof data.parent_id !== 'undefined') {
                        setTimeout(function() {
                            var parentItem = document.getElementById('commentItem_' + data.parent_id);
                            if (parentItem && typeof parentItem.scrollIntoView === 'function') {
                                parentItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
                            }
                        }, 120);
                    }
                } else {
                    showAlert(localMsg, 'danger', data.message || 'No se pudo enviar la respuesta.');
                }
            });

            return false;
        }
    });
})();
</script>

<script type="text/javascript">
var TIMEOUT = null;
$(window).on('resize', function () {
    if (TIMEOUT === null) {
        TIMEOUT = window.setTimeout(function () {
            TIMEOUT = null;
            $('.fb-page').removeClass('fb_iframe_widget fb_iframe_widget_fluid');
            if (typeof FB !== 'undefined' && FB.XFBML && typeof FB.XFBML.parse === 'function') {
                FB.XFBML.parse();
            }
        }, 300);
    }
});

$(function(){
    $(".carousel-captionh1").fitText(1.2, { minFontSize: '14px', maxFontSize: '18px' });
    $(".colorTitulo").fitText(1.2, { minFontSize: '14px', maxFontSize: '24px' });
    $(".carousel-caption h2").fitText(1.2, { minFontSize: '14px', maxFontSize: '30px' });
    $(".tituloVideo").fitText(1.2, { minFontSize: '14px', maxFontSize: '30px' });
    $(".tarso").fitText(1.2, { minFontSize: '20px', maxFontSize: '50px' });
    $(".tarso2").fitText(1.2, { minFontSize: '5px', maxFontSize: '11px' });

    $('img.svg').each(function(){
        var $img = $(this);
        var imgID = $img.attr('id');
        var imgClass = $img.attr('class');
        var imgURL = $img.attr('src');
        $.get(imgURL, function(data) {
            var $svg = $(data).find('svg');
            if (typeof imgID !== 'undefined') { $svg = $svg.attr('id', imgID); }
            if (typeof imgClass !== 'undefined') { $svg = $svg.attr('class', imgClass + ' replaced-svg'); }
            $svg = $svg.removeAttr('xmlns:a');
            $img.replaceWith($svg);
        }, 'xml');
    });
});
</script>
<?php include 'google.php'; ?>
</body>
</html>