Improve date handling for the calendar widget
This commit is contained in:
@@ -91,6 +91,16 @@ class syntax_plugin_luxtools_calendar extends SyntaxPlugin
|
||||
$size = ChronologicalCalendarWidget::normalizeSize((string)($data['size'] ?? 'large'));
|
||||
$showTimes = (bool)($data['show_times'] ?? true);
|
||||
|
||||
if ($size === 'small') {
|
||||
$resolved = $this->resolveMonthFromCookie(
|
||||
'luxtools_calendar_month_' . preg_replace('/[^a-zA-Z0-9]/', '_', $baseNs)
|
||||
) ?? $this->resolveMonthFromCookie('luxtools_client_month');
|
||||
if ($resolved !== null) {
|
||||
$year = $resolved['year'];
|
||||
$month = $resolved['month'];
|
||||
}
|
||||
}
|
||||
|
||||
$slots = CalendarSlot::loadEnabled($this);
|
||||
$widgetSlots = CalendarSlot::filterWidgetVisible($slots);
|
||||
$indicators = [];
|
||||
@@ -122,6 +132,25 @@ class syntax_plugin_luxtools_calendar extends SyntaxPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $cookieName
|
||||
* @return array{year:int,month:int}|null
|
||||
*/
|
||||
protected function resolveMonthFromCookie(string $cookieName): ?array
|
||||
{
|
||||
$raw = $_COOKIE[$cookieName] ?? null;
|
||||
if ($raw === null) return null;
|
||||
|
||||
$decoded = json_decode($raw, true);
|
||||
if (!is_array($decoded)) return null;
|
||||
|
||||
$year = (int)($decoded['year'] ?? 0);
|
||||
$month = (int)($decoded['month'] ?? 0);
|
||||
if ($year < 1 || $month < 1 || $month > 12) return null;
|
||||
|
||||
return ['year' => $year, 'month' => $month];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $flags
|
||||
* @return array<string,string>
|
||||
|
||||
Reference in New Issue
Block a user