function seed_cspv4_footer($echo = true)
{
    global $seed_cspv4, $seed_cspv4_post_result;
    $seed_cspv4 = get_option('seed_cspv4');
    extract($seed_cspv4);
    $output = '';
    // Check if postback
    $is_post = false;
    if (!empty($seed_cspv4_post_result['status']) && $seed_cspv4_post_result['status'] == '200') {
        $is_post = true;
    }
    // WP Footer
    $enable_wp_head_footer_list = apply_filters('seed_cspv4_enable_wp_head_footer_list', array());
    if (in_array($emaillist, $enable_wp_head_footer_list)) {
        $enable_wp_head_footer = '1';
    }
    if (!empty($enable_wp_head_footer)) {
        $output .= "<!-- wp_footer() -->\n";
        ob_start();
        wp_footer();
        $output = ob_get_clean();
        $include_theme_stylesheet = seed_get_plugin_api_value('include_theme_stylesheet');
        if (empty($include_theme_stylesheet)) {
            $output .= "<script>\n";
            $output .= 'jQuery(\'link[href*="' . get_stylesheet_directory_uri() . '"]\').remove();';
            $output .= "</script>\n";
        }
    }
    //WPML
    include_once ABSPATH . 'wp-admin/includes/plugin.php';
    if (is_plugin_active('wpml-string-translation/plugin.php')) {
        //var_dump($display_lang_switcher);
        if (!empty($display_lang_switcher)) {
            ob_start();
            do_action('icl_language_selector');
            $output .= ob_get_clean();
        }
    }
    // Fitvid
    if (!empty($enable_fitvidjs)) {
        $output .= "<script>\n";
        $output .= 'jQuery(document).ready(function($){$("#cspv4-description,#cspv4-thankyoumsg").fitVids();});';
        $output .= "</script>\n";
    }
    // Animate
    if (!empty($container_effect_animation)) {
        $output .= "<script>\n";
        $output .= 'jQuery(document).ready(function($){$("#cspv4-content").addClass(\'animated ' . $container_effect_animation . '\');});';
        $output .= "</script>\n";
    }
    // Backgound IOS Fix
    if (empty($bg_slideshow)) {
        if (empty($bg_video)) {
            if ($background['background-size'] == 'cover' && !empty($background['background-image'])) {
                /*$output .= '<!--[if lt IE 9]>
                			<script>
                			jQuery(document).ready(function($){';
                
                
                			$output .= '$.supersized({';
                			$output .= "slides:[ {image : '{$background['background-image']}'} ]";
                			$output .= '});';
                
                
                			$output .= '});
                			</script>
                			<![endif]-->';*/
                //
                // $output .= '
                // <script>
                // jQuery(document).ready(function($){
                // if (Modernizr.touch == true) {
                // ';
                // $output .= '$.supersized({';
                // $output .= "slides:[ {image : '{$background['background-image']}'} ]";
                // $output .= '});';
                // $output .= '
                // }
                // });
                // </script>
                // ';
                //$ios_bg_cover_hack = seed_get_plugin_api_value('ios_bg_cover_hack');
                //if($ios_bg_cover_hack == false){
                $output .= '
				<style>
				html {
				height: 100%;
				overflow: hidden;
				}
				body
				{
				height:100%;
				overflow: scroll;
				-webkit-overflow-scrolling: touch;
				}
				</style>
				';
                //}
            }
        }
    }
    if (!empty($bg_slideshow)) {
        $output .= '
		<!-- Slideshow -->
		<style>
		 	#supersized{
				display:block;
			}
		</style>
		<script>
		jQuery(document).ready(function($){';
        $output .= '$.supersized({';
        if (!empty($bg_slideshow_slide_speed) && absint($bg_slideshow_slide_speed)) {
            $output .= 'slide_interval:' . $bg_slideshow_slide_speed . ',' . PHP_EOL;
        } else {
            $output .= 'slide_interval:3000,' . PHP_EOL;
        }
        if (!empty($bg_slideshow_slide_transition) && absint($bg_slideshow_slide_transition)) {
            $output .= 'transition:' . $bg_slideshow_slide_transition . ',' . PHP_EOL;
        } else {
            $output .= 'transition:1,' . PHP_EOL;
        }
        $slideshow_api = seed_get_plugin_api_value('slideshow_api');
        if (!empty($slideshow_api)) {
            $output .= $slideshow_api;
        }
        $output .= 'transition_speed:700,' . PHP_EOL;
        $output .= 'fit_landscape:0,' . PHP_EOL;
        if (!empty($bg_slideshow_randomize)) {
            $output .= 'random:1,' . PHP_EOL;
        }
        $output .= "slides:[\n";
        if (!empty($bg_slideshow_images)) {
            foreach ($bg_slideshow_images as $k => $v) {
                if ($k !== 0) {
                    $output .= "," . PHP_EOL;
                }
                if (!empty($v['url'])) {
                    $output .= " {image : '" . trim($v['url']) . "'}" . "\n";
                } else {
                    $output .= " {image : '" . trim($v['image']) . "'}" . "\n";
                }
            }
        }
        $output .= "]";
        $output .= '});});';
        $output .= '</script>';
    }
    // Background Video
    //var_dump($bg_video);
    if (!empty($bg_video)) {
        if (!empty($bg_video_url)) {
            // $adproof = 'false';
            // if(!empty($bg_video_adproof)){
            // 	$adproof = 'true';
            // }
            // $hd = 'false';
            // if(!empty($bg_video_hd)){
            // 	$hd = 'true';
            // }
            $bg_video_url_arr = '';
            parse_str(parse_url($bg_video_url, PHP_URL_QUERY), $bg_video_url_arr);
            //$bg_video_url_arr['v'];
            // Output: C4kxS1ksqtw
            if (strpos($bg_video_url, 'mp4') !== false) {
                if (empty($bg_video_audio)) {
                    $audio = 'true';
                } else {
                    $audio = 'false';
                }
                if (empty($bg_video_loop)) {
                    $loop = 'false';
                } else {
                    $loop = 'true';
                }
                $output .= '
				<script>
				jQuery(document).ready(function($){
				if (Modernizr.touch == false) {
				';
                $output .= "var BV = new \$.BigVideo();";
                $output .= "BV.init();";
                $output .= "BV.show('" . $bg_video_url . "',{ambient:" . $audio . ",doLoop:" . $loop . "});";
                $output .= "\$('#big-video-wrap').show()";
                $output .= '
				}
				});
				</script>
				';
            } elseif (!empty($bg_video_url_arr['v'])) {
                if (empty($bg_video_audio)) {
                    $audio = 'true';
                } else {
                    $audio = 'false';
                }
                if (empty($bg_video_loop)) {
                    $loop = 'false';
                } else {
                    $loop = 'true';
                }
                $output .= '
				<script>
				jQuery(document).ready(function($){
				if (Modernizr.touch == false) {
				';
                $output .= "\$('#cspv4-page').tubular({ ";
                $output .= "videoId: '" . $bg_video_url_arr['v'] . "',";
                // $output .= "hd: ".$hd.",";
                // $output .= "adproof: ".$adproof."";
                $output .= "mute: " . $audio . ",";
                $output .= "repeat: " . $loop . "";
                $output .= " })";
                $output .= '
				}
				});
				</script>
				';
            } else {
                if (empty($bg_video_audio)) {
                    $audio = '0';
                } else {
                    $audio = '100';
                }
                if (empty($bg_video_loop)) {
                    $loop = 'false';
                } else {
                    $loop = 'true';
                }
                $output .= '
				<script>
				jQuery(document).ready(function($){
				if (Modernizr.touch == false) {
				';
                $output .= "\$.okvideo({ ";
                $output .= "video: '" . $bg_video_url . "',";
                // $output .= "hd: ".$hd.",";
                // $output .= "adproof: ".$adproof."";
                $output .= "volume: " . $audio . ",";
                $output .= "loop: " . $loop . "";
                $output .= " })";
                $output .= '
				}
				});
				</script>
				';
            }
        }
    }
    // Footer Scripts
    if (!empty($footer_scripts)) {
        $output .= "<!-- Footer Scripts -->\n";
        $output .= $footer_scripts;
    }
    // Conversion Scripts
    if (!empty($conversion_scripts) && $is_post) {
        $output .= "<!-- Conversion Scripts -->\n";
        $output .= $conversion_scripts;
    }
    $output = apply_filters('seed_cspv4_footer', $output);
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
 /**
  * Display the coming soon page
  */
 function render_landing_page()
 {
     // Get Settings
     global $seed_cspv4;
     extract($seed_cspv4);
     $o = $seed_cspv4;
     // Check if Preview
     $is_preview = false;
     if (isset($_GET['seed_cspv4_preview']) && $_GET['seed_cspv4_preview'] == 'true') {
         //show_admin_bar( false );
         $is_preview = true;
     }
     // Countdown Launch
     if ($is_preview == false) {
         if (!empty($countdown_date) && !empty($enable_countdown) && !empty($countdown_launch)) {
             if (empty($o['countdown_time_hour'])) {
                 $o['countdown_time_hour'] = '0';
                 $countdown_time_hour = '0';
             }
             if (empty($o['countdown_time_minute'])) {
                 $o['countdown_time_minute'] = '0';
                 $countdown_time_minute = '0';
             }
             $dt = getdate(strtotime($o['countdown_date'] . $o['countdown_time_hour'] . ':' . $o['countdown_time_minute'] . ' UTC'));
             $tz = get_option('timezone_string');
             if (empty($tz)) {
                 $offset = get_option('gmt_offset');
                 $tz = timezone_name_from_abbr("", $offset * 3600, 0);
             }
             date_default_timezone_set($tz);
             $countdown_date = date_parse($countdown_date);
             $launch_date = new DateTime($countdown_date['year'] . '-' . $countdown_date['month'] . '-' . $countdown_date['day'] . ' ' . $countdown_time_hour . ':' . $countdown_time_minute . ':00');
             // Launch this biatch
             if ($launch_date <= new DateTime()) {
                 // Email the admin the site has been launched
                 $message = __(sprintf('%s has been launched.', home_url()), 'seedprod');
                 $result = wp_mail(get_option('admin_email'), __(sprintf('%s has been launched.', home_url()), 'seedprod'), $message);
                 $o = get_option('seed_cspv4');
                 $o['status'] = 0;
                 update_option('seed_cspv4', $o);
                 return false;
             }
         }
     }
     //If Referrer record it
     if (isset($_GET['ref'])) {
         $id = intval($_GET['ref'], 36) - 1000;
         global $wpdb;
         $tablename = $wpdb->prefix . SEED_CSPV4_TABLENAME;
         $sql = "UPDATE {$tablename} SET clicks = clicks + 1 WHERE id = %d";
         $safe_sql = $wpdb->prepare($sql, $id);
         $update_result = $wpdb->get_var($safe_sql);
     }
     // Exit if feed and feedburner is enabled.
     if (is_feed() && $emaillist == 'feedburner') {
         return false;
     }
     if (empty($_GET['seed_cspv4_preview'])) {
         $_GET['seed_cspv4_preview'] = false;
     }
     if (empty($_GET['bypass'])) {
         $_GET['bypass'] = false;
     }
     $alt_bypass = seed_get_plugin_api_value('alt_bypass');
     if (is_multisite() || $alt_bypass) {
         // Multisite Clientview
         if (empty($_GET['bypass'])) {
             $_GET['bypass'] = false;
         }
         if (empty($_GET['cs_preview'])) {
             $_GET['cs_preview'] = false;
         }
         //Check for Client View
         if (isset($_COOKIE['wp-client-view']) && (strtolower(basename($_SERVER['REQUEST_URI'])) == trim(strtolower($client_view_url)) || strtolower($_GET['bypass']) == trim(strtolower($client_view_url))) && !empty($client_view_url)) {
             header('Location: ' . home_url() . '?' . rand());
         }
         // Don't show Coming Soon Page if client View is active
         $client_view_hash = md5($client_view_url . get_current_blog_id());
         if (isset($_COOKIE['wp-client-view']) && $_COOKIE['wp-client-view'] == $client_view_hash && $_GET['cs_preview'] != 'true' && !empty($client_view_url)) {
             nocache_headers();
             header('Cache-Control: max-age=0');
             return false;
         } else {
             setcookie("wp-client-view", "", time() - 3600);
         }
         // If Client view is not empty and we are on the client view url set cookie.
         if (!empty($client_view_url)) {
             if (empty($_GET['bypass'])) {
                 $_GET['bypass'] = '';
             }
             if (strtolower(basename($_SERVER['REQUEST_URI'])) == trim(strtolower($client_view_url)) || strtolower($_GET['bypass']) == trim(strtolower($client_view_url))) {
                 setcookie("wp-client-view", $client_view_hash, time() + 21600, COOKIEPATH, COOKIE_DOMAIN, false);
                 header('Location: ' . home_url() . '?' . rand());
                 exit;
             }
         }
     } else {
         // ClientView
         if (!empty($client_view_url)) {
             if (empty($_GET['bypass'])) {
                 $_GET['bypass'] = '';
             }
             // If client view url is passed in log user in
             if (strtolower(basename($_SERVER['REQUEST_URI'])) == trim(strtolower($client_view_url)) || strtolower($_GET['bypass']) == trim(strtolower($client_view_url))) {
                 if (!username_exists('seed_cspv4_clientview_' . $client_view_url)) {
                     $user_id = wp_create_user('seed_cspv4_clientview_' . $client_view_url, wp_generate_password());
                     $user = new WP_User($user_id);
                     $user->set_role('none');
                 }
                 $client_view_hash = md5($client_view_url . get_current_blog_id());
                 setcookie("wp-client-view", $client_view_hash, time() + (int) $bypass_expires, COOKIEPATH, COOKIE_DOMAIN, false);
                 add_filter('auth_cookie_expiration', array(&$this, 'change_wp_cookie_logout'));
                 // Log user in auto
                 $username = '******' . $client_view_url;
                 if (!is_user_logged_in()) {
                     $user = get_user_by('login', $username);
                     $user_id = $user->ID;
                     wp_set_current_user($user_id, $username);
                     wp_set_auth_cookie($user_id);
                     do_action('wp_login', $username);
                     update_user_meta($user_id, 'show_admin_bar_front', false);
                 }
                 if (!empty($_REQUEST['return'])) {
                     header('Location: ' . urldecode($_REQUEST['return']));
                     exit;
                 } else {
                     header('Location: ' . home_url() . '?' . rand());
                     exit;
                 }
             }
         }
     }
     // Check for excluded IP's
     if ($is_preview == false) {
         if (!empty($ip_access)) {
             $ip = seed_cspv4_get_ip();
             $exclude_ips = explode("\r\n", $ip_access);
             if (is_array($exclude_ips) && in_array($ip, $exclude_ips)) {
                 return false;
             }
         }
     }
     // Check for included pages
     if (!empty($include_url_pattern) && @preg_match("/{$include_url_pattern}/", $_SERVER['REQUEST_URI']) == 0 && $is_preview == false) {
         return false;
     }
     // Check for excluded pages
     if (!empty($exclude_url_pattern) && @preg_match("/{$exclude_url_pattern}/", $_SERVER['REQUEST_URI']) > 0 && $is_preview == false) {
         return false;
     }
     // Exit if a custom login page
     if (empty($disable_default_excludes)) {
         $default_excludes_pattern = apply_filters('seed_cspv4_default_excludes_pattern', 'login');
         if (preg_match("/{$default_excludes_pattern}/i", $_SERVER['REQUEST_URI']) > 0 && $is_preview == false) {
             return false;
         }
     }
     //Exit if wysija double opt-in
     if ($emaillist == 'wysija' && preg_match("/wysija/i", $_SERVER['REQUEST_URI']) > 0 && $is_preview == false) {
         return false;
     }
     // Set values if not set
     if (empty($include_page)) {
         $include_page = '-1';
     }
     if (empty($include_roles)) {
         $include_roles = '0';
     }
     //Limit to one page
     if ($is_preview === false) {
         if ($include_page != '-1') {
             $post_id = $include_page;
             $post = get_post($post_id);
             $slug = $post->post_name;
             $is_page = false;
             if (@preg_match("/{$slug}/", $_SERVER['REQUEST_URI']) > 0 && $is_preview == false) {
                 $is_page = true;
             } else {
                 //backup_method
                 if (!is_page($include_page)) {
                     return false;
                 }
             }
         }
     }
     //Limit access by role
     if (!is_page($include_page)) {
         if ($is_preview === false) {
             if (!empty($include_roles) && !isset($_COOKIE['wp-client-view'])) {
                 foreach ($include_roles as $v) {
                     if ($v == '0' && is_user_logged_in()) {
                         return false;
                     }
                     if (current_user_can($v)) {
                         return false;
                     }
                 }
             } elseif (is_user_logged_in()) {
                 return false;
             }
         }
     }
     // Set 503 Headers
     if ($status == '2') {
         header('HTTP/1.1 503 Service Temporarily Unavailable');
         header('Status: 503 Service Temporarily Unavailable');
         header('Retry-After: 86400');
         // retry in a day
     } elseif ($status == '3') {
         if (!empty($redirect_url)) {
             wp_redirect($redirect_url);
             exit;
         }
     } else {
         header("HTTP/1.1 200 OK");
     }
     // Use maintenance.php
     $cspv4_maintenance_file = WP_CONTENT_DIR . "/maintenance.php";
     if (!empty($enable_maintenance_php) and file_exists($cspv4_maintenance_file)) {
         return $cspv4_maintenance_file;
     }
     do_action('seed_cspv4_pre_render');
     // Render Landing Page
     if (empty($template)) {
         $templates = new Seed_CSPV4_Template_Loader();
         if (!empty($theme) && $theme != 'default') {
             if (file_exists(apply_filters('seed_cspv4_themes_path', SEED_CSPV4_PLUGIN_PATH) . 'index.php')) {
                 include apply_filters('seed_cspv4_themes_path', SEED_CSPV4_PLUGIN_PATH) . 'index.php';
                 exit;
             } else {
                 $templates->get_template_part('default/index');
                 exit;
             }
         } else {
             $templates->get_template_part('default/index');
             exit;
         }
     } else {
         echo do_shortcode($template);
         exit;
     }
 }