| Current Path : /home/ereika83/www/wp-content/plugins/instasuite-for-wordpress 4 3/inc/ |
| Current File : /home/ereika83/www/wp-content/plugins/instasuite-for-wordpress 4 3/inc/functions.php |
<?php
add_action('wp', 'kyvio_template_hooks', 2);
function kyvio_template_hooks() {
if ( KYVIO_CURRENT_THEME == 'Thesis' ) {
add_action('template_redirect', 'inst_template_override', 3);
} else {
add_filter('template_include', 'inst_template_override');
}
}
function kyvio_template_framework() {
global $post, $kyvio_meta;
if ( empty($kyvio_meta) )
wp_die('ERROR: Data Not Set');
$is_enabled = ( is_array($kyvio_meta) && $kyvio_meta['enable'] == 1 ) ? true : false;
if ( !$is_enabled )
wp_die('Configuration Error');
list($funnel_id, $page_id) = explode(":", $kyvio_meta['page_id'], 2);
$variant = ( isset($_COOKIE["_isabs_{$page_id}"]) ? $_COOKIE["_isabs_{$page_id}"] : -1 );
$response = kyvio_call($funnel_id, $page_id, false, $variant);
if ( !$response )
wp_die('ERROR: Cannot contact Kyvio server');
if ( !isset($response->content) )
wp_die('ERROR: Content not found');
if ( $variant = -1 ) {
$variant = $response->variant;
@setcookie("_isabs_{$page_id}", $variant, time() + YEAR_IN_SECONDS, COOKIEPATH);
}
// Disable rocket lazyload
add_filter( 'do_rocket_lazyload', '__return_false' );
// pop up
$popdata = kyvio_pops($response->popdata, $response->popup_opts, $page_id);
$infobardata = kyvio_pops($response->infobardata, $response->popup_opts, $page_id, 1, 'infobar');
$actionmsgdata = kyvio_pops($response->actionmsgdata, $response->popup_opts, $page_id, 2, 'actionmsg');
$overlaydata = kyvio_pops($response->overlaydata, $response->popup_opts, $page_id, 3, 'overlay');
$content = $response->content;
if ( !empty($response->videoOptions) )
$video_options = json_encode($response->videoOptions);
if ( !empty($response->commentOptions) )
$comment_options = json_encode($response->commentOptions);
$fb_app_id = get_option('instasuite_fb_app_id');
$content = str_replace('%fb_app_id%', $fb_app_id, $content);
$content = str_replace('</body>', '', $content);
$content = str_replace('</html>', '', $content);
$content .= "\n\n" . '
<script>
var popdata = ' . json_encode($popdata) . ',
infobardata = ' . json_encode($infobardata) . ',
actionmsgdata = ' . json_encode($actionmsgdata) . ',
overlaydata = ' . json_encode($overlaydata) . ';
</script>
';
$content .= "\n\n" . '
</body>
</html>
';
echo $content;
exit();
}
function kyvio_pops( $data, $opts, $page_id, $num = 0, $name = 'popup' ) {
if ( !is_object($data) || !is_object($opts) )
return false;
$data = (array) $data;
$opts = (array) $opts;
$cookie_name = "instact-{$page_id}";
$cookie_data = '0.0.0.0';
$cookie = ( isset($_COOKIE[$cookie_name]) ? $_COOKIE[$cookie_name] : '' );
$sub = '';
switch ( $num ) {
case 1:
$sub = 'i';
break;
case 2:
$sub = 'a';
break;
case 3:
$sub = 'o';
break;
}
$save_cookie = false;
if ( $data['enable'] == true && !empty($data['popid']) ) {
$pop_schedule = $opts["{$name}-option-load"];
switch ( $pop_schedule ) {
case 'exit':
case 'scroll':
case 'always':
$data['show'] = 1;
break;
case 'first':
if ( empty($cookie) ) {
$vals = explode(".", $cookie_data);
$data['show'] = 1;
}
else {
$vals = explode(".", $cookie);
if ( $vals[$num] == 0 ) {
$data['show'] = 1;
}
}
if ( $data['show'] == 1 ) {
$vals[$num] = 1;
$cookie_data = implode(".", $vals);
$save_cookie = true;
}
break;
case 'day':
$day_cookie = ( isset($_COOKIE["{$cookie_name}-{$sub}day"]) ? $_COOKIE["{$cookie_name}-{$sub}day"] : '' );
if ( empty($day_cookie) ) {
$data['show'] = 1;
@setcookie("{$cookie_name}-{$sub}day", 1, time() + DAY_IN_SECONDS, COOKIEPATH);
}
break;
case 'session':
$sess_cookie = ( isset($_COOKIE["{$cookie_name}-{$sub}sess"]) ? $_COOKIE["{$cookie_name}-{$sub}sess"] : '' );
if ( empty($sess_cookie) ) {
$data['show'] = 1;
@setcookie("{$cookie_name}-{$sub}sess", 1, 0, COOKIEPATH);
}
break;
}
}
if ( $save_cookie )
@setcookie($cookie_name, $cookie_data, time() + YEAR_IN_SECONDS, COOKIEPATH);
return $data;
}
function inst_template_override( $template ) {
global $post, $kyvio_meta;
if ( KYVIO_CURRENT_THEME == 'Thesis' )
$template = true;
if ( !is_singular() || empty($post) )
return $template;
if ( post_password_required() )
return $template;
$token = get_option('instasuite_token');
if ( empty($token) )
return $template;
$kyvio_meta = get_post_meta($post->ID, 'instasuite_meta', true);
if ( empty($kyvio_meta) || !is_array($kyvio_meta) )
return $template;
$is_enabled = ( is_array($kyvio_meta) && $kyvio_meta['enable'] == 1 ) ? true : false;
if ( !$is_enabled || !file_exists(KYVIO_INC . 'template.php') ) return $template;
if ( KYVIO_CURRENT_THEME == 'Thesis' ) {
include_once(KYVIO_INC . 'template.php');
exit;
} else {
$template = KYVIO_INC . 'template.php'; // override default wp theme template with InstaSUITE
}
return $template;
}