Files
FARM/plant.php
T
2026-06-25 21:29:21 +00:00

226 lines
9.6 KiB
PHP
Raw 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=>'Jan',2=>'Feb',3=>'Mar',4=>'Apr',5=>'May',6=>'Jun',
7=>'Jul',8=>'Aug',9=>'Sep',10=>'Oct',11=>'Nov',12=>'Dec'];
$fullMonths = [1=>'January',2=>'February',3=>'March',4=>'April',
5=>'May',6=>'June',7=>'July',8=>'August',
9=>'September',10=>'October',11=>'November',12=>'December'];
$slug = isset($_GET['p']) ? preg_replace('/[^a-z0-9_]/','',strtolower($_GET['p'])) : '';
$refMonth = isset($_GET['m']) ? (int)$_GET['m'] : 0;
$plant = null;
if ($slug && file_exists($dataFile)) {
$json = json_decode(file_get_contents($dataFile), true);
if ($json && isset($json['plants'][$slug])) {
$plant = $json['plants'][$slug];
}
}
if (!$plant) {
http_response_code(404);
echo '<h1 style="font-family:sans-serif;padding:2rem">Plant not found</h1>';
echo '<a href="index.php" style="font-family:sans-serif;padding:2rem">← Home</a>';
exit;
}
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><?= htmlspecialchars($plant['name']) ?> - 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>
<?php if ($refMonth > 0): ?>
<span class="sep"></span>
<a href="month.php?m=<?= $refMonth ?>"><?= $fullMonths[$refMonth] ?></a>
<?php endif; ?>
<span class="sep"></span>
<span><?= htmlspecialchars($plant['name']) ?></span>
</div>
<div class="plant-hero">
<?php if (!empty($plant['image']) && file_exists(__DIR__ . '/' . $plant['image'])): ?>
<img src="/<?= htmlspecialchars($plant['image']) ?>"
alt="<?= htmlspecialchars($plant['name']) ?>"
class="plant-hero-img">
<?php endif; ?>
<div class="plant-hero-info">
<h2 class="plant-hero-name"><?= htmlspecialchars($plant['name']) ?></h2>
<?php if (!empty($plant['aliases'])): ?>
<p class="plant-hero-aliases">Also known as:
<em><?= htmlspecialchars(implode(', ', $plant['aliases'])) ?></em>
</p>
<?php endif; ?>
<div class="plant-hero-badges">
<?php if (!empty($plant['pot_friendly'])): ?>
<span class="hero-badge badge-pot">🪴 Pot Friendly</span>
<?php endif; ?>
<span class="hero-badge badge-zone">📍 Zone 8b</span>
</div>
</div>
</div>
<?php if (!empty($plant['description'])): ?>
<section class="plant-section">
<h3 class="section-title">📖 About</h3>
<p class="plant-description"><?= htmlspecialchars($plant['description']) ?></p>
</section>
<?php endif; ?>
<section class="plant-section">
<h3 class="section-title">📐 Growing Information</h3>
<div class="stats-grid">
<?php if (!empty($plant['spacing'])): ?>
<div class="stat-card">
<div class="stat-icon">↔️</div>
<div class="stat-label">Plant Spacing</div>
<div class="stat-value"><?= htmlspecialchars($plant['spacing']) ?></div>
</div>
<?php endif; ?>
<?php if (!empty($plant['row_spacing'])): ?>
<div class="stat-card">
<div class="stat-icon">↕️</div>
<div class="stat-label">Row Spacing</div>
<div class="stat-value"><?= htmlspecialchars($plant['row_spacing']) ?></div>
</div>
<?php endif; ?>
<?php if (!empty($plant['height'])): ?>
<div class="stat-card">
<div class="stat-icon">📏</div>
<div class="stat-label">Plant Height</div>
<div class="stat-value"><?= htmlspecialchars($plant['height']) ?></div>
</div>
<?php endif; ?>
<?php if (!empty($plant['harvest_time'])): ?>
<div class="stat-card">
<div class="stat-icon">🥕</div>
<div class="stat-label">Harvest Time</div>
<div class="stat-value"><?= htmlspecialchars($plant['harvest_time']) ?></div>
</div>
<?php endif; ?>
<?php if (empty($plant['spacing']) && empty($plant['height']) && empty($plant['harvest_time'])): ?>
<p class="no-data-msg">No growing stats yet. Re-run the scraper for more detail.</p>
<?php endif; ?>
</div>
</section>
<section class="plant-section">
<h3 class="section-title">📅 Planting Calendar (Zone 8b)</h3>
<div class="month-bar-container">
<?php foreach ($months as $num => $name):
$hasMonth = isset($plant['months'][strval($num)]);
$badge = $hasMonth ? actionBadge($plant['months'][strval($num)]) : null;
$title = $hasMonth ? htmlspecialchars($plant['months'][strval($num)]) : 'Not a planting month';
?>
<div class="month-bar-cell <?= $hasMonth ? 'active badge-'.$badge['type'] : 'inactive' ?>"
title="<?= $title ?>">
<div class="mbc-name"><?= $name ?></div>
<div class="mbc-icon"><?= $hasMonth ? $badge['icon'] : '' ?></div>
</div>
<?php endforeach; ?>
</div>
<div class="calendar-legend">
<span class="legend-item"><span class="legend-dot active-dot"></span> Active month</span>
<span class="legend-item"><span class="legend-dot inactive-dot"></span> Not recommended</span>
</div>
</section>
<?php if (!empty($plant['months'])): ?>
<section class="plant-section">
<h3 class="section-title">🗓️ Monthly Actions</h3>
<div class="action-list">
<?php foreach ($plant['months'] as $mnum => $action):
$badge = actionBadge($action);
?>
<div class="action-item">
<span class="action-month"><?= $fullMonths[(int)$mnum] ?></span>
<span class="action-badge badge-<?= $badge['type'] ?>"><?= $badge['icon'] ?> <?= $badge['label'] ?></span>
<span class="action-desc"><?= htmlspecialchars($action) ?></span>
</div>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php if (!empty($plant['notes'])): ?>
<section class="plant-section">
<h3 class="section-title">📝 Notes & Tips</h3>
<div class="notes-box"><?= nl2br(htmlspecialchars($plant['notes'])) ?></div>
</section>
<?php endif; ?>
<?php if (!empty($plant['compatible']) || !empty($plant['avoid'])): ?>
<section class="plant-section">
<h3 class="section-title">🤝 Companion Planting</h3>
<div class="companion-grid">
<?php if (!empty($plant['compatible'])): ?>
<div class="companion-card good">
<h4>✅ Grows Well With</h4>
<ul><?php foreach ($plant['compatible'] as $c): ?>
<li><?= htmlspecialchars($c) ?></li>
<?php endforeach; ?></ul>
</div>
<?php endif; ?>
<?php if (!empty($plant['avoid'])): ?>
<div class="companion-card bad">
<h4>❌ Avoid Growing With</h4>
<ul><?php foreach ($plant['avoid'] as $c): ?>
<li><?= htmlspecialchars($c) ?></li>
<?php endforeach; ?></ul>
</div>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
<div class="back-btn-wrap">
<?php if ($refMonth > 0): ?>
<a href="month.php?m=<?= $refMonth ?>" class="btn-back">← Back to <?= $fullMonths[$refMonth] ?></a>
<?php else: ?>
<a href="index.php" class="btn-back">← Back to Calendar</a>
<?php endif; ?>
</div>
</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>
</body>
</html>