|
@ -20,7 +20,8 @@ |
|
|
* @subpackage Water_The_Theme/public |
|
|
* @subpackage Water_The_Theme/public |
|
|
* @author Jonathan Rosenbaum <gnuser@gmail.com> |
|
|
* @author Jonathan Rosenbaum <gnuser@gmail.com> |
|
|
*/ |
|
|
*/ |
|
|
class Water_The_Theme_Public { |
|
|
class Water_The_Theme_Public |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* The ID of this plugin. |
|
|
* The ID of this plugin. |
|
@ -47,11 +48,11 @@ class Water_The_Theme_Public { |
|
|
* @param string $plugin_name The name of the plugin. |
|
|
* @param string $plugin_name The name of the plugin. |
|
|
* @param string $version The version of this plugin. |
|
|
* @param string $version The version of this plugin. |
|
|
*/ |
|
|
*/ |
|
|
public function __construct( $plugin_name, $version ) { |
|
|
public function __construct($plugin_name, $version) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$this->plugin_name = $plugin_name; |
|
|
$this->plugin_name = $plugin_name; |
|
|
$this->version = $version; |
|
|
$this->version = $version; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -59,7 +60,8 @@ class Water_The_Theme_Public { |
|
|
* |
|
|
* |
|
|
* @since 1.0.0 |
|
|
* @since 1.0.0 |
|
|
*/ |
|
|
*/ |
|
|
public function enqueue_styles() { |
|
|
public function enqueue_styles() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This function is provided for demonstration purposes only. |
|
|
* This function is provided for demonstration purposes only. |
|
@ -73,8 +75,7 @@ class Water_The_Theme_Public { |
|
|
* class. |
|
|
* class. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/water-the-theme-public.css', array(), $this->version, 'all' ); |
|
|
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/water-the-theme-public.css', array(), $this->version, 'all'); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -82,7 +83,8 @@ class Water_The_Theme_Public { |
|
|
* |
|
|
* |
|
|
* @since 1.0.0 |
|
|
* @since 1.0.0 |
|
|
*/ |
|
|
*/ |
|
|
public function enqueue_scripts() { |
|
|
public function enqueue_scripts() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This function is provided for demonstration purposes only. |
|
|
* This function is provided for demonstration purposes only. |
|
@ -96,11 +98,11 @@ class Water_The_Theme_Public { |
|
|
* class. |
|
|
* class. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/water-the-theme-public.js', array( 'jquery' ), $this->version, false ); |
|
|
wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/water-the-theme-public.js', array('jquery'), $this->version, false); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function water_the_theme($thePage) { |
|
|
public function water_the_theme($thePage) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
$doc = new DOMDocument(); |
|
|
$doc = new DOMDocument(); |
|
|
$doc->loadHTML($thePage); |
|
|
$doc->loadHTML($thePage); |
|
@ -108,7 +110,7 @@ class Water_The_Theme_Public { |
|
|
|
|
|
|
|
|
$short_code_name = (string)$xml_tree->body->div->attributes()->class; |
|
|
$short_code_name = (string)$xml_tree->body->div->attributes()->class; |
|
|
|
|
|
|
|
|
$thePage ="<table id='$short_code_name'>"; |
|
|
$thePage = "<table id='$short_code_name'>"; |
|
|
|
|
|
|
|
|
// front page |
|
|
// front page |
|
|
// [usgs_custom name="Timely Information" location='03071590,03071600,03071605' parameters='00010,00065,62614'] |
|
|
// [usgs_custom name="Timely Information" location='03071590,03071600,03071605' parameters='00010,00065,62614'] |
|
@ -145,7 +147,7 @@ class Water_The_Theme_Public { |
|
|
$sitename = 'Below Dam'; |
|
|
$sitename = 'Below Dam'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( $sitename !== 'Lake') { |
|
|
if ($sitename !== 'Lake') { |
|
|
$thePage .= '<tr>'; |
|
|
$thePage .= '<tr>'; |
|
|
$thePage .= "<td>$sitename $parameter</td><td>$value</td><td datetime='$datetime'></td>"; |
|
|
$thePage .= "<td>$sitename $parameter</td><td>$value</td><td datetime='$datetime'></td>"; |
|
|
$thePage .= '</tr>'; |
|
|
$thePage .= '</tr>'; |
|
@ -164,7 +166,6 @@ class Water_The_Theme_Public { |
|
|
$nws_custom = Water_The_Theme_Public::nws_custom($att); |
|
|
$nws_custom = Water_The_Theme_Public::nws_custom($att); |
|
|
|
|
|
|
|
|
$thePage .= $nws_custom; |
|
|
$thePage .= $nws_custom; |
|
|
|
|
|
|
|
|
} // end Timely Information |
|
|
} // end Timely Information |
|
|
|
|
|
|
|
|
// Statics Page - last 5 lake data |
|
|
// Statics Page - last 5 lake data |
|
@ -181,6 +182,7 @@ class Water_The_Theme_Public { |
|
|
$datetime = (string)$div->attributes()->datetime; |
|
|
$datetime = (string)$div->attributes()->datetime; |
|
|
|
|
|
|
|
|
list($sitename, $parameter) = explode(' ', $class); |
|
|
list($sitename, $parameter) = explode(' ', $class); |
|
|
|
|
|
|
|
|
$sitename = ucwords(preg_replace('/_/', ' ', $sitename)); |
|
|
$sitename = ucwords(preg_replace('/_/', ' ', $sitename)); |
|
|
$parameter = ucwords(preg_replace('/_/', ' ', $parameter)); |
|
|
$parameter = ucwords(preg_replace('/_/', ' ', $parameter)); |
|
|
|
|
|
|
|
@ -205,13 +207,31 @@ class Water_The_Theme_Public { |
|
|
if ($sitename === 'Tail Race Level') { |
|
|
if ($sitename === 'Tail Race Level') { |
|
|
$value = (float)$value + 776.63; |
|
|
$value = (float)$value + 776.63; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($value !== 'n/a') { |
|
|
$statistics[] = "<tr><td>$sitename $parameter</td><td>$value</td><td datetime='$datetime'></td></tr>"; |
|
|
$statistics[] = "<tr><td>$sitename $parameter</td><td>$value</td><td datetime='$datetime'></td></tr>"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//PC::debug($value . " " . $sitename . " " . $parameter); |
|
|
//PC::debug($value . " " . $sitename . " " . $parameter); |
|
|
} // end foreach |
|
|
} // end foreach |
|
|
|
|
|
|
|
|
list($array1, $array2, $array3) = array_chunk($statistics, ceil(count($statistics) / 3)); |
|
|
|
|
|
foreach($array1 as $key => $value ) { |
|
|
usort($statistics, function ($a, $b) { |
|
|
|
|
|
preg_match('/datetime=\'(\d+)\'/', $a, $matchesA); |
|
|
|
|
|
preg_match('/datetime=\'(\d+)\'/', $b, $matchesB); |
|
|
|
|
|
|
|
|
|
|
|
$dateTimeA = isset($matchesA[1]) ? (int)$matchesA[1] : 0; |
|
|
|
|
|
$dateTimeB = isset($matchesB[1]) ? (int)$matchesB[1] : 0; |
|
|
|
|
|
|
|
|
|
|
|
return $dateTimeB - $dateTimeA; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// highlight_string(var_export($statistics, true)); |
|
|
|
|
|
list($array1, $array2, $array3) = array_chunk($statistics, ceil(count($statistics) / 1)); |
|
|
|
|
|
// highlight_string(var_export($array1, true)); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($array1 as $key => $value) { |
|
|
|
|
|
|
|
|
$thePage .= $array2[$key]; |
|
|
$thePage .= $array2[$key]; |
|
|
$thePage .= $array3[$key]; |
|
|
$thePage .= $array3[$key]; |
|
|
$thePage .= $value; |
|
|
$thePage .= $value; |
|
@ -223,10 +243,10 @@ class Water_The_Theme_Public { |
|
|
|
|
|
|
|
|
$thePage .= '</table>'; |
|
|
$thePage .= '</table>'; |
|
|
return $thePage; |
|
|
return $thePage; |
|
|
|
|
|
|
|
|
} // function water the theme |
|
|
} // function water the theme |
|
|
|
|
|
|
|
|
public function nws_custom( $att ) { |
|
|
public function nws_custom($att) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list($name, $location, $parameters, $date_range, $order) = [ |
|
|
list($name, $location, $parameters, $date_range, $order) = [ |
|
@ -241,22 +261,22 @@ class Water_The_Theme_Public { |
|
|
// Tail Race Level = Gage Datum + Gage Height |
|
|
// Tail Race Level = Gage Datum + Gage Height |
|
|
foreach ($locations as $location) { |
|
|
foreach ($locations as $location) { |
|
|
|
|
|
|
|
|
$thePage = get_transient('nws_custom-' . $name . $location . $date_range . $parameters . $order ); |
|
|
$thePage = get_transient('nws_custom-' . $name . $location . $date_range . $parameters . $order); |
|
|
|
|
|
|
|
|
if ( !$thePage ) { |
|
|
if (!$thePage) { |
|
|
|
|
|
|
|
|
$url = "http://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=$location&output=xml"; |
|
|
$url = "http://water.weather.gov/ahps2/hydrograph_to_xml.php?gage=$location&output=xml"; |
|
|
|
|
|
|
|
|
$response = wp_remote_get( $url ); |
|
|
$response = wp_remote_get($url); |
|
|
$data = wp_remote_retrieve_body( $response ); |
|
|
$data = wp_remote_retrieve_body($response); |
|
|
|
|
|
|
|
|
if ( ! $data ) { |
|
|
if (!$data) { |
|
|
return 'Nation Weather Service is not Responding.'; |
|
|
return 'Nation Weather Service is not Responding.'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$xml_tree = simplexml_load_string( $data ); |
|
|
$xml_tree = simplexml_load_string($data); |
|
|
if ( False === $xml_tree ) { |
|
|
if (False === $xml_tree) { |
|
|
return 'Unable to parse NWS XML'; |
|
|
return 'Unable to parse NWS XML'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -267,7 +287,7 @@ class Water_The_Theme_Public { |
|
|
$waterlevel = (string)$xml_tree->zerodatum; |
|
|
$waterlevel = (string)$xml_tree->zerodatum; |
|
|
|
|
|
|
|
|
$c = 0; |
|
|
$c = 0; |
|
|
foreach ( $xml_tree->observed->datum as $datum ) { |
|
|
foreach ($xml_tree->observed->datum as $datum) { |
|
|
|
|
|
|
|
|
// in javascript this works out of the box (* 1000) |
|
|
// in javascript this works out of the box (* 1000) |
|
|
$datetime = strtotime($datum->valid) * 1000; |
|
|
$datetime = strtotime($datum->valid) * 1000; |
|
@ -283,7 +303,7 @@ class Water_The_Theme_Public { |
|
|
|
|
|
|
|
|
$tail_race_level = (float)$waterlevel + (float)$gageheight; |
|
|
$tail_race_level = (float)$waterlevel + (float)$gageheight; |
|
|
|
|
|
|
|
|
if($c === 0 && $date_range === 'current') { |
|
|
if ($c === 0 && $date_range === 'current') { |
|
|
$thePage .= "<tr><td>Tail Race Level (AMSL)</td><td>$tail_race_level ft</td><td datetime='$datetime'></td></tr>"; |
|
|
$thePage .= "<tr><td>Tail Race Level (AMSL)</td><td>$tail_race_level ft</td><td datetime='$datetime'></td></tr>"; |
|
|
//$thePage .= "<tr><td>Gage Datum (AMSL)</td><td>$waterlevel ft</td><td datetime='$datetime'></td></tr>"; |
|
|
//$thePage .= "<tr><td>Gage Datum (AMSL)</td><td>$waterlevel ft</td><td datetime='$datetime'></td></tr>"; |
|
|
//$thePage .= "<tr><td>Tail Water Flow</td><td>$waterflow</td><td datetime='$datetime'></td></tr>"; |
|
|
//$thePage .= "<tr><td>Tail Water Flow</td><td>$waterflow</td><td datetime='$datetime'></td></tr>"; |
|
@ -294,13 +314,12 @@ class Water_The_Theme_Public { |
|
|
//$thePage .= "<tr><td>Tail Water Flow</td><td>$waterflow</td><td datetime='$datetime'></td></tr>"; |
|
|
//$thePage .= "<tr><td>Tail Water Flow</td><td>$waterflow</td><td datetime='$datetime'></td></tr>"; |
|
|
} |
|
|
} |
|
|
$c++; |
|
|
$c++; |
|
|
|
|
|
|
|
|
} // foreach xml_tree as site data |
|
|
} // foreach xml_tree as site data |
|
|
|
|
|
|
|
|
} // foreach NWS location |
|
|
} // foreach NWS location |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_transient( 'nws_custom-' . $name . $location . $date_range . $parameters . $order, $thePage, 60 * 15 ); |
|
|
set_transient('nws_custom-' . $name . $location . $date_range . $parameters . $order, $thePage, 60 * 15); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $thePage; |
|
|
return $thePage; |
|
|