/**
         * Prints / Returns Custom JS & CSS Related to Call to Action
         */
        public static function load_custom_js_css($selected_cta = null, $return = false)
        {
            global $post;
            $inline_content = "";
            $selected_cta ? $selected_cta : ($selected_cta = self::$instance->selected_cta);
            if (!isset($selected_cta['id'])) {
                return;
            }
            foreach ($selected_cta['variations'] as $vid => $variation) {
                /* account for preview mode */
                if (isset($_GET['wp-cta-variation-id']) && $vid != $_GET['wp-cta-variation-id']) {
                    continue;
                }
                $meta = $selected_cta['meta'][$vid];
                $template_slug = $selected_cta['meta'][$vid]['wp-cta-selected-template-' . $vid];
                $custom_css = CTA_Variations::get_variation_custom_css($selected_cta['id'], $vid);
                $dynamic_css = self::$instance->cta_templates[$template_slug]['css-template'];
                $dynamic_css = self::$instance->replace_template_variables($selected_cta, $dynamic_css, $vid);
                $css_id_preface = "#wp_cta_" . $selected_cta['id'] . "_variation_" . $vid;
                $dynamic_css = str_replace("{{", "", $dynamic_css);
                $dynamic_css = str_replace("}}", "", $dynamic_css);
                $dynamic_css = self::$instance->parse_css_template($dynamic_css, $css_id_preface);
                $css_styleblock_class = apply_filters('wp_cta_styleblock_class', '', $selected_cta['id'], $vid);
                $custom_css = strip_tags($custom_css, '<style>');
                /* If style.css exists in root cta directory, insert here */
                $slug = $selected_cta['templates'][$vid]['slug'];
                $has_style = WP_CTA_PATH . 'templates/' . $slug . '/style.css';
                $has_style_url = WP_CTA_URLPATH . 'templates/' . $slug . '/style.css';
                if (file_exists($has_style)) {
                    $inline_content .= '<link rel="stylesheet" href="' . $has_style_url . '">';
                }
                /* Print Cusom CSS */
                $inline_content .= '<style type="text/css" id="wp_cta_css_custom_' . $selected_cta['id'] . '_' . $vid . '" class="wp_cta_css_' . $selected_cta['id'] . ' ' . $css_styleblock_class . '">' . $custom_css . ' ' . $dynamic_css . '</style>';
                $custom_js = CTA_Variations::get_variation_custom_js($selected_cta['id'], $vid);
                if (!stristr($custom_css, '<script')) {
                    $inline_content .= '<script type="text/javascript">jQuery(document).ready(function($) {
					' . $custom_js . ' });</script>';
                } else {
                    $inline_content .= $custom_js;
                }
            }
            if ($return) {
                return $inline_content;
            } else {
                echo $inline_content;
            }
        }
Esempio n. 2
0
        /**
         * Prints / Returns Custom JS & CSS Related to Call to Action
         */
        public static function load_custom_js_css($selected_cta = null, $return = false)
        {
            global $post;
            $inline_content = "";
            $selected_cta ? $selected_cta : ($selected_cta = self::$instance->selected_cta);
            if (!isset($selected_cta['id'])) {
                return;
            }
            foreach ($selected_cta['variations'] as $vid => $variation) {
                /* account for preview mode */
                if (isset($_GET['wp-cta-variation-id']) && $vid != $_GET['wp-cta-variation-id']) {
                    continue;
                }
                $meta = $selected_cta['meta'][$vid];
                $vid < 1 ? $suffix = '' : ($suffix = '-' . $vid);
                $template_slug = $selected_cta['meta'][$vid]['wp-cta-selected-template-' . $vid];
                $custom_css = CTA_Variations::get_variation_custom_css($selected_cta['id'], $vid);
                /* This is printing CTA CSS Twice on Preview Mode */
                /* We may reserve this function only for custom css and custom js */
                $dynamic_css = self::$instance->cta_templates[$template_slug]['css-template'];
                $dynamic_css = self::$instance->replace_template_variables($selected_cta, $dynamic_css, $vid);
                $css_id_preface = "#wp_cta_" . $selected_cta['id'] . "_variation_" . $vid;
                $dynamic_css = str_replace("{{", "", $dynamic_css);
                $dynamic_css = str_replace("}}", "", $dynamic_css);
                $dynamic_css = self::$instance->parse_css_template($dynamic_css, $css_id_preface);
                /****** New Parse - DO NOT DELTE *******/
                // http://regexr.com/?36e6v
                // http://regex101.com/r/rF9iR9
                /* IN PROGRESS */
                /*
                				$css = explode("}", $dynamic_css);
                				$pattern = "/.-?[_a-zA-Z]+[_a-zA-Z0-9-]*(?=[^}]*\{)/"; // close. matches all ids and classes but separates
                				//$pattern = "/(?![^{]*})(#\S+)\b/";
                				preg_match_all($pattern, $dynamic_css, $match_css);
                				print_r($match_css[0]);
                				$matched_css_names = $match_css[0];
                				foreach ($matched_css_names as $key => $value) {
                
                					if (!preg_match("/:/", $value)){
                						echo $value . "<br>";
                					}
                				}
                
                				echo "<pre>";
                				print_r($css);
                				echo "</pre>"; /**/
                /****** End New Parse - DO NOT DELTE *******/
                $css_styleblock_class = apply_filters('wp_cta_styleblock_class', '', $selected_cta['id'], $vid);
                if (!stristr($custom_css, '<style')) {
                    $custom_css = strip_tags($custom_css);
                }
                /* If style.css exists in root cta directory, insert here */
                $slug = $selected_cta['templates'][$vid]['slug'];
                $has_style = WP_CTA_PATH . 'templates/' . $slug . '/style.css';
                $has_style_url = WP_CTA_URLPATH . 'templates/' . $slug . '/style.css';
                if (file_exists($has_style)) {
                    $inline_content .= '<link rel="stylesheet" href="' . $has_style_url . '">';
                }
                /* Print Cusom CSS */
                $inline_content .= '<style type="text/css" id="wp_cta_css_custom_' . $selected_cta['id'] . '_' . $vid . '" class="wp_cta_css_' . $selected_cta['id'] . ' ' . $css_styleblock_class . '">' . $custom_css . ' ' . $dynamic_css . '</style>';
                $custom_js = get_post_meta($selected_cta['id'], 'wp-cta-custom-js' . $suffix, true);
                if (!stristr($custom_css, '<script')) {
                    $inline_content .= '<script type="text/javascript" id="wp_cta_js_custom">jQuery(document).ready(function($) {
					' . $custom_js . ' });</script>';
                } else {
                    $inline_content .= $custom_js;
                }
            }
            if ($return) {
                return $inline_content;
            } else {
                echo $inline_content;
            }
        }
 public static function show_custom_css()
 {
     global $post;
     echo "<em>Custom CSS may be required to customize this call to action. Insert Your CSS Below. Format: #element-id { display:none !important; }</em>";
     $custom_css = CTA_Variations::get_variation_custom_css($post->ID);
     $custom_css_meta_key = apply_filters('wp_cta_prepare_input_id', 'wp-cta-custom-css');
     $line_count = substr_count($custom_css, "\n");
     $line_count ? $line_count : ($line_count = 5);
     echo '<textarea name="' . $custom_css_meta_key . '" id="wp-cta-custom-css" rows="' . $line_count . '" cols="30" style="width:100%;">' . $custom_css . '</textarea>';
 }