Weglot Translate – Translate your WP website - Version 3.0.0

Version Description

(16/04/2019) = * New major version * Link between WordPress options and Weglot dashboard options * Bugfix: Fixed an error on the JSON translation

Download this release

Release Info

Developer remyb92
Plugin Icon 128x128 Weglot Translate – Translate your WP website
Version 3.0.0
Comparing to
See all releases

Code changes from version 2.7.0 to 3.0.0

Files changed (96) hide show
  1. app/javascripts/index.js +0 -2
  2. app/javascripts/nav.js +6 -4
  3. app/javascripts/settings/admin-button-preview.js +2 -2
  4. app/javascripts/settings/admin-check-api-key.js +47 -22
  5. app/javascripts/settings/admin-exclusion.js +2 -2
  6. app/javascripts/settings/admin-prevent-save-form.js +0 -32
  7. app/javascripts/settings/admin-private-mode.js +2 -1
  8. app/javascripts/settings/admin-select.js +1 -2
  9. bootstrap.php +4 -0
  10. composer.json +3 -2
  11. dist/admin-js.js +1 -1
  12. dist/css/admin-css.css +0 -3
  13. dist/metaboxes-js.js +1 -1
  14. dist/nav-js.js +1 -1
  15. readme.txt +7 -2
  16. src/actions/admin/class-admin-enqueue-weglot.php +8 -8
  17. src/actions/admin/class-ajax-user-info.php +52 -0
  18. src/actions/admin/class-customize-menu-weglot.php +17 -4
  19. src/actions/admin/class-metabox-url-translate-weglot.php +1 -0
  20. src/actions/admin/class-options-weglot.php +101 -116
  21. src/actions/admin/class-pages-weglot.php +2 -0
  22. src/actions/class-migration-weglot.php +8 -7
  23. src/actions/front/class-clean-options.php +39 -0
  24. src/actions/front/class-front-menu-weglot.php +78 -14
  25. src/actions/front/class-translate-page-weglot.php +3 -3
  26. src/helpers/class-helper-api.php +54 -0
  27. src/helpers/class-helper-excluded-type.php +50 -0
  28. src/helpers/class-helper-filter-url-weglot.php +20 -2
  29. src/helpers/class-helper-flag-type.php +86 -0
  30. src/helpers/class-helper-keys-json-weglot.php +1 -0
  31. src/models/class-schema-option-migration-v3.php +88 -0
  32. src/models/class-schema-option-v3.php +110 -0
  33. src/services/class-button-service-weglot.php +14 -11
  34. src/services/class-custom-url-service-weglot.php +1 -1
  35. src/services/class-email-translate-service-weglot.php +3 -2
  36. src/services/class-generate-switcher-service-weglot.php +1 -48
  37. src/services/class-language-service-weglot.php +9 -4
  38. src/services/class-migration-service-weglot.php +3 -78
  39. src/services/class-option-service-weglot.php +369 -41
  40. src/services/class-other-translate-service-weglot.php +8 -2
  41. src/services/class-parser-service-weglot.php +22 -2
  42. src/services/class-private-language-service-weglot.php +10 -2
  43. src/services/class-request-url-service-weglot.php +34 -44
  44. src/services/class-translate-json-service.php +2 -2
  45. src/services/class-translate-service-weglot.php +1 -1
  46. src/services/class-user-api-service-weglot.php +13 -13
  47. src/third/calderaforms/class-caldera-translate.php +2 -2
  48. src/third/gravityforms/class-gf-active.php +34 -0
  49. src/third/gravityforms/class-gf-filter-urls.php +54 -0
  50. src/third/ninjaforms/class-ninja-translate-json-weglot.php +11 -2
  51. src/third/woocommerce/class-wc-translate-weglot.php +11 -3
  52. templates/admin/pages/settings.php +11 -2
  53. templates/admin/pages/tabs/advanced.php +140 -90
  54. templates/admin/pages/tabs/appearance.php +29 -10
  55. templates/admin/pages/tabs/custom-urls.php +4 -4
  56. templates/admin/pages/tabs/settings.php +33 -32
  57. vendor/autoload.php +1 -1
  58. vendor/composer/autoload_psr4.php +1 -0
  59. vendor/composer/autoload_real.php +7 -7
  60. vendor/composer/autoload_static.php +12 -4
  61. vendor/composer/installed.json +43 -6
  62. vendor/gmulti/morphism-php/.gitignore +2 -0
  63. vendor/gmulti/morphism-php/.travis.yml +14 -0
  64. vendor/gmulti/morphism-php/LICENSE +21 -0
  65. vendor/gmulti/morphism-php/README.md +238 -0
  66. vendor/gmulti/morphism-php/composer.json +20 -0
  67. vendor/gmulti/morphism-php/lib/Helpers/MorphismHelper.php +91 -0
  68. vendor/gmulti/morphism-php/lib/Morphism.php +86 -0
  69. vendor/gmulti/morphism-php/phpunit.xml.dist +7 -0
  70. vendor/gmulti/morphism-php/tests/Mocks/User.php +5 -0
  71. vendor/gmulti/morphism-php/tests/MorphismArrayTest.php +112 -0
  72. vendor/gmulti/morphism-php/tests/MorphismTest.php +91 -0
  73. vendor/weglot/weglot-php/CHANGELOG.md +6 -0
  74. vendor/weglot/weglot-php/src/Client/Client.php +3 -2
  75. vendor/weglot/weglot-php/src/Client/Profile.php +15 -13
  76. vendor/weglot/weglot-php/src/Parser/Check/Dom/Text.php +5 -5
  77. vendor/weglot/weglot-php/src/Parser/Check/DomCheckerProvider.php +243 -16
  78. vendor/weglot/weglot-php/src/Parser/Formatter/DomFormatter.php +42 -10
  79. vendor/weglot/weglot-php/src/Parser/Parser.php +3 -3
  80. vendor/weglot/weglot-php/src/Util/Regex.php +49 -0
  81. vendor/weglot/weglot-php/src/Util/Regex/RegexEnum.php +38 -0
  82. vendor/weglot/weglot-php/tests/unit/Client/ClientCachingTest.php +1 -1
  83. vendor/weglot/weglot-php/tests/unit/Client/ClientTest.php +3 -4
  84. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/CachedTranslateTest.php +1 -1
  85. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/LanguagesTest.php +1 -1
  86. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/StatusTest.php +1 -1
  87. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/TranslateTest.php +1 -1
  88. vendor/weglot/weglot-php/tests/unit/Parser/Check/Dom/MetaContentTest.php +3 -2
  89. vendor/weglot/weglot-php/tests/unit/Parser/ParserTest.php +65 -1
  90. vendor/weglot/weglot-php/tests/unit/Parser/tests_parser_1.json +162 -0
  91. vendor/weglot/weglot-php/tests/unit/Parser/tests_parser_2.json +176 -0
  92. vendor/weglot/weglot-php/tests/unit/Parser/tests_parser_3.json +358 -0
  93. vendor/weglot/weglot-php/tests/unit/Util/RegexTest.php +81 -0
  94. weglot-compatibility.php +35 -6
  95. weglot-functions.php +3 -2
  96. weglot.php +5 -4
app/javascripts/index.js CHANGED
@@ -4,7 +4,6 @@ import InitAdminExclusion from './settings/admin-exclusion'
4
  import InitAdminButtonPreview from './settings/admin-button-preview'
5
  import InitAdminCheckApiKey from './settings/admin-check-api-key'
6
  import InitAdminChangeCountry from './settings/admin-change-country'
7
- import InitAdminPreventSaveForm from './settings/admin-prevent-save-form'
8
  import InitAdminPrivateMode from './settings/admin-private-mode'
9
  import './find-polyfill'
10
  import './filter-polyfill'
@@ -15,5 +14,4 @@ InitAdminWeglotBox();
15
  InitAdminButtonPreview();
16
  InitAdminCheckApiKey();
17
  InitAdminChangeCountry();
18
- InitAdminPreventSaveForm();
19
  InitAdminPrivateMode();
4
  import InitAdminButtonPreview from './settings/admin-button-preview'
5
  import InitAdminCheckApiKey from './settings/admin-check-api-key'
6
  import InitAdminChangeCountry from './settings/admin-change-country'
 
7
  import InitAdminPrivateMode from './settings/admin-private-mode'
8
  import './find-polyfill'
9
  import './filter-polyfill'
14
  InitAdminButtonPreview();
15
  InitAdminCheckApiKey();
16
  InitAdminChangeCountry();
 
17
  InitAdminPrivateMode();
app/javascripts/nav.js CHANGED
@@ -1,5 +1,6 @@
1
  jQuery(document).ready(function ($) {
2
  $('#update-nav-menu').bind('click', function (e) {
 
3
  if (e.target && e.target.className && -1 != e.target.className.indexOf('item-edit')) {
4
 
5
  $("input[value='#weglot_switcher'][type=text]").parents('.menu-item-settings').each(function () {
@@ -22,8 +23,8 @@ jQuery(document).ready(function ($) {
22
 
23
  $(this).append($('<input>').attr({
24
  type: 'hidden',
25
- id: 'edit-menu-item-pll-detect-' + id,
26
- name: 'menu-item-pll-detect[' + id + ']',
27
  value: 1
28
  }));
29
 
@@ -42,13 +43,14 @@ jQuery(document).ready(function ($) {
42
  id: `edit-menu-item-${
43
  option.key
44
  }-${id}`,
45
- name: `menu-item-${
46
  option.key
47
  }[${id}]`,
48
  value: 1
49
  });
50
 
51
- if( weglot_data.options[ option.key ] === 1 ){
 
52
  checkbox.prop("checked", true);
53
  }
54
 
1
  jQuery(document).ready(function ($) {
2
  $('#update-nav-menu').bind('click', function (e) {
3
+
4
  if (e.target && e.target.className && -1 != e.target.className.indexOf('item-edit')) {
5
 
6
  $("input[value='#weglot_switcher'][type=text]").parents('.menu-item-settings').each(function () {
23
 
24
  $(this).append($('<input>').attr({
25
  type: 'hidden',
26
+ id: 'edit-menu-item-weglot-detect-' + id,
27
+ name: 'menu-item-weglot-detect[' + id + ']',
28
  value: 1
29
  }));
30
 
43
  id: `edit-menu-item-${
44
  option.key
45
  }-${id}`,
46
+ name: `menu-item-weglot-${
47
  option.key
48
  }[${id}]`,
49
  value: 1
50
  });
51
 
52
+
53
+ if (weglot_data.options && weglot_data.options[`menu-item-${id}`] && weglot_data.options[`menu-item-${id}`][ option.key ] === 1 ){
54
  checkbox.prop("checked", true);
55
  }
56
 
app/javascripts/settings/admin-button-preview.js CHANGED
@@ -3,7 +3,7 @@ const init_admin_button_preview = function () {
3
 
4
  const execute = () => {
5
  // Init old type flags
6
- let old_type_flags = $("#type_flags").val()
7
 
8
  let destination_languages = []
9
  destination_languages.push($(".country-selector label").data("code-language"));
@@ -31,7 +31,7 @@ const init_admin_button_preview = function () {
31
  // Change type flags
32
  $("#type_flags").on("change", function(e) {
33
  $(".country-selector label, .country-selector li").removeClass(`flag-${old_type_flags}`);
34
- const new_type_flags = e.target.value;
35
  $(".country-selector label, .country-selector li").addClass(`flag-${new_type_flags}`);
36
  old_type_flags = new_type_flags;
37
  });
3
 
4
  const execute = () => {
5
  // Init old type flags
6
+ let old_type_flags = $("#type_flags option:selected").data('value')
7
 
8
  let destination_languages = []
9
  destination_languages.push($(".country-selector label").data("code-language"));
31
  // Change type flags
32
  $("#type_flags").on("change", function(e) {
33
  $(".country-selector label, .country-selector li").removeClass(`flag-${old_type_flags}`);
34
+ const new_type_flags = $(':selected', this).data('value')
35
  $(".country-selector label, .country-selector li").addClass(`flag-${new_type_flags}`);
36
  old_type_flags = new_type_flags;
37
  });
app/javascripts/settings/admin-check-api-key.js CHANGED
@@ -3,36 +3,61 @@ const init_admin_button_preview = function () {
3
 
4
  const execute = () => {
5
 
6
- $("#api_key").blur(function() {
7
  var key = $(this).val();
8
  if( key.length === 0){
9
  $(".weglot-keyres").remove();
10
- $("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>');
11
  $("#wrap-weglot #submit").prop("disabled", true);
12
  return;
13
  }
14
- $.getJSON(
15
- "https://weglot.com/api/user-info?api_key=" + key,
16
- (data) => {
17
- $(".weglot-keyres").remove();
18
- $("#api_key").after(
19
- '<span class="weglot-keyres weglot-okkey"></span>'
20
- );
21
- $("#wrap-weglot #submit").prop(
22
- "disabled",
23
- false
24
- );
25
-
26
- const evt = new CustomEvent("weglotCheckApi", {
27
- detail: data
28
- });
29
-
30
- window.dispatchEvent(evt);
31
- }
32
- ).fail(function() {
 
 
33
  $(".weglot-keyres").remove();
34
- $("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>');
35
  $("#wrap-weglot #submit").prop("disabled", true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  });
37
  });
38
  }
3
 
4
  const execute = () => {
5
 
6
+ $("#api_key_private").blur(function() {
7
  var key = $(this).val();
8
  if( key.length === 0){
9
  $(".weglot-keyres").remove();
10
+ $("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>');
11
  $("#wrap-weglot #submit").prop("disabled", true);
12
  return;
13
  }
14
+
15
+ function validApiKey(response){
16
+
17
+ $(".weglot-keyres").remove();
18
+ $("#api_key_private").after(
19
+ '<span class="weglot-keyres weglot-okkey"></span>'
20
+ );
21
+
22
+ $("#wrap-weglot #submit").prop(
23
+ "disabled",
24
+ false
25
+ );
26
+
27
+ const evt = new CustomEvent("weglotCheckApi", {
28
+ detail: response
29
+ });
30
+
31
+ window.dispatchEvent(evt);
32
+ }
33
+
34
+ function unvalidApiKey(){
35
  $(".weglot-keyres").remove();
36
+ $("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>');
37
  $("#wrap-weglot #submit").prop("disabled", true);
38
+ }
39
+
40
+ $.ajax(
41
+ {
42
+ method: 'POST',
43
+ url: ajaxurl,
44
+ data : {
45
+ action: 'get_user_info',
46
+ api_key: key,
47
+ },
48
+ success: ({data, success}) => {
49
+
50
+ if (success ){
51
+ validApiKey(data)
52
+ }
53
+ else{
54
+ unvalidApiKey()
55
+ }
56
+
57
+ }
58
+ }
59
+ ).fail(function() {
60
+ unvalidApiKey()
61
  });
62
  });
63
  }
app/javascripts/settings/admin-exclusion.js CHANGED
@@ -1,5 +1,4 @@
1
  const init_admin_exclusion = function () {
2
- const $ = jQuery
3
 
4
  const execute = () => {
5
  const template_add_exclude_url = document.querySelector("#tpl-exclusion-url");
@@ -18,7 +17,8 @@ const init_admin_exclusion = function () {
18
  .querySelector("#js-add-exclude-url")
19
  .addEventListener("click", (e) => {
20
  e.preventDefault()
21
- parent_exclude_url_append.insertAdjacentHTML("beforeend", template_add_exclude_url.innerHTML);
 
22
  document
23
  .querySelector(
24
  "#container-exclude_urls .item-exclude:last-child .js-btn-remove"
1
  const init_admin_exclusion = function () {
 
2
 
3
  const execute = () => {
4
  const template_add_exclude_url = document.querySelector("#tpl-exclusion-url");
17
  .querySelector("#js-add-exclude-url")
18
  .addEventListener("click", (e) => {
19
  e.preventDefault()
20
+ const random_key = Math.random().toString(36).substring(7);
21
+ parent_exclude_url_append.insertAdjacentHTML("beforeend", template_add_exclude_url.innerHTML.replace(new RegExp('{KEY}', 'g'), random_key));
22
  document
23
  .querySelector(
24
  "#container-exclude_urls .item-exclude:last-child .js-btn-remove"
app/javascripts/settings/admin-prevent-save-form.js DELETED
@@ -1,32 +0,0 @@
1
- const init_prevent_save_form = function () {
2
- /* TODO : remove file
3
- const $ = jQuery
4
-
5
- const execute = () => {
6
-
7
- let warning = false;
8
- $(document).on({
9
- change: () => warning = true,
10
- keyup: () => warning = true
11
- }, "input[type='text'], select, textarea, input[type='checkbox']")
12
-
13
- $("input[type='submit']").on("click", (e) => {
14
- warning = false
15
- })
16
-
17
- window.onbeforeunload = function () {
18
- if (warning) {
19
- return "You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will lose your unsaved changes";
20
- }
21
- }
22
-
23
- }
24
-
25
- document.addEventListener('DOMContentLoaded', () => {
26
- execute();
27
- })
28
- */
29
- }
30
-
31
- export default init_prevent_save_form;
32
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/javascripts/settings/admin-private-mode.js CHANGED
@@ -20,7 +20,8 @@ const init_private_mode = function () {
20
  }
21
 
22
  document.addEventListener('DOMContentLoaded', () => {
23
- if (document.querySelector('#private_mode').length != 0){
 
24
  execute();
25
  }
26
  })
20
  }
21
 
22
  document.addEventListener('DOMContentLoaded', () => {
23
+ const private_mode = document.querySelector("#private_mode")
24
+ if (private_mode && private_mode.length != 0){
25
  execute();
26
  }
27
  })
app/javascripts/settings/admin-select.js CHANGED
@@ -123,9 +123,8 @@ const init_admin_select = function(){
123
  load_destination_selectize();
124
 
125
  window.addEventListener("weglotCheckApi", (data) => {
126
-
127
  let limit = 1000
128
- const plan = data.detail.answer.plan
129
 
130
  if (
131
  plan <= 0 ||
123
  load_destination_selectize();
124
 
125
  window.addEventListener("weglotCheckApi", (data) => {
 
126
  let limit = 1000
127
+ const plan = data.detail.plan
128
 
129
  if (
130
  plan <= 0 ||
bootstrap.php CHANGED
@@ -53,6 +53,7 @@ abstract class Context_Weglot {
53
  '\WeglotWP\Third\Amp\Amp_Service_Weglot',
54
  '\WeglotWP\Third\CalderaForms\Caldera_Translate',
55
  '\WeglotWP\Third\CalderaForms\Caldera_Active',
 
56
  '\WeglotWP\Services\User_Api_Service_Weglot',
57
  '\WeglotWP\Services\Other_Translate_Service_Weglot',
58
  '\WeglotWP\Services\Dom_Checkers_Service_Weglot',
@@ -83,6 +84,7 @@ abstract class Context_Weglot {
83
  '\WeglotWP\Actions\Front\Redirect_Log_User_Weglot',
84
  '\WeglotWP\Actions\Migration_Weglot',
85
  '\WeglotWP\Third\Woocommerce\WC_Filter_Urls_Weglot',
 
86
  '\WeglotWP\Third\Woocommerce\WC_Cart_Reload_Weglot',
87
  '\WeglotWP\Third\CalderaForms\Caldera_I18n_Inline',
88
  '\WeglotWP\Third\Amp\Amp_Enqueue_Weglot',
@@ -90,6 +92,8 @@ abstract class Context_Weglot {
90
  '\WeglotWP\Actions\Front\Front_Menu_Weglot',
91
  '\WeglotWP\Actions\Front\Search_Weglot',
92
  '\WeglotWP\Actions\Front\Redirect_Comment',
 
 
93
  ];
94
 
95
  self::$context->set_actions( $actions );
53
  '\WeglotWP\Third\Amp\Amp_Service_Weglot',
54
  '\WeglotWP\Third\CalderaForms\Caldera_Translate',
55
  '\WeglotWP\Third\CalderaForms\Caldera_Active',
56
+ '\WeglotWP\Third\Gravityforms\GF_Active',
57
  '\WeglotWP\Services\User_Api_Service_Weglot',
58
  '\WeglotWP\Services\Other_Translate_Service_Weglot',
59
  '\WeglotWP\Services\Dom_Checkers_Service_Weglot',
84
  '\WeglotWP\Actions\Front\Redirect_Log_User_Weglot',
85
  '\WeglotWP\Actions\Migration_Weglot',
86
  '\WeglotWP\Third\Woocommerce\WC_Filter_Urls_Weglot',
87
+ '\WeglotWP\Third\Gravityforms\GF_Filter_Urls',
88
  '\WeglotWP\Third\Woocommerce\WC_Cart_Reload_Weglot',
89
  '\WeglotWP\Third\CalderaForms\Caldera_I18n_Inline',
90
  '\WeglotWP\Third\Amp\Amp_Enqueue_Weglot',
92
  '\WeglotWP\Actions\Front\Front_Menu_Weglot',
93
  '\WeglotWP\Actions\Front\Search_Weglot',
94
  '\WeglotWP\Actions\Front\Redirect_Comment',
95
+ '\WeglotWP\Actions\Admin\Ajax_User_Info',
96
+ '\WeglotWP\Actions\Front\Clean_Options',
97
  ];
98
 
99
  self::$context->set_actions( $actions );
composer.json CHANGED
@@ -13,8 +13,9 @@
13
  }
14
  ],
15
  "require": {
16
- "weglot/weglot-php": "0.5.20",
17
- "galbar/jsonpath": "dev-master"
 
18
  },
19
  "require-dev": {
20
  "squizlabs/php_codesniffer": "*",
13
  }
14
  ],
15
  "require": {
16
+ "weglot/weglot-php": "^0.5",
17
+ "galbar/jsonpath": "dev-master",
18
+ "gmulti/morphism-php": "^0.3.0"
19
  },
20
  "require-dev": {
21
  "squizlabs/php_codesniffer": "*",
dist/admin-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function o(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)o.d(n,a,function(t){return e[t]}.bind(null,a));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/dist/",o(o.s=5)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var n=arguments[1],a=0;a<o;){var l=t[a];if(e.call(n,l,a,t))return l;a++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var o=this.length>>>0,n=new Array(o),a=this,l=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(a[r],r,a)&&(n[l++]=a[r]);else for(;++r!==o;)r in this&&e.call(t,a[r],r,a)&&(n[l++]=a[r]);return n.length=l,n})},,,,function(e,t,o){"use strict";o.r(t);var n=function(){const e=jQuery,t=()=>weglot_languages.available.filter(e=>e.code!==weglot_languages.original);let o;const n=()=>{let n=e("#original_language").val();e("#original_language").on("change",function(t){const a=n,l=n;n=t.target.value,o[0].selectize.removeOption(n);const r=weglot_languages.available.find(e=>e.code===l),s=weglot_languages.available.find(e=>e.code===n);o[0].selectize.addOption(r);const c=e("#is_fullname").is(":checked");let i="";e("#with_name").is(":checked")&&(i=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(a).addClass(n).attr("data-code-language",n).find("span").html(i)}),o=e(".weglot-select-destination").selectize({delimiter:"|",persist:!1,valueField:"code",labelField:"local",searchField:["code","english","local"],sortField:[{field:"english",direction:"asc"}],maxItems:weglot_languages.limit,plugins:["remove_button","drag_drop"],options:t(),render:{option:function(e,t){return'<div class="weglot__choice__language"><span class="weglot__choice__language--english">'+t(e.english)+'</span><span class="weglot__choice__language--local">'+t(e.local)+" ["+t(e.code)+"]</span></div>"}}}).on("change",t=>{const n=o[0].selectize.getValue(),a=e("#li-button-tpl");if(0===a.length)return;const l=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked"),s=e("#with_flags").is(":checked");let c="";s&&(c="weglot-flags");let i="";n.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=l?t.local:e.toUpperCase()),i+=a.html().replace("{LABEL_LANGUAGE}",o).replace(new RegExp("{CODE_LANGUAGE}","g"),e).replace("{CLASSES}",c)}),e(".country-selector ul").html(i)}),window.addEventListener("weglotCheckApi",e=>{let t=1e3;const n=e.detail.answer.plan;n<=0||weglot_languages.plans.starter_free.ids.indexOf(n)>=0?t=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(n)>=0&&(t=weglot_languages.plans.business.limit_language),o[0].selectize.settings.maxItems=t})};document.addEventListener("DOMContentLoaded",()=>{n()})};var a=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{e("#weglot-box-first-settings .weglot-btn-close").on("click",function(t){t.preventDefault(),e("#weglot-box-first-settings").hide()})})};var l=function(){jQuery;const e=()=>{const e=document.querySelector("#tpl-exclusion-url"),t=document.querySelector("#tpl-exclusion-block"),o=document.querySelector("#container-exclude_urls"),n=document.querySelector("#container-exclude_blocks");function a(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-url")&&document.querySelector("#js-add-exclude-url").addEventListener("click",t=>{t.preventDefault(),o.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_urls .item-exclude:last-child .js-btn-remove").addEventListener("click",a)}),document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",e=>{e.preventDefault(),n.insertAdjacentHTML("beforeend",t.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",a)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",a)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&(()=>{let t=e("#type_flags").val(),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,n)=>{o.push(e(n).data("code-language"))});const n=weglot_languages.available.filter(e=>o.indexOf(e.code)>=0);e("#weglot-css-inline").text(weglot_css.inline),e("#is_dropdown").on("change",function(){e(".country-selector").toggleClass("weglot-inline"),e(".country-selector").toggleClass("weglot-dropdown")}),e("#with_flags").on("change",function(){e(".country-selector label, .country-selector li").toggleClass("weglot-flags")}),e("#type_flags").on("change",function(o){e(".country-selector label, .country-selector li").removeClass(`flag-${t}`);const n=o.target.value;e(".country-selector label, .country-selector li").addClass(`flag-${n}`),t=n});const a=()=>{const t=n.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),a=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(a),e(".country-selector li").each((t,a)=>{const l=n.find(t=>t.code===e(a).data("code-language")),r=o?l.local:l.code.toUpperCase();e(a).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?a():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)a();else{const t=n.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const a=n.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(a.code.toUpperCase()),e(o).find("span").text(a.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})})()})};var s=function(){const e=jQuery,t=()=>{e("#api_key").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);e.getJSON("https://weglot.com/api/user-info?api_key="+t,t=>{e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}).fail(function(){e(".weglot-keyres").remove(),e("#api_key").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type").on("change",function(){!function(){var t=new Array,o=new Array,n=new Array,a=new Array,l=new Array;t[1]=[3570,7841,48,2712],t[2]=[3720,449,3048,4440],t[3]=[3840,1281,2712,4224],t[4]=[3240,5217,1224,2112],t[5]=[4050,3585,1944,2496],t[6]=[2340,3457,2016,2016],o[1]=[4320,4641,3144,3552],o[2]=[3750,353,2880,4656],o[3]=[4200,1601,2568,3192],o[4]=[3990,5793,1032,2232],o[5]=[5460,897,4104,3120],o[6]=[3810,7905,216,3888],o[7]=[3630,8065,192,2376],o[8]=[3780,1473,2496,4104],o[9]=[6120,2145,4680,2568],o[10]=[4440,3009,3240,1176],o[11]=[5280,1825,3936,2976],o[12]=[4770,2081,3624,1008],o[13]=[4080,3201,2160,2544],o[14]=[4590,5761,3432,624],o[15]=[4350,2209,3360,2688],o[16]=[5610,5249,3168,528],o[17]=[5070,1729,3792,2952],o[18]=[6870,5953,96,3408],o[19]=[4020,5697,1056,1224],n[1]=[1740,5921,528,3504],a[1]=[2760,736,2856,4416],a[2]=[3840,1280,2712,4224],a[3]=[5700,7201,5016,2400],a[4]=[2220,4160,1632,1944],l[1]=[1830,129,3096,5664],l[2]=[5100,2177,3840,2904],l[3]=[4890,3425,3648,2136],l[4]=[1320,3681,1896,4080],l[5]=[1260,3841,1824,1200],l[6]=[1020,3969,1608,312],l[7]=[4800,4065,3600,72],l[8]=[4710,4865,3504,480],l[9]=[6720,5984,5112,3792],l[10]=[4500,7233,3288,1800],l[11]=[720,7522,384,3936],l[12]=[690,7745,336,1104],l[13]=[600,8225,120,1272],l[14]=[660,5569,840,576];var r=e("select.flag-en-type").val(),s=e("select.flag-es-type").val(),c=e("select.flag-pt-type").val(),i=e("select.flag-fr-type").val(),g=e("select.flag-ar-type").val(),f=r<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[r][0]+"px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[r][1]+"px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[r][2]+"px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[r][3]+"px 0 !important; } ",u=s<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[s][0]+"px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[s][1]+"px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[s][2]+"px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[s][3]+"px 0 !important; } ",d=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+n[c][0]+"px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+n[c][1]+"px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+n[c][2]+"px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+n[c][3]+"px 0 !important; } ",p=i<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[i][0]+"px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[i][1]+"px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[i][2]+"px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[i][3]+"px 0 !important; } ",w=g<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+l[g][0]+"px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+l[g][1]+"px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+l[g][2]+"px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+l[g][3]+"px 0 !important; } ";e("#flag_css, #weglot-css-flag-css").text(f+u+d+p+w)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var i=function(){};var g=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{0!=document.querySelector("#private_mode").length&&(document.querySelector("#private_mode").addEventListener("change",function(e){document.querySelectorAll(".private-mode-lang--input").forEach(t=>{t.checked=e.target.checked})}),document.querySelectorAll(".private-mode-lang--input").forEach(e=>{e.addEventListener("change",function(e){0===document.querySelectorAll(".private-mode-lang--input:checked").length&&(document.querySelector("#private_mode").checked=!1)})}))})};o(0),o(1);n(),l(),a(),r(),s(),c(),i(),g()}]);
1
+ !function(e){var t={};function o(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)o.d(n,a,function(t){return e[t]}.bind(null,a));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/dist/",o(o.s=5)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),o=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var n=arguments[1],a=0;a<o;){var l=t[a];if(e.call(n,l,a,t))return l;a++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var o=this.length>>>0,n=new Array(o),a=this,l=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(a[r],r,a)&&(n[l++]=a[r]);else for(;++r!==o;)r in this&&e.call(t,a[r],r,a)&&(n[l++]=a[r]);return n.length=l,n})},,,,function(e,t,o){"use strict";o.r(t);var n=function(){const e=jQuery,t=()=>weglot_languages.available.filter(e=>e.code!==weglot_languages.original);let o;const n=()=>{let n=e("#original_language").val();e("#original_language").on("change",function(t){const a=n,l=n;n=t.target.value,o[0].selectize.removeOption(n);const r=weglot_languages.available.find(e=>e.code===l),s=weglot_languages.available.find(e=>e.code===n);o[0].selectize.addOption(r);const c=e("#is_fullname").is(":checked");let i="";e("#with_name").is(":checked")&&(i=c?s.local:s.code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(a).addClass(n).attr("data-code-language",n).find("span").html(i)}),o=e(".weglot-select-destination").selectize({delimiter:"|",persist:!1,valueField:"code",labelField:"local",searchField:["code","english","local"],sortField:[{field:"english",direction:"asc"}],maxItems:weglot_languages.limit,plugins:["remove_button","drag_drop"],options:t(),render:{option:function(e,t){return'<div class="weglot__choice__language"><span class="weglot__choice__language--english">'+t(e.english)+'</span><span class="weglot__choice__language--local">'+t(e.local)+" ["+t(e.code)+"]</span></div>"}}}).on("change",t=>{const n=o[0].selectize.getValue(),a=e("#li-button-tpl");if(0===a.length)return;const l=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked"),s=e("#with_flags").is(":checked");let c="";s&&(c="weglot-flags");let i="";n.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=l?t.local:e.toUpperCase()),i+=a.html().replace("{LABEL_LANGUAGE}",o).replace(new RegExp("{CODE_LANGUAGE}","g"),e).replace("{CLASSES}",c)}),e(".country-selector ul").html(i)}),window.addEventListener("weglotCheckApi",e=>{let t=1e3;const n=e.detail.plan;n<=0||weglot_languages.plans.starter_free.ids.indexOf(n)>=0?t=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(n)>=0&&(t=weglot_languages.plans.business.limit_language),o[0].selectize.settings.maxItems=t})};document.addEventListener("DOMContentLoaded",()=>{n()})};var a=function(){const e=jQuery;document.addEventListener("DOMContentLoaded",()=>{e("#weglot-box-first-settings .weglot-btn-close").on("click",function(t){t.preventDefault(),e("#weglot-box-first-settings").hide()})})};var l=function(){const e=()=>{const e=document.querySelector("#tpl-exclusion-url"),t=document.querySelector("#tpl-exclusion-block"),o=document.querySelector("#container-exclude_urls"),n=document.querySelector("#container-exclude_blocks");function a(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-url")&&document.querySelector("#js-add-exclude-url").addEventListener("click",t=>{t.preventDefault();const n=Math.random().toString(36).substring(7);o.insertAdjacentHTML("beforeend",e.innerHTML.replace(new RegExp("{KEY}","g"),n)),document.querySelector("#container-exclude_urls .item-exclude:last-child .js-btn-remove").addEventListener("click",a)}),document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",e=>{e.preventDefault(),n.insertAdjacentHTML("beforeend",t.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",a)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",a)})};document.addEventListener("DOMContentLoaded",()=>{e()})};var r=function(){const e=jQuery,t=()=>{let t=e("#type_flags option:selected").data("value"),o=[];o.push(e(".country-selector label").data("code-language")),e(".country-selector li").each((t,n)=>{o.push(e(n).data("code-language"))});const n=weglot_languages.available.filter(e=>o.indexOf(e.code)>=0);e("#weglot-css-inline").text(weglot_css.inline),e("#is_dropdown").on("change",function(){e(".country-selector").toggleClass("weglot-inline"),e(".country-selector").toggleClass("weglot-dropdown")}),e("#with_flags").on("change",function(){e(".country-selector label, .country-selector li").toggleClass("weglot-flags")}),e("#type_flags").on("change",function(o){e(".country-selector label, .country-selector li").removeClass(`flag-${t}`);const n=e(":selected",this).data("value");e(".country-selector label, .country-selector li").addClass(`flag-${n}`),t=n});const a=()=>{const t=n.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),a=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(a),e(".country-selector li").each((t,a)=>{const l=n.find(t=>t.code===e(a).data("code-language")),r=o?l.local:l.code.toUpperCase();e(a).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?a():(e(".country-selector label a, .country-selector label span").text(""),e(".country-selector li a, .country-selector li span").each((t,o)=>{e(o).text("")}))}),e("#is_fullname").on("change",function(t){if(e("#with_name").is(":checked"))if(t.target.checked)a();else{const t=n.find(t=>t.code===e(".country-selector label").data("code-language"));e(".country-selector label a, .country-selector label span").text(t.code.toUpperCase()),e(".country-selector li").each((t,o)=>{const a=n.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(a.code.toUpperCase()),e(o).find("span").text(a.code.toUpperCase())})}}),e("#override_css").on("keyup",function(t){e("#weglot-css-inline").text(t.target.value)})};document.addEventListener("DOMContentLoaded",()=>{0!==e(".weglot-preview").length&&t()})};var s=function(){const e=jQuery,t=()=>{e("#api_key_private").blur(function(){var t=e(this).val();if(0===t.length)return e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>'),void e("#wrap-weglot #submit").prop("disabled",!0);function o(){e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!0)}e.ajax({method:"POST",url:ajaxurl,data:{action:"get_user_info",api_key:t},success:({data:t,success:n})=>{n?function(t){e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-okkey"></span>'),e("#wrap-weglot #submit").prop("disabled",!1);const o=new CustomEvent("weglotCheckApi",{detail:t});window.dispatchEvent(o)}(t):o()}}).fail(function(){o()})})};document.addEventListener("DOMContentLoaded",()=>{t()})};var c=function(){const e=jQuery;"undefined"!=typeof weglot_css&&e("#weglot-css-flag-css").text(weglot_css.flag_css);const t=()=>{e(".flag-style-openclose").on("click",function(){e(".flag-style-wrapper").toggle()}),e("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type").on("change",function(){!function(){var t=new Array,o=new Array,n=new Array,a=new Array,l=new Array;t[1]=[3570,7841,48,2712],t[2]=[3720,449,3048,4440],t[3]=[3840,1281,2712,4224],t[4]=[3240,5217,1224,2112],t[5]=[4050,3585,1944,2496],t[6]=[2340,3457,2016,2016],o[1]=[4320,4641,3144,3552],o[2]=[3750,353,2880,4656],o[3]=[4200,1601,2568,3192],o[4]=[3990,5793,1032,2232],o[5]=[5460,897,4104,3120],o[6]=[3810,7905,216,3888],o[7]=[3630,8065,192,2376],o[8]=[3780,1473,2496,4104],o[9]=[6120,2145,4680,2568],o[10]=[4440,3009,3240,1176],o[11]=[5280,1825,3936,2976],o[12]=[4770,2081,3624,1008],o[13]=[4080,3201,2160,2544],o[14]=[4590,5761,3432,624],o[15]=[4350,2209,3360,2688],o[16]=[5610,5249,3168,528],o[17]=[5070,1729,3792,2952],o[18]=[6870,5953,96,3408],o[19]=[4020,5697,1056,1224],n[1]=[1740,5921,528,3504],a[1]=[2760,736,2856,4416],a[2]=[3840,1280,2712,4224],a[3]=[5700,7201,5016,2400],a[4]=[2220,4160,1632,1944],l[1]=[1830,129,3096,5664],l[2]=[5100,2177,3840,2904],l[3]=[4890,3425,3648,2136],l[4]=[1320,3681,1896,4080],l[5]=[1260,3841,1824,1200],l[6]=[1020,3969,1608,312],l[7]=[4800,4065,3600,72],l[8]=[4710,4865,3504,480],l[9]=[6720,5984,5112,3792],l[10]=[4500,7233,3288,1800],l[11]=[720,7522,384,3936],l[12]=[690,7745,336,1104],l[13]=[600,8225,120,1272],l[14]=[660,5569,840,576];var r=e("select.flag-en-type").val(),s=e("select.flag-es-type").val(),c=e("select.flag-pt-type").val(),i=e("select.flag-fr-type").val(),g=e("select.flag-ar-type").val(),f=r<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[r][0]+"px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[r][1]+"px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[r][2]+"px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[r][3]+"px 0 !important; } ",u=s<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[s][0]+"px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[s][1]+"px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[s][2]+"px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[s][3]+"px 0 !important; } ",d=c<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+n[c][0]+"px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+n[c][1]+"px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+n[c][2]+"px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+n[c][3]+"px 0 !important; } ",p=i<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[i][0]+"px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[i][1]+"px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[i][2]+"px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[i][3]+"px 0 !important; } ",b=g<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+l[g][0]+"px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+l[g][1]+"px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+l[g][2]+"px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+l[g][3]+"px 0 !important; } ";e("#flag_css, #weglot-css-flag-css").text(f+u+d+p+b)}()})};document.addEventListener("DOMContentLoaded",()=>{t()})};var i=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector("#private_mode");e&&0!=e.length&&(document.querySelector("#private_mode").addEventListener("change",function(e){document.querySelectorAll(".private-mode-lang--input").forEach(t=>{t.checked=e.target.checked})}),document.querySelectorAll(".private-mode-lang--input").forEach(e=>{e.addEventListener("change",function(e){0===document.querySelectorAll(".private-mode-lang--input:checked").length&&(document.querySelector("#private_mode").checked=!1)})}))})};o(0),o(1);n(),l(),a(),r(),s(),c(),i()}]);
dist/css/admin-css.css CHANGED
@@ -437,9 +437,6 @@ input[type="text"], .wg-input-textarea {
437
  .wg-input-textarea::-webkit-input-placeholder {
438
  color: #ccc; }
439
 
440
- .wg-input-textarea:-ms-input-placeholder {
441
- color: #ccc; }
442
-
443
  .wg-input-textarea::-ms-input-placeholder {
444
  color: #ccc; }
445
 
437
  .wg-input-textarea::-webkit-input-placeholder {
438
  color: #ccc; }
439
 
 
 
 
440
  .wg-input-textarea::-ms-input-placeholder {
441
  color: #ccc; }
442
 
dist/metaboxes-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function n(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(a,o,function(t){return e[t]}.bind(null,o));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=6)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var a=arguments[1],o=0;o<n;){var r=t[o];if(e.call(a,r,o,t))return r;o++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var n=this.length>>>0,a=new Array(n),o=this,r=0,i=-1;if(void 0===t)for(;++i!==n;)i in this&&e(o[i],i,o)&&(a[r++]=o[i]);else for(;++i!==n;)i in this&&e.call(t,o[i],i,o)&&(a[r++]=o[i]);return a.length=r,a})},function(e,t,n){var a;a=function(){var e=JSON.parse('{"$":"dollar","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I","į":"i","İ":"I","ı":"i","Ķ":"k","ķ":"k","Ļ":"L","ļ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ř":"R","ř":"r","Ś":"S","ś":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ũ":"U","ũ":"u","Ū":"u","ū":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Lj":"LJ","lj":"lj","Nj":"NJ","nj":"nj","Ș":"S","ș":"s","Ț":"T","ț":"t","˚":"o","Ά":"A","Έ":"E","Ή":"H","Ί":"I","Ό":"O","Ύ":"Y","Ώ":"W","ΐ":"i","Α":"A","Β":"B","Γ":"G","Δ":"D","Ε":"E","Ζ":"Z","Η":"H","Θ":"8","Ι":"I","Κ":"K","Λ":"L","Μ":"M","Ν":"N","Ξ":"3","Ο":"O","Π":"P","Ρ":"R","Σ":"S","Τ":"T","Υ":"Y","Φ":"F","Χ":"X","Ψ":"PS","Ω":"W","Ϊ":"I","Ϋ":"Y","ά":"a","έ":"e","ή":"h","ί":"i","ΰ":"y","α":"a","β":"b","γ":"g","δ":"d","ε":"e","ζ":"z","η":"h","θ":"8","ι":"i","κ":"k","λ":"l","μ":"m","ν":"n","ξ":"3","ο":"o","π":"p","ρ":"r","ς":"s","σ":"s","τ":"t","υ":"y","φ":"f","χ":"x","ψ":"ps","ω":"w","ϊ":"i","ϋ":"y","ό":"o","ύ":"y","ώ":"w","Ё":"Yo","Ђ":"DJ","Є":"Ye","І":"I","Ї":"Yi","Ј":"J","Љ":"LJ","Њ":"NJ","Ћ":"C","Џ":"DZ","А":"A","Б":"B","В":"V","Г":"G","Д":"D","Е":"E","Ж":"Zh","З":"Z","И":"I","Й":"J","К":"K","Л":"L","М":"M","Н":"N","О":"O","П":"P","Р":"R","С":"S","Т":"T","У":"U","Ф":"F","Х":"H","Ц":"C","Ч":"Ch","Ш":"Sh","Щ":"Sh","Ъ":"U","Ы":"Y","Ь":"","Э":"E","Ю":"Yu","Я":"Ya","а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ж":"zh","з":"z","и":"i","й":"j","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"ch","ш":"sh","щ":"sh","ъ":"u","ы":"y","ь":"","э":"e","ю":"yu","я":"ya","ё":"yo","ђ":"dj","є":"ye","і":"i","ї":"yi","ј":"j","љ":"lj","њ":"nj","ћ":"c","џ":"dz","Ґ":"G","ґ":"g","฿":"baht","ა":"a","ბ":"b","გ":"g","დ":"d","ე":"e","ვ":"v","ზ":"z","თ":"t","ი":"i","კ":"k","ლ":"l","მ":"m","ნ":"n","ო":"o","პ":"p","ჟ":"zh","რ":"r","ს":"s","ტ":"t","უ":"u","ფ":"f","ქ":"k","ღ":"gh","ყ":"q","შ":"sh","ჩ":"ch","ც":"ts","ძ":"dz","წ":"ts","ჭ":"ch","ხ":"kh","ჯ":"j","ჰ":"h","ẞ":"SS","Ạ":"A","ạ":"a","Ả":"A","ả":"a","Ấ":"A","ấ":"a","Ầ":"A","ầ":"a","Ẩ":"A","ẩ":"a","Ẫ":"A","ẫ":"a","Ậ":"A","ậ":"a","Ắ":"A","ắ":"a","Ằ":"A","ằ":"a","Ẳ":"A","ẳ":"a","Ẵ":"A","ẵ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ẻ":"E","ẻ":"e","Ẽ":"E","ẽ":"e","Ế":"E","ế":"e","Ề":"E","ề":"e","Ể":"E","ể":"e","Ễ":"E","ễ":"e","Ệ":"E","ệ":"e","Ỉ":"I","ỉ":"i","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ỏ":"O","ỏ":"o","Ố":"O","ố":"o","Ồ":"O","ồ":"o","Ổ":"O","ổ":"o","Ỗ":"O","ỗ":"o","Ộ":"O","ộ":"o","Ớ":"O","ớ":"o","Ờ":"O","ờ":"o","Ở":"O","ở":"o","Ỡ":"O","ỡ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ủ":"U","ủ":"u","Ứ":"U","ứ":"u","Ừ":"U","ừ":"u","Ử":"U","ử":"u","Ữ":"U","ữ":"u","Ự":"U","ự":"u","Ỳ":"Y","ỳ":"y","Ỵ":"Y","ỵ":"y","Ỷ":"Y","ỷ":"y","Ỹ":"Y","ỹ":"y","‘":"\'","’":"\'","“":"\\"","”":"\\"","†":"+","•":"*","…":"...","₠":"ecu","₢":"cruzeiro","₣":"french franc","₤":"lira","₥":"mill","₦":"naira","₧":"peseta","₨":"rupee","₩":"won","₪":"new shequel","₫":"dong","€":"euro","₭":"kip","₮":"tugrik","₯":"drachma","₰":"penny","₱":"peso","₲":"guarani","₳":"austral","₴":"hryvnia","₵":"cedi","₹":"indian rupee","₽":"russian ruble","℠":"sm","™":"tm","∂":"d","∆":"delta","∑":"sum","∞":"infinity","♥":"love","元":"yuan","円":"yen","﷼":"rial"}');function t(t,n){if("string"!=typeof t)throw new Error("slugify: string argument expected");n="string"==typeof n?{replacement:n}:n||{};var a=t.split("").reduce(function(t,a){return t+(e[a]||a).replace(n.remove||/[^\w\s$*_+~.()'"!\-:@]/g,"")},"").trim().replace(/[-\s]+/g,n.replacement||"-").replace("#{replacement}$","");return n.lower?a.toLowerCase():a}return t.extend=function(t){for(var n in t)e[n]=t[n]},t},e.exports=a(),e.exports.default=a()},,,,function(e,t,n){"use strict";n.r(t);n(0),n(1);var a=n(2),o=n.n(a);(()=>{const e=jQuery,t=()=>{let t={};const n=function(n){const a=e(this).data("lang"),r=o()(e(`#lang-${a}`).val(),{lower:!0,replacement:"-"});e(`#text-edit-${a}`).text(r),e(`#lang-${a}`).hide(),e(this).hide(),e(`.button-weglot-lang[data-lang=${a}]`).show(),e.ajax({url:ajaxurl,method:"POST",data:{action:"weglot_post_name",lang:a,id:e("#weglot_post_id").data("id"),post_name:r},success:function(n){if(n.data&&n.data.code&&"same_post_name"===n.data.code)return e(`#text-edit-${a}`).text(t[a]),void e(`#lang-${a}`).val("");n.data&&n.data.code&&"not_available"===n.data.code&&(e(`#weglot_permalink_not_available_${a}`).show(),e(`#lang-${a}`).val(""),setTimeout(()=>{e(`#weglot_permalink_not_available_${a}`).hide()},5e3)),e(`#text-edit-${a}`).text(n.data.result.slug)}})};e(".button-weglot-lang").each((a,o)=>{e(o).on("click",function(n){n.preventDefault();const a=e(this).data("lang"),o=e(`#text-edit-${a}`).text();t[a]=o,e(`#text-edit-${a}`).text(" "),e(`#lang-${a}`).val(o).show(),e(`.button-weglot-lang-submit[data-lang=${a}]`).show(),e(this).hide()});const r=e(o).data("lang");e(`.button-weglot-lang-submit[data-lang=${r}]`).on("click",n)}),e(".weglot_reset").each((t,n)=>{e(n).on("click",function(t){t.preventDefault();const n=e(this).data("lang"),a=e(this).attr("href"),o=e(this).data("id");e.ajax({url:ajaxurl,method:"POST",data:{action:"weglot_reset_custom_url",code_lang:n,id:o,custom_url:a},success:function(t){e(`#text-edit-${n}`).text(t.data.result.slug)}})})})};document.addEventListener("DOMContentLoaded",()=>{t()})})()}]);
1
+ !function(e){var t={};function n(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(a,o,function(t){return e[t]}.bind(null,o));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=6)}([function(e,t){Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var a=arguments[1],o=0;o<n;){var r=t[o];if(e.call(a,r,o,t))return r;o++}},configurable:!0,writable:!0})},function(e,t){Array.prototype.filter||(Array.prototype.filter=function(e,t){"use strict";if("Function"!=typeof e&&"function"!=typeof e||!this)throw new TypeError;var n=this.length>>>0,a=new Array(n),o=this,r=0,i=-1;if(void 0===t)for(;++i!==n;)i in this&&e(o[i],i,o)&&(a[r++]=o[i]);else for(;++i!==n;)i in this&&e.call(t,o[i],i,o)&&(a[r++]=o[i]);return a.length=r,a})},function(e,t,n){var a;a=function(){var e=JSON.parse('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I","į":"i","İ":"I","ı":"i","Ķ":"k","ķ":"k","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ũ":"U","ũ":"u","Ū":"u","ū":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Lj":"LJ","lj":"lj","Nj":"NJ","nj":"nj","Ș":"S","ș":"s","Ț":"T","ț":"t","˚":"o","Ά":"A","Έ":"E","Ή":"H","Ί":"I","Ό":"O","Ύ":"Y","Ώ":"W","ΐ":"i","Α":"A","Β":"B","Γ":"G","Δ":"D","Ε":"E","Ζ":"Z","Η":"H","Θ":"8","Ι":"I","Κ":"K","Λ":"L","Μ":"M","Ν":"N","Ξ":"3","Ο":"O","Π":"P","Ρ":"R","Σ":"S","Τ":"T","Υ":"Y","Φ":"F","Χ":"X","Ψ":"PS","Ω":"W","Ϊ":"I","Ϋ":"Y","ά":"a","έ":"e","ή":"h","ί":"i","ΰ":"y","α":"a","β":"b","γ":"g","δ":"d","ε":"e","ζ":"z","η":"h","θ":"8","ι":"i","κ":"k","λ":"l","μ":"m","ν":"n","ξ":"3","ο":"o","π":"p","ρ":"r","ς":"s","σ":"s","τ":"t","υ":"y","φ":"f","χ":"x","ψ":"ps","ω":"w","ϊ":"i","ϋ":"y","ό":"o","ύ":"y","ώ":"w","Ё":"Yo","Ђ":"DJ","Є":"Ye","І":"I","Ї":"Yi","Ј":"J","Љ":"LJ","Њ":"NJ","Ћ":"C","Џ":"DZ","А":"A","Б":"B","В":"V","Г":"G","Д":"D","Е":"E","Ж":"Zh","З":"Z","И":"I","Й":"J","К":"K","Л":"L","М":"M","Н":"N","О":"O","П":"P","Р":"R","С":"S","Т":"T","У":"U","Ф":"F","Х":"H","Ц":"C","Ч":"Ch","Ш":"Sh","Щ":"Sh","Ъ":"U","Ы":"Y","Ь":"","Э":"E","Ю":"Yu","Я":"Ya","а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ж":"zh","з":"z","и":"i","й":"j","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"ch","ш":"sh","щ":"sh","ъ":"u","ы":"y","ь":"","э":"e","ю":"yu","я":"ya","ё":"yo","ђ":"dj","є":"ye","і":"i","ї":"yi","ј":"j","љ":"lj","њ":"nj","ћ":"c","џ":"dz","Ґ":"G","ґ":"g","฿":"baht","ა":"a","ბ":"b","გ":"g","დ":"d","ე":"e","ვ":"v","ზ":"z","თ":"t","ი":"i","კ":"k","ლ":"l","მ":"m","ნ":"n","ო":"o","პ":"p","ჟ":"zh","რ":"r","ს":"s","ტ":"t","უ":"u","ფ":"f","ქ":"k","ღ":"gh","ყ":"q","შ":"sh","ჩ":"ch","ც":"ts","ძ":"dz","წ":"ts","ჭ":"ch","ხ":"kh","ჯ":"j","ჰ":"h","ẞ":"SS","Ạ":"A","ạ":"a","Ả":"A","ả":"a","Ấ":"A","ấ":"a","Ầ":"A","ầ":"a","Ẩ":"A","ẩ":"a","Ẫ":"A","ẫ":"a","Ậ":"A","ậ":"a","Ắ":"A","ắ":"a","Ằ":"A","ằ":"a","Ẳ":"A","ẳ":"a","Ẵ":"A","ẵ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ẻ":"E","ẻ":"e","Ẽ":"E","ẽ":"e","Ế":"E","ế":"e","Ề":"E","ề":"e","Ể":"E","ể":"e","Ễ":"E","ễ":"e","Ệ":"E","ệ":"e","Ỉ":"I","ỉ":"i","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ỏ":"O","ỏ":"o","Ố":"O","ố":"o","Ồ":"O","ồ":"o","Ổ":"O","ổ":"o","Ỗ":"O","ỗ":"o","Ộ":"O","ộ":"o","Ớ":"O","ớ":"o","Ờ":"O","ờ":"o","Ở":"O","ở":"o","Ỡ":"O","ỡ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ủ":"U","ủ":"u","Ứ":"U","ứ":"u","Ừ":"U","ừ":"u","Ử":"U","ử":"u","Ữ":"U","ữ":"u","Ự":"U","ự":"u","Ỳ":"Y","ỳ":"y","Ỵ":"Y","ỵ":"y","Ỷ":"Y","ỷ":"y","Ỹ":"Y","ỹ":"y","‘":"\'","’":"\'","“":"\\"","”":"\\"","†":"+","•":"*","…":"...","₠":"ecu","₢":"cruzeiro","₣":"french franc","₤":"lira","₥":"mill","₦":"naira","₧":"peseta","₨":"rupee","₩":"won","₪":"new shequel","₫":"dong","€":"euro","₭":"kip","₮":"tugrik","₯":"drachma","₰":"penny","₱":"peso","₲":"guarani","₳":"austral","₴":"hryvnia","₵":"cedi","₹":"indian rupee","₽":"russian ruble","₿":"bitcoin","℠":"sm","™":"tm","∂":"d","∆":"delta","∑":"sum","∞":"infinity","♥":"love","元":"yuan","円":"yen","﷼":"rial"}');function t(t,n){if("string"!=typeof t)throw new Error("slugify: string argument expected");n="string"==typeof n?{replacement:n}:n||{};var a=t.split("").reduce(function(t,a){return t+(e[a]||a).replace(n.remove||/[^\w\s$*_+~.()'"!\-:@]/g,"")},"").trim().replace(/[-\s]+/g,n.replacement||"-");return n.lower?a.toLowerCase():a}return t.extend=function(t){for(var n in t)e[n]=t[n]},t},e.exports=a(),e.exports.default=a()},,,,function(e,t,n){"use strict";n.r(t);n(0),n(1);var a=n(2),o=n.n(a);(()=>{const e=jQuery,t=()=>{let t={};const n=function(n){const a=e(this).data("lang"),r=o()(e(`#lang-${a}`).val(),{lower:!0,replacement:"-"});e(`#text-edit-${a}`).text(r),e(`#lang-${a}`).hide(),e(this).hide(),e(`.button-weglot-lang[data-lang=${a}]`).show(),e.ajax({url:ajaxurl,method:"POST",data:{action:"weglot_post_name",lang:a,id:e("#weglot_post_id").data("id"),post_name:r},success:function(n){if(n.data&&n.data.code&&"same_post_name"===n.data.code)return e(`#text-edit-${a}`).text(t[a]),void e(`#lang-${a}`).val("");n.data&&n.data.code&&"not_available"===n.data.code&&(e(`#weglot_permalink_not_available_${a}`).show(),e(`#lang-${a}`).val(""),setTimeout(()=>{e(`#weglot_permalink_not_available_${a}`).hide()},5e3)),e(`#text-edit-${a}`).text(n.data.result.slug)}})};e(".button-weglot-lang").each((a,o)=>{e(o).on("click",function(n){n.preventDefault();const a=e(this).data("lang"),o=e(`#text-edit-${a}`).text();t[a]=o,e(`#text-edit-${a}`).text(" "),e(`#lang-${a}`).val(o).show(),e(`.button-weglot-lang-submit[data-lang=${a}]`).show(),e(this).hide()});const r=e(o).data("lang");e(`.button-weglot-lang-submit[data-lang=${r}]`).on("click",n)}),e(".weglot_reset").each((t,n)=>{e(n).on("click",function(t){t.preventDefault();const n=e(this).data("lang"),a=e(this).attr("href"),o=e(this).data("id");e.ajax({url:ajaxurl,method:"POST",data:{action:"weglot_reset_custom_url",code_lang:n,id:o,custom_url:a},success:function(t){e(`#text-edit-${n}`).text(t.data.result.slug)}})})})};document.addEventListener("DOMContentLoaded",()=>{t()})})()}]);
dist/nav-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=4)}({4:function(e,t){jQuery(document).ready(function(e){e("#update-nav-menu").bind("click",function(t){t.target&&t.target.className&&-1!=t.target.className.indexOf("item-edit")&&e("input[value='#weglot_switcher'][type=text]").parents(".menu-item-settings").each(function(){const t=e(this).attr("id").substring(19);e(this).children("p:not( .field-move )").remove(),e(this).append(e("<input>").attr({type:"hidden",id:"edit-menu-item-title-"+t,name:"menu-item-title["+t+"]",value:weglot_data.title})),e(this).append(e("<input>").attr({type:"hidden",id:"edit-menu-item-url-"+t,name:"menu-item-url["+t+"]",value:"#weglot_switcher"})),e(this).append(e("<input>").attr({type:"hidden",id:"edit-menu-item-pll-detect-"+t,name:"menu-item-pll-detect["+t+"]",value:1})),e.each(weglot_data.list_options,(n,i)=>{const r=e("<p>").attr("class","description"),u=e("<label>").attr("for",`edit-menu-item-${i.key}-${t}`).text(` ${i.title}`);e(this).prepend(r),r.append(u);const o=e("<input>").attr({type:"checkbox",id:`edit-menu-item-${i.key}-${t}`,name:`menu-item-${i.key}[${t}]`,value:1});1===weglot_data.options[i.key]&&o.prop("checked",!0),u.prepend(o)})})})})}});
1
+ !function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=4)}({4:function(e,t){jQuery(document).ready(function(e){e("#update-nav-menu").bind("click",function(t){t.target&&t.target.className&&-1!=t.target.className.indexOf("item-edit")&&e("input[value='#weglot_switcher'][type=text]").parents(".menu-item-settings").each(function(){const t=e(this).attr("id").substring(19);e(this).children("p:not( .field-move )").remove(),e(this).append(e("<input>").attr({type:"hidden",id:"edit-menu-item-title-"+t,name:"menu-item-title["+t+"]",value:weglot_data.title})),e(this).append(e("<input>").attr({type:"hidden",id:"edit-menu-item-url-"+t,name:"menu-item-url["+t+"]",value:"#weglot_switcher"})),e(this).append(e("<input>").attr({type:"hidden",id:"edit-menu-item-weglot-detect-"+t,name:"menu-item-weglot-detect["+t+"]",value:1})),e.each(weglot_data.list_options,(n,i)=>{const r=e("<p>").attr("class","description"),o=e("<label>").attr("for",`edit-menu-item-${i.key}-${t}`).text(` ${i.title}`);e(this).prepend(r),r.append(o);const u=e("<input>").attr({type:"checkbox",id:`edit-menu-item-${i.key}-${t}`,name:`menu-item-weglot-${i.key}[${t}]`,value:1});weglot_data.options&&weglot_data.options[`menu-item-${t}`]&&1===weglot_data.options[`menu-item-${t}`][i.key]&&u.prop("checked",!0),o.prepend(u)})})})})}});
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Translate WP website - Weglot Translate ===
2
  Contributors: remyb92, gmulti, wysija
3
- Tags: translate,translation,language,multilingual,bilingual,international,localization,multilanguage,multi language,translations,translator,multilangues,traduction,traducteur,ubersetzung,mehrsprachig,traduccion,traduzione,vertaling,vertaler,meertalig
4
  Requires at least: 4.5
5
  Tested up to: 5.1
6
  Requires PHP: 5.4
7
- Stable tag: 2.7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -153,6 +153,11 @@ See changelog for upgrade changes.
153
 
154
  == Changelog ==
155
 
 
 
 
 
 
156
  = 2.7.0 (18/03/2019) =
157
  * Changed : Improve Compatibility with Caldera Forms
158
 
1
  === Translate WP website - Weglot Translate ===
2
  Contributors: remyb92, gmulti, wysija
3
+ Tags: translate, multilingual, language, translation, localization
4
  Requires at least: 4.5
5
  Tested up to: 5.1
6
  Requires PHP: 5.4
7
+ Stable tag: 3.0.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
153
 
154
  == Changelog ==
155
 
156
+ = 3.0.0 (16/04/2019) =
157
+ * New major version
158
+ * Link between WordPress options and Weglot dashboard options
159
+ * Bugfix: Fixed an error on the JSON translation
160
+
161
  = 2.7.0 (18/03/2019) =
162
  * Changed : Improve Compatibility with Caldera Forms
163
 
src/actions/admin/class-admin-enqueue-weglot.php CHANGED
@@ -75,23 +75,23 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
75
  $plans = $this->user_api_services->get_plans();
76
  $limit = 1000;
77
  if (
78
- isset( $user_info['plan'] ) &&
79
- $user_info['plan'] <= 0 ||
80
- isset( $user_info['plan'] ) &&
81
- in_array( $user_info['plan'], $plans['starter_free']['ids'] ) // phpcs:ignore
82
  ) {
83
  $limit = $plans['starter_free']['limit_language'];
84
  } elseif (
85
- isset( $user_info['plan'] ) &&
86
- in_array( $user_info['plan'], $plans['business']['ids'] ) // phpcs:ignore
87
  ) {
88
  $limit = $plans['business']['limit_language'];
89
  }
90
 
91
  wp_localize_script( 'weglot-admin', 'weglot_languages', [
92
- 'available' => $this->language_services->get_languages_available( [
93
  'sort' => true,
94
- ] ),
95
  'limit' => $limit,
96
  'plans' => $this->user_api_services->get_plans(),
97
  'original' => weglot_get_original_language(),
75
  $plans = $this->user_api_services->get_plans();
76
  $limit = 1000;
77
  if (
78
+ isset( $user_info['plan_id'] ) &&
79
+ $user_info['plan_id'] <= 1 ||
80
+ isset( $user_info['plan_id'] ) &&
81
+ in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) // phpcs:ignore
82
  ) {
83
  $limit = $plans['starter_free']['limit_language'];
84
  } elseif (
85
+ isset( $user_info['plan_id'] ) &&
86
+ in_array( $user_info['plan_id'], $plans['business']['ids'] ) // phpcs:ignore
87
  ) {
88
  $limit = $plans['business']['limit_language'];
89
  }
90
 
91
  wp_localize_script( 'weglot-admin', 'weglot_languages', [
92
+ 'available' => json_decode( json_encode( $this->language_services->get_languages_available( [
93
  'sort' => true,
94
+ ] ), true ), true ),
95
  'limit' => $limit,
96
  'plans' => $this->user_api_services->get_plans(),
97
  'original' => weglot_get_original_language(),
src/actions/admin/class-ajax-user-info.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Actions\Admin;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use WeglotWP\Models\Hooks_Interface_Weglot;
10
+
11
+ class Ajax_User_Info implements Hooks_Interface_Weglot {
12
+ public function __construct() {
13
+ $this->user_services = weglot_get_service( 'User_Api_Service_Weglot' );
14
+ }
15
+
16
+ /**
17
+ * @see Hooks_Interface_Weglot
18
+ *
19
+ * @since 3.0.0
20
+ * @return void
21
+ */
22
+ public function hooks() {
23
+ if ( ! is_admin() ) {
24
+ return;
25
+ }
26
+
27
+ add_action( 'wp_ajax_get_user_info', [ $this, 'get_user_info' ] );
28
+ }
29
+
30
+ /**
31
+ * @since 3.0.0
32
+ * @return array
33
+ */
34
+ public function get_user_info() {
35
+ if ( ! isset( $_POST['api_key'] ) ) { //phpcs:ignore
36
+ wp_send_json_error();
37
+ return;
38
+ }
39
+
40
+ $api_key = sanitize_title( $_POST['api_key'] ); //phpcs:ignore
41
+
42
+ $response = $this->user_services->get_user_info( $api_key );
43
+
44
+ if ( ! $response['allowed'] ) {
45
+ wp_send_json_error();
46
+ return;
47
+ }
48
+
49
+ wp_send_json_success( $response );
50
+ }
51
+ }
52
+
src/actions/admin/class-customize-menu-weglot.php CHANGED
@@ -50,6 +50,7 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
50
 
51
  /**
52
  * @since 2.4.0
 
53
  * @param int $menu_id
54
  * @param int $menu_item_db_id
55
  * @return void
@@ -65,12 +66,23 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
65
 
66
  check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
67
 
68
- $options = $this->option_services->get_option( 'menu_switcher' );
69
- foreach ( $options as $key => $value ) {
70
- $options[ $key ] = empty( $_POST[ 'menu-item-' . $key ][ $menu_item_db_id ] ) ? 0 : 1;
71
  }
72
 
73
- $this->option_services->set_option_by_key( 'menu_switcher', $options );
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
 
76
  /**
@@ -79,6 +91,7 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
79
  */
80
  public function nav_admin_enqueue_scripts() {
81
  $screen = get_current_screen();
 
82
  if ( 'nav-menus' !== $screen->base ) {
83
  return;
84
  }
50
 
51
  /**
52
  * @since 2.4.0
53
+ * @version 3.0.0
54
  * @param int $menu_id
55
  * @param int $menu_item_db_id
56
  * @return void
66
 
67
  check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
68
 
69
+ $options_menu = $this->option_services->get_option( 'menu_switcher' );
70
+ if ( ! $options_menu ) {
71
+ $options_menu = [];
72
  }
73
 
74
+ if ( array_key_exists( 'menu-item-weglot-dropdown', $_POST ) ) {
75
+ $options_menu[ 'menu-item-' . $menu_item_db_id ]['dropdown'] = empty( $_POST[ 'menu-item-weglot-dropdown' ][ $menu_item_db_id ] ) ? 0 : 1; //phpcs:ignore
76
+ } else {
77
+ $options_menu[ 'menu-item-' . $menu_item_db_id ]['dropdown'] = 0;
78
+ }
79
+ if ( array_key_exists( 'menu-item-weglot-hide_current', $_POST ) ) {
80
+ $options_menu[ 'menu-item-' . $menu_item_db_id ]['hide_current'] = empty( $_POST[ 'menu-item-weglot-hide_current' ][ $menu_item_db_id ] ) ? 0 : 1; //phpcs:ignore
81
+ } else {
82
+ $options_menu[ 'menu-item-' . $menu_item_db_id ]['hide_current'] = 0;
83
+ }
84
+
85
+ $this->option_services->set_option_by_key( 'menu_switcher', $options_menu );
86
  }
87
 
88
  /**
91
  */
92
  public function nav_admin_enqueue_scripts() {
93
  $screen = get_current_screen();
94
+
95
  if ( 'nav-menus' !== $screen->base ) {
96
  return;
97
  }
src/actions/admin/class-metabox-url-translate-weglot.php CHANGED
@@ -107,6 +107,7 @@ class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
107
  */
108
  public function weglot_wp_unique_post_slug( $slug ) {
109
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
 
110
  return $this->search_unique_key_post_name( $slug, $custom_urls );
111
  }
112
 
107
  */
108
  public function weglot_wp_unique_post_slug( $slug ) {
109
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
110
+
111
  return $this->search_unique_key_post_name( $slug, $custom_urls );
112
  }
113
 
src/actions/admin/class-options-weglot.php CHANGED
@@ -7,6 +7,8 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
 
 
10
 
11
  use WeglotWP\Models\Hooks_Interface_Weglot;
12
 
@@ -29,11 +31,12 @@ class Options_Weglot implements Hooks_Interface_Weglot {
29
  * @see Hooks_Interface_Weglot
30
  *
31
  * @since 2.0
 
32
  * @return void
33
  */
34
  public function hooks() {
35
- add_action( 'admin_init', [ $this, 'weglot_options_init' ] );
36
- $api_key = $this->option_services->get_option( 'api_key' );
37
  if ( empty( $api_key ) && ( ! isset( $_GET['page'] ) || strpos( $_GET['page'], 'weglot-settings' ) === false) ) { // phpcs:ignore
38
  //We don't show the notice if we are on Weglot configuration
39
  add_action( 'admin_notices', [ '\WeglotWP\Notices\No_Configuration_Weglot', 'admin_notice' ] );
@@ -47,160 +50,142 @@ class Options_Weglot implements Hooks_Interface_Weglot {
47
  */
48
  public function activate() {
49
  update_option( 'weglot_version', WEGLOT_VERSION );
50
- $options = $this->option_services->get_options();
51
-
52
- $this->option_services->set_options( $options );
53
  }
54
 
55
- /**
56
- * Register setting options
57
- *
58
- * @see admin_init
59
- * @since 2.0
60
- *
61
- * @return void
62
- */
63
- public function weglot_options_init() {
64
- register_setting( WEGLOT_OPTION_GROUP, WEGLOT_SLUG, [ $this, 'sanitize_options' ] );
65
- }
66
 
67
  /**
68
- * Callback register_setting for sanitize options
69
- *
70
- * @since 2.0
71
- *
72
- * @param array $options
73
- * @return array
74
  */
75
- public function sanitize_options( $options ) {
76
- $tab = ( isset( $_POST['tab'] ) ) ? $_POST['tab'] : null; //phpcs:ignore
77
- $options_bdd = $this->option_services->get_options();
 
 
 
78
 
79
- $new_options = wp_parse_args( $options, $options_bdd );
 
 
 
80
 
 
81
  switch ( $tab ) {
82
  case Helper_Tabs_Admin_Weglot::SETTINGS:
83
- $new_options = $this->sanitize_options_settings( $new_options, $options );
84
-
85
- if ( $options_bdd['has_first_settings'] ) {
86
- $new_options['has_first_settings'] = false;
87
- $new_options['show_box_first_settings'] = true;
88
- } else {
89
- $new_options = $this->sanitize_options_appearance( $new_options, $options );
90
- $new_options = $this->sanitize_options_advanced( $new_options, $options );
91
- }
92
- break;
93
- case Helper_Tabs_Admin_Weglot::SUPPORT:
94
- $new_options['active_wc_reload'] = isset( $options['active_wc_reload'] ) ? 1 : 0;
95
- break;
96
- case Helper_Tabs_Admin_Weglot::CUSTOM_URLS:
97
- if ( null === $options ) {
98
- $new_options['custom_urls'] = [];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
  break;
101
  }
102
 
103
- return $new_options;
104
  }
105
 
 
106
  /**
107
  * @since 2.0
108
  * @version 2.0.6
109
- * @param array $new_options
110
  * @param array $options
 
111
  * @return array
112
  */
113
- public function sanitize_options_settings( $new_options, $options ) {
114
- $user_info = $this->user_api_services->get_user_info( $new_options['api_key'] );
115
  $plans = $this->user_api_services->get_plans();
116
- $options_bdd = $this->option_services->get_options();
117
-
118
- $old_destination_languages = array_diff( $options_bdd['destination_language'], $new_options['destination_language'] );
119
-
120
- if ( ! empty( $old_destination_languages ) ) {
121
- foreach ( $old_destination_languages as $destination_language ) {
122
- $nav_menu = get_page_by_title( sprintf( '[weglot_menu_title-%s]', $destination_language ), 'OBJECT', 'nav_menu_item' ); //phpcs:ignore
123
- if ( ! $nav_menu ) {
124
- continue;
125
- }
126
- wp_delete_post( $nav_menu->ID, true );
127
- }
128
- }
129
 
130
  // Limit language
131
  if (
132
- $user_info['plan'] <= 0 ||
133
- in_array( $user_info['plan'], $plans['starter_free']['ids'] ) // phpcs:ignore
134
  ) {
135
- $new_options['destination_language'] = array_splice( $options['destination_language'], 0, $plans['starter_free']['limit_language'] );
136
  } elseif (
137
- in_array( $user_info['plan'], $plans['business']['ids'] ) // phpcs:ignore
138
  ) {
139
- $new_options['destination_language'] = array_splice( $options['destination_language'], 0, $plans['business']['limit_language'] );
140
  }
141
 
142
- if ( isset( $options['exclude_urls'] ) ) {
143
- $new_options['exclude_urls'] = array_filter( $options['exclude_urls'], function( $value ) {
144
- return '' !== $value;
145
- } );
146
- } else {
147
- $new_options['exclude_urls'] = [];
148
- }
149
 
150
- if ( isset( $options['exclude_blocks'] ) ) {
151
- $new_options['exclude_blocks'] = array_filter( $options['exclude_blocks'], function( $value ) {
152
- return '' !== $value;
153
- } );
154
- } else {
155
- $new_options['exclude_blocks'] = [];
 
 
 
 
156
  }
157
 
158
- return $new_options;
159
- }
160
 
161
- /**
162
- * @since 2.0
163
- * @version 2.4.0
164
- * @param array $new_options
165
- * @param array $options
166
- * @return array
167
- */
168
- public function sanitize_options_advanced( $new_options, $options ) {
169
- $new_options['auto_redirect'] = isset( $options['auto_redirect'] ) ? 1 : 0;
170
- $new_options['email_translate'] = isset( $options['email_translate'] ) ? 1 : 0;
171
- $new_options['translate_amp'] = isset( $options['translate_amp'] ) ? 1 : 0;
172
- $new_options['active_search'] = isset( $options['active_search'] ) ? 1 : 0;
173
- $new_options['private_mode']['active'] = isset( $options['private_mode']['active'] ) ? 1 : 0;
174
 
175
- $languages = weglot_get_languages_configured();
 
 
176
 
177
- foreach ( $languages as $key => $lang ) {
178
- if ( ! $lang ) {
 
179
  continue;
180
  }
181
- $new_options['private_mode'][ $lang->getIso639() ] = isset( $options['private_mode'][ $lang->getIso639() ] ) ? 1 : 0;
182
  }
183
 
184
- return $new_options;
185
- }
 
 
 
186
 
187
- /**
188
- * @since 2.0
189
- * @param array $new_options
190
- * @param array $options
191
- * @return array
192
- */
193
- public function sanitize_options_appearance( $new_options, $options ) {
194
- $new_options['is_menu'] = isset( $options['is_menu'] ) ? 1 : 0;
195
- $new_options['is_fullname'] = isset( $options['is_fullname'] ) ? 1 : 0;
196
- $new_options['with_name'] = isset( $options['with_name'] ) ? 1 : 0;
197
- $new_options['is_dropdown'] = isset( $options['is_dropdown'] ) ? 1 : 0;
198
- $new_options['with_flags'] = isset( $options['with_flags'] ) ? 1 : 0;
199
-
200
- $new_options['type_flags'] = isset( $options['type_flags'] ) ? $options['type_flags'] : '0';
201
- $new_options['override_css'] = isset( $options['override_css'] ) ? $options['override_css'] : '';
202
- $new_options['flag_css'] = isset( $options['flag_css'] ) ? $options['flag_css'] : '';
203
-
204
- return $new_options;
205
  }
206
  }
7
  }
8
 
9
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
10
+ use WeglotWP\Helpers\Helper_Pages_Weglot;
11
+ use WeglotWP\Helpers\Helper_Flag_Type;
12
 
13
  use WeglotWP\Models\Hooks_Interface_Weglot;
14
 
31
  * @see Hooks_Interface_Weglot
32
  *
33
  * @since 2.0
34
+ * @version 3.0.0
35
  * @return void
36
  */
37
  public function hooks() {
38
+ add_action( 'admin_post_weglot_save_settings', [ $this, 'weglot_save_settings' ] );
39
+ $api_key = $this->option_services->get_api_key( true );
40
  if ( empty( $api_key ) && ( ! isset( $_GET['page'] ) || strpos( $_GET['page'], 'weglot-settings' ) === false) ) { // phpcs:ignore
41
  //We don't show the notice if we are on Weglot configuration
42
  add_action( 'admin_notices', [ '\WeglotWP\Notices\No_Configuration_Weglot', 'admin_notice' ] );
50
  */
51
  public function activate() {
52
  update_option( 'weglot_version', WEGLOT_VERSION );
 
 
 
53
  }
54
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  /**
57
+ * @since 3.0.0
58
+ * @return void
 
 
 
 
59
  */
60
+ public function weglot_save_settings() {
61
+ $redirect_url = admin_url( 'admin.php?page=' . Helper_Pages_Weglot::SETTINGS );
62
+ if ( ! isset( $_GET['tab'] ) || ! isset( $_GET['_wpnonce'] ) ) { //phpcs:ignore
63
+ wp_redirect( $redirect_url );
64
+ return;
65
+ }
66
 
67
+ if ( ! wp_verify_nonce( $_GET[ '_wpnonce' ], 'weglot_save_settings' ) ) { //phpcs:ignore
68
+ wp_redirect( $redirect_url );
69
+ return;
70
+ }
71
 
72
+ $tab = $_GET[ 'tab' ]; //phpcs:ignore
73
  switch ( $tab ) {
74
  case Helper_Tabs_Admin_Weglot::SETTINGS:
75
+ $options = $_POST[ WEGLOT_SLUG ]; //phpcs:ignore
76
+
77
+ $options_bdd = $this->option_services->get_options_bdd_v3();
78
+ $has_first_settings = $this->option_services->get_has_first_settings();
79
+ $options = $this->sanitize_options_settings( $options, $has_first_settings );
80
+ $response = $this->option_services->save_options_to_weglot( $options, $has_first_settings );
81
+
82
+ if ( $response['success'] ) {
83
+ delete_transient( 'weglot_cache_cdn' );
84
+
85
+ $api_key_private = $this->option_services->get_api_key_private();
86
+
87
+ $option_v2 = $this->option_services->get_options_from_v2();
88
+ if ( ! $api_key_private && $option_v2 ) {
89
+ $options_bdd['custom_urls'] = $option_v2['custom_urls'];
90
+ $options_bdd['menu_switcher'] = $option_v2['menu_switcher'];
91
+ $options_bdd['has_first_settings'] = $option_v2['has_first_settings'];
92
+ $options_bdd['show_box_first_settings'] = $option_v2['show_box_first_settings'];
93
+ }
94
+
95
+ if ( $has_first_settings ) {
96
+ $options_bdd['has_first_settings'] = false;
97
+ $options_bdd['show_box_first_settings'] = true;
98
+ }
99
+
100
+ if ( array_key_exists( 'flag_css', $options ) ) {
101
+ $options_bdd['flag_css'] = $options['flag_css'];
102
+ }
103
+
104
+ $this->option_services->set_options( $options_bdd );
105
+
106
+ update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key_private' ), $options['api_key_private'] );
107
+ update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key' ), $response['result']['api_key'] );
108
  }
109
  break;
110
  }
111
 
112
+ wp_redirect( $redirect_url ); //phpcs:ignore
113
  }
114
 
115
+
116
  /**
117
  * @since 2.0
118
  * @version 2.0.6
 
119
  * @param array $options
120
+ * @param mixed $has_first_settings
121
  * @return array
122
  */
123
+ public function sanitize_options_settings( $options, $has_first_settings = false ) {
124
+ $user_info = $this->user_api_services->get_user_info( $options['api_key_private'] );
125
  $plans = $this->user_api_services->get_plans();
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  // Limit language
128
  if (
129
+ $user_info['plan_id'] <= 1 ||
130
+ in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) // phpcs:ignore
131
  ) {
132
+ $options['languages'] = array_splice( $options['languages'], 0, $plans['starter_free']['limit_language'] );
133
  } elseif (
134
+ in_array( $user_info['plan_id'], $plans['business']['ids'] ) // phpcs:ignore
135
  ) {
136
+ $options['languages'] = array_splice( $options['languages'], 0, $plans['business']['limit_language'] );
137
  }
138
 
139
+ $default_options = $this->option_services->get_options_default();
 
 
 
 
 
 
140
 
141
+ $options['custom_settings']['button_style']['is_dropdown'] = isset( $options['custom_settings']['button_style']['is_dropdown'] );
142
+ $options['custom_settings']['button_style']['with_flags'] = isset( $options['custom_settings']['button_style']['with_flags'] );
143
+ $options['custom_settings']['button_style']['full_name'] = isset( $options['custom_settings']['button_style']['full_name'] );
144
+ $options['custom_settings']['button_style']['with_name'] = isset( $options['custom_settings']['button_style']['with_name'] );
145
+
146
+ if ( $has_first_settings ) {
147
+ $options['custom_settings']['button_style']['is_dropdown'] = $default_options['custom_settings']['button_style']['is_dropdown'];
148
+ $options['custom_settings']['button_style']['with_flags'] = $default_options['custom_settings']['button_style']['with_flags'];
149
+ $options['custom_settings']['button_style']['full_name'] = $default_options['custom_settings']['button_style']['full_name'];
150
+ $options['custom_settings']['button_style']['with_name'] = $default_options['custom_settings']['button_style']['with_name'];
151
  }
152
 
153
+ $options['custom_settings']['button_style']['custom_css'] = isset( $options['custom_settings']['button_style']['custom_css'] ) ? $options['custom_settings']['button_style']['custom_css'] : '';
 
154
 
155
+ $options['custom_settings']['button_style']['flag_type'] = isset( $options['custom_settings']['button_style']['flag_type'] ) ? $options['custom_settings']['button_style']['flag_type'] : Helper_Flag_Type::RECTANGLE_MAT;
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
+ $options['custom_settings']['translate_email'] = isset( $options['custom_settings']['translate_email'] );
158
+ $options['custom_settings']['translate_search'] = isset( $options['custom_settings']['translate_search'] );
159
+ $options['custom_settings']['translate_amp'] = isset( $options['custom_settings']['translate_amp'] );
160
 
161
+ $options['auto_switch'] = isset( $options['auto_switch'] );
162
+ foreach ( $options['languages'] as $key => $language ) {
163
+ if ( 'active' === $key ) {
164
  continue;
165
  }
166
+ $options['languages'][ $key ]['enabled'] = ! isset( $options['languages'][ $key ]['enabled'] );
167
  }
168
 
169
+ if ( ! isset( $options['excluded_paths'] ) ) {
170
+ $options['excluded_paths'] = [];
171
+ } else {
172
+ $options['excluded_paths'] = array_values( $options['excluded_paths'] );
173
+ }
174
 
175
+ foreach ( $options['excluded_paths'] as $key => $item ) {
176
+ if ( empty( $item['value'] ) ) {
177
+ unset( $options['excluded_paths'][ $key ] );
178
+ }
179
+ }
180
+
181
+ if ( ! isset( $options['excluded_blocks'] ) ) {
182
+ $options['excluded_blocks'] = [];
183
+ }
184
+
185
+ if ( ! isset( $options['auto_switch_fallback'] ) ) {
186
+ $options['auto_switch_fallback'] = 'en';
187
+ }
188
+
189
+ return $options;
 
 
 
190
  }
191
  }
src/actions/admin/class-pages-weglot.php CHANGED
@@ -64,6 +64,8 @@ class Pages_Weglot implements Hooks_Interface_Weglot {
64
  $this->tabs = Helper_Tabs_Admin_Weglot::get_full_tabs();
65
  $this->tab_active = Helper_Tabs_Admin_Weglot::SETTINGS;
66
 
 
 
67
  if ( isset( $_GET['tab'] ) ) { // phpcs:ignore
68
  $this->tab_active = sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore
69
  }
64
  $this->tabs = Helper_Tabs_Admin_Weglot::get_full_tabs();
65
  $this->tab_active = Helper_Tabs_Admin_Weglot::SETTINGS;
66
 
67
+ delete_transient( 'weglot_cache_cdn' );
68
+
69
  if ( isset( $_GET['tab'] ) ) { // phpcs:ignore
70
  $this->tab_active = sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore
71
  }
src/actions/class-migration-weglot.php CHANGED
@@ -4,18 +4,20 @@ namespace WeglotWP\Actions;
4
 
5
  defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
6
 
 
7
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
8
 
9
  /**
10
  * Migration Weglot
11
  *
12
- * @since 2.0
13
  */
14
  class Migration_Weglot implements Hooks_Interface_Weglot {
15
 
16
 
17
  /**
18
- * @since 2.0
19
  */
20
  public function __construct() {
21
  $this->migration_services = weglot_get_service( 'Migration_Service_Weglot' );
@@ -24,6 +26,8 @@ class Migration_Weglot implements Hooks_Interface_Weglot {
24
 
25
  /**
26
  * @see HooksInterface
 
 
27
  * @return void
28
  */
29
  public function hooks() {
@@ -32,12 +36,9 @@ class Migration_Weglot implements Hooks_Interface_Weglot {
32
  }
33
 
34
  $weglot_version = get_option( 'weglot_version' );
35
- if ( ! $weglot_version && version_compare( WEGLOT_LATEST_VERSION, '2.0', '<' ) ) {
36
- $this->migration_services->update_v200();
37
- }
38
 
39
- if ( $weglot_version && version_compare( $weglot_version, '2.2.0', '>=' ) && version_compare( $weglot_version, '2.3.0', '<' ) ) {
40
- $this->migration_services->update_v230();
41
  }
42
  }
43
  }
4
 
5
  defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
6
 
7
+ use Morphism\Morphism;
8
  use WeglotWP\Models\Hooks_Interface_Weglot;
9
+ use WeglotWP\Models\Schema_Option_Migration_V3;
10
 
11
  /**
12
  * Migration Weglot
13
  *
14
+ * @since 2.0.0
15
  */
16
  class Migration_Weglot implements Hooks_Interface_Weglot {
17
 
18
 
19
  /**
20
+ * @since 2.0.0
21
  */
22
  public function __construct() {
23
  $this->migration_services = weglot_get_service( 'Migration_Service_Weglot' );
26
 
27
  /**
28
  * @see HooksInterface
29
+ * @since 2.0.0
30
+ * @version 3.0.0
31
  * @return void
32
  */
33
  public function hooks() {
36
  }
37
 
38
  $weglot_version = get_option( 'weglot_version' );
 
 
 
39
 
40
+ if ( $weglot_version && version_compare( $weglot_version, '2.3.0', '>=' ) && version_compare( $weglot_version, '3.0.0', '<' ) ) {
41
+ update_option( 'weglot_version', WEGLOT_VERSION );
42
  }
43
  }
44
  }
src/actions/front/class-clean-options.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Actions\Front;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use WeglotWP\Models\Hooks_Interface_Weglot;
10
+
11
+ class Clean_Options implements Hooks_Interface_Weglot {
12
+
13
+
14
+ public function __construct() {
15
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
16
+ }
17
+
18
+ /**
19
+ * @see Hooks_Interface_Weglot
20
+ *
21
+ * @since 3.0.0
22
+ * @return void
23
+ */
24
+ public function hooks() {
25
+ add_action( 'init', [ $this, 'clean_options' ] );
26
+ }
27
+
28
+
29
+
30
+ /**
31
+ * @since 3.0.0
32
+ * @return void
33
+ */
34
+ public function clean_options() {
35
+ if( isset( $_GET['_weglot_clean_cache_cdn'] ) && 'true' === $_GET['_weglot_clean_cache_cdn'] ) {
36
+ delete_transient( 'weglot_cache_cdn' );
37
+ }
38
+ }
39
+ }
src/actions/front/class-front-menu-weglot.php CHANGED
@@ -44,10 +44,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
44
 
45
  add_filter( 'wp_get_nav_menu_items', [ $this, 'weglot_wp_get_nav_menu_items' ], 20 );
46
  add_filter( 'nav_menu_link_attributes', [ $this, 'add_nav_menu_link_attributes' ], 10, 2 );
47
-
48
- if ( $this->option_services->get_option( 'is_menu' ) ) {
49
- add_filter( 'wp_nav_menu_items', [ $this, 'weglot_fallback_menu' ] );
50
- }
51
  }
52
 
53
  /**
@@ -93,23 +90,31 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
93
  $new_items[] = $item;
94
  continue;
95
  }
96
-
97
- $i = 0;
98
 
99
  $classes = [ 'weglot-lang', 'menu-item-weglot' ];
100
- $with_flags = $this->option_services->get_option( 'with_flags' );
101
  $options = $this->option_services->get_option( 'menu_switcher' );
 
 
 
 
 
 
 
 
 
102
 
103
- if ( ! $options['hide_current'] && $with_flags ) {
104
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
105
  }
106
 
107
  $languages = weglot_get_languages_configured();
108
  $current_language = $this->request_url_services->get_current_language_entry();
109
 
110
- if ( $options['dropdown'] ) {
111
  $title = __( 'Choose your language', 'weglot' );
112
- if ( ! $options['hide_current'] ) {
113
  $title = $this->button_services->get_name_with_language_entry( $current_language );
114
  }
115
  $item->title = apply_filters( 'weglot_menu_parent_menu_item_title', $title );
@@ -125,16 +130,17 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
125
  }
126
 
127
  if (
128
- ( $options['dropdown'] && $current_language->getIso639() === $language->getIso639() ) ||
129
- ( $options['hide_current'] && $current_language->getIso639() === $language->getIso639() ) ) {
130
  continue;
131
  }
132
 
133
  $add_classes = [];
134
- if ( $options['hide_current'] && $with_flags ) { // Just for children without flag classes
135
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
136
  }
137
 
 
138
  if ( $with_flags ) {
139
  $add_classes[] = $language->getIso639();
140
  }
@@ -148,7 +154,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
148
  $language_item->lang = $language->getIso639();
149
  $language_item->classes = array_merge( $classes, $add_classes );
150
  $language_item->menu_order += $offset + $i++;
151
- if ( $options['dropdown'] ) {
152
  $language_item->menu_item_parent = $item->db_id;
153
  $language_item->db_id = 0;
154
  }
@@ -157,9 +163,67 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
157
  }
158
  $offset += $i - 1;
159
  }
 
160
  return $new_items;
161
  }
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  /**
164
  * @since 2.0
165
  * @version 2.4.0
44
 
45
  add_filter( 'wp_get_nav_menu_items', [ $this, 'weglot_wp_get_nav_menu_items' ], 20 );
46
  add_filter( 'nav_menu_link_attributes', [ $this, 'add_nav_menu_link_attributes' ], 10, 2 );
47
+ add_filter( 'wp_nav_menu_objects', [ $this, 'wp_nav_menu_objects' ] );
 
 
 
48
  }
49
 
50
  /**
90
  $new_items[] = $item;
91
  continue;
92
  }
93
+ $id = $item->ID;
94
+ $i = 0;
95
 
96
  $classes = [ 'weglot-lang', 'menu-item-weglot' ];
 
97
  $options = $this->option_services->get_option( 'menu_switcher' );
98
+ $with_flags = $this->option_services->get_option_button( 'with_flags' );
99
+ $dropdown = 0;
100
+ if ( isset( $options[ 'menu-item-' . $id ] ) && isset( $options[ 'menu-item-' . $id ]['dropdown'] ) ) {
101
+ $dropdown = $options[ 'menu-item-' . $id ]['dropdown'];
102
+ }
103
+ $hide_current = 0;
104
+ if ( isset( $options[ 'menu-item-' . $id ] ) && isset( $options[ 'menu-item-' . $id ]['hide_current'] ) ) {
105
+ $hide_current = $options[ 'menu-item-' . $id ]['hide_current'];
106
+ }
107
 
108
+ if ( ! $hide_current && $with_flags ) {
109
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
110
  }
111
 
112
  $languages = weglot_get_languages_configured();
113
  $current_language = $this->request_url_services->get_current_language_entry();
114
 
115
+ if ( $dropdown ) {
116
  $title = __( 'Choose your language', 'weglot' );
117
+ if ( ! $hide_current ) {
118
  $title = $this->button_services->get_name_with_language_entry( $current_language );
119
  }
120
  $item->title = apply_filters( 'weglot_menu_parent_menu_item_title', $title );
130
  }
131
 
132
  if (
133
+ ( $dropdown && $current_language->getIso639() === $language->getIso639() ) ||
134
+ ( $hide_current && $current_language->getIso639() === $language->getIso639() ) ) {
135
  continue;
136
  }
137
 
138
  $add_classes = [];
139
+ if ( $hide_current && $with_flags ) { // Just for children without flag classes
140
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
141
  }
142
 
143
+ $add_classes[] = 'weglot-' . $language->getIso639();
144
  if ( $with_flags ) {
145
  $add_classes[] = $language->getIso639();
146
  }
154
  $language_item->lang = $language->getIso639();
155
  $language_item->classes = array_merge( $classes, $add_classes );
156
  $language_item->menu_order += $offset + $i++;
157
+ if ( $dropdown ) {
158
  $language_item->menu_item_parent = $item->db_id;
159
  $language_item->db_id = 0;
160
  }
163
  }
164
  $offset += $i - 1;
165
  }
166
+
167
  return $new_items;
168
  }
169
 
170
+ /**
171
+ * @since 2.7.0
172
+ * @param object $item
173
+ * @return array
174
+ */
175
+ public function get_ancestors( $item ) {
176
+ $ids = array();
177
+ $_anc_id = (int) $item->db_id;
178
+ while ( ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && ! in_array( $_anc_id, $ids ) ) {
179
+ $ids[] = $_anc_id;
180
+ }
181
+ return $ids;
182
+ }
183
+
184
+ /**
185
+ * @since 2.7.0
186
+ * @param array $items
187
+ * @return array
188
+ */
189
+ public function wp_nav_menu_objects( $items ) {
190
+ $r_ids = $k_ids = [];
191
+
192
+ foreach ( $items as $item ) {
193
+ if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
194
+ if ( in_array( 'menu-item-weglot', $item->classes ) ) {
195
+ $item->current = false;
196
+ $item->classes = array_diff( $item->classes, array( 'current-menu-item' ) );
197
+ $r_ids = array_merge( $r_ids, $this->get_ancestors( $item ) ); // Remove the classes for these ancestors
198
+ } elseif ( in_array( 'current-menu-item', $item->classes ) ) {
199
+ $k_ids = array_merge( $k_ids, $this->get_ancestors( $item ) ); // Keep the classes for these ancestors
200
+ }
201
+ }
202
+ }
203
+
204
+ $r_ids = array_diff( $r_ids, $k_ids );
205
+
206
+ foreach ( $items as $item ) {
207
+ if ( ! empty( $item->db_id ) && in_array( $item->db_id, $r_ids ) ) {
208
+ $item->classes = array_diff( $item->classes, array( 'current-menu-ancestor', 'current-menu-parent', 'current_page_parent', 'current_page_ancestor' ) );
209
+ }
210
+ }
211
+
212
+ if ( apply_filters( 'weglot_active_current_menu_item', false ) ) {
213
+ $current_language = weglot_get_current_language();
214
+ foreach ( $items as $item ) {
215
+ if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
216
+ if ( in_array( 'menu-item-weglot', $item->classes, true ) && in_array( 'weglot-' . $current_language, $item->classes, true ) ) {
217
+ $item->classes[] = 'current-menu-item';
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ return $items;
224
+ }
225
+
226
+
227
  /**
228
  * @since 2.0
229
  * @version 2.4.0
src/actions/front/class-translate-page-weglot.php CHANGED
@@ -10,9 +10,7 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
11
 
12
  use Weglot\Client\Api\Enum\BotType;
13
- use Weglot\Client\Client;
14
  use Weglot\Util\Server;
15
- use Weglot\Client\Api\Exception\ApiError;
16
 
17
 
18
  /**
@@ -88,6 +86,8 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
88
  'mailster_get_template', // Mailster Pro,
89
  'mmp_map_settings', // MMP Map,
90
  'elementor_ajax', // Elementor since 2.5
 
 
91
  ] );
92
 
93
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
@@ -150,7 +150,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
150
  return;
151
  }
152
 
153
- $file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/tests/templates/content.html' );
154
 
155
  if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
156
  $this->translate_services->set_original_language( weglot_get_original_language() );
10
  use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
11
 
12
  use Weglot\Client\Api\Enum\BotType;
 
13
  use Weglot\Util\Server;
 
14
 
15
 
16
  /**
86
  'mailster_get_template', // Mailster Pro,
87
  'mmp_map_settings', // MMP Map,
88
  'elementor_ajax', // Elementor since 2.5
89
+ 'ct_get_svg_icon_sets', // Oxygen
90
+ 'oxy_render_nav_menu', // Oxygen
91
  ] );
92
 
93
  if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && in_array( $_POST['action'], $action_ajax_no_translate ) ) { //phpcs:ignore
150
  return;
151
  }
152
 
153
+ $file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/content.html' );
154
 
155
  if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
156
  $this->translate_services->set_original_language( weglot_get_original_language() );
src/helpers/class-helper-api.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Helpers;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /**
10
+ * @since 3.0.0
11
+ */
12
+ abstract class Helper_API {
13
+ const API_BASE = 'https://api.weglot.com';
14
+
15
+ const API_BASE_STAGING = 'https://api-staging.weglot.com';
16
+
17
+ const API_BASE_OLD = 'https://weglot.com/api/';
18
+
19
+ const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
20
+
21
+ /**
22
+ * @since 3.0.0
23
+ * @return string
24
+ */
25
+ public static function get_cdn_url() {
26
+ if ( WEGLOT_DEV ) {
27
+ return self::CDN_BASE . 'staging/';
28
+ }
29
+
30
+ return self::CDN_BASE;
31
+ }
32
+
33
+ /**
34
+ * @since 3.0.0
35
+ * @return string
36
+ */
37
+ public static function get_api_url() {
38
+ if ( WEGLOT_DEV ) {
39
+ return self::API_BASE_STAGING;
40
+ }
41
+
42
+ return self::API_BASE;
43
+ }
44
+
45
+ /**
46
+ * @since 3.0.0
47
+ * @return string
48
+ */
49
+ public static function get_old_api_url() {
50
+ return self::API_BASE_OLD;
51
+ }
52
+ }
53
+
54
+
src/helpers/class-helper-excluded-type.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Helpers;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use Weglot\Util\Regex\RegexEnum;
10
+
11
+ /**
12
+ * @since 3.0.0
13
+ */
14
+ class Helper_Excluded_Type {
15
+ /**
16
+ * @since 3.0.0
17
+ * @return array
18
+ */
19
+ public static function get_excluded_type() {
20
+ return [
21
+ RegexEnum::START_WITH,
22
+ RegexEnum::END_WITH,
23
+ RegexEnum::CONTAIN,
24
+ RegexEnum::IS_EXACTLY,
25
+ RegexEnum::MATCH_REGEX,
26
+ ];
27
+ }
28
+
29
+ /**
30
+ * @since 3.0.0
31
+ * @param string $type
32
+ * @return string
33
+ */
34
+ public static function get_label_type( $type ) {
35
+ switch ( $type ) {
36
+ case RegexEnum::START_WITH:
37
+ return __( 'URL starts with', 'weglot' );
38
+ case RegexEnum::END_WITH:
39
+ return __( 'URL ends with', 'weglot' );
40
+ case RegexEnum::CONTAIN:
41
+ return __( 'URL contains substring', 'weglot' );
42
+ case RegexEnum::IS_EXACTLY:
43
+ return __( 'URL is exactly', 'weglot' );
44
+ case RegexEnum::MATCH_REGEX:
45
+ return __( 'URL matches regex', 'weglot' );
46
+ }
47
+ }
48
+ }
49
+
50
+
src/helpers/class-helper-filter-url-weglot.php CHANGED
@@ -13,6 +13,24 @@ if ( ! defined( 'ABSPATH' ) ) {
13
  */
14
  abstract class Helper_Filter_Url_Weglot {
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * @since 2.0.2
18
  * @param string $url
@@ -41,7 +59,7 @@ abstract class Helper_Filter_Url_Weglot {
41
 
42
  $url = $request_url_service->create_url_object( $url );
43
 
44
- return $url->getForLanguage( $current_and_original_language['current'] );
45
  }
46
 
47
  /**
@@ -91,7 +109,7 @@ abstract class Helper_Filter_Url_Weglot {
91
 
92
  $url = $request_url_service->create_url_object( $url_filter );
93
 
94
- return $url->getForLanguage( $current_and_original_language['current'] );
95
  }
96
 
97
  /**
13
  */
14
  abstract class Helper_Filter_Url_Weglot {
15
 
16
+ /**
17
+ * @since 3.0.0
18
+ * @param Weglot\Util\Url $url
19
+ * @return string
20
+ */
21
+ protected static function prevent_subfolder_install( $url ) {
22
+ $current_and_original_language = weglot_get_current_and_original_language();
23
+
24
+ $url_translate = $url->getForLanguage( $current_and_original_language['current'] );
25
+ $double_language = sprintf( '/%s/%s/', $current_and_original_language['current'], $current_and_original_language['current'] );
26
+
27
+ if ( strpos( $url_translate, $double_language ) === false ) {
28
+ return $url_translate;
29
+ }
30
+
31
+ return $url->getForLanguage( $current_and_original_language['original'] );
32
+ }
33
+
34
  /**
35
  * @since 2.0.2
36
  * @param string $url
59
 
60
  $url = $request_url_service->create_url_object( $url );
61
 
62
+ return apply_filters( 'weglot_helper_filter_url_lambda', self::prevent_subfolder_install( $url ) );
63
  }
64
 
65
  /**
109
 
110
  $url = $request_url_service->create_url_object( $url_filter );
111
 
112
+ return apply_filters( 'weglot_helper_filter_url_without_ajax', self::prevent_subfolder_install( $url ) );
113
  }
114
 
115
  /**
src/helpers/class-helper-flag-type.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Helpers;
4
+
5
+ // Exit if accessed directly.
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
+ /**
11
+ * @since 3.0.0
12
+ */
13
+ class Helper_Flag_Type {
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ const RECTANGLE_MAT = 'rectangle_mat';
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ const SHINY = 'shiny';
24
+
25
+ /**
26
+ * @var string
27
+ */
28
+ const SQUARE = 'square';
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ const CIRCLE = 'circle';
34
+
35
+ /**
36
+ * @since 3.0.0
37
+ * @return array
38
+ */
39
+ public static function get_flags_type() {
40
+ return [
41
+ RECTANGLE_MAT,
42
+ SHINY,
43
+ SQUARE,
44
+ CIRCLE,
45
+ ];
46
+ }
47
+
48
+ /**
49
+ * @since 3.0.0
50
+ * @param string|int $number
51
+ * @return string
52
+ */
53
+ public static function get_flag_type_with_number( $number ) {
54
+ switch ( (int) $number ) {
55
+ case 0:
56
+ return self::RECTANGLE_MAT;
57
+ break;
58
+ case 1:
59
+ return self::SHINY;
60
+ break;
61
+ case 2:
62
+ return self::SQUARE;
63
+ break;
64
+ case 3:
65
+ return self::CIRCLE;
66
+ break;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * @param string $type
72
+ * @return string
73
+ */
74
+ public static function get_flag_number_with_type( $type ) {
75
+ switch ( $type ) {
76
+ case self::RECTANGLE_MAT:
77
+ return 0;
78
+ case self::SHINY:
79
+ return 1;
80
+ case self::SQUARE:
81
+ return 2;
82
+ case self::CIRCLE:
83
+ return 3;
84
+ }
85
+ }
86
+ }
src/helpers/class-helper-keys-json-weglot.php CHANGED
@@ -31,6 +31,7 @@ abstract class Helper_Keys_Json_Weglot {
31
  return apply_filters( 'weglot_keys_translate_json', self::$keys );
32
  }
33
 
 
34
  /**
35
  * @since 2.4.0
36
  * @param string $key
31
  return apply_filters( 'weglot_keys_translate_json', self::$keys );
32
  }
33
 
34
+
35
  /**
36
  * @since 2.4.0
37
  * @param string $key
src/models/class-schema-option-migration-v3.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Models;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use WeglotWP\Helpers\Helper_Excluded_Type;
10
+ use WeglotWP\Helpers\Helper_Flag_Type;
11
+
12
+ class Schema_Option_Migration_V3 {
13
+
14
+
15
+ /**
16
+ * @since 3.0.0
17
+ * @return array
18
+ */
19
+ public static function get_schema_migration_options_v3() {
20
+ $schema = [
21
+ 'api_key_private' => 'api_key',
22
+ 'allowed' => 'allowed',
23
+ 'language_from' => 'original_language',
24
+ 'languages' => function( $options ) {
25
+ $destinations = [];
26
+ foreach ( $options['destination_language'] as $item ) {
27
+ $destinations[] = [
28
+ 'language_to' => $item,
29
+ 'enabled' => isset( $options['private_mode'][ $item ] ) && ! $options['private_mode'][ $item ],
30
+ 'automatic_translation_enabled' => true,
31
+ ];
32
+ }
33
+
34
+ return $destinations;
35
+ },
36
+ 'excluded_blocks' => (object) [
37
+ 'path' => 'exclude_blocks',
38
+ 'fn' => function( $blocks ) {
39
+ $objects = [];
40
+ foreach ( $blocks as $item ) {
41
+ $objects[] = [
42
+ 'value' => $item,
43
+ ];
44
+ }
45
+ return $objects;
46
+ },
47
+ ],
48
+ 'excluded_paths' => (object) [
49
+ 'path' => 'exclude_urls',
50
+ 'fn' => function( $urls ) {
51
+ $objects = [];
52
+ foreach ( $urls as $item ) {
53
+ $objects[] = [
54
+ 'type' => Helper_Excluded_Type::MATCH_REGEX,
55
+ 'value' => $item,
56
+ ];
57
+ }
58
+ return $objects;
59
+ },
60
+ ],
61
+ 'auto_switch' => (object) [
62
+ 'path' => 'auto_redirect',
63
+ 'fn' => function( $auto_redirect ) {
64
+ return (bool) $auto_redirect;
65
+ },
66
+ ],
67
+ 'auto_switch_fallback' => 'original_language',
68
+ 'custom_settings' => function( $options ) {
69
+ return [
70
+ 'translate_email' => (bool) $options['email_translate'],
71
+ 'translate_amp' => (bool) $options['translate_amp'],
72
+ 'translate_search' => (bool) $options['active_search'],
73
+ 'button_style' => [
74
+ 'is_dropdown' => (bool) $options['is_dropdown'],
75
+ 'full_name' => (bool) $options['is_fullname'],
76
+ 'with_name' => (bool) $options['with_name'],
77
+ 'with_flags' => (bool) $options['with_flags'],
78
+ 'flag_type' => Helper_Flag_Type::get_flag_type_with_number( $options['flag_type'] ),
79
+ 'custom_css' => $options['override_css'],
80
+ ],
81
+ ];
82
+ },
83
+
84
+ ];
85
+
86
+ return $schema;
87
+ }
88
+ }
src/models/class-schema-option-v3.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Models;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use WeglotWP\Helpers\Helper_Flag_Type;
10
+
11
+ class Schema_Option_V3 {
12
+
13
+ /**
14
+ * @since 3.0.0
15
+ * @return array
16
+ */
17
+ public static function get_schema_options_v3_compatible() {
18
+ $schema = [
19
+ 'api_key' => 'api_key',
20
+ 'api_key_private' => 'api_key_private',
21
+ 'allowed' => 'allowed',
22
+ 'original_language' => 'language_from',
23
+ 'translation_engine' => 'translation_engine',
24
+ 'destination_language' => (object) [
25
+ 'path' => 'languages',
26
+ 'fn' => function( $languages ) {
27
+ $destinations = [];
28
+ if( !$languages ){
29
+ return $destinations;
30
+ }
31
+ foreach ( $languages as $item ) {
32
+ $destinations[] = $item['language_to'];
33
+ }
34
+
35
+ return $destinations;
36
+ },
37
+ ],
38
+ 'private_mode' => (object) [
39
+ 'path' => 'languages',
40
+ 'fn' => function( $languages ) {
41
+ $private = [ 'active' => false ];
42
+ if( !$languages ){
43
+ return $private;
44
+ }
45
+ foreach ( $languages as $item ) {
46
+ if ( ! $item['enabled'] ) {
47
+ $private[ $item['language_to'] ] = true;
48
+ $private['active'] = true;
49
+ } else {
50
+ $private[ $item['language_to'] ] = false;
51
+ }
52
+ }
53
+
54
+ return $private;
55
+ },
56
+ ],
57
+ 'auto_redirect' => 'auto_switch',
58
+ 'autoswitch_fallback' => 'auto_switch_fallback',
59
+ 'exclude_urls' => 'excluded_paths',
60
+ 'exclude_blocks' => (object) [
61
+ 'path' => 'excluded_blocks',
62
+ 'fn' => function( $excluded_blocks ) {
63
+ $excluded = [];
64
+ if( !$excluded_blocks ){
65
+ return $excluded;
66
+ }
67
+ foreach ( $excluded_blocks as $item ) {
68
+ $excluded[] = $item['value'];
69
+ }
70
+ return $excluded;
71
+ },
72
+ ],
73
+ 'custom_settings' => 'custom_settings',
74
+ 'is_dropdown' => 'custom_settings.button_style.is_dropdown',
75
+ 'is_fullname' => 'custom_settings.button_style.full_name',
76
+ 'with_name' => 'custom_settings.button_style.with_name',
77
+ 'with_flags' => 'custom_settings.button_style.with_flags',
78
+ 'type_flags' => (object) [
79
+ 'path' => 'custom_settings.button_style.flag_type',
80
+ 'fn' => function( $flag_type ) {
81
+ if ( $flag_type ) {
82
+ return $flag_type;
83
+ }
84
+
85
+ return Helper_Flag_Type::RECTANGLE_MAT;
86
+ },
87
+ ],
88
+ 'override_css' => 'custom_settings.button_style.custom_css',
89
+ 'email_translate' => 'custom_settings.translate_email',
90
+ 'active_search' => 'custom_settings.translate_search',
91
+ 'translate_amp' => 'custom_settings.translate_amp',
92
+ 'has_first_settings' => 'has_first_settings',
93
+ 'show_box_first_settings' => 'show_box_first_settings',
94
+ 'custom_urls' => (object) [
95
+ 'path' => 'custom_urls',
96
+ 'fn' => function( $custom_urls ) {
97
+ if ( $custom_urls ) {
98
+ return $custom_urls;
99
+ }
100
+
101
+ return [];
102
+ },
103
+ ],
104
+ 'flag_css' => 'flag_css',
105
+ 'menu_switcher' => 'menu_switcher',
106
+ ];
107
+
108
+ return $schema;
109
+ }
110
+ }
src/services/class-button-service-weglot.php CHANGED
@@ -6,6 +6,8 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
 
9
  /**
10
  * Button services
11
  *
@@ -27,29 +29,31 @@ class Button_Service_Weglot {
27
 
28
  /**
29
  * @since 2.3.0
 
30
  * @return string
31
  */
32
  public function get_flag_class() {
33
- $options = $this->option_services->get_options();
34
- $type_flags = $options['type_flags'];
35
- $with_flags = $options['with_flags'];
36
 
37
  $flag_class = $with_flags ? 'weglot-flags ' : '';
38
- $flag_class .= '0' === $type_flags ? '' : 'flag-' . $type_flags . ' ';
 
 
 
39
 
40
  return apply_filters( 'weglot_get_flag_class', $flag_class );
41
  }
42
 
43
  /**
44
  * @since 2.3.0
45
- *
46
  * @param LanguageEntry $language_entry
47
  * @return string
48
  */
49
  public function get_name_with_language_entry( $language_entry ) {
50
- $options = $this->option_services->get_options();
51
- $with_name = $options['with_name'];
52
- $is_fullname = $options['is_fullname'];
53
  $name = '';
54
 
55
  if ( $with_name ) {
@@ -61,12 +65,11 @@ class Button_Service_Weglot {
61
 
62
  /**
63
  * @since 2.3.0
64
- *
65
  * @return string
66
  */
67
  public function get_class_dropdown() {
68
- $options = $this->option_services->get_options();
69
- $is_dropdown = $options['is_dropdown'];
70
  $class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
71
 
72
  return apply_filters( 'weglot_get_class_dropdown', $class );
6
  exit;
7
  }
8
 
9
+ use WeglotWP\Helpers\Helper_Flag_Type;
10
+
11
  /**
12
  * Button services
13
  *
29
 
30
  /**
31
  * @since 2.3.0
32
+ * @version 3.0.0
33
  * @return string
34
  */
35
  public function get_flag_class() {
36
+ $type_flags = $this->option_services->get_option_button( 'type_flags' );
37
+ $with_flags = $this->option_services->get_option_button( 'with_flags' );
 
38
 
39
  $flag_class = $with_flags ? 'weglot-flags ' : '';
40
+ $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
41
+ if ( '0' !== $type_flags ) {
42
+ $flag_class .= sprintf( 'flag-%s ', $type_flags );
43
+ }
44
 
45
  return apply_filters( 'weglot_get_flag_class', $flag_class );
46
  }
47
 
48
  /**
49
  * @since 2.3.0
50
+ * @version 3.0.0
51
  * @param LanguageEntry $language_entry
52
  * @return string
53
  */
54
  public function get_name_with_language_entry( $language_entry ) {
55
+ $with_name = $this->option_services->get_option_button( 'with_name' );
56
+ $is_fullname = $this->option_services->get_option( 'is_fullname' );
 
57
  $name = '';
58
 
59
  if ( $with_name ) {
65
 
66
  /**
67
  * @since 2.3.0
68
+ * @version 3.0.0
69
  * @return string
70
  */
71
  public function get_class_dropdown() {
72
+ $is_dropdown = $this->option_services->get_option_button( 'is_dropdown' );
 
73
  $class = $is_dropdown ? 'weglot-dropdown ' : 'weglot-inline ';
74
 
75
  return apply_filters( 'weglot_get_class_dropdown', $class );
src/services/class-custom-url-service-weglot.php CHANGED
@@ -38,7 +38,7 @@ class Custom_Url_Service_Weglot {
38
 
39
  $condition_test_custom_url = isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && ! is_post_type_archive() && ! is_category() && ! is_tax() && ! is_archive();
40
 
41
- if ( apply_filters( 'weglot_condition_test_custom_url', $condition_test_custom_url ) ) {
42
  $slug_in_work = $request_without_language[ $index_entries ];
43
 
44
  // Search from original slug
38
 
39
  $condition_test_custom_url = isset( $request_without_language[ $index_entries ] ) && ! is_admin() && ! empty( $custom_urls ) && ! is_post_type_archive() && ! is_category() && ! is_tax() && ! is_archive();
40
 
41
+ if ( apply_filters( 'weglot_condition_test_custom_url', $condition_test_custom_url, $url_lang, $key_code ) ) {
42
  $slug_in_work = $request_without_language[ $index_entries ];
43
 
44
  // Search from original slug
src/services/class-email-translate-service-weglot.php CHANGED
@@ -21,6 +21,7 @@ class Email_Translate_Service_Weglot {
21
  */
22
  public function __construct() {
23
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
 
24
  }
25
 
26
 
@@ -43,12 +44,12 @@ class Email_Translate_Service_Weglot {
43
  $exclude_blocks = $this->option_services->get_exclude_blocks();
44
 
45
  $config = new ServerConfigProvider();
46
- $client = new Client( $api_key );
47
  $parser = new Parser( $client, $config, $exclude_blocks );
48
  $translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $language ); //phpcs:ignore
49
 
50
  $config = new ServerConfigProvider();
51
- $client = new Client( $api_key );
52
  $parser = new Parser( $client, $config, $exclude_blocks );
53
  $translated_message = $parser->translate( $args['message'], $original_language, $language ); //phpcs:ignore
54
 
21
  */
22
  public function __construct() {
23
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
25
  }
26
 
27
 
44
  $exclude_blocks = $this->option_services->get_exclude_blocks();
45
 
46
  $config = new ServerConfigProvider();
47
+ $client = $this->parser_services->get_client();
48
  $parser = new Parser( $client, $config, $exclude_blocks );
49
  $translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $language ); //phpcs:ignore
50
 
51
  $config = new ServerConfigProvider();
52
+ $client = $this->parser_services->get_client();
53
  $parser = new Parser( $client, $config, $exclude_blocks );
54
  $translated_message = $parser->translate( $args['message'], $original_language, $language ); //phpcs:ignore
55
 
src/services/class-generate-switcher-service-weglot.php CHANGED
@@ -42,7 +42,7 @@ class Generate_Switcher_Service_Weglot {
42
 
43
  /**
44
  * @since 2.3.0
45
- * @version 2.4.0
46
  * @param string $dom
47
  * @return string
48
  */
@@ -52,53 +52,6 @@ class Generate_Switcher_Service_Weglot {
52
  return $dom;
53
  }
54
 
55
- if ( strpos( $dom, '[weglot_menu' ) === false ) {
56
- return $dom;
57
- }
58
-
59
-
60
-
61
- $languages_configured = $this->language_services->get_languages_configured();
62
- $options = $this->option_services->get_options();
63
- $is_fullname = $options['is_fullname'];
64
- $with_name = $options['with_name'];
65
-
66
- $url = $this->request_url_services->get_weglot_url();
67
-
68
- foreach ( $languages_configured as $language ) {
69
- $shortcode_title = sprintf( '\[weglot_menu_title-%s\]', $language->getIso639() );
70
- $shortcode_title_without_bracket = sprintf( 'weglot_menu_title-%s', $language->getIso639() );
71
- $shortcode_title_html = str_replace( '\[', '%5B', $shortcode_title );
72
- $shortcode_title_html = str_replace( '\]', '%5D', $shortcode_title_html );
73
- $shortcode_url = sprintf( '(http|https):\/\/\[weglot_menu_current_url-%s\]', $language->getIso639() );
74
- $shortcode_url_html = str_replace( '\[', '%5B', $shortcode_url );
75
- $shortcode_url_html = str_replace( '\]', '%5D', $shortcode_url_html );
76
-
77
- $name = $this->button_services->get_name_with_language_entry( $language );
78
-
79
- $dom = preg_replace( '#' . $shortcode_title . '#i', $name, $dom );
80
- $dom = preg_replace( '#' . $shortcode_title_html . '#i', $name, $dom );
81
- $dom = preg_replace( '#' . $shortcode_title_without_bracket . '#i', $name, $dom );
82
-
83
- $link_menu = $this->custom_url_services->get_link_button_with_key_code( $language->getIso639() );
84
-
85
- // Compatibility Menu HTTPS if not work. Since 2.0.6
86
- if (
87
- (
88
- is_ssl() ||
89
- isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] // phpcs:ignore
90
- ) &&
91
- strpos( $link_menu, 'https://' ) === false
92
- ) {
93
- $link_menu = str_replace( 'http', 'https', $link_menu );
94
- }
95
-
96
- $dom = preg_replace( '#' . $shortcode_url . '#i', $link_menu, $dom );
97
- $dom = preg_replace( '#' . $shortcode_url_html . '#i', $link_menu, $dom );
98
- }
99
-
100
- $dom .= sprintf( $this->string_version, WEGLOT_VERSION );
101
-
102
  return apply_filters( 'weglot_replace_weglot_menu', $dom );
103
  }
104
 
42
 
43
  /**
44
  * @since 2.3.0
45
+ * @version 3.0.0
46
  * @param string $dom
47
  * @return string
48
  */
52
  return $dom;
53
  }
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  return apply_filters( 'weglot_replace_weglot_menu', $dom );
56
  }
57
 
src/services/class-language-service-weglot.php CHANGED
@@ -49,9 +49,9 @@ class Language_Service_Weglot {
49
  return $this->languages;
50
  }
51
 
52
- $client = new Client( $this->option_services->get_option( 'api_key' ) );
53
- $languages = new Languages( $client );
54
 
 
55
  $this->languages = $languages->handle();
56
 
57
  if ( isset( $params['sort'] ) && $params['sort'] ) {
@@ -87,11 +87,15 @@ class Language_Service_Weglot {
87
  * @param null|string $type
88
  */
89
  public function get_languages_configured( $type = null ) {
90
- $languages[] = weglot_get_original_language();
 
 
 
 
 
91
  $languages = array_merge( $languages, weglot_get_destination_languages() );
92
 
93
  $languages_object = [];
94
-
95
  foreach ( $languages as $language ) {
96
  switch ( $type ) {
97
  case 'code':
@@ -113,6 +117,7 @@ class Language_Service_Weglot {
113
  * @return LanguageEntry
114
  */
115
  public function get_current_language_entry_from_key( $key_code ) {
 
116
  $languages = $this->get_languages_available();
117
 
118
  if ( isset( $languages[ $key_code ] ) ) {
49
  return $this->languages;
50
  }
51
 
52
+ $client = weglot_get_service( 'Parser_Service_Weglot' )->get_client();
 
53
 
54
+ $languages = new Languages( $client );
55
  $this->languages = $languages->handle();
56
 
57
  if ( isset( $params['sort'] ) && $params['sort'] ) {
87
  * @param null|string $type
88
  */
89
  public function get_languages_configured( $type = null ) {
90
+ $languages = [];
91
+ $original_language = weglot_get_original_language();
92
+
93
+ if( $original_language ){
94
+ $languages[] = $original_language;
95
+ }
96
  $languages = array_merge( $languages, weglot_get_destination_languages() );
97
 
98
  $languages_object = [];
 
99
  foreach ( $languages as $language ) {
100
  switch ( $type ) {
101
  case 'code':
117
  * @return LanguageEntry
118
  */
119
  public function get_current_language_entry_from_key( $key_code ) {
120
+
121
  $languages = $this->get_languages_available();
122
 
123
  if ( isset( $languages[ $key_code ] ) ) {
src/services/class-migration-service-weglot.php CHANGED
@@ -6,6 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
 
 
9
 
10
  /**
11
  * Migration service
@@ -20,83 +23,5 @@ class Migration_Service_Weglot {
20
  public function __construct() {
21
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
22
  }
23
-
24
- /**
25
- * Update V1 to V2 plugin
26
- * @since 2.0
27
- * @return void
28
- */
29
- public function update_v200() {
30
- $api_key = get_option( 'project_key' );
31
- $original_language = get_option( 'original_l' );
32
- $destination_language = get_option( 'destination_l' );
33
- $auto_switch = get_option( 'wg_auto_switch' );
34
- $wg_exclude_amp = get_option( 'wg_exclude_amp' );
35
- $override_css = get_option( 'override_css' );
36
- $flag_css = get_option( 'flag_css' );
37
- $with_flags = get_option( 'with_flags' );
38
- $type_flags = get_option( 'type_flags' );
39
- $with_name = get_option( 'with_name' );
40
- $is_dropdown = get_option( 'is_dropdown' );
41
- $is_fullname = get_option( 'is_fullname' );
42
- $is_menu = get_option( 'is_menu' );
43
- $exclude_url = get_option( 'exclude_url' );
44
- $exclude_blocks = get_option( 'exclude_blocks' );
45
- $rtl_ltr_style = get_option( 'rtl_ltr_style' );
46
- $allowed = get_option( 'wg_allowed' );
47
-
48
- $destination_language = explode( ',', $destination_language );
49
- $exclude_blocks = empty( $exclude_blocks ) ? [] : explode( ',', $exclude_blocks );
50
- $exclude_url = empty( $exclude_url ) ? [] : explode( ',', $exclude_url );
51
-
52
- $new_options = [
53
- 'api_key' => $api_key,
54
- 'original_language' => $original_language,
55
- 'destination_language' => empty( $destination_language ) ? [] : $destination_language,
56
- 'translate_amp' => ( 'on' === $wg_exclude_amp ) ? false : true,
57
- 'exclude_blocks' => empty( $exclude_blocks ) ? [] : $exclude_blocks,
58
- 'exclude_urls' => $exclude_url,
59
- 'auto_redirect' => ( 'on' === $auto_switch ) ? true : false,
60
- 'email_translate' => false,
61
- 'flag_css' => $flag_css,
62
- 'is_fullname' => ( 'on' === $is_fullname ) ? true : false,
63
- 'with_name' => ( 'on' === $with_name ) ? true : false,
64
- 'is_dropdown' => ( 'on' === $is_dropdown ) ? true : false,
65
- 'type_flags' => $type_flags,
66
- 'with_flags' => ( 'on' === $with_flags ) ? true : false,
67
- 'override_css' => $override_css,
68
- 'has_first_settings' => false,
69
- 'show_box_first_settings' => false,
70
- 'allowed' => $allowed,
71
- 'rtl_ltr_style' => $rtl_ltr_style,
72
- 'is_menu' => ( 'on' === $is_menu ) ? true : false,
73
- ];
74
-
75
- $this->option_services->set_options( $new_options );
76
- update_option( 'weglot_version', WEGLOT_VERSION );
77
- }
78
-
79
- /**
80
- * Update 2.2.0 > 2.3.0
81
- * @since 2.3.0
82
- * @return void
83
- */
84
- public function update_v230() {
85
- $private_mode = weglot_get_option( 'private_mode' );
86
-
87
- if ( $private_mode ) {
88
- $destination_language = weglot_get_destination_language();
89
- $new_options = weglot_get_options();
90
- $new_options['private_mode'] = [];
91
- $new_options['private_mode']['active'] = true;
92
-
93
- foreach ( $destination_language as $key => $lang ) {
94
- $new_options['private_mode'][ $lang ] = true;
95
- }
96
-
97
- $this->option_services->set_options( $new_options );
98
- update_option( 'weglot_version', WEGLOT_VERSION );
99
- }
100
- }
101
  }
102
 
6
  exit;
7
  }
8
 
9
+ use Morphism\Morphism;
10
+ use WeglotWP\Models\Schema_Option_V3;
11
+
12
 
13
  /**
14
  * Migration service
23
  public function __construct() {
24
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
src/services/class-option-service-weglot.php CHANGED
@@ -6,45 +6,75 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
 
 
 
 
 
9
  /**
10
  * Option services
11
  *
12
  * @since 2.0
13
  */
14
  class Option_Service_Weglot {
 
 
 
15
 
16
  /**
17
  * @var array
18
  */
19
  protected $options_default = [
20
- 'api_key' => '',
21
- 'original_language' => 'en',
22
- 'destination_language' => [],
23
- 'translate_amp' => false,
24
- 'exclude_blocks' => [],
25
- 'exclude_urls' => [],
26
- 'auto_redirect' => false,
27
- 'email_translate' => false,
28
- 'is_fullname' => false,
29
- 'with_name' => true,
30
- 'is_dropdown' => true,
31
- 'type_flags' => 0,
32
- 'with_flags' => true,
33
- 'override_css' => '',
34
- 'has_first_settings' => true,
35
- 'show_box_first_settings' => false,
36
- 'rtl_ltr_style' => '',
37
- 'allowed' => true,
38
- 'active_wc_reload' => false,
39
- 'custom_urls' => [],
40
- 'flag_css' => '',
41
- 'menu_switcher' => [],
42
- 'active_search' => false,
43
- 'private_mode' => [
44
- 'active' => false,
 
 
45
  ],
 
 
 
 
 
 
 
 
 
 
 
 
46
  ];
47
 
 
 
 
 
 
 
 
48
 
49
  /**
50
  * Get options default
@@ -56,35 +86,296 @@ class Option_Service_Weglot {
56
  return $this->options_default;
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  /**
60
  * @since 2.0
61
- * @version 2.4.0
62
  * @return array
63
  */
64
  public function get_options() {
65
- $options = wp_parse_args( get_option( WEGLOT_SLUG ), $this->get_options_default() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- if ( empty( $options['menu_switcher'] ) ) {
68
- $menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
69
- $options['menu_switcher'] = $menu_options_services->get_options_default();
 
 
 
 
 
 
 
 
 
 
 
70
  }
71
 
72
- return apply_filters( 'weglot_get_options', $options );
73
  }
74
 
75
  /**
76
  * @since 2.0
77
- * @param string $name
78
  * @return array
79
  */
80
- public function get_option( $name ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  $options = $this->get_options();
 
 
 
 
 
 
 
82
 
83
- if ( ! array_key_exists( $name, $options ) ) {
84
- return null; // @TODO : throw exception
 
85
  }
86
 
87
- return $options[ $name ];
88
  }
89
 
90
  /**
@@ -103,11 +394,11 @@ class Option_Service_Weglot {
103
 
104
  /**
105
  * @since 2.0.4
 
106
  * @return array
107
  */
108
  public function get_destination_languages() {
109
  $destination_languages = $this->get_option( 'destination_language' );
110
-
111
  return apply_filters( 'weglot_destination_languages', $destination_languages );
112
  }
113
 
@@ -116,13 +407,34 @@ class Option_Service_Weglot {
116
  * @return array
117
  */
118
  public function get_exclude_urls() {
119
- $exclude_urls = $this->get_option( 'exclude_urls' );
 
 
 
 
 
 
 
 
 
 
 
 
120
  $exclude_urls[] = '/wp-login.php';
121
  $exclude_urls[] = '/sitemaps_xsl.xsl';
122
  $exclude_urls[] = '/sitemaps.xml';
123
  $exclude_urls[] = 'wp-comments-post.php';
 
 
 
 
 
 
124
 
125
- return apply_filters( 'weglot_exclude_urls', $exclude_urls );
 
 
 
126
  }
127
 
128
  /**
@@ -143,6 +455,14 @@ class Option_Service_Weglot {
143
  return apply_filters( 'weglot_flag_css', $this->get_option( 'flag_css' ) );
144
  }
145
 
 
 
 
 
 
 
 
 
146
 
147
  /**
148
  * @since 2.0
@@ -150,10 +470,18 @@ class Option_Service_Weglot {
150
  * @return Option_Service_Weglot
151
  */
152
  public function set_options( $options ) {
153
- update_option( WEGLOT_SLUG, $options );
154
  return $this;
155
  }
156
 
 
 
 
 
 
 
 
 
157
  /**
158
  *
159
  * @param string $key
@@ -161,7 +489,7 @@ class Option_Service_Weglot {
161
  * @return Option_Service_Weglot
162
  */
163
  public function set_option_by_key( $key, $value ) {
164
- $options = $this->get_options();
165
  $options[ $key ] = $value;
166
  $this->set_options( $options );
167
  return $this;
6
  exit;
7
  }
8
 
9
+ use Morphism\Morphism;
10
+ use Weglot\Util\Regex;
11
+ use WeglotWP\Models\Schema_Option_V3;
12
+ use WeglotWP\Helpers\Helper_Flag_Type;
13
+ use WeglotWP\Helpers\Helper_API;
14
+
15
  /**
16
  * Option services
17
  *
18
  * @since 2.0
19
  */
20
  class Option_Service_Weglot {
21
+ protected $options_cdn = null;
22
+
23
+ protected $options_from_api = null;
24
 
25
  /**
26
  * @var array
27
  */
28
  protected $options_default = [
29
+ 'api_key_private' => '',
30
+ 'api_key' => '',
31
+ 'has_first_settings' => true,
32
+ 'show_box_first_settings' => false,
33
+ 'language_from' => 'en',
34
+ 'languages' => [],
35
+ 'auto_switch' => false,
36
+ 'auto_switch_fallback' => 'en',
37
+ 'excluded_blocks' => [],
38
+ 'excluded_paths' => [],
39
+ 'custom_settings' => [
40
+ 'translate_email' => false,
41
+ 'translate_amp' => false,
42
+ 'translate_search' => false,
43
+ 'button_style' => [
44
+ 'full_name' => true,
45
+ 'with_name' => true,
46
+ 'is_dropdown' => true,
47
+ 'with_flags' => true,
48
+ 'flag_type' => Helper_Flag_Type::RECTANGLE_MAT,
49
+ 'custom_css' => '',
50
+ ],
51
+ 'has_first_settings' => true,
52
+ 'show_box_first_settings' => false,
53
+ 'rtl_ltr_style' => '',
54
+ 'active_wc_reload' => false,
55
+ 'flag_css' => '',
56
  ],
57
+ 'allowed' => true,
58
+ ];
59
+
60
+ /**
61
+ * @var array
62
+ */
63
+ protected $options_bdd_default = [
64
+ 'has_first_settings' => true,
65
+ 'show_box_first_settings' => false,
66
+ 'menu_switcher' => [],
67
+ 'custom_urls' => [],
68
+ 'flag_css' => '',
69
  ];
70
 
71
+ /**
72
+ * @since 3.0.0
73
+ */
74
+ public function __construct() {
75
+ Morphism::setMapper( 'WeglotWP\Models\Schema_Option_V3', Schema_Option_V3::get_schema_options_v3_compatible() );
76
+ }
77
+
78
 
79
  /**
80
  * Get options default
86
  return $this->options_default;
87
  }
88
 
89
+ /**
90
+ * @since 3.0.0
91
+ * @param string $api_key
92
+ * @return array
93
+ */
94
+ protected function get_options_from_cdn_with_api_key( $api_key ) {
95
+ if ( $this->options_cdn ) {
96
+ return [
97
+ 'success' => true,
98
+ 'result' => $this->options_cdn,
99
+ ];
100
+ }
101
+
102
+ $cache_transient = apply_filters( 'weglot_get_options_from_cdn_cache', true );
103
+
104
+ if( $cache_transient ) {
105
+ $options = get_transient( 'weglot_cache_cdn', false );
106
+ if( $options ) {
107
+ $this->options_cdn = $options;
108
+ return [
109
+ 'success' => true,
110
+ 'result' => $this->options_cdn,
111
+ ];
112
+ }
113
+ }
114
+
115
+ $key = str_replace( 'wg_', '', $api_key );
116
+ $url = sprintf( '%s%s.json', Helper_API::get_cdn_url(), $key );
117
+
118
+ $response = wp_remote_get( $url, [
119
+ 'timeout' => 15,
120
+ ] );
121
+
122
+ if ( is_wp_error( $response ) ) {
123
+ return [
124
+ 'success' => false,
125
+ 'result' => [],
126
+ ];
127
+ }
128
+
129
+ try {
130
+ $body = json_decode( $response['body'], true );
131
+ $this->options_cdn = $body;
132
+
133
+ set_transient( 'weglot_cache_cdn', $body, apply_filters( 'weglot_get_options_from_cdn_cache_duration', 300 ) );
134
+
135
+ return [
136
+ 'success' => true,
137
+ 'result' => $body,
138
+ ];
139
+ } catch ( \Exception $th ) {
140
+ return [
141
+ 'success' => false,
142
+ ];
143
+ }
144
+ }
145
+
146
+ /**
147
+ * @since 3.0.0
148
+ * @param string $api_key
149
+ * @return array
150
+ */
151
+ public function get_options_from_api_with_api_key( $api_key ) {
152
+ if ( $this->options_from_api ) {
153
+ return [
154
+ 'success' => true,
155
+ 'result' => $this->options_from_api,
156
+ ];
157
+ }
158
+
159
+ $url = sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $api_key );
160
+
161
+ $response = wp_remote_get( $url, [
162
+ 'timeout' => 15,
163
+ ] );
164
+
165
+ if ( is_wp_error( $response ) ) {
166
+ return [
167
+ 'success' => false,
168
+ 'result' => $this->options_default,
169
+ ];
170
+ }
171
+
172
+ try {
173
+ $body = json_decode( $response['body'], true );
174
+
175
+ if ( null === $body ) {
176
+ return [
177
+ 'success' => false,
178
+ 'result' => $this->options_default,
179
+ ];
180
+ }
181
+
182
+ $options = apply_filters( 'weglot_get_options', array_merge( $this->get_options_bdd_v3(), $body ) );
183
+ $options['api_key_private'] = $this->get_api_key_private();
184
+ if ( empty( $options['custom_settings']['menu_switcher'] ) ) {
185
+ $menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
186
+ $options['custom_settings']['menu_switcher'] = $menu_options_services->get_options_default();
187
+ }
188
+
189
+ $this->options_from_api = $options;
190
+
191
+ return [
192
+ 'success' => true,
193
+ 'result' => $options,
194
+ ];
195
+ } catch ( \Exception $e ) {
196
+ return [
197
+ 'success' => false,
198
+ ];
199
+ }
200
+ }
201
+
202
+ /**
203
+ * @since 3.0.0
204
+ * @return array
205
+ */
206
+ public function get_options_from_v2() {
207
+ $options_v2 = get_option( WEGLOT_SLUG );
208
+ // $options_v2 = json_decode( file_get_contents(WEGLOT_DIR . '/settings-example.json'), true);
209
+
210
+ if ( $options_v2 ) {
211
+ if ( array_key_exists( 'api_key', $options_v2 ) ) {
212
+ $options_v2['api_key_private'] = $options_v2['api_key'];
213
+ }
214
+ if ( ! array_key_exists( 'custom_urls', $options_v2 ) || ! $options_v2['custom_urls'] ) {
215
+ $options_v2['custom_urls'] = [];
216
+ }
217
+ return $options_v2;
218
+ }
219
+
220
+ return (array) Morphism::map( 'WeglotWP\Models\Schema_Option_V3', $this->get_options_default() );
221
+ }
222
+
223
+ /**
224
+ * @since 3.0.0
225
+ * @param bool $compatibility
226
+ * @return string
227
+ */
228
+ public function get_api_key( $compatibility = false ) {
229
+ $api_key = get_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key' ), false );
230
+
231
+ if ( ! $compatibility || $api_key ) {
232
+ return apply_filters( 'weglot_get_api_key', $api_key );
233
+ }
234
+
235
+ $options = $this->get_options_from_v2();
236
+ return apply_filters( 'weglot_get_api_key', $options['api_key'] );
237
+ }
238
+
239
+ /**
240
+ * @since 3.0.0
241
+ * @param bool $compatibility
242
+ * @return bool
243
+ */
244
+ public function get_has_first_settings( $compatibility = false ) {
245
+ $options = $this->get_options();
246
+
247
+ if ( ! $compatibility || array_key_exists( 'has_first_settings', $options ) ) {
248
+ return $options['has_first_settings'];
249
+ }
250
+
251
+ $options = $this->get_options_from_v2();
252
+
253
+ return $options['has_first_settings'];
254
+ }
255
+
256
  /**
257
  * @since 2.0
258
+ * @version 3.0.0
259
  * @return array
260
  */
261
  public function get_options() {
262
+ $api_key = $this->get_api_key();
263
+ $api_key_private = $this->get_api_key_private();
264
+
265
+ if ( is_admin() && $api_key_private ) {
266
+ $response = $this->get_options_from_api_with_api_key(
267
+ $api_key_private
268
+ );
269
+ } else {
270
+ if ( ! is_admin() && $api_key ) {
271
+ $response = $this->get_options_from_cdn_with_api_key(
272
+ $api_key
273
+ );
274
+ } else {
275
+ return $this->get_options_from_v2();
276
+ }
277
+ }
278
+ $options = $response['result'];
279
+
280
+ if ( $api_key_private ) {
281
+ $options['api_key_private'] = $api_key_private;
282
+ }
283
+
284
+ $options = apply_filters( 'weglot_get_options', array_merge( $this->options_bdd_default, $this->get_options_bdd_v3(), $options ) );
285
+
286
+ return (array) Morphism::map( 'WeglotWP\Models\Schema_Option_V3', $options );
287
+ }
288
+
289
+ /**
290
+ * @since 3.0.0
291
+ * @return string
292
+ */
293
+ public function get_api_key_private() {
294
+ return get_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key_private' ) );
295
+ }
296
+
297
+
298
+ /**
299
+ * @since 3.0.0
300
+ * @param array $options
301
+ * @return array
302
+ */
303
+ public function save_options_to_weglot( $options ) {
304
+ $response = wp_remote_post( sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $options['api_key_private'] ), [
305
+ 'body' => json_encode( $options ), //phpcs:ignore
306
+ 'headers' => [
307
+ 'technology' => 'wordpress',
308
+ 'Content-Type' => 'application/json; charset=utf-8',
309
+ ],
310
+ ] );
311
+
312
+ if ( is_wp_error( $response ) ) {
313
+ return [
314
+ 'success' => false,
315
+ ];
316
+ }
317
+
318
+ return [
319
+ 'success' => true,
320
+ 'result' => json_decode( $response['body'], true ),
321
+ ];
322
+ }
323
 
324
+ /**
325
+ * @since 3.0.0
326
+ * @param string $key
327
+ * @return string|null
328
+ */
329
+ public function get_option_custom_settings( $key ){
330
+ $options = $this->get_options();
331
+
332
+ if( ! array_key_exists( 'custom_settings', $options ) ){
333
+ return $this->get_option( $key );
334
+ }
335
+
336
+ if ( ! array_key_exists( $key, $options['custom_settings'] ) ) {
337
+ return null;
338
  }
339
 
340
+ return $options['custom_settings'][ $key ];
341
  }
342
 
343
  /**
344
  * @since 2.0
345
+ * @param string $key
346
  * @return array
347
  */
348
+ public function get_option( $key ) {
349
+ $options = $this->get_options();
350
+
351
+ if ( ! array_key_exists( $key, $options ) ) {
352
+ return null;
353
+ }
354
+
355
+ return $options[ $key ];
356
+ }
357
+
358
+ /**
359
+ * @since 3.0.0
360
+ * @param string $key
361
+ * @return string|boolean|int
362
+ */
363
+ public function get_option_button( $key ) {
364
  $options = $this->get_options();
365
+ if (
366
+ array_key_exists( 'custom_settings', $options ) &&
367
+ is_array( $options['custom_settings'] ) &&
368
+ array_key_exists( $key, $options['custom_settings']['button_style'] )
369
+ ) {
370
+ return $options['custom_settings']['button_style'][ $key ];
371
+ }
372
 
373
+ // Retrocompatibility v2
374
+ if ( ! array_key_exists( $key, $options ) ) {
375
+ return null;
376
  }
377
 
378
+ return $options[ $key ];
379
  }
380
 
381
  /**
394
 
395
  /**
396
  * @since 2.0.4
397
+ * @version 3.0.0
398
  * @return array
399
  */
400
  public function get_destination_languages() {
401
  $destination_languages = $this->get_option( 'destination_language' );
 
402
  return apply_filters( 'weglot_destination_languages', $destination_languages );
403
  }
404
 
407
  * @return array
408
  */
409
  public function get_exclude_urls() {
410
+ $list_exclude_urls = $this->get_option( 'exclude_urls' );
411
+ $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
412
+ $exclude_urls = [];
413
+ if ( ! empty( $list_exclude_urls ) ) {
414
+ foreach ( $list_exclude_urls as $item ) {
415
+ if ( is_array( $item ) ) {
416
+ $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
417
+ $exclude_urls[] = $regex->getRegex();
418
+ } else {
419
+ $exclude_urls[] = $item;
420
+ }
421
+ }
422
+ }
423
  $exclude_urls[] = '/wp-login.php';
424
  $exclude_urls[] = '/sitemaps_xsl.xsl';
425
  $exclude_urls[] = '/sitemaps.xml';
426
  $exclude_urls[] = 'wp-comments-post.php';
427
+ $exclude_urls[] = '/ct_template'; // Compatibility Oxygen
428
+
429
+ $translate_amp = weglot_get_translate_amp_translation();
430
+ if ( ! $translate_amp ) {
431
+ $exclude_urls[] = weglot_get_service( 'Amp_Service_Weglot' )->get_regex();
432
+ }
433
 
434
+ // array_map : Need only for those who use the filter
435
+ return apply_filters( 'weglot_exclude_urls', array_map( function( $value ) use ( $request_url_services ) {
436
+ return $request_url_services->url_to_relative( $value );
437
+ }, $exclude_urls ) );
438
  }
439
 
440
  /**
455
  return apply_filters( 'weglot_flag_css', $this->get_option( 'flag_css' ) );
456
  }
457
 
458
+ /**
459
+ * @since 3.0.0
460
+ * @return int
461
+ */
462
+ public function get_translation_engine() {
463
+ return apply_filters( 'weglot_get_translation_engine', $this->get_option( 'translation_engine' ) );
464
+ }
465
+
466
 
467
  /**
468
  * @since 2.0
470
  * @return Option_Service_Weglot
471
  */
472
  public function set_options( $options ) {
473
+ update_option( sprintf( '%s-%s', WEGLOT_SLUG, 'v3' ), $options );
474
  return $this;
475
  }
476
 
477
+ /**
478
+ * @since 3.0.0
479
+ * @return array|false
480
+ */
481
+ public function get_options_bdd_v3() {
482
+ return get_option( sprintf( '%s-%s', WEGLOT_SLUG, 'v3' ), $this->options_bdd_default );
483
+ }
484
+
485
  /**
486
  *
487
  * @param string $key
489
  * @return Option_Service_Weglot
490
  */
491
  public function set_option_by_key( $key, $value ) {
492
+ $options = $this->get_options_bdd_v3();
493
  $options[ $key ] = $value;
494
  $this->set_options( $options );
495
  return $this;
src/services/class-other-translate-service-weglot.php CHANGED
@@ -23,6 +23,12 @@ use WeglotWP\Helpers\Helper_Json_Inline_Weglot;
23
  class Other_Translate_Service_Weglot {
24
  protected $max_chars = 500;
25
 
 
 
 
 
 
 
26
 
27
  /**
28
  * @since 2.0
@@ -58,8 +64,8 @@ class Other_Translate_Service_Weglot {
58
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
59
  }
60
 
61
- $client = new Client( weglot_get_option( 'api_key' ) );
62
- $translate = new Translate( $translate, $client );
63
 
64
  $object = $translate->handle();
65
 
23
  class Other_Translate_Service_Weglot {
24
  protected $max_chars = 500;
25
 
26
+ /**
27
+ * @since 3.0.0
28
+ */
29
+ public function __construct() {
30
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
31
+ }
32
 
33
  /**
34
  * @since 2.0
64
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
65
  }
66
 
67
+ $client = $this->parser_services->get_client();
68
+ $translate = new Translate( $translate, $client );
69
 
70
  $object = $translate->handle();
71
 
src/services/class-parser-service-weglot.php CHANGED
@@ -3,6 +3,7 @@
3
  namespace WeglotWP\Services;
4
 
5
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
6
 
7
 
8
  use Weglot\Client\Client;
@@ -39,6 +40,25 @@ class Parser_Service_Weglot {
39
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  /**
43
  * @since 2.0
44
  * @version 2.2.2
@@ -52,12 +72,12 @@ class Parser_Service_Weglot {
52
  }, $exclude_blocks);
53
  }
54
 
55
- $api_key = $this->option_services->get_option( 'api_key' );
56
  $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
57
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
58
  $config = new ServerConfigProvider();
59
  }
60
- $client = new Client( $api_key );
 
61
 
62
  if ( '2' === WEGLOT_LIB_PARSER ) {
63
  $listeners = $this->dom_listeners_services->get_dom_listeners();
3
  namespace WeglotWP\Services;
4
 
5
  use WeglotWP\Models\Hooks_Interface_Weglot;
6
+ use WeglotWP\Helpers\Helper_API;
7
 
8
 
9
  use Weglot\Client\Client;
40
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
41
  }
42
 
43
+ /**
44
+ * @since 3.0.0
45
+ * @return Client
46
+ */
47
+ public function get_client() {
48
+ $api_key = $this->option_services->get_api_key( true );
49
+ $translation_engine = $this->option_services->get_translation_engine();
50
+ if ( ! $translation_engine || empty( $translation_engine ) ) {
51
+ $translation_engine = 2;
52
+ }
53
+
54
+ $client = new Client( $api_key, $translation_engine, [
55
+ 'host' => Helper_API::get_api_url(),
56
+ ] );
57
+ $client->getHttpClient()->addHeader( 'weglot-integration: WordPress Plugin' );
58
+
59
+ return $client;
60
+ }
61
+
62
  /**
63
  * @since 2.0
64
  * @version 2.2.2
72
  }, $exclude_blocks);
73
  }
74
 
 
75
  $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
76
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
77
  $config = new ServerConfigProvider();
78
  }
79
+
80
+ $client = $this->get_client();
81
 
82
  if ( '2' === WEGLOT_LIB_PARSER ) {
83
  $listeners = $this->dom_listeners_services->get_dom_listeners();
src/services/class-private-language-service-weglot.php CHANGED
@@ -33,7 +33,8 @@ class Private_Language_Service_Weglot {
33
  */
34
  public function is_active_private_mode_for_lang( $key_lang ) {
35
  $private_mode_languages = $this->option_services->get_option( 'private_mode' );
36
- if ( ! $private_mode_languages['active'] ) {
 
37
  return false;
38
  }
39
 
@@ -57,13 +58,20 @@ class Private_Language_Service_Weglot {
57
  return false;
58
  }
59
 
 
 
 
 
60
  if ( ! $private_mode_languages['active'] ) {
61
  return false;
62
  }
63
 
64
  $original_language = weglot_get_original_language();
 
65
  unset( $private_mode_languages['active'] );
66
- unset( $private_mode_languages[ $original_language ] );
 
 
67
 
68
  foreach ( $private_mode_languages as $lang => $lang_active ) {
69
  if ( ! $lang_active ) {
33
  */
34
  public function is_active_private_mode_for_lang( $key_lang ) {
35
  $private_mode_languages = $this->option_services->get_option( 'private_mode' );
36
+
37
+ if ( ! array_key_exists( 'active', $private_mode_languages ) || ! $private_mode_languages['active'] ) {
38
  return false;
39
  }
40
 
58
  return false;
59
  }
60
 
61
+ if ( ! array_key_exists( 'active', $private_mode_languages ) ) {
62
+ return false;
63
+ }
64
+
65
  if ( ! $private_mode_languages['active'] ) {
66
  return false;
67
  }
68
 
69
  $original_language = weglot_get_original_language();
70
+
71
  unset( $private_mode_languages['active'] );
72
+ if ( array_key_exists( $original_language, $private_mode_languages ) ) {
73
+ unset( $private_mode_languages['original_language'] );
74
+ }
75
 
76
  foreach ( $private_mode_languages as $lang => $lang_active ) {
77
  if ( ! $lang_active ) {
src/services/class-request-url-service-weglot.php CHANGED
@@ -53,18 +53,18 @@ class Request_Url_Service_Weglot {
53
  * @return string
54
  */
55
  public function init_weglot_url() {
56
- $exclude_urls_option = $this->option_services->get_exclude_urls();
 
 
57
 
58
- if ( ! empty( $exclude_urls_option ) ) {
59
- $exclude_urls_option = array_map( function( $item ) {
60
- return $this->url_to_relative( $item );
61
- }, $exclude_urls_option);
62
  }
63
 
64
- $this->weglot_url = new Url(
65
  $this->get_full_url(),
66
- $this->option_services->get_option( 'original_language' ),
67
- weglot_get_destination_languages(),
68
  $this->get_home_wordpress_directory()
69
  );
70
 
@@ -121,6 +121,10 @@ class Request_Url_Service_Weglot {
121
  }
122
  }
123
 
 
 
 
 
124
  if ( $with_filter ) {
125
  return apply_filters( 'weglot_translate_current_language', $current_language );
126
  }
@@ -143,6 +147,11 @@ class Request_Url_Service_Weglot {
143
  * @return boolean
144
  */
145
  public function is_translatable_url() {
 
 
 
 
 
146
  return $this->get_weglot_url()->isTranslable() && $this->is_eligible_url( $this->get_full_url() );
147
  }
148
 
@@ -213,54 +222,36 @@ class Request_Url_Service_Weglot {
213
  * @return boolean
214
  */
215
  public function is_eligible_url( $url ) {
216
- $url = urldecode( $this->url_to_relative( $url ) );
217
- //Format exclude URL
218
- $exclude_urls_option = weglot_get_exclude_urls();
219
-
220
- if ( ! empty( $exclude_urls_option ) ) {
221
- $exclude_urls_option = implode( ',', $exclude_urls_option );
222
- $exclude_urls_option = preg_replace( '#\s+#', ',', trim( $exclude_urls_option ) );
223
-
224
- $excluded_urls = explode( ',', $exclude_urls_option );
225
- foreach ( $excluded_urls as $key => $ex_url ) {
226
- $excluded_urls[$key] = $this->url_to_relative( $ex_url ); //phpcs:ignore
227
- }
228
- $exclude_urls_option = implode( ',', $excluded_urls );
229
- }
230
-
231
- $exclusions = preg_replace( '#\s+#', ',', $exclude_urls_option );
232
-
233
- $list_regex = [];
234
- if ( ! empty( $exclusions ) ) {
235
- $list_regex = explode( ',', $exclusions );
236
  }
237
 
238
- $translate_amp = weglot_get_translate_amp_translation();
239
 
240
- if ( ! $translate_amp ) {
241
- $list_regex[] = $this->amp_services->get_regex();
242
- }
243
 
244
- $path_without_language = array_filter( explode( '/', $url ), 'strlen' );
245
  $index_entries = count( $path_without_language );
246
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
247
  $current_language = $this->get_current_language();
248
 
249
  $url_path_custom = null;
250
  if ( ! empty( $custom_urls ) && isset( $custom_urls[ $current_language ] ) && isset( $path_without_language[ $index_entries ] ) && isset( $custom_urls[ $current_language ][ $path_without_language[ $index_entries ] ] ) ) {
251
- $url_path_custom = '/' . $custom_urls[ $current_language ][ $path_without_language[ $index_entries ] ] . '/';
252
  }
253
 
254
- foreach ( $list_regex as $regex ) {
255
- $str = $this->escape_slash( $regex );
256
- $prepare_regex = sprintf( '/%s/', $str );
257
-
258
- if ( preg_match( $prepare_regex, $url ) === 1 ) {
259
- return apply_filters( 'weglot_is_eligible_url', false, $url );
260
- }
261
 
262
- if ( null !== $url_path_custom && preg_match( $prepare_regex, $url_path_custom ) === 1 ) {
263
- return apply_filters( 'weglot_is_eligible_url', false, $url );
 
 
 
264
  }
265
  }
266
 
@@ -280,7 +271,6 @@ class Request_Url_Service_Weglot {
280
 
281
  /**
282
  * @since 2.0
283
- *
284
  * @param string $url
285
  * @return string
286
  */
53
  * @return string
54
  */
55
  public function init_weglot_url() {
56
+ $exclude_urls_option = $this->option_services->get_exclude_urls();
57
+ $original_language = $this->option_services->get_option( 'original_language' );
58
+ $destinations_language = weglot_get_destination_languages();
59
 
60
+ if ( empty( $destinations_language ) ) {
61
+ $destinations_language[] = $original_language;
 
 
62
  }
63
 
64
+ $this->weglot_url = new Url(
65
  $this->get_full_url(),
66
+ $original_language,
67
+ $destinations_language,
68
  $this->get_home_wordpress_directory()
69
  );
70
 
121
  }
122
  }
123
 
124
+ if( empty( $current_language ) ){
125
+ return apply_filters( 'weglot_default_current_language_empty', 'en' );
126
+ }
127
+
128
  if ( $with_filter ) {
129
  return apply_filters( 'weglot_translate_current_language', $current_language );
130
  }
147
  * @return boolean
148
  */
149
  public function is_translatable_url() {
150
+ $destinations = weglot_get_destination_languages();
151
+ if ( empty( $destinations ) ) {
152
+ return true;
153
+ }
154
+
155
  return $this->get_weglot_url()->isTranslable() && $this->is_eligible_url( $this->get_full_url() );
156
  }
157
 
222
  * @return boolean
223
  */
224
  public function is_eligible_url( $url ) {
225
+ $destinations = weglot_get_destination_languages();
226
+ if ( empty( $destinations ) ) {
227
+ return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
 
230
+ $url_relative = urldecode( $this->url_to_relative( $url ) );
231
 
232
+ $exclude_urls_option = $this->option_services->get_exclude_urls();
 
 
233
 
234
+ $path_without_language = array_filter( explode( '/', $url_relative ), 'strlen' );
235
  $index_entries = count( $path_without_language );
236
  $custom_urls = $this->option_services->get_option( 'custom_urls' );
237
  $current_language = $this->get_current_language();
238
 
239
  $url_path_custom = null;
240
  if ( ! empty( $custom_urls ) && isset( $custom_urls[ $current_language ] ) && isset( $path_without_language[ $index_entries ] ) && isset( $custom_urls[ $current_language ][ $path_without_language[ $index_entries ] ] ) ) {
241
+ $url_path_custom = get_site_url() . '/' . $custom_urls[ $current_language ][ $path_without_language[ $index_entries ] ] . '/';
242
  }
243
 
244
+ $weglot_url = $this->create_url_object( $url );
245
+ $weglot_url->setExcludedUrls( $exclude_urls_option );
246
+ if ( ! $weglot_url->isTranslable() ) {
247
+ return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
248
+ }
 
 
249
 
250
+ if ( $url_path_custom ) {
251
+ $weglot_url = $this->create_url_object( $url_path_custom );
252
+ $weglot_url->setExcludedUrls( $exclude_urls_option );
253
+ if ( ! $weglot_url->isTranslable() ) {
254
+ return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
255
  }
256
  }
257
 
271
 
272
  /**
273
  * @since 2.0
 
274
  * @param string $url
275
  * @return string
276
  */
src/services/class-translate-json-service.php CHANGED
@@ -87,7 +87,7 @@ class Translate_Json_Service {
87
  try {
88
  $parser = $this->parser_services->get_parser();
89
  $words = $parser->parse( $val );
90
- if ( ! $words instanceof WordCollection ) {
91
  continue;
92
  }
93
  $this->collections = array_merge( $this->collections, $words->jsonSerialize() );
@@ -105,7 +105,7 @@ class Translate_Json_Service {
105
  try {
106
  $parser = $this->parser_services->get_parser();
107
  $words = $parser->parse( $val );
108
- if ( ! $words instanceof WordCollection ) {
109
  continue;
110
  }
111
  $this->collections = array_merge( $this->collections, $words->jsonSerialize() );
87
  try {
88
  $parser = $this->parser_services->get_parser();
89
  $words = $parser->parse( $val );
90
+ if ( ! $words instanceof WordCollection || $words->count() < 1 ) {
91
  continue;
92
  }
93
  $this->collections = array_merge( $this->collections, $words->jsonSerialize() );
105
  try {
106
  $parser = $this->parser_services->get_parser();
107
  $words = $parser->parse( $val );
108
+ if ( ! $words instanceof WordCollection || $words->count() < 1 ) {
109
  continue;
110
  }
111
  $this->collections = array_merge( $this->collections, $words->jsonSerialize() );
src/services/class-translate-service-weglot.php CHANGED
@@ -41,6 +41,7 @@ class Translate_Service_Weglot {
41
  public function weglot_translate() {
42
  $this->set_original_language( weglot_get_original_language() );
43
  $this->set_current_language( $this->request_url_services->get_current_language() );
 
44
  ob_start( [ $this, 'weglot_treat_page' ] );
45
  }
46
 
@@ -104,7 +105,6 @@ class Translate_Service_Weglot {
104
  return wp_json_encode( $content );
105
  case 'html':
106
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language ); // phpcs:ignore
107
-
108
  if ( $this->wc_active_services->is_active() ) {
109
  // Improve this with multiple service
110
  $translated_content = weglot_get_service( 'WC_Translate_Weglot' )->translate_words( $translated_content );
41
  public function weglot_translate() {
42
  $this->set_original_language( weglot_get_original_language() );
43
  $this->set_current_language( $this->request_url_services->get_current_language() );
44
+
45
  ob_start( [ $this, 'weglot_treat_page' ] );
46
  }
47
 
105
  return wp_json_encode( $content );
106
  case 'html':
107
  $translated_content = $parser->translate( $content, $this->original_language, $this->current_language ); // phpcs:ignore
 
108
  if ( $this->wc_active_services->is_active() ) {
109
  // Improve this with multiple service
110
  $translated_content = weglot_get_service( 'WC_Translate_Weglot' )->translate_words( $translated_content );
src/services/class-user-api-service-weglot.php CHANGED
@@ -6,13 +6,12 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
 
9
  /**
10
  * @since 2.0
11
  */
12
  class User_Api_Service_Weglot {
13
- const API_BASE = 'https://api.weglot.com';
14
- const API_BASE_OLD = 'https://weglot.com/api/';
15
-
16
  protected $user_info = null;
17
 
18
  /**
@@ -22,11 +21,11 @@ class User_Api_Service_Weglot {
22
  public function get_plans() {
23
  return [
24
  'starter_free' => [
25
- 'ids' => [ 18, 19, 1001, 1002 ],
26
  'limit_language' => 1,
27
  ],
28
  'business' => [
29
- 'ids' => [ 1, 4, 1003, 1004 ],
30
  'limit_language' => 5,
31
  ],
32
  ];
@@ -34,7 +33,7 @@ class User_Api_Service_Weglot {
34
 
35
  /**
36
  * @since 2.0
37
- * @version 2.0.1
38
  * @return array
39
  * @param null|string $api_key
40
  */
@@ -48,8 +47,9 @@ class User_Api_Service_Weglot {
48
  }
49
 
50
  try {
51
- $results = $this->do_request( self::API_BASE_OLD . 'user-info?api_key=' . $api_key, null );
52
  $json = \json_decode( $results, true );
 
53
  if ( \json_last_error() !== JSON_ERROR_NONE ) {
54
  throw new \Exception( 'Unknown error with Weglot Api (0001) : ' . \json_last_error() );
55
  }
@@ -67,12 +67,12 @@ class User_Api_Service_Weglot {
67
  $answer = $json['answer'];
68
  $this->user_info = $answer;
69
  return $this->user_info;
70
- } else {
71
- throw new \Exception( 'Unknown error with Weglot Api (0002) : ' . $json );
72
  }
 
 
73
  } catch ( \Exception $e ) {
74
  return [
75
- 'allowed' => true,
76
  ];
77
  }
78
  }
@@ -87,12 +87,12 @@ class User_Api_Service_Weglot {
87
  $plans = $this->get_plans();
88
  $limit = 1000;
89
  if (
90
- $user_info['plan'] <= 0 ||
91
- in_array( $user_info['plan'], $plans['starter_free']['ids'] ) // phpcs:ignore
92
  ) {
93
  $limit = $plans['starter_free']['limit_language'];
94
  } elseif (
95
- in_array( $user_info['plan'], $plans['business']['ids'] ) // phpcs:ignore
96
  ) {
97
  $limit = $plans['business']['limit_language'];
98
  }
6
  exit;
7
  }
8
 
9
+ use WeglotWP\Helpers\Helper_API;
10
+
11
  /**
12
  * @since 2.0
13
  */
14
  class User_Api_Service_Weglot {
 
 
 
15
  protected $user_info = null;
16
 
17
  /**
21
  public function get_plans() {
22
  return [
23
  'starter_free' => [
24
+ 'ids' => [ 2, 3 ],
25
  'limit_language' => 1,
26
  ],
27
  'business' => [
28
+ 'ids' => [ 4, 5 ],
29
  'limit_language' => 5,
30
  ],
31
  ];
33
 
34
  /**
35
  * @since 2.0
36
+ * @version 3.0.0
37
  * @return array
38
  * @param null|string $api_key
39
  */
47
  }
48
 
49
  try {
50
+ $results = $this->do_request( Helper_API::get_api_url() . '/projects/owner?api_key=' . $api_key, null );
51
  $json = \json_decode( $results, true );
52
+
53
  if ( \json_last_error() !== JSON_ERROR_NONE ) {
54
  throw new \Exception( 'Unknown error with Weglot Api (0001) : ' . \json_last_error() );
55
  }
67
  $answer = $json['answer'];
68
  $this->user_info = $answer;
69
  return $this->user_info;
 
 
70
  }
71
+
72
+ throw new \Exception( 'Unknown error with Weglot Api (0002) : ' . $json );
73
  } catch ( \Exception $e ) {
74
  return [
75
+ 'allowed' => false,
76
  ];
77
  }
78
  }
87
  $plans = $this->get_plans();
88
  $limit = 1000;
89
  if (
90
+ $user_info['plan_id'] <= 1 ||
91
+ in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) // phpcs:ignore
92
  ) {
93
  $limit = $plans['starter_free']['limit_language'];
94
  } elseif (
95
+ in_array( $user_info['plan_id'], $plans['business']['ids'] ) // phpcs:ignore
96
  ) {
97
  $limit = $plans['business']['limit_language'];
98
  }
src/third/calderaforms/class-caldera-translate.php CHANGED
@@ -55,7 +55,7 @@ class Caldera_Translate {
55
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
56
  }
57
 
58
- $client = new Client( weglot_get_option( 'api_key' ) );
59
  $translate = new Translate( $translate, $client );
60
 
61
  return $translate->handle();
@@ -88,7 +88,7 @@ class Caldera_Translate {
88
 
89
  $encoded = true;
90
 
91
- if ( in_array( $current_language, apply_filters('weglot_caldera_translate_languages_encoded_output', ['fr'] ), true ) ) {
92
  $encoded = false;
93
  }
94
 
55
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
56
  }
57
 
58
+ $client = $this->parser_services->get_client();
59
  $translate = new Translate( $translate, $client );
60
 
61
  return $translate->handle();
88
 
89
  $encoded = true;
90
 
91
+ if ( in_array( $current_language, apply_filters( 'weglot_caldera_translate_languages_encoded_output', [ 'fr' ] ), true ) ) {
92
  $encoded = false;
93
  }
94
 
src/third/gravityforms/class-gf-active.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Third\Gravityforms;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+
10
+ use WeglotWP\Models\Third_Active_Interface_Weglot;
11
+
12
+
13
+
14
+ /**
15
+ * @since 3.0
16
+ */
17
+ class GF_Active implements Third_Active_Interface_Weglot {
18
+
19
+ /**
20
+ * @since 3.0.0
21
+ * @return boolean
22
+ */
23
+ public function is_active() {
24
+ if ( ! function_exists( 'is_plugin_active' ) ) {
25
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
26
+ }
27
+
28
+ if ( ! is_plugin_active( 'gravityforms/gravityforms.php' ) ) {
29
+ return false;
30
+ }
31
+
32
+ return true;
33
+ }
34
+ }
src/third/gravityforms/class-gf-filter-urls.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace WeglotWP\Third\Gravityforms;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
+
12
+ /**
13
+ * @since 3.0.0
14
+ */
15
+ class GF_Filter_Urls implements Hooks_Interface_Weglot {
16
+
17
+ /**
18
+ * @since 2.0
19
+ * @return void
20
+ */
21
+ public function __construct() {
22
+ $this->gf_active_services = weglot_get_service( 'GF_Active' );
23
+ }
24
+
25
+ /**
26
+ * @since 3.0.0
27
+ * @see Hooks_Interface_Weglot
28
+ *
29
+ * @return void
30
+ */
31
+ public function hooks() {
32
+ if ( ! $this->gf_active_services->is_active() ) {
33
+ return;
34
+ }
35
+
36
+ add_filter( 'gform_confirmation', [ $this, 'weglot_gform_confirmation' ] );
37
+ }
38
+
39
+ /**
40
+ * @since 3.0.0
41
+ * @param array $data
42
+ * @return array
43
+ */
44
+ public function weglot_gform_confirmation( $data ) {
45
+ if( ! array_key_exists( 'redirect', $data ) ){
46
+ return $data;
47
+ }
48
+
49
+ $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_with_ajax($data['redirect']);
50
+ return $data;
51
+
52
+ }
53
+
54
+ }
src/third/ninjaforms/class-ninja-translate-json-weglot.php CHANGED
@@ -21,8 +21,17 @@ use WeglotWP\Helpers\Helper_Json_Inline_Weglot;
21
  * Ninja_Translate_Json_Weglot
22
  *
23
  * @since 2.5.0
 
24
  */
25
  class Ninja_Translate_Json_Weglot {
 
 
 
 
 
 
 
 
26
  protected function translate_entries( $all_words ) {
27
  // TranslateEntry
28
  $params = [
@@ -40,8 +49,8 @@ class Ninja_Translate_Json_Weglot {
40
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
41
  }
42
 
43
- $client = new Client( weglot_get_option( 'api_key' ) );
44
- $translate = new Translate( $translate, $client );
45
 
46
  return $translate->handle();
47
  }
21
  * Ninja_Translate_Json_Weglot
22
  *
23
  * @since 2.5.0
24
+ * @version 3.0.0
25
  */
26
  class Ninja_Translate_Json_Weglot {
27
+
28
+ /**
29
+ * @since 3.0.0
30
+ */
31
+ public function __construct() {
32
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
33
+ }
34
+
35
  protected function translate_entries( $all_words ) {
36
  // TranslateEntry
37
  $params = [
49
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
50
  }
51
 
52
+ $client = $this->parser_services->get_client();
53
+ $translate = new Translate( $translate, $client );
54
 
55
  return $translate->handle();
56
  }
src/third/woocommerce/class-wc-translate-weglot.php CHANGED
@@ -19,10 +19,18 @@ use WeglotWP\Helpers\Helper_Json_Inline_Weglot;
19
 
20
  /**
21
  * WC_Translate_Weglot
22
- *
23
  * @since 2.0
 
24
  */
25
  class WC_Translate_Weglot {
 
 
 
 
 
 
 
 
26
  protected function translate_entries( $all_words ) {
27
  // TranslateEntry
28
  $params = [
@@ -40,8 +48,8 @@ class WC_Translate_Weglot {
40
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
41
  }
42
 
43
- $client = new Client( weglot_get_option( 'api_key' ) );
44
- $translate = new Translate( $translate, $client );
45
 
46
  return $translate->handle();
47
  }
19
 
20
  /**
21
  * WC_Translate_Weglot
 
22
  * @since 2.0
23
+ * @version 3.0.0
24
  */
25
  class WC_Translate_Weglot {
26
+
27
+ /**
28
+ * @since 3.0.0
29
+ */
30
+ public function __construct() {
31
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
32
+ }
33
+
34
  protected function translate_entries( $all_words ) {
35
  // TranslateEntry
36
  $params = [
48
  $word_collection->addOne( new WordEntry( $value, WordType::TEXT ) );
49
  }
50
 
51
+ $client = $this->parser_services->get_client();
52
+ $translate = new Translate( $translate, $client );
53
 
54
  return $translate->handle();
55
  }
templates/admin/pages/settings.php CHANGED
@@ -6,12 +6,22 @@ if ( ! defined( 'ABSPATH' ) ) {
6
 
7
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
8
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  ?>
11
 
12
  <div id="wrap-weglot">
13
  <div class="wrap">
14
- <form method="post" id="mainform" action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>">
15
  <?php
16
 
17
 
@@ -37,7 +47,6 @@ use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
37
  }
38
 
39
  if ( ! in_array( $this->tab_active, [ Helper_Tabs_Admin_Weglot::STATUS ], true ) ) {
40
- settings_fields( WEGLOT_OPTION_GROUP );
41
  submit_button();
42
  }
43
  ?>
6
 
7
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
8
 
9
+ $url_form = wp_nonce_url(
10
+ add_query_arg(
11
+ [
12
+ 'action' => 'weglot_save_settings',
13
+ 'tab' => $this->tab_active,
14
+ ],
15
+ admin_url( 'admin-post.php' )
16
+ ),
17
+ 'weglot_save_settings'
18
+ );
19
 
20
  ?>
21
 
22
  <div id="wrap-weglot">
23
  <div class="wrap">
24
+ <form method="post" id="mainform" action="<?php echo esc_url( $url_form ); ?>">
25
  <?php
26
 
27
 
47
  }
48
 
49
  if ( ! in_array( $this->tab_active, [ Helper_Tabs_Admin_Weglot::STATUS ], true ) ) {
 
50
  submit_button();
51
  }
52
  ?>
templates/admin/pages/tabs/advanced.php CHANGED
@@ -5,8 +5,10 @@ if ( ! defined( 'ABSPATH' ) ) {
5
  }
6
 
7
  use Weglot\Client\Client;
 
8
 
9
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
 
10
 
11
  $options_available = [
12
  'exclude_urls' => [
@@ -58,76 +60,98 @@ foreach ( $languages as $key => $value ) {
58
  }
59
  }
60
 
 
 
61
  ?>
62
 
63
  <h3><?php esc_html_e( 'Translation Exclusion (Optional)', 'weglot' ); ?> </h3>
64
  <hr>
65
  <p><?php esc_html_e( 'By default, every page is translated. You can exclude parts of a page or a full page here.', 'weglot' ); ?></p>
66
  <table class="form-table">
67
- <tbody>
68
- <tr valign="top">
69
- <th scope="row" class="titledesc">
70
- <label for="<?php echo esc_attr( $options_available['exclude_urls']['key'] ); ?>">
71
- <?php echo esc_html( $options_available['exclude_urls']['label'] ); ?>
72
- </label>
73
- <p class="sub-label"><?php echo esc_html( $options_available['exclude_urls']['description'] ); ?></p>
74
- </th>
75
- <td class="forminp forminp-text">
76
- <div id="container-<?php echo esc_attr( $options_available['exclude_urls']['key'] ); ?>">
77
- <?php
78
  if ( ! empty( $this->options[ $options_available['exclude_urls']['key'] ] ) ) :
79
- foreach ( $this->options[ $options_available['exclude_urls']['key'] ] as $option ) :
 
 
 
 
 
 
80
  ?>
81
- <div class="item-exclude">
82
- <input
83
- type="text"
84
- placeholder="/my-awesome-url"
85
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['exclude_urls']['key'] ) ); ?>[]"
86
- value="<?php echo esc_attr( $option ); ?>"
87
- >
88
- <button class="js-btn-remove js-btn-remove-exclude-url">
89
- <span class="dashicons dashicons-minus"></span>
90
- </button>
91
- </div>
92
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
93
  endforeach;
94
- endif; ?>
95
- </div>
96
- <button id="js-add-exclude-url" class="btn btn-soft"><?php esc_html_e( 'Add an URL to exclude', 'weglot' ); ?></button>
97
- </td>
98
- </tr>
99
- <tr valign="top">
100
- <th scope="row" class="titledesc">
101
- <label for="<?php echo esc_attr( $options_available['exclude_blocks']['key'] ); ?>">
102
- <?php echo esc_html( $options_available['exclude_blocks']['label'] ); ?>
103
- </label>
104
- <p class="sub-label"><?php echo esc_html( $options_available['exclude_blocks']['description'] ); ?></p>
105
- </th>
106
- <td class="forminp forminp-text">
107
- <div id="container-<?php echo esc_attr( $options_available['exclude_blocks']['key'] ); ?>">
108
- <?php
 
109
  if ( ! empty( $this->options[ $options_available['exclude_blocks']['key'] ] ) ) :
110
  foreach ( $this->options[ $options_available['exclude_blocks']['key'] ] as $option ) :
111
  ?>
112
- <div class="item-exclude">
113
- <input
114
- type="text"
115
- placeholder=".my-class"
116
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['exclude_blocks']['key'] ) ); ?>[]"
117
- value="<?php echo esc_attr( $option ); ?>"
118
- >
119
- <button class="js-btn-remove js-btn-remove-exclude">
120
- <span class="dashicons dashicons-minus"></span>
121
- </button>
122
- </div>
123
- <?php
124
  endforeach;
125
- endif; ?>
126
- </div>
127
- <button id="js-add-exclude-block" class="btn btn-soft"><?php esc_html_e( 'Add a block to exclude', 'weglot' ); ?></button>
128
- </td>
129
- </tr>
130
- </tbody>
 
131
  </table>
132
 
133
  <h3><?php esc_html_e( 'Other options (Optional)', 'weglot' ); ?></h3>
@@ -142,7 +166,7 @@ foreach ( $languages as $key => $value ) {
142
  </th>
143
  <td class="forminp forminp-text">
144
  <input
145
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['auto_redirect']['key'] ) ); ?>"
146
  id="<?php echo esc_attr( $options_available['auto_redirect']['key'] ); ?>"
147
  type="checkbox"
148
  <?php checked( $this->options[ $options_available['auto_redirect']['key'] ], 1 ); ?>
@@ -158,7 +182,7 @@ foreach ( $languages as $key => $value ) {
158
  </th>
159
  <td class="forminp forminp-text">
160
  <input
161
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['email_translate']['key'] ) ); ?>"
162
  id="<?php echo esc_attr( $options_available['email_translate']['key'] ); ?>"
163
  type="checkbox"
164
  <?php checked( $this->options[ $options_available['email_translate']['key'] ], 1 ); ?>
@@ -174,7 +198,7 @@ foreach ( $languages as $key => $value ) {
174
  </th>
175
  <td class="forminp forminp-text">
176
  <input
177
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['translate_amp']['key'] ) ); ?>"
178
  id="<?php echo esc_attr( $options_available['translate_amp']['key'] ); ?>"
179
  type="checkbox"
180
  <?php checked( $this->options[ $options_available['translate_amp']['key'] ], 1 ); ?>
@@ -190,7 +214,7 @@ foreach ( $languages as $key => $value ) {
190
  </th>
191
  <td class="forminp forminp-text">
192
  <input
193
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['active_search']['key'] ) ); ?>"
194
  id="<?php echo esc_attr( $options_available['active_search']['key'] ); ?>"
195
  type="checkbox"
196
  <?php checked( $this->options[ $options_available['active_search']['key'] ], 1 ); ?>
@@ -209,20 +233,26 @@ foreach ( $languages as $key => $value ) {
209
  id="<?php echo esc_attr( $options_available['private_mode']['key'] ); ?>"
210
  name="<?php echo esc_attr( sprintf( '%s[%s][active]', WEGLOT_SLUG, $options_available['private_mode']['key'] ) ); ?>"
211
  type="checkbox"
212
- <?php checked( $this->options[ $options_available['private_mode']['key'] ]['active'], 1 ); ?>
 
 
 
 
213
  >
214
  <p class="description"><?php echo esc_html( $options_available['private_mode']['description'] ); ?></p>
215
  <div id="private-mode-detail">
216
- <?php foreach ( $languages as $key => $lang):
 
 
217
  if ( ! $lang ) {
218
  continue;
219
  }
220
 
221
  $checked_value = isset( $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] ) ? $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] : null;
222
- ?>
223
  <div class="private-mode-detail-lang">
224
  <input
225
- name="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>"
226
  id="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>"
227
  type="checkbox"
228
  class="private-mode-lang--input"
@@ -231,7 +261,9 @@ foreach ( $languages as $key => $value ) {
231
  <label for="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>">
232
  <?php
233
  // translators: 1 Local name language
234
- esc_html_e( sprintf( "Make '%s' a private language", $lang->getLocalName() ), 'weglot' ); ?>
 
 
235
  </label>
236
  </div>
237
  <?php endforeach; ?>
@@ -246,39 +278,57 @@ foreach ( $languages as $key => $value ) {
246
  <?php esc_html_e( 'If you need any help, you can contact us via email us at support@weglot.com.', 'weglot' ); ?>
247
  </p>
248
  <p>
249
- <?php esc_html_e( 'You can also return to version 1.13.1 by clicking on the button below', 'weglot' ); ?>
 
 
 
 
 
 
250
  </p>
251
  <p>
252
  <a href="<?php echo wp_nonce_url( admin_url( 'admin-post.php?action=weglot_rollback' ), 'weglot_rollback' ); //phpcs:ignore ?>" class="button">
253
- <?php echo esc_html__( 'Re-install version 1.13.1', 'weglot' ); ?>
 
 
 
 
 
254
  </a>
255
  </p>
256
  </div>
257
 
258
  <template id="tpl-exclusion-url">
259
- <div class="item-exclude">
260
- <input
261
- type="text"
262
- placeholder="/my-awesome-url"
263
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['exclude_urls']['key'] ) ); ?>[]"
264
- value=""
265
- >
266
- <button class="js-btn-remove js-btn-remove-exclude">
267
- <span class="dashicons dashicons-minus"></span>
268
- </button>
269
- </div>
 
 
 
 
 
 
 
270
  </template>
271
 
272
  <template id="tpl-exclusion-block">
273
- <div class="item-exclude">
274
- <input
275
- type="text"
276
- placeholder=".my-class"
277
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['exclude_blocks']['key'] ) ); ?>[]"
278
- value=""
279
- >
280
- <button class="js-btn-remove js-btn-remove-exclude">
281
- <span class="dashicons dashicons-minus"></span>
282
- </button>
283
- </div>
284
  </template>
5
  }
6
 
7
  use Weglot\Client\Client;
8
+ use Weglot\Util\Regex\RegexEnum;
9
 
10
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
11
+ use WeglotWP\Helpers\Helper_Excluded_Type;
12
 
13
  $options_available = [
14
  'exclude_urls' => [
60
  }
61
  }
62
 
63
+ $languages = array_values( $languages );
64
+
65
  ?>
66
 
67
  <h3><?php esc_html_e( 'Translation Exclusion (Optional)', 'weglot' ); ?> </h3>
68
  <hr>
69
  <p><?php esc_html_e( 'By default, every page is translated. You can exclude parts of a page or a full page here.', 'weglot' ); ?></p>
70
  <table class="form-table">
71
+ <tbody>
72
+ <tr valign="top">
73
+ <th scope="row" class="titledesc">
74
+ <label for="<?php echo esc_attr( $options_available['exclude_urls']['key'] ); ?>">
75
+ <?php echo esc_html( $options_available['exclude_urls']['label'] ); ?>
76
+ </label>
77
+ <p class="sub-label"><?php echo esc_html( $options_available['exclude_urls']['description'] ); ?></p>
78
+ </th>
79
+ <td class="forminp forminp-text">
80
+ <div id="container-<?php echo esc_attr( $options_available['exclude_urls']['key'] ); ?>">
81
+ <?php
82
  if ( ! empty( $this->options[ $options_available['exclude_urls']['key'] ] ) ) :
83
+ foreach ( $this->options[ $options_available['exclude_urls']['key'] ] as $key => $option ) :
84
+ $type_option = RegexEnum::MATCH_REGEX;
85
+ $value = $option;
86
+ if ( is_array( $option ) ) {
87
+ $type_option = $option['type'];
88
+ $value = $option['value'];
89
+ }
90
  ?>
91
+ <div class="item-exclude">
92
+ <select
93
+ name="<?php echo esc_attr( sprintf( '%s[excluded_paths][%s][type]', WEGLOT_SLUG, $key ) ); ?>"
94
+ >
95
+ <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $type ) : ?>
96
+ <option
97
+ value="<?php echo esc_attr( $type ); ?>"
98
+ <?php echo selected( $type_option, $type ); ?>
99
+ >
100
+ <?php echo esc_attr( Helper_Excluded_Type::get_label_type( $type ) ); ?>
101
+ </option>
102
+ <?php endforeach; ?>
103
+ </select>
104
+ <input
105
+ type="text"
106
+ placeholder="/my-awesome-url"
107
+ name="<?php echo esc_attr( sprintf( '%s[excluded_paths][%s][value]', WEGLOT_SLUG, $key ) ); ?>"
108
+ value="<?php echo esc_attr( $value ); ?>"
109
+ >
110
+ <button class="js-btn-remove js-btn-remove-exclude-url">
111
+ <span class="dashicons dashicons-minus"></span>
112
+ </button>
113
+ </div>
114
+ <?php
115
  endforeach;
116
+ endif;
117
+ ?>
118
+ </div>
119
+ <button id="js-add-exclude-url" class="btn btn-soft"><?php esc_html_e( 'Add an URL to exclude', 'weglot' ); ?></button>
120
+ </td>
121
+ </tr>
122
+ <tr valign="top">
123
+ <th scope="row" class="titledesc">
124
+ <label for="<?php echo esc_attr( $options_available['exclude_blocks']['key'] ); ?>">
125
+ <?php echo esc_html( $options_available['exclude_blocks']['label'] ); ?>
126
+ </label>
127
+ <p class="sub-label"><?php echo esc_html( $options_available['exclude_blocks']['description'] ); ?></p>
128
+ </th>
129
+ <td class="forminp forminp-text">
130
+ <div id="container-<?php echo esc_attr( $options_available['exclude_blocks']['key'] ); ?>">
131
+ <?php
132
  if ( ! empty( $this->options[ $options_available['exclude_blocks']['key'] ] ) ) :
133
  foreach ( $this->options[ $options_available['exclude_blocks']['key'] ] as $option ) :
134
  ?>
135
+ <div class="item-exclude">
136
+ <input
137
+ type="text"
138
+ placeholder=".my-class"
139
+ name="<?php echo esc_attr( sprintf( '%s[excluded_blocks][][value]', WEGLOT_SLUG ) ); ?>"
140
+ value="<?php echo esc_attr( $option ); ?>"
141
+ >
142
+ <button class="js-btn-remove js-btn-remove-exclude">
143
+ <span class="dashicons dashicons-minus"></span>
144
+ </button>
145
+ </div>
146
+ <?php
147
  endforeach;
148
+ endif;
149
+ ?>
150
+ </div>
151
+ <button id="js-add-exclude-block" class="btn btn-soft"><?php esc_html_e( 'Add a block to exclude', 'weglot' ); ?></button>
152
+ </td>
153
+ </tr>
154
+ </tbody>
155
  </table>
156
 
157
  <h3><?php esc_html_e( 'Other options (Optional)', 'weglot' ); ?></h3>
166
  </th>
167
  <td class="forminp forminp-text">
168
  <input
169
+ name="<?php echo esc_attr( sprintf( '%s[auto_switch]', WEGLOT_SLUG ) ); ?>"
170
  id="<?php echo esc_attr( $options_available['auto_redirect']['key'] ); ?>"
171
  type="checkbox"
172
  <?php checked( $this->options[ $options_available['auto_redirect']['key'] ], 1 ); ?>
182
  </th>
183
  <td class="forminp forminp-text">
184
  <input
185
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_email]', WEGLOT_SLUG ) ); ?>"
186
  id="<?php echo esc_attr( $options_available['email_translate']['key'] ); ?>"
187
  type="checkbox"
188
  <?php checked( $this->options[ $options_available['email_translate']['key'] ], 1 ); ?>
198
  </th>
199
  <td class="forminp forminp-text">
200
  <input
201
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_amp]', WEGLOT_SLUG ) ); ?>"
202
  id="<?php echo esc_attr( $options_available['translate_amp']['key'] ); ?>"
203
  type="checkbox"
204
  <?php checked( $this->options[ $options_available['translate_amp']['key'] ], 1 ); ?>
214
  </th>
215
  <td class="forminp forminp-text">
216
  <input
217
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][translate_search]', WEGLOT_SLUG ) ); ?>"
218
  id="<?php echo esc_attr( $options_available['active_search']['key'] ); ?>"
219
  type="checkbox"
220
  <?php checked( $this->options[ $options_available['active_search']['key'] ], 1 ); ?>
233
  id="<?php echo esc_attr( $options_available['private_mode']['key'] ); ?>"
234
  name="<?php echo esc_attr( sprintf( '%s[%s][active]', WEGLOT_SLUG, $options_available['private_mode']['key'] ) ); ?>"
235
  type="checkbox"
236
+ <?php
237
+ if ( array_key_exists( 'active', $this->options[ $options_available['private_mode']['key'] ] ) ) {
238
+ checked( $this->options[ $options_available['private_mode']['key'] ]['active'], 1 );
239
+ }
240
+ ?>
241
  >
242
  <p class="description"><?php echo esc_html( $options_available['private_mode']['description'] ); ?></p>
243
  <div id="private-mode-detail">
244
+ <?php
245
+ foreach ( $languages as $key => $lang ) :
246
+
247
  if ( ! $lang ) {
248
  continue;
249
  }
250
 
251
  $checked_value = isset( $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] ) ? $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] : null;
252
+ ?>
253
  <div class="private-mode-detail-lang">
254
  <input
255
+ name="<?php echo esc_attr( sprintf( '%s[languages][%s][enabled]', WEGLOT_SLUG, $key ) ); ?>"
256
  id="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>"
257
  type="checkbox"
258
  class="private-mode-lang--input"
261
  <label for="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>">
262
  <?php
263
  // translators: 1 Local name language
264
+ $str = __( 'Make "%s" a private language', 'weglot' );
265
+ echo esc_html( sprintf( $str, $lang->getLocalName() ), 'weglot' );
266
+ ?>
267
  </label>
268
  </div>
269
  <?php endforeach; ?>
278
  <?php esc_html_e( 'If you need any help, you can contact us via email us at support@weglot.com.', 'weglot' ); ?>
279
  </p>
280
  <p>
281
+ <?php
282
+ // translators: 1 Latest weglot version
283
+ $text = __( 'You can also return to version %s by clicking on the button below', 'weglot' );
284
+ $text = sprintf( $text, WEGLOT_LATEST_VERSION );
285
+
286
+ echo esc_html( $text );
287
+ ?>
288
  </p>
289
  <p>
290
  <a href="<?php echo wp_nonce_url( admin_url( 'admin-post.php?action=weglot_rollback' ), 'weglot_rollback' ); //phpcs:ignore ?>" class="button">
291
+ <?php
292
+ // translators: 1 Latest weglot version
293
+ $text = __( 'Re-install version %s', 'weglot' );
294
+ $text = sprintf( $text, WEGLOT_LATEST_VERSION );
295
+ echo esc_html( $text );
296
+ ?>
297
  </a>
298
  </p>
299
  </div>
300
 
301
  <template id="tpl-exclusion-url">
302
+ <div class="item-exclude">
303
+ <select
304
+ name="<?php echo esc_attr( sprintf( '%s[excluded_paths][{KEY}][type]', WEGLOT_SLUG ) ); ?>"
305
+ >
306
+ <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $type ) : ?>
307
+ <option value="<?php echo esc_attr( $type ); ?>"><?php echo esc_attr( Helper_Excluded_Type::get_label_type( $type ) ); ?></option>
308
+ <?php endforeach; ?>
309
+ </select>
310
+ <input
311
+ type="text"
312
+ placeholder="/my-awesome-url"
313
+ name="<?php echo esc_attr( sprintf( '%s[excluded_paths][{KEY}][value]', WEGLOT_SLUG ) ); ?>"
314
+ value=""
315
+ >
316
+ <button class="js-btn-remove js-btn-remove-exclude">
317
+ <span class="dashicons dashicons-minus"></span>
318
+ </button>
319
+ </div>
320
  </template>
321
 
322
  <template id="tpl-exclusion-block">
323
+ <div class="item-exclude">
324
+ <input
325
+ type="text"
326
+ placeholder=".my-class"
327
+ name="<?php echo esc_attr( sprintf( '%s[excluded_blocks][][value]', WEGLOT_SLUG ) ); ?>"
328
+ value=""
329
+ >
330
+ <button class="js-btn-remove js-btn-remove-exclude">
331
+ <span class="dashicons dashicons-minus"></span>
332
+ </button>
333
+ </div>
334
  </template>
templates/admin/pages/tabs/appearance.php CHANGED
@@ -4,6 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
 
7
 
8
  $options_available = [
9
  'type_flags' => [
@@ -41,6 +42,8 @@ $options_available = [
41
  ],
42
  ];
43
 
 
 
44
  ?>
45
  <style id="weglot-css-flag-css"></style>
46
  <style id="weglot-css-inline"></style>
@@ -68,7 +71,7 @@ $options_available = [
68
  </th>
69
  <td class="forminp forminp-text">
70
  <input
71
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['is_dropdown']['key'] ) ); ?>"
72
  id="<?php echo esc_attr( $options_available['is_dropdown']['key'] ); ?>"
73
  type="checkbox"
74
  <?php checked( $this->options[ $options_available['is_dropdown']['key'] ], 1 ); ?>
@@ -84,7 +87,7 @@ $options_available = [
84
  </th>
85
  <td class="forminp forminp-text">
86
  <input
87
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['with_flags']['key'] ) ); ?>"
88
  id="<?php echo esc_attr( $options_available['with_flags']['key'] ); ?>"
89
  type="checkbox"
90
  <?php checked( $this->options[ $options_available['with_flags']['key'] ], 1 ); ?>
@@ -101,19 +104,35 @@ $options_available = [
101
  <td class="forminp forminp-text">
102
  <select
103
  class="wg-input-select"
104
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['type_flags']['key'] ) ); ?>"
105
  id="<?php echo esc_attr( $options_available['type_flags']['key'] ); ?>"
106
  >
107
- <option <?php selected( $this->options[ $options_available['type_flags']['key'] ], '0' ); ?> value="0">
 
 
 
 
108
  <?php esc_html_e( 'Rectangle mat', 'weglot' ); ?>
109
  </option>
110
- <option <?php selected( $this->options[ $options_available['type_flags']['key'] ], '1' ); ?> value="1">
 
 
 
 
111
  <?php esc_html_e( 'Rectangle shiny', 'weglot' ); ?>
112
  </option>
113
- <option <?php selected( $this->options[ $options_available['type_flags']['key'] ], '2' ); ?> value="2">
 
 
 
 
114
  <?php esc_html_e( 'Square', 'weglot' ); ?>
115
  </option>
116
- <option <?php selected( $this->options[ $options_available['type_flags']['key'] ], '3' ); ?> value="3">
 
 
 
 
117
  <?php esc_html_e( 'Circle', 'weglot' ); ?>
118
  </option>
119
  </select>
@@ -196,7 +215,7 @@ $options_available = [
196
  </th>
197
  <td class="forminp forminp-text">
198
  <input
199
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['with_name']['key'] ) ); ?>"
200
  id="<?php echo esc_attr( $options_available['with_name']['key'] ); ?>"
201
  type="checkbox"
202
  <?php checked( $this->options[ $options_available['with_name']['key'] ], 1 ); ?>
@@ -212,7 +231,7 @@ $options_available = [
212
  </th>
213
  <td class="forminp forminp-text">
214
  <input
215
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['is_fullname']['key'] ) ); ?>"
216
  id="<?php echo esc_attr( $options_available['is_fullname']['key'] ); ?>"
217
  type="checkbox"
218
  <?php checked( $this->options[ $options_available['is_fullname']['key'] ], 1 ); ?>
@@ -235,7 +254,7 @@ $options_available = [
235
  type="text"
236
  rows="10"
237
  cols="30"
238
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['override_css']['key'] ) ); ?>" placeholder=".country-selector {
239
  margin-bottom: 20px;
240
  }"><?php echo $this->options[ $options_available['override_css']['key'] ]; //phpcs:ignore?></textarea>
241
  </tr>
4
  exit;
5
  }
6
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
7
+ use WeglotWP\Helpers\Helper_Flag_Type;
8
 
9
  $options_available = [
10
  'type_flags' => [
42
  ],
43
  ];
44
 
45
+
46
+
47
  ?>
48
  <style id="weglot-css-flag-css"></style>
49
  <style id="weglot-css-inline"></style>
71
  </th>
72
  <td class="forminp forminp-text">
73
  <input
74
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][button_style][is_dropdown]', WEGLOT_SLUG ) ); ?>"
75
  id="<?php echo esc_attr( $options_available['is_dropdown']['key'] ); ?>"
76
  type="checkbox"
77
  <?php checked( $this->options[ $options_available['is_dropdown']['key'] ], 1 ); ?>
87
  </th>
88
  <td class="forminp forminp-text">
89
  <input
90
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][button_style][with_flags]', WEGLOT_SLUG ) ); ?>"
91
  id="<?php echo esc_attr( $options_available['with_flags']['key'] ); ?>"
92
  type="checkbox"
93
  <?php checked( $this->options[ $options_available['with_flags']['key'] ], 1 ); ?>
104
  <td class="forminp forminp-text">
105
  <select
106
  class="wg-input-select"
107
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][button_style][flag_type]', WEGLOT_SLUG ) ); ?>"
108
  id="<?php echo esc_attr( $options_available['type_flags']['key'] ); ?>"
109
  >
110
+ <option
111
+ <?php selected( $this->options[ $options_available['type_flags']['key'] ], Helper_Flag_Type::RECTANGLE_MAT ); ?>
112
+ data-value="<?php echo esc_attr( Helper_Flag_Type::get_flag_number_with_type( Helper_Flag_Type::RECTANGLE_MAT ) ); ?>"
113
+ value="<?php echo esc_attr( Helper_Flag_Type::RECTANGLE_MAT ); ?>"
114
+ >
115
  <?php esc_html_e( 'Rectangle mat', 'weglot' ); ?>
116
  </option>
117
+ <option
118
+ <?php selected( $this->options[ $options_available['type_flags']['key'] ], Helper_Flag_Type::SHINY ); ?>
119
+ data-value="<?php echo esc_attr( Helper_Flag_Type::get_flag_number_with_type( Helper_Flag_Type::SHINY ) ); ?>"
120
+ value="<?php echo esc_attr( Helper_Flag_Type::SHINY ); ?>"
121
+ >
122
  <?php esc_html_e( 'Rectangle shiny', 'weglot' ); ?>
123
  </option>
124
+ <option
125
+ <?php selected( $this->options[ $options_available['type_flags']['key'] ], Helper_Flag_Type::SQUARE ); ?>
126
+ data-value="<?php echo esc_attr( Helper_Flag_Type::get_flag_number_with_type( Helper_Flag_Type::SQUARE ) ); ?>"
127
+ value="<?php echo esc_attr( Helper_Flag_Type::SQUARE ); ?>"
128
+ >
129
  <?php esc_html_e( 'Square', 'weglot' ); ?>
130
  </option>
131
+ <option
132
+ <?php selected( $this->options[ $options_available['type_flags']['key'] ], Helper_Flag_Type::CIRCLE ); ?>
133
+ data-value="<?php echo esc_attr( Helper_Flag_Type::get_flag_number_with_type( Helper_Flag_Type::CIRCLE ) ); ?>"
134
+ value="<?php echo esc_attr( Helper_Flag_Type::CIRCLE ); ?>"
135
+ >
136
  <?php esc_html_e( 'Circle', 'weglot' ); ?>
137
  </option>
138
  </select>
215
  </th>
216
  <td class="forminp forminp-text">
217
  <input
218
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][button_style][with_name]', WEGLOT_SLUG ) ); ?>"
219
  id="<?php echo esc_attr( $options_available['with_name']['key'] ); ?>"
220
  type="checkbox"
221
  <?php checked( $this->options[ $options_available['with_name']['key'] ], 1 ); ?>
231
  </th>
232
  <td class="forminp forminp-text">
233
  <input
234
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][button_style][full_name]', WEGLOT_SLUG ) ); ?>"
235
  id="<?php echo esc_attr( $options_available['is_fullname']['key'] ); ?>"
236
  type="checkbox"
237
  <?php checked( $this->options[ $options_available['is_fullname']['key'] ], 1 ); ?>
254
  type="text"
255
  rows="10"
256
  cols="30"
257
+ name="<?php echo esc_attr( sprintf( '%s[custom_settings][button_style][custom_css]', WEGLOT_SLUG ) ); ?>" placeholder=".country-selector {
258
  margin-bottom: 20px;
259
  }"><?php echo $this->options[ $options_available['override_css']['key'] ]; //phpcs:ignore?></textarea>
260
  </tr>
templates/admin/pages/tabs/custom-urls.php CHANGED
@@ -16,19 +16,19 @@ use Weglot\WeglotContext;
16
 
17
  <?php foreach ($options['custom_urls'] as $lang => $urls): ?>
18
 
19
- <h3><?php esc_html_e('Lang : ', 'weglot'); ?><?php echo $lang; ?></h3>
20
 
21
  <div style="display:flex;">
22
  <div style="flex:5; margin-right:10px;">
23
- <?php esc_html_e('Base URL :', 'weglot'); ?>
24
  </div>
25
  <div style="flex:5;">
26
- <?php esc_html_e('Custom URL :', 'weglot'); ?>
27
  </div>
28
  <div style="flex:1;"></div>
29
  </div>
30
  <?php
31
- foreach ($urls as $key => $value) {
32
  $keyGenerate = sprintf('%s-%s-%s', $lang, $key, $value); ?>
33
  <div style="display:flex;" id="<?php echo $keyGenerate; ?>">
34
  <div style="margin-right:10px; flex:5;">
16
 
17
  <?php foreach ($options['custom_urls'] as $lang => $urls): ?>
18
 
19
+ <h3><?php esc_html_e( 'Lang : ', 'weglot' ); ?><?php echo $lang; ?></h3>
20
 
21
  <div style="display:flex;">
22
  <div style="flex:5; margin-right:10px;">
23
+ <?php esc_html_e( 'Base URL :', 'weglot' ); ?>
24
  </div>
25
  <div style="flex:5;">
26
+ <?php esc_html_e( 'Custom URL :', 'weglot' ); ?>
27
  </div>
28
  <div style="flex:1;"></div>
29
  </div>
30
  <?php
31
+ foreach ( $urls as $key => $value ) {
32
  $keyGenerate = sprintf('%s-%s-%s', $lang, $key, $value); ?>
33
  <div style="display:flex;" id="<?php echo $keyGenerate; ?>">
34
  <div style="margin-right:10px; flex:5;">
templates/admin/pages/tabs/settings.php CHANGED
@@ -6,24 +6,23 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
7
 
8
  $options_available = [
9
- 'api_key' => [
10
- 'key' => 'api_key',
11
  'label' => __( 'API Key', 'weglot' ),
12
  'description' => __( 'Log in to <a target="_blank" href="https://weglot.com/register-wordpress">Weglot</a> to get your API key.', 'weglot' ),
13
  ],
14
- 'original_language' => [
15
  'key' => 'original_language',
16
  'label' => __( 'Original language', 'weglot' ),
17
  'description' => 'What is the original (current) language of your website?',
18
  ],
19
- 'destination_language' => [
20
  'key' => 'destination_language',
21
  'label' => __( 'Destination languages', 'weglot' ),
22
  'description' => 'Choose languages you want to translate into. Supported languages can be found <a target="_blank" href="https://weglot.com/translation-api#languages_code">here</a>.',
23
  ],
24
  ];
25
 
26
-
27
  $languages = $this->language_services->get_languages_available( [
28
  'sort' => true,
29
  ] );
@@ -38,19 +37,19 @@ $plans = $this->user_api_services->get_plans();
38
  <tbody>
39
  <tr valign="top">
40
  <th scope="row" class="titledesc">
41
- <label for="<?php echo esc_attr( $options_available['api_key']['key'] ); ?>">
42
- <?php echo esc_html( $options_available['api_key']['label'] ); ?>
43
  </label>
44
- <p class="sub-label"><?php echo $options_available['api_key']['description']; //phpcs:ignore ?></p>
45
  </th>
46
  <td class="forminp forminp-text">
47
  <input
48
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['api_key']['key'] ) ); ?>"
49
- id="<?php echo esc_attr( $options_available['api_key']['key'] ); ?>"
50
  type="text"
51
  required
52
  placeholder="wg_XXXXXXXXXXXX"
53
- value="<?php echo esc_attr( $this->options[ $options_available['api_key']['key'] ] ); ?>"
54
  >
55
  <br>
56
  <?php if ( $this->options['has_first_settings'] ) {
@@ -62,21 +61,21 @@ $plans = $this->user_api_services->get_plans();
62
  </tr>
63
  <tr valign="top">
64
  <th scope="row" class="titledesc">
65
- <label for="<?php echo esc_attr( $options_available['original_language']['key'] ); ?>">
66
- <?php echo esc_html( $options_available['original_language']['label'] ); ?>
67
  </label>
68
- <p class="sub-label"><?php echo $options_available['original_language']['description']; //phpcs:ignore ?></p>
69
  </th>
70
  <td class="forminp forminp-text">
71
  <select
72
  class="weglot-select weglot-select-original"
73
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['original_language']['key'] ) ); ?>"
74
- id="<?php echo esc_attr( $options_available['original_language']['key'] ); ?>"
75
  >
76
  <?php foreach ( $languages as $language ) : ?>
77
  <option
78
  value="<?php echo esc_attr( $language->getIso639() ); ?>"
79
- <?php selected( $language->getIso639(), $this->options[ $options_available['original_language']['key'] ] ); ?>
80
  >
81
  <?php esc_html_e( $language->getEnglishName(), 'weglot'); //phpcs:ignore ?>
82
  </option>
@@ -86,35 +85,37 @@ $plans = $this->user_api_services->get_plans();
86
  </tr>
87
  <tr valign="top">
88
  <th scope="row" class="titledesc">
89
- <label for="<?php echo esc_attr( $options_available['destination_language']['key'] ); ?>">
90
- <?php echo esc_html( $options_available['destination_language']['label'] ); ?>
91
  </label>
92
- <p class="sub-label"><?php echo $options_available['destination_language']['description']; //phpcs:ignore ?></p>
93
  </th>
94
 
95
  <td class="forminp forminp-text">
96
  <select
97
  class="weglot-select weglot-select-destination"
98
  style="display:none"
99
- name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['destination_language']['key'] ) ); ?>[]"
100
- id="<?php echo esc_attr( $options_available['destination_language']['key'] ); ?>"
101
  multiple="true"
102
  required
103
  >
104
- <?php foreach ( $this->options[ $options_available['destination_language']['key'] ] as $language ) :
105
- $languages[ $language ]; ?>
 
 
106
  <option
107
- value="<?php echo esc_attr( $language ); ?>"
108
  selected="selected"
109
  >
110
- <?php echo esc_html( $language ); ?>
111
  </option>
112
  <?php endforeach; ?>
113
 
114
  <?php foreach ( $languages as $language ) : ?>
115
  <option
116
  value="<?php echo esc_attr( $language->getIso639() ); ?>"
117
- <?php selected( true, in_array( $language->getIso639(), $this->options[ $options_available['destination_language']['key'] ], true ) ); ?>
118
  >
119
  <?php echo esc_html( $language->getLocalName() ); ?>
120
  </option>
@@ -122,21 +123,21 @@ $plans = $this->user_api_services->get_plans();
122
  </select>
123
 
124
  <?php
125
- if ( $user_info && isset( $user_info['plan'] ) && $user_info['plan'] <= 0 ) {
126
  ?>
127
  <p class="description">
128
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
129
  <?php echo sprintf( esc_html__( 'On the free plan, you can choose one language and use a maximum of 2000 words. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
130
  </p>
131
  <?php
132
- } elseif ( isset( $user_info['plan'] ) && in_array( $user_info['plan'], $plans['starter_free']['ids'] ) ) { //phpcs:ignore
133
  ?>
134
  <p class="description">
135
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
136
  <?php echo sprintf( esc_html__( 'On the Starter plan, you can choose one language. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
137
  </p>
138
  <?php
139
- } elseif ( isset( $user_info['plan'] ) && in_array( $user_info['plan'], $plans['business']['ids'] ) ) { //phpcs:ignore
140
  ?>
141
  <p class="description">
142
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
@@ -165,11 +166,11 @@ $plans = $this->user_api_services->get_plans();
165
  </div>
166
  </div>
167
  <?php
168
- if ( $this->options[ $options_available['destination_language']['key'] ] && count( $this->options[ $options_available['destination_language']['key'] ] ) > 0 ) :
169
  ?>
170
  <iframe
171
  style="visibility:hidden;"
172
- src="<?php echo esc_url( sprintf( '%s/%s', home_url(), $this->options[ $options_available['destination_language']['key'] ][0] ) ); ?>/" width="1" height="1">
173
  </iframe>
174
  <?php endif; ?>
175
  <?php endif; ?>
6
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
7
 
8
  $options_available = [
9
+ 'api_key_private' => [
10
+ 'key' => 'api_key_private',
11
  'label' => __( 'API Key', 'weglot' ),
12
  'description' => __( 'Log in to <a target="_blank" href="https://weglot.com/register-wordpress">Weglot</a> to get your API key.', 'weglot' ),
13
  ],
14
+ 'language_from' => [
15
  'key' => 'original_language',
16
  'label' => __( 'Original language', 'weglot' ),
17
  'description' => 'What is the original (current) language of your website?',
18
  ],
19
+ 'languages' => [
20
  'key' => 'destination_language',
21
  'label' => __( 'Destination languages', 'weglot' ),
22
  'description' => 'Choose languages you want to translate into. Supported languages can be found <a target="_blank" href="https://weglot.com/translation-api#languages_code">here</a>.',
23
  ],
24
  ];
25
 
 
26
  $languages = $this->language_services->get_languages_available( [
27
  'sort' => true,
28
  ] );
37
  <tbody>
38
  <tr valign="top">
39
  <th scope="row" class="titledesc">
40
+ <label for="<?php echo esc_attr( $options_available['api_key_private']['key'] ); ?>">
41
+ <?php echo esc_html( $options_available['api_key_private']['label'] ); ?>
42
  </label>
43
+ <p class="sub-label"><?php echo $options_available['api_key_private']['description']; //phpcs:ignore ?></p>
44
  </th>
45
  <td class="forminp forminp-text">
46
  <input
47
+ name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['api_key_private']['key'] ) ); ?>"
48
+ id="<?php echo esc_attr( $options_available['api_key_private']['key'] ); ?>"
49
  type="text"
50
  required
51
  placeholder="wg_XXXXXXXXXXXX"
52
+ value="<?php echo esc_attr( $this->options[ $options_available['api_key_private']['key'] ] ); ?>"
53
  >
54
  <br>
55
  <?php if ( $this->options['has_first_settings'] ) {
61
  </tr>
62
  <tr valign="top">
63
  <th scope="row" class="titledesc">
64
+ <label for="<?php echo esc_attr( $options_available['language_from']['key'] ); ?>">
65
+ <?php echo esc_html( $options_available['language_from']['label'] ); ?>
66
  </label>
67
+ <p class="sub-label"><?php echo $options_available['language_from']['description']; //phpcs:ignore ?></p>
68
  </th>
69
  <td class="forminp forminp-text">
70
  <select
71
  class="weglot-select weglot-select-original"
72
+ name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, 'language_from' ) ); ?>"
73
+ id="<?php echo esc_attr( $options_available['language_from']['key'] ); ?>"
74
  >
75
  <?php foreach ( $languages as $language ) : ?>
76
  <option
77
  value="<?php echo esc_attr( $language->getIso639() ); ?>"
78
+ <?php selected( $language->getIso639(), $this->options[ $options_available['language_from']['key'] ] ); ?>
79
  >
80
  <?php esc_html_e( $language->getEnglishName(), 'weglot'); //phpcs:ignore ?>
81
  </option>
85
  </tr>
86
  <tr valign="top">
87
  <th scope="row" class="titledesc">
88
+ <label for="<?php echo esc_attr( $options_available['languages']['key'] ); ?>">
89
+ <?php echo esc_html( $options_available['languages']['label'] ); ?>
90
  </label>
91
+ <p class="sub-label"><?php echo $options_available['languages']['description']; //phpcs:ignore ?></p>
92
  </th>
93
 
94
  <td class="forminp forminp-text">
95
  <select
96
  class="weglot-select weglot-select-destination"
97
  style="display:none"
98
+ name="<?php echo esc_attr( sprintf( '%s[languages][][language_to]', WEGLOT_SLUG ) ); ?>"
99
+ id="<?php echo esc_attr( $options_available['languages']['key'] ); ?>"
100
  multiple="true"
101
  required
102
  >
103
+ <?php foreach ( $this->options[ $options_available['languages']['key'] ] as $language ) :
104
+
105
+ $language = $languages[ $language ];
106
+ ?>
107
  <option
108
+ value="<?php echo esc_attr( $language->getIso639() ); ?>"
109
  selected="selected"
110
  >
111
+ <?php echo esc_html( $language->getLocalName() ); ?>
112
  </option>
113
  <?php endforeach; ?>
114
 
115
  <?php foreach ( $languages as $language ) : ?>
116
  <option
117
  value="<?php echo esc_attr( $language->getIso639() ); ?>"
118
+ <?php selected( true, in_array( $language->getIso639(), $this->options[ $options_available['languages']['key'] ], true ) ); ?>
119
  >
120
  <?php echo esc_html( $language->getLocalName() ); ?>
121
  </option>
123
  </select>
124
 
125
  <?php
126
+ if ( $user_info && isset( $user_info['plan_id'] ) && $user_info['plan_id'] <= 1 ) {
127
  ?>
128
  <p class="description">
129
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
130
  <?php echo sprintf( esc_html__( 'On the free plan, you can choose one language and use a maximum of 2000 words. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
131
  </p>
132
  <?php
133
+ } elseif ( isset( $user_info['plan_id'] ) && in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) ) { //phpcs:ignore
134
  ?>
135
  <p class="description">
136
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
137
  <?php echo sprintf( esc_html__( 'On the Starter plan, you can choose one language. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
138
  </p>
139
  <?php
140
+ } elseif ( isset( $user_info['plan_id'] ) && in_array( $user_info['plan_id'], $plans['business']['ids'] ) ) { //phpcs:ignore
141
  ?>
142
  <p class="description">
143
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
166
  </div>
167
  </div>
168
  <?php
169
+ if ( $this->options[ $options_available['languages']['key'] ] && count( $this->options[ $options_available['languages']['key'] ] ) > 0 ) :
170
  ?>
171
  <iframe
172
  style="visibility:hidden;"
173
+ src="<?php echo esc_url( sprintf( '%s/%s', home_url(), $this->options[ $options_available['languages']['key'] ][0] ) ); ?>/" width="1" height="1">
174
  </iframe>
175
  <?php endif; ?>
176
  <?php endif; ?>
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInite1098bd8183a6ef79167c2f7794e2531::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitb613fd1d18afcf8a668d35dbaba18ee4::getLoader();
vendor/composer/autoload_psr4.php CHANGED
@@ -8,4 +8,5 @@ $baseDir = dirname($vendorDir);
8
  return array(
9
  'Weglot\\' => array($vendorDir . '/weglot/weglot-php/src'),
10
  'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
 
11
  );
8
  return array(
9
  'Weglot\\' => array($vendorDir . '/weglot/weglot-php/src'),
10
  'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
11
+ 'Morphism\\' => array($vendorDir . '/gmulti/morphism-php/lib'),
12
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInite1098bd8183a6ef79167c2f7794e2531
6
  {
7
  private static $loader;
8
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInite1098bd8183a6ef79167c2f7794e2531
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInite1098bd8183a6ef79167c2f7794e2531', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInite1098bd8183a6ef79167c2f7794e2531', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
- call_user_func(\Composer\Autoload\ComposerStaticInite1098bd8183a6ef79167c2f7794e2531::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInite1098bd8183a6ef79167c2f7794e2531
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInite1098bd8183a6ef79167c2f7794e2531::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequiree1098bd8183a6ef79167c2f7794e2531($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
- function composerRequiree1098bd8183a6ef79167c2f7794e2531($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInitb613fd1d18afcf8a668d35dbaba18ee4
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInitb613fd1d18afcf8a668d35dbaba18ee4', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInitb613fd1d18afcf8a668d35dbaba18ee4', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
+ call_user_func(\Composer\Autoload\ComposerStaticInitb613fd1d18afcf8a668d35dbaba18ee4::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
+ $includeFiles = Composer\Autoload\ComposerStaticInitb613fd1d18afcf8a668d35dbaba18ee4::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
+ composerRequireb613fd1d18afcf8a668d35dbaba18ee4($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
+ function composerRequireb613fd1d18afcf8a668d35dbaba18ee4($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInite1098bd8183a6ef79167c2f7794e2531
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
@@ -19,6 +19,10 @@ class ComposerStaticInite1098bd8183a6ef79167c2f7794e2531
19
  array (
20
  'Psr\\Cache\\' => 10,
21
  ),
 
 
 
 
22
  );
23
 
24
  public static $prefixDirsPsr4 = array (
@@ -30,6 +34,10 @@ class ComposerStaticInite1098bd8183a6ef79167c2f7794e2531
30
  array (
31
  0 => __DIR__ . '/..' . '/psr/cache/src',
32
  ),
 
 
 
 
33
  );
34
 
35
  public static $prefixesPsr0 = array (
@@ -59,9 +67,9 @@ class ComposerStaticInite1098bd8183a6ef79167c2f7794e2531
59
  public static function getInitializer(ClassLoader $loader)
60
  {
61
  return \Closure::bind(function () use ($loader) {
62
- $loader->prefixLengthsPsr4 = ComposerStaticInite1098bd8183a6ef79167c2f7794e2531::$prefixLengthsPsr4;
63
- $loader->prefixDirsPsr4 = ComposerStaticInite1098bd8183a6ef79167c2f7794e2531::$prefixDirsPsr4;
64
- $loader->prefixesPsr0 = ComposerStaticInite1098bd8183a6ef79167c2f7794e2531::$prefixesPsr0;
65
 
66
  }, null, ClassLoader::class);
67
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitb613fd1d18afcf8a668d35dbaba18ee4
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
19
  array (
20
  'Psr\\Cache\\' => 10,
21
  ),
22
+ 'M' =>
23
+ array (
24
+ 'Morphism\\' => 9,
25
+ ),
26
  );
27
 
28
  public static $prefixDirsPsr4 = array (
34
  array (
35
  0 => __DIR__ . '/..' . '/psr/cache/src',
36
  ),
37
+ 'Morphism\\' =>
38
+ array (
39
+ 0 => __DIR__ . '/..' . '/gmulti/morphism-php/lib',
40
+ ),
41
  );
42
 
43
  public static $prefixesPsr0 = array (
67
  public static function getInitializer(ClassLoader $loader)
68
  {
69
  return \Closure::bind(function () use ($loader) {
70
+ $loader->prefixLengthsPsr4 = ComposerStaticInitb613fd1d18afcf8a668d35dbaba18ee4::$prefixLengthsPsr4;
71
+ $loader->prefixDirsPsr4 = ComposerStaticInitb613fd1d18afcf8a668d35dbaba18ee4::$prefixDirsPsr4;
72
+ $loader->prefixesPsr0 = ComposerStaticInitb613fd1d18afcf8a668d35dbaba18ee4::$prefixesPsr0;
73
 
74
  }, null, ClassLoader::class);
75
  }
vendor/composer/installed.json CHANGED
@@ -49,6 +49,43 @@
49
  "path"
50
  ]
51
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  {
53
  "name": "psr/cache",
54
  "version": "1.0.1",
@@ -146,17 +183,17 @@
146
  },
147
  {
148
  "name": "weglot/weglot-php",
149
- "version": "0.5.20",
150
- "version_normalized": "0.5.20.0",
151
  "source": {
152
  "type": "git",
153
  "url": "https://github.com/weglot/weglot-php.git",
154
- "reference": "6728f001f1bc393d95b1042e75af7fb0ff7434c1"
155
  },
156
  "dist": {
157
  "type": "zip",
158
- "url": "https://api.github.com/repos/weglot/weglot-php/zipball/6728f001f1bc393d95b1042e75af7fb0ff7434c1",
159
- "reference": "6728f001f1bc393d95b1042e75af7fb0ff7434c1",
160
  "shasum": ""
161
  },
162
  "require": {
@@ -168,7 +205,7 @@
168
  "codeception/codeception": "^2.4",
169
  "vlucas/phpdotenv": "^2.4"
170
  },
171
- "time": "2019-01-16T13:05:58+00:00",
172
  "type": "library",
173
  "installation-source": "dist",
174
  "autoload": {
49
  "path"
50
  ]
51
  },
52
+ {
53
+ "name": "gmulti/morphism-php",
54
+ "version": "0.3.0",
55
+ "version_normalized": "0.3.0.0",
56
+ "source": {
57
+ "type": "git",
58
+ "url": "https://github.com/Gmulti/morphism-php.git",
59
+ "reference": "0b4cc4e604452a724124b8d342635c4b0b0e9809"
60
+ },
61
+ "dist": {
62
+ "type": "zip",
63
+ "url": "https://api.github.com/repos/Gmulti/morphism-php/zipball/0b4cc4e604452a724124b8d342635c4b0b0e9809",
64
+ "reference": "0b4cc4e604452a724124b8d342635c4b0b0e9809",
65
+ "shasum": ""
66
+ },
67
+ "require-dev": {
68
+ "phpunit/phpunit": "^6.5"
69
+ },
70
+ "time": "2017-12-23T20:54:39+00:00",
71
+ "type": "project",
72
+ "installation-source": "dist",
73
+ "autoload": {
74
+ "psr-4": {
75
+ "Morphism\\": "lib/"
76
+ }
77
+ },
78
+ "notification-url": "https://packagist.org/downloads/",
79
+ "license": [
80
+ "MIT"
81
+ ],
82
+ "authors": [
83
+ {
84
+ "name": "Thomas DENEULIN",
85
+ "email": "thomas@delipress.io"
86
+ }
87
+ ]
88
+ },
89
  {
90
  "name": "psr/cache",
91
  "version": "1.0.1",
183
  },
184
  {
185
  "name": "weglot/weglot-php",
186
+ "version": "0.5.22",
187
+ "version_normalized": "0.5.22.0",
188
  "source": {
189
  "type": "git",
190
  "url": "https://github.com/weglot/weglot-php.git",
191
+ "reference": "30d870d0cce0d8fff2829c260465369b2245d1f7"
192
  },
193
  "dist": {
194
  "type": "zip",
195
+ "url": "https://api.github.com/repos/weglot/weglot-php/zipball/30d870d0cce0d8fff2829c260465369b2245d1f7",
196
+ "reference": "30d870d0cce0d8fff2829c260465369b2245d1f7",
197
  "shasum": ""
198
  },
199
  "require": {
205
  "codeception/codeception": "^2.4",
206
  "vlucas/phpdotenv": "^2.4"
207
  },
208
+ "time": "2019-03-19T12:51:48+00:00",
209
  "type": "library",
210
  "installation-source": "dist",
211
  "autoload": {
vendor/gmulti/morphism-php/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
1
+ vendor
2
+ composer.lock
vendor/gmulti/morphism-php/.travis.yml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ branches:
2
+ only:
3
+ - master
4
+ - develop
5
+
6
+ before_script:
7
+ - composer dump
8
+
9
+ language: php
10
+ php:
11
+ - '5.6'
12
+ - '7.0'
13
+ - '7.1'
14
+ - nightly
vendor/gmulti/morphism-php/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Thomas Deneulin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
vendor/gmulti/morphism-php/README.md ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Morphism PHP
2
+
3
+ [![Build Status][travis-image]][travis-url]
4
+ > Helps you to transform any object structure to another.
5
+
6
+ This library is inspired by Yann Renaudin's : [Morphism library](https://github.com/emyann/morphism)
7
+
8
+ ## Contribution
9
+
10
+ - Twitter: [@TDeneulin][twitter-account]
11
+ - Pull requests and stars are always welcome 🙏🏽 For bugs and feature requests, [please create an issue](https://github.com/Gmulti/morphism-php/issues)
12
+
13
+
14
+ ## Getting started 🚀
15
+
16
+ Install `morphism-php` using composer (soon).
17
+
18
+ ```php
19
+ use Morphism\Morphism;
20
+ ```
21
+
22
+ ## What does it do? 🤔
23
+
24
+ Morphism uses a semantic configuration to go through the collection of graph objects you have to process. Then it extracts and computes the value from the specified path(s). Finally, it sets this value to the destination property from the schema.
25
+
26
+ ## Usage 🍔
27
+ Morphism is curried function that allows a partial application with a semantic configuration. You can use it in many ways:
28
+
29
+ ### Example
30
+ ```php
31
+ // Target type you want to have
32
+ class User {
33
+ public function __construct($firstName, $lastName, $phoneNumber){
34
+ $this->firstName = $firstName;
35
+ $this->lastName = $lastName;
36
+ $this->phoneNumber = $phoneNumber;
37
+        $this->city = null;
38
+   }
39
+ }
40
+
41
+ // Data source you want to map
42
+ $data = array(
43
+ "name" => "Iron Man",
44
+ "firstName" => "Tony",
45
+ "lastName" => "Stark",
46
+ "address" => array(
47
+ "city" => "New York City",
48
+ "country" => "USA"
49
+ ),
50
+ "phoneNumber" => array(
51
+ array(
52
+ "type" => "home",
53
+ "number" => "212 555-1234"
54
+ ),
55
+ array(
56
+ "type" => "mobile",
57
+ "number" => "646 555-4567"
58
+ )
59
+ )
60
+ );
61
+
62
+ // Mapping Schema ( see more examples below )
63
+ $schema = array(
64
+ "city" => "address.city",
65
+ "name" => function($data){
66
+ return strtoupper($data["name"]);
67
+ }
68
+ );
69
+
70
+ Morphism::setMapper("User", $schema);
71
+
72
+ // Map using the registered type and the registry
73
+ $result = Morphism::map("User", $data);
74
+
75
+ /// *** OUTPUT *** ///
76
+
77
+ class User {
78
+ public $city // string(13) "New York City"
79
+ public $name // string(8) "iron man"
80
+ }
81
+ ```
82
+
83
+ ### Multidimensional array
84
+ ```php
85
+ // Target type you want to have
86
+ class User {
87
+ }
88
+
89
+ // Data source you want to map
90
+ $data = array(
91
+ array(
92
+ "name" => "Iron Man",
93
+ "firstName" => "Tony",
94
+ "lastName" => "Stark",
95
+ "address" => array(
96
+ "city" => "New York City",
97
+ "country" => "USA"
98
+ ),
99
+ "phoneNumber" => array(
100
+ array(
101
+ "type" => "home",
102
+ "number" => "212 555-1234"
103
+ ),
104
+ array(
105
+ "type" => "mobile",
106
+ "number" => "646 555-4567"
107
+ )
108
+ )
109
+ ),
110
+ array(
111
+ "name" => "Spiderman",
112
+ "firstName" => "Peter",
113
+ "lastName" => "Parker",
114
+ "address" => array(
115
+ "city" => "New York City",
116
+ "country" => "USA"
117
+ ),
118
+ "phoneNumber" => array(
119
+ array(
120
+ "type" => "home",
121
+ "number" => "999 999-9999"
122
+ )
123
+ )
124
+ )
125
+ );
126
+
127
+ // Mapping Schema ( see more examples below )
128
+ $schema = array(
129
+ "city" => "address.city",
130
+ "name" => function($data){
131
+ return strtoupper($data["name"]);
132
+ }
133
+ );
134
+
135
+ Morphism::setMapper("User", $schema);
136
+
137
+ // Map using the registered type and the registry
138
+ $result = Morphism::map("User", $data);
139
+
140
+ /// *** OUTPUT *** ///
141
+
142
+ array(
143
+ class User {
144
+ public $city // string(13) "New York City"
145
+ public $name // string(8) "iron man"
146
+ },
147
+ class User {
148
+ public $city // string(13) "New York City"
149
+ public $name // string(8) "spiderman"
150
+ }
151
+ )
152
+ ```
153
+
154
+ ## Schema Examples
155
+
156
+ ### Dataset sample
157
+ ```php
158
+ $data = array(
159
+ "name" => "Iron Man",
160
+ "firstName" => "Tony",
161
+ "lastName" => "Stark",
162
+ "address" => array(
163
+ "city" => "New York City",
164
+ "country" => "USA"
165
+ ),
166
+ "phoneNumber" => array(
167
+ array(
168
+ "type" => "home",
169
+ "number" => "212 555-1234"
170
+ ),
171
+ array(
172
+ "type" => "mobile",
173
+ "number" => "646 555-4567"
174
+ )
175
+ )
176
+ );
177
+
178
+ // Target type you want to have
179
+ class User {
180
+ }
181
+ ```
182
+
183
+ ### Agregator
184
+
185
+ ```php
186
+ // Schema
187
+ $schema = array(
188
+ "fullName" => array("firstName", "lastName")
189
+ );
190
+
191
+ Morphism::setMapper("User", $schema);
192
+
193
+ // Map using the registered type and the registry
194
+ $result = Morphism::map("User", $data);
195
+
196
+ /// *** OUTPUT *** ///
197
+
198
+ class User {
199
+ public $fullName // "Tony Stark"
200
+ }
201
+ ```
202
+
203
+ ### Computing over Flattening / Projection
204
+
205
+ ```php
206
+ // Schema
207
+ $schema = array(
208
+ "city" => (object) array(
209
+ "path" => "address.city",
210
+ "fn" => function($city) {
211
+ return strtolower($city);
212
+ }
213
+ ),
214
+ "nbContacts" => function($data){
215
+ return count($data["phoneNumber"]);
216
+ }
217
+ );
218
+
219
+ Morphism::setMapper("User", $schema);
220
+
221
+ // Map using the registered type and the registry
222
+ $result = Morphism::map("User", $data);
223
+
224
+ /// *** OUTPUT *** ///
225
+
226
+ class User {
227
+ public $city // "new york city" <= strtolower
228
+ public $nbContacts // 2 <= computed from the object
229
+ }
230
+ ```
231
+
232
+ ## License
233
+
234
+ MIT © [Thomas Deneulin][twitter-account]
235
+
236
+ [twitter-account]: https://twitter.com/TDeneulin
237
+ [travis-image]: https://travis-ci.org/Gmulti/morphism-php.svg?branch=master
238
+ [travis-url]: https://travis-ci.org/Gmulti/morphism-php
vendor/gmulti/morphism-php/composer.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "gmulti/morphism-php",
3
+ "type": "project",
4
+ "license": "MIT",
5
+ "authors": [
6
+ {
7
+ "name": "Thomas DENEULIN",
8
+ "email": "thomas@delipress.io"
9
+ }
10
+ ],
11
+ "minimum-stability": "stable",
12
+ "autoload": {
13
+ "psr-4": {
14
+ "Morphism\\": "lib/"
15
+ }
16
+ },
17
+ "require-dev": {
18
+ "phpunit/phpunit": "^6.5"
19
+ }
20
+ }
vendor/gmulti/morphism-php/lib/Helpers/MorphismHelper.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Morphism\Helpers;
4
+
5
+ trait MorphismHelper {
6
+
7
+ /**
8
+ * Source : https://stackoverflow.com/questions/5458241/php-dynamic-array-index-name
9
+ *
10
+ * @static
11
+ * @param array $array
12
+ * @param array $indexes
13
+ */
14
+ protected static function getArrayValue(array $array, array $indexes)
15
+ {
16
+ if (count($array) == 0 || count($indexes) == 0) {
17
+ return false;
18
+ }
19
+
20
+ $index = array_shift($indexes);
21
+ if(!array_key_exists($index, $array)){
22
+ return false;
23
+ }
24
+
25
+ $value = $array[$index];
26
+ if (count($indexes) == 0) {
27
+ return $value;
28
+ }
29
+
30
+ if(!is_array($value)) {
31
+ return false;
32
+ }
33
+
34
+ return self::getArrayValue($value, $indexes);
35
+ }
36
+
37
+ /**
38
+ * @static
39
+ * @param array $paths
40
+ * @param array $object
41
+ * @return string
42
+ */
43
+ protected static function agregator($paths, $object){
44
+ return array_reduce($paths, function($delta, $path) use ($object) {
45
+ $searchPath = $path;
46
+ if(!is_array($path)){
47
+ $searchPath = array($path);
48
+ }
49
+
50
+ return trim(sprintf("%s %s", $delta, self::getArrayValue($object, $searchPath) ));
51
+ });
52
+ }
53
+
54
+ /**
55
+ * @static
56
+ * @param array $object
57
+ * @param array $schema
58
+ * @param array $data
59
+ * @return object
60
+ */
61
+ protected static function transformValuesFromObject($object, $schema, $data){
62
+ foreach($schema as $key => $target){ // iterate on every action of the schema
63
+
64
+ if(is_string($target)){ // Target<String>: string path => [ target: 'source' ]
65
+ $indexes = explode(".", $target);
66
+ $object->{$key} = self::getArrayValue($data, $indexes);
67
+
68
+ }
69
+ else if(is_callable($target)){
70
+ $object->{$key} = call_user_func($target, $data);
71
+ }
72
+ else if (is_array($target)){
73
+ $object->{$key} = self::agregator($target, $data);
74
+ }
75
+ else if(is_object($target) ) {
76
+ $searchPath = $target->path;
77
+ if(is_array($target->path)){
78
+ $value = self::agregator($target->path, $data);
79
+ }
80
+ else{
81
+ $indexes = explode(".", $target->path);
82
+ $value = self::getArrayValue($data, $indexes);
83
+ }
84
+
85
+ $object->{$key} = call_user_func($target->fn, $value);
86
+ }
87
+ }
88
+
89
+ return $object;
90
+ }
91
+ }
vendor/gmulti/morphism-php/lib/Morphism.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Morphism;
4
+
5
+ use Morphism\Helpers\MorphismHelper;
6
+
7
+ abstract class Morphism {
8
+
9
+ use MorphismHelper;
10
+
11
+ protected static $registries = array();
12
+
13
+ public static function register($type, $schema) {
14
+
15
+ }
16
+
17
+ /**
18
+ * @static
19
+ * @param string $type
20
+ * @return bool
21
+ */
22
+ public static function exists($type){
23
+ return array_key_exists($type, self::$registries);
24
+ }
25
+
26
+ /**
27
+ * @static
28
+ * @param string $type
29
+ * @return array
30
+ */
31
+ public static function getMapper($type){
32
+ return self::$registries[$type];
33
+ }
34
+
35
+ /**
36
+ * @static
37
+ * @param string $type
38
+ * @param array $schema
39
+ */
40
+ public static function setMapper($type, $schema){
41
+ if (!$type) {
42
+ throw new \Exception('type paramater is required when register a mapping');
43
+ }
44
+ if (!$schema) {
45
+ throw new \Exception('schema paramater is required when register a mapping');
46
+ }
47
+
48
+ self::$registries[$type] = $schema;
49
+ }
50
+
51
+ /**
52
+ * @static
53
+ * @param string $type
54
+ */
55
+ public static function deleteMapper($type){
56
+ unset(self::$registries[$type]);
57
+ }
58
+
59
+ /**
60
+ * @static
61
+ * @param string $type
62
+ * @param array $data
63
+ */
64
+ public static function map($type, $data){
65
+ if(!Morphism::exists($type)){
66
+ throw new \Exception(sprintf("Mapper for %s not exist", $type));
67
+ }
68
+
69
+ $reflectedClass = new \ReflectionClass($type);
70
+
71
+ if(!$reflectedClass->isInstantiable()){
72
+ throw new \Exception($type . " is not an instantiable class.");
73
+ }
74
+
75
+ if(isset($data[0])){
76
+ return array_map(function($arr) use($reflectedClass, $type){
77
+ $instance = $reflectedClass->newInstance();
78
+ return self::transformValuesFromObject($instance, Morphism::getMapper($type), $arr);
79
+ }, $data);
80
+ }
81
+ else{
82
+ $instance = $reflectedClass->newInstance();
83
+ return self::transformValuesFromObject($instance, Morphism::getMapper($type), $data);
84
+ }
85
+ }
86
+ }
vendor/gmulti/morphism-php/phpunit.xml.dist ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <phpunit bootstrap="vendor/autoload.php" colors="true">
2
+ <testsuites>
3
+ <testsuite name="Morphism">
4
+ <directory>tests</directory>
5
+ </testsuite>
6
+ </testsuites>
7
+ </phpunit>
vendor/gmulti/morphism-php/tests/Mocks/User.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class User {
4
+
5
+ }
vendor/gmulti/morphism-php/tests/MorphismArrayTest.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use PHPUnit\Framework\TestCase;
4
+
5
+ use Morphism\Morphism;
6
+
7
+ class MorphismArrayTest extends TestCase
8
+ {
9
+ public function setUp(){
10
+ $this->data = array(
11
+ array(
12
+ "name" => "Iron Man",
13
+ "firstName" => "Tony",
14
+ "lastName" => "Stark",
15
+ "address" => array(
16
+ "city" => "New York City",
17
+ "country" => "USA"
18
+ ),
19
+ "phoneNumber" => array(
20
+ array(
21
+ "type" => "home",
22
+ "number" => "212 555-1234"
23
+ ),
24
+ array(
25
+ "type" => "mobile",
26
+ "number" => "646 555-4567"
27
+ )
28
+ )
29
+ ),
30
+ array(
31
+ "name" => "Spiderman",
32
+ "firstName" => "Peter",
33
+ "lastName" => "Parker",
34
+ "address" => array(
35
+ "city" => "New York City",
36
+ "country" => "USA"
37
+ ),
38
+ "phoneNumber" => array(
39
+ array(
40
+ "type" => "home",
41
+ "number" => "293 093-2321"
42
+ )
43
+ )
44
+ )
45
+ );
46
+ }
47
+
48
+
49
+ public function testActionArrayStringPath()
50
+ {
51
+ $schema = array(
52
+ "city" => "address.city"
53
+ );
54
+
55
+ Morphism::setMapper("User", $schema);
56
+
57
+ $result = Morphism::map("User", $this->data);
58
+
59
+ $this->assertEquals(count($result), 2);
60
+ $this->assertEquals($result[0]->city, "New York City");
61
+ }
62
+
63
+
64
+ public function testActionFunctionPath(){
65
+ $schema = array(
66
+ "city" => function($data){
67
+ return strtolower($data["address"]["city"]);
68
+ }
69
+ );
70
+
71
+ Morphism::setMapper("User", $schema);
72
+
73
+ $result = Morphism::map("User", $this->data);
74
+
75
+ $this->assertEquals($result[0]->city, "new york city");
76
+ $this->assertEquals($result[1]->city, "new york city");
77
+ }
78
+
79
+ public function testActionAgregatorPath(){
80
+ $schema = array(
81
+ "fullName" => array(
82
+ "firstName", "lastName"
83
+ )
84
+ );
85
+
86
+ Morphism::setMapper("User", $schema);
87
+
88
+ $result = Morphism::map("User", $this->data);
89
+
90
+ $this->assertEquals($result[0]->fullName, "Tony Stark");
91
+ $this->assertEquals($result[1]->fullName, "Peter Parker");
92
+ }
93
+
94
+ public function testActionFunctionObjectPath(){
95
+ $schema = array(
96
+ "city" => (object) array(
97
+ "path" => "address.city",
98
+ "fn" => function($city) {
99
+ return strtolower($city);
100
+ }
101
+ )
102
+ );
103
+
104
+ Morphism::setMapper("User", $schema);
105
+
106
+ $result = Morphism::map("User", $this->data);
107
+
108
+ $this->assertEquals($result[0]->city, "new york city");
109
+ $this->assertEquals($result[1]->city, "new york city");
110
+ }
111
+
112
+ }
vendor/gmulti/morphism-php/tests/MorphismTest.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use PHPUnit\Framework\TestCase;
4
+
5
+ use Morphism\Morphism;
6
+
7
+ require __DIR__ . "/Mocks/User.php";
8
+
9
+ class MorphismTest extends TestCase
10
+ {
11
+ public function setUp(){
12
+ $this->data = array(
13
+ "name" => "Iron Man",
14
+ "firstName" => "Tony",
15
+ "lastName" => "Stark",
16
+ "address" => array(
17
+ "city" => "New York City",
18
+ "country" => "USA"
19
+ ),
20
+ "phoneNumber" => array(
21
+ array(
22
+ "type" => "home",
23
+ "number" => "212 555-1234"
24
+ ),
25
+ array(
26
+ "type" => "mobile",
27
+ "number" => "646 555-4567"
28
+ )
29
+ )
30
+ );
31
+ }
32
+
33
+
34
+ public function testActionStringPath(){
35
+ $schema = array(
36
+ "city" => "address.city"
37
+ );
38
+
39
+ Morphism::setMapper("User", $schema);
40
+
41
+ $result = Morphism::map("User", $this->data);
42
+
43
+ $this->assertEquals($result->city, "New York City");
44
+
45
+ }
46
+
47
+ public function testActionFunctionPath(){
48
+ $schema = array(
49
+ "city" => function($data){
50
+ return strtolower($data["address"]["city"]);
51
+ }
52
+ );
53
+
54
+ Morphism::setMapper("User", $schema);
55
+
56
+ $result = Morphism::map("User", $this->data);
57
+
58
+ $this->assertEquals($result->city, "new york city");
59
+ }
60
+
61
+ public function testActionAgregatorPath(){
62
+ $schema = array(
63
+ "fullName" => array(
64
+ "firstName", "lastName"
65
+ )
66
+ );
67
+
68
+ Morphism::setMapper("User", $schema);
69
+
70
+ $result = Morphism::map("User", $this->data);
71
+
72
+ $this->assertEquals($result->fullName, "Tony Stark");
73
+ }
74
+
75
+ public function testActionFunctionObjectPath(){
76
+ $schema = array(
77
+ "city" => (object) array(
78
+ "path" => "address.city",
79
+ "fn" => function($city) {
80
+ return strtolower($city);
81
+ }
82
+ )
83
+ );
84
+
85
+ Morphism::setMapper("User", $schema);
86
+
87
+ $result = Morphism::map("User", $this->data);
88
+
89
+ $this->assertEquals($result->city, "new york city");
90
+ }
91
+ }
vendor/weglot/weglot-php/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
 
7
  ## [Unreleased]
8
 
 
 
 
 
 
 
9
  ## [0.5.12] - 2018-09-19
10
  Add escape property on dom checker
11
 
6
 
7
  ## [Unreleased]
8
 
9
+ ## [0.5.21] - 2019-03-12
10
+ ### Added
11
+ - Util Regex for excluded paths
12
+ ### Changed
13
+ - Update translation engine
14
+
15
  ## [0.5.12] - 2018-09-19
16
  Add escape property on dom checker
17
 
vendor/weglot/weglot-php/src/Client/Client.php CHANGED
@@ -58,12 +58,13 @@ class Client
58
  /**
59
  * Client constructor.
60
  * @param string $apiKey your Weglot API key
 
61
  * @param array $options an array of options, currently only "host" is implemented
62
  */
63
- public function __construct($apiKey, $options = [])
64
  {
65
  $this->apiKey = $apiKey;
66
- $this->profile = new Profile($apiKey);
67
 
68
  $this
69
  ->setHttpClient()
58
  /**
59
  * Client constructor.
60
  * @param string $apiKey your Weglot API key
61
+ * @param int $translationEngine
62
  * @param array $options an array of options, currently only "host" is implemented
63
  */
64
+ public function __construct($apiKey, $translationEngine, $options = [])
65
  {
66
  $this->apiKey = $apiKey;
67
+ $this->profile = new Profile($apiKey, $translationEngine);
68
 
69
  $this
70
  ->setHttpClient()
vendor/weglot/weglot-php/src/Client/Profile.php CHANGED
@@ -10,34 +10,36 @@ class Profile
10
  protected $version;
11
 
12
  /**
13
- * @var bool
14
  */
15
- protected $ignoredNodes;
16
 
17
  /**
18
  * Profile constructor.
19
  * @param string $apiKey
 
20
  */
21
- public function __construct($apiKey)
22
  {
23
- $this->setup($apiKey);
24
  }
25
 
26
  /**
27
  * @param string $apiKey
 
28
  */
29
- protected function setup($apiKey)
30
  {
31
  $apiKeyLength = \strlen($apiKey);
32
 
33
  if ($apiKeyLength === 35) {
34
  $this
35
  ->setApiVersion(1)
36
- ->setIgnoredNodes(false);
37
  } else {
38
  $this
39
  ->setApiVersion(2)
40
- ->setIgnoredNodes(true);
41
  }
42
  }
43
 
@@ -61,21 +63,21 @@ class Profile
61
  }
62
 
63
  /**
64
- * @param bool $ignoredNodes
65
  * @return $this
66
  */
67
- public function setIgnoredNodes($ignoredNodes)
68
  {
69
- $this->ignoredNodes = $ignoredNodes;
70
 
71
  return $this;
72
  }
73
 
74
  /**
75
- * @return bool
76
  */
77
- public function getIgnoredNodes()
78
  {
79
- return $this->ignoredNodes;
80
  }
81
  }
10
  protected $version;
11
 
12
  /**
13
+ * @var int
14
  */
15
+ protected $translationEngine;
16
 
17
  /**
18
  * Profile constructor.
19
  * @param string $apiKey
20
+ * @param int $translationEngine
21
  */
22
+ public function __construct($apiKey, $translationEngine)
23
  {
24
+ $this->setup($apiKey, $translationEngine);
25
  }
26
 
27
  /**
28
  * @param string $apiKey
29
+ * @param int $translationEngine
30
  */
31
+ protected function setup($apiKey, $translationEngine)
32
  {
33
  $apiKeyLength = \strlen($apiKey);
34
 
35
  if ($apiKeyLength === 35) {
36
  $this
37
  ->setApiVersion(1)
38
+ ->setTranslationEngine(1);
39
  } else {
40
  $this
41
  ->setApiVersion(2)
42
+ ->setTranslationEngine($translationEngine);
43
  }
44
  }
45
 
63
  }
64
 
65
  /**
66
+ * @param int $translationEngine
67
  * @return $this
68
  */
69
+ public function setTranslationEngine($translationEngine)
70
  {
71
+ $this->translationEngine = $translationEngine;
72
 
73
  return $this;
74
  }
75
 
76
  /**
77
+ * @return int
78
  */
79
+ public function getTranslationEngine()
80
  {
81
+ return $this->translationEngine;
82
  }
83
  }
vendor/weglot/weglot-php/src/Parser/Check/Dom/Text.php CHANGED
@@ -19,7 +19,7 @@ class Text extends AbstractDomChecker
19
  /**
20
  * {@inheritdoc}
21
  */
22
- const PROPERTY = 'outertext';
23
 
24
  /**
25
  * {@inheritdoc}
@@ -35,9 +35,9 @@ class Text extends AbstractDomChecker
35
  && $this->node->parent()->tag != 'style'
36
  && $this->node->parent()->tag != 'noscript'
37
  && $this->node->parent()->tag != 'code'
38
- && !is_numeric(TextUtil::fullTrim($this->node->outertext))
39
- && !preg_match('/^\d+%$/', TextUtil::fullTrim($this->node->outertext))
40
- && strpos($this->node->outertext, '[vc_') === false
41
- && strpos($this->node->outertext, '<?php') === false);
42
  }
43
  }
19
  /**
20
  * {@inheritdoc}
21
  */
22
+ const PROPERTY = 'innertext';
23
 
24
  /**
25
  * {@inheritdoc}
35
  && $this->node->parent()->tag != 'style'
36
  && $this->node->parent()->tag != 'noscript'
37
  && $this->node->parent()->tag != 'code'
38
+ && !is_numeric(TextUtil::fullTrim($this->node->innertext))
39
+ && !preg_match('/^\d+%$/', TextUtil::fullTrim($this->node->innertext))
40
+ && strpos($this->node->innertext, '[vc_') === false
41
+ && strpos($this->node->innertext, '<?php') === false);
42
  }
43
  }
vendor/weglot/weglot-php/src/Parser/Check/DomCheckerProvider.php CHANGED
@@ -12,6 +12,24 @@ use Weglot\Util\Text;
12
 
13
  class DomCheckerProvider
14
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  const DEFAULT_CHECKERS_NAMESPACE = '\\Weglot\\Parser\\Check\\Dom\\';
16
 
17
  /**
@@ -29,13 +47,20 @@ class DomCheckerProvider
29
  */
30
  protected $discoverCaching = [];
31
 
 
 
 
 
 
32
  /**
33
  * DomChecker constructor.
34
  * @param Parser $parser
 
35
  */
36
- public function __construct(Parser $parser)
37
  {
38
  $this->setParser($parser);
 
39
  $this->loadDefaultCheckers();
40
  }
41
 
@@ -58,6 +83,45 @@ class DomCheckerProvider
58
  return $this->parser;
59
  }
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  /**
62
  * @param $checker
63
  * @return $this
@@ -169,25 +233,188 @@ class DomCheckerProvider
169
  list($selector, $property, $wordType) = $class::toArray();
170
 
171
  $discoveringNodes = $this->discoverCachingGet($selector, $dom);
172
- foreach ($discoveringNodes as $k => $node) {
173
- $instance = new $class($node, $property);
174
-
175
- if ($instance->handle()) {
176
- $this->getParser()->getWords()->addOne(new WordEntry($node->$property, $wordType));
177
-
178
- $nodes[] = [
179
- 'node' => $node,
180
- 'class' => $class,
181
- 'property' => $property,
182
- ];
183
- } else {
184
- if (strpos($node->$property, '&gt;') !== false || strpos($node->$property, '&lt;') !== false) {
185
- $node->$property = str_replace(['&lt;', '&gt;'], ['<', '>'], $node->$property);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  }
187
  }
188
  }
189
- }
190
 
 
191
  return $nodes;
192
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  }
12
 
13
  class DomCheckerProvider
14
  {
15
+
16
+ /**
17
+ * @var array
18
+ */
19
+ protected $inlineNodes = [
20
+ 'a' , 'span',
21
+ 'strong', 'b',
22
+ 'em', 'i',
23
+ 'small', 'big',
24
+ 'sub', 'sup',
25
+ 'abbr',
26
+ 'acronym',
27
+ 'bdo',
28
+ 'cite',
29
+ 'kbd',
30
+ 'q', 'u'
31
+ ];
32
+
33
  const DEFAULT_CHECKERS_NAMESPACE = '\\Weglot\\Parser\\Check\\Dom\\';
34
 
35
  /**
47
  */
48
  protected $discoverCaching = [];
49
 
50
+ /**
51
+ * @var int
52
+ */
53
+ protected $translationEngine;
54
+
55
  /**
56
  * DomChecker constructor.
57
  * @param Parser $parser
58
+ * @param int $translationEngine
59
  */
60
+ public function __construct(Parser $parser, $translationEngine)
61
  {
62
  $this->setParser($parser);
63
+ $this->setTranslationEngine($translationEngine);
64
  $this->loadDefaultCheckers();
65
  }
66
 
83
  return $this->parser;
84
  }
85
 
86
+ /**
87
+ * @param array $inlineNodes
88
+ * @return $this
89
+ */
90
+ public function setInlineNodes($inlineNodes)
91
+ {
92
+ $this->inlineNodes = $inlineNodes;
93
+
94
+ return $this;
95
+ }
96
+
97
+ /**
98
+ * @return array
99
+ */
100
+ public function getInlineNodes()
101
+ {
102
+ return $this->inlineNodes;
103
+ }
104
+
105
+
106
+ /**
107
+ * @param int $translationEngine
108
+ * @return $this
109
+ */
110
+ public function setTranslationEngine($translationEngine)
111
+ {
112
+ $this->translationEngine = $translationEngine;
113
+
114
+ return $this;
115
+ }
116
+
117
+ /**
118
+ * @return int
119
+ */
120
+ public function getTranslationEngine()
121
+ {
122
+ return $this->translationEngine;
123
+ }
124
+
125
  /**
126
  * @param $checker
127
  * @return $this
233
  list($selector, $property, $wordType) = $class::toArray();
234
 
235
  $discoveringNodes = $this->discoverCachingGet($selector, $dom);
236
+
237
+ if($this->getTranslationEngine() <= 2) { // Old model
238
+ $this->handleOldEngine($discoveringNodes, $nodes , $class, $property, $wordType);
239
+ }
240
+ if($this->getTranslationEngine() == 3) { //New model
241
+
242
+ for ($i = 0; $i < count($discoveringNodes); $i++) {
243
+ $node = $discoveringNodes[$i];
244
+ $instance = new $class($node, $property);
245
+
246
+ if ($instance->handle()) {
247
+
248
+ $attributes = []; // Will contain attributes of merged node so that we can put them back after the API call.
249
+
250
+ if($selector === 'text') {
251
+
252
+ $shift = 0;
253
+
254
+ // If the parent node is eligible, we take it instead and we continue until it's not eligible.
255
+ while($number = $this->numberOfTextNodeInParentAfterChild($node->parentNode(), $node)) {
256
+
257
+ $node = $node->parentNode();
258
+ $shift = $number - 1;
259
+ }
260
+
261
+ // We descend the node to see if we can take a child instead, in the case there are wrapping node or empty nodes. For instance, In that case <p><b>Hello</b></p>, it's better to chose node "b" than "p"
262
+ $node = $this->getMinimalNode($node);
263
+
264
+ //We remove attributes from all child nodes and replace by wg-1, wg-2, etc... Real attributes are saved into $attributes.
265
+ $node = $this->removeAttributesFromChild($node, $attributes);
266
+
267
+ $i = $i + $shift;
268
+ }
269
+
270
+ $this->getParser()->getWords()->addOne(new WordEntry($node->$property, $wordType));
271
+
272
+ $nodes[] = [
273
+ 'node' => $node,
274
+ 'class' => $class,
275
+ 'property' => $property,
276
+ 'attributes' => $attributes,
277
+ ];
278
+
279
  }
280
  }
281
  }
 
282
 
283
+ }
284
  return $nodes;
285
  }
286
+
287
+ public function handleOldEngine($discoveringNodes, &$nodes, $class, $property, $wordType) {
288
+ foreach ($discoveringNodes as $k => $node) {
289
+ $instance = new $class($node, $property);
290
+
291
+ if ($instance->handle()) {
292
+ $this->getParser()->getWords()->addOne(new WordEntry($node->$property, $wordType));
293
+
294
+ $nodes[] = [
295
+ 'node' => $node,
296
+ 'class' => $class,
297
+ 'property' => $property,
298
+ ];
299
+ } else {
300
+ if (strpos($node->$property, '&gt;') !== false || strpos($node->$property, '&lt;') !== false) {
301
+ $node->$property = str_replace(['&lt;', '&gt;'], ['<', '>'], $node->$property);
302
+ }
303
+ }
304
+ }
305
+ }
306
+
307
+
308
+ // This function is important : It return the number of text node inside a given node, but it count only text node that are inside or after a given child (if no child is given it count everything)
309
+ // If at some point it find a block or a excluded block, it returns false.
310
+ public function numberOfTextNodeInParentAfterChild($node, $child = null) {
311
+
312
+ $count = 0;
313
+ if($this->isText($node)) {
314
+ $count++;
315
+ }
316
+
317
+
318
+ foreach($node->nodes as $n) {
319
+
320
+ if($this->isBlock($n) || $n->hasAttribute(Parser::ATTRIBUTE_NO_TRANSLATE)) {
321
+ return false;
322
+ }
323
+
324
+
325
+ if($child != null && $n->outertext() == $child->outertext()) {
326
+ $child = null;
327
+ }
328
+
329
+
330
+ if($child == null) {
331
+ $number = $this->numberOfTextNodeInParentAfterChild($n);
332
+ if($number === false) {
333
+ return false;
334
+ }
335
+ else {
336
+ $count += $number;
337
+ }
338
+ }
339
+ }
340
+ return $count;
341
+ }
342
+
343
+ public function getMinimalNode($node) {
344
+ if($this->isText($node)) {
345
+ return $node;
346
+ }
347
+
348
+ //We remove unnecessary wrapping nodes
349
+ while(count($node->nodes) == 1)
350
+ $node = $node->nodes[0];
351
+
352
+ $notEmptyChild = [];
353
+ foreach ($node->nodes as $n) {
354
+ if(!$this->hasOnlyEmptyChild($n)) {
355
+ $notEmptyChild[] = $n;
356
+ }
357
+ }
358
+
359
+ if(count($notEmptyChild) == 1) {
360
+ return $this->getMinimalNode($notEmptyChild[0]);
361
+ }
362
+
363
+
364
+ return $node;
365
+ }
366
+
367
+
368
+ public function removeAttributesFromChild($node, &$attributes) {
369
+
370
+ foreach ($node->children() as $child) {
371
+ $k = count($attributes)+1;
372
+ $attributes['wg-'.$k] = $child->getAllAttributes();
373
+ $child->attr = [];
374
+ $child->setAttribute('wg-'.$k, '');
375
+ $this->removeAttributesFromChild($child, $attributes);
376
+ }
377
+
378
+ return $node;
379
+ }
380
+
381
+ public function hasOnlyEmptyChild($node) {
382
+ if($this->isText($node)) {
383
+ if(Text::fullTrim($node->innertext()) != '')
384
+ return false;
385
+ else
386
+ return true;
387
+ }
388
+
389
+ foreach ($node->nodes as $child) {
390
+ if(!$this->hasOnlyEmptyChild($child))
391
+ return false;
392
+ }
393
+ return true;
394
+
395
+ }
396
+
397
+ public function isInline($node) {
398
+ return in_array($node->tag, $this->getInlineNodes());
399
+ }
400
+
401
+ public function isText($node) {
402
+ return $node->tag === 'text';
403
+ }
404
+
405
+ public function isBlock($node) {
406
+ return (!$this->isInline($node) && !$this->isText($node) && !($node->tag === 'br'));
407
+ }
408
+
409
+ public function isInlineOrText($node) {
410
+ return $this->isInline($node) || $this->isText($node);
411
+ }
412
+
413
+ public function unsetValue(array $array, $value, $strict = TRUE)
414
+ {
415
+ if(($key = array_search($value, $array, $strict)) !== FALSE) {
416
+ unset($array[$key]);
417
+ }
418
+ return $array;
419
+ }
420
  }
vendor/weglot/weglot-php/src/Parser/Formatter/DomFormatter.php CHANGED
@@ -16,15 +16,18 @@ class DomFormatter extends AbstractFormatter
16
  */
17
  public function handle(array $nodes)
18
  {
19
- $translated_words = $this->getTranslated()->getOutputWords();
 
 
 
20
 
21
  for ($i = 0; $i < \count($nodes); ++$i) {
22
  $currentNode = $nodes[$i];
23
 
24
  if ($translated_words[$i] !== null) {
25
- $currentTranslated = $translated_words[$i]->getWord();
26
 
27
- $this->metaContent($currentNode, $currentTranslated);
28
  $this->imageSource($currentNode, $currentTranslated, $i);
29
  }
30
  }
@@ -34,7 +37,7 @@ class DomFormatter extends AbstractFormatter
34
  * @param array $details
35
  * @param string $translated
36
  */
37
- protected function metaContent(array $details, $translated) {
38
  $property = $details['property'];
39
 
40
  if ($details['class']::ESCAPE_SPECIAL_CHAR) {
@@ -42,18 +45,47 @@ class DomFormatter extends AbstractFormatter
42
  } else {
43
  $details['node']->$property = $translated;
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
 
47
  protected function imageSource(array $details, $translated, $index) {
48
  $words = $this->getTranslated()->getInputWords();
49
 
50
- if ($details['class'] === '\Weglot\Parser\Check\Dom\ImageSource') {
51
- $details['node']->src = $translated;
52
- if ($details['node']->hasAttribute('srcset') &&
53
- $details['node']->srcset != '' &&
54
- $translated != $words[$index]->getWord()) {
55
- $details['node']->srcset = '';
 
56
  }
 
 
 
 
 
 
 
 
57
  }
 
58
  }
59
  }
16
  */
17
  public function handle(array $nodes)
18
  {
19
+ $translatable_attributes = $this->getTranslatableAttributes();
20
+
21
+ $original_words = array_column($this->getTranslated()->getInputWords()->jsonSerialize() , 'w');
22
+ $translated_words = array_column($this->getTranslated()->getOutputWords()->jsonSerialize() , 'w');
23
 
24
  for ($i = 0; $i < \count($nodes); ++$i) {
25
  $currentNode = $nodes[$i];
26
 
27
  if ($translated_words[$i] !== null) {
28
+ $currentTranslated = $translated_words[$i];
29
 
30
+ $this->metaContent($currentNode, $currentTranslated, $translatable_attributes, $original_words, $translated_words);
31
  $this->imageSource($currentNode, $currentTranslated, $i);
32
  }
33
  }
37
  * @param array $details
38
  * @param string $translated
39
  */
40
+ protected function metaContent(array $details, $translated, $translatable_attributes, $original_words, $translated_words) {
41
  $property = $details['property'];
42
 
43
  if ($details['class']::ESCAPE_SPECIAL_CHAR) {
45
  } else {
46
  $details['node']->$property = $translated;
47
  }
48
+
49
+ if(array_key_exists('attributes' , $details)) {
50
+ foreach ($details['attributes'] as $wg => $attributes) {
51
+ $attributeString = "";
52
+ foreach ($attributes as $key => $attribute) {
53
+ if(in_array($key, $translatable_attributes)) {
54
+ $pos = array_search($attribute, $original_words);
55
+ if($pos !== false) {
56
+ $attribute = $translated_words[$pos];
57
+ }
58
+ }
59
+ $attributeString .= $key."=\"".$attribute."\" ";
60
+ }
61
+ $attributeString = strlen($attributeString) > 0 ? " ".$attributeString:$attributeString;
62
+ $details['node']->$property = str_replace(" ".$wg.'=""', rtrim($attributeString), $details['node']->$property);
63
+ $details['node']->$property = str_replace(" ".$wg.'=\'\'', rtrim($attributeString), $details['node']->$property);
64
+ }
65
+ }
66
+
67
  }
68
 
69
  protected function imageSource(array $details, $translated, $index) {
70
  $words = $this->getTranslated()->getInputWords();
71
 
72
+ if ($details['class'] === '\Weglot\Parser\Check\Dom\ImageSource') {
73
+ $details['node']->src = $translated;
74
+ if ($details['node']->hasAttribute('srcset') &&
75
+ $details['node']->srcset != '' &&
76
+ $translated != $words[$index]->getWord()) {
77
+ $details['node']->srcset = '';
78
+ }
79
  }
80
+ }
81
+
82
+ protected function getTranslatableAttributes() {
83
+ $checkers = $this->getParser()->getDomCheckerProvider()->getCheckers();
84
+
85
+ $attributes= [];
86
+ foreach ($checkers as $class) {
87
+ $attributes[] = $class::toArray()[1];
88
  }
89
+ return $attributes;
90
  }
91
  }
vendor/weglot/weglot-php/src/Parser/Parser.php CHANGED
@@ -86,7 +86,7 @@ class Parser
86
  ->setConfigProvider($config)
87
  ->setExcludeBlocks($excludeBlocks)
88
  ->setWords(new WordCollection())
89
- ->setDomCheckerProvider(new DomCheckerProvider($this))
90
  ->setIgnoredNodesFormatter(new IgnoredNodes());
91
  }
92
 
@@ -258,7 +258,7 @@ class Parser
258
  ->setLanguageFrom($languageFrom)
259
  ->setLanguageTo($languageTo);
260
 
261
- if ($this->client->getProfile()->getIgnoredNodes()) {
262
  $ignoredNodesFormatter = $this->getIgnoredNodesFormatter();
263
 
264
  $ignoredNodesFormatter->setSource($source)
@@ -308,7 +308,7 @@ class Parser
308
  */
309
  public function parse($source)
310
  {
311
- if ($this->client->getProfile()->getIgnoredNodes()) {
312
  $ignoredNodesFormatter = $this->getIgnoredNodesFormatter();
313
 
314
  $ignoredNodesFormatter->setSource($source)
86
  ->setConfigProvider($config)
87
  ->setExcludeBlocks($excludeBlocks)
88
  ->setWords(new WordCollection())
89
+ ->setDomCheckerProvider(new DomCheckerProvider($this, $client->getProfile()->getTranslationEngine()))
90
  ->setIgnoredNodesFormatter(new IgnoredNodes());
91
  }
92
 
258
  ->setLanguageFrom($languageFrom)
259
  ->setLanguageTo($languageTo);
260
 
261
+ if ($this->client->getProfile()->getTranslationEngine() === 2) {
262
  $ignoredNodesFormatter = $this->getIgnoredNodesFormatter();
263
 
264
  $ignoredNodesFormatter->setSource($source)
308
  */
309
  public function parse($source)
310
  {
311
+ if ($this->client->getProfile()->getTranslationEngine() == 2) {
312
  $ignoredNodesFormatter = $this->getIgnoredNodesFormatter();
313
 
314
  $ignoredNodesFormatter->setSource($source)
vendor/weglot/weglot-php/src/Util/Regex.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Weglot\Util;
4
+
5
+ use Weglot\Util\Regex\RegexEnum;
6
+
7
+ /**
8
+ * Class Regex
9
+ * @package Weglot\Util
10
+ */
11
+ class Regex {
12
+ /**
13
+ * @param string $type
14
+ * @param string $value
15
+ */
16
+ public function __construct( $type, $value ) {
17
+ $this->type = $type;
18
+ $this->value = $value;
19
+ }
20
+
21
+ /**
22
+ * @return string
23
+ */
24
+ public function getRegex() {
25
+ $str = null;
26
+ switch ($this->type) {
27
+ case RegexEnum::START_WITH:
28
+ $str = sprintf('^%s', $this->value);
29
+ break;
30
+ case RegexEnum::END_WITH:
31
+ $str = sprintf('%s$', $this->value);
32
+ break;
33
+ case RegexEnum::CONTAIN:
34
+ $str = sprintf('%s', $this->value);
35
+ break;
36
+ case RegexEnum::IS_EXACTLY:
37
+ $str = sprintf('^%s$', $this->value);
38
+ break;
39
+ case RegexEnum::MATCH_REGEX:
40
+ return $this->value;
41
+ }
42
+
43
+ if ( null === $str) {
44
+ return $this->value;
45
+ }
46
+
47
+ return $str;
48
+ }
49
+ }
vendor/weglot/weglot-php/src/Util/Regex/RegexEnum.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Weglot\Util\Regex;
4
+
5
+ /**
6
+ * Class RegexEnum
7
+ * @package Weglot\Util
8
+ */
9
+ abstract class RegexEnum
10
+ {
11
+
12
+ /**
13
+ * @var string
14
+ */
15
+ const START_WITH = 'START_WITH';
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ const END_WITH = 'END_WITH';
21
+
22
+ /**
23
+ * @var string
24
+ */
25
+ const CONTAIN = 'CONTAIN';
26
+
27
+ /**
28
+ * @var string
29
+ */
30
+ const IS_EXACTLY = 'IS_EXACTLY';
31
+
32
+ /**
33
+ * @var string
34
+ */
35
+ const MATCH_REGEX = 'MATCH_REGEX';
36
+
37
+
38
+ }
vendor/weglot/weglot-php/tests/unit/Client/ClientCachingTest.php CHANGED
@@ -26,7 +26,7 @@ class ClientCachingTest extends \Codeception\Test\Unit
26
  */
27
  protected function _before()
28
  {
29
- $this->client = new Client(getenv('WG_API_KEY'));
30
 
31
  $this->redis = new Redis([
32
  'scheme' => getenv('REDIS_SCHEME'),
26
  */
27
  protected function _before()
28
  {
29
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
30
 
31
  $this->redis = new Redis([
32
  'scheme' => getenv('REDIS_SCHEME'),
vendor/weglot/weglot-php/tests/unit/Client/ClientTest.php CHANGED
@@ -20,7 +20,7 @@ class ClientTest extends \Codeception\Test\Unit
20
  */
21
  protected function _before()
22
  {
23
- $this->client = new Client(getenv('WG_API_KEY'));
24
  }
25
 
26
  // tests
@@ -53,15 +53,14 @@ class ClientTest extends \Codeception\Test\Unit
53
  public function testProfile()
54
  {
55
  $wgApiKeys = [
56
- 'wg_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' => 1,
57
  'wg_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' => 2
58
  ];
59
  foreach ($wgApiKeys as $wgApiKey => $version) {
60
- $client = new Client($wgApiKey);
61
  $profile = $client->getProfile();
62
 
63
  $this->assertEquals($version, $profile->getApiVersion());
64
- $this->assertEquals($version === 2, $profile->getIgnoredNodes());
65
  }
66
  }
67
 
20
  */
21
  protected function _before()
22
  {
23
+ $this->client = new Client(getenv('WG_API_KEY') , 3);
24
  }
25
 
26
  // tests
53
  public function testProfile()
54
  {
55
  $wgApiKeys = [
 
56
  'wg_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' => 2
57
  ];
58
  foreach ($wgApiKeys as $wgApiKey => $version) {
59
+ $client = new Client($wgApiKey , 3);
60
  $profile = $client->getProfile();
61
 
62
  $this->assertEquals($version, $profile->getApiVersion());
63
+ $this->assertEquals(3, $profile->getTranslationEngine());
64
  }
65
  }
66
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/CachedTranslateTest.php CHANGED
@@ -43,7 +43,7 @@ class CachedTranslateTest extends \Codeception\Test\Unit
43
  protected function _before()
44
  {
45
  // Client
46
- $this->client = new Client(getenv('WG_API_KEY'));
47
 
48
  // Redis
49
  $this->redis = new Redis([
43
  protected function _before()
44
  {
45
  // Client
46
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
47
 
48
  // Redis
49
  $this->redis = new Redis([
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/LanguagesTest.php CHANGED
@@ -26,7 +26,7 @@ class LanguagesTest extends \Codeception\Test\Unit
26
  */
27
  protected function _before()
28
  {
29
- $this->client = new Client(getenv('WG_API_KEY'));
30
  $endpoint = new Languages($this->client);
31
  $this->languages = $endpoint->handle();
32
  }
26
  */
27
  protected function _before()
28
  {
29
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
30
  $endpoint = new Languages($this->client);
31
  $this->languages = $endpoint->handle();
32
  }
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/StatusTest.php CHANGED
@@ -25,7 +25,7 @@ class StatusTest extends \Codeception\Test\Unit
25
  */
26
  protected function _before()
27
  {
28
- $this->client = new Client(getenv('WG_API_KEY'));
29
  $this->status = new Status($this->client);
30
  }
31
 
25
  */
26
  protected function _before()
27
  {
28
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
29
  $this->status = new Status($this->client);
30
  }
31
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/TranslateTest.php CHANGED
@@ -36,7 +36,7 @@ class TranslateTest extends \Codeception\Test\Unit
36
  protected function _before()
37
  {
38
  // Client
39
- $this->client = new Client(getenv('WG_API_KEY'));
40
 
41
  // TranslateEntry
42
  $params = [
36
  protected function _before()
37
  {
38
  // Client
39
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
40
 
41
  // TranslateEntry
42
  $params = [
vendor/weglot/weglot-php/tests/unit/Parser/Check/Dom/MetaContentTest.php CHANGED
@@ -42,10 +42,11 @@ class MetaContentTest extends \Codeception\Test\Unit
42
  $this->config = new ManualConfigProvider($this->url, BotType::HUMAN);
43
 
44
  // Client
45
- $this->client = new Client(getenv('WG_API_KEY'));
46
  }
47
 
48
  // tests
 
49
  public function testCheck()
50
  {
51
  // Parser
@@ -66,7 +67,7 @@ class MetaContentTest extends \Codeception\Test\Unit
66
 
67
  $this->assertEquals('This is my first web page, be kind :)', $oldContent);
68
  $this->assertNotEquals($oldContent, $newContent);
69
- }
70
 
71
  private function _getSimpleDom($source)
72
  {
42
  $this->config = new ManualConfigProvider($this->url, BotType::HUMAN);
43
 
44
  // Client
45
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
46
  }
47
 
48
  // tests
49
+ /*
50
  public function testCheck()
51
  {
52
  // Parser
67
 
68
  $this->assertEquals('This is my first web page, be kind :)', $oldContent);
69
  $this->assertNotEquals($oldContent, $newContent);
70
+ }*/
71
 
72
  private function _getSimpleDom($source)
73
  {
vendor/weglot/weglot-php/tests/unit/Parser/ParserTest.php CHANGED
@@ -52,7 +52,7 @@ class ParserTest extends \Codeception\Test\Unit
52
  ];
53
 
54
  // Client
55
- $this->client = new Client(getenv('WG_API_KEY'));
56
  }
57
 
58
  // tests
@@ -85,6 +85,70 @@ class ParserTest extends \Codeception\Test\Unit
85
  $this->assertTrue(\is_string($translatedContent));
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  private function _getContent($url)
89
  {
90
  // Fetching url content
52
  ];
53
 
54
  // Client
55
+ $this->client = new Client(getenv('WG_API_KEY'), 3);
56
  }
57
 
58
  // tests
85
  $this->assertTrue(\is_string($translatedContent));
86
  }
87
 
88
+ public function testParserEngine1NodeSplit()
89
+ {
90
+ $string = file_get_contents(__DIR__ . "/tests_parser_1.json");
91
+ $json_array = json_decode($string, true);
92
+
93
+
94
+ foreach ($json_array as $test) {
95
+
96
+ // Parser
97
+ $client = new Client(getenv('WG_API_KEY') , 1);
98
+ $this->parser = new Parser($client, $this->config['server']);
99
+
100
+ // Run the Parser
101
+ $strings = $this->parser->parse($test['body']);
102
+ foreach ($strings as $k => $string) {
103
+ $this->assertEquals( $test['expected'][$k]['w'], $string->getWord());
104
+ $this->assertEquals( $test['expected'][$k]['t'], $string->getType());
105
+ }
106
+ }
107
+ }
108
+
109
+ public function testParserEngine2NodeSplit()
110
+ {
111
+ $string = file_get_contents(__DIR__ . "/tests_parser_2.json");
112
+ $json_array = json_decode($string, true);
113
+
114
+
115
+ foreach ($json_array as $test) {
116
+
117
+ // Parser
118
+ $client = new Client(getenv('WG_API_KEY') , 2);
119
+ $this->parser = new Parser($client, $this->config['server']);
120
+
121
+ // Run the Parser
122
+ $strings = $this->parser->parse($test['body']);
123
+ foreach ($strings as $k => $string) {
124
+ $this->assertEquals( $test['expected'][$k]['w'], $string->getWord());
125
+ $this->assertEquals( $test['expected'][$k]['t'], $string->getType());
126
+ }
127
+ }
128
+ }
129
+
130
+ public function testParserEngine3NodeSplit()
131
+ {
132
+ $string = file_get_contents(__DIR__ . "/tests_parser_3.json");
133
+ $json_array = json_decode($string, true);
134
+
135
+
136
+ foreach ($json_array as $test) {
137
+
138
+ // Parser
139
+ $client = new Client(getenv('WG_API_KEY') , 3);
140
+ $this->parser = new Parser($client, $this->config['server']);
141
+
142
+ // Run the Parser
143
+ $strings = $this->parser->parse($test['body']);
144
+ foreach ($strings as $k => $string) {
145
+ $this->assertEquals( $test['expected'][$k]['w'], $string->getWord());
146
+ $this->assertEquals( $test['expected'][$k]['t'], $string->getType());
147
+ }
148
+ }
149
+ }
150
+
151
+
152
  private function _getContent($url)
153
  {
154
  // Fetching url content
vendor/weglot/weglot-php/tests/unit/Parser/tests_parser_1.json ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "Simple tag #1",
4
+ "body": "<p>Hello, <b>this is</b> a test!</p>",
5
+ "expected": [
6
+ {
7
+ "t": 1,
8
+ "w": "Hello, "
9
+ },
10
+ {
11
+ "t": 1,
12
+ "w": "this is"
13
+ },
14
+ {
15
+ "t": 1,
16
+ "w": " a test!"
17
+ }
18
+ ]
19
+ },
20
+ {
21
+ "name": "Nested tags 3",
22
+ "body": "<p>This is a sentence with <strong>bolded</strong> text and <em>italic text</em> and <div>other</div> text.</p>",
23
+ "expected": [
24
+ {
25
+ "t": 1,
26
+ "w": "This is a sentence with "
27
+ },
28
+ {
29
+ "t": 1,
30
+ "w": "bolded"
31
+ },
32
+ {
33
+ "t": 1,
34
+ "w": " text and "
35
+ },
36
+ {
37
+ "t": 1,
38
+ "w": "italic text"
39
+ },
40
+ {
41
+ "t": 1,
42
+ "w": " and "
43
+ },
44
+ {
45
+ "t": 1,
46
+ "w": "other"
47
+ },
48
+ {
49
+ "t": 1,
50
+ "w": " text."
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ "name": "Nested tags 4",
56
+ "body": "<p><strong>Everything is important</strong></p>",
57
+ "expected": [
58
+ {
59
+ "t": 1,
60
+ "w": "Everything is important"
61
+ }
62
+ ]
63
+ },
64
+ {
65
+ "name": "Nested tags 5",
66
+ "body": "<p>We believe <strong>everything is <em>really</em> important</strong></p>",
67
+ "expected": [
68
+ {
69
+ "t": 1,
70
+ "w": "We believe "
71
+ },
72
+ {
73
+ "t": 1,
74
+ "w": "everything is "
75
+ },
76
+ {
77
+ "t": 1,
78
+ "w": "really"
79
+ },
80
+ {
81
+ "t": 1,
82
+ "w": " important"
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "name": "Link tag",
88
+ "body": "<p>Hello, <a href='#'>this is</a> a test!</p>",
89
+ "expected": [
90
+ {
91
+ "t": 1,
92
+ "w": "Hello, "
93
+ },
94
+ {
95
+ "t": 1,
96
+ "w": "this is"
97
+ },
98
+ {
99
+ "t": 1,
100
+ "w": " a test!"
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "name": "Button tag",
106
+ "body": "<form><button value='Click me!'></button></form>",
107
+ "expected": [
108
+ {
109
+ "t": 2,
110
+ "w": "Click me!"
111
+ }
112
+ ]
113
+ },
114
+ {
115
+ "name": "Input tag",
116
+ "body": "<form><input type='text' placeholder='This is a placeholder!'></form>",
117
+ "expected": [
118
+ {
119
+ "t": 3,
120
+ "w": "This is a placeholder!"
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "name": "Meta tag",
126
+ "body": "<meta name='description' content='This is a website description!'>",
127
+ "expected": [
128
+ {
129
+ "t": 4,
130
+ "w": "This is a website description!"
131
+ }
132
+ ]
133
+ },
134
+ {
135
+ "name": "Image tag",
136
+ "body": "<p><img src='/an-image.png' alt='This is an image!'></p>",
137
+ "expected": [
138
+ {
139
+ "t": 7,
140
+ "w": "This is an image!"
141
+ },
142
+ {
143
+ "t": 6,
144
+ "w": "/an-image.png"
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "name": "Link tag with pdf",
150
+ "body": "<p><a href='/my-document.pdf'>Click here!</a></p>",
151
+ "expected": [
152
+ {
153
+ "t": 8,
154
+ "w": "/my-document.pdf"
155
+ },
156
+ {
157
+ "t": 1,
158
+ "w": "Click here!"
159
+ }
160
+ ]
161
+ }
162
+ ]
vendor/weglot/weglot-php/tests/unit/Parser/tests_parser_2.json ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "Simple tag #1",
4
+ "body": "<p>Hello, <b>this is</b> a test!</p>",
5
+ "expected": [
6
+ {
7
+ "t": 1,
8
+ "w": "Hello, &lt;b&gt;this is&lt;/b&gt; a test!"
9
+ }
10
+ ]
11
+ },
12
+ {
13
+ "name": "Simple tag #2",
14
+ "body": "<p>Hello, <strong>this is</strong> a test!</p>",
15
+ "expected": [
16
+ {
17
+ "t": 1,
18
+ "w": "Hello, &lt;strong&gt;this is&lt;/strong&gt; a test!"
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "name": "Simple tag #3",
24
+ "body": "<p>Hello, <em>this is</em> a test!</p>",
25
+ "expected": [
26
+ {
27
+ "t": 1,
28
+ "w": "Hello, &lt;em&gt;this is&lt;/em&gt; a test!"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "name": "Simple tag #4",
34
+ "body": "<p>This is a normal sentence</p>",
35
+ "expected": [
36
+ {
37
+ "t": 1,
38
+ "w": "This is a normal sentence"
39
+ }
40
+ ]
41
+ },
42
+ {
43
+ "name": "Nested simple tags",
44
+ "body": "<p>Hello, <i><b>this is</b></i> a test!</p>",
45
+ "expected": [
46
+ {
47
+ "t": 1,
48
+ "w": "Hello, &lt;i&gt;&lt;b&gt;this is&lt;/b&gt;&lt;/i&gt; a test!"
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "name": "Nested tags 2",
54
+ "body": "<p>This is a sentence with <strong>bolded</strong> text.</p>",
55
+ "expected": [
56
+ {
57
+ "t": 1,
58
+ "w": "This is a sentence with &lt;strong&gt;bolded&lt;/strong&gt; text."
59
+ }
60
+ ]
61
+ },
62
+ {
63
+ "name": "Nested tags 3",
64
+ "body": "<p>This is a sentence with <strong>bolded</strong> text and <em>italic text</em> and <div>other</div> text.</p>",
65
+ "expected": [
66
+ {
67
+ "t": 1,
68
+ "w": "This is a sentence with &lt;strong&gt;bolded&lt;/strong&gt; text and &lt;em&gt;italic text&lt;/em&gt; and "
69
+ },
70
+ {
71
+ "t": 1,
72
+ "w": "other"
73
+ },
74
+ {
75
+ "t": 1,
76
+ "w": " text."
77
+ }
78
+ ]
79
+ },
80
+ {
81
+ "name": "Nested tags 4",
82
+ "body": "<p><strong>Everything is important</strong></p>",
83
+ "expected": [
84
+ {
85
+ "t": 1,
86
+ "w": "&lt;strong&gt;Everything is important&lt;/strong&gt;"
87
+ }
88
+ ]
89
+ },
90
+ {
91
+ "name": "Nested tags 5",
92
+ "body": "<p>We believe <strong>everything is <em>really</em> important</strong></p>",
93
+ "expected": [
94
+ {
95
+ "t": 1,
96
+ "w": "We believe &lt;strong&gt;everything is &lt;em&gt;really&lt;/em&gt; important&lt;/strong&gt;"
97
+ }
98
+ ]
99
+ },
100
+ {
101
+ "name": "Link tag",
102
+ "body": "<p>Hello, <a href='#'>this is</a> a test!</p>",
103
+ "expected": [
104
+ {
105
+ "t": 1,
106
+ "w": "Hello, "
107
+ },
108
+ {
109
+ "t": 1,
110
+ "w": "this is"
111
+ },
112
+ {
113
+ "t": 1,
114
+ "w": " a test!"
115
+ }
116
+ ]
117
+ },
118
+ {
119
+ "name": "Button tag",
120
+ "body": "<form><button value='Click me!'></button></form>",
121
+ "expected": [
122
+ {
123
+ "t": 2,
124
+ "w": "Click me!"
125
+ }
126
+ ]
127
+ },
128
+ {
129
+ "name": "Input tag",
130
+ "body": "<form><input type='text' placeholder='This is a placeholder!'></form>",
131
+ "expected": [
132
+ {
133
+ "t": 3,
134
+ "w": "This is a placeholder!"
135
+ }
136
+ ]
137
+ },
138
+ {
139
+ "name": "Meta tag",
140
+ "body": "<meta name='description' content='This is a website description!'>",
141
+ "expected": [
142
+ {
143
+ "t": 4,
144
+ "w": "This is a website description!"
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "name": "Image tag",
150
+ "body": "<p><img src='/an-image.png' alt='This is an image!'></p>",
151
+ "expected": [
152
+ {
153
+ "t": 7,
154
+ "w": "This is an image!"
155
+ },
156
+ {
157
+ "t": 6,
158
+ "w": "/an-image.png"
159
+ }
160
+ ]
161
+ },
162
+ {
163
+ "name": "Link tag with pdf",
164
+ "body": "<p><a href='/my-document.pdf'>Click here!</a></p>",
165
+ "expected": [
166
+ {
167
+ "t": 8,
168
+ "w": "/my-document.pdf"
169
+ },
170
+ {
171
+ "t": 1,
172
+ "w": "Click here!"
173
+ }
174
+ ]
175
+ }
176
+ ]
vendor/weglot/weglot-php/tests/unit/Parser/tests_parser_3.json ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name": "Simple tag #1",
4
+ "body": "<p>Hello, <b>this is</b> a test!</p>",
5
+ "expected": [
6
+ {
7
+ "t": 1,
8
+ "w": "Hello, <b wg-1=\"\">this is</b> a test!"
9
+ }
10
+ ]
11
+ },
12
+ {
13
+ "name": "Simple tag #2",
14
+ "body": "<p>Hello, <strong>this is</strong> a test!</p>",
15
+ "expected": [
16
+ {
17
+ "t": 1,
18
+ "w": "Hello, <strong wg-1=\"\">this is</strong> a test!"
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "name": "Simple tag #3",
24
+ "body": "<p>Hello, <em>this is</em> a test!</p>",
25
+ "expected": [
26
+ {
27
+ "t": 1,
28
+ "w": "Hello, <em wg-1=\"\">this is</em> a test!"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "name": "Simple tag #4",
34
+ "body": "<p>This is a normal sentence</p>",
35
+ "expected": [
36
+ {
37
+ "t": 1,
38
+ "w": "This is a normal sentence"
39
+ }
40
+ ]
41
+ },
42
+ {
43
+ "name": "Nested simple tags",
44
+ "body": "<p>Hello, <i><b>this is</b></i> a test!</p>",
45
+ "expected": [
46
+ {
47
+ "t": 1,
48
+ "w": "Hello, <i wg-1=\"\"><b wg-2=\"\">this is</b></i> a test!"
49
+ }
50
+ ]
51
+ },
52
+ {
53
+ "name": "Nested tags 2",
54
+ "body": "<p>This is a sentence with <strong>bolded</strong> text.</p>",
55
+ "expected": [
56
+ {
57
+ "t": 1,
58
+ "w": "This is a sentence with <strong wg-1=\"\">bolded</strong> text."
59
+ }
60
+ ]
61
+ },
62
+ {
63
+ "name": "Nested tags 3",
64
+ "body": "<p>This is a sentence with <strong>bolded</strong> text and <em>italic text</em> and <div>other</div> text.</p>",
65
+ "expected": [
66
+ {
67
+ "t": 1,
68
+ "w": "This is a sentence with "
69
+ },
70
+ {
71
+ "t": 1,
72
+ "w": "bolded"
73
+ },
74
+ {
75
+ "t": 1,
76
+ "w": " text and "
77
+ },
78
+ {
79
+ "t": 1,
80
+ "w": "italic text"
81
+ },
82
+ {
83
+ "t": 1,
84
+ "w": " and "
85
+ },
86
+ {
87
+ "t": 1,
88
+ "w": "other"
89
+ },
90
+ {
91
+ "t": 1,
92
+ "w": " text."
93
+ }
94
+ ]
95
+ },
96
+ {
97
+ "name": "Nested tags 4",
98
+ "body": "<p><strong>Everything is important</strong></p>",
99
+ "expected": [
100
+ {
101
+ "t": 1,
102
+ "w": "Everything is important"
103
+ }
104
+ ]
105
+ },
106
+ {
107
+ "name": "Nested tags 5",
108
+ "body": "<p>We believe <strong>everything is <em>really</em> important</strong></p>",
109
+ "expected": [
110
+ {
111
+ "t": 1,
112
+ "w": "We believe <strong wg-1=\"\">everything is <em wg-2=\"\">really</em> important</strong>"
113
+ }
114
+ ]
115
+ },
116
+ {
117
+ "name": "Nested tags 6",
118
+ "body": "<p>We believe <strong><strong>everything</strong></strong><em><em> is important</em></em></p>",
119
+ "expected": [
120
+ {
121
+ "t": 1,
122
+ "w": "We believe <strong wg-1=\"\"><strong wg-2=\"\">everything</strong></strong><em wg-3=\"\"><em wg-4=\"\"> is important</em></em>"
123
+ }
124
+ ]
125
+ },
126
+ {
127
+ "name": "Nested tags 7",
128
+ "body": "<p><abbr><i></i><i></i><strong><strong>Hello, </strong></strong><em><em>how are you</em></em><i></i></abbr></p>",
129
+ "expected": [
130
+ {
131
+ "t": 1,
132
+ "w": "<i wg-1=\"\"></i><i wg-2=\"\"></i><strong wg-3=\"\"><strong wg-4=\"\">Hello, </strong></strong><em wg-5=\"\"><em wg-6=\"\">how are you</em></em><i wg-7=\"\"></i>"
133
+ }
134
+ ]
135
+ },
136
+ {
137
+ "name": "Nested tags 8",
138
+ "body": "<p><abbr><i></i><i></i><b><strong><strong>Hello, </strong></strong><em><em>how are you</em></em></b><i></i></abbr></p>",
139
+ "expected": [
140
+ {
141
+ "t": 1,
142
+ "w": "<strong wg-1=\"\"><strong wg-2=\"\">Hello, </strong></strong><em wg-3=\"\"><em wg-4=\"\">how are you</em></em>"
143
+ }
144
+ ]
145
+ },
146
+ {
147
+ "name": "Nested tags 9",
148
+ "body": "<p><abbr><i></i><i></i><b><strong><strong>Hello, </strong></strong></b><i></i></abbr></p>",
149
+ "expected": [
150
+ {
151
+ "t": 1,
152
+ "w": "Hello, "
153
+ }
154
+ ]
155
+ },
156
+ {
157
+ "name": "Nested tags 10",
158
+ "body": " <p><b>Hello </b><b>this is</b></p><p>bonjour</p><p><b>Hi </b><b>we are</b></p> ",
159
+ "expected": [
160
+ {
161
+ "t": 1,
162
+ "w": "<b wg-1=\"\">Hello </b><b wg-2=\"\">this is</b>"
163
+ },
164
+ {
165
+ "t": 1,
166
+ "w": "bonjour"
167
+ },
168
+ {
169
+ "t": 1,
170
+ "w": "<b wg-1=\"\">Hi </b><b wg-2=\"\">we are</b>"
171
+ }
172
+ ]
173
+ },
174
+ {
175
+ "name": "Nested tags 11",
176
+ "body": " <p><b>Hello </b> <b>this is</b></p> <i> </i> <p>bonjour</p><p><b>Hi </b><b>we are</b></p> ",
177
+ "expected": [
178
+ {
179
+ "t": 1,
180
+ "w": "<b wg-1=\"\">Hello </b> <b wg-2=\"\">this is</b>"
181
+ },
182
+ {
183
+ "t": 1,
184
+ "w": "bonjour"
185
+ },
186
+ {
187
+ "t": 1,
188
+ "w": "<b wg-1=\"\">Hi </b><b wg-2=\"\">we are</b>"
189
+ }
190
+ ]
191
+ },
192
+ {
193
+ "name": "Nested tags 12",
194
+ "body": " <p> <b>Hello</b> <i> </i> <i></i></p><p>This</p><p>is</p> ",
195
+ "expected": [
196
+ {
197
+ "t": 1,
198
+ "w": "Hello"
199
+ },
200
+ {
201
+ "t": 1,
202
+ "w": "This"
203
+ },
204
+ {
205
+ "t": 1,
206
+ "w": "is"
207
+ }
208
+ ]
209
+ },
210
+ {
211
+ "name": "Nested tags 13",
212
+ "body": " <p><b>8</b><b> Hello </b></p><p> Hi</p><p>Cool</p>",
213
+ "expected": [
214
+ {
215
+ "t": 1,
216
+ "w": "<b wg-1=\"\">8</b><b wg-2=\"\"> Hello </b>"
217
+ },
218
+ {
219
+ "t": 1,
220
+ "w": " Hi"
221
+ },
222
+ {
223
+ "t": 1,
224
+ "w": "Cool"
225
+ }
226
+ ]
227
+ },
228
+ {
229
+ "name": "tag with br",
230
+ "body": "<p>Hello, <br /> a test!</p>",
231
+ "expected": [
232
+ {
233
+ "t": 1,
234
+ "w": "Hello, <br wg-1=\"\" /> a test!"
235
+ }
236
+ ]
237
+ },
238
+ {
239
+ "name": "tag with br",
240
+ "body": "<p>Hello, <br> a test! how are <b>you</b></p>",
241
+ "expected": [
242
+ {
243
+ "t": 1,
244
+ "w": "Hello, <br wg-1=\"\"> a test! how are <b wg-2=\"\">you</b>"
245
+ }
246
+ ]
247
+ },
248
+ {
249
+ "name": "Exclude tags 1",
250
+ "body": " <p><b>Hello </b><b data-wg-notranslate>man</b></p> ",
251
+ "expected": [
252
+ {
253
+ "t": 1,
254
+ "w": "Hello "
255
+ }
256
+ ]
257
+ },
258
+ {
259
+ "name": "Link tag",
260
+ "body": "<p>Hello, <a href='#'>this is</a> a test!</p>",
261
+ "expected": [
262
+ {
263
+ "t": 1,
264
+ "w": "Hello, <a wg-1=''>this is</a> a test!"
265
+ }
266
+ ]
267
+ },
268
+ {
269
+ "name": "Link tag with title",
270
+ "body": "<p>Hello, <a href='#' title='title needs translation'>this is</a> a test!</p>",
271
+ "expected": [
272
+ {
273
+ "t": 1,
274
+ "w": "title needs translation"
275
+ },
276
+ {
277
+ "t": 1,
278
+ "w": "Hello, <a wg-1=''>this is</a> a test!"
279
+ }
280
+ ]
281
+ },
282
+ {
283
+ "name": "Link tag with title 2",
284
+ "body": "<p>Hello, <b><a href='#' class='translate' title='translate'>this is</a> a <a href='#' title='link needs translation'>link</a></b> and a test!</p>",
285
+ "expected": [
286
+ {
287
+ "t": 1,
288
+ "w": "translate"
289
+ },
290
+ {
291
+ "t": 1,
292
+ "w": "link needs translation"
293
+ },
294
+ {
295
+ "t": 1,
296
+ "w": "Hello, <b wg-1=\"\"><a wg-2=''>this is</a> a <a wg-3=''>link</a></b> and a test!"
297
+ }
298
+ ]
299
+ },
300
+ {
301
+ "name": "Button tag",
302
+ "body": "<form><button value='Click me!'></button></form>",
303
+ "expected": [
304
+ {
305
+ "t": 2,
306
+ "w": "Click me!"
307
+ }
308
+ ]
309
+ },
310
+ {
311
+ "name": "Input tag",
312
+ "body": "<form><input type='text' placeholder='This is a placeholder!'></form>",
313
+ "expected": [
314
+ {
315
+ "t": 3,
316
+ "w": "This is a placeholder!"
317
+ }
318
+ ]
319
+ },
320
+ {
321
+ "name": "Meta tag",
322
+ "body": "<meta name='description' content='This is a website description!'>",
323
+ "expected": [
324
+ {
325
+ "t": 4,
326
+ "w": "This is a website description!"
327
+ }
328
+ ]
329
+ },
330
+ {
331
+ "name": "Image tag",
332
+ "body": "<p><img src='/an-image.png' alt='This is an image!'></p>",
333
+ "expected": [
334
+ {
335
+ "t": 7,
336
+ "w": "This is an image!"
337
+ },
338
+ {
339
+ "t": 6,
340
+ "w": "/an-image.png"
341
+ }
342
+ ]
343
+ },
344
+ {
345
+ "name": "Link tag with pdf",
346
+ "body": "<p><a href='/my-document.pdf'>Click here!</a></p>",
347
+ "expected": [
348
+ {
349
+ "t": 8,
350
+ "w": "/my-document.pdf"
351
+ },
352
+ {
353
+ "t": 1,
354
+ "w": "Click here!"
355
+ }
356
+ ]
357
+ }
358
+ ]
vendor/weglot/weglot-php/tests/unit/Util/RegexTest.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Weglot\Util\Regex;
4
+ use Weglot\Util\Regex\RegexEnum;
5
+
6
+ class RegexTest extends \Codeception\Test\Unit {
7
+ /**
8
+ * @var \UnitTester
9
+ */
10
+ protected $tester;
11
+
12
+ /**
13
+ * @param array $option
14
+ * @return Regex
15
+ */
16
+ protected function _regexInstance(array $option) {
17
+ return new Regex(
18
+ $option['type'],
19
+ $option['value']
20
+ );
21
+ }
22
+
23
+ public function testRegexStartWith() {
24
+ $option = [
25
+ 'type' => RegexEnum::START_WITH,
26
+ 'value' => 'http://',
27
+ ];
28
+
29
+ $regex = $this->_regexInstance($option);
30
+
31
+ $this->assertEquals('#^http:\/\/#', $regex->getRegex());
32
+ $this->assertRegExp($regex->getRegex(), 'http://');
33
+ }
34
+
35
+ public function testRegexEndWith() {
36
+ $option = [
37
+ 'type' => RegexEnum::END_WITH,
38
+ 'value' => 'http://',
39
+ ];
40
+
41
+ $regex = $this->_regexInstance($option);
42
+
43
+ $this->assertEquals('#http:\/\/$#', $regex->getRegex());
44
+ $this->assertRegExp($regex->getRegex(), 'test string http://');
45
+ }
46
+
47
+ public function testRegexContain() {
48
+ $option = [
49
+ 'type' => RegexEnum::CONTAIN,
50
+ 'value' => 'http://',
51
+ ];
52
+
53
+ $regex = $this->_regexInstance($option);
54
+
55
+ $this->assertEquals('#http:\/\/#', $regex->getRegex());
56
+ $this->assertRegExp($regex->getRegex(), 'test http:// string');
57
+ }
58
+
59
+ public function testRegexIsExactly() {
60
+ $option = [
61
+ 'type' => RegexEnum::IS_EXACTLY,
62
+ 'value' => 'http://',
63
+ ];
64
+
65
+ $regex = $this->_regexInstance($option);
66
+
67
+ $this->assertEquals('#^http:\/\/$#', $regex->getRegex());
68
+ $this->assertRegExp($regex->getRegex(), 'http://');
69
+ }
70
+ public function testMatchRegex() {
71
+ $option = [
72
+ 'type' => RegexEnum::MATCH_REGEX,
73
+ 'value' => '#^http:\/\/#',
74
+ ];
75
+
76
+ $regex = $this->_regexInstance($option);
77
+
78
+ $this->assertEquals('#^http:\/\/#', $regex->getRegex());
79
+ $this->assertRegExp($regex->getRegex(), 'http://weglot.com');
80
+ }
81
+ }
weglot-compatibility.php CHANGED
@@ -21,7 +21,7 @@ if ( ! function_exists( 'wp_doing_ajax' ) ) {
21
  }
22
 
23
 
24
- if ( ! function_exists('is_rest')) {
25
  /**
26
  * Checks if the current request is a WP REST API request.
27
  *
@@ -34,15 +34,44 @@ if ( ! function_exists('is_rest')) {
34
  * @author matzeeable
35
  */
36
  function is_rest() {
37
- $prefix = rest_get_url_prefix( );
38
- if (defined('REST_REQUEST') && REST_REQUEST // (#1)
39
- || isset($_GET['rest_route']) // (#2)
40
- && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix, 0 ) === 0) {
41
  return true;
42
  }
43
  // (#3)
44
  $rest_url = wp_parse_url( site_url( $prefix ) );
45
- $current_url = wp_parse_url( add_query_arg( array( ) ) );
46
  return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
47
  }
48
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
 
23
 
24
+ if ( ! function_exists( 'is_rest' ) ) {
25
  /**
26
  * Checks if the current request is a WP REST API request.
27
  *
34
  * @author matzeeable
35
  */
36
  function is_rest() {
37
+ $prefix = rest_get_url_prefix();
38
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST // (#1)
39
+ || isset( $_GET['rest_route'] ) //phpcs:ignore
40
+ && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix, 0 ) === 0) { //phpcs:ignore
41
  return true;
42
  }
43
  // (#3)
44
  $rest_url = wp_parse_url( site_url( $prefix ) );
45
+ $current_url = wp_parse_url( add_query_arg( array() ) );
46
  return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
47
  }
48
  }
49
+
50
+ /**
51
+ * Compatibility for library weglot-php PHP 5.4
52
+ */
53
+ if ( ! function_exists( 'array_column' ) ) {
54
+ function array_column( array $input, $column_key, $index_key = null ) {
55
+ $array = array();
56
+ foreach ( $input as $value ) {
57
+ if ( ! array_key_exists( $column_key, $value ) ) {
58
+ trigger_error( "Key \"$column_key\" does not exist in array" );
59
+ return false;
60
+ }
61
+ if ( is_null( $index_key ) ) {
62
+ $array[] = $value[ $column_key ];
63
+ } else {
64
+ if ( ! array_key_exists( $index_key, $value ) ) {
65
+ trigger_error( "Key \"$index_key\" does not exist in array" );
66
+ return false;
67
+ }
68
+ if ( ! is_scalar( $value[ $index_key ] ) ) {
69
+ trigger_error( "Key \"$index_key\" does not contain scalar value" );
70
+ return false;
71
+ }
72
+ $array[ $value[ $index_key ] ] = $value[ $column_key ];
73
+ }
74
+ }
75
+ return $array;
76
+ }
77
+ }
weglot-functions.php CHANGED
@@ -139,7 +139,7 @@ function weglot_get_exclude_urls() {
139
  * @return bool
140
  */
141
  function weglot_get_translate_amp_translation() {
142
- return weglot_get_option( 'translate_amp' );
143
  }
144
 
145
  /**
@@ -164,10 +164,11 @@ function weglot_is_eligible_url( $url ) {
164
  /**
165
  * Get API KEY Weglot
166
  * @since 2.0
 
167
  * @return string
168
  */
169
  function weglot_get_api_key() {
170
- return weglot_get_option( 'api_key' );
171
  }
172
 
173
  /**
139
  * @return bool
140
  */
141
  function weglot_get_translate_amp_translation() {
142
+ return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_option_custom_settings( 'translate_amp' );
143
  }
144
 
145
  /**
164
  /**
165
  * Get API KEY Weglot
166
  * @since 2.0
167
+ * @version 3.0.0
168
  * @return string
169
  */
170
  function weglot_get_api_key() {
171
+ return weglot_get_option( 'api_key_private' );
172
  }
173
 
174
  /**
weglot.php CHANGED
@@ -7,7 +7,7 @@ Author: Weglot Translate team
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
- Version: 2.7.0
11
  */
12
 
13
  /**
@@ -22,18 +22,19 @@ if ( ! defined('ABSPATH')) {
22
  define('WEGLOT_NAME', 'Weglot');
23
  define('WEGLOT_SLUG', 'weglot-translate');
24
  define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
25
- define('WEGLOT_VERSION', '2.7.0');
26
  define('WEGLOT_PHP_MIN', '5.4');
27
  define('WEGLOT_BNAME', plugin_basename(__FILE__));
28
  define('WEGLOT_DIR', __DIR__ );
29
  define('WEGLOT_DIR_LANGUAGES', WEGLOT_DIR . '/languages');
30
  define('WEGLOT_DIR_DIST', WEGLOT_DIR . '/dist');
31
- define('WEGLOT_DEBUG', false);
32
 
33
  define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
34
  define('WEGLOT_URL_DIST', WEGLOT_DIRURL . 'dist');
35
- define('WEGLOT_LATEST_VERSION', '1.13.1');
36
  define('WEGLOT_LIB_PARSER', '1');
 
 
37
 
38
  define('WEGLOT_TEMPLATES', WEGLOT_DIR . '/templates');
39
  define('WEGLOT_TEMPLATES_ADMIN', WEGLOT_TEMPLATES . '/admin');
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
+ Version: 3.0.0
11
  */
12
 
13
  /**
22
  define('WEGLOT_NAME', 'Weglot');
23
  define('WEGLOT_SLUG', 'weglot-translate');
24
  define('WEGLOT_OPTION_GROUP', 'group-weglot-translate');
25
+ define('WEGLOT_VERSION', '3.0.0');
26
  define('WEGLOT_PHP_MIN', '5.4');
27
  define('WEGLOT_BNAME', plugin_basename(__FILE__));
28
  define('WEGLOT_DIR', __DIR__ );
29
  define('WEGLOT_DIR_LANGUAGES', WEGLOT_DIR . '/languages');
30
  define('WEGLOT_DIR_DIST', WEGLOT_DIR . '/dist');
 
31
 
32
  define('WEGLOT_DIRURL', plugin_dir_url(__FILE__));
33
  define('WEGLOT_URL_DIST', WEGLOT_DIRURL . 'dist');
34
+ define('WEGLOT_LATEST_VERSION', '2.7.0');
35
  define('WEGLOT_LIB_PARSER', '1');
36
+ define('WEGLOT_DEBUG', false);
37
+ define('WEGLOT_DEV', false);
38
 
39
  define('WEGLOT_TEMPLATES', WEGLOT_DIR . '/templates');
40
  define('WEGLOT_TEMPLATES_ADMIN', WEGLOT_TEMPLATES . '/admin');