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>
128 lines
4.0 KiB
PHP
128 lines
4.0 KiB
PHP
<?php
|
|
/**
|
|
* Social Share Buttons
|
|
*
|
|
* Funciones para mostrar botones de compartir en redes sociales
|
|
* en posts individuales. Utiliza URLs nativas sin dependencias de JavaScript.
|
|
*
|
|
* @package ROI_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Obtiene el HTML de los botones de compartir en redes sociales
|
|
*
|
|
* @param int $post_id ID del post (opcional, usa el post actual si no se proporciona)
|
|
* @return string HTML de los botones de compartir
|
|
*/
|
|
function roi_get_social_share_buttons( $post_id = 0 ) {
|
|
// Si no se proporciona post_id, usar el post actual
|
|
if ( ! $post_id ) {
|
|
$post_id = get_the_ID();
|
|
}
|
|
|
|
// Verificar que es un post válido
|
|
if ( ! $post_id ) {
|
|
return '';
|
|
}
|
|
|
|
// Obtener información del post
|
|
$post_title = get_the_title( $post_id );
|
|
$post_url = get_permalink( $post_id );
|
|
$post_url_encoded = urlencode( $post_url );
|
|
$post_title_encoded = urlencode( $post_title );
|
|
|
|
// URLs de compartir para cada red social
|
|
$facebook_url = 'https://www.facebook.com/sharer/sharer.php?u=' . $post_url_encoded;
|
|
$twitter_url = 'https://twitter.com/intent/tweet?url=' . $post_url_encoded . '&text=' . $post_title_encoded;
|
|
$linkedin_url = 'https://www.linkedin.com/shareArticle?mini=true&url=' . $post_url_encoded . '&title=' . $post_title_encoded;
|
|
$whatsapp_url = 'https://api.whatsapp.com/send?text=' . $post_title_encoded . '%20' . $post_url_encoded;
|
|
$email_url = 'mailto:?subject=' . $post_title_encoded . '&body=' . $post_url_encoded;
|
|
|
|
// Obtener texto de compartir desde las opciones del tema
|
|
$share_text = roi_get_option( 'roi_share_text', __( 'Compartir:', 'roi-theme' ) );
|
|
|
|
// Construir el HTML
|
|
ob_start();
|
|
?>
|
|
<!-- Share Buttons Section -->
|
|
<div class="social-share-section my-5 py-4 border-top">
|
|
<p class="mb-3 text-muted"><?php echo esc_html( $share_text ); ?></p>
|
|
<div class="d-flex gap-2 flex-wrap share-buttons">
|
|
<!-- Facebook -->
|
|
<a href="<?php echo esc_url( $facebook_url ); ?>"
|
|
class="btn btn-outline-primary btn-sm"
|
|
aria-label="<?php esc_attr_e( 'Compartir en Facebook', 'roi-theme' ); ?>"
|
|
target="_blank"
|
|
rel="noopener noreferrer">
|
|
<i class="bi bi-facebook"></i>
|
|
</a>
|
|
|
|
<!-- X (Twitter) -->
|
|
<a href="<?php echo esc_url( $twitter_url ); ?>"
|
|
class="btn btn-outline-dark btn-sm"
|
|
aria-label="<?php esc_attr_e( 'Compartir en X', 'roi-theme' ); ?>"
|
|
target="_blank"
|
|
rel="noopener noreferrer">
|
|
<i class="bi bi-twitter-x"></i>
|
|
</a>
|
|
|
|
<!-- LinkedIn -->
|
|
<a href="<?php echo esc_url( $linkedin_url ); ?>"
|
|
class="btn btn-outline-info btn-sm"
|
|
aria-label="<?php esc_attr_e( 'Compartir en LinkedIn', 'roi-theme' ); ?>"
|
|
target="_blank"
|
|
rel="noopener noreferrer">
|
|
<i class="bi bi-linkedin"></i>
|
|
</a>
|
|
|
|
<!-- WhatsApp -->
|
|
<a href="<?php echo esc_url( $whatsapp_url ); ?>"
|
|
class="btn btn-outline-success btn-sm"
|
|
aria-label="<?php esc_attr_e( 'Compartir en WhatsApp', 'roi-theme' ); ?>"
|
|
target="_blank"
|
|
rel="noopener noreferrer">
|
|
<i class="bi bi-whatsapp"></i>
|
|
</a>
|
|
|
|
<!-- Email -->
|
|
<a href="<?php echo esc_url( $email_url ); ?>"
|
|
class="btn btn-outline-secondary btn-sm"
|
|
aria-label="<?php esc_attr_e( 'Compartir por Email', 'roi-theme' ); ?>">
|
|
<i class="bi bi-envelope"></i>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Template tag para mostrar los botones de compartir
|
|
*
|
|
* Muestra los botones de compartir en redes sociales solo en posts individuales
|
|
* si la opción está habilitada en el panel de opciones del tema.
|
|
*
|
|
* @param int $post_id ID del post (opcional)
|
|
*/
|
|
function roi_display_social_share( $post_id = 0 ) {
|
|
// Solo mostrar en posts individuales
|
|
if ( ! is_single() ) {
|
|
return;
|
|
}
|
|
|
|
// Verificar si los botones de compartir están habilitados
|
|
$enable_share = roi_get_option( 'roi_enable_share_buttons', '1' );
|
|
if ( $enable_share !== '1' ) {
|
|
return;
|
|
}
|
|
|
|
// Mostrar los botones
|
|
echo roi_get_social_share_buttons( $post_id );
|
|
}
|