Colorbox fix

This commit is contained in:
JayWood
2014-07-13 15:44:39 -04:00
parent ef36c1d7f3
commit 59bb5e2e99
3 changed files with 18 additions and 25 deletions

View File

@ -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 ) {

View File

@ -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;
});
});
}

2
js/cwv3.min.js vendored
View File

@ -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})}))});
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})}))});