From 59bb5e2e99c40bdd845fdd29f0d4296ee7470af9 Mon Sep 17 00:00:00 2001 From: JayWood Date: Sun, 13 Jul 2014 15:44:39 -0400 Subject: [PATCH] Colorbox fix --- class/main.class.php | 26 +++++++++++--------------- js/cwv3.js | 15 ++++++--------- js/cwv3.min.js | 2 +- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/class/main.class.php b/class/main.class.php index 945fd10..373faba 100644 --- a/class/main.class.php +++ b/class/main.class.php @@ -2,11 +2,7 @@ class CWV3 { - function CWV3() { - $this->__construct(); - } - - public function __construct() { + public function CWV3() { // Styling and such add_action( 'init', array( &$this, 'register_frontend_data' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'load_dependancies' ) ); @@ -136,14 +132,14 @@ class CWV3 { $elink = get_option( 'cwv3_enter_link' ); $exlink = get_option( 'cwv3_exit_link' ); - $p_ID = ( is_home() ) ? -1 : ( is_attachment() ? $post->post_parent : ( is_archive() || is_search() ) ? -2 : $post->ID ); + $p_ID = ( is_front_page() ) ? -1 : ( is_attachment() ? $post->post_parent : ( is_archive() || is_search() ) ? -2 : $post->ID ); $d = get_option( 'cwv3_denial' ); wp_localize_script( 'cwv3_js', 'cwv3_params', array( 'action' => 'cwv3_ajax', 'nonce' => wp_create_nonce( 'cwv3_ajax_'.$p_ID ), 'admin_url' => admin_url( 'admin-ajax.php' ), 'id' => $p_ID, - 'sd' => ( $this->check_data() == false || ( $this->check_data() == 3 && $d[0] == 'enabled' ) ) ? true : false, + 'sd' => ( $this->check_data() == false || ( $this->check_data() == 3 && !empty( $d ) ) ) ? true : false, 'enter' => !empty( $elink ) ? $elink : '#', 'exit' => !empty( $exlink ) ? $exlink : 'http://google.com', 'opacity' => get_option( 'cwv3_bg_opacity', 0.85 ) @@ -225,9 +221,9 @@ class CWV3 { return true; } $cData = array( - 'pages' => json_decode( stripslashes( $_COOKIE['cwv3_pages'] ), true ), - 'posts' => json_decode( stripslashes( $_COOKIE['cwv3_posts'] ), true ), - 'categories' => json_decode( stripslashes( $_COOKIE['cwv3_cats'] ), true ) + 'pages' => json_decode( stripslashes( @$_COOKIE['cwv3_pages'] ), true ), + 'posts' => json_decode( stripslashes( @$_COOKIE['cwv3_posts'] ), true ), + 'categories' => json_decode( stripslashes( @$_COOKIE['cwv3_cats'] ), true ) ); //return print_r($cData, true); @@ -236,15 +232,15 @@ class CWV3 { $hm = get_option( 'cwv3_homepage' ); $mi = get_option( 'cwv3_misc' ); - if ( $sw[0] == 'enabled' ) { + if ( ! empty( $sw ) ) { return !empty( $cData['pages']['sitewide'] ) ? $cData['pages']['sitewide'] : false; } - if ( is_home() && $hm[0] == 'enabled' ) { + if ( is_front_page() && !empty( $hm ) ) { return !empty( $cData['pages']['home'] ) ? $cData['pages']['home'] : false; } - if ( ( is_archive() || is_search() ) && $mi[0] == 'enabled' ) { + if ( ( is_archive() || is_search() ) && !empty( $mi ) ) { // Protect misc pages aswell return !empty( $cData['pages']['other'] ) ? $cData['pages']['other'] : false; } @@ -264,11 +260,11 @@ class CWV3 { return !empty( $cData['categories'][$post->ID] ) ? $cData['categories'][$id] : false; } // Since that's not the case, we need to check post_meta data and see if this post is protected. - if ( get_post_meta( $post->ID, 'cwv3_auth', true ) == 'yes' && !is_home() ) { + if ( get_post_meta( $post->ID, 'cwv3_auth', true ) == 'yes' && !is_front_page() ) { return !empty( $cData['posts'][$post->ID] ) ? $cData['posts'][$id] : false; } - return 'failed all checks'; + return true; } public function inCat( $catIDs, $catArray ) { diff --git a/js/cwv3.js b/js/cwv3.js index 488ed08..0021e0a 100644 --- a/js/cwv3.js +++ b/js/cwv3.js @@ -1,11 +1,9 @@ /* global cwv3_params */ jQuery(document).ready(function($) { - var wpdata = cwv3_params; - //console.log(wpdata); var enter = $('#cw_enter_link'); var exit = $('#cw_exit_link'); - if(wpdata.sd === true){ + if(cwv3_params.sd === "1"){ $.colorbox( { scrolling: false, @@ -13,8 +11,7 @@ jQuery(document).ready(function($) { escKey: false, inline: true, href: '#cwv3_auth', - initialWidth: '50%', - maxWidth: '600px', + maxWidth: '80%', loop: false, onLoad: function(){ $('#cboxClose').remove(); @@ -29,11 +26,11 @@ jQuery(document).ready(function($) { e.preventDefault(); } //console.log(e); - $.post(wpdata.admin_url, {action: wpdata.action, nonce: wpdata.nonce, id: wpdata.id, method: 'enter'}, function(){ + $.post(cwv3_params.admin_url, {action: cwv3_params.action, nonce: cwv3_params.nonce, id: cwv3_params.id, method: 'enter'}, function(){ if(cwv3_params.enter === "#"){ $.colorbox.close(); }else{ - window.location = wpdata.enter; + window.location = cwv3_params.enter; } }); }); @@ -42,8 +39,8 @@ jQuery(document).ready(function($) { if( typeof(e) !== "undefined" ){ e.preventDefault(); } - $.post(wpdata.admin_url, {action: wpdata.action, nonce: wpdata.nonce, id: wpdata.id, method: 'exit'}, function(){ - window.location = wpdata.exit; + $.post(cwv3_params.admin_url, {action: cwv3_params.action, nonce: cwv3_params.nonce, id: cwv3_params.id, method: 'exit'}, function(){ + window.location = cwv3_params.exit; }); }); } diff --git a/js/cwv3.min.js b/js/cwv3.min.js index 7a0d5b4..fd1a49f 100644 --- a/js/cwv3.min.js +++ b/js/cwv3.min.js @@ -1 +1 @@ -jQuery(document).ready(function($){var wpdata=cwv3_params,enter=$("#cw_enter_link"),exit=$("#cw_exit_link");wpdata.sd===!0&&($.colorbox({scrolling:!1,overlayClose:!1,escKey:!1,inline:!0,href:"#cwv3_auth",initialWidth:"50%",maxWidth:"600px",loop:!1,onLoad:function(){$("#cboxClose").remove()},className:"cwv3_box",opacity:cwv3_params.opacity}),enter.click(function(e){"undefined"!=typeof e&&e.preventDefault(),$.post(wpdata.admin_url,{action:wpdata.action,nonce:wpdata.nonce,id:wpdata.id,method:"enter"},function(){"#"===cwv3_params.enter?$.colorbox.close():window.location=wpdata.enter})}),exit.click(function(e){"undefined"!=typeof e&&e.preventDefault(),$.post(wpdata.admin_url,{action:wpdata.action,nonce:wpdata.nonce,id:wpdata.id,method:"exit"},function(){window.location=wpdata.exit})}))}); \ No newline at end of file +jQuery(document).ready(function($){var enter=$("#cw_enter_link"),exit=$("#cw_exit_link");"1"===cwv3_params.sd&&($.colorbox({scrolling:!1,overlayClose:!1,escKey:!1,inline:!0,href:"#cwv3_auth",maxWidth:"80%",loop:!1,onLoad:function(){$("#cboxClose").remove()},className:"cwv3_box",opacity:cwv3_params.opacity}),enter.click(function(e){"undefined"!=typeof e&&e.preventDefault(),$.post(cwv3_params.admin_url,{action:cwv3_params.action,nonce:cwv3_params.nonce,id:cwv3_params.id,method:"enter"},function(){"#"===cwv3_params.enter?$.colorbox.close():window.location=cwv3_params.enter})}),exit.click(function(e){"undefined"!=typeof e&&e.preventDefault(),$.post(cwv3_params.admin_url,{action:cwv3_params.action,nonce:cwv3_params.nonce,id:cwv3_params.id,method:"exit"},function(){window.location=cwv3_params.exit})}))}); \ No newline at end of file