Files
2026-06-25 21:29:21 +00:00

151 lines
6.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
$dataFile = __DIR__ . '/data/plants.json';
$months = [
1=>"January",2=>"February",3=>"March",4=>"April",
5=>"May",6=>"June",7=>"July",8=>"August",
9=>"September",10=>"October",11=>"November",12=>"December"
];
$monthEmoji = [
1=>"❄️",2=>"❄️",3=>"🌱",4=>"🌸",5=>"🌿",6=>"☀️",
7=>"☀️",8=>"🌻",9=>"🍂",10=>"🍂",11=>"🌧️",12=>"❄️"
];
$m = isset($_GET['m']) ? (int)$_GET['m'] : 1;
if ($m < 1 || $m > 12) $m = 1;
$prev = $m > 1 ? $m - 1 : 12;
$next = $m < 12 ? $m + 1 : 1;
$plants = [];
if (file_exists($dataFile)) {
$json = json_decode(file_get_contents($dataFile), true);
if ($json && isset($json['plants'])) {
foreach ($json['plants'] as $slug => $plant) {
if (isset($plant['months'][strval($m)])) {
$plants[$slug] = $plant;
}
}
uksort($plants, fn($a,$b) => strcmp($plants[$a]['name'], $plants[$b]['name']));
}
}
function actionBadge($action) {
$a = strtolower($action);
if (strpos($a,'sow seed') !== false) return ['type'=>'sow', 'label'=>'Sow Seed', 'icon'=>'🌱'];
if (strpos($a,'seed tray') !== false ||
strpos($a,'start in') !== false) return ['type'=>'tray', 'label'=>'Start in Trays','icon'=>'🪴'];
if (strpos($a,'transplant') !== false ||
strpos($a,'plant out') !== false) return ['type'=>'transplant','label'=>'Transplant', 'icon'=>'🌿'];
if (strpos($a,'tuber') !== false) return ['type'=>'tuber', 'label'=>'Plant Tubers', 'icon'=>'🥔'];
if (strpos($a,'crown') !== false) return ['type'=>'crown', 'label'=>'Plant Crowns', 'icon'=>'👑'];
if (strpos($a,'clove') !== false) return ['type'=>'clove', 'label'=>'Plant Cloves', 'icon'=>'🧄'];
return ['type'=>'general','label'=>'Plant','icon'=>'🌱'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $months[$m] ?> Planting - Zone 8b</title>
<link rel="stylesheet" href="assets/style.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
</head>
<body>
<header class="site-header">
<div class="header-inner">
<div class="logo">
<span class="logo-icon">🌱</span>
<div>
<h1>Zone 8b Planting Calendar</h1>
<p class="logo-sub">Your year-round garden guide</p>
</div>
</div>
<nav class="top-nav">
<a href="index.php" class="nav-link">Calendar</a>
<a href="plants.php" class="nav-link">All Plants</a>
</nav>
</div>
</header>
<main class="content">
<div class="breadcrumb">
<a href="index.php">🏠 Home</a>
<span class="sep"></span>
<span><?= $monthEmoji[$m] ?> <?= $months[$m] ?></span>
</div>
<div class="month-nav">
<a href="month.php?m=<?= $prev ?>" class="month-nav-btn">← <?= $months[$prev] ?></a>
<h2 class="month-title"><?= $monthEmoji[$m] ?> <?= $months[$m] ?></h2>
<a href="month.php?m=<?= $next ?>" class="month-nav-btn"><?= $months[$next] ?> →</a>
</div>
<?php if (empty($plants)): ?>
<div class="notice info">🌧️ No data for <?= $months[$m] ?>. Run the scraper first.</div>
<?php else: ?>
<p class="month-summary"><?= count($plants) ?> plants for <?= $months[$m] ?> in Zone 8b</p>
<div class="filter-bar">
<button class="filter-btn active" data-filter="all">All (<?= count($plants) ?>)</button>
<?php
$seenTypes = [];
foreach ($plants as $slug => $plant) {
$b = actionBadge($plant['months'][strval($m)]);
if (!in_array($b['type'], $seenTypes)) {
$seenTypes[] = $b['type'];
echo "<button class='filter-btn' data-filter='{$b['type']}'>{$b['label']}</button>";
}
}
?>
</div>
<div class="plant-grid">
<?php foreach ($plants as $slug => $plant):
$action = $plant['months'][strval($m)];
$badge = actionBadge($action);
?>
<a href="plant.php?p=<?= urlencode($slug) ?>&m=<?= $m ?>"
class="plant-card" data-type="<?= $badge['type'] ?>">
<div class="plant-card-header">
<?php if (!empty($plant['image']) && file_exists(__DIR__ . '/' . $plant['image'])): ?>
<img src="/<?= htmlspecialchars($plant['image']) ?>"
alt="<?= htmlspecialchars($plant['name']) ?>"
class="plant-thumb">
<?php else: ?>
<span class="plant-icon"><?= $badge['icon'] ?></span>
<?php endif; ?>
<span class="action-badge badge-<?= $badge['type'] ?>"><?= $badge['label'] ?></span>
</div>
<div class="plant-name"><?= htmlspecialchars($plant['name']) ?></div>
<?php if (!empty($plant['aliases'])): ?>
<div class="plant-aliases">also: <?= htmlspecialchars(implode(', ', array_slice($plant['aliases'],0,3))) ?></div>
<?php endif; ?>
<div class="plant-action-text"><?= htmlspecialchars($action) ?></div>
<?php if (!empty($plant['pot_friendly'])): ?>
<div class="pot-badge">🪴 Pot-friendly</div>
<?php endif; ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</main>
<footer class="site-footer">
<p>Zone 8b Garden Planting Guide &mdash; Data sourced from
<a href="https://gardenate.com" target="_blank">Gardenate.com</a></p>
</footer>
<script>
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const filter = btn.dataset.filter;
document.querySelectorAll('.plant-card').forEach(card => {
card.style.display = (filter === 'all' || card.dataset.type === filter) ? '' : 'none';
});
});
});
</script>
</body>
</html>