PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 6.0.4
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v6.0.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.0.4, at enviroment/EstateClass.php

271 lines 8.7 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 * Deal with extra meta
54 */
55 public function mlsimportSaasSetExtraMeta( $property_id, $property ) {
56 $property_history = '';
57 $extra_meta_log = '';
58 $answer = array();
59 $options = get_option( 'mlsimport_admin_fields_select' );
60 $permited_meta = $options['mls-fields'];
61
62 if ( isset( $property['extra_meta'] ) && is_array( $property['extra_meta'] ) ) {
63 $meta_properties = $property['extra_meta'];
64 foreach ( $meta_properties as $meta_name => $meta_value ) :
65 // check if extra meta is set to import
66 if ( ! isset( $permited_meta[ $meta_name ] ) ) {
67 // we do not have the extra meta
68 continue;
69 } elseif ( isset( $permited_meta[ $meta_name ] ) && intval( $permited_meta[ $meta_name ] ) === 0 ) {
70 // meta exists but is set to no
71 continue;
72 }
73
74 $meta_name = strtolower( $meta_name );
75 if ( is_array( $meta_value ) ) {
76 $meta_value = implode( ',', $meta_value );
77 }
78 update_post_meta( $property_id, $meta_name, $meta_value );
79
80 if( isset( $options['mls-fields-map-postmeta'][ $meta_name ]) && $options['mls-fields-map-postmeta'][ $meta_name ]!=='' ){
81 $new_post_meta_key=$options['mls-fields-map-postmeta'][ $meta_name ];
82 update_post_meta( $property_id, $new_post_meta_key, $meta_value );
83 $property_history .= 'Updated CUSTOM post meta ' . $new_post_meta_key . ' original ' . $meta_name . ' and value ' . $meta_value . '</br>';
84 }
85
86
87 $property_history .= 'Updated EXTRA Meta ' . $meta_name . ' with meta_value ' . $meta_value . '</br>';
88 $extra_meta_log .= 'Property with ID ' . $property_id . ' Updated EXTRA Meta ' . $meta_name . ' with value ' . $meta_value . PHP_EOL;
89 endforeach;
90
91 $answer['property_history'] = $property_history;
92 $answer['extra_meta_log'] = $extra_meta_log;
93 }
94
95 $answer = $this->mlsimport_saas_set_extra_meta_features( $property_id, $property, $answer );
96
97 return $answer;
98 }
99
100 public function mlsimport_saas_set_extra_meta_features( $property_id, $property, $answer ) {
101 $property_history = '';
102 $extra_meta_log = '';
103
104 $feature_list = esc_html( get_option( 'wp_estate_feature_list' ) );
105 $post_id = $property_id;
106
107 if ( isset( $property['meta']['property_features'] ) && is_array( $property['meta']['property_features'] ) ) :
108 foreach ( $property['meta']['property_features'] as $key => $feature_name ) :
109 if ( is_array( $feature_name ) ) {
110 foreach ( $feature_name as $key => $feature_name_from_arr ) {
111 if ( '' === $to_insert ) {
112 $post_var_name = str_replace( ' ', '_', trim( $feature_name_from_arr ) );
113 $input_name = sanitize_title( $post_var_name );
114 $input_name = sanitize_key( $input_name );
115 } else {
116 $input_name = $to_insert;
117 $feature_name = $to_insert;
118 }
119
120 update_post_meta( $post_id, $input_name, 1 );
121 $property_history .= 'Updated Featured ' . $input_name . ' with yes</br>';
122 $extra_meta_log .= 'Property with ID ' . $property_id . ' pdated Featured ' . $input_name . ' with yes' . PHP_EOL;
123
124 if ( false === strpos( $feature_list, $feature_name_from_arr ) && '' !== $feature_name ) {
125 $feature_list .= ',' . $feature_name_from_arr;
126 update_option( 'wp_estate_feature_list', $feature_list );
127 }
128 }
129 } else {
130 if ( '' === $to_insert ) {
131 $post_var_name = str_replace( ' ', '_', trim( $feature_name ) );
132 $input_name = sanitize_title( $post_var_name );
133 $input_name = sanitize_key( $input_name );
134 } else {
135 $post_var_name = str_replace( ' ', '_', trim( $to_insert ) );
136 $input_name = sanitize_title( $post_var_name );
137 $input_name = sanitize_key( $input_name );
138
139 $feature_name = $to_insert;
140 }
141
142 update_post_meta( $post_id, $input_name, 1 );
143 $property_history .= 'Updated Featured ' . $input_name . ' with yes</br>';
144 $extra_meta_log .= 'Property with ID ' . $property_id . ' pdated Featured ' . $input_name . ' with yes' . PHP_EOL;
145
146 if ( false === strpos( $feature_list, $feature_name ) && '' !== $feature_name ) {
147 $feature_list .= ',' . $feature_name;
148 update_option( 'wp_estate_feature_list', $feature_list );
149 }
150 }
151 endforeach;
152 endif;
153
154 $answer['property_history'] = $answer['property_history'] . $property_history;
155 $answer['extra_meta_log'] = $answer['extra_meta_log'] . $extra_meta_log;
156
157 return $answer;
158 }
159
160
161
162
163
164 /**
165 * set hardcode fields after updated
166 *
167 * @since 1.0.0
168 * @access protected
169 * @var string $plugin_name
170 */
171 public function correlationUpdateAfter( $is_insert, $property_id, $global_extra_fields ) {
172 if ( 'yes' === $is_insert ) {
173 update_post_meta( $property_id, 'local_pgpr_slider_type', 'global' );
174 update_post_meta( $property_id, 'local_pgpr_content_type', 'global' );
175 update_post_meta( $property_id, 'prop_featured', 0 );
176 update_post_meta( $property_id, 'page_custom_zoom', 16 );
177 $options_mls = get_option( 'mlsimport_admin_mls_sync' );
178 update_post_meta( $property_id, 'property_agent', $options_mls['property_agent'] );
179
180 update_post_meta( $property_id, 'property_page_desing_local', '' );
181 update_post_meta( $property_id, 'header_transparent', 'global' );
182 update_post_meta( $property_id, 'page_show_adv_search', 'global' );
183 update_post_meta( $property_id, 'page_show_adv_search', 'global' );
184 update_post_meta( $property_id, 'header_type', 0 );
185 update_post_meta( $property_id, 'sidebar_agent_option', 'global' );
186 update_post_meta( $property_id, 'local_pgpr_slider_type', 'global' );
187 update_post_meta( $property_id, 'local_pgpr_content_type', 'global' );
188 update_post_meta( $property_id, 'sidebar_select', 'global' );
189 update_post_meta( $property_id, 'sidebar_option', 'global' );
190 if ( function_exists( 'wpestate_update_hiddent_address_single' ) ) {
191 wpestate_update_hiddent_address_single( $property_id );
192 }
193 }
194 }
195
196
197
198
199
200 /**
201 * save custom fields per environment
202 *
203 * @since 1.0.0
204 * @access protected
205 * @var string $plugin_name
206 */
207 public function enviroment_custom_fields( $option_name ) {
208
209 $custom_fields = get_option( 'wp_estate_custom_fields', true );
210
211 if ( ! is_array( $custom_fields ) ) {
212 $custom_fields = array();
213 }
214 $custom_field_no = 100;
215 $options = get_option( $option_name . '_admin_fields_select' );
216
217 foreach ( $options['mls-fields'] as $key => $value ) {
218 if ( 1 === intval($value) && 0 === intval( $options['mls-fields-admin'][ $key ]) ) {
219 if ( ! in_array( $key, array_column( $custom_fields, 0 ) ) && '' !== $key ) {
220 ++$custom_field_no;
221 $temp_array = array();
222 $temp_array[0] = $key;
223 $label = isset( $options['mls-fields-label'][ $key ] ) && '' !== $options['mls-fields-label'][ $key ] ? $options['mls-fields-label'][ $key ] : $key;
224 $temp_array[1] = $label;
225
226 $temp_array[2] = 'short text';
227 $temp_array[3] = $custom_field_no;
228 $custom_fields[] = $temp_array;
229 } else {
230 $to_replace_key = array_search( $key, array_column( $custom_fields, 0 ) );
231 $label = isset( $options['mls-fields-label'][ $key ] ) && '' !== $options['mls-fields-label'][ $key ] ? $options['mls-fields-label'][ $key ] : $key;
232 $custom_fields[ $to_replace_key ]['1'] = $label;
233 }
234 } else {
235 // remove item from custom fields
236 $key_remove = $this->searchForId( $key, $custom_fields );
237
238 if ( intval( $key_remove ) > 0 ) {
239 unset( $custom_fields[ $key_remove ] );
240 }
241 }
242 }
243
244 update_option( 'wp_estate_custom_fields', $custom_fields );
245 }
246
247
248 public function searchForId( $id, $array ) {
249 foreach ( $array as $key => $val ) {
250 if ( $val[0] === $id ) {
251 return $key;
252 }
253 }
254 return null;
255 }
256
257
258
259 /**
260 * return theme schema
261 *
262 * @since 1.0.0
263 * @access protected
264 * @var string $plugin_name
265 */
266 public function return_theme_schema() {
267
268 return;
269 }
270 }
271