Your IP : 216.73.217.176


Current Path : /home/bechata/mp/wp-content/uploads/2022/ejn73c/
Upload File :
Current File : /home/bechata/mp/wp-content/uploads/2022/ejn73c/classes.tar

db-restore.php000066600000017465151764271220007353 0ustar00<?php
/**
 * Define database parameters here
 */
$upload_dir = wp_upload_dir();
$backup_dirname = $upload_dir['basedir'].'/wp-file-manager-pro/fm_backup';
define("BACKUP_DIR", $backup_dirname);
define("CHARSET", 'utf8');
define("DISABLE_FOREIGN_KEY_CHECKS", true);

/**
 * The Restore_Database class
 */
class Restore_Database {
    /**
     * Host where the database is located
     */
    var $host;

    /**
     * Username used to connect to database
     */
    var $username;

    /**
     * Password used to connect to database
     */
    var $passwd;

    /**
     * Database to backup
     */
    var $dbName;

    /**
     * Database charset
     */
    var $charset;

    /**
     * Database connection
     */
    var $conn;

    /**
     * Disable foreign key checks
     */
    var $disableForeignKeyChecks;

    /**
     * Constructor initializes database
     */
    function __construct($filename) {
        $this->host                    = DB_HOST;
        $this->username                = DB_USER;
        $this->passwd                  = DB_PASSWORD;
        $this->dbName                  = DB_NAME;
        $this->charset                 = DB_CHARSET;
        $this->disableForeignKeyChecks = defined('DISABLE_FOREIGN_KEY_CHECKS') ? DISABLE_FOREIGN_KEY_CHECKS : true;
        $this->conn                    = $this->initializeDatabase();
        $this->backupDir               = defined('BACKUP_DIR') ? BACKUP_DIR : '.';
        $this->backupFile              = $filename;
    }

    /**
     * Destructor re-enables foreign key checks
     */
    function __destructor() {
        /**
         * Re-enable foreign key checks 
         */
        if ($this->disableForeignKeyChecks === true) {
            mysqli_query($this->conn, 'SET foreign_key_checks = 1');
        }
    }

    protected function initializeDatabase() {
        try {
            $conn = mysqli_connect($this->host, $this->username, $this->passwd, $this->dbName);
            if (mysqli_connect_errno()) {
                throw new Exception('ERROR connecting database: ' . mysqli_connect_error());
                die();
            }
            if (!mysqli_set_charset($conn, $this->charset)) {
                mysqli_query($conn, 'SET NAMES '.$this->charset);
            }

            /**
             * Disable foreign key checks 
             */
            if ($this->disableForeignKeyChecks === true) {
                mysqli_query($conn, 'SET foreign_key_checks = 0');
            }

        } catch (Exception $e) {
            print_r($e->getMessage());
            die();
        }

        return $conn;
    }

    /**
     * Backup the whole database or just some tables
     * Use '*' for whole database or 'table1 table2 table3...'
     * @param string $tables
     */
    public function restoreDb() {
        try {
            $sql = '';
            $multiLineComment = false;

            $backupDir = $this->backupDir;
            $backupFile = $this->backupFile;

            /**
             * Gunzip file if gzipped
             */
            $backupFileIsGzipped = substr($backupFile, -3, 3) == '.gz' ? true : false;
            if ($backupFileIsGzipped) {
                if (!$backupFile = $this->gunzipBackupFile()) {
                    throw new Exception("ERROR: couldn't gunzip backup file " . $backupDir . '/' . $backupFile);
                }
            }

            /**
            * Read backup file line by line
            */
            $handle = fopen($backupDir . '/' . $backupFile, "r");
            if ($handle) {
                while (($line = fgets($handle)) !== false) {
                    $line = ltrim(rtrim($line));
                    if (strlen($line) > 1) { // avoid blank lines
                        $lineIsComment = false;
                        if (preg_match('/^\/\*/', $line)) {
                            $multiLineComment = true;
                            $lineIsComment = true;
                        }
                        if ($multiLineComment or preg_match('/^\/\//', $line)) {
                            $lineIsComment = true;
                        }
                        if (!$lineIsComment) {
                            $sql .= $line;
                            if (preg_match('/;$/', $line)) {
                                // execute query
                                if(mysqli_query($this->conn, $sql)) {
                                    if (preg_match('/^CREATE TABLE `([^`]+)`/i', $sql, $tableName)) {
                                        $this->obfPrint("Table succesfully created: `" . $tableName[1] . "`");
                                    }
                                    $sql = '';
                                } else {
                                    throw new Exception("ERROR: SQL execution error: " . mysqli_error($this->conn));
                                }
                            }
                        } else if (preg_match('/\*\/$/', $line)) {
                            $multiLineComment = false;
                        }
                    }
                }
                fclose($handle);
            } else {
                throw new Exception("ERROR: couldn't open backup file " . $backupDir . '/' . $backupFile);
            } 
        } catch (Exception $e) {
            print_r($e->getMessage());
            return false;
        }

        if ($backupFileIsGzipped) {
            unlink($backupDir . '/' . $backupFile);
        }

        return true;
    }

    /*
     * Gunzip backup file
     *
     * @return string New filename (without .gz appended and without backup directory) if success, or false if operation fails
     */
    protected function gunzipBackupFile() {
        // Raising this value may increase performance
        $bufferSize = 4096; // read 4kb at a time
        $error = false;

        $source = $this->backupDir . '/' . $this->backupFile;
        $dest = $this->backupDir . '/' . date("Ymd_His", time()) . '_' . substr($this->backupFile, 0, -3);

        $this->obfPrint('Gunzipping backup file ' . $source . '... ', 1, 1);

        // Remove $dest file if exists
        if (file_exists($dest)) {
            if (!unlink($dest)) {
                return false;
            }
        }
        
        // Open gzipped and destination files in binary mode
        if (!$srcFile = gzopen($this->backupDir . '/' . $this->backupFile, 'rb')) {
            return false;
        }
        if (!$dstFile = fopen($dest, 'wb')) {
            return false;
        }

        while (!gzeof($srcFile)) {
            // Read buffer-size bytes
            // Both fwrite and gzread are binary-safe
            if(!fwrite($dstFile, gzread($srcFile, $bufferSize))) {
                return false;
            }
        }

        fclose($dstFile);
        gzclose($srcFile);

        // Return backup filename excluding backup directory
        return str_replace($this->backupDir . '/', '', $dest);
    }

    /**
     * Prints message forcing output buffer flush
     *
     */
    public function obfPrint ($msg = '', $lineBreaksBefore = 0, $lineBreaksAfter = 1) {
        if (!$msg) {
            return false;
        }

        $msg = date("Y-m-d H:i:s") . ' - ' . $msg;
        $output = '';

        if (php_sapi_name() != "cli") {
            $lineBreak = "<br />";
        } else {
            $lineBreak = "\n";
        }

        if ($lineBreaksBefore > 0) {
            for ($i = 1; $i <= $lineBreaksBefore; $i++) {
                $output .= $lineBreak;
            }                
        }

        $output .= $msg;

        if ($lineBreaksAfter > 0) {
            for ($i = 1; $i <= $lineBreaksAfter; $i++) {
                $output .= $lineBreak;
            }                
        }

        if (php_sapi_name() == "cli") {
            $output .= "\n";
        }

        echo $output;

        if (php_sapi_name() != "cli") {
            ob_flush();
        }

        flush();
    }
}
files-backup.php000066600000005647151764271220007651 0ustar00<?php 
class wp_file_manager_files_backup {

    public function zipData($source, $destination) {
        if (extension_loaded('zip') === true) {
            if (file_exists($source) === true) {
                $zip = new ZipArchive();
                if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
                    $source = realpath($source);
                    if (is_dir($source) === true) {
                        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
                        foreach ($files as $file) {
                          if(strpos($file,'fm_backup') === false && (strpos($file,'opt') === false || strpos($file,'opt'))) {
                            $file = realpath($file);
                            if (is_dir($file) === true) {
                                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                            } else if (is_file($file) === true) {
                                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                            }
                          }
                        }
                    } else if (is_file($source) === true) {
                        $zip->addFromString(basename($source), file_get_contents($source));
                    }
                }
                return $zip->close();
            }
        }
        return false;
    }
    public function zipOther($source, $destination) {
        if (extension_loaded('zip') === true) {
            if (file_exists($source) === true) {
                $zip = new ZipArchive();
                if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) {
                    $source = realpath($source);
                    if (is_dir($source) === true) {
                        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);                        
                        foreach ($files as $file) {     
                         if(strpos($file,'themes') === false && strpos($file,'uploads') === false && strpos($file,'plugins') === false){
                            $file = realpath($file);
                            if (is_dir($file) === true) {
                                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                            } else if (is_file($file) === true) {
                                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                            }
                         }

                        }
                    } else if (is_file($source) === true) {
                        $zip->addFromString(basename($source), file_get_contents($source));
                    }
                }
                return $zip->close();
            }
        }
        return false;
    }
}files-restore.php000066600000001146151764271220010055 0ustar00<?php
class wp_file_manager_files_restore {

   public function extract($source, $destination) {
      if (extension_loaded('zip') === true) {
            if (file_exists($source) === true) {
                $zip = new ZipArchive();
                $res = $zip->open($source);
                if ($res === TRUE) {
                    $zip->extractTo($destination);
                    $zip->close();
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        return false;
   }

}db-backup.php000066600000026520151764271220007125 0ustar00<?php 
/**
 * Define database parameters here
 */
$upload_dir = wp_upload_dir();
$backup_dirname = $upload_dir['basedir'].'/wp-file-manager-pro/fm_backup';
define("BACKUP_DIR", $backup_dirname); // Comment this line to use same script's directory ('.')
define("TABLES", '*'); // Full backup
define("CHARSET", 'utf8');
define("GZIP_BACKUP_FILE", true); // Set to false if you want plain SQL backup files (not gzipped)
define("DISABLE_FOREIGN_KEY_CHECKS", true); // Set to true if you are having foreign key constraint fails
define("BATCH_SIZE", 1000); // Batch size when selecting rows from database in order to not exhaust system memory
                            // Also number of rows per INSERT statement in backup file
/**
 * The Backup_Database class
 */
class Backup_Database {
    /**
     * Host where the database is located
     */
    var $host;

    /**
     * Username used to connect to database
     */
    var $username;

    /**
     * Password used to connect to database
     */
    var $passwd;

    /**
     * Database to backup
     */
    var $dbName;

    /**
     * Database charset
     */
    var $charset;

    /**
     * Database connection
     */
    var $conn;

    /**
     * Backup directory where backup files are stored 
     */
    var $backupDir;

    /**
     * Output backup file
     */
    var $backupFile;

    /**
     * Use gzip compression on backup file
     */
    var $gzipBackupFile;

    /**
     * Content of standard output
     */
    var $output;

    /**
     * Disable foreign key checks
     */
    var $disableForeignKeyChecks;

    /**
     * Batch size, number of rows to process per iteration
     */
    var $batchSize;

    /**
     * Constructor initializes database
     */
    public function __construct($filename) {
        $this->host                    = DB_HOST;
        $this->username                = DB_USER;
        $this->passwd                  = DB_PASSWORD;
        $this->dbName                  = DB_NAME;
        $this->charset                 = DB_CHARSET;
        $this->conn                    = $this->initializeDatabase();
        $this->backupDir               = BACKUP_DIR ? BACKUP_DIR : '.';
        $this->backupFile              = $filename.'-db.sql';
        $this->gzipBackupFile          = defined('GZIP_BACKUP_FILE') ? GZIP_BACKUP_FILE : true;
        $this->disableForeignKeyChecks = defined('DISABLE_FOREIGN_KEY_CHECKS') ? DISABLE_FOREIGN_KEY_CHECKS : true;
        $this->batchSize               = defined('BATCH_SIZE') ? BATCH_SIZE : 1000; // default 1000 rows
        $this->output                  = '';
    }

    protected function initializeDatabase() {
        try {
            $conn = mysqli_connect($this->host, $this->username, $this->passwd, $this->dbName);
            if (mysqli_connect_errno()) {
                throw new Exception('ERROR connecting database: ' . mysqli_connect_error());
                die();
            }
            if (!mysqli_set_charset($conn, $this->charset)) {
                mysqli_query($conn, 'SET NAMES '.$this->charset);
            }
        } catch (Exception $e) {
            print_r($e->getMessage());
            die();
        }

        return $conn;
    }

    /**
     * Backup the whole database or just some tables
     * Use '*' for whole database or 'table1 table2 table3...'
     * @param string $tables
     */
    public function backupTables($tables = '*', $bkpDir="") {
        try {
            /**
             * Tables to export
             */
            if($tables == '*') {
                $tables = array();
                $result = mysqli_query($this->conn, 'SHOW TABLES');
                while($row = mysqli_fetch_row($result)) {
                    $tables[] = $row[0];
                }
            } else {
                $tables = is_array($tables) ? $tables : explode(',', str_replace(' ', '', $tables));
            }

            $sql = 'CREATE DATABASE IF NOT EXISTS `'.$this->dbName."`;\n\n";
            $sql .= 'USE `'.$this->dbName."`;\n\n";

            /**
             * Disable foreign key checks 
             */
            if ($this->disableForeignKeyChecks === true) {
                $sql .= "SET foreign_key_checks = 0;\n\n";
            }

            /**
             * Iterate tables
             */
            foreach($tables as $table) {
                $this->obfPrint("Backing up `".$table."` table...".str_repeat('.', 50-strlen($table)), 0, 0);

                /**
                 * CREATE TABLE
                 */
                $sql .= 'DROP TABLE IF EXISTS `'.$table.'`;';
                $row = mysqli_fetch_row(mysqli_query($this->conn, 'SHOW CREATE TABLE `'.$table.'`'));
                $sql .= "\n\n".$row[1].";\n\n";

                /**
                 * INSERT INTO
                 */

                $row = mysqli_fetch_row(mysqli_query($this->conn, 'SELECT COUNT(*) FROM `'.$table.'`'));
                $numRows = $row[0];

                // Split table in batches in order to not exhaust system memory 
                $numBatches = intval($numRows / $this->batchSize) + 1; // Number of while-loop calls to perform

                for ($b = 1; $b <= $numBatches; $b++) {
                    
                    $query = 'SELECT * FROM `' . $table . '` LIMIT ' . ($b * $this->batchSize - $this->batchSize) . ',' . $this->batchSize;
                    $result = mysqli_query($this->conn, $query);
                    $realBatchSize = mysqli_num_rows ($result); // Last batch size can be different from $this->batchSize
                    $numFields = mysqli_num_fields($result);

                    if ($realBatchSize !== 0) {
                        $sql .= 'INSERT INTO `'.$table.'` VALUES ';

                        for ($i = 0; $i < $numFields; $i++) {
                            $rowCount = 1;
                            while($row = mysqli_fetch_row($result)) {
                                $sql.='(';
                                for($j=0; $j<$numFields; $j++) {
                                    if (isset($row[$j])) {
                                        $row[$j] = addslashes($row[$j]);
                                        $row[$j] = str_replace("\n","\\n",$row[$j]);
                                        $row[$j] = str_replace("\r","\\r",$row[$j]);
                                        $row[$j] = str_replace("\f","\\f",$row[$j]);
                                        $row[$j] = str_replace("\t","\\t",$row[$j]);
                                        $row[$j] = str_replace("\v","\\v",$row[$j]);
                                        $row[$j] = str_replace("\a","\\a",$row[$j]);
                                        $row[$j] = str_replace("\b","\\b",$row[$j]);
                                        if (preg_match('/^-?[0-9]+$/', $row[$j]) or $row[$j] == 'NULL' or $row[$j] == 'null') {
                                            $sql .= $row[$j];
                                        } else {
                                            $sql .= '"'.$row[$j].'"' ;
                                        }
                                    } else {
                                        $sql.= 'NULL';
                                    }
    
                                    if ($j < ($numFields-1)) {
                                        $sql .= ',';
                                    }
                                }
    
                                if ($rowCount == $realBatchSize) {
                                    $rowCount = 0;
                                    $sql.= ");\n"; //close the insert statement
                                } else {
                                    $sql.= "),\n"; //close the row
                                }
    
                                $rowCount++;
                            }
                        }
    
                        $this->saveFile($sql);
                        $sql = '';
                    }
                }
                $sql.="\n\n";

                $this->obfPrint('OK');
            }

            /**
             * Re-enable foreign key checks 
             */
            if ($this->disableForeignKeyChecks === true) {
                $sql .= "SET foreign_key_checks = 1;\n";
            }

            $this->saveFile($sql);

            if ($this->gzipBackupFile) {
                $this->gzipBackupFile();
            } else {
                $this->obfPrint('Backup file succesfully saved to ' . $this->backupDir.'/'.$this->backupFile, 1, 1);
            }
        } catch (Exception $e) {
            print_r($e->getMessage());
            return false;
        }

        return true;
    }

    /**
     * Save SQL to file
     * @param string $sql
     */
    protected function saveFile(&$sql) {
        if (!$sql) return false;

        try {

            if (!file_exists($this->backupDir)) {
                mkdir($this->backupDir, 0777, true);
            }

            file_put_contents($this->backupDir.'/'.$this->backupFile, $sql, FILE_APPEND | LOCK_EX);

        } catch (Exception $e) {
            print_r($e->getMessage());
            return false;
        }

        return true;
    }

    /*
     * Gzip backup file
     *
     * @param integer $level GZIP compression level (default: 9)
     * @return string New filename (with .gz appended) if success, or false if operation fails
     */
    protected function gzipBackupFile($level = 9) {
        if (!$this->gzipBackupFile) {
            return true;
        }

        $source = $this->backupDir . '/' . $this->backupFile;
        $dest =  $source . '.gz';

        $this->obfPrint('Gzipping backup file to ' . $dest . '... ', 1, 0);

        $mode = 'wb' . $level;
        if ($fpOut = gzopen($dest, $mode)) {
            if ($fpIn = fopen($source,'rb')) {
                while (!feof($fpIn)) {
                    gzwrite($fpOut, fread($fpIn, 1024 * 256));
                }
                fclose($fpIn);
            } else {
                return false;
            }
            gzclose($fpOut);
            if(!unlink($source)) {
                return false;
            }
        } else {
            return false;
        }
        
        $this->obfPrint('OK');
        return $dest;
    }

    /**
     * Prints message forcing output buffer flush
     *
     */
    public function obfPrint ($msg = '', $lineBreaksBefore = 0, $lineBreaksAfter = 1) {
        if (!$msg) {
            return false;
        }

        if ($msg != 'OK' and $msg != 'KO') {
            $msg = date("Y-m-d H:i:s") . ' - ' . $msg;
        }
        $output = '';

        if (php_sapi_name() != "cli") {
            $lineBreak = "<br />";
        } else {
            $lineBreak = "\n";
        }

        if ($lineBreaksBefore > 0) {
            for ($i = 1; $i <= $lineBreaksBefore; $i++) {
                $output .= $lineBreak;
            }                
        }

        $output .= $msg;

        if ($lineBreaksAfter > 0) {
            for ($i = 1; $i <= $lineBreaksAfter; $i++) {
                $output .= $lineBreak;
            }                
        }


        // Save output for later use
        $this->output .= str_replace('<br />', '\n', $output);

        return $output;


        if (php_sapi_name() != "cli") {
            if( ob_get_level() > 0 ) {
                ob_flush();
            }
        }

        $this->output .= " ";

        flush();
    }

    /**
     * Returns full execution output
     *
     */
    public function getOutput() {
        return $this->output;
    }
}class-wppcp-woocommerce-tab-manager.php000066600000015427151765001320014217 0ustar00<?php

class WPPCP_Woocommerce_Tab_Manager{

	public function __construct(){
		add_action( 'init',array($this,'register_woo_tabs'));
        add_action( 'add_meta_boxes', array($this,'woo_tabs_meta_box'));
        add_action( 'save_post', array($this,'save_woo_tabs'), 10, 3 );
        add_filter( 'woocommerce_product_tabs', array($this,'add_frontend_woo_tabs') );
	}

	public function register_woo_tabs(){
		register_post_type( WPPCP_WOO_TABS_POST_TYPE,
            array(
                'labels' => array(
                    'name'              => __('Woo Product Tabs','wppcp'),
                    'singular_name'     => __('Woo Product Tab','wppcp'),
                    'add_new'           => __('Add New','wppcp'),
                    'add_new_item'      => __('Add New Woo Product Tab','wppcp'),
                    'edit'              => __('Edit','wppcp'),
                    'edit_item'         => __('Edit Woo Product Tab','wppcp'),
                    'new_item'          => __('New Woo Product Tab','wppcp'),
                    'view'              => __('View','wppcp'),
                    'view_item'         => __('View Woo Product Tab','wppcp'),
                    'search_items'      => __('Search Woo Product Tab','wppcp'),
                    'not_found'         => __('No Woo Product Tab found','wppcp'),
                    'not_found_in_trash' => __('No Woo Product Tab found in Trash','wppcp'),
                ),

                'public' => true,
                'menu_position' => 100,
                'supports' => array( 'title','editor'),
                'has_archive' => true
            )
        );

	}


	public function save_woo_tabs($post_id){

        $skipped_types = array('attachment','revision','nav_menu_item');

        if ( ! isset( $_POST['wppcp_restriction_settings_nonce'] ) ) {
            return;
        }

        if ( ! wp_verify_nonce( $_POST['wppcp_restriction_settings_nonce'], 'wppcp_restriction_settings' ) ) {
            return;
        }

        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
        }

        if ( ! ( current_user_can( 'manage_options', $post_id ) || current_user_can( 'wppcp_manage_options', $post_id ) )) {
            return;
        }

        $visibility = isset( $_POST['wppcp_woo_tabs_visibility'] ) ? sanitize_text_field( $_POST['wppcp_woo_tabs_visibility'] ) : 'none';        
        $visible_roles = isset( $_POST['wppcp_woo_tabs_roles'] ) ? (array) $_POST['wppcp_woo_tabs_roles'] : array();

        $visible_roles_filtered = array();
        foreach ($visible_roles as $key => $value) {
            $visible_roles_filtered[$key] = sanitize_text_field($value);
        }


        update_post_meta( $post_id, '_wppcp_woo_tabs_visibility', $visibility );
        update_post_meta( $post_id, '_wppcp_woo_tabs_roles', $visible_roles_filtered );
        

    }   

    public function woo_tabs_meta_box(){

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') || apply_filters('wppcp_restriction_setting_meta_box_visibility',false,array() ) ){
                add_meta_box(
                    'wppcp-woo-product-tab-restrictions',
                    __( 'WP Private Content Plus - WooCommrce Product Tab Settings', 'wppcp' ),
                    array($this,'add_woo_tabs_restrictions'),
                    'wppcp_fproduct_tabs',
                    'normal',
                    'low'
                );
        }

    } 

    public function add_woo_tabs_restrictions($post){
        global $wppcp,$woo_tabs_restriction_params;

        $wppcp->settings->load_wppcp_select2_scripts_style();

        $woo_tabs_restriction_params['post'] = $post;

        ob_start();
        $wppcp->template_loader->get_template_part('woo-tabs-restriction-meta');    
        $display = ob_get_clean();  
        echo $display;

    }       

    
    public function add_frontend_woo_tabs( $tabs ) {
        global $wppcp;

        $query = new WP_Query( array( 
            'post_type' => WPPCP_WOO_TABS_POST_TYPE,
            'post_status' => 'publish',
            'posts_per_page' => 25,
             ) );

        if ( $query->have_posts() ) {
            while ($query->have_posts()) : $query->the_post();

                $product_tab_id = get_the_ID();
                if($this->protection_status($product_tab_id)){
                    $tabs['wppcp_woo_'.$product_tab_id] = array(
                        'title'     => __( get_the_title() , 'wppcp' ),
                        'priority'     => 150,
                        'callback'  => array($this, 'woo_new_product_tab_content')
                    );
                }
                
            endwhile;
            wp_reset_query();

            
        }

        return $tabs;
    }

    public function woo_new_product_tab_content($key,$tab)  {
        $post_id = str_replace("wppcp_woo_", "", $key);
        $product_tab = get_post($post_id);
        echo do_shortcode($product_tab->post_content);
    }

    public function protection_status($post_id){
        global $wppcp;

        $visibility = get_post_meta( $post_id, '_wppcp_woo_tabs_visibility', true );
        $visible_roles = get_post_meta( $post_id, '_wppcp_woo_tabs_roles', true );
        if(!is_array($visible_roles)){
            $visible_roles = array();
        }

        switch ($visibility) {
            case 'all':
                return TRUE;
                break;
            
            case 'guest':
                if(is_user_logged_in()){
                    return FALSE;
                }else{
                    return TRUE;
                }
                break;

            case 'member':
                if(is_user_logged_in()){
                    return TRUE;
                }else{
                    return FALSE;
                }
                break;

            case 'role':
                if(is_user_logged_in()){
                    if(count($visible_roles) == 0){
                        return FALSE;
                    }else{
                        $user_roles = $wppcp->roles_capability->get_user_roles_by_id(get_current_user_id());
                        foreach ($visible_roles as  $visible_role ) {
                            if(in_array($visible_role, $user_roles)){
                                return TRUE;
                            }
                        }
                        return FALSE;
                    }
                }else{
                    return FALSE;
                }
                
                break;
                
            

            default:
                return "none";
                break;
        }

        return TRUE;
    }
}


class-wppcp-ip-restrictions.php000066600000007264151765001320012662 0ustar00<?php

class WPPCP_IP_Restrictions{
	public function __construct(){

		add_action('init', array($this, 'validate_ip_restrictions'), 1); 
	}

	public function validate_ip_restrictions(){
		global $wppcp,$wp_query,$wppcp_cpt_id;;
        $private_content_settings  = get_option('wppcp_options');
        if(!isset($private_content_settings['general']['private_content_module_status'])){
            return;        
        }

        $this->current_user = wp_get_current_user();
        if(is_user_logged_in() && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') )){
            return;
        }

        $data = isset($private_content_settings['security_ip']) ? $private_content_settings['security_ip'] : array();
                
        $restriction_status = isset($data['restriction_status']) ? $data['restriction_status'] : '';
        $allowed_urls = isset($data['allowed_urls']) ? $data['allowed_urls'] : '';
        $whitelisted = isset($data['whitelisted']) ? $data['whitelisted'] : '';
        $redirect_url = isset($data['redirect_url']) ? $data['redirect_url'] : site_url();

        


        if($restriction_status != 'disabled'){

        	$allowed_urls = explode(PHP_EOL, $allowed_urls);
	        $filtered_allowed_urls = array();
	        foreach ($allowed_urls as $url) {
	            if($url != ''){
	            	$url = rtrim($url , '/');
	                array_push($filtered_allowed_urls, $url);
	            }
	        }

	        $skipped_urls = array( $redirect_url , wp_login_url(), wp_registration_url(), wp_lostpassword_url());
        	$filtered_allowed_urls = array_merge($filtered_allowed_urls,$skipped_urls);

	        $whitelisted = explode(PHP_EOL, $whitelisted);
	        $filtered_whitelisted = array();
	        foreach ($whitelisted as $ip) {
	            if($ip != ''){
	                array_push($filtered_whitelisted, $ip);
	            }
	        }

	        $current_page_url = wppcp_current_page_url();

	        $parsed_url = parse_url($current_page_url);
	        $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
	        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
	        $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
	        $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
	        $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
	        $pass     = ($user || $pass) ? "$pass@" : '';
	        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
	 
	        $current_page_trailing_slash_url = $scheme.$user.$pass.$host.$port.$path;
	        $current_page_url = rtrim($current_page_trailing_slash_url , '/');
	        $redirect_url = rtrim($redirect_url , '/');
	        $redirect_url = esc_url_raw($redirect_url);


        	$client_ip = wppcp_get_client_ip();
        	
        	if($current_page_url != esc_url($redirect_url) ){
	        	switch ($restriction_status) {
	        		case 'guests':
	        			if(!is_admin() && !is_user_logged_in()){
	        				if(!in_array($client_ip, $filtered_whitelisted)
	        					&& !in_array($current_page_url, $filtered_allowed_urls)){
	        					wp_redirect( $redirect_url );
	        					exit;
	        				}
	        			}
	        			break;
	        		
	        		case 'members':	        			
        				if(!in_array($client_ip, $filtered_whitelisted)
        					&& !in_array($current_page_url, $filtered_allowed_urls)){
        					wp_redirect( $redirect_url );
        					exit;
        				}	        			
	        			break;
	        	}
	        }

        
        }
        
	}
}

class-wppcp-groups.php000066600000037322151765001320011041 0ustar00<?php

class WPPCP_Groups{

	public function __construct(){
		add_action( 'init',array($this,'register_groups'));
        add_action( 'add_meta_boxes', array($this,'groups_meta_box'));
        add_action( 'wp_ajax_wppcp_load_group_setting_users', array($this, 'wppcp_load_group_setting_users'));
        add_action( 'save_post', array($this,'save_groups'), 10, 3 );
        add_action( 'wp_ajax_wppcp_remove_group_setting_users', array($this, 'wppcp_remove_group_setting_users'));
        
        add_filter( 'manage_edit-' . WPPCP_GROUPS_POST_TYPE . '_columns', array($this,'custom_columns'));
        add_action( 'manage_' . WPPCP_GROUPS_POST_TYPE . '_posts_custom_column', array( $this,'custom_column_values'), 10, 2 );

        add_action( 'delete_post', array($this,'delete_group_info'), 10 );
        add_action('restrict_manage_users', array($this,'add_group_filter_user_list'));
        add_filter('init', array($this,'add_user_group'));
        add_action('admin_notices', array($this,'bulk_admin_notices'));
	}

	public function register_groups(){
		register_post_type( WPPCP_GROUPS_POST_TYPE,
            array(
                'labels' => array(
                    'name'              => __('Groups','wppcp'),
                    'singular_name'     => __('Group','wppcp'),
                    'add_new'           => __('Add New','wppcp'),
                    'add_new_item'      => __('Add New Group','wppcp'),
                    'edit'              => __('Edit','wppcp'),
                    'edit_item'         => __('Edit Group','wppcp'),
                    'new_item'          => __('New Group','wppcp'),
                    'view'              => __('View','wppcp'),
                    'view_item'         => __('View Group','wppcp'),
                    'search_items'      => __('Search Group','wppcp'),
                    'not_found'         => __('No Group found','wppcp'),
                    'not_found_in_trash' => __('No Group found in Trash','wppcp'),
                ),

                'public' => true,
                'menu_position' => 100,
                'supports' => array( 'title','editor'),
                'has_archive' => true
            )
        );

	}

    public function groups_meta_box(){

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') || apply_filters('wppcp_groups_setting_meta_box_visibility',false,array() ) ){
        
            add_meta_box(
                        'wppcp-groups-general',
                        __( 'WP Private Content Plus - Add New Users', 'wppcp' ),
                        array($this,'add_group_user'),
                        WPPCP_GROUPS_POST_TYPE,
                        'normal',
                        'high'
                    );

            add_meta_box(
                        'wppcp-groups-users',
                        __( 'WP Private Content Plus - Group Members', 'wppcp' ),
                        array($this,'list_group_user'),
                        WPPCP_GROUPS_POST_TYPE,
                        'normal',
                        'high'
                    );
        }
    }

    public function add_group_user($post, $metabox){
        global $wppcp;

        $wppcp->settings->load_wppcp_select2_scripts_style();

        $placeholder = __('Start typing username or email to Add New Members','wppcp');
        $display = "<div class='wppcp-select2-full-setting'><select data-group-id='".$post->ID."' multiple class='wppcp-select2-setting wppcp-select2-full-setting' style='width:100%' placeholder='".$placeholder."' name='wppcp_backend_group_add_new_member[]' id='wppcp_backend_group_add_new_member' ></select></div>";

        $display .= '<input type="hidden" name="wppcp_backend_group_add_new_member_nonce" value="'.wp_create_nonce( 'wppcp-backend-group-add-new-member-nonce' ).' " />';
        echo $display;
    }

    public function list_group_user($post, $metabox){
        global $wpdb;

        $group_list_page = isset($_GET['group_list_page']) ? (int) $_GET['group_list_page'] : 1;
        $limit = 10;
        $group_list_next = ($group_list_page)*$limit;
        $group_list_start = ($group_list_page - 1)*$limit;
        $limit_str = " limit $group_list_start,$limit ";

        $sql_total  = $wpdb->prepare( "SELECT usr.*,gru.user_id,gru.group_id FROM {$wpdb->prefix}users as usr inner join {$wpdb->prefix}wppcp_group_users as gru on usr.ID=gru.user_id WHERE group_id = %d  ", $post->ID );
        $result_total = $wpdb->get_results($sql_total);
        if($result_total){

            $sql  = $wpdb->prepare( "SELECT usr.*,gru.user_id,gru.group_id  FROM {$wpdb->prefix}users as usr inner join {$wpdb->prefix}wppcp_group_users as gru on usr.ID=gru.user_id WHERE group_id = %d  $limit_str", $post->ID );
            $result = $wpdb->get_results($sql);

            $display = "";
            $display .= "<div class='wppcp-admin-group-list-header' >
                            <div class='wppcp-admin-group-list-header-item' >".__('ID','wppcp')."</div>
                            <div class='wppcp-admin-group-list-header-item' >".__('Name','wppcp')."</div>
                            <div class='wppcp-admin-group-list-header-item' ></div>
                            <div class='wppcp-clear' ></div>
                        </div>";
            $group_users = array();
            if($result && is_array($result)){  
                foreach($result as $row){
                    $display .= "<div class='wppcp-admin-group-list-values' >
                                    <div class='wppcp-admin-group-list-value wppcp-admin-group-list-id' >".$row->user_id."</div>
                                    <div class='wppcp-admin-group-list-value ' ><span>".get_avatar($row->user_id, 30)."</span><span class='wppcp-admin-group-list-name'>".esc_html($row->display_name)."</span></div>
                                    <div class='wppcp-admin-group-list-value wppcp-admin-group-list-control' ><a href='javascript:void(0)' data-group-id='".$row->group_id."' data-user-id='".$row->user_id."' class='wppcp-admin-group-list-remove'>".__('Remove from Group','wppcp')."</a></div>
                                    <div class='wppcp-clear' ></div>
                                </div>";
                }
            }

            if($group_list_page > 1)
                $display .= "<a style='float:left' class='button button-primary button-large' href='".get_edit_post_link( $post->ID)."&group_list_page=".($group_list_page-1)."'>". __('Previous','wppcp')."</a>";


            if(count($result_total) > $group_list_next)
                $display .= "<a style='float:right' class='button button-primary button-large' href='".get_edit_post_link( $post->ID)."&group_list_page=".($group_list_page+1)."'>".__('Next','wppcp')."</a>";

            $display .= "<div class='wppcp-clear' ></div>";
            echo $display;
        }else{
            $display  = "<div class='wppcp-group-empty-users' >".__('No Users Found','wppcp')."</div>";
            $display .= "<div class='wppcp-clear' ></div>";
            echo $display;
        }

        
    }

    /* Get the users for the private page content form */
    public function wppcp_load_group_setting_users(){
        global $wpdb,$post;

        if( (current_user_can('manage_options') || current_user_can('wppcp_manage_options'))
         && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false )  ){

            $search_text  = isset($_POST['q']) ? sanitize_text_field( $_POST['q'] )  : '';
            $group_id = isset($_POST['group_id']) ? (int) $_POST['group_id'] : '';

            $sql  = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppcp_group_users WHERE group_id = %d", $group_id );
            $result = $wpdb->get_results($sql);

            $group_users = array();
            if($result && is_array($result)){  
                foreach($result as $row){
                    array_push($group_users, intval($row->user_id));
                }
            }
            
            $args = array('number' => 20);
            if($search_text != ''){
                $args['search'] = "*".$search_text."*";
            }
            
            $user_results = array();
            $user_json_results = array();
            
            $user_query = new WP_User_Query( $args );
            $user_results = $user_query->get_results();

            foreach($user_results as $user){
                if($user->ID != $this->current_user && !in_array($user->ID, $group_users)){
                    array_push($user_json_results , array('id' => $user->ID, 'name' => $user->data->display_name." (".$user->data->user_email.")") ) ;
                }                           
            }

        }else{
            $user_json_results = array();
        }
    
        echo json_encode(array('items' => $user_json_results ));exit;
    }  

	public function save_groups($post_id, $post, $update){
        global $wpdb;

        if ( WPPCP_GROUPS_POST_TYPE != $post->post_type ) {
            return;
        }

        $nonce = isset($_POST['wppcp_backend_group_add_new_member_nonce']) ? 
            sanitize_text_field($_POST['wppcp_backend_group_add_new_member_nonce']) : '';

        if ( isset($_POST['wppcp_backend_group_add_new_member_nonce']) && ! wp_verify_nonce( $nonce, 'wppcp-backend-group-add-new-member-nonce' ) ) {
            return;
        } 

        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
        }

        if ( ! ( current_user_can( 'manage_options', $post_id ) || current_user_can( 'wppcp_manage_options', $post_id ) ) ) {
            return;
        }

        if ( isset( $_REQUEST['wppcp_backend_group_add_new_member'] ) ) {
            $group_members = (array) $_REQUEST['wppcp_backend_group_add_new_member'];
            
            foreach ($group_members as $key => $group_member) {
                $group_member = (int) $group_member;
                $sql  = $wpdb->prepare( "Insert into {$wpdb->prefix}wppcp_group_users(group_id,user_id,updated_at) values(%d,%d,'%s')", $post_id , $group_member, date("Y-m-d H:i:s"));
                
                $result = $wpdb->get_results($sql);
            }
        }

        update_post_meta( $post_id , 'wppcp_group_type' , 'Administrative');
        
    }

    public function wppcp_remove_group_setting_users(){
        global $wpdb,$post;

        if( ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') )
         && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){

            $group_id = isset($_POST['group_id']) ? (int) $_POST['group_id'] : '0';
            $user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : '0';

            $sql  = $wpdb->prepare( "Delete FROM {$wpdb->prefix}wppcp_group_users WHERE group_id = %d AND user_id=%d", $group_id, $user_id );
            $result = $wpdb->get_results($sql);

            echo json_encode(array('status' => 'success' ));exit;

        }else{
            echo json_encode(array('status' => 'error' ));exit;
        }
        
    }

    public function custom_columns( $columns ) {

        $columns = array(
            'cb' => '<input type="checkbox" />',
            'title' => __('Title','wppcp'),
            'wppcp_group_id' => __( 'Group ID','wppcp' ),
            'date' => __( 'Dates','wppcp' )
        );

        return $columns;
    }

    public function custom_column_values($column, $post_id ) {
        global $post;

        switch( $column ) {

          case 'wppcp_group_id' :
                echo (int) $post_id;
                break;

          default :
            break;
       }
        
    }

    public function get_user_groups_by_id($user_id){
        global $wpdb;

        $sql  = $wpdb->prepare( "Select * FROM {$wpdb->prefix}wppcp_group_users WHERE user_id=%d", $user_id );
        $result = $wpdb->get_results($sql);

        $user_groups = array();

        if($result){
            foreach ($result as $key => $value) {
               array_push($user_groups, $value->group_id );
            }
        }

        return $user_groups;
    }


    public function delete_group_info($post_id){
        global $wpdb;

        if ( ! ( current_user_can( 'manage_options', $post_id ) ||
            current_user_can( 'wppcp_manage_options', $post_id ) ) ) {
            return;
        }

        $sql  = $wpdb->prepare( "Delete FROM {$wpdb->prefix}wppcp_group_users WHERE group_id=%d", $post_id );
        $result = $wpdb->get_results($sql);

    }

    public function add_group_filter_user_list($name){

        $group_select = '<select name="wppcp_user_list_group_%s" style="float:none;margin-left:10px;">
    <option value="">%s</option>%s</select>';


        $query = new WP_Query( array( 
            'post_type' => WPPCP_GROUPS_POST_TYPE,
            'post_status' => 'publish',
            'posts_per_page'=>-1    ) );

        $options = '';
        if ( $query->have_posts() ) {
            while ($query->have_posts()) : $query->the_post();            
                 $options .= '<option value="'.get_the_ID().'">'.get_the_title().'</option>';
            endwhile;
            wp_reset_query();
        }


        $select = sprintf( $group_select, $name, __( 'Select Group...', 'wppcp' ), $options );

        echo $select;
        echo wp_nonce_field( 'wppcp_user_assign_group_nonce', 'wppcp_user_assign_group_nonce_field' );
        submit_button(__( 'Assign Group','wppcp' ), null, 'wppcp_user_list_group_submit' , false);
    }

    public function add_user_group($query){
         global $pagenow,$wpdb;
         if ( (current_user_can('manage_options') || (current_user_can('wppcp_manage_options') ) ) 
            && isset($_POST['wppcp_user_assign_group_nonce_field']) && wp_verify_nonce( $_POST['wppcp_user_assign_group_nonce_field'], 'wppcp_user_assign_group_nonce' ) && is_admin() && 'users.php' == $pagenow 
            && isset($_REQUEST['wppcp_user_list_group_submit']) ) {

            $users = isset($_GET['users']) ?   (array) $_GET['users'] : array() ;
            $user_list_group = isset($_GET['wppcp_user_list_group_top']) ? (int) $_GET['wppcp_user_list_group_top'] : 0;

            if($user_list_group != 0) {
                foreach ($users as $user_id ) {
                    $user_id = (int) $user_id;
                    
                    $sql  = $wpdb->prepare( "Delete from {$wpdb->prefix}wppcp_group_users where group_id=%d and user_id=%d", $user_list_group , $user_id);
                    $result = $wpdb->get_results($sql);

                    $sql  = $wpdb->prepare( "Insert into {$wpdb->prefix}wppcp_group_users(group_id,user_id,updated_at) values(%d,%d,'%s')", $user_list_group , $user_id, date("Y-m-d H:i:s"));
                    $result = $wpdb->get_results($sql);
                }        
            }
         }
    }

    public function bulk_admin_notices(){

        $screen = get_current_screen();
        if ( $screen->id != "users" )   // Only add to users.php page
            return;

        $message = '';

        if((isset($_REQUEST['wppcp_user_list_group_submit'])) ) {
            $users = isset($_GET['users']) ?   (array) $_GET['users'] : array() ;
            $user_list_group = isset($_GET['wppcp_user_list_group_top']) ? (int) $_GET['wppcp_user_list_group_top'] : 0;
            if($user_list_group != 0 && count($users) > 0 ) {
                $message = __( 'Users added to group.','wppcp');
            }

        }

        if('' != $message){
            $html = '<div class="updated">
                        <p>'.$message.'</p>
                    </div>';
            echo $html; 
        }
        
    }
        
}


class-wppcp-password-protected-content.php000066600000014344151765001320015022 0ustar00<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

/* Manage content restriction shortcodes */
class WPPCP_Password_Protected_Content{
    
    public $current_user;
    public $private_content_settings;
    
    /* intialize the settings and shortcodes */
    public function __construct(){
        global $wppcp;

        add_action('init', array($this, 'init'));           
        add_filter('template_include', array($this, 'validate_restrictions'),99);         
    }

    public function init(){
        $this->current_user = get_current_user_id(); 
    }

    public function validate_restrictions($template){
        global $wppcp,$wp_query,$wppcp_password_protect_data;

        $private_content_settings  = get_option('wppcp_options');
        $password_settings = isset($private_content_settings['password_global']) ? $private_content_settings['password_global'] : array();
        $global_password_protect = isset($password_settings['global_password_protect']) ? $password_settings['global_password_protect'] : 'disabled';
        $site_password = isset($password_settings['global_protect_password']) ? $password_settings['global_protect_password'] : '';
        $protected_form_header = isset($password_settings['password_form_title']) ? $password_settings['password_form_title'] : __('Protected Content','wppcp');
        $protected_form_message = isset($password_settings['password_form_message']) ? $password_settings['password_form_message'] : __('This content is password protected. Please enter the password to view the content.','wppcp');
         
        $site_password_status = isset( $_COOKIE['wppcp_global_password_protected_status'] ) ? sanitize_text_field($_COOKIE['wppcp_global_password_protected_status']) : 'INACTIVE';
     

        if(!isset($private_content_settings['general']['private_content_module_status'])){
            return $template;        
        }

        if($global_password_protect == 'disabled'){
            return $template;
        }

        $this->current_user = wp_get_current_user();

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $template;
        } 

        $allowed_urls = isset($password_settings['allowed_urls']) ? $password_settings['allowed_urls'] : '';        
        $allowed_urls = explode(PHP_EOL, $allowed_urls );
        $current_page_url = wppcp_current_page_url();

        $parsed_url = parse_url($current_page_url);
        $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
        $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
        $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
        $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
        $pass     = ($user || $pass) ? "$pass@" : '';
        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
 
        $current_page_trailing_slash_url = $scheme.$user.$pass.$host.$port.$path;
        $current_page_url = rtrim($current_page_trailing_slash_url , '/');
   
        if(in_array($current_page_url, $allowed_urls) || in_array($current_page_trailing_slash_url, $allowed_urls)){
            return $template;
        }               


        if(is_home() || is_page() || is_single() || is_archive() || is_feed() || is_search() || is_404() ){
            if($global_password_protect == 'enabled_all_users'){
                $this->verify_global_password_protection($site_password);
                if($this->password_protect_status){
                    $site_password_status = 'ACTIVE';
                }

            }else if($global_password_protect == 'enabled_guest_users'){
                if(is_user_logged_in()){
                    return $template;
                }else{
                    $this->verify_global_password_protection($site_password);
                    if($this->password_protect_status){
                        $site_password_status = 'ACTIVE';
                    }
                }
            }

            if($site_password == ''){
            
            }else{
                if($site_password_status == 'ACTIVE'){
                    
                }else{
                    $wppcp_password_protect_data['protected_form_header'] = $protected_form_header;
                    $wppcp_password_protect_data['password_protect_error'] = $this->password_protect_error;
                    $wppcp_password_protect_data['protected_form_message'] = $protected_form_message;
                    $template = WPPCP_PLUGIN_DIR.'templates/global-password-form.php';
                }    
                
            }

        }

        
     
        return $template;
    }

    public function verify_global_password_protection($site_password){
        $site_password_status = isset( $_COOKIE['wppcp_global_password_protected_status'] ) ? sanitize_text_field($_COOKIE['wppcp_global_password_protected_status']) : 'INACTIVE';
           
        $this->password_protect_error = '';
        $this->password_protect_status = FALSE;
        if ( isset( $_POST['site_protect_password_submit'] ) ) {
            if ( ! isset( $_POST['wppcp_password_protect_nonce'] ) ) {
                $this->password_protect_status = FALSE;
                return;
            }

            if ( ! wp_verify_nonce( $_POST['wppcp_password_protect_nonce'], 'wppcp_password_protect' ) ) {
                $this->password_protect_status = FALSE;
                return;
            }

            $site_protect_password = isset($_POST['site_protect_password']) ? sanitize_text_field($_POST['site_protect_password']) : '';

            if(trim($site_password) == trim($site_protect_password) ){
                setcookie( 'wppcp_global_password_protected_status' , 'ACTIVE' , strtotime( '+1 year' ) , "/");
                $site_password_status = 'ACTIVE';
                $this->password_protect_status = TRUE;
            }else{
                $this->password_protect_error = __('Please enter valid password.','wppcp');
                $this->password_protect_status = FALSE;
            }
        }
    }
}class-wppcp-search.php000066600000006544151765001320010771 0ustar00<?php

class WPPCP_Search{

	public function __construct(){
		add_action('pre_get_posts', array($this,'search_restrictions'));
	}

	public function search_restrictions($query) {
		
		$wppcp_options = get_option('wppcp_options');

		if(isset($wppcp_options['general']['search_restrictions_module_status'])){    
         
			if ($query->is_search && $query->is_main_query() && !is_admin()) {	
				$search_blocked_ids = $this->get_globally_blocked_posts();
				$search_allowed_types = $this->verify_search_restrictions();

		   		$query->set('post__not_in', $search_blocked_ids );
		   		$query->set('post_type', $search_allowed_types );
			}
		}

		$query = apply_filters('wppcp_search_restrictions_query',$query, array('wppcp_options' => $wppcp_options) );

		return $query;
	}

	public function get_globally_blocked_posts(){
		global $wppcp;

		$wppcp_options = get_option('wppcp_options');

		if(!isset($wppcp_options['general']['private_content_module_status'])){
            return;        
        }


		$general_options =  isset($wppcp_options['search_general']) ? (array) $wppcp_options['search_general'] : array();
		$search_blocked_ids = array();

		$blocked_posts = isset( $general_options['blocked_post_search'] ) ? (array) $general_options['blocked_post_search'] : array();
		$blocked_pages = isset( $general_options['blocked_page_search'] ) ? (array) $general_options['blocked_page_search'] : array();

		$search_blocked_ids = array_merge($search_blocked_ids, $blocked_posts , $blocked_pages);

        $search_blocked_ids = apply_filters('wppcp_search_blocked_post_ids',$search_blocked_ids, array('general_options' => $general_options));
		
        
        return $search_blocked_ids;
	}

	public function verify_search_restrictions(){
		global $wppcp;

		$wppcp_options = get_option('wppcp_options');
		$data = isset($wppcp_options['search_restrictions']) ? $wppcp_options['search_restrictions'] : array() ;

		if(!isset($wppcp_options['general']['private_content_module_status'])){
            return;        
        }

        $allowed_types = array();
        if(!is_user_logged_in()){
        	// Guest
        	$everyone_search_types = isset($data['everyone_search_types']) ? (array) $data['everyone_search_types'] :array();
            $guests_search_types = isset($data['guests_search_types']) ? (array) $data['guests_search_types'] :array();
            $allowed_types = array_merge($allowed_types,$guests_search_types,$everyone_search_types);
        }else{
        	$user_id = get_current_user_id();
        	$roles = $wppcp->roles_capability->get_user_roles_by_id($user_id);

        	foreach ($roles as $role ) {
        		$role_search_types = isset($data[$role.'_search_types']) ? (array) $data[$role.'_search_types'] :array();
        	
                $allowed_types = array_merge($allowed_types,$role_search_types);
        	}

        	$everyone_search_types = isset($data['everyone_search_types']) ? (array) $data['everyone_search_types'] :array();
            
            $members_search_types = isset($data['members_search_types']) ? (array) $data['members_search_types'] :array();
            $allowed_types = array_merge($allowed_types,$members_search_types,$everyone_search_types);
        }

        $allowed_types = array_unique($allowed_types);
        
        return $allowed_types;

    }

}class-wppcp-private-content.php000066600000123042151765001320012637 0ustar00<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

/* Manage content restriction shortcodes */
class WPPCP_Private_Content{
    
    public $current_user;
    public $private_content_settings;
    
    /* intialize the settings and shortcodes */
    public function __construct(){
        global $wppcp;

        add_action('init', array($this, 'init'));            
      
        add_shortcode('wppcp_private_content', array($this,'private_content_block'));
        add_shortcode('wppcp_private_page', array($this,'private_content_page'));
        add_shortcode('wppcp_guest_content', array($this,'guest_content_block'));
        add_shortcode('wppcp_member_content', array($this,'member_content_block'));
        add_shortcode('wppcp_scheduled_content', array($this,'scheduled_content_block'));
        add_shortcode('wppcp_private_content_by_registration', array($this,'private_content_by_registration'));
        add_shortcode('wppcp_password_protected_content', array($this,'private_content_by_password'));
        add_shortcode('wppcp_woocommerce_product_content', array($this,'private_content_by_woocommerce_product'));
    
        add_shortcode('wppcp_user_restricted_posts', array($this,'user_restricted_posts'));
        add_shortcode('wppcp_user_role_restricted_posts', array($this,'user_role_restricted_posts'));

        add_action('init', array($this,'save_bulk_private_content_upload') );

    }

    public function init(){
        $this->current_user = get_current_user_id(); 

        $this->private_content_settings  = get_option('wppcp_options'); 
        if ( defined( 'upme_url' ) ) {
            if(isset($this->private_content_settings['upme_general']['private_content_tab_status'])){
                add_filter('upme_profile_tab_items', array($this,'profile_tab_items'),10,2);
                add_filter('upme_profile_view_forms',array($this,'profile_view_forms'),10,2);      
            }
        }
    }
    
    /* Display private content for logged in user */
    public function private_content_page($atts,$content){
        global $wppcp,$wpdb;
        if(isset($atts) && is_array($atts))
            extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }

        if(is_user_logged_in()){
            if(isset($user_id)){
                $user_id =  (int) $user_id;
            }else{
                $user_id =  $this->current_user;
            }

            $sql  = $wpdb->prepare( "SELECT content FROM " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE . " WHERE user_id = %d ", $user_id );
            $result = $wpdb->get_results($sql);

            if($result){
                return stripslashes(do_shortcode($result[0]->content));
            }else{
                return stripslashes(get_option('wppcp_parivate_page_starter_content'));
            }
        }
            
        return apply_filters('wppcp_private_page_empty_message' , __('No content found.','wppcp'));
        
    }

    /* Restrict content based on user roles, capabilities, user meta values */
    public function private_content_block($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }

        if(!is_array($atts)){
            $atts = array();
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => ''

     	), $atts));
        
        $user_id =  $this->current_user;
        $message = sanitize_text_field($message);
        
        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
        	return $this->get_restriction_message($atts,$content,$private_content_result);
        }
        
        $this->status = $this->guest_filter();
        if(!$this->status){
        	$private_content_result['status'] = false;
        	$private_content_result['type'] = 'guest';
        	return $this->get_restriction_message($atts,$content,$private_content_result);
        }
        
        $visibility = TRUE;
        $message    = '';
        
        // Filter conditions
        foreach ($atts as $sh_attr => $sh_value) {

            $sh_attr = sanitize_text_field($sh_attr);
            $sh_value = sanitize_text_field($sh_value);

        	switch ($sh_attr) {
	        	case 'allowed_roles':
	        		$this->status = $this->allowed_roles_filter($atts,$sh_value);
	        		$private_content_result['type'] = $sh_attr;
	        		break;

                case 'blocked_roles':
                    $this->status = $this->blocked_roles_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'allowed_capabilities':
                    $this->status = $this->allowed_capabilities_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'blocked_capabilities':
                    $this->status = $this->blocked_capabilities_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'allowed_meta_keys':
                    $this->status = $this->allowed_meta_key_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'allowed_groups':
                    $this->status = $this->allowed_group_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'blocked_groups':
                    $this->status = $this->blocked_group_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'allowed_users':
                    $this->status = $this->allowed_users_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'blocked_users':
                    $this->status = $this->blocked_users_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;
            }

            if(!$this->status){
                break;
            }
        }
        
        if(!$this->status){
            $private_content_result['status'] = false;        		
        }
        
        return $this->get_restriction_message($atts,$content,$private_content_result);
        
    }
    
    /* Check whether user is a guest or member */
    public function guest_filter(){
		if (!is_user_logged_in())
			return false;
		return true;
	}
    
    /* Filter allowed user roles and restrict content */
    public function allowed_roles_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

		$user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
        $roles = explode(',',$sh_value);
        
        // Checking for multiple roles
        if(is_array($roles) && count($roles) > 1){
            
            
            if(isset($role_operator) && strtoupper(trim($role_operator)) == 'AND'){
                $role_operator = 'AND';
            }else{
                $role_operator = 'OR';
            }
            
            $multiple_role_checker = 0;
            foreach ($roles as $role) {
                $role = sanitize_text_field($role);
                if($role_operator == 'OR'){
                    if(in_array($role, $user_roles)){
                        
                        return true;
                    }
                }else{
                    if(in_array($role, $user_roles)){
                        $multiple_role_checker++;
                        if($multiple_role_checker == count($roles) ){
                            
                            return true;
                        }
                    }
                }                
            }
        }
        
        // Checking for role levels
        if(is_array($roles) && count($roles) == 1){
            
            foreach ($roles as $role) {
                $role = sanitize_text_field($role);
                $role_level = explode('-',$role);
                if(count($role_level) == '2'){
                    
                    $role_hierarchy = isset($this->private_content_settings['role_hierarchy']['hierarchy']) ? $this->private_content_settings['role_hierarchy']['hierarchy'] : '';
                    if($role_hierarchy == ''){
                        return false;
                    }
                    
                    $user_role_level = $role_level[0];
                    $key = array_search($user_role_level, $role_hierarchy);
                    
                    switch($role_level[1]){
                        case 'plus':
                            $allowed_roles = array_slice($role_hierarchy, 0, (int)$key + 1);
                        
                            foreach($allowed_roles as $allowed_role){
                                if(in_array($allowed_role, $user_roles)){
                                   return true;
                                }
                            }
                            break;
                        case 'minus':
                            $allowed_roles = array_slice($role_hierarchy, $key);
                            foreach($allowed_roles as $allowed_role){
                                if(in_array($allowed_role, $user_roles)){
                                    return true;
                                }
                            }
                            break;
                    }
                }else{
                    if(in_array($role, $user_roles)){
                        return true;
                    }
                }                                
            }
        }

        
     
		return false;
    }

    /* Filter blocked user roles and restrict content */
    public function blocked_roles_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
        $roles = explode(',',$sh_value);
        
        // Checking for multiple roles
        if(is_array($roles) && count($roles) > 1){
            
            
            if(isset($role_operator) && strtoupper(trim($role_operator)) == 'AND'){
                $role_operator = 'AND';
            }else{
                $role_operator = 'OR';
            }
            
            $multiple_role_checker = 0;
            foreach ($roles as $role) {
                $role = sanitize_text_field($role);
                if($role_operator == 'OR'){
                    if(in_array($role, $user_roles)){
                        
                        return false;
                    }
                }else{
                    
                    if(in_array($role, $user_roles)){
                        $multiple_role_checker++;
                  
                        if($multiple_role_checker == count($roles) ){
                            
                            return false;
                        }
                    }
                }                
            }
        }
        
        // Checking for role levels
        if(is_array($roles) && count($roles) == 1){
            
            foreach ($roles as $role) {
                $role = sanitize_text_field($role);
                $role_level = explode('-',$role);
                if(count($role_level) == '2'){
                    
                    $role_hierarchy = isset($this->private_content_settings['role_hierarchy']['hierarchy']) ? $this->private_content_settings['role_hierarchy']['hierarchy'] : '';
                    if($role_hierarchy == ''){
                        return false;
                    }
                    
                    $user_role_level = $role_level[0];
                    $key = array_search($user_role_level, $role_hierarchy);
                    
                    switch($role_level[1]){
                        case 'plus':
                            $allowed_roles = array_slice($role_hierarchy, 0, (int)$key + 1);
                        
                            foreach($allowed_roles as $allowed_role){
                                if(in_array($allowed_role, $user_roles)){
                                   return false;
                                }
                            }
                            break;
                        case 'minus':
                            $allowed_roles = array_slice($role_hierarchy, $key);
                            foreach($allowed_roles as $allowed_role){
                                if(in_array($allowed_role, $user_roles)){
                                    return false;
                                }
                            }
                            break;
                    }
                }else{
                    if(in_array($role, $user_roles)){
                        return false;
                    }
                }                                
            }
        }

        
     
        return true;
    }

    /* Filter allowed capabilities and restrict content */
    public function allowed_capabilities_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        //$user_capabilities = $wppcp->roles_capability->get_user_capabilities_by_id($this->current_user);
        $capabilities = explode(',',$sh_value);
        
        // Checking for multiple capabilities
        if(is_array($capabilities) && count($capabilities) > 1){
            
            
            if(isset($capability_operator) && strtoupper(trim($capability_operator)) == 'AND'){
                $capability_operator = 'AND';
            }else{
                $capability_operator = 'OR';
            }
            
            $multiple_capability_checker = 0;
            foreach ($capabilities as $capability) {
                $capability = sanitize_text_field($capability);
                if($capability_operator == 'OR'){
                    if(current_user_can($capability)){                        
                        return true;
                    }
                }else{
                    if(current_user_can($capability)){ 
                        $multiple_capability_checker++;
                        if($multiple_capability_checker == count($capabilities) ){
                            
                            return true;
                        }
                    }
                }                
            }
        }
        
        // Checking for single capability
        if(is_array($capabilities) && count($capabilities) == 1){
            
            foreach ($capabilities as $capability) {
                $capability = sanitize_text_field($capability);
                if(current_user_can($capability)){     
                    return true;
                }
            
            }
        }

        
     
        return false;
    }

    /* Filter blocked capabilities and restrict content */
    public function blocked_capabilities_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $capabilities = explode(',',$sh_value);
        
        // Checking for multiple capabilities
        if(is_array($capabilities) && count($capabilities) > 1){
            
            
            if(isset($capability_operator) && strtoupper(trim($capability_operator)) == 'AND'){
                $capability_operator = 'AND';
            }else{
                $capability_operator = 'OR';
            }
            
            $multiple_capability_checker = 0;
            foreach ($capabilities as $capability) {
                $capability = sanitize_text_field($capability);
                if($capability_operator == 'OR'){
                    if(current_user_can($capability)){                        
                        return false;
                    }
                }else{
                    if(current_user_can($capability)){ 
                        $multiple_capability_checker++;
                        if($multiple_capability_checker == count($capabilities) ){
                            
                            return false;
                        }
                    }
                }                
            }
        }
        
        // Checking for single capability
        if(is_array($capabilities) && count($capabilities) == 1){
            
            foreach ($capabilities as $capability) {
                $capability = sanitize_text_field($capability);
                if(current_user_can($capability)){     
                    return false;
                }
            
            }
        }
     
        return true;
    }

    /* Filter allowed user meta keys and restrict content */
    public function allowed_meta_key_filter($args,$sh_value){
        extract($args);

        $meta_keys = explode(',',$sh_value);
        
        if(is_array($meta_keys)){
            $allowed_meta_values = isset($allowed_meta_values) ? $allowed_meta_values : '';
            $allowed_meta_operator = isset($allowed_meta_operator) ? strtolower($allowed_meta_operator) : 'AND';

            $meta_count = 0;
            $meta_values = explode(',',$allowed_meta_values);
            foreach ($meta_keys as $k => $meta_key) {
                $meta_key = sanitize_text_field($meta_key);
                $value = get_user_meta($this->current_user,trim($meta_key),true);

                if(count($meta_keys) == 1 && count($meta_values) > 1){
                    foreach ($meta_values as $meta_values_key => $meta_values_data) {
                        if(strtolower(trim($value)) == strtolower(trim($meta_values_data))){
                            return true;        
                        }
                    }
       
                }else{
     
                    if(strtoupper($allowed_meta_operator) == 'OR'){
                        if(strtolower(trim($value)) == strtolower(trim($meta_values[$k]))){
                            return true;        
                        }
                    }else{
                        if(strtolower(trim($value)) == strtolower(trim($meta_values[$k]))){
                            $meta_count++;
                            if($meta_count == count($meta_keys)){
                                return true;      
                            }        
                        }
                    }
                }
                
            }
        }

        
        
        return false;
    }
    
    /* Generate content restriction message */
    public function get_restriction_message($args,$content,$private_content_result){
		$display = null;

        /* Arguments */
        $defaults = array(
            'message' => ''
        );
        $args = wp_parse_args($args, $defaults);
        extract($args, EXTR_SKIP);

        /* Require login */
        if (!$private_content_result['status']) {
            $message = sanitize_text_field($message);
            if ($message != '') {

            	switch ($private_content_result['type']) {
            		case 'guest':
            			$display .= __('Login to access this content','wppcp');
            			break;
            		
            		case 'allowed_roles':
            		case 'blocked_roles':
            		case 'allowed_users':
            		case 'blocked_users':
            		case 'allowed_meta_key':
            		case 'blocked_meta_key':
                    case 'allowed_groups':
                    case 'blocked_groups':
                    case 'start_date':
                    case 'end_date':
                    case 'registered_before':
                    case 'registered_after':
		                $display .= $message;
		        		break;
		        	
                    case 'admin':
                        $display .= do_shortcode($content);
                        break;
            	}                

                               
            }else{

                $restriction_params = array( 'args' => $args, 'content' => $content, 'private_content_result' => $private_content_result);
                $display .= apply_filters('wppcp_content_restricted_default_message',__('You don\'t have permission to access this content','wppcp'),$restriction_params);
            }
        } else { 
            $display .= do_shortcode($content);
        }

        $restriction_params = array( 'args' => $args, 'content' => $content, 'private_content_result' => $private_content_result);
        $display = apply_filters('wppcp_content_restricted_message',$display, $restriction_params );

        return $display;
	}    

    public function guest_content_block($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => ''

        ), $atts));

        $message = sanitize_text_field($message);
        
        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }
        
        if($this->guest_filter()){
            return $message;
        }else{
            return do_shortcode($content);
        }      
        
    }

    public function member_content_block($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => ''

        ), $atts));
        
        $message = sanitize_text_field($message);

        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }
        
        if(!$this->guest_filter()){
            return $message;
        }else{
            return do_shortcode($content);
        }      
        
    }

    public function profile_tab_items($display,$params){
        extract($params);
        
        $userid = get_current_user_id();        
   
        if( is_user_logged_in() && ($userid == $id || current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) ){
            $display .= '<div class="upme-profile-tab" data-tab-id="upme-private-page-panel" >
                        <i class="upme-profile-icon upme-icon-lock"></i>
                        <div class="upme-profile-tab-title">'.apply_filters('wppcp_profile_tab_items_private_page_title', __('My Private Page','wppcp'),$params).'</div>
                    
                    </div>';
        }        

        return $display;
    }

    public function profile_view_forms($display,$params){
        extract($params);

        wp_enqueue_script('wppcp_front_js');

        if($view != 'compact'){
                   
            $display .= '<div id="upme-private-page-panel" class="upme-profile-tab-panel upme-private-page-panel upme-private-page-tab-panel" style="display:none;"  >
                            <div style="padding:20px;">'.do_shortcode("[wppcp_private_page user_id='".$id."' ]").'</div>       
                        </div>';
        
        }

        return $display;
    }

    public function allowed_group_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_groups = $wppcp->groups->get_user_groups_by_id($this->current_user);
        $groups = explode(',',$sh_value);

        if(is_array($groups) && count($groups) > 0){  
            foreach ($groups as $group) {
                $group = sanitize_text_field($group);
                if(in_array($group, $user_groups)){
                   return true;
                }             
            }
        }        
     
        return false;
    }

    public function blocked_group_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_groups = $wppcp->groups->get_user_groups_by_id($this->current_user);
        $groups = explode(',',$sh_value);

        if(is_array($groups) && count($groups) > 0){
            foreach ($groups as $group) {
                $group = sanitize_text_field($group);
                if(in_array($group, $user_groups)){
                   return false;
                }             
            }
        }        
     
        return true;
    }

    public function allowed_users_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_id = get_current_user_id();
        $users = explode(',',$sh_value);

        if(is_array($users) && count($users) > 0){  
            foreach ($users as $user) {
                $user = (int) $user;
                if($user == $user_id){
                   return true;
                }             
            }
        }        
     
        return false;
    }

    public function blocked_users_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_id = get_current_user_id();
        $users = explode(',',$sh_value);

        if(is_array($users) && count($users) > 0){  
            foreach ($users as $user) {
                $user = (int) $user;
                if($user == $user_id){
                   return false;
                }             
            }
        }        
     
        return true;
    }

    public function scheduled_content_block($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => ''

        ), $atts));

        $message = sanitize_text_field($message);
        
        $user_id =  $this->current_user;
        
        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }

        foreach ($atts as $sh_attr => $sh_value) {
            $sh_attr = sanitize_text_field($sh_attr);
            $sh_value = sanitize_text_field($sh_value);

            switch ($sh_attr) {
                case 'start_date':
                    $this->status = $this->start_date_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'end_date':
                    $this->status = $this->end_date_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;
            }
        }

        if(!$this->status){
            $private_content_result['status'] = false;              
        }else{
            $content = $this->private_content_block($atts,$content);
            return $content;
        }
        
        return $this->get_restriction_message($atts,$content,$private_content_result);
             
    }

    public function start_date_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $start_date = date("Y-m-d",strtotime($sh_value));
        $start_date = strtotime($start_date);
        $current_time = strtotime(date("Y-m-d H:i:s"));


        if($current_time >= $start_date){
            return true;
        }        
       
        return false;
    }

    public function end_date_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $end_date = date("Y-m-d",strtotime($sh_value));
        $end_date = strtotime($end_date);
        $current_time = strtotime(date("Y-m-d"));


        if($current_time <= $end_date){
            return true;
        }        
       
        return false;
    }

    public function private_content_by_registration($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => ''

        ), $atts));
        
        $user_id =  $this->current_user;

        $message = sanitize_text_field($message);
        
        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }

        foreach ($atts as $sh_attr => $sh_value) {

            $sh_attr = sanitize_text_field($sh_attr);
            $sh_value = sanitize_text_field($sh_value);

            switch ($sh_attr) {
                case 'registered_before':
                    $this->status = $this->registered_before_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;

                case 'registered_after':
                    $this->status = $this->registered_after_filter($atts,$sh_value);
                    $private_content_result['type'] = $sh_attr;
                    break;
            }
        }

        if(!$this->status){
            $private_content_result['status'] = false;              
        }else{
            $content = $this->private_content_block($atts,$content);
            return $content;
        }
        
        return $this->get_restriction_message($atts,$content,$private_content_result);
             
    }

    public function registered_before_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_id = get_current_user_id();
        $user = get_userdata($user_id);
        $registered_date = isset($user->user_registered) ? $user->user_registered : date("Y-m-d H:i:s");

        $registered_date = strtotime($registered_date);
        $before_date = date("Y-m-d",strtotime($sh_value));
        $before_date = strtotime($before_date);


        if($before_date >= $registered_date){
            return true;
        }        
       
        return false;
    }

    public function registered_after_filter($atts,$sh_value){
        global $wppcp;
        extract($atts);

        $this->private_content_settings  = get_option('wppcp_options');  

        $user_id = get_current_user_id();
        $user = get_userdata($user_id);
        $registered_date = isset($user->user_registered) ? $user->user_registered : date("Y-m-d H:i:s");

        $registered_date = strtotime($registered_date);
        $after_date = date("Y-m-d",strtotime($sh_value));
        $after_date = strtotime($after_date);


        if($after_date <= $registered_date){
            return true;
        }        
       
        return false;
    }

    public function private_content_by_password($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => '',
            'password' => ''
        ), $atts));
        
        $user_id =  $this->current_user;
        $message = sanitize_text_field($message);
        $password = sanitize_text_field($password);
        
        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }        

        if($password != '' && !isset($_POST['wppcp_protected_content_password'])){
            return "<p><form method='POST'>".__("Enter Password ","wppcp").": <input type='password' name='wppcp_protected_content_password'  />
            <input type='submit' value='".__("Submit ","wppcp")."' /></form></p>";
        }else if($password != '' &&  isset($_POST['wppcp_protected_content_password']) ){
            $user_password = sanitize_text_field($_POST['wppcp_protected_content_password']);
            
            if(trim($user_password) == $password){
                return $content;
            }else{
                return "<p><form method='POST'>".__("Enter Password ","wppcp").": <input type='password' name='wppcp_protected_content_password'  />
            <input type='submit' value='".__("Submit ","wppcp")."' /></form></p>";
            }
        }else if($password == ''){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }

        
             
    }

    public function private_content_by_woocommerce_product($atts,$content){
        global $wppcp,$wpdb;

        $this->private_content_settings  = get_option('wppcp_options');  

        if(!isset($this->private_content_settings['general']['private_content_module_status'])){
            return __('Private content module is disabled.','wppcp');        
        }
        
        $private_content_result = array('status'=>true, 'type'=>'admin');
        
        extract(shortcode_atts(array(
            'message' => '',
            'product_id' => ''
        ), $atts));
        
        $user_id =  $this->current_user;
        $user = get_userdata($user_id);
        $message = sanitize_text_field($message);

        // Provide permission for admin to view any content
        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') 
            || $product_id == '' ){
            return $this->get_restriction_message($atts,$content,$private_content_result);
        }        

        if($product_id != '' && wc_customer_bought_product( $user->user_email, $user->ID, $product_id )){
            return do_shortcode($content);
        }else{
            return $message;
        }

        
             
    }

    public function user_restricted_posts($atts,$content){
        global $wppcp,$wpdb;
        extract(shortcode_atts(array(
            'user_id' => '',
            'post_type' => 'post',
            'result_limit' => 100,

        ), $atts));
        
        $user_id =  ($user_id == '') ? get_current_user_id() : $user_id;
        
        $query = new WP_Query( array( 
            'post_type' => sanitize_text_field($post_type),
            'post_status' => 'publish',
            'posts_per_page' => (int) $result_limit,
            'meta_query' => array(
                array(
                    'key'     => '_wppcp_post_page_allowed_users',
                    'value'   => ':"'.$user_id.'"',
                    'compare' => 'REGEXP',
                ) ) ) );

        $html = "";
        if ( $query->have_posts() ) {

            $html .= "<ul>";

            while ($query->have_posts()) : $query->the_post();
                $html .= "<li><a href='".get_permalink()."'>".get_the_title()."</a></li>";
            endwhile;
            wp_reset_query();

            $html .= "</ul>";
        }
        
        return $html;
             
    }
    

    public function user_role_restricted_posts($atts,$content){
        global $wppcp,$wpdb;
        extract(shortcode_atts(array(
            'role' => '',
            'post_type' => 'post',
            'result_limit' => 100,

        ), $atts));
        
        $role =  ($role == '') ? '' : $role;
        
        $query = new WP_Query( array( 
            'post_type' => sanitize_text_field($post_type),
            'post_status' => 'publish',
            'posts_per_page' => (int) $result_limit,
            'meta_query' => array(
                array(
                    'key'     => '_wppcp_post_page_roles',
                    'value'   => ':"'.sanitize_text_field($role).'"',
                    'compare' => 'REGEXP',
                ) ) ) );

        $html = "";
        if ( $query->have_posts() ) {

            $html .= "<ul>";

            while ($query->have_posts()) : $query->the_post();
                $html .= "<li><a href='".get_permalink()."'>".get_the_title()."</a></li>";
            endwhile;
            wp_reset_query();

            $html .= "</ul>";
        }
        
        return $html;
             
    }

    public function save_bulk_private_content_upload(){
        global $wppcp,$wpdb;

        if($_POST && isset($_POST['wppcp_bulk_private_page_upload_mod']) && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) ){

            if (isset( $_POST['wppcp_settings_page_nonce_field'] ) && wp_verify_nonce( $_POST['wppcp_settings_page_nonce_field'], 'wppcp_settings_page_nonce' ) ) {

                // echo "<pre>";print_r($_POST);exit;
                $type = isset($_POST['wppcp_bulk_private_page_upload_type']) ? sanitize_text_field($_POST['wppcp_bulk_private_page_upload_type']) : 'none';
                if($type != 'none'){
                    $users = isset($_POST['wppcp_bulk_private_page_upload_users']) ? (array) $_POST['wppcp_bulk_private_page_upload_users'] : array();

                    $content = isset($_POST['wppcp_bulk_private_page_upload_content']) ? $_POST['wppcp_bulk_private_page_upload_content'] : '';

                    foreach ($users as $key => $user_id) {

                        $updated_date = date("Y-m-d H:i:s");
                        $sql  = $wpdb->prepare( "SELECT content FROM " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE . " WHERE user_id = %d ", $user_id );
                        $result = $wpdb->get_results($sql);
                        if($result){
                            $sql  = $wpdb->prepare( "Update " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE ." set content=%s,updated_at=%s where user_id=%d ", $content,$updated_date, $user_id );
                        }else{
                            $sql  = $wpdb->prepare( "Insert into " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE ."(user_id,content,type,updated_at) values(%d,%s,%s,%s)", $user_id, $content, 'ADMIN', $updated_date );
                        }
                        $wpdb->query($sql);

                    }
                    add_action( 'admin_notices', array( $this, 'private_content_success_notices' ) );
                }
                 
            }else{
                add_action( 'admin_notices', array( $this, 'private_content_error_notices' ) ); 
            }

        }
    }

    public function private_content_success_notices(){
        ?>
        <div class="updated">
          <p><?php esc_html_e( 'Private content saved successfully.', 'wppcp' ); ?></p>
       </div>
        <?php
    }

    public function private_content_error_notices(){
        ?>
        <div class="updated">
          <p><?php esc_html_e( 'You don\'t have permission to update private content.', 'wppcp' ); ?></p>
       </div>
        <?php
    }
}class-wppcp-posts.php000066600000010014151765001320010657 0ustar00<?php

class WPPCP_Posts{

	public function __construct(){
		add_action('wp_ajax_wppcp_load_published_posts', array($this, 'load_published_posts'));
        add_action('wp_ajax_wppcp_load_published_pages', array($this, 'load_published_pages'));
        add_action('wp_ajax_wppcp_load_published_cpt', array($this, 'load_published_cpt'));
        
	}

	public function load_published_pages(){
        global $wpdb;

        $post_json_results = array();
        if( ( current_user_can('manage_options') || current_user_can('wpppcp_manage_options') )
        && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){
            $search_text  = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : '';

            $post_json_results = array();

            $query = "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_title like '%".$search_text."%' && $wpdb->posts.post_status='publish'  && $wpdb->posts.post_type='page' order by $wpdb->posts.post_date desc limit 20";
            $result = $wpdb->get_results($query);
            if($result){
                foreach($result as $post_row){
                    array_push($post_json_results , array('id' => $post_row->ID, 'name' => esc_html($post_row->post_title)) ) ;
                }
            }
        }       
        
        echo json_encode(array('items' => $post_json_results ));exit;
    }

    public function load_published_posts(){
        global $wpdb;

        $post_json_results = array();
        if( ( current_user_can('manage_options') || current_user_can('wpppcp_manage_options') )
        && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){
            $search_text  = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : '';

            $post_json_results = array();

            $query = "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_title like '%".$search_text."%' && $wpdb->posts.post_status='publish'  && $wpdb->posts.post_type='post' order by $wpdb->posts.post_date desc limit 20";
            $result = $wpdb->get_results($query);
            if($result){
                foreach($result as $post_row){
                    array_push($post_json_results , array('id' => $post_row->ID, 'name' => esc_html($post_row->post_title)) ) ;
                }
            }
        }        
        
        echo json_encode(array('items' => $post_json_results ));exit;
    }

    public function load_published_cpt(){
    	global $wpdb;
        

        $post_json_results = array();
        if( ( current_user_can('manage_options') || current_user_can('wpppcp_manage_options') )
        && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){
            $search_text  = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : '';
            $post_type  = isset($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : '';

            $post_json_results = array();

            $query = "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_title like '%".$search_text."%' && $wpdb->posts.post_status='publish'  && $wpdb->posts.post_type='".$post_type."' order by $wpdb->posts.post_date desc limit 20";
            $result = $wpdb->get_results($query);
            if($result){
                foreach($result as $post_row){
                    array_push($post_json_results , array('id' => $post_row->ID, 'name' => esc_html($post_row->post_title) )) ;
                }
            }

        }        
        
        echo json_encode(array('items' => $post_json_results ));exit;
    }

    public function get_post_types(){

    	$skipped_types = array('post','page','attachment','revision','nav_menu_item');
    	$allowed_post_types = array();

    	$args = array();
    	$output = 'objects'; 
    	$post_types = get_post_types( $args, $output );
    	foreach ($post_types as $post_type => $post_type_data) {
    		if(!in_array($post_type, $skipped_types)){
    			$allowed_post_types[$post_type] = $post_type_data->label;
    		}
    	}
    	

    	return $allowed_post_types;
    }
}class-wppcp-menu.php000066600000017644151765001320010473 0ustar00<?php

/* Manage menu related settings */
class WPPCP_Menu{

	/* Initialize menu related acttions and filters */
	public function __construct(){
		global $wppcp;

		$this->private_content_settings  = get_option('wppcp_options');  

		if(isset($this->private_content_settings['general']['private_content_module_status'])){
           
			add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'menu_item_custom_fields' ), 10, 4 );
			add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
			add_action( 'wp_update_nav_menu_item', array( $this, 'update_nav_menu_item' ), 10, 3 );	
			if ( ! is_admin() ) {
				add_filter( 'wp_get_nav_menu_items', array( &$this, 'restrict_nav_menu_items' ), 10, 3 );			
			}
			

		}

	}

	

	/* Include a custom menu walker class to modify the menu */
	public function edit_nav_menu_walker( $walker ) {
		require_once( dirname( __FILE__ ) . '/class-wppcp-walker-nav-menu-edit.php' );
		return 'WPPCP_Walker_Nav_Menu_Edit';
	}

	/* Display restriction settings for menu items */
	public function menu_item_custom_fields($item_id, $item, $depth, $args ) {
		global $wp_roles;

		$user_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names, $item );

		$roles = (array) get_post_meta( $item->ID, 'wppcp_nav_menu_roles', true );
		$visibility_level = get_post_meta( $item->ID, 'wppcp_nav_menu_visibility_level', true );
		if($visibility_level == ''){
			$visibility_level = '0';
		}

		$users = (array) get_post_meta( $item->ID, 'wppcp_nav_menu_users', true );

		?>

		<?php wp_nonce_field( 'wppcp_nav_menu_page_nonce', 'wppcp_nav_menu_page_nonce_field' );  ?>

		<div class="description-wide">
		    <span class="description"><?php _e( "Visibility", 'wppcp' ); ?></span>
		    <br />

		    <input type="hidden" class="nav-menu-id" value="<?php echo (int) $item->ID ;?>" />

		    <div class="logged-input-holder" style="float: left; width: 35%;">
		        <select class="wppcp_menu_visibility" name='wppcp_menu_visibility_<?php echo (int) $item->ID ;?>' id='wppcp_menu_visibility_<?php echo $item->ID ;?>' >
		        	<option value='0' <?php selected('0',$visibility_level); ?> ><?php _e('Everyone','wppcp'); ?></option>
		        	<option value='1' <?php selected('1',$visibility_level); ?> ><?php _e('Members','wppcp'); ?></option>
		        	<option value='2' <?php selected('2',$visibility_level); ?> ><?php _e('Guests','wppcp'); ?></option>
		        	<option value='3' <?php selected('3',$visibility_level); ?> ><?php _e('By User Role','wppcp'); ?></option>
		        	<option value='4' <?php selected('4',$visibility_level); ?> ><?php _e('By Users','wppcp'); ?></option>
		        
		        </select>
		    </div>

		    

		</div>

		<?php
			$role_display_panel = "display:none";
			if($visibility_level == '3'){
				$role_display_panel = "display:block";
			}
		?>
		<div class="wppcp-menu-role-display-panel description-wide" style="margin: 5px 0;<?php echo esc_attr($role_display_panel); ?>">
		    <span class="description"><?php _e( "Permitted user roles", 'wppcp' ); ?></span>
		    <br />

		    <?php
		    foreach ( $user_roles as $role => $name ) {

		        $checked = checked( true, in_array( $role, $roles ) , false );
		        
		        ?>

		        <div class="" style="">
		        	<input type="checkbox" name="wppcp_menu_roles[<?php echo $item->ID ;?>][]" id="wppcp_menu_roles<?php echo $item->ID ;?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
		        	<label for="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>">
		        	<?php echo esc_html( $name ); ?>
		        </label>
		        </div>

		<?php } ?>

		</div>

		<?php
			$users_display_panel = "display:none";
			if($visibility_level == '4'){
				$users_display_panel = "display:block";
			}
		?>
		<div class="wppcp-menu-users-display-panel description-wide" style="margin: 5px 0;<?php echo esc_attr($users_display_panel); ?>">
		    <span class="description"><?php _e( "Permitted users", 'wppcp' ); ?></span>
		    <br />

		    <select class="wppcp-select2-full-setting wppcp_menu_user_restrictions" multiple name="wppcp_menu_users[<?php echo (int) $item->ID ;?>][]" id="wppcp_menu_users<?php echo (int) $item->ID ;?>">
		    	<?php foreach ($users as $user_id) { 
		    			if($user_id != '' &&  $user_id != '0'){
		    			$user = get_user_by('ID',$user_id);
		    			if($user){
		    	?>
		    		<option value='<?php echo $user_id; ?>' selected ><?php echo esc_html($user->data->display_name); ?></option>
		    	<?php }}} ?>
		    </select>
		    <input type='hidden' class='wppcp_menu_user_restrictions_hidden' value='' name='wppcp_menu_users_hidden[<?php echo (int) $item->ID ;?>]' />
		    

		</div>

		<?php 
	
	}

	/* Save restriction settings for menu items */
	public function update_nav_menu_item( $menu_id, $menu_item_db_id, $args ) {

		if( ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') )
			&& wp_verify_nonce( $_POST['wppcp_nav_menu_page_nonce_field'], 'wppcp_nav_menu_page_nonce' )) {


			$visibility_level = get_post_meta( $menu_item_db_id, 'wppcp_nav_menu_visibility_level', true );
			$new_visibility_level = isset( $_POST['wppcp_menu_visibility_'.$menu_item_db_id] ) ? sanitize_text_field($_POST['wppcp_menu_visibility_'.$menu_item_db_id]) : '0';
		
			$visibility_roles = isset($_POST['wppcp_menu_roles'][$menu_item_db_id]) ? (array) $_POST['wppcp_menu_roles'][$menu_item_db_id] : array();

			$visibility_users = isset($_POST['wppcp_menu_users'][$menu_item_db_id]) ? (array) $_POST['wppcp_menu_users'][$menu_item_db_id] : array();

			$visibility_users_list = array();
			foreach ($visibility_users as $key => $value) {
				if($key !== '' && !in_array($value,$visibility_users_list)){
					$value = (int) $value;
					array_push($visibility_users_list, $value);
				}
			}

			$visibility_roles_list = array();
			foreach ($visibility_roles as $key => $value) {
				if($key !== '' && !in_array($value,$visibility_roles_list)){
					$value = sanitize_text_field($value);
					array_push($visibility_roles_list, $value);
				}
			}

			update_post_meta( $menu_item_db_id, 'wppcp_nav_menu_visibility_level', $new_visibility_level );
			update_post_meta( $menu_item_db_id, 'wppcp_nav_menu_roles', $visibility_roles_list );
			update_post_meta( $menu_item_db_id, 'wppcp_nav_menu_users', $visibility_users_list );
		}
	}

	

	/* Restrict menu items based on specified conditions */
	public function restrict_nav_menu_items( $items, $menu, $args ) {

		$hide_children_of = array();

		// Iterate over the items to search and destroy
		foreach ( $items as $key => $item ) {

			$visible = true;

			$visibility_level = get_post_meta( $item->ID, 'wppcp_nav_menu_visibility_level', true );
	
			if( in_array( $item->menu_item_parent, $hide_children_of ) ){
				$visible = false;
				$hide_children_of[] = $item->ID;
			}

			if( $visible && isset( $visibility_level ) ) {

				// check all logged in, all logged out, or role
				switch( $visibility_level ) {
					case '0' :
						$visible = true;
						break;
					case '1' :
						$visible = is_user_logged_in() ? true : false;
						break;
					case '2' :
						$visible = ! is_user_logged_in() ? true : false;
						break;
					case '3' :
						$visibility_roles = (array) get_post_meta( $item->ID, 'wppcp_nav_menu_roles', true );
						$visible = false;
						foreach ( $visibility_roles as $role ) {
							if ( current_user_can( $role ) ) 
								$visible = true;
						}
						break;
					case '4' :
						$visibility_users = (array) get_post_meta( $item->ID, 'wppcp_nav_menu_users', true );
						$visible = false;
						foreach ( $visibility_users as $user ) {
							if ( get_current_user_id() == $user ) 
								$visible = true;
						}
						break;
				}

			}

			// add filter to work with plugins that don't use traditional roles
			$visible = apply_filters( 'nav_menu_roles_item_visibility', $visible, $item );

			// unset non-visible item
			if ( ! $visible ) {
				$hide_children_of[] = $item->ID; // store ID of item 
				unset( $items[$key] ) ;
			}

		}

		return $items;
	}
}class-wppcp-template-loader.php000066600000004324151765001320012575 0ustar00<?php
/* Manage template loading */
class WPPCP_Template_Loader{
    
    public function get_template_part( $slug, $name = null, $load = true ) {

        // Setup possible parts
        $templates = array();
        if ( isset( $name ) )
            $templates[] = $slug . '-' . $name . '.php';
        $templates[] = $slug . '.php';

        // Return the part that is found
        return $this->locate_template( $templates, $load, false );
    }
    
    public function locate_template( $template_names, $load = false, $require_once = true ) {
        // No file found yet
        $located = false;

        // Traverse through template files
        foreach ( (array) $template_names as $template_name ) {

            // Continue if template is empty
            if ( empty( $template_name ) )
                continue;

            $template_name = ltrim( $template_name, '/' );

            // Check templates for frontend section
            if ( file_exists( trailingslashit( WPPCP_PLUGIN_DIR ) . 'templates/' . $template_name ) ) {
                $located = trailingslashit( WPPCP_PLUGIN_DIR ) . 'templates/' . $template_name;
                break;
            }  elseif ( file_exists( trailingslashit( WPPCP_PLUGIN_DIR ) . 'admin/templates/' . $template_name ) ) {
                // Check templates for admin section
                $located = trailingslashit( WPPCP_PLUGIN_DIR ) . 'admin/templates/' . $template_name;
                break;
            } else{
               
                /* Enable additional template locations using filters for addons */
                $template_locations = apply_filters('wppcp_template_loader_locations',array());
                 
                foreach($template_locations as $location){
                    
                    if(file_exists( $location . $template_name)){
                        
                        $located = $location . $template_name;
                        break;
                    }
                }
                
            }
        }

        
        if ( ( true == $load ) && ! empty( $located ) )
            load_template( $located, $require_once );

        return $located;
    }
}


?>class-wppcp-upme.php000066600000015216151765001320010466 0ustar00<?php

class WPPCP_UPME{

	public function __construct(){
		$this->upme_options = get_option('upme_options');
		$this->private_content_settings  = get_option('wppcp_options');
		
		add_filter('wppcp_global_post_restriction_redirect',array($this,'upme_wppcp_post_restriction_redirect'),100,2);
		add_filter('wppcp_single_post_restriction_redirect',array($this,'upme_wppcp_post_restriction_redirect'),100,2);
		
		add_filter('upme_search_shortcode_display' , array($this,'upme_search_shortcode_display'),100,2);
		add_filter('upme_profile_shortcode_display' , array($this,'upme_profile_shortcode_display'),100,2);
        add_filter('upme_profile_fields_panel',array($this,'upme_profile_fields_shortcode_display'),100,2);
        
		add_action('init', array($this, 'init')); 
	}

    public function init(){
        $this->current_user = get_current_user_id(); 
    }

	public function upme_wppcp_post_restriction_redirect($url,$params){
		
		$login_link_status = $this->private_content_settings['upme_general']['redirect_to_upme_login'];
		if(!is_user_logged_in() && $login_link_status == 'enabled') {
			$url = get_permalink($this->upme_options['login_page_id']);
		}
		return $url;
	}

	public function upme_search_shortcode_display($display,$params){
		global $wppcp;

		if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
			return $display;
		}

		$visibility = isset($this->private_content_settings['upme_search']['upme_search_visibility']) ? $this->private_content_settings['upme_search']['upme_search_visibility'] : 'all';
		$visible_roles = isset($this->private_content_settings['upme_search']['upme_search_user_roles']) ? $this->private_content_settings['upme_search']['upme_search_user_roles'] : array();
	
		switch ($visibility) {
            case 'all':
                break;
            
            case 'guest':
                if(is_user_logged_in()){
                    $display = '';
                }
                break;

            case 'member':
                if(is_user_logged_in()){

                }else{
                    $display = '';
                }
                break;

            case 'role':
                if(is_user_logged_in()){
                    if(count($visible_roles) == 0){
                        $display = '';
                    }else{
                        $user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
                        foreach ($visible_roles as  $visible_role ) {
                            if(in_array($visible_role, $user_roles)){
                               return $display;
                            }
                        }
                        $display = '';
                    }
                }else{
                    $display = '';
                }
                
                break;
        }
        return $display;
	}

	public function upme_profile_shortcode_display($display,$params){
		global $wppcp;
		extract($params);

		if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') || (isset($atts['group']) && $atts['group'] != 'all') || !isset($atts['group']) ){
			return $display;
		}

		$visibility = isset($this->private_content_settings['upme_member_list']['upme_member_list_visibility']) ? $this->private_content_settings['upme_member_list']['upme_member_list_visibility'] : 'all';
		$visible_roles = isset($this->private_content_settings['upme_member_list']['upme_member_list_user_roles']) ? $this->private_content_settings['upme_member_list']['upme_member_list_user_roles'] : array();
	
		switch ($visibility) {
            case 'all':
                break;
            
            case 'guest':
                if(is_user_logged_in()){
                    $display = '';
                }
                break;

            case 'member':
                if(is_user_logged_in()){

                }else{
                    $display = '';
                }
                break;

            case 'role':
                if(is_user_logged_in()){
                    if(count($visible_roles) == 0){
                        $display = '';
                    }else{
                        $user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
                        foreach ($visible_roles as  $visible_role ) {
                            if(in_array($visible_role, $user_roles)){
                               return $display;
                            }
                        }
                        $display = '';
                    }
                }else{
                    $display = '';
                }
                
                break;
        }
        return $display;
	}

    public function upme_profile_fields_shortcode_display($display,$params){
        global $wppcp;
        extract($params);

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return $display;
        }

        $visibility = isset($this->private_content_settings['upme_member_profile']['upme_member_profile_visibility']) ? $this->private_content_settings['upme_member_profile']['upme_member_profile_visibility'] : 'all';
        $visible_roles = isset($this->private_content_settings['upme_member_profile']['upme_member_profile_user_roles']) ? $this->private_content_settings['upme_member_profile']['upme_member_profile_user_roles'] : array();
    
        switch ($visibility) {
            case 'all':
                break;
            
            case 'guest':
                if(is_user_logged_in()){
                    $display = '';
                }
                break;

            case 'member':
                if(is_user_logged_in()){

                }else{
                    $display = '';
                }
                break;

            case 'role':
                if(is_user_logged_in()){
                    if(count($visible_roles) == 0){
                        $display = '';
                    }else{
                        $user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
                        foreach ($visible_roles as  $visible_role ) {
                            if(in_array($visible_role, $user_roles)){
                               return $display;
                            }
                        }
                        $display = '';
                    }
                }else{
                    $display = '';
                }
                
                break;
        }
        return $display;
    }
}class-wppcp-widgets.php000066600000007562151765001320011173 0ustar00<?php

class WPPCP_Widgets{

	public function __construct(){
		add_filter('in_widget_form', array($this, 'widget_custom_options'), 10, 3 );

		add_filter( 'widget_update_callback', array($this, 'save_widget_options'), 10, 2 );

		add_filter( 'widget_display_callback', array($this, 'content_visibility'),10,3 );
	}

	public function widget_custom_options( $widget, $return, $instance ) {
 		global $wp_roles;
	        // Display the description option.
	    $visibility_level = isset( $instance['wppcp_visibility'] ) ? sanitize_text_field($instance['wppcp_visibility']) : '';
	    $visible_roles = isset( $instance['wppcp_visibility_roles'] ) ? (array) $instance['wppcp_visibility_roles'] : array();

	    $role_visibility = "display:none;";
	    if($visibility_level == '3'){
	    	$role_visibility = "display:block;";
	    }

	    

	    $display = '<div ><p>
	    				<label for="'.$widget->get_field_id('wppcp_visibility').'">'.__('Visibility','wppcp') .':</label>
						<select class="widefat wppcp_widget_visibility" id="'. $widget->get_field_id('wppcp_visibility').'" name="'.$widget->get_field_name('wppcp_visibility').'" >
							<option value="0" '. selected("0",$visibility_level,false) .' >'. __("Everyone","wppcp").' </option>
		        			<option value="1" '. selected("1",$visibility_level,false) .' >'. __("Members","wppcp").' </option>
		        			<option value="2" '. selected("2",$visibility_level,false) .' >'. __("Guests","wppcp").' </option>
		        			<option value="3" '. selected("3",$visibility_level,false) .' >'. __("By User Role","wppcp").' </option>
		        
						</select>
					</p>';

		
		$display .= '<div style="'.esc_attr($role_visibility).'" class="wppcp_widget_visibility_roles"><p >
	    				<label for="'.$widget->get_field_id('wppcp_visibility_roles').'">'.__('Visibility Roles','wppcp') .':</label></p><p>';

	    		$user_roles = $wp_roles->role_names;
		    	foreach ( $user_roles as $role => $name ) {

		        	$checked = checked( true, in_array( $role, $visible_roles ) , false );
		   
					$display .= '<input   type="checkbox" name="'.$widget->get_field_name('wppcp_visibility_roles').'[]" id="'.$widget->get_field_id('wppcp_visibility_roles').'" '.$checked.' value="'.$role.'" />
						        	<label for="">
						        	'.$name .'
						        </label><br/>';
	

				}
						
		$display .= '</p></div></div>';
	    echo $display;

	}

	public function save_widget_options( $instance, $new_instance ) {

	    if ( empty( $new_instance['wppcp_visibility'] ) ) {
	        $new_instance['wppcp_visibility'] = 0;
	    }

	    if ( empty( $new_instance['wppcp_visibility_roles'] ) ) {
	        $new_instance['wppcp_visibility_roles'] = array();
	    }
	 
	    return $new_instance;
	}


	public function content_visibility($instance, $current_obj, $args){
			//unset( $sidebars_widgets[ '$sidebar_id' ] );
		$visible = true;
		if(isset($instance['wppcp_visibility'])){

			$visibility_level = sanitize_text_field($instance['wppcp_visibility']);
			
			switch( $visibility_level ) {
					case '0' :
						$visible = true;
						break;
					case '1' :
						$visible = is_user_logged_in() ? true : false;
						break;
					case '2' :
						$visible = ! is_user_logged_in() ? true : false;
						break;
					case '3' :
						$visibility_roles = isset($instance['wppcp_visibility_roles']) ? (array)  $instance['wppcp_visibility_roles'] : array();
						$visible = false;
						foreach ( $visibility_roles as $role ) {
							$role = sanitize_text_field($role);
							if ( current_user_can( $role ) ) 
								$visible = true;
						}
						break;
				}
		}

		$visible = apply_filters('wppcp_widget_visibility', $visible , array('instance' => $instance, 'current_obj' => $current_obj, 'args' => $args) );

		if($visible){
			return $instance;	
		}else{
			return false;
		}
		

	}
}


class-wppcp-walker-nav-menu-edit.php000066600000023166151765001320013457 0ustar00<?php

class WPPCP_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {

	/**
	 * Start the element output.
	 *
	 * @see Walker_Nav_Menu::start_el()
	 * @since 3.0.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $item   Menu item data object.
	 * @param int    $depth  Depth of menu item. Used for padding.
	 * @param array  $args   Not used.
	 * @param int    $id     Not used.
	 */
	function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
		global $_wp_nav_menu_max_depth;
		$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;

		ob_start();
		$item_id = esc_attr( $item->ID );
		$removed_args = array(
			'action',
			'customlink-tab',
			'edit-menu-item',
			'menu-item',
			'page-tab',
			'_wpnonce',
		);

		$original_title = '';
		if ( 'taxonomy' == $item->type ) {
			$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
			if ( is_wp_error( $original_title ) )
				$original_title = false;
		} elseif ( 'post_type' == $item->type ) {
			$original_object = get_post( $item->object_id );
			$original_title = get_the_title( $original_object->ID );
		}

		$classes = array(
			'menu-item menu-item-depth-' . $depth,
			'menu-item-' . esc_attr( $item->object ),
			'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == sanitize_title($_GET['edit-menu-item'] )) ? 'active' : 'inactive'),
		);

		$title = $item->title;

		if ( ! empty( $item->_invalid ) ) {
			$classes[] = 'menu-item-invalid';
			/* translators: %s: title of menu item which is invalid */
			$title = sprintf( __( '%s (Invalid)' ), $item->title );
		} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
			$classes[] = 'pending';
			/* translators: %s: title of menu item in draft status */
			$title = sprintf( __('%s (Pending)'), $item->title );
		}

		$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;

		$submenu_text = '';
		if ( 0 == $depth )
			$submenu_text = 'style="display: none;"';

		?>
		<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
			<dl class="menu-item-bar">
				<dt class="menu-item-handle">
					<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span>
					<span class="item-controls">
						<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
						<span class="item-order hide-if-js">
							<a href="<?php
								echo wp_nonce_url(
									add_query_arg(
										array(
											'action' => 'move-up-menu-item',
											'menu-item' => $item_id,
										),
										remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
									),
									'move-menu_item'
								);
							?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
							|
							<a href="<?php
								echo wp_nonce_url(
									add_query_arg(
										array(
											'action' => 'move-down-menu-item',
											'menu-item' => $item_id,
										),
										remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
									),
									'move-menu_item'
								);
							?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
						</span>
						<a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
							echo ( isset( $_GET['edit-menu-item'] ) && $item_id == sanitize_title($_GET['edit-menu-item'] ) ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
						?>"><?php _e( 'Edit Menu Item' ); ?></a>
					</span>
				</dt>
			</dl>

			<div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
				<?php if( 'custom' == $item->type ) : ?>
					<p class="field-url description description-wide">
						<label for="edit-menu-item-url-<?php echo $item_id; ?>">
							<?php _e( 'URL' ); ?><br />
							<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
						</label>
					</p>
				<?php endif; ?>
				<p class="description description-thin">
					<label for="edit-menu-item-title-<?php echo $item_id; ?>">
						<?php _e( 'Navigation Label' ); ?><br />
						<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
					</label>
				</p>
				<p class="description description-thin">
					<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
						<?php _e( 'Title Attribute' ); ?><br />
						<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
					</label>
				</p>
				<p class="field-link-target description">
					<label for="edit-menu-item-target-<?php echo $item_id; ?>">
						<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
						<?php _e( 'Open link in a new window/tab' ); ?>
					</label>
				</p>
				<p class="field-css-classes description description-thin">
					<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
						<?php _e( 'CSS Classes (optional)' ); ?><br />
						<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
					</label>
				</p>
				<p class="field-xfn description description-thin">
					<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
						<?php _e( 'Link Relationship (XFN)' ); ?><br />
						<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
					</label>
				</p>
				<p class="field-description description description-wide">
					<label for="edit-menu-item-description-<?php echo $item_id; ?>">
						<?php _e( 'Description' ); ?><br />
						<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
						<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
					</label>
				</p>

				<?php do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args ); ?>
				<div class='wppcp-clear'></div>

				<!-- <p class="field-move hide-if-no-js description description-wide">
					<label>
						<span><?php _e( 'Move' ); ?></span>
						<a href="#" class="menus-move-up"><?php _e( 'Up one' ); ?></a>
						<a href="#" class="menus-move-down"><?php _e( 'Down one' ); ?></a>
						<a href="#" class="menus-move-left"></a>
						<a href="#" class="menus-move-right"></a>
						<a href="#" class="menus-move-top"><?php _e( 'To the top' ); ?></a>
					</label>
				</p> -->

				<div class="menu-item-actions description-wide submitbox">
					<?php if( 'custom' != $item->type && $original_title !== false ) : ?>
						<p class="link-to-original">
							<?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
						</p>
					<?php endif; ?>
					<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
					echo wp_nonce_url(
						add_query_arg(
							array(
								'action' => 'delete-menu-item',
								'menu-item' => $item_id,
							),
							admin_url( 'nav-menus.php' )
						),
						'delete-menu_item_' . $item_id
					); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
						?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
				</div>

				<div class='wppcp-clear'></div>

				<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
				<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
				<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
				<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
				<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
				<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
			</div><!-- .menu-item-settings-->
			<ul class="menu-item-transport"></ul>
		<?php
		$output .= ob_get_clean();
	}
}class-wppcp-admin-stats.php000066600000041236151765001320011745 0ustar00<?php

class WPPCP_Admin_Stats{


	public function __construct(){
		add_action( 'wp_dashboard_setup', array($this,'register_my_dashboard_widget' ) );
		add_action('init', array($this, 'init'),9999);

	}

	public function init(){
		$this->private_content_settings  = get_option('wppcp_options');      

	}

	public function generate_stats(){

		$results['single_data'] = $this->get_individual_restriction_data();
		$results['global_data'] = $this->get_global_restriction_data();
		$results['password_data'] = $this->get_password_protected_data();
        $results['menu_data'] = $this->get_menu_stats();
        $results['widgets_data'] = $this->get_widget_stats();
        $results['search_data'] = $this->get_search_stats();
        $results['private_page_data'] = $this->get_private_page_stats();
        $results['attachment_data'] = $this->get_attachments_data();
        $results['shortcode_data'] = $this->get_private_shortcode_data();
        return $results;
	}

	public function register_my_dashboard_widget() {
	 	global $wp_meta_boxes;

	 	$wppcp_options = get_option('wppcp_options');

	 	if( ! ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') )){
	 		return;
	 	}

	 	$dashboard_restrictions_widget_status = isset($wppcp_options['general']['dashboard_restrictions_widget_status']) ?
	 	 ($wppcp_options['general']['dashboard_restrictions_widget_status']) : 0;
		if($dashboard_restrictions_widget_status == '1'){    
			wp_add_dashboard_widget(
				'wppcp_dashboard_stats_widget',
				__('WP Private Content Plus - Stats','wppcp'),
				array($this,'wppcp_dashboard_stats_widget_display')
			);

		 	$dashboard = $wp_meta_boxes['dashboard']['normal']['core'];

			$wppcp_stats_widget = array( 'wppcp_dashboard_stats_widget' => $dashboard['wppcp_dashboard_stats_widget'] );
		 	unset( $dashboard['wppcp_dashboard_stats_widget'] );

		 	$sorted_dashboard = array_merge( $wppcp_stats_widget, $dashboard );
		 	$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
		}
		
	}


	public function wppcp_dashboard_stats_widget_display() {
		?>

		<p>
		<?php _e('Thank you for using <strong>WP Private Content Plus</strong> to protect your site.','wppcp'); ?>
		<?php _e('You are using WP Private Content Plus to protect following data types.','wppcp'); ?>
		</p>

		

		<?php
		$results = $this->generate_stats();
		$individual_protection = array();
		if($results['single_data']['post_count'] > 0){
			$individual_protection[] = "<span>" . $results['single_data']['post_count'] . __(' Posts ','wppcp')."</span>" ;
		}
		if($results['single_data']['page_count'] > 0){
			$individual_protection[] = "<span>" .$results['single_data']['page_count'] . __(' Pages ','wppcp')."</span>" ;
		}
		if($results['single_data']['cpt_count'] > 0){
			$individual_protection[] = "<span>" .$results['single_data']['cpt_count'] . __(' Custom Post Types ','wppcp')."</span>" ;
		}

		$individual_protection = implode("-", $individual_protection);
		if($individual_protection != ''){
			$individual_protection .= __(' are protected','wppcp');
		}


		$global_protection = array();
		if($results['global_data']['restrict_all_posts_status'] == '1'){
			$global_protection[] = "<span>" .$results['global_data']['post_count'] . __(' Posts ','wppcp')."</span>" ;
		}
		if($results['global_data']['restrict_all_pages_status'] == '1'){
			$global_protection[] = "<span>" .$results['global_data']['page_count'] . __(' Pages ','wppcp')."</span>" ;
		}
		
		$global_protection = implode("-", $global_protection);
		if($global_protection != ''){
			$global_protection .= __(' are protected','wppcp');
		}

		$password_protection = '';		
		if(isset($results['password_data']['status'])){
			$password_protection = "<span>" .$results['password_data']['post_count'] . __(' Posts ','wppcp')."</span>"  . " - " .
									"<span>" .$results['password_data']['page_count'] . __(' Pages ','wppcp')."</span>"  ." - " .
									"<span>" .$results['password_data']['cpt_count'] . __(' Custom Post Types ','wppcp')."</span>"  ;
			$password_protection .= __(' are protected','wppcp');
		
		}

		$menu_protection = '';
		if($results['menu_data']['count'] > 0){
			$menu_protection = "<span>" .$results['menu_data']['count'] . __(' Menu Items ','wppcp')."</span>"  ;
			$menu_protection .= __(' are protected','wppcp');
		
		}

		$widget_protection = '';
		if($results['widgets_data']['count'] > 0){
			$widget_protection = "<span>" .$results['widgets_data']['count'] . __(' Widgets ','wppcp')."</span>"  ;
			$widget_protection .= __(' are protected','wppcp');
		
		}

		$shortcode_protection = '';
		if($results['shortcode_data']['count'] > 0){
			$shortcode_protection = "<span>" .$results['shortcode_data']['count'] . __(' Post/Page Content Blocks ','wppcp') ."</span>" ;
			$shortcode_protection .= __(' are protected','wppcp');
		
		}

		$private_page_protection = '';
		if($results['private_page_data']['count'] > 0){
			$private_page_protection = "<span>" .$results['private_page_data']['count'].__(' Users ','wppcp') . "</span>" . __('have private page with protected content. ','wppcp') ."</span>" ;
	
		}

		$attachment_protection = array();
		if($results['attachment_data']['post_count'] > 0){
			$attachment_protection[] = "<span>" .$results['attachment_data']['post_count'] . __(' Post ','wppcp')."</span>" ;
		}
		if($results['attachment_data']['page_count'] > 0){
			$attachment_protection[] = "<span>" .$results['attachment_data']['page_count'] . __(' Page ','wppcp')."</span>" ;
		}
		if($results['attachment_data']['cpt_count'] > 0){
			$attachment_protection[] = "<span>" .$results['attachment_data']['cpt_count'] . __(' Custom Post Type ','wppcp')."</span>" ;
		}

		$attachment_protection = implode("-", $attachment_protection);
		if($attachment_protection != ''){
			$attachment_protection .= __(' attachments are protected','wppcp');
		}



		$search_protection = array();
		if($results['search_data']['blocked_posts'] > 0){
			$search_protection[] = "<span>" .$results['search_data']['blocked_posts'] . __(' Posts ','wppcp')."</span>" ;
		}
		if($results['search_data']['blocked_pages'] > 0){
			$search_protection[] = "<span>" .$results['search_data']['blocked_pages'] . __(' Pages ','wppcp')."</span>" ;
		}
		$search_protection = implode("-", $search_protection);
		if($search_protection != ''){
			$search_protection .= __(' are protected from search','wppcp');
		}

		?>
		<table id='wppcp-admin-stats'  border="1">

			<?php if($individual_protection != ''){ ?>
				<tr><th><?php _e('Individual Post/Page Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($individual_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($global_protection != ''){ ?>
				<tr><th><?php _e('Global Post/Page Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($global_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($password_protection != ''){ ?>
				<tr><th><?php _e('Password Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($password_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($menu_protection != ''){ ?>
				<tr><th><?php _e('Menu Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($menu_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($widget_protection != ''){ ?>
				<tr><th><?php _e('Widget Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($widget_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($shortcode_protection != ''){ ?>
				<tr><th><?php _e('Shortcode Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($shortcode_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($attachment_protection != ''){ ?>
				<tr><th><?php _e('Attachment Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($attachment_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($private_page_protection != ''){ ?>
				<tr><th><?php _e('Private Page','wppcp'); ?></th>
					<td><?php echo wp_kses_post($private_page_protection); ?></td>
				</tr>
			<?php } ?>

			<?php if($search_protection != ''){ ?>
				<tr><th><?php _e('Search Protection','wppcp'); ?></th>
					<td><?php echo wp_kses_post($search_protection); ?></td>
				</tr>
			<?php } ?>
		</table>
		<?php
	}

	public function get_menu_stats(){
		$args = array(
			'post_type' => 'nav_menu_item',
			'post_status' => 'publish',
			'posts_per_page' => -1,
			'meta_key' => 'wppcp_nav_menu_visibility_level',
			'meta_value' => '0',
			'meta_compare' => '!='
		);
		 
		$query = new WP_Query( $args );
		$count = $query->post_count;

		return array('count' => $count);
	}

	public function get_password_protected_data(){
		global $wppcp;
		$password_settings = isset($this->private_content_settings['password_global']) ? $this->private_content_settings['password_global'] : array();
        $global_password_protect = isset($password_settings['global_password_protect']) ? $password_settings['global_password_protect'] : 'disabled';
        
        $password_data = array();
        $cpt_count = 0;
        if($global_password_protect != 'disabled'){
        	$password_data['status'] = $global_password_protect;

        	$p_types = $wppcp->posts->get_post_types();
        	$skipped_types = array('attachment','revision','nav_menu_item');
			foreach ( $p_types as $post_type => $post_type_label ) {
        		if(!in_array($post_type, $skipped_types)){
				   // $password_data[$post_type.'_count'] = wp_count_posts($post_type);
        			$cpt_count += wp_count_posts($post_type)->publish;
				}
			}
        }

        $password_data['post_count'] = wp_count_posts('post')->publish;
        $password_data['page_count'] = wp_count_posts('page')->publish;
        $password_data['cpt_count'] = $cpt_count;


        return $password_data;
	}

	public function get_widget_stats(){
		global $wpdb;

        $sql  = $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE autoload = '%s' and option_name like '%s' ", 'yes' , 'widget_%' );
        $result = $wpdb->get_results($sql);

        $restricted_widgets_data = array();
        $restricted_widgets_data['count'] = 0;

        foreach ($result as $key => $widget_options) {
        	$widget_settings = unserialize($widget_options->option_value);
        	if(is_array($widget_settings)){
	        	foreach ($widget_settings as $key => $widget_setting) {
	        		if(isset($widget_setting['wppcp_visibility']) && $widget_setting['wppcp_visibility'] != '0'){

	        			$restricted_widgets_data['widgets'][] = array('name' => $widget_options->option_name, 'visibility' => $widget_setting['wppcp_visibility']);
	        			$restricted_widgets_data['count']++;
	        		}
	        	}
	        }

        }

        return $restricted_widgets_data;
	}

	public function get_search_stats(){
		$general_options =  isset($this->private_content_settings['search_general']) ? (array) $this->private_content_settings['search_general'] : array();
		$search_data = array();

		$blocked_posts = isset( $general_options['blocked_post_search'] ) ? (array) $general_options['blocked_post_search'] : array();
		$blocked_pages = isset( $general_options['blocked_page_search'] ) ? (array) $general_options['blocked_page_search'] : array();
		$search_data['blocked_posts'] = count($blocked_posts);
		$search_data['blocked_pages'] = count($blocked_pages);

		$search_restrictions = isset($this->private_content_settings['search_restrictions']) ? $this->private_content_settings['search_restrictions'] : array() ;
		$everyone_search_types = isset($search_restrictions['everyone_search_types']) ? (array) $search_restrictions['everyone_search_types'] :array();
        $guests_search_types = isset($search_restrictions['guests_search_types']) ? (array) $search_restrictions['guests_search_types'] :array();
        $members_search_types = isset($search_restrictions['members_search_types']) ? (array) $search_restrictions['members_search_types'] :array();
               
        $search_data['everyone_search_types'] = count($everyone_search_types);
		$search_data['guests_search_types'] = count($guests_search_types);
		$search_data['members_search_types'] = count($members_search_types);
		return $search_data;
	}

	public function get_private_page_stats(){
		global $wpdb;

		$table_private_page = $wpdb->prefix."wppcp_private_page";
        $sql  = $wpdb->prepare( "SELECT * FROM $table_private_page WHERE id != %d ", 0 );
        $result = $wpdb->get_results($sql);
		
		$private_page_data = array();
		$private_page_data['count'] = count($result);
		return $private_page_data;
	}

	public function get_attachments_data(){
		global $wppcp;

		$p_types = $wppcp->posts->get_post_types();
		$skipped_types = array();
        		
        $attachment_data = array();
        $cpt_count = 0;
		foreach ( $p_types as $post_type => $post_type_label ) {
			$args = array(
				'post_type' => $post_type,
				'post_status' => 'publish',
				'posts_per_page' => -1,
				'meta_key' => '_wppcp_post_attachments',
				'meta_value' => 'a:0:{}',
				'meta_compare' => '!='
			);
			 
			$query = new WP_Query( $args );
			// $attachment_data[$post_type."_count"] = $query->post_count;
			$cpt_count += $query->post_count;
		}

		$attachment_data["cpt_count"] = $cpt_count;

		$args = array(
				'post_type' => 'post',
				'post_status' => 'publish',
				'posts_per_page' => -1,
				'meta_key' => '_wppcp_post_attachments',
				'meta_value' => 'a:0:{}',
				'meta_compare' => '!='
			);
			 
		$query = new WP_Query( $args );
		$attachment_data["post_count"] = $query->post_count;

		$args = array(
			'post_type' => 'page',
			'post_status' => 'publish',
			'posts_per_page' => -1,
			'meta_key' => '_wppcp_post_attachments',
			'meta_value' => 'a:0:{}',
			'meta_compare' => '!='
		);
		 
		$query = new WP_Query( $args );
		$attachment_data["page_count"] = $query->post_count;
		
		
		return $attachment_data;
	}

	public function get_private_shortcode_data(){
		global $wpdb;

        $sql  = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_status = '%s' 
        	and post_content like '%s' ", 'publish' , '%[wppcp_private_content%' );
        $result = $wpdb->get_results($sql);

		return array('count' => count($result));
	}

	public function get_global_restriction_data(){
		$post_restrictions = isset($this->private_content_settings['global_post_restriction']) ? $this->private_content_settings['global_post_restriction'] : array();
        $restrict_all_posts_status = isset($post_restrictions['restrict_all_posts_status']) ? $post_restrictions['restrict_all_posts_status'] :'0';
          
        $page_restrictions = isset($this->private_content_settings['global_page_restriction']) ? $this->private_content_settings['global_page_restriction'] : array();
        $restrict_all_pages_status = isset($page_restrictions['restrict_all_pages_status']) ? $page_restrictions['restrict_all_pages_status'] :'0';

        return array('restrict_all_posts_status' => $restrict_all_posts_status ,
        			 'restrict_all_pages_status' => $restrict_all_pages_status ,
        			 'post_count' => wp_count_posts('post')->publish,
        			 'page_count' => wp_count_posts('page')->publish );
	}

	public function get_individual_restriction_data(){
		global $wpdb,$wppcp;
		$args = array(
			'post_type' => 'post',
			'post_status' => 'publish',
			'posts_per_page' => -1,
			'meta_key' => '_wppcp_post_page_visibility',
			'meta_value' => 'none',
			'meta_compare' => '!='
		);
		 
		$query = new WP_Query( $args );
		$post_count = $query->post_count;

		$args = array(
			'post_type' => 'page',
			'post_status' => 'publish',
			'posts_per_page' => -1,
			'meta_key' => '_wppcp_post_page_visibility',
			'meta_value' => 'none',
			'meta_compare' => '!='
		);

		 
		$query = new WP_Query( $args );
		$page_count = $query->post_count;

		$post_data = array('post_count' => $post_count, 'page_count' => $page_count);

		$p_types = $wppcp->posts->get_post_types();
		$skipped_types = array('attachment','revision','nav_menu_item');
        		
        $cpt_count = 0;
		foreach ( $p_types as $post_type => $post_type_label ) {

			if(!in_array($post_type, $skipped_types)){
			   	$args = array(
					'post_type' => $post_type,
					'post_status' => 'publish',
					'posts_per_page' => -1,
					'meta_key' => '_wppcp_post_page_visibility',
					'meta_value' => 'none',
					'meta_compare' => '!='
				);

				 
				$query = new WP_Query( $args );
				$p_count = $query->post_count;
			   	// $post_data[$post_type."_count"] = $p_count;
			   	$cpt_count += $p_count;
		   	}
		}

		$post_data['cpt_count'] = $cpt_count;

		return $post_data;
	}
}
class-wppcp-roles-capability.php000066600000001275151765001320012763 0ustar00<?php
/* Manage user role and capability functions */
class WPPCP_Roles_Capability {

    private $user_roles;

    public function __construct() { }

    public function wppcp_user_roles(){
        global $wp_roles;

        $roles = $wp_roles->get_names();
        return $roles;
    }
    
    /* Get the roles of the given user */
    public function get_user_roles_by_id($user_id) {
        $user = new WP_User($user_id);
        if (!empty($user->roles) && is_array($user->roles)) {
            $this->user_roles = $user->roles;
            return $user->roles;
        } else {
            $this->user_roles = array();
            return array();
        }
    }

}
class-wppcp-admin-permissions.php000066600000014154151765001320013161 0ustar00<?php

class WPPCP_Admin_Permissions{

	public function __construct(){
		add_action( 'init' , array( $this, 'init') );
		add_action( 'wp_ajax_wppcp_load_admin_menu_permission', array( $this, 'load_admin_menu_permission') );
		add_action( 'wp_ajax_wppcp_update_admin_menu_permission', array( $this, 'update_admin_menu_permission') );
		add_filter( 'admin_menu', array( $this, 'restrict_admin_menus') , 9999 );
	}

	public function init(){
		global $wppcp;
		$this->wppcp_options = $wppcp->settings->wppcp_options; 
	}

	public function load_admin_menu_permission(){
		global $wppcp, $wppcp_settings_data;

		if( current_user_can('manage_options') ){			

			$slug = isset( $_POST['slug'] ) ? sanitize_text_field( $_POST['slug'] ) : '';

			if( check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){

				$admin_menu_settings = isset( $this->wppcp_options['admin_menu_visibility'][$slug] ) ? $this->wppcp_options['admin_menu_visibility'][$slug] : '';
				$wppcp_settings_data['admin_menu_visibility'] = isset($admin_menu_settings['visibility']) ? $admin_menu_settings['visibility'] : 0;
				$wppcp_settings_data['admin_menu_roles'] = isset($admin_menu_settings['user_roles']) ? $admin_menu_settings['user_roles'] : array() ;
				$wppcp_settings_data['admin_menu_slug'] = $slug;

				ob_start();
	      		$wppcp->template_loader->get_template_part('admin-menu-visibility');    
	      		$display = ob_get_clean();  


				$result = array( 'msg' => $display , 'status' => 'success' );
			}else{
				$result = array( 'msg' => __('Invalid request.','wppcp'), 'status' => 'error' );
			}
		}else{
			$result = array( 'msg' => __('Permission denied.','wppcp'), 'status' => 'error' );
		}

		echo json_encode( $result );exit;
		exit;
	}

	public function update_admin_menu_permission(){
		global $wppcp, $wppcp_settings_data;

		if( current_user_can('manage_options') ){	

			$visibility = isset( $_POST['visibility'] ) ? sanitize_text_field( $_POST['visibility'] ) : 0;
			$slug = isset( $_POST['slug'] ) ? sanitize_text_field( $_POST['slug'] ) : '';
			$user_roles = isset( $_POST['user_roles'] ) ? (array)( $_POST['user_roles'] ) : array();
			$user_roles_filtered = array();
			foreach ($user_roles as $key => $value) {
				$user_roles_filtered[$key] = sanitize_text_field($value);
			}
			if($visibility == '0'){
				$user_roles_filtered = array();
			}

			if( check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){

				$this->wppcp_options['admin_menu_visibility'][$slug] = array('visibility' => $visibility, 'user_roles' => $user_roles_filtered);

				update_option('wppcp_options',$this->wppcp_options);
			
				$admin_menu_settings = get_option('wppcp_options');
				// echo "<pre>";print_r($admin_menu_settings);exit;
				$admin_menu_settings = isset( $admin_menu_settings['admin_menu_visibility'][$slug] ) ? $admin_menu_settings['admin_menu_visibility'][$slug] : '';
				
				$wppcp_settings_data['admin_menu_visibility'] = isset($admin_menu_settings['visibility']) ? $admin_menu_settings['visibility'] : 0;
				$wppcp_settings_data['admin_menu_roles'] = isset($admin_menu_settings['user_roles']) ? $admin_menu_settings['user_roles'] : array() ;
				$wppcp_settings_data['admin_menu_slug'] = $slug;

				ob_start();
	      		$wppcp->template_loader->get_template_part('admin-menu-visibility');    
	      		$display = ob_get_clean(); 

				$result = array( 'msg' => $display , 'status' => 'success' );
			}else{
				$result = array( 'msg' => __('Invalid request.','wppcp'), 'status' => 'error' );
			}

		}else{
			$result = array( 'msg' => __('Permission denied.','wppcp'), 'status' => 'error' );
		}

		echo json_encode( $result );exit;
		exit;
	}
	
	public function restrict_admin_menus() {
	    if ( current_user_can('manage_options') ) {
	        return ;
	    }

	    global $menu, $submenu;
	    if ( ! isset( $menu ) || empty( $menu ) ) {
	      return;
	    }

	    $user              = wp_get_current_user();
	    $user_roles        = $user->roles;

	    $admin_menu_settings = get_option('wppcp_options');
		$admin_menu_settings = isset( $admin_menu_settings['admin_menu_visibility']) ? (array) $admin_menu_settings['admin_menu_visibility'] : array();
		$restricted_slugs = array();
		foreach ($admin_menu_settings as $slug => $menu_data) {
			$restricted_status = true;
			if($menu_data['visibility'] == 'user_roles'){
				$allowed_roles = (array) $menu_data['user_roles'];
				foreach ($user_roles as $role) {
					if(in_array($role, $allowed_roles)){
						$restricted_status = false;
					}
				}

				if($restricted_status){
					$restricted_slugs[] = $slug;
				}
			}
		}
			

	    foreach ( $menu as $key => $item ) {
	        if ( isset( $item[ 2 ] ) ) {
	            $menu_slug = $item[ 2 ];            
	            if ( in_array( $menu_slug, $restricted_slugs , false ) ) {                
	                $this->restrict_menu_access( $menu_slug , 'menu' );
	            }

	            if ( isset( $submenu ) && ! empty( $submenu[ $menu_slug ] ) ) {
	                foreach ( (array) $submenu[ $menu_slug ] as $subindex => $subitem ) {
	                    if ( in_array($subitem[ 2 ], $restricted_slugs)  ) {                         
	                        $this->restrict_menu_access( $menu_slug  , 'submenu' , $subitem[ 2 ]);
	                    }
	                }
	            }
	        }
	    }
	}

	public function restrict_menu_access( $menu_slug , $menu_type , $sub_menu_slug = '' ){

		if($menu_type == 'menu'){
			remove_menu_page( $menu_slug );
			$remove_slug = $menu_slug;
		}else{
			remove_submenu_page( $menu_slug, $sub_menu_slug );
			$remove_slug = $sub_menu_slug;
		}

		$url = basename( esc_url_raw( $_SERVER[ 'REQUEST_URI' ] ) );
		$url = htmlspecialchars( $url );
		$uri = parse_url( $url );

		if ( $remove_slug === $url ) {
			add_action( 'load-' . basename( $uri[ 'path' ] ), array($this, 'block_page_access') );
			return TRUE;
		}
	}

	public function block_page_access(){
		global $wp_query;
	    $wp_query->set_404();
	    status_header( 404 );
	    get_template_part( 404 ); 
	    exit();
	}


}

?>class-wppcp-site-lockdown.php000066600000020354151765001320012301 0ustar00<?php
class WPPCP_Site_Lockdown{

	public function __construct(){
		add_action('wppcp_admin_menu_pages',array($this, 'admin_menu_pages'));

		add_action('wppcp_custom_plugin_options_tab_content', array($this, 'tab_content'),10,3);
		
		add_action('wppcp_plugin_options_tabs', array($this, 'option_tabs'),10,2);

		add_action('wppcp_save_settings_page', array($this, 'save_settings'),10,2);

		add_action('template_redirect', array($this, 'check_site_lockdown'));
        

	}

	public function admin_menu_pages($params){
		add_submenu_page('wppcp-settings', __('Site Lockdown', 'wppcp' ), __('Site Lockdown', 'wppcp'), 'manage_options' ,'wppcp-site-lockdown-settings-page', array($this,'site_lockdown_settings'));
	}

	public function tab_content($tab,$private_content_settings,$params){
		global $wppcp_site_lockdown_settings_data,$wppcp;
		if($tab == 'wppcp_section_site_lockdown'){
			$data = isset($private_content_settings['site_lockdown']) ? $private_content_settings['site_lockdown'] : array();
// echo "<pre>";print_r($data);exit;
	        $wppcp_site_lockdown_settings_data['tab'] = $tab;
	        
	        $wppcp_site_lockdown_settings_data['lockdown_status'] = isset($data['lockdown_status']) ? $data['lockdown_status'] : 'disabled';
	        $wppcp_site_lockdown_settings_data['lockdown_allowed_pages'] = isset($data['lockdown_allowed_pages']) ? (array) $data['lockdown_allowed_pages'] : array();
	        $wppcp_site_lockdown_settings_data['lockdown_allowed_posts'] = isset($data['lockdown_allowed_posts']) ? (array) $data['lockdown_allowed_posts'] : array();
	        $wppcp_site_lockdown_settings_data['allowed_urls'] = isset($data['allowed_urls']) ? $data['allowed_urls'] : '';
	        $wppcp_site_lockdown_settings_data['redirect_url'] = isset($data['redirect_url']) ? $data['redirect_url'] : site_url();

	        $wppcp_site_lockdown_settings_data = apply_filters('wppcp_site_lockdown_settings_data',$wppcp_site_lockdown_settings_data, array('data' => $data, 'section' => 'wppcp_section_site_lockdown' ) );



	        $wppcp->template_loader->get_template_part('site-lockdown-settings'); 
		}
		 
	}

	public function site_lockdown_settings(){
        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_site_lockdown', __('Site Lockdown','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-site-lockdown' );
        
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title ( $_GET['tab'] ) : 'wppcp_section_site_lockdown';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $wppcp->settings->plugin_options_tabs('site_lockdown',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $wppcp->settings->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }

    public function option_tabs($type,$params){
    	global $wppcp;

    	if($type == 'site_lockdown'){
    		$wppcp->settings->plugin_settings_tabs['wppcp_section_site_lockdown']  = __('Site Lockdown Settings','wppcp');
    	}
    }

    public function save_settings($tab,$params){
        global $wppcp;

        if(isset($_POST['wppcp_site_lockdown'])){
            foreach($_POST['wppcp_site_lockdown'] as $k=>$v){
                switch ($k) {
                    case 'allowed_posts':
 					case 'allowed_pages':
                        break;
                    case 'lockdown_status':
                    	$v = sanitize_text_field($v);
                        break;
                    case 'allowed_urls':
                        $v = sanitize_textarea_field($v);
                        break;
                    case 'redirect_url':
                        $v = esc_url_raw($v);
                        break;
                }
                $this->settings[$k] = $v;
            }              
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['site_lockdown'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $wppcp->settings, 'admin_notices' ) ); 
    }

    public function check_site_lockdown(){
        global $wppcp,$pagenow;

        $private_content_settings  = get_option('wppcp_options');
        if(!isset($private_content_settings['general']['private_content_module_status'])){
            return;        
        }

        $lockdown_settings = isset($wppcp->settings->wppcp_options['site_lockdown']) ? $wppcp->settings->wppcp_options['site_lockdown'] : array();
        $lockdown_settings['lockdown_status'] = isset($lockdown_settings['lockdown_status']) ? $lockdown_settings['lockdown_status'] : 'disabled';
        //echo $lockdown_settings['lockdown_status'];exit;
        if( $lockdown_settings['lockdown_status'] != 'enabled'){
            return;
        }

        if(is_feed()){
            return;
        }

        if (is_user_logged_in ()) {
            return;
        }else{
            $this->user_id = 0;
        }

        $redirect_url = isset($lockdown_settings['redirect_url']) ? $lockdown_settings['redirect_url'] : '';
        if(trim($redirect_url) == ''){
            $redirect_url = site_url();
        }

        // Add globally skipped URL's, pages and posts
        $skipped_urls = array( strtok(rtrim($redirect_url,"/"), '?') , strtok(rtrim(wp_login_url(),"/"),'?'), strtok(rtrim(wp_registration_url(),"/"),'?') , strtok(rtrim(wp_lostpassword_url(),"/"),'?') );
        $skipped_pages = isset($lockdown_settings['lockdown_allowed_pages']) ? (array) $lockdown_settings['lockdown_allowed_pages'] : array();
        
        foreach ($skipped_pages as $page_id) {
           if($page_id != '0' && $page_id != ''){
                array_push($skipped_urls, strtok(rtrim(get_permalink( $page_id ),"/"),'?') );
           }
        }

        $skipped_posts = isset($lockdown_settings['lockdown_allowed_posts']) ? (array) $lockdown_settings['lockdown_allowed_posts'] : array() ;
        foreach ($skipped_posts as $page_id) {
           if($page_id != '0' && $page_id != ''){
                array_push($skipped_urls, strtok(rtrim(get_permalink( $page_id ),"/"),'?') );
           }
        }

        $lockdown_settings_allowed_urls = isset($lockdown_settings['allowed_urls']) ? $lockdown_settings['allowed_urls'] : '';
        $skipped_custom_urls = explode(PHP_EOL, $lockdown_settings_allowed_urls);
        foreach ($skipped_custom_urls as $url) {
            if($url != ''){
                array_push($skipped_urls, rtrim($url,"/"));
            }
        }

        $current_page_url = rtrim(wppcp_current_page_url(),"/");
        // echo "<pre>";print_R($skipped_urls);echo $current_page_url ;exit;

        $parsed_url = parse_url($current_page_url);
        $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
        $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
        $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
        $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
        $pass     = ($user || $pass) ? "$pass@" : '';
        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
 
        $current_page_url = rtrim($scheme.$user.$pass.$host.$port.$path,"/");
        // print_r($current_page_url);print_r($skipped_urls);exit;
        if(in_array($current_page_url, $skipped_urls)){
            return;
        }else{

            // Check for URL exceptions in admin area                
            if('wp-login' == $redirect_url){
                $url = add_query_arg( 'redirect_to', $current_page_url, wp_login_url() );
                wp_redirect($url);
                
            }else{
                
                $url = add_query_arg( 'redirect_to', $current_page_url, ($redirect_url) );
                // echo $url;exit;
                wp_redirect($url);
            }             
            exit;
           
        }        

    }
}class-wppcp-post-attachments.php000066600000025036151765001320013017 0ustar00<?php
/*  Supported files types
 	jpg,png,gif,pdf,csv,xls,ppt,pptx,xlsx,pdf,
*/
class WPPCP_Post_Attachments{

	public function __construct(){
		add_action( 'add_meta_boxes', array($this,'file_attachments_meta_box'));
		add_action( 'save_post', array($this,'save_file_attachments' ));
		add_filter( 'the_content' , array($this,'display_file_attachments' ));
		add_action( 'init', array( $this, 'file_attachment_download'));
	}

	public function file_attachments_meta_box(){
		$post_types = get_post_types( '', 'names' ); 
		$skipped_types = array('attachment','revision','nav_menu_item','wppcp_group','wppcp_fproduct_tabs');

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') || apply_filters('wppcp_file_attachment_setting_meta_box_visibility',false,array() ) ){
        
            foreach ( $post_types as $post_type ) {
                if(!in_array($post_type, $skipped_types)){

                	add_meta_box(
                        'wppcp-post-file-attachments-general',
                        __( 'WP Private Content Plus - File Attachments Settings', 'wppcp' ),
                        array($this,'file_attachments_settings'),
                        $post_type
                    );

                    add_meta_box(
                        'wppcp-post-file-attachments',
                        __( 'WP Private Content Plus - Manage File Attachments', 'wppcp' ),
                        array($this,'manage_file_attachments'),
                        $post_type
                    );
                }
            }
        }
	}

	public function manage_file_attachments($post){
        global $wppcp,$wppcp_attachments_params;

        wp_enqueue_media();
        wp_enqueue_script('jquery-ui-sortable');

        $wppcp_attachments_params['post'] = $post;

        ob_start();
        $wppcp->template_loader->get_template_part('manage-file-attachments');    
        $display = ob_get_clean();  
        echo $display;
    }

    public function file_attachments_settings($post){
        global $wppcp,$wppcp_attachments_params;

        $wppcp_attachments_params['post'] = $post;

        ob_start();
        $wppcp->template_loader->get_template_part('file-attachments-settings');    
        $display = ob_get_clean();  
        echo $display;
    }

    public function save_file_attachments($post_id){

    	$skipped_types = array('attachment','revision','nav_menu_item','forum','topic','reply','product','shop_order','download');
        if ( ! isset( $_POST['wppcp_file_attachment_nonce'] ) ) {
            return;
        }

        if ( ! wp_verify_nonce( $_POST['wppcp_file_attachment_nonce'], 'wppcp_file_attachment_settings' ) ) {
            return;
        }

        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
        }

        if ( ! ( current_user_can( 'manage_options', $post_id ) || current_user_can( 'wppcp_manage_options', $post_id ) ) ) {
            return;
        }

        $wppcp_post_files_list_title = isset($_POST['wppcp_post_files_list_title']) ? sanitize_text_field($_POST['wppcp_post_files_list_title']) : '';
		$wppcp_post_files_list_description = isset($_POST['wppcp_post_files_list_description']) ? sanitize_textarea_field($_POST['wppcp_post_files_list_description']) : '';
		update_post_meta( $post_id, '_wppcp_post_files_list_title', $wppcp_post_files_list_title );
		update_post_meta( $post_id, '_wppcp_post_files_list_description', $wppcp_post_files_list_description );

        $wppcp_attachments = isset($_POST['wppcp_attachments']) ? $_POST['wppcp_attachments'] : array();
        
        $wppcp_post_attachments = array();

		if(is_array($wppcp_attachments)){
			foreach ($wppcp_attachments as $key => $wppcp_attachment) {
                foreach ($wppcp_attachment as $wppcp_attachment_key => $value) {
                    $wppcp_attachment[$wppcp_attachment_key] = sanitize_text_field($value);
                }
				$wppcp_attachment['attach_id'] = (int) $key;
				array_push($wppcp_post_attachments,$wppcp_attachment);
			}

			update_post_meta( $post_id, '_wppcp_post_attachments', $wppcp_post_attachments );
		}

        
      
    }

    public function display_file_attachments($content){
    	global $post,$wppcp;

    	$wppcp->include_styles();

    	$skipped_types = array('attachment','revision','nav_menu_item','forum','topic','reply','product','shop_order','download');
        
    	if(is_single() || is_page() ){
    		if(!in_array($post->post_type, $skipped_types)){
    			$post_id = $post->ID;
    			$post_attachments = get_post_meta( $post_id, '_wppcp_post_attachments', true );

    			if(is_array($post_attachments)){

    				$wppcp_post_files_list_title = get_post_meta( $post_id, '_wppcp_post_files_list_title', true );
					$wppcp_post_files_list_description = get_post_meta( $post_id, '_wppcp_post_files_list_description', true );


    				$attachment_content = "<div class='wppcp-attachments-display-panel'>";

    				if($wppcp_post_files_list_title != ''){
    					$attachment_content .= "<div class='wppcp-attachments-display-panel-title'>".esc_html($wppcp_post_files_list_title)."</div>";
    				}

    				if($wppcp_post_files_list_description != ''){
    					$attachment_content .= "<div class='wppcp-attachments-display-panel-desc'>".esc_html($wppcp_post_files_list_description)."</div>";
    				}

    				$attachment_status = FALSE;
	                foreach($post_attachments as $attach_data){
	                    if($attach_data['attach_id'] != ''){
	                    	

	                    	if($this->verify_attachment_permission($attach_data)){
	                    		$attachment_status = TRUE;
	                    		$attachment = wp_get_attachment_url( $attach_data['attach_id'] );

	                    		if($this->verify_download_permission($attach_data)){

	                    			$url = $_SERVER['REQUEST_URI'];
									$url = wppcp_add_query_string($url,'wppcp_file_download=yes');
    								$url = wppcp_add_query_string($url,'wppcp_file_id='.$attach_data['attach_id']);
    								$url = wppcp_add_query_string($url,'wppcp_post_id='.$post_id);


	                    			$attachment_content .= "<div class='wppcp-attachments-display-panel-file' ><img src='".WPPCP_PLUGIN_URL  . "images/file-mini.png' />
	                    			<a href='".esc_url($url)."'>" . esc_html($attach_data['name']). "</a></div>";

	                    		}else{
	                    			$attachment_content .= "<div class='wppcp-attachments-display-panel-file' ><img src='".WPPCP_PLUGIN_URL  . "images/file-mini.png' />" . esc_html($attach_data['name']). "</div>";
	                    		}

	                    	}
	                    }
	                }

	                $attachment_content .= "</div>";

	                if($attachment_status){
	                	$content .= $attachment_content;
	                }	                
	            }
    		}    		
    	}

    	return $content;
    }

    public function verify_attachment_permission($attach_data){
    	$visibility = isset($attach_data['visibility']) ? $attach_data['visibility'] : 'all';
    	$visibility_status = FALSE;
    	switch ($visibility) {
    		case 'all':
    			$visibility_status = TRUE;
    			break;
    		
    		case 'guest':
    			if(!is_user_logged_in() || current_user_can( 'manage_options') || current_user_can('wppcp_manage_options') ){
    				$visibility_status = TRUE;
    			}
    			break;

    		case 'member':
    			if(is_user_logged_in()){
    				$visibility_status = TRUE;
    			}
    			break;
    	}

        $visibility_status = apply_filters('wppcp_attachment_view_permission_status', $visibility_status , array('attach_data' => $attach_data ));

    	return $visibility_status;
    }

    public function verify_download_permission($attach_data){
    	$download_permission = isset($attach_data['download_permission']) ? $attach_data['download_permission'] : 'all';
    	$download_permission_status = FALSE;
    	switch ($download_permission) {
    		case 'all':
    			$download_permission_status = TRUE;
    			break;
    		
    		case 'guest':
    			if(!is_user_logged_in() || current_user_can( 'manage_options') || current_user_can('wppcp_manage_options') ){
    				$download_permission_status = TRUE;
    			}
    			break;

    		case 'member':
    			if(is_user_logged_in()){
    				$download_permission_status = TRUE;
    			}
    			break;
    	}

        $download_permission_status = apply_filters('wppcp_attachment_download_permission_status', $download_permission_status , array('attach_data' => $attach_data ));

    	return $download_permission_status;
    }

    public function file_attachment_download(){
    	if(isset($_GET['wppcp_file_download']) && sanitize_text_field($_GET['wppcp_file_download']) =='yes'){
			$wppcp_file_download = sanitize_text_field($_GET['wppcp_file_download']);
			$wppcp_file_id = isset($_GET['wppcp_file_id']) ? (int) sanitize_text_field($_GET['wppcp_file_id']) : '';
			$wppcp_post_id = isset($_GET['wppcp_post_id']) ? (int) sanitize_text_field($_GET['wppcp_post_id']) : '';

			if($wppcp_file_id != '' && $wppcp_post_id != ''){
				$file_link = wp_get_attachment_url($wppcp_file_id);

				$upload_dir = wp_upload_dir(); 
				$file_dir =  str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $file_link);

				$post_attachments = get_post_meta( $wppcp_post_id, '_wppcp_post_attachments', true );
				foreach ($post_attachments as $key => $attach_data) {
					if($attach_data['attach_id'] == $wppcp_file_id){
						// echo "<pre>";print_r($attach_data);exit;

                        if ($this->verify_download_permission($attach_data)){

    						$file_mime_type = isset($attach_data['mime']) ? $attach_data['mime'] : '';
    						if($file_mime_type != ''){

    							header('Cache-Control: public');
    							header('Content-Description: File Transfer');
    							header('Content-disposition: attachment;filename='.basename($file_dir));

    						
    							header('Content-Type: '. $file_mime_type);
    							header('Content-Transfer-Encoding: binary');
    							header('Content-Length: '. filesize($file_dir));
    							readfile($file_dir);
    							exit;
    						}
                        }else {
                            echo sprintf(__('You need to <a href="%s">login</a> before downloading this file.','wppcp'),wp_login_url());
                            exit();
                        }
						
					}
				}
				
			}			
		}
    }
}

class-wppcp-private-posts-pages.php000066600000051221151765001320013431 0ustar00<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

/* Manage content restriction shortcodes */
class WPPCP_Private_Posts_Pages{
    
    public $current_user;
    public $private_content_settings;
    
    /* intialize the settings and shortcodes */
    public function __construct(){
        global $wppcp;

        add_action('init', array($this, 'init'));           
      
        add_action( 'add_meta_boxes', array($this,'add_post_restriction_box' ));

        add_action( 'save_post', array($this,'save_post_restrictions' ));

        add_action('template_redirect', array($this, 'validate_restrictions'), 1); 
        add_action('template_redirect', array($this, 'validate_post_author_restrictions'), 5);
        
        add_filter( 'woocommerce_product_is_visible', array($this,'woocommerce_product_is_visible'),10,2);
        add_filter( 'bbp_get_forum_content', array($this,'bbporess_forum_is_visible'),10,2);
                                   
    }

    public function init(){
        $this->current_user = get_current_user_id(); 
    }
    
    public function add_post_restriction_box(){
        $post_types = get_post_types( '', 'names' ); 
        $skipped_types = array('attachment','revision','nav_menu_item','wppcp_private_block','wppcp_group', 'wppcp_fproduct_tabs');

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') || apply_filters('wppcp_restriction_setting_meta_box_visibility',false,array() ) ){
        
            foreach ( $post_types as $post_type ) {
                if(!in_array($post_type, $skipped_types)){
                    add_meta_box(
                        'wppcp-post-restrictions',
                        __( 'WP Private Content Plus - Restriction Settings', 'wppcp' ),
                        array($this,'add_post_restrictions'),
                        $post_type,
                        'normal',
                        'low'
                    );

                    do_action('wppcp_custom_post_restriction_boxes', $post_type, array() );
                }
            }
        }


        $wppcp_options = get_option('wppcp_options');

        if(isset($wppcp_options['general']['author_post_page_restrictions_status'])){
            foreach ( $post_types as $post_type ) {
                if(!in_array($post_type, $skipped_types)){
                    add_meta_box(
                        'wppcp-post-author-restrictions',
                        __( 'WP Private Content Plus - Post Author Restrictions', 'wppcp' ),
                        array($this,'add_post_author_restrictions'),
                        $post_type,
                        'normal',
                        'low'
                    );
                }
            }
        }       
    }

    public function add_post_restrictions($post){
        global $wppcp,$post_page_restriction_params;

        $wppcp->settings->load_wppcp_select2_scripts_style();

        $post_page_restriction_params['post'] = $post;

        ob_start();
        $wppcp->template_loader->get_template_part('post-page-restriction-meta');    
        $display = ob_get_clean();  
        echo $display;
    }

    public function save_post_restrictions($post_id){

        $skipped_types = array('attachment','revision','nav_menu_item');

        if ( ! isset( $_POST['wppcp_restriction_settings_nonce'] ) ) {
            return;
        }

        if ( ! wp_verify_nonce( $_POST['wppcp_restriction_settings_nonce'], 'wppcp_restriction_settings' ) ) {
            return;
        }

        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return;
        }

        if ( ! ( current_user_can( 'manage_options', $post_id ) || current_user_can( 'wppcp_manage_options', $post_id ) ) ) {
            return;
        }

        $visibility = isset( $_POST['wppcp_post_page_visibility'] ) ? sanitize_text_field($_POST['wppcp_post_page_visibility']) : 'none';
        $redirection_url = isset( $_POST['wppcp_post_page_redirection_url'] ) ? esc_url_raw($_POST['wppcp_post_page_redirection_url']) : '';
        $visible_roles = isset( $_POST['wppcp_post_page_roles'] ) ? (array) $_POST['wppcp_post_page_roles'] : array();
        $visible_roles_filtered = array();
        foreach ($visible_roles as $key => $value) {
            $visible_roles_filtered[$key] = sanitize_text_field($value);
        }

        $allowed_users = isset( $_POST['wppcp_post_page_users'] ) ? (array) $_POST['wppcp_post_page_users'] : array();
        $allowed_users_filtered = array();
        foreach ($allowed_users as $key => $value) {
            $allowed_users_filtered[$key] = sanitize_text_field($value);
        }

        // Update the meta field in the database.
        update_post_meta( $post_id, '_wppcp_post_page_visibility', $visibility );
        update_post_meta( $post_id, '_wppcp_post_page_redirection_url', $redirection_url );
        update_post_meta( $post_id, '_wppcp_post_page_roles', $visible_roles_filtered );
        update_post_meta( $post_id, '_wppcp_post_page_allowed_users', $allowed_users_filtered );

        if(isset($_POST['wppcp_post_page_author_visibility'])){
            $visibility = isset( $_POST['wppcp_post_page_author_visibility'] ) ? sanitize_text_field($_POST['wppcp_post_page_author_visibility']) : 'no';
            $redirection_url = isset( $_POST['wppcp_post_page_author_redirection_url'] ) ? esc_url_raw($_POST['wppcp_post_page_author_redirection_url']) : '';
        
            update_post_meta( $post_id, '_wppcp_post_page_author_visibility', $visibility );
            update_post_meta( $post_id, '_wppcp_post_page_author_redirection_url', $redirection_url );
        }

        do_action('wppcp_post_iniline_restrictions',$post_id , array());

    }

    public function validate_restrictions(){
        global $wppcp,$wp_query,$wppcp_cpt_id;;

        $private_content_settings  = get_option('wppcp_options');


        if(!isset($private_content_settings['general']['private_content_module_status'])){
            return;        
        }

        $this->current_user = wp_get_current_user();

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return;
        }

        if (! isset($wp_query->post->ID) ) {
            return;
        }

        if(is_page() || is_single()){
            $post_id = $wp_query->post->ID;

            $protection_status = $this->protection_status($post_id);

            if($protection_status){
                if(trim($protection_status) == 'none'){
                    if($this->global_protection_status($post_id)){
                        return;
                    }else{

                        $url = $private_content_settings['general']['post_page_redirect_url'];
                        $post_redirection_url = get_post_meta( $post_id, '_wppcp_post_page_redirection_url', true );
                        if(trim($post_redirection_url) != ''){
                            $url = $post_redirection_url;
                        }
                        $url = apply_filters('wppcp_global_post_restriction_redirect',$url, array());
                        
                        if(trim($url) == ''){
                            $url = get_home_url();
                        }

                        $url = esc_url_raw($url);
                        wp_redirect($url);exit;
                    }
                }
                return;
            }else{
                $url = $private_content_settings['general']['post_page_redirect_url'];
                $post_redirection_url = get_post_meta( $post_id, '_wppcp_post_page_redirection_url', true );
                if(trim($post_redirection_url) != ''){
                    $url = $post_redirection_url;
                }
                $url = apply_filters('wppcp_single_post_restriction_redirect',$url, array());
                
                if(trim($url) == ''){
                    $url = get_home_url();
                }

                $url = esc_url_raw($url);
                wp_redirect($url);exit;
            }

        }

        // if(is_tax() is_tag() is_category() is_author()
       
        if(is_archive() || is_feed() || is_search() || is_home() ){
            
            if(isset($wp_query->posts) && is_array($wp_query->posts)){
                foreach ($wp_query->posts as $key => $post_obj) {
                    $protection_status = $this->protection_status($post_obj->ID);
                    if(!$protection_status){
                        $wp_query->posts[$key]->post_content = apply_filters('wppcp_archive_page_restrict_message', __('You don\'t have permission to view the content','wppcp'), array());
                    }else{
                        if(trim($protection_status) == 'none'){

                            if($this->global_protection_status($post_obj->ID)){
                                
                            }else{                               
                               $wp_query->posts[$key]->post_content = apply_filters('wppcp_archive_page_restrict_message', __('You don\'t have permission to view the content','wppcp'), array());
                                                  
                            }
                        }
                        
                    }
                }
            }
        }

        return;
    }

    public function protection_status($post_id){
        global $wppcp;

        $visibility = get_post_meta( $post_id, '_wppcp_post_page_visibility', true );
        $visible_roles = get_post_meta( $post_id, '_wppcp_post_page_roles', true );
        if(!is_array($visible_roles)){
            $visible_roles = array();
        }

        $allowed_users = get_post_meta( $post_id, '_wppcp_post_page_allowed_users', true );
        if(!is_array($allowed_users)){
            $allowed_users = array();
        }

        switch ($visibility) {
            case 'all':
                return TRUE;
                break;
            
            case 'guest':
                if(is_user_logged_in()){
                    return FALSE;
                }else{
                    return TRUE;
                }
                break;

            case 'member':
                if(is_user_logged_in()){
                    return TRUE;
                }else{
                    return FALSE;
                }
                break;

            case 'role':
                if(is_user_logged_in()){
                    if(count($visible_roles) == 0){
                        return FALSE;
                    }else{
                        $user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
                        foreach ($visible_roles as  $visible_role ) {
                            if(in_array($visible_role, $user_roles)){
                                return TRUE;
                            }
                        }
                        return FALSE;
                    }
                }else{
                    return FALSE;
                }
                
                break;
                
            case 'users':
                if(is_user_logged_in()){
                    if(count($allowed_users) == 0){
                        return FALSE;
                    }else{
                        
                        foreach ($allowed_users as  $allowed_user ) {
                            if(in_array($this->current_user->ID, $allowed_users)){
                                return TRUE;
                            }
                        }
                        return FALSE;
                    }
                }else{
                    return FALSE;
                }
                
                break;            

            default:
                return "none";
                break;
        }

        return TRUE;
    }

    public function global_protection_status($post_id){
        global $wppcp;

        $predefined_post_types = array('forum','topic','product');
        $predefined_post_type_labels = array('forum' => 'bbpress_forums','topic' => 'bbpress_topics','product' => 'woo_products');

        $private_content_settings = get_option('wppcp_options');

        $post_type = get_post_type($post_id);
        if($post_type != 'post' && $post_type != 'page' && !in_array($post_type, $predefined_post_types)){
            return TRUE;
        }

        
        if($post_type == 'post'){
            $data = isset($private_content_settings['global_post_restriction']) ? $private_content_settings['global_post_restriction'] : array();
            $restrict_all_posts_status = isset($data['restrict_all_posts_status']) ? $data['restrict_all_posts_status'] :'0';
            $visibility = isset($data['all_post_visibility']) ? $data['all_post_visibility'] :'all';
            $visible_roles = isset($data['all_post_user_roles']) ? (array) $data['all_post_user_roles'] : array();

            if($restrict_all_posts_status == '0'){
                return TRUE;
            }
         
        }else if($post_type == 'page'){
            $data = isset($private_content_settings['global_page_restriction']) ? $private_content_settings['global_page_restriction'] : array();
            $restrict_all_pages_status = isset($data['restrict_all_pages_status']) ? $data['restrict_all_pages_status'] :'0';
            $visibility = isset($data['all_page_visibility']) ? $data['all_page_visibility'] :'all';
            $visible_roles = isset($data['all_page_user_roles']) ? (array) $data['all_page_user_roles'] : array();

            if($restrict_all_pages_status == '0'){
                return TRUE;
            }

        }else if(in_array($post_type, $predefined_post_types)){
            $data = isset($private_content_settings['global_'.$predefined_post_type_labels[$post_type].'_restriction']) ? $private_content_settings['global_'.$predefined_post_type_labels[$post_type].'_restriction'] : array();
            $restrict_all_status = isset($data['restrict_all_'.$predefined_post_type_labels[$post_type].'_status']) ? $data['restrict_all_'.$predefined_post_type_labels[$post_type].'_status'] :'0';
            $visibility = isset($data['all_'.$predefined_post_type_labels[$post_type].'_visibility']) ? $data['all_'.$predefined_post_type_labels[$post_type].'_visibility'] :'all';
            $visible_roles = isset($data['all_'.$predefined_post_type_labels[$post_type].'_user_roles']) ? $data['all_'.$predefined_post_type_labels[$post_type].'_user_roles'] : array();
//echo "<pre>";print_r($private_content_settings);exit;
            if($restrict_all_status == '0'){
                return TRUE;
            }

        }else{
            return;
        }

        if(!is_array($visible_roles)){
            $visible_roles = array();
        }


        switch ($visibility) {
            case 'all':
                return TRUE;
                break;
            
            case 'guest':
                if(is_user_logged_in()){
                    return FALSE;
                }else{
                    return TRUE;
                }
                break;

            case 'member':
                if(is_user_logged_in()){
                    return TRUE;
                }else{
                    return FALSE;
                }
                break;

            case 'role':
                if(is_user_logged_in()){
                    if(count($visible_roles) == 0){
                        return FALSE;
                    }else{
                        $user_roles = $wppcp->roles_capability->get_user_roles_by_id($this->current_user);
                        foreach ($visible_roles as  $visible_role ) {
                            if(in_array($visible_role, $user_roles)){
                                return TRUE;
                            }
                        }
                        return FALSE;
                    }
                }else{
                    return FALSE;
                }
                
                break;
                
            
        }

        return TRUE;
    }

    public function woocommerce_product_is_visible($visibility,$id){
        $protection_status = $this->protection_status($id);
        if(!$protection_status){
            $visibility = FALSE;
        }else{
            if(trim($protection_status) == 'none'){
                if($this->global_protection_status($id)){
                    
                }else{
                   $visibility = FALSE;
                }
            }
            
        }
        return $visibility;
    }

    public function bbporess_forum_is_visible($content,$id){
        $protection_status = $this->protection_status($id);
        if(!$protection_status){
            $content = apply_filters('wppcp_archive_page_restrict_message', __('You don\'t have permission to view the content','wppcp'), array());
                    
        }else{
            if(trim($protection_status) == 'none'){
                if($this->global_protection_status($id)){
                    
                }else{
                   $content = apply_filters('wppcp_archive_page_restrict_message', __('You don\'t have permission to view the content','wppcp'), array());
            
                }
            }
            
        }
        return $content;
    }

    public function add_post_author_restrictions($post){
        global $wppcp,$post_page_restriction_params;

        $wppcp->settings->load_wppcp_select2_scripts_style();

        $post_page_restriction_params['post'] = $post;

        ob_start();
        $wppcp->template_loader->get_template_part('post-page-author-restriction-meta');    
        $display = ob_get_clean();  
        echo $display;
    }

    public function validate_post_author_restrictions(){
        global $wppcp,$wp_query,$wppcp_cpt_id;;

        $private_content_settings  = get_option('wppcp_options');


        if(!isset($private_content_settings['general']['private_content_module_status'])){
            return;        
        }

        $this->current_user = wp_get_current_user();

        if(current_user_can('manage_options') || current_user_can('wppcp_manage_options') ){
            return;
        }

        if (! isset($wp_query->post->ID) ) {
            return;
        }

        if ( get_post_meta( $wp_query->post->ID, '_wppcp_post_page_author_visibility', true ) == 'no' ||
            get_post_meta( $wp_query->post->ID, '_wppcp_post_page_author_visibility', true ) == '' ) {
           return;
        }

        if(is_page() || is_single()){
            $post_id = $wp_query->post->ID;

            $protection_status = $this->protection_author_status($post_id);

            if($protection_status){
                return;
            }else{
                $url = $private_content_settings['general']['post_page_redirect_url'];
                $post_redirection_url = get_post_meta( $post_id, '_wppcp_post_page_author_redirection_url', true );
                if(trim($post_redirection_url) != ''){
                    $url = $post_redirection_url;
                }
                $url = apply_filters('wppcp_single_post_restriction_redirect',$url, array());
                
                if(trim($url) == ''){
                    $url = get_home_url();
                }

                $url = esc_url_raw($url);
                wp_redirect($url);exit;
            }
        }

   
        if(is_archive() || is_feed() || is_search() || is_home() ){
            
            if(isset($wp_query->posts) && is_array($wp_query->posts)){
                foreach ($wp_query->posts as $key => $post_obj) {
                    $protection_status = $this->protection_author_status($post_obj->ID);
                    if(!$protection_status){
                        $wp_query->posts[$key]->post_content = apply_filters('wppcp_archive_page_restrict_message', __('You don\'t have permission to view the content','wppcp'), array());
                    }
                }
            }
        }

        return;
    }

    public function protection_author_status($post_id){
        global $wppcp;

        if(!is_user_logged_in()){
            return FALSE;
        }else{

            $post   = get_post( $post_id );
            $author_id = $post->post_author;

            
            if($this->current_user->ID == $author_id || current_user_can('manage_options')
                ){
                return TRUE;
            }else{
                return FALSE;
            }
        }
    }
}


class-wppcp-settings.php000066600000227560151765001320011367 0ustar00<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

/* Manage settings of WP Private Content Plus plugin */
class WPPCP_Settings{
    
    public $template_locations;
    public $current_user;
    
    /* Intialize actions for plugin settings */
    public function __construct(){
        
        add_action('init', array($this, 'init'));
        add_action('admin_menu', array(&$this, 'admin_settings_menu'), 9);
        add_action('init', array($this,'save_settings_page') );
        
        add_action('wp_ajax_wppcp_load_private_page_users', array($this, 'wppcp_load_private_page_users'));
        add_action('wp_ajax_wppcp_save_user_role_hierarchy', array($this, 'wppcp_save_user_role_hierarchy'));

        add_action('wp_ajax_wppcp_load_restriction_users', array($this, 'wppcp_load_restriction_users'));
        add_action('admin_enqueue_scripts', array($this,'wppcp_conditional_scripts'));
        add_action('admin_footer', array($this,'wppcp_deactivate_popup'));

        /* Welcome Screen */
        add_action( 'admin_menu', array( $this, 'welcome_plus' ));
        add_action( 'admin_head', array( $this, 'hide_welcome' ));
        add_action( 'admin_init', array( $this, 'display_welcome_screen'  ), 9999 );
    }

    public function welcome_plus(){
        add_dashboard_page(
            __( 'Welcome to WP Private Content Plus', 'wppcp' ),
            __( 'Welcome to WP Private Content Plus', 'wppcp' ),
            apply_filters( 'wppcp_welcome_cap', 'manage_options' ),
            'wppcp-welcome-screen',
            array( $this, 'welcome_screen' )
        );
    }

    public function hide_welcome() {
        remove_submenu_page( 'index.php', 'wppcp-welcome-screen' );
    }

    public function welcome_screen(){
        global $wppcp;

        ob_start();
        $wppcp->template_loader->get_template_part( 'welcome-screen');
        $display = ob_get_clean();
        echo $display;    
    }

    public function display_welcome_screen(){
        if ( ! get_transient( 'wppcp_welcome_redirect' ) ) {
            return;
        }

        delete_transient( 'wppcp_welcome_redirect' );
        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
            return;
        }

        wp_safe_redirect( admin_url( 'index.php?page=wppcp-welcome-screen' ) );
    }

    public function init(){
        $this->current_user = get_current_user_id();

        $this->wppcp_options = get_option('wppcp_options'); 
          
    }
    
    /*  Save settings tabs */
    public function save_settings_page(){

        if(!is_admin())
            return;
        
        $wppcp_settings_pages = array('wppcp-settings','wppcp-search-settings-page','wppcp-password-settings-page','wppcp-global-restrictions','wppcp-upme-settings',
            'wppcp-security-settings-page','wppcp-site-lockdown-settings-page');


        if( ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) 
            && isset($_POST['wppcp_tab']) ){

            if( isset($_GET['page']) && in_array($_GET['page'],$wppcp_settings_pages) && wp_verify_nonce( $_POST['wppcp_settings_page_nonce_field'], 'wppcp_settings_page_nonce' ) ) {

                $tab = '';
                
                $allowed_tabs = array('wppcp_section_general','wppcp_section_information','wppcp_section_user_role_hierarchy','wppcp_section_wppcp_permissions',
                    'wppcp_section_global_post','wppcp_section_global_page',
                    'wppcp_section_search_general','wppcp_section_search_restrictions',
                    'wppcp_section_security_ip','wppcp_section_admin_menu',
                    'wppcp_section_password_global','wppcp_section_upme_general',
                    'wppcp_section_upme_search','wppcp_section_upme_member_list','wppcp_section_upme_member_profile','wppcp_section_site_lockdown');

                if ( isset ( $_POST['wppcp_tab'] ) )
                   $tab = sanitize_text_field($_POST['wppcp_tab']); 

                if($tab != '' && in_array($tab, $allowed_tabs )){
                    $func = 'save_'.$tab;
                    
                    if(method_exists($this,$func)){
                        $this->$func();
                    }else{
                        do_action('wppcp_save_settings_page',$tab,array());
                    }
                }

            }else{
                add_action( 'admin_notices', array( $this, 'admin_notices_failed' ) ); 
            } 
            
        }
    }
    
    /* Include necessary js and CSS files for admin section */
    public function include_scripts(){

        wp_register_style('wppcp_admin_css', WPPCP_PLUGIN_URL . 'css/wppcp-admin.css');
        wp_enqueue_style('wppcp_admin_css');

        $wppcp_plugin_data = (array) get_option('wppcp_plugin_data');
        if(!isset($wppcp_plugin_data['init_deactivation'])){
            $init_deactivation = 'no';
        }else{
            $init_deactivation = 'yes';
        }
        
        wp_register_script('wppcp_admin_js', WPPCP_PLUGIN_URL . 'js/wppcp-admin.js', array('jquery','jquery-ui-sortable'));
        wp_enqueue_script('wppcp_admin_js');
        
        $custom_js_strings = array(        
            'AdminAjax' => admin_url('admin-ajax.php'),
            'images_path' =>  WPPCP_PLUGIN_URL . 'images/',
            'init_deactivation' => $init_deactivation,
            'Messages'  => array(
                                'userEmpty' => __('Please select a user.','wppcp'),
                                'addToPost' => __('Add to Post','wppcp'), 
                                'insertToPost' => __('Insert Files to Post','wppcp'),   
                                'removeGroupUser' => __('Removing User...','wppcp'),
                                'loading' => __('Loading...','wppcp'), 
                                'saving' => __('Saving...','wppcp'),   
                            ),
            'nonce' => wp_create_nonce('wppcp-admin'),   

        );

        wp_localize_script('wppcp_admin_js', 'WPPCPAdmin', $custom_js_strings);
    }
    
    /* Intialize settings page and tabs */
    public function admin_settings_menu(){
        global $submenu;

        add_action('admin_enqueue_scripts', array($this,'include_scripts'));
        
        add_menu_page(__('Private Content Settings', 'wppcp' ), __('Private Content Settings', 'wppcp' ),
            apply_filters('wppcp_main_settings_page_capability','manage_options',array()),'wppcp-settings',array(&$this,'settings'));
        
        add_submenu_page('wppcp-settings',__('Global Restrictions', 'wppcp' ), __('Global Restrictions', 'wppcp' ),
            apply_filters('wppcp_global_restrictions_settings_page_capability','manage_options',array()),'wppcp-global-restrictions',array(&$this,'global_restrictions_settings'));
        
        add_submenu_page('wppcp-settings', __('Search', 'wppcp' ), __('Search Settings', 'wppcp'),
            apply_filters('wppcp_search_settings_page_capability','manage_options',array()),'wppcp-search-settings-page',array(&$this,'search_settings'));
       
        add_submenu_page('wppcp-settings', __('Password', 'wppcp' ), __('Password Settings', 'wppcp'),
            apply_filters('wppcp_password_settings_page_capability','manage_options',array()),'wppcp-password-settings-page',array(&$this,'password_settings'));
       
        add_submenu_page('wppcp-settings', __('Private User Page', 'wppcp' ), __('Private User Page', 'wppcp'),
            apply_filters('wppcp_private_page_settings_page_capability','manage_options',array()),'wppcp-private-user-page',array(&$this,'private_user_page'));
        
        add_submenu_page('wppcp-settings',__('Admin Permissions', 'wppcp' ), __('Admin Permissions', 'wppcp' ),
            apply_filters('wppcp_admin_permission_settings_page_capability','manage_options',array()),'wppcp-admin-permissions',array(&$this,'admin_permission_settings'));

        add_submenu_page('wppcp-settings', __('Security Settings', 'wppcp' ), __('Security Settings', 'wppcp'),
            apply_filters('wppcp_security_settings_page_capability','manage_options',array()),'wppcp-security-settings-page',array(&$this,'security_settings'));

        do_action('wppcp_admin_menu_pages', array() );
        
        
        add_submenu_page('wppcp-settings', __('User Profiles Made Easy', 'wppcp' ), __('User Profiles Made Easy', 'wppcp'),
            apply_filters('wppcp_upme_settings_page_capability','manage_options',array()),'wppcp-upme-settings',array(&$this,'upme_settings'));

        
       
        add_submenu_page('wppcp-settings', __('Getting Started', 'wppcp' ), __('Getting Started', 'wppcp'),
            'manage_options','wppcp-help',array(&$this,'help'));
       
        add_submenu_page('wppcp-settings', __('PRO Version', 'wppcp' ), __('PRO Version', 'wppcp'),
            'manage_options','wppcp-pro',array(&$this,'pro'));
       
        $url = 'https://www.wpexpertdeveloper.com/request-pro-version-trial/';    
        $label = __('Try PRO Version', 'wppcp');
        $submenu['wppcp-settings'][] = array( $label , 'manage_options', $url);
        
        add_submenu_page('wppcp-settings', __('Addons', 'wppcp' ), __('Addons', 'wppcp'),
            'manage_options','wppcp-pro-addons',array(&$this,'pro_addons'));
       
        $url = 'https://www.wpexpertdeveloper.com/wp-private-content-plus-faq';    
        $label = __('FAQ', 'wppcp');
        $submenu['wppcp-settings'][] = array( $label , 'manage_options', $url);

        
        
    }  
    
    /* Display settings */
    public function settings(){
        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_general', __('General Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-general' );
        add_settings_section( 'wppcp_section_information', __('Information Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-general' );
        add_settings_section( 'wppcp_section_user_role_hierarchy', __('User Role Hierarchy','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-general' );
        add_settings_section( 'wppcp_section_wppcp_permissions', __('Restriction Permissions','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-general' );
        
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_general';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('general',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
		$wppcp->template_loader->get_template_part( 'menu-page-container');
		$display = ob_get_clean();
		echo $display;
        
    
    }

    public function global_restrictions_settings(){
        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_global_post', __('Post Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-general' );
        
        add_settings_section( 'wppcp_section_global_page', __('Page Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-general' );
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_global_post';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('global_restrictions',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;
        
    
    }
    
    /* Manage settings tabs for the plugin */
    public function plugin_options_tabs($type,$tab) {
        $current_tab = $tab;
        $this->plugin_settings_tabs = array();
        
        switch($type){

            case 'general':
                $this->plugin_settings_tabs['wppcp_section_general']  = __('General Settings','wppcp');
                $this->plugin_settings_tabs['wppcp_section_information']  = __('Information Settings','wppcp');
                $this->plugin_settings_tabs['wppcp_section_user_role_hierarchy']  = __('User Role Hierarchy','wppcp');
                $this->plugin_settings_tabs['wppcp_section_wppcp_permissions']  = __('Restriction Permissions','wppcp');
                
                break;

            case 'global_restrictions':
                $this->plugin_settings_tabs['wppcp_section_global_post']  = __('Post Settings','wppcp');
                $this->plugin_settings_tabs['wppcp_section_global_page']  = __('Page Settings','wppcp');
                break;   

            case 'search':
                $this->plugin_settings_tabs['wppcp_section_search_general']  = __('Search Settings','wppcp');
                $this->plugin_settings_tabs['wppcp_section_search_restrictions']  = __('Search Restrictions','wppcp');
                break;

            case 'security':
                $this->plugin_settings_tabs['wppcp_section_security_ip']  = __('IP Restrictions','wppcp');
                break;

            case 'admin_permissions':
                $this->plugin_settings_tabs['wppcp_section_admin_menu']  = __('Admin Menu Restrictions','wppcp');
                break;

            case 'password':
                $this->plugin_settings_tabs['wppcp_section_password_global']  = __('Password Settings','wppcp');                
                break;  

                  

            case 'upme_general':
                $this->plugin_settings_tabs['wppcp_section_upme_general']  = __('UPME General Settings','wppcp');                
                $this->plugin_settings_tabs['wppcp_section_upme_search']  = __('UPME Search Settings','wppcp');                
                $this->plugin_settings_tabs['wppcp_section_upme_member_list']  = __('UPME Member List Settings','wppcp');                
                $this->plugin_settings_tabs['wppcp_section_upme_member_profile']  = __('UPME Member Profile Settings','wppcp');                
                break;  

            case 'private_page':
                $this->plugin_settings_tabs['wppcp_section_private_page_user']  = __('Private Page','wppcp');
                $this->plugin_settings_tabs['wppcp_section_private_page_bulk_content']  = __('Bulk Private Page Content','wppcp');
                break;

            default:
                do_action('wppcp_plugin_options_tabs',$type, array());
                break;

              

        }
        
        ob_start();
        ?>

        <h2 class="nav-tab-wrapper">
        <?php 
            foreach ( $this->plugin_settings_tabs as $tab_key => $tab_caption ) {
            $active = $current_tab == $tab_key ? 'nav-tab-active' : '';
            $page = isset($_GET['page']) ? sanitize_title( $_GET['page'] ) : '';
        ?>
                <a class="nav-tab <?php echo $active; ?> " href="?page=<?php echo $page; ?>&tab=<?php echo esc_html($tab_key); ?>"><?php echo esc_html($tab_caption); ?></a>
            
        <?php } ?>
        </h2>

        <?php
                
        return ob_get_clean();
    }
    
    /* Manage settings tab contents for the plugin */
    public function plugin_options_tab_content($tab,$params = array()){
        global $wppcp,$wppcp_settings_data,$wppcp_search_settings_data,$wppcp_password_settings_data,
        $wppcp_security_settings_data;
        
        $post_types = $wppcp->posts->get_post_types();

        $private_content_settings = get_option('wppcp_options');
    
        $this->load_wppcp_select2_scripts_style();
        
        ob_start();
        switch($tab){
            case 'wppcp_section_general':                
	            $data = isset($private_content_settings['general']) ? $private_content_settings['general'] : array();
      
                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['private_content_module_status'] = isset($data['private_content_module_status']) ? $data['private_content_module_status'] :'0';
                $wppcp_settings_data['post_page_redirect_url'] = isset($data['post_page_redirect_url']) ? $data['post_page_redirect_url'] :'';
                $wppcp_settings_data['search_restrictions_module_status'] = isset($data['search_restrictions_module_status']) ? $data['search_restrictions_module_status'] :'0';
                $wppcp_settings_data['dashboard_restrictions_widget_status'] = isset($data['dashboard_restrictions_widget_status']) ? $data['dashboard_restrictions_widget_status'] :'0';
                $wppcp_settings_data['author_post_page_restrictions_status'] = isset($data['author_post_page_restrictions_status']) ? $data['author_post_page_restrictions_status'] :'0';
    
                $wppcp->template_loader->get_template_part('general-settings');            
                break;

            case 'wppcp_section_information':                
                $data = isset($private_content_settings['information']) ? $private_content_settings['information'] : array();
      
                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['pro_info_post_restrictions'] = isset($data['pro_info_post_restrictions']) ? $data['pro_info_post_restrictions'] :'1';
                $wppcp_settings_data['pro_info_post_attachments'] = isset($data['pro_info_post_attachments']) ? $data['pro_info_post_attachments'] :'1';
                $wppcp_settings_data['pro_info_search_restrictions'] = isset($data['pro_info_search_restrictions']) ? $data['pro_info_search_restrictions'] :'1';
                $wppcp_settings_data['pro_info_private_page'] = isset($data['pro_info_private_page']) ? $data['pro_info_private_page'] :'1';
            
                $wppcp->template_loader->get_template_part('information-settings');            
                break;
            
            case 'wppcp_section_user_role_hierarchy':                
                $data = isset($private_content_settings['role_hierarchy']) ? $private_content_settings['role_hierarchy'] : array();
            
                $wppcp_settings_data['hierarchy'] = isset($data['hierarchy']) ? $data['hierarchy'] : array();         
                $wppcp_settings_data['tab'] = $tab;
            
                $wppcp->template_loader->get_template_part('user-role-hierarchy');            
                break;

            case 'wppcp_section_wppcp_permissions':                
                $data = isset($private_content_settings['restriction_permissions']) ? $private_content_settings['restriction_permissions'] : array();
      
                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['wppcp_feature_permission_roles'] = isset($data['wppcp_feature_permission_roles']) ? $data['wppcp_feature_permission_roles'] : array();
                
                $wppcp->template_loader->get_template_part('restriction-permission-settings');            
                break;

            case 'wppcp_section_private_page_bulk_content':                
                $wppcp->template_loader->get_template_part('private-page-bulk-content');            
                break;

            case 'wppcp_section_global_post':                
                $data = isset($private_content_settings['global_post_restriction']) ? $private_content_settings['global_post_restriction'] : array();

                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['restrict_all_posts_status'] = isset($data['restrict_all_posts_status']) ? $data['restrict_all_posts_status'] :'0';
                $wppcp_settings_data['all_post_visibility'] = isset($data['all_post_visibility']) ? $data['all_post_visibility'] :'all';
                $wppcp_settings_data['all_post_user_roles'] = isset($data['all_post_user_roles']) ? $data['all_post_user_roles'] : array();
                             
                $wppcp->template_loader->get_template_part('global-post-restriction-settings');            
                break;

            case 'wppcp_section_global_page':                
                $data = isset($private_content_settings['global_page_restriction']) ? $private_content_settings['global_page_restriction'] : array();

                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['restrict_all_pages_status'] = isset($data['restrict_all_pages_status']) ? $data['restrict_all_pages_status'] :'0';
                $wppcp_settings_data['all_page_visibility'] = isset($data['all_page_visibility']) ? $data['all_page_visibility'] :'all';
                $wppcp_settings_data['all_page_user_roles'] = isset($data['all_page_user_roles']) ? $data['all_page_user_roles'] : array();
                             
                $wppcp->template_loader->get_template_part('global-page-restriction-settings');            
                break;

            // Settings for Search
            case 'wppcp_section_search_general':                
                $data = isset($private_content_settings['search_general']) ? $private_content_settings['search_general'] : array();

                $wppcp_search_settings_data['tab'] = $tab;
                $wppcp_search_settings_data['blocked_post_search'] = isset($data['blocked_post_search']) ? (array) $data['blocked_post_search'] : array();
                $wppcp_search_settings_data['blocked_page_search'] = isset($data['blocked_page_search']) ? (array) $data['blocked_page_search'] : array();
                $wppcp_search_settings_data['post_types'] = $post_types;

                $wppcp_search_settings_data = apply_filters('wppcp_search_setting_data',$wppcp_search_settings_data, array('data' => $data, 'section' => 'wppcp_section_search_general' ) );


                $wppcp->template_loader->get_template_part('search-general-settings');            
                break;

            case 'wppcp_section_search_restrictions':                
                $data = isset($private_content_settings['search_restrictions']) ? $private_content_settings['search_restrictions'] : array();
     // echo "<pre>";print_r($data);exit;
                $wppcp_search_settings_data['tab'] = $tab;
                $wppcp_search_settings_data['everyone_search_types'] = isset($data['everyone_search_types']) ? (array) $data['everyone_search_types'] :array();
                $wppcp_search_settings_data['guests_search_types'] = isset($data['guests_search_types']) ? (array) $data['guests_search_types'] :array();
                $wppcp_search_settings_data['members_search_types'] = isset($data['members_search_types']) ? (array) $data['members_search_types'] :array();
                $wppcp_search_settings_data['data'] = $data; 
                $wppcp_search_settings_data['post_types'] = $post_types;

                $wppcp->template_loader->get_template_part('search-restrictions');            
                break;

            case 'wppcp_section_security_ip':                
                $data = isset($private_content_settings['security_ip']) ? $private_content_settings['security_ip'] : array();

                $wppcp_security_settings_data['tab'] = $tab;
                
                $wppcp_security_settings_data['restriction_status'] = isset($data['restriction_status']) ? $data['restriction_status'] : '';
                $wppcp_security_settings_data['allowed_urls'] = isset($data['allowed_urls']) ? $data['allowed_urls'] : '';
                $wppcp_security_settings_data['whitelisted'] = isset($data['whitelisted']) ? $data['whitelisted'] : '';
                $wppcp_security_settings_data['redirect_url'] = isset($data['redirect_url']) ? $data['redirect_url'] : site_url();

                $wppcp_security_settings_data = apply_filters('wppcp_security_settings_data',$wppcp_security_settings_data, array('data' => $data, 'section' => 'wppcp_section_security_ip' ) );


                $wppcp->template_loader->get_template_part('security-ip-settings');            
                break;



            case 'wppcp_section_admin_menu':                



                $wppcp->template_loader->get_template_part('admin-menu-settings');            
                break;

            // Settings for Global Password
            case 'wppcp_section_password_global':                
                $data = isset($private_content_settings['password_global']) ? $private_content_settings['password_global'] : array();

                $wppcp_password_settings_data['tab'] = $tab;
                $wppcp_password_settings_data['global_password_protect'] = isset($data['global_password_protect']) ? $data['global_password_protect'] : 'disabled';
                $wppcp_password_settings_data['global_protect_password'] = isset($data['global_protect_password']) ? $data['global_protect_password'] : '';
                $wppcp_password_settings_data['password_form_title'] = isset($data['password_form_title']) ? $data['password_form_title'] : __('Protected Content','wppcp');
                $wppcp_password_settings_data['password_form_message'] = isset($data['password_form_message']) ? $data['password_form_message'] : __('This content is password protected. Please enter the password to view the content.','wppcp');
                
                $wppcp_password_settings_data['allowed_urls'] = isset($data['allowed_urls']) ? $data['allowed_urls'] : '';
                
                $wppcp_password_settings_data = apply_filters('wppcp_password_setting_data',$wppcp_password_settings_data, array('data' => $data, 'section' => 'wppcp_section_password_global' ) );
                $wppcp->template_loader->get_template_part('password-global-settings');            
                break;

            

            case 'wppcp_section_upme_general':                
                $data = isset($private_content_settings['upme_general']) ? $private_content_settings['upme_general'] : array();

                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['private_content_tab_status'] = isset($data['private_content_tab_status']) ? $data['private_content_tab_status'] :'0';
                $wppcp_settings_data['redirect_to_upme_login'] = isset($data['redirect_to_upme_login']) ? $data['redirect_to_upme_login'] :'disabled';
                $wppcp->template_loader->get_template_part('upme-general');            
                break;

            case 'wppcp_section_upme_search':                
                $data = isset($private_content_settings['upme_search']) ? $private_content_settings['upme_search'] : array();

                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['upme_search_visibility'] = isset($data['upme_search_visibility']) ? $data['upme_search_visibility'] :'all';
                $wppcp_settings_data['upme_search_user_roles'] = isset($data['upme_search_user_roles']) ? $data['upme_search_user_roles'] :array();
                $wppcp->template_loader->get_template_part('upme-search');            
                break;

            case 'wppcp_section_upme_member_list':                
                $data = isset($private_content_settings['upme_member_list']) ? $private_content_settings['upme_member_list'] : array();

                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['upme_member_list_visibility'] = isset($data['upme_member_list_visibility']) ? $data['upme_member_list_visibility'] :'all';
                $wppcp_settings_data['upme_member_list_user_roles'] = isset($data['upme_member_list_user_roles']) ? $data['upme_member_list_user_roles'] :array();
                $wppcp->template_loader->get_template_part('upme-member-list');            
                break;

            case 'wppcp_section_upme_member_profile':                
                $data = isset($private_content_settings['upme_member_profile']) ? $private_content_settings['upme_member_profile'] : array();

                $wppcp_settings_data['tab'] = $tab;
                $wppcp_settings_data['upme_member_profile_visibility'] = isset($data['upme_member_profile_visibility']) ? $data['upme_member_profile_visibility'] :'all';
                $wppcp_settings_data['upme_member_profile_user_roles'] = isset($data['upme_member_profile_user_roles']) ? $data['upme_member_profile_user_roles'] :array();
                $wppcp->template_loader->get_template_part('upme-member-profile');            
                break;

            case 'wppcp_section_private_page_user':

                global $wppcp,$wppcp_private_page_params,$wpdb;
        
                $wppcp_private_page_params = array();
                
                $this->load_wppcp_select2_scripts_style();
                
                $private_page_user = 0;
                if($_POST && isset($_POST['wppcp_private_page_user_load']) && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) ){
                    $private_page_user = isset($_POST['wppcp_private_page_user']) ? (int) ( $_POST['wppcp_private_page_user'] ) : 0;
                    $user = get_user_by( 'id', $private_page_user );
                    $wppcp_private_page_params['display_name'] = $user->data->display_name;
                    $wppcp_private_page_params['user_id'] = $private_page_user;
                }
        
                if($_POST && isset($_POST['wppcp_private_page_content_submit']) && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) ){

                    if (isset( $_POST['wppcp_private_page_nonce_field'] ) && wp_verify_nonce( $_POST['wppcp_private_page_nonce_field'], 'wppcp_private_page_nonce' ) ) {

                        $user_id = isset($_POST['wppcp_user_id']) ? (int) $_POST['wppcp_user_id'] : 0; 
                        $private_content = isset($_POST['wppcp_private_page_content']) ? ( $_POST['wppcp_private_page_content']) : '';
                        $updated_date = date("Y-m-d H:i:s");
                        
                        $sql  = $wpdb->prepare( "SELECT content FROM " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE . " WHERE user_id = %d ", $user_id );
                        $result = $wpdb->get_results($sql);
                        if($result){
                            $sql  = $wpdb->prepare( "Update " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE ." set content=%s,updated_at=%s where user_id=%d ", $private_content,$updated_date, $user_id );
                        }else{
                            $sql  = $wpdb->prepare( "Insert into " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE ."(user_id,content,type,updated_at) values(%d,%s,%s,%s)", $user_id, $private_content, 'ADMIN', $updated_date );
                        }
                        
                        
                        if($wpdb->query($sql) === FALSE){
                            $wppcp_private_page_params['message'] = __('Private content update failed.','wppcp');
                            $wppcp_private_page_params['message_status'] = FALSE;
                        }else{
                            $wppcp_private_page_params['message'] = __('Private content updated successfully.','wppcp');
                            $wppcp_private_page_params['message_status'] = TRUE;
                        }        
                    }
                }
                
                $sql  = $wpdb->prepare( "SELECT content FROM " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE . " WHERE user_id = %d ", $private_page_user );
                $result = $wpdb->get_results($sql);
                if($result){
                    $wppcp_private_page_params['private_content'] = stripslashes($result[0]->content);
                }else{
                    $wppcp_private_page_params['private_content'] = stripslashes(get_option('wppcp_parivate_page_starter_content'));
                }

                // ob_start();
                $wppcp->template_loader->get_template_part('private-user-page');
                // $display = ob_get_clean();        
                // echo $display;

                break;

            default:
                do_action('wppcp_custom_plugin_options_tab_content',$tab,$private_content_settings, array() );
                break;
                
        }
        
        $display = ob_get_clean();
        return $display;
        
    }

    /* Save general settings */
    public function save_wppcp_section_general(){
        global $wppcp;

        if(isset($_POST['wppcp_general'])){
            foreach($_POST['wppcp_general'] as $k=>$v){
                switch ($k) {
                    case 'private_content_module_status':
                    case 'search_restrictions_module_status':
                    case 'dashboard_restrictions_widget_status':
                    case 'author_post_page_restrictions_status':
                        $v = sanitize_text_field($v);
                        break;
                    case 'post_page_redirect_url':
                        $v = esc_url_raw($v);
                        break;

                }
                $this->settings[$k] = $v;
            }            
        }
        
        $wppcp_options = get_option('wppcp_options');
        
        $wppcp_options['general'] = $this->settings;
        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) );  

        
    }

    public function save_wppcp_section_information(){
        global $wppcp;

        if(isset($_POST['wppcp_information'])){
            foreach($_POST['wppcp_information'] as $k=>$v){
                switch ($k) {
                    case 'pro_info_post_restrictions':
                    case 'pro_info_post_attachments':
                    case 'pro_info_search_restrictions':
                    case 'pro_info_private_page':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }   

            if(!isset($_POST['wppcp_information']['pro_info_post_restrictions'])){
                $this->settings['pro_info_post_restrictions'] = 0;
            }
            if(!isset($_POST['wppcp_information']['pro_info_post_attachments'])){
                $this->settings['pro_info_post_attachments'] = 0;
            }
            if(!isset($_POST['wppcp_information']['pro_info_search_restrictions'])){
                $this->settings['pro_info_search_restrictions'] = 0;
            }
            if(!isset($_POST['wppcp_information']['pro_info_private_page'])){
                $this->settings['pro_info_private_page'] = 0;
            }         
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['information'] = $this->settings;
        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) );  

        
    }

    public function save_wppcp_section_global_post(){
        global $wppcp;

        if(isset($_POST['wppcp_global_post_restriction'])){
            foreach($_POST['wppcp_global_post_restriction'] as $k=>$v){
                switch ($k) {
                    case 'restrict_all_posts_status':
                    case 'all_post_visibility':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['global_post_restriction'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function save_wppcp_section_global_page(){
        global $wppcp;

        if(isset($_POST['wppcp_global_page_restriction'])){
            foreach($_POST['wppcp_global_page_restriction'] as $k=>$v){
                switch ($k) {
                    case 'restrict_all_pages_status':
                    case 'all_page_visibility':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['global_page_restriction'] = $this->settings;
        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }
    
    public function private_user_page(){

        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_private_page_user', __('Private Page','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-private-user-page' );
        add_settings_section( 'wppcp_section_private_page_bulk_content', __('Bulk Content','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-private-user-page' );
        add_settings_section( 'wppcp_section_private_page_default_content', __('Default Content','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-private-user-page' );
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_private_page_user';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('private_page',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }
    
    /* Display private user page add content form */
    // public function private_user_page(){
    //     global $wppcp,$wppcp_private_page_params,$wpdb;
        
    //     $wppcp_private_page_params = array();
        
    //     $this->load_wppcp_select2_scripts_style();
        
    //     $private_page_user = 0;
    //     if($_POST && isset($_POST['wppcp_private_page_user_load']) && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) ){
    //         $private_page_user = isset($_POST['wppcp_private_page_user']) ? (int) ( $_POST['wppcp_private_page_user'] ) : 0;
    //         $user = get_user_by( 'id', $private_page_user );
    //         $wppcp_private_page_params['display_name'] = $user->data->display_name;
    //         $wppcp_private_page_params['user_id'] = $private_page_user;
    //     }
        

        
    //     if($_POST && isset($_POST['wppcp_private_page_content_submit']) && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) ){

    //         if (isset( $_POST['wppcp_private_page_nonce_field'] ) && wp_verify_nonce( $_POST['wppcp_private_page_nonce_field'], 'wppcp_private_page_nonce' ) ) {

    //             $user_id = isset($_POST['wppcp_user_id']) ? (int) $_POST['wppcp_user_id'] : 0; 
    //             $private_content = isset($_POST['wppcp_private_page_content']) ? ( $_POST['wppcp_private_page_content']) : '';
    //             $updated_date = date("Y-m-d H:i:s");
                
    //             $sql  = $wpdb->prepare( "SELECT content FROM " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE . " WHERE user_id = %d ", $user_id );
    //             $result = $wpdb->get_results($sql);
    //             if($result){
    //                 $sql  = $wpdb->prepare( "Update " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE ." set content=%s,updated_at=%s where user_id=%d ", $private_content,$updated_date, $user_id );
    //             }else{
    //                 $sql  = $wpdb->prepare( "Insert into " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE ."(user_id,content,type,updated_at) values(%d,%s,%s,%s)", $user_id, $private_content, 'ADMIN', $updated_date );
    //             }
                
                
    //             if($wpdb->query($sql) === FALSE){
    //                 $wppcp_private_page_params['message'] = __('Private content update failed.','wppcp');
    //                 $wppcp_private_page_params['message_status'] = FALSE;
    //             }else{
    //                 $wppcp_private_page_params['message'] = __('Private content updated successfully.','wppcp');
    //                 $wppcp_private_page_params['message_status'] = TRUE;
    //             }        
    //         }
    //     }
        
    //     $sql  = $wpdb->prepare( "SELECT content FROM " . $wpdb->prefix . WPPCP_PRIVATE_CONTENT_TABLE . " WHERE user_id = %d ", $private_page_user );
    //     $result = $wpdb->get_results($sql);
    //     if($result){
    //         $wppcp_private_page_params['private_content'] = stripslashes($result[0]->content);
    //     }else{
    //         $wppcp_private_page_params['private_content'] = '';
    //     }
        
        
        
        
    //     ob_start();
    //     $wppcp->template_loader->get_template_part('private-user-page');
    //     $display = ob_get_clean();        
    //     echo $display;
    // }
    
    /* Load Select 2 library for settings section */
    public function load_wppcp_select2_scripts_style(){          

        wp_register_script('wppcp_select2_js', WPPCP_PLUGIN_URL . 'js/select2/wppcp-select2.min.js');
        wp_enqueue_script('wppcp_select2_js');
        
        wp_register_style('wppcp_select2_css', WPPCP_PLUGIN_URL . 'js/select2/wppcp-select2.min.css');
        wp_enqueue_style('wppcp_select2_css');

    }
    
    /* Get the users for the private page content form */
    public function wppcp_load_private_page_users(){
        global $wpdb;
        

        if( ( current_user_can('manage_options') || current_user_can('wppcp_manage_options')) 
            && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){
            $search_text  = isset($_POST['q']) ? sanitize_text_field ( $_POST['q'] ) : '';
            
            $args = array('number' => 20);
            if($search_text != ''){
                $args['search'] = "*".$search_text."*";
            }
            
            $user_results = array();
            $user_json_results = array();
            
            $user_query = new WP_User_Query( $args );
            $user_results = $user_query->get_results();

            foreach($user_results as $user){
                if($user->ID != $this->current_user){
                    array_push($user_json_results , array('id' => $user->ID, 'name' => $user->data->display_name) ) ;
                }
                           
            }
        }else{
            $user_json_results = array();
        }
        
        echo json_encode(array('items' => $user_json_results ));exit;
    }  
    
    
    /* Save user role hierarchy of the site */
    public function wppcp_save_user_role_hierarchy(){ //<todononce>
        global $wppcp,$user_role_hierarchy_result;
        if(is_user_logged_in() && ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false )){
            $private_content_settings = get_option('wppcp_options');

            $user_role_hierarchy = isset($_POST['user_role_hierarchy']) ? $_POST['user_role_hierarchy'] : array();
            $user_role_hierarchy_filtered = array();
            foreach ($user_role_hierarchy as $key => $value) {
                $user_role_hierarchy_filtered[sanitize_text_field($key)] = sanitize_text_field($value);
            }

            $private_content_settings['role_hierarchy']['hierarchy'] = $user_role_hierarchy_filtered;
            
            update_option('wppcp_options',$private_content_settings);
            
            $result = array('status' => 'success', 'msg' => __('Role Hierarchy saved succefully.','wppcp'));
            
        }else{
            $result = array('status' => 'error', 'msg' => __('Role Hierarchy save failed.','wppcp'));
        }
        
        echo json_encode($result);exit;
    }

    public function save_wppcp_section_wppcp_permissions(){
        global $wppcp,$wp_roles;

        if(isset($_POST['wppcp_feature_restrictions'])){


            foreach($_POST['wppcp_feature_restrictions'] as $k=>$v){
                switch ($k) {
                    case 'wppcp_feature_permission_roles':
                        foreach ($v as $key => $value) {
                            $v[$key] = sanitize_text_field($value);
                        }
                        
                        break;


                }
                $this->settings[$k] = $v;
            }      
               
            $res_user_roles = isset($_POST['wppcp_feature_restrictions']['wppcp_feature_permission_roles']) ?
                (array) $_POST['wppcp_feature_restrictions']['wppcp_feature_permission_roles'] : array();

            $user_roles = $wppcp->roles_capability->wppcp_user_roles();

            foreach($user_roles as $role_key => $role){
                $role_key = sanitize_text_field($role_key);
                $wp_roles->remove_cap($role_key, 'wppcp_manage_options');
            }

            foreach ($res_user_roles as $key ) {
                $key = sanitize_text_field($key);
                $wp_roles->add_cap( $key, 'wppcp_manage_options' ); 
            }

            $wp_roles->add_cap( 'administrator', 'wppcp_manage_options' ); 
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['restriction_permissions'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }
    
    /* Display settings saved message */  
    public function admin_notices(){
        ?>
        <div class="updated">
          <p><?php esc_html_e( 'Settings saved successfully.', 'wppcp' ); ?></p>
       </div>
        <?php
    }

    public function admin_notices_failed(){
        ?>
        <div class="error">
          <p><?php esc_html_e( 'Settings saving failed.', 'wppcp' ); ?></p>
       </div>
        <?php
    }

    /* Help and information about the plugin */
    public function help(){
        global $wppcp;
        ob_start();
        $wppcp->template_loader->get_template_part('plugin-help');    
        $display = ob_get_clean();  
    
        echo $display;
    }

    public function search_settings(){

        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_search_general', __('Search Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-search-general' );
        
        add_settings_section( 'wppcp_section_search_restrictions', __('Search Restrictions','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-search-general' );
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_search_general';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('search',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }

    public function security_settings(){

        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_security_ip', __('IP Restrictions','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-security-ip' );
        
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title ( $_GET['tab'] ) : 'wppcp_section_security_ip';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('security',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }

    public function save_wppcp_section_security_ip(){
        global $wppcp;

        if(isset($_POST['wppcp_security_ip'])){
            foreach($_POST['wppcp_security_ip'] as $k=>$v){
                switch ($k) {
                    case 'restriction_status':
                        $v = sanitize_text_field($v);
                        break;
                    case 'allowed_urls':
                    case 'whitelisted':
                        $v = sanitize_textarea_field($v);
                        break;
                    case 'redirect_url':
                        $v = esc_url_raw($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['security_ip'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function save_wppcp_section_search_general(){
        global $wppcp;

        if(isset($_POST['wppcp_search_general'])){
            foreach($_POST['wppcp_search_general'] as $k=>$v){
                
                switch ($k) {
                    case 'blocked_post_search':
                    case 'blocked_page_search':
                        foreach ($v as $key => $post_id) {
                           $v[$key] = (int) ($post_id);
                        }
                        
                        break;                   

                }

                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['search_general'] = $this->settings;
        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function save_wppcp_section_search_restrictions(){
        global $wppcp;

        if(isset($_POST['wppcp_search_restrictions'])){
            foreach($_POST['wppcp_search_restrictions'] as $k=>$v){
                switch ($k) {
                    case 'everyone_search_types':
                    case 'guests_search_types':
                    case 'members_search_types':
                        foreach ($v as $key => $post_types) {
                           $v[$key] = sanitize_text_field($post_types);
                        }
                        
                        break;                   

                }
                $this->settings[$k] = $v;
            } 

            $wppcp_options = get_option('wppcp_options');
            $wppcp_options['search_restrictions'] = $this->settings;
            update_option('wppcp_options',$wppcp_options);
            add_action( 'admin_notices', array( $this, 'admin_notices' ) );           
        }
        
         
    }

    public function password_settings(){

        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_password_global', __('Global Password Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-password-global' );
        
        //add_settings_section( 'wppcp_section_search_restrictions', __('Search Restrictions','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-search-general' );
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_password_global';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('password',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }

    public function save_wppcp_section_password_global(){
        global $wppcp;

        if(isset($_POST['wppcp_password_global'])){
            foreach($_POST['wppcp_password_global'] as $k=>$v){
                switch ($k) {
                    case 'global_password_protect':
                    case 'global_protect_password':
                    case 'password_form_title':

                        $v = sanitize_text_field($v);
                        break;

                    case 'password_form_message':
                        $v = wp_kses_post($v);
                        break;

                    case 'allowed_urls':
                        $v = sanitize_textarea_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['password_global'] = $this->settings;
        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function admin_permission_settings(){

        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_admin_menu', __('Admin Menu Permissions','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-security-ip' );
        
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_admin_menu';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('admin_permissions',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }

    /* Get the users for restrictions on various locations */
    public function wppcp_load_restriction_users(){
        global $wpdb;
        

        if( ( current_user_can('manage_options') || current_user_can('wppcp_manage_options') ) && check_ajax_referer( 'wppcp-admin', 'verify_nonce',false ) ){

            $search_text  = isset($_POST['q']) ? sanitize_text_field( $_POST['q'] ) : '';
            
            $args = array('number' => 20);
            if($search_text != ''){
                $args['search'] = "*".$search_text."*";
            }
            
            $user_results = array();
            $user_json_results = array();
            
            $user_query = new WP_User_Query( $args );
            $user_results = $user_query->get_results();

            foreach($user_results as $user){
                if($user->ID != $this->current_user){
                    array_push($user_json_results , array('id' => $user->ID, 'name' => $user->data->display_name) ) ;
                }
                           
            }
        }
        
        echo json_encode(array('items' => $user_json_results ));exit;
    } 


    public function pro(){
        global $wppcp;
        ob_start();
        $wppcp->template_loader->get_template_part('plugin-pro');    
        $display = ob_get_clean();  
    
        echo $display;
    }

    public function pro_trial(){
        global $wppcp;
        ob_start();
        $wppcp->template_loader->get_template_part('pro-trial');    
        $display = ob_get_clean();  
    
        echo $display;
    }

    public function mailchimp_settings(){
        global $wppcp,$wppcp_settings_data;
        
       
        ob_start();
        $wppcp->template_loader->get_template_part( 'mailchimp-general-settings');
        $display = ob_get_clean();
        echo $display;
    }

    
    public function upme_settings(){

        global $wppcp,$wppcp_settings_data;
        
        add_settings_section( 'wppcp_section_upme_general', __('UPME General Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-upme-general' );
        add_settings_section( 'wppcp_section_upme_search', __('UPME Search Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-upme-general' );
        add_settings_section( 'wppcp_section_upme_member_list', __('UPME Member List Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-upme-general' );
        add_settings_section( 'wppcp_section_upme_member_profile', __('UPME Member Profile Settings','wppcp'), array( &$this, 'wppcp_section_general_desc' ), 'wppcp-upme-general' );
        
        
        $tab = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : 'wppcp_section_upme_general';
        $wppcp_settings_data['tab'] = $tab;
        
        $tabs = $this->plugin_options_tabs('upme_general',$tab);
   
        $wppcp_settings_data['tabs'] = $tabs;
        
        $tab_content = $this->plugin_options_tab_content($tab);
        $wppcp_settings_data['tab_content'] = $tab_content;
        
        ob_start();
        $wppcp->template_loader->get_template_part( 'menu-page-container');
        $display = ob_get_clean();
        echo $display;

    }

    public function save_wppcp_section_upme_general(){
        global $wppcp;

        if(isset($_POST['wppcp_upme_general'])){
            foreach($_POST['wppcp_upme_general'] as $k=>$v){
                switch ($k) {
                    case 'private_content_tab_status':
                    case 'redirect_to_upme_login':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['upme_general'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function save_wppcp_section_upme_search(){
        global $wppcp;

        if(isset($_POST['wppcp_upme_search'])){
            foreach($_POST['wppcp_upme_search'] as $k=>$v){
                switch ($k) {
                    case 'upme_search_visibility':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['upme_search'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function save_wppcp_section_upme_member_list(){
        global $wppcp;

        if(isset($_POST['wppcp_upme_member_list'])){
            foreach($_POST['wppcp_upme_member_list'] as $k=>$v){
                switch ($k) {
                    case 'upme_member_list_visibility':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['upme_member_list'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function save_wppcp_section_upme_member_profile(){
        global $wppcp;

        if(isset($_POST['wppcp_upme_member_profile'])){
            foreach($_POST['wppcp_upme_member_profile'] as $k=>$v){
                switch ($k) {
                    case 'upme_member_profile_visibility':
                        $v = sanitize_text_field($v);
                        break;

                }
                $this->settings[$k] = $v;
            }      
               
        }
        
        $wppcp_options = get_option('wppcp_options');
        $wppcp_options['upme_member_profile'] = $this->settings;

        update_option('wppcp_options',$wppcp_options);
        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
    }

    public function wppcp_conditional_scripts($hook_suffix){
        if($hook_suffix == 'nav-menus.php'){
            $this->load_wppcp_select2_scripts_style();
        }
    }

    public function wppcp_deactivate_popup() {
        global $pagenow,$wppcp;

        $wppcp_plugin_data = (array) get_option('wppcp_plugin_data');
        $wppcp_init_version = isset($wppcp_plugin_data['init_version']) ? $wppcp_plugin_data['init_version'] : '';
        $wppcp_init_date = isset($wppcp_plugin_data['init_date']) ? $wppcp_plugin_data['init_date'] : '';

        if(trim($pagenow) == 'plugins.php'){


            $results = $wppcp->admin_stats->generate_stats();
            $individual_protection = array();
            if($results['single_data']['post_count'] > 0){
                $individual_protection[] = "<span>" . $results['single_data']['post_count'] . __(' Posts ','wppcp')."</span>" ;
            }
            if($results['single_data']['page_count'] > 0){
                $individual_protection[] = "<span>" .$results['single_data']['page_count'] . __(' Pages ','wppcp')."</span>" ;
            }
            if($results['single_data']['cpt_count'] > 0){
                $individual_protection[] = "<span>" .$results['single_data']['cpt_count'] . __(' Custom Post Types ','wppcp')."</span>" ;
            }

            $individual_protection = implode("-", $individual_protection);
            if($individual_protection != ''){
                $individual_protection .= __(' are protected','wppcp');
            }


            $global_protection = array();
            if($results['global_data']['restrict_all_posts_status'] == '1'){
                $global_protection[] = "<span>" .$results['global_data']['post_count'] . __(' Posts ','wppcp')."</span>" ;
            }
            if($results['global_data']['restrict_all_pages_status'] == '1'){
                $global_protection[] = "<span>" .$results['global_data']['page_count'] . __(' Pages ','wppcp')."</span>" ;
            }
            
            $global_protection = implode("-", $global_protection);
            if($global_protection != ''){
                $global_protection .= __(' are protected','wppcp');
            }

            $password_protection = '';      
            if(isset($results['password_data']['status'])){
                $password_protection = "<span>" .$results['password_data']['post_count'] . __(' Posts ','wppcp')."</span>"  . " - " .
                                        "<span>" .$results['password_data']['page_count'] . __(' Pages ','wppcp')."</span>"  ." - " .
                                        "<span>" .$results['password_data']['cpt_count'] . __(' Custom Post Types ','wppcp')."</span>"  ;
                $password_protection .= __(' are protected','wppcp');
            
            }

            $menu_protection = '';
            if($results['menu_data']['count'] > 0){
                $menu_protection = "<span>" .$results['menu_data']['count'] . __(' Menu Items ','wppcp')."</span>"  ;
                $menu_protection .= __(' are protected','wppcp');
            
            }

            $widget_protection = '';
            if($results['widgets_data']['count'] > 0){
                $widget_protection = "<span>" .$results['widgets_data']['count'] . __(' Widgets ','wppcp')."</span>"  ;
                $widget_protection .= __(' are protected','wppcp');
            
            }

            $shortcode_protection = '';
            if($results['shortcode_data']['count'] > 0){
                $shortcode_protection = "<span>" .$results['shortcode_data']['count'] . __(' Post/Page Content Blocks ','wppcp') ."</span>" ;
                $shortcode_protection .= __(' are protected','wppcp');
            
            }

            $private_page_protection = '';
            if($results['private_page_data']['count'] > 0){
                $private_page_protection = "<span>" .$results['private_page_data']['count'].__(' Users ','wppcp') . "</span>" . __('have private page with protected content. ','wppcp') ."</span>" ;
        
            }

            $attachment_protection = array();
            if($results['attachment_data']['post_count'] > 0){
                $attachment_protection[] = "<span>" .$results['attachment_data']['post_count'] . __(' Post ','wppcp')."</span>" ;
            }
            if($results['attachment_data']['page_count'] > 0){
                $attachment_protection[] = "<span>" .$results['attachment_data']['page_count'] . __(' Page ','wppcp')."</span>" ;
            }
            if($results['attachment_data']['cpt_count'] > 0){
                $attachment_protection[] = "<span>" .$results['attachment_data']['cpt_count'] . __(' Custom Post Type ','wppcp')."</span>" ;
            }

            $attachment_protection = implode("-", $attachment_protection);
            if($attachment_protection != ''){
                $attachment_protection .= __(' attachments are protected','wppcp');
            }



            $search_protection = array();
            if($results['search_data']['blocked_posts'] > 0){
                $search_protection[] = "<span>" .$results['search_data']['blocked_posts'] . __(' Posts ','wppcp')."</span>" ;
            }
            if($results['search_data']['blocked_pages'] > 0){
                $search_protection[] = "<span>" .$results['search_data']['blocked_pages'] . __(' Pages ','wppcp')."</span>" ;
            }
            $search_protection = implode("-", $search_protection);
            if($search_protection != ''){
                $search_protection .= __(' are protected from search','wppcp');
            }


            $table = "<table id='wppcp-admin-stats' class='wppcp-admin-stats-deactivate'  border='1'>";

            $protection_count = 0;
            if($individual_protection != ''){
                $table .= "<tr><th>". __('Individual Post/Page Protection','wppcp'). "</th>
                                <td>".$individual_protection."</td>
                            </tr>";
                $protection_count++;
            }

            if($global_protection != ''){ 
                $table .= "<tr><th>". __('Global Post/Page Protection','wppcp'). "</th>
                                        <td>".$global_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($password_protection != ''){ 
                $table .= "<tr><th>". __('Password Protection','wppcp'). "</th>
                                        <td>".$password_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($menu_protection != ''){ 
                $table .= "<tr><th>". __('Menu Protection','wppcp'). "</th>
                                        <td>".$menu_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($widget_protection != ''){ 
                $table .= "<tr><th>". __('Widget Protection','wppcp'). "</th>
                                        <td>".$widget_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($shortcode_protection != ''){ 
                $table .= "<tr><th>". __('Shortcode Protection','wppcp'). "</th>
                                        <td>".$shortcode_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($attachment_protection != ''){
                $table .= "<tr><th>". __('Attachment Protection','wppcp'). "</th>
                                        <td>".$attachment_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($private_page_protection != ''){
                $table .= "<tr><th>". __('Private Page','wppcp'). "</th>
                                        <td>".$private_page_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            if($search_protection != ''){ 
                $table .= "<tr><th>". __('Search Protection','wppcp'). "</th>
                                        <td>".$search_protection. "</td>
                                    </tr>";
                $protection_count++;
            }

            $table .= "</table>";
        
            $display = '  <div id="wppcp-deactivate-popup" class="wppcp-modal-box">
                      <header> <a href="#" class="wppcp-js-modal-close close">×</a>
                        <h3>'.__('Deactivate WP Private Content Plus','wppcp').'</h3>
                      </header>';

            if($protection_count != 0){
                $display .=  '<div id="wppcp-modal-body-step1">
                                <div class="wppcp-modal-body">
                                    <div class="wppcp-deactivate-general-message">'.__('Are you sure that you would like to deactivate the plugin?','wppcp').'</div><br/>
                                    <div style="font-weight:400;font-size:14px;" class="wppcp-deactivate-general-message">'.__('Just a reminder - Currently WP Private Content Plus is protecting your important site content. Following content types are 
                                        protected on your site and these content will be visible to public once you deactivate the plugin.','wppcp').'</div>
                                    
                                    '.$table.'

                                  </div>
                                  <footer> 
                                    <input id="wppcp-deactivate-step1-submit" class="wppcp-modal-btn wppcp-modal-btn-small" type="button" value="'.__('Continue','wppcp').'" />
                                  </footer>
                              </div>
                              <div id="wppcp-modal-body-step2" style="display:none" >';
            }else{
                $display .=  '<div id="wppcp-modal-body-step2" >';
            }

                $display .=  '
                      <div  class="wppcp-modal-body" >
                        <div class="wppcp-deactivate-general-message">'.__('Please help us understand why you are removing our plugin and what we can do to improve our plugin.','wppcp').'</div>
                        
                        <ul class="wppcp-deactivate-reasons">
                            <li><input type="radio" checked value="1" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('I no longer need the plugin.','wppcp').'</li>
                            <li><input type="radio" value="2" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('I found a better plugin.','wppcp').'
                            <div class="wppcp_deactivate_input"><input type="text" id="wppcp_deactivate_plugin_name" name="wppcp_deactivate_plugin_name" placeholder="'.__('Plugin Name','wppcp').'" /></div></li>
                            <li><input type="radio" value="3" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('I only needed the plugin for short period.','wppcp').'</li>
                            <li><input type="radio" value="4" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('The plugin broke my site or stopped working','wppcp').'
                            <div class="wppcp_deactivate_input"><input type="text" id="wppcp_deactivate_plugin_error" name="wppcp_deactivate_plugin_error" placeholder="'.__('What exactly happened?','wppcp').'" /></div></li>
                            <li><input type="radio" value="5" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('The feature I need is in PRO version and its expensive.','wppcp').'
                            <div class="wppcp_deactivate_input"><input type="text" id="wppcp_deactivate_pro_price" name="wppcp_deactivate_pro_price" placeholder="'.__('What\'s your budget?','wppcp').'" /></div></li>
                            <li><input type="radio" value="6" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('The feature I need is not available.','wppcp').'
                            <div class="wppcp_deactivate_input"><input type="text" id="wppcp_deactivate_plugin_feature" name="wppcp_deactivate_plugin_feature" placeholder="'.__('Let us know more about this feature','wppcp').'" /></div></li>
                            <li><input type="radio" value="7" name="wppcp_deactivate_reason" class="wppcp_deactivate_reason" />'.__('Other.','wppcp').'
                            <div class="wppcp_deactivate_input"><input type="text" id="wppcp_deactivate_other" name="wppcp_deactivate_other" placeholder="'.__('Please explain the reason','wppcp').'" /></div></li>
                        </ul>
                        <div class="wppcp-modal-permission-info">
                            <div class="wppcp-modal-permission-message">
                                '.__('<strong>Submit & Deactivate</strong> option will send the following details to developers of the plugin. Your feedback will be 
                                    used to improve the future versions of the plugin.','wppcp').'<br/>
                                <ul>
                                    <li>'.__('Reason for deactivation','wppcp').'</li>
                                    <li>'.__('Plugin Version','wppcp').'</li>
                                    <li>'.__('Activated Date','wppcp').'</li>
                                    <li>'.__('Admin Email (If you tick the following checkbox)','wppcp').'</li>
                                </ul>
                                <div class="wppcp-clear"></div>
                            </div><br/>
                            <input type="checkbox" id="wppcp_deactivate_admin_email" value="1" />
                            '.__('<b>I would like to get a response from developers regarding my feedback.</b>','wppcp').'
                        </div> 
                      </div>
                      <footer> 
                        <input id="wppcp_init_version" type="hidden" value="'.$wppcp_init_version.'" />
                        <input id="wppcp_init_date" type="hidden" value="'.$wppcp_init_date.'" />
                        <input id="wppcp_init_admin_email" type="hidden" value="'.get_option('admin_email').'" />
                        <input id="wppcp-deactivate-reasons-submit" class="wppcp-modal-btn wppcp-modal-btn-small" type="button" value="'.__('Submit & Deactivate','wppcp').'" />
                        <input id="wppcp-deactivate-submit" class="wppcp-modal-btn wppcp-modal-btn-small" type="button" value="'.__('Skip & Deactivate','wppcp').'" />
                        <a href="#" class="wppcp-modal-btn wppcp-modal-btn-small wppcp-js-modal-close">'.__('Close','wppcp').'</a> </footer>
                      </div>
                    </div>';
            echo $display;
        }

        
    }

    public function pro_addons(){
        global $wppcp;
        ob_start();
        $wppcp->template_loader->get_template_part('plugin-pro-addons');    
        $display = ob_get_clean();  
    
        echo $display;
    }

}