From bc3b484300dabf9092196005dea4f7b087e47026 Mon Sep 17 00:00:00 2001 From: Ramil Valitov Date: Tue, 13 Mar 2018 00:34:42 +0300 Subject: [PATCH] [fix] improved Google API key code #72 --- map_ex/assets/maps.js | 2 +- map_ex/plugin.php | 32 ++++++++++++++++++++++++++++++++ map_ex/views/widget.php | 19 ------------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/map_ex/assets/maps.js b/map_ex/assets/maps.js index 64a9d7c..4af7fba 100644 --- a/map_ex/assets/maps.js +++ b/map_ex/assets/maps.js @@ -43,7 +43,7 @@ if (!String.prototype.endsWith) { t.getMarkerClusterer().extend(r, google.maps.OverlayView), this.styles_ = e, this.padding_ = i || 0, this.cluster_ = t, this.center_ = null, this.map_ = t.getMap(), this.div_ = null, this.sums_ = null, this.visible_ = false, this.setMap(this.map_) } var s, o = function() { - return s || (s = t.Deferred(), window.wkInitializeGoogleMapsEx = s.resolve,t.getScript("//maps.google.com/maps/api/js?callback=wkInitializeGoogleMapsEx"+((mapexGoogleApiKey)?("&key="+mapexGoogleApiKey):""))), s.promise() + return s || (s = t.Deferred(), window.wkInitializeGoogleMapsEx = s.resolve,t.getScript("//maps.google.com/maps/api/js?callback=wkInitializeGoogleMapsEx&key="+(window.GOOGLE_MAPS_API_KEY||window.mapexGoogleApiKey||"") )), s.promise() }; t(function() { t('script[type="widgetkit/mapex"]').each(function() { diff --git a/map_ex/plugin.php b/map_ex/plugin.php index 0a6b586..5115246 100644 --- a/map_ex/plugin.php +++ b/map_ex/plugin.php @@ -147,12 +147,44 @@ 'init.site' => function($event, $app) { $uikit=(WidgetkitExMapPlugin::getCSSPrefix($app)=='uk') ? 'uikit' : 'uikit2'; + + //Adding native key from Widgetkit + $key = $app['config']->get('googlemapseapikey'); + $key = ($key && strlen($key) > 0) ? filter_var(trim($key), FILTER_SANITIZE_URL) : ""; + if ($key === false) + $key=""; + $app['scripts']->add('googlemapsapi', 'GOOGLE_MAPS_API_KEY = "' . $key . '";', array(), 'string'); + + //Adding key from MapEx settings + $plugin = new WidgetkitExMapPlugin($app); + $global_settings = $plugin->readGlobalSettings(); + $key = (isset($global_settings['apikey'])) ? filter_var(trim($global_settings['apikey']), FILTER_SANITIZE_URL) : ""; + if ($key === false) + $key = ""; + $app['scripts']->add('widgetkit-map-ex-google-key', 'mapexGoogleApiKey = "' . $key . '";', array(), 'string'); + $app['scripts']->add('widgetkit-map-ex', 'plugins/widgets/map_ex/assets/maps.js', array($uikit)); }, 'init.admin' => function($event, $app) { $plugin=new WidgetkitExMapPlugin($app); $uikit=(WidgetkitExMapPlugin::getCSSPrefix($app)=='uk') ? 'uikit' : 'uikit2'; + + //Adding native key from Widgetkit + $key = $app['config']->get('googlemapseapikey'); + $key = ($key && strlen($key) > 0) ? filter_var(trim($key), FILTER_SANITIZE_URL) : ""; + if ($key === false) + $key=""; + $app['scripts']->add('googlemapsapi', 'GOOGLE_MAPS_API_KEY = "' . $key . '";', array(), 'string'); + + //Adding key from MapEx settings + $plugin = new WidgetkitExMapPlugin($app); + $global_settings = $plugin->readGlobalSettings(); + $key = (isset($global_settings['apikey'])) ? filter_var(trim($global_settings['apikey']), FILTER_SANITIZE_URL) : ""; + if ($key === false) + $key = ""; + $app['scripts']->add('widgetkit-map-ex-google-key', 'mapexGoogleApiKey = "' . $key . '";', array(), 'string'); + //Backend CSS $app['styles']->add('map_ex_edit', 'plugins/widgets/map_ex/css/mapex.edit.css', array('widgetkit-application')); //Adding our own translations: diff --git a/map_ex/views/widget.php b/map_ex/views/widget.php index 99ab538..8192f2d 100644 --- a/map_ex/views/widget.php +++ b/map_ex/views/widget.php @@ -211,25 +211,6 @@