TranslatePress – Translate Multilingual sites - Version 1.3.6

Version Description

  • Refactored the get_url_for_language() function which should fix a lot of problems with links
  • Speed improvements
  • Fixed translation block icon when creating a new block
  • Fixed issues with trp tags leftovers in html
  • Fixed issues with gettext strings that weren't detected correctly
  • Add support for relative url's
  • Added warning in settings about controlling costs of Google API
  • Changed API key field description. Added feature to show/hide API key field based on Google Translate Active Yes/No
  • Fixed Translated-dom-changes string not translated through trp-ajax.
  • Fixed 400 errors in google translate API
Download this release

Release Info

Developer madalin.ungureanu
Plugin Icon 128x128 TranslatePress – Translate Multilingual sites
Version 1.3.6
Comparing to
See all releases

Code changes from version 1.3.5 to 1.3.6

assets/js/trp-back-end-script.js CHANGED
@@ -1,154 +1,194 @@
1
- /**
2
- * Script used in Settings Page to change the language selector and slugs.
3
  */
4
 
5
- function TRP_Settings_Language_Selector() {
6
- var _this = this;
7
- var duplicate_url_error_message;
8
- var iso_codes;
9
 
10
  /**
11
- * Initialize select to become select2
12
  */
13
- this.initialize_select2 = function () {
14
- jQuery('.trp-select2').each(function () {
15
- var select_element = jQuery(this);
16
- select_element.select2(/*arguments*/);
17
- });
18
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- this.get_default_url_slug = function( new_language ){
21
- var return_slug = iso_codes[new_language];
22
- var url_slugs = _this.get_existing_url_slugs();
23
- url_slugs.push( return_slug );
24
- if ( has_duplicates ( url_slugs ) ){
25
- return_slug = new_language;
26
- }
27
- return return_slug.toLowerCase();
28
- };
29
 
30
- this.add_language = function(){
31
- var selected_language = jQuery( '#trp-select-language' );
32
- var new_language = selected_language.val();
33
- if ( new_language == "" ){
34
- return;
35
- }
36
 
37
- if (jQuery( "#trp-languages-table .trp-language" ).length >= 2 ){
38
- jQuery(".trp-upsell-multiple-languages").show('fast');
39
- return;
40
- }
41
 
42
- selected_language.val( '' ).trigger( 'change' );
 
 
 
 
 
 
43
 
44
- var new_option = jQuery( '.trp-language' ).first().clone();
45
- new_option = jQuery( new_option );
46
 
47
- new_option.find( '.trp-hidden-default-language' ).remove();
48
- new_option.find( '.select2-container' ).remove();
49
- var select = new_option.find( 'select.trp-translation-language' );
50
- select.removeAttr( 'disabled' );
51
- select.find( 'option' ).each(function(index, el){
52
- el.text = el.text.replace('Default: ', '');
53
- })
54
 
55
- select.val( new_language );
56
- select.select2();
 
57
 
58
- var checkbox = new_option.find( 'input.trp-translation-published' );
59
- checkbox.removeAttr( 'disabled' );
60
- checkbox.val( new_language );
61
 
62
- var url_slug = new_option.find( 'input.trp-language-slug' );
63
- url_slug.val( _this.get_default_url_slug( new_language ) );
64
- url_slug.attr('name', 'trp_settings[url-slugs][' + new_language + ']' );
65
 
66
- var remove = new_option.find( '.trp-remove-language' ).toggle();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- new_option = jQuery( '#trp-sortable-languages' ).append( new_option );
69
- new_option.find( '.trp-remove-language' ).last().click( _this.remove_language );
70
- };
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
- this.remove_language = function( element ){
73
- var message = jQuery( element.target ).attr( 'data-confirm-message' );
74
- var confirmed = confirm( message );
75
- if ( confirmed ) {
76
- jQuery ( element.target ).parent().parent().remove();
77
- }
78
- };
79
 
80
- this.update_default_language = function(){
81
- var selected_language = jQuery( '#trp-default-language').val();
82
- jQuery( '.trp-hidden-default-language' ).val( selected_language );
83
- jQuery( '.trp-translation-published[disabled]' ).val( selected_language );
84
- jQuery( '.trp-translation-language[disabled]').val( selected_language ).trigger( 'change' );
85
- };
86
 
87
- function has_duplicates(array) {
88
- var valuesSoFar = Object.create(null);
89
- for (var i = 0; i < array.length; ++i) {
90
- var value = array[i];
91
- if (value in valuesSoFar) {
92
- return true;
93
  }
94
- valuesSoFar[value] = true;
95
- }
96
- return false;
97
- }
98
 
99
- this.get_existing_url_slugs = function(){
100
- var url_slugs = [];
101
- jQuery( '.trp-language-slug' ).each( function (){
102
- url_slugs.push( jQuery( this ).val().toLowerCase() );
103
- } );
104
- return url_slugs;
105
- };
106
 
107
- this.check_unique_url_slugs = function (event){
108
- var url_slugs = _this.get_existing_url_slugs();
109
- if ( has_duplicates(url_slugs)){
110
- alert( duplicate_url_error_message );
111
- event.preventDefault();
112
- }
113
- };
114
 
115
- this.update_url_slug_and_status = function ( event ) {
116
- var select = jQuery( event.target );
117
- var new_language = select.val();
118
- var row = jQuery( select ).parents( '.trp-language' ) ;
119
- row.find( '.trp-language-slug' ).attr( 'name', 'trp_settings[url-slugs][' + new_language + ']').val( '' ).val( _this.get_default_url_slug( new_language ) );
120
- row.find( '.trp-translation-published' ).val( new_language );
121
- };
122
 
123
- this.initialize = function () {
124
- this.initialize_select2();
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
- if ( !jQuery( '.trp-language-selector-limited' ).length ){
127
- return;
 
 
128
  }
129
 
130
- duplicate_url_error_message = trp_url_slugs_info['error_message_duplicate_slugs'];
131
- iso_codes = trp_url_slugs_info['iso_codes'];
 
 
 
 
 
132
 
133
- jQuery( '#trp-sortable-languages' ).sortable({ handle: '.trp-sortable-handle' });
134
- jQuery( '#trp-add-language' ).click( _this.add_language );
135
- jQuery( '.trp-remove-language' ).click( _this.remove_language );
136
- jQuery( '#trp-default-language' ).on( 'change', _this.update_default_language );
137
- jQuery( "form[action='options.php']").on ( 'submit', _this.check_unique_url_slugs );
138
- jQuery( '#trp-languages-table' ).on( 'change', '.trp-translation-language', _this.update_url_slug_and_status );
139
  };
140
 
141
- this.initialize();
142
- }
143
-
144
- var trpSettingsLanguages;
145
-
146
- // Initialize the Translate Press Settings after jQuery is ready
147
- jQuery( function() {
148
- trpSettingsLanguages = new TRP_Settings_Language_Selector();
149
 
150
  jQuery('#trp-default-language').on("select2:selecting", function(e) {
151
  jQuery("#trp-options .warning").show('fast');
152
  });
 
 
 
 
153
  });
154
 
1
+ /*
2
+ * Script used in Settings Page
3
  */
4
 
5
+ jQuery( function() {
 
 
 
6
 
7
  /**
8
+ * Change the language selector and slugs
9
  */
10
+ function TRP_Settings_Language_Selector() {
11
+ var _this = this;
12
+ var duplicate_url_error_message;
13
+ var iso_codes;
14
+
15
+ /**
16
+ * Initialize select to become select2
17
+ */
18
+ this.initialize_select2 = function () {
19
+ jQuery('.trp-select2').each(function () {
20
+ var select_element = jQuery(this);
21
+ select_element.select2(/*arguments*/);
22
+ });
23
+ };
24
+
25
+ this.get_default_url_slug = function( new_language ){
26
+ var return_slug = iso_codes[new_language];
27
+ var url_slugs = _this.get_existing_url_slugs();
28
+ url_slugs.push( return_slug );
29
+ if ( has_duplicates ( url_slugs ) ){
30
+ return_slug = new_language;
31
+ }
32
+ return return_slug.toLowerCase();
33
+ };
34
+
35
+ this.add_language = function(){
36
+ var selected_language = jQuery( '#trp-select-language' );
37
+ var new_language = selected_language.val();
38
+ if ( new_language == "" ){
39
+ return;
40
+ }
41
 
42
+ if (jQuery( "#trp-languages-table .trp-language" ).length >= 2 ){
43
+ jQuery(".trp-upsell-multiple-languages").show('fast');
44
+ return;
45
+ }
 
 
 
 
 
46
 
47
+ selected_language.val( '' ).trigger( 'change' );
 
 
 
 
 
48
 
49
+ var new_option = jQuery( '.trp-language' ).first().clone();
50
+ new_option = jQuery( new_option );
 
 
51
 
52
+ new_option.find( '.trp-hidden-default-language' ).remove();
53
+ new_option.find( '.select2-container' ).remove();
54
+ var select = new_option.find( 'select.trp-translation-language' );
55
+ select.removeAttr( 'disabled' );
56
+ select.find( 'option' ).each(function(index, el){
57
+ el.text = el.text.replace('Default: ', '');
58
+ })
59
 
60
+ select.val( new_language );
61
+ select.select2();
62
 
63
+ var checkbox = new_option.find( 'input.trp-translation-published' );
64
+ checkbox.removeAttr( 'disabled' );
65
+ checkbox.val( new_language );
 
 
 
 
66
 
67
+ var url_slug = new_option.find( 'input.trp-language-slug' );
68
+ url_slug.val( _this.get_default_url_slug( new_language ) );
69
+ url_slug.attr('name', 'trp_settings[url-slugs][' + new_language + ']' );
70
 
71
+ var remove = new_option.find( '.trp-remove-language' ).toggle();
 
 
72
 
73
+ new_option = jQuery( '#trp-sortable-languages' ).append( new_option );
74
+ new_option.find( '.trp-remove-language' ).last().click( _this.remove_language );
75
+ };
76
 
77
+ this.remove_language = function( element ){
78
+ var message = jQuery( element.target ).attr( 'data-confirm-message' );
79
+ var confirmed = confirm( message );
80
+ if ( confirmed ) {
81
+ jQuery ( element.target ).parent().parent().remove();
82
+ }
83
+ };
84
+
85
+ this.update_default_language = function(){
86
+ var selected_language = jQuery( '#trp-default-language').val();
87
+ jQuery( '.trp-hidden-default-language' ).val( selected_language );
88
+ jQuery( '.trp-translation-published[disabled]' ).val( selected_language );
89
+ jQuery( '.trp-translation-language[disabled]').val( selected_language ).trigger( 'change' );
90
+ };
91
+
92
+ function has_duplicates(array) {
93
+ var valuesSoFar = Object.create(null);
94
+ for (var i = 0; i < array.length; ++i) {
95
+ var value = array[i];
96
+ if (value in valuesSoFar) {
97
+ return true;
98
+ }
99
+ valuesSoFar[value] = true;
100
+ }
101
+ return false;
102
+ }
103
 
104
+ this.get_existing_url_slugs = function(){
105
+ var url_slugs = [];
106
+ jQuery( '.trp-language-slug' ).each( function (){
107
+ url_slugs.push( jQuery( this ).val().toLowerCase() );
108
+ } );
109
+ return url_slugs;
110
+ };
111
+
112
+ this.check_unique_url_slugs = function (event){
113
+ var url_slugs = _this.get_existing_url_slugs();
114
+ if ( has_duplicates(url_slugs)){
115
+ alert( duplicate_url_error_message );
116
+ event.preventDefault();
117
+ }
118
+ };
119
 
120
+ this.update_url_slug_and_status = function ( event ) {
121
+ var select = jQuery( event.target );
122
+ var new_language = select.val();
123
+ var row = jQuery( select ).parents( '.trp-language' ) ;
124
+ row.find( '.trp-language-slug' ).attr( 'name', 'trp_settings[url-slugs][' + new_language + ']').val( '' ).val( _this.get_default_url_slug( new_language ) );
125
+ row.find( '.trp-translation-published' ).val( new_language );
126
+ };
127
 
128
+ this.initialize = function () {
129
+ this.initialize_select2();
 
 
 
 
130
 
131
+ if ( !jQuery( '.trp-language-selector-limited' ).length ){
132
+ return;
 
 
 
 
133
  }
 
 
 
 
134
 
135
+ duplicate_url_error_message = trp_url_slugs_info['error_message_duplicate_slugs'];
136
+ iso_codes = trp_url_slugs_info['iso_codes'];
 
 
 
 
 
137
 
138
+ jQuery( '#trp-sortable-languages' ).sortable({ handle: '.trp-sortable-handle' });
139
+ jQuery( '#trp-add-language' ).click( _this.add_language );
140
+ jQuery( '.trp-remove-language' ).click( _this.remove_language );
141
+ jQuery( '#trp-default-language' ).on( 'change', _this.update_default_language );
142
+ jQuery( "form[action='options.php']").on ( 'submit', _this.check_unique_url_slugs );
143
+ jQuery( '#trp-languages-table' ).on( 'change', '.trp-translation-language', _this.update_url_slug_and_status );
144
+ };
145
 
146
+ this.initialize();
147
+ }
 
 
 
 
 
148
 
149
+ /*
150
+ * Show Google Translate API Key only when Google Translate is active
151
+ */
152
+ function TRP_Field_Toggler (){
153
+ var _$setting_toggled;
154
+ var _$trigger_field;
155
+ var _trigger_field_value_for_show;
156
+
157
+ function show_hide_based_on_value( value ) {
158
+ if ( value === _trigger_field_value_for_show ) {
159
+ _$setting_toggled.show();
160
+ } else {
161
+ _$setting_toggled.hide();
162
+ }
163
+ }
164
 
165
+ function add_event_on_change() {
166
+ _$trigger_field.on('change', function () {
167
+ show_hide_based_on_value( this.value );
168
+ });
169
  }
170
 
171
+ function init( trigger_select_id, setting_id, value_for_show ){
172
+ _trigger_field_value_for_show = value_for_show;
173
+ _$trigger_field = jQuery( trigger_select_id );
174
+ _$setting_toggled = jQuery( setting_id ).parents('tr');
175
+ show_hide_based_on_value( _$trigger_field.val() );
176
+ add_event_on_change();
177
+ }
178
 
179
+ return {
180
+ init: init
181
+ };
 
 
 
182
  };
183
 
184
+ var trpSettingsLanguages = new TRP_Settings_Language_Selector();
 
 
 
 
 
 
 
185
 
186
  jQuery('#trp-default-language').on("select2:selecting", function(e) {
187
  jQuery("#trp-options .warning").show('fast');
188
  });
189
+
190
+ var trpGoogleTranslate = TRP_Field_Toggler();
191
+ trpGoogleTranslate.init('#trp-g-translate', '#trp-g-translate-key', 'yes' );
192
+
193
  });
194
 
assets/js/trp-editor-script.js CHANGED
@@ -1014,6 +1014,7 @@ function TRP_String( language, array_index ){
1014
  }
1015
 
1016
  if ( _this.jquery_object && _this.block_type != 2 ) {
 
1017
  if ( trp_language == trp_on_screen_language ) {
1018
  var text_to_set = null;
1019
  if (new_settings.hasOwnProperty('translated') && new_settings.translated != _this.translated) {
@@ -1022,7 +1023,6 @@ function TRP_String( language, array_index ){
1022
  if (new_settings.hasOwnProperty('status') && new_settings.status == 0) {
1023
  text_to_set = _this.original;
1024
  }
1025
- _this.wrap_special_html_elements();
1026
  _this.set_text_in_iframe( text_to_set, _this.jquery_object );
1027
  }
1028
 
@@ -1038,19 +1038,23 @@ function TRP_String( language, array_index ){
1038
  * Wrap buttons and placeholders so that we can display the pencil button and also replace with translation.
1039
  */
1040
  this.wrap_special_html_elements = function(){
1041
- if( _this.jquery_object.is('button') ){
1042
- _this.jquery_object.unwrap('trp-highlight');
1043
- _this.jquery_object.wrap('<trp-highlight data-trp-button="true"></trp-highlight>');
1044
- _this.jquery_object = _this.jquery_object.parent();
1045
- }
1046
- else if ( _this.jquery_object.attr( 'type' ) == 'submit' || _this.jquery_object.attr( 'type' ) == 'button' ) {
1047
- _this.jquery_object.unwrap('trp-highlight');
1048
- _this.jquery_object.wrap('<trp-highlight data-trp-attr="value"></trp-highlight>');
1049
  _this.jquery_object = _this.jquery_object.parent();
 
1050
  }
1051
- else if ( ( _this.jquery_object.attr( 'type' ) == 'text' || _this.jquery_object.attr( 'type' ) == 'search' ) && ( typeof _this.jquery_object.attr( 'placeholder' ) != 'undefined' ) ) {
1052
- _this.jquery_object.unwrap('trp-highlight');
1053
- _this.jquery_object.wrap('<trp-highlight data-trp-attr="placeholder"></trp-highlight>');
 
 
 
 
 
 
 
 
 
1054
  _this.jquery_object = _this.jquery_object.parent();
1055
  }
1056
  };
@@ -1061,32 +1065,38 @@ function TRP_String( language, array_index ){
1061
  */
1062
  this.highlight = function (e){
1063
  e.stopPropagation();
1064
- var this_jquery_object;
1065
  var tb_parent = _this.jquery_object.parents( '.trp-create-translation-block' );
1066
  if ( tb_parent.length > 0 ){
1067
- this_jquery_object = tb_parent.first();
1068
- }else{
1069
- this_jquery_object = _this.jquery_object;
1070
  }
1071
 
1072
  trpEditor.remove_pencil_icon();
1073
-
1074
  if ( ! trpEditor.edit_translation_button ){
1075
- this_jquery_object.prepend( trp_action_button_html );
1076
- trpEditor.edit_translation_button = this_jquery_object.children('trp-span');
1077
  }else{
1078
- _this.wrap_special_html_elements();
1079
  trpEditor.maybe_overflow_fix(trpEditor.edit_translation_button);
1080
- this_jquery_object.prepend(trpEditor.edit_translation_button);
1081
  }
1082
  trpEditor.edit_translation_button.children( ).removeClass( 'trp-active-icon' );
1083
  var merge_or_split = trpEditor.decide_if_merge_or_split( _this );
 
 
 
 
1084
  if ( merge_or_split != 'none' ) {
1085
  trpEditor.edit_translation_button.children('trp-' + merge_or_split ).addClass( 'trp-active-icon' );
1086
  }
1087
 
1088
- trpEditor.make_sure_pencil_icon_is_inside_view( this_jquery_object[0] );
1089
 
 
 
 
 
1090
  trpEditor.edit_translation_button.off( 'click' );
1091
  trpEditor.edit_translation_button.on( 'click', function(e){
1092
  e.preventDefault();
@@ -1560,7 +1570,7 @@ jQuery(function(){
1560
  trpEditor.edit_translation_button.children( ).removeClass( 'trp-active-icon' );
1561
  trpEditor.maybe_overflow_fix(trpEditor.edit_translation_button);
1562
 
1563
- if ( jQuery(this).attr( 'type' ) == 'submit' || jQuery(this).attr( 'type' ) == 'button' || jQuery(this).attr('type') == 'search' ) {
1564
  if( jQuery(this).parent('trp-wrap').length == 0 )
1565
  jQuery(this).wrap('<trp-wrap class="trpgettext-wrap"></trp-wrap>');
1566
  jQuery(this).parent().prepend(trpEditor.edit_translation_button);
1014
  }
1015
 
1016
  if ( _this.jquery_object && _this.block_type != 2 ) {
1017
+ _this.wrap_special_html_elements();
1018
  if ( trp_language == trp_on_screen_language ) {
1019
  var text_to_set = null;
1020
  if (new_settings.hasOwnProperty('translated') && new_settings.translated != _this.translated) {
1023
  if (new_settings.hasOwnProperty('status') && new_settings.status == 0) {
1024
  text_to_set = _this.original;
1025
  }
 
1026
  _this.set_text_in_iframe( text_to_set, _this.jquery_object );
1027
  }
1028
 
1038
  * Wrap buttons and placeholders so that we can display the pencil button and also replace with translation.
1039
  */
1040
  this.wrap_special_html_elements = function(){
1041
+ if ( _this.jquery_object.parent().is('trp-highlight') ){
1042
+ // if the iframe lookup is triggered a second time, the same string will be recognized again as the image and jquery_object is set as an image, not the trp-highlight wrapping. Fix this by assigning it to parent if exists.
 
 
 
 
 
 
1043
  _this.jquery_object = _this.jquery_object.parent();
1044
+ return;
1045
  }
1046
+ var extra_attribute = false;
1047
+ if( _this.jquery_object.is('button') ) {
1048
+ extra_attribute = 'data-trp-button="true"';
1049
+ }else if ( ( _this.jquery_object.attr( 'type' ) == 'submit' || _this.jquery_object.attr( 'type' ) == 'button' ) ) {
1050
+ extra_attribute = 'data-trp-attr="value"';
1051
+ }else if ( ( _this.jquery_object.attr( 'type' ) == 'text' || _this.jquery_object.attr( 'type' ) == 'search' || _this.jquery_object.is( 'textarea' ) ) && ( typeof _this.jquery_object.attr( 'placeholder' ) != 'undefined' ) ) {
1052
+ extra_attribute = 'data-trp-attr="placeholder"';
1053
+ }else if ( _this.jquery_object.is( 'img' ) ){
1054
+ extra_attribute = 'data-trp-attr="alt"';
1055
+ }
1056
+ if ( extra_attribute !== false ) {
1057
+ _this.jquery_object.wrap('<trp-highlight ' + extra_attribute + '></trp-highlight>');
1058
  _this.jquery_object = _this.jquery_object.parent();
1059
  }
1060
  };
1065
  */
1066
  this.highlight = function (e){
1067
  e.stopPropagation();
1068
+ var old_jquery_object = null;
1069
  var tb_parent = _this.jquery_object.parents( '.trp-create-translation-block' );
1070
  if ( tb_parent.length > 0 ){
1071
+ // we are creating a new block
1072
+ old_jquery_object = _this.jquery_object;
1073
+ _this.jquery_object = tb_parent.first();
1074
  }
1075
 
1076
  trpEditor.remove_pencil_icon();
 
1077
  if ( ! trpEditor.edit_translation_button ){
1078
+ _this.jquery_object.prepend( trp_action_button_html );
1079
+ trpEditor.edit_translation_button = _this.jquery_object.children('trp-span');
1080
  }else{
 
1081
  trpEditor.maybe_overflow_fix(trpEditor.edit_translation_button);
1082
+ _this.jquery_object.prepend(trpEditor.edit_translation_button);
1083
  }
1084
  trpEditor.edit_translation_button.children( ).removeClass( 'trp-active-icon' );
1085
  var merge_or_split = trpEditor.decide_if_merge_or_split( _this );
1086
+ if ( old_jquery_object ){
1087
+ // we are creating a new block
1088
+ merge_or_split = 'merge';
1089
+ }
1090
  if ( merge_or_split != 'none' ) {
1091
  trpEditor.edit_translation_button.children('trp-' + merge_or_split ).addClass( 'trp-active-icon' );
1092
  }
1093
 
1094
+ trpEditor.make_sure_pencil_icon_is_inside_view( _this.jquery_object[0] );
1095
 
1096
+ if ( old_jquery_object ){
1097
+ // we are creating a new block
1098
+ _this.jquery_object = old_jquery_object;
1099
+ }
1100
  trpEditor.edit_translation_button.off( 'click' );
1101
  trpEditor.edit_translation_button.on( 'click', function(e){
1102
  e.preventDefault();
1570
  trpEditor.edit_translation_button.children( ).removeClass( 'trp-active-icon' );
1571
  trpEditor.maybe_overflow_fix(trpEditor.edit_translation_button);
1572
 
1573
+ if ( jQuery(this).attr( 'type' ) == 'submit' || jQuery(this).attr( 'type' ) == 'button' || jQuery(this).attr('type') == 'search' || jQuery(this).attr('placeholder') || jQuery(this).attr('alt')) {
1574
  if( jQuery(this).parent('trp-wrap').length == 0 )
1575
  jQuery(this).wrap('<trp-wrap class="trpgettext-wrap"></trp-wrap>');
1576
  jQuery(this).parent().prepend(trpEditor.edit_translation_button);
class-translate-press.php CHANGED
@@ -40,7 +40,7 @@ class TRP_Translate_Press{
40
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
41
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
42
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
43
- define( 'TRP_PLUGIN_VERSION', '1.3.5' );
44
 
45
  $this->load_dependencies();
46
  $this->initialize_components();
@@ -73,6 +73,7 @@ class TRP_Translate_Press{
73
  require_once TRP_PLUGIN_DIR . 'includes/class-machine-translator.php';
74
  require_once TRP_PLUGIN_DIR . 'includes/class-query.php';
75
  require_once TRP_PLUGIN_DIR . 'includes/class-url-converter.php';
 
76
  require_once TRP_PLUGIN_DIR . 'includes/class-plugin-notices.php';
77
  require_once TRP_PLUGIN_DIR . 'includes/functions.php';
78
  require_once TRP_PLUGIN_DIR . 'assets/lib/simplehtmldom/simple_html_dom.php';
@@ -132,7 +133,6 @@ class TRP_Translate_Press{
132
  */
133
  protected function define_frontend_hooks(){
134
  $this->loader->add_action( 'init', $this->translation_render, 'start_output_buffer', 0 );
135
- $this->loader->add_action( 'admin_init', $this->translation_render, 'start_output_buffer' );
136
  $this->loader->add_action( 'wp_enqueue_scripts', $this->translation_render, 'enqueue_dynamic_translation', 1 );
137
  $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_preview_on_url_redirect', 99, 2 );
138
  $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_language_on_form_url_redirect', 99, 2 );
40
  define( 'TRP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
41
  define( 'TRP_PLUGIN_BASE', plugin_basename( __DIR__ . '/index.php' ) );
42
  define( 'TRP_PLUGIN_SLUG', 'translatepress-multilingual' );
43
+ define( 'TRP_PLUGIN_VERSION', '1.3.6' );
44
 
45
  $this->load_dependencies();
46
  $this->initialize_components();
73
  require_once TRP_PLUGIN_DIR . 'includes/class-machine-translator.php';
74
  require_once TRP_PLUGIN_DIR . 'includes/class-query.php';
75
  require_once TRP_PLUGIN_DIR . 'includes/class-url-converter.php';
76
+ require_once TRP_PLUGIN_DIR . 'includes/class-uri.php';
77
  require_once TRP_PLUGIN_DIR . 'includes/class-plugin-notices.php';
78
  require_once TRP_PLUGIN_DIR . 'includes/functions.php';
79
  require_once TRP_PLUGIN_DIR . 'assets/lib/simplehtmldom/simple_html_dom.php';
133
  */
134
  protected function define_frontend_hooks(){
135
  $this->loader->add_action( 'init', $this->translation_render, 'start_output_buffer', 0 );
 
136
  $this->loader->add_action( 'wp_enqueue_scripts', $this->translation_render, 'enqueue_dynamic_translation', 1 );
137
  $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_preview_on_url_redirect', 99, 2 );
138
  $this->loader->add_filter( 'wp_redirect', $this->translation_render, 'force_language_on_form_url_redirect', 99, 2 );
includes/class-machine-translator.php CHANGED
@@ -29,6 +29,53 @@ class TRP_Machine_Translator{
29
  return false;
30
  }
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  /**
33
  * Returns an array with the API provided translations of the $new_strings array.
34
  *
@@ -39,8 +86,10 @@ class TRP_Machine_Translator{
39
  public function translate_array( $new_strings, $trp_language_code ){
40
  /* we need these settings to go on */
41
  $language_code = $this->settings['google-translate-codes'][$trp_language_code];
42
- if( empty( $this->settings['g-translate-key'] ) || empty( $this->settings['google-translate-codes'][$this->settings['default-language']] ) || empty( $language_code ) )
43
- return array();
 
 
44
 
45
  $translated_strings = array();
46
 
@@ -49,20 +98,8 @@ class TRP_Machine_Translator{
49
  $new_strings_chunks = array_chunk( $new_strings, 128, true );
50
  /* if there are more than 128 strings we make multiple requests */
51
  foreach( $new_strings_chunks as $new_strings_chunk ){
52
- /* build our translation request */
53
- $translation_request = 'key='.$this->settings['g-translate-key'];
54
- $translation_request .= '&source='.$this->settings['google-translate-codes'][$this->settings['default-language']];
55
- $translation_request .= '&target='.$language_code;
56
- foreach( $new_strings_chunk as $new_string ){
57
- $translation_request .= '&q='.rawurlencode(html_entity_decode( $new_string, ENT_QUOTES ));
58
- }
59
 
60
- /* Due to url length restrictions we need so send a POST request faked as a GET request and send the strings in the body of the request and not in the URL */
61
- $response = wp_remote_post( "https://www.googleapis.com/language/translate/v2", array(
62
- 'headers' => array( 'X-HTTP-Method-Override' => 'GET' ),//this fakes a GET request
63
- 'body' => $translation_request,
64
- )
65
- );
66
 
67
  /* analyze the response */
68
  if ( is_array( $response ) && ! is_wp_error( $response ) ) {
29
  return false;
30
  }
31
 
32
+ /**
33
+ * Return referer to be sent in Google Translation request header
34
+ *
35
+ * @return string
36
+ */
37
+ public function get_referer(){
38
+ if( ! $this->referer ) {
39
+ if( ! $this->url_converter ) {
40
+ $trp = TRP_Translate_Press::get_trp_instance();
41
+ $this->url_converter = $trp->get_component( 'url_converter' );
42
+ }
43
+ $this->referer = $this->url_converter->get_abs_home();
44
+ }
45
+ return $this->referer;
46
+ }
47
+
48
+ /**
49
+ * Send request to Google Translation API
50
+ *
51
+ * @param string $source_language Translate from language
52
+ * @param string $language_code Translate to language
53
+ * @param array $strings_array Array of string to translate
54
+ *
55
+ * @return array|WP_Error Response
56
+ */
57
+ public function send_request( $source_language, $language_code, $strings_array ){
58
+ /* build our translation request */
59
+ $translation_request = 'key='.$this->settings['g-translate-key'];
60
+ $translation_request .= '&source='.$source_language;
61
+ $translation_request .= '&target='.$language_code;
62
+ foreach( $strings_array as $new_string ){
63
+ $translation_request .= '&q='.rawurlencode(html_entity_decode( $new_string, ENT_QUOTES ));
64
+ }
65
+ $referer = $this->get_referer();
66
+
67
+ /* Due to url length restrictions we need so send a POST request faked as a GET request and send the strings in the body of the request and not in the URL */
68
+ $response = wp_remote_post( "https://www.googleapis.com/language/translate/v2", array(
69
+ 'headers' => array(
70
+ 'X-HTTP-Method-Override' => 'GET', //this fakes a GET request
71
+ 'Referer' => $referer
72
+ ),
73
+ 'body' => $translation_request,
74
+ )
75
+ );
76
+ return $response;
77
+ }
78
+
79
  /**
80
  * Returns an array with the API provided translations of the $new_strings array.
81
  *
86
  public function translate_array( $new_strings, $trp_language_code ){
87
  /* we need these settings to go on */
88
  $language_code = $this->settings['google-translate-codes'][$trp_language_code];
89
+ $source_language = $this->settings['google-translate-codes'][$this->settings['default-language']];
90
+ if( empty( $this->settings['g-translate-key'] ) || empty( $this->settings['google-translate-codes'][$this->settings['default-language']] ) || empty( $language_code ) || ( $language_code == $source_language ) ) {
91
+ return array();
92
+ }
93
 
94
  $translated_strings = array();
95
 
98
  $new_strings_chunks = array_chunk( $new_strings, 128, true );
99
  /* if there are more than 128 strings we make multiple requests */
100
  foreach( $new_strings_chunks as $new_strings_chunk ){
 
 
 
 
 
 
 
101
 
102
+ $response = $this->send_request( $source_language, $language_code, $new_strings_chunk );
 
 
 
 
 
103
 
104
  /* analyze the response */
105
  if ( is_array( $response ) && ! is_wp_error( $response ) ) {
includes/class-settings.php CHANGED
@@ -11,6 +11,7 @@ class TRP_Settings{
11
  protected $trp_query;
12
  protected $url_converter;
13
  protected $trp_languages;
 
14
 
15
  /**
16
  * Return array of customization options for language switchers.
@@ -75,11 +76,15 @@ class TRP_Settings{
75
  * Settings page content.
76
  */
77
  public function settings_page_content(){
78
- if ( ! $this->trp_languages ){
79
- $trp = TRP_Translate_Press::get_trp_instance();
80
  $this->trp_languages = $trp->get_component( 'languages' );
81
  }
 
 
 
82
  $languages = $this->trp_languages->get_languages( 'english_name' );
 
83
  require_once TRP_PLUGIN_DIR . 'partials/main-settings-page.php';
84
  }
85
 
11
  protected $trp_query;
12
  protected $url_converter;
13
  protected $trp_languages;
14
+ protected $machine_translator;
15
 
16
  /**
17
  * Return array of customization options for language switchers.
76
  * Settings page content.
77
  */
78
  public function settings_page_content(){
79
+ $trp = TRP_Translate_Press::get_trp_instance();
80
+ if ( ! $this->trp_languages ){
81
  $this->trp_languages = $trp->get_component( 'languages' );
82
  }
83
+ if ( ! $this->machine_translator ){
84
+ $this->machine_translator = $trp->get_component( 'machine_translator' );
85
+ }
86
  $languages = $this->trp_languages->get_languages( 'english_name' );
87
+ $gtranslate_referer = $this->machine_translator->get_referer();
88
  require_once TRP_PLUGIN_DIR . 'partials/main-settings-page.php';
89
  }
90
 
includes/class-translation-manager.php CHANGED
@@ -133,18 +133,9 @@ class TRP_Translation_Manager{
133
  */
134
  public function add_slug_as_meta_tag() {
135
  global $post;
136
- // we need this further down when generating slug translations
137
- global $trp_backup_post_id;
138
- if( isset( $post->ID ) && !empty( $post->ID ) && !is_home() && !is_front_page() && !is_archive() && !is_search() ){
139
- $trp_backup_post_id = $post->ID;
140
- } else {
141
- $trp_backup_post_id = 0;
142
- }
143
-
144
  if ( isset( $post->ID ) && !empty( $post->ID ) && isset( $post->post_name ) && !empty( $post->post_name ) && !is_home() && !is_front_page() && !is_archive() && !is_search() ) {
145
  echo '<meta name="trp-slug" original="' . $post->post_name. '" content="' . $post->post_name. '" post-id="' . $post->ID . '"/>' . "\n";
146
  }
147
-
148
  }
149
 
150
  /**
@@ -753,6 +744,11 @@ class TRP_Translation_Manager{
753
  * @return bool
754
  */
755
  static function is_ajax_on_frontend(){
 
 
 
 
 
756
  $trp = TRP_Translate_Press::get_trp_instance();
757
  $url_converter = $trp->get_component("url_converter");
758
 
@@ -941,8 +937,11 @@ class TRP_Translation_Manager{
941
  }
942
  }
943
 
944
- if( ( !empty($TRP_LANGUAGE) && $this->settings["default-language"] != $TRP_LANGUAGE ) || ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] == 'preview' ) )
945
- $translation = '#!trpst#trp-gettext data-trpgettextoriginal=' . $db_id . '#!trpen#' . $translation . '#!trpst#/trp-gettext#!trpen#';//add special start and end tags so that it does not influence html in any way. we will replace them with < and > at the start of the translate function
 
 
 
946
  }
947
 
948
  return $translation;
@@ -1093,6 +1092,23 @@ class TRP_Translation_Manager{
1093
 
1094
  }
1095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1096
  /**
1097
  * Add the current language as a class to the body
1098
  * @param $classes
133
  */
134
  public function add_slug_as_meta_tag() {
135
  global $post;
 
 
 
 
 
 
 
 
136
  if ( isset( $post->ID ) && !empty( $post->ID ) && isset( $post->post_name ) && !empty( $post->post_name ) && !is_home() && !is_front_page() && !is_archive() && !is_search() ) {
137
  echo '<meta name="trp-slug" original="' . $post->post_name. '" content="' . $post->post_name. '" post-id="' . $post->ID . '"/>' . "\n";
138
  }
 
139
  }
140
 
141
  /**
744
  * @return bool
745
  */
746
  static function is_ajax_on_frontend(){
747
+
748
+ /* for our own actions return false */
749
+ if( isset( $_REQUEST['action'] ) && strpos($_REQUEST['action'], 'trp_') === 0 )
750
+ return false;
751
+
752
  $trp = TRP_Translate_Press::get_trp_instance();
753
  $url_converter = $trp->get_component("url_converter");
754
 
937
  }
938
  }
939
 
940
+ if( did_action('init') ) {
941
+ if ((!empty($TRP_LANGUAGE) && $this->settings["default-language"] != $TRP_LANGUAGE) || (isset($_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] == 'preview')) {
942
+ $translation = '#!trpst#trp-gettext data-trpgettextoriginal=' . $db_id . '#!trpen#' . $translation . '#!trpst#/trp-gettext#!trpen#';//add special start and end tags so that it does not influence html in any way. we will replace them with < and > at the start of the translate function
943
+ }
944
+ }
945
  }
946
 
947
  return $translation;
1092
 
1093
  }
1094
 
1095
+ /**
1096
+ * function that strips the gettext tags from a string
1097
+ * @param $string
1098
+ * @return mixed
1099
+ */
1100
+ static function strip_gettext_tags( $string ){
1101
+ if( strpos( $string, ' data-trpgettextoriginal=' ) !== false ) {
1102
+ $string = preg_replace('/ data-trpgettextoriginal=\d+#!trpen#/', '', $string);
1103
+ $string = str_replace('#!trpst#trp-gettext', '', $string);
1104
+ $string = str_replace('#!trpst#/trp-gettext', '', $string);
1105
+ $string = str_replace('#!trpst#\/trp-gettext', '', $string);
1106
+ $string = str_replace('#!trpen#', '', $string);
1107
+ }
1108
+
1109
+ return $string;
1110
+ }
1111
+
1112
  /**
1113
  * Add the current language as a class to the body
1114
  * @param $classes
includes/class-translation-render.php CHANGED
@@ -28,16 +28,18 @@ class TRP_Translation_Render{
28
  */
29
  public function start_output_buffer(){
30
  global $TRP_LANGUAGE;
31
- if( TRP_Translation_Manager::is_ajax_on_frontend() ){
32
- //in this case move forward
33
- }else if( is_admin() ||
34
- ( $TRP_LANGUAGE == $this->settings['default-language'] && ( ! isset( $_REQUEST['trp-edit-translation'] ) || ( isset( $_REQUEST['trp-edit-translation'] ) && $_REQUEST['trp-edit-translation'] != 'preview' ) ) ) ||
35
- ( isset( $_REQUEST['trp-edit-translation']) && $_REQUEST['trp-edit-translation'] == 'true' ) ) {
36
- return;
37
- }
38
 
39
- mb_http_output("UTF-8");
40
- ob_start(array($this, 'translate_page'));
 
 
 
 
 
 
 
 
 
41
  }
42
 
43
  /**
@@ -324,14 +326,16 @@ class TRP_Translation_Render{
324
  foreach ( $json_array as $key => $value ) {
325
  if ( ! empty( $value ) ) {
326
  if ( ! is_array( $value ) ) { //if the current element is not an array check if it a html text and translate
327
- if ( html_entity_decode( (string) $value ) != strip_tags( html_entity_decode( (string) $value ) ) ) {
 
328
  $json_array[ $key ] = $this->translate_page( stripslashes( $value ) );
329
  }
330
  } else {//look for the html elements
331
  foreach ( $value as $k => $v ) {
332
  if ( ! empty( $v ) ) {
333
  if ( ! is_array( $v ) ) {
334
- if ( html_entity_decode( (string) $v ) != strip_tags( html_entity_decode( (string) $v ) ) ) {
 
335
  $json_array[ $key ][ $k ] = $this->translate_page( stripslashes( $v ) );
336
  }
337
  }
@@ -730,6 +734,16 @@ class TRP_Translation_Render{
730
  return $html->save();
731
  }
732
 
 
 
 
 
 
 
 
 
 
 
733
  /**
734
  * Whether given url links to an external domain.
735
  *
28
  */
29
  public function start_output_buffer(){
30
  global $TRP_LANGUAGE;
 
 
 
 
 
 
 
31
 
32
+ if( ( is_admin() && !TRP_Translation_Manager::is_ajax_on_frontend() ) || trp_is_translation_editor( 'true' ) ){
33
+ return;//we have two cases where we don't do anything: we are on the admin side and we are not in an ajax call or we are in the left side of the translation editor
34
+ }
35
+ else {
36
+ mb_http_output("UTF-8");
37
+ if ( $TRP_LANGUAGE == $this->settings['default-language'] && !trp_is_translation_editor() ) {
38
+ ob_start(array($this, 'clear_trp_tags'));//on default language when we are not in editor we just need to clear any trp tags that could still be present
39
+ } else {
40
+ ob_start(array($this, 'translate_page'));//everywhere else translate the page
41
+ }
42
+ }
43
  }
44
 
45
  /**
326
  foreach ( $json_array as $key => $value ) {
327
  if ( ! empty( $value ) ) {
328
  if ( ! is_array( $value ) ) { //if the current element is not an array check if it a html text and translate
329
+ $html_decoded_value = html_entity_decode( (string) $value );
330
+ if ( $html_decoded_value != strip_tags( $html_decoded_value ) ) {
331
  $json_array[ $key ] = $this->translate_page( stripslashes( $value ) );
332
  }
333
  } else {//look for the html elements
334
  foreach ( $value as $k => $v ) {
335
  if ( ! empty( $v ) ) {
336
  if ( ! is_array( $v ) ) {
337
+ $html_decoded_v = html_entity_decode( (string) $v );
338
+ if ( $html_decoded_v != strip_tags( $html_decoded_v ) ) {
339
  $json_array[ $key ][ $k ] = $this->translate_page( stripslashes( $v ) );
340
  }
341
  }
734
  return $html->save();
735
  }
736
 
737
+ /**
738
+ * Function that should be called only on the default language and when we are not in the editor mode and it is designed as a fallback to clear
739
+ * any trp gettext tags that we added and for some reason show up although they should not
740
+ * @param $output
741
+ * @return mixed
742
+ */
743
+ function clear_trp_tags( $output ){
744
+ return TRP_Translation_Manager::strip_gettext_tags($output);
745
+ }
746
+
747
  /**
748
  * Whether given url links to an external domain.
749
  *
includes/class-uri.php ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace TranslatePress;
3
+
4
+ class Uri
5
+ {
6
+ const SCHEMES_WITH_AUTHORITY = ';http;https;ftp';
7
+ /** @var string */
8
+ private $scheme;
9
+ /** @var string */
10
+ private $host;
11
+ /** @var string */
12
+ private $user;
13
+ /** @var string */
14
+ private $pass;
15
+ /** @var string */
16
+ private $path;
17
+ /** @var string */
18
+ private $query;
19
+ /** @var string */
20
+ private $fragment;
21
+ /** @var int */
22
+ private $port;
23
+ /** @var bool */
24
+ private $absolute = true;
25
+
26
+ /**
27
+ * If $uri is set, we'll hydrate this object with it
28
+ *
29
+ * @param string $uri {optional}
30
+ */
31
+ public function __construct($uri = null)
32
+ {
33
+ if ($uri !== null) {
34
+ $this->fromString($uri);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Alias for getUri.
40
+ * @return string
41
+ */
42
+ public function __toString()
43
+ {
44
+ return $this->getUri();
45
+ }
46
+
47
+ /**
48
+ * Hydrate this object with values from a string
49
+ * @param $uri
50
+ * @return self
51
+ */
52
+ public function fromString($uri)
53
+ {
54
+ if (is_numeric($uri)) { //Could be a valid url
55
+ $uri = '' . $uri;
56
+ }
57
+ if (!is_string($uri)) {
58
+ $uri = '';
59
+ }
60
+ $this->setRelative();
61
+ if (0 === strpos($uri, '//')) {
62
+ $this->setAbsolute();
63
+ }
64
+ $parsed_url = parse_url($uri);
65
+ if (!$parsed_url) {
66
+ return $this;
67
+ }
68
+ if (array_key_exists('scheme', $parsed_url)) {
69
+ $this->setAbsolute();
70
+ }
71
+ foreach ($parsed_url as $urlPart => $value) {
72
+ $method = 'set' . ucfirst($urlPart);
73
+ if (method_exists($this, $method)) {
74
+ $this->$method($value);
75
+ }
76
+ }
77
+ return $this;
78
+ }
79
+
80
+ /**
81
+ * Get the URI from the set parameters
82
+ * @return string
83
+ */
84
+ public function getUri()
85
+ {
86
+ $userPart = '';
87
+ if ($this->getUser() !== null && $this->getPass() !== null) {
88
+ $userPart = $this->getUser() . ':' . $this->getPass() . '@';
89
+ } else if ($this->getUser() !== null) {
90
+ $userPart = $this->getUser() . '@';
91
+ }
92
+ $schemePart = ($this->getScheme() ? $this->getScheme() . '://' : '//');
93
+ if (!in_array($this->getScheme(), self::getSchemesWithAuthority())) {
94
+ $schemePart = $this->getScheme() . ':';
95
+ }
96
+ $portPart = ($this->getPort() ? ':' . $this->getPort() : '');
97
+ $queryPart = ($this->getQuery() ? '?' . $this->getQuery() : '');
98
+ $fragmentPart = ($this->getFragment() ? '#' . $this->getFragment() : '');
99
+ if ($this->isRelative()) {
100
+ return $this->getPath() .
101
+ $queryPart .
102
+ $fragmentPart;
103
+ }
104
+ $path = $this->getPath();
105
+ if (0 !== strlen($path) && '/' !== $path[0]) {
106
+ $path = '/' . $path;
107
+ }
108
+ return $schemePart .
109
+ $userPart .
110
+ $this->getHost() .
111
+ $portPart .
112
+ $path .
113
+ $queryPart .
114
+ $fragmentPart;
115
+ }
116
+
117
+ /**
118
+ * @param string $fragment
119
+ * @return self
120
+ */
121
+ public function setFragment($fragment)
122
+ {
123
+ $this->fragment = $fragment;
124
+ return $this;
125
+ }
126
+
127
+ /**
128
+ * @return string
129
+ */
130
+ public function getFragment()
131
+ {
132
+ return $this->fragment;
133
+ }
134
+
135
+ /**
136
+ * @param string $host
137
+ * @return self
138
+ */
139
+ public function setHost($host)
140
+ {
141
+ $this->host = $host;
142
+ $this->setAbsolute();
143
+ return $this;
144
+ }
145
+
146
+ /**
147
+ * @return string
148
+ */
149
+ public function getHost()
150
+ {
151
+ return $this->host;
152
+ }
153
+
154
+ /**
155
+ * @param string $pass
156
+ * @return self
157
+ */
158
+ public function setPass($pass)
159
+ {
160
+ $this->pass = $pass;
161
+ return $this;
162
+ }
163
+
164
+ /**
165
+ * @return string
166
+ */
167
+ public function getPass()
168
+ {
169
+ return $this->pass;
170
+ }
171
+
172
+ /**
173
+ * @param string $path
174
+ * @return self
175
+ */
176
+ public function setPath($path)
177
+ {
178
+ $this->path = $path;
179
+ return $this;
180
+ }
181
+
182
+ /**
183
+ * @return string
184
+ */
185
+ public function getPath()
186
+ {
187
+ return $this->path;
188
+ }
189
+
190
+ /**
191
+ * Set the query. Must be a string, and the prepending "?" will be trimmed.
192
+ * Example: ?a=b&c[]=123 -> "a=b&c[]=123"
193
+ * @see Sensimity_Helper_UriTest::provideSetQuery
194
+ *
195
+ * @param string $query
196
+ * @return self
197
+ */
198
+ public function setQuery($query)
199
+ {
200
+ $this->query = null;
201
+ if (is_string($query)) {
202
+ $this->query = ltrim($query, '?');
203
+ }
204
+ return $this;
205
+ }
206
+
207
+ /**
208
+ * @return string
209
+ */
210
+ public function getQuery()
211
+ {
212
+ return $this->query;
213
+ }
214
+
215
+ /**
216
+ * Set the scheme. If its empty, it will be set to null.
217
+ *
218
+ * Must be a string. Can only contain "a-z A-Z 0-9 . : -".
219
+ * Will be forced to lowercase.
220
+ * Appended : or // will be removed.
221
+ * @see Sensimity_Helper_UriTest::provideSetScheme
222
+ *
223
+ * @param string $scheme
224
+ * @return self
225
+ */
226
+ public function setScheme($scheme)
227
+ {
228
+ $this->scheme = null;
229
+ if (empty($scheme) || null === $scheme) {
230
+ return $this;
231
+ }
232
+ $scheme = preg_replace('/[^a-zA-Z0-9\.\:\-]/', '', $scheme);
233
+ $scheme = strtolower($scheme);
234
+ $scheme = rtrim($scheme, ':/');
235
+ $scheme = trim($scheme, ':/');
236
+ $scheme = str_replace('::', ':', $scheme);
237
+ if (strlen($scheme) != 0) {
238
+ if ($this->isRelative()) {
239
+ /* Explained: */
240
+ /* @see Sensimity_Helper_UriTest::testRelativeAbsoluteUrls */
241
+ $exp = explode('/', ltrim($this->getPath(), '/'));
242
+ $this->setHost($exp[0]);
243
+ unset($exp[0]);
244
+ $this->setPath(null);
245
+ $path = implode('/', $exp);
246
+ if (strlen($path) > 0) {
247
+ //Only create the "/" if theres a path
248
+ $this->setPath('/' . $path);
249
+ }
250
+ $this->setAbsolute();
251
+ }
252
+ $this->scheme = $scheme;
253
+ }
254
+ return $this;
255
+ }
256
+
257
+ /**
258
+ * @return string
259
+ */
260
+ public function getScheme()
261
+ {
262
+ return $this->scheme;
263
+ }
264
+
265
+ /**
266
+ * @param string $user
267
+ * @return self
268
+ */
269
+ public function setUser($user)
270
+ {
271
+ $this->user = $user;
272
+ return $this;
273
+ }
274
+
275
+ /**
276
+ * @return string
277
+ */
278
+ public function getUser()
279
+ {
280
+ return $this->user;
281
+ }
282
+
283
+ /**
284
+ * Port must be a valid number. Otherwise it will be set to NULL. (default scheme port)
285
+ * @see Sensimity_Helper_UriTest::provideSetPort
286
+ *
287
+ * @param int|string $port
288
+ * @return self
289
+ */
290
+ public function setPort($port)
291
+ {
292
+ $this->port = null;
293
+ if ((is_string($port) || is_numeric($port)) && ctype_digit(strval($port))) {
294
+ $this->port = (int) $port;
295
+ }
296
+ return $this;
297
+ }
298
+
299
+ /**
300
+ * @return int
301
+ */
302
+ public function getPort()
303
+ {
304
+ return $this->port;
305
+ }
306
+
307
+ /**
308
+ * @return bool
309
+ */
310
+ public function isRelative()
311
+ {
312
+ return (!$this->absolute);
313
+ }
314
+
315
+ /**
316
+ * @return bool
317
+ */
318
+ public function isAbsolute()
319
+ {
320
+ return ($this->absolute);
321
+ }
322
+
323
+ /**
324
+ * @return $this
325
+ */
326
+ public function setAbsolute()
327
+ {
328
+ $this->absolute = true;
329
+ return $this;
330
+ }
331
+
332
+ /**
333
+ * @return $this
334
+ */
335
+ public function setRelative()
336
+ {
337
+ $this->absolute = false;
338
+ return $this;
339
+ }
340
+
341
+ /** Some helpful static functions */
342
+
343
+ /**
344
+ * @param $uri
345
+ * @param null $scheme
346
+ * @return string
347
+ */
348
+ public static function changeScheme($uri, $scheme = null)
349
+ {
350
+ if ($scheme == null) { //null for scheme = just no change at all - only in this static function, for BC!
351
+ return $uri;
352
+ }
353
+ $class = get_called_class();
354
+ $uri = new $class($uri);
355
+ $uri->setScheme($scheme);
356
+ return $uri->getUri();
357
+ }
358
+
359
+ /**
360
+ * @see http://tools.ietf.org/html/rfc3986#section-3
361
+ * @return array
362
+ */
363
+ public static function getSchemesWithAuthority()
364
+ {
365
+ return explode(';', self::SCHEMES_WITH_AUTHORITY);
366
+ }
367
+
368
+ /**
369
+ * @return bool
370
+ */
371
+ public function isSchemeless()
372
+ {
373
+ $scheme = $this->getScheme();
374
+ return (bool) ($this->isRelative() || ($this->isAbsolute() && empty($scheme)));
375
+ }
376
+ }
includes/class-url-converter.php CHANGED
@@ -129,93 +129,137 @@ class TRP_Url_Converter {
129
  *
130
  * Defaults to current Url and current language.
131
  *
132
- * @param string $language Language code.
133
  * @param string $url Url to encode.
134
  * @return string
135
  */
 
136
  public function get_url_for_language ( $language = null, $url = null, $trp_link_is_processed = '#TRPLINKPROCESSED') {
 
 
137
  global $TRP_LANGUAGE;
138
- global $trp_backup_post_id;
139
- $new_url = '';
 
 
 
 
 
 
 
140
 
141
- // we're appending $trp_link_is_processed string to the end of each processed link so we don't process them again in the render class.
142
- // we're stripping this from each url in the render class
143
- // $trp_link_is_processed is part of the function params so we can pass an empty link in case we need get_url_for_language() in other places that don't go through the render.
144
- // since the render doesn't work on the default language, we're striping the processed tag.
145
  if( $TRP_LANGUAGE == $this->settings['default-language'] ){
146
  $trp_link_is_processed = '';
147
  }
148
 
 
149
  if ( $this->url_is_file($url) ){
150
- return $url . $trp_link_is_processed;
 
151
  }
152
 
153
- $trp_language_copy = $TRP_LANGUAGE;
 
 
 
154
 
155
- if ( empty( $language ) ) {
156
- $language = $TRP_LANGUAGE;
 
157
  }
158
 
159
- /* @ TO-DO
160
- * need our own url_to_postid()This is due to the fact that we're using get_permalink that's filtered to get the correct url based on language with SEO Addon.
161
- * url_to_postid() can be slow because it's doing a query for each bloody url.
162
- * this is not a problem with pages that have fewer links, however, it is a problem
163
- * with pages that list a ton of links
164
- */
165
- $post_id = url_to_postid( $url );
166
 
167
- if( empty( $url ) ) {
168
- $url = $this->cur_page_url();
169
- $post_id = ( url_to_postid( $url ) ) ? ( url_to_postid( $url ) ) : ( $trp_backup_post_id );
 
 
 
 
 
170
  }
171
 
172
- if ( $post_id == 0 ) {
 
 
 
 
 
 
 
173
  $TRP_LANGUAGE = $this->settings['default-language'];
174
  $post_id = url_to_postid( $url );
 
175
  $TRP_LANGUAGE = $trp_language_copy;
176
  }
177
 
178
  if( $post_id ){
 
179
  /*
180
  * We need to find if the current URL (either passed as parameter or found via cur_page_url)
181
  * has extra arguments compared to it's permalink.
182
  * We need the permalink based on the language IN THE URL, not the one passed to this function,
183
  * as that represents the language to be translated into.
184
  */
 
 
 
 
 
 
 
185
  $TRP_LANGUAGE = $this->get_lang_from_url_string( $url );
186
  $processed_permalink = get_permalink($post_id);
187
- $arguments = str_replace($processed_permalink, '', $url);
 
 
 
 
 
 
188
  // if nothing was replaced, something was wrong, just use the normal permalink without any arguments.
189
  if( $arguments == $url ) $arguments = '';
190
 
191
- /*
192
- * Transform the global language into the language to be translated,
193
- * so we can get the correct permalink (slug and all) and add the remaining arguments that might exist.
194
- */
195
  $TRP_LANGUAGE = $language;
196
- if ( !empty ( $arguments ) ) {
197
- $arguments = apply_filters('trp_get_url_for_language_custom_arguments', $arguments, $language, $url, $post_id);
198
- }
199
  $new_url = get_permalink( $post_id ) . $arguments;
 
200
  $TRP_LANGUAGE = $trp_language_copy;
 
201
  } else {
202
- // If no $post_id is set we simply replace the current language root with the new language root.
203
- // we can't assume the URL's have / at the end so we need to untrailingslashit both $abs_home and $new_language_root
204
- $abs_home = trailingslashit( $this->get_abs_home() );
205
- $current_url_language = $this->get_lang_from_url_string( $url );
206
- $current_lang_root = untrailingslashit($abs_home . $this->get_url_slug( $current_url_language ));
207
- $new_language_root = untrailingslashit($abs_home . $this->get_url_slug( $language ) );
208
 
209
  if( $this->get_lang_from_url_string($url) === null ){
210
- // this is for forcing the custom url's. We expect them to not have a language in them.
211
- $new_url = str_replace(untrailingslashit($abs_home), $new_language_root, $url);
 
 
 
 
212
  } else {
213
- $new_url = str_replace($current_lang_root, $new_language_root, $url);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  }
215
- $new_url = apply_filters( 'trp_get_url_for_language', $new_url, $url, $language, $abs_home, $current_lang_root, $new_language_root );
216
  }
217
 
218
-
219
  /* fix links for woocommerce on language switcher for product categories and product tags */
220
  if( class_exists( 'WooCommerce' ) ){
221
  $default_woocommerce_slugs = array('product-category', 'product-tag', 'product');
@@ -237,6 +281,7 @@ class TRP_Url_Converter {
237
  }
238
 
239
  return $new_url . $trp_link_is_processed ;
 
240
  }
241
 
242
  /**
@@ -323,32 +368,28 @@ class TRP_Url_Converter {
323
  if ( ! $url ){
324
  $url = $this->cur_page_url();
325
  }
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
- // we remove http or https
328
- // if the user links to a http link but the abs_home_url is https, we're serving the https one so we don't brake cookies if he doesn't have proper redirects
329
- $lang = preg_replace( '#^(http|https)://#', '', $url );
330
- $abs_home = preg_replace( '#^(http|https)://#', '', $this->get_abs_home() );
331
-
332
- // we have removed the home path from our URL. We're adding a / in case it's the homepage of one of the languages
333
- // removing / from the front so it's easier for understanding explode()
334
- $lang = ltrim( trailingslashit( str_replace($abs_home, '', $lang)),'/' );
335
-
336
- // We now have to see if the first part of the string is actually a language slug
337
- $lang = explode('/', $lang);
338
- if( $lang == false ){
339
- return null;
340
- }
341
- // If we have a language in the URL, the first element of the array should be it.
342
- $lang = $lang[0];
343
-
344
- $lang = apply_filters( 'trp_get_lang_from_url_string', $lang, $url );
345
 
346
- // the lang slug != actual lang. So we need to do array_search so we don't end up with en instead of en_US
347
- if( isset($this->settings['url-slugs']) && in_array($lang, $this->settings['url-slugs']) ){
348
- return array_search($lang, $this->settings['url-slugs']);
349
- } else {
350
- return null;
351
  }
 
 
352
  }
353
 
354
  /**
129
  *
130
  * Defaults to current Url and current language.
131
  *
132
+ * @param string $language Language code that we want to translate into.
133
  * @param string $url Url to encode.
134
  * @return string
135
  */
136
+
137
  public function get_url_for_language ( $language = null, $url = null, $trp_link_is_processed = '#TRPLINKPROCESSED') {
138
+ $debug = false;
139
+ // initializations
140
  global $TRP_LANGUAGE;
141
+ $trp_language_copy = $TRP_LANGUAGE;
142
+ if ( empty( $language ) ) {
143
+ $language = $TRP_LANGUAGE;
144
+ }
145
+ if ( empty($url) ){
146
+ $url = $this->cur_page_url();
147
+ }
148
+ $url_obj = new \TranslatePress\Uri($url);
149
+ $abs_home_url_obj = new \TranslatePress\Uri( $this->get_abs_home() );
150
 
 
 
 
 
151
  if( $TRP_LANGUAGE == $this->settings['default-language'] ){
152
  $trp_link_is_processed = '';
153
  }
154
 
155
+ // actual logic of the function
156
  if ( $this->url_is_file($url) ){
157
+ trp_bulk_debug($debug, array('url' => $url, 'abort' => 'is file'));
158
+ return $url . $trp_link_is_processed; //abort for files
159
  }
160
 
161
+ if ( !$url_obj->isSchemeless() && $url_obj->getScheme() != 'http' && $url_obj->getScheme() != 'https' ){
162
+ trp_bulk_debug($debug, array('url' => $url, 'abort' => "is different scheme ".$url_obj->getScheme()));
163
+ return $url . $trp_link_is_processed; // abort for non-http/https links
164
+ }
165
 
166
+ if ( $url_obj->isSchemeless() && !$url_obj->getPath() && !$url_obj->getQuery() ){
167
+ trp_bulk_debug($debug, array('url' => $url, 'abort' => "is anchor"));
168
+ return $url; // abort for anchors
169
  }
170
 
171
+ if ( $url_obj->getHost() && $abs_home_url_obj->getHost() && $url_obj->getHost() != $abs_home_url_obj->getHost() ){
172
+ trp_bulk_debug($debug, array('url' => $url, 'abort' => "is external url "));
173
+ return $url; // abort for external url's
174
+ }
 
 
 
175
 
176
+ if( $this->get_lang_from_url_string($url) === null && $this->settings['default-language'] === $language && $this->settings['add-subdirectory-to-default-language'] !== 'yes' ){
177
+ trp_bulk_debug($debug, array('url' => $url, 'abort' => "URL already has the correct language added to it and default language has subdir"));
178
+ return $url;
179
+ }
180
+
181
+ if( $this->get_lang_from_url_string($url) === $language ){
182
+ trp_bulk_debug($debug, array('url' => $url, 'abort' => "URL already has the correct language added to it"));
183
+ return $url;
184
  }
185
 
186
+ // maybe find the post_id for the current URL
187
+ $possible_post_id = url_to_postid($url);
188
+ if ( $possible_post_id ){
189
+ $post_id = $possible_post_id;
190
+
191
+ trp_bulk_debug($debug, array('url' => $url, 'found post id' => $post_id, 'for language' => $TRP_LANGUAGE));
192
+ } else {
193
+ // try again but with the default language home_url
194
  $TRP_LANGUAGE = $this->settings['default-language'];
195
  $post_id = url_to_postid( $url );
196
+ if($post_id){ trp_bulk_debug($debug, array('url' => $url, 'found post id' => $post_id, 'for default language' => $TRP_LANGUAGE)); }
197
  $TRP_LANGUAGE = $trp_language_copy;
198
  }
199
 
200
  if( $post_id ){
201
+
202
  /*
203
  * We need to find if the current URL (either passed as parameter or found via cur_page_url)
204
  * has extra arguments compared to it's permalink.
205
  * We need the permalink based on the language IN THE URL, not the one passed to this function,
206
  * as that represents the language to be translated into.
207
  */
208
+
209
+ /*
210
+ * WE ARE NOT USING \TranslatePress\Uri
211
+ * due to URL's having extra path elements after the permalink slug. Using the class would strip those end points.
212
+ *
213
+ */
214
+
215
  $TRP_LANGUAGE = $this->get_lang_from_url_string( $url );
216
  $processed_permalink = get_permalink($post_id);
217
+
218
+ if($url_obj->isSchemeless()){
219
+ $arguments = str_replace($processed_permalink, '', trailingslashit( home_url() ) . ltrim($url, '/') );
220
+ } else {
221
+ $arguments = str_replace($processed_permalink, '', $url );
222
+ }
223
+
224
  // if nothing was replaced, something was wrong, just use the normal permalink without any arguments.
225
  if( $arguments == $url ) $arguments = '';
226
 
 
 
 
 
227
  $TRP_LANGUAGE = $language;
 
 
 
228
  $new_url = get_permalink( $post_id ) . $arguments;
229
+ trp_bulk_debug($debug, array('url' => $url, 'new url' => $new_url, 'found post id' => $post_id, 'isSchemeless' => 'true', 'url type' => 'based on permalink', 'for language' => $TRP_LANGUAGE));
230
  $TRP_LANGUAGE = $trp_language_copy;
231
+
232
  } else {
233
+ // we're just adding the new language to the url
234
+ $new_url_obj = new \TranslatePress\Uri( $url );
 
 
 
 
235
 
236
  if( $this->get_lang_from_url_string($url) === null ){
237
+ // these are the custom url. They don't have language
238
+ $abs_home_considered_path = trim(str_replace($abs_home_url_obj->getPath(), '', $url_obj->getPath()), '/');
239
+ $new_url_obj->setPath( trailingslashit($abs_home_url_obj->getPath()) . trailingslashit($this->get_url_slug( $language )) . $abs_home_considered_path );
240
+ $new_url = $new_url_obj->getUri();
241
+
242
+ trp_bulk_debug($debug, array('url' => $url, 'new url' => $new_url, 'lang' => $language, 'url type' => 'custom url without language parameter'));
243
  } else {
244
+ // these have language param in them and we need to replace them with the new language
245
+ $abs_home_considered_path = trim(str_replace($abs_home_url_obj->getPath(), '', $url_obj->getPath()), '/');
246
+ $no_lang_orig_path = explode('/', $abs_home_considered_path);
247
+ unset($no_lang_orig_path[0]);
248
+ $no_lang_orig_path = implode('/', $no_lang_orig_path );
249
+
250
+ if ( !$this->get_url_slug( $language ) ){
251
+ $url_lang_slug = '';
252
+ } else {
253
+ $url_lang_slug = trailingslashit($this->get_url_slug( $language ));
254
+ }
255
+
256
+ $new_url_obj->setPath( trailingslashit($abs_home_url_obj->getPath()) . $url_lang_slug . ltrim($no_lang_orig_path, '/') );
257
+ $new_url = $new_url_obj->getUri();
258
+
259
+ trp_bulk_debug($debug, array('url' => $url, 'new url' => $new_url, 'lang' => $language, 'url type' => 'custom url with language', 'abs home path' => $abs_home_url_obj->getPath()));
260
  }
 
261
  }
262
 
 
263
  /* fix links for woocommerce on language switcher for product categories and product tags */
264
  if( class_exists( 'WooCommerce' ) ){
265
  $default_woocommerce_slugs = array('product-category', 'product-tag', 'product');
281
  }
282
 
283
  return $new_url . $trp_link_is_processed ;
284
+
285
  }
286
 
287
  /**
368
  if ( ! $url ){
369
  $url = $this->cur_page_url();
370
  }
371
+ $url_obj = new \TranslatePress\Uri($url);
372
+ $abs_home_url_obj = new \TranslatePress\Uri( $this->get_abs_home() );
373
+
374
+ if( $url_obj->getPath() ){
375
+ $possible_path = str_replace($abs_home_url_obj->getPath(), '', $url_obj->getPath());
376
+ $lang = ltrim( $possible_path,'/' );
377
+ $lang = explode('/', $lang);
378
+ if( $lang == false ){
379
+ return null;
380
+ }
381
+ // If we have a language in the URL, the first element of the array should be it.
382
+ $lang = $lang[0];
383
 
384
+ $lang = apply_filters( 'trp_get_lang_from_url_string', $lang, $url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
 
386
+ // the lang slug != actual lang. So we need to do array_search so we don't end up with en instead of en_US
387
+ if( isset($this->settings['url-slugs']) && in_array($lang, $this->settings['url-slugs']) ){
388
+ return array_search($lang, $this->settings['url-slugs']);
389
+ }
 
390
  }
391
+
392
+ return null;
393
  }
394
 
395
  /**
includes/functions.php CHANGED
@@ -165,6 +165,30 @@ function trp_sanitize_string( $filtered ){
165
  }
166
 
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  /** Compatibility functions */
170
 
@@ -555,4 +579,29 @@ add_filter('ginger_iframe_banner', 'trp_do_shortcode', 999 );
555
  add_filter('ginger_text_banner', 'trp_do_shortcode', 999 );
556
  function trp_do_shortcode($content){
557
  return do_shortcode(stripcslashes($content));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  }
165
  }
166
 
167
 
168
+ /**
169
+ * function that checks if $_REQUEST['trp-edit-translation'] is set or if it has a certain value
170
+ */
171
+ function trp_is_translation_editor( $value = '' ){
172
+ if( isset( $_REQUEST['trp-edit-translation'] ) ){
173
+ if( !empty( $value ) ) {
174
+ if( $_REQUEST['trp-edit-translation'] === $value ) {
175
+ return true;
176
+ }
177
+ else{
178
+ return false;
179
+ }
180
+ }
181
+ else{
182
+ $possible_values = array ('preview', 'true');
183
+ if( in_array( $_REQUEST['trp-edit-translation'], $possible_values ) ) {
184
+ return true;
185
+ }
186
+ }
187
+ }
188
+
189
+ return false;
190
+ }
191
+
192
 
193
  /** Compatibility functions */
194
 
579
  add_filter('ginger_text_banner', 'trp_do_shortcode', 999 );
580
  function trp_do_shortcode($content){
581
  return do_shortcode(stripcslashes($content));
582
+ }
583
+
584
+ /**
585
+ * Debuger function. Mainly designed for the get_url_for_language() function
586
+ *
587
+ * @since 1.3.6
588
+ *
589
+ * @param bool $enabled
590
+ * @param array $logger
591
+ */
592
+ function trp_bulk_debug($debug = false, $logger = array()){
593
+ if(!$debug){
594
+ return;
595
+ }
596
+ error_log('---------------------------------------------------------');
597
+ $key_length = '';
598
+ foreach ($logger as $key => $value){
599
+ if ( strlen($key) > $key_length)
600
+ $key_length = strlen($key);
601
+ }
602
+
603
+ foreach ($logger as $key => $value){
604
+ error_log("$key : " . str_repeat(' ', $key_length - strlen($key)) . $value);
605
+ }
606
+ error_log('---------------------------------------------------------');
607
  }
includes/trp-ajax.php CHANGED
@@ -50,7 +50,7 @@ class TRP_Ajax{
50
  if ( is_array( $strings ) ) {
51
  foreach ($strings as $key => $string) {
52
  if ( isset($string->original ) ) {
53
- $original_array[$key] = mysqli_real_escape_string( $this->connection, filter_var( $string->original, FILTER_SANITIZE_STRING ) );
54
  }
55
  }
56
  }
@@ -155,7 +155,7 @@ class TRP_Ajax{
155
  * @param string $original_language Language to translate from. Default language.
156
  */
157
  protected function output_translations( $strings, $language, $original_language ){
158
- $sql = 'SELECT original, translated FROM ' . $this->table_prefix . 'trp_dictionary_' . strtolower( $original_language ) . '_' . strtolower( $language ) . ' WHERE original IN (\'' . implode( "','", array_map( array( $this, 'full_trim' ), $strings ) ).'\') AND status != 0';
159
  $result = mysqli_query( $this->connection, $sql );
160
  if ( $result === false ){
161
  $this->return_error();
50
  if ( is_array( $strings ) ) {
51
  foreach ($strings as $key => $string) {
52
  if ( isset($string->original ) ) {
53
+ $original_array[$key] = mysqli_real_escape_string( $this->connection, $this->full_trim( filter_var( $string->original, FILTER_SANITIZE_STRING ) ) );
54
  }
55
  }
56
  }
155
  * @param string $original_language Language to translate from. Default language.
156
  */
157
  protected function output_translations( $strings, $language, $original_language ){
158
+ $sql = 'SELECT original, translated FROM ' . $this->table_prefix . 'trp_dictionary_' . strtolower( $original_language ) . '_' . strtolower( $language ) . ' WHERE original IN (\'' . implode( "','", $strings ) .'\') AND status != 0';
159
  $result = mysqli_query( $this->connection, $sql );
160
  if ( $result === false ){
161
  $this->return_error();
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site, with full support for WooCommerce and site builders.
6
- Version: 1.3.5
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
3
  Plugin Name: TranslatePress - Multilingual
4
  Plugin URI: https://translatepress.com/
5
  Description: Experience a better way of translating your WordPress site, with full support for WooCommerce and site builders.
6
+ Version: 1.3.6
7
  Author: Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban
8
  Author URI: https://cozmoslabs.com/
9
  Text Domain: translatepress-multilingual
languages/translatepress-multilingual.catalog.php CHANGED
@@ -85,8 +85,9 @@
85
  <?php __("Google Translate", "translatepress-multilingual"); ?>
86
  <?php __("Enable or disable the automatic translation of the site with Google Translate. Only untranslated strings will receive a translation.<br>You can later edit these automatic translations.<br>Note: Not all languages support automatic translation. Please consult the <a href=\"https://cloud.google.com/translate/docs/languages\" target=\"_blank\" title=\"Automatic translation supported languages.\">supported languages list</a>. ", "translatepress-multilingual"); ?>
87
  <?php __("Google Translate API Key", "translatepress-multilingual"); ?>
88
- <?php __("Test api key", "translatepress-multilingual"); ?>
89
- <?php __("Visit this <a href=\"https://cloud.google.com/docs/authentication/api-keys\" target=\"_blank\">link</a> to see how you can set up an API key. ", "translatepress-multilingual"); ?>
 
90
  <?php __("Language Switcher", "translatepress-multilingual"); ?>
91
  <?php __("Shortcode ", "translatepress-multilingual"); ?>
92
  <?php __("Use shortcode on any page or widget.", "translatepress-multilingual"); ?>
@@ -96,6 +97,8 @@
96
  <?php __("Floating language selection", "translatepress-multilingual"); ?>
97
  <?php __("Have a floating dropdown following the user on every page.", "translatepress-multilingual"); ?>
98
  <?php __("Google API Key from settings page:", "translatepress-multilingual"); ?>
 
 
99
  <?php __("Response:", "translatepress-multilingual"); ?>
100
  <?php __("Response Body:", "translatepress-multilingual"); ?>
101
  <?php __("Entire Response From wp_remote_get():", "translatepress-multilingual"); ?>
@@ -135,6 +138,3 @@
135
  <?php __("Batch size", "translatepress-multilingual"); ?>
136
  <?php __("The number of rows to check at once.<br>Choosing a smaller number helps solve the 502 error \"Page took too long to respond\" on large databases.<br>May take several minutes depending on the database size.", "translatepress-multilingual"); ?>
137
  <?php __("Remove duplicate rows", "translatepress-multilingual"); ?>
138
- <?php __(" TranslatePress Settings", "translatepress-multilingual"); ?>
139
- <?php __("Translator", "translatepress-multilingual"); ?>
140
- <?php __("Allow this user to translate the website.", "translatepress-multilingual"); ?>
85
  <?php __("Google Translate", "translatepress-multilingual"); ?>
86
  <?php __("Enable or disable the automatic translation of the site with Google Translate. Only untranslated strings will receive a translation.<br>You can later edit these automatic translations.<br>Note: Not all languages support automatic translation. Please consult the <a href=\"https://cloud.google.com/translate/docs/languages\" target=\"_blank\" title=\"Automatic translation supported languages.\">supported languages list</a>. ", "translatepress-multilingual"); ?>
87
  <?php __("Google Translate API Key", "translatepress-multilingual"); ?>
88
+ <?php __("Test API key", "translatepress-multilingual"); ?>
89
+ <?php __("Visit <a href=\"https://cloud.google.com/docs/authentication/api-keys\" target=\"_blank\">this link</a> to see how you can set up an API key, <strong>control API costs</strong> and set HTTP referrer restrictions.", "translatepress-multilingual"); ?>
90
+ <?php __("<br>Your HTTP referrer is: %s", "translatepress-multilingual"); ?>
91
  <?php __("Language Switcher", "translatepress-multilingual"); ?>
92
  <?php __("Shortcode ", "translatepress-multilingual"); ?>
93
  <?php __("Use shortcode on any page or widget.", "translatepress-multilingual"); ?>
97
  <?php __("Floating language selection", "translatepress-multilingual"); ?>
98
  <?php __("Have a floating dropdown following the user on every page.", "translatepress-multilingual"); ?>
99
  <?php __("Google API Key from settings page:", "translatepress-multilingual"); ?>
100
+ <?php __("HTTP Referrer:", "translatepress-multilingual"); ?>
101
+ <?php __("Use this HTTP Referrer if you want to restrict usage of the API from Google Dashboard.", "translatepress-multilingual"); ?>
102
  <?php __("Response:", "translatepress-multilingual"); ?>
103
  <?php __("Response Body:", "translatepress-multilingual"); ?>
104
  <?php __("Entire Response From wp_remote_get():", "translatepress-multilingual"); ?>
138
  <?php __("Batch size", "translatepress-multilingual"); ?>
139
  <?php __("The number of rows to check at once.<br>Choosing a smaller number helps solve the 502 error \"Page took too long to respond\" on large databases.<br>May take several minutes depending on the database size.", "translatepress-multilingual"); ?>
140
  <?php __("Remove duplicate rows", "translatepress-multilingual"); ?>
 
 
 
languages/translatepress-multilingual.pot CHANGED
@@ -21,7 +21,7 @@ msgstr ""
21
  msgid "Limit this menu item to the following languages"
22
  msgstr ""
23
 
24
- #: ../tp-add-on-seo-pack/class-seo-pack.php:155
25
  msgid "The Yoast SEO Sitemaps will now contain the default language slug: example.com/en/sitemap_index.xml <br/> This works perfectly, just take it into account when you submit the sitemap to Google."
26
  msgstr ""
27
 
@@ -45,23 +45,23 @@ msgstr ""
45
  msgid "<div class=\"warning\">WARNING. Cannot determine your language preference based on your current IP.<br>This is most likely because the website is on a local environment.</div>"
46
  msgstr ""
47
 
48
- #: partials/license-settings-page.php:4, ../tp-add-on-browse-as-other-roles/partials/license-settings-page.php:4, ../tp-add-on-extra-languages/partials/license-settings-page.php:4, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:4, ../tp-add-on-seo-pack/partials/license-settings-page.php:4, ../translatepress/partials/addons-settings-page.php:3, ../translatepress/partials/main-settings-page.php:5, ../translatepress/partials/test-google-key-settings-page.php:17, ../translatepress/partials/trp-remove-duplicate-rows.php:3, ../trp-add-on-translator-accounts-add-on/partials/license-settings-page.php:4
49
  msgid "TranslatePress Settings"
50
  msgstr ""
51
 
52
- #: partials/license-settings-page.php:10, ../tp-add-on-browse-as-other-roles/partials/license-settings-page.php:10, ../tp-add-on-extra-languages/partials/license-settings-page.php:10, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:10, ../tp-add-on-seo-pack/partials/license-settings-page.php:10, ../trp-add-on-translator-accounts-add-on/partials/license-settings-page.php:10
53
  msgid "License Key"
54
  msgstr ""
55
 
56
- #: partials/license-settings-page.php:15, ../tp-add-on-browse-as-other-roles/partials/license-settings-page.php:15, ../tp-add-on-extra-languages/partials/license-settings-page.php:15, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:15, ../tp-add-on-seo-pack/partials/license-settings-page.php:15, ../trp-add-on-translator-accounts-add-on/partials/license-settings-page.php:15
57
  msgid "Enter your license key."
58
  msgstr ""
59
 
60
- #: partials/license-settings-page.php:22, partials/license-settings-page.php:31, ../tp-add-on-browse-as-other-roles/partials/license-settings-page.php:22, ../tp-add-on-browse-as-other-roles/partials/license-settings-page.php:31, ../tp-add-on-extra-languages/partials/license-settings-page.php:22, ../tp-add-on-extra-languages/partials/license-settings-page.php:31, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:22, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:31, ../tp-add-on-seo-pack/partials/license-settings-page.php:22, ../tp-add-on-seo-pack/partials/license-settings-page.php:31, ../trp-add-on-translator-accounts-add-on/partials/license-settings-page.php:22, ../trp-add-on-translator-accounts-add-on/partials/license-settings-page.php:31
61
  msgid "Activate License"
62
  msgstr ""
63
 
64
- #: partials/license-settings-page.php:28, ../tp-add-on-browse-as-other-roles/partials/license-settings-page.php:28, ../tp-add-on-extra-languages/partials/license-settings-page.php:28, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:28, ../tp-add-on-seo-pack/partials/license-settings-page.php:28, ../trp-add-on-translator-accounts-add-on/partials/license-settings-page.php:28
65
  msgid "Deactivate License"
66
  msgstr ""
67
 
@@ -121,79 +121,79 @@ msgstr ""
121
  msgid "Redirect users to their preferred language based on their browser language or IP address using our new <a href=\"https://translatepress.com/docs/addons/automatic-user-language-detection/\" >Automatic User Language Detection Add-on</a>."
122
  msgstr ""
123
 
124
- #: ../translatepress/includes/class-settings.php:25
125
  msgid "Full Language Names"
126
  msgstr ""
127
 
128
- #: ../translatepress/includes/class-settings.php:26
129
  msgid "Short Language Names"
130
  msgstr ""
131
 
132
- #: ../translatepress/includes/class-settings.php:27
133
  msgid "Flags with Full Language Names"
134
  msgstr ""
135
 
136
- #: ../translatepress/includes/class-settings.php:28
137
  msgid "Flags with Short Language Names"
138
  msgstr ""
139
 
140
- #: ../translatepress/includes/class-settings.php:29
141
  msgid "Only Flags"
142
  msgstr ""
143
 
144
- #: ../translatepress/includes/class-settings.php:119
145
  msgid "Done."
146
  msgstr ""
147
 
148
- #: ../translatepress/includes/class-settings.php:119, ../translatepress/includes/class-settings.php:124
149
  msgid "Back to TranslatePress Settings page"
150
  msgstr ""
151
 
152
- #: ../translatepress/includes/class-settings.php:124
153
  msgid "Invalid nonce."
154
  msgstr ""
155
 
156
- #: ../translatepress/includes/class-settings.php:144
157
  msgid "Querying table <strong>%s</strong>"
158
  msgstr ""
159
 
160
- #: ../translatepress/includes/class-settings.php:174
161
  msgid "%s duplicates removed"
162
  msgstr ""
163
 
164
- #: ../translatepress/includes/class-settings.php:204
165
  msgid "If the page does not redirect automatically"
166
  msgstr ""
167
 
168
- #: ../translatepress/includes/class-settings.php:204
169
  msgid "click here"
170
  msgstr ""
171
 
172
- #: ../translatepress/includes/class-settings.php:447
173
  msgid "Current Language"
174
  msgstr ""
175
 
176
- #: ../translatepress/includes/class-settings.php:488
177
  msgid "General"
178
  msgstr ""
179
 
180
- #: ../translatepress/includes/class-settings.php:493, ../translatepress/includes/class-translation-manager.php:626
181
  msgid "Translate Site"
182
  msgstr ""
183
 
184
- #: ../translatepress/includes/class-settings.php:501
185
  msgid "License"
186
  msgstr ""
187
 
188
- #: ../translatepress/includes/class-settings.php:507
189
  msgid "Addons"
190
  msgstr ""
191
 
192
- #: ../translatepress/includes/class-settings.php:532, ../translatepress/includes/class-translation-manager.php:657
193
  msgid "Settings"
194
  msgstr ""
195
 
196
- #: ../translatepress/includes/class-settings.php:536
197
  msgid "Pro Features"
198
  msgstr ""
199
 
@@ -229,47 +229,47 @@ msgstr ""
229
  msgid "Dynamic Added Strings"
230
  msgstr ""
231
 
232
- #: ../translatepress/includes/class-translation-manager.php:638
233
  msgid "Translate Page"
234
  msgstr ""
235
 
236
- #: ../translatepress/includes/class-translation-manager.php:1125
237
  msgid "Security check"
238
  msgstr ""
239
 
240
- #: ../translatepress/includes/class-translation-render.php:159
241
  msgid "Description"
242
  msgstr ""
243
 
244
- #: ../translatepress/includes/class-translation-render.php:165
245
  msgid "OG Title"
246
  msgstr ""
247
 
248
- #: ../translatepress/includes/class-translation-render.php:171
249
  msgid "OG Site Name"
250
  msgstr ""
251
 
252
- #: ../translatepress/includes/class-translation-render.php:177
253
  msgid "OG Description"
254
  msgstr ""
255
 
256
- #: ../translatepress/includes/class-translation-render.php:183
257
  msgid "Twitter Title"
258
  msgstr ""
259
 
260
- #: ../translatepress/includes/class-translation-render.php:189
261
  msgid "Twitter Description"
262
  msgstr ""
263
 
264
- #: ../translatepress/includes/class-translation-render.php:195
265
  msgid "Post Slug"
266
  msgstr ""
267
 
268
- #: ../translatepress/includes/class-translation-render.php:199
269
  msgid "Page Title"
270
  msgstr ""
271
 
272
- #: ../translatepress/includes/functions.php:192
273
  msgid "<strong>TranslatePress</strong> requires <strong><a href=\"http://php.net/manual/en/book.mbstring.php\">Multibyte String PHP library</a></strong>. Please contact your server administrator to install it on your server."
274
  msgstr ""
275
 
@@ -358,58 +358,70 @@ msgid "Google Translate API Key"
358
  msgstr ""
359
 
360
  #: ../translatepress/partials/main-settings-page.php:92
361
- msgid "Test api key"
362
  msgstr ""
363
 
364
  #: ../translatepress/partials/main-settings-page.php:94
365
- msgid "Visit this <a href=\"https://cloud.google.com/docs/authentication/api-keys\" target=\"_blank\">link</a> to see how you can set up an API key. "
366
  msgstr ""
367
 
368
- #: ../translatepress/partials/main-settings-page.php:101
 
 
 
 
369
  msgid "Language Switcher"
370
  msgstr ""
371
 
372
- #: ../translatepress/partials/main-settings-page.php:104
373
  msgid "Shortcode "
374
  msgstr ""
375
 
376
- #: ../translatepress/partials/main-settings-page.php:109
377
  msgid "Use shortcode on any page or widget."
378
  msgstr ""
379
 
380
- #: ../translatepress/partials/main-settings-page.php:113
381
  msgid "Menu item"
382
  msgstr ""
383
 
384
- #: ../translatepress/partials/main-settings-page.php:121
385
  msgid "Go to %1$s Appearance -> Menus%2$s to add Language Switcher Languages in any menu."
386
  msgstr ""
387
 
388
- #: ../translatepress/partials/main-settings-page.php:122
389
  msgid "Learn more in our documentation."
390
  msgstr ""
391
 
392
- #: ../translatepress/partials/main-settings-page.php:126
393
  msgid "Floating language selection"
394
  msgstr ""
395
 
396
- #: ../translatepress/partials/main-settings-page.php:131
397
  msgid "Have a floating dropdown following the user on every page."
398
  msgstr ""
399
 
400
- #: ../translatepress/partials/test-google-key-settings-page.php:22
401
  msgid "Google API Key from settings page:"
402
  msgstr ""
403
 
404
- #: ../translatepress/partials/test-google-key-settings-page.php:24
 
 
 
 
 
 
 
 
405
  msgid "Response:"
406
  msgstr ""
407
 
408
- #: ../translatepress/partials/test-google-key-settings-page.php:28
409
  msgid "Response Body:"
410
  msgstr ""
411
 
412
- #: ../translatepress/partials/test-google-key-settings-page.php:33
413
  msgid "Entire Response From wp_remote_get():"
414
  msgstr ""
415
 
@@ -558,15 +570,3 @@ msgstr ""
558
  #: ../translatepress/partials/trp-remove-duplicate-rows.php:28
559
  msgid "Remove duplicate rows"
560
  msgstr ""
561
-
562
- #: ../trp-add-on-translator-accounts-add-on/includes/class-translator-accounts.php:119
563
- msgid " TranslatePress Settings"
564
- msgstr ""
565
-
566
- #: ../trp-add-on-translator-accounts-add-on/includes/class-translator-accounts.php:123, ../trp-add-on-translator-accounts-add-on/includes/class-translator-accounts.php:124
567
- msgid "Translator"
568
- msgstr ""
569
-
570
- #: ../trp-add-on-translator-accounts-add-on/includes/class-translator-accounts.php:128
571
- msgid "Allow this user to translate the website."
572
- msgstr ""
21
  msgid "Limit this menu item to the following languages"
22
  msgstr ""
23
 
24
+ #: ../tp-add-on-seo-pack/class-seo-pack.php:158
25
  msgid "The Yoast SEO Sitemaps will now contain the default language slug: example.com/en/sitemap_index.xml <br/> This works perfectly, just take it into account when you submit the sitemap to Google."
26
  msgstr ""
27
 
45
  msgid "<div class=\"warning\">WARNING. Cannot determine your language preference based on your current IP.<br>This is most likely because the website is on a local environment.</div>"
46
  msgstr ""
47
 
48
+ #: partials/license-settings-page.php:4, ../tp-add-on-extra-languages/partials/license-settings-page.php:4, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:4, ../tp-add-on-seo-pack/partials/license-settings-page.php:4, ../translatepress/partials/addons-settings-page.php:3, ../translatepress/partials/main-settings-page.php:5, ../translatepress/partials/test-google-key-settings-page.php:10, ../translatepress/partials/trp-remove-duplicate-rows.php:3
49
  msgid "TranslatePress Settings"
50
  msgstr ""
51
 
52
+ #: partials/license-settings-page.php:10, ../tp-add-on-extra-languages/partials/license-settings-page.php:10, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:10, ../tp-add-on-seo-pack/partials/license-settings-page.php:10
53
  msgid "License Key"
54
  msgstr ""
55
 
56
+ #: partials/license-settings-page.php:15, ../tp-add-on-extra-languages/partials/license-settings-page.php:15, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:15, ../tp-add-on-seo-pack/partials/license-settings-page.php:15
57
  msgid "Enter your license key."
58
  msgstr ""
59
 
60
+ #: partials/license-settings-page.php:22, partials/license-settings-page.php:31, ../tp-add-on-extra-languages/partials/license-settings-page.php:22, ../tp-add-on-extra-languages/partials/license-settings-page.php:31, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:22, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:31, ../tp-add-on-seo-pack/partials/license-settings-page.php:22, ../tp-add-on-seo-pack/partials/license-settings-page.php:31
61
  msgid "Activate License"
62
  msgstr ""
63
 
64
+ #: partials/license-settings-page.php:28, ../tp-add-on-extra-languages/partials/license-settings-page.php:28, ../tp-add-on-navigation-based-on-language/partials/license-settings-page.php:28, ../tp-add-on-seo-pack/partials/license-settings-page.php:28
65
  msgid "Deactivate License"
66
  msgstr ""
67
 
121
  msgid "Redirect users to their preferred language based on their browser language or IP address using our new <a href=\"https://translatepress.com/docs/addons/automatic-user-language-detection/\" >Automatic User Language Detection Add-on</a>."
122
  msgstr ""
123
 
124
+ #: ../translatepress/includes/class-settings.php:26
125
  msgid "Full Language Names"
126
  msgstr ""
127
 
128
+ #: ../translatepress/includes/class-settings.php:27
129
  msgid "Short Language Names"
130
  msgstr ""
131
 
132
+ #: ../translatepress/includes/class-settings.php:28
133
  msgid "Flags with Full Language Names"
134
  msgstr ""
135
 
136
+ #: ../translatepress/includes/class-settings.php:29
137
  msgid "Flags with Short Language Names"
138
  msgstr ""
139
 
140
+ #: ../translatepress/includes/class-settings.php:30
141
  msgid "Only Flags"
142
  msgstr ""
143
 
144
+ #: ../translatepress/includes/class-settings.php:124
145
  msgid "Done."
146
  msgstr ""
147
 
148
+ #: ../translatepress/includes/class-settings.php:124, ../translatepress/includes/class-settings.php:129
149
  msgid "Back to TranslatePress Settings page"
150
  msgstr ""
151
 
152
+ #: ../translatepress/includes/class-settings.php:129
153
  msgid "Invalid nonce."
154
  msgstr ""
155
 
156
+ #: ../translatepress/includes/class-settings.php:149
157
  msgid "Querying table <strong>%s</strong>"
158
  msgstr ""
159
 
160
+ #: ../translatepress/includes/class-settings.php:179
161
  msgid "%s duplicates removed"
162
  msgstr ""
163
 
164
+ #: ../translatepress/includes/class-settings.php:209
165
  msgid "If the page does not redirect automatically"
166
  msgstr ""
167
 
168
+ #: ../translatepress/includes/class-settings.php:209
169
  msgid "click here"
170
  msgstr ""
171
 
172
+ #: ../translatepress/includes/class-settings.php:452
173
  msgid "Current Language"
174
  msgstr ""
175
 
176
+ #: ../translatepress/includes/class-settings.php:493
177
  msgid "General"
178
  msgstr ""
179
 
180
+ #: ../translatepress/includes/class-settings.php:498, ../translatepress/includes/class-translation-manager.php:617
181
  msgid "Translate Site"
182
  msgstr ""
183
 
184
+ #: ../translatepress/includes/class-settings.php:506
185
  msgid "License"
186
  msgstr ""
187
 
188
+ #: ../translatepress/includes/class-settings.php:512
189
  msgid "Addons"
190
  msgstr ""
191
 
192
+ #: ../translatepress/includes/class-settings.php:537, ../translatepress/includes/class-translation-manager.php:648
193
  msgid "Settings"
194
  msgstr ""
195
 
196
+ #: ../translatepress/includes/class-settings.php:541
197
  msgid "Pro Features"
198
  msgstr ""
199
 
229
  msgid "Dynamic Added Strings"
230
  msgstr ""
231
 
232
+ #: ../translatepress/includes/class-translation-manager.php:629
233
  msgid "Translate Page"
234
  msgstr ""
235
 
236
+ #: ../translatepress/includes/class-translation-manager.php:1141
237
  msgid "Security check"
238
  msgstr ""
239
 
240
+ #: ../translatepress/includes/class-translation-render.php:161
241
  msgid "Description"
242
  msgstr ""
243
 
244
+ #: ../translatepress/includes/class-translation-render.php:167
245
  msgid "OG Title"
246
  msgstr ""
247
 
248
+ #: ../translatepress/includes/class-translation-render.php:173
249
  msgid "OG Site Name"
250
  msgstr ""
251
 
252
+ #: ../translatepress/includes/class-translation-render.php:179
253
  msgid "OG Description"
254
  msgstr ""
255
 
256
+ #: ../translatepress/includes/class-translation-render.php:185
257
  msgid "Twitter Title"
258
  msgstr ""
259
 
260
+ #: ../translatepress/includes/class-translation-render.php:191
261
  msgid "Twitter Description"
262
  msgstr ""
263
 
264
+ #: ../translatepress/includes/class-translation-render.php:197
265
  msgid "Post Slug"
266
  msgstr ""
267
 
268
+ #: ../translatepress/includes/class-translation-render.php:201
269
  msgid "Page Title"
270
  msgstr ""
271
 
272
+ #: ../translatepress/includes/functions.php:216
273
  msgid "<strong>TranslatePress</strong> requires <strong><a href=\"http://php.net/manual/en/book.mbstring.php\">Multibyte String PHP library</a></strong>. Please contact your server administrator to install it on your server."
274
  msgstr ""
275
 
358
  msgstr ""
359
 
360
  #: ../translatepress/partials/main-settings-page.php:92
361
+ msgid "Test API key"
362
  msgstr ""
363
 
364
  #: ../translatepress/partials/main-settings-page.php:94
365
+ msgid "Visit <a href=\"https://cloud.google.com/docs/authentication/api-keys\" target=\"_blank\">this link</a> to see how you can set up an API key, <strong>control API costs</strong> and set HTTP referrer restrictions."
366
  msgstr ""
367
 
368
+ #: ../translatepress/partials/main-settings-page.php:95
369
+ msgid "<br>Your HTTP referrer is: %s"
370
+ msgstr ""
371
+
372
+ #: ../translatepress/partials/main-settings-page.php:102
373
  msgid "Language Switcher"
374
  msgstr ""
375
 
376
+ #: ../translatepress/partials/main-settings-page.php:105
377
  msgid "Shortcode "
378
  msgstr ""
379
 
380
+ #: ../translatepress/partials/main-settings-page.php:110
381
  msgid "Use shortcode on any page or widget."
382
  msgstr ""
383
 
384
+ #: ../translatepress/partials/main-settings-page.php:114
385
  msgid "Menu item"
386
  msgstr ""
387
 
388
+ #: ../translatepress/partials/main-settings-page.php:122
389
  msgid "Go to %1$s Appearance -> Menus%2$s to add Language Switcher Languages in any menu."
390
  msgstr ""
391
 
392
+ #: ../translatepress/partials/main-settings-page.php:123
393
  msgid "Learn more in our documentation."
394
  msgstr ""
395
 
396
+ #: ../translatepress/partials/main-settings-page.php:127
397
  msgid "Floating language selection"
398
  msgstr ""
399
 
400
+ #: ../translatepress/partials/main-settings-page.php:132
401
  msgid "Have a floating dropdown following the user on every page."
402
  msgstr ""
403
 
404
+ #: ../translatepress/partials/test-google-key-settings-page.php:15
405
  msgid "Google API Key from settings page:"
406
  msgstr ""
407
 
408
+ #: ../translatepress/partials/test-google-key-settings-page.php:17
409
+ msgid "HTTP Referrer:"
410
+ msgstr ""
411
+
412
+ #: ../translatepress/partials/test-google-key-settings-page.php:18
413
+ msgid "Use this HTTP Referrer if you want to restrict usage of the API from Google Dashboard."
414
+ msgstr ""
415
+
416
+ #: ../translatepress/partials/test-google-key-settings-page.php:20
417
  msgid "Response:"
418
  msgstr ""
419
 
420
+ #: ../translatepress/partials/test-google-key-settings-page.php:24
421
  msgid "Response Body:"
422
  msgstr ""
423
 
424
+ #: ../translatepress/partials/test-google-key-settings-page.php:29
425
  msgid "Entire Response From wp_remote_get():"
426
  msgstr ""
427
 
570
  #: ../translatepress/partials/trp-remove-duplicate-rows.php:28
571
  msgid "Remove duplicate rows"
572
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
partials/main-settings-page.php CHANGED
@@ -36,7 +36,7 @@
36
  <tr>
37
  <th scope="row"><?php _e( 'Native language name', 'translatepress-multilingual' ); ?> </th>
38
  <td>
39
- <select id="trp-g-translate" name="trp_settings[native_or_english_name]" class="trp-select">
40
  <option value="english_name" <?php selected( $this->settings['native_or_english_name'], 'english_name' ); ?>><?php _e( 'No', 'translatepress-multilingual') ?></option>
41
  <option value="native_name" <?php selected( $this->settings['native_or_english_name'], 'native_name' ); ?>><?php _e( 'Yes', 'translatepress-multilingual') ?></option>
42
  </select>
@@ -49,7 +49,7 @@
49
  <tr>
50
  <th scope="row"><?php _e( 'Use subdirectory for default language', 'translatepress-multilingual' ); ?> </th>
51
  <td>
52
- <select id="trp-g-translate" name="trp_settings[add-subdirectory-to-default-language]" class="trp-select">
53
  <option value="no" <?php selected( $this->settings['add-subdirectory-to-default-language'], 'no' ); ?>><?php _e( 'No', 'translatepress-multilingual') ?></option>
54
  <option value="yes" <?php selected( $this->settings['add-subdirectory-to-default-language'], 'yes' ); ?>><?php _e( 'Yes', 'translatepress-multilingual') ?></option>
55
  </select>
@@ -62,7 +62,7 @@
62
  <tr>
63
  <th scope="row"><?php _e( 'Force language in custom links', 'translatepress-multilingual' ); ?> </th>
64
  <td>
65
- <select id="trp-g-translate" name="trp_settings[force-language-to-custom-links]" class="trp-select">
66
  <option value="no" <?php selected( $this->settings['force-language-to-custom-links'], 'no' ); ?>><?php _e( 'No', 'translatepress-multilingual') ?></option>
67
  <option value="yes" <?php selected( $this->settings['force-language-to-custom-links'], 'yes' ); ?>><?php _e( 'Yes', 'translatepress-multilingual') ?></option>
68
  </select>
@@ -89,9 +89,10 @@
89
  <th scope="row"><?php _e( 'Google Translate API Key', 'translatepress-multilingual' ); ?> </th>
90
  <td>
91
  <input type="text" id="trp-g-translate-key" class="trp-text-input" name="trp_settings[g-translate-key]" value="<?php if( !empty( $this->settings['g-translate-key'] ) ) echo esc_attr( $this->settings['g-translate-key']);?>"/>
92
- <?php if( !empty( $this->settings['g-translate-key'] ) ) echo '<a href="'.admin_url( 'admin.php?page=trp_test_google_key_page' ).'">'.__( "Test api key", 'translatepress-multilingual' ).'</a>'; ?>
93
  <p class="description">
94
- <?php _e( 'Visit this <a href="https://cloud.google.com/docs/authentication/api-keys" target="_blank">link</a> to see how you can set up an API key. ', 'translatepress-multilingual' ); ?>
 
95
  </p>
96
  </td>
97
 
36
  <tr>
37
  <th scope="row"><?php _e( 'Native language name', 'translatepress-multilingual' ); ?> </th>
38
  <td>
39
+ <select id="trp-native-language-name" name="trp_settings[native_or_english_name]" class="trp-select">
40
  <option value="english_name" <?php selected( $this->settings['native_or_english_name'], 'english_name' ); ?>><?php _e( 'No', 'translatepress-multilingual') ?></option>
41
  <option value="native_name" <?php selected( $this->settings['native_or_english_name'], 'native_name' ); ?>><?php _e( 'Yes', 'translatepress-multilingual') ?></option>
42
  </select>
49
  <tr>
50
  <th scope="row"><?php _e( 'Use subdirectory for default language', 'translatepress-multilingual' ); ?> </th>
51
  <td>
52
+ <select id="trp-subdirectory-for-default-language" name="trp_settings[add-subdirectory-to-default-language]" class="trp-select">
53
  <option value="no" <?php selected( $this->settings['add-subdirectory-to-default-language'], 'no' ); ?>><?php _e( 'No', 'translatepress-multilingual') ?></option>
54
  <option value="yes" <?php selected( $this->settings['add-subdirectory-to-default-language'], 'yes' ); ?>><?php _e( 'Yes', 'translatepress-multilingual') ?></option>
55
  </select>
62
  <tr>
63
  <th scope="row"><?php _e( 'Force language in custom links', 'translatepress-multilingual' ); ?> </th>
64
  <td>
65
+ <select id="trp-force-language-in-custom-links" name="trp_settings[force-language-to-custom-links]" class="trp-select">
66
  <option value="no" <?php selected( $this->settings['force-language-to-custom-links'], 'no' ); ?>><?php _e( 'No', 'translatepress-multilingual') ?></option>
67
  <option value="yes" <?php selected( $this->settings['force-language-to-custom-links'], 'yes' ); ?>><?php _e( 'Yes', 'translatepress-multilingual') ?></option>
68
  </select>
89
  <th scope="row"><?php _e( 'Google Translate API Key', 'translatepress-multilingual' ); ?> </th>
90
  <td>
91
  <input type="text" id="trp-g-translate-key" class="trp-text-input" name="trp_settings[g-translate-key]" value="<?php if( !empty( $this->settings['g-translate-key'] ) ) echo esc_attr( $this->settings['g-translate-key']);?>"/>
92
+ <?php if( !empty( $this->settings['g-translate-key'] ) ) echo '<a href="'.admin_url( 'admin.php?page=trp_test_google_key_page' ).'">'.__( "Test API key", 'translatepress-multilingual' ).'</a>'; ?>
93
  <p class="description">
94
+ <?php _e( 'Visit <a href="https://cloud.google.com/docs/authentication/api-keys" target="_blank">this link</a> to see how you can set up an API key, <strong>control API costs</strong> and set HTTP referrer restrictions.', 'translatepress-multilingual' ); ?>
95
+ <?php echo sprintf( __( '<br>Your HTTP referrer is: %s', 'translatepress-multilingual' ), $gtranslate_referer ); ?>
96
  </p>
97
  </td>
98
 
partials/test-google-key-settings-page.php CHANGED
@@ -1,16 +1,9 @@
1
  <?php
2
- $translation_request = 'key='.$this->settings['g-translate-key'];
3
- $translation_request .= '&source=en';
4
- $translation_request .= '&target=es';
5
- $translation_request .= '&q=about';
6
-
7
-
8
- /* Due to url length restrictions we need so send a POST request faked as a GET request and send the strings in the body of the request and not in the URL */
9
- $response = wp_remote_post( "https://www.googleapis.com/language/translate/v2", array(
10
- 'headers' => array( 'X-HTTP-Method-Override' => 'GET' ),//this fakes a GET request
11
- 'body' => $translation_request,
12
- )
13
- );
14
  ?>
15
  <div id="trp-addons-page" class="wrap">
16
 
@@ -19,7 +12,10 @@ $response = wp_remote_post( "https://www.googleapis.com/language/translate/v2",
19
 
20
  <div class="grid feat-header">
21
  <div class="grid-cell">
22
- <h2><?php _e('Google API Key from settings page:', 'translatepress-multilingual');?> <span style="font-family:monospace"><?php echo $this->settings['g-translate-key']; ?></span></h2>
 
 
 
23
 
24
  <h3><?php _e('Response:', 'translatepress-multilingual');?></h3>
25
  <pre>
1
  <?php
2
+
3
+ $trp = TRP_Translate_Press::get_trp_instance();
4
+ $machine_translator = $trp->get_component( 'machine_translator' );
5
+ $response = $machine_translator->send_request( 'en', 'es', array( 'about' ) );
6
+
 
 
 
 
 
 
 
7
  ?>
8
  <div id="trp-addons-page" class="wrap">
9
 
12
 
13
  <div class="grid feat-header">
14
  <div class="grid-cell">
15
+ <h2><?php _e('Google API Key from settings page:', 'translatepress-multilingual');?> <span style="font-family:monospace"><?php echo esc_html( $this->settings['g-translate-key'] ); ?></span></h2>
16
+
17
+ <h2><?php _e('HTTP Referrer:', 'translatepress-multilingual');?> <span style="font-family:monospace"><?php echo esc_url( $machine_translator->get_referer() ); ?></span></h2>
18
+ <p><?php _e('Use this HTTP Referrer if you want to restrict usage of the API from Google Dashboard.', 'translatepress-multilingual'); ?></p>
19
 
20
  <h3><?php _e('Response:', 'translatepress-multilingual');?></h3>
21
  <pre>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.cozmoslabs.com/
4
  Tags: translate, translation, multilingual, automatic translation, bilingual, front-end translation, google translate, language
5
  Requires at least: 3.1.0
6
  Tested up to: 4.9.8
7
- Stable tag: 1.3.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -124,6 +124,18 @@ For more information please check out [TranslatePress - Multilingual plugin docu
124
  6. Menu Language Switcher
125
 
126
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
127
  = 1.3.5 =
128
  * Fixed translation problems introduced in the last two versions
129
  * Added a console message when trp-ajax request uses fall back to admin ajax for debugging purposes.
4
  Tags: translate, translation, multilingual, automatic translation, bilingual, front-end translation, google translate, language
5
  Requires at least: 3.1.0
6
  Tested up to: 4.9.8
7
+ Stable tag: 1.3.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
124
  6. Menu Language Switcher
125
 
126
  == Changelog ==
127
+ = 1.3.6 =
128
+ * Refactored the get_url_for_language() function which should fix a lot of problems with links
129
+ * Speed improvements
130
+ * Fixed translation block icon when creating a new block
131
+ * Fixed issues with trp tags leftovers in html
132
+ * Fixed issues with gettext strings that weren't detected correctly
133
+ * Add support for relative url's
134
+ * Added warning in settings about controlling costs of Google API
135
+ * Changed API key field description. Added feature to show/hide API key field based on Google Translate Active Yes/No
136
+ * Fixed Translated-dom-changes string not translated through trp-ajax.
137
+ * Fixed 400 errors in google translate API
138
+
139
  = 1.3.5 =
140
  * Fixed translation problems introduced in the last two versions
141
  * Added a console message when trp-ajax request uses fall back to admin ajax for debugging purposes.