diff --git a/crouton.php b/crouton.php index 50ef149..1eba0f8 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.20.4 +Version: 3.20.5 */ /* Disallow direct access to the plugin file */ if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) { @@ -24,9 +24,7 @@ class Crouton * @var mixed[] */ public $options = array(); - public $croutonBlockInitialized = false; public static $HOUR_IN_SECONDS = 3600; - public $has_handlebars = false; public $themes = [ "asheboro", "florida-nights", @@ -51,12 +49,10 @@ class Crouton 'timeout' => 60 ); // crouton includes a map, we need to include the JS files and create the croutonMap object. - private $hasMap = false; public $shortCodeOptions = array( "root_server" => '', "service_body" => '', "service_body_parent" => '', - "jsInFooter" => true, "venue_types" => '', "formats" => '', "has_tabs" => '1', @@ -130,7 +126,6 @@ class Crouton "filter_visible", "has_common_needs" ]; - private $waitMsg = '
'; private MeetingMap\Controller $meetingMapController; public function __construct() { @@ -146,19 +141,19 @@ public function __construct() add_action("wp_enqueue_scripts", array(&$this, "enqueueFrontendFiles")); add_shortcode('init_crouton', array( &$this, - "initCrouton" + "blank" )); add_shortcode('bmlt_tabs', array( &$this, - "tabbedUi" + "replaceShortcodeWithStandardTags" )); add_shortcode('crouton_map', array( &$this, - "croutonMap" + "replaceShortcodeWithStandardTags" )); add_shortcode('bmlt_map', array( &$this, - "meetingMap" + "replaceShortcodeWithStandardTags" )); add_shortcode('bmlt_count', array( &$this, @@ -182,26 +177,55 @@ public function __construct() )); } } - - private function hasShortcode() + /** + * + * @return string + */ + private function croutonInitializationScript() { $post_to_check = get_post(get_the_ID()); $post_content = $post_to_check->post_content ?? ''; - $tags = ['bmlt_tabs', 'bmlt_map', 'crouton_map', 'bmlt_count', 'meeting_count', 'group_count', 'service_body_names', 'bmlt_handlebar']; + $tags = ['bmlt_tabs', 'bmlt_map', 'crouton_map', 'bmlt_handlebar']; preg_match_all('/' . get_shortcode_regex($tags) . '/', $post_content, $matches, PREG_SET_ORDER); if (empty($matches)) { - return false; + return ''; } foreach ($matches as $shortcode) { - if ($shortcode[2] === 'bmlt_handlebar' || - $shortcode[2] === 'bmlt_tabs' || - $shortcode[2] === 'crouton_map' || - $shortcode[2] === 'bmlt_map') { - $this->hasMap = true; + if (isset($_GET['meeting-id'])) { + $shortcode[2] = 'bmlt_handlebar'; + $shortcode[3] = ''; + } + switch ($shortcode[2]) { + case 'bmlt_tabs': + $script = $this->renderTable(wp_parse_args($shortcode[3])); + break; + case 'init_crouton': + $script = $this->initCrouton(wp_parse_args($shortcode[3])); + break; + case 'crouton_map': + $script = $this->renderMap(wp_parse_args($shortcode[3])); + break; + case 'bmlt_map': + $atts = wp_parse_args($shortcode[3]); + if (is_array($atts)) { + $atts['has_venues'] = '0'; + } else { + $atts = ["has_venues" => "0"]; + } + $script = $this->renderMap($atts, false); + break; + case 'bmlt_handlebar': + $script = $this->handlebarFooterScript(); + break; + default: + $script = ''; + break; + } + if ($script != '') { + return $script; } } - return true; } @@ -245,7 +269,8 @@ public function enqueueBackendFiles($hook) */ public function enqueueFrontendFiles() { - if ($this->hasShortcode()) { + $script = $this->croutonInitializationScript(); + if ($script !== '') { wp_enqueue_style("croutoncss", plugin_dir_url(__FILE__) . "croutonjs/dist/crouton-core.min.css", false, filemtime(plugin_dir_path(__FILE__) . "croutonjs/dist/crouton-core.min.css"), false); if (isset($_GET['croutonjsdebug'])) { wp_enqueue_script("croutonnocorejs", plugin_dir_url(__FILE__) . "croutonjs/dist/crouton-nocore.js", array('jquery'), filemtime(plugin_dir_path(__FILE__) . "croutonjs/dist/crouton-nocore.js"), true); @@ -254,6 +279,7 @@ public function enqueueFrontendFiles() wp_enqueue_script("croutonjs", plugin_dir_url(__FILE__) . "croutonjs/dist/crouton-core.min.js", array('jquery'), filemtime(plugin_dir_path(__FILE__) . "croutonjs/dist/crouton-core.min.js"), true); } $this->meetingMapController->enqueueFrontendFiles(); + wp_add_inline_script("croutonjs", $script); } } @@ -294,10 +320,9 @@ private function testRootServer($root_server) return ''; } - - private function sharedRender() + private function outputTag() { - $output = ""; + $output = ''; if (isset($_GET['this_title'])) { $output .= '