COMPLETADO: Fase 1 de la migración a Clean Architecture + POO ## Estructura de Carpetas - ✓ Estructura completa de 4 capas (Domain, Application, Infrastructure, Presentation) - ✓ Carpetas de Use Cases (SaveComponent, GetComponent, DeleteComponent, SyncSchema) - ✓ Estructura de tests (Unit, Integration, E2E) - ✓ Carpetas de schemas y templates ## Composer y Autoloading - ✓ PSR-4 autoloading configurado para ROITheme namespace - ✓ Autoloader optimizado regenerado ## DI Container - ✓ DIContainer implementado con patrón Singleton - ✓ Métodos set(), get(), has() para gestión de servicios - ✓ Getters específicos para ComponentRepository, ValidationService, CacheService - ✓ Placeholders que serán implementados en Fase 5 - ✓ Prevención de clonación y deserialización ## Interfaces - ✓ ComponentRepositoryInterface (Domain) - ✓ ValidationServiceInterface (Application) - ✓ CacheServiceInterface (Application) - ✓ Component entity placeholder (Domain) ## Bootstrap - ✓ functions.php actualizado con carga de Composer autoloader - ✓ Inicialización del DIContainer - ✓ Helper function roi_container() disponible globalmente ## Tests - ✓ 10 tests unitarios para DIContainer (100% cobertura) - ✓ Total: 13 tests unitarios, 28 assertions - ✓ Suite de tests pasando correctamente ## Validación - ✓ Script de validación automatizado (48/48 checks pasados) - ✓ 100% de validaciones exitosas La arquitectura base está lista para la Fase 2. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
151 lines
4.1 KiB
PHP
151 lines
4.1 KiB
PHP
<?php
|
|
/**
|
|
* Funciones de sanitización para el tema ROI
|
|
*
|
|
* Este archivo centraliza todas las funciones de sanitización utilizadas
|
|
* en el Customizer, panel de opciones y demás componentes del tema.
|
|
*
|
|
* @package ROI_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_checkbox')) {
|
|
/**
|
|
* Sanitiza valores de checkbox
|
|
*
|
|
* Convierte cualquier valor a boolean para asegurar que solo
|
|
* se guarden valores true/false en la base de datos.
|
|
*
|
|
* @param mixed $input Valor a sanitizar
|
|
* @return bool Valor sanitizado como boolean
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_checkbox($input) {
|
|
return (bool) $input;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_select')) {
|
|
/**
|
|
* Sanitiza valores de select
|
|
*
|
|
* Verifica que el valor seleccionado existe en las opciones disponibles.
|
|
* Si no existe, retorna el valor por defecto del setting.
|
|
*
|
|
* @param mixed $input Valor a sanitizar
|
|
* @param object $setting Setting object del Customizer
|
|
* @return string Valor sanitizado
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_select($input, $setting) {
|
|
// Asegurar que el setting tiene las opciones disponibles
|
|
$choices = $setting->manager->get_control($setting->id)->choices;
|
|
|
|
// Retornar el input si es una opción válida, de lo contrario retornar el default
|
|
return (array_key_exists($input, $choices) ? $input : $setting->default);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_css')) {
|
|
/**
|
|
* Sanitiza CSS
|
|
*
|
|
* Remueve scripts y código PHP potencialmente peligroso del CSS personalizado.
|
|
*
|
|
* @param string $css El string CSS a sanitizar
|
|
* @return string CSS sanitizado
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_css($css) {
|
|
// Remove <script> tags
|
|
$css = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $css);
|
|
// Remove potential PHP code
|
|
$css = preg_replace('#<\?php(.*?)\?>#is', '', $css);
|
|
return wp_strip_all_tags($css);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_js')) {
|
|
/**
|
|
* Sanitiza JavaScript
|
|
*
|
|
* Remueve etiquetas script externas y código PHP del JavaScript personalizado.
|
|
*
|
|
* @param string $js El string JavaScript a sanitizar
|
|
* @return string JavaScript sanitizado
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_js($js) {
|
|
// Remove <script> tags if present
|
|
$js = preg_replace('#<script(.*?)>(.*?)</script>#is', '$2', $js);
|
|
// Remove potential PHP code
|
|
$js = preg_replace('#<\?php(.*?)\?>#is', '', $js);
|
|
return trim($js);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_integer')) {
|
|
/**
|
|
* Sanitiza valores enteros
|
|
*
|
|
* Convierte el valor a un entero absoluto (no negativo).
|
|
*
|
|
* @param mixed $input Valor a sanitizar
|
|
* @return int Valor sanitizado como entero
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_integer($input) {
|
|
return absint($input);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_text')) {
|
|
/**
|
|
* Sanitiza campos de texto
|
|
*
|
|
* Remueve etiquetas HTML y caracteres especiales del texto.
|
|
*
|
|
* @param string $input Valor a sanitizar
|
|
* @return string Texto sanitizado
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_text($input) {
|
|
return sanitize_text_field($input);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_url')) {
|
|
/**
|
|
* Sanitiza URLs
|
|
*
|
|
* Valida y sanitiza URLs para asegurar que son válidas.
|
|
*
|
|
* @param string $input URL a sanitizar
|
|
* @return string URL sanitizada
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_url($input) {
|
|
return esc_url_raw($input);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('roi_sanitize_html')) {
|
|
/**
|
|
* Sanitiza contenido HTML
|
|
*
|
|
* Permite etiquetas HTML seguras, removiendo scripts y código peligroso.
|
|
*
|
|
* @param string $input Contenido HTML a sanitizar
|
|
* @return string HTML sanitizado
|
|
* @since 1.0.0
|
|
*/
|
|
function roi_sanitize_html($input) {
|
|
return wp_kses_post($input);
|
|
}
|
|
}
|