Origin commit

This commit is contained in:
Hoang Huu
2019-09-10 11:27:33 +07:00
commit 499e068e4f
844 changed files with 188705 additions and 0 deletions

BIN
inc/.DS_Store vendored Executable file

Binary file not shown.

156
inc/admin/agency/class-agency.php Executable file
View File

@@ -0,0 +1,156 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Admin_Agency {
/**
*
*/
public function __construct(){
add_action( 'cmb2_admin_init', array( $this, 'metaboxes' ) );
add_action( 'save_post', array( $this , 'on_save_post'), 13, 2 );
add_action( 'user_register' , array( $this, 'on_update_user' ), 10, 1 );
add_action( 'profile_update' , array( $this, 'on_update_user' ), 10, 1 );
}
/**
* Update relationship post and user data, auto update meta information from post to user
*/
public function on_save_post( $post_id ){
$post_type = get_post_type($post_id);
if( $post_type == 'opalestate_agency' ){
if( isset($_POST[OPALESTATE_AGENCY_PREFIX.'user_id']) && $_POST[OPALESTATE_AGENCY_PREFIX.'user_id'] ){
$user_id = absint( $_POST[OPALESTATE_AGENCY_PREFIX.'user_id'] );
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
OpalEstate_Agency::update_user_data( $user_id );
// OpalEstate_Agency::update_properties_related( $user_id );
}
}
}
/**
* Auto update meta information to post from user data updated or created
*/
public function on_update_user() {
if( isset($_POST['user_id']) && (int) $_POST['user_id'] && isset($_POST['role']) ) {
if( $_POST['role'] == 'opalestate_agency' ){
$user_id = absint( $_POST['user_id'] );
$related_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
$post = get_post( $related_id );
if( isset($post->ID) && $post->ID ){
OpalEstate_Agency::update_data_from_user( $related_id );
}
}
}
}
/**
*
*/
public function metaboxes_fields( $prefix = '' ){
if ( ! $prefix ) {
$prefix = OPALESTATE_AGENCY_PREFIX;
}
$fields = array(
array(
'name' => esc_html__('Gallery' ,'opalestate-pro'),
'desc' => esc_html__('Select one, to add new you create in location of estate panel','opalestate-pro'),
'id' => $prefix."gallery",
'type' => 'file_list',
) ,
array(
'name' => esc_html__( 'slogan', 'opalestate-pro' ),
'id' => "{$prefix}slogan",
'type' => 'text'
)
);
return apply_filters( 'opalestate_postype_agency_metaboxes_fields' , $fields );
}
/**
*
*/
public function metaboxes( ){
global $pagenow;
if( ($pagenow == 'post.php' || $pagenow == 'post-new.php') ) {
$prefix = OPALESTATE_AGENCY_PREFIX;
$metabox = new Opalestate_Agency_MetaBox();
$fields = $this->metaboxes_fields();
$fields = array_merge_recursive( $fields ,
$metabox->get_office_fields( $prefix ),
$metabox->get_address_fields( $prefix )
);
$box_options = array(
'id' => $prefix . 'edit',
'title' => esc_html__( 'Metabox', 'opalestate-pro' ),
'object_types' => array( 'opalestate_agency' ),
'show_names' => true,
);
// Setup meta box
$cmb = new_cmb2_box( $box_options );
// Setting tabs
$tabs_setting = array(
'config' => $box_options,
'layout' => 'vertical', // Default : horizontal
'tabs' => array()
);
$tabs_setting['tabs'][] = array(
'id' => 'p-general',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'General', 'opalestate-pro' ),
'fields' => $fields
);
$tabs_setting['tabs'][] = array(
'id' => 'p-socials',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'Socials', 'opalestate-pro' ),
'fields' => $metabox->get_social_fields( $prefix )
);
$tabs_setting['tabs'][] = array(
'id' => 'p-target',
'icon' => 'dashicons-admin-tools',
'title' => esc_html__( 'Team', 'opalestate-pro' ),
'fields' => $metabox->metaboxes_target()
);
// Set tabs
$cmb->add_field( array(
'id' => '__tabs',
'type' => 'tabs',
'tabs' => $tabs_setting
) );
}
}
}
new Opalestate_Admin_Agency();

123
inc/admin/agent/class-agent.php Executable file
View File

@@ -0,0 +1,123 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Admin_Agent {
/**
* Auto update meta information to post from user data updated or created
*/
public function __construct() {
add_action( 'cmb2_admin_init', [ $this, 'metaboxes' ] );
add_action( 'save_post', [ $this, 'save_post' ], 10, 3 );
add_action( 'user_register', [ $this, 'on_update_user' ], 10, 1 );
add_action( 'profile_update', [ $this, 'on_update_user' ], 10, 1 );
}
/**
* Auto update meta information to post from user data updated or created
*/
public function on_update_user() {
if ( isset( $_POST['user_id'] ) && (int) $_POST['user_id'] && isset( $_POST['role'] ) ) {
if ( $_POST['role'] == 'opalestate_agent' ) {
$user_id = absint( $_POST['user_id'] );
$related_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
$post = get_post( $related_id );
if ( isset( $post->ID ) && $post->ID ) {
OpalEstate_Agent::update_data_from_user( $related_id );
}
}
}
}
/**
*
*/
public function metaboxes() {
global $pagenow;
if ( ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) {
$prefix = OPALESTATE_AGENT_PREFIX;
$metabox = new Opalestate_Agent_MetaBox();
// echo '<pre>' . print_r( $metabox->get_social_fields( $prefix ) ,1 );die;
$box_options = [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Metabox', 'opalestate-pro' ),
'object_types' => [ 'opalestate_agent' ],
'show_names' => true,
];
// Setup meta box
$cmb = new_cmb2_box( $box_options );
// Setting tabs
$tabs_setting = [
'config' => $box_options,
'layout' => 'vertical', // Default : horizontal
'tabs' => [],
];
$tabs_setting['tabs'][] = [
'id' => 'p-general',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'General', 'opalestate-pro' ),
'fields' => $metabox->metaboxes_admin_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-socials',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'Socials', 'opalestate-pro' ),
'fields' => $metabox->get_social_fields( $prefix ),
];
$tabs_setting['tabs'][] = [
'id' => 'p-prices-target',
'icon' => 'dashicons-admin-tools',
'title' => esc_html__( 'Target Search', 'opalestate-pro' ),
'fields' => $metabox->metaboxes_target(),
];
// Set tabs
$cmb->add_field( [
'id' => '__tabs',
'type' => 'tabs',
'tabs' => $tabs_setting,
] );
}
}
public function save_post( $post_id, $post, $update ) {
///
$post_type = get_post_type( $post_id );
if ( $post_type == 'opalestate_agent' ) {
if ( isset( $_POST[ OPALESTATE_AGENT_PREFIX . 'user_id' ] ) && absint( $_POST[ OPALESTATE_AGENT_PREFIX . 'user_id' ] ) ) {
$user_id = absint( $_POST[ OPALESTATE_AGENT_PREFIX . 'user_id' ] );
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
OpalEstate_Agent::update_user_data( $user_id );
}
}
}
}
new Opalestate_Admin_Agent();

101
inc/admin/class-admin.php Executable file
View File

@@ -0,0 +1,101 @@
<?php
/**
* Opalestate_Admin
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @Class Wpopal_Core_Setup
*
* Entry point class to setup load all files and init working on frontend and process something logic in admin
*/
class Opalestate_Admin {
/**
* Opalestate_Admin constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'setup' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
/**
* enqueue editor.js for edit mode
*/
public function enqueue_scripts() {
wp_enqueue_style( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/admin.css', [], '3.0.3' );
$suffix = '';
wp_enqueue_style( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/css/select2.min.css', null, '1.3' );
wp_enqueue_script( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/js/select2.min.js', null, '1.3', true );
wp_enqueue_script( 'opalestate-country-select', OPALESTATE_PLUGIN_URL . 'assets/js/country-select.js', [ 'jquery' ], null, true );
wp_enqueue_script( 'opalestate-admin', OPALESTATE_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', [ 'jquery' ], null, true );
}
/**
* Include all files from supported plugins.
*/
public function setup() {
$this->includes( [
'cron-jobs-functions.php',
'agent/class-agent.php',
'property/class-property.php',
'agency/class-agency.php',
'rating/class-rating.php',
'class-user.php',
] );
///
$this->includes( [
'settings/base.php',
'settings/api_keys.php',
'settings/email.php',
'settings/3rd_party.php',
'settings/searcharea.php',
'settings/general.php',
'settings/property.php',
] );
//
// Get it started
$Opalestate_Settings = new Opalestate_Plugin_Settings();
}
/**
* Include list of collection files
*
* @var array $files
*/
public function includes( $files ) {
foreach ( $files as $file ) {
$this->_include( $file );
}
}
/**
* include single file if found
*
* @var string $file
*/
private function _include( $file = '' ) {
$file = OPALESTATE_PLUGIN_DIR . 'inc/admin/' . $file;
if ( file_exists( $file ) ) {
include_once $file;
}
}
}
new Opalestate_Admin();

View File

@@ -0,0 +1,327 @@
<?php
/**
* API Key Table Class
*
* @package Opalestate
* @subpackage Admin/Tools/APIKeys
* @copyright Copyright (c) 2019, WordImpress
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.1
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Load WP_List_Table if not loaded
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
* Opalestate_API_Keys_Table Class
*
* Renders the API Keys table
*
* @since 1.1
*/
class Opalestate_API_Keys_Table extends WP_List_Table {
/**
* @var int Number of items per page
* @since 1.1
*/
public $per_page = 30;
/**
* @var object Query results
* @since 1.1
*/
private $keys;
/**
* Get things started
*
* @since 1.1
* @see WP_List_Table::__construct()
*/
public function __construct() {
global $status, $page;
// Set parent defaults
parent::__construct( array(
'singular' => esc_html__( 'API Key', 'opalestate-pro' ), // Singular name of the listed records
'plural' => esc_html__( 'API Keys', 'opalestate-pro' ), // Plural name of the listed records
'ajax' => false // Does this table support ajax?
) );
$this->query();
}
/**
* This function renders most of the columns in the list table.
*
* @access public
* @since 1.1
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_default( $item, $column_name ) {
return $item[ $column_name ];
}
/**
* Displays the public key rows
*
* @access public
* @since 1.1
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_key( $item ) {
return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>';
}
/**
* Displays the token rows
*
* @access public
* @since 1.1
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_token( $item ) {
return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>';
}
/**
* Displays the secret key rows
*
* @access public
* @since 1.1
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column
*
* @return string Column Name
*/
public function column_secret( $item ) {
return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>';
}
/**
* Renders the column for the user field
*
* @access public
* @since 1.1
* @return void
*/
public function column_user( $item ) {
$actions = array();
if ( apply_filters( 'opalestate_api_log_requests', true ) ) {
$actions['view'] = sprintf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( array(
'view' => 'api_requests',
'post_type' => 'opalestate_forms',
'page' => 'opalestate-reports',
'tab' => 'logs',
's' => $item['email']
), 'edit.php' ) ),
esc_html__( 'View API Log', 'opalestate-pro' )
);
}
$actions['reissue'] = sprintf(
'<a href="%s" class="opalestate-regenerate-api-key">%s</a>',
esc_url( wp_nonce_url( add_query_arg( array(
'user_id' => $item['id'],
'opalestate_action' => 'process_api_key',
'opalestate_api_process' => 'regenerate'
) ), 'opalestate-api-nonce' ) ),
esc_html__( 'Reissue', 'opalestate-pro' )
);
$actions['revoke'] = sprintf(
'<a href="%s" class="opalestate-revoke-api-key opalestate-delete">%s</a>',
esc_url( wp_nonce_url( add_query_arg( array(
'user_id' => $item['id'],
'opalestate_action' => 'process_api_key',
'opalestate_api_process' => 'revoke'
) ), 'opalestate-api-nonce' ) ),
esc_html__( 'Revoke', 'opalestate-pro' )
);
$actions = apply_filters( 'opalestate_api_row_actions', array_filter( $actions ) );
return sprintf( '%1$s %2$s', $item['user'], $this->row_actions( $actions ) );
}
/**
* Retrieve the table columns
*
* @access public
* @since 1.1
* @return array $columns Array of all the list table columns
*/
public function get_columns() {
$columns = array(
'user' => esc_html__( 'Username' , 'opalestate-pro' ),
'key' => esc_html__( 'Public Key' , 'opalestate-pro' ),
'token' => esc_html__( 'Token' , 'opalestate-pro' ),
'secret' => esc_html__( 'Secret Key' , 'opalestate-pro' )
);
return $columns;
}
/**
* Generate the table navigation above or below the table
*
* @since 3.1.0
* @access protected
* @param string $which
*/
protected function display_tablenav( $which ) {
if ( 'top' === $which ) {
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
}
?>
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<div class="alignleft actions bulkactions">
<?php $this->bulk_actions( $which ); ?>
</div>
<?php
$this->extra_tablenav( $which );
$this->pagination( $which );
?>
<br class="clear" />
</div>
<?php
}
/**
* Display the key generation form
*
* @access public
* @since 1.1
* @return void
*/
public function bulk_actions( $which = '' ) {
// These aren't really bulk actions but this outputs the markup in the right place
static $opalestate_api_is_bottom;
if ( $opalestate_api_is_bottom ) {
return;
}
?>
<input type="hidden" name="opalestate_action" value="process_api_key"/>
<input type="hidden" name="opalestate_api_process" value="generate"/>
<?php wp_nonce_field( 'opalestate-api-nonce' ); ?>
<?php echo OpalEstate()->html->ajax_user_search(); ?>
<?php submit_button( esc_html__( 'Generate New API Keys', 'opalestate-pro' ), 'secondary', 'submit', false ); ?>
<?php
$opalestate_api_is_bottom = true;
}
/**
* Retrieve the current page number
*
* @access public
* @since 1.1
* @return int Current page number
*/
public function get_paged() {
return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
}
/**
* Performs the key query
*
* @access public
* @since 1.1
* @return array
*/
public function query() {
$users = get_users( array(
'meta_value' => 'opalestate_user_secret_key',
'number' => $this->per_page,
'offset' => $this->per_page * ( $this->get_paged() - 1 )
) );
$keys = array();
foreach ( $users as $user ) {
$keys[ $user->ID ]['id'] = $user->ID;
$keys[ $user->ID ]['email'] = $user->user_email;
$keys[ $user->ID ]['user'] = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>';
$keys[ $user->ID ]['key'] = OpalEstate()->api->get_user_public_key( $user->ID );
$keys[ $user->ID ]['secret'] = OpalEstate()->api->get_user_secret_key( $user->ID );
$keys[ $user->ID ]['token'] = OpalEstate()->api->get_token( $user->ID );
}
return $keys;
}
/**
* Retrieve count of total users with keys
*
* @access public
* @since 1.1
* @return int
*/
public function total_items() {
global $wpdb;
if ( ! get_transient( 'opalestate_total_api_keys' ) ) {
$total_items = $wpdb->get_var( "SELECT count(user_id) FROM $wpdb->usermeta WHERE meta_value='opalestate_user_secret_key'" );
set_transient( 'opalestate_total_api_keys', $total_items, 60 * 60 );
}
return get_transient( 'opalestate_total_api_keys' );
}
/**
* Setup the final data for the table
*
* @access public
* @since 1.1
* @return void
*/
public function prepare_items() {
$columns = $this->get_columns();
$hidden = array(); // No hidden columns
$sortable = array(); // Not sortable... for now
$this->_column_headers = array( $columns, $hidden, $sortable, 'id' );
$data = $this->query();
$total_items = $this->total_items();
$this->items = $data;
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $this->per_page,
'total_pages' => ceil( $total_items / $this->per_page )
)
);
}
}

187
inc/admin/class-user.php Executable file
View File

@@ -0,0 +1,187 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class OpalEstate_Admin_User{
/**
*
*/
public function __construct( ){
add_action( 'cmb2_admin_init', array( $this, 'register_user_profile_metabox') );
add_action( 'personal_options', array( $this, 'show_message_user_profile' ) );
}
/**
*
*/
public function show_message_user_profile(){
$user_id = isset( $_GET['user_id'] ) ? intval( $_GET['user_id'] ) : 0;
$roles = opalestate_user_roles_by_user_id( $user_id );
if( $roles ):
if( in_array( 'opalestate_agency', $roles) ):
$agency_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
if( !$agency_id ){
return ;
}
$link = get_edit_post_link( $agency_id );
?>
<div id="message" class="updated fade">
<p><?php echo sprintf( esc_html__('This user has role <strong>Opal Estate Agency</strong> and click here to <a href="%s">update Agency profile</a>', 'opalestate-pro'), $link ); ?></p>
</div>
<?php elseif( in_array( 'opalestate_agent', $roles) ) :
$agent_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
if( !$agent_id ){
return ;
}
$link = get_edit_post_link( $agent_id );
?>
<div id="message" class="updated fade">
<p><?php echo sprintf( esc_html__('This user has role <strong>Opal Estate Agent</strong> and click here to <a href="%s">update Agent profile</a>', 'opalestate-pro'), $link ); ?></p>
</div>
<?php endif; ?>
<?php
endif;
}
/**
*
*/
public function shortcode_button(){
}
/**
* Hook in and add a metabox to add fields to the user profile pages
*/
public function register_user_profile_metabox() {
global $pagenow;
if( $pagenow == 'profile.php' || $pagenow == 'user-new.php' || 'user-edit.php' ){
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
$metabox = new Opalestate_User_MetaBox();
$box_options = array(
'id' => $prefix . 'edit',
'title' => esc_html__( 'Metabox', 'opalestate-pro' ),
'object_types' => array( 'user' ),
'show_names' => true,
);
$cmb = new_cmb2_box( $box_options );
// Setting tabs
$tabs_setting = array(
'config' => $box_options,
'layout' => 'vertical', // Default : horizontal
'tabs' => array()
);
$tabs_setting['tabs'][] = array(
'id' => 'p-general',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'General', 'opalestate-pro' ),
'fields' => $this->get_base_fields()
);
$tabs_setting['tabs'][] = array(
'id' => 'p-socials',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'Socials', 'opalestate-pro' ),
'fields' => $metabox->get_social_fields( $prefix ),
);
// Set tabs
$cmb->add_field( array(
'id' => '__tabs',
'type' => 'tabs',
'tabs' => $tabs_setting
) );
/**
* Metabox for the user profile screen
*/
$cmb_user = new_cmb2_box( array(
'id' => $prefix . 'edit',
'title' => esc_html__( 'User Profile Metabox', 'cmb2' ), // Doesn't output for user boxes
'object_types' => array( 'user' ), // Tells CMB2 to use user_meta vs post_meta
'show_names' => true,
'new_user_section' => 'add-new-user', // where form will show on new user page. 'add-existing-user' is only other valid option.
) );
$fields = $this->extra_info_fields();
foreach( $fields as $field ){
$cmb_user->add_field( $field );
}
}
}
public function get_base_fields(){
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
$metabox = new Opalestate_User_MetaBox();
$fields = array_merge_recursive(
$metabox->get_base_fields( $prefix ),
$metabox->get_job_fields( $prefix ) ,
$metabox->get_address_fields( $prefix )
);
return $fields;
}
/**
*
*/
public function extra_info_fields(){
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
$management = array();
$admin_fields = array();
$admin_fields[] = array(
'id' => "{$prefix}block_submission",
'name' => esc_html__( 'Block Submssion', 'opalestate-pro' ),
'type' => 'checkbox',
'description' => esc_html__( 'Disable Submssion Functions to not allow submit property', 'opalestate-pro' ),
'before_row' => '<hr>'
);
$admin_fields[] = array(
'id' => "{$prefix}block_submission_msg",
'name' => esc_html__( 'Block Submssion Message', 'opalestate-pro' ),
'type' => 'textarea',
'description' => esc_html__( 'Show message for disabled user', 'opalestate-pro' ),
);
$management = array_merge_recursive( $admin_fields, $management );
return $management;
}
}
new OpalEstate_Admin_User();

View File

599
inc/admin/functions.php Executable file
View File

@@ -0,0 +1,599 @@
<?php
/**
* Admin functions
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Wrapper function around cmb2_get_option
*
* @param string $key Options array key
*
* @return mixed Option value
* @since 0.1.0
*
*/
function opalestate_get_option( $key = '', $default = false ) {
global $opalestate_options;
$value = ! empty( $opalestate_options[ $key ] ) ? $opalestate_options[ $key ] : $default;
$value = apply_filters( 'opalestate_get_option', $value, $key, $default );
return apply_filters( 'opalestate_get_option_' . $key, $value, $key, $default );
}
/**
* Update an option
*
* Updates an opalestate setting value in both the db and the global variable.
* Warning: Passing in an empty, false or null string value will remove
* the key from the opalestate_options array.
*
* @param string $key The Key to update
* @param string|bool|int $value The value to set the key to
*
* @return boolean True if updated, false if not.
* @since 1.0
*
*/
function opalestate_update_option( $key = '', $value = false ) {
// If no key, exit
if ( empty( $key ) ) {
return false;
}
if ( empty( $value ) ) {
$remove_option = opalestate_delete_option( $key );
return $remove_option;
}
// First let's grab the current settings
$options = get_option( 'opalestate_settings' );
// Let's let devs alter that value coming in
$value = apply_filters( 'opalestate_update_option', $value, $key );
// Next let's try to update the value
$options[ $key ] = $value;
$did_update = update_option( 'opalestate_settings', $options );
// If it updated, let's update the global variable
if ( $did_update ) {
global $opalestate_options;
$opalestate_options[ $key ] = $value;
}
return $did_update;
}
/**
* Remove an option
*
* Removes an opalestate setting value in both the db and the global variable.
*
* @param string $key The Key to delete
*
* @return boolean True if updated, false if not.
* @since 1.0
*
*/
function opalestate_delete_option( $key = '' ) {
// If no key, exit
if ( empty( $key ) ) {
return false;
}
// First let's grab the current settings
$options = get_option( 'opalestate_settings' );
// Next let's try to update the value
if ( isset( $options[ $key ] ) ) {
unset( $options[ $key ] );
}
$did_update = update_option( 'opalestate_settings', $options );
// If it updated, let's update the global variable
if ( $did_update ) {
global $opalestate_options;
$opalestate_options = $options;
}
return $did_update;
}
/**
* Get Settings
*
* Retrieves all Opalestate plugin settings
*
* @return array Opalestate settings
* @since 1.0
*/
function opalestate_get_settings() {
$settings = get_option( 'opalestate_settings' );
return (array) apply_filters( 'opalestate_get_settings', $settings );
}
/**
* Gateways Callback
*
* Renders gateways fields.
*
* @return void
* @global $opalestate_options Array of all the Opalestate Options
* @since 1.0
*
*/
function opalestate_enabled_gateways_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
$id = $field_type_object->field->args['id'];
$field_description = $field_type_object->field->args['desc'];
$gateways = opalestate_get_payment_gateways();
echo '<ul class="cmb2-checkbox-list cmb2-list">';
foreach ( $gateways as $key => $option ) :
if ( is_array( $escaped_value ) && array_key_exists( $key, $escaped_value ) ) {
$enabled = '1';
} else {
$enabled = null;
}
echo '<li><input name="' . $id . '[' . $key . ']" id="' . $id . '[' . $key . ']" type="checkbox" value="1" ' . checked( '1', $enabled, false ) . '/>&nbsp;';
echo '<label for="' . $id . '[' . $key . ']">' . $option['admin_label'] . '</label></li>';
endforeach;
if ( $field_description ) {
echo '<p class="cmb2-metabox-description">' . $field_description . '</p>';
}
echo '</ul>';
}
/**
* Gateways Callback (drop down)
*
* Renders gateways select menu
*
* @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
*
* @return void
* @since 1.0
*
*/
function opalestate_default_gateway_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
$id = $field_type_object->field->args['id'];
$field_description = $field_type_object->field->args['desc'];
$gateways = opalestate_get_enabled_payment_gateways();
echo '<select class="cmb2_select" name="' . $id . '" id="' . $id . '">';
//Add a field to the Opalestate Form admin single post view of this field
if ( $field_type_object->field->object_type === 'post' ) {
echo '<option value="global">' . esc_html__( 'Global Default', 'opalestate-pro' ) . '</option>';
}
foreach ( $gateways as $key => $option ) :
$selected = isset( $escaped_value ) ? selected( $key, $escaped_value, false ) : '';
echo '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
endforeach;
echo '</select>';
echo '<p class="cmb2-metabox-description">' . $field_description . '</p>';
}
/**
* Opalestate Title
*
* Renders custom section titles output; Really only an <hr> because CMB2's output is a bit funky
*
* @param $field_object , $escaped_value, $object_id, $object_type, $field_type_object
*
* @return void
* @since 1.0
*
*/
function opalestate_title_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
$id = $field_type_object->field->args['id'];
$title = $field_type_object->field->args['name'];
$field_description = $field_type_object->field->args['desc'];
echo '<hr>';
}
/**
* Gets a number of posts and displays them as options
*
* @param array $query_args Optional. Overrides defaults.
* @param bool $force Force the pages to be loaded even if not on settings
*
* @return array An array of options that matches the CMB2 options array
* @see: https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types
*/
function opalestate_cmb2_get_post_options( $query_args, $force = false ) {
$post_options = [ '' => '' ]; // Blank option
if ( ( ! isset( $_GET['page'] ) || 'opalestate-settings' != $_GET['page'] ) && ! $force ) {
return $post_options;
}
$args = wp_parse_args( $query_args, [
'post_type' => 'page',
'numberposts' => 10,
] );
$posts = get_posts( $args );
if ( $posts ) {
foreach ( $posts as $post ) {
$post_options[ $post->ID ] = $post->post_title;
}
}
return $post_options;
}
/**
* Modify CMB2 Default Form Output
*
* @param string @args
*
* @since 1.0
*/
add_filter( 'cmb2_get_metabox_form_format', 'opalestate_modify_cmb2_form_output', 10, 3 );
function opalestate_modify_cmb2_form_output( $form_format, $object_id, $cmb ) {
//only modify the opalestate settings form
if ( 'opalestate_settings' == $object_id && 'options_page' == $cmb->cmb_id ) {
return '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<div class="opalestate-submit-wrap"><input type="submit" name="submit-cmb" value="' . esc_html__( 'Save Settings',
'opalestate-pro' ) . '" class="button-primary"></div></form>';
}
return $form_format;
}
/**
* Opalestate License Key Callback
*
* @description Registers the license field callback for EDD's Software Licensing
* @param array $field_object , $escaped_value, $object_id, $object_type, $field_type_object Arguments passed by CMB2
*
* @return void
* @since 1.0
*
*/
if ( ! function_exists( 'opalestate_license_key_callback' ) ) {
function opalestate_license_key_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) {
$id = $field_type_object->field->args['id'];
$field_description = $field_type_object->field->args['desc'];
$license_status = get_option( $field_type_object->field->args['options']['is_valid_license_option'] );
$field_classes = 'regular-text opalestate-license-field';
$type = empty( $escaped_value ) ? 'text' : 'password';
if ( $license_status === 'valid' ) {
$field_classes .= ' opalestate-license-active';
}
$html = $field_type_object->input( [
'class' => $field_classes,
'type' => $type,
] );
//License is active so show deactivate button
if ( $license_status === 'valid' ) {
$html .= '<input type="submit" class="button-secondary opalestate-license-deactivate" name="' . $id . '_deactivate" value="' . esc_html__( 'Deactivate License', 'opalestate-pro' ) . '"/>';
} else {
//This license is not valid so delete it
opalestate_delete_option( $id );
}
$html .= '<label for="opalestate_settings[' . $id . ']"> ' . $field_description . '</label>';
wp_nonce_field( $id . '-nonce', $id . '-nonce' );
echo $html;
}
}
/**
* Display the API Keys
*
* @return void
* @since 2.0
*/
function opalestate_api_keys_callback() {
if ( ! current_user_can( 'manage_opalestate_settings' ) ) {
return;
}
do_action( 'opalestate_tools_api_keys_keys_before' );
require_once OPALESTATE_PLUGIN_DIR . 'inc/admin/class-api-keys-table.php';
$keys_table_list = new Opalestate_API_Keys_Table();
$keys_table_list->prepare_items();
echo '<input type="hidden" name="page" value="wc-settings" />';
echo '<input type="hidden" name="tab" value="api" />';
echo '<input type="hidden" name="section" value="keys" />';
$keys_table_list->views();
$keys_table_list->search_box( esc_html__( 'Search Key', 'opalestate-pro' ), 'key' );
$keys_table_list->display();
?>
<p>
<?php printf(
__( 'API keys allow users to use the <a href="%s">Opalestate REST API</a> to retrieve donation data in JSON or XML for external applications or devices, such as <a href="%s">Zapi_keyser</a>.',
'opalestate-pro' ),
'https://wpopal.com/opalestate/documentation/opalestate-api_keys-reference/',
'https://wpopal.com/addons/opalestate/'
); ?>
</p>
<style>
.opalestate_properties_page_opalestate-settings .opalestate-submit-wrap {
display: none; /* Hide Save settings button on System Info Tab (not needed) */
}
</style>
<?php
do_action( 'opalestate_tools_api_keys_keys_after' );
}
add_action( 'opalestate_settings_tab_api_keys_keys', 'opalestate_api_keys_callback' );
/**
* Hook Callback
*
* Adds a do_action() hook in place of the field
*
* @param array $args Arguments passed by the setting
*
* @return void
* @since 1.0
*
*/
function opalestate_hook_callback( $args ) {
do_action( 'opalestate_' . $args['id'] );
}
register_activation_hook( __FILE__, 'opalestate_active_cron_jobs' );
function opalestate_active_cron_jobs() {
if ( ! wp_next_scheduled( 'opalestate_cleanup' ) ) {
wp_schedule_event( time(), 'daily', 'opalestate_cleanup' );
}
}
register_deactivation_hook( __FILE__, 'opalestate_deactive_cron_jobs' );
function opalestate_deactive_cron_jobs() {
wp_clear_scheduled_hook( 'opalestate_cleanup' );
}
function opalestate_cleanup() {
$query = new WP_Query(
[
'post_type' => 'attachment',
'post_status' => 'inherit',
'date_query' => [
'column' => 'post_date',
'before' => date( 'Y-m-d', strtotime( '-1 days' ) ),
],
'meta_query' => [
[
'key' => '_pending_to_use_',
'value' => 1,
'compare' => '>=',
],
],
]
);
// clean up per day
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
wp_delete_attachment( get_the_ID() );
}
}
wp_reset_postdata();
}
/**
* Searches for users via ajax and returns a list of results
*
* @return void
* @since 1.0
*
*/
function opalestate_ajax_search_agencies() {
if ( current_user_can( 'manage_opalestate_settings' ) ) {
$search_query = trim( $_GET['q'] );
$agents_objects = Opalestate_Query::get_agencies( [
'posts_per_page' => -1,
's' => $search_query,
] );
$agents = [];
if ( ! empty( $agents_objects->posts ) && is_array( $agents_objects->posts ) ) {
foreach ( $agents_objects->posts as $object ) {
$agents[] = [
'id' => $object->ID,
'name' => $object->post_title,
'avatar_url' => 'https://avatars1.githubusercontent.com/u/9919?v=4',
'full_name' => $object->post_title,
'description' => 'okokok',
];
}
}
$output = [
'total_count' => count( $agents ),
'items' => $agents,
'incomplete_results' => false,
];
echo json_encode( $output );
}
die();
}
add_action( 'wp_ajax_opalestate_search_agencies', 'opalestate_ajax_search_agencies' );
/**
* Searches for users via ajax and returns a list of results
*
* @return void
* @since 1.0
*
*/
function opalestate_ajax_search_agents() {
if ( current_user_can( 'manage_opalestate_settings' ) ) {
$search_query = trim( $_GET['q'] );
$agents_objects = Opalestate_Query::get_agents( [
'posts_per_page' => -1,
's' => $search_query,
] );
$agents = [];
if ( ! empty( $agents_objects->posts ) && is_array( $agents_objects->posts ) ) {
foreach ( $agents_objects->posts as $object ) {
$agents[] = [
'id' => $object->ID,
'name' => $object->post_title,
'avatar_url' => 'https://avatars1.githubusercontent.com/u/9919?v=4',
'full_name' => $object->post_title,
'description' => 'okokok',
];
}
}
$output = [
'total_count' => count( $agents ),
'items' => $agents,
'incomplete_results' => false,
];
echo json_encode( $output );
}
die();
}
add_action( 'wp_ajax_opalestate_search_agents', 'opalestate_ajax_search_agents' );
/**
* Searches for users via ajax and returns a list of results
*
* @return void
* @since 1.0
*
*/
function opalestate_ajax_search_users() {
if ( current_user_can( 'manage_opalestate_settings' ) ) {
$search_query = trim( $_GET['q'] );
$get_users_args = [
'number' => 9999,
'search' => $search_query . '*',
];
if ( ! empty( $exclude ) ) {
$exclude_array = explode( ',', $exclude );
$get_users_args['exclude'] = $exclude_array;
}
$get_users_args = apply_filters( 'opalestate_search_users_args', $get_users_args );
$found_users = apply_filters( 'opalestate_ajax_found_users', get_users( $get_users_args ), $search_query );
$user_list = '<ul>';
if ( $found_users ) {
foreach ( $found_users as $user ) {
$user_list .= '<li><a href="#" data-userid="' . esc_attr( $user->ID ) . '" data-login="' . esc_attr( $user->user_login ) . '">' . esc_html( $user->user_login ) . '</a></li>';
}
} else {
$user_list .= '<li>' . esc_html__( 'No users found', 'opalestate-pro' ) . '</li>';
}
$user_list .= '</ul>';
echo json_encode( [ 'results' => $user_list ] );
}
die();
}
add_action( 'wp_ajax_opalestate_search_users', 'opalestate_ajax_search_users' );
function opalestate_ajax_search_username() {
$search_query = trim( $_POST['user_name'] );
$user = get_userdatabylogin( $search_query );
$output = [];
if ( $user ) {
$data = $user->data;
$data->author_link = get_author_posts_url( $user->data->ID );
$data->avatar = get_avatar_url( $user->data->ID );
$output['message'] = esc_html__( 'We could find this user', 'opalestate-pro' );
$output['status'] = true;
$output['user'] = $data;
} else {
$output['message'] = esc_html__( 'We could not find this user', 'opalestate-pro' );
$output['status'] = false;
}
echo json_encode( $output );
exit;
}
add_action( 'wp_ajax_opalestate_ajax_search_username', 'opalestate_ajax_search_username' );

View File

@@ -0,0 +1,163 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Admin_Property {
/**
* @var $tab
*/
private $tab;
/**
* Opalestate_Admin_Property constructor.
*/
public function __construct() {
add_filter( 'cmb2_admin_init', [ $this, 'metaboxes' ] );
add_action( 'transition_opalestate_property_status', [ $this, 'process_publish_property' ], 10, 1 );
/* property column */
add_filter( 'manage_opalestate_property_posts_columns', [ $this, 'columns' ] );
add_action( 'manage_opalestate_property_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 );
add_action( 'admin_menu', [ $this, 'remove_meta_boxes' ] );
// add_action( 'transition_post_status', array( __CLASS__, 'save_post' ), 10, 3 );
}
/**
*
*/
public static function save_post( $new_status, $old_status, $post ){
if ( $new_status == 'publish' && $post->post_type == "opalestate_property" ) {
$user_id = $post->post_author;
$user = get_user_by( 'id', $user_id );
if ( ! is_object( $user ) ) {
$from_name = opalestate_get_option( 'from_name' );
$from_email = opalestate_get_option( 'from_email' );
$subject = opalestate_get_option( 'publish_submission_email_subject' );
$headers = sprintf( "From: %s <%s>\r\n Content-type: text/html", $from_name, $from_email );
$property_link = get_permalink( $post );
$tags = [ "{first_name}", "{last_name}", "{property_link}" ];
$values = [ $user->first_name, $user->last_name, $property_link ];
$body = opalestate_get_option( 'publish_submission_email_body' );
$body = html_entity_decode( $body );
$message = str_replace( $tags, $values, $body );
return wp_mail( $user->user_email, $subject, $message, $headers );
}
}
}
/**
*
*/
public function metaboxes() {
global $pagenow;
if ( ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) {
$metabox = new Opalestate_Property_MetaBox();
return $metabox->register_admin_fields();
}
}
private function add_fields_to_tab( $fields, $tab ) {
foreach ( $fields as $field ) {
$field['tab'] = $tab;
$field['render_row_cb'] = [ 'CMB2_Tabs', 'tabs_render_row_cb' ];
$this->tab->add_field( $field );
}
}
/**
*
*/
public function columns( $columns ) {
$comments = $columns['comments'];
unset( $columns['author'], $columns['date'], $columns['comments'] );
$columns['featured'] = esc_html__( 'Featured', 'opalestate-pro' );
$columns['sku'] = esc_html__( 'Sku', 'opalestate-pro' );
$columns['address'] = esc_html__( 'Address', 'opalestate-pro' );
$columns['comments'] = $comments;
$columns['author'] = esc_html__( 'Author', 'opalestate-pro' );
$columns['date'] = esc_html__( 'Date', 'opalestate-pro' );
return $columns;
}
/**
*
*/
public function custom_columns( $column, $post_id ) {
$property = new Opalestate_Property( $post_id );
$nonce = wp_create_nonce( 'opalestate_property' );
switch ( $column ) {
case 'featured':
if ( $property->featured ) {
$url = add_query_arg( [
'action' => 'opalestate_remove_feature_property',
'property_id' => $post_id,
'nonce' => $nonce,
], admin_url( 'admin-ajax.php' ) );
echo '<a href="' . esc_url( $url ) . '">';
echo '<i class="dashicons dashicons-star-filled"></i>';
echo '</a>';
} else {
$url = add_query_arg( [
'action' => 'opalestate_set_feature_property',
'property_id' => $post_id,
'nonce' => $nonce,
], admin_url( 'admin-ajax.php' ) );
echo '<a href="' . esc_url( $url ) . '">';
echo '<i class="dashicons dashicons-star-empty"></i>';
echo '</a>';
}
break;
case 'sku':
if ( $property->sku ) {
echo sprintf( '%s', $property->sku );
}
break;
case 'address':
if ( $property->address ) {
echo sprintf( '%s', $property->address );
}
break;
default:
# code...
break;
}
}
public function remove_meta_boxes() {
remove_meta_box( 'authordiv', 'opalestate_property', 'normal' );
}
}
new Opalestate_Admin_Property();
?>

101
inc/admin/rating/class-rating.php Executable file
View File

@@ -0,0 +1,101 @@
<?php
/**
* Admin Rating.
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Admin_Rating {
/**
* Opalestate_Admin_Rating constructor.
*/
public function __construct() {
add_action( 'cmb2_admin_init', [ $this, 'comment_metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'feature_metaboxes' ] );
add_filter( 'opalestate_settings_tabs', [ $this, 'register_admin_setting_tab' ], 1 );
add_filter( 'opalestate_registered_review_settings', [ $this, 'register_admin_settings' ], 10, 1 );
// Save Rating Meta Boxes.
add_filter( 'wp_update_comment_data', 'Opalestate_Rating_MetaBox::save', 1 );
}
public function comment_metaboxes() {
$metabox = new Opalestate_Rating_MetaBox();
return $metabox->register_admin_comment_fields();
}
public function feature_metaboxes() {
$metabox = new Opalestate_Rating_MetaBox();
return $metabox->register_admin_feature_fields();
}
public function register_admin_setting_tab( $tabs ) {
$tabs['review'] = esc_html__( 'Review', 'opalestate-pro' );
return $tabs;
}
public function register_admin_settings( $fields ) {
$fields = [
'id' => 'options_page_review',
'title' => esc_html__( 'Review Settings', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ 'opalestate_settings' ], ],
'fields' => apply_filters( 'opalestate_settings_review', [
[
'name' => esc_html__( 'Review Settings', 'opalestate-pro' ),
'desc' => '<hr>',
'id' => 'opalestate_title_review_settings',
'type' => 'title',
],
[
'name' => esc_html__( 'Enable property reviews', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable property reviews', 'opalestate-pro' ),
'id' => 'enable_property_reviews',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable agency reviews', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable agency reviews', 'opalestate-pro' ),
'id' => 'enable_agency_reviews',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable agent reviews', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable agent reviews', 'opalestate-pro' ),
'id' => 'enable_agent_reviews',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
]
),
];
return $fields;
}
}
new Opalestate_Admin_Rating();

306
inc/admin/register-settings.php Executable file
View File

@@ -0,0 +1,306 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Plugin_Settings {
/**
* Option key, and option page slug
*
* @var string
*/
private $key = 'opalestate_settings';
/**
* Array of metaboxes/fields
*
* @var array
*/
protected $option_metabox = [];
/**
* Options Page title
*
* @var string
*/
protected $title = '';
/**
* Options Page hook
*
* @var string
*/
protected $options_page = '';
protected $subtabs = array();
protected $setting_object = array();
/**
* Constructor
*
* @since 1.0
*/
public function __construct() {
add_action( 'admin_menu', [ $this, 'admin_menu' ], 10 );
add_action( 'admin_init', [ $this, 'init' ] );
//Custom CMB2 Settings Fields
add_action( 'cmb2_render_opalestate_title', 'opalestate_title_callback', 10, 5 );
// add_action( 'cmb2_render_api_keys', 'opalestate_api_keys_callback', 10, 5 );
// add_action( 'cmb2_render_license_key', 'opalestate_license_key_callback', 10, 5 );
add_action( "cmb2_save_options-page_fields", [ $this, 'settings_notices' ], 10, 3 );
add_action( 'cmb2_render_api_keys', 'opalestate_api_keys_callback', 10, 5 );
// Include CMB CSS in the head to avoid FOUC
add_action( "admin_print_styles-opalestate_properties_page_opalestate-settings", [ 'CMB2_hookup', 'enqueue_cmb_css' ] );
}
public function admin_menu() {
//Settings
$opalestate_settings_page = add_submenu_page( 'edit.php?post_type=opalestate_property', esc_html__( 'Settings', 'opalestate-pro' ), esc_html__( 'Settings', 'opalestate-pro' ), 'manage_opalestate_settings',
'opalestate-settings',
[ $this, 'admin_page_display' ] );
// addons setting
$opalestate_settings_page = add_submenu_page( 'edit.php?post_type=opalestate_property', esc_html__( 'Addons', 'opalestate-pro' ), esc_html__( 'Addons', 'opalestate-pro' ), 'manage_options', 'opalestate-addons',
[ $this, 'admin_addons_page_display' ] );
}
/**
* Register our setting to WP
*
* @since 1.0
*/
public function init() {
register_setting( $this->key, $this->key );
}
/**
* Retrieve settings tabs
*
* @return array $tabs
* @since 1.0
*/
public function opalestate_get_settings_tabs() {
$settings = $this->opalestate_settings( null );
$tabs = [];
$tabs['general'] = esc_html__( 'General', 'opalestate-pro' );
$tabs['property'] = esc_html__( 'Property', 'opalestate-pro' );
if ( ! empty( $settings['addons']['fields'] ) ) {
$tabs['addons'] = esc_html__( 'Add-ons', 'opalestate-pro' );
}
if ( ! empty( $settings['licenses']['fields'] ) ) {
$tabs['licenses'] = esc_html__( 'Licenses', 'opalestate-pro' );
}
$tabs['api_keys'] = esc_html__( 'API', 'opalestate-pro' );
$tabs['3rd_party'] = esc_html__( '3rd Party', 'opalestate-pro' );
return apply_filters( 'opalestate_settings_tabs', $tabs );
}
public function admin_addons_page_display() {
require_once opalestate_get_admin_view( 'addons/list.php' );
}
public function get_subtabs_link ( $tab_id , $stab_id ) {
$tab_url = esc_url( add_query_arg( [
'settings-updated' => false,
'tab' => $tab_id,
'subtab' => $stab_id
] ) );
return $tab_url;
}
/**
* Admin page markup. Mostly handled by CMB2
*
* @since 1.0
*/
public function admin_page_display() {
$active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->opalestate_get_settings_tabs() ) ? $_GET['tab'] : 'general';
$sub_active_tab = isset( $_GET['subtab'] ) ? sanitize_text_field( $_GET['subtab'] ): '';
$tabs_fields = $this->opalestate_settings( $active_tab );
$sub_tabs_fields = array();
if( empty($sub_active_tab) && $this->subtabs ){
$first = array_flip( $this->subtabs );
$sub_active_tab = reset( $first );
}
if( $this->subtabs ){
$sub_tabs_fields = $this->setting_object->get_subtabs_content( $sub_active_tab );
}
?>
<div class="wrap opalestate_settings_page cmb2_options_page <?php echo $this->key; ?>">
<h2 class="nav-tab-wrapper">
<?php
foreach ( $this->opalestate_get_settings_tabs() as $tab_id => $tab_name ) {
$tab_url = esc_url( add_query_arg( [
'settings-updated' => false,
'tab' => $tab_id,
'subtab' => false
] ) );
$active = $active_tab == $tab_id ? ' nav-tab-active' : '';
echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
echo esc_html( $tab_name );
echo '</a>';
}
?>
</h2>
<div class="form-settings-wrap">
<?php if( $this->subtabs ): ?>
<div class="subtab-settings-navs">
<ul>
<?php foreach( $this->subtabs as $key => $value ): ?>
<li>
<a <?php if( $key == $sub_active_tab ): ?>class="active"<?php endif; ?> href="<?php echo esc_url( $this->get_subtabs_link( $active_tab, $key ) ); ?>">
<?php echo $value; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif ; ?>
<div class="form-settings-form">
<?php if( $sub_active_tab ): ?>
<?php cmb2_metabox_form( $sub_tabs_fields , $this->key ); ?>
<?php else : ?>
<?php cmb2_metabox_form( $tabs_fields , $this->key ); ?>
<?php endif; ?>
</div>
</div>
</div><!-- .wrap -->
<?php
}
/**
* Define General Settings Metabox and field configurations.
*
* Filters are provided for each settings section to allow add-ons and other plugins to add their own settings
*
* @param $active_tab active tab settings; null returns full array
*
* @return array
*/
public function opalestate_settings( $active_tab ) {
$pages = opalestate_cmb2_get_post_options( [
'post_type' => 'page',
'numberposts' => -1,
] );
$general = array();
$opalestate_settings = array();
//Return all settings array if necessary
if ( $active_tab === null ) {
return apply_filters( 'opalestate_registered_settings', $opalestate_settings );
}
$output = apply_filters( 'opalestate_registered_' . $active_tab . '_settings', isset( $opalestate_settings[ $active_tab ] ) ? $opalestate_settings[ $active_tab ] : [] );
if( empty($output) ){
$class = "Opalestate_Settings_".ucfirst( $active_tab )."_Tab";
if( class_exists($class) ){
$tab = new $class( $this->key );
$this->setting_object = $tab;
$this->subtabs = $tab->get_subtabs();
return $tab->get_tab_content( $this->key );
}
return array( $active_tab => array() );
}
// Add other tabs and settings fields as needed
return $output;
}
/**
* Show Settings Notices
*
* @param $object_id
* @param $updated
* @param $cmb
*/
public function settings_notices( $object_id, $updated, $cmb ) {
//Sanity check
if ( $object_id !== $this->key ) {
return;
}
if ( did_action( 'cmb2_save_options-page_fields' ) === 1 ) {
settings_errors( 'opalestate-notices' );
}
add_settings_error( 'opalestate-notices', 'global-settings-updated', esc_html__( 'Settings updated.', 'opalestate-pro' ), 'updated' );
}
/**
* Public getter method for retrieving protected/private variables
*
* @param string $field Field to retrieve
*
* @return mixed Field value or exception is thrown
* @since 1.0
*
*/
public function __get( $field ) {
// Allowed fields to retrieve
if ( in_array( $field, [ 'key', 'fields', 'opalestate_title', 'options_page' ], true ) ) {
return $this->{$field};
}
if ( 'option_metabox' === $field ) {
return $this->option_metabox();
}
throw new Exception( 'Invalid property: ' . $field );
}
}

137
inc/admin/settings/3rd_party.php Executable file
View File

@@ -0,0 +1,137 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Settings_3rd_party_Tab extends Opalestate_Settings_Base_Tab {
public function get_subtabs () {
$tabs = (array)apply_filters (
'opalestate_settings_3rd_party_subtabs_nav', array()
);
$tabs = array_merge_recursive( $tabs, array(
'yelp' => "Yelp",
'walkcore' => "Walkcore"
) );
return $tabs;
}
public function get_subtabs_content( $key ="" ) {
// echo $key;die;
$fields = apply_filters ( 'opalestate_settings_3rd_party_subtabs_'.$key.'_fields', array() );
if( $key == 'yelp' ){
$fields = $this->get_yelp_fields();
}else if( $key == 'walkcore' ){
$fields = $this->get_walkscore_fields();
}
return [
'id' => 'options_page',
'opalestate_title' => esc_html__( '3rd Party Settings', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ $key ], ],
'fields' => (array)$fields
];
}
public function get_walkscore_fields(){
return array(
[
'name' => esc_html__( 'Walk Score', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_walkscore',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Walk Score APi Key', 'opalestate-pro' ),
'desc' => esc_html__( 'Add Walk Score API key. To get your Walk Score API key, go to your Walk Score Account.', 'opalestate-pro' ),
'id' => 'walkscore_api_key',
'type' => 'text',
]
);
}
public function get_yelp_fields(){
return array(
[
'name' => esc_html__( 'Yelp', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_yelp',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Yelp API Client ID', 'opalestate-pro' ),
'desc' => esc_html__( 'Add Yelp client ID. To get your Yelp Api Client ID, go to your Yelp Account. Register <a href="https://www.yelp.com/developers/v3/manage_app" target="_blank">here</a>',
'opalestate-pro' ),
'id' => 'yelp_app_id',
'type' => 'text',
],
[
'name' => esc_html__( 'Yelp API Secret', 'opalestate-pro' ),
'desc' => esc_html__( 'Add Yelp API Secret. Register <a href="https://www.yelp.com/developers/v3/manage_app" target="_blank">here</a>',
'opalestate-pro' ),
'id' => 'yelp_app_secret',
'type' => 'text',
],
[
'name' => esc_html__( 'Yelp App key', 'opalestate-pro' ),
'desc' => esc_html__( 'You can find it in your Yelp Application Dashboard. Register <a href="https://www.yelp.com/developers/v3/manage_app" target="_blank">here</a>',
'opalestate-pro' ),
'id' => 'yelp_app_key',
'type' => 'text',
],
[
'name' => esc_html__( 'Yelp Categories', 'opalestate-pro' ),
'desc' => esc_html__( 'Yelp Categories to show on front page', 'opalestate-pro' ),
'id' => 'yelp_categories',
'type' => 'multicheck',
'options' => OpalEstate_Yelp::get_all_categories_options(),
],
[
'name' => esc_html__( 'Yelp - Number of results', 'opalestate-pro' ),
'desc' => esc_html__( 'Number of results to show on listing page for each category.', 'opalestate-pro' ),
'id' => 'yelp_number_results',
'type' => 'text',
'default' => 3,
'attributes' => [
'type' => 'number',
'min' => 1,
],
],
[
'name' => esc_html__( 'Yelp Distance Measurement Unit', 'opalestate-pro' ),
'desc' => esc_html__( 'Yelp Distance Measurement Unit', 'opalestate-pro' ),
'id' => 'yelp_measurement_unit',
'type' => 'select',
'options' => [
'miles' => esc_html__( 'miles', 'opalestate-pro' ),
'kilometers' => esc_html__( 'kilometers', 'opalestate-pro' ),
],
'default' => 'miles',
]
);
}
}

46
inc/admin/settings/api_keys.php Executable file
View File

@@ -0,0 +1,46 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Settings_Api_keys_Tab extends Opalestate_Settings_Base_Tab {
public function get_tabnav () {
}
public function get_tab_content( $key= '' ) {
return [
'id' => 'api_keys',
'opalestate_title' => esc_html__( 'API', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ $key ], ],
'show_names' => false, // Hide field names on the left
'fields' => apply_filters( 'opalestate_settings_api', [
[
'id' => 'api_keys',
'name' => esc_html__( 'API', 'opalestate-pro' ),
'type' => 'api_keys',
],
]
),
];
}
public function get_tab_fields () {
}
}

47
inc/admin/settings/base.php Executable file
View File

@@ -0,0 +1,47 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Settings_Base_Tab {
public $key;
public function __construct ( $key ='' ){
$this->key = $key;
}
public function get_tabnav () {
}
public function get_tab_content( $key= '' ) {
}
public function get_subtabs(){
}
public function get_tab_fields () {
}
public function get_subtabs_content( $subtab ) {
}
}

38
inc/admin/settings/email.php Executable file
View File

@@ -0,0 +1,38 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Settings_Email_Tab extends Opalestate_Settings_Base_Tab {
public function get_tabnav () {
}
public function get_tab_content( $key='' ) {
return [
'id' => 'options_page',
'opalestate_title' => esc_html__( 'General Settings', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ $key ], ],
'fields' => $this->get_tab_fields()
];
}
public function get_tab_fields () {
}
}

257
inc/admin/settings/general.php Executable file
View File

@@ -0,0 +1,257 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Settings_General_Tab extends Opalestate_Settings_Base_Tab {
public function get_tabnav() {
}
public function get_tab_content( $key = '' ) {
return [
'id' => 'options_page',
'opalestate_title' => esc_html__( 'General Settings', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ $key, ], ],
'fields' => $this->get_tab_fields(),
];
}
public function get_tab_fields( $key = '' ) {
$pages = opalestate_cmb2_get_post_options( [
'post_type' => 'page',
'numberposts' => -1,
] );
return apply_filters( 'opalestate_settings_general', [
[
'name' => esc_html__( 'General Settings', 'opalestate-pro' ),
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_1',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'User Management Page', 'opalestate-pro' ),
'desc' => esc_html__( 'This is page use User Management Page using for show content of management page such as profile, my properties', 'opalestate-pro' ),
'id' => 'user_management_page',
'type' => 'select',
'options' => $pages,
],
[
'name' => esc_html__( 'My Account Page', 'opalestate-pro' ),
'desc' => esc_html__( 'This is page use User login and register an account, or reset password.', 'opalestate-pro' ),
'id' => 'user_myaccount_page',
'type' => 'select',
'options' => $pages,
],
[
'name' => esc_html__( 'Enable Message Database', 'opalestate-pro' ),
'desc' => esc_html__( 'Allow User send message Contact/Equire via email and saved into database to exchange theirs message direct in User Message Management', 'opalestate-pro' ),
'id' => 'message_log',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Maximun Upload Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximun volumn size having < x MB', 'opalestate-pro' ),
'id' => 'upload_image_max_size',
'type' => 'text',
'default' => '0.5',
],
[
'name' => esc_html__( 'Maximun Upload Image Files', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximun volumn size having < x MB', 'opalestate-pro' ),
'id' => 'upload_image_max_files',
'type' => 'text',
'default' => '10',
],
[
'name' => esc_html__( 'Maximun Upload Other Size', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximun volumn size having < x MB for upload docx, pdf...', 'opalestate-pro' ),
'id' => 'upload_other_max_size',
'type' => 'text',
'default' => '0.8'
],
[
'name' => esc_html__( 'Maximun Upload Other Files', 'opalestate-pro' ),
'desc' => esc_html__( 'Set maximun volumn size having < x MB for upload docx, pdf...', 'opalestate-pro' ),
'id' => 'upload_other_max_files',
'type' => 'text',
'default' => '10',
'after_row' => '<hr>'
],
[
'name' => esc_html__( 'Agent Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'The Loop Image is an Agent that is chosen as the representative Agent in grid and list.', 'opalestate-pro' ),
'id' => 'agent_image_size',
'type' => 'select',
'default' => 'medium',
'options' => opalestate_get_featured_image_sizes(),
],
[
'name' => esc_html__( 'Agent Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'The Loop Image is an Agent that is chosen as the representative Agent in grid and list.', 'opalestate-pro' ),
'id' => 'agent_image_size',
'type' => 'select',
'default' => 'medium',
'options' => opalestate_get_featured_image_sizes(),
],
[
'name' => esc_html__( 'Loop Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'The Loop Image is an image that is chosen as the representative image in grid and list.', 'opalestate-pro' ),
'id' => 'loop_image_size',
'type' => 'select',
'default' => 'large',
'options' => opalestate_get_featured_image_sizes(),
],
[
'name' => esc_html__( 'Featured Image Size', 'opalestate-pro' ),
'desc' => esc_html__( 'The Featured Image is an image that is chosen as the representative image in single page. .', 'opalestate-pro' ),
'id' => 'featured_image_size',
'type' => 'select',
'default' => 'full',
'options' => opalestate_get_featured_image_sizes(),
'after_row' => '<em>' . esc_html__( 'To generate images with new image sizes, you can use this <a href="https://goo.gl/FuXFex" target="_blank">Force Regenerate Thumbnails</a>',
'opalestate-pro' ) . '</em>',
],
[
'name' => esc_html__( 'Minimum of Target Price For Agent', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter minimum of price for starting search agent by target', 'opalestate-pro' ),
'id' => 'search_agent_min_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 0,
],
[
'name' => esc_html__( 'Maximum of Target Price For Agent', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter maximum of price for starting search agent by target', 'opalestate-pro' ),
'id' => 'search_agent_max_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 1000000,
],
[
'name' => esc_html__( 'Single Layout Page', 'opalestate-pro' ),
'desc' => esc_html__( 'Choose layout for single property.', 'opalestate-pro' ),
'id' => 'layout',
'type' => 'select',
'options' => apply_filters( 'opalestate_single_layout_templates', [ '' => esc_html__( 'Inherit', 'opalestate-pro' ) ] ),
],
[
'name' => esc_html__( 'Currency Settings', 'opalestate-pro' ),
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_2',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Currency', 'opalestate-pro' ),
'desc' => 'Choose your currency. Note that some payment gateways have currency restrictions.',
'id' => 'currency',
'type' => 'select',
'options' => opalestate_get_currencies(),
'default' => 'USD',
],
[
'name' => esc_html__( 'Currency Position', 'opalestate-pro' ),
'desc' => 'Choose the position of the currency sign.',
'id' => 'currency_position',
'type' => 'select',
'options' => [
'before' => esc_html__( 'Before - $10', 'opalestate-pro' ),
'after' => esc_html__( 'After - 10$', 'opalestate-pro' ),
],
'default' => 'before',
],
[
'name' => esc_html__( 'Thousands Separator', 'opalestate-pro' ),
'desc' => esc_html__( 'The symbol (typically , or .) to separate thousands', 'opalestate-pro' ),
'id' => 'thousands_separator',
'type' => 'text_small',
'default' => ',',
],
[
'name' => esc_html__( 'Decimal Separator', 'opalestate-pro' ),
'desc' => esc_html__( 'The symbol (usually , or .) to separate decimal points', 'opalestate-pro' ),
'id' => 'decimal_separator',
'type' => 'text_small',
'default' => '.',
],
[
'name' => esc_html__( 'Number of Decimals', 'opalestate-pro' ),
'desc' => esc_html__( 'This sets the number of decimal points shown in displayed prices.', 'opalestate-pro' ),
'id' => 'number_decimals',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
],
'default' => 2,
],
[
'name' => esc_html__( 'Measurement Unit', 'opalestate-pro' ),
'desc' => esc_html__( 'Measurement Unit', 'opalestate-pro' ),
'id' => 'measurement_unit',
'type' => 'select',
'options' => apply_filters( 'opalestate_measurement_unit', [
'sq ft' => esc_html__( 'sq ft', 'opalestate-pro' ),
'sq m' => esc_html__( 'sq m', 'opalestate-pro' ),
'mq' => esc_html__( 'mq', 'opalestate-pro' ),
'm2' => esc_html__( 'm2', 'opalestate-pro' ),
] ),
'default' => 'sq ft',
],
[
'name' => esc_html__( 'Google Map API', 'opalestate-pro' ),
'desc' => __( 'You need to register <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">Google API Key</a>, then put the key in this setting.',
'opalestate-pro' ),
'id' => 'google_map_api_keys',
'type' => 'text',
'default' => 'AIzaSyCfMVNIa7khIqYHCw6VBn8ShUWWm4tjbG8',
],
]
);
}
}

446
inc/admin/settings/property.php Executable file
View File

@@ -0,0 +1,446 @@
<?php
/**
* Opalestate_Settings_Property_Tab
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
public function get_subtabs() {
return apply_filters(
'opalestate_settings_property_subtabs_nav',
[
'property_general' => esc_html__( 'General', 'opalestate-pro' ),
'property_search' => esc_html__( 'Search Page', 'opalestate-pro' ),
'property_detail' => esc_html__( 'Single Page', 'opalestate-pro' ),
]
);
}
public function get_subtabs_content( $key = "" ) {
$fields = apply_filters( 'opalestate_settings_property_subtabs_' . $key . '_fields', [] );
if ( $fields ) {
} else {
switch ( $key ) {
case 'property_search':
$fields = $this->get_subtab_search_fields();
break;
case 'property_detail':
$fields = $this->get_subtab_detail_fields();
break;
default:
$fields = $this->get_subtab_property_fields();
break;
}
}
return [
'id' => 'options_page',
'opalestate_title' => esc_html__( 'Property Settings', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ $key ], ],
'fields' => $fields,
];
}
private function get_subtab_property_fields() {
$fields = [];
$fields[] = [
'name' => esc_html__( 'Enable User Submission', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable to allow user post/submit properties in front-end', 'opalestate-pro' ),
'id' => 'enable_submission',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
// show setting short meta infox
$metabox = new Opalestate_Property_MetaBox();
$metas = $metabox->metaboxes_info_fields();
$checkes = [];
foreach ( $metas as $key => $field ) {
$id = str_replace( OPALESTATE_PROPERTY_PREFIX, '', $field['id'] );
$checkes [ $id ] = $field['name'];
}
$fields[] = [
'name' => esc_html__( 'Show Meta Information in Grid and Single Page', 'opalestate-pro' ),
'id' => 'show_property_meta',
'type' => 'multicheck',
'options' => $checkes,
];
$fields[] = [
'name' => esc_html__( 'Archive Grid layout', 'opalestate-pro' ),
'id' => 'property_archive_grid_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_grid_layouts(),
];
$fields[] = [
'name' => esc_html__( 'Archive List layout', 'opalestate-pro' ),
'id' => 'property_archive_list_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_list_layouts(),
];
return $fields;
}
private function get_subtab_search_fields() {
$pages = opalestate_cmb2_get_post_options( [
'post_type' => 'page',
'numberposts' => -1,
] );
$metabox = new Opalestate_Property_MetaBox();
$metas = $metabox->metaboxes_info_fields();
$fields = [];
if ( $metas ) {
$fields[] = [
'name' => esc_html__( 'User Share Search', 'opalestate-pro' ),
'desc' => esc_html__( 'Display Share Search Link Management', 'opalestate-pro' ),
'id' => 'enable_share_earch',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'User Saved Search', 'opalestate-pro' ),
'desc' => esc_html__( 'Display Save Search Link Management', 'opalestate-pro' ),
'id' => 'enable_saved_usersearch',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Search Properties Page', 'opalestate-pro' ),
'desc' => esc_html__( 'This is page to display result of properties after user searching via form.',
'opalestate-pro' ),
'id' => 'search_map_properties_page',
'type' => 'select',
'options' => opalestate_cmb2_get_post_options( [
'post_type' => 'page',
'numberposts' => -1,
] ),
'default' => '',
];
$fields[] = [
'name' => esc_html__( 'Properties Per Page', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter min of properties display in search page', 'opalestate-pro' ),
'id' => 'search_property_per_page',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
],
'default' => 9,
];
$fields[] = [
'name' => esc_html__( 'Show Featured First', 'opalestate-pro' ),
'id' => 'show_featured_first',
'desc' => esc_html__( 'Show featured first in page result, as default Newest is showed', 'opalestate-pro' ),
'type' => 'switch',
'options' => [
0 => esc_html__( 'Disable', 'opalestate-pro' ),
1 => esc_html__( 'Enable', 'opalestate-pro' ),
],
'default' => 0,
];
$fields[] = [
'name' => esc_html__( 'Minimum of Search Price', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter minimum of price for starting search', 'opalestate-pro' ),
'id' => 'search_min_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 0,
];
$fields[] = [
'name' => esc_html__( 'Maximum of Search Price', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter maximum of price for starting search', 'opalestate-pro' ),
'id' => 'search_max_price',
'type' => 'text_medium',
'attributes' => [
'type' => 'number',
],
'default' => 10000000,
];
$fields[] = [
'name' => esc_html__( 'Minimum of Search Aea', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter minimum of area for starting search', 'opalestate-pro' ),
'id' => 'search_min_area',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
],
'default' => 0,
];
$fields[] = [
'name' => esc_html__( 'Maximum of Search Aea', 'opalestate-pro' ),
'desc' => esc_html__( 'Enter maximum of area for starting search', 'opalestate-pro' ),
'id' => 'search_max_area',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
],
'default' => 1000,
];
$fields[] = [
'name' => esc_html__( 'Search Grid layout', 'opalestate-pro' ),
'id' => 'property_search_grid_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_grid_layouts(),
];
$fields[] = [
'name' => esc_html__( 'Search List layout', 'opalestate-pro' ),
'id' => 'property_search_list_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_list_layouts(),
];
$fields[] = [
'name' => esc_html__( 'Horizontal Search Fields', 'opalestate-pro' ),
'desc' => esc_html__( 'Disable or enable fields appearing in search form', 'opalestate-pro' ),
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_1',
'before_row' => '<hr>',
'after_row' => '<hr>',
];
$fields[] = [
'name' => esc_html__( 'Show Price', 'opalestate-pro' ),
'id' => OPALESTATE_PROPERTY_PREFIX . 'price_opt',
'type' => 'switch',
'options' => [
0 => esc_html__( 'Disable', 'opalestate-pro' ),
1 => esc_html__( 'Enable', 'opalestate-pro' ),
],
];
foreach ( $metas as $key => $meta ) {
$fields[] = [
'name' => $meta['name'],
'id' => $meta['id'] . '_opt',
'type' => 'switch',
'options' => [
0 => esc_html__( 'Disable', 'opalestate-pro' ),
1 => esc_html__( 'Enable', 'opalestate-pro' ),
],
];
}
$fields[] = [
'name' => esc_html__( 'Vertical Search Fields', 'opalestate-pro' ),
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_2',
'before_row' => '<hr>',
'after_row' => '<hr>',
];
$fields[] = [
'name' => esc_html__( 'Show Price', 'opalestate-pro' ),
'id' => OPALESTATE_PROPERTY_PREFIX . 'price_opt_v',
'type' => 'switch',
'options' => [
0 => esc_html__( 'Disable', 'opalestate-pro' ),
1 => esc_html__( 'Enable', 'opalestate-pro' ),
],
];
foreach ( $metas as $key => $meta ) {
$fields[] = [
'name' => $meta['name'],
'id' => $meta['id'] . '_opt_v',
'type' => 'switch',
'options' => [
0 => esc_html__( 'Disable', 'opalestate-pro' ),
1 => esc_html__( 'Enable', 'opalestate-pro' ),
],
];
}
}
return $fields;
}
/**
*
*/
private function get_subtab_detail_fields() {
$fields = [];
$fields[] = [
'name' => esc_html__( 'Show Amenities tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Amenities tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_amenities',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Facilities tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Facilities tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_facilities',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Attachments tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Attachments tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_attachments',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Video tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Video tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_video',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Map tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Map tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_map',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Nearby tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Nearby tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_nearby',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Walk Scores tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Walk Scores tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_walkscores',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Apartments tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Apartments tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_apartments',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Floor Plans tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Floor Plans tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_floor_plans',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Views Statistics tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Views Statistics tab in the single property page.', 'opalestate-pro' ),
'id' => 'enable_single_views_statistics',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Views Statistics time limit (days)', 'opalestate-pro' ),
'desc' => esc_html__( 'The number of days will be saved to the database.', 'opalestate-pro' ),
'id' => 'single_views_statistics_limit',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
'min' => 1,
'max' => 365,
],
'default' => 8,
];
$fields[] = [
'name' => esc_html__( 'Related properties layout', 'opalestate-pro' ),
'desc' => esc_html__( 'Select a layout for related properties.', 'opalestate-pro' ),
'id' => 'single_related_properties_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_layouts(),
];
$fields[] = [
'name' => esc_html__( 'Nearby properties layout', 'opalestate-pro' ),
'desc' => esc_html__( 'Select a layout for nearby properties.', 'opalestate-pro' ),
'id' => 'single_nearby_properties_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_layouts(),
];
return $fields;
}
}

348
inc/admin/views/addons/list.php Executable file
View File

@@ -0,0 +1,348 @@
<div class="wrap" id="opalestate-add-ons">
<h1><?php esc_html_e( 'Opal Estate Add-ons', 'opalestate-pro' ); ?></h1>
<p><?php esc_html_e( 'The following Add-ons extend the functionality of Opal Estate.', 'opalestate-pro' ); ?></p>
<?php
$tag = apply_filters( 'opalestate_addons_tag', 'opalestate_addon' );
if ( ! function_exists( 'plugins_api' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
}
$plugins_api = plugins_api( 'query_plugins', [
'tag' => $tag,
] );
if ( ! is_wp_error( $plugins_api ) ) {
$plugins = $plugins_api->plugins;
$plugins_allowedtags = [
'a' => [
'href' => [],
'title' => [],
'target' => [],
],
'abbr' => [ 'title' => [] ],
'acronym' => [ 'title' => [] ],
'code' => [],
'pre' => [],
'em' => [],
'strong' => [],
'ul' => [],
'ol' => [],
'li' => [],
'p' => [],
'br' => [],
];
$plugins_group_titles = [
'Performance' => _x( 'Performance', 'Plugin installer group title' ),
'Social' => _x( 'Social', 'Plugin installer group title' ),
'Tools' => _x( 'Tools', 'Plugin installer group title' ),
];
$group = null;
?>
<?php if ( $plugins ) : ?>
<div id="the-list">
<?php foreach ( $plugins as $plugin ) : ?>
<?php
if ( is_object( $plugin ) ) {
$plugin = (array) $plugin;
}
// Display the group heading if there is one
if ( isset( $plugin['group'] ) && $plugin['group'] != $group ) {
if ( isset( $this->groups[ $plugin['group'] ] ) ) {
$group_name = $this->groups[ $plugin['group'] ];
if ( isset( $plugins_group_titles[ $group_name ] ) ) {
$group_name = $plugins_group_titles[ $group_name ];
}
} else {
$group_name = $plugin['group'];
}
// Starting a new group, close off the divs of the last one
if ( ! empty( $group ) ) {
echo '</div></div>';
}
echo '<div class="plugin-group"><h3>' . esc_html( $group_name ) . '</h3>';
// needs an extra wrapping div for nth-child selectors to work
echo '<div class="plugin-items">';
$group = $plugin['group'];
}
$title = wp_kses( $plugin['name'], $plugins_allowedtags );
// Remove any HTML from the description.
$description = strip_tags( $plugin['short_description'] );
$version = wp_kses( $plugin['version'], $plugins_allowedtags );
$name = strip_tags( $title . ' ' . $version );
$author = wp_kses( $plugin['author'], $plugins_allowedtags );
if ( ! empty( $author ) ) {
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
}
$requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
$requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );
$tested_wp = ( empty( $plugin['tested'] ) || version_compare( get_bloginfo( 'version' ), $plugin['tested'], '<=' ) );
$action_links = [];
if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
$status = install_plugin_install_status( $plugin );
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] ) {
if ( $compatible_php && $compatible_wp ) {
$action_links[] = sprintf(
'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
esc_attr( $name ),
__( 'Install Now' )
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Cannot Install', 'plugin' )
);
}
}
break;
case 'update_available':
if ( $status['url'] ) {
if ( $compatible_php && $compatible_wp ) {
$action_links[] = sprintf(
'<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
esc_attr( $status['file'] ),
esc_attr( $plugin['slug'] ),
esc_url( $status['url'] ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'Update %s now' ), $name ) ),
esc_attr( $name ),
__( 'Update Now' )
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Cannot Update', 'plugin' )
);
}
}
break;
case 'latest_installed':
case 'newer_installed':
if ( is_plugin_active( $status['file'] ) ) {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Active', 'plugin' )
);
} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
$button_text = __( 'Activate' );
/* translators: %s: plugin name */
$button_label = _x( 'Activate %s', 'plugin' );
$activate_url = add_query_arg(
[
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
'action' => 'activate',
'plugin' => $status['file'],
],
network_admin_url( 'plugins.php' )
);
if ( is_network_admin() ) {
$button_text = __( 'Network Activate' );
/* translators: %s: plugin name */
$button_label = _x( 'Network Activate %s', 'plugin' );
$activate_url = add_query_arg( [ 'networkwide' => 1 ], $activate_url );
}
$action_links[] = sprintf(
'<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>',
esc_url( $activate_url ),
esc_attr( sprintf( $button_label, $plugin['name'] ) ),
$button_text
);
} else {
$action_links[] = sprintf(
'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
_x( 'Installed', 'plugin' )
);
}
break;
}
}
$details_link = self_admin_url(
'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
'&amp;TB_iframe=true&amp;width=600&amp;height=550'
);
$action_links[] = sprintf(
'<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
esc_url( $details_link ),
/* translators: %s: plugin name and version */
esc_attr( sprintf( __( 'More information about %s' ), $name ) ),
esc_attr( $name ),
__( 'More Details' )
);
if ( ! empty( $plugin['icons']['svg'] ) ) {
$plugin_icon_url = $plugin['icons']['svg'];
} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
$plugin_icon_url = $plugin['icons']['2x'];
} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
$plugin_icon_url = $plugin['icons']['1x'];
} else {
$plugin_icon_url = $plugin['icons']['default'];
}
/**
* Filters the install action links for a plugin.
*
* @param string[] $action_links An array of plugin action links. Defaults are links to Details and Install Now.
* @param array $plugin The plugin currently being listed.
* @since 2.7.0
*
*/
$action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
$last_updated_timestamp = strtotime( $plugin['last_updated'] );
?>
<div class="plugin-card plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
<?php
if ( ! $compatible_php || ! $compatible_wp ) {
echo '<div class="notice inline notice-error notice-alt"><p>';
if ( ! $compatible_php && ! $compatible_wp ) {
_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.' );
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
printf(
/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
self_admin_url( 'update-core.php' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
} elseif ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
} elseif ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
}
} elseif ( ! $compatible_wp ) {
_e( 'This plugin doesn&#8217;t work with your version of WordPress.' );
if ( current_user_can( 'update_core' ) ) {
printf(
/* translators: %s: "Update WordPress" screen URL */
' ' . __( '<a href="%s">Please update WordPress</a>.' ),
self_admin_url( 'update-core.php' )
);
}
} elseif ( ! $compatible_php ) {
_e( 'This plugin doesn&#8217;t work with your version of PHP.' );
if ( current_user_can( 'update_php' ) ) {
printf(
/* translators: %s: "Update PHP" page URL */
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
esc_url( wp_get_update_php_url() )
);
wp_update_php_annotation( '</p><p><em>', '</em>' );
}
}
echo '</p></div>';
}
?>
<div class="plugin-card-top">
<div class="name column-name">
<h3>
<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
<?php echo $title; ?>
<img src="<?php echo esc_attr( $plugin_icon_url ); ?>" class="plugin-icon" alt="">
</a>
</h3>
</div>
<div class="action-links">
<?php
if ( $action_links ) {
echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
}
?>
</div>
<div class="desc column-description">
<p><?php echo $description; ?></p>
<p class="authors"><?php echo $author; ?></p>
</div>
</div>
<div class="plugin-card-bottom">
<div class="vers column-rating">
<?php
wp_star_rating(
[
'rating' => $plugin['rating'],
'type' => 'percent',
'number' => $plugin['num_ratings'],
]
);
?>
<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?>)</span>
</div>
<div class="column-updated">
<strong><?php _e( 'Last Updated:' ); ?></strong> <?php printf( __( '%s ago' ), human_time_diff( $last_updated_timestamp ) ); ?>
</div>
<div class="column-downloaded">
<?php
if ( $plugin['active_installs'] >= 1000000 ) {
$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
$active_installs_text = sprintf(
_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
number_format_i18n( $active_installs_millions )
);
} elseif ( 0 == $plugin['active_installs'] ) {
$active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
} else {
$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
}
printf( __( '%s Active Installations' ), $active_installs_text );
?>
</div>
<div class="column-compatibility">
<?php
if ( ! $tested_wp ) {
echo '<span class="compatibility-untested">' . __( 'Untested with your version of WordPress' ) . '</span>';
} elseif ( ! $compatible_wp ) {
echo '<span class="compatibility-incompatible">' . __( '<strong>Incompatible</strong> with your version of WordPress' ) . '</span>';
} else {
echo '<span class="compatibility-compatible">' . __( '<strong>Compatible</strong> with your version of WordPress' ) . '</span>';
}
?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
} else {
echo '<div class="error"><p>' . esc_html__( 'There was an error retrieving the Opalestate Add-ons list from the server. Please try again later.', 'opalestate-pro' ) . '</div>';
}
?>
</div>

View File

@@ -0,0 +1,482 @@
<?php
/**
* Opalestate_Agency_Front
*
* @author Opal Team <info@wpopal.com >
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Opalestate_Agency_Front {
/**
* Instance.
*
* @access private
* @var Opalestate_Agent_Front
*/
static private $instance;
/**
* Singleton pattern.
*
* @since $Id
* @access private
*/
private function __construct() {
}
/**
* Get instance.
*
* @return Opalestate_Agent_Front
* @since $Id
* @access public
*/
public static function get_instance() {
if ( null === static::$instance ) {
self::$instance = new static();
self::$instance->init();
}
return self::$instance;
}
public $new_attachmenet_ids;
/**
* Auto update meta information to post from user data updated or created
*/
public function init() {
add_action( 'opalestate_on_set_role_agency', [ $this, 'on_set_role' ], 1, 9 );
add_filter( 'opalestate_before_render_profile_agency_form', [ $this, 'render_front_form' ], 2, 2 );
add_action( 'save_post', [ $this, 'on_save_post' ], 13, 2 );
add_filter( 'pre_get_posts', [ $this, 'archives_query' ], 1 );
add_action( 'cmb2_after_init', [ $this, 'on_save_front_data' ] );
add_filter( 'opalestate_management_user_menu', [ $this, 'render_extra_profile_link' ] );
add_action( "opalestate_user_content_agency_profile_page", [ $this, 'render_profile' ] );
add_action( "opalestate_user_content_agency_team_page", [ $this, 'render_team' ] );
add_action( "opalestate_user_init", [ $this, 'process_action_member' ] );
$this->register_shortcodes();
}
/**
*
*/
public function render_extra_profile_link( $menu ) {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift( $user_roles );
if ( $user_role == 'opalestate_agency' ) {
$menu['agency_profile'] = [
'icon' => 'fa fa-user',
'link' => "agency_profile",
'title' => esc_html__( 'Agency Profile', 'opalestate-pro' ),
'id' => 0,
];
$menu['agency_team'] = [
'icon' => 'fa fa-users',
'link' => "agency_team",
'title' => esc_html__( 'Agency Team', 'opalestate-pro' ),
'id' => 0,
];
}
return $menu;
}
/**
* Auto update meta information to post from user data updated or created
*/
public function archives_query( $query ) {
if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agency' ) ) {
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query = [];
$tax_query[] = [
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
$query->set( 'tax_query', $tax_query );
}
if ( isset( $_GET['search_text'] ) ) {
$query->set( 's', sanitize_text_field( $_GET['search_text'] ) );
}
}
return $query;
}
/**
*
*/
private function update_data_agent_or_agency( $prefix ) {
global $current_user;
$post_id = isset( $_POST['object_id'] ) && absint( $_POST['object_id'] ) ? $_POST['object_id'] : 0;
$user_id = get_current_user_id();
$metaboxes = apply_filters( 'opalestate_before_render_profile_agency_form', [], $post_id );
$metaboxes = apply_filters( 'cmb2_meta_boxes', $metaboxes );
if ( isset( $metaboxes[ $prefix . 'front' ] ) ) {
if ( ! empty( $post_id ) ) {
$old_post = get_post( $post_id );
$post_date = $old_post->post_date;
} else {
$post_date = '';
}
$post = get_post( $post_id );
$data = [
'ID' => $post->ID ? $post_id : null,
'post_title' => sanitize_text_field( $_POST[ $prefix . 'title' ] ),
'post_author' => $user_id,
'post_type' => 'opalestate_agency',
'post_date' => $post_date,
'post_content' => wp_kses( $_POST[ $prefix . 'text' ], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ),
];
unset( $_POST[ $prefix . 'title' ] );
unset( $_POST[ $prefix . 'text' ] );
if ( $data['ID'] > 0 ) {
$post_id = wp_update_post( $data, true );
} else {
$data['post_status'] = 'pending';
$post_id = wp_insert_post( $data, true );
}
$post = get_post( $post_id );
if ( empty( $post->post_content ) || empty( $post->post_title ) || ! has_post_thumbnail( $post_id ) ) {
// $data['post_status'] = 'public';
// $data['ID'] = $post_id;
// $post_id = wp_update_post( $data , true );
}
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
/*
* Processing upload files
*/
$this->process_upload_files( $post_id, $_POST );
cmb2_get_metabox_form( $metaboxes[ $prefix . 'front' ], $post_id );
$cmb = cmb2_get_metabox( $prefix . 'front', $post_id );
$sanitized_values = $cmb->get_sanitized_values( $_POST );
$cmb->save_fields( $post_id, 'post', $sanitized_values );
/// update
// Create featured image
$featured_image = get_post_meta( $post_id, $prefix . 'featured_image', true );
if ( ! empty( $_POST[ $prefix . 'featured_image' ] ) && isset( $_POST[ $prefix . 'featured_image' ] ) ) {
set_post_thumbnail( $post_id, sanitize_text_field( $_POST[ $prefix . 'featured_image' ] ) );
unset( $_POST[ $prefix . 'featured_image' ] );
} else {
delete_post_thumbnail( $post_id );
}
// set ready of attachment for use.
if ( $this->new_attachmenet_ids ) {
foreach ( $this->new_attachmenet_ids as $_id ) {
delete_post_meta( $_id, '_pending_to_use_', 1 );
}
}
return $post_id;
}
return false;
}
/**
*
*
*/
private function get_field_name( $field ) {
return OPALESTATE_AGENCY_PREFIX . $field;
}
private function process_upload_files( $post_id ) {
//upload images for featured and gallery images
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
///
$fields = [
$this->get_field_name( 'avatar_id' ),
$this->get_field_name( 'gallery' ),
$this->get_field_name( 'featured_image' ),
];
foreach ( $_FILES as $key => $value ) {
// allow processing in fixed collection
if ( in_array( $key, $fields ) ) {
$ufile = $_FILES[ $key ];
/// /////
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
$output = [];
foreach ( $ufile['name'] as $f_key => $f_value ) {
$loop_file = [
'name' => $ufile['name'][ $f_key ],
'type' => $ufile['type'][ $f_key ],
'tmp_name' => $ufile['tmp_name'][ $f_key ],
'error' => $ufile['error'][ $f_key ],
'size' => $ufile['size'][ $f_key ],
];
$new_atm = $this->upload_image( $loop_file, $post_id );
if ( $new_atm ) {
$_POST[ $key ] = isset( $_POST[ $key ] ) ? sanitize_text_field( $_POST[ $key ] ) : [];
$_POST[ $key ][ $new_atm['attachment_id'] ] = $new_atm['url'];
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
} ///
elseif ( isset( $ufile['name'] ) ) {
$new_atm = $this->upload_image( $ufile, $post_id );
if ( $new_atm ) {
$_POST[ $key ] = $new_atm['attachment_id'];
if ( preg_match( "#id#", $key ) ) {
$_key = str_replace( "_id", "", $key );
$_POST[ $_key ] = $new_atm['url'];
}
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
}
}
}
}
/**
* Process upload images for properties
*/
public function upload_image( $submitted_file, $parent_id = 0 ) {
return opalesate_upload_image( $submitted_file, $parent_id );
}
public function on_save_front_data() {
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENCY_PREFIX . 'front' ] ) ) {
$post_id = isset( $_POST['object_id'] ) && $_POST['object_id'] ? absint( $_POST['object_id'] ) : 0;
$post = get_post( $post_id );
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENCY_PREFIX );
if ( $post_id ) {
OpalEstate_Agency::update_user_data( get_current_user_id() );
}
return opalestate_output_msg_json( true,
__( 'The data updated successful, please wait for redirecting', 'opalestate-pro' ),
[
'heading' => esc_html__( 'Update Information', 'opalestate-pro' ),
'redirect' => opalestate_get_user_management_page_uri( [ 'tab' => 'agency_profile' ] ),
]
);
return opalestate_output_msg_json( false,
__( 'Currently, The data could not save!', 'opalestate-pro' ),
[ 'heading' => esc_html__( 'Update Information', 'opalestate-pro' ) ]
);
}
}
/**
*
*/
public function register_shortcodes() {
}
/**
*
*/
public function render_profile() {
$post_id = OpalEstate_User::get_member_id();
if ( isset( $post->ID ) && $post->post_status != 'publish' ) {
opalestate_add_notice( "warning", esc_html__( 'You account is under reviewing! it take some time to process' ) );
add_action( "opalestate_profile_agency_form_before", "opalestate_print_notices" );
}
$metaboxes = $this->render_front_form( [], $post_id );
return opalestate_load_template_path( 'user/agency/profile-agency', [ 'metaboxes' => $metaboxes, 'post_id' => $post_id ] );
}
/**
*
*/
public function render_team() {
$user_id = get_current_user_id();
$post_id = OpalEstate_User::get_member_id();
$metaboxes = $this->render_front_form( [], $post_id );
return opalestate_load_template_path( 'user/agency/agency-team', [ 'metaboxes' => $metaboxes, 'post_id' => $post_id ] );
}
/**
*
*/
public function process_action_member() {
if ( isset( $_POST['add_team_action'] ) && wp_verify_nonce( $_POST['add_team_action'], 'agency-add-member' ) ) {
if ( isset( $_POST['user_id'] ) ) {
$user_id = get_current_user_id();
$post_id = OpalEstate_User::get_member_id();
$team = get_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
if ( empty( $team ) ) {
$team = [];
}
$team[] = intval( $_POST['user_id'] );
$team = array_unique( $team );
update_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', $team );
}
}
if ( isset( $_GET['tab'] ) && $_GET['tab'] == "agency_team" && isset( $_GET['remove_id'] ) && $_GET['remove_id'] ) {
$remove_id = intval( $_GET['remove_id'] );
$user_id = get_current_user_id();
$post_id = OpalEstate_User::get_member_id();
$team = get_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
if ( empty( $team ) ) {
$team = [];
}
$team[] = $user_id;
$team = array_unique( $team );
foreach ( $team as $key => $id ) {
if ( $id == $remove_id ) {
unset( $team[ $key ] );
}
}
update_post_meta( $post_id, OPALESTATE_AGENCY_PREFIX . 'team', $team );
wp_redirect( opalestate_get_user_management_page_uri( [ 'tab' => 'agency_team' ] ) );
die;
}
}
/**
*
*/
public static function on_save_post( $post_id ) {
$post_type = get_post_type( $post_id );
if ( $post_type == 'opalestate_agency' ) {
if ( isset( $_POST[ OPALESTATE_AGENCY_PREFIX . 'user_id' ] ) && $_POST[ OPALESTATE_AGENCY_PREFIX . 'user_id' ] ) {
update_user_meta( $_POST[ OPALESTATE_AGENCY_PREFIX . 'user_id' ], OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
}
}
}
public static function on_set_role( $user_id ) {
if ( $user_id ) {
$args = [
'post_type' => 'opalestate_agency',
'posts_per_page' => 10,
];
$args['meta_key'] = OPALESTATE_AGENCY_PREFIX . 'user_id';
$args['meta_value'] = $user_id;
$args['meta_compare'] = '=';
$args['post_status'] = [ 'publish', 'pending' ];
$post = get_posts( $args );
if ( empty( $post ) ) {
$agency_id = self::create_agency( [], $user_id );
update_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'user_id', $user_id );
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $agency_id );
}
}
}
/**
*
*/
public static function create_agency( $args = [], $user_id ) {
$data = get_user_by( 'id', $user_id );
$args = wp_parse_args( $args, [
'first_name' => $data->first_name,
'last_name' => $data->last_name,
'avatar' => '',
'job' => '',
'email' => '',
'phone' => '',
'mobile' => '',
'fax' => '',
'web' => '',
'address' => '',
'twitter' => '',
'facebook' => '',
'google' => '',
'linkedin' => '',
'instagram' => '',
] );
$agency_id = wp_insert_post( [
'post_title' => $args['first_name'] && $args['last_name'] ? $args['first_name'] . ' ' . $args['last_name'] : esc_html__( 'User ID', 'opalestate-pro' ) . ': ' . $user_id,
'post_content' => 'empty description',
'post_excerpt' => 'empty excerpt',
'post_type' => 'opalestate_agency',
'post_status' => 'pending',
'post_author' => $user_id,
], true );
do_action( 'opalesate_insert_user_agency', $agency_id );
return $agency_id;
}
/**
*
*/
public function render_front_form( $metaboxes, $post_id = 0 ) {
$metabox = new Opalestate_Agency_MetaBox();
return $metabox->render_front_form( $metaboxes, $post_id );
}
}
Opalestate_Agency_Front::get_instance();

View File

@@ -0,0 +1,389 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Agency_MetaBox extends Opalestate_User_MetaBox {
/**
*
*/
public function metaboxes_target() {
$prefix = OPALESTATE_AGENCY_PREFIX;
$fields = [
[
'id' => "{$prefix}user_id",
'name' => esc_html__( 'Link To User ID', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Set relationship to existed user, allow user can edit Agency profile in front-end and show account info in each property.', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Agent Team', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
'id' => $prefix . "team",
'type' => 'adduser',
],
];
return $fields;
}
/**
*
*/
public function metaboxes_admin_fields( $prefix = '' ) {
if ( ! $prefix ) {
$prefix = OPALESTATE_AGENCY_PREFIX;
}
$fields = [
[
'id' => "{$prefix}featured",
'name' => esc_html__( 'Is Featured', 'opalestate-pro' ),
'type' => 'switch',
'description' => esc_html__( 'Set this agent as featured', 'opalestate-pro' ),
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
],
];
$fields = array_merge_recursive( $fields,
$this->get_base_fields( $prefix ),
$this->get_address_fields( $prefix )
);
return apply_filters( 'opalestate_postype_agency_metaboxes_fields', $fields );
}
/**
*
*/
public function get_front_fields( $prefix ) {
return [
'id' => $prefix . 'front',
'title' => esc_html__( 'Name and Description', 'opalestate-pro' ),
'object_types' => [ 'opalestate_property' ],
'context' => 'normal',
'object_types' => [ 'user' ], // Tells CMB2 to use user_meta vs post_meta
'priority' => 'high',
'show_names' => true,
'fields' => $this->get_fields( $prefix ),
];
}
/**
*
*/
public function get_fields( $prefix ) {
$management = [
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar',
'type' => is_admin() ? 'file' : 'opal_upload',
'avatar' => true,
'before_row' => '<div class="' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> <div class="col-lg-4">',
'after_row' => '</div>',
],
[
'id' => 'first_name',
'name' => esc_html__( 'First Name', 'opalestate-pro' ),
'type' => 'text',
'attributes' => [
'required' => 'required',
],
'before_row' => '<div class="col-lg-8">',
],
[
'id' => 'last_name',
'name' => esc_html__( 'Last Name', 'opalestate-pro' ),
'type' => 'text',
'attributes' => [
'required' => 'required',
],
],
[
'id' => 'description',
'name' => esc_html__( 'Biographical Info', 'opalestate-pro' ),
'type' => 'textarea',
'description' => esc_html__( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'opalestate-pro' ),
'after_row' => '</div></div>',
],
[
'id' => "{$prefix}job",
'name' => esc_html__( 'Title/Job', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Please enter position or job in your company.', 'opalestate-pro' ),
'before_row' => '<div class="clearfix clear"></div><hr><div class="row-group-features group-has-two clearfix"><h3>' . __( 'Information', 'opalestate-pro' ) . '</h3>', // callback
],
[
'id' => "{$prefix}company",
'name' => esc_html__( 'company', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Please enter company name.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}email",
'name' => esc_html__( 'Contact email', 'opalestate-pro' ),
'type' => 'text_email',
'description' => esc_html__( 'Enter contact name that allow user contact you via the contact form of website.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}phone",
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Enter your home phone.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}skype",
'name' => esc_html__( 'Skype', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Input for skype account.', 'opalestate-pro' ),
],
[
'id' => "url",
'name' => esc_html__( 'Website URL', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Link to your website', 'opalestate-pro' ),
'after_row' => '</div>',
],
[
'id' => "{$prefix}facebook",
'name' => esc_html__( 'Facebook', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Enter your facebook profile or facebook newfeed', 'opalestate-pro' ),
'before_row' => '<div class="row-group-features group-has-two group-price clearfix"><h3>' . __( 'Social', 'opalestate-pro' ) . '</h3>', // callback
],
[
'id' => "{$prefix}linkedin",
'name' => esc_html__( 'Linkedin URL', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Input for linked in profile.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}instagram",
'name' => esc_html__( 'Instagram URL', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Input for instagram profile.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}pinterest",
'name' => esc_html__( 'Pinterest Url', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Input for pinterest feed', 'opalestate-pro' ),
],
[
'id' => "{$prefix}googleplus",
'name' => esc_html__( 'Google Plus Url', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Input for goolge plus profile or your newfeed.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}youtube",
'name' => esc_html__( 'Youtube Url', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Input for your channel youtube.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}vimeo",
'name' => esc_html__( 'Vimeo Url', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Input for your channel Vimeo', 'opalestate-pro' ),
'after_row' => '</div>',
],
];
return $management;
}
/**
*
*/
public function metaboxes_front_fields( $prefix = '', $post_id = 0 ) {
if ( ! $prefix ) {
$prefix = OPALESTATE_AGENCY_PREFIX;
}
$post = get_post( $post_id );
$fields = [
[
'id' => $prefix . 'post_type',
'type' => 'hidden',
'default' => 'opalestate_agency',
],
[
'id' => 'post_id',
'type' => 'hidden',
'default' => $post_id,
],
[
'name' => esc_html__( 'Title / Name', 'opalestate-pro' ),
'id' => $prefix . 'title',
'type' => 'text',
'default' => ! empty( $post ) ? $post->post_title : '',
'attributes' => [
'required' => 'required',
],
],
[
'name' => esc_html__( 'slogan', 'opalestate-pro' ),
'id' => "{$prefix}slogan",
'type' => 'text',
],
[
'name' => esc_html__( 'Information', 'opalestate-pro' ),
'id' => $prefix . 'text',
'type' => 'wysiwyg',
'default' => ! empty( $post ) ? $post->post_content : '',
'attributes' => [
'required' => 'required',
],
],
[
'name' => esc_html__( 'Types', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
'id' => $prefix . "type",
'taxonomy' => 'opalestate_types',
'type' => 'taxonomy_select',
]
];
$fields = array_merge_recursive( $fields,
$this->get_base_front_fields( $prefix ),
$this->get_address_fields( $prefix ),
$this->get_social_fields( $prefix )
);
return apply_filters( 'opalestate_postype_office_metaboxes_fields', $fields );
}
public function get_base_front_fields( $prefix ) {
return [
[
'id' => "{$prefix}featured_image",
'name' => esc_html__( 'Banner', 'opalestate-pro' ),
'type' => 'uploader',
'is_featured' => true,
'limit' => 1,
'single' => 1,
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
'before_row' => '<hr>',
],
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar',
'type' => 'hidden',
'single' => 1,
'limit' => 1,
'avatar' => true,
],
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar_id',
'type' => 'uploader',
'single' => 1,
'limit' => 1,
'avatar' => true,
],
[
'name' => esc_html__( 'Gallery', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
'id' => $prefix . "gallery",
'type' => 'uploader',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Email', 'opalestate-pro' ),
'id' => "{$prefix}email",
'type' => 'text',
'before_row' => '<div class="field-row-2">',
],
[
'name' => esc_html__( 'Website', 'opalestate-pro' ),
'id' => "{$prefix}web",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'id' => "{$prefix}phone",
'type' => 'text',
],
[
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
'id' => "{$prefix}mobile",
'type' => 'text',
],
[
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
'id' => "{$prefix}fax",
'type' => 'text',
'after_row' => '</div>',
],
];
}
/**
*
*/
public function render_front_form( $metaboxes, $post_id = 0 ) {
$prefix = OPALESTATE_AGENCY_PREFIX;
$metaboxes[ $prefix . 'front' ] = [
'id' => $prefix . 'front',
'title' => esc_html__( 'Agency Information', 'opalestate-pro' ),
'object_types' => [ 'opalestate_agency' ],
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'cmb_styles' => false,
'fields' => $this->metaboxes_front_fields( $prefix, $post_id ),
];
return $metaboxes;
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Opalestate_PostType_Agency
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2016 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Opalestate_PostType_Agency
*
* @version 1.0
*/
class Opalestate_PostType_Agency {
/**
* Init
*/
public static function init() {
add_action( 'init', [ __CLASS__, 'definition' ] );
}
/**
* Register Post type and taxonomies
*/
public static function definition() {
if ( ! is_blog_installed() || post_type_exists( 'opalestate_agency' ) ) {
return;
}
$labels = [
'name' => esc_html__( 'Agencies', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Property', 'opalestate-pro' ),
'add_new' => esc_html__( 'Add New Agency', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Agency', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Agency', 'opalestate-pro' ),
'new_item' => esc_html__( 'New Agency', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Agencies', 'opalestate-pro' ),
'view_item' => esc_html__( 'View Agency', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Agency', 'opalestate-pro' ),
'not_found' => esc_html__( 'No Agencies found', 'opalestate-pro' ),
'not_found_in_trash' => esc_html__( 'No Agencies found in Trash', 'opalestate-pro' ),
'parent_item_colon' => '',
'menu_name' => esc_html__( 'Agencies', 'opalestate-pro' ),
];
$labels = apply_filters( 'opalestate_postype_agency_labels', $labels );
register_post_type( 'opalestate_agency',
apply_filters( 'opalestate_agency_post_type_parameters', [
'labels' => $labels,
'supports' => [ 'title', 'editor', 'thumbnail', 'comments', 'author', 'excerpt' ],
'public' => true,
'has_archive' => true,
'menu_position' => 51,
'categories' => [],
'menu_icon' => 'dashicons-groups',
'rewrite' => [ 'slug' => esc_html_x( 'agency', 'agency slug', 'opalestate-pro' ) ],
] )
);
///
$labels = [
'name' => esc_html__( 'Agency Categories', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Category', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Category', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Categories', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Category', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Category:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Category', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Category', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Category', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Category Name', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Agency Categories', 'opalestate-pro' ),
];
///
register_taxonomy( 'opalestate_agency_cat', [ 'opalestate_agency' ],
[
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_nav_menus' => true,
'rewrite' => [
'slug' => esc_html_x( 'agency-category', 'agency category slug', 'opalestate-pro' ),
],
] );
}
}
Opalestate_PostType_Agency::init();

View File

@@ -0,0 +1,20 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package $package$
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2014 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
class Opalestate_Agency_Query extends OpalEstate_Abstract_Query {
}

View File

@@ -0,0 +1,306 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Agency
*
* @version 1.0
*/
class OpalEstate_Agency {
/**
* @var String $author_name
*
* @access protected
*/
protected $author_name;
/**
* @var Boolean $is_featured
*
* @access protected
*/
protected $is_featured;
/**
* Get A Instance Of Opalestate_Property
*/
public static function get_instance( $post_id = null ) {
static $_instance;
if ( ! $_instance ) {
$_instance = new OpalEstate_Agency( $post_id );
}
return $_instance;
}
/**
* Constructor
*/
public function __construct( $post_id = null ) {
global $post;
$this->post = $post;
$this->post_id = $post_id ? $post_id : get_the_ID();
$this->author = get_userdata( $post->post_author );
$this->author_name = ! empty( $this->author ) ? sprintf( '%s %s', $this->author->first_name, $this->author->last_name ) : null;
$this->is_featured = $this->get_meta( 'featured' );
$this->is_trusted = $this->get_meta( 'trusted' );
}
public function get_id() {
return $this->post_id;
}
/**
* Get Collection Of soicals with theirs values
*/
public function get_socials() {
$socials = [
'facebook' => '',
'twitter' => '',
'pinterest' => '',
'google' => '',
'instagram' => '',
'linkedIn' => '',
];
$output = [];
foreach ( $socials as $social => $k ) {
$data = $this->get_meta( $social );
if ( $data && $data != "#" && ! empty( $data ) ) {
$output[ $social ] = $data;
}
}
return $output;
}
/**
* Get url of user avatar by agency id
*/
public static function get_avatar_url( $userID ) {
return get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . "avatar", true );
}
/**
* Render list of levels of agency
*/
public function render_level() {
$levels = wp_get_post_terms( $this->post_id, 'opalestate_agency_cat' );
if ( empty( $levels ) ) {
return;
}
$output = '<span class="agency-levels">';
foreach ( $levels as $key => $value ) {
$output .= '<span class="agency-label"><span>' . $value->name . '</span></span>';
}
$output .= '</span>';
echo $output;
}
/**
* get meta data value of key without prefix
*/
public function get_meta( $key ) {
return get_post_meta( $this->get_id(), OPALESTATE_AGENCY_PREFIX . $key, true );
}
/**
* return true if this agency is featured
*/
public function is_featured() {
return $this->is_featured;
}
public function render_avatar() {
}
/**
* render block information by id
*/
public static function render_box_info( $post_id ) {
}
public function get_gallery() {
return $this->get_meta( 'gallery' );
}
public function get_trusted() {
return $this->is_trusted;
}
public function get_members() {
$team = [];
$ids = get_post_meta( $this->post_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
foreach ( $ids as $id ) {
$user = get_user_by( 'id', $id ); // echo '<pre>' . print_r( $user, 1 );die;
$team[] = [
'id' => $user->ID,
'name' => $user->display_name,
'avatar_url' => OpalEstate_User::get_author_picture( $user->ID ),
'username' => $user->user_login,
'description' => 'okokok',
];
}
return $team;
}
public static function get_link( $agency_id ) {
$agency = get_post( $agency_id );
$url = self::get_avatar_url( $agency_id );
return [
'name' => $agency->post_title,
'avatar' => $url,
'link' => get_permalink( $agency->ID ),
];
}
public static function metaboxes_fields() {
$metabox = new Opalestate_Agency_MetaBox();
$fields = $metabox->metaboxes_admin_fields();
return array_merge_recursive( $fields, $metabox->get_social_fields( OPALESTATE_AGENCY_PREFIX ) );
}
/**
* Get rating count.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return int
*/
public function get_rating_counts() {
return $this->get_meta( 'rating_count' ) ? $this->get_meta( 'rating_count' ) : 0;
}
/**
* Get average rating.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return float
*/
public function get_average_rating() {
return $this->get_meta( 'average_rating' ) ? $this->get_meta( 'average_rating' ) : 0;
}
/**
* Get review count.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return int
*/
public function get_review_count() {
return $this->get_meta( 'review_count' ) ? $this->get_meta( 'review_count' ) : 0;
}
public function get_rating_count_stats() {
return $this->get_meta( 'rating_count_stats' ) ? $this->get_meta( 'rating_count_stats' ) : [
5 => 0,
4 => 0,
3 => 0,
2 => 0,
1 => 0,
];
}
public function get_rating_average_stats() {
return $this->get_meta( 'rating_average_stats' );
}
/**
*
*/
public static function update_user_data( $user_id ) {
$fields = self::metaboxes_fields();
$others = [
'avatar_id' => '',
'map' => '',
];
foreach ( $fields as $key => $field ) {
$kpos = $field['id'];
$tmp = str_replace( OPALESTATE_AGENCY_PREFIX, "", $field['id'] );
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $tmp, $data );
}
}
// update for others
foreach ( $others as $key => $value ) {
$kpos = OPALESTATE_AGENCY_PREFIX . $key;
if ( isset( $_POST[ $kpos ] ) ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $key, $data );
}
}
}
/**
*
*/
public static function update_data_from_user( $related_id ) {
$fields = self::metaboxes_fields();
$others = [
'avatar_id' => '',
'map' => '',
];
foreach ( $fields as $key => $field ) {
$tmp = str_replace( OPALESTATE_AGENCY_PREFIX, "", $field['id'] );
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $tmp;
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_post_meta( $related_id, OPALESTATE_AGENCY_PREFIX . $tmp, $data );
}
}
// update for others
foreach ( $others as $key => $value ) {
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $key;
if ( isset( $_POST[ $kpos ] ) ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_post_meta( $related_id, OPALESTATE_AGENCY_PREFIX . $key, $data );
}
}
}
}

0
inc/agency/functions.php Executable file
View File

View File

@@ -0,0 +1,508 @@
<?php
/**
* Opalestate_Agent_Front
*
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2014 wpopal.com. All Rights Reserved.
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Opalestate_Agent_Front {
/**
* Instance.
*
* @access private
* @var Opalestate_Agent_Front
*/
static private $instance;
/**
* Singleton pattern.
*
* @since $Id
* @access private
*/
private function __construct() {
}
public $new_attachmenet_ids;
/**
* Get instance.
*
* @access public
* @return Opalestate_Agent_Front
*/
public static function get_instance() {
if ( null === static::$instance ) {
self::$instance = new static();
self::$instance->init();
}
return self::$instance;
}
/**
* Auto update meta information to post from user data updated or created
*/
public function init() {
add_action( 'opalestate_on_set_role_agent', [ $this, 'on_set_role' ], 1, 9 );
add_filter( 'opalestate_before_render_profile_agent_form', [ $this, 'render_front_form' ], 2, 2 );
add_filter( 'pre_get_posts', [ $this, 'archives_query' ], 1 );
add_action( 'cmb2_after_init', [ $this, 'on_save_front_data' ] );
add_action( 'opalestate_user_content_agent_profile_page', [ $this, 'render_profile' ] );
add_filter( 'opalestate_management_user_menu', [ $this, 'render_extra_profile_link' ] );
$this->register_shortcodes();
}
/**
* render_extra_profile_link.
*/
public function render_extra_profile_link( $menu ) {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift( $user_roles );
if ( $user_role == 'opalestate_agent' ) {
$menu['extra_profile'] = [
'icon' => 'fa fa-user',
'link' => "agent_profile",
'title' => esc_html__( 'Agent Profile', 'opalestate-pro' ),
'id' => 0,
];
}
return $menu;
}
/**
* render_profile
*/
public function render_profile() {
$user_id = get_current_user_id();
$post_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
$post = get_post( $post_id );
if ( isset( $post->ID ) && $post->post_status != 'publish' ) {
opalestate_add_notice( "warning", esc_html__( 'You account is under reviewing! it take some time to process' ) );
add_action( "opalestate_profile_agency_form_before", "opalestate_print_notices" );
}
$metaboxes = $this->render_front_form( [], $post_id );
return opalestate_load_template_path( 'user/agent/profile-agent', [ 'metaboxes' => $metaboxes, 'post_id' => $post_id ] );
}
/**
* Process upload images for properties
*/
public function upload_image( $submitted_file, $parent_id = 0 ) {
return opalesate_upload_image( $submitted_file, $parent_id );
}
/**
* Remove dirty images of current user
*/
public function remove_dirty_images( $post_id, $user_id ) {
if ( isset( $_POST['remove_image_id'] ) && is_array( $_POST['remove_image_id'] ) && $_POST['remove_image_id'] ) {
foreach ( $_POST['remove_image_id'] as $key => $value ) {
$post = get_post( $value );
if ( $post->post_author == $user_id ) {
wp_delete_attachment( $value );
}
}
}
}
private function process_upload_files( $post_id ) {
//upload images for featured and gallery images
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
///
$fields = [
$this->get_field_name( 'gallery' ),
$this->get_field_name( 'avatar_id' ),
$this->get_field_name( 'featured_image' ),
];
foreach ( $_FILES as $key => $value ) {
// allow processing in fixed collection
if ( in_array( $key, $fields ) ) {
$ufile = $_FILES[ $key ];
/// /////
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
$output = [];
foreach ( $ufile['name'] as $f_key => $f_value ) {
$loop_file = [
'name' => $ufile['name'][ $f_key ],
'type' => $ufile['type'][ $f_key ],
'tmp_name' => $ufile['tmp_name'][ $f_key ],
'error' => $ufile['error'][ $f_key ],
'size' => $ufile['size'][ $f_key ],
];
$new_atm = $this->upload_image( $loop_file, $post_id );
if ( $new_atm ) {
$_POST[ $key ] = isset( $_POST[ $key ] ) ? sanitize_text_field( $_POST[ $key ] ) : [];
$_POST[ $key ][ $new_atm['attachment_id'] ] = $new_atm['url'];
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
} ///
elseif ( isset( $ufile['name'] ) ) {
$new_atm = $this->upload_image( $ufile, $post_id );
if ( $new_atm ) {
$_POST[ $key ] = $new_atm['attachment_id'];
if ( preg_match( "#id#", $key ) ) {
$_key = str_replace( "_id", "", $key );
$_POST[ $_key ] = $new_atm['url'];
}
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
}
}
}
}
public function on_save_front_data() {
if ( isset( $_POST[ 'nonce_CMB2php' . OPALESTATE_AGENT_PREFIX . 'front' ] ) ) {
$post_id = $this->update_data_agent_or_agency( OPALESTATE_AGENT_PREFIX );
if ( $post_id ) {
OpalEstate_Agent::update_user_data( get_current_user_id() );
}
return opalestate_output_msg_json( true,
__( 'The data updated successful, please wait for redirecting', 'opalestate-pro' ),
[
'heading' => esc_html__( 'Update Information', 'opalestate-pro' ),
'redirect' => opalestate_get_user_management_page_uri( [ 'tab' => 'agent_profile' ] ),
]
);
return opalestate_output_msg_json( fales,
__( 'Currently, The data could not save!', 'opalestate-pro' ),
[ 'heading' => esc_html__( 'Update Information', 'opalestate-pro' ) ]
);
exit;
}
}
/**
*
*/
private function get_field_name( $field ) {
return OPALESTATE_AGENT_PREFIX . $field;
}
/**
*
*/
private function update_data_agent_or_agency( $prefix ) {
global $current_user;
$post_id = isset( $_POST['object_id'] ) && absint( $_POST['object_id'] ) ? $_POST['object_id'] : 0;
$user_id = get_current_user_id();
$metaboxes = apply_filters( 'opalestate_before_render_profile_agent_form', [], $post_id );
$metaboxes = apply_filters( 'cmb2_meta_boxes', $metaboxes );
if ( isset( $metaboxes[ $prefix . 'front' ] ) ) {
if ( ! empty( $post_id ) ) {
$old_post = get_post( $post_id );
$post_date = $old_post->post_date;
} else {
$post_date = '';
}
$post = get_post( $post_id );
$data = [
'ID' => $post->ID ? $post_id : null,
'post_title' => sanitize_text_field( $_POST[ $prefix . 'title' ] ),
'post_author' => $user_id,
'post_type' => 'opalestate_agent',
'post_date' => $post_date,
'post_content' => wp_kses( $_POST[ $prefix . 'text' ], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ),
];
unset( $_POST[ $prefix . 'title' ] );
unset( $_POST[ $prefix . 'text' ] );
if ( $data['ID'] > 0 ) {
$post_id = wp_update_post( $data, true );
} else {
$data['post_status'] = 'pending';
$post_id = wp_insert_post( $data, true );
}
$post = get_post( $post_id );
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $post_id );
/*
* Processing upload files
*/
$this->process_upload_files( $post_id, $_POST );
cmb2_get_metabox_form( $metaboxes[ $prefix . 'front' ], $post_id );
$cmb = cmb2_get_metabox( $prefix . 'front', $post_id );
$sanitized_values = $cmb->get_sanitized_values( $_POST );
$cmb->save_fields( $post_id, 'post', $sanitized_values );
/// update
// Create featured image
$featured_image = get_post_meta( $post_id, $prefix . 'featured_image', true );
if ( ! empty( $_POST[ $prefix . 'featured_image' ] ) && isset( $_POST[ $prefix . 'featured_image' ] ) ) {
set_post_thumbnail( $post_id, $_POST[ $prefix . 'featured_image' ] );
unset( $_POST[ $prefix . 'featured_image' ] );
} else {
delete_post_thumbnail( $post_id );
}
// remove dirty images
$this->remove_dirty_images( $post_id, $user_id );
// set ready of attachment for use.
if ( $this->new_attachmenet_ids ) {
foreach ( $this->new_attachmenet_ids as $_id ) {
delete_post_meta( $_id, '_pending_to_use_', 1 );
}
}
return $post_id;
}
return false;
}
public function register_shortcodes() {
$this->shortcodes = [
'change_agent_profile' => [ 'code' => 'change_agent_profile', 'label' => esc_html__( 'Agent Profile', 'opalestate-pro' ) ],
'search_agents' => [ 'code' => 'search_agents', 'label' => esc_html__( 'Search Agents', 'opalestate-pro' ) ],
];
foreach ( $this->shortcodes as $shortcode ) {
add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] );
}
}
public function archives_query( $query ) {
if ( $query->is_main_query() && is_post_type_archive( 'opalestate_agent' ) ) {
$args = [];
$min = opalestate_options( 'search_agent_min_price', 0 );
$max = opalestate_options( 'search_agent_max_price', 10000000 );
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
$default = [
'post_type' => 'opalestate_agent',
'posts_per_page' => apply_filters( 'opalestate_agent_per_page', 12 ),
'paged' => $paged,
];
$args = array_merge( $default, $args );
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
}
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['types'] ),
];
}
if ( $tax_query ) {
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
}
$args['meta_query'] = [ 'relation' => 'AND' ];
if ( $search_min_price != $min && is_numeric( $search_min_price ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_AGENT_PREFIX . 'target_min_price',
'value' => $search_min_price,
'compare' => '>=',
'type' => 'NUMERIC',
] );
}
if ( is_numeric( $search_max_price ) && $search_max_price != $max ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_AGENT_PREFIX . 'target_max_price',
'value' => $search_max_price,
'compare' => '<=',
'type' => 'NUMERIC',
] );
}
///// search by address and geo location ///
if ( isset( $_GET['geo_long'] ) && isset( $_GET['geo_lat'] ) ) {
$prefix = OPALESTATE_AGENT_PREFIX;
if ( $_GET['location_text'] && ( empty( $_GET['geo_long'] ) || empty( $_GET['geo_lat'] ) ) ) {
array_push( $args['meta_query'], [
'key' => $prefix . 'map_address',
'value' => sanitize_text_field( trim( $_GET['location_text'] ) ),
'compare' => 'LIKE',
'operator' => 'OR',
] );
} else {
$radius = isset( $_GET['geo_radius'] ) ? sanitize_text_field( $_GET['geo_radius'] ) : 5;
$post_ids = Opalestate_Query::filter_by_location(
sanitize_text_field( $_GET['geo_lat'] ),
sanitize_text_field( $_GET['geo_long'] ), $radius, $prefix );
$args['post__in'] = $post_ids;
$query->set( 'post__in', $post_ids );
}
}
if ( isset( $args['tax_query'] ) && $args['tax_query'] ) {
$query->set( 'tax_query', $args['tax_query'] );
}
if ( isset( $args['meta_query'] ) && $args['meta_query'] ) {
$query->set( 'meta_query', $args['meta_query'] );
}
}
return $query;
}
/**
*
*/
public function search_agents() {
return opalestate_load_template_path( 'shortcodes/search-agents' );
}
/**
* Auto update meta information to post from user data updated or created
*/
public function on_set_role( $user_id ) {
if ( $user_id ) {
$args = [
'post_type' => 'opalestate_agent',
'posts_per_page' => 10,
];
$args['meta_key'] = OPALESTATE_AGENT_PREFIX . 'user_id';
$args['meta_value'] = $user_id;
$args['meta_compare'] = '=';
$args['post_status'] = [ 'publish', 'pending' ];
$post = get_posts( $args );
if ( empty( $post ) ) {
$agent_id = $this->create_agent( [], $user_id );
update_post_meta( $agent_id, OPALESTATE_AGENT_PREFIX . 'user_id', $user_id );
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', $agent_id );
}
}
}
public function create_agent( $args = [], $user_id ) {
$data = get_user_by( 'id', $user_id );
$args = wp_parse_args( $args, [
'first_name' => $data->first_name,
'last_name' => $data->last_name,
'post_author' => $user_id,
'avatar' => '',
'job' => '',
'email' => '',
'phone' => '',
'mobile' => '',
'fax' => '',
'web' => '',
'address' => '',
'twitter' => '',
'facebook' => '',
'google' => '',
'linkedin' => '',
'instagram' => '',
] );
$agent_id = wp_insert_post( [
'post_title' => $args['first_name'] && $args['last_name'] ? $args['first_name'] . ' ' . $args['last_name'] : esc_html__( 'User ID', 'opalestate-pro' ) . ': ' . $user_id,
'post_content' => '',
'post_excerpt' => '',
'post_type' => 'opalestate_agent',
'post_status' => 'pending',
'post_author' => $user_id,
], true );
do_action( 'opalesate_insert_user_agent', $agent_id );
return $agent_id;
}
/**
*
*/
public function render_front_form( $metaboxes, $post_id = 0 ) {
$metabox = new Opalestate_Agent_MetaBox();
return $metabox->render_front_form( $metaboxes, $post_id );
}
}
Opalestate_Agent_Front::get_instance();

View File

@@ -0,0 +1,225 @@
<?php
/**
* Opalestate_Agent_MetaBox.
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Agent_MetaBox extends Opalestate_User_MetaBox {
/**
*
*/
public function metaboxes_admin_fields( $prefix = '' ) {
if ( ! $prefix ) {
$prefix = OPALESTATE_AGENT_PREFIX;
}
$fields = [];
$fields = array_merge_recursive( $fields,
$this->get_base_fields( $prefix ),
$this->get_job_fields( $prefix ),
$this->get_address_fields( $prefix )
);
return apply_filters( 'opalestate_postype_agent_metaboxes_fields', $fields );
}
public function metaboxes_target() {
$prefix = OPALESTATE_AGENT_PREFIX;
$fields = [
[
'id' => "{$prefix}user_id",
'name' => esc_html__( 'Link to User', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Enter User ID to show information without using user info', 'opalestate-pro' ),
],
[
'id' => "{$prefix}target_min_price",
'name' => esc_html__( 'Target Min Price', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Enter min price of property which is for sale/rent...', 'opalestate-pro' ),
],
[
'id' => "{$prefix}target_max_price",
'name' => esc_html__( 'Target Max Price', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Enter max price of property which is for sale/rent...', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Types', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
'id' => $prefix . "type",
'taxonomy' => 'opalestate_types', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
],
];
return $fields;
}
/**
*
*/
public function metaboxes_front_fields( $prefix = '', $post_id = 0 ) {
if ( ! $prefix ) {
$prefix = OPALESTATE_AGENT_PREFIX;
}
$post = get_post( $post_id );
$fields = [
[
'id' => $prefix . 'post_type',
'type' => 'hidden',
'default' => 'opalestate_agent',
],
[
'name' => esc_html__( 'Title/Name', 'opalestate-pro' ),
'id' => $prefix . 'title',
'type' => 'text',
'default' => ! empty( $post ) ? $post->post_title : '',
'attributes' => [
'required' => 'required',
],
],
[
'name' => esc_html__( 'Information', 'opalestate-pro' ),
'id' => $prefix . 'text',
'type' => 'wysiwyg',
'default' => ! empty( $post ) ? $post->post_content : '',
'attributes' => [
'required' => 'required',
],
],
[
'name' => esc_html__( 'Types', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
'id' => $prefix . "type",
'taxonomy' => 'opalestate_types', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
],
[
'id' => "{$prefix}target_min_price",
'name' => esc_html__( 'Target Min Price', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Enter min price of property which is for sale/rent...', 'opalestate-pro' ),
],
[
'id' => "{$prefix}target_max_price",
'name' => esc_html__( 'Target Max Price', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Enter max price of property which is for sale/rent...', 'opalestate-pro' ),
'after_row' => '</div>',
],
];
$fields = array_merge_recursive( $fields,
$this->get_base_front_fields( $prefix ),
$this->get_address_fields( $prefix ),
$this->get_social_fields( $prefix )
);
return apply_filters( 'opalestate_postype_agent_metaboxes_fields', $fields );
}
public function get_base_front_fields( $prefix ) {
return [
[
'id' => "{$prefix}featured_image",
'name' => esc_html__( 'Banner', 'opalestate-pro' ),
'type' => 'uploader',
'is_featured' => true,
'limit' => 1,
'single' => 1,
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
'before_row' => '<hr>',
],
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar',
'type' => 'hidden',
'single' => 1,
'limit' => 1,
],
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar_id',
'type' => 'uploader',
'single' => 1,
'limit' => 1,
],
[
'name' => esc_html__( 'Email', 'opalestate-pro' ),
'id' => "{$prefix}email",
'type' => 'text',
'before_row' => '<div class="field-row-2">',
],
[
'name' => esc_html__( 'Website', 'opalestate-pro' ),
'id' => "{$prefix}web",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'id' => "{$prefix}phone",
'type' => 'text',
],
[
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
'id' => "{$prefix}mobile",
'type' => 'text',
],
[
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
'id' => "{$prefix}fax",
'type' => 'text',
'after_row' => '</div>',
],
];
}
/**
*
*/
public function render_front_form( $metaboxes, $post_id = 0 ) {
$prefix = OPALESTATE_AGENT_PREFIX;
$metaboxes[ $prefix . 'front' ] = [
'id' => $prefix . 'front',
'title' => esc_html__( 'Agent Information', 'opalestate-pro' ),
'object_types' => [ 'opalestate_agent' ],
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => $this->metaboxes_front_fields( $prefix, $post_id ),
];
return $metaboxes;
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Opalestate_PostType_Agent
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_PostType_Agent {
/**
* Opalestate_PostType_Agent constructor.
*/
public function __construct() {
add_action( 'init', [ __CLASS__, 'definition' ] );
}
/**
* Register Post type and taxonomies
*/
public static function definition() {
if ( ! is_blog_installed() || post_type_exists( 'opalestate_agent' ) ) {
return;
}
$labels = [
'name' => esc_html__( 'Agents', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Property', 'opalestate-pro' ),
'add_new' => esc_html__( 'Add New Agent', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Agent', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Agent', 'opalestate-pro' ),
'new_item' => esc_html__( 'New Agent', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Agents', 'opalestate-pro' ),
'view_item' => esc_html__( 'View Agent', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Agent', 'opalestate-pro' ),
'not_found' => esc_html__( 'No Agents found', 'opalestate-pro' ),
'not_found_in_trash' => esc_html__( 'No Agents found in Trash', 'opalestate-pro' ),
'parent_item_colon' => '',
'menu_name' => esc_html__( 'Agents', 'opalestate-pro' ),
];
$labels = apply_filters( 'opalestate_postype_agent_labels', $labels );
register_post_type( 'opalestate_agent',
apply_filters( 'opalestate_agent_post_type_parameters', [
'labels' => $labels,
'supports' => [ 'title', 'editor', 'thumbnail', 'comments', 'author', 'excerpt' ],
'public' => true,
'has_archive' => true,
'menu_position' => 51,
'categories' => [],
'menu_icon' => 'dashicons-groups',
'rewrite' => [ 'slug' => esc_html_x( 'agent', 'agent slug', 'opalestate-pro' ) ],
] )
);
static::register_taxonomies();
}
/**
* Register Agency Agency Taxonomy
*/
private static function register_taxonomies() {
/// Register Agent Levels
$labels = [
'name' => esc_html__( 'Agent Levels', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Level', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Level', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Levels', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Level', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Level:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Level', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Level', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Level', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Level Name', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Agent Levels', 'opalestate-pro' ),
];
///
register_taxonomy( 'opalestate_agent_level', [ 'opalestate_agent' ],
[
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'show_in_nav_menus' => true,
'rewrite' => [
'slug' => esc_html_x( 'agent-level', 'agent level slug', 'opalestate-pro' ),
],
] );
}
}
new Opalestate_PostType_Agent();

View File

@@ -0,0 +1,20 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package $package$
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2014 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
class Opalestate_Agent_Query extends OpalEstate_Abstract_Query {
}

View File

@@ -0,0 +1,277 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Agent
*
* @version 1.0
*/
class OpalEstate_Agent {
/**
* @var String $author_name
*
* @access protected
*/
protected $author_name;
/**
* @var Boolean $is_featured
*
* @access protected
*/
protected $is_featured;
/**
* Constructor
*/
public function __construct( $post_id = null ) {
global $post;
if ( $post ) {
$this->post = $post;
$this->post_id = $post_id ? $post_id : get_the_ID();
$this->author = get_userdata( $post->post_author );
$this->author_name = ! empty( $this->author ) ? sprintf( '%s %s', $this->author->first_name, $this->author->last_name ) : null;
$this->is_featured = $this->get_meta( 'featured' );
$this->is_trusted = $this->get_meta( 'trusted' );
}
}
public function get_id() {
return $this->post_id;
}
/**
* Get Collection Of soicals with theirs values
*/
public function get_socials() {
$socials = [
'facebook' => '',
'twitter' => '',
'pinterest' => '',
'google' => '',
'instagram' => '',
'linkedIn' => '',
];
$output = [];
foreach ( $socials as $social => $k ) {
$data = $this->get_meta( $social );
if ( $data && $data != "#" && ! empty( $data ) ) {
$output[ $social ] = $data;
}
}
return $output;
}
/**
* Get url of user avatar by agent id
*/
public static function get_avatar_url( $userID ) {
return get_post_meta( $userID, OPALESTATE_AGENT_PREFIX . "avatar", true );
}
/**
* Render list of levels of agent
*/
public function render_level() {
$levels = wp_get_post_terms( $this->get_id(), 'opalestate_agent_level' );
if ( empty( $levels ) ) {
return;
}
$output = '<span class="agent-levels">';
foreach ( $levels as $key => $value ) {
$output .= '<span class="agent-label"><span>' . $value->name . '</span></span>';
}
$output .= '</span>';
echo $output;
}
/**
* get meta data value of key without prefix
*/
public function get_meta( $key ) {
return get_post_meta( $this->get_id(), OPALESTATE_AGENT_PREFIX . $key, true );
}
/**
* return true if this agent is featured
*/
public function is_featured() {
return $this->is_featured;
}
/**
* render block information by id
*/
public static function render_box_info( $post_id ) {
}
public static function get_link( $agent_id ) {
$agent = get_post( $agent_id );
$url = self::get_avatar_url( $agent_id );
return [
'name' => $agent->post_title,
'avatar' => $url,
'link' => get_permalink( $agent->ID ),
];
}
public static function metaboxes_fields() {
$metabox = new Opalestate_Agent_MetaBox();
$fields = $metabox->metaboxes_admin_fields();
return array_merge_recursive( $fields, $metabox->get_social_fields( OPALESTATE_AGENT_PREFIX ) );
}
public static function update_user_data( $user_id ) {
$fields = self::metaboxes_fields();
$others = [
'avatar_id' => '',
'opalestate_agt_map' => '',
'map' => '',
];
foreach ( $fields as $key => $field ) {
$kpos = $field['id'];
$tmp = str_replace( OPALESTATE_AGENT_PREFIX, '', $field['id'] );
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $tmp, $data );
}
}
// update for others
foreach ( $others as $key => $value ) {
$kpos = OPALESTATE_AGENT_PREFIX . $key;
if ( isset( $_POST[ $kpos ] ) ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $key, $data );
}
}
}
/**
*
*/
public function get_trusted() {
return $this->is_trusted;
}
/**
*
*/
public static function update_data_from_user( $related_id ) {
$fields = self::metaboxes_fields();
$others = [
'avatar_id' => '',
'map' => '',
];
foreach ( $fields as $key => $field ) {
$tmp = str_replace( OPALESTATE_AGENT_PREFIX, "", $field['id'] );
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $tmp;
if ( isset( $_POST[ $kpos ] ) && $tmp ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . $tmp, $data );
}
}
// update for others
foreach ( $others as $key => $value ) {
$kpos = OPALESTATE_USER_PROFILE_PREFIX . $key;
if ( isset( $_POST[ $kpos ] ) ) {
$data = is_string( $_POST[ $kpos ] ) ? sanitize_text_field( $_POST[ $kpos ] ) : $_POST[ $kpos ];
update_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . $key, $data );
}
}
}
/**
* Get rating count.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return int
*/
public function get_rating_counts() {
return $this->get_meta( 'rating_count' ) ? $this->get_meta( 'rating_count' ) : 0;
}
/**
* Get average rating.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return float
*/
public function get_average_rating() {
return $this->get_meta( 'average_rating' ) ? $this->get_meta( 'average_rating' ) : 0;
}
/**
* Get review count.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return int
*/
public function get_review_count() {
return $this->get_meta( 'review_count' ) ? $this->get_meta( 'review_count' ) : 0;
}
/**
*
*/
public function get_rating_count_stats() {
return $this->get_meta( 'rating_count_stats' ) ? $this->get_meta( 'rating_count_stats' ) : [
5 => 0,
4 => 0,
3 => 0,
2 => 0,
1 => 0,
];
}
/**
*
*/
public function get_rating_average_stats() {
return $this->get_meta( 'rating_average_stats' );
}
public function get_count_listing() {
return 4;
}
}
?>

0
inc/agent/functions.php Executable file
View File

301
inc/ajax-functions.php Executable file
View File

@@ -0,0 +1,301 @@
<?php
/**
* Ajax functions
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
function opalestate_gallery_property() {
$post_id = intval( $_POST['property_id'] );
$gallery = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'gallery', 1 );
echo json_encode( [ 'gallery' => $gallery ] );
die;
}
add_action( 'wp_ajax_opalestate_gallery_property', 'opalestate_gallery_property' );
add_action( 'wp_ajax_nopriv_opalestate_gallery_property', 'opalestate_gallery_property' );
/**
* Searches for users via ajax and returns a list of results
*
* @return void
* @since 1.0
*
*/
function opalestate_ajax_search_property_users() {
$search_query = trim( $_GET['q'] );
$get_users_args = [
'number' => 9999,
'search' => $search_query . '*',
];
$get_users_args = apply_filters( 'opalestate_search_users_args', $get_users_args );
$found_users = apply_filters( 'opalestate_ajax_found_property_users', get_users( $get_users_args ), $search_query );
$users = [];
if ( ! empty( $found_users ) ) {
foreach ( $found_users as $user ) {
$users[] = [
'id' => $user->ID,
'name' => $user->display_name,
'avatar_url' => OpalEstate_User::get_author_picture( $user->ID ),
'full_name' => $user->display_name,
'description' => 'okokok',
];
}
}
$output = [
'total_count' => count( $users ),
'items' => $users,
'incomplete_results' => false,
];
echo json_encode( $output );
die();
}
add_action( 'wp_ajax_opalestate_search_property_users', 'opalestate_ajax_search_property_users' );
add_action( 'wp_ajax_opalestate_ajax_get_state_by_country', "opalestate_ajax_get_state_by_country" );
function opalestate_ajax_get_state_by_country() {
if ( ! isset( $_POST['country'] ) ) {
die;
}
$country = sanitize_text_field( $_POST['country'] );
$is_search = isset( $_POST['is_search'] ) && $_POST['is_search'];
$terms = get_terms( [
'taxonomy' => 'opalestate_state',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => $is_search ? true : false,
'meta_query' => [
[
'key' => 'opalestate_state_location',
'value' => $country,
],
],
] );
$states = [];
$states[] = [
'id' => $is_search ? '-1' : '',
'text' => esc_html__( 'Select State', 'opalestate-pro' ),
];
if ( $terms ) {
foreach ( $terms as $term ) {
$states[] = [
'id' => $term->slug,
'text' => $term->name,
];
}
}
echo json_encode( $states );
wp_die();
}
add_action( 'wp_ajax_opalestate_ajax_get_city_by_state', "opalestate_ajax_get_city_by_state" );
function opalestate_ajax_get_city_by_state() {
if ( ! isset( $_POST['state'] ) ) {
die;
}
$state = sanitize_text_field( $_POST['state'] );
$is_search = isset( $_POST['is_search'] ) && $_POST['is_search'];
$terms = get_terms( [
'taxonomy' => 'opalestate_city',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => $is_search ? true : false,
'meta_query' => [
[
'key' => 'opalestate_city_state',
'value' => $state,
],
],
] );
$cities = [];
$cities[] = [
'id' => $is_search ? '-1' : '',
'text' => esc_html__( 'Select City', 'opalestate-pro' ),
];
if ( $terms ) {
foreach ( $terms as $term ) {
$cities[] = [
'id' => $term->slug,
'text' => $term->name,
];
}
}
echo json_encode( $cities );
wp_die();
}
/* set feature property */
add_action( 'wp_ajax_opalestate_set_feature_property', 'opalestate_set_feature_property' );
add_action( 'wp_ajax_nopriv_opalestate_set_feature_property', 'opalestate_set_feature_property' );
if ( ! function_exists( 'opalestate_set_feature_property' ) ) {
function opalestate_set_feature_property() {
if ( ! isset( $_REQUEST['nonce'] ) && ! wp_verify_nonce( $_REQUEST['nonce'], 'nonce' ) ) {
return;
}
if ( ! isset( $_REQUEST['property_id'] ) ) {
return;
}
update_post_meta( absint( $_REQUEST['property_id'] ), OPALESTATE_PROPERTY_PREFIX . 'featured', 1 );
wp_redirect( admin_url( 'edit.php?post_type=opalestate_property' ) );
exit();
}
}
/* remove feature property */
add_action( 'wp_ajax_opalestate_remove_feature_property', 'opalestate_remove_feature_property' );
add_action( 'wp_ajax_nopriv_opalestate_remove_feature_property', 'opalestate_remove_feature_property' );
if ( ! function_exists( 'opalestate_remove_feature_property' ) ) {
function opalestate_remove_feature_property() {
if ( ! isset( $_REQUEST['nonce'] ) && ! wp_verify_nonce( $_REQUEST['nonce'], 'nonce' ) ) {
return;
}
if ( ! isset( $_REQUEST['property_id'] ) ) {
return;
}
update_post_meta( absint( $_REQUEST['property_id'] ), OPALESTATE_PROPERTY_PREFIX . 'featured', '' );
wp_redirect( admin_url( 'edit.php?post_type=opalestate_property' ) );
exit();
}
}
/**
* Set Featured Item Following user
*/
add_action( 'wp_ajax_opalestate_toggle_featured_property', 'opalestate_toggle_featured_property' );
add_action( 'wp_ajax_nopriv_opalestate_toggle_featured_property', 'opalestate_toggle_featured_property' );
function opalestate_toggle_featured_property() {
global $current_user;
wp_get_current_user();
$user_id = $current_user->ID;
$property_id = intval( $_POST['property_id'] );
$post = get_post( $property_id );
if ( $post->post_author == $user_id ) {
$check = apply_filters( 'opalestate_set_feature_property_checked', false );
if ( $check ) {
do_action( 'opalestate_toggle_featured_property_before', $user_id, $property_id );
update_post_meta( $property_id, OPALESTATE_PROPERTY_PREFIX . 'featured', 1 );
echo json_encode( [ 'status' => true, 'msg' => esc_html__( 'Could not set this as featured', 'opalestate-pro' ) ] );
wp_die();
}
}
echo json_encode( [ 'status' => false, 'msg' => esc_html__( 'Could not set this as featured', 'opalestate-pro' ) ] );
wp_reset_query();
wp_die();
}
/**
* load more properties by agency
*/
add_action( 'wp_ajax_get_agency_property', 'opalestate_load_more_agency_property' );
add_action( 'wp_ajax_nopriv_get_agency_property', 'opalestate_load_more_agency_property' );
function opalestate_load_more_agency_property() {
$post = [
'post_id' => 0,
'paged' => 1,
'user_id' => 13,
'related' => '',
'limit' => apply_filters( 'opalesate_agency_properties_limit', 5 ),
];
$post = array_merge( $post, $_POST );
extract( $post );
$user_id = get_post_meta( absint( $post_id ), OPALESTATE_AGENCY_PREFIX . 'user_id', true );
$query = Opalestate_Query::get_agency_property( absint( $post_id ), absint( $user_id ), absint( $limit ), absint( $paged ) );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-lg-12 col-md-12 col-sm-12">
<?php echo opalestate_load_template_path( 'content-property-list-v2' ); ?>
</div>
<?php endwhile;
endif;
wp_reset_postdata();
exit;
}
/**
* load more properties by agency
*/
add_action( 'wp_ajax_get_agent_property', 'opalestate_get_agent_property' );
add_action( 'wp_ajax_nopriv_get_agent_property', 'opalestate_get_agent_property' );
function opalestate_get_agent_property() {
global $paged;
$post = [
'paged' => 1,
'id' => 13,
'limit' => apply_filters( 'opalesate_agent_properties_limit', 1 ),
];
$post = array_merge( $post, $_POST );
extract( $post );
set_query_var( 'paged', $post['paged'] );
$query = Opalestate_Query::get_agent_property( null, absint( $post['id'] ), absint( $limit ) );
$paged = absint( $post['paged'] );
if ( $query->have_posts() ) : ?>
<div class="opalestate-rows">
<div class="<?php echo apply_filters( 'opalestate_row_container_class', 'row opal-row' ); ?>">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-lg-12 col-md-12 col-sm-12">
<?php echo opalestate_load_template_path( 'content-property-list' ); ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php if ( $query->max_num_pages > 1 ): ?>
<div class="w-pagination"><?php opalestate_pagination( $query->max_num_pages ); ?></div>
<?php endif; ?>
<?php
endif;
wp_reset_postdata();
exit;
}

1367
inc/api/class-opalestate-api.php Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,160 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Nocaptcha_Recaptcha
*
* @version 1.0
*/
class OpalEstate_Nocaptcha_Recaptcha {
/**
* OpalEstate_Nocaptcha_Recaptcha constructor.
*/
public function __construct() {
if ( is_admin() ) {
add_filter( 'opalestate_settings_3rd_party_subtabs_nav', [ $this, 'admin_tab_setting' ] );
add_filter( 'opalestate_settings_3rd_party_subtabs_google_captcha_page_fields', [ $this, 'admin_content_setting' ] );
}
if ( opalestate_options( 'show_captcha' ) == 'on' ) {
define( 'WPOPAL_CAPTCHA_LOAED', true );
$this->theme = opalestate_options( 'captcha_theme', 'light' );
add_action( 'wp_head', [ $this, 'add_custom_styles' ] );
add_action( 'opalestate_message_form_after', [ __CLASS__, 'show_captcha' ] );
add_action( 'opalestate_process_send_email_before', [ __CLASS__, 'ajax_verify_captcha' ] );
}
}
/**
*
*/
public function add_custom_styles() {
$lang = null;
echo '<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_' . opalestate_options( 'site_key' ) . '" async defer></script>' . "\r\n";
}
/**
*
*/
public static function show_captcha() {
if ( isset( $_GET['captcha'] ) && $_GET['captcha'] == 'failed' ) {
}
echo '<div style="transform:scale(0.77);-webkit-transform:scale(0.77);transform-origin:0 0;-webkit-transform-origin:0 0;" class="g-recaptcha" data-sitekey="' . opalestate_options( 'site_key' ) . '" data-theme="' . opalestate_options( 'captcha_theme',
'light' ) . '"></div>';
}
/**
*
*/
public static function ajax_verify_captcha() {
$response = isset( $_POST['g-recaptcha-response'] ) ? esc_attr( $_POST['g-recaptcha-response'] ) : '';
$remote_ip = $_SERVER["REMOTE_ADDR"];
// make a GET request to the Google reCAPTCHA Server
$request = wp_remote_get(
'https://www.google.com/recaptcha/api/siteverify?secret=' . opalestate_options( 'secret_key' ) . '&response=' . $response . '&remoteip=' . $remote_ip
);
// get the request response body
$response_body = wp_remote_retrieve_body( $request );
$result = json_decode( $response_body, true );
if ( isset( $result['hostname'] ) && ! empty( $result['hostname'] ) && empty( $result['success'] ) ) {
$result['success'] = 1;
}
if ( ! $result['success'] ) {
$return = [ 'status' => false, 'msg' => esc_html__( 'The captcha is not verified, please try again!', 'opalestate-pro' ) ];
echo json_encode( $return );
die();
}
}
/**
*
*/
public function admin_content_setting( $fields ) {
$fields = apply_filters( 'opalestate_settings_google_captcha', [
[
'name' => esc_html__( 'Show Captcha In Form', 'opalestate-pro' ),
'desc' => __( 'Enable google captch in contact , register form. After Set yes, you change setting in Google Captcha Tab. Register here:<a href="https://www.google.com/recaptcha/admin" target="_blank"> https://www.google.com/recaptcha/admin</a> Version 2',
'opalestate-pro' ),
'id' => 'show_captcha',
'type' => 'switch',
'options' => [
'off' => esc_html__( 'No', 'opalestate-pro' ),
'on' => esc_html__( 'Yes', 'opalestate-pro' ),
],
'default' => 'on',
],
[
'name' => esc_html__( 'Google Captcha page Settings', 'opalestate-pro' ),
'desc' => '<hr>',
'id' => 'opalestate_title_google_captcha_settings',
'type' => 'title',
],
[
'name' => esc_html__( 'Site Key', 'opalestate-pro' ),
'desc' => esc_html__( 'Used for displaying the CAPTCHA. Grab it %s', 'opalestate-pro' ),
'id' => 'site_key',
'type' => 'text',
],
[
'name' => esc_html__( 'Secret key', 'opalestate-pro' ),
'desc' => esc_html__( 'Used for communication between your site and Google. Grab it.', 'opalestate-pro' ),
'id' => 'secret_key',
'type' => 'text',
],
[
'name' => esc_html__( 'Theme', 'opalestate-pro' ),
'desc' => esc_html__( 'Display captcha box with color style.', 'opalestate-pro' ),
'id' => 'captcha_theme',
'type' => 'select',
'options' => [
'light' => esc_html__( 'Light', 'opalestate-pro' ),
'dark' => esc_html__( 'Dark', 'opalestate-pro' ),
],
],
] );
return $fields;
}
/**
*
*/
public function admin_tab_setting( $tabs ) {
$tabs['google_captcha_page'] = esc_html__( 'Google Captcha', 'opalestate-pro' );
return $tabs;
}
}
new OpalEstate_Nocaptcha_Recaptcha();

458
inc/class-opalestate-email.php Executable file
View File

@@ -0,0 +1,458 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package $package$
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2014 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* @class OpalMembership_Checkout
*
* @version 1.0
*/
class Opalestate_Emails {
/**
* init action to automatic send email when user edit or submit a new submission and init setting form in plugin setting of admin
*/
public static function init() {
self::load();
add_action( 'opalestate_processed_new_submission' , array( __CLASS__ , 'new_submission_email'), 10, 2 );
//add_action( 'opalestate_processed_edit_submission' , array( __CLASS__ , 'new_submission_email'), 10, 2 );
if( is_admin() ){
add_filter( 'opalestate_settings_tabs', array( __CLASS__, 'setting_email_tab'), 1 );
add_filter( 'opalestate_registered_emails_settings', array( __CLASS__, 'setting_email_fields'), 10, 1 );
}
$enable_approve_property_email = opalestate_get_option( 'enable_approve_property_email' );
if ( $enable_approve_property_email == 'on' ) {
add_action( 'transition_post_status', array( __CLASS__, 'send_email_when_publish_property') , 10, 3 );
add_action( 'opalestate_processed_approve_publish_property', array( __CLASS__, 'approve_publish_property_email') , 10, 1 );
}
/**
* Send email when User contact via Enquiry Form and Contact Form
*/
add_action( 'opalestate_send_email_notifycation', array(__CLASS__,'send_notifycation') );
add_action( 'opalestate_send_email_submitted', array(__CLASS__,'new_submission_email') );
add_action( 'opalestate_send_email_request_reviewing', array( __CLASS__, 'send_email_request_reviewing') );
}
/**
*
*/
public static function load() {
require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-abs-email-template.php';
require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-email-notifycation.php';
require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-request-viewing.php';
require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalestate-new-submitted.php';
require_once OPALESTATE_PLUGIN_DIR . 'inc/email/class-opalesate-approve.php';
}
/**
* Send Email Notifycation with two types: Enquiry or Contact
*/
public static function send_notifycation ( $content ) {
$mail = new OpalEstate_Send_Email_Notification() ;
$mail->set_args ( $content );
$return = self::send_mail_now( $mail );
if( isset($content['data']) ){
$return['data'] = $content['data'];
}
echo json_encode( $return ); die();
}
/**
* send email if agent submit a new property
*/
public static function new_submission_email( $user_id, $post_id ){
$mail = new OpalEstate_Send_Email_New_Submitted() ;
$mail->set_pros( $post_id, $user_id );
$return = self::send_mail_now( $mail );
echo json_encode( $return ); die();
}
/**
* Send email to requet viewing a property
*/
public static function send_email_request_reviewing( $content ){
$mail = new OpalEstate_Send_Email_Request_Reviewing();
$mail->set_args( $content );
$return = self::send_mail_now( $mail );
echo json_encode( $return ); die();
}
/**
*
*/
public static function send_mail_now( $mail ){
$from_name = $mail->from_name();
$from_email = $mail->from_email();
$headers = sprintf( "From: %s <%s>\r\n Content-type: text/html", $from_name, $from_email );
$subject = $mail->get_subject();
$message = $mail->get_body();
if( $mail->to_email() ) {
if( $mail->get_cc() ){
$status = @wp_mail( $mail->get_cc(), $subject, $message, $headers );
}
$status = @wp_mail( $mail->to_email(), $subject, $message, $headers );
$return = array( 'status' => true, 'msg' => esc_html__( 'Message has been successfully sent.', 'opalestate-pro' ) );
} else {
$return = array( 'status' => true, 'msg' => esc_html__( 'Message has been successfully sent.', 'opalestate-pro' ) );
}
return $return;
}
/**
*
*/
public static function send_email_when_publish_property( $new_status, $old_status, $post ) {
if( is_object( $post ) ){
if ( $post->post_type == 'opalestate_property' ) {
if ( $new_status != $old_status ) {
if ($new_status == 'publish' ) {
if ($old_status == 'draft' || $old_status == 'pending') {
// Send email
$post_id = $post->ID;
do_action( "opalestate_processed_approve_publish_property", $post_id );
}
}
}
}
}
}
/**
* add new tab Email in opalestate -> setting
*/
public static function setting_email_tab( $tabs ){
$tabs['emails'] = esc_html__( 'Email', 'opalestate-pro' );
return $tabs;
}
public static function newproperty_email_body(){
}
public static function approve_email_body(){
}
/**
* render setting email fields with default values
*/
public static function setting_email_fields( $fields ){
$contact_list_tags = '<div>
<p class="tags-description">Use the following tags to automatically add property information to the emails. Tags labeled with an asterisk (*) can be used in the email subject as well.</p>
<div class="opalestate-template-tags-box">
<strong>{receive_name}</strong> Name of the agent who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> Property of the user who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{name}</strong> Name of the user who contact via email form
</div>
<div class="opalestate-template-tags-box">
<strong>{email}</strong> Email of the user who contact via email form
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> * Link of the property
</div>
<div class="opalestate-template-tags-box">
<strong>{message}</strong> * Message content of who sent via form
</div>
</div> ';
$list_tags = '<div>
<p class="tags-description">Use the following tags to automatically add property information to the emails. Tags labeled with an asterisk (*) can be used in the email subject as well.</p>
<div class="opalestate-template-tags-box">
<strong>{property_name}</strong> Email of the user who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{property_link}</strong> Email of the user who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{user_email}</strong> Email of the user who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{submitted_date}</strong> Email of the user who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{user_name}</strong> * Name of the user who made the property
</div>
<div class="opalestate-template-tags-box">
<strong>{date}</strong> * Date and time of the property
</div>
<div class="opalestate-template-tags-box">
<strong>{site_name}</strong> The name of this website
</div>
<div class="opalestate-template-tags-box">
<strong>{site_link}</strong> A link to this website
</div>
<div class="opalestate-template-tags-box">
<strong>{current_time}</strong> Current date and time
</div></div>';
$list_tags = apply_filters( 'opalestate_email_tags', $list_tags );
$fields = array(
'id' => 'options_page',
'title' => esc_html__( 'Email Settings', 'opalestate-pro' ),
'show_on' => array( 'key' => 'options-page', 'value' => array( 'opalestate_settings' ), ),
'fields' => apply_filters( 'opalestate_settings_emails', array(
array(
'name' => esc_html__( 'Email Settings', 'opalestate-pro' ),
'desc' => '<hr>',
'id' => 'opalestate_title_email_settings_1',
'type' => 'title'
),
array(
'id' => 'from_name',
'name' => esc_html__( 'From Name', 'opalestate-pro' ),
'desc' => esc_html__( 'The name donation receipts are said to come from. This should probably be your site or shop name.', 'opalestate-pro' ),
'default' => get_bloginfo( 'name' ),
'type' => 'text'
),
array(
'id' => 'from_email',
'name' => esc_html__( 'From Email', 'opalestate-pro' ),
'desc' => esc_html__( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'opalestate-pro' ),
'default' => get_bloginfo( 'admin_email' ),
'type' => 'text'
),
array(
'name' => esc_html__( 'Email Submission Templates (Template Tags)', 'opalestate-pro' ),
'desc' => $list_tags.'<br><hr>',
'id' => 'opalestate_title_email_settings_2',
'type' => 'title'
),
array(
'name' => esc_html__( 'Notification For New Property Submission', 'opalestate-pro' ),
'desc' => '<hr>',
'id' => 'opalestate_title_email_settings_3',
'type' => 'title'
),
array(
'id' => 'newproperty_email_subject',
'name' => esc_html__( 'Email Subject', 'opalestate-pro' ),
'type' => 'text',
'desc' => esc_html__( 'The email subject for admin notifications.', 'opalestate-pro' ),
'attributes' => array(
'placeholder' => 'Your package is expired',
'rows' => 3,
),
'default' => esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' )
),
array(
'id' => 'newproperty_email_body',
'name' => esc_html__( 'Email Body', 'opalestate-pro' ),
'type' => 'wysiwyg',
'desc' => esc_html__( 'Enter the email an admin should receive when an initial payment request is made.', 'opalestate-pro' ),
'default' => OpalEstate_Send_Email_New_Submitted::get_default_template(),
),
//------------------------------------------
array(
'name' => esc_html__( 'Approve property for publish', 'opalestate-pro' ),
'desc' => '<hr>',
'id' => 'opalestate_title_email_settings_4',
'type' => 'title'
),
array(
'name' => esc_html__( 'Enable approve property email', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable approve property email.', 'opalestate-pro' ),
'id' => 'enable_approve_property_email',
'type' => 'switch',
'options' => array(
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
),
'default' => 'off',
),
array(
'id' => 'approve_email_subject',
'name' => esc_html__( 'Email Subject', 'opalestate-pro' ),
'type' => 'text',
'desc' => esc_html__( 'The email subject a user should receive when they make an initial property request.', 'opalestate-pro' ),
'attributes' => array(
'placeholder' => 'Your property at I Love WordPress is pending',get_bloginfo( 'name' ),
'rows' => 3,
),
'default' => esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' )
),
array(
'id' => 'approve_email_body',
'name' => esc_html__( 'Email Body', 'opalestate-pro' ),
'type' => 'wysiwyg',
'desc' => esc_html__( 'Enter the email a user should receive when they make an initial payment request.', 'opalestate-pro' ),
'default' => OpalEstate_Send_Email_Approve::get_default_template(),
),
/// email contact template ////
array(
'name' => esc_html__( 'Email Contact Templates (Template Tags)', 'opalestate-pro' ),
'desc' => $contact_list_tags.'<br><hr>',
'id' => 'opalestate_title_email_settings_6',
'type' => 'title'
),
array(
'id' => 'contact_email_subject',
'name' => esc_html__( 'Email Subject', 'opalestate-pro' ),
'type' => 'text',
'desc' => esc_html__( 'The email subject a user should receive when they make an initial property request.', 'opalestate-pro' ),
'attributes' => array(
'placeholder' => 'Your property at I Love WordPress is pending',get_bloginfo( 'name' ),
'rows' => 3,
),
'default' => esc_html__('You got a message', 'opalestate-pro')
),
array(
'id' => 'contact_email_body',
'name' => esc_html__( 'Email Body', 'opalestate-pro' ),
'type' => 'wysiwyg',
'desc' => trim(preg_replace('/\t+/', '', "Hi {receive_name},<br>
You have got message from {name} with email {email}. Here is detail:
<br>
<br>
{message}
<br>
&nbsp;<br>
<br>
<em>This message was sent by {site_link} on {current_time}.</em>"))
)
)
)
);
return $fields;
}
/**
* get data of newrequest email
*
* @var $args array: property_id , $body
* @return text: message
*/
public static function replace_shortcode( $args, $body ) {
$tags = array(
'user_name' => "",
'user_mail' => "",
'submitted_date' => "",
'property_name' => "",
'site_name' => '',
'site_link' => '',
'property_link' => '',
);
$tags = array_merge( $tags, $args );
extract( $tags );
$tags = array( "{user_mail}",
"{user_name}",
"{submitted_date}",
"{site_name}",
"{site_link}",
"{current_time}",
'{property_name}',
'{property_link}');
$values = array( $user_mail,
$user_name ,
$submitted_date ,
get_bloginfo( 'name' ) ,
get_home_url(),
date("F j, Y, g:i a"),
$property_name,
$property_link
);
$message = str_replace($tags, $values, $body);
return $message;
}
public static function approve_publish_property_email( $post_id ) {
$mail = new OpalEstate_Send_Email_Approve();
$mail->set_pros( $post_id );
$return = self::send_mail_now( $mail );
echo json_encode( $return ); die();
}
}
Opalestate_Emails::init();

216
inc/class-opalestate-enqueue.php Executable file
View File

@@ -0,0 +1,216 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Enqueue
*
* @version 1.0
*/
class OpalEstate_Enqueue {
/**
* Constructor
*/
public function __construct() {
add_action( 'wp_enqueue_scripts', [ $this, 'load_scripts' ] );
add_action( 'wp_head', [ $this, 'add_custom_styles' ] );
}
/**
* Load javascript and css
*/
public function load_scripts() {
$api = opalestate_get_map_api_uri();
wp_enqueue_script( 'opalestate-google-maps', $api, null, '0.0.1', false );
wp_enqueue_script( 'infobox', OPALESTATE_PLUGIN_URL . 'assets/js/infobox.js', [ 'jquery' ], OPALESTATE_VERSION, false );
wp_enqueue_script( 'markerclusterer', OPALESTATE_PLUGIN_URL . 'assets/js/markerclusterer.js', [ 'jquery' ], '1.3', false );
wp_enqueue_script( 'opalestate-scripts', OPALESTATE_PLUGIN_URL . 'assets/js/opalestate.js', [ 'jquery' ], OPALESTATE_VERSION, true );
wp_enqueue_script( 'opalestate-country-select', OPALESTATE_PLUGIN_URL . 'assets/js/country-select.js', [ 'jquery' ], OPALESTATE_VERSION, true );
wp_enqueue_script( 'noUiSlider', OPALESTATE_PLUGIN_URL . 'assets/js/nouislider.min.js', [ 'jquery' ], '1.0.0', true );
wp_enqueue_script( 'fitvids', OPALESTATE_PLUGIN_URL . 'assets/js/jquery.fitvids.js', [ 'jquery' ], '1.0.0', true );
// load google map for searchable
wp_enqueue_script( 'opalestate-gmap', OPALESTATE_PLUGIN_URL . 'assets/js/frontend/googlemaps.js', [ 'jquery' ], '1.3', false );
wp_enqueue_script( 'opalestate-messages', OPALESTATE_PLUGIN_URL . 'assets/js/frontend/property.js', [ 'jquery' ], '1.3', false );
wp_enqueue_style( 'opalestate-style', OPALESTATE_PLUGIN_URL . '/assets/opalestate.css' );
wp_enqueue_style( 'font-awesome', OPALESTATE_PLUGIN_URL . 'assets/3rd/fontawesome/css/all.min.css', null, '1.3', false );
// load tooltips css3
wp_enqueue_style( 'hint', OPALESTATE_PLUGIN_URL . 'assets/hint.min.css', null, '1.3', false );
// load tooltips css3
wp_enqueue_style( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/css/select2.min.css', null, '1.3', false );
wp_enqueue_script( 'select2', OPALESTATE_PLUGIN_URL . 'assets/3rd/select2/js/select2.min.js', null, '1.3', false );
wp_register_script( 'chart-js', OPALESTATE_PLUGIN_URL . 'assets/js/chart.min.js', null, '2.8.0', true );
wp_register_style( 'tooltipster', OPALESTATE_PLUGIN_URL . 'assets/3rd/tooltipster/css/tooltipster.bundle.min.css', [], false );
wp_register_script( 'tooltipster', OPALESTATE_PLUGIN_URL . 'assets/3rd/tooltipster/js/tooltipster.bundle.min.js', [ 'jquery' ], false, true );
if ( is_single_property() ) {
wp_enqueue_script( 'chart-js' );
}
if ( is_single_property() || is_single_agent() || is_single_agency() ) {
wp_enqueue_style( 'tooltipster' );
wp_enqueue_script( 'tooltipster' );
}
// load global variables
wp_localize_script( 'opalestate-scripts', 'opalesateJS',
[
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'siteurl' => get_template_directory_uri(),
'mapiconurl' => OPALESTATE_PLUGIN_URL . 'assets/map/',
'rtl' => is_rtl() ? 'true' : 'false',
'confirmed' => esc_html__( 'Are you sure to remove?', 'opalestate-pro' ),
'error_upload_size' => esc_html__( 'This file is has large volume size, please try to upload other.', 'opalestate-pro' ),
'size_image' => opalestate_options( 'upload_image_max_size', 0.5 ) * 1000000,
'mfile_image' => opalestate_options( 'upload_image_max_files', 10 ),
'size_other' => opalestate_options( 'upload_other_max_size', 0.8 ) * 1000000,
'mfile_other' => opalestate_options( 'upload_other_max_files', 10 ),
] );
///
$this->register_enqueue();
}
/**
* Register and enqueue javascript, css library
*/
public function register_enqueue() {
wp_register_script(
'jquery-modernizr',
OPALESTATE_PLUGIN_URL . '/assets/3rd/magnific-popup/jquery.magnific-popup.min.js',
[
'jquery',
],
'4.4.3',
true
);
wp_enqueue_script( 'jquery-magnific-popup' );
wp_register_script( 'jquery-sticky-kit', trailingslashit( OPALESTATE_PLUGIN_URL ) . 'assets/3rd/sticky/jquery.sticky-kit.min.js', [], null, true );
wp_enqueue_script( 'jquery-sticky-kit' );
wp_enqueue_script( 'opalestate-elementor', OPALESTATE_PLUGIN_URL . 'assets/js/frontend/elementor.js', [], null, true );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style( 'jquery-ui-datepicker-style', OPALESTATE_PLUGIN_URL . '/assets/3rd/datepicker.css' );
///
wp_register_script( 'jquery-toast',
OPALESTATE_PLUGIN_URL . 'assets/3rd/toast/jquery.toast.js', [], null, true );
wp_enqueue_script( 'jquery-toast' );
wp_register_script(
'jquery-swiper',
OPALESTATE_PLUGIN_URL . '/assets/3rd/swiper/js/swiper.min.js',
[
'jquery',
],
'4.4.3',
true
);
wp_enqueue_script( 'jquery-swiper' );
}
/**
* Add custom styles.
*/
public function add_custom_styles() {
$custom = '';
$status_color = $this->add_custom_property_status_color();
if ( $status_color ) {
$custom .= $status_color;
}
$label_color = $this->add_custom_property_label_color();
if ( $label_color ) {
$custom .= $label_color;
}
if ( $custom ) {
echo '<style type="text/css">' . $custom . '</style>';
}
}
/**
* Add custom property status color.
*
* @return string
*/
public function add_custom_property_status_color() {
$statuses = Opalestate_Taxonomy_Status::get_list();
$custom = '';
if ( $statuses ) {
foreach ( $statuses as $status ) {
$bg = get_term_meta( $status->term_id, 'opalestate_status_lb_bg', true );
$color = get_term_meta( $status->term_id, 'opalestate_status_lb_color', true );
if ( $bg || $color ) {
$custom .= '.property-status-' . trim( $status->slug ) . ' { ';
if ( $bg ) {
$custom .= 'background-color:' . $bg . ' !important;';
}
if ( $color ) {
$custom .= 'color:' . $color . '!important';
}
$custom .= ' } ';
}
}
}
return $custom;
}
/**
* Add custom property status color.
*
* @return string
*/
public function add_custom_property_label_color() {
$labels = Opalestate_Taxonomy_Label::get_list();
$custom = '';
if ( $labels ) {
foreach ( $labels as $label ) {
$bg = get_term_meta( $label->term_id, 'opalestate_label_lb_bg', true );
$color = get_term_meta( $label->term_id, 'opalestate_label_lb_color', true );
if ( $bg || $color ) {
$custom .= '.property-label-' . trim( $label->slug ) . ' { ';
if ( $bg ) {
$custom .= 'background-color:' . $bg . ' !important;';
}
if ( $color ) {
$custom .= 'color:' . $color . '!important';
}
$custom .= ' } ';
}
}
}
return $custom;
}
}
new OpalEstate_Enqueue();

395
inc/class-opalestate-html.php Executable file
View File

@@ -0,0 +1,395 @@
<?php
/**
* HTML elements
*
* A helper class for outputting common HTML elements, such as product drop downs
*
* @package Opalestate
* @subpackage Classes/HTML
* @copyright Copyright (c) 2015, Pippin Williamson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.5
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Opalestate_HTML_Elements Class
*
* @since 1.5
*/
class Opalestate_HTML_Elements {
public $form_id = '';
/**
* Renders an ajax user search field
*
* @param array $args
* @return string text field with ajax search
* @since 2.0
*
*/
public function ajax_user_search( $args = [] ) {
$defaults = [
'name' => 'user_id',
'value' => isset( $args['default'] ) ? $args['default'] : null,
'placeholder' => esc_html__( 'Enter username', 'opalestate-pro' ),
'label' => null,
'desc' => null,
'class' => '',
'disabled' => false,
'autocomplete' => 'off',
'data' => false,
];
$args = wp_parse_args( $args, $defaults );
$args['class'] = 'opalestate-ajax-user-search ' . $args['class'];
$output = '<span class="opalestate_user_search_wrap">';
$output .= $this->text_field( $args );
$output .= '<span class="opalestate_user_search_results hidden"><a class="opalestate-ajax-user-cancel" aria-label="' . esc_html__( 'Cancel',
'opalestate-pro' ) . '" href="#">x</a><span></span></span>';
$output .= '</span>';
return $output;
}
/**
* Text Field
*
* Renders an HTML Text field.
*
* @param array $args Arguments for the text field.
*
* @return string The text field.
* @since 1.0
* @access public
*
*/
public function text_field( $field_args, $args = [] ) {
$defaults = [
'id' => '',
'value' => isset( $field_args['default'] ) ? $field_args['default'] : null,
'name' => '',
'description' => null,
'placeholder' => '',
'class' => 'regular-text form-control',
'disabled' => false,
'autocomplete' => 'off',
'data' => false,
'default' => '',
'required' => false,
];
$args = wp_parse_args( $field_args, $defaults );
$disabled = '';
if ( $args['disabled'] ) {
$disabled = ' disabled="disabled"';
}
$data = '';
if ( ! empty( $args['data'] ) ) {
foreach ( $args['data'] as $key => $value ) {
$data .= 'data-' . $key . '="' . $value . '" ';
}
}
if ( $args['required'] ) {
$data .= ' required="required" ';
}
$output = '<span id="opalestate-' . sanitize_key( $this->form_id . $args['id'] ) . '-wrap">';
$output .= '<label class="opalestate-label" for="opalestate-' . sanitize_key( $this->form_id . $args['id'] ) . '">' . esc_html( $args['name'] ) . '</label>';
$output .= '<input type="text" name="' . esc_attr( $args['id'] ) . '" id="opalestate-' . esc_attr( $this->form_id . $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $args['class'] . '" ' . $data . '' . $disabled . '/>';
if ( ! empty( $args['description'] ) ) {
$output .= '<span class="opalestate-description">' . esc_html( $args['description'] ) . '</span>';
}
$output .= '</span>';
return $output;
}
/**
* Date Picker
*
* Renders a date picker field.
*
* @param array $args Arguments for the date picker.
*
* @return string The date picker.
* @since 1.5
* @access public
*
*/
public function date_field( $args = [] ) {
if ( empty( $args['class'] ) ) {
$args['class'] = 'opalestate-datepicker form-control';
} elseif ( ! strpos( $args['class'], 'opalestate-datepicker' ) ) {
$args['class'] .= ' opalestate-datepicker form-control';
}
return $this->text_field( $args );
}
/**
* Textarea
*
* Renders an HTML textarea.
*
* @param array $args Arguments for the textarea.
*
* @return string The textarea.
* @since 1.0
* @access public
*
*/
public function textarea_field( $args = [] ) {
$defaults = [
'name' => '',
'value' => isset( $args['default'] ) ? $args['default'] : null,
'label' => null,
'description' => null,
'class' => 'large-text',
'disabled' => false,
];
$args = wp_parse_args( $args, $defaults );
$disabled = '';
if ( $args['disabled'] ) {
$disabled = ' disabled="disabled"';
}
$output = '<span id="opalestate-' . sanitize_key( $this->form_id . $args['id'] ) . '-wrap">';
$output .= '<label class="opalestate-label" for="opalestate-' . sanitize_key( $this->form_id . $args['id'] ) . '">' . esc_html( $args['name'] ) . '</label>';
$data = '';
if ( $args['required'] ) {
$data .= ' required="required" ';
}
$output .= '<textarea name="' . esc_attr( $args['id'] ) . '" id="opalestate-' . esc_attr( $this->form_id . $args['id'] ) . '" class="' . $args['class'] . '"' . $disabled . ' ' . $data . ' >' . esc_attr( $args['value'] ) . '</textarea>';
if ( ! empty( $args['description'] ) ) {
$output .= '<span class="opalestate-description">' . esc_html( $args['description'] ) . '</span>';
}
$output .= '</span>';
return $output;
}
/**
* Dropdown
*
* Renders an HTML Dropdown.
*
* @param array $args Arguments for the dropdown.
*
* @return string The dropdown.
* @since 1.0
* @access public
*
*/
public function select_field( $field_args = [] ) {
$defaults = [
'options' => [],
'name' => null,
'class' => 'form-control',
'id' => '',
'autocomplete' => 'off',
'selected' => 0,
'chosen' => false,
'placeholder' => null,
'multiple' => false,
'select_atts' => false,
'show_option_all' => esc_html__( 'All', 'opalestate-pro' ),
'show_option_none' => esc_html__( 'None', 'opalestate-pro' ),
'data' => [],
'readonly' => false,
'disabled' => false,
'required' => '',
];
$args = wp_parse_args( $field_args, $defaults );
$data_elements = '';
foreach ( $args['data'] as $key => $value ) {
$data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
}
$multiple = '';
if ( $args['multiple'] ) {
$multiple = 'MULTIPLE';
}
if ( $args['chosen'] ) {
$args['class'] .= ' opalestate-select-chosen';
}
$placeholder = '';
if ( $args['placeholder'] ) {
$placeholder = $args['placeholder'];
}
$output = '<label class="opalestate-label" for="' . esc_attr( sanitize_key( str_replace( '-', '_', $this->form_id . $args['id'] ) ) ) . '">' . esc_html( $args['name'] ) . '</label>';
$data = '';
if ( $args['required'] ) {
$data .= ' required="required" ';
}
$output .= sprintf(
'<select ' . $data . ' name="%1$s" id="%2$s" autocomplete="%8$s" class="opalestate-select %3$s" %4$s %5$s data-placeholder="%6$s" %7$s>',
esc_attr( $args['id'] ),
esc_attr( sanitize_key( str_replace( '-', '_', $this->form_id . $args['id'] ) ) ),
esc_attr( $args['class'] ),
$multiple,
$args['select_atts'],
$placeholder,
$data_elements,
$args['autocomplete']
);
if ( $args['show_option_all'] ) {
if ( $args['multiple'] ) {
$selected = selected( true, in_array( 0, $args['selected'] ), false );
} else {
$selected = selected( $args['selected'], 0, false );
}
// $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
}
if ( ! empty( $args['options'] ) ) {
if ( $args['show_option_none'] ) {
if ( $args['multiple'] ) {
$selected = selected( true, in_array( -1, $args['selected'] ), false );
} else {
$selected = selected( $args['selected'], -1, false );
}
// $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
}
foreach ( $args['options'] as $key => $option ) {
if ( $args['multiple'] && is_array( $args['selected'] ) ) {
$selected = selected( true, in_array( $key, $args['selected'] ), false );
} else {
$selected = selected( $args['selected'], $key, false );
}
$output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
}
}
$output .= '</select>';
return $output;
}
public function hidden_field( $args ) {
$defaults = [
'id' => '',
'value' => isset( $args['default'] ) ? $args['default'] : null,
'name' => '',
'description' => null,
'placeholder' => '',
'class' => 'regular-text form-control',
'disabled' => false,
'autocomplete' => 'off',
'data' => false,
'default' => '',
'required' => false,
];
$args = wp_parse_args( $args, $defaults );
$output = '<input type="hidden" name="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" class="' . $args['class'] . '" />';
return $output;
}
public function render_field( $field ) {
switch ( $field['type'] ) {
case 'date':
return $this->date_field( $field );
break;
case 'text':
return $this->text_field( $field );
break;
case 'hidden':
return $this->hidden_field( $field );
break;
case 'textarea':
return $this->textarea_field( $field );
break;
case 'user':
return $this->ajax_user_search( $field );
break;
case 'select':
return $this->select_field( $field );
break;
default:
# code...
break;
}
}
public function render_form( $fields ) {
static $id_counter = 0;
if ( function_exists( 'wp_unique_id' ) ) {
$form_id = wp_unique_id( 'opalestate-form-' );
} else {
$form_id = 'opalestate-form-' . (string) ++$id_counter;
}
$output = '';
$this->form_id = $form_id;
foreach ( $fields as $field ) {
$wrap = '';
if ( isset( $field['before_row'] ) ) {
$wrap .= $field['before_row'];
}
$wrap .= '<div class="form-group">';
$wrap .= $this->render_field( $field );
$wrap .= '</div>';
if ( isset( $field['after_row'] ) ) {
$wrap .= $field['after_row'];
}
$output .= $wrap;
}
return $output;
}
}

252
inc/class-opalestate-install.php Executable file
View File

@@ -0,0 +1,252 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
class Opalestate_Install {
/**
* Install Opalestate.
*/
public static function install() {
if ( ! is_blog_installed() ) {
return;
}
// Check if we are not already running this routine.
if ( 'yes' === get_transient( 'opalestate_installing' ) ) {
return;
}
// If we made it till here nothing is running yet, lets set the transient now.
set_transient( 'opalestate_installing', 'yes', MINUTE_IN_SECONDS * 10 );
static::create_options();
static::create_tables();
static::create_roles();
static::setup_environment();
static::update_opalestate_version();
if ( function_exists( 'opalmembership_install' ) ) {
// opalmembership_install();
}
// Add the transient to redirect.
set_transient( '_opalestate_activation_redirect', true, 30 );
delete_transient( 'opalestate_installing' );
// Remove rewrite rules and then recreate rewrite rules.
flush_rewrite_rules();
do_action( 'opalestate_installed' );
}
/**
* Setup Opalestate environment - post types, taxonomies, endpoints.
*/
private static function setup_environment() {
Opalestate_PostType_Property::definition();
Opalestate_PostType_Agent::definition();
Opalestate_PostType_Agency::definition();
}
/**
* Set up the database tables which the plugin needs to function.
*/
private static function create_tables() {
OpalEstate_User_Search::install();
OpalEstate_User_Message::install();
OpalEstate_User_Request_Viewing::install();
}
/**
* Create roles and capabilities.
*/
public static function create_roles() {
$roles = new Opalestate_Roles();
$roles->add_roles();
$roles->add_caps();
}
/**
* Default options.
*
* Sets up the default options used on the settings page.
*/
private static function create_options() {
global $opalestate_options;
// Add Upgraded From Option
$current_version = get_option( 'opalestate_version' );
if ( $current_version ) {
update_option( 'opalestate_version_upgraded_from', $current_version );
}
// Setup some default options
$options = [];
//Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency
if ( empty( $current_version ) ) {
$options['test_mode'] = 1;
$options['currency'] = 'USD';
$options['currency_position'] = 'before';
$options['measurement_unit'] = 'sq ft';
$options['google_map_api_keys'] = 'AIzaSyCfMVNIa7khIqYHCw6VBn8ShUWWm4tjbG8';
$options['admin_approve'] = 'on';
$options['require_input_price'] = 'on';
$options['from_name'] = get_bloginfo( 'name' );
$options['from_email'] = get_bloginfo( 'admin_email' );
$options['message_log'] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'bedrooms_opt' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'parking_opt' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'bathrooms_opt' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'areasize_opt' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'price_opt' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'bedrooms_opt_v' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'parking_opt_v' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'bathrooms_opt_v' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'areasize_opt_v' ] = 1;
$options[ OPALESTATE_PROPERTY_PREFIX . 'price_opt_v' ] = 1;
$options['enable_single_amenities'] = 'on';
$options['enable_single_facilities'] = 'on';
$options['enable_single_attachments'] = 'on';
$options['enable_single_video'] = 'on';
$options['enable_single_map'] = 'on';
$options['enable_single_nearby'] = 'on';
$options['enable_single_walkscores'] = 'on';
$options['enable_single_apartments'] = 'on';
$options['enable_single_floor_plans'] = 'on';
$options['enable_single_views_statistics'] = 'on';
$options['single_views_statistics_limit'] = 8;
$options['enable_property_reviews'] = 'on';
$options['enable_agency_reviews'] = 'on';
$options['enable_agent_reviews'] = 'on';
$options['enable_submission_tab_media'] = 'on';
$options['enable_submission_tab_location'] = 'on';
$options['enable_submission_tab_amenities'] = 'on';
$options['enable_submission_tab_facilities'] = 'on';
$options['enable_submission_tab_apartments'] = 'on';
$options['enable_submission_tab_floor_plans'] = 'on';
}
// Checks if the Success Page option exists AND that the page exists
if ( ! get_post( opalestate_get_option( 'user_management_page' ) ) ) {
// Purchase Confirmation (Success) Page
$profile_page = wp_insert_post(
[
'post_title' => esc_html__( 'User Dashboard Page', 'opalestate-pro' ),
'post_content' => esc_html__( '', 'opalestate-pro' ),
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'comment_status' => 'closed',
'page_template' => 'user-management.php',
]
);
// Store our page IDs
$options['user_management_page'] = $profile_page;
}
// Checks if the Success Page option exists AND that the page exists
if ( ! get_post( opalestate_get_option( 'user_myaccount_page' ) ) ) {
$saved_link_page = wp_insert_post(
[
'post_title' => esc_html__( 'My Account', 'opalestate-pro' ),
'post_content' => esc_html__( '[opalestate_myaccount]', 'opalestate-pro' ),
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'comment_status' => 'closed',
]
);
// Store our page IDs
$options['user_myaccount_page'] = $saved_link_page;
}
// Checks if the Success Page option exists AND that the page exists
if ( ! get_post( opalestate_get_option( 'submission_page' ) ) ) {
// Purchase Confirmation (Success) Page
$submission_page = wp_insert_post(
[
'post_title' => esc_html__( 'Property Submission Page', 'opalestate-pro' ),
'post_content' => esc_html__( '[opalestate_submission]', 'opalestate-pro' ),
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'comment_status' => 'closed',
]
);
// Store our page IDs
$options['submission_page'] = $submission_page;
}
// Checks if the Success Page option exists AND that the page exists
if ( ! get_post( opalestate_get_option( 'search_map_properties_page' ) ) ) {
// Purchase Confirmation (Success) Page
$search_map_properties_page = wp_insert_post(
[
'post_title' => esc_html__( 'Search Map Properties Page', 'opalestate-pro' ),
'post_content' => esc_html__( '[opalestate_search_map_properties]', 'opalestate-pro' ),
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'comment_status' => 'closed',
'page_template' => 'fullwidth-page.php',
]
);
// Store our page IDs
$options['search_map_properties_page'] = $search_map_properties_page;
}
// Populate some default values
update_option( 'opalestate_settings', array_merge( $opalestate_options, $options ) );
// Add a temporary option to note that Give pages have been created
set_transient( '_opalestate_installed', $options, 30 );
}
/**
* Update Opalestate version to current.
*/
private static function update_opalestate_version() {
update_option( 'opalestate_version', OPALESTATE_VERSION );
}
}
/**
* Install user roles on sub-sites of a network
*
* Roles do not get created when Give is network activation so we need to create them during admin_init
*
* @return void
* @since 1.0
*/
function opalestate_install_roles_on_network() {
global $wp_roles;
if ( ! is_object( $wp_roles ) ) {
return;
}
if ( ! array_key_exists( 'opalestate_manager', $wp_roles->roles ) ) {
$roles = new Opalestate_Roles;
$roles->add_roles();
$roles->add_caps();
} else {
// remove_role( 'opalestate_manager' );
// remove_role( 'opalestate_manager' );
// $roles = new Opalestate_Roles;
// $roles->remove_caps();
}
}
add_action( 'admin_init', 'opalestate_install_roles_on_network' );

273
inc/class-opalestate-roles.php Executable file
View File

@@ -0,0 +1,273 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Opalestate_Roles Class
*
* This class handles the role creation and assignment of capabilities for those roles.
*
* These roles let us have Opalestate Accountants, Opalestate Workers, etc, each of whom can do
* certain things within the plugin
*
* @since 1.0.0
*/
class Opalestate_Roles {
/**
* Get things going
*
* @since 1.0.0
*/
public function __construct() {
add_filter( 'opalestate_map_meta_cap', array( $this, 'meta_caps' ), 10, 4 );
}
/**
* Add new shop roles with default WP caps
*
* @access public
* @since 1.0.0
* @return void
*/
public function add_roles() {
add_role( 'opalestate_manager', esc_html__( 'Opal Estate Manager', 'opalestate-pro' ), array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true,
'unfiltered_html' => true,
'upload_files' => true,
'export' => true,
'import' => true,
'delete_others_pages' => true,
'delete_others_posts' => true,
'delete_pages' => true,
'delete_private_pages' => true,
'delete_private_posts' => true,
'delete_published_pages' => true,
'delete_published_posts' => true,
'edit_others_pages' => true,
'edit_others_posts' => true,
'edit_pages' => true,
'edit_private_pages' => true,
'edit_private_posts' => true,
'edit_published_pages' => true,
'edit_published_posts' => true,
'manage_categories' => true,
'manage_links' => true,
'moderate_comments' => true,
'publish_pages' => true,
'publish_posts' => true,
'read_private_pages' => true,
'read_private_posts' => true
) );
add_role( 'opalestate_agent', esc_html__( 'Opal Estate Agent', 'opalestate-pro' ), array(
'read' => true,
'edit_posts' => false,
'upload_files' => true,
'delete_posts' => false,
'publish_posts' => false,
'upload_files' =>true,
'edit_attachments' =>true,
'delete_attachments' =>true,
'delete_post' => true,
) );
add_role( 'opalestate_agency', esc_html__( 'Opal Estate Agency', 'opalestate-pro' ), array(
'read' => true,
'edit_posts' => false,
'upload_files' => true,
'delete_posts' => false,
'publish_posts' => false,
) );
}
/**
* Add new shop-specific capabilities
*
* @access public
* @since 1.0.0
* @global WP_Roles $wp_roles
* @return void
*/
public function add_caps() {
global $wp_roles;
if ( class_exists('WP_Roles') ) {
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
}
if ( is_object( $wp_roles ) ) {
$wp_roles->add_cap( 'opalestate_manager', 'view_opalestate_reports' );
$wp_roles->add_cap( 'opalestate_manager', 'view_opalestate_sensitive_data' );
$wp_roles->add_cap( 'opalestate_manager', 'export_opalestate_reports' );
$wp_roles->add_cap( 'opalestate_manager', 'manage_opalestate_settings' );
$wp_roles->add_cap( 'administrator', 'view_opalestate_reports' );
$wp_roles->add_cap( 'administrator', 'view_opalestate_sensitive_data' );
$wp_roles->add_cap( 'administrator', 'export_opalestate_reports' );
$wp_roles->add_cap( 'administrator', 'manage_opalestate_settings' );
// Add the main post type capabilities
$capabilities = $this->get_core_caps();
foreach ( $capabilities as $cap_group ) {
foreach ( $cap_group as $cap ) {
$wp_roles->add_cap( 'opalestate_manager', $cap );
$wp_roles->add_cap( 'administrator', $cap );
$wp_roles->add_cap( 'opalestate_agent', $cap );
}
}
$wp_roles->add_cap( 'opalestate_accountant', 'edit_opalestate_properties' );
$wp_roles->add_cap( 'opalestate_accountant', 'read_private_forms' );
$wp_roles->add_cap( 'opalestate_accountant', 'view_opalestate_reports' );
$wp_roles->add_cap( 'opalestate_accountant', 'export_opalestate_reports' );
$wp_roles->add_cap( 'opalestate_accountant', 'edit_opalestate_payments' );
}
}
/**
* Gets the core post type capabilities
*
* @access public
* @since 1.0.0
* @return array $capabilities Core post type capabilities
*/
public function get_core_caps() {
$capabilities = array();
$capability_types = array( 'opalestate_properties', 'opalestate_agents' );
foreach ( $capability_types as $capability_type ) {
$capabilities[ $capability_type ] = array(
// Post type
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
// Terms
"manage_{$capability_type}_terms",
"edit_{$capability_type}_terms",
"delete_{$capability_type}_terms",
"assign_{$capability_type}_terms",
// Custom
"view_{$capability_type}_stats"
);
}
return $capabilities;
}
/**
* Map meta caps to primitive caps
*
* @access public
* @since 2.0
* @return array $caps
*/
public function meta_caps( $caps, $cap, $user_id, $args ) {
switch( $cap ) {
case 'view_opalestate_properties_stats' :
if( empty( $args[0] ) ) {
break;
}
$form = get_post( $args[0] );
if ( empty( $form ) ) {
break;
}
if( user_can( $user_id, 'view_opalestate_reports' ) || $user_id == $form->post_author ) {
$caps = array();
}
break;
}
return $caps;
}
/**
* Remove core post type capabilities (called on uninstall)
*
* @access public
* @since 1.0
* @return void
*/
public function remove_caps() {
global $wp_roles;
if ( class_exists( 'WP_Roles' ) ) {
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
}
if ( is_object( $wp_roles ) ) {
/** Opalestate Manager Capabilities */
$wp_roles->remove_cap( 'opalestate_manager', 'view_opalestate_reports' );
$wp_roles->remove_cap( 'opalestate_manager', 'view_opalestate_sensitive_data' );
$wp_roles->remove_cap( 'opalestate_manager', 'export_opalestate_reports' );
$wp_roles->remove_cap( 'opalestate_manager', 'manage_opalestate_settings' );
/** Site Administrator Capabilities */
$wp_roles->remove_cap( 'administrator', 'view_opalestate_reports' );
$wp_roles->remove_cap( 'administrator', 'view_opalestate_sensitive_data' );
$wp_roles->remove_cap( 'administrator', 'export_opalestate_reports' );
$wp_roles->remove_cap( 'administrator', 'manage_opalestate_settings' );
/** Remove the Main Post Type Capabilities */
$capabilities = $this->get_core_caps();
foreach ( $capabilities as $cap_group ) {
foreach ( $cap_group as $cap ) {
$wp_roles->remove_cap( 'opalestate_manager', $cap );
$wp_roles->remove_cap( 'administrator', $cap );
$wp_roles->remove_cap( 'opalestate_agent', $cap );
}
}
/** Shop Accountant Capabilities */
$wp_roles->remove_cap( 'opalestate_accountant', 'edit_opalestate_properties' );
$wp_roles->remove_cap( 'opalestate_accountant', 'read_private_forms' );
$wp_roles->remove_cap( 'opalestate_accountant', 'view_opalestate_reports' );
$wp_roles->remove_cap( 'opalestate_accountant', 'export_opalestate_reports' );
}
}
}

142
inc/class-template-loader.php Executable file
View File

@@ -0,0 +1,142 @@
<?php
/**
* Opalestate_Template_Loader
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Template_Loader {
/**
* Initialize template loader
*
* @access public
* @return void
*/
public static function init() {
add_filter( 'template_include', [ __CLASS__, 'templates' ] );
}
/**
* Default templates
*
* @access public
* @param $template
* @return string
* @throws Exception
*/
public static function templates( $template ) {
$post_type = get_post_type();
$custom_post_types = [ 'opalestate_property', 'opalestate_agent', 'opalestate_agency' ];
if ( in_array( $post_type, $custom_post_types ) ) {
if ( is_tax( 'opalestate_agency' ) ) {
return self::locate( 'single-opalestate_agency' );
}
if ( is_archive() ) {
return self::locate( 'archive-' . $post_type );
}
if ( is_single() ) {
return self::locate( 'single-' . $post_type );
}
}
if ( is_post_type_archive( 'opalestate_agency' ) ) {
return self::locate( 'archive-opalestate_agency' );
}
if ( is_post_type_archive( 'opalestate_agent' ) ) {
return self::locate( 'archive-opalestate_agent' );
}
return $template;
}
/**
* Gets template path
*
* @access public
* @param $name
* @param $plugin_dir
* @return string
* @throws Exception
*/
public static function locate( $name, $plugin_dir = OPALESTATE_PLUGIN_DIR, $warning = true ) {
$template = '';
// Current theme base dir
if ( ! empty( $name ) ) {
$template = locate_template( "{$name}.php" );
}
// Child theme
if ( ! $template && ! empty( $name ) && file_exists( get_stylesheet_directory() . "/opalestate/{$name}.php" ) ) {
$template = get_stylesheet_directory() . "/opalestate/{$name}.php";
}
// Original theme
if ( ! $template && ! empty( $name ) && file_exists( get_template_directory() . "/opalestate/{$name}.php" ) ) {
$template = get_template_directory() . "/opalestate/{$name}.php";
}
// Plugin
if ( ! $template && ! empty( $name ) && file_exists( $plugin_dir . "/templates/{$name}.php" ) ) {
$template = $plugin_dir . "/templates/{$name}.php";
}
// Nothing found
if ( empty( $template ) && $warning ) {
throw new Exception( "Template /templates/{$name}.php in plugin dir {$plugin_dir} not found." );
}
return $template;
}
/**
* Loads template content
*
* @param string $name
* @param array $args
* @param string $plugin_dir
* @return string
* @throws Exception
*/
public static function get_template_part( $name, $args = [], $slug = null ) {
if ( is_array( $args ) && count( $args ) > 0 ) {
extract( $args, EXTR_SKIP );
}
if ( $slug ) {
$path = self::locate( $name . '-' . $slug, OPALESTATE_PLUGIN_DIR, false );
if ( empty( $path ) ) {
$path = self::locate( $name, OPALESTATE_PLUGIN_DIR );
}
} else {
$path = self::locate( $name, OPALESTATE_PLUGIN_DIR );
}
ob_start();
include $path;
$result = ob_get_contents();
ob_end_clean();
return $result;
}
}
Opalestate_Template_Loader::init();

View File

@@ -0,0 +1,141 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Agent
*
* @version 1.0
*/
class OpalEstate_Abstract_Query{
/**
* Preserve args
*
* @since $id
* @access public
*
* @var string
*/
public $group;
/**
* Preserve args
*
* @since $id
* @access public
*
* @var array
*/
public $_args = array();
/**
* The args to pass to the give_get_payments() query
*
* @since $id
* @access public
*
* @var array
*/
public $args = array();
/**
* The collection found based on the criteria set
*
* @since $id
* @access public
*
* @var array
*/
public $collection = array();
public function set_filters() {
}
public function unset_filters() {
}
public function get_list(){
}
public function status() {
}
public function page() {
}
/**
* Posts Per Page
*
* @since 1.0
* @access public
*
* @return void
*/
public function per_page() {
}
/**
* Order by
*
* @since 1.0
* @access public
*
* @return void
*/
public function orderby() {
}
public function get_by_user() {
}
public function search () {
}
/**
* Set a query variable.
*
* @since 1.0
* @access public
*
* @param $query_var
* @param $value
*/
public function __set( $query_var, $value ) {
if ( in_array( $query_var, array( 'meta_query', 'tax_query' ) ) ) {
$this->args[ $query_var ][] = $value;
} else {
$this->args[ $query_var ] = $value;
}
}
/**
* Unset a query variable.
*
* @since 1.0
* @access public
*
* @param $query_var
*/
public function __unset( $query_var ) {
unset( $this->args[ $query_var ] );
}
}

View File

@@ -0,0 +1,686 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Cache {
/**
* Instance.
*
* @since 1.8.7
* @access private
* @var Opalestate_Cache
*/
static private $instance;
/**
* Flag to check if caching enabled or not.
*
* @since 2.0
* @access private
* @var
*/
private $is_cache;
/**
* Singleton pattern.
*
* @since 1.8.7
* @access private
* Opalestate_Cache constructor.
*/
private function __construct() {
}
/**
* Get instance.
*
* @since 1.8.7
* @access public
* @return static
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Opalestate_Cache ) ) {
self::$instance = new Opalestate_Cache();
}
return self::$instance;
}
/**
* Setup hooks.
*
* @since 1.8.7
* @access public
*/
public function setup() {
// Currently enable cache only for backend.
self::$instance->is_cache = ( defined( 'GIVE_CACHE' ) ? GIVE_CACHE : opalestate_is_setting_enabled( opalestate_get_option( 'cache', 'enabled' ) ) ) && is_admin();
// weekly delete all expired cache.
Give_Cron::add_weekly_event( array( $this, 'delete_all_expired' ) );
add_action( 'save_post_opalestate_forms', array( $this, 'delete_form_related_cache' ) );
add_action( 'save_post_opalestate_payment', array( $this, 'delete_payment_related_cache' ) );
add_action( 'opalestate_deleted_opalestate-donors_cache', array( $this, 'delete_donor_related_cache' ), 10, 3 );
add_action( 'opalestate_deleted_opalestate-donations_cache', array( $this, 'delete_donations_related_cache' ), 10, 3 );
add_action( 'opalestate_save_settings_opalestate_settings', array( __CLASS__, 'flush_cache' ) );
add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
add_action( 'admin_notices', array( $this, '__notices' ) );
}
/**
* Prevent caching on certain pages
*
* @since 2.0.5
* @access public
* @credit WooCommerce
*/
public static function prevent_caching() {
if ( ! is_blog_installed() ) {
return;
}
$page_ids = array_filter( array(
opalestate_get_option( 'success_page' ),
opalestate_get_option( 'failure_page' ),
opalestate_get_option( 'history_page' ),
) );
if (
is_page( $page_ids )
|| is_singular( 'opalestate_forms' )
) {
self::set_nocache_constants();
nocache_headers();
}
}
/**
* Set constants to prevent caching by some plugins.
*
* @since 2.0.5
* @access public
* @credit WooCommerce
*
* @param mixed $return Value to return. Previously hooked into a filter.
*
* @return mixed
*/
public static function set_nocache_constants( $return = true ) {
return $return;
}
/**
* Notices function.
*
* @since 2.0.5
* @access public
* @credit WooCommerce
*/
public function __notices() {
if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
return;
}
$config = w3_instance( 'W3_Config' );
$enabled = $config->get_integer( 'dbcache.enabled' );
$settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
if ( $enabled && ! in_array( 'opalestate-pro', $settings, true ) ) {
?>
<div class="error">
<p><?php echo wp_kses_post( sprintf( esc_html__( 'In order for <strong>database caching</strong> to work with Give you must add %1$s to the "Ignored query stems" option in <a href="%2$s">W3 Total Cache settings</a>.', 'opalestate-pro' ), '<code>opalestate</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache#dbcache_reject_sql' ) ) ) ); ?></p>
</div>
<?php
}
}
/**
* Get cache key.
*
* @since 1.8.7
*
* @param string $action Cache key prefix.
* @param array $query_args (optional) Query array.
* @param bool $is_prefix
*
* @return string
*/
public static function get_key( $action, $query_args = null, $is_prefix = true ) {
// Bailout.
if ( empty( $action ) ) {
return new WP_Error( 'opalestate_invalid_cache_key_action', esc_html__( 'Do not pass empty action to generate cache key.', 'opalestate-pro' ) );
}
// Set cache key.
$cache_key = $is_prefix ? "opalestate_cache_{$action}" : $action;
// Bailout.
if ( ! empty( $query_args ) ) {
$cache_key = "{$cache_key}_" . substr( md5( serialize( $query_args ) ), 0, 15 );
}
/**
* Filter the cache key name.
*
* @since 2.0
*/
return apply_filters( 'opalestate_get_cache_key', $cache_key, $action, $query_args );
}
/**
* Get cache.
*
* @since 1.8.7
*
* @param string $cache_key
* @param bool $custom_key
* @param mixed $query_args
*
* @return mixed
*/
public static function get( $cache_key, $custom_key = false, $query_args = array() ) {
if ( ! self::is_valid_cache_key( $cache_key ) ) {
if( empty( $cache_key ) ) {
return new WP_Error( 'opalestate_empty_cache_key', esc_html__( 'Do not pass invalid empty cache key', 'opalestate-pro' ) );
}elseif ( ! $custom_key ) {
return new WP_Error( 'opalestate_invalid_cache_key', esc_html__( 'Cache key format should be opalestate_cache_*', 'opalestate-pro' ) );
}
$cache_key = self::get_key( $cache_key, $query_args );
}
$option = get_option( $cache_key );
// Backward compatibility (<1.8.7).
if ( ! is_array( $option ) || empty( $option ) || ! array_key_exists( 'expiration', $option ) ) {
return $option;
}
// Get current time.
$current_time = current_time( 'timestamp', 1 );
if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) {
$option = $option['data'];
} else {
$option = false;
}
return $option;
}
/**
* Set cache.
*
* @since 1.8.7
*
* @param string $cache_key
* @param mixed $data
* @param int|null $expiration Timestamp should be in GMT format.
* @param bool $custom_key
* @param mixed $query_args
*
* @return mixed
*/
public static function set( $cache_key, $data, $expiration = null, $custom_key = false, $query_args = array() ) {
if ( ! self::is_valid_cache_key( $cache_key ) ) {
if ( ! $custom_key ) {
return new WP_Error( 'opalestate_invalid_cache_key', esc_html__( 'Cache key format should be opalestate_cache_*', 'opalestate-pro' ) );
}
$cache_key = self::get_key( $cache_key, $query_args );
}
$option_value = array(
'data' => $data,
'expiration' => ! is_null( $expiration )
? ( $expiration + current_time( 'timestamp', 1 ) )
: null,
);
$result = update_option( $cache_key, $option_value, false );
return $result;
}
/**
* Delete cache.
*
* Note: only for internal use
*
* @since 1.8.7
*
* @param string|array $cache_keys
*
* @return bool|WP_Error
*/
public static function delete( $cache_keys ) {
$result = true;
$invalid_keys = array();
if ( ! empty( $cache_keys ) ) {
$cache_keys = is_array( $cache_keys ) ? $cache_keys : array( $cache_keys );
foreach ( $cache_keys as $cache_key ) {
if ( ! self::is_valid_cache_key( $cache_key ) ) {
$invalid_keys[] = $cache_key;
$result = false;
}
delete_option( $cache_key );
}
}
if ( ! $result ) {
$result = new WP_Error(
'opalestate_invalid_cache_key',
__( 'Cache key format should be opalestate_cache_*', 'opalestate-pro' ),
$invalid_keys
);
}
return $result;
}
/**
* Delete all logging cache.
*
* Note: only for internal use
*
* @since 1.8.7
* @access public
* @global wpdb $wpdb
*
* @param bool $force If set to true then all cached values will be delete instead of only expired
*
* @return bool
*/
public static function delete_all_expired( $force = false ) {
global $wpdb;
$options = $wpdb->get_results(
$wpdb->prepare(
"SELECT option_name, option_value
FROM {$wpdb->options}
Where option_name
LIKE '%%%s%%'",
'opalestate_cache'
),
ARRAY_A
);
// Bailout.
if ( empty( $options ) ) {
return false;
}
$current_time = current_time( 'timestamp', 1 );
// Delete log cache.
foreach ( $options as $option ) {
$option['option_value'] = maybe_unserialize( $option['option_value'] );
if (
(
! self::is_valid_cache_key( $option['option_name'] )
|| ! is_array( $option['option_value'] ) // Backward compatibility (<1.8.7).
|| ! array_key_exists( 'expiration', $option['option_value'] ) // Backward compatibility (<1.8.7).
|| empty( $option['option_value']['expiration'] )
|| ( $current_time < $option['option_value']['expiration'] )
)
&& ! $force
) {
continue;
}
self::delete( $option['option_name'] );
}
}
/**
* Get list of options like.
*
* Note: only for internal use
*
* @since 1.8.7
* @access public
*
* @param string $option_name
* @param bool $fields
*
* @return array
*/
public static function get_options_like( $option_name, $fields = false ) {
global $wpdb;
$field_names = $fields ? 'option_name, option_value' : 'option_name';
if ( $fields ) {
$options = $wpdb->get_results(
$wpdb->prepare(
"SELECT {$field_names }
FROM {$wpdb->options}
Where option_name
LIKE '%%%s%%'",
"opalestate_cache_{$option_name}"
),
ARRAY_A
);
} else {
$options = $wpdb->get_col(
$wpdb->prepare(
"SELECT *
FROM {$wpdb->options}
Where option_name
LIKE '%%%s%%'",
"opalestate_cache_{$option_name}"
),
1
);
}
if ( ! empty( $options ) && $fields ) {
foreach ( $options as $index => $option ) {
$option['option_value'] = maybe_unserialize( $option['option_value'] );
$options[ $index ] = $option;
}
}
return $options;
}
/**
* Check cache key validity.
*
* @since 1.8.7
* @access public
*
* @param $cache_key
*
* @return bool
*/
public static function is_valid_cache_key( $cache_key ) {
$is_valid = ( false !== strpos( $cache_key, 'opalestate_cache_' ) );
/**
* Filter the flag which tell about cache key valid or not
*
* @since 2.0
*/
return apply_filters( 'opalestate_is_valid_cache_key', $is_valid, $cache_key );
}
/**
* Get cache from group
*
* @since 2.0
* @access public
*
* @param int $id
* @param string $group
*
* @return mixed
*/
public static function get_group( $id, $group = '' ) {
$cached_data = null;
// Bailout.
if ( self::$instance->is_cache && ! empty( $id ) ) {
$group = self::$instance->filter_group_name( $group );
$cached_data = wp_cache_get( $id, $group );
$cached_data = false !== $cached_data ? $cached_data : null;
}
return $cached_data;
}
/**
* Cache small chunks inside group
*
* @since 2.0
* @access public
*
* @param int $id
* @param mixed $data
* @param string $group
* @param int $expire
*
* @return bool
*/
public static function set_group( $id, $data, $group = '', $expire = 0 ) {
$status = false;
// Bailout.
if ( ! self::$instance->is_cache || empty( $id ) ) {
return $status;
}
$group = self::$instance->filter_group_name( $group );
$status = wp_cache_set( $id, $data, $group, $expire );
return $status;
}
/**
* Cache small db query chunks inside group
*
* @since 2.0
* @access public
*
* @param int $id
* @param mixed $data
*
* @return bool
*/
public static function set_db_query( $id, $data ) {
$status = false;
// Bailout.
if ( ! self::$instance->is_cache || empty( $id ) ) {
return $status;
}
return self::set_group( $id, $data, 'opalestate-db-queries', 0 );
}
/**
* Get cache from group
*
* @since 2.0
* @access public
*
* @param string $id
*
* @return mixed
*/
public static function get_db_query( $id ) {
return self::get_group( $id, 'opalestate-db-queries' );
}
/**
* Delete group cache
*
* @since 2.0
* @access public
*
* @param int|array $ids
* @param string $group
* @param int $expire
*
* @return bool
*/
public static function delete_group( $ids, $group = '', $expire = 0 ) {
$status = false;
// Bailout.
if ( ! self::$instance->is_cache || empty( $ids ) ) {
return $status;
}
$group_prefix = $group;
$group = self::$instance->filter_group_name( $group );
// Delete single or multiple cache items from cache.
if ( ! is_array( $ids ) ) {
$status = wp_cache_delete( $ids, $group );
self::$instance->get_incrementer( true );
/**
* Fire action when cache deleted for specific id.
*
* @since 2.0
*
* @param string $ids
* @param string $group
* @param int $expire
*/
do_action( "opalestate_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status );
} else {
foreach ( $ids as $id ) {
$status = wp_cache_delete( $id, $group );
self::$instance->get_incrementer( true );
/**
* Fire action when cache deleted for specific id .
*
* @since 2.0
*
* @param string $ids
* @param string $group
* @param int $expire
*/
do_action( "opalestate_deleted_{$group_prefix}_cache", $id, $group, $expire, $status );
}
}
return $status;
}
/**
* Get unique incrementer.
*
* @see https://core.trac.wordpress.org/ticket/4476
* @see https://www.tollmanz.com/invalidation-schemes/
*
* @since 2.0
* @access public
*
* @param bool $refresh
* @param string $incrementer_key
*
* @return string
*/
public function get_incrementer( $refresh = false, $incrementer_key = 'opalestate-cache-incrementer-db-queries' ) {
$incrementer_value = wp_cache_get( $incrementer_key );
if ( false === $incrementer_value || true === $refresh ) {
$incrementer_value = (string) microtime( true );
wp_cache_set( $incrementer_key, $incrementer_value );
}
return $incrementer_value;
}
/**
* Flush cache on cache setting enable/disable
* Note: only for internal use
*
* @since 2.0
* @access public
*
* @param bool $force Delete cache forcefully.
*
* @return bool
*/
public static function flush_cache( $force = false ) {
return false;
}
/**
* Filter the group name
*
* @since 2.0
* @access private
*
* @param $group
*
* @return mixed
*/
private function filter_group_name( $group ) {
/**
* Filter the group name
*
* @since 2.1.0
*/
$filtered_group = apply_filters( 'opalestate_cache_filter_group_name', '', $group );
if ( empty( $filtered_group ) ) {
switch ( $group ) {
case 'opalestate-db-queries':
$incrementer = self::$instance->get_incrementer();
break;
default:
$incrementer = self::$instance->get_incrementer( false, 'opalestate-cache-incrementer' );
}
$current_blog_id = get_current_blog_id();
$filtered_group = "{$group}_{$current_blog_id}_{$incrementer}";
}
return $filtered_group;
}
/**
* Disable cache.
*
* @since 2.0
* @access public
*/
public static function disable() {
self::get_instance()->is_cache = false;
}
/**
* Enable cache.
*
* @since 2.0
* @access public
*/
public static function enable() {
self::get_instance()->is_cache = true;
}
}
// Initialize
Opalestate_Cache::get_instance()->setup();

View File

@@ -0,0 +1,111 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class OpalEstate_GeoLocation {
/*
* function to geocode address, it will return false if unable to geocode address
*/
public static function get_points_in_miles( $latitude, $longitude, $miles ) {
$equator = 69.172;
$maxlat = $latitude + $miles / $EQUATOR_LAT_MILE;
$minlat = $latitude - ($maxlat - $latitude);
$maxlong = $longitude + $miles / (cos($minlat * M_PI / 180) * $equator);
$minlong = $longitude - ($maxlong - $longitude);
return array(
'minlat' => $minlat,
'maxlat' => $maxlat,
'minlong' => $minlong,
'maxlong' => $maxlong
);
}
/*
* function to geocode address, it will return false if unable to geocode address
*/
public static function calculate( $lat1, $long1, $lat2, $long2 ) {
$EARTH_RADIUS_MILES = 3963;
$dist = 0;
//convert degrees to radians
$lat1 = $lat1 * M_PI / 180;
$long1 = $long1 * M_PI / 180;
$lat2 = $lat2 * M_PI / 180;
$long2 = $long2 * M_PI / 180;
if ($lat1 != $lat2 || $long1 != $long2) {
$dist = sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($long2 - $long1);
$dist = $EARTH_RADIUS_MILES * (-1 * atan($dist / sqrt(1 - $dist * $dist)) + M_PI / 2);
}
return $dist;
}
/*
* function to geocode address, it will return false if unable to geocode address
*/
public static function geocode( $address ){
// url encode the address
$address = urlencode($address);
// google map geocode api url
$url = opalestate_get_map_search_api_uri( $address );
// get the json response
// $resp_json = file get contents($url);
$resp_json = wp_remote_get($url);
// decode the json
$resp = json_decode($resp_json, true);
// response status will be 'OK', if able to geocode given address
if($resp['status']=='OK'){
// get the important data
$lati = isset($resp['results'][0]['geometry']['location']['lat']) ? $resp['results'][0]['geometry']['location']['lat'] : "";
$longi = isset($resp['results'][0]['geometry']['location']['lng']) ? $resp['results'][0]['geometry']['location']['lng'] : "";
$formatted_address = isset($resp['results'][0]['formatted_address']) ? $resp['results'][0]['formatted_address'] : "";
// verify if data is complete
if($lati && $longi && $formatted_address){
// put the data in the array
$data_arr = array();
array_push(
$data_arr,
$lati,
$longi,
$formatted_address
);
return $data_arr;
}else{
return false;
}
}
else{
return false;
}
}
}

View File

@@ -0,0 +1,290 @@
<?php
/**
* Class Opalestate_User_MetaBox
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_User_MetaBox {
public function get_front_base_field( $prefix ) {
$management = [
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar',
'type' => 'hidden',
'single' => 1,
'limit' => 1,
],
[
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar_id',
'type' => 'uploader',
'single' => 1,
'limit' => 1,
],
[
'id' => 'first_name',
'name' => esc_html__( 'First Name', 'opalestate-pro' ),
'type' => 'text',
'attributes' => [
'required' => 'required',
],
],
[
'id' => 'last_name',
'name' => esc_html__( 'Last Name', 'opalestate-pro' ),
'type' => 'text',
'attributes' => [
'required' => 'required',
],
],
[
'id' => 'description',
'name' => esc_html__( 'Biographical Info', 'opalestate-pro' ),
'type' => 'textarea',
'description' => esc_html__( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'opalestate-pro' ),
'after_row' => '<hr>',
],
];
return $management;
}
public function get_avatar_fields( $prefix ) {
return [
[
'name' => esc_html__( 'Avatar Pictures', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar',
'type' => is_admin() ? 'file' : 'opal_upload',
'avatar' => true,
],
];
}
public function get_address_fields( $prefix ) {
return [
[
'name' => esc_html__( 'Location', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
'id' => $prefix . "location",
'taxonomy' => 'opalestate_location', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
'before_row' => '<div class="field-row-3">',
],
[
'name' => esc_html__( 'State / Province', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in state of estate panel', 'opalestate-pro' ),
'id' => $prefix . "state",
'taxonomy' => 'opalestate_state', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
],
[
'name' => esc_html__( 'City / Town', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in city of estate panel', 'opalestate-pro' ),
'id' => $prefix . "city",
'taxonomy' => 'opalestate_city', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
'after_row' => '</div>',
],
[
'name' => esc_html__( 'Address', 'opalestate-pro' ),
'id' => "{$prefix}address",
'type' => 'text',
'attributes' => [
'required' => 'required',
],
],
[
'id' => "{$prefix}map",
'name' => esc_html__( 'Map Location', 'opalestate-pro' ),
'type' => 'opal_map',
'sanitization_cb' => 'opal_map_sanitise',
'split_values' => true,
'attributes' => [
'required' => 'required',
],
],
];
}
public function get_job_fields( $prefix ) {
return [
[
'name' => esc_html__( 'Job', 'opalestate-pro' ),
'id' => "{$prefix}job",
'type' => 'text',
'before_row' => '<div class="field-row-2">',
],
[
'name' => esc_html__( 'Company', 'opalestate-pro' ),
'id' => "{$prefix}company",
'type' => 'text',
'after_row' => '</div>',
],
];
}
public function get_office_fields( $prefix ) {
return $this->get_base_fields( $prefix );
}
public function get_base_front_fields( $prefix ) {
return [
[
'name' => esc_html__( 'Email', 'opalestate-pro' ),
'id' => "{$prefix}email",
'type' => 'text',
'before_row' => '<div class="field-row-2">',
],
[
'name' => esc_html__( 'Website', 'opalestate-pro' ),
'id' => "{$prefix}web",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'id' => "{$prefix}phone",
'type' => 'text',
],
[
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
'id' => "{$prefix}mobile",
'type' => 'text',
],
[
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
'id' => "{$prefix}fax",
'type' => 'text',
'after_row' => '</div>',
],
];
}
public function get_base_fields( $prefix ) {
return [
[
'id' => "{$prefix}featured",
'name' => esc_html__( 'Is Featured', 'opalestate-pro' ),
'type' => 'switch',
'description' => esc_html__( 'Set member as featured', 'opalestate-pro' ),
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
],
[
'id' => "{$prefix}trusted",
'name' => esc_html__( 'Trusted', 'opalestate-pro' ),
'type' => 'switch',
'description' => esc_html__( 'Set this member as Trusted Member', 'opalestate-pro' ),
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Avatar Pictures', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
'id' => $prefix . 'avatar',
'type' => is_admin() ? 'file' : 'uploader',
'single' => true,
'avatar' => true,
],
[
'name' => esc_html__( 'Email', 'opalestate-pro' ),
'id' => "{$prefix}email",
'type' => 'text',
'before_row' => '<div class="field-row-2">',
],
[
'name' => esc_html__( 'Website', 'opalestate-pro' ),
'id' => "{$prefix}web",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'id' => "{$prefix}phone",
'type' => 'text',
],
[
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
'id' => "{$prefix}mobile",
'type' => 'text',
],
[
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
'id' => "{$prefix}fax",
'type' => 'text',
'after_row' => '</div>',
],
];
}
public function get_social_fields( $prefix ) {
return [
[
'name' => esc_html__( 'Twitter', 'opalestate-pro' ),
'id' => "{$prefix}twitter",
'type' => 'text_url',
'before_row' => '<div class="field-row-2">',
],
[
'name' => esc_html__( 'Facebook', 'opalestate-pro' ),
'id' => "{$prefix}facebook",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Google', 'opalestate-pro' ),
'id' => "{$prefix}google",
'type' => 'text_url',
],
[
'name' => esc_html__( 'LinkedIn', 'opalestate-pro' ),
'id' => "{$prefix}linkedin",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Pinterest', 'opalestate-pro' ),
'id' => "{$prefix}pinterest",
'type' => 'text_url',
],
[
'name' => esc_html__( 'Instagram', 'opalestate-pro' ),
'id' => "{$prefix}instagram",
'type' => 'text_url',
'after_row' => '</div>',
],
];
}
}

View File

@@ -0,0 +1,157 @@
<?php
class Opalestate_Multilingual {
/**
* The current language.
*
* @var string
*/
protected $current_language;
/**
* The default language.
*
* @var string
*/
protected $default_language;
/**
* Constructor.
*/
public function __construct() {
// Make sure to create class after/within 'setup_theme' action.
if ( ! did_action( 'setup_theme' ) ) {
_doing_it_wrong(
__CLASS__ . '::' . __FUNCTION__,
'The class must be call after "setup_theme" has been fire.',
'1.0'
);
} else {
$this->check();
}
}
/**
* Get the current language.
*
* @return string|null
*/
public function get_current_language() {
return $this->current_language ?: null;
}
/**
* Get the main language.
*
* @return string|null
*/
public function get_default_language() {
return $this->default_language ?: null;
}
/**
* Get the original post.
*
* @param int $post_id The post ID.
* @return int
*/
public function get_original_post( $post_id ) {
return $this->get_original_object( $post_id, 'post' );
}
/**
* Get the original object ID (post, taxonomy, etc...).
*
* @param int $id The object id.
* @param string $type Optional, post type or taxonomy name of the object, defaults to 'post'.
* @return int|null
*/
public function get_original_object( $id, $type = 'post' ) {
return icl_object_id( $id, $type, true, $this->get_default_language() );
}
/**
* Perform check the language.
*
* @access private
*/
public function check() {
switch ( true ) {
case ( static::is_wpml() ):
global $sitepress;
$this->current_language = $sitepress->get_current_language();
$this->default_language = $sitepress->get_default_language();
break;
case ( static::is_polylang() ):
$this->default_language = pll_default_language( 'slug' );
$this->current_language = pll_current_language( 'slug' );
break;
}
}
/**
* Sets the specified language.
*
* @param string|null $language The language name.
* @return void
*/
public function set_language( $language = null ) {
if ( static::is_polylang() ) {
$this->set_polylang_language( $language );
} elseif ( static::is_wpml() ) {
global $sitepress;
$sitepress->switch_lang( $language, ! headers_sent() );
}
}
/**
* Sets the specified language on PLL.
*
* @sse \PLL_Choose_Lang::set_language()
*
* @param string|null $language The language name.
* @return void
*/
public function set_polylang_language( $language = null ) {
if ( ! static::is_polylang() ) {
return;
}
/* @var \Polylang $polylang */
$polylang = PLL();
// In frontend, if no language given, get the preferred language
// according to the browser preferences.
if ( empty( $language ) && ( ! is_admin() && ! defined( 'DOING_CRON' ) ) ) {
$curlang = $polylang->choose_lang->get_preferred_language();
} else {
$curlang = $polylang->model->get_language( trim( $language ) );
}
if ( $curlang instanceof \PLL_Language ) {
$polylang->curlang = $curlang;
$GLOBALS['text_direction'] = $curlang->is_rtl ? 'rtl' : 'ltr'; // @codingStandardsIgnoreLine
}
}
/**
* Determine if we're using WPML.
*
* Since PolyLang has a compatibility layer for WPML, we'll have to consider that too.
*
* @return bool
*/
public static function is_wpml() {
return ( defined( 'ICL_SITEPRESS_VERSION' ) && ! static::is_polylang() );
}
/**
* Determine if we're using PolyLang.
*
* @return bool
*/
public static function is_polylang() {
return class_exists( 'Polylang' ) && function_exists( 'pll_current_language' );
}
}

View File

@@ -0,0 +1,299 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Give_Session Class
*
* @since 1.0
*/
class Opalestate_Session {
/**
* Holds our session data
*
* @var array
* @access private
* @since 1.0
*/
private $session;
/**
* Whether to use PHP $_SESSION or WP_Session
*
* @var bool
* @access private
* @since 1.0
*/
private $use_php_sessions = false;
/**
* Expiration Time
*
* @var int
* @access private
* @since 1.0
*/
private $exp_option = false;
/**
* Session index prefix
*
* @var string
* @access private
* @since 1.0
*/
private $prefix = '';
/**
* Get things started
*
* Defines our WP_Session constants, includes the necessary libraries and
* retrieves the WP Session instance
*
* @since 1.0
*/
public function __construct() {
$this->use_php_sessions = $this->use_php_sessions();
$this->exp_option = 604800; //opalestate_get_option( 'session_lifetime' );
if ( $this->use_php_sessions ) {
if ( is_multisite() ) {
$this->prefix = '_' . get_current_blog_id();
}
// Use PHP SESSION (must be enabled via the OPALMEMBERSHIP_USE_PHP_SESSIONS constant)
add_action( 'init', array( $this, 'maybe_start_session' ), - 2 );
} else {
// Use WP_Session (default)
if ( ! defined( 'WP_SESSION_COOKIE' ) ) {
define( 'WP_SESSION_COOKIE', 'opalestate_wp_session' );
}
if ( ! class_exists( 'Recursive_ArrayAccess' ) ) {
// require_once OPALESTATE_PLUGIN_DIR . 'inc/libraries/class-recursive-arrayaccess.php';
}
if ( ! class_exists( 'WP_Session' ) ) {
require_once OPALESTATE_PLUGIN_DIR . 'inc/libraries/wp_session/class-wp-session.php';
require_once OPALESTATE_PLUGIN_DIR . 'inc/libraries/wp-session.php';
}
add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 );
add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 );
}
if ( empty( $this->session ) && ! $this->use_php_sessions ) {
add_action( 'plugins_loaded', array( $this, 'init' ), - 1 );
} else {
add_action( 'init', array( $this, 'init' ), - 1 );
}
}
/**
* Setup the WP_Session instance
*
* @access public
* @since 1.0
* @return array $this->session
*/
public function init() {
if ( $this->use_php_sessions ) {
$this->session = isset( $_SESSION[ 'opalestate-pro' . $this->prefix ] ) && is_array( $_SESSION[ 'opalestate-pro' . $this->prefix ] ) ? $_SESSION[ 'opalestate-pro' . $this->prefix ] : array();
} else {
$this->session = WP_Session::get_instance();
}
return $this->session;
}
/**
* Retrieve session ID
*
* @access public
* @since 1.0
* @return string Session ID
*/
public function get_id() {
return $this->session->session_id;
}
/**
* Retrieve a session variable
*
* @access public
* @since 1.0
*
* @param string $key Session key
*
* @return string Session variable
*/
public function get( $key = '', $default = false ) {
$key = sanitize_key( $key );
return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : $default;
}
/**
* Set a session variable
*
* @since 1.0
*
* @param $key $_SESSION key
* @param $value $_SESSION variable
*
* @return mixed Session variable
*/
public function set( $key, $value ) {
$key = sanitize_key( $key );
if ( is_array( $value ) ) {
$this->session[ $key ] = serialize( $value );
} else {
$this->session[ $key ] = $value;
}
if ( $this->use_php_sessions ) {
$_SESSION[ 'opalestate-pro' . $this->prefix ] = $this->session;
}
return $this->session[ $key ];
}
/**
* Set Cookie Variant Time
*
* @description Force the cookie expiration variant time to custom expiration option, less and hour; defaults to 23 hours (set_expiration_variant_time used in WP_Session)
*
* @access public
* @since 1.0
*
* @return int
*/
public function set_expiration_variant_time() {
return ( ! empty( $this->exp_option ) ? ( intval( $this->exp_option ) - 3600 ) : 30 * 60 * 23 );
}
/**
* Set the Cookie Expiration
*
* @description Force the cookie expiration time if set, default to 24 hours
*
* @access public
* @since 1.0
*
* @return int
*/
public function set_expiration_time() {
return ( ! empty( $this->exp_option ) ? intval( $this->exp_option ) : 30 * 60 * 24 );
}
/**
* Starts a new session if one hasn't started yet.
*
* @return null
* Checks to see if the server supports PHP sessions
* or if the OPALMEMBERSHIP_USE_PHP_SESSIONS constant is defined
*
* @access public
* @since 1.0
* @return bool $ret True if we are using PHP sessions, false otherwise
*/
public function use_php_sessions() {
$ret = false;
// If the database variable is already set, no need to run autodetection
$opalestate_use_php_sessions = (bool) get_option( 'opalestate_use_php_sessions' );
if ( ! $opalestate_use_php_sessions ) {
// Attempt to detect if the server supports PHP sessions
if ( function_exists( 'session_start' ) && ! ini_get( 'safe_mode' ) ) {
$this->set( 'opalestate_use_php_sessions', 1 );
if ( $this->get( 'opalestate_use_php_sessions' ) ) {
$ret = true;
// Set the database option
update_option( 'opalestate_use_php_sessions', true );
}
}
} else {
$ret = $opalestate_use_php_sessions;
}
// Enable or disable PHP Sessions based on the OPALMEMBERSHIP_USE_PHP_SESSIONS constant
if ( defined( 'OPALMEMBERSHIP_USE_PHP_SESSIONS' ) && OPALMEMBERSHIP_USE_PHP_SESSIONS ) {
$ret = true;
} else if ( defined( 'OPALMEMBERSHIP_USE_PHP_SESSIONS' ) && ! OPALMEMBERSHIP_USE_PHP_SESSIONS ) {
$ret = false;
}
return (bool) apply_filters( 'opalestate_use_php_sessions', $ret );
}
/**
* Maybe Start Session
*
* @description Starts a new session if one hasn't started yet.
* @see http://php.net/manual/en/function.session-set-cookie-params.php
*/
public function maybe_start_session() {
// session_destroy(); //Uncomment for testing ONLY
if ( ! session_id() && ! headers_sent() ) {
$lifetime = current_time( 'timestamp' ) + $this->set_expiration_time();
session_start();
setcookie( session_name(), session_id(), $lifetime ); //
setcookie( session_name() . '_expiration', $lifetime, $lifetime );
}
}
/**
* Get Session Expiration
*
* @description Looks at the session cookies and returns the expiration date for this session if applicable
*
*/
public function get_session_expiration() {
$expiration = false;
if ( session_id() && isset( $_COOKIE[ session_name() . '_expiration' ] ) ) {
$expiration = date( 'D, d M Y h:i:s', intval( $_COOKIE[ session_name() . '_expiration' ] ) );
}
return $expiration;
}
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* Opalestate_WalkScore
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* An implementation of the Walk Score API in PHP.
*
* @see http://www.walkscore.com/
*/
class Opalestate_WalkScore {
/**
* Constructs a WalkScore object
*
* @param string $wsapikey
* Walk Score API key obtainable at http://www.walkscore.com/request-api-key.php
*/
function __construct($wsapikey) {
// a Walk Score API key is required
if (!isset($wsapikey)) {
throw new Exception("Walk Score API key required");
}
$this->wsapikey = $wsapikey;
}
/**
* Makes the API call using curl
*
* @param string $url
* The URL to send the request to
* @param array $options
* The options to send as the query appended to the URL
*/
private function make_api_call($url, $options) {
$options['wsapikey'] = $this->wsapikey;
$options['format'] = 'json';
$query = http_build_query($options);
$response_url = $url . '?' . $query;
$response = wp_remote_get($response_url);
$response = wp_remote_retrieve_body( $response );
$response = json_decode($response);
return $response;
}
/**
* Implement the Walk Score Public Transit API
*
* @param string $call
* Which call to make to the Public Transit API
* - score: Returns the Transit Score for a given location.
* - stop search: Returns information about stops near a given location.
* - network search: Returns connected stops and routes near a given location.
* - stop detail: Returns details for a single stop.
* - route detail: eturns details for a single route.
* - supported cities: Returns a list of cities for which scores are available.
* @param array $options
* Options to send to the Public Transit API. Keys and values are dependent
* on the call made.
* @return
* An object containing the results of the call.
* @see http://www.walkscore.com/services/public-transit-api.php
*/
public function PublicTransit($call, $options = array()) {
$api_url = 'http://transit.walkscore.com/transit/';
$calls = array(
'score' => 'score/',
'stop search' => 'search/stops/',
'network search' => 'search/network/',
'stop detail' => 'stop/ID/',
'route detail' => 'route/ID/',
'supported cities' => 'supported/cities/',
);
$api_url .= $calls[$call];
return $this->make_api_call($api_url, $options);
}
/**
* Implementation of the Walk Score API
*
* @param array $options
* An array of options. The array keys to pass are:
* - mode: string, one of 'walk', 'bike', 'drive', or 'transit'.
* - origin: string containing a comma-separated lat,lng.
* - destination: string containing a comma-separated lat,lng.
* @todo Multiple destinations.
* @ see http://www.walkscore.com/professional/travel-time-api.php
*/
public function TravelTime($options = array()) {
if (!is_array($options)) {
throw new Exception("Input parameter must be an array.");
}
$modes = array('walk', 'bike', 'drive', 'transit');
if (!in_array($options['mode'], $modes)) {
throw new Exception("Mode parameter must be one of 'walk', 'bike', 'drive', or 'transit'.");
}
$response = $this->make_api_call('http://www.walkscore.com/api/v1/traveltime/json', $options);
return $response->response;
}
/**
* Implementation of the Walk Score API
*
* @param array $options
* An array of options. The array keys to pass are:
* - address: string containing the street address of the location
* - lat: string or number containing the latitude of the location
* - lon: string or number containing the longitude of the location
* @return
* An object containing the results of the call. An added property
* called status_description gives a human-readable description of
* the numeric status code returned in the object
* @see http://www.walkscore.com/services/api.php
*/
public function WalkScore($options = array()) {
if (!is_array($options)) {
throw new Exception("Input parameter must be an array.");
}
$response = $this->make_api_call('http://api.walkscore.com/score', $options);
// stuff the status code description in the response object
// so you don't have to look it up on the Walk Score website
$status_descriptions = array(
1 => 'Walk Score successfully returned.',
2 => 'Score is being calculated and is not currently available.',
30 => 'Invalid latitude/longitude.',
40 => 'Your WSAPIKEY is invalid.',
41 => 'Your daily API quota has been exceeded.',
42 => 'Your IP address has been blocked.',
);
$response->status_description = $status_descriptions[$response->status];
return $response;
}
/**
* Implementation of the Walk Shed API
*
* @param array $options
* An array of options. The array keys to pass are:
* - lat: string or number containing the latitude of the location
* - lon: string or number containing the longitude of the location
* @return
* An object containing the results of the call. An added property
* called status_description gives a human-readable description of
* the numeric status code returned in the object
* @see http://www.walkscore.com/services/api.php
*/
public function WalkShed($options = array()) {
if (!is_array($options)) {
throw new Exception("Input parameter must be an array.");
}
$response = $this->make_api_call('http://api.walkscore.com/walk_shed', $options);
// stuff the status code description in the response object
// so you don't have to look it up on the Walk Score website
$status_descriptions = array(
1 => 'Walk shed successfully returned.',
2 => 'Walk shed unavailable.',
30 => 'Invalid latitude/longitude.',
31 => 'Walk Score API internal error.',
40 => 'Your WSAPIKEY is invalid.',
41 => 'Your daily API quota has been exceeded.',
);
$response->status_description = $status_descriptions[$response->status];
return $response;
}
}

View File

@@ -0,0 +1,250 @@
<?php
/**
* Opalestate_Yelp
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Yelp {
// API constants, you shouldn't have to change these.
const API_HOST = "https://api.yelp.com";
const SEARCH_PATH = "/v3/businesses/search";
const BUSINESS_PATH = "/v3/businesses/"; // Business ID will come after slash.
const TOKEN_PATH = "/oauth2/token";
const GRANT_TYPE = "client_credentials";
public static function get_client_id() {
return opalestate_get_option( 'yelp_app_id', '' );
}
public static function get_app_secret() {
return opalestate_get_option( 'yelp_app_secret', '' );
}
public static function get_app_key() {
return opalestate_get_option( 'yelp_app_key', '' );
}
public static function get_categories() {
return opalestate_get_option( 'yelp_categories', [] );
}
public static function get_category_results_limit() {
return opalestate_get_option( 'yelp_number_results', 3 );
}
/**
* Given a bearer token, send a GET request to the API.
*
* @return OAuth bearer token, obtained using client_id and client_secret.
*/
public function obtain_bearer_token() {
$yelp_client_id = static::get_client_id();
$yelp_client_secret = static::get_app_secret();
$yelp_app_key = static::get_app_key();
return $yelp_app_key;
}
/**
* Makes a request to the Yelp API and returns the response
*
* @param $bearer_token API bearer token from obtain_bearer_token
* @param $host The domain host of the API
* @param $path The path of the API after the domain.
* @param $url_params Array of query-string parameters.
* @return The JSON response from the request
*/
public function request( $bearer_token, $host, $path, $url_params = [] ) {
// Send Yelp API Call
try {
$url = $host . $path . "?" . http_build_query( $url_params );
$args = [
'timeout' => 30,
'redirection' => 10,
'httpversion' => CURL_HTTP_VERSION_1_1,
'user-agent' => '',
'headers' => [
'authorization' => 'Bearer ' . $bearer_token,
],
'sslverify' => false,
];
$response = wp_remote_get( $url, $args );
$response = wp_remote_retrieve_body( $response );
} catch ( Exception $e ) {
}
return $response;
}
/**
* Query the Search API by a search term and location
*
* @param $bearer_token API bearer token from obtain_bearer_token
* @param $term The search term passed to the API
* @param $location The search location passed to the API
* @return The JSON response from the request
*/
public function search( $bearer_token, $term, $latitude, $longitude ) {
$url_params = [];
$url_params['term'] = $term;
$url_params['latitude'] = $latitude;
$url_params['longitude'] = $longitude;
$url_params['limit'] = static::get_category_results_limit();
return $this->request( $bearer_token, static::API_HOST, static::SEARCH_PATH, $url_params );
}
/**
* Query the Business API by business_id
*
* @param $bearer_token API bearer token from obtain_bearer_token
* @param $business_id The ID of the business to query
* @return The JSON response from the request
*/
public function get_business( $bearer_token, $business_id ) {
$business_path = $GLOBALS['BUSINESS_PATH'] . urlencode( $business_id );
return $this->request( $bearer_token, $GLOBALS['API_HOST'], $business_path );
}
public function query_api( $term, $latitude, $longitude ) {
$bearer_token = $this->obtain_bearer_token();
$response = json_decode( $this->search( $bearer_token, $term, $latitude, $longitude ) );
return $response;
}
public function get_results( $term, $latitude, $longitude ) {
if ( ! static::get_categories() ) {
return false;
}
$results = $this->query_api( $term, $latitude, $longitude );
if ( isset( $results->error ) && $results->error ) {
return false;
}
return $results;
}
public static function get_all_categories() {
return apply_filters( 'opalestate_yelp_all_categories',
[
'active' => [
'category' => esc_html__( 'Active Life', 'opalestate-pro' ),
'category_sign' => 'fa fa-bicycle',
],
'arts' => [
'category' => esc_html__( 'Arts & Entertainment', 'opalestate-pro' ),
'category_sign' => 'fa fa-music',
],
'auto' => [
'category' => esc_html__( 'Automotive', 'opalestate-pro' ),
'category_sign' => 'fa fa-car',
],
'beautysvc' => [
'category' => esc_html__( 'Beauty & Spas', 'opalestate-pro' ),
'category_sign' => 'fa fa-female',
],
'education' => [
'category' => esc_html__( 'Education', 'opalestate-pro' ),
'category_sign' => 'fa fa-graduation-cap',
],
'eventservices' => [
'category' => esc_html__( 'Event Planning & Services', 'opalestate-pro' ),
'category_sign' => 'fa fa-birthday-cake',
],
'financialservices' => [
'category' => esc_html__( 'Financial Services', 'opalestate-pro' ),
'category_sign' => 'fa fa-money',
],
'food' => [
'category' => esc_html__( 'Food', 'opalestate-pro' ),
'category_sign' => 'fa fa fa-cutlery',
],
'health' => [
'category' => esc_html__( 'Health & Medical', 'opalestate-pro' ),
'category_sign' => 'fa fa-medkit',
],
'homeservices' => [
'category' => esc_html__( 'Home Services ', 'opalestate-pro' ),
'category_sign' => 'fa fa-wrench',
],
'hotelstravel' => [
'category' => esc_html__( 'Hotels & Travel', 'opalestate-pro' ),
'category_sign' => 'fa fa-bed',
],
'localflavor' => [
'category' => esc_html__( 'Local Flavor', 'opalestate-pro' ),
'category_sign' => 'fa fa-coffee',
],
'localservices' => [
'category' => esc_html__( 'Local Services', 'opalestate-pro' ),
'category_sign' => 'fa fa-dot-circle-o',
],
'massmedia' => [
'category' => esc_html__( 'Mass Media', 'opalestate-pro' ),
'category_sign' => 'fa fa-television',
],
'nightlife' => [
'category' => esc_html__( 'Nightlife', 'opalestate-pro' ),
'category_sign' => 'fa fa-glass',
],
'pets' => [
'category' => esc_html__( 'Pets', 'opalestate-pro' ),
'category_sign' => 'fa fa-paw',
],
'professional' => [
'category' => esc_html__( 'Professional Services', 'opalestate-pro' ),
'category_sign' => 'fa fa-suitcase',
],
'publicservicesgovt' => [
'category' => esc_html__( 'Public Services & Government', 'opalestate-pro' ),
'category_sign' => 'fa fa-university',
],
'realestate' => [
'category' => esc_html__( 'Real Estate', 'opalestate-pro' ),
'category_sign' => 'fa fa-building-o',
],
'religiousorgs' => [
'category' => esc_html__( 'Religious Organizations', 'opalestate-pro' ),
'category_sign' => 'fa fa-cloud',
],
'restaurants' => [
'category' => esc_html__( 'Restaurants', 'opalestate-pro' ),
'category_sign' => 'fa fa-cutlery',
],
'shopping' => [
'category' => esc_html__( 'Shopping', 'opalestate-pro' ),
'category_sign' => 'fa fa-shopping-bag',
],
'transport' => [
'category' => esc_html__( 'Transportation', 'opalestate-pro' ),
'category_sign' => 'fa fa-bus',
],
]
);
}
public static function get_all_categories_options() {
$categories = static::get_all_categories();
$options = [];
foreach ( $categories as $key => $term ) {
$options[ $key ] = $term['category'];
}
return $options;
}
}

646
inc/cli/export.php Executable file
View File

@@ -0,0 +1,646 @@
<?php
class OpalEstate_Command {
public $path;
/**
* Constructor
*/
public function __construct(){
$this->path = OPALESTATE_PLUGIN_DIR;
// $this->cfg = json_decode( file get contents( $this->path.'project.json' ) );
$this->cfg = json_decode( wp_remote_get( $this->path.'project.json' ) );
$this->server = $this->cfg->server;
$this->oldurl = $this->cfg->oldurl;
$this->theme = $this->cfg->theme;
$this->name = $this->cfg->name;
$this->subpath = $this->cfg->subpath;
}
/**
* Write data in file
*/
private function output_file_content( $file_path, $output ) {
$fp = fopen( $file_path, 'w+' );
fwrite( $fp, $output );
fclose( $fp );
}
/**
* Get more options
*/
public function get_more_options(){
$data = array(
'header' => 'header-1',
'footer' => 'footer-1',
'page' => 'home-1'
);
if( isset($this->cfg->active) && $this->cfg->active ) {
$data = (array) $this->cfg->active;
}
return array(
'active' => $data,
'oldurl' => $this->oldurl,
'server' => $this->server,
"samples" => array(
'post' => array(),
'product' => array()
)
);
}
/**
* Export theme options in customizer
*/
public function options(){
return array();
$thememods = get_option( 'theme_mods_' . $this->theme );
$file = $this->path.'/sample/thememods.json';
$ids = array();
foreach( $thememods as $key => $mod ){
if( is_string($mod) ){
// $thememods[$key] = $this->_replace_uri( $mod, $this->oldurl, "SITE_URL_HERE");
if( preg_match( "#jpg|png|gif|svg#", $mod) && $mod ){
$ids[$key] = $this->find_image_id_byguid( $mod );
}
}
if( isset($thememods['wpopal_customize_css']) ){
unset( $thememods['wpopal_customize_css'] );
}
if( isset($thememods['osf_theme_custom_style']) ){
unset( $thememods['osf_theme_custom_style'] );
}
if( isset($thememods['sidebars_widgets']) ){
unset( $thememods['sidebars_widgets'] );
}
///
if( $key == 'custom_logo' && $mod ){
$ids[$key] = $mod;
}
}
$attachments = array();
if( $ids ){
foreach( $ids as $id ) {
$post = get_post( $id );
if( $post ) {
$attachments[$post->ID] = array(
'id' => $post->ID,
'guid' => wp_get_attachment_url( $post->ID ),
'post_parent' => $post->post_parent,
'post_name' => $post->post_name,
'post_date' => $post->post_date );
}
}
}
$options = array(
'woocommerce_single_image_width' => '',
'woocommerce_thumbnail_image_width' => '',
'woocommerce_thumbnail_cropping' => '',
'woocommerce_thumbnail_cropping_custom_height' => '',
'woocommerce_thumbnail_cropping_custom_width' => '',
"woocommerce_shop_page_id" => '',
"woocommerce_cart_page_id" => '',
'woocommerce_checkout_page_id' => '',
'woocommerce_myaccount_page_id' => '',
'woocommerce_terms_page_id' => '',
'yith_wcwl_wishlist_page_id' => ''
);
foreach( $options as $key => $value ){
$value = get_option( $key );
if( empty($value) ) {
unset( $options[$key] );
continue;
}
$options[$key] = $value;
}
$options['page_for_posts'] = 'Blog';
if( function_exists( 'wp_get_custom_css_post' ) ) {
$options['wp_css'] = wp_get_custom_css();
}
$data = array( 'thememods' => $thememods, 'attachments' => $attachments, "options" => $options );
// $this->output_file_content( $file, wp_json_encode($data ,JSON_PRETTY_PRINT ) );
return $data;
}
/**
* Replace URI in xml
*/
public function _replace_uri( $str, $oldurl, $server ){
$str = str_replace( str_replace("/","\/", $oldurl ), str_replace("/","\/", $server ), $str );
$str = str_replace( $oldurl, $server, $str );
$str = str_replace( str_replace("/","\\\\\\/", $oldurl ), str_replace("/","\\\\\\/", $server ), $str );
return $str;
}
/**
* Export config samples
*/
public function config_samples( $dev=0 ){
$data['samples'] = array();
$file = $this->path.$this->cfg->folder_source.'/samples.json';
$niches = $this->cfg->niches;
$single = $this->cfg->single;
$key = 0;
$data['samples'][] = array(
"name" => isset($single->name)?$single->name:"Sample",
"key" => "niche-".$key,
"url" => isset($single->url)?$single->url:"",
"demo" => isset($single->demo)?$single->demo:"",
"preview" => $this->cfg->server_source.'/screenshot.png',
"sample" => $this->cfg->server_source.'/data.zip'
);
$this->output_file_content( $file, wp_json_encode($data ) );
///
//$file = $this->path.'/wp-content/themes/'.$this->cfg->theme.'/project.json';
//$data = $this->cfg->themeinfo;
//$this->output_file_content( $file, json_encode($data , JSON_PRETTY_PRINT ) );
}
/**
* Export all pages
*/
public function pages(){
return array();
$excludes = array();
global $wpdb;
$post_type = 'page';
/// items
$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s and {$wpdb->posts}.post_content LIKE '%opalestate_%'", $post_type );
// grab a snapshot of post IDs, just in case it changes during the export
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE $where" );
$data = $this->export_json_ids( $post_ids, $excludes, $isattachement );
echo '<pre>' . print_r( $data ,1 );die;
//$file = $this->path.'sample/pages.json';
// $this->output_file_content( $file, wp_json_encode($data ) );
return $data;
}
/**
* Export all pages
*/
public function data_posttypes(){
$excludes = array();
$data = $this->export_posttype( array(
'opalestate_agent',
'opalestate_agency',
'opalestate_agent_ft',
'opalestate_agency_ft',
'opalestate_rating_ft',
'opalestate_property'
), $excludes );
// $file = ABSPATH.'src/json/elementor.json';
// $this->output_file_content( $file, wp_json_encode($data ) );
return $data;
}
/**
* get all attachments by post ids
*/
protected function get_attachment( $post_ids ) {
$attachments = array();
foreach ( $post_ids as $post_id) {
$value = get_post_meta($post_id, '_thumbnail_id', true);
if ( $value ) {
$attachments = array_merge( $attachments, array($value) );
}
$attachArgs = array(
'post_parent' => $post_id,
'post_type' => 'attachment',
'numberposts' => -1,
'post__not_in' => $attachments, //To skip duplicates
);
$attachList = get_children($attachArgs, ARRAY_A);
$attachments = array_merge($attachments, array_keys($attachList));
}
$ids = $this->get_images_posts( $post_ids );
if( $ids ){
$attachments = array_merge( $ids, $attachments );
}
return $attachments;
}
/**
* Export data posts by post type with attachments
*/
protected function export_posttype( $post_type, $excludes=array(), $isattachement=true ) {
global $wpdb;
/// items
if( is_array($post_type) ){
$tmp = "'".implode( "','", $post_type )."'";
$where = "{$wpdb->posts}.post_type IN( ".$tmp ." )";
} else {
$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $post_type );
}
// grab a snapshot of post IDs, just in case it changes during the export
$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE $where" );
return $this->export_json_ids( $post_ids, $excludes, $isattachement );
}
public function aa(){
global $wpdb;
$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", 240) );
$exls = array(
'_edit_last',
'_edit_lock',
'_elementor_version',
'_menu_item_type',
'_menu_item_menu_item_parent',
'_menu_item_object_id',
'_menu_item_object',
'_menu_item_target',
'_menu_item_classes',
'_menu_item_xfn',
'_menu_item_url',
'_elementor_css'
);
$tmp = array();
foreach( $postmeta as $key => $meta ){
unset( $postmeta[$key]->post_id );
unset( $postmeta[$key]->meta_id );
foreach( $exls as $exl ){
if( $meta->meta_key == $exl ){
unset( $postmeta[$key] );
}
}
}
foreach( $postmeta as $key => $meta ){
$tmp[$meta->meta_key] = $meta->meta_value;
}
}
/**
* export json data by ids
*/
protected function export_json_ids( $post_ids , $excludes, $isattachement ){
global $wpdb;
$output = array();
$export = array();
if( $isattachement ){
$ids = $this->get_attachment( $post_ids );
if( $ids ){
$where = 'WHERE ID IN (' . join( ',', $ids ) . ')';
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
$export['attachments'] = array();
foreach( $posts as $post ) {
$export['attachments'][$post->ID] = array(
'id' => $post->ID,
'guid'=> wp_get_attachment_url( $post->ID ),
'post_parent' => $post->post_parent,
'post_name' => $post->post_name,
'post_date' => $post->post_date );
}
}
}
while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
$where = 'ID IN (' . join( ',', $next_posts ) . ')';
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE post_status='publish' and $where" );
// Begin Loop.
foreach ( $posts as $post ) {
if( in_array($post->ID , $excludes) ){
continue;
}
setup_postdata( $post );
$data = array();
if ( get_post_meta( $post->ID, '_elementor_edit_mode', true ) === 'builder' ) {
$post->post_content = "";
}
$post->guid = $this->_replace_uri( $post->guid, $this->oldurl, "SITE_URL_HERE" );
$excludes = array(
'guid',
'to_ping',
'pinged',
'post_content_filtered',
'post_mime_type',
'comment_count',
'filter',
'post_modified',
'post_modified_gmt'
);
foreach( $excludes as $exl ){
if( isset($post->$exl) ){
unset( $post->$exl );
}
}
$data['post'] = $post;
// meta data
$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
$exls = array(
'_edit_last',
'_edit_lock',
'_elementor_version',
'_menu_item_type',
'_menu_item_menu_item_parent',
'_menu_item_object_id',
'_menu_item_object',
'_menu_item_target',
'_menu_item_classes',
'_menu_item_xfn',
'_menu_item_url',
'_elementor_css'
);
$tmp = array();
foreach( $postmeta as $key => $meta ){
unset( $postmeta[$key]->post_id );
unset( $postmeta[$key]->meta_id );
foreach( $exls as $exl ){
if( $meta->meta_key == $exl ){
unset( $postmeta[$key] );
}
}
}
foreach( $postmeta as $key => $meta ){
$tmp[$meta->meta_key] = $meta->meta_value;
}
$data['postmeta'] = $tmp;
if ( $post->post_type == 'attachment' ){
$data['attachment_url'] = wp_get_attachment_url( $post->ID );
}
$data['thumbnail_id'] = get_post_meta( $post->ID, '_thumbnail_id', true );
// taxonomy
$taxonomies = get_object_taxonomies( $post->post_type );
if ( !empty( $taxonomies ) ) {
$data['taxonomy'] = array();
$terms = wp_get_object_terms( $post->ID, $taxonomies );
foreach ( (array) $terms as $term ) {
if( $term->taxonomy == 'nav_menu' ){
continue;
}
$t = array(
$term->taxonomy => array (
$term->slug => $term->name
)
);
$data['taxonomy'][] = $t;
}
}
$output [] = $data;
}
}
$export['posts'] = $output;
return $export;
}
/**
* find attachment post id by guid
*/
private function find_image_id_byguid( $image_url ) {
global $wpdb;
$attachment = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE guid LIKE '%".$image_url."%';" );
return isset($attachment[0])?$attachment[0]:0;
}
/**
* find all images:svg,git,png,jpg in data setting of elementor
*/
private function get_images_posts( $ids ){
$mids = array();
$images = array();
foreach( $ids as $id ){
if ( get_post_meta( $id, '_elementor_edit_mode', true ) === 'builder' ) {
$data = json_decode( get_post_meta( $id, '_elementor_data', true ), ARRAY_A );
if( $data ){
$string = "start".print_r( $data , true )."end";
$pattern = '~(http.*\.)(jpe?g|png|svg|gif|[tg]iff?|svg)~i';
$m = preg_match_all($pattern,$string,$matches);
if( $matches[0] ){
foreach( $matches[0] as $img ){
$pattern = '#(/\d+/\d+/(.*))$#';
$a = preg_match( $pattern , $img, $m );
if( isset($m[1]) ){ ///echo '<Pre>' . print_r( $data, 1 );die;
$_id = $this->find_image_id_byguid( $m[1] );
if( $_id ) {
$mids[$_id] = $_id;
} else {
$images[] = $img;
}
}
}
}
}
}
}
echo '<Pre> Missing Images:' . print_r( $images , 1 ); //die;
return $mids;
}
public function sample(){
$data = array();
return $data;
}
public function download_images( $attachments, $jcontent ){
$folder = $this->path .'/'.$this->cfg->folder_source.'/images';
if( is_dir($folder) ){
$file = new Filesystem();
$file->deleteDirectory( $folder );
}
if( !is_dir($folder) ){
mkdir( $folder );
}
$url = $this->cfg->server_source.'/images/';
$replaces = array();
foreach( $attachments as $attachment ){
$guid = str_replace( $this->server , $this->oldurl, $attachment['guid'] ) ;
// $image = file get contents( $guid );
$image = wp_remote_get( $guid );
$name = basename( $attachment['guid'] );
$path = $folder.'/'.$name;
file_put_contents( $path, $image );
$guid = $attachment['guid'];
$newurl = $url.$name;
$replaces[$guid] = $newurl;
}
foreach( $replaces as $key => $replace ){
$jcontent = $this->_replace_uri( $jcontent, $key, $replace);
}
return $jcontent;
}
/**
* export all sample data
*/
public function source(){
// $content = file get contents( $this->path.'/sample/data.json' );
$content = wp_remote_get( $this->path.'/sample/data.json' );
$data = json_decode( $content, true );
$file = new Filesystem();
$content = $this->download_images( $data['attachments'], $content );
$file = $this->path.'/'.$this->cfg->folder_source.'/data.json';
$this->output_file_content( $file, $content );
$zip = new ZipArchive;
if ($zip->open( $this->path.'/'.$this->cfg->folder_source .'/data.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
$zip->addFile( $file, 'data.json');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
}
/**
* export all sample data
*/
public function data(){
$this->fix_images_parents();
$data = $this->pages();
$data = array_merge_recursive(
$data,
$this->data_posttypes(),
$this->options(),
$this->get_more_options(),
$this->sample()
);
$data = apply_filters( 'opaltools_single_wp_cli_exporter', $data , $this->cfg );
$file = $this->path.'sample/data.json';
///
$attachments = array();
foreach ( $data['attachments'] as $key => $value ) {
$attachments[$value['id']] = $value;
}
$data['attachments'] = $attachments;
$content = $this->_replace_uri( json_encode($data , JSON_PRETTY_PRINT ), $this->oldurl, $this->server );
$content = str_replace( $this->cfg->theme, $this->cfg->domain, $content );
$this->output_file_content( $file, $content );
$this->config_samples();
$this->source();
}
public function fix_images_parents(){
global $wpdb;
$fixs = array(
'product-',
'bg-slider',
'slide-',
'bg-slide'
);
foreach( $fixs as $fix ) {
$wpdb->query( "UPDATE wp_posts SET post_parent=0 WHERE post_title LIKE '".$fix."%'" );
}
}
}
WP_CLI::add_command( 'opalestate', new OpalEstate_Command );
?>

View File

@@ -0,0 +1,110 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Send_Email_Notification
*
* @version 1.0
*/
class OpalEstate_Send_Email_Approve extends OpalEstate_Abstract_Email_Template {
/**
*
*/
public function get_subject () {
$propety_title = '' ;
return sprintf( esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' ), $propety_title );
}
/**
* get collection of key and value base on tags which using to replace custom tags
*/
public function set_pros( $property_id ){
$property = get_post( $property_id );
$user = get_userdata( $property->post_author );
$email = get_user_meta( $property->post_author, OPALESTATE_USER_PROFILE_PREFIX . 'email', true );
$email = $email ? $email : $user->data->user_email;
$this->args = array(
'receiver_email' => $email,
'user_mail' => $email,
'user_name' => $user->display_name,
'submitted_date' => $property->post_date,
'property_name' => $property->post_title,
'property_link' => get_permalink( $property_id ),
'current_time' => date("F j, Y, g:i a"),
);
return $this->args ;
}
/**
*
*/
public function get_content_template() {
return opalestate_load_template_path( 'emails/request-reviewing' );
}
/**
*
*/
public static function get_default_template() {
return trim(preg_replace('/\t+/', '', "Hi {user_name},<br>
<br>
Thank you so much for submitting to {site_name}.
<br>
We have completed the auditing process for your property '{property_name}' and are pleased to inform you that your submission has been accepted.
<br>
<br>
Thanks again for your contribution
<br>
&nbsp;<br>
<br>
<em>This message was sent by {site_link} on {current_time}.</em>"));
}
/**
*
*/
public function to_email () {
return $this->args ['receiver_email'];
}
/**
*
*/
public function cc_email () {
return $this->args ['sender_email'];
}
/**
*
*/
public function get_body() {
$post = get_post( $this->args['post_id'] );
$this->args['email'] = $this->args['receiver_email'];
$this->args['property_link'] = $post->post_title;
return parent::get_body();
}
}
?>

View File

@@ -0,0 +1,125 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Send_Email_Notification
*
* @version 1.0
*/
class OpalEstate_Abstract_Email_Template {
public $args = array();
/**
* Get the unique email notification key.
*
* @return string
*/
public function get_key() {
return 'opalestate-notification';
}
/**
* Get the friendly name for this email notification.
*
* @return string
*/
public function get_title() {
return esc_html__( 'Admin Notice of Expiring Job Listings', 'opalestate-pro' );
}
/**
* Get the description for this email notification.
*
* @type abstract
* @return string
*/
public function get_description() {
return esc_html__( 'Send notices to the site administrator before a job listing expires.', 'opalestate-pro' );
}
public function to_email () {
}
public function get_content_template() {
}
public function set_args ( $args ) {
return $this->args = $args;
}
public function replace_tags ( $template ) {
$args = $this->args;
$default = array(
'receiver_name' => '',
'name' => '',
'receiver_email' => '',
'property_link' => '',
'message' => '',
'site_name' => bloginfo(),
'site_link' => get_home_url(),
'current_time' => date("F j, Y, g:i a"),
'phone' => ''
);
$args = array_merge( $default, $args );
$tags = array();
$values = array() ;
foreach ( $args as $key => $value ) {
$tags[] = "{".$key."}";
$values[] = $value;
}
$message = str_replace( $tags, $values, $template );
return $message;
}
public function get_subject () {
}
public function from_email() {
return opalestate_get_option( 'from_email' , get_bloginfo( 'admin_email' ) );
}
public function from_name() {
return opalestate_get_option('from_name', get_bloginfo( 'name' ) );
}
public function get_cc() {
}
public function get_body(){
$template = $this->get_content_template();
return $this->replace_tags( $template );
}
public function get_plain_text_body () {
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Send_Email_Notification
*
* @version 1.0
*/
class OpalEstate_Send_Email_Notification extends OpalEstate_Abstract_Email_Template {
public $type = '';
/**
* Send Email
*/
public function get_subject () {
switch ( $this->type ) {
case 'enquiry':
$subject = html_entity_decode( esc_html__('You got a message enquiry', 'opalestate-pro') );
break;
default:
$subject = html_entity_decode( esc_html__('You got a message contact', 'opalestate-pro') );
break;
}
return $subject;
}
/**
* Send Email
*/
public function get_content_template() {
switch ( $this->type ) {
case 'enquiry':
return opalestate_load_template_path( 'emails/enquiry' );
break;
default:
return opalestate_load_template_path( 'emails/contact' );
break;
}
}
public function to_email () {
return $this->args ['receiver_email'];
}
public function cc_email () {
return $this->args ['sender_email'];
}
public function get_body() {
$this->args['email'] = $this->args['receiver_email'];
return parent::get_body();
}
}
?>

View File

@@ -0,0 +1,110 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Send_Email_Notification
*
* @version 1.0
*/
class OpalEstate_Send_Email_New_Submitted extends OpalEstate_Abstract_Email_Template {
/**
* Send Email
*/
public function get_subject () {
$propety_title = '' ;
$d = esc_html__( 'New Property Listing Submitted: {property_name}', 'opalestate-pro' );
$s = opalestate_get_option( 'newproperty_email_subject' , $d );
return $s;
}
/**
* get collection of key and value base on tags which using to replace custom tags
*/
public function set_pros( $property_id, $user_id ){
$property = get_post( $property_id );
$user = get_userdata( $property->post_author );
$email = get_user_meta( $property->post_author, OPALESTATE_USER_PROFILE_PREFIX . 'email', true );
$email = $email ? $email : $user->data->user_email;
$this->args = array(
'receiver_email' => $email,
'user_mail' => $email,
'user_name' => $user->display_name,
'submitted_date' => $property->post_date,
'property_name' => $property->post_title,
'property_link' => get_permalink( $property_id ),
'current_time' => date("F j, Y, g:i a"),
);
return $this->args ;
}
/**
* Send Email
*/
public function get_content_template() {
$body = opalestate_get_option( 'newproperty_email_body', self::newproperty_email_body() );
return $body;
}
/**
* Send Email
*/
public static function get_default_template() {
return trim(preg_replace('/\t+/', '','
Hi {user_name},
<br>
Thanks you so much for submitting {property_name} at {site_name}:<br>
Give us a few moments to make sure that we are got space for you. You will receive another email from us soon.
If this request was made outside of our normal working hours, we may not be able to confirm it until we are open again.
<br>
You may review your property at any time by logging in to your client area.
<br>
<em>This message was sent by {site_link} on {current_time}.</em>'
) );
}
/**
* Send Email
*/
public function to_email () {
return $this->args ['receiver_email'];
}
/**
* Send Email
*/
public function cc_email () {
return $this->args ['sender_email'];
}
/**
* Send Email
*/
public function get_body() {
return parent::get_body();
}
}
?>

View File

@@ -0,0 +1,70 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Send_Email_Notification
*
* @version 1.0
*/
class OpalEstate_Send_Email_Request_Reviewing extends OpalEstate_Abstract_Email_Template {
/**
* Send Email
*/
public function get_subject () {
$propety_title = '' ;
return sprintf( esc_html__( 'You have a message request reviewing: %s at', 'opalestate-pro' ), $propety_title );
}
/**
* Send Email
*/
public function get_content_template() {
return opalestate_load_template_path( 'emails/request-reviewing' );
}
/**
* Send Email
*/
public function to_email () {
return $this->args ['receiver_email'];
}
/**
* Send Email
*/
public function cc_email () {
return $this->args ['sender_email'];
}
/**
* Send Email
*/
public function get_body() {
$post = get_post( $this->args['post_id'] );
$this->args['email'] = $this->args['receiver_email'];
$this->args['property_link'] = get_permalink( $post->ID );
$this->args['property_name'] = $post->post_title;
return parent::get_body();
}
}
?>

129
inc/function-search-fields.php Executable file
View File

@@ -0,0 +1,129 @@
<?php
/**
* Search field templates.
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Render field template.
*
* @param string $field Field.
* @param string $label Label.
* @param string $type Type.
*/
function opalestate_property_render_field_template( $field, $label, $type = 'select' ) {
$qvalue = isset( $_GET['info'][ $field ] ) ? sanitize_text_field( $_GET['info'][ $field ] ) : '';
$template = '';
$template = apply_filters( 'opalestate_property_render_search_field_template', $field, $label );
$template = apply_filters( 'opalestate_property_' . $field . '_field_template', $template );
if ( $template == $field ) {
$template = '';
}
if ( empty( $template ) ) {
switch ( $type ) {
case 'input': ?>
<label class="opalestate-label opalestate-label--<?php echo sanitize_html_class( $field ); ?>"><?php echo esc_html( $label ); ?></label>
<div class="input-group-number">
<i class="fa icon-property-<?php echo esc_attr( $field ); ?>"></i>
<input class="form-control" value="1" type="text" name="info[<?php echo $field; ?>]" placeholder="<?php echo esc_attr( $label ); ?>"/>
<div class="btn-actions">
<span class="btn-minus"><i class="fa fa-minus"></i></span>
<span class="btn-plus"><i class="fa fa-plus"></i></span>
</div>
</div>
<?php break;
default:
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$template .= '<select class="form-control" name="info[%s]"><option value="">%s</option>';
for ( $i = 1; $i <= 10; $i++ ) {
$selected = $i == $qvalue ? 'selected="selected"' : '';
$template .= '<option ' . $selected . ' value="' . $i . '">' . $i . '</option>';
}
$template .= '</select>';
$template = sprintf( $template, $field, $label );
break;
}
}
echo $template; // WPCS: XSS OK.
}
/**
* Render area size field.
*/
function opalestate_property_areasize_field_template( $template = '' ) {
$search_min = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : opalestate_options( 'search_min_area', 0 );
$search_max = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : opalestate_options( 'search_max_area', 1000 );
$data = [
'id' => 'area',
'unit' => opalestate_options( 'measurement_unit', 'sq ft' ) . ' ',
'ranger_min' => opalestate_options( 'search_min_area', 0 ),
'ranger_max' => opalestate_options( 'search_max_area', 1000 ),
'input_min' => $search_min,
'input_max' => $search_max,
];
opalesate_property_slide_ranger_template( esc_html__( 'Area', 'opalestate-pro' ), $data );
return;
}
add_filter( "opalestate_property_areasize_field_template", 'opalestate_property_areasize_field_template' );
/**
* Render slider ranger template.
*
* @param $label
* @param $data
*/
function opalesate_property_slide_ranger_template( $label, $data ) {
$default = [
'id' => 'price',
'unit' => '',
'decimals' => 0,
'ranger_min' => 0,
'ranger_max' => 1000,
'input_min' => 0,
'input_max' => 1000,
'unit_position' => 'postfix',
'mode' => 2,
'start' => '',
];
$data = array_merge( $default, $data );
extract( $data );
?>
<label class="opalestate-label opalestate-label--<?php echo sanitize_title( $label ); ?>"><?php echo esc_html( $label ); ?></label>
<div class="opal-slide-ranger" data-unit="<?php echo $unit; ?>" data-unitpos="<?php echo $unit_position ?>" data-decimals="<?php echo $decimals; ?>">
<label class="slide-ranger-label">
<span class="slide-ranger-min-label"></span>
<?php echo ( $mode == 2 ) ? '<i>-</i>' : ''; ?>
<span class="slide-ranger-max-label"></span>
</label>
<div class="slide-ranger-bar" data-min="<?php echo $ranger_min; ?>" data-max="<?php echo $ranger_max; ?>" data-mode="<?php echo $mode; ?>" data-start="<?php echo $start; ?>"></div>
<?php if ( $mode == 1 ) : ?>
<input type="hidden" class="slide-ranger-min-input ranger-<?php echo $id; ?>" name="<?php echo $id; ?>" autocomplete="off" value="<?php echo (int) $input_min; ?>"/>
<?php else : ?>
<input type="hidden" class="slide-ranger-min-input ranger-<?php echo $id; ?>" name="min_<?php echo $id; ?>" autocomplete="off" value="<?php echo (int) $input_min; ?>"/>
<input type="hidden" class="slide-ranger-max-input ranger-<?php echo $id; ?>" name="max_<?php echo $id; ?>" autocomplete="off" value="<?php echo (int) $input_max; ?>"/>
<?php endif; ?>
</div>
<?php
}

149
inc/libraries/array2xml.php Executable file
View File

@@ -0,0 +1,149 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Array2XML {
private static $xml = null;
private static $encoding = 'UTF-8';
/**
* Initialize the root XML node [optional]
* @param $version
* @param $encoding
* @param $format_output
*/
public static function init($version = '1.0', $encoding = 'UTF-8', $format_output = true) {
self::$xml = new DomDocument($version, $encoding);
self::$xml->formatOutput = $format_output;
self::$encoding = $encoding;
}
/**
* Convert an Array to XML
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DomDocument
*/
public static function &createXML($node_name, $arr=array()) {
$xml = self::getXMLRoot();
$xml->appendChild(self::convert($node_name, $arr));
self::$xml = null; // clear the xml node in the class for 2nd time use.
return $xml;
}
/**
* Convert an Array to XML
* @param string $node_name - name of the root node to be converted
* @param array $arr - aray to be converterd
* @return DOMNode
*/
private static function &convert($node_name, $arr=array()) {
//print_arr($node_name);
$xml = self::getXMLRoot();
$node = $xml->createElement($node_name);
if(is_array($arr)){
// get the attributes first.;
if(isset($arr['@attributes'])) {
foreach($arr['@attributes'] as $key => $value) {
if(!self::isValidTagName($key)) {
throw new Exception('[Array2XML] Illegal character in attribute name. attribute: '.$key.' in node: '.$node_name);
}
$node->setAttribute($key, self::bool2str($value));
}
unset($arr['@attributes']); //remove the key from the array once done.
}
// check if it has a value stored in @value, if yes store the value and return
// else check if its directly stored as string
if(isset($arr['@value'])) {
$node->appendChild($xml->createTextNode(self::bool2str($arr['@value'])));
unset($arr['@value']); //remove the key from the array once done.
//return from recursion, as a note with value cannot have child nodes.
return $node;
} else if(isset($arr['@cdata'])) {
$node->appendChild($xml->createCDATASection(self::bool2str($arr['@cdata'])));
unset($arr['@cdata']); //remove the key from the array once done.
//return from recursion, as a note with cdata cannot have child nodes.
return $node;
}
}
//create subnodes using recursion
if(is_array($arr)){
// recurse to get the node for that key
foreach($arr as $key=>$value){
if(!self::isValidTagName($key)) {
throw new Exception('[Array2XML] Illegal character in tag name. tag: '.$key.' in node: '.$node_name);
}
if(is_array($value) && is_numeric(key($value))) {
// MORE THAN ONE NODE OF ITS KIND;
// if the new array is numeric index, means it is array of nodes of the same kind
// it should follow the parent key name
foreach($value as $k=>$v){
$node->appendChild(self::convert($key, $v));
}
} else {
// ONLY ONE NODE OF ITS KIND
$node->appendChild(self::convert($key, $value));
}
unset($arr[$key]); //remove the key from the array once done.
}
}
// after we are done with all the keys in the array (if it is one)
// we check if it has any text value, if yes, append it.
if(!is_array($arr)) {
$node->appendChild($xml->createTextNode(self::bool2str($arr)));
}
return $node;
}
/*
* Get the root XML node, if there isn't one, create it.
*/
private static function getXMLRoot(){
if(empty(self::$xml)) {
self::init();
}
return self::$xml;
}
/*
* Get string representation of boolean value
*/
private static function bool2str($v){
//convert boolean to text value.
$v = $v === true ? 'true' : $v;
$v = $v === false ? 'false' : $v;
return $v;
}
/*
* Check if the tag name or attribute name contains illegal characters
* Ref: http://www.w3.org/TR/xml/#sec-common-syn
*/
private static function isValidTagName($tag){
$pattern = '/^[a-z_]+[a-z0-9\:\-\.\_]*[^:]*$/i';
return preg_match($pattern, $tag, $matches) && $matches[0] == $tag;
}
}
?>

178
inc/libraries/wp-session.php Executable file
View File

@@ -0,0 +1,178 @@
<?php
/**
* WordPress session managment.
*
* Standardizes WordPress session data and uses either database transients or in-memory caching
* for storing user session information.
*
* @package WordPress
* @subpackage Session
* @since 3.7.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Return the current cache expire setting.
*
* @return int
*/
function wp_session_cache_expire() {
$wp_session = WP_Session::get_instance();
return $wp_session->cache_expiration();
}
/**
* Alias of wp_session_write_close()
*/
function wp_session_commit() {
wp_session_write_close();
}
/**
* Load a JSON-encoded string into the current session.
*
* @param string $data
*/
function wp_session_decode( $data ) {
$wp_session = WP_Session::get_instance();
return $wp_session->json_in( $data );
}
/**
* Encode the current session's data as a JSON string.
*
* @return string
*/
function wp_session_encode() {
$wp_session = WP_Session::get_instance();
return $wp_session->json_out();
}
/**
* Regenerate the session ID.
*
* @param bool $delete_old_session
*
* @return bool
*/
function wp_session_regenerate_id( $delete_old_session = false ) {
$wp_session = WP_Session::get_instance();
$wp_session->regenerate_id( $delete_old_session );
return true;
}
/**
* Start new or resume existing session.
*
* Resumes an existing session based on a value sent by the _wp_session cookie.
*
* @return bool
*/
function wp_session_start() {
$wp_session = WP_Session::get_instance();
do_action( 'wp_session_start' );
return $wp_session->session_started();
}
add_action( 'plugins_loaded', 'wp_session_start' );
/**
* Return the current session status.
*
* @return int
*/
function wp_session_status() {
$wp_session = WP_Session::get_instance();
if ( $wp_session->session_started() ) {
return PHP_SESSION_ACTIVE;
}
return PHP_SESSION_NONE;
}
/**
* Unset all session variables.
*/
function wp_session_unset() {
$wp_session = WP_Session::get_instance();
$wp_session->reset();
}
/**
* Write session data and end session
*/
function wp_session_write_close() {
$wp_session = WP_Session::get_instance();
$wp_session->write_data();
do_action( 'wp_session_commit' );
}
add_action( 'shutdown', 'wp_session_write_close' );
/**
* Clean up expired sessions by removing data and their expiration entries from
* the WordPress options table.
*
* This method should never be called directly and should instead be triggered as part
* of a scheduled task or cron job.
*/
function wp_session_cleanup() {
global $wpdb;
if ( defined( 'WP_SETUP_CONFIG' ) ) {
return;
}
if ( ! defined( 'WP_INSTALLING' ) ) {
$expiration_keys = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%'" );
$now = current_time( 'timestamp' );
$expired_sessions = array();
foreach( $expiration_keys as $expiration ) {
// If the session has expired
if ( $now > intval( $expiration->option_value ) ) {
// Get the session ID by parsing the option_name
$session_id = substr( $expiration->option_name, 20 );
if( (int) -1 === (int) $session_id || ! preg_match( '/^[a-f0-9]{32}$/', $session_id ) ) {
continue;
}
$expired_sessions[] = $expiration->option_name;
$expired_sessions[] = esc_sql( "_wp_session_$session_id" );
}
}
// Delete all expired sessions in a single query
if ( ! empty( $expired_sessions ) ) {
$option_names = implode( "','", $expired_sessions );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
}
}
// Allow other plugins to hook in to the garbage collection process.
do_action( 'wp_session_cleanup' );
}
add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' );
/**
* Register the garbage collector as a twice daily event.
*/
function wp_session_register_garbage_collection() {
if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wp_session_garbage_collection' );
}
}
add_action( 'wp', 'wp_session_register_garbage_collection' );

View File

@@ -0,0 +1,341 @@
<?php
/**
* WordPress session managment.
*
* Standardizes WordPress session data using database-backed options for storage.
* for storing user session information.
*
* @package WordPress
* @subpackage Session
* @since 3.6.0
*/
/**
* WordPress Session class for managing user session data.
*
* @package WordPress
* @since 3.6.0
*/
class WP_Session implements ArrayAccess, Iterator, Countable {
/**
* Internal data collection.
*
* @var array
*/
private $container;
/**
* ID of the current session.
*
* @var string
*/
private $session_id;
/**
* Unix timestamp when session expires.
*
* @var int
*/
private $expires;
/**
* Singleton instance.
*
* @var bool|WP_Session
*/
private static $instance = false;
/**
* Retrieve the current session instance.
*
* @param bool $session_id Session ID from which to populate data.
*
* @return bool|WP_Session
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Default constructor.
* Will rebuild the session collection from the given session ID if it exists. Otherwise, will
* create a new session with that ID.
*
* @param $session_id
* @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire.
*/
private function __construct() {
if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) {
$this->session_id = stripslashes( $_COOKIE[WP_SESSION_COOKIE] );
} else {
$this->session_id = $this->generate_id();
}
$this->expires = time() + intval( apply_filters( 'wp_session_expiration', 24 * 60 ) );
$this->read_data();
setcookie( WP_SESSION_COOKIE, $this->session_id, $this->expires, COOKIEPATH, COOKIE_DOMAIN );
}
/**
* Generate a cryptographically strong unique ID for the session token.
*
* @return string
*/
private function generate_id() {
require_once ABSPATH . 'wp-includes/class-phpass.php';
$hasher = new PasswordHash( 8, false );
return md5( $hasher->get_random_bytes( 32 ) );
}
/**
* Read data from a transient for the current session.
*
* Automatically resets the expiration time for the session transient to some time in the future.
*
* @return array
*/
private function read_data() {
$this->touch_session();
$this->container = get_option( "_wp_session_{$this->session_id}", array() );
return $this->container;
}
/**
* Write the data from the current session to the data storage system.
*/
public function write_data() {
$session_list = get_option( '_wp_session_list', array() );
$this->touch_session();
update_option( "_wp_session_{$this->session_id}", $this->container );
}
private function touch_session() {
$session_list = get_option( '_wp_session_list', array() );
$session_list[ $this->session_id ] = $this->expires;
foreach( $session_list as $id => $expires ) {
if ( time() > $this->expires ) {
delete_option( "_wp_session_{$id}" );
unset( $session_list[$id] );
}
}
update_option( '_wp_session_list', $session_list );
}
/**
* Output the current container contents as a JSON-encoded string.
*
* @return string
*/
public function json_out() {
return json_encode( $this->container );
}
/**
* Decodes a JSON string and, if the object is an array, overwrites the session container with its contents.
*
* @param string $data
*
* @return bool
*/
public function json_in( $data ) {
$array = json_decode( $data );
if ( is_array( $array ) ) {
$this->container = $array;
return true;
}
return false;
}
/**
* Regenerate the current session's ID.
*
* @param bool $delete_old Flag whether or not to delete the old session data from the server.
*/
public function regenerate_id( $delete_old = false ) {
if ( $delete_old ) {
delete_option( "_wp_session_{$this->session_id}" );
$session_list = get_option( '_wp_session_list', array() );
unset ($session_list[ $this->session_id ] );
update_option( '_wp_session_list', $session_list );
}
$this->session_id = $this->generate_id();
setcookie( WP_SESSION_COOKIE, $this->session_id, time() + $this->expires, COOKIEPATH, COOKIE_DOMAIN );
}
/**
* Check if a session has been initialized.
*
* @return bool
*/
public function session_started() {
return !!self::$instance;
}
/**
* Return the read-only cache expiration value.
*
* @return int
*/
public function cache_expiration() {
return $this->expires;
}
/**
* Flushes all session variables.
*/
public function reset() {
$this->container = array();
}
/*****************************************************************/
/* ArrayAccess Implementation */
/*****************************************************************/
/**
* Whether a offset exists
*
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
*
* @param mixed $offset An offset to check for.
*
* @return boolean true on success or false on failure.
*/
public function offsetExists( $offset ) {
return isset( $this->container[ $offset ]) ;
}
/**
* Offset to retrieve
*
* @link http://php.net/manual/en/arrayaccess.offsetget.php
*
* @param mixed $offset The offset to retrieve.
*
* @return mixed Can return all value types.
*/
public function offsetGet( $offset ) {
return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
}
/**
* Offset to set
*
* @link http://php.net/manual/en/arrayaccess.offsetset.php
*
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*
* @return void
*/
public function offsetSet( $offset, $value ) {
if ( is_null( $offset ) ) {
$this->container[] = $value;
} else {
$this->container[ $offset ] = $value;
}
}
/**
* Offset to unset
*
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
*
* @param mixed $offset The offset to unset.
*
* @return void
*/
public function offsetUnset( $offset ) {
unset( $this->container[ $offset ] );
}
/*****************************************************************/
/* Iterator Implementation */
/*****************************************************************/
/**
* Current position of the array.
*
* @link http://php.net/manual/en/iterator.current.php
*
* @return mixed
*/
public function current() {
return current( $this->container );
}
/**
* Key of the current element.
*
* @link http://php.net/manual/en/iterator.key.php
*
* @return mixed
*/
public function key() {
return key( $this->container );
}
/**
* Move the internal point of the container array to the next item
*
* @link http://php.net/manual/en/iterator.next.php
*
* @return void
*/
public function next() {
next( $this->container );
}
/**
* Rewind the internal point of the container array.
*
* @link http://php.net/manual/en/iterator.rewind.php
*
* @return void
*/
public function rewind() {
reset( $this->container );
}
/**
* Is the current key valid?
*
* @link http://php.net/manual/en/iterator.rewind.php
*
* @return bool
*/
public function valid() {
return $this->offsetExists( $this->key() );
}
/*****************************************************************/
/* Countable Implementation */
/*****************************************************************/
/**
* Get the count of elements in the container array.
*
* @link http://php.net/manual/en/countable.count.php
*
* @return int
*/
public function count() {
return count( $this->container );
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* WordPress session managment.
*
* Standardizes WordPress session data and uses either database transients or in-memory caching
* for storing user session information.
*
* @package WordPress
* @subpackage Session
* @since 3.6.0
*/
/**
* Return the current cache expire setting.
*
* @return int
*/
function wp_session_cache_expire() {
$wp_session = WP_Session::get_instance();
return $wp_session->cache_expiration();
}
/**
* Alias of wp_session_write_close()
*/
function wp_session_commit() {
wp_session_write_close();
}
/**
* Load a JSON-encoded string into the current session.
*
* @param string $data
*/
function wp_session_decode( $data ) {
$wp_session = WP_Session::get_instance();
return $wp_session->json_in( $data );
}
/**
* Encode the current session's data as a JSON string.
*
* @return string
*/
function wp_session_encode() {
$wp_session = WP_Session::get_instance();
return $wp_session->json_out();
}
/**
* Regenerate the session ID.
*
* @param bool $delete_old_session
*
* @return bool
*/
function wp_session_regenerate_id( $delete_old_session = false ) {
$wp_session = WP_Session::get_instance();
$wp_session->regenerate_id( $delete_old_session );
return true;
}
/**
* Start new or resume existing session.
*
* Resumes an existing session based on a value sent by the _wp_session cookie.
*
* @return bool
*/
function wp_session_start() {
$wp_session = WP_Session::get_instance();
$wp_session = WP_Session::get_instance();
do_action( 'wp_session_start' );
return $wp_session->session_started();
}
add_action( 'plugins_loaded', 'wp_session_start' );
/**
* Return the current session status.
*
* @return int
*/
function wp_session_status() {
$wp_session = WP_Session::get_instance();
if ( $wp_session->session_started() ) {
return PHP_SESSION_ACTIVE;
}
return PHP_SESSION_NONE;
}
/**
* Unset all session variables.
*/
function wp_session_unset() {
$wp_session = WP_Session::get_instance();
$wp_session->reset();
}
/**
* Write session data and end session
*/
function wp_session_write_close() {
$wp_session = WP_Session::get_instance();
$wp_session->write_data();
do_action( 'wp_session_commit' );
}
add_action( 'shutdown', 'wp_session_write_close' );

View File

@@ -0,0 +1,757 @@
<?php
/**
* OpalEstate_User_Message
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* OpalEstate_User_Message Class
*
* @since 1.0.0
*/
class OpalEstate_User_Message {
/**
*
*/
protected $user_id = 0;
protected $is_log;
/**
*
*/
public static function get_instance() {
static $_instance;
if ( ! $_instance ) {
$_instance = new self();
}
return $_instance;
}
public function get_types() {
return [
'request_view' => '',
'contact' => '',
'send_equiry' => '',
];
}
/**
*
*/
public function __construct() {
add_action( 'init', [ $this, 'init' ] );
/// process ajax send message
add_action( 'wp_ajax_send_email_contact', [ $this, 'process_send_email' ] );
add_action( 'wp_ajax_nopriv_send_email_contact', [ $this, 'process_send_email' ] );
// process ajax
add_action( 'wp_ajax_send_email_contact_reply', [ $this, 'process_send_reply_email' ] );
add_action( 'wp_ajax_nopriv_send_email_contact_reply', [ $this, 'process_send_reply_email' ] );
add_filter( 'opalestate_user_content_messages_page', [ $this, 'render_user_content_page' ] );
}
/**
* Set values when user logined in system
*/
public function init() {
global $current_user;
wp_get_current_user();
$this->user_id = $current_user->ID;
$this->is_log = opalestate_get_option( 'message_log' );
}
/**
* Set values when user logined in system
*/
public function send_equiry( $post, $member ) {
$default = [
'send_equiry_name' => '',
'action' => '',
'post_id' => '',
'sender_id' => '',
'email' => '',
'phone' => '',
'message' => '',
'message_action' => '',
];
$post = array_merge( $default, $post );
$post['property_link'] = (int) $post['post_id'] ? get_permalink( $post['post_id'] ) : get_home_url();
$post['receive_name'] = $member['name'];
$subject = html_entity_decode( esc_html__( 'You got a message', 'opalestate-pro' ) );
$post['receiver_name'] = $member['receiver_name'];
$output = [
'subject' => $subject,
'name' => $member['name'],
'receiver_email' => $member['receiver_email'],
'receiver_id' => $member['receiver_id'],
'sender_id' => get_current_user_id(),
'sender_email' => $post['email'],
'phone' => $post['phone'],
'message' => $post['message'],
'post_id' => $post['post_id'],
'type' => 'send_enquiry',
];
if ( $output['sender_id'] == $output['receiver_id'] ) {
// return false;
}
return $output;
}
/**
* Set values when user logined in system
*/
public function send_contact( $post ) {
$member = get_post( $post['post_id'] );
if ( $member->post_type == 'opalestate_agent' ) {
$receiver_id = get_post_meta( $member->ID, OPALESTATE_AGENT_PREFIX . 'user_id', true );
$email = get_post_meta( $member->ID, OPALESTATE_AGENT_PREFIX . 'email', true );
} else {
$receiver_id = get_post_meta( $member->ID, OPALESTATE_AGENCY_PREFIX . 'user_id', true );
$email = get_post_meta( $member->ID, OPALESTATE_AGENCY_PREFIX . 'email', true );
}
$member = [
'receiver_email' => $email,
'receiver_name' => $member->post_title,
'receiver_id' => $receiver_id,
];
$default = [
'send_equiry_name' => '',
'action' => '',
'post_id' => '',
'sender_id' => '',
'email' => '',
'phone' => '',
'message' => '',
'message_action' => '',
];
$post = array_merge( $default, $post );
$post['link'] = (int) $post['post_id'] ? get_permalink( $post['post_id'] ) : get_home_url();
$post['receive_name'] = $member['name'];
$subject = html_entity_decode( esc_html__( 'You got a message contact', 'opalestate-pro' ) );
$post['receiver_name'] = $member['receiver_name'];
$output = [
'subject' => $subject,
'name' => $member['name'],
'receiver_email' => $member['receiver_email'],
'receiver_id' => $member['receiver_id'],
'sender_id' => get_current_user_id(),
'sender_email' => $post['email'],
'phone' => $post['phone'],
'message' => $post['message'],
'post_id' => $post['post_id'],
'type' => 'send_contact',
];
if ( $output['sender_id'] == $output['receiver_id'] ) {
// return false;
}
return $output;
}
/**
* Set values when user logined in system
*/
public function get_member_email_data( $post_id ) {
return opalestate_get_member_email_data( $post_id );
}
/**
* Set values when user logined in system
*/
public function process_send_reply_email() {
if ( isset( $_POST ) && $this->is_log ) {
$id = 2;
$message = $this->get_message( intval( $_POST['message_id'] ) );
if ( $message ) {
$data = [
'message_id' => $message->id,
'sender_id' => $this->user_id,
'receiver_id' => $message->sender_id,
'message' => sanitize_text_field( $_POST['message'] ),
'created' => current_time( 'mysql', 1 ),
];
$id = $this->insert_reply( $data );
$reply = $this->get_reply( $id );
$data['data'] = [
'created' => $reply->created,
'message' => $reply->message,
'avatar' => OpalEstate_User::get_author_picture( $message->sender_id ),
];
// send email for user to inbox email.
do_action( 'opalestate_send_email_notifycation', $data );
$return = [
'status' => true,
'msg' => esc_html__( 'Email Sent successful', 'opalestate-pro' ),
'heading' => esc_html__( 'Sending Message', 'opalestate-pro' ),
];
}
} else {
$return = [ 'status' => false, 'msg' => esc_html__( 'Unable to send a message.', 'opalestate-pro' ), 'heading' => esc_html__( 'Sending Message', 'opalestate-pro' ) ];
}
echo json_encode( $return );
die();
}
/**
*
*/
public function process_send_email() {
do_action( 'opalestate_process_send_email_before' );
if ( isset( $_POST['type'] ) && $_POST['type'] ) {
$content = [];
switch ( trim( $_POST['type'] ) ) {
case 'send_equiry':
if ( wp_verify_nonce( $_POST['message_action'], 'send-enquiry-form' ) ) {
$member = $this->get_member_email_data( (int) $_POST['post_id'] );
$content = $this->send_equiry( $_POST, $member );
}
break;
case 'send_contact':
if ( wp_verify_nonce( $_POST['message_action'], 'send-contact-form' ) ) {
$content = $this->send_contact( $_POST );
}
break;
default:
break;
}
if ( $content ) {
// only save in db for user only
if ( $content['receiver_id'] > 0 && $this->is_log ) {
$this->insert( $content );
}
// send email for user to inbox email.
do_action( 'opalestate_send_email_notifycation', $content );
}
}
$return = [ 'status' => false, 'msg' => esc_html__( 'Unable to send a message.', 'opalestate-pro' ) ];
echo json_encode( $return );
die();
}
/**
*
*/
public function insert( $data ) {
global $wpdb;
$args = [
'subject' => '',
'message' => '',
'sender_email' => '',
'phone' => '',
'sender_id' => '',
'created' => current_time( 'mysql', 1 ),
'receiver_id' => '',
'post_id' => '',
'type' => '',
];
foreach ( $args as $key => $value ) {
if ( isset( $data[ $key ] ) ) {
$args[ $key ] = $data[ $key ];
}
}
$id = $wpdb->insert( $wpdb->prefix . 'opalestate_message', $args );
return $wpdb->insert_id;
}
public function insert_reply( $data ) {
global $wpdb;
$args = [
'message_id' => '',
'message' => '',
'sender_id' => '',
'created' => current_time( 'mysql', 1 ),
'receiver_id' => '',
];
foreach ( $args as $key => $value ) {
if ( isset( $data[ $key ] ) ) {
$args[ $key ] = $data[ $key ];
}
}
$id = $wpdb->insert( $wpdb->prefix . 'opalestate_message_reply', $args );
return $wpdb->insert_id;
}
public function get_reply( $id ) {
global $wpdb;
$query = " SELECT * FROM " . $wpdb->prefix . "opalestate_message_reply where id=" . (int) $id;
$reply = $wpdb->get_row( $query );
return $reply;
}
/**
*
*/
public static function install() {
try {
if ( ! function_exists( 'dbDelta' ) ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
}
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'opalestate_message' . ' (
`id` int(11) UNSIGNED NOT NULL,
`subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`message` text COLLATE utf8mb4_unicode_ci NOT NULL,
`phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`sender_email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sender_id` int(11) DEFAULT NULL,
`created` datetime NOT NULL,
`receiver_id` int(11) NOT NULL,
`post_id` int(11) NOT NULL,
`type` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
`isread` tinyint(1) NOT NULL
) ' . $charset_collate;
dbDelta( $sql );
///
$sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'opalestate_message_reply' . ' (
`id` int(11) NOT NULL,
`message_id` int(11) NOT NULL,
`sender_id` int(11) NOT NULL,
`message` text NOT NULL,
`created` datetime NOT NULL,
`receiver_id` int(11) NOT NULL
) ' . $charset_collate;
dbDelta( $sql );
} catch ( Exception $e ) {
}
}
/**
*
*/
public function do_delete( $id ) {
global $wpdb;
if ( $this->user_id ) {
$wpdb->delete( $wpdb->prefix . "opalestate_message", [ "id" => $id, 'user_id' => $this->user_id ], [ '%d' ] );
}
}
/**
*
*/
public function get_list( $args = [] ) {
global $wpdb;
$default = [
'cpage' => 1,
'items_per_page' => 3,
];
$args = array_merge( $default, $args );
$items_per_page = $args['items_per_page'];
$offset = ( $args['cpage'] * $items_per_page ) - $items_per_page;
$query = " SELECT * FROM " . $wpdb->prefix . "opalestate_message where receiver_id=" . $this->user_id . ' OR sender_id=' . $this->user_id;
$query .= ' ORDER BY id DESC LIMIT ' . $offset . ', ' . $items_per_page;
return $wpdb->get_results( $query );
}
public function get_total() {
global $wpdb;
$query = " SELECT count(1) as total FROM " . $wpdb->prefix . "opalestate_message where receiver_id=" . $this->user_id . ' OR sender_id=' . $this->user_id;
return $wpdb->get_var( $query );
}
/**
*
*/
public function get_message( $id ) {
global $wpdb;
$query = " SELECT * FROM " . $wpdb->prefix . "opalestate_message where ( sender_id=" . $this->user_id . " OR receiver_id=" . $this->user_id . ') and id=' . (int) $id;
$message = $wpdb->get_results( $query );
if ( isset( $message[0] ) ) {
return $message[0];
}
return [];
}
public function get_replies( $id ) {
global $wpdb;
$query = " SELECT * FROM " . $wpdb->prefix . "opalestate_message_reply where message_id=" . (int) $id . ' ORDER BY created ';
$messages = $wpdb->get_results( $query );
return $messages;
}
/**
*
*/
public function is_saved() {
}
/**
*
*/
public function get_equiry_form_fields( $msg = '' ) {
$prefix = '';
$id = '';
$sender_id = '';
$post_id = get_the_ID();
$email = '';
$current_user = wp_get_current_user();
$name = '';
if ( 0 != $current_user->ID ) {
$email = $current_user->user_email;
$name = $current_user->user_firstname . ' ' . $current_user->user_lastname;
$sender_id = $current_user->ID;
}
$fields = [
[
'id' => "type",
'name' => esc_html__( 'Type', 'opalestate-pro' ),
'type' => 'hidden',
'default' => 'send_equiry',
'description' => "",
],
[
'id' => "post_id",
'name' => esc_html__( 'Property ID', 'opalestate-pro' ),
'type' => 'hidden',
'default' => $post_id,
'description' => "",
],
[
'id' => "sender_id",
'name' => esc_html__( 'Sender ID', 'opalestate-pro' ),
'type' => 'hidden',
'default' => $sender_id,
'description' => "",
],
[
'id' => "{$prefix}name",
'name' => esc_html__( 'Name', 'opalestate-pro' ),
'type' => 'text',
'before_row' => '',
'required' => 'required',
'default' => $name,
'description' => "",
],
[
'id' => "{$prefix}email",
'name' => esc_html__( 'Email', 'opalestate-pro' ),
'type' => 'text',
'default' => $email,
'description' => "",
'required' => 'required',
],
[
'id' => "{$prefix}phone",
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'type' => 'text',
'description' => "",
'required' => 'required',
],
[
'id' => "{$prefix}message",
'name' => esc_html__( 'Message', 'opalestate-pro' ),
'type' => 'textarea',
'description' => "",
'default' => $msg,
'required' => 'required',
],
];
return $fields;
}
public function get_reply_form_fields() {
$prefix = '';
$fields = [
[
'id' => "type",
'name' => esc_html__( 'Type', 'opalestate-pro' ),
'type' => 'hidden',
'default' => 'send_contact',
'description' => "",
],
[
'id' => "{$prefix}message",
'name' => esc_html__( 'Message', 'opalestate-pro' ),
'type' => 'textarea',
'description' => "",
'required' => 'required',
],
];
return $fields;
}
/**
*
*/
public function get_contact_form_fields( $msg = '' ) {
$prefix = '';
$id = '';
$sender_id = '';
$post_id = get_the_ID();
$email = '';
$current_user = wp_get_current_user();
$name = '';
if ( 0 != $current_user->ID ) {
$email = $current_user->user_email;
$name = $current_user->user_firstname . ' ' . $current_user->user_lastname;
$sender_id = $current_user->ID;
}
$fields = [
[
'id' => "type",
'name' => esc_html__( 'Type', 'opalestate-pro' ),
'type' => 'hidden',
'default' => 'send_contact',
'description' => "",
],
[
'id' => "post_id",
'name' => esc_html__( 'Property ID', 'opalestate-pro' ),
'type' => 'hidden',
'default' => $post_id,
'description' => "",
],
[
'id' => "sender_id",
'name' => esc_html__( 'Sender ID', 'opalestate-pro' ),
'type' => 'hidden',
'default' => $sender_id,
'description' => "",
],
[
'id' => "{$prefix}name",
'name' => esc_html__( 'Name', 'opalestate-pro' ),
'type' => 'text',
'default' => $name,
'required' => 'required',
'description' => "",
],
[
'id' => "{$prefix}email",
'name' => esc_html__( 'Email', 'opalestate-pro' ),
'type' => 'text',
'default' => $email,
'description' => "",
'required' => 'required',
],
[
'id' => "{$prefix}phone",
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'type' => 'text',
'description' => "",
'required' => 'required',
],
[
'id' => "{$prefix}message",
'name' => esc_html__( 'Message', 'opalestate-pro' ),
'type' => 'textarea',
'description' => "",
'default' => $msg,
'required' => 'required',
],
];
return $fields;
}
public function get_request_review_form_fields( $msg = '' ) {
$prefix = '';
$id = '';
$sender_id = '';
$post_id = get_the_ID();
$email = '';
$current_user = wp_get_current_user();
$name = '';
if ( 0 != $current_user->ID ) {
$email = $current_user->user_email;
$name = $current_user->user_firstname . ' ' . $current_user->user_lastname;
$sender_id = $current_user->ID;
}
$fields = [
[
'id' => "type",
'name' => esc_html__( 'Type', 'opalestate-pro' ),
'type' => 'hidden',
'default' => 'send_request_review',
'description' => "",
],
[
'id' => "post_id",
'name' => esc_html__( 'Property ID', 'opalestate-pro' ),
'type' => 'hidden',
'default' => $post_id,
'description' => "",
],
[
'id' => "sender_id",
'name' => esc_html__( 'Sender ID', 'opalestate-pro' ),
'type' => 'hidden',
'default' => $sender_id,
'description' => "",
],
[
'id' => "{$prefix}date",
'name' => esc_html__( 'Schedule', 'opalestate-pro' ),
'type' => 'date',
'before_row' => '',
'required' => 'required',
'description' => "",
],
[
'id' => "{$prefix}time",
'name' => esc_html__( 'Time', 'opalestate-pro' ),
'type' => 'select',
'options' => opalestate_get_time_lapses(),
'description' => "",
],
[
'id' => "{$prefix}phone",
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
'type' => 'text',
'description' => "",
'required' => 'required',
],
[
'id' => "{$prefix}message",
'name' => esc_html__( 'Message', 'opalestate-pro' ),
'type' => 'textarea',
'description' => "",
'default' => $msg,
'required' => 'required',
],
];
return $fields;
}
public function render_user_content_page() {
if ( isset( $_GET['message_id'] ) ) {
$message = $this->get_message( absint( $_GET['message_id'] ) );
return opalestate_load_template_path( 'user/read-messages',
[
'message' => $message,
'fields' => $this->get_reply_form_fields(),
'replies' => $this->get_replies( absint( $_GET['message_id'] ) ),
]
);
} else {
return opalestate_load_template_path( 'user/messages' );
}
}
}
OpalEstate_User_Message::get_instance();

View File

@@ -0,0 +1,141 @@
<?php
/**
* OpalEstate_User_Request_Viewing
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* OpalEstate_User_Message Class
*
* @since 1.0.0
*/
class OpalEstate_User_Request_Viewing {
/**
* @var int
*/
protected $user_id = 0;
/**
* Gets types.
*
* @return array
*/
public function get_types() {
return [
'request_view' => '',
'contact' => '',
'send_equiry' => '',
];
}
/**
* OpalEstate_User_Request_Viewing constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'init' ] );
/// process ajax send message
add_action( 'wp_ajax_send_email_request_reviewing', [ $this, 'process_send_email' ] );
add_action( 'wp_ajax_nopriv_send_email_request_reviewing', [ $this, 'process_send_email' ] );
}
/**
* Set values when user logined in system
*/
public function init() {
global $current_user;
wp_get_current_user();
$this->user_id = $current_user->ID;
}
/**
* get_member_email_data
*
* @param $post_id
* @return array
*/
public function get_member_email_data( $post_id ) {
return opalestate_get_member_email_data( $post_id );
}
/**
* Process send email.
*/
public function process_send_email() {
if ( wp_verify_nonce( $_POST['message_action'], 'property-request-view' ) ) {
$post = $_POST;
$member = $this->get_member_email_data( absint( $post['post_id'] ) );
$output = [
'subject' => isset( $subject ) && $subject ? esc_html( $subject ) : '',
'name' => esc_html( $member['receiver_name'] ),
'receiver_email' => sanitize_email( $member['receiver_email'] ),
'receiver_id' => sanitize_text_field( $member['receiver_id'] ),
'sender_id' => get_current_user_id(),
'sender_email' => sanitize_email( $post['email'] ),
'phone' => sanitize_text_field( $post['phone'] ),
'message' => esc_html( $post['message'] ),
'schedule_time' => sanitize_text_field( $post['time'] ),
'schedule_date' => sanitize_text_field( $post['date'] ),
'post_id' => absint( $post['post_id'] ),
];
$this->insert( $output );
// insert data into request_reviewing form
do_action( 'opalestate_send_email_request_reviewing', $output );
}
$return = [ 'status' => false, 'msg' => esc_html__( 'Unable to send a message.', 'opalestate-pro' ) ];
echo json_encode( $return );
die();
}
public function insert( $data ) {
}
/**
* Install.
*/
public static function install() {
try {
if ( ! function_exists( 'dbDelta' ) ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
}
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'opalestate_message' . ' (
`id` int(11) UNSIGNED NOT NULL,
`subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`message` text COLLATE utf8mb4_unicode_ci NOT NULL,
`phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`sender_email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sender_id` int(11) DEFAULT NULL,
`created` datetime NOT NULL,
`receiver_id` int(11) NOT NULL,
`post_id` int(11) NOT NULL,
`type` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
`isread` tinyint(1) NOT NULL
) ' . $charset_collate;
dbDelta( $sql );
} catch ( Exception $e ) {
}
}
}
new OpalEstate_User_Request_Viewing();

46
inc/message/functions.php Executable file
View File

@@ -0,0 +1,46 @@
<?php
function opalestate_get_message_by_user( $args=array() ){
return array(
'items' => OpalEstate_User_Message::get_instance()->get_list( $args ),
'total' => OpalEstate_User_Message::get_instance()->get_total( $args )
);
}
function opalestate_get_member_email_data( $post_id ){
$output = array();
$type = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'author_type', true );
$receiver_id = 0;
switch ( $type ) {
case 'agent':
$related_id = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'related_id', true );
$post = get_post( $related_id );
$name = $post->post_title;
$email = get_post_meta( $related_id, OPALESTATE_AGENT_PREFIX . 'email', true );
break;
case 'agency':
$related_id = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'related_id', true );
$agent = get_post( $related_id );
$name = $agent->post_title;
$email = get_post_meta( $related_id, OPALESTATE_AGENCY_PREFIX . 'email', true );
break;
default:
$post = get_post( $post_id );
$user = get_user_by( 'id', $post->post_author );
$email = $user->data->user_email;
$name = $user->data->display_name;
$receiver_id = $post->post_author;
break;
}
return $output = array(
'receiver_email' => $email,
'receiver_name' => $name,
'receiver_id' => $receiver_id
);
}
?>

1134
inc/mixes-functions.php Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,690 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Property_MetaBox {
/**
*
*/
public function register_admin_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$box_options = [
'id' => 'property_metabox',
'title' => esc_html__( 'Property Metabox', 'opalestate-pro' ),
'object_types' => [ 'opalestate_property' ],
'show_names' => true,
];
// Setup meta box
$cmb = new_cmb2_box( $box_options );
// Setting tabs
$tabs_setting = [
'config' => $box_options,
'layout' => 'vertical', // Default : horizontal
'tabs' => [],
];
$tabs_setting['tabs'][] = [
'id' => 'p-general',
'icon' => 'dashicons-admin-home',
'title' => esc_html__( 'General', 'opalestate-pro' ),
'fields' => $this->metaboxes_management_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-prices',
'icon' => 'dashicons-admin-tools',
'title' => esc_html__( 'Prices', 'opalestate-pro' ),
'fields' => $this->metaboxes_price_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-information',
'icon' => 'dashicons-admin-post',
'title' => esc_html__( 'Information', 'opalestate-pro' ),
'fields' => $this->metaboxes_info_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-facilities',
'icon' => 'dashicons-grid-view',
'title' => esc_html__( 'Facility', 'opalestate-pro' ),
'fields' => $this->metaboxes_public_facilities_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-floor-plans',
'icon' => 'dashicons-grid-view',
'title' => esc_html__( 'Floor Plan', 'opalestate-pro' ),
'fields' => $this->metaboxes_floor_plans(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-apartments',
'icon' => 'dashicons-admin-multisite',
'title' => esc_html__( 'Apartments', 'opalestate-pro' ),
'fields' => $this->metaboxes_apartments(),
];
////
$tabs_setting['tabs'][] = [
'id' => 'p-gallery',
'icon' => 'dashicons-format-gallery',
'title' => esc_html__( 'Gallery', 'opalestate-pro' ),
'fields' => [
[
'id' => "{$prefix}gallery",
'name' => esc_html__( 'Images Gallery', 'opalestate-pro' ),
'type' => 'file_list',
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
],
],
];
///
$tabs_setting['tabs'][] = [
'id' => 'p-vt_gallery',
'title' => esc_html__( 'Virtual Tour 360', 'opalestate-pro' ),
'icon' => 'dashicons-format-image',
'fields' => [
[
'id' => "{$prefix}vt_gallery",
'name' => esc_html__( 'Manual Images 360 ', 'opalestate-pro' ),
'type' => 'opal_upload',
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
],
[
'id' => "{$prefix}virtual",
'name' => esc_html__( 'Or 360° Virtual Tour', 'opalestate-pro' ),
'type' => 'textarea_code',
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
],
],
];
///
$tabs_setting['tabs'][] = [
'id' => 'p-attachments',
'icon' => 'dashicons-media-default',
'title' => esc_html__( 'Attachments', 'opalestate-pro' ),
'fields' => [
[
'id' => "{$prefix}attachments",
'name' => esc_html__( 'Attachments', 'opalestate-pro' ),
'type' => 'file_list',
'options' => [
'url' => false, // Hide the text input for the url
],
'description' => esc_html__( 'Select one or more files to allow download', 'opalestate-pro' ),
],
],
];
$tabs_setting['tabs'][] = [
'id' => 'p-agents',
'icon' => 'dashicons-admin-users',
'title' => esc_html__( 'Contact Member', 'opalestate-pro' ),
'fields' => $this->metaboxes_members_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-assignment',
'icon' => 'dashicons-admin-users',
'title' => esc_html__( 'User Assignment', 'opalestate-pro' ),
'fields' => $this->metaboxes_assignment_fields(),
];
$tabs_setting['tabs'][] = [
'id' => 'p-layout',
'title' => esc_html__( 'Layout', 'opalestate-pro' ),
'fields' => $this->metaboxes_layout_fields(),
];
// Set tabs
$cmb->add_field( [
'id' => '__tabs',
'type' => 'tabs',
'tabs' => $tabs_setting,
] );
return true;
}
/**
*
*/
public function metaboxes_management_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'name' => esc_html__( 'Featured', 'opalestate-pro' ),
'id' => $prefix . 'featured',
'type' => 'switch',
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
'default' => 0,
],
[
'name' => esc_html__( 'Property SKU', 'opalestate-pro' ),
'id' => $prefix . 'sku',
'type' => 'text',
'description' => esc_html__( 'Please Enter Your Property SKU', 'opalestate-pro' ),
],
[
'id' => $prefix . 'map',
'name' => esc_html__( 'Location', 'opalestate-pro' ),
'type' => 'opal_map',
'sanitization_cb' => 'opal_map_sanitise',
'split_values' => true,
],
[
'name' => esc_html__( 'Postal Code / Zip', 'opalestate-pro' ),
'id' => $prefix . 'zipcode',
'type' => 'text',
],
[
'name' => esc_html__( 'Google Map View', 'opalestate-pro' ),
'id' => $prefix . 'enablemapview',
'type' => 'switch',
'options' => [
1 => esc_html__( 'Yes', 'opalestate-pro' ),
0 => esc_html__( 'No', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Address', 'opalestate-pro' ),
'id' => $prefix . 'address',
'type' => 'textarea_small',
'attributes' => [
'required' => 'required',
],
],
[
'id' => "{$prefix}video",
'name' => esc_html__( 'Video', 'opalestate-pro' ),
'type' => 'text_url',
'description' => esc_html__( 'Input for videos, audios from Youtube, Vimeo and all supported sites by WordPress. It has preview feature.', 'opalestate-pro' ),
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_management', $fields );
}
/**
*
*/
public function metaboxes_price_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$currency = opalestate_currency_symbol() ? ' (' . opalestate_currency_symbol() . ')' : ' ($)';
$fields = [
[
'id' => $prefix . 'price',
'name' => esc_html__( 'Regular Price', 'opalestate-pro' ) . $currency,
'type' => 'text',
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
'attributes' => opalestate_get_option( 'require_input_price' ) ? [ 'required' => 'required' ] : '',
'before_row' => '<div class="row-group-features group-has-three group-price clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Price', 'opalestate-pro' ) ) . '</h3>', // callback
],
[
'id' => $prefix . 'saleprice',
'name' => esc_html__( 'Sale Price', 'opalestate-pro' ) . $currency,
'type' => 'text',
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
],
[
'id' => $prefix . 'before_pricelabel',
'name' => esc_html__( 'Before Price Label (optional)', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Before Price Label (e.g. "from")', 'opalestate-pro' ),
],
[
'id' => $prefix . 'pricelabel',
'name' => esc_html__( 'After Price Label (optional)', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'After Price Label (e.g. "per month")', 'opalestate-pro' ),
'after_row' => '</div>', // callback
],
[
'name' => esc_html__( 'Is Price On Call', 'opalestate-pro' ),
'id' => $prefix . 'price_oncall',
'type' => 'switch',
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
'default' => 0,
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_price', $fields );
}
/**
*
*/
public static function metaboxes_info_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'name' => esc_html__( 'Built year', 'opalestate-pro' ),
'id' => $prefix . 'builtyear',
'type' => 'text_date',
'description' => esc_html__( 'Enter built year', 'opalestate-pro' ),
'before_row' => '<div class="row-group-features group-has-three group-property-info clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Property Information', 'opalestate-pro' ) ) . '</h3>',
// callback
],
[
'name' => esc_html__( 'Parking', 'opalestate-pro' ),
'id' => $prefix . 'parking',
'type' => 'text',
'attributes' => [
'type' => 'number',
'min' => 0,
],
'description' => esc_html__( 'Enter number of Parking', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Bedrooms', 'opalestate-pro' ),
'id' => $prefix . 'bedrooms',
'type' => 'text',
'attributes' => [
'type' => 'number',
'min' => 0,
],
'description' => esc_html__( 'Enter number of bedrooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Bathrooms', 'opalestate-pro' ),
'id' => $prefix . 'bathrooms',
'type' => 'text',
'attributes' => [
'type' => 'number',
'min' => 0,
],
'description' => esc_html__( 'Enter number of bathrooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Plot Size', 'opalestate-pro' ),
'id' => $prefix . 'plotsize',
'type' => 'text',
'description' => esc_html__( 'Enter size of Plot as 20x30, 20x30x40, 20x30x40x50', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Area Size', 'opalestate-pro' ),
'id' => $prefix . 'areasize',
'type' => 'text',
'description' => esc_html__( 'Enter size of area in sqft', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Orientation', 'opalestate-pro' ),
'id' => "{$prefix}orientation",
'type' => 'text',
'description' => esc_html__( 'Enter Orientation of property', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Living Rooms', 'opalestate-pro' ),
'id' => "{$prefix}livingrooms",
'type' => 'text',
'attributes' => [
'type' => 'number',
'min' => 0,
],
'description' => esc_html__( 'Enter Number of Living Rooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Kitchens', 'opalestate-pro' ),
'id' => "{$prefix}kitchens",
'type' => 'text',
'attributes' => [
'type' => 'number',
'min' => 0,
],
'description' => esc_html__( 'Enter Number of Kitchens', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
'id' => "{$prefix}amountrooms",
'type' => 'text',
'attributes' => [
'type' => 'number',
'min' => 0,
],
'description' => esc_html__( 'Enter Number of Amount Rooms', 'opalestate-pro' ),
'after_row' => '</div>',
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_info', $fields );
}
/**
*
*/
public function metaboxes_public_facilities_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'id' => $prefix . 'public_facilities_group',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'public_facilities_key',
'name' => esc_html__( 'Label', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'public_facilities_value',
'name' => esc_html__( 'Content', 'opalestate-pro' ),
'type' => 'text',
],
],
'options' => [
'group_title' => esc_html__( 'Facility {#}', 'opalestate-pro' ),
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
'sortable' => true,
'closed' => false,
],
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_public_facilities', $fields );
}
/**
*
*/
public function metaboxes_members_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
global $post;
$types = [
'hide' => esc_html__( 'Hide Author Information', 'opalestate-pro' ),
'user' => esc_html__( 'User Author Information', 'opalestate-pro' ),
'agent' => esc_html__( 'Agent Information', 'opalestate-pro' ),
'agency' => esc_html__( 'Agency Information', 'opalestate-pro' ),
];
// agent
$agents = [
0 => esc_html__( 'No', 'opalestate-pro' ),
];
if ( isset( $_GET['post'] ) && $_GET['post'] ) {
$id = get_post_meta( (int) $_GET['post'], OPALESTATE_PROPERTY_PREFIX . 'agent', true );
if ( $id ) {
$agents[ $id ] = get_the_title( $id );
}
}
// agency
$agency = [
0 => esc_html__( 'No', 'opalestate-pro' ),
];
if ( isset( $_GET['post'] ) && $_GET['post'] ) {
$id = get_post_meta( (int) $_GET['post'], OPALESTATE_PROPERTY_PREFIX . 'agency', true );
if ( $id ) {
$agency[ $id ] = get_the_title( $id );
}
}
$fields = [
[
'name' => esc_html__( 'Author Information', 'opalestate-pro' ),
'id' => "{$prefix}author_type",
'type' => 'select',
'options' => $types,
'default' => 'user',
],
[
'name' => esc_html__( 'Agent', 'opalestate-pro' ),
'id' => "{$prefix}agent",
'type' => 'select',
'options' => $agents,
],
[
'name' => esc_html__( 'Agency', 'opalestate-pro' ),
'id' => "{$prefix}agency",
'type' => 'select',
'options' => $agency,
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_agent', $fields );
}
/**
*
*/
public function metaboxes_assignment_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
global $post;
// users
$users = [
0 => esc_html__( 'Default User', 'opalestate-pro' ),
];
$all_users = get_users();
foreach ( $all_users as $user ) {
$users[ $user->ID ] = $user->display_name;
}
$fields = [
[
'name' => esc_html__( 'User', 'opalestate-pro' ),
'id' => "post_author_override",
'type' => 'select',
"description" => esc_html__( 'Change to new owner of this property, which be listed in That user dashboard', 'opalestate-pro' ),
'options' => $users,
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_assignment', $fields );
}
/**
*
*/
public function metaboxes_layout_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$templates = opalestate_single_layout_prieview();
$fields = [
[
'name' => esc_html__( 'Layout Display', 'opalestate-pro' ),
'id' => "{$prefix}layout",
'type' => 'select',
'options' => apply_filters( 'opalestate_single_layout_templates', [ '' => esc_html__( 'Inherit', 'opalestate-pro' ) ] ),
'description' => esc_html__( 'Select a layout to display full information of this property', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Preview Display', 'opalestate-pro' ),
'id' => "{$prefix}preview",
'type' => 'select',
'options' => $templates,
'description' => esc_html__( 'Select a layout to display full information of this property', 'opalestate-pro' ),
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_layout', $fields );
}
/**
*
*/
public function metaboxes_floor_plans() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'id' => $prefix . 'public_floor_group',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'floor_name',
'name' => esc_html__( 'Name', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'floor_price',
'name' => esc_html__( 'Price', 'opalestate-pro' ),
'before_row' => '<div class="field-row-2">',
'type' => 'text',
],
[
'id' => $prefix . 'floor_size',
'name' => esc_html__( 'Size', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'floor_room',
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'floor_bath',
'name' => esc_html__( 'Baths', 'opalestate-pro' ),
'type' => 'text',
'after_row' => '</div>',
],
[
'id' => $prefix . 'floor_content',
'name' => esc_html__( 'Content', 'opalestate-pro' ),
'type' => 'textarea_small',
],
[
'id' => "{$prefix}floor_image",
'name' => esc_html__( 'Image Preview', 'opalestate-pro' ),
'type' => 'file',
'query_args' => [
'type' => [
'image/gif',
'image/jpeg',
'image/png',
],
],
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
],
],
'options' => [
'group_title' => esc_html__( 'Floor {#}', 'opalestate-pro' ),
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
'sortable' => true,
'closed' => false,
],
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_floor_plans', $fields );
}
/**
*
*/
public function metaboxes_apartments() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'id' => $prefix . 'apartments',
'type' => 'group',
'fields' => [
[
'id' => $prefix . 'apartment_plot',
'name' => esc_html__( 'Plot', 'opalestate-pro' ),
'before_row' => '<div class="field-row-2">',
'type' => 'text',
],
[
'id' => $prefix . 'apartment_beds',
'name' => esc_html__( 'Beds', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'apartment_price_from',
'name' => esc_html__( 'Price from', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'apartment_floor',
'name' => esc_html__( 'Floor', 'opalestate-pro' ),
'type' => 'text',
'after_row' => '</div>',
],
[
'id' => $prefix . 'apartment_building_address',
'name' => esc_html__( 'Building / Address', 'opalestate-pro' ),
'type' => 'textarea_small',
],
[
'id' => $prefix . 'apartment_status',
'name' => esc_html__( 'Status', 'opalestate-pro' ),
'type' => 'select',
'options' => apply_filters( 'opalestate_property_apartment_statuses', [
'' => esc_html__( 'None', 'opalestate-pro' ),
'available' => esc_html__( 'Available', 'opalestate-pro' ),
'unavailable' => esc_html__( 'Unavailable', 'opalestate-pro' ),
] ),
'before_row' => '<div class="field-row-2">',
],
[
'id' => $prefix . 'apartment_link',
'name' => esc_html__( 'Link', 'opalestate-pro' ),
'type' => 'text',
'after_row' => '</div>',
],
],
'options' => [
'group_title' => esc_html__( 'Apartment {#}', 'opalestate-pro' ),
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
'sortable' => true,
'closed' => false,
],
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_apartments', $fields );
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class Opalestate_Favorite_Property: work as wishlist function
*
* @version 1.0
*/
class Opalestate_Favorite_Property{
/**
* @var integer $userId
*/
protected $userId ;
/**
* Get instance of this object
*/
public static function get_instance(){
static $_instance;
if( !$_instance ){
$_instance = new Opalestate_Favorite_Property();
}
return $_instance;
}
/**
* Constructor
*/
public function __construct(){
add_shortcode( 'opalestate_favorite_button' , array( $this, 'favorite_button' ) );
add_shortcode( 'opalestate_user_favious_properties' , array( $this, 'favorite_properties' ) );
/**
* Ajax action
*/
add_action( 'wp_ajax_opalestate_toggle_status', array($this,'toggle_status') );
add_action( 'wp_ajax_nopriv_opalestate_toggle_status', array($this,'toggle_status') );
add_action( 'init', array($this,'init') );
// show content page in user dashboard
add_filter( 'opalestate_user_content_favorite_page' , array( $this, 'favorite_properties' ) );
}
/**
* Set values when user logined in system
*/
public function init(){
global $current_user;
wp_get_current_user();
$this->userId = $current_user->ID;
}
/**
* Allow set or remove favorite
*/
public function toggle_status(){
if( isset($_POST['property_id']) ){
$property_id = absint( $_POST['property_id'] );
$items = (array)get_user_meta( $this->userId, 'opalestate_user_favorite', true );
$key = array_search( $property_id, $items);
if( $key != false || $key != '' ){
unset($items[$key]);
}else {
$items[] = $property_id;
}
// remove items emty
foreach( $items as $key => $value ) {
if( empty($value) ) {
unset( $items[$key] );
}
}
update_user_meta( $this->userId, 'opalestate_user_favorite', $items );
}
echo $this->favorite_button( array('property_id' => $property_id ) );
exit;
}
/**
* render favorite button in loop
*/
public function favorite_button( $atts ){
$atts['userId'] = $this->userId;
if( !isset($atts['property_id']) ){
$atts['property_id'] = get_the_ID();
}
$items = (array)get_user_meta( $this->userId, 'opalestate_user_favorite', true );
$key = array_search( $atts['property_id'], $items);
$atts['existed'] = $key;
ob_start();
echo opalestate_load_template_path( 'user/favorite-button' , $atts );
$ouput = ob_get_contents();
ob_end_clean();
return $ouput;
}
/**
* show all favorited properties with pagination.
*/
public function favorite_properties(){
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
$per_page = 9;
$items = (array)get_user_meta( $this->userId, 'opalestate_user_favorite', true );
$args = array(
'post_type' => 'opalestate_property',
'paged' => $paged,
'posts_per_page' => $per_page,
'post__in' => !empty($items) ? $items : array( 9999999 )
);
$loop = new WP_Query( $args );
return opalestate_load_template_path( 'user/favorite-properties' , array('loop' => $loop) );
}
}
Opalestate_Favorite_Property::get_instance();

View File

@@ -0,0 +1,79 @@
<?php
/**
* Opalestate_PostType_Property
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Opalestate_PostType_Agency
*
* @version 1.0
*/
class Opalestate_PostType_Property {
/**
* Opalestate_PostType_Property constructor.
*/
public function __construct() {
add_action( 'init', [ __CLASS__, 'definition' ] );
}
/**
* Register Post type and taxonomies
*/
public static function definition() {
if ( ! is_blog_installed() || post_type_exists( 'opalestate_property' ) ) {
return;
}
$labels = [
'name' => esc_html__( 'Properties', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Property', 'opalestate-pro' ),
'add_new' => esc_html__( 'Add New Property', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Property', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Property', 'opalestate-pro' ),
'new_item' => esc_html__( 'New Property', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Properties', 'opalestate-pro' ),
'view_item' => esc_html__( 'View Property', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Property', 'opalestate-pro' ),
'not_found' => esc_html__( 'No Properties found', 'opalestate-pro' ),
'not_found_in_trash' => esc_html__( 'No Properties found in Trash', 'opalestate-pro' ),
'parent_item_colon' => '',
'menu_name' => esc_html__( 'Properties', 'opalestate-pro' ),
];
$labels = apply_filters( 'opalestate_postype_property_labels', $labels );
register_post_type( 'opalestate_property',
apply_filters( 'opalestate_property_post_type_parameters', [
'labels' => $labels,
'supports' => [ 'title', 'editor', 'thumbnail', 'comments', 'author' ],
'public' => true,
'has_archive' => true,
'menu_position' => 51,
'categories' => [],
'menu_icon' => 'dashicons-admin-home',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'query_var' => true,
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'show_in_nav_menus' => true,
'rewrite' => [ 'slug' => esc_html_x( 'property', 'property slug', 'opalestate-pro' ) ],
] )
);
}
}
new Opalestate_PostType_Property();

View File

@@ -0,0 +1,71 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Property_Query {
/**
* The args to pass to the give_get_donors() query
*
* @since 1.8.14
* @access public
*
* @var array
*/
public $args = array();
/**
* The collection found based on the criteria set
*
* @since 1.8.14
* @access public
*
* @var array
*/
public $count = 0;
public $collection = array();
public function insert( ) {
}
public function update() {
}
public function mapping_query(){
}
public function query( $args ){
$this->count = '';
$this->collection = '';
$data = '';
}
public function get_list ( $args ){
return $collection;
}
public function count() {
}
}

View File

@@ -0,0 +1,727 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class Opalestate_Property
*
* @version 1.0
*/
class Opalestate_Property {
/**
* @var Integer $post_id
*
* @access protected
*/
public $post_id;
/**
* @var array $metabox_info
*
* @access protected
*/
protected $metabox_info;
/**
* @var float $price
*
* @access protected
*/
protected $price;
/**
* @var float $saleprice
*
* @access protected
*/
protected $saleprice;
/**
* @var String $map
*
* @access protected
*/
protected $map;
/**
* @var Integer $address
*
* @access protected
*/
public $address;
/**
* @var String $sku
*
* @access protected
*/
public $sku;
/**
* @var String $latitude
*
* @access protected
*/
public $latitude;
/**
* @var String $longitude
*
* @access protected
*/
public $longitude;
/**
* @var Integer $featured 1 or 0
*
* @access protected
*/
public $featured;
/**
* @var array Property page settings $property_settings
*
* @access public
*/
public $property_settings;
/**
* Constructor
*/
public function __construct( $post_id ) {
$this->post_id = $post_id;
$this->map = $this->get_metabox_value( 'map' );
$this->address = $this->get_metabox_value( 'address' );
$this->price = $this->get_metabox_value( 'price' );
$this->saleprice = $this->get_metabox_value( 'saleprice' );
$this->before_pricelabel = $this->get_metabox_value( 'before_pricelabel' );
$this->pricelabel = $this->get_metabox_value( 'pricelabel' );
$this->featured = $this->get_metabox_value( 'featured' );
$this->sku = $this->get_metabox_value( 'sku' );
$this->latitude = isset( $this->map['latitude'] ) ? $this->map['latitude'] : '';
$this->longitude = isset( $this->map['longitude'] ) ? $this->map['longitude'] : '';
}
/**
* Get A Instance Of Opalestate_Property
*/
public static function get_instance( $post_id ) {
static $_instance;
if ( ! $_instance ) {
$_instance = new Opalestate_Property( $post_id );
}
return $_instance;
}
public function get_block_setting( $key ) {
if ( ! $this->property_settings ) {
$keys = [
'amenities',
'attachments',
'facilities',
'video',
'map',
'nearby',
'walkscores',
'apartments',
'floor_plans',
'views_statistics',
];
foreach ( $keys as $key ) {
$this->property_settings[ $key ] = opalestate_get_option( 'enable_single_' . $key, 'on' );
}
}
return $this->property_settings[ $key ];
}
/**
* Gets Amenities
*
* @access public
* @param string $all
* @return array
*/
public function get_meta_fullinfo() {
if ( empty( $this->metabox_info ) ) {
$fields = Opalestate_Property_MetaBox::metaboxes_info_fields();
foreach ( $fields as $a => $field ) {
$id = str_replace( OPALESTATE_PROPERTY_PREFIX, "", $field['id'] );
if ( $field['type'] == 'multicheck' || $field['type'] == 'select' ) {
$opt_values = (array) get_post_meta( $this->post_id, $field['id'] );
if ( ! empty( $opt_values ) && isset( $field['options'] ) ) {
$tmp = [];
foreach ( $opt_values as $key => $val ) {
if ( isset( $field['options'][ $val ] ) ) {
$tmp[ $val ] = $field['options'][ $val ];
}
}
$opt_values = $tmp;
}
$value = implode( ", ", $opt_values );
} else {
$value = get_post_meta( $this->post_id, $field['id'], true );
}
$value = isset( $field['unit'] ) ? $value . ' ' . $field['unit'] : $value;
$this->metabox_info[ $id ] = [ 'label' => $field['name'], 'value' => $value ];
}
}
return $this->metabox_info;
}
public function get_id() {
return $this->post_id;
}
/**
*
*/
public function is_featured() {
return $this->featured;
}
/**
*
*/
public function get_meta_search_objects() {
$prop = new stdClass();
$map = $this->get_metabox_value( 'map' );
$image_id = get_post_thumbnail_id( $this->post_id );
if ( $image_id ) {
$url = wp_get_attachment_url( $image_id, opalestate_options( 'loop_image_size', 'large' ), true );
} else {
$url = opalestate_get_image_placeholder( apply_filters( 'opalestate_loop_property_thumbnail', 'large' ), true );
}
$prop->id = $this->post_id;
$prop->title = get_the_title();
$prop->url = get_permalink( $this->post_id );
$prop->lat = $map['latitude'];
$prop->lng = $map['longitude'];
$prop->address = $this->address;
$prop->pricehtml = opalestate_price_format( $this->get_price() );
$prop->pricelabel = $this->get_price_label();
$prop->thumb = $url;
if ( file_exists( get_template_directory() . '/images/map/market_icon.png' ) ) {
$prop->icon = get_template_directory_uri() . '/images/map/market_icon.png';
} else {
$prop->icon = OPALESTATE_PLUGIN_URL . '/assets/map/market_icon.png';
}
$prop->featured = $this->featured;
$metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
foreach ( $metas as $key => $field ) {
$id = str_replace( OPALESTATE_PROPERTY_PREFIX, "", $field['id'] );
$prop->$id = get_post_meta( $this->post_id, $field['id'], true );
}
$metas = $this->get_meta_shortinfo();
$prop->metas = $metas;
$prop->status = $this->render_statuses();
$terms = wp_get_post_terms( $this->post_id, 'opalestate_types' );
if ( $terms ) {
$term = reset( $terms );
$icon = get_term_meta( $term->term_id, 'opalestate_type_iconmarker', true );
if ( $icon ) {
$prop->icon = $icon;
}
}
return $prop;
}
/**
* Gets Amenities
*
* @access public
* @param string $all
* @return array
*/
public function get_meta_shortinfo() {
$output = [];
$meta = opalestate_options( 'show_property_meta' );
$meta = apply_filters( 'opalestate_property_meta_shortinfo_fields', $meta );
if ( ! empty( $meta ) ) {
$fields = $this->get_meta_fullinfo();
foreach ( $meta as $key => $value ) {
if ( isset( $fields[ $value ] ) ) {
$output[ $value ] = $fields[ $value ];
}
}
}
return $output;
}
/**
* Gets Amenities
*
* @access public
* @param string $all
* @return array
*/
public function get_amenities( $all = true ) {
if ( $all ) {
$terms = Opalestate_Query::get_amenities();
} else {
$terms = wp_get_post_terms( $this->post_id, 'opalestate_amenities' );
}
return $terms;
}
/**
*
*/
public function get_locations() {
$terms = wp_get_post_terms( $this->post_id, 'opalestate_location' );
if ( $terms ) {
return $terms;
}
return [];
}
/**
* Gets locations
*
* @access public
* @return array
*/
public function render_locations() {
$terms = wp_get_post_terms( $this->post_id, 'opalestate_location' );
if ( $terms ) {
$output = '<span class="property-locations">';
foreach ( $terms as $key => $term ) {
$output .= '<a href="' . get_term_link( $term->term_id ) . '" class="location-name">' . $term->name . '</a>';
if ( $key < ( count( $terms ) - 1 ) ) {
$output .= ", ";
}
}
$output .= '</span>';
echo $output;
}
}
/**
* Gets labels
*
* @access public
* @return array
*/
public function get_labels() {
return wp_get_post_terms( $this->post_id, 'opalestate_label' );
}
/**
* Render labels.
*
* @access public
* @return string
*/
public function render_labels() {
$labels = $this->get_labels();
if ( empty( $labels ) ) {
return;
}
$output = '<ul class="property-labels">';
foreach ( $labels as $key => $value ) {
$output .= '<li class="property-labels-item property-label-' . trim( $value->slug ) . '"><span class="label-status label">' . esc_html( $value->name ) . '</span></li>';
}
$output .= '</ul>';
return $output;
}
/**
* Gets statuses
*
* @access public
* @return array
*/
public function get_status() {
$terms = wp_get_post_terms( $this->post_id, 'opalestate_status' );
return $terms;
}
/**
* Render statuses.
*
* @access public
* @return string
*/
public function render_statuses() {
$statuses = $this->get_status();
if ( empty( $statuses ) ) {
return;
}
$output = '<ul class="property-status">';
foreach ( $statuses as $key => $value ) {
$output .= '<li class="property-status-item property-status-' . esc_attr( $value->slug ) . '"><span class="label-status label">' . esc_html( $value->name ) . '</span></li>';
}
$output .= '</ul>';
return $output;
}
/**
*
*/
public function getAuthor() {
}
public function get_author_type() {
return $this->get_metabox_value( 'author_type' );
}
/**
*
*/
public function render_author_link() {
switch ( $this->get_author_type() ) {
case 'hide':
return;
break;
case 'agent':
$agent_id = $this->get_metabox_value( 'agent' );
$data = OpalEstate_Agent::get_link( $agent_id );
break;
case 'agency':
$agency_id = $this->get_metabox_value( 'agency' );
$data = OpalEstate_Agency::get_link( $agency_id );
break;
default:
$data = $this->get_author_link();
break;
}
$avatar = $data['avatar'] ? $data['avatar'] : opalestate_get_image_avatar_placehold();
$avatar = '<img class="avatar" src="' . esc_url( $avatar ) . '" alt="' . $data['name'] . '" />';
return '<a href="' . $data['link'] . '" aria-label="' . $data['name'] . '" class="author-link"><span aria-label="' . $data['name'] . '" class="author-avatar hint--top">' . $avatar . '</span><span class="author-name">' . $data['name'] . '</span></a>';
}
private function get_author_link() {
$image_id = get_user_meta( get_the_author_meta( 'ID' ), OPALESTATE_USER_PROFILE_PREFIX . 'avatar_id', true );
$related_id = get_user_meta( get_the_author_meta( 'ID' ), OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
if ( $image_id ) {
$url = wp_get_attachment_url( $image_id );
} else {
$url = get_avatar_url( get_the_author_meta( 'email' ) );
}
if ( $related_id ) {
$authorlink = get_permalink( $related_id );
$author = get_the_title( $related_id );
} else {
$authorlink = get_author_posts_url( get_the_author_meta( 'ID' ) );
$author = get_the_author();
}
return [
'name' => $author,
'avatar' => $url,
'link' => $authorlink,
];
}
/**
* Gets status
*
* @access public
* @return array
*/
public function get_category_tax() {
$terms = wp_get_post_terms( $this->post_id, 'property_category' );
return $terms;
}
public function get_types_tax() {
$terms = wp_get_post_terms( $this->post_id, 'opalestate_types' );
return $terms;
}
/**
* Gets meta box value
*
* @access public
* @param $key
* @param $single
* @return string
*/
public function get_metabox_value( $key, $single = true ) {
return get_post_meta( $this->post_id, OPALESTATE_PROPERTY_PREFIX . $key, $single );
}
/**
* Gets map value
*
* @access public
* @return string
*/
public function get_map() {
return $this->map;
}
/**
* Gets address value
*
* @access public
* @return string
*/
public function get_address() {
return $this->address;
}
/**
* Gets sku value
*
* @access public
* @return string
*/
public function get_sku() {
return $this->sku;
}
/**
* Gets video url value
*
* @access public
* @return string
*/
public function get_video_url() {
return $this->get_metabox_value( 'video' );
}
/**
* Gets 360 virtual tour value
*
* @access public
* @return string
*/
public function get_virtual_tour() {
return $this->get_metabox_value( 'virtual' );
}
/**
* Gets gallery ids value
*
* @access public
* @return array
*/
public function get_gallery() {
return $this->get_metabox_value( 'gallery', true );
}
public function get_gallery_count() {
$count = $this->get_gallery();
return count( $count );
}
/**
* Gets price value
*
* @access public
* @return string
*/
public function get_price() {
return $this->price;
}
/**
* Gets sale price value
*
* @access public
* @return string
*/
public function get_sale_price() {
return $this->saleprice;
}
/**
* Gets price value
*
* @access public
* @return string
*/
public function get_before_price_label() {
return $this->before_pricelabel;
}
/**
* Gets price value
*
* @access public
* @return string
*/
public function get_price_label() {
return $this->pricelabel;
}
/**
* Gets price format value
*
* @access public
* @return string
*/
public function get_format_price() {
return $this->get_metabox_value( 'formatprice' );
}
public function enable_google_mapview() {
return $this->get_metabox_value( 'enablemapview' );
}
public function get_google_map_link() {
$url = 'https://maps.google.com/maps?q=' . $this->address . '&ll=' . $this->latitude . ',' . $this->longitude . '&z=17';
return $url;
}
public static function is_allowed_remove( $user_id, $item_id ) {
$item = get_post( $item_id );
if ( ! empty( $item->post_author ) ) {
if ( $item->post_author == $user_id ) {
return true;
}
}
return false;
}
public function get_price_oncall() {
return $this->get_metabox_value( 'price_oncall' );
}
public function get_facilities() {
return $this->get_metabox_value( 'public_facilities_group' );
}
public function get_attachments() {
return $this->get_metabox_value( 'attachments' );
}
public function get_content_single_layout() {
return $this->get_metabox_value( 'layout' );
}
public function get_preview_template() {
return $this->get_metabox_value( 'preview' );
}
/**
* Get rating count.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return int
*/
public function get_rating_counts() {
return $this->get_metabox_value( 'rating_count' ) ? $this->get_metabox_value( 'rating_count' ) : 0;
}
/**
* Get average rating.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return float
*/
public function get_average_rating() {
return $this->get_metabox_value( 'average_rating' ) ? $this->get_metabox_value( 'average_rating' ) : 0;
}
/**
* Get review count.
*
* @param string $context What the value is for. Valid values are view and edit.
* @return int
*/
public function get_review_count() {
return $this->get_metabox_value( 'review_count' ) ? $this->get_metabox_value( 'review_count' ) : 0;
}
public function get_rating_count_stats() {
return $this->get_metabox_value( 'rating_count_stats' ) ? $this->get_metabox_value( 'rating_count_stats' ) : [
5 => 0,
4 => 0,
3 => 0,
2 => 0,
1 => 0,
];
}
public function get_rating_average_stats() {
return $this->get_metabox_value( 'rating_average_stats' );
}
public function get_apartments() {
return $this->get_metabox_value( 'apartments' );
}
public function get_floor_plans() {
return $this->get_metabox_value( 'public_floor_group' );
}
public function get_posted() {
return human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ' . esc_html__( 'ago' );
}
}

View File

@@ -0,0 +1,402 @@
<?php
/**
* Opalestate_Query
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Query {
/**
* Set active location
*/
public static $LOCATION;
/**
* Get Query Object to display list of agents
*/
public static function get_agents( $args = [], $featured = false ) {
$default = [
'post_type' => 'opalestate_agent',
'posts_per_page' => 10,
];
$args = array_merge( $default, $args );
if ( $featured ) {
$args['meta_key'] = OPALESTATE_AGENT_PREFIX . 'featured';
$args['meta_value'] = 1;
$args['meta_compare'] = '=';
}
return new WP_Query( $args );
}
/**
* Get Query Object to display list of agents
*/
public static function get_agencies( $args = [], $featured = false ) {
$default = [
'post_type' => 'opalestate_agency',
'posts_per_page' => 10,
];
$args = array_merge( $default, $args );
if ( $featured ) {
$args['meta_key'] = OPALESTATE_AGENCY_PREFIX . 'featured';
$args['meta_value'] = 1;
$args['meta_compare'] = '=';
}
return new WP_Query( $args );
}
/**
* Get Query Object By post and agent with setting items per page.
*/
public static function get_agency_property( $agency_id = null, $user_id = null, $per_page = 10, $page = null ) {
if ( null == $agency_id ) {
$agency_id = get_the_ID();
}
$paged = $page ? $page : ( ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' ) );
// if this has not any relationship with any user
if ( $user_id ) {
$author = [ $user_id ]; //echo '<pre>'.print_r( $post_id, 1 );die;
$team = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
if ( is_array( $team ) ) {
$author = array_merge( $author, $team );
}
$args = [
'post_type' => 'opalestate_property',
'author__in' => $author,
'posts_per_page' => $per_page,
'paged' => $paged,
];
} else {
$agents = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'team', true );
$args = [
'post_type' => 'opalestate_property',
'posts_per_page' => $per_page,
'paged' => $paged,
];
$args['meta_query'] = [ 'relation' => 'OR' ];
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'agency',
'value' => $agency_id,
'compare' => '=',
] );
if ( $agents ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'agent',
'value' => $agents,
] );
}
}
$query = new WP_Query( $args );
return $query;
}
/**
* Get Query Object By post and agent with setting items per page.
*/
public static function get_agent_property( $post_id = null, $agent_id = null, $per_page = 10, $isfeatured = false ) {
if ( null == $post_id ) {
$post_id = get_the_ID();
}
$user_id = get_post_meta( $post_id, OPALESTATE_AGENT_PREFIX . 'user_id', true );
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
$args = [
'post_type' => 'opalestate_property',
'posts_per_page' => $per_page,
'post__not_in' => [ $post_id ],
'paged' => $paged,
];
$args['meta_query'] = [ 'relation' => 'AND' ];
if ( $user_id ) {
$args['author'] = $user_id;
} else {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'agent',
'value' => $agent_id,
'compare' => '=',
] );
}
if ( $isfeatured ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'value' => 'on',
'compare' => '=',
] );
}
$query = new WP_Query( $args );
return $query;
}
/**
* Get Query Object to show featured properties with custom setting via Arguments passing.
*/
public static function get_featured_properties_query( $args = [] ) {
$default = [
'post_type' => 'opalestate_property',
'posts_per_page' => 10,
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'meta_value' => 1,
'meta_compare' => '=',
];
$args = array_merge( $default, $args );
return new WP_Query( $args );
}
/**
* Set filter location to query when user set his location as global filterable.
*/
public static function set_location( $args ) {
if ( $args && self::$LOCATION ) {
$tax_query = [
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => self::$LOCATION,
],
];
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
}
return $args;
}
/**
* Get WP Query Object with custom passing arguments and User request as get data.
*/
public static function get_property_query( $args = [] ) {
$condition = [
'post_type' => 'opalestate_property',
'posts_per_page' => isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : 5,
'paged' => isset( $args['paged'] ) ? $args['paged'] : 1,
];
$condition = array_merge( $condition, $args );
$relation = "AND";
$condition['meta_query'] = [];
$condition['tax_query'] = [
'relation' => $relation,
];
if ( ! empty( $args['categories'] ) ) {
array_push( $condition['tax_query'], [
'taxonomy' => 'property_category',
'terms' => implode( ',', $args['categories'] ),
'field' => 'slug',
'operator' => 'IN',
] );
}
if ( ! empty( $args['types'] ) ) {
array_push( $condition['tax_query'], [
'taxonomy' => 'opalestate_types',
'terms' => $args['types'],
'field' => 'slug',
'operator' => 'IN',
] );
}
if ( ! empty( $args['statuses'] ) ) {
array_push( $condition['tax_query'], [
'taxonomy' => 'opalestate_status',
'terms' => $args['statuses'],
'field' => 'slug',
'operator' => 'IN',
] );
}
if ( ! empty( $args['labels'] ) ) {
array_push( $condition['tax_query'], [
'taxonomy' => 'opalestate_label',
'terms' => $args['labels'],
'field' => 'slug',
] );
}
if ( ! empty( $args['cities'] ) ) {
array_push( $condition['tax_query'], [
'taxonomy' => 'opalestate_city',
'terms' => $args['cities'],
'field' => 'slug',
'operator' => 'IN',
] );
}
if ( ! empty( $args['showmode'] ) ) {
if ( $args['showmode'] == 'featured' ) {
array_push( $condition['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'value' => 'on',
'compare' => '=',
] );
} elseif ( $args['showmode'] == 'normal' ) {
array_push( $condition['meta_query'], [
'relation' => 'OR',
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'compare' => 'NOT EXISTS',
'value' => '' // This is ignored, but is necessary...
],
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'value' => 'on',
'compare' => '!=',
],
] );
}
}
$query = new WP_Query( $condition );
wp_reset_postdata();
return $query;
}
/**
* Get Agent id by property id
*/
public static function get_agent_by_property( $post_id = null ) {
if ( null == $post_id ) {
$post_id = get_the_ID();
}
$agent_id = get_post_meta( $post_id, OPALESTATE_PROPERTY_PREFIX . 'agent', true );
return $agent_id;
}
/**
* Get List of properties by user
*/
public static function get_properties_by_user( $oargs = [], $user_id = null ) {
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
$per_page = 9;
$args = [
'post_type' => 'opalestate_property',
'paged' => $paged,
'post_status' => 'any',
'author' => $user_id,
'posts_per_page' => $per_page,
];
if ( ! empty( $oargs ) || is_array( $oargs ) ) {
$args = array_merge( $args, $oargs );
}
if ( isset( $args['featured'] ) && $args['featured'] ) {
$args = array_merge( $args,
[
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'meta_value' => 'on',
'meta_compare' => '=',
] );
unset( $args['featured'] );
}
$query = new WP_Query( $args );
wp_reset_postdata();
return $query;
}
/**
*
*/
public static function get_amenities() {
return get_terms( 'opalestate_amenities', [ 'hide_empty' => false ] );
}
/**
*
*/
public static function filter_by_location( $geo_lat, $geo_long, $radius, $prefix = OPALESTATE_PROPERTY_PREFIX ) {
global $wpdb;
$radius_measure = '';
$earth = 3959;
if ( $radius_measure == 'km' ) {
$earth = 6371;
}
$latitude = $prefix . 'map_latitude';
$longitude = $prefix . 'map_longitude';
$sql = "SELECT $wpdb->posts.ID,
( %s * acos(
cos( radians(%s) ) *
cos( radians( latitude.meta_value ) ) *
cos( radians( longitude.meta_value ) - radians(%s) ) +
sin( radians(%s) ) *
sin( radians( latitude.meta_value ) )
) )
AS distance, latitude.meta_value AS latitude, longitude.meta_value AS longitude
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta
AS latitude
ON $wpdb->posts.ID = latitude.post_id
INNER JOIN $wpdb->postmeta
AS longitude
ON $wpdb->posts.ID = longitude.post_id
WHERE 1=1
AND latitude.meta_key = '" . $latitude . "'
AND longitude.meta_key= '" . $longitude . "'
HAVING distance < %s
ORDER BY $wpdb->posts.menu_order ASC, distance ASC";
$query = $wpdb->prepare( $sql,
$earth,
$geo_lat,
$geo_long,
$geo_lat,
$radius
);
$post_ids = $wpdb->get_results( $query, OBJECT_K );
if ( $post_ids ) {
$post_ids = array_keys( $post_ids );
return $post_ids;
}
return [ 0 ];
}
}

View File

@@ -0,0 +1,484 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class OpalEstate_Search {
/**
* Add action to ajax search to display query data results with json format.
*/
public static function init() {
add_action( 'wp_ajax_opalestate_ajx_get_properties', [ __CLASS__, 'get_search_json' ] );
add_action( 'wp_ajax_nopriv_opalestate_ajx_get_properties', [ __CLASS__, 'get_search_json' ] );
add_action( 'wp_ajax_opalestate_render_get_properties', [ __CLASS__, 'render_get_properties' ] );
add_action( 'wp_ajax_nopriv_opalestate_render_get_properties', [ __CLASS__, 'render_get_properties' ] );
// add_filter( "pre_get_posts", array( __CLASS__, 'change_archive_query' ) );
}
/**
* Get Query Object to display collection of property with user request which submited via search form
*/
public static function get_search_results_query( $limit = 9 ) {
// global $paged;
global $wp_query;
$show_featured_first = opalestate_options( 'show_featured_first', 1 );
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
$location_text = isset( $_GET['location_text'] ) ? sanitize_text_field( $_GET['location_text'] ) : null;
$posts_per_page = apply_filters( 'opalestate_search_property_per_page', opalestate_options( 'search_property_per_page', $limit ) );
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$paged = isset( $wp_query->query['paged'] ) ? $wp_query->query['paged'] : $paged;
$paged = ! empty( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : $paged;
if ( isset( $_GET['paged'] ) && intval( $_GET['paged'] ) > 0 ) {
$paged = intval( $_GET['paged'] );
}
$infos = [];
$args = [
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'post_type' => 'opalestate_property',
'post_status' => 'publish',
's' => $s,
];
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
}
if ( isset( $_GET['state'] ) && $_GET['state'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_state',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['state'] ),
];
}
if ( isset( $_GET['city'] ) && $_GET['city'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_city',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['city'] ),
];
}
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['types'] ),
];
}
if ( isset( $_GET['status'] ) && $_GET['status'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_status',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['status'] ),
];
}
if ( isset( $_GET['amenities'] ) && is_array( $_GET['amenities'] ) ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_amenities',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['amenities'] ),
];
}
if ( $tax_query ) {
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
}
$args['meta_query'] = [ 'relation' => 'AND' ];
if ( isset( $_GET['info'] ) && is_array( $_GET['info'] ) ) {
$metaquery = [];
foreach ( $_GET['info'] as $key => $value ) {
if ( trim( $value ) ) {
if ( is_numeric( trim( $value ) ) ) {
$fieldquery = [
'key' => OPALESTATE_PROPERTY_PREFIX . $key,
'value' => sanitize_text_field( trim( $value ) ),
'compare' => '>=',
'type' => 'NUMERIC',
];
} else {
$fieldquery = [
'key' => OPALESTATE_PROPERTY_PREFIX . $key,
'value' => sanitize_text_field( trim( $value ) ),
'compare' => 'LIKE',
];
}
$sarg = apply_filters( 'opalestate_search_field_query_' . $key, $fieldquery );
$metaquery[] = $sarg;
}
}
$args['meta_query'] = array_merge( $args['meta_query'], $metaquery );
}
if ( $search_min_price != '' && $search_min_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) {
if ( $search_min_price ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
'value' => [ $search_min_price, $search_max_price ],
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
] );
} else {
array_push( $args['meta_query'], [
[
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
'compare' => 'NOT EXISTS',
],
'relation' => 'OR',
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
'value' => $search_max_price,
'compare' => '<=',
'type' => 'NUMERIC',
],
],
] );
}
} elseif ( $search_min_price != '' && is_numeric( $search_min_price ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
'value' => $search_min_price,
'compare' => '>=',
'type' => 'NUMERIC',
] );
} elseif ( $search_max_price != '' && is_numeric( $search_max_price ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
'value' => $search_max_price,
'compare' => '<=',
'type' => 'NUMERIC',
] );
}
if ( $search_min_area != '' && $search_min_area != '' && is_numeric( $search_min_area ) && is_numeric( $search_max_area ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
'value' => [ $search_min_area, $search_max_area ],
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
] );
} elseif ( $search_min_area != '' && is_numeric( $search_min_area ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
'value' => $search_min_area,
'compare' => '>=',
'type' => 'NUMERIC',
] );
} elseif ( $search_max_area != '' && is_numeric( $search_max_area ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
'value' => $search_max_area,
'compare' => '<=',
'type' => 'NUMERIC',
] );
}
///// search by address and geo location ///
if ( isset( $_GET['geo_long'] ) && isset( $_GET['geo_lat'] ) ) {
if ( $_GET['location_text'] && ( empty( $_GET['geo_long'] ) || empty( $_GET['geo_lat'] ) ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_PROPERTY_PREFIX . 'map_address',
'value' => sanitize_text_field( trim( $_GET['location_text'] ) ),
'compare' => 'LIKE',
'operator' => 'OR',
] );
} elseif ( $_GET['geo_lat'] && $_GET['geo_long'] ) {
$radius = isset( $_GET['geo_radius'] ) ? $_GET['geo_radius'] : 5;
$post_ids = Opalestate_Query::filter_by_location( $_GET['geo_lat'], $_GET['geo_long'], $radius );
$args['post__in'] = $post_ids;
}
}
/// ///
$ksearchs = [];
if ( isset( $_REQUEST['opalsortable'] ) && ! empty( $_REQUEST['opalsortable'] ) ) {
$ksearchs = explode( "_", $_REQUEST['opalsortable'] );
} elseif ( isset( $_SESSION['opalsortable'] ) && ! empty( $_SESSION['opalsortable'] ) ) {
$ksearchs = explode( "_", $_SESSION['opalsortable'] );
}
if ( ! empty( $ksearchs ) && count( $ksearchs ) == 2 ) {
$args['meta_key'] = OPALESTATE_PROPERTY_PREFIX . $ksearchs[0];
$args['orderby'] = 'meta_value_num';
$args['order'] = $ksearchs[1];
}
$args = apply_filters( 'opalestate_get_search_results_query_args', $args );
$query = new WP_Query( $args );
wp_reset_postdata();
return $query;
}
/**
* Get search query base on user request to filter collection of Agents
*/
public static function get_search_agents_query( $args = [] ) {
$min = opalestate_options( 'search_agent_min_price', 0 );
$max = opalestate_options( 'search_agent_max_price', 10000000 );
$search_min_price = isset( $_GET['min_price'] ) ? sanitize_text_field( $_GET['min_price'] ) : '';
$search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['max_price'] ) : '';
$search_min_area = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : '';
$search_max_area = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : '';
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
$default = [
'post_type' => 'opalestate_agent',
'posts_per_page' => apply_filters( 'opalestate_agent_per_page', 12 ),
'paged' => $paged,
];
$args = array_merge( $default, $args );
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
}
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['types'] ),
];
}
if ( $tax_query ) {
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
}
$args['meta_query'] = [ 'relation' => 'AND' ];
if ( $search_min_price != $min && is_numeric( $search_min_price ) ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_AGENT_PREFIX . 'target_min_price',
'value' => $search_min_price,
'compare' => '>=',
// 'type' => 'NUMERIC'
] );
}
if ( is_numeric( $search_max_price ) && $search_max_price != $max ) {
array_push( $args['meta_query'], [
'key' => OPALESTATE_AGENT_PREFIX . 'target_max_price',
'value' => $search_max_price,
'compare' => '<=',
// 'type' => 'NUMERIC'
] );
}
return new WP_Query( $args );
}
/**
* Get search query base on user request to filter collection of Agents
*/
public static function get_search_agencies_query( $args = [] ) {
$s = isset( $_GET['search_text'] ) ? sanitize_text_field( $_GET['search_text'] ) : null;
$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
$default = [
'post_type' => 'opalestate_agency',
'posts_per_page' => apply_filters( 'opalestate_agency_per_page', 12 ),
'paged' => $paged,
];
$args = array_merge( $default, $args );
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
}
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['types'] ),
];
}
if ( $tax_query ) {
$args['tax_query'] = [ 'relation' => 'AND' ];
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
}
$args['meta_query'] = [ 'relation' => 'AND' ];
return new WP_Query( $args );
}
public function filter_by_geolocations() {
}
/**
*
*/
public static function get_setting_search_fields( $option = '' ) {
$options = [
OPALESTATE_PROPERTY_PREFIX . 'bedrooms' => esc_html__( 'Bed Rooms', 'opalestate-pro' ),
OPALESTATE_PROPERTY_PREFIX . 'parking' => esc_html__( 'Parking', 'opalestate-pro' ),
OPALESTATE_PROPERTY_PREFIX . 'bathrooms' => esc_html__( 'Bath Rooms', 'opalestate-pro' ),
];
$default = apply_filters( 'opalestate_default_fields_setting', $options );
$metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
$esettings = [];
$found = false;
foreach ( $metas as $key => $meta ) {
$value = opalestate_options( $meta['id'] . '_opt' . $option );
if ( preg_match( "#areasize#", $meta['id'] ) ) {
continue;
}
if ( $value ) {
$id = str_replace( OPALESTATE_PROPERTY_PREFIX, "", $meta['id'] );
$esettings[ $id ] = $meta['name'];
}
if ( $value == 0 ) {
$found = true;
}
}
if ( ! empty( $esettings ) ) {
return $esettings;
} elseif ( $found ) {
return [];
}
return $default;
}
/**
* Get Json data by action ajax filter
*/
public static function get_search_json() {
$query = self::get_search_results_query();
$output = [];
while ( $query->have_posts() ) {
$query->the_post();
$property = opalesetate_property( get_the_ID() );
$output[] = $property->get_meta_search_objects();
}
wp_reset_query();
echo json_encode( $output );
exit;
}
public static function render_get_properties() {
// $_GET = $_POST;
echo opalestate_load_template_path( 'shortcodes/ajax-map-search-result' );
die;
}
/**
* Render search property form in horizontal
*/
public static function render_horizontal_form( $atts = [] ) {
echo opalestate_load_template_path( 'search-box/search-form-h', $atts );
}
/**
* Render search property form in vertical
*/
public static function render_vertical_form( $atts = [] ) {
echo opalestate_load_template_path( 'search-box/search-form-v', $atts );
}
/**
*
*/
public static function render_field_price() {
}
/**
*
*/
public static function render_field_area() {
}
}
OpalEstate_Search::init();

View File

@@ -0,0 +1,125 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @class OpalEstate_Shortcodes
*
* @version 1.0
*/
class OpalEstate_Shortcodes{
/**
* Static $shortcodes
*/
public $shortcodes;
/**
* defined list of shortcode and functions of this for each.
*/
public function __construct(){
$this->shortcodes = array(
'search_properties_result' => array( 'code' => 'search_properties_result', 'label' => esc_html__( 'Search Properties Result', 'opalestate-pro' ) ),
'search_properties' => array( 'code' => 'search_properties', 'label' => esc_html__( 'Search Properties', 'opalestate-pro' ) ),
'search_properties_v' => array( 'code' => 'search_properties_v', 'label' => esc_html__( 'Search Properties Vertical', 'opalestate-pro' ) ),
'search_map_properties' => array( 'code' => 'search_map_properties', 'label' => esc_html__( 'Search Map Properties', 'opalestate-pro' ) ),
'ajax_map_search' => array( 'code' => 'ajax_map_search', 'label' => esc_html__( 'Ajax Search Map Properties', 'opalestate-pro' ) ),
'ajax_map_quick_search' => array( 'code' => 'ajax_map_quick_search', 'label' => esc_html__( 'Ajax Search Map Properties', 'opalestate-pro' ) ),
'register_form' => array( 'code' => 'register_form', 'label' => esc_html__( 'Register User Form', 'opalestate-pro' ) ),
'login_form' => array( 'code' => 'login_form', 'label' => esc_html__( 'Login Form', 'opalestate-pro' ) ),
);
foreach( $this->shortcodes as $shortcode ){
add_shortcode( 'opalestate_'.$shortcode['code'] , array( $this, $shortcode['code'] ) );
}
if( is_admin() ){
add_action( 'media_buttons', array( $this, 'shortcode_button' ) );
}
}
public function shortcode_button(){
}
public function search_properties_result(){
return opalestate_load_template_path( 'shortcodes/search-properties-result' );
}
/**
* Display all properties follow user when logined
*/
public function agent_property(){
return opalestate_load_template_path( 'shortcodes/agent-property-listing' );
}
/**
* Render search property page with horizontal form and map
*/
public function search_properties(){
return opalestate_load_template_path( 'shortcodes/search-properties', array( 'loop' => '') );
}
/**
* Render search property page with vertical form and map
*/
public function search_properties_v(){
return opalestate_load_template_path( 'shortcodes/search-properties-v', array( 'loop' => '') );
}
public function search_map_properties(){
return opalestate_load_template_path( 'shortcodes/search-map-properties', array( 'loop' => '') );
}
public function ajax_map_search(){
wp_enqueue_script( 'sticky-kit', OPALESTATE_PLUGIN_URL . 'assets/js/jquery.sticky-kit.min.js' );
return opalestate_load_template_path( 'shortcodes/ajax-map-search', array( 'loop' => '') );
}
public function ajax_map_quick_search(){
return opalestate_load_template_path( 'shortcodes/ajax-map-quick-search', array( 'loop' => '') );
}
/* register form show up */
public function register_form( $atts = array() ) {
$atts = shortcode_atts( array(
'message' => '',
'redirect' => '',
'hide_title' => false
), $atts );
return opalestate_load_template_path( 'user/register-form', $atts );
}
/* sign in show up */
public function login_form( $atts = array() ) {
$atts = shortcode_atts( array(
'message' => '',
'redirect' => '',
'hide_title' => false
), $atts );
return opalestate_load_template_path( 'user/login-form', $atts );
}
}
new OpalEstate_Shortcodes();

View File

@@ -0,0 +1,155 @@
<?php
/**
* Property view stats.
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_View_Stats {
protected $id;
protected $record;
public function __construct( $id, $record = 8 ) {
$this->id = $id;
$this->record = $record;
$this->count_page_stats();
}
/**
* @return mixed
*/
public static function get_real_ip_addr() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { //check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { //to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
$ip = '';
}
return $ip;
}
/**
* Count page views.
*/
public function count_page_stats() {
// Get IPs.
$ips = $this->get_ips_viewed();
$current_ip = static::get_real_ip_addr();
if ( ! in_array( $current_ip, $ips ) ) {
// Update IPS.
array_push( $ips, $current_ip );
update_post_meta( $this->id, 'opalestate_ips_viewed', $ips );
// Count and update total views.
$total_views = intval( get_post_meta( $this->id, 'opalestate_total_views', true ) );
if ( $total_views == '' ) {
$total_views = 1;
} else {
$total_views++;
}
update_post_meta( $this->id, 'opalestate_total_views', $total_views );
// Update detailed views.
$today = date( 'm-d-Y', time() );
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
if ( $detailed_views == '' || ! is_array( $detailed_views ) ) {
$detailed_views = [];
$detailed_views[ $today ] = 1;
} else {
if ( ! isset( $detailed_views[ $today ] ) ) {
if ( count( $detailed_views ) > 15 ) {
array_shift( $detailed_views );
}
$detailed_views[ $today ] = 1;
} else {
$detailed_views[ $today ] = intval( $detailed_views[ $today ] ) + 1;
}
}
$detailed_views = update_post_meta( $this->id, 'opalestate_detailed_views', $detailed_views );
}
}
public function get_traffic_labels() {
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
if ( ! is_array( $detailed_views ) ) {
$detailed_views = [];
}
$array_label = array_keys( $detailed_views );
$array_label = array_slice( $array_label, -1 * $this->record, $this->record, false );
return $array_label;
}
public function get_traffic_data() {
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
if ( ! is_array( $detailed_views ) ) {
$detailed_views = [];
}
$array_values = array_values( $detailed_views );
$array_values = array_slice( $array_values, -1 * $this->record, $this->record, false );
return $array_values;
}
public function get_traffic_data_accordion() {
$detailed_views = get_post_meta( $this->id, 'opalestate_detailed_views', true );
if ( ! is_array( $detailed_views ) ) {
$detailed_views = [];
}
// since this runs before we increment the visits - on acc page style
$today = date( 'm-d-Y', time() );
if ( isset( $detailed_views[ $today ] ) ) {
$detailed_views[ $today ] = intval( $detailed_views[ $today ] ) + 1;
}
$array_values = array_values( $detailed_views );
$array_values = array_slice( $array_values, -1 * $this->record, $this->record, false );
return $array_values;
}
/**
* Get IPs viewed.
*
* @return array
*/
public function get_ips_viewed() {
$ips = get_post_meta( $this->id, 'opalestate_ips_viewed', true );
if ( ! $ips ) {
$ips = [];
}
return $ips;
}
}

0
inc/property/functions.php Executable file
View File

84
inc/query-functions.php Executable file
View File

@@ -0,0 +1,84 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
function opalestate_clean_attachments( $user_id ){
$query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'author' => $user_id ,
'meta_query' => array(
array(
'key' => '_pending_to_use_',
'value' => 1,
'compare' => '>=',
)
)
)
);
if( $query->have_posts() ){
while( $query->have_posts() ){ $query->the_post();
wp_delete_attachment( get_the_ID() );
}
}
wp_reset_postdata();
}
/****/
add_filter( 'pre_get_posts', 'opalestate_archives_property_query', 1 );
function opalestate_archives_property_query( $query ){
if( $query->is_main_query() && ( is_post_type_archive( 'opalestate_property' ) || is_tax('property_category') || is_tax('opalestate_amenities') || is_tax('opalestate_location') || is_tax('opalestate_types') ) ){
$args = array();
$ksearchs = array();
if( isset($_REQUEST['opalsortable']) && !empty($_REQUEST['opalsortable']) ){
$ksearchs = explode( "_", $_REQUEST['opalsortable'] );
}
if( !empty($ksearchs) && count($ksearchs) == 2 ){
$args['meta_key'] = OPALESTATE_PROPERTY_PREFIX.$ksearchs[0];
$args['orderby'] = 'meta_value_num';
$args['order'] = $ksearchs[1];
}
if( isset( $_GET['status']) && !empty($_GET['status']) && $_GET['status'] != 'all' ){
$tax_query = array(
array(
'taxonomy' => 'opalestate_status',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['status'] ),
),
);
$args['tax_query'] = array('relation' => 'AND');
$args['tax_query'] = array_merge( $args['tax_query'], $tax_query );
}
if( $args ){
foreach( $args as $key => $value ){
$query->set( $key, $value );
}
}
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Opalestate_PostType_Rating_Features
*/
class Opalestate_PostType_Rating_Features {
/**
* Init action and filter data to define property post type
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
}
/**
* Definition
*/
public function definition() {
if ( ! is_blog_installed() ) {
return;
}
$rating_supports = Opalestate_Rating::get_rating_supports();
foreach ( $rating_supports as $key => $support ) {
$this->register_post_type( $support['features_cpt'], $support['post_type'] );
}
}
public function register_post_type( $cpt_feature, $cpt_support ) {
if ( post_type_exists( $cpt_feature ) ) {
return;
}
register_post_type( $cpt_feature, apply_filters( $cpt_feature . '_cpt_args', [
'labels' => [
'name' => esc_html_x( 'Rating Features', 'Feature plural name', 'opalestate-pro' ),
'singular_name' => esc_html_x( 'Rating Feature', 'Feature singular name', 'opalestate-pro' ),
'menu_name' => esc_html_x( 'Rating Features', 'Admin menu name', 'opalestate-pro' ),
'add_new' => esc_html__( 'Add rating feature', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add new rating feature', 'opalestate-pro' ),
'edit' => esc_html__( 'Edit', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit rating feature', 'opalestate-pro' ),
'new_item' => esc_html__( 'New rating feature', 'opalestate-pro' ),
'view_item' => esc_html__( 'View rating feature', 'opalestate-pro' ),
'search_items' => esc_html__( 'Query rating features', 'opalestate-pro' ),
'not_found' => esc_html__( 'No rating features found', 'opalestate-pro' ),
'not_found_in_trash' => esc_html__( 'No rating features found in trash', 'opalestate-pro' ),
'parent' => esc_html__( 'Parent rating features', 'opalestate-pro' ),
'filter_items_list' => esc_html__( 'Filter rating features', 'opalestate-pro' ),
'items_list_navigation' => esc_html__( 'Rating Features navigation', 'opalestate-pro' ),
'items_list' => esc_html__( 'Rating Features List', 'opalestate-pro' ),
],
'description' => esc_html__( 'This is where store rating features are stored.', 'opalestate-pro' ),
'public' => false,
'hierarchical' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=' . $cpt_support,
'show_in_nav_menus' => false,
'show_in_admin_bar' => false,
'show_in_rest' => true,
'map_meta_cap' => true,
'supports' => [ 'title' ],
'rewrite' => false,
'has_archive' => false,
] ) );
}
}
new Opalestate_PostType_Rating_Features();

View File

@@ -0,0 +1,169 @@
<?php
/**
* Class Opalestate_Rating_Helper
*/
class Opalestate_Rating_Helper {
public static function get_average_rating( $comment, $cpt_feature ) {
$features = static::get_features( $cpt_feature );
if ( $features ) {
$sum = 0;
foreach ( $features as $feature_slug => $feature_title ) {
$sum += absint( get_comment_meta( $comment->comment_ID, $cpt_feature . '_' . $feature_slug, true ) );
}
$average = number_format( $sum / count( $features ), 1 );
} else {
$average = absint( get_comment_meta( $comment->comment_ID, 'opalestate_rating', true ) );
}
return $average;
}
/**
* Get property rating for a property. Please note this is not cached.
*
* @return float
*/
public static function get_average_rating_for_post( $post_id, $cpt_feature ) {
$comments = get_comments( [ 'post_id' => $post_id, 'status' => 'approve' ] );
if ( ! $comments ) {
return 0;
}
$sum = 0;
foreach ( $comments as $comment ) {
$sum += static::get_average_rating( $comment, $cpt_feature );
}
return number_format( $sum / static::get_review_count_for_post( $post_id ), 2 );
}
/**
* Get property review count for a property (not replies). Please note this is not cached.
*/
public static function get_review_count_for_post( $post_id ) {
global $wpdb;
$count = $wpdb->get_var(
$wpdb->prepare(
"
SELECT COUNT(*) FROM $wpdb->comments
WHERE comment_parent = 0
AND comment_post_ID = %d
AND comment_approved = '1'
",
$post_id
)
);
return $count;
}
/**
* Get property rating count for a property. Please note this is not cached.
*/
public static function get_rating_counts_for_post( $post_id, $cpt_feature ) {
$features = static::get_features( $cpt_feature );
if ( $features ) {
return static::get_review_count_for_post( $post_id ) * count( $features );
}
return static::get_review_count_for_post( $post_id );
}
public static function get_rating_count_stats_for_post( $post_id, $cpt_feature ) {
$output = [
5 => 0,
4 => 0,
3 => 0,
2 => 0,
1 => 0,
];
$features = static::get_features( $cpt_feature );
for ( $i = 5; $i >= 1; $i-- ) {
$args = [
'post_id' => $post_id,
'count' => true,
'status' => 'approve',
];
if ( $features ) {
$features_query = [];
foreach ( $features as $feature_slug => $feature_title ) {
$features_query[] = [
'key' => $cpt_feature . '_' . $feature_slug,
'value' => $i,
];
}
$args['meta_query'] = $features_query;
$args['meta_query']['relation'] = 'OR';
} else {
$args['meta_query'] = [
[
'key' => 'opalestate_rating',
'value' => $i,
],
];
}
$output[ $i ] = get_comments( $args );
}
return $output;
}
public static function get_rating_average_stats_by_features_for_post( $post_id, $cpt_feature, $meta_prefix ) {
global $wpdb;
$output = [];
$count = get_post_meta( $post_id, $meta_prefix . 'review_count', true );
$features = static::get_features( $cpt_feature );
if ( ! $features || ! $count ) {
return $output;
}
foreach ( $features as $feature_slug => $feature_title ) {
$meta_key = $cpt_feature . '_' . $feature_slug;
$ratings = $wpdb->get_var(
$wpdb->prepare(
"
SELECT SUM(meta_value) FROM $wpdb->commentmeta
LEFT JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID
WHERE meta_key = %s
AND comment_post_ID = %d
AND comment_approved = '1'
AND meta_value > 0
",
$meta_key,
$post_id
)
);
$average = number_format( $ratings / $count, 2, '.', '' );
$output[ $feature_slug ] = $average;
}
return $output;
}
public static function get_features( $cpt_feature, $posts_per_page = -1 ) {
$args = [
'post_type' => $cpt_feature,
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'opalestate_feature_order',
];
$features = get_posts( $args );
return wp_list_pluck( $features, 'post_title', 'post_name' );
}
}
new Opalestate_Rating_Helper();

View File

@@ -0,0 +1,245 @@
<?php
/**
* Class Opalestate_Rating_Init
*/
class Opalestate_Rating_Init {
/**
* @var string
*/
protected $cpt_support;
/**
* @var string
*/
protected $cpt_feature;
/**
* @var string
*/
protected $meta_prefix;
/**
* Opalestate_Rating_Init constructor.
*
* @param string $cpt_support Custom post type supported name
* @param string $cpt_feature Custom post type feature rating name
* @param string $meta_prefix Meta data prefix.
*/
public function __construct( $cpt_support, $cpt_feature, $meta_prefix ) {
$this->cpt_support = $cpt_support;
$this->cpt_feature = $cpt_feature;
$this->meta_prefix = $meta_prefix;
// Check comment fields.
add_filter( 'comments_open', [ $this, 'comments_open' ], 10, 2 );
add_filter( 'preprocess_comment', [ $this, 'check_comment_rating' ], 0 );
// Add comment rating.
add_action( 'comment_post', [ $this, 'add_comment_rating' ], 1 );
// Clear transients.
add_action( 'wp_update_comment_count', [ $this, 'clear_transients' ] );
// Support avatars for `review` comment type.
add_filter( 'get_avatar_comment_types', [ $this, 'add_avatar_for_review_comment_type' ] );
// Set comment type.
add_filter( 'preprocess_comment', [ $this, 'update_comment_type' ], 1 );
// Remove comment meta boxes.
add_action( 'admin_menu', [ $this, 'remove_meta_boxes' ] );
// Clean
add_action( 'trashed_post', [ $this, 'trash_feature' ] );
add_action( 'untrashed_post', [ $this, 'trash_feature' ] );
add_action( 'delete_post', [ $this, 'clear_meta' ] );
}
/**
* Gets comment type.
*
* @return string
*/
public function get_comment_type() {
return str_replace( 'opalestate_', '', $this->cpt_support ) . '_review';
}
/**
* See if comments are open.
*
* @param bool $open Whether the current post is open for comments.
* @param int $post_id Post ID.
* @return bool
*/
public function comments_open( $open, $post_id ) {
if ( $this->cpt_support === get_post_type( $post_id ) && ! post_type_supports( $this->cpt_support, 'comments' ) ) {
$open = false;
}
return $open;
}
/**
* Validate the comment ratings.
*
* @param array $comment_data Comment data.
* @return array
*/
public function check_comment_rating( $comment_data ) {
// If posting a comment (not trackback etc) and not logged in.
$features = Opalestate_Rating_Helper::get_features( $this->cpt_feature );
if ( $features ) {
foreach ( $features as $feature_slug => $feature_title ) {
$post = $this->cpt_feature . '_' . $feature_slug;
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST[ $post ], $comment_data['comment_type'] ) && $this->cpt_support === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST[ $post ] ) && '' === $comment_data['comment_type'] ) { // WPCS: input var ok, CSRF ok.
wp_die( esc_html__( 'Please rate all features.', 'opalestate-pro' ) );
exit;
}
}
} else {
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $_POST['opalestate_rating'], $comment_data['comment_type'] ) && $this->cpt_support === get_post_type( absint( $_POST['comment_post_ID'] ) ) && empty( $_POST['opalestate_rating'] ) && '' === $comment_data['comment_type'] ) { // WPCS: input var ok, CSRF ok.
wp_die( esc_html__( 'Please rate.', 'opalestate-pro' ) );
exit;
}
}
return $comment_data;
}
/**
* Rating field for comments.
*
* @param int $comment_id Comment ID.
*/
public function add_comment_rating( $comment_id ) {
if ( ! isset( $_POST['comment_post_ID'] ) || ( $this->cpt_support !== get_post_type( absint( $_POST['comment_post_ID'] ) ) ) ) {
return;
}
$features = Opalestate_Rating_Helper::get_features( $this->cpt_feature );
if ( $features ) {
foreach ( $features as $feature_slug => $feature_title ) {
$post = $this->cpt_feature . '_' . $feature_slug;
if ( isset( $_POST[ $post ] ) ) {
if ( ! $_POST[ $post ] || $_POST[ $post ] > 5 || $_POST[ $post ] < 0 ) { // WPCS: input var ok, CSRF ok, sanitization ok.
continue;
}
add_comment_meta( $comment_id, $post, intval( $_POST[ $post ] ), true ); // WPCS: input var ok, CSRF ok.
}
}
} else {
if ( isset( $_POST['opalestate_rating'] ) ) { // WPCS: input var ok, CSRF ok.
if ( ! $_POST['opalestate_rating'] || $_POST['opalestate_rating'] > 5 || $_POST['opalestate_rating'] < 0 ) { // WPCS: input var ok, CSRF ok, sanitization ok.
return;
}
add_comment_meta( $comment_id, 'opalestate_rating', intval( $_POST['opalestate_rating'] ), true ); // WPCS: input var ok, CSRF ok.
}
}
$post_id = isset( $_POST['comment_post_ID'] ) ? absint( $_POST['comment_post_ID'] ) : 0; // WPCS: input var ok, CSRF ok.
if ( $post_id ) {
$this->clear_transients( $post_id );
}
}
/**
* Make sure WP displays avatars for comments with the `$this->cpt_support` type.
*
* @param array $comment_types Comment types.
* @return array
*/
public function add_avatar_for_review_comment_type( $comment_types ) {
return array_merge( $comment_types, [ $this->get_comment_type() ] );
}
/**
* Ensure property average rating and review count is kept up to date.
*
* @param int $post_id Post ID.
*/
public function clear_transients( $post_id ) {
if ( $this->cpt_support === get_post_type( $post_id ) ) {
do_action( 'opalestate_rating_before_clear_transients', $post_id, $this->cpt_support, $this->cpt_feature );
update_post_meta( $post_id, $this->meta_prefix . 'rating_count', Opalestate_Rating_Helper::get_rating_counts_for_post( $post_id, $this->cpt_feature ) );
update_post_meta( $post_id, $this->meta_prefix . 'average_rating', Opalestate_Rating_Helper::get_average_rating_for_post( $post_id, $this->cpt_feature ) );
update_post_meta( $post_id, $this->meta_prefix . 'review_count', Opalestate_Rating_Helper::get_review_count_for_post( $post_id ) );
update_post_meta( $post_id, $this->meta_prefix . 'rating_count_stats', Opalestate_Rating_Helper::get_rating_count_stats_for_post( $post_id, $this->cpt_feature ) );
update_post_meta( $post_id, $this->meta_prefix . 'rating_average_stats', Opalestate_Rating_Helper::get_rating_average_stats_by_features_for_post( $post_id, $this->cpt_feature,
$this->meta_prefix ) );
do_action( 'opalestate_rating_after_clear_transients', $post_id, $this->cpt_support, $this->cpt_feature );
}
}
/**
* Update comment type of property reviews.
*
* @param array $comment_data Comment data.
* @return array
*/
public function update_comment_type( $comment_data ) {
if ( ! is_admin() && isset( $_POST['comment_post_ID'], $comment_data['comment_type'] ) && '' === $comment_data['comment_type'] && $this->cpt_support === get_post_type( absint( $_POST['comment_post_ID'] ) ) ) { // WPCS: input var ok, CSRF ok.
$comment_data['comment_type'] = $this->get_comment_type();
}
return $comment_data;
}
public function remove_meta_boxes() {
// remove_meta_box( 'commentstatusdiv', $this->cpt_support, 'normal' );
remove_meta_box( 'commentsdiv', $this->cpt_support, 'normal' );
}
public function trash_feature( $id ) {
if ( ! $id ) {
return;
}
$post_type = get_post_type( $id );
if ( $post_type !== $this->cpt_feature ) {
return;
}
$this->clean_and_recal();
}
public function clear_meta( $id ) {
if ( ! current_user_can( 'delete_posts' ) || ! $id ) {
return;
}
$post_type = get_post_type( $id );
if ( $post_type !== $this->cpt_feature ) {
return;
}
global $wpdb;
$feature = get_post( $id );
if ( ! $feature ) {
return;
}
$meta_key = $this->cpt_feature . '_' . str_replace( '__trashed', '', $feature->post_name );
if ( $meta_key && ( 0 !== $meta_key ) ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE meta_key = %s;", $meta_key ) );
}
$this->clean_and_recal();
}
protected function clean_and_recal() {
$posts = get_posts( [
'post_type' => $this->cpt_support,
'posts_per_page' => -1,
'post_status' => 'any',
] );
foreach ( $posts as $post ) {
$this->clear_transients( $post->ID );
}
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* Opalestate_Rating_MetaBox
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Opalestate_Rating_MetaBox
*/
class Opalestate_Rating_MetaBox {
public function register_admin_comment_fields() {
$rating_supports = Opalestate_Rating::get_rating_supports();
foreach ( $rating_supports as $key => $support ) {
$this->register_comment_metabox( $support['post_type'], $support['features_cpt'] );
}
}
public function register_admin_feature_fields() {
$rating_supports = Opalestate_Rating::get_rating_supports();
foreach ( $rating_supports as $key => $support ) {
$this->register_feature_metabox( $support['features_cpt'] );
}
}
/**
* Hook in and register a metabox for the admin comment edit page.
*/
public function register_comment_metabox( $cpt_support, $cpt_feature ) {
if ( ! isset( $_GET['c'] ) ) {
return;
}
$comment_type = get_comment_type( sanitize_text_field( $_GET['c'] ) );
if ( $comment_type !== $this->get_comment_type( $cpt_support ) ) {
return;
}
$features = Opalestate_Rating_Helper::get_features( $cpt_feature );
$cmb = new_cmb2_box( [
'id' => $cpt_support . '_comment_meta',
'title' => $features ? esc_html__( 'Rating features', 'opalestate-pro' ) : esc_html__( 'Rating', 'opalestate-pro' ),
'object_types' => [ 'comment' ],
] );
if ( $features ) {
foreach ( $features as $feature_slug => $feature_title ) {
$id = $cpt_feature . '_' . $feature_slug;
$cmb->add_field( [
'id' => $id,
'type' => 'select',
'name' => $feature_title,
'options' => [
'1' => '1&nbsp;&#9733;',
'2' => '2&nbsp;&#9733;&#9733;',
'3' => '3&nbsp;&#9733;&#9733;&#9733;',
'4' => '4&nbsp;&#9733;&#9733;&#9733;&#9733;',
'5' => '5&nbsp;&#9733;&#9733;&#9733;&#9733;&#9733;',
],
// 'show_on_cb' => function ( $cmb ) {
// return isset( $_GET['c'] );
// },
] );
}
} else {
$cmb->add_field( [
'id' => 'opalestate_rating',
'type' => 'select',
'options' => [
'1' => '1&nbsp;&#9733;',
'2' => '2&nbsp;&#9733;&#9733;',
'3' => '3&nbsp;&#9733;&#9733;&#9733;',
'4' => '4&nbsp;&#9733;&#9733;&#9733;&#9733;',
'5' => '5&nbsp;&#9733;&#9733;&#9733;&#9733;&#9733;',
],
// 'show_on_cb' => function ( $cmb ) {
// return isset( $_GET['c'] );
// },
] );
}
}
/**
* Hook in and register a metabox for the admin comment edit page.
*/
public function register_feature_metabox( $cpt_feature ) {
$cmb = new_cmb2_box( [
'id' => $cpt_feature . '_meta',
'title' => esc_html__( 'Data', 'opalestate-pro' ),
'object_types' => [ $cpt_feature ],
] );
$cmb->add_field( [
'name' => esc_html__( 'Description', 'opalestate-pro' ),
'id' => 'opalestate_feature_desc',
'type' => 'textarea_small',
] );
$cmb->add_field( [
'name' => esc_html__( 'Order', 'opalestate-pro' ),
'desc' => esc_html__( 'Set a priority to display', 'opalestate-pro' ),
'id' => 'opalestate_feature_order',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
],
'default' => 0,
] );
}
/**
* Save meta box data
*
* @param mixed $data Data to save.
* @return mixed
*/
public static function save( $data ) {
if ( ! isset( $data['comment_post_ID'] ) || ! $data['comment_post_ID'] ) {
return $data;
}
$comment_post_ID = $data['comment_post_ID'];
$cpt_support = get_post_type( $comment_post_ID );
$rating_supports = Opalestate_Rating::get_rating_supports();
if ( ! isset( $rating_supports[ $cpt_support ] ) || ! isset( $rating_supports[ $cpt_support ]['features_cpt'] ) ) {
return $data;
}
$cpt_feature = $rating_supports[ $cpt_support ]['features_cpt'];
$comment_id = $data['comment_ID'];
$features = Opalestate_Rating_Helper::get_features( $cpt_feature );
if ( $features ) {
foreach ( $features as $feature_slug => $feature_title ) {
$id = $cpt_feature . '_' . $feature_slug;
if ( isset( $_POST[ $id ] ) && ( $_POST[ $id ] > 0 ) && ( $_POST[ $id ] <= 5 ) ) {
update_comment_meta( $comment_id, $id, intval( wp_unslash( $_POST[ $id ] ) ) ); // WPCS: input var ok.
}
}
} else {
if ( isset( $_POST['opalestate_rating'] ) && ( $_POST['opalestate_rating'] > 0 ) && ( $_POST['opalestate_rating'] <= 5 ) ) {
update_comment_meta( $comment_id, 'opalestate_rating', intval( wp_unslash( $_POST['opalestate_rating'] ) ) ); // WPCS: input var ok.
}
}
// Return regular value after updating.
return $data;
}
/**
* Gets comment type.
*
* @return string
*/
public function get_comment_type( $cpt_support ) {
return str_replace( 'opalestate_', '', $cpt_support ) . '_review';
}
}

View File

@@ -0,0 +1,102 @@
<?php
class Opalestate_Rating {
public function __construct() {
$this->includes();
$this->process();
// Template loader.
add_filter( 'comments_template', [ $this, 'comments_template_loader' ] );
// Add shortcode User property reviews.
add_shortcode( 'opalestate_user_property_reviews', [ $this, 'property_reviews_template' ] );
add_filter( 'opalestate_user_content_reviews_page', [ $this, 'property_reviews_template' ] );
}
public function includes() {
require_once 'class-opalestate-rating-features-posttype.php';
require_once 'class-opalestate-rating-metabox.php';
require_once 'class-opalestate-rating-helper.php';
require_once 'class-opalestate-rating-init.php';
require_once 'rating-functions.php';
require_once 'rating-hook-functions.php';
}
public static function get_rating_supports() {
return [
// Support property rating.
'opalestate_property' => [
'post_type' => 'opalestate_property',
'features_cpt' => 'opalestate_rating_ft',
'prefix' => OPALESTATE_PROPERTY_PREFIX,
],
// Support agency rating.
'opalestate_agency' => [
'post_type' => 'opalestate_agency',
'features_cpt' => 'opalestate_agency_ft',
'prefix' => OPALESTATE_AGENCY_PREFIX,
],
// Support agent rating.
'opalestate_agent' => [
'post_type' => 'opalestate_agent',
'features_cpt' => 'opalestate_agent_ft',
'prefix' => OPALESTATE_AGENT_PREFIX,
],
];
}
public function process() {
$rating_supports = static::get_rating_supports();
foreach ( $rating_supports as $key => $support ) {
new Opalestate_Rating_Init( $support['post_type'], $support['features_cpt'], $support['prefix'] );
}
}
/**
* Load comments template.
*
* @param string $template template to load.
* @return string
*/
public function comments_template_loader( $template ) {
$supports = static::get_rating_supports();
$post_type_supports = array_keys( $supports );
if ( ! in_array( get_post_type(), $post_type_supports ) ) {
return $template;
}
$check_dirs = [
trailingslashit( get_stylesheet_directory() ) . 'opalestate/rating/',
trailingslashit( get_template_directory() ) . 'opalestate/rating/',
trailingslashit( get_stylesheet_directory() ),
trailingslashit( get_template_directory() ),
trailingslashit( OPALESTATE_PLUGIN_DIR ) . 'templates/rating/',
];
foreach ( $check_dirs as $dir ) {
$file = 'opalestate-ratings.php';
if ( file_exists( trailingslashit( $dir ) . $file ) ) {
return trailingslashit( $dir ) . $file;
}
}
}
public function property_reviews_template() {
if ( ! is_user_logged_in() || ! $current_user_id = get_current_user_id() ) {
return '';
}
$args = [
'post_author__in' => [ $current_user_id ],
'status' => 'approve',
'type' => 'property_review',
];
$comments = get_comments( $args );
return opalestate_load_template_path( 'user/property-ratings', [ 'comments' => $comments ] );
}
}
new Opalestate_Rating();

107
inc/rating/rating-functions.php Executable file
View File

@@ -0,0 +1,107 @@
<?php
/**
* Check if reviews are enabled.
*
* @return bool
*/
function opalestate_property_reviews_enabled() {
return 'on' === opalestate_get_option( 'enable_property_reviews', 'on' );
}
/**
* Check if reviews are enabled.
*
* @return bool
*/
function opalestate_agency_reviews_enabled() {
return 'on' === opalestate_get_option( 'enable_agency_reviews', 'on' );
}
/**
* Check if reviews are enabled.
*
* @return bool
*/
function opalestate_agent_reviews_enabled() {
return 'on' === opalestate_get_option( 'enable_agent_reviews', 'on' );
}
if ( ! function_exists( 'opalestate_comments' ) ) {
/**
* Output the Review comments template.
*
* @param WP_Comment $comment Comment object.
* @param array $args Arguments.
* @param int $depth Depth.
*/
function opalestate_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment; // WPCS: override ok.
echo opalestate_load_template_path(
'rating/review',
[
'comment' => $comment,
'args' => $args,
'depth' => $depth,
]
);
}
}
if ( ! function_exists( 'opalestate_review_display_gravatar' ) ) {
/**
* Display the review authors gravatar
*
* @param array $comment WP_Comment.
* @return void
*/
function opalestate_review_display_gravatar( $comment ) {
echo get_avatar( $comment, apply_filters( 'opalestate_review_gravatar_size', '60' ), '' );
}
}
if ( ! function_exists( 'opalestate_review_display_rating' ) ) {
/**
* Display the reviewers star rating
*
* @return void
*/
function opalestate_review_display_rating() {
echo opalestate_load_template_path( 'rating/review-rating' );
}
}
if ( ! function_exists( 'opalestate_review_display_meta' ) ) {
/**
* Display the review authors meta (name, verified owner, review date)
*
* @return void
*/
function opalestate_review_display_meta() {
echo opalestate_load_template_path( 'rating/review-meta' );
}
}
if ( ! function_exists( 'opalestate_review_display_comment_text' ) ) {
/**
* Display the review content.
*/
function opalestate_review_display_comment_text() {
echo '<div class="description">';
comment_text();
echo '</div>';
}
}
function opalestate_get_property_rating_features() {
return Opalestate_Rating_Helper::get_features( 'opalestate_rating_ft' );
}
function opalestate_get_agency_rating_features() {
return Opalestate_Rating_Helper::get_features( 'opalestate_agency_ft' );
}
function opalestate_get_agent_rating_features() {
return Opalestate_Rating_Helper::get_features( 'opalestate_agent_ft' );
}

View File

@@ -0,0 +1,13 @@
<?php
/**
* Reviews for opalestate.
*
* @see opalestate_review_display_gravatar()
* @see opalestate_review_display_rating()
* @see opalestate_review_display_meta()
* @see opalestate_review_display_comment_text()
*/
add_action( 'opalestate_review_before', 'opalestate_review_display_gravatar', 10 );
add_action( 'opalestate_review_before_comment_meta', 'opalestate_review_display_meta', 10 );
add_action( 'opalestate_review_meta', 'opalestate_review_display_rating', 10 );
add_action( 'opalestate_review_comment_text', 'opalestate_review_display_comment_text', 10 );

View File

@@ -0,0 +1,679 @@
<?php
/**
* Submission form.
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Property_MetaBox_Submission {
/**
* Defines custom front end fields
*
* @access public
* @param array $metaboxes
* @return array
*/
public function register_form( array $metaboxes ) {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = array_merge(
$this->metaboxes_general_fields_front(),
$this->is_enabled_tab( 'media' ) ? $this->metaboxes_media_fields() : [],
$this->is_enabled_tab( 'location' ) ? $this->metaboxes_location_fields() : [],
$this->is_enabled_tab( 'information' ) ? $this->metaboxes_info_fields() : [],
$this->is_enabled_tab( 'amenities' ) ? $this->metaboxes_amenities_fields() : [],
$this->is_enabled_tab( 'facilities' ) ? $this->metaboxes_public_facilities_fields() : [],
$this->is_enabled_tab( 'apartments' ) ? $this->metaboxes_public_apartments_fields() : [],
$this->is_enabled_tab( 'floor_plans' ) ? $this->metaboxes_public_floor_plans_fields() : []
);
$metaboxes[ $prefix . 'front' ] = [
'id' => $prefix . 'front',
'title' => esc_html__( 'Name and Description', 'opalestate-pro' ),
'object_types' => [ 'opalestate_property' ],
'context' => 'normal',
'priority' => 'high',
'save_fields' => false,
'show_names' => true,
'fields' => $fields,
'cmb_styles' => false,
];
return $metaboxes;
}
public function get_fields_groups() {
return [
'general' => [ 'status' => true, 'title' => esc_html__( 'General', 'opalestate-pro' ) ],
'media' => [ 'status' => $this->is_enabled_tab( 'media' ), 'title' => esc_html__( 'Media', 'opalestate-pro' ) ],
'location' => [ 'status' => $this->is_enabled_tab( 'location' ), 'title' => esc_html__( 'Location', 'opalestate-pro' ) ],
'information' => [ 'status' => $this->is_enabled_tab( 'information' ), 'title' => esc_html__( 'Information', 'opalestate-pro' ) ],
'amenities' => [ 'status' => $this->is_enabled_tab( 'amenities' ), 'title' => esc_html__( 'Amenities', 'opalestate-pro' ) ],
'facilities' => [ 'status' => $this->is_enabled_tab( 'facilities' ), 'title' => esc_html__( 'Facilities', 'opalestate-pro' ) ],
'apartments' => [ 'status' => $this->is_enabled_tab( 'apartments' ), 'title' => esc_html__( 'Apartments', 'opalestate-pro' ) ],
'floor_plans' => [ 'status' => $this->is_enabled_tab( 'floor_plans' ), 'title' => esc_html__( 'Floor plans', 'opalestate-pro' ) ]
];
}
public function metaboxes_general_fields_front() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$post_id = '';
if ( ! empty( $_GET['id'] ) ) {
$post = get_post( intval( $_GET['id'] ) );
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( absint( $_GET['id'] ) ) );
$post_id = $post->ID;
}
$currency = opalestate_currency_symbol() ? ' (' . opalestate_currency_symbol() . ')' : ' ($)';
$fields = [
[
'id' => 'post_type',
'type' => 'hidden',
'default' => 'opalestate_property',
],
[
'id' => 'post_id',
'type' => 'hidden',
'default' => $post_id,
],
[
'name' => esc_html__( 'Title', 'opalestate-pro' ) . '<span class="required"> *</span>',
'id' => $prefix . 'title',
'type' => 'text',
'default' => ! empty( $post ) ? $post->post_title : '',
'before_row' => '<div id="opalestate-submission-general" class="opalestate-tab-content">',
'attributes' => [
'required' => 'required',
],
],
[
'name' => esc_html__( 'Description', 'opalestate-pro' ),
'id' => $prefix . 'text',
'type' => 'wysiwyg',
'default' => ! empty( $post ) ? $post->post_content : '',
'before_row' => '<hr>',
],
[
'id' => $prefix . 'price',
'name' => esc_html__( 'Regular Price', 'opalestate-pro' ) . $currency . '<span class="required"> *</span>',
'type' => 'text',
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
'attributes' => opalestate_get_option( 'require_input_price' ) ? [ 'required' => 'required' ] : '',
'before_row' => '<hr><div class="field-row-2">', // callback
],
[
'id' => $prefix . 'saleprice',
'name' => esc_html__( 'Sale Price', 'opalestate-pro' ) . $currency,
'type' => 'text',
'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ),
],
[
'id' => $prefix . 'before_pricelabel',
'name' => esc_html__( 'Before Price Label (optional)', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'Before Price Label (e.g. "from")', 'opalestate-pro' ),
],
[
'id' => $prefix . 'pricelabel',
'name' => esc_html__( 'After Price Label (optional)', 'opalestate-pro' ),
'type' => 'text',
'description' => esc_html__( 'After Price Label (e.g. "per month")', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Statuses', 'opalestate-pro' ),
'id' => $prefix . 'status',
'type' => 'taxonomy_select',
'taxonomy' => 'opalestate_status',
'class' => 'form-control',
'attributes' => [
'required' => 'required',
],
'before_row' => '</div><hr><div class="field-row-2">', // callback
],
[
'name' => esc_html__( 'Types', 'opalestate-pro' ),
'id' => $prefix . 'type',
'type' => 'taxonomy_select',
'taxonomy' => 'opalestate_types',
'class' => 'form-control',
'attributes' => [
'required' => 'required',
],
'after_row' => '</div><hr><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>', // callback
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_general', $fields );
}
public function metaboxes_media_fields() {
$id = 0;
if( isset($_GET['id']) ){
$post_id = intval( $_GET['id'] );
$id = get_post_thumbnail_id( $post_id );
}
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'id' => "{$prefix}featured_image",
'name' => esc_html__( 'Featured Image', 'opalestate-pro' ),
'type' => 'uploader',
'single' => true,
'value' => $id,
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
'before_row' => '<div id="opalestate-submission-media" class="opalestate-tab-content">',
],
[
'id' => "{$prefix}gallery",
'name' => esc_html__( 'Images Gallery', 'opalestate-pro' ),
'type' => 'uploader',
'description' => esc_html__( 'Select one or more images to show as gallery', 'opalestate-pro' ),
],
[
'id' => "{$prefix}video",
'name' => esc_html__( 'Video', 'opalestate-pro' ),
'type' => 'text_url',
'before_row' => '<hr>',
'description' => esc_html__( 'Input for videos, audios from Youtube, Vimeo and all supported sites by WordPress. It has preview feature.', 'opalestate-pro' ),
],
[
'id' => "{$prefix}virtual",
'name' => esc_html__( '360° Virtual Tour', 'opalestate-pro' ),
'type' => 'textarea_small',
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
'before_row' => '<hr>'
],
[
'id' => "{$prefix}attachments",
'name' => esc_html__( 'Attachments', 'opalestate-pro' ),
'type' => 'uploader',
'before_row' => '<hr>',
'show_icon' => true,
'accept' => 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'options' => [
'url' => true, // Hide the text input for the url
],
'description' => esc_html__( 'Select one or more files to allow download', 'opalestate-pro' ),
'after_row' => '<hr><button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step ',
'opalestate-pro' ) . '</button><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>',
],
];
return apply_filters( 'opalestate_postype_property_metaboxes_fields_price', $fields );
}
public function metaboxes_info_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'name' => esc_html__( 'Built year', 'opalestate-pro' ),
'id' => $prefix . 'builtyear',
'type' => 'text_date',
'description' => esc_html__( 'Enter built year', 'opalestate-pro' ),
'before_row' => '<div id="opalestate-submission-information" class="opalestate-tab-content"><div class="field-row-2">',
],
[
'name' => esc_html__( 'Parking', 'opalestate-pro' ),
'id' => $prefix . 'parking',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter number of Parking', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Bedrooms', 'opalestate-pro' ),
'id' => $prefix . 'bedrooms',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter number of bedrooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Bathrooms', 'opalestate-pro' ),
'id' => $prefix . 'bathrooms',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter number of bathrooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Plot Size', 'opalestate-pro' ),
'id' => $prefix . 'plotsize',
'type' => 'text',
'description' => esc_html__( 'Enter size of Plot as 20x30, 20x30x40, 20x30x40x50', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Area Size', 'opalestate-pro' ),
'id' => $prefix . 'areasize',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter size of area in sqft', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Orientation', 'opalestate-pro' ),
'id' => "{$prefix}orientation",
'type' => 'text',
'description' => esc_html__( 'Enter Orientation of property', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Living Rooms', 'opalestate-pro' ),
'id' => "{$prefix}livingrooms",
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter Number of Living Rooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Kitchens', 'opalestate-pro' ),
'id' => "{$prefix}kitchens",
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter Number of Kitchens', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
'id' => "{$prefix}amountrooms",
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
'sanitization_cb' => 'absint',
'escape_cb' => 'absint',
'description' => esc_html__( 'Enter Number of Amount Rooms', 'opalestate-pro' ),
'after_row' => '</div><hr><button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step',
'opalestate-pro' ) . '</button><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>',
],
];
return apply_filters( 'opalestate_metaboxes_public_info_fields', $fields );
}
public function metaboxes_location_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$management = [
[
'name' => esc_html__( 'Country', 'opalestate-pro' ),
'id' => $prefix . 'location',
'type' => 'taxonomy_select',
'taxonomy' => 'opalestate_location',
'before_row' => '<div id="opalestate-submission-location" class="opalestate-tab-content"><div class="field-row-2">',
],
[
'name' => esc_html__( 'States / Province', 'opalestate-pro' ),
'id' => $prefix . 'state',
'type' => 'taxonomy_select',
'taxonomy' => 'opalestate_state',
],
[
'name' => esc_html__( 'City / Town', 'opalestate-pro' ),
'id' => $prefix . 'city',
'type' => 'taxonomy_select',
'taxonomy' => 'opalestate_city',
],
[
'name' => esc_html__( 'Postal Code / Zip', 'opalestate-pro' ),
'id' => $prefix . 'zipcode',
'type' => 'text',
'after_row'=> '</div><hr>'
],
[
'name' => esc_html__( 'Address', 'opalestate-pro' ) . '<span class="required"> *</span>',
'id' => $prefix . 'address',
'type' => 'text',
'attributes' => [
'required' => 'required',
],
],
[
'name' => esc_html__( 'Google Map View', 'opalestate-pro' ),
'id' => $prefix . 'enablemapview',
'type' => 'switch',
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
'description' => esc_html__( 'Enable Google Map', 'opalestate-pro' ),
],
[
'id' => $prefix . 'map',
'name' => esc_html__( 'Google Map', 'opalestate-pro' ),
'type' => 'opal_map',
'sanitization_cb' => 'opal_map_sanitise',
'split_values' => true,
'after_row' => '<button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step',
'opalestate-pro' ) . '</button><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>',
],
];
return $management;
}
public function metaboxes_amenities_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'name' => esc_html__( 'Amenities', 'opalestate-pro' ),
'id' => $prefix . 'amenity',
'type' => 'taxonomy_multicheck',
'before_row' => '<div id="opalestate-submission-amenities" class="opalestate-tab-content">',
'after_row' => '<button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step',
'opalestate-pro' ) . '</button><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>',
'taxonomy' => 'opalestate_amenities',
'render_row_cb' => [ $this, 'amenities_html_callback' ],
],
];
return apply_filters( 'opalestate_metaboxes_amenities_fields', $fields );
}
public function metaboxes_public_facilities_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'id' => $prefix . 'public_facilities_group',
'type' => 'group',
'before_group' => '<div id="opalestate-submission-facilities" class="opalestate-tab-content">',
'after_group' => '<button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step',
'opalestate-pro' ) . '</button><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>',
'fields' => [
[
'id' => $prefix . 'public_facilities_key',
'name' => esc_html__( 'Label', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'public_facilities_value',
'name' => esc_html__( 'Content', 'opalestate-pro' ),
'type' => 'text',
],
],
'options' => [
'group_title' => esc_html__( 'Facility {#}', 'opalestate-pro' ),
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
'sortable' => true,
'closed' => true,
],
],
];
return apply_filters( 'opalestate_metaboxes_public_facilities_fields', $fields );
}
public function metaboxes_public_apartments_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'name' => esc_html__( 'Apartments', 'opalestate-pro' ),
'id' => $prefix . 'enable_apartments',
'type' => 'heading',
'options' => [
0 => esc_html__( 'No', 'opalestate-pro' ),
1 => esc_html__( 'Yes', 'opalestate-pro' ),
],
'before_row' => '<div id="opalestate-submission-apartments" class="opalestate-tab-content">',
],
[
'id' => $prefix . 'apartments',
'type' => 'group',
'after_group' => '<button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step',
'opalestate-pro' ) . '</button><button type="button" class="submission-next-btn btn btn-primary">' . esc_html__( 'Next Step', 'opalestate-pro' ) . '</button></div>',
'fields' => [
[
'id' => $prefix . 'apartment_plot',
'name' => esc_html__( 'Plot', 'opalestate-pro' ),
'before_row' => '<div class="field-row-2">',
'type' => 'text',
],
[
'id' => $prefix . 'apartment_beds',
'name' => esc_html__( 'Beds', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'apartment_price_from',
'name' => esc_html__( 'Price from', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'apartment_floor',
'name' => esc_html__( 'Floor', 'opalestate-pro' ),
'type' => 'text',
'after_row' => '</div>',
],
[
'id' => $prefix . 'apartment_building_address',
'name' => esc_html__( 'Building / Address', 'opalestate-pro' ),
'type' => 'textarea_small',
],
[
'id' => $prefix . 'apartment_status',
'name' => esc_html__( 'Status', 'opalestate-pro' ),
'type' => 'select',
'options' => apply_filters( 'opalestate_property_apartment_statuses', [
'available' => esc_html__( 'Available', 'opalestate-pro' ),
'unavailable' => esc_html__( 'Unavailable', 'opalestate-pro' ),
] ),
'before_row' => '<div class="field-row-2">',
],
[
'id' => $prefix . 'apartment_link',
'name' => esc_html__( 'Link', 'opalestate-pro' ),
'type' => 'text',
'default' => '#',
'after_row' => '</div>',
],
],
'options' => [
'group_title' => esc_html__( 'Apartment {#}', 'opalestate-pro' ),
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
'sortable' => true,
'closed' => true,
],
],
];
return apply_filters( 'opalestate_metaboxes_public_apartments_fields', $fields );
}
public function metaboxes_public_floor_plans_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$fields = [
[
'name' => esc_html__( 'Floor Plans', 'opalestate-pro' ),
'id' => $prefix . 'enable_floor',
'type' => 'heading',
'before_row' => '<div id="opalestate-submission-floor_plans" class="opalestate-tab-content">',
],
[
'id' => $prefix . 'public_floor_group',
'type' => 'group',
'after_group' => '<button type="button" class="submission-back-btn btn btn-primary">' . esc_html__( 'Previous Step', 'opalestate-pro' ) . '</button></div>',
'fields' => [
[
'id' => $prefix . 'floor_name',
'name' => esc_html__( 'Name', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'floor_price',
'name' => esc_html__( 'Price', 'opalestate-pro' ),
'before_row' => '<div class="field-row-2">',
'type' => 'text',
],
[
'id' => $prefix . 'floor_size',
'name' => esc_html__( 'Size', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'floor_room',
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
'type' => 'text',
],
[
'id' => $prefix . 'floor_bath',
'name' => esc_html__( 'Baths', 'opalestate-pro' ),
'type' => 'text',
'after_row' => '</div>',
],
[
'id' => $prefix . 'floor_content',
'name' => esc_html__( 'Content', 'opalestate-pro' ),
'type' => 'textarea_small',
],
[
'id' => "{$prefix}floor_image_id",
'name' => esc_html__( 'Image Preview', 'opalestate-pro' ),
'type' => 'uploader',
'single' => 1,
'query_args' => [
'type' => [
'image/gif',
'image/jpeg',
'image/png',
],
],
'description' => esc_html__( 'Input iframe to show 360° Virtual Tour.', 'opalestate-pro' ),
],
],
'options' => [
'group_title' => esc_html__( 'Floor {#}', 'opalestate-pro' ),
'add_button' => esc_html__( 'Add more', 'opalestate-pro' ),
'remove_button' => esc_html__( 'Remove', 'opalestate-pro' ),
'sortable' => true,
'closed' => false,
],
],
];
return apply_filters( 'opalestate_metaboxes_public_floor_plans_fields', $fields );
}
protected function is_enabled_tab( $tab ) {
return ( 'on' === opalestate_get_option( 'enable_submission_tab_' . $tab, true ) );
}
/**
* Manually render a field column display.
*
* @param array $field_args Array of field arguments.
* @param CMB2_Field $field The field object
*/
public function amenities_html_callback( $field_args, $field ) {
$id = $field->args( 'id' );
$label = $field->args( 'name' );
$name = $field->args( '_name' );
$value = $field->escaped_value();
$description = $field->args( 'description' );
$amenites = get_terms( [
'taxonomy' => 'opalestate_amenities',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
] );
if ( ! $amenites ) {
return;
}
?>
<div id="opalestate-submission-amenities" class="opalestate-tab-content">
<div class="cmb-row cmb-type-taxonomy-multicheck cmb2-id-opalestate-ppt-amenity" data-fieldtype="taxonomy_multicheck">
<div class="cmb-th">
<label for="<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $label ); ?></label>
</div>
<div class="cmb-td">
<ul class="cmb2-checkbox-list list-inline cmb2-list">
<?php foreach ( $amenites as $key => $amenity ) : ?>
<li>
<input type="checkbox" class="cmb2-option" name="<?php echo esc_attr( $name ); ?>[]" id="opalestate_ppt_amenity<?php echo esc_attr( $key + 1 ); ?>"
value="<?php echo esc_attr( $amenity->slug ); ?>">
<label for="opalestate_ppt_amenity<?php echo esc_attr( $key + 1 ); ?>">
<?php
if ( $image_id = get_term_meta( $amenity->term_id, 'opalestate_amt_image_id', true )) {
echo opalestate_get_image_by_id( $image_id );
}
?>
<?php echo esc_html( $amenity->name ); ?>
</label>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<button type="button" class="submission-back-btn btn btn-primary"><?php esc_html_e( 'Previous Step', 'opalestate-pro' ); ?></button>
<button type="button" class="submission-next-btn btn btn-primary"><?php esc_html_e( 'Next Step', 'opalestate-pro' ); ?></button>
</div>
<?php
}
}

View File

@@ -0,0 +1,701 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! session_id() ) {
@session_start();
}
/**
* @class OpalEstate_Submission
*
* @version 1.0
*/
class OpalEstate_Submission {
/**
*
*
*/
public $metabox;
/**
*
*
*/
public $new_attachmenet_ids = array();
/**
* Constructor
*/
public function __construct() {
/**
* Can not use $this->is_submission_page() || use 'wp_enqueue_scripts' here
* because inside this hook global $post == null
*/
add_action( 'wp_head', [ $this, 'head_check_page' ] );
add_action( 'cmb2_after_init', [ $this, 'process_submission' ], 10000 );
add_action( 'opalestate_single_property_before', [ $this, 'render_button_edit' ] );
if ( is_admin() ) {
add_filter( 'opalestate_settings_tabs', [ $this, 'setting_content_tab' ] );
add_filter( 'opalestate_registered_submission_page_settings', [ $this, 'setting_content_fields' ] );
}
add_action( 'opalestate_user_content_submission_list_page', [ $this, 'submission_list' ] );
add_action( 'opalestate_user_content_submission_page', [ $this, 'submission' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'scripts_styles' ], 99 );
$this->register_shortcodes();
}
/**
* Save post.
*/
public function scripts_styles() {
wp_register_style( 'opalesate-submission', OPALESTATE_PLUGIN_URL . 'assets/submission.css' );
wp_register_style( 'opalesate-cmb2-front', OPALESTATE_PLUGIN_URL . 'assets/cmb2-front.css' );
wp_register_script(
'opalestate-submission',
OPALESTATE_PLUGIN_URL . 'assets/js/frontend/submission.js',
[
'jquery',
],
'1.0',
true
);
}
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function register_shortcodes() {
$shortcodes = [
'submission' => [
'code' => 'submission',
'label' => esc_html__( 'Submission Form', 'opalestate-pro' ),
],
'submission_list' => [
'code' => 'submission_list',
'label' => esc_html__( 'My Properties', 'opalestate-pro' ),
]
];
foreach ( $shortcodes as $shortcode ) {
add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] );
}
}
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function setting_content_tab( $tabs ) {
$tabs['submission_page'] = esc_html__( 'Submission Page', 'opalestate-pro' );
return $tabs;
}
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function setting_content_fields( $fields = [] ) {
$fields = [
'id' => 'submission_page',
'title' => esc_html__( 'Email Settings', 'opalestate-pro' ),
'show_on' => [ 'key' => 'options-page', 'value' => [ 'opalestate_settings' ], ],
'fields' => apply_filters( 'opalestate_settings_submission', [
[
'name' => esc_html__( 'Submission Page Settings', 'opalestate-pro' ),
'id' => 'opalestate_title_submission_page_settings',
'type' => 'title',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Property Submission Page', 'opalestate-pro' ),
'desc' => esc_html__( 'This is the submission page. The <code>[opalestate_submission]</code> shortcode should be on this page.', 'opalestate-pro' ),
'id' => 'submission_page',
'type' => 'select',
'options' => opalestate_cmb2_get_post_options( [
'post_type' => 'page',
'numberposts' => -1,
] ),
],
[
'name' => esc_html__( 'Show Content Use Not Login', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Login/Register form and submission form if user not logined', 'opalestate-pro' ),
'id' => 'submission_show_content',
'type' => 'select',
'default' => '',
'options' => [
'' => esc_html__( 'Show Login Form', 'opalestate-pro' ),
'login_submission' => esc_html__( 'Show Login Form and Submission Form', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Admin Approve', 'opalestate-pro' ),
'desc' => esc_html__( 'the Property will be auto approve when user submit, if you do not enable it.', 'opalestate-pro' ),
'id' => 'admin_approve',
'type' => 'checkbox',
],
[
'name' => esc_html__( 'Enable Require Price', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable or Disable require user enter price and price label.', 'opalestate-pro' ),
'id' => 'require_input_price',
'type' => 'checkbox',
],
[
'name' => esc_html__( 'Submission Tab Settings', 'opalestate-pro' ),
'id' => 'opalestate_title_submission_tab_settings',
'type' => 'title',
'before_row' => '<hr>',
'after_row' => '<hr>',
],
[
'name' => esc_html__( 'Enable Media tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Media tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_media',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Location tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Location tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_location',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Information tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Information tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_information',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Amenities tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Amenities tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_amenities',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Facilities tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Facilities tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_facilities',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Apartments tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Apartments tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_apartments',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Enable Floor plans tab', 'opalestate-pro' ),
'desc' => esc_html__( 'Enable Floor plans tab', 'opalestate-pro' ),
'id' => 'enable_submission_tab_floor_plans',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
],
]
),
];
return $fields;
}
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function head_check_page() {
}
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function render_button_edit() {
global $post, $current_user;
wp_get_current_user();
if ( $current_user->ID == $post->post_author ) {
echo '<div class="property-button-edit">
<a href="' . opalestate_submssion_page( $post->ID ) . '">' . esc_html__( 'Edit My Property', 'opalestate-pro' ) . '</a>
</div>';
}
}
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function is_submission_page() {
global $post;
if ( ! $post || ! isset( $post->ID ) || ! $post->ID ) {
return false;
}
return opalestate_get_option( 'submission_page' ) == $post->ID;
}
/**
*
*
*/
public function register_metabox() {
$metabox = new Opalestate_Property_MetaBox_Submission();
add_filter( 'cmb2_meta_boxes', [ $metabox, 'register_form' ], 9999 );
return $metabox;
}
/**
* FrontEnd Submission
*/
public function submission() {
global $current_user;
if ( ! is_user_logged_in() ) {
echo opalestate_load_template_path( 'submission/require-login' );
if( empty(opalestate_get_option("submission_show_content")) ){
return "";
}
}
if( isset($_GET['do']) && $_GET['do'] == 'completed' ){
OpalEstate()->session->set( 'submission', 'addnew' );
echo opalestate_load_template_path( 'submission/completed' );
return ;
}
// remove all dirty images before edit/create new a property
$this->cleanup();
wp_enqueue_script( 'opalestate-submission' );
wp_enqueue_style( 'opalesate-submission' );
wp_enqueue_style( 'opalesate-cmb2-front' );
$metabox = $this->register_metabox();
$metaboxes = apply_filters( 'cmb2_meta_boxes', [] );
if ( ! isset( $metaboxes[ OPALESTATE_PROPERTY_PREFIX . 'front' ] ) ) {
return esc_html__( 'A metabox with the specified \'metabox_id\' doesn\'t exist.', 'opalestate-pro' );
}
$post_id = 0;
if( is_user_logged_in() ) {
// CMB2 is getting fields values from current post what means it will fetch data from submission page
// We need to remove all data before.
$post_id = ! empty( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
if ( ! $post_id ) {
unset( $_POST );
foreach ( $metaboxes[ OPALESTATE_PROPERTY_PREFIX . 'front' ]['fields'] as $field_name => $field_value ) {
delete_post_meta( get_the_ID(), $field_value['id'] );
}
}
if ( ! empty( $post_id ) && ! empty( $_POST['object_id'] ) ) {
$post_id = absint( $_POST['object_id'] );
}
if ( $post_id && ! opalestate_is_own_property( $post_id, $current_user->ID ) ) {
echo opalestate_load_template_path( 'parts/has-warning' );
return ;
}
}
return opalestate_load_template_path( 'submission/submission-form',
[
'post_id' => $post_id,
'metaboxes' => $metaboxes,
'navigation' => $metabox->get_fields_groups(),
] );
}
/**
*
*
*/
public function cmb2_get_metabox() {
$object_id = 'fake-oject-id';
return cmb2_get_metabox( OPALESTATE_PROPERTY_PREFIX . 'front', $object_id );
}
/**
* FrontEnd Submission
*/
public function process_submission() {
if ( isset( $_POST['submission_action'] ) && ! empty( $_POST['submission_action'] ) ) {
if ( wp_verify_nonce( $_POST['submission_action'], 'submitted-property' ) ) {
$user_id = get_current_user_id();
$edit = false;
$prefix = OPALESTATE_PROPERTY_PREFIX;
$blocked = OpalEstate_User::is_blocked();
// Setup and sanitize data
if ( isset( $_POST[ $prefix . 'title' ] ) && ! $blocked && $user_id ) {
$metabox = $this->register_metabox();
$metaboxes = apply_filters( 'cmb2_meta_boxes', [] );
$post_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : false;
if( $post_id ){
do_action( 'opalestate_process_edit_submission_before' );
} else {
do_action( 'opalestate_process_submission_before' );
}
$review_before = opalestate_get_option( 'admin_approve' );
$post_status = 'pending';
if ( ! $review_before ) {
$post_status = 'publish';
}
// If we are updating the post get old one. We need old post to set proper
// post_date value because just modified post will at the top in archive pages.
if ( ! empty( $post_id ) ) {
$old_post = get_post( $post_id );
$post_date = $old_post->post_date;
} else {
$post_date = '';
}
$post_content = isset( $_POST[ $prefix . 'text' ] ) ? wp_kses( $_POST[ $prefix . 'text' ],
'<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ) : '';
$data = [
'post_title' => sanitize_text_field( $_POST[ $prefix . 'title' ] ),
'post_author' => $user_id,
'post_status' => $post_status,
'post_type' => 'opalestate_property',
'post_date' => $post_date,
'post_content' => $post_content,
];
$unset_fields = [
'text',
'title',
'post_type',
];
unset( $_POST['post_type'] );
foreach ( $unset_fields as $field ) {
unset( $_POST[ $prefix . $field ] );
}
if ( ! empty( $post_id ) ) {
$edit = true;
$data['ID'] = $post_id;
do_action( 'opalestate_process_edit_submission_before' );
} else {
do_action( 'opalestate_process_add_submission_before' );
}
if ( empty( $data['post_title'] ) || empty( $data['post_author'] ) ) {
return opalestate_output_msg_json( false,
__( 'Please enter data for all require fields before submitting', 'opalestate-pro' ),
array(
'heading' => esc_html__('Submission Information' ,'opalestate-pro')
)) ;
}
$post_id = wp_insert_post( $data, true );
if ( ! empty( $post_id ) && ! empty( $_POST['object_id'] ) ) {
$_POST['object_id'] = (int) $post_id;
$metaboxes = apply_filters( 'cmb2_meta_boxes', [] );
/*
* Processing upload files
*/
$this->process_upload_files( $post_id, $_POST );
/**
* Fetch sanitized values
*/
cmb2_get_metabox_form( $metaboxes[ $prefix. 'front' ], $post_id );
$cmb = $this->cmb2_get_metabox();
$sanitized_values = $cmb->get_sanitized_values( $_POST );
$cmb->save_fields( $post_id, 'post', $sanitized_values );
// Create featured image
$featured_image = get_post_meta( $post_id, $prefix . 'featured_image', true );
if ( ! empty( $_POST[ $prefix . 'featured_image' ] ) && isset( $_POST[ $prefix . 'featured_image' ] ) ) {
foreach( $_POST[ $prefix . 'featured_image' ] as $key => $value ) {
set_post_thumbnail( $post_id, $key );
}
unset( $_POST[ $prefix . 'featured_image' ] );
} else {
delete_post_thumbnail( $post_id );
}
// remove meta field;
update_post_meta( $post_id, $prefix . 'featured_image', null );
//redirect
$_SESSION['messages'][] = [ 'success', esc_html__( 'Property has been successfully updated.', 'opalestate-pro' ) ];
do_action( "opalestate_process_submission_after", $user_id, $post_id, $edit );
if ( $edit ) {
$type = OpalEstate()->session->set( 'submission' , 'edit' );
$message = esc_html__('The property has updated completed with new information', 'opalestate-pro' );
do_action( "opalestate_processed_edit_submission", $user_id, $post_id );
} else {
$type = OpalEstate()->session->get( 'submission' , 'addnew' );
$message = esc_html__('You have submitted the property successful', 'opalestate-pro' );
do_action( "opalestate_processed_new_submission", $user_id, $post_id );
}
// set ready of attachment for use.
if( $this->new_attachmenet_ids ){
foreach ( $this->new_attachmenet_ids as $_id ) {
delete_post_meta( $_id, '_pending_to_use_', 1 );
}
}
//
return opalestate_output_msg_json( true,
$message,
array(
'heading' => esc_html__('Submission Information' ,'opalestate-pro'),
'redirect' => opalestate_submssion_page( $post_id, array('do' => 'completed') )
)) ;
}
} else {
return opalestate_output_msg_json( fales,
__('Currently, your account was blocked, please keep contact admin to resolve this!.', 'opalestate-pro' ),
array('heading' => esc_html__('Submission Information' ,'opalestate-pro') )
) ;
}
}
return opalestate_output_msg_json( fales,
__('Sorry! Your submitted datcould not save a at this time', 'opalestate-pro' ),
array('heading' => esc_html__('Submission Information', 'opalestate-pro') )
) ;
}
}
/**
*
*
*/
private function get_field_name( $field ){
return OPALESTATE_PROPERTY_PREFIX.$field;
}
/**
*
*
*/
private function process_upload_files ( $post_id ) {
//upload images for featured and gallery images
if( isset($_FILES) && !empty($_FILES) ){
///
$fields = array(
$this->get_field_name('gallery'),
$this->get_field_name('featured_image'),
);
foreach( $_FILES as $key => $value ) {
// allow processing in fixed collection
if( in_array($key, $fields) ){
$ufile = $_FILES[$key];
/// /////
if( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ){
$output = array();
foreach ( $ufile['name'] as $f_key => $f_value ) {
$loop_file = array(
'name' => $ufile['name'][$f_key],
'type' => $ufile['type'][$f_key],
'tmp_name' => $ufile['tmp_name'][$f_key],
'error' => $ufile['error'][$f_key],
'size' => $ufile['size'][$f_key]
);
$new_atm = $this->upload_image( $loop_file, $post_id );
if( $new_atm ){
$_POST[$key] = isset($_POST[$key]) ? $_POST[$key] : array();
$_POST[$key][$new_atm['attachment_id']] = $new_atm['url'];
$this->new_attachmenet_ids[$new_atm['attachment_id']] = $new_atm['attachment_id'];
}
}
}
///
elseif( isset($ufile['name']) ) {
$new_atm = $this->upload_image( $ufile, $post_id );
if( $new_atm ){
$_POST[$key][$new_atm['attachment_id']] = $new_atm['url'];
$this->new_attachmenet_ids[$new_atm['attachment_id']] = $new_atm['attachment_id'];
}
}
//// / //
}
}
// for group files
$fields = array(
$this->get_field_name('public_floor_group')
);
foreach( $_FILES as $key => $value ) {
if( in_array($key, $fields) ){
$ufile = $_FILES[$key];
if( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ){
$output = array();
foreach ( $ufile['name'] as $f_key => $f_value ) {
foreach( $f_value as $u_key => $u_v ) {
$loop_file = array(
'name' => $ufile['name'][$f_key][$u_key],
'type' => $ufile['type'][$f_key][$u_key],
'tmp_name' => $ufile['tmp_name'][$f_key][$u_key],
'error' => $ufile['error'][$f_key][$u_key],
'size' => $ufile['size'][$f_key][$u_key]
);
$new_atm = $this->upload_image( $loop_file, $post_id );
if( $new_atm ){
$_POST[$key][$f_key][$u_key] = $new_atm['attachment_id'];
$this->new_attachmenet_ids[$new_atm['attachment_id']] = $new_atm['attachment_id'];
}
}
}
}
}
}
}
}
/**
* Process upload images for properties
*/
public function upload_image( $submitted_file, $parent_id=0 ){
return opalesate_upload_image( $submitted_file, $parent_id );
}
/**
* FrontEnd Submission
*/
private function cleanup() {
$user_id = get_current_user_id();
opalestate_clean_attachments( $user_id );
}
/**
* FrontEnd Submission
*/
public function submission_list() {
if ( ! is_user_logged_in() ) {
echo opalestate_load_template_path( 'parts/not-allowed' );
return;
}
if ( isset( $_GET['id'] ) && isset( $_GET['remove'] ) ) {
$is_allowed = Opalestate_Property::is_allowed_remove( get_current_user_id(), intval( $_GET['id'] ) );
if ( ! $is_allowed ) {
echo opalestate_load_template_path( 'parts/not-allowed' );
return;
}
if ( wp_delete_post( intval( $_GET['id'] ) ) ) {
$_SESSION['messages'][] = [ 'success', esc_html__( 'Property has been successfully removed.', 'opalestate-pro' ) ];
} else {
$_SESSION['messages'][] = [ 'danger', esc_html__( 'An error occured when removing an item.', 'opalestate-pro' ) ];
}
wp_redirect( opalestate_submssion_list_page() );
}
$args = [];
if ( isset( $_GET['status'] ) && ! empty( $_GET['status'] ) ) {
$args['post_status'] = sanitize_text_field( $_GET['status'] );
}
$loop = Opalestate_Query::get_properties_by_user( $args, get_current_user_id() );
return opalestate_load_template_path( 'user/my-properties', [ 'loop' => $loop ] );
}
}
new OpalEstate_Submission();

3
inc/submission/function.php Executable file
View File

@@ -0,0 +1,3 @@
<?php
?>

View File

@@ -0,0 +1,93 @@
<?php
/**
* Opalestate_Taxonomy_Amenities
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Amenities {
/**
* Opalestate_Taxonomy_Amenities constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ], 999 );
}
/**
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Amenities', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Amenity', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Amenities', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Amenities', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Amenity', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Amenity:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Amenity', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Amenity', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Amenity', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Amenity', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Amenities', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_amenities', 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_amenities_labels', $labels ),
'hierarchical' => true,
'query_var' => 'amenity',
'rewrite' => [ 'slug' => _x( 'amenity', 'slug', 'opalestate-pro' ), 'with_front' => false, 'hierarchical' => true ],
'public' => true,
'show_ui' => true,
] );
}
public static function get_list() {
return get_terms( 'opalestate_amenities', [ 'hide_empty' => false ] );
}
public function taxonomy_metaboxes() {
$prefix = 'opalestate_amt_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_amenities' ], // Tells CMB2 which taxonomies should have these fields
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image Icon', 'opalestate-pro' ),
'desc' => esc_html__( 'Select an image icon (SVG, PNG or JPEG).', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
'preview_size' => [ 50, 50 ],
'options' => [
'url' => false, // Hide the text input for the url
],
'query_args' => [
'type' => [
'image/gif',
'image/jpeg',
'image/png',
],
],
] );
}
}
new Opalestate_Taxonomy_Amenities();

View File

@@ -0,0 +1,116 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Categories {
/**
*
*/
public static function init() {
add_action( 'init', [ __CLASS__, 'definition' ] );
add_filter( 'opalestate_taxomony_category_metaboxes', [ __CLASS__, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ __CLASS__, 'taxonomy_metaboxes' ], 999 );
}
public static function metaboxes() {
}
/**
*
*/
public static function definition() {
register_taxonomy( 'property_category', 'opalestate_property', apply_filters( 'opalestate_taxonomy_args_property_category', [
'labels' => [
'name' => esc_html__( 'Categories', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Category', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Category', 'opalestate-pro' ),
],
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => [ 'slug' => _x( 'property-category', 'slug', 'opalestate-pro' ), 'with_front' => false, 'hierarchical' => true ],
] ) );
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public static function taxonomy_metaboxes() {
$prefix = 'opalestate_category_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Category Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'property_category' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image', 'opalestate-pro' ),
'desc' => esc_html__( 'Category image', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
] );
}
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => 'property_category',
'hide_empty' => true,
];
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
public static function dropdown_list( $selected = 0 ) {
$id = "opalestate_category" . rand();
$args = [
'show_option_none' => esc_html__( 'Select category', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
'name' => 'label',
'value_field' => 'slug',
'selected' => $selected,
'taxonomy' => 'opalestate_category',
];
return wp_dropdown_categories( $args );
}
}
Opalestate_Taxonomy_Categories::init();

View File

@@ -0,0 +1,152 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_City {
/**
*
*/
public static function init() {
add_action( 'init', [ __CLASS__, 'definition' ] );
add_action( 'cmb2_admin_init', [ __CLASS__, 'taxonomy_metaboxes' ] );
}
/**
*
*/
public static function definition() {
$labels = [
'name' => esc_html__( 'Cities / Towns', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By City', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Cities / Towns', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Cities / Town', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent City', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent City:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit City', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update City', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New City', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New City', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Cities / Towns', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_city', 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_city_labels', $labels ),
'hierarchical' => true,
'query_var' => 'city',
'rewrite' => [ 'slug' => esc_html__( 'city', 'opalestate-pro' ) ],
'public' => true,
'show_ui' => true,
] );
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public static function taxonomy_metaboxes() {
$prefix = 'opalestate_city_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'City Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_city' ], // Tells CMB2 which taxonomies should have these fields
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image', 'opalestate-pro' ),
'desc' => esc_html__( 'City image', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
'preview_size' => 'small',
'options' => [
'url' => false, // Hide the text input for the url
],
] );
////
$cmb_term->add_field( [
'name' => esc_html__( 'Country', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in countries of estate panel', 'opalestate-pro' ),
'id' => $prefix . 'location',
'taxonomy' => 'opalestate_location', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
] );
///
$cmb_term->add_field( [
'name' => esc_html__( 'State / Province', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in City/Town of estate panel', 'opalestate-pro' ),
'id' => $prefix . 'state',
'taxonomy' => 'opalestate_state', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
] );
}
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => 'opalestate_city',
'hide_empty' => true,
];
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
/**
* Render dopdown list.
*
* @param int $selected
* @return string
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_city' . rand();
$args = [
'show_option_none' => esc_html__( 'Select City', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'name' => 'city',
'show_count' => 0,
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_city',
'orderby' => 'name',
'order' => 'ASC',
'echo' => 0,
];
$label = '<label class="opalestate-label opalestate-label--city" for="' . esc_attr( $id ) . '">' . esc_html__( 'City', 'opalestate-pro' ) . '</label>';
echo $label . wp_dropdown_categories( $args );
}
}
Opalestate_Taxonomy_City::init();

View File

@@ -0,0 +1,150 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Label {
/**
*
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_filter( 'opalestate_taxomony_label_metaboxes', [ $this, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ], 999 );
}
/**
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Label', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Label', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Label', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Label', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Label', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Label:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Label', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Label', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Label', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Label', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Label', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_label', 'opalestate_property', [
'labels' => apply_filters( 'opalestate_label_labels', $labels ),
'hierarchical' => true,
'query_var' => 'property-label',
'rewrite' => [ 'slug' => esc_html__( 'property-label', 'opalestate-pro' ) ],
'public' => true,
'show_ui' => true,
] );
}
public function metaboxes() {
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_label_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Category Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_label' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Background', 'opalestate-pro' ),
'desc' => esc_html__( 'Set background of label', 'opalestate-pro' ),
'id' => $prefix . 'lb_bg',
'type' => 'colorpicker',
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Color', 'opalestate-pro' ),
'desc' => esc_html__( 'Set color of text', 'opalestate-pro' ),
'id' => $prefix . 'lb_color',
'type' => 'colorpicker',
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image Logo', 'opalestate-pro' ),
'desc' => esc_html__( 'Or Using Image Logo without using text', 'opalestate-pro' ),
'id' => $prefix . 'lb_img',
'type' => 'file',
'preview_size' => 'small',
'options' => [
'url' => false, // Hide the text input for the url
],
] );
}
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = [
'taxonomy' => 'opalestate_label',
'hide_empty' => false,
];
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
/**
* Render dopdown list.
*
* @param int $selected
* @return string
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_label' . rand();
$args = [
'show_option_none' => esc_html__( 'Select Label', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
'name' => 'label',
'value_field' => 'slug',
'selected' => $selected,
'taxonomy' => 'opalestate_label',
];
return wp_dropdown_categories( $args );
}
}
new Opalestate_Taxonomy_Label();

View File

@@ -0,0 +1,152 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Location {
/**
*
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_filter( 'opalestate_taxomony_location_metaboxes', [ $this, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ] );
}
/**
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Countries', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Country', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Countries', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Countries', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Country', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Country:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Country', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Country', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Country', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Country', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Countries', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_location', 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_location_labels', $labels ),
'hierarchical' => true,
'query_var' => 'location',
'rewrite' => [ 'slug' => esc_html__( 'location', 'opalestate-pro' ) ],
'public' => true,
'show_ui' => true,
] );
}
/**
*
*/
public function metaboxes() {
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_location_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Country Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_location' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image', 'opalestate-pro' ),
'desc' => esc_html__( 'Country image', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
'preview_size' => 'small',
'options' => [
'url' => false, // Hide the text input for the url
],
] );
}
/**
*
*/
public static function get_list() {
return get_terms( 'opalestate_location', [ 'hide_empty' => false ] );
}
/**
*
*/
public static function dropdown_agents_list( $selected = 0 ) {
$id = "opalestate_location" . rand();
$args = [
'show_option_none' => esc_html__( 'Select Country', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'name' => 'location',
'show_count' => 0,
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_agent_location',
];
return wp_dropdown_categories( $args );
}
/**
*
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'opalestate_location' . rand();
$args = [
'show_option_none' => esc_html__( 'Select Country', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'name' => 'location',
'show_count' => 0,
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_location',
'orderby' => 'name',
'order' => 'ASC',
'echo' => 0,
];
$label = '<label class="opalestate-label opalestate-label--country" for="' . esc_attr( $id ) . '">' . esc_html__( 'Country', 'opalestate-pro' ) . '</label>';
echo $label . wp_dropdown_categories( $args );
}
public static function get_multi_check_list() {
}
}
new Opalestate_Taxonomy_Location();

View File

@@ -0,0 +1,114 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Neighborhood{
/**
*
*/
public static function init(){
add_action( 'init', array( $this, 'definition' ), 99 );
add_action( 'cmb2_admin_init', array( $this, 'taxonomy_metaboxes' ), 9 );
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_nb_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( array(
'id' => $prefix . 'edit',
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => array( 'opalestate_neighborhoods' ), // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
) );
$cmb_term->add_field( array(
'name' => esc_html__( 'Icon', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in google map', 'opalestate-pro' ),
'id' => $prefix . 'icon',
'type' => 'file',
'preview_size' => 'small',
'options' => array(
'url' => false, // Hide the text input for the url
)
) );
}
/**
*
*/
public function definition(){
$labels = array(
'name' => esc_html__( 'Neighborhoods', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Neighborhood', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Neighborhoods', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Neighborhoods', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Neighborhood', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Neighborhood:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Neighborhood', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Neighborhood', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Neighborhood', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Neighborhood', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Neighborhoods', 'opalestate-pro' ),
);
register_taxonomy( 'opalestate_neighborhoods', array( 'opalestate_property' ) , array(
'labels' => apply_filters( 'opalestate_taxomony_neighborhoods_labels', $labels ),
'hierarchical' => true,
'query_var' => 'property-neighborhood',
'rewrite' => array( 'slug' => esc_html__( 'property-neighborhood', 'opalestate-pro' ) ),
'public' => true,
'show_ui' => true,
) );
}
public static function metaboxes(){
}
public static function dropdown_list( $selected=0 ){
$id = "opalestate_neighborhoods".rand();
$args = array(
'show_option_none' => esc_html__( 'Select Neighborhoods', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
'name' => 'neighborhoods',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_neighborhoods'
);
return wp_dropdown_categories( $args );
}
}
new Opalestate_Taxonomy_Neighborhood();

View File

@@ -0,0 +1,145 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_State {
/**
* Opalestate_Taxonomy_State constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_filter( 'opalestate_taxomony_state_metaboxes', [ $this, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ] );
}
/**
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'States / Provinces', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By State', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search States', 'opalestate-pro' ),
'all_items' => esc_html__( 'All States / Province', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent State', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent State:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit State', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update State', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New State', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New State', 'opalestate-pro' ),
'menu_name' => esc_html__( 'States / Provinces', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_state', 'opalestate_property', [
'labels' => apply_filters( 'opalestate_taxomony_state_labels', $labels ),
'hierarchical' => true,
'query_var' => 'state',
'rewrite' => [ 'slug' => esc_html__( 'state', 'opalestate-pro' ) ],
'public' => true,
'show_ui' => true,
] );
}
public function metaboxes() {
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_state_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'State Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_state' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image', 'opalestate-pro' ),
'desc' => esc_html__( 'State image', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
'preview_size' => 'small',
'options' => [
'url' => false, // Hide the text input for the url
],
] );
////
$cmb_term->add_field( [
'name' => esc_html__( 'Country', 'opalestate-pro' ),
'desc' => esc_html__( 'Select one, to add new you create in countries of estate panel', 'opalestate-pro' ),
'id' => $prefix . "location",
'taxonomy' => 'opalestate_location', //Enter Taxonomy Slug
'type' => 'taxonomy_select',
] );
///
}
public static function get_list() {
return get_terms( 'opalestate_state', [ 'hide_empty' => false ] );
}
public static function dropdown_agents_list( $selected = 0 ) {
$id = "opalestate_state" . rand();
$args = [
'show_option_none' => esc_html__( 'Select State', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'name' => 'state',
'show_count' => 0,
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_agent_state',
];
return wp_dropdown_categories( $args );
}
public static function dropdown_list( $selected = 0 ) {
$id = "opalestate_state" . rand();
$args = [
'show_option_none' => esc_html__( 'Select State', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'name' => 'state',
'show_count' => 0,
'hierarchical' => '',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_state',
'orderby' => 'name',
'order' => 'ASC',
'echo' => 0,
];
$label = '<label class="opalestate-label opalestate-label--state" for="' . esc_attr( $id ) . '">' . esc_html__( 'State', 'opalestate-pro' ) . '</label>';
echo $label . wp_dropdown_categories( $args );
}
}
new Opalestate_Taxonomy_State();

View File

@@ -0,0 +1,159 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Status {
/**
* Opalestate_Taxonomy_Status constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_filter( 'opalestate_taxomony_status_metaboxes', [ $this, 'metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ] );
}
/**
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Status', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Status', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Status', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Status', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Status', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Status:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Status', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Status', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Status', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Status', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Status', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_status', 'opalestate_property', [
'labels' => apply_filters( 'opalestate_status_labels', $labels ),
'hierarchical' => true,
'query_var' => 'status',
'rewrite' => [ 'slug' => esc_html__( 'status', 'opalestate-pro' ) ],
'public' => true,
'show_ui' => true,
] );
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_status_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Category Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_status' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Background', 'opalestate-pro' ),
'desc' => esc_html__( 'Set background of label', 'opalestate-pro' ),
'id' => $prefix . 'lb_bg',
'type' => 'colorpicker',
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Color', 'opalestate-pro' ),
'desc' => esc_html__( 'Set background of text', 'opalestate-pro' ),
'id' => $prefix . 'lb_color',
'type' => 'colorpicker',
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Order', 'opalestate-pro' ),
'desc' => esc_html__( 'Set a priority to display', 'opalestate-pro' ),
'id' => $prefix . 'order',
'type' => 'text_small',
'attributes' => [
'type' => 'number',
],
'default' => 0,
] );
}
public function metaboxes() {
}
/**
* Gets list.
*
* @param array $args
* @return array|int|\WP_Error
*/
public static function get_list( $args = [] ) {
$default = apply_filters( 'opalestate_status_args', [
'taxonomy' => 'opalestate_status',
'hide_empty' => false,
'hierarchical' => false,
'parent' => 0,
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_query' => [
[
'key' => 'opalestate_status_order',
'type' => 'NUMERIC',
],
],
] );
if ( $args ) {
$default = array_merge( $default, $args );
}
return get_terms( $default );
}
/**
* Render dopdown list.
*
* @param int $selected
* @return string
*/
public static function dropdown_list( $selected = 0 ) {
$id = 'palestate_status' . rand();
$args = [
'show_option_none' => esc_html__( 'Select Status', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
'name' => 'status',
'value_field' => 'slug',
'selected' => $selected,
'taxonomy' => 'opalestate_status',
'echo' => 0,
];
$label = '<label class="opalestate-label opalestate-label--status" for="' . esc_attr( $id ) . '">' . esc_html__( 'Status', 'opalestate-pro' ) . '</label>';
echo $label . wp_dropdown_categories( $args );
}
}
new Opalestate_Taxonomy_Status();

View File

@@ -0,0 +1,136 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Taxonomy_Type {
/**
*
*/
public function __construct() {
add_action( 'init', [ $this, 'definition' ] );
add_action( 'cmb2_admin_init', [ $this, 'taxonomy_metaboxes' ] );
}
/**
* Hook in and add a metabox to add fields to taxonomy terms
*/
public function taxonomy_metaboxes() {
$prefix = 'opalestate_type_';
/**
* Metabox to add fields to categories and tags
*/
$cmb_term = new_cmb2_box( [
'id' => $prefix . 'edit',
'title' => esc_html__( 'Type Metabox', 'opalestate-pro' ), // Doesn't output for term boxes
'object_types' => [ 'term' ], // Tells CMB2 to use term_meta vs post_meta
'taxonomies' => [ 'opalestate_types' ], // Tells CMB2 which taxonomies should have these fields
// 'new_term_section' => true, // Will display in the "Add New Category" section
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Custom Icon Marker', 'opalestate-pro' ),
'desc' => esc_html__( 'This image will display in google map', 'opalestate-pro' ),
'id' => $prefix . 'iconmarker',
'type' => 'file',
'preview_size' => 'small',
'options' => [
'url' => false, // Hide the text input for the url
],
] );
$cmb_term->add_field( [
'name' => esc_html__( 'Image', 'opalestate-pro' ),
'desc' => esc_html__( 'Type image', 'opalestate-pro' ),
'id' => $prefix . 'image',
'type' => 'file',
'preview_size' => 'small',
'options' => [
'url' => false, // Hide the text input for the url
],
] );
}
/**
*
*/
public function definition() {
$labels = [
'name' => esc_html__( 'Types', 'opalestate-pro' ),
'singular_name' => esc_html__( 'Properties By Type', 'opalestate-pro' ),
'search_items' => esc_html__( 'Search Types', 'opalestate-pro' ),
'all_items' => esc_html__( 'All Types', 'opalestate-pro' ),
'parent_item' => esc_html__( 'Parent Type', 'opalestate-pro' ),
'parent_item_colon' => esc_html__( 'Parent Type:', 'opalestate-pro' ),
'edit_item' => esc_html__( 'Edit Type', 'opalestate-pro' ),
'update_item' => esc_html__( 'Update Type', 'opalestate-pro' ),
'add_new_item' => esc_html__( 'Add New Type', 'opalestate-pro' ),
'new_item_name' => esc_html__( 'New Type', 'opalestate-pro' ),
'menu_name' => esc_html__( 'Types', 'opalestate-pro' ),
];
register_taxonomy( 'opalestate_types', [ 'opalestate_property' ], [
'labels' => apply_filters( 'opalestate_taxomony_types_labels', $labels ),
'hierarchical' => true,
'query_var' => 'type',
'rewrite' => [ 'slug' => esc_html__( 'type', 'opalestate-pro' ) ],
'public' => true,
'show_ui' => true,
] );
}
public function metaboxes() {
}
public static function get_list() {
return get_terms( 'opalestate_types', [ 'hide_empty' => false ] );
}
public static function dropdown_list( $selected = 0 ) {
$id = "opalestate_types" . rand();
$args = [
'show_option_none' => esc_html__( 'Select Type', 'opalestate-pro' ),
'id' => $id,
'class' => 'form-control',
'show_count' => 0,
'hierarchical' => '',
'name' => 'types',
'selected' => $selected,
'value_field' => 'slug',
'taxonomy' => 'opalestate_types',
'echo' => 0,
];
$label = '<label class="opalestate-label opalestate-label--type" for="' . esc_attr( $id ) . '">' . esc_html__( 'Type', 'opalestate-pro' ) . '</label>';
echo $label . wp_dropdown_categories( $args );
}
public static function get_multi_check_list( $stypes ) {
$list = self::get_list();
echo opalestate_terms_multi_check( $list, $stypes );
}
}
new Opalestate_Taxonomy_Type();

1050
inc/template-functions.php Executable file

File diff suppressed because it is too large Load Diff

310
inc/template-hook-functions.php Executable file
View File

@@ -0,0 +1,310 @@
<?php
/**
* Archive Page
*/
add_action( "opalestate_archive_property_page_before", "opalestate_archive_search_block", 4 );
/**
* Layout Single Default
*/
function opalestate_single_property_layout_default() {
add_action( 'opalestate_single_property_summary', 'opalestate_get_single_short_meta', 10 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_content', 12 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_information', 15 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_amenities', 16 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_facilities', 17 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_attachments', 18 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_video', 20 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_virtual_tour', 25 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_map', 30 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_nearby', 35 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_walkscore', 40 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_apartments', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_floor_plans', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_views_statistics', 50 );
// add_action( 'opalestate_after_single_property_summary', '', 55 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_tags', 60 );
add_action( 'opalestate_after_single_property_summary', 'comments_template', 65 );
add_action( 'opalestate_after_single_property_summary_v2', 'opalestate_property_map_v2', 5 );
////// sidebar ////////
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_author_v2', 5 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_equiry_form', 6 );
// add_action( 'opalestate_single_property_sidebar', 'opalestate_property_request_viewing_button', 7 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_mortgage', 9 );
add_filter( 'opalestate_thumbnail_nav_column', function () {
return 6;
} );
}
/**
* Layout Single Default
*/
function opalestate_single_property_layout_v2() {
add_action( 'opalestate_single_property_summary', 'opalestate_get_single_short_meta', 10 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_content', 12 );
//add_action( 'opalestate_single_property_summary', 'opalestate_property_information', 15 );
//add_action( 'opalestate_single_property_summary', 'opalestate_property_amenities', 16 );
//add_action( 'opalestate_single_property_summary', 'opalestate_property_facilities', 17 );
//add_action( 'opalestate_single_property_summary', 'opalestate_property_attachments', 18 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_video', 20 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_virtual_tour', 25 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_map', 30 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_nearby', 35 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_walkscore', 40 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_apartments', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_views_statistics', 50 );
// add_action( 'opalestate_after_single_property_summary', 'opalestate_property_author', 55 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_tags', 60 );
add_action( 'opalestate_after_single_property_summary', 'comments_template', 65 );
add_action( 'opalestate_after_single_property_summary_v2', 'opalestate_property_map_v2', 5 );
/// /// sidebar ////////
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_mortgage', 9 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_author_v3', 10 );
// add_action( 'opalestate_single_property_sidebar', 'opalestate_property_equiry_form' , 12 );
}
/**
* Layout Single Version 3
*/
function opalestate_single_property_layout_v3() {
add_action( 'opalestate_single_property_summary', 'opalestate_get_single_short_meta', 10 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_content', 12 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_information', 15 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_amenities', 16 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_facilities', 17 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_attachments', 18 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_video', 20 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_virtual_tour', 25 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_map', 30 );
// add_action( 'opalestate_after_single_property_summary', 'opalestate_property_nearby', 35 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_walkscore', 40 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_apartments', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_views_statistics', 50 );
// add_action( 'opalestate_after_single_property_summary', 'opalestate_property_author', 55 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_tags', 60 );
add_action( 'opalestate_after_single_property_summary', 'comments_template', 65 );
add_action( 'opalestate_after_single_property_summary_v2', 'opalestate_property_map_v2', 5 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_author_v2', 5 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_equiry_form', 6 );
///
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_mortgage' );
}
/**
* Layout Single Version 4
*/
function opalestate_single_property_layout_v4() {
add_action( 'opalestate_single_property_summary', 'opalestate_get_single_short_meta', 10 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_content', 12 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_information', 15 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_amenities', 16 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_facilities', 17 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_attachments', 18 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_video', 20 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_virtual_tour', 25 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_map', 30 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_nearby', 35 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_walkscore', 40 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_apartments', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_views_statistics', 50 );
// add_action( 'opalestate_after_single_property_summary', 'opalestate_property_author', 55 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_tags', 60 );
add_action( 'opalestate_after_single_property_summary', 'comments_template', 65 );
add_action( 'opalestate_after_single_property_summary_v2', 'opalestate_property_map_v2', 5 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_author_v2', 5 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_equiry_form', 6 );
///
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_mortgage', 9 );
}
/**
* Layout Single Version 5
*/
function opalestate_single_property_layout_v5() {
add_action( 'opalestate_single_property_summary', 'opalestate_get_single_short_meta', 10 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_content', 12 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_information', 15 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_amenities', 16 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_facilities', 17 );
add_action( 'opalestate_single_property_summary', 'opalestate_property_attachments', 18 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_video', 20 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_virtual_tour', 25 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_map', 30 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_nearby', 35 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_walkscore', 40 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_apartments', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_floor_plans', 45 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_views_statistics', 50 );
// add_action( 'opalestate_after_single_property_summary', 'opalestate_property_author', 55 );
add_action( 'opalestate_after_single_property_summary', 'opalestate_property_tags', 60 );
add_action( 'opalestate_after_single_property_summary', 'comments_template', 65 );
add_action( 'opalestate_after_single_property_summary_v2', 'opalestate_property_map_v2', 5 );
add_filter( 'opalestate_thumbnail_nav_column', function () {
return 10;
} );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_author_v2', 5 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_equiry_form', 6 );
// add_action( 'opalestate_single_property_sidebar', 'opalestate_property_request_viewing_button', 7 );
add_action( 'opalestate_single_property_sidebar', 'opalestate_property_mortgage', 9 );
}
///
add_action( 'opalestate_single_property_after_render', 'opalestate_properties_related', 5 );
add_action( 'opalestate_single_property_after_render', 'opalestate_properties_nearby', 6 );
add_action( 'opalestate_single_property_preview', 'opalestate_property_preview', 15 );
function opalestate_property_request_viewing_button( $islink = false ) {
$class = $islink ? 'btn-link' : 'btn btn-primary';
echo '<a href="#opalestate-user-form-popup" class="' . $class . ' btn-request-viewing opalestate-popup-button" data-target="#property-request-view-popup" >
<i class="fa fa-calendar-check-o"></i>
<span class="btn-request-viewing__text">' . esc_html__( 'Request Viewing', 'opalestate-pro' ) . '</span>
</a>';
}
///
add_action( 'opalestate_single_property_layout', 'opalestate_single_property_layout' );
function opalestate_single_property_layout( $layout ) {
switch ( $layout ) {
case 'v2':
opalestate_single_property_layout_v2();
break;
case 'v3':
opalestate_single_property_layout_v3();
break;
case 'v4':
opalestate_single_property_layout_v4();
break;
case 'v5':
opalestate_single_property_layout_v5();
break;
default:
opalestate_single_property_layout_default();
break;
}
}
/**
* Forms
*/
function opalestate_property_request_view_form() {
if ( ! is_single_property() ) {
return;
}
$object = OpalEstate_User_Message::get_instance();
$fields = $object->get_request_review_form_fields();
$form = OpalEstate()->html->render_form( $fields );
$description = esc_html__( 'Physical Arrange viewings is always been attractive to property clients. Fill out the form to arrange visualizations around our properties.', 'opalestate-pro' );
$atts = [
'heading' => esc_html__( 'Request Viewing', 'opalestate-pro' ),
'description' => $description,
'id' => 'property-request-view',
'form' => $form,
];
echo opalestate_load_template_path( 'messages/request-reviewing-form', $atts );
}
add_action( 'wp_footer', 'opalestate_property_request_view_form', 9 );
function opalestate_property_equiry_form() {
echo opalestate_load_template_path( 'messages/enquiry-form' );
}
if ( ! function_exists( "opalestate_login_register_form_popup" ) ) {
function opalestate_login_register_form_popup() {
echo opalestate_load_template_path( 'user/my-account-popup' );
}
}
add_action( 'wp_footer', 'opalestate_login_register_form_popup', 9 );
/**
* Add "Custom" template to page attirbute template section.
*/
function opalestate_add_template_to_select( $post_templates, $wp_theme, $post, $post_type ) {
// Add custom template named template-custom.php to select dropdown
$post_templates['user-management.php'] = esc_html__( 'User Management', 'opalestate-pro' );
$post_templates['fullwidth-page.php'] = esc_html__( 'Opalestate Fullwidth', 'opalestate-pro' );
return $post_templates;
}
add_filter( 'theme_page_templates', 'opalestate_add_template_to_select', 10, 4 );
function opalestate_load_plugin_template( $template ) {
if ( get_page_template_slug() === 'user-management.php' ) {
if ( $theme_file = locate_template( [ 'page-templates/user-management.php', 'user-management.php' ] ) ) {
$template = $theme_file;
} else {
$template = OPALESTATE_PLUGIN_DIR . '/templates/user-management.php';
}
} elseif ( get_page_template_slug() === 'fullwidth-page.php' ) {
if ( $theme_file = locate_template( [ 'page-templates/fullwidth-page.php', 'fullwidth-page.php' ] ) ) {
$template = $theme_file;
} else {
$template = OPALESTATE_PLUGIN_DIR . '/templates/fullwidth-page.php';
}
}
if ( $template == '' ) {
throw new \Exception( 'No template found' );
}
return $template;
}
add_filter( 'template_include', 'opalestate_load_plugin_template' );
add_action( 'opalestate_before_property_loop_item', 'opalestate_property_featured_label' );
add_action( 'opalestate_before_property_loop_item', 'opalestate_property_label' );

View File

@@ -0,0 +1,327 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit();
}
/**
* Login processer
*/
class Opalestate_User_Form_Handler {
/**
* Login processer
*/
public function __construct() {
add_action( 'init', [ $this, 'process_login' ] );
add_action( 'init', [ $this, 'process_register' ] );
add_action( 'wp_ajax_opalestate_login_form', [ $this, 'process_login' ] );
add_action( 'wp_ajax_opalestate_register_form', [ $this, 'process_register' ] );
}
/**
* Login processer
*/
public static function process_login() {
$nonce_value = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
$nonce_value = isset( $_POST['opalestate-login-nonce'] ) ? sanitize_text_field( $_POST['opalestate-login-nonce'] ) : $nonce_value;
/* verify wp nonce */
if ( ! wp_verify_nonce( $nonce_value, 'opalestate-login' ) ) {
return;
}
try {
do_action( 'opalestate_user_proccessing_login_before' );
$credentials = [];
$username = isset( $_POST['username'] ) ? sanitize_user( $_POST['username'] ) : '';
$password = isset( $_POST['password'] ) ? sanitize_text_field( $_POST['password'] ) : '';
/* sanitize, allow hook process like block somebody =)))) */
$validation = apply_filters( 'opalestate_validation_process_login_error', new WP_Error(), $username, $password );
if ( $validation->get_error_code() ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . $validation->get_error_message() );
}
/* validate username */
if ( ! $username ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Username is required.', 'opalestate-pro' ) );
} else {
if ( is_email( $username ) ) {
/* user object */
$user = get_user_by( 'email', $username );
if ( $user->user_login ) {
$credentials['user_login'] = $user->user_login;
} else {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'A user could not be found with this email address.',
'opalestate-pro' ) );
}
} else {
$credentials['user_login'] = $username;
}
}
/* validate password if it empty */
if ( ! $password ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Password is required.', 'opalestate-pro' ) );
}
$credentials['user_password'] = $password;
/* is rembemer me checkbox */
$credentials['remember'] = isset( $_POST['remember'] );
/* signon user */
$user = wp_signon( $credentials, is_ssl() );
if ( is_wp_error( $user ) ) {
throw new Exception( $user->get_error_message() );
} else {
/* after signon successfully */
do_action( 'opalestate_after_signon_successfully', $user );
$redirect = opalestate_get_dashdoard_page_uri();
if ( ! empty( $_POST['redirect'] ) ) {
$redirect = sanitize_text_field( $_POST['redirect'] );
} elseif ( wp_get_referer() ) {
$redirect = wp_get_referer();
}
$redirect = apply_filters( 'opalestate_signon_redirect_url', $redirect );
if ( opalestate_is_ajax_request() ) {
opalestate_add_notice( 'success', esc_html__( 'Logged successfully, welcome back!', 'opalestate-pro' ) );
ob_start();
opalestate_print_notices();
$message = ob_get_clean();
wp_send_json( [
'status' => true,
'message' => $message,
'redirect' => $redirect,
] );
} else {
wp_safe_redirect( $redirect );
exit();
}
}
do_action( 'opalestate_user_proccessing_login_after' );
} catch ( Exception $e ) {
opalestate_add_notice( 'error', $e->getMessage() );
}
if ( opalestate_is_ajax_request() ) {
ob_start();
opalestate_print_notices();
$message = ob_get_clean();
wp_send_json( [
'status' => false,
'message' => $message,
] );
}
}
/**
* Register processer
*/
public function process_register() {
if ( ! isset( $_POST['opalestate-register-nonce'] ) ) {
return;
}
$nonce_value = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
$nonce_value = isset( $_POST['opalestate-register-nonce'] ) ? sanitize_text_field( $_POST['opalestate-register-nonce'] ) : $nonce_value;
/* verify wp nonce */
if ( ! isset( $_POST['confirmed_register'] ) || ! wp_verify_nonce( $nonce_value, 'opalestate-register' ) ) {
return;
}
try {
do_action( 'opalestate_user_proccessing_register_before' );
$credentials = [];
$username = isset( $_POST['username'] ) ? sanitize_user( $_POST['username'] ) : '';
$email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : '';
$password = isset( $_POST['password'] ) ? sanitize_text_field( $_POST['password'] ) : '';
$password1 = isset( $_POST['password1'] ) ? sanitize_text_field( $_POST['password1'] ) : '';
/* sanitize, allow hook process like block somebody =)))) */
$validation = apply_filters( 'opalestate_validation_process_register_error', new WP_Error(), $username, $email );
/* sanitize */
if ( $validation->get_error_code() ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . $validation->get_error_message() );
}
/* validate username */
if ( ! $username ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Username is required.', 'opalestate-pro' ) );
} else {
$credentials['user_login'] = $username;
}
/* validate email */
if ( ! $email ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Email is required.', 'opalestate-pro' ) );
} else {
$credentials['user_email'] = $email;
}
/* validate password */
if ( ! $password ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Password is required.', 'opalestate-pro' ) );
}
if ( $password !== $password1 ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Re-Password is not match.', 'opalestate-pro' ) );
}
$credentials['user_pass'] = $password;
/* create new user */
$user_id = opalestate_create_user( $credentials );
if ( is_wp_error( $user_id ) ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . $user_id->get_error_message() );
} else {
/* after register successfully */
do_action( 'opalestate_after_register_successfully', $user_id );
$redirect = home_url();
if ( opalestate_get_option( 'login_user' ) ) {
wp_set_auth_cookie( $user_id );
$redirect = opalestate_get_dashdoard_page_uri();
} elseif ( ! empty( $_POST['redirect'] ) ) {
$redirect = sanitize_text_field( $_POST['redirect'] );
} elseif ( wp_get_referer() ) {
$redirect = wp_get_referer();
}
do_action( 'opalestate_user_proccessing_register_after' );
$redirect = apply_filters( 'opalestate_register_redirect_url', $redirect );
/* is ajax request */
if ( opalestate_is_ajax_request() ) {
wp_send_json( [ 'status' => true, 'redirect' => $redirect ] );
} else {
wp_safe_redirect( $redirect );
exit();
}
}
} catch ( Exception $e ) {
opalestate_add_notice( 'error', $e->getMessage() );
}
/* is ajax request */
if ( opalestate_is_ajax_request() ) {
ob_start();
opalestate_print_notices();
$message = ob_get_clean();
wp_send_json( [
'status' => false,
'message' => $message,
] );
}
}
/**
* process user doForgotPassword with username/password
*
* return Json Data with messsage and login status
*/
public function process_forgot_password() {
// First check the nonce, if it fails the function will break
check_ajax_referer( 'ajax-pbr-lostpassword-nonce', 'security' );
global $wpdb;
$account = sanitize_text_field( $_POST['user_login'] );
if ( empty( $account ) ) {
$error = esc_html__( 'Enter an username or e-mail address.', 'opalestate-pro' );
} else {
if ( is_email( $account ) ) {
if ( email_exists( $account ) ) {
$get_by = 'email';
} else {
$error = esc_html__( 'There is no user registered with that email address.', 'opalestate-pro' );
}
} elseif ( validate_username( $account ) ) {
if ( username_exists( $account ) ) {
$get_by = 'login';
} else {
$error = esc_html__( 'There is no user registered with that username.', 'opalestate-pro' );
}
} else {
$error = esc_html__( 'Invalid username or e-mail address.', 'opalestate-pro' );
}
}
if ( empty ( $error ) ) {
$random_password = wp_generate_password();
$user = get_user_by( $get_by, $account );
$update_user = wp_update_user( [ 'ID' => $user->ID, 'user_pass' => $random_password ] );
if ( $update_user ) {
$from = get_option( 'admin_email' ); // Set whatever you want like mail@yourdomain.com
if ( ! ( isset( $from ) && is_email( $from ) ) ) {
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
$from = 'do-not-reply@' . $sitename;
}
$to = $user->user_email;
$subject = esc_html__( 'Your new password', 'opalestate-pro' );
$sender = 'From: ' . get_option( 'name' ) . ' <' . $from . '>' . "\r\n";
$message = esc_html__( 'Your new password is: ', 'opalestate-pro' ) . $random_password;
$headers[] = 'MIME-Version: 1.0' . "\r\n";
$headers[] = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers[] = "X-Mailer: PHP \r\n";
$headers[] = $sender;
$mail = wp_mail( $to, $subject, $message, $headers );
if ( $mail ) {
$success = esc_html__( 'Check your email address for you new password.', 'opalestate-pro' );
} else {
$error = esc_html__( 'System is unable to send you mail containg your new password.', 'opalestate-pro' );
}
} else {
$error = esc_html__( 'Oops! Something went wrong while updating your account.', 'opalestate-pro' );
}
}
if ( ! empty( $error ) ) {
echo wp_send_json( [ 'status' => false, 'message' => ( $error ) ] );
}
if ( ! empty( $success ) ) {
echo wp_send_json( [ 'status' => false, 'message' => $success ] );
}
die();
}
}
new Opalestate_User_Form_Handler();

View File

@@ -0,0 +1,222 @@
<?php
/**
* $Desc$
*
* @version $Id$
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class OpalEstate_User_Search {
/**
*
*/
protected $user_id = 0;
/**
*
*/
public static function get_instance() {
static $_instance;
if ( ! $_instance ) {
$_instance = new self();
}
return $_instance;
}
/**
*
*/
public function __construct() {
add_action( 'init', [ $this, 'init' ] );
}
/**
* Set values when user logined in system
*/
public function init() {
global $current_user;
wp_get_current_user();
$this->user_id = $current_user->ID;
add_filter( 'opalestate_management_user_menu', [ $this, 'dashboard_menu' ] );
add_action( 'wp_ajax_opalestate_ajx_save_search', [ $this, 'do_save' ] );
add_action( 'wp_ajax_nopriv_opalestate_ajx_save_search', [ $this, 'do_save' ] );
add_shortcode( 'opalestate_user_saved_search', [ $this, 'savedsearch_page' ] );
add_filter( 'opalestate_user_content_saved_search_page', [ $this, 'savedsearch_page' ] );
}
/**
*
*/
public function get_search_by_code( $code ) {
global $wpdb;
$query = " SELECT * FROM " . $wpdb->prefix . "opalestate_usersearch WHERE code like %s ";
$items = $wpdb->get_results( $wpdb->prepare( $query, $code ) );
if ( isset( $items[0] ) ) {
return $items[0];
}
return false;
}
/**
*
*/
public function has_existed( $params ) {
return $this->get_search_by_code( md5( $params ) );
}
/**
*
*/
public function insert( $data ) {
global $wpdb;
$args = [
'name' => '',
'params' => '',
'code' => '',
'user_id' => $this->user_id,
];
$args = array_merge( $args, $data );
$args['code'] = md5( $data['params'] );
$id = $wpdb->insert( $wpdb->prefix . 'opalestate_usersearch', $args );
return $id;
}
/**
*
*/
public static function install() {
try {
if ( ! function_exists( 'dbDelta' ) ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
}
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'opalestate_usersearch' . ' (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
params VARCHAR(255),
code VARCHAR(255),
user_id INT(11) DEFAULT 0
) ' . $charset_collate;
dbDelta( $sql );
} catch ( Exception $e ) {
}
}
/**
*
*/
public function do_save() {
if ( $this->user_id > 0 && isset( $_POST['params'] ) && isset( $_POST['name'] ) && ! empty( $_POST['name'] ) && ! empty( $_POST['params'] ) ) {
if ( ! $this->has_existed( $_POST['params'] ) ) {
$this->insert( [ 'name' => sanitize_text_field( $_POST['name'] ), 'params' => $_POST['params'] ] );
$result = [ 'status' => true, 'message' => esc_html__( 'Saved this search successful.', 'opalestate-pro' ) ];
} else {
$result = [ 'status' => false, 'message' => esc_html__( 'You saved this search', 'opalestate-pro' ) ];
}
} else {
$result = [ 'status' => false, 'message' => esc_html__( 'Please sign in to save this search.', 'opalestate-pro' ) ];
}
echo json_encode( $result );
die;
}
/**
*
*/
public function do_delete( $id ) {
global $wpdb;
if ( $this->user_id ) {
$wpdb->delete( $wpdb->prefix . "opalestate_usersearch", [ 'id' => $id, 'user_id' => $this->user_id ], [ '%d' ] );
}
}
/**
*
*/
public function get_list() {
global $wpdb;
$query = " SELECT * FROM " . $wpdb->prefix . "opalestate_usersearch where user_id=" . $this->user_id;
return $wpdb->get_results( $query );
}
/**
*
*/
public function is_saved() {
}
/**
*
*/
public function dashboard_menu( $menu ) {
$menu['savedsearch'] = [
'icon' => 'fa fa-search',
'link' => 'saved_search',
'title' => esc_html__( 'Saved Search', 'opalestate-pro' ),
'id' => 0,
];
return $menu;
}
/**
*
*/
public function savedsearch_page() {
if ( isset( $_GET['doaction'] ) && $_GET['doaction'] == 'delete' && isset( $_GET['id'] ) ) {
$this->do_delete( absint( $_GET['id'] ) );
}
return opalestate_load_template_path( 'user-search/content-savedsearch' );
}
/**
*
*/
public function render_button() {
echo opalestate_load_template_path( 'user-search/render-form' );
}
}
if ( opalestate_options( 'enable_saved_usersearch', 'on' ) == 'on' ) {
OpalEstate_User_Search::get_instance();
}

View File

@@ -0,0 +1,717 @@
<?php
/**
* OpalEstate_User
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* @website http://www.wpopal.com
* @support http://www.wpopal.com/support/forum.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class OpalEstate_User {
/**
* @var
*/
public $id;
/**
* @var
*/
public $current_user_id;
/**
* @var mixed|void
*/
public $enable_extra_profile;
/**
* @var
*/
public $roles;
/**
* @var
*/
public $user_id;
/**
* @var
*/
public $new_attachmenet_ids;
/**
* OpalEstate_User constructor.
*/
public function __construct() {
define( "OPALESTATE_USER_PROFILE_PREFIX", 'opalestate_user_' );
$shortcodes = [
'user_profile' => [ 'code' => 'user_profile', 'label' => esc_html__( 'User Profile', 'opalestate-pro' ) ],
'myaccount' => [ 'code' => 'myaccount', 'label' => esc_html__( 'My Account', 'opalestate-pro' ) ],
];
foreach ( $shortcodes as $shortcode ) {
add_shortcode( 'opalestate_' . $shortcode['code'], [ $this, $shortcode['code'] ] );
}
$this->enable_extra_profile = opalestate_options( 'enable_extra_profile', 'on' );
add_action( 'init', [ $this, 'process_frontend_submit' ], 99999 );
add_action( 'cmb2_render_text_password', [ $this, 'cmb2_render_text_password' ], 10, 5 );
/**
* Ajax action
*/
add_action( 'wp_ajax_opalestate_save_changepass', [ $this, 'save_change_password' ] );
add_action( 'wp_ajax_nopriv_opalestate_save_changepass', [ $this, 'save_change_password' ] );
add_action( 'cmb2_after_init', [ $this, 'process_submission' ], 100000 );
/**
* Check User Block Submission
*/
add_action( 'opalestate_submission_form_before', [ $this, 'show_message' ], 9 );
add_action( 'opalestate_before_process_ajax_upload_file', [ $this, 'check_blocked' ] );
add_action( 'opalestate_before_process_ajax_upload_user_avatar', [ $this, 'check_blocked' ] );
add_action( 'opalestate_profile_form_process_before', [ $this, 'check_blocked' ] );
add_action( 'opalestate_toggle_featured_property_before', [ $this, 'check_blocked' ] );
add_action( 'user_register', [ $this, 'on_create_user' ], 10, 1 );
add_action( 'profile_update', [ $this, 'on_create_user' ], 10, 1 );
add_action( 'opalestate_after_register_successfully', [ $this, 'on_regiser_user' ], 10, 1 );
add_action( 'init', [ $this, 'disable' ], 100000 );
add_action( 'init', [ $this, 'init_user_management' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'scripts_styles' ], 99 );
add_filter( 'pre_get_posts', [ $this, 'show_current_user_attachments' ] );
}
/**
* FrontEnd Submission
*/
public function show_current_user_attachments( $wp_query_obj ) {
global $current_user, $pagenow;
if ( ! is_a( $current_user, 'WP_User' ) ) {
return;
}
if ( ! in_array( $pagenow, [ 'upload.php', 'admin-ajax.php' ] ) ) {
return;
}
if ( ! empty( $current_user->roles ) ) {
if ( in_array( 'opalestate_agent', $current_user->roles ) || in_array( 'opalestate_agency', $current_user->roles ) ) {
$wp_query_obj->set( 'author', $current_user->ID );
}
}
return;
}
public function scripts_styles() {
if ( isset( $_GET['tab'] ) ) {
wp_register_style( 'opalesate-cmb2-front', OPALESTATE_PLUGIN_URL . 'assets/cmb2-front.css' );
wp_enqueue_style( 'opalesate-cmb2-front' );
wp_register_script(
'opalestate-dashboard',
OPALESTATE_PLUGIN_URL . 'assets/js/frontend/dashboard.js',
[
'jquery',
],
'1.0',
true
);
wp_enqueue_script( 'opalestate-dashboard' );
}
}
public function disable() {
if ( ! current_user_can( 'manage_options' ) ) {
add_action( 'wp_before_admin_bar_render', [ $this, 'disable_profile_page' ] );
add_action( 'admin_init', [ $this, 'disable_profile_page' ] );
add_filter( 'show_admin_bar', '__return_false' );
}
}
public function init_user_management() {
add_action( 'opalestate_user_content_profile_page', [ $this, 'user_profile' ] );
}
/**
*
*/
public function show_message_user_profile() {
$user_id = isset( $_GET['user_id'] ) ? intval( $_GET['user_id'] ) : 0;
$roles = opalestate_user_roles_by_user_id( $user_id );
if ( $roles ):
if ( in_array( 'opalestate_agency', $roles ) ):
$agency_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
if ( ! $agency_id ) {
return;
}
$link = get_edit_post_link( $agency_id );
?>
<div id="message" class="updated fade">
<p><?php echo sprintf( esc_html__( 'This user has role <strong>Opal Estate Agency</strong> and click here to <a target="_blank" href="%s">update Agency profile</a>',
'opalestate-pro' ), $link ); ?></p>
</div>
<?php elseif ( in_array( 'opalestate_agent', $roles ) ) :
$agent_id = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
if ( ! $agent_id ) {
return;
}
$link = get_edit_post_link( $agent_id );
?>
<div id="message" class="updated fade">
<p><?php echo sprintf( esc_html__( 'This user has role <strong>Opal Estate Agent</strong> and click here to <a target="_blank" href="%s">update Agent profile</a>',
'opalestate-pro' ), $link ); ?></p>
</div>
<?php endif; ?>
<?php
endif;
}
/**
*
*/
public function on_regiser_user( $user_id ) {
if ( isset( $_POST['role'] ) ) {
$roles = opalestate_user_roles_by_user_id( $user_id );
// Fetch the WP_User object of our user.
$u = new WP_User( $user_id );
$u->remove_role( 'subscriber' );
// Replace the current role with 'editor' role
$u->set_role( sanitize_text_field( $_POST['role'] ) );
if ( $roles && in_array( $_POST['role'], $roles ) ) {
$role = str_replace( 'opalestate_', '', sanitize_text_field( $_POST['role'] ) );
do_action( 'opalestate_on_set_role_' . $role, $user_id );
}
}
}
/**
*
*/
public function on_create_user( $user_id ) {
if ( isset( $_POST['role'] ) ) {
$roles = opalestate_user_roles_by_user_id( $user_id );
if ( $roles && in_array( $_POST['role'], $roles ) ) {
$role = sanitize_text_field( str_replace( 'opalestate_', '', $_POST['role'] ) );
do_action( 'opalestate_on_set_role_' . $role, $user_id );
}
}
}
/**
*
*/
public function disable_profile_page() {
// Remove AdminBar Link
if (
'wp_before_admin_bar_render' === current_filter()
&& ! current_user_can( 'manage_options' )
) {
return $GLOBALS['wp_admin_bar']->remove_menu( 'edit-profile', 'user-actions' );
}
// Remove (sub)menu items
// remove_menu_page( 'profile.php' );
if ( function_exists( "remove_submenu_page" ) ) {
remove_submenu_page( 'users.php', 'profile.php' );
}
// Deny access to the profile page and redirect upon try
if (
defined( 'IS_PROFILE_PAGE' )
&& IS_PROFILE_PAGE
&& ! current_user_can( 'manage_options' )
) {
// wp_redirect( admin_url() );
exit;
}
}
/**
*
*/
public function show_message() {
if ( $this->is_blocked() ) {
echo apply_filters( 'opalestate_user_block_submission_message',
'<div class="alert alert-danger">' . __( 'Your account was blocked to use the submission form, so you could not submit any property.', 'opalestate-pro' ) . '</div>' );
}
}
/**
*
*/
public function check_blocked() {
$check = $this->is_blocked();
if ( $check ) {
$std = new stdClass();
$std->status = false;
$std->message = esc_html__( 'Your account is blocked, you could not complete this action', 'opalestate-pro' );
$std->msg = $std->message;
echo json_encode( $std );
wp_die();
}
}
/**
*
*/
public static function get_user_types() {
return apply_filters( 'opalestate_usertypes', [
'none' => esc_html__( 'Subscriber', 'opalestate-pro' ),
'opalestate_agent' => esc_html__( 'Agent', 'opalestate-pro' ),
'opalestate_agency' => esc_html__( 'Agency', 'opalestate-pro' ),
] );
}
/**
*
*/
public function process_submission() {
global $current_user;
// Verify Nonce
$user_id = get_current_user_id();
$check = $this->is_blocked();
$key = 'nonce_CMB2phpopalestate_user_front';
if ( ! isset( $_POST[ $key ] ) || empty( $_POST[ $key ] ) || ! is_user_logged_in() || $check ) {
return;
}
$this->process_upload_files( 0 );
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
$post_id = $user_id;
$metaboxes = apply_filters( 'cmb2_meta_boxes', $this->front_edit_fields( [] ) );
cmb2_get_metabox_form( $metaboxes[ $prefix . 'front' ], $post_id );
$cmb = cmb2_get_metabox( $prefix . 'front', $post_id );
$sanitized_values = $cmb->get_sanitized_values( $_POST );
$cmb->save_fields( $user_id, 'user', $sanitized_values );
$posts = [
'first_name',
'last_name',
'description',
];
foreach ( $posts as $post ) {
if ( isset( $_POST[ $post ] ) ) {
update_user_meta( $current_user->ID, $post, esc_attr( $_POST[ $post ] ) );
}
}
if ( $this->new_attachmenet_ids ) {
foreach ( $this->new_attachmenet_ids as $_id ) {
delete_post_meta( $_id, '_pending_to_use_', 1 );
}
}
$this->remove_dirty_images( $user_id );
return opalestate_output_msg_json( true,
__( 'The data updated successful, please wait for redirecting', 'opalestate-pro' ),
[
'heading' => esc_html__( 'Update Information', 'opalestate-pro' ),
'redirect' => opalestate_get_user_management_page_uri( [ 'tab' => 'profile' ] ),
]
);
}
/**
* Remove dirty images of current user
*/
public function remove_dirty_images( $user_id ) {
if ( isset( $_POST['remove_image_id'] ) && is_array( $_POST['remove_image_id'] ) && $_POST['remove_image_id'] ) {
foreach ( $_POST['remove_image_id'] as $key => $value ) {
$post = get_post( $value );
if ( $post->post_author == $user_id ) {
wp_delete_attachment( $value );
}
}
}
}
/**
*
*
*/
private function get_field_name( $field ) {
return OPALESTATE_USER_PROFILE_PREFIX . $field;
}
/**
* Process upload images for properties
*/
public function upload_image( $submitted_file, $parent_id = 0 ) {
return opalesate_upload_image( $submitted_file, $parent_id );
}
private function process_upload_files( $post_id ) {
//upload images for featured and gallery images
if ( isset( $_FILES ) && ! empty( $_FILES ) ) {
///
$fields = [
$this->get_field_name( 'avatar_id' ),
];
foreach ( $_FILES as $key => $value ) {
// allow processing in fixed collection
if ( in_array( $key, $fields ) ) {
$ufile = $_FILES[ $key ];
/// /////
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
$output = [];
foreach ( $ufile['name'] as $f_key => $f_value ) {
$loop_file = [
'name' => $ufile['name'][ $f_key ],
'type' => $ufile['type'][ $f_key ],
'tmp_name' => $ufile['tmp_name'][ $f_key ],
'error' => $ufile['error'][ $f_key ],
'size' => $ufile['size'][ $f_key ],
];
$new_atm = $this->upload_image( $loop_file, $post_id );
if ( $new_atm ) {
$_POST[ $key ] = isset( $_POST[ $key ] ) ? $_POST[ $key ] : [];
$_POST[ $key ][ $new_atm['attachment_id'] ] = $new_atm['url'];
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
} ///
elseif ( isset( $ufile['name'] ) ) {
$new_atm = $this->upload_image( $ufile, $post_id );
if ( $new_atm ) {
$_POST[ $key ] = $new_atm['attachment_id'];
if ( preg_match( "#id#", $key ) ) {
$_key = str_replace( "_id", "", $key );
$_POST[ $_key ] = $new_atm['url'];
}
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
//// / //
}
}
}
}
/**
*
*/
public static function is_blocked() {
global $current_user;
// Verify Nonce
$user_id = get_current_user_id();
if ( $user_id <= 0 ) {
return true;
}
$blocked = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'block_submission', true );
return $blocked;
}
/**
*
*/
public function get_avatar_url( $user_id ) {
return get_avatar_url( $user_id );
}
/**
*
*/
public static function get_author_picture( $user_id ) {
$avatar = get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'avatar', true );
if ( ! $avatar ) {
$avatar = opalestate_get_image_avatar_placehold();
}
return $avatar;
}
/**
*
*/
public function shortcode_button() {
}
/**
*
*/
public function save_change_password() {
global $current_user;
$nonce = 'nonce_CMB2phpopalestate_user_frontchangepass';
if ( ! isset( $_POST[ $nonce ], $_POST['oldpassword'], $_POST['new_password'], $_POST['confirm_password'] ) || ! wp_verify_nonce( $_POST[ $nonce ], $nonce ) ) {
return false;
}
do_action( 'opalestate_profile_form_process_before' );
$output = new stdClass();
$output->status = false;
$output->message = esc_html__( 'Found a problem while updating', 'opalestate-pro' );
wp_get_current_user();
$userID = $current_user->ID;
$oldpassword = sanitize_text_field( $_POST['oldpassword'] );
$new_password = sanitize_text_field( $_POST['new_password'] );
$confirm_password = sanitize_text_field( $_POST['confirm_password'] );
if ( empty( $oldpassword ) || empty( $new_password ) || empty( $confirm_password ) ) {
$output->message = esc_html__( 'Passwords fields are not empty', 'opalestate-pro' );
echo json_encode( $output );
exit;
}
if ( $new_password != $confirm_password ) {
$output->message = esc_html__( 'New password is not same confirm password', 'opalestate-pro' );
echo json_encode( $output );
exit;
}
$user = get_user_by( 'id', $userID );
if ( $user && wp_check_password( $oldpassword, $user->data->user_pass, $userID ) ) {
wp_set_password( $new_password, $userID );
$output->status = true;
$output->message = esc_html__( 'Password Updated', 'opalestate-pro' );
} else {
$output->message = esc_html__( 'Old password is not correct', 'opalestate-pro' );
}
echo json_encode( $output );
die();
}
/**
* Defines custom front end fields
*
* @access public
* @param array $metaboxes
* @return array
*/
public function front_edit_fields( array $metaboxes ) {
$post_id = 0;
$prefix = OPALESTATE_USER_PROFILE_PREFIX;
global $current_user;
$default = [];
$user_roles = $current_user->roles;
$user_role = array_shift( $user_roles );
$metabox = new Opalestate_User_MetaBox();
///
if ( $this->get_member_id() ) {
$fields = array_merge_recursive( $default,
$metabox->get_front_base_field( $prefix )
);
} else {
$fields = array_merge_recursive( $default,
$metabox->get_front_base_field( $prefix ),
$metabox->get_job_fields( $prefix ),
$metabox->get_base_front_fields( $prefix ),
$metabox->get_address_fields( $prefix )
);
}
$metaboxes[ $prefix . 'front' ] = [
'id' => $prefix . 'front',
'title' => esc_html__( 'Name and Description', 'opalestate-pro' ),
'object_types' => [ 'opalestate_property' ],
'context' => 'normal',
'object_types' => [ 'user' ], // Tells CMB2 to use user_meta vs post_meta
'priority' => 'high',
'show_names' => true,
'cmb_styles' => false,
'fields' => $fields,
];
$metaboxes[ $prefix . 'frontchangepass' ] = [
'id' => $prefix . 'frontchangepass',
'title' => esc_html__( 'Name and Description', 'opalestate-pro' ),
'object_types' => [ 'opalestate_property' ],
'context' => 'normal',
'object_types' => [ 'user' ], // Tells CMB2 to use user_meta vs post_meta
'priority' => 'high',
'show_names' => true,
'fields' => [
[
'id' => "oldpassword",
'name' => esc_html__( 'Old Password', 'opalestate-pro' ),
'type' => 'text_password',
'attributes' => [
'required' => 'required',
],
'description' => esc_html__( 'Please enter your old password', 'opalestate-pro' ),
],
[
'id' => "new_password",
'name' => esc_html__( 'New Password', 'opalestate-pro' ),
'type' => 'text_password',
'attributes' => [
'required' => 'required',
],
'description' => esc_html__( 'Please enter your new password.', 'opalestate-pro' ),
],
[
'id' => "confirm_password",
'name' => esc_html__( 'Confirm Password', 'opalestate-pro' ),
'type' => 'text_password',
'attributes' => [
'required' => 'required',
],
'description' => esc_html__( 'Please enter your confirm password.', 'opalestate-pro' ),
],
],
];
return $metaboxes;
}
public function cmb2_render_text_password( $field_args, $escaped_value, $object_id, $object_type, $field_type_object ) {
echo $field_type_object->input( [ 'type' => 'password', 'class' => 'form-control' ] );
}
public function myaccount() {
return opalestate_load_template_path( 'user/my-account' );
}
/**
* FrontEnd Submission
*/
public function user_profile() {
global $current_user;
if ( ! is_user_logged_in() ) {
echo opalestate_load_template_path( 'parts/not-allowed' );
return;
}
$user_id = get_current_user_id();
$metaboxes = apply_filters( 'cmb2_meta_boxes', $this->front_edit_fields( [] ) );
return opalestate_load_template_path( 'user/profile', [ 'metaboxes' => $metaboxes, 'user_id' => $user_id ] );
}
public function process_frontend_submit() {
if ( opalestate_options( 'enable_extra_profile', 'on' ) != 'on' ) {
return;
}
global $current_user;
}
/**
*
*/
private function update_data_agent_or_agency( $prefix ) {
global $current_user;
$post_id = isset( $_POST['object_id'] ) && absint( $_POST['object_id'] ) ? absint( $_POST['object_id'] ) : 0;
$user_id = get_current_user_id();
$metaboxes = apply_filters( 'opalestate_before_render_profile_' . $_GET['tab'] . '_form', [], $post_id );
$metaboxes = apply_filters( 'cmb2_meta_boxes', $metaboxes );
if ( isset( $metaboxes[ $prefix . 'front' ] ) ) {
if ( ! empty( $post_id ) ) {
$old_post = get_post( $post_id );
$post_date = $old_post->post_date;
} else {
$post_date = '';
}
$data = [
'ID' => $post_id,
'post_title' => $current_user->display_name,
'post_author' => $user_id,
'post_status' => 'publish',
'post_type' => 'opalestate_agent',
'post_date' => $post_date,
'post_content' => wp_kses( $_POST[ $prefix . 'text' ], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span><p>' ),
];
unset( $_POST[ $prefix . 'text' ] );
if ( $post_id > 0 ) {
$post_id = wp_update_post( $data, true );
} else {
$post_id = wp_insert_post( $data, true );
}
$post = get_post( $post_id );
if ( empty( $post->post_content ) || empty( $post->post_title ) || ! has_post_thumbnail( $post_id ) ) {
$data['post_status'] = 'pending';
$post_id = wp_update_post( $data, true );
}
update_user_meta( $user_id, $prefix . 'related_id', $post_id );
cmb2_get_metabox_form( $metaboxes[ $prefix . 'front' ], $post_id );
return $post_id;
}
return false;
}
public static function get_member_id() {
$user_id = get_current_user_id();
return get_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . 'related_id', true );
}
}
new OpalEstate_User();

View File

@@ -0,0 +1,29 @@
<?php
class OpalEstate_User_Statistics {
public $user_id;
public function __construct () {
$this->user_id = get_current_user_id();
}
public function get_count_properties() {
$query = Opalestate_Query::get_properties_by_user( array(), $this->user_id );
return $query->found_posts;
}
public function get_count_featured() {
$query = Opalestate_Query::get_properties_by_user( array(
'featured' => 1
), $this->user_id );
return $query->found_posts;
}
public function get_count_pending_properties() {
$query = Opalestate_Query::get_properties_by_user( array(
'post_status' => 'pending'
), $this->user_id );
return $query->found_posts;
}
}
?>

261
inc/user/functions.php Executable file
View File

@@ -0,0 +1,261 @@
<?php
function opalestate_submssion_list_page( $args = [] ) {
return opalestate_get_user_management_page_uri( array('tab' => 'submission_list') );
}
function opalestate_get_user_management_page_uri( $args = [] ) {
global $opalestate_options;
$uri = isset( $opalestate_options['user_management_page'] ) ? get_permalink( absint( $opalestate_options['user_management_page'] ) ) : get_bloginfo( 'url' );
if ( ! empty( $args ) ) {
// Check for backward compatibility
if ( is_string( $args ) ) {
$args = str_replace( '?', '', $args );
}
$args = wp_parse_args( $args );
$uri = add_query_arg( $args, $uri );
}
return apply_filters( 'opalestate_user_management_page_uri', $uri );
}
function opalestate_get_current_url( $args = [] ) {
global $wp;
if( isset($_GET['tab']) && $_GET['tab'] ) {
$args['tab'] = $_GET['tab'];
}
$current_url = home_url( add_query_arg( $args, $wp->request ) );
return $current_url;
}
function opalestate_get_user_tab_uri( $tab ) {
$args['tab'] = $tab ;
return opalestate_get_current_url( $args );
}
function opalestate_management_show_content_page_tab() {
$tab = isset($_GET['tab']) && $_GET['tab'] ? sanitize_text_field( $_GET['tab'] ): 'dashboard';
$fnc = 'opalestate_user_content_'.$tab.'_page';
$content = apply_filters( $fnc, '' );
if( $content ) {
echo $content;
} else {
if( function_exists( $fnc ) ) {
$fnc();
} else {
opalestate_user_content_dashboard_page();
}
}
}
function opalestate_user_savedsearch_page( $args = [] ) {
$uri = get_permalink( opalestate_get_option( 'saved_link_page', '/' ) );
if ( ! empty( $args ) ) {
// Check for backward compatibility
if ( is_string( $args ) ) {
$args = str_replace( '?', '', $args );
}
$args = wp_parse_args( $args );
$uri = add_query_arg( $args, $uri );
}
return $uri;
}
function opalestate_my_account_page( $id = false, $args = array() ) {
$page = get_permalink( opalestate_get_option( 'user_myaccount_page', '/' ) );
if ( $id ) {
$edit_page_id = opalestate_get_option( 'user_myaccount_page' );
$page = $edit_page_id ? get_permalink( $edit_page_id ) : $page;
$page = add_query_arg( 'id', $id, $page );
}
if( $args ){
foreach( $args as $key => $value ) {
$page = add_query_arg( $key, $value, $page );
}
}
return $page;
}
function opalestate_submssion_page( $id = false, $args = array() ) {
$page = get_permalink( opalestate_get_option( 'submission_page', '/' ) );
if ( $id ) {
$edit_page_id = opalestate_get_option( 'submission_edit_page' );
$page = $edit_page_id ? get_permalink( $edit_page_id ) : $page;
$page = add_query_arg( 'id', $id, $page );
}
if( $args ){
foreach( $args as $key => $value ) {
$page = add_query_arg( $key, $value, $page );
}
}
return $page;
}
function opalestate_management_user_menu() {
}
function opalestate_management_user_menu_tabs() {
global $opalestate_options;
$menu = [];
$menu['dashboard'] = [
'icon' => 'fa fa-user',
'link' => 'dashboard',
'title' => esc_html__( 'Dashboard', 'opalestate-pro' ),
'id' => isset( $opalestate_options['profile_page'] ) ? $opalestate_options['profile_page'] : 0,
];
$menu['profile'] = [
'icon' => 'fa fa-user',
'link' => 'profile',
'title' => esc_html__( 'Personal Information', 'opalestate-pro' ),
'id' => isset( $opalestate_options['profile_page'] ) ? $opalestate_options['profile_page'] : 0,
];
$menu['favorite'] = [
'icon' => 'fa fa-heart',
'link' => 'favorite',
'title' => esc_html__( 'Favorite', 'opalestate-pro' ),
'id' => isset( $opalestate_options['favorite_page'] ) ? $opalestate_options['favorite_page'] : 0,
];
$menu['reviews'] = [
'icon' => 'fa fa-star',
'link' => 'reviews',
'title' => esc_html__( 'Reviews', 'opalestate-pro' ),
'id' => isset( $opalestate_options['reviews_page'] ) ? $opalestate_options['reviews_page'] : 0,
];
$menu['reviews'] = [
'icon' => 'fa fa-star',
'link' => 'reviews',
'title' => esc_html__( 'Reviews', 'opalestate-pro' ),
'id' => isset( $opalestate_options['reviews_page'] ) ? $opalestate_options['reviews_page'] : 0,
];
if( opalestate_get_option('message_log') ) {
$menu['messages'] = [
'icon' => 'fa fa-envelope',
'link' => 'messages',
'title' => esc_html__( 'Messages', 'opalestate-pro' ),
'id' => isset( $opalestate_options['reviews_page'] ) ? $opalestate_options['reviews_page'] : 0,
];
}
$menu['submission'] = [
'icon' => 'fa fa-upload',
'link' => 'submission',
'title' => esc_html__( 'Submit Property', 'opalestate-pro' ),
'id' => isset( $opalestate_options['submission_page'] ) ? $opalestate_options['submission_page'] : 0,
];
$menu['myproperties'] = [
'icon' => 'fa fa-building',
'link' => 'submission_list',
'title' => esc_html__( 'My Properties', 'opalestate-pro' ),
'id' => isset( $opalestate_options['submission_list_page'] ) ? $opalestate_options['submission_list_page'] : 0,
];
$menu = apply_filters( 'opalestate_management_user_menu', $menu );
$output = '<ul class="account-links nav-pills nav-stacked">';
global $post;
$uri = opalestate_get_user_management_page_uri();
foreach ( $menu as $key => $item ) {
if( preg_match("#http#", $item['link']) ){
$link = $item['link'];
} else {
$link = $uri . '?tab=' . $item['link'];
}
$output .= '<li class="' . ( is_object( $post ) && $post->ID == $item['id'] ? 'active' : '' ) . '"><a href="' . $link . '"><i class="' . $item['icon'] . '"></i> ' . $item['title'] . '</a></li>';
}
$output .= '<li><a href="' . wp_logout_url( home_url( '/' ) ) . '"> <i class="fa fa-unlock"></i> ' . esc_html__( 'Log out', 'opalestate-pro' ) . '</a></li>';
$output .= '</ul>';
echo $output;
}
function opalestate_user_content_dashboard_page(){
echo opalestate_load_template_path( 'user/dashboard' );
}
if ( ! function_exists( 'opalestate_create_user' ) ) {
/**
* create new wp user
*/
function opalestate_create_user( $credentials = [] ) {
$cred = wp_parse_args( $credentials, [
'user_login' => '',
'user_email' => '',
'user_pass' => '',
'first_name' => '',
'last_name' => '',
] );
/* sanitize user email */
$user_email = sanitize_email( $cred['user_email'] );
if ( email_exists( $user_email ) ) {
return new WP_Error( 'email-exists', esc_html__( 'An account is already registered with your email address. Please login.', 'opalestate-pro' ) );
}
$username = sanitize_user( $cred['user_login'] );
if ( ! $username || ! validate_username( $username ) ) {
return new WP_Error( 'username-invalid', esc_html__( 'Please enter a valid account username.', 'opalestate-pro' ) );
}
/* if username exists */
if ( username_exists( $username ) ) {
return new WP_Error( 'username-exists', esc_html__( 'Username is already exists.', 'opalestate-pro' ) );
}
/* password empty */
if ( ! $cred['user_pass'] ) {
return new WP_Error( 'password-empty', esc_html__( 'Password is requried.', 'opalestate-pro' ) );
} else {
$password = $cred['user_pass'];
}
$user_data = apply_filters( 'opalestate_create_user_data', [
'user_login' => $username,
'user_pass' => $password,
'user_email' => $user_email,
] );
/* insert new wp user */
$user_id = wp_insert_user( $user_data );
if ( is_wp_error( $user_id ) ) {
return new WP_Error( 'user-create-failed', $user_id->get_error_message() );
}
/* allow hook like insert user meta. create new post type agent in opalmembership */
do_action( 'opalmembership_create_new_user_successfully', $user_id, $user_data, $cred );
return $user_id;
}
}
?>

BIN
inc/vendors/.DS_Store vendored Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More