
<?php
add_to_head(' <style>
body { font-family: Arial, sans-serif; background: #f2f2f2; padding: 30px; }
form { background: white; padding: 20px; border-radius: 8px; width: 320px; margin: auto; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
input { width: 100%; padding: 8px; margin: 8px 0; }
button { background: #007BFF; color: white; border: none; padding: 10px; width: 100%; cursor: pointer; }
button:hover { background: #0056b3; }
.result { text-align: center; margin-top: 20px; font-size: 1.2em; }
</style>');
add_to_title(' 🥶 kalkulator odczuwalnej temperatury');
set_meta("description", "Darmowy skrypt PHP dla CMS PHP-Fusion obliczający odczuwalną temperaturę na podstawie wilgotności i prędkości wiatru. Prosty, szybki i bezpłatny dodatek.");
add_to_head('<style> body{font-family:Arial, sans-serif;background-color:#f9f9f9;padding:20px;}h1{color:#333;font-size:1.8em;margin-bottom:20px;}h2{color:#555;font-size:1.5em;margin:20px 0 10px;}.container{background-color:#fff;padding:20px;border-radius:5px;box-shadow:0 2px 5px rgba(0, 0, 0, 0.1);margin-bottom:20px;}.article-item{width:95%;overflow:hidden;margin:auto;}.article-item h1{font-size:1.5em;color:#333;font-weight:bold;}.article-article{max-width:95%;margin:auto;font-size:20px;color:#333;}.form-container{max-width:100%;margin:0 auto;}.form-group{margin-bottom:15px;}.btn-primary{background-color:#007bff;border-color:#007bff;color:#fff;padding:10px 15px;border-radius:5px;text-align:center;text-decoration:none;display:inline-block;}.btn-primary:hover{background-color:#0056b3;border-color:#0056b3;}@media (max-width:768px){body{padding:10px;}h1{font-size:1.5em;}h2{font-size:1.3em;}.container{padding:15px;}.article-item h1{font-size:1.6em;}.article-article{font-size:18px;}.form-group{display:flex;flex-direction:column;}.form-group label{margin-bottom:5px;}.form-group input{width:100%;}}</style>');
function odczuwalna_temperatura($tempC, $wilgotnosc, $wiatrKmh) {
// Jeśli jest zimno (poniżej lub równe 10°C), używamy wzoru "wind chill"
if ($tempC <= 10) {
$odczuwalna = 13.12 + 0.6215 * $tempC - 11.37 * pow($wiatrKmh, 0.16) + 0.3965 * $tempC * pow($wiatrKmh, 0.16);
} else {
// Wzór Steadmana (Heat Index)
$T = $tempC;
$R = $wilgotnosc;
$odczuwalna =
-8.784695 +
1.61139411 * $T +
2.338549 * $R +
-0.14611605 * $T * $R +
-0.012308094 * pow($T, 2) +
-0.016424828 * pow($R, 2) +
0.002211732 * pow($T, 2) * $R +
0.00072546 * $T * pow($R, 2) +
-0.000003582 * pow($T, 2) * pow($R, 2);
}
return round($odczuwalna, 1);
}
// --- Przykład działania ---
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$temp = floatval($_POST['temp']);
$wilg = floatval($_POST['wilg']);
$wiatr = floatval($_POST['wiatr']);
$wynik = odczuwalna_temperatura($temp, $wilg, $wiatr);
}
?>
<form method="POST">
<h3>Oblicz odczuwalną temperaturę</h3>
<label>Temperatura [°C]:</label>
<input type="number" step="0.1" name="temp" required>
<label>Wilgotność [%]:</label>
<input type="number" step="0.1" name="wilg" required>
<label>Wiatr [km/h]:</label>
<input type="number" step="0.1" name="wiatr" required>
<button type="submit">Oblicz</button>
</form>
<?php if (isset($wynik)): ?>
<div class="result">
<strong>Odczuwalna temperatura:</strong> <?= $wynik ?> °C
</div>
<?php endif; ?>