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

Hide map if no API key #446

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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
16 changes: 12 additions & 4 deletions crouton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: A tabbed based display for showing meeting information.
Author: bmlt-enabled
Author URI: https://bmlt.app
Version: 3.17.4
Version: 3.17.5
*/
/* Disallow direct access to the plugin file */
if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
Expand Down Expand Up @@ -354,6 +354,9 @@ public function bmltHandlebar($atts, $template = null)
}
public function croutonMap($atts, $content = null)
{
if (isset($_GET['meeting-id'])) {
return do_shortcode($this->getDefaultMeetingDetailsPageContents());
}
return sprintf('%s<div id="bmlt-tabs" class="bmlt-tabs hide">%s</div>', $this->sharedRender(), $this->renderMap($atts));
}
private function getMapInitialization($mapConfig)
Expand All @@ -368,7 +371,7 @@ private function getMapInitialization($mapConfig)
isset($config['language']) ? substr($config['language'], 0, 2) : 'en',
"croutonMap",
$this->options['meeting_details_href']
);
).';';
}
}
return $externalMap;
Expand All @@ -378,7 +381,7 @@ private function getInitializeCroutonBlock($config, $mapConfig)
if (!$this->croutonBlockInitialized) {
$this->croutonBlockInitialized = true;
$externalMap = $this->getMapInitialization($mapConfig);
return "<script type='text/javascript'>var crouton;jQuery(document).ready(function() { $externalMap; crouton = new Crouton($config); });</script>";
return "<script type='text/javascript'>var crouton;jQuery(document).ready(function() { $externalMap crouton = new Crouton($config); });</script>";
} else {
return isset($config) ? "<script type='text/javascript'>jQuery(document).ready(function() { crouton.setConfig($config); });</script>" : "";
}
Expand Down Expand Up @@ -466,7 +469,7 @@ public function handlebarFooter()
var crouton;

jQuery(document).ready(function() {
<?php echo $externalMap; ?>; crouton = new Crouton(<?php echo $config; ?>);
<?php echo $externalMap; ?> crouton = new Crouton(<?php echo $config; ?>);
crouton.doHandlebars();
});
</script>
Expand Down Expand Up @@ -1104,6 +1107,10 @@ private function getCroutonJsConfig($atts)
$params['meetingpage_contents_template'] = $this->templateToParameter('meetingpage_contents_template');

$mapParams['google_api_key'] = $this->options['google_api_key'];
$params['missing_api_key'] = 0;
if (empty($this->options['google_api_key']) && !has_filter("crouton_map_create_control")) {
$params['missing_api_key'] = 1;
}
$mapParams['template_path'] = $params['template_path'];
$extra_meetings_array = [];
if (isset($this->options['extra_meetings']) && !isset($_GET['meeting-id'])) {
Expand All @@ -1121,6 +1128,7 @@ private function getCroutonJsConfig($atts)
$this->options['meeting_details_href'] = $params['meeting_details_href'];

$params['force_rootserver_in_querystring'] = ($params['root_server'] !== $this->options['root_server']);

$params = apply_filters('crouton_configuration', $params);
$mapParams['theme'] = $params['theme'];

Expand Down
5 changes: 5 additions & 0 deletions croutonjs/src/js/crouton-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function Crouton(config) {
force_timeformat_in_querystring: true, // Set to false to shorten generated meeting detail query strings
force_language_in_querystring: true, // Set to false to shorten generated meeting detail query strings
theme: "jack", // Allows for setting pre-packaged themes. Choices are listed here: https://github.com/bmlt-enabled/crouton/blob/master/croutonjs/dist/templates/themes
missing_api_key: false, // Hide map is google not configured
meeting_data_template: croutonDefaultTemplates.meeting_data_template,
metadata_template: croutonDefaultTemplates.metadata_template,
observer_template: croutonDefaultTemplates.observer_template,
Expand Down Expand Up @@ -903,6 +904,10 @@ Crouton.prototype.doHandlebars = function() {
if (brothers) firstPart.after(...brothers);
}
if (mustDoMap) {
if (self.config.missing_api_key) {
jQuery("#bmlt-map").parent().remove();
return;
}
self.meetingData = enrichedMeetingData;
croutonMap.initialize(self.createBmltMapElement(),self.meetingData, self.formatsData, self.handlebarMapOptions);
jQuery("#bmlt-map").removeClass("hide");
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: na, meeting list, meeting finder, maps, recovery, addiction, webservant, b
Requires at least: 4.0
Required PHP: 5.6
Tested up to: 6.2.2
Stable tag: 3.17.4
Stable tag: 3.17.5
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
crouton implements a Tabbed UI for BMLT.
Expand Down Expand Up @@ -36,6 +36,10 @@ https://demo.bmlt.app/crouton

== Changelog ==

= 3.17.5 =
* hide meeting-details map if google maps but no api key
* meeting details on crouton_map pages, too

= 3.17.4 =
* bug fix release

Expand Down