| Current Path : /home/bechata/mp/wp-content/uploads/2022/ejn73c/ |
| Current File : /home/bechata/mp/wp-content/uploads/2022/ejn73c/classes.tar |
db-restore.php 0000666 00000017465 15176427122 0007353 0 ustar 00 <?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.php 0000666 00000005647 15176427122 0007651 0 ustar 00 <?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.php 0000666 00000001146 15176427122 0010055 0 ustar 00 <?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.php 0000666 00000026520 15176427122 0007125 0 ustar 00 <?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.php 0000666 00000015427 15176500132 0014217 0 ustar 00 <?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.php 0000666 00000007264 15176500132 0012662 0 ustar 00 <?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.php 0000666 00000037322 15176500132 0011041 0 ustar 00 <?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.php 0000666 00000014344 15176500132 0015022 0 ustar 00 <?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.php 0000666 00000006544 15176500132 0010771 0 ustar 00 <?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.php 0000666 00000123042 15176500132 0012637 0 ustar 00 <?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.php 0000666 00000010014 15176500132 0010657 0 ustar 00 <?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.php 0000666 00000017644 15176500132 0010473 0 ustar 00 <?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.php 0000666 00000004324 15176500132 0012575 0 ustar 00 <?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;
}
}
?>