| Server IP : 65.1.209.187 / Your IP : 216.73.216.144 Web Server : nginx/1.24.0 System : Linux ip-172-31-5-206 6.14.0-1015-aws #15~24.04.1-Ubuntu SMP Tue Sep 23 22:44:48 UTC 2025 x86_64 User : ( 1001) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/ttc_wordpress/wp-content/themes/ttc/ |
Upload File : |
<?php
/**
* Template Name: Schedule Calendar
*
* Full-month view of court fixtures (past and future in the selected month).
*
* @package ttc
*/
get_header('inner');
if (!have_posts()) {
get_footer();
return;
}
the_post();
$tz = ttc_fixture_wp_timezone();
$now = new DateTime('now', $tz);
$month = isset($_GET['cal_m']) ? (int) $_GET['cal_m'] : (int) $now->format('n');
$year = isset($_GET['cal_y']) ? (int) $_GET['cal_y'] : (int) $now->format('Y');
if ($month < 1 || $month > 12) {
$month = (int) $now->format('n');
}
if ($year < 2000 || $year > 2100) {
$year = (int) $now->format('Y');
}
$kind_filter = isset($_GET['fixture_kind']) ? sanitize_key(wp_unslash($_GET['fixture_kind'])) : '';
if ($kind_filter !== 'tournament' && $kind_filter !== 'single_event') {
$kind_filter = '';
}
$fixtures = ttc_get_fixtures_for_month($year, $month, $kind_filter);
$by_day = ttc_group_fixtures_by_day($fixtures);
try {
$first_of_month = new DateTime(sprintf('%04d-%02d-01', $year, $month), $tz);
} catch (Exception $e) {
$first_of_month = clone $now;
}
$days_in_month = (int) $first_of_month->format('t');
$start_weekday = (int) $first_of_month->format('N'); // 1 = Monday
$pad_before = $start_weekday - 1;
$prev = (clone $first_of_month)->modify('-1 month');
$next = (clone $first_of_month)->modify('+1 month');
$base_url = get_permalink();
$nav_params = array();
if ($kind_filter !== '') {
$nav_params['fixture_kind'] = $kind_filter;
}
$prev_url = esc_url(add_query_arg(array_merge($nav_params, array('cal_m' => (int) $prev->format('n'), 'cal_y' => (int) $prev->format('Y'))), $base_url));
$next_url = esc_url(add_query_arg(array_merge($nav_params, array('cal_m' => (int) $next->format('n'), 'cal_y' => (int) $next->format('Y'))), $base_url));
$month_title = wp_date('F Y', $first_of_month->getTimestamp());
?>
<div class="ttc-ms-cal py-20">
<div class="container px-4 sm:px-8">
<div class="ttc-ms-cal__intro">
<h1 class="ttc-ms-cal__h1"><?php the_title(); ?></h1>
<?php
$content = get_post_field('post_content', get_the_ID());
if (trim(wp_strip_all_tags($content)) !== '') {
echo '<div class="ttc-ms-cal__content">';
the_content();
echo '</div>';
}
?>
</div>
<form class="ttc-ms-cal__filters" method="get" action="<?php echo esc_url($base_url); ?>">
<input type="hidden" name="cal_m" value="<?php echo esc_attr((string) $month); ?>" />
<input type="hidden" name="cal_y" value="<?php echo esc_attr((string) $year); ?>" />
<label class="screen-reader-text" for="fixture_kind"><?php esc_html_e('Fixture type', 'ttc'); ?></label>
<select class="ttc-ms-cal__select" id="fixture_kind" name="fixture_kind" onchange="this.form.submit()">
<option value=""><?php esc_html_e('All fixtures', 'ttc'); ?></option>
<option value="tournament" <?php selected($kind_filter, 'tournament'); ?>><?php esc_html_e('Tournament only', 'ttc'); ?></option>
<option value="single_event" <?php selected($kind_filter, 'single_event'); ?>><?php esc_html_e('Club events only', 'ttc'); ?></option>
</select>
<noscript><button type="submit" class="ttc-ms-btn ttc-ms-btn--solid"><?php esc_html_e('Apply', 'ttc'); ?></button></noscript>
</form>
<div class="ttc-ms-cal__toolbar">
<a class="ttc-ms-cal__nav" href="<?php echo $prev_url; ?>"><?php esc_html_e('Previous month', 'ttc'); ?></a>
<h2 class="ttc-ms-cal__month"><?php echo esc_html($month_title); ?></h2>
<a class="ttc-ms-cal__nav" href="<?php echo $next_url; ?>"><?php esc_html_e('Next month', 'ttc'); ?></a>
</div>
<div class="ttc-ms-cal__grid" role="grid" aria-label="<?php echo esc_attr($month_title); ?>">
<div class="ttc-ms-cal__dow" role="row">
<?php
$dows = array(__('Mon', 'ttc'), __('Tue', 'ttc'), __('Wed', 'ttc'), __('Thu', 'ttc'), __('Fri', 'ttc'), __('Sat', 'ttc'), __('Sun', 'ttc'));
foreach ($dows as $d) {
echo '<div class="ttc-ms-cal__dow-cell" role="columnheader">' . esc_html($d) . '</div>';
}
?>
</div>
<div class="ttc-ms-cal__cells" role="row">
<?php
for ($i = 0; $i < $pad_before; $i++) {
echo '<div class="ttc-ms-cal__cell ttc-ms-cal__cell--muted" aria-hidden="true"></div>';
}
for ($d = 1; $d <= $days_in_month; $d++) {
$day_key = sprintf('%04d-%02d-%02d', $year, $month, $d);
$day_posts = isset($by_day[ $day_key ]) ? $by_day[ $day_key ] : array();
$is_today = ($day_key === $now->format('Y-m-d'));
$cell_classes = 'ttc-ms-cal__cell';
if ($is_today) {
$cell_classes .= ' ttc-ms-cal__cell--today';
}
if (!empty($day_posts)) {
$cell_classes .= ' ttc-ms-cal__cell--has';
}
?>
<div class="<?php echo esc_attr($cell_classes); ?>" role="gridcell">
<div class="ttc-ms-cal__daynum"><?php echo esc_html((string) $d); ?></div>
<?php if (!empty($day_posts)) { ?>
<ul class="ttc-ms-cal__dots">
<?php
foreach ($day_posts as $fp) {
$tstored = get_post_meta($fp->ID, TTC_FIXTURE_DATETIME_META, true);
$tts = $tstored ? ttc_fixture_datetime_to_timestamp($tstored) : false;
$tlab = $tts ? wp_date('g:i a', $tts) : '';
?>
<li class="ttc-ms-cal__dot" title="<?php echo esc_attr(get_the_title($fp)); ?>">
<span class="ttc-ms-cal__dot-time"><?php echo esc_html($tlab); ?></span>
<span class="ttc-ms-cal__dot-title"><?php echo esc_html(wp_trim_words(get_the_title($fp), 4, '…')); ?></span>
</li>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php
}
$total_cells = $pad_before + $days_in_month;
$remainder = $total_cells % 7;
if ($remainder !== 0) {
for ($i = 0; $i < 7 - $remainder; $i++) {
echo '<div class="ttc-ms-cal__cell ttc-ms-cal__cell--muted" aria-hidden="true"></div>';
}
}
?>
</div>
</div>
<section class="ttc-ms-cal__detail" aria-labelledby="ttc-ms-cal-detail-heading">
<h2 id="ttc-ms-cal-detail-heading" class="ttc-ms-cal__detail-h"><?php esc_html_e('Fixtures this month', 'ttc'); ?></h2>
<?php if (!empty($fixtures)) { ?>
<ol class="ttc-ms-cal__detail-list">
<?php
foreach ($fixtures as $fp) {
$pid = $fp->ID;
$stored = get_post_meta($pid, TTC_FIXTURE_DATETIME_META, true);
$ts = $stored ? ttc_fixture_datetime_to_timestamp($stored) : false;
$kind = get_post_meta($pid, 'ttc_fixture_kind', true);
$event_name = get_post_meta($pid, 'ttc_event_name', true);
$stage = get_post_meta($pid, 'ttc_stage', true);
$court = get_post_meta($pid, 'ttc_court', true);
$result = get_post_meta($pid, 'ttc_result_summary', true);
$kind_label = ($kind === 'single_event') ? __('Event', 'ttc') : __('Tournament', 'ttc');
?>
<li class="ttc-ms-cal__detail-row">
<div class="ttc-ms-cal__detail-when">
<?php echo $ts ? esc_html(wp_date('D, j M · g:i a', $ts)) : '—'; ?>
</div>
<div class="ttc-ms-cal__detail-main">
<span class="ttc-ms-pill"><?php echo esc_html($kind_label); ?></span>
<?php if ($event_name) { ?>
<strong class="ttc-ms-cal__detail-event"><?php echo esc_html($event_name); ?></strong>
<?php } ?>
<?php if ($stage) { ?>
<span class="ttc-ms-cal__detail-stage"><?php echo esc_html($stage); ?></span>
<?php } ?>
<div class="ttc-ms-cal__detail-players"><?php echo wp_kses_post(ttc_fixture_players_line_html($pid)); ?></div>
<div class="ttc-ms-cal__detail-meta">
<?php if ($court) { ?>
<span><?php echo esc_html(sprintf(__('Court: %s', 'ttc'), $court)); ?></span>
<?php } ?>
<?php if ($result) { ?>
<span><?php echo esc_html(sprintf(__('Result: %s', 'ttc'), $result)); ?></span>
<?php } ?>
</div>
</div>
</li>
<?php } ?>
</ol>
<?php } else { ?>
<p class="ttc-ms-cal__empty"><?php esc_html_e('No fixtures in this month for the selected filter.', 'ttc'); ?></p>
<?php } ?>
</section>
</div>
</div>
<?php
get_footer();