Changeset 1876522
- Timestamp:
- 05/17/2018 03:53:13 PM (7 years ago)
- Location:
- usgs-stream-flow-data
- Files:
-
- 31 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
usgs-stream-flow-data/trunk/README.txt
r1850211 r1876522 5 5 Requires at least: 3.7 6 6 Tested up to: 5.0 7 Stable tag: 2.6. 37 Stable tag: 2.6.4 8 8 License: GPLv2 or later 9 9 License URI: //www.gnu.org/licenses/gpl-2.0.html -
usgs-stream-flow-data/trunk/admin/class-kwc-usgs-admin.php
r1848669 r1876522 1 1 <?php 2 2 /** 3 * Admin class for plugin3 * Admin 4 4 * 5 * @package USGS Steam Flow Data 6 * @author Chris Kindred <[email protected]> 7 * @license GPL-2.0+ 8 * @link //www.kindredwebconsulting.com 9 * @copyright 2015 Kindred Web Consulting 5 * @package USGS Steam Flow Data 6 * @author Chris Kindred <[email protected]> 7 * @license GPL-2.0+ 8 * @link //www.kindredwebconsulting.com 9 * @copyright 2015 Kindred Web Consulting 10 */ 11 12 /** 13 * The admin-specific functionality of the plugin. 14 * 15 * Defines the plugin name, version, and two examples hooks for how to 16 * enqueue the admin-specific stylesheet and JavaScript. 17 * 18 * @package USGS Steam Flow Data 19 * @subpackage usgs_stream_flow_data/admin 10 20 */ 11 21 class Kwc_Usgs_Admin { … … 39 49 * Call $plugin_slug from public plugin class. 40 50 */ 41 $plugin = Kwc_Usgs::get_instance(); 42 $this->plugin_slug = $plugin->get_plugin_slug(); 51 $this->plugin_slug = Kwc_Usgs::get_instance()->get_plugin_slug(); 43 52 44 53 // Load admin style sheet and JavaScript. … … 118 127 */ 119 128 public function add_plugin_admin_menu() { 120 121 /*122 * Add a settings page for this plugin to the Settings menu.123 *124 * NOTE: Alternative menu locations are available via WordPress administration menu functions.125 *126 * Administration Menus: //codex.wordpress.org/Administration_Menus127 *128 */129 129 $this->plugin_screen_hook_suffix = add_options_page( 130 __( 'USGS Stream Flow Data', $this->plugin_slug),131 __( 'Stream Flow Data', $this->plugin_slug),130 __( 'USGS Stream Flow Data', 'kwc_usgs' ), 131 __( 'Stream Flow Data', 'kwc_usgs' ), 132 132 'manage_options', 133 133 $this->plugin_slug, … … 149 149 * Add settings action link to the plugins page. 150 150 * 151 * @since 1.0.0 151 * @since 1.0.0 152 * @param array $links The links array. 152 153 */ 153 154 public function add_action_links( $links ) { … … 155 156 return array_merge( 156 157 array( 157 'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>'158 'settings' => '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_slug ) . '">' . __( 'Settings', 'kwc_usgs' ) . '</a>', 158 159 ), 159 160 $links … … 161 162 162 163 } 163 164 /**165 * NOTE: Actions are points in the execution of a page or process166 * lifecycle that WordPress fires.167 *168 * Actions: //codex.wordpress.org/Plugin_API#Actions169 * Reference: //codex.wordpress.org/Plugin_API/Action_Reference170 *171 * @since 1.0.0172 */173 // public function action_method_name() {174 // @TODO: Define your action hook callback here175 // }176 177 164 178 165 /** … … 200 187 }); 201 188 </script> 202 <?php189 <?php 203 190 } 204 191 /** … … 209 196 public function kwcusgsajax_callback() { 210 197 $state = $_POST['state']; 211 212 $url = "https://waterservices.usgs.gov/nwis/iv?stateCd=$state&format=waterml¶meterCd=00060"; 213 $data = wp_remote_get( $url ); 198 $url = "https://waterservices.usgs.gov/nwis/iv?stateCd=$state&format=waterml¶meterCd=00060"; 199 $data = wp_remote_get( $url ); 214 200 if ( ! $data ) { 215 201 echo 'Error retrieving: ' . esc_url( $url ); … … 241 227 </tr> 242 228 </tfoot>"; 243 $cnt = 0; 229 $cnt = 0; 230 // phpcs:disable 231 /** 232 * phpcs is disabled because the data coming from the api is not formed 233 * correctly to match the valid snake_case format required by the CS. 234 */ 244 235 foreach ( $xml_tree->timeSeries as $site_data ) { 245 236 $cnt = ++$cnt; … … 256 247 } 257 248 $page .= '</tbody></table>'; 258 echo $page; 249 // phpcs:enable 250 echo $page; 259 251 die(); 260 252 } -
usgs-stream-flow-data/trunk/admin/views/admin.php
r1622006 r1876522 1 1 <?php 2 2 /** 3 * The admin view file for plugin 4 * 3 5 * @package USGS Steam Flow Data 4 6 * @author Chris Kindred <[email protected]> … … 7 9 * @copyright 2015 Kindred Web Consulting 8 10 */ 9 ?> 10 <?php 11 if ( !current_user_can( 'manage_options' ) ) { 12 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 11 12 if ( ! current_user_can( 'manage_options' ) ) { 13 wp_die( __( 'You do not have sufficient permissions to access this page.', 'kwc_usgs' ) ); 13 14 } 14 $tabs = array( 'home-settings' => 'Usage', 'search' => 'Search Site Codes', 'credits' => 'Credits' ); 15 $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'home-settings'; 15 16 $usgs_tabs = array( 17 'home-settings' => 'Usage', 18 'search' => 'Search Site Codes', 19 'credits' => 'Credits', 20 ); 21 22 $usgs_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'home-settings'; 16 23 ?> 17 24 <div class="wrap"> 18 19 20 <?php21 foreach( $tabs as $tab => $name ){22 $class = ( $tab == $active_tab ) ? ' nav-tab-active' : '';23 echo "<a class='nav-tab$class' href='?page=kwcusgs&tab=$tab'>$name</a>";24 25 ?>26 27 <?php28 switch ( $active_tab ){29 30 $state_values=array(31 'AL' => "Alabama",32 'AK' => "Alaska",33 'AZ' => "Arizona",34 'AR' => "Arkansas",35 'CA' => "California",36 'CO' => "Colorado",37 'CT' => "Connecticut",38 'DE' => "Delaware",39 'DC' => "District Of Columbia",40 'FL' => "Florida",41 'GA' => "Georgia",42 'HI' => "Hawaii",43 'ID' => "Idaho",44 'IL' => "Illinois",45 'IN' => "Indiana",46 'IA' => "Iowa",47 'KS' => "Kansas",48 'KY' => "Kentucky",49 'LA' => "Louisiana",50 'ME' => "Maine",51 'MD' => "Maryland",52 'MA' => "Massachusetts",53 'MI' => "Michigan",54 'MN' => "Minnesota",55 'MS' => "Mississippi",56 'MO' => "Missouri",57 'MT' => "Montana",58 'NE' => "Nebraska",59 'NV' => "Nevada",60 'NH' => "New Hampshire",61 'NJ' => "New Jersey",62 'NM' => "New Mexico",63 'NY' => "New York",64 'NC' => "North Carolina",65 'ND' => "North Dakota",66 'OH' => "Ohio",67 'OK' => "Oklahoma",68 'OR' => "Oregon",69 'PA' => "Pennsylvania",70 'RI' => "Rhode Island",71 'SC' => "South Carolina",72 'SD' => "South Dakota",73 'TN' => "Tennessee",74 'TX' => "Texas",75 'UT' => "Utah",76 'VT' => "Vermont",77 'VA' => "Virginia",78 'WA' => "Washington",79 'WV' => "West Virginia",80 'WI' => "Wisconsin",81 'WY' => "Wyoming" 82 83 84 85 86 87 88 89 90 91 if ( !empty( $state_values ) ) {92 $blnfirst = true;93 foreach( $state_values as $state_short => $state_full ) {94 if ( true == $blnfirst ){95 echo "<option value='$state_short' SELECTED >$state_full</option>";96 $blnfirst = false;97 98 echo "<option value='$state_short' >$state_full</option>";99 100 101 102 echo "</select>";103 104 <input type='submit' value='<?php _e('Get Stations'); ?>' class='button-secondary' />105 106 107 <?php108 25 <h2><span style="padding-top: 5px;" class="dashicons dashicons-location"></span> <?php echo esc_html( get_admin_page_title() ); ?> </h2><br /> 26 <h2 class="nav-tab-wrapper"> 27 <?php 28 foreach ( $usgs_tabs as $usgs_tab => $name ) { 29 $usgs_class = ( $usgs_tab == $usgs_active_tab ) ? ' nav-tab-active' : ''; 30 echo "<a class='nav-tab$usgs_class' href='?page=kwcusgs&tab=$usgs_tab'>$name</a>"; 31 } 32 ?> 33 </h2> 34 <?php 35 switch ( $usgs_active_tab ) { 36 case 'search': 37 $usgs_state_values = array( 38 'AL' => 'Alabama', 39 'AK' => 'Alaska', 40 'AZ' => 'Arizona', 41 'AR' => 'Arkansas', 42 'CA' => 'California', 43 'CO' => 'Colorado', 44 'CT' => 'Connecticut', 45 'DE' => 'Delaware', 46 'DC' => 'District Of Columbia', 47 'FL' => 'Florida', 48 'GA' => 'Georgia', 49 'HI' => 'Hawaii', 50 'ID' => 'Idaho', 51 'IL' => 'Illinois', 52 'IN' => 'Indiana', 53 'IA' => 'Iowa', 54 'KS' => 'Kansas', 55 'KY' => 'Kentucky', 56 'LA' => 'Louisiana', 57 'ME' => 'Maine', 58 'MD' => 'Maryland', 59 'MA' => 'Massachusetts', 60 'MI' => 'Michigan', 61 'MN' => 'Minnesota', 62 'MS' => 'Mississippi', 63 'MO' => 'Missouri', 64 'MT' => 'Montana', 65 'NE' => 'Nebraska', 66 'NV' => 'Nevada', 67 'NH' => 'New Hampshire', 68 'NJ' => 'New Jersey', 69 'NM' => 'New Mexico', 70 'NY' => 'New York', 71 'NC' => 'North Carolina', 72 'ND' => 'North Dakota', 73 'OH' => 'Ohio', 74 'OK' => 'Oklahoma', 75 'OR' => 'Oregon', 76 'PA' => 'Pennsylvania', 77 'RI' => 'Rhode Island', 78 'SC' => 'South Carolina', 79 'SD' => 'South Dakota', 80 'TN' => 'Tennessee', 81 'TX' => 'Texas', 82 'UT' => 'Utah', 83 'VT' => 'Vermont', 84 'VA' => 'Virginia', 85 'WA' => 'Washington', 86 'WV' => 'West Virginia', 87 'WI' => 'Wisconsin', 88 'WY' => 'Wyoming', 89 ); 90 ?> 91 <h3>Search Site Codes</h3> 92 <p class="">You can search for a site by selecting a state and pressing the 'Get Stations' button. The stations come up in code order directly from USGS. Once you are showing a states stations the easiest way to find the one you are looking for is to use the browswers built in search. The search can take as long as two minutes to contact USGS and bring back the data in some cases.</p> 93 <p class="">Click the Site Name link to go directly to the site on the USGS website.</p> 94 <p class="">Click the Latitude / Longitude link to view the site location in google maps. The location in google maps is an aproximation.</p> 95 <label>Select State:</label> 96 <?php 97 echo "<select id='state' class='state' name='state'>"; 98 if ( ! empty( $usgs_state_values ) ) { 99 $usgs_blnfirst = true; 100 foreach ( $usgs_state_values as $usgs_state_short => $usgs_state_full ) { 101 if ( true == $usgs_blnfirst ) { 102 echo "<option value='$usgs_state_short' SELECTED >$usgs_state_full</option>"; 103 $usgs_blnfirst = false; 104 } else { 105 echo "<option value='$usgs_state_short' >$usgs_state_full</option>"; 106 } 107 } 108 } 109 echo '</select>'; 110 ?> 111 <input type='submit' value='<?php _e( 'Get Stations', 'kwc_usgs' ); ?>' class='button-secondary' /> 112 <br /><br /> 113 <div class="" id="results"></div> 114 <?php 115 break; 109 116 110 case 'home-settings': 111 ?> 112 <h3 class="">Using USGS Steam Flow Data</h3> 113 <p class="">This plugin uses short codes to allow you to include the USGS infromation for a location on any post or in a Text Widget.</p> 114 <p class="">You can copy and paste the shortcode below to get started.</p> 115 <p>[USGS location='09080400' title='Great Place To Fish' graph='show'] </p> 116 <h4 class="">Location</h4> 117 <p>The location is the Site Code for the location you want to show. You can get the Site Code by using the Search tab or by finding it on the USGS website.</p> 118 <h4 class="">Title</h4> 119 <p>The title is what you would like to use as a title for the location information. The title defaults to the Site Name if you leave it blank. </p> 120 <h4 class="">Graph</h4> 121 <p>Graph is for showing graphs with the information (true) or not (false). If you leave Graph blank it will default to false.</p> 122 <?php 123 break; 117 case 'home-settings': 118 ?> 119 <h3 class="">Using USGS Steam Flow Data</h3> 120 <p class="">This plugin uses short codes to allow you to include the USGS infromation for a location on any post or in a Text Widget.</p> 121 <p class="">You can copy and paste the shortcode below to get started.</p> 122 <p> 123 <code>[USGS location='09080400' title='Great Place To Fish' graph='show' /]</code> 124 </p> 125 <h4 class="">Location</h4> 126 <p>The location is the Site Code for the location you want to show. You can get the Site Code by using the Search tab or by finding it on the USGS website.</p> 127 <h4 class="">Title</h4> 128 <p>The title is what you would like to use as a title for the location information. The title defaults to the Site Name if you leave it blank. </p> 129 <h4 class="">Graph</h4> 130 <p>Graph is for showing graphs with the information (true) or not (false). If you leave Graph blank it will default to false.</p> 131 <?php 132 break; 124 133 125 default: 126 ?> 127 <center><a href="https://www.kindredwebconsulting.com/"><img src="<?php echo plugins_url( '../assets/kwc-logo.png', __FILE__ ) ?>" alt="Kindred Web Consulting Logo" border="0" /></a><p>Development by: <a href="https://www.kindredwebconsulting.com">Kindred Web Consulting</a></p></center> 128 <div class="sidebar"> 129 <h2 class="">Support</h2> 130 <p class="">Thanks for using our plugin. We are happy to address any bugs you might find and address suggestions you have by either posting on the plugin page at WordPress.org or through the <a href="https://www.kindredwebconsulting.com/contact-us/">Contact Us</a> on our website.</p> 131 <h2 class="">Donations</h2> 132 <p class="">If you are interested in helping us to add new features and fix bugs please consider donating a few dollars. 133 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> 134 <input type="hidden" name="cmd" value="_s-xclick"> 135 <input type="hidden" name="hosted_button_id" value="BUFMZVZ6L358J"> 136 <table> 137 <tr><td><input type="hidden" name="on0" value="Donation"></td></tr><tr><td><select name="os0"> 138 <option value="Buy Us a Drink">Buy Us a Drink $5.00 USD</option> 139 <option value="Buy Us a Meal">Buy Us a Meal $25.00 USD</option> 140 <option value="Be The Coolest Person We Know">Be The Coolest Person We Know $100.00 USD</option> 141 </select> </td></tr> 142 </table> 143 <input type="hidden" name="currency_code" value="USD"> 144 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> 145 <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> 146 </form></p> 147 <h2 class="">Social Media</h2> 148 <p class=""> 149 <a href="https://www.facebook.com/kindredwebconsulting/" ><img src="<?php echo plugins_url( '../assets/facebook.png', __FILE__ ) ?>" alt="Kindred Web Consulting on Facebook" width="" height="32px" border="" align="" /></a> 150 <a href="https://www.google.com/+KindredWebConsulting"><img src="<?php echo plugins_url( '../assets/google.png', __FILE__ ) ?>" alt="Kindred Web Consulting on Google+" width="" height="32px" border="" align="" /></a> 151 <a href="https://www.kindredwebconsulting.com/"><img src="<?php echo plugins_url( '../assets/kwc.png', __FILE__ ) ?>" alt="Kindred Web Consulting" width="" height="32px" border="" align="" /></a> 152 </p> 153 154 </div> 155 <h2 class="">About the Plugin</h2> 156 <p class="">We are avid fly fishermen. We wanted an easier way to find out what the rivers and streams were flowing at besides to going to the USGS website and looking each one up individually every day. We decided the easiest way would be to write our own plugin to get the data. We hope you enjoy using it and if you have any suggestions please let us know!</p> 157 <p class="">If you would like to receive updates about development and features of USGS Stream Flow Data please <a href="//eepurl.com/JQ68X">click here</a> and enter your email.</p> 158 <h2 class="">USGS</h2> 159 <p class="">We are dependent on the <a href="//www.usgs.gov/water/">USGS website</a> for the data that this plugin uses. They do a good job of notifying developers of any updates. We will quickly update the plugin any time there are updates that effect the API calls.</p> 160 <a href="//www.usgs.gov/water/"><img src="<?php echo plugins_url( '../assets/usgs.jpg', __FILE__ ) ?>" alt="USGS" border="0" height="32px" /></a> 161 <?php 162 break; 163 } 134 default: 135 ?> 136 <center><a href="https://www.kindredwebconsulting.com/"><img src="<?php echo plugins_url( '../assets/kwc-logo.png', __FILE__ ); ?>" alt="Kindred Web Consulting Logo" border="0" /></a><p>Development by: <a href="https://www.kindredwebconsulting.com">Kindred Web Consulting</a></p></center> 137 <div class="sidebar"> 138 <h2 class="">Support</h2> 139 <p class="">Thanks for using our plugin. We are happy to address any bugs you might find and address suggestions you have by either posting on the plugin page at WordPress.org or through the <a href="https://www.kindredwebconsulting.com/contact-us/">Contact Us</a> on our website.</p> 140 <h2 class="">Donations</h2> 141 <p class="">If you are interested in helping us to add new features and fix bugs please consider donating a few dollars. 142 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> 143 <input type="hidden" name="cmd" value="_s-xclick"> 144 <input type="hidden" name="hosted_button_id" value="BUFMZVZ6L358J"> 145 <table> 146 <tr><td><input type="hidden" name="on0" value="Donation"></td></tr><tr><td><select name="os0"> 147 <option value="Buy Us a Meal">Buy Us a Meal $25.00 USD</option> 148 <option value="Buy Us a Drink">Buy Us a Drink $5.00 USD</option> 149 <option value="Be The Coolest Person We Know">Be The Coolest Person We Know $100.00 USD</option> 150 </select></td></tr> 151 </table> 152 <input type="hidden" name="currency_code" value="USD"> 153 <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> 154 <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> 155 </form></p> 156 <h2 class="">Social Media</h2> 157 <p class=""> 158 <a href="https://www.facebook.com/kindredwebconsulting/" ><img src="<?php echo plugins_url( '../assets/facebook.png', __FILE__ ); ?>" alt="Kindred Web Consulting on Facebook" width="" height="32px" border="" align="" /></a> 159 <a href="https://www.google.com/+KindredWebConsulting"><img src="<?php echo plugins_url( '../assets/google.png', __FILE__ ); ?>" alt="Kindred Web Consulting on Google+" width="" height="32px" border="" align="" /></a> 160 <a href="https://www.kindredwebconsulting.com/"><img src="<?php echo plugins_url( '../assets/kwc.png', __FILE__ ); ?>" alt="Kindred Web Consulting" width="" height="32px" border="" align="" /></a> 161 </p> 162 </div> 163 <h2 class="">About the Plugin</h2> 164 <p class="">We are avid fly fishermen. We wanted an easier way to find out what the rivers and streams were flowing at besides to going to the USGS website and looking each one up individually every day. We decided the easiest way would be to write our own plugin to get the data. We hope you enjoy using it and if you have any suggestions please let us know!</p> 165 <p class="">If you would like to receive updates about development and features of USGS Stream Flow Data please <a href="//eepurl.com/JQ68X">click here</a> and enter your email.</p> 166 <h2 class="">USGS</h2> 167 <p class="">We are dependent on the <a href="//www.usgs.gov/water/">USGS website</a> for the data that this plugin uses. They do a good job of notifying developers of any updates. We will quickly update the plugin any time there are updates that effect the API calls.</p> 168 <a href="//www.usgs.gov/water/"><img src="<?php echo plugins_url( '../assets/usgs.jpg', __FILE__ ); ?>" alt="USGS" border="0" height="32px" /></a> 169 <?php 170 break; 171 } 164 172 ?> 165 173 </div> -
usgs-stream-flow-data/trunk/kwcusgs.php
r1850211 r1876522 13 13 * Plugin URI: //wordpress.org/plugins/usgs-stream-flow-data/ 14 14 * Description: USGS Stream Flow Data 15 * Version: 2.6. 315 * Version: 2.6.4 16 16 * Author: Chris Kindred 17 17 * Author URI: //www.kindredwebconsulting.com -
usgs-stream-flow-data/trunk/public/assets/css/public.css
r812236 r1876522 19 19 div .KWC_USGS ul.sitevalues li { 20 20 margin: 0px; 21 padding-left: 14px; 21 padding-left: 14px; 22 22 } 23 23 24 24 div .KWC_USGS a { 25 float: right; 25 float: right; 26 26 } 27 27 -
usgs-stream-flow-data/trunk/public/assets/js/public.js
r1208516 r1876522 1 /** 2 * All of the code for your public-facing JavaScript source 3 * should reside in this file. 4 * 5 * @package USGS Steam Flow Data 6 */ 7 1 8 (function ( $ ) { 2 9 "use strict"; 3 10 4 $(function () { 5 6 7 }); 8 9 }(jQuery)); 11 }( jQuery ) ); -
usgs-stream-flow-data/trunk/public/class-kwc-usgs.php
r1850211 r1876522 1 1 <?php 2 /** 3 * Public 4 * 5 * @package USGS Steam Flow Data 6 * @author Chris Kindred <[email protected]> 7 * @license GPL-2.0+ 8 * @link //www.kindredwebconsulting.com 9 * @copyright 2015 Kindred Web Consulting 10 */ 11 2 12 /** 3 13 * The main class for the plugin 4 14 * 5 15 * @package USGS Steam Flow Data 16 * @subpackage public 6 17 * @author Chris Kindred <[email protected]> 7 18 * @license GPL-2.0+ … … 17 28 * @var string 18 29 */ 19 const VERSION = '2.6. 3';30 const VERSION = '2.6.4'; 20 31 21 32 /** 22 33 * Unique identifier for your plugin. 23 *24 34 * 25 35 * The variable name is used as the text domain when internationalizing strings … … 50 60 private function __construct() { 51 61 52 // Load plugin text domain53 62 add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 54 55 // Activate plugin when new blog is added56 63 add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) ); 57 58 // Load public-facing style sheet and JavaScript.59 64 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 60 65 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 61 62 66 add_shortcode( 'USGS', array( $this, 'USGS' ) ); 63 /* Define custom functionality.64 * Refer To //codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters65 */66 // add_action( '@TODO', array( $this, 'action_method_name' ) );67 // add_filter( '@TODO', array( $this, 'filter_method_name' ) );68 69 67 } 70 68 … … 108 106 */ 109 107 public static function activate( $network_wide ) { 110 111 108 if ( function_exists( 'is_multisite' ) && is_multisite() ) { 112 113 if ( $network_wide ) { 114 115 // Get all blog ids 109 if ( $network_wide ) { 116 110 $blog_ids = self::get_blog_ids(); 117 118 111 foreach ( $blog_ids as $blog_id ) { 119 120 112 switch_to_blog( $blog_id ); 121 113 self::single_activate(); 122 114 } 123 124 115 restore_current_blog(); 125 126 116 } else { 127 117 self::single_activate(); 128 118 } 129 130 119 } else { 131 120 self::single_activate(); 132 121 } 133 134 122 } 135 123 … … 149 137 150 138 if ( $network_wide ) { 151 152 // Get all blog ids153 139 $blog_ids = self::get_blog_ids(); 154 155 140 foreach ( $blog_ids as $blog_id ) { 156 157 141 switch_to_blog( $blog_id ); 158 142 self::single_deactivate(); 159 160 } 161 143 } 162 144 restore_current_blog(); 163 164 145 } else { 165 146 self::single_deactivate(); 166 147 } 167 168 148 } else { 169 149 self::single_deactivate(); 170 150 } 171 172 151 } 173 152 … … 177 156 * @since 1.0.0 178 157 * 179 * @param int 158 * @param int $blog_id ID of the new blog. 180 159 */ 181 160 public function activate_new_site( $blog_id ) { … … 202 181 */ 203 182 private static function get_blog_ids() { 204 205 183 global $wpdb; 206 207 // get an array of blog ids 208 $sql = "SELECT blog_id FROM $wpdb->blogs 209 WHERE archived = '0' AND spam = '0' 210 AND deleted = '0'"; 211 212 return $wpdb->get_col( $sql ); 213 184 return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE archived = %s AND spam = %s AND deleted = %s", array( '0', '0', '0' ) ) ); 214 185 } 215 186 … … 240 211 241 212 $domain = $this->plugin_slug; 242 $locale = apply_filters( ' plugin_locale', get_locale(), $domain );213 $locale = apply_filters( 'kwc_usgs_plugin_locale', get_locale(), $domain ); 243 214 244 215 load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); … … 281 252 * This needs to be split into different functions 282 253 * 283 * @since 1.0.0 284 */ 285 286 public function USGS( $atts, $content = null ) { 287 extract( shortcode_atts( 288 array( 289 'location' => '09080400', 290 'title' => null, 291 'graph' => null 292 ), $atts ) ); 293 294 $thePage = get_transient( 'kwc_usgs-' . $location . $graph . $title ); 295 296 if ( !$thePage ) { 254 * @since 1.0.0 255 */ 256 /** 257 * Undocumented function 258 * 259 * @param array $atts the attributes passed to the shortcode. 260 * @param string $content the content. 261 * @return string the html for the shortcode. 262 */ 263 public function USGS( $atts, $content = null ) { //phpcs:ignore 264 $defaults = array( 265 'location' => '09080400', 266 'title' => null, 267 'graph' => null, 268 ); 269 $atts = shortcode_atts( $defaults, $atts ); 270 $location = $atts['location']; 271 $title = $atts['title']; 272 $graph = $atts['graph']; 273 $the_page = get_transient( 'kwc_usgs-' . $location . $graph . $title ); 274 275 if ( ! $the_page ) { 297 276 $response = $this->get_usgs( $location ); 298 277 299 if ( is_wp_error( $response ) ) {278 if ( is_wp_error( $response ) ) { 300 279 return get_error_message( $response ); 301 280 } … … 308 287 309 288 $xml_tree = simplexml_load_string( $data ); 310 if ( False === $xml_tree ) {289 if ( false === $xml_tree ) { 311 290 return 'Unable to parse USGS\'s XML'; 312 291 } 313 292 314 if ( ! isset( $title ) 315 $ SiteName = $xml_tree->timeSeries->sourceInfo->siteName;293 if ( ! isset( $title ) ) { 294 $site_name = $xml_tree->timeSeries->sourceInfo->siteName; //phpcs:ignore 316 295 } else { 317 if ( $title == '') {318 $ SiteName = $xml_tree->timeSeries->sourceInfo->siteName;296 if ( '' == $title ) { 297 $site_name = $xml_tree->timeSeries->sourceInfo->siteName; //phpcs:ignore 319 298 } else { 320 $ SiteName = $title;321 } 322 } 323 324 $the Page= "<div class='KWC_USGS clearfix'>325 <h3 class='header'>$ SiteName</h3>299 $site_name = $title; 300 } 301 } 302 303 $the_page = "<div class='KWC_USGS clearfix'> 304 <h3 class='header'>$site_name</h3> 326 305 <ul class='sitevalues'>"; 327 $graphflow = "";328 $graphgage = "";329 foreach ( $xml_tree->timeSeries as $site_data ) { 330 if ( $site_data->values->value == '') {306 $graphflow = ''; 307 $graphgage = ''; 308 foreach ( $xml_tree->timeSeries as $site_data ) { //phpcs:ignore 309 if ( '' == $site_data->values->value ) { 331 310 $value = '-'; 332 } else if ( $site_data->values->value == -999999) {333 $value = 'UNKNOWN';311 } elseif ( -999999 == $site_data->values->value ) { 312 $value = 'UNKNOWN'; 334 313 $provisional = '-'; 335 314 } else { 336 315 $desc = $site_data->variable->variableName; 337 316 switch ( $site_data->variable->variableCode ) { 338 case "00010":339 $value= $site_data->values->value;340 $degf = ( 9 / 5 ) * (float)$value + 32;341 $watertemp= $degf;342 $watertempdesc = "° F";343 $thePage.= "<li class='watertemp'>Water Temp: $watertemp $watertempdesc</li>";344 break;345 346 case "00060":347 $splitDesc = explode( ",", $desc );348 $value= $site_data->values->value;349 $streamflow = $value;350 $streamflowdesc = $splitDesc[1];351 $thePage.= "<li class='flow'>Flow: $streamflow $streamflowdesc</li>";352 $graphflow = "<img src='https://waterdata.usgs.gov/nwisweb/graph?agency_cd=USGS&site_no=$location&parm_cd=00060" . "&rand=" . rand() . "'/>";353 break;354 355 case "00065":356 $splitDesc = explode( ",", $desc );357 $value= $site_data->values->value;358 $gageheight= $value;359 $gageheightdesc = $splitDesc[1];360 $thePage.= "<li class='gageheight'>Water Level: $gageheight $gageheightdesc</li>";361 $graphgage = "<img src='https://waterdata.usgs.gov/nwisweb/graph?agency_cd=USGS&site_no=$location&parm_cd=00065" . "&rand=" . rand() . "'/>";362 break;317 case '00010': 318 $value = $site_data->values->value; 319 $degf = ( 9 / 5 ) * (float) $value + 32; 320 $watertemp = $degf; 321 $watertempdesc = '° F'; 322 $the_page .= "<li class='watertemp'>Water Temp: $watertemp $watertempdesc</li>"; 323 break; 324 325 case '00060': 326 $split_desc = explode( ',', $desc ); 327 $value = $site_data->values->value; 328 $streamflow = $value; 329 $streamflowdesc = $split_desc[1]; 330 $the_page .= "<li class='flow'>Flow: $streamflow $streamflowdesc</li>"; 331 $graphflow = "<img src='https://waterdata.usgs.gov/nwisweb/graph?agency_cd=USGS&site_no=$location&parm_cd=00060&rand=" . rand() . "'/>"; 332 break; 333 334 case '00065': 335 $split_desc = explode( ',', $desc ); 336 $value = $site_data->values->value; 337 $gageheight = $value; 338 $gageheightdesc = $split_desc[1]; 339 $the_page .= "<li class='gageheight'>Water Level: $gageheight $gageheightdesc</li>"; 340 $graphgage = "<img src='https://waterdata.usgs.gov/nwisweb/graph?agency_cd=USGS&site_no=$location&parm_cd=00065&rand=" . rand() . "'/>"; 341 break; 363 342 } 364 343 } 365 344 } 366 $the Page .= "</ul>";345 $the_page .= '</ul>'; 367 346 if ( isset( $graph ) ) { 368 if ( $graph == 'show' ) { 369 $thePage .= "<div class='clearfix'>"; 370 $thePage .= $graphgage . $graphflow; 371 $thePage .= "</div>"; 372 } 373 } 374 $thePage .= "<a class='clearfix' href='https://waterdata.usgs.gov/nwis/uv?$location' target='_blank'>USGS</a>"; 375 $thePage .= "</div>"; 376 377 set_transient( 'kwc_usgs-' . $location . $graph . $title, $thePage, 60 * 15 ); 378 } 379 return $thePage; 347 if ( 'show' == $graph ) { 348 $the_page .= "<div class='clearfix'>$graphgage . $graphflow</div>"; 349 } 350 } 351 $the_page .= "<a class='clearfix' href='https://waterdata.usgs.gov/nwis/uv?$location' target='_blank'>USGS</a>"; 352 $the_page .= '</div>'; 353 354 set_transient( 'kwc_usgs-' . $location . $graph . $title, $the_page, 60 * 15 ); 355 } 356 return $the_page; 380 357 } 381 358 … … 383 360 * Makes USGS Call 384 361 * 385 * @param string $location 362 * @param string $location the location to make call with. 386 363 * @return mixed|array|WP_Error 387 364 */ 388 365 public function get_usgs( $location ) { 389 $url = "https://waterservices.usgs.gov/nwis/iv?site=$location¶meterCd=00010,00060,00065&format=waterml";366 $url = "https://waterservices.usgs.gov/nwis/iv?site=$location¶meterCd=00010,00060,00065&format=waterml"; 390 367 $response = wp_remote_get( $url ); 391 368 if ( is_wp_error( $response ) ) { … … 393 370 } 394 371 return array( 395 'response_code' => wp_remote_retrieve_response_code( $response ),372 'response_code' => wp_remote_retrieve_response_code( $response ), 396 373 'response_message' => wp_remote_retrieve_response_message( $response ), 397 'data' => wp_remote_retrieve_body( $response ),374 'data' => wp_remote_retrieve_body( $response ), 398 375 ); 399 376 }
Note: See TracChangeset
for help on using the changeset viewer.