Plugin Directory

Changeset 3381078


Ignore:
Timestamp:
10/20/2025 07:06:14 AM (5 months ago)
Author:
easyling
Message:

Updating plugin to version 2.4

Location:
easyling
Files:
1 deleted
8 edited
12 copied

Legend:

Unmodified
Added
Removed
  • easyling/tags/2.4/assets/css/admin.css

    r3098777 r3381078  
    5252    display: none;
    5353}
     54#EasylingConnectionStatus {
     55    overflow-x: auto;
     56  max-width: 60vw;
     57}
  • easyling/tags/2.4/assets/js/admin.js

    r3236567 r3381078  
    4242        if (data.status) {
    4343            $('#EasylingConnectionStatus').removeClass('notice-error').addClass('notice-success');
     44
     45            // TODO: Add details
    4446        } else {
    4547            $('#EasylingConnectionStatus').removeClass('notice-success').addClass('notice-error');
     
    4951      .fail(function onFail() {
    5052        console.log('onFail');
    51         $('#EasylingConnectionStatus').removeClass('notice-success').addClass('notice-error');
     53            $('#EasylingConnectionStatus').removeClass('notice-success').addClass('notice-error');
    5254        $('#EasylingConnectionStatus').show().html( 'Unknown error occurred' );
    5355      })
  • easyling/tags/2.4/easyling.php

    r3236567 r3381078  
    44Plugin URI: https://www.easyling.com/
    55Description: One-click website translation solution from Easyling.
    6 Version: 2.3
     6Version: 2.4
    77Author: Easyling
    88Copyright: Easyling
     
    8080  private function __construct() {
    8181    $this->settings = array(
    82       'version'  => '2.3',
     82      'version'  => '2.4',
    8383      'path'     => plugin_dir_path( __FILE__ ),
    8484      'url'      => plugin_dir_url( __FILE__ ),
     
    111111    // Get from cache if not expired
    112112    $project_settings = defined('ENABLE_CACHE') ? wp_cache_get( 'project_settings', 'easyling' ) : get_transient( 'easyling_project_settings' );
     113
    113114    if ( ! empty( $project_settings ) && ! $ignore_cache ) {
    114115      // Settings are saved as encoded JSON string
     
    133134      $url = "https://{$location_host}/client/{$project_code}/0/stub.json?deployed={$deployed}";
    134135      $response = wp_remote_get( $url, array( 'timeout' => 180 ) );
     136
    135137      $response_body = wp_remote_retrieve_body( $response );
    136138
     
    184186
    185187  /**
     188   *  Test connection of the configured project
     189   */
     190  public function format_debug_array_values( $arr ) {
     191    return sprintf(
     192      '<span style="display: block; padding-left: 10px;">%s</span>',
     193      implode(
     194        '<br />',
     195        array_map(
     196          function( $key, $value ) {
     197            $value = is_array( $value ) ? easyling()->format_debug_array_values( $value ) : $value;
     198            return "{$key}: {$value}";
     199          },
     200          array_keys( $arr ),
     201          array_values( $arr )
     202        )
     203      )
     204    );
     205  }
     206
     207
     208  /**
     209   *  Test connection of the configured project
     210   */
     211  public function test_connection_request() {
     212    try {
     213      $user_config = easyling()->get_user_config();
     214
     215      $project_settings = easyling()->get_project_settings();
     216      if ( empty( $project_settings ) ) {
     217        throw new Exception( __( 'Project settings are not saved yet', 'easyling' ), 1);
     218      }
     219
     220      $subdir_locale_map = ! empty( $project_settings['subdir_locale_map'] ) ? $project_settings['subdir_locale_map'] : array();
     221      if ( empty( $subdir_locale_map ) ) {
     222        throw new Exception( __( 'Languages are not configured', 'easyling' ), 1);
     223      }
     224
     225      $location_host = $user_config['location_host'] === 'custom' ? $user_config['custom_location_host'] : $user_config['location_host'];
     226      $location_host = ! empty( $location_host ) ? trim( $location_host ) : $location_host;
     227      if ( empty( $location_host ) ) {
     228        throw new Exception( __( 'Easyling location is invalid', 'easyling' ), 1);
     229      }
     230      $locale_prefix = array_key_first( $subdir_locale_map );
     231      $locale = $subdir_locale_map[ $locale_prefix ];
     232
     233      $headers = easyling()->get_request_headers();
     234
     235      $request_details = array();
     236      add_filter( 'pre_http_request', function( $preempt, $args, $url ) use ( &$request_details ) {
     237        $request_details['preempt'] = $preempt;
     238        $request_details['args'] = $args;
     239        $request_details['url'] = $url;
     240        return false;
     241      }, 10, 3);
     242
     243      $result = easyling()->app_request( array(
     244        'publishing_mode' => $user_config['publishing_mode'],
     245        'locale'          => $locale,
     246        'project_code'    => $user_config['project_code'],
     247        'location_host'   => $location_host,
     248        'request_method'  => 'GET',
     249        'request_headers' => $headers,
     250        'request_body'    => null,
     251        'request_uri'     => "/{$locale_prefix}/",
     252        'enforce_request_protocol' => "https",
     253      ) );
     254      $response = $result['response'];
     255
     256      if ( is_wp_error( $response ) ) {
     257        $error = sprintf(
     258          __( 'Failed fetching %s, error: %s', 'easyling' ),
     259          $result['proxy_url'],
     260          $response->get_error_message()
     261        );
     262        throw new Exception( $error, 1 );
     263      }
     264
     265      if ( $response['response']['code'] !== 200 ) {
     266        $message = '';
     267        $message .= sprintf(
     268          '<strong>%s</strong>',
     269          __( 'Invalid response!', 'easyling' )
     270        );
     271        $message .= '<br />';
     272        $message .= '<br />';
     273
     274        $message .= sprintf( '<strong>Request URL:</strong> %s<br />', $result['proxy_url'] );
     275        $message .= sprintf(
     276          '<strong>Request arguments:</strong><br>%s<br>',
     277          easyling()->format_debug_array_values( $result['proxy_request_args'] )
     278        );
     279        $message .= '<br />';
     280        $message .= '<br />';
     281
     282        $message .= sprintf( '<strong>Status code:</strong> %s<br />', $response['response']['code'] );
     283        $message .= sprintf(
     284          '<strong>Headers:</strong><br>%s<br>',
     285          easyling()->format_debug_array_values( $response['headers']->getAll() )
     286        );
     287        $message .= '<br />';
     288        $message .= sprintf( '<strong>Body:</strong> <pre>%s</pre><br />', htmlspecialchars( $response['body'] ) );
     289       
     290        return array(
     291          'status' => false,
     292          'message' => $message,
     293        );
     294      }
     295
     296      return array(
     297        'request_details' => $request_details,
     298        'response'        => array(
     299          'status'  => $response['response']['code'],
     300          'headers' => $response['headers']->getAll(),
     301          'body'    => $response['body'],
     302        ),
     303        'status'          => true,
     304        'message'         => sprintf(
     305          __( 'Successfully fetched %s, response code %s', 'easyling' ),
     306          $result['proxy_url'],
     307          $response['response']['code']
     308        ),
     309      );
     310    } catch (Exception $e) {
     311      return array(
     312        'status' => false,
     313        'message' => $e->getMessage(),
     314      );
     315    }
     316  }
     317
     318
     319  /**
    186320   *  Performs request to the app server
    187321   */
     
    199333
    200334    // Prepare headers
     335    $headers = ! empty( $request_headers ) ? $request_headers : array();
    201336    $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
     337
     338    // For GET requests remove headers implying a request body
     339    if ($request_method === 'GET') {
     340      $headers = easyling()->get_sanitized_request_headers( $headers );
     341    }
     342
     343    // Set required headers
    202344    $headers['Origin'] = $http_host;
    203345    $headers['Host'] = $proxy_host;
     
    219361    }
    220362
    221     $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     363    // Ensure the body is empty for the GET requests
     364    if ( $request_method === 'GET' ) {
     365      $proxy_request_args['body'] = null;
     366    }
     367
     368    $forwarded_proto = '';
     369    if ( ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
     370      $proto_raw = strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) );
     371      if ( strpos( $proto_raw, ',' ) !== false ) {
     372        $parts = array_map( 'trim', explode( ',', $proto_raw ) );
     373        if ( in_array( 'https', $parts, true ) ) {
     374          $forwarded_proto = 'https';
     375        } elseif ( in_array( 'http', $parts, true ) ) {
     376          $forwarded_proto = 'http';
     377        } else {
     378          $forwarded_proto = reset( $parts );
     379        }
     380      } else {
     381        $forwarded_proto = $proto_raw;
     382      }
     383    }
     384
     385    $request_scheme = $forwarded_proto;
     386    if ( empty( $request_scheme ) && ! empty( $_SERVER['REQUEST_SCHEME'] ) ) {
     387      $request_scheme = strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     388    }
     389    if ( empty( $request_scheme ) ) {
     390      $request_scheme = is_ssl() ? 'https' : 'http';
     391    }
     392
     393    if ( !empty( $enforce_request_protocol) ) {
     394        $request_scheme = $enforce_request_protocol;
     395    }
     396
    222397    $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
    223398    $proxy_url = "{$request_scheme}://{$proxy_host}{$request_uri}";
     
    225400    // Proxy request
    226401    set_time_limit( $timeout + 10 );
     402
     403    $response = wp_remote_request( $proxy_url, $proxy_request_args );
    227404
    228405    return array(
    229406      'proxy_url'          => $proxy_url,
    230407      'proxy_request_args' => $proxy_request_args,
    231       'response'           => wp_remote_request( $proxy_url, $proxy_request_args ),
     408      'response'           => $response,
    232409    );
     410  }
     411
     412
     413  /**
     414   *  Sanitize headers
     415   */
     416  public function get_sanitized_request_headers( $headers = array() ) {
     417    $disallowed_get_headers = array(
     418      'Content-Type',
     419      'Content-Length',
     420      'Transfer-Encoding',
     421      'Content-Encoding',
     422      'Content-MD5',
     423    );
     424    foreach ( $disallowed_get_headers as $header_name ) {
     425      if ( isset( $headers[ $header_name ] ) ) {
     426        unset( $headers[ $header_name ] );
     427      }
     428    }
     429
     430    return $headers;
     431  }
     432
     433
     434  /**
     435   *  Parse all request headers
     436   *  Note: getallheaders works for apache only, but not nginx
     437   */
     438  public function get_request_headers() {
     439    $request_headers = array();
     440    foreach ( $_SERVER as $key => $value ) {
     441      if ( empty( $value ) ) continue;
     442
     443      $is_http_key = strpos( $key, 'HTTP_' ) === 0;
     444      $is_content_key = strpos( $key, 'CONTENT_' ) === 0;
     445      if ( $is_http_key || $is_content_key ) {
     446        $header_name = strtolower( $key );
     447        $header_name = preg_replace( '#^(HTTP_|CONTENT_)#i', '', $header_name );
     448        $header_name = str_replace( '_', ' ', $header_name );
     449        $header_name = ucwords( $header_name );
     450        $header_name = str_replace( ' ', '-', $header_name );
     451        $request_headers[ $header_name ] = $value;
     452      }
     453    }
     454
     455    return $request_headers;
    233456  }
    234457
     
    333556}
    334557
    335 
    336558// initialize
    337559easyling();
  • easyling/tags/2.4/inc/admin.php

    r3236567 r3381078  
    407407      check_ajax_referer( 'easyling_test_connection', 'nonce' );
    408408
    409       $user_config = easyling()->get_user_config();
    410 
    411       $project_settings = easyling()->get_project_settings();
    412       if ( empty( $project_settings ) ) {
    413         throw new Exception( __( 'Project settings are not saved yet', 'easyling' ), 1);
    414       }
    415 
    416       $subdir_locale_map = ! empty( $project_settings['subdir_locale_map'] ) ? $project_settings['subdir_locale_map'] : array();
    417       if ( empty( $subdir_locale_map ) ) {
    418         throw new Exception( __( 'Languages are not configured', 'easyling' ), 1);
    419       }
    420 
    421       $location_host = $user_config['location_host'] === 'custom' ? $user_config['custom_location_host'] : $user_config['location_host'];
    422       $location_host = ! empty( $location_host ) ? trim( $location_host ) : $location_host;
    423       if ( empty( $location_host ) ) {
    424         throw new Exception( __( 'Easyling location is invalid', 'easyling' ), 1);
    425       }
    426       $locale_prefix = array_key_first( $subdir_locale_map );
    427       $locale = $subdir_locale_map[ $locale_prefix ];
    428 
    429       $result = easyling()->app_request( array(
    430         'publishing_mode' => $user_config['publishing_mode'],
    431         'locale'          => $locale,
    432         'project_code'    => $user_config['project_code'],
    433         'location_host'   => $location_host,
    434         'request_method'  => 'GET',
    435         'request_body'    => null,
    436         'request_uri'     => "/{$locale_prefix}/",
    437       ) );
    438       $response = $result['response'];
    439 
    440       if ( is_wp_error( $response ) ) {
    441         $error = sprintf(
    442           __( 'Failed fetching %s, error: %s', 'easyling' ),
    443           $result['proxy_url'],
    444           $response->get_error_message()
    445         );
    446         throw new Exception( $error, 1 );
    447       }
    448 
    449       echo json_encode( array(
    450         'result' => $result,
    451         'status' => true,
    452         'message' => sprintf(
    453           __( 'Successfully fetched %s, response code %s', 'easyling' ),
    454           $result['proxy_url'],
    455           $response['response']['code']
    456         ),
    457       ) );
     409      $test_connection_result = easyling()->test_connection_request();
     410      echo json_encode( $test_connection_result );
    458411    } catch (Exception $e) {
    459412      echo json_encode( array(
  • easyling/tags/2.4/inc/frontend.php

    r3236567 r3381078  
    4848   */
    4949  public function handle_request() {
    50     $headers = $this->get_request_headers();
     50    $headers = easyling()->get_request_headers();
    5151
    5252    $user_config = easyling()->get_user_config();
     
    125125          wp_enqueue_script( 'easyling-stub', "https://{$location_host}/client/{$project_code}/0/stub.js?deployed={$deployed_value}{$floating_language_selector_param}", array(), null, true );
    126126        } if ( 'proxy' === $publishing_mode ) {
    127           wp_enqueue_script( 'easyling-language-selector', "https://{$location_host}/_el/ext/js/languageSelector.js?code={$project_code}", array(), null, true );
     127          //wp_enqueue_script( 'easyling-language-selector', "https://{$location_host}/_el/ext/js/languageSelector.js?code={$project_code}", array(), null, true );
     128          wp_enqueue_script( 'easyling-language-selector', "https://{$location_host}/js/webtranslate/languageDropdown.js?crest=0&code={$project_code}&v=3", array(), null, true );
    128129        }
    129130      } );
     
    236237
    237238      $response = wp_remote_request( $prerender_url, $request_args );
    238       $response_body = wp_remote_retrieve_body( $response );
    239       $response_body = is_wp_error( $response_body ) ? '' : $response_body;
     239      $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';
     240      $response_body = ! is_wp_error( $response_body ) ? $response_body : '';
    240241
    241242      print( $response_body );
     
    252253      'location_host'   => $location_host,
    253254      'request_method'  => $request_method,
     255      'request_headers' => $headers,
    254256      'request_body'    => $request_body,
    255257      'request_uri'     => $server_request_uri,
     
    257259    $response = $result['response'];
    258260    $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';
    259     $response_body = is_wp_error( $response_body ) ? '' : $response_body;
     261    $response_body = ! is_wp_error( $response_body ) ? $response_body : '';
    260262    $proxy_response_headers = ! is_wp_error( $response ) && ! empty( $response['headers'] ) ? $response['headers']->getAll() : array();
    261263
     
    326328
    327329    return $should_prerender;
    328   }
    329 
    330 
    331   /**
    332    *  Parse all request headers
    333    *  Note: getallheaders works for apache only, but not nginx
    334    */
    335   public function get_request_headers() {
    336     $request_headers = array();
    337     foreach ( $_SERVER as $key => $value ) {
    338       if ( empty( $value ) ) continue;
    339 
    340       $is_http_key = strpos( $key, 'HTTP_' ) === 0;
    341       $is_content_key = strpos( $key, 'CONTENT_' ) === 0;
    342       if ( $is_http_key || $is_content_key ) {
    343         $header_name = strtolower( $key );
    344         $header_name = preg_replace( '#^(HTTP_|CONTENT_)#i', '', $header_name );
    345         $header_name = str_replace( '_', ' ', $header_name );
    346         $header_name = ucwords( $header_name );
    347         $header_name = str_replace( ' ', '-', $header_name );
    348         $request_headers[ $header_name ] = $value;
    349       }
    350     }
    351 
    352     return $request_headers;
    353330  }
    354331
  • easyling/tags/2.4/inc/integration/menus.php

    r3035191 r3381078  
    8080                        <li>
    8181                            <label class="menu-item-title">
    82                                 <input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1" /> <?php echo esc_html( __('Language Selector', 'easyling') ); ?>
     82                                <input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1" /> <?php echo esc_html( __('EL Language Selector', 'easyling') ); ?>
    8383                            </label>
    8484                            <input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="custom" />
    85                             <input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="<?php echo esc_attr( __('Language Selector', 'easyling') ); ?>" />
     85                            <input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="<?php echo esc_attr( __('EL Language Selector', 'easyling') ); ?>" />
    8686                            <input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value="#easyling-language-selector" />
    8787                            <input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" />
     
    142142        $items[] = array(
    143143            'id'         => 'easyling_language_selector',
    144             'title'      => __('Language Selector', 'easyling'),
     144            'title'      => __('EL Language Selector', 'easyling'),
    145145            'type'       => 'custom',
    146146            'url'        => '#easyling-language-selector',
  • easyling/tags/2.4/readme.txt

    r3236567 r3381078  
    44Requires at least: 4.7
    55Tested up to: 6.7
    6 Stable tag: 2.3
     6Stable tag: 2.4
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    4444
    4545== Changelog ==
     46= 2.4 =
     47Release Date: October 20th, 2025
     48
     49Enhancements:
     50
     51* Minor improvements to the frontend and admin
     52
    4653= 2.3 =
    4754Release Date: February 7th, 2025
  • easyling/trunk/assets/css/admin.css

    r3098777 r3381078  
    5252    display: none;
    5353}
     54#EasylingConnectionStatus {
     55    overflow-x: auto;
     56  max-width: 60vw;
     57}
  • easyling/trunk/assets/js/admin.js

    r3236567 r3381078  
    4242        if (data.status) {
    4343            $('#EasylingConnectionStatus').removeClass('notice-error').addClass('notice-success');
     44
     45            // TODO: Add details
    4446        } else {
    4547            $('#EasylingConnectionStatus').removeClass('notice-success').addClass('notice-error');
     
    4951      .fail(function onFail() {
    5052        console.log('onFail');
    51         $('#EasylingConnectionStatus').removeClass('notice-success').addClass('notice-error');
     53            $('#EasylingConnectionStatus').removeClass('notice-success').addClass('notice-error');
    5254        $('#EasylingConnectionStatus').show().html( 'Unknown error occurred' );
    5355      })
  • easyling/trunk/easyling.php

    r3236567 r3381078  
    44Plugin URI: https://www.easyling.com/
    55Description: One-click website translation solution from Easyling.
    6 Version: 2.3
     6Version: 2.4
    77Author: Easyling
    88Copyright: Easyling
     
    8080  private function __construct() {
    8181    $this->settings = array(
    82       'version'  => '2.3',
     82      'version'  => '2.4',
    8383      'path'     => plugin_dir_path( __FILE__ ),
    8484      'url'      => plugin_dir_url( __FILE__ ),
     
    111111    // Get from cache if not expired
    112112    $project_settings = defined('ENABLE_CACHE') ? wp_cache_get( 'project_settings', 'easyling' ) : get_transient( 'easyling_project_settings' );
     113
    113114    if ( ! empty( $project_settings ) && ! $ignore_cache ) {
    114115      // Settings are saved as encoded JSON string
     
    133134      $url = "https://{$location_host}/client/{$project_code}/0/stub.json?deployed={$deployed}";
    134135      $response = wp_remote_get( $url, array( 'timeout' => 180 ) );
     136
    135137      $response_body = wp_remote_retrieve_body( $response );
    136138
     
    184186
    185187  /**
     188   *  Test connection of the configured project
     189   */
     190  public function format_debug_array_values( $arr ) {
     191    return sprintf(
     192      '<span style="display: block; padding-left: 10px;">%s</span>',
     193      implode(
     194        '<br />',
     195        array_map(
     196          function( $key, $value ) {
     197            $value = is_array( $value ) ? easyling()->format_debug_array_values( $value ) : $value;
     198            return "{$key}: {$value}";
     199          },
     200          array_keys( $arr ),
     201          array_values( $arr )
     202        )
     203      )
     204    );
     205  }
     206
     207
     208  /**
     209   *  Test connection of the configured project
     210   */
     211  public function test_connection_request() {
     212    try {
     213      $user_config = easyling()->get_user_config();
     214
     215      $project_settings = easyling()->get_project_settings();
     216      if ( empty( $project_settings ) ) {
     217        throw new Exception( __( 'Project settings are not saved yet', 'easyling' ), 1);
     218      }
     219
     220      $subdir_locale_map = ! empty( $project_settings['subdir_locale_map'] ) ? $project_settings['subdir_locale_map'] : array();
     221      if ( empty( $subdir_locale_map ) ) {
     222        throw new Exception( __( 'Languages are not configured', 'easyling' ), 1);
     223      }
     224
     225      $location_host = $user_config['location_host'] === 'custom' ? $user_config['custom_location_host'] : $user_config['location_host'];
     226      $location_host = ! empty( $location_host ) ? trim( $location_host ) : $location_host;
     227      if ( empty( $location_host ) ) {
     228        throw new Exception( __( 'Easyling location is invalid', 'easyling' ), 1);
     229      }
     230      $locale_prefix = array_key_first( $subdir_locale_map );
     231      $locale = $subdir_locale_map[ $locale_prefix ];
     232
     233      $headers = easyling()->get_request_headers();
     234
     235      $request_details = array();
     236      add_filter( 'pre_http_request', function( $preempt, $args, $url ) use ( &$request_details ) {
     237        $request_details['preempt'] = $preempt;
     238        $request_details['args'] = $args;
     239        $request_details['url'] = $url;
     240        return false;
     241      }, 10, 3);
     242
     243      $result = easyling()->app_request( array(
     244        'publishing_mode' => $user_config['publishing_mode'],
     245        'locale'          => $locale,
     246        'project_code'    => $user_config['project_code'],
     247        'location_host'   => $location_host,
     248        'request_method'  => 'GET',
     249        'request_headers' => $headers,
     250        'request_body'    => null,
     251        'request_uri'     => "/{$locale_prefix}/",
     252        'enforce_request_protocol' => "https",
     253      ) );
     254      $response = $result['response'];
     255
     256      if ( is_wp_error( $response ) ) {
     257        $error = sprintf(
     258          __( 'Failed fetching %s, error: %s', 'easyling' ),
     259          $result['proxy_url'],
     260          $response->get_error_message()
     261        );
     262        throw new Exception( $error, 1 );
     263      }
     264
     265      if ( $response['response']['code'] !== 200 ) {
     266        $message = '';
     267        $message .= sprintf(
     268          '<strong>%s</strong>',
     269          __( 'Invalid response!', 'easyling' )
     270        );
     271        $message .= '<br />';
     272        $message .= '<br />';
     273
     274        $message .= sprintf( '<strong>Request URL:</strong> %s<br />', $result['proxy_url'] );
     275        $message .= sprintf(
     276          '<strong>Request arguments:</strong><br>%s<br>',
     277          easyling()->format_debug_array_values( $result['proxy_request_args'] )
     278        );
     279        $message .= '<br />';
     280        $message .= '<br />';
     281
     282        $message .= sprintf( '<strong>Status code:</strong> %s<br />', $response['response']['code'] );
     283        $message .= sprintf(
     284          '<strong>Headers:</strong><br>%s<br>',
     285          easyling()->format_debug_array_values( $response['headers']->getAll() )
     286        );
     287        $message .= '<br />';
     288        $message .= sprintf( '<strong>Body:</strong> <pre>%s</pre><br />', htmlspecialchars( $response['body'] ) );
     289       
     290        return array(
     291          'status' => false,
     292          'message' => $message,
     293        );
     294      }
     295
     296      return array(
     297        'request_details' => $request_details,
     298        'response'        => array(
     299          'status'  => $response['response']['code'],
     300          'headers' => $response['headers']->getAll(),
     301          'body'    => $response['body'],
     302        ),
     303        'status'          => true,
     304        'message'         => sprintf(
     305          __( 'Successfully fetched %s, response code %s', 'easyling' ),
     306          $result['proxy_url'],
     307          $response['response']['code']
     308        ),
     309      );
     310    } catch (Exception $e) {
     311      return array(
     312        'status' => false,
     313        'message' => $e->getMessage(),
     314      );
     315    }
     316  }
     317
     318
     319  /**
    186320   *  Performs request to the app server
    187321   */
     
    199333
    200334    // Prepare headers
     335    $headers = ! empty( $request_headers ) ? $request_headers : array();
    201336    $http_host = sanitize_text_field( $_SERVER['HTTP_HOST'] );
     337
     338    // For GET requests remove headers implying a request body
     339    if ($request_method === 'GET') {
     340      $headers = easyling()->get_sanitized_request_headers( $headers );
     341    }
     342
     343    // Set required headers
    202344    $headers['Origin'] = $http_host;
    203345    $headers['Host'] = $proxy_host;
     
    219361    }
    220362
    221     $request_scheme = ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ? strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) : strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     363    // Ensure the body is empty for the GET requests
     364    if ( $request_method === 'GET' ) {
     365      $proxy_request_args['body'] = null;
     366    }
     367
     368    $forwarded_proto = '';
     369    if ( ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
     370      $proto_raw = strtolower( sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) );
     371      if ( strpos( $proto_raw, ',' ) !== false ) {
     372        $parts = array_map( 'trim', explode( ',', $proto_raw ) );
     373        if ( in_array( 'https', $parts, true ) ) {
     374          $forwarded_proto = 'https';
     375        } elseif ( in_array( 'http', $parts, true ) ) {
     376          $forwarded_proto = 'http';
     377        } else {
     378          $forwarded_proto = reset( $parts );
     379        }
     380      } else {
     381        $forwarded_proto = $proto_raw;
     382      }
     383    }
     384
     385    $request_scheme = $forwarded_proto;
     386    if ( empty( $request_scheme ) && ! empty( $_SERVER['REQUEST_SCHEME'] ) ) {
     387      $request_scheme = strtolower( sanitize_text_field( $_SERVER['REQUEST_SCHEME'] ) );
     388    }
     389    if ( empty( $request_scheme ) ) {
     390      $request_scheme = is_ssl() ? 'https' : 'http';
     391    }
     392
     393    if ( !empty( $enforce_request_protocol) ) {
     394        $request_scheme = $enforce_request_protocol;
     395    }
     396
    222397    $request_scheme = in_array( $request_scheme, array( 'http', 'https' ) ) ? $request_scheme : 'https';
    223398    $proxy_url = "{$request_scheme}://{$proxy_host}{$request_uri}";
     
    225400    // Proxy request
    226401    set_time_limit( $timeout + 10 );
     402
     403    $response = wp_remote_request( $proxy_url, $proxy_request_args );
    227404
    228405    return array(
    229406      'proxy_url'          => $proxy_url,
    230407      'proxy_request_args' => $proxy_request_args,
    231       'response'           => wp_remote_request( $proxy_url, $proxy_request_args ),
     408      'response'           => $response,
    232409    );
     410  }
     411
     412
     413  /**
     414   *  Sanitize headers
     415   */
     416  public function get_sanitized_request_headers( $headers = array() ) {
     417    $disallowed_get_headers = array(
     418      'Content-Type',
     419      'Content-Length',
     420      'Transfer-Encoding',
     421      'Content-Encoding',
     422      'Content-MD5',
     423    );
     424    foreach ( $disallowed_get_headers as $header_name ) {
     425      if ( isset( $headers[ $header_name ] ) ) {
     426        unset( $headers[ $header_name ] );
     427      }
     428    }
     429
     430    return $headers;
     431  }
     432
     433
     434  /**
     435   *  Parse all request headers
     436   *  Note: getallheaders works for apache only, but not nginx
     437   */
     438  public function get_request_headers() {
     439    $request_headers = array();
     440    foreach ( $_SERVER as $key => $value ) {
     441      if ( empty( $value ) ) continue;
     442
     443      $is_http_key = strpos( $key, 'HTTP_' ) === 0;
     444      $is_content_key = strpos( $key, 'CONTENT_' ) === 0;
     445      if ( $is_http_key || $is_content_key ) {
     446        $header_name = strtolower( $key );
     447        $header_name = preg_replace( '#^(HTTP_|CONTENT_)#i', '', $header_name );
     448        $header_name = str_replace( '_', ' ', $header_name );
     449        $header_name = ucwords( $header_name );
     450        $header_name = str_replace( ' ', '-', $header_name );
     451        $request_headers[ $header_name ] = $value;
     452      }
     453    }
     454
     455    return $request_headers;
    233456  }
    234457
     
    333556}
    334557
    335 
    336558// initialize
    337559easyling();
  • easyling/trunk/inc/admin.php

    r3236567 r3381078  
    407407      check_ajax_referer( 'easyling_test_connection', 'nonce' );
    408408
    409       $user_config = easyling()->get_user_config();
    410 
    411       $project_settings = easyling()->get_project_settings();
    412       if ( empty( $project_settings ) ) {
    413         throw new Exception( __( 'Project settings are not saved yet', 'easyling' ), 1);
    414       }
    415 
    416       $subdir_locale_map = ! empty( $project_settings['subdir_locale_map'] ) ? $project_settings['subdir_locale_map'] : array();
    417       if ( empty( $subdir_locale_map ) ) {
    418         throw new Exception( __( 'Languages are not configured', 'easyling' ), 1);
    419       }
    420 
    421       $location_host = $user_config['location_host'] === 'custom' ? $user_config['custom_location_host'] : $user_config['location_host'];
    422       $location_host = ! empty( $location_host ) ? trim( $location_host ) : $location_host;
    423       if ( empty( $location_host ) ) {
    424         throw new Exception( __( 'Easyling location is invalid', 'easyling' ), 1);
    425       }
    426       $locale_prefix = array_key_first( $subdir_locale_map );
    427       $locale = $subdir_locale_map[ $locale_prefix ];
    428 
    429       $result = easyling()->app_request( array(
    430         'publishing_mode' => $user_config['publishing_mode'],
    431         'locale'          => $locale,
    432         'project_code'    => $user_config['project_code'],
    433         'location_host'   => $location_host,
    434         'request_method'  => 'GET',
    435         'request_body'    => null,
    436         'request_uri'     => "/{$locale_prefix}/",
    437       ) );
    438       $response = $result['response'];
    439 
    440       if ( is_wp_error( $response ) ) {
    441         $error = sprintf(
    442           __( 'Failed fetching %s, error: %s', 'easyling' ),
    443           $result['proxy_url'],
    444           $response->get_error_message()
    445         );
    446         throw new Exception( $error, 1 );
    447       }
    448 
    449       echo json_encode( array(
    450         'result' => $result,
    451         'status' => true,
    452         'message' => sprintf(
    453           __( 'Successfully fetched %s, response code %s', 'easyling' ),
    454           $result['proxy_url'],
    455           $response['response']['code']
    456         ),
    457       ) );
     409      $test_connection_result = easyling()->test_connection_request();
     410      echo json_encode( $test_connection_result );
    458411    } catch (Exception $e) {
    459412      echo json_encode( array(
  • easyling/trunk/inc/frontend.php

    r3236567 r3381078  
    4848   */
    4949  public function handle_request() {
    50     $headers = $this->get_request_headers();
     50    $headers = easyling()->get_request_headers();
    5151
    5252    $user_config = easyling()->get_user_config();
     
    125125          wp_enqueue_script( 'easyling-stub', "https://{$location_host}/client/{$project_code}/0/stub.js?deployed={$deployed_value}{$floating_language_selector_param}", array(), null, true );
    126126        } if ( 'proxy' === $publishing_mode ) {
    127           wp_enqueue_script( 'easyling-language-selector', "https://{$location_host}/_el/ext/js/languageSelector.js?code={$project_code}", array(), null, true );
     127          //wp_enqueue_script( 'easyling-language-selector', "https://{$location_host}/_el/ext/js/languageSelector.js?code={$project_code}", array(), null, true );
     128          wp_enqueue_script( 'easyling-language-selector', "https://{$location_host}/js/webtranslate/languageDropdown.js?crest=0&code={$project_code}&v=3", array(), null, true );
    128129        }
    129130      } );
     
    236237
    237238      $response = wp_remote_request( $prerender_url, $request_args );
    238       $response_body = wp_remote_retrieve_body( $response );
    239       $response_body = is_wp_error( $response_body ) ? '' : $response_body;
     239      $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';
     240      $response_body = ! is_wp_error( $response_body ) ? $response_body : '';
    240241
    241242      print( $response_body );
     
    252253      'location_host'   => $location_host,
    253254      'request_method'  => $request_method,
     255      'request_headers' => $headers,
    254256      'request_body'    => $request_body,
    255257      'request_uri'     => $server_request_uri,
     
    257259    $response = $result['response'];
    258260    $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';
    259     $response_body = is_wp_error( $response_body ) ? '' : $response_body;
     261    $response_body = ! is_wp_error( $response_body ) ? $response_body : '';
    260262    $proxy_response_headers = ! is_wp_error( $response ) && ! empty( $response['headers'] ) ? $response['headers']->getAll() : array();
    261263
     
    326328
    327329    return $should_prerender;
    328   }
    329 
    330 
    331   /**
    332    *  Parse all request headers
    333    *  Note: getallheaders works for apache only, but not nginx
    334    */
    335   public function get_request_headers() {
    336     $request_headers = array();
    337     foreach ( $_SERVER as $key => $value ) {
    338       if ( empty( $value ) ) continue;
    339 
    340       $is_http_key = strpos( $key, 'HTTP_' ) === 0;
    341       $is_content_key = strpos( $key, 'CONTENT_' ) === 0;
    342       if ( $is_http_key || $is_content_key ) {
    343         $header_name = strtolower( $key );
    344         $header_name = preg_replace( '#^(HTTP_|CONTENT_)#i', '', $header_name );
    345         $header_name = str_replace( '_', ' ', $header_name );
    346         $header_name = ucwords( $header_name );
    347         $header_name = str_replace( ' ', '-', $header_name );
    348         $request_headers[ $header_name ] = $value;
    349       }
    350     }
    351 
    352     return $request_headers;
    353330  }
    354331
  • easyling/trunk/inc/integration/menus.php

    r3035191 r3381078  
    8080                        <li>
    8181                            <label class="menu-item-title">
    82                                 <input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1" /> <?php echo esc_html( __('Language Selector', 'easyling') ); ?>
     82                                <input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1" /> <?php echo esc_html( __('EL Language Selector', 'easyling') ); ?>
    8383                            </label>
    8484                            <input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="custom" />
    85                             <input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="<?php echo esc_attr( __('Language Selector', 'easyling') ); ?>" />
     85                            <input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="<?php echo esc_attr( __('EL Language Selector', 'easyling') ); ?>" />
    8686                            <input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value="#easyling-language-selector" />
    8787                            <input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" />
     
    142142        $items[] = array(
    143143            'id'         => 'easyling_language_selector',
    144             'title'      => __('Language Selector', 'easyling'),
     144            'title'      => __('EL Language Selector', 'easyling'),
    145145            'type'       => 'custom',
    146146            'url'        => '#easyling-language-selector',
  • easyling/trunk/readme.txt

    r3236567 r3381078  
    44Requires at least: 4.7
    55Tested up to: 6.7
    6 Stable tag: 2.3
     6Stable tag: 2.4
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    4444
    4545== Changelog ==
     46= 2.4 =
     47Release Date: October 20th, 2025
     48
     49Enhancements:
     50
     51* Minor improvements to the frontend and admin
     52
    4653= 2.3 =
    4754Release Date: February 7th, 2025
Note: See TracChangeset for help on using the changeset viewer.