added cron and waiting
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugin Name: YogaSoul Eventi
|
||||
* Description: Mostra gli eventi di YogiBook con card di prenotazione (lista d'attesa inclusa). Shortcode: [yogasoul_eventi], [yogasoul_eventi ids="12,15"], [yogasoul_eventi id="12"], [yogasoul_eventi limit="3"].
|
||||
@@ -19,15 +18,10 @@ if (!defined('YSE_API_BASE')) {
|
||||
define('YSE_API_BASE', 'https://yogibook.yogasoul.it/apiwp');
|
||||
}
|
||||
|
||||
/* Registra gli asset (accodati solo quando lo shortcode è in pagina) */
|
||||
/* Registra gli asset (accodati solo quando lo shortcode è in pagina).
|
||||
Nessun Google Font: il widget eredita il carattere del tema. */
|
||||
add_action('wp_enqueue_scripts', function () {
|
||||
wp_register_style(
|
||||
'yse-fonts',
|
||||
'https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600&display=swap',
|
||||
[],
|
||||
null
|
||||
);
|
||||
wp_register_style('yse-eventi', plugins_url('assets/yogasoul-eventi.css', __FILE__), ['yse-fonts'], '1.0.0');
|
||||
wp_register_style('yse-eventi', plugins_url('assets/yogasoul-eventi.css', __FILE__), [], '1.0.1');
|
||||
wp_register_script('yse-eventi', plugins_url('assets/yogasoul-eventi.js', __FILE__), [], '1.0.0', true);
|
||||
});
|
||||
|
||||
@@ -60,8 +54,11 @@ function yse_render_shortcode($atts)
|
||||
}
|
||||
$url = YSE_API_BASE . '/events.php' . (!empty($query) ? '?' . http_build_query($query) : '');
|
||||
|
||||
// Lettura server-side (niente CORS)
|
||||
$resp = wp_remote_get($url, ['timeout' => 8]);
|
||||
// Lettura server-side (niente CORS) + anti-cache
|
||||
$resp = wp_remote_get($url . (strpos($url, '?') !== false ? '&' : '?') . '_=' . time(), [
|
||||
'timeout' => 8,
|
||||
'headers' => ['Cache-Control' => 'no-cache'],
|
||||
]);
|
||||
if (is_wp_error($resp) || (int) wp_remote_retrieve_response_code($resp) !== 200) {
|
||||
return '<div class="yse-widget"><p class="yse-empty">Eventi non disponibili al momento.</p></div>';
|
||||
}
|
||||
@@ -136,13 +133,13 @@ function yse_render_card($ev)
|
||||
|| !empty($ev['cover_image']) || !empty($gallery) || $mapQuery !== '';
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
?>
|
||||
<div class="yse-card" style="--yse-accent: <?php echo esc_attr($color); ?>;"
|
||||
data-eid="<?php echo $id; ?>"
|
||||
data-cost="<?php echo esc_attr($cost); ?>"
|
||||
data-sym="<?php echo esc_attr($sym); ?>"
|
||||
data-maxqty="<?php echo (int) $maxQty; ?>"
|
||||
data-waitmode="<?php echo $waitMode ? 1 : 0; ?>">
|
||||
data-eid="<?php echo $id; ?>"
|
||||
data-cost="<?php echo esc_attr($cost); ?>"
|
||||
data-sym="<?php echo esc_attr($sym); ?>"
|
||||
data-maxqty="<?php echo (int) $maxQty; ?>"
|
||||
data-waitmode="<?php echo $waitMode ? 1 : 0; ?>">
|
||||
|
||||
<!-- HEADER COMPATTO -->
|
||||
<div class="yse-chead">
|
||||
@@ -150,6 +147,9 @@ function yse_render_card($ev)
|
||||
<div class="yse-m"><?php echo esc_html($monAbbr); ?></div>
|
||||
<div class="yse-d"><?php echo $dayNum; ?></div>
|
||||
</div>
|
||||
<?php if (!empty($ev['cover_image'])) : ?>
|
||||
<img class="yse-thumb" src="<?php echo esc_url($ev['cover_image']); ?>" alt="<?php echo esc_attr($ev['title']); ?>">
|
||||
<?php endif; ?>
|
||||
<div class="yse-main">
|
||||
<div class="yse-title-row">
|
||||
<h3><?php echo esc_html($ev['title']); ?></h3>
|
||||
@@ -188,22 +188,13 @@ function yse_render_card($ev)
|
||||
<?php if (trim((string) ($ev['suitable_for'] ?? '')) !== '' || trim((string) ($ev['what_to_bring'] ?? '')) !== '' || trim((string) ($ev['instructions'] ?? '')) !== '') : ?>
|
||||
<div class="yse-detail-grid">
|
||||
<?php if (trim((string) ($ev['suitable_for'] ?? '')) !== '') : ?>
|
||||
<div class="yse-detail">
|
||||
<div class="yse-dh"><?php echo yse_icon('heart'); ?> Per chi è adatto</div>
|
||||
<div class="yse-dt"><?php echo nl2br(esc_html($ev['suitable_for'])); ?></div>
|
||||
</div>
|
||||
<div class="yse-detail"><div class="yse-dh"><?php echo yse_icon('heart'); ?> Per chi è adatto</div><div class="yse-dt"><?php echo nl2br(esc_html($ev['suitable_for'])); ?></div></div>
|
||||
<?php endif; ?>
|
||||
<?php if (trim((string) ($ev['what_to_bring'] ?? '')) !== '') : ?>
|
||||
<div class="yse-detail">
|
||||
<div class="yse-dh"><?php echo yse_icon('bag'); ?> Cosa portare</div>
|
||||
<div class="yse-dt"><?php echo nl2br(esc_html($ev['what_to_bring'])); ?></div>
|
||||
</div>
|
||||
<div class="yse-detail"><div class="yse-dh"><?php echo yse_icon('bag'); ?> Cosa portare</div><div class="yse-dt"><?php echo nl2br(esc_html($ev['what_to_bring'])); ?></div></div>
|
||||
<?php endif; ?>
|
||||
<?php if (trim((string) ($ev['instructions'] ?? '')) !== '') : ?>
|
||||
<div class="yse-detail">
|
||||
<div class="yse-dh"><?php echo yse_icon('info'); ?> Istruzioni</div>
|
||||
<div class="yse-dt"><?php echo nl2br(esc_html($ev['instructions'])); ?></div>
|
||||
</div>
|
||||
<div class="yse-detail"><div class="yse-dh"><?php echo yse_icon('info'); ?> Istruzioni</div><div class="yse-dt"><?php echo nl2br(esc_html($ev['instructions'])); ?></div></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -231,11 +222,21 @@ function yse_render_card($ev)
|
||||
|
||||
<!-- BOOKING -->
|
||||
<div class="yse-booking">
|
||||
<?php if ($hardFull) : ?>
|
||||
<?php if (!empty($ev['scheduled'])) :
|
||||
$pt = !empty($ev['publish_at']) ? strtotime($ev['publish_at']) : 0;
|
||||
$ptLabel = $pt ? ((int) date('j', $pt) . ' ' . $mesi[(int) date('n', $pt)] . ' ' . date('Y', $pt) . ' alle ' . date('H:i', $pt)) : '';
|
||||
?>
|
||||
<div class="yse-scheduled">Prenotazioni aperte dal <strong><?php echo esc_html($ptLabel); ?></strong></div>
|
||||
<?php elseif ($hardFull) : ?>
|
||||
<div class="yse-soldout">Evento esaurito — non ci sono più posti disponibili.</div>
|
||||
<?php else : ?>
|
||||
<?php if ($waitMode) : ?>
|
||||
<div class="yse-wl-banner">Posti esauriti — puoi iscriverti alla <strong>lista d'attesa</strong>: ti avviseremo se si libera un posto.</div>
|
||||
<?php if ($waitMode) :
|
||||
$waitingCount = (int) ($ev['waiting'] ?? 0);
|
||||
$waitingTxt = $waitingCount > 0
|
||||
? ' Al momento ' . ($waitingCount === 1 ? "c'è 1 persona" : "ci sono {$waitingCount} persone") . ' in coda.'
|
||||
: '';
|
||||
?>
|
||||
<div class="yse-wl-banner">Posti esauriti — puoi iscriverti alla <strong>lista d'attesa</strong>: ti avviseremo se si libera un posto.<?php echo esc_html($waitingTxt); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="yse-bcompact">
|
||||
<div class="yse-btitle"><?php echo $waitMode ? "Lista d'attesa" : 'Prenota questo evento'; ?></div>
|
||||
@@ -270,6 +271,6 @@ function yse_render_card($ev)
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user