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