Plugin Directory

Changeset 1572919


Ignore:
Timestamp:
01/11/2017 11:19:29 PM (9 years ago)
Author:
laubsterboy
Message:

Fixed compatibility with Google Maps

Location:
national-weather-service-alerts/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • national-weather-service-alerts/trunk/classes/class-nws-alerts-admin.php

    r1118148 r1572919  
    234234
    235235    public static function add_settings_page() {
    236         $controls = array();
     236        $alerts_bar_controls = array();
     237        $google_maps_controls = array();
    237238
    238239        if (!empty($_POST)) {
     
    242243                $control = 'error';
    243244                $key = $prefix . $control;
    244                 $controls[$control] = false;
     245                $alerts_bar_controls[$control] = false;
    245246
    246247                $control = 'zip';
     
    248249                if (isset($_POST[$key])) {
    249250                    update_option($key, $_POST[$key]);
    250                     $controls[$control] = $_POST[$key];
     251                    $alerts_bar_controls[$control] = $_POST[$key];
    251252                }
    252253
     
    255256                if (isset($_POST[$key])) {
    256257                    update_option($key, $_POST[$key]);
    257                     $controls[$control] = $_POST[$key];
     258                    $alerts_bar_controls[$control] = $_POST[$key];
    258259                }
    259260
     
    262263                if (isset($_POST[$key])) {
    263264                    update_option($key, $_POST[$key]);
    264                     $controls[$control] = $_POST[$key];
     265                    $alerts_bar_controls[$control] = $_POST[$key];
    265266                }
    266267
     
    269270                if (isset($_POST[$key])) {
    270271                    update_option($key, $_POST[$key]);
    271                     $controls[$control] = $_POST[$key];
     272                    $alerts_bar_controls[$control] = $_POST[$key];
    272273                }
    273274
     
    276277                if (isset($_POST[$key])) {
    277278                    update_option($key, $_POST[$key]);
    278                     $controls[$control] = $_POST[$key];
     279                    $alerts_bar_controls[$control] = $_POST[$key];
    279280                }
    280281
     
    283284                if (isset($_POST[$key])) {
    284285                    update_option($key, $_POST[$key]);
    285                     $controls[$control] = $_POST[$key];
     286                    $alerts_bar_controls[$control] = $_POST[$key];
    286287                }
    287288
     
    290291                if (isset($_POST[$key])) {
    291292                    update_option($key, $_POST[$key]);
    292                     $controls[$control] = $_POST[$key];
     293                    $alerts_bar_controls[$control] = $_POST[$key];
    293294                }
    294295
     
    297298                if (isset($_POST[$key]) && $_POST[$key] == 'on') {
    298299                    update_option($key, 1);
    299                     $controls[$control] = true;
     300                    $alerts_bar_controls[$control] = true;
    300301                } else {
    301302                    update_option($key, 0);
    302                     $controls[$control] = false;
     303                    $alerts_bar_controls[$control] = false;
    303304                }
    304305
     
    307308                $allow_enabled = false;
    308309
    309                 if (isset($controls['zip']) && !empty($controls['zip'])) $allow_enabled = true;
    310                 if (isset($controls['city']) && !empty($controls['city']) && isset($controls['state']) && !empty($controls['state'])) $allow_enabled = true;
    311                 if (isset($controls['state']) && !empty($controls['state']) && isset($controls['county']) && !empty($controls['county'])) $allow_enabled = true;
     310                if (isset($alerts_bar_controls['zip']) && !empty($alerts_bar_controls['zip'])) $allow_enabled = true;
     311                if (isset($alerts_bar_controls['city']) && !empty($alerts_bar_controls['city']) && isset($alerts_bar_controls['state']) && !empty($alerts_bar_controls['state'])) $allow_enabled = true;
     312                if (isset($alerts_bar_controls['state']) && !empty($alerts_bar_controls['state']) && isset($alerts_bar_controls['county']) && !empty($alerts_bar_controls['county'])) $allow_enabled = true;
    312313
    313314                if ($allow_enabled && isset($_POST[$key]) && $_POST[$key] == 'on') {
    314315                    update_option($key, 1);
    315                     $controls[$control] = true;
     316                    $alerts_bar_controls[$control] = true;
    316317                } else {
    317318                    if (isset($_POST[$key]) && $_POST[$key] == 'on') {
    318                         $controls['error'] = 'Not enough location information was provided to enable the Alerts Bar';
     319                        $alerts_bar_controls['error'] = 'Not enough location information was provided to enable the Alerts Bar';
    319320                    }
    320321
    321322                    update_option($key, 0);
    322                     $controls[$control] = false;
     323                    $alerts_bar_controls[$control] = false;
     324                }
     325            }
     326
     327            if (isset($_POST['nws_alerts_google_maps_action']) && $_POST['nws_alerts_google_maps_action'] === 'update' && check_admin_referer('update', 'nws_alerts_google_maps_nonce')) {
     328                $prefix = 'nws_alerts_google_maps_';
     329
     330                $control = 'api_key';
     331                $key = $prefix . $control;
     332                if (isset($_POST[$key])) {
     333                    update_option($key, $_POST[$key]);
     334                    $google_maps_controls[$control] = $_POST[$key];
    323335                }
    324336            }
     
    329341        echo '<h2>National Weather Service Alerts</h2>';
    330342
    331         echo self::get_module('build-tables', $controls);
    332         echo self::get_module('alerts-bar', $controls);
     343        echo self::get_module('build-tables', array());
     344        echo self::get_module('google-maps', $google_maps_controls);
     345        echo self::get_module('alerts-bar', $alerts_bar_controls);
    333346
    334347        echo '</div>';
     
    519532                            }
    520533
    521                         $return_value .= '</tbody>'; 
    522                     $return_value .= '</table>'; 
     534                        $return_value .= '</tbody>';
     535                    $return_value .= '</table>';
    523536
    524537                    $return_value .= '<input type="submit" value="Save Changes" class="button button-primary" id="' . $control_id_prefix . '-submit" name="' . str_replace('-', '_', $control_id_prefix) . '-submit">';
    525538
    526                 $return_value .= '</form>'; 
    527             $return_value .= '</div>'; 
    528             $return_value .= '</div>'; 
     539                $return_value .= '</form>';
     540            $return_value .= '</div>';
     541            $return_value .= '</div>';
    529542        } else if ($module === 'build-tables') {
    530543            $return_value = '';
     
    545558                    $return_value .= '<p class="description">The NWS Alerts plugin database tables are fully setup and the plugin is ready to be used.</p>';
    546559                }
     560            $return_value .= '</div>';
     561            $return_value .= '</div>';
     562        } else if ($module === 'google-maps') {
     563            $defaults = array('api_key' => NWS_ALERTS_GOOGLE_MAPS_API_KEY);
     564            $controls = wp_parse_args($controls, $defaults);
     565            $return_value = '';
     566            $module_id_prefix = 'nws-alerts';
     567            $control_id_prefix = $module_id_prefix . '-' . $module;
     568
     569            $return_value .= '<div class="metabox-holder"><div class="meta-box-sortables ui-sortable"><div class="postbox"><h3 class="hndle"><span>Google Maps</span></h3>';
     570            $return_value .= '<div class="inside">';
     571                $return_value .= '<p class="description">The Google Maps JavaScript API now requires an API key in order to display maps on websites. Due to the map API quota limits this API key cannot be included with the plugin and a unique key must be obtained by you.</p>';
     572                $return_value .= '<p class="description">You can obtain a Google Maps JavaScript API key by visiting the <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">Get a Key/Authentication</a> page and following the instructions. Once a project has been created and an associated key has been generated, simply copy it and paste it into the "Google Maps API Key" field below.</p>';
     573                $return_value .= '<form id="' . $control_id_prefix . '" method="post" action="">';
     574
     575                    $return_value .= self::get_control('action', $control_id_prefix);
     576                    $return_value .= self::get_control('nonce', $control_id_prefix);
     577
     578                    $return_value .= '<table>';
     579                        $return_value .= '<tbody>';
     580
     581                            foreach($controls as $control => $default) {
     582                                $return_value .= self::get_control($control, $control_id_prefix, $default);
     583                            }
     584
     585                        $return_value .= '</tbody>';
     586                    $return_value .= '</table>';
     587
     588                    $return_value .= '<input type="submit" value="Save Changes" class="button button-primary" id="' . $control_id_prefix . '-submit" name="' . str_replace('-', '_', $control_id_prefix) . '-submit">';
     589
     590                $return_value .= '</form>';
    547591            $return_value .= '</div>';
    548592            $return_value .= '</div>';
     
    572616            if ($default === false) { $default = 'update'; }
    573617            $return_value .= wp_nonce_field($default, str_replace('-', '_', $control_id_prefix . '_' . $control), true, false);
     618        } else if ($control === 'api_key') {
     619            if ($default) { $default = ' value="' . $default . '"'; } else { $default = ''; }
     620            $return_value .= '<tr>';
     621                $return_value .= '<td><h4>Google Maps API Key</h4></td>';
     622                $return_value .= '<td>';
     623                    $return_value .= '<div class="nws-alerts-control-text-container">';
     624                        $return_value .= '<input data-control-parent="' . $control . '" data-control="' . $control . '" id="' . $control_id_prefix . '-' . $control . '" name="' . str_replace('-', '_', $control_id_prefix . '_' . $control) . '" type="text"' . $default . ' />';
     625                    $return_value .= '</div>';
     626                $return_value .= '</td>';
     627            $return_value .= '</tr>';
    574628        } else if ($control === 'error') {
    575629            if ($default === false) return;
  • national-weather-service-alerts/trunk/classes/class-nws-alerts-client.php

    r1118148 r1572919  
    7676        /* JavaScript */
    7777        wp_enqueue_script('nws-alerts-js', NWS_ALERTS_URL . 'js/nws-alerts.js', array('jquery'), null, true);
    78         wp_enqueue_script('google-map-api', 'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=weather&sensor=false', false, null, false);
     78
     79        if (!empty(NWS_ALERTS_GOOGLE_MAPS_API_KEY)) {
     80            wp_enqueue_script('google-map-api', 'https://maps.googleapis.com/maps/api/js?key=' . NWS_ALERTS_GOOGLE_MAPS_API_KEY . '&v=3.exp&libraries=weather', false, null, false);
     81        }
    7982    }
    8083
  • national-weather-service-alerts/trunk/nws-alerts-globals.php

    r1451950 r1572919  
    2020define('NWS_ALERTS_ABSPATH', plugin_dir_path(__FILE__));
    2121define('NWS_ALERTS_URL', plugins_url('/', __FILE__));
     22
     23define('NWS_ALERTS_GOOGLE_MAPS_API_KEY', get_option('nws_alerts_google_maps_api_key'));
    2224
    2325define('NWS_ALERTS_BAR_ENABLED', filter_var(get_option('nws_alerts_alerts_bar_enabled'), FILTER_VALIDATE_BOOLEAN));
  • national-weather-service-alerts/trunk/nws-alerts.php

    r1451950 r1572919  
    44* Plugin URI: https://github.com/laubsterboy/nws-alerts
    55* Description: Easily add official National Weather Service alerts to your website.
    6 * Version: 1.3.2
     6* Version: 1.3.3
    77* Author: John Russell
    88* Author URI: http://www.laubsterboy.com
  • national-weather-service-alerts/trunk/readme.txt

    r1451950 r1572919  
    44Tags: National Weather Service, NWS, Storm Prediction Center, SPC, Alert, Weather, Storm, Severe, Tornado, Thunder, Flood
    55Requires at least: 3.1
    6 Tested up to: 4.5
    7 Stable tag: 1.3.2
     6Tested up to: 4.7
     7Stable tag: 1.3.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    108108== Changelog ==
    109109
     110= 1.3.3 =
     111* Fixed: The alerts map now requires a Google Maps JavaScript API key, so a new setting was added to the NWS Alerts settings page.
     112
    110113= 1.3.2 =
    111114* Improvement: The wp_remote_get function is now used to request National Weather Service CAP data. This will use WordPress core HTTP functions and classes and improves server compatibility.
     
    155158== Upgrade Notice ==
    156159
     160= 1.3.3 =
     161* Fixed: The maps are working again as long as a Google Maps JavaScript API key is provided.
     162
    157163= 1.3.2 =
    158164* Standardized the method used to request National Weather Service alert data.
  • national-weather-service-alerts/trunk/templates/template-map.php

    r1118148 r1572919  
    1111*/
    1212
     13if (!empty(NWS_ALERTS_GOOGLE_MAPS_API_KEY)) {
    1314$return_value = '
    1415    <script type="text/javascript">
     
    3233    </script>
    3334    <section id="nws-alerts-map-' . $this->zip . $this->scope . '" class="nws-alerts-map"></section>';
     35}
    3436
    3537?>
Note: See TracChangeset for help on using the changeset viewer.