| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
$theme_schema= mlsimport_hardocde_theme_schema(); |
| 6 |
|
| 7 |
$options = get_option( 'mlsimport_admin_options' ); |
| 8 |
$mlsimport_mls_metadata_populated = get_option( 'mlsimport_mls_metadata_populated', '' ); |
| 9 |
$permited_tags = mlsimport_allowed_html_tags_content(); |
| 10 |
$post_type = ''; |
| 11 |
if (method_exists($this->env_data, 'get_property_post_type')) { |
| 12 |
$post_type = $this->env_data->get_property_post_type(); |
| 13 |
} |
| 14 |
|
| 15 |
$available_taxonomies = mlsimport_get_custom_post_type_taxonomies($post_type); |
| 16 |
|
| 17 |
|
| 18 |
global $mlsimport; |
| 19 |
$token = $mlsimport->admin->mlsimport_saas_get_mls_api_token_from_transient(); |
| 20 |
$is_mls_connected = get_option('mlsimport_connection_test', ''); |
| 21 |
$mlsimport->admin->mlsimport_saas_setting_up(); |
| 22 |
|
| 23 |
if ('yes' !== $is_mls_connected) { |
| 24 |
$mlsimport->admin->mlsimport_saas_check_mls_connection(); |
| 25 |
$is_mls_connected = get_option('mlsimport_connection_test', ''); |
| 26 |
} |
| 27 |
|
| 28 |
if (trim($token) === '') { |
| 29 |
echo '<div class="mlsimport_warning">' . esc_html__('You are not connected to MlsImport - Please check your Username and Password.', 'mlsimport') . '</div>'; |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
if ('yes' !== $is_mls_connected) { |
| 34 |
echo '<div class="mlsimport_warning">' . esc_html__('The connection to your MLS was NOT succesful. Please check the authentication token is correct and check your MLS Data Access Application is approved.', 'mlsimport') . '</div>'; |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
if ( 'yes' === $mlsimport_mls_metadata_populated ) { |
| 39 |
// We have MLS metadata, so we can show the field selection interface |
| 40 |
?> |
| 41 |
<form method="post" class= "mlsimport-import-fields-form" name="cleanup_options" action="options.php"> |
| 42 |
<?php |
| 43 |
|
| 44 |
|
| 45 |
global $mlsimport; |
| 46 |
$mlsimport->admin->mlsimport_saas_setting_up(); |
| 47 |
|
| 48 |
|
| 49 |
// Add this to the beginning of the form processing |
| 50 |
$options = get_option('mlsimport_admin_fields_select', array()); |
| 51 |
|
| 52 |
|
| 53 |
// Ensure all arrays are initialized |
| 54 |
if (!is_array($options) || |
| 55 |
(is_array($options) && empty($options)) ) { |
| 56 |
|
| 57 |
$mlsimport_mls_metadata_mls_data = get_option( 'mlsimport_mls_metadata_mls_data', '' ); |
| 58 |
$metadata_api_call_data_service_property = json_decode( $mlsimport_mls_metadata_mls_data, true ); |
| 59 |
$options = array(); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
if (!isset($options['mls-fields'])) { |
| 64 |
$options['mls-fields'] = array(); |
| 65 |
} |
| 66 |
|
| 67 |
if (!isset($options['mls-fields-admin'])) { |
| 68 |
$options['mls-fields-admin'] = array(); |
| 69 |
} |
| 70 |
|
| 71 |
if (!isset($options['mls-fields-label'])) { |
| 72 |
$options['mls-fields-label'] = array(); |
| 73 |
} |
| 74 |
|
| 75 |
if (!isset($options['mls-fields-map-postmeta'])) { |
| 76 |
$options['mls-fields-map-postmeta'] = array(); |
| 77 |
} |
| 78 |
|
| 79 |
if (!isset($options['mls-fields-map-taxonomy'])) { |
| 80 |
$options['mls-fields-map-taxonomy'] = array(); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
$order_item=0; |
| 85 |
if (!is_array($metadata_api_call_data_service_property)) { |
| 86 |
$metadata_api_call_data_service_property = []; |
| 87 |
} |
| 88 |
|
| 89 |
ksort($metadata_api_call_data_service_property); |
| 90 |
|
| 91 |
foreach ( $metadata_api_call_data_service_property as $key => $value ) { |
| 92 |
$description = 'no description '; |
| 93 |
|
| 94 |
$options['mls-fields'][ $key ]=0; |
| 95 |
$options['field_order'][ $key ]=$order_item++; |
| 96 |
$options['mls-fields-admin'][ $key ]=0 ; |
| 97 |
$options['mls-fields-map-postmeta'][ $key ]=''; |
| 98 |
|
| 99 |
$options['mls-fields-label'][ $key ]=''; |
| 100 |
|
| 101 |
if ( array_key_exists( $key, $theme_schema ) ) { |
| 102 |
$options['mls-fields'][ $key ]=1; |
| 103 |
|
| 104 |
if( isset( $theme_schema[$key]['type']) && $theme_schema[$key]['type']=='taxonomy' ){ |
| 105 |
$options['mls-fields-map-taxonomy'][ $key ]=$theme_schema[$key]['name']; |
| 106 |
}else{ |
| 107 |
$options['mls-fields-map-taxonomy'][ $key ]=''; |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
?> |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
<h3><?php esc_html_e( 'Select the extra fields you want to import', 'mlsimport' ); ?>:</h3> |
| 121 |
|
| 122 |
<?php |
| 123 |
|
| 124 |
|
| 125 |
// $options = get_option( 'mlsimport_admin_fields_select', array() ); |
| 126 |
// print_r($options); |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
// Get the current page and search parameters |
| 131 |
$current_page = isset( $_GET['mlsimport_page'] ) ? intval( $_GET['mlsimport_page'] ) : 1; |
| 132 |
$search_term = isset( $_GET['mlsimport_search'] ) ? sanitize_text_field( $_GET['mlsimport_search'] ) : ''; |
| 133 |
$import_filter = isset( $_GET['mlsimport_filter'] ) ? sanitize_text_field( $_GET['mlsimport_filter'] ) : 'all'; |
| 134 |
$alpha_filter = isset( $_GET['mlsimport_alpha'] ) ? sanitize_text_field( $_GET['mlsimport_alpha'] ) : ''; |
| 135 |
|
| 136 |
// Set up render parameters |
| 137 |
$render_params = array( |
| 138 |
'page' => $current_page, |
| 139 |
'fields_per_page' => 99999, // Adjust as needed |
| 140 |
'search_term' => $search_term, |
| 141 |
'import_filter' => $import_filter, |
| 142 |
'alpha_filter' => $alpha_filter, |
| 143 |
'show_pagination' => true, |
| 144 |
'show_filters' => true, |
| 145 |
'show_stats' => true, |
| 146 |
'enable_drag_drop' => true, |
| 147 |
'form_action' => 'options.php', |
| 148 |
'form_method' => 'post', |
| 149 |
'form_name' => 'cleanup_options', |
| 150 |
'nonce_field' => 'mlsimport_admin_fields_select', |
| 151 |
'plugin_name' => 'mlsimport', |
| 152 |
); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
// Then in the admin page, update the function call: |
| 162 |
echo render_mls_field_selection_interface( |
| 163 |
$options, |
| 164 |
$options, |
| 165 |
$render_params, |
| 166 |
$theme_schema |
| 167 |
); |
| 168 |
?> |
| 169 |
|
| 170 |
<input type="hidden" name="mlsimport_admin_fields_select[mls-fields-admin][force_rand]" value="<?php echo esc_attr( wp_rand() ); ?>"> |
| 171 |
|
| 172 |
|
| 173 |
<?php mlsimport_add_field_selector_nonce(); ?> |
| 174 |
</form> |
| 175 |
<?php |
| 176 |
} else { |
| 177 |
// We don't have MLS metadata yet, show waiting message |
| 178 |
global $mlsimport; |
| 179 |
$token = $mlsimport->admin->mlsimport_saas_get_mls_api_token_from_transient(); |
| 180 |
if ( trim( $token ) !== '' ) { |
| 181 |
?> |
| 182 |
<div class="mlsimport_warning mlsimport_validated"> |
| 183 |
<?php |
| 184 |
esc_html_e( 'We need to gather some information about your MLS. Please Stand By! ', 'mlsimport' ); |
| 185 |
?> |
| 186 |
</div> |
| 187 |
<?php |
| 188 |
} else { |
| 189 |
esc_html_e( 'You are not connected to MLS Import', 'mlsimport' ); |
| 190 |
} |
| 191 |
} |
| 192 |
?> |
| 193 |
<input type="hidden" id="mlsimport_saas_get_metadata" value="<?php echo esc_attr( wp_create_nonce( "mlsimport_saas_get_metadata" ) ); ?>" /> |