From af9ef241ffb2554bc23d0c7d763ff3bc40584d72 Mon Sep 17 00:00:00 2001 From: christianruhstaller Date: Fri, 1 Jul 2016 11:16:00 +0200 Subject: [PATCH 1/4] fix: google API key --- GoogleMapsPlugin.php | 2 +- fieldtypes/GoogleMaps_GoogleMapFieldType.php | 5 +++-- services/GoogleMaps_TemplatesService.php | 5 +++-- templates/settings.html | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/GoogleMapsPlugin.php b/GoogleMapsPlugin.php index ca2f13c..6f1a448 100644 --- a/GoogleMapsPlugin.php +++ b/GoogleMapsPlugin.php @@ -30,7 +30,7 @@ protected function defineSettings() 'geocodeSections' => array(AttributeType::Mixed, 'label' => 'Geocode Sections', 'default' => array()), 'geocodeFields' => array(AttributeType::String, 'label' => 'Geocode Fields'), 'mapFields' => array(AttributeType::Mixed, 'label' => 'Google Maps Fields', 'default' => array()), - //'apiKey' => array(AttributeType::String, 'required' => true, 'label' => 'API Key'), + 'apiKey' => array(AttributeType::String, 'required' => true, 'label' => 'API Key'), ); } diff --git a/fieldtypes/GoogleMaps_GoogleMapFieldType.php b/fieldtypes/GoogleMaps_GoogleMapFieldType.php index 1ba003a..eb562fa 100644 --- a/fieldtypes/GoogleMaps_GoogleMapFieldType.php +++ b/fieldtypes/GoogleMaps_GoogleMapFieldType.php @@ -234,11 +234,12 @@ public function getInputHtml($name, $value) // Figure out what that ID is going to look like once it has been namespaced $namespacedId = craft()->templates->namespaceInputId($id); - // craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?sensor=false'); + $pluginSettings = craft()->plugins->getPlugin('GoogleMaps')->getSettings(); + $key = $pluginSettings->apiKey; craft()->templates->includeJsResource('googlemaps/js/app.compiled.js'); craft()->templates->includeCssResource('googlemaps/css/app.css'); - craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?key=&sensor=false&callback=GoogleMaps.init'); + craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?key='.$key.'&sensor=false&callback=GoogleMaps.init'); $addressFields = $this->getSettings()->addressFields; diff --git a/services/GoogleMaps_TemplatesService.php b/services/GoogleMaps_TemplatesService.php index 8909ad5..6f43831 100644 --- a/services/GoogleMaps_TemplatesService.php +++ b/services/GoogleMaps_TemplatesService.php @@ -14,9 +14,10 @@ public function scripts() $protocol = 'http://'; } - $key = craft()->config->get('key', 'googlemaps'); + $pluginSettings = craft()->plugins->getPlugin('GoogleMaps')->getSettings(); + $key = $pluginSettings->apiKey; - craft()->templates->includeJsFile($protocol . 'maps.google.com/maps/api/js?sensor=true&libraries=geometry'.($key ? 'key='.$key : '')); + craft()->templates->includeJsFile($protocol . 'maps.google.com/maps/api/js?sensor=true&libraries=geometry'.($key ? '&key='.$key : '')); craft()->templates->includeJsResource('googlemaps/js/vendor/base.js'); craft()->templates->includeJsResource('googlemaps/js/vendor/underscore.js'); craft()->templates->includeJsResource('googlemaps/js/vendor/markerclusterer.js'); diff --git a/templates/settings.html b/templates/settings.html index 8a54955..5978fab 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -41,4 +41,13 @@

{{ "Geocoder Settings"|t }}

name: 'geocodeFields', value: settings.geocodeFields, rows: 10 +}) }} + +{{ forms.textField({ +label: "API Key"|t, +instructions: "Enter the Google API Key."|t, +id: 'apiKey', +name: 'apiKey', +value: settings.apiKey, +required: true }) }} \ No newline at end of file From 372ad8f94c1471cfaa3715b626a3b0e8fe6e3a29 Mon Sep 17 00:00:00 2001 From: christianruhstaller Date: Thu, 15 Dec 2016 18:05:06 +0100 Subject: [PATCH 2/4] Mixed Content being loaded over https --- resources/js/templates.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/templates.js b/resources/js/templates.js index 61efebe..0b0ab3a 100644 --- a/resources/js/templates.js +++ b/resources/js/templates.js @@ -920,7 +920,7 @@ function program5(depth0,data,depth1) { function program7(depth0,data) { - return "http://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-poi.png&scale=2"; + return "https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-poi.png&scale=2"; } function program9(depth0,data) { From 8973f5d47a8e24f1fb9a0628d0c52ce1c937bd49 Mon Sep 17 00:00:00 2001 From: Christian Ruhstaller Date: Tue, 4 Apr 2017 14:25:42 +0200 Subject: [PATCH 3/4] Fix: add Google API key to address fieldtype --- fieldtypes/GoogleMaps_AddressFieldType.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fieldtypes/GoogleMaps_AddressFieldType.php b/fieldtypes/GoogleMaps_AddressFieldType.php index 30e3160..fd38951 100644 --- a/fieldtypes/GoogleMaps_AddressFieldType.php +++ b/fieldtypes/GoogleMaps_AddressFieldType.php @@ -64,12 +64,15 @@ public function getInputHtml($name, $value) { $id = craft()->templates->formatInputId($name); + $pluginSettings = craft()->plugins->getPlugin('GoogleMaps')->getSettings(); + $key = $pluginSettings->apiKey; + // Figure out what that ID is going to look like once it has been namespaced $namespacedId = craft()->templates->namespaceInputId($id); craft()->templates->includeJsResource('googlemaps/js/app.compiled.js'); craft()->templates->includeCssResource('googlemaps/css/app.css'); - craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?key=&sensor=false&callback=GoogleMaps.init'); + craft()->templates->includeJsFile('//maps.googleapis.com/maps/api/js?key='.$key.'&sensor=false&callback=GoogleMaps.init'); craft()->templates->includeJs(" var data = ['#$namespacedId-field .oh-google-map-wrapper', { From a6033f99ee5f4b6134b65e98382e389082d8790c Mon Sep 17 00:00:00 2001 From: Christian Ruhstaller Date: Thu, 21 Sep 2017 09:16:16 +0200 Subject: [PATCH 4/4] Fix error when no Geocode Sections are set --- GoogleMapsPlugin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GoogleMapsPlugin.php b/GoogleMapsPlugin.php index 6f1a448..21eade2 100644 --- a/GoogleMapsPlugin.php +++ b/GoogleMapsPlugin.php @@ -81,9 +81,10 @@ public function init() { $entry = $event->params['entry']; $content = $entry->getContent(); + $geocodeSettings = is_array($settings->geocodeSections) ? $settings->geocodeSections : []; // If section being saved matches a section set in the geocode settings - if(in_array($entry->sectionId, $settings->geocodeSections)) + if(in_array($entry->sectionId, $geocodeSettings)) { $address = array();