Big fixes

This commit is contained in:
Hoang Huu
2020-05-04 15:53:09 +07:00
parent 453e78da8b
commit b4db533574
24 changed files with 4837 additions and 4697 deletions

View File

@@ -84,6 +84,14 @@ class Opalestate_Settings_3rd_party_Tab extends Opalestate_Settings_Base_Tab {
'id' => 'google_map_custom_style',
'type' => 'textarea_code',
],
[
'name' => esc_html__( 'Autocomplete Restrictions', 'opalestate-pro' ),
'desc' => __( 'Enter one or more country codes ALPHA-2 separator by ",". Example: "us" for USA. <a href="https://www.iban.com/country-codes" target="_blank">See list country codes.</a>',
'opalestate-pro' ),
'id' => 'autocomplete_restrictions',
'type' => 'text',
'default' => '',
],
];
}

View File

@@ -53,8 +53,9 @@ class OpalEstate_Enqueue {
wp_enqueue_script( 'opalestate-gmap', OPALESTATE_PLUGIN_URL . 'assets/js/frontend/googlemaps.js', [ 'jquery' ], OPALESTATE_VERSION, false );
$custom_map_styles = json_decode( ( opalestate_options( 'google_map_custom_style', '' ) ) );
wp_localize_script( 'opalestate-gmap', 'opalestateGmap', [
'style' => opalestate_options( 'google_map_style', 'standard' ),
'custom_style' => json_encode( $custom_map_styles ),
'style' => opalestate_options( 'google_map_style', 'standard' ),
'autocomplete_restrictions' => opalestate_get_autocomplete_restrictions(),
'custom_style' => json_encode( $custom_map_styles ),
] );
/**
@@ -126,7 +127,7 @@ class OpalEstate_Enqueue {
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 );

View File

@@ -34,7 +34,7 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
<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="<?php echo opalestate_get_property_meta_icon( $field ); ?>"></i>
<input class="form-control" value="<?php echo $qvalue ? $qvalue : $input_default_value; ?>" type="text" name="info[<?php echo $field; ?>]" placeholder="<?php echo esc_attr(
<input class="form-control" value="<?php echo esc_attr( $qvalue ? $qvalue : $input_default_value ); ?>" 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>
@@ -62,7 +62,7 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
foreach ( $option_values as $value ) {
$selected = $value == $qvalue ? 'selected="selected"' : '';
$template .= '<option ' . $selected . ' value="' . $value . '">' . $value . '</option>';
$template .= '<option ' . $selected . ' value="' . esc_attr( $value ) . '">' . esc_html( $value ) . '</option>';
}
$template .= '</select>';
$template = sprintf( $template, $field, $label );

View File

@@ -1349,9 +1349,9 @@ function opalestate_is_require_login_to_show_author_box() {
function opalestate_clean( $var ) {
if ( is_array( $var ) ) {
return array_map( 'opalestate_clean', $var );
} else {
return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
}
return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
}
/**
@@ -1400,8 +1400,34 @@ add_action( 'widgets_init', 'opalestate_widgets_init' );
/**
* Get email date format.
*
* @return mixed|void
* @return string
*/
function opalestate_email_date_format() {
return apply_filters( 'opalestate_email_date_format', 'F j, Y, g:i a' );
}
/**
* Get autocomplete restrictions.
*
* @return string
*/
function opalestate_get_autocomplete_restrictions() {
$restrictions_option = trim( opalestate_options( 'autocomplete_restrictions', '' ) );
if ( ! $restrictions_option ) {
return '';
}
$array = explode( ',', $restrictions_option );
$results = [];
foreach ( $array as $res ) {
$results[] = strtolower( trim( $res ) );
}
if ( ! $results ) {
return '';
}
return json_encode( $results );
}

View File

@@ -37,12 +37,12 @@ class OpalEstate_Search {
$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 = 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'] );
if ( isset( $_GET['paged'] ) && absint( $_GET['paged'] ) > 0 ) {
$paged = absint( $_GET['paged'] );
}
$args = [
@@ -56,66 +56,92 @@ class OpalEstate_Search {
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
$tax_query[] = [
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
}
if ( isset( $_GET['state'] ) && $_GET['state'] != -1 ) {
$tax_query[] =
[
if ( is_array( $_GET['state'] ) ) {
$tax_query[] = [
'taxonomy' => 'opalestate_state',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['state'] ),
];
} else {
$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'] ),
];
$tax_query[] = [
'taxonomy' => 'opalestate_city',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['city'] ),
];
}
if ( isset( $_GET['types'] ) && $_GET['types'] != -1 ) {
$tax_query[] =
[
if ( is_array( $_GET['types'] ) ) {
$tax_query[] = [
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['types'] ),
];
} else {
$tax_query[] = [
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['types'] ),
];
}
}
if ( isset( $_GET['cat'] ) && $_GET['cat'] != -1 ) {
$tax_query[] =
[
if ( is_array( $_GET['cat'] ) ) {
$tax_query[] = [
'taxonomy' => 'property_category',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['cat'] ),
];
} else {
$tax_query[] = [
'taxonomy' => 'property_category',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['cat'] ),
];
}
}
if ( isset( $_GET['status'] ) && $_GET['status'] != -1 ) {
$tax_query[] =
[
if ( is_array( $_GET['status'] ) ) {
$tax_query[] = [
'taxonomy' => 'opalestate_status',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['status'] ),
];
} else {
$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' => ( $_GET['amenities'] ),
];
$tax_query[] = [
'taxonomy' => 'opalestate_amenities',
'field' => 'slug',
'terms' => opalestate_clean( $_GET['amenities'] ),
];
}
if ( $tax_query ) {
@@ -153,14 +179,14 @@ class OpalEstate_Search {
if ( $search_min_price != '' && $search_max_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) {
if ( $search_min_price ) {
array_push( $args['meta_query'], [
$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'], [
$args['meta_query'][] = [
[
[
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
@@ -174,56 +200,55 @@ class OpalEstate_Search {
'type' => 'NUMERIC',
],
],
] );
];
}
} elseif ( $search_min_price != '' && is_numeric( $search_min_price ) ) {
array_push( $args['meta_query'], [
$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'], [
$args['meta_query'][] = [
'key' => OPALESTATE_PROPERTY_PREFIX . 'price',
'value' => $search_max_price,
'compare' => '<=',
'type' => 'NUMERIC',
] );
];
}
if ( $search_min_area != '' && $search_max_area != '' && is_numeric( $search_min_area ) && is_numeric( $search_max_area ) ) {
array_push( $args['meta_query'], [
$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'], [
$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'], [
$args['meta_query'][] = [
'key' => OPALESTATE_PROPERTY_PREFIX . 'areasize',
'value' => $search_max_area,
'compare' => '<=',
'type' => 'NUMERIC',
] );
];
}
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'], [
$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;
@@ -249,7 +274,7 @@ class OpalEstate_Search {
$args['orderby'] = 'meta_value_num';
$args['order'] = $ksearchs[1];
}
} elseif ( 'on' == opalestate_options( 'show_featured_first', 'off' ) ) {
} elseif ( 'on' === opalestate_options( 'show_featured_first', 'off' ) ) {
$args['orderby'] = [ 'meta_value' => 'DESC', 'date' => 'DESC' ];
$args['meta_key'] = OPALESTATE_PROPERTY_PREFIX . 'featured';
}
@@ -269,26 +294,26 @@ class OpalEstate_Search {
$max_request = isset( $_GET[ 'max_' . $request ] ) ? sanitize_text_field( $_GET[ 'max_' . $request ] ) : '';
if ( $min_request != '' && $max_request != '' && is_numeric( $min_request ) && is_numeric( $max_request ) ) {
array_push( $args['meta_query'], [
$args['meta_query'][] = [
'key' => $meta['id'],
'value' => [ $min_request, $max_request ],
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
] );
];
} elseif ( $min_request != '' && is_numeric( $min_request ) ) {
array_push( $args['meta_query'], [
$args['meta_query'][] = [
'key' => $meta['id'],
'value' => $min_request,
'compare' => '>=',
'type' => 'NUMERIC',
] );
];
} elseif ( $max_request != '' && is_numeric( $max_request ) ) {
array_push( $args['meta_query'], [
$args['meta_query'][] = [
'key' => $meta['id'],
'value' => $max_request,
'compare' => '<=',
'type' => 'NUMERIC',
] );
];
}
}
}
@@ -352,20 +377,20 @@ class OpalEstate_Search {
$args['meta_query'] = [ 'relation' => 'AND' ];
if ( $search_min_price != $min && is_numeric( $search_min_price ) ) {
array_push( $args['meta_query'], [
$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'], [
$args['meta_query'][] = [
'key' => OPALESTATE_AGENT_PREFIX . 'target_max_price',
'value' => $search_max_price,
'compare' => '<=',
// 'type' => 'NUMERIC'
] );
];
}
return new WP_Query( $args );
@@ -388,23 +413,20 @@ class OpalEstate_Search {
$tax_query = [];
if ( isset( $_GET['location'] ) && $_GET['location'] != -1 ) {
$tax_query[] =
[
'taxonomy' => 'opalestate_location',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['location'] ),
];
$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'] ),
];
$tax_query[] = [
'taxonomy' => 'opalestate_types',
'field' => 'slug',
'terms' => sanitize_text_field( $_GET['types'] ),
];
}
if ( $tax_query ) {
@@ -418,7 +440,6 @@ class OpalEstate_Search {
return new WP_Query( $args );
}
public function filter_by_geolocations() {
}
@@ -444,7 +465,7 @@ class OpalEstate_Search {
continue;
}
if ( 'on' == $value ) {
if ( 'on' === $value ) {
$id = str_replace( OPALESTATE_PROPERTY_PREFIX, '', $meta['id'] );
$esettings[ $id ] = $meta['name'];
}
@@ -467,7 +488,6 @@ class OpalEstate_Search {
* Get Json data by action ajax filter
*/
public static function get_search_json() {
$query = self::get_search_results_query();
$output = [];
@@ -486,7 +506,6 @@ class OpalEstate_Search {
}
public static function render_get_properties() {
// $_GET = $_POST;
echo opalestate_load_template_path( 'shortcodes/ajax-map-search-result' );
die;
}

View File

@@ -83,8 +83,8 @@ class OpalEstate_Submission {
);
}
/*
* Is submission page. 'submission_page' option in General Setting
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function register_shortcodes() {
$shortcodes = [
@@ -103,8 +103,8 @@ class OpalEstate_Submission {
}
}
/*
* Is submission page. 'submission_page' option in General Setting
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function setting_content_tab( $tabs ) {
$tabs['submission_page'] = esc_html__( 'Submission', 'opalestate-pro' );
@@ -112,8 +112,8 @@ class OpalEstate_Submission {
return $tabs;
}
/*
* Is submission page. 'submission_page' option in General Setting
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function setting_content_fields( $fields = [] ) {
$fields = [
@@ -267,15 +267,15 @@ class OpalEstate_Submission {
return $fields;
}
/*
* Is submission page. 'submission_page' option in General Setting
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function head_check_page() {
}
/*
* Is submission page. 'submission_page' option in General Setting
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function render_button_edit() {
global $post, $current_user;
@@ -289,8 +289,8 @@ class OpalEstate_Submission {
}
}
/*
* Is submission page. 'submission_page' option in General Setting
/*
* Is submission page. 'submission_page' option in General Setting
*/
public function is_submission_page() {
global $post;
@@ -335,7 +335,7 @@ class OpalEstate_Submission {
return;
}
// remove all dirty images before edit/create new a property
// remove all dirty images before edit/create new a property
$this->cleanup();
wp_enqueue_script( 'opalestate-submission' );
@@ -396,11 +396,8 @@ class OpalEstate_Submission {
* 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;
@@ -421,7 +418,7 @@ class OpalEstate_Submission {
$post_status = 'pending';
if ( 'on' != opalestate_get_option( 'admin_approve', 'on' ) ) {
if ( 'on' !== opalestate_get_option( 'admin_approve', 'on' ) ) {
$post_status = 'publish';
}
@@ -485,7 +482,7 @@ class OpalEstate_Submission {
/*
* Processing upload files
*/
$this->process_upload_files( $post_id, $_POST );
$this->process_upload_files( $post_id );
/**
* Fetch sanitized values
@@ -513,12 +510,14 @@ class OpalEstate_Submission {
update_post_meta( $post_id, $prefix . 'featured_image', null );
// Update SKU.
if ( 'on' == opalestate_get_option( 'enable_submission_generate_sku', 'off' ) ) {
if ( 'on' === opalestate_get_option( 'enable_submission_generate_sku', 'off' ) ) {
$_sku = str_replace( '{property_id}', $post_id, opalestate_options( 'submission_sku_format', 'SKU-{property_id}' ) );
$sku_generated = apply_filters( 'opalestate_submission_sku_generated', sanitize_text_field( $_sku ) );
update_post_meta( $post_id, $prefix . 'sku', $sku_generated );
}
update_post_meta( $post_id, $prefix . 'featured', '' );
//redirect
$_SESSION['messages'][] = [ 'success', esc_html__( 'Property has been successfully updated.', 'opalestate-pro' ) ];
@@ -577,11 +576,8 @@ class OpalEstate_Submission {
* @param int $post_id Post 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( 'gallery' ),
$this->get_field_name( 'featured_image' ),
@@ -592,7 +588,6 @@ class OpalEstate_Submission {
if ( in_array( $key, $fields ) ) {
$ufile = $_FILES[ $key ];
/// /////
if ( isset( $ufile['name'] ) && is_array( $ufile['name'] ) ) {
$output = [];
@@ -620,11 +615,11 @@ class OpalEstate_Submission {
$this->new_attachmenet_ids[ $new_atm['attachment_id'] ] = $new_atm['attachment_id'];
}
}
//// / //
//// / //
}
}
// for group files
// for group files
$fields = [
$this->get_field_name( 'public_floor_group' ),
];

View File

@@ -149,7 +149,7 @@ class Opalestate_Taxonomy_Type {
public static function get_multi_check_list( $stypes ) {
$list = self::get_list();
echo opalestate_terms_multi_check( $list, $stypes );
echo opalestate_terms_multi_check( $list );
}
}

View File

@@ -126,37 +126,40 @@ function opalestate_get_read_message_uri( $message_id ) {
return opalestate_get_current_url( $args );
}
if ( ! function_exists( 'opalestate_terms_multi_check' ) ) {
function opalestate_terms_multi_check( $terms ) {
$html = '<div class="opal-form-group">';
function opalestate_terms_multi_check( $terms ) {
$html = '<div class="opal-form-group">';
foreach ( $terms as $term ) {
$id = time() . '-' . $term->slug;
$html .= '<div class="group-item">';
$html .= '<input type="checkbox" class="form-control-checkbox" id="' . $id . '" name="types[]" id="' . $id . '" value="' . $term->slug . '">';
$html .= ' <label for="' . $id . '">' . $term->name . '</label>';
$html .= '</div>';
}
foreach ( $terms as $term ) {
$id = time() . '-' . $term->slug;
$html .= '<div class="group-item">';
$html .= '<input type="checkbox" class="form-control-checkbox" id="' . $id . '" name="types[' . $term->slug . ']" id="' . $id . '" value="' . $term->slug . '">';
$html .= ' <label for="' . $id . '">' . $term->name . '</label>';
$html .= '</div>';
return $html;
}
$html .= '</div>';
return $html;
}
function opalestate_categories_multi_check( $terms ) {
$html = '<div class="opal-form-group">';
if ( ! function_exists( 'opalestate_categories_multi_check' ) ) {
function opalestate_categories_multi_check( $terms ) {
$html = '<div class="opal-form-group">';
foreach ( $terms as $term ) {
$id = time() . '-' . $term->slug;
$html .= '<div class="group-item">';
$html .= '<input type="checkbox" class="form-control-checkbox" id="' . $id . '" name="cat[' . $term->slug . ']" id="' . $id . '" value="' . $term->slug . '">';
$html .= ' <label for="' . $id . '">' . $term->name . '</label>';
$html .= '</div>';
}
foreach ( $terms as $term ) {
$id = time() . '-' . $term->slug;
$html .= '<div class="group-item">';
$html .= '<input type="checkbox" class="form-control-checkbox" id="' . $id . '" name="cat[' . $term->slug . ']" id="' . $id . '" value="' . $term->slug . '">';
$html .= ' <label for="' . $id . '">' . $term->name . '</label>';
$html .= '</div>';
return $html;
}
$html .= '</div>';
return $html;
}
function opalestate_get_image_by_id( $id ) {
@@ -169,39 +172,34 @@ function opalestate_get_image_by_id( $id ) {
return '';
}
/**
*
*/
function opalestate_get_loop_thumbnail( $size = 'property-thumbnail' ) { ?>
<div class="property-box-image">
<a href="<?php the_permalink(); ?>" class="property-box-image-inner">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( apply_filters( 'opalestate_loop_property_thumbnail', $size ) ); ?>
<?php else: ?>
<?php echo opalestate_get_image_placeholder( $size ); ?>
<?php endif; ?>
</a>
</div>
<?php
if ( ! function_exists( 'opalestate_get_loop_thumbnail' ) ) {
function opalestate_get_loop_thumbnail( $size = 'property-thumbnail' ) { ?>
<div class="property-box-image">
<a href="<?php the_permalink(); ?>" class="property-box-image-inner">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( apply_filters( 'opalestate_loop_property_thumbnail', $size ) ); ?>
<?php else: ?>
<?php echo opalestate_get_image_placeholder( $size ); ?>
<?php endif; ?>
</a>
</div>
<?php
}
}
/**
*
*/
function opalestate_get_loop_agent_thumbnail( $size = 'agent-thumbnail' ) { ?>
<div class="agent-box-image">
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( apply_filters( 'opalestate_loop_agent_thumbnail', $size ) ); ?>
<?php else: ?>
<?php echo opalestate_get_image_placeholder( $size ); ?>
<?php endif; ?>
</a>
</div>
<?php
if ( ! function_exists( 'opalestate_get_loop_agent_thumbnail' ) ) {
function opalestate_get_loop_agent_thumbnail( $size = 'agent-thumbnail' ) { ?>
<div class="agent-box-image">
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( apply_filters( 'opalestate_loop_agent_thumbnail', $size ) ); ?>
<?php else: ?>
<?php echo opalestate_get_image_placeholder( $size ); ?>
<?php endif; ?>
</a>
</div>
<?php
}
}
function opalestate_get_loop_short_meta() {

View File

@@ -1,173 +1,156 @@
<?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
exit; // Exit if accessed directly
}
if( !class_exists( 'CMB2_Uploader_Button' ) ) {
if ( ! class_exists( 'CMB2_Uploader_Button' ) ) {
/**
* Class CMB2_Uploader_Button
*/
class CMB2_Uploader_Button {
/**
* Class CMB2_Uploader_Button
*/
class CMB2_Uploader_Button {
/**
* Constructor
*/
public function __construct() {
add_action( 'cmb2_render_uploader', [ $this, 'callback' ], 10, 5 );
add_action( 'admin_head', [ $this, 'admin_head' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'scripts_styles' ], 99 );
}
/**
* Constructor
*/
public function __construct() {
add_action( 'cmb2_render_uploader', array( $this, 'callback' ), 10, 5 );
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'wp_enqueue_scripts', [$this,'scripts_styles'], 99 );
}
/**
* Register javascript file for processing upload images/files
*/
public function scripts_styles() {
wp_register_script(
'cmb2-uploader',
OPALESTATE_PLUGIN_URL . 'assets/js/frontend/uploader.js',
[
'jquery',
],
'4.4.3',
true
);
}
/**
* Register javascript file for processing upload images/files
*/
public function scripts_styles () {
wp_register_script(
'cmb2-uploader',
OPALESTATE_PLUGIN_URL . 'assets/js/frontend/uploader.js',
[
'jquery',
],
'4.4.3',
true
);
}
/**
* Render Preview is image or icon with its name
*/
private function render_image_or_icon( $escaped_value, $show_icon ) {
$cls = $show_icon ? "preview-icon" : "preview-image";
echo '<div class="inner ' . $cls . '">';
echo ' <span class="btn-close fa fa-close"></span> ';
if ( $show_icon ) {
echo '<i class="fas fa-paperclip"></i> ' . basename( get_attached_file( $escaped_value ) );
} else {
echo wp_get_attachment_image( $escaped_value, 'thumbnail' );
}
/**
* Render Preview is image or icon with its name
*/
private function render_image_or_icon ( $escaped_value , $show_icon ) {
$cls = $show_icon ? "preview-icon" : "preview-image";
echo '<div class="inner '.$cls.'">';
echo ' <span class="btn-close fa fa-close"></span> ';
if( $show_icon ){
echo '<i class="fas fa-paperclip"></i> '. basename ( get_attached_file( $escaped_value ) );
} else {
echo wp_get_attachment_image( $escaped_value, 'thumbnail' );
}
echo '</div>';
}
echo '</div>';
}
/**
* Render content input field.
*/
public function callback( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
wp_enqueue_script( 'cmb2-uploader' );
/**
* Render content input field.
*/
public function callback( $field, $escaped_value, $object_id, $object_type, $field_type_object) {
wp_enqueue_script( 'cmb2-uploader');
$field_name = $field->_name();
$field_name = $field->_name();
$args = array(
'type' => 'checkbox',
'id' => $field_name,
'name' => $field_name,
'desc' => '',
'value' => 'on',
);
$args = [
'type' => 'checkbox',
'id' => $field_name,
'name' => $field_name,
'desc' => '',
'value' => 'on',
];
if( $escaped_value == 'on' || $escaped_value == 1 ){
$args['checked'] = 'checked';
}
if ( $escaped_value == 'on' || $escaped_value == 1 ) {
$args['checked'] = 'checked';
}
$single = isset( $field->args['single'] ) && $field->args['single'];
$attrs = $single ? "" : 'multiple="multiple"';
$size = '';
if( isset($field->args['accept']) && $field->args['accept'] ){
$attrs .= ' accept="'.$field->args['accept'].'" ';
$single = isset( $field->args['single'] ) && $field->args['single'];
$attrs = $single ? "" : 'multiple="multiple"';
$size = '';
$info = array(
'size' => opalestate_options( 'upload_other_max_size', 0.5),
'number' => opalestate_options( 'upload_other_max_files', 10)
);
$class = 'upload-file-wrap';
} else {
$attrs .= ' accept="image/*" ';
$class = 'upload-image-wrap';
if ( isset( $field->args['accept'] ) && $field->args['accept'] ) {
$attrs .= ' accept="' . $field->args['accept'] . '" ';
$info = array(
'size' => opalestate_options( 'upload_image_max_size', 0.5),
'number' => opalestate_options( 'upload_image_max_files', 10)
);
}
if( $single ){
$info['number'] = 1;
}
$show_icon = isset($field->args['show_icon']) && $field->args['show_icon'] ? $field->args['show_icon']: false;
?>
<div class="cmb2-uploader-files <?php echo $class; ?>" data-name="<?php echo $args['id'];?>" data-single="<?php echo $single; ?>" data-show-icon="<?php echo $show_icon; ?>">
<?php if( $escaped_value && is_array($escaped_value) ): ?>
<?php foreach( $escaped_value as $key => $url ): ?>
<div class="uploader-item-preview">
<?php echo $this->render_image_or_icon( $key, $show_icon ); ?>
<input type="hidden" name="<?php echo $field_name; ?>" value="<?php echo $key; ?>">
</div>
<?php endforeach; ?>
<?php elseif( $escaped_value && !is_array($escaped_value) ): ?>
<div class="uploader-item-preview">
<?php echo $this->render_image_or_icon( $escaped_value, $show_icon ); ?>
<input type="hidden" name="<?php echo $field_name; ?>" value="<?php echo $escaped_value; ?>">
</div>
<?php elseif( empty($escaped_value) && isset($field->args['value']) && (int)$field->args['value'] ):
$image_id = $field->args['value'];
?>
<div class="uploader-item-preview">
<?php echo $this->render_image_or_icon( $image_id , $show_icon ); ?>
<input type="hidden" name="<?php echo $field_name; ?>" value="<?php echo $image_id; ?>">
</div>
<?php endif; ?>
<div class="button-placehold">
<div class="button-placehold-content">
<i class="fa fa-plus"></i>
<span><?php esc_html_e( "Upload", "opalestate" ); ?></span>
$info = [
'size' => opalestate_options( 'upload_other_max_size', 0.5 ),
'number' => opalestate_options( 'upload_other_max_files', 10 ),
];
$class = 'upload-file-wrap';
} else {
$attrs .= ' accept="image/*" ';
$class = 'upload-image-wrap';
$info = [
'size' => opalestate_options( 'upload_image_max_size', 0.5 ),
'number' => opalestate_options( 'upload_image_max_files', 10 ),
];
}
if ( $single ) {
$info['number'] = 1;
}
$show_icon = isset( $field->args['show_icon'] ) && $field->args['show_icon'] ? $field->args['show_icon'] : false;
?>
<div class="cmb2-uploader-files <?php echo $class; ?>" data-name="<?php echo $args['id']; ?>" data-single="<?php echo $single; ?>" data-show-icon="<?php echo $show_icon; ?>">
<?php if ( $escaped_value && is_array( $escaped_value ) ): ?>
<?php foreach ( $escaped_value as $key => $url ): ?>
<div class="uploader-item-preview">
<?php echo $this->render_image_or_icon( $key, $show_icon ); ?>
<input type="hidden" name="<?php echo $field_name; ?>[<?php echo $key; ?>]" value="<?php echo $url; ?>">
</div>
<?php endforeach; ?>
<?php elseif ( $escaped_value && ! is_array( $escaped_value ) ): ?>
<div class="uploader-item-preview">
<?php echo $this->render_image_or_icon( $escaped_value, $show_icon ); ?>
<input type="hidden" name="<?php echo $field_name; ?>" value="<?php echo $escaped_value; ?>">
</div>
</div>
<input type="file" name="<?php echo $args['id'];?>" <?php echo $attrs; ?> class="select-file" style="visibility: hidden;">
</div>
<?php elseif ( empty( $escaped_value ) && isset( $field->args['value'] ) && (int) $field->args['value'] ):
$image_id = $field->args['value'];
?>
<div class="uploader-item-preview">
<?php echo $this->render_image_or_icon( $image_id, $show_icon ); ?>
<input type="hidden" name="<?php echo $field_name; ?>" value="<?php echo $image_id; ?>">
</div>
<?php endif; ?>
<div class="button-placehold">
<div class="button-placehold-content">
<i class="fa fa-plus"></i>
<span><?php esc_html_e( "Upload", "opalestate-pro" ); ?></span>
</div>
</div>
<input type="file" name="<?php echo $args['id']; ?>" <?php echo $attrs; ?> class="select-file" style="visibility: hidden;">
</div>
<p class="cmb2-metabox-description">
<i>
<?php
echo sprintf( esc_html__( 'Allow upload file have size < %s MB and maximum number of files: %s' ,'opalestate-pro'),
'<strong>'.$info['size'].'</strong>', '<strong>'.$info['number'].'</strong>' ); ?>
</i>
<?php
echo sprintf( esc_html__( 'Allow upload file have size < %s MB and maximum number of files: %s', 'opalestate-pro' ),
'<strong>' . $info['size'] . '</strong>', '<strong>' . $info['number'] . '</strong>' ); ?>
</i>
</p>
<?php
}
<?php
}
/**
*
*/
public function admin_head() {
?>
<?php
}
}
$uploader = new CMB2_Uploader_Button();
/**
*
*/
public function admin_head() {
?>
<?php
}
}
$uploader = new CMB2_Uploader_Button();
}