Changeset 3370692
- Timestamp:
- 09/30/2025 07:45:50 PM (5 months ago)
- Location:
- flexmls-idx/trunk
- Files:
-
- 5 edited
-
Admin/NginxCompatibility.php (modified) (1 diff)
-
README.txt (modified) (2 diffs)
-
flexmls_connect.php (modified) (3 diffs)
-
lib/flexmlsAPI/Core.php (modified) (1 diff)
-
views/admin-settings-behavior.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
flexmls-idx/trunk/Admin/NginxCompatibility.php
r3367368 r3370692 391 391 392 392 /** 393 * AJAX handler to get nginx configuration rules with custom parameters 394 */ 395 public static function ajax_get_nginx_rules() { 396 // Verify nonce for security 397 if ( ! wp_verify_nonce( $_POST['nonce'], 'fmc_nginx_rules_nonce' ) ) { 398 wp_die( 'Security check failed' ); 399 } 400 401 // Get parameters from AJAX request 402 $permabase = sanitize_text_field( $_POST['permabase'] ); 403 $destlink = sanitize_text_field( $_POST['destlink'] ); 404 405 // Temporarily update settings for rule generation 406 $fmc_settings = get_option( 'fmc_settings' ); 407 $original_permabase = $fmc_settings['permabase']; 408 $original_destlink = $fmc_settings['destlink']; 409 410 $fmc_settings['permabase'] = $permabase; 411 $fmc_settings['destlink'] = $destlink; 412 413 // Generate rules with temporary settings 414 $rules = self::get_nginx_rewrite_rules_with_params( $permabase, $destlink ); 415 $rules_text = implode( "\n", $rules ); 416 417 // Restore original settings 418 $fmc_settings['permabase'] = $original_permabase; 419 $fmc_settings['destlink'] = $original_destlink; 420 421 wp_send_json_success( array( 422 'rules' => $rules_text, 423 'permabase' => $permabase, 424 'destlink' => $destlink 425 ) ); 426 } 427 428 /** 429 * Generate nginx rewrite rules with specific parameters 430 * 431 * @param string $permabase The permalink base 432 * @param string $destlink The destination page ID 433 * @return array Array of nginx rewrite rules 434 */ 435 public static function get_nginx_rewrite_rules_with_params( $permabase, $destlink ) { 436 // Detect if WordPress is in a subdirectory 437 $wp_path = ''; 438 $site_url = site_url(); 439 440 // Extract the path from the site URL 441 $parsed_url = parse_url( $site_url ); 442 if ( isset( $parsed_url['path'] ) && $parsed_url['path'] !== '/' ) { 443 $wp_path = rtrim( $parsed_url['path'], '/' ); 444 } 445 446 $rules = array( 447 '# Flexmls IDX Plugin Rewrite Rules for nginx', 448 '# Add these rules to your nginx server block configuration', 449 '# Place these rules BEFORE the main WordPress location block', 450 '', 451 '# OAuth callback rules', 452 'location ~ ^' . $wp_path . '/oauth/callback/?$ {', 453 ' try_files $uri $uri/ ' . $wp_path . '/index.php?plugin=flexmls-idx&oauth_tag=oauth-login;', 454 '}', 455 '', 456 'location ~ ^' . $wp_path . '/oauth/spark-logout/?$ {', 457 ' try_files $uri $uri/ ' . $wp_path . '/index.php?plugin=flexmls-idx&oauth_tag=oauth-logout;', 458 '}', 459 '', 460 '# IDX permalink rules (matches WordPress: permabase/([^/]+)?)', 461 'location ~ ^' . $wp_path . '/' . $permabase . '/([^/]+)/?$ {', 462 ' try_files $uri $uri/ ' . $wp_path . '/index.php?plugin=flexmls-idx&fmc_tag=$1' . ( $destlink ? '&page_id=' . $destlink : '' ) . ';', 463 '}', 464 '', 465 '# Portal rules (matches WordPress: portal/([^/]+)?)', 466 'location ~ ^' . $wp_path . '/portal/([^/]+)/?$ {', 467 ' try_files $uri $uri/ ' . $wp_path . '/index.php?plugin=flexmls-idx&fmc_vow_tag=$1' . ( $destlink ? '&page_id=' . $destlink : '' ) . ';', 468 '}', 469 '', 470 '# End Flexmls IDX Plugin Rewrite Rules' 471 ); 472 473 return $rules; 474 } 475 476 /** 393 477 * Get server information for debugging 394 478 * -
flexmls-idx/trunk/README.txt
r3367368 r3370692 5 5 Tested up to: 6.8.2 6 6 Requires PHP: 7.4 7 Stable tag: 3.15. 37 Stable tag: 3.15.4 8 8 9 9 Add Flexmls® IDX listings, market statistics, IDX searches, and a contact form on your web site. … … 86 86 87 87 == Changelog == 88 = 3.15.4 = 89 Efficiency Update 90 * Ajax improvements to the nginx configuration block under Behavior settings 91 92 88 93 = 3.15.3 = 89 94 New Feature -
flexmls-idx/trunk/flexmls_connect.php
r3367368 r3370692 6 6 Description: Provides Flexmls® Customers with Flexmls® IDX features on their WordPress websites. <strong>Tips:</strong> <a href="admin.php?page=fmc_admin_settings">Activate your Flexmls® IDX plugin</a> on the settings page; <a href="widgets.php">add widgets to your sidebar</a> using the Widgets Admin under Appearance; and include widgets on your posts or pages using the Flexmls® IDX Widget Short-Code Generator on the Visual page editor. 7 7 Author: FBS 8 Version: 3.15. 38 Version: 3.15.4 9 9 Author URI: https://www.flexmls.com 10 10 Requires at least: 5.0 … … 17 17 const FMC_API_BASE = 'sparkapi.com'; 18 18 const FMC_API_VERSION = 'v1'; 19 const FMC_PLUGIN_VERSION = '3.15. 3';19 const FMC_PLUGIN_VERSION = '3.15.4'; 20 20 21 21 define( 'FMC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); … … 91 91 add_action( 'wp_ajax_flexmls_connect_save_search', array( 'flexmlsConnectPageSearchResults', 'save_user_search' ) ); 92 92 add_action( 'wp_ajax_nopriv_flexmls_connect_save_search', array( 'flexmlsConnectPageSearchResults', 'save_user_search' ) ); 93 94 // AJAX handler for nginx configuration rules 95 add_action( 'wp_ajax_fmc_get_nginx_rules', array( '\FlexMLS\Admin\NginxCompatibility', 'ajax_get_nginx_rules' ) ); 93 96 94 97 add_shortcode( 'idx_frame', array( 'flexmlsConnect', 'shortcode' ) ); -
flexmls-idx/trunk/lib/flexmlsAPI/Core.php
r3367368 r3370692 44 44 'Accept-Encoding' => "gzip,deflate", 45 45 'Content-Type' => "application/json", 46 'User-Agent' => "Flexmls WordPress Plugin/3.15. 3",47 'X-SparkApi-User-Agent' => "flexmls-WordPress-Plugin/3.15. 3"46 'User-Agent' => "Flexmls WordPress Plugin/3.15.4", 47 'X-SparkApi-User-Agent' => "flexmls-WordPress-Plugin/3.15.4" 48 48 ); 49 49 -
flexmls-idx/trunk/views/admin-settings-behavior.php
r3367368 r3370692 319 319 </table> 320 320 <?php endif; ?> 321 322 <?php 323 // Display red warning message for nginx users about copying config and saving changes 324 if ( \FlexMLS\Admin\NginxCompatibility::is_nginx() ) { 325 ?> 326 <div style="background: #f8d7da; padding: 15px; margin: 20px 0; border: 1px solid #f5c6cb; border-radius: 4px;"> 327 <p style="margin: 0; color: #721c24; font-size: 14px; font-weight: bold;"> 328 ⚠️ <strong>Important:</strong> If you see nginx configuration blocks above, you must: 329 </p> 330 <ol style="margin: 10px 0 0 0; padding-left: 20px; color: #721c24; font-size: 13px;"> 331 <li><strong>Copy the nginx configuration block</strong> and add it to your nginx server configuration file</li> 332 <li><strong>Click "Save Settings" button below</strong> to save your changes to this page</li> 333 </ol> 334 </div> 335 <?php 336 } 337 ?> 338 321 339 <p><?php wp_nonce_field( 'update_fmc_behavior_action', 'update_fmc_behavior_nonce' ); ?><button type="submit" class="button-primary">Save Settings</button></p> 322 340 </form> … … 324 342 <script> 325 343 jQuery(document).ready(function($) { 344 var originalPermabase = '<?php echo esc_js( $fmc_settings[ 'permabase' ] ); ?>'; 345 var originalDestlink = '<?php echo esc_js( $fmc_settings[ 'destlink' ] ); ?>'; 346 var nginxConfigTextarea = null; 347 var currentValuesContainer = null; 348 349 // Function to update nginx configuration and current values via AJAX 350 function updateNginxConfig(permabase, destlink) { 351 // Only make AJAX call if nginx warning exists 352 var nginxWarning = $('.nginx-permabase-warning'); 353 if (nginxWarning.length === 0) { 354 return; 355 } 356 357 // Find the nginx config textarea 358 if (!nginxConfigTextarea) { 359 nginxConfigTextarea = nginxWarning.find('textarea[id="nginx-permabase-config"]'); 360 } 361 362 // Find current values container - there might be multiple instances 363 if (!currentValuesContainer) { 364 currentValuesContainer = nginxWarning.find('p:contains("Current permalink base")'); 365 } 366 367 // Make AJAX request to get updated nginx rules 368 $.ajax({ 369 url: ajaxurl, 370 type: 'POST', 371 data: { 372 action: 'fmc_get_nginx_rules', 373 permabase: permabase, 374 destlink: destlink, 375 nonce: '<?php echo wp_create_nonce( 'fmc_nginx_rules_nonce' ); ?>' 376 }, 377 success: function(response) { 378 if (response.success) { 379 // Update nginx configuration textarea 380 if (nginxConfigTextarea.length > 0) { 381 nginxConfigTextarea.val(response.data.rules); 382 } 383 384 // Update current values display - handle multiple instances 385 if (currentValuesContainer.length > 0) { 386 var newContent = 'Current permalink base: <code>' + response.data.permabase + '</code>'; 387 if (response.data.destlink && response.data.destlink !== '0') { 388 newContent += '<br>Current destination page ID: <code>' + response.data.destlink + '</code>'; 389 } 390 // Update all instances of current values 391 currentValuesContainer.each(function() { 392 $(this).html(newContent); 393 }); 394 } 395 } 396 }, 397 error: function() { 398 console.log('Failed to update nginx configuration'); 399 } 400 }); 401 } 402 326 403 // Show nginx warning when permalink base field is focused or changed 327 404 $('#permabase').on('focus change input', function() { … … 330 407 331 408 // If nginx warning exists and value has changed, show a note and expand the warning 332 if (nginxWarning.length > 0 && currentValue !== '<?php echo esc_js( $fmc_settings[ 'permabase' ] ); ?>') {409 if (nginxWarning.length > 0 && currentValue !== originalPermabase) { 333 410 // Expand the warning if it's collapsed 334 411 var details = nginxWarning.find('details'); … … 337 414 } 338 415 339 // Add the change notice if it doesn't exist 340 if (!nginxWarning.find('.value-changed-notice').length) { 341 nginxWarning.find('details > div').prepend('<div class="value-changed-notice" style="background: #d4edda; padding: 8px; margin-bottom: 10px; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724; font-size: 13px;"><strong>Note:</strong> You will need to update your nginx configuration after saving this change.</div>'); 342 } 416 // Add the change notice only to the first nginx warning container if it doesn't exist 417 if (!$('.value-changed-notice').length) { 418 $('.nginx-permabase-warning').first().find('> details > div').prepend('<div class="value-changed-notice" style="background: #d4edda; padding: 8px; margin-bottom: 10px; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724; font-size: 13px;"><strong>Note:</strong> You will need to update your nginx configuration after saving this change.</div>'); 419 } 420 421 // Update nginx configuration in real-time 422 var currentDestlink = $('select[name="fmc_settings[destlink]"]').val() || '0'; 423 updateNginxConfig(currentValue, currentDestlink); 343 424 } 344 425 }); … … 348 429 var currentValue = $(this).val(); 349 430 var nginxWarning = $(this).closest('td').find('.nginx-permabase-warning'); 350 var valueChangedNotice = nginxWarning.find('.value-changed-notice'); 351 352 if (currentValue === '<?php echo esc_js( $fmc_settings[ 'permabase' ] ); ?>' && valueChangedNotice.length > 0) { 353 valueChangedNotice.remove(); 431 432 if (currentValue === originalPermabase) { 433 $('.value-changed-notice').remove(); 354 434 // Optionally collapse the warning if it was auto-expanded 355 435 var details = nginxWarning.find('details'); … … 358 438 } 359 439 } 440 441 // Update nginx configuration in real-time 442 var currentDestlink = $('select[name="fmc_settings[destlink]"]').val() || '0'; 443 updateNginxConfig(currentValue, currentDestlink); 360 444 }); 361 445 … … 363 447 $('select[name="fmc_settings[destlink]"]').on('change', function() { 364 448 var currentValue = $(this).val(); 365 var originalValue = '<?php echo esc_js( $fmc_settings[ 'destlink' ] ); ?>';366 449 var nginxWarning = $('.nginx-permabase-warning'); 367 450 368 451 // If nginx warning exists and value has changed, show a note and expand the warning 369 if (nginxWarning.length > 0 && currentValue !== original Value) {452 if (nginxWarning.length > 0 && currentValue !== originalDestlink) { 370 453 // Expand the warning if it's collapsed 371 454 var details = nginxWarning.find('details'); … … 374 457 } 375 458 376 // Add the change notice if it doesn't exist 377 if (!nginxWarning.find('.value-changed-notice').length) { 378 nginxWarning.find('details > div').prepend('<div class="value-changed-notice" style="background: #d4edda; padding: 8px; margin-bottom: 10px; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724; font-size: 13px;"><strong>Note:</strong> You will need to update your nginx configuration after saving this change.</div>'); 379 } 459 // Add the change notice only to the first nginx warning container if it doesn't exist 460 if (!$('.value-changed-notice').length) { 461 $('.nginx-permabase-warning').first().find('> details > div').prepend('<div class="value-changed-notice" style="background: #d4edda; padding: 8px; margin-bottom: 10px; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724; font-size: 13px;"><strong>Note:</strong> You will need to update your nginx configuration after saving this change.</div>'); 462 } 463 464 // Update nginx configuration in real-time 465 var currentPermabase = $('#permabase').val() || originalPermabase; 466 updateNginxConfig(currentPermabase, currentValue); 380 467 } 381 468 382 469 // Hide the note when value is reverted to original 383 if (currentValue === originalValue) { 384 var valueChangedNotice = nginxWarning.find('.value-changed-notice'); 385 if (valueChangedNotice.length > 0) { 386 valueChangedNotice.remove(); 387 // Optionally collapse the warning if it was auto-expanded 388 var details = nginxWarning.find('details'); 389 if (details.length > 0 && details.attr('open') && !details.data('user-opened')) { 390 details.removeAttr('open'); 391 } 392 } 393 } 470 if (currentValue === originalDestlink) { 471 $('.value-changed-notice').remove(); 472 // Optionally collapse the warning if it was auto-expanded 473 var details = nginxWarning.find('details'); 474 if (details.length > 0 && details.attr('open') && !details.data('user-opened')) { 475 details.removeAttr('open'); 476 } 477 } 478 479 // Update nginx configuration in real-time 480 var currentPermabase = $('#permabase').val() || originalPermabase; 481 updateNginxConfig(currentPermabase, currentValue); 394 482 }); 395 483 });
Note: See TracChangeset
for help on using the changeset viewer.