PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 6.3.4
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v6.3.4
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / enviroment / EstateClass.php

EstateClass.php in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 6.3.4, at enviroment/EstateClass.php

370 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 /**
7 * Description of EstateClass
8 *
9 * @author mlsimport
10 */
11 class EstateClass {
12
13 public function __construct() {
14 }
15
16
17 /**
18 * return custom post field
19 *
20 * @since 1.0.0
21 * @access protected
22 * @var string $plugin_name
23 */
24 public function get_property_post_type() {
25 return 'estate_property';
26 }
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 'estate_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 return;
50 }
51
52 /**
53 * Format extra meta values into a safe string representation.
54 */
55 private function normalizeExtraMetaValue($meta_value) {
56 if (is_array($meta_value)) {
57 $normalized = array();
58
59 foreach ($meta_value as $value) {
60 if (is_array($value)) {
61 $encoded = function_exists('wp_json_encode') ? wp_json_encode($value) : json_encode($value);
62
63 if (false !== $encoded && null !== $encoded) {
64 $normalized[] = $encoded;
65 }
66 } else {
67 $value = trim((string) $value);
68 if ('' !== $value) {
69 $normalized[] = $value;
70 }
71 }
72 }
73
74 if (empty($normalized)) {
75 return '';
76 }
77
78 return implode(', ', $normalized);
79 }
80
81 return preg_replace('/\s*,\s*/', ', ', trim((string) $meta_value));
82 }
83
84 /**
85 * Format Rooms extra meta entries into a single string.
86 */
87 private function formatRoomsExtraMeta($rooms) {
88 if (!is_array($rooms) || empty($rooms)) {
89 return '';
90 }
91
92 $formatted_rooms = array();
93
94 foreach ($rooms as $room_details) {
95 if (!is_array($room_details)) {
96 continue;
97 }
98
99 $room_type = isset($room_details['RoomType']) ? trim((string) $room_details['RoomType']) : '';
100 $room_level = isset($room_details['RoomLevel']) ? trim((string) $room_details['RoomLevel']) : '';
101 $room_length = isset($room_details['RoomLength']) ? trim((string) $room_details['RoomLength']) : '';
102 $room_width = isset($room_details['RoomWidth']) ? trim((string) $room_details['RoomWidth']) : '';
103 $room_units = isset($room_details['RoomLengthWidthUnits']) ? trim((string) $room_details['RoomLengthWidthUnits']) : '';
104
105 if ($room_type === '') {
106 continue;
107 }
108
109 $details = array();
110 if ($room_level !== '') {
111 $details[] = $room_level;
112 }
113
114 $dimension = '';
115 if ($room_length !== '' && $room_width !== '') {
116 $dimension = $room_length . ' x ' . $room_width;
117 } elseif ($room_length !== '') {
118 $dimension = $room_length;
119 } elseif ($room_width !== '') {
120 $dimension = $room_width;
121 }
122
123 if ($dimension !== '') {
124 if ($room_units !== '') {
125 $dimension .= ' ' . $room_units;
126 }
127 $details[] = $dimension;
128 } elseif ($room_units !== '') {
129 $details[] = $room_units;
130 }
131
132 $formatted_value = $room_type;
133 if (!empty($details)) {
134 $formatted_value .= ': ' . implode(', ', $details);
135 }
136
137 $formatted_rooms[] = $formatted_value;
138 }
139
140 return implode(' | ', $formatted_rooms);
141 }
142
143 /**
144 * Deal with extra meta
145 */
146 public function mlsimportSaasSetExtraMeta( $property_id, $property ) {
147 $property_history = '';
148 $extra_meta_log = '';
149 $answer = array();
150 $options = get_option( 'mlsimport_admin_fields_select' );
151 $permited_meta = isset( $options['mls-fields'] ) ? $options['mls-fields'] : array();
152
153 if ( isset( $property['extra_meta'] ) && is_array( $property['extra_meta'] ) ) {
154 $meta_properties = $property['extra_meta'];
155
156 foreach ( $meta_properties as $meta_name => $meta_value ) {
157 if ( ! isset( $permited_meta[ $meta_name ] ) || intval( $permited_meta[ $meta_name ] ) === 0 ) {
158 continue;
159 }
160
161 if ( 'Rooms' === $meta_name && is_array( $meta_value ) ) {
162 $formatted_rooms = $this->formatRoomsExtraMeta( $meta_value );
163 if ( '' !== $formatted_rooms ) {
164 update_post_meta( $property_id, 'rooms', $formatted_rooms );
165 $property_history .= 'Updated EXTRA Meta rooms</br>';
166 $extra_meta_log .= 'Property with ID ' . $property_id . ' Updated EXTRA Meta rooms with value ' . $formatted_rooms . PHP_EOL;
167 }
168 continue;
169 }
170
171 $normalized_value = $this->normalizeExtraMetaValue( $meta_value );
172 $meta_key = strtolower( $meta_name );
173
174 update_post_meta( $property_id, $meta_key, $normalized_value );
175
176 if ( isset( $options['mls-fields-map-postmeta'][ $meta_key ] ) && $options['mls-fields-map-postmeta'][ $meta_key ] !== '' ) {
177 $new_post_meta_key = $options['mls-fields-map-postmeta'][ $meta_key ];
178 update_post_meta( $property_id, $new_post_meta_key, $normalized_value );
179 $property_history .= 'Updated CUSTOM post meta ' . $new_post_meta_key . ' original ' . $meta_key . ' and value ' . $normalized_value . '</br>';
180 }
181
182 $property_history .= 'Updated EXTRA Meta ' . $meta_key . ' with meta_value ' . $normalized_value . '</br>';
183 $extra_meta_log .= 'Property with ID ' . $property_id . ' Updated EXTRA Meta ' . $meta_key . ' with value ' . $normalized_value . PHP_EOL;
184 }
185
186 $answer['property_history'] = $property_history;
187 $answer['extra_meta_log'] = $extra_meta_log;
188 }
189
190 $answer = $this->mlsimport_saas_set_extra_meta_features( $property_id, $property, $answer );
191
192 return $answer;
193 }
194
195 public function mlsimport_saas_set_extra_meta_features( $property_id, $property, $answer ) {
196 $property_history = '';
197 $extra_meta_log = '';
198
199 $feature_list = esc_html( get_option( 'wp_estate_feature_list' ) );
200 $post_id = $property_id;
201
202 if ( isset( $property['meta']['property_features'] ) && is_array( $property['meta']['property_features'] ) ) :
203 foreach ( $property['meta']['property_features'] as $key => $feature_name ) :
204 if ( is_array( $feature_name ) ) {
205 foreach ( $feature_name as $key => $feature_name_from_arr ) {
206 if ( '' === $to_insert ) {
207 $post_var_name = str_replace( ' ', '_', trim( $feature_name_from_arr ) );
208 $input_name = sanitize_title( $post_var_name );
209 $input_name = sanitize_key( $input_name );
210 } else {
211 $input_name = $to_insert;
212 $feature_name = $to_insert;
213 }
214
215 update_post_meta( $post_id, $input_name, 1 );
216 $property_history .= 'Updated Featured ' . $input_name . ' with yes</br>';
217 $extra_meta_log .= 'Property with ID ' . $property_id . ' pdated Featured ' . $input_name . ' with yes' . PHP_EOL;
218
219 if ( false === strpos( $feature_list, $feature_name_from_arr ) && '' !== $feature_name ) {
220 $feature_list .= ',' . $feature_name_from_arr;
221 update_option( 'wp_estate_feature_list', $feature_list );
222 }
223 }
224 } else {
225 if ( '' === $to_insert ) {
226 $post_var_name = str_replace( ' ', '_', trim( $feature_name ) );
227 $input_name = sanitize_title( $post_var_name );
228 $input_name = sanitize_key( $input_name );
229 } else {
230 $post_var_name = str_replace( ' ', '_', trim( $to_insert ) );
231 $input_name = sanitize_title( $post_var_name );
232 $input_name = sanitize_key( $input_name );
233
234 $feature_name = $to_insert;
235 }
236
237 update_post_meta( $post_id, $input_name, 1 );
238 $property_history .= 'Updated Featured ' . $input_name . ' with yes</br>';
239 $extra_meta_log .= 'Property with ID ' . $property_id . ' pdated Featured ' . $input_name . ' with yes' . PHP_EOL;
240
241 if ( false === strpos( $feature_list, $feature_name ) && '' !== $feature_name ) {
242 $feature_list .= ',' . $feature_name;
243 update_option( 'wp_estate_feature_list', $feature_list );
244 }
245 }
246 endforeach;
247 endif;
248
249 $answer['property_history'] = $answer['property_history'] . $property_history;
250 $answer['extra_meta_log'] = $answer['extra_meta_log'] . $extra_meta_log;
251
252 return $answer;
253 }
254
255
256
257
258
259 /**
260 * set hardcode fields after updated
261 *
262 * @since 1.0.0
263 * @access protected
264 * @var string $plugin_name
265 */
266 public function correlationUpdateAfter( $is_insert, $property_id, $global_extra_fields ) {
267 if ( 'yes' === $is_insert ) {
268 update_post_meta( $property_id, 'local_pgpr_slider_type', 'global' );
269 update_post_meta( $property_id, 'local_pgpr_content_type', 'global' );
270 update_post_meta( $property_id, 'prop_featured', 0 );
271 update_post_meta( $property_id, 'page_custom_zoom', 16 );
272 $options_mls = get_option( 'mlsimport_admin_mls_sync' );
273 update_post_meta( $property_id, 'property_agent', $options_mls['property_agent'] );
274
275 update_post_meta( $property_id, 'property_page_desing_local', '' );
276 update_post_meta( $property_id, 'header_transparent', 'global' );
277 update_post_meta( $property_id, 'page_show_adv_search', 'global' );
278 update_post_meta( $property_id, 'page_show_adv_search', 'global' );
279 update_post_meta( $property_id, 'header_type', 0 );
280 update_post_meta( $property_id, 'sidebar_agent_option', 'global' );
281 update_post_meta( $property_id, 'local_pgpr_slider_type', 'global' );
282 update_post_meta( $property_id, 'local_pgpr_content_type', 'global' );
283 update_post_meta( $property_id, 'sidebar_select', 'global' );
284 update_post_meta( $property_id, 'sidebar_option', 'global' );
285 if ( function_exists( 'wpestate_update_hiddent_address_single' ) ) {
286 wpestate_update_hiddent_address_single( $property_id );
287 }
288 }
289 }
290
291
292
293 public function enviroment_image_save_gallery( $property_id, $post_attachments ) {
294
295
296 }
297
298
299 /**
300 * save custom fields per environment
301 *
302 * @since 1.0.0
303 * @access protected
304 * @var string $plugin_name
305 */
306 public function enviroment_custom_fields( $option_name ) {
307
308 $custom_fields = get_option( 'wp_estate_custom_fields', true );
309
310 if ( ! is_array( $custom_fields ) ) {
311 $custom_fields = array();
312 }
313 $custom_field_no = 100;
314 $options = get_option( $option_name . '_admin_fields_select' );
315
316 foreach ( $options['mls-fields'] as $key => $value ) {
317 if ( 1 === intval($value) && 0 === intval( $options['mls-fields-admin'][ $key ]) ) {
318 if ( ! in_array( $key, array_column( $custom_fields, 0 ) ) && '' !== $key ) {
319 ++$custom_field_no;
320 $temp_array = array();
321 $temp_array[0] = $key;
322 $label = isset( $options['mls-fields-label'][ $key ] ) && '' !== $options['mls-fields-label'][ $key ] ? $options['mls-fields-label'][ $key ] : $key;
323 $temp_array[1] = $label;
324
325 $temp_array[2] = 'short text';
326 $temp_array[3] = $custom_field_no;
327 $custom_fields[] = $temp_array;
328 } else {
329 $to_replace_key = array_search( $key, array_column( $custom_fields, 0 ) );
330 $label = isset( $options['mls-fields-label'][ $key ] ) && '' !== $options['mls-fields-label'][ $key ] ? $options['mls-fields-label'][ $key ] : $key;
331 $custom_fields[ $to_replace_key ]['1'] = $label;
332 }
333 } else {
334 // remove item from custom fields
335 $key_remove = $this->searchForId( $key, $custom_fields );
336
337 if ( intval( $key_remove ) > 0 ) {
338 unset( $custom_fields[ $key_remove ] );
339 }
340 }
341 }
342
343 update_option( 'wp_estate_custom_fields', $custom_fields );
344 }
345
346
347 public function searchForId( $id, $array ) {
348 foreach ( $array as $key => $val ) {
349 if ( $val[0] === $id ) {
350 return $key;
351 }
352 }
353 return null;
354 }
355
356
357
358 /**
359 * return theme schema
360 *
361 * @since 1.0.0
362 * @access protected
363 * @var string $plugin_name
364 */
365 public function return_theme_schema() {
366
367 return;
368 }
369 }
370