Skip to content

Commit

Permalink
fix to CDN (querystring issues) closes bozdoz#35
Browse files Browse the repository at this point in the history
  • Loading branch information
bozdoz committed Aug 14, 2017
1 parent 2e587b3 commit 5ddf05e
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 84 deletions.
96 changes: 96 additions & 0 deletions class.admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
*
* Used to generate an admin for Leaflet Map
*
*/

// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

class Leaflet_Map_Admin {
/**
* @var Leaflet_Map_Admin
**/
private static $instance = null;

/**
* Singleton
* @static
*/
public static function init() {
if ( !self::$instance ) {
self::$instance = new self;
}

return self::$instance;
}

private function __construct () {
add_action('admin_init', array($this, 'admin_init'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_enqueue_scripts', array('Leaflet_Map', 'enqueue_and_register'));

/* add settings to plugin page */
add_filter('plugin_action_links_' . plugin_basename(LEAFLET_MAP__PLUGIN_FILE), array($this, 'plugin_action_links'));
}

/**
* Admin init registers styles
*
*/

public function admin_init () {
wp_register_style('leaflet_admin_stylesheet', plugins_url('style.css', LEAFLET_MAP__PLUGIN_FILE));
}

/**
* 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', LEAFLET_MAP__PLUGIN_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"));
}

/**
* 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', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false);

include 'templates/shortcode-helper.php';
}

/**
* Add settings link to the plugin on Installed Plugins page
*
*/
public function plugin_action_links ( $links ) {
$links[] = '<a href="'. esc_url( get_admin_url(null, 'admin.php?page=leaflet-map') ) .'">Settings</a>';
return $links;
}
}
97 changes: 20 additions & 77 deletions class.leaflet-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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');
Expand All @@ -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[] = '<a href="'. esc_url( get_admin_url(null, 'admin.php?page=leaflet-map') ) .'">Settings</a>';
return $links;
wp_enqueue_script('leaflet_map_construct', plugins_url('scripts/construct-leaflet-map.js', __FILE__), Array(), self::$version, false);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions class.plugin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion leaflet-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion shortcodes/class.marker-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
}
<?php
Expand Down
1 change: 0 additions & 1 deletion shortcodes/class.shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static function getClass () {
public static function shortcode ($atts, $content = null) {
$class = self::getClass();
$instance = new $class($atts, $content);

return $instance->getHTML($atts, $content);
}

Expand Down

0 comments on commit 5ddf05e

Please sign in to comment.