function pc_pvt_redirect()
{
    include_once PC_DIR . '/functions.php';
    $orig_redirect_val = get_option('pg_redirect_page');
    $redirect_url = pc_man_redirects('pg_redirect_page');
    // only if redirect option is setted
    if (!empty($redirect_url)) {
        // get redirect page url
        $orig_redirect_val = get_option('pg_redirect_page');
        $redirect_url = pc_man_redirects('pg_redirect_page');
        //////////////////////////////////////////////////////////////
        // complete website lock
        if (get_option('pg_complete_lock') && pc_user_check('all', '', true) !== 1) {
            global $post;
            $excluded_pages = filter_var($orig_redirect_val, FILTER_VALIDATE_INT) ? array($orig_redirect_val) : array();
            // PC-FILTER - add page IDS to exclude from complete site lock - page IDs array
            $excluded_pages = apply_filters('pc_complete_lock_exceptions', $excluded_pages);
            // exceptions check
            foreach ((array) $excluded_pages as $pag_id) {
                if ($pag_id == $post->ID) {
                    $exception_page = true;
                    break;
                } elseif (pc_wpml_translated_pag_id($pag_id) == $post->ID) {
                    $exception_page = true;
                    break;
                }
            }
            if (!isset($exception_page)) {
                // last restricted page redirect system
                if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') {
                    $_SESSION['pc_last_restricted'] = pc_curr_url();
                }
                header('location: ' . $redirect_url);
                die;
            }
        }
        //////////////////////////////////////////////////////////////
        // single page/post redirect
        if (is_page() || is_single()) {
            global $post;
            $result = pc_redirect_check('page', $post);
            // custom unlogged redirect system
            $is_unl_custom_redir = isset($GLOBALS['pc_unlogged_custom_redirect']) ? true : false;
            if ($is_unl_custom_redir) {
                $redirect_url = $GLOBALS['pc_unlogged_custom_redirect'];
                // avoid redirect loops
                if ($redirect_url == pc_curr_url()) {
                    return false;
                }
            }
            if (($post->ID != $orig_redirect_val || $is_unl_custom_redir) && !$result) {
                // last restricted page redirect system
                if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '' && !$is_unl_custom_redir) {
                    $_SESSION['pc_last_restricted'] = pc_curr_url();
                }
                header('location: ' . $redirect_url);
                die;
            }
        }
        //////////////////////////////////////////////////////////////
        // if is category or archive
        if (is_category() || is_archive()) {
            $cat_id = get_query_var('cat');
            // know which taxonomy is involved
            foreach (pc_affected_tax() as $tax) {
                $cat_data = get_term_by('id', $cat_id, $tax);
                if ($cat_data != false) {
                    if (!pc_redirect_check('category', $cat_data, $tax)) {
                        if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') {
                            $_SESSION['pc_last_restricted'] = pc_curr_url();
                        }
                        header('location: ' . $redirect_url);
                        die;
                    }
                    break;
                }
            }
        }
        //////////////////////////////////////////////////////////////
        // WooCommerce category
        if (function_exists('is_product_category') && is_product_category()) {
            $cat_slug = get_query_var('product_cat');
            $cat_data = get_term_by('slug', $cat_slug, 'product_cat');
            if ($cat_data != false) {
                if (!pc_redirect_check('category', $cat_data, 'product_cat')) {
                    if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') {
                        $_SESSION['pc_last_restricted'] = pc_curr_url();
                    }
                    header('location: ' . $redirect_url);
                    die;
                }
            }
        }
        //////////////////////////////////////////////////////////////
        // if is a single post (check category restriction)
        if (is_single()) {
            global $post;
            include_once PC_DIR . '/functions.php';
            // search post terms in every involved taxonomy
            foreach (pc_affected_tax() as $tax) {
                $terms = wp_get_post_terms($post->ID, $tax);
                if (is_array($terms)) {
                    foreach ($terms as $term) {
                        $cat_data = get_term_by('id', $term->term_id, $tax);
                        if (!pc_redirect_check('category', $cat_data, $tax)) {
                            if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') {
                                $_SESSION['pc_last_restricted'] = pc_curr_url();
                            }
                            header('location: ' . $redirect_url);
                            die;
                        }
                    }
                }
            }
        }
        //////////////////////////////////////////////////////////////
        // PC-FILTER custom restriction (URL based) - associative array('url' => array('allowed', 'blocked'))
        $restrictet_urls = apply_filters('pc_custom_restriction', array());
        if (is_array($restrictet_urls) && count($restrictet_urls)) {
            $curr_url = pc_curr_url();
            foreach ((array) $restrictet_urls as $url => $val) {
                if (isset($val['allowed']) && $curr_url == $url) {
                    $blocked = isset($val['blocked']) ? $val['blocked'] : '';
                    if (pc_user_check($val['allowed'], $blocked, true) !== 1) {
                        header('location: ' . $redirect_url);
                        die;
                    }
                }
            }
        }
    }
}
function pc_wp_user_logout()
{
    global $wpdb;
    global $pc_wp_user;
    $user = wp_get_current_user();
    if (isset($user->ID) && !empty($user->ID)) {
        $user_data = $pc_wp_user->wp_user_is_linked($user->ID);
        if ($user_data) {
            if (!isset($GLOBALS['pc_only_wp_logout'])) {
                pc_logout();
            }
            // check if a redirect is needed
            if (get_option('pg_logout_user_redirect')) {
                $redirect_url = pc_man_redirects('pg_logout_user_redirect');
                wp_redirect($redirect_url);
                exit;
            }
        }
    }
}
function pc_register_user()
{
    global $wpdb, $pc_users;
    if (isset($_POST['type']) && $_POST['type'] == 'pc_registration') {
        require_once PC_DIR . '/classes/pc_form_framework.php';
        require_once PC_DIR . '/classes/recaptchalib.php';
        include_once PC_DIR . '/functions.php';
        ////////// VALIDATION ////////////////////////////////////
        $term = get_term((int) $_REQUEST['form_id'], 'pc_reg_form');
        if (!$term) {
            $mess = json_encode(array('resp' => 'error', 'mess' => __('Form not found', 'pc_ml')));
            die($mess);
        }
        $GLOBALS['pc_custom_cat_name'] = true;
        $f_fw = new pc_form(array('use_custom_cat_name' => true, 'strip_no_reg_cats' => true));
        $form_structure = unserialize(base64_decode($term->description));
        $antispam = get_option('pg_antispam_sys', 'honeypot');
        // custom validation indexes
        $custom_indexes = array();
        $indexes = $f_fw->generate_validator($form_structure, $custom_indexes);
        //// prior custom validation
        $cust_errors = array();
        if ($antispam == 'honeypot') {
            if (!$f_fw->honeypot_validaton()) {
                $cust_errors[] = "Antispam - we've got a bot here!";
            }
        } else {
            $privatekey = "6LfQas0SAAAAAIzpthJ7UC89nV9THR9DxFXg3nVL";
            $resp = pc_recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
            //var_dump($resp->is_valid);
            if (!$resp->is_valid) {
                $cust_errors[] = "reCAPTCHA - " . __("wasn't entered correctly", 'pc_ml');
            }
        }
        // check disclaimer
        if (get_option('pg_use_disclaimer') && !isset($_POST['pc_disclaimer'])) {
            $cust_errors[] = __("Disclaimer", 'pc_ml') . " - " . __("must be accepted to proceed with registration", 'pc_ml');
        }
        // validation wrap-up
        $is_valid = $f_fw->validate_form($indexes, $cust_errors, false, false);
        $fdata = $f_fw->form_data;
        if (!$is_valid) {
            $error = $f_fw->errors;
        } else {
            $status = get_option('pg_registered_pending') ? 3 : 1;
            $allow_wp_sync_fail = !get_option('pg_require_wps_registration') ? true : false;
            // if no categories field - use forced or default ones
            if (!isset($fdata['categories'])) {
                $fdata['categories'] = isset($_POST['pc_cc']) && !empty($_POST['pc_cc']) ? explode(',', $_POST['pc_cc']) : get_option('pg_registration_cat');
                if (isset($_POST['pc_cc']) && !empty($_POST['pc_cc'])) {
                    $GLOBALS['pc_escape_no_reg_cats'] = true;
                }
                // flag to bypass reg cats restrictions
            }
            // private page switch - put in form data
            $fdata['disable_pvt_page'] = get_option('pg_registered_pvtpage') ? 0 : 1;
            // insert user
            $result = $pc_users->insert_user($fdata, $status, $allow_wp_sync_fail);
            if (!$result) {
                $error = $pc_users->validation_errors;
            }
        }
        // results
        if (isset($error) && !empty($error)) {
            $mess = json_encode(array('resp' => 'error', 'mess' => $error));
            die($mess);
        } else {
            // PC-ACTION - registered user - passes new user ID and status
            do_action('pc_registered_user', $result, $status);
            // success message
            $mess = json_encode(array('resp' => 'success', 'mess' => pc_get_message('pc_default_sr_mex'), 'redirect' => pc_man_redirects('pg_registered_user_redirect')));
            die($mess);
        }
        die;
        // security block
    }
}
Beispiel #4
0
function pc_logout_user()
{
    if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'pc_logout' || isset($_REQUEST['pc_logout']) || isset($_REQUEST['pg_logout'])) {
        include_once PC_DIR . '/functions.php';
        $GLOBALS['pc_is_logging_out'] = true;
        pc_logout();
        // if logging out through URL parameter - stop here
        if (!isset($_REQUEST['type'])) {
            return true;
        }
        // check if a redirect is needed
        echo pc_man_redirects('pg_logout_user_redirect');
        die;
    }
}