| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
|
| 7 |
/** |
| 8 |
* Description of RealHomesClass |
| 9 |
* |
| 10 |
* @author mlsimport |
| 11 |
*/ |
| 12 |
class RealHomesClass { |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
/** |
| 19 |
* return custom post field |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
* @access protected |
| 23 |
* @var string $plugin_name |
| 24 |
*/ |
| 25 |
public function get_property_post_type() { |
| 26 |
return 'property'; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
/** |
| 32 |
* return custom post field |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @access protected |
| 36 |
* @var string $plugin_name |
| 37 |
*/ |
| 38 |
public function get_agent_post_type() { |
| 39 |
return 'agent'; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* image save |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* @access protected |
| 47 |
* @var string $plugin_name |
| 48 |
*/ |
| 49 |
public function enviroment_image_save( $property_id, $attach_id ) { |
| 50 |
add_post_meta( $property_id, 'REAL_HOMES_property_images', intval( $attach_id ) ); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Deal with extra meta |
| 56 |
*/ |
| 57 |
public function mlsimportSaasSetExtraMeta( $property_id, $property ) { |
| 58 |
$property_history = ''; |
| 59 |
$extra_meta_log = ''; |
| 60 |
$answer = array(); |
| 61 |
$extra_fields = array(); |
| 62 |
$options = get_option( 'mlsimport_admin_fields_select' ); |
| 63 |
$permited_meta = $options['mls-fields']; |
| 64 |
|
| 65 |
// save geo coordinates |
| 66 |
|
| 67 |
if ( isset( $property['meta']['property_longitude'] ) && isset( $property['meta']['property_latitude'] ) ) { |
| 68 |
$savingx = $property['meta']['property_latitude'] . ',' . $property['meta']['property_longitude']; |
| 69 |
update_post_meta( $property_id, 'REAL_HOMES_property_location', $savingx ); |
| 70 |
$property_history .= 'Update Coordinates Meta with ' . $savingx . '</br>'; |
| 71 |
$extra_meta_log .= 'Property with ID ' . $property_id . ' Update Coordinates Meta with ' . $savingx . PHP_EOL; |
| 72 |
} |
| 73 |
|
| 74 |
if ( isset( $property['extra_meta'] ) && is_array( $property['extra_meta'] ) ) { |
| 75 |
$meta_properties = $property['extra_meta']; |
| 76 |
foreach ( $meta_properties as $meta_name => $meta_value ) : |
| 77 |
// check if extra meta is set to import |
| 78 |
if ( ! isset( $permited_meta[ $meta_name ] ) ) { |
| 79 |
// we do not have the extra meta |
| 80 |
continue; |
| 81 |
} elseif ( isset( $permited_meta[ $meta_name ] ) && intval( $permited_meta[ $meta_name ] ) === 0 ) { |
| 82 |
// meta exists but is set to no |
| 83 |
continue; |
| 84 |
} |
| 85 |
|
| 86 |
if ( is_array( $meta_value ) ) { |
| 87 |
$meta_value = implode( ',', $meta_value ); |
| 88 |
} |
| 89 |
$orignal_meta_name = $meta_name; |
| 90 |
|
| 91 |
if( isset( $options['mls-fields-map-postmeta'][ $meta_name ]) && $options['mls-fields-map-postmeta'][ $meta_name ]!=='' ){ |
| 92 |
$new_post_meta_key=$options['mls-fields-map-postmeta'][ $meta_name ]; |
| 93 |
update_post_meta( $property_id, $new_post_meta_key, $meta_value ); |
| 94 |
$property_history .= 'Updated CUSTOM post meta ' . $new_post_meta_key . ' original ' . $meta_name . ' and value ' . $meta_value . '</br>'; |
| 95 |
}else if( isset( $options['mls-fields-map-taxonomy'][ $orignal_meta_name ]) && $options['mls-fields-map-taxonomy'][ $orignal_meta_name ]!=='' ){ |
| 96 |
$new_taxonomy=$options['mls-fields-map-taxonomy'][ $orignal_meta_name ]; |
| 97 |
|
| 98 |
$custom_label=$options['mls-fields-label'][ $orignal_meta_name ]; |
| 99 |
if(!is_array($meta_value)){ |
| 100 |
$meta_value_with_label = array( trim( $custom_label.' '.$meta_value) ) ; |
| 101 |
}else{ |
| 102 |
$meta_value_with_label=array( trim( $custom_label.' '.implode(', ',$meta_value) ) ); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
wp_set_object_terms( $property_id, $meta_value_with_label, $new_taxonomy, true ); |
| 109 |
clean_term_cache( $property_id, $new_taxonomy ); |
| 110 |
|
| 111 |
|
| 112 |
$property_history.= 'Updated CUSTOM TAX: ' . $new_taxonomy . '<-- original '.$orignal_meta_name.'/' . $meta_name .'/'.$custom_label. ' and value ' . json_encode($meta_value_with_label); |
| 113 |
}else{ |
| 114 |
|
| 115 |
|
| 116 |
if ( '' !== $meta_value && |
| 117 |
isset( $options['mls-fields-label'][ $meta_name ] ) && |
| 118 |
'' !== $options['mls-fields-label'][ $meta_name ] && |
| 119 |
isset( $options['mls-fields'][ $meta_name ] ) && |
| 120 |
1 === intval( $options['mls-fields'][ $meta_name ] ) |
| 121 |
) { |
| 122 |
$feature_name = $options['mls-fields-label'][ $meta_name ]; |
| 123 |
if ( '' === $feature_name ) { |
| 124 |
$feature_name = $meta_name; |
| 125 |
} |
| 126 |
|
| 127 |
if ( |
| 128 |
isset( $options['mls-fields-admin'][ $meta_name ] ) && |
| 129 |
0 === intval( $options['mls-fields-admin'][ $meta_name ] ) |
| 130 |
) { |
| 131 |
$extra_fields[ $feature_name ] = $meta_value; |
| 132 |
} elseif ( |
| 133 |
isset( $options['mls-fields-admin'][ $meta_name ] ) && |
| 134 |
1 === intval( $options['mls-fields-admin'][ $meta_name ] ) ) { |
| 135 |
update_post_meta( $property_id, strtolower( $feature_name ), $meta_value ); |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
$property_history .= 'Updated EXTRA Meta ' . $meta_name . ' with label ' . $feature_name . ' and value ' . $meta_value . '</br>'; |
| 142 |
$extra_meta_log .= 'Property with ID ' . $property_id . ' Update EXTRA Meta ' . $meta_name . ' with value ' . $meta_value . PHP_EOL; |
| 143 |
endforeach; |
| 144 |
|
| 145 |
update_post_meta( $property_id, 'REAL_HOMES_additional_details', $extra_fields ); |
| 146 |
update_post_meta( $property_id, 'REAL_HOMES_additional_details_list', $extra_fields ); |
| 147 |
|
| 148 |
$answer['property_history'] = $property_history; |
| 149 |
$answer['extra_meta_log'] = $extra_meta_log; |
| 150 |
} |
| 151 |
|
| 152 |
return $answer; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
/** |
| 160 |
* set hardcode fields after updated |
| 161 |
* |
| 162 |
* @since 1.0.0 |
| 163 |
* @access protected |
| 164 |
* @var string $plugin_name |
| 165 |
*/ |
| 166 |
public function correlationUpdateAfter( $is_insert, $property_id, $global_extra_fields, $new_agent ) { |
| 167 |
if ( 'yes' === $is_insert ) { |
| 168 |
update_post_meta( $property_id, 'REAL_HOMES_featured', 0 ); |
| 169 |
update_post_meta( $property_id, 'REAL_HOMES_agent_display_option', 'agent_info' ); |
| 170 |
|
| 171 |
$options_mls = get_option( 'mlsimport_admin_mls_sync' ); |
| 172 |
// update_post_meta($property_id, 'REAL_HOMES_agents', $options_mls['property_agent']); |
| 173 |
update_post_meta( $property_id, 'REAL_HOMES_agents', $new_agent ); |
| 174 |
|
| 175 |
update_post_meta( $property_id, 'REAL_HOMES_property_map', 0 ); |
| 176 |
update_post_meta( $property_id, 'inspiry_property_label_color', '#fb641c' ); |
| 177 |
|
| 178 |
$fave_property_size_prefix = get_post_meta( $property_id, 'REAL_HOMES_property_size_postfix', true ); |
| 179 |
if ( '' === $fave_property_size_prefix ) { |
| 180 |
update_post_meta( $property_id, 'REAL_HOMES_property_size_postfix', 'Sq Ft' ); |
| 181 |
} |
| 182 |
|
| 183 |
$fave_property_land_postfix = get_post_meta( $property_id, 'REAL_HOMES_property_lot_size_postfix', true ); |
| 184 |
if ( '' === $fave_property_land_postfix ) { |
| 185 |
update_post_meta( $property_id, 'REAL_HOMES_property_lot_size_postfix', 'Sq Ft' ); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
/** |
| 197 |
* save custom fields per environment |
| 198 |
* |
| 199 |
* @since 1.0.0 |
| 200 |
* @access protected |
| 201 |
* @var string $plugin_name |
| 202 |
*/ |
| 203 |
public function enviroment_custom_fields( $option_name ) { |
| 204 |
|
| 205 |
$theme_options = get_option( 'wpresidence_admin' ); |
| 206 |
$custom_fields = $theme_options['wpestate_custom_fields_list']; |
| 207 |
$custom_field_no = 100; |
| 208 |
|
| 209 |
$options = get_option( $option_name . '_admin_fields_select' ); |
| 210 |
|
| 211 |
$custom_fields_admin = array(); |
| 212 |
|
| 213 |
$test = 0; |
| 214 |
foreach ( $options['mls-fields'] as $key => $value ) { |
| 215 |
++$test; |
| 216 |
|
| 217 |
if ( 1 === intval($value) && 0 === intval($options['mls-fields-admin'][ $key ]) ) { |
| 218 |
if (is_array($custom_fields['add_field_name']) && !in_array( $key, $custom_fields['add_field_name'] ) && '' !== $key ) { |
| 219 |
++$custom_field_no; |
| 220 |
$custom_fields['add_field_name'][] = $key; |
| 221 |
$custom_fields['add_field_label'][] = $key; |
| 222 |
$custom_fields['add_field_type'][] = 'short text'; |
| 223 |
$custom_fields['add_field_order'][] = $custom_field_no; |
| 224 |
$custom_fields['add_dropdown_order'][] = ''; |
| 225 |
} |
| 226 |
} elseif ( is_array( $custom_fields['add_field_name'] ) ) { |
| 227 |
// remove item from custom fields |
| 228 |
$key_remove = array_search( $key, $custom_fields['add_field_name'] ); |
| 229 |
|
| 230 |
unset( $custom_fields['add_field_name'][ $key_remove ] ); |
| 231 |
unset( $custom_fields['add_field_label'][ $key_remove ] ); |
| 232 |
unset( $custom_fields['add_field_type'][ $key_remove ] ); |
| 233 |
unset( $custom_fields['add_field_order'][ $key_remove ] ); |
| 234 |
unset( $custom_fields['add_dropdown_order'][ $key_remove ] ); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
$theme_options['wpestate_custom_fields_list'] = $custom_fields; |
| 239 |
update_option( 'wpresidence_admin', $theme_options ); |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
/** |
| 248 |
* return theme schema |
| 249 |
* |
| 250 |
* @since 1.0.0 |
| 251 |
* @access protected |
| 252 |
* @var string $plugin_name |
| 253 |
*/ |
| 254 |
public function return_theme_schema() { |
| 255 |
return; |
| 256 |
} |
| 257 |
} |
| 258 |
|