Version Description
- Fixed issue related to new version of Contact Form 7
- Ready for WordPress 4.9
Download this release
Release Info
Developer | edo888 |
Plugin | Translate WordPress with GTranslate |
Version | 2.8.33 |
Comparing to | |
See all releases |
Code changes from version 2.8.31 to 2.8.33
- gtranslate.php +116 -22
- native_names_map.php +1 -1
- readme.txt +11 -4
- url_addon/gtranslate.php +232 -222
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.
|
7 |
Author: Translate AI Multilingual Solutions
|
8 |
Author URI: https://gtranslate.io
|
9 |
Text Domain: gtranslate
|
@@ -118,6 +118,26 @@ class GTranslate extends WP_Widget {
|
|
118 |
echo '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
119 |
}
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
echo $args['after_widget'];
|
122 |
}
|
123 |
|
@@ -139,6 +159,26 @@ class GTranslate extends WP_Widget {
|
|
139 |
echo '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
140 |
}
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
echo $args['after_widget'];
|
143 |
}
|
144 |
|
@@ -152,9 +192,31 @@ class GTranslate extends WP_Widget {
|
|
152 |
|
153 |
// avoid caching issues
|
154 |
if($data['widget_look'] == 'dropdown_with_flags' and ($data['pro_version'] or $data['enterprise_version'])) {
|
155 |
-
|
156 |
} elseif($data['widget_look'] == 'popup' and ($data['pro_version'] or $data['enterprise_version'])) {
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
|
160 |
return $data['widget_code'];
|
@@ -168,7 +230,7 @@ class GTranslate extends WP_Widget {
|
|
168 |
public static function admin_menu() {
|
169 |
add_options_page(__('GTranslate Options', 'gtranslate'), 'GTranslate', 'administrator', 'gtranslate_options', array('GTranslate', 'options'));
|
170 |
|
171 |
-
deactivate_plugins(array('wptranslator/WPTranslator.php', 'google-language-translator/google-language-translator.php', 'google-website-translator/google-website-translator.php', 'weglot/weglot.php'), true);
|
172 |
}
|
173 |
|
174 |
public static function options() {
|
@@ -239,6 +301,7 @@ function RefreshDoWidgetCode() {
|
|
239 |
var floating_language_selector = jQuery('#floating_language_selector').val();
|
240 |
var native_language_names = jQuery('#native_language_names:checked').length > 0 ? true : false;
|
241 |
var analytics = jQuery('#analytics:checked').length > 0 ? true : false;
|
|
|
242 |
|
243 |
// make sure default language is on
|
244 |
if(widget_look == 'flags_dropdown' || widget_look == 'dropdown_with_flags' || widget_look == 'flags' || widget_look == 'flags_name' || widget_code == 'flags_code' || widget_look == 'popup')
|
@@ -250,9 +313,11 @@ function RefreshDoWidgetCode() {
|
|
250 |
translation_method = 'redirect';
|
251 |
jQuery('#new_window_option').show();
|
252 |
jQuery('#url_translation_option').show();
|
|
|
253 |
} else {
|
254 |
jQuery('#new_window_option').hide();
|
255 |
jQuery('#url_translation_option').hide();
|
|
|
256 |
}
|
257 |
|
258 |
if(widget_look == 'dropdown' || widget_look == 'flags_dropdown' || widget_look == 'globe' || widget_look == 'lang_names' || widget_look == 'lang_codes') {
|
@@ -282,7 +347,7 @@ function RefreshDoWidgetCode() {
|
|
282 |
jQuery('#line_break_option').hide();
|
283 |
}
|
284 |
|
285 |
-
if(widget_look == 'dropdown_with_flags' || widget_look == 'dropdown' || widget_look == 'lang_names' || widget_look == 'lang_codes') {
|
286 |
jQuery('#flag_size_option').hide();
|
287 |
} else {
|
288 |
jQuery('#flag_size_option').show();
|
@@ -500,25 +565,25 @@ function RefreshDoWidgetCode() {
|
|
500 |
widget_preview += '</div>'+new_line;
|
501 |
widget_preview += '</div>'+new_line;
|
502 |
|
503 |
-
console.log('Count: ' + count_languages);
|
504 |
|
505 |
flag_size = parseInt(flag_size);
|
506 |
-
console.log('Flag size: ' + flag_size);
|
507 |
|
508 |
var popup_height = 25 + count_languages * ((flag_size > 16 ? flag_size : 20) + 10 + 1);
|
509 |
|
510 |
-
console.log('height: ' + popup_height);
|
511 |
|
512 |
var popup_columns = Math.ceil(popup_height / 375);
|
513 |
|
514 |
-
console.log('Cols: ' + popup_columns);
|
515 |
|
516 |
if(popup_height > 375)
|
517 |
popup_height = 375;
|
518 |
|
519 |
var popup_width = popup_columns * (326 + 15);
|
520 |
|
521 |
-
console.log('Width: ' + popup_width);
|
522 |
|
523 |
if(popup_width > 980)
|
524 |
popup_width = 980;
|
@@ -712,6 +777,7 @@ jQuery('#show_in_menu').val('$show_in_menu');
|
|
712 |
jQuery('#floating_language_selector').val('$floating_language_selector');
|
713 |
jQuery('#native_language_names').attr('checked', '$native_language_names'.length > 0);
|
714 |
jQuery('#analytics').attr('checked', '$analytics'.length > 0);
|
|
|
715 |
jQuery('#add_new_line').attr('checked', '$add_new_line'.length > 0);
|
716 |
jQuery('#default_language').val('$default_language');
|
717 |
jQuery('#widget_look').val('$widget_look');
|
@@ -720,6 +786,7 @@ jQuery('#flag_size').val('$flag_size');
|
|
720 |
if(jQuery('#pro_version:checked').length || jQuery('#enterprise_version:checked').length) {
|
721 |
jQuery('#new_window_option').show();
|
722 |
jQuery('#url_translation_option').show();
|
|
|
723 |
}
|
724 |
|
725 |
if('$widget_look' == 'dropdown' || '$widget_look' == 'flags_dropdown' || '$widget_look' == 'globe' || '$widget_look' == 'lang_names' || '$widget_look' == 'lang_codes') {
|
@@ -749,7 +816,7 @@ if('$widget_look' == 'flags_dropdown') {
|
|
749 |
jQuery('#line_break_option').hide();
|
750 |
}
|
751 |
|
752 |
-
if('$widget_look' == 'dropdown_with_flags' || '$widget_look' == 'dropdown' || '$widget_look' == 'lang_names' || '$widget_look' == 'lang_codes') {
|
753 |
jQuery('#flag_size_option').hide();
|
754 |
} else {
|
755 |
jQuery('#flag_size_option').show();
|
@@ -938,10 +1005,6 @@ EOT;
|
|
938 |
</select>
|
939 |
</td>
|
940 |
</tr>
|
941 |
-
<tr>
|
942 |
-
<td class="option_name"><?php _e('Analytics', 'gtranslate'); ?>:</td>
|
943 |
-
<td><input id="analytics" name="analytics" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
944 |
-
</tr>
|
945 |
<tr>
|
946 |
<td class="option_name">* <?php _e('Sub-directory URL structure', 'gtranslate'); ?>:<br><code><small>http://example.com/<b>ru</b>/</small></code></td>
|
947 |
<td><input id="pro_version" name="pro_version" value="1" type="checkbox" onclick="if(jQuery('#pro_version').is(':checked') && jQuery('#enterprise_version').is(':checked'))jQuery('#enterprise_version').prop('checked', false);RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/> <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank" title="If you already have a subscription, you can enable this.">* <?php _e('for paid plans only', 'gtranslate'); ?></a></td>
|
@@ -958,6 +1021,14 @@ EOT;
|
|
958 |
<td class="option_name"><?php _e('Open in new window', 'gtranslate'); ?>:</td>
|
959 |
<td><input id="new_window" name="new_window" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
960 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
961 |
<tr>
|
962 |
<td class="option_name"><?php _e('Show in menu', 'gtranslate'); ?>:</td>
|
963 |
<td>
|
@@ -986,9 +1057,9 @@ EOT;
|
|
986 |
</select>
|
987 |
</td>
|
988 |
</tr>
|
|
|
989 |
<td class="option_name"><?php _e('Show native language names', 'gtranslate'); ?>:</td>
|
990 |
<td><input id="native_language_names" name="native_language_names" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
991 |
-
<tr>
|
992 |
</tr>
|
993 |
<tr id="flag_size_option">
|
994 |
<td class="option_name"><?php _e('Flag size', 'gtranslate'); ?>:</td>
|
@@ -1234,6 +1305,7 @@ EOT;
|
|
1234 |
$data['floating_language_selector'] = isset($_POST['floating_language_selector']) ? sanitize_text_field($_POST['floating_language_selector']) : 'no';
|
1235 |
$data['native_language_names'] = isset($_POST['native_language_names']) ? intval($_POST['native_language_names']) : '';
|
1236 |
$data['analytics'] = isset($_POST['analytics']) ? intval($_POST['analytics']) : '';
|
|
|
1237 |
$data['add_new_line'] = isset($_POST['add_new_line']) ? intval($_POST['add_new_line']) : '';
|
1238 |
$data['default_language'] = isset($_POST['default_language']) ? sanitize_text_field($_POST['default_language']) : 'en';
|
1239 |
$data['translation_method'] = 'onfly';
|
@@ -1250,7 +1322,6 @@ EOT;
|
|
1250 |
else
|
1251 |
$data['widget_code'] = isset($_POST['widget_code']) ? stripslashes($_POST['widget_code']) : '';
|
1252 |
|
1253 |
-
|
1254 |
echo '<p style="color:red;">' . __('Changes Saved', 'gtranslate') . '</p>';
|
1255 |
update_option('GTranslate', $data);
|
1256 |
|
@@ -1300,6 +1371,7 @@ EOT;
|
|
1300 |
$data['floating_language_selector'] = isset($data['floating_language_selector']) ? $data['floating_language_selector'] : 'no';
|
1301 |
$data['native_language_names'] = isset($data['native_language_names']) ? $data['native_language_names'] : '';
|
1302 |
$data['analytics'] = isset($data['analytics']) ? $data['analytics'] : '';
|
|
|
1303 |
$data['add_new_line'] = isset($data['add_new_line']) ? $data['add_new_line'] : '1';
|
1304 |
|
1305 |
if(!isset($data['default_language'])) {
|
@@ -1354,6 +1426,26 @@ class GTranslateWidget extends WP_Widget {
|
|
1354 |
echo '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
1355 |
}
|
1356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1357 |
echo $args['after_widget'];
|
1358 |
}
|
1359 |
|
@@ -1761,12 +1853,14 @@ if($data['floating_language_selector'] != 'no' and !is_admin()) {
|
|
1761 |
GTranslate::load_defaults($data);
|
1762 |
|
1763 |
if($data['widget_look'] == 'dropdown_with_flags')
|
1764 |
-
|
1765 |
-
$vertical_location = '32px';
|
1766 |
-
else
|
1767 |
-
$vertical_location = '0';
|
1768 |
else
|
1769 |
-
$vertical_location =
|
|
|
|
|
|
|
|
|
|
|
1770 |
|
1771 |
switch($data['floating_language_selector']) {
|
1772 |
case 'top_left': $html = '<div style="position:fixed;top:'.$vertical_location.';left:8%;z-index:999999;" id="gtranslate_wrapper">'.GTranslate::get_widget_code(false).'</div>'; break;
|
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.33
|
7 |
Author: Translate AI Multilingual Solutions
|
8 |
Author URI: https://gtranslate.io
|
9 |
Text Domain: gtranslate
|
118 |
echo '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
119 |
}
|
120 |
|
121 |
+
// detect browser language
|
122 |
+
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
|
123 |
+
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')
|
124 |
+
$allowed_languages = $data['fincl_langs'];
|
125 |
+
elseif($data['widget_look'] == 'flags_dropdown')
|
126 |
+
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
|
127 |
+
else
|
128 |
+
$allowed_languages = $data['incl_langs'];
|
129 |
+
$allowed_languages = json_encode($allowed_languages);
|
130 |
+
|
131 |
+
echo "<script>jQuery(document).ready(function() {";
|
132 |
+
echo "var allowed_languages = $allowed_languages;var accept_language = navigator.language.toLowerCase() || navigator.userLanguage.toLowerCase();switch(accept_language) {case 'zh-cn': var preferred_language = 'zh-CN'; break;case 'zh': var preferred_language = 'zh-CN'; break;case 'zh-tw': var preferred_language = 'zh-TW'; break;case 'zh-hk': var preferred_language = 'zh-TW'; break;default: var preferred_language = accept_language.substr(0, 2); break;}if(preferred_language != '".$data['default_language']."' && GTranslateGetCurrentLang() == null && document.cookie.match('gt_auto_switch') == null && allowed_languages.indexOf(preferred_language) >= 0){doGTranslate('".$data['default_language']."|'+preferred_language);document.cookie = 'gt_auto_switch=1; expires=Thu, 05 Dec 2030 08:08:08 UTC; path=/;';";
|
133 |
+
if($data['widget_look'] == 'dropdown_with_flags') {
|
134 |
+
echo "var lang_html = jQuery('div.switcher div.option').find('img[alt=\"'+preferred_language+'\"]').parent().html();if(typeof lang_html != 'undefined')jQuery('div.switcher div.selected a').html(lang_html.replace('data-gt-lazy-', ''));";
|
135 |
+
} elseif($data['widget_look'] == 'popup') {
|
136 |
+
echo 'var lang_html = jQuery(".gt_languages a[onclick*=\'|"+preferred_language+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');';
|
137 |
+
}
|
138 |
+
echo "}});</script>";
|
139 |
+
}
|
140 |
+
|
141 |
echo $args['after_widget'];
|
142 |
}
|
143 |
|
159 |
echo '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
160 |
}
|
161 |
|
162 |
+
// detect browser language
|
163 |
+
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
|
164 |
+
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')
|
165 |
+
$allowed_languages = $data['fincl_langs'];
|
166 |
+
elseif($data['widget_look'] == 'flags_dropdown')
|
167 |
+
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
|
168 |
+
else
|
169 |
+
$allowed_languages = $data['incl_langs'];
|
170 |
+
$allowed_languages = json_encode($allowed_languages);
|
171 |
+
|
172 |
+
echo "<script>jQuery(document).ready(function() {";
|
173 |
+
echo "var allowed_languages = $allowed_languages;var accept_language = navigator.language.toLowerCase() || navigator.userLanguage.toLowerCase();switch(accept_language) {case 'zh-cn': var preferred_language = 'zh-CN'; break;case 'zh': var preferred_language = 'zh-CN'; break;case 'zh-tw': var preferred_language = 'zh-TW'; break;case 'zh-hk': var preferred_language = 'zh-TW'; break;default: var preferred_language = accept_language.substr(0, 2); break;}if(preferred_language != '".$data['default_language']."' && GTranslateGetCurrentLang() == null && document.cookie.match('gt_auto_switch') == null && allowed_languages.indexOf(preferred_language) >= 0){doGTranslate('".$data['default_language']."|'+preferred_language);document.cookie = 'gt_auto_switch=1; expires=Thu, 05 Dec 2030 08:08:08 UTC; path=/;';";
|
174 |
+
if($data['widget_look'] == 'dropdown_with_flags') {
|
175 |
+
echo "var lang_html = jQuery('div.switcher div.option').find('img[alt=\"'+preferred_language+'\"]').parent().html();if(typeof lang_html != 'undefined')jQuery('div.switcher div.selected a').html(lang_html.replace('data-gt-lazy-', ''));";
|
176 |
+
} elseif($data['widget_look'] == 'popup') {
|
177 |
+
echo 'var lang_html = jQuery(".gt_languages a[onclick*=\'|"+preferred_language+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');';
|
178 |
+
}
|
179 |
+
echo "}});</script>";
|
180 |
+
}
|
181 |
+
|
182 |
echo $args['after_widget'];
|
183 |
}
|
184 |
|
192 |
|
193 |
// avoid caching issues
|
194 |
if($data['widget_look'] == 'dropdown_with_flags' and ($data['pro_version'] or $data['enterprise_version'])) {
|
195 |
+
$data['widget_code'] .= '<script>jQuery(document).ready(function() {var lang_html = jQuery(".switcher div.option a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'.switcher div.selected a\').html(lang_html.replace("data-gt-lazy-", ""))});</script>';
|
196 |
} elseif($data['widget_look'] == 'popup' and ($data['pro_version'] or $data['enterprise_version'])) {
|
197 |
+
$data['widget_code'] .= '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
198 |
+
}
|
199 |
+
|
200 |
+
//$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'ru-Ru'; // debug
|
201 |
+
|
202 |
+
// detect browser language
|
203 |
+
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
|
204 |
+
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')
|
205 |
+
$allowed_languages = $data['fincl_langs'];
|
206 |
+
elseif($data['widget_look'] == 'flags_dropdown')
|
207 |
+
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
|
208 |
+
else
|
209 |
+
$allowed_languages = $data['incl_langs'];
|
210 |
+
$allowed_languages = json_encode($allowed_languages);
|
211 |
+
|
212 |
+
$data['widget_code'] .= "<script>jQuery(document).ready(function() {";
|
213 |
+
$data['widget_code'] .= "var allowed_languages = $allowed_languages;var accept_language = navigator.language.toLowerCase() || navigator.userLanguage.toLowerCase();switch(accept_language) {case 'zh-cn': var preferred_language = 'zh-CN'; break;case 'zh': var preferred_language = 'zh-CN'; break;case 'zh-tw': var preferred_language = 'zh-TW'; break;case 'zh-hk': var preferred_language = 'zh-TW'; break;default: var preferred_language = accept_language.substr(0, 2); break;}if(preferred_language != '".$data['default_language']."' && GTranslateGetCurrentLang() == null && document.cookie.match('gt_auto_switch') == null && allowed_languages.indexOf(preferred_language) >= 0){doGTranslate('".$data['default_language']."|'+preferred_language);document.cookie = 'gt_auto_switch=1; expires=Thu, 05 Dec 2030 08:08:08 UTC; path=/;';";
|
214 |
+
if($data['widget_look'] == 'dropdown_with_flags') {
|
215 |
+
$data['widget_code'] .= "var lang_html = jQuery('div.switcher div.option').find('img[alt=\"'+preferred_language+'\"]').parent().html();if(typeof lang_html != 'undefined')jQuery('div.switcher div.selected a').html(lang_html.replace('data-gt-lazy-', ''));";
|
216 |
+
} elseif($data['widget_look'] == 'popup') {
|
217 |
+
$data['widget_code'] .= 'var lang_html = jQuery(".gt_languages a[onclick*=\'|"+preferred_language+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');';
|
218 |
+
}
|
219 |
+
$data['widget_code'] .= "}});</script>";
|
220 |
}
|
221 |
|
222 |
return $data['widget_code'];
|
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() {
|
301 |
var floating_language_selector = jQuery('#floating_language_selector').val();
|
302 |
var native_language_names = jQuery('#native_language_names:checked').length > 0 ? true : false;
|
303 |
var analytics = jQuery('#analytics:checked').length > 0 ? true : false;
|
304 |
+
var detect_browser_language = jQuery('#detect_browser_language:checked').length > 0 ? true : false;
|
305 |
|
306 |
// make sure default language is on
|
307 |
if(widget_look == 'flags_dropdown' || widget_look == 'dropdown_with_flags' || widget_look == 'flags' || widget_look == 'flags_name' || widget_code == 'flags_code' || widget_look == 'popup')
|
313 |
translation_method = 'redirect';
|
314 |
jQuery('#new_window_option').show();
|
315 |
jQuery('#url_translation_option').show();
|
316 |
+
jQuery('#auto_switch_option').hide();
|
317 |
} else {
|
318 |
jQuery('#new_window_option').hide();
|
319 |
jQuery('#url_translation_option').hide();
|
320 |
+
jQuery('#auto_switch_option').show();
|
321 |
}
|
322 |
|
323 |
if(widget_look == 'dropdown' || widget_look == 'flags_dropdown' || widget_look == 'globe' || widget_look == 'lang_names' || widget_look == 'lang_codes') {
|
347 |
jQuery('#line_break_option').hide();
|
348 |
}
|
349 |
|
350 |
+
if(widget_look == 'dropdown_with_flags' || widget_look == 'dropdown' || widget_look == 'lang_names' || widget_look == 'lang_codes' || widget_look == 'globe') {
|
351 |
jQuery('#flag_size_option').hide();
|
352 |
} else {
|
353 |
jQuery('#flag_size_option').show();
|
565 |
widget_preview += '</div>'+new_line;
|
566 |
widget_preview += '</div>'+new_line;
|
567 |
|
568 |
+
//console.log('Count: ' + count_languages);
|
569 |
|
570 |
flag_size = parseInt(flag_size);
|
571 |
+
//console.log('Flag size: ' + flag_size);
|
572 |
|
573 |
var popup_height = 25 + count_languages * ((flag_size > 16 ? flag_size : 20) + 10 + 1);
|
574 |
|
575 |
+
//console.log('height: ' + popup_height);
|
576 |
|
577 |
var popup_columns = Math.ceil(popup_height / 375);
|
578 |
|
579 |
+
//console.log('Cols: ' + popup_columns);
|
580 |
|
581 |
if(popup_height > 375)
|
582 |
popup_height = 375;
|
583 |
|
584 |
var popup_width = popup_columns * (326 + 15);
|
585 |
|
586 |
+
//console.log('Width: ' + popup_width);
|
587 |
|
588 |
if(popup_width > 980)
|
589 |
popup_width = 980;
|
777 |
jQuery('#floating_language_selector').val('$floating_language_selector');
|
778 |
jQuery('#native_language_names').attr('checked', '$native_language_names'.length > 0);
|
779 |
jQuery('#analytics').attr('checked', '$analytics'.length > 0);
|
780 |
+
jQuery('#detect_browser_language').attr('checked', '$detect_browser_language'.length > 0);
|
781 |
jQuery('#add_new_line').attr('checked', '$add_new_line'.length > 0);
|
782 |
jQuery('#default_language').val('$default_language');
|
783 |
jQuery('#widget_look').val('$widget_look');
|
786 |
if(jQuery('#pro_version:checked').length || jQuery('#enterprise_version:checked').length) {
|
787 |
jQuery('#new_window_option').show();
|
788 |
jQuery('#url_translation_option').show();
|
789 |
+
jQuery('#auto_switch_option').hide();
|
790 |
}
|
791 |
|
792 |
if('$widget_look' == 'dropdown' || '$widget_look' == 'flags_dropdown' || '$widget_look' == 'globe' || '$widget_look' == 'lang_names' || '$widget_look' == 'lang_codes') {
|
816 |
jQuery('#line_break_option').hide();
|
817 |
}
|
818 |
|
819 |
+
if('$widget_look' == 'dropdown_with_flags' || '$widget_look' == 'dropdown' || '$widget_look' == 'lang_names' || '$widget_look' == 'lang_codes' || '$widget_look' == 'globe') {
|
820 |
jQuery('#flag_size_option').hide();
|
821 |
} else {
|
822 |
jQuery('#flag_size_option').show();
|
1005 |
</select>
|
1006 |
</td>
|
1007 |
</tr>
|
|
|
|
|
|
|
|
|
1008 |
<tr>
|
1009 |
<td class="option_name">* <?php _e('Sub-directory URL structure', 'gtranslate'); ?>:<br><code><small>http://example.com/<b>ru</b>/</small></code></td>
|
1010 |
<td><input id="pro_version" name="pro_version" value="1" type="checkbox" onclick="if(jQuery('#pro_version').is(':checked') && jQuery('#enterprise_version').is(':checked'))jQuery('#enterprise_version').prop('checked', false);RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/> <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank" title="If you already have a subscription, you can enable this.">* <?php _e('for paid plans only', 'gtranslate'); ?></a></td>
|
1021 |
<td class="option_name"><?php _e('Open in new window', 'gtranslate'); ?>:</td>
|
1022 |
<td><input id="new_window" name="new_window" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
1023 |
</tr>
|
1024 |
+
<tr>
|
1025 |
+
<td class="option_name"><?php _e('Analytics', 'gtranslate'); ?>:</td>
|
1026 |
+
<td><input id="analytics" name="analytics" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
1027 |
+
</tr>
|
1028 |
+
<tr id="auto_switch_option">
|
1029 |
+
<td class="option_name"><?php _e('Auto switch to browser language', 'gtranslate'); ?>:</td>
|
1030 |
+
<td><input id="detect_browser_language" name="detect_browser_language" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
1031 |
+
</tr>
|
1032 |
<tr>
|
1033 |
<td class="option_name"><?php _e('Show in menu', 'gtranslate'); ?>:</td>
|
1034 |
<td>
|
1057 |
</select>
|
1058 |
</td>
|
1059 |
</tr>
|
1060 |
+
<tr>
|
1061 |
<td class="option_name"><?php _e('Show native language names', 'gtranslate'); ?>:</td>
|
1062 |
<td><input id="native_language_names" name="native_language_names" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/></td>
|
|
|
1063 |
</tr>
|
1064 |
<tr id="flag_size_option">
|
1065 |
<td class="option_name"><?php _e('Flag size', 'gtranslate'); ?>:</td>
|
1305 |
$data['floating_language_selector'] = isset($_POST['floating_language_selector']) ? sanitize_text_field($_POST['floating_language_selector']) : 'no';
|
1306 |
$data['native_language_names'] = isset($_POST['native_language_names']) ? intval($_POST['native_language_names']) : '';
|
1307 |
$data['analytics'] = isset($_POST['analytics']) ? intval($_POST['analytics']) : '';
|
1308 |
+
$data['detect_browser_language'] = isset($_POST['detect_browser_language']) ? intval($_POST['detect_browser_language']) : '';
|
1309 |
$data['add_new_line'] = isset($_POST['add_new_line']) ? intval($_POST['add_new_line']) : '';
|
1310 |
$data['default_language'] = isset($_POST['default_language']) ? sanitize_text_field($_POST['default_language']) : 'en';
|
1311 |
$data['translation_method'] = 'onfly';
|
1322 |
else
|
1323 |
$data['widget_code'] = isset($_POST['widget_code']) ? stripslashes($_POST['widget_code']) : '';
|
1324 |
|
|
|
1325 |
echo '<p style="color:red;">' . __('Changes Saved', 'gtranslate') . '</p>';
|
1326 |
update_option('GTranslate', $data);
|
1327 |
|
1371 |
$data['floating_language_selector'] = isset($data['floating_language_selector']) ? $data['floating_language_selector'] : 'no';
|
1372 |
$data['native_language_names'] = isset($data['native_language_names']) ? $data['native_language_names'] : '';
|
1373 |
$data['analytics'] = isset($data['analytics']) ? $data['analytics'] : '';
|
1374 |
+
$data['detect_browser_language'] = isset($data['detect_browser_language']) ? $data['detect_browser_language'] : '';
|
1375 |
$data['add_new_line'] = isset($data['add_new_line']) ? $data['add_new_line'] : '1';
|
1376 |
|
1377 |
if(!isset($data['default_language'])) {
|
1426 |
echo '<script>jQuery(document).ready(function() {var lang_html = jQuery(".gt_languages a[onclick*=\'|"+jQuery(\'html\').attr(\'lang\')+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');});</script>';
|
1427 |
}
|
1428 |
|
1429 |
+
// detect browser language
|
1430 |
+
if(!($data['pro_version'] or $data['enterprise_version']) and $data['detect_browser_language']) {
|
1431 |
+
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')
|
1432 |
+
$allowed_languages = $data['fincl_langs'];
|
1433 |
+
elseif($data['widget_look'] == 'flags_dropdown')
|
1434 |
+
$allowed_languages = array_values(array_unique(array_merge($data['fincl_langs'], $data['incl_langs'])));
|
1435 |
+
else
|
1436 |
+
$allowed_languages = $data['incl_langs'];
|
1437 |
+
$allowed_languages = json_encode($allowed_languages);
|
1438 |
+
|
1439 |
+
echo "<script>jQuery(document).ready(function() {";
|
1440 |
+
echo "var allowed_languages = $allowed_languages;var accept_language = navigator.language.toLowerCase() || navigator.userLanguage.toLowerCase();switch(accept_language) {case 'zh-cn': var preferred_language = 'zh-CN'; break;case 'zh': var preferred_language = 'zh-CN'; break;case 'zh-tw': var preferred_language = 'zh-TW'; break;case 'zh-hk': var preferred_language = 'zh-TW'; break;default: var preferred_language = accept_language.substr(0, 2); break;}if(preferred_language != '".$data['default_language']."' && GTranslateGetCurrentLang() == null && document.cookie.match('gt_auto_switch') == null && allowed_languages.indexOf(preferred_language) >= 0){doGTranslate('".$data['default_language']."|'+preferred_language);document.cookie = 'gt_auto_switch=1; expires=Thu, 05 Dec 2030 08:08:08 UTC; path=/;';";
|
1441 |
+
if($data['widget_look'] == 'dropdown_with_flags') {
|
1442 |
+
echo "var lang_html = jQuery('div.switcher div.option').find('img[alt=\"'+preferred_language+'\"]').parent().html();if(typeof lang_html != 'undefined')jQuery('div.switcher div.selected a').html(lang_html.replace('data-gt-lazy-', ''));";
|
1443 |
+
} elseif($data['widget_look'] == 'popup') {
|
1444 |
+
echo 'var lang_html = jQuery(".gt_languages a[onclick*=\'|"+preferred_language+"\']").html();if(typeof lang_html != "undefined")jQuery(\'a.switcher-popup\').html(lang_html.replace("data-gt-lazy-", "")+\'<span style=\"color:#666;font-size:8px;font-weight:bold;\">▼</span>\');';
|
1445 |
+
}
|
1446 |
+
echo "}});</script>";
|
1447 |
+
}
|
1448 |
+
|
1449 |
echo $args['after_widget'];
|
1450 |
}
|
1451 |
|
1853 |
GTranslate::load_defaults($data);
|
1854 |
|
1855 |
if($data['widget_look'] == 'dropdown_with_flags')
|
1856 |
+
$vertical_location = 0;
|
|
|
|
|
|
|
1857 |
else
|
1858 |
+
$vertical_location = 10;
|
1859 |
+
|
1860 |
+
if(is_admin_bar_showing() and ($data['floating_language_selector'] == 'top_left' or $data['floating_language_selector'] == 'top_right' or $data['floating_language_selector'] == 'top_left_sticky' or $data['floating_language_selector'] == 'top_right_sticky'))
|
1861 |
+
$vertical_location += 32;
|
1862 |
+
|
1863 |
+
$vertical_location = $vertical_location . 'px';
|
1864 |
|
1865 |
switch($data['floating_language_selector']) {
|
1866 |
case 'top_left': $html = '<div style="position:fixed;top:'.$vertical_location.';left:8%;z-index:999999;" id="gtranslate_wrapper">'.GTranslate::get_widget_code(false).'</div>'; break;
|
native_names_map.php
CHANGED
@@ -31,7 +31,7 @@ $native_names_map = array(
|
|
31 |
'gl' => 'Galego',
|
32 |
'ka' => 'ქართული',
|
33 |
'de' => 'Deutsch',
|
34 |
-
'el' => '
|
35 |
'gu' => 'ગુજરાતી',
|
36 |
'ht' => 'Kreyol ayisyen',
|
37 |
'ha' => 'Harshen Hausa',
|
31 |
'gl' => 'Galego',
|
32 |
'ka' => 'ქართული',
|
33 |
'de' => 'Deutsch',
|
34 |
+
'el' => 'Ελληνικά',
|
35 |
'gu' => 'ગુજરાતી',
|
36 |
'ht' => 'Kreyol ayisyen',
|
37 |
'ha' => 'Harshen Hausa',
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: edo888
|
|
3 |
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.
|
7 |
-
Stable tag: 2.8.
|
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
|
@@ -35,6 +35,7 @@ Please check our [FAQ](https://gtranslate.io/?xyz=998#faq) to get quick answers.
|
|
35 |
* Themes and plugins translation
|
36 |
* Right to left language support
|
37 |
* Google language translator widget
|
|
|
38 |
* Available styles Dropdown, Flags, Flags with dropdown, Nice dropdown with flags, Flags with language names, Flags with language codes, Language names, Language codes, Globe, Popup
|
39 |
* Floating language selector
|
40 |
* Language bar with flags in menu
|
@@ -79,8 +80,6 @@ Please check our [FAQ](https://gtranslate.io/?xyz=998#faq) to get quick answers.
|
|
79 |
**Edit Translations Demo (paid)**
|
80 |
[youtube https://www.youtube.com/watch?v=YwSy3VtQx3I]
|
81 |
|
82 |
-
Keywords: translate wordpress, wordpress translator, translate, translator, translation, machine translate, wp translate, ajax translate, bilingual, multilanguage, multilingual, i18n, localization, l10n, tradurre, traducir, traduire, traduzione, ubersetzung, mehrsprachig, oversette, oversatta, vertaling, vertaler, meertalig
|
83 |
-
|
84 |
List of supported languages: Afrikaans, Albanian, Amharic, Arabic, Armenian, Azerbaijani, Basque, Belarusian, Bengali, Bosnian, Bulgarian, Catalan, Cebuano, Chichewa, Chinese (Simplified), Chinese (Traditional), Corsican, Croatian, Czech, Danish, Dutch, English, Esperanto, Estonian, Filipino, Finnish, French, Frisian, Galician, Georgian, German, Greek, Gujarati, Haitian Creole, Hausa, Hawaiian, Hebrew, Hindi, Hmong, Hungarian, Icelandic, Igbo, Indonesian, Irish, Italian, Japanese, Javanese, Kannada, Kazakh, Khmer, Korean, Kurdish (Kurmanji), Kyrgyz, Lao, Latin, Latvian, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Myanmar (Burmese), Nepali, Norwegian, Pashto, Persian, Polish, Portuguese, Punjabi, Romanian, Russian, Samoan, Scottish Gaelic, Serbian, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenian, Somali, Spanish, Sudanese, Swahili, Swedish, Tajik, Tamil, Telugu, Thai, Turkish, Ukrainian, Urdu, Uzbek, Vietnamese, Welsh, Xhosa, Yiddish, Yoruba, Zulu
|
85 |
|
86 |
== Installation ==
|
@@ -220,6 +219,14 @@ You need to go to the language you want to edit, for instance, French: http://do
|
|
220 |
|
221 |
== Changelog ==
|
222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
= 2.8.31 =
|
224 |
* Removed email and name from Intercom chat
|
225 |
|
3 |
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.33
|
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
|
35 |
* Themes and plugins translation
|
36 |
* Right to left language support
|
37 |
* Google language translator widget
|
38 |
+
* Auto-switch language based on browser defined language
|
39 |
* Available styles Dropdown, Flags, Flags with dropdown, Nice dropdown with flags, Flags with language names, Flags with language codes, Language names, Language codes, Globe, Popup
|
40 |
* Floating language selector
|
41 |
* Language bar with flags in menu
|
80 |
**Edit Translations Demo (paid)**
|
81 |
[youtube https://www.youtube.com/watch?v=YwSy3VtQx3I]
|
82 |
|
|
|
|
|
83 |
List of supported languages: Afrikaans, Albanian, Amharic, Arabic, Armenian, Azerbaijani, Basque, Belarusian, Bengali, Bosnian, Bulgarian, Catalan, Cebuano, Chichewa, Chinese (Simplified), Chinese (Traditional), Corsican, Croatian, Czech, Danish, Dutch, English, Esperanto, Estonian, Filipino, Finnish, French, Frisian, Galician, Georgian, German, Greek, Gujarati, Haitian Creole, Hausa, Hawaiian, Hebrew, Hindi, Hmong, Hungarian, Icelandic, Igbo, Indonesian, Irish, Italian, Japanese, Javanese, Kannada, Kazakh, Khmer, Korean, Kurdish (Kurmanji), Kyrgyz, Lao, Latin, Latvian, Lithuanian, Luxembourgish, Macedonian, Malagasy, Malay, Malayalam, Maltese, Maori, Marathi, Mongolian, Myanmar (Burmese), Nepali, Norwegian, Pashto, Persian, Polish, Portuguese, Punjabi, Romanian, Russian, Samoan, Scottish Gaelic, Serbian, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenian, Somali, Spanish, Sudanese, Swahili, Swedish, Tajik, Tamil, Telugu, Thai, Turkish, Ukrainian, Urdu, Uzbek, Vietnamese, Welsh, Xhosa, Yiddish, Yoruba, Zulu
|
84 |
|
85 |
== Installation ==
|
219 |
|
220 |
== Changelog ==
|
221 |
|
222 |
+
= 2.8.33 =
|
223 |
+
* Fixed issue related to new version of Contact Form 7
|
224 |
+
* Ready for WordPress 4.9
|
225 |
+
|
226 |
+
= 2.8.32 =
|
227 |
+
* New feature: auto switch language based on browser language settigns
|
228 |
+
* Minor fixes: Greek name in native alphabet, Flag size option for Globe Widget look, vertical position in pixels
|
229 |
+
|
230 |
= 2.8.31 =
|
231 |
* Removed email and name from Intercom chat
|
232 |
|
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['
|
93 |
-
$request_headers['Content-Type'] = '
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
//
|
108 |
-
$
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
case '
|
128 |
-
curl_setopt($ch,
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
$
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
$
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
$
|
185 |
-
|
186 |
-
|
187 |
-
$
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
);
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
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 |
+
}
|