From 7935d26cd16a4f8f69a59a44e27a7263b60e54bf Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 14 Sep 2026 19:05:30 +0000
Subject: [PATCH] =Simple Calendar block up and running
---
inc/blocks/EventBlock.php | 147 ++++--------------------------------------------
1 files changed, 14 insertions(+), 133 deletions(-)
diff --git a/inc/blocks/EventBlock.php b/inc/blocks/EventBlock.php
index acfd31e..9b531ba 100644
--- a/inc/blocks/EventBlock.php
+++ b/inc/blocks/EventBlock.php
@@ -3,6 +3,7 @@
use DateTime;
+use JVBase\helpers\Events;
use JVBase\meta\Meta;
use JVBase\utility\Image;
use WP_Block;
@@ -38,27 +39,8 @@
$values = $meta->getAll();
$out = '<section class="event-block">';
- $out .= '<div class="event tags row right">';
- $get = ['is_free' => 'Free', 'rsvp_required' => 'Must RSVP', 'public' => 'Private Event'];
- foreach ($get as $k => $g) {
- $check = !empty($values[$k]) && $values[$k] === '1';
- if ($k === 'public') {
- $check = !$check;
- }
- $icon = match ($k) {
- 'is_free' => jvbIcon('check-circle'),
- 'rsvp_required' => jvbIcon('envelope'),
- 'public' => jvbIcon('lock-key'),
- };
- if ($check) {
- $out .= sprintf(
- '<div class="tag">%s%s</div>',
- $icon,
- $g
- );
- }
- }
- $out .= '</div>';
+ $out .= Events::tags($values);
+
if (!empty($values['post_thumbnail'])) {
$out .= jvbFormatImage($values['post_thumbnail']);
}
@@ -70,7 +52,7 @@
$values['post_title']
);
}
- $out .= $this->calendarDay($values['date_start']??'');
+ $out .= Events::calendarDay($values['date_start']??'');
$out .= '</header>';
@@ -79,23 +61,24 @@
'<ul class="time term-list row left"><li class="title">%s</li>',
jvbIcon('clock')
);
- $out .= $this->formatDay($values['date_start']??'', $values['time_start']??'', $values['time_end']??'');
+ $out .= sprintf(
+ '<li>%s</li>',
+ Events::formatDay($values['date_start']??'', $values['time_start']??'', $values['time_end']??'')
+ );
foreach ($values['schedule']??[] as $date) {
- $out .= $this->formatDay($date['date'], $date['time_start'], $date['time_end'], $date['notes']);
+ $out .= sprintf(
+ '<li>%s</li>',
+ Events::formatDay($date['date'], $date['time_start'], $date['time_end'], $date['notes'])
+ );
}
$out .= '</ul>';
- $out .= $this->location($values['location']??[], $values['location_notes']??'');
+ $out .= Events::location($values);
$out .= $this->price($values['cost']??'', $values['ticket_url']??'');
$out .= $this->participants($values['max_participants']??'');
- $get = ['city', 'event_category'];
- foreach ($get as $g) {
- if (!empty($values[$g])) {
- $out .= jvbMetaTermList($values[$g], $g);
- }
- }
+ $out .= Events::terms($values);
$out .= $this->rsvp($values['rsvp_required']??'', $values['rsvp_limit']??'', $values['rsvp_deadline']);
@@ -111,108 +94,6 @@
jvbRenderGallery();
}
- protected function calendarDay(string $day):string
- {
- $out = '';
- if (!empty($day)) {
- $date = new DateTime($day, wp_timezone());
- $weekday = $date->format('D');
- $num = $date->format('d');
- $month = $date->format('M');
-
- $out .= sprintf(
- '<div class="col calendar">
- <span class="weekday">%s</span>
- <span class="month">%s</span>
- <span class="day">%d</span>
- </div>',
- $weekday,
- $month,
- $num
- );
- }
- return $out;
- }
- protected function renderLocationString(array $location):string
- {
- if (!array_key_exists('address', $location) ||
- !array_key_exists('street', $location) ||
- !array_key_exists('city', $location) ||
- !array_key_exists('province', $location) ||
- !array_key_exists('country', $location)) {
- return '';
- }
-
- return sprintf(
- '<p class="location">%s%s<br>%s, %s %s</p>',
- $location['address'],
- $location['street'],
- $location['city'],
- $location['province'],
- $location['country'] === 'CA' ? '' : $location['country']
- );
- }
-
- protected function formatDay(string $date, string $start, string $end, string $notes = ''):string
- {
- $out = '<li>';
- if (!empty($date)) {
- $out .= sprintf(
- '<time datetime="%s">%s</time><br>',
- date('c', strtotime($date)),
- date('F j, Y', strtotime($date))
- );
- }
- $doit = false;
-
- if (!empty($start)) {
- $doit = true;
- $d = strtotime($date.' '.$start);
- $out .= sprintf(
- '<time datetime="%s">%s</time>',
- date('c', $d),
- date('g:ia', $d)
- );
- }
- if (!empty($end)) {
- if ($doit) {
- $out .= ' - ';
- }
- $d = strtotime($date.' '.$end);
- $out .= sprintf(
- '<time datetime="%s">%s</time>',
- date('c', $d),
- date('g:ia', $d)
- );
-
- }
- if (!empty($notes)) {
- $out .= wpautop($notes);
- }
-
- $out .= '</li>';
- return $out;
- }
-
- protected function location(array $location, string $notes = ''):string
- {
- $out = '';
- if (!empty($location['address']??'')) {
- $out .= sprintf(
- '<ul class="location term-list row left">
- <li class="title">%sLocation</li>
- <li>%s</li>
- <li>%s</li>
- %s
- </ul>',
- jvbIcon('map-pin'),
- $this->renderLocationString($location),
- jvbLocationLinks($location),
- empty($notes) ? '' : '<li>'.$notes.'</li>',
- );
- }
- return $out;
- }
protected function price(string $price, string $url):string
{
--
Gitblit v1.10.0