Weglot Translate – Translate your WP website - Version 3.3.0

Version Description

(18/01/2021) = * Full refacto of the code * Add: custom language

Download this release

Release Info

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

Code changes from version 3.2.0 to 3.3.0

Files changed (126) hide show
  1. app/javascripts/metaboxes.js +0 -5
  2. app/javascripts/nav.js +6 -6
  3. app/javascripts/settings/admin-change-country.js +7 -3
  4. app/javascripts/settings/admin-check-api-key.js +1 -1
  5. app/javascripts/settings/admin-select.js +13 -23
  6. app/styles/admin.scss +5 -0
  7. bootstrap.php +0 -4
  8. composer.json +5 -3
  9. dist/admin-css.js +1 -1
  10. dist/admin-js.js +1 -1
  11. dist/css/admin-css.css +4 -0
  12. dist/front-amp-css.js +1 -1
  13. dist/front-css.js +1 -1
  14. dist/front-js.js +1 -1
  15. dist/metaboxes-js.js +0 -1
  16. dist/nav-js.js +1 -1
  17. languages/weglot-de_DE.po +2 -2
  18. languages/weglot-en_GB.po +3 -3
  19. languages/weglot-es_ES.po +2 -2
  20. languages/weglot-fr_FR.po +2 -2
  21. languages/weglot-it_IT.po +2 -2
  22. languages/weglot-nl_NL.po +2 -2
  23. languages/weglot-pt_BR.po +2 -2
  24. languages/weglot-ru_RU.po +2 -2
  25. languages/weglot.pot +2 -2
  26. readme.txt +7 -3
  27. src/actions/admin/class-admin-enqueue-weglot.php +22 -31
  28. src/actions/admin/class-ajax-user-info.php +6 -0
  29. src/actions/admin/class-customize-menu-weglot.php +14 -8
  30. src/actions/admin/class-metabox-url-translate-weglot.php +0 -325
  31. src/actions/admin/class-options-weglot.php +18 -11
  32. src/actions/admin/class-pages-weglot.php +44 -5
  33. src/actions/admin/class-plugin-links-weglot.php +1 -1
  34. src/actions/class-email-translate-weglot.php +30 -7
  35. src/actions/class-migration-weglot.php +2 -3
  36. src/actions/class-register-widget-weglot.php +2 -2
  37. src/actions/front/class-clean-options.php +7 -1
  38. src/actions/front/class-front-enqueue-weglot.php +5 -0
  39. src/actions/front/class-front-menu-weglot.php +62 -46
  40. src/actions/front/class-redirect-log-user-weglot.php +0 -1
  41. src/actions/front/class-search-weglot.php +28 -8
  42. src/actions/front/class-shortcode-weglot.php +12 -2
  43. src/actions/front/class-translate-page-weglot.php +78 -65
  44. src/class-bootstrap-weglot.php +4 -21
  45. src/helpers/class-helper-api.php +0 -9
  46. src/helpers/class-helper-filter-url-weglot.php +13 -109
  47. src/helpers/class-helper-flag-type.php +0 -13
  48. src/helpers/class-helper-is-admin.php +2 -1
  49. src/helpers/class-helper-json-inline-weglot.php +0 -34
  50. src/helpers/class-helper-tabs-admin-weglot.php +0 -17
  51. src/models/class-schema-option-migration-v3.php +0 -89
  52. src/models/class-schema-option-v3.php +7 -6
  53. src/services/class-button-service-weglot.php +63 -51
  54. src/services/class-custom-url-service-weglot.php +0 -89
  55. src/services/class-dom-listeners-service-weglot.php +0 -38
  56. src/services/class-email-translate-service-weglot.php +18 -9
  57. src/services/class-generate-switcher-service-weglot.php +17 -2
  58. src/services/class-href-lang-service-weglot.php +10 -19
  59. src/services/class-language-service-weglot.php +102 -84
  60. src/services/class-menu-options-service-weglot.php +4 -0
  61. src/services/class-migration-service-weglot.php +0 -27
  62. src/services/class-multisite-service-weglot.php +5 -0
  63. src/services/class-option-service-weglot.php +79 -183
  64. src/services/class-parser-service-weglot.php +24 -33
  65. src/services/class-private-language-service-weglot.php +0 -98
  66. src/services/class-redirect-service-weglot.php +33 -33
  67. src/services/class-regex-checkers-service-weglot.php +5 -5
  68. src/services/class-replace-link-service-weglot.php +34 -76
  69. src/services/class-replace-url-service-weglot.php +22 -16
  70. src/services/class-request-url-service-weglot.php +53 -131
  71. src/services/class-translate-service-weglot.php +47 -15
  72. src/services/class-user-api-service-weglot.php +3 -25
  73. src/third/amp/class-amp-enqueue-weglot.php +27 -9
  74. src/third/amp/class-amp-service-weglot.php +2 -1
  75. src/third/cacheenabler/class-cache-enabler-cache.php +21 -3
  76. src/third/calderaforms/class-caldera-i18n-inline.php +4 -0
  77. src/third/calderaforms/regexcheckers/class-caldera-form-json-fields.php +0 -1
  78. src/third/contactform7/class-contactform7-json-keys.php +4 -0
  79. src/third/edd/class-edd-filter-urls.php +4 -0
  80. src/third/gravityforms/class-gf-filter-urls.php +5 -1
  81. src/third/mailoptin/regexcheckers/class-mailoptin-json.php +0 -1
  82. src/third/maintenance/class-maintenance-tracking.php +6 -1
  83. src/third/ninjaforms/regexcheckers/class-ninja-form-json-fields.php +0 -1
  84. src/third/ninjaforms/regexcheckers/class-ninja-form-json-nfi18n.php +0 -1
  85. src/third/ninjaforms/regexcheckers/class-ninja-form-json-setting.php +0 -1
  86. src/third/theeventscalendar/class-theeventscalendar-words.php +6 -1
  87. src/third/underconstructionpage/class-ucp-tracking.php +6 -1
  88. src/third/woocommerce/class-wc-cart-reload-weglot.php +4 -1
  89. src/third/woocommerce/class-wc-filter-urls-weglot.php +43 -53
  90. src/third/woocommerce/class-wc-mail-weglot.php +29 -9
  91. src/third/wpforms/regexcheckers/class-wp-form-json-setting.php +0 -1
  92. src/third/wpoptimize/class-wp-optimize-cache.php +14 -2
  93. src/third/yoast/class-redirect-handler-weglot.php +12 -4
  94. src/widgets/class-widget-selector-weglot.php +13 -5
  95. templates/admin/metaboxes/url-translate.php +0 -91
  96. templates/admin/pages/nav.php +3 -3
  97. templates/admin/pages/tabs/advanced.php +2 -59
  98. templates/admin/pages/tabs/appearance.php +6 -1
  99. templates/admin/pages/tabs/custom-urls.php +5 -5
  100. templates/admin/pages/tabs/settings.php +48 -43
  101. templates/admin/pages/tabs/status.php +10 -8
  102. templates/admin/pages/tabs/support.php +2 -2
  103. vendor/autoload.php +1 -1
  104. vendor/composer/ClassLoader.php +3 -3
  105. vendor/composer/InstalledVersions.php +264 -0
  106. vendor/composer/autoload_classmap.php +1 -0
  107. vendor/composer/autoload_real.php +13 -8
  108. vendor/composer/autoload_static.php +6 -5
  109. vendor/composer/installed.json +261 -232
  110. vendor/composer/installed.php +69 -0
  111. vendor/composer/platform_check.php +26 -0
  112. vendor/weglot/weglot-php/.travis.yml +3 -6
  113. vendor/weglot/weglot-php/src/Client/Api/LanguageCollection.php +1 -1
  114. vendor/weglot/weglot-php/src/Client/Api/LanguageEntry.php +40 -12
  115. vendor/weglot/weglot-php/src/Client/Factory/Languages.php +115 -113
  116. vendor/weglot/weglot-php/src/Parser/Check/Dom/ImageDataSource.php +27 -0
  117. vendor/weglot/weglot-php/src/Parser/Check/RegexCheckerProvider.php +6 -2
  118. vendor/weglot/weglot-php/src/Parser/Formatter/DomFormatter.php +10 -2
  119. vendor/weglot/weglot-php/src/Util/Url.php +176 -81
  120. vendor/weglot/weglot-php/src/Util/Url/UrlConfig.php +0 -73
  121. vendor/weglot/weglot-php/src/Util/Url/UrlTranslate.php +0 -56
  122. vendor/weglot/weglot-php/tests/unit/Client/Endpoint/LanguagesTest.php +5 -5
  123. vendor/weglot/weglot-php/tests/unit/Util/UrlTest.php +123 -132
  124. webpack.config.js +0 -1
  125. weglot-functions.php +22 -108
  126. weglot.php +3 -8
app/javascripts/metaboxes.js DELETED
@@ -1,5 +0,0 @@
1
- import "./find-polyfill";
2
- import "./filter-polyfill";
3
- import InitUrlTranslate from "./metaboxes/url-translate";
4
-
5
- InitUrlTranslate();
 
 
 
 
 
app/javascripts/nav.js CHANGED
@@ -7,21 +7,21 @@ jQuery(document).ready(function ($) {
7
  const id = $(this).attr('id').substring(19);
8
  $(this).children('p:not( .field-move )').remove(); // remove default fields we don't need
9
 
10
- $(this).append($('<input>').attr({
11
  type: 'hidden',
12
  id: 'edit-menu-item-title-' + id,
13
  name: 'menu-item-title[' + id + ']',
14
  value: weglot_data.title
15
  }));
16
 
17
- $(this).append($("<input>").attr({
18
  type: "hidden",
19
  id: "edit-menu-item-url-" + id,
20
  name: "menu-item-url[" + id + "]",
21
  value: "#weglot_switcher"
22
  }));
23
 
24
- $(this).append($('<input>').attr({
25
  type: 'hidden',
26
  id: 'edit-menu-item-weglot-detect-' + id,
27
  name: 'menu-item-weglot-detect[' + id + ']',
@@ -35,8 +35,8 @@ jQuery(document).ready(function ($) {
35
  .attr("for", `edit-menu-item-${option.key}-${id}`)
36
  .text(` ${option.title}`);
37
 
38
- $(this).prepend(paragraph);
39
- paragraph.append(label);
40
 
41
  const checkbox = $("<input>").attr({
42
  type: "checkbox",
@@ -54,7 +54,7 @@ jQuery(document).ready(function ($) {
54
  checkbox.prop("checked", true);
55
  }
56
 
57
- label.prepend(checkbox);
58
  })
59
  });
60
 
7
  const id = $(this).attr('id').substring(19);
8
  $(this).children('p:not( .field-move )').remove(); // remove default fields we don't need
9
 
10
+ $(this).append($('<input>').attr({ // phpcs:ignore
11
  type: 'hidden',
12
  id: 'edit-menu-item-title-' + id,
13
  name: 'menu-item-title[' + id + ']',
14
  value: weglot_data.title
15
  }));
16
 
17
+ $(this).append($("<input>").attr({ // phpcs:ignore
18
  type: "hidden",
19
  id: "edit-menu-item-url-" + id,
20
  name: "menu-item-url[" + id + "]",
21
  value: "#weglot_switcher"
22
  }));
23
 
24
+ $(this).append($('<input>').attr({ // phpcs:ignore
25
  type: 'hidden',
26
  id: 'edit-menu-item-weglot-detect-' + id,
27
  name: 'menu-item-weglot-detect[' + id + ']',
35
  .attr("for", `edit-menu-item-${option.key}-${id}`)
36
  .text(` ${option.title}`);
37
 
38
+ $(this).prepend(paragraph); // phpcs:ignore
39
+ paragraph.append(label); // phpcs:ignore
40
 
41
  const checkbox = $("<input>").attr({
42
  type: "checkbox",
54
  checkbox.prop("checked", true);
55
  }
56
 
57
+ label.prepend(checkbox); // phpcs:ignore
58
  })
59
  });
60
 
app/javascripts/settings/admin-change-country.js CHANGED
@@ -12,6 +12,7 @@ const init_admin_change_country = function() {
12
  var ar_flags = new Array();
13
  var tw_flags = new Array();
14
  var zh_flags = new Array();
 
15
 
16
  en_flags[1] = [3570, 7841, 48, 2712];
17
  en_flags[2] = [3720, 449, 3048, 4440];
@@ -66,21 +67,24 @@ const init_admin_change_country = function() {
66
  zh_flags[1] = [2970, 6369, 3408, 4008]; // Taiwan
67
  zh_flags[2] = [3600, 3233, 2112, 48]; // Hong Kong
68
 
 
 
69
  var enval = $("select.flag-en-type").val();
70
  var esval = $("select.flag-es-type").val();
71
  var frval = $("select.flag-fr-type").val();
72
  var arval = $("select.flag-ar-type").val();
73
  var twval = $("select.flag-tw-type").val();
74
  var zhval = $("select.flag-zh-type").val();
75
-
76
  var en_style = enval <= 0 ? "" : ".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -" + en_flags[enval][0] + "px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -" + en_flags[enval][1] + "px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -" + en_flags[enval][2] + "px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -" + en_flags[enval][3] + "px 0 !important; } ";
77
  var es_style = esval <= 0 ? "" : ".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -" + es_flags[esval][0] + "px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -" + es_flags[esval][1] + "px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -" + es_flags[esval][2] + "px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -" + es_flags[esval][3] + "px 0 !important; } ";
78
  var fr_style = frval <= 0 ? "" : ".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -" + fr_flags[frval][0] + "px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -" + fr_flags[frval][1] + "px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -" + fr_flags[frval][2] + "px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -" + fr_flags[frval][3] + "px 0 !important; } ";
79
  var ar_style = arval <= 0 ? "" : ".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -" + ar_flags[arval][0] + "px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -" + ar_flags[arval][1] + "px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -" + ar_flags[arval][2] + "px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -" + ar_flags[arval][3] + "px 0 !important; } ";
80
  var tw_style = twval <= 0 ? "" : ".weglot-flags.tw > a:before, .weglot-flags.tw > span:before { background-position: -" + tw_flags[twval][0] + "px 0 !important; } .weglot-flags.flag-1.tw > a:before, .weglot-flags.flag-1.tw > span:before { background-position: -" + tw_flags[twval][1] + "px 0 !important; } .weglot-flags.flag-2.tw > a:before, .weglot-flags.flag-2.tw > span:before { background-position: -" + tw_flags[twval][2] + "px 0 !important; } .weglot-flags.flag-3.tw > a:before, .weglot-flags.flag-3.tw > span:before { background-position: -" + tw_flags[twval][3] + "px 0 !important; } ";
81
  var zh_style = zhval <= 0 ? "" : ".weglot-flags.zh > a:before, .weglot-flags.zh > span:before { background-position: -" + zh_flags[zhval][0] + "px 0 !important; } .weglot-flags.flag-1.zh > a:before, .weglot-flags.flag-1.zh > span:before { background-position: -" + zh_flags[zhval][1] + "px 0 !important; } .weglot-flags.flag-2.zh > a:before, .weglot-flags.flag-2.zh > span:before { background-position: -" + zh_flags[zhval][2] + "px 0 !important; } .weglot-flags.flag-3.zh > a:before, .weglot-flags.flag-3.zh > span:before { background-position: -" + zh_flags[zhval][3] + "px 0 !important; } ";
 
82
 
83
- $("#flag_css, #weglot-css-flag-css").text(en_style + es_style + fr_style + ar_style + tw_style + zh_style);
84
  }
85
 
86
  const execute = () => {
@@ -91,7 +95,7 @@ const init_admin_change_country = function() {
91
  }
92
  );
93
 
94
- $("select.flag-en-type, select.flag-es-type, select.flag-fr-type, select.flag-ar-type, select.flag-tw-type, select.flag-zh-type").on('change',
95
  function () {
96
  refresh_flag_css()
97
  }
12
  var ar_flags = new Array();
13
  var tw_flags = new Array();
14
  var zh_flags = new Array();
15
+ var pt_flags = new Array();
16
 
17
  en_flags[1] = [3570, 7841, 48, 2712];
18
  en_flags[2] = [3720, 449, 3048, 4440];
67
  zh_flags[1] = [2970, 6369, 3408, 4008]; // Taiwan
68
  zh_flags[2] = [3600, 3233, 2112, 48]; // Hong Kong
69
 
70
+ pt_flags[1] = [6630, 993, 2784, 4344];
71
+
72
  var enval = $("select.flag-en-type").val();
73
  var esval = $("select.flag-es-type").val();
74
  var frval = $("select.flag-fr-type").val();
75
  var arval = $("select.flag-ar-type").val();
76
  var twval = $("select.flag-tw-type").val();
77
  var zhval = $("select.flag-zh-type").val();
78
+ var ptval = $("select.flag-pt-type").val();
79
  var en_style = enval <= 0 ? "" : ".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -" + en_flags[enval][0] + "px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -" + en_flags[enval][1] + "px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -" + en_flags[enval][2] + "px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -" + en_flags[enval][3] + "px 0 !important; } ";
80
  var es_style = esval <= 0 ? "" : ".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -" + es_flags[esval][0] + "px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -" + es_flags[esval][1] + "px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -" + es_flags[esval][2] + "px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -" + es_flags[esval][3] + "px 0 !important; } ";
81
  var fr_style = frval <= 0 ? "" : ".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -" + fr_flags[frval][0] + "px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -" + fr_flags[frval][1] + "px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -" + fr_flags[frval][2] + "px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -" + fr_flags[frval][3] + "px 0 !important; } ";
82
  var ar_style = arval <= 0 ? "" : ".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -" + ar_flags[arval][0] + "px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -" + ar_flags[arval][1] + "px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -" + ar_flags[arval][2] + "px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -" + ar_flags[arval][3] + "px 0 !important; } ";
83
  var tw_style = twval <= 0 ? "" : ".weglot-flags.tw > a:before, .weglot-flags.tw > span:before { background-position: -" + tw_flags[twval][0] + "px 0 !important; } .weglot-flags.flag-1.tw > a:before, .weglot-flags.flag-1.tw > span:before { background-position: -" + tw_flags[twval][1] + "px 0 !important; } .weglot-flags.flag-2.tw > a:before, .weglot-flags.flag-2.tw > span:before { background-position: -" + tw_flags[twval][2] + "px 0 !important; } .weglot-flags.flag-3.tw > a:before, .weglot-flags.flag-3.tw > span:before { background-position: -" + tw_flags[twval][3] + "px 0 !important; } ";
84
  var zh_style = zhval <= 0 ? "" : ".weglot-flags.zh > a:before, .weglot-flags.zh > span:before { background-position: -" + zh_flags[zhval][0] + "px 0 !important; } .weglot-flags.flag-1.zh > a:before, .weglot-flags.flag-1.zh > span:before { background-position: -" + zh_flags[zhval][1] + "px 0 !important; } .weglot-flags.flag-2.zh > a:before, .weglot-flags.flag-2.zh > span:before { background-position: -" + zh_flags[zhval][2] + "px 0 !important; } .weglot-flags.flag-3.zh > a:before, .weglot-flags.flag-3.zh > span:before { background-position: -" + zh_flags[zhval][3] + "px 0 !important; } ";
85
+ var pt_style = ptval <= 0 ? "" : ".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -" + pt_flags[ptval][0] + "px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -" + pt_flags[ptval][1] + "px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -" + pt_flags[ptval][2] + "px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -" + pt_flags[ptval][3] + "px 0 !important; } ";
86
 
87
+ $("#flag_css, #weglot-css-flag-css").text(en_style + es_style + fr_style + ar_style + tw_style + zh_style + pt_style);
88
  }
89
 
90
  const execute = () => {
95
  }
96
  );
97
 
98
+ $("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type, select.flag-tw-type, select.flag-zh-type").on('change',
99
  function () {
100
  refresh_flag_css()
101
  }
app/javascripts/settings/admin-check-api-key.js CHANGED
@@ -33,7 +33,7 @@ const init_admin_button_preview = function () {
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
 
33
 
34
  function unvalidApiKey(){
35
  $(".weglot-keyres").remove();
36
+ $("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span><p class="weglot-keyres">Make sure you enter a valid Weglot API key. If the key is still not validating, you can contact your host provider and ask if it\'s possible to whitelist api.weglot.com and weglot.com</p>');
37
  $("#wrap-weglot #submit").prop("disabled", true);
38
  }
39
 
app/javascripts/settings/admin-select.js CHANGED
@@ -3,7 +3,7 @@ const init_admin_select = function(){
3
  const $ = jQuery
4
  const generate_destination_language = () => {
5
  return weglot_languages.available.filter(itm => {
6
- return itm.code !== weglot_languages.original
7
  });
8
  }
9
 
@@ -15,27 +15,19 @@ const init_admin_select = function(){
15
  .selectize({
16
  delimiter: "|",
17
  persist: false,
18
- valueField: "code",
19
  labelField: "local",
20
- searchField: ["code", "english", "local"],
21
  sortField: [{ field: "english", direction: "asc" }],
22
  maxItems: weglot_languages.limit,
23
  plugins: ["remove_button", "drag_drop"],
24
  options: generate_destination_language(),
25
  render: {
26
  option: function(item, escape) {
27
- return (
28
- '<div class="weglot__choice__language">' +
29
- '<span class="weglot__choice__language--english">' +
30
- escape(item.english) +
31
- "</span>" +
32
- '<span class="weglot__choice__language--local">' +
33
- escape(item.local) +
34
- " [" +
35
- escape(item.code) +
36
- "]</span>" +
37
- "</div>"
38
- );
39
  }
40
  }
41
  })
@@ -59,7 +51,7 @@ const init_admin_select = function(){
59
 
60
  let new_dest_language = ''
61
  code_languages.forEach(element => {
62
- const language = weglot_languages.available.find(itm => itm.code === element);
63
  let label = ''
64
  if(with_name){
65
  if (is_fullname){
@@ -79,7 +71,7 @@ const init_admin_select = function(){
79
 
80
 
81
  });
82
- $(".country-selector ul").html(new_dest_language)
83
  });
84
  }
85
 
@@ -93,11 +85,11 @@ const init_admin_select = function(){
93
  destination_selectize[0].selectize.removeOption(work_original_language);
94
 
95
  const new_option = weglot_languages.available.find(itm => {
96
- return itm.code === new_destination_option
97
  });
98
 
99
  const new_original_option = weglot_languages.available.find(itm => {
100
- return itm.code === work_original_language;
101
  });
102
 
103
  destination_selectize[0].selectize.addOption(new_option);
@@ -107,16 +99,14 @@ const init_admin_select = function(){
107
  const with_name = $("#with_name").is(":checked")
108
  let label = ''
109
  if(with_name){
110
- label = is_fullname ? new_original_option.local : new_original_option.code.toUpperCase();
111
  }
112
 
113
  $(".wgcurrent.wg-li")
114
  .removeClass(old_original_language)
115
  .addClass(work_original_language)
116
  .attr("data-code-language", work_original_language)
117
- .find('span').html(label)
118
-
119
-
120
  });
121
 
122
 
3
  const $ = jQuery
4
  const generate_destination_language = () => {
5
  return weglot_languages.available.filter(itm => {
6
+ return itm.internal_code !== weglot_languages.original
7
  });
8
  }
9
 
15
  .selectize({
16
  delimiter: "|",
17
  persist: false,
18
+ valueField: "internal_code",
19
  labelField: "local",
20
+ searchField: ["internal_code", "english", "local"],
21
  sortField: [{ field: "english", direction: "asc" }],
22
  maxItems: weglot_languages.limit,
23
  plugins: ["remove_button", "drag_drop"],
24
  options: generate_destination_language(),
25
  render: {
26
  option: function(item, escape) {
27
+ var english = escape(item.english);
28
+ var local = escape(item.local);
29
+ var external = escape(item.external_code);
30
+ return `<div class="weglot__choice__language"><span class="weglot__choice__language--english">${english}</span><span class="weglot__choice__language--local">${local}[${external}]</span></div>`;
 
 
 
 
 
 
 
 
31
  }
32
  }
33
  })
51
 
52
  let new_dest_language = ''
53
  code_languages.forEach(element => {
54
+ const language = weglot_languages.available.find(itm => itm.internal_code === element);
55
  let label = ''
56
  if(with_name){
57
  if (is_fullname){
71
 
72
 
73
  });
74
+ $(".country-selector ul").html(new_dest_language) //phpcs:ignore
75
  });
76
  }
77
 
85
  destination_selectize[0].selectize.removeOption(work_original_language);
86
 
87
  const new_option = weglot_languages.available.find(itm => {
88
+ return itm.internal_code === new_destination_option
89
  });
90
 
91
  const new_original_option = weglot_languages.available.find(itm => {
92
+ return itm.internal_code === work_original_language;
93
  });
94
 
95
  destination_selectize[0].selectize.addOption(new_option);
99
  const with_name = $("#with_name").is(":checked")
100
  let label = ''
101
  if(with_name){
102
+ label = is_fullname ? new_original_option.local : new_original_option.internal_code.toUpperCase();
103
  }
104
 
105
  $(".wgcurrent.wg-li")
106
  .removeClass(old_original_language)
107
  .addClass(work_original_language)
108
  .attr("data-code-language", work_original_language)
109
+ .find('span').text(label)
 
 
110
  });
111
 
112
 
app/styles/admin.scss CHANGED
@@ -32,6 +32,11 @@ $wp-color-green: #46b450; // RGB(70, 180, 80)
32
  }
33
  }
34
 
 
 
 
 
 
35
  .weglot_text_error {
36
  color: $wp-color-red;
37
  }
32
  }
33
  }
34
 
35
+ p.weglot-keyres {
36
+ font-style: italic;
37
+ color: #ff6464;
38
+ }
39
+
40
  .weglot_text_error {
41
  color: $wp-color-red;
42
  }
bootstrap.php CHANGED
@@ -45,13 +45,10 @@ abstract class Context_Weglot {
45
  '\WeglotWP\Services\Replace_Url_Service_Weglot',
46
  '\WeglotWP\Services\Multisite_Service_Weglot',
47
  '\WeglotWP\Services\Replace_Link_Service_Weglot',
48
- '\WeglotWP\Services\Migration_Service_Weglot',
49
- '\WeglotWP\Services\Dom_Listeners_Service_Weglot',
50
  '\WeglotWP\Services\Parser_Service_Weglot',
51
  '\WeglotWP\Services\User_Api_Service_Weglot',
52
  '\WeglotWP\Services\Dom_Checkers_Service_Weglot',
53
  '\WeglotWP\Services\Regex_Checkers_Service_Weglot',
54
- '\WeglotWP\Services\Custom_Url_Service_Weglot',
55
  '\WeglotWP\Services\Generate_Switcher_Service_Weglot',
56
  '\WeglotWP\Services\Email_Translate_Service_Weglot',
57
  '\WeglotWP\Services\Translate_Service_Weglot',
@@ -92,7 +89,6 @@ abstract class Context_Weglot {
92
  '\WeglotWP\Actions\Front\Shortcode_Weglot',
93
  '\WeglotWP\Actions\Front\Redirect_Log_User_Weglot',
94
  '\WeglotWP\Actions\Migration_Weglot',
95
- '\WeglotWP\Actions\Admin\Metabox_Url_Translate_Weglot',
96
  '\WeglotWP\Actions\Front\Front_Menu_Weglot',
97
  '\WeglotWP\Actions\Front\Search_Weglot',
98
  '\WeglotWP\Actions\Front\Redirect_Comment',
45
  '\WeglotWP\Services\Replace_Url_Service_Weglot',
46
  '\WeglotWP\Services\Multisite_Service_Weglot',
47
  '\WeglotWP\Services\Replace_Link_Service_Weglot',
 
 
48
  '\WeglotWP\Services\Parser_Service_Weglot',
49
  '\WeglotWP\Services\User_Api_Service_Weglot',
50
  '\WeglotWP\Services\Dom_Checkers_Service_Weglot',
51
  '\WeglotWP\Services\Regex_Checkers_Service_Weglot',
 
52
  '\WeglotWP\Services\Generate_Switcher_Service_Weglot',
53
  '\WeglotWP\Services\Email_Translate_Service_Weglot',
54
  '\WeglotWP\Services\Translate_Service_Weglot',
89
  '\WeglotWP\Actions\Front\Shortcode_Weglot',
90
  '\WeglotWP\Actions\Front\Redirect_Log_User_Weglot',
91
  '\WeglotWP\Actions\Migration_Weglot',
 
92
  '\WeglotWP\Actions\Front\Front_Menu_Weglot',
93
  '\WeglotWP\Actions\Front\Search_Weglot',
94
  '\WeglotWP\Actions\Front\Redirect_Comment',
composer.json CHANGED
@@ -18,15 +18,17 @@
18
  }
19
  ],
20
  "require": {
21
- "weglot/weglot-php": "^1.0",
22
  "gmulti/morphism-php": "^0.3.0"
23
  },
24
  "require-dev": {
25
  "squizlabs/php_codesniffer": "^3.2.2",
26
- "wp-coding-standards/wpcs": "^0.14.1",
27
  "phpunit/phpunit": "^4 || ^6",
28
  "roave/security-advisories": "dev-master",
29
- "phpseclib/phpseclib": "^2.0"
 
 
30
  },
31
  "scripts": {
32
  "post-install-cmd": [
18
  }
19
  ],
20
  "require": {
21
+ "weglot/weglot-php": "^1.1",
22
  "gmulti/morphism-php": "^0.3.0"
23
  },
24
  "require-dev": {
25
  "squizlabs/php_codesniffer": "^3.2.2",
26
+ "wp-coding-standards/wpcs": "^2.3.0",
27
  "phpunit/phpunit": "^4 || ^6",
28
  "roave/security-advisories": "dev-master",
29
+ "phpseclib/phpseclib": "^2.0",
30
+ "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
31
+ "automattic/vipwpcs": "^2.2"
32
  },
33
  "scripts": {
34
  "post-install-cmd": [
dist/admin-css.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=11)}({11:function(e,t){}});
1
+ !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=9)}({9:function(e,t){}});
dist/admin-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function o(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=e,o.c=t,o.d=function(e,t,a){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},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 a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(a,n,function(t){return e[t]}.bind(null,n));return a},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=4)}([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,a=new Array(o),n=this,l=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(n[r],r,n)&&(a[l++]=n[r]);else for(;++r!==o;)r in this&&e.call(t,n[r],r,n)&&(a[l++]=n[r]);return a.length=l,a})},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 a=arguments[1],n=0;n<o;){var l=t[n];if(e.call(a,l,n,t))return l;n++}},configurable:!0,writable:!0})},,,function(e,t,o){"use strict";o.r(t);var a=function(){const e=jQuery;let t;const o=()=>{t=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:(()=>weglot_languages.available.filter(e=>e.code!==weglot_languages.original))(),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",o=>{const a=t[0].selectize.getValue(),n=e("#li-button-tpl");if(0===n.length)return;const l=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked");let s="";e("#with_flags").is(":checked")&&(s="weglot-flags");let c="";a.forEach(e=>{const t=weglot_languages.available.find(t=>t.code===e);let o="";r&&(o=l?t.local:e.toUpperCase()),c+=n.html().replace("{LABEL_LANGUAGE}",o).replace(new RegExp("{CODE_LANGUAGE}","g"),e).replace("{CLASSES}",s)}),e(".country-selector ul").html(c)})};document.addEventListener("DOMContentLoaded",()=>{(()=>{let a=e("#original_language").val();e("#original_language").on("change",function(o){const n=a,l=a;a=o.target.value,t[0].selectize.removeOption(a);const r=weglot_languages.available.find(e=>e.code===l),s=weglot_languages.available.find(e=>e.code===a);t[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(n).addClass(a).attr("data-code-language",a).find("span").html(i)}),o(),window.addEventListener("weglotCheckApi",e=>{let o=1e3;const a=e.detail.plan;a<=0||weglot_languages.plans.starter_free.ids.indexOf(a)>=0?o=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(a)>=0&&(o=weglot_languages.plans.business.limit_language),t[0].selectize.settings.maxItems=o})})()})};var n=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=()=>{document.querySelector("#tpl-exclusion-url");const e=document.querySelector("#tpl-exclusion-block"),t=document.querySelector("#container-exclude_blocks");function o(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",a=>{a.preventDefault(),t.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",o)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",o)})};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,a)=>{o.push(e(a).data("code-language"))});const a=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 a=e(":selected",this).data("value");e(".country-selector label, .country-selector li").addClass(`flag-${a}`),t=a});const n=()=>{const t=a.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),n=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(n),e(".country-selector li").each((t,n)=>{const l=a.find(t=>t.code===e(n).data("code-language")),r=o?l.local:l.code.toUpperCase();e(n).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?n():(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)n();else{const t=a.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 n=a.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(n.code.toUpperCase()),e(o).find("span").text(n.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(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-ckeckkey"></span>'),e.ajax({method:"POST",url:ajaxurl,data:{action:"get_user_info",api_key:t},success:({data:t,success:a})=>{e(".weglot-keyres").remove(),a?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(){jQuery;document.addEventListener("DOMContentLoaded",()=>{jQuery(document).ready(function(e){wp.codeEditor.initialize(e("#override_css"),cm_settings)})})};var i=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-fr-type, select.flag-ar-type, select.flag-tw-type, select.flag-zh-type").on("change",function(){!function(){var t=new Array,o=new Array,a=new Array,n=new Array,l=new Array,r=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],a[1]=[2760,736,2856,4416],a[2]=[3840,1280,2712,4224],a[3]=[5700,7201,5016,2400],a[4]=[2220,4160,1632,1944],n[1]=[1830,129,3096,5664],n[2]=[5100,2177,3840,2904],n[3]=[4890,3425,3648,2136],n[4]=[1320,3681,1896,4080],n[5]=[1260,3841,1824,1200],n[6]=[1020,3969,1608,312],n[7]=[4800,4065,3600,72],n[8]=[4710,4865,3504,480],n[9]=[6720,5984,5112,3792],n[10]=[4500,7233,3288,1800],n[11]=[720,7522,384,3936],n[12]=[690,7745,336,1104],n[13]=[600,8225,120,1272],n[14]=[660,5569,840,576],l[1]=[3690,1505,2592,3240],l[2]=[3600,3233,2112,48],r[1]=[2970,6369,3408,4008],r[2]=[3600,3233,2112,48];var s=e("select.flag-en-type").val(),c=e("select.flag-es-type").val(),i=e("select.flag-fr-type").val(),g=e("select.flag-ar-type").val(),f=e("select.flag-tw-type").val(),d=e("select.flag-zh-type").val(),u=s<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[s][0]+"px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[s][1]+"px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[s][2]+"px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[s][3]+"px 0 !important; } ",p=c<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[c][0]+"px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[c][1]+"px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[c][2]+"px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[c][3]+"px 0 !important; } ",w=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: -"+n[g][0]+"px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+n[g][1]+"px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+n[g][2]+"px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+n[g][3]+"px 0 !important; } ",y=f<=0?"":".weglot-flags.tw > a:before, .weglot-flags.tw > span:before { background-position: -"+l[f][0]+"px 0 !important; } .weglot-flags.flag-1.tw > a:before, .weglot-flags.flag-1.tw > span:before { background-position: -"+l[f][1]+"px 0 !important; } .weglot-flags.flag-2.tw > a:before, .weglot-flags.flag-2.tw > span:before { background-position: -"+l[f][2]+"px 0 !important; } .weglot-flags.flag-3.tw > a:before, .weglot-flags.flag-3.tw > span:before { background-position: -"+l[f][3]+"px 0 !important; } ",m=d<=0?"":".weglot-flags.zh > a:before, .weglot-flags.zh > span:before { background-position: -"+r[d][0]+"px 0 !important; } .weglot-flags.flag-1.zh > a:before, .weglot-flags.flag-1.zh > span:before { background-position: -"+r[d][1]+"px 0 !important; } .weglot-flags.flag-2.zh > a:before, .weglot-flags.flag-2.zh > span:before { background-position: -"+r[d][2]+"px 0 !important; } .weglot-flags.flag-3.zh > a:before, .weglot-flags.flag-3.zh > span:before { background-position: -"+r[d][3]+"px 0 !important; } ";e("#flag_css, #weglot-css-flag-css").text(u+p+w+b+y+m)}()});var t=e("#flag_css").text();t.trim()&&e("#weglot-css-flag-css").text(t)};document.addEventListener("DOMContentLoaded",()=>{t()})};var g=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(1),o(0);a(),l(),n(),r(),s(),c(),i(),g()}]);
1
+ !function(e){var t={};function o(a){if(t[a])return t[a].exports;var l=t[a]={i:a,l:!1,exports:{}};return e[a].call(l.exports,l,l.exports,o),l.l=!0,l.exports}o.m=e,o.c=t,o.d=function(e,t,a){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},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 a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var l in e)o.d(a,l,function(t){return e[t]}.bind(null,l));return a},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=0)}([function(e,t,o){"use strict";o.r(t);var a=function(){const e=jQuery;let t;const o=()=>{t=e(".weglot-select-destination").selectize({delimiter:"|",persist:!1,valueField:"internal_code",labelField:"local",searchField:["internal_code","english","local"],sortField:[{field:"english",direction:"asc"}],maxItems:weglot_languages.limit,plugins:["remove_button","drag_drop"],options:(()=>weglot_languages.available.filter(e=>e.internal_code!==weglot_languages.original))(),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.external_code)}]</span></div>`}}}).on("change",o=>{const a=t[0].selectize.getValue(),l=e("#li-button-tpl");if(0===l.length)return;const n=e("#is_fullname").is(":checked"),r=e("#with_name").is(":checked");let s="";e("#with_flags").is(":checked")&&(s="weglot-flags");let i="";a.forEach(e=>{const t=weglot_languages.available.find(t=>t.internal_code===e);let o="";r&&(o=n?t.local:e.toUpperCase()),i+=l.html().replace("{LABEL_LANGUAGE}",o).replace(new RegExp("{CODE_LANGUAGE}","g"),e).replace("{CLASSES}",s)}),e(".country-selector ul").html(i)})};document.addEventListener("DOMContentLoaded",()=>{(()=>{let a=e("#original_language").val();e("#original_language").on("change",function(o){const l=a,n=a;a=o.target.value,t[0].selectize.removeOption(a);const r=weglot_languages.available.find(e=>e.internal_code===n),s=weglot_languages.available.find(e=>e.internal_code===a);t[0].selectize.addOption(r);const i=e("#is_fullname").is(":checked");let c="";e("#with_name").is(":checked")&&(c=i?s.local:s.internal_code.toUpperCase()),e(".wgcurrent.wg-li").removeClass(l).addClass(a).attr("data-code-language",a).find("span").text(c)}),o(),window.addEventListener("weglotCheckApi",e=>{let o=1e3;const a=e.detail.plan;a<=0||weglot_languages.plans.starter_free.ids.indexOf(a)>=0?o=weglot_languages.plans.starter_free.limit_language:weglot_languages.plans.business.ids.indexOf(a)>=0&&(o=weglot_languages.plans.business.limit_language),t[0].selectize.settings.maxItems=o})})()})};var l=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 n=function(){const e=()=>{document.querySelector("#tpl-exclusion-url");const e=document.querySelector("#tpl-exclusion-block"),t=document.querySelector("#container-exclude_blocks");function o(e){e.preventDefault(),this.parentNode.remove()}document.querySelector("#js-add-exclude-block")&&document.querySelector("#js-add-exclude-block").addEventListener("click",a=>{a.preventDefault(),t.insertAdjacentHTML("beforeend",e.innerHTML),document.querySelector("#container-exclude_blocks .item-exclude:last-child .js-btn-remove-exclude").addEventListener("click",o)}),document.querySelectorAll(".js-btn-remove").forEach(e=>{e.addEventListener("click",o)})};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,a)=>{o.push(e(a).data("code-language"))});const a=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 a=e(":selected",this).data("value");e(".country-selector label, .country-selector li").addClass(`flag-${a}`),t=a});const l=()=>{const t=a.find(t=>t.code===e(".country-selector label").data("code-language")),o=e("#is_fullname").is(":checked"),l=o?t.local:t.code.toUpperCase();e(".country-selector label a, .country-selector label span").text(l),e(".country-selector li").each((t,l)=>{const n=a.find(t=>t.code===e(l).data("code-language")),r=o?n.local:n.code.toUpperCase();e(l).find("a").text(r)})};e("#with_name").on("change",function(t){t.target.checked?l():(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)l();else{const t=a.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 l=a.find(t=>t.code===e(o).data("code-language"));e(o).find("a").text(l.code.toUpperCase()),e(o).find("span").text(l.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><p class="weglot-keyres">Make sure you enter a valid Weglot API key. If the key is still not validating, you can contact your host provider and ask if it\'s possible to whitelist api.weglot.com and weglot.com</p>'),e("#wrap-weglot #submit").prop("disabled",!0)}e(".weglot-keyres").remove(),e("#api_key_private").after('<span class="weglot-keyres weglot-ckeckkey"></span>'),e.ajax({method:"POST",url:ajaxurl,data:{action:"get_user_info",api_key:t},success:({data:t,success:a})=>{e(".weglot-keyres").remove(),a?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 i=function(){jQuery;document.addEventListener("DOMContentLoaded",()=>{jQuery(document).ready(function(e){wp.codeEditor.initialize(e("#override_css"),cm_settings)})})};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, select.flag-tw-type, select.flag-zh-type").on("change",function(){!function(){var t=new Array,o=new Array,a=new Array,l=new Array,n=new Array,r=new Array,s=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],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],n[1]=[3690,1505,2592,3240],n[2]=[3600,3233,2112,48],r[1]=[2970,6369,3408,4008],r[2]=[3600,3233,2112,48],s[1]=[6630,993,2784,4344];var i=e("select.flag-en-type").val(),c=e("select.flag-es-type").val(),g=e("select.flag-fr-type").val(),f=e("select.flag-ar-type").val(),p=e("select.flag-tw-type").val(),d=e("select.flag-zh-type").val(),u=e("select.flag-pt-type").val(),w=i<=0?"":".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -"+t[i][0]+"px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -"+t[i][1]+"px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -"+t[i][2]+"px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -"+t[i][3]+"px 0 !important; } ",b=c<=0?"":".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -"+o[c][0]+"px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -"+o[c][1]+"px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -"+o[c][2]+"px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -"+o[c][3]+"px 0 !important; } ",y=g<=0?"":".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -"+a[g][0]+"px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -"+a[g][1]+"px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -"+a[g][2]+"px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -"+a[g][3]+"px 0 !important; } ",m=f<=0?"":".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -"+l[f][0]+"px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -"+l[f][1]+"px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -"+l[f][2]+"px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -"+l[f][3]+"px 0 !important; } ",v=p<=0?"":".weglot-flags.tw > a:before, .weglot-flags.tw > span:before { background-position: -"+n[p][0]+"px 0 !important; } .weglot-flags.flag-1.tw > a:before, .weglot-flags.flag-1.tw > span:before { background-position: -"+n[p][1]+"px 0 !important; } .weglot-flags.flag-2.tw > a:before, .weglot-flags.flag-2.tw > span:before { background-position: -"+n[p][2]+"px 0 !important; } .weglot-flags.flag-3.tw > a:before, .weglot-flags.flag-3.tw > span:before { background-position: -"+n[p][3]+"px 0 !important; } ",h=d<=0?"":".weglot-flags.zh > a:before, .weglot-flags.zh > span:before { background-position: -"+r[d][0]+"px 0 !important; } .weglot-flags.flag-1.zh > a:before, .weglot-flags.flag-1.zh > span:before { background-position: -"+r[d][1]+"px 0 !important; } .weglot-flags.flag-2.zh > a:before, .weglot-flags.flag-2.zh > span:before { background-position: -"+r[d][2]+"px 0 !important; } .weglot-flags.flag-3.zh > a:before, .weglot-flags.flag-3.zh > span:before { background-position: -"+r[d][3]+"px 0 !important; } ",_=u<=0?"":".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -"+s[u][0]+"px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -"+s[u][1]+"px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -"+s[u][2]+"px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -"+s[u][3]+"px 0 !important; } ";e("#flag_css, #weglot-css-flag-css").text(w+b+y+m+v+h+_)}()});var t=e("#flag_css").text();t.trim()&&e("#weglot-css-flag-css").text(t)};document.addEventListener("DOMContentLoaded",()=>{t()})};var g=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(3),o(2);a(),n(),l(),r(),s(),i(),c(),g()},,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,a=new Array(o),l=this,n=0,r=-1;if(void 0===t)for(;++r!==o;)r in this&&e(l[r],r,l)&&(a[n++]=l[r]);else for(;++r!==o;)r in this&&e.call(t,l[r],r,l)&&(a[n++]=l[r]);return a.length=n,a})},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 a=arguments[1],l=0;l<o;){var n=t[l];if(e.call(a,n,l,t))return n;l++}},configurable:!0,writable:!0})}]);
dist/css/admin-css.css CHANGED
@@ -346,6 +346,10 @@
346
  border-width: 50px;
347
  color: #a6a6a6;
348
  display: block; }
 
 
 
 
349
  #weglot-url-translate .weglot_text_error,
350
  #wrap-weglot .weglot_text_error {
351
  color: #dc3232; }
346
  border-width: 50px;
347
  color: #a6a6a6;
348
  display: block; }
349
+ #weglot-url-translate p.weglot-keyres,
350
+ #wrap-weglot p.weglot-keyres {
351
+ font-style: italic;
352
+ color: #ff6464; }
353
  #weglot-url-translate .weglot_text_error,
354
  #wrap-weglot .weglot_text_error {
355
  color: #dc3232; }
dist/front-amp-css.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=8)}({8:function(e,t){}});
1
+ !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=6)}({6:function(e,t){}});
dist/front-css.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=16)}({16:function(e,t){}});
1
+ !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=14)}({14:function(e,t){}});
dist/front-js.js CHANGED
@@ -1 +1 @@
1
- !function(e){var t={};function o(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,o),r.l=!0,r.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 r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));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=6)}({6:function(e,t){document.addEventListener("DOMContentLoaded",function(e){const t=document.querySelector(".country-selector");if(!t)return;const o=function(e){let t=0,o=0;do{t+=e.offsetTop||0,o+=e.offsetLeft||0,e=e.offsetParent}while(e);return{top:t,left:o}}(t).top,n=document.body,r=document.documentElement,u=Math.max(n.scrollHeight,n.offsetHeight,r.clientHeight,r.scrollHeight,r.offsetHeight),i=window.getComputedStyle(t).getPropertyValue("position");window.getComputedStyle(t).getPropertyValue("bottom"),window.getComputedStyle(t).getPropertyValue("top");return("fixed"!==i&&o>u/2||"fixed"===i&&o>100)&&(t.className+=" weglot-invert"),!1})}});
1
+ !function(e){var t={};function o(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,o),r.l=!0,r.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 r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));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=4)}({4:function(e,t){document.addEventListener("DOMContentLoaded",function(e){const t=document.querySelector(".country-selector");if(!t)return;const o=function(e){let t=0,o=0;do{t+=e.offsetTop||0,o+=e.offsetLeft||0,e=e.offsetParent}while(e);return{top:t,left:o}}(t).top,n=document.body,r=document.documentElement,u=Math.max(n.scrollHeight,n.offsetHeight,r.clientHeight,r.scrollHeight,r.offsetHeight),i=window.getComputedStyle(t).getPropertyValue("position");window.getComputedStyle(t).getPropertyValue("bottom"),window.getComputedStyle(t).getPropertyValue("top");return("fixed"!==i&&o>u/2||"fixed"===i&&o>100)&&(t.className+=" weglot-invert"),!1})}});
dist/metaboxes-js.js DELETED
@@ -1 +0,0 @@
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=3)}([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){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,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(1),n(0);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=5)}({5: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)})})})})}});
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=1)}([,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)})})})})}]);
languages/weglot-de_DE.po CHANGED
@@ -294,7 +294,7 @@ msgstr ""
294
  #: templates/admin/pages/tabs/settings.php:147
295
  #, php-format
296
  msgid ""
297
- "On the Business plan, you can choose five languages. If you need more, "
298
  "please %1$supgrade your plan%2$s."
299
  msgstr ""
300
 
@@ -527,7 +527,7 @@ msgstr ""
527
 
528
  #: templates/admin/pages/tabs/appearance.php:18
529
  msgid ""
530
- "Check if you want the name of the languge. Don't check if you want the "
531
  "language code."
532
  msgstr ""
533
 
294
  #: templates/admin/pages/tabs/settings.php:147
295
  #, php-format
296
  msgid ""
297
+ "On the Business plan, you can choose 3 languages. If you need more, "
298
  "please %1$supgrade your plan%2$s."
299
  msgstr ""
300
 
527
 
528
  #: templates/admin/pages/tabs/appearance.php:18
529
  msgid ""
530
+ "Check if you want the name of the language. Don't check if you want the "
531
  "language code."
532
  msgstr ""
533
 
languages/weglot-en_GB.po CHANGED
@@ -291,7 +291,7 @@ msgstr ""
291
  #: templates/admin/pages/tabs/settings.php:147
292
  #, php-format
293
  msgid ""
294
- "On the Business plan, you can choose five languages. If you need more, "
295
  "please %1$supgrade your plan%2$s."
296
  msgstr ""
297
 
@@ -526,10 +526,10 @@ msgstr ""
526
 
527
  #: templates/admin/pages/tabs/appearance.php:18
528
  msgid ""
529
- "Check if you want the name of the languge. Don't check if you want the "
530
  "language code."
531
  msgstr ""
532
- "Check if you want the name of the languge. Don't check if you want the "
533
  "language code."
534
 
535
  #: templates/admin/pages/tabs/appearance.php:22
291
  #: templates/admin/pages/tabs/settings.php:147
292
  #, php-format
293
  msgid ""
294
+ "On the Business plan, you can choose 3 languages. If you need more, "
295
  "please %1$supgrade your plan%2$s."
296
  msgstr ""
297
 
526
 
527
  #: templates/admin/pages/tabs/appearance.php:18
528
  msgid ""
529
+ "Check if you want the name of the language. Don't check if you want the "
530
  "language code."
531
  msgstr ""
532
+ "Check if you want the name of the language. Don't check if you want the "
533
  "language code."
534
 
535
  #: templates/admin/pages/tabs/appearance.php:22
languages/weglot-es_ES.po CHANGED
@@ -292,7 +292,7 @@ msgstr ""
292
  #: templates/admin/pages/tabs/settings.php:147
293
  #, php-format
294
  msgid ""
295
- "On the Business plan, you can choose five languages. If you need more, "
296
  "please %1$supgrade your plan%2$s."
297
  msgstr ""
298
 
@@ -525,7 +525,7 @@ msgstr ""
525
 
526
  #: templates/admin/pages/tabs/appearance.php:18
527
  msgid ""
528
- "Check if you want the name of the languge. Don't check if you want the "
529
  "language code."
530
  msgstr ""
531
 
292
  #: templates/admin/pages/tabs/settings.php:147
293
  #, php-format
294
  msgid ""
295
+ "On the Business plan, you can choose 3 languages. If you need more, "
296
  "please %1$supgrade your plan%2$s."
297
  msgstr ""
298
 
525
 
526
  #: templates/admin/pages/tabs/appearance.php:18
527
  msgid ""
528
+ "Check if you want the name of the language. Don't check if you want the "
529
  "language code."
530
  msgstr ""
531
 
languages/weglot-fr_FR.po CHANGED
@@ -319,7 +319,7 @@ msgstr ""
319
  #: templates/admin/pages/tabs/settings.php:147
320
  #, php-format
321
  msgid ""
322
- "On the Business plan, you can choose five languages. If you need more, "
323
  "please %1$supgrade your plan%2$s."
324
  msgstr ""
325
  "Avec le plan Business, vous pouvez choisir cinq langues. Si vous avez besoin "
@@ -571,7 +571,7 @@ msgstr "Nom complet"
571
 
572
  #: templates/admin/pages/tabs/appearance.php:18
573
  msgid ""
574
- "Check if you want the name of the languge. Don't check if you want the "
575
  "language code."
576
  msgstr ""
577
  "Cochez si vous voulez le nom du language. Sinon ce sera le code du language."
319
  #: templates/admin/pages/tabs/settings.php:147
320
  #, php-format
321
  msgid ""
322
+ "On the Business plan, you can choose 3 languages. If you need more, "
323
  "please %1$supgrade your plan%2$s."
324
  msgstr ""
325
  "Avec le plan Business, vous pouvez choisir cinq langues. Si vous avez besoin "
571
 
572
  #: templates/admin/pages/tabs/appearance.php:18
573
  msgid ""
574
+ "Check if you want the name of the language. Don't check if you want the "
575
  "language code."
576
  msgstr ""
577
  "Cochez si vous voulez le nom du language. Sinon ce sera le code du language."
languages/weglot-it_IT.po CHANGED
@@ -293,7 +293,7 @@ msgstr ""
293
  #: templates/admin/pages/tabs/settings.php:147
294
  #, php-format
295
  msgid ""
296
- "On the Business plan, you can choose five languages. If you need more, "
297
  "please %1$supgrade your plan%2$s."
298
  msgstr ""
299
 
@@ -526,7 +526,7 @@ msgstr ""
526
 
527
  #: templates/admin/pages/tabs/appearance.php:18
528
  msgid ""
529
- "Check if you want the name of the languge. Don't check if you want the "
530
  "language code."
531
  msgstr ""
532
 
293
  #: templates/admin/pages/tabs/settings.php:147
294
  #, php-format
295
  msgid ""
296
+ "On the Business plan, you can choose 3 languages. If you need more, "
297
  "please %1$supgrade your plan%2$s."
298
  msgstr ""
299
 
526
 
527
  #: templates/admin/pages/tabs/appearance.php:18
528
  msgid ""
529
+ "Check if you want the name of the language. Don't check if you want the "
530
  "language code."
531
  msgstr ""
532
 
languages/weglot-nl_NL.po CHANGED
@@ -291,7 +291,7 @@ msgstr ""
291
  #: templates/admin/pages/tabs/settings.php:147
292
  #, php-format
293
  msgid ""
294
- "On the Business plan, you can choose five languages. If you need more, "
295
  "please %1$supgrade your plan%2$s."
296
  msgstr ""
297
 
@@ -527,7 +527,7 @@ msgstr ""
527
 
528
  #: templates/admin/pages/tabs/appearance.php:18
529
  msgid ""
530
- "Check if you want the name of the languge. Don't check if you want the "
531
  "language code."
532
  msgstr ""
533
  "Vink aan als je de naam van de taal wilt. Vink niet aan als je de taalcode "
291
  #: templates/admin/pages/tabs/settings.php:147
292
  #, php-format
293
  msgid ""
294
+ "On the Business plan, you can choose 3 languages. If you need more, "
295
  "please %1$supgrade your plan%2$s."
296
  msgstr ""
297
 
527
 
528
  #: templates/admin/pages/tabs/appearance.php:18
529
  msgid ""
530
+ "Check if you want the name of the language. Don't check if you want the "
531
  "language code."
532
  msgstr ""
533
  "Vink aan als je de naam van de taal wilt. Vink niet aan als je de taalcode "
languages/weglot-pt_BR.po CHANGED
@@ -292,7 +292,7 @@ msgstr ""
292
  #: templates/admin/pages/tabs/settings.php:147
293
  #, php-format
294
  msgid ""
295
- "On the Business plan, you can choose five languages. If you need more, "
296
  "please %1$supgrade your plan%2$s."
297
  msgstr ""
298
 
@@ -525,7 +525,7 @@ msgstr ""
525
 
526
  #: templates/admin/pages/tabs/appearance.php:18
527
  msgid ""
528
- "Check if you want the name of the languge. Don't check if you want the "
529
  "language code."
530
  msgstr ""
531
 
292
  #: templates/admin/pages/tabs/settings.php:147
293
  #, php-format
294
  msgid ""
295
+ "On the Business plan, you can choose 3 languages. If you need more, "
296
  "please %1$supgrade your plan%2$s."
297
  msgstr ""
298
 
525
 
526
  #: templates/admin/pages/tabs/appearance.php:18
527
  msgid ""
528
+ "Check if you want the name of the language. Don't check if you want the "
529
  "language code."
530
  msgstr ""
531
 
languages/weglot-ru_RU.po CHANGED
@@ -294,7 +294,7 @@ msgstr ""
294
  #: templates/admin/pages/tabs/settings.php:147
295
  #, php-format
296
  msgid ""
297
- "On the Business plan, you can choose five languages. If you need more, "
298
  "please %1$supgrade your plan%2$s."
299
  msgstr ""
300
 
@@ -527,7 +527,7 @@ msgstr ""
527
 
528
  #: templates/admin/pages/tabs/appearance.php:18
529
  msgid ""
530
- "Check if you want the name of the languge. Don't check if you want the "
531
  "language code."
532
  msgstr ""
533
 
294
  #: templates/admin/pages/tabs/settings.php:147
295
  #, php-format
296
  msgid ""
297
+ "On the Business plan, you can choose 3 languages. If you need more, "
298
  "please %1$supgrade your plan%2$s."
299
  msgstr ""
300
 
527
 
528
  #: templates/admin/pages/tabs/appearance.php:18
529
  msgid ""
530
+ "Check if you want the name of the language. Don't check if you want the "
531
  "language code."
532
  msgstr ""
533
 
languages/weglot.pot CHANGED
@@ -288,7 +288,7 @@ msgstr ""
288
  #: templates/admin/pages/tabs/settings.php:147
289
  #, php-format
290
  msgid ""
291
- "On the Business plan, you can choose five languages. If you need more, "
292
  "please %1$supgrade your plan%2$s."
293
  msgstr ""
294
 
@@ -521,7 +521,7 @@ msgstr ""
521
 
522
  #: templates/admin/pages/tabs/appearance.php:18
523
  msgid ""
524
- "Check if you want the name of the languge. Don't check if you want the "
525
  "language code."
526
  msgstr ""
527
 
288
  #: templates/admin/pages/tabs/settings.php:147
289
  #, php-format
290
  msgid ""
291
+ "On the Business plan, you can choose 3 languages. If you need more, "
292
  "please %1$supgrade your plan%2$s."
293
  msgstr ""
294
 
521
 
522
  #: templates/admin/pages/tabs/appearance.php:18
523
  msgid ""
524
+ "Check if you want the name of the language. Don't check if you want the "
525
  "language code."
526
  msgstr ""
527
 
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: remyb92, gmulti, wysija, wpr0ck
3
  Tags: translate, multilingual, language, translation, localization
4
  Requires at least: 4.5
5
- Tested up to: 5.6
6
  Requires PHP: 5.4
7
- Stable tag: 3.2.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -183,6 +183,11 @@ See changelog for upgrade changes.
183
 
184
  == Changelog ==
185
 
 
 
 
 
 
186
  = 3.2.0 (15/10/2020) =
187
  * Add translate slug option
188
  * Fix: auto redirect on traditional chinese and brazilian portuguese
@@ -690,4 +695,3 @@ See changelog for upgrade changes.
690
 
691
  = 0.40 =
692
  * Add PDF translate, fix simple dom limit, uninstall hook, no &lt;/body&gt; case.
693
-
2
  Contributors: remyb92, gmulti, wysija, wpr0ck
3
  Tags: translate, multilingual, language, translation, localization
4
  Requires at least: 4.5
5
+ Tested up to: 5.5
6
  Requires PHP: 5.4
7
+ Stable tag: 3.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
183
 
184
  == Changelog ==
185
 
186
+ = 3.3.0 (18/01/2021) =
187
+ * Full refacto of the code
188
+ * Add: custom language
189
+
190
+
191
  = 3.2.0 (15/10/2020) =
192
  * Add translate slug option
193
  * Fix: auto redirect on traditional chinese and brazilian portuguese
695
 
696
  = 0.40 =
697
  * Add PDF translate, fix simple dom limit, uninstall hook, no &lt;/body&gt; case.
 
src/actions/admin/class-admin-enqueue-weglot.php CHANGED
@@ -6,9 +6,12 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Pages_Weglot;
11
- use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
 
 
12
 
13
  /**
14
  * Enqueue CSS / JS on administration
@@ -17,8 +20,21 @@ use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
17
  *
18
  */
19
  class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  /**
 
22
  * @since 2.0
23
  */
24
  public function __construct() {
@@ -35,33 +51,18 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
35
  */
36
  public function hooks() {
37
  add_action( 'admin_enqueue_scripts', array( $this, 'weglot_admin_enqueue_scripts' ) );
38
- add_action( 'admin_enqueue_scripts', array( $this, 'weglot_admin_enqueue_scripts_metaboxes' ) );
39
  add_action( 'admin_head', array( $this, 'weglot_admin_print_head' ) );
40
  }
41
 
42
- /**
43
- * @since 2.1.0
44
- *
45
- * @return void
46
- * @param mixed $page
47
- */
48
- public function weglot_admin_enqueue_scripts_metaboxes( $page ) {
49
- if ( ! in_array( $page, [ 'post.php' ] ) ) { //phpcs:ignore
50
- return;
51
- }
52
-
53
- wp_enqueue_script( 'weglot-admin-metaboxes-js', WEGLOT_URL_DIST . '/metaboxes-js.js', array( 'jquery' ) );
54
- wp_enqueue_style( 'weglot-admin-css', WEGLOT_URL_DIST . '/css/admin-css.css', array(), WEGLOT_VERSION );
55
- }
56
-
57
 
58
  /**
59
  * Register CSS and JS
60
  *
61
- * @see admin_enqueue_scripts
62
- * @since 2.0
63
  * @param string $page
64
  * @return void
 
 
 
65
  */
66
  public function weglot_admin_enqueue_scripts( $page ) {
67
  if ( ! in_array( $page, array( 'toplevel_page_' . Helper_Pages_Weglot::SETTINGS ), true ) ) {
@@ -93,20 +94,10 @@ class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
93
  'weglot-admin',
94
  'weglot_languages',
95
  array(
96
- 'available' => json_decode(
97
- json_encode(
98
- $this->language_services->get_languages_available(
99
- array(
100
- 'sort' => true,
101
- )
102
- ),
103
- true
104
- ),
105
- true
106
- ),
107
  'limit' => $limit,
108
  'plans' => $this->user_api_services->get_plans(),
109
- 'original' => weglot_get_original_language(),
110
  )
111
  );
112
 
6
  exit;
7
  }
8
 
9
+ use Exception;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
  use WeglotWP\Helpers\Helper_Pages_Weglot;
12
+ use WeglotWP\Services\Language_Service_Weglot;
13
+ use WeglotWP\Services\Option_Service_Weglot;
14
+ use WeglotWP\Services\User_Api_Service_Weglot;
15
 
16
  /**
17
  * Enqueue CSS / JS on administration
20
  *
21
  */
22
  class Admin_Enqueue_Weglot implements Hooks_Interface_Weglot {
23
+ /**
24
+ * @var Language_Service_Weglot
25
+ */
26
+ private $language_services;
27
+ /**
28
+ * @var Option_Service_Weglot
29
+ */
30
+ private $option_services;
31
+ /**
32
+ * @var User_Api_Service_Weglot
33
+ */
34
+ private $user_api_services;
35
 
36
  /**
37
+ * @throws Exception
38
  * @since 2.0
39
  */
40
  public function __construct() {
51
  */
52
  public function hooks() {
53
  add_action( 'admin_enqueue_scripts', array( $this, 'weglot_admin_enqueue_scripts' ) );
 
54
  add_action( 'admin_head', array( $this, 'weglot_admin_print_head' ) );
55
  }
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  /**
59
  * Register CSS and JS
60
  *
 
 
61
  * @param string $page
62
  * @return void
63
+ * @throws Exception
64
+ * @since 2.0
65
+ * @see admin_enqueue_scripts
66
  */
67
  public function weglot_admin_enqueue_scripts( $page ) {
68
  if ( ! in_array( $page, array( 'toplevel_page_' . Helper_Pages_Weglot::SETTINGS ), true ) ) {
94
  'weglot-admin',
95
  'weglot_languages',
96
  array(
97
+ 'available' => $this->language_services->get_all_languages(),
 
 
 
 
 
 
 
 
 
 
98
  'limit' => $limit,
99
  'plans' => $this->user_api_services->get_plans(),
100
+ 'original' => $this->language_services->get_original_language()->getInternalCode(),
101
  )
102
  );
103
 
src/actions/admin/class-ajax-user-info.php CHANGED
@@ -7,8 +7,14 @@ if ( ! defined( 'ABSPATH' ) ) {
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
  }
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\User_Api_Service_Weglot;
11
 
12
  class Ajax_User_Info implements Hooks_Interface_Weglot {
13
+ /**
14
+ * @var User_Api_Service_Weglot
15
+ */
16
+ private $user_services;
17
+
18
  public function __construct() {
19
  $this->user_services = weglot_get_service( 'User_Api_Service_Weglot' );
20
  }
src/actions/admin/class-customize-menu-weglot.php CHANGED
@@ -7,7 +7,8 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
- use WeglotWP\Helpers\Helper_Pages_Weglot;
 
11
 
12
  /**
13
  *
@@ -16,16 +17,21 @@ use WeglotWP\Helpers\Helper_Pages_Weglot;
16
  */
17
  class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
18
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * @since 2.0
21
  */
22
  public function __construct() {
23
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
24
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
26
- $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
27
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
- $this->menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
29
  return $this;
30
  }
31
 
@@ -79,8 +85,8 @@ class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
79
  $options_menu[ 'menu-item-' . $menu_item_db_id ]['hide_current'] = 0;
80
  }
81
 
 
82
  $this->option_services->set_option_by_key( 'menu_switcher', $options_menu );
83
-
84
  }
85
 
86
  /**
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\Menu_Options_Service_Weglot;
11
+ use WeglotWP\Services\Option_Service_Weglot;
12
 
13
  /**
14
  *
17
  */
18
  class Customize_Menu_Weglot implements Hooks_Interface_Weglot {
19
 
20
+ /**
21
+ * @var Option_Service_Weglot
22
+ */
23
+ private $option_services;
24
+ /**
25
+ * @var Menu_Options_Service_Weglot
26
+ */
27
+ private $menu_options_services;
28
+
29
  /**
30
  * @since 2.0
31
  */
32
  public function __construct() {
33
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
34
+ $this->menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
 
 
 
 
35
  return $this;
36
  }
37
 
85
  $options_menu[ 'menu-item-' . $menu_item_db_id ]['hide_current'] = 0;
86
  }
87
 
88
+ delete_transient( 'weglot_cache_cdn' );
89
  $this->option_services->set_option_by_key( 'menu_switcher', $options_menu );
 
90
  }
91
 
92
  /**
src/actions/admin/class-metabox-url-translate-weglot.php DELETED
@@ -1,325 +0,0 @@
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
- use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
11
-
12
- /**
13
- *
14
- * @since 2.1.0
15
- */
16
- class Metabox_Url_Translate_Weglot implements Hooks_Interface_Weglot {
17
- protected $old_post_name = null;
18
- protected $new_post_name = null;
19
-
20
- /**
21
- * @since 2.1.0
22
- */
23
- public function __construct() {
24
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
25
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
- }
27
-
28
- /**
29
- * @see Hooks_Interface_Weglot
30
- *
31
- * @since 2.1.0
32
- * @return void
33
- */
34
- public function hooks() {
35
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes_url_translate' ) );
36
- add_action( 'save_post', array( $this, 'save_post_meta_boxes_url_translate' ), 10, 3 );
37
- add_action( 'wp_ajax_weglot_post_name', array( $this, 'weglot_post_name' ) );
38
- add_action( 'wp_ajax_weglot_reset_custom_url', array( $this, 'weglot_reset_custom_url' ) );
39
-
40
- add_filter( 'wp_insert_post_data', array( $this, 'weglot_wp_insert_post_data' ), 10, 2 );
41
- add_filter( 'wp_unique_post_slug', array( $this, 'weglot_wp_unique_post_slug' ) );
42
- }
43
-
44
- /**
45
- * @since 2.1.0
46
- *
47
- * @return void
48
- */
49
- public function weglot_reset_custom_url() {
50
- if (
51
- $_SERVER['REQUEST_METHOD'] !== 'POST' || //phpcs:ignore
52
- ! isset( $_POST['code_lang'] ) || //phpcs:ignore
53
- ! isset( $_POST['custom_url'] ) || //phpcs:ignore
54
- ! isset( $_POST['id'] ) //phpcs:ignore
55
- ) {
56
- wp_send_json_error(
57
- array(
58
- 'code' => 'missing_parameter',
59
- )
60
- );
61
- return;
62
- }
63
-
64
- $code_lang = sanitize_text_field( wp_unslash( $_POST['code_lang'] ) ); //phpcs:ignore
65
- $post_name_weglot = sanitize_text_field( wp_unslash( $_POST['custom_url'] ) ); //phpcs:ignore
66
-
67
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
68
-
69
- if ( isset( $custom_urls[ $code_lang ] ) && isset( $custom_urls[ $code_lang ][ $post_name_weglot ] ) ) {
70
- unset( $custom_urls[ $code_lang ][ $post_name_weglot ] );
71
- $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
72
- }
73
-
74
- $post = get_post( $_POST['id'] ); //phpcs:ignore
75
-
76
- wp_send_json_success(
77
- array(
78
- 'result' => array(
79
- 'slug' => $post->post_name,
80
- ),
81
- )
82
- );
83
- }
84
-
85
- /**
86
- * Improve wp_unique_post_slug with custom URLs weglot
87
- * @since 2.1.0
88
- * @param string $slug
89
- * @param array $custom_urls
90
- * @param integer $suffix
91
- * @return string
92
- */
93
- protected function search_unique_key_post_name( $slug, $custom_urls, $suffix = 2 ) {
94
- foreach ( $custom_urls as $key_code => $urls ) {
95
- if ( isset( $urls[ $slug ] ) ) {
96
- $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
97
- return $this->search_unique_key_post_name( $alt_post_name, $custom_urls, ++$suffix );
98
- }
99
- }
100
-
101
- return $slug;
102
- }
103
-
104
-
105
- /**
106
- * Filters the unique post slug.
107
- *
108
- * @since 2.1.0
109
- *
110
- * @param string $slug The post slug.
111
- */
112
- public function weglot_wp_unique_post_slug( $slug ) {
113
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
114
-
115
- return $this->search_unique_key_post_name( $slug, $custom_urls );
116
- }
117
-
118
- /**
119
- * @since 2.1.0
120
- * @return void
121
- */
122
- public function weglot_post_name() {
123
- $weglot_post_name = ( isset( $_POST['post_name'] ) && ! empty( $_POST['post_name'] ) ) ? sanitize_title( $_POST['post_name'] ) : null ; //phpcs:ignore
124
- $code_language = ( isset( $_POST['lang'] ) && ! empty( $_POST['lang'] ) ) ? sanitize_text_field( $_POST['lang'] ) : null ; //phpcs:ignore
125
- $post_id = ( isset( $_POST['id'] ) && ! empty( $_POST['id'] ) ) ? sanitize_text_field( $_POST['id'] ) : null ; //phpcs:ignore
126
-
127
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
128
-
129
- if ( ! $weglot_post_name || ! $code_language || ! $post_id ) {
130
- wp_send_json_error(
131
- array(
132
- 'success' => false,
133
- 'code' => 'missing_parameter',
134
- )
135
- );
136
- return;
137
- }
138
-
139
- // Check if not an autosave.
140
- if ( wp_is_post_autosave( $post_id ) ) {
141
- wp_send_json_error(
142
- array(
143
- 'success' => false,
144
- )
145
- );
146
- return;
147
- }
148
-
149
- // Check if not a revision.
150
- if ( wp_is_post_revision( $post_id ) ) {
151
- wp_send_json_error(
152
- array(
153
- 'success' => false,
154
- )
155
- );
156
- return;
157
- }
158
-
159
- $post = get_post( $post_id );
160
- if ( $post->post_name === $weglot_post_name ) {
161
- if ( in_array( $post->post_name, $custom_urls[ $code_language ] ) ) { // phpcs:ignore
162
- $key_post_name = array_search( $post->post_name, $custom_urls[ $code_language ] );// phpcs:ignore
163
- unset( $custom_urls[ $code_language ][ $key_post_name ] );
164
-
165
- $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
166
-
167
- wp_send_json_success(
168
- array(
169
- 'success' => true,
170
- 'result' => array(
171
- 'slug' => $weglot_post_name,
172
- ),
173
- )
174
- );
175
- return;
176
- }
177
-
178
- wp_send_json_success(
179
- array(
180
- 'code' => 'same_post_name',
181
- )
182
- );
183
-
184
- return;
185
- }
186
-
187
- if ( isset( $custom_urls[ $code_language ] ) ) {
188
- // Same use
189
- if ( isset( $custom_urls[ $code_language ][ $weglot_post_name ] ) && $custom_urls[ $code_language ][ $weglot_post_name ] === $post->post_name ) {
190
- wp_send_json_success(
191
- array(
192
- 'code' => 'same_post_name',
193
- )
194
- );
195
- return;
196
- }
197
-
198
- if ( in_array( $post->post_name, $custom_urls[ $code_language ] ) ) { // phpcs:ignore
199
- $key_post_name = array_search( $post->post_name, $custom_urls[ $code_language ] );// phpcs:ignore
200
- unset( $custom_urls[ $code_language ][ $key_post_name ] );
201
- }
202
- }
203
-
204
- $weglot_unique_slug = wp_unique_post_slug( trim( $weglot_post_name ), $post->ID, $post->post_status, $post->post_type, $post->post_parent );
205
-
206
- $custom_urls[ $code_language ][ $weglot_unique_slug ] = $post->post_name;
207
- $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
208
-
209
- wp_send_json_success(
210
- array(
211
- 'success' => true,
212
- 'result' => array(
213
- 'slug' => $weglot_unique_slug,
214
- ),
215
- )
216
- );
217
- }
218
-
219
- /**
220
- * @since 2.1.0
221
- * @return void
222
- */
223
- public function add_meta_boxes_url_translate() {
224
- global $post;
225
- if ( ! $post ) {
226
- return;
227
- }
228
-
229
- $post_type = get_post_type();
230
-
231
- $exclude_post_type_metabox = apply_filters(
232
- 'weglot_url_translate_metabox_post_type_exclude',
233
- array(
234
- 'attachment',
235
- 'seopress_404',
236
- 'product',
237
- 'shop_order',
238
- 'shop_coupon',
239
- )
240
- );
241
-
242
- if ( in_array( $post_type, $exclude_post_type_metabox ) ) { //phpcs:ignore
243
- return;
244
- }
245
-
246
- add_meta_box( 'weglot-url-translate', __( 'Weglot URL Translate', 'weglot' ), array( $this, 'weglot_url_translate_box' ) );
247
- }
248
-
249
- /**
250
- * @since 2.1.0
251
- * @return void
252
- * @param mixed $post
253
- */
254
- public function weglot_url_translate_box( $post ) {
255
- if ( ! $post ) {
256
- return;
257
- }
258
-
259
- $this->custom_urls = $this->option_services->get_option( 'custom_urls' );
260
-
261
- include_once WEGLOT_TEMPLATES_ADMIN_METABOXES . '/url-translate.php';
262
- }
263
-
264
- /**
265
- * Prevent change post_name
266
- * @since 2.1.0
267
- * @param array $data
268
- * @param array $postarr
269
- * @return array
270
- */
271
- public function weglot_wp_insert_post_data( $data, $postarr ) {
272
- $post = get_post( $postarr['ID'] );
273
- if ( $post ) {
274
- $this->old_post_name = $post->post_name;
275
- $this->new_post_name = $data['post_name'];
276
- }
277
- return $data;
278
- }
279
-
280
- /**
281
- * @since 2.1.0
282
- *
283
- * @param mixed $post_id
284
- * @return void
285
- */
286
- public function save_post_meta_boxes_url_translate( $post_id, $post, $update ) {
287
-
288
- // Add nonce for security and authentication.
289
- $post_name_weglot = isset( $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] ) ? $_POST[ Helper_Post_Meta_Weglot::POST_NAME_WEGLOT ] : []; //phpcs:ignore
290
-
291
- if ( empty( $post_name_weglot ) ) {
292
- return;
293
- }
294
-
295
- // Check if user has permissions to save data.
296
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
297
- return;
298
- }
299
-
300
- // Check if not an autosave.
301
- if ( wp_is_post_autosave( $post_id ) ) {
302
- return;
303
- }
304
-
305
- // Check if not a revision.
306
- if ( wp_is_post_revision( $post_id ) || $update ) {
307
- return;
308
- }
309
-
310
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
311
-
312
- // Update new post_name
313
- if ( $this->old_post_name !== $this->new_post_name ) {
314
- foreach ( $custom_urls as $key_code => $urls ) {
315
- $key_search = array_search( $this->old_post_name, $urls ); // phpcs:ignore
316
- if ( false === $key_search ) {
317
- continue;
318
- }
319
-
320
- $custom_urls[ $key_code ][ $key_search ] = $this->new_post_name;
321
- }
322
- $this->option_services->set_option_by_key( 'custom_urls', $custom_urls );
323
- }
324
- }
325
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/actions/admin/class-options-weglot.php CHANGED
@@ -6,10 +6,13 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
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
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
13
 
14
  /**
15
  * Sanitize options after submit form
@@ -17,8 +20,17 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
17
  * @since 2.0
18
  */
19
  class Options_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
20
 
21
  /**
 
22
  * @since 2.0
23
  */
24
  public function __construct() {
@@ -27,11 +39,12 @@ class Options_Weglot implements Hooks_Interface_Weglot {
27
  }
28
 
29
  /**
 
 
 
30
  * @see Hooks_Interface_Weglot
31
  *
32
  * @since 2.0
33
- * @version 3.0.0
34
- * @return void
35
  */
36
  public function hooks() {
37
  add_action( 'admin_post_weglot_save_settings', array( $this, 'weglot_save_settings' ) );
@@ -60,12 +73,12 @@ class Options_Weglot implements Hooks_Interface_Weglot {
60
  $redirect_url = admin_url( 'admin.php?page=' . Helper_Pages_Weglot::SETTINGS );
61
  if ( ! isset( $_GET['tab'] ) || ! isset( $_GET['_wpnonce'] ) ) { //phpcs:ignore
62
  wp_redirect( $redirect_url );
63
- return;
64
  }
65
 
66
  if ( ! wp_verify_nonce( $_GET[ '_wpnonce' ], 'weglot_save_settings' ) ) { //phpcs:ignore
67
  wp_redirect( $redirect_url );
68
- return;
69
  }
70
 
71
  $tab = $_GET[ 'tab' ]; //phpcs:ignore
@@ -106,7 +119,7 @@ class Options_Weglot implements Hooks_Interface_Weglot {
106
  }
107
  break;
108
  case Helper_Tabs_Admin_Weglot::SUPPORT:
109
- if ( array_key_exists( 'active_wc_reload', $options ) && $options['active_wc_reload'] === 'on' ) {
110
  $options_bdd['active_wc_reload'] = true;
111
  } else {
112
  $options_bdd['active_wc_reload'] = false;
@@ -179,12 +192,6 @@ class Options_Weglot implements Hooks_Interface_Weglot {
179
  $options['custom_settings']['translate_amp'] = isset( $options['custom_settings']['translate_amp'] );
180
 
181
  $options['auto_switch'] = isset( $options['auto_switch'] );
182
- foreach ( $options['languages'] as $key => $language ) {
183
- if ( 'active' === $key ) {
184
- continue;
185
- }
186
- $options['languages'][ $key ]['enabled'] = ! isset( $options['languages'][ $key ]['enabled'] );
187
- }
188
 
189
  if ( ! isset( $options['excluded_blocks'] ) ) {
190
  $options['excluded_blocks'] = array();
6
  exit;
7
  }
8
 
9
+ use Exception;
10
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
11
  use WeglotWP\Helpers\Helper_Pages_Weglot;
12
  use WeglotWP\Helpers\Helper_Flag_Type;
13
  use WeglotWP\Models\Hooks_Interface_Weglot;
14
+ use WeglotWP\Services\Option_Service_Weglot;
15
+ use WeglotWP\Services\User_Api_Service_Weglot;
16
 
17
  /**
18
  * Sanitize options after submit form
20
  * @since 2.0
21
  */
22
  class Options_Weglot implements Hooks_Interface_Weglot {
23
+ /**
24
+ * @var Option_Service_Weglot
25
+ */
26
+ private $option_services;
27
+ /**
28
+ * @var User_Api_Service_Weglot
29
+ */
30
+ private $user_api_services;
31
 
32
  /**
33
+ * @throws Exception
34
  * @since 2.0
35
  */
36
  public function __construct() {
39
  }
40
 
41
  /**
42
+ * @return void
43
+ * @throws Exception
44
+ * @version 3.0.0
45
  * @see Hooks_Interface_Weglot
46
  *
47
  * @since 2.0
 
 
48
  */
49
  public function hooks() {
50
  add_action( 'admin_post_weglot_save_settings', array( $this, 'weglot_save_settings' ) );
73
  $redirect_url = admin_url( 'admin.php?page=' . Helper_Pages_Weglot::SETTINGS );
74
  if ( ! isset( $_GET['tab'] ) || ! isset( $_GET['_wpnonce'] ) ) { //phpcs:ignore
75
  wp_redirect( $redirect_url );
76
+ exit;
77
  }
78
 
79
  if ( ! wp_verify_nonce( $_GET[ '_wpnonce' ], 'weglot_save_settings' ) ) { //phpcs:ignore
80
  wp_redirect( $redirect_url );
81
+ exit;
82
  }
83
 
84
  $tab = $_GET[ 'tab' ]; //phpcs:ignore
119
  }
120
  break;
121
  case Helper_Tabs_Admin_Weglot::SUPPORT:
122
+ if ( array_key_exists( 'active_wc_reload', $options ) && 'on' === $options['active_wc_reload'] ) {
123
  $options_bdd['active_wc_reload'] = true;
124
  } else {
125
  $options_bdd['active_wc_reload'] = false;
192
  $options['custom_settings']['translate_amp'] = isset( $options['custom_settings']['translate_amp'] );
193
 
194
  $options['auto_switch'] = isset( $options['auto_switch'] );
 
 
 
 
 
 
195
 
196
  if ( ! isset( $options['excluded_blocks'] ) ) {
197
  $options['excluded_blocks'] = array();
src/actions/admin/class-pages-weglot.php CHANGED
@@ -9,6 +9,11 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Pages_Weglot;
11
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
 
 
 
 
 
12
 
13
  /**
14
  * Register pages administration
@@ -17,15 +22,48 @@ use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
17
  *
18
  */
19
  class Pages_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  /**
22
  * @since 2.0
23
  */
24
  public function __construct() {
25
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
 
26
  $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
27
  $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
28
- $this->user_api_services = weglot_get_service( 'User_Api_Service_Weglot' );
29
  $this->wc_active_services = weglot_get_service( 'Wc_Active' );
30
  return $this;
31
  }
@@ -119,16 +157,15 @@ class Pages_Weglot implements Hooks_Interface_Weglot {
119
  /**
120
  * Page settings
121
  *
 
 
122
  * @since 2.0
123
  *
124
- * @return void
125
  */
126
  public function weglot_plugin_settings_page() {
127
  $this->tabs = Helper_Tabs_Admin_Weglot::get_full_tabs();
128
  $this->tab_active = Helper_Tabs_Admin_Weglot::SETTINGS;
129
 
130
- //delete_transient( 'weglot_cache_cdn' );
131
-
132
  if ( isset( $_GET['tab'] ) ) { // phpcs:ignore
133
  $this->tab_active = sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore
134
  }
@@ -137,7 +174,9 @@ class Pages_Weglot implements Hooks_Interface_Weglot {
137
 
138
  try {
139
  $user_info = $this->user_api_services->get_user_info();
140
- $this->option_services->set_option_by_key( 'allowed', $user_info['allowed'] );
 
 
141
  } catch ( \Exception $e ) {
142
  // If an exception occurs, do nothing, keep wg_allowed.
143
  }
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Pages_Weglot;
11
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
12
+ use WeglotWP\Services\Button_Service_Weglot;
13
+ use WeglotWP\Services\Language_Service_Weglot;
14
+ use WeglotWP\Services\Option_Service_Weglot;
15
+ use WeglotWP\Services\User_Api_Service_Weglot;
16
+ use WeglotWP\Third\Woocommerce\Wc_Active;
17
 
18
  /**
19
  * Register pages administration
22
  *
23
  */
24
  class Pages_Weglot implements Hooks_Interface_Weglot {
25
+ /**
26
+ * @var Option_Service_Weglot
27
+ */
28
+ private $option_services;
29
+ /**
30
+ * @var User_Api_Service_Weglot
31
+ */
32
+ private $user_api_services;
33
+ /**
34
+ * @var Language_Service_Weglot
35
+ */
36
+ private $language_services;
37
+ /**
38
+ * @var Button_Service_Weglot
39
+ */
40
+ private $button_services;
41
+ /**
42
+ * @var array
43
+ */
44
+ private $options;
45
+ /**
46
+ * @var array|array[]
47
+ */
48
+ private $tabs;
49
+ /**
50
+ * @var string
51
+ */
52
+ private $tab_active;
53
+ /**
54
+ * @var Wc_Active
55
+ */
56
+ private $wc_active_services;
57
+
58
 
59
  /**
60
  * @since 2.0
61
  */
62
  public function __construct() {
63
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
64
+ $this->user_api_services = weglot_get_service( 'User_Api_Service_Weglot' );
65
  $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
66
  $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
 
67
  $this->wc_active_services = weglot_get_service( 'Wc_Active' );
68
  return $this;
69
  }
157
  /**
158
  * Page settings
159
  *
160
+ * @return void
161
+ * @throws \Exception
162
  * @since 2.0
163
  *
 
164
  */
165
  public function weglot_plugin_settings_page() {
166
  $this->tabs = Helper_Tabs_Admin_Weglot::get_full_tabs();
167
  $this->tab_active = Helper_Tabs_Admin_Weglot::SETTINGS;
168
 
 
 
169
  if ( isset( $_GET['tab'] ) ) { // phpcs:ignore
170
  $this->tab_active = sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore
171
  }
174
 
175
  try {
176
  $user_info = $this->user_api_services->get_user_info();
177
+ if ( isset( $user_info['allowed'] ) ) {
178
+ $this->option_services->set_option_by_key( 'allowed', $user_info['allowed'] );
179
+ }
180
  } catch ( \Exception $e ) {
181
  // If an exception occurs, do nothing, keep wg_allowed.
182
  }
src/actions/admin/class-plugin-links-weglot.php CHANGED
@@ -34,7 +34,7 @@ class Plugin_Links_Weglot implements Hooks_Interface_Weglot {
34
  * @return array
35
  */
36
  public function weglot_plugin_action_links( $links ) {
37
- $url = get_admin_url( null, sprintf( 'admin.php?page=%s', Helper_Pages_Weglot::SETTINGS ) );
38
  $text = __( 'Settings', 'weglot' );
39
 
40
  $links[] = sprintf( '<a href="%s">%s</a>', $url, $text );
34
  * @return array
35
  */
36
  public function weglot_plugin_action_links( $links ) {
37
+ $url = get_admin_url( null, sprintf( 'admin.php?page=%s', Helper_Pages_Weglot::SETTINGS ) );
38
  $text = __( 'Settings', 'weglot' );
39
 
40
  $links[] = sprintf( '<a href="%s">%s</a>', $url, $text );
src/actions/class-email-translate-weglot.php CHANGED
@@ -7,6 +7,10 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
 
 
10
 
11
 
12
  /**
@@ -16,6 +20,22 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  *
17
  */
18
  class Email_Translate_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  /**
21
  * @since 2.0
@@ -24,6 +44,7 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
24
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
26
  $this->email_translate_services = weglot_get_service( 'Email_Translate_Service_Weglot' );
 
27
  }
28
 
29
  /**
@@ -51,7 +72,9 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
51
  return $args;
52
  }
53
 
54
- $current_and_original_language = weglot_get_current_and_original_language();
 
 
55
  $current_and_original_language_forced = apply_filters( 'weglot_translate_email_languages_forced', false );
56
 
57
  $message_and_subject = array(
@@ -74,18 +97,18 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
74
  if ( $current_and_original_language_forced['current'] !== $current_and_original_language_forced['original'] ) {
75
  $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $current_and_original_language_forced['current'] );
76
  }
77
- } elseif ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) {
78
 
79
- $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $current_and_original_language['current'] );
80
 
81
  } elseif ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
82
 
83
  $url = $this->request_url_services ->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
84
- $choose_current_language = $url->detectCurrentLanguage();
85
 
86
- if ( $choose_current_language !== $current_and_original_language['original'] ) { //If language in referer
87
 
88
- $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $choose_current_language );
89
 
90
  } elseif ( strpos( $_SERVER['HTTP_REFERER'], 'wg_language=' ) !== false ) { //phpcs:ignore
91
  //If language in parameter
@@ -94,7 +117,7 @@ class Email_Translate_Weglot implements Hooks_Interface_Weglot {
94
  $start = $pos + strlen( 'wg_language=' );
95
  $choose_current_language = substr( $_SERVER['HTTP_REFERER'], $start, 2 ); //phpcs:ignore
96
 
97
- if ( $choose_current_language && $choose_current_language !== $current_and_original_language['original'] ) {
98
  $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $choose_current_language );
99
  }
100
  }
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\Email_Translate_Service_Weglot;
11
+ use WeglotWP\Services\Language_Service_Weglot;
12
+ use WeglotWP\Services\Option_Service_Weglot;
13
+ use WeglotWP\Services\Request_Url_Service_Weglot;
14
 
15
 
16
  /**
20
  *
21
  */
22
  class Email_Translate_Weglot implements Hooks_Interface_Weglot {
23
+ /**
24
+ * @var Option_Service_Weglot
25
+ */
26
+ private $option_services;
27
+ /**
28
+ * @var Request_Url_Service_Weglot
29
+ */
30
+ private $request_url_services;
31
+ /**
32
+ * @var Email_Translate_Service_Weglot
33
+ */
34
+ private $email_translate_services;
35
+ /**
36
+ * @var Language_Service_Weglot
37
+ */
38
+ private $language_services;
39
 
40
  /**
41
  * @since 2.0
44
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
45
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
46
  $this->email_translate_services = weglot_get_service( 'Email_Translate_Service_Weglot' );
47
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
48
  }
49
 
50
  /**
72
  return $args;
73
  }
74
 
75
+ $current_language = $this->request_url_services->get_current_language();
76
+ $original_language = $this->language_services->get_original_language();
77
+
78
  $current_and_original_language_forced = apply_filters( 'weglot_translate_email_languages_forced', false );
79
 
80
  $message_and_subject = array(
97
  if ( $current_and_original_language_forced['current'] !== $current_and_original_language_forced['original'] ) {
98
  $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $current_and_original_language_forced['current'] );
99
  }
100
+ } elseif ( $current_language !== $original_language ) {
101
 
102
+ $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $current_language->getInternalCode() );
103
 
104
  } elseif ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
105
 
106
  $url = $this->request_url_services ->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
107
+ $current_language = $url->getCurrentLanguage();
108
 
109
+ if ( $current_language !== $original_language ) { //If language in referer
110
 
111
+ $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $current_language->getInternalCode() );
112
 
113
  } elseif ( strpos( $_SERVER['HTTP_REFERER'], 'wg_language=' ) !== false ) { //phpcs:ignore
114
  //If language in parameter
117
  $start = $pos + strlen( 'wg_language=' );
118
  $choose_current_language = substr( $_SERVER['HTTP_REFERER'], $start, 2 ); //phpcs:ignore
119
 
120
+ if ( $choose_current_language && $choose_current_language !== $original_language->getInternalCode() ) {
121
  $message_and_subject_translated = $this->email_translate_services->translate_email( $message_and_subject, $choose_current_language );
122
  }
123
  }
src/actions/class-migration-weglot.php CHANGED
@@ -6,9 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Morphism\Morphism;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
- use WeglotWP\Models\Schema_Option_Migration_V3;
12
 
13
  /**
14
  * Migration Weglot
@@ -18,11 +16,12 @@ use WeglotWP\Models\Schema_Option_Migration_V3;
18
  class Migration_Weglot implements Hooks_Interface_Weglot {
19
 
20
 
 
21
  /**
22
  * @since 2.0.0
23
  */
24
  public function __construct() {
25
- $this->migration_services = weglot_get_service( 'Migration_Service_Weglot' );
26
  }
27
 
28
 
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
10
 
11
  /**
12
  * Migration Weglot
16
  class Migration_Weglot implements Hooks_Interface_Weglot {
17
 
18
 
19
+
20
  /**
21
  * @since 2.0.0
22
  */
23
  public function __construct() {
24
+
25
  }
26
 
27
 
src/actions/class-register-widget-weglot.php CHANGED
@@ -20,14 +20,14 @@ class Register_Widget_Weglot implements Hooks_Interface_Weglot {
20
  * @return void
21
  */
22
  public function hooks() {
23
- add_action( 'widgets_init', array( $this, 'register_widget_weglot' ) );
24
  }
25
 
26
  /**
27
  * @since 2.0
28
  * @return void
29
  */
30
- public function register_widget_weglot() {
31
  register_widget( 'WeglotWP\Widgets\Widget_Selector_Weglot' );
32
  }
33
  }
20
  * @return void
21
  */
22
  public function hooks() {
23
+ add_action( 'widgets_init', array( $this, 'register_a_widget_weglot' ) );
24
  }
25
 
26
  /**
27
  * @since 2.0
28
  * @return void
29
  */
30
+ public function register_a_widget_weglot() {
31
  register_widget( 'WeglotWP\Widgets\Widget_Selector_Weglot' );
32
  }
33
  }
src/actions/front/class-clean-options.php CHANGED
@@ -7,10 +7,16 @@ if ( ! defined( 'ABSPATH' ) ) {
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
  }
@@ -32,7 +38,7 @@ class Clean_Options implements Hooks_Interface_Weglot {
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
  delete_transient( 'weglot_slugs_cache' );
38
  }
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\Option_Service_Weglot;
11
 
12
  class Clean_Options implements Hooks_Interface_Weglot {
13
 
14
 
15
+ /**
16
+ * @var Option_Service_Weglot
17
+ */
18
+ private $option_services;
19
+
20
  public function __construct() {
21
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
22
  }
38
  * @return void
39
  */
40
  public function clean_options() {
41
+ if ( isset( $_GET['_weglot_clean_cache_cdn'] ) && 'true' === $_GET['_weglot_clean_cache_cdn'] ) { // phpcs:ignore
42
  delete_transient( 'weglot_cache_cdn' );
43
  delete_transient( 'weglot_slugs_cache' );
44
  }
src/actions/front/class-front-enqueue-weglot.php CHANGED
@@ -7,6 +7,7 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
10
 
11
  /**
12
  * Enqueue CSS / JS on front
@@ -14,6 +15,10 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
14
  * @since 2.0
15
  */
16
  class Front_Enqueue_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
17
 
18
  /**
19
  * @since 2.0
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\Option_Service_Weglot;
11
 
12
  /**
13
  * Enqueue CSS / JS on front
15
  * @since 2.0
16
  */
17
  class Front_Enqueue_Weglot implements Hooks_Interface_Weglot {
18
+ /**
19
+ * @var Option_Service_Weglot
20
+ */
21
+ private $option_services;
22
 
23
  /**
24
  * @since 2.0
src/actions/front/class-front-menu-weglot.php CHANGED
@@ -7,7 +7,11 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
- use WeglotWP\Helpers\Helper_Pages_Weglot;
 
 
 
 
11
 
12
  /**
13
  *
@@ -15,16 +19,31 @@ use WeglotWP\Helpers\Helper_Pages_Weglot;
15
  *
16
  */
17
  class Front_Menu_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  /**
20
  * @since 2.4.0
21
  */
22
  public function __construct() {
23
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
- $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
25
- $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
26
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
27
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
28
  }
29
 
30
  /**
@@ -43,25 +62,13 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
43
  add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ) );
44
  }
45
 
46
- /**
47
- * @since 2.4.0
48
- * @param string $items
49
- * @return string
50
- */
51
- public function weglot_fallback_menu( $items ) {
52
- $button = $this->button_services->get_html();
53
- $items .= $button;
54
-
55
- return $items;
56
- }
57
-
58
  /**
59
  * @since 2.4.0
60
  * @param array $items
61
  * @return array
62
  */
63
  public function weglot_wp_get_nav_menu_items( $items ) {
64
- if ( ! $this->request_url_services->is_translatable_url() || ! weglot_current_url_is_eligible() || $this->private_language_services->private_mode_for_all_languages() ) {
65
  foreach ( $items as $key => $item ) {
66
  if ( 'weglot-switcher' !== $item->post_name ) {
67
  continue;
@@ -105,8 +112,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
105
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
106
  }
107
 
108
- $languages = weglot_get_current_languages_configured();
109
- $current_language = $this->request_url_services->get_current_language_entry();
110
 
111
  if ( $dropdown ) {
112
  $title = __( 'Choose your language', 'weglot' );
@@ -115,19 +121,21 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
115
  }
116
  $item->title = apply_filters( 'weglot_menu_parent_menu_item_title', $title );
117
  $item->attr_title = $current_language->getLocalName();
118
- $item->classes = array_merge( array( 'weglot-parent-menu-item' ), $classes, array( $current_language->getIso639() ) );
119
  $new_items[] = $item;
120
  $offset++;
121
  }
122
 
123
- foreach ( $languages as $language ) {
124
- if ( $this->private_language_services->is_active_private_mode_for_lang( $language->getIso639() ) ) {
 
 
 
125
  continue;
126
  }
127
 
128
- if (
129
- ( $dropdown && $current_language->getIso639() === $language->getIso639() ) ||
130
- ( $hide_current && $current_language->getIso639() === $language->getIso639() ) ) {
131
  continue;
132
  }
133
 
@@ -136,21 +144,27 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
136
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
137
  }
138
 
139
- $add_classes[] = 'weglot-' . $language->getIso639();
140
  if ( $with_flags ) {
141
- $add_classes[] = $language->getIso639();
142
  }
143
 
144
- $language_item = clone $item;
145
- $language_item->ID = 'weglot-' . $item->ID . '-' . $language->getIso639();
146
- $language_item->title = $this->button_services->get_name_with_language_entry( $language );
147
- $language_item->attr_title = $language->getLocalName();
148
-
149
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
150
- $l = isset( $language_code_rewrited[ $language->getIso639() ] ) ? $language_code_rewrited[ $language->getIso639() ] : $language->getIso639();
151
- $language_item->url = $this->custom_url_services->get_link_button_with_key_code( $l );
 
152
 
153
- $language_item->lang = $language->getIso639();
 
 
 
 
 
154
  $language_item->classes = array_merge( $classes, $add_classes );
155
  $language_item->menu_order += $offset + $i++;
156
  if ( $dropdown ) {
@@ -174,8 +188,10 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
174
  public function get_ancestors( $item ) {
175
  $ids = array();
176
  $_anc_id = (int) $item->db_id;
177
- while ( ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && ! in_array( $_anc_id, $ids ) ) {
 
178
  $ids[] = $_anc_id;
 
179
  }
180
  return $ids;
181
  }
@@ -186,15 +202,16 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
186
  * @return array
187
  */
188
  public function wp_nav_menu_objects( $items ) {
189
- $r_ids = $k_ids = array();
 
190
 
191
  foreach ( $items as $item ) {
192
  if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
193
- if ( in_array( 'menu-item-weglot', $item->classes ) ) {
194
  $item->current = false;
195
  $item->classes = array_diff( $item->classes, array( 'current-menu-item' ) );
196
  $r_ids = array_merge( $r_ids, $this->get_ancestors( $item ) ); // Remove the classes for these ancestors
197
- } elseif ( in_array( 'current-menu-item', $item->classes ) ) {
198
  $k_ids = array_merge( $k_ids, $this->get_ancestors( $item ) ); // Keep the classes for these ancestors
199
  }
200
  }
@@ -203,13 +220,13 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
203
  $r_ids = array_diff( $r_ids, $k_ids );
204
 
205
  foreach ( $items as $item ) {
206
- if ( ! empty( $item->db_id ) && in_array( $item->db_id, $r_ids ) ) {
207
  $item->classes = array_diff( $item->classes, array( 'current-menu-ancestor', 'current-menu-parent', 'current_page_parent', 'current_page_ancestor' ) );
208
  }
209
  }
210
 
211
  if ( apply_filters( 'weglot_active_current_menu_item', false ) ) {
212
- $current_language = weglot_get_current_language();
213
  foreach ( $items as $item ) {
214
  if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
215
  if ( in_array( 'menu-item-weglot', $item->classes, true ) && in_array( 'weglot-' . $current_language, $item->classes, true ) ) {
@@ -234,8 +251,7 @@ class Front_Menu_Weglot implements Hooks_Interface_Weglot {
234
  public function add_nav_menu_link_attributes( $attrs, $item ) {
235
  $str = 'weglot-switcher';
236
  if ( strpos( $item->post_name, $str ) !== false ) {
237
- $current_language = $this->request_url_services->get_current_language();
238
- if ( ! $this->request_url_services->is_translatable_url() || ! weglot_current_url_is_eligible() ) {
239
  $attrs['style'] = 'display:none';
240
  return $attrs;
241
  }
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\Button_Service_Weglot;
11
+
12
+ use WeglotWP\Services\Language_Service_Weglot;
13
+ use WeglotWP\Services\Option_Service_Weglot;
14
+ use WeglotWP\Services\Request_Url_Service_Weglot;
15
 
16
  /**
17
  *
19
  *
20
  */
21
  class Front_Menu_Weglot implements Hooks_Interface_Weglot {
22
+ /**
23
+ * @var Option_Service_Weglot
24
+ */
25
+ private $option_services;
26
+ /**
27
+ * @var Button_Service_Weglot
28
+ */
29
+ private $button_services;
30
+ /**
31
+ * @var Request_Url_Service_Weglot
32
+ */
33
+ private $request_url_services;
34
+ /**
35
+ * @var Language_Service_Weglot
36
+ */
37
+ private $language_services;
38
 
39
  /**
40
  * @since 2.4.0
41
  */
42
  public function __construct() {
43
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
44
+ $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
45
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
46
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
 
47
  }
48
 
49
  /**
62
  add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ) );
63
  }
64
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  * @since 2.4.0
67
  * @param array $items
68
  * @return array
69
  */
70
  public function weglot_wp_get_nav_menu_items( $items ) {
71
+ if ( ! $this->request_url_services->is_eligible_url() ) {
72
  foreach ( $items as $key => $item ) {
73
  if ( 'weglot-switcher' !== $item->post_name ) {
74
  continue;
112
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
113
  }
114
 
115
+ $current_language = $this->request_url_services->get_current_language();
 
116
 
117
  if ( $dropdown ) {
118
  $title = __( 'Choose your language', 'weglot' );
121
  }
122
  $item->title = apply_filters( 'weglot_menu_parent_menu_item_title', $title );
123
  $item->attr_title = $current_language->getLocalName();
124
+ $item->classes = array_merge( array( 'weglot-parent-menu-item' ), $classes, array( $current_language->getInternalCode() ) );
125
  $new_items[] = $item;
126
  $offset++;
127
  }
128
 
129
+ foreach ( $this->language_services->get_original_and_destination_languages( $this->request_url_services->is_allowed_private() ) as $language ) {
130
+
131
+ if (
132
+ ( $dropdown && $current_language->getInternalCode() === $language->getInternalCode() ) ||
133
+ ( $hide_current && $current_language->getInternalCode() === $language->getInternalCode() ) ) {
134
  continue;
135
  }
136
 
137
+ $link_button = $this->request_url_services->get_weglot_url()->getForLanguage( $language );
138
+ if ( ! $link_button ) {
 
139
  continue;
140
  }
141
 
144
  $classes = array_merge( $classes, explode( ' ', $this->button_services->get_flag_class() ) );
145
  }
146
 
147
+ $add_classes[] = 'weglot-' . $language->getInternalCode();
148
  if ( $with_flags ) {
149
+ $add_classes[] = $language->getInternalCode();
150
  }
151
 
152
+ if ( $language === $this->language_services->get_original_language() &&
153
+ strpos( $link_button, 'no_lredirect' ) === false && // If not exist
154
+ ( is_home() || is_front_page() ) ) { // Only for homepage
155
+ if( strpos($link_button, '?') !== false ) {
156
+ $link_button = str_replace('?' , '?no_lredirect=true&' , $link_button);
157
+ } else {
158
+ $link_button .= '?no_lredirect=true';
159
+ }
160
+ }
161
 
162
+ $language_item = clone $item;
163
+ $language_item->ID = 'weglot-' . $item->ID . '-' . $language->getInternalCode();
164
+ $language_item->title = $this->button_services->get_name_with_language_entry( $language );
165
+ $language_item->attr_title = $language->getLocalName();
166
+ $language_item->url = $link_button;
167
+ $language_item->lang = $language->getInternalCode();
168
  $language_item->classes = array_merge( $classes, $add_classes );
169
  $language_item->menu_order += $offset + $i++;
170
  if ( $dropdown ) {
188
  public function get_ancestors( $item ) {
189
  $ids = array();
190
  $_anc_id = (int) $item->db_id;
191
+ $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true );
192
+ while ( isset( $_anc_id ) && ! in_array( $_anc_id, $ids, true ) ) {
193
  $ids[] = $_anc_id;
194
+ $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true );
195
  }
196
  return $ids;
197
  }
202
  * @return array
203
  */
204
  public function wp_nav_menu_objects( $items ) {
205
+ $r_ids = array();
206
+ $k_ids = array();
207
 
208
  foreach ( $items as $item ) {
209
  if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
210
+ if ( in_array( 'menu-item-weglot', $item->classes, true ) ) {
211
  $item->current = false;
212
  $item->classes = array_diff( $item->classes, array( 'current-menu-item' ) );
213
  $r_ids = array_merge( $r_ids, $this->get_ancestors( $item ) ); // Remove the classes for these ancestors
214
+ } elseif ( in_array( 'current-menu-item', $item->classes, true ) ) {
215
  $k_ids = array_merge( $k_ids, $this->get_ancestors( $item ) ); // Keep the classes for these ancestors
216
  }
217
  }
220
  $r_ids = array_diff( $r_ids, $k_ids );
221
 
222
  foreach ( $items as $item ) {
223
+ if ( ! empty( $item->db_id ) && in_array( $item->db_id, $r_ids, true ) ) {
224
  $item->classes = array_diff( $item->classes, array( 'current-menu-ancestor', 'current-menu-parent', 'current_page_parent', 'current_page_ancestor' ) );
225
  }
226
  }
227
 
228
  if ( apply_filters( 'weglot_active_current_menu_item', false ) ) {
229
+ $current_language = $this->request_url_services->get_current_language()->getInternalCode();
230
  foreach ( $items as $item ) {
231
  if ( ! empty( $item->classes ) && is_array( $item->classes ) ) {
232
  if ( in_array( 'menu-item-weglot', $item->classes, true ) && in_array( 'weglot-' . $current_language, $item->classes, true ) ) {
251
  public function add_nav_menu_link_attributes( $attrs, $item ) {
252
  $str = 'weglot-switcher';
253
  if ( strpos( $item->post_name, $str ) !== false ) {
254
+ if ( ! $this->request_url_services->is_eligible_url() ) {
 
255
  $attrs['style'] = 'display:none';
256
  return $attrs;
257
  }
src/actions/front/class-redirect-log-user-weglot.php CHANGED
@@ -21,7 +21,6 @@ class Redirect_Log_User_Weglot implements Hooks_Interface_Weglot {
21
  * @return void
22
  */
23
  public function hooks() {
24
- // add_filter( 'login_redirect', [ '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ] );
25
  add_filter( 'logout_redirect', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ) );
26
  }
27
  }
21
  * @return void
22
  */
23
  public function hooks() {
 
24
  add_filter( 'logout_redirect', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_log_redirect' ) );
25
  }
26
  }
src/actions/front/class-search-weglot.php CHANGED
@@ -8,6 +8,10 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
 
 
11
 
12
  /**
13
  * @since 2.4.0
@@ -16,13 +20,31 @@ class Search_Weglot implements Hooks_Interface_Weglot {
16
  protected $old_search = null;
17
 
18
  protected $new_search = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  /**
21
  * @since 2.4.0
22
  */
23
  public function __construct() {
24
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
- $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
 
 
26
  }
27
 
28
  /**
@@ -59,20 +81,18 @@ class Search_Weglot implements Hooks_Interface_Weglot {
59
  if ( empty( $query->query_vars[ $query_vars_check ] ) ) {
60
  return;
61
  }
62
- $original_language = weglot_get_original_language();
63
- $current_language = weglot_get_current_language();
 
64
 
65
  if ( $original_language === $current_language ) {
66
  return;
67
  }
68
 
69
  try {
70
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
71
- $to_translate_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
72
-
73
  $parser = $this->parser_services->get_parser();
74
  $this->old_search = $query->query_vars['s'];
75
- $this->new_search = $parser->translate( $query->query_vars[ 's' ], $to_translate_language_iso, $original_language ); //phpcs:ignore
76
 
77
  if ( empty( $this->new_search ) ) {
78
  return;
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
+ use WeglotWP\Services\Language_Service_Weglot;
12
+ use WeglotWP\Services\Option_Service_Weglot;
13
+ use WeglotWP\Services\Parser_Service_Weglot;
14
+ use WeglotWP\Services\Request_Url_Service_Weglot;
15
 
16
  /**
17
  * @since 2.4.0
20
  protected $old_search = null;
21
 
22
  protected $new_search = null;
23
+ /**
24
+ * @var Option_Service_Weglot
25
+ */
26
+ private $option_services;
27
+ /**
28
+ * @var Parser_Service_Weglot
29
+ */
30
+ private $parser_services;
31
+ /**
32
+ * @var Request_Url_Service_Weglot
33
+ */
34
+ private $request_url_services;
35
+ /**
36
+ * @var Language_Service_Weglot
37
+ */
38
+ private $language_services;
39
 
40
  /**
41
  * @since 2.4.0
42
  */
43
  public function __construct() {
44
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
45
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
46
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
47
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
48
  }
49
 
50
  /**
81
  if ( empty( $query->query_vars[ $query_vars_check ] ) ) {
82
  return;
83
  }
84
+
85
+ $original_language = $this->language_services->get_original_language()->getInternalCode();
86
+ $current_language = $this->request_url_services->get_current_language()->getInternalCode();
87
 
88
  if ( $original_language === $current_language ) {
89
  return;
90
  }
91
 
92
  try {
 
 
 
93
  $parser = $this->parser_services->get_parser();
94
  $this->old_search = $query->query_vars['s'];
95
+ $this->new_search = $parser->translate( $query->query_vars[ 's' ], $current_language, $original_language ); //phpcs:ignore
96
 
97
  if ( empty( $this->new_search ) ) {
98
  return;
src/actions/front/class-shortcode-weglot.php CHANGED
@@ -7,12 +7,22 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
10
 
11
  /**
12
  *
13
  * @since 2.0
14
  */
15
  class Shortcode_Weglot {
 
 
 
 
 
 
 
 
16
 
17
  /**
18
  * @since 2.0
@@ -31,8 +41,8 @@ class Shortcode_Weglot {
31
  * @return string
32
  */
33
  public function weglot_switcher_callback() {
34
- if ( ! $this->request_url_services->is_translatable_url() || ! weglot_current_url_is_eligible() ) {
35
- return;
36
  }
37
 
38
  return $this->button_services->get_html( 'weglot-shortcode' ); //phpcs:ignore
7
  }
8
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
+ use WeglotWP\Services\Button_Service_Weglot;
11
+ use WeglotWP\Services\Request_Url_Service_Weglot;
12
 
13
  /**
14
  *
15
  * @since 2.0
16
  */
17
  class Shortcode_Weglot {
18
+ /**
19
+ * @var Button_Service_Weglot
20
+ */
21
+ private $button_services;
22
+ /**
23
+ * @var Request_Url_Service_Weglot
24
+ */
25
+ private $request_url_services;
26
 
27
  /**
28
  * @since 2.0
41
  * @return string
42
  */
43
  public function weglot_switcher_callback() {
44
+ if ( ! $this->request_url_services->is_eligible_url() ) {
45
+ return '';
46
  }
47
 
48
  return $this->button_services->get_html( 'weglot-shortcode' ); //phpcs:ignore
src/actions/front/class-translate-page-weglot.php CHANGED
@@ -6,11 +6,19 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
  use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
12
  use Weglot\Client\Api\Enum\BotType;
13
  use Weglot\Util\Server;
 
 
 
 
 
 
14
 
15
 
16
  /**
@@ -20,27 +28,54 @@ use Weglot\Util\Server;
20
  */
21
  class Translate_Page_Weglot implements Hooks_Interface_Weglot {
22
  /**
23
- * @var object
24
  */
25
  private $option_services;
26
 
27
  /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  * @since 2.0
29
  */
30
  public function __construct() {
31
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
32
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
33
- $this->redirect_services = weglot_get_service( 'Redirect_Service_Weglot' );
34
- $this->translate_services = weglot_get_service( 'Translate_Service_Weglot' );
35
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
36
- $this->href_lang_services = weglot_get_service( 'Href_Lang_Service_Weglot' );
37
  }
38
 
39
  /**
 
 
40
  * @see Hooks_Interface_Weglot
41
  *
42
  * @since 2.0
43
- * @return void
44
  */
45
  public function hooks() {
46
  if ( Helper_Is_Admin::is_wp_admin() ) {
@@ -51,29 +86,12 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
51
  return;
52
  }
53
 
54
- $this->api_key = $this->option_services->get_option( 'api_key' );
55
-
56
- if ( ! $this->api_key ) {
57
- return;
58
- }
59
-
60
- if (
61
- null === $this->request_url_services->get_current_language() ||
62
- ! $this->request_url_services->is_translatable_url()
63
- ) {
64
- return;
65
- }
66
- $this->request_url_services->init_weglot_url();
67
- $this->request_url_services->get_weglot_url()->detectUrlDetails();
68
- $this->current_language = $this->request_url_services->get_current_language();
69
-
70
- if ( $this->private_language_services->is_active_private_mode_for_lang( $this->current_language ) ) {
71
  return;
72
  }
73
 
74
  $this->prepare_request_uri();
75
  $this->prepare_rtl_language();
76
-
77
  add_action( 'init', array( $this, 'weglot_init' ), 11 );
78
  add_action( 'wp_head', array( $this, 'weglot_href_lang' ) );
79
  }
@@ -116,34 +134,35 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
116
  }
117
 
118
  /**
 
 
 
119
  * @see init
120
  * @since 2.0
121
- * @version 2.3.0
122
- * @return void
123
  */
124
  public function weglot_init() {
125
  do_action( 'weglot_init_start' );
126
 
127
- if ( $this->no_translate_action_ajax() ) {
128
- return;
129
- }
130
 
131
- $this->noredirect = false;
132
- $this->original_language = $this->option_services->get_option( 'original_language' );
133
- if ( empty( $this->original_language ) ) {
134
  return;
135
  }
136
 
137
- $full_url_no_language = $this->request_url_services->get_full_url_no_language();
 
 
 
 
138
 
139
  // URL not eligible
140
- if ( ! $this->request_url_services->is_eligible_url( $full_url_no_language ) ) {
141
  return;
142
  }
143
 
144
  $active_translation = apply_filters( 'weglot_active_translation_before_process', true );
145
 
146
- // Default : yes
147
  if ( ! $active_translation ) {
148
  return;
149
  }
@@ -158,7 +177,7 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
158
  }
159
 
160
  $active_translation = apply_filters( 'weglot_active_translation_before_treat_page', true );
161
- // Default : yes
162
  if ( ! $active_translation ) {
163
  return;
164
  }
@@ -166,9 +185,8 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
166
  $file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/content.html' );
167
 
168
  if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
169
- $this->translate_services->set_original_language( weglot_get_original_language() );
170
  $this->translate_services->set_current_language( $this->request_url_services->get_current_language() );
171
- // header( 'Content-Type: application/json' );
172
  echo $this->translate_services->weglot_treat_page( file_get_contents( $file ) ); //phpcs:ignore
173
  die;
174
  } else {
@@ -177,9 +195,10 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
177
  }
178
 
179
  /**
 
 
180
  * @since 2.0
181
  *
182
- * @return void
183
  */
184
  public function check_need_to_redirect() {
185
  if (
@@ -199,30 +218,15 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
199
  * @return void
200
  */
201
  public function prepare_request_uri() {
202
- $original_language = weglot_get_original_language();
203
- $current_language = $this->request_url_services->get_current_language( false );
204
 
205
- if ( $original_language === $current_language ) {
206
- return;
207
- }
208
-
209
- $_SERVER['REQUEST_URI'] = str_replace(
210
- '/' . $current_language . '/',
211
- '/',
212
- $_SERVER['REQUEST_URI']
213
- );
214
-
215
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
216
- $to_translate_language_iso = $this->option_services->get_iso_code_from_custom_code( $current_language );
217
-
218
- if ( isset( $custom_urls[ $to_translate_language_iso ] ) ) {
219
- foreach ( $custom_urls[ $to_translate_language_iso ] as $key => $value ) {
220
- //If we receive a not translated slug we return a 404. For example if we have /fr/products but should have /fr/produits we should have a 404
221
- $_SERVER['REQUEST_URI'] = str_replace( '/' . $value . '/', '/404/', urldecode($_SERVER['REQUEST_URI']) );
222
 
223
- $_SERVER['REQUEST_URI'] = str_replace( '/' . $key . '/', '/' . $value . '/', urldecode($_SERVER['REQUEST_URI']) );
224
- }
225
  }
 
226
  }
227
 
228
  /**
@@ -231,10 +235,10 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
231
  * @return void
232
  */
233
  public function prepare_rtl_language() {
234
- if ( $this->request_url_services->is_language_rtl( $this->current_language ) ) {
235
- $GLOBALS['text_direction'] = 'rtl';
236
  } else {
237
- $GLOBALS['text_direction'] = 'ltr';
238
  }
239
  }
240
 
@@ -245,6 +249,15 @@ class Translate_Page_Weglot implements Hooks_Interface_Weglot {
245
  * @return void
246
  */
247
  public function weglot_href_lang() {
 
 
 
 
 
 
 
 
 
248
  echo $this->href_lang_services->generate_href_lang_tags(); //phpcs:ignore
249
  }
250
  }
6
  exit;
7
  }
8
 
9
+ use Exception;
10
+ use Weglot\Client\Api\LanguageEntry;
11
  use WeglotWP\Helpers\Helper_Is_Admin;
12
  use WeglotWP\Models\Hooks_Interface_Weglot;
13
  use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
14
  use Weglot\Client\Api\Enum\BotType;
15
  use Weglot\Util\Server;
16
+ use WeglotWP\Services\Href_Lang_Service_Weglot;
17
+ use WeglotWP\Services\Language_Service_Weglot;
18
+ use WeglotWP\Services\Option_Service_Weglot;
19
+ use WeglotWP\Services\Redirect_Service_Weglot;
20
+ use WeglotWP\Services\Request_Url_Service_Weglot;
21
+ use WeglotWP\Services\Translate_Service_Weglot;
22
 
23
 
24
  /**
28
  */
29
  class Translate_Page_Weglot implements Hooks_Interface_Weglot {
30
  /**
31
+ * @var Option_Service_Weglot
32
  */
33
  private $option_services;
34
 
35
  /**
36
+ * @var LanguageEntry
37
+ */
38
+ private $current_language;
39
+ /**
40
+ * @var Request_Url_Service_Weglot
41
+ */
42
+ private $request_url_services;
43
+ /**
44
+ * @var Language_Service_Weglot
45
+ */
46
+ private $language_services;
47
+ /**
48
+ * @var Redirect_Service_Weglot
49
+ */
50
+ private $redirect_services;
51
+ /**
52
+ * @var Translate_Service_Weglot
53
+ */
54
+ private $translate_services;
55
+ /**
56
+ * @var Href_Lang_Service_Weglot
57
+ */
58
+ private $href_lang_services;
59
+
60
+ /**
61
+ * @throws Exception
62
  * @since 2.0
63
  */
64
  public function __construct() {
65
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
66
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
67
+ $this->redirect_services = weglot_get_service( 'Redirect_Service_Weglot' );
68
+ $this->translate_services = weglot_get_service( 'Translate_Service_Weglot' );
69
+ $this->href_lang_services = weglot_get_service( 'Href_Lang_Service_Weglot' );
70
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
71
  }
72
 
73
  /**
74
+ * @return void
75
+ * @throws Exception
76
  * @see Hooks_Interface_Weglot
77
  *
78
  * @since 2.0
 
79
  */
80
  public function hooks() {
81
  if ( Helper_Is_Admin::is_wp_admin() ) {
86
  return;
87
  }
88
 
89
+ if ( ! $this->option_services->get_option( 'api_key' ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  return;
91
  }
92
 
93
  $this->prepare_request_uri();
94
  $this->prepare_rtl_language();
 
95
  add_action( 'init', array( $this, 'weglot_init' ), 11 );
96
  add_action( 'wp_head', array( $this, 'weglot_href_lang' ) );
97
  }
134
  }
135
 
136
  /**
137
+ * @return void
138
+ * @throws Exception
139
+ * @version 2.3.0
140
  * @see init
141
  * @since 2.0
 
 
142
  */
143
  public function weglot_init() {
144
  do_action( 'weglot_init_start' );
145
 
146
+ //We refresh the current language as now the wp_doing_ajax is valid
147
+ $this->current_language = $this->request_url_services->get_current_language();
 
148
 
149
+ if ( ! $this->option_services->get_option( 'original_language' ) ) {
 
 
150
  return;
151
  }
152
 
153
+ if($this->request_url_services->is_allowed_private()) {
154
+ if(!isset($_COOKIE['weglot_allow_private'])) {
155
+ setcookie("weglot_allow_private" , true, time() + 86400 * 2, '/' ); //phpcs:ignore
156
+ }
157
+ }
158
 
159
  // URL not eligible
160
+ if ( ! $this->request_url_services->is_eligible_url() ) {
161
  return;
162
  }
163
 
164
  $active_translation = apply_filters( 'weglot_active_translation_before_process', true );
165
 
 
166
  if ( ! $active_translation ) {
167
  return;
168
  }
177
  }
178
 
179
  $active_translation = apply_filters( 'weglot_active_translation_before_treat_page', true );
180
+
181
  if ( ! $active_translation ) {
182
  return;
183
  }
185
  $file = apply_filters( 'weglot_debug_file', WEGLOT_DIR . '/content.html' );
186
 
187
  if ( defined( 'WEGLOT_DEBUG' ) && WEGLOT_DEBUG && file_exists( $file ) ) {
188
+ $this->translate_services->set_original_language( $this->language_services->get_original_language() );
189
  $this->translate_services->set_current_language( $this->request_url_services->get_current_language() );
 
190
  echo $this->translate_services->weglot_treat_page( file_get_contents( $file ) ); //phpcs:ignore
191
  die;
192
  } else {
195
  }
196
 
197
  /**
198
+ * @return void
199
+ * @throws Exception
200
  * @since 2.0
201
  *
 
202
  */
203
  public function check_need_to_redirect() {
204
  if (
218
  * @return void
219
  */
220
  public function prepare_request_uri() {
221
+ $original_language = $this->language_services->get_original_language();
 
222
 
223
+ // We initialize the URL here for the first time, the current language might be wrong in case of ajax with the language in a referer because at this time wp_doing_ajax is always false.
224
+ $this->current_language = $this->request_url_services->get_current_language();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
+ if ( $original_language === $this->current_language->getInternalCode() ) {
227
+ return;
228
  }
229
+ $_SERVER['REQUEST_URI'] = $this->request_url_services->get_weglot_url()->getPathAndQuery();
230
  }
231
 
232
  /**
235
  * @return void
236
  */
237
  public function prepare_rtl_language() {
238
+ if ( $this->current_language->isRtl() ) {
239
+ $GLOBALS['text_direction'] = 'rtl'; // phpcs:ignore
240
  } else {
241
+ $GLOBALS['text_direction'] = 'ltr'; // phpcs:ignore
242
  }
243
  }
244
 
249
  * @return void
250
  */
251
  public function weglot_href_lang() {
252
+ $remove_google_translate = apply_filters( 'weglot_remove_google_translate', true );
253
+ if ( $remove_google_translate ) {
254
+ $original_language = $this->language_services->get_original_language();
255
+ $current_language = $this->request_url_services->get_current_language( false );
256
+ if ( $current_language !== $original_language ) {
257
+ echo "\n" . '<meta name="google" content="notranslate"/>';
258
+ }
259
+ }
260
+
261
  echo $this->href_lang_services->generate_href_lang_tags(); //phpcs:ignore
262
  }
263
  }
src/class-bootstrap-weglot.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
 
11
 
@@ -41,15 +42,6 @@ class Bootstrap_Weglot {
41
  return $this;
42
  }
43
 
44
- /**
45
- * Get services
46
- * @since 2.0
47
- * @return array
48
- */
49
- public function get_actions() {
50
- return $this->actions;
51
- }
52
-
53
  /**
54
  * Set services
55
  * @since 2.0
@@ -77,25 +69,16 @@ class Bootstrap_Weglot {
77
  return $this;
78
  }
79
 
80
-
81
- /**
82
- * Get services
83
- * @since 2.0
84
- * @return array
85
- */
86
- public function get_services() {
87
- return $this->services;
88
- }
89
-
90
  /**
91
  * Get one service by classname
92
- * @since 2.0
93
  * @param string $name
94
  * @return object
 
 
95
  */
96
  public function get_service( $name ) {
97
  if ( ! array_key_exists( $name, $this->services ) ) {
98
- throw new \Exception( 'Service : ' . $name . ' not exist' );
99
  }
100
 
101
  if ( is_string( $this->services[ $name ] ) ) {
6
  exit;
7
  }
8
 
9
+ use Exception;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
 
12
 
42
  return $this;
43
  }
44
 
 
 
 
 
 
 
 
 
 
45
  /**
46
  * Set services
47
  * @since 2.0
69
  return $this;
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * Get one service by classname
 
74
  * @param string $name
75
  * @return object
76
+ * @throws Exception
77
+ * @since 2.0
78
  */
79
  public function get_service( $name ) {
80
  if ( ! array_key_exists( $name, $this->services ) ) {
81
+ throw new Exception( 'Service : ' . $name . ' not exist' );
82
  }
83
 
84
  if ( is_string( $this->services[ $name ] ) ) {
src/helpers/class-helper-api.php CHANGED
@@ -14,7 +14,6 @@ abstract class Helper_API {
14
 
15
  const API_BASE = 'https://api.weglot.com';
16
  const API_BASE_STAGING = 'https://api.weglot.dev';
17
- const API_BASE_OLD = 'https://weglot.com/api/';
18
  const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
19
 
20
  /**
@@ -40,14 +39,6 @@ abstract class Helper_API {
40
 
41
  return self::API_BASE;
42
  }
43
-
44
- /**
45
- * @since 3.0.0
46
- * @return string
47
- */
48
- public static function get_old_api_url() {
49
- return self::API_BASE_OLD;
50
- }
51
  }
52
 
53
 
14
 
15
  const API_BASE = 'https://api.weglot.com';
16
  const API_BASE_STAGING = 'https://api.weglot.dev';
 
17
  const CDN_BASE = 'https://cdn.weglot.com/projects-settings/';
18
 
19
  /**
39
 
40
  return self::API_BASE;
41
  }
 
 
 
 
 
 
 
 
42
  }
43
 
44
 
src/helpers/class-helper-filter-url-weglot.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace WeglotWP\Helpers;
4
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
@@ -14,63 +16,15 @@ if ( ! defined( 'ABSPATH' ) ) {
14
  */
15
  abstract class Helper_Filter_Url_Weglot {
16
 
17
- /**
18
- * @since 3.0.0
19
- * @param Weglot\Util\Url $url
20
- * @return string
21
- */
22
- protected static function prevent_subfolder_install( $url ) {
23
- $current_and_original_language = weglot_get_current_and_original_language();
24
-
25
- $url_translate = $url->getForLanguage( $current_and_original_language['current'] );
26
- $double_language = sprintf( '/%s/%s/', $current_and_original_language['current'], $current_and_original_language['current'] );
27
-
28
- $custom_urls = weglot_get_option( 'custom_urls' );
29
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
30
- $key = array_search( $current_and_original_language['current'], $language_code_rewrited, true );
31
- $to_iso_language = $key ? $key : $current_and_original_language['current'];
32
- if ( isset( $custom_urls[ $to_iso_language ] ) ) {
33
- foreach ( $custom_urls[ $to_iso_language ] as $key => $value ) {
34
- $url_translate = str_replace( '/' . $value . '/', '/' . $key . '/', $url_translate );
35
- }
36
- }
37
-
38
- if ( strpos( $url_translate, $double_language ) === false ) {
39
- return $url_translate;
40
- }
41
-
42
- return $url->getForLanguage( $current_and_original_language['original'] );
43
- }
44
-
45
- /**
46
- * @since 2.0.2
47
- * @param string $url
48
- * @return string
49
- */
50
- protected static function get_clean_base_url( $url ) {
51
- if ( strpos( $url, 'http' ) === false ) {
52
- $url = sprintf( '%s%s', get_site_url(), $url );
53
- }
54
-
55
- return apply_filters( 'weglot_get_clean_base_url', $url );
56
- }
57
-
58
  /**
59
  * @since 2.4.0
60
  * @param string $url
61
  * @return string
62
  */
63
  public static function filter_url_lambda( $url ) {
64
- $current_and_original_language = weglot_get_current_and_original_language();
65
- $request_url_service = weglot_get_request_url_service();
66
-
67
- if ( $current_and_original_language['current'] === $current_and_original_language['original'] ) {
68
- return $url;
69
- }
70
-
71
- $url = $request_url_service->create_url_object( $url );
72
-
73
- return apply_filters( 'weglot_helper_filter_url_lambda', self::prevent_subfolder_install( $url ) );
74
  }
75
 
76
  /**
@@ -81,70 +35,20 @@ abstract class Helper_Filter_Url_Weglot {
81
  * @return string
82
  */
83
  public static function filter_url_log_redirect( $url_filter ) {
84
- $current_and_original_language = weglot_get_current_and_original_language();
85
- $request_url_service = weglot_get_request_url_service();
86
- $choose_current_language = $current_and_original_language['current'];
87
 
88
- $url_filter = self::get_clean_base_url( $url_filter );
 
 
89
 
90
  $url = $request_url_service->create_url_object( $url_filter );
91
 
92
- if ( $current_and_original_language['current'] === $current_and_original_language['original']
93
  && isset( $_SERVER['HTTP_REFERER'] ) //phpcs:ignore
94
  ) {
95
- $url = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
96
- $choose_current_language = $url->detectCurrentLanguage();
97
-
98
- if ( $choose_current_language !== $current_and_original_language['original'] ) {
99
- $url = $request_url_service->create_url_object( $url_filter );
100
- }
101
- }
102
-
103
- return $url->getForLanguage( $choose_current_language );
104
- }
105
-
106
-
107
- /**
108
- * Filter url without Ajax
109
- *
110
- * @since 2.0
111
- * @param string $url_filter
112
- * @return string
113
- */
114
- public static function filter_url_without_ajax( $url_filter ) {
115
- $current_and_original_language = weglot_get_current_and_original_language();
116
- $request_url_service = weglot_get_request_url_service();
117
- if ( $current_and_original_language['current'] === $current_and_original_language['original'] ) {
118
- return $url_filter;
119
  }
120
-
121
- $url = $request_url_service->create_url_object( $url_filter );
122
-
123
- return apply_filters( 'weglot_helper_filter_url_without_ajax', self::prevent_subfolder_install( $url ) );
124
- }
125
-
126
- /**
127
- * Filter url with optional Ajax
128
- *
129
- * @since 2.0
130
- * @param string $url_filter
131
- * @return string
132
- */
133
- public static function filter_url_with_ajax( $url_filter ) {
134
- $current_and_original_language = weglot_get_current_and_original_language();
135
- $choose_current_language = $current_and_original_language['current'];
136
- $request_url_service = weglot_get_request_url_service();
137
- if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) { // Not ajax
138
- $url = $request_url_service->create_url_object( $url_filter );
139
- } else {
140
- if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
141
- // Ajax
142
- $url = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
143
- $choose_current_language = $url->detectCurrentLanguage();
144
- $url = $request_url_service->create_url_object( $url_filter );
145
- }
146
- }
147
-
148
- return $url->getForLanguage( $choose_current_language );
149
  }
150
  }
2
 
3
  namespace WeglotWP\Helpers;
4
 
5
+ use WeglotWP\Services\Language_Service_Weglot;
6
+
7
  if ( ! defined( 'ABSPATH' ) ) {
8
  exit;
9
  }
16
  */
17
  abstract class Helper_Filter_Url_Weglot {
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * @since 2.4.0
21
  * @param string $url
22
  * @return string
23
  */
24
  public static function filter_url_lambda( $url ) {
25
+ $request_url_service = weglot_get_request_url_service();
26
+ $url = $request_url_service->create_url_object( $url );
27
+ return $url->getForLanguage( $request_url_service->get_current_language() );
 
 
 
 
 
 
 
28
  }
29
 
30
  /**
35
  * @return string
36
  */
37
  public static function filter_url_log_redirect( $url_filter ) {
 
 
 
38
 
39
+ $request_url_service = weglot_get_request_url_service();
40
+ /** @var $language_service Language_Service_Weglot */
41
+ $language_service = weglot_get_service( 'Language_Service_Weglot' );
42
 
43
  $url = $request_url_service->create_url_object( $url_filter );
44
 
45
+ if ( $request_url_service->get_current_language() === $language_service->get_original_language()
46
  && isset( $_SERVER['HTTP_REFERER'] ) //phpcs:ignore
47
  ) {
48
+ $url_referer = $request_url_service->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
49
+ $current_language = $url_referer->getCurrentLanguage();
50
+ return $url->getForLanguage( $current_language );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
+ return $url->getForLanguage( $request_url_service->get_current_language() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
  }
src/helpers/class-helper-flag-type.php CHANGED
@@ -32,19 +32,6 @@ class Helper_Flag_Type {
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
32
  */
33
  const CIRCLE = 'circle';
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  /**
36
  * @since 3.0.0
37
  * @param string|int $number
src/helpers/class-helper-is-admin.php CHANGED
@@ -18,6 +18,7 @@ abstract class Helper_Is_Admin {
18
  */
19
  public static function is_wp_admin() {
20
 
21
- return is_admin() && ( ! wp_doing_ajax() || ( wp_doing_ajax() && isset( $_SERVER['HTTP_REFERER'] ) && strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) !== false ) );
 
22
  }
23
  }
18
  */
19
  public static function is_wp_admin() {
20
 
21
+ return is_admin() && ( ! wp_doing_ajax() || ( wp_doing_ajax() && isset( $_SERVER['HTTP_REFERER'] )
22
+ && strpos( esc_url_raw( $_SERVER['HTTP_REFERER'] ), 'wp-admin' ) !== false ) );
23
  }
24
  }
src/helpers/class-helper-json-inline-weglot.php CHANGED
@@ -13,40 +13,6 @@ if ( ! defined( 'ABSPATH' ) ) {
13
  */
14
  abstract class Helper_Json_Inline_Weglot {
15
 
16
- /**
17
- * @since 2.0
18
- * @param string $string
19
- * @return string
20
- */
21
- public static function format_for_api( $string ) {
22
- $string = '"' . $string . '"';
23
- return \json_decode( str_replace( '\\/', '/', str_replace( '\\\\', '\\', $string ) ) );
24
- }
25
-
26
- /**
27
- * @since 2.0
28
- * @param string $string
29
- * @return string
30
- */
31
- public static function unformat_from_api( $string ) {
32
- $string = str_replace( '"', '', str_replace( '/', '\\\\/', str_replace( '\\u', '\\\\u', \json_encode( $string ) ) ) ); //phpcs:ignore
33
- return $string;
34
- }
35
-
36
- /**
37
- * @since 2.5.0
38
- * @param string $string
39
- * @return string
40
- */
41
- public static function need_json_encode_api( $string ) {
42
- if ( strip_tags( $string ) !== $string ) { // Is HTML
43
- $str = \json_encode( $string ); //phpcs:ignore
44
- return trim( $str, '"' );
45
- }
46
-
47
- return str_replace( '"', '', \json_encode( $string ) ); //phpcs:ignore
48
- }
49
-
50
  /**
51
  * @since 2.3.0
52
  *
13
  */
14
  abstract class Helper_Json_Inline_Weglot {
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * @since 2.3.0
18
  *
src/helpers/class-helper-tabs-admin-weglot.php CHANGED
@@ -34,23 +34,6 @@ abstract class Helper_Tabs_Admin_Weglot {
34
  */
35
  const SUPPORT = 'support';
36
 
37
-
38
- /**
39
- * Get tabs constant
40
- *
41
- * @since 2.0
42
- * @static
43
- * @return array
44
- */
45
- public static function get_tabs() {
46
- return array(
47
- self::SETTINGS,
48
- self::STATUS,
49
- self::CUSTOM_URLS,
50
- self::SUPPORT,
51
- );
52
- }
53
-
54
  /**
55
  * Get full tabs information
56
  * @static
34
  */
35
  const SUPPORT = 'support';
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  /**
38
  * Get full tabs information
39
  * @static
src/models/class-schema-option-migration-v3.php DELETED
@@ -1,89 +0,0 @@
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
-
13
- class Schema_Option_Migration_V3 {
14
-
15
-
16
- /**
17
- * @since 3.0.0
18
- * @return array
19
- */
20
- public static function get_schema_migration_options_v3() {
21
- $schema = array(
22
- 'api_key_private' => 'api_key',
23
- 'allowed' => 'allowed',
24
- 'language_from' => 'original_language',
25
- 'languages' => function( $options ) {
26
- $destinations = array();
27
- foreach ( $options['destination_language'] as $item ) {
28
- $destinations[] = array(
29
- 'language_to' => $item,
30
- 'enabled' => isset( $options['private_mode'][ $item ] ) && ! $options['private_mode'][ $item ],
31
- 'automatic_translation_enabled' => true,
32
- );
33
- }
34
-
35
- return $destinations;
36
- },
37
- 'excluded_blocks' => (object) array(
38
- 'path' => 'exclude_blocks',
39
- 'fn' => function( $blocks ) {
40
- $objects = array();
41
- foreach ( $blocks as $item ) {
42
- $objects[] = array(
43
- 'value' => $item,
44
- );
45
- }
46
- return $objects;
47
- },
48
- ),
49
- 'excluded_paths' => (object) array(
50
- 'path' => 'exclude_urls',
51
- 'fn' => function( $urls ) {
52
- $objects = array();
53
- foreach ( $urls as $item ) {
54
- $objects[] = array(
55
- 'type' => Helper_Excluded_Type::MATCH_REGEX,
56
- 'value' => $item,
57
- );
58
- }
59
- return $objects;
60
- },
61
- ),
62
- 'auto_switch' => (object) array(
63
- 'path' => 'auto_redirect',
64
- 'fn' => function( $auto_redirect ) {
65
- return (bool) $auto_redirect;
66
- },
67
- ),
68
- 'auto_switch_fallback' => 'original_language',
69
- 'custom_settings' => function( $options ) {
70
- return array(
71
- 'translate_email' => (bool) $options['email_translate'],
72
- 'translate_amp' => (bool) $options['translate_amp'],
73
- 'translate_search' => (bool) $options['active_search'],
74
- 'button_style' => array(
75
- 'is_dropdown' => (bool) $options['is_dropdown'],
76
- 'full_name' => (bool) $options['is_fullname'],
77
- 'with_name' => (bool) $options['with_name'],
78
- 'with_flags' => (bool) $options['with_flags'],
79
- 'flag_type' => Helper_Flag_Type::get_flag_type_with_number( $options['flag_type'] ),
80
- 'custom_css' => $options['override_css'],
81
- ),
82
- );
83
- },
84
-
85
- );
86
-
87
- return $schema;
88
- }
89
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/models/class-schema-option-v3.php CHANGED
@@ -30,7 +30,12 @@ class Schema_Option_V3 {
30
  return $destinations;
31
  }
32
  foreach ( $languages as $item ) {
33
- $destinations[] = $item['language_to'];
 
 
 
 
 
34
  }
35
 
36
  return $destinations;
@@ -39,14 +44,10 @@ class Schema_Option_V3 {
39
  'private_mode' => (object) array(
40
  'path' => 'languages',
41
  'fn' => function( $languages ) {
42
- $private = array( 'active' => false );
43
- if ( ! $languages ) {
44
- return $private;
45
- }
46
  foreach ( $languages as $item ) {
47
  if ( ! $item['enabled'] ) {
48
  $private[ $item['language_to'] ] = true;
49
- $private['active'] = true;
50
  } else {
51
  $private[ $item['language_to'] ] = false;
52
  }
30
  return $destinations;
31
  }
32
  foreach ( $languages as $item ) {
33
+ $destinations[] = array(
34
+ 'language_to' => $item['language_to'],
35
+ 'custom_code' => $item['custom_code'],
36
+ 'custom_name' => $item['custom_name'],
37
+ 'public' => $item['enabled'],
38
+ );
39
  }
40
 
41
  return $destinations;
44
  'private_mode' => (object) array(
45
  'path' => 'languages',
46
  'fn' => function( $languages ) {
47
+ $private = array();
 
 
 
48
  foreach ( $languages as $item ) {
49
  if ( ! $item['enabled'] ) {
50
  $private[ $item['language_to'] ] = true;
 
51
  } else {
52
  $private[ $item['language_to'] ] = false;
53
  }
src/services/class-button-service-weglot.php CHANGED
@@ -6,7 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Helpers\Helper_Flag_Type;
 
10
 
11
 
12
  /**
@@ -15,17 +17,32 @@ use WeglotWP\Helpers\Helper_Flag_Type;
15
  * @since 2.0
16
  */
17
  class Button_Service_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  /**
20
  * @since 2.0
21
  */
22
  public function __construct() {
23
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
24
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
25
- $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
26
- $this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
27
- $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
28
- $this->private_language_services = weglot_get_service( 'Private_Language_Service_Weglot' );
29
  }
30
 
31
  /**
@@ -53,14 +70,10 @@ class Button_Service_Weglot {
53
  * @return string
54
  */
55
  public function get_name_with_language_entry( $language_entry ) {
56
- $with_name = $this->option_services->get_option_button( 'with_name' );
57
- $is_fullname = $this->option_services->get_option( 'is_fullname' );
58
- $name = '';
59
-
60
- if ( $with_name ) {
61
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
62
- $l = isset( $language_code_rewrited[ $language_entry->getIso639() ] ) ? $language_code_rewrited[ $language_entry->getIso639() ] : $language_entry->getIso639();
63
- $name = ( $is_fullname ) ? $language_entry->getLocalName() : strtoupper( $l );
64
  }
65
 
66
  return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
@@ -89,18 +102,14 @@ class Button_Service_Weglot {
89
  * @param string $add_class
90
  */
91
  public function get_html( $add_class = '' ) {
92
- $private_mode = $this->option_services->get_option( 'private_mode' );
93
- $original_language = weglot_get_original_language();
94
 
95
- $private_all_languages = $this->private_language_services->private_mode_for_all_languages();
96
- if ( apply_filters( 'weglot_view_button_html', $private_all_languages ) ) {
97
  return '';
98
  }
99
 
100
- $weglot_url = $this->request_url_services->get_weglot_url();
101
- $amp_regex = $this->amp_services->get_regex( true );
102
- $destination_language = weglot_get_current_destination_languages();
103
- $current_language = $this->request_url_services->get_current_language( false );
104
 
105
  if ( weglot_get_translate_amp_translation() && preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
106
  $add_class .= ' weglot-invert';
@@ -110,47 +119,50 @@ class Button_Service_Weglot {
110
  $class_aside = $this->get_class_dropdown();
111
 
112
  $button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
113
- $button_html .= sprintf( "<aside data-wg-notranslate class=\"country-selector %s\">", $class_aside . $add_class );
114
-
115
- if ( ! empty( $original_language ) && ! empty( $destination_language ) ) {
116
- $current_language_entry = $this->language_services->get_current_language_entry_from_key( $current_language );
117
- $name = $this->get_name_with_language_entry( $current_language_entry );
118
 
119
- $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . rand( 1, 1000 );
120
- $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li weglot-lang weglot-language %s" data-code-language="%s"><span>%s</span></label>', esc_attr( $uniq_id ), esc_attr( $uniq_id ), esc_attr( $flag_class . $current_language_entry->getIso639() ), esc_attr( $current_language_entry->getIso639() ), esc_html( $name ) );
121
 
122
- $button_html .= '<ul>';
 
123
 
124
- array_unshift( $destination_language, $original_language );
125
 
126
- foreach ( $destination_language as $key => $key_code ) {
127
 
128
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
129
- $to_translate_language_iso = ( $key = array_search( $key_code, $language_code_rewrited ) ) ? $key : $key_code;
130
-
131
- if ( $key_code === $current_language || $this->private_language_services->is_active_private_mode_for_lang( $to_translate_language_iso ) ) {
132
- continue;
133
- }
134
-
135
- $button_html .= sprintf( '<li class="wg-li weglot-lang weglot-language %s" data-code-language="%s">', $flag_class . $to_translate_language_iso, $to_translate_language_iso );
136
-
137
- $current_language_entry = $this->language_services->get_current_language_entry_from_key( $to_translate_language_iso );
138
- $name = $this->get_name_with_language_entry( $current_language_entry );
139
 
140
- $link_button = $this->custom_url_services->get_link_button_with_key_code( $key_code );
 
 
 
141
 
142
- $button_html .= sprintf(
143
- '<a data-wg-notranslate href="%s">%s</a>',
144
- esc_url( $link_button ),
145
- esc_html( $name )
146
- );
147
 
148
- $button_html .= '</li>';
 
 
 
 
 
 
 
149
  }
150
 
151
- $button_html .= '</ul>';
 
 
 
 
 
 
152
  }
153
 
 
 
154
  $button_html .= '</aside>';
155
 
156
  return apply_filters( 'weglot_button_html', $button_html, $add_class );
6
  exit;
7
  }
8
 
9
+ use Weglot\Client\Api\LanguageEntry;
10
  use WeglotWP\Helpers\Helper_Flag_Type;
11
+ use WeglotWP\Third\Amp\Amp_Service_Weglot;
12
 
13
 
14
  /**
17
  * @since 2.0
18
  */
19
  class Button_Service_Weglot {
20
+ /**
21
+ * @var Option_Service_Weglot
22
+ */
23
+ private $option_services;
24
+ /**
25
+ * @var Language_Service_Weglot
26
+ */
27
+ private $language_services;
28
+ /**
29
+ * @var Request_Url_Service_Weglot
30
+ */
31
+ private $request_url_services;
32
+ /**
33
+ * @var Amp_Service_Weglot
34
+ */
35
+ private $amp_services;
36
+
37
 
38
  /**
39
  * @since 2.0
40
  */
41
  public function __construct() {
42
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
43
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
44
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
45
+ $this->amp_services = weglot_get_service( 'Amp_Service_Weglot' );
 
 
46
  }
47
 
48
  /**
70
  * @return string
71
  */
72
  public function get_name_with_language_entry( $language_entry ) {
73
+ if ( $this->option_services->get_option_button( 'with_name' ) ) {
74
+ $name = ( $this->option_services->get_option( 'is_fullname' ) ) ? $language_entry->getLocalName() : strtoupper( $language_entry->getExternalCode() );
75
+ } else {
76
+ $name = '';
 
 
 
 
77
  }
78
 
79
  return apply_filters( 'weglot_get_name_with_language_entry', $name, $language_entry );
102
  * @param string $add_class
103
  */
104
  public function get_html( $add_class = '' ) {
 
 
105
 
106
+ if ( apply_filters( 'weglot_view_button_html', ! $this->request_url_services->is_eligible_url() ) ) {
 
107
  return '';
108
  }
109
 
110
+ $weglot_url = $this->request_url_services->get_weglot_url();
111
+ $amp_regex = $this->amp_services->get_regex( true );
112
+ $current_language = $this->request_url_services->get_current_language();
 
113
 
114
  if ( weglot_get_translate_amp_translation() && preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
115
  $add_class .= ' weglot-invert';
119
  $class_aside = $this->get_class_dropdown();
120
 
121
  $button_html = sprintf( '<!--Weglot %s-->', WEGLOT_VERSION );
122
+ $button_html .= sprintf( '<aside data-wg-notranslate class="country-selector %s">', $class_aside . $add_class );
 
 
 
 
123
 
124
+ $name = $this->get_name_with_language_entry( $current_language );
 
125
 
126
+ $uniq_id = 'wg' . uniqid( strtotime( 'now' ) ) . wp_rand( 1, 1000 );
127
+ $button_html .= sprintf( '<input id="%s" class="weglot_choice" type="checkbox" name="menu"/><label for="%s" class="wgcurrent wg-li weglot-lang weglot-language %s" data-code-language="%s"><span>%s</span></label>', esc_attr( $uniq_id ), esc_attr( $uniq_id ), esc_attr( $flag_class . $current_language->getInternalCode() ), esc_attr( $current_language->getInternalCode() ), esc_html( $name ) );
128
 
129
+ $button_html .= '<ul>';
130
 
131
+ foreach ( $this->language_services->get_original_and_destination_languages( $this->request_url_services->is_allowed_private() ) as $language ) {
132
 
133
+ if ( $language->getInternalCode() === $current_language->getInternalCode() ) {
134
+ continue;
135
+ }
 
 
 
 
 
 
 
 
136
 
137
+ $link_button = $this->request_url_services->get_weglot_url()->getForLanguage( $language );
138
+ if ( ! $link_button ) {
139
+ continue;
140
+ }
141
 
142
+ $button_html .= sprintf( '<li class="wg-li weglot-lang weglot-language %s" data-code-language="%s">', $flag_class . $language->getInternalCode(), $language->getInternalCode() );
143
+ $name = $this->get_name_with_language_entry( $language );
 
 
 
144
 
145
+ if ( $language === $this->language_services->get_original_language() &&
146
+ strpos( $link_button, 'no_lredirect' ) === false && // If not exist
147
+ ( is_home() || is_front_page() ) ) { // Only for homepage
148
+ if( strpos($link_button, '?') !== false ) {
149
+ $link_button = str_replace('?' , '?no_lredirect=true' , $link_button);
150
+ } else {
151
+ $link_button .= '?no_lredirect=true';
152
+ }
153
  }
154
 
155
+ $button_html .= sprintf(
156
+ '<a data-wg-notranslate href="%s">%s</a>',
157
+ esc_url( $link_button ),
158
+ esc_html( $name )
159
+ );
160
+
161
+ $button_html .= '</li>';
162
  }
163
 
164
+ $button_html .= '</ul>';
165
+
166
  $button_html .= '</aside>';
167
 
168
  return apply_filters( 'weglot_button_html', $button_html, $add_class );
src/services/class-custom-url-service-weglot.php DELETED
@@ -1,89 +0,0 @@
1
- <?php
2
-
3
- namespace WeglotWP\Services;
4
-
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit;
7
- }
8
-
9
-
10
- /**
11
- * Custom URL services
12
- *
13
- * @since 2.3.0
14
- */
15
- class Custom_Url_Service_Weglot {
16
-
17
- /**
18
- * @since 2.3.0
19
- */
20
- public function __construct() {
21
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
22
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
23
- }
24
-
25
- /**
26
- * @since 2.3.0
27
- * @param string $key_code
28
- * @param boolean $add_no_redirect
29
- * @return string
30
- */
31
- public function get_link( $key_code, $add_no_redirect = true ) {
32
-
33
- if ( apply_filters( 'weglot_need_reset_postdata', false ) ) {
34
- wp_reset_postdata();
35
- }
36
-
37
- $original_language = weglot_get_original_language();
38
- $current_language = weglot_get_current_language();
39
-
40
- $weglot_url = $this->request_url_services->get_weglot_url();
41
- $url_lang = $weglot_url->getForLanguage( $key_code );
42
-
43
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
44
-
45
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
46
- $to_translate_language_iso = ( $key = array_search( $key_code, $language_code_rewrited, true ) ) ? $key : $key_code;
47
- $current_language_iso = ( $key = array_search( $current_language, $language_code_rewrited, true ) ) ? $key : $current_language;
48
-
49
- if ( isset( $custom_urls[ $current_language_iso ] ) ) {
50
- foreach ( $custom_urls[ $current_language_iso ] as $key => $value ) {
51
- $url_lang = str_replace( '/' . $key . '/', '/' . $value . '/', urldecode($url_lang) );
52
- }
53
- }
54
-
55
- if ( isset( $custom_urls[ $to_translate_language_iso ] ) ) {
56
- foreach ( $custom_urls[ $to_translate_language_iso ] as $key => $value ) {
57
- $url_lang = str_replace( '/' . $value . '/', '/' . $key . '/', $url_lang );
58
- }
59
- }
60
-
61
- $link_button = apply_filters( 'weglot_link_language', $url_lang, $key_code );
62
-
63
- if (
64
- weglot_has_auto_redirect() &&
65
- strpos( $link_button, 'no_lredirect' ) === false && // If not exist
66
- ( is_home() || is_front_page() ) && // Only for homepage
67
- $key_code === $original_language && // Only for original language
68
- $add_no_redirect // Example : for hreflang service
69
- ) {
70
- $link_button .= '?no_lredirect=true';
71
- } else {
72
- // Remove ending "?no_lredirect=true"
73
- $link_button = preg_replace( '#\?no_lredirect=true$#', '', $link_button );
74
- }
75
-
76
- return apply_filters( 'weglot_get_link_with_key_code', $link_button );
77
- }
78
-
79
- /**
80
- * @since 2.3.0
81
- * @return string
82
- * @param mixed $key_code
83
- */
84
- public function get_link_button_with_key_code( $key_code ) {
85
- $link_button = $this->get_link( $key_code );
86
-
87
- return apply_filters( 'weglot_get_link_button_with_key_code', $link_button );
88
- }
89
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/services/class-dom-listeners-service-weglot.php DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
-
3
- namespace WeglotWP\Services;
4
-
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit;
7
- }
8
-
9
- use Weglot\Util\Text;
10
-
11
-
12
- /**
13
- * Dom Checkers
14
- *
15
- * @since 2.0
16
- */
17
- class Dom_Listeners_Service_Weglot {
18
-
19
- /**
20
- * @since 2.0
21
- */
22
- public function __construct() {
23
- if ( '1' === WEGLOT_LIB_PARSER ) {
24
- return;
25
- }
26
- $this->dom_listeners = array(
27
- 'parser.crawler.after' => new \WeglotWP\Domlisteners\Meta_Listener_Weglot(),
28
- );
29
- }
30
-
31
- /**
32
- * @since 2.0
33
- * @return array
34
- */
35
- public function get_dom_listeners() {
36
- return apply_filters( 'weglot_get_dom_listeners', $this->dom_listeners );
37
- }
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/services/class-email-translate-service-weglot.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Client\Client;
10
  use Weglot\Parser\Parser;
11
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
12
 
@@ -15,13 +14,26 @@ use Weglot\Parser\ConfigProvider\ServerConfigProvider;
15
  * @since 2.3.0
16
  */
17
  class Email_Translate_Service_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  /**
20
  * @since 2.3.0
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
 
@@ -35,26 +47,23 @@ class Email_Translate_Service_Weglot {
35
  public function translate_email( $args, $language ) {
36
  $api_key = $this->option_services->get_option( 'api_key' );
37
 
38
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
39
- $to_translate_language_iso = ( $key = array_search( $language, $language_code_rewrited ) ) ? $key : $language;
40
-
41
  if ( ! $api_key ) {
42
  return $args;
43
  }
44
 
45
  try {
46
- $original_language = weglot_get_original_language();
47
  $exclude_blocks = $this->option_services->get_exclude_blocks();
48
 
49
  $config = new ServerConfigProvider();
50
  $client = $this->parser_services->get_client();
51
  $parser = new Parser( $client, $config, $exclude_blocks );
52
- $translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $to_translate_language_iso ); //phpcs:ignore
53
 
54
  $config = new ServerConfigProvider();
55
  $client = $this->parser_services->get_client();
56
  $parser = new Parser( $client, $config, $exclude_blocks );
57
- $translated_message = $parser->translate( $args['message'], $original_language, $to_translate_language_iso ); //phpcs:ignore
58
 
59
  return array(
60
  'subject' => $translated_subject,
6
  exit;
7
  }
8
 
 
9
  use Weglot\Parser\Parser;
10
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
11
 
14
  * @since 2.3.0
15
  */
16
  class Email_Translate_Service_Weglot {
17
+ /**
18
+ * @var Option_Service_Weglot
19
+ */
20
+ private $option_services;
21
+ /**
22
+ * @var Parser_Service_Weglot
23
+ */
24
+ private $parser_services;
25
+ /**
26
+ * @var Language_Service_Weglot
27
+ */
28
+ private $language_services;
29
 
30
  /**
31
  * @since 2.3.0
32
  */
33
  public function __construct() {
34
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
35
+ $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
36
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
37
  }
38
 
39
 
47
  public function translate_email( $args, $language ) {
48
  $api_key = $this->option_services->get_option( 'api_key' );
49
 
 
 
 
50
  if ( ! $api_key ) {
51
  return $args;
52
  }
53
 
54
  try {
55
+ $original_language = $this->language_services->get_original_language()->getInternalCode();
56
  $exclude_blocks = $this->option_services->get_exclude_blocks();
57
 
58
  $config = new ServerConfigProvider();
59
  $client = $this->parser_services->get_client();
60
  $parser = new Parser( $client, $config, $exclude_blocks );
61
+ $translated_subject = $parser->translate( '<p>' . $args['subject'] . '</p>', $original_language, $language ); //phpcs:ignore
62
 
63
  $config = new ServerConfigProvider();
64
  $client = $this->parser_services->get_client();
65
  $parser = new Parser( $client, $config, $exclude_blocks );
66
+ $translated_message = $parser->translate( $args['message'], $original_language, $language ); //phpcs:ignore
67
 
68
  return array(
69
  'subject' => $translated_subject,
src/services/class-generate-switcher-service-weglot.php CHANGED
@@ -12,7 +12,23 @@ if ( ! defined( 'ABSPATH' ) ) {
12
  * @since 2.3.0
13
  */
14
  class Generate_Switcher_Service_Weglot {
15
- protected $string_version = '<!--Weglot %s-->';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * @since 2.3.0
18
  */
@@ -20,7 +36,6 @@ class Generate_Switcher_Service_Weglot {
20
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
21
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
22
  $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
23
- $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
24
  $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
25
  }
26
 
12
  * @since 2.3.0
13
  */
14
  class Generate_Switcher_Service_Weglot {
15
+ /**
16
+ * @var Option_Service_Weglot
17
+ */
18
+ private $option_services;
19
+ /**
20
+ * @var Request_Url_Service_Weglot
21
+ */
22
+ private $request_url_services;
23
+ /**
24
+ * @var Language_Service_Weglot
25
+ */
26
+ private $language_services;
27
+ /**
28
+ * @var Button_Service_Weglot
29
+ */
30
+ private $button_services;
31
+
32
  /**
33
  * @since 2.3.0
34
  */
36
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
37
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
38
  $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
 
39
  $this->button_services = weglot_get_service( 'Button_Service_Weglot' );
40
  }
41
 
src/services/class-href-lang-service-weglot.php CHANGED
@@ -11,39 +11,30 @@ if ( ! defined( 'ABSPATH' ) ) {
11
  * @since 2.3.0
12
  */
13
  class Href_Lang_Service_Weglot {
14
- protected $languages = null;
 
 
 
 
 
15
 
16
  /**
17
  * @since 2.3.0
18
  */
19
  public function __construct() {
20
- $this->custom_url_services = weglot_get_service( 'Custom_Url_Service_Weglot' );
21
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
22
- $this->private_language_service = weglot_get_service( 'Private_Language_Service_Weglot' );
23
  }
24
 
25
  /**
26
  * @since 2.3.0
27
  */
28
  public function generate_href_lang_tags() {
29
- $destination_languages = weglot_get_all_languages_configured();
30
- $render = "\n";
31
- if ( $this->private_language_service->private_mode_for_all_languages() ) {
32
  return apply_filters( 'weglot_href_lang', $render );
33
  }
34
 
35
- try {
36
- foreach ( $destination_languages as $language ) {
37
- if ( $this->private_language_service->is_active_private_mode_for_lang( $language ) ) {
38
- continue;
39
- }
40
-
41
- $url = $this->custom_url_services->get_link( $language, false );
42
- $render .= '<link rel="alternate" hreflang="' . $language . '" href="' . esc_url( $url ) . '"/>' . "\n";
43
- }
44
- } catch ( \Exception $e ) {
45
- $render = $this->request_url_services->get_weglot_url()->generateHrefLangsTags();
46
- }
47
 
48
  return apply_filters( 'weglot_href_lang', $render );
49
  }
11
  * @since 2.3.0
12
  */
13
  class Href_Lang_Service_Weglot {
14
+
15
+ /**
16
+ * @var Request_Url_Service_Weglot
17
+ */
18
+ private $request_url_services;
19
+
20
 
21
  /**
22
  * @since 2.3.0
23
  */
24
  public function __construct() {
25
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
 
 
26
  }
27
 
28
  /**
29
  * @since 2.3.0
30
  */
31
  public function generate_href_lang_tags() {
32
+ $render = "\n";
33
+ if ( ! $this->request_url_services->is_eligible_url() ) {
 
34
  return apply_filters( 'weglot_href_lang', $render );
35
  }
36
 
37
+ $render = $this->request_url_services->get_weglot_url()->generateHrefLangsTags();
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  return apply_filters( 'weglot_href_lang', $render );
40
  }
src/services/class-language-service-weglot.php CHANGED
@@ -6,10 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use Weglot\Client\Endpoint\Languages;
10
- use Weglot\Client\Client;
11
  use Weglot\Client\Api\LanguageCollection;
12
- use Weglot\Client\Factory\Languages as LanguagesFactory;
13
 
14
 
15
  /**
@@ -19,6 +18,10 @@ use Weglot\Client\Factory\Languages as LanguagesFactory;
19
  */
20
  class Language_Service_Weglot {
21
  protected $languages = null;
 
 
 
 
22
 
23
  /**
24
  * @since 2.0
@@ -38,11 +41,11 @@ class Language_Service_Weglot {
38
  }
39
 
40
  /**
41
- * Get languages available from API
42
  * @since 2.0
43
  * @version 2.0.6
44
  * @param array $params
45
- * @return array
46
  */
47
  public function get_languages_available( $params = array() ) {
48
  if ( null !== $this->languages ) {
@@ -54,116 +57,131 @@ class Language_Service_Weglot {
54
  $languages = new Languages( $client );
55
  $this->languages = $languages->handle();
56
 
 
 
57
  if ( isset( $params['sort'] ) && $params['sort'] ) {
58
- $this->languages = $this->languages->jsonSerialize();
59
  usort( $this->languages, array( $this, 'compare_language' ) );
60
-
61
- $language_collection = new LanguageCollection();
62
-
63
- foreach ( $this->languages as $language ) {
64
- $factory = new LanguagesFactory( $language );
65
- $language_collection->addOne( $factory->handle() );
66
- }
67
-
68
- $this->languages = $language_collection;
69
  }
70
 
 
 
 
 
 
 
 
 
71
  return $this->languages;
72
  }
73
 
74
  /**
75
- * Get language entry
76
- * @since 2.0
77
- * @param string $key_code
 
 
 
78
  * @return array
79
  */
80
- public function get_language( $key_code ) {
81
-
82
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
83
- $language = ( $key = array_search( $key_code, $language_code_rewrited ) ) ? $this->get_languages_available()[ $key ] : $this->get_languages_available()[ $key_code ];
84
- return $language;
85
  }
86
 
87
  /**
88
- * @since 2.0
89
- * @return array
90
- * @param null|string $type
91
  */
92
- public function get_languages_configured( $type = null ) {
93
- $languages = array();
94
- $original_language = weglot_get_original_language();
95
-
96
- if ( $original_language ) {
97
- $languages[] = $original_language;
98
  }
99
- $languages = array_merge( $languages, weglot_get_destination_languages() );
100
-
101
- $languages_object = array();
102
- foreach ( $languages as $language ) {
103
- switch ( $type ) {
104
- case 'code':
105
- $languages_object[] = $this->get_language( $language )->getIso639();
106
- break;
107
- default:
108
- $languages_object[] = $this->get_language( $language );
109
- break;
110
  }
111
  }
112
- return $languages_object;
 
113
  }
114
 
115
  /**
116
- * @since 2.0
117
- * @return array
118
- * @param null|string $type
 
119
  */
120
- public function get_current_languages_configured( $type = null ) {
121
-
122
- $languages = array();
123
- $original_language = weglot_get_original_language();
124
-
125
- if ( $original_language ) {
126
- $languages[] = $original_language;
127
- }
128
- $languages = array_merge( $languages, weglot_get_current_destination_languages() );
129
-
130
- $languages_object = array();
131
- foreach ( $languages as $language ) {
132
- switch ( $type ) {
133
- case 'code':
134
- $languages_object[] = $this->get_language( $language )->getIso639();
135
- break;
136
- default:
137
- $languages_object[] = $this->get_language( $language );
138
- break;
139
- }
140
- }
141
- return $languages_object;
142
  }
143
 
144
  /**
145
- * @since 2.3.0
146
- *
147
- * @param string $key_code
148
  * @return LanguageEntry
149
  */
150
- public function get_current_language_entry_from_key( $key_code ) {
151
-
152
- $languages = $this->get_languages_available();
153
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
154
- if ( $key = array_search( $key_code, $language_code_rewrited ) ) {
155
- $key_code = $key;
156
  }
 
 
157
 
158
- if ( isset( $languages[ $key_code ] ) ) {
159
- $current_language_entry = $languages[ $key_code ];
160
- } else {
161
- $current_language_entry = apply_filters( 'weglot_current_language_entry', $key_code );
162
- if ( $current_language_entry === $key_code ) {
163
- throw new \Exception( 'You need create a language entry' );
 
 
 
 
 
 
 
164
  }
165
  }
 
 
166
 
167
- return $current_language_entry;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
  }
6
  exit;
7
  }
8
 
9
+ use Weglot\Client\Api\LanguageEntry;
10
  use Weglot\Client\Endpoint\Languages;
 
11
  use Weglot\Client\Api\LanguageCollection;
 
12
 
13
 
14
  /**
18
  */
19
  class Language_Service_Weglot {
20
  protected $languages = null;
21
+ /**
22
+ * @var Option_Service_Weglot
23
+ */
24
+ private $option_services;
25
 
26
  /**
27
  * @since 2.0
41
  }
42
 
43
  /**
44
+ * Get defaults languages available from API
45
  * @since 2.0
46
  * @version 2.0.6
47
  * @param array $params
48
+ * @return LanguageCollection
49
  */
50
  public function get_languages_available( $params = array() ) {
51
  if ( null !== $this->languages ) {
57
  $languages = new Languages( $client );
58
  $this->languages = $languages->handle();
59
 
60
+ //We add the weglot_language_code_replace filter for custom code
61
+ $this->languages = $this->languages->jsonSerialize();
62
  if ( isset( $params['sort'] ) && $params['sort'] ) {
 
63
  usort( $this->languages, array( $this, 'compare_language' ) );
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
+ $language_collection = new LanguageCollection();
67
+ foreach ( $this->languages as $language ) {
68
+ $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
69
+ $external_code = array_key_exists( $language['internal_code'], $language_code_rewrited ) ? $language_code_rewrited[ $language['internal_code'] ] : $language['external_code'];
70
+ $entry = new LanguageEntry( $language['internal_code'], $external_code, $language['english'], $language['local'], $language['rtl'] );
71
+ $language_collection->addOne( $entry );
72
+ }
73
+ $this->languages = $language_collection;
74
  return $this->languages;
75
  }
76
 
77
  /**
78
+ * Adds a language to the language collection
79
+ * @param $internal_code
80
+ * @param $external_code
81
+ * @param $english_name
82
+ * @param $local_name
83
+ * @param bool $is_rtl
84
  * @return array
85
  */
86
+ public function add_language( $internal_code, $external_code, $english_name, $local_name, $is_rtl = false ) {
87
+ $entry = new LanguageEntry( $internal_code, $external_code, $english_name, $local_name, $is_rtl );
88
+ $this->languages->addOne( $entry );
89
+ return $this->languages;
 
90
  }
91
 
92
  /**
93
+ * Get all languages : list of 109 default languages merged with custom languages taken from options
94
+ * @return array|LanguageCollection|null
 
95
  */
96
+ public function get_all_languages() {
97
+ if ( null !== $this->languages ) {
98
+ return $this->languages;
 
 
 
99
  }
100
+
101
+ $this->languages = $this->get_languages_available( [ 'sort' => true ] );
102
+ $destination_languages = $this->option_services->get_destination_languages();
103
+ foreach ( $destination_languages as $d ) {
104
+ if ( $d['custom_name'] ) {
105
+ $this->languages = $this->add_language( $d['language_to'], $d['custom_code'], $d['custom_name'], $d['custom_name'] );
 
 
 
 
 
106
  }
107
  }
108
+
109
+ return $this->languages;
110
  }
111
 
112
  /**
113
+ * Get language entry from the internal code
114
+ * @since 3.2.1
115
+ * @param string $internal_code
116
+ * @return LanguageEntry
117
  */
118
+ public function get_language_from_internal( $internal_code ) {
119
+ return $this->get_all_languages()[ $internal_code ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
 
122
  /**
123
+ * Get language entry from the external code
124
+ * @since 3.2.1
125
+ * @param string $external_code
126
  * @return LanguageEntry
127
  */
128
+ public function get_language_from_external( $external_code ) {
129
+ foreach ( $this->get_all_languages() as $language ) {
130
+ if ( $language->getExternalCode() === $external_code ) {
131
+ return $language;
132
+ }
 
133
  }
134
+ return null;
135
+ }
136
 
137
+ /**
138
+ * Get destination languages as language entries
139
+ * @param bool $allowed_private
140
+ * @return LanguageEntry[]
141
+ */
142
+ public function get_destination_languages( $allowed_private = false ) {
143
+ $destination_languages_as_array = $this->option_services->get_destination_languages();
144
+ $destination_languages = [];
145
+ foreach ( $destination_languages_as_array as $destination_language_as_array ) {
146
+ if ( $destination_language_as_array['public'] || $allowed_private ) {
147
+ if ( $this->get_all_languages()[ $destination_language_as_array['language_to'] ] ) {
148
+ $destination_languages[] = $this->get_all_languages()[ $destination_language_as_array['language_to'] ];
149
+ }
150
  }
151
  }
152
+ return $destination_languages;
153
+ }
154
 
155
+ /**
156
+ * Get destination languages as language entries
157
+ * @param bool $allowed_private
158
+ * @return string[]
159
+ */
160
+ public function get_destination_languages_external( $allowed_private = false ) {
161
+ return array_map(
162
+ function( $l ) {
163
+ return $l->getExternalCode();
164
+ }, $this->get_destination_languages( $allowed_private )
165
+ );
166
+ }
167
+
168
+ /**
169
+ * Get original language as language entry
170
+ * @return LanguageEntry
171
+ */
172
+ public function get_original_language() {
173
+ $original_language_code = $this->option_services->get_option( 'original_language' );
174
+ return $this->get_language_from_internal( $original_language_code );
175
+ }
176
+
177
+ /**
178
+ * Get original language and destination languages as language entries
179
+ * @param bool $allowed_private
180
+ * @return LanguageEntry[]
181
+ */
182
+ public function get_original_and_destination_languages( $allowed_private = false ) {
183
+ $languages = $this->get_destination_languages( $allowed_private );
184
+ array_unshift( $languages, $this->get_original_language() );
185
+ return $languages;
186
  }
187
  }
src/services/class-menu-options-service-weglot.php CHANGED
@@ -13,6 +13,10 @@ use WeglotWP\Helpers\Helper_Menu_Options_Weglot;
13
  * @since 2.4.0
14
  */
15
  class Menu_Options_Service_Weglot {
 
 
 
 
16
 
17
  /**
18
  * @since 2.4.0
13
  * @since 2.4.0
14
  */
15
  class Menu_Options_Service_Weglot {
16
+ /**
17
+ * @var Option_Service_Weglot
18
+ */
19
+ private $option_services;
20
 
21
  /**
22
  * @since 2.4.0
src/services/class-migration-service-weglot.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
-
3
- namespace WeglotWP\Services;
4
-
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit;
7
- }
8
-
9
- use Morphism\Morphism;
10
- use WeglotWP\Models\Schema_Option_V3;
11
-
12
-
13
- /**
14
- * Migration service
15
- *
16
- * @since 2.0
17
- */
18
- class Migration_Service_Weglot {
19
-
20
- /**
21
- * @since 2.0
22
- */
23
- public function __construct() {
24
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
- }
26
- }
27
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/services/class-multisite-service-weglot.php CHANGED
@@ -13,6 +13,10 @@ if ( ! defined( 'ABSPATH' ) ) {
13
  * @since 2.0
14
  */
15
  class Multisite_Service_Weglot {
 
 
 
 
16
 
17
  /**
18
  * @since 2.0
@@ -23,6 +27,7 @@ class Multisite_Service_Weglot {
23
 
24
  /**
25
  * @since 2.0
 
26
  *
27
  * @return array
28
  */
13
  * @since 2.0
14
  */
15
  class Multisite_Service_Weglot {
16
+ /**
17
+ * @var Request_Url_Service_Weglot
18
+ */
19
+ private $request_url_services;
20
 
21
  /**
22
  * @since 2.0
27
 
28
  /**
29
  * @since 2.0
30
+ * @deprecated
31
  *
32
  * @return array
33
  */
src/services/class-option-service-weglot.php CHANGED
@@ -6,6 +6,8 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
 
9
  use Morphism\Morphism;
10
  use Weglot\Util\Regex;
11
  use WeglotWP\Helpers\Helper_Is_Admin;
@@ -72,6 +74,7 @@ class Option_Service_Weglot {
72
  );
73
 
74
  /**
 
75
  * @since 3.0.0
76
  */
77
  public function __construct() {
@@ -118,10 +121,10 @@ class Option_Service_Weglot {
118
  $key = str_replace( 'wg_', '', $api_key );
119
  $url = sprintf( '%s%s.json', Helper_API::get_cdn_url(), $key );
120
 
121
- $response = wp_remote_get(
122
  $url,
123
  array(
124
- 'timeout' => 15,
125
  )
126
  );
127
 
@@ -131,6 +134,7 @@ class Option_Service_Weglot {
131
  $body = $response['result'];
132
  } else {
133
  $body = json_decode( $response['body'], true );
 
134
  }
135
  $this->options_cdn = $body;
136
 
@@ -138,7 +142,7 @@ class Option_Service_Weglot {
138
  'success' => true,
139
  'result' => $body,
140
  );
141
- } catch ( \Exception $th ) {
142
  return array(
143
  'success' => false,
144
  );
@@ -171,7 +175,7 @@ class Option_Service_Weglot {
171
  $this->slugs_cache = $body;
172
 
173
  return $body;
174
- } catch ( \Exception $th ) {
175
  return array();
176
  }
177
  }
@@ -191,33 +195,34 @@ class Option_Service_Weglot {
191
 
192
  $url = sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $api_key );
193
 
194
- $response = wp_remote_get(
195
  $url,
196
  array(
197
- 'timeout' => 15,
198
  )
199
  );
200
 
201
  if ( is_wp_error( $response ) ) {
202
  return array(
203
  'success' => false,
204
- 'result' => $this->options_default,
205
  );
206
  }
207
 
208
  try {
209
  $body = json_decode( $response['body'], true );
210
 
211
- if ( null === $body ) {
212
  return array(
213
  'success' => false,
214
- 'result' => $this->options_default,
215
  );
216
  }
217
 
218
  $options = apply_filters( 'weglot_get_options', array_merge( $this->get_options_bdd_v3(), $body ) );
219
  $options['api_key_private'] = $this->get_api_key_private();
220
  if ( empty( $options['custom_settings']['menu_switcher'] ) ) {
 
221
  $menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
222
  $options['custom_settings']['menu_switcher'] = $menu_options_services->get_options_default();
223
  }
@@ -227,7 +232,7 @@ class Option_Service_Weglot {
227
  'success' => true,
228
  'result' => $options,
229
  );
230
- } catch ( \Exception $e ) {
231
  return array(
232
  'success' => false,
233
  );
@@ -235,10 +240,10 @@ class Option_Service_Weglot {
235
  }
236
 
237
  /**
238
- * @since 3.0.0
239
  * @param string $api_key
240
- * @param string $l_to
241
  * @return array
 
242
  */
243
  public function get_slugs_from_api_with_api_key( $api_key, $destinations_languages ) {
244
  if ( $this->slugs_from_api ) {
@@ -250,7 +255,7 @@ class Option_Service_Weglot {
250
 
251
  $url = sprintf( '%s/translations/slugs?api_key=%s&&language_to=%s', Helper_API::get_api_url(), $api_key, $destinations_language );
252
 
253
- $response = wp_remote_get( $url, array( 'timeout' => 15 ) );
254
 
255
  if ( is_wp_error( $response ) ) {
256
  continue;
@@ -268,7 +273,7 @@ class Option_Service_Weglot {
268
  $slugs[ $destinations_language ] = array_flip( $body );
269
 
270
  }
271
- } catch ( \Exception $e ) {
272
  continue;
273
  }
274
  }
@@ -279,12 +284,12 @@ class Option_Service_Weglot {
279
  }
280
 
281
  /**
282
- * @since 3.0.0
283
  * @return array
 
 
284
  */
285
  public function get_options_from_v2() {
286
  $options_v2 = get_option( WEGLOT_SLUG );
287
- // $options_v2 = json_decode( file_get_contents(WEGLOT_DIR . '/settings-example.json'), true);
288
 
289
  if ( $options_v2 ) {
290
  if ( array_key_exists( 'api_key', $options_v2 ) ) {
@@ -300,9 +305,10 @@ class Option_Service_Weglot {
300
  }
301
 
302
  /**
303
- * @since 3.0.0
304
  * @param bool $compatibility
305
  * @return string
 
 
306
  */
307
  public function get_api_key( $compatibility = false ) {
308
  $api_key = get_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key' ), false );
@@ -316,9 +322,10 @@ class Option_Service_Weglot {
316
  }
317
 
318
  /**
319
- * @since 3.0.0
320
  * @param bool $compatibility
321
  * @return bool
 
 
322
  */
323
  public function get_has_first_settings( $compatibility = false ) {
324
  $options = $this->get_options();
@@ -333,9 +340,10 @@ class Option_Service_Weglot {
333
  }
334
 
335
  /**
 
 
336
  * @since 2.0
337
  * @version 3.0.0
338
- * @return array
339
  */
340
  public function get_options() {
341
  $api_key = $this->get_api_key();
@@ -359,11 +367,13 @@ class Option_Service_Weglot {
359
  $options = apply_filters( 'weglot_get_options', array_merge( $this->options_bdd_default, $this->get_options_bdd_v3(), $options ) );
360
  $options = (array) Morphism::map( 'WeglotWP\Models\Schema_Option_V3', $options );
361
 
 
 
362
  if ( Helper_Is_Admin::is_wp_admin() && $api_key_private ) {
363
- $slugs = $this->get_slugs_from_api_with_api_key( $api_key_private, $options['destination_language'] );
364
  } else {
365
  if ( ! Helper_Is_Admin::is_wp_admin() && $api_key ) {
366
- $slugs = $this->get_slugs_from_cache_with_api_key( $api_key_private, $options['destination_language'] );
367
  }
368
  }
369
  if ( isset( $slugs ) ) {
@@ -406,10 +416,11 @@ class Option_Service_Weglot {
406
  * @return array
407
  */
408
  public function save_options_to_weglot( $options ) {
409
- $response = wp_remote_post(
 
410
  sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $options['api_key_private'] ),
411
  array(
412
- 'body' => json_encode( $options ), //phpcs: ignore
413
  'headers' => array(
414
  'technology' => 'wordpress',
415
  'Content-Type' => 'application/json; charset=utf-8',
@@ -430,9 +441,10 @@ class Option_Service_Weglot {
430
  }
431
 
432
  /**
433
- * @since 3.0.0
434
  * @param string $key
435
  * @return string|null
 
 
436
  */
437
  public function get_option_custom_settings( $key ) {
438
  $options = $this->get_options();
@@ -449,10 +461,10 @@ class Option_Service_Weglot {
449
  }
450
 
451
  /**
452
- * @since 2.0
453
  * @param string $key
454
- * @param string $language_to
455
- * @return array
 
456
  */
457
  public function get_option( $key ) {
458
  $options = $this->get_options();
@@ -465,9 +477,10 @@ class Option_Service_Weglot {
465
  }
466
 
467
  /**
468
- * @since 3.0.0
469
  * @param string $key
470
  * @return string|boolean|int
 
 
471
  */
472
  public function get_option_button( $key ) {
473
  $options = $this->get_options();
@@ -488,8 +501,9 @@ class Option_Service_Weglot {
488
  }
489
 
490
  /**
491
- * @since 2.0
492
  * @return array
 
 
493
  */
494
  public function get_exclude_blocks() {
495
  $exclude_blocks = $this->get_option( 'exclude_blocks' );
@@ -528,201 +542,83 @@ class Option_Service_Weglot {
528
  }
529
 
530
  /**
531
- * @since 2.0.4
532
- * @version 3.0.0
533
  * @return array
 
 
 
534
  */
535
- public function get_destination_languages( $formated = false ) {
536
- $destination_languages = $this->get_option( 'destination_language' );
537
-
538
- if ( ! $formated ) {
539
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
540
- $destination_languages = array_map(
541
- function ( $v ) use ( $language_code_rewrited ) {
542
- return isset( $language_code_rewrited[ $v ] ) ? $language_code_rewrited[ $v ] : $v;
543
- },
544
- $destination_languages
545
- );
546
- }
547
 
548
- return apply_filters( 'weglot_destination_languages', $destination_languages );
 
 
549
  }
550
 
551
-
552
  /**
553
- * @since 3.2.0
554
  * @return array
555
- */
556
- public function get_current_destination_languages( $current_url = null ) {
557
- $destination_languages = $this->get_destination_languages();
558
- $request_url_service = weglot_get_request_url_service();
559
-
560
- if ( is_null( $current_url ) ) {
561
- $current_url = $request_url_service->get_full_url_no_language();
562
- }
563
-
564
- $current_url = $request_url_service->url_to_relative( $current_url );
565
- $exclude_urls_by_languages = $this->get_exclude_urls_by_languages();
566
- $current_language = $request_url_service->get_current_language();
567
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
568
- $custom_urls = $request_url_service->option_services->get_option( 'custom_urls' );
569
- $current_language_iso = ( $key = array_search( $current_language, $language_code_rewrited ) ) ? $key : $current_language;
570
-
571
- if ( isset( $custom_urls[ $current_language_iso ] ) ) {
572
- foreach ( $custom_urls[ $current_language_iso ] as $key => $value ) {
573
- $current_url = str_replace( '/' . $key . '/', '/' . $value . '/', $current_url );
574
- }
575
- }
576
-
577
- foreach ( $exclude_urls_by_languages as $item ) {
578
- if ( preg_match( '#' . $item['value'] . '#', $current_url ) != 0 ) {
579
- $destination_languages = array_diff( $destination_languages, $item['excluded_languages'] );
580
- }
581
- }
582
-
583
- return apply_filters( 'weglot_current_destination_languages', $destination_languages, $current_url );
584
- }
585
-
586
-
587
- /**
588
- * @param $custom_code
589
- * @return string
590
- * @since 3.2.0
591
- */
592
- public function get_iso_code_from_custom_code( $custom_code ) {
593
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
594
- $key = array_search( $custom_code, $language_code_rewrited, true );
595
- return $key ? $key : $custom_code;
596
- }
597
-
598
- /**
599
  * @since 2.0
600
- * @return array
601
  */
602
  public function get_exclude_urls() {
603
- $list_exclude_urls = $this->get_option( 'exclude_urls' );
604
- $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
605
- $destination_languages = $this->get_destination_languages( true );
606
- $exclude_urls = array();
 
607
  if ( ! empty( $list_exclude_urls ) ) {
608
  foreach ( $list_exclude_urls as $item ) {
609
  if ( is_array( $item ) ) {
610
- if ( ! empty( $item['excluded_languages'] ) ) {
611
-
612
- if ( ! is_array( $item['excluded_languages'] ) ) {
613
- continue;
614
- }
615
-
616
- $not_exclude = array_diff( $destination_languages, $item['excluded_languages'] );
617
- if ( empty( $not_exclude ) ) {
618
- //$exclude_urls[] = $item;
619
- } else {
620
- continue;
621
  }
622
  }
623
  $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
624
- $exclude_urls[] = $regex->getRegex();
625
- } else {
626
- $exclude_urls[] = $item;
627
  }
628
  }
629
  }
630
- $exclude_urls[] = '/wp-login.php';
631
- $exclude_urls[] = '/sitemaps_xsl.xsl';
632
- $exclude_urls[] = '/sitemaps.xml';
633
- $exclude_urls[] = '/wp-cron.php';
634
- $exclude_urls[] = '/wp-comments-post.php';
635
- $exclude_urls[] = '/ct_template'; // Compatibility Oxygen
636
- $exclude_urls[] = '/main-sitemap.xsl'; // SEO by Rank Math
637
-
638
- $translate_amp = weglot_get_translate_amp_translation();
639
- if ( ! $translate_amp ) {
640
- $exclude_urls[] = weglot_get_service( 'Amp_Service_Weglot' )->get_regex();
641
- }
642
-
643
- // array_map : Need only for those who use the filter
644
- return apply_filters(
645
- 'weglot_exclude_urls',
646
- array_map(
647
- function( $value ) use ( $request_url_services ) {
648
- return $request_url_services->url_to_relative( $value );
649
- },
650
- $exclude_urls
651
- )
652
- );
653
- }
654
 
 
 
 
 
 
 
 
655
 
656
- /**
657
- * @since 3.2.0
658
- * @return array
659
- */
660
- public function get_exclude_urls_by_languages() {
661
- $list_exclude_urls = $this->get_option( 'exclude_urls' );
662
- $exclude_urls = array();
663
-
664
- if ( ! empty( $list_exclude_urls ) ) {
665
-
666
- $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
667
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
668
-
669
- foreach ( $list_exclude_urls as $item ) {
670
- if (
671
- is_array( $item )
672
- && ! empty( $item['excluded_languages'] )
673
- && is_array( $item['excluded_languages'] )
674
- ) {
675
-
676
- $item['excluded_languages'] = array_map(
677
- function ( $v ) use ( $language_code_rewrited ) {
678
- return isset( $language_code_rewrited[ $v ] ) ? $language_code_rewrited[ $v ] : $v;
679
- },
680
- $item['excluded_languages']
681
- );
682
-
683
- $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
684
- $exclude_urls[] = array(
685
- 'value' => $regex->getRegex(),
686
- 'excluded_languages' => $item['excluded_languages'],
687
- );
688
-
689
- } else {
690
- continue;
691
- }
692
- }
693
  }
694
-
695
- apply_filters( 'weglot_exclude_urls_by_languages', $exclude_urls );
696
-
697
- // Need only for those who use the filter
698
- foreach ( $exclude_urls as $exclude_url ) {
699
- $exclude_url['value'] = $request_url_services->url_to_relative( $exclude_url['value'] );
700
- }
701
-
702
- return $exclude_urls;
703
  }
704
 
705
  /**
 
 
706
  * @since 2.0
707
  *
708
- * @return string
709
  */
710
  public function get_css_custom_inline() {
711
  return apply_filters( 'weglot_css_custom_inline', $this->get_option( 'override_css' ) );
712
  }
713
 
714
  /**
 
 
715
  * @since 2.0
716
  *
717
- * @return string
718
  */
719
  public function get_flag_css() {
720
  return apply_filters( 'weglot_flag_css', $this->get_option( 'flag_css' ) );
721
  }
722
 
723
  /**
724
- * @since 3.0.0
725
  * @return int
 
 
726
  */
727
  public function get_translation_engine() {
728
  return apply_filters( 'weglot_get_translation_engine', $this->get_option( 'translation_engine' ) );
@@ -764,7 +660,7 @@ class Option_Service_Weglot {
764
  }
765
  /**
766
  * @param string $key
767
- * @return any
768
  */
769
  public function get_option_by_key_v3( $key ) {
770
  $options = $this->get_options_bdd_v3();
6
  exit;
7
  }
8
 
9
+ use Exception;
10
+ use http\Env\Request;
11
  use Morphism\Morphism;
12
  use Weglot\Util\Regex;
13
  use WeglotWP\Helpers\Helper_Is_Admin;
74
  );
75
 
76
  /**
77
+ * @throws Exception
78
  * @since 3.0.0
79
  */
80
  public function __construct() {
121
  $key = str_replace( 'wg_', '', $api_key );
122
  $url = sprintf( '%s%s.json', Helper_API::get_cdn_url(), $key );
123
 
124
+ $response = wp_remote_get( // phpcs:ignore
125
  $url,
126
  array(
127
+ 'timeout' => 3,
128
  )
129
  );
130
 
134
  $body = $response['result'];
135
  } else {
136
  $body = json_decode( $response['body'], true );
137
+ set_transient( 'weglot_cache_cdn', $body, apply_filters( 'weglot_get_options_from_cdn_cache_duration', 300 ) );
138
  }
139
  $this->options_cdn = $body;
140
 
142
  'success' => true,
143
  'result' => $body,
144
  );
145
+ } catch ( Exception $th ) {
146
  return array(
147
  'success' => false,
148
  );
175
  $this->slugs_cache = $body;
176
 
177
  return $body;
178
+ } catch ( Exception $th ) {
179
  return array();
180
  }
181
  }
195
 
196
  $url = sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $api_key );
197
 
198
+ $response = wp_remote_get( // phpcs:ignore
199
  $url,
200
  array(
201
+ 'timeout' => 3,
202
  )
203
  );
204
 
205
  if ( is_wp_error( $response ) ) {
206
  return array(
207
  'success' => false,
208
+ 'result' => $this->get_options_default(),
209
  );
210
  }
211
 
212
  try {
213
  $body = json_decode( $response['body'], true );
214
 
215
+ if ( null === $body || !is_array($body)) {
216
  return array(
217
  'success' => false,
218
+ 'result' => $this->get_options_default(),
219
  );
220
  }
221
 
222
  $options = apply_filters( 'weglot_get_options', array_merge( $this->get_options_bdd_v3(), $body ) );
223
  $options['api_key_private'] = $this->get_api_key_private();
224
  if ( empty( $options['custom_settings']['menu_switcher'] ) ) {
225
+ /** @var $menu_options_services Menu_Options_Service_Weglot */
226
  $menu_options_services = weglot_get_service( 'Menu_Options_Service_Weglot' );
227
  $options['custom_settings']['menu_switcher'] = $menu_options_services->get_options_default();
228
  }
232
  'success' => true,
233
  'result' => $options,
234
  );
235
+ } catch ( Exception $e ) {
236
  return array(
237
  'success' => false,
238
  );
240
  }
241
 
242
  /**
 
243
  * @param string $api_key
244
+ * @param $destinations_languages
245
  * @return array
246
+ * @since 3.0.0
247
  */
248
  public function get_slugs_from_api_with_api_key( $api_key, $destinations_languages ) {
249
  if ( $this->slugs_from_api ) {
255
 
256
  $url = sprintf( '%s/translations/slugs?api_key=%s&&language_to=%s', Helper_API::get_api_url(), $api_key, $destinations_language );
257
 
258
+ $response = wp_remote_get( $url, array( 'timeout' => 3 ) ); // phpcs:ignore
259
 
260
  if ( is_wp_error( $response ) ) {
261
  continue;
273
  $slugs[ $destinations_language ] = array_flip( $body );
274
 
275
  }
276
+ } catch ( Exception $e ) {
277
  continue;
278
  }
279
  }
284
  }
285
 
286
  /**
 
287
  * @return array
288
+ * @throws Exception
289
+ * @since 3.0.0
290
  */
291
  public function get_options_from_v2() {
292
  $options_v2 = get_option( WEGLOT_SLUG );
 
293
 
294
  if ( $options_v2 ) {
295
  if ( array_key_exists( 'api_key', $options_v2 ) ) {
305
  }
306
 
307
  /**
 
308
  * @param bool $compatibility
309
  * @return string
310
+ * @throws Exception
311
+ * @since 3.0.0
312
  */
313
  public function get_api_key( $compatibility = false ) {
314
  $api_key = get_option( sprintf( '%s-%s', WEGLOT_SLUG, 'api_key' ), false );
322
  }
323
 
324
  /**
 
325
  * @param bool $compatibility
326
  * @return bool
327
+ * @throws Exception
328
+ * @since 3.0.0
329
  */
330
  public function get_has_first_settings( $compatibility = false ) {
331
  $options = $this->get_options();
340
  }
341
 
342
  /**
343
+ * @return array
344
+ * @throws Exception
345
  * @since 2.0
346
  * @version 3.0.0
 
347
  */
348
  public function get_options() {
349
  $api_key = $this->get_api_key();
367
  $options = apply_filters( 'weglot_get_options', array_merge( $this->options_bdd_default, $this->get_options_bdd_v3(), $options ) );
368
  $options = (array) Morphism::map( 'WeglotWP\Models\Schema_Option_V3', $options );
369
 
370
+ $destinations_languages = array_column( $options['destination_language'], 'language_to' );
371
+
372
  if ( Helper_Is_Admin::is_wp_admin() && $api_key_private ) {
373
+ $slugs = $this->get_slugs_from_api_with_api_key( $api_key_private, $destinations_languages );
374
  } else {
375
  if ( ! Helper_Is_Admin::is_wp_admin() && $api_key ) {
376
+ $slugs = $this->get_slugs_from_cache_with_api_key( $api_key_private, $destinations_languages );
377
  }
378
  }
379
  if ( isset( $slugs ) ) {
416
  * @return array
417
  */
418
  public function save_options_to_weglot( $options ) {
419
+
420
+ $response = wp_remote_post( // phpcs:ignore
421
  sprintf( '%s/projects/settings?api_key=%s', Helper_API::get_api_url(), $options['api_key_private'] ),
422
  array(
423
+ 'body' => wp_json_encode( $options ), //phpcs: ignore
424
  'headers' => array(
425
  'technology' => 'wordpress',
426
  'Content-Type' => 'application/json; charset=utf-8',
441
  }
442
 
443
  /**
 
444
  * @param string $key
445
  * @return string|null
446
+ * @throws Exception
447
+ * @since 3.0.0
448
  */
449
  public function get_option_custom_settings( $key ) {
450
  $options = $this->get_options();
461
  }
462
 
463
  /**
 
464
  * @param string $key
465
+ * @return array|string
466
+ * @throws Exception
467
+ * @since 2.0
468
  */
469
  public function get_option( $key ) {
470
  $options = $this->get_options();
477
  }
478
 
479
  /**
 
480
  * @param string $key
481
  * @return string|boolean|int
482
+ * @throws Exception
483
+ * @since 3.0.0
484
  */
485
  public function get_option_button( $key ) {
486
  $options = $this->get_options();
501
  }
502
 
503
  /**
 
504
  * @return array
505
+ * @throws Exception
506
+ * @since 2.0
507
  */
508
  public function get_exclude_blocks() {
509
  $exclude_blocks = $this->get_option( 'exclude_blocks' );
542
  }
543
 
544
  /**
 
 
545
  * @return array
546
+ * @throws Exception
547
+ * @version 3.0.0
548
+ * @since 3.2.1
549
  */
 
 
 
 
 
 
 
 
 
 
 
 
550
 
551
+ public function get_destination_languages() {
552
+ $destination_languages = $this->get_option( 'destination_language' );
553
+ return apply_filters( 'weglot_destination_languages_full', $destination_languages );
554
  }
555
 
 
556
  /**
 
557
  * @return array
558
+ * @throws Exception
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  * @since 2.0
 
560
  */
561
  public function get_exclude_urls() {
562
+ $list_exclude_urls = $this->get_option( 'exclude_urls' );
563
+ /** @var $request_url_services Request_Url_Service_Weglot */
564
+ $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
565
+ $exclude_urls = array();
566
+
567
  if ( ! empty( $list_exclude_urls ) ) {
568
  foreach ( $list_exclude_urls as $item ) {
569
  if ( is_array( $item ) ) {
570
+ $excluded_languages = null;
571
+ if ( ! empty( $item['excluded_languages'] ) && is_array( $item['excluded_languages'] ) ) {
572
+ foreach ( $item['excluded_languages'] as $excluded_language ) {
573
+ /** @var Language_Service_Weglot $language_service */
574
+ $language_service = weglot_get_service( 'Language_Service_Weglot' );
575
+ $excluded_languages[] = $language_service->get_language_from_internal( $excluded_language );
 
 
 
 
 
576
  }
577
  }
578
  $regex = new Regex( $item['type'], $request_url_services->url_to_relative( $item['value'] ) );
579
+ $exclude_urls[] = array( $regex->getRegex(), $excluded_languages );
 
 
580
  }
581
  }
582
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
 
584
+ $exclude_urls[] = array( '/wp-login.php', null );
585
+ $exclude_urls[] = array( '/sitemaps_xsl.xsl', null );
586
+ $exclude_urls[] = array( '/sitemaps.xml', null );
587
+ $exclude_urls[] = array( '/wp-cron.php', null );
588
+ $exclude_urls[] = array( '/wp-comments-post.php', null );
589
+ $exclude_urls[] = array( '/ct_template', null ); // Compatibility Oxygen
590
+ $exclude_urls[] = array( '/main-sitemap.xsl', null ); // SEO by Rank Math
591
 
592
+ if ( ! weglot_get_translate_amp_translation() ) {
593
+ $exclude_urls[] = array( weglot_get_service( 'Amp_Service_Weglot' )->get_regex(), null );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
594
  }
595
+ return apply_filters( 'weglot_exclude_urls', $exclude_urls );
 
 
 
 
 
 
 
 
596
  }
597
 
598
  /**
599
+ * @return string
600
+ * @throws Exception
601
  * @since 2.0
602
  *
 
603
  */
604
  public function get_css_custom_inline() {
605
  return apply_filters( 'weglot_css_custom_inline', $this->get_option( 'override_css' ) );
606
  }
607
 
608
  /**
609
+ * @return string
610
+ * @throws Exception
611
  * @since 2.0
612
  *
 
613
  */
614
  public function get_flag_css() {
615
  return apply_filters( 'weglot_flag_css', $this->get_option( 'flag_css' ) );
616
  }
617
 
618
  /**
 
619
  * @return int
620
+ * @throws Exception
621
+ * @since 3.0.0
622
  */
623
  public function get_translation_engine() {
624
  return apply_filters( 'weglot_get_translation_engine', $this->get_option( 'translation_engine' ) );
660
  }
661
  /**
662
  * @param string $key
663
+ * @return mixed
664
  */
665
  public function get_option_by_key_v3( $key ) {
666
  $options = $this->get_options_bdd_v3();
src/services/class-parser-service-weglot.php CHANGED
@@ -6,12 +6,10 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_API;
11
  use Weglot\Client\Client;
12
  use Weglot\Parser\Parser;
13
- use Weglot\Util\Url;
14
- use Weglot\Util\Server;
15
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
16
  use Weglot\Parser\ConfigProvider\ConfigProviderInterface;
17
 
@@ -22,25 +20,32 @@ use Weglot\Parser\ConfigProvider\ConfigProviderInterface;
22
  * @since 2.0
23
  */
24
  class Parser_Service_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  /**
27
  * @since 2.0
28
  */
29
  public function __construct() {
30
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
31
-
32
- if ( '2' === WEGLOT_LIB_PARSER ) {
33
- $this->dom_listeners_services = weglot_get_service( 'Dom_Listeners_Service_Weglot' );
34
- } else {
35
- $this->dom_checkers_services = weglot_get_service( 'Dom_Checkers_Service_Weglot' );
36
- }
37
  $this->regex_checkers_services = weglot_get_service( 'Regex_Checkers_Service_Weglot' );
38
- $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
39
  }
40
 
41
  /**
42
- * @since 3.0.0
43
  * @return Client
 
 
44
  */
45
  public function get_client() {
46
  $api_key = $this->option_services->get_api_key( true );
@@ -62,20 +67,13 @@ class Parser_Service_Weglot {
62
  }
63
 
64
  /**
 
 
65
  * @since 2.0
66
  * @version 2.2.2
67
- * @return array
68
  */
69
  public function get_parser() {
70
  $exclude_blocks = $this->option_services->get_exclude_blocks();
71
- if ( ! empty( $exclude_blocks ) ) {
72
- $exclude_blocks = array_map(
73
- function( $item ) {
74
- return $this->request_url_services->url_to_relative( $item );
75
- },
76
- $exclude_blocks
77
- );
78
- }
79
 
80
  $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
81
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
@@ -87,18 +85,11 @@ class Parser_Service_Weglot {
87
  }
88
 
89
  $client = $this->get_client();
90
-
91
- if ( '2' === WEGLOT_LIB_PARSER ) {
92
- $listeners = $this->dom_listeners_services->get_dom_listeners();
93
- $parser = new Parser( $client, $config, $exclude_blocks, $listeners );
94
- } else {
95
- $parser = new Parser( $client, $config, $exclude_blocks );
96
- $parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
97
- $parser->getRegexCheckerProvider()->addCheckers( $this->regex_checkers_services->get_regex_checkers() );
98
- $ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
99
-
100
- $parser->getIgnoredNodesFormatter()->setIgnoredNodes( $ignored_nodes );
101
- }
102
 
103
  return $parser;
104
  }
6
  exit;
7
  }
8
 
9
+ use Exception;
10
  use WeglotWP\Helpers\Helper_API;
11
  use Weglot\Client\Client;
12
  use Weglot\Parser\Parser;
 
 
13
  use Weglot\Parser\ConfigProvider\ServerConfigProvider;
14
  use Weglot\Parser\ConfigProvider\ConfigProviderInterface;
15
 
20
  * @since 2.0
21
  */
22
  class Parser_Service_Weglot {
23
+ /**
24
+ * @var Option_Service_Weglot
25
+ */
26
+ private $option_services;
27
+ /**
28
+ * @var Regex_Checkers_Service_Weglot
29
+ */
30
+ private $regex_checkers_services;
31
+ /**
32
+ * @var Dom_Checkers_Service_Weglot
33
+ */
34
+ private $dom_checkers_services;
35
 
36
  /**
37
  * @since 2.0
38
  */
39
  public function __construct() {
40
+ $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
41
+ $this->dom_checkers_services = weglot_get_service( 'Dom_Checkers_Service_Weglot' );
 
 
 
 
 
42
  $this->regex_checkers_services = weglot_get_service( 'Regex_Checkers_Service_Weglot' );
 
43
  }
44
 
45
  /**
 
46
  * @return Client
47
+ * @throws Exception
48
+ * @since 3.0.0
49
  */
50
  public function get_client() {
51
  $api_key = $this->option_services->get_api_key( true );
67
  }
68
 
69
  /**
70
+ * @return Parser
71
+ * @throws Exception
72
  * @since 2.0
73
  * @version 2.2.2
 
74
  */
75
  public function get_parser() {
76
  $exclude_blocks = $this->option_services->get_exclude_blocks();
 
 
 
 
 
 
 
 
77
 
78
  $config = apply_filters( 'weglot_parser_config_provider', new ServerConfigProvider() );
79
  if ( ! ( $config instanceof ConfigProviderInterface ) ) {
85
  }
86
 
87
  $client = $this->get_client();
88
+ $parser = new Parser( $client, $config, $exclude_blocks );
89
+ $parser->getDomCheckerProvider()->addCheckers( $this->dom_checkers_services->get_dom_checkers() );
90
+ $parser->getRegexCheckerProvider()->addCheckers( $this->regex_checkers_services->get_regex_checkers() );
91
+ $ignored_nodes = apply_filters( 'weglot_get_parser_ignored_nodes', $parser->getIgnoredNodesFormatter()->getIgnoredNodes() );
92
+ $parser->getIgnoredNodesFormatter()->setIgnoredNodes( $ignored_nodes );
 
 
 
 
 
 
 
93
 
94
  return $parser;
95
  }
src/services/class-private-language-service-weglot.php DELETED
@@ -1,98 +0,0 @@
1
- <?php
2
-
3
- namespace WeglotWP\Services;
4
-
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit;
7
- }
8
-
9
- use Weglot\Util\Url;
10
- use Weglot\Util\Server;
11
-
12
-
13
- /**
14
- * Private_Language_Service_Weglot
15
- *
16
- * @since 2.3.0
17
- */
18
- class Private_Language_Service_Weglot {
19
- protected $role_private_mode = 'administrator';
20
-
21
- /**
22
- * @since 2.3.0
23
- */
24
- public function __construct() {
25
- $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
26
- }
27
-
28
- /**
29
- * @since 2.3.0
30
- * @version 3.0.1
31
- * @param string $key_lang
32
- * @return boolean
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 ( ! is_array( $private_mode_languages ) ) {
38
- return false;
39
- }
40
-
41
- if ( ! array_key_exists( 'active', $private_mode_languages ) || ! $private_mode_languages['active'] ) {
42
- return false;
43
- }
44
-
45
- unset( $private_mode_languages['active'] );
46
- foreach ( $private_mode_languages as $lang => $lang_active ) {
47
- if ( $key_lang === $lang && $lang_active && ! $this->is_allowed_view_private() ) {
48
- return true;
49
- }
50
- }
51
-
52
- return false;
53
- }
54
-
55
- public function is_allowed_view_private() {
56
- return current_user_can( $this->role_private_mode ) || strpos( weglot_get_current_full_url(), 'weglot-private=1' ) !== false;
57
- }
58
-
59
- /**
60
- * @since 2.4.0
61
- * @return bool
62
- */
63
- public function private_mode_for_all_languages() {
64
- $private_mode_languages = $this->option_services->get_option( 'private_mode' );
65
- if ( $this->is_allowed_view_private() ) { // No check if admin
66
- return false;
67
- }
68
-
69
- if ( ! is_array( $private_mode_languages ) ) {
70
- return false;
71
- }
72
-
73
- if ( ! array_key_exists( 'active', $private_mode_languages ) ) {
74
- return false;
75
- }
76
-
77
- if ( ! $private_mode_languages['active'] ) {
78
- return false;
79
- }
80
-
81
- $original_language = weglot_get_original_language();
82
-
83
- unset( $private_mode_languages['active'] );
84
- if ( array_key_exists( $original_language, $private_mode_languages ) ) {
85
- unset( $private_mode_languages['original_language'] );
86
- }
87
-
88
- foreach ( $private_mode_languages as $lang => $lang_active ) {
89
- if ( ! $lang_active ) {
90
- return false;
91
- }
92
- }
93
-
94
- return true;
95
- }
96
- }
97
-
98
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/services/class-redirect-service-weglot.php CHANGED
@@ -6,28 +6,30 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Util\Url;
10
- use Weglot\Util\Server;
11
-
12
-
13
  /**
14
  * Redirect URL
15
  *
16
  * @since 2.0
17
  */
18
  class Redirect_Service_Weglot {
19
- /**
20
- * @since 2.0
21
- *
22
- * @var string
23
- */
24
- protected $weglot_url = null;
25
 
26
  /**
27
  *
28
  * @var boolean
29
  */
30
  protected $no_redirect = false;
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  /**
33
  * @since 2.0
@@ -35,7 +37,7 @@ class Redirect_Service_Weglot {
35
  public function __construct() {
36
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
37
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
38
- $this->private_services = weglot_get_service( 'Private_Language_Service_Weglot' );
39
  }
40
 
41
  /**
@@ -54,15 +56,15 @@ class Redirect_Service_Weglot {
54
  */
55
  protected function language_exception( $server_lang ) {
56
 
57
- if(in_array( $server_lang, ['zh-TW', 'zh-HK' ])) {
58
- $server_lang = "tw";
59
  }
60
 
61
- if(in_array( $server_lang, ['pt-BR'])) {
62
- $server_lang = "br";
63
  }
64
 
65
- $server_lang = substr($server_lang, 0, 2);
66
 
67
  if ( in_array( $server_lang, ['nb', 'nn', ] ) ) { //phpcs:ignore
68
  // Case Norwegian
@@ -83,7 +85,7 @@ class Redirect_Service_Weglot {
83
  }
84
 
85
  if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { //phpcs:ignore
86
- $server_lang = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, apply_filters( 'weglot_number_of_character_for_language', 5 ) );
87
  $server_lang = $this->language_exception( $server_lang );
88
  } else {
89
  if ( isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { // phpcs:ignore
@@ -92,25 +94,22 @@ class Redirect_Service_Weglot {
92
  }
93
  }
94
 
95
- $destination_languages = $this->option_services->get_destination_languages( true );
 
96
 
97
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
98
- $server_lang_modified = array_key_exists($server_lang, $language_code_rewrited) ? $language_code_rewrited[$server_lang] : $server_lang;
99
  if (
100
- in_array( $server_lang, $destination_languages ) && // phpcs:ignore
101
- weglot_get_original_language() === $this->request_url_services->get_current_language() &&
102
- ! $this->private_services->is_active_private_mode_for_lang( $server_lang )
103
  ) {
104
- $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $server_lang_modified ) );
105
  header( "Location: $url_auto_redirect", true, 302 );
106
  exit();
107
  }
108
 
109
  if (
110
- ! in_array( $server_lang, $destination_languages ) // phpcs:ignore
111
- && $server_lang !== weglot_get_original_language()
112
- && weglot_get_original_language() === $this->request_url_services->get_current_language()
113
- && ! $this->private_services->is_active_private_mode_for_lang( $server_lang )
114
  && $this->option_services->get_option( 'autoswitch_fallback' ) !== null
115
  ) {
116
  $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $this->option_services->get_option( 'autoswitch_fallback' ) ) );
@@ -130,13 +129,14 @@ class Redirect_Service_Weglot {
130
  }
131
 
132
  $this->no_redirect = true;
133
-
134
  if ( isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore
135
- $_SERVER['REQUEST_URI'] = str_replace(
136
- '?no_lredirect=true',
137
- '',
138
  $_SERVER['REQUEST_URI'] //phpcs:ignore
139
- );
 
 
140
  }
141
  }
142
  }
6
  exit;
7
  }
8
 
 
 
 
 
9
  /**
10
  * Redirect URL
11
  *
12
  * @since 2.0
13
  */
14
  class Redirect_Service_Weglot {
 
 
 
 
 
 
15
 
16
  /**
17
  *
18
  * @var boolean
19
  */
20
  protected $no_redirect = false;
21
+ /**
22
+ * @var Option_Service_Weglot
23
+ */
24
+ private $option_services;
25
+ /**
26
+ * @var Request_Url_Service_Weglot
27
+ */
28
+ private $request_url_services;
29
+ /**
30
+ * @var Language_Service_Weglot
31
+ */
32
+ private $language_services;
33
 
34
  /**
35
  * @since 2.0
37
  public function __construct() {
38
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
39
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
40
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
41
  }
42
 
43
  /**
56
  */
57
  protected function language_exception( $server_lang ) {
58
 
59
+ if ( in_array( $server_lang, [ 'zh-TW', 'zh-HK' ] ) ) {
60
+ $server_lang = 'tw';
61
  }
62
 
63
+ if ( in_array( $server_lang, [ 'pt-BR' ] ) ) {
64
+ $server_lang = 'br';
65
  }
66
 
67
+ $server_lang = substr( $server_lang, 0, 2 );
68
 
69
  if ( in_array( $server_lang, ['nb', 'nn', ] ) ) { //phpcs:ignore
70
  // Case Norwegian
85
  }
86
 
87
  if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { //phpcs:ignore
88
+ $server_lang = substr( sanitize_text_field( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ), 0, apply_filters( 'weglot_number_of_character_for_language', 5 ) );
89
  $server_lang = $this->language_exception( $server_lang );
90
  } else {
91
  if ( isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) { // phpcs:ignore
94
  }
95
  }
96
 
97
+ $destination_languages_external = $this->language_services->get_destination_languages_external( $this->request_url_services->is_allowed_private() );
98
+ $browser_language = $this->language_services->get_language_from_internal( $server_lang );
99
 
 
 
100
  if (
101
+ in_array( $browser_language->getExternalCode(), $destination_languages_external ) && // phpcs:ignore
102
+ $this->language_services->get_original_language() === $this->request_url_services->get_current_language()
 
103
  ) {
104
+ $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $browser_language ) );
105
  header( "Location: $url_auto_redirect", true, 302 );
106
  exit();
107
  }
108
 
109
  if (
110
+ ! in_array( $browser_language->getExternalCode(), $destination_languages_external ) // phpcs:ignore
111
+ && $browser_language !== $this->language_services->get_original_language()
112
+ && $this->language_services->get_original_language() === $this->request_url_services->get_current_language()
 
113
  && $this->option_services->get_option( 'autoswitch_fallback' ) !== null
114
  ) {
115
  $url_auto_redirect = apply_filters( 'weglot_url_auto_redirect', $this->request_url_services->get_weglot_url()->getForLanguage( $this->option_services->get_option( 'autoswitch_fallback' ) ) );
129
  }
130
 
131
  $this->no_redirect = true;
 
132
  if ( isset( $_SERVER['REQUEST_URI'] ) ) { // phpcs:ignore
133
+ $_SERVER['REQUEST_URI'] = str_replace('?no_lredirect=true' , '?' , str_replace(
134
+ '?no_lredirect=true&',
135
+ '?',
136
  $_SERVER['REQUEST_URI'] //phpcs:ignore
137
+ ));
138
+
139
+ $this->request_url_services->init_weglot_url(); //We reset the URL as we removed the parameter from URL
140
  }
141
  }
142
  }
src/services/class-regex-checkers-service-weglot.php CHANGED
@@ -52,12 +52,12 @@ class Regex_Checkers_Service_Weglot {
52
  if ( isset( $service ) ) {
53
  $active = $service->is_active();
54
  if ( $active ) {
55
- $regexDir = WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/';
56
- if ( is_dir( $regexDir ) ) {
57
- $regexFiles = array_diff( scandir( WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/' ), array( '..', '.' ) );
58
 
59
- foreach ( $regexFiles as $regexFile ) {
60
- $filename = Text::removeFileExtension( $regexFile );
61
  $filename = str_replace( 'class-', '', $filename );
62
  $filename = implode( '_', array_map( 'ucfirst', explode( '-', $filename ) ) );
63
  $class = '\\WeglotWP\\Third\\' . implode( '', array_map( 'ucfirst', explode( '-', $third ) ) ) . '\\Regexcheckers\\' . $filename;
52
  if ( isset( $service ) ) {
53
  $active = $service->is_active();
54
  if ( $active ) {
55
+ $regex_dir = WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/';
56
+ if ( is_dir( $regex_dir ) ) {
57
+ $regex_files = array_diff( scandir( WEGLOT_DIR . '/src/third/' . $third . '/regexcheckers/' ), array( '..', '.' ) );
58
 
59
+ foreach ( $regex_files as $regex_file ) {
60
+ $filename = Text::removeFileExtension( $regex_file );
61
  $filename = str_replace( 'class-', '', $filename );
62
  $filename = implode( '_', array_map( 'ucfirst', explode( '-', $filename ) ) );
63
  $class = '\\WeglotWP\\Third\\' . implode( '', array_map( 'ucfirst', explode( '-', $third ) ) ) . '\\Regexcheckers\\' . $filename;
src/services/class-replace-link-service-weglot.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace WeglotWP\Services;
4
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
@@ -12,86 +14,42 @@ if ( ! defined( 'ABSPATH' ) ) {
12
  */
13
  class Replace_Link_Service_Weglot {
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  * @since 2.0
17
  */
18
  public function __construct() {
19
- $this->multisite_service = weglot_get_service( 'Multisite_Service_Weglot' );
20
- $this->option_service = weglot_get_service( 'Option_Service_Weglot' );
 
 
21
  }
22
 
23
  /**
24
  * Replace an original URL into the current language
25
  * @since 2.0
26
  * @param string $url
 
27
  * @return string
28
  */
29
- public function replace_url( $url ) {
30
- $no_replace_condition = apply_filters( 'weglot_no_replace_url_condition', 'wp-content/uploads' );
31
-
32
- if ( strpos( $url, $no_replace_condition ) !== false ) {
33
- return $url;
34
- }
35
-
36
- $current_and_original = weglot_get_current_and_original_language();
37
- $custom_urls = $this->option_service->get_option( 'custom_urls' );
38
-
39
- $parsed_url = wp_parse_url( $url );
40
- $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
41
- $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
42
- $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
43
- $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
44
- $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
45
- $pass = ( $user || $pass ) ? "$pass@" : '';
46
- $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
47
- $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
48
- $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
49
- $current_language = $current_and_original['current'];
50
- $current_destination_languages = weglot_get_current_destination_languages( $url );
51
-
52
- if ( $current_and_original['current'] === $current_and_original['original'] ) {
53
- return $url;
54
- }
55
-
56
- if ( ! in_array( $current_language, $current_destination_languages, true ) ) {
57
-
58
- $default_language = apply_filters( 'weglot_replace_url_default_language', $current_and_original['original'] );
59
-
60
- if ( $default_language === $current_and_original['original'] ) {
61
- return $url;
62
- }
63
-
64
- if ( ! in_array( $default_language, $current_destination_languages, true ) ) {
65
- return $url;
66
- }
67
-
68
- $current_language = $default_language;
69
- }
70
-
71
- $to_translate_language_iso = $this->option_service->get_iso_code_from_custom_code( $current_language );
72
-
73
- if ( isset( $custom_urls[ $to_translate_language_iso ] ) ) {
74
- foreach ( $custom_urls[ $to_translate_language_iso ] as $key => $value ) {
75
- $path = str_replace( '/' . $value . '/', '/' . $key . '/', $path );
76
- }
77
- }
78
-
79
- $url_translated = ( strlen( $path ) > 2 && strpos( $path, "/$current_language/" ) !== false ) ?
80
- "$scheme$user$pass$host$port$path$query$fragment" : "$scheme$user$pass$host$port/$current_language$path$query$fragment";
81
-
82
-
83
- // We displace the multi-site path before the language code
84
- foreach ( array_reverse( $this->multisite_service->get_list_of_network_path() ) as $np ) {
85
- if ( strlen( $np ) > 2 && strpos( $url_translated, $np ) !== false ) {
86
- $url_translated = str_replace(
87
- str_replace( '//', '/', '/' . $current_language . $np . '/' ),
88
- str_replace( '//', '/', $np . '/' . $current_language . '/' ),
89
- $url_translated
90
- );
91
- }
92
- }
93
-
94
- return $url_translated;
95
  }
96
 
97
  /**
@@ -107,7 +65,7 @@ class Replace_Link_Service_Weglot {
107
  * @return string
108
  */
109
  public function replace_a( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
110
- $current_language = weglot_get_current_language();
111
  $no_replace_condition = apply_filters( 'weglot_no_replace_a_href', 'wp-content/uploads' );
112
 
113
  if ( strpos( $current_url, $no_replace_condition ) !== false ) {
@@ -132,7 +90,7 @@ class Replace_Link_Service_Weglot {
132
  * @return string
133
  */
134
  public function replace_datalink( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
135
- $current_language = weglot_get_current_language();
136
  $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-link=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-link=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
137
 
138
  return $translated_page;
@@ -151,7 +109,7 @@ class Replace_Link_Service_Weglot {
151
  * @return string
152
  */
153
  public function replace_dataurl( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
154
- $current_language = weglot_get_current_language();
155
  $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
156
 
157
  return $translated_page;
@@ -170,7 +128,7 @@ class Replace_Link_Service_Weglot {
170
  * @return string
171
  */
172
  public function replace_datacart( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
173
- $current_language = weglot_get_current_language();
174
  $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-cart-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-cart-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
175
 
176
  return $translated_page;
@@ -189,7 +147,7 @@ class Replace_Link_Service_Weglot {
189
  * @return string
190
  */
191
  public function replace_form( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
192
- $current_language = weglot_get_current_language();
193
  $translated_page = preg_replace( '/<form' . preg_quote( $sometags, '/' ) . 'action=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<form ' . $sometags . 'action=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
194
 
195
  return $translated_page;
@@ -208,7 +166,7 @@ class Replace_Link_Service_Weglot {
208
  * @return string
209
  */
210
  public function replace_canonical( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
211
- $current_language = weglot_get_current_language();
212
  $translated_page = preg_replace( '/<link rel="canonical"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="canonical"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
213
 
214
  return $translated_page;
@@ -227,7 +185,7 @@ class Replace_Link_Service_Weglot {
227
  * @return string
228
  */
229
  public function replace_amp( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
230
- $current_language = weglot_get_current_language();
231
  $translated_page = preg_replace( '/<link rel="amphtml"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="amphtml"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
232
 
233
  return $translated_page;
@@ -246,7 +204,7 @@ class Replace_Link_Service_Weglot {
246
  * @return string
247
  */
248
  public function replace_meta( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
249
- $current_language = weglot_get_current_language();
250
  $translated_page = preg_replace( '/<meta property="og:url"' . preg_quote( $sometags, '/' ) . 'content=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<meta property="og:url"' . $sometags . 'content=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
251
 
252
  return $translated_page;
2
 
3
  namespace WeglotWP\Services;
4
 
5
+ use Weglot\Client\Api\LanguageEntry;
6
+
7
  if ( ! defined( 'ABSPATH' ) ) {
8
  exit;
9
  }
14
  */
15
  class Replace_Link_Service_Weglot {
16
 
17
+ /**
18
+ * @var Multisite_Service_Weglot
19
+ */
20
+ private $multisite_service;
21
+ /**
22
+ * @var Option_Service_Weglot
23
+ */
24
+ private $option_service;
25
+ /**
26
+ * @var Language_Service_Weglot
27
+ */
28
+ private $language_services;
29
+ /**
30
+ * @var Request_Url_Service_Weglot
31
+ */
32
+ private $request_url_services;
33
+
34
  /**
35
  * @since 2.0
36
  */
37
  public function __construct() {
38
+ $this->multisite_service = weglot_get_service( 'Multisite_Service_Weglot' );
39
+ $this->option_service = weglot_get_service( 'Option_Service_Weglot' );
40
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
41
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
42
  }
43
 
44
  /**
45
  * Replace an original URL into the current language
46
  * @since 2.0
47
  * @param string $url
48
+ * @param LanguageEntry $language
49
  * @return string
50
  */
51
+ public function replace_url( $url, $language ) {
52
+ return $this->request_url_services->create_url_object( $url )->getForLanguage( $language );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
 
55
  /**
65
  * @return string
66
  */
67
  public function replace_a( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
68
+ $current_language = $this->request_url_services->get_current_language();
69
  $no_replace_condition = apply_filters( 'weglot_no_replace_a_href', 'wp-content/uploads' );
70
 
71
  if ( strpos( $current_url, $no_replace_condition ) !== false ) {
90
  * @return string
91
  */
92
  public function replace_datalink( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
93
+ $current_language = $this->request_url_services->get_current_language();
94
  $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-link=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-link=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
95
 
96
  return $translated_page;
109
  * @return string
110
  */
111
  public function replace_dataurl( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
112
+ $current_language = $this->request_url_services->get_current_language();
113
  $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
114
 
115
  return $translated_page;
128
  * @return string
129
  */
130
  public function replace_datacart( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
131
+ $current_language = $this->request_url_services->get_current_language();
132
  $translated_page = preg_replace( '/<' . preg_quote( $sometags, '/' ) . 'data-cart-url=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<' . $sometags . 'data-cart-url=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
133
 
134
  return $translated_page;
147
  * @return string
148
  */
149
  public function replace_form( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
150
+ $current_language = $this->request_url_services->get_current_language();
151
  $translated_page = preg_replace( '/<form' . preg_quote( $sometags, '/' ) . 'action=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<form ' . $sometags . 'action=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
152
 
153
  return $translated_page;
166
  * @return string
167
  */
168
  public function replace_canonical( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
169
+ $current_language = $this->request_url_services->get_current_language();
170
  $translated_page = preg_replace( '/<link rel="canonical"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="canonical"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
171
 
172
  return $translated_page;
185
  * @return string
186
  */
187
  public function replace_amp( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
188
+ $current_language = $this->request_url_services->get_current_language();
189
  $translated_page = preg_replace( '/<link rel="amphtml"' . preg_quote( $sometags, '/' ) . 'href=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<link rel="amphtml"' . $sometags . 'href=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
190
 
191
  return $translated_page;
204
  * @return string
205
  */
206
  public function replace_meta( $translated_page, $current_url, $quote1, $quote2, $sometags = null, $sometags2 = null ) {
207
+ $current_language = $this->request_url_services->get_current_language();
208
  $translated_page = preg_replace( '/<meta property="og:url"' . preg_quote( $sometags, '/' ) . 'content=' . preg_quote( $quote1 . $current_url . $quote2, '/' ) . '/', '<meta property="og:url"' . $sometags . 'content=' . $quote1 . $this->replace_url( $current_url, $current_language ) . $quote2, $translated_page );
209
 
210
  return $translated_page;
src/services/class-replace-url-service-weglot.php CHANGED
@@ -17,6 +17,14 @@ use WeglotWP\Helpers\Helper_Replace_Url_Weglot;
17
  * @since 2.0
18
  */
19
  class Replace_Url_Service_Weglot {
 
 
 
 
 
 
 
 
20
 
21
  /**
22
  * @since 2.0
@@ -39,16 +47,15 @@ class Replace_Url_Service_Weglot {
39
  $dom = $this->modify_link( $value, $dom, $key );
40
  }
41
 
42
- $current_language = weglot_get_current_language();
43
- $language_code_rewrited = array_search( $current_language, apply_filters( 'weglot_language_code_replace', array() ) );
44
 
45
- if ( ! empty( $language_code_rewrited ) ) {
46
- $dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language . '$4 weglot-lang=$2' . $language_code_rewrited . '$4', $dom );
47
  } else {
48
- $dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language . '$4', $dom );
49
  }
50
 
51
- $dom = preg_replace( '/property="og:locale" content=(\"|\')(\S*)(\"|\')/', 'property="og:locale" content=$1' . $current_language . '$3', $dom );
52
 
53
  return apply_filters( 'weglot_replace_link', $dom );
54
  }
@@ -60,11 +67,11 @@ class Replace_Url_Service_Weglot {
60
  if ( is_array( $val ) ) {
61
  $json[ $key ] = $this->replace_link_in_json( $val );
62
  } else {
63
- if ( Parser::getSourceType( $val ) == SourceType::SOURCE_HTML ) {
64
  $json[ $key ] = $this->replace_link_in_dom( $val );
65
  } else {
66
  if ( in_array( $key, $replace_urls, true ) && $this->check_link( $val ) ) {
67
- $json[ $key ] = $this->replace_link_service->replace_url( $val );
68
  }
69
  }
70
  }
@@ -82,15 +89,14 @@ class Replace_Url_Service_Weglot {
82
  * @return string
83
  */
84
  public function modify_link( $pattern, $translated_page, $type ) {
85
- $current_language = weglot_get_current_language();
86
  preg_match_all( $pattern, $translated_page, $out, PREG_PATTERN_ORDER );
87
  $count_out_0 = count( $out[0] );
88
  for ( $i = 0;$i < $count_out_0; $i++ ) {
89
- $sometags = ( isset( $out[1] ) ) ? $out[1][ $i ] : null;
90
- $quote1 = ( isset( $out[2] ) ) ? $out[2][ $i ] : null;
91
  $current_url = ( isset( $out[3] ) ) ? $out[3][ $i ] : null;
92
- $quote2 = ( isset( $out[4] ) ) ? $out[4][ $i ] : null;
93
- $sometags2 = ( isset( $out[5] ) ) ? $out[5][ $i ] : null;
94
 
95
  $length_link = apply_filters( 'weglot_length_replace_a', 1500 ); // Prevent error on long URL (preg_match_all Compilation failed: regular expression is too large at offset)
96
  if ( strlen( $current_url ) >= $length_link ) {
@@ -130,8 +136,8 @@ class Replace_Url_Service_Weglot {
130
  * @return string
131
  */
132
  public function check_link( $current_url, $sometags = null, $sometags2 = null ) {
133
- $admin_url = admin_url();
134
- $parsed_url = wp_parse_url( $current_url );
135
  $server_host = apply_filters( 'weglot_check_link_server_host', $_SERVER['HTTP_HOST'] ); //phpcs:ignore
136
 
137
  return (
@@ -189,7 +195,7 @@ class Replace_Url_Service_Weglot {
189
  * @return boolean
190
  */
191
  public function ends_with( $haystack, $needle ) {
192
- $temp = strlen( $haystack );
193
  $len_needle = strlen( $needle );
194
 
195
  return '' === $needle ||
17
  * @since 2.0
18
  */
19
  class Replace_Url_Service_Weglot {
20
+ /**
21
+ * @var Request_Url_Service_Weglot
22
+ */
23
+ private $request_url_services;
24
+ /**
25
+ * @var Replace_Link_Service_Weglot
26
+ */
27
+ private $replace_link_service;
28
 
29
  /**
30
  * @since 2.0
47
  $dom = $this->modify_link( $value, $dom, $key );
48
  }
49
 
50
+ $current_language = $this->request_url_services->get_current_language();
 
51
 
52
+ if ( $current_language->getExternalCode() !== $current_language->getInternalCode() ) {
53
+ $dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language->getExternalCode() . '$4 weglot-lang=$2' . $current_language->getInternalCode() . '$4', $dom );
54
  } else {
55
+ $dom = preg_replace( '/<html (.*?)?lang=(\"|\')(\S*)(\"|\')/', '<html $1lang=$2' . $current_language->getExternalCode() . '$4', $dom );
56
  }
57
 
58
+ $dom = preg_replace( '/property="og:locale" content=(\"|\')(\S*)(\"|\')/', 'property="og:locale" content=$1' . $current_language->getExternalCode() . '$3', $dom );
59
 
60
  return apply_filters( 'weglot_replace_link', $dom );
61
  }
67
  if ( is_array( $val ) ) {
68
  $json[ $key ] = $this->replace_link_in_json( $val );
69
  } else {
70
+ if ( Parser::getSourceType( $val ) === SourceType::SOURCE_HTML ) {
71
  $json[ $key ] = $this->replace_link_in_dom( $val );
72
  } else {
73
  if ( in_array( $key, $replace_urls, true ) && $this->check_link( $val ) ) {
74
+ $json[ $key ] = $this->replace_link_service->replace_url( $val , $this->request_url_services->get_current_language());
75
  }
76
  }
77
  }
89
  * @return string
90
  */
91
  public function modify_link( $pattern, $translated_page, $type ) {
 
92
  preg_match_all( $pattern, $translated_page, $out, PREG_PATTERN_ORDER );
93
  $count_out_0 = count( $out[0] );
94
  for ( $i = 0;$i < $count_out_0; $i++ ) {
95
+ $sometags = ( isset( $out[1] ) ) ? $out[1][ $i ] : null;
96
+ $quote1 = ( isset( $out[2] ) ) ? $out[2][ $i ] : null;
97
  $current_url = ( isset( $out[3] ) ) ? $out[3][ $i ] : null;
98
+ $quote2 = ( isset( $out[4] ) ) ? $out[4][ $i ] : null;
99
+ $sometags2 = ( isset( $out[5] ) ) ? $out[5][ $i ] : null;
100
 
101
  $length_link = apply_filters( 'weglot_length_replace_a', 1500 ); // Prevent error on long URL (preg_match_all Compilation failed: regular expression is too large at offset)
102
  if ( strlen( $current_url ) >= $length_link ) {
136
  * @return string
137
  */
138
  public function check_link( $current_url, $sometags = null, $sometags2 = null ) {
139
+ $admin_url = admin_url();
140
+ $parsed_url = wp_parse_url( $current_url );
141
  $server_host = apply_filters( 'weglot_check_link_server_host', $_SERVER['HTTP_HOST'] ); //phpcs:ignore
142
 
143
  return (
195
  * @return boolean
196
  */
197
  public function ends_with( $haystack, $needle ) {
198
+ $temp = strlen( $haystack );
199
  $len_needle = strlen( $needle );
200
 
201
  return '' === $needle ||
src/services/class-request-url-service-weglot.php CHANGED
@@ -6,8 +6,10 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\Url;
10
  use Weglot\Util\Server;
 
11
 
12
 
13
  /**
@@ -19,10 +21,24 @@ class Request_Url_Service_Weglot {
19
  /**
20
  * @since 2.0
21
  *
22
- * @var string
23
  */
24
  protected $weglot_url = null;
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  /**
27
  * @since 2.0
28
  */
@@ -39,48 +55,34 @@ class Request_Url_Service_Weglot {
39
  * @return Url
40
  */
41
  public function create_url_object( $url ) {
 
42
  return new Url(
43
  $url,
44
- $this->option_services->get_option( 'original_language' ),
45
- weglot_get_destination_languages(),
46
- $this->get_home_wordpress_directory()
 
 
47
  );
48
  }
49
 
50
  /**
 
51
  * @since 2.0
52
  *
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
-
71
- $this->weglot_url->setExcludedUrls( $exclude_urls_option );
72
-
73
  return $this;
74
  }
75
 
76
  /**
77
  * Get request URL in process
78
  * @since 2.0
79
- * @param boolean $cache
80
- * @return \Weglot\Util\Url
81
  */
82
- public function get_weglot_url( $cache = true ) {
83
- if ( null === $this->weglot_url || ! $cache ) {
84
  $this->init_weglot_url();
85
  }
86
 
@@ -105,56 +107,27 @@ class Request_Url_Service_Weglot {
105
 
106
  /**
107
  * Abstraction of \Weglot\Util\Url
 
 
108
  * @since 2.0
109
- * @version 2.4.0
110
- * @param boolean $with_filter
111
- * @return string
112
  */
113
- public function get_current_language( $with_filter = true ) {
114
- $current_language = $this->get_weglot_url()->detectCurrentLanguage();
115
 
116
  if ( ( wp_doing_ajax() || $this->is_rest() ) && isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
117
- $current_language = $this->create_url_object( $_SERVER['HTTP_REFERER'] )->detectCurrentLanguage(); //phpcs:ignore
118
  } else {
119
  if ( strpos( $this->get_full_url(), 'wp-comments-post.php' ) !== false ) {
120
- $current_language = $this->create_url_object( $_SERVER['HTTP_REFERER'] )->detectCurrentLanguage(); //phpcs:ignore
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
  }
131
-
132
  return $current_language;
133
  }
134
 
135
- /**
136
- * @since 2.4.0
137
- * @return LanguageEntry
138
- */
139
- public function get_current_language_entry() {
140
- return $this->language_services->get_current_language_entry_from_key( $this->get_current_language() );
141
- }
142
-
143
- /**
144
- * Abstraction of \Weglot\Util\Url
145
- * @since 2.0
146
- *
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
-
158
 
159
  /**
160
  * @since 2.0
@@ -166,32 +139,6 @@ class Request_Url_Service_Weglot {
166
  return Server::fullUrl($_SERVER, $use_forwarded_host); //phpcs:ignore
167
  }
168
 
169
- /**
170
- * @since 2.0.4
171
- *
172
- * @return string
173
- * @param mixed $use_forwarded_host
174
- */
175
- public function get_full_url_no_language( $use_forwarded_host = false ) {
176
- return $this->create_url_object( $this->get_full_url() )->getForLanguage( weglot_get_original_language() );
177
- }
178
-
179
-
180
- /**
181
- * @todo : Change this when weglot-php included
182
- *
183
- * @param string $code
184
- * @return boolean
185
- */
186
- public function is_language_rtl( $code ) {
187
- $rtls = array( 'ar', 'he', 'fa' );
188
- if ( in_array( $code, $rtls, true ) ) {
189
- return true;
190
- }
191
-
192
- return false;
193
- }
194
-
195
  /**
196
  * @since 2.0
197
  *
@@ -216,66 +163,31 @@ class Request_Url_Service_Weglot {
216
 
217
 
218
  /**
219
- * Is eligible URL
220
  * @since 2.0
221
  * @param string $url
222
  * @return boolean
223
  */
224
- public function is_eligible_url( $url ) {
225
- $destinations = weglot_get_current_destination_languages();
226
- if ( empty( $destinations ) ) {
227
- return true;
228
- }
229
-
230
- $url_relative = urldecode( $this->url_to_relative( $url ) );
231
- $exclude_urls_option = $this->option_services->get_exclude_urls();
232
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
233
- $current_language = $this->get_current_language();
234
- $url_path_custom = null;
235
-
236
- if ( isset( $custom_urls[ $current_language ] ) ) {
237
- foreach ( $custom_urls[ $current_language ] as $key => $value ) {
238
- $url_path_custom = str_replace( '/' . $key . '/', '/' . $value . '/', $url_relative );
239
- }
240
- }
241
 
242
- $weglot_url = $this->create_url_object( $url );
243
- $weglot_url->setExcludedUrls( $exclude_urls_option );
244
-
245
- if ( ! $weglot_url->isTranslable() ) {
246
- return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
247
  }
248
 
249
- if ( ! in_array( $current_language, array_merge( $destinations, array( weglot_get_original_language() ) ), true ) ) {
250
  return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
251
  }
252
-
253
- if ( $url_path_custom ) {
254
- $weglot_url = $this->create_url_object( $url_path_custom );
255
- $weglot_url->setExcludedUrls( $exclude_urls_option );
256
- if ( ! $weglot_url->isTranslable() ) {
257
- return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
258
- }
259
- }
260
-
261
  return apply_filters( 'weglot_is_eligible_url', true, $url );
262
  }
263
 
264
- /**
265
- * @since 2.0
266
- *
267
- * @param string $str
268
- * @return string
269
- */
270
- public function escape_slash( $str ) {
271
- return str_replace( '/', '\/', $str );
272
- }
273
-
274
  /**
275
  * @since 2.0
276
  * @param string $url
277
  * @return string
278
  */
 
279
  public function url_to_relative( $url ) {
280
  if ( ( substr( $url, 0, 7 ) === 'http://' ) || ( substr( $url, 0, 8 ) === 'https://' ) ) {
281
  // the current link is an "absolute" URL - parse it to get just the path
@@ -294,6 +206,16 @@ class Request_Url_Service_Weglot {
294
  }
295
  return $url;
296
  }
 
 
 
 
 
 
 
 
 
 
297
  }
298
 
299
 
6
  exit;
7
  }
8
 
9
+ use Weglot\Client\Api\LanguageEntry;
10
  use Weglot\Util\Url;
11
  use Weglot\Util\Server;
12
+ use WeglotWP\Third\Amp\Amp_Service_Weglot;
13
 
14
 
15
  /**
21
  /**
22
  * @since 2.0
23
  *
24
+ * @var Url
25
  */
26
  protected $weglot_url = null;
27
 
28
+ /**
29
+ * @var Language_Service_Weglot
30
+ */
31
+ private $language_services;
32
+
33
+ /**
34
+ * @var Option_Service_Weglot
35
+ */
36
+ private $option_services;
37
+ /**
38
+ * @var Amp_Service_Weglot
39
+ */
40
+ private $amp_services;
41
+
42
  /**
43
  * @since 2.0
44
  */
55
  * @return Url
56
  */
57
  public function create_url_object( $url ) {
58
+
59
  return new Url(
60
  $url,
61
+ $this->language_services->get_original_language(),
62
+ $this->language_services->get_destination_languages( $this->is_allowed_private() ),
63
+ $this->get_home_wordpress_directory(),
64
+ $this->option_services->get_exclude_urls(),
65
+ $this->option_services->get_option( 'custom_urls' )
66
  );
67
  }
68
 
69
  /**
70
+ * @return Request_Url_Service_Weglot
71
  * @since 2.0
72
  *
 
73
  */
74
  public function init_weglot_url() {
75
+ $this->weglot_url = $this->create_url_object( $this->get_full_url() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  return $this;
77
  }
78
 
79
  /**
80
  * Get request URL in process
81
  * @since 2.0
82
+ * @return Url
 
83
  */
84
+ public function get_weglot_url() {
85
+ if ( null === $this->weglot_url ) {
86
  $this->init_weglot_url();
87
  }
88
 
107
 
108
  /**
109
  * Abstraction of \Weglot\Util\Url
110
+ * @return LanguageEntry
111
+ * @version 3.2.0
112
  * @since 2.0
 
 
 
113
  */
114
+ public function get_current_language() {
115
+ $current_language = $this->get_weglot_url()->getCurrentLanguage();
116
 
117
  if ( ( wp_doing_ajax() || $this->is_rest() ) && isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
118
+ $current_language = $this->create_url_object( $_SERVER['HTTP_REFERER'] )->getCurrentLanguage(); //phpcs:ignore
119
  } else {
120
  if ( strpos( $this->get_full_url(), 'wp-comments-post.php' ) !== false ) {
121
+ $current_language = $this->create_url_object( $_SERVER['HTTP_REFERER'] )->getCurrentLanguage(); //phpcs:ignore
122
  }
123
  }
124
 
125
  if ( empty( $current_language ) ) {
126
+ return apply_filters( 'weglot_default_current_language_empty', $this->language_services->get_original_language() );
 
 
 
 
127
  }
 
128
  return $current_language;
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  /**
133
  * @since 2.0
139
  return Server::fullUrl($_SERVER, $use_forwarded_host); //phpcs:ignore
140
  }
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  /**
143
  * @since 2.0
144
  *
163
 
164
 
165
  /**
166
+ * Returns true if the URL is translated in at least one language
167
  * @since 2.0
168
  * @param string $url
169
  * @return boolean
170
  */
171
+ public function is_eligible_url( $url = null ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
+ if ( ! $url ) {
174
+ $weglot_url = $this->get_weglot_url();
175
+ } else {
176
+ $weglot_url = $this->create_url_object( $url );
 
177
  }
178
 
179
+ if ( empty( $weglot_url->availableInLanguages() ) && $this->get_current_language() === $this->language_services->get_original_language() ) {
180
  return apply_filters( 'weglot_is_eligible_url', false, $weglot_url );
181
  }
 
 
 
 
 
 
 
 
 
182
  return apply_filters( 'weglot_is_eligible_url', true, $url );
183
  }
184
 
 
 
 
 
 
 
 
 
 
 
185
  /**
186
  * @since 2.0
187
  * @param string $url
188
  * @return string
189
  */
190
+
191
  public function url_to_relative( $url ) {
192
  if ( ( substr( $url, 0, 7 ) === 'http://' ) || ( substr( $url, 0, 8 ) === 'https://' ) ) {
193
  // the current link is an "absolute" URL - parse it to get just the path
206
  }
207
  return $url;
208
  }
209
+
210
+ public function is_allowed_private() {
211
+ if ( current_user_can( 'administrator' )
212
+ || strpos( $this->get_full_url(), 'weglot-private=1' ) !== false
213
+ || isset($_COOKIE['weglot_allow_private'])
214
+ ) {
215
+ return true;
216
+ }
217
+ return false;
218
+ }
219
  }
220
 
221
 
src/services/class-translate-service-weglot.php CHANGED
@@ -7,6 +7,7 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  }
8
 
9
  use Weglot\Client\Api\Exception\ApiError;
 
10
  use WeglotWP\Helpers\Helper_Json_Inline_Weglot;
11
  use WeglotWP\Helpers\Helper_Keys_Json_Weglot;
12
 
@@ -15,6 +16,38 @@ use WeglotWP\Helpers\Helper_Keys_Json_Weglot;
15
  * @since 2.3.0
16
  */
17
  class Translate_Service_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  /**
@@ -24,9 +57,9 @@ class Translate_Service_Weglot {
24
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
25
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
26
  $this->replace_url_services = weglot_get_service( 'Replace_Url_Service_Weglot' );
27
- $this->replace_link_services = weglot_get_service( 'Replace_Link_Service_Weglot' );
28
  $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
29
  $this->generate_switcher_service = weglot_get_service( 'Generate_Switcher_Service_Weglot' );
 
30
  }
31
 
32
 
@@ -35,37 +68,38 @@ class Translate_Service_Weglot {
35
  * @return void
36
  */
37
  public function weglot_translate() {
38
- $this->set_original_language( weglot_get_original_language() );
39
- $this->set_current_language( $this->request_url_services->get_current_language() );
40
-
41
  ob_start( array( $this, 'weglot_treat_page' ) );
42
  }
43
 
44
  /**
 
 
45
  * @since 2.3.0
46
- * @param string $current_language
47
  */
48
  public function set_current_language( $current_language ) {
49
- $this->current_language = $current_language;
50
  return $this;
51
  }
52
 
53
  /**
 
 
54
  * @since 2.3.0
55
- * @param string $original_language
56
  */
57
  public function set_original_language( $original_language ) {
58
- $this->original_language = $original_language;
59
  return $this;
60
  }
61
 
62
  /**
63
- * @see weglot_init / ob_start
64
- * @since 2.3.0
65
  * @param string $content
66
  * @return string
 
 
 
67
  */
68
  public function weglot_treat_page( $content ) {
 
69
  $this->set_current_language( $this->request_url_services->get_current_language() ); // Need to reset
70
 
71
  // Choose type translate
@@ -82,17 +116,15 @@ class Translate_Service_Weglot {
82
  $parser = $this->parser_services->get_parser();
83
 
84
  try {
85
- $to_translate_language_iso = $this->option_services->get_iso_code_from_custom_code( $this->current_language );
86
-
87
  switch ( $type ) {
88
  case 'json':
89
  $extraKeys = apply_filters( 'weglot_add_json_keys', array() );
90
- $translated_content = $parser->translate( $content, $this->original_language, $to_translate_language_iso, $extraKeys );
91
- $translated_content = json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
92
  $translated_content = apply_filters( 'weglot_json_treat_page', $translated_content );
93
  return $translated_content;
94
  case 'html':
95
- $translated_content = $parser->translate( $content, $this->original_language, $to_translate_language_iso ); // phpcs:ignore
96
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
97
  return $this->weglot_render_dom( $translated_content );
98
  default:
7
  }
8
 
9
  use Weglot\Client\Api\Exception\ApiError;
10
+ use Weglot\Client\Api\LanguageEntry;
11
  use WeglotWP\Helpers\Helper_Json_Inline_Weglot;
12
  use WeglotWP\Helpers\Helper_Keys_Json_Weglot;
13
 
16
  * @since 2.3.0
17
  */
18
  class Translate_Service_Weglot {
19
+ /**
20
+ * @var Parser_Service_Weglot
21
+ */
22
+ private $parser_services;
23
+ /**
24
+ * @var string
25
+ */
26
+ private $current_language;
27
+ /**
28
+ * @var string
29
+ */
30
+ private $original_language;
31
+ /**
32
+ * @var Request_Url_Service_Weglot
33
+ */
34
+ private $request_url_services;
35
+ /**
36
+ * @var Language_Service_Weglot
37
+ */
38
+ private $language_services;
39
+ /**
40
+ * @var Replace_Url_Service_Weglot
41
+ */
42
+ private $replace_url_services;
43
+ /**
44
+ * @var Option_Service_Weglot
45
+ */
46
+ private $option_services;
47
+ /**
48
+ * @var Generate_Switcher_Service_Weglot
49
+ */
50
+ private $generate_switcher_service;
51
 
52
 
53
  /**
57
  $this->option_services = weglot_get_service( 'Option_Service_Weglot' );
58
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
59
  $this->replace_url_services = weglot_get_service( 'Replace_Url_Service_Weglot' );
 
60
  $this->parser_services = weglot_get_service( 'Parser_Service_Weglot' );
61
  $this->generate_switcher_service = weglot_get_service( 'Generate_Switcher_Service_Weglot' );
62
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
63
  }
64
 
65
 
68
  * @return void
69
  */
70
  public function weglot_translate() {
 
 
 
71
  ob_start( array( $this, 'weglot_treat_page' ) );
72
  }
73
 
74
  /**
75
+ * @param LanguageEntry $current_language
76
+ * @return Translate_Service_Weglot
77
  * @since 2.3.0
 
78
  */
79
  public function set_current_language( $current_language ) {
80
+ $this->current_language = $current_language->getInternalCode();
81
  return $this;
82
  }
83
 
84
  /**
85
+ * @param LanguageEntry $original_language
86
+ * @return Translate_Service_Weglot
87
  * @since 2.3.0
 
88
  */
89
  public function set_original_language( $original_language ) {
90
+ $this->original_language = $original_language->getInternalCode();
91
  return $this;
92
  }
93
 
94
  /**
 
 
95
  * @param string $content
96
  * @return string
97
+ * @throws \Exception
98
+ * @since 2.3.0
99
+ * @see weglot_init / ob_start
100
  */
101
  public function weglot_treat_page( $content ) {
102
+ $this->set_original_language( $this->language_services->get_original_language() );
103
  $this->set_current_language( $this->request_url_services->get_current_language() ); // Need to reset
104
 
105
  // Choose type translate
116
  $parser = $this->parser_services->get_parser();
117
 
118
  try {
 
 
119
  switch ( $type ) {
120
  case 'json':
121
  $extraKeys = apply_filters( 'weglot_add_json_keys', array() );
122
+ $translated_content = $parser->translate( $content, $this->original_language, $this->current_language, $extraKeys );
123
+ $translated_content = wp_json_encode( $this->replace_url_services->replace_link_in_json( json_decode( $translated_content, true ) ) );
124
  $translated_content = apply_filters( 'weglot_json_treat_page', $translated_content );
125
  return $translated_content;
126
  case 'html':
127
+ $translated_content = $parser->translate( $content, $this->original_language, $this->current_language ); // phpcs:ignore
128
  $translated_content = apply_filters( 'weglot_html_treat_page', $translated_content );
129
  return $this->weglot_render_dom( $translated_content );
130
  default:
src/services/class-user-api-service-weglot.php CHANGED
@@ -78,34 +78,12 @@ class User_Api_Service_Weglot {
78
  }
79
  }
80
 
81
- /**
82
- * @since 2.0.6
83
- *
84
- * @return int
85
- */
86
- public function get_limit_destination_language() {
87
- $user_info = $this->get_user_info();
88
- $plans = $this->get_plans();
89
- $limit = 1000;
90
- if (
91
- $user_info['plan_id'] <= 1 ||
92
- in_array( $user_info['plan_id'], $plans['starter_free']['ids'] ) // phpcs:ignore
93
- ) {
94
- $limit = $plans['starter_free']['limit_language'];
95
- } elseif (
96
- in_array( $user_info['plan_id'], $plans['business']['ids'] ) // phpcs:ignore
97
- ) {
98
- $limit = $plans['business']['limit_language'];
99
- }
100
-
101
- return $limit;
102
- }
103
-
104
  /**
105
  *
106
  * @param string $url
107
  * @param array $parameters
108
  * @return array
 
109
  */
110
  public function do_request( $url, $parameters ) {
111
  if ( $parameters ) {
@@ -115,7 +93,7 @@ class User_Api_Service_Weglot {
115
  $url,
116
  array(
117
  'method' => 'POST',
118
- 'timeout' => 45,
119
  'redirection' => 5,
120
  'blocking' => true,
121
  'headers' => array(
@@ -134,7 +112,7 @@ class User_Api_Service_Weglot {
134
  $url,
135
  array(
136
  'method' => 'GET',
137
- 'timeout' => 45,
138
  'redirection' => 5,
139
  'blocking' => true,
140
  'headers' => array(
78
  }
79
  }
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  *
83
  * @param string $url
84
  * @param array $parameters
85
  * @return array
86
+ * @throws \Exception
87
  */
88
  public function do_request( $url, $parameters ) {
89
  if ( $parameters ) {
93
  $url,
94
  array(
95
  'method' => 'POST',
96
+ 'timeout' => 3,
97
  'redirection' => 5,
98
  'blocking' => true,
99
  'headers' => array(
112
  $url,
113
  array(
114
  'method' => 'GET',
115
+ 'timeout' => 3,
116
  'redirection' => 5,
117
  'blocking' => true,
118
  'headers' => array(
src/third/amp/class-amp-enqueue-weglot.php CHANGED
@@ -6,8 +6,13 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use WeglotWP\Models\Hooks_Interface_Weglot;
10
  use WeglotWP\Helpers\Helper_Flag_Type;
 
 
 
 
11
 
12
 
13
  /**
@@ -16,6 +21,10 @@ use WeglotWP\Helpers\Helper_Flag_Type;
16
  * @since 2.0
17
  */
18
  class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
19
 
20
  /**
21
  * @since 2.0
@@ -25,10 +34,11 @@ class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
25
  }
26
 
27
  /**
 
 
28
  * @since 2.0
29
  * @see Hooks_Interface_Weglot
30
  *
31
- * @return void
32
  */
33
  public function hooks() {
34
  if ( ! defined( 'AMPFORWP_PLUGIN_DIR' ) && ! defined( 'AMP__VERSION' ) ) {
@@ -46,21 +56,29 @@ class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
46
 
47
 
48
  /**
49
- * @since 3.1.7
50
- *
51
  * @return string
 
 
52
  */
53
  public function weglot_amp_css( $html ) {
54
 
55
- $button_service = weglot_get_service( 'Button_Service_Weglot' );
56
- $weglot_url = $button_service->request_url_services->get_weglot_url();
57
- $amp_regex = $button_service->amp_services->get_regex( true );
58
 
59
- if ( ! weglot_get_translate_amp_translation() || ! preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
 
 
 
 
60
  return $html;
61
  }
62
 
63
- $languages_configured = weglot_get_all_languages_configured();
 
 
 
64
  $flags_positions = $this->weglot_get_flags_positions();
65
  $type_flags = weglot_get_option( 'type_flags' );
66
  $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
@@ -82,7 +100,7 @@ class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
82
  if ( $with_flags ) {
83
  foreach ( $languages_configured as $lang ) {
84
 
85
- $lang = $this->option_services->get_iso_code_from_custom_code( $lang );
86
  if ( ! empty( $flags_positions[ $type_flags ][ $lang ] ) ) {
87
  $css .= '.weglot-flags.flag-' . $type_flags . '.' . $lang . ' > a:before, .weglot-flags.flag-' . $type_flags . '.' . $lang . ' > span:before { background-position: ' . $flags_positions[ $type_flags ][ $lang ] . 'px 0; }';
88
  }
6
  exit;
7
  }
8
 
9
+ use Exception;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
  use WeglotWP\Helpers\Helper_Flag_Type;
12
+ use WeglotWP\Services\Button_Service_Weglot;
13
+ use WeglotWP\Services\Language_Service_Weglot;
14
+ use WeglotWP\Services\Option_Service_Weglot;
15
+ use WeglotWP\Services\Request_Url_Service_Weglot;
16
 
17
 
18
  /**
21
  * @since 2.0
22
  */
23
  class Amp_Enqueue_Weglot implements Hooks_Interface_Weglot {
24
+ /**
25
+ * @var Option_Service_Weglot
26
+ */
27
+ private $option_services;
28
 
29
  /**
30
  * @since 2.0
34
  }
35
 
36
  /**
37
+ * @return void
38
+ * @throws Exception
39
  * @since 2.0
40
  * @see Hooks_Interface_Weglot
41
  *
 
42
  */
43
  public function hooks() {
44
  if ( ! defined( 'AMPFORWP_PLUGIN_DIR' ) && ! defined( 'AMP__VERSION' ) ) {
56
 
57
 
58
  /**
59
+ * @param $html
 
60
  * @return string
61
+ * @throws Exception
62
+ * @since 3.1.7
63
  */
64
  public function weglot_amp_css( $html ) {
65
 
66
+ /** @var Request_Url_Service_Weglot $request_url_service */
67
+ $request_url_service = weglot_get_service( 'Request_Url_Service_Weglot' );
68
+ $weglot_url = $request_url_service->get_weglot_url();
69
 
70
+ /** @var Amp_Service_Weglot $amp_service */
71
+ $amp_service = weglot_get_service( 'Amp_Service_Weglot' );
72
+ $amp_regex = $amp_service->get_regex( true );
73
+
74
+ if ( ! $this->option_services->get_option_custom_settings( 'translate_amp' ) || ! preg_match( '#' . $amp_regex . '#', $weglot_url->getUrl() ) === 1 ) {
75
  return $html;
76
  }
77
 
78
+ /** @var Language_Service_Weglot $language_service */
79
+ $language_service = weglot_get_service( 'Language_Service_Weglot' );
80
+
81
+ $languages_configured = $language_service->get_original_and_destination_languages( $request_url_service->is_allowed_private() );
82
  $flags_positions = $this->weglot_get_flags_positions();
83
  $type_flags = weglot_get_option( 'type_flags' );
84
  $type_flags = Helper_Flag_Type::get_flag_number_with_type( $type_flags );
100
  if ( $with_flags ) {
101
  foreach ( $languages_configured as $lang ) {
102
 
103
+ $lang = $lang->getInternalCode();
104
  if ( ! empty( $flags_positions[ $type_flags ][ $lang ] ) ) {
105
  $css .= '.weglot-flags.flag-' . $type_flags . '.' . $lang . ' > a:before, .weglot-flags.flag-' . $type_flags . '.' . $lang . ' > span:before { background-position: ' . $flags_positions[ $type_flags ][ $lang ] . 'px 0; }';
106
  }
src/third/amp/class-amp-service-weglot.php CHANGED
@@ -13,8 +13,9 @@ if ( ! defined( 'ABSPATH' ) ) {
13
  class Amp_Service_Weglot {
14
 
15
  /**
 
 
16
  * @since 2.0
17
- * @param mixed $with_escape
18
  */
19
  public function get_regex( $with_escape = false ) {
20
  $regex = '([&\?/])amp(/)?$';
13
  class Amp_Service_Weglot {
14
 
15
  /**
16
+ * @param bool $with_escape
17
+ * @return string
18
  * @since 2.0
 
19
  */
20
  public function get_regex( $with_escape = false ) {
21
  $regex = '([&\?/])amp(/)?$';
src/third/cacheenabler/class-cache-enabler-cache.php CHANGED
@@ -8,6 +8,9 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
 
11
 
12
 
13
  /**
@@ -16,6 +19,14 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 3.1.4
17
  */
18
  class Cache_Enabler_Cache implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
19
 
20
  /**
21
  * @since 3.1.4
@@ -42,12 +53,18 @@ class Cache_Enabler_Cache implements Hooks_Interface_Weglot {
42
  }
43
 
44
  /**
45
- * @since 3.1.4
46
  * @return bool
 
47
  */
48
  public function bypass_cache( $bypass_cache ) {
49
 
50
- if ( weglot_get_original_language() !== weglot_get_current_language() ) {
 
 
 
 
 
51
  return true;
52
  }
53
 
@@ -63,8 +80,9 @@ class Cache_Enabler_Cache implements Hooks_Interface_Weglot {
63
  }
64
 
65
  /**
66
- * @since 3.1.4
67
  * @return string
 
68
  */
69
  public function add_default_switcher( $dom ) {
70
  return $this->generate_switcher_service->generate_switcher_from_dom( $dom );
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
+ use WeglotWP\Services\Generate_Switcher_Service_Weglot;
12
+ use WeglotWP\Services\Language_Service_Weglot;
13
+ use WeglotWP\Services\Request_Url_Service_Weglot;
14
 
15
 
16
  /**
19
  * @since 3.1.4
20
  */
21
  class Cache_Enabler_Cache implements Hooks_Interface_Weglot {
22
+ /**
23
+ * @var Cache_Enabler_Active
24
+ */
25
+ private $cache_enabler_active;
26
+ /**
27
+ * @var Generate_Switcher_Service_Weglot
28
+ */
29
+ private $generate_switcher_service;
30
 
31
  /**
32
  * @since 3.1.4
53
  }
54
 
55
  /**
56
+ * @param $bypass_cache
57
  * @return bool
58
+ * @since 3.1.4
59
  */
60
  public function bypass_cache( $bypass_cache ) {
61
 
62
+ /** @var $request_url_services Request_Url_Service_Weglot */
63
+ $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
64
+ /** @var $language_services Language_Service_Weglot */
65
+ $language_services = weglot_get_service( 'Language_Service_Weglot' );
66
+
67
+ if ( $request_url_services->get_current_language() !== $language_services->get_original_language() ) {
68
  return true;
69
  }
70
 
80
  }
81
 
82
  /**
83
+ * @param $dom
84
  * @return string
85
+ * @since 3.1.4
86
  */
87
  public function add_default_switcher( $dom ) {
88
  return $this->generate_switcher_service->generate_switcher_from_dom( $dom );
src/third/calderaforms/class-caldera-i18n-inline.php CHANGED
@@ -14,6 +14,10 @@ use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
14
  * @since 3.0.0
15
  */
16
  class Caldera_I18n_Inline implements Hooks_Interface_Weglot {
 
 
 
 
17
 
18
  /**
19
  * @since 3.0.0
14
  * @since 3.0.0
15
  */
16
  class Caldera_I18n_Inline implements Hooks_Interface_Weglot {
17
+ /**
18
+ * @var Caldera_Active
19
+ */
20
+ private $caldera_active_services;
21
 
22
  /**
23
  * @since 3.0.0
src/third/calderaforms/regexcheckers/class-caldera-form-json-fields.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\SourceType;
10
 
11
 
src/third/contactform7/class-contactform7-json-keys.php CHANGED
@@ -16,6 +16,10 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 3.1.2
17
  */
18
  class Contactform7_Json_Keys implements Hooks_Interface_Weglot {
 
 
 
 
19
 
20
  /**
21
  * @since 3.1.2
16
  * @since 3.1.2
17
  */
18
  class Contactform7_Json_Keys implements Hooks_Interface_Weglot {
19
+ /**
20
+ * @var Contactform7_Active
21
+ */
22
+ private $contactform7_active_services;
23
 
24
  /**
25
  * @since 3.1.2
src/third/edd/class-edd-filter-urls.php CHANGED
@@ -11,6 +11,10 @@ use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
11
 
12
 
13
  class Edd_Filter_Urls implements Hooks_Interface_Weglot {
 
 
 
 
14
 
15
  /**
16
  * @return void
11
 
12
 
13
  class Edd_Filter_Urls implements Hooks_Interface_Weglot {
14
+ /**
15
+ * @var Edd_Active
16
+ */
17
+ private $edd_active_services;
18
 
19
  /**
20
  * @return void
src/third/gravityforms/class-gf-filter-urls.php CHANGED
@@ -14,6 +14,10 @@ use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
14
  * @since 3.0.0
15
  */
16
  class GF_Filter_Urls implements Hooks_Interface_Weglot {
 
 
 
 
17
 
18
  /**
19
  * @since 2.0
@@ -51,7 +55,7 @@ class GF_Filter_Urls implements Hooks_Interface_Weglot {
51
  return $data;
52
  }
53
 
54
- $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_with_ajax( $data['redirect'] );
55
  return $data;
56
 
57
  }
14
  * @since 3.0.0
15
  */
16
  class GF_Filter_Urls implements Hooks_Interface_Weglot {
17
+ /**
18
+ * @var Gf_Active
19
+ */
20
+ private $gf_active_services;
21
 
22
  /**
23
  * @since 2.0
55
  return $data;
56
  }
57
 
58
+ $data['redirect'] = Helper_Filter_Url_Weglot::filter_url_lambda( $data['redirect'] );
59
  return $data;
60
 
61
  }
src/third/mailoptin/regexcheckers/class-mailoptin-json.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\SourceType;
10
 
11
 
src/third/maintenance/class-maintenance-tracking.php CHANGED
@@ -16,6 +16,10 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 3.1.4
17
  */
18
  class Maintenance_Tracking implements Hooks_Interface_Weglot {
 
 
 
 
19
 
20
  /**
21
  * @since 3.1.4
@@ -44,8 +48,9 @@ class Maintenance_Tracking implements Hooks_Interface_Weglot {
44
 
45
 
46
  /**
 
 
47
  * @since 3.1.4
48
- * @return void
49
  */
50
  public function weglot_maintenance_tracking( $options_available ) {
51
 
16
  * @since 3.1.4
17
  */
18
  class Maintenance_Tracking implements Hooks_Interface_Weglot {
19
+ /**
20
+ * @var Maintenance_Active
21
+ */
22
+ private $maintenance_active_services;
23
 
24
  /**
25
  * @since 3.1.4
48
 
49
 
50
  /**
51
+ * @param $options_available
52
+ * @return mixed
53
  * @since 3.1.4
 
54
  */
55
  public function weglot_maintenance_tracking( $options_available ) {
56
 
src/third/ninjaforms/regexcheckers/class-ninja-form-json-fields.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\SourceType;
10
 
11
 
src/third/ninjaforms/regexcheckers/class-ninja-form-json-nfi18n.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\SourceType;
10
 
11
 
src/third/ninjaforms/regexcheckers/class-ninja-form-json-setting.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\SourceType;
10
 
11
 
src/third/theeventscalendar/class-theeventscalendar-words.php CHANGED
@@ -17,6 +17,11 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
17
  */
18
  class Theeventscalendar_Words implements Hooks_Interface_Weglot {
19
 
 
 
 
 
 
20
  /**
21
  * @since 3.1.2
22
  * @return void
@@ -41,8 +46,8 @@ class Theeventscalendar_Words implements Hooks_Interface_Weglot {
41
 
42
 
43
  /**
 
44
  * @since 3.1.2
45
- * @return void
46
  */
47
  public function weglot_theeventscalendar_words( $words ) {
48
 
17
  */
18
  class Theeventscalendar_Words implements Hooks_Interface_Weglot {
19
 
20
+ /**
21
+ * @var Theeventscalendar_Active
22
+ */
23
+ private $theeventcalendar_active_services;
24
+
25
  /**
26
  * @since 3.1.2
27
  * @return void
46
 
47
 
48
  /**
49
+ * @return array
50
  * @since 3.1.2
 
51
  */
52
  public function weglot_theeventscalendar_words( $words ) {
53
 
src/third/underconstructionpage/class-ucp-tracking.php CHANGED
@@ -16,6 +16,10 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 3.1.1
17
  */
18
  class UCP_Tracking implements Hooks_Interface_Weglot {
 
 
 
 
19
 
20
  /**
21
  * @since 3.1.1
@@ -44,8 +48,9 @@ class UCP_Tracking implements Hooks_Interface_Weglot {
44
 
45
 
46
  /**
 
 
47
  * @since 3.1.1
48
- * @return void
49
  */
50
  public function weglot_ucp_tracking( $options_available ) {
51
 
16
  * @since 3.1.1
17
  */
18
  class UCP_Tracking implements Hooks_Interface_Weglot {
19
+ /**
20
+ * @var Ucp_Active
21
+ */
22
+ private $ucp_active_services;
23
 
24
  /**
25
  * @since 3.1.1
48
 
49
 
50
  /**
51
+ * @param $options_available
52
+ * @return mixed
53
  * @since 3.1.1
 
54
  */
55
  public function weglot_ucp_tracking( $options_available ) {
56
 
src/third/woocommerce/class-wc-cart-reload-weglot.php CHANGED
@@ -16,7 +16,10 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 2.4.0
17
  */
18
  class WC_Cart_Reload_Weglot implements Hooks_Interface_Weglot {
19
- protected $name_transient = 'weglot_wc_clean_cart';
 
 
 
20
 
21
  /**
22
  * @since 2.4.0
16
  * @since 2.4.0
17
  */
18
  class WC_Cart_Reload_Weglot implements Hooks_Interface_Weglot {
19
+ /**
20
+ * @var Wc_Active
21
+ */
22
+ private $wc_active_services;
23
 
24
  /**
25
  * @since 2.4.0
src/third/woocommerce/class-wc-filter-urls-weglot.php CHANGED
@@ -6,8 +6,12 @@ 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
  /**
@@ -16,10 +20,27 @@ use WeglotWP\Helpers\Helper_Filter_Url_Weglot;
16
  * @since 2.0
17
  */
18
  class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  /**
21
- * @since 2.0
22
  * @return void
 
 
23
  */
24
  public function __construct() {
25
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
@@ -40,9 +61,9 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
40
  return;
41
  }
42
 
43
- add_filter( 'woocommerce_get_cart_url', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ) );
44
- add_filter( 'woocommerce_get_checkout_url', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ) );
45
- add_filter( 'woocommerce_get_myaccount_page_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_without_ajax' ) );
46
  add_filter( 'woocommerce_payment_successful_result', array( $this, 'woocommerce_filter_url_array' ) );
47
  add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'woocommerce_filter_order_received_url' ) );
48
  add_action( 'woocommerce_reset_password_notification', array( $this, 'woocommerce_filter_reset_password' ), 999 );
@@ -67,54 +88,20 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
67
  * @return string
68
  */
69
  public function woocommerce_filter_order_received_url( $url_filter ) {
70
- $current_and_original_language = weglot_get_current_and_original_language();
71
- $choose_current_language = $current_and_original_language['current'];
72
- $url = $this->request_url_services->create_url_object( $url_filter );
73
-
74
- $url_translated = $url->getForLanguage( $choose_current_language );
75
- $custom_urls = $this->option_services->get_option( 'custom_urls' );
76
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
77
- $key = array_search( $current_and_original_language['current'], $language_code_rewrited, true );
78
- $to_iso_language = $key ? $key : $current_and_original_language['current'];
79
- if ( isset( $custom_urls[ $to_iso_language ] ) ) {
80
- foreach ( $custom_urls[ $to_iso_language ] as $key => $value ) {
81
- $url_translated = str_replace( '/' . $value . '/', '/' . $key . '/', $url_translated );
82
- }
83
- }
84
-
85
- if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) { // Not ajax
86
-
87
- if ( substr( get_option( 'permalink_structure' ), -1 ) !== '/' ) {
88
- return str_replace( '/?key', '?key', $url_translated );
89
- } else {
90
- return str_replace( '//?key', '/?key', str_replace( '?key', '/?key', $url_translated ) );
91
- }
92
- } else {
93
- if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
94
- // Ajax
95
- $choose_current_language = $url->detectCurrentLanguage();
96
- if ( $choose_current_language && $choose_current_language !== $current_and_original_language['original'] ) {
97
- if ( substr( get_option( 'permalink_structure' ), -1 ) !== '/' ) {
98
- return str_replace( '/?key', '?key', $url_translated );
99
- } else {
100
- return str_replace( '//?key', '/?key', str_replace( '?key', '/?key', $url_translated ) );
101
- }
102
- }
103
- }
104
- }
105
- return $url_filter;
106
  }
107
 
108
  public function last_password_url_filter( $url, $endpoint, $value, $permalink ) {
109
 
110
- if ( $endpoint === 'lost-password' ) {
111
  $current_headers = headers_list();
112
  foreach ( $current_headers as $header ) {
113
  if ( strpos( $header, 'wp-resetpass' ) !== false ) {
114
- preg_match( '#wp-resetpass-(.*?)=(.*?);#', $header, $matchesName );
115
- preg_match( '#path=(.*?);#', $header, $matchesPath );
116
- if ( isset( $matchesName[0] ) && isset( $matchesPath[0] ) && isset( $matchesPath[1] ) ) {
117
- setcookie( 'wp-resetpass-' . $matchesName[1], urldecode( $matchesName[2] ), 0, '/' . weglot_get_current_language() . $matchesPath[1], '', is_ssl(), true );
118
  }
119
  }
120
  }
@@ -130,15 +117,17 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
130
  * @return array
131
  */
132
  public function woocommerce_filter_url_array( $result ) {
133
- $current_and_original_language = weglot_get_current_and_original_language();
134
- $choose_current_language = $current_and_original_language['current'];
135
- if ( $current_and_original_language['current'] !== $current_and_original_language['original'] ) { // Not ajax
 
 
136
  $url = $this->request_url_services->create_url_object( $result['redirect'] );
137
  } else {
138
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
139
  // Ajax
140
  $url = $this->request_url_services->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
141
- $choose_current_language = $url->detectCurrentLanguage();
142
  $url = $this->request_url_services->create_url_object( $result['redirect'] );
143
  }
144
  }
@@ -159,16 +148,17 @@ class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
159
  * @return void
160
  */
161
  public function woocommerce_filter_reset_password( $url ) {
162
- $current_and_original_language = weglot_get_current_and_original_language();
 
163
 
164
- if ( $current_and_original_language['current'] === $current_and_original_language['original'] ) {
165
  return $url;
166
  }
167
 
168
  $url_redirect = add_query_arg( 'reset-link-sent', 'true', wc_get_account_endpoint_url( 'lost-password' ) );
169
  $url_redirect = $this->request_url_services->create_url_object( $url_redirect );
170
 
171
- wp_redirect( $url_redirect->getForLanguage( $current_and_original_language['current'] ) ); //phpcs:ignore
172
  exit;
173
  }
174
  }
6
  exit;
7
  }
8
 
9
+ use Exception;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
+ use WeglotWP\Services\Language_Service_Weglot;
12
+ use WeglotWP\Services\Option_Service_Weglot;
13
+ use WeglotWP\Services\Replace_Url_Service_Weglot;
14
+ use WeglotWP\Services\Request_Url_Service_Weglot;
15
 
16
 
17
  /**
20
  * @since 2.0
21
  */
22
  class WC_Filter_Urls_Weglot implements Hooks_Interface_Weglot {
23
+ /**
24
+ * @var Request_Url_Service_Weglot
25
+ */
26
+ private $request_url_services;
27
+ /**
28
+ * @var Option_Service_Weglot
29
+ */
30
+ private $option_services;
31
+ /**
32
+ * @var Wc_Active
33
+ */
34
+ private $wc_active_services;
35
+ /**
36
+ * @var Replace_Url_Service_Weglot
37
+ */
38
+ private $replace_url_services;
39
 
40
  /**
 
41
  * @return void
42
+ * @throws Exception
43
+ * @since 2.0
44
  */
45
  public function __construct() {
46
  $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
61
  return;
62
  }
63
 
64
+ add_filter( 'woocommerce_get_cart_url', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
65
+ add_filter( 'woocommerce_get_checkout_url', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
66
+ add_filter( 'woocommerce_get_myaccount_page_permalink', array( '\WeglotWP\Helpers\Helper_Filter_Url_Weglot', 'filter_url_lambda' ) );
67
  add_filter( 'woocommerce_payment_successful_result', array( $this, 'woocommerce_filter_url_array' ) );
68
  add_filter( 'woocommerce_get_checkout_order_received_url', array( $this, 'woocommerce_filter_order_received_url' ) );
69
  add_action( 'woocommerce_reset_password_notification', array( $this, 'woocommerce_filter_reset_password' ), 999 );
88
  * @return string
89
  */
90
  public function woocommerce_filter_order_received_url( $url_filter ) {
91
+ $url = $this->request_url_services->create_url_object( $url_filter );
92
+ return $url->getForLanguage( $this->request_url_services->get_current_language() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
 
95
  public function last_password_url_filter( $url, $endpoint, $value, $permalink ) {
96
 
97
+ if ( 'lost-password' === $endpoint ) {
98
  $current_headers = headers_list();
99
  foreach ( $current_headers as $header ) {
100
  if ( strpos( $header, 'wp-resetpass' ) !== false ) {
101
+ preg_match( '#wp-resetpass-(.*?)=(.*?);#', $header, $matches_name );
102
+ preg_match( '#path=(.*?);#', $header, $matches_path );
103
+ if ( isset( $matches_name[0] ) && isset( $matches_path[0] ) && isset( $matches_path[1] ) ) {
104
+ setcookie( 'wp-resetpass-' . $matches_name[1], urldecode( $matches_name[2] ), 0, '/' . $this->request_url_services->get_current_language()->getExternalCode() . $matches_path[1], '', is_ssl(), true ); // phpcs:ignore
105
  }
106
  }
107
  }
117
  * @return array
118
  */
119
  public function woocommerce_filter_url_array( $result ) {
120
+ /** @var $language_service Language_Service_Weglot */
121
+ $language_service = weglot_get_service( 'Language_Service_Weglot' );
122
+
123
+ $choose_current_language = $this->request_url_services->get_current_language();
124
+ if ( $choose_current_language !== $language_service->get_original_language() ) { // Not ajax
125
  $url = $this->request_url_services->create_url_object( $result['redirect'] );
126
  } else {
127
  if ( isset( $_SERVER['HTTP_REFERER'] ) ) { //phpcs:ignore
128
  // Ajax
129
  $url = $this->request_url_services->create_url_object( $_SERVER['HTTP_REFERER'] ); //phpcs:ignore
130
+ $choose_current_language = $url->getCurrentLanguage();
131
  $url = $this->request_url_services->create_url_object( $result['redirect'] );
132
  }
133
  }
148
  * @return void
149
  */
150
  public function woocommerce_filter_reset_password( $url ) {
151
+ /** @var $language_service Language_Service_Weglot */
152
+ $language_service = weglot_get_service( 'Language_Service_Weglot' );
153
 
154
+ if ( $this->request_url_services->get_current_language() === $language_service->get_original_language() ) {
155
  return $url;
156
  }
157
 
158
  $url_redirect = add_query_arg( 'reset-link-sent', 'true', wc_get_account_endpoint_url( 'lost-password' ) );
159
  $url_redirect = $this->request_url_services->create_url_object( $url_redirect );
160
 
161
+ wp_redirect( $url_redirect->getForLanguage( $this->request_url_services->get_current_language() ) ); //phpcs:ignore
162
  exit;
163
  }
164
  }
src/third/woocommerce/class-wc-mail-weglot.php CHANGED
@@ -8,6 +8,8 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
11
 
12
 
13
  /**
@@ -16,13 +18,27 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 3.1.6
17
  */
18
  class WC_Mail_Weglot implements Hooks_Interface_Weglot {
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  /**
21
  * @since 3.1.6
22
  * @return void
23
  */
24
  public function __construct() {
25
- $this->wc_active_services = weglot_get_service( 'Wc_Active' );
 
 
26
  }
27
 
28
  /**
@@ -39,8 +55,10 @@ class WC_Mail_Weglot implements Hooks_Interface_Weglot {
39
  }
40
 
41
  /**
42
- * @since 3.1.6
 
43
  * @return array
 
44
  */
45
  public function translate_following_mail( $args, $mail ) {
46
 
@@ -56,11 +74,13 @@ class WC_Mail_Weglot implements Hooks_Interface_Weglot {
56
 
57
  if ( $mail->is_customer_email() ) { // If mail is for customer
58
  $woocommerce_order_language = get_post_meta( $mail->object->get_id(), 'weglot_language', true );
59
-
60
  if ( ! empty( $woocommerce_order_language ) ) {
61
 
62
- $current_and_original_language = weglot_get_current_and_original_language();
63
- $current_and_original_language['current'] = $woocommerce_order_language;
 
 
 
64
 
65
  add_filter(
66
  'weglot_translate_email_languages_forced',
@@ -70,7 +90,7 @@ class WC_Mail_Weglot implements Hooks_Interface_Weglot {
70
  );
71
  }
72
  } else { // If mail is for admin
73
- $current_and_original_language['original'] = weglot_get_original_language();
74
  $current_and_original_language['current'] = $current_and_original_language['original'];
75
 
76
  add_filter(
@@ -95,9 +115,9 @@ class WC_Mail_Weglot implements Hooks_Interface_Weglot {
95
  return;
96
  }
97
 
98
- $current_language = weglot_get_current_language();
99
- if ( weglot_get_original_language() !== $current_language ) {
100
- add_post_meta( $order_id, 'weglot_language', weglot_get_current_language() );
101
  }
102
 
103
  return $order_id;
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
+ use WeglotWP\Services\Language_Service_Weglot;
12
+ use WeglotWP\Services\Request_Url_Service_Weglot;
13
 
14
 
15
  /**
18
  * @since 3.1.6
19
  */
20
  class WC_Mail_Weglot implements Hooks_Interface_Weglot {
21
+ /**
22
+ * @var Wc_Active
23
+ */
24
+ private $wc_active_services;
25
+ /**
26
+ * @var Request_Url_Service_Weglot
27
+ */
28
+ private $request_url_services;
29
+ /**
30
+ * @var Language_Service_Weglot
31
+ */
32
+ private $language_services;
33
 
34
  /**
35
  * @since 3.1.6
36
  * @return void
37
  */
38
  public function __construct() {
39
+ $this->wc_active_services = weglot_get_service( 'Wc_Active' );
40
+ $this->request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
41
+ $this->language_services = weglot_get_service( 'Language_Service_Weglot' );
42
  }
43
 
44
  /**
55
  }
56
 
57
  /**
58
+ * @param $args
59
+ * @param $mail
60
  * @return array
61
+ * @since 3.1.6
62
  */
63
  public function translate_following_mail( $args, $mail ) {
64
 
74
 
75
  if ( $mail->is_customer_email() ) { // If mail is for customer
76
  $woocommerce_order_language = get_post_meta( $mail->object->get_id(), 'weglot_language', true );
 
77
  if ( ! empty( $woocommerce_order_language ) ) {
78
 
79
+ $current_and_original_language = array(
80
+ 'original' => $this->language_services->get_original_language()->getInternalCode(),
81
+ 'current' => $this->request_url_services->get_current_language()->getInternalCode(),
82
+ );
83
+ $current_and_original_language['current'] = $this->language_services->get_language_from_external( $woocommerce_order_language )->getInternalCode();
84
 
85
  add_filter(
86
  'weglot_translate_email_languages_forced',
90
  );
91
  }
92
  } else { // If mail is for admin
93
+ $current_and_original_language['original'] = $this->language_services->get_original_language()->getInternalCode();
94
  $current_and_original_language['current'] = $current_and_original_language['original'];
95
 
96
  add_filter(
115
  return;
116
  }
117
 
118
+ $current_language = $this->request_url_services->get_current_language()->getInternalCode();
119
+ if ( $this->language_services->get_original_language()->getInternalCode() !== $current_language ) {
120
+ add_post_meta( $order_id, 'weglot_language', $this->request_url_services->get_current_language()->getExternalCode() );
121
  }
122
 
123
  return $order_id;
src/third/wpforms/regexcheckers/class-wp-form-json-setting.php CHANGED
@@ -6,7 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- use Weglot\Parser\Check\Regex\RegexChecker;
10
  use Weglot\Util\SourceType;
11
 
12
 
6
  exit;
7
  }
8
 
 
9
  use Weglot\Util\SourceType;
10
 
11
 
src/third/wpoptimize/class-wp-optimize-cache.php CHANGED
@@ -8,6 +8,8 @@ if ( ! defined( 'ABSPATH' ) ) {
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
 
 
11
 
12
 
13
  /**
@@ -16,6 +18,10 @@ use WeglotWP\Models\Hooks_Interface_Weglot;
16
  * @since 3.1.4
17
  */
18
  class Wp_Optimize_Cache implements Hooks_Interface_Weglot {
 
 
 
 
19
 
20
  /**
21
  * @since 3.1.4
@@ -41,12 +47,18 @@ class Wp_Optimize_Cache implements Hooks_Interface_Weglot {
41
 
42
 
43
  /**
44
- * @since 3.1.4
45
  * @return bool
 
46
  */
47
  public function weglot_wpo_can_cache_page( $can_cache_page ) {
48
 
49
- if ( weglot_get_original_language() !== weglot_get_current_language() ) {
 
 
 
 
 
50
  return false;
51
  }
52
 
8
 
9
  use WeglotWP\Helpers\Helper_Is_Admin;
10
  use WeglotWP\Models\Hooks_Interface_Weglot;
11
+ use WeglotWP\Services\Language_Service_Weglot;
12
+ use WeglotWP\Services\Request_Url_Service_Weglot;
13
 
14
 
15
  /**
18
  * @since 3.1.4
19
  */
20
  class Wp_Optimize_Cache implements Hooks_Interface_Weglot {
21
+ /**
22
+ * @var Wp_Optimize_Active
23
+ */
24
+ private $wp_optimize_active_services;
25
 
26
  /**
27
  * @since 3.1.4
47
 
48
 
49
  /**
50
+ * @param $can_cache_page
51
  * @return bool
52
+ * @since 3.1.4
53
  */
54
  public function weglot_wpo_can_cache_page( $can_cache_page ) {
55
 
56
+ /** @var $request_url_services Request_Url_Service_Weglot */
57
+ $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
58
+ /** @var $language_services Language_Service_Weglot */
59
+ $language_services = weglot_get_service( 'Language_Service_Weglot' );
60
+
61
+ if ( $request_url_services->get_current_language() !== $language_services->get_original_language() ) {
62
  return false;
63
  }
64
 
src/third/yoast/class-redirect-handler-weglot.php CHANGED
@@ -1,5 +1,8 @@
1
  <?php
2
 
 
 
 
3
  if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
@@ -32,9 +35,11 @@ class Redirect_Handler_Weglot extends \WPSEO_Redirect_Handler {
32
  protected $request_url = '';
33
 
34
  public function load() {
35
- $original_destination = weglot_get_current_and_original_language();
36
 
37
- if ( empty( $original_destination['original'] ) || empty( $original_destination['destination'] ) ) {
 
 
 
38
  return;
39
  }
40
 
@@ -70,7 +75,7 @@ class Redirect_Handler_Weglot extends \WPSEO_Redirect_Handler {
70
  */
71
  protected function handle_normal_redirects( $request_url ) {
72
  // Setting the redirects.
73
- $redirects = $this->get_redirects( $this->normal_option_name );
74
  $this->redirects = $this->normalize_redirects( $redirects );
75
 
76
  // Trim the slashes, to match the variants of a request URL (Like: url, /url, /url/, url/).
@@ -83,7 +88,10 @@ class Redirect_Handler_Weglot extends \WPSEO_Redirect_Handler {
83
  if ( isset( $request_url[2] ) && '/' === $request_url[2] ) {
84
  $code_language = explode( '/', $request_url );
85
 
86
- $langs = weglot_get_current_languages_configured( 'code' );
 
 
 
87
 
88
  if ( ! in_array( $code_language[0], $langs ) ) { // phpcs:ignore
89
  //Default behavior Yoast
1
  <?php
2
 
3
+ use WeglotWP\Services\Language_Service_Weglot;
4
+ use WeglotWP\Services\Request_Url_Service_Weglot;
5
+
6
  if ( ! defined( 'ABSPATH' ) ) {
7
  exit;
8
  }
35
  protected $request_url = '';
36
 
37
  public function load() {
 
38
 
39
+ /** @var $language_services Language_Service_Weglot */
40
+ $language_services = weglot_get_service( 'Language_Service_Weglot' );
41
+
42
+ if ( empty( $language_services->get_original_language() ) ) {
43
  return;
44
  }
45
 
75
  */
76
  protected function handle_normal_redirects( $request_url ) {
77
  // Setting the redirects.
78
+ $redirects = $this->get_redirects( $this->normal_option_name );
79
  $this->redirects = $this->normalize_redirects( $redirects );
80
 
81
  // Trim the slashes, to match the variants of a request URL (Like: url, /url, /url/, url/).
88
  if ( isset( $request_url[2] ) && '/' === $request_url[2] ) {
89
  $code_language = explode( '/', $request_url );
90
 
91
+ /** @var $language_services Language_Service_Weglot */
92
+ $language_services = weglot_get_service( 'Language_Service_Weglot' );
93
+
94
+ $langs = $language_services->get_destination_languages_external();
95
 
96
  if ( ! in_array( $code_language[0], $langs ) ) { // phpcs:ignore
97
  //Default behavior Yoast
src/widgets/class-widget-selector-weglot.php CHANGED
@@ -2,6 +2,9 @@
2
 
3
  namespace WeglotWP\Widgets;
4
 
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
@@ -25,13 +28,16 @@ class Widget_Selector_Weglot extends \WP_Widget {
25
  /**
26
  * Front-end display of widget.
27
  *
 
 
 
28
  * @see WP_Widget::widget()
29
  *
30
- * @param array $args Widget arguments.
31
- * @param array $instance Saved values from database.
32
  */
33
  public function widget( $args, $instance ) {
34
- if ( ! weglot_current_url_is_eligible() ) {
 
 
35
  return;
36
  }
37
  $title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
@@ -39,7 +45,9 @@ class Widget_Selector_Weglot extends \WP_Widget {
39
 
40
  $tt = ( ! empty( $title ) ) ? $args['before_title'] . $title . $args['after_title'] : '';
41
 
42
- $button = weglot_get_button_selector_html( 'weglot-widget' );
 
 
43
 
44
  echo $args['before_widget'] . $tt . $button . $args['after_widget']; //phpcs:ignore
45
  }
@@ -78,7 +86,7 @@ class Widget_Selector_Weglot extends \WP_Widget {
78
  */
79
  public function update( $new_instance, $old_instance ) {
80
  $instance = array();
81
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( strip_tags( $new_instance['title'] ) ) : '';
82
  return $instance;
83
  }
84
  }
2
 
3
  namespace WeglotWP\Widgets;
4
 
5
+ use WeglotWP\Services\Button_Service_Weglot;
6
+ use WeglotWP\Services\Request_Url_Service_Weglot;
7
+
8
  if ( ! defined( 'ABSPATH' ) ) {
9
  exit;
10
  }
28
  /**
29
  * Front-end display of widget.
30
  *
31
+ * @param array $args Widget arguments.
32
+ * @param array $instance Saved values from database.
33
+ * @throws \Exception
34
  * @see WP_Widget::widget()
35
  *
 
 
36
  */
37
  public function widget( $args, $instance ) {
38
+ /** @var Request_Url_Service_Weglot $request_url_service */
39
+ $request_url_service = weglot_get_service( 'Request_Url_Service_Weglot' );
40
+ if ( ! $request_url_service->is_eligible_url() ) {
41
  return;
42
  }
43
  $title = ( isset( $instance['title'] ) ) ? $instance['title'] : '';
45
 
46
  $tt = ( ! empty( $title ) ) ? $args['before_title'] . $title . $args['after_title'] : '';
47
 
48
+ /** @var $button_service Button_Service_Weglot */
49
+ $button_service = weglot_get_service( 'Button_Service_Weglot' );
50
+ $button = $button_service->get_html( 'weglot-widget' );
51
 
52
  echo $args['before_widget'] . $tt . $button . $args['after_widget']; //phpcs:ignore
53
  }
86
  */
87
  public function update( $new_instance, $old_instance ) {
88
  $instance = array();
89
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( wp_strip_all_tags( $new_instance['title'] ) ) : '';
90
  return $instance;
91
  }
92
  }
templates/admin/metaboxes/url-translate.php DELETED
@@ -1,91 +0,0 @@
1
- <?php
2
-
3
- use WeglotWP\Helpers\Helper_Post_Meta_Weglot;
4
-
5
- if ( ! defined( 'ABSPATH' ) ) {
6
- exit;
7
- }
8
-
9
-
10
- global $pagenow;
11
-
12
- if ( 'post-new.php' === $pagenow ) {
13
- esc_html_e( 'You must first create the page a first time before you can benefit from custom URLs', 'weglot' );
14
- } else {
15
-
16
- $languages_available = weglot_get_languages_configured();
17
- $original_language = weglot_get_original_language();
18
- list( $permalink ) = get_sample_permalink( $post->ID );
19
- $display_link_original = str_replace( array( '%pagename%', '%postname%', home_url() ), '', $permalink );
20
- $display_link_original = implode( '/', array_filter( explode( '/', $display_link_original ), 'strlen' ) );
21
- $language_code_rewrited = apply_filters( 'weglot_language_code_replace', array() );
22
-
23
- if ( ! empty( $display_link_original ) && '/' !== $display_link_original[ strlen( $display_link_original ) - 1 ] ) {
24
- $display_link_original .= '/';
25
- }
26
- ?>
27
- <input type="hidden" id="weglot_post_id" data-id="<?php echo esc_attr( $post->ID ); ?>" />
28
- <?php
29
- foreach ( $languages_available as $language ) {
30
-
31
- $display_link = $display_link_original;
32
- $code = $language->getIso639();
33
-
34
- if ( $code === $original_language ) {
35
- continue;
36
- }
37
-
38
- $code_rewrited = $code;
39
- if ( isset( $language_code_rewrited[ $code ] ) ) {
40
- $code_rewrited = $language_code_rewrited[ $code ];
41
- }
42
-
43
- $post_name_weglot = $post->post_name;
44
- $post_name_input = '';
45
- if ( isset( $this->custom_urls[ $code ] ) ) {
46
- $post_name_weglot = array_search( $post_name_weglot, $this->custom_urls[ $code ] );
47
- if ( false === $post_name_weglot || empty( $post_name_weglot ) ) {
48
- $post_name_weglot = $post->post_name;
49
- } else {
50
- $post_name_input = $post_name_weglot;
51
- }
52
- }
53
-
54
- $display_link = '/' . untrailingslashit( $display_link ) . '/';
55
- if ( isset( $this->custom_urls[ $code ] ) ) {
56
- foreach ( $this->custom_urls[ $code ] as $slug_translated => $slug_original ) {
57
- if ( empty( $slug_translated ) || empty( $slug_original ) ) {
58
- continue;
59
- }
60
- $display_link = str_replace( '/' . $slug_original . '/', '/' . $slug_translated . '/', $display_link );
61
-
62
- }
63
- }
64
- $display_link = trim( $display_link, '/' ) . '/';
65
-
66
- if ( '/' === $display_link ) {
67
- $display_link = '';
68
- }
69
-
70
- ?>
71
- <label for="lang-<?php echo esc_attr( $code ); ?>">
72
- <strong><?php echo esc_html( $language->getLocalName() ); ?></strong>
73
- </label>
74
- <div class="weglot_custom_url">
75
- <p class="weglot_custom_url--text_link">
76
- <?php echo esc_url( home_url() ); ?>/<?php echo esc_attr( $code_rewrited ); ?>/<?php echo esc_attr( $display_link ); ?><span id="text-edit-<?php echo esc_attr( $code ); ?>"><?php echo esc_attr( $post_name_weglot ); ?></span>
77
- <input type="text" id="lang-<?php echo esc_attr( $code ); ?>" name="post_name_weglot[<?php echo esc_attr( $code ); ?>]" value="<?php echo esc_attr( $post_name_input ); ?>" style="display:none;"/>
78
-
79
- <button type="button" class="button button-small button-weglot-lang" data-lang="<?php echo esc_attr( $code ); ?>" aria-label="Edit permalink weglot"><span class="dashicons dashicons-edit"></span> <?php esc_html_e( 'Edit', 'weglot' ); ?></button>
80
-
81
- <button type="button" class="button button-small button-weglot-lang-submit" data-lang="<?php echo esc_attr( $code ); ?>" style="display:none;"><?php esc_html_e( 'Ok', 'weglot' ); ?></button>
82
- </p>
83
- <p id="weglot_permalink_not_available_<?php echo esc_attr( $code ); ?>" class="weglot_text_error" style="display:none;"><?php esc_html_e( 'The permalink is not available.', 'weglot' ); ?></p>
84
- <a id="weglot_reset_custom_<?php echo esc_attr( $code ); ?>" data-lang="<?php echo esc_attr( $code ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>" href="<?php echo esc_attr( $post_name_weglot ); ?>" class="weglot_reset">
85
- <span class="dashicons dashicons-update-alt"></span> <?php esc_html_e( 'Reset custom url', 'weglot' ); ?>
86
- </a>
87
- </div>
88
-
89
- <?php
90
- }
91
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/admin/pages/nav.php CHANGED
@@ -10,14 +10,14 @@ if ( ! defined( 'ABSPATH' ) ) {
10
 
11
  <nav class="nav-tab-wrapper">
12
  <?php
13
- foreach ( $this->tabs as $key => $tab ) {
14
  $class_active = ( $this->tab_active === $key ) ? 'nav-tab-active' : '';
15
  if ( Helper_Tabs_Admin_Weglot::STATUS !== $key ) {
16
  ?>
17
  <a
18
- href="<?php echo esc_url( $tab['url'] ); ?>"
19
  class="nav-tab <?php echo esc_attr( $class_active ); ?>">
20
- <?php echo esc_html( $tab['title'] ); ?>
21
  </a>
22
  <?php
23
  }
10
 
11
  <nav class="nav-tab-wrapper">
12
  <?php
13
+ foreach ( $this->tabs as $key => $weglot_tab ) {
14
  $class_active = ( $this->tab_active === $key ) ? 'nav-tab-active' : '';
15
  if ( Helper_Tabs_Admin_Weglot::STATUS !== $key ) {
16
  ?>
17
  <a
18
+ href="<?php echo esc_url( $weglot_tab['url'] ); ?>"
19
  class="nav-tab <?php echo esc_attr( $class_active ); ?>">
20
+ <?php echo esc_html( $weglot_tab['title'] ); ?>
21
  </a>
22
  <?php
23
  }
templates/admin/pages/tabs/advanced.php CHANGED
@@ -53,15 +53,6 @@ $options_available = [
53
  ],
54
  ];
55
 
56
- $languages = weglot_get_languages_configured();
57
- foreach ( $languages as $key => $value ) {
58
- if ( $value && $value->getIso639() === weglot_get_original_language() ) {
59
- unset( $languages[ $key ] );
60
- }
61
- }
62
-
63
- $languages = array_values( $languages );
64
-
65
  ?>
66
 
67
  <h3><?php esc_html_e( 'Translation Exclusion (Optional)', 'weglot' ); ?> </h3>
@@ -183,54 +174,6 @@ $languages = array_values( $languages );
183
  <p class="description"><?php echo esc_html( $options_available['active_search']['description'] ); ?></p>
184
  </td>
185
  </tr>
186
- <tr valign="top">
187
- <th scope="row" class="titledesc">
188
- <label for="<?php echo esc_attr( $options_available['private_mode']['key'] ); ?>">
189
- <?php echo esc_html( $options_available['private_mode']['label'] ); ?>
190
- </label>
191
- </th>
192
- <td class="forminp forminp-text">
193
- <input
194
- id="<?php echo esc_attr( $options_available['private_mode']['key'] ); ?>"
195
- name="<?php echo esc_attr( sprintf( '%s[%s][active]', WEGLOT_SLUG, $options_available['private_mode']['key'] ) ); ?>"
196
- type="checkbox"
197
- <?php
198
- if ( array_key_exists( 'active', $this->options[ $options_available['private_mode']['key'] ] ) ) {
199
- checked( $this->options[ $options_available['private_mode']['key'] ]['active'], 1 );
200
- }
201
- ?>
202
- >
203
- <p class="description"><?php echo esc_html( $options_available['private_mode']['description'] ); ?></p>
204
- <div id="private-mode-detail">
205
- <?php
206
- foreach ( $languages as $key => $lang ) :
207
-
208
- if ( ! $lang ) {
209
- continue;
210
- }
211
-
212
- $checked_value = isset( $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] ) ? $this->options[ $options_available['private_mode']['key'] ][ $lang->getIso639() ] : null;
213
- ?>
214
- <div class="private-mode-detail-lang">
215
- <input
216
- name="<?php echo esc_attr( sprintf( '%s[languages][%s][enabled]', WEGLOT_SLUG, $key ) ); ?>"
217
- id="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>"
218
- type="checkbox"
219
- class="private-mode-lang--input"
220
- <?php checked( $checked_value, 1 ); ?>
221
- />
222
- <label for="<?php echo esc_attr( sprintf( '%s[%s][%s]', WEGLOT_SLUG, $options_available['private_mode']['key'], $lang->getIso639() ) ); ?>">
223
- <?php
224
- // translators: 1 Local name language
225
- $str = __( 'Make "%s" a private language', 'weglot' );
226
- echo esc_html( sprintf( $str, $lang->getEnglishName() ), 'weglot' );
227
- ?>
228
- </label>
229
- </div>
230
- <?php endforeach; ?>
231
- </div>
232
- </td>
233
- </tr>
234
  </tbody>
235
  </table>
236
 
@@ -239,8 +182,8 @@ $languages = array_values( $languages );
239
  <select
240
  name="<?php echo esc_attr( sprintf( '%s[excluded_paths][{KEY}][type]', WEGLOT_SLUG ) ); ?>"
241
  >
242
- <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $type ) : ?>
243
- <option value="<?php echo esc_attr( $type ); ?>"><?php echo esc_attr( Helper_Excluded_Type::get_label_type( $type ) ); ?></option>
244
  <?php endforeach; ?>
245
  </select>
246
  <input
53
  ],
54
  ];
55
 
 
 
 
 
 
 
 
 
 
56
  ?>
57
 
58
  <h3><?php esc_html_e( 'Translation Exclusion (Optional)', 'weglot' ); ?> </h3>
174
  <p class="description"><?php echo esc_html( $options_available['active_search']['description'] ); ?></p>
175
  </td>
176
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  </tbody>
178
  </table>
179
 
182
  <select
183
  name="<?php echo esc_attr( sprintf( '%s[excluded_paths][{KEY}][type]', WEGLOT_SLUG ) ); ?>"
184
  >
185
+ <?php foreach ( Helper_Excluded_Type::get_excluded_type() as $ex_type ) : ?>
186
+ <option value="<?php echo esc_attr( $ex_type ); ?>"><?php echo esc_attr( Helper_Excluded_Type::get_label_type( $ex_type ) ); ?></option>
187
  <?php endforeach; ?>
188
  </select>
189
  <input
templates/admin/pages/tabs/appearance.php CHANGED
@@ -15,7 +15,7 @@ $options_available = [
15
  'is_fullname' => [
16
  'key' => 'is_fullname',
17
  'label' => __( 'Is fullname', 'weglot' ),
18
- 'description' => __( "Check if you want the name of the languge. Don't check if you want the language code.", 'weglot' ),
19
  ],
20
  'with_name' => [
21
  'key' => 'with_name',
@@ -209,6 +209,11 @@ $options_available = [
209
  <option value=1><?php esc_html_e( 'China', 'weglot' ); ?></option>
210
  <option value=2><?php esc_html_e( 'Hong Kong', 'weglot' ); ?></option>
211
  </select>
 
 
 
 
 
212
  <p><?php esc_html_e( 'If you want to use a different flag, just ask us.', 'weglot' ); ?></p>
213
  </div>
214
  <textarea id="flag_css" name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['flag_css']['key'] ) ); ?>" style="display:none;"><?php echo esc_attr( $this->options['flag_css'] ); ?></textarea>
15
  'is_fullname' => [
16
  'key' => 'is_fullname',
17
  'label' => __( 'Is fullname', 'weglot' ),
18
+ 'description' => __( "Check if you want the name of the language. Don't check if you want the language code.", 'weglot' ),
19
  ],
20
  'with_name' => [
21
  'key' => 'with_name',
209
  <option value=1><?php esc_html_e( 'China', 'weglot' ); ?></option>
210
  <option value=2><?php esc_html_e( 'Hong Kong', 'weglot' ); ?></option>
211
  </select>
212
+ <select class="flag-pt-type wg-input-select">
213
+ <option value=0><?php esc_html_e( 'Choose Portuguese flag:', 'weglot' ); ?></option>
214
+ <option value=0><?php esc_html_e( 'Portugal (default)', 'weglot' ); ?></option>
215
+ <option value=1><?php esc_html_e( 'Brazil', 'weglot' ); ?></option>
216
+ </select>
217
  <p><?php esc_html_e( 'If you want to use a different flag, just ask us.', 'weglot' ); ?></p>
218
  </div>
219
  <textarea id="flag_css" name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, $options_available['flag_css']['key'] ) ); ?>" style="display:none;"><?php echo esc_attr( $this->options['flag_css'] ); ?></textarea>
templates/admin/pages/tabs/custom-urls.php CHANGED
@@ -11,7 +11,7 @@ use Weglot\WeglotContext;
11
  <hr>
12
 
13
  <?php
14
- if ( ! empty( $_GET['reset-all-custom-urls'] ) && 'true' === $_GET['reset-all-custom-urls'] ) {
15
  // Reset all customs URLs
16
  $option_service_weglot = weglot_get_service( 'Option_Service_Weglot' );
17
  $option_service_weglot->set_option_by_key( 'custom_urls', array() );
@@ -31,7 +31,7 @@ if ( ! empty( $_GET['reset-all-custom-urls'] ) && 'true' === $_GET['reset-all-cu
31
 
32
  <?php
33
  if ( ! empty( $options['custom_urls'] ) ) :
34
- foreach ( $options['custom_urls'] as $lang => $urls ) :
35
  ?>
36
 
37
  <h3><?php esc_html_e( 'Lang : ', 'weglot' ); ?><?php echo esc_html( $lang ); ?></h3>
@@ -46,8 +46,8 @@ if ( ! empty( $_GET['reset-all-custom-urls'] ) && 'true' === $_GET['reset-all-cu
46
  <div style="flex:1;"></div>
47
  </div>
48
  <?php
49
- if ( ! empty( $urls ) ) :
50
- foreach ( $urls as $key => $value ) :
51
  $key_generate = sprintf( '%s-%s-%s', $lang, $key, $value );
52
  ?>
53
  <div style="display:flex;" id="<?php echo esc_attr( $key_generate ); ?>">
@@ -102,7 +102,7 @@ if ( ! empty( $_GET['reset-all-custom-urls'] ) && 'true' === $_GET['reset-all-cu
102
  <hr />
103
  <p><span class="dashicons dashicons-trash"></span> <a href="<?php echo esc_url( $url_reset_all_custom_urls ); ?>" class="reset-all-custom-urls" style="color: #dc3232;"><?php esc_html_e( 'Reset all Weglot custom URLs', 'weglot' ); ?></a></p>
104
  <hr />
105
- <?php elseif ( empty( $_GET['reset-all-custom-urls'] ) ) : ?>
106
  <div class="error notice">
107
  <p><?php esc_html_e( 'No custom URL found.', 'weglot' ); ?></p>
108
  </div>
11
  <hr>
12
 
13
  <?php
14
+ if ( ! empty( $_GET['reset-all-custom-urls'] ) && 'true' === $_GET['reset-all-custom-urls'] ) { // phpcs:ignore
15
  // Reset all customs URLs
16
  $option_service_weglot = weglot_get_service( 'Option_Service_Weglot' );
17
  $option_service_weglot->set_option_by_key( 'custom_urls', array() );
31
 
32
  <?php
33
  if ( ! empty( $options['custom_urls'] ) ) :
34
+ foreach ( $options['custom_urls'] as $lang => $weglot_urls ) :
35
  ?>
36
 
37
  <h3><?php esc_html_e( 'Lang : ', 'weglot' ); ?><?php echo esc_html( $lang ); ?></h3>
46
  <div style="flex:1;"></div>
47
  </div>
48
  <?php
49
+ if ( ! empty( $weglot_urls ) ) :
50
+ foreach ( $weglot_urls as $key => $value ) :
51
  $key_generate = sprintf( '%s-%s-%s', $lang, $key, $value );
52
  ?>
53
  <div style="display:flex;" id="<?php echo esc_attr( $key_generate ); ?>">
102
  <hr />
103
  <p><span class="dashicons dashicons-trash"></span> <a href="<?php echo esc_url( $url_reset_all_custom_urls ); ?>" class="reset-all-custom-urls" style="color: #dc3232;"><?php esc_html_e( 'Reset all Weglot custom URLs', 'weglot' ); ?></a></p>
104
  <hr />
105
+ <?php elseif ( empty( $_GET['reset-all-custom-urls'] ) ) : // phpcs:ignore ?>
106
  <div class="error notice">
107
  <p><?php esc_html_e( 'No custom URL found.', 'weglot' ); ?></p>
108
  </div>
templates/admin/pages/tabs/settings.php CHANGED
@@ -5,29 +5,28 @@ if ( ! defined( 'ABSPATH' ) ) {
5
  }
6
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
7
 
8
- $options_available = apply_filters( 'weglot_tabs_admin_options_available', [
9
- 'api_key_private' => [
10
- 'key' => 'api_key_private',
11
- 'label' => __( 'API Key', 'weglot' ),
12
- 'description' => sprintf( esc_html__( 'Log in to %1$sWeglot%2$s to get your API key.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/register-wordpress">', '</a>' ),
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' => sprintf ( esc_html__( 'Choose languages you want to translate into. Supported languages can be found %1$shere%2$s.', 'weglot' ), '<a target="_blank" href="https://weglot.com/documentation/available-languages/">', '</a>' ),
23
- ],
24
- ] );
 
 
25
 
26
- $languages = $this->language_services->get_languages_available( [
27
- 'sort' => true,
28
- ] );
29
- $user_info = $this->user_api_services->get_user_info();
30
- $plans = $this->user_api_services->get_plans();
31
 
32
  ?>
33
 
@@ -52,11 +51,13 @@ $plans = $this->user_api_services->get_plans();
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'] ) {
56
- ?>
57
- <p class="description"><?php echo esc_html_e( 'If you don\'t have an account, you can create one in 20 seconds !', 'weglot' ); ?></p>
58
  <?php
59
- } ?>
 
 
 
 
 
60
  </td>
61
  </tr>
62
  <tr valign="top">
@@ -72,14 +73,21 @@ $plans = $this->user_api_services->get_plans();
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>
82
- <?php endforeach; ?>
 
 
 
83
  </select>
84
  </td>
85
  </tr>
@@ -100,25 +108,22 @@ $plans = $this->user_api_services->get_plans();
100
  multiple="true"
101
  required
102
  >
103
- <?php foreach ( $this->options[ $options_available['languages']['key'] ] as $language ) :
104
-
105
- $language = $languages[ $language ];
106
- if( ! $language ) {
107
- continue;
108
- }
109
- ?>
110
  <option
111
- value="<?php echo esc_attr( $language->getIso639() ); ?>"
112
- selected="selected"
113
- >
114
  <?php echo esc_html( $language->getLocalName() ); ?>
115
  </option>
116
  <?php endforeach; ?>
117
 
118
  <?php foreach ( $languages as $language ) : ?>
119
  <option
120
- value="<?php echo esc_attr( $language->getIso639() ); ?>"
121
- <?php selected( true, in_array( $language->getIso639(), $this->options[ $options_available['languages']['key'] ], true ) ); ?>
122
  >
123
  <?php echo esc_html( $language->getLocalName() ); ?>
124
  </option>
@@ -144,7 +149,7 @@ $plans = $this->user_api_services->get_plans();
144
  ?>
145
  <p class="description">
146
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
147
- <?php echo sprintf( esc_html__( 'On the Business plan, you can choose five languages. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
148
  </p>
149
  <?php
150
  }
5
  }
6
  use WeglotWP\Helpers\Helper_Tabs_Admin_Weglot;
7
 
8
+ $options_available = apply_filters(
9
+ 'weglot_tabs_admin_options_available', [
10
+ 'api_key_private' => [
11
+ 'key' => 'api_key_private',
12
+ 'label' => __( 'API Key', 'weglot' ),
13
+ 'description' => sprintf( esc_html__( 'Log in to %1$sWeglot%2$s to get your API key.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/register-wordpress">', '</a>' ),
14
+ ],
15
+ 'language_from' => [
16
+ 'key' => 'original_language',
17
+ 'label' => __( 'Original language', 'weglot' ),
18
+ 'description' => 'What is the original (current) language of your website?',
19
+ ],
20
+ 'languages' => [
21
+ 'key' => 'destination_language',
22
+ 'label' => __( 'Destination languages', 'weglot' ),
23
+ 'description' => sprintf( esc_html__( 'Choose languages you want to translate into. Supported languages can be found %1$shere%2$s.', 'weglot' ), '<a target="_blank" href="https://weglot.com/documentation/available-languages/">', '</a>' ),
24
+ ],
25
+ ]
26
+ );
27
 
28
+ $user_info = $this->user_api_services->get_user_info();
29
+ $plans = $this->user_api_services->get_plans();
 
 
 
30
 
31
  ?>
32
 
51
  value="<?php echo esc_attr( $this->options[ $options_available['api_key_private']['key'] ] ); ?>"
52
  >
53
  <br>
 
 
 
54
  <?php
55
+ if ( $this->options['has_first_settings'] ) {
56
+ ?>
57
+ <p class="description"><?php echo esc_html_e( 'If you don\'t have an account, you can create one in 20 seconds !', 'weglot' ); ?></p>
58
+ <?php
59
+ }
60
+ ?>
61
  </td>
62
  </tr>
63
  <tr valign="top">
73
  name="<?php echo esc_attr( sprintf( '%s[%s]', WEGLOT_SLUG, 'language_from' ) ); ?>"
74
  id="<?php echo esc_attr( $options_available['language_from']['key'] ); ?>"
75
  >
76
+ <?php
77
+ $original_languages_possible = $this->language_services->get_languages_available( [ 'sort' => true ] );
78
+ foreach ( $original_languages_possible as $language ) {
79
+ if ( $language->getInternalCode() !== 'br' ) {
80
+ ?>
81
  <option
82
+ value="<?php echo esc_attr( $language->getInternalCode() ); ?>"
83
+ <?php selected( $language->getInternalCode(), $this->options[ $options_available['language_from']['key'] ] ); ?>
84
  >
85
  <?php esc_html_e( $language->getEnglishName(), 'weglot'); //phpcs:ignore ?>
86
  </option>
87
+ <?php
88
+ }
89
+ }
90
+ ?>
91
  </select>
92
  </td>
93
  </tr>
108
  multiple="true"
109
  required
110
  >
111
+ <?php
112
+ $languages = $this->language_services->get_all_languages();
113
+ $destination_languages = $this->language_services->get_destination_languages( true );
114
+ foreach ( $destination_languages as $language ) :
115
+ ?>
 
 
116
  <option
117
+ value="<?php echo esc_attr( $language->getInternalCode() ); ?>"
118
+ selected="selected">
 
119
  <?php echo esc_html( $language->getLocalName() ); ?>
120
  </option>
121
  <?php endforeach; ?>
122
 
123
  <?php foreach ( $languages as $language ) : ?>
124
  <option
125
+ value="<?php echo esc_attr( $language->getInternalCode() ); ?>"
126
+ <?php selected( true, in_array( $language, $destination_languages, true ) ); ?>
127
  >
128
  <?php echo esc_html( $language->getLocalName() ); ?>
129
  </option>
149
  ?>
150
  <p class="description">
151
  <?php // translators: 1 HTML Tag, 2 HTML Tag ?>
152
+ <?php echo sprintf( esc_html__( 'On the Business plan, you can choose 3 languages. If you need more, please %1$supgrade your plan%2$s.', 'weglot' ), '<a target="_blank" href="https://dashboard.weglot.com/billing/upgrade">', '</a>' ); ?>
153
  </p>
154
  <?php
155
  }
templates/admin/pages/tabs/status.php CHANGED
@@ -120,12 +120,12 @@ $options = weglot_get_options();
120
  <tbody>
121
  <tr>
122
  <td><?php esc_html_e( 'Original Language', 'weglot' ); ?></td>
123
- <td><?php echo esc_attr( weglot_get_original_language() ); ?></td>
124
  </tr>
125
  <tr>
126
  <td><?php esc_html_e( 'Destination Language', 'weglot' ); ?></td>
127
  <td>
128
- <?php foreach ( weglot_get_destination_language() as $language ) : ?>
129
  <?php echo esc_attr( sprintf( '%s - ', $language ) ); ?>
130
  <?php endforeach; ?>
131
  </td>
@@ -133,8 +133,9 @@ $options = weglot_get_options();
133
  <tr>
134
  <td><?php esc_html_e( 'Exclude URLs', 'weglot' ); ?></td>
135
  <td>
136
- <?php if ( ! empty($options[ 'exclude_urls' ] ) ):
137
- foreach ( $options[ 'exclude_urls' ] as $type => $exclude_url ) :
 
138
  if ( empty( $exclude_url['type'] ) || empty( $exclude_url['value'] ) ) {
139
  continue;
140
  }
@@ -142,21 +143,22 @@ $options = weglot_get_options();
142
  echo esc_html( $exclude_url['type'] . ' - ' . $exclude_url['value'] ) . '<br/>';
143
 
144
  endforeach;
145
- else:
146
  esc_html_e( 'Empty', 'weglot' );
147
- endif; ?>
 
148
  </td>
149
 
150
  </tr>
151
  <tr>
152
  <td><?php esc_html_e( 'Exclude Blocks', 'weglot' ); ?></td>
153
- <td><?php echo esc_attr( implode( $options[ 'exclude_blocks' ], ' - ' ) ); ?></td>
154
  </tr>
155
  </tbody>
156
  </table>
157
  <br />
158
  <div class="widefat">
159
  <h2><?php esc_html_e( 'Custom URLS', 'weglot' ); ?></h2>
160
- <pre><?php var_export( $options['custom_urls'] ); ?></pre>
161
  </div>
162
  </div>
120
  <tbody>
121
  <tr>
122
  <td><?php esc_html_e( 'Original Language', 'weglot' ); ?></td>
123
+ <td><?php echo esc_attr( $this->language_services->get_original_language()->getInternalCode() ); ?></td>
124
  </tr>
125
  <tr>
126
  <td><?php esc_html_e( 'Destination Language', 'weglot' ); ?></td>
127
  <td>
128
+ <?php foreach ( $this->language_services->get_destination_languages_external( true ) as $language ) : ?>
129
  <?php echo esc_attr( sprintf( '%s - ', $language ) ); ?>
130
  <?php endforeach; ?>
131
  </td>
133
  <tr>
134
  <td><?php esc_html_e( 'Exclude URLs', 'weglot' ); ?></td>
135
  <td>
136
+ <?php
137
+ if ( ! empty( $options['exclude_urls'] ) ) :
138
+ foreach ( $options['exclude_urls'] as $t => $exclude_url ) :
139
  if ( empty( $exclude_url['type'] ) || empty( $exclude_url['value'] ) ) {
140
  continue;
141
  }
143
  echo esc_html( $exclude_url['type'] . ' - ' . $exclude_url['value'] ) . '<br/>';
144
 
145
  endforeach;
146
+ else :
147
  esc_html_e( 'Empty', 'weglot' );
148
+ endif;
149
+ ?>
150
  </td>
151
 
152
  </tr>
153
  <tr>
154
  <td><?php esc_html_e( 'Exclude Blocks', 'weglot' ); ?></td>
155
+ <td><?php echo esc_attr( implode( $options['exclude_blocks'], ' - ' ) ); ?></td>
156
  </tr>
157
  </tbody>
158
  </table>
159
  <br />
160
  <div class="widefat">
161
  <h2><?php esc_html_e( 'Custom URLS', 'weglot' ); ?></h2>
162
+ <pre><?php var_export( $options['custom_urls'] ); // phpcs:ignore ?></pre>
163
  </div>
164
  </div>
templates/admin/pages/tabs/support.php CHANGED
@@ -19,8 +19,8 @@ $options_available = [
19
  <hr>
20
 
21
  <table class="form-table">
22
- <tbody>
23
- <?php if ($this->wc_active_services->is_active()): ?>
24
  <tr valign="top">
25
  <th scope="row" class="titledesc">
26
  <label for="<?php echo esc_attr( $options_available['active_wc_reload']['key'] ); ?>">
19
  <hr>
20
 
21
  <table class="form-table">
22
+ <tbody>
23
+ <?php if ( $this->wc_active_services->is_active() ) : ?>
24
  <tr valign="top">
25
  <th scope="row" class="titledesc">
26
  <label for="<?php echo esc_attr( $options_available['active_wc_reload']['key'] ); ?>">
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInitae314e18789233c1e13de8010f8b5e1a::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitb3218cce4e3202ba135172f06516602f::getLoader();
vendor/composer/ClassLoader.php CHANGED
@@ -37,8 +37,8 @@ namespace Composer\Autoload;
37
  *
38
  * @author Fabien Potencier <fabien@symfony.com>
39
  * @author Jordi Boggiano <j.boggiano@seld.be>
40
- * @see http://www.php-fig.org/psr/psr-0/
41
- * @see http://www.php-fig.org/psr/psr-4/
42
  */
43
  class ClassLoader
44
  {
@@ -60,7 +60,7 @@ class ClassLoader
60
  public function getPrefixes()
61
  {
62
  if (!empty($this->prefixesPsr0)) {
63
- return call_user_func_array('array_merge', $this->prefixesPsr0);
64
  }
65
 
66
  return array();
37
  *
38
  * @author Fabien Potencier <fabien@symfony.com>
39
  * @author Jordi Boggiano <j.boggiano@seld.be>
40
+ * @see https://www.php-fig.org/psr/psr-0/
41
+ * @see https://www.php-fig.org/psr/psr-4/
42
  */
43
  class ClassLoader
44
  {
60
  public function getPrefixes()
61
  {
62
  if (!empty($this->prefixesPsr0)) {
63
+ return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
64
  }
65
 
66
  return array();
vendor/composer/InstalledVersions.php ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+ namespace Composer;
14
+
15
+ use Composer\Semver\VersionParser;
16
+
17
+
18
+
19
+
20
+
21
+
22
+ class InstalledVersions
23
+ {
24
+ private static $installed = array (
25
+ 'root' =>
26
+ array (
27
+ 'pretty_version' => 'dev-master',
28
+ 'version' => 'dev-master',
29
+ 'aliases' =>
30
+ array (
31
+ ),
32
+ 'reference' => 'f3c6043c0974f05066db495501f0ec4f30395800',
33
+ 'name' => 'weglot/translate-wordpress',
34
+ ),
35
+ 'versions' =>
36
+ array (
37
+ 'gmulti/morphism-php' =>
38
+ array (
39
+ 'pretty_version' => '0.3.0',
40
+ 'version' => '0.3.0.0',
41
+ 'aliases' =>
42
+ array (
43
+ ),
44
+ 'reference' => '0b4cc4e604452a724124b8d342635c4b0b0e9809',
45
+ ),
46
+ 'psr/cache' =>
47
+ array (
48
+ 'pretty_version' => '1.0.1',
49
+ 'version' => '1.0.1.0',
50
+ 'aliases' =>
51
+ array (
52
+ ),
53
+ 'reference' => 'd11b50ad223250cf17b86e38383413f5a6764bf8',
54
+ ),
55
+ 'weglot/simplehtmldom' =>
56
+ array (
57
+ 'pretty_version' => '0.5',
58
+ 'version' => '0.5.0.0',
59
+ 'aliases' =>
60
+ array (
61
+ ),
62
+ 'reference' => 'ae2c353a18aa421703824838e5d921b3de5388fd',
63
+ ),
64
+ 'weglot/translate-wordpress' =>
65
+ array (
66
+ 'pretty_version' => 'dev-master',
67
+ 'version' => 'dev-master',
68
+ 'aliases' =>
69
+ array (
70
+ ),
71
+ 'reference' => 'f3c6043c0974f05066db495501f0ec4f30395800',
72
+ ),
73
+ 'weglot/translation-definitions' =>
74
+ array (
75
+ 'pretty_version' => 'v2.3.2',
76
+ 'version' => '2.3.2.0',
77
+ 'aliases' =>
78
+ array (
79
+ ),
80
+ 'reference' => '3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6',
81
+ ),
82
+ 'weglot/weglot-php' =>
83
+ array (
84
+ 'pretty_version' => '1.1.1',
85
+ 'version' => '1.1.1.0',
86
+ 'aliases' =>
87
+ array (
88
+ ),
89
+ 'reference' => '9dab3aec1d314638f0890fd451d7eb328fce8398',
90
+ ),
91
+ ),
92
+ );
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ public static function getInstalledPackages()
101
+ {
102
+ return array_keys(self::$installed['versions']);
103
+ }
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+ public static function isInstalled($packageName)
114
+ {
115
+ return isset(self::$installed['versions'][$packageName]);
116
+ }
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ public static function satisfies(VersionParser $parser, $packageName, $constraint)
132
+ {
133
+ $constraint = $parser->parseConstraints($constraint);
134
+ $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
135
+
136
+ return $provided->matches($constraint);
137
+ }
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ public static function getVersionRanges($packageName)
149
+ {
150
+ if (!isset(self::$installed['versions'][$packageName])) {
151
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
152
+ }
153
+
154
+ $ranges = array();
155
+ if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
156
+ $ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
157
+ }
158
+ if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
159
+ $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
160
+ }
161
+ if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
162
+ $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
163
+ }
164
+ if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
165
+ $ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
166
+ }
167
+
168
+ return implode(' || ', $ranges);
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+ public static function getVersion($packageName)
176
+ {
177
+ if (!isset(self::$installed['versions'][$packageName])) {
178
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
179
+ }
180
+
181
+ if (!isset(self::$installed['versions'][$packageName]['version'])) {
182
+ return null;
183
+ }
184
+
185
+ return self::$installed['versions'][$packageName]['version'];
186
+ }
187
+
188
+
189
+
190
+
191
+
192
+ public static function getPrettyVersion($packageName)
193
+ {
194
+ if (!isset(self::$installed['versions'][$packageName])) {
195
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
196
+ }
197
+
198
+ if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
199
+ return null;
200
+ }
201
+
202
+ return self::$installed['versions'][$packageName]['pretty_version'];
203
+ }
204
+
205
+
206
+
207
+
208
+
209
+ public static function getReference($packageName)
210
+ {
211
+ if (!isset(self::$installed['versions'][$packageName])) {
212
+ throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
213
+ }
214
+
215
+ if (!isset(self::$installed['versions'][$packageName]['reference'])) {
216
+ return null;
217
+ }
218
+
219
+ return self::$installed['versions'][$packageName]['reference'];
220
+ }
221
+
222
+
223
+
224
+
225
+
226
+ public static function getRootPackage()
227
+ {
228
+ return self::$installed['root'];
229
+ }
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+ public static function getRawData()
238
+ {
239
+ return self::$installed;
240
+ }
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+ public static function reload($data)
261
+ {
262
+ self::$installed = $data;
263
+ }
264
+ }
vendor/composer/autoload_classmap.php CHANGED
@@ -6,5 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
 
9
  'Weglot\\TranslationDefinitions' => $vendorDir . '/weglot/translation-definitions/index.php',
10
  );
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
+ 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10
  'Weglot\\TranslationDefinitions' => $vendorDir . '/weglot/translation-definitions/index.php',
11
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitae314e18789233c1e13de8010f8b5e1a
6
  {
7
  private static $loader;
8
 
@@ -13,21 +13,26 @@ class ComposerAutoloaderInitae314e18789233c1e13de8010f8b5e1a
13
  }
14
  }
15
 
 
 
 
16
  public static function getLoader()
17
  {
18
  if (null !== self::$loader) {
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInitae314e18789233c1e13de8010f8b5e1a', 'loadClassLoader'), true, true);
 
 
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInitae314e18789233c1e13de8010f8b5e1a', '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\ComposerStaticInitae314e18789233c1e13de8010f8b5e1a::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
@@ -48,19 +53,19 @@ class ComposerAutoloaderInitae314e18789233c1e13de8010f8b5e1a
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInitae314e18789233c1e13de8010f8b5e1a::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequireae314e18789233c1e13de8010f8b5e1a($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
- function composerRequireae314e18789233c1e13de8010f8b5e1a($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 ComposerAutoloaderInitb3218cce4e3202ba135172f06516602f
6
  {
7
  private static $loader;
8
 
13
  }
14
  }
15
 
16
+ /**
17
+ * @return \Composer\Autoload\ClassLoader
18
+ */
19
  public static function getLoader()
20
  {
21
  if (null !== self::$loader) {
22
  return self::$loader;
23
  }
24
 
25
+ require __DIR__ . '/platform_check.php';
26
+
27
+ spl_autoload_register(array('ComposerAutoloaderInitb3218cce4e3202ba135172f06516602f', 'loadClassLoader'), true, true);
28
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
29
+ spl_autoload_unregister(array('ComposerAutoloaderInitb3218cce4e3202ba135172f06516602f', 'loadClassLoader'));
30
 
31
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32
  if ($useStaticLoader) {
33
+ require __DIR__ . '/autoload_static.php';
34
 
35
+ call_user_func(\Composer\Autoload\ComposerStaticInitb3218cce4e3202ba135172f06516602f::getInitializer($loader));
36
  } else {
37
  $map = require __DIR__ . '/autoload_namespaces.php';
38
  foreach ($map as $namespace => $path) {
53
  $loader->register(true);
54
 
55
  if ($useStaticLoader) {
56
+ $includeFiles = Composer\Autoload\ComposerStaticInitb3218cce4e3202ba135172f06516602f::$files;
57
  } else {
58
  $includeFiles = require __DIR__ . '/autoload_files.php';
59
  }
60
  foreach ($includeFiles as $fileIdentifier => $file) {
61
+ composerRequireb3218cce4e3202ba135172f06516602f($fileIdentifier, $file);
62
  }
63
 
64
  return $loader;
65
  }
66
  }
67
 
68
+ function composerRequireb3218cce4e3202ba135172f06516602f($fileIdentifier, $file)
69
  {
70
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInitae314e18789233c1e13de8010f8b5e1a
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
@@ -51,16 +51,17 @@ class ComposerStaticInitae314e18789233c1e13de8010f8b5e1a
51
  );
52
 
53
  public static $classMap = array (
 
54
  'Weglot\\TranslationDefinitions' => __DIR__ . '/..' . '/weglot/translation-definitions/index.php',
55
  );
56
 
57
  public static function getInitializer(ClassLoader $loader)
58
  {
59
  return \Closure::bind(function () use ($loader) {
60
- $loader->prefixLengthsPsr4 = ComposerStaticInitae314e18789233c1e13de8010f8b5e1a::$prefixLengthsPsr4;
61
- $loader->prefixDirsPsr4 = ComposerStaticInitae314e18789233c1e13de8010f8b5e1a::$prefixDirsPsr4;
62
- $loader->prefixesPsr0 = ComposerStaticInitae314e18789233c1e13de8010f8b5e1a::$prefixesPsr0;
63
- $loader->classMap = ComposerStaticInitae314e18789233c1e13de8010f8b5e1a::$classMap;
64
 
65
  }, null, ClassLoader::class);
66
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitb3218cce4e3202ba135172f06516602f
8
  {
9
  public static $files = array (
10
  '6c200413eed8aeea54dbaf934a31b127' => __DIR__ . '/..' . '/weglot/simplehtmldom/src/simple_html_dom.php',
51
  );
52
 
53
  public static $classMap = array (
54
+ 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
55
  'Weglot\\TranslationDefinitions' => __DIR__ . '/..' . '/weglot/translation-definitions/index.php',
56
  );
57
 
58
  public static function getInitializer(ClassLoader $loader)
59
  {
60
  return \Closure::bind(function () use ($loader) {
61
+ $loader->prefixLengthsPsr4 = ComposerStaticInitb3218cce4e3202ba135172f06516602f::$prefixLengthsPsr4;
62
+ $loader->prefixDirsPsr4 = ComposerStaticInitb3218cce4e3202ba135172f06516602f::$prefixDirsPsr4;
63
+ $loader->prefixesPsr0 = ComposerStaticInitb3218cce4e3202ba135172f06516602f::$prefixesPsr0;
64
+ $loader->classMap = ComposerStaticInitb3218cce4e3202ba135172f06516602f::$classMap;
65
 
66
  }, null, ClassLoader::class);
67
  }
vendor/composer/installed.json CHANGED
@@ -1,236 +1,265 @@
1
- [
2
- {
3
- "name": "gmulti/morphism-php",
4
- "version": "0.3.0",
5
- "version_normalized": "0.3.0.0",
6
- "source": {
7
- "type": "git",
8
- "url": "https://github.com/Gmulti/morphism-php.git",
9
- "reference": "0b4cc4e604452a724124b8d342635c4b0b0e9809"
10
- },
11
- "dist": {
12
- "type": "zip",
13
- "url": "https://api.github.com/repos/Gmulti/morphism-php/zipball/0b4cc4e604452a724124b8d342635c4b0b0e9809",
14
- "reference": "0b4cc4e604452a724124b8d342635c4b0b0e9809",
15
- "shasum": ""
16
- },
17
- "require-dev": {
18
- "phpunit/phpunit": "^6.5"
19
- },
20
- "time": "2017-12-23T20:54:39+00:00",
21
- "type": "project",
22
- "installation-source": "dist",
23
- "autoload": {
24
- "psr-4": {
25
- "Morphism\\": "lib/"
26
- }
27
- },
28
- "notification-url": "https://packagist.org/downloads/",
29
- "license": [
30
- "MIT"
31
- ],
32
- "authors": [
33
- {
34
- "name": "Thomas DENEULIN",
35
- "email": "thomas@delipress.io"
36
- }
37
- ]
38
- },
39
- {
40
- "name": "psr/cache",
41
- "version": "1.0.1",
42
- "version_normalized": "1.0.1.0",
43
- "source": {
44
- "type": "git",
45
- "url": "https://github.com/php-fig/cache.git",
46
- "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
47
- },
48
- "dist": {
49
- "type": "zip",
50
- "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
51
- "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
52
- "shasum": ""
53
- },
54
- "require": {
55
- "php": ">=5.3.0"
56
- },
57
- "time": "2016-08-06T20:24:11+00:00",
58
- "type": "library",
59
- "extra": {
60
- "branch-alias": {
61
- "dev-master": "1.0.x-dev"
62
- }
63
- },
64
- "installation-source": "dist",
65
- "autoload": {
66
- "psr-4": {
67
- "Psr\\Cache\\": "src/"
68
- }
69
- },
70
- "notification-url": "https://packagist.org/downloads/",
71
- "license": [
72
- "MIT"
73
- ],
74
- "authors": [
75
- {
76
- "name": "PHP-FIG",
77
- "homepage": "http://www.php-fig.org/"
78
- }
79
- ],
80
- "description": "Common interface for caching libraries",
81
- "keywords": [
82
- "cache",
83
- "psr",
84
- "psr-6"
85
- ]
86
- },
87
- {
88
- "name": "weglot/simplehtmldom",
89
- "version": "0.5",
90
- "version_normalized": "0.5.0.0",
91
- "source": {
92
- "type": "git",
93
- "url": "https://github.com/weglot/simple_html_dom.git",
94
- "reference": "ae2c353a18aa421703824838e5d921b3de5388fd"
95
- },
96
- "dist": {
97
- "type": "zip",
98
- "url": "https://api.github.com/repos/weglot/simple_html_dom/zipball/ae2c353a18aa421703824838e5d921b3de5388fd",
99
- "reference": "ae2c353a18aa421703824838e5d921b3de5388fd",
100
- "shasum": ""
101
- },
102
- "require": {
103
- "php": ">=5.3.0"
104
- },
105
- "time": "2019-01-03T10:18:36+00:00",
106
- "type": "library",
107
- "installation-source": "dist",
108
- "autoload": {
109
- "psr-0": {
110
- "WGSimpleHtmlDom": "src/"
111
- },
112
- "files": [
113
- "src/simple_html_dom.php"
114
- ]
115
- },
116
- "notification-url": "https://packagist.org/downloads/",
117
- "license": [
118
- "MIT"
119
- ],
120
- "authors": [
121
- {
122
- "name": "S.C. Chen",
123
- "email": "me578022@gmail.com"
124
- }
125
- ],
126
- "description": "Composer package that gives you access to and (unlike all the others at this time) autoloads S.C. Chen's PHP Simple HTML DOM Parser Library",
127
- "homepage": "http://simplehtmldom.sourceforge.net/",
128
- "keywords": [
129
- "Simple",
130
- "dom",
131
- "html"
132
- ]
133
- },
134
- {
135
- "name": "weglot/translation-definitions",
136
- "version": "v2.3.2",
137
- "version_normalized": "2.3.2.0",
138
- "source": {
139
- "type": "git",
140
- "url": "https://github.com/weglot/weglot-translation-definitions.git",
141
- "reference": "3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6"
142
- },
143
- "dist": {
144
- "type": "zip",
145
- "url": "https://api.github.com/repos/weglot/weglot-translation-definitions/zipball/3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6",
146
- "reference": "3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6",
147
- "shasum": ""
148
- },
149
- "require": {
150
- "php": ">=5"
151
- },
152
- "time": "2020-09-09T14:22:43+00:00",
153
- "type": "library",
154
- "installation-source": "dist",
155
- "autoload": {
156
- "classmap": [
157
- "index.php"
158
- ]
159
- },
160
- "notification-url": "https://packagist.org/downloads/",
161
- "license": [
162
- "MIT"
163
- ],
164
- "authors": [
165
- {
166
- "name": "Mehdi Rejraji",
167
- "email": "mehdi@weglot.com"
168
- }
169
- ],
170
- "description": "Weglot's shared definitions"
171
- },
172
- {
173
- "name": "weglot/weglot-php",
174
- "version": "1.0.7",
175
- "version_normalized": "1.0.7.0",
176
- "source": {
177
- "type": "git",
178
- "url": "https://github.com/weglot/weglot-php.git",
179
- "reference": "9013839325cfb6c45f705c556354ba8faac17a7d"
180
- },
181
- "dist": {
182
- "type": "zip",
183
- "url": "https://api.github.com/repos/weglot/weglot-php/zipball/9013839325cfb6c45f705c556354ba8faac17a7d",
184
- "reference": "9013839325cfb6c45f705c556354ba8faac17a7d",
185
- "shasum": ""
186
  },
187
- "require": {
188
- "php": ">=5.4",
189
- "psr/cache": "^1.0",
190
- "weglot/simplehtmldom": "^0.5",
191
- "weglot/translation-definitions": "^2.0"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  },
193
- "require-dev": {
194
- "codeception/codeception": "^2.4",
195
- "vlucas/phpdotenv": "^2.4"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  },
197
- "time": "2020-08-12T15:45:39+00:00",
198
- "type": "library",
199
- "installation-source": "dist",
200
- "autoload": {
201
- "psr-4": {
202
- "Weglot\\": "src/"
203
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  },
205
- "notification-url": "https://packagist.org/downloads/",
206
- "license": [
207
- "MIT"
208
- ],
209
- "authors": [
210
- {
211
- "name": "Baptiste Leduc",
212
- "email": "baptiste@weglot.com",
213
- "homepage": "https://baptiste-leduc.now.sh/",
214
- "role": "Developer"
215
- },
216
- {
217
- "name": "Thomas Deneulin",
218
- "email": "thomas@weglot.com",
219
- "role": "Review"
220
- }
221
- ],
222
- "description": "PHP library for the Weglot API",
223
- "homepage": "https://weglot.com/",
224
- "keywords": [
225
- "Weglot",
226
- "i18n",
227
- "languages",
228
- "localization",
229
- "php",
230
- "translate",
231
- "translation",
232
- "translator",
233
- "weglot-library"
234
- ]
235
- }
236
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "packages": [
3
+ {
4
+ "name": "gmulti/morphism-php",
5
+ "version": "0.3.0",
6
+ "version_normalized": "0.3.0.0",
7
+ "source": {
8
+ "type": "git",
9
+ "url": "https://github.com/Gmulti/morphism-php.git",
10
+ "reference": "0b4cc4e604452a724124b8d342635c4b0b0e9809"
11
+ },
12
+ "dist": {
13
+ "type": "zip",
14
+ "url": "https://api.github.com/repos/Gmulti/morphism-php/zipball/0b4cc4e604452a724124b8d342635c4b0b0e9809",
15
+ "reference": "0b4cc4e604452a724124b8d342635c4b0b0e9809",
16
+ "shasum": ""
17
+ },
18
+ "require-dev": {
19
+ "phpunit/phpunit": "^6.5"
20
+ },
21
+ "time": "2017-12-23T20:54:39+00:00",
22
+ "type": "project",
23
+ "installation-source": "dist",
24
+ "autoload": {
25
+ "psr-4": {
26
+ "Morphism\\": "lib/"
27
+ }
28
+ },
29
+ "notification-url": "https://packagist.org/downloads/",
30
+ "license": [
31
+ "MIT"
32
+ ],
33
+ "authors": [
34
+ {
35
+ "name": "Thomas DENEULIN",
36
+ "email": "thomas@delipress.io"
37
+ }
38
+ ],
39
+ "support": {
40
+ "issues": "https://github.com/Gmulti/morphism-php/issues",
41
+ "source": "https://github.com/Gmulti/morphism-php/tree/0.3.0"
42
+ },
43
+ "install-path": "../gmulti/morphism-php"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  },
45
+ {
46
+ "name": "psr/cache",
47
+ "version": "1.0.1",
48
+ "version_normalized": "1.0.1.0",
49
+ "source": {
50
+ "type": "git",
51
+ "url": "https://github.com/php-fig/cache.git",
52
+ "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
53
+ },
54
+ "dist": {
55
+ "type": "zip",
56
+ "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
57
+ "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
58
+ "shasum": ""
59
+ },
60
+ "require": {
61
+ "php": ">=5.3.0"
62
+ },
63
+ "time": "2016-08-06T20:24:11+00:00",
64
+ "type": "library",
65
+ "extra": {
66
+ "branch-alias": {
67
+ "dev-master": "1.0.x-dev"
68
+ }
69
+ },
70
+ "installation-source": "dist",
71
+ "autoload": {
72
+ "psr-4": {
73
+ "Psr\\Cache\\": "src/"
74
+ }
75
+ },
76
+ "notification-url": "https://packagist.org/downloads/",
77
+ "license": [
78
+ "MIT"
79
+ ],
80
+ "authors": [
81
+ {
82
+ "name": "PHP-FIG",
83
+ "homepage": "http://www.php-fig.org/"
84
+ }
85
+ ],
86
+ "description": "Common interface for caching libraries",
87
+ "keywords": [
88
+ "cache",
89
+ "psr",
90
+ "psr-6"
91
+ ],
92
+ "support": {
93
+ "source": "https://github.com/php-fig/cache/tree/master"
94
+ },
95
+ "install-path": "../psr/cache"
96
  },
97
+ {
98
+ "name": "weglot/simplehtmldom",
99
+ "version": "0.5",
100
+ "version_normalized": "0.5.0.0",
101
+ "source": {
102
+ "type": "git",
103
+ "url": "https://github.com/weglot/simple_html_dom.git",
104
+ "reference": "ae2c353a18aa421703824838e5d921b3de5388fd"
105
+ },
106
+ "dist": {
107
+ "type": "zip",
108
+ "url": "https://api.github.com/repos/weglot/simple_html_dom/zipball/ae2c353a18aa421703824838e5d921b3de5388fd",
109
+ "reference": "ae2c353a18aa421703824838e5d921b3de5388fd",
110
+ "shasum": ""
111
+ },
112
+ "require": {
113
+ "php": ">=5.3.0"
114
+ },
115
+ "time": "2019-01-03T10:18:36+00:00",
116
+ "type": "library",
117
+ "installation-source": "dist",
118
+ "autoload": {
119
+ "psr-0": {
120
+ "WGSimpleHtmlDom": "src/"
121
+ },
122
+ "files": [
123
+ "src/simple_html_dom.php"
124
+ ]
125
+ },
126
+ "notification-url": "https://packagist.org/downloads/",
127
+ "license": [
128
+ "MIT"
129
+ ],
130
+ "authors": [
131
+ {
132
+ "name": "S.C. Chen",
133
+ "email": "me578022@gmail.com"
134
+ }
135
+ ],
136
+ "description": "Composer package that gives you access to and (unlike all the others at this time) autoloads S.C. Chen's PHP Simple HTML DOM Parser Library",
137
+ "homepage": "http://simplehtmldom.sourceforge.net/",
138
+ "keywords": [
139
+ "Simple",
140
+ "dom",
141
+ "html"
142
+ ],
143
+ "support": {
144
+ "source": "https://github.com/weglot/simple_html_dom/tree/master"
145
+ },
146
+ "install-path": "../weglot/simplehtmldom"
147
  },
148
+ {
149
+ "name": "weglot/translation-definitions",
150
+ "version": "v2.3.2",
151
+ "version_normalized": "2.3.2.0",
152
+ "source": {
153
+ "type": "git",
154
+ "url": "https://github.com/weglot/weglot-translation-definitions.git",
155
+ "reference": "3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6"
156
+ },
157
+ "dist": {
158
+ "type": "zip",
159
+ "url": "https://api.github.com/repos/weglot/weglot-translation-definitions/zipball/3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6",
160
+ "reference": "3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6",
161
+ "shasum": ""
162
+ },
163
+ "require": {
164
+ "php": ">=5"
165
+ },
166
+ "time": "2020-09-09T14:22:43+00:00",
167
+ "type": "library",
168
+ "installation-source": "dist",
169
+ "autoload": {
170
+ "classmap": [
171
+ "index.php"
172
+ ]
173
+ },
174
+ "notification-url": "https://packagist.org/downloads/",
175
+ "license": [
176
+ "MIT"
177
+ ],
178
+ "authors": [
179
+ {
180
+ "name": "Mehdi Rejraji",
181
+ "email": "mehdi@weglot.com"
182
+ }
183
+ ],
184
+ "description": "Weglot's shared definitions",
185
+ "support": {
186
+ "issues": "https://github.com/weglot/weglot-translation-definitions/issues",
187
+ "source": "https://github.com/weglot/weglot-translation-definitions/tree/v2.3.2"
188
+ },
189
+ "install-path": "../weglot/translation-definitions"
190
  },
191
+ {
192
+ "name": "weglot/weglot-php",
193
+ "version": "1.1.1",
194
+ "version_normalized": "1.1.1.0",
195
+ "source": {
196
+ "type": "git",
197
+ "url": "https://github.com/weglot/weglot-php.git",
198
+ "reference": "9dab3aec1d314638f0890fd451d7eb328fce8398"
199
+ },
200
+ "dist": {
201
+ "type": "zip",
202
+ "url": "https://api.github.com/repos/weglot/weglot-php/zipball/9dab3aec1d314638f0890fd451d7eb328fce8398",
203
+ "reference": "9dab3aec1d314638f0890fd451d7eb328fce8398",
204
+ "shasum": ""
205
+ },
206
+ "require": {
207
+ "php": ">=5.4",
208
+ "psr/cache": "^1.0",
209
+ "weglot/simplehtmldom": "^0.5",
210
+ "weglot/translation-definitions": "^2.0"
211
+ },
212
+ "require-dev": {
213
+ "codeception/codeception": "^2.4",
214
+ "vlucas/phpdotenv": "^2.4"
215
+ },
216
+ "time": "2020-12-30T10:38:22+00:00",
217
+ "type": "library",
218
+ "installation-source": "dist",
219
+ "autoload": {
220
+ "psr-4": {
221
+ "Weglot\\": "src/"
222
+ }
223
+ },
224
+ "notification-url": "https://packagist.org/downloads/",
225
+ "license": [
226
+ "MIT"
227
+ ],
228
+ "authors": [
229
+ {
230
+ "name": "Baptiste Leduc",
231
+ "email": "baptiste@weglot.com",
232
+ "homepage": "https://baptiste-leduc.now.sh/",
233
+ "role": "Developer"
234
+ },
235
+ {
236
+ "name": "Thomas Deneulin",
237
+ "email": "thomas@weglot.com",
238
+ "role": "Review"
239
+ }
240
+ ],
241
+ "description": "PHP library for the Weglot API",
242
+ "homepage": "https://weglot.com/",
243
+ "keywords": [
244
+ "Weglot",
245
+ "i18n",
246
+ "languages",
247
+ "localization",
248
+ "php",
249
+ "translate",
250
+ "translation",
251
+ "translator",
252
+ "weglot-library"
253
+ ],
254
+ "support": {
255
+ "docs": "https://weglot.github.io/weglot-documentation/",
256
+ "email": "support@weglot.com",
257
+ "issues": "https://github.com/weglot/weglot-php/issues",
258
+ "source": "https://github.com/weglot/weglot-php"
259
+ },
260
+ "install-path": "../weglot/weglot-php"
261
+ }
262
+ ],
263
+ "dev": false,
264
+ "dev-package-names": []
265
+ }
vendor/composer/installed.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php return array (
2
+ 'root' =>
3
+ array (
4
+ 'pretty_version' => 'dev-master',
5
+ 'version' => 'dev-master',
6
+ 'aliases' =>
7
+ array (
8
+ ),
9
+ 'reference' => 'f3c6043c0974f05066db495501f0ec4f30395800',
10
+ 'name' => 'weglot/translate-wordpress',
11
+ ),
12
+ 'versions' =>
13
+ array (
14
+ 'gmulti/morphism-php' =>
15
+ array (
16
+ 'pretty_version' => '0.3.0',
17
+ 'version' => '0.3.0.0',
18
+ 'aliases' =>
19
+ array (
20
+ ),
21
+ 'reference' => '0b4cc4e604452a724124b8d342635c4b0b0e9809',
22
+ ),
23
+ 'psr/cache' =>
24
+ array (
25
+ 'pretty_version' => '1.0.1',
26
+ 'version' => '1.0.1.0',
27
+ 'aliases' =>
28
+ array (
29
+ ),
30
+ 'reference' => 'd11b50ad223250cf17b86e38383413f5a6764bf8',
31
+ ),
32
+ 'weglot/simplehtmldom' =>
33
+ array (
34
+ 'pretty_version' => '0.5',
35
+ 'version' => '0.5.0.0',
36
+ 'aliases' =>
37
+ array (
38
+ ),
39
+ 'reference' => 'ae2c353a18aa421703824838e5d921b3de5388fd',
40
+ ),
41
+ 'weglot/translate-wordpress' =>
42
+ array (
43
+ 'pretty_version' => 'dev-master',
44
+ 'version' => 'dev-master',
45
+ 'aliases' =>
46
+ array (
47
+ ),
48
+ 'reference' => 'f3c6043c0974f05066db495501f0ec4f30395800',
49
+ ),
50
+ 'weglot/translation-definitions' =>
51
+ array (
52
+ 'pretty_version' => 'v2.3.2',
53
+ 'version' => '2.3.2.0',
54
+ 'aliases' =>
55
+ array (
56
+ ),
57
+ 'reference' => '3a4d4b76892fe26cba132f6f9a29e4520dfc3ab6',
58
+ ),
59
+ 'weglot/weglot-php' =>
60
+ array (
61
+ 'pretty_version' => '1.1.1',
62
+ 'version' => '1.1.1.0',
63
+ 'aliases' =>
64
+ array (
65
+ ),
66
+ 'reference' => '9dab3aec1d314638f0890fd451d7eb328fce8398',
67
+ ),
68
+ ),
69
+ );
vendor/composer/platform_check.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // platform_check.php @generated by Composer
4
+
5
+ $issues = array();
6
+
7
+ if (!(PHP_VERSION_ID >= 50400)) {
8
+ $issues[] = 'Your Composer dependencies require a PHP version ">= 5.4.0". You are running ' . PHP_VERSION . '.';
9
+ }
10
+
11
+ if ($issues) {
12
+ if (!headers_sent()) {
13
+ header('HTTP/1.1 500 Internal Server Error');
14
+ }
15
+ if (!ini_get('display_errors')) {
16
+ if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
17
+ fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
18
+ } elseif (!headers_sent()) {
19
+ echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
20
+ }
21
+ }
22
+ trigger_error(
23
+ 'Composer detected issues in your platform: ' . implode(' ', $issues),
24
+ E_USER_ERROR
25
+ );
26
+ }
vendor/weglot/weglot-php/.travis.yml CHANGED
@@ -19,17 +19,14 @@ env:
19
  matrix:
20
  fast_finish: true
21
  include:
22
- - php: 5.4
23
- env: TEST_FLAGS="-g client -g parser -g util" DEPENDENCIES="" prefer="low"
24
- - php: 5.4
25
- env: TEST_FLAGS="-g client -g parser -g util" DEPENDENCIES=""
26
  - php: 5.5
27
  env: TEST_FLAGS="-g client -g parser -g util" DEPENDENCIES=""
28
  - php: 5.6
29
  - php: 7.0
30
  - php: 7.1
31
  - php: 7.2
32
- env: COVERAGE=true TEST_FLAGS="--coverage --coverage-xml"
 
33
 
34
  install:
35
  - composer config -g github-oauth.github.com "$TOKEN"
@@ -64,4 +61,4 @@ after_script:
64
 
65
  cache:
66
  directories:
67
- - $HOME/.composer/cache
19
  matrix:
20
  fast_finish: true
21
  include:
 
 
 
 
22
  - php: 5.5
23
  env: TEST_FLAGS="-g client -g parser -g util" DEPENDENCIES=""
24
  - php: 5.6
25
  - php: 7.0
26
  - php: 7.1
27
  - php: 7.2
28
+ # - php: 7.3
29
+ # env: COVERAGE=true TEST_FLAGS="--coverage --coverage-xml"
30
 
31
  install:
32
  - composer config -g github-oauth.github.com "$TOKEN"
61
 
62
  cache:
63
  directories:
64
+ - $HOME/.composer/cache
vendor/weglot/weglot-php/src/Client/Api/LanguageCollection.php CHANGED
@@ -17,7 +17,7 @@ class LanguageCollection extends AbstractCollection
17
  */
18
  public function addOne(AbstractCollectionEntry $entry)
19
  {
20
- $this->collection[$entry->getIso639()] = $entry;
21
 
22
  return $this;
23
  }
17
  */
18
  public function addOne(AbstractCollectionEntry $entry)
19
  {
20
+ $this->collection[$entry->getInternalCode()] = $entry;
21
 
22
  return $this;
23
  }
vendor/weglot/weglot-php/src/Client/Api/LanguageEntry.php CHANGED
@@ -11,12 +11,18 @@ use Weglot\Client\Api\Shared\AbstractCollectionEntry;
11
  class LanguageEntry extends AbstractCollectionEntry
12
  {
13
  /**
14
- * ISO 639-1 code to identify language
15
  *
16
- * @see https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
17
  * @var string
18
  */
19
- protected $iso_639_1;
 
 
 
 
 
 
 
20
 
21
  /**
22
  * English name of the language
@@ -41,27 +47,48 @@ class LanguageEntry extends AbstractCollectionEntry
41
 
42
  /**
43
  * LanguageEntry constructor.
44
- * @param string $iso_639_1 ISO 639-1 code to identify language
 
45
  * @param string $englishName English name of the language
46
  * @param string $localName Name of the language in the language
47
  * @param bool $isRtl Language is right to left
48
  */
49
- public function __construct($iso_639_1, $englishName, $localName, $isRtl = false)
50
  {
51
  $this
52
- ->setIso639($iso_639_1)
 
53
  ->setEnglishName($englishName)
54
  ->setLocalName($localName)
55
  ->setRtl($isRtl);
56
  }
57
 
58
  /**
59
- * @param $iso_639_1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  * @return $this
61
  */
62
- public function setIso639($iso_639_1)
63
  {
64
- $this->iso_639_1 = $iso_639_1;
65
 
66
  return $this;
67
  }
@@ -69,9 +96,9 @@ class LanguageEntry extends AbstractCollectionEntry
69
  /**
70
  * @return string
71
  */
72
- public function getIso639()
73
  {
74
- return $this->iso_639_1;
75
  }
76
 
77
  /**
@@ -137,7 +164,8 @@ class LanguageEntry extends AbstractCollectionEntry
137
  public function jsonSerialize()
138
  {
139
  return [
140
- 'code' => $this->getIso639(),
 
141
  'english' => $this->getEnglishName(),
142
  'local' => $this->getLocalName(),
143
  'rtl' => $this->isRtl(),
11
  class LanguageEntry extends AbstractCollectionEntry
12
  {
13
  /**
14
+ * Internal weglot code to identify language, is 2 letters, eg tw
15
  *
 
16
  * @var string
17
  */
18
+ protected $internalCode;
19
+
20
+ /**
21
+ * External code that shows on website on URLs (can be more than 2 letters)
22
+ *
23
+ * @var string
24
+ */
25
+ protected $externalCode;
26
 
27
  /**
28
  * English name of the language
47
 
48
  /**
49
  * LanguageEntry constructor.
50
+ * @param string $internalCode Internal weglot code to identify language
51
+ * @param string $externalCode External code that shows on website on URLs
52
  * @param string $englishName English name of the language
53
  * @param string $localName Name of the language in the language
54
  * @param bool $isRtl Language is right to left
55
  */
56
+ public function __construct($internalCode, $externalCode, $englishName, $localName, $isRtl = false)
57
  {
58
  $this
59
+ ->setInternalCode($internalCode)
60
+ ->setExternalCode($externalCode)
61
  ->setEnglishName($englishName)
62
  ->setLocalName($localName)
63
  ->setRtl($isRtl);
64
  }
65
 
66
  /**
67
+ * @param $internalCode
68
+ * @return $this
69
+ */
70
+ public function setInternalCode($internalCode)
71
+ {
72
+ $this->internalCode = $internalCode;
73
+
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * @return string
79
+ */
80
+ public function getInternalCode()
81
+ {
82
+ return $this->internalCode;
83
+ }
84
+
85
+ /**
86
+ * @param $externalCode
87
  * @return $this
88
  */
89
+ public function setExternalCode($externalCode)
90
  {
91
+ $this->externalCode = isset($externalCode) ? $externalCode : $this->internalCode;
92
 
93
  return $this;
94
  }
96
  /**
97
  * @return string
98
  */
99
+ public function getExternalCode()
100
  {
101
+ return $this->externalCode;
102
  }
103
 
104
  /**
164
  public function jsonSerialize()
165
  {
166
  return [
167
+ 'internal_code' => $this->getInternalCode(),
168
+ 'external_code' => $this->getExternalCode(),
169
  'english' => $this->getEnglishName(),
170
  'local' => $this->getLocalName(),
171
  'rtl' => $this->isRtl(),
vendor/weglot/weglot-php/src/Client/Factory/Languages.php CHANGED
@@ -37,13 +37,14 @@ class Languages
37
 
38
  /**
39
  * @param null $key
40
- * @return array|string|bool
41
  */
42
  public function getLanguage($key = null)
43
  {
44
- if ($key !== null && isset($this->language[$key])) {
45
- return $this->language[$key];
46
  }
 
47
  return $this->language;
48
  }
49
 
@@ -53,7 +54,8 @@ class Languages
53
  public function handle()
54
  {
55
  $language = new LanguageEntry(
56
- $this->getLanguage('code'),
 
57
  $this->getLanguage('english'),
58
  $this->getLanguage('local'),
59
  $this->getLanguage('rtl')
@@ -72,655 +74,655 @@ class Languages
72
  {
73
  return [
74
  'sq' => [
75
- 'code' => 'sq',
76
  'english' => 'Albanian',
77
  'local' => 'Shqip',
78
  'rtl' => false,
79
  ],
80
  'en' => [
81
- 'code' => 'en',
82
  'english' => 'English',
83
  'local' => 'English',
84
  'rtl' => false,
85
  ],
86
  'ar' => [
87
- 'code' => 'ar',
88
  'english' => 'Arabic',
89
  'local' => 'العربية‏',
90
  'rtl' => true,
91
  ],
92
  'hy' => [
93
- 'code' => 'hy',
94
  'english' => 'Armenian',
95
  'local' => 'հայերեն',
96
  'rtl' => false,
97
  ],
98
  'az' => [
99
- 'code' => 'az',
100
  'english' => 'Azerbaijani',
101
  'local' => 'Azərbaycan dili',
102
  'rtl' => false,
103
  ],
104
  'af' => [
105
- 'code' => 'af',
106
  'english' => 'Afrikaans',
107
  'local' => 'Afrikaans',
108
  'rtl' => false,
109
  ],
110
  'eu' => [
111
- 'code' => 'eu',
112
  'english' => 'Basque',
113
  'local' => 'Euskara',
114
  'rtl' => false,
115
  ],
116
  'be' => [
117
- 'code' => 'be',
118
  'english' => 'Belarusian',
119
  'local' => 'Беларуская',
120
  'rtl' => false,
121
  ],
122
  'bg' => [
123
- 'code' => 'bg',
124
  'english' => 'Bulgarian',
125
  'local' => 'български',
126
  'rtl' => false,
127
  ],
128
  'bs' => [
129
- 'code' => 'bs',
130
  'english' => 'Bosnian',
131
  'local' => 'Bosanski',
132
  'rtl' => false,
133
  ],
134
  'cy' => [
135
- 'code' => 'cy',
136
  'english' => 'Welsh',
137
  'local' => 'Cymraeg',
138
  'rtl' => false,
139
  ],
140
  'vi' => [
141
- 'code' => 'vi',
142
  'english' => 'Vietnamese',
143
  'local' => 'Tiếng Việt',
144
  'rtl' => false,
145
  ],
146
  'hu' => [
147
- 'code' => 'hu',
148
  'english' => 'Hungarian',
149
  'local' => 'Magyar',
150
  'rtl' => false,
151
  ],
152
  'ht' => [
153
- 'code' => 'ht',
154
  'english' => 'Haitian',
155
  'local' => 'Kreyòl ayisyen',
156
  'rtl' => false,
157
  ],
158
  'gl' => [
159
- 'code' => 'gl',
160
  'english' => 'Galician',
161
  'local' => 'Galego',
162
  'rtl' => false,
163
  ],
164
  'nl' => [
165
- 'code' => 'nl',
166
  'english' => 'Dutch',
167
  'local' => 'Nederlands',
168
  'rtl' => false,
169
  ],
170
  'el' => [
171
- 'code' => 'el',
172
  'english' => 'Greek',
173
  'local' => 'Ελληνικά',
174
  'rtl' => false,
175
  ],
176
  'ka' => [
177
- 'code' => 'ka',
178
  'english' => 'Georgian',
179
  'local' => 'ქართული',
180
  'rtl' => false,
181
  ],
182
  'da' => [
183
- 'code' => 'da',
184
  'english' => 'Danish',
185
  'local' => 'Dansk',
186
  'rtl' => false,
187
  ],
188
  'he' => [
189
- 'code' => 'he',
190
  'english' => 'Hebrew',
191
  'local' => 'עברית',
192
  'rtl' => true,
193
  ],
194
  'id' => [
195
- 'code' => 'id',
196
  'english' => 'Indonesian',
197
  'local' => 'Bahasa Indonesia',
198
  'rtl' => false,
199
  ],
200
  'ga' => [
201
- 'code' => 'ga',
202
  'english' => 'Irish',
203
  'local' => 'Gaeilge',
204
  'rtl' => false,
205
  ],
206
  'it' => [
207
- 'code' => 'it',
208
  'english' => 'Italian',
209
  'local' => 'Italiano',
210
  'rtl' => false,
211
  ],
212
  'is' => [
213
- 'code' => 'is',
214
  'english' => 'Icelandic',
215
  'local' => 'Íslenska',
216
  'rtl' => false,
217
  ],
218
  'es' => [
219
- 'code' => 'es',
220
  'english' => 'Spanish',
221
  'local' => 'Español',
222
  'rtl' => false,
223
  ],
224
  'kk' => [
225
- 'code' => 'kk',
226
  'english' => 'Kazakh',
227
  'local' => 'Қазақша',
228
  'rtl' => false,
229
  ],
230
  'ca' => [
231
- 'code' => 'ca',
232
  'english' => 'Catalan',
233
  'local' => 'Català',
234
  'rtl' => false,
235
  ],
236
  'ky' => [
237
- 'code' => 'ky',
238
  'english' => 'Kyrgyz',
239
  'local' => 'кыргызча',
240
  'rtl' => false,
241
  ],
242
  'zh' => [
243
- 'code' => 'zh',
244
  'english' => 'Simplified Chinese',
245
  'local' => '中文 (简体)',
246
  'rtl' => false,
247
  ],
248
  'tw' => [
249
- 'code' => 'tw',
250
  'english' => 'Traditional Chinese',
251
  'local' => '中文 (繁體)',
252
  'rtl' => false,
253
  ],
254
  'ko' => [
255
- 'code' => 'ko',
256
  'english' => 'Korean',
257
  'local' => '한국어',
258
  'rtl' => false,
259
  ],
260
  'lv' => [
261
- 'code' => 'lv',
262
  'english' => 'Latvian',
263
  'local' => 'Latviešu',
264
  'rtl' => false,
265
  ],
266
  'lt' => [
267
- 'code' => 'lt',
268
  'english' => 'Lithuanian',
269
  'local' => 'Lietuvių',
270
  'rtl' => false,
271
  ],
272
  'mg' => [
273
- 'code' => 'mg',
274
  'english' => 'Malagasy',
275
  'local' => 'Malagasy',
276
  'rtl' => false,
277
  ],
278
  'ms' => [
279
- 'code' => 'ms',
280
  'english' => 'Malay',
281
  'local' => 'Bahasa Melayu',
282
  'rtl' => false,
283
  ],
284
  'mt' => [
285
- 'code' => 'mt',
286
  'english' => 'Maltese',
287
  'local' => 'Malti',
288
  'rtl' => false,
289
  ],
290
  'mk' => [
291
- 'code' => 'mk',
292
  'english' => 'Macedonian',
293
  'local' => 'Македонски',
294
  'rtl' => false,
295
  ],
296
  'mn' => [
297
- 'code' => 'mn',
298
  'english' => 'Mongolian',
299
  'local' => 'Монгол',
300
  'rtl' => false,
301
  ],
302
  'de' => [
303
- 'code' => 'de',
304
  'english' => 'German',
305
  'local' => 'Deutsch',
306
  'rtl' => false,
307
  ],
308
  'no' => [
309
- 'code' => 'no',
310
  'english' => 'Norwegian',
311
  'local' => 'Norsk',
312
  'rtl' => false,
313
  ],
314
  'fa' => [
315
- 'code' => 'fa',
316
  'english' => 'Persian',
317
  'local' => 'فارسی',
318
  'rtl' => true,
319
  ],
320
  'pl' => [
321
- 'code' => 'pl',
322
  'english' => 'Polish',
323
  'local' => 'Polski',
324
  'rtl' => false,
325
  ],
326
  'pt' => [
327
- 'code' => 'pt',
328
  'english' => 'Portuguese',
329
  'local' => 'Português',
330
  'rtl' => false,
331
  ],
332
  'ro' => [
333
- 'code' => 'ro',
334
  'english' => 'Romanian',
335
  'local' => 'Română',
336
  'rtl' => false,
337
  ],
338
  'ru' => [
339
- 'code' => 'ru',
340
  'english' => 'Russian',
341
  'local' => 'Русский',
342
  'rtl' => false,
343
  ],
344
  'sr' => [
345
- 'code' => 'sr',
346
  'english' => 'Serbian',
347
  'local' => 'Српски',
348
  'rtl' => false,
349
  ],
350
  'sk' => [
351
- 'code' => 'sk',
352
  'english' => 'Slovak',
353
  'local' => 'Slovenčina',
354
  'rtl' => false,
355
  ],
356
  'sl' => [
357
- 'code' => 'sl',
358
  'english' => 'Slovenian',
359
  'local' => 'Slovenščina',
360
  'rtl' => false,
361
  ],
362
  'sw' => [
363
- 'code' => 'sw',
364
  'english' => 'Swahili',
365
  'local' => 'Kiswahili',
366
  'rtl' => false,
367
  ],
368
  'tg' => [
369
- 'code' => 'tg',
370
  'english' => 'Tajik',
371
  'local' => 'Тоҷикӣ',
372
  'rtl' => false,
373
  ],
374
  'th' => [
375
- 'code' => 'th',
376
  'english' => 'Thai',
377
  'local' => 'ภาษาไทย',
378
  'rtl' => false,
379
  ],
380
  'tl' => [
381
- 'code' => 'tl',
382
  'english' => 'Tagalog',
383
  'local' => 'Tagalog',
384
  'rtl' => false,
385
  ],
386
  'tt' => [
387
- 'code' => 'tt',
388
  'english' => 'Tatar',
389
  'local' => 'Tatar',
390
  'rtl' => false,
391
  ],
392
  'tr' => [
393
- 'code' => 'tr',
394
  'english' => 'Turkish',
395
  'local' => 'Türkçe',
396
  'rtl' => false,
397
  ],
398
  'uz' => [
399
- 'code' => 'uz',
400
  'english' => 'Uzbek',
401
  'local' => 'O\'zbek',
402
  'rtl' => false,
403
  ],
404
  'uk' => [
405
- 'code' => 'uk',
406
  'english' => 'Ukrainian',
407
  'local' => 'Українська',
408
  'rtl' => false,
409
  ],
410
  'fi' => [
411
- 'code' => 'fi',
412
  'english' => 'Finnish',
413
  'local' => 'Suomi',
414
  'rtl' => false,
415
  ],
416
  'fr' => [
417
- 'code' => 'fr',
418
  'english' => 'French',
419
  'local' => 'Français',
420
  'rtl' => false,
421
  ],
422
  'hr' => [
423
- 'code' => 'hr',
424
  'english' => 'Croatian',
425
  'local' => 'Hrvatski',
426
  'rtl' => false,
427
  ],
428
  'cs' => [
429
- 'code' => 'cs',
430
  'english' => 'Czech',
431
  'local' => 'Čeština',
432
  'rtl' => false,
433
  ],
434
  'sv' => [
435
- 'code' => 'sv',
436
  'english' => 'Swedish',
437
  'local' => 'Svenska',
438
  'rtl' => false,
439
  ],
440
  'et' => [
441
- 'code' => 'et',
442
  'english' => 'Estonian',
443
  'local' => 'Eesti',
444
  'rtl' => false,
445
  ],
446
  'ja' => [
447
- 'code' => 'ja',
448
  'english' => 'Japanese',
449
  'local' => '日本語',
450
  'rtl' => false,
451
  ],
452
  'hi' => [
453
- 'code' => 'hi',
454
  'english' => 'Hindi',
455
  'local' => 'हिंदी',
456
  'rtl' => false,
457
  ],
458
  'ur' => [
459
- 'code' => 'ur',
460
  'english' => 'Urdu',
461
  'local' => 'اردو',
462
  'rtl' => false,
463
  ],
464
  'co' => [
465
- 'code' => 'co',
466
  'english' => 'Corsican',
467
  'local' => 'Corsu',
468
  'rtl' => false,
469
  ],
470
  'fj' => [
471
- 'code' => 'fj',
472
  'english' => 'Fijian',
473
  'local' => 'Vosa Vakaviti',
474
  'rtl' => false,
475
  ],
476
  'hw' => [
477
- 'code' => 'hw',
478
  'english' => 'Hawaiian',
479
  'local' => '‘Ōlelo Hawai‘i',
480
  'rtl' => false,
481
  ],
482
  'ig' => [
483
- 'code' => 'ig',
484
  'english' => 'Igbo',
485
  'local' => 'Igbo',
486
  'rtl' => false,
487
  ],
488
  'ny' => [
489
- 'code' => 'ny',
490
  'english' => 'Chichewa',
491
  'local' => 'chiCheŵa',
492
  'rtl' => false,
493
  ],
494
  'ps' => [
495
- 'code' => 'ps',
496
  'english' => 'Pashto',
497
  'local' => 'پښت',
498
  'rtl' => false,
499
  ],
500
  'sd' => [
501
- 'code' => 'sd',
502
  'english' => 'Sindhi',
503
  'local' => 'سنڌي، سندھی, सिन्धी',
504
  'rtl' => false,
505
  ],
506
  'sn' => [
507
- 'code' => 'sn',
508
  'english' => 'Shona',
509
  'local' => 'chiShona',
510
  'rtl' => false,
511
  ],
512
  'to' => [
513
- 'code' => 'to',
514
  'english' => 'Tongan',
515
  'local' => 'faka-Tonga',
516
  'rtl' => false,
517
  ],
518
  'yo' => [
519
- 'code' => 'yo',
520
  'english' => 'Yoruba',
521
  'local' => 'Yorùbá',
522
  'rtl' => false,
523
  ],
524
  'zu' => [
525
- 'code' => 'zu',
526
  'english' => 'Zulu',
527
  'local' => 'isiZulu',
528
  'rtl' => false,
529
  ],
530
  'ty' => [
531
- 'code' => 'ty',
532
  'english' => 'Tahitian',
533
  'local' => 'te reo Tahiti, te reo Māʼohi',
534
  'rtl' => false,
535
  ],
536
  'sm' => [
537
- 'code' => 'sm',
538
  'english' => 'Samoan',
539
  'local' => 'gagana fa\'a Samoa',
540
  'rtl' => false,
541
  ],
542
  'ku' => [
543
- 'code' => 'ku',
544
  'english' => 'Kurdish',
545
  'local' => 'كوردی',
546
  'rtl' => false,
547
  ],
548
  'ha' => [
549
- 'code' => 'ha',
550
  'english' => 'Hausa',
551
  'local' => 'هَوُسَ',
552
  'rtl' => false,
553
  ],
554
  'bn' => [
555
- 'code' => 'bn',
556
  'english' => 'Bengali',
557
  'local' => 'বাংলা',
558
  'rtl' => false,
559
  ],
560
  'st' => [
561
- 'code' => 'st',
562
  'english' => 'Southern Sotho',
563
  'local' => 'seSotho',
564
  'rtl' => false,
565
  ],
566
  'ba' => [
567
- 'code' => 'ba',
568
  'english' => 'Bashkir',
569
  'local' => 'башҡорт теле',
570
  'rtl' => false,
571
  ],
572
  'jv' => [
573
- 'code' => 'jv',
574
  'english' => 'Javanese',
575
  'local' => 'Wong Jawa',
576
  'rtl' => false,
577
  ],
578
  'kn' => [
579
- 'code' => 'kn',
580
  'english' => 'Kannada',
581
  'local' => 'ಕನ್ನಡ',
582
  'rtl' => false,
583
  ],
584
  'la' => [
585
- 'code' => 'la',
586
  'english' => 'Latin',
587
  'local' => 'Latine',
588
  'rtl' => false,
589
  ],
590
  'lo' => [
591
- 'code' => 'lo',
592
  'english' => 'Lao',
593
  'local' => 'ພາສາລາວ',
594
  'rtl' => false,
595
  ],
596
  'mi' => [
597
- 'code' => 'mi',
598
  'english' => 'Māori',
599
  'local' => 'te reo Māori',
600
  'rtl' => false,
601
  ],
602
  'ml' => [
603
- 'code' => 'ml',
604
  'english' => 'Malayalam',
605
  'local' => 'മലയാളം',
606
  'rtl' => false,
607
  ],
608
  'mr' => [
609
- 'code' => 'mr',
610
  'english' => 'Marathi',
611
  'local' => 'मराठी',
612
  'rtl' => false,
613
  ],
614
  'ne' => [
615
- 'code' => 'ne',
616
  'english' => 'Nepali',
617
  'local' => 'नेपाली',
618
  'rtl' => false,
619
  ],
620
  'pa' => [
621
- 'code' => 'pa',
622
  'english' => 'Punjabi',
623
  'local' => 'ਪੰਜਾਬੀ',
624
  'rtl' => false,
625
  ],
626
  'so' => [
627
- 'code' => 'so',
628
  'english' => 'Somali',
629
  'local' => 'Soomaaliga',
630
  'rtl' => false,
631
  ],
632
  'su' => [
633
- 'code' => 'su',
634
  'english' => 'Sundanese',
635
  'local' => 'Sundanese',
636
  'rtl' => false,
637
  ],
638
  'te' => [
639
- 'code' => 'te',
640
  'english' => 'Telugu',
641
  'local' => 'తెలుగు',
642
  'rtl' => false,
643
  ],
644
  'yi' => [
645
- 'code' => 'yi',
646
  'english' => 'Yiddish',
647
  'local' => 'ייִדיש',
648
  'rtl' => false,
649
  ],
650
  'am' => [
651
- 'code' => 'am',
652
  'english' => 'Amharic',
653
  'local' => 'አማርኛ',
654
  'rtl' => false,
655
  ],
656
  'eo' => [
657
- 'code' => 'eo',
658
  'english' => 'Esperanto',
659
  'local' => 'Esperanto',
660
  'rtl' => false,
661
  ],
662
  'fy' => [
663
- 'code' => 'fy',
664
  'english' => 'Western Frisian',
665
  'local' => 'frysk',
666
  'rtl' => false,
667
  ],
668
  'gd' => [
669
- 'code' => 'gd',
670
  'english' => 'Scottish Gaelic',
671
  'local' => 'Gàidhlig',
672
  'rtl' => false,
673
  ],
674
  'gu' => [
675
- 'code' => 'gu',
676
  'english' => 'Gujarati',
677
  'local' => 'ગુજરાતી',
678
  'rtl' => false,
679
  ],
680
  'km' => [
681
- 'code' => 'km',
682
  'english' => 'Central Khmer',
683
  'local' => 'ភាសាខ្មែរ',
684
  'rtl' => false,
685
  ],
686
  'lb' => [
687
- 'code' => 'lb',
688
  'english' => 'Luxembourgish',
689
  'local' => 'Lëtzebuergesch',
690
  'rtl' => false,
691
  ],
692
  'my' => [
693
- 'code' => 'my',
694
  'english' => 'Burmese',
695
  'local' => 'မျန္မာစာ',
696
  'rtl' => false,
697
  ],
698
  'si' => [
699
- 'code' => 'si',
700
  'english' => 'Sinhalese',
701
  'local' => 'සිංහල',
702
  'rtl' => false,
703
  ],
704
  'ta' => [
705
- 'code' => 'ta',
706
  'english' => 'Tamil',
707
  'local' => 'தமிழ்',
708
  'rtl' => false,
709
  ],
710
  'xh' => [
711
- 'code' => 'xh',
712
  'english' => 'Xhosa',
713
  'local' => 'isiXhosa',
714
  'rtl' => false,
715
  ],
716
  'fl' => [
717
- 'code' => 'fl',
718
  'english' => 'Filipino',
719
  'local' => 'Pilipino',
720
  'rtl' => false,
721
  ],
722
  'br' => [
723
- 'code' => 'br',
724
  'english' => 'Brazilian Portuguese',
725
  'local' => 'Português Brasileiro',
726
  'rtl' => false,
37
 
38
  /**
39
  * @param null $key
40
+ * @return array|string|bool|null
41
  */
42
  public function getLanguage($key = null)
43
  {
44
+ if ($key !== null) {
45
+ return isset($this->language[$key]) ? $this->language[$key] : null;
46
  }
47
+
48
  return $this->language;
49
  }
50
 
54
  public function handle()
55
  {
56
  $language = new LanguageEntry(
57
+ $this->getLanguage('internal_code'),
58
+ $this->getLanguage('external_code'),
59
  $this->getLanguage('english'),
60
  $this->getLanguage('local'),
61
  $this->getLanguage('rtl')
74
  {
75
  return [
76
  'sq' => [
77
+ 'internal_code' => 'sq',
78
  'english' => 'Albanian',
79
  'local' => 'Shqip',
80
  'rtl' => false,
81
  ],
82
  'en' => [
83
+ 'internal_code' => 'en',
84
  'english' => 'English',
85
  'local' => 'English',
86
  'rtl' => false,
87
  ],
88
  'ar' => [
89
+ 'internal_code' => 'ar',
90
  'english' => 'Arabic',
91
  'local' => 'العربية‏',
92
  'rtl' => true,
93
  ],
94
  'hy' => [
95
+ 'internal_code' => 'hy',
96
  'english' => 'Armenian',
97
  'local' => 'հայերեն',
98
  'rtl' => false,
99
  ],
100
  'az' => [
101
+ 'internal_code' => 'az',
102
  'english' => 'Azerbaijani',
103
  'local' => 'Azərbaycan dili',
104
  'rtl' => false,
105
  ],
106
  'af' => [
107
+ 'internal_code' => 'af',
108
  'english' => 'Afrikaans',
109
  'local' => 'Afrikaans',
110
  'rtl' => false,
111
  ],
112
  'eu' => [
113
+ 'internal_code' => 'eu',
114
  'english' => 'Basque',
115
  'local' => 'Euskara',
116
  'rtl' => false,
117
  ],
118
  'be' => [
119
+ 'internal_code' => 'be',
120
  'english' => 'Belarusian',
121
  'local' => 'Беларуская',
122
  'rtl' => false,
123
  ],
124
  'bg' => [
125
+ 'internal_code' => 'bg',
126
  'english' => 'Bulgarian',
127
  'local' => 'български',
128
  'rtl' => false,
129
  ],
130
  'bs' => [
131
+ 'internal_code' => 'bs',
132
  'english' => 'Bosnian',
133
  'local' => 'Bosanski',
134
  'rtl' => false,
135
  ],
136
  'cy' => [
137
+ 'internal_code' => 'cy',
138
  'english' => 'Welsh',
139
  'local' => 'Cymraeg',
140
  'rtl' => false,
141
  ],
142
  'vi' => [
143
+ 'internal_code' => 'vi',
144
  'english' => 'Vietnamese',
145
  'local' => 'Tiếng Việt',
146
  'rtl' => false,
147
  ],
148
  'hu' => [
149
+ 'internal_code' => 'hu',
150
  'english' => 'Hungarian',
151
  'local' => 'Magyar',
152
  'rtl' => false,
153
  ],
154
  'ht' => [
155
+ 'internal_code' => 'ht',
156
  'english' => 'Haitian',
157
  'local' => 'Kreyòl ayisyen',
158
  'rtl' => false,
159
  ],
160
  'gl' => [
161
+ 'internal_code' => 'gl',
162
  'english' => 'Galician',
163
  'local' => 'Galego',
164
  'rtl' => false,
165
  ],
166
  'nl' => [
167
+ 'internal_code' => 'nl',
168
  'english' => 'Dutch',
169
  'local' => 'Nederlands',
170
  'rtl' => false,
171
  ],
172
  'el' => [
173
+ 'internal_code' => 'el',
174
  'english' => 'Greek',
175
  'local' => 'Ελληνικά',
176
  'rtl' => false,
177
  ],
178
  'ka' => [
179
+ 'internal_code' => 'ka',
180
  'english' => 'Georgian',
181
  'local' => 'ქართული',
182
  'rtl' => false,
183
  ],
184
  'da' => [
185
+ 'internal_code' => 'da',
186
  'english' => 'Danish',
187
  'local' => 'Dansk',
188
  'rtl' => false,
189
  ],
190
  'he' => [
191
+ 'internal_code' => 'he',
192
  'english' => 'Hebrew',
193
  'local' => 'עברית',
194
  'rtl' => true,
195
  ],
196
  'id' => [
197
+ 'internal_code' => 'id',
198
  'english' => 'Indonesian',
199
  'local' => 'Bahasa Indonesia',
200
  'rtl' => false,
201
  ],
202
  'ga' => [
203
+ 'internal_code' => 'ga',
204
  'english' => 'Irish',
205
  'local' => 'Gaeilge',
206
  'rtl' => false,
207
  ],
208
  'it' => [
209
+ 'internal_code' => 'it',
210
  'english' => 'Italian',
211
  'local' => 'Italiano',
212
  'rtl' => false,
213
  ],
214
  'is' => [
215
+ 'internal_code' => 'is',
216
  'english' => 'Icelandic',
217
  'local' => 'Íslenska',
218
  'rtl' => false,
219
  ],
220
  'es' => [
221
+ 'internal_code' => 'es',
222
  'english' => 'Spanish',
223
  'local' => 'Español',
224
  'rtl' => false,
225
  ],
226
  'kk' => [
227
+ 'internal_code' => 'kk',
228
  'english' => 'Kazakh',
229
  'local' => 'Қазақша',
230
  'rtl' => false,
231
  ],
232
  'ca' => [
233
+ 'internal_code' => 'ca',
234
  'english' => 'Catalan',
235
  'local' => 'Català',
236
  'rtl' => false,
237
  ],
238
  'ky' => [
239
+ 'internal_code' => 'ky',
240
  'english' => 'Kyrgyz',
241
  'local' => 'кыргызча',
242
  'rtl' => false,
243
  ],
244
  'zh' => [
245
+ 'internal_code' => 'zh',
246
  'english' => 'Simplified Chinese',
247
  'local' => '中文 (简体)',
248
  'rtl' => false,
249
  ],
250
  'tw' => [
251
+ 'internal_code' => 'tw',
252
  'english' => 'Traditional Chinese',
253
  'local' => '中文 (繁體)',
254
  'rtl' => false,
255
  ],
256
  'ko' => [
257
+ 'internal_code' => 'ko',
258
  'english' => 'Korean',
259
  'local' => '한국어',
260
  'rtl' => false,
261
  ],
262
  'lv' => [
263
+ 'internal_code' => 'lv',
264
  'english' => 'Latvian',
265
  'local' => 'Latviešu',
266
  'rtl' => false,
267
  ],
268
  'lt' => [
269
+ 'internal_code' => 'lt',
270
  'english' => 'Lithuanian',
271
  'local' => 'Lietuvių',
272
  'rtl' => false,
273
  ],
274
  'mg' => [
275
+ 'internal_code' => 'mg',
276
  'english' => 'Malagasy',
277
  'local' => 'Malagasy',
278
  'rtl' => false,
279
  ],
280
  'ms' => [
281
+ 'internal_code' => 'ms',
282
  'english' => 'Malay',
283
  'local' => 'Bahasa Melayu',
284
  'rtl' => false,
285
  ],
286
  'mt' => [
287
+ 'internal_code' => 'mt',
288
  'english' => 'Maltese',
289
  'local' => 'Malti',
290
  'rtl' => false,
291
  ],
292
  'mk' => [
293
+ 'internal_code' => 'mk',
294
  'english' => 'Macedonian',
295
  'local' => 'Македонски',
296
  'rtl' => false,
297
  ],
298
  'mn' => [
299
+ 'internal_code' => 'mn',
300
  'english' => 'Mongolian',
301
  'local' => 'Монгол',
302
  'rtl' => false,
303
  ],
304
  'de' => [
305
+ 'internal_code' => 'de',
306
  'english' => 'German',
307
  'local' => 'Deutsch',
308
  'rtl' => false,
309
  ],
310
  'no' => [
311
+ 'internal_code' => 'no',
312
  'english' => 'Norwegian',
313
  'local' => 'Norsk',
314
  'rtl' => false,
315
  ],
316
  'fa' => [
317
+ 'internal_code' => 'fa',
318
  'english' => 'Persian',
319
  'local' => 'فارسی',
320
  'rtl' => true,
321
  ],
322
  'pl' => [
323
+ 'internal_code' => 'pl',
324
  'english' => 'Polish',
325
  'local' => 'Polski',
326
  'rtl' => false,
327
  ],
328
  'pt' => [
329
+ 'internal_code' => 'pt',
330
  'english' => 'Portuguese',
331
  'local' => 'Português',
332
  'rtl' => false,
333
  ],
334
  'ro' => [
335
+ 'internal_code' => 'ro',
336
  'english' => 'Romanian',
337
  'local' => 'Română',
338
  'rtl' => false,
339
  ],
340
  'ru' => [
341
+ 'internal_code' => 'ru',
342
  'english' => 'Russian',
343
  'local' => 'Русский',
344
  'rtl' => false,
345
  ],
346
  'sr' => [
347
+ 'internal_code' => 'sr',
348
  'english' => 'Serbian',
349
  'local' => 'Српски',
350
  'rtl' => false,
351
  ],
352
  'sk' => [
353
+ 'internal_code' => 'sk',
354
  'english' => 'Slovak',
355
  'local' => 'Slovenčina',
356
  'rtl' => false,
357
  ],
358
  'sl' => [
359
+ 'internal_code' => 'sl',
360
  'english' => 'Slovenian',
361
  'local' => 'Slovenščina',
362
  'rtl' => false,
363
  ],
364
  'sw' => [
365
+ 'internal_code' => 'sw',
366
  'english' => 'Swahili',
367
  'local' => 'Kiswahili',
368
  'rtl' => false,
369
  ],
370
  'tg' => [
371
+ 'internal_code' => 'tg',
372
  'english' => 'Tajik',
373
  'local' => 'Тоҷикӣ',
374
  'rtl' => false,
375
  ],
376
  'th' => [
377
+ 'internal_code' => 'th',
378
  'english' => 'Thai',
379
  'local' => 'ภาษาไทย',
380
  'rtl' => false,
381
  ],
382
  'tl' => [
383
+ 'internal_code' => 'tl',
384
  'english' => 'Tagalog',
385
  'local' => 'Tagalog',
386
  'rtl' => false,
387
  ],
388
  'tt' => [
389
+ 'internal_code' => 'tt',
390
  'english' => 'Tatar',
391
  'local' => 'Tatar',
392
  'rtl' => false,
393
  ],
394
  'tr' => [
395
+ 'internal_code' => 'tr',
396
  'english' => 'Turkish',
397
  'local' => 'Türkçe',
398
  'rtl' => false,
399
  ],
400
  'uz' => [
401
+ 'internal_code' => 'uz',
402
  'english' => 'Uzbek',
403
  'local' => 'O\'zbek',
404
  'rtl' => false,
405
  ],
406
  'uk' => [
407
+ 'internal_code' => 'uk',
408
  'english' => 'Ukrainian',
409
  'local' => 'Українська',
410
  'rtl' => false,
411
  ],
412
  'fi' => [
413
+ 'internal_code' => 'fi',
414
  'english' => 'Finnish',
415
  'local' => 'Suomi',
416
  'rtl' => false,
417
  ],
418
  'fr' => [
419
+ 'internal_code' => 'fr',
420
  'english' => 'French',
421
  'local' => 'Français',
422
  'rtl' => false,
423
  ],
424
  'hr' => [
425
+ 'internal_code' => 'hr',
426
  'english' => 'Croatian',
427
  'local' => 'Hrvatski',
428
  'rtl' => false,
429
  ],
430
  'cs' => [
431
+ 'internal_code' => 'cs',
432
  'english' => 'Czech',
433
  'local' => 'Čeština',
434
  'rtl' => false,
435
  ],
436
  'sv' => [
437
+ 'internal_code' => 'sv',
438
  'english' => 'Swedish',
439
  'local' => 'Svenska',
440
  'rtl' => false,
441
  ],
442
  'et' => [
443
+ 'internal_code' => 'et',
444
  'english' => 'Estonian',
445
  'local' => 'Eesti',
446
  'rtl' => false,
447
  ],
448
  'ja' => [
449
+ 'internal_code' => 'ja',
450
  'english' => 'Japanese',
451
  'local' => '日本語',
452
  'rtl' => false,
453
  ],
454
  'hi' => [
455
+ 'internal_code' => 'hi',
456
  'english' => 'Hindi',
457
  'local' => 'हिंदी',
458
  'rtl' => false,
459
  ],
460
  'ur' => [
461
+ 'internal_code' => 'ur',
462
  'english' => 'Urdu',
463
  'local' => 'اردو',
464
  'rtl' => false,
465
  ],
466
  'co' => [
467
+ 'internal_code' => 'co',
468
  'english' => 'Corsican',
469
  'local' => 'Corsu',
470
  'rtl' => false,
471
  ],
472
  'fj' => [
473
+ 'internal_code' => 'fj',
474
  'english' => 'Fijian',
475
  'local' => 'Vosa Vakaviti',
476
  'rtl' => false,
477
  ],
478
  'hw' => [
479
+ 'internal_code' => 'hw',
480
  'english' => 'Hawaiian',
481
  'local' => '‘Ōlelo Hawai‘i',
482
  'rtl' => false,
483
  ],
484
  'ig' => [
485
+ 'internal_code' => 'ig',
486
  'english' => 'Igbo',
487
  'local' => 'Igbo',
488
  'rtl' => false,
489
  ],
490
  'ny' => [
491
+ 'internal_code' => 'ny',
492
  'english' => 'Chichewa',
493
  'local' => 'chiCheŵa',
494
  'rtl' => false,
495
  ],
496
  'ps' => [
497
+ 'internal_code' => 'ps',
498
  'english' => 'Pashto',
499
  'local' => 'پښت',
500
  'rtl' => false,
501
  ],
502
  'sd' => [
503
+ 'internal_code' => 'sd',
504
  'english' => 'Sindhi',
505
  'local' => 'سنڌي، سندھی, सिन्धी',
506
  'rtl' => false,
507
  ],
508
  'sn' => [
509
+ 'internal_code' => 'sn',
510
  'english' => 'Shona',
511
  'local' => 'chiShona',
512
  'rtl' => false,
513
  ],
514
  'to' => [
515
+ 'internal_code' => 'to',
516
  'english' => 'Tongan',
517
  'local' => 'faka-Tonga',
518
  'rtl' => false,
519
  ],
520
  'yo' => [
521
+ 'internal_code' => 'yo',
522
  'english' => 'Yoruba',
523
  'local' => 'Yorùbá',
524
  'rtl' => false,
525
  ],
526
  'zu' => [
527
+ 'internal_code' => 'zu',
528
  'english' => 'Zulu',
529
  'local' => 'isiZulu',
530
  'rtl' => false,
531
  ],
532
  'ty' => [
533
+ 'internal_code' => 'ty',
534
  'english' => 'Tahitian',
535
  'local' => 'te reo Tahiti, te reo Māʼohi',
536
  'rtl' => false,
537
  ],
538
  'sm' => [
539
+ 'internal_code' => 'sm',
540
  'english' => 'Samoan',
541
  'local' => 'gagana fa\'a Samoa',
542
  'rtl' => false,
543
  ],
544
  'ku' => [
545
+ 'internal_code' => 'ku',
546
  'english' => 'Kurdish',
547
  'local' => 'كوردی',
548
  'rtl' => false,
549
  ],
550
  'ha' => [
551
+ 'internal_code' => 'ha',
552
  'english' => 'Hausa',
553
  'local' => 'هَوُسَ',
554
  'rtl' => false,
555
  ],
556
  'bn' => [
557
+ 'internal_code' => 'bn',
558
  'english' => 'Bengali',
559
  'local' => 'বাংলা',
560
  'rtl' => false,
561
  ],
562
  'st' => [
563
+ 'internal_code' => 'st',
564
  'english' => 'Southern Sotho',
565
  'local' => 'seSotho',
566
  'rtl' => false,
567
  ],
568
  'ba' => [
569
+ 'internal_code' => 'ba',
570
  'english' => 'Bashkir',
571
  'local' => 'башҡорт теле',
572
  'rtl' => false,
573
  ],
574
  'jv' => [
575
+ 'internal_code' => 'jv',
576
  'english' => 'Javanese',
577
  'local' => 'Wong Jawa',
578
  'rtl' => false,
579
  ],
580
  'kn' => [
581
+ 'internal_code' => 'kn',
582
  'english' => 'Kannada',
583
  'local' => 'ಕನ್ನಡ',
584
  'rtl' => false,
585
  ],
586
  'la' => [
587
+ 'internal_code' => 'la',
588
  'english' => 'Latin',
589
  'local' => 'Latine',
590
  'rtl' => false,
591
  ],
592
  'lo' => [
593
+ 'internal_code' => 'lo',
594
  'english' => 'Lao',
595
  'local' => 'ພາສາລາວ',
596
  'rtl' => false,
597
  ],
598
  'mi' => [
599
+ 'internal_code' => 'mi',
600
  'english' => 'Māori',
601
  'local' => 'te reo Māori',
602
  'rtl' => false,
603
  ],
604
  'ml' => [
605
+ 'internal_code' => 'ml',
606
  'english' => 'Malayalam',
607
  'local' => 'മലയാളം',
608
  'rtl' => false,
609
  ],
610
  'mr' => [
611
+ 'internal_code' => 'mr',
612
  'english' => 'Marathi',
613
  'local' => 'मराठी',
614
  'rtl' => false,
615
  ],
616
  'ne' => [
617
+ 'internal_code' => 'ne',
618
  'english' => 'Nepali',
619
  'local' => 'नेपाली',
620
  'rtl' => false,
621
  ],
622
  'pa' => [
623
+ 'internal_code' => 'pa',
624
  'english' => 'Punjabi',
625
  'local' => 'ਪੰਜਾਬੀ',
626
  'rtl' => false,
627
  ],
628
  'so' => [
629
+ 'internal_code' => 'so',
630
  'english' => 'Somali',
631
  'local' => 'Soomaaliga',
632
  'rtl' => false,
633
  ],
634
  'su' => [
635
+ 'internal_code' => 'su',
636
  'english' => 'Sundanese',
637
  'local' => 'Sundanese',
638
  'rtl' => false,
639
  ],
640
  'te' => [
641
+ 'internal_code' => 'te',
642
  'english' => 'Telugu',
643
  'local' => 'తెలుగు',
644
  'rtl' => false,
645
  ],
646
  'yi' => [
647
+ 'internal_code' => 'yi',
648
  'english' => 'Yiddish',
649
  'local' => 'ייִדיש',
650
  'rtl' => false,
651
  ],
652
  'am' => [
653
+ 'internal_code' => 'am',
654
  'english' => 'Amharic',
655
  'local' => 'አማርኛ',
656
  'rtl' => false,
657
  ],
658
  'eo' => [
659
+ 'internal_code' => 'eo',
660
  'english' => 'Esperanto',
661
  'local' => 'Esperanto',
662
  'rtl' => false,
663
  ],
664
  'fy' => [
665
+ 'internal_code' => 'fy',
666
  'english' => 'Western Frisian',
667
  'local' => 'frysk',
668
  'rtl' => false,
669
  ],
670
  'gd' => [
671
+ 'internal_code' => 'gd',
672
  'english' => 'Scottish Gaelic',
673
  'local' => 'Gàidhlig',
674
  'rtl' => false,
675
  ],
676
  'gu' => [
677
+ 'internal_code' => 'gu',
678
  'english' => 'Gujarati',
679
  'local' => 'ગુજરાતી',
680
  'rtl' => false,
681
  ],
682
  'km' => [
683
+ 'internal_code' => 'km',
684
  'english' => 'Central Khmer',
685
  'local' => 'ភាសាខ្មែរ',
686
  'rtl' => false,
687
  ],
688
  'lb' => [
689
+ 'internal_code' => 'lb',
690
  'english' => 'Luxembourgish',
691
  'local' => 'Lëtzebuergesch',
692
  'rtl' => false,
693
  ],
694
  'my' => [
695
+ 'internal_code' => 'my',
696
  'english' => 'Burmese',
697
  'local' => 'မျန္မာစာ',
698
  'rtl' => false,
699
  ],
700
  'si' => [
701
+ 'internal_code' => 'si',
702
  'english' => 'Sinhalese',
703
  'local' => 'සිංහල',
704
  'rtl' => false,
705
  ],
706
  'ta' => [
707
+ 'internal_code' => 'ta',
708
  'english' => 'Tamil',
709
  'local' => 'தமிழ்',
710
  'rtl' => false,
711
  ],
712
  'xh' => [
713
+ 'internal_code' => 'xh',
714
  'english' => 'Xhosa',
715
  'local' => 'isiXhosa',
716
  'rtl' => false,
717
  ],
718
  'fl' => [
719
+ 'internal_code' => 'fl',
720
  'english' => 'Filipino',
721
  'local' => 'Pilipino',
722
  'rtl' => false,
723
  ],
724
  'br' => [
725
+ 'internal_code' => 'br',
726
  'english' => 'Brazilian Portuguese',
727
  'local' => 'Português Brasileiro',
728
  'rtl' => false,
vendor/weglot/weglot-php/src/Parser/Check/Dom/ImageDataSource.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Weglot\Parser\Check\Dom;
4
+
5
+ use Weglot\Client\Api\Enum\WordType;
6
+
7
+ /**
8
+ * Class ImageDataSource
9
+ * @package Weglot\Parser\Check\Dom
10
+ */
11
+ class ImageDataSource extends AbstractDomChecker
12
+ {
13
+ /**
14
+ * {@inheritdoc}
15
+ */
16
+ const DOM = 'img';
17
+
18
+ /**
19
+ * {@inheritdoc}
20
+ */
21
+ const PROPERTY = 'data-src';
22
+
23
+ /**
24
+ * {@inheritdoc}
25
+ */
26
+ const WORD_TYPE = WordType::IMG_SRC;
27
+ }
vendor/weglot/weglot-php/src/Parser/Check/RegexCheckerProvider.php CHANGED
@@ -100,10 +100,14 @@ class RegexCheckerProvider
100
  protected function loadDefaultCheckers()
101
  {
102
  /* Add JSON LD checker */
103
- $this->addChecker(new RegexChecker("#<script type=('|\")application\/ld\+json('|\")([^\>]+?)?>(.*?)<\/script>#s" , SourceType::SOURCE_JSON, 4 , array( "description" , "name" , "headline" , "articleSection" )));
 
 
104
 
105
  /* Add HTML template checker */
106
- $this->addChecker(new RegexChecker( "#<script type=('|\")text/html('|\")([^\>]+?)?>(.+?)<\/script>#s" , SourceType::SOURCE_HTML, 4));
 
 
107
  }
108
 
109
  /**
100
  protected function loadDefaultCheckers()
101
  {
102
  /* Add JSON LD checker */
103
+ if(strpos(implode("," , $this->parser->getExcludeBlocks()), 'application/ld+json') === false ) {
104
+ $this->addChecker(new RegexChecker("#<script type=('|\")application\/ld\+json('|\")([^\>]+?)?>(.*?)<\/script>#s" , SourceType::SOURCE_JSON, 4 , array( "description" , "name" , "headline" , "articleSection" )));
105
+ }
106
 
107
  /* Add HTML template checker */
108
+ if(strpos(implode("," , $this->parser->getExcludeBlocks()), 'text/html') === false ) {
109
+ $this->addChecker(new RegexChecker("#<script type=('|\")text/html('|\")([^\>]+?)?>(.+?)<\/script>#s", SourceType::SOURCE_HTML, 4));
110
+ }
111
  }
112
 
113
  /**
vendor/weglot/weglot-php/src/Parser/Formatter/DomFormatter.php CHANGED
@@ -69,7 +69,7 @@ class DomFormatter extends AbstractFormatter
69
 
70
  if ($details['class']::ESCAPE_SPECIAL_CHAR) {
71
  $details['node']->$property = htmlspecialchars($translated);
72
- } else {
73
  $details['node']->$property = $translated;
74
  }
75
 
@@ -97,13 +97,21 @@ class DomFormatter extends AbstractFormatter
97
  $words = $this->getTranslated()->getInputWords();
98
 
99
  if ($details['class'] === '\Weglot\Parser\Check\Dom\ImageSource') {
100
- $details['node']->src = $translated;
101
  if ($details['node']->hasAttribute('srcset') &&
102
  $details['node']->srcset != '' &&
103
  $translated != $words[$index]->getWord()) {
104
  $details['node']->srcset = '';
105
  }
106
  }
 
 
 
 
 
 
 
 
 
107
  }
108
 
109
  protected function getTranslatableAttributes() {
69
 
70
  if ($details['class']::ESCAPE_SPECIAL_CHAR) {
71
  $details['node']->$property = htmlspecialchars($translated);
72
+ } else {
73
  $details['node']->$property = $translated;
74
  }
75
 
97
  $words = $this->getTranslated()->getInputWords();
98
 
99
  if ($details['class'] === '\Weglot\Parser\Check\Dom\ImageSource') {
 
100
  if ($details['node']->hasAttribute('srcset') &&
101
  $details['node']->srcset != '' &&
102
  $translated != $words[$index]->getWord()) {
103
  $details['node']->srcset = '';
104
  }
105
  }
106
+
107
+ if ($details['class'] === '\Weglot\Parser\Check\Dom\ImageDataSource') {
108
+ $dataSrcSet = "data-srcset";;
109
+ if ($details['node']->hasAttribute('data-srcset') &&
110
+ $details['node']->$dataSrcSet != '' &&
111
+ $translated != $words[$index]->getWord()) {
112
+ $details['node']->$dataSrcSet = '';
113
+ }
114
+ }
115
  }
116
 
117
  protected function getTranslatableAttributes() {
vendor/weglot/weglot-php/src/Util/Url.php CHANGED
@@ -2,8 +2,8 @@
2
 
3
  namespace Weglot\Util;
4
 
5
- use Weglot\Util\Url\UrlConfig;
6
- use Weglot\Util\Url\UrlTranslate;
7
 
8
  /**
9
  * Class Url
@@ -26,32 +26,69 @@ class Url
26
  */
27
  protected $query = null;
28
 
 
 
 
 
 
29
  /**
30
  * @var null|array
31
  */
32
  protected $allUrls = null;
33
 
34
  /**
35
- * @var UrlConfig
 
 
 
 
 
 
 
 
 
 
36
  */
37
- protected $config = null;
38
 
39
  /**
40
- * @var UrlTranslate
41
  */
42
- protected $translate = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  /**
45
  * Url constructor.
46
  * @param string $url Current visited url
47
- * @param string $default Default language represented by ISO 639-1 code
48
- * @param array $languages All available languages
49
- * @param string $pathPrefix Prefix to access website root path (ie. : `/my/custom/path`, don't forget: starting `/` and no ending `/`)
 
 
50
  */
51
- public function __construct($url, $default, $languages = [], $pathPrefix = '')
52
  {
53
- $this->config = new UrlConfig($url, $pathPrefix);
54
- $this->translate = new UrlTranslate($default, $languages);
 
 
 
 
 
55
  }
56
 
57
  /**
@@ -59,7 +96,7 @@ class Url
59
  */
60
  public function getUrl()
61
  {
62
- return $this->config->getRaw();
63
  }
64
 
65
  /**
@@ -78,22 +115,12 @@ class Url
78
  return $this->path;
79
  }
80
 
81
- /**
82
- * @deprecated Use getPath() instead
83
- * @return null|string
84
- */
85
- public function getBaseUrl()
86
- {
87
- @trigger_error('Use getPath() instead', E_USER_DEPRECATED);
88
- return $this->getPath();
89
- }
90
-
91
  /**
92
  * @return string
93
  */
94
  public function getPathPrefix()
95
  {
96
- return $this->config->getPathPrefix();
97
  }
98
 
99
  /**
@@ -102,8 +129,7 @@ class Url
102
  */
103
  public function setExcludedUrls($excludedUrls)
104
  {
105
- $this->config->setExcludedUrls($excludedUrls);
106
-
107
  return $this;
108
  }
109
 
@@ -112,7 +138,7 @@ class Url
112
  */
113
  public function getDefault()
114
  {
115
- return $this->translate->getDefault();
116
  }
117
 
118
  /**
@@ -124,61 +150,87 @@ class Url
124
  }
125
 
126
  /**
127
- * @param string $code Language represented by ISO 639-1 code
128
- * @return bool|string
129
  */
130
- public function getForLanguage($code)
131
  {
132
- $url = false;
 
133
 
134
- if ($this->translate->checkIfAvailable($code)) {
135
- $all = $this->currentRequestAllUrls();
136
- $url = $all[$code];
 
 
 
 
 
137
  }
 
 
138
 
139
- return $url;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
 
142
  /**
143
  * Check if we need to translate given URL
144
  *
 
145
  * @return bool
146
  */
147
- public function isTranslable()
148
  {
149
- if ($this->getPath() === null) {
150
- $this->detectUrlDetails();
151
  }
 
 
152
 
153
- foreach ($this->config->getExcludedUrls() as $regex) {
154
- $escapedRegex = Text::escapeForRegex($regex);
155
- $fullRegex = sprintf('/%s/', $escapedRegex);
156
-
157
- if (preg_match($fullRegex, $this->getPath()) === 1) {
158
- return false;
 
 
 
 
 
 
159
  }
160
  }
161
-
162
- return true;
163
  }
164
 
165
  /**
166
  * Check current locale, based on URI segments from the given URL
167
  *
168
- * @return mixed
169
  */
170
- public function detectCurrentLanguage()
171
  {
172
- // parsing url to get only path & removing prefix if there is one
173
- $escapedPathPrefix = Text::escapeForRegex($this->config->getPathPrefix());
174
- $uriPath = parse_url($this->config->getRaw(), PHP_URL_PATH);
175
- $uriPath = preg_replace('/^' . $escapedPathPrefix . '/s', '', $uriPath);
176
- $uriSegments = explode('/', $uriPath);
177
-
178
- if (isset($uriSegments[1]) && in_array($uriSegments[1], $this->translate->getLanguages())) {
179
- return $uriSegments[1];
180
- }
181
- return $this->translate->getDefault();
182
  }
183
 
184
  /**
@@ -192,31 +244,56 @@ class Url
192
  return;
193
  }
194
 
195
- $escapedPathPrefix = Text::escapeForRegex($this->config->getPathPrefix());
196
- $languages = implode('|', $this->translate->getLanguages());
 
 
197
 
198
- $fullUrl = preg_replace('#' . $escapedPathPrefix . '\/(' . $languages . ')$#i', '', $this->getUrl());
199
- $fullUrl = preg_replace('#' . $escapedPathPrefix . '\/(' . $languages . ')/#i', '/', $fullUrl);
200
- $parsed = parse_url($fullUrl);
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  if(isset($parsed['scheme'])) {
203
  $this->host = $parsed['scheme'] . '://' . $parsed['host'] . (isset($parsed['port']) ? ':'.$parsed['port'] : '');
204
  }
205
  $this->path = isset($parsed['path']) ? $parsed['path'] : '/';
206
  $this->query = isset($parsed['query']) ? $parsed['query'] : null;
207
-
208
- if (preg_match('#^' .$this->config->getPathPrefix(). '#i', $this->path)) {
209
- $this->path = preg_replace('#^' .$this->config->getPathPrefix(). '#i', '', $this->path);
210
- }
211
 
212
  if ($this->path === "") {
213
  $this->path = '/';
214
  }
215
 
 
 
 
 
 
 
 
 
216
  $url = $this->getHost() . $this->getPathPrefix() . $this->getPath();
217
  if (!is_null($this->getQuery())) {
218
  $url .= '?'. $this->getQuery();
219
  }
 
 
 
 
 
220
  return $url;
221
  }
222
 
@@ -225,7 +302,7 @@ class Url
225
  *
226
  * @return array
227
  */
228
- public function currentRequestAllUrls()
229
  {
230
  if (defined('WP_CLI') && WP_CLI) {
231
  return array();
@@ -234,22 +311,40 @@ class Url
234
  $urls = $this->allUrls;
235
 
236
  if ($urls === null) {
237
- if ($this->getPath() === null) {
238
- $this->detectUrlDetails();
239
- }
240
 
241
  $urls = [];
242
- $current = $this->getHost() . $this->config->getPathPrefix() . $this->getPath();
243
  if (!is_null($this->getQuery())) {
244
- $current .= '?'. $this->getQuery();
245
  }
246
- $urls[$this->translate->getDefault()] = $current;
247
- foreach ($this->translate->getLanguages() as $language) {
248
- $current = $this->getHost() . $this->config->getPathPrefix() . '/' . $language . $this->getPath();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  if (!is_null($this->getQuery())) {
250
- $current .= '?'. $this->getQuery();
 
 
 
251
  }
252
- $urls[$language] = $current;
253
  }
254
 
255
  $this->allUrls = $urls;
@@ -266,10 +361,10 @@ class Url
266
  public function generateHrefLangsTags()
267
  {
268
  $render = '';
269
- $urls = $this->currentRequestAllUrls();
270
 
271
- foreach ($urls as $language => $url) {
272
- $render .= '<link rel="alternate" href="' .$url. '" hreflang="' .$language. '"/>'."\n";
273
  }
274
 
275
  return $render;
2
 
3
  namespace Weglot\Util;
4
 
5
+ use Weglot\Client\Api\LanguageEntry;
6
+
7
 
8
  /**
9
  * Class Url
26
  */
27
  protected $query = null;
28
 
29
+ /**
30
+ * @var null|string
31
+ */
32
+ protected $fragment = null;
33
+
34
  /**
35
  * @var null|array
36
  */
37
  protected $allUrls = null;
38
 
39
  /**
40
+ * @var LanguageEntry
41
+ */
42
+ protected $currentLanguage = null;
43
+
44
+ /**
45
+ * @var string
46
+ */
47
+ protected $url;
48
+
49
+ /**
50
+ * @var LanguageEntry
51
  */
52
+ protected $originalLanguage;
53
 
54
  /**
55
+ * @var LanguageEntry[]
56
  */
57
+ protected $destinationLanguages;
58
+
59
+ /**
60
+ * @var string
61
+ */
62
+ protected $pathPrefix;
63
+
64
+ /**
65
+ * @var array
66
+ */
67
+ protected $excludedUrls;
68
+
69
+ /**
70
+ * @var array
71
+ */
72
+ protected $customUrls;
73
 
74
  /**
75
  * Url constructor.
76
  * @param string $url Current visited url
77
+ * @param LanguageEntry $originalLanguage Default language represented by ISO 639-1 code
78
+ * @param LanguageEntry[] $destinationLanguages All available languages
79
+ * @param null|string $pathPrefix Prefix to access website root path (ie. : `/my/custom/path`, don't forget: starting `/` and no ending `/`)
80
+ * @param array $excludedUrls Array of excluded URL with regex and languages
81
+ * @param array $customUrls Array of custom URLs (translated URLs)
82
  */
83
+ public function __construct($url, $originalLanguage, $destinationLanguages, $pathPrefix , $excludedUrls, $customUrls)
84
  {
85
+ $this->url = $url;
86
+ $this->originalLanguage = $originalLanguage;
87
+ $this->destinationLanguages = $destinationLanguages;
88
+ $this->pathPrefix = $pathPrefix;
89
+ $this->excludedUrls = $excludedUrls;
90
+ $this->customUrls = $customUrls;
91
+ $this->detectUrlDetails();
92
  }
93
 
94
  /**
96
  */
97
  public function getUrl()
98
  {
99
+ return $this->url;
100
  }
101
 
102
  /**
115
  return $this->path;
116
  }
117
 
 
 
 
 
 
 
 
 
 
 
118
  /**
119
  * @return string
120
  */
121
  public function getPathPrefix()
122
  {
123
+ return $this->pathPrefix;
124
  }
125
 
126
  /**
129
  */
130
  public function setExcludedUrls($excludedUrls)
131
  {
132
+ $this->excludedUrls = $excludedUrls;
 
133
  return $this;
134
  }
135
 
138
  */
139
  public function getDefault()
140
  {
141
+ return $this->originalLanguage;
142
  }
143
 
144
  /**
150
  }
151
 
152
  /**
153
+ * @return null|string
 
154
  */
155
+ public function getFragment()
156
  {
157
+ return $this->fragment;
158
+ }
159
 
160
+ /**
161
+ * @return null|string
162
+ */
163
+ public function getPathAndQuery()
164
+ {
165
+ $pathAndQuery = $this->path;
166
+ if (!is_null($this->getQuery())) {
167
+ $pathAndQuery .= '?'. $this->getQuery();
168
  }
169
+ return $pathAndQuery;
170
+ }
171
 
172
+ /**
173
+ * Returns the destination languages external codes
174
+ * @return string[]
175
+ */
176
+ public function getDestinationLanguagesExternal() {
177
+ return array_map( function( $l ) { return $l->getExternalCode();}, $this->destinationLanguages);
178
+ }
179
+
180
+ /**
181
+ * @param LanguageEntry $language
182
+ * @return bool|string
183
+ */
184
+ public function getForLanguage($language)
185
+ {
186
+ $urls = $this->getAllUrls();
187
+ foreach ($urls as $url) {
188
+ if($url['language'] === $language) {
189
+ return $url['url'];
190
+ }
191
+ }
192
+ return false;
193
  }
194
 
195
  /**
196
  * Check if we need to translate given URL
197
  *
198
+ * @param LanguageEntry $language
199
  * @return bool
200
  */
201
+ public function isTranslableInLanguage( $language )
202
  {
203
+ if($this->getForLanguage($language)) {
204
+ return true;
205
  }
206
+ return false;
207
+ }
208
 
209
+ /**
210
+ * Check if we need to translate given URL
211
+ *
212
+ * @param LanguageEntry $language
213
+ * @return bool
214
+ */
215
+ public function availableInLanguages()
216
+ {
217
+ $availableLanguage = [];
218
+ foreach ($this->destinationLanguages as $destinationLanguage) {
219
+ if($this->getForLanguage($destinationLanguage)) {
220
+ $availableLanguage[] = $destinationLanguage;
221
  }
222
  }
223
+ return $availableLanguage;
 
224
  }
225
 
226
  /**
227
  * Check current locale, based on URI segments from the given URL
228
  *
229
+ * @return LanguageEntry
230
  */
231
+ public function getCurrentLanguage()
232
  {
233
+ return $this->currentLanguage;
 
 
 
 
 
 
 
 
 
234
  }
235
 
236
  /**
244
  return;
245
  }
246
 
247
+ $escapedPathPrefix = Text::escapeForRegex($this->pathPrefix);
248
+ $languages = implode('|', $this->getDestinationLanguagesExternal());
249
+
250
+ $urlNoPrefix = preg_replace('#' . $escapedPathPrefix . '#i', '', $this->getUrl());
251
 
252
+ $uriPath = parse_url($urlNoPrefix, PHP_URL_PATH);
253
+ $uriSegments = explode('/', $uriPath);
254
+
255
+ if (isset($uriSegments[1]) && in_array($uriSegments[1], $this->getDestinationLanguagesExternal() ) ) {
256
+ foreach ($this->destinationLanguages as $language) {
257
+ if($language->getExternalCode() === $uriSegments[1]) {
258
+ $this->currentLanguage = $language;
259
+ }
260
+ }
261
+ } else {
262
+ $this->currentLanguage = $this->originalLanguage;
263
+ }
264
+
265
+ $urlNoPrefixNoLanguage = str_replace('/' . $this->currentLanguage->getExternalCode() . '/', '/', $urlNoPrefix);
266
+
267
+ $parsed = parse_url($urlNoPrefixNoLanguage);
268
 
269
  if(isset($parsed['scheme'])) {
270
  $this->host = $parsed['scheme'] . '://' . $parsed['host'] . (isset($parsed['port']) ? ':'.$parsed['port'] : '');
271
  }
272
  $this->path = isset($parsed['path']) ? $parsed['path'] : '/';
273
  $this->query = isset($parsed['query']) ? $parsed['query'] : null;
274
+ $this->fragment = isset($parsed['fragment']) ? $parsed['fragment'] : null;
 
 
 
275
 
276
  if ($this->path === "") {
277
  $this->path = '/';
278
  }
279
 
280
+ //We need to change the path to the original path if there are custom URL
281
+ if(isset($this->customUrls[$this->currentLanguage->getInternalCode()])) {
282
+ foreach( $this->customUrls[$this->currentLanguage->getInternalCode()] as $translatedURL => $originalURL ) {
283
+ $this->path = str_replace('/' . $originalURL , '/404' ,$this->path); //If we receive a not translated slug we return a 404. For example if we have /fr/products but should have /fr/produits we should have a 404
284
+ $this->path = str_replace('/' . $translatedURL , '/' . $originalURL ,$this->path);
285
+ }
286
+ }
287
+
288
  $url = $this->getHost() . $this->getPathPrefix() . $this->getPath();
289
  if (!is_null($this->getQuery())) {
290
  $url .= '?'. $this->getQuery();
291
  }
292
+
293
+ if (!is_null($this->getFragment())) {
294
+ $url .= '#'. $this->getFragment();
295
+ }
296
+
297
  return $url;
298
  }
299
 
302
  *
303
  * @return array
304
  */
305
+ public function getAllUrls()
306
  {
307
  if (defined('WP_CLI') && WP_CLI) {
308
  return array();
311
  $urls = $this->allUrls;
312
 
313
  if ($urls === null) {
 
 
 
314
 
315
  $urls = [];
316
+ $originalURL = $this->getHost() . $this->getPathPrefix() . $this->getPath();
317
  if (!is_null($this->getQuery())) {
318
+ $originalURL .= '?'. $this->getQuery();
319
  }
320
+ if (!is_null($this->getFragment())) {
321
+ $originalURL .= '#'. $this->getFragment();
322
+ }
323
+
324
+ $urls[] = array( 'language' => $this->originalLanguage, 'url' => $originalURL);
325
+ foreach ($this->destinationLanguages as $language) {
326
+
327
+ foreach ($this->excludedUrls as $excludedUrl) {
328
+ if( $excludedUrl[1] === null || ( is_array($excludedUrl[1]) && in_array($language, $excludedUrl[1]) ) ) {
329
+ if( preg_match('#' . $excludedUrl[0] . '#', $this->getPath()) != 0)
330
+ continue 2;
331
+ }
332
+ }
333
+
334
+ $translatedPath = $this->getPath();
335
+ if(isset($this->customUrls[$language->getInternalCode()])) {
336
+ foreach ($this->customUrls[$language->getInternalCode()] as $translatedURL => $originalURL) {
337
+ $translatedPath = str_replace('/' . $originalURL , '/' . $translatedURL , $translatedPath);
338
+ }
339
+ }
340
+ $url = $this->getHost() . $this->getPathPrefix() . '/' . $language->getExternalCode() . $translatedPath;
341
  if (!is_null($this->getQuery())) {
342
+ $url .= '?'. $this->getQuery();
343
+ }
344
+ if (!is_null($this->getFragment())) {
345
+ $url .= '#'. $this->getFragment();
346
  }
347
+ $urls[] = array( 'language' => $language, 'url' => $url);
348
  }
349
 
350
  $this->allUrls = $urls;
361
  public function generateHrefLangsTags()
362
  {
363
  $render = '';
364
+ $urls = $this->getAllUrls();
365
 
366
+ foreach ($urls as $url) {
367
+ $render .= '<link rel="alternate" href="' . $url['url'] . '" hreflang="' . $url['language']->getExternalCode() . '"/>'."\n";
368
  }
369
 
370
  return $render;
vendor/weglot/weglot-php/src/Util/Url/UrlConfig.php DELETED
@@ -1,73 +0,0 @@
1
- <?php
2
-
3
- namespace Weglot\Util\Url;
4
-
5
- /**
6
- * Class UrlConfig
7
- * @package Weglot\Util\Url
8
- */
9
- class UrlConfig
10
- {
11
- /**
12
- * @var string
13
- */
14
- protected $raw;
15
-
16
- /**
17
- * @var string
18
- */
19
- protected $pathPrefix = '';
20
-
21
- /**
22
- * @var array
23
- */
24
- protected $excludedUrls = [];
25
-
26
- /**
27
- * UrlConfig constructor.
28
- * @param string $raw Current visited url
29
- * @param string $pathPrefix Prefix to access website root path (ie. : `/my/custom/path`, don't forget: starting `/` and no ending `/`)
30
- * @param array $excludedUrls
31
- */
32
- public function __construct($raw, $pathPrefix = '', $excludedUrls = [])
33
- {
34
- $this->raw = $raw;
35
- $this->pathPrefix = $pathPrefix;
36
- $this->excludedUrls = $excludedUrls;
37
- }
38
-
39
- /**
40
- * @return string
41
- */
42
- public function getRaw()
43
- {
44
- return $this->raw;
45
- }
46
-
47
- /**
48
- * @return string
49
- */
50
- public function getPathPrefix()
51
- {
52
- return $this->pathPrefix;
53
- }
54
-
55
- /**
56
- * @param array $excludedUrls
57
- * @return $this
58
- */
59
- public function setExcludedUrls($excludedUrls)
60
- {
61
- $this->excludedUrls = $excludedUrls;
62
-
63
- return $this;
64
- }
65
-
66
- /**
67
- * @return array
68
- */
69
- public function getExcludedUrls()
70
- {
71
- return $this->excludedUrls;
72
- }
73
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/src/Util/Url/UrlTranslate.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
-
3
- namespace Weglot\Util\Url;
4
-
5
- /**
6
- * Class UrlTranslate
7
- * @package Weglot\Util\Url
8
- */
9
- class UrlTranslate
10
- {
11
- /**
12
- * @var string
13
- */
14
- protected $default = 'en';
15
-
16
- /**
17
- * @var array
18
- */
19
- protected $languages = [];
20
-
21
- /**
22
- * UrlTranslate constructor.
23
- * @param string $default Default language represented by ISO 639-1 code
24
- * @param array $languages All available languages
25
- */
26
- public function __construct($default, $languages)
27
- {
28
- $this->default = $default;
29
- $this->languages = $languages;
30
- }
31
-
32
- /**
33
- * @return string
34
- */
35
- public function getDefault()
36
- {
37
- return $this->default;
38
- }
39
-
40
- /**
41
- * @return array
42
- */
43
- public function getLanguages()
44
- {
45
- return $this->languages;
46
- }
47
-
48
- /**
49
- * @param string $code Language represented by ISO 639-1 code
50
- * @return bool
51
- */
52
- public function checkIfAvailable($code)
53
- {
54
- return in_array($code, $this->getLanguages()) || $code === $this->getDefault();
55
- }
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/weglot/weglot-php/tests/unit/Client/Endpoint/LanguagesTest.php CHANGED
@@ -47,23 +47,23 @@ class LanguagesTest extends \Codeception\Test\Unit
47
  public function testSerialize()
48
  {
49
  $json = json_encode($this->languages->getCode('fa'));
50
- $expected = '{"code":"fa","english":"Persian","local":"\u0641\u0627\u0631\u0633\u06cc","rtl":true}';
51
  $this->assertEquals($expected, $json);
52
 
53
  $json = json_encode($this->languages->getCode('fr'));
54
- $expected = '{"code":"fr","english":"French","local":"Fran\u00e7ais","rtl":false}';
55
  $this->assertEquals($expected, $json);
56
 
57
  $json = json_encode($this->languages->getCode('ar'));
58
- $expected = '{"code":"ar","english":"Arabic","local":"\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u200f","rtl":true}';
59
  $this->assertEquals($expected, $json);
60
 
61
  $json = json_encode($this->languages->getCode('he'));
62
- $expected = '{"code":"he","english":"Hebrew","local":"\u05e2\u05d1\u05e8\u05d9\u05ea","rtl":true}';
63
  $this->assertEquals($expected, $json);
64
 
65
  $json = json_encode($this->languages->getCode('no'));
66
- $expected = '{"code":"no","english":"Norwegian","local":"Norsk","rtl":false}';
67
  $this->assertEquals($expected, $json);
68
  }
69
  }
47
  public function testSerialize()
48
  {
49
  $json = json_encode($this->languages->getCode('fa'));
50
+ $expected = '{"internal_code":"fa","external_code":"fa","english":"Persian","local":"\u0641\u0627\u0631\u0633\u06cc","rtl":true}';
51
  $this->assertEquals($expected, $json);
52
 
53
  $json = json_encode($this->languages->getCode('fr'));
54
+ $expected = '{"internal_code":"fr","external_code":"fr","english":"French","local":"Fran\u00e7ais","rtl":false}';
55
  $this->assertEquals($expected, $json);
56
 
57
  $json = json_encode($this->languages->getCode('ar'));
58
+ $expected = '{"internal_code":"ar","external_code":"ar","english":"Arabic","local":"\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u200f","rtl":true}';
59
  $this->assertEquals($expected, $json);
60
 
61
  $json = json_encode($this->languages->getCode('he'));
62
+ $expected = '{"internal_code":"he","external_code":"he","english":"Hebrew","local":"\u05e2\u05d1\u05e8\u05d9\u05ea","rtl":true}';
63
  $this->assertEquals($expected, $json);
64
 
65
  $json = json_encode($this->languages->getCode('no'));
66
+ $expected = '{"internal_code":"no","external_code":"no","english":"Norwegian","local":"Norsk","rtl":false}';
67
  $this->assertEquals($expected, $json);
68
  }
69
  }
vendor/weglot/weglot-php/tests/unit/Util/UrlTest.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
  use Weglot\Util\Url;
 
4
 
5
  class UrlTest extends \Codeception\Test\Unit
6
  {
@@ -9,26 +10,39 @@ class UrlTest extends \Codeception\Test\Unit
9
  */
10
  protected $tester;
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  public function testSimpleUrlDefaultEnWithEsUrl()
13
  {
14
  $profile = [
15
  'url' => 'https://weglot.com/es/pricing',
16
- 'default' => 'en',
17
- 'languages' => ['fr', 'de', 'es'],
18
  'prefix' => '',
19
  'exclude' => [],
20
  'results' => [
21
  'getHost' => 'https://weglot.com',
22
  'getPathPrefix' => '',
23
  'getPath' => '/pricing',
24
- 'isTranslable' => true,
25
- 'detectCurrentLanguage' => 'es',
26
  'detectBaseUrl' => 'https://weglot.com/pricing',
27
- 'currentRequestAllUrls' => [
28
- 'en' => 'https://weglot.com/pricing',
29
- 'fr' => 'https://weglot.com/fr/pricing',
30
- 'de' => 'https://weglot.com/de/pricing',
31
- 'es' => 'https://weglot.com/es/pricing'
32
  ]
33
  ]
34
  ];
@@ -41,8 +55,8 @@ class UrlTest extends \Codeception\Test\Unit
41
  {
42
  $profile = [
43
  'url' => 'https://www.ratp.fr/en/horaires',
44
- 'default' => 'fr',
45
- 'languages' => ['en'],
46
  'prefix' => '',
47
  'exclude' => [],
48
  'results' => [
@@ -50,11 +64,10 @@ class UrlTest extends \Codeception\Test\Unit
50
  'getPathPrefix' => '',
51
  'detectBaseUrl' => 'https://www.ratp.fr/horaires',
52
  'getPath' => '/horaires',
53
- 'isTranslable' => true,
54
- 'detectCurrentLanguage' => 'en',
55
- 'currentRequestAllUrls' => [
56
- 'fr' => 'https://www.ratp.fr/horaires',
57
- 'en' => 'https://www.ratp.fr/en/horaires',
58
  ]
59
  ]
60
  ];
@@ -67,8 +80,8 @@ class UrlTest extends \Codeception\Test\Unit
67
  {
68
  $profile = [
69
  'url' => 'https://www.ratp.fr:3000/en/horaires',
70
- 'default' => 'fr',
71
- 'languages' => ['en'],
72
  'prefix' => '',
73
  'exclude' => [],
74
  'results' => [
@@ -76,11 +89,10 @@ class UrlTest extends \Codeception\Test\Unit
76
  'getPathPrefix' => '',
77
  'detectBaseUrl' => 'https://www.ratp.fr:3000/horaires',
78
  'getPath' => '/horaires',
79
- 'isTranslable' => true,
80
- 'detectCurrentLanguage' => 'en',
81
- 'currentRequestAllUrls' => [
82
- 'fr' => 'https://www.ratp.fr:3000/horaires',
83
- 'en' => 'https://www.ratp.fr:3000/en/horaires',
84
  ]
85
  ]
86
  ];
@@ -93,8 +105,8 @@ class UrlTest extends \Codeception\Test\Unit
93
  {
94
  $profile = [
95
  'url' => 'https://www.ratp.fr/horaires',
96
- 'default' => 'fr',
97
- 'languages' => ['en'],
98
  'prefix' => '',
99
  'exclude' => [],
100
  'results' => [
@@ -102,11 +114,10 @@ class UrlTest extends \Codeception\Test\Unit
102
  'getPathPrefix' => '',
103
  'detectBaseUrl' => 'https://www.ratp.fr/horaires',
104
  'getPath' => '/horaires',
105
- 'isTranslable' => true,
106
- 'detectCurrentLanguage' => 'fr',
107
- 'currentRequestAllUrls' => [
108
- 'fr' => 'https://www.ratp.fr/horaires',
109
- 'en' => 'https://www.ratp.fr/en/horaires',
110
  ]
111
  ]
112
  ];
@@ -119,22 +130,21 @@ class UrlTest extends \Codeception\Test\Unit
119
  {
120
  $profile = [
121
  'url' => 'https://weglot.com/web/es/pricing',
122
- 'default' => 'en',
123
- 'languages' => ['fr', 'de', 'es'],
124
  'prefix' => '/web',
125
  'exclude' => [],
126
  'results' => [
127
  'getHost' => 'https://weglot.com',
128
  'getPathPrefix' => '/web',
129
  'getPath' => '/pricing',
130
- 'isTranslable' => true,
131
- 'detectCurrentLanguage' => 'es',
132
  'detectBaseUrl' => 'https://weglot.com/web/pricing',
133
- 'currentRequestAllUrls' => [
134
- 'en' => 'https://weglot.com/web/pricing',
135
- 'fr' => 'https://weglot.com/web/fr/pricing',
136
- 'de' => 'https://weglot.com/web/de/pricing',
137
- 'es' => 'https://weglot.com/web/es/pricing'
138
  ]
139
  ]
140
  ];
@@ -147,22 +157,21 @@ class UrlTest extends \Codeception\Test\Unit
147
  {
148
  $profile = [
149
  'url' => 'http://weglotmultiv2.local/othersite/',
150
- 'default' => 'en',
151
- 'languages' => ['fr', 'de', 'es'],
152
  'prefix' => '/othersite',
153
  'exclude' => [],
154
  'results' => [
155
  'getHost' => 'http://weglotmultiv2.local',
156
  'getPathPrefix' => '/othersite',
157
  'getPath' => '/',
158
- 'isTranslable' => true,
159
- 'detectCurrentLanguage' => 'en',
160
  'detectBaseUrl' => 'http://weglotmultiv2.local/othersite/',
161
- 'currentRequestAllUrls' => [
162
- 'en' => 'http://weglotmultiv2.local/othersite/',
163
- 'fr' => 'http://weglotmultiv2.local/othersite/fr/',
164
- 'de' => 'http://weglotmultiv2.local/othersite/de/',
165
- 'es' => 'http://weglotmultiv2.local/othersite/es/'
166
  ]
167
  ]
168
  ];
@@ -175,22 +184,21 @@ class UrlTest extends \Codeception\Test\Unit
175
  {
176
  $profile = [
177
  'url' => 'https://weglot.com/web',
178
- 'default' => 'en',
179
- 'languages' => ['fr', 'de', 'es'],
180
  'prefix' => '/web',
181
  'exclude' => [],
182
  'results' => [
183
  'getHost' => 'https://weglot.com',
184
  'getPathPrefix' => '/web',
185
  'getPath' => '/',
186
- 'isTranslable' => true,
187
- 'detectCurrentLanguage' => 'en',
188
  'detectBaseUrl' => 'https://weglot.com/web/',
189
- 'currentRequestAllUrls' => [
190
- 'en' => 'https://weglot.com/web/',
191
- 'fr' => 'https://weglot.com/web/fr/',
192
- 'de' => 'https://weglot.com/web/de/',
193
- 'es' => 'https://weglot.com/web/es/'
194
  ]
195
  ]
196
  ];
@@ -203,22 +211,21 @@ class UrlTest extends \Codeception\Test\Unit
203
  {
204
  $profile = [
205
  'url' => 'https://weglot.com:8080/web/es/',
206
- 'default' => 'en',
207
- 'languages' => ['fr', 'de', 'es'],
208
  'prefix' => '/web',
209
  'exclude' => [],
210
  'results' => [
211
  'getHost' => 'https://weglot.com:8080',
212
  'getPathPrefix' => '/web',
213
  'getPath' => '/',
214
- 'isTranslable' => true,
215
- 'detectCurrentLanguage' => 'es',
216
  'detectBaseUrl' => 'https://weglot.com:8080/web/',
217
- 'currentRequestAllUrls' => [
218
- 'en' => 'https://weglot.com:8080/web/',
219
- 'fr' => 'https://weglot.com:8080/web/fr/',
220
- 'de' => 'https://weglot.com:8080/web/de/',
221
- 'es' => 'https://weglot.com:8080/web/es/'
222
  ]
223
  ]
224
  ];
@@ -231,23 +238,22 @@ class UrlTest extends \Codeception\Test\Unit
231
  {
232
  $profile = [
233
  'url' => 'https://weglot.com/fr/pricing',
234
- 'default' => 'en',
235
- 'languages' => ['fr', 'kr'],
236
  'prefix' => '',
237
  'exclude' => [
238
- '\/admin\/.*'
239
  ],
240
  'results' => [
241
  'getHost' => 'https://weglot.com',
242
  'getPathPrefix' => '',
243
  'getPath' => '/pricing',
244
- 'isTranslable' => true,
245
- 'detectCurrentLanguage' => 'fr',
246
  'detectBaseUrl' => 'https://weglot.com/pricing',
247
- 'currentRequestAllUrls' => [
248
- 'en' => 'https://weglot.com/pricing',
249
- 'fr' => 'https://weglot.com/fr/pricing',
250
- 'kr' => 'https://weglot.com/kr/pricing'
251
  ]
252
  ]
253
  ];
@@ -257,12 +263,9 @@ class UrlTest extends \Codeception\Test\Unit
257
 
258
  $profile['url'] = 'https://weglot.com/fr/admin/dashboard';
259
  $profile['results']['getPath'] = '/admin/dashboard';
260
- $profile['results']['isTranslable'] = false;
261
  $profile['results']['detectBaseUrl'] = 'https://weglot.com/admin/dashboard';
262
- $profile['results']['currentRequestAllUrls'] = [
263
- 'en' => 'https://weglot.com/admin/dashboard',
264
- 'fr' => 'https://weglot.com/fr/admin/dashboard',
265
- 'kr' => 'https://weglot.com/kr/admin/dashboard'
266
  ];
267
 
268
  $url = $this->_urlInstance($profile);
@@ -273,24 +276,21 @@ class UrlTest extends \Codeception\Test\Unit
273
  {
274
  $profile = [
275
  'url' => 'https://weglot.com/kr/pricing',
276
- 'default' => 'en',
277
- 'languages' => ['fr', 'kr'],
278
  'prefix' => '',
279
  'exclude' => [
280
- '^(?!/rgpd-wordpress/?|/optimiser-wordpress/?).*$'
281
  ],
282
  'results' => [
283
  'getHost' => 'https://weglot.com',
284
  'getPathPrefix' => '',
285
  'getPath' => '/pricing',
286
- 'isTranslable' => false,
287
- 'detectCurrentLanguage' => 'kr',
288
  'detectBaseUrl' => 'https://weglot.com/pricing',
289
- 'currentRequestAllUrls' => [
290
- 'en' => 'https://weglot.com/pricing',
291
- 'fr' => 'https://weglot.com/fr/pricing',
292
- 'kr' => 'https://weglot.com/kr/pricing'
293
- ]
294
  ]
295
  ];
296
 
@@ -299,12 +299,11 @@ class UrlTest extends \Codeception\Test\Unit
299
 
300
  $profile['url'] = 'https://weglot.com/kr/rgpd-wordpress';
301
  $profile['results']['getPath'] = '/rgpd-wordpress';
302
- $profile['results']['isTranslable'] = true;
303
  $profile['results']['detectBaseUrl'] = 'https://weglot.com/rgpd-wordpress';
304
- $profile['results']['currentRequestAllUrls'] = [
305
- 'en' => 'https://weglot.com/rgpd-wordpress',
306
- 'fr' => 'https://weglot.com/fr/rgpd-wordpress',
307
- 'kr' => 'https://weglot.com/kr/rgpd-wordpress'
308
  ];
309
 
310
  $url = $this->_urlInstance($profile);
@@ -315,8 +314,8 @@ class UrlTest extends \Codeception\Test\Unit
315
  {
316
  $profile = [
317
  'url' => 'https://weglot.com/landing/fr/how-to-manage-your-translations',
318
- 'default' => 'en',
319
- 'languages' => ['fr', 'kr'],
320
  'prefix' => '/landing',
321
  'exclude' => [
322
  '\/admin\/.*'
@@ -325,13 +324,12 @@ class UrlTest extends \Codeception\Test\Unit
325
  'getHost' => 'https://weglot.com',
326
  'getPathPrefix' => '/landing',
327
  'getPath' => '/how-to-manage-your-translations',
328
- 'isTranslable' => true,
329
- 'detectCurrentLanguage' => 'fr',
330
  'detectBaseUrl' => 'https://weglot.com/landing/how-to-manage-your-translations',
331
- 'currentRequestAllUrls' => [
332
- 'en' => 'https://weglot.com/landing/how-to-manage-your-translations',
333
- 'fr' => 'https://weglot.com/landing/fr/how-to-manage-your-translations',
334
- 'kr' => 'https://weglot.com/landing/kr/how-to-manage-your-translations'
335
  ]
336
  ]
337
  ];
@@ -341,12 +339,11 @@ class UrlTest extends \Codeception\Test\Unit
341
 
342
  $profile['url'] = 'https://weglot.com/landing/fr/admin/how-to-manage-your-translations';
343
  $profile['results']['getPath'] = '/admin/how-to-manage-your-translations';
344
- $profile['results']['isTranslable'] = false;
345
  $profile['results']['detectBaseUrl'] = 'https://weglot.com/landing/admin/how-to-manage-your-translations';
346
- $profile['results']['currentRequestAllUrls'] = [
347
- 'en' => 'https://weglot.com/landing/admin/how-to-manage-your-translations',
348
- 'fr' => 'https://weglot.com/landing/fr/admin/how-to-manage-your-translations',
349
- 'kr' => 'https://weglot.com/landing/kr/admin/how-to-manage-your-translations'
350
  ];
351
 
352
  $url = $this->_urlInstance($profile);
@@ -357,8 +354,8 @@ class UrlTest extends \Codeception\Test\Unit
357
  {
358
  $profile = [
359
  'url' => 'https://www.ratp.fr/en/horaires?from=2018-06-04&to=2018-06-05',
360
- 'default' => 'fr',
361
- 'languages' => ['en'],
362
  'prefix' => '',
363
  'exclude' => [],
364
  'results' => [
@@ -366,11 +363,10 @@ class UrlTest extends \Codeception\Test\Unit
366
  'getPathPrefix' => '',
367
  'detectBaseUrl' => 'https://www.ratp.fr/horaires?from=2018-06-04&to=2018-06-05',
368
  'getPath' => '/horaires',
369
- 'isTranslable' => true,
370
- 'detectCurrentLanguage' => 'en',
371
- 'currentRequestAllUrls' => [
372
- 'fr' => 'https://www.ratp.fr/horaires?from=2018-06-04&to=2018-06-05',
373
- 'en' => 'https://www.ratp.fr/en/horaires?from=2018-06-04&to=2018-06-05',
374
  ]
375
  ]
376
  ];
@@ -389,9 +385,10 @@ class UrlTest extends \Codeception\Test\Unit
389
  $profile['url'],
390
  $profile['default'],
391
  $profile['languages'],
392
- $profile['prefix']
393
- ))
394
- ->setExcludedUrls($profile['exclude']);
 
395
  }
396
 
397
  /**
@@ -401,8 +398,8 @@ class UrlTest extends \Codeception\Test\Unit
401
  protected function _generateHrefLangs(array $currentRequestAllUrls)
402
  {
403
  $render = '';
404
- foreach ($currentRequestAllUrls as $language => $url) {
405
- $render .= '<link rel="alternate" href="' .$url. '" hreflang="' .$language. '"/>'."\n";
406
  }
407
  return $render;
408
  }
@@ -416,14 +413,10 @@ class UrlTest extends \Codeception\Test\Unit
416
  {
417
  // cloned $url, to be sure to have a `null` $baseUrl
418
  $cloned = clone $url;
419
- $this->assertEquals($profile['results']['currentRequestAllUrls'], $cloned->currentRequestAllUrls());
420
 
421
  // cloned $url, to be sure to have a `null` $baseUrl
422
  $cloned = clone $url;
423
- $this->assertEquals($profile['results']['isTranslable'], $cloned->isTranslable());
424
-
425
- $this->assertNull($url->getHost());
426
- $this->assertNull($url->getPath());
427
 
428
  $this->assertEquals($profile['results']['detectBaseUrl'], $url->detectUrlDetails());
429
 
@@ -431,15 +424,13 @@ class UrlTest extends \Codeception\Test\Unit
431
  $this->assertEquals($profile['results']['getPathPrefix'], $url->getPathPrefix());
432
  $this->assertEquals($profile['results']['getPath'], $url->getPath());
433
 
434
- $this->assertEquals($profile['results']['isTranslable'], $url->isTranslable());
435
-
436
- $this->assertEquals($profile['results']['detectCurrentLanguage'], $url->detectCurrentLanguage());
437
 
438
- $this->assertEquals($profile['results']['currentRequestAllUrls'], $url->currentRequestAllUrls());
439
- $this->assertEquals($this->_generateHrefLangs($profile['results']['currentRequestAllUrls']), $url->generateHrefLangsTags());
440
 
441
- foreach ($profile['results']['currentRequestAllUrls'] as $lang => $expected) {
442
- $this->assertEquals($expected, $url->getForLanguage($lang));
443
  }
444
  }
445
  }
1
  <?php
2
 
3
  use Weglot\Util\Url;
4
+ use Weglot\Client\Api\LanguageEntry;
5
 
6
  class UrlTest extends \Codeception\Test\Unit
7
  {
10
  */
11
  protected $tester;
12
 
13
+ protected $languages;
14
+
15
+ public function __construct($name = null, array $data = [], $dataName = '')
16
+ {
17
+ $this->languages = array (
18
+ 'en' => new LanguageEntry( 'en' , 'en' , 'English' , 'English' , false),
19
+ 'fr' => new LanguageEntry( 'fr' , 'fr' , 'French' , 'Français' , false),
20
+ 'es' => new LanguageEntry( 'es' , 'es' , 'Spanish' , 'Espanol' , false),
21
+ 'de' => new LanguageEntry( 'de' , 'de' , 'German' , 'Deutsch' , false),
22
+ 'kr' => new LanguageEntry( 'kr' , 'kr' , 'unknown' , 'unknown' , false),
23
+ );
24
+ parent::__construct($name, $data, $dataName);
25
+ }
26
+
27
  public function testSimpleUrlDefaultEnWithEsUrl()
28
  {
29
  $profile = [
30
  'url' => 'https://weglot.com/es/pricing',
31
+ 'default' => $this->languages['en'],
32
+ 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
33
  'prefix' => '',
34
  'exclude' => [],
35
  'results' => [
36
  'getHost' => 'https://weglot.com',
37
  'getPathPrefix' => '',
38
  'getPath' => '/pricing',
39
+ 'getCurrentLanguage' => $this->languages['es'],
 
40
  'detectBaseUrl' => 'https://weglot.com/pricing',
41
+ 'getAllUrls' => [
42
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/pricing'),
43
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/fr/pricing'),
44
+ array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com/de/pricing'),
45
+ array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com/es/pricing')
46
  ]
47
  ]
48
  ];
55
  {
56
  $profile = [
57
  'url' => 'https://www.ratp.fr/en/horaires',
58
+ 'default' => $this->languages['fr'],
59
+ 'languages' => [ $this->languages['en']],
60
  'prefix' => '',
61
  'exclude' => [],
62
  'results' => [
64
  'getPathPrefix' => '',
65
  'detectBaseUrl' => 'https://www.ratp.fr/horaires',
66
  'getPath' => '/horaires',
67
+ 'getCurrentLanguage' => $this->languages['en'],
68
+ 'getAllUrls' => [
69
+ array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr/horaires'),
70
+ array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr/en/horaires'),
 
71
  ]
72
  ]
73
  ];
80
  {
81
  $profile = [
82
  'url' => 'https://www.ratp.fr:3000/en/horaires',
83
+ 'default' => $this->languages['fr'],
84
+ 'languages' => [ $this->languages['en']],
85
  'prefix' => '',
86
  'exclude' => [],
87
  'results' => [
89
  'getPathPrefix' => '',
90
  'detectBaseUrl' => 'https://www.ratp.fr:3000/horaires',
91
  'getPath' => '/horaires',
92
+ 'getCurrentLanguage' => $this->languages['en'],
93
+ 'getAllUrls' => [
94
+ array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr:3000/horaires'),
95
+ array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr:3000/en/horaires'),
 
96
  ]
97
  ]
98
  ];
105
  {
106
  $profile = [
107
  'url' => 'https://www.ratp.fr/horaires',
108
+ 'default' => $this->languages['fr'],
109
+ 'languages' => [ $this->languages['en']],
110
  'prefix' => '',
111
  'exclude' => [],
112
  'results' => [
114
  'getPathPrefix' => '',
115
  'detectBaseUrl' => 'https://www.ratp.fr/horaires',
116
  'getPath' => '/horaires',
117
+ 'getCurrentLanguage' => $this->languages['fr'],
118
+ 'getAllUrls' => [
119
+ array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr/horaires'),
120
+ array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr/en/horaires')
 
121
  ]
122
  ]
123
  ];
130
  {
131
  $profile = [
132
  'url' => 'https://weglot.com/web/es/pricing',
133
+ 'default' => $this->languages['en'],
134
+ 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
135
  'prefix' => '/web',
136
  'exclude' => [],
137
  'results' => [
138
  'getHost' => 'https://weglot.com',
139
  'getPathPrefix' => '/web',
140
  'getPath' => '/pricing',
141
+ 'getCurrentLanguage' => $this->languages['es'],
 
142
  'detectBaseUrl' => 'https://weglot.com/web/pricing',
143
+ 'getAllUrls' => [
144
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/web/pricing'),
145
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/web/fr/pricing'),
146
+ array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com/web/de/pricing'),
147
+ array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com/web/es/pricing')
148
  ]
149
  ]
150
  ];
157
  {
158
  $profile = [
159
  'url' => 'http://weglotmultiv2.local/othersite/',
160
+ 'default' => $this->languages['en'],
161
+ 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
162
  'prefix' => '/othersite',
163
  'exclude' => [],
164
  'results' => [
165
  'getHost' => 'http://weglotmultiv2.local',
166
  'getPathPrefix' => '/othersite',
167
  'getPath' => '/',
168
+ 'getCurrentLanguage' => $this->languages['en'],
 
169
  'detectBaseUrl' => 'http://weglotmultiv2.local/othersite/',
170
+ 'getAllUrls' => [
171
+ array( 'language' => $this->languages['en'], 'url' => 'http://weglotmultiv2.local/othersite/'),
172
+ array( 'language' => $this->languages['fr'], 'url' => 'http://weglotmultiv2.local/othersite/fr/'),
173
+ array( 'language' => $this->languages['de'], 'url' => 'http://weglotmultiv2.local/othersite/de/'),
174
+ array( 'language' => $this->languages['es'], 'url' => 'http://weglotmultiv2.local/othersite/es/')
175
  ]
176
  ]
177
  ];
184
  {
185
  $profile = [
186
  'url' => 'https://weglot.com/web',
187
+ 'default' => $this->languages['en'],
188
+ 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
189
  'prefix' => '/web',
190
  'exclude' => [],
191
  'results' => [
192
  'getHost' => 'https://weglot.com',
193
  'getPathPrefix' => '/web',
194
  'getPath' => '/',
195
+ 'getCurrentLanguage' => $this->languages['en'],
 
196
  'detectBaseUrl' => 'https://weglot.com/web/',
197
+ 'getAllUrls' => [
198
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/web/'),
199
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/web/fr/'),
200
+ array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com/web/de/'),
201
+ array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com/web/es/')
202
  ]
203
  ]
204
  ];
211
  {
212
  $profile = [
213
  'url' => 'https://weglot.com:8080/web/es/',
214
+ 'default' => $this->languages['en'],
215
+ 'languages' => [ $this->languages['fr'], $this->languages['de'], $this->languages['es']],
216
  'prefix' => '/web',
217
  'exclude' => [],
218
  'results' => [
219
  'getHost' => 'https://weglot.com:8080',
220
  'getPathPrefix' => '/web',
221
  'getPath' => '/',
222
+ 'getCurrentLanguage' => $this->languages['es'],
 
223
  'detectBaseUrl' => 'https://weglot.com:8080/web/',
224
+ 'getAllUrls' => [
225
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com:8080/web/'),
226
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com:8080/web/fr/'),
227
+ array( 'language' => $this->languages['de'], 'url' => 'https://weglot.com:8080/web/de/'),
228
+ array( 'language' => $this->languages['es'], 'url' => 'https://weglot.com:8080/web/es/')
229
  ]
230
  ]
231
  ];
238
  {
239
  $profile = [
240
  'url' => 'https://weglot.com/fr/pricing',
241
+ 'default' => $this->languages['en'],
242
+ 'languages' => [ $this->languages['fr'], $this->languages['kr']],
243
  'prefix' => '',
244
  'exclude' => [
245
+ [ '\/admin\/.*' , null ]
246
  ],
247
  'results' => [
248
  'getHost' => 'https://weglot.com',
249
  'getPathPrefix' => '',
250
  'getPath' => '/pricing',
251
+ 'getCurrentLanguage' => $this->languages['fr'],
 
252
  'detectBaseUrl' => 'https://weglot.com/pricing',
253
+ 'getAllUrls' => [
254
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/pricing'),
255
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/fr/pricing'),
256
+ array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/kr/pricing')
257
  ]
258
  ]
259
  ];
263
 
264
  $profile['url'] = 'https://weglot.com/fr/admin/dashboard';
265
  $profile['results']['getPath'] = '/admin/dashboard';
 
266
  $profile['results']['detectBaseUrl'] = 'https://weglot.com/admin/dashboard';
267
+ $profile['results']['getAllUrls'] = [
268
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/admin/dashboard'),
 
 
269
  ];
270
 
271
  $url = $this->_urlInstance($profile);
276
  {
277
  $profile = [
278
  'url' => 'https://weglot.com/kr/pricing',
279
+ 'default' => $this->languages['en'],
280
+ 'languages' => [ $this->languages['fr'], $this->languages['kr']],
281
  'prefix' => '',
282
  'exclude' => [
283
+ ['^(?!/rgpd-wordpress/?|/optimiser-wordpress/?).*$' , null ]
284
  ],
285
  'results' => [
286
  'getHost' => 'https://weglot.com',
287
  'getPathPrefix' => '',
288
  'getPath' => '/pricing',
289
+ 'getCurrentLanguage' => $this->languages['kr'],
 
290
  'detectBaseUrl' => 'https://weglot.com/pricing',
291
+ 'getAllUrls' => [
292
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/pricing'),
293
+ ] // because it's excluded
 
 
294
  ]
295
  ];
296
 
299
 
300
  $profile['url'] = 'https://weglot.com/kr/rgpd-wordpress';
301
  $profile['results']['getPath'] = '/rgpd-wordpress';
 
302
  $profile['results']['detectBaseUrl'] = 'https://weglot.com/rgpd-wordpress';
303
+ $profile['results']['getAllUrls'] = [
304
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/rgpd-wordpress'),
305
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/fr/rgpd-wordpress'),
306
+ array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/kr/rgpd-wordpress')
307
  ];
308
 
309
  $url = $this->_urlInstance($profile);
314
  {
315
  $profile = [
316
  'url' => 'https://weglot.com/landing/fr/how-to-manage-your-translations',
317
+ 'default' => $this->languages['en'],
318
+ 'languages' => [ $this->languages['fr'], $this->languages['kr']],
319
  'prefix' => '/landing',
320
  'exclude' => [
321
  '\/admin\/.*'
324
  'getHost' => 'https://weglot.com',
325
  'getPathPrefix' => '/landing',
326
  'getPath' => '/how-to-manage-your-translations',
327
+ 'getCurrentLanguage' => $this->languages['fr'],
 
328
  'detectBaseUrl' => 'https://weglot.com/landing/how-to-manage-your-translations',
329
+ 'getAllUrls' => [
330
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/landing/how-to-manage-your-translations'),
331
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/landing/fr/how-to-manage-your-translations'),
332
+ array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/landing/kr/how-to-manage-your-translations')
333
  ]
334
  ]
335
  ];
339
 
340
  $profile['url'] = 'https://weglot.com/landing/fr/admin/how-to-manage-your-translations';
341
  $profile['results']['getPath'] = '/admin/how-to-manage-your-translations';
 
342
  $profile['results']['detectBaseUrl'] = 'https://weglot.com/landing/admin/how-to-manage-your-translations';
343
+ $profile['results']['getAllUrls'] = [
344
+ array( 'language' => $this->languages['en'], 'url' => 'https://weglot.com/landing/admin/how-to-manage-your-translations'),
345
+ array( 'language' => $this->languages['fr'], 'url' => 'https://weglot.com/landing/fr/admin/how-to-manage-your-translations'),
346
+ array( 'language' => $this->languages['kr'], 'url' => 'https://weglot.com/landing/kr/admin/how-to-manage-your-translations')
347
  ];
348
 
349
  $url = $this->_urlInstance($profile);
354
  {
355
  $profile = [
356
  'url' => 'https://www.ratp.fr/en/horaires?from=2018-06-04&to=2018-06-05',
357
+ 'default' => $this->languages['fr'],
358
+ 'languages' => [ $this->languages['en']],
359
  'prefix' => '',
360
  'exclude' => [],
361
  'results' => [
363
  'getPathPrefix' => '',
364
  'detectBaseUrl' => 'https://www.ratp.fr/horaires?from=2018-06-04&to=2018-06-05',
365
  'getPath' => '/horaires',
366
+ 'getCurrentLanguage' => $this->languages['en'],
367
+ 'getAllUrls' => [
368
+ array( 'language' => $this->languages['fr'], 'url' => 'https://www.ratp.fr/horaires?from=2018-06-04&to=2018-06-05'),
369
+ array( 'language' => $this->languages['en'], 'url' => 'https://www.ratp.fr/en/horaires?from=2018-06-04&to=2018-06-05'),
 
370
  ]
371
  ]
372
  ];
385
  $profile['url'],
386
  $profile['default'],
387
  $profile['languages'],
388
+ $profile['prefix'],
389
+ $profile['exclude'],
390
+ null
391
+ ));
392
  }
393
 
394
  /**
398
  protected function _generateHrefLangs(array $currentRequestAllUrls)
399
  {
400
  $render = '';
401
+ foreach ($currentRequestAllUrls as $urlArray) {
402
+ $render .= '<link rel="alternate" href="' .$urlArray['url']. '" hreflang="' .$urlArray['language']->getExternalCode(). '"/>'."\n";
403
  }
404
  return $render;
405
  }
413
  {
414
  // cloned $url, to be sure to have a `null` $baseUrl
415
  $cloned = clone $url;
416
+ $this->assertEquals($profile['results']['getAllUrls'], $cloned->getAllUrls());
417
 
418
  // cloned $url, to be sure to have a `null` $baseUrl
419
  $cloned = clone $url;
 
 
 
 
420
 
421
  $this->assertEquals($profile['results']['detectBaseUrl'], $url->detectUrlDetails());
422
 
424
  $this->assertEquals($profile['results']['getPathPrefix'], $url->getPathPrefix());
425
  $this->assertEquals($profile['results']['getPath'], $url->getPath());
426
 
427
+ $this->assertEquals($profile['results']['getCurrentLanguage'], $url->getCurrentLanguage());
 
 
428
 
429
+ $this->assertEquals($profile['results']['getAllUrls'], $url->getAllUrls());
430
+ $this->assertEquals($this->_generateHrefLangs($profile['results']['getAllUrls']), $url->generateHrefLangsTags());
431
 
432
+ foreach ($profile['results']['getAllUrls'] as $urlArray) {
433
+ $this->assertEquals($urlArray['url'], $url->getForLanguage($urlArray['language']));
434
  }
435
  }
436
  }
webpack.config.js CHANGED
@@ -8,7 +8,6 @@ module.exports = {
8
  entry: {
9
  "front-js": "./app/javascripts/front.js",
10
  "admin-js": "./app/javascripts/index.js",
11
- "metaboxes-js": "./app/javascripts/metaboxes.js",
12
  "front-css": "./app/styles/index.scss",
13
  "admin-css": "./app/styles/admin.scss",
14
  "front-amp-css": "./app/styles/amp.scss",
8
  entry: {
9
  "front-js": "./app/javascripts/front.js",
10
  "admin-js": "./app/javascripts/index.js",
 
11
  "front-css": "./app/styles/index.scss",
12
  "admin-css": "./app/styles/admin.scss",
13
  "front-amp-css": "./app/styles/amp.scss",
weglot-functions.php CHANGED
@@ -1,15 +1,20 @@
1
  <?php
2
 
 
 
 
 
3
  if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
 
7
  /**
8
  * Get a service Weglot
9
- * @since 2.0
10
- *
11
  * @param string $service
12
  * @return object
 
 
 
13
  */
14
  function weglot_get_service( $service ) {
15
  return Context_Weglot::weglot_get_context()->get_service( $service );
@@ -17,9 +22,10 @@ function weglot_get_service( $service ) {
17
 
18
  /**
19
  * Get all options
 
 
20
  * @since 2.0
21
  *
22
- * @return array
23
  */
24
  function weglot_get_options() {
25
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_options();
@@ -27,9 +33,10 @@ function weglot_get_options() {
27
 
28
  /**
29
  * Get option
30
- * @since 2.0
31
  * @param string $key
32
- * @return any
 
 
33
  */
34
  function weglot_get_option( $key ) {
35
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_option( $key );
@@ -37,8 +44,9 @@ function weglot_get_option( $key ) {
37
 
38
  /**
39
  * Get original language
40
- * @since 2.0
41
  * @return string
 
 
42
  */
43
  function weglot_get_original_language() {
44
  return weglot_get_option( 'original_language' );
@@ -46,42 +54,24 @@ function weglot_get_original_language() {
46
 
47
  /**
48
  * Get current language
49
- * @since 2.0
50
  * @return string
 
 
51
  */
52
  function weglot_get_current_language() {
53
- return Context_Weglot::weglot_get_context()->get_service( 'Request_Url_Service_Weglot' )->get_current_language();
54
  }
55
 
56
  /**
57
  * Get destination language with filters
58
- * @since 2.0
59
  * @return string
 
 
60
  */
61
  function weglot_get_destination_languages() {
62
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_destination_languages();
63
  }
64
 
65
- /**
66
- * Get currrent destinations language with filters enable on specific URL
67
- * @since 3.2.0
68
- * @return array
69
- */
70
- function weglot_get_current_destination_languages( $current_url = null ) {
71
- return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_current_destination_languages( $current_url );
72
- }
73
-
74
- /**
75
- * @since 2.3.0
76
- * @return array
77
- */
78
- function weglot_get_all_languages_configured() {
79
- $destinations = weglot_get_current_destination_languages();
80
- $original = weglot_get_original_language();
81
- array_unshift( $destinations, $original );
82
- return $destinations;
83
- }
84
-
85
  /**
86
  * Get Request Url Service
87
  * @since 2.0
@@ -91,47 +81,16 @@ function weglot_get_request_url_service() {
91
  return Context_Weglot::weglot_get_context()->get_service( 'Request_Url_Service_Weglot' );
92
  }
93
 
94
- /**
95
- * Get an array with current and original language
96
- * @since 2.0
97
- * @return array
98
- */
99
- function weglot_get_current_and_original_language() {
100
- return [
101
- 'current' => weglot_get_current_language(),
102
- 'original' => weglot_get_original_language(),
103
- ];
104
- }
105
-
106
  /**
107
  * Get languages available on Weglot
 
 
108
  * @since 2.0
109
- * @return array
110
  */
111
  function weglot_get_languages_available() {
112
  return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_languages_available();
113
  }
114
 
115
- /**
116
- * @since 2.0
117
- *
118
- * @param null|string $type
119
- * @return array
120
- */
121
- function weglot_get_languages_configured( $type = null ) {
122
- return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_languages_configured( $type );
123
- }
124
-
125
- /**
126
- * @since 2.0
127
- *
128
- * @param null|string $type
129
- * @return array
130
- */
131
- function weglot_get_current_languages_configured( $type = null ) {
132
- return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_current_languages_configured( $type );
133
- }
134
-
135
  /**
136
  * Get button selector HTML
137
  * @since 2.0
@@ -167,7 +126,7 @@ function weglot_get_translate_amp_translation() {
167
  * @return string
168
  */
169
  function weglot_get_current_full_url() {
170
- return weglot_create_url_object( weglot_get_request_url_service()->get_full_url() )->getForLanguage( weglot_get_current_language() );
171
  }
172
 
173
  /**
@@ -199,24 +158,6 @@ function weglot_has_auto_redirect() {
199
  return weglot_get_option( 'auto_redirect' );
200
  }
201
 
202
- /**
203
- * @since 2.0.2
204
- * @return boolean
205
- */
206
- function weglot_current_url_is_eligible() {
207
- $full_url = weglot_get_full_url_no_language();
208
- return weglot_is_eligible_url( $full_url );
209
- }
210
-
211
-
212
- /**
213
- * @since 2.0.4
214
- * @return string
215
- */
216
- function weglot_get_full_url_no_language() {
217
- return weglot_get_request_url_service()->get_full_url_no_language();
218
- }
219
-
220
  /**
221
  * @since 2.0.4
222
  * @param string $url
@@ -226,33 +167,6 @@ function weglot_create_url_object( $url ) {
226
  return weglot_get_request_url_service()->create_url_object( $url );
227
  }
228
 
229
- /**
230
- * @since 2.0.4
231
- * @return int
232
- */
233
- function weglot_get_postid_from_url() {
234
- return url_to_postid( weglot_get_full_url_no_language() ); //phpcs:ignore
235
- }
236
-
237
- /**
238
- * Get option destination language
239
- * @since 2.0
240
- * @version 2.0.4
241
- * @return array
242
- */
243
- function weglot_get_destination_language() {
244
- return weglot_get_option( 'destination_language' );
245
- }
246
-
247
- /**
248
- * @since 2.3.0
249
- *
250
- * @return string
251
- */
252
- function weglot_get_private_languages() {
253
- return weglot_get_option( 'private_mode' );
254
- }
255
-
256
 
257
  /**
258
  * @since 2.4.0
1
  <?php
2
 
3
+ use Weglot\Client\Api\LanguageCollection;
4
+ use Weglot\Client\Api\LanguageEntry;
5
+ use WeglotWP\Services\Request_Url_Service_Weglot;
6
+
7
  if ( ! defined( 'ABSPATH' ) ) {
8
  exit;
9
  }
10
 
11
  /**
12
  * Get a service Weglot
 
 
13
  * @param string $service
14
  * @return object
15
+ * @throws Exception
16
+ * @since 2.0
17
+ *
18
  */
19
  function weglot_get_service( $service ) {
20
  return Context_Weglot::weglot_get_context()->get_service( $service );
22
 
23
  /**
24
  * Get all options
25
+ * @return array
26
+ * @throws Exception
27
  * @since 2.0
28
  *
 
29
  */
30
  function weglot_get_options() {
31
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_options();
33
 
34
  /**
35
  * Get option
 
36
  * @param string $key
37
+ * @return mixed
38
+ * @throws Exception
39
+ * @since 2.0
40
  */
41
  function weglot_get_option( $key ) {
42
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_option( $key );
44
 
45
  /**
46
  * Get original language
 
47
  * @return string
48
+ * @throws Exception
49
+ * @since 2.0
50
  */
51
  function weglot_get_original_language() {
52
  return weglot_get_option( 'original_language' );
54
 
55
  /**
56
  * Get current language
 
57
  * @return string
58
+ * @throws Exception
59
+ * @since 2.0
60
  */
61
  function weglot_get_current_language() {
62
+ return Context_Weglot::weglot_get_context()->get_service( 'Request_Url_Service_Weglot' )->get_current_language()->getInternalCode();
63
  }
64
 
65
  /**
66
  * Get destination language with filters
 
67
  * @return string
68
+ * @throws Exception
69
+ * @since 2.0
70
  */
71
  function weglot_get_destination_languages() {
72
  return Context_Weglot::weglot_get_context()->get_service( 'Option_Service_Weglot' )->get_destination_languages();
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Get Request Url Service
77
  * @since 2.0
81
  return Context_Weglot::weglot_get_context()->get_service( 'Request_Url_Service_Weglot' );
82
  }
83
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  /**
85
  * Get languages available on Weglot
86
+ * @return LanguageCollection
87
+ * @throws Exception
88
  * @since 2.0
 
89
  */
90
  function weglot_get_languages_available() {
91
  return Context_Weglot::weglot_get_context()->get_service( 'Language_Service_Weglot' )->get_languages_available();
92
  }
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  /**
95
  * Get button selector HTML
96
  * @since 2.0
126
  * @return string
127
  */
128
  function weglot_get_current_full_url() {
129
+ return weglot_create_url_object( weglot_get_request_url_service()->get_full_url() )->getForLanguage( weglot_get_request_url_service()->get_current_language() );
130
  }
131
 
132
  /**
158
  return weglot_get_option( 'auto_redirect' );
159
  }
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  /**
162
  * @since 2.0.4
163
  * @param string $url
167
  return weglot_get_request_url_service()->create_url_object( $url );
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  /**
172
  * @since 2.4.0
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: 3.2.0
11
  */
12
 
13
  /**
@@ -22,7 +22,7 @@ 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', '3.2.0' );
26
  define( 'WEGLOT_PHP_MIN', '5.4' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );
@@ -32,13 +32,11 @@ define( 'WEGLOT_DIR_DIST', WEGLOT_DIR . '/dist' );
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' );
41
- define( 'WEGLOT_TEMPLATES_ADMIN_METABOXES', WEGLOT_TEMPLATES_ADMIN . '/metaboxes' );
42
  define( 'WEGLOT_TEMPLATES_ADMIN_NOTICES', WEGLOT_TEMPLATES_ADMIN . '/notices' );
43
  define( 'WEGLOT_TEMPLATES_ADMIN_PAGES', WEGLOT_TEMPLATES_ADMIN . '/pages' );
44
 
@@ -125,8 +123,6 @@ function weglot_plugin_activate() {
125
  * @since 2.0
126
  */
127
  function weglot_plugin_deactivate() {
128
- flush_rewrite_rules();
129
-
130
  require_once __DIR__ . '/weglot-autoload.php';
131
  require_once __DIR__ . '/vendor/autoload.php';
132
  require_once __DIR__ . '/weglot-compatibility.php';
@@ -142,7 +138,6 @@ function weglot_plugin_deactivate() {
142
  * @since 2.0
143
  */
144
  function weglot_plugin_uninstall() {
145
- flush_rewrite_rules();
146
  delete_option( WEGLOT_SLUG );
147
  }
148
 
@@ -152,7 +147,7 @@ function weglot_plugin_uninstall() {
152
  * @return void
153
  */
154
  function weglot_rollback() {
155
- if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'weglot_rollback' ) ) {
156
  wp_nonce_ays( '' );
157
  }
158
 
7
  Author URI: https://weglot.com/
8
  Text Domain: weglot
9
  Domain Path: /languages/
10
+ Version: 3.3.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.3.0' );
26
  define( 'WEGLOT_PHP_MIN', '5.4' );
27
  define( 'WEGLOT_BNAME', plugin_basename( __FILE__ ) );
28
  define( 'WEGLOT_DIR', __DIR__ );
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_DEBUG', false );
36
  define( 'WEGLOT_DEV', false );
37
 
38
  define( 'WEGLOT_TEMPLATES', WEGLOT_DIR . '/templates' );
39
  define( 'WEGLOT_TEMPLATES_ADMIN', WEGLOT_TEMPLATES . '/admin' );
 
40
  define( 'WEGLOT_TEMPLATES_ADMIN_NOTICES', WEGLOT_TEMPLATES_ADMIN . '/notices' );
41
  define( 'WEGLOT_TEMPLATES_ADMIN_PAGES', WEGLOT_TEMPLATES_ADMIN . '/pages' );
42
 
123
  * @since 2.0
124
  */
125
  function weglot_plugin_deactivate() {
 
 
126
  require_once __DIR__ . '/weglot-autoload.php';
127
  require_once __DIR__ . '/vendor/autoload.php';
128
  require_once __DIR__ . '/weglot-compatibility.php';
138
  * @since 2.0
139
  */
140
  function weglot_plugin_uninstall() {
 
141
  delete_option( WEGLOT_SLUG );
142
  }
143
 
147
  * @return void
148
  */
149
  function weglot_rollback() {
150
+ if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( esc_url_raw( $_GET['_wpnonce'] ), 'weglot_rollback' ) ) {
151
  wp_nonce_ays( '' );
152
  }
153