| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template for the Test Import 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 |
|
| 17 |
// Get saved data |
| 18 |
$user_data = get_option('mlsimport_onboarding_user_data', array()); |
| 19 |
$import_id = isset($user_data['import_id']) ? $user_data['import_id'] : 0; |
| 20 |
|
| 21 |
// Get import status |
| 22 |
$spawn_status = ''; |
| 23 |
if ($import_id) { |
| 24 |
$spawn_status = get_post_meta($import_id, 'mlsimport_spawn_status', true); |
| 25 |
} |
| 26 |
|
| 27 |
// Check if test has been run |
| 28 |
$test_completed = false; |
| 29 |
if ($import_id) { |
| 30 |
global $mlsimport; |
| 31 |
$post_type = $mlsimport->admin->env_data->get_property_post_type(); |
| 32 |
|
| 33 |
$args = array( |
| 34 |
'post_type' => $post_type, |
| 35 |
'post_status' => 'any', |
| 36 |
'posts_per_page' => -1, |
| 37 |
'meta_query' => array( |
| 38 |
array( |
| 39 |
'key' => 'MLSimport_item_inserted', |
| 40 |
'value' => $import_id, |
| 41 |
'compare' => '=', |
| 42 |
), |
| 43 |
), |
| 44 |
); |
| 45 |
|
| 46 |
$query = new WP_Query($args); |
| 47 |
$test_completed = $query->found_posts > 0; |
| 48 |
$imported_count = $query->found_posts; |
| 49 |
wp_reset_postdata(); |
| 50 |
} |
| 51 |
|
| 52 |
// Get the current theme to provide tailored advice |
| 53 |
$current_theme = wp_get_theme(); |
| 54 |
$theme_name = $current_theme->get('Name'); |
| 55 |
|
| 56 |
// Detect supported theme |
| 57 |
$supported_themes = array( |
| 58 |
'WpResidence' => 'WP Residence', |
| 59 |
'houzez' => 'Houzez', |
| 60 |
'RealHomes' => 'Real Homes', |
| 61 |
'Wpestate' => 'WP Estate', |
| 62 |
); |
| 63 |
|
| 64 |
$detected_theme = 'your theme'; |
| 65 |
foreach ($supported_themes as $theme_key => $theme_label) { |
| 66 |
if (strtolower($theme_name) === strtolower($theme_key) || strpos(strtolower($theme_name), strtolower($theme_key)) !== false) { |
| 67 |
$detected_theme = $theme_label; |
| 68 |
break; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
// Get log file content if it exists |
| 73 |
$log_content = ''; |
| 74 |
$log_path = WP_PLUGIN_DIR . '/mlsimport/logs/import_logs-' . date('Y-m-d') . '.log'; |
| 75 |
if (file_exists($log_path)) { |
| 76 |
$log_content = file_get_contents($log_path); |
| 77 |
// Get the last few lines (up to 20) |
| 78 |
$log_lines = explode(PHP_EOL, $log_content); |
| 79 |
$log_lines = array_filter($log_lines); // Remove empty lines |
| 80 |
$log_lines = array_slice($log_lines, -20); // Get last 20 lines |
| 81 |
$log_content = implode(PHP_EOL, $log_lines); |
| 82 |
} |
| 83 |
|
| 84 |
// Get any import errors |
| 85 |
$import_errors = array(); |
| 86 |
if (!empty($log_content)) { |
| 87 |
// Extract error messages |
| 88 |
if (preg_match_all('/ERROR: (.+?)(?=\n|$)/i', $log_content, $matches)) { |
| 89 |
$import_errors = $matches[1]; |
| 90 |
} |
| 91 |
} |
| 92 |
?> |
| 93 |
|
| 94 |
<div class="mlsimport-test-import-content"> |
| 95 |
<div class="mlsimport-section"> |
| 96 |
<p class="mlsimport-test-intro"> |
| 97 |
<?php _e('Now let\'s run a small test import to verify everything is working properly. We will import 5 listings from your MLS.', 'mlsimport'); ?> |
| 98 |
</p> |
| 99 |
|
| 100 |
<?php if (!$import_id) : ?> |
| 101 |
<div class="mlsimport-error-message"> |
| 102 |
<p> |
| 103 |
<?php _e('No import configuration found. Please go back to the previous step and try again.', 'mlsimport'); ?> |
| 104 |
</p> |
| 105 |
</div> |
| 106 |
<?php else : ?> |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
<div class="mlsimport-section-inner"> |
| 111 |
<h3><?php _e('Import Configuration', 'mlsimport'); ?></h3> |
| 112 |
<div class="mlsimport-import-summary"> |
| 113 |
<p> |
| 114 |
<strong><?php _e('Import Name:', 'mlsimport'); ?></strong> |
| 115 |
<?php echo esc_html(get_the_title($import_id)); ?> |
| 116 |
</p> |
| 117 |
<p> |
| 118 |
<strong><?php _e('Status:', 'mlsimport'); ?></strong> |
| 119 |
<?php |
| 120 |
if ($test_completed) { |
| 121 |
echo '<span class="mlsimport-status-success">' . esc_html__('Test Completed 2', 'mlsimport') . '</span>'; |
| 122 |
} elseif ($spawn_status === 'started') { |
| 123 |
echo '<span class="mlsimport-status-progress">' . esc_html__('In Progress', 'mlsimport') . '</span>'; |
| 124 |
} else { |
| 125 |
echo '<span class="mlsimport-status-pending">' . esc_html__('Ready to Test', 'mlsimport') . '</span>'; |
| 126 |
} |
| 127 |
?> |
| 128 |
</p> |
| 129 |
|
| 130 |
<?php |
| 131 |
// Get listing count based on filters |
| 132 |
global $mlsimport; |
| 133 |
$listing_count = 0; |
| 134 |
|
| 135 |
if ($import_id) { |
| 136 |
$mlsrequest = $mlsimport->admin->mlsimport_make_listing_requests($import_id); |
| 137 |
|
| 138 |
$listing_count = isset($mlsrequest['results']) ? intval($mlsrequest['results']) : 0; |
| 139 |
} |
| 140 |
?> |
| 141 |
|
| 142 |
<p> |
| 143 |
<strong><?php _e('Listings Found:', 'mlsimport'); ?></strong> |
| 144 |
<span class="mlsimport-listing-count"><?php echo esc_html($listing_count); ?></span> |
| 145 |
<?php if ($listing_count === 0): ?> |
| 146 |
<span class="mlsimport-zero-warning"><?php _e('(No listings match your current filters)', 'mlsimport'); ?></span> |
| 147 |
<?php endif; ?> |
| 148 |
</p> |
| 149 |
|
| 150 |
<?php if ($test_completed) : ?> |
| 151 |
<p> |
| 152 |
<strong><?php _e('Properties Imported:', 'mlsimport'); ?></strong> |
| 153 |
<?php echo esc_html($imported_count); ?> |
| 154 |
</p> |
| 155 |
<?php endif; ?> |
| 156 |
</div> |
| 157 |
|
| 158 |
<?php if ($listing_count === 0): ?> |
| 159 |
<div class="mlsimport-zero-listings-warning"> |
| 160 |
<p> |
| 161 |
<?php _e('Please go back and adjust your filters to broaden your search.', 'mlsimport'); ?> |
| 162 |
</p> |
| 163 |
<a href="<?php echo admin_url('admin.php?page=mlsimport-onboarding&step=import-config'); ?>" class="button mlsimport_button secondary "> |
| 164 |
<?php _e('Back to Import Configuration', 'mlsimport'); ?> |
| 165 |
</a> |
| 166 |
</div> |
| 167 |
<?php endif; ?> |
| 168 |
|
| 169 |
<?php if (!$test_completed && $spawn_status !== 'started' && $listing_count > 0) : ?> |
| 170 |
<div class="mlsimport-test-actions"> |
| 171 |
<button type="button" id="mlsimport-run-test" data-post-number="<?php echo intval($listing_count);?>" data-post_id="<?php echo intval($import_id)?>" class="button mlsimport_button"> |
| 172 |
<?php _e('Run Test Import', 'mlsimport'); ?> |
| 173 |
</button> |
| 174 |
<input type="hidden" id="mlsimport_item_actions" value="<?php echo esc_attr(wp_create_nonce("mlsimport_item_actions")); ?>"/> |
| 175 |
<span id="mlsimport-test-spinner" class="mlsimport-spinner" style="display: none;"></span> |
| 176 |
</div> |
| 177 |
<?php endif; ?> |
| 178 |
</div> |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
<div class="mlsimport-test-recommendations"> |
| 188 |
<h3><?php _e('Next Steps', 'mlsimport'); ?></h3> |
| 189 |
|
| 190 |
<?php if ($test_completed) : ?> |
| 191 |
<p> |
| 192 |
<?php echo sprintf( |
| 193 |
__('Congratulations! You\'ve successfully imported properties from your MLS into %s.', 'mlsimport'), |
| 194 |
$detected_theme |
| 195 |
); ?> |
| 196 |
</p> |
| 197 |
<ul> |
| 198 |
<li><?php _e('Click "Continue" to complete the setup', 'mlsimport'); ?></li> |
| 199 |
<li><?php _e('Your import configuration has been saved and will update automatically', 'mlsimport'); ?></li> |
| 200 |
<li><?php _e('You can create additional import configurations with different criteria later', 'mlsimport'); ?></li> |
| 201 |
</ul> |
| 202 |
<?php elseif ($spawn_status === 'started') : ?> |
| 203 |
<p> |
| 204 |
<?php _e('The import is currently in progress. Please wait for it to complete before continuing.', 'mlsimport'); ?> |
| 205 |
</p> |
| 206 |
<?php else : ?> |
| 207 |
<p> |
| 208 |
<?php _e('Please run the test import to verify your MLS connection and configuration.', 'mlsimport'); ?> |
| 209 |
</p> |
| 210 |
<?php endif; ?> |
| 211 |
</div> |
| 212 |
<?php endif; ?> |
| 213 |
</div> |
| 214 |
</div> |
| 215 |
|
| 216 |
<script> |
| 217 |
jQuery(document).ready(function($) { |
| 218 |
var testIntervalId; |
| 219 |
var importId = <?php echo intval($import_id); ?>; |
| 220 |
var testStarted = <?php echo ($spawn_status === 'started') ? 'true' : 'false'; ?>; |
| 221 |
var testCompleted = <?php echo $test_completed ? 'true' : 'false'; ?>; |
| 222 |
|
| 223 |
// If import already started, check status |
| 224 |
if (testStarted && !testCompleted) { |
| 225 |
// startStatusCheck(); |
| 226 |
} |
| 227 |
|
| 228 |
// Run test import |
| 229 |
$('#mlsimport-run-test').on('click', function() { |
| 230 |
$(this).prop('disabled', true); |
| 231 |
$('#mlsimport-test-spinner').show(); |
| 232 |
|
| 233 |
$('.mlsimport-status-message') |
| 234 |
.removeClass('pending') |
| 235 |
.addClass('progress') |
| 236 |
.html('<p><?php _e("Starting import... Please wait.", "mlsimport"); ?></p>'); |
| 237 |
|
| 238 |
// Send AJAX request |
| 239 |
$.ajax({ |
| 240 |
url: ajaxurl, |
| 241 |
type: 'POST', |
| 242 |
data: { |
| 243 |
action: 'mlsimport_run_test_import', |
| 244 |
nonce: mlsimportOnboarding.nonce |
| 245 |
}, |
| 246 |
success: function(response) { |
| 247 |
if (response.success) { |
| 248 |
testStarted = true; |
| 249 |
startStatusCheck(); |
| 250 |
} else { |
| 251 |
$('.mlsimport-status-message') |
| 252 |
.removeClass('pending progress') |
| 253 |
.addClass('error') |
| 254 |
.html('<p>' + response.data.message + '</p>'); |
| 255 |
|
| 256 |
$('#mlsimport-run-test').prop('disabled', false); |
| 257 |
$('#mlsimport-test-spinner').hide(); |
| 258 |
} |
| 259 |
}, |
| 260 |
error: function() { |
| 261 |
$('.mlsimport-status-message') |
| 262 |
.removeClass('pending progress') |
| 263 |
.addClass('error') |
| 264 |
.html('<p><?php _e("Connection failed. Please try again.", "mlsimport"); ?></p>'); |
| 265 |
|
| 266 |
$('#mlsimport-run-test').prop('disabled', false); |
| 267 |
$('#mlsimport-test-spinner').hide(); |
| 268 |
} |
| 269 |
}); |
| 270 |
}); |
| 271 |
|
| 272 |
// Check test status periodically |
| 273 |
function startStatusCheck() { |
| 274 |
function checkStatus() { |
| 275 |
jQuery.ajax({ |
| 276 |
url: ajaxurl, |
| 277 |
type: 'POST', |
| 278 |
dataType: 'json', |
| 279 |
data: { |
| 280 |
action: 'mlsimport_logger_per_item', |
| 281 |
post_id: importId, |
| 282 |
security: mlsimportOnboarding.nonce |
| 283 |
}, |
| 284 |
success: function(response) { |
| 285 |
console.log("Status response:", response); |
| 286 |
|
| 287 |
if (response.is_done === 'done' || response.status === 'completed') { |
| 288 |
|
| 289 |
clearInterval(testIntervalId); |
| 290 |
testIntervalId = null; |
| 291 |
|
| 292 |
// Hide spinner and get imported count |
| 293 |
jQuery('#mlsimport-test-spinner,#mlsimport-run-test').hide(); |
| 294 |
|
| 295 |
|
| 296 |
// Update next steps |
| 297 |
jQuery('.mlsimport-test-recommendations').html( |
| 298 |
'<h3><Next Steps</h3>' + |
| 299 |
'<p>Congratulations! You\'ve successfully imported properties from your MLS ! </p>' |
| 300 |
|
| 301 |
); |
| 302 |
|
| 303 |
|
| 304 |
} |
| 305 |
}, |
| 306 |
error: function() { |
| 307 |
// Error checking status |
| 308 |
} |
| 309 |
}); |
| 310 |
} |
| 311 |
|
| 312 |
// Check immediately, then every 5 seconds |
| 313 |
checkStatus(); |
| 314 |
testIntervalId = setInterval(checkStatus, 5000); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
}); |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
</script> |
| 328 |
|
| 329 |
<style> |
| 330 |
.mlsimport-test-import-content { |
| 331 |
max-width: 800px; |
| 332 |
} |
| 333 |
|
| 334 |
.mlsimport-test-intro { |
| 335 |
font-size: 15px; |
| 336 |
margin-bottom: 25px; |
| 337 |
} |
| 338 |
|
| 339 |
.mlsimport-section-inner { |
| 340 |
margin-bottom: 40px; |
| 341 |
} |
| 342 |
|
| 343 |
.mlsimport-section-inner h3 { |
| 344 |
margin-top: 0; |
| 345 |
border-bottom: 1px solid #f0f0f0; |
| 346 |
padding-bottom: 10px; |
| 347 |
margin-bottom: 15px; |
| 348 |
} |
| 349 |
|
| 350 |
.mlsimport-import-summary { |
| 351 |
background-color: #f9f9f9; |
| 352 |
padding: 15px; |
| 353 |
border-radius: 4px; |
| 354 |
margin-bottom: 20px; |
| 355 |
} |
| 356 |
|
| 357 |
.mlsimport-import-summary p { |
| 358 |
margin: 5px 0; |
| 359 |
} |
| 360 |
|
| 361 |
.mlsimport-status-success { |
| 362 |
color: #46b450; |
| 363 |
font-weight: 600; |
| 364 |
} |
| 365 |
|
| 366 |
.mlsimport-status-progress { |
| 367 |
color: #f56e28; |
| 368 |
font-weight: 600; |
| 369 |
} |
| 370 |
|
| 371 |
.mlsimport-status-pending { |
| 372 |
color: #666; |
| 373 |
font-weight: 600; |
| 374 |
} |
| 375 |
|
| 376 |
.mlsimport-test-actions { |
| 377 |
margin-top: 20px; |
| 378 |
display: flex; |
| 379 |
flex-direction: row; |
| 380 |
flex-wrap: nowrap; |
| 381 |
justify-content: flex-start; |
| 382 |
align-items: center; |
| 383 |
} |
| 384 |
|
| 385 |
.mlsimport-spinner { |
| 386 |
display: inline-block; |
| 387 |
width: 20px; |
| 388 |
height: 20px; |
| 389 |
margin-left: 10px; |
| 390 |
vertical-align: middle; |
| 391 |
border: 2px solid rgba(0, 0, 0, 0.1); |
| 392 |
border-radius: 50%; |
| 393 |
border-top-color: #07d; |
| 394 |
animation: mlsimport-spin 1s linear infinite; |
| 395 |
order:2; |
| 396 |
} |
| 397 |
|
| 398 |
@keyframes mlsimport-spin { |
| 399 |
to { |
| 400 |
transform: rotate(360deg); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
/* Status message styling */ |
| 405 |
.mlsimport-status-message { |
| 406 |
padding: 15px; |
| 407 |
border-radius: 4px; |
| 408 |
margin-bottom: 20px; |
| 409 |
} |
| 410 |
|
| 411 |
.mlsimport-status-message.success { |
| 412 |
background-color: #ecf7ed; |
| 413 |
border-left: 4px solid #46b450; |
| 414 |
} |
| 415 |
|
| 416 |
.mlsimport-status-message.error { |
| 417 |
background-color: #fbeaea; |
| 418 |
border-left: 4px solid #dc3232; |
| 419 |
} |
| 420 |
|
| 421 |
.mlsimport-status-message.warning { |
| 422 |
background-color: #fff8e5; |
| 423 |
border-left: 4px solid #ffb900; |
| 424 |
} |
| 425 |
|
| 426 |
.mlsimport-status-message.progress { |
| 427 |
background-color: #f0f8ff; |
| 428 |
border-left: 4px solid #00a0d2; |
| 429 |
} |
| 430 |
|
| 431 |
.mlsimport-status-message.pending { |
| 432 |
background-color: #f9f9f9; |
| 433 |
border-left: 4px solid #ccc; |
| 434 |
} |
| 435 |
|
| 436 |
.mlsimport-status-message p { |
| 437 |
margin: 0 0 10px 0; |
| 438 |
} |
| 439 |
|
| 440 |
.mlsimport-status-message p:last-child { |
| 441 |
margin-bottom: 0; |
| 442 |
} |
| 443 |
|
| 444 |
/* Progress bar */ |
| 445 |
/* Log container */ |
| 446 |
.mlsimport-log-container { |
| 447 |
max-height: 300px; |
| 448 |
overflow-y: auto; |
| 449 |
background-color: #f5f5f5; |
| 450 |
border: 1px solid #ddd; |
| 451 |
border-radius: 3px; |
| 452 |
padding: 10px; |
| 453 |
margin-bottom: 20px; |
| 454 |
} |
| 455 |
|
| 456 |
.mlsimport-log-content { |
| 457 |
font-family: monospace; |
| 458 |
font-size: 12px; |
| 459 |
line-height: 1.5; |
| 460 |
margin: 0; |
| 461 |
white-space: pre-wrap; |
| 462 |
} |
| 463 |
|
| 464 |
.mlsimport-log-empty { |
| 465 |
color: #666; |
| 466 |
font-style: italic; |
| 467 |
} |
| 468 |
|
| 469 |
.mlsimport-view-properties { |
| 470 |
margin-top: 20px; |
| 471 |
} |
| 472 |
|
| 473 |
/* Error list */ |
| 474 |
.mlsimport-error-list { |
| 475 |
background-color: #fbeaea; |
| 476 |
padding: 15px; |
| 477 |
border-radius: 4px; |
| 478 |
margin-top: 20px; |
| 479 |
} |
| 480 |
|
| 481 |
.mlsimport-error-list h4 { |
| 482 |
margin-top: 0; |
| 483 |
margin-bottom: 10px; |
| 484 |
color: #dc3232; |
| 485 |
} |
| 486 |
|
| 487 |
.mlsimport-error-list ul { |
| 488 |
margin-top: 10px; |
| 489 |
margin-left: 20px; |
| 490 |
} |
| 491 |
|
| 492 |
.mlsimport-error-list li { |
| 493 |
margin-bottom: 5px; |
| 494 |
} |
| 495 |
|
| 496 |
/* Error message */ |
| 497 |
.mlsimport-error-message { |
| 498 |
background-color: #fbeaea; |
| 499 |
border-left: 4px solid #dc3232; |
| 500 |
padding: 15px; |
| 501 |
margin-bottom: 20px; |
| 502 |
} |
| 503 |
|
| 504 |
.mlsimport-error-message p { |
| 505 |
margin: 0; |
| 506 |
} |
| 507 |
|
| 508 |
/* Next steps */ |
| 509 |
.mlsimport-test-recommendations { |
| 510 |
background-color: #f9f9f9; |
| 511 |
border-left: 4px solid #4f46e5; |
| 512 |
padding: 15px; |
| 513 |
margin-top: 20px; |
| 514 |
} |
| 515 |
|
| 516 |
.mlsimport-test-recommendations h3 { |
| 517 |
margin-top: 0; |
| 518 |
margin-bottom: 15px; |
| 519 |
border-bottom: none; |
| 520 |
padding-bottom: 0; |
| 521 |
} |
| 522 |
|
| 523 |
.mlsimport-test-recommendations ul { |
| 524 |
margin-left: 20px; |
| 525 |
} |
| 526 |
|
| 527 |
.mlsimport-test-recommendations li { |
| 528 |
margin-bottom: 8px; |
| 529 |
} |
| 530 |
</style> |