Translate WordPress with GTranslate - Version 2.8.36

Version Description

  • Option to add hreflang tags for translated pages
  • Fix for Contact Form 7
Download this release

Release Info

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

Code changes from version 2.8.35 to 2.8.36

Files changed (3) hide show
  1. gtranslate.php +48 -1
  2. readme.txt +6 -1
  3. url_addon/gtranslate.php +21 -2
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.35
7
  Author: Translate AI Multilingual Solutions
8
  Author URI: https://gtranslate.io
9
  Text Domain: gtranslate
@@ -320,10 +320,12 @@ function RefreshDoWidgetCode() {
320
  translation_method = 'redirect';
321
  jQuery('#new_window_option').show();
322
  jQuery('#url_translation_option').show();
 
323
  jQuery('#auto_switch_option').hide();
324
  } else {
325
  jQuery('#new_window_option').hide();
326
  jQuery('#url_translation_option').hide();
 
327
  jQuery('#auto_switch_option').show();
328
  }
329
 
@@ -779,6 +781,7 @@ function ShowWidgetPreview(widget_preview) {
779
  jQuery('#pro_version').attr('checked', '$pro_version'.length > 0);
780
  jQuery('#enterprise_version').attr('checked', '$enterprise_version'.length > 0);
781
  jQuery('#url_translation').attr('checked', '$url_translation'.length > 0);
 
782
  jQuery('#new_window').attr('checked', '$new_window'.length > 0);
783
  jQuery('#show_in_menu').val('$show_in_menu');
784
  jQuery('#floating_language_selector').val('$floating_language_selector');
@@ -793,6 +796,7 @@ jQuery('#flag_size').val('$flag_size');
793
  if(jQuery('#pro_version:checked').length || jQuery('#enterprise_version:checked').length) {
794
  jQuery('#new_window_option').show();
795
  jQuery('#url_translation_option').show();
 
796
  jQuery('#auto_switch_option').hide();
797
  }
798
 
@@ -1024,6 +1028,10 @@ EOT;
1024
  <td class="option_name"><?php _e('Enable URL Translation', 'gtranslate'); ?>:</td>
1025
  <td><input id="url_translation" name="url_translation" value="1" type="checkbox"/></td>
1026
  </tr>
 
 
 
 
1027
  <tr id="new_window_option" style="display:none;">
1028
  <td class="option_name"><?php _e('Open in new window', 'gtranslate'); ?>:</td>
1029
  <td><input id="new_window" name="new_window" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
@@ -1307,6 +1315,7 @@ EOT;
1307
  $data['pro_version'] = isset($_POST['pro_version']) ? intval($_POST['pro_version']) : '';
1308
  $data['enterprise_version'] = isset($_POST['enterprise_version']) ? intval($_POST['enterprise_version']) : '';
1309
  $data['url_translation'] = isset($_POST['url_translation']) ? intval($_POST['url_translation']) : '';
 
1310
  $data['new_window'] = isset($_POST['new_window']) ? intval($_POST['new_window']) : '';
1311
  $data['show_in_menu'] = isset($_POST['show_in_menu']) ? sanitize_text_field($_POST['show_in_menu']) : '';
1312
  $data['floating_language_selector'] = isset($_POST['floating_language_selector']) ? sanitize_text_field($_POST['floating_language_selector']) : 'no';
@@ -1374,6 +1383,7 @@ EOT;
1374
  $data['pro_version'] = isset($data['pro_version']) ? $data['pro_version'] : '';
1375
  $data['enterprise_version'] = isset($data['enterprise_version']) ? $data['enterprise_version'] : '';
1376
  $data['url_translation'] = isset($data['url_translation']) ? $data['url_translation'] : '';
 
1377
  $data['new_window'] = isset($data['new_window']) ? $data['new_window'] : '';
1378
  $data['show_in_menu'] = isset($data['show_in_menu']) ? $data['show_in_menu'] : ((isset($data['show_in_primary_menu']) and $data['show_in_primary_menu'] == 1) ? 'primary' : '');
1379
  $data['floating_language_selector'] = isset($data['floating_language_selector']) ? $data['floating_language_selector'] : 'no';
@@ -1926,3 +1936,40 @@ if($data['url_translation'] and ($data['pro_version'] or $data['enterprise_versi
1926
  echo '<meta name="uri-translation" content="on" />';
1927
  }
1928
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.36
7
  Author: Translate AI Multilingual Solutions
8
  Author URI: https://gtranslate.io
9
  Text Domain: gtranslate
320
  translation_method = 'redirect';
321
  jQuery('#new_window_option').show();
322
  jQuery('#url_translation_option').show();
323
+ jQuery('#hreflang_tags_option').show();
324
  jQuery('#auto_switch_option').hide();
325
  } else {
326
  jQuery('#new_window_option').hide();
327
  jQuery('#url_translation_option').hide();
328
+ jQuery('#hreflang_tags_option').hide();
329
  jQuery('#auto_switch_option').show();
330
  }
331
 
781
  jQuery('#pro_version').attr('checked', '$pro_version'.length > 0);
782
  jQuery('#enterprise_version').attr('checked', '$enterprise_version'.length > 0);
783
  jQuery('#url_translation').attr('checked', '$url_translation'.length > 0);
784
+ jQuery('#add_hreflang_tags').attr('checked', '$add_hreflang_tags'.length > 0);
785
  jQuery('#new_window').attr('checked', '$new_window'.length > 0);
786
  jQuery('#show_in_menu').val('$show_in_menu');
787
  jQuery('#floating_language_selector').val('$floating_language_selector');
796
  if(jQuery('#pro_version:checked').length || jQuery('#enterprise_version:checked').length) {
797
  jQuery('#new_window_option').show();
798
  jQuery('#url_translation_option').show();
799
+ jQuery('#hreflang_tags_option').show();
800
  jQuery('#auto_switch_option').hide();
801
  }
802
 
1028
  <td class="option_name"><?php _e('Enable URL Translation', 'gtranslate'); ?>:</td>
1029
  <td><input id="url_translation" name="url_translation" value="1" type="checkbox"/></td>
1030
  </tr>
1031
+ <tr id="hreflang_tags_option" style="display:none;">
1032
+ <td class="option_name"><?php _e('Add hreflang tags', 'gtranslate'); ?>:</td>
1033
+ <td><input id="add_hreflang_tags" name="add_hreflang_tags" value="1" type="checkbox"/></td>
1034
+ </tr>
1035
  <tr id="new_window_option" style="display:none;">
1036
  <td class="option_name"><?php _e('Open in new window', 'gtranslate'); ?>:</td>
1037
  <td><input id="new_window" name="new_window" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
1315
  $data['pro_version'] = isset($_POST['pro_version']) ? intval($_POST['pro_version']) : '';
1316
  $data['enterprise_version'] = isset($_POST['enterprise_version']) ? intval($_POST['enterprise_version']) : '';
1317
  $data['url_translation'] = isset($_POST['url_translation']) ? intval($_POST['url_translation']) : '';
1318
+ $data['add_hreflang_tags'] = isset($_POST['add_hreflang_tags']) ? intval($_POST['add_hreflang_tags']) : '';
1319
  $data['new_window'] = isset($_POST['new_window']) ? intval($_POST['new_window']) : '';
1320
  $data['show_in_menu'] = isset($_POST['show_in_menu']) ? sanitize_text_field($_POST['show_in_menu']) : '';
1321
  $data['floating_language_selector'] = isset($_POST['floating_language_selector']) ? sanitize_text_field($_POST['floating_language_selector']) : 'no';
1383
  $data['pro_version'] = isset($data['pro_version']) ? $data['pro_version'] : '';
1384
  $data['enterprise_version'] = isset($data['enterprise_version']) ? $data['enterprise_version'] : '';
1385
  $data['url_translation'] = isset($data['url_translation']) ? $data['url_translation'] : '';
1386
+ $data['add_hreflang_tags'] = isset($data['add_hreflang_tags']) ? $data['add_hreflang_tags'] : '';
1387
  $data['new_window'] = isset($data['new_window']) ? $data['new_window'] : '';
1388
  $data['show_in_menu'] = isset($data['show_in_menu']) ? $data['show_in_menu'] : ((isset($data['show_in_primary_menu']) and $data['show_in_primary_menu'] == 1) ? 'primary' : '');
1389
  $data['floating_language_selector'] = isset($data['floating_language_selector']) ? $data['floating_language_selector'] : 'no';
1936
  echo '<meta name="uri-translation" content="on" />';
1937
  }
1938
  }
1939
+
1940
+ if($data['add_hreflang_tags'] and ($data['pro_version'] or $data['enterprise_version'])) {
1941
+ add_action('wp_head', 'gtranslate_add_hreflang_tags', 1);
1942
+ function gtranslate_add_hreflang_tags() {
1943
+ $data = get_option('GTranslate');
1944
+ GTranslate::load_defaults($data);
1945
+
1946
+ $enabled_languages = array();
1947
+ 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')
1948
+ $enabled_languages = $data['fincl_langs'];
1949
+ elseif($data['widget_look'] == 'flags_dropdown')
1950
+ $enabled_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
1951
+ else
1952
+ $enabled_languages = $data['incl_langs'];
1953
+
1954
+ $current_url = wp_get_canonical_url();
1955
+
1956
+ if($current_url !== false) {
1957
+ // adding default language
1958
+ echo '<link rel="alternate" hreflang="'.$data['default_language'].'" href="'.$current_url.'" />'."\n";
1959
+
1960
+ // adding enabled languages
1961
+ foreach($enabled_languages as $lang) {
1962
+ $href = '';
1963
+ $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
1964
+
1965
+ if($data['enterprise_version'])
1966
+ $href = str_ireplace('://' . $domain, '://' . $lang . '.' . $domain, $current_url);
1967
+ elseif($data['pro_version'])
1968
+ $href = str_ireplace('://' . $domain, '://' . $domain . '/' . $lang, $current_url);
1969
+
1970
+ if(!empty($href) and $lang != $data['default_language'])
1971
+ echo '<link rel="alternate" hreflang="'.$lang.'" href="'.$href.'" />'."\n";
1972
+ }
1973
+ }
1974
+ }
1975
+ }
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.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
@@ -56,6 +56,7 @@ Please check our [FAQ](https://gtranslate.io/?xyz=998#faq) to get quick answers.
56
  * WooCommerce compatible
57
  * You can have sub-directory (example.com/**es**/) or sub-domain (**es.**example.com) URL structure
58
  * URL Translation aka slug translation is possible (example.com/about-us &rarr; example.es/sobre-nosotros)
 
59
  * You can manually correct translations
60
  * In context translation interface (make corrections without loosing the context)
61
  * Meta data translation (meta keywords, meta description)
@@ -219,6 +220,10 @@ You need to go to the language you want to edit, for instance, French: http://do
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
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.36
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
56
  * WooCommerce compatible
57
  * You can have sub-directory (example.com/**es**/) or sub-domain (**es.**example.com) URL structure
58
  * URL Translation aka slug translation is possible (example.com/about-us &rarr; example.es/sobre-nosotros)
59
+ * Add hreflang tags for translated alternatives
60
  * You can manually correct translations
61
  * In context translation interface (make corrections without loosing the context)
62
  * Meta data translation (meta keywords, meta description)
220
 
221
  == Changelog ==
222
 
223
+ = 2.8.36 =
224
+ * Option to add hreflang tags for translated pages
225
+ * Fix for Contact Form 7
226
+
227
  = 2.8.35 =
228
  * Admin notice added for conflicting plugins
229
  * Disabled translation of non-selected languages when accessed directly in sub-directory URL structure mode
url_addon/gtranslate.php CHANGED
@@ -95,7 +95,9 @@ if(isset($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']))
@@ -126,9 +128,23 @@ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
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
  }
@@ -196,8 +212,11 @@ $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(
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-Type'] = 'application/x-www-form-urlencoded';
100
+ $is_multipart = true;
101
  $request_headers['Content-Length'] = '';
102
 
103
  if(isset($request_headers['content-length']))
128
  switch($_SERVER['REQUEST_METHOD']) {
129
  case 'POST': {
130
  curl_setopt($ch, CURLOPT_POST, true);
131
+ if(isset($is_multipart)) {
132
  http_build_query_for_curl($_POST, $new_post);
133
+ $new_post2 = array();
134
+ foreach($new_post as $key => $value)
135
+ $new_post2[] = $key.'='.urlencode($value);
136
+ $new_post = implode('&', $new_post2);
137
+ $headers[] = 'Content-Length: '.strlen($new_post);
138
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
139
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $new_post);
140
+
141
+ } elseif(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data') !== false) {
142
+ http_build_query_for_curl($_POST, $new_post);
143
+
144
+ $new_post = array('a'=>1,'b'=>2);
145
  curl_setopt($ch, CURLOPT_POSTFIELDS, $new_post); // todo: think about $_FILES: http://php.net/manual/en/class.curlfile.php
146
+ //curl_setopt($ch, CURLOPT_HTTPHEADER, array());
147
+ file_put_contents('debug.txt', print_r($new_post, true)."\n", FILE_APPEND);
148
  } else {
149
  curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
150
  }
212
  $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
213
  $html = str_ireplace('href="/' . $glang . '//', 'href="//', $html);
214
  $html = str_ireplace('action="/', 'action="/' . $glang . '/', $html);
215
+ $html = str_ireplace('action=\'/', 'action=\'/' . $glang . '/', $html);
216
  $html = str_ireplace('action="/' . $glang . '//', 'action="//', $html);
217
+ $html = str_ireplace('action=\'/' . $glang . '//', 'action=\'//', $html);
218
  $html = str_ireplace('action="//' . $_SERVER['HTTP_HOST'], 'action="//' . $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
219
+ $html = str_ireplace('action=\'//' . $_SERVER['HTTP_HOST'], 'action=\'//' . $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
220
 
221
  // woocommerce specific changes
222
  $html = str_ireplace(