Plugin Directory

Changeset 3236569


Ignore:
Timestamp:
02/07/2025 12:22:28 PM (12 months ago)
Author:
motionpointexpress
Message:

Updating plugin to version 1.9

Location:
motionpoint-express
Files:
6 edited
8 copied

Legend:

Unmodified
Added
Removed
  • motionpoint-express/tags/1.9/assets/js/admin.js

    r3094569 r3236569  
    1919        $debugInfoBtn.toggleClass('active');
    2020    } );
     21
     22    $('#MotionPointExpressTestConnectionBtn').on( 'click', function( e ) {
     23        e.preventDefault();
     24        testConnection();
     25    } );
    2126});
     27
     28function testConnection() {
     29    $('#MotionPointExpressTestConnectionBtn').attr('disabled', 'disabled');
     30
     31    $.ajax({
     32      'type': 'post',
     33      'dataType': 'json',
     34      'url': MotionPointExpress.ajaxUrl,
     35      'data': {
     36        'action': MotionPointExpress.testConnectionAction,
     37        'nonce': MotionPointExpress.testConnectionNonce,
     38      }
     39    })
     40      .done(function onDone( data ) {
     41        console.log('onDone', { data });
     42        if (data.status) {
     43            $('#MotionPointExpressConnectionStatus').removeClass('notice-error').addClass('notice-success');
     44        } else {
     45            $('#MotionPointExpressConnectionStatus').removeClass('notice-success').addClass('notice-error');
     46        }
     47        $('#MotionPointExpressConnectionStatus').show().html( data.message );
     48      })
     49      .fail(function onFail() {
     50        console.log('onFail');
     51        $('#MotionPointExpressConnectionStatus').removeClass('notice-success').addClass('notice-error');
     52        $('#MotionPointExpressConnectionStatus').show().html( 'Unknown error occurred' );
     53      })
     54      .always(function onFail() {
     55        $('#MotionPointExpressTestConnectionBtn').removeAttr('disabled');
     56      })
     57    ;
     58}
    2259
    2360function updateCustomLocationVisibility() {
  • motionpoint-express/tags/1.9/inc/admin.php

    r3188804 r3236569  
    3333      add_filter( 'plugin_action_links_' . motionpointexpress()->get_setting('basename'), array( $this, 'plugin_actions' ) );
    3434      add_action( 'admin_notices', array( $this, 'admin_notices' ) );
     35    }
     36
     37    if ( is_admin() ) {
     38      add_action( 'wp_ajax_motionpointexpress_test_connection', array( $this, 'ajax_test_connection' ) );
    3539    }
    3640  }
     
    157161    }
    158162
     163    $is_configured = ! empty( $project_settings['languages'] ) && ! empty( $config['project_code'] );
    159164
    160165    $new_tab_link_icon = '<i aria-hidden="true" class="dashicons dashicons-external" style="text-decoration:none;"></i>';
     
    261266            </tr>
    262267            <tr>
     268              <th><?php esc_html_e( 'Connection testing', 'motionpoint-express' ) ?></th>
     269              <td>
     270                <a id="MotionPointExpressTestConnectionBtn" href="#" class="button button-primary"<?php echo $is_configured ? '' : ' disabled' ?>><?php esc_html_e( 'Test connection', 'motionpoint-express' ) ?></a>
     271                <?php if ( ! $is_configured ) : ?>
     272                  <p><?php esc_html_e( 'Configure and save settings first before you can test your connection.', 'motionpoint-express' ) ?></p>
     273                <?php else : ?>
     274                  <p id="MotionPointExpressConnectionStatus" class="notice" style="display: none;"></p>
     275                  <p><?php esc_html_e( 'Click to check if your connection works fine.', 'motionpoint-express' ) ?></p>
     276                <?php endif; ?>
     277              </td>
     278            </tr>
     279            <tr>
    263280              <th><?php esc_html_e( 'Floating language selector', 'motionpoint-express' ) ?></th>
    264281              <td>
     
    268285                  <?php endforeach; ?>
    269286                </select>
    270                 <p><?php esc_html_e( 'Override project settings for the floating sidebar language selector or choose "Default" to leave it as it is.', 'easyling' ) ?></p>
     287                <p><?php esc_html_e( 'Override project settings for the floating sidebar language selector or choose "Default" to leave it as it is.', 'motionpoint-express' ) ?></p>
    271288              </td>
    272289            </tr>
     
    357374      wp_enqueue_style( 'motionpointexpress-admin', motionpointexpress()->get_setting('url') . 'assets/css/admin.css', array(), motionpointexpress()->get_setting('version'), 'all' );
    358375      wp_enqueue_script( 'motionpointexpress-admin', motionpointexpress()->get_setting('url') . 'assets/js/admin.js', array( 'jquery' ), motionpointexpress()->get_setting('version'), true );
     376      wp_localize_script(
     377        'motionpointexpress-admin',
     378        'MotionPointExpress',
     379        array(
     380          'ajaxUrl'              => admin_url( 'admin-ajax.php' ),
     381          'testConnectionNonce'  => wp_create_nonce( 'motionpointexpress_test_connection' ),
     382          'testConnectionAction' => 'motionpointexpress_test_connection',
     383        )
     384      );
    359385    }
     386  }
     387
     388
     389  /**
     390   *  Test connection of the configured project
     391   */
     392  public function ajax_test_connection() {
     393    try {
     394      check_ajax_referer( 'motionpointexpress_test_connection', 'nonce' );
     395
     396      $user_config = motionpointexpress()->get_user_config();
     397
     398      $project_settings = motionpointexpress()->get_project_settings();
     399      if ( empty( $project_settings ) ) {
     400        throw new Exception( __( 'Project settings are not saved yet', 'motionpoint-express' ), 1);
     401      }
     402
     403      $subdir_locale_map = ! empty( $project_settings['subdir_locale_map'] ) ? $project_settings['subdir_locale_map'] : array();
     404      if ( empty( $subdir_locale_map ) ) {
     405        throw new Exception( __( 'Languages are not configured', 'motionpoint-express' ), 1);
     406      }
     407
     408      $location_host = $user_config['location_host'] === 'custom' ? $user_config['custom_location_host'] : $user_config['location_host'];
     409      $location_host = ! empty( $location_host ) ? trim( $location_host ) : $location_host;
     410      if ( empty( $location_host ) ) {
     411        throw new Exception( __( 'MotionPoint Eexpress location is invalid', 'motionpoint-express' ), 1);
     412      }
     413      $locale_prefix = array_key_first( $subdir_locale_map );
     414      $locale = $subdir_locale_map[ $locale_prefix ];
     415
     416      $result = motionpointexpress()->app_request( array(
     417        'publishing_mode' => $user_config['publishing_mode'],
     418        'locale'          => $locale,
     419        'project_code'    => $user_config['project_code'],
     420        'location_host'   => $location_host,
     421        'request_method'  => 'GET',
     422        'request_body'    => null,
     423        'request_uri'     => "/{$locale_prefix}/",
     424      ) );
     425      $response = $result['response'];
     426
     427      if ( is_wp_error( $response ) ) {
     428        $error = sprintf(
     429          __( 'Failed fetching %s, error: %s', 'motionpoint-express' ),
     430          $result['proxy_url'],
     431          $response->get_error_message()
     432        );
     433        throw new Exception( $error, 1 );
     434      }
     435
     436      echo json_encode( array(
     437        'result' => $result,
     438        'status' => true,
     439        'message' => sprintf(
     440          __( 'Successfully fetched %s, response code %s', 'motionpoint-express' ),
     441          $result['proxy_url'],
     442          $response['response']['code']
     443        ),
     444      ) );
     445    } catch (Exception $e) {
     446      echo json_encode( array(
     447        'status' => false,
     448        'message' => $e->getMessage(),
     449      ) );
     450    }
     451
     452    die();
    360453  }
    361454
  • motionpoint-express/tags/1.9/inc/frontend.php

    r3235656 r3236569  
    8686    $has_language_prefix = ! empty( $language_subdirectories ) && preg_match( "#^/($language_subdirectories)(/|\?|$)#i", $server_request_uri, $language_subdirectory_matches );
    8787    $language_subdirectory = $has_language_prefix && ! empty( $language_subdirectory_matches[1] ) ? $language_subdirectory_matches[1] : null;
    88     $locale = ! empty( $project_settings['subdir_locale_map'][ $language_subdirectory ] ) ? strtolower( $project_settings['subdir_locale_map'][ $language_subdirectory ] ) : '';
     88    $locale = ! empty( $subdir_locale_map[ $language_subdirectory ] ) ? strtolower( $subdir_locale_map[ $language_subdirectory ] ) : '';
    8989
    9090    if ( ! empty( $has_language_prefix ) && preg_match( "#/{$language_subdirectory}/wp-admin#i", $server_request_uri ) ) {
     
    246246    // Non-bot request processing
    247247
    248     if ( 'js' === $publishing_mode ) {
    249       $proxy_host = "{$locale}-{$project_code}-j.app.motionpointexpress.com";
    250     } else {
    251       // Proxy mode
    252       $proxy_host = "{$locale}-{$project_code}.{$location_host}";
    253     }
    254 
    255 
    256     // Prepare headers
    257     $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
    258     $headers['Origin'] = $http_host;
    259     $headers['Host'] = $proxy_host;
    260     $headers['X-TranslationProxy-Cache-Info'] = 'disable';
    261     $headers['X-TranslationProxy-EnableDeepRoot'] = 'true';
    262     $headers['X-TranslationProxy-AllowRobots'] = 'true';
    263     $headers['X-TranslationProxy-ServingDomain'] = $http_host;
    264 
    265     // Prepare request args
    266     $proxy_request_args = array(
    267       'method'      => $request_method,
    268       'headers'     => $headers,
    269       'timeout'     => 180,
    270       'redirection' => 0,
    271     );
    272 
    273     if ( ! empty( $request_body ) ) {
    274       $proxy_request_args['body'] = $request_body;
    275     }
    276 
    277     $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
    278     $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
    279     $proxy_url = "{$request_scheme}://{$proxy_host}{$server_request_uri}";
     248    // if ( 'js' === $publishing_mode ) {
     249    //   $proxy_host = "{$locale}-{$project_code}-j.app.motionpointexpress.com";
     250    // } else {
     251    //   // Proxy mode
     252    //   $proxy_host = "{$locale}-{$project_code}.{$location_host}";
     253    // }
     254
     255
     256    // // Prepare headers
     257    // $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
     258    // $headers['Origin'] = $http_host;
     259    // $headers['Host'] = $proxy_host;
     260    // $headers['X-TranslationProxy-Cache-Info'] = 'disable';
     261    // $headers['X-TranslationProxy-EnableDeepRoot'] = 'true';
     262    // $headers['X-TranslationProxy-AllowRobots'] = 'true';
     263    // $headers['X-TranslationProxy-ServingDomain'] = $http_host;
     264
     265    // // Prepare request args
     266    // $proxy_request_args = array(
     267    //   'method'      => $request_method,
     268    //   'headers'     => $headers,
     269    //   'timeout'     => 180,
     270    //   'redirection' => 0,
     271    // );
     272
     273    // if ( ! empty( $request_body ) ) {
     274    //   $proxy_request_args['body'] = $request_body;
     275    // }
     276
     277    // $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     278    // $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
     279    // $proxy_url = "{$request_scheme}://{$proxy_host}{$server_request_uri}";
    280280
    281281    // Proxy request
    282     $response = wp_remote_request( $proxy_url, $proxy_request_args );
     282    // $response = wp_remote_request( $proxy_url, $proxy_request_args );
     283    $result = motionpointexpress()->app_request( array(
     284      'publishing_mode' => $publishing_mode,
     285      'locale'          => $locale,
     286      'project_code'    => $project_code,
     287      'location_host'   => $location_host,
     288      'request_method'  => $request_method,
     289      'request_body'    => $request_body,
     290      'request_uri'     => $server_request_uri,
     291    ) );
     292    $response = $result['response'];
     293
    283294    $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';
    284295    $response_body = is_wp_error( $response_body ) ? '' : $response_body;
  • motionpoint-express/tags/1.9/motionpoint-express.php

    r3235656 r3236569  
    44Plugin URI: https://www.motionpointexpress.com/
    55Description: MotionPoint Express website translation solution.
    6 Version: 1.8
     6Version: 1.9
    77Author: MotionPoint Express
    88Copyright: MotionPoint Express
     
    8282  private function __construct() {
    8383    $this->settings = array(
    84       'version'  => '1.7',
     84      'version'  => '1.9',
    8585      'path'     => plugin_dir_path( __FILE__ ),
    8686      'url'      => plugin_dir_url( __FILE__ ),
     
    186186
    187187  /**
     188   *  Performs request to the app server
     189   */
     190  public function app_request( $params ) {
     191    extract( $params ); // publishing_mode, locale, project_code, location_host, request_method, request_body, request_uri
     192
     193    $timeout = 180;
     194
     195    if ( 'js' === $publishing_mode ) {
     196      $proxy_host = "{$locale}-{$project_code}-j.app.motionpointexpress.com";
     197    } else {
     198      // Proxy mode
     199      $proxy_host = "{$locale}-{$project_code}.{$location_host}";
     200    }
     201
     202
     203    // Prepare headers
     204    $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
     205    $headers['Origin'] = $http_host;
     206    $headers['Host'] = $proxy_host;
     207    $headers['X-TranslationProxy-Cache-Info'] = 'disable';
     208    $headers['X-TranslationProxy-EnableDeepRoot'] = 'true';
     209    $headers['X-TranslationProxy-AllowRobots'] = 'true';
     210    $headers['X-TranslationProxy-ServingDomain'] = $http_host;
     211
     212    // Prepare request args
     213    $proxy_request_args = array(
     214      'method'      => $request_method,
     215      'headers'     => $headers,
     216      'timeout'     => $timeout,
     217      'redirection' => 0,
     218    );
     219
     220    if ( ! empty( $request_body ) ) {
     221      $proxy_request_args['body'] = $request_body;
     222    }
     223
     224    $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     225    $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
     226    $proxy_url = "{$request_scheme}://{$proxy_host}{$request_uri}";
     227
     228    // Proxy request
     229    set_time_limit( $timeout + 10 );
     230
     231    return array(
     232      'proxy_url'          => $proxy_url,
     233      'proxy_request_args' => $proxy_request_args,
     234      'response'           => wp_remote_request( $proxy_url, $proxy_request_args ),
     235    );
     236  }
     237
     238
     239  /**
    188240   *  Initialize plugin
    189241   */
  • motionpoint-express/tags/1.9/readme.txt

    r3235656 r3236569  
    44Requires at least: 4.7
    55Tested up to: 6.7
    6 Stable tag: 1.8
     6Stable tag: 1.9
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    7575 
    7676== Changelog ==
     77= 1.9 =
     78Release Date: February 7th, 2025
     79
     80Enhancements:
     81
     82* Connection testing feature
     83
    7784= 1.8 =
    7885Release Date: February 5th, 2025
  • motionpoint-express/trunk/assets/js/admin.js

    r3094569 r3236569  
    1919        $debugInfoBtn.toggleClass('active');
    2020    } );
     21
     22    $('#MotionPointExpressTestConnectionBtn').on( 'click', function( e ) {
     23        e.preventDefault();
     24        testConnection();
     25    } );
    2126});
     27
     28function testConnection() {
     29    $('#MotionPointExpressTestConnectionBtn').attr('disabled', 'disabled');
     30
     31    $.ajax({
     32      'type': 'post',
     33      'dataType': 'json',
     34      'url': MotionPointExpress.ajaxUrl,
     35      'data': {
     36        'action': MotionPointExpress.testConnectionAction,
     37        'nonce': MotionPointExpress.testConnectionNonce,
     38      }
     39    })
     40      .done(function onDone( data ) {
     41        console.log('onDone', { data });
     42        if (data.status) {
     43            $('#MotionPointExpressConnectionStatus').removeClass('notice-error').addClass('notice-success');
     44        } else {
     45            $('#MotionPointExpressConnectionStatus').removeClass('notice-success').addClass('notice-error');
     46        }
     47        $('#MotionPointExpressConnectionStatus').show().html( data.message );
     48      })
     49      .fail(function onFail() {
     50        console.log('onFail');
     51        $('#MotionPointExpressConnectionStatus').removeClass('notice-success').addClass('notice-error');
     52        $('#MotionPointExpressConnectionStatus').show().html( 'Unknown error occurred' );
     53      })
     54      .always(function onFail() {
     55        $('#MotionPointExpressTestConnectionBtn').removeAttr('disabled');
     56      })
     57    ;
     58}
    2259
    2360function updateCustomLocationVisibility() {
  • motionpoint-express/trunk/inc/admin.php

    r3188804 r3236569  
    3333      add_filter( 'plugin_action_links_' . motionpointexpress()->get_setting('basename'), array( $this, 'plugin_actions' ) );
    3434      add_action( 'admin_notices', array( $this, 'admin_notices' ) );
     35    }
     36
     37    if ( is_admin() ) {
     38      add_action( 'wp_ajax_motionpointexpress_test_connection', array( $this, 'ajax_test_connection' ) );
    3539    }
    3640  }
     
    157161    }
    158162
     163    $is_configured = ! empty( $project_settings['languages'] ) && ! empty( $config['project_code'] );
    159164
    160165    $new_tab_link_icon = '<i aria-hidden="true" class="dashicons dashicons-external" style="text-decoration:none;"></i>';
     
    261266            </tr>
    262267            <tr>
     268              <th><?php esc_html_e( 'Connection testing', 'motionpoint-express' ) ?></th>
     269              <td>
     270                <a id="MotionPointExpressTestConnectionBtn" href="#" class="button button-primary"<?php echo $is_configured ? '' : ' disabled' ?>><?php esc_html_e( 'Test connection', 'motionpoint-express' ) ?></a>
     271                <?php if ( ! $is_configured ) : ?>
     272                  <p><?php esc_html_e( 'Configure and save settings first before you can test your connection.', 'motionpoint-express' ) ?></p>
     273                <?php else : ?>
     274                  <p id="MotionPointExpressConnectionStatus" class="notice" style="display: none;"></p>
     275                  <p><?php esc_html_e( 'Click to check if your connection works fine.', 'motionpoint-express' ) ?></p>
     276                <?php endif; ?>
     277              </td>
     278            </tr>
     279            <tr>
    263280              <th><?php esc_html_e( 'Floating language selector', 'motionpoint-express' ) ?></th>
    264281              <td>
     
    268285                  <?php endforeach; ?>
    269286                </select>
    270                 <p><?php esc_html_e( 'Override project settings for the floating sidebar language selector or choose "Default" to leave it as it is.', 'easyling' ) ?></p>
     287                <p><?php esc_html_e( 'Override project settings for the floating sidebar language selector or choose "Default" to leave it as it is.', 'motionpoint-express' ) ?></p>
    271288              </td>
    272289            </tr>
     
    357374      wp_enqueue_style( 'motionpointexpress-admin', motionpointexpress()->get_setting('url') . 'assets/css/admin.css', array(), motionpointexpress()->get_setting('version'), 'all' );
    358375      wp_enqueue_script( 'motionpointexpress-admin', motionpointexpress()->get_setting('url') . 'assets/js/admin.js', array( 'jquery' ), motionpointexpress()->get_setting('version'), true );
     376      wp_localize_script(
     377        'motionpointexpress-admin',
     378        'MotionPointExpress',
     379        array(
     380          'ajaxUrl'              => admin_url( 'admin-ajax.php' ),
     381          'testConnectionNonce'  => wp_create_nonce( 'motionpointexpress_test_connection' ),
     382          'testConnectionAction' => 'motionpointexpress_test_connection',
     383        )
     384      );
    359385    }
     386  }
     387
     388
     389  /**
     390   *  Test connection of the configured project
     391   */
     392  public function ajax_test_connection() {
     393    try {
     394      check_ajax_referer( 'motionpointexpress_test_connection', 'nonce' );
     395
     396      $user_config = motionpointexpress()->get_user_config();
     397
     398      $project_settings = motionpointexpress()->get_project_settings();
     399      if ( empty( $project_settings ) ) {
     400        throw new Exception( __( 'Project settings are not saved yet', 'motionpoint-express' ), 1);
     401      }
     402
     403      $subdir_locale_map = ! empty( $project_settings['subdir_locale_map'] ) ? $project_settings['subdir_locale_map'] : array();
     404      if ( empty( $subdir_locale_map ) ) {
     405        throw new Exception( __( 'Languages are not configured', 'motionpoint-express' ), 1);
     406      }
     407
     408      $location_host = $user_config['location_host'] === 'custom' ? $user_config['custom_location_host'] : $user_config['location_host'];
     409      $location_host = ! empty( $location_host ) ? trim( $location_host ) : $location_host;
     410      if ( empty( $location_host ) ) {
     411        throw new Exception( __( 'MotionPoint Eexpress location is invalid', 'motionpoint-express' ), 1);
     412      }
     413      $locale_prefix = array_key_first( $subdir_locale_map );
     414      $locale = $subdir_locale_map[ $locale_prefix ];
     415
     416      $result = motionpointexpress()->app_request( array(
     417        'publishing_mode' => $user_config['publishing_mode'],
     418        'locale'          => $locale,
     419        'project_code'    => $user_config['project_code'],
     420        'location_host'   => $location_host,
     421        'request_method'  => 'GET',
     422        'request_body'    => null,
     423        'request_uri'     => "/{$locale_prefix}/",
     424      ) );
     425      $response = $result['response'];
     426
     427      if ( is_wp_error( $response ) ) {
     428        $error = sprintf(
     429          __( 'Failed fetching %s, error: %s', 'motionpoint-express' ),
     430          $result['proxy_url'],
     431          $response->get_error_message()
     432        );
     433        throw new Exception( $error, 1 );
     434      }
     435
     436      echo json_encode( array(
     437        'result' => $result,
     438        'status' => true,
     439        'message' => sprintf(
     440          __( 'Successfully fetched %s, response code %s', 'motionpoint-express' ),
     441          $result['proxy_url'],
     442          $response['response']['code']
     443        ),
     444      ) );
     445    } catch (Exception $e) {
     446      echo json_encode( array(
     447        'status' => false,
     448        'message' => $e->getMessage(),
     449      ) );
     450    }
     451
     452    die();
    360453  }
    361454
  • motionpoint-express/trunk/inc/frontend.php

    r3235656 r3236569  
    8686    $has_language_prefix = ! empty( $language_subdirectories ) && preg_match( "#^/($language_subdirectories)(/|\?|$)#i", $server_request_uri, $language_subdirectory_matches );
    8787    $language_subdirectory = $has_language_prefix && ! empty( $language_subdirectory_matches[1] ) ? $language_subdirectory_matches[1] : null;
    88     $locale = ! empty( $project_settings['subdir_locale_map'][ $language_subdirectory ] ) ? strtolower( $project_settings['subdir_locale_map'][ $language_subdirectory ] ) : '';
     88    $locale = ! empty( $subdir_locale_map[ $language_subdirectory ] ) ? strtolower( $subdir_locale_map[ $language_subdirectory ] ) : '';
    8989
    9090    if ( ! empty( $has_language_prefix ) && preg_match( "#/{$language_subdirectory}/wp-admin#i", $server_request_uri ) ) {
     
    246246    // Non-bot request processing
    247247
    248     if ( 'js' === $publishing_mode ) {
    249       $proxy_host = "{$locale}-{$project_code}-j.app.motionpointexpress.com";
    250     } else {
    251       // Proxy mode
    252       $proxy_host = "{$locale}-{$project_code}.{$location_host}";
    253     }
    254 
    255 
    256     // Prepare headers
    257     $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
    258     $headers['Origin'] = $http_host;
    259     $headers['Host'] = $proxy_host;
    260     $headers['X-TranslationProxy-Cache-Info'] = 'disable';
    261     $headers['X-TranslationProxy-EnableDeepRoot'] = 'true';
    262     $headers['X-TranslationProxy-AllowRobots'] = 'true';
    263     $headers['X-TranslationProxy-ServingDomain'] = $http_host;
    264 
    265     // Prepare request args
    266     $proxy_request_args = array(
    267       'method'      => $request_method,
    268       'headers'     => $headers,
    269       'timeout'     => 180,
    270       'redirection' => 0,
    271     );
    272 
    273     if ( ! empty( $request_body ) ) {
    274       $proxy_request_args['body'] = $request_body;
    275     }
    276 
    277     $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
    278     $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
    279     $proxy_url = "{$request_scheme}://{$proxy_host}{$server_request_uri}";
     248    // if ( 'js' === $publishing_mode ) {
     249    //   $proxy_host = "{$locale}-{$project_code}-j.app.motionpointexpress.com";
     250    // } else {
     251    //   // Proxy mode
     252    //   $proxy_host = "{$locale}-{$project_code}.{$location_host}";
     253    // }
     254
     255
     256    // // Prepare headers
     257    // $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
     258    // $headers['Origin'] = $http_host;
     259    // $headers['Host'] = $proxy_host;
     260    // $headers['X-TranslationProxy-Cache-Info'] = 'disable';
     261    // $headers['X-TranslationProxy-EnableDeepRoot'] = 'true';
     262    // $headers['X-TranslationProxy-AllowRobots'] = 'true';
     263    // $headers['X-TranslationProxy-ServingDomain'] = $http_host;
     264
     265    // // Prepare request args
     266    // $proxy_request_args = array(
     267    //   'method'      => $request_method,
     268    //   'headers'     => $headers,
     269    //   'timeout'     => 180,
     270    //   'redirection' => 0,
     271    // );
     272
     273    // if ( ! empty( $request_body ) ) {
     274    //   $proxy_request_args['body'] = $request_body;
     275    // }
     276
     277    // $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     278    // $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
     279    // $proxy_url = "{$request_scheme}://{$proxy_host}{$server_request_uri}";
    280280
    281281    // Proxy request
    282     $response = wp_remote_request( $proxy_url, $proxy_request_args );
     282    // $response = wp_remote_request( $proxy_url, $proxy_request_args );
     283    $result = motionpointexpress()->app_request( array(
     284      'publishing_mode' => $publishing_mode,
     285      'locale'          => $locale,
     286      'project_code'    => $project_code,
     287      'location_host'   => $location_host,
     288      'request_method'  => $request_method,
     289      'request_body'    => $request_body,
     290      'request_uri'     => $server_request_uri,
     291    ) );
     292    $response = $result['response'];
     293
    283294    $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';
    284295    $response_body = is_wp_error( $response_body ) ? '' : $response_body;
  • motionpoint-express/trunk/motionpoint-express.php

    r3235656 r3236569  
    44Plugin URI: https://www.motionpointexpress.com/
    55Description: MotionPoint Express website translation solution.
    6 Version: 1.8
     6Version: 1.9
    77Author: MotionPoint Express
    88Copyright: MotionPoint Express
     
    8282  private function __construct() {
    8383    $this->settings = array(
    84       'version'  => '1.7',
     84      'version'  => '1.9',
    8585      'path'     => plugin_dir_path( __FILE__ ),
    8686      'url'      => plugin_dir_url( __FILE__ ),
     
    186186
    187187  /**
     188   *  Performs request to the app server
     189   */
     190  public function app_request( $params ) {
     191    extract( $params ); // publishing_mode, locale, project_code, location_host, request_method, request_body, request_uri
     192
     193    $timeout = 180;
     194
     195    if ( 'js' === $publishing_mode ) {
     196      $proxy_host = "{$locale}-{$project_code}-j.app.motionpointexpress.com";
     197    } else {
     198      // Proxy mode
     199      $proxy_host = "{$locale}-{$project_code}.{$location_host}";
     200    }
     201
     202
     203    // Prepare headers
     204    $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
     205    $headers['Origin'] = $http_host;
     206    $headers['Host'] = $proxy_host;
     207    $headers['X-TranslationProxy-Cache-Info'] = 'disable';
     208    $headers['X-TranslationProxy-EnableDeepRoot'] = 'true';
     209    $headers['X-TranslationProxy-AllowRobots'] = 'true';
     210    $headers['X-TranslationProxy-ServingDomain'] = $http_host;
     211
     212    // Prepare request args
     213    $proxy_request_args = array(
     214      'method'      => $request_method,
     215      'headers'     => $headers,
     216      'timeout'     => $timeout,
     217      'redirection' => 0,
     218    );
     219
     220    if ( ! empty( $request_body ) ) {
     221      $proxy_request_args['body'] = $request_body;
     222    }
     223
     224    $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     225    $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
     226    $proxy_url = "{$request_scheme}://{$proxy_host}{$request_uri}";
     227
     228    // Proxy request
     229    set_time_limit( $timeout + 10 );
     230
     231    return array(
     232      'proxy_url'          => $proxy_url,
     233      'proxy_request_args' => $proxy_request_args,
     234      'response'           => wp_remote_request( $proxy_url, $proxy_request_args ),
     235    );
     236  }
     237
     238
     239  /**
    188240   *  Initialize plugin
    189241   */
  • motionpoint-express/trunk/readme.txt

    r3235656 r3236569  
    44Requires at least: 4.7
    55Tested up to: 6.7
    6 Stable tag: 1.8
     6Stable tag: 1.9
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    7575 
    7676== Changelog ==
     77= 1.9 =
     78Release Date: February 7th, 2025
     79
     80Enhancements:
     81
     82* Connection testing feature
     83
    7784= 1.8 =
    7885Release Date: February 5th, 2025
Note: See TracChangeset for help on using the changeset viewer.