function build_cta_content($selected_cta = null) { $selected_cta ? $selected_cta : ($selected_cta = self::$instance->selected_cta); /* debug information */ if (isset($_GET['debug-cta'])) { echo "<pre>"; print_r($selected_cta); echo "</pre>"; } /* Helper Function to output Template Tokens */ if (isset($_GET['cta-tokens'])) { $template_slug = $selected_cta['templates'][0]['slug']; $token_array = $selected_cta['meta'][0]; $ignore = array('_edit_last', 'wp-cta-selected-template', 'cta_ab_variations', 'wp-cta-variations', 'wp-cta-variation-notes', 'wp-cta-custom-css', 'wp-cta-custom-js', 'wp-cta-link-open-option', '_edit_lock', 'wp_cta_width', 'wp_cta_height'); foreach ($token_array as $key => $value) { $key = str_replace($template_slug . '-', '', $key); $key = str_replace('-0', '', $key); if (!in_array($key, $ignore)) { echo "{{" . $key . "}}<br>"; } } //print_r($token_array); } /* Reveal Variation if Preview */ self::$instance->is_preview ? $display = 'none' : ($display = 'none'); /* Pepare Container Margins if Available */ isset($selected_cta['margin_top']) ? $margin_top : ($margin_top = '0px'); isset($selected_cta['margin_bottom']) ? $margin_botom : ($margin_bottom = '0px'); /* discover the shortest variation height */ foreach ($selected_cta['variations'] as $vid => $variation) { $meta = $selected_cta['meta'][$vid]; if (isset($meta['wp_cta_height-' . $vid]) && is_int($meta['wp_cta_height-' . $vid])) { $heights[] = $meta['wp_cta_height-' . $vid]; } } if (isset($heights)) { asort($heights); $min_height = $heights[0]; } else { $min_height = 'auto;'; } /* build cta container class */ $cta_container_class = "wp_cta_container cta_outer_container"; $cta_container_class = apply_filters('wp_cta_container_class', $cta_container_class, $selected_cta['id']); $cta_template = "<div id='wp_cta_" . $selected_cta['id'] . "_container' class='{$cta_container_class}' style='margin-top:{$margin_top};margin-bottom:{$margin_bottom};position:relative;' >"; /* build cta content */ foreach ($selected_cta['variations'] as $vid => $variation) { $meta = $selected_cta['meta'][$vid]; if (isset($_GET['wp-cta-variation-id']) && $vid != $_GET['wp-cta-variation-id']) { continue; } isset($meta['wp_cta_width-' . $vid]) ? $w = $meta['wp_cta_width-' . $vid] : ($w = 'auto'); isset($meta['wp_cta_height-' . $vid]) ? $h = $meta['wp_cta_height-' . $vid] : ($h = 'auto'); $width = self::$instance->cta_get_correct_dimensions($w, 'width'); $height = self::$instance->cta_get_correct_dimensions($h, 'height'); $template_slug = $selected_cta['meta'][$vid]['wp-cta-selected-template-' . $vid]; $cta_variation_class = "inbound-cta-container wp_cta_content wp_cta_variation wp_cta_" . $selected_cta['id'] . "_variation_" . $vid . ""; $cta_variation_class = apply_filters('wp_cta_variation_class', $cta_variation_class, $selected_cta['id'], $vid); $cta_variation_attributes = apply_filters('wp_cta_variation_attributes', '', $selected_cta['id'], $vid); $cta_template .= "<div id='wp_cta_" . $selected_cta['id'] . "_variation_" . $vid . "' class='" . $cta_variation_class . "' style='display:{$display}; margin:auto;" . $width . $height . "' " . $cta_variation_attributes . " data-variation='" . $vid . "' data-cta-id='" . $selected_cta['id'] . "'>"; $cta_template .= CTA_Render::replace_template_variables($selected_cta, self::$instance->cta_templates[$template_slug]['html-template'], $vid); $cta_template .= "</div>"; } $cta_template .= '</div>'; return $cta_template; }
/** * Creates html of cta variations and sets their visibility to hidden. Javascript will be used to display the correct variation. * @param ARRAY $selected_cta dataset containing meta information on call to action * @returns STRING $cta_template prepared html */ function build_cta_content($selected_cta = null) { $selected_cta ? $selected_cta : ($selected_cta = self::$instance->selected_cta); /* debug information */ if (isset($_GET['debug-cta'])) { echo "<pre>"; print_r($selected_cta); echo "</pre>"; } /* Helper Function to output Template Tokens */ if (isset($_GET['cta-tokens'])) { $template_slug = $selected_cta['templates'][0]['slug']; $token_array = $selected_cta['meta'][0]; $ignore = array('_edit_last', 'wp-cta-selected-template', 'cta_ab_variations', 'wp-cta-variations', 'wp-cta-variation-notes', 'wp-cta-custom-css', 'wp-cta-custom-js', 'wp-cta-link-open-option', '_edit_lock', 'wp_cta_width', 'wp_cta_height'); foreach ($token_array as $key => $value) { $key = str_replace($template_slug . '-', '', $key); $key = str_replace('-0', '', $key); if (!in_array($key, $ignore)) { echo "{{" . $key . "}}<br>"; } } } /* Reveal Variation if Preview */ self::$instance->is_preview ? $display = 'none' : ($display = 'none'); /* Pepare Container Margins if Available */ $margin_top = isset($selected_cta['margin-top']) ? $selected_cta['margin-top'] : '0'; $margin_bottom = isset($selected_cta['margin-bottom']) ? $selected_cta['margin-bottom'] : '0'; /* discover the shortest variation height */ foreach ($selected_cta['variations'] as $vid => $variation) { $meta = $selected_cta['meta'][$vid]; if (isset($meta['wp_cta_height-' . $vid]) && is_int($meta['wp_cta_height-' . $vid])) { $heights[] = $meta['wp_cta_height-' . $vid]; } } /* get the maximum height of all variations and use it as the min height */ if (isset($heights)) { asort($heights); $min_height = $heights[0]; } else { $min_height = 'auto;'; } /* build cta container class */ $cta_container_class = "wp_cta_container cta_outer_container"; $cta_container_class = apply_filters('wp_cta_container_class', $cta_container_class, $selected_cta['id']); /* build cta parent container */ $cta_template = "<div id='wp_cta_" . $selected_cta['id'] . "_container' class='{$cta_container_class}' style='margin-top:{$margin_top}px;margin-bottom:{$margin_bottom}px;position:relative;' >"; /* build cta content */ foreach ($selected_cta['variations'] as $vid => $variation) { /* if cta preview mode is on then skip non-selected variations */ if (isset($_GET['wp-cta-variation-id']) && $vid != $_GET['wp-cta-variation-id']) { continue; } /* get width and height values */ isset($selected_cta['meta'][$vid]['wp_cta_width-' . $vid]) ? $w = $selected_cta['meta'][$vid]['wp_cta_width-' . $vid] : ($w = 'auto'); isset($selected_cta['meta'][$vid]['wp_cta_height-' . $vid]) ? $h = $selected_cta['meta'][$vid]['wp_cta_height-' . $vid] : ($h = 'auto'); /* validate/correct impropper css property value setup */ $width = self::$instance->validate_css_property_value($w, 'width'); $height = self::$instance->validate_css_property_value($h, 'height'); /* add cta width values into array pool for later use */ $width_array[$vid] = $w; self::$instance->cta_width = $width_array; /* add height values into array pool for later use */ $height_array[$vid] = $h; self::$instance->cta_height = $height_array; /* get variation's template slug name */ $template_slug = $selected_cta['meta'][$vid]['wp-cta-selected-template-' . $vid]; /* prepare the variation class */ $cta_variation_class = "inbound-cta-container wp_cta_content wp_cta_variation wp_cta_" . $selected_cta['id'] . "_variation_" . $vid . ""; $cta_variation_class = apply_filters('wp_cta_variation_class', $cta_variation_class, $selected_cta['id'], $vid); /* prepare additional attributes for cta varaition */ $cta_variation_attributes = apply_filters('wp_cta_variation_attributes', '', $selected_cta['id'], $vid); /* Prepare variation HTML container */ $cta_template .= "<div id='wp_cta_" . $selected_cta['id'] . "_variation_" . $vid . "' class='" . $cta_variation_class . "' style='display:{$display}; margin:auto;" . $width . $height . "' " . $cta_variation_attributes . " data-variation='" . $vid . "' data-cta-id='" . $selected_cta['id'] . "'>"; $variation_html = self::$instance->cta_templates[$template_slug]['html-template']; /* Replace common token variables with their value */ $variation_html = CTA_Render::replace_template_variables($selected_cta, $variation_html, $vid); /* replace all internal links with masked tracked links */ $variation_html = CTA_Render::prepare_tracked_links($variation_html, $selected_cta, $vid); $cta_template .= $variation_html; /* close variation container */ $cta_template .= "</div>"; } $cta_template .= '</div>'; return $cta_template; }