From a6707b732741ed2ff23c62f49b67aa4fc6075bee Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:10:56 +0200 Subject: [PATCH 01/15] use wp_add_inline_script --- crouton.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crouton.php b/crouton.php index 846a7cb..387da4d 100644 --- a/crouton.php +++ b/crouton.php @@ -304,14 +304,18 @@ private function sharedRender() return $output; } - + private function inlineScript($s) + { + wp_add_inline_script('croutonjs', $s); + } public function tabbedUi($atts, $content = null) { $this->hasMap = true; if (isset($_GET['meeting-id'])) { return do_shortcode($this->getDefaultMeetingDetailsPageContents()); } - return $this->waitMsg.sprintf('%s
', $this->sharedRender(), $this->renderTable($atts)); + $this->inlineScript($this->renderTable($atts)); + return $this->waitMsg.sprintf('%s', $this->sharedRender()); } public function bmltHandlebar($atts, $template = null) { @@ -338,7 +342,8 @@ public function croutonMap($atts, $content = null) if (isset($_GET['meeting-id'])) { return do_shortcode($this->getDefaultMeetingDetailsPageContents()); } - return sprintf('%s ', $this->sharedRender(), $this->renderMap($atts)); + $this->inlineScript($this->renderMap($atts)); + return sprintf('%s', $this->sharedRender()); } public function meetingMap($atts, $content = null) { @@ -351,7 +356,8 @@ public function meetingMap($atts, $content = null) } else { $atts = ["has_venues" => "0"]; } - return sprintf('%s ', $this->sharedRender(), $this->renderMap($atts, false)); + $this->inlineScript($this->renderMap($atts, false)); + return sprintf('%s ', $this->sharedRender()); } private function getMapInitialization($mapConfig) { From fac513715d66a141aea192d8d8598d4a6fc53761 Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:13:28 +0200 Subject: [PATCH 02/15] version bump --- crouton.php | 2 +- readme.txt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crouton.php b/crouton.php index 387da4d..f81a2a2 100644 --- a/crouton.php +++ b/crouton.php @@ -5,7 +5,7 @@ Description: A tabbed based display for showing meeting information. Author: bmlt-enabled Author URI: https://bmlt.app -Version: 3.19.4 +Version: 3.19.5 */ /* Disallow direct access to the plugin file */ if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) { diff --git a/readme.txt b/readme.txt index 9fba6073..9988c2b 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: na, meeting list, meeting finder, maps, recovery, addiction, webservant, b Requires at least: 4.0 Required PHP: 8.0 Tested up to: 6.4.2 -Stable tag: 3.19.4 +Stable tag: 3.19.5 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html crouton implements a Tabbed UI for BMLT. @@ -36,6 +36,9 @@ https://demo.bmlt.app/crouton == Changelog == += 3.19.5 = +* Add script that configures crouton to footer, rather than the body + = 3.19.4 = * Bug fix From 43e5e7c3ec46f0a7e7f89384b1d7a1cb7a6f7dd8 Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:21:55 +0200 Subject: [PATCH 03/15] handle handlebars, too --- crouton.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/crouton.php b/crouton.php index f81a2a2..74f8837 100644 --- a/crouton.php +++ b/crouton.php @@ -331,7 +331,7 @@ public function bmltHandlebar($atts, $template = null) } } if (!$this->has_handlebars) { - add_action("wp_footer", [$this,'handlebarFooter']); + $this->handlebarFooter(); } $this->has_handlebars = true; return sprintf(' ', htmlspecialchars($template)); @@ -443,16 +443,9 @@ public function handlebarFooter() 'strict_datafields' => false]; [$config, $mapConfig] = $this->getCroutonJsConfig($attr); $croutonMap = $this->getMapInitialization($mapConfig); - ?> - - inlineScript($ret); } /** * @desc Adds the options sub-panel From 2470b3b63a2a60c0012647b59d46306a16a0e8ff Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:46:49 +0200 Subject: [PATCH 04/15] refactor map js config --- crouton.php | 7 ++-- croutonjs/meetingMap/meeting_map.php | 61 ++++++++++++---------------- 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/crouton.php b/crouton.php index 74f8837..101b62e 100644 --- a/crouton.php +++ b/crouton.php @@ -1039,13 +1039,12 @@ private function getAllFields($root_server) private function templateToParameter($atts, $name) { if (isset($atts[$name]) && $atts[$name] !== null && $atts[$name] !== "") { - $template = $atts[$name]; + return $atts[$name]; } elseif (isset($this->options[$name])) { - $template = $this->options[$name]; + return $this->options[$name]; } else { - $template = ""; + return ""; } - return html_entity_decode($template); } private function getAllMeetings($root_server) { diff --git a/croutonjs/meetingMap/meeting_map.php b/croutonjs/meetingMap/meeting_map.php index a6cee1b..5598aab 100644 --- a/croutonjs/meetingMap/meeting_map.php +++ b/croutonjs/meetingMap/meeting_map.php @@ -188,48 +188,39 @@ private function hsc($field) } private function createJavascriptConfig($options) { - $ret = '{'; + $ret = []; //$ret .= 'BMLTPlugin_files_uri:\''.$this->hsc($this->getPluginPath()).'?\',' . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= "BMLTPlugin_images:'".$this->hsc(plugin_dir_url(__FILE__)."map_images")."'," . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= "BMLTPlugin_lang_dir:'".$this->hsc(plugin_dir_url(__FILE__)."lang")."'," . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= "BMLTPlugin_throbber_img_src:'".$this->hsc(plugin_dir_url(__FILE__)."map_images/Throbber.gif")."'," . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= 'region:"'.$options['region_bias'].'",'; - $ret .= 'bounds:{'; - $ret .= ' "north": "'.$options['bounds_north'].'",'; - $ret .= ' "east": "'.$options['bounds_east'].'",'; - $ret .= ' "south": "'.$options['bounds_south'].'",'; - $ret .= ' "west": "'.$options['bounds_west'].'"'; - $ret .= '},'; - $ret .= 'tileUrl:"'.$options['tile_url'].'",'; - $ret .= 'clustering:"'.$options['clustering'].'",'; - $ret .= 'nominatimUrl:"'.$options['nominatim_url'].'",'; - $ret .= 'tileOptions:{'; - foreach ($options['tile_params'] as $key => $value) { - $ret .= " '".$key."': '".$value."',"; - } - $ret .= '},'; - $ret .= 'api_key:"'.$options['api_key'].'",'; - $ret .= 'lat:"'.$options['lat'].'",'; - $ret .= 'lng:"'.$options['lng'].'",'; - $ret .= 'zoom:"'.$options['zoom'].'",'; - $ret .= 'minZoom:"'.$options['min_zoom'].'",'; - $ret .= 'maxZoom:"'.$options['max_zoom'].'",'; + $ret["BMLTPlugin_images"] = $this->hsc(plugin_dir_url(__FILE__)."map_images"); + $ret["BMLTPlugin_lang_dir"] = $this->hsc(plugin_dir_url(__FILE__)."lang"); + $ret["BMLTPlugin_throbber_img_src"] = $this->hsc(plugin_dir_url(__FILE__)."map_images/Throbber.gif"); + $ret['region'] = $options['region_bias']; + $ret['bounds'] = [ + "north" => $options['bounds_north'], + "east" => $options['bounds_east'], + "south" => $options['bounds_south'], + "west" => $options['bounds_west'] + ]; + $ret['tileUrl'] = $options['tile_url']; + $ret['clustering'] = $options['clustering']; + $ret['nominatimUrl'] = $options['nominatim_url']; + $ret['tileOptions'] = $options['tile_params']; + $ret['api_key'] = $options['api_key']; + $ret['lat'] = $options['lat']; + $ret['lng'] = $options['lng']; + $ret['zoom'] = $options['zoom']; + $ret['minZoom'] = $options['min_zoom']; + $ret['maxZoom'] = $options['max_zoom']; if (!empty($options['center_me'])) { - $ret .= 'centerMe:"'.$options['center_me'].'",'; + $ret['centerMe'] = $options['center_me']; } if (!empty($options['goto'])) { - $ret .= 'goto:"'.$options['goto'].'",'; + $ret['goto'] = $options['goto']; } if (isset($options['map_search'])) { - $ret .= 'map_search: {'; - foreach ($options['map_search'] as $key => $value) { - $ret .= $key.':"'.$value.'",'; - } - $ret .= '},'; + $ret['map_search'] = $options['map_search']; } - $ret .= '"marker_contents_template":'.json_encode($options['marker_contents_template']); - $ret .= '},'; - return $ret; + $ret["marker_contents_template"] = $options['marker_contents_template']; + return json_encode($ret); } public function adminSection() { From 157e7b973496fa7cc35cde0f5639abe340afab01 Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 2 Sep 2024 15:56:15 +0200 Subject: [PATCH 05/15] small fix for goto in query string --- crouton.php | 2 +- croutonjs/meetingMap/js/meeting_map.js | 2 +- js/bmlt_tabs_admin.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crouton.php b/crouton.php index 101b62e..0f54763 100644 --- a/crouton.php +++ b/crouton.php @@ -357,7 +357,7 @@ public function meetingMap($atts, $content = null) $atts = ["has_venues" => "0"]; } $this->inlineScript($this->renderMap($atts, false)); - return sprintf('%s ', $this->sharedRender()); + return sprintf('%s', $this->sharedRender()); } private function getMapInitialization($mapConfig) { diff --git a/croutonjs/meetingMap/js/meeting_map.js b/croutonjs/meetingMap/js/meeting_map.js index f384bbd..349c55b 100644 --- a/croutonjs/meetingMap/js/meeting_map.js +++ b/croutonjs/meetingMap/js/meeting_map.js @@ -303,7 +303,7 @@ function MeetingMap(inConfig) { showGeocodingDialog(); } } else if (config.goto) { - gDelegate.callGeocoder(goto, filterMeetingsAndBounds); + gDelegate.callGeocoder(config.goto, filterMeetingsAndBounds); } } function createCityHash(allMeetings) { diff --git a/js/bmlt_tabs_admin.js b/js/bmlt_tabs_admin.js index 6dc49eb..aea8a12 100644 --- a/js/bmlt_tabs_admin.js +++ b/js/bmlt_tabs_admin.js @@ -36,7 +36,6 @@ function numbersonly(myfield, e, dec) return false; }; function resetCodemirrorToDefault(textAreaId) { - console.log("in Function"); let cm = jQuery('#'+textAreaId).next()[0].CodeMirror; cm.setValue(croutonDefaultTemplates[textAreaId]); } From 520f223d9d08dc421fdd73086c7050f95f83848c Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 9 Sep 2024 10:31:04 +0200 Subject: [PATCH 06/15] goto in query overrides centerMe --- croutonjs/meetingMap/meeting_map.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/croutonjs/meetingMap/meeting_map.php b/croutonjs/meetingMap/meeting_map.php index 5598aab..314b667 100644 --- a/croutonjs/meetingMap/meeting_map.php +++ b/croutonjs/meetingMap/meeting_map.php @@ -215,6 +215,9 @@ private function createJavascriptConfig($options) } if (!empty($options['goto'])) { $ret['goto'] = $options['goto']; + if (isset($_GET['goto'])) { + $ret['centerMe'] = ''; + } } if (isset($options['map_search'])) { $ret['map_search'] = $options['map_search']; From 194e339845f544f7f22525a65948fae05e013c00 Mon Sep 17 00:00:00 2001 From: otrok7 <50595291+otrok7@users.noreply.github.com> Date: Mon, 9 Sep 2024 23:54:42 +0200 Subject: [PATCH 07/15] Checkbox controls where to place JS --- crouton.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/crouton.php b/crouton.php index 0f54763..cdffeaf 100644 --- a/crouton.php +++ b/crouton.php @@ -56,6 +56,7 @@ class Crouton "root_server" => '', "service_body" => '', "service_body_parent" => '', + "jsInFooter" => true, "venue_types" => '', "formats" => '', "has_tabs" => '1', @@ -308,14 +309,21 @@ private function inlineScript($s) { wp_add_inline_script('croutonjs', $s); } + private function outputScript($s) + { + if ($this->options['jsInFooter']) { + wp_add_inline_script('croutonjs', $s); + $s = ""; + } + return $this->waitMsg.sprintf('%s ', $this->sharedRender(), $s); + } public function tabbedUi($atts, $content = null) { $this->hasMap = true; if (isset($_GET['meeting-id'])) { return do_shortcode($this->getDefaultMeetingDetailsPageContents()); } - $this->inlineScript($this->renderTable($atts)); - return $this->waitMsg.sprintf('%s', $this->sharedRender()); + return $this->outputScript($this->renderTable($atts)); } public function bmltHandlebar($atts, $template = null) { @@ -342,8 +350,7 @@ public function croutonMap($atts, $content = null) if (isset($_GET['meeting-id'])) { return do_shortcode($this->getDefaultMeetingDetailsPageContents()); } - $this->inlineScript($this->renderMap($atts)); - return sprintf('%s', $this->sharedRender()); + return $this->outputScript($this->renderMap($atts)); } public function meetingMap($atts, $content = null) { @@ -356,8 +363,7 @@ public function meetingMap($atts, $content = null) } else { $atts = ["has_venues" => "0"]; } - $this->inlineScript($this->renderMap($atts, false)); - return sprintf('%s', $this->sharedRender()); + return $this->outputScript($this->renderMap($atts, false)); } private function getMapInitialization($mapConfig) { @@ -510,6 +516,7 @@ public function adminOptionsPage() } $this->options['root_server'] = $_POST['root_server']; $this->options['service_body_1'] = $_POST['service_body_1']; + $this->options['jsInFooter'] = $_POST['jsInFooter']; $this->options['time_format'] = $_POST['time_format']; $this->options['language'] = $_POST['language']; $this->options['strict_datafields'] = isset($_POST['strict_datafields']); @@ -568,6 +575,9 @@ public function adminOptionsPage() } else { $this->options['extra_meetings_enabled'] = 1; } + if (!isset($this->options['jsInFooter'])) { + $this->options['jsInFooter'] = true; + } ?>