Extract front page content into a separate file, extract event times into a config file

This commit is contained in:
Vencislav Atanasov 2024-10-30 21:37:11 +02:00
parent b0ea463d53
commit 2322eb3e66
3 changed files with 87 additions and 56 deletions

16
config-events.php Normal file
View File

@ -0,0 +1,16 @@
<?php
$eventsConfig = [
'2024' => [
'startTime' => '2024-11-02 09:45:00',
'endTime' => '2024-11-03 18:15:00',
'streams' => [[
'startTime' => '2024-11-02 09:45:00',
'endTime' => '2024-11-02 19:00:00',
'tracks' => ['hall-a', 'hall-b'],
], [
'startTime' => '2024-11-03 09:45:00',
'endTime' => '2024-11-03 18:15:00',
'tracks' => ['hall-a', 'hall-b'],
]],
],
];

70
front-page-content.php Normal file
View File

@ -0,0 +1,70 @@
<?php
if (!function_exists('get_blog_slug')) {
exit;
}
require __DIR__ . '/config-events.php';
$blog_slug = get_blog_slug();
if (!array_key_exists($blog_slug, $eventsConfig)) {
return;
}
$now = new DateTimeImmutable('now');
$eventStart = new DateTimeImmutable($eventsConfig[$blog_slug]['eventStart'] . ' Europe/Sofia');
$eventStartInterval = $now->diff($eventStart);
$isBeforeEvent = $eventStartInterval instanceof DateInterval && $eventStartInterval->invert === 0;
$eventEnd = new DateTimeImmutable($eventsConfig[$blog_slug]['eventEnd'] . ' Europe/Sofia');
$eventEndInterval = $now->diff($eventEnd);
$isAfterEvent = $eventEndInterval instanceof DateInterval && $eventEndInterval->invert === 1;
if ($isBeforeEvent) {
?>
<style>
.countdown {
text-align: center;
}
.countdown > table {
margin: 0 auto;
}
.countdown .digits > td {
font-size: 30px;
padding: 0 10px;
}
.countdown .units > td {
font-size: 12px;
}
</style>
<br><br>
<div class="countdown">
<?php e_('countdown_text_before'); ?>
<table>
<tbody>
<tr class="digits">
<td><?php echo $eventStartInterval->format('%a'); ?></td>
<td><?php echo $eventStartInterval->format('%H'); ?></td>
<td><?php echo $eventStartInterval->format('%I'); ?></td>
</tr>
<tr class="units">
<td><?php e_('countdown_days'); ?></td>
<td><?php e_('countdown_hours'); ?></td>
<td><?php e_('countdown_minutes'); ?></td>
</tr>
</tbody>
</table>
<?php e_('countdown_text_after'); ?>
</div>
<?php
}
if ($isAfterEvent) {
?>
<?php e_('after_event'); ?>
<?php
}

View File

@ -3,62 +3,7 @@
<section class="content subtitle_content"> <section class="content subtitle_content">
<?php <?php
e_('about_event'); e_('about_event');
require __DIR__ . '/front-page-content.php';
// countdown begin
$eventStartTimes = [
'2024' => '2024-11-02 10:00:00',
];
$blog_slug = get_blog_slug();
if (array_key_exists($blog_slug, $eventStartTimes)) {
$now = new DateTimeImmutable('now');
$eventStart = new DateTimeImmutable($eventStartTimes[$blog_slug] . ' Europe/Sofia');
$interval = $now->diff($eventStart);
}
if ($interval instanceof DateInterval && $interval->invert === 0) {
?>
<style>
.countdown {
text-align: center;
}
.countdown > table {
margin: 0 auto;
}
.countdown .digits > td {
font-size: 30px;
padding: 0 10px;
}
.countdown .units > td {
font-size: 12px;
}
</style>
<br><br>
<div class="countdown">
<?php e_('countdown_text_before'); ?>
<table>
<tbody>
<tr class="digits">
<td><?php echo $interval->format('%a'); ?></td>
<td><?php echo $interval->format('%H'); ?></td>
<td><?php echo $interval->format('%I'); ?></td>
</tr>
<tr class="units">
<td><?php e_('countdown_days'); ?></td>
<td><?php e_('countdown_hours'); ?></td>
<td><?php e_('countdown_minutes'); ?></td>
</tr>
</tbody>
</table>
<?php e_('countdown_text_after'); ?>
</div>
<?php
}
// countdown end
?> ?>
</section> </section>
<section class="content"> <section class="content">