Translate WordPress with GTranslate - Version 2.8.3

Version Description

  • Added URL add-on to easily enable sub-directory URL structure (paid)
  • New option to easily enable URL Translation
  • Disallow both sub-domain and sub-directory URL structure selection at the same time
  • Fix for language change issue when URL Translation is on
Download this release

Release Info

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

Code changes from version 2.8.2 to 2.8.3

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.2
7
  Author: Edvard Ananyan
8
  Author URI: https://gtranslate.io
9
  Text Domain: gtranslate
@@ -79,6 +79,13 @@ if($data['floating_language_selector'] != 'no' and !$data['show_in_primary_menu'
79
  }
80
  }
81
 
 
 
 
 
 
 
 
82
  class GTranslate extends WP_Widget {
83
  public static function activate() {
84
  $data = array(
@@ -117,6 +124,9 @@ class GTranslate extends WP_Widget {
117
 
118
  wp_enqueue_style( 'gtranslate-style', plugins_url('gtranslate-style'.$data['flag_size'].'.css', __FILE__) );
119
  wp_enqueue_script('jquery');
 
 
 
120
  }
121
 
122
  public static function load_textdomain() {
@@ -251,8 +261,10 @@ function RefreshDoWidgetCode() {
251
  if(pro_version || enterprise_version) {
252
  translation_method = 'redirect';
253
  jQuery('#new_window_option').show();
 
254
  } else {
255
  jQuery('#new_window_option').hide();
 
256
  }
257
 
258
  if(widget_look == 'dropdown' || widget_look == 'flags_dropdown' || widget_look == 'globe') {
@@ -297,28 +309,7 @@ function RefreshDoWidgetCode() {
297
  if(pro_version && enterprise_version)
298
  pro_version = false;
299
 
300
- if(translation_method == 'google_default') {
301
- included_languages = '';
302
- jQuery.each(language_codes2, function(i, val) {
303
- lang = language_codes2[i];
304
- if(jQuery('#incl_langs'+lang+':checked').length) {
305
- lang_name = gt_lang_array[lang];
306
- included_languages += ','+lang;
307
- }
308
- });
309
-
310
- widget_preview += '<div id="google_translate_element"></div>'+new_line;
311
- widget_preview += '<script type="text/javascript">'+new_line;
312
- widget_preview += 'function googleTranslateElementInit() {new google.translate.TranslateElement({pageLanguage: \'';
313
- widget_preview += default_language;
314
- widget_preview += '\', layout: google.translate.TranslateElement.InlineLayout.SIMPLE';
315
- widget_preview += ', autoDisplay: false';
316
- widget_preview += ', includedLanguages: \'';
317
- widget_preview += included_languages;
318
- widget_preview += "'}, 'google_translate_element');}"+new_line;
319
- widget_preview += '<\/script>';
320
- widget_preview += '<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"><\/script>'+new_line;
321
- } else if(translation_method == 'on_fly' || translation_method == 'redirect' || translation_method == 'onfly') {
322
  // Adding flags
323
  if(widget_look == 'flags' || widget_look == 'flags_dropdown' /* jQuery('#show_flags:checked').length */) {
324
  //console.log('adding flags');
@@ -557,42 +548,25 @@ function hideGSatelites($) {
557
  if(pro_version && translation_method == 'redirect' && new_window) {
558
  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;
559
  if(analytics)
560
- 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.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')openTab(location.protocol+'//'+location.host+location.pathname.replace('/'+plang+'/', '/')+location.search);else openTab(location.protocol+'//'+location.host+'/'+lang+location.pathname.replace('/'+plang+'/', '/')+location.search);}"+new_line;
561
  else
562
- 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.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')openTab(location.protocol+'//'+location.host+location.pathname.replace('/'+plang+'/', '/')+location.search);else openTab(location.protocol+'//'+location.host+'/'+lang+location.pathname.replace('/'+plang+'/', '/')+location.search);}"+new_line;
563
  } else if(pro_version && translation_method == 'redirect') {
564
  if(analytics)
565
- 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.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')location.href=location.protocol+'//'+location.host+location.pathname.replace('/'+plang+'/', '/')+location.search;else location.href=location.protocol+'//'+location.host+'/'+lang+location.pathname.replace('/'+plang+'/', '/')+location.search;}"+new_line;
566
  else
567
- 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.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')location.href=location.protocol+'//'+location.host+location.pathname.replace('/'+plang+'/', '/')+location.search;else location.href=location.protocol+'//'+location.host+'/'+lang+location.pathname.replace('/'+plang+'/', '/')+location.search;}"+new_line;
568
  } else if(enterprise_version && translation_method == 'redirect' && new_window) {
569
  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;
570
  if(analytics)
571
- 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='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+location.pathname+location.search);}"+new_line;
572
  else
573
- 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='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+location.pathname+location.search);}"+new_line;
574
  } else if(enterprise_version && translation_method == 'redirect') {
575
  if(analytics)
576
- 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='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+location.pathname+location.search;}"+new_line;
577
- else
578
- 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='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+location.pathname+location.search;}"+new_line;
579
- } else if(translation_method == 'redirect' && new_window) {
580
- widget_code += 'if(top.location!=self.location)top.location=self.location;'+new_line;
581
- widget_code += "window['_tipoff']=function(){};window['_tipon']=function(a){};"+new_line;
582
- if(analytics)
583
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;if(location.hostname!='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}if(location.hostname=='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')openTab(unescape(gfg('u')));else if(location.hostname!='translate.googleusercontent.com' && lang_pair!='"+default_language+"|"+default_language+"')openTab('//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href));else openTab('//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u')));}"+new_line;
584
- else
585
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(location.hostname!='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')return;else if(location.hostname=='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')openTab(unescape(gfg('u')));else if(location.hostname!='translate.googleusercontent.com' && lang_pair!='"+default_language+"|"+default_language+"')openTab('//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href));else openTab('//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u')));}"+new_line;
586
- widget_code += 'function gfg(name) {name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(location.href);if(results==null)return "";return results[1];}'+new_line;
587
- 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;
588
- } else if(translation_method == 'redirect') {
589
- widget_code += 'if(top.location!=self.location)top.location=self.location;'+new_line;
590
- widget_code += "window['_tipoff']=function(){};window['_tipon']=function(a){};"+new_line;
591
- if(analytics)
592
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;if(location.hostname!='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}if(location.hostname=='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')location.href=unescape(gfg('u'));else if(location.hostname!='translate.googleusercontent.com' && lang_pair!='"+default_language+"|"+default_language+"')location.href='//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href);else location.href='//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u'));}"+new_line;
593
  else
594
- widget_code += "function doGTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(location.hostname!='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')return;else if(location.hostname=='translate.googleusercontent.com' && lang_pair=='"+default_language+"|"+default_language+"')location.href=unescape(gfg('u'));else if(location.hostname!='translate.googleusercontent.com' && lang_pair!='"+default_language+"|"+default_language+"')location.href='//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+escape(location.href);else location.href='//translate.google.com/translate?client=tmpg&hl=en&langpair='+lang_pair+'&u='+unescape(gfg('u'));}"+new_line;
595
- widget_code += 'function gfg(name) {name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(location.href);if(results==null)return "";return results[1];}'+new_line;
596
  } else if(translation_method == 'onfly') {
597
  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){}}function doGTranslate(lang_pair){if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var teCombo;var sel=document.getElementsByTagName('select');for(var i=0;i<sel.length;i++)if(sel[i].className=='goog-te-combo')teCombo=sel[i];if(document.getElementById('google_translate_element2')==null||document.getElementById('google_translate_element2').innerHTML.length==0||teCombo.length==0||teCombo.innerHTML.length==0){setTimeout(function(){doGTranslate(lang_pair)},500)}else{teCombo.value=lang;GTranslateFireEvent(teCombo,'change');GTranslateFireEvent(teCombo,'change')}}"+new_line;
598
  if(widget_look == 'dropdown_with_flags') {
@@ -624,6 +598,7 @@ function ShowWidgetPreview(widget_preview) {
624
 
625
  jQuery('#pro_version').attr('checked', '$pro_version'.length > 0);
626
  jQuery('#enterprise_version').attr('checked', '$enterprise_version'.length > 0);
 
627
  jQuery('#new_window').attr('checked', '$new_window'.length > 0);
628
  jQuery('#show_in_primary_menu').attr('checked', '$show_in_primary_menu'.length > 0);
629
  jQuery('#floating_language_selector').val('$floating_language_selector');
@@ -636,8 +611,10 @@ jQuery('#default_language').val('$default_language');
636
  jQuery('#widget_look').val('$widget_look');
637
  jQuery('#flag_size').val('$flag_size');
638
 
639
- if(jQuery('#pro_version:checked').length || jQuery('#enterprise_version:checked').length)
640
  jQuery('#new_window_option').show();
 
 
641
 
642
  if('$widget_look' == 'dropdown' || '$widget_look' == 'flags_dropdown' || '$widget_look' == 'globe') {
643
  jQuery('#dropdown_languages_option').show();
@@ -863,11 +840,15 @@ foreach($alt_flags as $flag)
863
  </tr>
864
  <tr>
865
  <td class="option_name">* <?php _e('Sub-directory URL structure', 'gtranslate'); ?>:<br><code><small>http://example.com/<b>ru</b>/</small></code></td>
866
- <td><input id="pro_version" name="pro_version" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/> <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">* <?php _e('paid plans only', 'gtranslate'); ?></a></td>
867
  </tr>
868
  <tr>
869
  <td class="option_name">* <?php _e('Sub-domain URL structure', 'gtranslate'); ?>:<br><code><small>http://<b>es</b>.example.com/</small></code></td>
870
- <td><input id="enterprise_version" name="enterprise_version" value="1" type="checkbox" onclick="RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/> <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">* <?php _e('paid plans only', 'gtranslate'); ?></a></td>
 
 
 
 
871
  </tr>
872
  <tr id="new_window_option" style="display:none;">
873
  <td class="option_name"><?php _e('Open in new window', 'gtranslate'); ?>:</td>
@@ -988,48 +969,47 @@ foreach($alt_flags as $flag)
988
  </div>
989
  </div>
990
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
991
  <div id="poststuff">
992
  <div class="postbox">
993
  <h3 id="settings"><?php _e('Do you like GTranslate?', 'gtranslate'); ?></h3>
994
  <div class="inside">
995
- <p><?php _e('Please write a review on', 'gtranslate'); ?> <a href="https://wordpress.org/support/view/plugin-reviews/gtranslate?filter=5">WordPress.org</a>.</p>
996
 
997
  <div id="fb-root"></div>
998
  <script>(function(d, s, id) {
999
  var js, fjs = d.getElementsByTagName(s)[0];
1000
  if (d.getElementById(id)) return;
1001
  js = d.createElement(s); js.id = id;
1002
- js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5&appId=231165476898475";
1003
  fjs.parentNode.insertBefore(js, fjs);
1004
  }(document, 'script', 'facebook-jssdk'));</script>
1005
 
1006
- <div class="fb-page" data-href="https://www.facebook.com/gtranslate" data-width="450" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/gtranslate"><a href="https://www.facebook.com/gtranslate">GTranslate</a></blockquote></div></div>
1007
-
1008
  </div>
1009
  </div>
1010
  </div>
1011
 
1012
- <div id="poststuff">
1013
- <div class="postbox">
1014
- <h3 id="settings"><?php _e('Useful info', 'gtranslate'); ?></h3>
1015
- <div class="inside">
1016
- <?php _e('Upgrade to <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">GTranslate Enterprise</a> to have the following features', 'gtranslate'); ?>:
1017
- <ul style="list-style-type: square;padding-left:40px;">
1018
- <li><?php _e('Enable search engine indexing', 'gtranslate'); ?></li>
1019
- <li><?php _e('Search engine friendly (SEF) URLs', 'gtranslate'); ?></li>
1020
- <li><?php _e('Increase traffic and AdSense revenue', 'gtranslate'); ?></li>
1021
- <li><?php _e('Meta data translation', 'gtranslate'); ?></li>
1022
- <li><?php _e('Edit translations manually', 'gtranslate'); ?></li>
1023
- <li><?php _e('URL translation', 'gtranslate'); ?></li>
1024
- <li><?php _e('Language hosting', 'gtranslate'); ?></li>
1025
- <li><?php _e('Seamless updates', 'gtranslate'); ?></li>
1026
- <li><?php _e('SSL support', 'gtranslate'); ?></li>
1027
- </ul>
1028
-
1029
- <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank"><?php _e('More Info', 'gtranslate'); ?></a>
1030
- </div>
1031
- </div>
1032
- </div>
1033
  <div id="poststuff">
1034
  <div class="postbox">
1035
  <h3 id="settings"><?php _e('GTranslate Tour Video', 'gtranslate'); ?></h3>
@@ -1081,6 +1061,7 @@ foreach($alt_flags as $flag)
1081
 
1082
  $data['pro_version'] = isset($_POST['pro_version']) ? intval($_POST['pro_version']) : '';
1083
  $data['enterprise_version'] = isset($_POST['enterprise_version']) ? intval($_POST['enterprise_version']) : '';
 
1084
  $data['new_window'] = isset($_POST['new_window']) ? intval($_POST['new_window']) : '';
1085
  $data['show_in_primary_menu'] = isset($_POST['show_in_primary_menu']) ? intval($_POST['show_in_primary_menu']) : '';
1086
  $data['floating_language_selector'] = isset($_POST['floating_language_selector']) ? sanitize_text_field($_POST['floating_language_selector']) : 'no';
@@ -1100,11 +1081,40 @@ foreach($alt_flags as $flag)
1100
 
1101
  echo '<p style="color:red;">' . __('Changes Saved') . '</p>';
1102
  update_option('GTranslate', $data);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1103
  }
1104
 
1105
  public static function load_defaults(& $data) {
1106
  $data['pro_version'] = isset($data['pro_version']) ? $data['pro_version'] : '';
1107
  $data['enterprise_version'] = isset($data['enterprise_version']) ? $data['enterprise_version'] : '';
 
1108
  $data['new_window'] = isset($data['new_window']) ? $data['new_window'] : '';
1109
  $data['show_in_primary_menu'] = isset($data['show_in_primary_menu']) ? $data['show_in_primary_menu'] : '';
1110
  $data['floating_language_selector'] = isset($data['floating_language_selector']) ? $data['floating_language_selector'] : 'no';
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.3
7
  Author: Edvard Ananyan
8
  Author URI: https://gtranslate.io
9
  Text Domain: gtranslate
79
  }
80
  }
81
 
82
+ if($data['url_translation'] and ($data['pro_version'] or $data['enterprise_version'])) {
83
+ add_action('wp_head', 'gtranslate_url_translation_meta', 1);
84
+ function gtranslate_url_translation_meta() {
85
+ echo '<meta name="uri-translation" content="on" />';
86
+ }
87
+ }
88
+
89
  class GTranslate extends WP_Widget {
90
  public static function activate() {
91
  $data = array(
124
 
125
  wp_enqueue_style( 'gtranslate-style', plugins_url('gtranslate-style'.$data['flag_size'].'.css', __FILE__) );
126
  wp_enqueue_script('jquery');
127
+
128
+ if($data['pro_version'] or $data['enterprise_version'])
129
+ wp_add_inline_script('jquery-core', "var gt_request_uri = '".addslashes($_SERVER['REQUEST_URI'])."';", 'before');
130
  }
131
 
132
  public static function load_textdomain() {
261
  if(pro_version || enterprise_version) {
262
  translation_method = 'redirect';
263
  jQuery('#new_window_option').show();
264
+ jQuery('#url_translation_option').show();
265
  } else {
266
  jQuery('#new_window_option').hide();
267
+ jQuery('#url_translation_option').hide();
268
  }
269
 
270
  if(widget_look == 'dropdown' || widget_look == 'flags_dropdown' || widget_look == 'globe') {
309
  if(pro_version && enterprise_version)
310
  pro_version = false;
311
 
312
+ if(translation_method == 'on_fly' || translation_method == 'redirect' || translation_method == 'onfly') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  // Adding flags
314
  if(widget_look == 'flags' || widget_look == 'flags_dropdown' /* jQuery('#show_flags:checked').length */) {
315
  //console.log('adding flags');
548
  if(pro_version && translation_method == 'redirect' && new_window) {
549
  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;
550
  if(analytics)
551
+ 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.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')openTab(location.protocol+'//'+location.host+gt_request_uri);else openTab(location.protocol+'//'+location.host+'/'+lang+gt_request_uri);}"+new_line;
552
  else
553
+ 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.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')openTab(location.protocol+'//'+location.host+gt_request_uri);else openTab(location.protocol+'//'+location.host+'/'+lang+gt_request_uri);}"+new_line;
554
  } else if(pro_version && translation_method == 'redirect') {
555
  if(analytics)
556
+ 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.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.pathname+location.search);}var plang=location.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')location.href=location.protocol+'//'+location.host+gt_request_uri;else location.href=location.protocol+'//'+location.host+'/'+lang+gt_request_uri;}"+new_line;
557
  else
558
+ 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.pathname.split('/')[1];if(plang.length !=2 && plang != 'zh-CN' && plang != 'zh-TW')plang='"+default_language+"';if(lang == '"+default_language+"')location.href=location.protocol+'//'+location.host+gt_request_uri;else location.href=location.protocol+'//'+location.host+'/'+lang+gt_request_uri;}"+new_line;
559
  } else if(enterprise_version && translation_method == 'redirect' && new_window) {
560
  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;
561
  if(analytics)
562
+ 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='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+gt_request_uri);}"+new_line;
563
  else
564
+ 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='"+default_language+"';openTab(location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+gt_request_uri);}"+new_line;
565
  } else if(enterprise_version && translation_method == 'redirect') {
566
  if(analytics)
567
+ 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='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+gt_request_uri;}"+new_line;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  else
569
+ 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='"+default_language+"';location.href=location.protocol+'//'+(lang == '"+default_language+"' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '\.'), '')+gt_request_uri;}"+new_line;
 
570
  } else if(translation_method == 'onfly') {
571
  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){}}function doGTranslate(lang_pair){if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];var teCombo;var sel=document.getElementsByTagName('select');for(var i=0;i<sel.length;i++)if(sel[i].className=='goog-te-combo')teCombo=sel[i];if(document.getElementById('google_translate_element2')==null||document.getElementById('google_translate_element2').innerHTML.length==0||teCombo.length==0||teCombo.innerHTML.length==0){setTimeout(function(){doGTranslate(lang_pair)},500)}else{teCombo.value=lang;GTranslateFireEvent(teCombo,'change');GTranslateFireEvent(teCombo,'change')}}"+new_line;
572
  if(widget_look == 'dropdown_with_flags') {
598
 
599
  jQuery('#pro_version').attr('checked', '$pro_version'.length > 0);
600
  jQuery('#enterprise_version').attr('checked', '$enterprise_version'.length > 0);
601
+ jQuery('#url_translation').attr('checked', '$url_translation'.length > 0);
602
  jQuery('#new_window').attr('checked', '$new_window'.length > 0);
603
  jQuery('#show_in_primary_menu').attr('checked', '$show_in_primary_menu'.length > 0);
604
  jQuery('#floating_language_selector').val('$floating_language_selector');
611
  jQuery('#widget_look').val('$widget_look');
612
  jQuery('#flag_size').val('$flag_size');
613
 
614
+ if(jQuery('#pro_version:checked').length || jQuery('#enterprise_version:checked').length) {
615
  jQuery('#new_window_option').show();
616
+ jQuery('#url_translation_option').show();
617
+ }
618
 
619
  if('$widget_look' == 'dropdown' || '$widget_look' == 'flags_dropdown' || '$widget_look' == 'globe') {
620
  jQuery('#dropdown_languages_option').show();
840
  </tr>
841
  <tr>
842
  <td class="option_name">* <?php _e('Sub-directory URL structure', 'gtranslate'); ?>:<br><code><small>http://example.com/<b>ru</b>/</small></code></td>
843
+ <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">* <?php _e('paid plans only', 'gtranslate'); ?></a></td>
844
  </tr>
845
  <tr>
846
  <td class="option_name">* <?php _e('Sub-domain URL structure', 'gtranslate'); ?>:<br><code><small>http://<b>es</b>.example.com/</small></code></td>
847
+ <td><input id="enterprise_version" name="enterprise_version" value="1" type="checkbox" onclick="if(jQuery('#pro_version').is(':checked') && jQuery('#enterprise_version').is(':checked'))jQuery('#pro_version').prop('checked', false);RefreshDoWidgetCode()" onchange="RefreshDoWidgetCode()"/> <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank">* <?php _e('paid plans only', 'gtranslate'); ?></a></td>
848
+ </tr>
849
+ <tr id="url_translation_option" style="display:none;">
850
+ <td class="option_name"><?php _e('Enable URL Translation', 'gtranslate'); ?>:</td>
851
+ <td><input id="url_translation" name="url_translation" value="1" type="checkbox"/></td>
852
  </tr>
853
  <tr id="new_window_option" style="display:none;">
854
  <td class="option_name"><?php _e('Open in new window', 'gtranslate'); ?>:</td>
969
  </div>
970
  </div>
971
 
972
+ <div id="poststuff">
973
+ <div class="postbox">
974
+ <h3 id="settings"><?php _e('Paid features', 'gtranslate'); ?></h3>
975
+ <div class="inside">
976
+ <ul style="list-style-type:square;padding-left:20px;">
977
+ <li style="margin:0;"><?php _e('Enable search engine indexing', 'gtranslate'); ?></li>
978
+ <li style="margin:0;"><?php _e('Search engine friendly (SEF) URLs', 'gtranslate'); ?></li>
979
+ <li style="margin:0;"><?php _e('Increase traffic and AdSense revenue', 'gtranslate'); ?></li>
980
+ <li style="margin:0;"><?php _e('Meta data translation', 'gtranslate'); ?></li>
981
+ <li style="margin:0;"><?php _e('Edit translations manually', 'gtranslate'); ?></li>
982
+ <li style="margin:0;"><?php _e('URL translation', 'gtranslate'); ?></li>
983
+ <li style="margin:0;"><?php _e('Language hosting', 'gtranslate'); ?></li>
984
+ <li style="margin:0;"><?php _e('Seamless updates', 'gtranslate'); ?></li>
985
+ <li style="margin:0;"><?php _e('SSL support', 'gtranslate'); ?></li>
986
+ </ul>
987
+
988
+ <a href="https://gtranslate.io/?xyz=998#pricing" target="_blank"><?php _e('15 day free trial', 'gtranslate'); ?></a> | <a href="https://gtranslate.io/?xyz=998#faq" target="_blank"><?php _e('FAQ', 'gtranslate'); ?></a>
989
+ </div>
990
+ </div>
991
+ </div>
992
+
993
  <div id="poststuff">
994
  <div class="postbox">
995
  <h3 id="settings"><?php _e('Do you like GTranslate?', 'gtranslate'); ?></h3>
996
  <div class="inside">
997
+ <p><?php _e('Please write a review on', 'gtranslate'); ?> <a href="https://wordpress.org/support/plugin/gtranslate/reviews/?filter=5">WordPress.org</a>.</p>
998
 
999
  <div id="fb-root"></div>
1000
  <script>(function(d, s, id) {
1001
  var js, fjs = d.getElementsByTagName(s)[0];
1002
  if (d.getElementById(id)) return;
1003
  js = d.createElement(s); js.id = id;
1004
+ js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.8&appId=231165476898475";
1005
  fjs.parentNode.insertBefore(js, fjs);
1006
  }(document, 'script', 'facebook-jssdk'));</script>
1007
 
1008
+ <div class="fb-page" data-href="https://www.facebook.com/gtranslate" data-small-header="true" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="false"><blockquote cite="https://www.facebook.com/gtranslate" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/gtranslate">GTranslate</a></blockquote></div>
 
1009
  </div>
1010
  </div>
1011
  </div>
1012
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1013
  <div id="poststuff">
1014
  <div class="postbox">
1015
  <h3 id="settings"><?php _e('GTranslate Tour Video', 'gtranslate'); ?></h3>
1061
 
1062
  $data['pro_version'] = isset($_POST['pro_version']) ? intval($_POST['pro_version']) : '';
1063
  $data['enterprise_version'] = isset($_POST['enterprise_version']) ? intval($_POST['enterprise_version']) : '';
1064
+ $data['url_translation'] = isset($_POST['url_translation']) ? intval($_POST['url_translation']) : '';
1065
  $data['new_window'] = isset($_POST['new_window']) ? intval($_POST['new_window']) : '';
1066
  $data['show_in_primary_menu'] = isset($_POST['show_in_primary_menu']) ? intval($_POST['show_in_primary_menu']) : '';
1067
  $data['floating_language_selector'] = isset($_POST['floating_language_selector']) ? sanitize_text_field($_POST['floating_language_selector']) : 'no';
1081
 
1082
  echo '<p style="color:red;">' . __('Changes Saved') . '</p>';
1083
  update_option('GTranslate', $data);
1084
+
1085
+ if($data['pro_version']) { // check if rewrite rules are in place
1086
+ $htaccess_file = get_home_path() . '.htaccess';
1087
+ if(is_writeable($htaccess_file)) {
1088
+ $htaccess = file_get_contents($htaccess_file);
1089
+ if(strpos($htaccess, 'gtranslate.php') === false) { // no config rules
1090
+ $rewrite_rules = file_get_contents(dirname(__FILE__) . '/url_addon/rewrite.txt');
1091
+ $rewrite_rules = str_replace('GTRANSLATE_PLUGIN_PATH', plugins_url() . '/gtranslate', $rewrite_rules);
1092
+
1093
+ $htaccess = $rewrite_rules . "\r\n\r\n" . $htaccess;
1094
+ if(!empty($htaccess)) { // going to update .htaccess
1095
+ file_put_contents($htaccess_file, $htaccess);
1096
+ echo '<p style="color:red;">' . __('.htaccess file updated') . '</p>';
1097
+ }
1098
+ }
1099
+ }
1100
+
1101
+ // update main_lang in config.php
1102
+ $config_file = dirname(__FILE__) . '/url_addon/config.php';
1103
+ if(is_writable($config_file)) {
1104
+ $config = file_get_contents($config_file);
1105
+ $config = preg_replace('/\$main_lang = \'[a-z-]{2,5}\'/i', '$main_lang = \''.$data['default_language'].'\'', $config);
1106
+ file_put_contents($config_file, $config);
1107
+ }
1108
+
1109
+ } else { // todo: remove rewrite rules
1110
+ // do nothing
1111
+ }
1112
  }
1113
 
1114
  public static function load_defaults(& $data) {
1115
  $data['pro_version'] = isset($data['pro_version']) ? $data['pro_version'] : '';
1116
  $data['enterprise_version'] = isset($data['enterprise_version']) ? $data['enterprise_version'] : '';
1117
+ $data['url_translation'] = isset($data['url_translation']) ? $data['url_translation'] : '';
1118
  $data['new_window'] = isset($data['new_window']) ? $data['new_window'] : '';
1119
  $data['show_in_primary_menu'] = isset($data['show_in_primary_menu']) ? $data['show_in_primary_menu'] : '';
1120
  $data['floating_language_selector'] = isset($data['floating_language_selector']) ? $data['floating_language_selector'] : 'no';
readme.txt CHANGED
@@ -4,7 +4,7 @@ Author: Edvard Ananyan
4
  Tags: translation proxy, localization, translate, translation, localization, google translate, language, multilingual, multilanguage, bilingual, tradurre, traducir, traduire, traduzione, ubersetzung, mehrsprachig, oversette, oversatta, vertaling, vertaler, meertalig, polylang, qtranslate, transposh
5
  Requires at least: 2.8
6
  Tested up to: 4.7
7
- Stable tag: 2.8.2
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
@@ -31,7 +31,8 @@ Please check our [FAQ](https://gtranslate.io/?xyz=998#faq) to get quick answers.
31
  * Google Analytics integration
32
  * Translates the site on the fly
33
  * Google language translator widget
34
- * Available styles Dropdown/Flags/Flags with dropdown/Nice dropdown with flags
 
35
  * Valid XHTML
36
  * Alternative for WPML, qtranslate, transposh, loco translate and polylang
37
  * (paid) You can manually correct translations
@@ -409,6 +410,12 @@ You need to go to the language you want to edit, for instance, French: http://do
409
 
410
  == Changelog ==
411
 
 
 
 
 
 
 
412
  = 2.8.2 =
413
  * Floating language selector option added: Top left, Top right, Bottom left, Bottom right
414
 
4
  Tags: translation proxy, localization, translate, translation, localization, google translate, language, multilingual, multilanguage, bilingual, tradurre, traducir, traduire, traduzione, ubersetzung, mehrsprachig, oversette, oversatta, vertaling, vertaler, meertalig, polylang, qtranslate, transposh
5
  Requires at least: 2.8
6
  Tested up to: 4.7
7
+ Stable tag: 2.8.3
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
31
  * Google Analytics integration
32
  * Translates the site on the fly
33
  * Google language translator widget
34
+ * Available styles Dropdown/Flags/Flags with dropdown/Nice dropdown with flags/Globe
35
+ * Floating language selector
36
  * Valid XHTML
37
  * Alternative for WPML, qtranslate, transposh, loco translate and polylang
38
  * (paid) You can manually correct translations
410
 
411
  == Changelog ==
412
 
413
+ = 2.8.3 =
414
+ * Added URL add-on to easily enable sub-directory URL structure (paid)
415
+ * New option to easily enable URL Translation
416
+ * Disallow both sub-domain and sub-directory URL structure selection at the same time
417
+ * Fix for language change issue when URL Translation is on
418
+
419
  = 2.8.2 =
420
  * Floating language selector option added: Top left, Top right, Bottom left, Bottom right
421
 
url_addon/config.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Specify the original language code of your website
3
+ $main_lang = 'en';
4
+
5
+ /*
6
+ List of available language codes:
7
+
8
+ en -> English
9
+ ar -> Arabic
10
+ bg -> Bulgarian
11
+ zh-CN -> Chinese (Simplified)
12
+ zh-TW -> Chinese (Traditional)
13
+ hr -> Croatian
14
+ cs -> Czech
15
+ da -> Danish
16
+ nl -> Dutch
17
+ fi -> Finnish
18
+ fr -> French
19
+ de -> German
20
+ el -> Greek
21
+ hi -> Hindi
22
+ it -> Italian
23
+ ja -> Japanese
24
+ ko -> Korean
25
+ no -> Norwegian
26
+ pl -> Polish
27
+ pt -> Portuguese
28
+ ro -> Romanian
29
+ ru -> Russian
30
+ es -> Spanish
31
+ sv -> Swedish
32
+ ca -> Catalan
33
+ tl -> Filipino
34
+ iw -> Hebrew
35
+ id -> Indonesian
36
+ lv -> Latvian
37
+ lt -> Lithuanian
38
+ sr -> Serbian
39
+ sk -> Slovak
40
+ sl -> Slovenian
41
+ uk -> Ukrainian
42
+ vi -> Vietnamese
43
+ sq -> Albanian
44
+ et -> Estonian
45
+ gl -> Galician
46
+ hu -> Hungarian
47
+ mt -> Maltese
48
+ th -> Thai
49
+ tr -> Turkish
50
+ fa -> Persian
51
+ af -> Afrikaans
52
+ ms -> Malay
53
+ sw -> Swahili
54
+ ga -> Irish
55
+ cy -> Welsh
56
+ be -> Belarusian
57
+ is -> Icelandic
58
+ mk -> Macedonian
59
+ yi -> Yiddish
60
+ hy -> Armenian
61
+ az -> Azerbaijani
62
+ eu -> Basque
63
+ ka -> Georgian
64
+ ht -> Haitian Creole
65
+ ur -> Urdu
66
+ bn -> Bengali
67
+ bs -> Bosnian
68
+ ceb -> Cebuano
69
+ eo -> Esperanto
70
+ gu -> Gujarati
71
+ ha -> Hausa
72
+ hmn -> Hmong
73
+ ig -> Igbo
74
+ jw -> Javanese
75
+ kn -> Kannada
76
+ km -> Khmer
77
+ lo -> Lao
78
+ la -> Latin
79
+ mi -> Maori
80
+ mr -> Marathi
81
+ mn -> Mongolian
82
+ ne -> Nepali
83
+ pa -> Punjabi
84
+ so -> Somali
85
+ ta -> Tamil
86
+ te -> Telugu
87
+ yo -> Yoruba
88
+ zu -> Zulu
89
+ my -> Myanmar (Burmese)
90
+ ny -> Chichewa
91
+ kk -> Kazakh
92
+ mg -> Malagasy
93
+ ml -> Malayalam
94
+ si -> Sinhala
95
+ st -> Sesotho
96
+ su -> Sudanese
97
+ tg -> Tajik
98
+ uz -> Uzbek
99
+ am -> Amharic
100
+ co -> Corsican
101
+ haw -> Hawaiian
102
+ ku -> Kurdish (Kurmanji)
103
+ ky -> Kyrgyz
104
+ lb -> Luxembourgish
105
+ ps -> Pashto
106
+ sm -> Samoan
107
+ gd -> Scottish Gaelic
108
+ sn -> Shona
109
+ sd -> Sindhi
110
+ fy -> Frisian
111
+ xh -> Xhosa
112
+ */
113
+
114
+ $servers = array('van', 'kars', 'sis', 'dvin');
115
+ $debug = false;
url_addon/debug.txt ADDED
File without changes
url_addon/gtranslate.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include 'config.php';
3
+
4
+ if(!isset($_GET['glang']) or !isset($_GET['gurl']))
5
+ exit;
6
+
7
+ $glang = $_GET['glang'];
8
+
9
+ shuffle($servers);
10
+ $server = $servers[1];
11
+
12
+ $page_url = '/'.$_GET['gurl'];
13
+
14
+ $page_url_segments = explode('/', $page_url);
15
+ foreach($page_url_segments as $i => $segment) {
16
+ $page_url_segments[$i] = rawurlencode($segment);
17
+ }
18
+ $page_url = implode('/', $page_url_segments);
19
+
20
+ $get_params = $_GET;
21
+ if(isset($get_params['glang']))
22
+ unset($get_params['glang']);
23
+ if(isset($get_params['gurl']))
24
+ unset($get_params['gurl']);
25
+
26
+ if(count($get_params)) {
27
+ $page_url .= '?' . http_build_query($get_params);
28
+ }
29
+
30
+ if($glang == $main_lang) {
31
+ header('Location: ' . $page_url, true, 301);
32
+ exit;
33
+ }
34
+
35
+ $page_url = $server.'.tdn.gtranslate.net' . $page_url;
36
+
37
+ $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';
38
+ $page_url = $protocol . '://' . $page_url;
39
+
40
+ 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')))
41
+ exit;
42
+
43
+ if(!function_exists("getallheaders")) {
44
+ //Adapted from http://www.php.net/manual/en/function.getallheaders.php#99814
45
+ function getallheaders() {
46
+ $result = array();
47
+ foreach($_SERVER as $key => $value) {
48
+ if (substr($key, 0, 5) == "HTTP_") {
49
+ $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
50
+ $result[$key] = $value;
51
+ } else if ($key == "CONTENT_TYPE") {
52
+ $result["Content-Type"] = $value;
53
+ }
54
+ }
55
+ return $result;
56
+ }
57
+ }
58
+
59
+ $request_headers = getallheaders();
60
+
61
+ if(isset($request_headers['X-GT-Lang'])) {
62
+ echo 'Please remove DNS cname records for GTranslate!';
63
+ exit;
64
+ }
65
+
66
+ $host = $glang . '.' . preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']);
67
+ $request_headers['Host'] = $host;
68
+ $request_headers['Accept-Encoding'] = '';
69
+ if(isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']))
70
+ $request_headers['Authorization'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
71
+ //print_r($request_headers);
72
+ //exit;
73
+
74
+ if(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data;') !== false)
75
+ $request_headers['Content-Type'] = 'multipart/form-data'; // remove boundary
76
+
77
+ $headers = array();
78
+ foreach($request_headers as $key => $val) {
79
+ $headers[] = $key . ': ' . $val;
80
+ }
81
+
82
+ //print_r($headers);
83
+ //exit;
84
+
85
+ // proxy request
86
+ $ch = curl_init();
87
+ curl_setopt($ch, CURLOPT_URL, $page_url);
88
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
89
+ curl_setopt($ch, CURLOPT_HEADER, true);
90
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
91
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
92
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
93
+
94
+ switch($_SERVER['REQUEST_METHOD']) {
95
+ case 'POST': {
96
+ curl_setopt($ch, CURLOPT_POST, true);
97
+ if(isset($request_headers['Content-Type']) and strpos($request_headers['Content-Type'], 'multipart/form-data') !== false) {
98
+ http_build_query_for_curl($_POST, $new_post);
99
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $new_post); // todo: think about $_FILES: http://php.net/manual/en/class.curlfile.php
100
+ } else {
101
+ curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));
102
+ }
103
+ }; break;
104
+
105
+ case 'PUT': {
106
+ curl_setopt($ch, CURLOPT_PUT, true);
107
+ curl_setopt($ch, CURLOPT_INFILE, fopen('php://input', 'r'));
108
+ }; break;
109
+ }
110
+
111
+ // Debug
112
+ if($debug or isset($_GET['enable_debug'])) {
113
+ $fh = fopen('debug.txt', 'a');
114
+ curl_setopt($ch, CURLOPT_VERBOSE, true);
115
+ curl_setopt($ch, CURLOPT_STDERR, $fh);
116
+ }
117
+
118
+ $response = curl_exec($ch);
119
+ $response_info = curl_getinfo($ch);
120
+ curl_close($ch);
121
+
122
+ //print_r($response_info);
123
+
124
+ $header_size = $response_info['header_size'];
125
+ $header = substr($response, 0, $header_size);
126
+ $html = substr($response, $header_size);
127
+
128
+ $response_headers = explode(PHP_EOL, $header);
129
+ //print_r($response_headers);
130
+ $headers_sent = '';
131
+ foreach($response_headers as $header) {
132
+ if(!empty($header) and !preg_match('/Content\-Length|Transfer\-Encoding|Content\-Encoding|Link/', $header)) {
133
+
134
+ if(preg_match('/^Location:/', $header))
135
+ $header = str_ireplace($host, $_SERVER['HTTP_HOST'] . '/' . $glang, $header);
136
+
137
+ $headers_sent .= $header;
138
+ header($header, false);
139
+ }
140
+ }
141
+ //echo $headers_sent;
142
+
143
+ // TODO: modify URLs
144
+ $html = str_ireplace($host, $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
145
+ $html = str_ireplace('href="/', 'href="/' . $glang . '/', $html);
146
+ $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
147
+ $html = str_ireplace('href="/' . $glang . '//', 'href="//', $html);
148
+ $html = str_ireplace('action="/', 'action="/' . $glang . '/', $html);
149
+ $html = str_ireplace('action="/' . $glang . '//', 'action="//', $html);
150
+ $html = str_ireplace('action="//' . $_SERVER['HTTP_HOST'], 'action="//' . $_SERVER['HTTP_HOST'] . '/' . $glang, $html);
151
+
152
+ if(isset($_GET['language_edit'])) {
153
+ $html = str_replace('/tdn-static/', $protocol . '://tdns.gtranslate.net/tdn-static/', $html);
154
+ $html = str_replace('/tdn-bin/', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' . $glang . '/tdn-bin/', $html);
155
+ }
156
+
157
+ echo $html;
158
+
159
+ function http_build_query_for_curl($arrays, &$new = array(), $prefix = null) { // flatten multidimentional array for post
160
+ if(is_object($arrays)) {
161
+ $arrays = get_object_vars($arrays);
162
+ }
163
+
164
+ foreach($arrays AS $key => $value) {
165
+ $k = isset($prefix) ? $prefix . '[' . $key . ']' : $key;
166
+ if(is_array($value) or is_object($value)) {
167
+ http_build_query_for_curl($value, $new, $k);
168
+ } else {
169
+ $new[$k] = $value;
170
+ }
171
+ }
172
+ }
url_addon/rewrite.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ ### BEGIN GTranslate config ###
2
+ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
3
+ RewriteRule ^(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)/(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)/(.*)$ /$1/$3 [R=301,L]
4
+ RewriteCond %{REQUEST_FILENAME} !-f
5
+ RewriteRule ^(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)/(.*)$ GTRANSLATE_PLUGIN_PATH/url_addon/gtranslate.php?glang=$1&gurl=$2 [L,QSA]
6
+ RewriteRule ^(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)$ /$1/ [R=301,L]
7
+ ### END GTranslate config ###