| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for the Field Mapping step of the MLSImport onboarding wizard |
| 4 |
* |
| 5 |
* @link https://mlsimport.com/ |
| 6 |
* @since 6.1.0 |
| 7 |
* |
| 8 |
* @package Mlsimport |
| 9 |
* @subpackage Mlsimport/admin/partials/mlsimport-onboarding-steps |
| 10 |
*/ |
| 11 |
|
| 12 |
// If this file is called directly, abort. |
| 13 |
if (!defined('WPINC')) { |
| 14 |
die; |
| 15 |
} |
| 16 |
// Get post type |
| 17 |
$post_type = ''; |
| 18 |
global $mlsimport; |
| 19 |
if (method_exists($mlsimport->admin->env_data, 'get_property_post_type')) { |
| 20 |
$post_type = $mlsimport->admin->env_data->get_property_post_type(); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
// Get saved data |
| 25 |
$field_data = mlsimport_get_onboarding_step_data('field-mapping'); |
| 26 |
|
| 27 |
// Set default values |
| 28 |
$template = isset($field_data['template']) ? $field_data['template'] : 'standard'; |
| 29 |
$custom_fields = isset($field_data['custom_fields']) ? $field_data['custom_fields'] : array(); |
| 30 |
|
| 31 |
// Get MLS metadata from API |
| 32 |
$mlsimport_mls_metadata_mls_data = get_option('mlsimport_mls_metadata_mls_data', ''); |
| 33 |
$mlsimport_mls_metadata_theme_schema = get_option('mlsimport_mls_metadata_theme_schema', ''); |
| 34 |
// Get taxonomies |
| 35 |
$available_taxonomies = mlsimport_get_custom_post_type_taxonomies($post_type); |
| 36 |
|
| 37 |
$mlsimport_mls_metadata_populated = get_option( 'mlsimport_mls_metadata_populated', '' ); |
| 38 |
|
| 39 |
// Parse metadata |
| 40 |
$mls_data = is_string($mlsimport_mls_metadata_mls_data) ? json_decode($mlsimport_mls_metadata_mls_data, true) : $mlsimport_mls_metadata_mls_data; |
| 41 |
$theme_schema= mlsimport_hardocde_theme_schema(); |
| 42 |
// Define template options |
| 43 |
$template_options = array( |
| 44 |
'essential' => array( |
| 45 |
'title' => __('Essential', 'mlsimport'), |
| 46 |
'description' => __('Import only the most essential fields needed for a basic property listing.', 'mlsimport'), |
| 47 |
'field_count' => 15, |
| 48 |
), |
| 49 |
'standard' => array( |
| 50 |
'title' => __('Standard', 'mlsimport'), |
| 51 |
'description' => __('A balanced selection of fields suitable for most real estate websites.', 'mlsimport'), |
| 52 |
'field_count' => 30, |
| 53 |
), |
| 54 |
'complete' => array( |
| 55 |
'title' => __('Complete', 'mlsimport'), |
| 56 |
'description' => __('Import all available fields for the most comprehensive property listings.', 'mlsimport'), |
| 57 |
'field_count' => is_array($mls_data) ? count($mls_data) : '700+', |
| 58 |
), |
| 59 |
); |
| 60 |
|
| 61 |
// Get the current theme to provide tailored advice |
| 62 |
$current_theme = wp_get_theme(); |
| 63 |
$theme_name = $current_theme->get('Name'); |
| 64 |
|
| 65 |
// Detect supported theme |
| 66 |
$supported_themes = array( |
| 67 |
'WpResidence' => 'WP Residence', |
| 68 |
'houzez' => 'Houzez', |
| 69 |
'RealHomes' => 'Real Homes', |
| 70 |
'Wpestate' => 'WP Estate', |
| 71 |
); |
| 72 |
|
| 73 |
$detected_theme = 'your theme'; |
| 74 |
foreach ($supported_themes as $theme_key => $theme_label) { |
| 75 |
if (strtolower($theme_name) === strtolower($theme_key) || strpos(strtolower($theme_name), strtolower($theme_key)) !== false) { |
| 76 |
$detected_theme = $theme_label; |
| 77 |
break; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
if ( 'yes' === $mlsimport_mls_metadata_populated ) { |
| 84 |
?> |
| 85 |
<form method="post" name="cleanup_options" action="options.php"> |
| 86 |
<?php |
| 87 |
// We have MLS metadata, so we can show the field selection interface |
| 88 |
?> |
| 89 |
|
| 90 |
<?php |
| 91 |
settings_fields( 'mlsimport_admin_fields_select' ); |
| 92 |
do_settings_sections( 'mlsimport_admin_fields_select' ); |
| 93 |
|
| 94 |
global $mlsimport; |
| 95 |
$mlsimport->admin->mlsimport_saas_setting_up(); |
| 96 |
|
| 97 |
|
| 98 |
// Add this to the beginning of the form processing |
| 99 |
$options = get_option('mlsimport_admin_fields_select', array()); |
| 100 |
|
| 101 |
|
| 102 |
// Ensure all arrays are initialized |
| 103 |
if (!is_array($options) || |
| 104 |
(is_array($options) && empty($options)) ) { |
| 105 |
|
| 106 |
$mlsimport_mls_metadata_mls_data = get_option( 'mlsimport_mls_metadata_mls_data', '' ); |
| 107 |
$metadata_api_call_data_service_property = json_decode( $mlsimport_mls_metadata_mls_data, true ); |
| 108 |
$options = array(); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
if (!isset($options['mls-fields'])) { |
| 113 |
$options['mls-fields'] = array(); |
| 114 |
} |
| 115 |
|
| 116 |
if (!isset($options['mls-fields-admin'])) { |
| 117 |
$options['mls-fields-admin'] = array(); |
| 118 |
} |
| 119 |
|
| 120 |
if (!isset($options['mls-fields-label'])) { |
| 121 |
$options['mls-fields-label'] = array(); |
| 122 |
} |
| 123 |
|
| 124 |
if (!isset($options['mls-fields-map-postmeta'])) { |
| 125 |
$options['mls-fields-map-postmeta'] = array(); |
| 126 |
} |
| 127 |
|
| 128 |
if (!isset($options['mls-fields-map-taxonomy'])) { |
| 129 |
$options['mls-fields-map-taxonomy'] = array(); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
$order_item=0; |
| 134 |
if (!is_array($metadata_api_call_data_service_property)) { |
| 135 |
$metadata_api_call_data_service_property = []; |
| 136 |
} |
| 137 |
ksort($metadata_api_call_data_service_property); |
| 138 |
|
| 139 |
foreach ( $metadata_api_call_data_service_property as $key => $value ) { |
| 140 |
$description = 'no description '; |
| 141 |
|
| 142 |
$options['mls-fields'][ $key ]=0; |
| 143 |
$options['field_order'][ $key ]=$order_item++; |
| 144 |
$options['mls-fields-admin'][ $key ]=0 ; |
| 145 |
$options['mls-fields-map-postmeta'][ $key ]=''; |
| 146 |
|
| 147 |
$options['mls-fields-label'][ $key ]=''; |
| 148 |
|
| 149 |
if ( array_key_exists( $key, $theme_schema ) ) { |
| 150 |
$options['mls-fields'][ $key ]=1; |
| 151 |
|
| 152 |
if( isset( $theme_schema[$key]['type']) && $theme_schema[$key]['type']=='taxonomy' ){ |
| 153 |
$options['mls-fields-map-taxonomy'][ $key ]=$theme_schema[$key]['name']; |
| 154 |
}else{ |
| 155 |
$options['mls-fields-map-taxonomy'][ $key ]=''; |
| 156 |
} |
| 157 |
|
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
// Set up render parameters |
| 169 |
$render_params = array( |
| 170 |
'page' => 1, |
| 171 |
'fields_per_page' => 15, // Show limited fields for onboarding |
| 172 |
'search_term' => '', |
| 173 |
'import_filter' => 'selected', // Show selected fields by default |
| 174 |
'alpha_filter' => '', |
| 175 |
'show_pagination' => true, |
| 176 |
'show_filters' => true, |
| 177 |
'show_stats' => true, |
| 178 |
'enable_drag_drop' => true, |
| 179 |
'form_action' => 'options.php', |
| 180 |
'form_method' => 'post', |
| 181 |
'form_name' => 'mlsimport_onboarding_form', |
| 182 |
'nonce_field' => 'mlsimport_admin_fields_select', |
| 183 |
'plugin_name' => 'mlsimport', |
| 184 |
); |
| 185 |
|
| 186 |
?> |
| 187 |
|
| 188 |
<div class="mlsimport-field-mapping-content"> |
| 189 |
<div class="mlsimport-section"> |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
<div class="mlsimport-section-inner"> |
| 194 |
<button type="submit" class="button button-primary mlsimport-wizard-next mlsimport_button "> |
| 195 |
<?php _e('Continue', 'mlsimport'); ?> |
| 196 |
</button> |
| 197 |
|
| 198 |
<form method="post" name="mlsimport_onboarding_form" action="options.php"> |
| 199 |
<?php |
| 200 |
settings_fields('mlsimport_admin_fields_select'); |
| 201 |
do_settings_sections('mlsimport_admin_fields_select'); |
| 202 |
|
| 203 |
// Add hidden field for template selection |
| 204 |
echo '<input type="hidden" id="selected_template" name="selected_template" value="' . esc_attr($template) . '">'; |
| 205 |
|
| 206 |
// Call the render function from admin |
| 207 |
if (function_exists('render_mls_field_selection_interface')) { |
| 208 |
echo render_mls_field_selection_interface( |
| 209 |
$options, |
| 210 |
$options, |
| 211 |
$render_params, |
| 212 |
$theme_schema |
| 213 |
); |
| 214 |
} |
| 215 |
|
| 216 |
// Add nonce field |
| 217 |
mlsimport_add_field_selector_nonce(); |
| 218 |
?> |
| 219 |
<input type="hidden" name="mlsimport_admin_fields_select[mls-fields-admin][force_rand]" value="<?php echo esc_attr(wp_rand()); ?>"> |
| 220 |
</form> |
| 221 |
|
| 222 |
<p class="mlsimport-field-note"> |
| 223 |
<?php _e('You can always refine these field mappings later in MLS Import settings.', 'mlsimport'); ?> |
| 224 |
</p> |
| 225 |
</div> |
| 226 |
</div> |
| 227 |
|
| 228 |
</div> |
| 229 |
|
| 230 |
</form> |
| 231 |
<?php |
| 232 |
} else { |
| 233 |
// We don't have MLS metadata yet, show waiting message |
| 234 |
global $mlsimport; |
| 235 |
$token = $mlsimport->admin->mlsimport_saas_get_mls_api_token_from_transient(); |
| 236 |
if ( trim( $token ) !== '' ) { |
| 237 |
?> |
| 238 |
<div class="mlsimport_populate_warning"> |
| 239 |
<?php |
| 240 |
esc_html_e( 'We need to gather some information about your MLS. Please Stand By! ', 'mlsimport' ); |
| 241 |
?> |
| 242 |
</div> |
| 243 |
<?php |
| 244 |
} else { |
| 245 |
esc_html_e( 'You are not connected to MLS Import', 'mlsimport' ); |
| 246 |
} |
| 247 |
?> |
| 248 |
<input type="hidden" id="mlsimport_saas_get_metadata" value="<?php echo esc_attr( wp_create_nonce( "mlsimport_saas_get_metadata" ) ); ?>" /> |
| 249 |
<?php |
| 250 |
} |
| 251 |
?> |
| 252 |
<script> |
| 253 |
jQuery(document).ready(function(jQuery) { |
| 254 |
jQuery('.mlsimport-wizard-content-field-mapping .mlsimport-wizard-next').on('click', function(e) { |
| 255 |
e.preventDefault(); |
| 256 |
window.location.href = ajaxurl.replace('admin-ajax.php', 'admin.php') + '?page=mlsimport-onboarding&step=import-config'; |
| 257 |
}); |
| 258 |
}); |
| 259 |
</script> |
| 260 |
|
| 261 |
<style> |
| 262 |
.mlsimport-field-mapping-content { |
| 263 |
max-width: 100%; |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
.mlsimport-section-inner { |
| 269 |
margin-bottom: 40px; |
| 270 |
} |
| 271 |
|
| 272 |
.mlsimport-section-inner h3 { |
| 273 |
margin-top: 0; |
| 274 |
border-bottom: 1px solid #f0f0f0; |
| 275 |
padding-bottom: 10px; |
| 276 |
margin-bottom: 15px; |
| 277 |
} |
| 278 |
|
| 279 |
.mlsimport-template-header { |
| 280 |
display: flex; |
| 281 |
justify-content: space-between; |
| 282 |
align-items: center; |
| 283 |
margin-bottom: 10px; |
| 284 |
} |
| 285 |
|
| 286 |
.mlsimport-template-title { |
| 287 |
margin: 0; |
| 288 |
font-size: 16px; |
| 289 |
} |
| 290 |
|
| 291 |
.mlsimport-template-description { |
| 292 |
margin: 0 0 15px 0; |
| 293 |
font-size: 13px; |
| 294 |
color: #666; |
| 295 |
min-height: 40px; |
| 296 |
} |
| 297 |
|
| 298 |
.mlsimport-template-detail { |
| 299 |
font-size: 12px; |
| 300 |
color: #666; |
| 301 |
padding-top: 10px; |
| 302 |
border-top: 1px solid #eee; |
| 303 |
} |
| 304 |
|
| 305 |
.mlsimport-template-field-count { |
| 306 |
font-weight: 600; |
| 307 |
} |
| 308 |
|
| 309 |
.mlsimport-field-note { |
| 310 |
font-style: italic; |
| 311 |
color: #666; |
| 312 |
margin-top: 15px; |
| 313 |
} |
| 314 |
|
| 315 |
/* Tips section */ |
| 316 |
.mlsimport-mapping-tips { |
| 317 |
background-color: #f9f9f9; |
| 318 |
border-left: 4px solid #00a0d2; |
| 319 |
padding: 15px; |
| 320 |
margin-top: 20px; |
| 321 |
} |
| 322 |
|
| 323 |
.mlsimport-mapping-tips h3 { |
| 324 |
margin-top: 0; |
| 325 |
margin-bottom: 10px; |
| 326 |
font-size: 15px; |
| 327 |
} |
| 328 |
|
| 329 |
.mlsimport-mapping-tips ul { |
| 330 |
margin-top: 10px; |
| 331 |
margin-left: 20px; |
| 332 |
} |
| 333 |
|
| 334 |
.mlsimport-mapping-tips li { |
| 335 |
margin-bottom: 8px; |
| 336 |
} |
| 337 |
|
| 338 |
</style> |