From f66d0a9627b0b466527a43883d7f08d40af95f6c Mon Sep 17 00:00:00 2001 From: Jay Wood Date: Mon, 1 Dec 2014 07:54:44 -0500 Subject: [PATCH] Remove deprecated code --- class/main.class.php | 139 ++++--------------------------------------- 1 file changed, 10 insertions(+), 129 deletions(-) diff --git a/class/main.class.php b/class/main.class.php index 4581176..200b887 100644 --- a/class/main.class.php +++ b/class/main.class.php @@ -47,6 +47,16 @@ class CWV3 { wp_register_style( 'cwv3_css', plugins_url( "css/cwv3{$min}.css", dirname( __FILE__ ) ), '', '1.0' ); } + /** + * Get Cookie Name + * + * If the cookie is to be shown, this function will return the ID, and the javascript + * will handle the rest of it. + * + * If this function returns false, the javascript will not show a popup. + * + * @return string|int String if special page like homepage, or post_id otherwise. + */ public function get_cookie_name(){ global $post; @@ -119,138 +129,9 @@ class CWV3 { } } - /*$type = get_post_type( $id ); - if ( 'post' == $type ) { - $catData = get_option( 'cwv3_cat_list' ); - $curCat = get_the_category( $id ); - if ( $this->in_cat( $catData, $curCat ) ) { - $cData['categories']->$id = $action; - return setcookie( 'cwv3_cats', json_encode( $cData['categories'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } else if ( 'yes' == get_post_meta( $id, 'cwv3_auth', true ) ) { - $cData['posts']->$id = $action; - return setcookie( 'cwv3_posts', json_encode( $cData['posts'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } - } - - if ( 'yes' == get_post_meta( $id, 'cwv3_auth', true ) ) { - $cData['pages']->$id = $action; - return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - }*/ - return false; } - public function set_cookie( $id, $action ) { - - $time = get_option( 'cwv3_death' ); - - $sw = get_option( 'cwv3_sitewide' ); - $hm = get_option( 'cwv3_homepage' ); - $mi = get_option( 'cwv3_misc' ); - - $cData = array( - // check isset before access (edit by @jgraup) - 'pages' => ! isset( $_COOKIE['cwv3_pages'] ) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_pages'] ) ), - 'posts' => ! isset( $_COOKIE['cwv3_posts'] ) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_posts'] ) ), - 'categories' => ! isset( $_COOKIE['cwv3_cats'] ) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_cats'] ) ) - ); - - // ensure we're using valid objects (edit by @jgraup) - foreach ( $cData as $key => $value ) { - if ( is_scalar( $value ) ) { - $cData[ $key ] = new stdClass; - } - } - if ( 'enabled' == ! empty( $sw ) ) { - $cData['pages']->sitewide = $action; - return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } - - if ( 'enabled' == ! empty( $hm ) && -1 == $id ) { - $cData['pages']->home = $action; - return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } - - if ( 'enabled' == ! empty( $mi ) && -2 == $id ) { - $cData['pages']->other = $action; - return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } - - $type = get_post_type( $id ); - if ( 'post' == $type ) { - $catData = get_option( 'cwv3_cat_list' ); - $curCat = get_the_category( $id ); - if ( $this->in_cat( $catData, $curCat ) ) { - $cData['categories']->$id = $action; - return setcookie( 'cwv3_cats', json_encode( $cData['categories'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } else if ( 'yes' == get_post_meta( $id, 'cwv3_auth', true ) ) { - $cData['posts']->$id = $action; - return setcookie( 'cwv3_posts', json_encode( $cData['posts'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } - } - - if ( 'yes' == get_post_meta( $id, 'cwv3_auth', true ) ) { - $cData['pages']->$id = $action; - return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); - } - - return 'Failed to set cookie.'; - } - - public function check_data() { - global $post; - - if ( is_feed() ) { - //Don't want to hender the feed, just in case. - return true; - } - - $cData = array( - // check isset before access (edit by @jgraup) - 'pages' => ! isset( $_COOKIE['cwv3_pages'] ) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_pages'] ), true ), - 'posts' => ! isset( $_COOKIE['cwv3_posts'] ) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_posts'] ), true ), - 'categories' => ! isset( $_COOKIE['cwv3_cats'] ) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_cats'] ), true ) - ); - - $sw = get_option( 'cwv3_sitewide' ); - $hm = get_option( 'cwv3_homepage' ); - $mi = get_option( 'cwv3_misc' ); - - if ( ! empty( $sw ) ) { - return ! empty( $cData['pages']['sitewide'] ) ? $cData['pages']['sitewide'] : false; - } - - if ( is_front_page() && ! empty( $hm ) ) { - return ! empty( $cData['pages']['home'] ) ? $cData['pages']['home'] : false; - } - - if ( ( is_archive() || is_search() ) && ! empty( $mi ) ) { - // Protect misc pages aswell - return ! empty( $cData['pages']['other'] ) ? $cData['pages']['other'] : false; - } - - if ( is_page() && 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) ) { - $c = $cData['pages'][ $post->ID ]; - return ! empty( $c ) ? $c : false; - } - - $id = ( is_attachment() ? $post->post_parent : $post->ID ); - // First see if categories are setup in the admin side. - $catData = get_option( 'cwv3_cat_list' ); - $curCat = get_the_category( $id ); - if ( 'post' == get_post_type( $id ) && $this->in_cat( $catData, $curCat ) ) { - // If the current category is selected in the admin page, that means the administrator wishes to protect it. - // respect the admin's wishes and do it. - 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 ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) && ! is_front_page() ) { - return ! empty( $cData['posts'][ $post->ID ] ) ? $cData['posts'][ $id ] : false; - } - - return true; - } - public function in_cat( $catIDs, $catArray ) { if ( ! is_array( $catIDs ) ) { $catIDs = array(); // Empty