Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: google API key #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions GoogleMapsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}

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

Expand Down
5 changes: 4 additions & 1 deletion fieldtypes/GoogleMaps_AddressFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
5 changes: 3 additions & 2 deletions fieldtypes/GoogleMaps_GoogleMapFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion resources/js/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions services/GoogleMaps_TemplatesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
9 changes: 9 additions & 0 deletions templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ <h2>{{ "Geocoder Settings"|t }}</h2>
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
}) }}