Skip to content

Commit

Permalink
[fix] improved Google API key code #72
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalitov committed Mar 12, 2018
1 parent bcff790 commit bc3b484
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion map_ex/assets/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
32 changes: 32 additions & 0 deletions map_ex/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 0 additions & 19 deletions map_ex/views/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,6 @@

<!--suppress Annotator, JSUnresolvedFunction, UnnecessaryReturnStatementJS -->
<script>
<?php
if ($debug->isWKAPIKeySupported($app)) {
/** @noinspection PhpUndefinedMethodInspection */
$gapikey = $app['config']->get('googlemapseapikey');
if (!$gapikey)
$gapikey = "";
} else {
if (!isset($global_settings['apikey']))
$global_settings['apikey'] = "";
else
$global_settings['apikey'] = trim($global_settings['apikey']);
$gapikey = $global_settings['apikey'];
}
$gapikey = filter_var($gapikey, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
if ($gapikey === false)
$gapikey = "";
echo 'var mapexGoogleApiKey=mapexGoogleApiKey || "' . $gapikey . '";';
?>

function getMapZoom<?php echo $map_id2;?>(){
if (window.outerWidth<=767) {
var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation || null;
Expand Down

0 comments on commit bc3b484

Please sign in to comment.