Translate WordPress with GTranslate - Version 2.8.35

Version Description

  • Admin notice added for conflicting plugins
  • Disabled translation of non-selected languages when accessed directly in sub-directory URL structure mode
  • Update to WordPress 4.9.1 before updating GTranslate
  • Fixed update issue related to bug in new WP 4.9 flatten_dirlist function
Download this release

Release Info

Developer edo888
Plugin Icon 128x128 Translate WordPress with GTranslate
Version 2.8.35
Comparing to
See all releases

Code changes from version 2.8.32 to 2.8.35

Files changed (4) hide show
  1. 24/Morocco.png +0 -0
  2. gtranslate.php +47 -15
  3. readme.txt +14 -1
  4. url_addon/gtranslate.php +232 -222
24/Morocco.png DELETED
Binary file
gtranslate.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: GTranslate
4
  Plugin URI: https://gtranslate.io/?xyz=998
5
  Description: Makes your website <strong>multilingual</strong> and available to the world using Google Translate. For support visit <a href="https://wordpress.org/support/plugin/gtranslate">GTranslate Support</a>.
6
- Version: 2.8.32
7
  Author: Translate AI Multilingual Solutions
8
  Author URI: https://gtranslate.io
9
  Text Domain: gtranslate
@@ -230,7 +230,6 @@ class GTranslate extends WP_Widget {
230
  public static function admin_menu() {
231
  add_options_page(__('GTranslate Options', 'gtranslate'), 'GTranslate', 'administrator', 'gtranslate_options', array('GTranslate', 'options'));
232
 
233
- deactivate_plugins(array('wptranslator/WPTranslator.php', 'translatepress-multilingual/index.php', 'google-language-translator/google-language-translator.php', 'google-website-translator/google-website-translator.php', 'weglot/weglot.php'), true);
234
  }
235
 
236
  public static function options() {
@@ -247,6 +246,14 @@ class GTranslate extends WP_Widget {
247
  wp_enqueue_script('jquery-ui-sortable');
248
  wp_enqueue_script('jquery-effects-core');
249
 
 
 
 
 
 
 
 
 
250
  $site_url = site_url();
251
  $wp_plugin_url = preg_replace('/^https?:/i', '', plugins_url() . '/gtranslate');
252
 
@@ -727,14 +734,14 @@ function RefreshDoWidgetCode() {
727
  } else if(enterprise_version && translation_method == 'redirect' && new_window) {
728
  widget_code += "function openTab(url) {var form=document.createElement('form');form.method='post';form.action=url;form.target='_blank';document.body.appendChild(form);form.submit();}"+new_line;
729
  if(analytics)
730
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\\\\\.'), '')+gt_request_uri);}"+new_line;
731
  else
732
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\\\\\.'), '')+gt_request_uri);}"+new_line;
733
  } else if(enterprise_version && translation_method == 'redirect') {
734
  if(analytics)
735
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\\\\\.'), '')+gt_request_uri;}"+new_line;
736
  else
737
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\\\\\\\\.'), '')+gt_request_uri;}"+new_line;
738
  } else if(translation_method == 'onfly') {
739
  widget_code += "function GTranslateGetCurrentLang() {var keyValue = document['cookie'].match('(^|;) ?googtrans=([^;]*)(;|$)');return keyValue ? keyValue[2].split('/')[2] : null;}"+new_line;
740
  widget_code += "function GTranslateFireEvent(element,event){try{if(document.createEventObject){var evt=document.createEventObject();element.fireEvent('on'+event,evt)}else{var evt=document.createEvent('HTMLEvents');evt.initEvent(event,true,true);element.dispatchEvent(evt)}}catch(e){}}"+new_line;
@@ -1327,6 +1334,7 @@ EOT;
1327
 
1328
  if($data['pro_version']) { // check if rewrite rules are in place
1329
  $htaccess_file = get_home_path() . '.htaccess';
 
1330
  if(is_writeable($htaccess_file)) {
1331
  $htaccess = file_get_contents($htaccess_file);
1332
  if(strpos($htaccess, 'gtranslate.php') === false) { // no config rules
@@ -1471,7 +1479,7 @@ class GTranslateWidget extends WP_Widget {
1471
  class GTranslate_Notices {
1472
  protected $prefix = 'gtranslate';
1473
  public $notice_spam = 0;
1474
- public $notice_spam_max = 1;
1475
 
1476
  // Basic actions to run
1477
  public function __construct() {
@@ -1550,6 +1558,7 @@ class GTranslate_Notices {
1550
  $admin_display_msg = (isset($admin_notices[$slug]['msg']) ? $admin_notices[$slug]['msg'] : '');
1551
  $admin_display_title = (isset($admin_notices[$slug]['title']) ? $admin_notices[$slug]['title'] : '');
1552
  $admin_display_link = (isset($admin_notices[$slug]['link']) ? $admin_notices[$slug]['link'] : '');
 
1553
  $output_css = false;
1554
 
1555
  // Ensure the notice hasn't been hidden and that the current date is after the start date
@@ -1569,7 +1578,8 @@ class GTranslate_Notices {
1569
  echo '<ul class="gt-notice-body gt-red">
1570
  ' . $admin_display_link . '
1571
  </ul>';
1572
- echo '<a href="' . $query_str . '" class="dashicons dashicons-dismiss"></a>';
 
1573
  echo '</div>';
1574
 
1575
  $this->notice_spam += 1;
@@ -1674,6 +1684,21 @@ class GTranslate_Notices {
1674
  }
1675
 
1676
  public function gt_admin_notices() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1677
  /*
1678
  $one_week_support = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'one_week_support')));
1679
 
@@ -1698,7 +1723,7 @@ class GTranslate_Notices {
1698
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1699
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1700
  'later_link' => $two_week_review_temp,
1701
- 'int' => 3
1702
  );
1703
 
1704
  $data = get_option('GTranslate');
@@ -1715,7 +1740,7 @@ class GTranslate_Notices {
1715
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1716
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1717
  'later_link' => $upgrade_tips_temp,
1718
- 'int' => 5
1719
  );
1720
 
1721
  $notices['upgrade_tips'][] = array(
@@ -1725,7 +1750,7 @@ class GTranslate_Notices {
1725
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1726
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1727
  'later_link' => $upgrade_tips_temp,
1728
- 'int' => 5
1729
  );
1730
 
1731
  $notices['upgrade_tips'][] = array(
@@ -1735,7 +1760,7 @@ class GTranslate_Notices {
1735
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1736
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1737
  'later_link' => $upgrade_tips_temp,
1738
- 'int' => 5
1739
  );
1740
 
1741
  $notices['upgrade_tips'][] = array(
@@ -1745,7 +1770,7 @@ class GTranslate_Notices {
1745
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1746
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1747
  'later_link' => $upgrade_tips_temp,
1748
- 'int' => 5
1749
  );
1750
 
1751
  $notices['upgrade_tips'][] = array(
@@ -1755,7 +1780,7 @@ class GTranslate_Notices {
1755
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1756
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1757
  'later_link' => $upgrade_tips_temp,
1758
- 'int' => 5
1759
  );
1760
 
1761
  shuffle($notices['upgrade_tips']);
@@ -1791,7 +1816,14 @@ if($data['pro_version']) { // gtranslate redirect rules with PHP (for environmen
1791
  exit;
1792
  } // #2 add trailing slash
1793
 
1794
- if(preg_match('/^\/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)\/(.*)/', $request_uri, $matches)) {
 
 
 
 
 
 
 
1795
  $_GET['glang'] = $matches[1];
1796
  $_GET['gurl'] = rawurldecode($matches[2]);
1797
 
3
  Plugin Name: GTranslate
4
  Plugin URI: https://gtranslate.io/?xyz=998
5
  Description: Makes your website <strong>multilingual</strong> and available to the world using Google Translate. For support visit <a href="https://wordpress.org/support/plugin/gtranslate">GTranslate Support</a>.
6
+ Version: 2.8.35
7
  Author: Translate AI Multilingual Solutions
8
  Author URI: https://gtranslate.io
9
  Text Domain: gtranslate
230
  public static function admin_menu() {
231
  add_options_page(__('GTranslate Options', 'gtranslate'), 'GTranslate', 'administrator', 'gtranslate_options', array('GTranslate', 'options'));
232
 
 
233
  }
234
 
235
  public static function options() {
246
  wp_enqueue_script('jquery-ui-sortable');
247
  wp_enqueue_script('jquery-effects-core');
248
 
249
+ /* code editor for widget_code textarea
250
+ if(function_exists('wp_enqueue_code_editor')) {
251
+ $editor_settings = wp_enqueue_code_editor(array('type' => 'text/html'));
252
+ if($editor_settings !== false)
253
+ wp_add_inline_script('code-editor', sprintf('jQuery(function() {wp.codeEditor.initialize("widget_code", %s);});', wp_json_encode($editor_settings)));
254
+ }
255
+ */
256
+
257
  $site_url = site_url();
258
  $wp_plugin_url = preg_replace('/^https?:/i', '', plugins_url() . '/gtranslate');
259
 
734
  } else if(enterprise_version && translation_method == 'redirect' && new_window) {
735
  widget_code += "function openTab(url) {var form=document.createElement('form');form.method='post';form.action=url;form.target='_blank';document.body.appendChild(form);form.submit();}"+new_line;
736
  if(analytics)
737
+ widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+gt_request_uri);}"+new_line;
738
  else
739
+ widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+gt_request_uri);}"+new_line;
740
  } else if(enterprise_version && translation_method == 'redirect') {
741
  if(analytics)
742
+ widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+gt_request_uri;}"+new_line;
743
  else
744
+ widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+gt_request_uri;}"+new_line;
745
  } else if(translation_method == 'onfly') {
746
  widget_code += "function GTranslateGetCurrentLang() {var keyValue = document['cookie'].match('(^|;) ?googtrans=([^;]*)(;|$)');return keyValue ? keyValue[2].split('/')[2] : null;}"+new_line;
747
  widget_code += "function GTranslateFireEvent(element,event){try{if(document.createEventObject){var evt=document.createEventObject();element.fireEvent('on'+event,evt)}else{var evt=document.createEvent('HTMLEvents');evt.initEvent(event,true,true);element.dispatchEvent(evt)}}catch(e){}}"+new_line;
1334
 
1335
  if($data['pro_version']) { // check if rewrite rules are in place
1336
  $htaccess_file = get_home_path() . '.htaccess';
1337
+ // todo: use insert_with_markers functions instead
1338
  if(is_writeable($htaccess_file)) {
1339
  $htaccess = file_get_contents($htaccess_file);
1340
  if(strpos($htaccess, 'gtranslate.php') === false) { // no config rules
1479
  class GTranslate_Notices {
1480
  protected $prefix = 'gtranslate';
1481
  public $notice_spam = 0;
1482
+ public $notice_spam_max = 3;
1483
 
1484
  // Basic actions to run
1485
  public function __construct() {
1558
  $admin_display_msg = (isset($admin_notices[$slug]['msg']) ? $admin_notices[$slug]['msg'] : '');
1559
  $admin_display_title = (isset($admin_notices[$slug]['title']) ? $admin_notices[$slug]['title'] : '');
1560
  $admin_display_link = (isset($admin_notices[$slug]['link']) ? $admin_notices[$slug]['link'] : '');
1561
+ $admin_display_dismissible= (isset($admin_notices[$slug]['dismissible']) ? $admin_notices[$slug]['dismissible'] : true);
1562
  $output_css = false;
1563
 
1564
  // Ensure the notice hasn't been hidden and that the current date is after the start date
1578
  echo '<ul class="gt-notice-body gt-red">
1579
  ' . $admin_display_link . '
1580
  </ul>';
1581
+ if($admin_display_dismissible)
1582
+ echo '<a href="' . $query_str . '" class="dashicons dashicons-dismiss"></a>';
1583
  echo '</div>';
1584
 
1585
  $this->notice_spam += 1;
1684
  }
1685
 
1686
  public function gt_admin_notices() {
1687
+
1688
+ $deactivate_plugins= array('WP Translator' => 'wptranslator/WPTranslator.php', 'TranslatePress' => 'translatepress-multilingual/index.php', 'Google Language Translator' => 'google-language-translator/google-language-translator.php', 'Google Website Translator' => 'google-website-translator/google-website-translator.php', 'Weglot' => 'weglot/weglot.php');
1689
+ foreach($deactivate_plugins as $name => $plugin_file) {
1690
+ if(is_plugin_active($plugin_file)) {
1691
+ $deactivate_link = wp_nonce_url('plugins.php?action=deactivate&amp;plugin='.urlencode($plugin_file ).'&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $plugin_file);
1692
+ $notices['deactivate_plugin_'.strtolower(str_replace(' ', '', $name))] = array(
1693
+ 'title' => sprintf(__('Please deactivate %s plugin', 'gtranslate'), $name),
1694
+ 'msg' => sprintf(__('%s plugin causes conflicts with GTranslate.', 'gtranslate'), $name),
1695
+ 'link' => '<li><span class="dashicons dashicons-dismiss"></span><a href="'.$deactivate_link.'">' . sprintf(__('Deactivate %s plugin', 'gtranslate'), $name) . '</a></li>',
1696
+ 'dismissible' => false,
1697
+ 'int' => 0
1698
+ );
1699
+ }
1700
+ }
1701
+
1702
  /*
1703
  $one_week_support = esc_url(add_query_arg(array($this->prefix . '_admin_notice_ignore' => 'one_week_support')));
1704
 
1723
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1724
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1725
  'later_link' => $two_week_review_temp,
1726
+ 'int' => 5
1727
  );
1728
 
1729
  $data = get_option('GTranslate');
1740
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1741
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1742
  'later_link' => $upgrade_tips_temp,
1743
+ 'int' => 2
1744
  );
1745
 
1746
  $notices['upgrade_tips'][] = array(
1750
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1751
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1752
  'later_link' => $upgrade_tips_temp,
1753
+ 'int' => 2
1754
  );
1755
 
1756
  $notices['upgrade_tips'][] = array(
1760
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1761
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1762
  'later_link' => $upgrade_tips_temp,
1763
+ 'int' => 2
1764
  );
1765
 
1766
  $notices['upgrade_tips'][] = array(
1770
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1771
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1772
  'later_link' => $upgrade_tips_temp,
1773
+ 'int' => 2
1774
  );
1775
 
1776
  $notices['upgrade_tips'][] = array(
1780
  '<li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $upgrade_tips_temp . '">' . __('Maybe later', 'gtranslate') . '</a></li>' .
1781
  '<li><span class="dashicons dashicons-dismiss"></span><a href="' . $upgrade_tips_ignore . '">' . __('Never show again', 'gtranslate') . '</a></li>',
1782
  'later_link' => $upgrade_tips_temp,
1783
+ 'int' => 2
1784
  );
1785
 
1786
  shuffle($notices['upgrade_tips']);
1816
  exit;
1817
  } // #2 add trailing slash
1818
 
1819
+ if($data['widget_look'] == 'flags' or $data['widget_look'] == 'dropdown_with_flags' or $data['widget_look'] == 'flags_name' or $data['widget_look'] == 'flags_code' or $data['widget_look'] == 'popup')
1820
+ $allowed_languages = $data['fincl_langs'];
1821
+ elseif($data['widget_look'] == 'flags_dropdown')
1822
+ $allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
1823
+ else
1824
+ $allowed_languages = $data['incl_langs'];
1825
+ $allowed_languages = implode('|', $allowed_languages); // ex: en|ru|it|de
1826
+ if(preg_match('/^\/('.$allowed_languages.')\/(.*)/', $request_uri, $matches)) {
1827
  $_GET['glang'] = $matches[1];
1828
  $_GET['gurl'] = rawurldecode($matches[2]);
1829
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Author: Translate AI Multilingual Solutions
4
  Tags: translate wordpress, multilingual, translate, translation, language, bilingual, localization, translation proxy, i18n, l10n, localisation, multilanguage, google translate
5
  Requires at least: 2.8.1
6
  Tested up to: 4.9
7
- Stable tag: 2.8.32
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Donate link: https://gtranslate.io/?xyz=998#pricing
@@ -219,6 +219,19 @@ You need to go to the language you want to edit, for instance, French: http://do
219
 
220
  == Changelog ==
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  = 2.8.32 =
223
  * New feature: auto switch language based on browser language settigns
224
  * Minor fixes: Greek name in native alphabet, Flag size option for Globe Widget look, vertical position in pixels
4
  Tags: translate wordpress, multilingual, translate, translation, language, bilingual, localization, translation proxy, i18n, l10n, localisation, multilanguage, google translate
5
  Requires at least: 2.8.1
6
  Tested up to: 4.9
7
+ Stable tag: 2.8.35
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  Donate link: https://gtranslate.io/?xyz=998#pricing
219
 
220
  == Changelog ==
221
 
222
+ = 2.8.35 =
223
+ * Admin notice added for conflicting plugins
224
+ * Disabled translation of non-selected languages when accessed directly in sub-directory URL structure mode
225
+ * Update to WordPress 4.9.1 before updating GTranslate
226
+ * Fixed update issue related to bug in new WP 4.9 flatten_dirlist function
227
+
228
+ = 2.8.34 =
229
+ * Non-stable: Fixed update issue related to bug in new WP 4.9 flatten_dirlist function. Important: If you are using Globe widget look, make sure to open GTranslate settings page, click "Reset Code to Default" under Widget Code section and Save.
230
+
231
+ = 2.8.33 =
232
+ * Fixed issue related to new version of Contact Form 7
233
+ * Ready for WordPress 4.9
234
+
235
  = 2.8.32 =
236
  * New feature: auto switch language based on browser language settigns
237
  * Minor fixes: Greek name in native alphabet, Flag size option for Globe Widget look, vertical position in pixels
url_addon/gtranslate.php CHANGED
@@ -1,222 +1,232 @@
1
- <?php
2
- error_reporting(0);
3
-
4
- include 'config.php';
5
-
6
- if(!isset($_GET['glang']) or !isset($_GET['gurl']))
7
- exit;
8
-
9
- $glang = $_GET['glang'];
10
-
11
- // pick a server based on hostname
12
- $server_id = intval(substr(md5(preg_replace('/^www\./', '', $_SERVER['HTTP_HOST'])), 0, 5), 16) % count($servers);
13
- $server = $servers[$server_id];
14
-
15
- $page_url = '/'.$_GET['gurl'];
16
-
17
- $page_url_segments = explode('/', $page_url);
18
- foreach($page_url_segments as $i => $segment) {
19
- $page_url_segments[$i] = rawurlencode($segment);
20
- }
21
- $page_url = implode('/', $page_url_segments);
22
-
23
- $get_params = $_GET;
24
- if(isset($get_params['glang']))
25
- unset($get_params['glang']);
26
- if(isset($get_params['gurl']))
27
- unset($get_params['gurl']);
28
-
29
- if(count($get_params)) {
30
- $page_url .= '?' . http_build_query($get_params);
31
- }
32
-
33
- $main_lang = isset($data['default_language']) ? $data['default_language'] : $main_lang;
34
-
35
- if($glang == $main_lang) {
36
- $page_url = preg_replace('/^[\/]+/', '/', $page_url);
37
-
38
- header('Location: ' . $page_url, true, 301);
39
- exit;
40
- }
41
-
42
- $page_url = $server.'.tdn.gtranslate.net' . $page_url;
43
-
44
- $protocol = ((isset($_SERVER['HTTPS']) and ($_SERVER['HTTPS'] == 'on' or $_SERVER['HTTPS'] == 1)) or (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http';
45
- $page_url = $protocol . '://' . $page_url;
46
-
47
- if(!in_array(strtolower($glang), array('en','ar','bg','zh-cn','zh-tw','hr','cs','da','nl','fi','fr','de','el','hi','it','ja','ko','no','pl','pt','ro','ru','es','sv','ca','tl','iw','id','lv','lt','sr','sk','sl','uk','vi','sq','et','gl','hu','mt','th','tr','fa','af','ms','sw','ga','cy','be','is','mk','yi','hy','az','eu','ka','ht','ur','bn','bs','ceb','eo','gu','ha','hmn','ig','jw','kn','km','lo','la','mi','mr','mn','ne','pa','so','ta','te','yo','zu','my','ny','kk','mg','ml','si','st','su','tg','uz','am','co','haw','ku','ky','lb','ps','sm','gd','sn','sd','fy','xh')))
48
- exit;
49
-
50
- if(!function_exists("getallheaders")) {
51
- //Adapted from http://www.php.net/manual/en/function.getallheaders.php#99814
52
- function getallheaders() {
53
- $result = array();
54
- foreach($_SERVER as $key => $value) {
55
- if (substr($key, 0, 5) == "HTTP_") {
56
- $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
57
- $result[$key] = $value;
58
- } else if ($key == "CONTENT_TYPE") {
59
- $result["Content-Type"] = $value;
60
- }
61
- }
62
- return $result;
63
- }
64
- }
65
-
66
- $request_headers = getallheaders();
67
-
68
- if(isset($request_headers['X-GT-Lang']) or isset($request_headers['X-Gt-Lang']) or isset($request_headers['x-gt-lang'])) {
69
- echo 'Please remove DNS cname records for GTranslate!';
70
- exit;
71
- }
72
-
73
- $host = $glang . '.' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
74
- $request_headers['Host'] = $host;
75
- if(isset($request_headers['HOST'])) unset($request_headers['HOST']);
76
- if(isset($request_headers['host'])) unset($request_headers['host']);
77
-
78
- if(!function_exists('gzdecode'))
79
- $request_headers['Accept-Encoding'] = '';
80
- else
81
- $request_headers['Accept-Encoding'] = 'gzip';
82
-
83
- if(isset($request_headers['accept-encoding'])) unset($request_headers['accept-encoding']);
84
-
85
- if(isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
86
- $request_headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
87
- if(isset($request_headers['authorization'])) unset($request_headers['authorization']);
88
- }
89
- //print_r($request_headers);
90
- //exit;
91
-
92
- if(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data;') !== false)
93
- $request_headers['Content-Type'] = 'multipart/form-data'; // remove boundary
94
-
95
- $headers = array();
96
- foreach($request_headers as $key => $val) {
97
- // remove cloudflare CF headers: CF-IPCountry, CF-Ray, etc...
98
- if(preg_match('/^CF-/i', $key))
99
- continue;
100
- else
101
- $headers[] = $key . ': ' . $val;
102
- }
103
-
104
- //print_r($headers);
105
- //exit;
106
-
107
- // proxy request
108
- $ch = curl_init();
109
- curl_setopt($ch, CURLOPT_URL, $page_url);
110
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
111
- curl_setopt($ch, CURLOPT_HEADER, true);
112
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
113
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
114
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
115
-
116
- switch($_SERVER['REQUEST_METHOD']) {
117
- case 'POST': {
118
- curl_setopt($ch, CURLOPT_POST, true);
119
- if(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data') !== false) {
120
- http_build_query_for_curl($_POST, $new_post);
121
- curl_setopt($ch, CURLOPT_POSTFIELDS, $new_post); // todo: think about $_FILES: http://php.net/manual/en/class.curlfile.php
122
- } else {
123
- curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
124
- }
125
- }; break;
126
-
127
- case 'PUT': {
128
- curl_setopt($ch, CURLOPT_PUT, true);
129
- curl_setopt($ch, CURLOPT_INFILE, fopen('php://input', 'r'));
130
- }; break;
131
- }
132
-
133
- // Debug
134
- if($debug or isset($_GET['enable_debug'])) {
135
- $fh = fopen('debug.txt', 'a');
136
- curl_setopt($ch, CURLOPT_VERBOSE, true);
137
- curl_setopt($ch, CURLOPT_STDERR, $fh);
138
- }
139
-
140
- $response = curl_exec($ch);
141
- $response_info = curl_getinfo($ch);
142
- curl_close($ch);
143
-
144
- //print_r($response_info);
145
-
146
- $header_size = $response_info['header_size'];
147
- $header = substr($response, 0, $header_size);
148
- $html = substr($response, $header_size);
149
-
150
- if(function_exists('gzdecode')) {
151
- $return_gz = false;
152
- $html_gunzip = @gzdecode($html);
153
-
154
- if($html_gunzip !== false) {
155
- $html = $html_gunzip;
156
- unset($html_gunzip);
157
-
158
- if(strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
159
- $return_gz = true;
160
- header('Content-Encoding: gzip');
161
- header('Vary: Accept-Encoding');
162
- }
163
- }
164
- }
165
-
166
- $response_headers = explode(PHP_EOL, $header);
167
- //print_r($response_headers);
168
- $headers_sent = '';
169
- foreach($response_headers as $header) {
170
- if(!empty($header) and !preg_match('/Content\-Length|Transfer\-Encoding|Content\-Encoding|Link/i', $header)) {
171
-
172
- if(preg_match('/^Location:/i', $header)) {
173
- $header = str_ireplace($host, $_SERVER['HTTP_HOST'] . '/' . $glang, $header);
174
- $header = str_ireplace('Location: /', 'Location: /' . $glang . '/', $header);
175
- }
176
-
177
- $headers_sent .= $header;
178
- header($header, false);
179
- }
180
- }
181
- //echo $headers_sent;
182
-
183
- // TODO: modify URLs
184
- $html = str_ireplace($host, $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
185
- $html = str_ireplace('href="/', 'href="/' . $glang . '/', $html);
186
- $html = preg_replace('/href=\"\/' . $glang . '\/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)\//i', 'href="/$1/', $html); // fix double language code
187
- $html = str_ireplace('href="/' . $glang . '//', 'href="//', $html);
188
- $html = str_ireplace('action="/', 'action="/' . $glang . '/', $html);
189
- $html = str_ireplace('action="/' . $glang . '//', 'action="//', $html);
190
- $html = str_ireplace('action="//' . $_SERVER['HTTP_HOST'], 'action="//' . $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
191
-
192
- // woocommerce specific changes
193
- $html = str_ireplace(
194
- array('"wc_ajax_url":"\\/', '"checkout_url":"\\/', 'var wc_country_select_params', 'var wc_address_i18n_params' ),
195
- array('"wc_ajax_url":"\\/'.$glang.'\\/', '"checkout_url":"\\/'.$glang.'\\/', 'var wc_country_select_params2', 'var wc_address_i18n_params2'),
196
- $html
197
- );
198
-
199
- if(isset($_GET['language_edit'])) {
200
- $html = str_replace('/tdn-static/', $protocol . '://tdns.gtranslate.net/tdn-static/', $html);
201
- $html = str_replace('/tdn-bin/', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' . $glang . '/tdn-bin/', $html);
202
- }
203
-
204
- if(function_exists('gzencode') and isset($return_gz) and $return_gz and zlib_get_coding_type() == false)
205
- echo gzencode($html);
206
- else
207
- echo $html;
208
-
209
- function http_build_query_for_curl($arrays, &$new = array(), $prefix = null) { // flatten multidimentional array for post
210
- if(is_object($arrays)) {
211
- $arrays = get_object_vars($arrays);
212
- }
213
-
214
- foreach($arrays AS $key => $value) {
215
- $k = isset($prefix) ? $prefix . '[' . $key . ']' : $key;
216
- if(is_array($value) or is_object($value)) {
217
- http_build_query_for_curl($value, $new, $k);
218
- } else {
219
- $new[$k] = $value;
220
- }
221
- }
222
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ error_reporting(0);
3
+
4
+ include 'config.php';
5
+
6
+ if(!isset($_GET['glang']) or !isset($_GET['gurl']))
7
+ exit;
8
+
9
+ $glang = $_GET['glang'];
10
+
11
+ // pick a server based on hostname
12
+ $server_id = intval(substr(md5(preg_replace('/^www\./', '', $_SERVER['HTTP_HOST'])), 0, 5), 16) % count($servers);
13
+ $server = $servers[$server_id];
14
+
15
+ $page_url = '/'.$_GET['gurl'];
16
+
17
+ $page_url_segments = explode('/', $page_url);
18
+ foreach($page_url_segments as $i => $segment) {
19
+ $page_url_segments[$i] = rawurlencode($segment);
20
+ }
21
+ $page_url = implode('/', $page_url_segments);
22
+
23
+ $get_params = $_GET;
24
+ if(isset($get_params['glang']))
25
+ unset($get_params['glang']);
26
+ if(isset($get_params['gurl']))
27
+ unset($get_params['gurl']);
28
+
29
+ if(count($get_params)) {
30
+ $page_url .= '?' . http_build_query($get_params);
31
+ }
32
+
33
+ $main_lang = isset($data['default_language']) ? $data['default_language'] : $main_lang;
34
+
35
+ if($glang == $main_lang) {
36
+ $page_url = preg_replace('/^[\/]+/', '/', $page_url);
37
+
38
+ header('Location: ' . $page_url, true, 301);
39
+ exit;
40
+ }
41
+
42
+ $page_url = $server.'.tdn.gtranslate.net' . $page_url;
43
+
44
+ $protocol = ((isset($_SERVER['HTTPS']) and ($_SERVER['HTTPS'] == 'on' or $_SERVER['HTTPS'] == 1)) or (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https' : 'http';
45
+ $page_url = $protocol . '://' . $page_url;
46
+
47
+ if(!in_array(strtolower($glang), array('en','ar','bg','zh-cn','zh-tw','hr','cs','da','nl','fi','fr','de','el','hi','it','ja','ko','no','pl','pt','ro','ru','es','sv','ca','tl','iw','id','lv','lt','sr','sk','sl','uk','vi','sq','et','gl','hu','mt','th','tr','fa','af','ms','sw','ga','cy','be','is','mk','yi','hy','az','eu','ka','ht','ur','bn','bs','ceb','eo','gu','ha','hmn','ig','jw','kn','km','lo','la','mi','mr','mn','ne','pa','so','ta','te','yo','zu','my','ny','kk','mg','ml','si','st','su','tg','uz','am','co','haw','ku','ky','lb','ps','sm','gd','sn','sd','fy','xh')))
48
+ exit;
49
+
50
+ if(!function_exists("getallheaders")) {
51
+ //Adapted from http://www.php.net/manual/en/function.getallheaders.php#99814
52
+ function getallheaders() {
53
+ $result = array();
54
+ foreach($_SERVER as $key => $value) {
55
+ if (substr($key, 0, 5) == "HTTP_") {
56
+ $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
57
+ $result[$key] = $value;
58
+ } else if ($key == "CONTENT_TYPE") {
59
+ $result["Content-Type"] = $value;
60
+ }
61
+ }
62
+ return $result;
63
+ }
64
+ }
65
+
66
+ $request_headers = getallheaders();
67
+
68
+ if(isset($request_headers['X-GT-Lang']) or isset($request_headers['X-Gt-Lang']) or isset($request_headers['x-gt-lang'])) {
69
+ echo 'Please remove DNS cname records for GTranslate!';
70
+ exit;
71
+ }
72
+
73
+ $host = $glang . '.' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
74
+ $request_headers['Host'] = $host;
75
+ if(isset($request_headers['HOST'])) unset($request_headers['HOST']);
76
+ if(isset($request_headers['host'])) unset($request_headers['host']);
77
+
78
+ if(!function_exists('gzdecode'))
79
+ $request_headers['Accept-Encoding'] = '';
80
+ else
81
+ $request_headers['Accept-Encoding'] = 'gzip';
82
+
83
+ if(isset($request_headers['accept-encoding'])) unset($request_headers['accept-encoding']);
84
+
85
+ if(isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
86
+ $request_headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
87
+ if(isset($request_headers['authorization'])) unset($request_headers['authorization']);
88
+ }
89
+ //print_r($request_headers);
90
+ //exit;
91
+
92
+ if(isset($request_headers['content-type'])) {
93
+ $request_headers['Content-Type'] = $request_headers['content-type'];
94
+ unset($request_headers['content-type']);
95
+ }
96
+
97
+ if(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data;') !== false) {
98
+ $request_headers['Content-Type'] = 'multipart/form-data'; // remove boundary
99
+ $request_headers['Content-Length'] = '';
100
+
101
+ if(isset($request_headers['content-length']))
102
+ unset($request_headers['content-length']);
103
+ }
104
+
105
+ $headers = array();
106
+ foreach($request_headers as $key => $val) {
107
+ // remove cloudflare CF headers: CF-IPCountry, CF-Ray, etc...
108
+ if(preg_match('/^CF-/i', $key))
109
+ continue;
110
+ else
111
+ $headers[] = $key . ': ' . $val;
112
+ }
113
+
114
+ //print_r($headers);
115
+ //exit;
116
+
117
+ // proxy request
118
+ $ch = curl_init();
119
+ curl_setopt($ch, CURLOPT_URL, $page_url);
120
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
121
+ curl_setopt($ch, CURLOPT_HEADER, true);
122
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
123
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
124
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
125
+
126
+ switch($_SERVER['REQUEST_METHOD']) {
127
+ case 'POST': {
128
+ curl_setopt($ch, CURLOPT_POST, true);
129
+ if(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data') !== false) {
130
+ http_build_query_for_curl($_POST, $new_post);
131
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $new_post); // todo: think about $_FILES: http://php.net/manual/en/class.curlfile.php
132
+ } else {
133
+ curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
134
+ }
135
+ }; break;
136
+
137
+ case 'PUT': {
138
+ curl_setopt($ch, CURLOPT_PUT, true);
139
+ curl_setopt($ch, CURLOPT_INFILE, fopen('php://input', 'r'));
140
+ }; break;
141
+ }
142
+
143
+ // Debug
144
+ if($debug or isset($_GET['enable_debug'])) {
145
+ $fh = fopen('debug.txt', 'a');
146
+ curl_setopt($ch, CURLOPT_VERBOSE, true);
147
+ curl_setopt($ch, CURLOPT_STDERR, $fh);
148
+ }
149
+
150
+ $response = curl_exec($ch);
151
+ $response_info = curl_getinfo($ch);
152
+ curl_close($ch);
153
+
154
+ //print_r($response_info);
155
+
156
+ $header_size = $response_info['header_size'];
157
+ $header = substr($response, 0, $header_size);
158
+ $html = substr($response, $header_size);
159
+
160
+ if(function_exists('gzdecode')) {
161
+ $return_gz = false;
162
+ $html_gunzip = @gzdecode($html);
163
+
164
+ if($html_gunzip !== false) {
165
+ $html = $html_gunzip;
166
+ unset($html_gunzip);
167
+
168
+ if(strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
169
+ $return_gz = true;
170
+ header('Content-Encoding: gzip');
171
+ header('Vary: Accept-Encoding');
172
+ }
173
+ }
174
+ }
175
+
176
+ $response_headers = explode(PHP_EOL, $header);
177
+ //print_r($response_headers);
178
+ $headers_sent = '';
179
+ foreach($response_headers as $header) {
180
+ if(!empty($header) and !preg_match('/Content\-Length|Transfer\-Encoding|Content\-Encoding|Link/i', $header)) {
181
+
182
+ if(preg_match('/^Location:/i', $header)) {
183
+ $header = str_ireplace($host, $_SERVER['HTTP_HOST'] . '/' . $glang, $header);
184
+ $header = str_ireplace('Location: /', 'Location: /' . $glang . '/', $header);
185
+ }
186
+
187
+ $headers_sent .= $header;
188
+ header($header, false);
189
+ }
190
+ }
191
+ //echo $headers_sent;
192
+
193
+ // TODO: modify URLs
194
+ $html = str_ireplace($host, $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
195
+ $html = str_ireplace('href="/', 'href="/' . $glang . '/', $html);
196
+ $html = preg_replace('/href=\"\/' . $glang . '\/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)\//i', 'href="/$1/', $html); // fix double language code
197
+ $html = str_ireplace('href="/' . $glang . '//', 'href="//', $html);
198
+ $html = str_ireplace('action="/', 'action="/' . $glang . '/', $html);
199
+ $html = str_ireplace('action="/' . $glang . '//', 'action="//', $html);
200
+ $html = str_ireplace('action="//' . $_SERVER['HTTP_HOST'], 'action="//' . $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
201
+
202
+ // woocommerce specific changes
203
+ $html = str_ireplace(
204
+ array('"wc_ajax_url":"\\/', '"checkout_url":"\\/', 'var wc_country_select_params', 'var wc_address_i18n_params' ),
205
+ array('"wc_ajax_url":"\\/'.$glang.'\\/', '"checkout_url":"\\/'.$glang.'\\/', 'var wc_country_select_params2', 'var wc_address_i18n_params2'),
206
+ $html
207
+ );
208
+
209
+ if(isset($_GET['language_edit'])) {
210
+ $html = str_replace('/tdn-static/', $protocol . '://tdns.gtranslate.net/tdn-static/', $html);
211
+ $html = str_replace('/tdn-bin/', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' . $glang . '/tdn-bin/', $html);
212
+ }
213
+
214
+ if(function_exists('gzencode') and isset($return_gz) and $return_gz and zlib_get_coding_type() == false)
215
+ echo gzencode($html);
216
+ else
217
+ echo $html;
218
+
219
+ function http_build_query_for_curl($arrays, &$new = array(), $prefix = null) { // flatten multidimentional array for post
220
+ if(is_object($arrays)) {
221
+ $arrays = get_object_vars($arrays);
222
+ }
223
+
224
+ foreach($arrays AS $key => $value) {
225
+ $k = isset($prefix) ? $prefix . '[' . $key . ']' : $key;
226
+ if(is_array($value) or is_object($value)) {
227
+ http_build_query_for_curl($value, $new, $k);
228
+ } else {
229
+ $new[$k] = $value;
230
+ }
231
+ }
232
+ }