Skip to content

Commit

Permalink
Merge pull request #16 from chswx/decouple-observations
Browse files Browse the repository at this point in the history
Decouple observations from theme
  • Loading branch information
jaredwsmith authored Jul 7, 2023
2 parents 15defd9 + 2fc1271 commit 7a5fc52
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 169 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
}
],
"require": {
"rarst/wpdatetime": "0.3",
"olifolkerd/convertor": "dev-master"
},
"license": "GPLv2",
Expand Down
51 changes: 3 additions & 48 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions css/responsive-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,43 @@ div#currentwx #temp.hot {
color: rgb(146, 0, 0);
}

div.system-message.outdated-data {
font-size: 0.75em;
font-weight: bold;
margin: -10px auto 20px auto;
padding: 10px 20px;
border-radius: 0.5em;
text-align: center;
display: inline-block;
}

div.system-message.outdated-data::before {
content: '\26A0';
padding-right: 3px;
}

div.fail {
margin-bottom: 32px;
color: #555;
display: inline-block;
background-color: #ffdfdf;
border: 1px solid #ff9f9f;
border-radius: 5px;
padding: 30px 30px 32px 30px;
}

div.fail h3 {
font-size: 2em;
margin: 0px;
padding: 0px;
color: #9f6363;
}

div.fail p {
font-size: 0.8em;
margin: 3px 0 0 0;
}

#sky {
font-size: 2em;
font-weight: 600;
Expand Down Expand Up @@ -665,6 +702,21 @@ article.full-post .entry-footer.tagged .meta {
background: linear-gradient(180deg, rgba(39, 39, 142, 1) 0%, rgb(122, 151, 194) 100%);
}

div.fail {
color: #EEE;
background-color: #9f6363;
border: 1px solid #7f2f2f;
}

div.fail h3 {
color: #ffbfbf;
}

div.system-message {
background-color: #9e8300;
border: 1px solid #a18508;
}

.home h2,
.alternate,
a {
Expand Down
116 changes: 8 additions & 108 deletions front-page.php
Original file line number Diff line number Diff line change
@@ -1,117 +1,17 @@
<?php

use Rarst\WordPress\DateTime\WpDateTime;
use Rarst\WordPress\DateTime\WpDateTimeZone;

$data = array();

$data['current_observation'] = chswx_normalize_observation_data(chswx_get_observation_data());
$data['forecast'] = chswx_get_forecast_data();

// Current conditions
if (isset($data['current_observation'])) {
$ob = $data['current_observation'];
$temperature = $ob['temp_f'] . "&deg;";

// Feels like (heat index/wind chill)
$feels_like_temp = $ob['feelslike_f'] . "&deg;";
// v3.0.3: Set a default feels like type for sanity's sake
$feels_like_type = "";
// v3.0.3: WU API does not empty out the heat index/wind chill values,
// just uses NA when they don't apply...so check against that instead
if ($ob['heat_index_f'] != "NA") {
$feels_like_type = 'hi';
} elseif ($ob['windchill_f'] != "NA") {
$feels_like_type = 'wc';
}
$display_feels_like = $feels_like_temp != $temperature;

// Temperature color
if ($temperature < 28) {
$tempcolor = "frigid";
} else if ($temperature > 28 && $temperature < 50) {
$tempcolor = "cold";
} else if ($temperature >= 50 && $temperature < 70) {
$tempcolor = "moderate";
} else if ($temperature >= 70 && $temperature < 83) {
$tempcolor = "warm";
} else if ($temperature >= 83 && $temperature < 95) {
$tempcolor = "verywarm";
} else {
$tempcolor = "hot";
}

// Sensible weather
$sky = $ob['weather'];

// Winds
if ($ob['wind_mph'] === 0) {
$wind = "Calm";
} else {
$wind = $ob['wind_dir'] . " " . $ob['wind_mph'];
}

if ($ob['wind_gust_mph'] > 0) {
$wind .= " (gust {$ob['wind_gust_mph']})";
}

// Other statistics
$dewpoint = $ob['dewpoint_f'] . "&deg;F";
$rh = $ob['relative_humidity'];
$pressure = $ob['pressure_in'] . " in";
$obdate = new WpDateTime();
$obdate->setTimestamp($ob['observation_epoch']);
$obdate->setTimezone(WpDateTimeZone::getWpTimezone());
}
get_header();
?>
<?php get_header(); ?>

<div id="currentwx">
<h2>CURRENTLY</h2>
<?php
if (isset($data['current_observation'])) {
?>
<div id="temp" class="<?php echo $tempcolor ?>"><?php echo $temperature ?></div>
<?php if ($display_feels_like) : ?>
<div id="feels-like">Feels Like <span class="<?php echo $feels_like_type ?>"><?php echo $feels_like_temp ?></span></div>
<?php endif; ?>
<div id="sky"><?php echo $sky; ?></div>
<ul id="others">
<li><span class="title">Wind</span> <?php echo $wind ?></li>
<li><span class="title">Pressure</span> <?php echo $pressure; ?></li>
<li><span class="title">Dewpoint</span> <?php echo $dewpoint; ?></li>
<li><span class="title">Humidity</span> <?php echo $rh; ?></li>
</ul>
<div class="updated-time">last updated at <?php echo $obdate->formatTime(); ?> on <?php echo $obdate->formatDate(); ?></div>
<?php } else { ?>
<div class="fail">Temporarily Unavailable</div>
<?php } ?>
<?php do_action('wxpress_observations'); ?>
</div>
<?php do_action('chswx_alerts'); ?>
<?php do_action('wxpress_alerts'); ?>
<?php do_action('chswx_updates'); ?>
<?php if (isset($data['forecast'])) :
$fcstdate = new WpDateTime();
if (isset($data['forecast']['updated'])) {
$fcstdate->setTimestamp($data['forecast']['updated']);
$fcstdate->setTimezone(WpDateTimeZone::getWpTimezone());
}
?>
<div id="forecast">
<h2>Forecast</h2>
<div class="updated-time">Forecast for Charleston updated at <?php echo $fcstdate->formatTime() ?> on <?php echo $fcstdate->formatDate(); ?></div>
<ul>
<?php
if (isset($data['forecast']['periods'])) {
foreach ($data['forecast']['periods'] as $forecast) {
?><li><span class="day"><?php echo $forecast['name'] ?></span> <span class="forecast_text"><?php echo $forecast['detailedForecast'] ?></span></li>
<?php
}
} else {
?><div class="fail">Forecast temporarily unavailable</div>
<?php }
?>
</ul>
</div>
<?php endif; ?>
<div id="forecast">
<h2>Forecast</h2>
<?php do_action('wxpress_forecast'); ?>
</div>
<?php
$blog_args = [
'post_type' => 'post',
Expand Down
8 changes: 0 additions & 8 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ function register_stylesheet()
}
add_action('wp_enqueue_scripts', 'register_stylesheet');

function maybe_register_jquery()
{
if (is_front_page()) {
wp_enqueue_script('jquery');
}
}
add_action('wp_enqueue_scripts', 'maybe_register_jquery');

add_theme_support('title-tag');
add_theme_support('wp-block-styles');
add_theme_support('responsive-embeds');
Expand Down
12 changes: 8 additions & 4 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<meta name="theme-color" content="#ffffff">
<link rel="icon" type="image/png" href="<?php echo get_stylesheet_directory_uri() ?>/assets/favicon.png">
<link rel="apple-touch-icon" type="image/png" href="<?php echo get_stylesheet_directory_uri() ?>/assets/chswx-retro-2023.png">
<?php wp_head(); ?>
<?php

wp_head();
?>
</head>

<body <?php body_class(); ?>>
Expand All @@ -20,7 +23,8 @@
<a href="/"><object type="image/svg+xml" data="<?php echo get_stylesheet_directory_uri() ?>/assets/wordmark-oneline.svg" class="chswx-logo">Charleston Weather</object></a>
</span>
</h1>
<?php do_action('wxpress_critical_alerts'); ?>
<div id="wrapper">
<?php if (is_blog_page() && !is_home()) {
?><h2 class="alternate"><a href="<?php echo get_post_type_archive_link('post') ?>">Blog</a></h2><?php
}
<?php if (is_blog_page() && !is_home()) : ?>
<h2 class="alternate"><a href="<?php echo get_post_type_archive_link('post') ?>">Blog</a></h2>
<?php endif; ?>

0 comments on commit 7a5fc52

Please sign in to comment.