From 5ddf05e8d95672a53764904b8dfc45ec84502ebf Mon Sep 17 00:00:00 2001 From: bozdoz Date: Mon, 14 Aug 2017 03:15:45 -0300 Subject: [PATCH] fix to CDN (querystring issues) closes #35 --- class.admin.php | 96 ++++++++++++++++++++++++++ class.leaflet-map.php | 97 ++++++--------------------- class.plugin-settings.php | 3 +- leaflet-map.php | 2 +- readme.txt | 11 ++- shortcodes/class.marker-shortcode.php | 1 - shortcodes/class.shortcode.php | 1 - 7 files changed, 127 insertions(+), 84 deletions(-) create mode 100644 class.admin.php diff --git a/class.admin.php b/class.admin.php new file mode 100644 index 0000000..0e26057 --- /dev/null +++ b/class.admin.php @@ -0,0 +1,96 @@ +Settings'; + return $links; + } +} \ No newline at end of file diff --git a/class.leaflet-map.php b/class.leaflet-map.php index cb2c5e4..5769391 100644 --- a/class.leaflet-map.php +++ b/class.leaflet-map.php @@ -8,11 +8,18 @@ class Leaflet_Map { + /** + * Version of this plugin + * Used for asset file cache-busting + * @var string major minor patch version + */ + public static $version = '2.8.4'; + /** * Leaflet version * @var string major minor patch version */ - public $leaflet_version = '1.2.0'; + public static $leaflet_version = '1.2.0'; /** * Number of maps on page; used for unique map ids @@ -88,6 +95,8 @@ private function __construct() { private function includes() { // Leaflet_Map_Plugin_Settings include_once(LEAFLET_MAP__PLUGIN_DIR . 'class.plugin-settings.php'); + // Leaflet_Map_Admin + include_once(LEAFLET_MAP__PLUGIN_DIR . 'class.admin.php'); } /** @@ -97,15 +106,10 @@ private function includes() { */ private function init_hooks() { - // get these details above - add_action('admin_init', array($this, 'admin_init')); - add_action('admin_menu', array($this, 'admin_menu')); - add_action('admin_enqueue_scripts', array($this, 'enqueue_and_register')); - - /* add settings to plugin page */ - add_filter('plugin_action_links_' . plugin_basename(LEAFLET_MAP__PLUGIN_FILE), array($this, 'plugin_action_links')); + // init admin + Leaflet_Map_Admin::init(); - add_action( 'wp_enqueue_scripts', array($this, 'enqueue_and_register') ); + add_action( 'wp_enqueue_scripts', array('Leaflet_Map', 'enqueue_and_register') ); /* allows maps on excerpts @@ -151,15 +155,15 @@ public static function uninstall () { * */ - public function enqueue_and_register () { + public static function enqueue_and_register () { /* defaults from db */ $settings = Leaflet_Map_Plugin_Settings::init(); $js_url = $settings->get('js_url'); $css_url = $settings->get('css_url'); - wp_register_style('leaflet_stylesheet', $css_url, Array(), $this->leaflet_version, false); - wp_register_script('leaflet_js', $js_url, Array(), $this->leaflet_version, true); + wp_register_style('leaflet_stylesheet', $css_url, Array(), null, false); + wp_register_script('leaflet_js', $js_url, Array(), null, true); // new required MapQuest javascript file $tiling_service = $settings->get('default_tiling_service'); @@ -173,75 +177,14 @@ public function enqueue_and_register () { } // optional ajax geojson plugin - wp_register_script('leaflet_ajax_geojson_js', plugins_url('scripts/leaflet-ajax-geojson.js', __FILE__), Array('leaflet_js',), '1.0', false); + wp_register_script('leaflet_ajax_geojson_js', plugins_url('scripts/leaflet-ajax-geojson.js', __FILE__), Array('leaflet_js',), self::$version, false); - wp_register_script('tmcw_togeojson', 'https://cdn.rawgit.com/mapbox/togeojson/master/togeojson.js', Array('jquery'), '1.0', false); + wp_register_script('tmcw_togeojson', 'https://cdn.rawgit.com/mapbox/togeojson/master/togeojson.js', Array('jquery'), self::$version, false); - wp_register_script('leaflet_ajax_kml_js', plugins_url('scripts/leaflet-ajax-kml.js', __FILE__), Array('tmcw_togeojson', 'leaflet_js', 'leaflet_ajax_geojson_js'), '1.0', false); + wp_register_script('leaflet_ajax_kml_js', plugins_url('scripts/leaflet-ajax-kml.js', __FILE__), Array('tmcw_togeojson', 'leaflet_js', 'leaflet_ajax_geojson_js'), self::$version, false); /* run a construct function in the document head for subsequent functions to use (it is lightweight) */ - wp_enqueue_script('leaflet_map_construct', plugins_url('scripts/construct-leaflet-map.js', __FILE__), Array(), '1.0', false); - } - - /** - * Admin init registers styles - * - * todo: candidate for separate class - * - */ - - public function admin_init () { - wp_register_style('leaflet_admin_stylesheet', plugins_url('style.css', __FILE__)); - } - - /** - * Main settings page includes form inputs - * - */ - - public function settings_page () { - wp_enqueue_style( 'leaflet_admin_stylesheet' ); - - $settings = Leaflet_Map_Plugin_Settings::init(); - $plugin_data = get_plugin_data(LEAFLET_MAP__PLUGIN_FILE); - include 'templates/settings.php'; - } - - /** - * Shortcode page shows example shortcodes and an interactive generator - * - */ - public function shortcode_page () { - wp_enqueue_style( 'leaflet_admin_stylesheet' ); - wp_enqueue_script('custom_plugin_js', plugins_url('scripts/get-shortcode.js', __FILE__), Array('leaflet_js'), false); - - include 'templates/shortcode-helper.php'; - } - - /** - * Add admin menu page when user in admin area - * - */ - - public function admin_menu () { - if (current_user_can('manage_options')) { - $main_link = 'leaflet-map'; - } else { - $main_link = 'leaflet-get-shortcode'; - } - - add_menu_page("Leaflet Map", "Leaflet Map", 'manage_options', $main_link, array($this, "settings_page"), plugins_url('images/leaf.png', __FILE__)); - add_submenu_page("leaflet-map", "Default Values", "Default Values", 'manage_options', "leaflet-map", array($this, "settings_page")); - add_submenu_page("leaflet-map", "Shortcode Helper", "Shortcode Helper", 'edit_posts', "leaflet-get-shortcode", array($this, "shortcode_page")); - } - - /** - * Add settings link to the plugin on Installed Plugins page - * - */ - public function plugin_action_links ( $links ) { - $links[] = 'Settings'; - return $links; + wp_enqueue_script('leaflet_map_construct', plugins_url('scripts/construct-leaflet-map.js', __FILE__), Array(), self::$version, false); } /** diff --git a/class.plugin-settings.php b/class.plugin-settings.php index 58f1cee..2990e3c 100644 --- a/class.plugin-settings.php +++ b/class.plugin-settings.php @@ -153,8 +153,7 @@ public static function init() { private function __construct () { /* update leaflet version from main class */ - $LM = Leaflet_Map::init(); - $leaflet_version = $LM->leaflet_version; + $leaflet_version = Leaflet_Map::$leaflet_version; $this->options['js_url']['default'] = sprintf($this->options['js_url']['default'], $leaflet_version); $this->options['css_url']['default'] = sprintf($this->options['css_url']['default'], $leaflet_version); diff --git a/leaflet-map.php b/leaflet-map.php index 521d9d8..0f7cdd8 100644 --- a/leaflet-map.php +++ b/leaflet-map.php @@ -5,7 +5,7 @@ Description: A plugin for creating a Leaflet JS map with a shortcode. Boasts two free map tile services and three free geocoders. Author: bozdoz Author URI: https://twitter.com/bozdoz/ - Version: 2.8.3 + Version: 2.8.4 License: GPL2 Leaflet Map is free software: you can redistribute it and/or modify diff --git a/readme.txt b/readme.txt index 6e8565c..844777c 100644 --- a/readme.txt +++ b/readme.txt @@ -7,8 +7,8 @@ Donate link: https://www.paypal.me/bozdoz Tags: leaflet, map, mobile, javascript, openstreetmap, mapquest, interactive Requires at least: 3.0.1 Tested up to: 4.8.1 -Version: 2.8.3 -Stable tag: 2.8.3 +Version: 2.8.4 +Stable tag: 2.8.4 License: GPLv2 License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -120,6 +120,10 @@ Yes: use the keyword `attribution` in your shortcode (semi-colon separated list == Changelog == += 2.8.4 = +* Fixed issues with css and js CDN; removed version from querystring +* Split admin into new class + = 2.8.3 = * Fix to [leaflet-kml] * Standardized `src` in leaflet-image and leaflet-geojson/kml @@ -250,6 +254,9 @@ Yes: use the keyword `attribution` in your shortcode (semi-colon separated list == Upgrade Notice == += 2.8.4 = +Fixed issues with css and js CDN; removed version from querystring + = 2.8.3 = Fixed issues with leaflet-kml diff --git a/shortcodes/class.marker-shortcode.php b/shortcodes/class.marker-shortcode.php index 188374f..dca0636 100644 --- a/shortcodes/class.marker-shortcode.php +++ b/shortcodes/class.marker-shortcode.php @@ -108,7 +108,6 @@ protected function getHTML ($atts, $content) { if (!is_image) { marker.setLatLng( previous_map.getCenter() ); } else { - console.warn("hello"); marker.setLatLng( [0, 0] ); } getHTML($atts, $content); }