/html/mod_articles_category/tarjetas.php */ defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Uri\Uri; if (empty($list)) { return; } /* ---------- Configuración ---------- */ $fceCarpetaNoticias = 'images/noticias'; // carpeta donde están las fotos de cada noticia (images/noticias/56/...) $fceLimiteParrafo = 300; // máximo de caracteres del primer párrafo $fceTextoBoton = 'Ver más'; $fceUrlVerTodas = Uri::root(true) . '/noticias'; /* ----------------------------------- */ if (!function_exists('fceUrlPublica')) { /** Convierte una ruta relativa (images/...) en URL del sitio y codifica espacios. */ function fceUrlPublica($ruta) { $ruta = trim($ruta); if ($ruta === '') { return ''; } if (!preg_match('#^(https?:)?//#i', $ruta) && strpos($ruta, '/') !== 0) { $ruta = Uri::root(true) . '/' . $ruta; } return str_replace(' ', '%20', $ruta); } } if (!function_exists('fceTarjetaImagen')) { /** Devuelve la URL de la primera imagen de la noticia. */ function fceTarjetaImagen($item, $carpetaBase) { // 1. Imagen de introducción o imagen completa del artículo $imagenes = json_decode($item->images ?? '{}'); foreach (['image_intro', 'image_fulltext'] as $campo) { if (!empty($imagenes->$campo)) { $limpia = HTMLHelper::_('cleanImageURL', $imagenes->$campo); return fceUrlPublica($limpia->url); } } // 2. Primera imagen dentro del texto (ignorando íconos del sitio) $html = ($item->introtext ?? '') . ' ' . ($item->fulltext ?? ''); if (preg_match_all('/]+src=["\']([^"\']+)["\']/i', $html, $m)) { foreach ($m[1] as $src) { if (preg_match('#/(footer|NuevoHome|iconos?)/#i', $src)) { continue; } return fceUrlPublica(html_entity_decode($src)); } } // 3. Primera imagen de la carpeta images/noticias/
/ $numero = preg_match('/noticia-(\d+)/', $item->alias ?? '', $a) ? $a[1] : (int) $item->id; $dir = JPATH_ROOT . '/' . trim($carpetaBase, '/') . '/' . $numero; if (is_dir($dir)) { $archivos = []; foreach (scandir($dir) as $archivo) { if (preg_match('/\.(jpe?g|png|webp|gif)$/i', $archivo)) { $archivos[] = $archivo; } } if ($archivos) { natcasesort($archivos); $primero = reset($archivos); return Uri::root(true) . '/' . trim($carpetaBase, '/') . '/' . $numero . '/' . rawurlencode($primero); } } return ''; } } if (!function_exists('fceTarjetaParrafo')) { /** Devuelve el primer párrafo real de la noticia (sin títulos en negrita ni shortcodes). */ function fceTarjetaParrafo($item, $limite) { $html = ($item->introtext ?? '') . ' ' . ($item->fulltext ?? ''); $html = preg_replace('/\{[^{}]+\}/', '', $html); // quita {smartslider3 ..}, {loadmodule ..}, etc. $html = preg_replace('#<(script|style)\b.*?#is', '', $html); if (!preg_match_all('#]*>(.*?)
#is', $html, $m)) { return ''; } $titulo = mb_strtolower(trim($item->title)); foreach ($m[1] as $p) { $texto = trim(preg_replace('/\s+/u', ' ', html_entity_decode(strip_tags($p), ENT_QUOTES, 'UTF-8'))); $largo = mb_strlen($texto); if ($largo < 60 || mb_strtolower($texto) === $titulo) { continue; } // Si casi todo el párrafo está en negrita, es un título: se omite $negrita = ''; if (preg_match_all('#<(strong|b)\b[^>]*>(.*?)#is', $p, $n)) { $negrita = trim(preg_replace('/\s+/u', ' ', html_entity_decode(strip_tags(implode(' ', $n[2])), ENT_QUOTES, 'UTF-8'))); } if (mb_strlen($negrita) >= $largo * 0.8) { continue; } if ($largo > $limite) { $corte = mb_substr($texto, 0, $limite); $espacio = mb_strrpos($corte, ' '); $texto = rtrim(mb_substr($corte, 0, $espacio ?: $limite), " ,.;:") . '…'; } return $texto; } return ''; } } ?>
title, ENT_QUOTES, 'UTF-8'); ?>